Remaining Cleanup Refactor Implementation Plan
For Claude: REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
Goal: Finish the remaining organization cleanup called out after the v2 refactor assessment.
Architecture: Keep behavior unchanged and split by responsibility, not by framework. The current command APIs stay stable; new modules should expose small helpers used by the existing command entrypoints.
Tech Stack: TypeScript, Commander, Vitest, better-sqlite3, fast-glob.
Scope#
Must-fix:
- Split
src/commands/topics.tsso read formatting, mutation workspace, and page rewrites are no longer buried in one file. - Add lightweight regression coverage for the CLI command surface so future registration splits cannot silently drop commands or options.
- Organize
setupandhookresponsibilities on top of the current working-tree behavior without reverting existing local edits.
Out of scope:
- Changing CLI behavior, command names, option semantics, output text, or topic DAG rules.
- Introducing a GUI architecture framework into the CLI.
- Rewriting setup/hook behavior beyond extracting named helpers.
Task 1: Topics Module Split#
Files:
- Modify:
src/commands/topics.ts - Create:
src/commands/topics/read.ts - Create:
src/commands/topics/workspace.ts - Create:
src/commands/topics/page-rewrite.ts
Steps:
- Move
TopicsShowRecord,pagesDirectlyTagged,pagesForSubtree, andformatShowintotopics/read.ts. - Move
TopicsWorkspace,resolveTopicsRepo,openFreshTopicsWorkspace,closeWorkspace, andtopicExistsintotopics/workspace.ts. - Move
rewriteTopicOnPagesintotopics/page-rewrite.ts. - Update imports in
topics.tsand keep all exported command functions intopics.ts. - Run
npm test -- test/topics.test.ts test/tag.test.tsandnpm run lint. - Commit as
refactor(v2): split topics helpers.
Task 2: CLI Command Surface Regression Test#
Files:
- Modify:
test/cli.test.ts
Steps:
- Add a test that instantiates
programthroughrun()with--helpor imports the registration shape indirectly. - Verify the expected command names remain present: query commands, edit commands, wiki lifecycle commands, setup commands, and hook subcommands.
- Verify representative options for renamed risk areas:
setup --yes,doctor --json,topics show --descendants,search --mentions,list --drop. - Keep the test broad but not brittle to help text wording.
- Run
npm test -- test/cli.test.tsandnpm run lint. - Commit as
test(v2): cover CLI command surface.
Task 3: Setup And Hook Responsibility Split#
Files:
- Modify:
src/commands/setup.ts - Modify:
src/commands/hook.ts - Create supporting files under
src/commands/setup/and/orsrc/commands/hook/only if the split clearly reduces the main file size. - Modify tests only if imports need updating or coverage catches a refactor regression.
Steps:
- Preserve the current working-tree behavior exactly, including stable hook copy, ephemeral install detection, ABI guard integration, and updated next steps.
- Extract setup install-path detection and global install spawning into a setup helper module.
- Extract setup next-step rendering/repo page counting into a setup helper module.
- Extract hook script resolution/stable copy into a hook helper module if it reduces
hook.tswithout scattering schema logic. - Keep settings JSON classification and mutation together unless a cleaner boundary emerges.
- Run
npm test -- test/setup.test.ts test/hook.test.ts test/init-helper.test.tsandnpm run lint. - Commit as
refactor(v2): split setup and hook helpers.
Final Verification#
Run:
npm testnpm run buildnpm run lint
Then request one review pass over the new commits. Fix and commit any must-fix or should-fix findings before final handoff.