From f87b4938ca4c9057fdffc1b1b37b396db5455aa4 Mon Sep 17 00:00:00 2001 From: Ryan Harrington Date: Mon, 16 Mar 2026 17:02:58 -0400 Subject: [PATCH] fix/gsd-bg-shell-stale-cwd: normalize bg-shell worktree cwd detection --- src/resources/extensions/bg-shell/utilities.ts | 4 +--- src/tests/bg-shell-persistence-cwd.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/resources/extensions/bg-shell/utilities.ts b/src/resources/extensions/bg-shell/utilities.ts index 9d534a2ee..284387d1d 100644 --- a/src/resources/extensions/bg-shell/utilities.ts +++ b/src/resources/extensions/bg-shell/utilities.ts @@ -4,7 +4,6 @@ import { createRequire } from "node:module"; import { existsSync } from "node:fs"; -import { sep } from "node:path"; // ── Windows VT Input Restoration ──────────────────────────────────────────── // Child processes (esp. Git Bash / MSYS2) can strip the ENABLE_VIRTUAL_TERMINAL_INPUT @@ -61,8 +60,7 @@ export function resolveBgShellPersistenceCwd( liveCwd = process.cwd(), pathExists: (path: string) => boolean = existsSync, ): string { - const worktreeMarker = `${sep}.gsd${sep}worktrees${sep}`; - const cachedIsAutoWorktree = cachedCwd.includes(worktreeMarker); + const cachedIsAutoWorktree = /(?:^|[\\/])\.gsd[\\/]worktrees[\\/]/.test(cachedCwd); if (!cachedIsAutoWorktree) return cachedCwd; if (cachedCwd === liveCwd && pathExists(cachedCwd)) return cachedCwd; if (!pathExists(cachedCwd)) return liveCwd; diff --git a/src/tests/bg-shell-persistence-cwd.test.ts b/src/tests/bg-shell-persistence-cwd.test.ts index f686beb28..f1277b1e7 100644 --- a/src/tests/bg-shell-persistence-cwd.test.ts +++ b/src/tests/bg-shell-persistence-cwd.test.ts @@ -27,6 +27,15 @@ test("rewrites mismatched auto-worktree cwd to live cwd even if old path still e ); }); +test("rewrites Windows-style auto-worktree cwd to live cwd", () => { + const cached = "C:\\repo\\.gsd\\worktrees\\M001"; + const live = "C:\\repo"; + assert.equal( + resolveBgShellPersistenceCwd(cached, live, () => true), + live, + ); +}); + test("keeps current auto-worktree cwd when it still matches process cwd", () => { const cached = "/repo/.gsd/worktrees/M001"; assert.equal(