Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/resources/extensions/gsd/worktree-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import type { ExtensionAPI, ExtensionCommandContext } from "@gsd/pi-coding-agent";
import { loadPrompt } from "./prompt-loader.js";
import { autoCommitCurrentBranch, getMainBranch, resolveGitHeadPath, nudgeGitBranchCache } from "./worktree.js";
import { runWorktreePostCreateHook } from "./auto-worktree.js";
import { runWorktreePostCreateHook, syncGsdStateToWorktree } from "./auto-worktree.js";
import { showConfirm } from "../shared/tui.js";
import { gsdRoot, milestonesDir } from "./paths.js";
import {
Expand Down Expand Up @@ -329,6 +329,9 @@ async function handleCreate(
ctx.ui.notify(hookError, "warning");
}

// Sync .gsd/ state from main into the new worktree (#3427)
syncGsdStateToWorktree(mainBase, info.path);

Comment on lines +332 to +334
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syncGsdStateToWorktree() is a no-op when the destination worktree doesn’t already have a .gsd/ directory (if (!existsSync(mainGsd) || !existsSync(wtGsd)) return). For manual worktree creation, .gsd/ is commonly untracked and therefore won’t exist in the freshly created worktree, which means this call may not actually bootstrap any state (the #3427 failure case). Consider creating/initializing the worktree-local .gsd/ directory (or reusing the auto-worktree planning-artifact seeding logic) before calling sync so /worktree create produces an immediately usable workspace.

Copilot uses AI. Check for mistakes.
Comment on lines +332 to +334
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change adds new behavior (bootstrapping .gsd/ during manual worktree creation) but doesn’t appear to be covered by tests. Since the repo already has worktree integration coverage (e.g. auto-worktree/worktree-manager tests), consider adding a regression test that creates a repo where .gsd/ is untracked in git, runs the manual create path, and asserts the new worktree contains the expected .gsd planning/state artifacts.

Copilot uses AI. Check for mistakes.
// Track original cwd before switching
if (!originalCwd) originalCwd = basePath;

Expand Down
4 changes: 4 additions & 0 deletions src/worktree-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface ExtensionModules {
worktreeBranchName: (name: string) => string
worktreePath: (basePath: string, name: string) => string
runWorktreePostCreateHook: (basePath: string, wtPath: string) => string | null
syncGsdStateToWorktree: (mainBasePath: string, worktreePath: string) => { synced: string[] }
nativeHasChanges: (path: string) => boolean
nativeDetectMainBranch: (basePath: string) => string
nativeCommitCountBetween: (basePath: string, from: string, to: string) => number
Expand All @@ -68,6 +69,7 @@ async function loadExtensionModules(): Promise<ExtensionModules> {
worktreeBranchName: wtMgr.worktreeBranchName,
worktreePath: wtMgr.worktreePath,
runWorktreePostCreateHook: autoWt.runWorktreePostCreateHook,
syncGsdStateToWorktree: autoWt.syncGsdStateToWorktree,
nativeHasChanges: gitBridge.nativeHasChanges,
nativeDetectMainBranch: gitBridge.nativeDetectMainBranch,
nativeCommitCountBetween: gitBridge.nativeCommitCountBetween,
Expand Down Expand Up @@ -381,6 +383,8 @@ async function createAndEnter(ext: ExtensionModules, basePath: string, name: str
process.stderr.write(chalk.yellow(`[gsd] ${hookError}\n`))
}

ext.syncGsdStateToWorktree(basePath, info.path)

process.chdir(info.path)
process.env.GSD_CLI_WORKTREE = name
process.env.GSD_CLI_WORKTREE_BASE = basePath
Expand Down
Loading