@hivehub/rulebook 5.7.0 → 5.8.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 (599) hide show
  1. package/.claude/commands/analysis.md +35 -35
  2. package/.claude/commands/continue.md +33 -33
  3. package/.claude/commands/rulebook-decision-create.md +55 -55
  4. package/.claude/commands/rulebook-decision-list.md +15 -15
  5. package/.claude/commands/rulebook-knowledge-add.md +41 -41
  6. package/.claude/commands/rulebook-knowledge-list.md +15 -15
  7. package/.claude/commands/rulebook-memory-save.md +48 -48
  8. package/.claude/commands/rulebook-memory-search.md +47 -47
  9. package/.claude/commands/rulebook-task-apply.md +67 -67
  10. package/.claude/commands/rulebook-task-archive.md +94 -94
  11. package/.claude/commands/rulebook-task-create.md +93 -93
  12. package/.claude/commands/rulebook-task-list.md +42 -42
  13. package/.claude/commands/rulebook-task-show.md +52 -52
  14. package/.claude/commands/rulebook-task-validate.md +53 -53
  15. package/.claude-plugin/marketplace.json +28 -28
  16. package/.claude-plugin/plugin.json +8 -8
  17. package/README.md +86 -0
  18. package/dist/cli/commands/claude.d.ts +17 -0
  19. package/dist/cli/commands/claude.d.ts.map +1 -0
  20. package/dist/cli/commands/claude.js +56 -0
  21. package/dist/cli/commands/claude.js.map +1 -0
  22. package/dist/cli/commands/init.d.ts.map +1 -1
  23. package/dist/cli/commands/init.js +18 -2
  24. package/dist/cli/commands/init.js.map +1 -1
  25. package/dist/cli/commands/update.d.ts.map +1 -1
  26. package/dist/cli/commands/update.js +6 -1
  27. package/dist/cli/commands/update.js.map +1 -1
  28. package/dist/cli/prompts.d.ts +13 -0
  29. package/dist/cli/prompts.d.ts.map +1 -1
  30. package/dist/cli/prompts.js +106 -0
  31. package/dist/cli/prompts.js.map +1 -1
  32. package/dist/core/claude/claude-mcp.d.ts +9 -0
  33. package/dist/core/claude/claude-mcp.d.ts.map +1 -1
  34. package/dist/core/claude/claude-mcp.js +30 -0
  35. package/dist/core/claude/claude-mcp.js.map +1 -1
  36. package/dist/core/claude/claude-settings-manager.d.ts +12 -0
  37. package/dist/core/claude/claude-settings-manager.d.ts.map +1 -1
  38. package/dist/core/claude/claude-settings-manager.js +59 -3
  39. package/dist/core/claude/claude-settings-manager.js.map +1 -1
  40. package/dist/core/detect/detector.d.ts +8 -1
  41. package/dist/core/detect/detector.d.ts.map +1 -1
  42. package/dist/core/detect/detector.js +225 -0
  43. package/dist/core/detect/detector.js.map +1 -1
  44. package/dist/core/detect/library-registry.d.ts +40 -0
  45. package/dist/core/detect/library-registry.d.ts.map +1 -0
  46. package/dist/core/detect/library-registry.js +239 -0
  47. package/dist/core/detect/library-registry.js.map +1 -0
  48. package/dist/core/generators/generator.d.ts +1 -0
  49. package/dist/core/generators/generator.d.ts.map +1 -1
  50. package/dist/core/generators/generator.js +37 -0
  51. package/dist/core/generators/generator.js.map +1 -1
  52. package/dist/core/generators/rules-generator.d.ts +1 -5
  53. package/dist/core/generators/rules-generator.d.ts.map +1 -1
  54. package/dist/core/generators/rules-generator.js +40 -1
  55. package/dist/core/generators/rules-generator.js.map +1 -1
  56. package/dist/index.js +12 -0
  57. package/dist/index.js.map +1 -1
  58. package/dist/mcp/rulebook-server.js +0 -0
  59. package/dist/types.d.ts +13 -0
  60. package/dist/types.d.ts.map +1 -1
  61. package/package.json +23 -22
  62. package/templates/agents/accessibility-reviewer.md +43 -43
  63. package/templates/agents/api-designer.md +42 -42
  64. package/templates/agents/architect.md +51 -51
  65. package/templates/agents/build-engineer.md +36 -36
  66. package/templates/agents/code-reviewer.md +47 -47
  67. package/templates/agents/compiler/codegen-debugger.md +34 -34
  68. package/templates/agents/compiler/stdlib-engineer.md +28 -28
  69. package/templates/agents/compiler/test-coverage-guardian.md +31 -31
  70. package/templates/agents/database-architect.md +41 -41
  71. package/templates/agents/devops-engineer.md +42 -42
  72. package/templates/agents/docs-writer.md +38 -38
  73. package/templates/agents/game-engine/cpp-core-expert.md +35 -35
  74. package/templates/agents/game-engine/render-engineer.md +22 -22
  75. package/templates/agents/game-engine/shader-engineer.md +38 -38
  76. package/templates/agents/game-engine/systems-integration.md +43 -43
  77. package/templates/agents/generic/code-reviewer.md +41 -41
  78. package/templates/agents/generic/docs-writer.md +25 -25
  79. package/templates/agents/generic/project-manager.md +36 -36
  80. package/templates/agents/generic/researcher.md +34 -34
  81. package/templates/agents/generic/test-engineer.md +41 -41
  82. package/templates/agents/i18n-engineer.md +42 -42
  83. package/templates/agents/implementer.md +42 -42
  84. package/templates/agents/migration-engineer.md +42 -42
  85. package/templates/agents/mobile/platform-specialist.md +22 -22
  86. package/templates/agents/mobile/ui-engineer.md +22 -22
  87. package/templates/agents/performance-engineer.md +49 -49
  88. package/templates/agents/project-manager.md +215 -0
  89. package/templates/agents/quality-gatekeeper.md +205 -0
  90. package/templates/agents/refactoring-agent.md +41 -41
  91. package/templates/agents/researcher.md +38 -38
  92. package/templates/agents/security-reviewer.md +40 -40
  93. package/templates/agents/team-lead.md +37 -37
  94. package/templates/agents/tester.md +48 -48
  95. package/templates/agents/ux-reviewer.md +43 -43
  96. package/templates/agents/web-app/api-designer.md +22 -22
  97. package/templates/agents/web-app/backend-engineer.md +30 -30
  98. package/templates/agents/web-app/database-engineer.md +22 -22
  99. package/templates/agents/web-app/frontend-engineer.md +29 -29
  100. package/templates/agents/web-app/security-reviewer.md +32 -32
  101. package/templates/ci/rulebook-review.yml +26 -26
  102. package/templates/claude-workflows/bugfix.js +94 -0
  103. package/templates/claude-workflows/feature-pipeline.js +88 -0
  104. package/templates/claude-workflows/release-gate.js +64 -0
  105. package/templates/claude-workflows/review-fanout.js +118 -0
  106. package/templates/claude-workflows/rulebook-driver.js +343 -0
  107. package/templates/claude-workflows/spec-author.js +133 -0
  108. package/templates/cli/AIDER.md +49 -49
  109. package/templates/cli/AMAZON_Q.md +25 -25
  110. package/templates/cli/AUGGIE.md +32 -32
  111. package/templates/cli/CLAUDE.md +117 -117
  112. package/templates/cli/CLINE.md +99 -99
  113. package/templates/cli/CODEBUDDY.md +20 -20
  114. package/templates/cli/CODEIUM.md +20 -20
  115. package/templates/cli/CODEX.md +21 -21
  116. package/templates/cli/CONTINUE.md +34 -34
  117. package/templates/cli/CURSOR_CLI.md +62 -62
  118. package/templates/cli/FACTORY.md +18 -18
  119. package/templates/cli/GEMINI.md +35 -35
  120. package/templates/cli/KILOCODE.md +18 -18
  121. package/templates/cli/_GENERIC_TEMPLATE.md +29 -29
  122. package/templates/commands/rulebook-decision-create.md +55 -55
  123. package/templates/commands/rulebook-decision-list.md +15 -15
  124. package/templates/commands/rulebook-knowledge-add.md +41 -41
  125. package/templates/commands/rulebook-knowledge-list.md +15 -15
  126. package/templates/commands/rulebook-memory-save.md +48 -48
  127. package/templates/commands/rulebook-memory-search.md +47 -47
  128. package/templates/commands/rulebook-task-apply.md +67 -67
  129. package/templates/commands/rulebook-task-archive.md +94 -94
  130. package/templates/commands/rulebook-task-create.md +93 -93
  131. package/templates/commands/rulebook-task-list.md +42 -42
  132. package/templates/commands/rulebook-task-show.md +52 -52
  133. package/templates/commands/rulebook-task-validate.md +53 -53
  134. package/templates/compact-context/_default.md +23 -23
  135. package/templates/compact-context/cpp.md +26 -26
  136. package/templates/compact-context/go.md +26 -26
  137. package/templates/compact-context/python.md +26 -26
  138. package/templates/compact-context/rust.md +28 -28
  139. package/templates/compact-context/typescript.md +29 -29
  140. package/templates/core/AGENTS_OVERRIDE.md +16 -16
  141. package/templates/core/AGENT_AUTOMATION.md +296 -296
  142. package/templates/core/CLAUDE_MD_v2.md +90 -90
  143. package/templates/core/DAG.md +304 -304
  144. package/templates/core/DECISIONS.md +38 -38
  145. package/templates/core/DOCUMENTATION_RULES.md +36 -36
  146. package/templates/core/KNOWLEDGE.md +49 -49
  147. package/templates/core/MULTI_AGENT.md +74 -74
  148. package/templates/core/PLANS.md +28 -28
  149. package/templates/core/QUALITY_ENFORCEMENT.md +68 -68
  150. package/templates/core/RULEBOOK.md +1947 -1947
  151. package/templates/core/TIER1_PROHIBITIONS.md +154 -154
  152. package/templates/core/TOKEN_OPTIMIZATION.md +49 -49
  153. package/templates/git/CI_CD_PATTERNS.md +661 -661
  154. package/templates/git/GITHUB_ACTIONS.md +728 -728
  155. package/templates/git/GITLAB_CI.md +730 -730
  156. package/templates/git/GIT_WORKFLOW.md +1192 -1192
  157. package/templates/git/SECRETS_MANAGEMENT.md +585 -585
  158. package/templates/hooks/COMMIT_MSG.md +530 -530
  159. package/templates/hooks/POST_CHECKOUT.md +546 -546
  160. package/templates/hooks/PREPARE_COMMIT_MSG.md +619 -619
  161. package/templates/hooks/PRE_COMMIT.md +414 -414
  162. package/templates/hooks/PRE_PUSH.md +601 -601
  163. package/templates/hooks/check-context-and-handoff.sh +16 -6
  164. package/templates/hooks/update-check.ps1 +84 -0
  165. package/templates/hooks/update-check.sh +103 -0
  166. package/templates/ides/CONTINUE_RULES.md +16 -16
  167. package/templates/ides/COPILOT_INSTRUCTIONS.md +23 -23
  168. package/templates/ides/GEMINI_RULES.md +17 -17
  169. package/templates/ides/WINDSURF_RULES.md +14 -14
  170. package/templates/languages/C.md +333 -333
  171. package/templates/languages/CPP.md +743 -743
  172. package/templates/languages/CSHARP.md +417 -417
  173. package/templates/languages/ELIXIR.md +454 -454
  174. package/templates/languages/ERLANG.md +361 -361
  175. package/templates/languages/GO.md +645 -645
  176. package/templates/languages/HASKELL.md +177 -177
  177. package/templates/languages/JAVA.md +607 -607
  178. package/templates/languages/JAVASCRIPT.md +631 -631
  179. package/templates/languages/JULIA.md +97 -97
  180. package/templates/languages/KOTLIN.md +511 -511
  181. package/templates/languages/LISP.md +100 -100
  182. package/templates/languages/LUA.md +74 -74
  183. package/templates/languages/OBJECTIVEC.md +90 -90
  184. package/templates/languages/PHP.md +416 -416
  185. package/templates/languages/PYTHON.md +682 -682
  186. package/templates/languages/RUBY.md +421 -421
  187. package/templates/languages/RUST.md +477 -477
  188. package/templates/languages/SAS.md +73 -73
  189. package/templates/languages/SCALA.md +348 -348
  190. package/templates/languages/SOLIDITY.md +580 -580
  191. package/templates/languages/SQL.md +137 -137
  192. package/templates/languages/SWIFT.md +466 -466
  193. package/templates/languages/TYPESCRIPT.md +591 -591
  194. package/templates/languages/ZIG.md +265 -265
  195. package/templates/libraries/go/ECHO.md +18 -0
  196. package/templates/libraries/go/GIN.md +18 -0
  197. package/templates/libraries/go/GORM.md +18 -0
  198. package/templates/libraries/python/DJANGO.md +18 -0
  199. package/templates/libraries/python/FASTAPI.md +18 -0
  200. package/templates/libraries/python/FLASK.md +17 -0
  201. package/templates/libraries/python/PYDANTIC.md +17 -0
  202. package/templates/libraries/python/PYTEST.md +17 -0
  203. package/templates/libraries/python/SQLALCHEMY.md +17 -0
  204. package/templates/libraries/rust/ACTIX.md +17 -0
  205. package/templates/libraries/rust/AXUM.md +18 -0
  206. package/templates/libraries/rust/SERDE.md +16 -0
  207. package/templates/libraries/rust/SQLX.md +17 -0
  208. package/templates/libraries/rust/TOKIO.md +16 -0
  209. package/templates/libraries/typescript/ANGULAR.md +17 -0
  210. package/templates/libraries/typescript/DRIZZLE.md +16 -0
  211. package/templates/libraries/typescript/EXPRESS.md +17 -0
  212. package/templates/libraries/typescript/HEROUI.md +16 -0
  213. package/templates/libraries/typescript/JEST.md +17 -0
  214. package/templates/libraries/typescript/NESTJS.md +17 -0
  215. package/templates/libraries/typescript/NEXT.md +18 -0
  216. package/templates/libraries/typescript/PRISMA.md +16 -0
  217. package/templates/libraries/typescript/RADIX.md +16 -0
  218. package/templates/libraries/typescript/REACT.md +18 -0
  219. package/templates/libraries/typescript/SHADCN.md +16 -0
  220. package/templates/libraries/typescript/SVELTE.md +16 -0
  221. package/templates/libraries/typescript/TAILWIND.md +16 -0
  222. package/templates/libraries/typescript/TRPC.md +16 -0
  223. package/templates/libraries/typescript/VITEST.md +17 -0
  224. package/templates/libraries/typescript/VUE.md +17 -0
  225. package/templates/libraries/typescript/ZOD.md +17 -0
  226. package/templates/modules/ATLASSIAN.md +255 -255
  227. package/templates/modules/CONTEXT7.md +54 -54
  228. package/templates/modules/FIGMA.md +267 -267
  229. package/templates/modules/GITHUB_MCP.md +64 -64
  230. package/templates/modules/GRAFANA.md +328 -328
  231. package/templates/modules/MEMORY.md +126 -126
  232. package/templates/modules/NOTION.md +247 -247
  233. package/templates/modules/PLAYWRIGHT.md +90 -90
  234. package/templates/modules/RULEBOOK_MCP.md +208 -208
  235. package/templates/modules/SERENA.md +337 -337
  236. package/templates/modules/SUPABASE.md +223 -223
  237. package/templates/modules/SYNAP.md +69 -69
  238. package/templates/modules/VECTORIZER.md +63 -63
  239. package/templates/modules/sequential-thinking.md +42 -42
  240. package/templates/rules/consult-analysis-before-implementing.md +23 -23
  241. package/templates/rules/cpp.md +46 -46
  242. package/templates/rules/csharp.md +44 -44
  243. package/templates/rules/diagnostic-first.md +39 -39
  244. package/templates/rules/fail-twice-escalate.md +46 -46
  245. package/templates/rules/follow-task-sequence.md +36 -36
  246. package/templates/rules/git-safety.md +29 -29
  247. package/templates/rules/go.md +40 -40
  248. package/templates/rules/incremental-implementation.md +56 -56
  249. package/templates/rules/incremental-tests.md +29 -29
  250. package/templates/rules/java.md +43 -43
  251. package/templates/rules/javascript.md +39 -39
  252. package/templates/rules/knowledge-base-usage.md +41 -41
  253. package/templates/rules/multi-agent-teams.md +75 -75
  254. package/templates/rules/no-deferred.md +31 -31
  255. package/templates/rules/no-shortcuts.md +30 -30
  256. package/templates/rules/python.md +43 -43
  257. package/templates/rules/research-first.md +30 -30
  258. package/templates/rules/respect-handoff-trigger.md +41 -41
  259. package/templates/rules/rust.md +40 -40
  260. package/templates/rules/sequential-editing.md +21 -21
  261. package/templates/rules/session-workflow.md +24 -24
  262. package/templates/rules/task-decomposition.md +32 -32
  263. package/templates/rules/typescript.md +40 -40
  264. package/templates/skills/cli/aider/SKILL.md +59 -59
  265. package/templates/skills/cli/amazon-q/SKILL.md +35 -35
  266. package/templates/skills/cli/auggie/SKILL.md +42 -42
  267. package/templates/skills/cli/claude/SKILL.md +42 -42
  268. package/templates/skills/cli/cline/SKILL.md +42 -42
  269. package/templates/skills/cli/codebuddy/SKILL.md +30 -30
  270. package/templates/skills/cli/codeium/SKILL.md +30 -30
  271. package/templates/skills/cli/codex/SKILL.md +31 -31
  272. package/templates/skills/cli/continue/SKILL.md +44 -44
  273. package/templates/skills/cli/cursor-cli/SKILL.md +38 -38
  274. package/templates/skills/cli/factory/SKILL.md +28 -28
  275. package/templates/skills/cli/gemini/SKILL.md +45 -45
  276. package/templates/skills/cli/kilocode/SKILL.md +28 -28
  277. package/templates/skills/core/agent-automation/SKILL.md +194 -194
  278. package/templates/skills/core/dag/SKILL.md +314 -314
  279. package/templates/skills/core/documentation-rules/SKILL.md +46 -46
  280. package/templates/skills/core/quality-enforcement/SKILL.md +78 -78
  281. package/templates/skills/core/rulebook/SKILL.md +176 -176
  282. package/templates/skills/core/rulebook-terse/SKILL.md +116 -116
  283. package/templates/skills/core/rulebook-terse-commit/SKILL.md +96 -96
  284. package/templates/skills/core/rulebook-terse-review/SKILL.md +112 -112
  285. package/templates/skills/dev/accessibility/SKILL.md +17 -17
  286. package/templates/skills/dev/analysis/SKILL.md +19 -19
  287. package/templates/skills/dev/api-design/SKILL.md +15 -15
  288. package/templates/skills/dev/architect/SKILL.md +17 -17
  289. package/templates/skills/dev/build-fix/SKILL.md +17 -17
  290. package/templates/skills/dev/db-design/SKILL.md +15 -15
  291. package/templates/skills/dev/debug/SKILL.md +16 -16
  292. package/templates/skills/dev/deploy/SKILL.md +17 -17
  293. package/templates/skills/dev/docs/SKILL.md +17 -17
  294. package/templates/skills/dev/handoff/SKILL.md +27 -27
  295. package/templates/skills/dev/migrate/SKILL.md +15 -15
  296. package/templates/skills/dev/perf/SKILL.md +17 -17
  297. package/templates/skills/dev/refactor/SKILL.md +17 -17
  298. package/templates/skills/dev/research/SKILL.md +14 -14
  299. package/templates/skills/dev/review/SKILL.md +18 -18
  300. package/templates/skills/dev/security-audit/SKILL.md +17 -17
  301. package/templates/skills/dev/spec/SKILL.md +65 -0
  302. package/templates/skills/ides/copilot/SKILL.md +47 -47
  303. package/templates/skills/ides/cursor/SKILL.md +53 -53
  304. package/templates/skills/ides/jetbrains-ai/SKILL.md +45 -45
  305. package/templates/skills/ides/replit/SKILL.md +46 -46
  306. package/templates/skills/ides/tabnine/SKILL.md +39 -39
  307. package/templates/skills/ides/vscode/SKILL.md +50 -50
  308. package/templates/skills/ides/windsurf/SKILL.md +46 -46
  309. package/templates/skills/ides/zed/SKILL.md +42 -42
  310. package/templates/skills/languages/c/SKILL.md +343 -343
  311. package/templates/skills/languages/cpp/SKILL.md +753 -753
  312. package/templates/skills/languages/csharp/SKILL.md +427 -427
  313. package/templates/skills/languages/elixir/SKILL.md +464 -464
  314. package/templates/skills/languages/erlang/SKILL.md +371 -371
  315. package/templates/skills/languages/go/SKILL.md +655 -655
  316. package/templates/skills/languages/haskell/SKILL.md +187 -187
  317. package/templates/skills/languages/java/SKILL.md +617 -617
  318. package/templates/skills/languages/javascript/SKILL.md +641 -641
  319. package/templates/skills/languages/julia/SKILL.md +107 -107
  320. package/templates/skills/languages/kotlin/SKILL.md +521 -521
  321. package/templates/skills/languages/lisp/SKILL.md +110 -110
  322. package/templates/skills/languages/lua/SKILL.md +84 -84
  323. package/templates/skills/languages/objectivec/SKILL.md +100 -100
  324. package/templates/skills/languages/php/SKILL.md +426 -426
  325. package/templates/skills/languages/python/SKILL.md +692 -692
  326. package/templates/skills/languages/ruby/SKILL.md +431 -431
  327. package/templates/skills/languages/rust/SKILL.md +487 -487
  328. package/templates/skills/languages/sas/SKILL.md +83 -83
  329. package/templates/skills/languages/scala/SKILL.md +358 -358
  330. package/templates/skills/languages/solidity/SKILL.md +590 -590
  331. package/templates/skills/languages/sql/SKILL.md +147 -147
  332. package/templates/skills/languages/swift/SKILL.md +476 -476
  333. package/templates/skills/languages/typescript/SKILL.md +302 -302
  334. package/templates/skills/languages/zig/SKILL.md +275 -275
  335. package/templates/skills/modules/atlassian/SKILL.md +265 -265
  336. package/templates/skills/modules/context7/SKILL.md +64 -64
  337. package/templates/skills/modules/figma/SKILL.md +277 -277
  338. package/templates/skills/modules/github-mcp/SKILL.md +74 -74
  339. package/templates/skills/modules/grafana/SKILL.md +338 -338
  340. package/templates/skills/modules/memory/SKILL.md +73 -73
  341. package/templates/skills/modules/notion/SKILL.md +257 -257
  342. package/templates/skills/modules/playwright/SKILL.md +100 -100
  343. package/templates/skills/modules/rulebook-mcp/SKILL.md +166 -166
  344. package/templates/skills/modules/serena/SKILL.md +347 -347
  345. package/templates/skills/modules/supabase/SKILL.md +233 -233
  346. package/templates/skills/modules/synap/SKILL.md +79 -79
  347. package/templates/skills/modules/vectorizer/SKILL.md +73 -73
  348. package/dist/agents/ralph-parser.d.ts +0 -91
  349. package/dist/agents/ralph-parser.d.ts.map +0 -1
  350. package/dist/agents/ralph-parser.js +0 -415
  351. package/dist/agents/ralph-parser.js.map +0 -1
  352. package/dist/cli/commands/analysis.d.ts +0 -8
  353. package/dist/cli/commands/analysis.d.ts.map +0 -1
  354. package/dist/cli/commands/analysis.js +0 -78
  355. package/dist/cli/commands/analysis.js.map +0 -1
  356. package/dist/cli/commands/compress.d.ts +0 -18
  357. package/dist/cli/commands/compress.d.ts.map +0 -1
  358. package/dist/cli/commands/compress.js +0 -100
  359. package/dist/cli/commands/compress.js.map +0 -1
  360. package/dist/cli/commands/ralph.d.ts +0 -45
  361. package/dist/cli/commands/ralph.d.ts.map +0 -1
  362. package/dist/cli/commands/ralph.js +0 -694
  363. package/dist/cli/commands/ralph.js.map +0 -1
  364. package/dist/cli/docs-prompts.d.ts +0 -3
  365. package/dist/cli/docs-prompts.d.ts.map +0 -1
  366. package/dist/cli/docs-prompts.js +0 -45
  367. package/dist/cli/docs-prompts.js.map +0 -1
  368. package/dist/core/agent-manager.d.ts +0 -69
  369. package/dist/core/agent-manager.d.ts.map +0 -1
  370. package/dist/core/agent-manager.js +0 -476
  371. package/dist/core/agent-manager.js.map +0 -1
  372. package/dist/core/agent-template-engine.d.ts +0 -51
  373. package/dist/core/agent-template-engine.d.ts.map +0 -1
  374. package/dist/core/agent-template-engine.js +0 -291
  375. package/dist/core/agent-template-engine.js.map +0 -1
  376. package/dist/core/analysis-manager.d.ts +0 -56
  377. package/dist/core/analysis-manager.d.ts.map +0 -1
  378. package/dist/core/analysis-manager.js +0 -218
  379. package/dist/core/analysis-manager.js.map +0 -1
  380. package/dist/core/auto-fixer.d.ts +0 -14
  381. package/dist/core/auto-fixer.d.ts.map +0 -1
  382. package/dist/core/auto-fixer.js +0 -207
  383. package/dist/core/auto-fixer.js.map +0 -1
  384. package/dist/core/changelog-generator.d.ts +0 -44
  385. package/dist/core/changelog-generator.d.ts.map +0 -1
  386. package/dist/core/changelog-generator.js +0 -222
  387. package/dist/core/changelog-generator.js.map +0 -1
  388. package/dist/core/claude-mcp.d.ts +0 -59
  389. package/dist/core/claude-mcp.d.ts.map +0 -1
  390. package/dist/core/claude-mcp.js +0 -220
  391. package/dist/core/claude-mcp.js.map +0 -1
  392. package/dist/core/claude-md-generator.d.ts +0 -52
  393. package/dist/core/claude-md-generator.d.ts.map +0 -1
  394. package/dist/core/claude-md-generator.js +0 -104
  395. package/dist/core/claude-md-generator.js.map +0 -1
  396. package/dist/core/claude-settings-manager.d.ts +0 -44
  397. package/dist/core/claude-settings-manager.d.ts.map +0 -1
  398. package/dist/core/claude-settings-manager.js +0 -191
  399. package/dist/core/claude-settings-manager.js.map +0 -1
  400. package/dist/core/cli-bridge.d.ts +0 -113
  401. package/dist/core/cli-bridge.d.ts.map +0 -1
  402. package/dist/core/cli-bridge.js +0 -1094
  403. package/dist/core/cli-bridge.js.map +0 -1
  404. package/dist/core/compact-context-manager.d.ts +0 -34
  405. package/dist/core/compact-context-manager.d.ts.map +0 -1
  406. package/dist/core/compact-context-manager.js +0 -60
  407. package/dist/core/compact-context-manager.js.map +0 -1
  408. package/dist/core/complexity-detector.d.ts +0 -36
  409. package/dist/core/complexity-detector.d.ts.map +0 -1
  410. package/dist/core/complexity-detector.js +0 -334
  411. package/dist/core/complexity-detector.js.map +0 -1
  412. package/dist/core/compress/compressor.d.ts +0 -60
  413. package/dist/core/compress/compressor.d.ts.map +0 -1
  414. package/dist/core/compress/compressor.js +0 -232
  415. package/dist/core/compress/compressor.js.map +0 -1
  416. package/dist/core/compress/discover.d.ts +0 -19
  417. package/dist/core/compress/discover.d.ts.map +0 -1
  418. package/dist/core/compress/discover.js +0 -100
  419. package/dist/core/compress/discover.js.map +0 -1
  420. package/dist/core/compress/validator.d.ts +0 -47
  421. package/dist/core/compress/validator.d.ts.map +0 -1
  422. package/dist/core/compress/validator.js +0 -131
  423. package/dist/core/compress/validator.js.map +0 -1
  424. package/dist/core/config-manager.d.ts +0 -86
  425. package/dist/core/config-manager.d.ts.map +0 -1
  426. package/dist/core/config-manager.js +0 -621
  427. package/dist/core/config-manager.js.map +0 -1
  428. package/dist/core/coverage-checker.d.ts +0 -14
  429. package/dist/core/coverage-checker.d.ts.map +0 -1
  430. package/dist/core/coverage-checker.js +0 -176
  431. package/dist/core/coverage-checker.js.map +0 -1
  432. package/dist/core/cursor-mdc-generator.d.ts +0 -30
  433. package/dist/core/cursor-mdc-generator.d.ts.map +0 -1
  434. package/dist/core/cursor-mdc-generator.js +0 -98
  435. package/dist/core/cursor-mdc-generator.js.map +0 -1
  436. package/dist/core/decision-manager.d.ts +0 -25
  437. package/dist/core/decision-manager.d.ts.map +0 -1
  438. package/dist/core/decision-manager.js +0 -183
  439. package/dist/core/decision-manager.js.map +0 -1
  440. package/dist/core/dependency-checker.d.ts +0 -21
  441. package/dist/core/dependency-checker.d.ts.map +0 -1
  442. package/dist/core/dependency-checker.js +0 -247
  443. package/dist/core/dependency-checker.js.map +0 -1
  444. package/dist/core/detector.d.ts +0 -27
  445. package/dist/core/detector.d.ts.map +0 -1
  446. package/dist/core/detector.js +0 -1763
  447. package/dist/core/detector.js.map +0 -1
  448. package/dist/core/docs-generator.d.ts +0 -9
  449. package/dist/core/docs-generator.d.ts.map +0 -1
  450. package/dist/core/docs-generator.js +0 -531
  451. package/dist/core/docs-generator.js.map +0 -1
  452. package/dist/core/doctor.d.ts +0 -19
  453. package/dist/core/doctor.d.ts.map +0 -1
  454. package/dist/core/doctor.js +0 -229
  455. package/dist/core/doctor.js.map +0 -1
  456. package/dist/core/generator.d.ts +0 -56
  457. package/dist/core/generator.d.ts.map +0 -1
  458. package/dist/core/generator.js +0 -1193
  459. package/dist/core/generator.js.map +0 -1
  460. package/dist/core/github-issues-importer.d.ts +0 -82
  461. package/dist/core/github-issues-importer.d.ts.map +0 -1
  462. package/dist/core/github-issues-importer.js +0 -161
  463. package/dist/core/github-issues-importer.js.map +0 -1
  464. package/dist/core/gitignore-generator.d.ts +0 -13
  465. package/dist/core/gitignore-generator.d.ts.map +0 -1
  466. package/dist/core/gitignore-generator.js +0 -307
  467. package/dist/core/gitignore-generator.js.map +0 -1
  468. package/dist/core/health-scorer.d.ts +0 -61
  469. package/dist/core/health-scorer.d.ts.map +0 -1
  470. package/dist/core/health-scorer.js +0 -638
  471. package/dist/core/health-scorer.js.map +0 -1
  472. package/dist/core/iteration-tracker.d.ts +0 -85
  473. package/dist/core/iteration-tracker.d.ts.map +0 -1
  474. package/dist/core/iteration-tracker.js +0 -295
  475. package/dist/core/iteration-tracker.js.map +0 -1
  476. package/dist/core/knowledge-manager.d.ts +0 -24
  477. package/dist/core/knowledge-manager.d.ts.map +0 -1
  478. package/dist/core/knowledge-manager.js +0 -173
  479. package/dist/core/knowledge-manager.js.map +0 -1
  480. package/dist/core/learn-manager.d.ts +0 -29
  481. package/dist/core/learn-manager.d.ts.map +0 -1
  482. package/dist/core/learn-manager.js +0 -159
  483. package/dist/core/learn-manager.js.map +0 -1
  484. package/dist/core/mcp-reference-generator.d.ts +0 -13
  485. package/dist/core/mcp-reference-generator.d.ts.map +0 -1
  486. package/dist/core/mcp-reference-generator.js +0 -66
  487. package/dist/core/mcp-reference-generator.js.map +0 -1
  488. package/dist/core/minimal-scaffolder.d.ts +0 -8
  489. package/dist/core/minimal-scaffolder.d.ts.map +0 -1
  490. package/dist/core/minimal-scaffolder.js +0 -51
  491. package/dist/core/minimal-scaffolder.js.map +0 -1
  492. package/dist/core/modern-console.d.ts +0 -98
  493. package/dist/core/modern-console.d.ts.map +0 -1
  494. package/dist/core/modern-console.js +0 -556
  495. package/dist/core/modern-console.js.map +0 -1
  496. package/dist/core/multi-tool-generator.d.ts +0 -59
  497. package/dist/core/multi-tool-generator.d.ts.map +0 -1
  498. package/dist/core/multi-tool-generator.js +0 -157
  499. package/dist/core/multi-tool-generator.js.map +0 -1
  500. package/dist/core/override-manager.d.ts +0 -23
  501. package/dist/core/override-manager.d.ts.map +0 -1
  502. package/dist/core/override-manager.js +0 -82
  503. package/dist/core/override-manager.js.map +0 -1
  504. package/dist/core/plans-manager.d.ts +0 -46
  505. package/dist/core/plans-manager.d.ts.map +0 -1
  506. package/dist/core/plans-manager.js +0 -158
  507. package/dist/core/plans-manager.js.map +0 -1
  508. package/dist/core/prd-generator.d.ts +0 -48
  509. package/dist/core/prd-generator.d.ts.map +0 -1
  510. package/dist/core/prd-generator.js +0 -233
  511. package/dist/core/prd-generator.js.map +0 -1
  512. package/dist/core/ralph-manager.d.ts +0 -163
  513. package/dist/core/ralph-manager.d.ts.map +0 -1
  514. package/dist/core/ralph-manager.js +0 -555
  515. package/dist/core/ralph-manager.js.map +0 -1
  516. package/dist/core/ralph-parallel.d.ts +0 -55
  517. package/dist/core/ralph-parallel.d.ts.map +0 -1
  518. package/dist/core/ralph-parallel.js +0 -201
  519. package/dist/core/ralph-parallel.js.map +0 -1
  520. package/dist/core/ralph-plan-checkpoint.d.ts +0 -58
  521. package/dist/core/ralph-plan-checkpoint.d.ts.map +0 -1
  522. package/dist/core/ralph-plan-checkpoint.js +0 -154
  523. package/dist/core/ralph-plan-checkpoint.js.map +0 -1
  524. package/dist/core/ralph-scripts.d.ts +0 -12
  525. package/dist/core/ralph-scripts.d.ts.map +0 -1
  526. package/dist/core/ralph-scripts.js +0 -50
  527. package/dist/core/ralph-scripts.js.map +0 -1
  528. package/dist/core/review-manager.d.ts +0 -74
  529. package/dist/core/review-manager.d.ts.map +0 -1
  530. package/dist/core/review-manager.js +0 -371
  531. package/dist/core/review-manager.js.map +0 -1
  532. package/dist/core/rules-generator.d.ts +0 -73
  533. package/dist/core/rules-generator.d.ts.map +0 -1
  534. package/dist/core/rules-generator.js +0 -202
  535. package/dist/core/rules-generator.js.map +0 -1
  536. package/dist/core/skills-manager.d.ts +0 -126
  537. package/dist/core/skills-manager.d.ts.map +0 -1
  538. package/dist/core/skills-manager.js +0 -654
  539. package/dist/core/skills-manager.js.map +0 -1
  540. package/dist/core/state-writer.d.ts +0 -35
  541. package/dist/core/state-writer.d.ts.map +0 -1
  542. package/dist/core/state-writer.js +0 -81
  543. package/dist/core/state-writer.js.map +0 -1
  544. package/dist/core/task-manager.d.ts +0 -127
  545. package/dist/core/task-manager.d.ts.map +0 -1
  546. package/dist/core/task-manager.js +0 -607
  547. package/dist/core/task-manager.js.map +0 -1
  548. package/dist/core/telemetry.d.ts +0 -29
  549. package/dist/core/telemetry.d.ts.map +0 -1
  550. package/dist/core/telemetry.js +0 -57
  551. package/dist/core/telemetry.js.map +0 -1
  552. package/dist/core/validator.d.ts +0 -21
  553. package/dist/core/validator.d.ts.map +0 -1
  554. package/dist/core/validator.js +0 -177
  555. package/dist/core/validator.js.map +0 -1
  556. package/dist/core/version-bumper.d.ts +0 -19
  557. package/dist/core/version-bumper.d.ts.map +0 -1
  558. package/dist/core/version-bumper.js +0 -180
  559. package/dist/core/version-bumper.js.map +0 -1
  560. package/dist/core/watcher.d.ts +0 -9
  561. package/dist/core/watcher.d.ts.map +0 -1
  562. package/dist/core/watcher.js +0 -22
  563. package/dist/core/watcher.js.map +0 -1
  564. package/dist/core/workflow-generator.d.ts +0 -15
  565. package/dist/core/workflow-generator.d.ts.map +0 -1
  566. package/dist/core/workflow-generator.js +0 -391
  567. package/dist/core/workflow-generator.js.map +0 -1
  568. package/dist/hooks/terse-activate.d.ts +0 -59
  569. package/dist/hooks/terse-activate.d.ts.map +0 -1
  570. package/dist/hooks/terse-activate.js +0 -149
  571. package/dist/hooks/terse-activate.js.map +0 -1
  572. package/dist/hooks/terse-config.d.ts +0 -51
  573. package/dist/hooks/terse-config.d.ts.map +0 -1
  574. package/dist/hooks/terse-config.js +0 -130
  575. package/dist/hooks/terse-config.js.map +0 -1
  576. package/dist/hooks/terse-mode-tracker.d.ts +0 -78
  577. package/dist/hooks/terse-mode-tracker.d.ts.map +0 -1
  578. package/dist/hooks/terse-mode-tracker.js +0 -213
  579. package/dist/hooks/terse-mode-tracker.js.map +0 -1
  580. package/dist/memory/hnsw-index.d.ts +0 -68
  581. package/dist/memory/hnsw-index.d.ts.map +0 -1
  582. package/dist/memory/hnsw-index.js +0 -544
  583. package/dist/memory/hnsw-index.js.map +0 -1
  584. package/dist/memory/memory-cache.d.ts +0 -33
  585. package/dist/memory/memory-cache.d.ts.map +0 -1
  586. package/dist/memory/memory-cache.js +0 -85
  587. package/dist/memory/memory-cache.js.map +0 -1
  588. package/dist/memory/memory-search.d.ts +0 -42
  589. package/dist/memory/memory-search.d.ts.map +0 -1
  590. package/dist/memory/memory-search.js +0 -180
  591. package/dist/memory/memory-search.js.map +0 -1
  592. package/dist/memory/memory-store.d.ts +0 -84
  593. package/dist/memory/memory-store.d.ts.map +0 -1
  594. package/dist/memory/memory-store.js +0 -566
  595. package/dist/memory/memory-store.js.map +0 -1
  596. package/dist/memory/memory-vectorizer.d.ts +0 -29
  597. package/dist/memory/memory-vectorizer.d.ts.map +0 -1
  598. package/dist/memory/memory-vectorizer.js +0 -199
  599. package/dist/memory/memory-vectorizer.js.map +0 -1
