@bonesofspring/ai-rules 0.2.42 → 0.2.44

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 (468) hide show
  1. package/CHANGELOG.md +48 -1
  2. package/bin/lib/seed-ai-local-team.js +41 -4
  3. package/docs/LOCAL-OVERLAY.md +6 -4
  4. package/docs/PRESET-CONTRIBUTION.md +2 -2
  5. package/docs/PRESET-ENGLISH-STYLE.md +1 -1
  6. package/docs/specs/INDEX.md +3 -1
  7. package/docs/specs/_templates/feature.md +6 -0
  8. package/package.json +1 -1
  9. package/presets/_shared/README.md +1 -1
  10. package/presets/_shared/assets/docs-specs/_templates/feature.md +6 -0
  11. package/presets/_shared/core/agent-team/agent-artifact-contracts.md +1 -1
  12. package/presets/_shared/core/agent-team/agent-team-intake.md +1 -1
  13. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +23 -7
  14. package/presets/_shared/core/agent-team/language-policy.md +24 -16
  15. package/presets/_shared/core/agent-team/plan-graph.md +9 -1
  16. package/presets/_shared/core/quality/anti-hallucination-contract.md +2 -0
  17. package/presets/_shared/core/quality/context-and-iteration.md +2 -1
  18. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +1080 -4
  19. package/presets/claude/android-kotlin/REPO_AGENTS.md +1 -3
  20. package/presets/claude/android-kotlin/commands/task-continue.md +1 -1
  21. package/presets/claude/android-kotlin/commands/task.md +1 -3
  22. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +1080 -4
  23. package/presets/claude/android-kotlin/rules/stack/android-app-core.md +1 -3
  24. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-intake.md +1 -1
  25. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  26. package/presets/claude/android-kotlin/rules/tooling-and-review/ai-local-overlay.md +1 -1
  27. package/presets/claude/android-kotlin/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  28. package/presets/claude/android-kotlin/rules/tooling-and-review/language-policy.md +25 -17
  29. package/presets/claude/go/REPO_AGENTS.md +1 -3
  30. package/presets/claude/go/commands/task-continue.md +1 -1
  31. package/presets/claude/go/commands/task.md +1 -3
  32. package/presets/claude/go/hooks/chain-team-phases.sh +1080 -4
  33. package/presets/claude/go/rules/stack/go-app-core.md +1 -3
  34. package/presets/claude/go/rules/tooling-and-review/agent-team-intake.md +1 -1
  35. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  36. package/presets/claude/go/rules/tooling-and-review/ai-local-overlay.md +1 -1
  37. package/presets/claude/go/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  38. package/presets/claude/go/rules/tooling-and-review/language-policy.md +25 -17
  39. package/presets/claude/ios-swift/REPO_AGENTS.md +1 -3
  40. package/presets/claude/ios-swift/commands/task-continue.md +1 -1
  41. package/presets/claude/ios-swift/commands/task.md +1 -3
  42. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +1080 -4
  43. package/presets/claude/ios-swift/rules/stack/ios-app-core.md +1 -3
  44. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-intake.md +1 -1
  45. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  46. package/presets/claude/ios-swift/rules/tooling-and-review/ai-local-overlay.md +1 -1
  47. package/presets/claude/ios-swift/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  48. package/presets/claude/ios-swift/rules/tooling-and-review/language-policy.md +25 -17
  49. package/presets/claude/java/REPO_AGENTS.md +1 -3
  50. package/presets/claude/java/commands/task-continue.md +1 -1
  51. package/presets/claude/java/commands/task.md +1 -3
  52. package/presets/claude/java/hooks/chain-team-phases.sh +1080 -4
  53. package/presets/claude/java/rules/stack/java-app-core.md +1 -3
  54. package/presets/claude/java/rules/tooling-and-review/agent-team-intake.md +1 -1
  55. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  56. package/presets/claude/java/rules/tooling-and-review/ai-local-overlay.md +1 -1
  57. package/presets/claude/java/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  58. package/presets/claude/java/rules/tooling-and-review/language-policy.md +25 -17
  59. package/presets/claude/mcp-ts/REPO_AGENTS.md +1 -3
  60. package/presets/claude/mcp-ts/commands/task-continue.md +1 -1
  61. package/presets/claude/mcp-ts/commands/task.md +1 -3
  62. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +1080 -4
  63. package/presets/claude/mcp-ts/rules/stack/mcp-ts-app-core.md +1 -3
  64. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-intake.md +1 -1
  65. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  66. package/presets/claude/mcp-ts/rules/tooling-and-review/ai-local-overlay.md +1 -1
  67. package/presets/claude/mcp-ts/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  68. package/presets/claude/mcp-ts/rules/tooling-and-review/language-policy.md +25 -17
  69. package/presets/claude/next/REPO_AGENTS.md +2 -4
  70. package/presets/claude/next/agents/openspec-author.md +26 -2
  71. package/presets/claude/next/agents/task-analyst.md +15 -6
  72. package/presets/claude/next/agents/task-router.md +20 -2
  73. package/presets/{cursor/next/ai-local/rules-library → claude/next/ai-local/rules}/task-levels.md +2 -0
  74. package/presets/claude/next/commands/task-continue.md +1 -1
  75. package/presets/claude/next/commands/task.md +1 -3
  76. package/presets/claude/next/hooks/chain-team-phases.sh +1080 -4
  77. package/presets/claude/next/rules/stack/next-app-core.md +1 -3
  78. package/presets/claude/next/rules/tooling-and-review/agent-team-intake.md +1 -1
  79. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  80. package/presets/claude/next/rules/tooling-and-review/ai-local-overlay.md +2 -2
  81. package/presets/claude/next/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  82. package/presets/claude/next/rules/tooling-and-review/language-policy.md +25 -17
  83. package/presets/claude/nuxt/REPO_AGENTS.md +1 -3
  84. package/presets/claude/nuxt/agents/README.md +1 -1
  85. package/presets/claude/nuxt/commands/task-continue.md +1 -1
  86. package/presets/claude/nuxt/commands/task.md +1 -3
  87. package/presets/claude/nuxt/hooks/chain-team-phases.sh +1080 -4
  88. package/presets/claude/nuxt/rules/stack/nuxt-app-core.md +1 -3
  89. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-intake.md +1 -1
  90. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  91. package/presets/claude/nuxt/rules/tooling-and-review/ai-local-overlay.md +1 -1
  92. package/presets/claude/nuxt/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  93. package/presets/claude/nuxt/rules/tooling-and-review/language-policy.md +25 -17
  94. package/presets/claude/php-hexagonal/REPO_AGENTS.md +1 -3
  95. package/presets/claude/php-hexagonal/commands/task-continue.md +1 -1
  96. package/presets/claude/php-hexagonal/commands/task.md +1 -3
  97. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +1080 -4
  98. package/presets/claude/php-hexagonal/rules/stack/php-app-core.md +1 -3
  99. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-intake.md +1 -1
  100. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  101. package/presets/claude/php-hexagonal/rules/tooling-and-review/ai-local-overlay.md +1 -1
  102. package/presets/claude/php-hexagonal/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  103. package/presets/claude/php-hexagonal/rules/tooling-and-review/language-policy.md +25 -17
  104. package/presets/claude/php-laravel/REPO_AGENTS.md +1 -3
  105. package/presets/claude/php-laravel/commands/task-continue.md +1 -1
  106. package/presets/claude/php-laravel/commands/task.md +1 -3
  107. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +1080 -4
  108. package/presets/claude/php-laravel/rules/stack/laravel-app-core.md +1 -3
  109. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-intake.md +1 -1
  110. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  111. package/presets/claude/php-laravel/rules/tooling-and-review/ai-local-overlay.md +1 -1
  112. package/presets/claude/php-laravel/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  113. package/presets/claude/php-laravel/rules/tooling-and-review/language-policy.md +25 -17
  114. package/presets/claude/svelte/REPO_AGENTS.md +1 -3
  115. package/presets/claude/svelte/agents/README.md +1 -1
  116. package/presets/claude/svelte/commands/task-continue.md +1 -1
  117. package/presets/claude/svelte/commands/task.md +1 -3
  118. package/presets/claude/svelte/hooks/chain-team-phases.sh +1080 -4
  119. package/presets/claude/svelte/rules/stack/svelte-app-core.md +1 -3
  120. package/presets/claude/svelte/rules/tooling-and-review/agent-team-intake.md +1 -1
  121. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +23 -7
  122. package/presets/claude/svelte/rules/tooling-and-review/ai-local-overlay.md +1 -1
  123. package/presets/claude/svelte/rules/tooling-and-review/anti-hallucination-contract.md +2 -0
  124. package/presets/claude/svelte/rules/tooling-and-review/language-policy.md +25 -17
  125. package/presets/cursor/android-kotlin/REPO_AGENTS.md +1 -3
  126. package/presets/cursor/android-kotlin/commands/task-continue.md +1 -1
  127. package/presets/cursor/android-kotlin/commands/task.md +1 -3
  128. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +1080 -4
  129. package/presets/cursor/android-kotlin/rules/agent-team-intake.mdc +1 -1
  130. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +2 -9
  131. package/presets/cursor/android-kotlin/rules/ai-local-overlay.mdc +1 -1
  132. package/presets/cursor/android-kotlin/rules/android-app-core.mdc +1 -3
  133. package/presets/cursor/android-kotlin/rules/anti-hallucination-contract.mdc +2 -0
  134. package/presets/cursor/android-kotlin/rules/language-policy.mdc +25 -17
  135. package/presets/cursor/go/REPO_AGENTS.md +1 -3
  136. package/presets/cursor/go/commands/task-continue.md +1 -1
  137. package/presets/cursor/go/commands/task.md +1 -3
  138. package/presets/cursor/go/hooks/chain-team-phases.sh +1080 -4
  139. package/presets/cursor/go/rules/agent-team-intake.mdc +1 -1
  140. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +2 -9
  141. package/presets/cursor/go/rules/ai-local-overlay.mdc +1 -1
  142. package/presets/cursor/go/rules/anti-hallucination-contract.mdc +2 -0
  143. package/presets/cursor/go/rules/go-app-core.mdc +1 -3
  144. package/presets/cursor/go/rules/language-policy.mdc +25 -17
  145. package/presets/cursor/ios-swift/REPO_AGENTS.md +1 -3
  146. package/presets/cursor/ios-swift/commands/task-continue.md +1 -1
  147. package/presets/cursor/ios-swift/commands/task.md +1 -3
  148. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +1080 -4
  149. package/presets/cursor/ios-swift/rules/agent-team-intake.mdc +1 -1
  150. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +2 -9
  151. package/presets/cursor/ios-swift/rules/ai-local-overlay.mdc +1 -1
  152. package/presets/cursor/ios-swift/rules/anti-hallucination-contract.mdc +2 -0
  153. package/presets/cursor/ios-swift/rules/ios-app-core.mdc +1 -3
  154. package/presets/cursor/ios-swift/rules/language-policy.mdc +25 -17
  155. package/presets/cursor/java/REPO_AGENTS.md +1 -3
  156. package/presets/cursor/java/commands/task-continue.md +1 -1
  157. package/presets/cursor/java/commands/task.md +1 -3
  158. package/presets/cursor/java/hooks/chain-team-phases.sh +1080 -4
  159. package/presets/cursor/java/rules/agent-team-intake.mdc +1 -1
  160. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +2 -9
  161. package/presets/cursor/java/rules/ai-local-overlay.mdc +1 -1
  162. package/presets/cursor/java/rules/anti-hallucination-contract.mdc +2 -0
  163. package/presets/cursor/java/rules/java-app-core.mdc +1 -3
  164. package/presets/cursor/java/rules/language-policy.mdc +25 -17
  165. package/presets/cursor/mcp-ts/REPO_AGENTS.md +1 -3
  166. package/presets/cursor/mcp-ts/commands/task-continue.md +1 -1
  167. package/presets/cursor/mcp-ts/commands/task.md +1 -3
  168. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +1080 -4
  169. package/presets/cursor/mcp-ts/rules/agent-team-intake.mdc +1 -1
  170. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +2 -9
  171. package/presets/cursor/mcp-ts/rules/ai-local-overlay.mdc +1 -1
  172. package/presets/cursor/mcp-ts/rules/anti-hallucination-contract.mdc +2 -0
  173. package/presets/cursor/mcp-ts/rules/language-policy.mdc +25 -17
  174. package/presets/cursor/mcp-ts/rules/mcp-ts-app-core.mdc +1 -3
  175. package/presets/cursor/next/REPO_AGENTS.md +2 -4
  176. package/presets/cursor/next/agents/README.md +1 -1
  177. package/presets/cursor/next/agents/build-verifier.md +2 -0
  178. package/presets/cursor/next/agents/feature-developer.md +9 -0
  179. package/presets/cursor/next/agents/openspec-author.md +26 -2
  180. package/presets/cursor/next/agents/task-analyst.md +20 -6
  181. package/presets/cursor/next/agents/task-router.md +31 -2
  182. package/presets/cursor/next/ai-local/conventions.md +20 -0
  183. package/presets/{mavis/next/ai-local/rules-library → cursor/next/ai-local/rules}/task-levels.md +12 -0
  184. package/presets/cursor/next/commands/task-continue.md +1 -1
  185. package/presets/cursor/next/commands/task.md +1 -3
  186. package/presets/cursor/next/hooks/chain-team-phases.sh +1080 -4
  187. package/presets/cursor/next/rules/agent-team-intake.mdc +1 -1
  188. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +20 -11
  189. package/presets/cursor/next/rules/ai-local-overlay.mdc +2 -2
  190. package/presets/cursor/next/rules/anti-hallucination-contract.mdc +2 -0
  191. package/presets/cursor/next/rules/language-policy.mdc +25 -17
  192. package/presets/cursor/next/rules/next-app-core.mdc +1 -3
  193. package/presets/cursor/nuxt/REPO_AGENTS.md +1 -3
  194. package/presets/cursor/nuxt/agents/README.md +1 -1
  195. package/presets/cursor/nuxt/commands/task-continue.md +1 -1
  196. package/presets/cursor/nuxt/commands/task.md +1 -3
  197. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +1080 -4
  198. package/presets/cursor/nuxt/rules/agent-team-intake.mdc +1 -1
  199. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +2 -9
  200. package/presets/cursor/nuxt/rules/ai-local-overlay.mdc +1 -1
  201. package/presets/cursor/nuxt/rules/anti-hallucination-contract.mdc +2 -0
  202. package/presets/cursor/nuxt/rules/language-policy.mdc +25 -17
  203. package/presets/cursor/nuxt/rules/nuxt-app-core.mdc +1 -3
  204. package/presets/cursor/php-hexagonal/REPO_AGENTS.md +1 -3
  205. package/presets/cursor/php-hexagonal/commands/task-continue.md +1 -1
  206. package/presets/cursor/php-hexagonal/commands/task.md +1 -3
  207. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +1080 -4
  208. package/presets/cursor/php-hexagonal/rules/agent-team-intake.mdc +1 -1
  209. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +2 -9
  210. package/presets/cursor/php-hexagonal/rules/ai-local-overlay.mdc +1 -1
  211. package/presets/cursor/php-hexagonal/rules/anti-hallucination-contract.mdc +2 -0
  212. package/presets/cursor/php-hexagonal/rules/language-policy.mdc +25 -17
  213. package/presets/cursor/php-hexagonal/rules/php-app-core.mdc +1 -3
  214. package/presets/cursor/php-laravel/REPO_AGENTS.md +1 -3
  215. package/presets/cursor/php-laravel/commands/task-continue.md +1 -1
  216. package/presets/cursor/php-laravel/commands/task.md +1 -3
  217. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +1080 -4
  218. package/presets/cursor/php-laravel/rules/agent-team-intake.mdc +1 -1
  219. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +2 -9
  220. package/presets/cursor/php-laravel/rules/ai-local-overlay.mdc +1 -1
  221. package/presets/cursor/php-laravel/rules/anti-hallucination-contract.mdc +2 -0
  222. package/presets/cursor/php-laravel/rules/language-policy.mdc +25 -17
  223. package/presets/cursor/php-laravel/rules/laravel-app-core.mdc +1 -3
  224. package/presets/cursor/svelte/REPO_AGENTS.md +1 -3
  225. package/presets/cursor/svelte/agents/README.md +1 -1
  226. package/presets/cursor/svelte/commands/task-continue.md +1 -1
  227. package/presets/cursor/svelte/commands/task.md +1 -3
  228. package/presets/cursor/svelte/hooks/chain-team-phases.sh +1080 -4
  229. package/presets/cursor/svelte/rules/agent-team-intake.mdc +1 -1
  230. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +2 -9
  231. package/presets/cursor/svelte/rules/ai-local-overlay.mdc +1 -1
  232. package/presets/cursor/svelte/rules/anti-hallucination-contract.mdc +2 -0
  233. package/presets/cursor/svelte/rules/language-policy.mdc +25 -17
  234. package/presets/cursor/svelte/rules/svelte-app-core.mdc +1 -3
  235. package/presets/mavis/android-kotlin/REPO_AGENTS.md +1 -3
  236. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  237. package/presets/mavis/android-kotlin/commands/task-continue.md +1 -1
  238. package/presets/mavis/android-kotlin/commands/task.md +1 -3
  239. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +1080 -4
  240. package/presets/mavis/android-kotlin/rules/agent-team-intake.md +1 -1
  241. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +23 -7
  242. package/presets/mavis/android-kotlin/rules/ai-local-overlay.md +1 -1
  243. package/presets/mavis/android-kotlin/rules/android-app-core.md +1 -3
  244. package/presets/mavis/android-kotlin/rules/anti-hallucination-contract.md +2 -0
  245. package/presets/mavis/android-kotlin/rules/language-policy.md +24 -16
  246. package/presets/mavis/go/REPO_AGENTS.md +1 -3
  247. package/presets/mavis/go/adapter-map.json +1 -1
  248. package/presets/mavis/go/commands/task-continue.md +1 -1
  249. package/presets/mavis/go/commands/task.md +1 -3
  250. package/presets/mavis/go/hooks/chain-team-phases.sh +1080 -4
  251. package/presets/mavis/go/rules/agent-team-intake.md +1 -1
  252. package/presets/mavis/go/rules/agent-team-orchestrator.md +23 -7
  253. package/presets/mavis/go/rules/ai-local-overlay.md +1 -1
  254. package/presets/mavis/go/rules/anti-hallucination-contract.md +2 -0
  255. package/presets/mavis/go/rules/go-app-core.md +1 -3
  256. package/presets/mavis/go/rules/language-policy.md +24 -16
  257. package/presets/mavis/ios-swift/REPO_AGENTS.md +1 -3
  258. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  259. package/presets/mavis/ios-swift/commands/task-continue.md +1 -1
  260. package/presets/mavis/ios-swift/commands/task.md +1 -3
  261. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +1080 -4
  262. package/presets/mavis/ios-swift/rules/agent-team-intake.md +1 -1
  263. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +23 -7
  264. package/presets/mavis/ios-swift/rules/ai-local-overlay.md +1 -1
  265. package/presets/mavis/ios-swift/rules/anti-hallucination-contract.md +2 -0
  266. package/presets/mavis/ios-swift/rules/ios-app-core.md +1 -3
  267. package/presets/mavis/ios-swift/rules/language-policy.md +24 -16
  268. package/presets/mavis/java/REPO_AGENTS.md +1 -3
  269. package/presets/mavis/java/adapter-map.json +1 -1
  270. package/presets/mavis/java/commands/task-continue.md +1 -1
  271. package/presets/mavis/java/commands/task.md +1 -3
  272. package/presets/mavis/java/hooks/chain-team-phases.sh +1080 -4
  273. package/presets/mavis/java/rules/agent-team-intake.md +1 -1
  274. package/presets/mavis/java/rules/agent-team-orchestrator.md +23 -7
  275. package/presets/mavis/java/rules/ai-local-overlay.md +1 -1
  276. package/presets/mavis/java/rules/anti-hallucination-contract.md +2 -0
  277. package/presets/mavis/java/rules/java-app-core.md +1 -3
  278. package/presets/mavis/java/rules/language-policy.md +24 -16
  279. package/presets/mavis/mcp-ts/REPO_AGENTS.md +1 -3
  280. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  281. package/presets/mavis/mcp-ts/commands/task-continue.md +1 -1
  282. package/presets/mavis/mcp-ts/commands/task.md +1 -3
  283. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +1080 -4
  284. package/presets/mavis/mcp-ts/rules/agent-team-intake.md +1 -1
  285. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +23 -7
  286. package/presets/mavis/mcp-ts/rules/ai-local-overlay.md +1 -1
  287. package/presets/mavis/mcp-ts/rules/anti-hallucination-contract.md +2 -0
  288. package/presets/mavis/mcp-ts/rules/language-policy.md +24 -16
  289. package/presets/mavis/mcp-ts/rules/mcp-ts-app-core.md +1 -3
  290. package/presets/mavis/next/REPO_AGENTS.md +2 -4
  291. package/presets/mavis/next/adapter-map.json +5 -5
  292. package/presets/mavis/next/agents/build-verifier.md +2 -0
  293. package/presets/mavis/next/agents/feature-developer.md +9 -0
  294. package/presets/mavis/next/agents/openspec-author.md +26 -2
  295. package/presets/mavis/next/agents/task-analyst.md +20 -6
  296. package/presets/mavis/next/agents/task-router.md +31 -2
  297. package/presets/mavis/next/ai-local/conventions.md +20 -0
  298. package/presets/{opencode/next/ai-local/rules-library → mavis/next/ai-local/rules}/task-levels.md +12 -0
  299. package/presets/mavis/next/commands/task-continue.md +1 -1
  300. package/presets/mavis/next/commands/task.md +1 -3
  301. package/presets/mavis/next/hooks/chain-team-phases.sh +1080 -4
  302. package/presets/mavis/next/rules/agent-team-intake.md +1 -1
  303. package/presets/mavis/next/rules/agent-team-orchestrator.md +23 -7
  304. package/presets/mavis/next/rules/ai-local-overlay.md +2 -2
  305. package/presets/mavis/next/rules/anti-hallucination-contract.md +2 -0
  306. package/presets/mavis/next/rules/language-policy.md +24 -16
  307. package/presets/mavis/next/rules/next-app-core.md +1 -3
  308. package/presets/mavis/nuxt/REPO_AGENTS.md +1 -3
  309. package/presets/mavis/nuxt/adapter-map.json +1 -1
  310. package/presets/mavis/nuxt/commands/task-continue.md +1 -1
  311. package/presets/mavis/nuxt/commands/task.md +1 -3
  312. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +1080 -4
  313. package/presets/mavis/nuxt/rules/agent-team-intake.md +1 -1
  314. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +23 -7
  315. package/presets/mavis/nuxt/rules/ai-local-overlay.md +1 -1
  316. package/presets/mavis/nuxt/rules/anti-hallucination-contract.md +2 -0
  317. package/presets/mavis/nuxt/rules/language-policy.md +24 -16
  318. package/presets/mavis/nuxt/rules/nuxt-app-core.md +1 -3
  319. package/presets/mavis/php-hexagonal/REPO_AGENTS.md +1 -3
  320. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  321. package/presets/mavis/php-hexagonal/commands/task-continue.md +1 -1
  322. package/presets/mavis/php-hexagonal/commands/task.md +1 -3
  323. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +1080 -4
  324. package/presets/mavis/php-hexagonal/rules/agent-team-intake.md +1 -1
  325. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +23 -7
  326. package/presets/mavis/php-hexagonal/rules/ai-local-overlay.md +1 -1
  327. package/presets/mavis/php-hexagonal/rules/anti-hallucination-contract.md +2 -0
  328. package/presets/mavis/php-hexagonal/rules/language-policy.md +24 -16
  329. package/presets/mavis/php-hexagonal/rules/php-app-core.md +1 -3
  330. package/presets/mavis/php-laravel/REPO_AGENTS.md +1 -3
  331. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  332. package/presets/mavis/php-laravel/commands/task-continue.md +1 -1
  333. package/presets/mavis/php-laravel/commands/task.md +1 -3
  334. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +1080 -4
  335. package/presets/mavis/php-laravel/rules/agent-team-intake.md +1 -1
  336. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +23 -7
  337. package/presets/mavis/php-laravel/rules/ai-local-overlay.md +1 -1
  338. package/presets/mavis/php-laravel/rules/anti-hallucination-contract.md +2 -0
  339. package/presets/mavis/php-laravel/rules/language-policy.md +24 -16
  340. package/presets/mavis/php-laravel/rules/laravel-app-core.md +1 -3
  341. package/presets/mavis/svelte/REPO_AGENTS.md +1 -3
  342. package/presets/mavis/svelte/adapter-map.json +1 -1
  343. package/presets/mavis/svelte/commands/task-continue.md +1 -1
  344. package/presets/mavis/svelte/commands/task.md +1 -3
  345. package/presets/mavis/svelte/hooks/chain-team-phases.sh +1080 -4
  346. package/presets/mavis/svelte/rules/agent-team-intake.md +1 -1
  347. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +23 -7
  348. package/presets/mavis/svelte/rules/ai-local-overlay.md +1 -1
  349. package/presets/mavis/svelte/rules/anti-hallucination-contract.md +2 -0
  350. package/presets/mavis/svelte/rules/language-policy.md +24 -16
  351. package/presets/mavis/svelte/rules/svelte-app-core.md +1 -3
  352. package/presets/opencode/android-kotlin/REPO_AGENTS.md +1 -3
  353. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  354. package/presets/opencode/android-kotlin/commands/task-continue.md +1 -1
  355. package/presets/opencode/android-kotlin/commands/task.md +1 -3
  356. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +1080 -4
  357. package/presets/opencode/android-kotlin/rules/agent-team-intake.md +1 -1
  358. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +23 -7
  359. package/presets/opencode/android-kotlin/rules/ai-local-overlay.md +1 -1
  360. package/presets/opencode/android-kotlin/rules/android-app-core.md +1 -3
  361. package/presets/opencode/android-kotlin/rules/anti-hallucination-contract.md +2 -0
  362. package/presets/opencode/android-kotlin/rules/language-policy.md +24 -16
  363. package/presets/opencode/go/REPO_AGENTS.md +1 -3
  364. package/presets/opencode/go/adapter-map.json +1 -1
  365. package/presets/opencode/go/commands/task-continue.md +1 -1
  366. package/presets/opencode/go/commands/task.md +1 -3
  367. package/presets/opencode/go/hooks/chain-team-phases.sh +1080 -4
  368. package/presets/opencode/go/rules/agent-team-intake.md +1 -1
  369. package/presets/opencode/go/rules/agent-team-orchestrator.md +23 -7
  370. package/presets/opencode/go/rules/ai-local-overlay.md +1 -1
  371. package/presets/opencode/go/rules/anti-hallucination-contract.md +2 -0
  372. package/presets/opencode/go/rules/go-app-core.md +1 -3
  373. package/presets/opencode/go/rules/language-policy.md +24 -16
  374. package/presets/opencode/ios-swift/REPO_AGENTS.md +1 -3
  375. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  376. package/presets/opencode/ios-swift/commands/task-continue.md +1 -1
  377. package/presets/opencode/ios-swift/commands/task.md +1 -3
  378. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +1080 -4
  379. package/presets/opencode/ios-swift/rules/agent-team-intake.md +1 -1
  380. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +23 -7
  381. package/presets/opencode/ios-swift/rules/ai-local-overlay.md +1 -1
  382. package/presets/opencode/ios-swift/rules/anti-hallucination-contract.md +2 -0
  383. package/presets/opencode/ios-swift/rules/ios-app-core.md +1 -3
  384. package/presets/opencode/ios-swift/rules/language-policy.md +24 -16
  385. package/presets/opencode/java/REPO_AGENTS.md +1 -3
  386. package/presets/opencode/java/adapter-map.json +1 -1
  387. package/presets/opencode/java/commands/task-continue.md +1 -1
  388. package/presets/opencode/java/commands/task.md +1 -3
  389. package/presets/opencode/java/hooks/chain-team-phases.sh +1080 -4
  390. package/presets/opencode/java/rules/agent-team-intake.md +1 -1
  391. package/presets/opencode/java/rules/agent-team-orchestrator.md +23 -7
  392. package/presets/opencode/java/rules/ai-local-overlay.md +1 -1
  393. package/presets/opencode/java/rules/anti-hallucination-contract.md +2 -0
  394. package/presets/opencode/java/rules/java-app-core.md +1 -3
  395. package/presets/opencode/java/rules/language-policy.md +24 -16
  396. package/presets/opencode/mcp-ts/REPO_AGENTS.md +1 -3
  397. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  398. package/presets/opencode/mcp-ts/commands/task-continue.md +1 -1
  399. package/presets/opencode/mcp-ts/commands/task.md +1 -3
  400. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +1080 -4
  401. package/presets/opencode/mcp-ts/rules/agent-team-intake.md +1 -1
  402. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +23 -7
  403. package/presets/opencode/mcp-ts/rules/ai-local-overlay.md +1 -1
  404. package/presets/opencode/mcp-ts/rules/anti-hallucination-contract.md +2 -0
  405. package/presets/opencode/mcp-ts/rules/language-policy.md +24 -16
  406. package/presets/opencode/mcp-ts/rules/mcp-ts-app-core.md +1 -3
  407. package/presets/opencode/next/REPO_AGENTS.md +2 -4
  408. package/presets/opencode/next/adapter-map.json +5 -5
  409. package/presets/opencode/next/agents/build-verifier.md +2 -0
  410. package/presets/opencode/next/agents/feature-developer.md +9 -0
  411. package/presets/opencode/next/agents/openspec-author.md +26 -2
  412. package/presets/opencode/next/agents/task-analyst.md +20 -6
  413. package/presets/opencode/next/agents/task-router.md +31 -2
  414. package/presets/opencode/next/ai-local/conventions.md +20 -0
  415. package/presets/opencode/next/ai-local/rules/task-levels.md +40 -0
  416. package/presets/opencode/next/commands/task-continue.md +1 -1
  417. package/presets/opencode/next/commands/task.md +1 -3
  418. package/presets/opencode/next/hooks/chain-team-phases.sh +1080 -4
  419. package/presets/opencode/next/rules/agent-team-intake.md +1 -1
  420. package/presets/opencode/next/rules/agent-team-orchestrator.md +23 -7
  421. package/presets/opencode/next/rules/ai-local-overlay.md +2 -2
  422. package/presets/opencode/next/rules/anti-hallucination-contract.md +2 -0
  423. package/presets/opencode/next/rules/language-policy.md +24 -16
  424. package/presets/opencode/next/rules/next-app-core.md +1 -3
  425. package/presets/opencode/nuxt/REPO_AGENTS.md +1 -3
  426. package/presets/opencode/nuxt/adapter-map.json +1 -1
  427. package/presets/opencode/nuxt/commands/task-continue.md +1 -1
  428. package/presets/opencode/nuxt/commands/task.md +1 -3
  429. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +1080 -4
  430. package/presets/opencode/nuxt/rules/agent-team-intake.md +1 -1
  431. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +23 -7
  432. package/presets/opencode/nuxt/rules/ai-local-overlay.md +1 -1
  433. package/presets/opencode/nuxt/rules/anti-hallucination-contract.md +2 -0
  434. package/presets/opencode/nuxt/rules/language-policy.md +24 -16
  435. package/presets/opencode/nuxt/rules/nuxt-app-core.md +1 -3
  436. package/presets/opencode/php-hexagonal/REPO_AGENTS.md +1 -3
  437. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  438. package/presets/opencode/php-hexagonal/commands/task-continue.md +1 -1
  439. package/presets/opencode/php-hexagonal/commands/task.md +1 -3
  440. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +1080 -4
  441. package/presets/opencode/php-hexagonal/rules/agent-team-intake.md +1 -1
  442. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +23 -7
  443. package/presets/opencode/php-hexagonal/rules/ai-local-overlay.md +1 -1
  444. package/presets/opencode/php-hexagonal/rules/anti-hallucination-contract.md +2 -0
  445. package/presets/opencode/php-hexagonal/rules/language-policy.md +24 -16
  446. package/presets/opencode/php-hexagonal/rules/php-app-core.md +1 -3
  447. package/presets/opencode/php-laravel/REPO_AGENTS.md +1 -3
  448. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  449. package/presets/opencode/php-laravel/commands/task-continue.md +1 -1
  450. package/presets/opencode/php-laravel/commands/task.md +1 -3
  451. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +1080 -4
  452. package/presets/opencode/php-laravel/rules/agent-team-intake.md +1 -1
  453. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +23 -7
  454. package/presets/opencode/php-laravel/rules/ai-local-overlay.md +1 -1
  455. package/presets/opencode/php-laravel/rules/anti-hallucination-contract.md +2 -0
  456. package/presets/opencode/php-laravel/rules/language-policy.md +24 -16
  457. package/presets/opencode/php-laravel/rules/laravel-app-core.md +1 -3
  458. package/presets/opencode/svelte/REPO_AGENTS.md +1 -3
  459. package/presets/opencode/svelte/adapter-map.json +1 -1
  460. package/presets/opencode/svelte/commands/task-continue.md +1 -1
  461. package/presets/opencode/svelte/commands/task.md +1 -3
  462. package/presets/opencode/svelte/hooks/chain-team-phases.sh +1080 -4
  463. package/presets/opencode/svelte/rules/agent-team-intake.md +1 -1
  464. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +23 -7
  465. package/presets/opencode/svelte/rules/ai-local-overlay.md +1 -1
  466. package/presets/opencode/svelte/rules/anti-hallucination-contract.md +2 -0
  467. package/presets/opencode/svelte/rules/language-policy.md +24 -16
  468. package/presets/opencode/svelte/rules/svelte-app-core.md +1 -3
