Hook chain repairs (Group A):
- alignment-check.sh: read .prompt (was .user_prompt) — hook was dead
- block-dangerous.sh: jq instead of inline interpreter (RULE 0.2 + fail-open fix)
- destructive-guard.sh: explicit INPUT=cat + jq guard + exit 0 — was silent no-op
- numeric-claims-guard.sh: exit 1 -> exit 2 (Claude Code spec — was non-blocking)
comments updated 0.17 -> 0.18 (env var name kept)
- no-downgrade.sh: removed (?i) PCRE syntax — POSIX ERE matched literal text
- task-timer.sh: jq -nc instead of bare printf — JSON injection on quotes/backslashes
in description was corrupting RULE 0.18 evidence journal
- check-error-patterns.sh: replaced with no-op stub — had hardcoded /Users/denis/...
PATH LEAK in public kit, plus inline interpreter use
- post-commit-audit.sh: added trailing exit 0 — grep return code was hook exit code
- citation-verify.sh: ALLOW_REGEX accepts HOOK-BYPASS marker — bypass was documented
but never matched
- settings-snippet.json: agent-stub-scan moved PreToolUse:Agent -> PostToolUse:Agent
(RULE 0.16 enforcement was firing before transcript existed)
- check-error-patterns hook removed from settings-snippet.json
New defensive hooks (Group H):
- no-github-push.sh: PreToolUse:Bash hard deny on github.com push/create/sync/remote-add
(RULE 0.1 — patent IP protection; was missing from public kit)
- secrets-pre-guard.sh: PreToolUse:Edit|Write — token-pattern scan with allowlist (RULE 0.8)
- chat-numeric-prewarn.sh: UserPromptSubmit reminder when prompt mentions time/cost
(RULE 0.18 chat extension)
- chat-numeric-postflag.sh: Stop event scans last assistant message for naked numerics
without REAL/FROM-JOURNAL/ESTIMATE-HTC markers
Source: full Sonnet test-retest audit 2026-05-02 (3 parallel waves of 6 agents each)
identified hook chain bugs as HIGH severity in all 3 runs independently.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
77 lines
2.4 KiB
Bash
Executable file
77 lines
2.4 KiB
Bash
Executable file
#!/bin/sh
|
|
# chat-numeric-postflag.sh — Stop warn (RULE 0.18 chat-output)
|
|
#
|
|
# Reads the session transcript, extracts the last assistant message,
|
|
# and scans it for naked numeric claims that lack a RULE 0.18 evidence
|
|
# marker within 100 characters of the number.
|
|
#
|
|
# Severity: warn — always exits 0, emits stderr on violation.
|
|
# Never blocks; this is a post-session audit hook.
|
|
#
|
|
# Bypass: set RULE_018_CHAT_BYPASS=1 in the calling environment.
|
|
|
|
set -u
|
|
|
|
if [ "${RULE_018_CHAT_BYPASS:-0}" = "1" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
if ! command -v jq > /dev/null 2>&1; then
|
|
exit 0
|
|
fi
|
|
|
|
INPUT=$(cat)
|
|
TRANSCRIPT_PATH=$(printf '%s' "$INPUT" \
|
|
| jq -r '.transcript_path // empty' 2>/dev/null)
|
|
|
|
[ -z "$TRANSCRIPT_PATH" ] && exit 0
|
|
[ ! -f "$TRANSCRIPT_PATH" ] && exit 0
|
|
|
|
# Extract last assistant message text from the JSONL transcript.
|
|
# Each line is a JSON object; assistant messages have role="assistant".
|
|
# We want the last one.
|
|
LAST_MSG=$(grep '"role":"assistant"' "$TRANSCRIPT_PATH" 2>/dev/null \
|
|
| tail -1 \
|
|
| jq -r '.content // empty' 2>/dev/null)
|
|
|
|
[ -z "$LAST_MSG" ] && exit 0
|
|
|
|
# Numeric claim pattern: optional ~ + digits + unit
|
|
# Units: min, hour, day, week, MB, GB, LOC, tests, crates, atomars, %, $N,
|
|
# минут, часов, дней, недель (Russian time units)
|
|
NUMERIC_RE='~?[0-9]+[[:space:]]*(min|minute|hour|hr|day|week|month|MB|GB|KB|LOC|test|crate|atomar|%|минут|часов|дней|недел)'
|
|
|
|
# Evidence marker pattern
|
|
MARKER_RE='\[REAL:|\[FROM-JOURNAL:|\[ESTIMATE-HTC:'
|
|
|
|
# Quick check: does the message contain any numeric claim at all?
|
|
if ! printf '%s' "$LAST_MSG" | grep -iqE "$NUMERIC_RE"; then
|
|
exit 0
|
|
fi
|
|
|
|
# Quick check: does the message contain at least one marker?
|
|
# If it does, we assume the author was compliant (shallow check).
|
|
# A deeper per-match proximity check would require awk/perl.
|
|
if printf '%s' "$LAST_MSG" | grep -qE "$MARKER_RE"; then
|
|
exit 0
|
|
fi
|
|
|
|
# No marker found anywhere in the message — extract a short excerpt for context
|
|
EXCERPT=$(printf '%s' "$LAST_MSG" \
|
|
| grep -ioE "$NUMERIC_RE" \
|
|
| head -3 \
|
|
| tr '\n' ' ')
|
|
|
|
COUNT=$(printf '%s' "$LAST_MSG" \
|
|
| grep -ioE "$NUMERIC_RE" \
|
|
| wc -l \
|
|
| tr -d ' ')
|
|
|
|
cat >&2 <<EOF
|
|
[chat-numeric-postflag] WARN — assistant emitted ${COUNT} naked numeric claim(s) without RULE 0.18 marker.
|
|
First example(s): ${EXCERPT}
|
|
Required markers: [REAL: ...] [FROM-JOURNAL: ...] [ESTIMATE-HTC: ...]
|
|
See: ~/.claude/rules/chat-numeric-pre-output.md
|
|
EOF
|
|
|
|
exit 0
|