@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
@@ -260,10 +260,429 @@ function writeSkeletonManifest(manifestPath) {
260
260
  }
261
261
  }
262
262
 
263
+ function normalizeRepoPath(value) {
264
+ let text = typeof value === 'string' ? value.trim() : '';
265
+ text = text.replace(/\\/g, '/');
266
+ while (text.startsWith('./')) text = text.slice(2);
267
+ if (!text || text === '—' || text === '-' || text === '–') return '';
268
+ if (/[\s()]/.test(text)) return '';
269
+ return text;
270
+ }
271
+
272
+ function isAppPath(file) {
273
+ const normalized = normalizeRepoPath(file);
274
+ return normalized === 'app' || normalized.startsWith('app/') || normalized.startsWith('app/**') || normalized.startsWith('app/*');
275
+ }
276
+
277
+ function isSpecFolderPath(file) {
278
+ const normalized = normalizeRepoPath(file);
279
+ return normalized.startsWith('docs/specs/') || normalized.startsWith('docs/specs/**') || normalized.startsWith('openspec/') || normalized.startsWith('openspec/**');
280
+ }
281
+
282
+ function listsBothSpecAndApp(files) {
283
+ let app = false;
284
+ let spec = false;
285
+ for (const file of files || []) {
286
+ if (isAppPath(file)) app = true;
287
+ if (isSpecFolderPath(file)) spec = true;
288
+ }
289
+ return app && spec;
290
+ }
291
+
292
+ function pathInWriteScopes(file, writeScopes) {
293
+ const target = normalizeRepoPath(file);
294
+ if (!target) return false;
295
+ const scopes = Array.isArray(writeScopes) ? writeScopes : [];
296
+ for (const scope of scopes) {
297
+ const normalized = normalizeRepoPath(scope);
298
+ if (!normalized) continue;
299
+ if (normalized === target) return true;
300
+ if (normalized.endsWith('/**')) {
301
+ const prefix = normalized.slice(0, -3);
302
+ if (target === prefix || target.startsWith(prefix + '/')) return true;
303
+ } else if (normalized.endsWith('/*')) {
304
+ const prefix = normalized.slice(0, -2);
305
+ const rest = target.startsWith(prefix + '/') ? target.slice(prefix.length + 1) : '';
306
+ if (rest && !rest.includes('/')) return true;
307
+ }
308
+ }
309
+ return false;
310
+ }
311
+
312
+ function taskFileSet(task) {
313
+ const all = []
314
+ .concat((task && task.files) || [], (task && task.specFiles) || [], (task && task.appFiles) || [])
315
+ .map((file) => normalizeRepoPath(file))
316
+ .filter(Boolean);
317
+ return new Set(all);
318
+ }
319
+
320
+ function taskReaches(tasks, startId, targetId) {
321
+ const byId = new Map(tasks.map((task) => [String(task.id), task]));
322
+ const seen = new Set();
323
+ const stack = [String(startId)];
324
+ while (stack.length > 0) {
325
+ const id = stack.pop();
326
+ if (seen.has(id)) continue;
327
+ seen.add(id);
328
+ const task = byId.get(id);
329
+ const deps = task && Array.isArray(task.dependsOn) ? task.dependsOn : [];
330
+ for (const dep of deps) {
331
+ if (String(dep) === String(targetId)) return true;
332
+ stack.push(String(dep));
333
+ }
334
+ }
335
+ return false;
336
+ }
337
+
338
+ function tasksAreOrdered(tasks, left, right) {
339
+ return taskReaches(tasks, left.id, right.id) || taskReaches(tasks, right.id, left.id);
340
+ }
341
+
342
+ function validateTaskFileLists(tasks, writeScopes) {
343
+ const list = Array.isArray(tasks) ? tasks : [];
344
+ const scopes = Array.isArray(writeScopes) ? writeScopes : [];
345
+ for (const task of list) {
346
+ const id = task && task.id ? task.id : '(unnamed)';
347
+ const files = (task && task.files) || [];
348
+ if (listsBothSpecAndApp(files)) {
349
+ return 'task "' + id + '" lists spec-folder paths and app/** paths in one file list; they are different lists';
350
+ }
351
+ if (scopes.length === 0) continue;
352
+ const combined = files.concat((task && task.specFiles) || [], (task && task.appFiles) || []);
353
+ for (const file of combined) {
354
+ if (!pathInWriteScopes(file, scopes)) {
355
+ const label = normalizeRepoPath(file) || file;
356
+ return 'task "' + id + '" file "' + label + '" is outside the implementing step writeScopes';
357
+ }
358
+ }
359
+ }
360
+ for (let i = 0; i < list.length; i += 1) {
361
+ for (let j = i + 1; j < list.length; j += 1) {
362
+ if (tasksAreOrdered(list, list[i], list[j])) continue;
363
+ const left = taskFileSet(list[i]);
364
+ let shared = '';
365
+ for (const file of taskFileSet(list[j])) {
366
+ if (left.has(file)) {
367
+ shared = file;
368
+ break;
369
+ }
370
+ }
371
+ if (shared) return 'parallel tasks "' + list[i].id + '" and "' + list[j].id + '" share "' + shared + '"';
372
+ }
373
+ }
374
+ return null;
375
+ }
376
+
377
+ function productionPathsOutsideTaskList(paths, tasks) {
378
+ const allowed = new Set();
379
+ for (const task of tasks || []) {
380
+ for (const file of taskFileSet(task)) allowed.add(file);
381
+ }
382
+ const outside = [];
383
+ for (const cited of paths || []) {
384
+ const normalized = normalizeRepoPath(cited);
385
+ if (normalized && !allowed.has(normalized)) outside.push(normalized);
386
+ }
387
+ return outside;
388
+ }
389
+
390
+ function splitMarkdownCells(line) {
391
+ const trimmed = String(line || '').trim();
392
+ if (!trimmed.startsWith('|')) return [];
393
+ const cells = trimmed.split('|').map((cell) => cell.trim());
394
+ if (cells.length && cells[0] === '') cells.shift();
395
+ if (cells.length && cells[cells.length - 1] === '') cells.pop();
396
+ return cells;
397
+ }
398
+
399
+ function isSeparatorRow(cells) {
400
+ return cells.length > 0 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
401
+ }
402
+
403
+ function pathsFromCell(cell) {
404
+ const text = String(cell || '');
405
+ const found = [];
406
+ const pattern = /`([^`]+)`/g;
407
+ let match = pattern.exec(text);
408
+ while (match) {
409
+ const normalized = normalizeRepoPath(match[1]);
410
+ if (normalized && normalized.includes('/')) found.push(normalized);
411
+ match = pattern.exec(text);
412
+ }
413
+ if (found.length > 0) return found;
414
+ return text.split(',').map((part) => normalizeRepoPath(part)).filter((part) => part.includes('/'));
415
+ }
416
+
417
+ function dependsFromCell(cell) {
418
+ const cleaned = String(cell || '').replace(/[`*]/g, '').trim();
419
+ if (!cleaned || cleaned === '—' || cleaned === '-' || cleaned === '–') return [];
420
+ return cleaned.split(/[,|/]/).map((part) => part.trim()).filter((part) => /^[A-Za-z][A-Za-z0-9._-]*$/.test(part));
421
+ }
422
+
423
+ function cellIsComplete(cell) {
424
+ const cleaned = String(cell || '').replace(/[`*[\]]/g, '').trim().toLowerCase();
425
+ return cleaned === 'complete' || cleaned === 'completed' || cleaned === 'done' || cleaned === 'x';
426
+ }
427
+
428
+ function absorbMarkdownTable(block, byId) {
429
+ const rows = [];
430
+ for (const line of block) {
431
+ const cells = splitMarkdownCells(line);
432
+ if (cells.length === 0 || isSeparatorRow(cells)) continue;
433
+ rows.push(cells);
434
+ }
435
+ if (rows.length < 2) return false;
436
+ const headers = rows[0].map((cell) => cell.replace(/[`*]/g, '').trim());
437
+ const idIndex = headers.findIndex((header) => /^id$/i.test(header));
438
+ if (idIndex < 0) return false;
439
+ const dependsIndex = headers.findIndex((header) => /dependson/i.test(header));
440
+ const specIndex = headers.findIndex((header) => /spec files/i.test(header));
441
+ const appIndex = headers.findIndex((header) => /^app files$/i.test(header));
442
+ const filesIndex = headers.findIndex((header, index) => index !== specIndex && index !== appIndex && /files|paths/i.test(header));
443
+ const statusIndex = headers.findIndex((header) => /^(status|done|state)$/i.test(header));
444
+ const sawFiles = specIndex >= 0 || appIndex >= 0 || filesIndex >= 0;
445
+ for (const cells of rows.slice(1)) {
446
+ const id = String(cells[idIndex] || '').replace(/[`*]/g, '').trim();
447
+ if (!id || /^id$/i.test(id)) continue;
448
+ const task = byId.get(id) || { id, dependsOn: [], files: [], specFiles: [], appFiles: [], tracked: false, rowComplete: false };
449
+ if (dependsIndex >= 0) {
450
+ task.dependsOn = dependsFromCell(cells[dependsIndex] || '');
451
+ task.tracked = true;
452
+ }
453
+ if (statusIndex >= 0) task.rowComplete = cellIsComplete(cells[statusIndex] || '');
454
+ if (filesIndex >= 0) {
455
+ const parsed = pathsFromCell(cells[filesIndex] || '');
456
+ if (parsed.length > 0) task.files = parsed;
457
+ }
458
+ if (specIndex >= 0) {
459
+ const parsed = pathsFromCell(cells[specIndex] || '');
460
+ if (parsed.length > 0) task.specFiles = parsed;
461
+ }
462
+ if (appIndex >= 0) {
463
+ const parsed = pathsFromCell(cells[appIndex] || '');
464
+ if (parsed.length > 0) task.appFiles = parsed;
465
+ }
466
+ byId.set(id, task);
467
+ }
468
+ return sawFiles;
469
+ }
470
+
471
+ function parseDecompositionTaskFileLists(markdown) {
472
+ const lines = String(markdown || '').split(/\r?\n/);
473
+ const byId = new Map();
474
+ let hasFileColumn = false;
475
+ let index = 0;
476
+ while (index < lines.length) {
477
+ if (!String(lines[index] || '').trim().startsWith('|')) {
478
+ index += 1;
479
+ continue;
480
+ }
481
+ const block = [];
482
+ while (index < lines.length && String(lines[index] || '').trim().startsWith('|')) {
483
+ block.push(lines[index]);
484
+ index += 1;
485
+ }
486
+ if (absorbMarkdownTable(block, byId)) hasFileColumn = true;
487
+ }
488
+ return { tasks: [...byId.values()], hasFileColumn };
489
+ }
490
+
491
+ function parseDecompositionTasks(markdown) {
492
+ const lines = String(markdown || '').split(/\r?\n/);
493
+ const byId = new Map();
494
+ let index = 0;
495
+ while (index < lines.length) {
496
+ if (!String(lines[index] || '').trim().startsWith('|')) {
497
+ index += 1;
498
+ continue;
499
+ }
500
+ const block = [];
501
+ while (index < lines.length && String(lines[index] || '').trim().startsWith('|')) {
502
+ block.push(lines[index]);
503
+ index += 1;
504
+ }
505
+ absorbMarkdownTable(block, byId);
506
+ }
507
+ return [...byId.values()].filter((task) => task.tracked === true);
508
+ }
509
+
510
+ function taskCoveredByCompletedArtifact(taskId, artifacts) {
511
+ const id = String(taskId);
512
+ const list = Array.isArray(artifacts) ? artifacts : [];
513
+ for (let index = 0; index < list.length; index += 1) {
514
+ const artifact = list[index];
515
+ if (!artifact || artifact.status !== 'completed') continue;
516
+ if (String(artifact.id) === id) return true;
517
+ const taskIds = Array.isArray(artifact.taskIds) ? artifact.taskIds : [];
518
+ for (let taskIndex = 0; taskIndex < taskIds.length; taskIndex += 1) {
519
+ if (String(taskIds[taskIndex]) === id) return true;
520
+ }
521
+ }
522
+ return false;
523
+ }
524
+
525
+ function computeDecompositionReadySet(tasks, artifacts) {
526
+ const list = (Array.isArray(tasks) ? tasks : []).filter((task) => task && task.id && task.tracked !== false);
527
+ const complete = new Set();
528
+ for (let index = 0; index < list.length; index += 1) {
529
+ const task = list[index];
530
+ if (task.rowComplete === true || taskCoveredByCompletedArtifact(task.id, artifacts)) complete.add(String(task.id));
531
+ }
532
+ const ready = [];
533
+ const blocked = [];
534
+ for (let index = 0; index < list.length; index += 1) {
535
+ const task = list[index];
536
+ const id = String(task.id);
537
+ if (complete.has(id)) continue;
538
+ const deps = Array.isArray(task.dependsOn) ? task.dependsOn.map((dep) => String(dep)) : [];
539
+ const waiting = [];
540
+ const seen = new Set();
541
+ for (let depIndex = 0; depIndex < deps.length; depIndex += 1) {
542
+ const dep = deps[depIndex];
543
+ if (!dep || seen.has(dep) || complete.has(dep)) continue;
544
+ seen.add(dep);
545
+ waiting.push(dep);
546
+ }
547
+ if (waiting.length === 0) ready.push(id);
548
+ else blocked.push({ id, waiting_on: waiting });
549
+ }
550
+ return { ready, blocked };
551
+ }
552
+
553
+ function readManifestArtifacts(dir) {
554
+ try {
555
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
556
+ return Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
557
+ } catch {
558
+ return [];
559
+ }
560
+ }
561
+
562
+ function readDecompositionReadySet(dir) {
563
+ let markdown = '';
564
+ try {
565
+ markdown = fs.readFileSync(path.join(dir, 'decomposition.md'), 'utf8');
566
+ } catch {
567
+ markdown = '';
568
+ }
569
+ return computeDecompositionReadySet(parseDecompositionTasks(markdown), readManifestArtifacts(dir));
570
+ }
571
+
572
+ function formatDecompositionReadyClause(report, stepsForRows) {
573
+ const source = report && typeof report === 'object' ? report : { ready: [], blocked: [] };
574
+ const stepList = Array.isArray(stepsForRows) ? stepsForRows : [];
575
+ const allow = [];
576
+ for (let index = 0; index < stepList.length; index += 1) {
577
+ const taskIds = stepList[index] && stepList[index].taskIds;
578
+ if (!Array.isArray(taskIds)) continue;
579
+ for (let idIndex = 0; idIndex < taskIds.length; idIndex += 1) {
580
+ if (taskIds[idIndex] != null && String(taskIds[idIndex])) allow.push(String(taskIds[idIndex]));
581
+ }
582
+ }
583
+ const gate = allow.length > 0 ? new Set(allow) : null;
584
+ const ready = (Array.isArray(source.ready) ? source.ready : []).filter((id) => !gate || gate.has(String(id)));
585
+ const blocked = (Array.isArray(source.blocked) ? source.blocked : []).filter((row) => row && (!gate || gate.has(String(row.id))));
586
+ const readyText = ready.length > 0 ? ready.join(', ') : '(none)';
587
+ let text = ' Decomposition ready set: ' + readyText + '.';
588
+ if (blocked.length > 0) {
589
+ const parts = [];
590
+ for (let index = 0; index < blocked.length; index += 1) {
591
+ const row = blocked[index];
592
+ const waiting = Array.isArray(row.waiting_on) ? row.waiting_on.join(', ') : '';
593
+ parts.push(String(row.id) + ' waiting_on ' + waiting);
594
+ }
595
+ text += ' Blocked: ' + parts.join('; ') + '.';
596
+ }
597
+ return text;
598
+ }
599
+
600
+ function decompositionReadyClause(stepsForRows) {
601
+ try {
602
+ return formatDecompositionReadyClause(readDecompositionReadySet(taskDir), stepsForRows);
603
+ } catch {
604
+ return ' Decomposition ready set: (none).';
605
+ }
606
+ }
607
+
608
+ function productionCitationRepoPath(cited) {
609
+ const value = typeof cited === 'string' ? cited.trim() : '';
610
+ if (!value) return null;
611
+ const normalized = value.replace(/\\/g, '/');
612
+ if (path.isAbsolute(normalized)) {
613
+ const fromCwd = path.relative(process.cwd(), normalized);
614
+ if (fromCwd && !fromCwd.startsWith('..') && !path.isAbsolute(fromCwd)) return normalizeRepoPath(fromCwd);
615
+ return normalizeRepoPath(normalized) || normalized;
616
+ }
617
+ const taskResolved = path.resolve(taskDir, normalized);
618
+ const taskRelative = path.relative(taskDir, taskResolved);
619
+ const insideTask = taskRelative !== '' && taskRelative !== '..' && !taskRelative.startsWith('..' + path.sep) && !path.isAbsolute(taskRelative);
620
+ if (insideTask) {
621
+ try {
622
+ if (fs.statSync(taskResolved).isFile()) return null;
623
+ } catch {}
624
+ }
625
+ return normalizeRepoPath(normalized);
626
+ }
627
+
628
+ function implementingStepForTaskIds(taskIds) {
629
+ if (!Array.isArray(steps) || taskIds.length === 0) return null;
630
+ return steps.find((step) => Array.isArray(step && step.taskIds) && taskIds.some((id) => step.taskIds.map((item) => String(item)).includes(String(id)))) || null;
631
+ }
632
+
633
+ function productionWriteListError(entry) {
634
+ const artifactId = entry && entry.id ? entry.id : '(unnamed)';
635
+ const resume = 'Then resume with: /task-continue ' + slug;
636
+ const fail = (detail) => '[chain-team-phases] ' + slug + ': receipt "' + artifactId + '" ' + detail + ' ' + resume;
637
+ try {
638
+ const evidence = entry && Array.isArray(entry.evidencePaths) ? entry.evidencePaths : [];
639
+ const production = [];
640
+ for (const cited of evidence) {
641
+ const repoPath = productionCitationRepoPath(cited);
642
+ if (repoPath) production.push(repoPath);
643
+ }
644
+ if (production.length === 0) return null;
645
+ let markdown = '';
646
+ try {
647
+ markdown = fs.readFileSync(path.join(taskDir, 'decomposition.md'), 'utf8');
648
+ } catch {
649
+ markdown = '';
650
+ }
651
+ const parsed = parseDecompositionTaskFileLists(markdown);
652
+ if (!parsed.hasFileColumn) return null;
653
+ const tasks = parsed.tasks;
654
+ const taskIds = Array.isArray(entry && entry.taskIds) ? entry.taskIds.map((id) => String(id)) : [];
655
+ const step = implementingStepForTaskIds(taskIds);
656
+ const selectedIds = new Set(taskIds);
657
+ if (step && Array.isArray(step.taskIds)) {
658
+ for (const id of step.taskIds) selectedIds.add(String(id));
659
+ }
660
+ const selected = tasks.filter((task) => selectedIds.has(String(task.id)));
661
+ if (selected.length === 0) {
662
+ return fail('cites production paths but decomposition.md has no file list for ' + (taskIds.join(', ') || '(none)') + '. Record the task file list.');
663
+ }
664
+ const writeScopes = step && Array.isArray(step.writeScopes) ? step.writeScopes : [];
665
+ const listError = validateTaskFileLists(selected, writeScopes);
666
+ if (listError) return fail(listError + '.');
667
+ const owned = selected.filter((task) => taskIds.includes(String(task.id)));
668
+ const citedAgainst = owned.length > 0 ? owned : selected;
669
+ const outside = productionPathsOutsideTaskList(production, citedAgainst);
670
+ if (outside.length > 0) {
671
+ const ids = taskIds.length > 0 ? taskIds.join(', ') : citedAgainst.map((task) => task.id).join(', ');
672
+ return fail('cites production path "' + outside[0] + '", which is not on the decomposition file list for ' + ids + '.');
673
+ }
674
+ return null;
675
+ } catch (error) {
676
+ return fail('production file-list check failed (' + (error && error.message ? error.message : error) + ').');
677
+ }
678
+ }
679
+
263
680
  // A2: a `completed` receipt must cite evidence the harness can inspect. Order is
264
681
  // the message order — the first failing predicate wins, so the operator sees one
265
682
  // actionable line. `authoritativePaths[]` stays task-dir-relative; external
266
- // references belong in `evidencePaths[]`.
683
+ // references belong in `evidencePaths[]`. The task-folder checks below stay in
684
+ // place. A later production evidencePaths check uses the decomposition file list
685
+ // only when that list column exists.
267
686
  function validateCompletedArtifact(entry) {
268
687
  const artifactId = entry && entry.id ? entry.id : '(unnamed)';
269
688
  const entryStatus = entry && entry.status;
@@ -295,6 +714,8 @@ function validateCompletedArtifact(entry) {
295
714
  }
296
715
  }
297
716
  }
717
+ const productionListError = productionWriteListError(entry);
718
+ if (productionListError) return productionListError;
298
719
  return null;
299
720
  }
300
721
 
@@ -464,6 +885,309 @@ function recordSkippedStep(step, stepIndex) {
464
885
  }
465
886
  }
466
887
 
888
+ // Living task files and the hook ledger stay put. A completed entry's other markdown is the body that leaves the default read.
889
+ const CLOSED_BODY_KEEP = new Set([
890
+ 'brief.md',
891
+ 'decomposition.md',
892
+ 'goal.md',
893
+ 'prompt.md',
894
+ 'prompt-log.md',
895
+ 'pipeline.json',
896
+ 'implementation.md',
897
+ '.memlog.md',
898
+ 'focus.md',
899
+ 'status.json',
900
+ 'metrics.json',
901
+ 'artifact-manifest.json',
902
+ 'overlay-scope.json',
903
+ ]);
904
+
905
+ function closedMarkdownBody(dir, cited) {
906
+ if (typeof cited !== 'string') return null;
907
+ const value = cited.trim();
908
+ if (!value || path.isAbsolute(value)) return null;
909
+ const resolved = path.resolve(dir, value);
910
+ const relative = path.relative(dir, resolved);
911
+ if (!relative || relative === '..' || relative.startsWith('..' + path.sep) || path.isAbsolute(relative)) return null;
912
+ const normalized = relative.split(path.sep).join('/');
913
+ if (!/\.md$/i.test(normalized) || normalized.startsWith('archive/')) return null;
914
+ const base = normalized.slice(normalized.lastIndexOf('/') + 1);
915
+ if (CLOSED_BODY_KEEP.has(base) || CLOSED_BODY_KEEP.has(normalized)) return null;
916
+ return { resolved, base };
917
+ }
918
+
919
+ function archiveClosedBody(dir, date, id, body) {
920
+ const archiveDir = path.join(dir, 'archive', date);
921
+ fs.mkdirSync(archiveDir, { recursive: true });
922
+ let name = body.base;
923
+ let destination = path.join(archiveDir, name);
924
+ if (fs.existsSync(destination)) {
925
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(id)) return null;
926
+ name = id + '--' + body.base;
927
+ destination = path.join(archiveDir, name);
928
+ }
929
+ if (fs.existsSync(destination)) return null;
930
+ fs.renameSync(body.resolved, destination);
931
+ return 'archive/' + date + '/' + name;
932
+ }
933
+
934
+ function appendMemlogEvent(dir, text) {
935
+ const memlogPath = path.join(dir, '.memlog.md');
936
+ const line = '- `event`: ' + text + '\n';
937
+ let existing = '';
938
+ try { existing = fs.readFileSync(memlogPath, 'utf8'); } catch { existing = ''; }
939
+ if (existing.includes(text)) return existing;
940
+ const prefix = existing.length > 0 && !existing.endsWith('\n') ? '\n' : '';
941
+ fs.appendFileSync(memlogPath, prefix + line);
942
+ return existing + prefix + line;
943
+ }
944
+
945
+ function writeJsonFile(filePath, value) {
946
+ const temporary = filePath + '.' + String(process.pid) + '.tmp';
947
+ const fd = fs.openSync(temporary, 'w');
948
+ try {
949
+ fs.writeSync(fd, JSON.stringify(value, null, 2) + '\n');
950
+ } finally {
951
+ fs.closeSync(fd);
952
+ }
953
+ fs.renameSync(temporary, filePath);
954
+ }
955
+
956
+ function compactClosedManifestBodies(dir, closedOn) {
957
+ const date = typeof closedOn === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(closedOn)
958
+ ? closedOn
959
+ : new Date().toISOString().slice(0, 10);
960
+ const manifestPath = path.join(dir, 'artifact-manifest.json');
961
+ let manifest;
962
+ try {
963
+ manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
964
+ } catch {
965
+ return { moved: [] };
966
+ }
967
+ const slugBefore = manifest.slug;
968
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
969
+ let memlog = '';
970
+ try { memlog = fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8'); } catch { memlog = ''; }
971
+ let manifestChanged = false;
972
+ const moved = [];
973
+ for (let index = 0; index < artifacts.length; index += 1) {
974
+ const entry = artifacts[index];
975
+ if (!entry || entry.status !== 'completed' || typeof entry.id !== 'string' || !entry.id) continue;
976
+ const marker = 'closed manifest artifact ' + entry.id + ';';
977
+ if (memlog.includes(marker)) continue;
978
+ const cited = Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths.slice() : [];
979
+ const relocated = [];
980
+ for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
981
+ const body = closedMarkdownBody(dir, cited[pathIndex]);
982
+ if (!body) continue;
983
+ let stat = null;
984
+ try { stat = fs.statSync(body.resolved); } catch { stat = null; }
985
+ if (!stat || !stat.isFile()) continue;
986
+ let content = '';
987
+ try { content = fs.readFileSync(body.resolved, 'utf8'); } catch { content = ''; }
988
+ if (!/\S/.test(content)) continue;
989
+ const archived = archiveClosedBody(dir, date, entry.id, body);
990
+ if (!archived) continue;
991
+ cited[pathIndex] = archived;
992
+ relocated.push(archived);
993
+ moved.push(archived);
994
+ manifestChanged = true;
995
+ }
996
+ if (relocated.length > 0) entry.authoritativePaths = cited;
997
+ let archiveHint = relocated.length > 0 ? 'archive/' + date + '/' : '';
998
+ if (!archiveHint) {
999
+ for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
1000
+ const value = typeof cited[pathIndex] === 'string' ? cited[pathIndex].trim() : '';
1001
+ const match = /^archive\/\d{4}-\d{2}-\d{2}\//.exec(value);
1002
+ if (match) {
1003
+ archiveHint = match[0];
1004
+ break;
1005
+ }
1006
+ }
1007
+ }
1008
+ const text = archiveHint
1009
+ ? 'closed manifest artifact ' + entry.id + '; body archived under ' + archiveHint
1010
+ : 'closed manifest artifact ' + entry.id + '; no bulky markdown body moved';
1011
+ memlog = appendMemlogEvent(dir, text);
1012
+ }
1013
+ if (manifest.slug !== slugBefore) manifest.slug = slugBefore;
1014
+ if (manifestChanged) writeJsonFile(manifestPath, manifest);
1015
+ return { moved };
1016
+ }
1017
+
1018
+ function projectResumeArtifact(entry) {
1019
+ if (!entry || typeof entry !== 'object') return entry;
1020
+ if (entry.status !== 'completed') return entry;
1021
+ return {
1022
+ id: entry.id,
1023
+ status: entry.status,
1024
+ authoritativePaths: Array.isArray(entry.authoritativePaths) ? entry.authoritativePaths : [],
1025
+ };
1026
+ }
1027
+
1028
+ function defaultResumeRead(dir) {
1029
+ const chunks = [];
1030
+ try { chunks.push(fs.readFileSync(path.join(dir, 'focus.md'), 'utf8')); } catch {}
1031
+ try {
1032
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
1033
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
1034
+ const projected = [];
1035
+ for (let index = 0; index < artifacts.length; index += 1) {
1036
+ projected.push(projectResumeArtifact(artifacts[index]));
1037
+ }
1038
+ chunks.push(JSON.stringify({ slug: manifest.slug, artifacts: projected }));
1039
+ } catch {}
1040
+ try { chunks.push(fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8')); } catch {}
1041
+ return chunks.join('\n');
1042
+ }
1043
+
1044
+ function archiveIndexLine(dir) {
1045
+ const root = path.join(dir, 'archive');
1046
+ let names = [];
1047
+ try { names = fs.readdirSync(root); } catch { names = []; }
1048
+ const dates = [];
1049
+ for (let index = 0; index < names.length; index += 1) {
1050
+ const name = names[index];
1051
+ if (!/^\d{4}-\d{2}-\d{2}$/.test(name)) continue;
1052
+ let stat = null;
1053
+ try { stat = fs.statSync(path.join(root, name)); } catch { stat = null; }
1054
+ if (stat && stat.isDirectory()) dates.push(name);
1055
+ }
1056
+ dates.sort();
1057
+ if (dates.length === 0) return '- archive index: (none)';
1058
+ const parts = [];
1059
+ for (let index = 0; index < dates.length; index += 1) parts.push('archive/' + dates[index] + '/');
1060
+ return '- archive index: ' + parts.join(', ');
1061
+ }
1062
+
1063
+ function focusDigestMarkdown(dir, statusSnapshot) {
1064
+ const snapshot = statusSnapshot && typeof statusSnapshot === 'object' ? statusSnapshot : {};
1065
+ const slugValue = typeof snapshot.slug === 'string' ? snapshot.slug : '';
1066
+ const stepIndex = Number.isInteger(snapshot.pipelineIndex) ? snapshot.pipelineIndex : 0;
1067
+ const incomplete = [];
1068
+ try {
1069
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'artifact-manifest.json'), 'utf8'));
1070
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
1071
+ for (let index = 0; index < artifacts.length; index += 1) {
1072
+ const artifact = artifacts[index];
1073
+ if (!artifact || artifact.status === 'completed') continue;
1074
+ const id = typeof artifact.id === 'string' ? artifact.id : '(no id)';
1075
+ const cited = Array.isArray(artifact.authoritativePaths) ? artifact.authoritativePaths : [];
1076
+ const paths = [];
1077
+ for (let pathIndex = 0; pathIndex < cited.length; pathIndex += 1) {
1078
+ if (typeof cited[pathIndex] === 'string') paths.push(cited[pathIndex]);
1079
+ }
1080
+ incomplete.push({ id, paths });
1081
+ }
1082
+ } catch {}
1083
+ let lastEvent = '(none)';
1084
+ try {
1085
+ const raw = fs.readFileSync(path.join(dir, '.memlog.md'), 'utf8');
1086
+ const lines = raw.split(/\r?\n/);
1087
+ const tickEvent = /`event`:\s*(.*)$/;
1088
+ const bareEvent = /(?:^|\s)event:\s*(.*)$/;
1089
+ for (let index = lines.length - 1; index >= 0; index -= 1) {
1090
+ const line = lines[index];
1091
+ let matched = tickEvent.exec(line);
1092
+ if (!matched) matched = bareEvent.exec(line);
1093
+ if (matched && matched[1].trim()) {
1094
+ lastEvent = matched[1].trim();
1095
+ break;
1096
+ }
1097
+ }
1098
+ } catch {}
1099
+ let nextGate = 'none';
1100
+ if (snapshot.awaitingHumanGate === true || snapshot.state === 'awaiting_approval') {
1101
+ nextGate = 'human gate — /task-continue ' + slugValue;
1102
+ } else {
1103
+ try {
1104
+ const pipeline = JSON.parse(fs.readFileSync(path.join(dir, 'pipeline.json'), 'utf8'));
1105
+ const steps = Array.isArray(pipeline.steps) ? pipeline.steps : [];
1106
+ const gates = Array.isArray(pipeline.humanGates) ? pipeline.humanGates : [];
1107
+ for (let index = stepIndex; index < steps.length; index += 1) {
1108
+ const step = steps[index];
1109
+ const agents = !step ? [] : (Array.isArray(step.agent) ? step.agent : [step.agent]);
1110
+ let hit = '';
1111
+ for (let agentIndex = 0; agentIndex < agents.length; agentIndex += 1) {
1112
+ const agent = agents[agentIndex];
1113
+ if (typeof agent === 'string' && gates.indexOf('after:' + agent) !== -1) {
1114
+ hit = agent;
1115
+ break;
1116
+ }
1117
+ }
1118
+ if (hit) {
1119
+ const stepId = step && typeof step.id === 'string' ? step.id : 'step-' + String(index);
1120
+ nextGate = 'after:' + hit + ' (step ' + stepId + ', index ' + String(index) + ')';
1121
+ break;
1122
+ }
1123
+ }
1124
+ } catch {}
1125
+ }
1126
+ const pathLines = [];
1127
+ if (incomplete.length === 0) pathLines.push(' - (none)');
1128
+ else {
1129
+ for (let index = 0; index < incomplete.length; index += 1) {
1130
+ const item = incomplete[index];
1131
+ if (item.paths.length === 0) pathLines.push(' - ' + item.id + ': (none)');
1132
+ else {
1133
+ for (let pathIndex = 0; pathIndex < item.paths.length; pathIndex += 1) {
1134
+ pathLines.push(' - ' + item.id + ': ' + item.paths[pathIndex]);
1135
+ }
1136
+ }
1137
+ }
1138
+ }
1139
+ let readyLine = '- decomposition ready set: (none)';
1140
+ try {
1141
+ const report = readDecompositionReadySet(dir);
1142
+ const ids = Array.isArray(report.ready) ? report.ready : [];
1143
+ readyLine = '- decomposition ready set: ' + (ids.length > 0 ? ids.join(', ') : '(none)');
1144
+ } catch {
1145
+ readyLine = '- decomposition ready set: (none)';
1146
+ }
1147
+ const head = [
1148
+ '# focus.md',
1149
+ '',
1150
+ 'View only. `status.json`, `metrics.json`, `artifact-manifest.json`, and `.memlog.md` stay the system of record.',
1151
+ '',
1152
+ '- slug: ' + slugValue,
1153
+ '- pipeline step index: ' + String(stepIndex),
1154
+ readyLine,
1155
+ archiveIndexLine(dir),
1156
+ '- incomplete authoritative paths:',
1157
+ ];
1158
+ const tail = [
1159
+ '- last memlog event: ' + lastEvent,
1160
+ '- next gate: ' + nextGate,
1161
+ ];
1162
+ let pathBudget = 99 - head.length - tail.length;
1163
+ if (pathBudget < 1) pathBudget = 1;
1164
+ let kept = pathLines;
1165
+ if (pathLines.length > pathBudget) {
1166
+ const room = pathBudget - 1;
1167
+ kept = pathLines.slice(0, room);
1168
+ const omitted = pathLines.length - kept.length;
1169
+ kept.push(' - (' + String(omitted) + ' lines omitted to stay under 100)');
1170
+ }
1171
+ return head.concat(kept, tail).join('\n') + '\n';
1172
+ }
1173
+
1174
+ function writeFocusDigest() {
1175
+ const focusPath = path.join(taskDir, 'focus.md');
1176
+ const temporary = focusPath + '.' + String(process.pid) + '.' + String(Date.now()) + '.tmp';
1177
+ try {
1178
+ const markdown = focusDigestMarkdown(taskDir, status);
1179
+ const fd = fs.openSync(temporary, 'w');
1180
+ try {
1181
+ fs.writeSync(fd, markdown);
1182
+ try { fs.fsyncSync(fd); } catch {}
1183
+ } finally {
1184
+ fs.closeSync(fd);
1185
+ }
1186
+ fs.renameSync(temporary, focusPath);
1187
+ } catch {
1188
+ try { fs.unlinkSync(temporary); } catch {}
1189
+ }
1190
+ }
467
1191
 
468
1192
  function writeStatus(next) {
469
1193
  status = { ...status, ...next, slug, updatedAt: now };
@@ -480,6 +1204,11 @@ function writeStatus(next) {
480
1204
  fs.closeSync(fd);
481
1205
  }
482
1206
  fs.renameSync(temporary, statusPath);
1207
+ // Closed bodies move after the checkpoint lands. A compaction miss must not roll status.json back.
1208
+ try { compactClosedManifestBodies(taskDir, now.slice(0, 10)); } catch {}
1209
+ // focus.md is a view of this checkpoint. It is written after status.json
1210
+ // lands so a digest failure cannot roll the checkpoint back.
1211
+ writeFocusDigest();
483
1212
  }
484
1213
 
485
1214
  function out(message) {
@@ -642,7 +1371,8 @@ function handoffForWave(units, waveId) {
642
1371
  `Invoke IN PARALLEL (one message, multiple Task calls): ${labels.join(' AND ')} for slug "${slug}"${waveId ? ` (waveId=${waveId})` : ''}. ` +
643
1372
  `Each agent writes its artifact and owned receipt; the hook records slot joins from stops. Do not mutate status.json lifecycle fields. ` +
644
1373
  `Artifact inputs: ${inputIds.length > 0 ? inputIds.join(', ') : 'manifest defaults'}; owned output IDs: ${outputIds.join('; ')}. ` +
645
- `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()}`
1374
+ `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()}` +
1375
+ decompositionReadyClause(units.map((unit) => steps[unit.stepIndex]))
646
1376
  );
647
1377
  }
648
1378
  function blockedNotice(blockedIndex, agent) {
@@ -678,6 +1408,9 @@ function dispatchReadyWave(prefixMessage) {
678
1408
  // Slot-filtered dispatch: only unsatisfied (stepIndex, agent) slots are invoked.
679
1409
  const units = wave.flatMap((stepIndex) => unsatisfiedAgents(stepIndex).map((agent) => ({ stepIndex, agent })));
680
1410
  if (units.length === 0) return false;
1411
+ const unitAgents = units.map((unit) => unit.agent);
1412
+ refuseImplementationStart(unitAgents, (agent) => implementationDebugRetry(agent));
1413
+ recordAllowedDebugRetries(unitAgents);
681
1414
  const first = units[0].stepIndex;
682
1415
  const waveId = `${status.metricsRunId || slug}:wave-${first}`;
683
1416
  for (const unit of units) activateAttempts(steps[unit.stepIndex], unit.stepIndex, units.length > 1 ? waveId : null, [unit.agent]);
@@ -784,10 +1517,165 @@ function artifactHandoff(step, agent) {
784
1517
  return ` Artifact inputs: ${inputIds}; owned output ID: ${artifactOutputIdFor(step, agent)}. Bind the terminal receipt to the supplied attemptId. ${receiptPathClause()}`;
785
1518
  }
786
1519
 
1520
+ // <<<implementation-rail>>>
1521
+ // Opt-in. Omitted, "off", and non-production intents stay off. Only "on" applies.
1522
+ function testBeforeHandoffRule() {
1523
+ return 'Include unit tests for mappers/logic before handoff.';
1524
+ }
1525
+ function railOnHandoffClause() {
1526
+ 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.';
1527
+ }
1528
+ function implementationRailApplies(pipeline) {
1529
+ if (!pipeline || typeof pipeline !== 'object') return false;
1530
+ const intent = typeof pipeline.intent === 'string' ? pipeline.intent : '';
1531
+ const level = pipeline.taskLevel;
1532
+ if (level === 'L0' || level === 0 || level === '0') return false;
1533
+ if (intent === 'docs-only' || intent === 'research' || intent === 'preset-only' || intent === 'spike') return false;
1534
+ if (pipeline.presetOnly === true) return false;
1535
+ return pipeline.implementationRail === 'on';
1536
+ }
1537
+ function briefHasOpenClarificationMarker(text) {
1538
+ if (typeof text !== 'string' || text.length === 0) return false;
1539
+ const lines = text.split(/\r?\n/);
1540
+ for (let index = 0; index < lines.length; index += 1) {
1541
+ let body = lines[index].trim().replace(/^(?:>\s*)+/, '');
1542
+ body = body.replace(/^(?:[-*+]|\d+[.)])\s+/, '');
1543
+ if (body.startsWith('[NEEDS CLARIFICATION]')) return true;
1544
+ }
1545
+ return false;
1546
+ }
1547
+ function implementationHandoffDecision(input) {
1548
+ const agent = input && input.agent;
1549
+ const applies = agent === 'feature-developer' && implementationRailApplies(input && input.pipeline);
1550
+ if (!applies) {
1551
+ return {
1552
+ start: true,
1553
+ rail: 'off',
1554
+ handoffRule: agent === 'feature-developer' ? testBeforeHandoffRule() : null,
1555
+ constraints: [],
1556
+ };
1557
+ }
1558
+ if (briefHasOpenClarificationMarker(input && input.briefText)) {
1559
+ return { start: false, rail: 'on', reason: 'open-marker', handoffRule: testBeforeHandoffRule(), constraints: [] };
1560
+ }
1561
+ const debugRetries = Number(input && input.debugRetryCount) || 0;
1562
+ if (input && input.debugRetry === true && debugRetries >= 2) {
1563
+ return { start: false, rail: 'on', reason: 'debug-retry-cap', handoffRule: testBeforeHandoffRule(), constraints: [] };
1564
+ }
1565
+ return {
1566
+ start: true,
1567
+ rail: 'on',
1568
+ handoffRule: testBeforeHandoffRule(),
1569
+ constraints: [
1570
+ 'failing test before production edits',
1571
+ 'branch or worktree before the first implementation task',
1572
+ 'code-reviewer between decomposition tasks',
1573
+ 'debug retries capped at two',
1574
+ ],
1575
+ };
1576
+ }
1577
+ // <<<implementation-rail-end>>>
1578
+
1579
+ function readPipelineRecord() {
1580
+ try {
1581
+ return JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
1582
+ } catch {
1583
+ return null;
1584
+ }
1585
+ }
1586
+ function readBriefText() {
1587
+ try {
1588
+ return fs.readFileSync(path.join(taskDir, 'brief.md'), 'utf8');
1589
+ } catch {
1590
+ return '';
1591
+ }
1592
+ }
1593
+ function countDebugImplementationRetries() {
1594
+ try {
1595
+ const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
1596
+ const events = Array.isArray(metrics.events) ? metrics.events : [];
1597
+ return events.filter((event) => event && event.type === 'retry_scheduled' && event.nextAgent === 'feature-developer' && event.retryAfterFix === 'debugger').length;
1598
+ } catch {
1599
+ return 0;
1600
+ }
1601
+ }
1602
+ function featureDeveloperAlreadyStarted() {
1603
+ try {
1604
+ const metrics = JSON.parse(fs.readFileSync(METRICS_PATH, 'utf8'));
1605
+ const events = Array.isArray(metrics.events) ? metrics.events : [];
1606
+ return events.some((event) => event && event.type === 'attempt_started' && event.agent === 'feature-developer');
1607
+ } catch {
1608
+ return false;
1609
+ }
1610
+ }
1611
+ function implementationDebugRetry(agent) {
1612
+ return agent === 'feature-developer' && status.currentAgent === 'debugger' && featureDeveloperAlreadyStarted();
1613
+ }
1614
+ function blockImplementationStart(agent, debugRetry) {
1615
+ const decision = implementationHandoffDecision({
1616
+ agent,
1617
+ pipeline: readPipelineRecord(),
1618
+ briefText: readBriefText(),
1619
+ debugRetry: Boolean(debugRetry),
1620
+ debugRetryCount: countDebugImplementationRetries(),
1621
+ });
1622
+ if (decision.start) return null;
1623
+ if (decision.reason === 'debug-retry-cap') {
1624
+ return `Strict implementation rail is on for slug "${slug}". Debug retries for the implementation handoff are capped at two. Do not start implementation.`;
1625
+ }
1626
+ return `Strict implementation rail is on for slug "${slug}" and a [NEEDS CLARIFICATION] marker is open. Do not start implementation.`;
1627
+ }
1628
+ function refuseImplementationStart(agents, debugRetryFor) {
1629
+ const list = Array.isArray(agents) ? agents : [agents];
1630
+ for (let index = 0; index < list.length; index += 1) {
1631
+ const block = blockImplementationStart(list[index], debugRetryFor(list[index]));
1632
+ if (!block) continue;
1633
+ beginHumanGate();
1634
+ writeStatus({
1635
+ state: 'awaiting_approval',
1636
+ phase: 'human_gate',
1637
+ awaitingHumanGate: true,
1638
+ waveSteps: [],
1639
+ waveId: null,
1640
+ retryAfterFix: null,
1641
+ retryAfterFixStepIndex: null,
1642
+ });
1643
+ out(block);
1644
+ process.exit(0);
1645
+ }
1646
+ }
1647
+ function recordAllowedDebugRetries(agents) {
1648
+ if (!implementationRailApplies(readPipelineRecord())) return;
1649
+ const list = Array.isArray(agents) ? agents : [agents];
1650
+ for (let index = 0; index < list.length; index += 1) {
1651
+ if (!implementationDebugRetry(list[index])) continue;
1652
+ appendMetric({
1653
+ type: 'retry_scheduled',
1654
+ at: now,
1655
+ attemptId: null,
1656
+ nextAgent: 'feature-developer',
1657
+ retryAfterFix: 'debugger',
1658
+ source: 'hook',
1659
+ attributionConfidence: 'high',
1660
+ });
1661
+ }
1662
+ }
1663
+ function railInstructionClause(agent) {
1664
+ const decision = implementationHandoffDecision({
1665
+ agent,
1666
+ pipeline: readPipelineRecord(),
1667
+ briefText: readBriefText(),
1668
+ debugRetry: false,
1669
+ debugRetryCount: 0,
1670
+ });
1671
+ if (decision.rail !== 'on' || !decision.start) return '';
1672
+ return railOnHandoffClause();
1673
+ }
1674
+
787
1675
  function handoffForAgent(agent, scope, step = null) {
788
1676
  const fn = AGENT_HANDOFF[agent];
789
1677
  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.`;
790
- return handoff + artifactHandoff(step, agent) + metricsHandoff(agent);
1678
+ return handoff + railInstructionClause(agent) + artifactHandoff(step, agent) + metricsHandoff(agent) + decompositionReadyClause(step ? [step] : []);
791
1679
  }
