@bonesofspring/ai-rules 0.2.55 → 0.2.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/README.md +27 -0
  3. package/docs/PRESET-CONTRIBUTION.md +13 -1
  4. package/docs/TEAM-DB.md +82 -13
  5. package/docs/openapi/team-db.v1.json +139 -4
  6. package/package.json +2 -1
  7. package/presets/_shared/ai-local/scripts/rule-improver.mjs +333 -26
  8. package/presets/_shared/ai-local/scripts/run.mjs +21 -6
  9. package/presets/_shared/ai-local/scripts/team-db-api.mjs +71 -4
  10. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +35 -4
  11. package/presets/_shared/ai-local/scripts/team-db-project.mjs +143 -2
  12. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +79 -9
  13. package/presets/_shared/ai-local/scripts/team-db.mjs +50 -6
  14. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +17 -6
  15. package/presets/_shared/core/quality/self-review-and-context-hygiene.md +3 -1
  16. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +20 -15
  17. package/presets/claude/android-kotlin/agents/build-verifier.md +1 -1
  18. package/presets/claude/android-kotlin/agents/code-reviewer.md +1 -1
  19. package/presets/claude/android-kotlin/agents/debugger.md +1 -1
  20. package/presets/claude/android-kotlin/agents/feature-developer.md +1 -1
  21. package/presets/claude/android-kotlin/agents/task-analyst.md +1 -1
  22. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +20 -15
  23. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  24. package/presets/claude/go/agents/build-verifier.md +1 -1
  25. package/presets/claude/go/agents/code-reviewer.md +1 -1
  26. package/presets/claude/go/agents/debugger.md +1 -1
  27. package/presets/claude/go/agents/feature-developer.md +1 -1
  28. package/presets/claude/go/agents/task-analyst.md +1 -1
  29. package/presets/claude/go/hooks/chain-team-phases.sh +20 -15
  30. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  31. package/presets/claude/ios-swift/agents/build-verifier.md +1 -1
  32. package/presets/claude/ios-swift/agents/code-reviewer.md +1 -1
  33. package/presets/claude/ios-swift/agents/debugger.md +1 -1
  34. package/presets/claude/ios-swift/agents/feature-developer.md +1 -1
  35. package/presets/claude/ios-swift/agents/task-analyst.md +1 -1
  36. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +20 -15
  37. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  38. package/presets/claude/java/agents/build-verifier.md +1 -1
  39. package/presets/claude/java/agents/code-reviewer.md +1 -1
  40. package/presets/claude/java/agents/debugger.md +1 -1
  41. package/presets/claude/java/agents/feature-developer.md +1 -1
  42. package/presets/claude/java/agents/task-analyst.md +1 -1
  43. package/presets/claude/java/hooks/chain-team-phases.sh +20 -15
  44. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  45. package/presets/claude/mcp-ts/agents/build-verifier.md +1 -1
  46. package/presets/claude/mcp-ts/agents/feature-developer.md +1 -1
  47. package/presets/claude/mcp-ts/agents/task-analyst.md +1 -1
  48. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +20 -15
  49. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  50. package/presets/claude/mol/agents/build-verifier.md +1 -1
  51. package/presets/claude/mol/agents/code-reviewer.md +1 -1
  52. package/presets/claude/mol/agents/debugger.md +1 -1
  53. package/presets/claude/mol/agents/feature-developer.md +1 -1
  54. package/presets/claude/mol/agents/task-analyst.md +1 -1
  55. package/presets/claude/mol/hooks/chain-team-phases.sh +20 -15
  56. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  57. package/presets/claude/next/agents/build-verifier.md +16 -1
  58. package/presets/claude/next/agents/code-reviewer.md +1 -1
  59. package/presets/claude/next/agents/debugger.md +1 -1
  60. package/presets/claude/next/agents/feature-developer.md +13 -1
  61. package/presets/claude/next/agents/task-analyst.md +1 -1
  62. package/presets/claude/next/agents/task-router.md +10 -0
  63. package/presets/claude/next/hooks/chain-team-phases.sh +20 -15
  64. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  65. package/presets/claude/next/rules/tooling-and-review/code-review-mr.md +2 -1
  66. package/presets/claude/nuxt/agents/build-verifier.md +1 -1
  67. package/presets/claude/nuxt/agents/code-reviewer.md +1 -1
  68. package/presets/claude/nuxt/agents/debugger.md +1 -1
  69. package/presets/claude/nuxt/agents/feature-developer.md +1 -1
  70. package/presets/claude/nuxt/agents/task-analyst.md +1 -1
  71. package/presets/claude/nuxt/hooks/chain-team-phases.sh +20 -15
  72. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  73. package/presets/claude/php-hexagonal/agents/build-verifier.md +1 -1
  74. package/presets/claude/php-hexagonal/agents/code-reviewer.md +1 -1
  75. package/presets/claude/php-hexagonal/agents/debugger.md +1 -1
  76. package/presets/claude/php-hexagonal/agents/feature-developer.md +1 -1
  77. package/presets/claude/php-hexagonal/agents/task-analyst.md +1 -1
  78. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  79. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  80. package/presets/claude/php-laravel/agents/build-verifier.md +1 -1
  81. package/presets/claude/php-laravel/agents/code-reviewer.md +1 -1
  82. package/presets/claude/php-laravel/agents/debugger.md +1 -1
  83. package/presets/claude/php-laravel/agents/feature-developer.md +1 -1
  84. package/presets/claude/php-laravel/agents/task-analyst.md +1 -1
  85. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +20 -15
  86. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  87. package/presets/claude/svelte/agents/build-verifier.md +1 -1
  88. package/presets/claude/svelte/agents/code-reviewer.md +1 -1
  89. package/presets/claude/svelte/agents/debugger.md +1 -1
  90. package/presets/claude/svelte/agents/feature-developer.md +1 -1
  91. package/presets/claude/svelte/agents/task-analyst.md +1 -1
  92. package/presets/claude/svelte/hooks/chain-team-phases.sh +20 -15
  93. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +17 -6
  94. package/presets/cursor/android-kotlin/agents/build-verifier.md +1 -1
  95. package/presets/cursor/android-kotlin/agents/code-reviewer.md +1 -1
  96. package/presets/cursor/android-kotlin/agents/debugger.md +1 -1
  97. package/presets/cursor/android-kotlin/agents/feature-developer.md +1 -1
  98. package/presets/cursor/android-kotlin/agents/task-analyst.md +1 -1
  99. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +20 -15
  100. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
  101. package/presets/cursor/go/agents/build-verifier.md +1 -1
  102. package/presets/cursor/go/agents/code-reviewer.md +1 -1
  103. package/presets/cursor/go/agents/debugger.md +1 -1
  104. package/presets/cursor/go/agents/feature-developer.md +1 -1
  105. package/presets/cursor/go/agents/task-analyst.md +1 -1
  106. package/presets/cursor/go/hooks/chain-team-phases.sh +20 -15
  107. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
  108. package/presets/cursor/ios-swift/agents/build-verifier.md +1 -1
  109. package/presets/cursor/ios-swift/agents/code-reviewer.md +1 -1
  110. package/presets/cursor/ios-swift/agents/debugger.md +1 -1
  111. package/presets/cursor/ios-swift/agents/feature-developer.md +1 -1
  112. package/presets/cursor/ios-swift/agents/task-analyst.md +1 -1
  113. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +20 -15
  114. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
  115. package/presets/cursor/java/agents/build-verifier.md +1 -1
  116. package/presets/cursor/java/agents/code-reviewer.md +1 -1
  117. package/presets/cursor/java/agents/debugger.md +1 -1
  118. package/presets/cursor/java/agents/feature-developer.md +1 -1
  119. package/presets/cursor/java/agents/task-analyst.md +1 -1
  120. package/presets/cursor/java/hooks/chain-team-phases.sh +20 -15
  121. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
  122. package/presets/cursor/mcp-ts/agents/build-verifier.md +1 -1
  123. package/presets/cursor/mcp-ts/agents/feature-developer.md +1 -1
  124. package/presets/cursor/mcp-ts/agents/task-analyst.md +1 -1
  125. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +20 -15
  126. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
  127. package/presets/cursor/mol/agents/build-verifier.md +1 -1
  128. package/presets/cursor/mol/agents/code-reviewer.md +1 -1
  129. package/presets/cursor/mol/agents/debugger.md +1 -1
  130. package/presets/cursor/mol/agents/feature-developer.md +1 -1
  131. package/presets/cursor/mol/agents/task-analyst.md +1 -1
  132. package/presets/cursor/mol/hooks/chain-team-phases.sh +20 -15
  133. package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
  134. package/presets/cursor/next/agents/README.md +2 -0
  135. package/presets/cursor/next/agents/build-verifier.md +16 -1
  136. package/presets/cursor/next/agents/code-reviewer.md +1 -1
  137. package/presets/cursor/next/agents/debugger.md +1 -1
  138. package/presets/cursor/next/agents/feature-developer.md +13 -1
  139. package/presets/cursor/next/agents/task-analyst.md +1 -1
  140. package/presets/cursor/next/agents/task-router.md +10 -0
  141. package/presets/cursor/next/hooks/chain-team-phases.sh +20 -15
  142. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +1 -1
  143. package/presets/cursor/next/rules/code-review-mr.mdc +2 -1
  144. package/presets/cursor/next/team/fixtures/feature-l2-lite.json +27 -0
  145. package/presets/cursor/nuxt/agents/build-verifier.md +1 -1
  146. package/presets/cursor/nuxt/agents/code-reviewer.md +1 -1
  147. package/presets/cursor/nuxt/agents/debugger.md +1 -1
  148. package/presets/cursor/nuxt/agents/feature-developer.md +1 -1
  149. package/presets/cursor/nuxt/agents/task-analyst.md +1 -1
  150. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +20 -15
  151. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
  152. package/presets/cursor/php-hexagonal/agents/build-verifier.md +1 -1
  153. package/presets/cursor/php-hexagonal/agents/code-reviewer.md +1 -1
  154. package/presets/cursor/php-hexagonal/agents/debugger.md +1 -1
  155. package/presets/cursor/php-hexagonal/agents/feature-developer.md +1 -1
  156. package/presets/cursor/php-hexagonal/agents/task-analyst.md +1 -1
  157. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  158. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
  159. package/presets/cursor/php-laravel/agents/build-verifier.md +1 -1
  160. package/presets/cursor/php-laravel/agents/code-reviewer.md +1 -1
  161. package/presets/cursor/php-laravel/agents/debugger.md +1 -1
  162. package/presets/cursor/php-laravel/agents/feature-developer.md +1 -1
  163. package/presets/cursor/php-laravel/agents/task-analyst.md +1 -1
  164. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +20 -15
  165. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
  166. package/presets/cursor/svelte/agents/build-verifier.md +1 -1
  167. package/presets/cursor/svelte/agents/code-reviewer.md +1 -1
  168. package/presets/cursor/svelte/agents/debugger.md +1 -1
  169. package/presets/cursor/svelte/agents/feature-developer.md +1 -1
  170. package/presets/cursor/svelte/agents/task-analyst.md +1 -1
  171. package/presets/cursor/svelte/hooks/chain-team-phases.sh +20 -15
  172. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
  173. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  174. package/presets/mavis/android-kotlin/agents/build-verifier.md +1 -1
  175. package/presets/mavis/android-kotlin/agents/code-reviewer.md +1 -1
  176. package/presets/mavis/android-kotlin/agents/debugger.md +1 -1
  177. package/presets/mavis/android-kotlin/agents/feature-developer.md +1 -1
  178. package/presets/mavis/android-kotlin/agents/task-analyst.md +1 -1
  179. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +20 -15
  180. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +17 -6
  181. package/presets/mavis/go/adapter-map.json +1 -1
  182. package/presets/mavis/go/agents/build-verifier.md +1 -1
  183. package/presets/mavis/go/agents/code-reviewer.md +1 -1
  184. package/presets/mavis/go/agents/debugger.md +1 -1
  185. package/presets/mavis/go/agents/feature-developer.md +1 -1
  186. package/presets/mavis/go/agents/task-analyst.md +1 -1
  187. package/presets/mavis/go/hooks/chain-team-phases.sh +20 -15
  188. package/presets/mavis/go/rules/agent-team-orchestrator.md +17 -6
  189. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  190. package/presets/mavis/ios-swift/agents/build-verifier.md +1 -1
  191. package/presets/mavis/ios-swift/agents/code-reviewer.md +1 -1
  192. package/presets/mavis/ios-swift/agents/debugger.md +1 -1
  193. package/presets/mavis/ios-swift/agents/feature-developer.md +1 -1
  194. package/presets/mavis/ios-swift/agents/task-analyst.md +1 -1
  195. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +20 -15
  196. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +17 -6
  197. package/presets/mavis/java/adapter-map.json +1 -1
  198. package/presets/mavis/java/agents/build-verifier.md +1 -1
  199. package/presets/mavis/java/agents/code-reviewer.md +1 -1
  200. package/presets/mavis/java/agents/debugger.md +1 -1
  201. package/presets/mavis/java/agents/feature-developer.md +1 -1
  202. package/presets/mavis/java/agents/task-analyst.md +1 -1
  203. package/presets/mavis/java/hooks/chain-team-phases.sh +20 -15
  204. package/presets/mavis/java/rules/agent-team-orchestrator.md +17 -6
  205. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  206. package/presets/mavis/mcp-ts/agents/build-verifier.md +1 -1
  207. package/presets/mavis/mcp-ts/agents/feature-developer.md +1 -1
  208. package/presets/mavis/mcp-ts/agents/task-analyst.md +1 -1
  209. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +20 -15
  210. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +17 -6
  211. package/presets/mavis/mol/adapter-map.json +1 -1
  212. package/presets/mavis/mol/agents/build-verifier.md +1 -1
  213. package/presets/mavis/mol/agents/code-reviewer.md +1 -1
  214. package/presets/mavis/mol/agents/debugger.md +1 -1
  215. package/presets/mavis/mol/agents/feature-developer.md +1 -1
  216. package/presets/mavis/mol/agents/task-analyst.md +1 -1
  217. package/presets/mavis/mol/hooks/chain-team-phases.sh +20 -15
  218. package/presets/mavis/mol/rules/agent-team-orchestrator.md +17 -6
  219. package/presets/mavis/next/adapter-map.json +9 -1
  220. package/presets/mavis/next/agents/build-verifier.md +16 -1
  221. package/presets/mavis/next/agents/code-reviewer.md +1 -1
  222. package/presets/mavis/next/agents/debugger.md +1 -1
  223. package/presets/mavis/next/agents/feature-developer.md +13 -1
  224. package/presets/mavis/next/agents/task-analyst.md +1 -1
  225. package/presets/mavis/next/agents/task-router.md +10 -0
  226. package/presets/mavis/next/hooks/chain-team-phases.sh +20 -15
  227. package/presets/mavis/next/rules/agent-team-orchestrator.md +17 -6
  228. package/presets/mavis/next/rules/code-review-mr.md +2 -1
  229. package/presets/mavis/next/team/fixtures/feature-l2-lite.json +27 -0
  230. package/presets/mavis/nuxt/adapter-map.json +1 -1
  231. package/presets/mavis/nuxt/agents/build-verifier.md +1 -1
  232. package/presets/mavis/nuxt/agents/code-reviewer.md +1 -1
  233. package/presets/mavis/nuxt/agents/debugger.md +1 -1
  234. package/presets/mavis/nuxt/agents/feature-developer.md +1 -1
  235. package/presets/mavis/nuxt/agents/task-analyst.md +1 -1
  236. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +20 -15
  237. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +17 -6
  238. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  239. package/presets/mavis/php-hexagonal/agents/build-verifier.md +1 -1
  240. package/presets/mavis/php-hexagonal/agents/code-reviewer.md +1 -1
  241. package/presets/mavis/php-hexagonal/agents/debugger.md +1 -1
  242. package/presets/mavis/php-hexagonal/agents/feature-developer.md +1 -1
  243. package/presets/mavis/php-hexagonal/agents/task-analyst.md +1 -1
  244. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  245. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +17 -6
  246. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  247. package/presets/mavis/php-laravel/agents/build-verifier.md +1 -1
  248. package/presets/mavis/php-laravel/agents/code-reviewer.md +1 -1
  249. package/presets/mavis/php-laravel/agents/debugger.md +1 -1
  250. package/presets/mavis/php-laravel/agents/feature-developer.md +1 -1
  251. package/presets/mavis/php-laravel/agents/task-analyst.md +1 -1
  252. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +20 -15
  253. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +17 -6
  254. package/presets/mavis/svelte/adapter-map.json +1 -1
  255. package/presets/mavis/svelte/agents/build-verifier.md +1 -1
  256. package/presets/mavis/svelte/agents/code-reviewer.md +1 -1
  257. package/presets/mavis/svelte/agents/debugger.md +1 -1
  258. package/presets/mavis/svelte/agents/feature-developer.md +1 -1
  259. package/presets/mavis/svelte/agents/task-analyst.md +1 -1
  260. package/presets/mavis/svelte/hooks/chain-team-phases.sh +20 -15
  261. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +17 -6
  262. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  263. package/presets/opencode/android-kotlin/agents/build-verifier.md +1 -1
  264. package/presets/opencode/android-kotlin/agents/code-reviewer.md +1 -1
  265. package/presets/opencode/android-kotlin/agents/debugger.md +1 -1
  266. package/presets/opencode/android-kotlin/agents/feature-developer.md +1 -1
  267. package/presets/opencode/android-kotlin/agents/task-analyst.md +1 -1
  268. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +20 -15
  269. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +17 -6
  270. package/presets/opencode/go/adapter-map.json +1 -1
  271. package/presets/opencode/go/agents/build-verifier.md +1 -1
  272. package/presets/opencode/go/agents/code-reviewer.md +1 -1
  273. package/presets/opencode/go/agents/debugger.md +1 -1
  274. package/presets/opencode/go/agents/feature-developer.md +1 -1
  275. package/presets/opencode/go/agents/task-analyst.md +1 -1
  276. package/presets/opencode/go/hooks/chain-team-phases.sh +20 -15
  277. package/presets/opencode/go/rules/agent-team-orchestrator.md +17 -6
  278. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  279. package/presets/opencode/ios-swift/agents/build-verifier.md +1 -1
  280. package/presets/opencode/ios-swift/agents/code-reviewer.md +1 -1
  281. package/presets/opencode/ios-swift/agents/debugger.md +1 -1
  282. package/presets/opencode/ios-swift/agents/feature-developer.md +1 -1
  283. package/presets/opencode/ios-swift/agents/task-analyst.md +1 -1
  284. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +20 -15
  285. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +17 -6
  286. package/presets/opencode/java/adapter-map.json +1 -1
  287. package/presets/opencode/java/agents/build-verifier.md +1 -1
  288. package/presets/opencode/java/agents/code-reviewer.md +1 -1
  289. package/presets/opencode/java/agents/debugger.md +1 -1
  290. package/presets/opencode/java/agents/feature-developer.md +1 -1
  291. package/presets/opencode/java/agents/task-analyst.md +1 -1
  292. package/presets/opencode/java/hooks/chain-team-phases.sh +20 -15
  293. package/presets/opencode/java/rules/agent-team-orchestrator.md +17 -6
  294. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  295. package/presets/opencode/mcp-ts/agents/build-verifier.md +1 -1
  296. package/presets/opencode/mcp-ts/agents/feature-developer.md +1 -1
  297. package/presets/opencode/mcp-ts/agents/task-analyst.md +1 -1
  298. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +20 -15
  299. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +17 -6
  300. package/presets/opencode/mol/adapter-map.json +1 -1
  301. package/presets/opencode/mol/agents/build-verifier.md +1 -1
  302. package/presets/opencode/mol/agents/code-reviewer.md +1 -1
  303. package/presets/opencode/mol/agents/debugger.md +1 -1
  304. package/presets/opencode/mol/agents/feature-developer.md +1 -1
  305. package/presets/opencode/mol/agents/task-analyst.md +1 -1
  306. package/presets/opencode/mol/hooks/chain-team-phases.sh +20 -15
  307. package/presets/opencode/mol/rules/agent-team-orchestrator.md +17 -6
  308. package/presets/opencode/next/adapter-map.json +9 -1
  309. package/presets/opencode/next/agents/build-verifier.md +16 -1
  310. package/presets/opencode/next/agents/code-reviewer.md +1 -1
  311. package/presets/opencode/next/agents/debugger.md +1 -1
  312. package/presets/opencode/next/agents/feature-developer.md +13 -1
  313. package/presets/opencode/next/agents/task-analyst.md +1 -1
  314. package/presets/opencode/next/agents/task-router.md +10 -0
  315. package/presets/opencode/next/hooks/chain-team-phases.sh +20 -15
  316. package/presets/opencode/next/rules/agent-team-orchestrator.md +17 -6
  317. package/presets/opencode/next/rules/code-review-mr.md +2 -1
  318. package/presets/opencode/next/team/fixtures/feature-l2-lite.json +27 -0
  319. package/presets/opencode/nuxt/adapter-map.json +1 -1
  320. package/presets/opencode/nuxt/agents/build-verifier.md +1 -1
  321. package/presets/opencode/nuxt/agents/code-reviewer.md +1 -1
  322. package/presets/opencode/nuxt/agents/debugger.md +1 -1
  323. package/presets/opencode/nuxt/agents/feature-developer.md +1 -1
  324. package/presets/opencode/nuxt/agents/task-analyst.md +1 -1
  325. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +20 -15
  326. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +17 -6
  327. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  328. package/presets/opencode/php-hexagonal/agents/build-verifier.md +1 -1
  329. package/presets/opencode/php-hexagonal/agents/code-reviewer.md +1 -1
  330. package/presets/opencode/php-hexagonal/agents/debugger.md +1 -1
  331. package/presets/opencode/php-hexagonal/agents/feature-developer.md +1 -1
  332. package/presets/opencode/php-hexagonal/agents/task-analyst.md +1 -1
  333. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  334. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +17 -6
  335. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  336. package/presets/opencode/php-laravel/agents/build-verifier.md +1 -1
  337. package/presets/opencode/php-laravel/agents/code-reviewer.md +1 -1
  338. package/presets/opencode/php-laravel/agents/debugger.md +1 -1
  339. package/presets/opencode/php-laravel/agents/feature-developer.md +1 -1
  340. package/presets/opencode/php-laravel/agents/task-analyst.md +1 -1
  341. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +20 -15
  342. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +17 -6
  343. package/presets/opencode/svelte/adapter-map.json +1 -1
  344. package/presets/opencode/svelte/agents/build-verifier.md +1 -1
  345. package/presets/opencode/svelte/agents/code-reviewer.md +1 -1
  346. package/presets/opencode/svelte/agents/debugger.md +1 -1
  347. package/presets/opencode/svelte/agents/feature-developer.md +1 -1
  348. package/presets/opencode/svelte/agents/task-analyst.md +1 -1
  349. package/presets/opencode/svelte/hooks/chain-team-phases.sh +20 -15
  350. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +17 -6
  351. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  352. package/presets/zcode/android-kotlin/agents/build-verifier.md +1 -1
  353. package/presets/zcode/android-kotlin/agents/code-reviewer.md +1 -1
  354. package/presets/zcode/android-kotlin/agents/debugger.md +1 -1
  355. package/presets/zcode/android-kotlin/agents/feature-developer.md +1 -1
  356. package/presets/zcode/android-kotlin/agents/task-analyst.md +1 -1
  357. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +20 -15
  358. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +17 -6
  359. package/presets/zcode/go/adapter-map.json +1 -1
  360. package/presets/zcode/go/agents/build-verifier.md +1 -1
  361. package/presets/zcode/go/agents/code-reviewer.md +1 -1
  362. package/presets/zcode/go/agents/debugger.md +1 -1
  363. package/presets/zcode/go/agents/feature-developer.md +1 -1
  364. package/presets/zcode/go/agents/task-analyst.md +1 -1
  365. package/presets/zcode/go/hooks/chain-team-phases.sh +20 -15
  366. package/presets/zcode/go/rules/agent-team-orchestrator.md +17 -6
  367. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  368. package/presets/zcode/ios-swift/agents/build-verifier.md +1 -1
  369. package/presets/zcode/ios-swift/agents/code-reviewer.md +1 -1
  370. package/presets/zcode/ios-swift/agents/debugger.md +1 -1
  371. package/presets/zcode/ios-swift/agents/feature-developer.md +1 -1
  372. package/presets/zcode/ios-swift/agents/task-analyst.md +1 -1
  373. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +20 -15
  374. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +17 -6
  375. package/presets/zcode/java/adapter-map.json +1 -1
  376. package/presets/zcode/java/agents/build-verifier.md +1 -1
  377. package/presets/zcode/java/agents/code-reviewer.md +1 -1
  378. package/presets/zcode/java/agents/debugger.md +1 -1
  379. package/presets/zcode/java/agents/feature-developer.md +1 -1
  380. package/presets/zcode/java/agents/task-analyst.md +1 -1
  381. package/presets/zcode/java/hooks/chain-team-phases.sh +20 -15
  382. package/presets/zcode/java/rules/agent-team-orchestrator.md +17 -6
  383. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  384. package/presets/zcode/mcp-ts/agents/build-verifier.md +1 -1
  385. package/presets/zcode/mcp-ts/agents/feature-developer.md +1 -1
  386. package/presets/zcode/mcp-ts/agents/task-analyst.md +1 -1
  387. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +20 -15
  388. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +17 -6
  389. package/presets/zcode/mol/adapter-map.json +1 -1
  390. package/presets/zcode/mol/agents/build-verifier.md +1 -1
  391. package/presets/zcode/mol/agents/code-reviewer.md +1 -1
  392. package/presets/zcode/mol/agents/debugger.md +1 -1
  393. package/presets/zcode/mol/agents/feature-developer.md +1 -1
  394. package/presets/zcode/mol/agents/task-analyst.md +1 -1
  395. package/presets/zcode/mol/hooks/chain-team-phases.sh +20 -15
  396. package/presets/zcode/mol/rules/agent-team-orchestrator.md +17 -6
  397. package/presets/zcode/next/adapter-map.json +9 -1
  398. package/presets/zcode/next/agents/build-verifier.md +16 -1
  399. package/presets/zcode/next/agents/code-reviewer.md +1 -1
  400. package/presets/zcode/next/agents/debugger.md +1 -1
  401. package/presets/zcode/next/agents/feature-developer.md +13 -1
  402. package/presets/zcode/next/agents/task-analyst.md +1 -1
  403. package/presets/zcode/next/agents/task-router.md +10 -0
  404. package/presets/zcode/next/hooks/chain-team-phases.sh +20 -15
  405. package/presets/zcode/next/rules/agent-team-orchestrator.md +17 -6
  406. package/presets/zcode/next/rules/code-review-mr.md +2 -1
  407. package/presets/zcode/next/team/fixtures/feature-l2-lite.json +27 -0
  408. package/presets/zcode/nuxt/adapter-map.json +1 -1
  409. package/presets/zcode/nuxt/agents/build-verifier.md +1 -1
  410. package/presets/zcode/nuxt/agents/code-reviewer.md +1 -1
  411. package/presets/zcode/nuxt/agents/debugger.md +1 -1
  412. package/presets/zcode/nuxt/agents/feature-developer.md +1 -1
  413. package/presets/zcode/nuxt/agents/task-analyst.md +1 -1
  414. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +20 -15
  415. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +17 -6
  416. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  417. package/presets/zcode/php-hexagonal/agents/build-verifier.md +1 -1
  418. package/presets/zcode/php-hexagonal/agents/code-reviewer.md +1 -1
  419. package/presets/zcode/php-hexagonal/agents/debugger.md +1 -1
  420. package/presets/zcode/php-hexagonal/agents/feature-developer.md +1 -1
  421. package/presets/zcode/php-hexagonal/agents/task-analyst.md +1 -1
  422. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +20 -15
  423. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +17 -6
  424. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  425. package/presets/zcode/php-laravel/agents/build-verifier.md +1 -1
  426. package/presets/zcode/php-laravel/agents/code-reviewer.md +1 -1
  427. package/presets/zcode/php-laravel/agents/debugger.md +1 -1
  428. package/presets/zcode/php-laravel/agents/feature-developer.md +1 -1
  429. package/presets/zcode/php-laravel/agents/task-analyst.md +1 -1
  430. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +20 -15
  431. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +17 -6
  432. package/presets/zcode/svelte/adapter-map.json +1 -1
  433. package/presets/zcode/svelte/agents/build-verifier.md +1 -1
  434. package/presets/zcode/svelte/agents/code-reviewer.md +1 -1
  435. package/presets/zcode/svelte/agents/debugger.md +1 -1
  436. package/presets/zcode/svelte/agents/feature-developer.md +1 -1
  437. package/presets/zcode/svelte/agents/task-analyst.md +1 -1
  438. package/presets/zcode/svelte/hooks/chain-team-phases.sh +20 -15
  439. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +17 -6
@@ -1,5 +1,6 @@
1
1
  /**
2
- * The OpenAPI 3.1 document for the read-only team-db API.
2
+ * The OpenAPI 3.1 document for the team-db API: reads plus two bounded
3
+ * mutations (the idempotent rescan and the confirmed task delete).
3
4
  *
4
5
  * This module is the single source of the checked-in
5
6
  * `packages/ai-rules/docs/openapi/team-db.v1.json`: `check-team-db-contract.mjs
@@ -61,6 +62,7 @@ export const ERROR_CODES = [
61
62
  'E_DOC_NOT_FOUND',
62
63
  'E_DOC_BINARY',
63
64
  'E_DOC_CONTENT_OMITTED',
65
+ 'E_ACTIVE_TASK',
64
66
  'E_RANGE',
65
67
  'E_DISABLED',
66
68
  'E_DB_MISSING',
@@ -225,6 +227,12 @@ const schemas = {
225
227
  },
226
228
  ['items', 'total', 'limit', 'offset', 'nextOffset'],
227
229
  ),
230
+ TaskDeleteResult: object(
231
+ {
232
+ slug: { type: 'string', pattern: SLUG_PATTERN },
233
+ },
234
+ ['slug'],
235
+ ),
228
236
  TaskDetail: object(
229
237
  {
230
238
  task: ref('TaskSummary'),
@@ -616,8 +624,12 @@ const schemas = {
616
624
  ['total', 'absent'],
617
625
  ),
618
626
  projectedAt: nullable('string'),
627
+ capabilities: {
628
+ type: 'array',
629
+ items: { type: 'string', enum: ['sync', 'delete'] },
630
+ },
619
631
  },
620
- ['status', 'db', 'tasks', 'projectedAt'],
632
+ ['status', 'db', 'tasks', 'projectedAt', 'capabilities'],
621
633
  ),
622
634
  Migration: object(
623
635
  {
@@ -813,6 +825,7 @@ const EXAMPLES = {
813
825
  ErrorEnvelope: [{ error: { code: 'E_VALIDATION', message: 'limit must be an integer between 1 and 200', details: { parameter: 'limit' } } }],
814
826
  TaskSummary: [taskSummaryExample],
815
827
  TaskList: [{ items: [taskSummaryExample], total: 90, limit: 50, offset: 0, nextOffset: 50 }],
828
+ TaskDeleteResult: [{ slug: 'agent-team-sqlite-dashboard' }],
816
829
  TaskDetail: [detailExample],
817
830
  Pipeline: [
818
831
  {
@@ -925,6 +938,7 @@ const EXAMPLES = {
925
938
  db: { file: 'team.db', present: true, schemaVersion: 1, fingerprintOk: true, search: 'fts5' },
926
939
  tasks: { total: 90, absent: 0 },
927
940
  projectedAt: '2026-11-06T08:00:04.000Z',
941
+ capabilities: ['sync', 'delete'],
928
942
  },
929
943
  ],
930
944
  Meta: [
@@ -1106,9 +1120,9 @@ export const OPENAPI_DOCUMENT = {
1106
1120
  info: {
1107
1121
  title: 'Agent team SQLite projection API',
1108
1122
  summary:
1109
- 'Read-only projection of `.ai.local/team`. Task files are authoritative; the database is a rebuildable copy. The only mutation is an idempotent rescan.',
1123
+ 'Projection of `.ai.local/team`. Task files are authoritative; the database is a rebuildable copy. Two mutations exist — the idempotent rescan and the confirmed task delete — and both run as bounded child processes.',
1110
1124
  description:
1111
- 'Loopback-only operator API. No authentication by design, no CORS, no outbound request. Errors use one `{error:{code,message,details?}}` envelope. Every non-GET/HEAD request to a read-only path returns 405 `E_METHOD_NOT_ALLOWED` with `Allow: GET, HEAD`; `GET` and `HEAD` on `/api/v1/sync` return 405 with `Allow: POST`.',
1125
+ 'Loopback-only operator API. No authentication by design, no CORS, no outbound request. Errors use one `{error:{code,message,details?}}` envelope. Every non-GET/HEAD request to a read-only path returns 405 `E_METHOD_NOT_ALLOWED` with `Allow: GET, HEAD`; `GET` and `HEAD` on `/api/v1/sync` return 405 with `Allow: POST`; any other method on `/api/v1/tasks/{slug}` returns 405 with `Allow: GET, HEAD, DELETE`.',
1112
1126
  version: API_VERSION,
1113
1127
  'x-api-major': API_MAJOR,
1114
1128
  },
@@ -1210,6 +1224,23 @@ export const OPENAPI_DOCUMENT = {
1210
1224
  },
1211
1225
  '/api/v1/tasks/{slug}': {
1212
1226
  get: taskScopedOperation(['tasks'], 'One task with routing and counts', 'getTask', 'TaskDetail'),
1227
+ delete: operation({
1228
+ tags: ['tasks'],
1229
+ summary: 'Delete one task: the task folder first, then its projection rows',
1230
+ description:
1231
+ 'Confirmed, destructive and irreversible. The task folder `.ai.local/team/tasks/{slug}` is removed before the database rows, so a crash between the two legs converges toward deleted on the next rescan and never resurrects content. The row delete is one transaction: the task row plus every child row by cascade, plus the task\'s search rows. The slug in `active-task.json` is refused with 409 `E_ACTIVE_TASK`. An unknown slug answers 404 `E_NOT_FOUND` and touches nothing. The request body is ignored and no query parameters are declared. Executed as a bounded child process; `AI_RULES_TEAM_DB_DISABLE=1` answers 503 `E_DISABLED` before anything runs.',
1232
+ operationId: 'deleteTask',
1233
+ parameters: [slugParameter],
1234
+ responses: {
1235
+ 200: jsonResponse('TaskDeleteResult', 'The deleted slug'),
1236
+ 400: errorResponse('Malformed request: an invalid slug'),
1237
+ 403: errorResponse('A non-loopback Host or Origin was rejected before routing'),
1238
+ 404: errorResponse('The task does not exist in the projection or on disk'),
1239
+ 405: methodNotAllowedResponse,
1240
+ 409: errorResponse('The slug is the active task; the delete is refused with `details.activeSlug` naming it'),
1241
+ 503: errorResponse('The projection is disabled, the database is missing, unusable, busy, or the child exceeded its time bound'),
1242
+ },
1243
+ }),
1213
1244
  },
1214
1245
  '/api/v1/tasks/{slug}/pipeline': {
1215
1246
  get: taskScopedOperation(['pipeline'], 'Pipeline steps with derived state', 'getTaskPipeline', 'Pipeline'),
@@ -1,11 +1,14 @@
1
1
  /**
2
- * Parsers and projector for the `.ai.local/team` SQLite projection.
2
+ * Parsers, the idempotent projector, confirmed task deletion, retention and
3
+ * search for the `.ai.local/team` SQLite projection.
3
4
  *
4
5
  * Files are authoritative. One task directory is one transaction: parse the
5
6
  * known artifacts, upsert every normalized row by its natural key, store every
6
7
  * regular file as a raw document, and rebuild the task's search rows. A
7
8
  * malformed input is recorded and the rest of the tree still projects; a
8
- * database-level failure aborts the run.
9
+ * database-level failure aborts the run. Deleting a task removes the folder
10
+ * before the rows, so a crash between the legs converges toward deleted on
11
+ * the next rescan and never resurrects content.
9
12
  *
10
13
  * Nothing here writes a lifecycle file. `status.json` and `metrics.json` are
11
14
  * read-only inputs.
@@ -16,12 +19,14 @@ import fs from 'node:fs';
16
19
  import path from 'node:path';
17
20
 
18
21
  import {
22
+ DEFAULT_TEAM_ROOT,
19
23
  SEARCH_MODE_FTS5,
20
24
  TeamDbError,
21
25
  chmodDatabaseFiles,
22
26
  integrityCheck,
23
27
  isBusyError,
24
28
  isCorruptError,
29
+ isKillSwitchSet,
25
30
  openTeamDb,
26
31
  readSearchMode,
27
32
  teamDbFail,
@@ -1581,6 +1586,142 @@ export function syncProjection(options = {}) {
1581
1586
  }
1582
1587
  }
1583
1588
 
1589
+ /**
1590
+ * Delete one task: the folder first (files are authoritative), then the rows.
1591
+ *
1592
+ * The two legs converge prior partial states: a folder without rows loses
1593
+ * only the folder; rows without a folder lose only the rows. The row leg is
1594
+ * one transaction — the task row plus every child row by foreign-key cascade,
1595
+ * plus the task's standalone search rows. The active-task guard and the slug
1596
+ * confinement run before any leg, and a symlink at `tasks/<slug>` is refused,
1597
+ * never followed or removed.
1598
+ *
1599
+ * Returns the one-line result the CLI prints and the API child parses:
1600
+ * `{ ok: true, slug, folderRemoved, rowsDeleted }`. Throws `TeamDbError`:
1601
+ * `E_DISABLED` (kill switch, exit 1), `E_USAGE` (bad slug, exit 3),
1602
+ * `E_NOT_FOUND` (nothing to delete, exit 1), `E_ACTIVE_TASK` (the guard,
1603
+ * exit 1), `E_INTERNAL` (the folder leg failed, exit 1), and the
1604
+ * database-level `E_DB_BUSY` (exit 4) / `E_DB_CORRUPT` (exit 2).
1605
+ */
1606
+ export function deleteTaskProjection(options = {}) {
1607
+ const slug = typeof options.slug === 'string' ? options.slug : '';
1608
+ if (isKillSwitchSet(options.env ?? process.env)) {
1609
+ teamDbFail('E_DISABLED', 'disabled by AI_RULES_TEAM_DB_DISABLE', 1);
1610
+ }
1611
+ if (!SLUG_RE.test(slug)) {
1612
+ teamDbFail('E_USAGE', `delete needs --slug matching ${SLUG_RE.source}`, 3);
1613
+ }
1614
+ const teamRoot = path.resolve(options.teamRoot || process.env.AI_RULES_TEAM_DB_ROOT || DEFAULT_TEAM_ROOT);
1615
+ const tasksRoot = path.join(teamRoot, 'tasks');
1616
+ const taskDir = path.join(tasksRoot, slug);
1617
+
1618
+ // The guard reads the team root, not the database, and runs before any leg.
1619
+ // The parse stays inside the try; the refusal lives outside it, so a named
1620
+ // guard failure is never mistaken for an unreadable guard file. An
1621
+ // unreadable or missing guard file does not block the delete.
1622
+ let guardSlug = null;
1623
+ try {
1624
+ const guard = JSON.parse(fs.readFileSync(path.join(teamRoot, 'active-task.json'), 'utf8'));
1625
+ guardSlug = guard && typeof guard.slug === 'string' ? guard.slug : null;
1626
+ } catch {
1627
+ guardSlug = null;
1628
+ }
1629
+ if (guardSlug === slug) {
1630
+ teamDbFail(
1631
+ 'E_ACTIVE_TASK',
1632
+ `${slug} is the active task; a pipeline may be writing into it, and deletion is blocked while it is active`,
1633
+ 1,
1634
+ );
1635
+ }
1636
+
1637
+ // Presence is a real directory on an lstat: a symlink (or any other
1638
+ // non-directory) is refused with the unknown-slug outcome and is never
1639
+ // followed or removed.
1640
+ let dirState = 'absent';
1641
+ try {
1642
+ dirState = fs.lstatSync(taskDir).isDirectory() ? 'present' : 'not-a-directory';
1643
+ } catch {
1644
+ dirState = 'absent';
1645
+ }
1646
+ if (dirState === 'not-a-directory') {
1647
+ teamDbFail('E_NOT_FOUND', `no task "${slug}" in the team root; its path is not a task directory, and nothing was deleted`, 1);
1648
+ }
1649
+
1650
+ let handle = null;
1651
+ try {
1652
+ handle = openTeamDb({ teamRoot, dbPath: options.dbPath, env: options.env });
1653
+ } catch (error) {
1654
+ if (isBusyError(error)) teamDbFail('E_DB_BUSY', `${slug}: ${error.message}`, 4);
1655
+ if (isCorruptError(error)) teamDbFail('E_DB_CORRUPT', `${slug}: ${error.message}`, 2);
1656
+ throw error;
1657
+ }
1658
+ const { db } = handle;
1659
+
1660
+ try {
1661
+ let rowExists = false;
1662
+ try {
1663
+ rowExists = db.prepare('SELECT slug FROM tasks WHERE slug = ?').get(slug) !== undefined;
1664
+ } catch (error) {
1665
+ if (isBusyError(error)) teamDbFail('E_DB_BUSY', `${slug}: ${error.message}`, 4);
1666
+ if (isCorruptError(error)) teamDbFail('E_DB_CORRUPT', `${slug}: ${error.message}`, 2);
1667
+ throw error;
1668
+ }
1669
+
1670
+ if (!rowExists && dirState !== 'present') {
1671
+ teamDbFail('E_NOT_FOUND', `no task "${slug}" in the projection or the team root`, 1);
1672
+ }
1673
+
1674
+ if (dirState === 'present') {
1675
+ // Belt and braces: the slug pattern admits no separator or dot segment,
1676
+ // so the task directory is tasksRoot/<slug> by construction; the
1677
+ // realpath prefix check also closes an ancestor-symlink escape.
1678
+ const realTaskDir = fs.realpathSync(taskDir);
1679
+ const realTasksRoot = fs.realpathSync(tasksRoot);
1680
+ if (!realTaskDir.startsWith(realTasksRoot + path.sep)) {
1681
+ teamDbFail('E_INTERNAL', `${slug}: the task folder resolves outside the tasks root; nothing was deleted`, 1);
1682
+ }
1683
+ // Leg A — files first. The next rescan finds no directory and
1684
+ // reconciles the rows toward deleted; content can never resurrect.
1685
+ try {
1686
+ fs.rmSync(taskDir, { recursive: true, force: true });
1687
+ } catch (error) {
1688
+ teamDbFail('E_INTERNAL', `${slug}: the task folder could not be deleted (${error.message}); the row leg did not run`, 1);
1689
+ }
1690
+ }
1691
+
1692
+ // Leg B — one transaction. `DELETE FROM tasks` cascades every child table
1693
+ // under `PRAGMA foreign_keys=ON`; `search_fts` is a standalone FTS table
1694
+ // with no foreign key, so its rows are deleted explicitly.
1695
+ let rowsDeleted = 0;
1696
+ if (rowExists) {
1697
+ try {
1698
+ db.exec('BEGIN IMMEDIATE');
1699
+ if (hasSearchTable(db)) db.prepare('DELETE FROM search_fts WHERE task_slug = ?').run(slug);
1700
+ rowsDeleted = db.prepare('DELETE FROM tasks WHERE slug = ?').run(slug).changes;
1701
+ db.exec('COMMIT');
1702
+ } catch (error) {
1703
+ try {
1704
+ db.exec('ROLLBACK');
1705
+ } catch {
1706
+ /* the failed transaction is already unwound */
1707
+ }
1708
+ if (isBusyError(error)) teamDbFail('E_DB_BUSY', `${slug}: ${error.message}`, 4);
1709
+ if (isCorruptError(error)) teamDbFail('E_DB_CORRUPT', `${slug}: ${error.message}`, 2);
1710
+ throw error;
1711
+ }
1712
+ }
1713
+
1714
+ chmodDatabaseFiles(handle.dbPath);
1715
+ return { ok: true, slug, folderRemoved: dirState === 'present', rowsDeleted };
1716
+ } finally {
1717
+ try {
1718
+ db.close();
1719
+ } catch {
1720
+ /* a close error after a settled leg is not a delete failure */
1721
+ }
1722
+ }
1723
+ }
1724
+
1584
1725
  /** Human summary for a `sync` run. */
