anvil-dev-framework 0.1.6

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.
Files changed (190) hide show
  1. package/README.md +719 -0
  2. package/VERSION +1 -0
  3. package/docs/ANVIL-REPO-IMPLEMENTATION-PLAN.md +441 -0
  4. package/docs/FIRST-SKILL-TUTORIAL.md +408 -0
  5. package/docs/INSTALLATION-RETRO-NOTES.md +458 -0
  6. package/docs/INSTALLATION.md +984 -0
  7. package/docs/anvil-hud.md +469 -0
  8. package/docs/anvil-init.md +255 -0
  9. package/docs/anvil-state.md +210 -0
  10. package/docs/boris-cherny-ralph-wiggum-insights.md +608 -0
  11. package/docs/command-reference.md +2022 -0
  12. package/docs/hooks-tts.md +368 -0
  13. package/docs/implementation-guide.md +810 -0
  14. package/docs/linear-github-integration.md +247 -0
  15. package/docs/local-issues.md +677 -0
  16. package/docs/patterns/README.md +419 -0
  17. package/docs/planning-responsibilities.md +139 -0
  18. package/docs/session-workflow.md +573 -0
  19. package/docs/simplification-plan-template.md +297 -0
  20. package/docs/simplification-principles.md +129 -0
  21. package/docs/specifications/CCS-RALPH-INTEGRATION-DESIGN.md +633 -0
  22. package/docs/specifications/CCS-RESEARCH-REPORT.md +169 -0
  23. package/docs/specifications/PLAN-ANV-verification-ralph-wiggum.md +403 -0
  24. package/docs/specifications/PLAN-parallel-tracks-anvil-memory-ccs.md +494 -0
  25. package/docs/specifications/SPEC-ANV-VRW/component-01-verify.md +208 -0
  26. package/docs/specifications/SPEC-ANV-VRW/component-02-stop-gate.md +226 -0
  27. package/docs/specifications/SPEC-ANV-VRW/component-03-posttooluse.md +209 -0
  28. package/docs/specifications/SPEC-ANV-VRW/component-04-ralph-wiggum.md +604 -0
  29. package/docs/specifications/SPEC-ANV-VRW/component-05-atomic-actions.md +311 -0
  30. package/docs/specifications/SPEC-ANV-VRW/component-06-verify-subagent.md +264 -0
  31. package/docs/specifications/SPEC-ANV-VRW/component-07-claude-md.md +363 -0
  32. package/docs/specifications/SPEC-ANV-VRW/index.md +182 -0
  33. package/docs/specifications/SPEC-ANV-anvil-memory.md +573 -0
  34. package/docs/specifications/SPEC-ANV-context-checkpoints.md +781 -0
  35. package/docs/specifications/SPEC-ANV-verification-ralph-wiggum.md +789 -0
  36. package/docs/sync.md +122 -0
  37. package/global/CLAUDE.md +140 -0
  38. package/global/agents/verify-app.md +164 -0
  39. package/global/commands/anvil-settings.md +527 -0
  40. package/global/commands/anvil-sync.md +121 -0
  41. package/global/commands/change.md +197 -0
  42. package/global/commands/clarify.md +252 -0
  43. package/global/commands/cleanup.md +292 -0
  44. package/global/commands/commit-push-pr.md +207 -0
  45. package/global/commands/decay-review.md +127 -0
  46. package/global/commands/discover.md +158 -0
  47. package/global/commands/doc-coverage.md +122 -0
  48. package/global/commands/evidence.md +307 -0
  49. package/global/commands/explore.md +121 -0
  50. package/global/commands/force-exit.md +135 -0
  51. package/global/commands/handoff.md +191 -0
  52. package/global/commands/healthcheck.md +302 -0
  53. package/global/commands/hud.md +84 -0
  54. package/global/commands/insights.md +319 -0
  55. package/global/commands/linear-setup.md +184 -0
  56. package/global/commands/lint-fix.md +198 -0
  57. package/global/commands/orient.md +510 -0
  58. package/global/commands/plan.md +228 -0
  59. package/global/commands/ralph.md +346 -0
  60. package/global/commands/ready.md +182 -0
  61. package/global/commands/release.md +305 -0
  62. package/global/commands/retro.md +96 -0
  63. package/global/commands/shard.md +166 -0
  64. package/global/commands/spec.md +227 -0
  65. package/global/commands/sprint.md +184 -0
  66. package/global/commands/tasks.md +228 -0
  67. package/global/commands/test-and-commit.md +151 -0
  68. package/global/commands/validate.md +132 -0
  69. package/global/commands/verify.md +251 -0
  70. package/global/commands/weekly-review.md +156 -0
  71. package/global/hooks/__pycache__/ralph_context_monitor.cpython-314.pyc +0 -0
  72. package/global/hooks/__pycache__/statusline_agent_sync.cpython-314.pyc +0 -0
  73. package/global/hooks/anvil_memory_observe.ts +322 -0
  74. package/global/hooks/anvil_memory_session.ts +166 -0
  75. package/global/hooks/anvil_memory_stop.ts +187 -0
  76. package/global/hooks/parse_transcript.py +116 -0
  77. package/global/hooks/post_merge_cleanup.sh +132 -0
  78. package/global/hooks/post_tool_format.sh +215 -0
  79. package/global/hooks/ralph_context_monitor.py +240 -0
  80. package/global/hooks/ralph_stop.sh +502 -0
  81. package/global/hooks/statusline.sh +1110 -0
  82. package/global/hooks/statusline_agent_sync.py +224 -0
  83. package/global/hooks/stop_gate.sh +250 -0
  84. package/global/lib/.claude/anvil-state.json +21 -0
  85. package/global/lib/__pycache__/agent_registry.cpython-314.pyc +0 -0
  86. package/global/lib/__pycache__/claim_service.cpython-314.pyc +0 -0
  87. package/global/lib/__pycache__/coderabbit_service.cpython-314.pyc +0 -0
  88. package/global/lib/__pycache__/config_service.cpython-314.pyc +0 -0
  89. package/global/lib/__pycache__/coordination_service.cpython-314.pyc +0 -0
  90. package/global/lib/__pycache__/doc_coverage_service.cpython-314.pyc +0 -0
  91. package/global/lib/__pycache__/gate_logger.cpython-314.pyc +0 -0
  92. package/global/lib/__pycache__/github_service.cpython-314.pyc +0 -0
  93. package/global/lib/__pycache__/hygiene_service.cpython-314.pyc +0 -0
  94. package/global/lib/__pycache__/issue_models.cpython-314.pyc +0 -0
  95. package/global/lib/__pycache__/issue_provider.cpython-314.pyc +0 -0
  96. package/global/lib/__pycache__/linear_data_service.cpython-314.pyc +0 -0
  97. package/global/lib/__pycache__/linear_provider.cpython-314.pyc +0 -0
  98. package/global/lib/__pycache__/local_provider.cpython-314.pyc +0 -0
  99. package/global/lib/__pycache__/quality_service.cpython-314.pyc +0 -0
  100. package/global/lib/__pycache__/ralph_state.cpython-314.pyc +0 -0
  101. package/global/lib/__pycache__/state_manager.cpython-314.pyc +0 -0
  102. package/global/lib/__pycache__/transcript_parser.cpython-314.pyc +0 -0
  103. package/global/lib/__pycache__/verification_runner.cpython-314.pyc +0 -0
  104. package/global/lib/__pycache__/verify_iteration.cpython-314.pyc +0 -0
  105. package/global/lib/__pycache__/verify_subagent.cpython-314.pyc +0 -0
  106. package/global/lib/agent_registry.py +995 -0
  107. package/global/lib/anvil-state.sh +435 -0
  108. package/global/lib/claim_service.py +515 -0
  109. package/global/lib/coderabbit_service.py +314 -0
  110. package/global/lib/config_service.py +423 -0
  111. package/global/lib/coordination_service.py +331 -0
  112. package/global/lib/doc_coverage_service.py +1305 -0
  113. package/global/lib/gate_logger.py +316 -0
  114. package/global/lib/github_service.py +310 -0
  115. package/global/lib/handoff_generator.py +775 -0
  116. package/global/lib/hygiene_service.py +712 -0
  117. package/global/lib/issue_models.py +257 -0
  118. package/global/lib/issue_provider.py +339 -0
  119. package/global/lib/linear_data_service.py +210 -0
  120. package/global/lib/linear_provider.py +987 -0
  121. package/global/lib/linear_provider.py.backup +671 -0
  122. package/global/lib/local_provider.py +486 -0
  123. package/global/lib/orient_fast.py +457 -0
  124. package/global/lib/quality_service.py +470 -0
  125. package/global/lib/ralph_prompt_generator.py +563 -0
  126. package/global/lib/ralph_state.py +1202 -0
  127. package/global/lib/state_manager.py +417 -0
  128. package/global/lib/transcript_parser.py +597 -0
  129. package/global/lib/verification_runner.py +557 -0
  130. package/global/lib/verify_iteration.py +490 -0
  131. package/global/lib/verify_subagent.py +250 -0
  132. package/global/skills/README.md +155 -0
  133. package/global/skills/quality-gates/SKILL.md +252 -0
  134. package/global/skills/skill-template/SKILL.md +109 -0
  135. package/global/skills/testing-strategies/SKILL.md +337 -0
  136. package/global/templates/CHANGE-template.md +105 -0
  137. package/global/templates/HANDOFF-template.md +63 -0
  138. package/global/templates/PLAN-template.md +111 -0
  139. package/global/templates/SPEC-template.md +93 -0
  140. package/global/templates/ralph/PROMPT.md.template +89 -0
  141. package/global/templates/ralph/fix_plan.md.template +31 -0
  142. package/global/templates/ralph/progress.txt.template +23 -0
  143. package/global/tests/__pycache__/test_doc_coverage.cpython-314.pyc +0 -0
  144. package/global/tests/test_doc_coverage.py +520 -0
  145. package/global/tests/test_issue_models.py +299 -0
  146. package/global/tests/test_local_provider.py +323 -0
  147. package/global/tools/README.md +178 -0
  148. package/global/tools/__pycache__/anvil-hud.cpython-314.pyc +0 -0
  149. package/global/tools/anvil-hud.py +3622 -0
  150. package/global/tools/anvil-hud.py.bak +3318 -0
  151. package/global/tools/anvil-issue.py +432 -0
  152. package/global/tools/anvil-memory/CLAUDE.md +49 -0
  153. package/global/tools/anvil-memory/README.md +42 -0
  154. package/global/tools/anvil-memory/bun.lock +25 -0
  155. package/global/tools/anvil-memory/bunfig.toml +9 -0
  156. package/global/tools/anvil-memory/package.json +23 -0
  157. package/global/tools/anvil-memory/src/__tests__/ccs/context-monitor.test.ts +535 -0
  158. package/global/tools/anvil-memory/src/__tests__/ccs/edge-cases.test.ts +645 -0
  159. package/global/tools/anvil-memory/src/__tests__/ccs/fixtures.ts +363 -0
  160. package/global/tools/anvil-memory/src/__tests__/ccs/index.ts +8 -0
  161. package/global/tools/anvil-memory/src/__tests__/ccs/integration.test.ts +417 -0
  162. package/global/tools/anvil-memory/src/__tests__/ccs/prompt-generator.test.ts +571 -0
  163. package/global/tools/anvil-memory/src/__tests__/ccs/ralph-stop.test.ts +440 -0
  164. package/global/tools/anvil-memory/src/__tests__/ccs/test-utils.ts +252 -0
  165. package/global/tools/anvil-memory/src/__tests__/commands.test.ts +657 -0
  166. package/global/tools/anvil-memory/src/__tests__/db.test.ts +641 -0
  167. package/global/tools/anvil-memory/src/__tests__/hooks.test.ts +272 -0
  168. package/global/tools/anvil-memory/src/__tests__/performance.test.ts +427 -0
  169. package/global/tools/anvil-memory/src/__tests__/test-utils.ts +113 -0
  170. package/global/tools/anvil-memory/src/commands/checkpoint.ts +197 -0
  171. package/global/tools/anvil-memory/src/commands/get.ts +115 -0
  172. package/global/tools/anvil-memory/src/commands/init.ts +94 -0
  173. package/global/tools/anvil-memory/src/commands/observe.ts +163 -0
  174. package/global/tools/anvil-memory/src/commands/search.ts +112 -0
  175. package/global/tools/anvil-memory/src/db.ts +638 -0
  176. package/global/tools/anvil-memory/src/index.ts +205 -0
  177. package/global/tools/anvil-memory/src/types.ts +122 -0
  178. package/global/tools/anvil-memory/tsconfig.json +29 -0
  179. package/global/tools/ralph-loop.sh +359 -0
  180. package/package.json +45 -0
  181. package/scripts/anvil +822 -0
  182. package/scripts/extract_patterns.py +222 -0
  183. package/scripts/init-project.sh +541 -0
  184. package/scripts/install.sh +229 -0
  185. package/scripts/postinstall.js +41 -0
  186. package/scripts/rollback.sh +188 -0
  187. package/scripts/sync.sh +623 -0
  188. package/scripts/test-statusline.sh +248 -0
  189. package/scripts/update_claude_md.py +224 -0
  190. package/scripts/verify.sh +255 -0
