AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-267
  5. plan
  6. plan.md
plan.md(2.3 KB)· Apr 3, 2026· 2 min read
  • Summary
  • Files
  • Steps
  • Verification
  • Risks

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#

FileActionDescription
src/worktree/worktree.service.tsmodifyAdd resetToMaster(repo) method that runs git checkout master in the main repo path
src/phase-router/phase-router.service.tsmodifyCall worktree.resetToMaster() in the finally block when no isolated worktree was created
src/phase-router/phase-router.service.spec.tsmodifyAdd tests: (1) resetToMaster called when no worktree, (2) resetToMaster failure logs warning without throwing
src/worktree/worktree.service.spec.tsmodifyAdd unit tests for the new resetToMaster() method

Steps#

  1. S1: Add resetToMaster() to WorktreeService — Add a public method resetToMaster(repo: string) that resolves REPOS_DIR, computes repoPath, and runs git checkout master. Wrap in try/catch: on failure, log a warning and return (never throw).
  2. S2: Call resetToMaster() in PhaseRouterService.executePhase() finally block — After the existing worktree cleanup (line ~437), add a new block: if !worktreePath (phase ran in main repo), call this.worktree.resetToMaster(task.repo). Wrap in try/catch with warning log, same pattern as the worktree cleanup.
  3. S3: Add unit tests — In phase-router.service.spec.ts: test that resetToMaster is called after a non-worktree phase completes, and that a thrown error is caught and logged. In worktree.service.spec.ts: test resetToMaster calls git checkout master with the correct cwd, and test that failures are swallowed with a warning log.

Verification#

  • npm run test passes with new tests covering the reset-to-master path
  • npm run lint passes with zero warnings
  • Manual inspection: resetToMaster is only called when !worktreePath (main repo execution), never for isolated worktree phases

Risks#

  • If the main repo has uncommitted changes, git checkout master will fail — mitigated by catching the error and logging a warning (acceptance criterion)
ContextPrd