@bonesofspring/ai-rules 0.2.56 → 0.2.57

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 (438) hide show
  1. package/CHANGELOG.md +66 -1
  2. package/README.md +27 -0
  3. package/docs/PRESET-CONTRIBUTION.md +13 -1
  4. package/docs/TEAM-DB.md +34 -1
  5. package/docs/openapi/team-db.v1.json +17 -2
  6. package/package.json +2 -1
  7. package/presets/_shared/ai-local/scripts/rule-improver.mjs +333 -26
  8. package/presets/_shared/ai-local/scripts/run.mjs +21 -6
  9. package/presets/_shared/ai-local/scripts/team-db-api.mjs +1 -0
  10. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +6 -1
  11. package/presets/_shared/ai-local/scripts/team-db-project.mjs +1 -1
  12. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +79 -9
  13. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +17 -6
  14. package/presets/_shared/core/quality/self-review-and-context-hygiene.md +3 -1
  15. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +20 -15
  16. package/presets/claude/android-kotlin/agents/build-verifier.md +1 -1
  17. package/presets/claude/android-kotlin/agents/code-reviewer.md +1 -1
  18. package/presets/claude/android-kotlin/agents/debugger.md +1 -1
  19. package/presets/claude/android-kotlin/agents/feature-developer.md +1 -1
  20. package/presets/claude/android-kotlin/agents/task-analyst.md +1 -1
  21. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +20 -15
  22. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  23. package/presets/claude/go/agents/build-verifier.md +1 -1
  24. package/presets/claude/go/agents/code-reviewer.md +1 -1
  25. package/presets/claude/go/agents/debugger.md +1 -1
  26. package/presets/claude/go/agents/feature-developer.md +1 -1
  27. package/presets/claude/go/agents/task-analyst.md +1 -1
  28. package/presets/claude/go/hooks/chain-team-phases.sh +20 -15
  29. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  30. package/presets/claude/ios-swift/agents/build-verifier.md +1 -1
  31. package/presets/claude/ios-swift/agents/code-reviewer.md +1 -1
  32. package/presets/claude/ios-swift/agents/debugger.md +1 -1
  33. package/presets/claude/ios-swift/agents/feature-developer.md +1 -1
  34. package/presets/claude/ios-swift/agents/task-analyst.md +1 -1
  35. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +20 -15
  36. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  37. package/presets/claude/java/agents/build-verifier.md +1 -1
  38. package/presets/claude/java/agents/code-reviewer.md +1 -1
  39. package/presets/claude/java/agents/debugger.md +1 -1
  40. package/presets/claude/java/agents/feature-developer.md +1 -1
  41. package/presets/claude/java/agents/task-analyst.md +1 -1
  42. package/presets/claude/java/hooks/chain-team-phases.sh +20 -15
  43. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  44. package/presets/claude/mcp-ts/agents/build-verifier.md +1 -1
  45. package/presets/claude/mcp-ts/agents/feature-developer.md +1 -1
  46. package/presets/claude/mcp-ts/agents/task-analyst.md +1 -1
  47. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +20 -15
  48. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  49. package/presets/claude/mol/agents/build-verifier.md +1 -1
  50. package/presets/claude/mol/agents/code-reviewer.md +1 -1
  51. package/presets/claude/mol/agents/debugger.md +1 -1
  52. package/presets/claude/mol/agents/feature-developer.md +1 -1
  53. package/presets/claude/mol/agents/task-analyst.md +1 -1
  54. package/presets/claude/mol/hooks/chain-team-phases.sh +20 -15
  55. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  56. package/presets/claude/next/agents/build-verifier.md +16 -1
  57. package/presets/claude/next/agents/code-reviewer.md +1 -1
  58. package/presets/claude/next/agents/debugger.md +1 -1
  59. package/presets/claude/next/agents/feature-developer.md +13 -1
  60. package/presets/claude/next/agents/task-analyst.md +1 -1
  61. package/presets/claude/next/agents/task-router.md +10 -0
  62. package/presets/claude/next/hooks/chain-team-phases.sh +20 -15
  63. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  64. package/presets/claude/next/rules/tooling-and-review/code-review-mr.md +2 -1
  65. package/presets/claude/nuxt/agents/build-verifier.md +1 -1
  66. package/presets/claude/nuxt/agents/code-reviewer.md +1 -1
  67. package/presets/claude/nuxt/agents/debugger.md +1 -1
  68. package/presets/claude/nuxt/agents/feature-developer.md +1 -1
  69. package/presets/claude/nuxt/agents/task-analyst.md +1 -1
  70. package/presets/claude/nuxt/hooks/chain-team-phases.sh +20 -15
  71. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  72. package/presets/claude/php-hexagonal/agents/build-verifier.md +1 -1
  73. package/presets/claude/php-hexagonal/agents/code-reviewer.md +1 -1
  74. package/presets/claude/php-hexagonal/agents/debugger.md +1 -1
  75. package/presets/claude/php-hexagonal/agents/feature-developer.md +1 -1
  76. package/presets/claude/php-hexagonal/agents/task-analyst.md +1 -1
  77. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  78. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  79. package/presets/claude/php-laravel/agents/build-verifier.md +1 -1
  80. package/presets/claude/php-laravel/agents/code-reviewer.md +1 -1
  81. package/presets/claude/php-laravel/agents/debugger.md +1 -1
  82. package/presets/claude/php-laravel/agents/feature-developer.md +1 -1
  83. package/presets/claude/php-laravel/agents/task-analyst.md +1 -1
  84. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +20 -15
  85. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  86. package/presets/claude/svelte/agents/build-verifier.md +1 -1
  87. package/presets/claude/svelte/agents/code-reviewer.md +1 -1
  88. package/presets/claude/svelte/agents/debugger.md +1 -1
  89. package/presets/claude/svelte/agents/feature-developer.md +1 -1
  90. package/presets/claude/svelte/agents/task-analyst.md +1 -1
  91. package/presets/claude/svelte/hooks/chain-team-phases.sh +20 -15
  92. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  93. package/presets/cursor/android-kotlin/agents/build-verifier.md +1 -1
  94. package/presets/cursor/android-kotlin/agents/code-reviewer.md +1 -1
  95. package/presets/cursor/android-kotlin/agents/debugger.md +1 -1
  96. package/presets/cursor/android-kotlin/agents/feature-developer.md +1 -1
  97. package/presets/cursor/android-kotlin/agents/task-analyst.md +1 -1
  98. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +20 -15
  99. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
  100. package/presets/cursor/go/agents/build-verifier.md +1 -1
  101. package/presets/cursor/go/agents/code-reviewer.md +1 -1
  102. package/presets/cursor/go/agents/debugger.md +1 -1
  103. package/presets/cursor/go/agents/feature-developer.md +1 -1
  104. package/presets/cursor/go/agents/task-analyst.md +1 -1
  105. package/presets/cursor/go/hooks/chain-team-phases.sh +20 -15
  106. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
  107. package/presets/cursor/ios-swift/agents/build-verifier.md +1 -1
  108. package/presets/cursor/ios-swift/agents/code-reviewer.md +1 -1
  109. package/presets/cursor/ios-swift/agents/debugger.md +1 -1
  110. package/presets/cursor/ios-swift/agents/feature-developer.md +1 -1
  111. package/presets/cursor/ios-swift/agents/task-analyst.md +1 -1
  112. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +20 -15
  113. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
  114. package/presets/cursor/java/agents/build-verifier.md +1 -1
  115. package/presets/cursor/java/agents/code-reviewer.md +1 -1
  116. package/presets/cursor/java/agents/debugger.md +1 -1
  117. package/presets/cursor/java/agents/feature-developer.md +1 -1
  118. package/presets/cursor/java/agents/task-analyst.md +1 -1
  119. package/presets/cursor/java/hooks/chain-team-phases.sh +20 -15
  120. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
  121. package/presets/cursor/mcp-ts/agents/build-verifier.md +1 -1
  122. package/presets/cursor/mcp-ts/agents/feature-developer.md +1 -1
  123. package/presets/cursor/mcp-ts/agents/task-analyst.md +1 -1
  124. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +20 -15
  125. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
  126. package/presets/cursor/mol/agents/build-verifier.md +1 -1
  127. package/presets/cursor/mol/agents/code-reviewer.md +1 -1
  128. package/presets/cursor/mol/agents/debugger.md +1 -1
  129. package/presets/cursor/mol/agents/feature-developer.md +1 -1
  130. package/presets/cursor/mol/agents/task-analyst.md +1 -1
  131. package/presets/cursor/mol/hooks/chain-team-phases.sh +20 -15
  132. package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
  133. package/presets/cursor/next/agents/README.md +2 -0
  134. package/presets/cursor/next/agents/build-verifier.md +16 -1
  135. package/presets/cursor/next/agents/code-reviewer.md +1 -1
  136. package/presets/cursor/next/agents/debugger.md +1 -1
  137. package/presets/cursor/next/agents/feature-developer.md +13 -1
  138. package/presets/cursor/next/agents/task-analyst.md +1 -1
  139. package/presets/cursor/next/agents/task-router.md +10 -0
  140. package/presets/cursor/next/hooks/chain-team-phases.sh +20 -15
  141. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +1 -1
  142. package/presets/cursor/next/rules/code-review-mr.mdc +2 -1
  143. package/presets/cursor/next/team/fixtures/feature-l2-lite.json +27 -0
  144. package/presets/cursor/nuxt/agents/build-verifier.md +1 -1
  145. package/presets/cursor/nuxt/agents/code-reviewer.md +1 -1
  146. package/presets/cursor/nuxt/agents/debugger.md +1 -1
  147. package/presets/cursor/nuxt/agents/feature-developer.md +1 -1
  148. package/presets/cursor/nuxt/agents/task-analyst.md +1 -1
  149. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +20 -15
  150. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
  151. package/presets/cursor/php-hexagonal/agents/build-verifier.md +1 -1
  152. package/presets/cursor/php-hexagonal/agents/code-reviewer.md +1 -1
  153. package/presets/cursor/php-hexagonal/agents/debugger.md +1 -1
  154. package/presets/cursor/php-hexagonal/agents/feature-developer.md +1 -1
  155. package/presets/cursor/php-hexagonal/agents/task-analyst.md +1 -1
  156. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  157. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
  158. package/presets/cursor/php-laravel/agents/build-verifier.md +1 -1
  159. package/presets/cursor/php-laravel/agents/code-reviewer.md +1 -1
  160. package/presets/cursor/php-laravel/agents/debugger.md +1 -1
  161. package/presets/cursor/php-laravel/agents/feature-developer.md +1 -1
  162. package/presets/cursor/php-laravel/agents/task-analyst.md +1 -1
  163. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +20 -15
  164. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
  165. package/presets/cursor/svelte/agents/build-verifier.md +1 -1
  166. package/presets/cursor/svelte/agents/code-reviewer.md +1 -1
  167. package/presets/cursor/svelte/agents/debugger.md +1 -1
  168. package/presets/cursor/svelte/agents/feature-developer.md +1 -1
  169. package/presets/cursor/svelte/agents/task-analyst.md +1 -1
  170. package/presets/cursor/svelte/hooks/chain-team-phases.sh +20 -15
  171. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
  172. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  173. package/presets/mavis/android-kotlin/agents/build-verifier.md +1 -1
  174. package/presets/mavis/android-kotlin/agents/code-reviewer.md +1 -1
  175. package/presets/mavis/android-kotlin/agents/debugger.md +1 -1
  176. package/presets/mavis/android-kotlin/agents/feature-developer.md +1 -1
  177. package/presets/mavis/android-kotlin/agents/task-analyst.md +1 -1
  178. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +20 -15
  179. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +17 -6
  180. package/presets/mavis/go/adapter-map.json +1 -1
  181. package/presets/mavis/go/agents/build-verifier.md +1 -1
  182. package/presets/mavis/go/agents/code-reviewer.md +1 -1
  183. package/presets/mavis/go/agents/debugger.md +1 -1
  184. package/presets/mavis/go/agents/feature-developer.md +1 -1
  185. package/presets/mavis/go/agents/task-analyst.md +1 -1
  186. package/presets/mavis/go/hooks/chain-team-phases.sh +20 -15
  187. package/presets/mavis/go/rules/agent-team-orchestrator.md +17 -6
  188. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  189. package/presets/mavis/ios-swift/agents/build-verifier.md +1 -1
  190. package/presets/mavis/ios-swift/agents/code-reviewer.md +1 -1
  191. package/presets/mavis/ios-swift/agents/debugger.md +1 -1
  192. package/presets/mavis/ios-swift/agents/feature-developer.md +1 -1
  193. package/presets/mavis/ios-swift/agents/task-analyst.md +1 -1
  194. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +20 -15
  195. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +17 -6
  196. package/presets/mavis/java/adapter-map.json +1 -1
  197. package/presets/mavis/java/agents/build-verifier.md +1 -1
  198. package/presets/mavis/java/agents/code-reviewer.md +1 -1
  199. package/presets/mavis/java/agents/debugger.md +1 -1
  200. package/presets/mavis/java/agents/feature-developer.md +1 -1
  201. package/presets/mavis/java/agents/task-analyst.md +1 -1
  202. package/presets/mavis/java/hooks/chain-team-phases.sh +20 -15
  203. package/presets/mavis/java/rules/agent-team-orchestrator.md +17 -6
  204. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  205. package/presets/mavis/mcp-ts/agents/build-verifier.md +1 -1
  206. package/presets/mavis/mcp-ts/agents/feature-developer.md +1 -1
  207. package/presets/mavis/mcp-ts/agents/task-analyst.md +1 -1
  208. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +20 -15
  209. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +17 -6
  210. package/presets/mavis/mol/adapter-map.json +1 -1
  211. package/presets/mavis/mol/agents/build-verifier.md +1 -1
  212. package/presets/mavis/mol/agents/code-reviewer.md +1 -1
  213. package/presets/mavis/mol/agents/debugger.md +1 -1
  214. package/presets/mavis/mol/agents/feature-developer.md +1 -1
  215. package/presets/mavis/mol/agents/task-analyst.md +1 -1
  216. package/presets/mavis/mol/hooks/chain-team-phases.sh +20 -15
  217. package/presets/mavis/mol/rules/agent-team-orchestrator.md +17 -6
  218. package/presets/mavis/next/adapter-map.json +9 -1
  219. package/presets/mavis/next/agents/build-verifier.md +16 -1
  220. package/presets/mavis/next/agents/code-reviewer.md +1 -1
  221. package/presets/mavis/next/agents/debugger.md +1 -1
  222. package/presets/mavis/next/agents/feature-developer.md +13 -1
  223. package/presets/mavis/next/agents/task-analyst.md +1 -1
  224. package/presets/mavis/next/agents/task-router.md +10 -0
  225. package/presets/mavis/next/hooks/chain-team-phases.sh +20 -15
  226. package/presets/mavis/next/rules/agent-team-orchestrator.md +17 -6
  227. package/presets/mavis/next/rules/code-review-mr.md +2 -1
  228. package/presets/mavis/next/team/fixtures/feature-l2-lite.json +27 -0
  229. package/presets/mavis/nuxt/adapter-map.json +1 -1
  230. package/presets/mavis/nuxt/agents/build-verifier.md +1 -1
  231. package/presets/mavis/nuxt/agents/code-reviewer.md +1 -1
  232. package/presets/mavis/nuxt/agents/debugger.md +1 -1
  233. package/presets/mavis/nuxt/agents/feature-developer.md +1 -1
  234. package/presets/mavis/nuxt/agents/task-analyst.md +1 -1
  235. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +20 -15
  236. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +17 -6
  237. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  238. package/presets/mavis/php-hexagonal/agents/build-verifier.md +1 -1
  239. package/presets/mavis/php-hexagonal/agents/code-reviewer.md +1 -1
  240. package/presets/mavis/php-hexagonal/agents/debugger.md +1 -1
  241. package/presets/mavis/php-hexagonal/agents/feature-developer.md +1 -1
  242. package/presets/mavis/php-hexagonal/agents/task-analyst.md +1 -1
  243. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  244. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +17 -6
  245. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  246. package/presets/mavis/php-laravel/agents/build-verifier.md +1 -1
  247. package/presets/mavis/php-laravel/agents/code-reviewer.md +1 -1
  248. package/presets/mavis/php-laravel/agents/debugger.md +1 -1
  249. package/presets/mavis/php-laravel/agents/feature-developer.md +1 -1
  250. package/presets/mavis/php-laravel/agents/task-analyst.md +1 -1
  251. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +20 -15
  252. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +17 -6
  253. package/presets/mavis/svelte/adapter-map.json +1 -1
  254. package/presets/mavis/svelte/agents/build-verifier.md +1 -1
  255. package/presets/mavis/svelte/agents/code-reviewer.md +1 -1
  256. package/presets/mavis/svelte/agents/debugger.md +1 -1
  257. package/presets/mavis/svelte/agents/feature-developer.md +1 -1
  258. package/presets/mavis/svelte/agents/task-analyst.md +1 -1
  259. package/presets/mavis/svelte/hooks/chain-team-phases.sh +20 -15
  260. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +17 -6
  261. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  262. package/presets/opencode/android-kotlin/agents/build-verifier.md +1 -1
  263. package/presets/opencode/android-kotlin/agents/code-reviewer.md +1 -1
  264. package/presets/opencode/android-kotlin/agents/debugger.md +1 -1
  265. package/presets/opencode/android-kotlin/agents/feature-developer.md +1 -1
  266. package/presets/opencode/android-kotlin/agents/task-analyst.md +1 -1
  267. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +20 -15
  268. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +17 -6
  269. package/presets/opencode/go/adapter-map.json +1 -1
  270. package/presets/opencode/go/agents/build-verifier.md +1 -1
  271. package/presets/opencode/go/agents/code-reviewer.md +1 -1
  272. package/presets/opencode/go/agents/debugger.md +1 -1
  273. package/presets/opencode/go/agents/feature-developer.md +1 -1
  274. package/presets/opencode/go/agents/task-analyst.md +1 -1
  275. package/presets/opencode/go/hooks/chain-team-phases.sh +20 -15
  276. package/presets/opencode/go/rules/agent-team-orchestrator.md +17 -6
  277. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  278. package/presets/opencode/ios-swift/agents/build-verifier.md +1 -1
  279. package/presets/opencode/ios-swift/agents/code-reviewer.md +1 -1
  280. package/presets/opencode/ios-swift/agents/debugger.md +1 -1
  281. package/presets/opencode/ios-swift/agents/feature-developer.md +1 -1
  282. package/presets/opencode/ios-swift/agents/task-analyst.md +1 -1
  283. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +20 -15
  284. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +17 -6
  285. package/presets/opencode/java/adapter-map.json +1 -1
  286. package/presets/opencode/java/agents/build-verifier.md +1 -1
  287. package/presets/opencode/java/agents/code-reviewer.md +1 -1
  288. package/presets/opencode/java/agents/debugger.md +1 -1
  289. package/presets/opencode/java/agents/feature-developer.md +1 -1
  290. package/presets/opencode/java/agents/task-analyst.md +1 -1
  291. package/presets/opencode/java/hooks/chain-team-phases.sh +20 -15
  292. package/presets/opencode/java/rules/agent-team-orchestrator.md +17 -6
  293. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  294. package/presets/opencode/mcp-ts/agents/build-verifier.md +1 -1
  295. package/presets/opencode/mcp-ts/agents/feature-developer.md +1 -1
  296. package/presets/opencode/mcp-ts/agents/task-analyst.md +1 -1
  297. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +20 -15
  298. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +17 -6
  299. package/presets/opencode/mol/adapter-map.json +1 -1
  300. package/presets/opencode/mol/agents/build-verifier.md +1 -1
  301. package/presets/opencode/mol/agents/code-reviewer.md +1 -1
  302. package/presets/opencode/mol/agents/debugger.md +1 -1
  303. package/presets/opencode/mol/agents/feature-developer.md +1 -1
  304. package/presets/opencode/mol/agents/task-analyst.md +1 -1
  305. package/presets/opencode/mol/hooks/chain-team-phases.sh +20 -15
  306. package/presets/opencode/mol/rules/agent-team-orchestrator.md +17 -6
  307. package/presets/opencode/next/adapter-map.json +9 -1
  308. package/presets/opencode/next/agents/build-verifier.md +16 -1
  309. package/presets/opencode/next/agents/code-reviewer.md +1 -1
  310. package/presets/opencode/next/agents/debugger.md +1 -1
  311. package/presets/opencode/next/agents/feature-developer.md +13 -1
  312. package/presets/opencode/next/agents/task-analyst.md +1 -1
  313. package/presets/opencode/next/agents/task-router.md +10 -0
  314. package/presets/opencode/next/hooks/chain-team-phases.sh +20 -15
  315. package/presets/opencode/next/rules/agent-team-orchestrator.md +17 -6
  316. package/presets/opencode/next/rules/code-review-mr.md +2 -1
  317. package/presets/opencode/next/team/fixtures/feature-l2-lite.json +27 -0
  318. package/presets/opencode/nuxt/adapter-map.json +1 -1
  319. package/presets/opencode/nuxt/agents/build-verifier.md +1 -1
  320. package/presets/opencode/nuxt/agents/code-reviewer.md +1 -1
  321. package/presets/opencode/nuxt/agents/debugger.md +1 -1
  322. package/presets/opencode/nuxt/agents/feature-developer.md +1 -1
  323. package/presets/opencode/nuxt/agents/task-analyst.md +1 -1
  324. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +20 -15
  325. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +17 -6
  326. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  327. package/presets/opencode/php-hexagonal/agents/build-verifier.md +1 -1
  328. package/presets/opencode/php-hexagonal/agents/code-reviewer.md +1 -1
  329. package/presets/opencode/php-hexagonal/agents/debugger.md +1 -1
  330. package/presets/opencode/php-hexagonal/agents/feature-developer.md +1 -1
  331. package/presets/opencode/php-hexagonal/agents/task-analyst.md +1 -1
  332. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  333. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +17 -6
  334. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  335. package/presets/opencode/php-laravel/agents/build-verifier.md +1 -1
  336. package/presets/opencode/php-laravel/agents/code-reviewer.md +1 -1
  337. package/presets/opencode/php-laravel/agents/debugger.md +1 -1
  338. package/presets/opencode/php-laravel/agents/feature-developer.md +1 -1
  339. package/presets/opencode/php-laravel/agents/task-analyst.md +1 -1
  340. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +20 -15
  341. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +17 -6
  342. package/presets/opencode/svelte/adapter-map.json +1 -1
  343. package/presets/opencode/svelte/agents/build-verifier.md +1 -1
  344. package/presets/opencode/svelte/agents/code-reviewer.md +1 -1
  345. package/presets/opencode/svelte/agents/debugger.md +1 -1
  346. package/presets/opencode/svelte/agents/feature-developer.md +1 -1
  347. package/presets/opencode/svelte/agents/task-analyst.md +1 -1
  348. package/presets/opencode/svelte/hooks/chain-team-phases.sh +20 -15
  349. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +17 -6
  350. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  351. package/presets/zcode/android-kotlin/agents/build-verifier.md +1 -1
  352. package/presets/zcode/android-kotlin/agents/code-reviewer.md +1 -1
  353. package/presets/zcode/android-kotlin/agents/debugger.md +1 -1
  354. package/presets/zcode/android-kotlin/agents/feature-developer.md +1 -1
  355. package/presets/zcode/android-kotlin/agents/task-analyst.md +1 -1
  356. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +20 -15
  357. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +17 -6
  358. package/presets/zcode/go/adapter-map.json +1 -1
  359. package/presets/zcode/go/agents/build-verifier.md +1 -1
  360. package/presets/zcode/go/agents/code-reviewer.md +1 -1
  361. package/presets/zcode/go/agents/debugger.md +1 -1
  362. package/presets/zcode/go/agents/feature-developer.md +1 -1
  363. package/presets/zcode/go/agents/task-analyst.md +1 -1
  364. package/presets/zcode/go/hooks/chain-team-phases.sh +20 -15
  365. package/presets/zcode/go/rules/agent-team-orchestrator.md +17 -6
  366. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  367. package/presets/zcode/ios-swift/agents/build-verifier.md +1 -1
  368. package/presets/zcode/ios-swift/agents/code-reviewer.md +1 -1
  369. package/presets/zcode/ios-swift/agents/debugger.md +1 -1
  370. package/presets/zcode/ios-swift/agents/feature-developer.md +1 -1
  371. package/presets/zcode/ios-swift/agents/task-analyst.md +1 -1
  372. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +20 -15
  373. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +17 -6
  374. package/presets/zcode/java/adapter-map.json +1 -1
  375. package/presets/zcode/java/agents/build-verifier.md +1 -1
  376. package/presets/zcode/java/agents/code-reviewer.md +1 -1
  377. package/presets/zcode/java/agents/debugger.md +1 -1
  378. package/presets/zcode/java/agents/feature-developer.md +1 -1
  379. package/presets/zcode/java/agents/task-analyst.md +1 -1
  380. package/presets/zcode/java/hooks/chain-team-phases.sh +20 -15
  381. package/presets/zcode/java/rules/agent-team-orchestrator.md +17 -6
  382. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  383. package/presets/zcode/mcp-ts/agents/build-verifier.md +1 -1
  384. package/presets/zcode/mcp-ts/agents/feature-developer.md +1 -1
  385. package/presets/zcode/mcp-ts/agents/task-analyst.md +1 -1
  386. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +20 -15
  387. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +17 -6
  388. package/presets/zcode/mol/adapter-map.json +1 -1
  389. package/presets/zcode/mol/agents/build-verifier.md +1 -1
  390. package/presets/zcode/mol/agents/code-reviewer.md +1 -1
  391. package/presets/zcode/mol/agents/debugger.md +1 -1
  392. package/presets/zcode/mol/agents/feature-developer.md +1 -1
  393. package/presets/zcode/mol/agents/task-analyst.md +1 -1
  394. package/presets/zcode/mol/hooks/chain-team-phases.sh +20 -15
  395. package/presets/zcode/mol/rules/agent-team-orchestrator.md +17 -6
  396. package/presets/zcode/next/adapter-map.json +9 -1
  397. package/presets/zcode/next/agents/build-verifier.md +16 -1
  398. package/presets/zcode/next/agents/code-reviewer.md +1 -1
  399. package/presets/zcode/next/agents/debugger.md +1 -1
  400. package/presets/zcode/next/agents/feature-developer.md +13 -1
  401. package/presets/zcode/next/agents/task-analyst.md +1 -1
  402. package/presets/zcode/next/agents/task-router.md +10 -0
  403. package/presets/zcode/next/hooks/chain-team-phases.sh +20 -15
  404. package/presets/zcode/next/rules/agent-team-orchestrator.md +17 -6
  405. package/presets/zcode/next/rules/code-review-mr.md +2 -1
  406. package/presets/zcode/next/team/fixtures/feature-l2-lite.json +27 -0
  407. package/presets/zcode/nuxt/adapter-map.json +1 -1
  408. package/presets/zcode/nuxt/agents/build-verifier.md +1 -1
  409. package/presets/zcode/nuxt/agents/code-reviewer.md +1 -1
  410. package/presets/zcode/nuxt/agents/debugger.md +1 -1
  411. package/presets/zcode/nuxt/agents/feature-developer.md +1 -1
  412. package/presets/zcode/nuxt/agents/task-analyst.md +1 -1
  413. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +20 -15
  414. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +17 -6
  415. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  416. package/presets/zcode/php-hexagonal/agents/build-verifier.md +1 -1
  417. package/presets/zcode/php-hexagonal/agents/code-reviewer.md +1 -1
  418. package/presets/zcode/php-hexagonal/agents/debugger.md +1 -1
  419. package/presets/zcode/php-hexagonal/agents/feature-developer.md +1 -1
  420. package/presets/zcode/php-hexagonal/agents/task-analyst.md +1 -1
  421. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  422. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +17 -6
  423. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  424. package/presets/zcode/php-laravel/agents/build-verifier.md +1 -1
  425. package/presets/zcode/php-laravel/agents/code-reviewer.md +1 -1
  426. package/presets/zcode/php-laravel/agents/debugger.md +1 -1
  427. package/presets/zcode/php-laravel/agents/feature-developer.md +1 -1
  428. package/presets/zcode/php-laravel/agents/task-analyst.md +1 -1
  429. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +20 -15
  430. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +17 -6
  431. package/presets/zcode/svelte/adapter-map.json +1 -1
  432. package/presets/zcode/svelte/agents/build-verifier.md +1 -1
  433. package/presets/zcode/svelte/agents/code-reviewer.md +1 -1
  434. package/presets/zcode/svelte/agents/debugger.md +1 -1
  435. package/presets/zcode/svelte/agents/feature-developer.md +1 -1
  436. package/presets/zcode/svelte/agents/task-analyst.md +1 -1
  437. package/presets/zcode/svelte/hooks/chain-team-phases.sh +20 -15
  438. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +17 -6
