Skip to content

refactor(claude_code, agy): split the backends, no behaviour change - #63

Merged
blockmandev merged 3 commits into
mainfrom
refactor/claude-code-agy
Oct 23, 2026
Merged

blockmandev merged 3 commits into
mainfrom
refactor/claude-code-agy

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Answers the code-auditor findings on the two CLI backends, with no behaviour change.

Findings

  • 61cca2ff219e8b85 / 5bcfc09b27cc70a1: claude_code.rs (2999 lines, fan-out 465) becomes src/agent/claude_code/, with every file 42-899 lines.
  • 67d03875838af645: map_line (complexity 24) becomes a dispatch over session_started, stream_delta, assistant_text, quota, result_events and failure_detail.
  • 678f3d6c5545abf5: run_once (157 lines) becomes setup plus trace_spawn, dump_argv, spawn and finish.
  • dfca66823754eb28 / b983d3bca036581a: agy's run_turn (117 lines) becomes spawn, read, started, finished and no_result_line. Its tests move to agy_tests.rs.

audit_static_check reports no function over 100 lines and no complexity over 20 in any changed file. Fan-out is left as the split leaves it. The two remaining cycle reports in wire_tests.rs are name-matching false positives (the test helper map is matched against .map( calls).

Commits

  1. 7548a73 pins behaviour first, and the pins pass on the original single file:
    • a 47-line map_line corpus;
    • the exact argv and environment of each command;
    • whole turns through run_turn on stand-in CLIs, with the exact error texts (spawn failure, no result line, cancelled).
  2. 7a9aa77 is the split. Every crate::agent::claude_code:: path is re-exported unchanged. The process tree still lives until stderr is read, as before.

MAX_UNWIRED 41 -> 38: read this before merging

The old file had a column-zero #[cfg(test)] at line 8, so the wiring scanner never read the rest of it.

  • Toolbox::run_subagents_on and tool_bridge::client_entry were listed as unwired while called from that file. They are now correctly seen.
  • guards::restrictions is not really wired. It is still called only by tests. The scanner now reads the split-out test files as production code because they have no column-zero marker, the same blind spot api_wire_tests.rs and runner/*_tests.rs already have. That is a scanner limitation to decide on separately.

Gate (Windows)

  • cargo fmt --all -- --check: clean.
  • cargo clippy --all-targets -- -D warnings: clean.
  • cargo test: lib 2305 passed, 10 ignored. Before this work: 2289 passed, 10 ignored.
  • No tests deleted or ignored, no new #[allow], no new crates.

blockmandev and others added 3 commits October 23, 2026 13:11
…hole turns

Before splitting the two backends, pin what they do through the paths a
refactor could move: a 47-line corpus over map_line (every event type,
subagent and empty cases, each way a failed result describes itself,
lines that do not parse) and that only a result line writes the outcome;
the exact argv and environment of claude's command for a plain turn, a
fully configured one and one after the thinking flag was refused, and
the stdin message; agy's exact command, default and configured. Whole
turns run through run_turn on stand-in CLIs: the events in order, the
outcome, the session kept, and the exact error texts for a CLI that
cannot start, a turn with no result line and a cancelled agy turn.

All pass on the original single-file code.

Co-Authored-By: Claude <noreply@anthropic.com>
claude_code.rs (3557 lines with the pins) becomes src/agent/claude_code/:
the backend and its AgentBackend face (mod.rs), the stream-json lines
and what each becomes (wire.rs), the argv and environment a turn starts
with (command.rs), one run of the CLI with the bridge and the stream loop
(turn.rs), profile and login choice (profiles.rs), and deny rendering
(deny.rs); tests split into tests.rs (stand_in_cli stays at its crate
path), wire_tests.rs, command_tests.rs and profile_tests.rs. Everything
other code names is re-exported, so every crate::agent::claude_code::
path is unchanged.

map_line is a dispatch over named steps (session_started, stream_delta,
assistant_text, quota, result_events, failure_detail); run_once is
spawn plumbing plus trace_spawn, dump_argv, spawn and finish, with the
process tree kept alive until stderr is read, as before. agy's run_turn
becomes spawn, read, started, finished and no_result_line, and its tests
move to agy_tests.rs. A stray doc comment that sat on PROFILE_ENV goes
back to consume, which it describes.

MAX_UNWIRED 41 -> 38, as the wiring ratchet asks. The old file had a
column-zero #[cfg(test)] at line 8, so the scanner never read it:
Toolbox::run_subagents_on and tool_bridge::client_entry were listed
unwired while called from it, and are now seen. The third drop is NOT
real wiring: guards::restrictions is still called only by tests, which
the scanner now reads because test files reached by #[path]/mod have no
column-zero marker (the same blind spot api_wire_tests.rs and the
runner's test files already have).

The pins from the previous commit pass unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
From the independent review of #63: budget_for_spawn's doc named
claude_code.rs for run_once (now claude_code/turn.rs), and contracts.json's
RateLimitInfo _owner named claude_code.rs (now claude_code/wire.rs).
Documentation only; nothing reads _owner.
@blockmandev
blockmandev merged commit c298434 into main Oct 23, 2026
12 checks passed
@blockmandev
blockmandev deleted the refactor/claude-code-agy branch November 15, 2026 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant