From 1333f08077691c9a6c830bca2e4a95531edc55bc Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 00:45:18 +1100 Subject: [PATCH 01/10] test(hook-check): give the setup hook cases explicit budgets The three cases in test/setup-hook-syntax-gate.test.ts that run setup's hook sections had no budget of their own: a bare `bun test` gives each 5 s (the free runner gives 30 s). The upgrade case runs them twice and took 3.2 s on main at a load average near 47; each run parses every hook and bundles its TypeScript, so its time grows with the hook list. Each case now gets 120 s. No assertion changes. Co-Authored-By: Claude Opus 5.5 --- test/setup-hook-syntax-gate.test.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/setup-hook-syntax-gate.test.ts b/test/setup-hook-syntax-gate.test.ts index 4ab68650976..4374c3f2c08 100644 --- a/test/setup-hook-syntax-gate.test.ts +++ b/test/setup-hook-syntax-gate.test.ts @@ -213,6 +213,11 @@ describe('setup: registers the hooks that parse, refuses the rest, exits non-zer const shim = (fx: Fx, rel: string) => path.join(fx.canonical, rel); const ALL = ['bin/gstack-session-update', 'hosts/claude/hooks/question-log-hook', 'hosts/claude/hooks/question-preference-hook', 'hosts/claude/hooks/auq-error-fallback-hook', 'hosts/claude/hooks/timeline-stop-hook']; + // Each case runs the hook sections once or twice, and each run parses every + // hook and bundles its TypeScript. A run took 2.5 s at load 48, so a case + // that runs it twice can pass a bare `bun test`'s 5 s default (the free + // runner allows 30 s). + const SETUP_HOOKS_TEST_MS = 120_000; test('healthy install registers every hook and finishes', () => { const fx = setupFixture(); @@ -221,7 +226,7 @@ describe('setup: registers the hooks that parse, refuses the rest, exits non-zer expect(r.code).toBe(0); expect(r.out).not.toContain('refusing to register'); expect(registeredCommands(fx)).toEqual(ALL.map(rel => shim(fx, rel)).sort()); - }); + }, SETUP_HOOKS_TEST_MS); test('fresh install: the unparseable hook is not registered, the rest are, and setup exits 1 with file:line', () => { const fx = setupFixture(); @@ -240,7 +245,7 @@ describe('setup: registers the hooks that parse, refuses the rest, exits non-zer expect(r.out).not.toContain('previous install is still active'); expect(r.out).not.toContain('no stable install'); expect(registeredCommands(fx)).toEqual(ALL.filter(rel => rel !== 'hosts/claude/hooks/question-log-hook').map(rel => shim(fx, rel)).sort()); - }); + }, SETUP_HOOKS_TEST_MS); test('upgrade over live registrations: the others stay registered, the broken one is not re-registered, exit 1', () => { const fx = setupFixture(); @@ -257,5 +262,5 @@ describe('setup: registers the hooks that parse, refuses the rest, exits non-zer expect(r.out).toContain('keeps running the broken file until it is fixed'); expect(r.out).not.toContain('previous install is still active'); expect(registeredCommands(fx)).toEqual(before); - }); + }, SETUP_HOOKS_TEST_MS); }); From 761eeeb0069f44d329a7590831aafe5d9b82eb11 Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 00:45:43 +1100 Subject: [PATCH 02/10] fix(hook-check): check the hooks skills register in their frontmatter Claude Code registers a skill's frontmatter `hooks:` while the skill is active, so a skill hook that does not parse fails exactly like a broken setup hook (a PreToolUse one blocks the tool call). gstack-hook-check only listed the hooks setup registers plus a hard-coded /autoplan hook, so three skill hooks went unchecked: - careful/bin/check-careful.sh (/careful, /guard) - freeze/bin/check-freeze.sh (/freeze, /guard, /investigate) - plan-ceo-review/bin/mode-handoff-hook (/plan-ceo-review) The list now takes every gstack path named on a `command:` line in the YAML frontmatter of SKILL.md and each /SKILL.md, which also finds the /autoplan hook it used to name by hand: 9 hooks, up from 6. setup and the auto-updater already report a failing skill hook ("or that a skill file runs, keeps running the broken file"), so neither changes. The list-equality test derives the frontmatter hooks independently, the fixture tree carries each hook-bearing skill's frontmatter, and a broken /freeze check now fails with its file and line. docs/troubleshooting.md names the skill hooks. Both tests fail against the previous checker. Co-Authored-By: Claude Opus 5.5 --- bin/gstack-hook-check | 35 ++++++++++++++++++--- docs/troubleshooting.md | 13 +++++--- test/setup-hook-syntax-gate.test.ts | 49 ++++++++++++++++++++++++++--- 3 files changed, 83 insertions(+), 14 deletions(-) diff --git a/bin/gstack-hook-check b/bin/gstack-hook-check index 3601e8d47af..5c299b03e1e 100755 --- a/bin/gstack-hook-check +++ b/bin/gstack-hook-check @@ -13,9 +13,13 @@ # # The hook list comes from the registration code: every # `_hook_command_path ` argument in /setup (or the setup named by -# --setup, when another tree's setup registers 's hooks), plus the autoplan -# phase-publication hook (registered by its skill frontmatter). -# test/setup-hook-syntax-gate.test.ts keeps the two equal. +# --setup, when another tree's setup registers 's hooks), plus every +# gstack path a skill's frontmatter hook command runs (/SKILL.md and +# /*/SKILL.md: /autoplan's phase-publication hook, and the /careful and +# /freeze checks that /guard and /investigate run too). Claude Code registers +# those while the skill is active, so a broken one blocks tool calls exactly +# like a broken setup hook. test/setup-hook-syntax-gate.test.ts keeps the +# lists equal. # # Each shim is parsed by the interpreter its shebang names (bash -n, sh -n). # Each TypeScript entry the shim runs (a `.ts` beside it) is bundled with @@ -46,9 +50,31 @@ if [ -z "$ROOT" ] || [ ! -d "$ROOT" ]; then fi SETUP_FILE="${SETUP_FILE:-$ROOT/setup}" +# frontmatter_hooks — the gstack paths named on `command:` lines inside each +# skill's YAML frontmatter (the block between the first two `---` lines). One +# awk over every SKILL.md: a pipeline per file cost ~0.4 s across 56 skills. +frontmatter_hooks() { + local skills=() f + for f in "$ROOT/SKILL.md" "$ROOT"/*/SKILL.md; do + [ -f "$f" ] && skills+=("$f") + done + [ "${#skills[@]}" -gt 0 ] || return 0 + awk ' + FNR == 1 { front = ($0 == "---"); next } + front && $0 == "---" { front = 0; next } + front && /^[[:space:]]*command:/ { + s = $0 + while (match(s, /skills\/gstack\/[A-Za-z0-9._\/-]+/)) { + print substr(s, RSTART + 14, RLENGTH - 14) + s = substr(s, RSTART + RLENGTH) + } + } + ' "${skills[@]}" +} + hook_list() { sed -n 's/.*\$(_hook_command_path \([A-Za-z0-9._/-]*\).*/\1/p' "$SETUP_FILE" 2>/dev/null - echo autoplan/bin/phase-publication-hook + frontmatter_hooks } HOOKS=$(hook_list | awk '!seen[$0]++') @@ -82,6 +108,7 @@ first_message() { FAILED=0 fail() { echo "fail $1 $2: $3"; FAILED=1; } + for hook in $HOOKS; do shim="$ROOT/$hook" if [ ! -f "$shim" ]; then echo "missing $hook"; continue; fi diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 2c0c6682ce2..48c1872ecad 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -570,11 +570,14 @@ Bun first. **Meaning.** Claude Code runs gstack's hook shims through `/bin/sh`, and a hook that does not parse exits 2, which blocks the tool call it guards in every -session. Setup parse-checks every hook it registers (the shim, and the -TypeScript it runs with its local imports). It registers the hooks that parse, -skips the ones listed, finishes the rest of the install, and exits non-zero. -Claude Code runs hooks straight from `~/.claude/skills/gstack`, so a skipped -hook that an earlier setup registered keeps running the broken file until it +session. Setup parse-checks every hook it registers, and every hook a skill +registers while it runs (`/autoplan`, `/careful`, `/freeze` and +`/plan-ceo-review`; `/guard` and `/investigate` reuse the `/careful` and +`/freeze` checks): the shim, and the TypeScript it runs with its local imports. +It registers the hooks that parse, skips the ones listed, finishes the rest +of the install, and exits non-zero. Claude Code runs hooks +straight from `~/.claude/skills/gstack`, so a skipped hook that an earlier +setup registered, or that a skill runs, keeps running the broken file until it is fixed. This is a gstack bug, or a half-applied edit or merge in your checkout: report the printed `:`. diff --git a/test/setup-hook-syntax-gate.test.ts b/test/setup-hook-syntax-gate.test.ts index 4374c3f2c08..0ed42d5cfd3 100644 --- a/test/setup-hook-syntax-gate.test.ts +++ b/test/setup-hook-syntax-gate.test.ts @@ -47,7 +47,28 @@ afterEach(() => { for (const b of bases.splice(0)) fs.rmSync(b, { recursive: tru const HOOKS = listHooks(ROOT); -/** A gstack tree with the real hook shims and trivial TypeScript entries. */ +// Skill frontmatter hooks: Claude Code registers a skill's `hooks:` while the +// skill is active, so they block tool calls exactly like setup's. Read here +// independently of the checker: the YAML frontmatter of the root SKILL.md and +// each /SKILL.md, every `command:` line, every installed gstack path. +const SKILL_FILES = ['SKILL.md', ...fs.readdirSync(ROOT).map(d => path.join(d, 'SKILL.md'))] + .filter(rel => fs.existsSync(path.join(ROOT, rel))); +function frontmatterOf(rel: string): string | null { + const text = fs.readFileSync(path.join(ROOT, rel), 'utf8'); + if (!text.startsWith('---\n')) return null; + const end = text.indexOf('\n---', 4); + return end < 0 ? null : text.slice(4, end); +} +const FRONTMATTER_HOOKS = new Map(); +for (const rel of SKILL_FILES) { + const front = frontmatterOf(rel); + if (!front) continue; + const hooks = front.split('\n').filter(l => /^\s*command:/.test(l)) + .flatMap(l => [...l.matchAll(/\$HOME\/\.claude\/skills\/gstack\/([A-Za-z0-9._/-]+)/g)].map(m => m[1]!)); + if (hooks.length) FRONTMATTER_HOOKS.set(rel, [...new Set(hooks)]); +} + +/** A gstack tree with the real hook shims, trivial TypeScript entries, and the frontmatter of each skill that registers a hook. */ function fixtureTree(root: string) { for (const hook of HOOKS) { fs.mkdirSync(path.dirname(path.join(root, hook)), { recursive: true }); @@ -56,6 +77,10 @@ function fixtureTree(root: string) { if (fs.existsSync(path.join(ROOT, `${hook}.ts`))) fs.writeFileSync(path.join(root, `${hook}.ts`), 'export const ok = 1;\n'); } fs.copyFileSync(path.join(ROOT, 'setup'), path.join(root, 'setup')); + for (const rel of FRONTMATTER_HOOKS.keys()) { + fs.mkdirSync(path.dirname(path.join(root, rel)), { recursive: true }); + fs.writeFileSync(path.join(root, rel), `---\n${frontmatterOf(rel)}\n---\n`); + } } function tmpBase(): string { @@ -70,13 +95,16 @@ function check(root: string) { } describe('gstack-hook-check: the hook list is the registration code', () => { - test('equals every hook setup resolves for registration plus the frontmatter-registered autoplan hook', () => { + test('equals every hook setup resolves for registration plus every skill-frontmatter hook', () => { const registered = [...SETUP.matchAll(/_hook_command_path (\S+)/g)].map(m => m[1]!.replace(/\W+$/, '')); - const frontmatter = [...fs.readFileSync(path.join(ROOT, 'autoplan', 'SKILL.md'), 'utf8') - .matchAll(/skills\/gstack\/(autoplan\/bin\/[a-z-]+-hook)\b/g)].map(m => m[1]!); + const frontmatter = [...FRONTMATTER_HOOKS.values()].flat(); const expected = [...new Set([...registered, ...frontmatter])].sort(); expect(registered.length).toBeGreaterThanOrEqual(5); - expect(frontmatter.length).toBeGreaterThan(0); + // /autoplan's guard, the /careful and /freeze checks (also run by /guard + // and /investigate), and /plan-ceo-review's mode hand-off. + for (const hook of ['autoplan/bin/phase-publication-hook', 'careful/bin/check-careful.sh', 'freeze/bin/check-freeze.sh', 'plan-ceo-review/bin/mode-handoff-hook']) { + expect(frontmatter).toContain(hook); + } expect([...HOOKS].sort()).toEqual(expected); }); @@ -105,6 +133,17 @@ describe('gstack-hook-check: what fails', () => { expect(r.out).toMatch(new RegExp(`^fail hosts/claude/hooks/question-preference-hook ${shim}:${lines}: syntax error`, 'm')); }); + test('a broken skill-frontmatter hook fails like a setup hook (/freeze, which /guard and /investigate also run)', () => { + const root = tmpBase(); + fixtureTree(root); + const shim = path.join(root, 'freeze/bin/check-freeze.sh'); + const lines = fs.readFileSync(shim, 'utf8').split('\n').length; + fs.appendFileSync(shim, 'if then\n'); + const r = check(root); + expect(r.code).toBe(1); + expect(r.out).toMatch(new RegExp(`^fail freeze/bin/check-freeze\\.sh ${shim}:${lines}: syntax error`, 'm')); + }); + test('a TypeScript entry with a syntax error fails with its file and line', () => { const root = tmpBase(); fixtureTree(root); From cb47580dc16b53bcc4971479684449e3c13491d7 Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 00:46:12 +1100 Subject: [PATCH 03/10] fix(hook-check): refuse conflict markers that still parse A half-merged hook is not always a parse error. When the conflict markers land inside a heredoc, a quoted string, a comment or a TypeScript template literal, `bash -n` and `bun build` both accept the file, gstack-hook-check printed `ok`, and Claude Code runs a hook built from both halves of the merge. The check now scans each shim and each TypeScript entry it runs for a line that starts with `<<<<<<<`, `|||||||` or `>>>>>>>` followed by a space or the end of the line, and fails the hook at the first one with `unresolved merge conflict marker`. A bare `=======` is left alone: it is also an ordinary banner, and a real conflict always carries the other two. Tests: a shim with markers in a heredoc (bash -n accepts it), a TypeScript entry with markers in a template literal, and a /careful hook with markers run through setup (named, its own hooks still registered, exit 1) all fail against the previous checker; a bare ======= banner stays green. docs/troubleshooting.md names the new failure. Co-Authored-By: Claude Opus 5.5 --- bin/gstack-hook-check | 20 +++++++++++- docs/troubleshooting.md | 6 ++-- test/setup-hook-syntax-gate.test.ts | 50 +++++++++++++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/bin/gstack-hook-check b/bin/gstack-hook-check index 5c299b03e1e..8f984fa44f7 100755 --- a/bin/gstack-hook-check +++ b/bin/gstack-hook-check @@ -24,7 +24,10 @@ # Each shim is parsed by the interpreter its shebang names (bash -n, sh -n). # Each TypeScript entry the shim runs (a `.ts` beside it) is bundled with # its local imports into a temp directory, packages external, so a broken or -# missing local import fails; a missing entry fails. +# missing local import fails; a missing entry fails. The shim and each entry +# are also scanned for merge conflict markers: a half-merged hook whose markers +# sit inside a heredoc, a string or a comment still parses, and still runs the +# wrong half. # # Output, one line per hook: # ok @@ -108,6 +111,19 @@ first_message() { FAILED=0 fail() { echo "fail $1 $2: $3"; FAILED=1; } +# marker_line — the line number of the first merge conflict marker +# (`<<<<<<<`, `|||||||` or `>>>>>>>` at the start of a line, then a space or +# the end of the line), or nothing. A bare `=======` is left alone: it is also +# an ordinary banner, and a real conflict always carries the other two. +marker_line() { + LC_ALL=C grep -nE '^(<{7}|[|]{7}|>{7})( |$)' "$1" 2>/dev/null | head -1 | cut -d: -f1 +} +check_markers() { + _at=$(marker_line "$2") + [ -n "$_at" ] || return 0 + fail "$1" "$2:$_at" "unresolved merge conflict marker" + return 1 +} for hook in $HOOKS; do shim="$ROOT/$hook" @@ -127,6 +143,7 @@ for hook in $HOOKS; do fail "$hook" "$(first_location "$shim" "$err")" "$(first_message "$err")" hook_ok=0 fi + check_markers "$hook" "$shim" || hook_ok=0 dir=$(dirname "$shim") for entry in $(grep -v '^[[:space:]]*#' "$shim" | grep -oE '[A-Za-z0-9._-]+\.ts([^A-Za-z0-9_]|$)' | sed -E 's/\.ts.*$/.ts/' | awk '!seen[$0]++'); do if [ ! -f "$dir/$entry" ]; then @@ -138,6 +155,7 @@ for hook in $HOOKS; do fail "$hook" "$(first_location "$dir/$entry" "$err")" "$(first_message "$err")" hook_ok=0 fi + check_markers "$hook" "$dir/$entry" || hook_ok=0 done [ "$hook_ok" -eq 1 ] && echo "ok $hook" done diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 48c1872ecad..c9a643da0b4 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -574,8 +574,10 @@ session. Setup parse-checks every hook it registers, and every hook a skill registers while it runs (`/autoplan`, `/careful`, `/freeze` and `/plan-ceo-review`; `/guard` and `/investigate` reuse the `/careful` and `/freeze` checks): the shim, and the TypeScript it runs with its local imports. -It registers the hooks that parse, skips the ones listed, finishes the rest -of the install, and exits non-zero. Claude Code runs hooks +A merge conflict marker left in a hook is refused too, as `unresolved merge +conflict marker`, even when the file still parses: markers inside a heredoc or +a string do. It registers the hooks that parse, skips the ones listed, +finishes the rest of the install, and exits non-zero. Claude Code runs hooks straight from `~/.claude/skills/gstack`, so a skipped hook that an earlier setup registered, or that a skill runs, keeps running the broken file until it is fixed. This is a gstack bug, or a half-applied edit or merge in your diff --git a/test/setup-hook-syntax-gate.test.ts b/test/setup-hook-syntax-gate.test.ts index 0ed42d5cfd3..68728526c6f 100644 --- a/test/setup-hook-syntax-gate.test.ts +++ b/test/setup-hook-syntax-gate.test.ts @@ -83,6 +83,10 @@ function fixtureTree(root: string) { } } +// Conflict markers are built here so this file never carries one at the start +// of a line. +const LT = '<'.repeat(7), EQ = '='.repeat(7), GT = '>'.repeat(7); + function tmpBase(): string { const base = fs.mkdtempSync(path.join(os.tmpdir(), 'hook-gate-')); bases.push(base); @@ -133,6 +137,39 @@ describe('gstack-hook-check: what fails', () => { expect(r.out).toMatch(new RegExp(`^fail hosts/claude/hooks/question-preference-hook ${shim}:${lines}: syntax error`, 'm')); }); + test('a half-merged shim whose markers sit inside a heredoc still parses, and fails at the first marker', () => { + const root = tmpBase(); + fixtureTree(root); + const shim = path.join(root, 'hosts/claude/hooks/question-preference-hook'); + const before = fs.readFileSync(shim, 'utf8'); + const first = before.split('\n').length + 1; + fs.appendFileSync(shim, `cat >/dev/null <<'EOF'\n${LT} HEAD\nours\n${EQ}\ntheirs\n${GT} main\nEOF\n`); + // The gap this closes: bash itself accepts the file. + expect(spawnSync('bash', ['-n', shim], { timeout: 15_000 }).status).toBe(0); + const r = check(root); + expect(r.code).toBe(1); + expect(r.out).toContain(`fail hosts/claude/hooks/question-preference-hook ${shim}:${first}: unresolved merge conflict marker`); + expect(r.out).not.toContain('ok hosts/claude/hooks/question-preference-hook'); + }); + + test('a TypeScript entry with markers inside a template literal still bundles, and fails at the first marker', () => { + const root = tmpBase(); + fixtureTree(root); + const ts = path.join(root, 'hosts/claude/hooks/timeline-stop-hook.ts'); + fs.writeFileSync(ts, `export const x = \`\n${LT} HEAD\na\n${EQ}\nb\n${GT} main\n\`;\n`); + const r = check(root); + expect(r.code).toBe(1); + expect(r.out).toContain(`fail hosts/claude/hooks/timeline-stop-hook ${ts}:2: unresolved merge conflict marker`); + }); + + test('a bare ======= line is an ordinary banner, not a marker', () => { + const root = tmpBase(); + fixtureTree(root); + const shim = path.join(root, 'hosts/claude/hooks/question-log-hook'); + fs.appendFileSync(shim, `cat >/dev/null <<'EOF'\n${EQ}\nEOF\n`); + expect(check(root).code).toBe(0); + }); + test('a broken skill-frontmatter hook fails like a setup hook (/freeze, which /guard and /investigate also run)', () => { const root = tmpBase(); fixtureTree(root); @@ -302,4 +339,17 @@ describe('setup: registers the hooks that parse, refuses the rest, exits non-zer expect(r.out).not.toContain('previous install is still active'); expect(registeredCommands(fx)).toEqual(before); }, SETUP_HOOKS_TEST_MS); + + test('a half-merged skill-frontmatter hook: setup names it, still registers its own hooks, and exits 1', () => { + const fx = setupFixture(); + const broken = shim(fx, 'careful/bin/check-careful.sh'); + const first = fs.readFileSync(broken, 'utf8').split('\n').length + 1; + fs.appendFileSync(broken, `cat >/dev/null <<'EOF'\n${LT} HEAD\nours\n${EQ}\ntheirs\n${GT} main\nEOF\n`); + const r = runSetupHooks(fx); + expect(r.code).toBe(1); + expect(r.out).toContain(` ${broken}:${first}: unresolved merge conflict marker`); + expect(r.out).toContain('Skipped: careful/bin/check-careful.sh'); + expect(r.out).toContain('or that a skill file runs, keeps running the broken file until it is fixed'); + expect(registeredCommands(fx)).toEqual(ALL.map(rel => shim(fx, rel)).sort()); + }, SETUP_HOOKS_TEST_MS); }); From eda7e95bd9dc78f83b3ce493168d530ce8c15a29 Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 01:13:34 +1100 Subject: [PATCH 04/10] fix(hook-check): read skill frontmatter under BusyBox awk and CRLF The frontmatter scan matched paths with the /.../ literal `/skills\/gstack\/[A-Za-z0-9._\/-]+/`. BusyBox awk (Alpine, v1.37.0) keeps the backslash of the escaped `\/` inside the bracket expression, so each path ran into the `\"` that closes it in the hook command. All four skill hooks came out with a trailing backslash, were reported `missing`, and went unchecked, the /autoplan hook included (the previous hard-coded entry was checked). macOS awk, mawk and gawk were not affected. The regex is now a string, which has no delimiter to escape; under BusyBox in postgres:15-alpine the list is clean. The scan also strips a trailing CR before comparing, so a CRLF checkout of a SKILL.md no longer hides its hooks, and accepts trailing spaces on the `---` delimiters. Tests: every listed hook is a file in the tree spelled exactly (the BusyBox failure mode), every SKILL.md whose frontmatter has `hooks:` contributes at least one path, and CRLF SKILL.md files list the same hooks. The CRLF case fails against the previous scan. Co-Authored-By: Claude Opus 5.5 --- bin/gstack-hook-check | 20 +++++++++++-------- test/setup-hook-syntax-gate.test.ts | 30 ++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/bin/gstack-hook-check b/bin/gstack-hook-check index 8f984fa44f7..f603a9b0f74 100755 --- a/bin/gstack-hook-check +++ b/bin/gstack-hook-check @@ -16,10 +16,10 @@ # --setup, when another tree's setup registers 's hooks), plus every # gstack path a skill's frontmatter hook command runs (/SKILL.md and # /*/SKILL.md: /autoplan's phase-publication hook, and the /careful and -# /freeze checks that /guard and /investigate run too). Claude Code registers -# those while the skill is active, so a broken one blocks tool calls exactly -# like a broken setup hook. test/setup-hook-syntax-gate.test.ts keeps the -# lists equal. +# /freeze checks that /guard and /investigate run too, and /plan-ceo-review's +# hand-off). Claude Code registers those while the skill is active, so a broken +# one fails exactly like a broken setup hook; a broken PreToolUse one blocks +# the tool call. test/setup-hook-syntax-gate.test.ts keeps the lists equal. # # Each shim is parsed by the interpreter its shebang names (bash -n, sh -n). # Each TypeScript entry the shim runs (a `.ts` beside it) is bundled with @@ -55,7 +55,10 @@ SETUP_FILE="${SETUP_FILE:-$ROOT/setup}" # frontmatter_hooks — the gstack paths named on `command:` lines inside each # skill's YAML frontmatter (the block between the first two `---` lines). One -# awk over every SKILL.md: a pipeline per file cost ~0.4 s across 56 skills. +# awk over every SKILL.md: a pipeline per file cost ~0.4 s across the 57 files. +# CRs are stripped first (a CRLF checkout), and the path regex is a string, not +# a /.../ literal: BusyBox awk (Alpine) keeps the backslash of an escaped `\/` +# inside a bracket expression, which ran each path into the `\"` closing it. frontmatter_hooks() { local skills=() f for f in "$ROOT/SKILL.md" "$ROOT"/*/SKILL.md; do @@ -63,11 +66,12 @@ frontmatter_hooks() { done [ "${#skills[@]}" -gt 0 ] || return 0 awk ' - FNR == 1 { front = ($0 == "---"); next } - front && $0 == "---" { front = 0; next } + { sub(/\r$/, "") } + FNR == 1 { front = ($0 ~ /^---[[:space:]]*$/); next } + front && $0 ~ /^---[[:space:]]*$/ { front = 0; next } front && /^[[:space:]]*command:/ { s = $0 - while (match(s, /skills\/gstack\/[A-Za-z0-9._\/-]+/)) { + while (match(s, "skills/gstack/[A-Za-z0-9._/-]+")) { print substr(s, RSTART + 14, RLENGTH - 14) s = substr(s, RSTART + RLENGTH) } diff --git a/test/setup-hook-syntax-gate.test.ts b/test/setup-hook-syntax-gate.test.ts index 68728526c6f..ebcdb8c0272 100644 --- a/test/setup-hook-syntax-gate.test.ts +++ b/test/setup-hook-syntax-gate.test.ts @@ -48,7 +48,8 @@ afterEach(() => { for (const b of bases.splice(0)) fs.rmSync(b, { recursive: tru const HOOKS = listHooks(ROOT); // Skill frontmatter hooks: Claude Code registers a skill's `hooks:` while the -// skill is active, so they block tool calls exactly like setup's. Read here +// skill is active, so a broken one fails exactly like a broken setup hook (a +// PreToolUse one blocks the tool call). Read here // independently of the checker: the YAML frontmatter of the root SKILL.md and // each /SKILL.md, every `command:` line, every installed gstack path. const SKILL_FILES = ['SKILL.md', ...fs.readdirSync(ROOT).map(d => path.join(d, 'SKILL.md'))] @@ -112,6 +113,33 @@ describe('gstack-hook-check: the hook list is the registration code', () => { expect([...HOOKS].sort()).toEqual(expected); }); + test('every listed hook is a file in this tree, spelled exactly (no trailing backslash or CR)', () => { + // BusyBox awk once ran each frontmatter path into the `\"` that closes it, + // so all four were reported `missing` and went unchecked. + for (const hook of HOOKS) { + expect(hook).toMatch(/^[A-Za-z0-9._/-]+$/); + expect(fs.statSync(path.join(ROOT, hook)).isFile()).toBe(true); + } + }); + + test('every skill whose frontmatter has hooks contributes at least one checked path', () => { + // Guards the derivation: a hook command spelled some other way (a YAML + // block scalar, a relative path) would otherwise drop out of the check. + const withHooks = SKILL_FILES.filter(rel => /^hooks:/m.test(frontmatterOf(rel) ?? '')); + expect(withHooks.length).toBeGreaterThanOrEqual(6); + expect(withHooks.filter(rel => !FRONTMATTER_HOOKS.has(rel))).toEqual([]); + }); + + test('SKILL.md files checked out with CRLF line endings still have their hooks listed', () => { + const root = tmpBase(); + fixtureTree(root); + for (const rel of FRONTMATTER_HOOKS.keys()) { + const skill = path.join(root, rel); + fs.writeFileSync(skill, fs.readFileSync(skill, 'utf8').replace(/\n/g, '\r\n')); + } + expect([...listHooks(root)].sort()).toEqual([...HOOKS].sort()); + }); + test('every shipped hook in this checkout passes', () => { const r = check(ROOT); expect(r.code).toBe(0); From a4a35a3b9964ab08a4a0fc8e17864a03e6d120a5 Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 01:17:57 +1100 Subject: [PATCH 05/10] fix(hook-check): check the helpers a hook sources and the modules it imports A hook can be broken in a file the shim only pulls in. The /careful and /freeze checks source careful/bin/hook-extract.sh; with markers or a syntax error there, the shims still parsed and the check printed `ok`, while at run time /freeze denied every Edit and Write and /careful asked on every Bash call. bin/gstack-session-update sources three sibling .sh files the same way. And a conflict marker inside a TypeScript module a hook entry imports passed: the bundle still built, and only the entry was scanned. For each shell shim the check now also parses and marker-scans the helpers it sources, and what those source in turn (four levels): each `# shellcheck source=` directive, each `*.sh` path on a line that runs `.` or `source`, and each `*.sh` path assigned to a variable such a line sources. A script the shim only runs is not a helper: it is parsed by its own shebang when it runs. For each TypeScript entry it asks bun for a --metafile and marker-scans every local module the bundle used. A bun whose `build --help` does not list --metafile falls back to scanning the entry alone; the bundle still fails on a syntax error anywhere in it. Tests (each fails against the previous check): markers in careful/bin/hook-extract.sh fail both /careful and /freeze at the helper; a syntax error in bin/gstack-egress-lib.sh fails the auto-updater hook; markers in a module the question-log entry imports fail at that module. A broken bin/gstack-state-root.sh, which careful/bin/hook-extract.sh sources, fails /careful and /freeze; a sh shim that execs a bash worker beside it stays ok. A bun without --metafile gets no false failure and still catches markers in the entry; passing --metafile to it unconditionally fails that case. The fixture tree carries each hook's helpers, found independently. docs/troubleshooting.md covers helpers and imports, and the auto-update entry names the same check. Co-Authored-By: Claude Opus 5.5 --- bin/gstack-hook-check | 189 +++++++++++++++++++++++++--- docs/troubleshooting.md | 23 ++-- test/setup-hook-syntax-gate.test.ts | 105 +++++++++++++++- 3 files changed, 286 insertions(+), 31 deletions(-) diff --git a/bin/gstack-hook-check b/bin/gstack-hook-check index f603a9b0f74..c0906299391 100755 --- a/bin/gstack-hook-check +++ b/bin/gstack-hook-check @@ -21,12 +21,14 @@ # one fails exactly like a broken setup hook; a broken PreToolUse one blocks # the tool call. test/setup-hook-syntax-gate.test.ts keeps the lists equal. # -# Each shim is parsed by the interpreter its shebang names (bash -n, sh -n). -# Each TypeScript entry the shim runs (a `.ts` beside it) is bundled with -# its local imports into a temp directory, packages external, so a broken or -# missing local import fails; a missing entry fails. The shim and each entry -# are also scanned for merge conflict markers: a half-merged hook whose markers -# sit inside a heredoc, a string or a comment still parses, and still runs the +# Each shim is parsed by the interpreter its shebang names (bash -n, sh -n), +# and so is each shell helper it sources (see helpers_of). Each TypeScript +# entry the shim runs (a `.ts` beside it) is bundled with its local +# imports into a temp directory, packages external, so a broken or missing +# local import fails; a missing entry fails. The shim, its helpers, each entry +# and (when bun can name them) each local module the entry bundles are also +# scanned for merge conflict markers: a half-merged hook whose markers sit +# inside a heredoc, a string or a comment still parses, and still runs the # wrong half. # # Output, one line per hook: @@ -97,6 +99,13 @@ if ! command -v "$BUN" >/dev/null 2>&1; then fi TMP_OUT=$(mktemp -d "${TMPDIR:-/tmp}/gstack-hook-check.XXXXXX") || { echo "gstack-hook-check: cannot create a temp directory" >&2; exit 1; } trap 'rm -rf "$TMP_OUT"' EXIT +# A bun whose `build` takes --metafile names every local module an entry +# bundles, so each is scanned for conflict markers too. Without it (an older +# bun) only the entry file is scanned; the bundle still fails on a syntax error +# anywhere in it. +META=0 +"$BUN" build --help 2>/dev/null | grep -q -- '--metafile' && META=1 +CWD_P=$(pwd -P) # first_location — ":" from bun's "at f:l:c" # or bash's "f: line N:" (falls back to ). @@ -115,20 +124,130 @@ first_message() { FAILED=0 fail() { echo "fail $1 $2: $3"; FAILED=1; } -# marker_line — the line number of the first merge conflict marker -# (`<<<<<<<`, `|||||||` or `>>>>>>>` at the start of a line, then a space or -# the end of the line), or nothing. A bare `=======` is left alone: it is also -# an ordinary banner, and a real conflict always carries the other two. -marker_line() { - LC_ALL=C grep -nE '^(<{7}|[|]{7}|>{7})( |$)' "$1" 2>/dev/null | head -1 | cut -d: -f1 -} -check_markers() { - _at=$(marker_line "$2") - [ -n "$_at" ] || return 0 - fail "$1" "$2:$_at" "unresolved merge conflict marker" +NL=' +' + +# report_markers — fails the hook at the first +# merge conflict marker in each file: `<<<<<<<`, `|||||||` or `>>>>>>>` at the +# start of a line, then a space or the end of the line. A bare `=======` is +# left alone: it is also an ordinary banner, and a real conflict always carries +# the other two. One grep for all of a hook's files. +report_markers() { + [ -n "$2" ] || return 0 + _out=$(IFS=$NL; set -f; LC_ALL=C grep -nHE '^(<{7}|[|]{7}|>{7})( |$)' -- $2 2>/dev/null) + [ -n "$_out" ] || return 0 + _hits=$(printf '%s\n' "$_out" | awk -F: '!seen[$1]++ { print $1 ":" $2 }') + _rifs=$IFS; IFS=$NL + for _hit in $_hits; do fail "$1" "$_hit" "unresolved merge conflict marker"; done + IFS=$_rifs return 1 } +# sourced_by — the shell files sources directly: each path a +# `# shellcheck source=` directive names, each `*.sh` path on a line that +# runs `.` or `source`, and each `*.sh` path assigned to a variable such a line +# sources (`H="$DIR/hook-extract.sh"` ... `. "$H"`). A script it only runs is +# not a helper: it is parsed by its own shebang when it runs, not by 's. +# A path resolves from the tree root, then beside , then with its first +# segment (a `$DIR/` or `${BASH_SOURCE%/*}/` prefix) dropped; the first that +# exists wins, with `.` and `..` folded so the path stays under . +sourced_by() { + # String regexes, not /.../ literals: see frontmatter_hooks on BusyBox awk. + awk -v root="$ROOT" -v dir="${1%/*}" -v self="$1" ' + function norm(p, a, n, i, k, st, out) { + n = split(p, a, "/"); k = 0 + for (i = 1; i <= n; i++) { + if (a[i] == "" || a[i] == ".") continue + if (a[i] == ".." && k > 0 && st[k] != "..") { k--; continue } + st[++k] = a[i] + } + out = "" + for (i = 1; i <= k; i++) out = out "/" st[i] + return out + } + function exists(p, line, r) { r = (getline line < p); close(p); return r >= 0 } + function resolve(t, c, i, n, parts) { + if (substr(t, 1, 1) != "/") { + c = norm(root "/" t); if (exists(c)) return c + c = norm(dir "/" t); if (exists(c)) return c + } + i = index(t, "/") + if (i > 0) { c = norm(dir "/" substr(t, i + 1)); if (exists(c)) return c } + n = split(t, parts, "/"); c = norm(dir "/" parts[n]); if (exists(c)) return c + return "" + } + function paths(s) { + while (match(s, "[A-Za-z0-9._/-]*[.]sh")) { + tok[++nt] = substr(s, RSTART, RLENGTH) + s = substr(s, RSTART + RLENGTH) + } + } + /^[[:space:]]*#/ { + if ($0 ~ "^[[:space:]]*#[[:space:]]*shellcheck[[:space:]]" && match($0, "source=[^[:space:]]+")) + tok[++nt] = substr($0, RSTART + 7, RLENGTH - 7) + next + } + { + if (match($0, "^[[:space:]]*(local[[:space:]]+|export[[:space:]]+|readonly[[:space:]]+)?[A-Za-z_][A-Za-z0-9_]*=")) { + name = substr($0, RSTART, RLENGTH - 1) + sub("^[[:space:]]*(local[[:space:]]+|export[[:space:]]+|readonly[[:space:]]+)?", "", name) + assigned[name] = assigned[name] " " $0 + } + if (match($0, "(^|[;&|!({])[[:space:]]*([.]|source)[[:space:]]+[^[:space:]]")) { + s = substr($0, RSTART) + paths(s) + while (match(s, "[$][{]?[A-Za-z_][A-Za-z0-9_]*")) { + v = substr(s, RSTART, RLENGTH); sub("^[$][{]?", "", v); sourced[v] = 1 + s = substr(s, RSTART + RLENGTH) + } + } + } + END { + for (v in sourced) if (v in assigned) paths(assigned[v]) + for (i = 1; i <= nt; i++) { + p = resolve(tok[i]) + if (p != "" && p != self && !(p in seen)) { seen[p] = 1; print p } + } + } + ' "$1" 2>/dev/null +} + +# helpers_of — every shell file the shim sources, and what those source +# in turn (four levels): /careful and /freeze source +# careful/bin/hook-extract.sh, which sources bin/gstack-state-root.sh. A broken +# one makes them deny or ask on every call while the shim itself still parses. +helpers_of() { + _seen="$NL$1$NL" _queue=$1 _depth=0 + _hifs=$IFS + while [ -n "$_queue" ] && [ "$_depth" -lt 4 ]; do + _next="" + IFS=$NL + for _f in $_queue; do + for _c in $(sourced_by "$_f"); do + case "$_seen" in *"$NL$_c$NL"*) continue ;; esac + _seen="$_seen$_c$NL" + printf '%s\n' "$_c" + _next="$_next$_c$NL" + done + done + IFS=$_hifs + _queue=$_next _depth=$((_depth + 1)) + done +} + +# metafile_inputs — the "inputs" keys of a bun build metafile, +# relative to the directory bun ran in. An unexpected layout yields nothing, +# and the caller falls back to scanning the entry alone. +metafile_inputs() { + awk '/^ "inputs": \{$/ { f = 1; next } f && /^ \}/ { exit } + f && /^ "[^"]+": \{$/ { sub(/^ "/, ""); sub(/": \{$/, ""); print }' "$1" 2>/dev/null +} + +# physical — the path with symlinks and `..` resolved. +physical() { + ( cd -P "${1%/*}" 2>/dev/null && printf '%s/%s\n' "$PWD" "${1##*/}" ) +} + for hook in $HOOKS; do shim="$ROOT/$hook" if [ ! -f "$shim" ]; then echo "missing $hook"; continue; fi @@ -147,7 +266,18 @@ for hook in $HOOKS; do fail "$hook" "$(first_location "$shim" "$err")" "$(first_message "$err")" hook_ok=0 fi - check_markers "$hook" "$shim" || hook_ok=0 + _scan=$shim # every file this hook runs, scanned for markers at the end + _helpers=$(helpers_of "$shim") + _ifs=$IFS; IFS=$NL + for helper in $_helpers; do + IFS=$_ifs + if ! err=$("$interp" -n "$helper" 2>&1); then + fail "$hook" "$(first_location "$helper" "$err")" "$(first_message "$err")" + hook_ok=0 + fi + _scan="$_scan$NL$helper" + done + IFS=$_ifs dir=$(dirname "$shim") for entry in $(grep -v '^[[:space:]]*#' "$shim" | grep -oE '[A-Za-z0-9._-]+\.ts([^A-Za-z0-9_]|$)' | sed -E 's/\.ts.*$/.ts/' | awk '!seen[$0]++'); do if [ ! -f "$dir/$entry" ]; then @@ -155,12 +285,31 @@ for hook in $HOOKS; do hook_ok=0 continue fi - if ! err=$("$BUN" build --target=bun --packages=external --outdir "$TMP_OUT/$(basename "$hook")" "$dir/$entry" 2>&1 >/dev/null); then + meta="$TMP_OUT/meta.json" + rm -f "$meta" + _mf="" + [ "$META" -eq 1 ] && _mf="--metafile=$meta" + if ! err=$("$BUN" build --target=bun --packages=external --outdir "$TMP_OUT/$(basename "$hook")" ${_mf:+"$_mf"} "$dir/$entry" 2>&1 >/dev/null); then fail "$hook" "$(first_location "$dir/$entry" "$err")" "$(first_message "$err")" hook_ok=0 fi - check_markers "$hook" "$dir/$entry" || hook_ok=0 + _scan="$_scan$NL$dir/$entry" + # Every other local module the entry bundles. + _inputs="" + [ -f "$meta" ] && _inputs=$(metafile_inputs "$meta") + [ -n "$_inputs" ] || continue + _entry_p=$(physical "$dir/$entry") + IFS=$NL + for rel in $_inputs; do + IFS=$_ifs + case "$rel" in /*) mod="$rel" ;; *) mod="$CWD_P/$rel" ;; esac + case "$mod" in */../*|*/./*) mod=$(physical "$mod") ;; esac + [ -f "$mod" ] && [ "$mod" != "$_entry_p" ] || continue + _scan="$_scan$NL$mod" + done + IFS=$_ifs done + report_markers "$hook" "$_scan" || hook_ok=0 [ "$hook_ok" -eq 1 ] && echo "ok $hook" done exit "$FAILED" diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index c9a643da0b4..de4fdac3db5 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -572,15 +572,16 @@ Bun first. that does not parse exits 2, which blocks the tool call it guards in every session. Setup parse-checks every hook it registers, and every hook a skill registers while it runs (`/autoplan`, `/careful`, `/freeze` and -`/plan-ceo-review`; `/guard` and `/investigate` reuse the `/careful` and -`/freeze` checks): the shim, and the TypeScript it runs with its local imports. -A merge conflict marker left in a hook is refused too, as `unresolved merge -conflict marker`, even when the file still parses: markers inside a heredoc or -a string do. It registers the hooks that parse, skips the ones listed, -finishes the rest of the install, and exits non-zero. Claude Code runs hooks -straight from `~/.claude/skills/gstack`, so a skipped hook that an earlier -setup registered, or that a skill runs, keeps running the broken file until it -is fixed. This is a gstack bug, or a half-applied edit or merge in your +`/plan-ceo-review`; `/guard` reuses the `/careful` and `/freeze` checks, and +`/investigate` the `/freeze` one): the shim, the shell helpers it sources (such +as `careful/bin/hook-extract.sh`), and the TypeScript it runs with its local +imports. A merge conflict marker left in any of those files is refused too, as +`unresolved merge conflict marker`, even when the file still parses: markers +inside a heredoc or a string do. It registers the hooks that parse, skips the +ones listed, finishes the rest of the install, and exits non-zero. Claude Code +runs hooks straight from `~/.claude/skills/gstack`, so a skipped hook that an +earlier setup registered, or that a skill runs, keeps running the broken file +until it is fixed. This is a gstack bug, or a half-applied edit or merge in your checkout: report the printed `:`. **Fix.** @@ -597,7 +598,9 @@ cd ~/.claude/skills/gstack && ./setup ### `gstack auto-update: update held (hook-does-not-parse: :: ); nothing was installed or changed, and your current hooks keep running. ...` **Meaning.** Team-mode auto-update fetched a release with a hook that does not -parse. It checked the incoming revision before moving your checkout, so your +parse, or that still holds a merge conflict marker (the same check setup runs, +skill hooks and the helpers they source included). It checked the incoming +revision before moving your checkout, so your checkout, installed skills and registered hooks stay at the current revision. gstack checks again at the next update check and installs the first release whose hooks parse. This is a gstack bug: report the printed `:`. diff --git a/test/setup-hook-syntax-gate.test.ts b/test/setup-hook-syntax-gate.test.ts index ebcdb8c0272..33fa293bef3 100644 --- a/test/setup-hook-syntax-gate.test.ts +++ b/test/setup-hook-syntax-gate.test.ts @@ -69,13 +69,28 @@ for (const rel of SKILL_FILES) { if (hooks.length) FRONTMATTER_HOOKS.set(rel, [...new Set(hooks)]); } -/** A gstack tree with the real hook shims, trivial TypeScript entries, and the frontmatter of each skill that registers a hook. */ +// The shell files a shim sources, read here independently of the checker: the +// paths its `# shellcheck source=` directives name, and each `.sh` a +// non-comment line names beside it. +function helpersOf(hook: string): string[] { + const text = fs.readFileSync(path.join(ROOT, hook), 'utf8'); + const declared = [...text.matchAll(/^\s*#\s*shellcheck\s.*source=(\S+)/gm)].map(m => m[1]!); + const beside = text.split('\n').filter(l => !/^\s*#/.test(l)) + .flatMap(l => l.match(/[A-Za-z0-9._-]+\.sh/g) ?? []).map(n => path.join(path.dirname(hook), n)); + return [...new Set([...declared, ...beside])].filter(rel => rel !== hook && fs.existsSync(path.join(ROOT, rel))); +} + +/** A gstack tree with the real hook shims and the helpers they source, trivial TypeScript entries, and the frontmatter of each skill that registers a hook. */ function fixtureTree(root: string) { for (const hook of HOOKS) { fs.mkdirSync(path.dirname(path.join(root, hook)), { recursive: true }); fs.copyFileSync(path.join(ROOT, hook), path.join(root, hook)); fs.chmodSync(path.join(root, hook), 0o755); if (fs.existsSync(path.join(ROOT, `${hook}.ts`))) fs.writeFileSync(path.join(root, `${hook}.ts`), 'export const ok = 1;\n'); + for (const helper of helpersOf(hook)) { + fs.mkdirSync(path.dirname(path.join(root, helper)), { recursive: true }); + fs.copyFileSync(path.join(ROOT, helper), path.join(root, helper)); + } } fs.copyFileSync(path.join(ROOT, 'setup'), path.join(root, 'setup')); for (const rel of FRONTMATTER_HOOKS.keys()) { @@ -190,6 +205,94 @@ describe('gstack-hook-check: what fails', () => { expect(r.out).toContain(`fail hosts/claude/hooks/timeline-stop-hook ${ts}:2: unresolved merge conflict marker`); }); + test('a half-merged helper the /careful and /freeze checks source fails both, at the helper', () => { + const root = tmpBase(); + fixtureTree(root); + const helper = path.join(root, 'careful/bin/hook-extract.sh'); + expect(fs.existsSync(helper)).toBe(true); + const first = fs.readFileSync(helper, 'utf8').split('\n').length + 1; + fs.appendFileSync(helper, `cat >/dev/null <<'EOF'\n${LT} HEAD\nours\n${EQ}\ntheirs\n${GT} main\nEOF\n`); + const r = check(root); + expect(r.code).toBe(1); + for (const hook of ['careful/bin/check-careful.sh', 'freeze/bin/check-freeze.sh']) { + expect(r.out).toContain(`fail ${hook} ${helper}:${first}: unresolved merge conflict marker`); + } + }); + + test('a helper that a helper sources is checked too (/careful and /freeze reach bin/gstack-state-root.sh through hook-extract.sh)', () => { + const root = tmpBase(); + fixtureTree(root); + const helper = path.join(root, 'bin/gstack-state-root.sh'); + expect(fs.existsSync(helper)).toBe(true); + const lines = fs.readFileSync(helper, 'utf8').split('\n').length; + fs.appendFileSync(helper, 'if then\n'); + const r = check(root); + expect(r.code).toBe(1); + for (const hook of ['careful/bin/check-careful.sh', 'freeze/bin/check-freeze.sh', 'bin/gstack-session-update']) { + expect(r.out).toMatch(new RegExp(`^fail ${hook.replace(/\./g, '\\.')} ${helper}:${lines}: syntax error`, 'm')); + } + }); + + test('a script a hook only runs, not sources, is not parsed as its helper', () => { + // A POSIX sh shim may exec a bash worker beside it; parsing that worker + // with sh would refuse a hook that runs fine. + const root = tmpBase(); + fs.mkdirSync(path.join(root, 'hooks'), { recursive: true }); + fs.writeFileSync(path.join(root, 'setup'), 'X="$(_hook_command_path hooks/plain || true)"\n'); + fs.writeFileSync(path.join(root, 'hooks/plain'), '#!/bin/sh\nexec "$(dirname "$0")/worker.sh" "$@"\n', { mode: 0o755 }); + fs.writeFileSync(path.join(root, 'hooks/worker.sh'), '#!/usr/bin/env bash\nwhile read -r l; do echo "$l"; done < <(echo a)\n', { mode: 0o755 }); + const r = check(root); + expect(r.out.trim()).toBe('ok hooks/plain'); + expect(r.code).toBe(0); + }); + + test('a helper the auto-updater sources that does not parse fails its hook with the helper file and line', () => { + const root = tmpBase(); + fixtureTree(root); + const helper = path.join(root, 'bin/gstack-egress-lib.sh'); + expect(fs.existsSync(helper)).toBe(true); + const lines = fs.readFileSync(helper, 'utf8').split('\n').length; + fs.appendFileSync(helper, 'if then\n'); + const r = check(root); + expect(r.code).toBe(1); + expect(r.out).toMatch(new RegExp(`^fail bin/gstack-session-update ${helper}:${lines}: syntax error`, 'm')); + }); + + const bunHasMetafile = (spawnSync('bun', ['build', '--help'], { encoding: 'utf8', timeout: 15_000 }).stdout ?? '').includes('--metafile'); + test.skipIf(!bunHasMetafile)('a module a TypeScript entry imports fails at its first marker, even inside a template literal', () => { + const root = tmpBase(); + fixtureTree(root); + const dir = path.join(root, 'hosts/claude/hooks'); + fs.writeFileSync(path.join(dir, 'question-log-hook.ts'), "import { banner } from './hook-log';\nconsole.log(banner);\n"); + const mod = path.join(dir, 'hook-log.ts'); + fs.writeFileSync(mod, `export const banner = \`\n${LT} HEAD\na\n${EQ}\nb\n${GT} main\n\`;\n`); + const r = check(root); + expect(r.code).toBe(1); + expect(r.out).toContain(`fail hosts/claude/hooks/question-log-hook ${fs.realpathSync(mod)}:2: unresolved merge conflict marker`); + }); + + test('a bun whose build has no --metafile falls back to scanning the entry alone, with no false failure', () => { + const root = tmpBase(); + fixtureTree(root); + const oldBun = path.join(root, 'old-bun'); + fs.writeFileSync(oldBun, [ + '#!/bin/bash', + `if [ "$1" = build ] && [ "$2" = --help ]; then '${process.execPath}' build --help | grep -v -- --metafile; exit 0; fi`, + 'for a in "$@"; do case "$a" in --metafile*) echo "error: unknown flag $a" >&2; exit 1 ;; esac; done', + `exec '${process.execPath}' "$@"`, + ].join('\n') + '\n', { mode: 0o755 }); + const run = () => { + const r = spawnSync('bash', [CHECK, root], { encoding: 'utf8', timeout: 30_000, env: { ...process.env, GSTACK_HOOK_CHECK_BUN: oldBun } }); + return { code: r.status, out: `${r.stdout}${r.stderr}` }; + }; + expect(run().code).toBe(0); + const ts = path.join(root, 'hosts/claude/hooks/timeline-stop-hook.ts'); + fs.writeFileSync(ts, `export const x = \`\n${LT} HEAD\n\`;\n`); + const r = run(); + expect(r.code).toBe(1); + expect(r.out).toContain(`fail hosts/claude/hooks/timeline-stop-hook ${ts}:2: unresolved merge conflict marker`); + }); + test('a bare ======= line is an ordinary banner, not a marker', () => { const root = tmpBase(); fixtureTree(root); From 47ada19a74acab364b692a0dca5bdd5ccb616092 Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 01:48:42 +1100 Subject: [PATCH 06/10] fix(hook-check): bundle hook TypeScript from the tree root gstack-hook-check ran `bun build` in the caller's directory, and bun reads the bunfig.toml and tsconfig.json it finds there. A malformed one failed every TypeScript hook: on main, a `{ this is not json` tsconfig.json in the current directory gives `fail hosts/claude/hooks/question-log-hook /tsconfig.json:1: Expected string but found "this"` for five hooks. The auto-updater runs the check from whatever project the session is in, so such a project held every release. The check now makes absolute and runs each bundle from it. bun names metafile inputs relative to that directory, so a module inside the tree is reported as /, the spelling the auto-updater strips from its hold message; one outside it is resolved physically. Test: a malformed tsconfig.json and bunfig.toml in the caller's directory leave every hook `ok` (fails against the previous check). Co-Authored-By: Claude Opus 5.5 --- bin/gstack-hook-check | 21 +++++++++++++++------ test/setup-hook-syntax-gate.test.ts | 19 ++++++++++++++++++- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/bin/gstack-hook-check b/bin/gstack-hook-check index c0906299391..2ec0dd42001 100755 --- a/bin/gstack-hook-check +++ b/bin/gstack-hook-check @@ -53,6 +53,9 @@ if [ -z "$ROOT" ] || [ ! -d "$ROOT" ]; then echo "usage: gstack-hook-check [--setup ] [--list] " >&2 exit 2 fi +# Absolute, so the bundles below can run from the tree root (see BUILD_DIR). +case "$ROOT" in /*) ;; *) ROOT="$PWD/$ROOT" ;; esac +[ "$ROOT" = / ] || ROOT=${ROOT%/} SETUP_FILE="${SETUP_FILE:-$ROOT/setup}" # frontmatter_hooks — the gstack paths named on `command:` lines inside each @@ -105,7 +108,11 @@ trap 'rm -rf "$TMP_OUT"' EXIT # anywhere in it. META=0 "$BUN" build --help 2>/dev/null | grep -q -- '--metafile' && META=1 -CWD_P=$(pwd -P) +# Bundles run from the tree root, never the caller's directory: bun reads the +# bunfig.toml and tsconfig.json it finds there, and the auto-updater runs this +# from whatever project the session is in. The metafile names inputs relative +# to that directory, physically resolved. +BUILD_DIR=$(cd -P "$ROOT" && pwd) || { echo "gstack-hook-check: cannot enter $ROOT" >&2; exit 1; } # first_location — ":" from bun's "at f:l:c" # or bash's "f: line N:" (falls back to ). @@ -289,7 +296,7 @@ for hook in $HOOKS; do rm -f "$meta" _mf="" [ "$META" -eq 1 ] && _mf="--metafile=$meta" - if ! err=$("$BUN" build --target=bun --packages=external --outdir "$TMP_OUT/$(basename "$hook")" ${_mf:+"$_mf"} "$dir/$entry" 2>&1 >/dev/null); then + if ! err=$(cd "$BUILD_DIR" && "$BUN" build --target=bun --packages=external --outdir "$TMP_OUT/$(basename "$hook")" ${_mf:+"$_mf"} "$dir/$entry" 2>&1 >/dev/null); then fail "$hook" "$(first_location "$dir/$entry" "$err")" "$(first_message "$err")" hook_ok=0 fi @@ -298,13 +305,15 @@ for hook in $HOOKS; do _inputs="" [ -f "$meta" ] && _inputs=$(metafile_inputs "$meta") [ -n "$_inputs" ] || continue - _entry_p=$(physical "$dir/$entry") + _entry_rel="${dir#"$ROOT"/}/$entry" IFS=$NL for rel in $_inputs; do IFS=$_ifs - case "$rel" in /*) mod="$rel" ;; *) mod="$CWD_P/$rel" ;; esac - case "$mod" in */../*|*/./*) mod=$(physical "$mod") ;; esac - [ -f "$mod" ] && [ "$mod" != "$_entry_p" ] || continue + [ "$rel" != "$_entry_rel" ] || continue + # Inside the tree: report it under as given, so a caller that + # strips its own / prefix (the auto-updater) still can. + case "$rel" in /*) mod="$rel" ;; ../*) mod=$(physical "$BUILD_DIR/$rel") ;; *) mod="$ROOT/$rel" ;; esac + [ -f "$mod" ] || continue _scan="$_scan$NL$mod" done IFS=$_ifs diff --git a/test/setup-hook-syntax-gate.test.ts b/test/setup-hook-syntax-gate.test.ts index 33fa293bef3..d5d37713c80 100644 --- a/test/setup-hook-syntax-gate.test.ts +++ b/test/setup-hook-syntax-gate.test.ts @@ -110,7 +110,11 @@ function tmpBase(): string { } function check(root: string) { - const r = spawnSync('bash', [CHECK, root], { encoding: 'utf8', timeout: 30_000 }); + return checkFrom(root, ROOT); +} + +function checkFrom(root: string, cwd: string) { + const r = spawnSync('bash', [CHECK, root], { encoding: 'utf8', timeout: 30_000, cwd }); return { code: r.status, out: `${r.stdout}${r.stderr}` }; } @@ -246,6 +250,19 @@ describe('gstack-hook-check: what fails', () => { expect(r.code).toBe(0); }); + test('a malformed tsconfig.json or bunfig.toml in the caller\'s directory does not fail the hooks', () => { + // The auto-updater runs the check from whatever project the session is in. + const root = tmpBase(); + fixtureTree(root); + const project = path.join(tmpBase(), 'project'); + fs.mkdirSync(project); + fs.writeFileSync(path.join(project, 'tsconfig.json'), '{ this is not json\n'); + fs.writeFileSync(path.join(project, 'bunfig.toml'), '[test\nbroken\n'); + const r = checkFrom(root, project); + expect(r.out).not.toContain('fail '); + expect(r.code).toBe(0); + }); + test('a helper the auto-updater sources that does not parse fails its hook with the helper file and line', () => { const root = tmpBase(); fixtureTree(root); From 77fa6a8236c4b48ecbfb0c74c16fda824831b65e Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 01:48:59 +1100 Subject: [PATCH 07/10] docs(hook-check): name the helper chain and the metafile condition docs/troubleshooting.md now says the check follows the helpers a hook's helpers source (careful/bin/hook-extract.sh sources bin/gstack-state-root.sh), and that markers in an imported module are only found when bun's `build` supports --metafile. The header comment of test/setup-hook-syntax-gate.test.ts describes what the checker covers now. Co-Authored-By: Claude Opus 5.5 --- docs/troubleshooting.md | 11 +++++++---- test/setup-hook-syntax-gate.test.ts | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index de4fdac3db5..9af8da2e13c 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -573,11 +573,14 @@ that does not parse exits 2, which blocks the tool call it guards in every session. Setup parse-checks every hook it registers, and every hook a skill registers while it runs (`/autoplan`, `/careful`, `/freeze` and `/plan-ceo-review`; `/guard` reuses the `/careful` and `/freeze` checks, and -`/investigate` the `/freeze` one): the shim, the shell helpers it sources (such -as `careful/bin/hook-extract.sh`), and the TypeScript it runs with its local -imports. A merge conflict marker left in any of those files is refused too, as +`/investigate` the `/freeze` one): the shim, the shell helpers it sources and +what those source (such as `careful/bin/hook-extract.sh` and +`bin/gstack-state-root.sh`), and the TypeScript it runs with its local imports. +A merge conflict marker left in any of those files is refused too, as `unresolved merge conflict marker`, even when the file still parses: markers -inside a heredoc or a string do. It registers the hooks that parse, skips the +inside a heredoc or a string do. (Markers in an imported module are found when +your bun's `build` supports `--metafile`; otherwise only the entry file is +scanned for them.) It registers the hooks that parse, skips the ones listed, finishes the rest of the install, and exits non-zero. Claude Code runs hooks straight from `~/.claude/skills/gstack`, so a skipped hook that an earlier setup registered, or that a skill runs, keeps running the broken file diff --git a/test/setup-hook-syntax-gate.test.ts b/test/setup-hook-syntax-gate.test.ts index d5d37713c80..818a963c883 100644 --- a/test/setup-hook-syntax-gate.test.ts +++ b/test/setup-hook-syntax-gate.test.ts @@ -1,10 +1,13 @@ /** * Claude Code runs gstack's hook shims through /bin/sh. A shim that does not * parse exits 2, which for a PreToolUse hook blocks the tool call in every - * session. bin/gstack-hook-check parses every hook setup registers (the shim - * with the interpreter its shebang names, and each TypeScript entry it runs - * bundled with its local imports), and setup registers the hooks that parse, - * refuses the rest with file and line, and exits non-zero. + * session. bin/gstack-hook-check checks every hook setup registers and every + * hook a skill's frontmatter registers: the shim with the interpreter its + * shebang names, the shell helpers it sources (transitively), and each + * TypeScript entry it runs bundled with its local imports, and it refuses a + * merge conflict marker in any of those files even when the file parses. + * setup registers the hooks that pass, refuses the rest with file and line, + * and exits non-zero. * * The setup tests run the real hook sections of setup (canonical root, gate, * heal, SessionStart, plan-tune and Stop registration, and the final refusal) From 86e3bbb58e1fbf08e020b627332eb9189a5796f0 Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 00:49:29 +1100 Subject: [PATCH 08/10] chore(release): 1.91.34.0 VERSION 1.91.34.0 (bin/gstack-next-version: PATCH above main 1.91.33.0, #3059), package.json 1.91.34, the agents digest, and the CHANGELOG entry for the skill-hook, helper, import and conflict-marker checks. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 41 ++++++++++++++++++++++++++++++++++ VERSION | 2 +- agents-digest/gstack-AGENTS.md | 2 +- package.json | 2 +- 4 files changed, 44 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1c33189ee2..25b8abc7386 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,46 @@ # Changelog +## [1.91.34.0] - 2026-10-08 + +**The hook parse check now covers what skill hooks run.** +**A half-merged hook, helper or import no longer passes as `ok`.** + +`./setup` and the auto-updater parse-check gstack's hooks before Claude Code runs them. Until now that meant the hooks setup registers, plus /autoplan's. /careful, /freeze, /guard and /investigate run a PreToolUse check on your Bash, Edit and Write calls, and /plan-ceo-review runs a hand-off hook after Bash calls. None of those were checked, and neither was the helper script the /careful and /freeze checks share. The check now covers every hook a skill registers, the shell helpers each hook sources, and the TypeScript modules it imports. It also refuses a merge conflict marker in any of them, including markers that bash parses without complaint inside a heredoc or a string. + +### The numbers that matter + +Measured with `bin/gstack-hook-check .` on this tree: macOS, a shared 18-core machine at load average 15 to 19, six timed runs of each version. + +| | Before | After | +|---|---|---| +| Hooks checked | 6 | 9 | +| Shell helpers checked | 0 | 4 | +| Conflict markers that still parse (in a heredoc, a string or a template literal), in a hook, a helper or an imported module | `ok`, exit 0 | refused at the first marker, exit 1 | +| A malformed `tsconfig.json` or `bunfig.toml` in the directory the check runs from | every TypeScript hook fails | no effect | +| Time for the whole check | 0.35 to 0.40 s | 0.92 to 1.26 s | + +The extra 0.6 s pays for three more hooks, four helpers, and the local modules the TypeScript entries import. + +### What this means for you + +If a pull or a merge leaves a /careful or /freeze check, or the helper they share, half-merged, `./setup` names the file and line, and the auto-updater holds the update. Before, the skill blocked or prompted on your tool calls until you found the file yourself. The auto-updater also stops holding updates because the project you happen to be in has a broken `tsconfig.json`. Nothing to do: run `./setup` as usual. + +### Itemized changes + +#### Fixed + +- `bin/gstack-hook-check` also checks every gstack path a skill's frontmatter hook command runs (`SKILL.md` and each `/SKILL.md`): `careful/bin/check-careful.sh`, `freeze/bin/check-freeze.sh`, `plan-ceo-review/bin/mode-handoff-hook`, and the /autoplan hook it used to name by hand. It reads CRLF `SKILL.md` files and runs under BusyBox awk. +- It parses each shell helper a hook sources, and what those source in turn: every `# shellcheck source=` path, and every `*.sh` path on a line that runs `.` or `source`, or assigned to a variable such a line sources. That is `careful/bin/hook-extract.sh` and the `bin/gstack-state-root.sh` it sources, and the three files `bin/gstack-session-update` sources. A script a hook only runs is not parsed as its helper. +- TypeScript hooks are bundled from the gstack tree, not the directory the check runs from, so a malformed `tsconfig.json` or `bunfig.toml` there no longer fails every TypeScript hook. The auto-updater runs the check from your current project. +- It refuses a merge conflict marker (`<<<<<<<`, `|||||||` or `>>>>>>>` at the start of a line) in a hook, its helpers, its TypeScript entry, and every local module the entry bundles, as `unresolved merge conflict marker`, even when the file parses. A bare `=======` line is not a marker. With a bun whose `build` has no `--metafile`, only the entry is scanned among the TypeScript files. +- `docs/troubleshooting.md` describes this for setup and for the auto-updater. + +#### For contributors + +- `test/setup-hook-syntax-gate.test.ts` derives the skill hooks and each hook's helpers on its own, and its fixture tree carries both. It adds 15 cases; 11 of them, and the rewritten list test, fail against the previous check. The setup cases get 120 s budgets. + +Contributed by @BenjaminDSmithy. + ## [1.91.33.0] - 2026-10-06 **A red eval case now gets one clear verdict from its measurement: meets, qualified, extend once, or fix.** diff --git a/VERSION b/VERSION index 8438d0e22e1..4101e586df7 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.91.33.0 +1.91.34.0 diff --git a/agents-digest/gstack-AGENTS.md b/agents-digest/gstack-AGENTS.md index 0ff5675e634..b8eaa0b1531 100644 --- a/agents-digest/gstack-AGENTS.md +++ b/agents-digest/gstack-AGENTS.md @@ -1,4 +1,4 @@ -# gstack digest v1.91.33.0 — regenerate/re-copy after upgrading gstack +# gstack digest v1.91.34.0 — regenerate/re-copy after upgrading gstack Behavioral rules from gstack (https://github.com/garrytan/gstack), compressed for agent hosts without a full skill install. The full skills add workflows, diff --git a/package.json b/package.json index 4334cbfe3eb..61274078b71 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gstack", - "version": "1.91.33", + "version": "1.91.34", "description": "Garry's Stack — Claude Code skills + fast headless browser. One repo, one install, entire AI engineering workflow.", "license": "MIT", "type": "module", From c5967d84c0dafe0d8a89124a5ee5fc243080db0d Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 18:41:35 +1100 Subject: [PATCH 09/10] fix(hook-check): always check /autoplan's hook, frontmatter or not The skill-frontmatter read replaced the line that named autoplan/bin/phase-publication-hook outright, so a tree without autoplan/SKILL.md stopped listing or checking it. gstack-doctor's test fixture (#3069) is such a tree: it copies setup and a few bin/ files, then expects a broken autoplan shim to fail the hooks row, and got ok (free-suite shard 18 on this PR). - bin/gstack-hook-check: hook_list names the autoplan hook again between setup's hooks and the frontmatter hooks; the existing dedupe keeps the real tree's list unchanged. - test/setup-hook-syntax-gate.test.ts: new case, a fixture without autoplan/SKILL.md still lists the hook and fails a broken shim (seen failing on the previous checker). The run-not-source case now asserts ok and no fail line instead of the exact output, which gains main's 'missing autoplan/...' line on a tree with no autoplan. Tests: gstack-doctor 15/15, setup-hook-syntax-gate 29/29. Co-Authored-By: Claude Opus 5.5 --- bin/gstack-hook-check | 4 ++++ test/setup-hook-syntax-gate.test.ts | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bin/gstack-hook-check b/bin/gstack-hook-check index 2ec0dd42001..9f8bb44d84e 100755 --- a/bin/gstack-hook-check +++ b/bin/gstack-hook-check @@ -84,8 +84,12 @@ frontmatter_hooks() { ' "${skills[@]}" } +# /autoplan's hook is named outright as well as read from its frontmatter: a +# tree without autoplan/SKILL.md (a partial copy, gstack-doctor's test fixture) +# still checks it, as it did before the frontmatter read. hook_list() { sed -n 's/.*\$(_hook_command_path \([A-Za-z0-9._/-]*\).*/\1/p' "$SETUP_FILE" 2>/dev/null + echo autoplan/bin/phase-publication-hook frontmatter_hooks } HOOKS=$(hook_list | awk '!seen[$0]++') diff --git a/test/setup-hook-syntax-gate.test.ts b/test/setup-hook-syntax-gate.test.ts index 818a963c883..800aa27feb1 100644 --- a/test/setup-hook-syntax-gate.test.ts +++ b/test/setup-hook-syntax-gate.test.ts @@ -162,6 +162,19 @@ describe('gstack-hook-check: the hook list is the registration code', () => { expect([...listHooks(root)].sort()).toEqual([...HOOKS].sort()); }); + test('a tree without autoplan/SKILL.md still lists and checks /autoplan\'s hook', () => { + // gstack-doctor's test fixture copies setup and a few bin/ files, no skill + // directories, and expects a broken autoplan shim to fail the hooks row. + const root = tmpBase(); + fixtureTree(root); + fs.rmSync(path.join(root, 'autoplan', 'SKILL.md')); + expect(listHooks(root)).toContain('autoplan/bin/phase-publication-hook'); + fs.writeFileSync(path.join(root, 'autoplan/bin/phase-publication-hook'), '#!/bin/sh\nif then\n'); + const r = check(root); + expect(r.code).toBe(1); + expect(r.out).toContain('fail autoplan/bin/phase-publication-hook'); + }); + test('every shipped hook in this checkout passes', () => { const r = check(ROOT); expect(r.code).toBe(0); @@ -249,7 +262,8 @@ describe('gstack-hook-check: what fails', () => { fs.writeFileSync(path.join(root, 'hooks/plain'), '#!/bin/sh\nexec "$(dirname "$0")/worker.sh" "$@"\n', { mode: 0o755 }); fs.writeFileSync(path.join(root, 'hooks/worker.sh'), '#!/usr/bin/env bash\nwhile read -r l; do echo "$l"; done < <(echo a)\n', { mode: 0o755 }); const r = check(root); - expect(r.out.trim()).toBe('ok hooks/plain'); + expect(r.out).toContain('ok hooks/plain'); + expect(r.out).not.toContain('fail '); expect(r.code).toBe(0); }); From d5f032515569c85d10542092663a06d3d0fee6fd Mon Sep 17 00:00:00 2001 From: "Benjamin D. Smith" Date: Thu, 8 Oct 2026 18:43:58 +1100 Subject: [PATCH 10/10] fix(hook-check): keep a Windows root absolute Making ROOT absolute treated only a leading / as absolute, so a Windows root such as D:\a\_temp\...\gstack became $PWD/D:\a\..., a path that names nothing, so setup's hooks could not be read. Every gstack-doctor case on windows-free-shard 1 failed with EISDIR in its fixture, which writes each listed hook: an empty list makes it write to path.join(root, ''), the tree root. - bin/gstack-hook-check: a drive path (D:\, D:/) or a UNC path (\\host\share) is kept as given; anything else is still prefixed with $PWD. Checked under /bin/bash, Homebrew bash 5.3 and /bin/sh for /a/b, D:\a\gstack, D:/a/gstack, c:\x, \\host\share (kept) and rel/dir, D:rel, ., gstack (prefixed). Windows CI runs test/gstack-doctor.test.ts, which covers this. Co-Authored-By: Claude Opus 5.5 --- bin/gstack-hook-check | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/gstack-hook-check b/bin/gstack-hook-check index 9f8bb44d84e..c1134ad2a53 100755 --- a/bin/gstack-hook-check +++ b/bin/gstack-hook-check @@ -54,7 +54,9 @@ if [ -z "$ROOT" ] || [ ! -d "$ROOT" ]; then exit 2 fi # Absolute, so the bundles below can run from the tree root (see BUILD_DIR). -case "$ROOT" in /*) ;; *) ROOT="$PWD/$ROOT" ;; esac +# A Windows root (`D:\a\gstack`, `D:/a/gstack`, `\\host\share`) is already +# absolute: prefixing $PWD would point every path at nothing. +case "$ROOT" in /* | [A-Za-z]:[\\/]* | \\\\*) ;; *) ROOT="$PWD/$ROOT" ;; esac [ "$ROOT" = / ] || ROOT=${ROOT%/} SETUP_FILE="${SETUP_FILE:-$ROOT/setup}"