Skip to content

TypeScript hooks start under a Windows home with an apostrophe, or with MSYS path conversion off - #4386

Closed
abyss-node wants to merge 1 commit into
garrytan:mainfrom
abyss-node:fix/windows-apostrophe-hooks
Closed

abyss-node wants to merge 1 commit into
garrytan:mainfrom
abyss-node:fix/windows-apostrophe-hooks

Conversation

@abyss-node

Copy link
Copy Markdown
Contributor

TypeScript hooks start under a Windows home with an apostrophe, or with MSYS path conversion off

Root cause

Git Bash rewrites a /c/x argument to C:/x when it starts a native program. msys2-runtime skips that rewrite for any argument that contains ` ' * ? [ ] (winsup/cygwin/msys2_path_conv.cc). It skips every argument when MSYS_NO_PATHCONV=1 or MSYS2_ARG_CONV_EXCL=* is set.

Each TypeScript hook shim builds HERE with pwd, which gives /c/x, and runs bun "$HERE/<hook>.ts". bun.exe cannot open /c/x: it reports Module not found, and Bun.build throws EINVAL: failed to open root directory. gstack-hook-check hands Bun its entries in the same /c/x spelling.

So under a home such as C:\Users\O'Brien:

  • All 13 shims die before their entry runs. The /autoplan Read barrier returns its "Publication hook unavailable" deny on every Read.
  • gstack-hook-check reports all 12 registered TypeScript hooks as bun could not bundle the TypeScript entry, so setup's hook-registration gate would refuse them (inferred from that gate's own tests; ./setup itself was not run under an apostrophe home).

Who is affected

Git Bash or MSYS2 users on Windows are affected in two cases:

  • The gstack path contains ', `, [, ] or ;. I tested each character by passing /c/a<char>b/x to bun.exe. Spaces, ( ) & # ! $ % @ { } = + ^ , ~ " and the rest were all rewritten. Windows file names cannot contain * or ?.
  • Path conversion is turned off with MSYS_NO_PATHCONV=1 or MSYS2_ARG_CONV_EXCL=*, which Docker users often set. This breaks every path, apostrophe or not: the unfixed checker failed all 12 hooks on a plain C:\gsp-ctl root.

Cygwin never rewrites arguments, so I expect it to fail on every path. I have not tested it.

Fix

The fix is one mechanism, placed where each path is created:

  • Shims: after HERE is set, each shim converts it with cygpath -m:
    case "${OSTYPE:-}" in msys*|cygwin*) if command -v cygpath >/dev/null 2>&1; then HERE="$(cygpath -m "$HERE")"; fi ;; esac
    This runs under the same OSTYPE/cygpath test that already sets GSTACK_BUN_CONFIG. It does nothing off a Windows bash or when cygpath is missing. phase-publication-hook uses the same line with its _AUTOPLAN_HOOK_DIR.
  • bin/gstack-hook-check: passes BUN_ENTRIES=$(cygpath -m $ENTRIES) to Bun under the same test. shellPath already maps Bun's C:/x output back to the /c/x keys the checker looks up.

The line is written into each shim rather than kept in a shared helper. This follows GSTACK_BUN_CONFIG, which is also one fixed line per shim, and keeps hook-check self-contained so it can still check an extracted archive. Calling a helper would add a uname plus a cygpath process to every hook run, and these shims run on every prompt and tool call. The inline line adds a single cygpath (about 25 ms), and only on Windows.

AGENTS.md states the rule for new shims.

Tests (test/setup-hook-syntax-gate.test.ts, already in the Windows lane)

  • entries bundle in a root Git Bash does not convert: runs hook-check on a fixture root named hook root o'brien. On Windows it runs both as-is and with MSYS_NO_PATHCONV=1. On POSIX it runs in a simulated Windows bash: OSTYPE=msys, a fake cygpath, and a fake bun that rejects the unconverted spelling the way bun.exe does.
  • every shim that runs TypeScript starts its entry …: copies every hook shim that runs a TypeScript entry into that root, 13 today (the registered ones plus memorable-user-prompt-hook). Each entry is replaced by a stub, and each shim must exit 0 and print entry ran. It uses the same real-or-simulated environment.

The space in the fixture root is needed on Windows. It makes Bun quote the path when it starts bash; without quotes, MSYS reads a bare ' in its command line as a quote character (see "Not fixed here").

run without fix with fix
Windows 11, Git Bash, bun 1.4.4-canary, whole file, --timeout 120000 15 pass, 5 fail 17 pass, 3 fail
Linux (WSL2 Ubuntu), bun 1.4.4, whole file 20 pass, 2 fail (the new tests) 22 pass, 0 fail

