Skip to content

refactor(#318): split run.ts monolith into focused modules - #329

Closed
admarble wants to merge 1 commit into
mainfrom
feature/318-refactor-run-split-3-459-line-monolith-into-focuse
Closed

admarble wants to merge 1 commit into
mainfrom
feature/318-refactor-run-split-3-459-line-monolith-into-focuse

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

  • Extract 2,892 lines from 3,740-line run.ts into 4 focused modules
  • run.ts: 950 lines (down from 3,740) - maintains backward compatibility via re-exports
  • worktree-manager.ts (1,323 lines): Git worktree lifecycle operations
  • phase-executor.ts (514 lines): Phase execution with Claude Agent SDK
  • phase-mapper.ts (385 lines): Label-based phase detection
  • batch-executor.ts (705 lines): Batch and sequential execution

Pre-PR AC Verification

AC Description Status Evidence
AC-1 run.ts reduced to < 1,000 lines ✅ Implemented 950 lines (wc -l src/commands/run.ts)
AC-2 Each extracted module has single responsibility ✅ Implemented 4 modules with focused concerns
AC-3 Existing exports continue to work (backward compatibility) ✅ Implemented Re-exports in run.ts
AC-4 All tests pass ✅ Implemented 1447 tests pass
AC-5 No behavior changes (pure refactor) ✅ Implemented Same function signatures
AC-6 Proper TypeScript types and JSDoc ✅ Implemented JSDoc headers on all modules

Test plan

  • npm run build passes
  • npm run lint passes
  • npm test passes (1447 tests)
  • Line count verified under 1,000

Closes #318

🤖 Generated with Claude Code

Extract 2,892 lines from 3,740-line run.ts into 4 focused modules:

- worktree-manager.ts (1,323 lines): Git worktree lifecycle operations
  - Worktree creation, cleanup, and health checks
  - PR creation and rebase handling
  - Diff stats and cache metrics

- phase-executor.ts (514 lines): Phase execution with Claude Agent SDK
  - Phase prompts and execution
  - Cold-start retry logic with MCP fallback
  - QA verdict parsing

- phase-mapper.ts (385 lines): Label-based phase detection
  - UI/bug/docs/complex label recognition
  - Recommended workflow parsing from spec output
  - Dependency sorting (topological sort)

- batch-executor.ts (705 lines): Batch and sequential execution
  - runIssueWithLogging orchestration
  - Quality loop iteration
  - Batch result aggregation

run.ts is now 950 lines (down from 3,740), maintaining backward
compatibility via re-exports.

Closes #318

Entire-Checkpoint: 1144d8c1980c
@admarble

Copy link
Copy Markdown
Contributor Author

Closing — will redo after merging other PRs

This refactor PR has accumulated merge conflicts with main (which still has the 3,767-line monolith). Every open PR likely touches run.ts, so merging this first would create cascading conflicts for #336, #338, #342, #345, #346.

Plan:

  1. Merge all open feature PRs first
  2. Re-run the refactor fresh on the settled monolith
  3. Include the improvements identified during QA:
    • Split worktree-manager.ts → worktree-manager.ts + pr-operations.ts
    • Extract metrics/summary → run-summary.ts
    • Add dedicated test files for each module (51 additional tests)
    • Target all modules under 850 lines

The refactor is mechanical and faster to redo than to resolve N merge conflicts.

Issue #318 remains open for the redo.

@admarble admarble closed this Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(run): split 3,459-line monolith into focused modules

1 participant