Plan: Return main repo to master after phase execution#
Summary#
After PhaseRouterService.executePhase() completes, the main repo checkout (/home/agent/repos/<repoName>) can be left on a feature branch when the phase ran without an isolated worktree. Add post-phase cleanup in the finally block to git checkout master when execution used the main repo directly.
Files#
| File | Action | Description |
|---|---|---|
src/worktree/worktree.service.ts | modify | Add resetToMaster(repo) method that runs git checkout master in the main repo path |
src/phase-router/phase-router.service.ts | modify | Call worktree.resetToMaster() in the finally block when no isolated worktree was created |
src/phase-router/phase-router.service.spec.ts | modify | Add tests: (1) resetToMaster called when no worktree, (2) resetToMaster failure logs warning without throwing |
src/worktree/worktree.service.spec.ts | modify | Add unit tests for the new resetToMaster() method |
Steps#
- S1: Add
resetToMaster()toWorktreeService— Add a public methodresetToMaster(repo: string)that resolvesREPOS_DIR, computesrepoPath, and runsgit checkout master. Wrap in try/catch: on failure, log a warning and return (never throw). - S2: Call
resetToMaster()inPhaseRouterService.executePhase()finally block — After the existing worktree cleanup (line ~437), add a new block: if!worktreePath(phase ran in main repo), callthis.worktree.resetToMaster(task.repo). Wrap in try/catch with warning log, same pattern as the worktree cleanup. - S3: Add unit tests — In
phase-router.service.spec.ts: test thatresetToMasteris called after a non-worktree phase completes, and that a thrown error is caught and logged. Inworktree.service.spec.ts: testresetToMastercallsgit checkout masterwith the correct cwd, and test that failures are swallowed with a warning log.
Verification#
npm run testpasses with new tests covering the reset-to-master pathnpm run lintpasses with zero warnings- Manual inspection:
resetToMasteris only called when!worktreePath(main repo execution), never for isolated worktree phases
Risks#
- If the main repo has uncommitted changes,
git checkout masterwill fail — mitigated by catching the error and logging a warning (acceptance criterion)