@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
@@ -81,7 +81,7 @@ Before you emit the terminal implementation receipt (per wave for multi-wave wor
81
81
 
82
82
  **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.
83
83
 
84
- 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).
84
+ 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).
85
85
 
86
86
  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.
87
87
 
@@ -50,7 +50,7 @@ Before you emit the terminal analysis receipt, self-audit the goal frame and dec
50
50
 
51
51
  **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.
52
52
 
53
- Record a `## Self-review` block in `brief.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).
53
+ Record a `## Self-review` block in `brief.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).
54
54
 
55
55
  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.
56
56
 
@@ -27,22 +27,27 @@ if (hookInput.status !== 'completed') {
27
27
  process.exit(0);
28
28
  }
29
29
 
30
- const activePath = path.join(TEAM_ROOT, 'active-task.json');
31
-
32
- if (!fs.existsSync(activePath)) {
33
- process.stdout.write('{}');
34
- process.exit(0);
35
- }
30
+ // The orchestrator passes TEAM_TASK_SLUG on every hook call. The single-slot
31
+ // active-task.json pointer is a fallback for the UI and older hosts; parallel
32
+ // sessions otherwise overwrite it and silently no-op each other's hooks.
33
+ let slug = process.env.TEAM_TASK_SLUG;
34
+ if (!slug) {
35
+ const activePath = path.join(TEAM_ROOT, 'active-task.json');
36
+
37
+ if (!fs.existsSync(activePath)) {
38
+ process.stdout.write('{}');
39
+ process.exit(0);
40
+ }
36
41
 
37
- let active;
38
- try {
39
- active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
40
- } catch {
41
- process.stdout.write('{}');
42
- process.exit(0);
42
+ let active;
43
+ try {
44
+ active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
45
+ } catch {
46
+ process.stdout.write('{}');
47
+ process.exit(0);
48
+ }
49
+ slug = active.slug;
43
50
  }
44
-
45
- const slug = active.slug;
46
51
  // Reject non-kebab / traversal slugs: the runtime writes status.json and
47
52
  // metrics.json under tasks/<slug>, so an unchecked slug could escape the tree.
48
53
  const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -842,7 +847,7 @@ function finishActiveAttempt(forced) {
842
847
  const resolved = forced || resolvedAttempt(); if (!resolved) return null;
843
848
  const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
844
849
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
845
- 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 });
850
+ 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 } : {}) });
846
851
  const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
847
852
  }
848
853
  function missingConsumerArtifacts() {
@@ -94,7 +94,7 @@ Each producing agent runs a **pre-receipt self-review** of its own output — go
94
94
 
95
95
  - **Context loss vs excess/noise.** *Loss* = a dropped/misattributed AC or constraint, a stale plan vs the current request, a forgotten prior decision. *Excess/noise* = irrelevant/tangent reads, scope creep beyond the frame, duplicated or bloated artifacts, chat state that belongs on disk.
96
96
  - **Re-anchor.** On detected drift, return the run to the framed task: 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). Re-anchor is a **trigger source of the existing `plan-graph` `replan`** — no second orchestrator, no `status.json`/`metrics.json` field.
