KeiSeiKit-1.0/_primitives/_rust/kei-spawn/src/lib.rs
Parfii-bot 6562b581f7 feat(w9d): kei-spawn drive subcommand + AnthropicDriver trait stub
kei-spawn drive <task.toml> internally calls spawn pipeline, emits
SpawnOutput JSON to stdout, returns exit 64 (NotImplemented) from
ManualDriver with stderr instruction to use manual Agent-tool path.

AnthropicDriver trait: ManualDriver (current) + HttpDriver (future
reqwest+tokio+KEI_ANTHROPIC_KEY). Extensibility preserved without
breaking-change deps.

Tests: 10/10 (was 6, +4: 2 drive unit + 2 drive_smoke binary integration).

Exit code contract: 0 success, 1 spawn-fail, 2 verify-fail, 64
NotImplemented (matches kei-runtime::invoke NotImplemented convention).

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

38 lines
1.6 KiB
Rust

//! kei-spawn — automation envelope around kei-agent-runtime + kei-ledger.
//!
//! Orchestrator flow pre-kei-spawn:
//! 1. Write task.toml manually
//! 2. Run `kei-agent-runtime prepare`
//! 3. Invoke Agent tool (harness-internal, orchestrator-only)
//! 4. Run `kei-ledger fork`
//! 5. On return, run `kei-agent-runtime verify`
//!
//! With kei-spawn, steps 2 + 4 collapse to one `kei-spawn spawn <task.toml>` call
//! and step 5 collapses to one `kei-spawn verify <agent-id> <worktree>` call.
//! Step 3 (the actual Agent tool invocation) STILL belongs to the orchestrator
//! because Claude Code's `Agent` tool is harness-internal — it can't be invoked
//! from Rust. `kei-spawn` emits a JSON bundle the orchestrator pastes.
//!
//! Design constraints:
//! - Constructor Pattern: one module = one responsibility, ≤200 LOC file,
//! ≤30 LOC fn.
//! - No HTTP / no Anthropic API — that's a later `kei-spawn drive` iteration.
//! - No git / no shell — ledger interactions go through `kei-ledger` as a
//! subprocess to avoid adding kei-ledger as a direct dep while it still
//! lacks a lib.rs (can't link to a bin-only crate).
//!
//! Per RULE 0.13: kei-spawn NEVER creates branches or commits. The orchestrator
//! owns git state. kei-spawn only writes into `tasks/<agent-id>/` and invokes
//! `kei-ledger` (which itself only writes to SQLite).
pub mod drive;
pub mod ledger_sh;
pub mod spawn;
pub mod verify;
pub use drive::{
drive_with, not_implemented_message, AgentResult, AnthropicDriver, DriveError, HttpDriver,
ManualDriver,
};
pub use spawn::{spawn_from_task, SpawnOutput};
pub use verify::{verify_agent, VerifyOutput};