Skip to content

refactor(slash_commands): split parse and the module, no behaviour change - #60

Merged
blockmandev merged 1 commit into
mainfrom
refactor/slash-commands
Oct 23, 2026
Merged

blockmandev merged 1 commit into
mainfrom
refactor/slash-commands

Conversation

@blockmandev

Copy link
Copy Markdown
Member

Answers code-auditor findings 8626e7d823e143d3, 2e6d084023ccf97a, 847a3ecc41a89f98 and 3abe5c8d5c43e040 on src/cli/slash_commands.rs.

Measured before

  • SlashCommand::parse: cyclomatic complexity 57 (threshold 20)
  • handle_roadmap: 112 lines (threshold 100)
  • file: 2399 lines (threshold 1000), fan-out 394

What changed

  • parse looks the command word up in SPELLINGS, a table of every spelling with the parser for its argument. /rewind, /remember, /forget, /kill, /bg and /image each get a named helper.
  • handle_roadmap now calls three steps in order: ready_brief, mark_proven_done, say_what_cannot_prove. The text and the order of what it prints are the same.
  • slash_commands.rs became slash_commands/ with one file per command family. mod.rs keeps the enum, COMMANDS and /help, and glob re-exports every handler, so no caller changed.
file lines
mod.rs 311
parse.rs (incl. parse tests) 601
agents.rs (incl. /agent, /roles tests) 718
workspace.rs 304
tools.rs (incl. skills tests) 286
session.rs 247
status.rs 215
memory.rs 86

Measured after (same auditor)

No function in the module is over complexity 20 or 100 lines, and no file is over 1000 lines. The longest function is roles_command at 98 lines, which this PR does not change. The only findings left are fan-out, now 34 to 157 per file instead of 394 for the one file.

Equivalence

  • Before the split, I added a test table pinning every spelling of every command, with and without its argument, including each usage text. It passed on the original code (29/29 module tests) and passes on the split.
  • New test no_spelling_is_listed_twice. The old match got this check from the compiler as an unreachable-pattern warning; a table does not.
  • Every existing test moved with its code and was not edited. None was removed or ignored.
  • Lib tests: 2264 before, 2268 after (4 added). The wiring ratchet passes at the same count.

Local gate (Windows): cargo fmt --all -- --check, cargo clippy --all-targets -q -- -D warnings, cargo test -q all pass.

…ange

The code auditor measured src/cli/slash_commands.rs at 2399 lines, fan-out
394, `SlashCommand::parse` at cyclomatic complexity 57 and `handle_roadmap`
at 112 lines.

- `parse` is now a lookup in `SPELLINGS`, a table of every spelling with
  the parser for its argument; the commands that need more than "keep the
  argument" (/rewind, /remember, /forget, /kill, /bg, /image) each have a
  named helper. No function in the module now exceeds complexity 20 or
  100 lines.
- `handle_roadmap` reads as its steps: `ready_brief` (the four gate
  outcomes, four messages), `mark_proven_done`, `say_what_cannot_prove`.
- The file is a module directory, one file per command family: parse,
  session, status, memory, agents, workspace, tools; mod.rs keeps the enum,
  COMMANDS and /help and re-exports every handler, so no caller changed.
  The largest file is agents.rs at 718 lines.

Equivalence: a table pinning every spelling of every command, with and
without its argument and each usage text, was added and passed on the
original code first, then on the split. A second test holds that no
spelling is listed twice, which the old `match` got from the compiler.
Every existing test moved with its code, unchanged.
@blockmandev
blockmandev merged commit 3c98a4f into main Oct 23, 2026
12 checks passed
@blockmandev
blockmandev deleted the refactor/slash-commands branch November 15, 2026 20:29
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.

1 participant