@@ -1,1193 +0,0 @@
1
- import path from 'path';
2
- import { readFile, fileExists, writeFile, ensureDir } from '../utils/file-system.js';
3
- import { fileURLToPath } from 'url';
4
- import { dirname } from 'path';
5
- import { DecisionManager } from './decision-manager.js';
6
- import { KnowledgeManager } from './knowledge-manager.js';
7
- const __filename = fileURLToPath(import.meta.url);
8
- const __dirname = dirname(__filename);
9
- // Resolve templates directory (handles both dev and production)
10
- export function getTemplatesDir() {
11
- // In production (dist/), templates are at package root
12
- // In development (src/), templates are at package root
13
- // Both resolve to same location
14
- return path.join(__dirname, '..', '..', 'templates');
15
- }
16
- // Helper to read core template files (AGENT_AUTOMATION, DOCUMENTATION_RULES, QUALITY_ENFORCEMENT, RULEBOOK)
17
- async function generateCoreRules(name) {
18
- const templatesDir = path.join(getTemplatesDir(), 'core');
19
- const templatePath = path.join(templatesDir, `${name.toUpperCase()}.md`);
20
- if (await fileExists(templatePath)) {
21
- return await readFile(templatePath);
22
- }
23
- return `<!-- ${name.toUpperCase()}:START -->\n# ${name.charAt(0).toUpperCase() + name.slice(1)} Rules\n\nCore rules for ${name}.\n<!-- ${name.toUpperCase()}:END -->\n`;
24
- }
25
- export async function generateAgentsContent(config) {
26
- const sections = [];
27
- // Header comment
28
- sections.push('<!-- RULEBOOK:START -->');
29
- sections.push('# Project Rules');
30
- sections.push('');
31
- sections.push('Generated by @hivellm/rulebook');
32
- sections.push(`Generated at: ${new Date().toISOString()}`);
33
- sections.push('');
34
- const rulebookDir = config.rulebookDir || '.rulebook';
35
- // RULEBOOK.md has HIGHEST PRECEDENCE - must be first and most prominent
36
- sections.push('## ⚠️ CRITICAL: Task Management Rules (HIGHEST PRECEDENCE)');
37
- sections.push('');
38
- sections.push('**MANDATORY**: All task creation MUST follow Rulebook task management system.');
39
- sections.push('');
40
- sections.push(`**📋 ALWAYS reference \`/${rulebookDir}/specs/RULEBOOK.md\` FIRST before creating any tasks.**`);
41
- sections.push('');
42
- sections.push('**Rules from RULEBOOK.md take precedence over all other rules in this file.**');
43
- sections.push('');
44
- sections.push('**Key Requirements:**');
45
- sections.push('- ✅ Context7 MCP is REQUIRED for task creation');
46
- sections.push('- ✅ All tasks MUST follow Rulebook task format');
47
- sections.push('- ✅ Use `rulebook task create` to create tasks');
48
- sections.push('- ✅ Always validate task format before committing');
49
- sections.push('- ❌ NEVER create tasks without checking RULEBOOK.md format requirements');
50
- sections.push('');
51
- sections.push('### ⚠️ CRITICAL: Task File Structure Rules');
52
- sections.push('');
53
- sections.push('**MANDATORY**: When creating or updating tasks, you MUST follow the correct file structure:');
54
- sections.push('');
55
- sections.push('**✅ CORRECT File Structure:**');
56
- sections.push('- `proposal.md` - **Why** and **What Changes** (detailed explanations go here)');
57
- sections.push('- `tasks.md` - **ONLY checklist items** (simple `- [ ]` or `- [x]` format)');
58
- sections.push('- `specs/<module>/spec.md` - **Technical specifications** (SHALL/MUST requirements)');
59
- sections.push('- `design.md` - **Technical design decisions** (optional, for complex features)');
60
- sections.push('');
61
- sections.push('**❌ FORBIDDEN Practices:**');
62
- sections.push('- ❌ **NEVER** add long explanations or specifications in `tasks.md`');
63
- sections.push('- ❌ **NEVER** put technical details in `tasks.md` (use `specs/` instead)');
64
- sections.push('- ❌ **NEVER** create `README.md` or `README` files in task directories');
65
- sections.push('- ❌ **NEVER** create `PROCESS.md` or `PROCESS` files in task directories');
66
- sections.push('- ❌ **NEVER** create any file not listed in the correct structure above');
67
- sections.push('');
68
- sections.push('**What Goes Where:**');
69
- sections.push('');
70
- sections.push('1. **`proposal.md`** - Use for:');
71
- sections.push(' - Detailed "Why" explanations (minimum 20 characters)');
72
- sections.push(' - "What Changes" descriptions');
73
- sections.push(' - Impact analysis');
74
- sections.push(' - Business/technical rationale');
75
- sections.push('');
76
- sections.push('2. **`tasks.md`** - Use ONLY for:');
77
- sections.push(' - Simple checklist items: `- [ ] Task description`');
78
- sections.push(' - Status updates: `- [x] Completed task`');
79
- sections.push(' - Brief comments: `<!-- tested, coverage: 95% -->`');
80
- sections.push(' - **DO NOT** add long explanations, specifications, or technical details here');
81
- sections.push('');
82
- sections.push('3. **`specs/<module>/spec.md`** - Use for:');
83
- sections.push(' - Technical specifications with SHALL/MUST requirements');
84
- sections.push(' - Scenario definitions (Given/When/Then)');
85
- sections.push(' - Delta operations (ADDED/MODIFIED/REMOVED)');
86
- sections.push(' - All detailed technical requirements');
87
- sections.push('');
88
- sections.push('4. **`design.md`** - Use for (optional):');
89
- sections.push(' - Architecture decisions');
90
- sections.push(' - Technical design rationale');
91
- sections.push(' - Complex implementation details');
92
- sections.push('');
93
- sections.push('**Example of WRONG usage:**');
94
- sections.push('```markdown');
95
- sections.push('# tasks.md (WRONG - too much detail)');
96
- sections.push('');
97
- sections.push('## Implementation');
98
- sections.push('- [ ] Create authentication system');
99
- sections.push(' The system SHALL implement JWT-based authentication...');
100
- sections.push(' Users MUST be able to login with email and password...');
101
- sections.push(' The system MUST validate tokens...');
102
- sections.push('```');
103
- sections.push('');
104
- sections.push('**Example of CORRECT usage:**');
105
- sections.push('```markdown');
106
- sections.push('# tasks.md (CORRECT - simple checklist)');
107
- sections.push('');
108
- sections.push('## 1. Implementation Phase');
109
- sections.push('- [ ] 1.1 Create authentication module');
110
- sections.push('- [ ] 1.2 Add JWT token generation');
111
- sections.push('- [ ] 1.3 Implement password validation');
112
- sections.push('');
113
- sections.push('# specs/auth/spec.md (CORRECT - specifications here)');
114
- sections.push('');
115
- sections.push('## ADDED Requirements');
116
- sections.push('');
117
- sections.push('### Requirement: Authentication System');
118
- sections.push('The system SHALL implement JWT-based authentication.');
119
- sections.push('');
120
- sections.push('#### Scenario: User Login');
121
- sections.push('Given a user with valid credentials');
122
- sections.push('When the user submits login form');
123
- sections.push('Then the system MUST return a JWT token');
124
- sections.push('```');
125
- sections.push('');
126
- sections.push('**Remember:**');
127
- sections.push('- ✅ `tasks.md` = Simple checklist only');
128
- sections.push('- ✅ `proposal.md` = Why and what changes');
129
- sections.push('- ✅ `specs/` = Technical specifications');
130
- sections.push('- ❌ No README, PROCESS, or other files');
131
- sections.push('');
132
- sections.push(`**For complete task management guidelines, see: \`/${rulebookDir}/specs/RULEBOOK.md\`**`);
133
- sections.push('');
134
- sections.push('---');
135
- sections.push('');
136
- // Core rules summary (detailed rules in /rulebook/)
137
- sections.push('## Core Rules');
138
- sections.push('');
139
- sections.push('This project uses @hivellm/rulebook standards.');
140
- sections.push('');
141
- sections.push('**CRITICAL RULES:**');
142
- sections.push('1. **ALWAYS check `RULEBOOK.md` first** when creating tasks');
143
- sections.push(`2. Write tests first (${config.coverageThreshold}%+ coverage required)`);
144
- sections.push('3. Run quality checks before committing:');
145
- sections.push(' - Type check / Compiler check');
146
- sections.push(' - Linter (no warnings allowed)');
147
- sections.push(' - All tests (100% pass rate)');
148
- sections.push(' - Coverage check');
149
- sections.push('4. Update docs/ when implementing features');
150
- sections.push('5. Follow strict documentation structure');
151
- sections.push('6. **NEVER run destructive deletions (`rm -rf`) in this repository; when adding submodules always use `git submodule add`.**');
152
- sections.push('7. **Temporary files and scripts**:');
153
- sections.push(' - ✅ ALL scripts MUST be created in `/scripts` directory');
154
- sections.push(' - ✅ ALL temporary files (test, log, debug) MUST be in `/scripts`');
155
- sections.push(' - ✅ ALL temporary files MUST be removed immediately after use (MANDATORY)');
156
- sections.push(' - ❌ NEVER create temporary files in project root or outside `/scripts`');
157
- sections.push(' - ❌ NEVER leave temporary files after use - clean up before committing');
158
- sections.push('');
159
- sections.push('## Detailed Rules');
160
- sections.push('');
161
- sections.push(`For comprehensive rules, see the corresponding files in \`/${rulebookDir}/specs/\`:`);
162
- sections.push('');
163
- // TIER1_PROHIBITIONS is ALWAYS first (absolute highest precedence)
164
- sections.push(`- \`/${rulebookDir}/specs/TIER1_PROHIBITIONS.md\` - **Absolute prohibitions (HIGHEST PRECEDENCE — read first)**`);
165
- // RULEBOOK.md is second (task management)
166
- sections.push(`- \`/${rulebookDir}/specs/RULEBOOK.md\` - **Task management rules**`);
167
- // Only reference QUALITY_ENFORCEMENT if not in light mode
168
- if (!config.lightMode) {
169
- sections.push(`- \`/${rulebookDir}/specs/QUALITY_ENFORCEMENT.md\` - Quality enforcement rules`);
170
- }
171
- // Only reference GIT if enabled
172
- if (config.includeGitWorkflow) {
173
- sections.push(`- \`/${rulebookDir}/specs/GIT.md\` - Git workflow rules`);
174
- }
175
- // Token optimization reference
176
- if (!config.lightMode) {
177
- sections.push(`- \`/${rulebookDir}/specs/TOKEN_OPTIMIZATION.md\` - Model tier assignment and output verbosity rules`);
178
- }
179
- // Reference PLANS.md for session continuity
180
- sections.push(`- \`/${rulebookDir}/PLANS.md\` - **Session scratchpad** (read at session start for current task context)`);
181
- sections.push('');
182
- sections.push(`Language-specific rules are in \`/${rulebookDir}/specs/\`.`);
183
- sections.push(`Module-specific patterns are in \`/${rulebookDir}/specs/\`.`);
184
- sections.push('');
185
- sections.push('## Persistent Memory System');
186
- sections.push('');
187
- sections.push('This project uses a **persistent memory system** with hybrid BM25+vector search.');
188
- sections.push('Memory is **enabled by default** and persists across sessions for maintaining context and preserving learnings.');
189
- sections.push('');
190
- sections.push('**MANDATORY: You MUST actively use memory to preserve context and learnings.**');
191
- sections.push('');
192
- sections.push('**Status**: ✅ Enabled by default in `.rulebook` configuration');
193
- sections.push('');
194
- sections.push('### Key Features');
195
- sections.push('');
196
- sections.push('- **Rich Contextual Summaries**: Memories auto-extract summaries with key concepts, decisions, patterns, gotchas');
197
- sections.push('- **Hybrid Search**: BM25 keyword search + HNSW vector semantic search for relevant results');
198
- sections.push('- **3-Layer Search Pattern**: Compact results → Timeline context → Full details (token-efficient)');
199
- sections.push('- **Auto-Capture**: Implementation outputs from AI agents automatically captured');
200
- sections.push('- **Zero Native Dependencies**: Pure WASM + TypeScript, works on all platforms');
201
- sections.push('');
202
- sections.push('### When to Save to Memory');
203
- sections.push('');
204
- sections.push('Save to memory whenever you:');
205
- sections.push('- **Make an architectural decision** — why you chose one approach over another');
206
- sections.push('- **Fix a bug** — root cause and how it was resolved');
207
- sections.push('- **Discover something important** — codebase patterns, gotchas, constraints');
208
- sections.push('- **Implement a feature** — design approach, patterns discovered, edge cases handled');
209
- sections.push('- **Encounter an error** — root cause and solution for future reference');
210
- sections.push('- **Receive user preferences** — coding style, conventions, workflow preferences');
211
- sections.push('- **Complete a task or session** — summarize what was accomplished and learnings');
212
- sections.push('');
213
- sections.push('### How to Save Memory');
214
- sections.push('');
215
- sections.push('Save memories with rich context for better future searches:');
216
- sections.push('');
217
- sections.push('**Via MCP:**');
218
- sections.push('```');
219
- sections.push('rulebook_memory_save({');
220
- sections.push(' type: "feature|decision|bugfix|discovery|refactor|change|observation",');
221
- sections.push(' title: "Short title (≤80 chars)",');
222
- sections.push(' content: "Detailed explanation: what was done, why, key decisions, patterns, gotchas...",');
223
- sections.push(' tags: ["relevant", "tags"]');
224
- sections.push('})');
225
- sections.push('```');
226
- sections.push('');
227
- sections.push('**Via CLI:**');
228
- sections.push('```bash');
229
- sections.push('rulebook memory save "Detailed content here" --type feature --title "Brief Title" --tags tag1,tag2');
230
- sections.push('```');
231
- sections.push('');
232
- sections.push('**Summary Auto-Extraction**: Summaries are automatically extracted from content, capturing:');
233
- sections.push('- Key concepts and decisions');
234
- sections.push('- Design patterns discovered');
235
- sections.push('- Gotchas and edge cases');
236
- sections.push('- Problem/solution context');
237
- sections.push('');
238
- sections.push('### When and How to Search Memory');
239
- sections.push('');
240
- sections.push('**At the START of every session**, search memory for relevant context:');
241
- sections.push('');
242
- sections.push('**Via MCP (3-Layer Search - token efficient):**');
243
- sections.push('```');
244
- sections.push('Layer 1 - Compact search: rulebook_memory_search({ query: "your topic", mode: "hybrid", limit: 10 })');
245
- sections.push(' → Returns: id, title, type, score, summary (compact results)');
246
- sections.push('Layer 2 - Timeline: rulebook_memory_timeline({ memoryId: "abc-123", window: 5 })');
247
- sections.push(' → Returns: 5 before/after chronologically');
248
- sections.push('Layer 3 - Full details: rulebook_memory_get({ ids: ["abc-123"] })');
249
- sections.push(' → Returns: complete memory objects');
250
- sections.push('```');
251
- sections.push('');
252
- sections.push('**Via CLI:**');
253
- sections.push('```bash');
254
- sections.push('rulebook memory search "authentication" --mode hybrid # Keyword + semantic');
255
- sections.push('rulebook memory search "oauth" --type feature # Filter by memory type');
256
- sections.push('rulebook memory list --limit 10 # Recent memories');
257
- sections.push('```');
258
- sections.push('');
259
- sections.push('Also search when:');
260
- sections.push("- Working on code you've touched before");
261
- sections.push('- The user references a past discussion or decision');
262
- sections.push('- You need context about why something was done a certain way');
263
- sections.push('- **Before implementing similar features** — find past patterns and gotchas');
264
- sections.push('');
265
- sections.push('### Session Workflow');
266
- sections.push('');
267
- sections.push('**Complete memory-enhanced workflow:**');
268
- sections.push('1. **Start of session**: Search memory for relevant past context');
269
- sections.push('2. **During work**: Save discoveries, patterns, decisions as they happen');
270
- sections.push('3. **After feature**: Save complete implementation with summaries');
271
- sections.push('4. **End of session**: Save session summary for future sessions');
272
- sections.push('');
273
- sections.push('### Session Summary');
274
- sections.push('');
275
- sections.push('Before ending a session or when context is getting long, save a summary:');
276
- sections.push('```');
277
- sections.push('type: observation');
278
- sections.push('title: "Session summary: <date or topic>"');
279
- sections.push('content: "Accomplished: ... | Pending: ... | Key decisions: ..."');
280
- sections.push('```');
281
- sections.push('');
282
- sections.push('When in doubt, ask to review @AGENTS.md first.');
283
- sections.push('');
284
- sections.push('## Ralph Autonomous Loop');
285
- sections.push('');
286
- sections.push('This project is **enabled for Ralph autonomous loop** for iterative feature implementation.');
287
- sections.push('Ralph automates multi-iteration development with fresh AI context per iteration, persisting learnings via git and progress logs.');
288
- sections.push('');
289
- sections.push('**Status**: ✅ Enabled by default in `.rulebook` configuration');
290
- sections.push('');
291
- sections.push('### Quick Start');
292
- sections.push('');
293
- sections.push('```bash');
294
- sections.push('# 1. Create tasks');
295
- sections.push('rulebook task create <task-id>');
296
- sections.push('');
297
- sections.push('# 2. Initialize Ralph');
298
- sections.push('rulebook ralph init');
299
- sections.push('');
300
- sections.push('# 3. Run autonomous loop');
301
- sections.push('rulebook ralph run --max-iterations 10');
302
- sections.push('');
303
- sections.push('# 4. Monitor progress');
304
- sections.push('rulebook ralph status');
305
- sections.push('rulebook ralph history');
306
- sections.push('```');
307
- sections.push('');
308
- sections.push('### Key Commands');
309
- sections.push('');
310
- sections.push('- `rulebook ralph init` — Initialize Ralph configuration and create PRD from tasks');
311
- sections.push('- `rulebook ralph run [--max-iterations N] [--tool claude|amp]` — Execute autonomous loop');
312
- sections.push('- `rulebook ralph status` — Show loop progress and current iteration');
313
- sections.push('- `rulebook ralph history` — Display iteration history and learnings');
314
- sections.push('- `rulebook ralph pause` — Gracefully pause autonomous loop');
315
- sections.push('- `rulebook ralph resume` — Resume from paused state');
316
- sections.push('');
317
- sections.push('For detailed Ralph documentation, see `templates/skills/workflows/ralph/SKILL.md`');
318
- sections.push('');
319
- // Decision Records section — inject active ADRs if any exist
320
- try {
321
- const projectRoot = config.rulebookDir ? process.cwd() : process.cwd();
322
- const dm = new DecisionManager(projectRoot, config.rulebookDir || '.rulebook');
323
- const decisionContent = await dm.getForGenerator();
324
- if (decisionContent) {
325
- sections.push(decisionContent);
326
- }
327
- }
328
- catch {
329
- // No decisions directory yet — skip silently
330
- }
331
- // Project Knowledge section — inject patterns/anti-patterns if any exist
332
- try {
333
- const projectRoot = config.rulebookDir ? process.cwd() : process.cwd();
334
- const km = new KnowledgeManager(projectRoot, config.rulebookDir || '.rulebook');
335
- const knowledgeContent = await km.getForGenerator();
336
- if (knowledgeContent) {
337
- sections.push(knowledgeContent);
338
- }
339
- }
340
- catch {
341
- // No knowledge directory yet — skip silently
342
- }
343
- sections.push('<!-- RULEBOOK:END -->');
344
- return sections.join('\n');
345
- }
346
- export async function generateLanguageRules(language) {
347
- const templatesDir = path.join(getTemplatesDir(), 'languages');
348
- const templatePath = path.join(templatesDir, `${language.toUpperCase()}.md`);
349
- if (await fileExists(templatePath)) {
350
- return await readFile(templatePath);
351
- }
352
- return `<!-- ${language.toUpperCase()}:START -->\n# ${language.charAt(0).toUpperCase() + language.slice(1)} Rules\n\nLanguage-specific rules for ${language}.\n<!-- ${language.toUpperCase()}:END -->\n`;
353
- }
354
- export async function generateFrameworkRules(framework) {
355
- const templatesDir = path.join(getTemplatesDir(), 'frameworks');
356
- const templatePath = path.join(templatesDir, `${framework.toUpperCase()}.md`);
357
- if (await fileExists(templatePath)) {
358
- return await readFile(templatePath);
359
- }
360
- const title = framework.charAt(0).toUpperCase() + framework.slice(1);
361
- return `<!-- ${framework.toUpperCase()}:START -->
362
- # ${title} Framework Rules
363
-
364
- Framework-specific rules for ${title}.
365
- <!-- ${framework.toUpperCase()}:END -->
366
- `;
367
- }
368
- export async function generateModuleRules(module) {
369
- const templatesDir = path.join(getTemplatesDir(), 'modules');
370
- // Try UPPERCASE.md first, then kebab-case.md (e.g. sequential_thinking → sequential-thinking.md)
371
- const candidates = [
372
- path.join(templatesDir, `${module.toUpperCase()}.md`),
373
- path.join(templatesDir, `${module.toLowerCase().replace(/_/g, '-')}.md`),
374
- ];
375
- for (const templatePath of candidates) {
376
- if (await fileExists(templatePath)) {
377
- return await readFile(templatePath);
378
- }
379
- }
380
- return `<!-- ${module.toUpperCase()}:START -->\n# ${module.charAt(0).toUpperCase() + module.slice(1)} Instructions\n\nModule-specific instructions for ${module}.\n<!-- ${module.toUpperCase()}:END -->\n`;
381
- }
382
- export async function generateServiceRules(service) {
383
- const templatesDir = path.join(getTemplatesDir(), 'services');
384
- // Convert service name to template filename (e.g., 'azure_blob' -> 'AZURE_BLOB.md')
385
- const serviceName = service.toUpperCase().replace(/-/g, '_');
386
- const templatePath = path.join(templatesDir, `${serviceName}.md`);
387
- if (await fileExists(templatePath)) {
388
- return await readFile(templatePath);
389
- }
390
- const serviceTitle = service
391
- .split(/[-_]/)
392
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
393
- .join(' ');
394
- return `<!-- ${serviceName}:START -->\n# ${serviceTitle} Instructions\n\nService-specific instructions for ${serviceTitle}.\n<!-- ${serviceName}:END -->\n`;
395
- }
396
- export async function generateGitRules(pushMode) {
397
- const templatesDir = path.join(getTemplatesDir(), 'git');
398
- const templatePath = path.join(templatesDir, 'GIT_WORKFLOW.md');
399
- let gitRules = '';
400
- if (await fileExists(templatePath)) {
401
- gitRules = await readFile(templatePath);
402
- }
403
- else {
404
- gitRules = `<!-- GIT:START -->\n# Git Workflow Rules\n\nGit workflow guidelines for this project.\n<!-- GIT:END -->\n`;
405
- }
406
- // Add push mode configuration
407
- const pushModeConfig = `\n**AI Assistant Git Push Mode**: ${pushMode.toUpperCase()}\n\n`;
408
- const pushModeInstructions = {
409
- manual: `**CRITICAL**: Never execute \`git push\` commands automatically.
410
- Always provide push commands for manual execution by the user.
411
-
412
- Example:
413
- \`\`\`
414
- ✋ MANUAL ACTION REQUIRED:
415
- Run these commands manually (SSH password may be required):
416
- git push origin main
417
- git push origin v1.0.0
418
- \`\`\``,
419
- prompt: `**CRITICAL**: Always ask user permission before pushing.
420
-
421
- Example:
422
- \`\`\`
423
- Ready to push changes. Execute these commands?
424
- git push origin main
425
-
426
- [Y/n]:
427
- \`\`\``,
428
- auto: `**INFO**: Automatic push enabled.
429
- AI assistants may execute push commands automatically.
430
-
431
- ⚠️ Only use this mode if:
432
- - SSH key has no password
433
- - GitHub CLI is authenticated
434
- - You trust the AI assistant completely`,
435
- };
436
- // Insert push mode config after <!-- GIT:START -->
437
- gitRules = gitRules.replace('<!-- GIT:START -->', `<!-- GIT:START -->\n${pushModeConfig}${pushModeInstructions[pushMode]}\n`);
438
- return gitRules;
439
- }
440
- /**
441
- * Write modular directive file to /rulebook/ directory
442
- * Adds header and footer comments for consistency
443
- */
444
- async function writeModularFile(projectRoot, fileName, content, rulebookDir = '.rulebook') {
445
- const specsPath = path.join(projectRoot, rulebookDir, 'specs');
446
- await ensureDir(specsPath);
447
- const filePath = path.join(specsPath, `${fileName}.md`);
448
- // Add header comment if not already present
449
- const headerComment = `<!-- ${fileName}:START -->\n`;
450
- const footerComment = `\n<!-- ${fileName}:END -->`;
451
- let finalContent = content.trim();
452
- // Add header if not present
453
- if (!finalContent.startsWith(headerComment.trim())) {
454
- finalContent = headerComment + finalContent;
455
- }
456
- // Add footer if not present
457
- if (!finalContent.endsWith(footerComment.trim())) {
458
- finalContent = finalContent + footerComment;
459
- }
460
- await writeFile(filePath, finalContent);
461
- }
462
- /**
463
- * Generate reference section for AGENTS.md
464
- */
465
- function generateReferenceSection(name, fileName, description, quickRef, rulebookDir = '.rulebook') {
466
- const sections = [];
467
- sections.push(`### ${name}`);
468
- sections.push('');
469
- sections.push(`For comprehensive ${description}, see \`/${rulebookDir}/specs/${fileName}.md\``);
470
- sections.push('');
471
- sections.push('Quick reference:');
472
- for (const item of quickRef) {
473
- sections.push(`- ${item}`);
474
- }
475
- sections.push('');
476
- return sections.join('\n');
477
- }
478
- /**
479
- * Generate language reference for AGENTS.md
480
- */
481
- function generateLanguageReference(language, rulebookDir = '.rulebook') {
482
- const languageName = language.charAt(0).toUpperCase() + language.slice(1);
483
- const quickRef = [
484
- 'Type safety and strict mode',
485
- 'Code quality standards',
486
- 'Testing requirements (95%+ coverage)',
487
- 'Package management',
488
- 'Error handling patterns',
489
- ];
490
- return generateReferenceSection(`${languageName} Development Rules`, language.toUpperCase(), `${languageName}-specific guidelines`, quickRef, rulebookDir);
491
- }
492
- /**
493
- * Generate framework reference for AGENTS.md
494
- */
495
- function generateFrameworkReference(framework, rulebookDir = '.rulebook') {
496
- const frameworkName = framework.charAt(0).toUpperCase() + framework.slice(1);
497
- const quickRef = [
498
- 'Framework-specific patterns',
499
- 'Component structure',
500
- 'Best practices',
501
- 'Testing conventions',
502
- ];
503
- return generateReferenceSection(`${frameworkName} Framework Rules`, framework.toUpperCase(), `${frameworkName}-specific guidelines`, quickRef, rulebookDir);
504
- }
505
- /**
506
- * Generate module reference for AGENTS.md
507
- */
508
- function generateModuleReference(module, rulebookDir = '.rulebook') {
509
- const moduleName = module.charAt(0).toUpperCase() + module.slice(1).replace(/_/g, ' ');
510
- const quickRef = ['Module-specific instructions', 'Usage guidelines', 'Integration patterns'];
511
- return generateReferenceSection(`${moduleName} Instructions`, module.toUpperCase(), `${moduleName}-specific instructions`, quickRef, rulebookDir);
512
- }
513
- /**
514
- * Generate service reference for AGENTS.md
515
- */
516
- function generateServiceReference(service, rulebookDir = '.rulebook') {
517
- const serviceName = service
518
- .split(/[-_]/)
519
- .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
520
- .join(' ');
521
- const serviceId = service.toUpperCase().replace(/-/g, '_');
522
- const quickRef = ['Connection setup', 'Basic operations', 'Best practices', 'Configuration'];
523
- return generateReferenceSection(`${serviceName} Instructions`, serviceId, `${serviceName}-specific instructions`, quickRef, rulebookDir);
524
- }
525
- /**
526
- * Load project configuration from .rulebook file
527
- */
528
- async function loadProjectConfigFromRulebook(projectRoot = process.cwd()) {
529
- const { createConfigManager } = await import('./config-manager.js');
530
- const configManager = createConfigManager(projectRoot);
531
- try {
532
- const rulebookConfig = await configManager.loadConfig();
533
- // Map RulebookConfig to ProjectConfig
534
- const projectConfig = {
535
- languages: rulebookConfig.languages || [],
536
- frameworks: rulebookConfig.frameworks || [],
537
- modules: rulebookConfig.modules || [],
538
- services: rulebookConfig.services || [],
539
- modular: rulebookConfig.modular !== false, // Default to true
540
- rulebookDir: rulebookConfig.rulebookDir || '.rulebook',
541
- };
542
- return projectConfig;
543
- }
544
- catch {
545
- // If .rulebook doesn't exist or can't be read, return empty config
546
- return {};
547
- }
548
- }
549
- const AGENT_REGISTRY = [
550
- // Core agents
551
- {
552
- task: 'Implementation',
553
- agent: 'implementer',
554
- model: 'sonnet',
555
- when: 'Writing new code or modifying existing',
556
- },
557
- {
558
- task: 'Research',
559
- agent: 'researcher',
560
- model: 'haiku',
561
- when: 'Exploring codebase, finding patterns',
562
- },
563
- {
564
- task: 'Testing',
565
- agent: 'tester',
566
- model: 'sonnet',
567
- when: 'Writing and running tests',
568
- },
569
- {
570
- task: 'Documentation',
571
- agent: 'docs-writer',
572
- model: 'haiku',
573
- when: 'README, docs, changelogs',
574
- },
575
- {
576
- task: 'Code Review',
577
- agent: 'code-reviewer',
578
- model: 'sonnet',
579
- when: 'Reviewing implementations for quality',
580
- },
581
- {
582
- task: 'Build/CI',
583
- agent: 'build-engineer',
584
- model: 'sonnet',
585
- when: 'Build failures, CI, dependencies',
586
- },
587
- {
588
- task: 'Security',
589
- agent: 'security-reviewer',
590
- model: 'haiku',
591
- when: 'Dependency audit, vulnerability review',
592
- },
593
- // Specialist agents
594
- {
595
- task: 'Architecture',
596
- agent: 'architect',
597
- model: 'opus',
598
- when: 'System design, ADRs, scalability decisions',
599
- },
600
- {
601
- task: 'API Design',
602
- agent: 'api-designer',
603
- model: 'sonnet',
604
- when: 'REST/GraphQL endpoints, OpenAPI specs',
605
- },
606
- {
607
- task: 'Database',
608
- agent: 'database-architect',
609
- model: 'sonnet',
610
- when: 'Schema design, migrations, query optimization',
611
- },
612
- {
613
- task: 'DevOps',
614
- agent: 'devops-engineer',
615
- model: 'sonnet',
616
- when: 'CI/CD, Docker, Kubernetes, infrastructure',
617
- },
618
- {
619
- task: 'Performance',
620
- agent: 'performance-engineer',
621
- model: 'sonnet',
622
- when: 'Profiling, benchmarks, optimization',
623
- },
624
- {
625
- task: 'Refactoring',
626
- agent: 'refactoring-agent',
627
- model: 'sonnet',
628
- when: 'Code smells, complexity reduction, cleanup',
629
- },
630
- {
631
- task: 'Migration',
632
- agent: 'migration-engineer',
633
- model: 'sonnet',
634
- when: 'DB migrations, API migrations, upgrades',
635
- },
636
- {
637
- task: 'Accessibility',
638
- agent: 'accessibility-reviewer',
639
- model: 'haiku',
640
- when: 'WCAG compliance, ARIA, screen readers',
641
- },
642
- {
643
- task: 'i18n',
644
- agent: 'i18n-engineer',
645
- model: 'haiku',
646
- when: 'Internationalization, localization, RTL',
647
- },
648
- {
649
- task: 'UX Review',
650
- agent: 'ux-reviewer',
651
- model: 'haiku',
652
- when: 'Usability, interaction patterns, error states',
653
- },
654
- // Orchestration
655
- {
656
- task: 'Orchestration',
657
- agent: 'team-lead',
658
- model: 'opus',
659
- when: 'Multi-agent coordination for complex tasks',
660
- },
661
- ];
662
- /**
663
- * Generate the agent delegation section for AGENTS.md.
664
- * Adapts table based on detected languages and frameworks.
665
- */
666
- export function generateDelegationSection(config) {
667
- const lines = [];
668
- const primaryLang = config.languages?.[0] || 'the project language';
669
- const primaryFramework = config.frameworks?.[0] || '';
670
- lines.push('## Agent Delegation');
671
- lines.push('');
672
- lines.push('Delegate work to specialist agents instead of doing everything in the main conversation. Each agent uses a cost-appropriate model.');
673
- lines.push('');
674
- lines.push('| Task | Agent | Model | When to use |');
675
- lines.push('|------|-------|-------|-------------|');
676
- for (const entry of AGENT_REGISTRY) {
677
- lines.push(`| ${entry.task} | ${entry.agent} | ${entry.model} | ${entry.when} |`);
678
- }
679
- lines.push('');
680
- lines.push('### Delegation Rules');
681
- lines.push('');
682
- lines.push('1. **Never write code directly in the main conversation** — delegate to the appropriate agent');
683
- lines.push('2. **After implementing code**, launch tester + docs-writer in parallel to update tests and documentation');
684
- lines.push('3. **The main conversation** serves for planning, coordination, and user communication only');
685
- lines.push('4. **Use haiku agents** (researcher, docs-writer, security-reviewer) for read-only tasks — they are significantly cheaper');
686
- lines.push('5. **Launch independent agents in parallel** when possible to maximize throughput');
687
- lines.push('');
688
- lines.push(`> **Project context**: Primary language is **${primaryLang}**${primaryFramework ? ` with **${primaryFramework}**` : ''}. Agents are pre-configured with this context.`);
689
- lines.push('');
690
- return lines.join('\n');
691
- }
692
- /**
693
- * Resolve placeholder values from project config.
694
- */
695
- export function resolveAgentPlaceholders(config) {
696
- const primaryLang = config.languages?.[0] || 'TypeScript';
697
- const primaryFramework = config.frameworks?.[0] || '';
698
- // Map language to common test framework
699
- const testFrameworkMap = {
700
- typescript: 'vitest',
701
- javascript: 'jest',
702
- python: 'pytest',
703
- rust: 'cargo test',
704
- go: 'go test',
705
- java: 'JUnit',
706
- csharp: 'xUnit',
707
- ruby: 'RSpec',
708
- php: 'PHPUnit',
709
- swift: 'XCTest',
710
- kotlin: 'JUnit',
711
- dart: 'flutter test',
712
- elixir: 'ExUnit',
713
- scala: 'ScalaTest',
714
- };
715
- // Map language to file naming convention
716
- const fileNamingMap = {
717
- typescript: 'kebab-case',
718
- javascript: 'kebab-case',
719
- python: 'snake_case',
720
- rust: 'snake_case',
721
- go: 'snake_case',
722
- java: 'PascalCase',
723
- csharp: 'PascalCase',
724
- ruby: 'snake_case',
725
- php: 'PascalCase',
726
- swift: 'PascalCase',
727
- kotlin: 'PascalCase',
728
- dart: 'snake_case',
729
- elixir: 'snake_case',
730
- scala: 'PascalCase',
731
- };
732
- const langKey = primaryLang.toLowerCase();
733
- return {
734
- '{{language}}': primaryLang,
735
- '{{framework}}': primaryFramework || 'none',
736
- '{{test_framework}}': testFrameworkMap[langKey] || 'the project test framework',
737
- '{{file_naming}}': fileNamingMap[langKey] || 'kebab-case',
738
- };
739
- }
740
- /**
741
- * Substitute placeholders in agent template content.
742
- */
743
- export function substituteAgentPlaceholders(content, placeholders) {
744
- let result = content;
745
- for (const [key, value] of Object.entries(placeholders)) {
746
- result = result.replaceAll(key, value);
747
- }
748
- return result;
749
- }
750
- /**
751
- * Install agent definitions to .claude/agents/ with placeholder substitution.
752
- */
753
- async function installAgentsWithPlaceholders(projectRoot, config) {
754
- const agentsDir = path.join(getTemplatesDir(), 'agents');
755
- const targetDir = path.join(projectRoot, '.claude', 'agents');
756
- if (!(await fileExists(agentsDir)))
757
- return;
758
- await ensureDir(targetDir);
759
- const placeholders = resolveAgentPlaceholders(config);
760
- const { readdirSync } = await import('fs');
761
- const files = readdirSync(agentsDir).filter((f) => f.endsWith('.md'));
762
- for (const file of files) {
763
- const content = await readFile(path.join(agentsDir, file));
764
- const substituted = substituteAgentPlaceholders(content, placeholders);
765
- await writeFile(path.join(targetDir, file), substituted);
766
- }
767
- }
768
- /**
769
- * Names of `core/` skills that are user-invocable (slash-command or
770
- * natural-language trigger), so their SKILL.md files must land in
771
- * `.claude/skills/` alongside the `dev/` skills. Non-invocable core
772
- * skills (agent-automation, dag, documentation-rules, quality-enforcement,
773
- * rulebook) stay referenced via AGENTS.md only.
774
- */
775
- export const INVOCABLE_CORE_SKILLS = [
776
- 'rulebook-terse',
777
- 'rulebook-terse-commit',
778
- 'rulebook-terse-review',
779
- 'karpathy-guidelines',
780
- ];
781
- /**
782
- * Copy every SKILL.md under a source directory into .claude/skills/.
783
- * Used for both the full `dev/` category and a curated subset of `core/`
784
- * skills (see INVOCABLE_CORE_SKILLS).
785
- *
786
- * Exported for test coverage of the install pipeline.
787
- */
788
- export async function installSkillsFromSource(sourceDir, targetSkillsDir, filter) {
789
- const { readdirSync, statSync } = await import('fs');
790
- if (!(await fileExists(sourceDir)))
791
- return;
792
- await ensureDir(targetSkillsDir);
793
- const entries = readdirSync(sourceDir);
794
- for (const entry of entries) {
795
- if (filter && !filter.includes(entry))
796
- continue;
797
- const entryPath = path.join(sourceDir, entry);
798
- if (!statSync(entryPath).isDirectory())
799
- continue;
800
- const skillFile = path.join(entryPath, 'SKILL.md');
801
- if (!(await fileExists(skillFile)))
802
- continue;
803
- const targetSkillDir = path.join(targetSkillsDir, entry);
804
- await ensureDir(targetSkillDir);
805
- const content = await readFile(skillFile);
806
- await writeFile(path.join(targetSkillDir, 'SKILL.md'), content);
807
- }
808
- }
809
- /**
810
- * Install dev skills + invocable core skills to .claude/skills/ (modern
811
- * Claude Code skills format). Each skill is a directory with a SKILL.md
812
- * file. Always installed on init/update — useful for any project.
813
- */
814
- async function installDevSkillsFromTemplates(projectRoot) {
815
- const skillsTargetDir = path.join(projectRoot, '.claude', 'skills');
816
- const templatesRoot = getTemplatesDir();
817
- await installSkillsFromSource(path.join(templatesRoot, 'skills', 'dev'), skillsTargetDir);
818
- await installSkillsFromSource(path.join(templatesRoot, 'skills', 'core'), skillsTargetDir, INVOCABLE_CORE_SKILLS);
819
- }
820
- /**
821
- * Generate modular AGENTS.md with references
822
- */
823
- export async function generateModularAgents(config, projectRoot = process.cwd()) {
824
- // Load saved configuration from .rulebook and merge with provided config
825
- const savedConfig = await loadProjectConfigFromRulebook(projectRoot);
826
- // Merge: saved config takes precedence for languages/frameworks/modules/services
827
- // provided config takes precedence for other settings (like rulebookDir when explicitly set)
828
- const mergedConfig = {
829
- ...config,
830
- languages: savedConfig.languages?.length ? savedConfig.languages : config.languages,
831
- frameworks: savedConfig.frameworks?.length ? savedConfig.frameworks : config.frameworks || [],
832
- modules: savedConfig.modules?.length ? savedConfig.modules : config.modules,
833
- services: savedConfig.services?.length ? savedConfig.services : config.services || [],
834
- modular: savedConfig.modular !== undefined ? savedConfig.modular : config.modular !== false,
835
- // rulebookDir: provided config takes precedence if explicitly set, otherwise use saved or default
836
- rulebookDir: config.rulebookDir || savedConfig.rulebookDir || '.rulebook',
837
- };
838
- const rulebookDir = mergedConfig.rulebookDir || '.rulebook';
839
- const sections = [];
840
- // Add Rulebook section (core rules stay embedded - simplified)
841
- sections.push(await generateAgentsContent(mergedConfig));
842
- sections.push('');
843
- // Write RULEBOOK.md to /rulebook/ (ALWAYS included - highest precedence)
844
- const rulebookContent = await generateCoreRules('RULEBOOK');
845
- await writeModularFile(projectRoot, 'RULEBOOK', rulebookContent.trim(), rulebookDir);
846
- // Write QUALITY_ENFORCEMENT to /rulebook/ (always included unless light mode)
847
- if (!mergedConfig.lightMode) {
848
- const enforcementContent = await generateCoreRules('QUALITY_ENFORCEMENT');
849
- await writeModularFile(projectRoot, 'QUALITY_ENFORCEMENT', enforcementContent.trim(), rulebookDir);
850
- }
851
- // Write TIER1_PROHIBITIONS to /rulebook/ (always included — highest precedence directives)
852
- const tier1Content = await generateCoreRules('TIER1_PROHIBITIONS');
853
- if (tier1Content.trim()) {
854
- await writeModularFile(projectRoot, 'TIER1_PROHIBITIONS', tier1Content.trim(), rulebookDir);
855
- }
856
- // Write TOKEN_OPTIMIZATION to /rulebook/ (always included unless light mode)
857
- if (!mergedConfig.lightMode) {
858
- const tokenOptContent = await generateCoreRules('TOKEN_OPTIMIZATION');
859
- if (tokenOptContent.trim()) {
860
- await writeModularFile(projectRoot, 'TOKEN_OPTIMIZATION', tokenOptContent.trim(), rulebookDir);
861
- }
862
- }
863
- // Write Git workflow rules to /.rulebook/specs/GIT.md
864
- if (mergedConfig.includeGitWorkflow) {
865
- const gitRules = await generateGitRules(mergedConfig.gitPushMode || 'manual');
866
- await writeModularFile(projectRoot, 'GIT', gitRules.trim(), rulebookDir);
867
- }
868
- // If WORKSPACE.md spec exists, add reference in AGENTS.md
869
- {
870
- const { existsSync } = await import('fs');
871
- const wsSpecPath = path.join(projectRoot, rulebookDir, 'specs', 'WORKSPACE.md');
872
- if (existsSync(wsSpecPath)) {
873
- sections.push('## Workspace Mode');
874
- sections.push('');
875
- sections.push(`**This project is part of a multi-project workspace.** All MCP tool calls MUST include the correct \`projectId\` parameter.`);
876
- sections.push('');
877
- sections.push(`**📋 ALWAYS read \`/${rulebookDir}/specs/WORKSPACE.md\` to understand project routing before using any Rulebook MCP tools.**`);
878
- sections.push('');
879
- }
880
- }
881
- // Write language files and add references
882
- if (mergedConfig.languages.length > 0) {
883
- sections.push('## Language-Specific Rules');
884
- sections.push('');
885
- sections.push(`The following languages are configured for this project. For detailed rules, see the corresponding files in \`/${rulebookDir}/specs/\`:`);
886
- sections.push('');
887
- // Write all language files first
888
- for (const language of mergedConfig.languages) {
889
- const langRules = await generateLanguageRules(language);
890
- await writeModularFile(projectRoot, language.toUpperCase(), langRules, rulebookDir);
891
- }
892
- // Then add all references together
893
- for (const language of mergedConfig.languages) {
894
- sections.push(generateLanguageReference(language, rulebookDir));
895
- }
896
- sections.push(`**Usage**: When working with language-specific code, reference the corresponding \`/${rulebookDir}/specs/[LANGUAGE].md\` file for detailed guidelines.`);
897
- sections.push('');
898
- }
899
- // Write framework files and add references
900
- if (mergedConfig.frameworks && mergedConfig.frameworks.length > 0) {
901
- sections.push('## Framework-Specific Rules');
902
- sections.push('');
903
- sections.push(`The following frameworks are configured for this project. For detailed rules, see the corresponding files in \`/${rulebookDir}/specs/\`:`);
904
- sections.push('');
905
- // Write all framework files first
906
- for (const framework of mergedConfig.frameworks) {
907
- const frameworkRules = await generateFrameworkRules(framework);
908
- await writeModularFile(projectRoot, framework.toUpperCase(), frameworkRules, rulebookDir);
909
- }
910
- // Then add all references together
911
- for (const framework of mergedConfig.frameworks) {
912
- sections.push(generateFrameworkReference(framework, rulebookDir));
913
- }
914
- sections.push('');
915
- sections.push(`**Usage**: When working with framework-specific code, reference the corresponding \`/${rulebookDir}/specs/[FRAMEWORK].md\` file for detailed guidelines.`);
916
- sections.push('');
917
- }
918
- // Write module files and add references
919
- // First, write AGENT_AUTOMATION if not minimal (core file, not module)
920
- if (!mergedConfig.minimal) {
921
- const agentAutomation = await generateCoreRules('AGENT_AUTOMATION');
922
- await writeModularFile(projectRoot, 'AGENT_AUTOMATION', agentAutomation, rulebookDir);
923
- }
924
- // Write MULTI_AGENT directives (after AGENT_AUTOMATION)
925
- if (!mergedConfig.minimal) {
926
- const multiAgentContent = await generateCoreRules('MULTI_AGENT');
927
- await writeModularFile(projectRoot, 'MULTI_AGENT', multiAgentContent, rulebookDir);
928
- }
929
- // Then handle all modules together
930
- const allModules = [];
931
- if (!mergedConfig.minimal) {
932
- allModules.push('agent_automation');
933
- allModules.push('multi_agent');
934
- }
935
- allModules.push(...mergedConfig.modules);
936
- if (allModules.length > 0) {
937
- sections.push('## Module-Specific Instructions');
938
- sections.push('');
939
- sections.push(`The following modules are configured for this project. For detailed instructions, see the corresponding files in \`/${rulebookDir}/specs/\`:`);
940
- sections.push('');
941
- // Write all module files first (except AGENT_AUTOMATION which is already written)
942
- for (const module of mergedConfig.modules) {
943
- const moduleRules = await generateModuleRules(module);
944
- await writeModularFile(projectRoot, module.toUpperCase(), moduleRules, rulebookDir);
945
- }
946
- // Then add all references together
947
- if (!mergedConfig.minimal) {
948
- sections.push(generateModuleReference('agent_automation', rulebookDir));
949
- sections.push(generateModuleReference('multi_agent', rulebookDir));
950
- }
951
- for (const module of mergedConfig.modules) {
952
- sections.push(generateModuleReference(module, rulebookDir));
953
- }
954
- sections.push(`**Usage**: When working with module-specific features, reference the corresponding \`/${rulebookDir}/specs/[MODULE].md\` file for detailed instructions.`);
955
- sections.push('');
956
- }
957
- // Write service files and add references
958
- if (mergedConfig.services && mergedConfig.services.length > 0) {
959
- sections.push('## Service-Specific Instructions');
960
- sections.push('');
961
- sections.push(`The following services are configured for this project. For detailed instructions, see the corresponding files in \`/${rulebookDir}/specs/\`:`);
962
- sections.push('');
963
- // Write all service files first
964
- for (const service of mergedConfig.services) {
965
- const serviceRules = await generateServiceRules(service);
966
- const serviceId = service.toUpperCase().replace(/-/g, '_');
967
- await writeModularFile(projectRoot, serviceId, serviceRules, rulebookDir);
968
- }
969
- // Then add all references together
970
- for (const service of mergedConfig.services) {
971
- sections.push(generateServiceReference(service, rulebookDir));
972
- }
973
- sections.push(`**Usage**: When working with service-specific features, reference the corresponding \`/${rulebookDir}/specs/[SERVICE].md\` file for detailed instructions.`);
974
- sections.push('');
975
- }
976
- // Add enabled skills section (v2.0)
977
- try {
978
- const { SkillsManager, getDefaultTemplatesPath } = await import('./skills-manager.js');
979
- const { createConfigManager } = await import('./config-manager.js');
980
- const configManager = createConfigManager(projectRoot);
981
- const rulebookConfig = await configManager.loadConfig();
982
- if (rulebookConfig.skills?.enabled && rulebookConfig.skills.enabled.length > 0) {
983
- const skillsManager = new SkillsManager(getDefaultTemplatesPath(), projectRoot);
984
- const enabledSkills = await skillsManager.getEnabledSkills(rulebookConfig);
985
- // Add capabilities summary
986
- if (enabledSkills.length > 0) {
987
- sections.push('## Project Capabilities');
988
- sections.push('');
989
- sections.push('This project has the following AI-assisted capabilities enabled:');
990
- sections.push('');
991
- // Group skills by category for summary
992
- const categorySummary = new Map();
993
- for (const skill of enabledSkills) {
994
- const category = skill.category;
995
- if (!categorySummary.has(category)) {
996
- categorySummary.set(category, []);
997
- }
998
- categorySummary.get(category)?.push(skill.metadata.name);
999
- }
1000
- for (const [category, skills] of categorySummary.entries()) {
1001
- const categoryLabel = category.charAt(0).toUpperCase() + category.slice(1);
1002
- sections.push(`- **${categoryLabel}**: ${skills.join(', ')}`);
1003
- }
1004
- sections.push('');
1005
- sections.push('Use `rulebook skill list` to see all available skills.');
1006
- sections.push('Use `rulebook skill add <skill-id>` to enable additional skills.');
1007
- sections.push('');
1008
- }
1009
- // Add skills content (includes index and detailed rules)
1010
- const skillsContent = await skillsManager.mergeSkillsContent(rulebookConfig);
1011
- if (skillsContent) {
1012
- sections.push(skillsContent);
1013
- }
1014
- }
1015
- }
1016
- catch {
1017
- // Skills not configured or error loading - skip silently
1018
- }
1019
- // Add monorepo package index and generate per-package AGENTS.md if monorepo detected
1020
- try {
1021
- const { detectMonorepo } = await import('./detector.js');
1022
- const monorepo = await detectMonorepo(projectRoot);
1023
- if (monorepo.detected && monorepo.packages.length > 0) {
1024
- sections.push('## Monorepo Package Index');
1025
- sections.push('');
1026
- sections.push(`Monorepo tool: **${monorepo.tool}**`);
1027
- sections.push('');
1028
- sections.push('Packages:');
1029
- for (const pkg of monorepo.packages) {
1030
- sections.push(`- \`${pkg}/\` — see \`${pkg}/AGENTS.md\` for package-specific rules`);
1031
- }
1032
- sections.push('');
1033
- // Generate per-package AGENTS.md files
1034
- for (const pkg of monorepo.packages) {
1035
- await generatePackageAgentsMd(path.join(projectRoot, pkg), mergedConfig, projectRoot).catch(() => {
1036
- /* skip on error */
1037
- });
1038
- }
1039
- }
1040
- }
1041
- catch {
1042
- // Monorepo detection failed — skip silently
1043
- }
1044
- // Generate .cursor/rules/*.mdc files if Cursor is detected
1045
- try {
1046
- const { isCursorInstalled, generateCursorMdcRules } = await import('./cursor-mdc-generator.js');
1047
- if (isCursorInstalled(projectRoot)) {
1048
- const { createConfigManager } = await import('./config-manager.js');
1049
- const configManager = createConfigManager(projectRoot);
1050
- const rulebookConfig = await configManager.loadConfig();
1051
- const ralphEnabled = rulebookConfig.ralph?.enabled ?? false;
1052
- await generateCursorMdcRules(projectRoot, {
1053
- languages: mergedConfig.languages,
1054
- ralphEnabled,
1055
- rulebookDir: rulebookDir,
1056
- });
1057
- }
1058
- }
1059
- catch {
1060
- // Cursor MDC generation failed - skip silently
1061
- }
1062
- // Generate multi-tool IDE config files (GEMINI.md, .windsurfrules, etc.)
1063
- try {
1064
- const { detectGeminiCli, detectContinueDev, detectWindsurf, detectGithubCopilot } = await import('./detector.js');
1065
- const { generateMultiToolConfigs } = await import('./multi-tool-generator.js');
1066
- const [geminiCli, continueDev, windsurf, githubCopilot] = await Promise.all([
1067
- detectGeminiCli(projectRoot),
1068
- detectContinueDev(projectRoot),
1069
- detectWindsurf(projectRoot),
1070
- detectGithubCopilot(projectRoot),
1071
- ]);
1072
- await generateMultiToolConfigs(projectRoot, {
1073
- languages: [],
1074
- modules: [],
1075
- frameworks: [],
1076
- services: [],
1077
- existingAgents: null,
1078
- geminiCli,
1079
- continueDev,
1080
- windsurf,
1081
- githubCopilot,
1082
- });
1083
- }
1084
- catch {
1085
- // Multi-tool generation failed - skip silently
1086
- }
1087
- // Generate agent delegation section
1088
- sections.push(generateDelegationSection(mergedConfig));
1089
- // Install agent definitions and dev skills to .claude/
1090
- try {
1091
- await installAgentsWithPlaceholders(projectRoot, mergedConfig);
1092
- await installDevSkillsFromTemplates(projectRoot);
1093
- }
1094
- catch {
1095
- // Agent/skill installation failed — skip silently
1096
- }
1097
- // Append AGENTS.override.md content if present and non-empty
1098
- try {
1099
- const { readOverrideContent } = await import('./override-manager.js');
1100
- const overrideContent = await readOverrideContent(projectRoot);
1101
- if (overrideContent) {
1102
- sections.push('');
1103
- sections.push('## Project-Specific Overrides');
1104
- sections.push('');
1105
- sections.push(overrideContent);
1106
- }
1107
- }
1108
- catch {
1109
- // Override reading failed — skip silently
1110
- }
1111
- return sections.join('\n').trim() + '\n';
1112
- }
1113
- /**
1114
- * Generate a minimal AGENTS.md for an individual package inside a monorepo.
1115
- * Inherits language detection from the package root and links back to the root AGENTS.md.
1116
- */
1117
- export async function generatePackageAgentsMd(packageRoot, rootConfig, monorepoRoot) {
1118
- const { existsSync } = await import('fs');
1119
- const { detectProject } = await import('./detector.js');
1120
- const agentsPath = path.join(packageRoot, 'AGENTS.md');
1121
- // Don't overwrite if already customized (has RULEBOOK markers)
1122
- if (existsSync(agentsPath)) {
1123
- const existing = await readFile(agentsPath).catch(() => '');
1124
- if (existing.includes('<!-- RULEBOOK:START -->'))
1125
- return;
1126
- }
1127
- // Detect languages specific to this package
1128
- const pkgDetection = await detectProject(packageRoot).catch(() => null);
1129
- const langList = pkgDetection
1130
- ? pkgDetection.languages.map((l) => l.language)
1131
- : rootConfig.languages;
1132
- const relRoot = path.relative(packageRoot, monorepoRoot) || '..';
1133
- const content = [
1134
- '<!-- RULEBOOK:START -->',
1135
- `# Package Agent Directives`,
1136
- '',
1137
- `> Part of a monorepo. Root rules: [\`${relRoot}/AGENTS.md\`](${relRoot}/AGENTS.md)`,
1138
- '',
1139
- '## Languages',
1140
- '',
1141
- langList.length > 0
1142
- ? langList.map((l) => `- ${l.toUpperCase()}`).join('\n')
1143
- : '- (inherits from root)',
1144
- '',
1145
- '## Rules',
1146
- '',
1147
- `- Follow root AGENTS.md for task management and quality gates`,
1148
- `- Package-specific overrides go in \`AGENTS.override.md\` (if present)`,
1149
- '<!-- RULEBOOK:END -->',
1150
- '',
1151
- ].join('\n');
1152
- await writeFile(agentsPath, content);
1153
- }
1154
- /**
1155
- * Generate lean AGENTS.md — a lightweight index (< 3KB) referencing spec files.
1156
- * All spec files are still written to .rulebook/specs/ by generateModularAgents.
1157
- */
1158
- export async function generateLeanAgents(config, projectRoot = process.cwd()) {
1159
- // First run modular generation to ensure all spec files are up to date
1160
- await generateModularAgents(config, projectRoot);
1161
- const rulebookDir = config.rulebookDir || '.rulebook';
1162
- // Load lean template
1163
- const templatesDir = path.join(getTemplatesDir(), 'core');
1164
- const leanTemplatePath = path.join(templatesDir, 'AGENTS_LEAN.md');
1165
- let template = '';
1166
- if (await fileExists(leanTemplatePath)) {
1167
- template = await readFile(leanTemplatePath);
1168
- }
1169
- else {
1170
- template = `<!-- RULEBOOK:START -->\n# Project Agent Directives\n\nSee \`/${rulebookDir}/specs/\` for all rules.\n\n- **Task Management**: \`/${rulebookDir}/specs/RULEBOOK.md\`\n- **Quality Gates**: \`/${rulebookDir}/specs/QUALITY_ENFORCEMENT.md\`\n- **Git Workflow**: \`/${rulebookDir}/specs/GIT.md\`\n<!-- RULEBOOK:END -->\n`;
1171
- }
1172
- // Build language refs
1173
- const langRefs = config.languages
1174
- .map((lang) => `- **${lang.toUpperCase()}**: \`/${rulebookDir}/specs/${lang.toUpperCase()}.md\``)
1175
- .join('\n');
1176
- template = template.replace('LANGUAGE_REFS', langRefs || '_None configured_');
1177
- // Build module refs (core + user modules)
1178
- const coreModules = config.minimal ? [] : ['agent_automation', 'multi_agent'];
1179
- const allModules = [...coreModules, ...(config.modules || [])];
1180
- const moduleRefs = allModules
1181
- .map((mod) => `- **${mod.toUpperCase()}**: \`/${rulebookDir}/specs/${mod.toUpperCase()}.md\``)
1182
- .join('\n');
1183
- template = template.replace('MODULE_REFS', moduleRefs || '_None configured_');
1184
- return template;
1185
- }
1186
- /**
1187
- * Generate full AGENTS.md (modular by default, legacy mode available)
1188
- */
1189
- export async function generateFullAgents(config, projectRoot = process.cwd()) {
1190
- // Always use lean template — the procedural 6k-line output is deprecated.
1191
- return await generateLeanAgents(config, projectRoot);
1192
- }
1193
- //# sourceMappingURL=generator.js.map