Make AI-generated code verifiable and maintainable. The codebase has grown to ~91K lines of production Rust (116 files in src/) with significant AI-assisted development. The core problems are:
Files have outgrown their module boundaries — 21 files exceed 1000 lines; the largest is 7575L. 18 additional files over 800L are not yet tracked for splitting.
Pervasive copy-paste duplication — 231 Style::default() chains across 21 files, 82 identical Dockerfile FROM literals, 123 inline manifest filename strings, 10 independent mount helper definitions, 4 byte-for-byte-identical config_with_agents test functions, 7+ agent match-arm dispatch blocks that all need updating when a new agent is added.
Mega-functions — 25 functions carry #[allow(clippy::too_many_lines)] suppressions; the worst (fn run in app/mod.rs) is 1141 lines. These make PR review nearly impossible.
Weak module contracts — 51 of 116 files (44%) still lack //! orientation docs; no behavioral specs exist; no snapshot tests exist.
DRY violations in constants — "jackin.role.toml" appears 123 times, "Dockerfile" 230 times, "FROM projectjackin/construct:trixie\n" 82 times — all should be shared constants.
TUI render layer — console/manager/render/ and all widget files: 231 Style::default().fg() calls, 347 Span::styled() calls, 19 Block::default() chains, inline color constants duplicated across 10+ files instead of using the centralized palette in console/widgets/mod.rs
Auth provisioning — instance/auth.rs contains 5 near-identical provision functions; 7+ agent match-arm dispatch blocks across the codebase mean adding a new agent requires touching 7+ files
String literal duplication — "FROM projectjackin/construct:trixie\n" (82 occurrences in 8 files), "jackin.role.toml" (123 in 12 files), "Dockerfile" (230 in 15 files) — all inline instead of shared constants
Test infrastructure — 11 separate mock/fake struct definitions; 10 independent mount helper functions in 7 files; 4 byte-for-byte-identical config_with_agents test helpers; 20 inline ResolvedWorkspace constructions
Mega-functions — fn run (1141L), fn load_role_with (695L), fn entrypoint_dispatches_on_jackin_agent (446L) are the top 3; 25 total functions have too_many_lines suppressions
Agent-generated entropy accelerating: each new agent runtime duplicates auth provision patterns, TUI tab handling, and match-arm dispatch across 7+ files
The “clean console/runtime boundary” claim was never enforced and now has 2 production dependencies — the window for a clean Cargo workspace split is narrowing
No snapshot tests exist, so Phase 2 file splits risk silent render regressions
console/ is 42% of the entire codebase (38,499L across 49 files) but has the best //! coverage (90%); instance/, isolation/, manifest/, and tui/ all have 0% doc coverage
The Sync arm (read host file → write to role-state → HostMissing on NotFound) is copy-pasted across Codex, Amp, and GitHub provisioners in src/instance/auth.rs. The wipe-then-return for ApiKey/Ignore is identical across 4 agents.
7+ sites with Agent::Claude => ..., Agent::Codex => ..., Agent::Amp => ... match arms (config/roles.rs has three identical blocks, instance/mod.rs has 2, launch.rs has 4, auth_kind.rs 1, agent_choice/mod.rs 1, derived_image.rs 1). Adding a new agent requires touching all 7.
7 files across config, runtime, instance, console, derived_image
Identical DinD sidecar docker run arg list at launch.rs:777-799 and attach.rs:472-498
runtime/launch.rs, runtime/attach.rs
fn resolve_mode_with_trace() returning both mode and layer trace
build_mode_resolution() in launch.rs:2977-3011 duplicates the 3-layer × 4-agent match (12 arms) from config/roles.rs:22-56 solely to capture the resolution trace
45+ copy-pasted seeding blocks across 10 files; uses the 82-occurrence FROM literal and 150+ version strings
10+ test files
fn test_workspace(repo_dir) -> ResolvedWorkspace
20 inline ResolvedWorkspace { ... } constructions across 5 files
5 test files
fn simple_mount(src, dst, iso) -> MountConfig
10 local fn mount() / fn worktree_mount() / fn clone_mount() / fn shared_mount() helpers across 7 files, each constructing a MountConfig with slight variations
7 test files
Consolidate fake_runner_with_running
2 near-identical helpers in app/context.rs and input/save.rs with a subtle trailing-newline format difference
2 files
Consolidate render_to_dump test helpers
3 definitions in render/editor.rs (different test modules, different signatures)
Phase 1 prerequisites — snapshot tests, refreshed PROJECT_STRUCTURE.md, and the runtime/launch.rs behavioral spec
Phase 1.5 DRY extractions — shared constants first (highest ROI, lowest risk), then TUI boilerplate, then auth provisioning, then Docker commands, then test infrastructure
Phase 2 file splits — follow the recommended split order; do runtime/launch.rs absolutely last
Documentation follow-through — //! module contracts (priority: instance/, isolation/, manifest/, runtime/, tui/ all at 0% coverage), per-directory README files, ADRs
Full 2343L research document and 40-iteration history archived in git at commit b7e9fc2 on analysis/code-readability. May 2026 deep-audit findings are grounded in commit 282e235 on main.