97
- - **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional loop. 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`.
97
+ - **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional loop. 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.
98
98
 
99
99
  - **Goal before execution.** During slug bootstrap, write `.ai.local/team/tasks/<slug>/goal.md` (`Goal`, `User value`, `Success criteria`, `Non-goals`, Derived from `prompt.md`). The goal is a formulated outcome. Do not copy the prompt into it. Show `goal.md` with the plan table before `steps[0]`. An implementer does not start when `goal.md` is missing. A goal change is a `planRevision` plus a new confirmation. Bounded, spike, and `light` still write the thin frame. See **agent-artifact-contracts** § Goal artifact.
100
100
  - **Outcome and review ledger.** Append a `review-ledger.md` row when a self-review defect changes the output. `code-reviewer` appends each finding. Append a user or other-agent objection from `prompt-log.md` or `/task-continue`. `fixed` is `fair: yes`; `rejected` is `fair: no` and cites the rebuttal; `open` at close is `fair: yes`. On a terminal pipeline state, write `outcome.md` (`goalAchieved`, `value`, per-criterion evidence, `reviewCounts`) before the closing user message. `satisfactory` requires every success criterion evidenced and no open fair row. `unsatisfactory` does not reopen the task. When the ledger has a `fair: yes` row, append one signal per distinct signature with `node .ai.local/scripts/signals.mjs --append '<json>'` and run `node .ai.local/scripts/run.mjs` once. Preset-prose targets stay staged for `/technical-retro`. See **agent-artifact-contracts** § Outcome artifact and § Review ledger.
@@ -38,7 +38,7 @@ Before you run the project gate and write the terminal validation receipt, self-
38
38
 
39
39
  **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.
40
40
 
41
- 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).
41
+ 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).
42
42
 
43
43
  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.
44
44
 
@@ -51,7 +51,7 @@ Before you emit the terminal review receipt, self-audit the review artifact: eve
51
51
 
52
52
  **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.
53
53
 
54
- 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).
54
+ 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).
55
55
 
56
56
  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.
57
57
 
@@ -43,7 +43,7 @@ Before you set `fixApplied: true` and emit the terminal receipt, self-audit the
43
43
 
44
44
  **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.
45
45
 
46
- 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).
46
+ 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).
47
47
 
48
48
  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.
49
49
 
@@ -68,7 +68,7 @@ Before you emit the terminal implementation receipt (per wave for multi-wave wor
68
68
 
69
69
  **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.
70
70
 
71
- 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).
71
+ 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).
72
72
 
73
73
  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.
74
74
 
@@ -50,7 +50,7 @@ Before you emit the terminal analysis receipt, self-audit the goal frame and dec
50
50
 
51
51
  **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.
52
52
 
53
- Record a `## Self-review` block in `brief.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).
53
+ Record a `## Self-review` block in `brief.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).
54
54
 
55
55
  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.
56
56
 
@@ -28,22 +28,27 @@ if (hookInput.status !== 'completed') {
28
28
  process.exit(0);
29
29
  }
30
30
 
31
- const activePath = path.join(TEAM_ROOT, 'active-task.json');
32
-
33
- if (!fs.existsSync(activePath)) {
34
- process.stdout.write('{}');
35
- process.exit(0);
36
- }
31
+ // The orchestrator passes TEAM_TASK_SLUG on every hook call. The single-slot
32
+ // active-task.json pointer is a fallback for the UI and older hosts; parallel
33
+ // sessions otherwise overwrite it and silently no-op each other's hooks.
34
+ let slug = process.env.TEAM_TASK_SLUG;
35
+ if (!slug) {
36
+ const activePath = path.join(TEAM_ROOT, 'active-task.json');
37
+
38
+ if (!fs.existsSync(activePath)) {
39
+ process.stdout.write('{}');
40
+ process.exit(0);
41
+ }
37
42
 
38
- let active;
39
- try {
40
- active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
41
- } catch {
42
- process.stdout.write('{}');
43
- process.exit(0);
43
+ let active;
44
+ try {
45
+ active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
46
+ } catch {
47
+ process.stdout.write('{}');
48
+ process.exit(0);
49
+ }
50
+ slug = active.slug;
44
51
  }
45
-
46
- const slug = active.slug;
47
52
  // Reject non-kebab / traversal slugs: the runtime writes status.json and
48
53
  // metrics.json under tasks/<slug>, so an unchecked slug could escape the tree.
49
54
  const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -841,7 +846,7 @@ function finishActiveAttempt(forced) {
841
846
  const resolved = forced || resolvedAttempt(); if (!resolved) return null;
842
847
  const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
843
848
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
844
- 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 });
849
+ 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 } : {}) });
845
850
  const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
846
851
  }
847
852
  function missingConsumerArtifacts() {
@@ -92,7 +92,7 @@ Each producing agent runs a **pre-receipt self-review** of its own output — go
92
92
 
93
93
  - **Context loss vs excess/noise.** *Loss* = a dropped/misattributed AC or constraint, a stale plan vs the current request, a forgotten prior decision. *Excess/noise* = irrelevant/tangent reads, scope creep beyond the frame, duplicated or bloated artifacts, chat state that belongs on disk.
94
94
  - **Re-anchor.** On detected drift, return the run to the framed task: 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). Re-anchor is a **trigger source of the existing `plan-graph` `replan`** — no second orchestrator, no `status.json`/`metrics.json` field.
95
- - **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional loop. 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`.
95
+ - **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional loop. 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.
96
96
 
