feat: Route REPL command output through machine-readable formatter (Phase 1 Task 1.4.1 and 1.4.3) #11
Notifications
Due Date
No due date set.
Blocks
Depends on
#8 feat: Phase 1 robot mode + forgiving parser test suite
terraphim/agent-tasks
#4 feat: Wire ForgivingParser into REPL command dispatch
terraphim/agent-tasks
Reference: terraphim/agent-tasks#11
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem Statement
Phase 1 Task 1.4.1 and Task 1.4.3 of the session-search spec are unchecked.
ForgivingParseris now wired intoReplHandler::execute_command(#4), andBudgetEngineis scheduled (#7), but individual command handlers (handle_search,handle_role,handle_vm, etc.) stillprintln!human-oriented coloured strings. There is noOutputModerouting:--format jsonor--roboton the CLI does not produce a machine-readable envelope for any command other than/n capabilities(already implemented by Task 1.3). Until the handler routes throughoutput::RobotFormatter, the Task 1.6 integration testtests/repl_robot_tests.rs(tracked by #8) cannot assert a full JSON envelope end-to-end, and AI-agent consumers cannot rely on structured output.Current State
crates/terraphim_agent/src/robot/output.rsdefinesRobotFormatter,ResponseEnvelope, compact/non-compact variants, and error payload shapes.crates/terraphim_agent/src/repl/handler.rsholdsReplHandler(line ~28) with nooutput_modefield and noRobotFormatterreference.handle_search(line ~458) and sibling handlers print directly withcoloredandprintln!.execute_command(line ~258) already wiresForgivingParserand composes a human-oriented auto-correction notice; there is no branch that suppresses the notice for machine mode or addsmeta.auto_correctedto the envelope.bin/terraphim-agent.rs) accepts--format jsonbut the value never reachesReplHandler.Acceptance Criteria
ReplHandlergains anoutput_mode: OutputModefield populated from CLI args (Interactive | Json | JsonCompact).execute_commandsuppresses coloured stdout writes whenoutput_mode != Interactiveand instead emits the correspondingResponseEnvelopeviaRobotFormatter.meta.auto_corrected: bool,meta.alias_expanded: bool,meta.duration_ms: u64.ExitCode(64 for usage, 70 for internal).handle_search,handle_role,handle_graph,handle_vm, andhandle_configroute results throughRobotFormatter::format_response.cargo test -p terraphim_agent --features repl-fullpasses.cargo clippy -p terraphim_agent --features repl-full -- -D warningspasses.terraphim-agent --format json search foo | jq .parses without error.Proposed Approach
ReplHandler::newwith anoutput_modeparameter; plumb frombin/terraphim-agent.rsarg parser.CommandOutputenum (Search(SearchHit), Role(RoleInfo), ...) returned by eachhandle_*method instead of printing.ReplHandler::emit(output: CommandOutput) -> Result<()>that dispatches toRobotFormatteror to the existing coloured printer.execute_commandto captureParseResultmetadata and merge into the envelope before emit.#[cfg(feature = "repl")] && matches!(output_mode, Interactive).Files affected:
crates/terraphim_agent/src/repl/handler.rs(main change)crates/terraphim_agent/src/bin/terraphim-agent.rs(CLI plumbing)crates/terraphim_agent/src/robot/output.rs(addmetafields if missing)Dependencies
Depends on #4 (
ForgivingParserwiring) so thatParseResultflows intoexecute_command.Unblocks #8 (Phase 1 tests): integration tests need the JSON envelope to assert shape.
Verification
Scope
Single PR, estimated 250-350 LOC across
handler.rs,bin/terraphim-agent.rs, and a handful of imports. Completes Phase 1 Tasks 1.4.1 and 1.4.3.Upstream: Implements
docs/specifications/terraphim-agent-session-search-tasks.mdPhase 1 Task 1.4 for terraphim/terraphim-ai.