Decompose tools/subagent/mod.rs (19k lines): ordered extraction plan
Author: HmbownCreated Sep 17, 2026Updated Sep 17, 2026
What
crates/tui/src/tools/subagent/mod.rs is ~19,200 lines / 360 top-level items;
its tests.rs sibling is ~23,200 lines. Every subagent fix pays the tax of
finding the defect site in a file no one can hold in their head, and every
edit risks unrelated coupling through use super::*. Extraction has started
(advisor, budget_handback, coord, delivery, lifecycle, mailbox,
naming, worktree are already siblings) but the bulk is still one file.
How to split it (leaf clusters first, pure moves, one slice per commit)
Order by dependency direction — each slice must compile and pass the subagent suite on its own, with no behavior change:
- Done:
fallback_partial_text+tool_target_preview→budget_handback.rs(commit7307f2302c). - Budget context cluster (
child_wall_time_exhausted_reason,child_runtime_budget_context,child_budget_pacing_notice, ~80 lines) →budget_handback.rsor a newbudgets.rs. - Summary/spill cluster (
subagent_summary_char_budget,stamp_subagent_summary*,spill_subagent_final_report,summarize_subagent_result, ~110 lines) → newsummary.rs. - Model routing cluster (
configured_model_*,resolve_subagent_assignment_route,subagent_reasoning_effort_*, ~470 lines) → newrouting.rs. - Usage/accounting cluster (
record_provider_response_usage,refresh_usage_note,priced_usd_microusd,AgentRunUsagehelpers, ~220 lines) → newusage.rs. - Tool admission policy (
is_unbounded_shell_run,reject_network_reaching_input,mutation_paths,build_allowed_tools, ~320 lines of pure predicates) → newadmission.rs. - Checkpoint/persistence cluster (
SubAgentCheckpoint,PersistedSubAgent*,build_subagent_checkpoint, …) → newcheckpoint.rs. SubAgentToolRegistryimpl (~1,400 lines, the single biggest block) → newtool_registry.rs, after 6 removes its predicate dependencies.- Spawn/parse cluster (
SpawnRequest,parse_*, launch) →lifecycle.rsor newspawn.rs. - Manager core + run loop stay in
mod.rslast; splittests.rsto mirror whatever modules exist by then.
Rules for each slice
- Pure move:
pub(super)visibility, qualified call sites, zero behavior change, subagent suite green before commit. - Migrate all callers or do not start the slice (no shims, no re-exports left behind "temporarily").
- New code goes in the new home from day one;
mod.rsonly shrinks.
Acceptance
-
mod.rsholds only the manager core + run loop (target: under 5,000 lines) - Every slice above landed as behavior-preserving commits with green gates
-
tests.rssplit to mirror the module layout - Related: #6034 (the
crate::configmonolith is the same disease one layer down)
Source: Hmbown/CodeWhale