You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(run): split 3,459-line monolith into focused modules #318
src/commands/run.ts has grown to 3,459 lines, mixing multiple concerns: worktree management, phase execution, state tracking, phase detection, and batch execution. Split into focused modules for maintainability.
Current State
The file contains 30+ functions spanning these concern areas:
Worktree management:ensureWorktree, ensureWorktrees, listWorktrees, getWorktreeChangedFiles, etc.
Phase execution:executePhase, executePhaseWithRetry, handlePhaseFailure, etc.
Phase detection/mapping:detectPhasesFromLabels, parseRecommendedWorkflow, determinePhasesForIssue, etc.
Batch/dependency handling:executeBatch, sortByDependencies, parseBatches, etc.
All symbols re-exported; no external code imports new module paths directly
AC-4
Original
All tests pass
MET
96/96 run.test.ts pass. 4 pre-existing timeout failures in state-utils.test.ts (unrelated)
AC-5
Original
No behavior changes (pure refactor)
MET
Pure extraction — no logic changes, test assertions unchanged
AC-6
Original
Proper TypeScript types and JSDoc
MET
All exported functions have JSDoc; 0 any types in diff
Coverage: 6/6 AC items fully met
CI Status
Check
State
Impact
build (18.x)
SUCCESS
✅ MET
build (20.x)
SUCCESS
✅ MET
build (22.x)
SUCCESS
✅ MET
validate-skills
SUCCESS
✅ MET
typecheck
SUCCESS
✅ MET
validate-plugin
SUCCESS
✅ MET
CI Summary: 6 passed, 0 failed
Quality Metrics
Metric
Value
Status
Type issues (any)
0
OK
Deleted tests
0
OK
Files changed
5
OK
Lines added
+3,029
-
Lines deleted
-2,892
-
Net change
+137
OK (module boilerplate)
Quality Plan Verification
N/A - No quality plan found in issue comments
Build Verification
N/A - Build passed (npm run build and tsc succeed)
Test Coverage Analysis
Changed File
Tier
Has Tests?
Test File
src/commands/run.ts
Standard
✅ Yes
src/commands/run.test.ts (96 tests)
src/lib/workflow/worktree-manager.ts
Standard
✅ Via re-export
Tested via run.test.ts
src/lib/workflow/phase-executor.ts
Standard
✅ Via re-export
Tested via run.test.ts
src/lib/workflow/phase-mapper.ts
Standard
✅ Via re-export
Tested via run.test.ts
src/lib/workflow/batch-executor.ts
Standard
✅ Via re-export
Tested via run.test.ts
Coverage: 5/5 changed files covered by existing tests Note: New modules don't have dedicated test files yet — all tested via run.test.ts re-exports
Code Review
Strengths:
Clean separation of concerns — each module has a clear responsibility
No circular dependencies (verified import hierarchy: worktree-manager → external only, phase-mapper → types only, batch-executor → imports from siblings)
All 32+ previously exported symbols properly re-exported from run.ts for backward compatibility
Good JSDoc coverage on all public APIs
Zero any types in the entire diff
Import hierarchy prevents tight coupling: batch-executor is the only module that imports siblings
Issues:
None found
Suggestions (non-blocking):
worktree-manager.ts at 1,323 lines is the largest extracted module — could be further split in a future pass (e.g., separate PR operations from worktree lifecycle)
Consider adding dedicated test files for each new module in a future PR to improve test isolation
Test Quality Review
N/A - No test files modified (run.test.ts unchanged, imports work via re-exports)
Anti-Pattern Detection
Code Patterns
No anti-patterns detected in changed files:
No hardcoded secrets
No SQL concatenation
No empty catch blocks
No await in loops (existing patterns preserved as-is)
Dependency Audit
N/A - No dependency changes
Call-Site Review
N/A - No new exported functions (all functions existed previously, just moved to new modules)
Execution Evidence
N/A - No executable script changes (pure refactor of library code)
Skill Command Verification
N/A - No skill files changed in this PR
CHANGELOG Verification
Result: N/A — Internal refactor with no user-facing changes
Self-Evaluation
Verified working: Yes — build passes, 96/96 run.test.ts pass, all CI green
Test efficacy: High — existing 96 tests cover the extracted functions via re-exports; same assertions, same mocks
Likely failure mode: If a future PR imports directly from a new module path instead of run.ts, and the module's internal imports change — but re-exports mitigate this
Verdict confidence: High — pure extraction refactor with no logic changes; comprehensive test coverage confirms behavior preserved
Verdict: READY_FOR_MERGE
Clean refactor that successfully splits a 3,740-line monolith into 5 focused files. All ACs met, all CI green, all tests pass, no behavior changes.
Documentation
N/A - No documentation needed (internal refactor, no new features or behavior changes)
This issue is a pure internal refactor — no user-facing behavior, CLI options, or output changed. Existing documentation in docs/reference/run-command.md remains accurate.
Activity
admarble commentedon Feb 22, 2026
Spec Review — Implementation Plan
AC Quality Check
run.tsreduced to < 1,000 linesSuggestions:
anyin exports, JSDoc with @param/@returns"Scope Assessment
Verdict:⚠️ SCOPE_WARNING — High AC count; Non-Goals missing
Suggested Non-Goals:
Acceptance Criteria with Verification
AC-1:
run.ts< 1,000 lineswc -l src/commands/run.tsAC-2: Single responsibility per module
worktree-manager.ts: 8-10 worktree functionsphase-executor.ts: 3-4 phase execution functionsphase-mapper.ts: 3-4 phase detection functionsbatch-executor.ts: 2-3 batch handling functionsAC-3: Existing exports preserved
AC-4: Tests pass
pnpm testAC-5: No behavior changes
AC-6: TypeScript types and JSDoc
grep -E "export.*: any"returns empty; JSDoc presentImplementation Plan
Phase 1: Create Module Scaffolding
Create
src/lib/workflow/worktree-manager.ts(~700 lines)slugify,getGitRoot,findExistingWorktree,checkWorktreeFreshness,removeStaleWorktree,listWorktrees,getWorktreeChangedFiles,getWorktreeDiffStats,ensureWorktree,ensureWorktrees,ensureWorktreesChainCreate
src/lib/workflow/phase-executor.ts(~400 lines)executePhase,executePhaseWithRetry,getPhasePrompt,PHASE_PROMPTSCreate
src/lib/workflow/phase-mapper.ts(~200 lines)detectPhasesFromLabels,parseRecommendedWorkflow,determinePhasesForIssue, label constantsCreate
src/lib/workflow/batch-executor.ts(~180 lines)executeBatch,parseBatches,sortByDependencies,parseDependenciesPhase 2: Wire Up Dependencies
5. Establish import hierarchy (no circular deps):
Phase 3: Refactor run.ts
6. Slim
runIssueWithLogging(519 → ~200 lines)7. Slim
runCommand(832 → ~400 lines)8. Add re-exports for backward compatibility
Phase 4: Test Updates
9. Update imports in test files
10. Run full test suite
Phase 5: Verification
11. Verify line counts
12. Confirm all tests pass
Assumptions to Validate
Recommended Workflow
Phases: spec → exec → qa
Quality Loop: enabled (auto-enabled due to scope + refactor label)
Reasoning: Large refactor benefits from QA verification
Conflict Analysis
Related Issues:
state-utils.tsrefactor (different file, no conflict)Existing Worktree:
/Users/tony/Projects/worktrees/feature/318-...(clean, no changes yet)refactor(#318): split run.ts monolith into focused modules
admarble commentedon Feb 22, 2026
Implementation Complete ✅
AC Coverage Summary
Files Changed
Modified:
src/commands/run.ts(950 lines, down from 3,740)Created:
src/lib/workflow/worktree-manager.ts(1,323 lines) - Git worktree lifecyclesrc/lib/workflow/phase-executor.ts(514 lines) - Phase execution with SDKsrc/lib/workflow/phase-mapper.ts(385 lines) - Label-based phase detectionsrc/lib/workflow/batch-executor.ts(705 lines) - Batch executionChecks
npm run build- Passesnpm run lint- Passesnpm test- 1447 tests passSelf-Evaluation
PR
Created PR #329: #329
admarble commentedon Mar 11, 2026
QA Review for Issue #318
AC Coverage
run.tsreduced to < 1,000 linesanytypes in diffCoverage: 6/6 AC items fully met
CI Status
build (18.x)build (20.x)build (22.x)validate-skillstypecheckvalidate-pluginCI Summary: 6 passed, 0 failed
Quality Metrics
any)Quality Plan Verification
N/A - No quality plan found in issue comments
Build Verification
N/A - Build passed (
npm run buildandtscsucceed)Test Coverage Analysis
src/commands/run.tssrc/commands/run.test.ts(96 tests)src/lib/workflow/worktree-manager.tsrun.test.tssrc/lib/workflow/phase-executor.tsrun.test.tssrc/lib/workflow/phase-mapper.tsrun.test.tssrc/lib/workflow/batch-executor.tsrun.test.tsCoverage: 5/5 changed files covered by existing tests
Note: New modules don't have dedicated test files yet — all tested via
run.test.tsre-exportsCode Review
Strengths:
run.tsfor backward compatibilityanytypes in the entire diffbatch-executoris the only module that imports siblingsIssues:
Suggestions (non-blocking):
worktree-manager.tsat 1,323 lines is the largest extracted module — could be further split in a future pass (e.g., separate PR operations from worktree lifecycle)Test Quality Review
N/A - No test files modified (run.test.ts unchanged, imports work via re-exports)
Anti-Pattern Detection
Code Patterns
No anti-patterns detected in changed files:
awaitin loops (existing patterns preserved as-is)Dependency Audit
N/A - No dependency changes
Call-Site Review
N/A - No new exported functions (all functions existed previously, just moved to new modules)
Execution Evidence
N/A - No executable script changes (pure refactor of library code)
Skill Command Verification
N/A - No skill files changed in this PR
CHANGELOG Verification
Result: N/A — Internal refactor with no user-facing changes
Self-Evaluation
run.ts, and the module's internal imports change — but re-exports mitigate thisVerdict: READY_FOR_MERGE
Clean refactor that successfully splits a 3,740-line monolith into 5 focused files. All ACs met, all CI green, all tests pass, no behavior changes.
Documentation
Next Steps
worktree-manager.ts(1,323 lines) in a future refactorQA completed: All acceptance criteria verified
refactor(#318): extract pr-operations, run-summary modules and add tests
refactor(#318): split run.ts monolith into focused modules
admarble commentedon Mar 12, 2026
Documentation Review Complete
This issue is a pure internal refactor — no user-facing behavior, CLI options, or output changed. Existing documentation in
docs/reference/run-command.mdremains accurate.Architecture Change:
src/commands/run.ts(3,865 lines)src/commands/run.ts(960 lines, orchestrator)src/lib/workflow/worktree-manager.ts(1,428 lines)src/lib/workflow/phase-executor.ts(493 lines)src/lib/workflow/phase-mapper.ts(209 lines)src/lib/workflow/batch-executor.ts(888 lines)Status:
No additional documentation generation required — all existing docs remain valid.
feat(cli): `sequant ready <issue>` — post-resolve A+ QA gate (#683) (#…
refactor(#318): split run.ts monolith into focused modules
refactor(#318): extract pr-operations, run-summary modules and add tests
feat(cli): `sequant ready <issue>` — post-resolve A+ QA gate (#683)