@@ -28,9 +28,28 @@ import {
28
28
  } from './signals.mjs';
29
29
  import { acquireLock, releaseLock } from './lock.mjs';
30
30
 
31
- // --- Envelope caps (architecture.md §3) -------------------------------------
31
+ // --- Envelope caps (architecture.md §3, ADR 0001 guard 2) --------------------
32
+ // Two stores, two budgets:
33
+ // human store — `.ai.local/rules/**` ≤ MAX_ACTIVE_RULES files, ≤ MAX_RULE_LINES lines
34
+ // machine store — `.ai.local/conventions.md` ≤ MAX_CONVENTION_LINES lines
35
+ // The combined envelope stays 200 non-empty lines; only its distribution moves.
36
+ // A saturated store refuses its own writes and never another store's.
32
37
  export const MAX_ACTIVE_RULES = 5;
33
- export const MAX_TOTAL_LINES = 200;
38
+ export const MAX_RULE_LINES = 170;
39
+ export const MAX_CONVENTION_LINES = 30;
40
+
41
+ /**
42
+ * Back-compat alias for the pre-split single-pool engine.
43
+ *
44
+ * A consumer seeded before the per-store split keeps its old `run.mjs`
45
+ * (seeding is skip-if-exists), and that module imports `MAX_TOTAL_LINES`.
46
+ * The alias keeps the import resolvable, so a stale sibling module still
47
+ * loads instead of dying with a `SyntaxError`.
48
+ *
49
+ * @deprecated Use MAX_RULE_LINES / MAX_CONVENTION_LINES. The per-store caps
50
+ * are the single source of truth; this alias is derived from them.
51
+ */
52
+ export const MAX_TOTAL_LINES = MAX_RULE_LINES + MAX_CONVENTION_LINES;
34
53
 