97
97
  - **Goal before execution.** During slug bootstrap, write `.ai.local/team/tasks/<slug>/goal.md` (`Goal`, `User value`, `Success criteria`, `Non-goals`, Derived from `prompt.md`). The goal is a formulated outcome. Do not copy the prompt into it. Show `goal.md` with the plan table before `steps[0]`. An implementer does not start when `goal.md` is missing. A goal change is a `planRevision` plus a new confirmation. Bounded, spike, and `light` still write the thin frame. See **agent-artifact-contracts** § Goal artifact.
98
98
  - **Outcome and review ledger.** Append a `review-ledger.md` row when a self-review defect changes the output. `code-reviewer` appends each finding. Append a user or other-agent objection from `prompt-log.md` or `/task-continue`. `fixed` is `fair: yes`; `rejected` is `fair: no` and cites the rebuttal; `open` at close is `fair: yes`. On a terminal pipeline state, write `outcome.md` (`goalAchieved`, `value`, per-criterion evidence, `reviewCounts`) before the closing user message. `satisfactory` requires every success criterion evidenced and no open fair row. `unsatisfactory` does not reopen the task. When the ledger has a `fair: yes` row, append one signal per distinct signature with `node .ai.local/scripts/signals.mjs --append '<json>'` and run `node .ai.local/scripts/run.mjs` once. Preset-prose targets stay staged for `/technical-retro`. See **agent-artifact-contracts** § Outcome artifact and § Review ledger.
@@ -45,7 +45,7 @@ Before you run the project gate and write the terminal validation receipt, self-
45
45
 
46
46
  **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.
47
47
 
48
- 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).
48
+ 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).
49
49
 
50
50
  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.
51
51
 
@@ -52,7 +52,7 @@ Before you emit the terminal review receipt, self-audit the review artifact: eve
52
52
 
53
53
  **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.
54
54
 
55
- 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).
55
+ 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).
56
56
 
57
57
  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.
58
58
 
@@ -84,7 +84,7 @@ Before you set `fixApplied: true` and emit the terminal receipt, self-audit the
84
84
 
85
85
  **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.
86
86
 
87
- 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).
87
+ 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).
88
88
 
89
89
  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.
90
90
 
@@ -81,7 +81,7 @@ Before you emit the terminal implementation receipt (per wave for multi-wave wor
81
81
 
82
82
  **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.
83
83
 
84
- 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).
84
+ 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).
85
85
 
86
86
  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.
87
87
 
@@ -50,7 +50,7 @@ Before you emit the terminal analysis receipt, self-audit the goal frame and dec
50
50
 
51
51
  **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.
52
52
 
53
- Record a `## Self-review` block in `brief.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).
53
+ Record a `## Self-review` block in `brief.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).
54
54
 
55
55
  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.
56
56
 
@@ -27,22 +27,27 @@ if (hookInput.status !== 'completed') {
27
27
  process.exit(0);
28
28
  }
29
29
 
