mirror of
https://github.com/garrytan/gstack.git
synced 2026-09-27 15:11:47 +02:00
* fix(memory-ingest): --scan-secrets scans the rendered page and fails closed --scan-secrets ran gitleaks on the raw transcript .jsonl, then imported a page rendered from it. gitleaks' assignment rules don't match across a JSON-escaped quote (KEY=\"v\" on disk), so a secret the rendered page shows as KEY="v" was imported unflagged. And the gate skipped a file only on scanner "gitleaks" with findings, so a scan that errored (non-zero exit, 16MB maxBuffer overflow on a file with many findings, unparseable report) or could not run (gitleaks missing, slow-probe cooldown) imported the file unscanned. Scan the rendered page body, the exact bytes writeStaged() writes, via a new secretScanText() helper, and skip the file whenever the scan did not complete. Skipped files stay out of the state file, so the next run retries them. Reword the helper warnings and setup-gbrain/memory.md, which described the fail-open as intended. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(test): reconcile Bun failure markers and footer counts * fix(sync-gbrain): verify source-scoped reads without mutation * fix(test): recognize grounded TTHW target choices structurally * fix(aside): make the readiness probe work under zsh and report why it failed The probe built its deadline into `_T` and expanded it unquoted, so `$_T aside repl …` only worked in a shell that word-splits. zsh does not: it looked for a command literally named "gtimeout 30", the probe answered ASIDE_NOT_RUNNING with Aside installed and ready, and every browsing skill fell back to the bundled Chromium in silence. zsh is the macOS default and Aside is macOS-only, so on a stock Mac the probe could never report READY. The deadline becomes a function, `_gs_d`. It receives the command as "$@", already split, so sh, bash and zsh all behave the same, and the gtimeout → timeout → perl alarm chain is unchanged. A 4th arm runs the call unbounded when none of the three is present, which is what the empty `_T` did before. Not `eval`: it re-parses the string, so the parens and `;` of the perl arm become syntax and that arm dies in bash *and* zsh — on a stock Mac, the arm that actually runs. On failure the probe now prints the CLI's reason after ASIDE_NOT_RUNNING:, the shape gstack-render already uses: the first line that starts with a capital letter, i.e. the CLI's own sentence or Node's `Error:` line below its loader frame. "Not running" covers states with different fixes — no window open for the profile, a NODE_OPTIONS preload that kills the CLI — and a bare verdict sent all of them to "open the Aside app". The BROWSER SETUP prose quotes that reason before asking the user to open the app. The text pin asserted the broken invocation verbatim, so it now pins the function and asserts neither `$_T aside repl` nor an eval form comes back. A second test executes the rendered probe in sh, bash and zsh on each of the four deadline arms with stubbed binaries on a narrowed PATH, plus two failing CLIs: one that prints its own sentence, one that crashes like Node with the useful line below the frame. The deadline function costs zero bytes against the lines it replaces; the reason costs 53 per copy of the probe (44 where the reworded BROWSER SETUP line gives 9 back). That moves four guards by the measured amount: plan-devex-review's skeleton cap to 68,550 (measured 68,544), plan-ceo-review's skeleton cap to 80,150 (measured 80,111) and union ratio to 1.081 (measured 1.0803), and plan-eng-review's union ratio to 1.151 (measured 1.1504). Fixes #2842, #2941. * Clarify engineering review startup and decision flow * Fix Windows readiness fixture PATH and command shim * fix(test): recognize grounded TTHW target choices structurally * Clarify engineering review startup and decision flow * fix(test): restrict QA-only fixture tools to its no-Edit contract * v1.90.0.0 fix(sync-gbrain): guard readiness verdicts and refresh metadata * fix(browse): validate canonical upload targets * fix(gbrain): classify structured PGLite busy response * fix(browse): preserve native extension runtime APIs * Fix displayless browser handoff ownership * Accept unique installed autoplan methodology aliases * fix(skills): preserve positional literals during installation * fix(browse): checksum installer contents through stdin * fix(test): normalize Windows checksum fixture paths * test: emulate unavailable shasum in Windows checksum fixture * fix(investigate): preserve owned freeze lifecycle * fix(review): preserve N+1 retry and Red Team completion * fix: bound Aside readiness and preserve safe fallback * test: exercise setup and Chromium on native ARM * fix: preserve install ownership and ARM browser selection * Fix gbrain ingest scan boundaries and seed observation * Refresh managed ship hooks and supervise expanded paid census * Reject resumed gbrain pages excluded by current policy * Recover zombie agent locks safely and enable CI Python venv * Repair paid actor declarations and Aside pitch assertions * Bump consolidated wave to next free minor release * Clarify CEO review admin choices and option tradeoffs * Preserve CEO mode handoff anchors in clarified workflow * Make Windows portability fixtures use shell-native paths * Restore ARM Bun alias and clarify ship review gates * Refresh ship workflow golden snapshots * Fix Windows DX documentation controls without piped stdin * Decode Codex child pipes without Bun's encoded-stream stall * Bound DX pre-review audit before product questions * Clarify trusted review-start read in paid revalidation * Bump consolidated wave to next free minor release * Clarify CEO review admin choices and option tradeoffs * Preserve CEO mode handoff anchors in clarified workflow * Make Windows portability fixtures use shell-native paths * Restore ARM Bun alias and clarify ship review gates * Refresh ship workflow golden snapshots * Fix Windows DX documentation controls without piped stdin * Decode Codex child pipes without Bun's encoded-stream stall * Bound DX pre-review audit before product questions * Clarify trusted review-start read in paid revalidation * Reconcile new main planning flow and paid judge census * fix: reconcile rebased planning and source-bound validation * test: pin cookie workflow judge to scored Sonnet model * fix: keep terminal agent boot out of module imports * fix: preserve pending-question uncertainty in engineering review * fix: stabilize Windows reliability-wave fixtures * fix: clarify design consultation research workflow * fix: preserve independent design consultation inputs * fix: resolve design taste scope and browser research guidance * fix: make consultation opt-in preflight unambiguous * test: await native Edge owner readiness or terminal result --------- Co-authored-by: Bruce Krysiak <brucek@alum.mit.edu> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Antonio Vitalic <antoninte99@gmail.com>
184 lines
7.3 KiB
Bash
Executable File
184 lines
7.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# check-freeze.sh — PreToolUse hook for /freeze skill
|
|
# Reads JSON from stdin, checks if file_path is within the freeze boundary.
|
|
# Returns a PreToolUse hookSpecificOutput with permissionDecision "deny" to block,
|
|
# or {} to allow. The decision MUST be nested under hookSpecificOutput — Claude
|
|
# Code ignores a top-level permissionDecision, which silently no-ops the block.
|
|
#
|
|
# Polarity: freeze is a DENY-tier hook, so an unreadable payload DENIES
|
|
# (fail closed). A payload that parses but has no file_path is a non-file
|
|
# tool — allow. This is the opposite edge-handling from careful's ask-tier
|
|
# and intentionally so: /guard runs both, and a boundary that fails open is
|
|
# not a boundary.
|
|
set -euo pipefail
|
|
|
|
# Deny-tier backstop: any unexpected non-zero death (a failing pipeline under
|
|
# set -e, a deleted cwd, EACCES) would otherwise exit with no decision JSON,
|
|
# which Claude Code treats as non-blocking — the edit proceeds. Every
|
|
# deliberate output below sets _FREEZE_DECIDED first so a late failure after
|
|
# a decision never prints a second JSON object.
|
|
_FREEZE_DECIDED=""
|
|
_freeze_backstop() {
|
|
local rc=$?
|
|
if [ "$rc" -ne 0 ] && [ -z "$_FREEZE_DECIDED" ]; then
|
|
_FREEZE_DECIDED=1
|
|
printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"[freeze] Hook failed unexpectedly (exit %s) - blocked, fail closed. Re-run ./setup or /unfreeze."}}\n' "$rc"
|
|
exit 0
|
|
fi
|
|
}
|
|
trap _freeze_backstop EXIT
|
|
|
|
# Read stdin
|
|
INPUT=$(cat)
|
|
|
|
# Shared JSON helpers (extractor + encoder) — one copy for careful AND freeze.
|
|
# freeze previously carried its own grep-first extractor which truncated at
|
|
# escaped quotes and failed OPEN; the shared file kills that drift class.
|
|
_HOOK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# shellcheck source=careful/bin/hook-extract.sh
|
|
# Freeze is deny-tier: if its own helpers are missing/broken (partial install,
|
|
# mid-upgrade state), the boundary must fail CLOSED — inline JSON, since the
|
|
# encoder we would normally use lives in the file that just failed to load.
|
|
# NOTE: bash treats `.` on a MISSING file as fatal in non-interactive shells
|
|
# (an if-guard cannot catch it) — the existence check must come first.
|
|
_HOOK_HELPER="$_HOOK_DIR/../../careful/bin/hook-extract.sh"
|
|
if [ ! -f "$_HOOK_HELPER" ] || ! . "$_HOOK_HELPER" 2>/dev/null; then
|
|
_FREEZE_DECIDED=1
|
|
printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"[freeze] Hook helpers unavailable (broken install?) - blocked, fail closed. Reinstall gstack or run /unfreeze."}}\n'
|
|
exit 0
|
|
fi
|
|
|
|
# Locate the freeze directory state file. The writer (/freeze via
|
|
# gstack-paths) and this reader MUST resolve the same root or the boundary
|
|
# fails open: with GSTACK_HOME set, /freeze wrote freeze-dir.txt under
|
|
# GSTACK_HOME while this hook read $HOME/.gstack, found nothing, and allowed
|
|
# everything (#1459, #1509). gstack_hook_state_root mirrors gstack-paths.
|
|
# A helper from an older install that lacks the function must fail CLOSED
|
|
# (the existence check above only proves the file sourced), never exit 127
|
|
# with no JSON — Claude Code treats that as non-blocking.
|
|
if ! command -v gstack_hook_state_root >/dev/null 2>&1; then
|
|
_FREEZE_DECIDED=1
|
|
printf '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"[freeze] Hook helpers out of date (partial upgrade?) - blocked, fail closed. Re-run ./setup or /unfreeze."}}\n'
|
|
exit 0
|
|
fi
|
|
STATE_DIR="$(gstack_hook_state_root; printf x)"; STATE_DIR="${STATE_DIR%x}"
|
|
FREEZE_FILE="$STATE_DIR/freeze-dir.txt"
|
|
|
|
# If no freeze file exists, allow everything (not yet configured)
|
|
if [ ! -f "$FREEZE_FILE" ]; then
|
|
_FREEZE_DECIDED=1
|
|
echo '{}'
|
|
exit 0
|
|
fi
|
|
|
|
{
|
|
IFS= read -r FREEZE_DIR || true
|
|
IFS= read -r FREEZE_OWNER_LINE || true
|
|
} < "$FREEZE_FILE"
|
|
case "$FREEZE_OWNER_LINE" in
|
|
gstack-freeze-v1:*) ;;
|
|
*) FREEZE_DIR=$(printf '%s\n' "$FREEZE_DIR" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//') ;;
|
|
esac
|
|
# A literal leading ~ in the state file never matches absolute tool paths
|
|
# (tilde is not expanded from variables) — expand it here.
|
|
case "$FREEZE_DIR" in
|
|
"~/"*) FREEZE_DIR="$HOME/${FREEZE_DIR#\~/}" ;;
|
|
"~") FREEZE_DIR="$HOME" ;;
|
|
esac
|
|
|
|
# If freeze dir is empty, allow
|
|
if [ -z "$FREEZE_DIR" ]; then
|
|
_FREEZE_DECIDED=1
|
|
echo '{}'
|
|
exit 0
|
|
fi
|
|
|
|
case "$FREEZE_DIR" in
|
|
/*) ;;
|
|
*)
|
|
gstack_hook_decision deny '[freeze] Legacy relative boundary is ambiguous. Re-run /freeze with an absolute directory chosen by the user; the saved state was preserved.'
|
|
_FREEZE_DECIDED=1
|
|
exit 0
|
|
;;
|
|
esac
|
|
|
|
# Extract file_path from tool_input with the shared real-JSON parser.
|
|
set +e
|
|
FILE_PATH=$(gstack_hook_extract_field "$INPUT" file_path)
|
|
EXTRACT_RC=$?
|
|
set -e
|
|
|
|
# Unparseable payload (or no parser available): DENY. A boundary hook that
|
|
# allows what it cannot read is not a boundary.
|
|
if [ "$EXTRACT_RC" -ne 0 ] && [ -n "$INPUT" ]; then
|
|
gstack_hook_decision deny "[freeze] Could not parse the tool payload to check the freeze boundary. Blocked (fail closed). Freeze boundary: $FREEZE_DIR"
|
|
_FREEZE_DECIDED=1
|
|
exit 0
|
|
fi
|
|
|
|
# Parsed fine but no file_path field: a non-file tool payload — allow.
|
|
if [ -z "$FILE_PATH" ]; then
|
|
_FREEZE_DECIDED=1
|
|
echo '{}'
|
|
exit 0
|
|
fi
|
|
|
|
# Resolve file_path to absolute if it isn't already
|
|
case "$FILE_PATH" in
|
|
/*) ;; # already absolute
|
|
*)
|
|
FILE_PATH="$(pwd)/$FILE_PATH"
|
|
;;
|
|
esac
|
|
|
|
# Normalize: remove double slashes and trailing slash
|
|
FILE_PATH=$(printf '%s' "$FILE_PATH" | sed 's|/\+|/|g;s|/$||')
|
|
[ -n "$FILE_PATH" ] || FILE_PATH="/"
|
|
|
|
# Resolve symlinks and .. sequences (POSIX-portable, works on macOS).
|
|
# The FULL path is resolved, including the FINAL component: the previous
|
|
# version resolved only the parent directory, so an in-boundary symlink
|
|
# pointing at an out-of-boundary target sailed through the check while the
|
|
# actual write landed outside the boundary. A final component that is a
|
|
# symlink is followed (bounded, cycle-safe) so the TARGET gets checked; a
|
|
# final component that does not exist yet (new file) has nothing to follow
|
|
# and parent resolution is the correct behavior.
|
|
_resolve_path() {
|
|
local _p="$1" _dir _base _tgt _i=0
|
|
while [ -L "$_p" ] && [ "$_i" -lt 40 ]; do
|
|
_tgt=$(readlink "$_p" 2>/dev/null) || break
|
|
case "$_tgt" in
|
|
/*) _p="$_tgt" ;;
|
|
*) _p="$(dirname "$_p")/$_tgt" ;;
|
|
esac
|
|
_i=$((_i + 1))
|
|
done
|
|
_dir="$(dirname "$_p")"
|
|
_base="$(basename "$_p")"
|
|
if [ "$_base" = / ]; then printf '/'; return; fi
|
|
_dir="$(cd "$_dir" 2>/dev/null && pwd -P || printf '%s' "$_dir")"
|
|
printf '%s/%s' "${_dir%/}" "$_base"
|
|
}
|
|
FILE_PATH=$(_resolve_path "$FILE_PATH")
|
|
FREEZE_DIR=$(_resolve_path "$FREEZE_DIR")
|
|
|
|
# Check: does the file path start with the freeze directory?
|
|
case "$FILE_PATH" in
|
|
"${FREEZE_DIR%/}/"*|"${FREEZE_DIR}")
|
|
# Inside freeze boundary — allow
|
|
_FREEZE_DECIDED=1
|
|
echo '{}'
|
|
;;
|
|
*)
|
|
# Outside freeze boundary — deny
|
|
# Log hook fire event (shared helper respects GSTACK_HOME)
|
|
gstack_hook_log_fire freeze boundary_deny
|
|
|
|
# The reason is JSON-encoded by the shared helper. Never interpolate paths
|
|
# into hand-built JSON: a path containing a quote or newline produced
|
|
# malformed JSON here, and the deny silently no-oped.
|
|
gstack_hook_decision deny "[freeze] Blocked: $FILE_PATH is outside the freeze boundary ($FREEZE_DIR). Only edits within the frozen directory are allowed."
|
|
_FREEZE_DECIDED=1
|
|
;;
|
|
esac
|