4 KiB
4 KiB
| estimated_steps | estimated_files |
|---|---|
| 5 | 1 |
T01: Fix worktree create ordering and add deterministic merge dispatch
Slice: S03 — Bug fixes and doc corrections Milestone: M001
Description
Fix two bugs in worktree-command.ts: (1) handleCreate() calls createWorktree() before autoCommitCurrentBranch(), meaning new worktrees fork from uncommitted HEAD — swap these so dirty state is committed first. (2) handleMerge() always dispatches to the LLM for merge even though mergeWorktreeToMain() exists as a deterministic helper — make the deterministic path the default, falling back to LLM only when a merge conflict occurs.
Steps
- Add imports: Import
mergeWorktreeToMainfrom./worktree-manager.jsandinferCommitTypefrom./git-service.jsat the top ofworktree-command.ts. - Fix handleCreate ordering (R007): Move the
autoCommitCurrentBranch(basePath, "worktree-switch", name)call to occur BEFOREcreateWorktree(mainBase, name). TheautoCommitCurrentBranchusesbasePath(current workspace), whilecreateWorktreeusesmainBase— no dependency conflict. - Add deterministic merge path in handleMerge (R008): After the confirmation prompt and CWD switch (where
process.chdir(basePath)already happens), insert a try/catch block that: (a) builds a conventional commit message usinginferCommitType(name)and the worktree name as scope/description, (b) callsmergeWorktreeToMain(basePath, name, commitMessage), (c) on success, notifies the user and returns early (skipping LLM dispatch). - Add conflict fallback: In the catch block for the deterministic merge, check if the error message indicates a merge conflict (contains "conflict" or "CONFLICT"). If so, run
git merge --abortto clean up, then fall through to the existing LLM dispatch path with a notification that deterministic merge failed due to conflicts. If the error is NOT a conflict, surface it to the user and return (don't fall back to LLM for non-conflict errors). - Verify: Run
npm run buildto confirm compilation. Rungrep -nto confirm ordering fix and presence of deterministic merge call.
Must-Haves
autoCommitCurrentBranch()call precedescreateWorktree()call inhandleCreate()mergeWorktreeToMain()attempted as first merge strategy inhandleMerge()- Commit message for deterministic merge uses
inferCommitType(name)for the type - Merge conflicts detected and handled:
git merge --abort+ LLM fallback - Non-conflict errors surfaced to user, not silently swallowed
npm run buildpasses
Verification
npm run buildcompletes without errorsgrep -n 'autoCommitCurrentBranch\|createWorktree' src/resources/extensions/gsd/worktree-command.ts— autoCommit line number < createWorktree line number in handleCreategrep -n 'mergeWorktreeToMain' src/resources/extensions/gsd/worktree-command.ts— appears in handleMerge functionnpm run test— existing tests still pass (4 pre-existing failures acceptable)
Observability Impact
- Signals added/changed:
ctx.ui.notifymessages for deterministic merge success, conflict fallback, and non-conflict errors - How a future agent inspects this: Read the notification messages in the TUI after a merge operation
- Failure state exposed: Conflict detection triggers a visible notification before LLM fallback; non-conflict errors show the error message directly
Inputs
src/resources/extensions/gsd/worktree-command.ts— current handleCreate (lines 348-390) and handleMerge (lines 572-710) implementationssrc/resources/extensions/gsd/worktree-manager.ts—mergeWorktreeToMain(basePath, name, commitMessage)at line 379src/resources/extensions/gsd/git-service.ts—inferCommitType(sliceTitle)at line 354- S03-RESEARCH.md — confirmed bug locations and existing function signatures
Expected Output
src/resources/extensions/gsd/worktree-command.ts— handleCreate has autoCommit before createWorktree; handleMerge attempts deterministicmergeWorktreeToMainbefore LLM dispatch with proper conflict handling