Problem
The init.ts action handler (src/cli/commands/init.ts:112-631) is 520+ lines with 10+ responsibilities:
- Version detection
- Scope determination (user/local)
- Interactive prompts (TTY handling)
- Plugin discovery and installation
- Registry updates
- Hook installation (memory, ambient, etc.)
- Working memory bootstrap
- Error handling and user feedback
Scope
This file is monolithic and violates single-responsibility principle. Extracting just 2-3 small blocks is insufficient. A proper refactor requires:
-
Phase functions - Decompose into ~5-7 phase handlers:
detectVersion() - Package version loading
determineScope() - User/local scope selection
selectPlugins() - Interactive plugin selection
installPlugins() - Plugin installation orchestration
setupHooks() - Memory and ambient hook installation
bootstrapMemory() - Working memory initialization
concludeInstallation() - Summary and next steps
-
Helper utilities - Extract reusable patterns:
- Registry update logic
- File system operations
- Error recovery and logging
-
Type safety - Define phase-to-phase contracts with Result types
Risk Assessment
- Risk Level: HIGH
- Why: The file is working and well-tested. Any refactor touches core installation logic
- Mitigation: Comprehensive test coverage already exists; refactor can be validated via existing test suite
Testing Strategy
- Keep all existing tests passing (no behavior changes)
- Add unit tests for new phase functions
- Integration test full installation flow end-to-end
Acceptance Criteria
Priority
Low - works well currently. Defer to post-v1.0.0 dedicated refactoring effort.
Problem
The
init.tsaction handler (src/cli/commands/init.ts:112-631) is 520+ lines with 10+ responsibilities:Scope
This file is monolithic and violates single-responsibility principle. Extracting just 2-3 small blocks is insufficient. A proper refactor requires:
Phase functions - Decompose into ~5-7 phase handlers:
detectVersion()- Package version loadingdetermineScope()- User/local scope selectionselectPlugins()- Interactive plugin selectioninstallPlugins()- Plugin installation orchestrationsetupHooks()- Memory and ambient hook installationbootstrapMemory()- Working memory initializationconcludeInstallation()- Summary and next stepsHelper utilities - Extract reusable patterns:
Type safety - Define phase-to-phase contracts with Result types
Risk Assessment
Testing Strategy
Acceptance Criteria
Priority
Low - works well currently. Defer to post-v1.0.0 dedicated refactoring effort.