792
1680
 
793
1681
  function handoffForParallelStep(step) {
@@ -799,7 +1687,8 @@ function handoffForParallelStep(step) {
799
1687
  `Invoke IN PARALLEL (one message, multiple Task calls): ${agents.join(' AND ')} for slug "${slug}". ` +
800
1688
  `Each agent writes its artifact and owned receipt; the hook records parallelCompleted from stops. Do not mutate status.json lifecycle fields. ` +
801
1689
  `Artifact inputs: ${Array.isArray(step.artifactInputIds) ? step.artifactInputIds.join(', ') : 'manifest defaults'}; owned output IDs: ${agents.map((agent) => `${agent}=${artifactOutputIdFor(step, agent)}`).join('; ')}. ` +
802
- `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()}`
1690
+ `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()}` +
1691
+ decompositionReadyClause([step])
803
1692
  );
804
1693
  }
805
1694
 
@@ -962,6 +1851,8 @@ if (hookInput.action === 'end_human_gate') {
962
1851
  const resumeNext = findNextExecutableStep(resumeSteps, resumeStart, taskDir);
963
1852
  if (resumeNext) {
964
1853
  const resumeAgents = getStepAgents(resumeNext.step);
1854
+ refuseImplementationStart(resumeAgents, (agent) => implementationDebugRetry(agent));
1855
+ recordAllowedDebugRetries(resumeAgents);
965
1856
  activateAttempts(resumeNext.step, resumeNext.index);
966
1857
  writeStatus({
967
1858
  pipelineIndex: resumeNext.index,
@@ -1118,6 +2009,9 @@ function nearestPrecedingStepIndex(agent, fromIndex, fallback) {
1118
2009
  return match >= 0 ? match : fallback;
1119
2010
  }
1120
2011
  function scheduleRetry(agent, retryAfterFix, predecessor, explicitStepIndex = null) {
2012
+ if (agent === 'feature-developer') {
2013
+ refuseImplementationStart([agent], () => retryAfterFix === 'debugger');
2014
+ }
1121
2015
  const currentIndex = typeof status.pipelineIndex === 'number' ? status.pipelineIndex : 0;
1122
2016
  const explicitOk = Number.isInteger(explicitStepIndex) && getStepAgents(steps[explicitStepIndex]).includes(agent);
1123
2017
  const stepIndex = explicitOk ? explicitStepIndex : nearestPrecedingStepIndex(agent, currentIndex, -1);
@@ -1425,6 +2319,8 @@ if (!next) {
1425
2319
  const { step: nextStep, index: nextIdx } = next;
1426
2320
  const nextAgents = getStepAgents(nextStep);
1427
2321
 
2322
+ refuseImplementationStart(nextAgents, (agent) => implementationDebugRetry(agent));
2323
+ recordAllowedDebugRetries(nextAgents);
1428
2324
  activateAttempts(nextStep, nextIdx);
1429
2325
  writeStatus({
1430
2326
  pipelineIndex: nextIdx,
@@ -1453,6 +2349,180 @@ const fs = require('fs');
1453
2349
  const path = require('path');
1454
2350
  const { spawnSync } = require('child_process');
1455
2351
 
2352
+ // <<<standards-draft>>>
2353
+ // Explicit payload only. This postflight never walks the repo and never
2354
+ // creates `.ai.local/rules/`. The same provenance tag does not rewrite an
2355
+ // accepted Gotchas, Patterns, or Decisions line.
2356
+ function standardsDraftTag(provenance) {
2357
+ return '(`' + provenance + '`)';
2358
+ }
2359
+
2360
+ function standardsDraftLineIndex(content, header) {
2361
+ if (content.startsWith(header) && (content.length === header.length || content.charAt(header.length) === '\n')) return 0;
2362
+ const at = content.indexOf('\n' + header + '\n');
2363
+ if (at !== -1) return at + 1;
2364
+ if (content.endsWith('\n' + header)) return content.length - header.length;
2365
+ return -1;
2366
+ }
2367
+
2368
+ function standardsDraftSection(content, name) {
2369
+ const header = '## ' + name;
2370
+ const start = standardsDraftLineIndex(content, header);
2371
+ if (start === -1) return null;
2372
+ const from = start + header.length;
2373
+ const next = content.indexOf('\n## ', from);
2374
+ const end = next === -1 ? content.length : next;
2375
+ return content.slice(start, end);
2376
+ }
2377
+
2378
+ function standardsDraftProtected(content) {
2379
+ const names = ['Language', 'Gotchas', 'Patterns', 'Decisions', 'Advisory index'];
2380
+ let snapshot = '';
2381
+ for (let index = 0; index < names.length; index += 1) {
2382
+ const body = standardsDraftSection(content, names[index]);
2383
+ snapshot += names[index] + '\n' + (body === null ? '' : body) + '\n';
2384
+ }
2385
+ return snapshot;
2386
+ }
2387
+
2388
+ function standardsDraftNormalize(line) {
2389
+ return line.trim().replace(/\s+/g, ' ').replace(/^-\s+/, '').replace(/\s+\(`[^`]*`\)$/, '').toLowerCase();
2390
+ }
2391
+
2392
+ function standardsDraftAccepted(content, text) {
2393
+ const pending = standardsDraftSection(content, 'Pending');
2394
+ let rest = content;
2395
+ if (pending !== null) {
2396
+ const start = content.indexOf(pending);
2397
+ rest = content.slice(0, start) + content.slice(start + pending.length);
2398
+ }
2399
+ const needle = standardsDraftNormalize(text);
2400
+ if (!needle) return false;
2401
+ const lines = rest.split('\n');
2402
+ for (let index = 0; index < lines.length; index += 1) {
2403
+ const line = lines[index];
2404
+ if (!/^-\s+\S/.test(line)) continue;
2405
+ if (standardsDraftNormalize(line) === needle) return true;
2406
+ }
2407
+ return false;
2408
+ }
2409
+
2410
+ function standardsDraftAppendPending(content, line) {
2411
+ const header = '## Pending';
2412
+ const start = standardsDraftLineIndex(content, header);
2413
+ if (start === -1) {
2414
+ const sep = content.endsWith('\n') ? '\n' : '\n\n';
2415
+ return content + sep + header + '\n\n' + line + '\n';
2416
+ }
2417
+ const from = start + header.length;
2418
+ const next = content.indexOf('\n## ', from);
2419
+ const end = next === -1 ? content.length : next;
2420
+ let body = content.slice(from, end);
2421
+ const hasBullet = /(^|\n)-\s+\S/.test(body);
2422
+ if (!hasBullet && /(^|\n)-[ \t]*(?=\n|$)/.test(body)) {
2423
+ body = body.replace(/(^|\n)-[ \t]*(?=\n|$)/, '$1' + line);
2424
+ } else if (body.endsWith('\n\n')) {
2425
+ body = body.slice(0, -1) + line + '\n\n';
2426
+ } else if (body.endsWith('\n')) {
2427
+ body = body + line + '\n';
2428
+ } else {
2429
+ body = body + '\n' + line + '\n';
2430
+ }
2431
+ return content.slice(0, from) + body + content.slice(end);
2432
+ }
2433
+
2434
+ function standardsDraftProvenance(draft) {
2435
+ if (!draft || typeof draft.provenance !== 'string') return '';
2436
+ const provenance = draft.provenance.trim();
2437
+ if (/^incident: [A-Za-z0-9][A-Za-z0-9._:-]{0,80}$/.test(provenance)) return provenance;
2438
+ const read = /^read: ([A-Za-z0-9][A-Za-z0-9._/-]{0,160})$/.exec(provenance);
2439
+ if (!read) return '';
2440
+ const parts = read[1].split('/');
2441
+ if (parts.indexOf('..') !== -1 || parts.indexOf('.') !== -1) return '';
2442
+ if (read[1] === '.ai.local/rules' || read[1].indexOf('.ai.local/rules/') === 0) return '';
2443
+ return provenance;
2444
+ }
2445
+
2446
+ function standardsDraftWrite(target, content) {
2447
+ fs.mkdirSync(path.dirname(target), { recursive: true });
2448
+ const temporary = target + '.' + String(process.pid) + '.tmp';
2449
+ fs.writeFileSync(temporary, content);
2450
+ fs.renameSync(temporary, target);
2451
+ }
2452
+
2453
+ function appendOptionalStandardsDraft(root, draft) {
2454
+ const provenance = standardsDraftProvenance(draft);
2455
+ if (!provenance) return { wrote: false, reason: 'provenance' };
2456
+ const text = draft && typeof draft.text === 'string' ? draft.text.trim() : '';
2457
+ if (!text || text.length > 400 || text.indexOf('\n') !== -1 || text.indexOf('\r') !== -1 || text.indexOf('## ') !== -1) {
2458
+ return { wrote: false, reason: 'text' };
2459
+ }
2460
+ let destination = 'conventions';
2461
+ if (draft.destination != null) {
2462
+ if (draft.destination === 'conventions' || draft.destination === 'rules-library') destination = draft.destination;
2463
+ else return { wrote: false, reason: 'destination' };
2464
+ }
2465
+ const line = '- ' + text + ' ' + standardsDraftTag(provenance);
2466
+ const overlay = path.join(root, '.ai.local');
2467
+ const rulesDir = path.join(overlay, 'rules');
2468
+ const rulesPrefix = rulesDir + path.sep;
2469
+
2470
+ if (destination === 'rules-library') {
2471
+ const stem = draft && typeof draft.stem === 'string' ? draft.stem : '';
2472
+ if (!/^[a-z0-9]+(?:-[a-z0-9]+){0,8}$/.test(stem) || stem.length > 48) {
2473
+ return { wrote: false, reason: 'stem' };
2474
+ }
2475
+ const libraryDir = path.join(overlay, 'rules-library');
2476
+ const target = path.join(libraryDir, stem + '.md');
2477
+ const libraryPrefix = libraryDir + path.sep;
2478
+ if (!target.startsWith(libraryPrefix)) return { wrote: false, reason: 'path' };
2479
+ if (target === rulesDir || target.startsWith(rulesPrefix)) return { wrote: false, reason: 'rules' };
2480
+ let existing = null;
2481
+ try {
2482
+ existing = fs.readFileSync(target, 'utf8');
2483
+ } catch (error) {
2484
+ if (!error || error.code !== 'ENOENT') throw error;
2485
+ }
2486
+ if (existing !== null) {
2487
+ if (existing.indexOf(standardsDraftTag(provenance)) !== -1) {
2488
+ return { wrote: false, reason: 'same-provenance', target: target };
2489
+ }
2490
+ const prefix = existing.endsWith('\n') ? '' : '\n';
2491
+ fs.appendFileSync(target, prefix + line + '\n');
2492
+ return { wrote: true, target: target, mode: 'append-provenance' };
2493
+ }
2494
+ standardsDraftWrite(target, '# ' + stem + '\n\nPending draft. Inactive until a human moves this file into `.ai.local/rules/`.\n\n' + line + '\n');
2495
+ return { wrote: true, target: target, mode: 'create' };
2496
+ }
2497
+
2498
+ const conventionsPath = path.join(overlay, 'conventions.md');
2499
+ if (conventionsPath === rulesDir || conventionsPath.startsWith(rulesPrefix)) {
2500
+ return { wrote: false, reason: 'rules' };
2501
+ }
2502
+ let content = null;
2503
+ try {
2504
+ content = fs.readFileSync(conventionsPath, 'utf8');
2505
+ } catch (error) {
2506
+ if (!error || error.code !== 'ENOENT') throw error;
2507
+ }
2508
+ if (content === null) content = '# Living conventions\n';
2509
+ if (content.indexOf(standardsDraftTag(provenance)) !== -1) {
2510
+ return { wrote: false, reason: 'same-provenance', target: conventionsPath };
2511
+ }
2512
+ const before = standardsDraftProtected(content);
2513
+ const next = standardsDraftAppendPending(content, line);
2514
+ if (standardsDraftProtected(next) !== before) {
2515
+ return { wrote: false, reason: 'protected', target: conventionsPath };
2516
+ }
2517
+ standardsDraftWrite(conventionsPath, next);
2518
+ return {
2519
+ wrote: true,
2520
+ target: conventionsPath,
2521
+ mode: standardsDraftAccepted(content, text) ? 'provenance-only' : 'pending',
2522
+ };
2523
+ }
2524
+ // <<<standards-draft-end>>>
2525
+
1456
2526
  let input;
1457
2527
  try {
1458
2528
  input = JSON.parse(process.env.INPUT || '');
@@ -1485,6 +2555,12 @@ if (pipeline && (pipeline.profile === 'light' || pipeline.intent === 'spike')) {
1485
2555
  process.exit(0);
1486
2556
  }
1487
2557
 
2558
+ try {
2559
+ appendOptionalStandardsDraft(process.cwd(), input.standardsDraft);
2560
+ } catch {
2561
+ // A draft failure must not fail the stop, and must not add a WARNING.
2562
+ }
2563
+
1488
2564
  if (!fs.existsSync(path.join(process.cwd(), '.ai.local', 'scripts', 'run.mjs'))) {
1489
2565
  process.stderr.write(
1490
2566
  'WARNING: self-learning loop skipped: .ai.local/scripts/run.mjs is missing (install it with `npx @bonesofspring/ai-rules init <tool> --preset <stack>`)\n',