30
- const activePath = path.join(TEAM_ROOT, 'active-task.json');
31
-
32
- if (!fs.existsSync(activePath)) {
33
- process.stdout.write('{}');
34
- process.exit(0);
35
- }
30
+ // The orchestrator passes TEAM_TASK_SLUG on every hook call. The single-slot
31
+ // active-task.json pointer is a fallback for the UI and older hosts; parallel
32
+ // sessions otherwise overwrite it and silently no-op each other's hooks.
33
+ let slug = process.env.TEAM_TASK_SLUG;
34
+ if (!slug) {
35
+ const activePath = path.join(TEAM_ROOT, 'active-task.json');
36
+
37
+ if (!fs.existsSync(activePath)) {
38
+ process.stdout.write('{}');
39
+ process.exit(0);
40
+ }
36
41
 
37
- let active;
38
- try {
39
- active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
40
- } catch {
41
- process.stdout.write('{}');
42
- process.exit(0);
42
+ let active;
43
+ try {
44
+ active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
45
+ } catch {
46
+ process.stdout.write('{}');
47
+ process.exit(0);
48
+ }
49
+ slug = active.slug;
43
50
  }
44
-
45
- const slug = active.slug;
46
51
  // Reject non-kebab / traversal slugs: the runtime writes status.json and
47
52
  // metrics.json under tasks/<slug>, so an unchecked slug could escape the tree.
48
53
  const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -842,7 +847,7 @@ function finishActiveAttempt(forced) {
842
847
  const resolved = forced || resolvedAttempt(); if (!resolved) return null;
843
848
  const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
844
849
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
845
- 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 });
850
+ 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 } : {}) });
846
851
  const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
847
852
  }
848
853
  function missingConsumerArtifacts() {
@@ -94,7 +94,7 @@ Each producing agent runs a **pre-receipt self-review** of its own output — go
94
94
 
95
95
  - **Context loss vs excess/noise.** *Loss* = a dropped/misattributed AC or constraint, a stale plan vs the current request, a forgotten prior decision. *Excess/noise* = irrelevant/tangent reads, scope creep beyond the frame, duplicated or bloated artifacts, chat state that belongs on disk.
96
96
  - **Re-anchor.** On detected drift, return the run to the framed task: 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). Re-anchor is a **trigger source of the existing `plan-graph` `replan`** — no second orchestrator, no `status.json`/`metrics.json` field.
