codecruise 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +111 -0
- package/bin/codecruise.js +68 -0
- package/config/CLAUDE.md +107 -0
- package/config/agents/analyst.md +48 -0
- package/config/agents/architect-reviewer.md +161 -0
- package/config/agents/architect.md +119 -0
- package/config/agents/critic.md +63 -0
- package/config/agents/developer.md +96 -0
- package/config/agents/devops.md +81 -0
- package/config/agents/orchestrator.md +91 -0
- package/config/agents/planner.md +139 -0
- package/config/agents/retro.md +52 -0
- package/config/agents/reviewer.md +101 -0
- package/config/agents/security-reviewer.md +57 -0
- package/config/agents/stack/expo/AGENT.md +473 -0
- package/config/agents/stack/expo/rules/critical.md +427 -0
- package/config/agents/stack/expo/rules/native.md +455 -0
- package/config/agents/stack/expo/rules/navigation.md +445 -0
- package/config/agents/stack/expo/rules/performance.md +415 -0
- package/config/agents/stack/fastify/AGENT.md +397 -0
- package/config/agents/stack/fastify/rules/api-design.md +283 -0
- package/config/agents/stack/fastify/rules/critical.md +232 -0
- package/config/agents/stack/fastify/rules/queues.md +303 -0
- package/config/agents/stack/fastify/rules/security.md +384 -0
- package/config/agents/stack/index.yaml +48 -0
- package/config/agents/stack/nextjs/AGENT.md +421 -0
- package/config/agents/stack/nextjs/rules/components.md +413 -0
- package/config/agents/stack/nextjs/rules/critical.md +391 -0
- package/config/agents/stack/nextjs/rules/performance.md +403 -0
- package/config/agents/stack/nextjs/rules/styling.md +334 -0
- package/config/agents/stack/shared-ts/AGENT.md +384 -0
- package/config/agents/stack/shared-ts/rules/critical.md +315 -0
- package/config/agents/stack/shared-ts/rules/patterns.md +384 -0
- package/config/agents/stack/shared-ts/rules/zod.md +427 -0
- package/config/agents/tester.md +79 -0
- package/config/commands/architect-discuss.md +366 -0
- package/config/commands/architect-list.md +160 -0
- package/config/commands/architect-review.md +111 -0
- package/config/commands/architect.md +118 -0
- package/config/commands/compact.md +118 -0
- package/config/commands/companion.md +279 -0
- package/config/commands/dashboard.md +152 -0
- package/config/commands/doctor.md +227 -0
- package/config/commands/dogfood-report.md +101 -0
- package/config/commands/flags/run-autonomous.md +110 -0
- package/config/commands/flags/run-pause.md +80 -0
- package/config/commands/ingest.md +173 -0
- package/config/commands/init.md +128 -0
- package/config/commands/metrics.md +87 -0
- package/config/commands/parallel.md +320 -0
- package/config/commands/pause.md +55 -0
- package/config/commands/plan-review.md +130 -0
- package/config/commands/plan.md +216 -0
- package/config/commands/production-check.md +308 -0
- package/config/commands/refine.md +323 -0
- package/config/commands/resume.md +72 -0
- package/config/commands/retro.md +121 -0
- package/config/commands/retry.md +75 -0
- package/config/commands/role.md +310 -0
- package/config/commands/run.md +417 -0
- package/config/commands/scope.md +85 -0
- package/config/commands/setup-permissions.md +104 -0
- package/config/commands/skip.md +75 -0
- package/config/commands/spec-forge.md +213 -0
- package/config/commands/spec-help.md +194 -0
- package/config/commands/spec-patch.md +342 -0
- package/config/commands/spec-resolve.md +110 -0
- package/config/commands/spec-review.md +153 -0
- package/config/commands/status.md +114 -0
- package/config/commands/sync.md +131 -0
- package/config/commands/task.md +138 -0
- package/config/commands/verify.md +124 -0
- package/config/hooks/README.md +632 -0
- package/config/hooks/activity-log.sh +187 -0
- package/config/hooks/anti-rationalize.sh +52 -0
- package/config/hooks/capture-verification.sh +112 -0
- package/config/hooks/collect-metrics.sh +135 -0
- package/config/hooks/enforce-file-scope.sh +75 -0
- package/config/hooks/enforce-state-machine.sh +161 -0
- package/config/hooks/enforce-tdd.sh +180 -0
- package/config/hooks/format.sh +40 -0
- package/config/hooks/lib/activity-helpers.sh +162 -0
- package/config/hooks/lib/read-settings.sh +71 -0
- package/config/hooks/load-context-skills.sh +95 -0
- package/config/hooks/notify.sh +81 -0
- package/config/hooks/pre-commit.sample +35 -0
- package/config/hooks/protect-files.sh +63 -0
- package/config/hooks/track-agents.sh +41 -0
- package/config/hooks/track-commands.sh +37 -0
- package/config/hooks/track-enforcement.sh +44 -0
- package/config/hooks/track-ooda.sh +77 -0
- package/config/hooks/validate-commit-msg.sh +35 -0
- package/config/hooks/validate-plan.sh +213 -0
- package/config/hooks/verify-criteria.sh +46 -0
- package/config/hooks/verify-todo-completion.sh +140 -0
- package/config/rules/comments.md +25 -0
- package/config/rules/decision-rules.md +308 -0
- package/config/rules/hygiene.md +247 -0
- package/config/rules/pattern-detection.md +372 -0
- package/config/rules/profiles.md +193 -0
- package/config/rules/recovery.md +83 -0
- package/config/rules/scope-detection.md +213 -0
- package/config/rules/standards.md +127 -0
- package/config/rules/workflow.md +121 -0
- package/config/schemas.md +767 -0
- package/config/settings.json +195 -0
- package/config/skills/backend/SKILL.md +734 -0
- package/config/skills/database/SKILL.md +426 -0
- package/config/skills/frontend/SKILL.md +434 -0
- package/config/skills/git/SKILL.md +396 -0
- package/config/skills/index.yaml +36 -0
- package/config/skills/observability/SKILL.md +430 -0
- package/config/skills/package-dev/SKILL.md +498 -0
- package/config/skills/performance/SKILL.md +378 -0
- package/config/skills/resilience/SKILL.md +573 -0
- package/config/skills/testing/SKILL.md +398 -0
- package/config/skills/testing-patterns/SKILL.md +276 -0
- package/config/skills/typescript/SKILL.md +152 -0
- package/config/templates/CLAUDE.md +70 -0
- package/config/templates/README.md +117 -0
- package/config/templates/steering/adr-template.md +102 -0
- package/config/templates/steering/product.md +60 -0
- package/config/templates/steering/rfc-template.md +159 -0
- package/config/templates/steering/structure.md +146 -0
- package/config/templates/steering/tech.md +85 -0
- package/package.json +40 -0
- package/src/install.js +163 -0
- package/src/report.js +310 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
# codecruise Hooks
|
|
2
|
+
|
|
3
|
+
Hooks enable **verified, secure, and autonomous execution** with real enforcement.
|
|
4
|
+
|
|
5
|
+
## P0 Enforcement Hooks (Critical)
|
|
6
|
+
|
|
7
|
+
These hooks provide **deterministic enforcement** — not suggestions, actual gates:
|
|
8
|
+
|
|
9
|
+
| Hook | Type | Enforcement |
|
|
10
|
+
|------|------|-------------|
|
|
11
|
+
| `verify-todo-completion.sh` | Stop | **Blocks completion** until quality gates pass |
|
|
12
|
+
| `enforce-tdd.sh` | PreToolUse | **Blocks implementation** until tests exist |
|
|
13
|
+
| `verify-criteria.sh` | Stop (Agent) | **Semantic verification** of TODO criteria |
|
|
14
|
+
|
|
15
|
+
## Available Hooks
|
|
16
|
+
|
|
17
|
+
| Hook | Type | Purpose |
|
|
18
|
+
|------|------|---------|
|
|
19
|
+
| `verify-todo-completion.sh` | Stop | **P0** Gate: Verify lint/typecheck/tests pass |
|
|
20
|
+
| `enforce-tdd.sh` | PreToolUse | **P0** Gate: Require tests before implementation |
|
|
21
|
+
| `verify-criteria.sh` | Stop (Agent) | **P0** Semantic: Verify TODO criteria met |
|
|
22
|
+
| `enforce-state-machine.sh` | PreToolUse | **P1** Gate: Prevent invalid state transitions |
|
|
23
|
+
| `collect-metrics.sh` | PostToolUse | **P2** Metrics: Track success/retry/intervention rates |
|
|
24
|
+
| `load-context-skills.sh` | SessionStart | **P2** Context: Auto-load relevant skills for TODO |
|
|
25
|
+
| `capture-verification.sh` | PostToolUse | Capture quality command output for scorecards |
|
|
26
|
+
| `format.sh` | PostToolUse | Auto-format files after write/edit |
|
|
27
|
+
| `protect-files.sh` | PreToolUse | Block edits to critical files |
|
|
28
|
+
| `anti-rationalize.sh` | Stop | Prevent premature "done" declarations |
|
|
29
|
+
| `enforce-file-scope.sh` | PreToolUse | Parallel execution safety (worktrees) |
|
|
30
|
+
| `notify.sh` | PostToolUse | Send external notifications |
|
|
31
|
+
|
|
32
|
+
## Enforcement Configuration
|
|
33
|
+
|
|
34
|
+
Configure enforcement at multiple levels (highest to lowest priority):
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
Command flag → /run --enforce=off (this run only)
|
|
38
|
+
↓
|
|
39
|
+
Project config → .claude/settings.json (this project)
|
|
40
|
+
↓
|
|
41
|
+
User config → ~/.claude/settings.json (all projects)
|
|
42
|
+
↓
|
|
43
|
+
Default → strict
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Enforcement Modes
|
|
47
|
+
|
|
48
|
+
| Mode | Behavior |
|
|
49
|
+
|------|----------|
|
|
50
|
+
| `strict` (default) | Block operations, Claude must fix |
|
|
51
|
+
| `ask` | Show user prompt, allow override |
|
|
52
|
+
| `off` | Disable enforcement entirely |
|
|
53
|
+
|
|
54
|
+
### 1. Command Flags (Highest Priority)
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
/run phase-01 --enforce=off # Hotfix mode
|
|
58
|
+
/run phase-01 --enforce=ask # Ask instead of block
|
|
59
|
+
/run phase-01 --no-tdd # Skip TDD only
|
|
60
|
+
/run phase-01 --no-quality-gates # Skip quality gates only
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 2. Project Settings (.claude/settings.json)
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"codecruise": {
|
|
68
|
+
"enforce": "strict",
|
|
69
|
+
"enforce_tdd": "strict",
|
|
70
|
+
"enforce_quality": "strict",
|
|
71
|
+
"enforce_criteria": "strict"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This project uses strict TDD but asks for quality gates:
|
|
77
|
+
```json
|
|
78
|
+
{
|
|
79
|
+
"codecruise": {
|
|
80
|
+
"enforce": "strict",
|
|
81
|
+
"enforce_quality": "ask"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 3. User Settings (~/.claude/settings.json)
|
|
87
|
+
|
|
88
|
+
Same format. Sets your personal defaults across all projects.
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"codecruise": {
|
|
93
|
+
"enforce": "ask"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### In Practice
|
|
99
|
+
|
|
100
|
+
**Strict mode (default):**
|
|
101
|
+
```
|
|
102
|
+
❌ TDD violation: Write tests first before implementing.
|
|
103
|
+
Expected test file: src/auth/login.test.ts
|
|
104
|
+
[Operation blocked - Claude must create test first]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Ask mode:**
|
|
108
|
+
```
|
|
109
|
+
⚠️ TDD: No test file found. Expected: src/auth/login.test.ts
|
|
110
|
+
Allow implementation anyway? [y/N]
|
|
111
|
+
[User can override and continue]
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Off mode:**
|
|
115
|
+
```
|
|
116
|
+
[No enforcement, operation proceeds]
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### When to Use Each Mode
|
|
120
|
+
|
|
121
|
+
| Scenario | Recommended Mode |
|
|
122
|
+
|----------|------------------|
|
|
123
|
+
| Normal development | `strict` |
|
|
124
|
+
| Prototyping/exploration | `ask` |
|
|
125
|
+
| Hotfix/emergency | `off` |
|
|
126
|
+
| CI/automated runs | `strict` |
|
|
127
|
+
| Learning the system | `ask` |
|
|
128
|
+
| Existing codebase (no tests) | `ask` or `off` for TDD |
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## Quick Setup
|
|
133
|
+
|
|
134
|
+
Copy the example settings to your project:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
cp ~/.claude/hooks/settings.example.json .claude/settings.json
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Or merge with existing settings.
|
|
141
|
+
|
|
142
|
+
## P0 Enforcement (Critical Gates)
|
|
143
|
+
|
|
144
|
+
### 1. TDD Enforcement (enforce-tdd.sh)
|
|
145
|
+
|
|
146
|
+
**Blocks writes to implementation files unless tests exist first.**
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"hooks": {
|
|
151
|
+
"PreToolUse": [
|
|
152
|
+
{
|
|
153
|
+
"matcher": "Edit|Write",
|
|
154
|
+
"hooks": [
|
|
155
|
+
{
|
|
156
|
+
"type": "command",
|
|
157
|
+
"command": "~/.claude/hooks/enforce-tdd.sh",
|
|
158
|
+
"timeout": 5
|
|
159
|
+
}
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**What it enforces:**
|
|
168
|
+
- Cannot write to `src/auth/login.ts` unless `src/auth/login.test.ts` exists
|
|
169
|
+
- Test file patterns: `.test.ts`, `.spec.ts`, `__tests__/`, etc.
|
|
170
|
+
- Skips config files (json, yaml, md, etc.)
|
|
171
|
+
|
|
172
|
+
**Error message:**
|
|
173
|
+
```
|
|
174
|
+
TDD violation: Write tests first before implementing.
|
|
175
|
+
Expected test file: src/auth/login.test.ts
|
|
176
|
+
Create the test file with failing tests (RED), then implement (GREEN).
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### 2. Quality Gate Verification (verify-todo-completion.sh)
|
|
180
|
+
|
|
181
|
+
**Blocks TODO completion until all quality gates pass.**
|
|
182
|
+
|
|
183
|
+
```json
|
|
184
|
+
{
|
|
185
|
+
"hooks": {
|
|
186
|
+
"Stop": [
|
|
187
|
+
{
|
|
188
|
+
"hooks": [
|
|
189
|
+
{
|
|
190
|
+
"type": "command",
|
|
191
|
+
"command": "~/.claude/hooks/verify-todo-completion.sh",
|
|
192
|
+
"timeout": 30
|
|
193
|
+
}
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
]
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
**What it enforces:**
|
|
202
|
+
- Lint must pass (exit code 0)
|
|
203
|
+
- TypeScript must pass (exit code 0)
|
|
204
|
+
- Tests must pass (exit code 0, 0 failed)
|
|
205
|
+
|
|
206
|
+
**Error message:**
|
|
207
|
+
```
|
|
208
|
+
Quality gates failed: lint typecheck tests(2 failed).
|
|
209
|
+
Fix issues before completing TODO todo-1.2a-005.
|
|
210
|
+
Run 'pnpm quality' or check .codecruise/verification/ for details.
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### 3. Semantic Criteria Verification (Agent Hook)
|
|
214
|
+
|
|
215
|
+
**Uses Claude to verify TODO acceptance criteria are actually met.**
|
|
216
|
+
|
|
217
|
+
```json
|
|
218
|
+
{
|
|
219
|
+
"hooks": {
|
|
220
|
+
"Stop": [
|
|
221
|
+
{
|
|
222
|
+
"hooks": [
|
|
223
|
+
{
|
|
224
|
+
"type": "agent",
|
|
225
|
+
"prompt": "Verify TODO completion. Run ~/.claude/hooks/verify-criteria.sh to get current TODO criteria. Then check the codebase: 1) All criteria in the TODO are implemented, 2) All tests listed exist and would pass, 3) Files match the specification. Return {\"ok\": true} if complete, or {\"ok\": false, \"reason\": \"specific missing items\"}. Be strict - partial completion is NOT complete.",
|
|
226
|
+
"timeout": 120
|
|
227
|
+
}
|
|
228
|
+
]
|
|
229
|
+
}
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
**What it enforces:**
|
|
236
|
+
- Reads TODO from `roadmap/` with criteria list
|
|
237
|
+
- Spawns agent to verify each criterion against codebase
|
|
238
|
+
- Blocks if any criterion not implemented
|
|
239
|
+
|
|
240
|
+
**Error example:**
|
|
241
|
+
```json
|
|
242
|
+
{
|
|
243
|
+
"ok": false,
|
|
244
|
+
"reason": "Missing: User model does not have 'updatedAt' field as specified in criteria"
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## P1 State Machine Enforcement
|
|
249
|
+
|
|
250
|
+
### 4. State Machine Enforcement (enforce-state-machine.sh)
|
|
251
|
+
|
|
252
|
+
**Prevents invalid TODO state transitions.**
|
|
253
|
+
|
|
254
|
+
```json
|
|
255
|
+
{
|
|
256
|
+
"hooks": {
|
|
257
|
+
"PreToolUse": [
|
|
258
|
+
{
|
|
259
|
+
"matcher": "Edit|Write",
|
|
260
|
+
"hooks": [
|
|
261
|
+
{
|
|
262
|
+
"type": "command",
|
|
263
|
+
"command": "~/.claude/hooks/enforce-state-machine.sh",
|
|
264
|
+
"timeout": 5
|
|
265
|
+
}
|
|
266
|
+
]
|
|
267
|
+
}
|
|
268
|
+
]
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Valid transitions:**
|
|
274
|
+
```
|
|
275
|
+
pending → in_progress
|
|
276
|
+
in_progress → done, blocked, failed
|
|
277
|
+
blocked → in_progress
|
|
278
|
+
failed → in_progress, skipped
|
|
279
|
+
done → (terminal)
|
|
280
|
+
skipped → (terminal)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**What it prevents:**
|
|
284
|
+
- `pending → done` (must go through in_progress)
|
|
285
|
+
- `done → anything` (terminal state)
|
|
286
|
+
- `pending → skipped` (must attempt first)
|
|
287
|
+
|
|
288
|
+
## P2 Metrics & Context
|
|
289
|
+
|
|
290
|
+
### 5. Metrics Collection (collect-metrics.sh)
|
|
291
|
+
|
|
292
|
+
**Tracks success rates, retry rates, and activity.**
|
|
293
|
+
|
|
294
|
+
```json
|
|
295
|
+
{
|
|
296
|
+
"hooks": {
|
|
297
|
+
"PostToolUse": [
|
|
298
|
+
{
|
|
299
|
+
"matcher": "Bash|Edit|Write",
|
|
300
|
+
"hooks": [
|
|
301
|
+
{
|
|
302
|
+
"type": "command",
|
|
303
|
+
"command": "~/.claude/hooks/collect-metrics.sh",
|
|
304
|
+
"timeout": 5
|
|
305
|
+
}
|
|
306
|
+
]
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
**Metrics collected:**
|
|
314
|
+
- Test pass/fail events
|
|
315
|
+
- Lint pass/fail events
|
|
316
|
+
- Commits made
|
|
317
|
+
- Files written (code vs tests)
|
|
318
|
+
|
|
319
|
+
**Output:** `.codecruise/metrics/summary.json`
|
|
320
|
+
```json
|
|
321
|
+
{
|
|
322
|
+
"tests": { "passes": 42, "fails": 3, "success_rate": "93.33%" },
|
|
323
|
+
"lint": { "passes": 45, "fails": 0, "success_rate": "100%" },
|
|
324
|
+
"activity": { "commits": 12, "tests_written": 15, "code_written": 28 }
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### 6. Context-Aware Skill Loading (load-context-skills.sh)
|
|
329
|
+
|
|
330
|
+
**Auto-loads relevant skills based on TODO files.**
|
|
331
|
+
|
|
332
|
+
```json
|
|
333
|
+
{
|
|
334
|
+
"hooks": {
|
|
335
|
+
"SessionStart": [
|
|
336
|
+
{
|
|
337
|
+
"matcher": "startup|resume",
|
|
338
|
+
"hooks": [
|
|
339
|
+
{
|
|
340
|
+
"type": "command",
|
|
341
|
+
"command": "~/.claude/hooks/load-context-skills.sh",
|
|
342
|
+
"timeout": 10
|
|
343
|
+
}
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
]
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
**Skill triggers:**
|
|
352
|
+
| File Pattern | Skill Loaded |
|
|
353
|
+
|--------------|--------------|
|
|
354
|
+
| `*.ts`, `*.tsx` | TypeScript |
|
|
355
|
+
| `/components/`, `/app/` | Frontend |
|
|
356
|
+
| `/api/`, `/routes/` | Backend |
|
|
357
|
+
| `prisma`, `/models/` | Database |
|
|
358
|
+
| `*.test.*`, `*.spec.*` | Testing |
|
|
359
|
+
|
|
360
|
+
Skills are loaded into Claude's context at session start, reducing the need to re-explain patterns.
|
|
361
|
+
|
|
362
|
+
## Hook Configurations
|
|
363
|
+
|
|
364
|
+
### 1. Verification Capture (Essential)
|
|
365
|
+
|
|
366
|
+
Captures real output from quality commands for accurate scorecards.
|
|
367
|
+
|
|
368
|
+
```json
|
|
369
|
+
{
|
|
370
|
+
"hooks": {
|
|
371
|
+
"PostToolUse": [
|
|
372
|
+
{
|
|
373
|
+
"matcher": {
|
|
374
|
+
"tool": ["Bash"],
|
|
375
|
+
"bash_command_regex": "^(pnpm|npm|yarn) (run )?(quality|verify|check|test|lint)"
|
|
376
|
+
},
|
|
377
|
+
"command": ".codecruise/hooks/capture-verification.sh",
|
|
378
|
+
"timeout": 120000
|
|
379
|
+
}
|
|
380
|
+
]
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### 2. Auto-Format (Recommended)
|
|
386
|
+
|
|
387
|
+
Automatically formats files after edits. "Handles the last 10% before CI" — Boris Cherny
|
|
388
|
+
|
|
389
|
+
```json
|
|
390
|
+
{
|
|
391
|
+
"hooks": {
|
|
392
|
+
"PostToolUse": [
|
|
393
|
+
{
|
|
394
|
+
"matcher": {
|
|
395
|
+
"tool": ["Write", "Edit"]
|
|
396
|
+
},
|
|
397
|
+
"command": "~/.claude/hooks/format.sh"
|
|
398
|
+
}
|
|
399
|
+
]
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
Requires: `prettier`, `black`, `gofmt` (based on file type)
|
|
405
|
+
|
|
406
|
+
### 3. Protected Files (Recommended)
|
|
407
|
+
|
|
408
|
+
Blocks modification of critical files like secrets and state.
|
|
409
|
+
|
|
410
|
+
```json
|
|
411
|
+
{
|
|
412
|
+
"hooks": {
|
|
413
|
+
"PreToolUse": [
|
|
414
|
+
{
|
|
415
|
+
"matcher": {
|
|
416
|
+
"tool": ["Write", "Edit"]
|
|
417
|
+
},
|
|
418
|
+
"command": "~/.claude/hooks/protect-files.sh"
|
|
419
|
+
}
|
|
420
|
+
]
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Protected by default:
|
|
426
|
+
- `.env*` (secrets)
|
|
427
|
+
- `progress.yaml` (state - use commands instead)
|
|
428
|
+
- `roadmap/` (TODOs - use commands instead)
|
|
429
|
+
- `*.lock` (lock files)
|
|
430
|
+
- `.git/`, `.ssh/`, `.aws/` (sensitive directories)
|
|
431
|
+
|
|
432
|
+
### 4. Anti-Rationalization (Autonomous Mode)
|
|
433
|
+
|
|
434
|
+
Prevents Claude from declaring victory with incomplete work. From Trail of Bits research.
|
|
435
|
+
|
|
436
|
+
```json
|
|
437
|
+
{
|
|
438
|
+
"hooks": {
|
|
439
|
+
"Stop": [
|
|
440
|
+
{
|
|
441
|
+
"command": "~/.claude/hooks/anti-rationalize.sh"
|
|
442
|
+
}
|
|
443
|
+
]
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
Blocks responses containing:
|
|
449
|
+
- "pre-existing"
|
|
450
|
+
- "out of scope"
|
|
451
|
+
- "leave for follow-up"
|
|
452
|
+
- "too many issues"
|
|
453
|
+
- "will address later"
|
|
454
|
+
|
|
455
|
+
### 5. File Scope Enforcement (Parallel Execution)
|
|
456
|
+
|
|
457
|
+
Blocks edits outside owned file scope. Essential for worktree-based parallel work.
|
|
458
|
+
|
|
459
|
+
```json
|
|
460
|
+
{
|
|
461
|
+
"hooks": {
|
|
462
|
+
"PreToolUse": [
|
|
463
|
+
{
|
|
464
|
+
"matcher": {
|
|
465
|
+
"tool": ["Write", "Edit"]
|
|
466
|
+
},
|
|
467
|
+
"command": "~/.claude/hooks/enforce-file-scope.sh"
|
|
468
|
+
}
|
|
469
|
+
]
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
```
|
|
473
|
+
|
|
474
|
+
Create `.claude/file_scope.txt` in each worktree:
|
|
475
|
+
```
|
|
476
|
+
src/auth/**/*
|
|
477
|
+
tests/auth/**/*
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
### 6. Notifications (Autonomous Mode)
|
|
481
|
+
|
|
482
|
+
Send notifications on important events.
|
|
483
|
+
|
|
484
|
+
```json
|
|
485
|
+
{
|
|
486
|
+
"hooks": {
|
|
487
|
+
"PostToolUse": [
|
|
488
|
+
{
|
|
489
|
+
"matcher": {
|
|
490
|
+
"tool": ["Bash"],
|
|
491
|
+
"bash_command_regex": "pilot-notify"
|
|
492
|
+
},
|
|
493
|
+
"command": "~/.claude/hooks/notify.sh"
|
|
494
|
+
}
|
|
495
|
+
]
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
Configure via environment:
|
|
501
|
+
```bash
|
|
502
|
+
export PILOT_NOTIFY_CHANNEL=slack
|
|
503
|
+
export SLACK_WEBHOOK_URL=https://hooks.slack.com/services/...
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### 7. Pre-Compact (Context Preservation)
|
|
507
|
+
|
|
508
|
+
Saves session context before compaction. Ensures "why" decisions survive context compression.
|
|
509
|
+
|
|
510
|
+
```json
|
|
511
|
+
{
|
|
512
|
+
"hooks": {
|
|
513
|
+
"PreCompact": [
|
|
514
|
+
{
|
|
515
|
+
"command": "~/.claude/hooks/pre-compact.sh"
|
|
516
|
+
}
|
|
517
|
+
]
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
Saves to `quality_reports/session_logs/`.
|
|
523
|
+
|
|
524
|
+
## Output Files
|
|
525
|
+
|
|
526
|
+
### Verification Output
|
|
527
|
+
|
|
528
|
+
```
|
|
529
|
+
.codecruise/verification/
|
|
530
|
+
├── timestamp.txt # When verification ran
|
|
531
|
+
├── lint.txt # Lint output
|
|
532
|
+
├── lint-exit.txt # Lint exit code
|
|
533
|
+
├── typecheck.txt # TypeScript output
|
|
534
|
+
├── typecheck-exit.txt # TypeScript exit code
|
|
535
|
+
├── test.txt # Test output
|
|
536
|
+
├── test-exit.txt # Test exit code
|
|
537
|
+
└── summary.json # Parsed summary for scorecard
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### Session Logs
|
|
541
|
+
|
|
542
|
+
```
|
|
543
|
+
quality_reports/session_logs/
|
|
544
|
+
├── 2026-02-19_auth-implementation.md
|
|
545
|
+
├── 2026-02-20_payment-flow.md
|
|
546
|
+
└── ...
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
## Environment Variables
|
|
550
|
+
|
|
551
|
+
| Variable | Purpose | Default |
|
|
552
|
+
|----------|---------|---------|
|
|
553
|
+
| `PILOT_NOTIFY_CHANNEL` | Notification channel: `slack`, `webhook` | none |
|
|
554
|
+
| `SLACK_WEBHOOK_URL` | Slack incoming webhook URL | none |
|
|
555
|
+
| `PILOT_WEBHOOK_URL` | Generic webhook URL | none |
|
|
556
|
+
| `PILOT_PROTECTED_FILES` | Additional protected file patterns | none |
|
|
557
|
+
|
|
558
|
+
## Manual Execution
|
|
559
|
+
|
|
560
|
+
Test hooks directly:
|
|
561
|
+
|
|
562
|
+
```bash
|
|
563
|
+
# Test verification capture
|
|
564
|
+
.codecruise/hooks/capture-verification.sh
|
|
565
|
+
|
|
566
|
+
# Test format hook (provide file path via stdin)
|
|
567
|
+
echo '{"tool_input": {"file_path": "src/test.ts"}}' | ~/.claude/hooks/format.sh
|
|
568
|
+
|
|
569
|
+
# Test notification
|
|
570
|
+
echo '{"event": "blocker", "message": "Redis not running"}' | ~/.claude/hooks/notify.sh
|
|
571
|
+
```
|
|
572
|
+
|
|
573
|
+
## Creating Custom Hooks
|
|
574
|
+
|
|
575
|
+
Hooks receive JSON input via stdin and can output JSON to affect behavior.
|
|
576
|
+
|
|
577
|
+
### PreToolUse Hook
|
|
578
|
+
|
|
579
|
+
Can block tool execution:
|
|
580
|
+
|
|
581
|
+
```bash
|
|
582
|
+
#!/bin/bash
|
|
583
|
+
INPUT=$(cat)
|
|
584
|
+
|
|
585
|
+
# Return this to block:
|
|
586
|
+
cat <<EOF
|
|
587
|
+
{
|
|
588
|
+
"hookSpecificOutput": {
|
|
589
|
+
"hookEventName": "PreToolUse",
|
|
590
|
+
"permissionDecision": "deny",
|
|
591
|
+
"permissionDecisionReason": "Reason for blocking"
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
EOF
|
|
595
|
+
exit 0
|
|
596
|
+
|
|
597
|
+
# Return nothing or exit 0 to allow
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
### Stop Hook
|
|
601
|
+
|
|
602
|
+
Can block session exit:
|
|
603
|
+
|
|
604
|
+
```bash
|
|
605
|
+
#!/bin/bash
|
|
606
|
+
INPUT=$(cat)
|
|
607
|
+
RESPONSE=$(echo "$INPUT" | jq -r '.response // empty')
|
|
608
|
+
|
|
609
|
+
# Return this to block exit:
|
|
610
|
+
cat <<EOF
|
|
611
|
+
{
|
|
612
|
+
"decision": "block",
|
|
613
|
+
"reason": "Why the session should not end"
|
|
614
|
+
}
|
|
615
|
+
EOF
|
|
616
|
+
exit 0
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
## Troubleshooting
|
|
620
|
+
|
|
621
|
+
**Hook not executing:**
|
|
622
|
+
- Check file permissions: `chmod +x hook.sh`
|
|
623
|
+
- Verify matcher patterns match your commands
|
|
624
|
+
- Check timeout settings (default 30s may be too short)
|
|
625
|
+
|
|
626
|
+
**JSON parsing errors:**
|
|
627
|
+
- Ensure `jq` is installed
|
|
628
|
+
- Validate JSON output with `jq .`
|
|
629
|
+
|
|
630
|
+
**Protected files blocking legitimate edits:**
|
|
631
|
+
- Modify `protect-files.sh` to adjust patterns
|
|
632
|
+
- Or use dedicated commands (`/found`, `/run`) instead of direct edits
|