KeiSeiKit-1.0/_primitives/_rust/kei-brain-view/src/error.rs
Parfii-bot 599eefeada feat(wave16): 5 parallel agents — ledger v6 + prune dedupe + brain-view clusters + fork-watch hook + three-role pipeline
51 crates, 753 tests green (up from 744 at v0.32.0).

All 5 agents launched in parallel via substrate composed prompts. Zero
file conflicts between scopes.

## A. kei-ledger v6 — 3 performance indexes + fork_transactional API
- idx_agents_started_ts, idx_agents_status, idx_agents_fork_parent_id
- fork_transactional<F>(): atomic fork row + caller side-effect
  closes kei-fork ↔ ledger transactional gap (Wave 15 known issue)
- 30 tests (was 23)

## B. kei-prune dedupe — cluster-based retirement via kei-dna-index
- dedupe_candidates() via kei_dna_index::cluster_by(Scope)
- dedupe_strict() — intersection of scope+body clusters
- apply_retirements() reuses mark_retired
- CLI: kei-prune dedupe [--strict] [--dry-run]
- 17 tests (was 9)

## C. kei-brain-view clusters — stats + cluster visualization
- render_clusters(by: ClusterBy) — indented tree output
- render_summary() — 6-line dashboard from kei-dna-index::stats
- CLI: kei-brain-view clusters --by scope|body|role; kei-brain-view summary
- 15 tests (was 8)

## D. kei-fork watch-hook — auto-collect on .DONE marker
- watch_loop() — kei-watch subscription + auto kei-fork collect
- hooks/fork-collect-on-done.sh — foreground daemon wrapper
- dedupe via HashSet + agent_id validation
- 21 tests (was 13)

## E. three-role pipeline (Writer → Auditor → Merger)
- _roles/auditor.toml (pipeline.handoff=["merger"], claude-subagent-type=critic)
- _roles/merger.toml (leaf, git-ops scoped, infra-implementer)
- 5 new capability fragments: policy/git-ops-scope, scope/read-only,
  output/verdict, output/merge-result, verify/fork-audit
- kei-spawn: pipeline_from_role + emit_pipeline_json + scaffold_downstream_tasks
- kei-spawn: precedent::run_advisory (env-gated KEI_SPAWN_PRECEDENT_CHECK)
- CLI: kei-spawn spawn --pipeline
- 19 tests (was 10)

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-23 18:53:58 +08:00

35 lines
1.2 KiB
Rust

//! Error type for brain-view ops.
//!
//! Constructor Pattern: one cube = one error type + its trait impls.
//! Thiserror-based so `Display` + `From<rusqlite::Error>` are derived.
use thiserror::Error;
/// Hard cap on BFS descent to guard against cyclic or runaway data.
/// Mirrors `kei-ledger::MAX_TREE_DEPTH` — the visualizer must fail fast
/// rather than hang rendering a malformed graph.
pub const MAX_TREE_DEPTH: usize = 1024;
#[derive(Debug, Error)]
pub enum BrainViewError {
#[error("sql: {0}")]
Sql(#[from] rusqlite::Error),
/// BFS traversal exceeded `MAX_TREE_DEPTH` iterations — the underlying
/// ledger likely contains a cycle or an unexpectedly deep chain.
#[error("tree walk exceeded {0} iterations (cycle or runaway ledger)")]
MaxDepthExceeded(usize),
/// Requested DNA prefix matched zero rows in the ledger.
#[error("dna not found: {0}")]
DnaNotFound(String),
/// Requested DNA prefix matched multiple rows; caller must disambiguate.
#[error("dna prefix {prefix} ambiguous ({count} matches)")]
DnaAmbiguous { prefix: String, count: usize },
#[error(transparent)]
DnaIndex(#[from] kei_dna_index::Error),
}
pub type Result<T> = std::result::Result<T, BrainViewError>;