35
54
  // --- Denylist (architecture.md §5.3) ----------------------------------------
36
55
  export const DENYLIST = [
@@ -249,12 +268,21 @@ export function recoverPendingCommit(ledgerPath, roots) {
249
268
  const current = target == null ? null : readExisting(target);
250
269
  const landed = content === null ? current === null : current === content;
251
270
  if (landed && entry.action) {
271
+ // A promotion intent carries the ledger row separately: the row's `before`
272
+ // is the reviewed snapshot, while the intent's `before` is the rule file's
273
+ // previous content.
274
+ const row = payload.ledgerEntry ?? entry;
252
275
  const existing = parseLedger(readExisting(ledgerPath) ?? '');
253
- const recorded = existing.some((row) => row
254
- && row.action === entry.action
255
- && row.signature === entry.signature
256
- && row.at === entry.at);
257
- if (!recorded) appendLedgerLine(ledgerPath, entry, resolved);
276
+ const recorded = existing.some((item) => item
277
+ && item.action === row.action
278
+ && item.signature === row.signature
279
+ && item.at === row.at);
280
+ if (!recorded) appendLedgerLine(ledgerPath, row, resolved);
281
+ for (const removal of payload.removeTargets ?? []) {
282
+ try { fs.unlinkSync(removal); } catch (error) {
283
+ if (!error || error.code !== 'ENOENT') throw error;
284
+ }
285
+ }
258
286
  clearIntent(ledgerPath);
259
287
  return { recovered: 'committed', entry };
260
288
  }
@@ -314,6 +342,37 @@ function commitWrite({ ledgerPath, target, content, entry, roots }) {
314
342
  clearIntent(ledgerPath);
315
343
  }
316
344
 
345
+ /**
346
+ * Promotion commit: the rule file, then the seed removal, then the ledger row.
347
+ *
348
+ * The intent carries the ledger row separately. The row's `before` is the
349
+ * reviewed snapshot (the contract's binding); the intent's `before` is the rule
350
+ * file's previous content (null — a promotion creates the rule). A failure
351
+ * leaves the intent in place: `recoverPendingCommit` finishes a landed rule or
352
+ * drops an attempt that never wrote it, so a ledger error cannot silently lose
353
+ * the seed or leave an unrecorded rule.
354
+ */
355
+ function commitPromotion({ ledgerPath, ruleTarget, ruleContent, seedTarget, entry, roots }) {
356
+ const resolved = typeof roots === 'string' ? { project: roots, repo: roots } : roots;
357
+ const ledgerRow = {
358
+ ...entry,
359
+ target: entry.target == null ? null : toLedgerTarget(entry.target, resolved.repo),
360
+ };
361
+ writeIntent(ledgerPath, {
362
+ entry: { ...ledgerRow, before: null },
363
+ ledgerEntry: ledgerRow,
364
+ content: ruleContent,
365
+ removeTargets: [seedTarget],
366
+ roots: resolved,
367
+ });
368
+ writeFileAtomic(ruleTarget, ruleContent);
369
+ try { fs.unlinkSync(seedTarget); } catch (error) {
370
+ if (!error || error.code !== 'ENOENT') throw error;
371
+ }
372
+ appendLedgerLine(ledgerPath, ledgerRow, resolved);
373
+ clearIntent(ledgerPath);
374
+ }
375
+
317
376
  // --- Signature parsing + template re-derivation ------------------------------
318
377
 
319
378
  export function parseSignature(signature) {
@@ -610,6 +669,56 @@ function deriveSeedText({ stem, kind, issue, paths, command }) {
610
669
  return `glob: always\n\n## Body\n\n${deriveRuleText({ stem, kind, issue, paths, command })}`;
611
670
  }
612
671
 
672
+ // --- Provenance footer (ADR 0001 guard 1) -------------------------------------
673
+
674
+ // The footer states the authorship of a staged seed. Its four fields are all
675
+ // machine-derived and bounded — a validated signature, a timestamp, a validated
676
+ // slug and a fixed state token — so no task or spec prose can reach it (guard 1:
677
+ // rule text is re-derived from the signature, never copied from prose).
678
+ export const PROVENANCE_STATE = 'awaiting-human-promotion';
679
+ const PROVENANCE_RE = /^<!--\s*ai-local-provenance:\s*(\{.*\})\s*-->$/;
680
+ const KEBAB_SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
681
+
682
+ /** The footer line for a staged seed. */
683
+ export function provenanceFooter({ signature, stagedAt, sourceSlug }) {
684
+ if (!SIGNATURE_RE.test(signature)) {
685
+ throw new Error(`invalid signature "${signature}"`);
686
+ }
687
+ if (!KEBAB_SLUG_RE.test(sourceSlug)) {
688
+ throw new Error(`invalid source slug "${sourceSlug}"`);
689
+ }
690
+ const payload = { signature, stagedAt, sourceSlug, state: PROVENANCE_STATE };
691
+ return `<!-- ai-local-provenance: ${JSON.stringify(payload)} -->`;
692
+ }
693
+
694
+ /** The seed file content: the reviewed body plus the trailing provenance line. */
695
+ export function withProvenanceFooter(body, provenance) {
696
+ return `${body.replace(/\n+$/, '')}\n${provenanceFooter(provenance)}\n`;
697
+ }
698
+
699
+ /** The parsed footer of a seed file, or null when it carries none. */
700
+ export function parseProvenanceFooter(content) {
701
+ const lines = content.split('\n');
702
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
703
+ const match = PROVENANCE_RE.exec(lines[i].trim());
704
+ if (!match) continue;
705
+ try {
706
+ return { payload: JSON.parse(match[1]), index: i };
707
+ } catch {
708
+ return null;
709
+ }
710
+ }
711
+ return null;
712
+ }
713
+
714
+ /** The reviewed content: the seed body without every provenance line. */
715
+ export function stripProvenanceFooter(content) {
716
+ const lines = content.split('\n');
717
+ const kept = lines.filter((line) => !PROVENANCE_RE.test(line.trim()));
718
+ if (kept.length === lines.length) return content;
719
+ return `${kept.join('\n').replace(/\n+$/, '')}\n`;
720
+ }
721
+
613
722
  /** Read-only `--status` lesson line: `lesson: pending` or `lesson: app/src [lint:js]`. */
614
723
  export function formatLessonStatus(lesson) {
615
724
  if (lesson === null) return 'lesson: pending';
@@ -692,21 +801,46 @@ export function thresholdAction(distinctSlugCount) {
692
801
 
693
802
  // --- Authoring envelope ------------------------------------------------------
694
803
 
695
- export function evaluateEnvelope({ ruleCount, lineCount, newRuleCount = 0, newLineCount = 0 }) {
696
- const nextRules = ruleCount + newRuleCount;
697
- const nextLines = lineCount + newLineCount;
698
- if (nextRules > MAX_ACTIVE_RULES) {
699
- return { ok: false, reason: `rule cap: ${nextRules} active rules would exceed ${MAX_ACTIVE_RULES}` };
804
+ /**
805
+ * One store's envelope. Each store is checked against its own caps, so a
806
+ * saturated `rules/` store never blocks a `conventions.md` write and a
807
+ * saturated `conventions.md` never blocks a promotion.
808
+ */
809
+ export function evaluateEnvelope({
810
+ store = 'rules',
811
+ ruleCount = 0,
812
+ lineCount = 0,
813
+ newRuleCount = 0,
814
+ newLineCount = 0,
815
+ }) {
816
+ if (store === 'rules') {
817
+ const nextRules = ruleCount + newRuleCount;
818
+ const nextLines = lineCount + newLineCount;
819
+ if (nextRules > MAX_ACTIVE_RULES) {
820
+ return { ok: false, reason: `rule cap: ${nextRules} active rules would exceed ${MAX_ACTIVE_RULES}` };
821
+ }
822
+ if (nextLines > MAX_RULE_LINES) {
823
+ return { ok: false, reason: `rule line cap: ${nextLines} nonempty lines would exceed ${MAX_RULE_LINES}` };
824
+ }
825
+ return { ok: true, reason: 'within envelope' };
700
826
  }
701
- if (nextLines > MAX_TOTAL_LINES) {
702
- return { ok: false, reason: `line cap: ${nextLines} nonempty lines would exceed ${MAX_TOTAL_LINES}` };
827
+ if (store === 'conventions') {
828
+ const nextLines = lineCount + newLineCount;
829
+ if (nextLines > MAX_CONVENTION_LINES) {
830
+ return { ok: false, reason: `conventions line cap: ${nextLines} nonempty lines would exceed ${MAX_CONVENTION_LINES}` };
831
+ }
832
+ return { ok: true, reason: 'within envelope' };
703
833
  }
704
- return { ok: true, reason: 'within envelope' };
834
+ throw new Error(`unknown envelope store "${store}"`);
705
835
  }
706
836
 
837
+ /**
838
+ * The two stores, counted separately: the human-promoted `rules/` files and
839
+ * the machine-written `conventions.md` bullets.
840
+ */
707
841
  export function countRulesAndLines({ rulesDir, conventionsPath }) {
708
842
  let ruleCount = 0;
709
- let lineCount = 0;
843
+ let ruleLineCount = 0;
710
844
  let names = [];
711
845
  try { names = fs.readdirSync(rulesDir); } catch (error) {
712
846
  if (!error || error.code !== 'ENOENT') throw error;
@@ -715,23 +849,27 @@ export function countRulesAndLines({ rulesDir, conventionsPath }) {
715
849
  if (!name.endsWith('.md')) continue;
716
850
  ruleCount += 1;
717
851
  try {
718
- lineCount += countNonEmptyLines(fs.readFileSync(path.join(rulesDir, name), 'utf8'));
852
+ ruleLineCount += countNonEmptyLines(fs.readFileSync(path.join(rulesDir, name), 'utf8'));
719
853
  } catch (error) {
720
854
  if (!error || error.code !== 'ENOENT') {
721
855
  throw new Error(`unreadable rule ${name}: ${error.message}`);
722
856
  }
723
857
  }
724
858
  }
859
+ let conventionLineCount = 0;
725
860
  if (conventionsPath) {
726
861
  try {
727
- lineCount += countNonEmptyLines(fs.readFileSync(conventionsPath, 'utf8'));
862
+ conventionLineCount = countNonEmptyLines(fs.readFileSync(conventionsPath, 'utf8'));
728
863
  } catch (error) {
729
864
  if (!error || error.code !== 'ENOENT') {
730
865
  throw new Error(`unreadable conventions: ${error.message}`);
731
866
  }
732
867
  }
733
868
  }
734
- return { ruleCount, lineCount };
869
+ return {
870
+ rules: { ruleCount, lineCount: ruleLineCount },
871
+ conventions: { lineCount: conventionLineCount },
872
+ };
735
873
  }
736
874
 
737
875
  // --- Conventions edit --------------------------------------------------------
@@ -1038,8 +1176,8 @@ function planConventions(ctx, decision) {
1038
1176
  };
1039
1177
  }
1040
1178
  const envelope = evaluateEnvelope({
1041
- ruleCount: ctx.envelope.ruleCount,
1042
- lineCount: ctx.envelope.lineCount,
1179
+ store: 'conventions',
1180
+ lineCount: ctx.envelope.conventions.lineCount,
1043
1181
  newLineCount: addedLines,
1044
1182
  });
1045
1183
  if (!envelope.ok) return { type: 'blocked', reason: envelope.reason, action: 'conventions-added' };
@@ -1091,6 +1229,7 @@ function hasOpenStage(entries, signature) {
1091
1229
  || entry.action === 'rule-created'
1092
1230
  || entry.action === 'applied'
1093
1231
  || entry.action === 'rejected'
1232
+ || entry.action === 'seed-promoted'
1094
1233
  ) open = false;
1095
1234
  }
1096
1235
  return open;
@@ -1146,6 +1285,12 @@ function stageNewRule({ decision, ctx, prior, ledgerPath, now, staged, rulesDir,
1146
1285
  const seed = planSeed(ctx, decision);
1147
1286
  const existing = readExisting(seed.target);
1148
1287
  if (existing !== null) {
1288
+ // The reviewed snapshot is the seed body without its provenance line, so
1289
+ // the ledger row and the file never disagree about what was reviewed.
1290
+ // An existing seed is left byte-for-byte alone: a file the engine never
1291
+ // wrote (an `init`-seeded template copy) must not carry a machine-authorship
1292
+ // claim.
1293
+ const reviewed = stripProvenanceFooter(existing);
1149
1294
  appendStage({
1150
1295
  prior,
1151
1296
  ledgerPath,
@@ -1153,7 +1298,7 @@ function stageNewRule({ decision, ctx, prior, ledgerPath, now, staged, rulesDir,
1153
1298
  action: 'seed-staged',
1154
1299
  target: seed.target,
1155
1300
  before: existing,
1156
- after: existing,
1301
+ after: reviewed,
1157
1302
  now,
1158
1303
  staged,
1159
1304
  reason: 'seed already staged',
@@ -1162,12 +1307,32 @@ function stageNewRule({ decision, ctx, prior, ledgerPath, now, staged, rulesDir,
1162
1307
  return;
1163
1308
  }
1164
1309
  const reason = decision.compliance ?? (band.verdict === 'stage' ? band.reason : 'new rule staged for human promote');
1310
+ // The engine writes the provenance footer; the ledger row keeps the reviewed
1311
+ // body, so the footer can never make the row and the file disagree.
1312
+ const stagedAt = now();
1313
+ const seedFile = withProvenanceFooter(seed.content, {
1314
+ signature: decision.signature,
1315
+ stagedAt,
1316
+ sourceSlug: sourceSlugFor(decision),
1317
+ });
1165
1318
  const entry = ledgerEntry(decision, 'seed-staged', seed.target, null, seed.content, now);
1166
- commitWrite({ ledgerPath, target: seed.target, content: seed.content, entry, roots });
1319
+ commitWrite({ ledgerPath, target: seed.target, content: seedFile, entry, roots });
1167
1320
  prior.push(entry);
1168
1321
  staged.push({ signature: decision.signature, target: seed.target, reason });
1169
1322
  }
1170
1323
 
1324
+ /**
1325
+ * The task slug the seed came from. The signal store validates it as
1326
+ * kebab-case, so the footer's slug field stays bounded (guard 1).
1327
+ */
1328
+ function sourceSlugFor(decision) {
1329
+ for (const slug of decision.slugs ?? []) {
1330
+ if (typeof slug === 'string' && KEBAB_SLUG_RE.test(slug)) return slug;
1331
+ }
1332
+ if (KEBAB_SLUG_RE.test(decision.slug)) return decision.slug;
1333
+ return decision.stem;
1334
+ }
1335
+
1171
1336
  function entrySlugs(entry) {
1172
1337
  const slugs = [];
1173
1338
  if (Array.isArray(entry?.slugs)) {
@@ -1216,6 +1381,7 @@ function hasOpenPendingLesson(entries, signature) {
1216
1381
  else if (
1217
1382
  entry.action === 'staged'
1218
1383
  || entry.action === 'seed-staged'
1384
+ || entry.action === 'seed-promoted'
1219
1385
  || entry.action === 'conventions-added'
1220
1386
  || entry.action === 'rollback'
1221
1387
  ) open = false;
@@ -1502,7 +1668,7 @@ export function runImprover(options = {}) {
1502
1668
  let applySkipped = [];
1503
1669
  let unloaded = [];
1504
1670
  let applyErrors = [];
1505
- let envelope = { ruleCount: 0, lineCount: 0 };
1671
+ let envelope = { rules: { ruleCount: 0, lineCount: 0 }, conventions: { lineCount: 0 } };
1506
1672
  try {
1507
1673
  ({ applied, staged, skipped: applySkipped, unloaded, envelope, errors: applyErrors } = applyDecisionsUnderLock({
1508
1674
  decisions,
@@ -1559,6 +1725,138 @@ function renderTarget(target, roots) {
1559
1725
  }
1560
1726
  }
1561
1727
 
1728
+ /**
1729
+ * The open `seed-staged` row of a staged seed, or null when the seed has no
1730
+ * open stage row (a seed without a row was never reviewed by the engine).
1731
+ */
1732
+ function findOpenSeedStage(entries, seedPath, roots) {
1733
+ const wanted = toLedgerTarget(seedPath, roots.repo);
1734
+ let found = null;
1735
+ for (const entry of entries) {
1736
+ if (!entry || entry.action !== 'seed-staged') continue;
1737
+ if (entry.target !== wanted) continue;
1738
+ found = entry;
1739
+ }
1740
+ if (!found) return null;
1741
+ if (!hasOpenStage(entries, found.signature)) return null;
1742
+ return found;
1743
+ }
1744
+
1745
+ /**
1746
+ * Promote a staged seed into `.ai.local/rules/`.
1747
+ *
1748
+ * The promotion is one auditable operation: locate the seed and its open
1749
+ * `seed-staged` row, strip the provenance footer, write the rule, remove the
1750
+ * seed and append the `seed-promoted` row. The row binds the promoted file to
1751
+ * the reviewed snapshot (the `seed-staged` row's `after`); a seed edited
1752
+ * between staging and promotion is recorded as a divergence, not refused.
1753
+ */
1754
+ export function runPromotion(options = {}) {
1755
+ const stem = options.stem;
1756
+ const baseDir = options.baseDir ?? path.join(process.cwd(), '.ai.local');
1757
+ const rulesDir = options.rulesDir ?? path.join(baseDir, 'rules');
1758
+ const libraryDir = options.libraryDir ?? path.join(baseDir, 'rules-library');
1759
+ const ledgerPath = options.ledgerPath ?? path.join(baseDir, 'rule-changes.jsonl');
1760
+ const lockPath = options.lockPath ?? path.join(baseDir, '.rules.lock');
1761
+ const now = options.now ?? (() => new Date().toISOString());
1762
+ const roots = resolveRoots(ledgerPath, options);
1763
+
1764
+ const refuse = (reason) => ({
1765
+ ok: false,
1766
+ stem,
1767
+ reason,
1768
+ report: `Seed promotion\nstem: ${stem}\nrefused: ${reason}\n`,
1769
+ });
1770
+
1771
+ if (typeof stem !== 'string' || stem === '') return refuse('no stem given');
1772
+ try {
1773
+ validateStem(stem);
1774
+ } catch (error) {
1775
+ return refuse(error instanceof Error ? error.message : String(error));
1776
+ }
1777
+
1778
+ const seedPath = path.join(libraryDir, `${stem}.md`);
1779
+ const rulePath = path.join(rulesDir, `${stem}.md`);
1780
+ const token = acquireLock(lockPath);
1781
+ try {
1782
+ const recovery = recoverPendingCommit(ledgerPath, roots);
1783
+ if (recovery?.recovered === 'conflict') {
1784
+ return refuse('a previous commit intent matches neither the previous nor the written file');
1785
+ }
1786
+ const seedContent = readExisting(seedPath);
1787
+ if (seedContent === null) return refuse(`no staged seed at ${renderTarget(seedPath, roots)}`);
1788
+ const promoted = stripProvenanceFooter(seedContent);
1789
+ const prior = parseLedger(readExisting(ledgerPath) ?? '');
1790
+ const stageRow = findOpenSeedStage(prior, seedPath, roots);
1791
+ if (!stageRow) return refuse(`no open seed-staged ledger row for "${stem}"`);
1792
+ if (readExisting(rulePath) !== null) return refuse(`a rule named "${stem}" is already active`);
1793
+
1794
+ const counts = countRulesAndLines({ rulesDir, conventionsPath: null });
1795
+ const envelope = evaluateEnvelope({
1796
+ store: 'rules',
1797
+ ruleCount: counts.rules.ruleCount,
1798
+ lineCount: counts.rules.lineCount,
1799
+ newRuleCount: 1,
1800
+ newLineCount: countNonEmptyLines(promoted),
1801
+ });
1802
+ if (!envelope.ok) return refuse(envelope.reason);
1803
+
1804
+ const reviewed = typeof stageRow.after === 'string' ? stageRow.after : promoted;
1805
+ const divergence = reviewed !== promoted;
1806
+ const entry = {
1807
+ signature: stageRow.signature,
1808
+ action: 'seed-promoted',
1809
+ target: rulePath,
1810
+ before: reviewed,
1811
+ after: promoted,
1812
+ at: now(),
1813
+ agent: stageRow.agent,
1814
+ slug: stageRow.slug,
1815
+ slugs: Array.isArray(stageRow.slugs) ? [...stageRow.slugs] : [],
1816
+ };
1817
+ try {
1818
+ commitPromotion({
1819
+ ledgerPath,
1820
+ ruleTarget: rulePath,
1821
+ ruleContent: promoted,
1822
+ seedTarget: seedPath,
1823
+ entry,
1824
+ roots,
1825
+ });
1826
+ } catch (error) {
1827
+ const reason = error instanceof Error ? error.message : String(error);
1828
+ return refuse(
1829
+ `the promotion write failed: ${reason}. The commit intent is retained; ` +
1830
+ 'run `node .ai.local/scripts/run.mjs` to finish or drop it',
1831
+ );
1832
+ }
1833
+
1834
+ const lines = [
1835
+ 'Seed promotion',
1836
+ `stem: ${stem}`,
1837
+ `promoted: ${renderTarget(rulePath, roots)}`,
1838
+ `seed removed: ${renderTarget(seedPath, roots)}`,
1839
+ `ledger: seed-promoted (${stageRow.signature})`,
1840
+ divergence
1841
+ ? 'divergence: the seed changed between staging and promotion — recorded in the ledger row'
1842
+ : 'divergence: none',
1843
+ ];
1844
+ return {
1845
+ ok: true,
1846
+ stem,
1847
+ signature: stageRow.signature,
1848
+ target: rulePath,
1849
+ seedTarget: seedPath,
1850
+ reviewed,
1851
+ promoted,
1852
+ divergence,
1853
+ report: `${lines.join('\n')}\n`,
1854
+ };
1855
+ } finally {
1856
+ releaseLock(lockPath, token);
1857
+ }
1858
+ }
1859
+
1562
1860
  function appendSkipGroup(lines, items, heading) {
1563
1861
  if (items.length === 0) return;
1564
1862
  lines.push('', heading);
@@ -1568,7 +1866,8 @@ function appendSkipGroup(lines, items, heading) {
1568
1866
  function renderReport({ applied, staged, skipped, rejected, unloaded = [], errors, envelope, roots }) {
1569
1867
  const lines = [
1570
1868
  'Self-learning rule improver',
1571
- `envelope: ${envelope.ruleCount}/${MAX_ACTIVE_RULES} rules, ${envelope.lineCount}/${MAX_TOTAL_LINES} lines`,
1869
+ `rules envelope: ${envelope.rules.lineCount}/${MAX_RULE_LINES} lines, ${envelope.rules.ruleCount}/${MAX_ACTIVE_RULES} rules`,
1870
+ `conventions envelope: ${envelope.conventions.lineCount}/${MAX_CONVENTION_LINES} lines`,
1572
1871
  '',
1573
1872
  `applied (${applied.length}) — auto, low-risk, reversible`,
1574
1873
  ];
@@ -1598,6 +1897,14 @@ function renderReport({ applied, staged, skipped, rejected, unloaded = [], error
1598
1897
  }
1599
1898
 
1600
1899
  // CLI entry: run directly (node rule-improver.mjs) and print the report.
1900
+ // `--promote <stem>` promotes a staged seed into `.ai.local/rules/`.
1601
1901
  if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
1602
- process.stdout.write(runImprover().report);
1902
+ const promoteIndex = process.argv.indexOf('--promote');
1903
+ if (promoteIndex !== -1) {
1904
+ const result = runPromotion({ stem: process.argv[promoteIndex + 1] });
1905
+ process.stdout.write(result.report);
1906
+ if (!result.ok) process.exitCode = 1;
1907
+ } else {
1908
+ process.stdout.write(runImprover().report);
1909
+ }
1603
1910
  }
@@ -29,7 +29,8 @@ import { pathToFileURL } from 'node:url';
29
29
  import { appendSignal, groupSignatures, isSignalRecord } from './signals.mjs';
30
30
  import {
31
31
  MAX_ACTIVE_RULES,
32
- MAX_TOTAL_LINES,
32
+ MAX_RULE_LINES,
33
+ MAX_CONVENTION_LINES,
33
34
  canonicalSignature,
34
35
  collectScriptReport,
35
36
  countRulesAndLines,
@@ -236,14 +237,27 @@ export function statusReport({ baseDir = DEFAULT_BASE_DIR } = {}) {
236
237
 
237
238
  // The engine fails closed on an unreadable rule; the read-only report must
238
239
  // still print, so the envelope degrades to `unreadable` instead of throwing.
240
+ // Two stores, two envelopes: the human `rules/` store and the machine
241
+ // `conventions.md` store each carry their own cap.
239
242
  let envelope;
240
- let envelopeState;
243
+ let rulesState;
244
+ let conventionsState;
241
245
  try {
242
246
  envelope = countRulesAndLines({ rulesDir, conventionsPath });
243
- envelopeState = evaluateEnvelope({ ruleCount: envelope.ruleCount, lineCount: envelope.lineCount });
247
+ rulesState = evaluateEnvelope({
248
+ store: 'rules',
249
+ ruleCount: envelope.rules.ruleCount,
250
+ lineCount: envelope.rules.lineCount,
251
+ });
252
+ conventionsState = evaluateEnvelope({
253
+ store: 'conventions',
254
+ lineCount: envelope.conventions.lineCount,
255
+ });
244
256
  } catch (error) {
245
- envelope = { ruleCount: 0, lineCount: 0 };
246
- envelopeState = { reason: `unreadable — ${error instanceof Error ? error.message : String(error)}` };
257
+ envelope = { rules: { ruleCount: 0, lineCount: 0 }, conventions: { lineCount: 0 } };
258
+ const reason = `unreadable — ${error instanceof Error ? error.message : String(error)}`;
259
+ rulesState = { reason };
260
+ conventionsState = { reason };
247
261
  }
248
262
  const pending = deriveGateSignals({ baseDir }).signals.length;
249
263
 
@@ -251,7 +265,8 @@ export function statusReport({ baseDir = DEFAULT_BASE_DIR } = {}) {
251
265
  lines.push(`store: ${storeState}`);
252
266
  lines.push(`pending derivations: ${pending}` + (pending > 0 ? ' (evidence not captured yet)' : ''));
253
267
  lines.push(
254
- `envelope: ${envelope.ruleCount}/${MAX_ACTIVE_RULES} rules, ${envelope.lineCount}/${MAX_TOTAL_LINES} lines — ${envelopeState.reason}`,
268
+ `rules envelope: ${envelope.rules.lineCount}/${MAX_RULE_LINES} lines, ${envelope.rules.ruleCount}/${MAX_ACTIVE_RULES} rules — ${rulesState.reason}`,
269
+ `conventions envelope: ${envelope.conventions.lineCount}/${MAX_CONVENTION_LINES} lines — ${conventionsState.reason}`,
255
270
  );
256
271
  for (const error of errors) {
257
272
  lines.push(` - malformed store line ${error.line}: ${error.reason}`);
@@ -903,6 +903,7 @@ const getHealth = (handle, settings) => {
903
903
  },
904
904
  tasks: { total: Number(totals.total), absent: Number(totals.absent) },
905
905
  projectedAt: totals.projected_at ?? null,
906
+ capabilities: ['sync', 'delete'],
906
907
  };
907
908
  };
908
909
 
@@ -624,8 +624,12 @@ const schemas = {
624
624
  ['total', 'absent'],
625
625
  ),
626
626
  projectedAt: nullable('string'),
627
+ capabilities: {
628
+ type: 'array',
629
+ items: { type: 'string', enum: ['sync', 'delete'] },
630
+ },
627
631
  },
628
- ['status', 'db', 'tasks', 'projectedAt'],
632
+ ['status', 'db', 'tasks', 'projectedAt', 'capabilities'],
629
633
  ),
630
634
  Migration: object(
631
635
  {
@@ -934,6 +938,7 @@ const EXAMPLES = {
934
938
  db: { file: 'team.db', present: true, schemaVersion: 1, fingerprintOk: true, search: 'fts5' },
935
939
  tasks: { total: 90, absent: 0 },
936
940
  projectedAt: '2026-11-06T08:00:04.000Z',
941
+ capabilities: ['sync', 'delete'],
937
942
  },
938
943
  ],
939
944
  Meta: [
@@ -1609,7 +1609,7 @@ export function deleteTaskProjection(options = {}) {
1609
1609
  teamDbFail('E_DISABLED', 'disabled by AI_RULES_TEAM_DB_DISABLE', 1);
1610
1610
  }
1611
1611
  if (!SLUG_RE.test(slug)) {
1612
- teamDbFail('E_USAGE', `delete needs a slug matching ${SLUG_RE.source}`, 3);
1612
+ teamDbFail('E_USAGE', `delete needs --slug matching ${SLUG_RE.source}`, 3);
1613
1613
  }
1614
1614
  const teamRoot = path.resolve(options.teamRoot || process.env.AI_RULES_TEAM_DB_ROOT || DEFAULT_TEAM_ROOT);
1615
1615
  const tasksRoot = path.join(teamRoot, 'tasks');