On Windows the two new tests are the only difference between the runs. The other 3 failures happen with and without the fix: the test harness writes BUN_CMD='<bun path>' in single quotes, and on the test machine the bun path itself contains an apostrophe. On Linux, the shell-caller ratchet in test/bun-entry-isolation.test.ts (run with -t "shell callers|detector|config-definition") passes 4/4; the whole file gives 7 pass, 3 fail on the partial tree used here, identically with and without the fix, and test/ceo-mode-handoff-hook.test.ts (which runs the real shim) passes 4/4.

Before/after on a real install under a home with an apostrophe (Windows 11, Git Bash)

The test tree is gstack v1.91.101.0 with the upstream 0326b14 hook subsystem copied over it: setup, the 13 shims, the hook-check, and every TypeScript entry with its local imports. <root> stands for /c/Users/<me>'/…/root.

Upstream bin/gstack-hook-check <root> exits 1:

ok bin/gstack-session-update
fail hosts/claude/hooks/question-log-hook <root>/hosts/claude/hooks/question-log-hook.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/question-preference-hook <root>/…/question-preference-hook.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/auq-error-fallback-hook <root>/…/auq-error-fallback-hook.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/timeline-stop-hook <root>/…/timeline-stop-hook.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/skill-route-hook <root>/…/skill-route-hook.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/skill-contract-stop-hook <root>/…/skill-contract-stop-hook.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/ceo-review-gate-stop <root>/…/ceo-review-gate.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/ceo-review-gate-subagent-stop <root>/…/ceo-review-gate.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/autoplan-stop-gate-stop <root>/…/autoplan-stop-gate.ts:1: bun could not bundle the TypeScript entry
fail hosts/claude/hooks/autoplan-stop-gate-publish <root>/…/autoplan-stop-gate.ts:1: bun could not bundle the TypeScript entry
fail autoplan/bin/phase-publication-hook <root>/autoplan/bin/phase-publication-hook.ts:1: bun could not bundle the TypeScript entry
ok careful/bin/check-careful.sh
ok freeze/bin/check-freeze.sh
fail plan-ceo-review/bin/mode-handoff-hook <root>/plan-ceo-review/bin/mode-handoff-hook.ts:1: bun could not bundle the TypeScript entry

The same bytes reached through a junction with no apostrophe (C:\gsp-ctl) give 15 ok and exit 0.

With the fix, the checker prints 15 ok, 0 fail, and exits 0. It does the same with MSYS_NO_PATHCONV=1 and with MSYS2_ARG_CONV_EXCL=*. A TypeScript syntax error planted under that root is still caught: fail plan-ceo-review/bin/mode-handoff-hook <root>/…/mode-handoff-hook.ts:35: Unexpected ;.

Each shim was run through /bin/sh -c '<root>/<shim>' with hook JSON on stdin:

SHIM                                           BEFORE                                         AFTER
plan-ceo-review/bin/mode-handoff-hook          1  Module not found ".../mode-handoff-hook.ts"  0  {"systemMessage":"Auto-decided review mode → HOLD SCOPE (your preference). …"}
hosts/claude/hooks/question-log-hook           1  Module not found                             0
autoplan/bin/phase-publication-hook            1  deny "Publication hook unavailable"           0  the .ts's own decision (identical through the no-apostrophe junction)
hosts/claude/hooks/auq-error-fallback-hook     1  Module not found                             0  {"hookSpecificOutput":{"hookEventName":"PostToolUse"}}
hosts/claude/hooks/question-preference-hook    1  Module not found                             0
timeline-stop, memorable-user-prompt, skill-route, skill-contract-stop,
ceo-review-gate-stop, ceo-review-gate-subagent-stop,
autoplan-stop-gate-stop, autoplan-stop-gate-publish   0  Module not found (fail-open)  0  no error

After the fix, every row at the apostrophe root matches the same run through the junction.

Off Windows, the line does nothing. With HERE=/home/o'brien/.claude/skills/gstack/plan-ceo-review/bin, HERE is unchanged under OSTYPE=linux-gnu or darwin23, with or without cygpath on PATH, and under OSTYPE=msys or cygwin with no cygpath. It becomes C:/… only under msys or cygwin with cygpath present.

