drchrisscheier commited on
Commit
c4fa9c5
·
unverified ·
2 Parent(s): 2e95e07c2771d8

Merge pull request #5 from implicitdiagnosticsandsolutions/hardening/decode-gates

Browse files
.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,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=$(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
+ `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/reviewer-hash.sh ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ #
3
+ # DECODE reviewer hash — single source of truth for the DIFF_HASH captured
4
+ # in the .decode-reviewer-clean marker.
5
+ #
6
+ # Used identically by:
7
+ # - the reviewer procedure (Claude writing the marker, per CLAUDE.md)
8
+ # - the Stop hook (.claude/hooks/reviewer-stop.sh)
9
+ # - the commit-msg hook (.githooks/commit-msg)
10
+ #
11
+ # Captures both tracked-file diffs (via `git diff HEAD`) AND the contents
12
+ # of untracked files (via `git ls-files --others --exclude-standard`).
13
+ # Any edit to either surface invalidates the marker.
14
+ #
15
+ # Why this exists: the original design hashed only `git diff HEAD`, which
16
+ # excludes untracked files. That left an attack path — agent creates a
17
+ # new file, reviewer passes, agent silently edits the new file, marker
18
+ # still validates. This helper closes the gap.
19
+
20
+ set -euo pipefail
21
+
22
+ REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
23
+ cd "$REPO_ROOT"
24
+
25
+ {
26
+ git diff HEAD 2>/dev/null || true
27
+ git ls-files --others --exclude-standard 2>/dev/null | while IFS= read -r f; do
28
+ [ -f "$f" ] || continue
29
+ printf 'UNTRACKED %s\n' "$f"
30
+ cat "$f"
31
+ printf '\n'
32
+ done
33
+ } | git hash-object --stdin
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]'"