Skip to content
Closed
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
41 changes: 41 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# Changelog

## [1.91.48.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>/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.42.0] - 2026-10-08

**/cso lifts its file-count ceiling: repositories with tens of thousands of files reach the audit.**
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.91.42.0
1.91.48.0
2 changes: 1 addition & 1 deletion agents-digest/gstack-AGENTS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# gstack digest v1.91.42.0 — regenerate/re-copy after upgrading gstack
# gstack digest v1.91.48.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,
Expand Down
229 changes: 221 additions & 8 deletions bin/gstack-hook-check
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,23 @@
#
# The hook list comes from the registration code: every
# `_hook_command_path <path>` argument in <root>/setup (or the setup named by
# --setup, when another tree's setup registers <root>'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 <root>'s hooks), plus every
# gstack path a skill's frontmatter hook command runs (<root>/SKILL.md and
# <root>/*/SKILL.md: /autoplan's phase-publication hook, and the /careful and
# /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 `<name>.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.
# 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 `<name>.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:
# ok <hook>
Expand All @@ -44,11 +53,46 @@ if [ -z "$ROOT" ] || [ ! -d "$ROOT" ]; then
echo "usage: gstack-hook-check [--setup <file>] [--list] <gstack root>" >&2
exit 2
fi
# Absolute, so the bundles below can run from the tree root (see BUILD_DIR).
# 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}"

# 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 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
[ -f "$f" ] && skills+=("$f")
done
[ "${#skills[@]}" -gt 0 ] || return 0
awk '
{ 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._/-]+")) {
print substr(s, RSTART + 14, RLENGTH - 14)
s = substr(s, RSTART + RLENGTH)
}
}
' "${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]++')

Expand All @@ -64,6 +108,17 @@ 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
# 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 <file> <tool output> — "<file>:<line>" from bun's "at f:l:c"
# or bash's "f: line N:" (falls back to <file>).
Expand All @@ -82,6 +137,130 @@ first_message() {
FAILED=0
fail() { echo "fail $1 $2: $3"; FAILED=1; }

NL='
'

# report_markers <hook> <files, one per line> — 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 <file> — the shell files <file> sources directly: each path a
# `# shellcheck source=<path>` 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 <file>'s.
# A path resolves from the tree root, then beside <file>, 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 <root>.
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 <shim> — 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 <metafile> — 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 <path> — 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
Expand All @@ -100,18 +279,52 @@ for hook in $HOOKS; do
fail "$hook" "$(first_location "$shim" "$err")" "$(first_message "$err")"
hook_ok=0
fi
_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
fail "$hook" "$dir/$entry:1" "missing TypeScript entry (the hook runs it)"
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=$(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
_scan="$_scan$NL$dir/$entry"
# Every other local module the entry bundles.
_inputs=""
[ -f "$meta" ] && _inputs=$(metafile_inputs "$meta")
[ -n "$_inputs" ] || continue
_entry_rel="${dir#"$ROOT"/}/$entry"
IFS=$NL
for rel in $_inputs; do
IFS=$_ifs
[ "$rel" != "$_entry_rel" ] || continue
# Inside the tree: report it under <root> as given, so a caller that
# strips its own <root>/ 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
done
report_markers "$hook" "$_scan" || hook_ok=0
[ "$hook_ok" -eq 1 ] && echo "ok $hook"
done
exit "$FAILED"
25 changes: 18 additions & 7 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -615,12 +615,21 @@ 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
is fixed. This is a gstack bug, or a half-applied edit or merge in your
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 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. (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
until it is fixed. This is a gstack bug, or a half-applied edit or merge in your
checkout: report the printed `<file>:<line>`.

**Fix.**
Expand All @@ -637,7 +646,9 @@ cd ~/.claude/skills/gstack && ./setup
### `gstack auto-update: update held (hook-does-not-parse: <file>:<line>: <error>); 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 `<file>:<line>`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gstack",
"version": "1.91.42",
"version": "1.91.48",
"description": "Garry's Stack — Claude Code skills + fast headless browser. One repo, one install, entire AI engineering workflow.",
"license": "MIT",
"type": "module",
Expand Down
Loading
Loading