@@ -254,10 +254,429 @@ function writeSkeletonManifest(manifestPath) {
254
254
  }
255
255
  }
256
256
 
257
+ function normalizeRepoPath(value) {
258
+ let text = typeof value === 'string' ? value.trim() : '';
259
+ text = text.replace(/\\/g, '/');
260
+ while (text.startsWith('./')) text = text.slice(2);
261
+ if (!text || text === '—' || text === '-' || text === '–') return '';
262
+ if (/[\s()]/.test(text)) return '';
263
+ return text;
264
+ }
265
+
266
+ function isAppPath(file) {
267
+ const normalized = normalizeRepoPath(file);
268
+ return normalized === 'app' || normalized.startsWith('app/') || normalized.startsWith('app/**') || normalized.startsWith('app/*');
269
+ }
270
+
271
+ function isSpecFolderPath(file) {
272
+ const normalized = normalizeRepoPath(file);
273
+ return normalized.startsWith('docs/specs/') || normalized.startsWith('docs/specs/**') || normalized.startsWith('openspec/') || normalized.startsWith('openspec/**');
274
+ }
275
+
276
+ function listsBothSpecAndApp(files) {
277
+ let app = false;
278
+ let spec = false;
279
+ for (const file of files || []) {
280
+ if (isAppPath(file)) app = true;
281
+ if (isSpecFolderPath(file)) spec = true;
282
+ }
283
+ return app && spec;
284
+ }
285
+
286
+ function pathInWriteScopes(file, writeScopes) {
287
+ const target = normalizeRepoPath(file);
288
+ if (!target) return false;
289
+ const scopes = Array.isArray(writeScopes) ? writeScopes : [];
290
+ for (const scope of scopes) {
291
+ const normalized = normalizeRepoPath(scope);
292
+ if (!normalized) continue;
293
+ if (normalized === target) return true;
294
+ if (normalized.endsWith('/**')) {
295
+ const prefix = normalized.slice(0, -3);
296
+ if (target === prefix || target.startsWith(prefix + '/')) return true;
297
+ } else if (normalized.endsWith('/*')) {
298
+ const prefix = normalized.slice(0, -2);
299
+ const rest = target.startsWith(prefix + '/') ? target.slice(prefix.length + 1) : '';
300
+ if (rest && !rest.includes('/')) return true;
301
+ }
302
+ }
303
+ return false;
304
+ }
305
+
306
+ function taskFileSet(task) {
307
+ const all = []
308
+ .concat((task && task.files) || [], (task && task.specFiles) || [], (task && task.appFiles) || [])
309
+ .map((file) => normalizeRepoPath(file))
310
+ .filter(Boolean);
311
+ return new Set(all);
312
+ }
313
+
314
+ function taskReaches(tasks, startId, targetId) {
315
+ const byId = new Map(tasks.map((task) => [String(task.id), task]));
316
+ const seen = new Set();
317
+ const stack = [String(startId)];
318
+ while (stack.length > 0) {
319
+ const id = stack.pop();
320
+ if (seen.has(id)) continue;
321
+ seen.add(id);
322
+ const task = byId.get(id);
323
+ const deps = task && Array.isArray(task.dependsOn) ? task.dependsOn : [];
324
+ for (const dep of deps) {
325
+ if (String(dep) === String(targetId)) return true;
326
+ stack.push(String(dep));
327
+ }
328
+ }
329
+ return false;
330
+ }
331
+
332
+ function tasksAreOrdered(tasks, left, right) {
333
+ return taskReaches(tasks, left.id, right.id) || taskReaches(tasks, right.id, left.id);
334
+ }
335
+
336
+ function validateTaskFileLists(tasks, writeScopes) {
337
+ const list = Array.isArray(tasks) ? tasks : [];
338
+ const scopes = Array.isArray(writeScopes) ? writeScopes : [];
339
+ for (const task of list) {
340
+ const id = task && task.id ? task.id : '(unnamed)';
341
+ const files = (task && task.files) || [];
342
+ if (listsBothSpecAndApp(files)) {
343
+ return 'task "' + id + '" lists spec-folder paths and app/** paths in one file list; they are different lists';
344
+ }
345
+ if (scopes.length === 0) continue;
346
+ const combined = files.concat((task && task.specFiles) || [], (task && task.appFiles) || []);
347
+ for (const file of combined) {
348
+ if (!pathInWriteScopes(file, scopes)) {
349
+ const label = normalizeRepoPath(file) || file;
350
+ return 'task "' + id + '" file "' + label + '" is outside the implementing step writeScopes';
351
+ }
352
+ }
353
+ }
354
+ for (let i = 0; i < list.length; i += 1) {
355
+ for (let j = i + 1; j < list.length; j += 1) {
356
+ if (tasksAreOrdered(list, list[i], list[j])) continue;
357
+ const left = taskFileSet(list[i]);
358
+ let shared = '';
359
+ for (const file of taskFileSet(list[j])) {
360
+ if (left.has(file)) {
361
+ shared = file;
362
+ break;
363
+ }
364
+ }
365
+ if (shared) return 'parallel tasks "' + list[i].id + '" and "' + list[j].id + '" share "' + shared + '"';
366
+ }
367
+ }
368
+ return null;
369
+ }
370
+
371
+ function productionPathsOutsideTaskList(paths, tasks) {
372
+ const allowed = new Set();
373
+ for (const task of tasks || []) {
374
+ for (const file of taskFileSet(task)) allowed.add(file);
375
+ }
376
+ const outside = [];
377
+ for (const cited of paths || []) {
378
+ const normalized = normalizeRepoPath(cited);
379
+ if (normalized && !allowed.has(normalized)) outside.push(normalized);
380
+ }
381
+ return outside;
382
+ }
383
+
384
+ function splitMarkdownCells(line) {
385
+ const trimmed = String(line || '').trim();
386
+ if (!trimmed.startsWith('|')) return [];
387
+ const cells = trimmed.split('|').map((cell) => cell.trim());
388
+ if (cells.length && cells[0] === '') cells.shift();
389
+ if (cells.length && cells[cells.length - 1] === '') cells.pop();
390
+ return cells;
391
+ }
392
+
393
+ function isSeparatorRow(cells) {
394
+ return cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
395
+ }
396
+
397
+ function pathsFromCell(cell) {
398
+ const text = String(cell || '');
399
+ const found = [];
400
+ const pattern = /`([^`]+)`/g;
401
+ let match = pattern.exec(text);
402
+ while (match) {
403
+ const normalized = normalizeRepoPath(match[1]);
404
+ if (normalized && normalized.includes('/')) found.push(normalized);
405
+ match = pattern.exec(text);
406
+ }
407
+ if (found.length > 0) return found;
408
+ return text.split(',').map((part) => normalizeRepoPath(part)).filter((part) => part.includes('/'));
409
+ }
410
+
411
+ function dependsFromCell(cell) {
412
+ const cleaned = String(cell || '').replace(/[`*]/g, '').trim();
413
+ if (!cleaned || cleaned === '—' || cleaned === '-' || cleaned === '–') return [];
414
+ return cleaned.split(/[,|/]/).map((part) => part.trim()).filter((part) => /^[A-Za-z][A-Za-z0-9._-]*$/.test(part));
415
+ }
416
+
417
+ function cellIsComplete(cell) {
418
+ const cleaned = String(cell || '').replace(/[`*[\]]/g, '').trim().toLowerCase();
419
+ return cleaned === 'complete' || cleaned === 'completed' || cleaned === 'done' || cleaned === 'x';
420
+ }
421
+
422
+ function absorbMarkdownTable(block, byId) {
423
+ const rows = [];
424
+ for (const line of block) {
425
+ const cells = splitMarkdownCells(line);
426
+ if (cells.length === 0 || isSeparatorRow(cells)) continue;
427
+ rows.push(cells);
428
+ }
429
+ if (rows.length < 2) return false;
430
+ const headers = rows[0].map((cell) => cell.replace(/[`*]/g, '').trim());
431
+ const idIndex = headers.findIndex((header) => /^id$/i.test(header));
432
+ if (idIndex < 0) return false;
433
+ const dependsIndex = headers.findIndex((header) => /dependson/i.test(header));
434
+ const specIndex = headers.findIndex((header) => /spec files/i.test(header));
435
+ const appIndex = headers.findIndex((header) => /^app files$/i.test(header));
436
+ const filesIndex = headers.findIndex((header, index) => index !== specIndex && index !== appIndex && /files|paths/i.test(header));
437
+ const statusIndex = headers.findIndex((header) => /^(status|done|state)$/i.test(header));
438
+ const sawFiles = specIndex >= 0 || appIndex >= 0 || filesIndex >= 0;
439
+ for (const cells of rows.slice(1)) {
440
+ const id = String(cells[idIndex] || '').replace(/[`*]/g, '').trim();
441
+ if (!id || /^id$/i.test(id)) continue;
442
+ const task = byId.get(id) || { id, dependsOn: [], files: [], specFiles: [], appFiles: [], tracked: false, rowComplete: false };
443
+ if (dependsIndex >= 0) {
444
+ task.dependsOn = dependsFromCell(cells[dependsIndex] || '');
445
+ task.tracked = true;
446
+ }
447
+ if (statusIndex >= 0) task.rowComplete = cellIsComplete(cells[statusIndex] || '');
448
+ if (filesIndex >= 0) {
449
+ const parsed = pathsFromCell(cells[filesIndex] || '');
450
+ if (parsed.length > 0) task.files = parsed;
451
+ }
452
+ if (specIndex >= 0) {
453
+ const parsed = pathsFromCell(cells[specIndex] || '');
454
+ if (parsed.length > 0) task.specFiles = parsed;
455
+ }
456
+ if (appIndex >= 0) {
457
+ const parsed = pathsFromCell(cells[appIndex] || '');
458
+ if (parsed.length > 0) task.appFiles = parsed;
459
+ }
460
+ byId.set(id, task);
461
+ }
462
+ return sawFiles;
463
+ }
464
+
465
+ function parseDecompositionTaskFileLists(markdown) {
466
+ const lines = String(markdown || '').split(/\r?\n/);
467
+ const byId = new Map();
468
+ let hasFileColumn = false;
469
+ let index = 0;
470
+ while (index < lines.length) {
471
+ if (!String(lines[index] || '').trim().startsWith('|')) {
472
+ index += 1;
473
+ continue;
474
+ }
475
+ const block = [];
476
+ while (index < lines.length && String(lines[index] || '').trim().startsWith('|')) {
477
+ block.push(lines[index]);
478
+ index += 1;
479
+ }
480
+ if (absorbMarkdownTable(block, byId)) hasFileColumn = true;
481
+ }
482
+ return { tasks: [...byId.values()], hasFileColumn };
483
+ }
484
+
485
+ function parseDecompositionTasks(markdown) {
486
+ const lines = String(markdown || '').split(/\r?\n/);
487
+ const byId = new Map();
488
+ let index = 0;
489
+ while (index < lines.length) {
490
+ if (!String(lines[index] || '').trim().startsWith('|')) {
491
+ index += 1;
492
+ continue;
493
+ }
494
+ const block = [];
495
+ while (index < lines.length && String(lines[index] || '').trim().startsWith('|')) {
496
+ block.push(lines[index]);
497
+ index += 1;
498
+ }
499
+ absorbMarkdownTable(block, byId);
500
+ }
501
+ return [...byId.values()].filter((task) => task.tracked === true);
502
+ }
503
+
504
+ function taskCoveredByCompletedArtifact(taskId, artifacts) {
505
+ const id = String(taskId);
506
+ const list = Array.isArray(artifacts) ? artifacts : [];
507
+ for (let index = 0; index < list.length; index += 1) {
508
+ const artifact = list[index];
509
+ if (!artifact || artifact.status !== 'completed') continue;
510
+ if (String(artifact.id) === id) return true;
511
+ const taskIds = Array.isArray(artifact.taskIds) ? artifact.taskIds : [];
512
+ for (let taskIndex = 0; taskIndex < taskIds.length; taskIndex += 1) {
513
+ if (String(taskIds[taskIndex]) === id) return true;
514
+ }
515
+ }
516
+ return false;
517
+ }
518
+
519
+ function computeDecompositionReadySet(tasks, artifacts) {
520
+ const list = (Array.isArray(tasks) ? tasks : []).filter((task) => task && task.id && task.tracked !== false);
521
+ const complete = new Set();
522
+ for (let index = 0; index < list.length; index += 1) {
523
+ const task = list[index];
524
+ if (task.rowComplete === true || taskCoveredByCompletedArtifact(task.id, artifacts)) complete.add(String(task.id));
525
+ }
526
+ const ready = [];
527
+ const blocked = [];
528
+ for (let index = 0; index < list.length; index += 1) {
529
+ const task = list[index];
530
+ const id = String(task.id);
531
+ if (complete.has(id)) continue;
532
+ const deps = Array.isArray(task.dependsOn) ? task.dependsOn.map((dep) => String(dep)) : [];
533
+ const waiting = [];
534
+ const seen = new Set();
535
+ for (let depIndex = 0; depIndex < deps.length; depIndex += 1) {
536
+ const dep = deps[depIndex];
537
+ if (!dep || seen.has(dep) || complete.has(dep)) continue;
538
+ seen.add(dep);
539
+ waiting.push(dep);
540
+ }
541
+ if (waiting.length === 0) ready.push(id);
542
+ else blocked.push({ id, waiting_on: waiting });
543
+ }
544
+ return { ready, blocked };
545
+ }
546
+
547
+ function readManifestArtifacts(dir) {
548
+ try {
549
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
550
+ return Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
551
+ } catch {
552
+ return [];
553
+ }
554
+ }
555
+
556
+ function readDecompositionReadySet(dir) {
557
+ let markdown = '';
558
+ try {
559
+ markdown = fs.readFileSync(path.join(dir, 'decomposition.md'), 'utf8');
560
+ } catch {
561
+ markdown = '';
562
+ }
563
+ return computeDecompositionReadySet(parseDecompositionTasks(markdown), readManifestArtifacts(dir));
564
+ }
565
+
566
+ function formatDecompositionReadyClause(report, stepsForRows) {
567
+ const source = report && typeof report === 'object' ? report : { ready: [], blocked: [] };
568
+ const stepList = Array.isArray(stepsForRows) ? stepsForRows : [];
569
+ const allow = [];
570
+ for (let index = 0; index < stepList.length; index += 1) {
571
+ const taskIds = stepList[index] && stepList[index].taskIds;
572
+ if (!Array.isArray(taskIds)) continue;
573
+ for (let idIndex = 0; idIndex < taskIds.length; idIndex += 1) {
574
+ if (taskIds[idIndex] != null && String(taskIds[idIndex])) allow.push(String(taskIds[idIndex]));
575
+ }
576
+ }
577
+ const gate = allow.length > 0 ? new Set(allow) : null;
578
+ const ready = (Array.isArray(source.ready) ? source.ready : []).filter((id) => !gate || gate.has(String(id)));
579
+ const blocked = (Array.isArray(source.blocked) ? source.blocked : []).filter((row) => row && (!gate || gate.has(String(row.id))));
580
+ const readyText = ready.length > 0 ? ready.join(', ') : '(none)';
581
+ let text = ' Decomposition ready set: ' + readyText + '.';
582
+ if (blocked.length > 0) {
583
+ const parts = [];
584
+ for (let index = 0; index < blocked.length; index += 1) {
585
+ const row = blocked[index];
586
+ const waiting = Array.isArray(row.waiting_on) ? row.waiting_on.join(', ') : '';
587
+ parts.push(String(row.id) + ' waiting_on ' + waiting);
588
+ }
589
+ text += ' Blocked: ' + parts.join('; ') + '.';
590
+ }
591
+ return text;
592
+ }
593
+
594
+ function decompositionReadyClause(stepsForRows) {
595
+ try {
596
+ return formatDecompositionReadyClause(readDecompositionReadySet(taskDir), stepsForRows);
597
+ } catch {
598
+ return ' Decomposition ready set: (none).';
599
+ }
600
+ }
601
+
602
+ function productionCitationRepoPath(cited) {
603
+ const value = typeof cited === 'string' ? cited.trim() : '';
604
+ if (!value) return null;
605
+ const normalized = value.replace(/\\/g, '/');
606
+ if (path.isAbsolute(normalized)) {
607
+ const fromCwd = path.relative(process.cwd(), normalized);
608
+ if (fromCwd && !fromCwd.startsWith('..') && !path.isAbsolute(fromCwd)) return normalizeRepoPath(fromCwd);
609
+ return normalizeRepoPath(normalized) || normalized;
610
+ }
611
+ const taskResolved = path.resolve(taskDir, normalized);
612
+ const taskRelative = path.relative(taskDir, taskResolved);
613
+ const insideTask = taskRelative !== '' && taskRelative !== '..' && !taskRelative.startsWith('..' + path.sep) && !path.isAbsolute(taskRelative);
614
+ if (insideTask) {
615
+ try {
616
+ if (fs.statSync(taskResolved).isFile()) return null;
617
+ } catch {}
618
+ }
619
+ return normalizeRepoPath(normalized);
620
+ }
621
+
622
+ function implementingStepForTaskIds(taskIds) {
623
+ if (!Array.isArray(steps) || taskIds.length === 0) return null;
624
+ return steps.find((step) => Array.isArray(step && step.taskIds) && taskIds.some((id) => step.taskIds.map((item) => String(item)).includes(String(id)))) || null;
625
+ }
626
+
627
+ function productionWriteListError(entry) {
628
+ const artifactId = entry && entry.id ? entry.id : '(unnamed)';
629
+ const resume = 'Then resume with: /task-continue ' + slug;
630
+ const fail = (detail) => '[chain-team-phases] ' + slug + ': receipt "' + artifactId + '" ' + detail + ' ' + resume;
631
+ try {
632
+ const evidence = entry && Array.isArray(entry.evidencePaths) ? entry.evidencePaths : [];
633
+ const production = [];
634
+ for (const cited of evidence) {
635
+ const repoPath = productionCitationRepoPath(cited);
636
+ if (repoPath) production.push(repoPath);
637
+ }
638
+ if (production.length === 0) return null;
639
+ let markdown = '';
640
+ try {
641
+ markdown = fs.readFileSync(path.join(taskDir, 'decomposition.md'), 'utf8');
642
+ } catch {
643
+ markdown = '';
644
+ }
645
+ const parsed = parseDecompositionTaskFileLists(markdown);
646
+ if (!parsed.hasFileColumn) return null;
647
+ const tasks = parsed.tasks;
648
+ const taskIds = Array.isArray(entry && entry.taskIds) ? entry.taskIds.map((id) => String(id)) : [];
649
+ const step = implementingStepForTaskIds(taskIds);
650
+ const selectedIds = new Set(taskIds);
651
+ if (step && Array.isArray(step.taskIds)) {
652
+ for (const id of step.taskIds) selectedIds.add(String(id));
653
+ }
654
+ const selected = tasks.filter((task) => selectedIds.has(String(task.id)));
655
+ if (selected.length === 0) {
656
+ return fail('cites production paths but decomposition.md has no file list for ' + (taskIds.join(', ') || '(none)') + '. Record the task file list.');
657
+ }
658
+ const writeScopes = step && Array.isArray(step.writeScopes) ? step.writeScopes : [];
659
+ const listError = validateTaskFileLists(selected, writeScopes);
660
+ if (listError) return fail(listError + '.');
661
+ const owned = selected.filter((task) => taskIds.includes(String(task.id)));
662
+ const citedAgainst = owned.length > 0 ? owned : selected;
663
+ const outside = productionPathsOutsideTaskList(production, citedAgainst);
664
+ if (outside.length > 0) {
665
+ const ids = taskIds.length > 0 ? taskIds.join(', ') : citedAgainst.map((task) => task.id).join(', ');
666
+ return fail('cites production path "' + outside[0] + '", which is not on the decomposition file list for ' + ids + '.');
667
+ }
668
+ return null;
669
+ } catch (error) {
670
+ return fail('production file-list check failed (' + (error && error.message ? error.message : error) + ').');
671
+ }
672
+ }
673
+
257
674
  // A2: a `completed` receipt must cite evidence the harness can inspect. Order is
258
675
  // the message order — the first failing predicate wins, so the operator sees one
259
676
  // actionable line. `authoritativePaths[]` stays task-dir-relative; external
260
- // references belong in `evidencePaths[]`.
677
+ // references belong in `evidencePaths[]`. The task-folder checks below stay in
678
+ // place. A later production evidencePaths check uses the decomposition file list
679
+ // only when that list column exists.
261
680
  function validateCompletedArtifact(entry) {
262
681
  const artifactId = entry && entry.id ? entry.id : '(unnamed)';
263
682
  const entryStatus = entry && entry.status;
@@ -289,6 +708,8 @@ function validateCompletedArtifact(entry) {
289
708
  }
290
709
  }
291
710
  }
711
+ const productionListError = productionWriteListError(entry);
712
+ if (productionListError) return productionListError;
292
713
  return null;
293
714
  }
294
715
 
@@ -458,6 +879,309 @@ function recordSkippedStep(step, stepIndex) {
458
879
  }
459
880
  }
460
881
 
882
+ // Living task files and the hook ledger stay put. A completed entry's other markdown is the body that leaves the default read.
883
+ const CLOSED_BODY_KEEP = new Set([
884
+ 'brief.md',
885
+ 'decomposition.md',
886
+ 'goal.md',
887
+ 'prompt.md',
888
+ 'prompt-log.md',
889
+ 'pipeline.json',
890
+ 'implementation.md',
891
+ '.memlog.md',
892
+ 'focus.md',
893
+ 'status.json',
894
+ 'metrics.json',
895
+ 'artifact-manifest.json',
896
+ 'overlay-scope.json',
897
+ ]);
898
+
899
+ function closedMarkdownBody(dir, cited) {
900
+ if (typeof cited !== 'string') return null;
901
+ const value = cited.trim();
902
+ if (!value || path.isAbsolute(value)) return null;
903
+ const resolved = path.resolve(dir, value);
904
+ const relative = path.relative(dir, resolved);
905
+ if (!relative || relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) return null;
906
+ const normalized = relative.split(path.sep).join('/');
907
+ if (!/\.md$/i.test(normalized) || normalized.startsWith('archive/')) return null;
908
+ const base = normalized.slice(normalized.lastIndexOf('/') + 1);
909
+ if (CLOSED_BODY_KEEP.has(base) || CLOSED_BODY_KEEP.has(normalized)) return null;
910
+ return { resolved, base };
911
+ }
912
+
913
+ function archiveClosedBody(dir, date, id, body) {
914
+ const archiveDir = path.join(dir, 'archive', date);
915
+ fs.mkdirSync(archiveDir, { recursive: true });
916
+ let name = body.base;
917
+ let destination = path.join(archiveDir, name);
918
+ if (fs.existsSync(destination)) {
919
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id)) return null;
920
+ name = id + '--' + body.base;
921
+ destination = path.join(archiveDir, name);
922
+ }
923
+ if (fs.existsSync(destination)) return null;
924
+ fs.renameSync(body.resolved, destination);
925
+ return 'archive/' + date + '/' + name;
926
+ }
927
+
928
+ function appendMemlogEvent(dir, text) {
929
+ const memlogPath = path.join(dir, '.memlog.md');
930
+ const line = '- `event`: ' + text + '\n';
931
+ let existing = '';
932
+ try { existing = fs.readFileSync(memlogPath, 'utf8'); } catch { existing = ''; }
933
+ if (existing.includes(text)) return existing;
934
+ const prefix = existing.length > 0 && !existing.endsWith('\n') ? '\n' : '';
935
+ fs.appendFileSync(memlogPath, prefix + line);
936
+ return existing + prefix + line;
937
+ }
938
+
939
+ function writeJsonFile(filePath, value) {
940
+ const temporary = filePath + '.' + String(process.pid) + '.tmp';
941
+ const fd = fs.openSync(temporary, 'w');
942
+ try {
943
+ fs.writeSync(fd, JSON.stringify(value, null, 2) + '\n');
944
+ } finally {
945
+ fs.closeSync(fd);
946
+ }
947
+ fs.renameSync(temporary, filePath);
948
+ }
949
+
950
+ function compactClosedManifestBodies(dir, closedOn) {
951
+ const date = typeof closedOn === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(closedOn)
952
+ ? closedOn
953
+ : new Date().toISOString().slice(0, 10);
954
+ const manifestPath = path.join(dir, 'artifact-manifest.json');
955
+ let manifest;
956
+ try {
957
+ manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
958
+ } catch {
959
+ return { moved: [] };
960
+ }
961
+ const slugBefore = manifest.slug;
962
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
963
+ let memlog = '';
964
+ try { memlog = fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8'); } catch { memlog = ''; }
965
+ let manifestChanged = false;
966
+ const moved = [];
967
+ for (let index = 0; index < artifacts.length; index += 1) {
968
+ const entry = artifacts[index];
969
+ if (!entry || entry.status !== 'completed' || typeof entry.id !== 'string' || !entry.id) continue;
970
+ const marker = 'closed manifest artifact ' + entry.id + ';';
971
+ if (memlog.includes(marker)) continue;
972
+ const cited = Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths.slice() : [];
973
+ const relocated = [];
974
+ for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
975
+ const body = closedMarkdownBody(dir, cited[pathIndex]);
976
+ if (!body) continue;
977
+ let stat = null;
978
+ try { stat = fs.statSync(body.resolved); } catch { stat = null; }
979
+ if (!stat || !stat.isFile()) continue;
980
+ let content = '';
981
+ try { content = fs.readFileSync(body.resolved, 'utf8'); } catch { content = ''; }
982
+ if (!/\S/.test(content)) continue;
983
+ const archived = archiveClosedBody(dir, date, entry.id, body);
984
+ if (!archived) continue;
985
+ cited[pathIndex] = archived;
986
+ relocated.push(archived);
987
+ moved.push(archived);
988
+ manifestChanged = true;
989
+ }
990
+ if (relocated.length > 0) entry.authoritativePaths = cited;
991
+ let archiveHint = relocated.length > 0 ? 'archive/' + date + '/' : '';
992
+ if (!archiveHint) {
993
+ for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
994
+ const value = typeof cited[pathIndex] === 'string' ? cited[pathIndex].trim() : '';
995
+ const match = /^archive\/\d{4}-\d{2}-\d{2}\//.exec(value);
996
+ if (match) {
997
+ archiveHint = match[0];
998
+ break;
999
+ }
1000
+ }
1001
+ }
1002
+ const text = archiveHint
1003
+ ? 'closed manifest artifact ' + entry.id + '; body archived under ' + archiveHint
1004
+ : 'closed manifest artifact ' + entry.id + '; no bulky markdown body moved';
1005
+ memlog = appendMemlogEvent(dir, text);
1006
+ }
1007
+ if (manifest.slug !== slugBefore) manifest.slug = slugBefore;
1008
+ if (manifestChanged) writeJsonFile(manifestPath, manifest);
1009
+ return { moved };
1010
+ }
1011
+
1012
+ function projectResumeArtifact(entry) {
1013
+ if (!entry || typeof entry !== 'object') return entry;
1014
+ if (entry.status !== 'completed') return entry;
1015
+ return {
1016
+ id: entry.id,
1017
+ status: entry.status,
1018
+ authoritativePaths: Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [],
1019
+ };
1020
+ }
1021
+
1022
+ function defaultResumeRead(dir) {
1023
+ const chunks = [];
1024
+ try { chunks.push(fs.readFileSync(path.join(dir, 'focus.md'), 'utf8')); } catch {}
1025
+ try {
1026
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
1027
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
1028
+ const projected = [];
1029
+ for (let index = 0; index < artifacts.length; index += 1) {
1030
+ projected.push(projectResumeArtifact(artifacts[index]));
1031
+ }
1032
+ chunks.push(JSON.stringify({ slug: manifest.slug, artifacts: projected }));
1033
+ } catch {}
1034
+ try { chunks.push(fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8')); } catch {}
1035
+ return chunks.join('\n');
1036
+ }
1037
+
1038
+ function archiveIndexLine(dir) {
1039
+ const root = path.join(dir, 'archive');
1040
+ let names = [];
1041
+ try { names = fs.readdirSync(root); } catch { names = []; }
1042
+ const dates = [];
1043
+ for (let index = 0; index < names.length; index += 1) {
1044
+ const name = names[index];
1045
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(name)) continue;
1046
+ let stat = null;
1047
+ try { stat = fs.statSync(path.join(root, name)); } catch { stat = null; }
1048
+ if (stat && stat.isDirectory()) dates.push(name);
1049
+ }
1050
+ dates.sort();
1051
+ if (dates.length === 0) return '- archive index: (none)';
1052
+ const parts = [];
1053
+ for (let index = 0; index < dates.length; index += 1) parts.push('archive/' + dates[index] + '/');
1054
+ return '- archive index: ' + parts.join(', ');
1055
+ }
1056
+
1057
+ function focusDigestMarkdown(dir, statusSnapshot) {
1058
+ const snapshot = statusSnapshot && typeof statusSnapshot === 'object' ? statusSnapshot : {};
1059
+ const slugValue = typeof snapshot.slug === 'string' ? snapshot.slug : '';
1060
+ const stepIndex = Number.isInteger(snapshot.pipelineIndex) ? snapshot.pipelineIndex : 0;
1061
+ const incomplete = [];
1062
+ try {
1063
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
1064
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
1065
+ for (let index = 0; index < artifacts.length; index += 1) {
1066
+ const artifact = artifacts[index];
1067
+ if (!artifact || artifact.status === 'completed') continue;
1068
+ const id = typeof artifact.id === 'string' ? artifact.id : '(no id)';
1069
+ const cited = Array.isArray(artifact.authoritativePaths) ? artifact.authoritativePaths : [];
1070
+ const paths = [];
1071
+ for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
1072
+ if (typeof cited[pathIndex] === 'string') paths.push(cited[pathIndex]);
1073
+ }
1074
+ incomplete.push({ id, paths });
1075
+ }
1076
+ } catch {}
1077
+ let lastEvent = '(none)';
1078
+ try {
1079
+ const raw = fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8');
1080
+ const lines = raw.split(/\r?\n/);
1081
+ const tickEvent = /`event`:\s*(.*)$/;
1082
+ const bareEvent = /(?:^|\s)event:\s*(.*)$/;
1083
+ for (let index = lines.length - 1; index >= 0; index -= 1) {
1084
+ const line = lines[index];
1085
+ let matched = tickEvent.exec(line);
1086
+ if (!matched) matched = bareEvent.exec(line);
1087
+ if (matched && matched[1].trim()) {
1088
+ lastEvent = matched[1].trim();
1089
+ break;
1090
+ }
1091
+ }
1092
+ } catch {}
1093
+ let nextGate = 'none';
1094
+ if (snapshot.awaitingHumanGate === true || snapshot.state === 'awaiting_approval') {
1095
+ nextGate = 'human gate — /task-continue ' + slugValue;
1096
+ } else {
1097
+ try {
1098
+ const pipeline = JSON.parse(fs.readFileSync(path.join(dir, 'pipeline.json'), 'utf8'));
1099
+ const steps = Array.isArray(pipeline.steps) ? pipeline.steps : [];
1100
+ const gates = Array.isArray(pipeline.humanGates) ? pipeline.humanGates : [];
1101
+ for (let index = stepIndex; index < steps.length; index += 1) {
1102
+ const step = steps[index];
1103
+ const agents = !step ? [] : (Array.isArray(step.agent) ? step.agent : [step.agent]);
1104
+ let hit = '';
1105
+ for (let agentIndex = 0; agentIndex < agents.length; agentIndex += 1) {
1106
+ const agent = agents[agentIndex];
1107
+ if (typeof agent === 'string' && gates.indexOf('after:' + agent) !== -1) {
1108
+ hit = agent;
1109
+ break;
1110
+ }
1111
+ }
1112
+ if (hit) {
1113
+ const stepId = step && typeof step.id === 'string' ? step.id : 'step-' + String(index);
1114
+ nextGate = 'after:' + hit + ' (step ' + stepId + ', index ' + String(index) + ')';
1115
+ break;
1116
+ }
1117
+ }
1118
+ } catch {}
1119
+ }
1120
+ const pathLines = [];
1121
+ if (incomplete.length === 0) pathLines.push(' - (none)');
1122
+ else {
1123
+ for (let index = 0; index < incomplete.length; index += 1) {
1124
+ const item = incomplete[index];
1125
+ if (item.paths.length === 0) pathLines.push(' - ' + item.id + ': (none)');
1126
+ else {
1127
+ for (let pathIndex = 0; pathIndex < item.paths.length; pathIndex += 1) {
1128
+ pathLines.push(' - ' + item.id + ': ' + item.paths[pathIndex]);
1129
+ }
1130
+ }
1131
+ }
1132
+ }
1133
+ let readyLine = '- decomposition ready set: (none)';
1134
+ try {
1135
+ const report = readDecompositionReadySet(dir);
1136
+ const ids = Array.isArray(report.ready) ? report.ready : [];
1137
+ readyLine = '- decomposition ready set: ' + (ids.length > 0 ? ids.join(', ') : '(none)');
1138
+ } catch {
1139
+ readyLine = '- decomposition ready set: (none)';
1140
+ }
1141
+ const head = [
1142
+ '# focus.md',
1143
+ '',
1144
+ 'View only. `status.json`, `metrics.json`, `artifact-manifest.json`, and `.memlog.md` stay the system of record.',
1145
+ '',
1146
+ '- slug: ' + slugValue,
1147
+ '- pipeline step index: ' + String(stepIndex),
1148
+ readyLine,
1149
+ archiveIndexLine(dir),
1150
+ '- incomplete authoritative paths:',
1151
+ ];
1152
+ const tail = [
1153
+ '- last memlog event: ' + lastEvent,
1154
+ '- next gate: ' + nextGate,
1155
+ ];
1156
+ let pathBudget = 99 - head.length - tail.length;
1157
+ if (pathBudget < 1) pathBudget = 1;
1158
+ let kept = pathLines;
1159
+ if (pathLines.length > pathBudget) {
1160
+ const room = pathBudget - 1;
1161
+ kept = pathLines.slice(0, room);
1162
+ const omitted = pathLines.length - kept.length;
1163
+ kept.push(' - (' + String(omitted) + ' lines omitted to stay under 100)');
1164
+ }
1165
+ return head.concat(kept, tail).join('\n') + '\n';
1166
+ }
1167
+
1168
+ function writeFocusDigest() {
1169
+ const focusPath = path.join(taskDir, 'focus.md');
1170
+ const temporary = focusPath + '.' + String(process.pid) + '.' + String(Date.now()) + '.tmp';
1171
+ try {
1172
+ const markdown = focusDigestMarkdown(taskDir, status);
1173
+ const fd = fs.openSync(temporary, 'w');
1174
+ try {
1175
+ fs.writeSync(fd, markdown);
1176
+ try { fs.fsyncSync(fd); } catch {}
1177
+ } finally {
1178
+ fs.closeSync(fd);
1179
+ }
1180
+ fs.renameSync(temporary, focusPath);
1181
+ } catch {
1182
+ try { fs.unlinkSync(temporary); } catch {}
1183
+ }
1184
+ }
461
1185
 
462
1186
  function writeStatus(next) {
463
1187
  status = { ...status, ...next, slug, updatedAt: now };
@@ -474,6 +1198,11 @@ function writeStatus(next) {
474
1198
  fs.closeSync(fd);
475
1199
  }
476
1200
  fs.renameSync(temporary, statusPath);
1201
+ // Closed bodies move after the checkpoint lands. A compaction miss must not roll status.json back.
1202
+ try { compactClosedManifestBodies(taskDir, now.slice(0, 10)); } catch {}
1203
+ // focus.md is a view of this checkpoint. It is written after status.json
1204
+ // lands so a digest failure cannot roll the checkpoint back.
1205
+ writeFocusDigest();
477
1206
  }
478
1207
 
479
1208
  function out(message) {
@@ -636,7 +1365,8 @@ function handoffForWave(units, waveId) {
636
1365
  `Invoke IN PARALLEL (one message, multiple Task calls): ${labels.join(' AND ')} for slug "${slug}"${waveId ? ` (waveId=${waveId})` : ''}. ` +
637
1366
  `Each agent writes its artifact and owned receipt; the hook records slot joins from stops. Do not mutate status.json lifecycle fields. ` +
638
1367
  `Artifact inputs: ${inputIds.length > 0 ? inputIds.join(', ') : 'manifest defaults'}; owned output IDs: ${outputIds.join('; ')}. ` +
639
- `Metrics attemptIds: ${attemptIds.join('; ')}. If the hook cannot identify a parallel stop, append a minimal { attemptId, outcome } receipt to .metrics-receipts.json; do not calculate duration. ${receiptPathClause()}`
1368
+ `Metrics attemptIds: ${attemptIds.join('; ')}. If the hook cannot identify a parallel stop, append a minimal { attemptId, outcome } receipt to .metrics-receipts.json; do not calculate duration. ${receiptPathClause()}` +
1369
+ decompositionReadyClause(units.map((unit) => steps[unit.stepIndex]))
640
1370
  );
641
1371
  }
642
1372
  function blockedNotice(blockedIndex, agent) {
@@ -672,6 +1402,9 @@ function dispatchReadyWave(prefixMessage) {
672
1402
  // Slot-filtered dispatch: only unsatisfied (stepIndex, agent) slots are invoked.
673
1403
  const units = wave.flatMap((stepIndex) => unsatisfiedAgents(stepIndex).map((agent) => ({ stepIndex, agent })));
674
1404
  if (units.length === 0) return false;
1405
+ const unitAgents = units.map((unit) => unit.agent);
1406
+ refuseImplementationStart(unitAgents, (agent) => implementationDebugRetry(agent));
1407
+ recordAllowedDebugRetries(unitAgents);
675
1408
  const first = units[0].stepIndex;
676
1409
  const waveId = `${status.metricsRunId || slug}:wave-${first}`;
677
1410
  for (const unit of units) activateAttempts(steps[unit.stepIndex], unit.stepIndex, units.length > 1 ? waveId : null, [unit.agent]);
@@ -765,10 +1498,165 @@ function artifactHandoff(step, agent) {
765
1498
  return ` Artifact inputs: ${inputIds}; owned output ID: ${artifactOutputIdFor(step, agent)}. Bind the terminal receipt to the supplied attemptId. ${receiptPathClause()}`;
766
1499
  }
767
1500
 
1501
+ // <<<implementation-rail>>>
1502
+ // Opt-in. Omitted, "off", and non-production intents stay off. Only "on" applies.
1503
+ function testBeforeHandoffRule() {
1504
+ return 'Include unit tests for mappers/logic before handoff.';
1505
+ }
1506
+ function railOnHandoffClause() {
1507
+ return ' Strict implementation rail: write a failing test before production edits; use a branch or worktree before the first implementation task; run code-reviewer between decomposition tasks; debug retries for this handoff are capped at two.';
1508
+ }
1509
+ function implementationRailApplies(pipeline) {
1510
+ if (!pipeline || typeof pipeline !== 'object') return false;
1511
+ const intent = typeof pipeline.intent === 'string' ? pipeline.intent : '';
1512
+ const level = pipeline.taskLevel;
1513
+ if (level === 'L0' || level === 0 || level === '0') return false;
1514
+ if (intent === 'docs-only' || intent === 'research' || intent === 'preset-only' || intent === 'spike') return false;
1515
+ if (pipeline.presetOnly === true) return false;
1516
+ return pipeline.implementationRail === 'on';
1517
+ }
1518
+ function briefHasOpenClarificationMarker(text) {
1519
+ if (typeof text !== 'string' || text.length === 0) return false;
1520
+ const lines = text.split(/\r?\n/);
1521
+ for (let index = 0; index < lines.length; index += 1) {
1522
+ let body = lines[index].trim().replace(/^(?:>\s*)+/, '');
1523
+ body = body.replace(/^(?:[-*+]|\d+[.)])\s+/, '');
1524
+ if (body.startsWith('[NEEDS CLARIFICATION]')) return true;
1525
+ }
1526
+ return false;
1527
+ }
1528
+ function implementationHandoffDecision(input) {
1529
+ const agent = input && input.agent;
1530
+ const applies = agent === 'feature-developer' && implementationRailApplies(input && input.pipeline);
1531
+ if (!applies) {
1532
+ return {
1533
+ start: true,
1534
+ rail: 'off',
1535
+ handoffRule: agent === 'feature-developer' ? testBeforeHandoffRule() : null,
1536
+ constraints: [],
1537
+ };
1538
+ }
1539
+ if (briefHasOpenClarificationMarker(input && input.briefText)) {
1540
+ return { start: false, rail: 'on', reason: 'open-marker', handoffRule: testBeforeHandoffRule(), constraints: [] };
1541
+ }
1542
+ const debugRetries = Number(input && input.debugRetryCount) || 0;
1543
+ if (input && input.debugRetry === true && debugRetries >= 2) {
1544
+ return { start: false, rail: 'on', reason: 'debug-retry-cap', handoffRule: testBeforeHandoffRule(), constraints: [] };
1545
+ }
1546
+ return {
1547
+ start: true,
1548
+ rail: 'on',
1549
+ handoffRule: testBeforeHandoffRule(),
1550
+ constraints: [
1551
+ 'failing test before production edits',
1552
+ 'branch or worktree before the first implementation task',
1553
+ 'code-reviewer between decomposition tasks',
1554
+ 'debug retries capped at two',
1555
+ ],
1556
+ };
1557
+ }
1558
+ // <<<implementation-rail-end>>>
1559
+
1560
+ function readPipelineRecord() {
1561
+ try {
1562
+ return JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
1563
+ } catch {
1564
+ return null;
1565
+ }
1566
+ }
1567
+ function readBriefText() {
1568
+ try {
1569
+ return fs.readFileSync(path.join(taskDir, 'brief.md'), 'utf8');
1570
+ } catch {
1571
+ return '';
1572
+ }
1573
+ }
1574
+ function countDebugImplementationRetries() {
1575
+ try {
1576
+ const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
1577
+ const events = Array.isArray(metrics.events) ? metrics.events : [];
1578
+ return events.filter((event) => event && event.type === 'retry_scheduled' && event.nextAgent === 'feature-developer' && event.retryAfterFix === 'debugger').length;
1579
+ } catch {
1580
+ return 0;
1581
+ }
1582
+ }
1583
+ function featureDeveloperAlreadyStarted() {
1584
+ try {
1585
+ const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
1586
+ const events = Array.isArray(metrics.events) ? metrics.events : [];
1587
+ return events.some((event) => event && event.type === 'attempt_started' && event.agent === 'feature-developer');
1588
+ } catch {
1589
+ return false;
1590
+ }
1591
+ }
1592
+ function implementationDebugRetry(agent) {
1593
+ return agent === 'feature-developer' && status.currentAgent === 'debugger' && featureDeveloperAlreadyStarted();
1594
+ }
1595
+ function blockImplementationStart(agent, debugRetry) {
1596
+ const decision = implementationHandoffDecision({
1597
+ agent,
1598
+ pipeline: readPipelineRecord(),
1599
+ briefText: readBriefText(),
1600
+ debugRetry: Boolean(debugRetry),
1601
+ debugRetryCount: countDebugImplementationRetries(),
1602
+ });
1603
+ if (decision.start) return null;
1604
+ if (decision.reason === 'debug-retry-cap') {
1605
+ return `Strict implementation rail is on for slug "${slug}". Debug retries for the implementation handoff are capped at two. Do not start implementation.`;
1606
+ }
1607
+ return `Strict implementation rail is on for slug "${slug}" and a [NEEDS CLARIFICATION] marker is open. Do not start implementation.`;
1608
+ }
1609
+ function refuseImplementationStart(agents, debugRetryFor) {
1610
+ const list = Array.isArray(agents) ? agents : [agents];
1611
+ for (let index = 0; index < list.length; index += 1) {
1612
+ const block = blockImplementationStart(list[index], debugRetryFor(list[index]));
1613
+ if (!block) continue;
1614
+ beginHumanGate();
1615
+ writeStatus({
1616
+ state: 'awaiting_approval',
1617
+ phase: 'human_gate',
1618
+ awaitingHumanGate: true,
1619
+ waveSteps: [],
1620
+ waveId: null,
1621
+ retryAfterFix: null,
1622
+ retryAfterFixStepIndex: null,
1623
+ });
1624
+ out(block);
1625
+ process.exit(0);
1626
+ }
1627
+ }
1628
+ function recordAllowedDebugRetries(agents) {
1629
+ if (!implementationRailApplies(readPipelineRecord())) return;
1630
+ const list = Array.isArray(agents) ? agents : [agents];
1631
+ for (let index = 0; index < list.length; index += 1) {
1632
+ if (!implementationDebugRetry(list[index])) continue;
1633
+ appendMetric({
1634
+ type: 'retry_scheduled',
1635
+ at: now,
1636
+ attemptId: null,
1637
+ nextAgent: 'feature-developer',
1638
+ retryAfterFix: 'debugger',
1639
+ source: 'hook',
1640
+ attributionConfidence: 'high',
1641
+ });
1642
+ }
1643
+ }
1644
+ function railInstructionClause(agent) {
1645
+ const decision = implementationHandoffDecision({
1646
+ agent,
1647
+ pipeline: readPipelineRecord(),
1648
+ briefText: readBriefText(),
1649
+ debugRetry: false,
1650
+ debugRetryCount: 0,
1651
+ });
1652
+ if (decision.rail !== 'on' || !decision.start) return '';
1653
+ return railOnHandoffClause();
1654
+ }
1655
+
768
1656
  function handoffForAgent(agent, scope, step = null) {
769
1657
  const fn = AGENT_HANDOFF[agent];
770
1658
  const handoff = fn ? fn(slug, scope) : `Invoke ${agent} subagent for slug "${slug}". Upsert the owned terminal receipt in artifact-manifest.json; do not mutate status.json lifecycle fields.`;
771
- return handoff + artifactHandoff(step, agent) + metricsHandoff(agent);
1659
+ return handoff + railInstructionClause(agent) + artifactHandoff(step, agent) + metricsHandoff(agent) + decompositionReadyClause(step ? [step] : []);
772
1660
  }
773
1661
 
774
1662
  function handoffForParallelStep(step) {
@@ -780,7 +1668,8 @@ function handoffForParallelStep(step) {
780
1668
  `Invoke IN PARALLEL (one message, multiple Task calls): ${agents.join(' AND ')} for slug "${slug}". ` +
781
1669
  `Each agent writes its artifact and owned receipt; the hook records parallelCompleted from stops. Do not mutate status.json lifecycle fields. ` +
782
1670
  `Artifact inputs: ${Array.isArray(step.artifactInputIds) ? step.artifactInputIds.join(', ') : 'manifest defaults'}; owned output IDs: ${agents.map((agent) => `${agent}=${artifactOutputIdFor(step, agent)}`).join('; ')}. ` +
783
- `Metrics attemptIds: ${attemptIds.join('; ')}. If the hook cannot identify a parallel stop, append a minimal { attemptId, outcome } receipt to .metrics-receipts.json; do not calculate duration. ${receiptPathClause()}`
1671
+ `Metrics attemptIds: ${attemptIds.join('; ')}. If the hook cannot identify a parallel stop, append a minimal { attemptId, outcome } receipt to .metrics-receipts.json; do not calculate duration. ${receiptPathClause()}` +
1672
+ decompositionReadyClause([step])
784
1673
  );
785
1674
  }
786
1675
 
@@ -879,6 +1768,8 @@ if (hookInput.action === 'end_human_gate') {
879
1768
  const resumeNext = findNextExecutableStep(resumeSteps, resumeStart, taskDir);
880
1769
  if (resumeNext) {
881
1770
  const resumeAgents = getStepAgents(resumeNext.step);
1771
+ refuseImplementationStart(resumeAgents, (agent) => implementationDebugRetry(agent));
1772
+ recordAllowedDebugRetries(resumeAgents);
882
1773
  activateAttempts(resumeNext.step, resumeNext.index);
883
1774
  writeStatus({
884
1775
  pipelineIndex: resumeNext.index,
@@ -1035,6 +1926,9 @@ function nearestPrecedingStepIndex(agent, fromIndex, fallback) {
1035
1926
  return match >= 0 ? match : fallback;
1036
1927
  }
1037
1928
  function scheduleRetry(agent, retryAfterFix, predecessor, explicitStepIndex = null) {
1929
+ if (agent === 'feature-developer') {
1930
+ refuseImplementationStart([agent], () => retryAfterFix === 'debugger');
1931
+ }
1038
1932
  const currentIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
1039
1933
  const explicitOk = Number.isInteger(explicitStepIndex) && getStepAgents(steps[explicitStepIndex]).includes(agent);
1040
1934
  const stepIndex = explicitOk ? explicitStepIndex : nearestPrecedingStepIndex(agent, currentIndex, -1);
@@ -1342,6 +2236,8 @@ if (!next) {
1342
2236
  const { step: nextStep, index: nextIdx } = next;
1343
2237
  const nextAgents = getStepAgents(nextStep);
1344
2238
 
2239
+ refuseImplementationStart(nextAgents, (agent) => implementationDebugRetry(agent));
2240
+ recordAllowedDebugRetries(nextAgents);
1345
2241
  activateAttempts(nextStep, nextIdx);
1346
2242
  writeStatus({
1347
2243
  pipelineIndex: nextIdx,
@@ -1370,6 +2266,180 @@ const fs = require('fs');
1370
2266
  const path = require('path');
1371
2267
  const { spawnSync } = require('child_process');
1372
2268
 
2269
+ // <<<standards-draft>>>
2270
+ // Explicit payload only. This postflight never walks the repo and never
2271
+ // creates `.ai.local/rules/`. The same provenance tag does not rewrite an
2272
+ // accepted Gotchas, Patterns, or Decisions line.
2273
+ function standardsDraftTag(provenance) {
2274
+ return '(`' + provenance + '`)';
2275
+ }
2276
+
2277
+ function standardsDraftLineIndex(content, header) {
2278
+ if (content.startsWith(header) && (content.length === header.length || content.charAt(header.length) === '\n')) return 0;
2279
+ const at = content.indexOf('\n' + header + '\n');
2280
+ if (at !== -1) return at + 1;
2281
+ if (content.endsWith('\n' + header)) return content.length - header.length;
2282
+ return -1;
2283
+ }
2284
+
2285
+ function standardsDraftSection(content, name) {
2286
+ const header = '## ' + name;
2287
+ const start = standardsDraftLineIndex(content, header);
2288
+ if (start === -1) return null;
2289
+ const from = start + header.length;
2290
+ const next = content.indexOf('\n## ', from);
2291
+ const end = next === -1 ? content.length : next;
2292
+ return content.slice(start, end);
2293
+ }
2294
+
2295
+ function standardsDraftProtected(content) {
2296
+ const names = ['Language', 'Gotchas', 'Patterns', 'Decisions', 'Advisory index'];
2297
+ let snapshot = '';
2298
+ for (let index = 0; index < names.length; index += 1) {
2299
+ const body = standardsDraftSection(content, names[index]);
2300
+ snapshot += names[index] + '\n' + (body === null ? '' : body) + '\n';
2301
+ }
2302
+ return snapshot;
2303
+ }
2304
+
2305
+ function standardsDraftNormalize(line) {
2306
+ return line.trim().replace(/\s+/g, ' ').replace(/^-\s+/, '').replace(/\s+\(`[^`]*`\)$/, '').toLowerCase();
2307
+ }
2308
+
2309
+ function standardsDraftAccepted(content, text) {
2310
+ const pending = standardsDraftSection(content, 'Pending');
2311
+ let rest = content;
2312
+ if (pending !== null) {
2313
+ const start = content.indexOf(pending);
2314
+ rest = content.slice(0, start) + content.slice(start + pending.length);
2315
+ }
2316
+ const needle = standardsDraftNormalize(text);
2317
+ if (!needle) return false;
2318
+ const lines = rest.split('\n');
2319
+ for (let index = 0; index < lines.length; index += 1) {
2320
+ const line = lines[index];
2321
+ if (!/^-\s+\S/.test(line)) continue;
2322
+ if (standardsDraftNormalize(line) === needle) return true;
2323
+ }
2324
+ return false;
2325
+ }
2326
+
2327
+ function standardsDraftAppendPending(content, line) {
2328
+ const header = '## Pending';
2329
+ const start = standardsDraftLineIndex(content, header);
2330
+ if (start === -1) {
2331
+ const sep = content.endsWith('\n') ? '\n' : '\n\n';
2332
+ return content + sep + header + '\n\n' + line + '\n';
2333
+ }
2334
+ const from = start + header.length;
2335
+ const next = content.indexOf('\n## ', from);
2336
+ const end = next === -1 ? content.length : next;
2337
+ let body = content.slice(from, end);
2338
+ const hasBullet = /(^|\n)-\s+\S/.test(body);
2339
+ if (!hasBullet && /(^|\n)-[ \t]*(?=\n|$)/.test(body)) {
2340
+ body = body.replace(/(^|\n)-[ \t]*(?=\n|$)/, '$1' + line);
2341
+ } else if (body.endsWith('\n\n')) {
2342
+ body = body.slice(0, -1) + line + '\n\n';
2343
+ } else if (body.endsWith('\n')) {
2344
+ body = body + line + '\n';
2345
+ } else {
2346
+ body = body + '\n' + line + '\n';
2347
+ }
2348
+ return content.slice(0, from) + body + content.slice(end);
2349
+ }
2350
+
2351
+ function standardsDraftProvenance(draft) {
2352
+ if (!draft || typeof draft.provenance !== 'string') return '';
2353
+ const provenance = draft.provenance.trim();
2354
+ if (/^incident: [A-Za-z0-9][A-Za-z0-9._:-]{0,80}$/.test(provenance)) return provenance;
2355
+ const read = /^read: ([A-Za-z0-9][A-Za-z0-9._/-]{0,160})$/.exec(provenance);
2356
+ if (!read) return '';
2357
+ const parts = read[1].split('/');
2358
+ if (parts.indexOf('..') !== -1 || parts.indexOf('.') !== -1) return '';
2359
+ if (read[1] === '.ai.local/rules' || read[1].indexOf('.ai.local/rules/') === 0) return '';
2360
+ return provenance;
2361
+ }
2362
+
2363
+ function standardsDraftWrite(target, content) {
2364
+ fs.mkdirSync(path.dirname(target), { recursive: true });
2365
+ const temporary = target + '.' + String(process.pid) + '.tmp';
2366
+ fs.writeFileSync(temporary, content);
2367
+ fs.renameSync(temporary, target);
2368
+ }
2369
+
2370
+ function appendOptionalStandardsDraft(root, draft) {
2371
+ const provenance = standardsDraftProvenance(draft);
2372
+ if (!provenance) return { wrote: false, reason: 'provenance' };
2373
+ const text = draft && typeof draft.text === 'string' ? draft.text.trim() : '';
2374
+ if (!text || text.length > 400 || text.indexOf('\n') !== -1 || text.indexOf('\r') !== -1 || text.indexOf('## ') !== -1) {
2375
+ return { wrote: false, reason: 'text' };
2376
+ }
2377
+ let destination = 'conventions';
2378
+ if (draft.destination != null) {
2379
+ if (draft.destination === 'conventions' || draft.destination === 'rules-library') destination = draft.destination;
2380
+ else return { wrote: false, reason: 'destination' };
2381
+ }
2382
+ const line = '- ' + text + ' ' + standardsDraftTag(provenance);
2383
+ const overlay = path.join(root, '.ai.local');
2384
+ const rulesDir = path.join(overlay, 'rules');
2385
+ const rulesPrefix = rulesDir + path.sep;
2386
+
2387
+ if (destination === 'rules-library') {
2388
+ const stem = draft && typeof draft.stem === 'string' ? draft.stem : '';
2389
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+){0,8}$/.test(stem) || stem.length > 48) {
2390
+ return { wrote: false, reason: 'stem' };
2391
+ }
2392
+ const libraryDir = path.join(overlay, 'rules-library');
2393
+ const target = path.join(libraryDir, stem + '.md');
2394
+ const libraryPrefix = libraryDir + path.sep;
2395
+ if (!target.startsWith(libraryPrefix)) return { wrote: false, reason: 'path' };
2396
+ if (target === rulesDir || target.startsWith(rulesPrefix)) return { wrote: false, reason: 'rules' };
2397
+ let existing = null;
2398
+ try {
2399
+ existing = fs.readFileSync(target, 'utf8');
2400
+ } catch (error) {
2401
+ if (!error || error.code !== 'ENOENT') throw error;
2402
+ }
2403
+ if (existing !== null) {
2404
+ if (existing.indexOf(standardsDraftTag(provenance)) !== -1) {
2405
+ return { wrote: false, reason: 'same-provenance', target: target };
2406
+ }
2407
+ const prefix = existing.endsWith('\n') ? '' : '\n';
2408
+ fs.appendFileSync(target, prefix + line + '\n');
2409
+ return { wrote: true, target: target, mode: 'append-provenance' };
2410
+ }
2411
+ standardsDraftWrite(target, '# ' + stem + '\n\nPending draft. Inactive until a human moves this file into `.ai.local/rules/`.\n\n' + line + '\n');
2412
+ return { wrote: true, target: target, mode: 'create' };
2413
+ }
2414
+
2415
+ const conventionsPath = path.join(overlay, 'conventions.md');
2416
+ if (conventionsPath === rulesDir || conventionsPath.startsWith(rulesPrefix)) {
2417
+ return { wrote: false, reason: 'rules' };
2418
+ }
2419
+ let content = null;
2420
+ try {
2421
+ content = fs.readFileSync(conventionsPath, 'utf8');
2422
+ } catch (error) {
2423
+ if (!error || error.code !== 'ENOENT') throw error;
2424
+ }
2425
+ if (content === null) content = '# Living conventions\n';
2426
+ if (content.indexOf(standardsDraftTag(provenance)) !== -1) {
2427
+ return { wrote: false, reason: 'same-provenance', target: conventionsPath };
2428
+ }
2429
+ const before = standardsDraftProtected(content);
2430
+ const next = standardsDraftAppendPending(content, line);
2431
+ if (standardsDraftProtected(next) !== before) {
2432
+ return { wrote: false, reason: 'protected', target: conventionsPath };
2433
+ }
2434
+ standardsDraftWrite(conventionsPath, next);
2435
+ return {
2436
+ wrote: true,
2437
+ target: conventionsPath,
2438
+ mode: standardsDraftAccepted(content, text) ? 'provenance-only' : 'pending',
2439
+ };
2440
+ }
2441
+ // <<<standards-draft-end>>>
2442
+
1373
2443
  let input;
1374
2444
  try {
1375
2445
  input = JSON.parse(process.env.INPUT || '');
@@ -1402,6 +2472,12 @@ if (pipeline && (pipeline.profile === 'light' || pipeline.intent === 'spike')) {
1402
2472
  process.exit(0);
1403
2473
  }
1404
2474
 
2475
+ try {
2476
+ appendOptionalStandardsDraft(process.cwd(), input.standardsDraft);
2477
+ } catch {
2478
+ // A draft failure must not fail the stop, and must not add a WARNING.
2479
+ }
2480
+
1405
2481
  if (!fs.existsSync(path.join(process.cwd(), '.ai.local', 'scripts', 'run.mjs'))) {
1406
2482
  process.stderr.write(
1407
2483
  'WARNING: self-learning loop skipped: .ai.local/scripts/run.mjs is missing (install it with `npx @bonesofspring/ai-rules init <tool> --preset <stack>`)\n',