CLI Refactor Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Make the CLI entrypoint easier to read by moving command wiring and help formatting into named modules without changing command behavior.
Architecture: Keep src/cli.ts as the process-level entrypoint: invocation-name handling, update scheduling, setup shortcut routing, and program.parseAsync. Move Commander registration into src/cli/register-commands.ts, shared CLI helpers into src/cli/helpers.ts, and root help rendering into src/cli/help.ts. Do not introduce a framework, domain layer, or new runtime behavior.
Tech Stack: TypeScript, Commander, Vitest.
Task 1: Extract Shared CLI Helpers#
Files:
- Create:
src/cli/helpers.ts - Modify:
src/cli.ts
Steps:
- Move
emit,collectOption,parsePositiveInt, andreadStdinintosrc/cli/helpers.ts. - Export a small
CommandResultinterface fromsrc/cli/helpers.ts. - Import helpers from
src/cli.ts. - Run
npm run lint.
Task 2: Extract Help Rendering#
Files:
- Create:
src/cli/help.ts - Modify:
src/cli.ts
Steps:
- Move
HELP_GROUPS,configureGroupedHelp, and the default subcommand help renderer intosrc/cli/help.ts. - Keep the existing ANSI formatting and Commander behavior unchanged.
- Import
configureGroupedHelpfromsrc/cli.ts. - Run
npm test -- test/cli.test.ts.
Task 3: Extract Command Registration#
Files:
- Create:
src/cli/register-commands.ts - Modify:
src/cli.ts
Steps:
- Move all
program.command(...)wiring intoregisterCommands(program). - Keep command actions calling the same command modules with the same option mapping.
- Keep
src/cli.tsresponsible for creating theCommand, configuring metadata, setup shortcut routing, grouped help, and parsing. - Run
npm test -- test/cli.test.ts.
Task 4: Verify Full Baseline#
Commands:
npm run lintnpm test
Expected: TypeScript passes and the full Vitest suite remains green.