trusty_code/cli_client/mod.rs
1//! Thin JSON-RPC client the `tcode` CLI binary drives against its own
2//! spawned `tcode serve --stdio` child (#2060, vision spec §4.4 "CLI as
3//! Thin Client" / Axiom 3 "API-First").
4//!
5//! Why: prior to this ticket, `tcode run-task` ran the PM->engineer
6//! `AgentLoop` IN-PROCESS inside the CLI binary — the only way to observe
7//! progress was the final printed report. The vision spec's Axiom 3 requires
8//! the CLI to hold NO orchestration logic: every session/task operation goes
9//! through the same JSON-RPC surface `tcode serve` already exposes, so a
10//! human, a script, and a future TUI all see identical behaviour. This
11//! module is the client half of that contract — the daemon (`crate::serve`,
12//! `crate::session`, `crate::task`) already defines the server half.
13//! What: [`stdio::StdioRpcClient`] spawns an EPHEMERAL `tcode serve --stdio`
14//! child per CLI invocation (the "simplest robust M1 approach" the ticket
15//! specifies — no persistent daemon discovery/lifecycle needed yet) and
16//! speaks JSON-RPC 2.0 NDJSON over its stdio pipes, reusing
17//! `trusty_common::mcp::{Request, Response}` for the wire envelope.
18//! [`render`] holds pure, unit-tested formatting functions (session table,
19//! one live-event line, transcript human view) shared by every CLI
20//! subcommand handler in the binary (`src/main.rs`/`src/cli/`), which own
21//! only argument parsing, the client lifecycle, and `process::exit` — never
22//! business logic.
23//! Test: `cli_client::stdio::tests` (line classification, id monotonicity —
24//! offline, no subprocess), `cli_client::render::tests` (formatting).
25//! End-to-end, real-subprocess coverage lives in `tests/cli_e2e.rs`, which
26//! drives the actual `tcode` binary as a black box.
27
28pub mod render;
29pub mod stdio;
30
31pub use stdio::{RpcClientError, StdioRpcClient};