Plan: Fix worktree reuse path destroying committed agent work#
Summary#
Remove git reset --hard origin/master from the worktree reuse path in WorktreeService.createWorktree(). The reset silently destroys agent commits made during prior phases (e.g., execute → address_review). The reuse path should only run git fetch origin to update remote refs, preserving the branch's existing HEAD.
Files#
| File | Action | Description |
|---|---|---|
src/worktree/worktree.service.ts | modify | Remove reset --hard origin/master from the worktreeReused block (lines 103-106); keep only git fetch origin |
src/worktree/worktree.service.spec.ts | modify | Update test at line 145 to assert reset --hard is NOT called on reuse; remove the assertion that expects the reset call |
Steps#
- In
src/worktree/worktree.service.ts, remove thegit reset --hard origin/masterexec call from theif (worktreeReused)block (lines 103-106). Keep thegit fetch origincall (line 103) and the surrounding log/comment. Remove or update the now-incorrect invariant comment (lines 98-102). - In
src/worktree/worktree.service.spec.ts, update the test'reuses an existing valid worktree without removal, runs fetch+reset'(line 145): rename to reflect fetch-only behavior, assert that NOresetcall is made (expect(resetCall).toBeUndefined()), and retain the assertion thatfetchis called in the worktree directory. - Run
npm run testandnpm run lintto verify all tests pass and no lint errors are introduced.
Verification#
- Unit test explicitly asserts
reset --hardis NOT called when a valid worktree is reused. - All existing worktree tests continue to pass (fresh create, invalid removal, branch attach paths unaffected).
npm run lintpasses with zero warnings.
Risks#
- None significant — the change is a 3-line deletion with a corresponding test update. The fresh-create and branch-attach paths are untouched.