97
- - **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional loop. 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`.
97
+ - **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional loop. 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.
98
98
 
99
99
  - **Goal before execution.** During slug bootstrap, write `.ai.local/team/tasks/<slug>/goal.md` (`Goal`, `User value`, `Success criteria`, `Non-goals`, Derived from `prompt.md`). The goal is a formulated outcome. Do not copy the prompt into it. Show `goal.md` with the plan table before `steps[0]`. An implementer does not start when `goal.md` is missing. A goal change is a `planRevision` plus a new confirmation. Bounded, spike, and `light` still write the thin frame. See **agent-artifact-contracts** § Goal artifact.
100
100
  - **Outcome and review ledger.** Append a `review-ledger.md` row when a self-review defect changes the output. `code-reviewer` appends each finding. Append a user or other-agent objection from `prompt-log.md` or `/task-continue`. `fixed` is `fair: yes`; `rejected` is `fair: no` and cites the rebuttal; `open` at close is `fair: yes`. On a terminal pipeline state, write `outcome.md` (`goalAchieved`, `value`, per-criterion evidence, `reviewCounts`) before the closing user message. `satisfactory` requires every success criterion evidenced and no open fair row. `unsatisfactory` does not reopen the task. When the ledger has a `fair: yes` row, append one signal per distinct signature with `node .ai.local/scripts/signals.mjs --append '<json>'` and run `node .ai.local/scripts/run.mjs` once. Preset-prose targets stay staged for `/technical-retro`. See **agent-artifact-contracts** § Outcome artifact and § Review ledger.
@@ -38,7 +38,7 @@ Before you run the project gate and write the terminal validation receipt, self-
38
38
 
39
39
  **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.
40
40
 
41
- 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).
41
+ 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).
42
42
 
43
43
  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.
44
44
 
@@ -51,7 +51,7 @@ Before you emit the terminal review receipt, self-audit the review artifact: eve
51
51
 
52
52
  **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.
53
53
 
54
- 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).
54
+ 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).
55
55
 
56
56
  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.
57
57
 
@@ -43,7 +43,7 @@ Before you set `fixApplied: true` and emit the terminal receipt, self-audit the
43
43
 
44
44
  **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.
45
45
 
46
- 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).
46
+ 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).
47
47
 
48
48
  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.
49
49
 
@@ -68,7 +68,7 @@ Before you emit the terminal implementation receipt (per wave for multi-wave wor
68
68
 
69
69
  **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.
70
70
 
71
- 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).
71
+ 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).
72
72
 
73
73
  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.
74
74
 
@@ -50,7 +50,7 @@ Before you emit the terminal analysis receipt, self-audit the goal frame and dec
50
50
 
51
51
  **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.
52
52
 
53
- Record a `## Self-review` block in `brief.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).
53
+ Record a `## Self-review` block in `brief.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).
54
54
 
55
55
  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.
56
56
 
@@ -28,22 +28,27 @@ if (hookInput.status !== 'completed') {
28
28
  process.exit(0);
29
29
  }
30
30
 
31
- const activePath = path.join(TEAM_ROOT, 'active-task.json');
32
-
33
- if (!fs.existsSync(activePath)) {
34
- process.stdout.write('{}');
35
- process.exit(0);
36
- }
31
+ // The orchestrator passes TEAM_TASK_SLUG on every hook call. The single-slot
32
+ // active-task.json pointer is a fallback for the UI and older hosts; parallel
33
+ // sessions otherwise overwrite it and silently no-op each other's hooks.
34
+ let slug = process.env.TEAM_TASK_SLUG;
35
+ if (!slug) {
36
+ const activePath = path.join(TEAM_ROOT, 'active-task.json');
37
+
38
+ if (!fs.existsSync(activePath)) {
39
+ process.stdout.write('{}');
40
+ process.exit(0);
41
+ }
37
42
 
38
- let active;
39
- try {
40
- active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
41
- } catch {
42
- process.stdout.write('{}');
43
- process.exit(0);
43
+ let active;
44
+ try {
45
+ active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
46
+ } catch {
47
+ process.stdout.write('{}');
48
+ process.exit(0);
49
+ }
50
+ slug = active.slug;
44
51
  }
45
-
46
- const slug = active.slug;
47
52
  // Reject non-kebab / traversal slugs: the runtime writes status.json and
48
53
  // metrics.json under tasks/<slug>, so an unchecked slug could escape the tree.
49
54
  const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -841,7 +846,7 @@ function finishActiveAttempt(forced) {
841
846
  const resolved = forced || resolvedAttempt(); if (!resolved) return null;
842
847
  const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
843
848
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
844
- 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 });
849
+ 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 } : {}) });
845
850
  const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
846
851
  }
847
852
  function missingConsumerArtifacts() {
@@ -92,7 +92,7 @@ Each producing agent runs a **pre-receipt self-review** of its own output — go
92
92
 
93
93
  - **Context loss vs excess/noise.** *Loss* = a dropped/misattributed AC or constraint, a stale plan vs the current request, a forgotten prior decision. *Excess/noise* = irrelevant/tangent reads, scope creep beyond the frame, duplicated or bloated artifacts, chat state that belongs on disk.
94
94
  - **Re-anchor.** On detected drift, return the run to the framed task: 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). Re-anchor is a **trigger source of the existing `plan-graph` `replan`** — no second orchestrator, no `status.json`/`metrics.json` field.
95
- - **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional loop. 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`.
95
+ - **Recording & ratchet.** The producer writes a `## Self-review` block in the artifact it owns; the correction lives only in `.memlog.md` (hook-only lifecycle preserved). No self-review, context-health pass, or re-anchor for `bounded`/`spike` tasks (or the `light` profile) — ratchet up for `standard`/`architectural`, never down past a required verification gate. See the requestable `quality/self-review-and-context-hygiene` contract — including the optional loop. 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.
96
96
 
97
97
  - **Goal before execution.** During slug bootstrap, write `.ai.local/team/tasks/<slug>/goal.md` (`Goal`, `User value`, `Success criteria`, `Non-goals`, Derived from `prompt.md`). The goal is a formulated outcome. Do not copy the prompt into it. Show `goal.md` with the plan table before `steps[0]`. An implementer does not start when `goal.md` is missing. A goal change is a `planRevision` plus a new confirmation. Bounded, spike, and `light` still write the thin frame. See **agent-artifact-contracts** § Goal artifact.
