Skip to content

refactor(cmd): split commands.rs into per-domain modules - #48

Open
duyet wants to merge 1 commit into
mainfrom
cursor/009-split-commands-4ce0
Open

refactor(cmd): split commands.rs into per-domain modules#48
duyet wants to merge 1 commit into
mainfrom
cursor/009-split-commands-4ce0

Conversation

@duyet

@duyet duyet commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Why

src/commands.rs held every command plus TUI plumbing in one 4,271-line file. Concurrent features collided there, and reviews mixed unrelated domains. The internal seams were already run_* per command, so this is a mechanical split with no behavior change.

Closes #24.

Scope

  • Add src/cmd/ with auth, login, models, usage, config_tui, launch, account, keys, menu, and dispatch.
  • src/commands.rs is a 154-line shim: run(), dispatch(), and the cmd imports. Target was ≤ 300 lines.
  • pub mod cmd; in src/lib.rs (alphabetically between channel and commands). Public entry stays commands::run.
  • Unit tests moved with their code: persist_login_tests in login.rs, picker catalog tests in models.rs, launcher tests in dispatch.rs.
  • No function renames. No command behavior change. Version stays 0.1.x.

Tradeoffs

Shared helpers that would cycle menuconfig_tui or modelslaunch live in dispatch.rs as a leaf: config_path, CreditsCache, catalog_lookup_enabled, tool_command_for, persist_tool_command, launcher_last_tool. RoutingField lives next to toggle_agent_routing_field in models.rs. pub(crate) on moved items is the crate-internal surface; nothing new is public outside the crate.

Blast Radius

Every CLI command still enters through commands::run. Callers in src/main.rs are unchanged. Reviewers should spot-check a few function bodies against main (ignore pub(crate) and rustfmt wraps on longer signatures). Do not merge release-please #15.

