@hivehub/rulebook 5.5.1 → 5.7.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.
Files changed (342) hide show
  1. package/.claude/commands/rulebook-learn-capture.md +41 -48
  2. package/.claude/commands/rulebook-learn-list.md +13 -13
  3. package/README.md +332 -394
  4. package/dist/cli/commands/context-intelligence.d.ts +0 -1
  5. package/dist/cli/commands/context-intelligence.d.ts.map +1 -1
  6. package/dist/cli/commands/context-intelligence.js +12 -33
  7. package/dist/cli/commands/context-intelligence.js.map +1 -1
  8. package/dist/cli/commands/index.d.ts +4 -7
  9. package/dist/cli/commands/index.d.ts.map +1 -1
  10. package/dist/cli/commands/index.js +4 -7
  11. package/dist/cli/commands/index.js.map +1 -1
  12. package/dist/cli/commands/init.d.ts.map +1 -1
  13. package/dist/cli/commands/init.js +40 -81
  14. package/dist/cli/commands/init.js.map +1 -1
  15. package/dist/cli/commands/mcp.d.ts +0 -1
  16. package/dist/cli/commands/mcp.d.ts.map +1 -1
  17. package/dist/cli/commands/mcp.js +1 -7
  18. package/dist/cli/commands/mcp.js.map +1 -1
  19. package/dist/cli/commands/memory.d.ts +7 -1
  20. package/dist/cli/commands/memory.d.ts.map +1 -1
  21. package/dist/cli/commands/memory.js +51 -57
  22. package/dist/cli/commands/memory.js.map +1 -1
  23. package/dist/cli/commands/misc.d.ts +1 -15
  24. package/dist/cli/commands/misc.d.ts.map +1 -1
  25. package/dist/cli/commands/misc.js +36 -215
  26. package/dist/cli/commands/misc.js.map +1 -1
  27. package/dist/cli/commands/plans.d.ts +0 -6
  28. package/dist/cli/commands/plans.d.ts.map +1 -1
  29. package/dist/cli/commands/plans.js +9 -77
  30. package/dist/cli/commands/plans.js.map +1 -1
  31. package/dist/cli/commands/skills.js +6 -6
  32. package/dist/cli/commands/skills.js.map +1 -1
  33. package/dist/cli/commands/task.js +4 -4
  34. package/dist/cli/commands/task.js.map +1 -1
  35. package/dist/cli/commands/update.d.ts.map +1 -1
  36. package/dist/cli/commands/update.js +122 -52
  37. package/dist/cli/commands/update.js.map +1 -1
  38. package/dist/cli/prompts.d.ts.map +1 -1
  39. package/dist/cli/prompts.js +1 -78
  40. package/dist/cli/prompts.js.map +1 -1
  41. package/dist/core/claude/claude-mcp.d.ts +59 -0
  42. package/dist/core/claude/claude-mcp.d.ts.map +1 -0
  43. package/dist/core/claude/claude-mcp.js +220 -0
  44. package/dist/core/claude/claude-mcp.js.map +1 -0
  45. package/dist/core/claude/claude-md-generator.d.ts +52 -0
  46. package/dist/core/claude/claude-md-generator.d.ts.map +1 -0
  47. package/dist/core/claude/claude-md-generator.js +104 -0
  48. package/dist/core/claude/claude-md-generator.js.map +1 -0
  49. package/dist/core/claude/claude-settings-manager.d.ts +44 -0
  50. package/dist/core/claude/claude-settings-manager.d.ts.map +1 -0
  51. package/dist/core/claude/claude-settings-manager.js +194 -0
  52. package/dist/core/claude/claude-settings-manager.js.map +1 -0
  53. package/dist/core/claude-settings-manager.d.ts.map +1 -1
  54. package/dist/core/claude-settings-manager.js +9 -3
  55. package/dist/core/claude-settings-manager.js.map +1 -1
  56. package/dist/core/console/cli-bridge.d.ts +113 -0
  57. package/dist/core/console/cli-bridge.d.ts.map +1 -0
  58. package/dist/core/console/cli-bridge.js +1094 -0
  59. package/dist/core/console/cli-bridge.js.map +1 -0
  60. package/dist/core/detect/detector.d.ts +35 -0
  61. package/dist/core/detect/detector.d.ts.map +1 -0
  62. package/dist/core/detect/detector.js +541 -0
  63. package/dist/core/detect/detector.js.map +1 -0
  64. package/dist/core/docs/docs-generator.d.ts +9 -0
  65. package/dist/core/docs/docs-generator.d.ts.map +1 -0
  66. package/dist/core/docs/docs-generator.js +531 -0
  67. package/dist/core/docs/docs-generator.js.map +1 -0
  68. package/dist/core/docs/mcp-reference-generator.d.ts +13 -0
  69. package/dist/core/docs/mcp-reference-generator.d.ts.map +1 -0
  70. package/dist/core/docs/mcp-reference-generator.js +66 -0
  71. package/dist/core/docs/mcp-reference-generator.js.map +1 -0
  72. package/dist/core/generators/generator.d.ts +54 -0
  73. package/dist/core/generators/generator.d.ts.map +1 -0
  74. package/dist/core/generators/generator.js +1041 -0
  75. package/dist/core/generators/generator.js.map +1 -0
  76. package/dist/core/generators/gitignore-generator.d.ts +13 -0
  77. package/dist/core/generators/gitignore-generator.d.ts.map +1 -0
  78. package/dist/core/generators/gitignore-generator.js +307 -0
  79. package/dist/core/generators/gitignore-generator.js.map +1 -0
  80. package/dist/core/generators/minimal-scaffolder.d.ts +8 -0
  81. package/dist/core/generators/minimal-scaffolder.d.ts.map +1 -0
  82. package/dist/core/generators/minimal-scaffolder.js +51 -0
  83. package/dist/core/generators/minimal-scaffolder.js.map +1 -0
  84. package/dist/core/generators/rules-generator.d.ts +73 -0
  85. package/dist/core/generators/rules-generator.d.ts.map +1 -0
  86. package/dist/core/generators/rules-generator.js +202 -0
  87. package/dist/core/generators/rules-generator.js.map +1 -0
  88. package/dist/core/generators/workflow-generator.d.ts +15 -0
  89. package/dist/core/generators/workflow-generator.d.ts.map +1 -0
  90. package/dist/core/generators/workflow-generator.js +390 -0
  91. package/dist/core/generators/workflow-generator.js.map +1 -0
  92. package/dist/core/ide/multi-tool-generator.d.ts +59 -0
  93. package/dist/core/ide/multi-tool-generator.d.ts.map +1 -0
  94. package/dist/core/ide/multi-tool-generator.js +157 -0
  95. package/dist/core/ide/multi-tool-generator.js.map +1 -0
  96. package/dist/core/ide/opencode-generator.d.ts +72 -0
  97. package/dist/core/ide/opencode-generator.d.ts.map +1 -0
  98. package/dist/core/ide/opencode-generator.js +450 -0
  99. package/dist/core/ide/opencode-generator.js.map +1 -0
  100. package/dist/core/merger.d.ts +1 -1
  101. package/dist/core/merger.d.ts.map +1 -1
  102. package/dist/core/merger.js +5 -5
  103. package/dist/core/merger.js.map +1 -1
  104. package/dist/core/migrator.d.ts +0 -1
  105. package/dist/core/migrator.d.ts.map +1 -1
  106. package/dist/core/migrator.js +4 -29
  107. package/dist/core/migrator.js.map +1 -1
  108. package/dist/core/quality/coverage-checker.d.ts +14 -0
  109. package/dist/core/quality/coverage-checker.d.ts.map +1 -0
  110. package/dist/core/quality/coverage-checker.js +176 -0
  111. package/dist/core/quality/coverage-checker.js.map +1 -0
  112. package/dist/core/quality/dependency-checker.d.ts +21 -0
  113. package/dist/core/quality/dependency-checker.d.ts.map +1 -0
  114. package/dist/core/quality/dependency-checker.js +247 -0
  115. package/dist/core/quality/dependency-checker.js.map +1 -0
  116. package/dist/core/quality/doctor.d.ts +19 -0
  117. package/dist/core/quality/doctor.d.ts.map +1 -0
  118. package/dist/core/quality/doctor.js +163 -0
  119. package/dist/core/quality/doctor.js.map +1 -0
  120. package/dist/core/quality/validator.d.ts +21 -0
  121. package/dist/core/quality/validator.d.ts.map +1 -0
  122. package/dist/core/quality/validator.js +177 -0
  123. package/dist/core/quality/validator.js.map +1 -0
  124. package/dist/core/ralph-scripts.d.ts.map +1 -1
  125. package/dist/core/ralph-scripts.js +7 -6
  126. package/dist/core/ralph-scripts.js.map +1 -1
  127. package/dist/core/skills/skills-manager.d.ts +126 -0
  128. package/dist/core/skills/skills-manager.d.ts.map +1 -0
  129. package/dist/core/skills/skills-manager.js +630 -0
  130. package/dist/core/skills/skills-manager.js.map +1 -0
  131. package/dist/core/state/config-manager.d.ts +86 -0
  132. package/dist/core/state/config-manager.d.ts.map +1 -0
  133. package/dist/core/state/config-manager.js +562 -0
  134. package/dist/core/state/config-manager.js.map +1 -0
  135. package/dist/core/state/override-manager.d.ts +23 -0
  136. package/dist/core/state/override-manager.d.ts.map +1 -0
  137. package/dist/core/state/override-manager.js +82 -0
  138. package/dist/core/state/override-manager.js.map +1 -0
  139. package/dist/core/state/state-writer.d.ts +34 -0
  140. package/dist/core/state/state-writer.d.ts.map +1 -0
  141. package/dist/core/state/state-writer.js +78 -0
  142. package/dist/core/state/state-writer.js.map +1 -0
  143. package/dist/core/state/version-bumper.d.ts +19 -0
  144. package/dist/core/state/version-bumper.d.ts.map +1 -0
  145. package/dist/core/state/version-bumper.js +180 -0
  146. package/dist/core/state/version-bumper.js.map +1 -0
  147. package/dist/core/tasks/decision-manager.d.ts +25 -0
  148. package/dist/core/tasks/decision-manager.d.ts.map +1 -0
  149. package/dist/core/tasks/decision-manager.js +183 -0
  150. package/dist/core/tasks/decision-manager.js.map +1 -0
  151. package/dist/core/tasks/knowledge-manager.d.ts +24 -0
  152. package/dist/core/tasks/knowledge-manager.d.ts.map +1 -0
  153. package/dist/core/tasks/knowledge-manager.js +173 -0
  154. package/dist/core/tasks/knowledge-manager.js.map +1 -0
  155. package/dist/core/tasks/learn-manager.d.ts +27 -0
  156. package/dist/core/tasks/learn-manager.d.ts.map +1 -0
  157. package/dist/core/tasks/learn-manager.js +121 -0
  158. package/dist/core/tasks/learn-manager.js.map +1 -0
  159. package/dist/core/tasks/plans-manager.d.ts +46 -0
  160. package/dist/core/tasks/plans-manager.d.ts.map +1 -0
  161. package/dist/core/tasks/plans-manager.js +158 -0
  162. package/dist/core/tasks/plans-manager.js.map +1 -0
  163. package/dist/core/tasks/task-manager.d.ts +127 -0
  164. package/dist/core/tasks/task-manager.d.ts.map +1 -0
  165. package/dist/core/tasks/task-manager.js +607 -0
  166. package/dist/core/tasks/task-manager.js.map +1 -0
  167. package/dist/core/workspace/project-worker.d.ts +6 -6
  168. package/dist/core/workspace/project-worker.d.ts.map +1 -1
  169. package/dist/core/workspace/project-worker.js +6 -6
  170. package/dist/core/workspace/project-worker.js.map +1 -1
  171. package/dist/index.d.ts +1 -1
  172. package/dist/index.d.ts.map +1 -1
  173. package/dist/index.js +19 -176
  174. package/dist/index.js.map +1 -1
  175. package/dist/mcp/rulebook-server.d.ts.map +1 -1
  176. package/dist/mcp/rulebook-server.js +16 -960
  177. package/dist/mcp/rulebook-server.js.map +1 -1
  178. package/dist/memory/file-search.d.ts +43 -0
  179. package/dist/memory/file-search.d.ts.map +1 -0
  180. package/dist/memory/file-search.js +228 -0
  181. package/dist/memory/file-search.js.map +1 -0
  182. package/dist/memory/file-store.d.ts +99 -0
  183. package/dist/memory/file-store.d.ts.map +1 -0
  184. package/dist/memory/file-store.js +615 -0
  185. package/dist/memory/file-store.js.map +1 -0
  186. package/dist/memory/legacy-migrator.d.ts +27 -0
  187. package/dist/memory/legacy-migrator.d.ts.map +1 -0
  188. package/dist/memory/legacy-migrator.js +185 -0
  189. package/dist/memory/legacy-migrator.js.map +1 -0
  190. package/dist/memory/memory-manager.d.ts +25 -24
  191. package/dist/memory/memory-manager.d.ts.map +1 -1
  192. package/dist/memory/memory-manager.js +97 -140
  193. package/dist/memory/memory-manager.js.map +1 -1
  194. package/dist/memory/memory-types.d.ts +1 -1
  195. package/dist/memory/memory-types.d.ts.map +1 -1
  196. package/dist/types.d.ts +8 -119
  197. package/dist/types.d.ts.map +1 -1
  198. package/dist/utils/file-system.d.ts +22 -0
  199. package/dist/utils/file-system.d.ts.map +1 -1
  200. package/dist/utils/file-system.js +31 -0
  201. package/dist/utils/file-system.js.map +1 -1
  202. package/dist/utils/git-hooks.d.ts.map +1 -1
  203. package/dist/utils/git-hooks.js +3 -2
  204. package/dist/utils/git-hooks.js.map +1 -1
  205. package/package.json +2 -6
  206. package/templates/agents/context-intelligence.md +50 -52
  207. package/templates/cli/OPENCODE.md +85 -18
  208. package/templates/commands/rulebook-learn-capture.md +41 -48
  209. package/templates/commands/rulebook-learn-list.md +13 -13
  210. package/templates/core/AGENTS_LEAN.md +0 -14
  211. package/templates/hooks/check-context-and-handoff.sh +74 -76
  212. package/templates/hooks/enforce-pre-tool.sh +70 -0
  213. package/templates/hooks/enforce-team-for-background-agents.sh +55 -55
  214. package/templates/hooks/on-compact-reinject.sh +34 -34
  215. package/templates/hooks/resume-from-handoff.sh +61 -61
  216. package/templates/hooks/terse-activate.sh +197 -197
  217. package/templates/hooks/terse-mode-tracker.sh +190 -187
  218. package/templates/ides/OPENCODE.md +63 -0
  219. package/templates/skills/cli/opencode/SKILL.md +82 -28
  220. package/.claude/commands/ralph-config.md +0 -112
  221. package/.claude/commands/ralph-history.md +0 -110
  222. package/.claude/commands/ralph-init.md +0 -72
  223. package/.claude/commands/ralph-pause-resume.md +0 -105
  224. package/.claude/commands/ralph-run.md +0 -101
  225. package/.claude/commands/ralph-status.md +0 -76
  226. package/templates/core/RALPH.md +0 -471
  227. package/templates/frameworks/ANGULAR.md +0 -36
  228. package/templates/frameworks/DJANGO.md +0 -83
  229. package/templates/frameworks/ELECTRON.md +0 -147
  230. package/templates/frameworks/FLASK.md +0 -38
  231. package/templates/frameworks/FLUTTER.md +0 -55
  232. package/templates/frameworks/JQUERY.md +0 -32
  233. package/templates/frameworks/LARAVEL.md +0 -38
  234. package/templates/frameworks/NESTJS.md +0 -43
  235. package/templates/frameworks/NEXTJS.md +0 -127
  236. package/templates/frameworks/NUXT.md +0 -40
  237. package/templates/frameworks/RAILS.md +0 -66
  238. package/templates/frameworks/REACT.md +0 -38
  239. package/templates/frameworks/REACT_NATIVE.md +0 -47
  240. package/templates/frameworks/SPRING.md +0 -39
  241. package/templates/frameworks/SYMFONY.md +0 -36
  242. package/templates/frameworks/VUE.md +0 -36
  243. package/templates/frameworks/ZEND.md +0 -35
  244. package/templates/hooks/enforce-mcp-for-tasks.sh +0 -31
  245. package/templates/hooks/enforce-no-deferred.sh +0 -21
  246. package/templates/hooks/enforce-no-shortcuts.sh +0 -31
  247. package/templates/ides/COPILOT.md +0 -37
  248. package/templates/ides/CURSOR.md +0 -43
  249. package/templates/ides/JETBRAINS_AI.md +0 -35
  250. package/templates/ides/REPLIT.md +0 -36
  251. package/templates/ides/TABNINE.md +0 -29
  252. package/templates/ides/VSCODE.md +0 -40
  253. package/templates/ides/WINDSURF.md +0 -36
  254. package/templates/ides/ZED.md +0 -32
  255. package/templates/ides/cursor-mdc/go.mdc +0 -24
  256. package/templates/ides/cursor-mdc/python.mdc +0 -24
  257. package/templates/ides/cursor-mdc/quality.mdc +0 -25
  258. package/templates/ides/cursor-mdc/ralph.mdc +0 -39
  259. package/templates/ides/cursor-mdc/rulebook.mdc +0 -38
  260. package/templates/ides/cursor-mdc/rust.mdc +0 -24
  261. package/templates/ides/cursor-mdc/typescript.mdc +0 -25
  262. package/templates/ralph/ralph-history.bat +0 -4
  263. package/templates/ralph/ralph-history.sh +0 -5
  264. package/templates/ralph/ralph-init.bat +0 -5
  265. package/templates/ralph/ralph-init.sh +0 -5
  266. package/templates/ralph/ralph-pause.bat +0 -5
  267. package/templates/ralph/ralph-pause.sh +0 -5
  268. package/templates/ralph/ralph-run.bat +0 -5
  269. package/templates/ralph/ralph-run.sh +0 -5
  270. package/templates/ralph/ralph-status.bat +0 -4
  271. package/templates/ralph/ralph-status.sh +0 -5
  272. package/templates/services/AZURE_BLOB.md +0 -184
  273. package/templates/services/CASSANDRA.md +0 -239
  274. package/templates/services/DATADOG.md +0 -26
  275. package/templates/services/DOCKER.md +0 -124
  276. package/templates/services/DOCKER_COMPOSE.md +0 -168
  277. package/templates/services/DYNAMODB.md +0 -308
  278. package/templates/services/ELASTICSEARCH.md +0 -347
  279. package/templates/services/GCS.md +0 -178
  280. package/templates/services/HELM.md +0 -194
  281. package/templates/services/INFLUXDB.md +0 -265
  282. package/templates/services/KAFKA.md +0 -341
  283. package/templates/services/KUBERNETES.md +0 -208
  284. package/templates/services/MARIADB.md +0 -183
  285. package/templates/services/MEMCACHED.md +0 -242
  286. package/templates/services/MINIO.md +0 -201
  287. package/templates/services/MONGODB.md +0 -268
  288. package/templates/services/MYSQL.md +0 -358
  289. package/templates/services/NEO4J.md +0 -247
  290. package/templates/services/OPENTELEMETRY.md +0 -25
  291. package/templates/services/ORACLE.md +0 -290
  292. package/templates/services/PINO.md +0 -24
  293. package/templates/services/POSTGRESQL.md +0 -326
  294. package/templates/services/PROMETHEUS.md +0 -33
  295. package/templates/services/RABBITMQ.md +0 -286
  296. package/templates/services/REDIS.md +0 -292
  297. package/templates/services/S3.md +0 -298
  298. package/templates/services/SENTRY.md +0 -23
  299. package/templates/services/SQLITE.md +0 -294
  300. package/templates/services/SQLSERVER.md +0 -294
  301. package/templates/services/WINSTON.md +0 -30
  302. package/templates/skills/frameworks/angular/SKILL.md +0 -46
  303. package/templates/skills/frameworks/django/SKILL.md +0 -93
  304. package/templates/skills/frameworks/electron/SKILL.md +0 -157
  305. package/templates/skills/frameworks/flask/SKILL.md +0 -48
  306. package/templates/skills/frameworks/flutter/SKILL.md +0 -65
  307. package/templates/skills/frameworks/jquery/SKILL.md +0 -42
  308. package/templates/skills/frameworks/laravel/SKILL.md +0 -48
  309. package/templates/skills/frameworks/nestjs/SKILL.md +0 -53
  310. package/templates/skills/frameworks/nextjs/SKILL.md +0 -137
  311. package/templates/skills/frameworks/nuxt/SKILL.md +0 -50
  312. package/templates/skills/frameworks/rails/SKILL.md +0 -76
  313. package/templates/skills/frameworks/react/SKILL.md +0 -48
  314. package/templates/skills/frameworks/react-native/SKILL.md +0 -57
  315. package/templates/skills/frameworks/spring/SKILL.md +0 -49
  316. package/templates/skills/frameworks/symfony/SKILL.md +0 -46
  317. package/templates/skills/frameworks/vue/SKILL.md +0 -46
  318. package/templates/skills/frameworks/zend/SKILL.md +0 -45
  319. package/templates/skills/services/azure-blob/SKILL.md +0 -194
  320. package/templates/skills/services/cassandra/SKILL.md +0 -249
  321. package/templates/skills/services/dynamodb/SKILL.md +0 -318
  322. package/templates/skills/services/elasticsearch/SKILL.md +0 -357
  323. package/templates/skills/services/gcs/SKILL.md +0 -188
  324. package/templates/skills/services/influxdb/SKILL.md +0 -275
  325. package/templates/skills/services/kafka/SKILL.md +0 -351
  326. package/templates/skills/services/mariadb/SKILL.md +0 -193
  327. package/templates/skills/services/memcached/SKILL.md +0 -252
  328. package/templates/skills/services/minio/SKILL.md +0 -211
  329. package/templates/skills/services/mongodb/SKILL.md +0 -278
  330. package/templates/skills/services/mysql/SKILL.md +0 -368
  331. package/templates/skills/services/neo4j/SKILL.md +0 -257
  332. package/templates/skills/services/oracle/SKILL.md +0 -300
  333. package/templates/skills/services/postgresql/SKILL.md +0 -336
  334. package/templates/skills/services/rabbitmq/SKILL.md +0 -296
  335. package/templates/skills/services/redis/SKILL.md +0 -302
  336. package/templates/skills/services/s3/SKILL.md +0 -308
  337. package/templates/skills/services/sqlite/SKILL.md +0 -304
  338. package/templates/skills/services/sqlserver/SKILL.md +0 -304
  339. package/templates/skills/workflows/ralph/SETUP.md +0 -228
  340. package/templates/skills/workflows/ralph/SKILL.md +0 -309
  341. package/templates/skills/workflows/ralph/install.sh +0 -87
  342. package/templates/skills/workflows/ralph/manifest.json +0 -158