Not fixed here (found while proving this)

  1. bun → bash argument passing. When Bun starts a bash script through lib/script-invocation.ts (runScriptSync), the MSYS runtime parses bash's Windows command line and treats a bare ' as a quote. Node and Bun only add quotes around an argument that has a space or a ". So C:/Users/O'Brien/…/bin/gstack-question-log plus its JSON argument reach bash as a single word, minus the apostrophe, and bash exits 127. With this fix, question-log-hook now runs, but this spawn still fails. timeline-stop-hook (gstack-slug: exit 127) and memorable-user-prompt-hook (gstack-config get … failed) fail at their own spawns, which looks like the same bug but I have not traced them.
  2. Shell bins that hand Bun a path. Examples: GSTACK_LIB_DIR="$SCRIPT_DIR/../lib" bun -e …, bun "$BIN/…ts", and bun run gen:skill-docs --out-dir "$RENDER_TMP". MSYS leaves environment values with an apostrophe unconverted too. Native Bun then resolves /c/Users/O'Brien/x as C:\c\Users\O'Brien\x. On the test machine, 406 files (skill renders render/claude.tmp.<pid> and .brain-sync-status.json) sit in C:\c\Users\<me>'\.gstack, which is where native Bun resolves /c/Users/<me>'/.gstack. They were all written before these test runs.
  3. Bun-shebang bins run by absolute path, for example ~/.claude/skills/gstack/bin/gstack-decision-log --help, fail with Module not found "/c/Users/…". Running the same bin from its directory (./gstack-decision-log) works.
  4. setup's own bun "$SOURCE_GSTACK_DIR/…" calls pass the same /c/x paths. I have not run setup under such a home.

Each of these needs its own change, and items 1 and 3 need changes outside the shims.

Not verified

  • The full test suite: the network only allowed fetching single files through the GitHub API, so every run used a partial upstream tree of 162 files.
  • macOS: the simulated-bash tests call realpath on their root because macOS /var is /private/var, but they have not run there.
  • Cygwin.

…th MSYS path conversion off

Git Bash rewrites a /c/x argument to C:/x when it starts a native program,
but msys2-runtime leaves any argument holding ' ` [ ] unconverted
(winsup/cygwin/msys2_path_conv.cc), and MSYS_NO_PATHCONV=1 leaves them all.
Every TypeScript hook shim spells its own directory with pwd, so bun.exe got
/c/x, which it cannot open. Under a home such as C:\Users\O'Brien all 13
shims died with "Module not found" before their entry ran (the /autoplan Read
barrier answered every Read with its "hook unavailable" deny), and
gstack-hook-check reported all 12 registered TypeScript hooks as "bun could
not bundle the TypeScript entry", so setup refused to register them.

Each shim now converts its directory with cygpath -m under the OSTYPE and
cygpath test that already picks GSTACK_BUN_CONFIG, and gstack-hook-check
hands Bun its entries the same way. Off a Windows bash, or with no cygpath on
PATH, both are no-ops. test/setup-hook-syntax-gate.test.ts runs the checker
and every TypeScript hook shim from a root with an apostrophe: for real on
Windows (also with MSYS_NO_PATHCONV=1), and through a simulated Windows bash
on POSIX. AGENTS.md states the rule for new shims.

Verified: upstream bin/gstack-hook-check on a gstack tree under a home with an apostrophe (Windows 11, Git Bash) -> exit 1, 12 of 12 TypeScript hooks fail; same tree through a junction with no apostrophe -> exit 0, 15 ok
Verified: fixed bin/gstack-hook-check on that tree -> exit 0, 15 ok, 0 fail; also with MSYS_NO_PATHCONV=1 and with MSYS2_ARG_CONV_EXCL=* -> 15 ok, 0 fail
Verified: fixed checker with a planted TypeScript syntax error under the same root -> exit 1, fail <file>.ts:35: Unexpected ;
Verified: all 13 shims run through /bin/sh -c with hook JSON on stdin -> before 13/13 "Module not found"; after 13/13 exit 0, rows identical to the no-apostrophe junction, mode-handoff-hook prints its systemMessage
Verified: bun test --timeout 120000 test/setup-hook-syntax-gate.test.ts on Windows (bun 1.4.4-canary) -> fixed 17 pass 3 fail, unfixed 15 pass 5 fail; the two new tests are the only difference
Verified: bun test test/setup-hook-syntax-gate.test.ts on Linux (WSL2 Ubuntu, bun 1.4.4) -> fixed 22 pass 0 fail; unfixed 20 pass, the two new tests fail
Verified: bun test test/bun-entry-isolation.test.ts -t "shell callers|detector|config-definition" and test/ceo-mode-handoff-hook.test.ts on Linux -> 4/4 and 4/4 pass
Verified: the conversion line under OSTYPE=linux-gnu or darwin23, and under OSTYPE=msys with no cygpath on PATH -> HERE unchanged
Unverified: the full suite; the runs used a 162-file partial upstream tree (git clone of the repo was not possible on this network)
Unverified: the 3 Windows setup-section failures, present with and without this change, come from the harness single-quoting a bun path that itself holds an apostrophe on the test machine
Unverified: macOS and Cygwin runs; the simulated-bash tests realpath their root for macOS /private/var
@trunk-io