Verification

  • wc -l src/commands.rs → 154

  • cargo test --locked --all-targets → 186 lib + 68 cli + 7 release_lock

  • cargo fmt --check → exit 0

  • cargo clippy --locked --all-targets -- -D warnings → no new hits under src/cmd/ or src/commands.rs (baseline warnings remain in upgrade.rs / spawn.rs / http.rs, owned by chore(dx): enforce clippy and rustfmt in CI #45)

  • cargo build --locked --target wasm32-unknown-unknown --no-default-features → exit 0

  • control-anyr launch + doctor → all ok

  • Driven isolated anyr --help, --version, whoami, menu --dump-tui, config --dump-tui, auth --help → exit 0; help still lists CORE COMMANDS / LAUNCH; whoami masks the fixture key; menu dump shows LAUNCH / claude / CONFIGURE; config dump shows ACCOUNT / MODEL / AGENT / GENERAL

  • Version stays on 0.1.x (do not introduce 0.2 / 1.0)

  • Do not auto-merge release-please PRs

Open in Web Open in Cursor 

Move auth, login, models, usage, config TUI, launch, account, keys,
menu, and dispatch into src/cmd/. commands.rs becomes a thin re-export
shim. No behavior change.

Closes #24

Co-authored-by: Duyet Le <me@duyet.net>
Co-authored-by: duyetbot <bot@duyet.net>
@github-actions

github-actions Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

anyr size and startup

Startup is wall time for a cold anyr --version / anyr --help (median of 21 runs). Size is the stripped release binary, or the .wasm for the browser demo.

Size budget: anyr-linux-x86_64 must stay ≤ 4.0 MiB (4194304 bytes) stripped.

Asset Kind Size --version median --help median
anyr-darwin-arm64 native 2.8 MiB 4.1 ms 3.53 ms
anyr-darwin-x86_64 native 3.0 MiB 41.24 ms 40.45 ms
anyr-linux-arm64 native 2.8 MiB 0.79 ms 0.8 ms
anyr-linux-x86_64 native 3.1 MiB 0.95 ms 0.94 ms
anyr-windows-x86_64.exe native 2.5 MiB 6.06 ms 5.93 ms
anyr.wasm wasm 176.5 KiB

Budget check: ok

raw timings
[
  {
    "asset": "anyr-darwin-arm64",
    "kind": "native",
    "path": "/Users/runner/work/cli/cli/anyr-darwin-arm64",
    "bytes": 2905848,
    "size": "2.8 MiB",
    "version": "0.1.11 (built 2026-09-03 18:24:36)",
    "target": "aarch64-apple-darwin",
    "os": "macos-latest",
    "startup_version": {
      "n": 21,
      "min_ms": 3.89,
      "median_ms": 4.1,
      "p95_ms": 5.69,
      "mean_ms": 4.63
    },
    "startup_help": {
      "n": 21,
      "min_ms": 3.06,
      "median_ms": 3.53,
      "p95_ms": 3.91,
      "mean_ms": 3.49
    }
  },
  {
    "asset": "anyr-darwin-x86_64",
    "kind": "native",
    "path": "/Users/runner/work/cli/cli/anyr-darwin-x86_64",
    "bytes": 3120192,
    "size": "3.0 MiB",
    "version": "0.1.11 (built 2026-09-03 18:24:53)",
    "target": "x86_64-apple-darwin",
    "os": "macos-latest",
    "startup_version": {
      "n": 21,
      "min_ms": 38.01,
      "median_ms": 41.24,
      "p95_ms": 49.43,
      "mean_ms": 42.17
    },
    "startup_help": {
      "n": 21,
      "min_ms": 35.42,
      "median_ms": 40.45,
      "p95_ms": 52.0,
      "mean_ms": 41.93
    }
  },
  {
    "asset": "anyr-linux-arm64",
    "kind": "native",
    "path": "/home/runner/work/cli/cli/anyr-linux-arm64",
    "bytes": 2888744,
    "size": "2.8 MiB",
    "version": "0.1.11 (built 2026-09-03 18:23:58)",
    "target": "aarch64-unknown-linux-gnu",
    "os": "ubuntu-24.04-arm",
    "startup_version": {
      "n": 21,
      "min_ms": 0.69,
      "median_ms": 0.79,
      "p95_ms": 0.87,
      "mean_ms": 0.79
    },
    "startup_help": {
      "n": 21,
      "min_ms": 0.74,
      "median_ms": 0.8,
      "p95_ms": 0.84,
      "mean_ms": 0.8
    }
  },
  {
    "asset": "anyr-linux-x86_64",
    "kind": "native",
    "path": "/home/runner/work/cli/cli/anyr-linux-x86_64",
    "bytes": 3216904,
    "size": "3.1 MiB",
    "version": "0.1.11 (built 2026-09-03 18:24:03)",
    "target": "x86_64-unknown-linux-gnu",
    "os": "ubuntu-latest",
    "startup_version": {
      "n": 21,
      "min_ms": 0.94,
      "median_ms": 0.95,
      "p95_ms": 0.97,
      "mean_ms": 0.95
    },
    "startup_help": {
      "n": 21,
      "min_ms": 0.93,
      "median_ms": 0.94,
      "p95_ms": 1.03,
      "mean_ms": 0.95
    }
  },
  {
    "asset": "anyr-windows-x86_64.exe",
    "kind": "native",
    "path": "D:\\a\\cli\\cli\\anyr-windows-x86_64.exe",
    "bytes": 2665984,
    "size": "2.5 MiB",
    "version": "0.1.11 (built 2026-09-03T18:24:43Z)",
    "target": "x86_64-pc-windows-msvc",
    "os": "windows-latest",
    "startup_version": {
      "n": 21,
      "min_ms": 5.83,
      "median_ms": 6.06,
      "p95_ms": 6.23,
      "mean_ms": 6.06
    },
    "startup_help": {
      "n": 21,
      "min_ms": 5.83,
      "median_ms": 5.93,
      "p95_ms": 6.08,
      "mean_ms": 5.95
    }
  },
  {
    "asset": "anyr.wasm",
    "kind": "wasm",
    "path": "/home/runner/work/cli/cli/target/wasm-pkg/anyr_cli_bg.wasm",
    "bytes": 180713,
    "size": "176.5 KiB",
    "version": "wasm",
    "target": "wasm32-unknown-unknown",
    "os": ""
  }
]

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.

Plan 009: Split commands.rs into per-domain modules

2 participants