Merge pull request #3 from implicitdiagnosticsandsolutions/hardening/decode-gates
Browse files- .claude/hooks/block-dangerous-git.sh +97 -0
- .claude/hooks/block-env-writes.sh +40 -0
- .claude/hooks/ensure-setup.sh +47 -0
- .claude/hooks/reviewer-stop.sh +55 -0
- .claude/settings.json +76 -0
- .claude/skills/deslop/SKILL.md +141 -0
- .githooks/commit-msg +97 -0
- .githooks/pre-commit +24 -0
- .github/workflows/gate.yml +120 -0
- .gitignore +3 -0
- CLAUDE.md +72 -109
- scripts/language-gate.sh +80 -0
- scripts/reviewer-hash.sh +46 -0
- scripts/setup.sh +28 -0
.claude/hooks/block-dangerous-git.sh
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE hardening PreToolUse hook on Bash.
|
| 4 |
+
# Blocks destructive git operations without explicit user sign-off.
|
| 5 |
+
#
|
| 6 |
+
# Tier-aware: product tier repos (node, java) get the full lockdown.
|
| 7 |
+
# Data tier repos (python, r) get a narrower lockdown that allows
|
| 8 |
+
# `checkout .` and `restore .` (routine scratch-exploration cleanup).
|
| 9 |
+
#
|
| 10 |
+
# Tier detection:
|
| 11 |
+
# - If repo has package.json (and no pyproject.toml/setup.py): node (full)
|
| 12 |
+
# - If repo has pom.xml or build.gradle: java (full)
|
| 13 |
+
# - Otherwise: data tier (narrow)
|
| 14 |
+
#
|
| 15 |
+
# Override: user must ask Claude to run the destructive command manually
|
| 16 |
+
# after explicit confirmation in chat. The hook does not have an env var
|
| 17 |
+
# override β bypasses must be visible.
|
| 18 |
+
|
| 19 |
+
set -euo pipefail
|
| 20 |
+
|
| 21 |
+
INPUT=$(cat)
|
| 22 |
+
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
|
| 23 |
+
|
| 24 |
+
if [ -z "$COMMAND" ]; then
|
| 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 |
+
|
| 39 |
+
# Patterns blocked in ALL tiers (always dangerous).
|
| 40 |
+
# Note: rm patterns are anchored to end-of-argument or followed by a
|
| 41 |
+
# slash-terminated root β this prevents false positives on `rm -rf /tmp/foo`
|
| 42 |
+
# (legitimate) while still blocking `rm -rf /` (catastrophic), `rm -rf ~`,
|
| 43 |
+
# and `rm -rf ~/` (same home-directory wipe with trailing slash).
|
| 44 |
+
BLOCKED_ALL=(
|
| 45 |
+
"git[[:space:]]+push[[:space:]].*--force"
|
| 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
|
| 60 |
+
BLOCKED_PRODUCT=(
|
| 61 |
+
"git[[:space:]]+checkout[[:space:]]+\.([[:space:]]|$)"
|
| 62 |
+
"git[[:space:]]+checkout[[:space:]]+--[[:space:]]+\.([[:space:]]|$)"
|
| 63 |
+
"git[[:space:]]+restore[[:space:]]+\.([[:space:]]|$)"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
# Check all-tier patterns
|
| 67 |
+
for pattern in "${BLOCKED_ALL[@]}"; do
|
| 68 |
+
if echo "$COMMAND" | grep -qE "$pattern"; then
|
| 69 |
+
cat >&2 <<EOF
|
| 70 |
+
BLOCKED: destructive command matched pattern '$pattern'
|
| 71 |
+
Command: $COMMAND
|
| 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
|
| 79 |
+
done
|
| 80 |
+
|
| 81 |
+
# Check product-tier-only patterns
|
| 82 |
+
if [ "$TIER" = "product" ]; then
|
| 83 |
+
for pattern in "${BLOCKED_PRODUCT[@]}"; do
|
| 84 |
+
if echo "$COMMAND" | grep -qE "$pattern"; then
|
| 85 |
+
cat >&2 <<EOF
|
| 86 |
+
BLOCKED: '$pattern' is blocked in product-tier repos (this repo detected as $TIER).
|
| 87 |
+
Command: $COMMAND
|
| 88 |
+
|
| 89 |
+
If you need to discard working-tree changes, use a narrower pattern
|
| 90 |
+
(specific paths) or ask the user to run it manually.
|
| 91 |
+
EOF
|
| 92 |
+
exit 2
|
| 93 |
+
fi
|
| 94 |
+
done
|
| 95 |
+
fi
|
| 96 |
+
|
| 97 |
+
exit 0
|
.claude/hooks/block-env-writes.sh
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE hardening PreToolUse hook on Edit / Write tools.
|
| 4 |
+
# Blocks writes to .env* files, credentials files, and key files.
|
| 5 |
+
#
|
| 6 |
+
# Exits 2 (block) if the target path matches the denylist.
|
| 7 |
+
|
| 8 |
+
set -euo pipefail
|
| 9 |
+
|
| 10 |
+
INPUT=$(cat)
|
| 11 |
+
TOOL=$(echo "$INPUT" | jq -r '.tool_name // empty' 2>/dev/null)
|
| 12 |
+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty' 2>/dev/null)
|
| 13 |
+
|
| 14 |
+
# Only gate Edit / Write
|
| 15 |
+
case "$TOOL" in
|
| 16 |
+
Edit|Write|NotebookEdit) ;;
|
| 17 |
+
*) exit 0 ;;
|
| 18 |
+
esac
|
| 19 |
+
|
| 20 |
+
if [ -z "$FILE_PATH" ]; then
|
| 21 |
+
exit 0
|
| 22 |
+
fi
|
| 23 |
+
|
| 24 |
+
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 |
+
|
| 32 |
+
Files containing credentials or secrets should never be modified by Claude
|
| 33 |
+
automatically. If this is intentional, ask the user to edit manually, or
|
| 34 |
+
use a gitignored .env.local that is not in the denylist.
|
| 35 |
+
EOF
|
| 36 |
+
exit 2
|
| 37 |
+
;;
|
| 38 |
+
esac
|
| 39 |
+
|
| 40 |
+
exit 0
|
.claude/hooks/ensure-setup.sh
ADDED
|
@@ -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
|
.claude/hooks/reviewer-stop.sh
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE hardening Stop hook.
|
| 4 |
+
# Blocks session stop when substantive files are modified and no fresh
|
| 5 |
+
# reviewer-clean marker exists. The detailed procedure lives in CLAUDE.md
|
| 6 |
+
# under "Reviewer procedure" β this hook just triggers it.
|
| 7 |
+
#
|
| 8 |
+
# Emits JSON with decision: "block" (structured) instead of exit 2 +
|
| 9 |
+
# stderr, to avoid rendering a verbose "hook error" block in the
|
| 10 |
+
# terminal UI. The reason goes to the model; the UI stays quiet.
|
| 11 |
+
|
| 12 |
+
set -euo pipefail
|
| 13 |
+
|
| 14 |
+
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; 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 )
|
| 28 |
+
|
| 29 |
+
if ! echo "$MODIFIED" | grep -qE "$PATTERNS"; then
|
| 30 |
+
exit 0
|
| 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
|
| 48 |
+
exit 0
|
| 49 |
+
fi
|
| 50 |
+
fi
|
| 51 |
+
|
| 52 |
+
cat <<'JSON'
|
| 53 |
+
{"decision": "block", "reason": "Substantive files were modified and no fresh .decode-reviewer-clean marker exists. Run the 'Reviewer procedure' from CLAUDE.md before ending the session or committing."}
|
| 54 |
+
JSON
|
| 55 |
+
exit 0
|
.claude/settings.json
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"$schema": "https://json.schemastore.org/claude-code-settings.json",
|
| 3 |
+
"extraKnownMarketplaces": {
|
| 4 |
+
"claude-plugins-official": {
|
| 5 |
+
"source": {
|
| 6 |
+
"source": "github",
|
| 7 |
+
"repo": "anthropics/claude-plugins-official"
|
| 8 |
+
}
|
| 9 |
+
}
|
| 10 |
+
},
|
| 11 |
+
"enabledPlugins": {
|
| 12 |
+
"feature-dev@claude-plugins-official": true,
|
| 13 |
+
"code-simplifier@claude-plugins-official": true,
|
| 14 |
+
"claude-md-management@claude-plugins-official": true,
|
| 15 |
+
"superpowers@claude-plugins-official": true
|
| 16 |
+
},
|
| 17 |
+
"permissions": {
|
| 18 |
+
"allow": [
|
| 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)",
|
| 27 |
+
"Bash(git status:*)",
|
| 28 |
+
"Write(.decode-reviewer-clean)",
|
| 29 |
+
"Write(.decode-reviewer-findings.md)",
|
| 30 |
+
"Edit(.decode-reviewer-clean)",
|
| 31 |
+
"Edit(.decode-reviewer-findings.md)"
|
| 32 |
+
]
|
| 33 |
+
},
|
| 34 |
+
"hooks": {
|
| 35 |
+
"PreToolUse": [
|
| 36 |
+
{
|
| 37 |
+
"matcher": "Bash",
|
| 38 |
+
"hooks": [
|
| 39 |
+
{
|
| 40 |
+
"type": "command",
|
| 41 |
+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
|
| 42 |
+
}
|
| 43 |
+
]
|
| 44 |
+
},
|
| 45 |
+
{
|
| 46 |
+
"matcher": "Edit|Write|NotebookEdit",
|
| 47 |
+
"hooks": [
|
| 48 |
+
{
|
| 49 |
+
"type": "command",
|
| 50 |
+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-env-writes.sh"
|
| 51 |
+
}
|
| 52 |
+
]
|
| 53 |
+
}
|
| 54 |
+
],
|
| 55 |
+
"Stop": [
|
| 56 |
+
{
|
| 57 |
+
"hooks": [
|
| 58 |
+
{
|
| 59 |
+
"type": "command",
|
| 60 |
+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/reviewer-stop.sh"
|
| 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 |
+
}
|
.claude/skills/deslop/SKILL.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
name: deslop
|
| 3 |
+
description: Run a final cleanup and review-readiness pass on a nearly finished change. Use when the change already works and you want to reduce AI slop, remove unnecessary indirection, preserve source-of-truth files and types, and tighten the diff before commit.
|
| 4 |
+
allowed-tools: Read, Glob, Grep, Bash
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
# Deslop
|
| 8 |
+
|
| 9 |
+
Use this skill after the change is functionally correct and before `commit`.
|
| 10 |
+
|
| 11 |
+
The goal is not beautification.
|
| 12 |
+
The goal is to pressure the last part of the diff so the committed version is:
|
| 13 |
+
|
| 14 |
+
- smaller
|
| 15 |
+
- clearer
|
| 16 |
+
- more repo-consistent
|
| 17 |
+
- less invented
|
| 18 |
+
|
| 19 |
+
## What This Skill Is For
|
| 20 |
+
|
| 21 |
+
Use it to catch:
|
| 22 |
+
|
| 23 |
+
- fake seams and pass-through wrappers
|
| 24 |
+
- duplicated or widened local types
|
| 25 |
+
- repo-local conventions invented without payoff
|
| 26 |
+
- debug leftovers and placeholder comments
|
| 27 |
+
- swallowed errors and empty catches
|
| 28 |
+
- edits to generated artifacts that should have been made at the source
|
| 29 |
+
|
| 30 |
+
Do not use it to:
|
| 31 |
+
|
| 32 |
+
- discover the solution
|
| 33 |
+
- rewrite unrelated stable code
|
| 34 |
+
- turn a straightforward change into a cleanup project
|
| 35 |
+
|
| 36 |
+
## Core Review Vectors
|
| 37 |
+
|
| 38 |
+
Every deslop pass should cover these three vectors:
|
| 39 |
+
|
| 40 |
+
1. Rules and repo conformance
|
| 41 |
+
- are we following `CLAUDE.md`, nested instructions, and local docs
|
| 42 |
+
- did we drift from repo conventions or file ownership boundaries
|
| 43 |
+
|
| 44 |
+
2. Source of truth and verification
|
| 45 |
+
- did we preserve canonical source files and types
|
| 46 |
+
- did we patch a generated artifact instead of the generator
|
| 47 |
+
- did we claim verification that was not actually run
|
| 48 |
+
|
| 49 |
+
3. Overengineering and simplification
|
| 50 |
+
- did we write more code than needed
|
| 51 |
+
- did we add helpers, wrappers, or abstractions that do not earn their keep
|
| 52 |
+
- can the same behavior be expressed more directly
|
| 53 |
+
|
| 54 |
+
## Workflow
|
| 55 |
+
|
| 56 |
+
### 1. Gather the smallest useful context bundle
|
| 57 |
+
|
| 58 |
+
Read only what defines the rules for the changed area:
|
| 59 |
+
|
| 60 |
+
- repo-root `CLAUDE.md`
|
| 61 |
+
- nested instructions for the touched area, if any
|
| 62 |
+
- the changed files plus enough nearby context to judge them properly
|
| 63 |
+
- any spec, plan, or issue that defined the work
|
| 64 |
+
|
| 65 |
+
### 2. Run the three review vectors
|
| 66 |
+
|
| 67 |
+
Cover all three vectors deliberately.
|
| 68 |
+
|
| 69 |
+
The point is not the tool shape.
|
| 70 |
+
The point is to check:
|
| 71 |
+
|
| 72 |
+
- repo conformance
|
| 73 |
+
- source-of-truth discipline
|
| 74 |
+
- unnecessary complexity
|
| 75 |
+
|
| 76 |
+
### 3. Run slop tooling only when it fits
|
| 77 |
+
|
| 78 |
+
If the repo already has a native slop command, prefer that.
|
| 79 |
+
|
| 80 |
+
Examples:
|
| 81 |
+
|
| 82 |
+
```bash
|
| 83 |
+
pnpm lint:slop
|
| 84 |
+
pnpm lint:slop:delta
|
| 85 |
+
npm run lint:slop
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
If the repo has no wrapper but `slop-scan` is appropriate and available, use it directly:
|
| 89 |
+
|
| 90 |
+
```bash
|
| 91 |
+
npx slop-scan scan . --lint
|
| 92 |
+
npx slop-scan scan . --json
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
Treat `slop-scan` as a heuristic pass, not an oracle.
|
| 96 |
+
|
| 97 |
+
### 4. Fix what is clearly in scope
|
| 98 |
+
|
| 99 |
+
High-value deslop fixes:
|
| 100 |
+
|
| 101 |
+
- remove dead helpers and pass-through wrappers
|
| 102 |
+
- remove type drift and duplicated local types
|
| 103 |
+
- replace invented protocols with normal repo patterns
|
| 104 |
+
- remove debug leftovers and placeholder comments
|
| 105 |
+
- fix empty catches and error-swallowing patterns
|
| 106 |
+
- move edits from generated outputs back to the actual source of truth
|
| 107 |
+
|
| 108 |
+
### 5. Re-validate narrowly
|
| 109 |
+
|
| 110 |
+
After cleanup:
|
| 111 |
+
|
| 112 |
+
- rerun the narrowest relevant checks
|
| 113 |
+
- rerun lint or typecheck for the touched area
|
| 114 |
+
- rerun `slop-scan` if you used it
|
| 115 |
+
|
| 116 |
+
The final diff should describe the post-deslop state, not the earlier draft state.
|
| 117 |
+
|
| 118 |
+
## What Good Deslop Looks Like
|
| 119 |
+
|
| 120 |
+
Good outcomes:
|
| 121 |
+
|
| 122 |
+
- one less wrapper
|
| 123 |
+
- one less fake boundary
|
| 124 |
+
- stronger source-of-truth discipline
|
| 125 |
+
- stronger compile-time guarantees where the repo already supports them
|
| 126 |
+
- less ceremony around a straightforward change
|
| 127 |
+
|
| 128 |
+
Bad outcomes:
|
| 129 |
+
|
| 130 |
+
- broad cleanup outside the task
|
| 131 |
+
- large code churn for aesthetic reasons
|
| 132 |
+
- optimizing for scanner score instead of code quality
|
| 133 |
+
- deleting useful structure just to make the diff shorter
|
| 134 |
+
|
| 135 |
+
## Stop Rules
|
| 136 |
+
|
| 137 |
+
- Do not widen scope just because cleanup opportunities exist nearby.
|
| 138 |
+
- Do not optimize for scanner score over code quality.
|
| 139 |
+
- Do not remove real abstraction that carries its weight.
|
| 140 |
+
- Do not add defensive runtime checks inside trusted internal code unless the boundary is actually untrusted.
|
| 141 |
+
- If a cleanup is subjective and not clearly better, leave it alone.
|
.githooks/commit-msg
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE commit-msg gate β reviewer marker check + strong override detection.
|
| 4 |
+
#
|
| 5 |
+
# Git invokes this hook AFTER the commit message is written, passing the
|
| 6 |
+
# message file path as $1. Unlike pre-commit, we can reliably read the
|
| 7 |
+
# intended commit message here.
|
| 8 |
+
#
|
| 9 |
+
# Gate logic:
|
| 10 |
+
# - If no substantive files changed: pass.
|
| 11 |
+
# - Else if commit message contains [override-reviewer: <reason>]: pass (logged).
|
| 12 |
+
# - Else if .decode-reviewer-clean exists with HEAD + DIFF hashes matching current repo state: pass.
|
| 13 |
+
# - Else: fail with a clear message explaining how to run the reviewer.
|
| 14 |
+
|
| 15 |
+
set -euo pipefail
|
| 16 |
+
|
| 17 |
+
COMMIT_MSG_FILE="${1:-}"
|
| 18 |
+
if [ -z "$COMMIT_MSG_FILE" ] || [ ! -f "$COMMIT_MSG_FILE" ]; then
|
| 19 |
+
echo >&2 "[commit-msg] ERROR: expected commit message file as \$1 (got '$COMMIT_MSG_FILE')"
|
| 20 |
+
exit 1
|
| 21 |
+
fi
|
| 22 |
+
|
| 23 |
+
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
| 24 |
+
cd "$REPO_ROOT"
|
| 25 |
+
|
| 26 |
+
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
|
| 27 |
+
|
| 28 |
+
# Ignore merge commits, squash messages, revert templates β these are
|
| 29 |
+
# generated by git, not author-written.
|
| 30 |
+
if echo "$COMMIT_MSG" | head -1 | grep -qE '^(Merge|Revert) '; then
|
| 31 |
+
exit 0
|
| 32 |
+
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)
|
| 40 |
+
fi
|
| 41 |
+
|
| 42 |
+
if [ -z "$SUBSTANTIVE_FILES" ]; then
|
| 43 |
+
# Nothing substantive β commit-msg gate has nothing to enforce
|
| 44 |
+
exit 0
|
| 45 |
+
fi
|
| 46 |
+
|
| 47 |
+
# ----- Strong override detection -----
|
| 48 |
+
# Format: [override-reviewer: reason] anywhere in the commit message.
|
| 49 |
+
# Visible forever in `git log --grep="override-reviewer"`.
|
| 50 |
+
OVERRIDE_REGEX='\[override-reviewer:[[:space:]]*[^]]+\]'
|
| 51 |
+
if echo "$COMMIT_MSG" | grep -qE "$OVERRIDE_REGEX"; then
|
| 52 |
+
echo >&2 "[commit-msg] override-reviewer present β gate bypassed."
|
| 53 |
+
echo >&2 "[commit-msg] This bypass is logged forever in git history."
|
| 54 |
+
exit 0
|
| 55 |
+
fi
|
| 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
|
| 73 |
+
# Fresh marker β allow
|
| 74 |
+
exit 0
|
| 75 |
+
fi
|
| 76 |
+
fi
|
| 77 |
+
|
| 78 |
+
# ----- No marker, no override β block -----
|
| 79 |
+
cat >&2 <<EOF
|
| 80 |
+
================================================================
|
| 81 |
+
DECODE COMMIT-MSG GATE: reviewer marker missing or stale.
|
| 82 |
+
|
| 83 |
+
This commit touches substantive files:
|
| 84 |
+
$(echo "$SUBSTANTIVE_FILES" | sed 's/^/ - /')
|
| 85 |
+
|
| 86 |
+
To proceed, ONE of:
|
| 87 |
+
(a) Run the reviewer subagent this session.
|
| 88 |
+
In Claude Code, ask: "dispatch the reviewer subagent".
|
| 89 |
+
The reviewer writes .decode-reviewer-clean if no blocking issues.
|
| 90 |
+
Then re-run the commit.
|
| 91 |
+
(b) Override with a reason in the commit message:
|
| 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
|
.githooks/pre-commit
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE pre-commit gate β thin wrapper around the shared language gate.
|
| 4 |
+
#
|
| 5 |
+
# Split from commit-msg to match git hook semantics:
|
| 6 |
+
# - pre-commit: runs before message is written. Cannot read commit message.
|
| 7 |
+
# Runs language lint + artifact-suspicion checks.
|
| 8 |
+
# - commit-msg: runs after message is written. Reads message from $1.
|
| 9 |
+
# Runs reviewer-marker check and override detection.
|
| 10 |
+
#
|
| 11 |
+
# The actual gate logic lives in scripts/language-gate.sh so CI and local
|
| 12 |
+
# hooks execute the same checks.
|
| 13 |
+
|
| 14 |
+
set -euo pipefail
|
| 15 |
+
|
| 16 |
+
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
| 17 |
+
cd "$REPO_ROOT"
|
| 18 |
+
|
| 19 |
+
if [ ! -x "scripts/language-gate.sh" ]; then
|
| 20 |
+
echo >&2 "[gate] ERROR: scripts/language-gate.sh not found or not executable"
|
| 21 |
+
exit 1
|
| 22 |
+
fi
|
| 23 |
+
|
| 24 |
+
exec bash scripts/language-gate.sh
|
.github/workflows/gate.yml
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: DECODE gate
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
pull_request:
|
| 5 |
+
branches: [main, master]
|
| 6 |
+
push:
|
| 7 |
+
branches: [main, master]
|
| 8 |
+
|
| 9 |
+
jobs:
|
| 10 |
+
language-gate:
|
| 11 |
+
runs-on: ubuntu-latest
|
| 12 |
+
steps:
|
| 13 |
+
- uses: actions/checkout@v4
|
| 14 |
+
with:
|
| 15 |
+
fetch-depth: 0
|
| 16 |
+
- name: Install language-gate dependencies
|
| 17 |
+
run: |
|
| 18 |
+
set -euo pipefail
|
| 19 |
+
if [ -f "package.json" ]; then
|
| 20 |
+
npm ci --no-audit --no-fund >/dev/null
|
| 21 |
+
fi
|
| 22 |
+
if grep -qE '\.py$' <(git ls-files) || [ -f "pyproject.toml" ] || [ -f "setup.py" ]; then
|
| 23 |
+
python -m pip install --upgrade pip >/dev/null
|
| 24 |
+
pip install ruff >/dev/null
|
| 25 |
+
fi
|
| 26 |
+
- name: Detect changes and run shared language gate
|
| 27 |
+
run: |
|
| 28 |
+
set -euo pipefail
|
| 29 |
+
if [ "${GITHUB_EVENT_NAME}" = "pull_request" ]; then
|
| 30 |
+
git diff --name-only "origin/${GITHUB_BASE_REF}"...HEAD > /tmp/changed.txt
|
| 31 |
+
else
|
| 32 |
+
if git rev-parse HEAD~1 >/dev/null 2>&1; then
|
| 33 |
+
git diff --name-only HEAD~1..HEAD > /tmp/changed.txt
|
| 34 |
+
else
|
| 35 |
+
git ls-files > /tmp/changed.txt
|
| 36 |
+
fi
|
| 37 |
+
fi
|
| 38 |
+
echo "Changed files:"
|
| 39 |
+
cat /tmp/changed.txt
|
| 40 |
+
mapfile -t CHANGED < /tmp/changed.txt
|
| 41 |
+
if [ "${#CHANGED[@]}" -eq 0 ]; then
|
| 42 |
+
exit 0
|
| 43 |
+
fi
|
| 44 |
+
bash scripts/language-gate.sh "${CHANGED[@]}"
|
| 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:
|
| 80 |
+
runs-on: ubuntu-latest
|
| 81 |
+
needs: [language-gate]
|
| 82 |
+
if: failure() && github.event_name == 'push'
|
| 83 |
+
steps:
|
| 84 |
+
- name: File incident in decode-claude-wiki
|
| 85 |
+
env:
|
| 86 |
+
INCIDENT_LOG_TOKEN: ${{ secrets.INCIDENT_LOG_TOKEN }}
|
| 87 |
+
REPO_NAME: ${{ github.repository }}
|
| 88 |
+
SHA: ${{ github.sha }}
|
| 89 |
+
RUN_ID: ${{ github.run_id }}
|
| 90 |
+
SERVER_URL: ${{ github.server_url }}
|
| 91 |
+
REPO_FULL: ${{ github.repository }}
|
| 92 |
+
WORKFLOW_NAME: ${{ github.workflow }}
|
| 93 |
+
run: |
|
| 94 |
+
set -euo pipefail
|
| 95 |
+
if [ -z "${INCIDENT_LOG_TOKEN:-}" ]; then
|
| 96 |
+
echo "INCIDENT_LOG_TOKEN secret not set β skipping incident filing"
|
| 97 |
+
exit 0
|
| 98 |
+
fi
|
| 99 |
+
SHORT_SHA="${SHA:0:7}"
|
| 100 |
+
DATE=$(date -u +%Y-%m-%d)
|
| 101 |
+
REPO_BASENAME="${REPO_NAME##*/}"
|
| 102 |
+
RUN_URL="${SERVER_URL}/${REPO_FULL}/actions/runs/${RUN_ID}"
|
| 103 |
+
TITLE="incident: ${DATE} ${REPO_BASENAME} ci-fail ${SHORT_SHA}"
|
| 104 |
+
BODY=$(cat <<EOF
|
| 105 |
+
Automated incident from ${REPO_BASENAME} CI gate failure.
|
| 106 |
+
|
| 107 |
+
- Repo: \`${REPO_BASENAME}\`
|
| 108 |
+
- Commit: \`${SHORT_SHA}\`
|
| 109 |
+
- Workflow: ${WORKFLOW_NAME}
|
| 110 |
+
- Run: ${RUN_URL}
|
| 111 |
+
|
| 112 |
+
Triage: open the run above, determine whether this is a real incident (something broke) or noise (flaky test, env issue). If real, convert to docs/incidents/ and close this issue linking to the MD file.
|
| 113 |
+
EOF
|
| 114 |
+
)
|
| 115 |
+
echo "$INCIDENT_LOG_TOKEN" | gh auth login --with-token
|
| 116 |
+
gh issue create \
|
| 117 |
+
-R implicitdiagnosticsandsolutions/decode-claude-wiki \
|
| 118 |
+
-t "$TITLE" \
|
| 119 |
+
-l "incident,ci-fail" \
|
| 120 |
+
-b "$BODY"
|
.gitignore
CHANGED
|
@@ -1,3 +1,6 @@
|
|
| 1 |
# Sample/client data (not committed)
|
| 2 |
sample_data/
|
| 3 |
__pycache__/
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Sample/client data (not committed)
|
| 2 |
sample_data/
|
| 3 |
__pycache__/
|
| 4 |
+
# Claude Code reviewer artifacts β session-local, never commit
|
| 5 |
+
.decode-reviewer-clean
|
| 6 |
+
.decode-reviewer-findings.md
|
CLAUDE.md
CHANGED
|
@@ -1,147 +1,110 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
-
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
- **Nonrewards** (functional/product attributes) β category-specific like "good taste", "healthy", "affordable"
|
| 13 |
-
- **Category Index** β importance score for each attribute
|
| 14 |
-
- **Deviation values** β differences from expected correlation (positive = above average association). The app uses deviations, not absolute means, because deviations show what's *distinctive*
|
| 15 |
|
| 16 |
-
##
|
| 17 |
|
| 18 |
-
|
| 19 |
-
- **Left sidebar**: Browsable attribute list with Category Index, sortable by Index (desc) or Name (alpha), with search filter. Collapsible.
|
| 20 |
-
- **Level 0**: Selected driver attribute (user picks from sidebar)
|
| 21 |
-
- **Level 1**: Top N directly correlated attributes (above threshold)
|
| 22 |
-
- **Level 2**: Secondary correlations from L1 nodes
|
| 23 |
-
- **Red nodes** = Rewards (emotional), **Blue nodes** = Nonrewards (functional)
|
| 24 |
-
- **Node size** = Category Index, **Edge thickness** = correlation strength
|
| 25 |
-
- **Hover**: Fades unrelated nodes/edges, highlights connected ones
|
| 26 |
-
- **Click**: Locks the focused state + opens right profile panel with horizontal bar chart of that node's correlations
|
| 27 |
-
- **Save PNG**: Downloads the network canvas as a PNG image (bottom-left button)
|
| 28 |
-
- **Header**: DECODE logo (left), project title centered (Client Β· Brand Β· Country Β· Category), legend (right)
|
| 29 |
-
- **Details panel**: Slide-up panel with technical stats (threshold, attribute counts, correlation summary)
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
-
|
| 34 |
-
- pandas + openpyxl (Excel parsing)
|
| 35 |
-
- vis-network 9.1.9 (in generated HTML output, no jQuery/Select2)
|
| 36 |
-
- Deployed on HuggingFace Spaces (DecodeMarketing/Correlation-network)
|
| 37 |
-
- Auto-deploys on push to main via GitHub Actions β HF Spaces sync
|
| 38 |
|
| 39 |
-
|
| 40 |
|
| 41 |
-
|
| 42 |
-
app.py # Streamlit UI (~180 lines)
|
| 43 |
-
config.py # Constants: COLORS
|
| 44 |
-
parse_excel.py # Excel detection + data extraction
|
| 45 |
-
build_network.py # Network building + HTML template generation
|
| 46 |
-
requirements.txt # streamlit, pandas, numpy, openpyxl
|
| 47 |
-
Dockerfile # Python 3.13.5-slim, port 8501
|
| 48 |
-
README.md # HuggingFace Spaces metadata
|
| 49 |
-
.github/workflows/main.yml # Auto-deploy to HF on push to main
|
| 50 |
-
sample_data/ # Test xlsx files (gitignored, client data)
|
| 51 |
-
.gitignore # Excludes sample_data/, __pycache__/
|
| 52 |
-
```
|
| 53 |
|
| 54 |
-
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
-
```
|
| 59 |
-
Row 4: Section headers β territory names, brand names
|
| 60 |
-
Row 5: Column headers β variable codes (used as correlation matrix column IDs)
|
| 61 |
|
| 62 |
-
|
| 63 |
-
[7-8 empty rows gap]
|
| 64 |
-
BLOCK 2 (rows N+8βend): DEVIATION values (what the app uses)
|
| 65 |
-
```
|
| 66 |
|
| 67 |
-
|
| 68 |
-
- **Col A**: Row number
|
| 69 |
-
- **Col B**: Variable code (`FCMARKENMAT_PA_Abenteuer_Abenteuer` or `FCBRANDMAT_PA_GreaterGood_carefortheplanet`)
|
| 70 |
-
- **Col C**: Display name (human-readable attribute)
|
| 71 |
-
- **Col D**: Category Index (importance score)
|
| 72 |
-
- **Col E**: Empty gap
|
| 73 |
-
- **Cols FβK/O**: Territory mean/deviation values
|
| 74 |
-
- **Col 25+ (DE) or 33+ (EN)**: Square correlation matrix (attribute x attribute)
|
| 75 |
|
| 76 |
-
|
| 77 |
|
| 78 |
-
|
| 79 |
-
- Prefix: `FCMARKENMAT` (DE BGO), `FCBRANDMAT` (EN iBHDD), `FCMARKENMODUL` (DE Retailer)
|
| 80 |
-
- Territory: one of the 6 or 10 reward territories, or a functional category
|
| 81 |
-
- Classification: if territory is in `REWARDS_FACTORS` list β Reward (red), otherwise β Nonreward (blue)
|
| 82 |
|
| 83 |
-
##
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|---|---|---|
|
| 87 |
-
| Territories | 6 (Abenteuer, Autonomie, Disziplin, Sicherheit, Genuss, Erregung) | 10 (GreaterGood, Caring, Acceptance, Control, Security, SelfPromotion, Achievement, Enjoyment, Excitement, Freedom) |
|
| 88 |
-
| Correlation matrix starts | Col 25 (Y) | Col 33 (AG) |
|
| 89 |
-
| Code prefix | FCMARKENMAT / FCMARKENMODUL | FCBRANDMAT |
|
| 90 |
-
| Non-reward naming | Explicit categories (funktional, features, Qualitaet, etc.) | Single "Nonrewards" territory |
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
-
|
| 101 |
-
2. **CORR_COL_START** (`detect_correlation_column_start`): Finds the first block of >50 consecutive non-empty cells in row 5. Works reliably.
|
| 102 |
-
3. **REWARD_TERRITORIES** (`detect_reward_territories`): Finds "per reward field" header in row 4, reads territory names from row 5 underneath. Works reliably (6 DE territories, 10 EN territories). Falls back to hardcoded defaults.
|
| 103 |
-
4. **CORR_THRESHOLD** (`detect_cutoff_value`): Searches for "cut-off used in columns" text in column B. **Always fails** on real files β defaults to 6.0.
|
| 104 |
|
| 105 |
-
|
| 106 |
|
| 107 |
```bash
|
| 108 |
-
|
| 109 |
-
streamlit run app.py
|
| 110 |
-
# Opens at http://localhost:8501
|
| 111 |
```
|
| 112 |
|
| 113 |
-
##
|
| 114 |
-
|
| 115 |
-
4 test files in `sample_data/` (gitignored):
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|---|---|---|---|---|---|
|
| 119 |
-
| `118014-45_Hassia_..._Korrelationen_...xlsx` | Hassia | DE | BGO | 114 | 11 |
|
| 120 |
-
| `126007-400_P&G_MX_..._Correlations_...xlsx` | P&G | MX | iBHDD | 82 | 6 |
|
| 121 |
-
| `126007-401_P&G_..._UK_..._Correlations_...xlsx` | P&G | UK | iBHDD | 83 | 9 |
|
| 122 |
-
| `128003-23_REWE_..._Correlations_...xlsx` | REWE | DE | Retailer BGO | 80 | 8 |
|
| 123 |
|
| 124 |
-
|
| 125 |
|
| 126 |
-
-
|
| 127 |
-
- **Auto-deploy**: Push to `main` β GitHub Actions workflow syncs to HF
|
| 128 |
-
- **Secret**: `HF_TOKEN` stored as GitHub repo secret (same token as icat_app/videoextraction_app)
|
| 129 |
-
- **Branch**: `v2` was the development branch, merged to `main`
|
| 130 |
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
-
- **Logo**: Inline SVG in HTML output (dark fill version of `decode-logo-negative.svg`)
|
| 135 |
|
| 136 |
-
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
#
|
|
|
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# CLAUDE.md
|
| 2 |
|
| 3 |
+
## Session-start: ensure required plugins are installed
|
| 4 |
|
| 5 |
+
At the start of any new session in this repo, run `/plugin marketplace list`. If `claude-plugins-official` is not listed, install the four required plugins:
|
| 6 |
|
| 7 |
+
```
|
| 8 |
+
/plugin marketplace add anthropics/claude-plugins-official
|
| 9 |
+
/plugin install feature-dev@claude-plugins-official
|
| 10 |
+
/plugin install code-simplifier@claude-plugins-official
|
| 11 |
+
/plugin install claude-md-management@claude-plugins-official
|
| 12 |
+
/plugin install superpowers@claude-plugins-official
|
| 13 |
+
```
|
| 14 |
|
| 15 |
+
One-time per user per machine. `feature-dev` provides the `code-reviewer` subagent referenced by the reviewer procedure (and `code-architect` for plan review). Without `feature-dev` installed, every commit touching source code will be blocked by the commit-msg gate.
|
| 16 |
|
| 17 |
+
Subsequent sessions refresh plugins automatically.
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
## Reviewer procedure
|
| 20 |
|
| 21 |
+
Triggered by the Stop hook when the session modified substantive files and no fresh `.decode-reviewer-clean` marker exists. The Stop hook blocks session end and points the model back to this procedure. Steps, in order:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 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 |
|
| 30 |
+
If the `feature-dev` plugin is not installed, stop and ask the user to run `/plugin install feature-dev@claude-plugins-official`.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
The `commit-msg` git hook blocks commits unless the marker's HEAD and DIFF hashes both match the current repo state, or the commit message contains `[override-reviewer: <reason>]`. Binding to the diff content means any edit made after review invalidates the marker. Overrides are visible forever in `git log --grep="override-reviewer"`.
|
| 33 |
|
| 34 |
+
## DECODE base rules
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
This repo enforces DECODE's Claude Code standards. The full rule catalog lives at https://github.com/implicitdiagnosticsandsolutions/decode-claude-wiki/tree/main/docs/rules β rules are loaded by reference.
|
| 37 |
|
| 38 |
+
**The short version β what you must follow:**
|
| 39 |
|
| 40 |
+
1. **Reviewer subagent required before commit.** For any change that touches source code, generator scripts, or data outputs, dispatch the `feature-dev:code-reviewer` subagent before committing. The Stop hook blocks session end until this procedure is handled. Committing without a fresh `.decode-reviewer-clean` marker is blocked by `.githooks/commit-msg` unless the commit message contains `[override-reviewer: <reason>]`. Overrides are visible forever in `git log --grep="override-reviewer"`.
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
2. **Verify before claiming.** Before saying "X works", "it's documented", or "it's in memory", run a concrete check. Paste the output. "Should" is a red flag β replace it with a check.
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
3. **Patch the source, not the generated artifact.** If a file under `output/` or `dist/` was produced by a script, edit the script and regenerate. Never edit the artifact directly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
4. **Stage files explicitly.** Never `git add -A` or `git add .`. Name each file.
|
| 47 |
|
| 48 |
+
5. **No AI attribution in commits.** Conventional format, human author.
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
## Optional final cleanup
|
| 51 |
|
| 52 |
+
This template also ships a repo-local `deslop` skill under `.claude/skills/deslop/`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
Use it after a change already works and before commit when you want a final pass focused on:
|
| 55 |
|
| 56 |
+
- removing unnecessary wrappers or indirection
|
| 57 |
+
- preserving source-of-truth files and types
|
| 58 |
+
- catching debug leftovers and placeholder comments
|
| 59 |
+
- reducing AI slop without widening scope
|
| 60 |
|
| 61 |
+
`deslop` is advisory, not a hard gate.
|
| 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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
Writes to `.env*`, `credentials*`, `*.pem`, `*.key`, and other secret files are blocked by `block-env-writes.sh`.
|
| 78 |
|
| 79 |
+
---
|
|
|
|
|
|
|
|
|
|
| 80 |
|
| 81 |
+
<!-- Per-repo section below. Fill in repo-specific conventions. -->
|
| 82 |
|
| 83 |
+
## This repo
|
|
|
|
| 84 |
|
| 85 |
+
`network_html` ist eine Streamlit-App die aus Excel-Korrelationsmatrizen interaktive HTML-Netzwerk-Visualisierungen erzeugt. DECODE-Consultants nutzen sie um implizite Markenattribute (aus SAT/MAT-Tests) als vis-network-Graphen zu explorieren. Deployed auf HuggingFace Spaces (`DecodeMarketing/Correlation-network`), auto-deploy bei Push auf `main`.
|
| 86 |
|
| 87 |
+
**Lokal starten:**
|
| 88 |
+
```bash
|
| 89 |
+
pip install -r requirements.txt
|
| 90 |
+
streamlit run app.py
|
| 91 |
+
# ΓΆffnet http://localhost:8501
|
| 92 |
+
```
|
| 93 |
|
| 94 |
+
**Source-Layout:**
|
| 95 |
+
- `app.py` β Streamlit UI, Entry Point (~180 Zeilen)
|
| 96 |
+
- `parse_excel.py` β Excel-Erkennung und Datenextraktion
|
| 97 |
+
- `build_network.py` β Netzwerk-Aufbau und HTML-Template-Generierung
|
| 98 |
+
- `config.py` β Konstanten (Farben, DECODE-Brand-Blau `#283273`)
|
| 99 |
+
- `velocity_source.py` β Velocity-Datenquelle
|
| 100 |
+
- `requirements.txt` β Python-AbhΓ€ngigkeiten (Quelle der Wahrheit)
|
| 101 |
+
|
| 102 |
+
**Repo-spezifische Regeln:**
|
| 103 |
+
- Der generierte HTML-Output ist ein Artefakt β nie direkt bearbeiten, immer ΓΌber `build_network.py` regenerieren.
|
| 104 |
+
- `sample_data/` ist gitignored (enthΓ€lt Kundendaten) β nie committen.
|
| 105 |
+
- Auto-Detection von `CORR_THRESHOLD` schlΓ€gt immer fehl; Default 6.0 ist beabsichtigt, nicht fixen ohne echten Testfall.
|
| 106 |
+
- Deployment-Secret `HF_TOKEN` liegt als GitHub Repo Secret β nie in Code oder Commits.
|
| 107 |
+
|
| 108 |
+
**Bekannte EinschrΓ€nkungen (nicht "fixen" ohne Absprache):**
|
| 109 |
+
- Cut-off-Detection schlΓ€gt auf echten Dateien immer fehl β Default 6.0
|
| 110 |
+
- Per-Brand-Matrizen werden ignoriert β nur "mean across all brands"
|
scripts/language-gate.sh
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE shared language gate.
|
| 4 |
+
#
|
| 5 |
+
# Used by:
|
| 6 |
+
# - .githooks/pre-commit (default: staged files)
|
| 7 |
+
# - .github/workflows/gate.yml (explicit changed-file list)
|
| 8 |
+
#
|
| 9 |
+
# Hard-fail on deterministic lint errors. Heuristic artifact checks stay
|
| 10 |
+
# advisory so normal regenerate flows are not blocked by noisy guesses.
|
| 11 |
+
|
| 12 |
+
set -euo pipefail
|
| 13 |
+
|
| 14 |
+
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
| 15 |
+
cd "$REPO_ROOT"
|
| 16 |
+
|
| 17 |
+
if [ "$#" -gt 0 ]; then
|
| 18 |
+
FILES=$(printf '%s\n' "$@")
|
| 19 |
+
else
|
| 20 |
+
FILES=$(git diff --cached --name-only --diff-filter=ACMR || true)
|
| 21 |
+
fi
|
| 22 |
+
|
| 23 |
+
if [ -z "$FILES" ]; then
|
| 24 |
+
exit 0
|
| 25 |
+
fi
|
| 26 |
+
|
| 27 |
+
FAIL=0
|
| 28 |
+
|
| 29 |
+
PY_FILES=$(printf '%s\n' "$FILES" | grep -E '\.py$' || true)
|
| 30 |
+
if [ -n "$PY_FILES" ]; then
|
| 31 |
+
if command -v ruff >/dev/null 2>&1; then
|
| 32 |
+
if ! printf '%s\n' "$PY_FILES" | xargs ruff check; then
|
| 33 |
+
echo >&2 "[gate] ruff check failed on Python files"
|
| 34 |
+
FAIL=1
|
| 35 |
+
fi
|
| 36 |
+
else
|
| 37 |
+
echo >&2 "[gate] WARN: ruff not installed β skipping Python lint."
|
| 38 |
+
fi
|
| 39 |
+
fi
|
| 40 |
+
|
| 41 |
+
JS_FILES=$(printf '%s\n' "$FILES" | grep -E '\.(ts|tsx|js|jsx)$' || true)
|
| 42 |
+
if [ -n "$JS_FILES" ] && [ -f "package.json" ]; then
|
| 43 |
+
if [ -x "node_modules/.bin/eslint" ]; then
|
| 44 |
+
if ! printf '%s\n' "$JS_FILES" | xargs node_modules/.bin/eslint; then
|
| 45 |
+
echo >&2 "[gate] eslint failed on JS/TS files"
|
| 46 |
+
FAIL=1
|
| 47 |
+
fi
|
| 48 |
+
else
|
| 49 |
+
echo >&2 "[gate] WARN: eslint not installed β skipping JS/TS lint."
|
| 50 |
+
fi
|
| 51 |
+
fi
|
| 52 |
+
|
| 53 |
+
R_FILES=$(printf '%s\n' "$FILES" | grep -E '\.(R|r)$' || true)
|
| 54 |
+
if [ -n "$R_FILES" ] && command -v Rscript >/dev/null 2>&1; then
|
| 55 |
+
printf '%s\n' "$R_FILES" | while IFS= read -r f; do
|
| 56 |
+
[ -f "$f" ] || continue
|
| 57 |
+
Rscript -e "lints <- tryCatch(lintr::lint('$f'), error = function(e) NULL); if (!is.null(lints) && length(lints) > 0) { cat(format(lints)); }" 2>/dev/null || true
|
| 58 |
+
done
|
| 59 |
+
fi
|
| 60 |
+
|
| 61 |
+
ARTIFACT_FILES=$(printf '%s\n' "$FILES" | grep -E '^(output|dist)/.*\.(csv|json|html|xlsx)$' || true)
|
| 62 |
+
SCRIPT_FILES=$(printf '%s\n' "$FILES" | grep -E '^scripts/.*\.(py|R|r|js|ts)$' || true)
|
| 63 |
+
if [ -n "$ARTIFACT_FILES" ] && [ -z "$SCRIPT_FILES" ]; then
|
| 64 |
+
echo >&2 "[gate] WARNING: artifacts changed under output/ or dist/ without any staged generator change under scripts/."
|
| 65 |
+
echo >&2 "[gate] WARNING: if these files are generated, rule 02 expects patching the generator and regenerating."
|
| 66 |
+
fi
|
| 67 |
+
|
| 68 |
+
if [ "$FAIL" -ne 0 ]; then
|
| 69 |
+
cat >&2 <<'EOF'
|
| 70 |
+
================================================================
|
| 71 |
+
DECODE LANGUAGE GATE: deterministic checks failed.
|
| 72 |
+
|
| 73 |
+
Fix the issues above and retry. The commit-msg hook may still allow a
|
| 74 |
+
reviewer override marker, but CI will rerun this same language gate.
|
| 75 |
+
================================================================
|
| 76 |
+
EOF
|
| 77 |
+
exit 1
|
| 78 |
+
fi
|
| 79 |
+
|
| 80 |
+
exit 0
|
scripts/reviewer-hash.sh
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE reviewer hash (stage-invariant) β single source of truth for the
|
| 4 |
+
# DIFF_HASH captured 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 |
+
# Produces the same hash regardless of whether changes are staged or
|
| 12 |
+
# unstaged. That means "run reviewer, write marker, then git add, then
|
| 13 |
+
# commit" works correctly β the hash the commit-msg hook computes matches
|
| 14 |
+
# the hash the reviewer wrote into the marker.
|
| 15 |
+
#
|
| 16 |
+
# Why the old implementation was stage-dependent: it hashed
|
| 17 |
+
# `git diff HEAD` (which doesn't include untracked files) plus untracked
|
| 18 |
+
# file contents (via ls-files --others). A new file would move between
|
| 19 |
+
# those two sections on `git add`, changing the text fed to hash-object
|
| 20 |
+
# even though the actual content was identical.
|
| 21 |
+
#
|
| 22 |
+
# This version takes the UNION of files-differing-from-HEAD and
|
| 23 |
+
# untracked-non-ignored, iterates that set in sorted order, and emits
|
| 24 |
+
# uniform framing for each file β stage-invariant by construction.
|
| 25 |
+
|
| 26 |
+
set -euo pipefail
|
| 27 |
+
|
| 28 |
+
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
| 29 |
+
cd "$REPO_ROOT"
|
| 30 |
+
|
| 31 |
+
{
|
| 32 |
+
# core.quotepath=false keeps paths with spaces / non-ASCII from being
|
| 33 |
+
# emitted as "quoted\\040path" which the while-read loop can't test/cat.
|
| 34 |
+
{ git -c core.quotepath=false diff --name-only HEAD 2>/dev/null || true
|
| 35 |
+
git -c core.quotepath=false ls-files --others --exclude-standard 2>/dev/null || true
|
| 36 |
+
} | sort -u | while IFS= read -r f; do
|
| 37 |
+
[ -n "$f" ] || continue
|
| 38 |
+
if [ -f "$f" ]; then
|
| 39 |
+
printf 'FILE %s\n' "$f"
|
| 40 |
+
cat "$f"
|
| 41 |
+
printf '\n'
|
| 42 |
+
else
|
| 43 |
+
printf 'DELETED %s\n' "$f"
|
| 44 |
+
fi
|
| 45 |
+
done
|
| 46 |
+
} | git hash-object --stdin
|
scripts/setup.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
#
|
| 3 |
+
# DECODE repo setup β run once after cloning or pulling this hardening PR.
|
| 4 |
+
# Wires the .githooks/pre-commit into git.
|
| 5 |
+
#
|
| 6 |
+
# Idempotent: safe to re-run.
|
| 7 |
+
|
| 8 |
+
set -euo pipefail
|
| 9 |
+
|
| 10 |
+
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
|
| 11 |
+
cd "$REPO_ROOT"
|
| 12 |
+
|
| 13 |
+
# Wire the hooks path
|
| 14 |
+
if [ -d ".githooks" ]; then
|
| 15 |
+
git config core.hooksPath .githooks
|
| 16 |
+
echo "[setup] core.hooksPath set to .githooks"
|
| 17 |
+
else
|
| 18 |
+
echo "[setup] WARN: .githooks/ not found β pre-commit gate will not run"
|
| 19 |
+
exit 1
|
| 20 |
+
fi
|
| 21 |
+
|
| 22 |
+
# Ensure hooks are executable
|
| 23 |
+
chmod +x .githooks/* 2>/dev/null || true
|
| 24 |
+
chmod +x .claude/hooks/*.sh 2>/dev/null || true
|
| 25 |
+
chmod +x scripts/*.sh 2>/dev/null || true
|
| 26 |
+
|
| 27 |
+
echo "[setup] Done. On your next commit, the reviewer-marker + language gate will run."
|
| 28 |
+
echo "[setup] To bypass (with audit trail): git commit -m '... [override-reviewer: reason]'"
|