98
98
  - **Outcome and review ledger.** Append a `review-ledger.md` row when a self-review defect changes the output. `code-reviewer` appends each finding. Append a user or other-agent objection from `prompt-log.md` or `/task-continue`. `fixed` is `fair: yes`; `rejected` is `fair: no` and cites the rebuttal; `open` at close is `fair: yes`. On a terminal pipeline state, write `outcome.md` (`goalAchieved`, `value`, per-criterion evidence, `reviewCounts`) before the closing user message. `satisfactory` requires every success criterion evidenced and no open fair row. `unsatisfactory` does not reopen the task. When the ledger has a `fair: yes` row, append one signal per distinct signature with `node .ai.local/scripts/signals.mjs --append '<json>'` and run `node .ai.local/scripts/run.mjs` once. Preset-prose targets stay staged for `/technical-retro`. See **agent-artifact-contracts** § Outcome artifact and § Review ledger.
@@ -39,7 +39,7 @@ Before you run the project gate and write the terminal validation receipt, self-
39
39
 
40
40
  **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.
41
41
 
42
- 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).
42
+ 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).
43
43
 
44
44
  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.
45
45
 
@@ -68,7 +68,7 @@ Before you emit the terminal implementation receipt (per wave for multi-wave wor
68
68
 
69
69
  **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.
70
70
 
71
- 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).
71
+ 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).
72
72
 
73
73
  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.
74
74
 
@@ -49,7 +49,7 @@ Before you emit the terminal analysis receipt, self-audit the goal frame and dec
49
49
 
50
50
  **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.
51
51
 
52
- Record a `## Self-review` block in `brief.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).
52
+ Record a `## Self-review` block in `brief.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).
53
53
 
54
54
  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.
55
55
 
@@ -30,22 +30,27 @@ if (hookInput.status !== 'completed') {
30
30
  process.exit(0);
31
31
  }
32
32
 
33
- const activePath = path.join(TEAM_ROOT, 'active-task.json');
34
-
35
- if (!fs.existsSync(activePath)) {
36
- process.stdout.write('{}');
37
- process.exit(0);
38
- }
33
+ // The orchestrator passes TEAM_TASK_SLUG on every hook call. The single-slot
34
+ // active-task.json pointer is a fallback for the UI and older hosts; parallel
35
+ // sessions otherwise overwrite it and silently no-op each other's hooks.
36
+ let slug = process.env.TEAM_TASK_SLUG;
37
+ if (!slug) {
38
+ const activePath = path.join(TEAM_ROOT, 'active-task.json');
39
+
40
+ if (!fs.existsSync(activePath)) {
41
+ process.stdout.write('{}');
42
+ process.exit(0);
43
+ }
39
44
 
40
- let active;
41
- try {
42
- active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
43
- } catch {
44
- process.stdout.write('{}');
45
- process.exit(0);
45
+ let active;
46
+ try {
47
+ active = JSON.parse(fs.readFileSync(activePath, 'utf8'));
48
+ } catch {
49
+ process.stdout.write('{}');
50
+ process.exit(0);
51
+ }
52
+ slug = active.slug;
46
53
  }
47
-
48
- const slug = active.slug;
49
54
  // Reject non-kebab / traversal slugs: the runtime writes status.json and
50
55
  // metrics.json under tasks/<slug>, so an unchecked slug could escape the tree.
51
56
  const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
@@ -829,7 +834,7 @@ function finishActiveAttempt(forced) {
829
834
  const resolved = forced || resolvedAttempt(); if (!resolved) return null;
830
835
  const durationMs = Date.parse(now) - Date.parse(resolved.entry.startedAt);
831
836
  const outcome = ['completed', 'blocked', 'changes_requested', 'validation_failed'].includes(status.state) ? status.state : 'unknown';
832
- 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 });
837
+ 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 } : {}) });
833
838
  const active = { ...(status.activeAttempts || {}) }; delete active[resolved.attemptId]; status.activeAttempts = active; status.lastCompletedAttempt = { attemptId: resolved.attemptId, completedAt: now }; return { ...resolved, outcome };
834
839
  }
835
840
  function missingConsumerArtifacts() {