1585
1726
  export function describeSyncResult(result) {
1586
1727
  return (
@@ -33,6 +33,44 @@ export const INDEX_UNAVAILABLE_LINE = `team-db: node:sqlite unavailable (require
33
33
 
34
34
  export const DEFAULT_TEAM_ROOT = path.join(process.cwd(), '.ai.local', 'team');
35
35
 
36
+ /**
37
+ * The released FTS layouts, oldest-first. The current shape is last.
38
+ *
39
+ * A shape is recorded in `schema_meta` under `search_fts_shape` when the search
40
+ * table is created. The registry enumerates **released** shapes only — a shape
41
+ * that was never released would make the registry lie — so the next shape is
42
+ * appended, never edited in place. The registry is not a migration chain: it
43
+ * records which layout is installed, and a drifted layout is reported, never
44
+ * rebuilt.
45
+ */
46
+ export const FTS_SHAPES = [
47
+ {
48
+ id: 'fts5-v1',
49
+ columns: ['task_slug UNINDEXED', 'doc_path UNINDEXED', 'kind UNINDEXED', 'body'],
50
+ tokenizer: 'unicode61 remove_diacritics 2',
51
+ },
52
+ ];
53
+ export const CURRENT_FTS_SHAPE = FTS_SHAPES[FTS_SHAPES.length - 1];
54
+ export const FTS_SHAPE_META_KEY = 'search_fts_shape';
55
+
56
+ /** The five drift states of an installed search table. */
57
+ export const FTS_DRIFT_STATES = ['absent', 'current', 'unrecorded', 'superseded', 'unknown'];
58
+
59
+ /** The installed table's column names, in declaration order. */
60
+ export const ftsColumnNames = (db) =>
61
+ db
62
+ .prepare(`PRAGMA table_info(${SEARCH_TABLE})`)
63
+ .all()
64
+ .map((row) => String(row.name));
65
+
66
+ /** The comparable signature of a shape: its column names, `UNINDEXED` dropped. */
67
+ export const ftsShapeSignature = (shape) =>
68
+ shape.columns.map((column) => column.replace(/\s+UNINDEXED\b/i, '').trim()).join(',');
69
+
70
+ /** The DDL of a shape. */
71
+ export const ftsShapeSql = (shape) =>
72
+ `CREATE VIRTUAL TABLE IF NOT EXISTS ${SEARCH_TABLE} USING fts5(\n ${shape.columns.join(',\n ')},\n tokenize = '${shape.tokenizer}'\n )`;
73
+
36
74
  const SQL = String.raw;
37
75
 
38
76
  export const BASE_SQL = SQL`
@@ -501,17 +539,14 @@ export function ensureSearchIndex(db, options = {}) {
501
539
  writeSchemaMeta(db, 'search', SEARCH_MODE_LIKE);
502
540
  return SEARCH_MODE_LIKE;
503
541
  }
542
+ const existed = tableExists(db, SEARCH_TABLE);
504
543
  try {
505
- db.exec(
506
- `CREATE VIRTUAL TABLE IF NOT EXISTS ${SEARCH_TABLE} USING fts5(
507
- task_slug UNINDEXED,
508
- doc_path UNINDEXED,
509
- kind UNINDEXED,
510
- body,
511
- tokenize = 'unicode61 remove_diacritics 2'
512
- )`,
513
- );
544
+ db.exec(ftsShapeSql(CURRENT_FTS_SHAPE));
514
545
  writeSchemaMeta(db, 'search', SEARCH_MODE_FTS5);
546
+ // The shape token is written only when the table is created: a database
547
+ // that predates the registry keeps an absent token, so its state stays
548
+ // `unrecorded` and keeps being reported.
549
+ if (!existed) writeSchemaMeta(db, FTS_SHAPE_META_KEY, CURRENT_FTS_SHAPE.id);
515
550
  return SEARCH_MODE_FTS5;
516
551
  } catch {
517
552
  writeSchemaMeta(db, 'search', SEARCH_MODE_LIKE);
@@ -519,6 +554,34 @@ export function ensureSearchIndex(db, options = {}) {
519
554
  }
520
555
  }
521
556
 
557
+ /**
558
+ * The drift state of the installed search table.
559
+ *
560
+ * The state is **reported**, never repaired: a drifted table is left as it is,
561
+ * the database stays readable, and the remedy is the existing rebuild path.
562
+ */
563
+ export function detectFtsShapeDrift(db) {
564
+ if (!tableExists(db, SEARCH_TABLE)) {
565
+ return { state: 'absent', recorded: null, shape: null, columns: [] };
566
+ }
567
+ const columns = ftsColumnNames(db);
568
+ const recorded = readSchemaMeta(db, FTS_SHAPE_META_KEY);
569
+ if (recorded === null) {
570
+ return { state: 'unrecorded', recorded: null, shape: null, columns };
571
+ }
572
+ const known = FTS_SHAPES.find((shape) => shape.id === recorded);
573
+ if (!known) {
574
+ return { state: 'unknown', recorded, shape: null, columns };
575
+ }
576
+ if (known.id !== CURRENT_FTS_SHAPE.id) {
577
+ return { state: 'superseded', recorded, shape: known.id, columns };
578
+ }
579
+ if (columns.join(',') !== ftsShapeSignature(known)) {
580
+ return { state: 'unknown', recorded, shape: known.id, columns };
581
+ }
582
+ return { state: 'current', recorded, shape: known.id, columns };
583
+ }
584
+
522
585
  export function readSearchMode(db) {
523
586
  const meta = readSchemaMeta(db, 'search');
524
587
  if (!tableExists(db, SEARCH_TABLE)) return SEARCH_MODE_LIKE;
@@ -783,6 +846,7 @@ export function openTeamDb(options = {}) {
783
846
  schemaVersion: current < SCHEMA_VERSION ? SCHEMA_VERSION : current,
784
847
  fingerprint,
785
848
  searchMode,
849
+ searchShape: detectFtsShapeDrift(db),
786
850
  };
787
851
  } catch (error) {
788
852
  try {
@@ -826,6 +890,12 @@ export function describeHandle(handle) {
826
890
  `search ${handle.searchMode}`,
827
891
  'integrity ok',
828
892
  ];
893
+ // A drifted search layout is reported, never repaired: the state names what
894
+ // is installed, and the rebuild path stays the remedy.
895
+ const shape = handle.searchShape;
896
+ if (shape && shape.state !== 'current' && shape.state !== 'absent') {
897
+ parts.push(`search-shape ${shape.state}`);
898
+ }
829
899
  if (handle.rebuilt) parts.push('rebuilt=1');
830
900
  return `${handle.dbPath}: ok (${parts.join(', ')})`;
831
901
  }
@@ -7,16 +7,25 @@
7
7
  * sync [--root <team-dir>] [--slug <slug>] [--quiet] [--json]
8
8
  * [--maintain] [--prune] [--vacuum] [--rebuild | --no-rebuild]
9
9
  * [--deadline-ms <n>] project files into the database
10
+ * delete --slug <slug> [--root <team-dir>] [--json]
11
+ * delete one task folder, then its rows
10
12
  * migrate-tasks [--root <team-dir>] [--quiet] [--json]
11
13
  * [--rebuild | --no-rebuild] create or reconcile the database
12
14
  * serve [--root <team-dir>] [--host <addr>] [--port <n>] [--allow-remote]
13
- * [--open] read-only API + dashboard
15
+ * [--open] loopback API + dashboard
14
16
  *
15
- * Exit codes: 0 ok, 1 at least one task failed or a migration checksum drifted,
16
- * 2 database-level failure, 3 usage, 4 deadline or busy.
17
+ * Exit codes: 0 ok, 1 at least one task failed, a delete refusal (unknown slug,
18
+ * active-task guard, kill switch, folder-delete failure) or a migration
19
+ * checksum drifted, 2 database-level failure, 3 usage, 4 deadline or busy.
17
20
  *
18
21
  * A runtime without `node:sqlite` prints one line and stays file-only:
19
- * `init`/`sync`/`migrate-tasks` exit 0 without creating a database, `check` exits 1.
22
+ * `init`/`sync`/`migrate-tasks` exit 0 without creating a database, `check` and
23
+ * `delete` exit non-zero (`delete` never deletes the folder while the row leg
24
+ * cannot run).
25
+ *
26
+ * With `--json`, `delete` prints exactly one machine-readable line: the result
27
+ * `{ ok: true, slug, folderRemoved, rowsDeleted }` on success, or
28
+ * `{ ok: false, code, message }` on a refusal.
20
29
  */
21
30
 
22
31
  import fs from 'node:fs';
@@ -38,7 +47,7 @@ import {
38
47
  openTeamDb,
39
48
  teamDbFail,
40
49
  } from './team-db-schema.mjs';
41
- import { describeSyncResult, syncProjection } from './team-db-project.mjs';
50
+ import { deleteTaskProjection, describeSyncResult, syncProjection } from './team-db-project.mjs';
42
51
 
43
52
  const USAGE = `usage:
44
53
  team-db.mjs init [--root <team-dir>] [--rebuild]
@@ -46,6 +55,7 @@ const USAGE = `usage:
46
55
  team-db.mjs sync [--root <team-dir>] [--slug <slug>] [--quiet] [--json]
47
56
  [--maintain] [--prune] [--vacuum] [--rebuild | --no-rebuild]
48
57
  [--deadline-ms <n>]
58
+ team-db.mjs delete --slug <slug> [--root <team-dir>] [--json]
49
59
  team-db.mjs migrate-tasks [--root <team-dir>] [--quiet] [--json]
50
60
  [--rebuild | --no-rebuild]
51
61
  team-db.mjs serve [--root <team-dir>] [--host <addr>] [--port <n>]
@@ -53,11 +63,12 @@ const USAGE = `usage:
53
63
 
54
64
  const VALUE_FLAGS = new Set(['root', 'slug', 'deadline-ms', 'host', 'port']);
55
65
  const BOOLEAN_FLAGS = new Set(['quiet', 'json', 'maintain', 'prune', 'vacuum', 'rebuild', 'no-rebuild', 'allow-remote', 'open']);
56
- const COMMANDS = new Set(['init', 'check', 'sync', 'migrate-tasks', 'serve']);
66
+ const COMMANDS = new Set(['init', 'check', 'sync', 'delete', 'migrate-tasks', 'serve']);
57
67
  const ALLOWED_FLAGS = {
58
68
  init: new Set(['root', 'rebuild']),
59
69
  check: new Set(['root']),
60
70
  sync: new Set(['root', 'slug', 'quiet', 'json', 'maintain', 'prune', 'vacuum', 'rebuild', 'no-rebuild', 'deadline-ms']),
71
+ delete: new Set(['root', 'slug', 'json']),
61
72
  'migrate-tasks': new Set(['root', 'quiet', 'json', 'rebuild', 'no-rebuild']),
62
73
  serve: new Set(['root', 'host', 'port', 'allow-remote', 'open']),
63
74
  };
@@ -175,6 +186,38 @@ const runSync = (flags) => {
175
186
  return result.exitCode;
176
187
  };
177
188
 
189
+ const runDelete = (flags) => {
190
+ // The kill switch refuses before any leg; `--json` still answers with the
191
+ // one failure line so an API child can map the code.
192
+ if (isKillSwitchSet(process.env)) {
193
+ disabledLine();
194
+ if (flags.json) process.stdout.write(`${JSON.stringify({ ok: false, code: 'E_DISABLED', message: 'disabled by AI_RULES_TEAM_DB_DISABLE' })}\n`);
195
+ return 1;
196
+ }
197
+ // Without node:sqlite the row leg cannot run, and a delete that leaves its
198
+ // rows behind is not a delete; refuse instead of deleting the folder only.
199
+ if (!isSqliteAvailable(process.env)) {
200
+ unavailableLine();
201
+ if (flags.json) process.stdout.write(`${JSON.stringify({ ok: false, code: 'E_INTERNAL', message: INDEX_UNAVAILABLE_LINE })}\n`);
202
+ return 2;
203
+ }
204
+ try {
205
+ const result = deleteTaskProjection({ teamRoot: teamRootFrom(flags), slug: flags.slug, env: process.env });
206
+ if (flags.json) {
207
+ process.stdout.write(`${JSON.stringify(result)}\n`);
208
+ } else {
209
+ process.stdout.write(`delete: slug=${result.slug} folderRemoved=${result.folderRemoved} rowsDeleted=${result.rowsDeleted}\n`);
210
+ }
211
+ return 0;
212
+ } catch (error) {
213
+ const code = error instanceof TeamDbError ? error.code : 'E_INTERNAL';
214
+ const exitCode = error instanceof TeamDbError ? error.exitCode : 2;
215
+ if (flags.json) process.stdout.write(`${JSON.stringify({ ok: false, code, message: error.message })}\n`);
216
+ process.stderr.write(`${error.message}\n`);
217
+ return exitCode;
218
+ }
219
+ };
220
+
178
221
  const runMigrateTasks = (flags) => {
179
222
  if (cannotProject(process.env)) return 0;
180
223
  if (flags.rebuild && flags['no-rebuild']) teamDbFail('E_USAGE', '--rebuild and --no-rebuild are exclusive', 3);
@@ -268,6 +311,7 @@ export async function runCli(argv) {
268
311
  }
269
312
  if (command === 'init') return runInit(flags);
270
313
  if (command === 'check') return runCheck(flags);
314
+ if (command === 'delete') return runDelete(flags);
271
315
  if (command === 'migrate-tasks') return runMigrateTasks(flags);
272
316
  if (command === 'serve') return runServe(flags);
273
317
  return runSync(flags);
@@ -244,13 +244,24 @@ Use Task tool or `/agent-name`. Pass: slug, artifact paths, step `scope` if set.
244
244
  ### Model when invoking (Task)
245
245
 
246
246
  1. Read `steps[i].model` if present; else use the agent’s frontmatter `model` (see `agents/README.md` matrix).
247
- 2. Map abstract tiers:
248
- - **`cheap`** → pass Task `model: "fast"` when the tool accepts it (or rely on agent `fast`).
249
- - **`standard`** → omit Task `model` (frontmatter `inherit` / mid default).
250
- - **`strong`** → **never** pass `fast`; rely on agent pin or parent Max model.
251
- 3. Parallel steps: apply the step-level `model` to **each** agent in the array (or omit → each agent’s own frontmatter).
247
+ 2. Resolve the tier through `.ai.local/team/model-tiers.json` → `tiers.<tier>` when that file exists. The user approved that map, so passing an explicit model is allowed. Pass the resolved `providerID/modelID` (or `providerID/modelID#variant`) to the Task/subagent tool.
248
+ - **`cheap`** → mechanical steps only (router, analyst, tech-writer, codebase-analyzer).
249
+ - **`standard`** → implementation, verification, review, QA, contract review.
250
+ - **`strong`** → architecture, security, migration, performance, mockup review. Never downgrade a `strong` step to the parent default.
251
+ - If a tier is declared but the file has no mapping, **STOP** and report `model-tier-unmapped`; do not silently inherit the parent model.
252
+ 3. If the tool does not accept a model (Cursor/Claude adapters), record the resolved tier in the handoff and let the platform pin apply.
253
+ 4. Parallel steps: apply the step-level `model` to **each** agent in the array (or omit → each agent’s own frontmatter).
254
+ 5. The tier never changes the step order, gates, receipts, or retry policy.
255
+
256
+ **Token usage.** When the host exposes token counts, append a `usage_recorded` event next to the attempt:
257
+
258
+ ```bash
259
+ node .ai.local/scripts/record-usage.mjs --task <slug> --attempt <attemptId> --input <n> --output <n> [--cached <n>] [--model <id>]
260
+ ```
261
+
262
+ The chain hook also forwards a `usage` object from its input into the `attempt_finished` event. Never estimate or invent token counts; a missing usage record stays missing.
252
263
 
253
- After each agent completes, verify its terminal manifest receipt, then let the orchestration runtime/hook reconcile `status.json` (`completed`, a blocking outcome, or `awaiting_approval`) from that receipt. Do not ask the agent to mutate shared lifecycle fields, and do not invoke the next specialist until the hook has written the handoff / updated `status.json`.
264
+ After each agent completes, verify its terminal manifest receipt, then let the orchestration runtime/hook reconcile `status.json` (`completed`, a blocking outcome, or `awaiting_approval`) from that receipt. Pass the active slug explicitly: `TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh` (or the host's hook path). The `active-task.json` pointer is a single-slot fallback and a parallel session can overwrite it; do not rely on it alone. Do not ask the agent to mutate shared lifecycle fields, and do not invoke the next specialist until the hook has written the handoff / updated `status.json`.
254
265
 
255
266
  ## Legacy mode
256
267
 
@@ -58,7 +58,9 @@ multi-wave work). It ratchets down for bounded/spike tasks (see § Ratchet).
58
58
  - **Opt-in and conditional — only when the engine exists.** In-task self-learning loop: run
59
59
  `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn
60
60
  with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with
61
- `node .ai.local/scripts/run.mjs --status`.
61
+ `node .ai.local/scripts/run.mjs --status`. Keep the loop deterministic: it runs no model-driven pass — rule text
62
+ is template-derived from the validated signature; a model-driven pass is not part of the loop, and if one is ever
63
+ added it must be default-off and may write only to the staged band.
62
64
  - The engine enforces the Rule of Three (≥2 distinct tasks → edit a local rule or `conventions.md` gotcha; ≥3 →
63
65
  stage a new rule) and applies or stages per the two-band autonomy policy. Never count the threshold by hand; never
64
66
  edit the engine. Engine absent → nothing to run; say so in the receipt instead of guessing. Not a new pipeline
@@ -29,22 +29,27 @@ if (hookInput.status !== 'completed') {
29
29
  process.exit(0);
30
30
  }
31
31
 
32
- const activePath = path.join(TEAM_ROOT, 'active-task.json');
33
-
34
- if (!fs.existsSync(activePath)) {
35
- process.stdout.write('{}');
36
- process.exit(0);
37
- }
32
+ // The orchestrator passes TEAM_TASK_SLUG on every hook call. The single-slot
33
+ // active-task.json pointer is a fallback for the UI and older hosts; parallel
34
+ // sessions otherwise overwrite it and silently no-op each other's hooks.
35
+ let slug = process.env.TEAM_TASK_SLUG;
36
+ if (!slug) {
37
+ const activePath = path.join(TEAM_ROOT, 'active-task.json');
38
+
39
+ if (!fs.existsSync(activePath)) {
40
+ process.stdout.write('{}');
41
+ process.exit(0);
42
+ }
38
43
 
39
- let active;
40
- try {
41
- active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
42
- } catch {
43
- process.stdout.write('{}');
44
- process.exit(0);
44
+ let active;
45
+ try {
46
+ active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
47
+ } catch {
48
+ process.stdout.write('{}');
49
+ process.exit(0);
50
+ }
51
+ slug = active.slug;
45
52
  }
46
-
47
- const slug = active.slug;
48
53
  // Reject non-kebab / traversal slugs: the runtime writes status.json and
49
54
  // metrics.json under tasks/<slug>, so an unchecked slug could escape the tree.
50
55
  const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -823,7 +828,7 @@ function finishActiveAttempt(forced) {
823
828
  const resolved = forced || resolvedAttempt(); if (!resolved) return null;
824
829
  const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
825
830
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
826
- appendMetric({ type: 'attempt_finished', at: now, attemptId: resolved.attemptId, outcome, durationMs: Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : null, retryAfterFix: status.retryAfterFix || null, source: resolved.source || 'hook', attributionConfidence: resolved.confidence });
831
+ appendMetric({ type: 'attempt_finished', at: now, attemptId: resolved.attemptId, outcome, durationMs: Number.isFinite(durationMs) && durationMs >= 0 ? durationMs : null, retryAfterFix: status.retryAfterFix || null, source: resolved.source || 'hook', attributionConfidence: resolved.confidence, ...(hookInput.usage && typeof hookInput.usage === 'object' ? { usage: hookInput.usage } : {}) });
827
832
  const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
828
833
  }
829
834
  function missingConsumerArtifacts() {
@@ -59,7 +59,7 @@ Before you run the project gate and write the terminal validation receipt, self-
59
59
 
60
60
  **Re-anchor.** On detected drift: re-read the `task-framing` goal frame + the current `decomposition.md` → repair the drift → re-run the affected gate → record append-only in `.memlog.md` (`event:` line; `decision: replan rev N → N+1` when the plan changes). Bound to the existing `plan-graph` `replan` — no second orchestrator, no `status.json`/`metrics.json` field.
61
61
 
62
- Record a `## Self-review` block in `validation-report.md` (goal/AC coverage, evidence, alignment/drift). Optional loop (see the requestable `self-review-and-context-hygiene` contract). In-task self-learning loop: run `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with `node .ai.local/scripts/run.mjs --status`. Ratchet: no self-review / context-health pass / re-anchor ceremony for `bounded`/`spike` tasks (or the `light` profile).
62
+ Record a `## Self-review` block in `validation-report.md` (goal/AC coverage, evidence, alignment/drift). Optional loop (see the requestable `self-review-and-context-hygiene` contract). In-task self-learning loop: run `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with `node .ai.local/scripts/run.mjs --status`. Keep the loop deterministic: it runs no model-driven pass — rule text is template-derived from the validated signature; a model-driven pass is not part of the loop, and if one is ever added it must be default-off and may write only to the staged band. Ratchet: no self-review / context-health pass / re-anchor ceremony for `bounded`/`spike` tasks (or the `light` profile).
63
63
 
64
64
  A self-review defect that changes the output appends one `review-ledger.md` row (`source: self`, `fair: yes`, `disposition: fixed`) before the receipt. Do not start implementation when `goal.md` is missing.
65
65
 
@@ -64,7 +64,7 @@ Before you emit the terminal review receipt, self-audit the review artifact: eve
64
64
 
65
65
  **Re-anchor.** On detected drift: re-read the `task-framing` goal frame + the current `decomposition.md` → repair the drift → re-run the affected gate → record append-only in `.memlog.md` (`event:` line; `decision: replan rev N → N+1` when the plan changes). Bound to the existing `plan-graph` `replan` — no second orchestrator, no `status.json`/`metrics.json` field.
66
66
 
67
- Record a `## Self-review` block in `review.md` (goal/AC coverage, evidence, alignment/drift). Optional loop (see the requestable `self-review-and-context-hygiene` contract). In-task self-learning loop: run `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with `node .ai.local/scripts/run.mjs --status`. Ratchet: no self-review / context-health pass / re-anchor ceremony for `bounded`/`spike` tasks (or the `light` profile).
67
+ Record a `## Self-review` block in `review.md` (goal/AC coverage, evidence, alignment/drift). Optional loop (see the requestable `self-review-and-context-hygiene` contract). In-task self-learning loop: run `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with `node .ai.local/scripts/run.mjs --status`. Keep the loop deterministic: it runs no model-driven pass — rule text is template-derived from the validated signature; a model-driven pass is not part of the loop, and if one is ever added it must be default-off and may write only to the staged band. Ratchet: no self-review / context-health pass / re-anchor ceremony for `bounded`/`spike` tasks (or the `light` profile).
68
68
 
69
69
  A self-review defect that changes the output appends one `review-ledger.md` row (`source: self`, `fair: yes`, `disposition: fixed`) before the receipt. Do not start implementation when `goal.md` is missing. Append each finding to `review-ledger.md` (`disposition: open`) before the receipt.
70
70
 
@@ -100,7 +100,7 @@ Before you set `fixApplied: true` and emit the terminal receipt, self-audit the
100
100
 
101
101
  **Re-anchor.** On detected drift: re-read the `task-framing` goal frame + the current `decomposition.md` → repair the drift → re-run the affected gate → record append-only in `.memlog.md` (`event:` line; `decision: replan rev N → N+1` when the plan changes). Bound to the existing `plan-graph` `replan` — no second orchestrator, no `status.json`/`metrics.json` field.
102
102
 
103
- Record a `## Self-review` block in `debug-report.md` (goal/AC coverage, evidence, alignment/drift). Optional loop (see the requestable `self-review-and-context-hygiene` contract). In-task self-learning loop: run `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with `node .ai.local/scripts/run.mjs --status`. Ratchet: no self-review / context-health pass / re-anchor ceremony for `bounded`/`spike` tasks (or the `light` profile).
103
+ Record a `## Self-review` block in `debug-report.md` (goal/AC coverage, evidence, alignment/drift). Optional loop (see the requestable `self-review-and-context-hygiene` contract). In-task self-learning loop: run `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with `node .ai.local/scripts/run.mjs --status`. Keep the loop deterministic: it runs no model-driven pass — rule text is template-derived from the validated signature; a model-driven pass is not part of the loop, and if one is ever added it must be default-off and may write only to the staged band. Ratchet: no self-review / context-health pass / re-anchor ceremony for `bounded`/`spike` tasks (or the `light` profile).
104
104
 
105
105
  A self-review defect that changes the output appends one `review-ledger.md` row (`source: self`, `fair: yes`, `disposition: fixed`) before the receipt. Do not start implementation when `goal.md` is missing.
106
106
 
@@ -102,7 +102,7 @@ Before you emit the terminal implementation receipt (per wave for multi-wave wor
102
102
 
103
103
  **Re-anchor.** On detected drift: re-read the `task-framing` goal frame + the current `decomposition.md` → repair the drift → re-run the affected gate → record append-only in `.memlog.md` (`event:` line; `decision: replan rev N → N+1` when the plan changes). Bound to the existing `plan-graph` `replan` — no second orchestrator, no `status.json`/`metrics.json` field.
104
104
 
105
- Record a `## Self-review` block in `implementation.md` (goal/AC coverage, evidence, alignment/drift). Optional loop (see the requestable `self-review-and-context-hygiene` contract). In-task self-learning loop: run `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with `node .ai.local/scripts/run.mjs --status`. Ratchet: no self-review / context-health pass / re-anchor ceremony for `bounded`/`spike` tasks (or the `light` profile).
105
+ Record a `## Self-review` block in `implementation.md` (goal/AC coverage, evidence, alignment/drift). Optional loop (see the requestable `self-review-and-context-hygiene` contract). In-task self-learning loop: run `node .ai.local/scripts/run.mjs` at the pre-receipt self-review when the engine exists; capture one wrong-turn with `node .ai.local/scripts/signals.mjs --append '<json>'` and inspect read-only with `node .ai.local/scripts/run.mjs --status`. Keep the loop deterministic: it runs no model-driven pass — rule text is template-derived from the validated signature; a model-driven pass is not part of the loop, and if one is ever added it must be default-off and may write only to the staged band. Ratchet: no self-review / context-health pass / re-anchor ceremony for `bounded`/`spike` tasks (or the `light` profile).
106
106
 
107
107
  A self-review defect that changes the output appends one `review-ledger.md` row (`source: self`, `fair: yes`, `disposition: fixed`) before the receipt. Do not start implementation when `goal.md` is missing.
108
108