@@ -1,52 +1,50 @@
1
- ---
2
- name: context-intelligence
3
- model: haiku
4
- description: Manages project decisions, knowledge base, and learnings. Use for capturing ADRs, patterns/anti-patterns, and post-implementation learnings.
5
- tools: Read, Glob, Grep, Bash, Write, Edit
6
- maxTurns: 15
7
- ---
8
-
9
- You are a context-intelligence agent. Your primary responsibility is managing the project's institutional knowledge: decisions, patterns, and learnings.
10
-
11
- ## Responsibilities
12
-
13
- - Create and manage Architecture Decision Records (ADRs) via `rulebook decision`
14
- - Add patterns and anti-patterns to the knowledge base via `rulebook knowledge`
15
- - Capture and promote learnings via `rulebook learn`
16
- - Extract learnings from Ralph iteration history
17
- - Ensure decisions have proper context, alternatives, and consequences
18
-
19
- ## Workflow
20
-
21
- ### When creating a decision:
22
- 1. Check existing decisions: `rulebook decision list`
23
- 2. Create: `rulebook decision create "<title>" --context "<context>"`
24
- 3. Enrich the `.rulebook/decisions/NNN-<slug>.md` file with full details
25
- 4. Verify: `rulebook decision show <id>`
26
-
27
- ### When adding knowledge:
28
- 1. Check existing entries: `rulebook knowledge list`
29
- 2. Create: `rulebook knowledge add <pattern|anti-pattern> "<title>" --category <cat>`
30
- 3. Enrich `.rulebook/knowledge/<type>s/<slug>.md` with examples and guidelines
31
- 4. Verify: `rulebook knowledge show <slug>`
32
-
33
- ### When capturing learnings:
34
- 1. Capture: `rulebook learn capture --title "<title>" --content "<content>" --tags "tag1,tag2"`
35
- 2. For Ralph learnings: `rulebook learn from-ralph`
36
- 3. Promote significant learnings: `rulebook learn promote <id> knowledge|decision`
37
-
38
- ## Standards
39
-
40
- 1. Every decision MUST include context, the decision, alternatives, and consequences
41
- 2. Patterns MUST include concrete code examples (not abstract descriptions)
42
- 3. Anti-patterns MUST explain what to do instead
43
- 4. Learnings should be captured immediately after discovery, not batched
44
- 5. Use descriptive titles — they appear in AGENTS.md for AI context
45
-
46
- ## Rules
47
-
48
- - Do NOT modify production source code — only `.rulebook/` files
49
- - Do NOT delete decisions — supersede or deprecate them
50
- - Knowledge entries auto-appear in AGENTS.md after `rulebook update`
51
- - Tag all entries for searchability
52
- - When promoting a learning, verify the promoted entry is complete
1
+ ---
2
+ name: context-intelligence
3
+ model: haiku
4
+ description: Manages project decisions, knowledge base, and learnings. Use for capturing ADRs, patterns/anti-patterns, and post-implementation learnings.
5
+ tools: Read, Glob, Grep, Bash, Write, Edit
6
+ maxTurns: 15
7
+ ---
8
+
9
+ You are a context-intelligence agent. Your primary responsibility is managing the project's institutional knowledge: decisions, patterns, and learnings.
10
+
11
+ ## Responsibilities
12
+
13
+ - Create and manage Architecture Decision Records (ADRs) via `rulebook decision`
14
+ - Add patterns and anti-patterns to the knowledge base via `rulebook knowledge`
15
+ - Capture and promote learnings via `rulebook learn`
16
+ - Ensure decisions have proper context, alternatives, and consequences
17
+
18
+ ## Workflow
19
+
20
+ ### When creating a decision:
21
+ 1. Check existing decisions: `rulebook decision list`
22
+ 2. Create: `rulebook decision create "<title>" --context "<context>"`
23
+ 3. Enrich the `.rulebook/decisions/NNN-<slug>.md` file with full details
24
+ 4. Verify: `rulebook decision show <id>`
25
+
26
+ ### When adding knowledge:
27
+ 1. Check existing entries: `rulebook knowledge list`
28
+ 2. Create: `rulebook knowledge add <pattern|anti-pattern> "<title>" --category <cat>`
29
+ 3. Enrich `.rulebook/knowledge/<type>s/<slug>.md` with examples and guidelines
30
+ 4. Verify: `rulebook knowledge show <slug>`
31
+
32
+ ### When capturing learnings:
33
+ 1. Capture: `rulebook learn capture --title "<title>" --content "<content>" --tags "tag1,tag2"`
34
+ 2. Promote significant learnings: `rulebook learn promote <id> knowledge|decision`
35
+
36
+ ## Standards
37
+
38
+ 1. Every decision MUST include context, the decision, alternatives, and consequences
39
+ 2. Patterns MUST include concrete code examples (not abstract descriptions)
40
+ 3. Anti-patterns MUST explain what to do instead
41
+ 4. Learnings should be captured immediately after discovery, not batched
42
+ 5. Use descriptive titles they appear in AGENTS.md for AI context
43
+
44
+ ## Rules
45
+
46
+ - Do NOT modify production source code — only `.rulebook/` files
47
+ - Do NOT delete decisions — supersede or deprecate them
48
+ - Knowledge entries auto-appear in AGENTS.md after `rulebook update`
49
+ - Tag all entries for searchability
50
+ - When promoting a learning, verify the promoted entry is complete
@@ -1,18 +1,85 @@
1
- <!-- OPENCODE:START -->
2
- # OpenCode Rules
3
-
4
- **Tool**: Open-source AI assistant
5
-
6
- ## Usage
7
-
8
- ```
9
- "Follow @AGENTS.md. Implement [feature] with tests."
10
- ```
11
-
12
- ## Workflow
13
-
14
- 1. Reference AGENTS.md
15
- 2. Review code
16
- 3. Run quality checks
17
-
18
- <!-- OPENCODE:END -->
1
+ <!-- OPENCODE:START -->
2
+ # OpenCode Rules
3
+
4
+ **Tool**: [OpenCode](https://opencode.ai) — open-source terminal coding agent (SST).
5
+
6
+ OpenCode reads `AGENTS.md` natively (with `CLAUDE.md` as fallback). When
7
+ Rulebook is initialized in this project, OpenCode also gets:
8
+
9
+ - `opencode.json` declares the rulebook MCP server and lazy-loads the
10
+ project rule files via the `instructions` array.
11
+ - `.opencode/commands/` — mirrors Rulebook's user-invocable slash commands
12
+ (`/handoff`, `/rulebook-task-*`, `/rulebook-decision-*`,
13
+ `/rulebook-knowledge-*`, `/rulebook-memory-*`, `/rulebook-learn-*`).
14
+ - `.opencode/agents/` — mirrors role agents (`researcher`, `implementer`,
15
+ `tester`, `code-reviewer`, `architect`, etc.) translated to OpenCode's
16
+ frontmatter schema (`mode`, `model`, `permission`).
17
+ - `.opencode/skills/` — mirrors the dev skill library normalized to
18
+ OpenCode's strict skill-name regex.
19
+
20
+ ## Quick Start
21
+
22
+ ```bash
23
+ # Install OpenCode
24
+ curl -fsSL https://opencode.ai/install | bash
25
+
26
+ # In a Rulebook-managed project, OpenCode picks up everything automatically:
27
+ opencode
28
+ ```
29
+
30
+ ## Workflow
31
+
32
+ 1. **Reference rules** — `AGENTS.md`, `AGENTS.override.md`, and
33
+ `.rulebook/specs/*.md` are wired into `instructions` so the model
34
+ has them on demand without burning context.
35
+ 2. **Use slash commands** — type `/rulebook-task-create`,
36
+ `/rulebook-task-list`, `/handoff`, etc. They're real OpenCode
37
+ commands, not just prompt text.
38
+ 3. **Delegate to role agents** — `@researcher analyze X`,
39
+ `@implementer add Y`, `@tester cover Z`. Each role has its own
40
+ `model`, `permission`, and `description` matching the Rulebook
41
+ delegation table.
42
+ 4. **Quality checks** — type-check / lint / test before committing,
43
+ per `AGENTS.md` quality-gate rules.
44
+ 5. **Save learnings** — `rulebook memory save`, `rulebook knowledge add`,
45
+ `rulebook learn capture`, or invoke the corresponding slash commands.
46
+
47
+ ## Sequential editing
48
+
49
+ OpenCode is held to the same Rulebook discipline as Claude Code:
50
+
51
+ - Edit files **one at a time** (Read → Edit → Read → Edit), not in batch.
52
+ - For 3+ files across subsystems, decompose into 1–2 file sub-tasks.
53
+ - Run diagnostics (type-check / lint) **before** the test suite.
54
+
55
+ ## MCP & token usage
56
+
57
+ The `mcp.rulebook` entry in `opencode.json` exposes the full Rulebook
58
+ MCP toolset (`rulebook_task_*`, `rulebook_memory_*`, `rulebook_decision_*`,
59
+ `rulebook_knowledge_*`, etc.). Prefer MCP tools over shell commands when
60
+ both exist — they're faster, structured, and don't pollute context.
61
+
62
+ Output discipline: prefer concise output. Don't generate "Quality Checks"
63
+ status tables, "Next Steps" sections, or restate the question. Put
64
+ implementation details in code comments, not markdown.
65
+
66
+ ## Isolation from Claude Code
67
+
68
+ OpenCode falls back to `CLAUDE.md` if `AGENTS.md` is absent. To force
69
+ OpenCode to ignore a `CLAUDE.md` shared with Claude Code, set:
70
+
71
+ ```bash
72
+ export OPENCODE_DISABLE_CLAUDE_CODE=*
73
+ ```
74
+
75
+ ## Documentation
76
+
77
+ - [opencode.ai/docs/rules](https://opencode.ai/docs/rules/)
78
+ - [opencode.ai/docs/config](https://opencode.ai/docs/config/)
79
+ - [opencode.ai/docs/mcp-servers](https://opencode.ai/docs/mcp-servers/)
80
+ - [opencode.ai/docs/commands](https://opencode.ai/docs/commands/)
81
+ - [opencode.ai/docs/agents](https://opencode.ai/docs/agents/)
82
+ - [opencode.ai/docs/skills](https://opencode.ai/docs/skills/)
83
+ - [opencode.ai/docs/permissions](https://opencode.ai/docs/permissions/)
84
+
85
+ <!-- OPENCODE:END -->
@@ -1,48 +1,41 @@
1
- ---
2
- name: /rulebook-learn-capture
3
- id: rulebook-learn-capture
4
- category: Rulebook
5
- description: Capture a learning from implementation work for future reference.
6
- ---
7
- <!-- RULEBOOK:START -->
8
- **Guardrails**
9
- - Learnings are saved to both the memory system and `.rulebook/learnings/` for offline backup.
10
- - Learnings can be promoted to patterns/decisions later via `rulebook learn promote`.
11
-
12
- **Steps**
13
- 1. **Gather the Learning**:
14
- - **Title**: Short description of what was learned
15
- - **Content**: Full explanation — what happened, what was discovered, why it matters
16
- - **Tags**: Keywords for searchability
17
- - **Related Task**: Task ID if this learning came from a specific task
18
- - **Source**: `manual` (default), `ralph`, or `task-archive`
19
-
20
- 2. **Capture**:
21
- ```bash
22
- rulebook learn capture --title "<title>" --content "<content>" --tags "tag1,tag2" --related-task <task-id>
23
- ```
24
-
25
- 3. **Verify**:
26
- ```bash
27
- rulebook learn list --limit 5
28
- ```
29
-
30
- **Promotion Flow**
31
- If a learning is significant enough to become a team pattern or decision:
32
- ```bash
33
- rulebook learn promote <id> knowledge # → creates a pattern
34
- rulebook learn promote <id> decision # → creates an ADR
35
- ```
36
-
37
- **Ralph Integration**
38
- Extract learnings from Ralph autonomous loop history:
39
- ```bash
40
- rulebook learn from-ralph
41
- ```
42
- This reads `.rulebook/ralph/history/iteration-*.json` and captures entries with non-empty learnings.
43
-
44
- **Reference**
45
- - Learnings are searchable via `rulebook memory search`
46
- - Use `rulebook learn list` to see all learnings
47
- - Learnings captured during `rulebook task archive` have source `task-archive`
48
- <!-- RULEBOOK:END -->
1
+ ---
2
+ name: /rulebook-learn-capture
3
+ id: rulebook-learn-capture
4
+ category: Rulebook
5
+ description: Capture a learning from implementation work for future reference.
6
+ ---
7
+ <!-- RULEBOOK:START -->
8
+ **Guardrails**
9
+ - Learnings are saved to both the memory system and `.rulebook/learnings/` for offline backup.
10
+ - Learnings can be promoted to patterns/decisions later via `rulebook learn promote`.
11
+
12
+ **Steps**
13
+ 1. **Gather the Learning**:
14
+ - **Title**: Short description of what was learned
15
+ - **Content**: Full explanation — what happened, what was discovered, why it matters
16
+ - **Tags**: Keywords for searchability
17
+ - **Related Task**: Task ID if this learning came from a specific task
18
+ - **Source**: `manual` (default) or `task-archive`
19
+
20
+ 2. **Capture**:
21
+ ```bash
22
+ rulebook learn capture --title "<title>" --content "<content>" --tags "tag1,tag2" --related-task <task-id>
23
+ ```
24
+
25
+ 3. **Verify**:
26
+ ```bash
27
+ rulebook learn list --limit 5
28
+ ```
29
+
30
+ **Promotion Flow**
31
+ If a learning is significant enough to become a team pattern or decision:
32
+ ```bash
33
+ rulebook learn promote <id> knowledge # → creates a pattern
34
+ rulebook learn promote <id> decision # → creates an ADR
35
+ ```
36
+
37
+ **Reference**
38
+ - Learnings are searchable via `rulebook memory search`
39
+ - Use `rulebook learn list` to see all learnings
40
+ - Learnings captured during `rulebook task archive` have source `task-archive`
41
+ <!-- RULEBOOK:END -->
@@ -1,13 +1,13 @@
1
- ---
2
- name: /rulebook-learn-list
3
- id: rulebook-learn-list
4
- category: Rulebook
5
- description: List captured learnings with source and promotion status.
6
- ---
7
- <!-- RULEBOOK:START -->
8
- **Steps**
9
- 1. Run `rulebook learn list` to see all learnings (newest first).
10
- 2. Optionally limit: `rulebook learn list --limit 10`
11
- 3. Present results with source badge (manual/ralph/archive) and promotion status.
12
- 4. Suggest promotion for significant learnings: `rulebook learn promote <id> knowledge|decision`
13
- <!-- RULEBOOK:END -->
1
+ ---
2
+ name: /rulebook-learn-list
3
+ id: rulebook-learn-list
4
+ category: Rulebook
5
+ description: List captured learnings with source and promotion status.
6
+ ---
7
+ <!-- RULEBOOK:START -->
8
+ **Steps**
9
+ 1. Run `rulebook learn list` to see all learnings (newest first).
10
+ 2. Optionally limit: `rulebook learn list --limit 10`
11
+ 3. Present results with source badge (manual/archive) and promotion status.
12
+ 4. Suggest promotion for significant learnings: `rulebook learn promote <id> knowledge|decision`
13
+ <!-- RULEBOOK:END -->
@@ -157,20 +157,6 @@ LANGUAGE_REFS
157
157
 
158
158
  MODULE_REFS
159
159
 
160
- ## Ralph Autonomous Loop
161
-
162
- 5-gate quality enforcement (type-check, lint, tests, coverage, security) per iteration, fresh context per iteration, parallel story execution, plan checkpoints, learning extraction.
163
-
164
- ```bash
165
- rulebook ralph init # Generate PRD from tasks
166
- rulebook ralph run --max-iterations 10
167
- rulebook ralph status / history / pause / resume
168
- ```
169
-
170
- PRD format: `userStories` array with `id`, `title`, `description`, `acceptanceCriteria`, `priority`, `passes: boolean`, `notes`. Status tracked via `passes`, NOT enum.
171
-
172
- Iteration records in `.rulebook/ralph/history/iteration-N.json`. Status: `success` (5/5 gates), `partial` (2-4), `failed` (0-1).
173
-
174
160
  ## Multi-Agent Teams
175
161
 
176
162
  Requires `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`. Background `Agent` calls **must** use a Team (`team_name` parameter) — standalone background agents can't communicate via `SendMessage`. Foreground calls and `team-lead` agents are exempt.
@@ -1,76 +1,74 @@
1
- #!/usr/bin/env bash
2
- # Claude Code Stop hook — context freshness monitor.
3
- #
4
- # Runs after every model turn. Estimates the current context usage
5
- # from the JSONL transcript and, when it exceeds the configured
6
- # threshold, emits additionalContext instructing the model to invoke
7
- # the /handoff skill and tell the user to type /clear.
8
- #
9
- # Thresholds are read from .rulebook/rulebook.json `handoff` section.
10
- # Defaults: warn=75, force=90 (percentage of estimated max context).
11
-
12
- set -euo pipefail
13
-
14
- # Read the hook input from stdin (Claude Code passes it as JSON)
15
- input="$(cat)"
16
-
17
- # Resolve project root from hook input cwd, NOT $(pwd) — the hook may be
18
- # invoked from a sub-directory the user is currently editing.
19
- PROJECT_ROOT=""
20
- if [[ -n "$input" ]] && command -v jq &>/dev/null; then
21
- PROJECT_ROOT="$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null || true)"
22
- fi
23
- [[ -z "$PROJECT_ROOT" ]] && PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$(pwd)}"
24
-
25
- CONFIG_FILE="${PROJECT_ROOT}/.rulebook/rulebook.json"
26
- HANDOFF_DIR="${PROJECT_ROOT}/.rulebook/handoff"
27
-
28
- # Defaults
29
- WARN_PCT=75
30
- FORCE_PCT=90
31
- MAX_CONTEXT_CHARS=1600000 # ~400k tokens ≈ 1.6M chars (rough 1:4 ratio)
32
-
33
- # Override from config if available
34
- if [[ -f "$CONFIG_FILE" ]] && command -v jq &>/dev/null; then
35
- WARN_PCT=$(jq -r '.handoff.warnThresholdPct // 75' "$CONFIG_FILE" 2>/dev/null || echo 75)
36
- FORCE_PCT=$(jq -r '.handoff.forceThresholdPct // 90' "$CONFIG_FILE" 2>/dev/null || echo 90)
37
- fi
38
-
39
- # Try to find the transcript path from the session
40
- # Claude Code stores transcripts as JSONL in ~/.claude/projects/<hash>/
41
- # The hook input may or may not contain session info; we fall back to
42
- # estimating from the input itself.
43
- transcript_size=0
44
-
45
- # Strategy 1: check the most recent JSONL in the project-specific Claude dir
46
- CLAUDE_PROJECTS_DIR="${HOME}/.claude/projects"
47
- if [[ -d "$CLAUDE_PROJECTS_DIR" ]]; then
48
- latest_jsonl=$(find "$CLAUDE_PROJECTS_DIR" -name "*.jsonl" -type f -printf '%T@ %p\n' 2>/dev/null | sort -rn | head -1 | awk '{print $2}' || true)
49
- if [[ -n "$latest_jsonl" && -f "$latest_jsonl" ]]; then
50
- transcript_size=$(stat -c%s "$latest_jsonl" 2>/dev/null || stat -f%z "$latest_jsonl" 2>/dev/null || echo 0)
51
- fi
52
- fi
53
-
54
- # If we couldn't get transcript size, emit nothing (no-op)
55
- if [[ "$transcript_size" -eq 0 ]]; then
56
- printf '%s' '{}'
57
- exit 0
58
- fi
59
-
60
- # Estimate context percentage
61
- pct=$(( transcript_size * 100 / MAX_CONTEXT_CHARS ))
62
-
63
- if [[ "$pct" -ge "$FORCE_PCT" ]]; then
64
- # Force mode: write urgent sentinel + emit strong instruction
65
- mkdir -p "$HANDOFF_DIR"
66
- touch "${HANDOFF_DIR}/.urgent"
67
- msg="⚠️ CONTEXT AT ${pct}% (FORCE THRESHOLD). You MUST invoke /handoff NOW to save session state to .rulebook/handoff/_pending.md. After it succeeds, tell the user: '>>> TYPE /clear NOW — your context will be auto-restored in the next session <<<'. Do NOT continue working until the user has typed /clear."
68
- jq -nc --arg msg "$msg" '{ hookSpecificOutput: { hookEventName: "Stop", additionalContext: $msg } }'
69
- elif [[ "$pct" -ge "$WARN_PCT" ]]; then
70
- msg="⚠️ Context at ${pct}%. Recommended: invoke /handoff to save session state. After it succeeds, tell the user to type /clear for a fresh session."
71
- jq -nc --arg msg "$msg" '{ hookSpecificOutput: { hookEventName: "Stop", additionalContext: $msg } }'
72
- else
73
- # Below threshold — no-op
74
- printf '%s' '{}'
75
- fi
76
- exit 0
1
+ #!/usr/bin/env bash
2
+ # Claude Code Stop hook — context freshness monitor.
3
+ #
4
+ # Runs after every model turn. Estimates the current context usage
5
+ # from the JSONL transcript and, when it exceeds the configured
6
+ # threshold, emits additionalContext instructing the model to invoke
7
+ # the /handoff skill and tell the user to type /clear.
8
+ #
9
+ # Thresholds are read from .rulebook/rulebook.json `handoff` section.
10
+ # Defaults: warn=75, force=90 (percentage of estimated max context).
11
+
12
+ set -euo pipefail
13
+
14
+ # Read the hook input from stdin (Claude Code passes it as JSON)
15
+ input="$(cat)"
16
+
17
+ # Resolve project root from hook input cwd, NOT $(pwd) — the hook may be
18
+ # invoked from a sub-directory the user is currently editing.
19
+ PROJECT_ROOT=""
20
+ if [[ -n "$input" ]] && command -v jq &>/dev/null; then
21
+ PROJECT_ROOT="$(printf '%s' "$input" | jq -r '.cwd // empty' 2>/dev/null || true)"
22
+ fi
23
+ [[ -z "$PROJECT_ROOT" ]] && PROJECT_ROOT="${CLAUDE_PROJECT_DIR:-$(pwd)}"
24
+
25
+ CONFIG_FILE="${PROJECT_ROOT}/.rulebook/rulebook.json"
26
+ HANDOFF_DIR="${PROJECT_ROOT}/.rulebook/handoff"
27
+
28
+ # Defaults
29
+ WARN_PCT=75
30
+ FORCE_PCT=90
31
+ MAX_CONTEXT_CHARS=1600000 # ~400k tokens ≈ 1.6M chars (rough 1:4 ratio)
32
+
33
+ # Override from config if available
34
+ if [[ -f "$CONFIG_FILE" ]] && command -v jq &>/dev/null; then
35
+ WARN_PCT=$(jq -r '.handoff.warnThresholdPct // 75' "$CONFIG_FILE" 2>/dev/null || echo 75)
36
+ FORCE_PCT=$(jq -r '.handoff.forceThresholdPct // 90' "$CONFIG_FILE" 2>/dev/null || echo 90)
37
+ fi
38
+
39
+ # Resolve transcript size from the payload's transcript_path. Claude Code
40
+ # always passes this in Stop hook stdin (Anthropic hook spec), so we avoid
41
+ # scanning $HOME/.claude/projects which grows linearly with session count
42
+ # and also returns the wrong file in concurrent sessions.
43
+ transcript_size=0
44
+
45
+ if [[ -n "$input" ]] && command -v jq &>/dev/null; then
46
+ transcript_path="$(printf '%s' "$input" | jq -r '.transcript_path // empty' 2>/dev/null || true)"
47
+ if [[ -n "$transcript_path" && -f "$transcript_path" ]]; then
48
+ transcript_size=$(stat -c%s "$transcript_path" 2>/dev/null || stat -f%z "$transcript_path" 2>/dev/null || echo 0)
49
+ fi
50
+ fi
51
+
52
+ # If we couldn't get transcript size, emit nothing (no-op)
53
+ if [[ "$transcript_size" -eq 0 ]]; then
54
+ printf '%s' '{}'
55
+ exit 0
56
+ fi
57
+
58
+ # Estimate context percentage
59
+ pct=$(( transcript_size * 100 / MAX_CONTEXT_CHARS ))
60
+
61
+ if [[ "$pct" -ge "$FORCE_PCT" ]]; then
62
+ # Force mode: write urgent sentinel + emit strong instruction
63
+ mkdir -p "$HANDOFF_DIR"
64
+ touch "${HANDOFF_DIR}/.urgent"
65
+ msg="⚠️ CONTEXT AT ${pct}% (FORCE THRESHOLD). You MUST invoke /handoff NOW to save session state to .rulebook/handoff/_pending.md. After it succeeds, tell the user: '>>> TYPE /clear NOW — your context will be auto-restored in the next session <<<'. Do NOT continue working until the user has typed /clear."
66
+ jq -nc --arg msg "$msg" '{ hookSpecificOutput: { hookEventName: "Stop", additionalContext: $msg } }'
67
+ elif [[ "$pct" -ge "$WARN_PCT" ]]; then
68
+ msg="⚠️ Context at ${pct}%. Recommended: invoke /handoff to save session state. After it succeeds, tell the user to type /clear for a fresh session."
69
+ jq -nc --arg msg "$msg" '{ hookSpecificOutput: { hookEventName: "Stop", additionalContext: $msg } }'
70
+ else
71
+ # Below threshold no-op
72
+ printf '%s' '{}'
73
+ fi
74
+ exit 0
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env bash
2
+ # PreToolUse hook (v5.6.0): consolidated deny rules.
3
+ #
4
+ # Replaces three legacy hooks (enforce-no-deferred / enforce-no-shortcuts /
5
+ # enforce-mcp-for-tasks) with a single bash + node invocation. Each rule's
6
+ # permissionDecisionReason is preserved verbatim so existing user guidance
7
+ # is unchanged.
8
+ set -euo pipefail
9
+ input="$(cat)"
10
+
11
+ result="$(node -e "
12
+ const input = JSON.parse(process.argv[1]);
13
+ const tool = input.tool_name || '';
14
+ const ti = input.tool_input || {};
15
+ const file = (ti.file_path || ti.filePath || '').replace(/\\\\/g, '/');
16
+ const content = ti.new_string || ti.content || '';
17
+ const cmd = ti.command || '';
18
+
19
+ // Rule: mcp-for-tasks — manual creation of task scaffolding is forbidden.
20
+ if (tool === 'Write' || tool === 'Edit') {
21
+ const m = file.match(/\.rulebook\/tasks\/[^/]+\/(proposal\.md|\.metadata\.json)\$/);
22
+ if (m) {
23
+ try { require('fs').accessSync(file); /* existing file: allow edit */ }
24
+ catch { console.log('DENY_MCP'); process.exit(0); }
25
+ }
26
+ }
27
+ if (tool === 'Bash' && /mkdir.*\\.rulebook\\/tasks\\//.test(cmd)) {
28
+ console.log('DENY_MCP'); process.exit(0);
29
+ }
30
+
31
+ // Rule: no-deferred — tasks.md must not contain deferred / skip / later / TODO.
32
+ if ((tool === 'Edit' || tool === 'Write') && file.endsWith('tasks.md')) {
33
+ if (/\\b(deferred|skip(ped)?|later|todo)\\b/i.test(content)) {
34
+ console.log('DENY_DEFERRED'); process.exit(0);
35
+ }
36
+ }
37
+
38
+ // Rule: no-shortcuts — source files must not contain TODO/FIXME/HACK or stub/placeholder.
39
+ if (tool === 'Edit' || tool === 'Write') {
40
+ if (/\\.(ts|tsx|js|jsx|py|rs|go|java|cs|cpp|c|hpp|h)\$/.test(file)
41
+ && !/\\.test\\.|\\.spec\\.|__tests__|\\/tests\\//.test(file)) {
42
+ if (/\\/\\/\\s*(TODO|FIXME|HACK)\\b|\\/\\*\\s*(TODO|FIXME|HACK)\\b|#\\s*(TODO|FIXME|HACK)\\b/.test(content)) {
43
+ console.log('DENY_TODO'); process.exit(0);
44
+ }
45
+ if (/\\bplaceholder\\b|\\bstub\\b/i.test(content)) {
46
+ console.log('DENY_STUB'); process.exit(0);
47
+ }
48
+ }
49
+ }
50
+
51
+ console.log('ALLOW');
52
+ " "$input" 2>/dev/null || echo "ALLOW")"
53
+
54
+ case "$result" in
55
+ DENY_MCP)
56
+ echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"DENIED: task files must be created via rulebook_task_create MCP tool, not manually. Use: rulebook_task_create({ taskId: phase1_your-task-name })"}}'
57
+ ;;
58
+ DENY_DEFERRED)
59
+ echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"DENIED: tasks.md cannot contain deferred, skip, later, or TODO. Implement the item now or explain why impossible. See .claude/rules/no-deferred.md"}}'
60
+ ;;
61
+ DENY_TODO)
62
+ echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"DENIED: source code cannot contain // TODO, // FIXME, or // HACK. Implement the logic now. See .claude/rules/no-shortcuts.md"}}'
63
+ ;;
64
+ DENY_STUB)
65
+ echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"deny","permissionDecisionReason":"DENIED: source code cannot contain placeholders or stubs. Implement real logic. See .claude/rules/no-shortcuts.md"}}'
66
+ ;;
67
+ *)
68
+ echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}'
69
+ ;;
70
+ esac