Hmbown / Hmbown/Codewhale

Decompose the mega files: lib.rs (18.7k), config.rs (12.3k), client.rs (11.1k), runtime_threads.rs (9.3k)

Open
#5,586 8 comments 0 reactions 0 assignees View on GitHub
v0.9.12
Dominant language
Rust
Stars
41k
Forks
3.6k
Avg merge
13h 59m
Merged PRs (30d)
299

Description

## Combined Core execution: C09

[Core execution plan]() owns order and scope. This issue contributes to C09; the linked plan owns the complete packet and any outstanding candidate acceptance. Record this issue's path claims and implementation evidence here.

**Issue mapping:** [SHA-6291 / GitHub #5586]()
covers cohesive large-file decomposition across C03–C09; move whole behaviors
and owning tests, with checked dependency boundaries rather than line-count
targets. [SHA-6286 / GitHub #5580]() moves remaining
event handling into domain reducers and leaves dispatch in `event_loop.rs`;
preserve the existing reducer pattern and migrate touched arms completely.
[SHA-6287 / GitHub #5581]() supplies the per-call
telemetry consumer requirements implemented in C11 with #6011: live token/time
display, cache visibility and durable mid-turn accounting, with authoritative
completion reconciliation and no double counting. Credit already-live cost,
background cost, timing and context surfaces.

[SHA-5509 / GitHub #3957]() separates shared modal
infrastructure from owned Config/SubAgents views and makes all provider
credential entry use the same masking, validation and geometry primitive.
Prove paste/delete/Enter/Esc/failure/retry and 80x24/120x32 wrapping; secrets
must never reach screenshots, logs or errors.
[SHA-5506 / GitHub #3954]() splits setup by
constitution, runtime, provider, persistence/report and navigation ownership
where warranted; preserve constitution checkpoints and onboarding handoff.
These client refactors keep behavior and private-test visibility intact.

[SHA-6251 / GitHub #5528]() requires visible
workflow dispatch/schema failures even before a child starts, with preserved
error/status receipts over the shared event authority.
[SHA-6156 / GitHub #5268]() requires visible queue,
send-now, cancel/keep-draft and named waits over existing runtime channels;
qualify those states with C12 and C08's submitted-steer consume/ack contract.
C01's #5479 register and controls must use this same runtime projection.

**Owner: client-adapter owner. Dependencies: C08.** Fold the embedded HTTP
API into the existing app-server HTTP/SSE/stdio surface over the shared
runtime, preserving routes and authentication. Move argument parsing and
headless presentation from TUI `lib.rs` into CLI; preserve binary names and
public commands. TUI owns terminal lifecycle, rendering, input, pickers and
slash-command presentation, calling the same runtime operations. Use existing
in-process `EngineHandle`/`Op`/`Event` seams; local terminal use need not hop
through HTTP. Separate wire DTOs from internal reply channels/capabilities.

**Completion evidence required:** all three clients reach the same lifecycle/execution owner,
transport/auth/protocol parity and reconnect/recovery pass, no UI-owned
provider I/O/policy/store/loop remains, and obsolete dependencies and temporary
internal shims are removed. Adopt `core/protocol_parity.rs` in real consumers
or retire it; unused parity code is not convergence. Resize UI files only by
remaining responsibility. Apps product work is not part of this packet.

---

## Original issue and contributor history

User ask for the 0.9.12 cleanup lane: the 10k+-line files keep causing pain. Measured today (prod code, excluding the 20k-line test files which should split alongside their subjects):

* `crates/tui/src/lib.rs` — 18,747
* `crates/tui/src/config.rs` — 12,346
* `crates/tui/src/client.rs` — 11,122
* `crates/tui/src/runtime_threads.rs` — 9,322
* `crates/tui/src/core/engine.rs` — 6,891, `core/engine/turn_loop.rs` — 6,668, `runtime_api.rs` — 6,542, `tui/ui/event_loop.rs` — 5,721 (event_loop already tracked in #5580)

Approach (same discipline as #5580): mechanical module extraction, one cohesive region per commit, no behavior change, moves verified by `cargo check` + the file's existing test slice. Suggested first cuts: [client.rs]() wire-parsing (parse_usage/SSE chunk parsing + their tests) into `client/wire.rs`; [config.rs]() merge/persistence into `config/merge.rs`; [lib.rs]() engine-config assembly into its own module. Declared one-way per AGENTS.md once started: new code lands in the extracted modules, touched regions migrate.

Tracker: #5573. Related: #5580, #5581.

Contributor guide

Open the contributing guide

Research direction

Read AGENTS.md and the C09 core execution plan first, then inspect crates/tui/src/client.rs, config.rs, lib.rs, and runtime_threads.rs. For a bounded starting slice, trace parse_usage and SSE chunk parsing with their existing tests, then run cargo check and that file's test slice. Done requires behavior-preserving module extraction with dependency boundaries and the stated lifecycle, protocol, reconnect, and recovery evidence.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend, cli
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.