trunk-io Bot commented Nov 15, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Thank you for the careful root-cause work and the simulated Windows bash in the test. Windows has minimal support in gstack, but we do keep hooks and startup working there, and this breaks every TypeScript hook for anyone with path conversion off or an apostrophe in their path. So we're taking it as a small fix: a maintainer agent will rebuild it on current main with you credited as co-author, and close this PR with a link once it lands. The rebuild will likely leave out the AGENTS.md line and keep the change to the hook shims, bin/gstack-hook-check and the test. It's queued behind other finished work, so it may take a few days.

@capy-ai capy-ai Bot added bug Something isn't working S3 Severity 3: everything else labels Nov 15, 2026
@abyss-node

Copy link
Copy Markdown
Contributor Author

Checked current main (f71e785, 1.102.1.0) on Windows under a home path with an apostrophe: ./setup still exits 1 at the first step (Module not found .../scripts/preflight-codex-overlap.ts), and gstack-hook-check fails 10 of 12 hooks with "bun could not bundle the TypeScript entry". The same tree under a plain path passes both. Happy to rebase this PR onto main if that's easier than the rebuild. Is it still in the queue?

@capy-ai capy-ai Bot added S2 Severity 2: broken workflow with no workaround and removed S3 Severity 3: everything else labels Nov 22, 2026
@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thanks for checking current main on Windows, and sorry for the wait. Yes, it's still queued, and it's now the first item in a batch of fixes a maintainer agent is starting (our tracking thread GSTA-801). We've labelled it S2 because ./setup and the TypeScript hooks fail outright for anyone whose Windows home path contains an apostrophe. The agent will first reproduce it on current main. If it reproduces, the agent rebuilds the hook-shim, gstack-hook-check and test change on main with you credited as co-author, leaving out the AGENTS.md line, and we'll close this PR with a link when it lands. No need to rebase: we don't merge outside branches directly, so the rebuild is the route. If it no longer reproduces, we'll close this and say what changed.

@abyss-node

Copy link
Copy Markdown
Contributor Author

Thanks! One note for the repro: #4386 only covers the hooks. On current main, ./setup also fails under an apostrophe home path, at its first step (Module not found .../scripts/preflight-codex-overlap.ts), because bun_cmd() and the preflight call pass /c/... paths straight to bun. The fix is the same: convert the paths with cygpath -m on Windows. Happy to open a separate issue if that's easier to track.

@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thank you for the root-cause work and the simulated Git Bash test. A rebuild of this landed on main in #4682, with you credited as co-author. Every TypeScript hook shim and gstack-hook-check now hand Bun a cygpath -m path, and ./setup turns Git Bash's path conversion back on for the programs it starts, which fixes the MSYS_NO_PATHCONV=1 case. One gap remains: under a home folder with an apostrophe, ./setup still passes Bun unconverted paths at a few call sites. We'll run setup on a Windows runner with such a home and post here with what that fixes. I'm closing this PR in favour of the merged one.

@capy-ai capy-ai Bot closed this Nov 22, 2026
garrytan added a commit that referenced this pull request Nov 26, 2026
…rophe (#4386)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
garrytan added a commit that referenced this pull request Nov 26, 2026
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
garrytan added a commit that referenced this pull request Nov 26, 2026
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
capy-ai Bot added a commit that referenced this pull request Nov 26, 2026
…4386) (#4845)

`./setup` on Windows now installs when your home folder has an
apostrophe in its name, such as `C:\Users\O'Brien`.

Git Bash turns `/c/...` paths into `C:/...` before starting Bun, but
skips any path holding an apostrophe, so setup stopped with `Module not
found`.

Nothing to do: re-run `./setup` after upgrading.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
@capy-ai

capy-ai Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Follow-up: the rest of this is now fixed on main in #4845. We ran ./setup on a Windows runner with the home folder at …/o'brien/…. On the old main it stopped with error: Module not found, because Git Bash skips its /c/… to C:/… conversion for any path holding an apostrophe, so Bun got a path it can't open. Setup now converts every path it hands Bun itself (cygpath -m), and the same run now installs, starts the core skills and runs /browse.

Four smaller spots still pass unconverted paths under such a home folder, and they're out of scope under our minimal Windows support policy: the one-time migration of old gstack-claude wrappers, the gbrain skill render, gbrain detection, and a theoretical setup stop if cygpath itself fails. None of them blocks install, startup or the core skills, and none loses data. If one of them bites you, please open a new issue with the output. Thanks again for the original report and fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working S2 Severity 2: broken workflow with no workaround

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant