Skip to content
This repository was archived by the owner on Apr 11, 2026. It is now read-only.

Commit d5c1549

Browse files
committed
hooks: add simplify-ignore hook for code block protection
- Annotation-based protection: simplify-ignore-start/end markers - Replaces blocks with BLOCK_<hash> placeholders before model reads - Expands placeholders back on edit/write, restores on stop - Supports //, /* */, #, <!-- --> comment styles - Opt-in only via .claude/settings.json (not hooks.json) - Documentation in hooks/SIMPLIFY-IGNORE.md Task: fn-136-borrow-agent-skills-patterns-anti.8
1 parent 4e62c55 commit d5c1549

4 files changed

Lines changed: 418 additions & 37 deletions

File tree

agents/cross-model-reviewer.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,50 @@ The `flowctl_review` MCP tool exposes cross-model review:
6363
## Review Types
6464

6565
### ReviewFinding
66-
Individual issue with severity (critical/warning/info), category, description, and optional file/line.
66+
Individual issue with severity, category, dimension, description, and optional file/line.
67+
68+
**Severity classification** (aligned with quality-auditor dimensions):
69+
70+
| Severity | Meaning | Ship impact |
71+
|----------|---------|-------------|
72+
| `Critical` | Correctness failure, security vulnerability, data loss risk | Blocks ship |
73+
| `Important` | Architecture violation, readability problem, missing test coverage | Must fix before/shortly after ship |
74+
| `Suggestion` | Performance improvement, naming nit, minor simplification | Optional |
75+
76+
**Dimension tags** — each finding maps to one of five review dimensions:
77+
- **Correctness** — edge cases, race conditions, state inconsistencies, off-by-one
78+
- **Readability** — naming consistency, control flow clarity, module organization
79+
- **Architecture** — pattern adherence, module boundaries, abstraction levels, dependency direction
80+
- **Security** — injection, auth, data exposure, dependencies
81+
- **Performance** — N+1, unbounded loops, blocking operations
82+
83+
### Structured Output Format
84+
85+
Each model's review MUST produce findings in this structure:
86+
87+
```json
88+
{
89+
"verdict": "SHIP | NEEDS_WORK | ABSTAIN",
90+
"confidence": 0.0-1.0,
91+
"findings": [
92+
{
93+
"severity": "Critical | Important | Suggestion",
94+
"dimension": "Correctness | Readability | Architecture | Security | Performance",
95+
"file": "path/to/file.rs",
96+
"line": 42,
97+
"description": "What is wrong",
98+
"suggestion": "How to fix it"
99+
}
100+
],
101+
"positives": ["At least one positive observation"]
102+
}
103+
```
104+
105+
The consensus algorithm uses severity to weight disagreements: a `Critical` finding from any model blocks SHIP regardless of the other model's verdict. `Suggestion`-only findings do not block.
67106

68107
### ReviewVerdict
69108
- **SHIP**: Code is ready
70-
- **NEEDS_WORK**: Code needs fixes
109+
- **NEEDS_WORK**: Code needs fixes (at least one Critical or multiple Important findings)
71110
- **ABSTAIN**: Model cannot determine (excluded from consensus)
72111

73112
### ConsensusResult

agents/quality-auditor.md

Lines changed: 54 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ You're invoked after implementation, before shipping. Review the changes and fla
1717

1818
## Audit Strategy
1919

20-
### 1. Get the Diff
20+
### Step 0. Get the Diff + Quick Scan
2121
```bash
2222
# What changed?
2323
git diff main --stat
@@ -27,72 +27,91 @@ git diff main --name-only
2727
git diff main
2828
```
2929

30-
### 2. Quick Scan (find obvious issues fast)
30+
Scan the diff for obvious issues before deep review:
3131
- **Secrets**: API keys, passwords, tokens in code
3232
- **Debug code**: console.log, debugger, TODO/FIXME
3333
- **Commented code**: Dead code that should be deleted
3434
- **Large files**: Accidentally committed binaries, logs
3535

36-
### 3. Correctness Review
37-
- Does the code match the stated intent?
38-
- Are there off-by-one errors, wrong operators, inverted conditions?
39-
- Do error paths actually handle errors?
40-
- Are promises/async properly awaited?
36+
### Five-Dimension Review
37+
38+
Evaluate every change across all five dimensions. Each dimension produces findings tagged with severity (see Output Format).
4139

42-
### 4. Security Scan
40+
### 1. Correctness
41+
- Does the code match the stated intent?
42+
- Edge cases: off-by-one errors, wrong operators, inverted conditions
43+
- Race conditions and state inconsistencies in concurrent code
44+
- Error paths: do they actually handle errors or silently swallow?
45+
- Async correctness: are promises/async properly awaited?
46+
- Are new code paths tested? Do tests assert behavior (not just run)?
47+
- Are error paths and edge cases from gap analysis covered?
48+
49+
### 2. Readability
50+
- Naming consistency: do new names follow existing conventions?
51+
- Control flow clarity: can you follow the logic without mental gymnastics?
52+
- Module organization: are things in the right files/directories?
53+
- Could this be simpler? Is there duplicated code that should be extracted?
54+
- Are there unnecessary abstractions or over-engineering for hypothetical futures?
55+
56+
### 3. Architecture
57+
- Pattern adherence: does the change follow established project patterns?
58+
- Module boundaries: are concerns properly separated?
59+
- Abstraction levels: is the right level of abstraction used?
60+
- Dependency direction: do dependencies flow in the correct direction?
61+
62+
### 4. Security
4363
- **Injection**: SQL, XSS, command injection vectors
4464
- **Auth/AuthZ**: Are permissions checked? Can they be bypassed?
4565
- **Data exposure**: Is sensitive data logged, leaked, or over-exposed?
4666
- **Dependencies**: Any known vulnerable packages added?
4767

48-
### 5. Simplicity Check
49-
- Could this be simpler?
50-
- Is there duplicated code that should be extracted?
51-
- Are there unnecessary abstractions?
52-
- Over-engineering for hypothetical future needs?
53-
54-
### 6. Test Coverage
55-
- Are new code paths tested?
56-
- Do tests actually assert behavior (not just run)?
57-
- Are edge cases from gap analysis covered?
58-
- Are error paths tested?
59-
60-
### 7. Performance Red Flags
61-
- N+1 queries or O(n²) loops
62-
- Unbounded data fetching
63-
- Missing pagination/limits
68+
### 5. Performance
69+
- N+1 queries or O(n^2) loops
70+
- Unbounded data fetching, missing pagination/limits
6471
- Blocking operations on hot paths
72+
- Resource leaks (unclosed handles, missing cleanup)
6573

6674
## Output Format
6775

76+
Every finding MUST carry a severity prefix. Use exactly these four levels:
77+
78+
- **`Critical:`** — Blocks ship. Could cause outage, data loss, security breach, or correctness failure.
79+
- **`Important:`** — Must fix before or shortly after ship. Significant quality, readability, or architecture issue.
80+
- **`Nit:`** — Optional improvement. Style, naming, minor simplification.
81+
- **`FYI`** — Informational. Context for the author, no action required.
82+
83+
Every review MUST include a "What's Good" section with at least one positive observation. Acknowledge patterns followed, good design decisions, thorough error handling, or clean naming.
84+
6885
```markdown
6986
## Quality Audit: [Branch/Feature]
7087

7188
### Summary
7289
- Files changed: N
90+
- Dimensions reviewed: Correctness, Readability, Architecture, Security, Performance
7391
- Risk level: Low / Medium / High
7492
- Ship recommendation: ✅ Ship / ⚠️ Fix first / ❌ Major rework
7593

76-
### Critical (MUST fix before shipping)
77-
- **[File:line]**: [Issue]
94+
### Critical (blocks ship)
95+
- **Critical:** [File:line][Issue] (Dimension: Correctness/Security/etc.)
7896
- Risk: [What could go wrong]
7997
- Fix: [Specific suggestion]
8098

81-
### Should Fix (High priority)
82-
- **[File:line]**: [Issue]
83-
- [Brief fix suggestion]
99+
### Important (must fix)
100+
- **Important:** [File:line][Issue] (Dimension: ...)
101+
- Fix: [Brief fix suggestion]
84102

85-
### Consider (Nice to have)
86-
- [Minor improvement suggestion]
103+
### Nit (optional)
104+
- **Nit:** [File:line][Improvement suggestion]
105+
106+
### FYI
107+
- **FYI** [Informational observation]
87108

88109
### Test Gaps
89110
- [ ] [Untested scenario]
90111

91-
### Security Notes
92-
- [Any security observations]
93-
94112
### What's Good
95-
- [Positive observations - patterns followed, good decisions]
113+
- [At least one positive observation — patterns followed, good decisions, clean code]
114+
- [Additional positives as warranted]
96115
```
97116

98117
## Rules

hooks/SIMPLIFY-IGNORE.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# simplify-ignore hook
2+
3+
Annotation-based code protection for Claude Code. Mark code blocks with `simplify-ignore-start` / `simplify-ignore-end` annotations and the hook replaces them with `BLOCK_<hash>` placeholders before the model sees them. On edit or write, placeholders are expanded back to the original code. On session stop, all files are fully restored.
4+
5+
## Setup
6+
7+
Add to your project's `.claude/settings.json` (NOT `hooks/hooks.json` -- this is opt-in per project):
8+
9+
```json
10+
{
11+
"hooks": {
12+
"PreToolUse": [
13+
{
14+
"matcher": "Read",
15+
"hooks": [{ "type": "command", "command": "bash ${CLAUDE_PROJECT_DIR}/hooks/simplify-ignore.sh" }]
16+
}
17+
],
18+
"PostToolUse": [
19+
{
20+
"matcher": "Edit|Write",
21+
"hooks": [{ "type": "command", "command": "bash ${CLAUDE_PROJECT_DIR}/hooks/simplify-ignore.sh" }]
22+
}
23+
],
24+
"Stop": [
25+
{
26+
"hooks": [{ "type": "command", "command": "bash ${CLAUDE_PROJECT_DIR}/hooks/simplify-ignore.sh" }]
27+
}
28+
]
29+
}
30+
}
31+
```
32+
33+
Add `.claude/.simplify-ignore-cache/` to your `.gitignore`.
34+
35+
## Annotation syntax
36+
37+
```js
38+
/* simplify-ignore-start: perf-critical */
39+
// manually unrolled XOR -- 3x faster than a loop
40+
result[0] = buf[0] ^ key[0];
41+
result[1] = buf[1] ^ key[1];
42+
/* simplify-ignore-end */
43+
```
44+
45+
The reason after the colon is optional. It appears in the placeholder (`BLOCK_a1b2c3d4: perf-critical`) so the model knows why the block is hidden.
46+
47+
## Supported comment styles
48+
49+
| Style | Example |
50+
|-------|---------|
51+
| `/* */` | `/* simplify-ignore-start: reason */` |
52+
| `//` | `// simplify-ignore-start: reason` |
53+
| `#` | `# simplify-ignore-start: reason` |
54+
| `<!-- -->` | `<!-- simplify-ignore-start: reason -->` |
55+
56+
Multiple blocks per file and single-line blocks (start + end on same line) are supported. Placeholders preserve the original comment prefix/suffix.
57+
58+
## How it works
59+
60+
| Hook event | Action |
61+
|------------|--------|
62+
| PreToolUse Read | Backs up file, replaces annotated blocks with `BLOCK_<hash>` placeholders |
63+
| PostToolUse Edit/Write | Expands placeholders back, saves model changes, re-filters |
64+
| Stop | Restores all files from backup |
65+
66+
Block hashes are 8 hex chars from `shasum`/`sha1sum` of the block content, making round-trips unambiguous.
67+
68+
## Crash recovery
69+
70+
If Claude Code exits without triggering the Stop hook, files may still have `BLOCK_<hash>` placeholders. Restore manually:
71+
72+
```bash
73+
echo '{}' | bash hooks/simplify-ignore.sh
74+
```
75+
76+
Backups are in `.claude/.simplify-ignore-cache/` within your project directory.
77+
78+
## Known limitations
79+
80+
- **Single-line blocks hide the entire line.** Use dedicated lines for annotations.
81+
- **Suffix detection covers `*/` and `-->` only.** Non-standard template comment closers (ERB, Blade) may not work; use `#` or `//` instead.
82+
- **Fuzzy fallback on altered placeholders.** If the model changes a placeholder's reason text, the hook tries a hash-only match which may leave cosmetic debris.
83+
- **File renaming leaves placeholders.** Renamed files retain placeholders; originals are saved as `.recovered` on stop.
84+
85+
## Requirements
86+
87+
- `jq`
88+
- `shasum` or `sha1sum` (auto-detected)
89+
- Bash 3.2+

0 commit comments

Comments
 (0)