@@ -0,0 +1,789 @@
1
+ ---
2
+ spec_id: SPEC-ANV-VRW
3
+ title: Verification Feedback Loops & Ralph Wiggum Mode
4
+ status: draft
5
+ created: 2026-01-04
6
+ updated: 2026-01-04
7
+ linear_issue: ANV-140
8
+ references:
9
+ - https://x.com/bcherny/status/2007179832300581177
10
+ - https://github.com/anthropics/claude-code/tree/main/plugins/ralph-wiggum
11
+ - docs/boris-cherny-ralph-wiggum-insights.md
12
+ ---
13
+
14
+ # Verification Feedback Loops & Ralph Wiggum Mode
15
+
16
+ ## Executive Summary
17
+
18
+ This specification implements proven methodologies from Boris Cherny (Claude Code creator) and Geoffrey Huntley's Ralph Wiggum technique to achieve **2-3x quality improvements** through verification feedback loops and enable **long-running unattended execution**.
19
+
20
+ ### Key Outcomes
21
+ - **Verification-first workflow** that catches issues before they compound
22
+ - **Stop hook gates** that prevent premature task completion
23
+ - **Ralph Wiggum mode** for overnight/unattended execution
24
+ - **Atomic action commands** for rapid inner-loop execution
25
+ - **Self-improving CLAUDE.md** via automated pattern extraction
26
+
27
+ ---
28
+
29
+ ## Problem Statement
30
+
31
+ ### Current Gaps vs. Best Practices
32
+
33
+ | Gap | Impact | Boris/Ralph Evidence |
34
+ |-----|--------|---------------------|
35
+ | No verification feedback loop | Errors compound, manual QA required | Boris: "2-3x quality improvement" |
36
+ | No stop hook gating | Claude exits with failing tests | Boris: Non-zero exit blocks stopping |
37
+ | No PostToolUse formatting | Manual formatting, inconsistent code | Boris: Auto-format on every edit |
38
+ | No long-running mode | Requires constant supervision | Geoffrey: 6 repos overnight, $50k→$297 |
39
+ | Scattered atomic actions | Slow inner loops | Boris: `/commit-push-pr` one-liners |
40
+ | Manual CLAUDE.md updates | Stale project context | Boris: GitHub Actions extraction |
41
+
42
+ ### User Pain Points
43
+
44
+ 1. **Quality Drift**: Without verification loops, small errors accumulate into large fixes
45
+ 2. **Context Pollution**: Main session bloated with research that should be in subagents
46
+ 3. **Supervision Burden**: Can't run Claude overnight without babysitting
47
+ 4. **Slow Iterations**: Common multi-step actions (test→commit→push→PR) require multiple commands
48
+
49
+ ---
50
+
51
+ ## Goals
52
+
53
+ | Goal | Success Metric |
54
+ |------|---------------|
55
+ | Verification-first workflow | All PRs pass CI before human review |
56
+ | Stop hook enforcement | Zero exits with failing tests |
57
+ | Unattended execution | 4+ hour autonomous sessions |
58
+ | Rapid inner loops | Single command for test→commit→push→PR |
59
+ | Self-improving context | CLAUDE.md updated weekly from commits |
60
+
61
+ ---
62
+
63
+ ## Component 1: Verification Command (`/verify`)
64
+
65
+ ### Overview
66
+
67
+ A new slash command that runs verification checks with automatic iteration on failure. This is the **highest-impact** feature from Boris Cherny's methodology.
68
+
69
+ ### Requirements
70
+
71
+ | ID | Requirement | Priority |
72
+ |----|-------------|----------|
73
+ | REQ-V-100 | Run configurable verification suite (tests, lint, types) | P0 |
74
+ | REQ-V-101 | On failure, re-read failing files and attempt fix | P0 |
75
+ | REQ-V-102 | Maximum 3 automatic fix attempts before escalating | P0 |
76
+ | REQ-V-103 | Track verification state (pass/fail/iterations) | P0 |
77
+ | REQ-V-104 | Integrate with stop hook for exit gating | P1 |
78
+ | REQ-V-105 | Support custom verification commands per project | P1 |
79
+ | REQ-V-106 | Report verification results in statusline | P2 |
80
+
81
+ ### Behavior
82
+
83
+ ```
84
+ User: /verify
85
+
86
+ Claude:
87
+ 1. Run verification suite:
88
+ - npm test (or configured test command)
89
+ - npm run lint
90
+ - npm run typecheck
91
+
92
+ 2. If ALL pass:
93
+ ✅ Verification passed (tests: 47, lint: clean, types: clean)
94
+ [Mark task ready for completion]
95
+
96
+ 3. If ANY fail:
97
+ ❌ Verification failed - 3 test failures
98
+
99
+ Analyzing failures...
100
+ - src/auth/login.test.ts:45 - Expected 200, got 401
101
+ - src/auth/login.test.ts:67 - Timeout
102
+
103
+ Attempting fix (iteration 1/3)...
104
+ [Re-read failing files]
105
+ [Apply targeted fix]
106
+ [Re-run verification]
107
+
108
+ 4. After 3 failed iterations:
109
+ ⚠️ Verification failed after 3 attempts
110
+
111
+ Remaining issues:
112
+ - [List of unfixed issues]
113
+
114
+ Manual intervention required.
115
+ ```
116
+
117
+ ### Configuration
118
+
119
+ ```yaml
120
+ # .claude/settings.yaml
121
+ verification:
122
+ commands:
123
+ test: "npm test"
124
+ lint: "npm run lint"
125
+ types: "npm run typecheck"
126
+ max_iterations: 3
127
+ required_for_completion: true
128
+ ```
129
+
130
+ ### Skill Implementation
131
+
132
+ ```markdown
133
+ # /verify - Verification Feedback Loop
134
+
135
+ > Run verification suite with automatic iteration on failure.
136
+
137
+ ## Execution Steps
138
+
139
+ ### Step 1: Run Verification Suite
140
+ Execute all configured verification commands:
141
+ - Test suite
142
+ - Linter
143
+ - Type checker
144
+
145
+ ### Step 2: Analyze Results
146
+ If all pass → Report success, allow completion
147
+ If any fail → Parse errors, identify failing files
148
+
149
+ ### Step 3: Iterate on Failures (max 3 times)
150
+ 1. Re-read each failing file
151
+ 2. Analyze the specific error
152
+ 3. Apply targeted fix
153
+ 4. Re-run failing command only
154
+ 5. Repeat until pass or max iterations
155
+
156
+ ### Step 4: Report Final State
157
+ - Success: List all passing checks
158
+ - Failure: List remaining issues, request manual help
159
+
160
+ ## Anti-Patterns
161
+ - ❌ Making broad changes instead of targeted fixes
162
+ - ❌ Continuing past max iterations
163
+ - ❌ Ignoring failing checks
164
+ ```
165
+
166
+ ---
167
+
168
+ ## Component 2: Stop Hook Verification Gate
169
+
170
+ ### Overview
171
+
172
+ A stop hook that prevents Claude from exiting when verification fails. This ensures the AI cannot prematurely complete tasks with broken code.
173
+
174
+ ### Requirements
175
+
176
+ | ID | Requirement | Priority |
177
+ |----|-------------|----------|
178
+ | REQ-SH-100 | Run verification checks before allowing exit | P0 |
179
+ | REQ-SH-101 | Return non-zero exit code to block stopping | P0 |
180
+ | REQ-SH-102 | Provide clear feedback on what's blocking exit | P0 |
181
+ | REQ-SH-103 | Allow override with explicit user command | P1 |
182
+ | REQ-SH-104 | Configure which checks are mandatory | P1 |
183
+ | REQ-SH-105 | Log all gate events for debugging | P2 |
184
+
185
+ ### Hook Implementation
186
+
187
+ ```bash
188
+ #!/bin/bash
189
+ # global/hooks/stop_gate.sh
190
+ # Stop hook that gates on verification
191
+
192
+ set -e
193
+
194
+ # Check if verification is required
195
+ REQUIRE_VERIFY="${ANVIL_REQUIRE_VERIFICATION:-true}"
196
+
197
+ if [[ "$REQUIRE_VERIFY" != "true" ]]; then
198
+ exit 0 # Allow exit
199
+ fi
200
+
201
+ # Check for explicit override
202
+ if [[ "$ANVIL_FORCE_EXIT" == "true" ]]; then
203
+ echo "⚠️ Force exit requested - bypassing verification"
204
+ exit 0
205
+ fi
206
+
207
+ echo "🔒 Running verification gate..."
208
+
209
+ # Run test suite
210
+ if ! npm test --silent 2>/dev/null; then
211
+ echo "❌ Tests failing - cannot exit"
212
+ echo "Fix failing tests or use /force-exit to bypass"
213
+ exit 1 # Block exit
214
+ fi
215
+
216
+ # Run lint
217
+ if ! npm run lint --silent 2>/dev/null; then
218
+ echo "❌ Lint errors - cannot exit"
219
+ echo "Fix lint errors or use /force-exit to bypass"
220
+ exit 1
221
+ fi
222
+
223
+ # Run typecheck
224
+ if ! npm run typecheck --silent 2>/dev/null; then
225
+ echo "❌ Type errors - cannot exit"
226
+ echo "Fix type errors or use /force-exit to bypass"
227
+ exit 1
228
+ fi
229
+
230
+ echo "✅ Verification gate passed"
231
+ exit 0
232
+ ```
233
+
234
+ ### Settings Configuration
235
+
236
+ ```json
237
+ {
238
+ "hooks": {
239
+ "Stop": [{
240
+ "type": "command",
241
+ "command": "bash global/hooks/stop_gate.sh"
242
+ }]
243
+ }
244
+ }
245
+ ```
246
+
247
+ ---
248
+
249
+ ## Component 3: PostToolUse Formatting Hook
250
+
251
+ ### Overview
252
+
253
+ Automatically format code files after every Edit or Write operation. This catches the "last 10%" of formatting issues that Claude often misses.
254
+
255
+ ### Requirements
256
+
257
+ | ID | Requirement | Priority |
258
+ |----|-------------|----------|
259
+ | REQ-PTU-100 | Run formatter on files after Edit tool | P0 |
260
+ | REQ-PTU-101 | Run formatter on files after Write tool | P0 |
261
+ | REQ-PTU-102 | Support project-specific formatter (prettier, black, etc.) | P0 |
262
+ | REQ-PTU-103 | Execute in <500ms to avoid slowdown | P1 |
263
+ | REQ-PTU-104 | Skip binary files and node_modules | P1 |
264
+ | REQ-PTU-105 | Log formatting changes for visibility | P2 |
265
+
266
+ ### Hook Implementation
267
+
268
+ ```bash
269
+ #!/bin/bash
270
+ # global/hooks/post_tool_format.sh
271
+ # PostToolUse hook for auto-formatting
272
+
273
+ FILE_PATH="$CLAUDE_FILE_PATH"
274
+
275
+ # Skip if no file path
276
+ if [[ -z "$FILE_PATH" ]]; then
277
+ exit 0
278
+ fi
279
+
280
+ # Skip non-existent files
281
+ if [[ ! -f "$FILE_PATH" ]]; then
282
+ exit 0
283
+ fi
284
+
285
+ # Skip binary and excluded paths
286
+ case "$FILE_PATH" in
287
+ */node_modules/*|*/.git/*|*.png|*.jpg|*.ico|*.woff*)
288
+ exit 0
289
+ ;;
290
+ esac
291
+
292
+ # Determine formatter based on file type
293
+ case "$FILE_PATH" in
294
+ *.ts|*.tsx|*.js|*.jsx|*.json|*.md|*.css|*.html)
295
+ if command -v npx &> /dev/null; then
296
+ npx prettier --write "$FILE_PATH" 2>/dev/null || true
297
+ fi
298
+ ;;
299
+ *.py)
300
+ if command -v black &> /dev/null; then
301
+ black "$FILE_PATH" 2>/dev/null || true
302
+ elif command -v ruff &> /dev/null; then
303
+ ruff format "$FILE_PATH" 2>/dev/null || true
304
+ fi
305
+ ;;
306
+ *.go)
307
+ if command -v gofmt &> /dev/null; then
308
+ gofmt -w "$FILE_PATH" 2>/dev/null || true
309
+ fi
310
+ ;;
311
+ *.sh)
312
+ if command -v shfmt &> /dev/null; then
313
+ shfmt -w "$FILE_PATH" 2>/dev/null || true
314
+ fi
315
+ ;;
316
+ esac
317
+
318
+ exit 0
319
+ ```
320
+
321
+ ### Settings Configuration
322
+
323
+ ```json
324
+ {
325
+ "hooks": {
326
+ "PostToolUse": [{
327
+ "matcher": "Edit|Write",
328
+ "hooks": [{
329
+ "type": "command",
330
+ "command": "bash global/hooks/post_tool_format.sh"
331
+ }]
332
+ }]
333
+ }
334
+ }
335
+ ```
336
+
337
+ ---
338
+
339
+ ## Component 4: Ralph Wiggum Mode (`/ralph`)
340
+
341
+ ### Overview
342
+
343
+ Long-running unattended execution mode based on Geoffrey Huntley's technique. Uses a bash loop with completion promises and stop hook interception for multi-hour autonomous sessions.
344
+
345
+ ### Core Mechanism
346
+
347
+ ```bash
348
+ # The Ralph Wiggum loop
349
+ while :; do
350
+ cat PROMPT.md | npx --yes @anthropic/claude-code --print
351
+ done
352
+ ```
353
+
354
+ ### Requirements
355
+
356
+ | ID | Requirement | Priority |
357
+ |----|-------------|----------|
358
+ | REQ-RW-100 | Create PROMPT.md with structured task format | P0 |
359
+ | REQ-RW-101 | Implement completion promise pattern | P0 |
360
+ | REQ-RW-102 | Stop hook intercepts exit, restarts on incomplete | P0 |
361
+ | REQ-RW-103 | Maximum iterations safety (default: 50) | P0 |
362
+ | REQ-RW-104 | Track iteration count and progress | P0 |
363
+ | REQ-RW-105 | Single-item focus per iteration (critical) | P0 |
364
+ | REQ-RW-106 | Context management via subagents | P1 |
365
+ | REQ-RW-107 | Self-learning AGENT.md updates | P2 |
366
+
367
+ ### Three-Phase Architecture
368
+
369
+ Based on Ralph Wiggum's proven pattern:
370
+
371
+ ```
372
+ Phase 1: Requirements → specs/*.md
373
+ Phase 2: Specs → fix_plan.md (TODO list)
374
+ Phase 3: TODO items → Implementation (one at a time)
375
+ ```
376
+
377
+ ### PROMPT.md Format
378
+
379
+ ```markdown
380
+ # Task: [Feature Name]
381
+
382
+ ## Objective
383
+ [Clear, single-item objective]
384
+
385
+ ## Current State
386
+ - Iteration: {iteration_count}
387
+ - Last action: {last_action}
388
+ - Remaining items: {remaining_count}
389
+
390
+ ## Instructions
391
+ 1. Read fix_plan.md for current TODO list
392
+ 2. Complete ONLY the first unchecked item
393
+ 3. Run tests after completion
394
+ 4. If tests pass, mark item complete
395
+ 5. If all items complete, output: <promise>COMPLETE</promise>
396
+
397
+ ## Constraints
398
+ - ONE item per iteration (critical)
399
+ - Do not skip verification
400
+ - Commit on each successful item
401
+ - Use subagents for research (max 500)
402
+ - Use only 1 agent for build/test
403
+
404
+ ## Completion Signal
405
+ When ALL items are done and tests pass:
406
+ <promise>COMPLETE</promise>
407
+ ```
408
+
409
+ ### Stop Hook Integration
410
+
411
+ ```bash
412
+ #!/bin/bash
413
+ # global/hooks/ralph_stop.sh
414
+ # Ralph Wiggum stop hook with completion promise
415
+
416
+ TRANSCRIPT="$CLAUDE_TRANSCRIPT"
417
+ MAX_ITERATIONS="${RALPH_MAX_ITERATIONS:-50}"
418
+ ITERATION_FILE="/tmp/ralph_iteration_count"
419
+
420
+ # Read or initialize iteration count
421
+ if [[ -f "$ITERATION_FILE" ]]; then
422
+ ITERATION=$(cat "$ITERATION_FILE")
423
+ else
424
+ ITERATION=0
425
+ fi
426
+
427
+ # Increment iteration
428
+ ITERATION=$((ITERATION + 1))
429
+ echo "$ITERATION" > "$ITERATION_FILE"
430
+
431
+ # Safety: Max iterations check
432
+ if [[ $ITERATION -ge $MAX_ITERATIONS ]]; then
433
+ echo "⚠️ Ralph Wiggum: Maximum iterations ($MAX_ITERATIONS) reached"
434
+ echo "Manual review required"
435
+ rm -f "$ITERATION_FILE"
436
+ exit 0 # Allow exit after max
437
+ fi
438
+
439
+ # Check for completion promise
440
+ if grep -q "<promise>COMPLETE</promise>" "$TRANSCRIPT" 2>/dev/null; then
441
+ echo "✅ Ralph Wiggum: Task complete after $ITERATION iterations"
442
+ rm -f "$ITERATION_FILE"
443
+ exit 0 # Allow exit
444
+ fi
445
+
446
+ # Check for fatal error signals
447
+ if grep -q "<fatal>" "$TRANSCRIPT" 2>/dev/null; then
448
+ echo "❌ Ralph Wiggum: Fatal error detected"
449
+ rm -f "$ITERATION_FILE"
450
+ exit 0 # Allow exit on fatal
451
+ fi
452
+
453
+ echo "🔄 Ralph Wiggum: Iteration $ITERATION - task incomplete, restarting..."
454
+ exit 1 # Block exit, trigger restart
455
+ ```
456
+
457
+ ### `/ralph` Skill Implementation
458
+
459
+ ```markdown
460
+ # /ralph - Ralph Wiggum Long-Running Mode
461
+
462
+ > Enable long-running unattended execution with completion promises.
463
+
464
+ ## Arguments
465
+ - `start [task-description]` - Initialize Ralph mode with task
466
+ - `status` - Show current iteration and progress
467
+ - `stop` - Force exit Ralph mode
468
+
469
+ ## Execution: /ralph start
470
+
471
+ ### Step 1: Create Task Structure
472
+ Create PROMPT.md with:
473
+ - Clear single objective
474
+ - Current state tracking
475
+ - Constraints and completion signal
476
+
477
+ ### Step 2: Enable Stop Hook
478
+ Activate ralph_stop.sh hook that:
479
+ - Checks for <promise>COMPLETE</promise>
480
+ - Blocks exit if incomplete
481
+ - Tracks iteration count
482
+ - Has max iterations safety
483
+
484
+ ### Step 3: Create fix_plan.md
485
+ Break task into atomic TODO items:
486
+ - [ ] Item 1
487
+ - [ ] Item 2
488
+ - ...
489
+
490
+ ### Step 4: Start Loop
491
+ Execute bash loop that:
492
+ - Feeds PROMPT.md to Claude
493
+ - Processes one item per iteration
494
+ - Commits on success
495
+ - Restarts until complete
496
+
497
+ ## Critical Rules
498
+ 1. **ONE item per loop** - Never try to do multiple items
499
+ 2. **Subagents for research** - Don't pollute main context
500
+ 3. **Commit on success** - Each item gets committed
501
+ 4. **Tests gate progress** - No marking complete without tests
502
+ 5. **500 research / 1 build** - Subagent ratio
503
+
504
+ ## Example
505
+ ```
506
+ /ralph start "Implement user authentication with OAuth"
507
+
508
+ Creates:
509
+ - PROMPT.md with structured task
510
+ - fix_plan.md with TODO items
511
+ - Enables ralph_stop.sh hook
512
+ - Starts execution loop
513
+
514
+ Claude will iterate until:
515
+ - All TODOs complete
516
+ - Tests pass
517
+ - <promise>COMPLETE</promise> output
518
+ ```
519
+ ```
520
+
521
+ ---
522
+
523
+ ## Component 5: Atomic Action Commands
524
+
525
+ ### Overview
526
+
527
+ Single commands that execute complete workflows for rapid inner-loop execution.
528
+
529
+ ### Commands
530
+
531
+ #### `/test-and-commit`
532
+
533
+ ```markdown
534
+ # /test-and-commit - Test Then Commit
535
+
536
+ > Run tests, and if passing, commit changes.
537
+
538
+ ## Execution
539
+ 1. Run test suite
540
+ 2. If pass → Create commit with conventional message
541
+ 3. If fail → Report failures, do not commit
542
+
543
+ ## Usage
544
+ /test-and-commit "feat: add user authentication"
545
+ ```
546
+
547
+ #### `/commit-push-pr`
548
+
549
+ ```markdown
550
+ # /commit-push-pr - Full Commit Workflow
551
+
552
+ > Commit, push, and create PR in one command.
553
+
554
+ ## Execution
555
+ 1. Stage all changes
556
+ 2. Create commit with message
557
+ 3. Push to remote
558
+ 4. Create PR with description
559
+
560
+ ## Usage
561
+ /commit-push-pr "feat: add OAuth support"
562
+ ```
563
+
564
+ #### `/lint-fix`
565
+
566
+ ```markdown
567
+ # /lint-fix - Auto-Fix Lint Issues
568
+
569
+ > Run linter with auto-fix enabled.
570
+
571
+ ## Execution
572
+ 1. Run linter with --fix flag
573
+ 2. Report remaining issues
574
+ 3. Stage auto-fixed changes
575
+
576
+ ## Usage
577
+ /lint-fix
578
+ ```
579
+
580
+ ### Requirements
581
+
582
+ | ID | Requirement | Priority |
583
+ |----|-------------|----------|
584
+ | REQ-AA-100 | `/test-and-commit` runs tests before committing | P0 |
585
+ | REQ-AA-101 | `/commit-push-pr` handles full workflow | P0 |
586
+ | REQ-AA-102 | `/lint-fix` auto-fixes lintable issues | P1 |
587
+ | REQ-AA-103 | All commands have clear success/failure output | P0 |
588
+ | REQ-AA-104 | Commands respect git conventions | P0 |
589
+
590
+ ---
591
+
592
+ ## Component 6: Verification Subagent
593
+
594
+ ### Overview
595
+
596
+ A dedicated subagent for verification that keeps research out of the main context.
597
+
598
+ ### Requirements
599
+
600
+ | ID | Requirement | Priority |
601
+ |----|-------------|----------|
602
+ | REQ-VS-100 | Subagent runs all verification checks | P0 |
603
+ | REQ-VS-101 | Returns structured pass/fail report | P0 |
604
+ | REQ-VS-102 | Isolates verification context from main session | P0 |
605
+ | REQ-VS-103 | Supports custom verification commands | P1 |
606
+
607
+ ### Agent Configuration
608
+
609
+ ```json
610
+ {
611
+ "name": "verify-app",
612
+ "description": "Verification subagent for running tests, lint, and type checks",
613
+ "tools": ["Bash", "Read", "Glob"],
614
+ "prompt": "You are a verification agent. Run all project checks and report results in structured format."
615
+ }
616
+ ```
617
+
618
+ ### Invocation Pattern
619
+
620
+ ```bash
621
+ # Use Task tool with verify-app subagent
622
+ Task(
623
+ subagent_type="verify-app",
624
+ prompt="Run full verification suite and report results"
625
+ )
626
+ ```
627
+
628
+ ---
629
+
630
+ ## Component 7: Automated CLAUDE.md Updates
631
+
632
+ ### Overview
633
+
634
+ GitHub Action that extracts patterns from commits and updates CLAUDE.md automatically.
635
+
636
+ ### Requirements
637
+
638
+ | ID | Requirement | Priority |
639
+ |----|-------------|----------|
640
+ | REQ-AC-100 | Weekly GitHub Action runs pattern extraction | P1 |
641
+ | REQ-AC-101 | Extracts common patterns from commit messages | P1 |
642
+ | REQ-AC-102 | Updates CLAUDE.md Project-Learned Patterns section | P1 |
643
+ | REQ-AC-103 | Creates PR for human review (no auto-merge) | P0 |
644
+
645
+ ### GitHub Action
646
+
647
+ ```yaml
648
+ # .github/workflows/update-claude-md.yml
649
+ name: Update CLAUDE.md
650
+
651
+ on:
652
+ schedule:
653
+ - cron: '0 0 * * 0' # Weekly on Sunday
654
+ workflow_dispatch:
655
+
656
+ jobs:
657
+ extract-patterns:
658
+ runs-on: ubuntu-latest
659
+ steps:
660
+ - uses: actions/checkout@v4
661
+ with:
662
+ fetch-depth: 0
663
+
664
+ - name: Extract patterns from recent commits
665
+ run: |
666
+ # Get commits from last week
667
+ COMMITS=$(git log --since="1 week ago" --pretty=format:"%s")
668
+
669
+ # Run pattern extraction script
670
+ python scripts/extract_patterns.py "$COMMITS" > patterns.json
671
+
672
+ - name: Update CLAUDE.md
673
+ run: |
674
+ python scripts/update_claude_md.py patterns.json
675
+
676
+ - name: Create PR
677
+ uses: peter-evans/create-pull-request@v5
678
+ with:
679
+ title: "chore: update CLAUDE.md patterns"
680
+ body: "Automated pattern extraction from weekly commits"
681
+ branch: auto/claude-md-update
682
+ labels: automated
683
+ ```
684
+
685
+ ---
686
+
687
+ ## Implementation Phases
688
+
689
+ ### Phase 1: Verification Foundation (P0)
690
+ - `/verify` command implementation
691
+ - Stop hook verification gate
692
+ - Basic integration tests
693
+
694
+ **Estimated effort**: 4-6 hours
695
+ **Dependencies**: None
696
+
697
+ ### Phase 2: PostToolUse Hooks (P0)
698
+ - Formatting hook implementation
699
+ - Multi-language formatter support
700
+ - Performance optimization
701
+
702
+ **Estimated effort**: 2-3 hours
703
+ **Dependencies**: None (parallel with Phase 1)
704
+
705
+ ### Phase 3: Ralph Wiggum Mode (P1)
706
+ - PROMPT.md templating
707
+ - Stop hook with completion promises
708
+ - Iteration tracking
709
+ - fix_plan.md integration
710
+
711
+ **Estimated effort**: 6-8 hours
712
+ **Dependencies**: Phase 1 (verification)
713
+
714
+ ### Phase 4: Atomic Actions (P1)
715
+ - `/test-and-commit` command
716
+ - `/commit-push-pr` command
717
+ - `/lint-fix` command
718
+
719
+ **Estimated effort**: 3-4 hours
720
+ **Dependencies**: Phase 1 (verification)
721
+
722
+ ### Phase 5: Subagents & Automation (P2)
723
+ - verify-app subagent configuration
724
+ - GitHub Action for CLAUDE.md updates
725
+ - Pattern extraction scripts
726
+
727
+ **Estimated effort**: 4-5 hours
728
+ **Dependencies**: Phase 1, Phase 4
729
+
730
+ ---
731
+
732
+ ## File Structure
733
+
734
+ ```
735
+ global/
736
+ ├── commands/
737
+ │ ├── verify.md # /verify skill
738
+ │ ├── ralph.md # /ralph skill
739
+ │ ├── test-and-commit.md # Atomic action
740
+ │ ├── commit-push-pr.md # Atomic action
741
+ │ └── lint-fix.md # Atomic action
742
+ ├── hooks/
743
+ │ ├── stop_gate.sh # Verification stop hook
744
+ │ ├── ralph_stop.sh # Ralph Wiggum stop hook
745
+ │ └── post_tool_format.sh # PostToolUse formatter
746
+ └── agents/
747
+ └── verify-app.json # Verification subagent
748
+
749
+ .github/
750
+ └── workflows/
751
+ └── update-claude-md.yml
752
+
753
+ scripts/
754
+ ├── extract_patterns.py # Pattern extraction
755
+ └── update_claude_md.py # CLAUDE.md updater
756
+ ```
757
+
758
+ ---
759
+
760
+ ## Success Metrics
761
+
762
+ | Metric | Target | Measurement |
763
+ |--------|--------|-------------|
764
+ | PR CI Pass Rate | >95% | GitHub Actions |
765
+ | Verification Iterations | <2 avg | Command logs |
766
+ | Ralph Mode Completion | >80% tasks | Completion promises |
767
+ | Format Violations | 0 post-save | Git diff checks |
768
+ | CLAUDE.md Freshness | <7 days | Last update date |
769
+
770
+ ---
771
+
772
+ ## Risk Assessment
773
+
774
+ | Risk | Mitigation |
775
+ |------|------------|
776
+ | Stop hook blocks legitimate exits | Provide `/force-exit` override |
777
+ | Ralph mode infinite loops | Max iterations safety (50 default) |
778
+ | Formatter breaks code | Run tests after formatting |
779
+ | Pattern extraction noise | Human review via PR |
780
+ | Performance degradation | Async hooks, time limits |
781
+
782
+ ---
783
+
784
+ ## References
785
+
786
+ - Boris Cherny's Claude Code Setup: https://x.com/bcherny/status/2007179832300581177
787
+ - Ralph Wiggum Plugin: https://github.com/anthropics/claude-code/tree/main/plugins/ralph-wiggum
788
+ - Research Document: `.claude/research/boris-cherny-ralph-wiggum-insights.md`
789
+ - Claude Code Best Practices: https://docs.anthropic.com/en/docs/claude-code/best-practices