Skip to content

refactor(cli): split main.rs into per-responsibility modules#3267

Open
thiagomargatho wants to merge 2 commits into
ultraworkers:mainfrom
thiagomargatho:split-main-rs-modules
Open

refactor(cli): split main.rs into per-responsibility modules#3267
thiagomargatho wants to merge 2 commits into
ultraworkers:mainfrom
thiagomargatho:split-main-rs-modules

Conversation

@thiagomargatho

Copy link
Copy Markdown

Summary

  • main.rs had grown to ~15k lines with 8+ unrelated concerns interleaved function-by-function throughout the file (arg parsing, boot/health checks, runtime bootstrap, provider client, progress reporting, model resolution, skill dispatch). Split along those natural boundaries into separate files; main.rs is now a thin entry point (constants, main(), mod declarations, existing tests).
  • Also fixes a stale path in root CLAUDE.md (.claude/settings.local.json.claw/settings.local.json, matching rust/CLAUDE.md and .claw.json).
  • No logic changed — items moved verbatim, marked pub(crate) where a new module boundary required it, with use crate::*; in each new file so cross-module references resolve through main.rs's re-exports.

New files:

  • model_provenance.rs — model alias/version resolution
  • cli_parse.rs — CLI arg parsing, help, report formatting
  • preflight.rs — doctor/health checks, boot snapshot, git status
  • bootstrap.rs — runtime bootstrap, LiveCli, session management
  • provider_client.rs — Anthropic client, tool executor, MCP wiring
  • progress.rs — prompt/hook progress reporting
  • skill_dispatch.rs — bare-skill dispatch, cwd guard, diff reports

Test plan

  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test --workspace — all suites pass
  • scripts/fmt.sh --check — clean

🤖 Generated with Claude Code

thiagomargatho and others added 2 commits July 7, 2026 09:15
Root CLAUDE.md said shared defaults live in .claude.json and
machine-local overrides in .claude/settings.local.json. Both are
wrong: .claude.json is Claude Code's own permission config, unrelated
to this project. The project's actual shared-defaults file is
.claw.json (model aliases etc.), and its local-override path is
.claw/settings.local.json — matching rust/CLAUDE.md and .claw.json.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
main.rs had grown to ~19.8k lines with 8+ unrelated concerns
interleaved function-by-function throughout the file (arg parsing,
boot/health checks, runtime bootstrap, provider client, progress
reporting, model resolution, skill dispatch all mixed together).
Split along those natural boundaries into separate files, keeping
main.rs as a thin entry point (constants, main(), mod declarations,
existing tests).

No logic changed — items moved verbatim, marked pub(crate) where a
new module boundary required it, with `use crate::*;` in each new
file so cross-module references keep resolving through main.rs's
re-exports. Verified with cargo check/clippy/test on this crate and
scripts/fmt.sh; confirmed the few remaining test failures
(provider-detection defaults in the api/rusty-claude-cli crates) are
pre-existing on a clean checkout of main, unrelated to this change.

New files:
- model_provenance.rs — model alias/version resolution
- cli_parse.rs — CLI arg parsing, help, report formatting
- preflight.rs — doctor/health checks, boot snapshot, git status
- bootstrap.rs — runtime bootstrap, LiveCli, session management
- provider_client.rs — Anthropic client, tool executor, MCP wiring
- progress.rs — prompt/hook progress reporting
- skill_dispatch.rs — bare-skill dispatch, cwd guard, diff reports

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@thiagomargatho thiagomargatho force-pushed the split-main-rs-modules branch from 8241299 to 0089e45 Compare July 7, 2026 12:16
@1716775457damn

Copy link
Copy Markdown

Nice refactor! The decomposition into per-responsibility modules is clean and well thought out. A couple of observations:

  • Each new file using use crate::*; to resolve through main.rs's re-exports works but creates a tight coupling — consider whether some of these modules could eventually be promoted to first-class crate modules with their own explicit imports, which would make dependencies more explicit and testable in isolation.
  • model_provenance.rs feels like it could be simplified to just provenance.rs or resolution.rs — the "model_" prefix is redundant given the file is already in a CLI context.
  • The .claw path fix in root CLAUDE.md is a good catch.

Test plan looks solid — clippy clean, all tests pass, fmt clean. No blockers from my side.

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.

2 participants