refactor(cli): split the run() god-function into a dispatch table (H3)#104
Merged
Merged
Conversation
The former ~2,420-line run() (a flat 44-branch `if (cmd === …)` chain, 97% of src/cli.js) is now a ~44-line dispatcher: it looks the command up in a HANDLERS map and delegates. Each command is a module-scope `async (argv, cmd)` handler — independently navigable and mergeable, ending the merge-conflict-magnet problem. Behavior is byte-identical: same argv in, same stdout/stderr/exit-code out. The pre-dispatch middleware (--help interception, first-run hint, cortex-mcp), the unknown-command fallback, the process.exitCode error model, and the main-module import guard are all preserved. Handler signatures are trimmed to the params each body actually uses, so no unused-parameter warnings are introduced. Verified: full spawn-based suite 1069 pass / 0 fail / 2 skip, biome 0 errors, tsc 0 errors, `docs check` green, and importing the package root still does not execute the CLI. Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01C7htTiesXKLvAUtv6ET2jz
CodeWithJuber
marked this pull request as ready for review
July 20, 2026 15:04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Fixes H3 from the deep review — the 2,420-line
run()god-function insrc/cli.js(97% of the file; a flat 44-branch
if (cmd === …)chain the review flagged as"unreviewable, a merge-conflict magnet, boilerplate per new command").
run()is now a ~44-line dispatcher: it looks the command up in aHANDLERSmap anddelegates. Each command is a module-scope
async (argv, cmd)handler — independentlynavigable (jump to
HANDLERS.verify) and independently mergeable, which ends themerge-conflict-magnet problem.
Behavior is byte-identical. Same argv in → same stdout/stderr/exit-code out. The
contract the whole test estate relies on (35+ files spawn
node src/cli.js <args>andassert output/exit codes) is unchanged and green. Preserved exactly:
--help/-hinterception, first-run hint, thecortex-mcpserver exemption) runs before the table lookup;
process.exitCode(neverprocess.exit()) error model;not execute the CLI).
Handler signatures are trimmed to the params each body actually uses, so the refactor
introduces no unused-parameter warnings (biome stays at its baseline 10 warnings, 0
errors).
Checklist
npm testpasses (1069 pass / 0 fail / 2 gated skips)npm run checkpasses (Biome — 0 errors)CHANGELOG.mdupdated under## [Unreleased]Risk & rollback
Extra checks
npm run typecheckpassesnode src/cli.js docs checkgreen--help,brand,catalog,verify --json, unknown-command → exit 1🤖 Generated with Claude Code
https://claude.ai/code/session_01C7htTiesXKLvAUtv6ET2jz
Generated by Claude Code