Spaces:
Sleeping
Sleeping
Kleopatra Jäger commited on
Commit ·
1878a50
1
Parent(s): 2e95e07
feat: add DECODE Claude Code hardening gates
Browse filesAdds reviewer-marker gate, language gate (ruff/Python), hooks, and CI
backstop from decode-claude-wiki template. Tier: python.
- .claude/hooks/block-dangerous-git.sh +89 -0
- .claude/hooks/block-env-writes.sh +40 -0
- .claude/hooks/reviewer-stop.sh +52 -0
- .claude/settings.json +64 -0
- .claude/skills/deslop/SKILL.md +141 -0
- .githooks/commit-msg +96 -0
- .githooks/pre-commit +24 -0
- .github/workflows/gate.yml +106 -0
- .gitignore +3 -0
- CLAUDE.md +112 -0
- scripts/language-gate.sh +80 -0
- scripts/setup.sh +28 -0
.claude/hooks/block-dangerous-git.sh
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 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 |
+
|
| 36 |
+
# Patterns blocked in ALL tiers (always dangerous).
|
| 37 |
+
# Note: rm patterns are anchored to end-of-argument or followed by a
|
| 38 |
+
# slash-terminated root — this prevents false positives on `rm -rf /tmp/foo`
|
| 39 |
+
# (legitimate) while still blocking `rm -rf /` (catastrophic), `rm -rf ~`,
|
| 40 |
+
# and `rm -rf ~/` (same home-directory wipe with trailing slash).
|
| 41 |
+
BLOCKED_ALL=(
|
| 42 |
+
"git[[:space:]]+push[[:space:]].*--force"
|
| 43 |
+
"git[[:space:]]+push[[:space:]]+-f([[:space:]]|$)"
|
| 44 |
+
"git[[:space:]]+reset[[:space:]]+--hard"
|
| 45 |
+
"git[[:space:]]+clean[[:space:]]+-[a-z]*f"
|
| 46 |
+
"git[[:space:]]+branch[[:space:]]+-D"
|
| 47 |
+
"(^|[^a-zA-Z0-9_/])rm[[:space:]]+-[a-z]*r[a-z]*f[a-z]*[[:space:]]+/(\s|$)"
|
| 48 |
+
"(^|[^a-zA-Z0-9_/])rm[[:space:]]+-[a-z]*r[a-z]*f[a-z]*[[:space:]]+~/?(\s|$)"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# Patterns blocked only in PRODUCT tier
|
| 52 |
+
BLOCKED_PRODUCT=(
|
| 53 |
+
"git[[:space:]]+checkout[[:space:]]+\.([[:space:]]|$)"
|
| 54 |
+
"git[[:space:]]+checkout[[:space:]]+--[[:space:]]+\.([[:space:]]|$)"
|
| 55 |
+
"git[[:space:]]+restore[[:space:]]+\.([[:space:]]|$)"
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# Check all-tier patterns
|
| 59 |
+
for pattern in "${BLOCKED_ALL[@]}"; do
|
| 60 |
+
if echo "$COMMAND" | grep -qE "$pattern"; then
|
| 61 |
+
cat >&2 <<EOF
|
| 62 |
+
BLOCKED: destructive command matched pattern '$pattern'
|
| 63 |
+
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. See decode-claude-wiki/docs/rules for rule 08.
|
| 68 |
+
EOF
|
| 69 |
+
exit 2
|
| 70 |
+
fi
|
| 71 |
+
done
|
| 72 |
+
|
| 73 |
+
# Check product-tier-only patterns
|
| 74 |
+
if [ "$TIER" = "product" ]; then
|
| 75 |
+
for pattern in "${BLOCKED_PRODUCT[@]}"; do
|
| 76 |
+
if echo "$COMMAND" | grep -qE "$pattern"; then
|
| 77 |
+
cat >&2 <<EOF
|
| 78 |
+
BLOCKED: '$pattern' is blocked in product-tier repos (this repo detected as $TIER).
|
| 79 |
+
Command: $COMMAND
|
| 80 |
+
|
| 81 |
+
If you need to discard working-tree changes, use a narrower pattern
|
| 82 |
+
(specific paths) or ask the user to run it manually.
|
| 83 |
+
EOF
|
| 84 |
+
exit 2
|
| 85 |
+
fi
|
| 86 |
+
done
|
| 87 |
+
fi
|
| 88 |
+
|
| 89 |
+
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/reviewer-stop.sh
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
cd "$(git rev-parse --show-toplevel)"
|
| 19 |
+
|
| 20 |
+
PATTERNS='\.(py|ts|tsx|js|jsx|R|r|java|sql)$|^scripts/|^output/|^dist/'
|
| 21 |
+
|
| 22 |
+
MODIFIED=$( {
|
| 23 |
+
git diff --name-only --diff-filter=ACMRD HEAD 2>/dev/null || true
|
| 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 )
|
| 27 |
+
|
| 28 |
+
if ! echo "$MODIFIED" | grep -qE "$PATTERNS"; then
|
| 29 |
+
exit 0
|
| 30 |
+
fi
|
| 31 |
+
|
| 32 |
+
# Marker format (one line): <HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>
|
| 33 |
+
# DIFF-HASH = git hash-object --stdin < (git diff HEAD). Binding to the
|
| 34 |
+
# diff content — not just HEAD — means any edit made after the reviewer
|
| 35 |
+
# cleared invalidates the marker.
|
| 36 |
+
MARKER=".decode-reviewer-clean"
|
| 37 |
+
if [ -f "$MARKER" ]; then
|
| 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=$(git diff HEAD 2>/dev/null | git hash-object --stdin 2>/dev/null || echo "")
|
| 42 |
+
if [ -n "$MARKED_SHA" ] && [ -n "$MARKED_DIFF" ] \
|
| 43 |
+
&& [ "$MARKED_SHA" = "$CURRENT_SHA" ] \
|
| 44 |
+
&& [ "$MARKED_DIFF" = "$CURRENT_DIFF" ]; then
|
| 45 |
+
exit 0
|
| 46 |
+
fi
|
| 47 |
+
fi
|
| 48 |
+
|
| 49 |
+
cat <<'JSON'
|
| 50 |
+
{"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."}
|
| 51 |
+
JSON
|
| 52 |
+
exit 0
|
.claude/settings.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 log)",
|
| 23 |
+
"Bash(git log:*)",
|
| 24 |
+
"Bash(git status)",
|
| 25 |
+
"Bash(git status:*)",
|
| 26 |
+
"Write(.decode-reviewer-clean)",
|
| 27 |
+
"Write(.decode-reviewer-findings.md)",
|
| 28 |
+
"Edit(.decode-reviewer-clean)",
|
| 29 |
+
"Edit(.decode-reviewer-findings.md)"
|
| 30 |
+
]
|
| 31 |
+
},
|
| 32 |
+
"hooks": {
|
| 33 |
+
"PreToolUse": [
|
| 34 |
+
{
|
| 35 |
+
"matcher": "Bash",
|
| 36 |
+
"hooks": [
|
| 37 |
+
{
|
| 38 |
+
"type": "command",
|
| 39 |
+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
|
| 40 |
+
}
|
| 41 |
+
]
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"matcher": "Edit|Write|NotebookEdit",
|
| 45 |
+
"hooks": [
|
| 46 |
+
{
|
| 47 |
+
"type": "command",
|
| 48 |
+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-env-writes.sh"
|
| 49 |
+
}
|
| 50 |
+
]
|
| 51 |
+
}
|
| 52 |
+
],
|
| 53 |
+
"Stop": [
|
| 54 |
+
{
|
| 55 |
+
"hooks": [
|
| 56 |
+
{
|
| 57 |
+
"type": "command",
|
| 58 |
+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/reviewer-stop.sh"
|
| 59 |
+
}
|
| 60 |
+
]
|
| 61 |
+
}
|
| 62 |
+
]
|
| 63 |
+
}
|
| 64 |
+
}
|
.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,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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/|^output/|^dist/'
|
| 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 = git hash-object --stdin < (git diff HEAD).
|
| 60 |
+
# Binding to the diff content — not just HEAD — prevents edits made
|
| 61 |
+
# after the reviewer cleared from silently bypassing the gate.
|
| 62 |
+
MARKER="$REPO_ROOT/.decode-reviewer-clean"
|
| 63 |
+
if [ -f "$MARKER" ]; then
|
| 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=$(git diff HEAD 2>/dev/null | git hash-object --stdin 2>/dev/null || echo "")
|
| 68 |
+
if [ -n "$MARKED_SHA" ] && [ -n "$MARKED_DIFF" ] \
|
| 69 |
+
&& [ "$MARKED_SHA" = "$CURRENT_HEAD" ] \
|
| 70 |
+
&& [ "$MARKED_DIFF" = "$CURRENT_DIFF" ]; then
|
| 71 |
+
# Fresh marker — allow
|
| 72 |
+
exit 0
|
| 73 |
+
fi
|
| 74 |
+
fi
|
| 75 |
+
|
| 76 |
+
# ----- No marker, no override → block -----
|
| 77 |
+
cat >&2 <<EOF
|
| 78 |
+
================================================================
|
| 79 |
+
DECODE COMMIT-MSG GATE: reviewer marker missing or stale.
|
| 80 |
+
|
| 81 |
+
This commit touches substantive files:
|
| 82 |
+
$(echo "$SUBSTANTIVE_FILES" | sed 's/^/ - /')
|
| 83 |
+
|
| 84 |
+
To proceed, ONE of:
|
| 85 |
+
(a) Run the reviewer subagent this session.
|
| 86 |
+
In Claude Code, ask: "dispatch the reviewer subagent".
|
| 87 |
+
The reviewer writes .decode-reviewer-clean if no blocking issues.
|
| 88 |
+
Then re-run the commit.
|
| 89 |
+
(b) Override with a reason in the commit message:
|
| 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
|
.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,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
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 in PR commits
|
| 54 |
+
env:
|
| 55 |
+
BASE_REF: ${{ github.base_ref }}
|
| 56 |
+
run: |
|
| 57 |
+
set -euo pipefail
|
| 58 |
+
OVERRIDES=$(git log --format='%H %s' "origin/${BASE_REF}"..HEAD | grep -E '\[override-reviewer:' || true)
|
| 59 |
+
if [ -n "$OVERRIDES" ]; then
|
| 60 |
+
echo "This PR contains reviewer overrides:"
|
| 61 |
+
echo "$OVERRIDES"
|
| 62 |
+
# Non-blocking — just surface it
|
| 63 |
+
fi
|
| 64 |
+
|
| 65 |
+
ci-fail-incident:
|
| 66 |
+
runs-on: ubuntu-latest
|
| 67 |
+
needs: [language-gate]
|
| 68 |
+
if: failure() && github.event_name == 'push'
|
| 69 |
+
steps:
|
| 70 |
+
- name: File incident in decode-claude-wiki
|
| 71 |
+
env:
|
| 72 |
+
INCIDENT_LOG_TOKEN: ${{ secrets.INCIDENT_LOG_TOKEN }}
|
| 73 |
+
REPO_NAME: ${{ github.repository }}
|
| 74 |
+
SHA: ${{ github.sha }}
|
| 75 |
+
RUN_ID: ${{ github.run_id }}
|
| 76 |
+
SERVER_URL: ${{ github.server_url }}
|
| 77 |
+
REPO_FULL: ${{ github.repository }}
|
| 78 |
+
WORKFLOW_NAME: ${{ github.workflow }}
|
| 79 |
+
run: |
|
| 80 |
+
set -euo pipefail
|
| 81 |
+
if [ -z "${INCIDENT_LOG_TOKEN:-}" ]; then
|
| 82 |
+
echo "INCIDENT_LOG_TOKEN secret not set — skipping incident filing"
|
| 83 |
+
exit 0
|
| 84 |
+
fi
|
| 85 |
+
SHORT_SHA="${SHA:0:7}"
|
| 86 |
+
DATE=$(date -u +%Y-%m-%d)
|
| 87 |
+
REPO_BASENAME="${REPO_NAME##*/}"
|
| 88 |
+
RUN_URL="${SERVER_URL}/${REPO_FULL}/actions/runs/${RUN_ID}"
|
| 89 |
+
TITLE="incident: ${DATE} ${REPO_BASENAME} ci-fail ${SHORT_SHA}"
|
| 90 |
+
BODY=$(cat <<EOF
|
| 91 |
+
Automated incident from ${REPO_BASENAME} CI gate failure.
|
| 92 |
+
|
| 93 |
+
- Repo: \`${REPO_BASENAME}\`
|
| 94 |
+
- Commit: \`${SHORT_SHA}\`
|
| 95 |
+
- Workflow: ${WORKFLOW_NAME}
|
| 96 |
+
- Run: ${RUN_URL}
|
| 97 |
+
|
| 98 |
+
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.
|
| 99 |
+
EOF
|
| 100 |
+
)
|
| 101 |
+
echo "$INCIDENT_LOG_TOKEN" | gh auth login --with-token
|
| 102 |
+
gh issue create \
|
| 103 |
+
-R implicitdiagnosticsandsolutions/decode-claude-wiki \
|
| 104 |
+
-t "$TITLE" \
|
| 105 |
+
-l "incident,ci-fail" \
|
| 106 |
+
-b "$BODY"
|
.gitignore
CHANGED
|
@@ -1,2 +1,5 @@
|
|
| 1 |
__pycache__/
|
| 2 |
*.py[cod]
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
__pycache__/
|
| 2 |
*.py[cod]
|
| 3 |
+
# Claude Code reviewer artifacts — session-local, never commit
|
| 4 |
+
.decode-reviewer-clean
|
| 5 |
+
.decode-reviewer-findings.md
|
CLAUDE.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=$(git diff HEAD | git hash-object --stdin)`, then Write `.decode-reviewer-clean` with exactly one line: `<HEAD-SHA> <DIFF-HASH> <ISO-8601-UTC-timestamp>`.
|
| 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 |
+
If this is the first time you (or anyone) is committing in this repo after the hardening PR merged, run:
|
| 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.
|
| 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 |
+
`icat_app` ist eine Streamlit-Webanwendung mit 8 Tools für Brand Asset Management bei DECODE. Sie läuft auf Hugging Face Spaces (Python 3.12, Streamlit 1.32.2).
|
| 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` — Entry Point, konfiguriert die Seite und bindet alle Tabs ein
|
| 96 |
+
- `tab1.py` – `tab8.py` — je ein Tool (ein Tab = eine Datei)
|
| 97 |
+
- `helper.py` — geteilte Hilfsfunktionen
|
| 98 |
+
- `requirements.txt` — Python-Abhängigkeiten (Quelle der Wahrheit für Dependencies)
|
| 99 |
+
|
| 100 |
+
**Die 8 Tools:**
|
| 101 |
+
1. Extract Images from Excel
|
| 102 |
+
2. Name Assets by Brand
|
| 103 |
+
3. Canvas White to Transparent
|
| 104 |
+
4. Asset Overview (PDF)
|
| 105 |
+
5. Name Stims by Block
|
| 106 |
+
6. Re-run Matrix
|
| 107 |
+
7. Resize
|
| 108 |
+
8. Place on Canvas
|
| 109 |
+
|
| 110 |
+
**Repo-spezifische Regeln:**
|
| 111 |
+
- Jeder Tab hat seine eigene Datei (`tab1.py`–`tab8.py`) — neue Tools als neue Tab-Datei anlegen, nicht in `app.py` einbauen.
|
| 112 |
+
- Die App deployed automatisch auf Hugging Face Spaces bei Push auf `main`.
|
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/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]'"
|