Skip to content

refactor(init): initCommand action handler 1704 lines #319

Description

@dean0x

Problem

src/cli/commands/init.ts:296-2000 — the initCommand action handler is a ~1,704-line monolithic function. This PR (PR #316) added ~28 executable lines to it (attribution wizard call site), pushing the function further into unmaintainability.

A function this large is difficult to test in isolation, hard to review, and resistant to incremental refactoring. Line count alone isn't the issue; architecture is: the Advanced prompt list, phase sequencing, and settings pass all live inline with zero separation of concerns.

Current Status

Expected Behavior

The function should be decomposed into separately testable units with clear responsibilities:

  1. Advanced prompt list construction (what prompts, in what order, with what defaults)
  2. Phase sequencing (flow through Recommended vs Advanced modes)
  3. Settings pass (applying wizard answers to settings.json)

Each unit should have unit tests that can run without invoking the full init command.

Suggested Sequencing

Phase 1: Extract the Advanced prompt list definition

  • Move prompt construction and phase sequencing into a separate module
  • Example: src/cli/commands/init-wizard.ts — pure definition, no I/O

Phase 2: Decompose the settings application logic

  • applyAttributionAnswer / applyCageAnswer patterns become a registry
  • Each setting has a dedicated apply_* function, tested independently

Phase 3: Reduce init.ts to a thin orchestrator

  • Call the wizard, get the answers, apply them, done
  • Line count target: <500 lines for the action handler

Acceptance Criteria

  • Prompt list extracted to separately testable module
  • Phase sequencing logic isolated with clear input/output contracts
  • Settings application decomposed into per-setting functions
  • initCommand line count reduced to <500
  • All new modules have unit test coverage
  • Existing e2e tests pass without modification
  • Code review surfaces no new regressions

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtTechnical debt items to address

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions