Spaces:
Sleeping
gates: sync to final DECODE hardening pattern
Browse filesBrings this branch up to the version now on PBI_team_utils/master and
icat_results/master. Closes gaps that were found by reviewer-subagent
passes on those two repos.
Hardening files (hook scripts, commit-msg gate, language-gate, setup,
settings.json, gate.yml workflow, .gitignore) are byte-identical copies
from PBI_team_utils/master. Kleo's icat_app-specific "## This repo"
section in CLAUDE.md is preserved verbatim.
Key closures vs the pre-fix version on this branch:
- scripts/reviewer-hash.sh (new): hashes git diff HEAD + untracked file
contents. Closes a real bypass where an agent could create a new file,
pass the reviewer, then silently edit the new file β the marker would
still validate because plain `git diff HEAD` misses untracked files.
- .claude/hooks/ensure-setup.sh (new): SessionStart hook auto-wires
core.hooksPath to .githooks on first Claude Code session. No one has
to remember `bash scripts/setup.sh`. Idempotent, warns without
overwriting if a conflicting hooks path is already set.
- block-dangerous-git.sh: expanded branch-delete coverage (-df, -fd,
-d -f, -d --force, --delete -f, all orders β 11 realistic combos);
CLAUDE_PROJECT_DIR-anchored tier detection; POSIX [[:space:]]
instead of non-POSIX \\s in rm patterns.
- block-env-writes.sh: *service-account*.json wildcard (catches
firebase-service-account-prod.json and similar).
- settings.json: adds Bash(git hash-object:*) and
Bash(bash scripts/reviewer-hash.sh) to permissions.allow.
- commit-msg, reviewer-stop.sh: use the hash helper; absolute
\$REPO_ROOT paths; --diff-filter=ACMR (not ACMRD).
- CLAUDE.md procedure: tells Claude to compute DIFF_HASH via
`bash scripts/reviewer-hash.sh`.
- .github/workflows/gate.yml: override-audit job runs on push events
too; event-aware range with root-commit fallback.
- Substantive-files pattern narrowed: dropped ^output/|^dist/.
- Hook error messages: dropped stale "rule NN" references.
Reviewer subagent ran before this commit and reported clean.
- .claude/hooks/block-dangerous-git.sh +15 -7
- .claude/hooks/block-env-writes.sh +1 -1
- .claude/hooks/ensure-setup.sh +47 -0
- .claude/hooks/reviewer-stop.sh +12 -9
- .claude/settings.json +12 -0
- .githooks/commit-msg +8 -7
- .github/workflows/gate.yml +19 -5
- CLAUDE.md +4 -4
- scripts/reviewer-hash.sh +33 -0
|
@@ -25,11 +25,14 @@ if [ -z "$COMMAND" ]; then
|
|
| 25 |
exit 0
|
| 26 |
fi
|
| 27 |
|
| 28 |
-
# Detect tier
|
|
|
|
|
|
|
|
|
|
| 29 |
TIER="data"
|
| 30 |
-
if [ -f "package.json" ] && [ ! -f "pyproject.toml" ] && [ ! -f "setup.py" ]; then
|
| 31 |
TIER="product"
|
| 32 |
-
elif [ -f "pom.xml" ] || [ -f "build.gradle" ] || [ -f "build.gradle.kts" ]; then
|
| 33 |
TIER="product"
|
| 34 |
fi
|
| 35 |
|
|
@@ -43,9 +46,14 @@ BLOCKED_ALL=(
|
|
| 43 |
"git[[:space:]]+push[[:space:]]+-f([[:space:]]|$)"
|
| 44 |
"git[[:space:]]+reset[[:space:]]+--hard"
|
| 45 |
"git[[:space:]]+clean[[:space:]]+-[a-z]*f"
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
)
|
| 50 |
|
| 51 |
# Patterns blocked only in PRODUCT tier
|
|
@@ -64,7 +72,7 @@ Command: $COMMAND
|
|
| 64 |
|
| 65 |
Destructive operations require explicit user sign-off. If the user asked
|
| 66 |
for this, the model should surface the command in chat for confirmation
|
| 67 |
-
before invoking the tool.
|
| 68 |
EOF
|
| 69 |
exit 2
|
| 70 |
fi
|
|
|
|
| 25 |
exit 0
|
| 26 |
fi
|
| 27 |
|
| 28 |
+
# Detect tier. Use CLAUDE_PROJECT_DIR if available so a subdirectory cwd
|
| 29 |
+
# can't silently downgrade a product-tier repo to data-tier by missing
|
| 30 |
+
# package.json in the current working directory.
|
| 31 |
+
TIER_BASE="${CLAUDE_PROJECT_DIR:-$PWD}"
|
| 32 |
TIER="data"
|
| 33 |
+
if [ -f "$TIER_BASE/package.json" ] && [ ! -f "$TIER_BASE/pyproject.toml" ] && [ ! -f "$TIER_BASE/setup.py" ]; then
|
| 34 |
TIER="product"
|
| 35 |
+
elif [ -f "$TIER_BASE/pom.xml" ] || [ -f "$TIER_BASE/build.gradle" ] || [ -f "$TIER_BASE/build.gradle.kts" ]; then
|
| 36 |
TIER="product"
|
| 37 |
fi
|
| 38 |
|
|
|
|
| 46 |
"git[[:space:]]+push[[:space:]]+-f([[:space:]]|$)"
|
| 47 |
"git[[:space:]]+reset[[:space:]]+--hard"
|
| 48 |
"git[[:space:]]+clean[[:space:]]+-[a-z]*f"
|
| 49 |
+
# branch delete-with-force: -D shorthand, combined short flags,
|
| 50 |
+
# longform pairs, and mixed-order combinations.
|
| 51 |
+
"git[[:space:]]+branch[[:space:]]+-[a-zA-Z]*D"
|
| 52 |
+
"git[[:space:]]+branch[[:space:]]+-[a-zA-Z]*(df|fd)[a-zA-Z]*([[:space:]]|$)"
|
| 53 |
+
"git[[:space:]]+branch[[:space:]]+.*(-d[[:space:]]|--delete[[:space:]]).*(-f([[:space:]]|$)|--force([[:space:]]|$))"
|
| 54 |
+
"git[[:space:]]+branch[[:space:]]+.*(-f[[:space:]]|--force[[:space:]]).*(-d([[:space:]]|$)|--delete([[:space:]]|$))"
|
| 55 |
+
"(^|[^a-zA-Z0-9_/])rm[[:space:]]+-[a-z]*r[a-z]*f[a-z]*[[:space:]]+/([[:space:]]|$)"
|
| 56 |
+
"(^|[^a-zA-Z0-9_/])rm[[:space:]]+-[a-z]*r[a-z]*f[a-z]*[[:space:]]+~/?([[:space:]]|$)"
|
| 57 |
)
|
| 58 |
|
| 59 |
# Patterns blocked only in PRODUCT tier
|
|
|
|
| 72 |
|
| 73 |
Destructive operations require explicit user sign-off. If the user asked
|
| 74 |
for this, the model should surface the command in chat for confirmation
|
| 75 |
+
before invoking the tool.
|
| 76 |
EOF
|
| 77 |
exit 2
|
| 78 |
fi
|
|
@@ -25,7 +25,7 @@ BASENAME=$(basename "$FILE_PATH")
|
|
| 25 |
|
| 26 |
# Denylist patterns (exact basename or glob-style)
|
| 27 |
case "$BASENAME" in
|
| 28 |
-
.env|.env.local|.env.*|credentials|credentials.*|*.pem|*.key|*.pfx|id_rsa|id_rsa.*|service-account.json)
|
| 29 |
cat >&2 <<EOF
|
| 30 |
BLOCKED: write to '$FILE_PATH' denied.
|
| 31 |
|
|
|
|
| 25 |
|
| 26 |
# Denylist patterns (exact basename or glob-style)
|
| 27 |
case "$BASENAME" in
|
| 28 |
+
.env|.env.local|.env.*|credentials|credentials.*|*.pem|*.key|*.pfx|id_rsa|id_rsa.*|*service-account*.json)
|
| 29 |
cat >&2 <<EOF
|
| 30 |
BLOCKED: write to '$FILE_PATH' denied.
|
| 31 |
|
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE SessionStart hook.
|
| 4 |
+
# Ensures .githooks is wired to git via core.hooksPath so the commit-msg
|
| 5 |
+
# and pre-commit gates fire on every commit β whether invoked from
|
| 6 |
+
# Claude Code or the terminal.
|
| 7 |
+
#
|
| 8 |
+
# Runs once per Claude Code session start. Idempotent. Silent on success;
|
| 9 |
+
# warns (non-blocking) if setup.sh fails so the user can debug.
|
| 10 |
+
|
| 11 |
+
set -euo pipefail
|
| 12 |
+
|
| 13 |
+
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
| 14 |
+
exit 0
|
| 15 |
+
fi
|
| 16 |
+
|
| 17 |
+
cd "$(git rev-parse --show-toplevel)"
|
| 18 |
+
|
| 19 |
+
if [ ! -x "scripts/setup.sh" ]; then
|
| 20 |
+
exit 0
|
| 21 |
+
fi
|
| 22 |
+
|
| 23 |
+
CURRENT=$(git config --local --get core.hooksPath 2>/dev/null || true)
|
| 24 |
+
|
| 25 |
+
if [ "$CURRENT" = ".githooks" ]; then
|
| 26 |
+
# Already wired to our hooks β nothing to do.
|
| 27 |
+
exit 0
|
| 28 |
+
fi
|
| 29 |
+
|
| 30 |
+
if [ -n "$CURRENT" ]; then
|
| 31 |
+
# core.hooksPath is set to something other than .githooks. Don't
|
| 32 |
+
# silently overwrite β warn the user and exit. Our hardening gates
|
| 33 |
+
# (commit-msg, pre-commit) will NOT fire from their current path.
|
| 34 |
+
echo >&2 "[ensure-setup] WARN: core.hooksPath is set to '$CURRENT', not '.githooks'."
|
| 35 |
+
echo >&2 "[ensure-setup] This repo's commit-msg and pre-commit gates will not fire."
|
| 36 |
+
echo >&2 "[ensure-setup] Either unset it (\`git config --unset core.hooksPath\`) or"
|
| 37 |
+
echo >&2 "[ensure-setup] make sure '$CURRENT' routes to the hooks in .githooks/."
|
| 38 |
+
exit 0
|
| 39 |
+
fi
|
| 40 |
+
|
| 41 |
+
# core.hooksPath is unset β wire it via setup.sh.
|
| 42 |
+
if ! bash scripts/setup.sh >/dev/null 2>&1; then
|
| 43 |
+
echo >&2 "[ensure-setup] WARN: scripts/setup.sh failed β git hooks may not be wired."
|
| 44 |
+
echo >&2 "[ensure-setup] Run 'bash scripts/setup.sh' manually to debug."
|
| 45 |
+
fi
|
| 46 |
+
|
| 47 |
+
exit 0
|
|
@@ -15,12 +15,13 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
|
| 15 |
exit 0
|
| 16 |
fi
|
| 17 |
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
PATTERNS='\.(py|ts|tsx|js|jsx|R|r|java|sql)$|^scripts/
|
| 21 |
|
| 22 |
MODIFIED=$( {
|
| 23 |
-
git diff --name-only --diff-filter=
|
| 24 |
git ls-files --others --exclude-standard 2>/dev/null || true
|
| 25 |
git diff --cached --name-only --diff-filter=ACMR 2>/dev/null || true
|
| 26 |
} | sort -u )
|
|
@@ -30,15 +31,17 @@ if ! echo "$MODIFIED" | grep -qE "$PATTERNS"; then
|
|
| 30 |
fi
|
| 31 |
|
| 32 |
# Marker format (one line): <HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>
|
| 33 |
-
# DIFF-HASH
|
| 34 |
-
#
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
MARKED_SHA=$(awk 'NR==1 {print $1}' "$MARKER" 2>/dev/null || echo "")
|
| 39 |
MARKED_DIFF=$(awk 'NR==1 {print $2}' "$MARKER" 2>/dev/null || echo "")
|
| 40 |
CURRENT_SHA=$(git rev-parse HEAD 2>/dev/null || echo "initial")
|
| 41 |
-
CURRENT_DIFF=$(
|
| 42 |
if [ -n "$MARKED_SHA" ] && [ -n "$MARKED_DIFF" ] \
|
| 43 |
&& [ "$MARKED_SHA" = "$CURRENT_SHA" ] \
|
| 44 |
&& [ "$MARKED_DIFF" = "$CURRENT_DIFF" ]; then
|
|
|
|
| 15 |
exit 0
|
| 16 |
fi
|
| 17 |
|
| 18 |
+
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
| 19 |
+
cd "$REPO_ROOT"
|
| 20 |
|
| 21 |
+
PATTERNS='\.(py|ts|tsx|js|jsx|R|r|java|sql)$|^scripts/'
|
| 22 |
|
| 23 |
MODIFIED=$( {
|
| 24 |
+
git diff --name-only --diff-filter=ACMR HEAD 2>/dev/null || true
|
| 25 |
git ls-files --others --exclude-standard 2>/dev/null || true
|
| 26 |
git diff --cached --name-only --diff-filter=ACMR 2>/dev/null || true
|
| 27 |
} | sort -u )
|
|
|
|
| 31 |
fi
|
| 32 |
|
| 33 |
# Marker format (one line): <HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>
|
| 34 |
+
# DIFF-HASH is computed by scripts/reviewer-hash.sh, which covers both
|
| 35 |
+
# tracked diffs (git diff HEAD) AND untracked file contents. Binding to
|
| 36 |
+
# the hash means any edit made after the reviewer cleared β whether to
|
| 37 |
+
# tracked OR untracked files β invalidates the marker.
|
| 38 |
+
MARKER="$REPO_ROOT/.decode-reviewer-clean"
|
| 39 |
+
HASH_SCRIPT="$REPO_ROOT/scripts/reviewer-hash.sh"
|
| 40 |
+
if [ -f "$MARKER" ] && [ -x "$HASH_SCRIPT" ]; then
|
| 41 |
MARKED_SHA=$(awk 'NR==1 {print $1}' "$MARKER" 2>/dev/null || echo "")
|
| 42 |
MARKED_DIFF=$(awk 'NR==1 {print $2}' "$MARKER" 2>/dev/null || echo "")
|
| 43 |
CURRENT_SHA=$(git rev-parse HEAD 2>/dev/null || echo "initial")
|
| 44 |
+
CURRENT_DIFF=$(bash "$HASH_SCRIPT" 2>/dev/null || echo "")
|
| 45 |
if [ -n "$MARKED_SHA" ] && [ -n "$MARKED_DIFF" ] \
|
| 46 |
&& [ "$MARKED_SHA" = "$CURRENT_SHA" ] \
|
| 47 |
&& [ "$MARKED_DIFF" = "$CURRENT_DIFF" ]; then
|
|
@@ -19,6 +19,8 @@
|
|
| 19 |
"Bash(git diff)",
|
| 20 |
"Bash(git diff:*)",
|
| 21 |
"Bash(git rev-parse HEAD)",
|
|
|
|
|
|
|
| 22 |
"Bash(git log)",
|
| 23 |
"Bash(git log:*)",
|
| 24 |
"Bash(git status)",
|
|
@@ -59,6 +61,16 @@
|
|
| 59 |
}
|
| 60 |
]
|
| 61 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
]
|
| 63 |
}
|
| 64 |
}
|
|
|
|
| 19 |
"Bash(git diff)",
|
| 20 |
"Bash(git diff:*)",
|
| 21 |
"Bash(git rev-parse HEAD)",
|
| 22 |
+
"Bash(git hash-object:*)",
|
| 23 |
+
"Bash(bash scripts/reviewer-hash.sh)",
|
| 24 |
"Bash(git log)",
|
| 25 |
"Bash(git log:*)",
|
| 26 |
"Bash(git status)",
|
|
|
|
| 61 |
}
|
| 62 |
]
|
| 63 |
}
|
| 64 |
+
],
|
| 65 |
+
"SessionStart": [
|
| 66 |
+
{
|
| 67 |
+
"hooks": [
|
| 68 |
+
{
|
| 69 |
+
"type": "command",
|
| 70 |
+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/ensure-setup.sh"
|
| 71 |
+
}
|
| 72 |
+
]
|
| 73 |
+
}
|
| 74 |
]
|
| 75 |
}
|
| 76 |
}
|
|
@@ -33,7 +33,7 @@ fi
|
|
| 33 |
|
| 34 |
# ----- Detect substantive changes -----
|
| 35 |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR || true)
|
| 36 |
-
SUBSTANTIVE_PATTERN='\.(py|ts|tsx|js|jsx|R|r|java|sql)$|^scripts/
|
| 37 |
SUBSTANTIVE_FILES=""
|
| 38 |
if [ -n "$STAGED_FILES" ]; then
|
| 39 |
SUBSTANTIVE_FILES=$(echo "$STAGED_FILES" | grep -E "$SUBSTANTIVE_PATTERN" || true)
|
|
@@ -56,15 +56,17 @@ fi
|
|
| 56 |
|
| 57 |
# ----- Reviewer marker check -----
|
| 58 |
# Marker format (one line): <HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>
|
| 59 |
-
# where DIFF-HASH
|
| 60 |
-
#
|
| 61 |
-
# after the reviewer cleared
|
|
|
|
| 62 |
MARKER="$REPO_ROOT/.decode-reviewer-clean"
|
| 63 |
-
|
|
|
|
| 64 |
MARKED_SHA=$(awk 'NR==1 {print $1}' "$MARKER" 2>/dev/null || echo "")
|
| 65 |
MARKED_DIFF=$(awk 'NR==1 {print $2}' "$MARKER" 2>/dev/null || echo "")
|
| 66 |
CURRENT_HEAD=$(git rev-parse HEAD 2>/dev/null || echo "initial")
|
| 67 |
-
CURRENT_DIFF=$(
|
| 68 |
if [ -n "$MARKED_SHA" ] && [ -n "$MARKED_DIFF" ] \
|
| 69 |
&& [ "$MARKED_SHA" = "$CURRENT_HEAD" ] \
|
| 70 |
&& [ "$MARKED_DIFF" = "$CURRENT_DIFF" ]; then
|
|
@@ -90,7 +92,6 @@ To proceed, ONE of:
|
|
| 90 |
git commit -m "... [override-reviewer: quick doc typo]"
|
| 91 |
Overrides are visible forever in \`git log --grep="override-reviewer"\`.
|
| 92 |
|
| 93 |
-
See decode-claude-wiki/docs/rules for rule 03 (reviewer required).
|
| 94 |
================================================================
|
| 95 |
EOF
|
| 96 |
exit 1
|
|
|
|
| 33 |
|
| 34 |
# ----- Detect substantive changes -----
|
| 35 |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR || true)
|
| 36 |
+
SUBSTANTIVE_PATTERN='\.(py|ts|tsx|js|jsx|R|r|java|sql)$|^scripts/'
|
| 37 |
SUBSTANTIVE_FILES=""
|
| 38 |
if [ -n "$STAGED_FILES" ]; then
|
| 39 |
SUBSTANTIVE_FILES=$(echo "$STAGED_FILES" | grep -E "$SUBSTANTIVE_PATTERN" || true)
|
|
|
|
| 56 |
|
| 57 |
# ----- Reviewer marker check -----
|
| 58 |
# Marker format (one line): <HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>
|
| 59 |
+
# where DIFF-HASH is computed by scripts/reviewer-hash.sh and covers both
|
| 60 |
+
# tracked diffs (git diff HEAD) AND untracked file contents. Binding to
|
| 61 |
+
# the hash prevents edits made after the reviewer cleared β whether to
|
| 62 |
+
# tracked or untracked files β from silently bypassing the gate.
|
| 63 |
MARKER="$REPO_ROOT/.decode-reviewer-clean"
|
| 64 |
+
HASH_SCRIPT="$REPO_ROOT/scripts/reviewer-hash.sh"
|
| 65 |
+
if [ -f "$MARKER" ] && [ -x "$HASH_SCRIPT" ]; then
|
| 66 |
MARKED_SHA=$(awk 'NR==1 {print $1}' "$MARKER" 2>/dev/null || echo "")
|
| 67 |
MARKED_DIFF=$(awk 'NR==1 {print $2}' "$MARKER" 2>/dev/null || echo "")
|
| 68 |
CURRENT_HEAD=$(git rev-parse HEAD 2>/dev/null || echo "initial")
|
| 69 |
+
CURRENT_DIFF=$(bash "$HASH_SCRIPT" 2>/dev/null || echo "")
|
| 70 |
if [ -n "$MARKED_SHA" ] && [ -n "$MARKED_DIFF" ] \
|
| 71 |
&& [ "$MARKED_SHA" = "$CURRENT_HEAD" ] \
|
| 72 |
&& [ "$MARKED_DIFF" = "$CURRENT_DIFF" ]; then
|
|
|
|
| 92 |
git commit -m "... [override-reviewer: quick doc typo]"
|
| 93 |
Overrides are visible forever in \`git log --grep="override-reviewer"\`.
|
| 94 |
|
|
|
|
| 95 |
================================================================
|
| 96 |
EOF
|
| 97 |
exit 1
|
|
@@ -45,21 +45,35 @@ jobs:
|
|
| 45 |
|
| 46 |
override-audit:
|
| 47 |
runs-on: ubuntu-latest
|
| 48 |
-
if: github.event_name == 'pull_request'
|
| 49 |
steps:
|
| 50 |
- uses: actions/checkout@v4
|
| 51 |
with:
|
| 52 |
fetch-depth: 0
|
| 53 |
-
- name: Report override-reviewer usage
|
| 54 |
env:
|
|
|
|
| 55 |
BASE_REF: ${{ github.base_ref }}
|
|
|
|
| 56 |
run: |
|
| 57 |
set -euo pipefail
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
if [ -n "$OVERRIDES" ]; then
|
| 60 |
-
echo "This
|
| 61 |
echo "$OVERRIDES"
|
| 62 |
-
# Non-blocking β just surface it
|
| 63 |
fi
|
| 64 |
|
| 65 |
ci-fail-incident:
|
|
|
|
| 45 |
|
| 46 |
override-audit:
|
| 47 |
runs-on: ubuntu-latest
|
|
|
|
| 48 |
steps:
|
| 49 |
- uses: actions/checkout@v4
|
| 50 |
with:
|
| 51 |
fetch-depth: 0
|
| 52 |
+
- name: Report override-reviewer usage
|
| 53 |
env:
|
| 54 |
+
EVENT_NAME: ${{ github.event_name }}
|
| 55 |
BASE_REF: ${{ github.base_ref }}
|
| 56 |
+
BEFORE_SHA: ${{ github.event.before }}
|
| 57 |
run: |
|
| 58 |
set -euo pipefail
|
| 59 |
+
if [ "$EVENT_NAME" = "pull_request" ]; then
|
| 60 |
+
RANGE="origin/${BASE_REF}..HEAD"
|
| 61 |
+
LABEL="PR"
|
| 62 |
+
else
|
| 63 |
+
if [ -n "${BEFORE_SHA:-}" ] && [ "$BEFORE_SHA" != "0000000000000000000000000000000000000000" ]; then
|
| 64 |
+
RANGE="${BEFORE_SHA}..HEAD"
|
| 65 |
+
elif git rev-parse HEAD~1 >/dev/null 2>&1; then
|
| 66 |
+
RANGE="HEAD~1..HEAD"
|
| 67 |
+
else
|
| 68 |
+
# root commit with no parent
|
| 69 |
+
RANGE="HEAD"
|
| 70 |
+
fi
|
| 71 |
+
LABEL="push"
|
| 72 |
+
fi
|
| 73 |
+
OVERRIDES=$(git log --format='%H %s' "$RANGE" 2>/dev/null | grep -E '\[override-reviewer:' || true)
|
| 74 |
if [ -n "$OVERRIDES" ]; then
|
| 75 |
+
echo "This $LABEL contains reviewer overrides:"
|
| 76 |
echo "$OVERRIDES"
|
|
|
|
| 77 |
fi
|
| 78 |
|
| 79 |
ci-fail-incident:
|
|
@@ -23,7 +23,7 @@ Triggered by the Stop hook when the session modified substantive files and no fr
|
|
| 23 |
1. Run `git diff HEAD` via Bash.
|
| 24 |
2. Dispatch `feature-dev:code-reviewer` via the Agent tool. Pass the diff as context. Instruct: review only the changes, target latency under 90 seconds, report only blocking issues (confidence β₯ 80).
|
| 25 |
3. When the reviewer returns:
|
| 26 |
-
- **No blocking issues** β compute `HEAD_SHA=$(git rev-parse HEAD)` and `DIFF_HASH=$(
|
| 27 |
- **Blocking issues** β Write `.decode-reviewer-findings.md` with the list. Do NOT write `.decode-reviewer-clean`.
|
| 28 |
4. Return.
|
| 29 |
|
|
@@ -62,14 +62,14 @@ Use it after a change already works and before commit when you want a final pass
|
|
| 62 |
|
| 63 |
## First-time setup in this repo
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
| 66 |
|
| 67 |
```bash
|
| 68 |
bash scripts/setup.sh
|
| 69 |
```
|
| 70 |
|
| 71 |
-
This wires `.githooks/pre-commit` into git via `core.hooksPath`. One-time per clone.
|
| 72 |
-
|
| 73 |
## Destructive operations
|
| 74 |
|
| 75 |
Destructive git operations (`push --force`, `reset --hard`, `clean -f`, `branch -D`, etc.) are blocked by the `block-dangerous-git.sh` PreToolUse hook. If you genuinely need one, ask the user to run it manually after explicit chat confirmation.
|
|
|
|
| 23 |
1. Run `git diff HEAD` via Bash.
|
| 24 |
2. Dispatch `feature-dev:code-reviewer` via the Agent tool. Pass the diff as context. Instruct: review only the changes, target latency under 90 seconds, report only blocking issues (confidence β₯ 80).
|
| 25 |
3. When the reviewer returns:
|
| 26 |
+
- **No blocking issues** β compute `HEAD_SHA=$(git rev-parse HEAD)` and `DIFF_HASH=$(bash scripts/reviewer-hash.sh)`, then Write `.decode-reviewer-clean` with exactly one line: `<HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>`. The hash helper covers tracked-file diffs AND untracked file contents; do not substitute a plain `git diff | git hash-object` pipe β it misses untracked files and lets create-file β pass-review β silent-edit bypass the marker.
|
| 27 |
- **Blocking issues** β Write `.decode-reviewer-findings.md` with the list. Do NOT write `.decode-reviewer-clean`.
|
| 28 |
4. Return.
|
| 29 |
|
|
|
|
| 62 |
|
| 63 |
## First-time setup in this repo
|
| 64 |
|
| 65 |
+
Setup runs automatically on Claude Code session start via the `ensure-setup.sh` SessionStart hook β it wires `.githooks` into git (`core.hooksPath`) so the commit-msg and pre-commit gates fire. Idempotent; no-ops once wired.
|
| 66 |
+
|
| 67 |
+
If you commit from a plain terminal in a fresh clone without ever opening a Claude Code session, the hooks will not fire until you run setup manually:
|
| 68 |
|
| 69 |
```bash
|
| 70 |
bash scripts/setup.sh
|
| 71 |
```
|
| 72 |
|
|
|
|
|
|
|
| 73 |
## Destructive operations
|
| 74 |
|
| 75 |
Destructive git operations (`push --force`, `reset --hard`, `clean -f`, `branch -D`, etc.) are blocked by the `block-dangerous-git.sh` PreToolUse hook. If you genuinely need one, ask the user to run it manually after explicit chat confirmation.
|
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE reviewer hash β single source of truth for the DIFF_HASH captured
|
| 4 |
+
# in the .decode-reviewer-clean marker.
|
| 5 |
+
#
|
| 6 |
+
# Used identically by:
|
| 7 |
+
# - the reviewer procedure (Claude writing the marker, per CLAUDE.md)
|
| 8 |
+
# - the Stop hook (.claude/hooks/reviewer-stop.sh)
|
| 9 |
+
# - the commit-msg hook (.githooks/commit-msg)
|
| 10 |
+
#
|
| 11 |
+
# Captures both tracked-file diffs (via `git diff HEAD`) AND the contents
|
| 12 |
+
# of untracked files (via `git ls-files --others --exclude-standard`).
|
| 13 |
+
# Any edit to either surface invalidates the marker.
|
| 14 |
+
#
|
| 15 |
+
# Why this exists: the original design hashed only `git diff HEAD`, which
|
| 16 |
+
# excludes untracked files. That left an attack path β agent creates a
|
| 17 |
+
# new file, reviewer passes, agent silently edits the new file, marker
|
| 18 |
+
# still validates. This helper closes the gap.
|
| 19 |
+
|
| 20 |
+
set -euo pipefail
|
| 21 |
+
|
| 22 |
+
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
| 23 |
+
cd "$REPO_ROOT"
|
| 24 |
+
|
| 25 |
+
{
|
| 26 |
+
git diff HEAD 2>/dev/null || true
|
| 27 |
+
git ls-files --others --exclude-standard 2>/dev/null | while IFS= read -r f; do
|
| 28 |
+
[ -f "$f" ] || continue
|
| 29 |
+
printf 'UNTRACKED %s\n' "$f"
|
| 30 |
+
cat "$f"
|
| 31 |
+
printf '\n'
|
| 32 |
+
done
|
| 33 |
+
} | git hash-object --stdin
|