@bonesofspring/ai-rules 0.2.57 → 0.2.60

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 (289) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +41 -3
  3. package/bin/cli.js +399 -27
  4. package/bin/lib/engine-scripts.js +3 -0
  5. package/bin/lib/mcp/catalog.js +97 -0
  6. package/bin/lib/mcp/clients.js +35 -2
  7. package/bin/lib/mcp/credentials.js +85 -1
  8. package/bin/lib/mcp/doctor.js +93 -17
  9. package/bin/lib/mcp/registry.js +10 -4
  10. package/bin/lib/seed-ai-local-team.js +8 -5
  11. package/docs/MCP-CATALOG.md +56 -0
  12. package/docs/MCP-SETUP.md +38 -6
  13. package/docs/PRESET-CONTRIBUTION.md +1 -0
  14. package/mcp/github-proxy.mjs +133 -0
  15. package/mcp/lib/github.mjs +187 -0
  16. package/mcp/lib/streamable-http.mjs +185 -0
  17. package/mcp/lib/yandex.mjs +16 -137
  18. package/package.json +3 -1
  19. package/presets/_shared/ai-local/scripts/check-write-scope.mjs +212 -0
  20. package/presets/_shared/ai-local/scripts/rule-improver.mjs +343 -50
  21. package/presets/_shared/ai-local/scripts/run.mjs +122 -3
  22. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +12 -0
  23. package/presets/_shared/core/review/code-review-mr.md +10 -0
  24. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +143 -1
  25. package/presets/claude/android-kotlin/commands/update.md +1 -0
  26. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +143 -1
  27. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  28. package/presets/claude/android-kotlin/rules/tooling-and-review/code-review.md +10 -0
  29. package/presets/claude/go/commands/update.md +1 -0
  30. package/presets/claude/go/hooks/chain-team-phases.sh +143 -1
  31. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  32. package/presets/claude/go/rules/tooling-and-review/code-review.md +10 -0
  33. package/presets/claude/ios-swift/commands/update.md +1 -0
  34. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +143 -1
  35. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  36. package/presets/claude/ios-swift/rules/tooling-and-review/code-review.md +10 -0
  37. package/presets/claude/java/commands/update.md +1 -0
  38. package/presets/claude/java/hooks/chain-team-phases.sh +143 -1
  39. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  40. package/presets/claude/java/rules/tooling-and-review/code-review.md +10 -0
  41. package/presets/claude/mcp-ts/commands/update.md +1 -0
  42. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +143 -1
  43. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  44. package/presets/claude/mcp-ts/rules/tooling-and-review/code-review.md +10 -0
  45. package/presets/claude/mol/commands/update.md +1 -0
  46. package/presets/claude/mol/hooks/chain-team-phases.sh +143 -1
  47. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  48. package/presets/claude/mol/rules/tooling-and-review/code-review-mr.md +10 -0
  49. package/presets/claude/next/agents/build-verifier.md +2 -0
  50. package/presets/claude/next/agents/code-reviewer.md +8 -0
  51. package/presets/claude/next/commands/task-continue.md +3 -1
  52. package/presets/claude/next/commands/update.md +1 -0
  53. package/presets/claude/next/hooks/chain-team-phases.sh +143 -1
  54. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  55. package/presets/claude/next/rules/tooling-and-review/code-review-mr.md +10 -0
  56. package/presets/claude/nuxt/commands/update.md +1 -0
  57. package/presets/claude/nuxt/hooks/chain-team-phases.sh +143 -1
  58. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  59. package/presets/claude/nuxt/rules/tooling-and-review/code-review-mr.md +10 -0
  60. package/presets/claude/php-hexagonal/commands/update.md +1 -0
  61. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  62. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  63. package/presets/claude/php-hexagonal/rules/tooling-and-review/code-review.md +10 -0
  64. package/presets/claude/php-laravel/commands/update.md +1 -0
  65. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +143 -1
  66. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  67. package/presets/claude/php-laravel/rules/tooling-and-review/code-review.md +10 -0
  68. package/presets/claude/svelte/commands/update.md +1 -0
  69. package/presets/claude/svelte/hooks/chain-team-phases.sh +143 -1
  70. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  71. package/presets/claude/svelte/rules/tooling-and-review/code-review-mr.md +10 -0
  72. package/presets/cursor/android-kotlin/commands/update.md +1 -0
  73. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +143 -1
  74. package/presets/cursor/android-kotlin/rules/code-review-mr.mdc +10 -0
  75. package/presets/cursor/go/commands/update.md +1 -0
  76. package/presets/cursor/go/hooks/chain-team-phases.sh +143 -1
  77. package/presets/cursor/go/rules/code-review-mr.mdc +10 -0
  78. package/presets/cursor/ios-swift/commands/update.md +1 -0
  79. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +143 -1
  80. package/presets/cursor/ios-swift/rules/code-review-mr.mdc +10 -0
  81. package/presets/cursor/java/commands/update.md +1 -0
  82. package/presets/cursor/java/hooks/chain-team-phases.sh +143 -1
  83. package/presets/cursor/java/rules/code-review-mr.mdc +10 -0
  84. package/presets/cursor/mcp-ts/commands/update.md +1 -0
  85. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +143 -1
  86. package/presets/cursor/mcp-ts/rules/code-review-mr.mdc +10 -0
  87. package/presets/cursor/mol/MCP.md +4 -3
  88. package/presets/cursor/mol/commands/update.md +1 -0
  89. package/presets/cursor/mol/hooks/chain-team-phases.sh +143 -1
  90. package/presets/cursor/mol/rules/code-review-mr.mdc +10 -0
  91. package/presets/cursor/next/MCP.md +4 -3
  92. package/presets/cursor/next/agents/build-verifier.md +2 -0
  93. package/presets/cursor/next/agents/code-reviewer.md +8 -0
  94. package/presets/cursor/next/commands/task-continue.md +3 -1
  95. package/presets/cursor/next/commands/update.md +1 -0
  96. package/presets/cursor/next/hooks/chain-team-phases.sh +143 -1
  97. package/presets/cursor/next/rules/code-review-mr.mdc +10 -0
  98. package/presets/cursor/nuxt/commands/update.md +1 -0
  99. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +143 -1
  100. package/presets/cursor/nuxt/rules/code-review-mr.mdc +10 -0
  101. package/presets/cursor/php-hexagonal/commands/update.md +1 -0
  102. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  103. package/presets/cursor/php-hexagonal/rules/code-review-mr.mdc +10 -0
  104. package/presets/cursor/php-laravel/commands/update.md +1 -0
  105. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +143 -1
  106. package/presets/cursor/php-laravel/rules/code-review-mr.mdc +10 -0
  107. package/presets/cursor/svelte/commands/update.md +1 -0
  108. package/presets/cursor/svelte/hooks/chain-team-phases.sh +143 -1
  109. package/presets/cursor/svelte/rules/code-review-mr.mdc +10 -0
  110. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  111. package/presets/mavis/android-kotlin/commands/update.md +1 -0
  112. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +143 -1
  113. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  114. package/presets/mavis/android-kotlin/rules/code-review-mr.md +10 -0
  115. package/presets/mavis/go/adapter-map.json +1 -1
  116. package/presets/mavis/go/commands/update.md +1 -0
  117. package/presets/mavis/go/hooks/chain-team-phases.sh +143 -1
  118. package/presets/mavis/go/rules/agent-team-orchestrator.md +12 -0
  119. package/presets/mavis/go/rules/code-review-mr.md +10 -0
  120. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  121. package/presets/mavis/ios-swift/commands/update.md +1 -0
  122. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +143 -1
  123. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +12 -0
  124. package/presets/mavis/ios-swift/rules/code-review-mr.md +10 -0
  125. package/presets/mavis/java/adapter-map.json +1 -1
  126. package/presets/mavis/java/commands/update.md +1 -0
  127. package/presets/mavis/java/hooks/chain-team-phases.sh +143 -1
  128. package/presets/mavis/java/rules/agent-team-orchestrator.md +12 -0
  129. package/presets/mavis/java/rules/code-review-mr.md +10 -0
  130. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  131. package/presets/mavis/mcp-ts/commands/update.md +1 -0
  132. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +143 -1
  133. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  134. package/presets/mavis/mcp-ts/rules/code-review-mr.md +10 -0
  135. package/presets/mavis/mol/MCP.md +4 -3
  136. package/presets/mavis/mol/adapter-map.json +1 -1
  137. package/presets/mavis/mol/commands/update.md +1 -0
  138. package/presets/mavis/mol/hooks/chain-team-phases.sh +143 -1
  139. package/presets/mavis/mol/rules/agent-team-orchestrator.md +12 -0
  140. package/presets/mavis/mol/rules/code-review-mr.md +10 -0
  141. package/presets/mavis/next/MCP.md +4 -3
  142. package/presets/mavis/next/adapter-map.json +1 -1
  143. package/presets/mavis/next/agents/build-verifier.md +2 -0
  144. package/presets/mavis/next/agents/code-reviewer.md +8 -0
  145. package/presets/mavis/next/commands/task-continue.md +3 -1
  146. package/presets/mavis/next/commands/update.md +1 -0
  147. package/presets/mavis/next/hooks/chain-team-phases.sh +143 -1
  148. package/presets/mavis/next/rules/agent-team-orchestrator.md +12 -0
  149. package/presets/mavis/next/rules/code-review-mr.md +10 -0
  150. package/presets/mavis/nuxt/adapter-map.json +1 -1
  151. package/presets/mavis/nuxt/commands/update.md +1 -0
  152. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +143 -1
  153. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +12 -0
  154. package/presets/mavis/nuxt/rules/code-review-mr.md +10 -0
  155. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  156. package/presets/mavis/php-hexagonal/commands/update.md +1 -0
  157. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  158. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  159. package/presets/mavis/php-hexagonal/rules/code-review-mr.md +10 -0
  160. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  161. package/presets/mavis/php-laravel/commands/update.md +1 -0
  162. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +143 -1
  163. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +12 -0
  164. package/presets/mavis/php-laravel/rules/code-review-mr.md +10 -0
  165. package/presets/mavis/svelte/adapter-map.json +1 -1
  166. package/presets/mavis/svelte/commands/update.md +1 -0
  167. package/presets/mavis/svelte/hooks/chain-team-phases.sh +143 -1
  168. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +12 -0
  169. package/presets/mavis/svelte/rules/code-review-mr.md +10 -0
  170. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  171. package/presets/opencode/android-kotlin/commands/update.md +1 -0
  172. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +143 -1
  173. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  174. package/presets/opencode/android-kotlin/rules/code-review-mr.md +10 -0
  175. package/presets/opencode/go/adapter-map.json +1 -1
  176. package/presets/opencode/go/commands/update.md +1 -0
  177. package/presets/opencode/go/hooks/chain-team-phases.sh +143 -1
  178. package/presets/opencode/go/rules/agent-team-orchestrator.md +12 -0
  179. package/presets/opencode/go/rules/code-review-mr.md +10 -0
  180. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  181. package/presets/opencode/ios-swift/commands/update.md +1 -0
  182. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +143 -1
  183. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +12 -0
  184. package/presets/opencode/ios-swift/rules/code-review-mr.md +10 -0
  185. package/presets/opencode/java/adapter-map.json +1 -1
  186. package/presets/opencode/java/commands/update.md +1 -0
  187. package/presets/opencode/java/hooks/chain-team-phases.sh +143 -1
  188. package/presets/opencode/java/rules/agent-team-orchestrator.md +12 -0
  189. package/presets/opencode/java/rules/code-review-mr.md +10 -0
  190. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  191. package/presets/opencode/mcp-ts/commands/update.md +1 -0
  192. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +143 -1
  193. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  194. package/presets/opencode/mcp-ts/rules/code-review-mr.md +10 -0
  195. package/presets/opencode/mol/MCP.md +4 -3
  196. package/presets/opencode/mol/adapter-map.json +1 -1
  197. package/presets/opencode/mol/commands/update.md +1 -0
  198. package/presets/opencode/mol/hooks/chain-team-phases.sh +143 -1
  199. package/presets/opencode/mol/rules/agent-team-orchestrator.md +12 -0
  200. package/presets/opencode/mol/rules/code-review-mr.md +10 -0
  201. package/presets/opencode/next/MCP.md +4 -3
  202. package/presets/opencode/next/adapter-map.json +1 -1
  203. package/presets/opencode/next/agents/build-verifier.md +2 -0
  204. package/presets/opencode/next/agents/code-reviewer.md +8 -0
  205. package/presets/opencode/next/commands/task-continue.md +3 -1
  206. package/presets/opencode/next/commands/update.md +1 -0
  207. package/presets/opencode/next/hooks/chain-team-phases.sh +143 -1
  208. package/presets/opencode/next/rules/agent-team-orchestrator.md +12 -0
  209. package/presets/opencode/next/rules/code-review-mr.md +10 -0
  210. package/presets/opencode/nuxt/adapter-map.json +1 -1
  211. package/presets/opencode/nuxt/commands/update.md +1 -0
  212. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +143 -1
  213. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +12 -0
  214. package/presets/opencode/nuxt/rules/code-review-mr.md +10 -0
  215. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  216. package/presets/opencode/php-hexagonal/commands/update.md +1 -0
  217. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  218. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  219. package/presets/opencode/php-hexagonal/rules/code-review-mr.md +10 -0
  220. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  221. package/presets/opencode/php-laravel/commands/update.md +1 -0
  222. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +143 -1
  223. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +12 -0
  224. package/presets/opencode/php-laravel/rules/code-review-mr.md +10 -0
  225. package/presets/opencode/svelte/adapter-map.json +1 -1
  226. package/presets/opencode/svelte/commands/update.md +1 -0
  227. package/presets/opencode/svelte/hooks/chain-team-phases.sh +143 -1
  228. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +12 -0
  229. package/presets/opencode/svelte/rules/code-review-mr.md +10 -0
  230. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  231. package/presets/zcode/android-kotlin/commands/update.md +1 -0
  232. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +143 -1
  233. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  234. package/presets/zcode/android-kotlin/rules/code-review-mr.md +10 -0
  235. package/presets/zcode/go/adapter-map.json +1 -1
  236. package/presets/zcode/go/commands/update.md +1 -0
  237. package/presets/zcode/go/hooks/chain-team-phases.sh +143 -1
  238. package/presets/zcode/go/rules/agent-team-orchestrator.md +12 -0
  239. package/presets/zcode/go/rules/code-review-mr.md +10 -0
  240. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  241. package/presets/zcode/ios-swift/commands/update.md +1 -0
  242. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +143 -1
  243. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +12 -0
  244. package/presets/zcode/ios-swift/rules/code-review-mr.md +10 -0
  245. package/presets/zcode/java/adapter-map.json +1 -1
  246. package/presets/zcode/java/commands/update.md +1 -0
  247. package/presets/zcode/java/hooks/chain-team-phases.sh +143 -1
  248. package/presets/zcode/java/rules/agent-team-orchestrator.md +12 -0
  249. package/presets/zcode/java/rules/code-review-mr.md +10 -0
  250. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  251. package/presets/zcode/mcp-ts/commands/update.md +1 -0
  252. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +143 -1
  253. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  254. package/presets/zcode/mcp-ts/rules/code-review-mr.md +10 -0
  255. package/presets/zcode/mol/MCP.md +4 -3
  256. package/presets/zcode/mol/adapter-map.json +1 -1
  257. package/presets/zcode/mol/commands/update.md +1 -0
  258. package/presets/zcode/mol/hooks/chain-team-phases.sh +143 -1
  259. package/presets/zcode/mol/rules/agent-team-orchestrator.md +12 -0
  260. package/presets/zcode/mol/rules/code-review-mr.md +10 -0
  261. package/presets/zcode/next/MCP.md +4 -3
  262. package/presets/zcode/next/adapter-map.json +1 -1
  263. package/presets/zcode/next/agents/build-verifier.md +2 -0
  264. package/presets/zcode/next/agents/code-reviewer.md +8 -0
  265. package/presets/zcode/next/commands/task-continue.md +3 -1
  266. package/presets/zcode/next/commands/update.md +1 -0
  267. package/presets/zcode/next/hooks/chain-team-phases.sh +143 -1
  268. package/presets/zcode/next/rules/agent-team-orchestrator.md +12 -0
  269. package/presets/zcode/next/rules/code-review-mr.md +10 -0
  270. package/presets/zcode/nuxt/adapter-map.json +1 -1
  271. package/presets/zcode/nuxt/commands/update.md +1 -0
  272. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +143 -1
  273. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +12 -0
  274. package/presets/zcode/nuxt/rules/code-review-mr.md +10 -0
  275. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  276. package/presets/zcode/php-hexagonal/commands/update.md +1 -0
  277. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  278. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  279. package/presets/zcode/php-hexagonal/rules/code-review-mr.md +10 -0
  280. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  281. package/presets/zcode/php-laravel/commands/update.md +1 -0
  282. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +143 -1
  283. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +12 -0
  284. package/presets/zcode/php-laravel/rules/code-review-mr.md +10 -0
  285. package/presets/zcode/svelte/adapter-map.json +1 -1
  286. package/presets/zcode/svelte/commands/update.md +1 -0
  287. package/presets/zcode/svelte/hooks/chain-team-phases.sh +143 -1
  288. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +12 -0
  289. package/presets/zcode/svelte/rules/code-review-mr.md +10 -0
@@ -228,15 +228,94 @@ const DEFAULT_ARTIFACT_OUTPUT_IDS = {
228
228
  // table in agent-artifact-contracts.md. A receipt outcome is not a status.
229
229
  const ARTIFACT_STATUSES = ['planned', 'in_progress', 'completed', 'blocked', 'superseded'];
230
230
  const RECEIPT_OUTCOME_STATUS = { completed: 'completed', blocked: 'blocked', changes_requested: 'blocked', validation_failed: 'blocked' };
231
+ const TERMINAL_RECEIPT_OUTCOMES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
232
+ // A dead producer is reclaimed only after this conservative age with no
233
+ // terminal manifest receipt. The override is milliseconds; an invalid,
234
+ // non-positive, or sub-floor value falls back to the default rather than
235
+ // reclaiming immediately or disabling the safety net.
236
+ const DEFAULT_ATTEMPT_STALE_MS = 60 * 60 * 1000;
237
+ const MIN_ATTEMPT_STALE_MS = 60 * 1000;
238
+ function attemptStaleMs() {
239
+ const raw = process.env.AI_RULES_ATTEMPT_STALE_MS;
240
+ if (typeof raw !== 'string' || raw.trim() === '') return DEFAULT_ATTEMPT_STALE_MS;
241
+ const value = Number(raw);
242
+ return Number.isFinite(value) && value >= MIN_ATTEMPT_STALE_MS ? value : DEFAULT_ATTEMPT_STALE_MS;
243
+ }
244
+ function hasTerminalReceipt(attemptId, entry) {
245
+ const manifestPath = path.join(taskDir, 'artifact-manifest.json');
246
+ if (!fs.existsSync(manifestPath)) return false;
247
+ try {
248
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
249
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
250
+ const step = Array.isArray(steps) ? steps[entry.stepIndex] : null;
251
+ const outputId = step ? artifactOutputIdFor(step, entry.agent) : entry.agent;
252
+ const startedAt = Date.parse(entry.startedAt);
253
+ return artifacts.some((artifact) => {
254
+ if (!artifact || !artifact.receipt || !TERMINAL_RECEIPT_OUTCOMES.has(artifact.receipt.outcome)) return false;
255
+ if (artifact.receipt.attemptId === attemptId) return true;
256
+ if (artifact.receipt.attemptId != null || artifact.id !== outputId) return false;
257
+ // A legacy receipt without an attemptId still proves the producer finished.
258
+ const terminalAt = Date.parse(artifact.timestamps?.completedAt || artifact.timestamps?.updatedAt || '');
259
+ return !Number.isFinite(terminalAt) || !Number.isFinite(startedAt) || terminalAt >= startedAt;
260
+ });
261
+ } catch {
262
+ return false;
263
+ }
264
+ }
265
+ // P4: a killed producer leaves its attempt in `activeAttempts` forever. Reclaim
266
+ // only an entry for the step being activated (or a sibling in the same parallel
267
+ // group) past the threshold with no terminal receipt; a live attempt of another
268
+ // step is left for that step's own activation. Keep the audit row in metrics as
269
+ // `outcome: "stale"`. Idempotent: the entry leaves the object.
270
+ function reclaimStaleAttempts(scope) {
271
+ const active = { ...(status.activeAttempts || {}) };
272
+ const threshold = attemptStaleMs();
273
+ const at = Date.parse(now);
274
+ const agents = Array.isArray(scope?.agents) ? scope.agents : [];
275
+ const stepIndex = scope?.stepIndex;
276
+ const parallelGroupId = scope?.parallelGroupId || null;
277
+ const belongsToActivation = (entry) => {
278
+ if (!entry || typeof entry !== 'object') return false;
279
+ if (parallelGroupId && entry.parallelGroupId === parallelGroupId) return true;
280
+ return Number.isInteger(stepIndex) && entry.stepIndex === stepIndex && agents.includes(entry.agent);
281
+ };
282
+ for (const attemptId of Object.keys(active)) {
283
+ const entry = active[attemptId];
284
+ if (!belongsToActivation(entry)) continue;
285
+ const startedAt = Date.parse(entry.startedAt);
286
+ if (!Number.isFinite(startedAt) || !Number.isFinite(at)) continue;
287
+ const ageMs = at - startedAt;
288
+ if (ageMs <= threshold) continue;
289
+ if (hasTerminalReceipt(attemptId, entry)) continue;
290
+ delete active[attemptId];
291
+ appendMetric({
292
+ type: 'attempt_finished',
293
+ at: now,
294
+ attemptId,
295
+ stepIndex: entry.stepIndex,
296
+ stepLabel: (Array.isArray(steps) && steps[entry.stepIndex] && steps[entry.stepIndex].label) || null,
297
+ agent: entry.agent,
298
+ role: roleFor(entry.agent),
299
+ outcome: 'stale',
300
+ durationMs: ageMs,
301
+ retryAfterFix: status.retryAfterFix || null,
302
+ source: 'hook',
303
+ attributionConfidence: 'high',
304
+ });
305
+ process.stderr.write(`WARNING: ${slug}: reclaimed stale attempt ${attemptId} (agent ${entry.agent}, started ${entry.startedAt}, no terminal receipt after ${Math.round(ageMs / 60000)} min). A new attempt may start.\n`);
306
+ }
307
+ status.activeAttempts = active;
308
+ }
231
309
  function artifactOutputIdFor(step, agent) {
232
310
  if (step && typeof step.artifactOutputId === 'string') return step.artifactOutputId;
233
311
  if (step?.artifactOutputIds && typeof step.artifactOutputIds[agent] === 'string') return step.artifactOutputIds[agent];
234
312
  return DEFAULT_ARTIFACT_OUTPUT_IDS[agent] || agent;
235
313
  }
236
314
  function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null) {
237
- const active = { ...(status.activeAttempts || {}) };
238
315
  const agents = Array.isArray(agentsOverride) && agentsOverride.length > 0 ? agentsOverride : getStepAgents(step);
239
316
  const parallelGroupId = step.parallel && getStepAgents(step).length > 1 ? `${status.metricsRunId || slug}:step-${stepIndex}` : null;
317
+ reclaimStaleAttempts({ stepIndex, agents, parallelGroupId });
318
+ const active = { ...(status.activeAttempts || {}) };
240
319
  for (const agent of agents) {
241
320
  const attempt = nextAttemptOrdinal(stepIndex, agent); const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
242
321
  status.metricsRunId = runId; const attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
@@ -1238,6 +1317,57 @@ function writeStatus(next) {
1238
1317
  writeFocusDigest();
1239
1318
  }
1240
1319
 
1320
+ // P1: the operator pause is a file sentinel, not a status field an agent may
1321
+ // write. It blocks NEW steps only: the completing receipt is reconciled and the
1322
+ // attempt is finished before this check runs. An empty or unreadable file still
1323
+ // counts as engaged (fail safe).
1324
+ const PAUSE_SENTINELS = [
1325
+ path.join(process.cwd(), '.ai.local', 'STOP'),
1326
+ path.join(process.cwd(), '.ai.local', 'ESTOP'),
1327
+ ];
1328
+ function readPauseSentinel() {
1329
+ for (const file of PAUSE_SENTINELS) {
1330
+ let stat = null;
1331
+ try { stat = fs.statSync(file); } catch (error) {
1332
+ if (error && error.code === 'ENOENT') continue;
1333
+ // A permission or I/O error is not proof of absence: fail safe and say so.
1334
+ process.stderr.write(`WARNING: ${slug}: cannot stat pause sentinel ${path.relative(process.cwd(), file).split(path.sep).join('/')} (${error && error.message ? error.message : String(error)}); treating it as engaged.\n`);
1335
+ return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), reason: 'sentinel stat failed' };
1336
+ }
1337
+ if (!stat || !stat.isFile()) continue;
1338
+ let reason = '';
1339
+ try {
1340
+ const raw = fs.readFileSync(file, 'utf8').trim();
1341
+ if (raw) {
1342
+ try {
1343
+ const parsed = JSON.parse(raw);
1344
+ reason = parsed && typeof parsed.reason === 'string' ? parsed.reason : raw;
1345
+ } catch {
1346
+ reason = raw;
1347
+ }
1348
+ }
1349
+ } catch { /* unreadable sentinel still counts as engaged */ }
1350
+ return {
1351
+ engaged: true,
1352
+ file: path.relative(process.cwd(), file).split(path.sep).join('/'),
1353
+ reason: reason.replace(/\s+/g, ' ').slice(0, 160),
1354
+ };
1355
+ }
1356
+ return { engaged: false, file: null, reason: '' };
1357
+ }
1358
+ function pausedNotice(pause) {
1359
+ const where = pause && pause.file ? pause.file : '.ai.local/STOP';
1360
+ const because = pause && pause.reason ? ` (${pause.reason})` : '';
1361
+ return `[chain-team-phases] ${slug}: paused — operator sentinel ${where} is engaged${because}. No step advanced and no handoff was emitted. Remove the sentinel and run /task-continue ${slug}.`;
1362
+ }
1363
+ function pauseBlocksAdvance() {
1364
+ const pause = readPauseSentinel();
1365
+ if (!pause.engaged) return null;
1366
+ writeStatus({ state: 'paused', phase: 'paused' });
1367
+ out(pausedNotice(pause));
1368
+ return pause;
1369
+ }
1370
+
1241
1371
  function out(message) {
1242
1372
  process.stdout.write(JSON.stringify({ followup_message: message }));
1243
1373
  }
@@ -1869,6 +1999,7 @@ function legacyFlow() {
1869
1999
 
1870
2000
 
1871
2001
  if (hookInput.action === 'end_human_gate') {
2002
+ if (pauseBlocksAdvance()) process.exit(0);
1872
2003
  // Only advance when a gate was actually open. A duplicate or retried
1873
2004
  // end_human_gate must be a no-op, not a silent pipeline skip.
1874
2005
  const gateWasOpen = Boolean(status.activeHumanGateEventId) || status.awaitingHumanGate === true;
@@ -1978,6 +2109,7 @@ if (hookInput.action === 'end_human_gate') {
1978
2109
  }
1979
2110
 
1980
2111
  if (!fs.existsSync(pipelinePath)) {
2112
+ if (pauseBlocksAdvance()) process.exit(0);
1981
2113
  legacyFlow();
1982
2114
  }
1983
2115
 
@@ -2034,11 +2166,21 @@ const reconcilingAttempt = resolvedAttempt();
2034
2166
  const wasWaitingForReceipt = status.state === 'awaiting_artifact_receipt';
2035
2167
  reconcileStatusFromManifest(completingAgentHint, initialStep, reconcilingAttempt);
2036
2168
  if (status.state === 'awaiting_artifact_receipt') {
2169
+ const pause = readPauseSentinel();
2170
+ if (pause.engaged) {
2171
+ if (artifactStallMessage) process.stderr.write(artifactStallMessage + '\n');
2172
+ writeStatus({ state: 'paused', phase: 'paused' });
2173
+ out(pausedNotice(pause));
2174
+ process.exit(0);
2175
+ }
2037
2176
  writeStatus({});
2038
2177
  emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
2039
2178
  process.exit(0);
2040
2179
  }
2041
2180
  let finishedAttempt = finishActiveAttempt();
2181
+ // The just-finished attempt's metric is already written; a pause now blocks
2182
+ // every handoff, including the unattributable-stop repair path below.
2183
+ if (pauseBlocksAdvance()) process.exit(0);
2042
2184
  if (!finishedAttempt && activeAttemptCountBeforeFinish > 0) {
2043
2185
  if (!hookInput.attemptId) {
2044
2186
  const repaired = repairUnattributableStop();
@@ -37,6 +37,7 @@ A diff-shaped read is a floor, not a review. Run these five passes on every non-
37
37
  - **`finding`** — reported like any other finding, with `path:line`.
38
38
  - **`no finding`** — with one line of evidence: what was searched or read.
39
39
  - **`unable to run`** — with the reason: the pass does not apply to this diff, or an input is missing.
40
+ - **`partial`** — the breadth budget stopped the pass; name every unread path or glob. Use it only on the call-site sweep.
40
41
 
41
42
  An outcome word alone is not a record: `no finding` without its evidence line, or `unable to run` without its reason, is an unfinished pass.
42
43
 
@@ -46,6 +47,15 @@ An outcome word alone is not a record: `no finding` without its evidence line, o
46
47
  4. **Test gap** — not "is there a test" but "which behaviour change would still pass every existing test". That gap is the finding.
47
48
  5. **Half-life** — what breaks in six months: hidden coupling, implicit contract, missing migration, an unowned copy of the same rule.
48
49
 
50
+ ## Review breadth budget
51
+
52
+ - Bound **breadth**, not depth: the call-site sweep and the one-hop consumer read stop at this budget. The five depth passes still run on what was read.
53
+ - Budget: the changed exports, types, routes, and events in the diff, plus one hop of their consumers. Read no consumer that neither the diff nor a recorded finding names.
54
+ - Stop when either limit is reached: 40 changed-symbol call sites, or 15 minutes of breadth reads on one review.
55
+ - When the budget is exhausted, stop the sweep and record `partial` in `## Depth passes` for the call-site sweep, with every unread path or glob named inline.
56
+ - Never claim full coverage after a `partial` row. The verdict follows the findings actually recorded.
57
+ - A deliberate overrun (frozen contract, security boundary, migration) states the limit exceeded in one line; do not extend the budget silently.
58
+
49
59
  ## Constraints
50
60
 
51
61
  - The diff defines the **change under review**, not the boundary of the review. Follow the change one hop out: call sites, consumers, contracts, migrations, and the tests that already cover the touched path. Do not review unchanged code for its own sake — cite it only as evidence about the change.
@@ -27,6 +27,7 @@ npx @bonesofspring/ai-rules update
27
27
  - `.claude/.ai-rules-install.json`
28
28
  - `.mavis/.ai-rules-install.json`
29
29
  - `.opencode/.ai-rules-install.json`
30
+ - `.zcode/.ai-rules-install.json`
30
31
 
31
32
  `update` reads those files. A tool without that file stays uninstalled. Report the result in the user's native language (`language-policy`).
32
33
 
@@ -227,15 +227,94 @@ const DEFAULT_ARTIFACT_OUTPUT_IDS = {
227
227
  // table in agent-artifact-contracts.md. A receipt outcome is not a status.
228
228
  const ARTIFACT_STATUSES = ['planned', 'in_progress', 'completed', 'blocked', 'superseded'];
229
229
  const RECEIPT_OUTCOME_STATUS = { completed: 'completed', blocked: 'blocked', changes_requested: 'blocked', validation_failed: 'blocked' };
230
+ const TERMINAL_RECEIPT_OUTCOMES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
231
+ // A dead producer is reclaimed only after this conservative age with no
232
+ // terminal manifest receipt. The override is milliseconds; an invalid,
233
+ // non-positive, or sub-floor value falls back to the default rather than
234
+ // reclaiming immediately or disabling the safety net.
235
+ const DEFAULT_ATTEMPT_STALE_MS = 60 * 60 * 1000;
236
+ const MIN_ATTEMPT_STALE_MS = 60 * 1000;
237
+ function attemptStaleMs() {
238
+ const raw = process.env.AI_RULES_ATTEMPT_STALE_MS;
239
+ if (typeof raw !== 'string' || raw.trim() === '') return DEFAULT_ATTEMPT_STALE_MS;
240
+ const value = Number(raw);
241
+ return Number.isFinite(value) && value >= MIN_ATTEMPT_STALE_MS ? value : DEFAULT_ATTEMPT_STALE_MS;
242
+ }
243
+ function hasTerminalReceipt(attemptId, entry) {
244
+ const manifestPath = path.join(taskDir, 'artifact-manifest.json');
245
+ if (!fs.existsSync(manifestPath)) return false;
246
+ try {
247
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
248
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
249
+ const step = Array.isArray(steps) ? steps[entry.stepIndex] : null;
250
+ const outputId = step ? artifactOutputIdFor(step, entry.agent) : entry.agent;
251
+ const startedAt = Date.parse(entry.startedAt);
252
+ return artifacts.some((artifact) => {
253
+ if (!artifact || !artifact.receipt || !TERMINAL_RECEIPT_OUTCOMES.has(artifact.receipt.outcome)) return false;
254
+ if (artifact.receipt.attemptId === attemptId) return true;
255
+ if (artifact.receipt.attemptId != null || artifact.id !== outputId) return false;
256
+ // A legacy receipt without an attemptId still proves the producer finished.
257
+ const terminalAt = Date.parse(artifact.timestamps?.completedAt || artifact.timestamps?.updatedAt || '');
258
+ return !Number.isFinite(terminalAt) || !Number.isFinite(startedAt) || terminalAt >= startedAt;
259
+ });
260
+ } catch {
261
+ return false;
262
+ }
263
+ }
264
+ // P4: a killed producer leaves its attempt in `activeAttempts` forever. Reclaim
265
+ // only an entry for the step being activated (or a sibling in the same parallel
266
+ // group) past the threshold with no terminal receipt; a live attempt of another
267
+ // step is left for that step's own activation. Keep the audit row in metrics as
268
+ // `outcome: "stale"`. Idempotent: the entry leaves the object.
269
+ function reclaimStaleAttempts(scope) {
270
+ const active = { ...(status.activeAttempts || {}) };
271
+ const threshold = attemptStaleMs();
272
+ const at = Date.parse(now);
273
+ const agents = Array.isArray(scope?.agents) ? scope.agents : [];
274
+ const stepIndex = scope?.stepIndex;
275
+ const parallelGroupId = scope?.parallelGroupId || null;
276
+ const belongsToActivation = (entry) => {
277
+ if (!entry || typeof entry !== 'object') return false;
278
+ if (parallelGroupId && entry.parallelGroupId === parallelGroupId) return true;
279
+ return Number.isInteger(stepIndex) && entry.stepIndex === stepIndex && agents.includes(entry.agent);
280
+ };
281
+ for (const attemptId of Object.keys(active)) {
282
+ const entry = active[attemptId];
283
+ if (!belongsToActivation(entry)) continue;
284
+ const startedAt = Date.parse(entry.startedAt);
285
+ if (!Number.isFinite(startedAt) || !Number.isFinite(at)) continue;
286
+ const ageMs = at - startedAt;
287
+ if (ageMs <= threshold) continue;
288
+ if (hasTerminalReceipt(attemptId, entry)) continue;
289
+ delete active[attemptId];
290
+ appendMetric({
291
+ type: 'attempt_finished',
292
+ at: now,
293
+ attemptId,
294
+ stepIndex: entry.stepIndex,
295
+ stepLabel: (Array.isArray(steps) && steps[entry.stepIndex] && steps[entry.stepIndex].label) || null,
296
+ agent: entry.agent,
297
+ role: roleFor(entry.agent),
298
+ outcome: 'stale',
299
+ durationMs: ageMs,
300
+ retryAfterFix: status.retryAfterFix || null,
301
+ source: 'hook',
302
+ attributionConfidence: 'high',
303
+ });
304
+ process.stderr.write(`WARNING: ${slug}: reclaimed stale attempt ${attemptId} (agent ${entry.agent}, started ${entry.startedAt}, no terminal receipt after ${Math.round(ageMs / 60000)} min). A new attempt may start.\n`);
305
+ }
306
+ status.activeAttempts = active;
307
+ }
230
308
  function artifactOutputIdFor(step, agent) {
231
309
  if (step && typeof step.artifactOutputId === 'string') return step.artifactOutputId;
232
310
  if (step?.artifactOutputIds && typeof step.artifactOutputIds[agent] === 'string') return step.artifactOutputIds[agent];
233
311
  return DEFAULT_ARTIFACT_OUTPUT_IDS[agent] || agent;
234
312
  }
235
313
  function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null) {
236
- const active = { ...(status.activeAttempts || {}) };
237
314
  const agents = Array.isArray(agentsOverride) && agentsOverride.length > 0 ? agentsOverride : getStepAgents(step);
238
315
  const parallelGroupId = step.parallel && getStepAgents(step).length > 1 ? `${status.metricsRunId || slug}:step-${stepIndex}` : null;
316
+ reclaimStaleAttempts({ stepIndex, agents, parallelGroupId });
317
+ const active = { ...(status.activeAttempts || {}) };
239
318
  for (const agent of agents) {
240
319
  const attempt = nextAttemptOrdinal(stepIndex, agent); const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
241
320
  status.metricsRunId = runId; const attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
@@ -1237,6 +1316,57 @@ function writeStatus(next) {
1237
1316
  writeFocusDigest();
1238
1317
  }
1239
1318
 
1319
+ // P1: the operator pause is a file sentinel, not a status field an agent may
1320
+ // write. It blocks NEW steps only: the completing receipt is reconciled and the
1321
+ // attempt is finished before this check runs. An empty or unreadable file still
1322
+ // counts as engaged (fail safe).
1323
+ const PAUSE_SENTINELS = [
1324
+ path.join(process.cwd(), '.ai.local', 'STOP'),
1325
+ path.join(process.cwd(), '.ai.local', 'ESTOP'),
1326
+ ];
1327
+ function readPauseSentinel() {
1328
+ for (const file of PAUSE_SENTINELS) {
1329
+ let stat = null;
1330
+ try { stat = fs.statSync(file); } catch (error) {
1331
+ if (error && error.code === 'ENOENT') continue;
1332
+ // A permission or I/O error is not proof of absence: fail safe and say so.
1333
+ process.stderr.write(`WARNING: ${slug}: cannot stat pause sentinel ${path.relative(process.cwd(), file).split(path.sep).join('/')} (${error && error.message ? error.message : String(error)}); treating it as engaged.\n`);
1334
+ return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), reason: 'sentinel stat failed' };
1335
+ }
1336
+ if (!stat || !stat.isFile()) continue;
1337
+ let reason = '';
1338
+ try {
1339
+ const raw = fs.readFileSync(file, 'utf8').trim();
1340
+ if (raw) {
1341
+ try {
1342
+ const parsed = JSON.parse(raw);
1343
+ reason = parsed && typeof parsed.reason === 'string' ? parsed.reason : raw;
1344
+ } catch {
1345
+ reason = raw;
1346
+ }
1347
+ }
1348
+ } catch { /* unreadable sentinel still counts as engaged */ }
1349
+ return {
1350
+ engaged: true,
1351
+ file: path.relative(process.cwd(), file).split(path.sep).join('/'),
1352
+ reason: reason.replace(/\s+/g, ' ').slice(0, 160),
1353
+ };
1354
+ }
1355
+ return { engaged: false, file: null, reason: '' };
1356
+ }
1357
+ function pausedNotice(pause) {
1358
+ const where = pause && pause.file ? pause.file : '.ai.local/STOP';
1359
+ const because = pause && pause.reason ? ` (${pause.reason})` : '';
1360
+ return `[chain-team-phases] ${slug}: paused — operator sentinel ${where} is engaged${because}. No step advanced and no handoff was emitted. Remove the sentinel and run /task-continue ${slug}.`;
1361
+ }
1362
+ function pauseBlocksAdvance() {
1363
+ const pause = readPauseSentinel();
1364
+ if (!pause.engaged) return null;
1365
+ writeStatus({ state: 'paused', phase: 'paused' });
1366
+ out(pausedNotice(pause));
1367
+ return pause;
1368
+ }
1369
+
1240
1370
  function out(message) {
1241
1371
  process.stdout.write(JSON.stringify({ followup_message: message }));
1242
1372
  }
@@ -1864,6 +1994,7 @@ function legacyFlow() {
1864
1994
 
1865
1995
 
1866
1996
  if (hookInput.action === 'end_human_gate') {
1997
+ if (pauseBlocksAdvance()) process.exit(0);
1867
1998
  // Only advance when a gate was actually open. A duplicate or retried
1868
1999
  // end_human_gate must be a no-op, not a silent pipeline skip.
1869
2000
  const gateWasOpen = Boolean(status.activeHumanGateEventId) || status.awaitingHumanGate === true;
@@ -1973,6 +2104,7 @@ if (hookInput.action === 'end_human_gate') {
1973
2104
  }
1974
2105
 
1975
2106
  if (!fs.existsSync(pipelinePath)) {
2107
+ if (pauseBlocksAdvance()) process.exit(0);
1976
2108
  legacyFlow();
1977
2109
  }
1978
2110
 
@@ -2029,11 +2161,21 @@ const reconcilingAttempt = resolvedAttempt();
2029
2161
  const wasWaitingForReceipt = status.state === 'awaiting_artifact_receipt';
2030
2162
  reconcileStatusFromManifest(completingAgentHint, initialStep, reconcilingAttempt);
2031
2163
  if (status.state === 'awaiting_artifact_receipt') {
2164
+ const pause = readPauseSentinel();
2165
+ if (pause.engaged) {
2166
+ if (artifactStallMessage) process.stderr.write(artifactStallMessage + '\n');
2167
+ writeStatus({ state: 'paused', phase: 'paused' });
2168
+ out(pausedNotice(pause));
2169
+ process.exit(0);
2170
+ }
2032
2171
  writeStatus({});
2033
2172
  emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
2034
2173
  process.exit(0);
2035
2174
  }
2036
2175
  let finishedAttempt = finishActiveAttempt();
2176
+ // The just-finished attempt's metric is already written; a pause now blocks
2177
+ // every handoff, including the unattributable-stop repair path below.
2178
+ if (pauseBlocksAdvance()) process.exit(0);
2037
2179
  if (!finishedAttempt && activeAttemptCountBeforeFinish > 0) {
2038
2180
  if (!hookInput.attemptId) {
2039
2181
  const repaired = repairUnattributableStop();
@@ -37,6 +37,7 @@ A diff-shaped read is a floor, not a review. Run these five passes on every non-
37
37
  - **`finding`** — reported like any other finding, with `path:line`.
38
38
  - **`no finding`** — with one line of evidence: what was searched or read.
39
39
  - **`unable to run`** — with the reason: the pass does not apply to this diff, or an input is missing.
40
+ - **`partial`** — the breadth budget stopped the pass; name every unread path or glob. Use it only on the call-site sweep.
40
41
 
41
42
  An outcome word alone is not a record: `no finding` without its evidence line, or `unable to run` without its reason, is an unfinished pass.
42
43
 
@@ -46,6 +47,15 @@ An outcome word alone is not a record: `no finding` without its evidence line, o
46
47
  4. **Test gap** — not "is there a test" but "which behaviour change would still pass every existing test". That gap is the finding.
47
48
  5. **Half-life** — what breaks in six months: hidden coupling, implicit contract, missing migration, an unowned copy of the same rule.
48
49
 
50
+ ## Review breadth budget
51
+
52
+ - Bound **breadth**, not depth: the call-site sweep and the one-hop consumer read stop at this budget. The five depth passes still run on what was read.
53
+ - Budget: the changed exports, types, routes, and events in the diff, plus one hop of their consumers. Read no consumer that neither the diff nor a recorded finding names.
54
+ - Stop when either limit is reached: 40 changed-symbol call sites, or 15 minutes of breadth reads on one review.
55
+ - When the budget is exhausted, stop the sweep and record `partial` in `## Depth passes` for the call-site sweep, with every unread path or glob named inline.
56
+ - Never claim full coverage after a `partial` row. The verdict follows the findings actually recorded.
57
+ - A deliberate overrun (frozen contract, security boundary, migration) states the limit exceeded in one line; do not extend the budget silently.
58
+
49
59
  ## Constraints
50
60
 
51
61
  - The diff defines the **change under review**, not the boundary of the review. Follow the change one hop out: call sites, consumers, contracts, migrations, and the tests that already cover the touched path. Do not review unchanged code for its own sake — cite it only as evidence about the change.
@@ -27,6 +27,7 @@ npx @bonesofspring/ai-rules update
27
27
  - `.claude/.ai-rules-install.json`
28
28
  - `.mavis/.ai-rules-install.json`
29
29
  - `.opencode/.ai-rules-install.json`
30
+ - `.zcode/.ai-rules-install.json`
30
31
 
31
32
  `update` reads those files. A tool without that file stays uninstalled. Report the result in the user's native language (`language-policy`).
32
33
 
@@ -228,15 +228,94 @@ const DEFAULT_ARTIFACT_OUTPUT_IDS = {
228
228
  // table in agent-artifact-contracts.md. A receipt outcome is not a status.
229
229
  const ARTIFACT_STATUSES = ['planned', 'in_progress', 'completed', 'blocked', 'superseded'];
230
230
  const RECEIPT_OUTCOME_STATUS = { completed: 'completed', blocked: 'blocked', changes_requested: 'blocked', validation_failed: 'blocked' };
231
+ const TERMINAL_RECEIPT_OUTCOMES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
232
+ // A dead producer is reclaimed only after this conservative age with no
233
+ // terminal manifest receipt. The override is milliseconds; an invalid,
234
+ // non-positive, or sub-floor value falls back to the default rather than
235
+ // reclaiming immediately or disabling the safety net.
236
+ const DEFAULT_ATTEMPT_STALE_MS = 60 * 60 * 1000;
237
+ const MIN_ATTEMPT_STALE_MS = 60 * 1000;
238
+ function attemptStaleMs() {
239
+ const raw = process.env.AI_RULES_ATTEMPT_STALE_MS;
240
+ if (typeof raw !== 'string' || raw.trim() === '') return DEFAULT_ATTEMPT_STALE_MS;
241
+ const value = Number(raw);
242
+ return Number.isFinite(value) && value >= MIN_ATTEMPT_STALE_MS ? value : DEFAULT_ATTEMPT_STALE_MS;
243
+ }
244
+ function hasTerminalReceipt(attemptId, entry) {
245
+ const manifestPath = path.join(taskDir, 'artifact-manifest.json');
246
+ if (!fs.existsSync(manifestPath)) return false;
247
+ try {
248
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
249
+ const artifacts = Array.isArray(manifest.artifacts) ? manifest.artifacts : [];
250
+ const step = Array.isArray(steps) ? steps[entry.stepIndex] : null;
251
+ const outputId = step ? artifactOutputIdFor(step, entry.agent) : entry.agent;
252
+ const startedAt = Date.parse(entry.startedAt);
253
+ return artifacts.some((artifact) => {
254
+ if (!artifact || !artifact.receipt || !TERMINAL_RECEIPT_OUTCOMES.has(artifact.receipt.outcome)) return false;
255
+ if (artifact.receipt.attemptId === attemptId) return true;
256
+ if (artifact.receipt.attemptId != null || artifact.id !== outputId) return false;
257
+ // A legacy receipt without an attemptId still proves the producer finished.
258
+ const terminalAt = Date.parse(artifact.timestamps?.completedAt || artifact.timestamps?.updatedAt || '');
259
+ return !Number.isFinite(terminalAt) || !Number.isFinite(startedAt) || terminalAt >= startedAt;
260
+ });
261
+ } catch {
262
+ return false;
263
+ }
264
+ }
265
+ // P4: a killed producer leaves its attempt in `activeAttempts` forever. Reclaim
266
+ // only an entry for the step being activated (or a sibling in the same parallel
267
+ // group) past the threshold with no terminal receipt; a live attempt of another
268
+ // step is left for that step's own activation. Keep the audit row in metrics as
269
+ // `outcome: "stale"`. Idempotent: the entry leaves the object.
270
+ function reclaimStaleAttempts(scope) {
271
+ const active = { ...(status.activeAttempts || {}) };
272
+ const threshold = attemptStaleMs();
273
+ const at = Date.parse(now);
274
+ const agents = Array.isArray(scope?.agents) ? scope.agents : [];
275
+ const stepIndex = scope?.stepIndex;
276
+ const parallelGroupId = scope?.parallelGroupId || null;
277
+ const belongsToActivation = (entry) => {
278
+ if (!entry || typeof entry !== 'object') return false;
279
+ if (parallelGroupId && entry.parallelGroupId === parallelGroupId) return true;
280
+ return Number.isInteger(stepIndex) && entry.stepIndex === stepIndex && agents.includes(entry.agent);
281
+ };
282
+ for (const attemptId of Object.keys(active)) {
283
+ const entry = active[attemptId];
284
+ if (!belongsToActivation(entry)) continue;
285
+ const startedAt = Date.parse(entry.startedAt);
286
+ if (!Number.isFinite(startedAt) || !Number.isFinite(at)) continue;
287
+ const ageMs = at - startedAt;
288
+ if (ageMs <= threshold) continue;
289
+ if (hasTerminalReceipt(attemptId, entry)) continue;
290
+ delete active[attemptId];
291
+ appendMetric({
292
+ type: 'attempt_finished',
293
+ at: now,
294
+ attemptId,
295
+ stepIndex: entry.stepIndex,
296
+ stepLabel: (Array.isArray(steps) && steps[entry.stepIndex] && steps[entry.stepIndex].label) || null,
297
+ agent: entry.agent,
298
+ role: roleFor(entry.agent),
299
+ outcome: 'stale',
300
+ durationMs: ageMs,
301
+ retryAfterFix: status.retryAfterFix || null,
302
+ source: 'hook',
303
+ attributionConfidence: 'high',
304
+ });
305
+ process.stderr.write(`WARNING: ${slug}: reclaimed stale attempt ${attemptId} (agent ${entry.agent}, started ${entry.startedAt}, no terminal receipt after ${Math.round(ageMs / 60000)} min). A new attempt may start.\n`);
306
+ }
307
+ status.activeAttempts = active;
308
+ }
231
309
  function artifactOutputIdFor(step, agent) {
232
310
  if (step && typeof step.artifactOutputId === 'string') return step.artifactOutputId;
233
311
  if (step?.artifactOutputIds && typeof step.artifactOutputIds[agent] === 'string') return step.artifactOutputIds[agent];
234
312
  return DEFAULT_ARTIFACT_OUTPUT_IDS[agent] || agent;
235
313
  }
236
314
  function activateAttempts(step, stepIndex, waveId = null, agentsOverride = null) {
237
- const active = { ...(status.activeAttempts || {}) };
238
315
  const agents = Array.isArray(agentsOverride) && agentsOverride.length > 0 ? agentsOverride : getStepAgents(step);
239
316
  const parallelGroupId = step.parallel && getStepAgents(step).length > 1 ? `${status.metricsRunId || slug}:step-${stepIndex}` : null;
317
+ reclaimStaleAttempts({ stepIndex, agents, parallelGroupId });
318
+ const active = { ...(status.activeAttempts || {}) };
240
319
  for (const agent of agents) {
241
320
  const attempt = nextAttemptOrdinal(stepIndex, agent); const runId = status.metricsRunId || `${slug}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
242
321
  status.metricsRunId = runId; const attemptId = `${runId}:step-${stepIndex}:${agent}:attempt-${attempt}`;
@@ -1238,6 +1317,57 @@ function writeStatus(next) {
1238
1317
  writeFocusDigest();
1239
1318
  }
1240
1319
 
1320
+ // P1: the operator pause is a file sentinel, not a status field an agent may
1321
+ // write. It blocks NEW steps only: the completing receipt is reconciled and the
1322
+ // attempt is finished before this check runs. An empty or unreadable file still
1323
+ // counts as engaged (fail safe).
1324
+ const PAUSE_SENTINELS = [
1325
+ path.join(process.cwd(), '.ai.local', 'STOP'),
1326
+ path.join(process.cwd(), '.ai.local', 'ESTOP'),
1327
+ ];
1328
+ function readPauseSentinel() {
1329
+ for (const file of PAUSE_SENTINELS) {
1330
+ let stat = null;
1331
+ try { stat = fs.statSync(file); } catch (error) {
1332
+ if (error && error.code === 'ENOENT') continue;
1333
+ // A permission or I/O error is not proof of absence: fail safe and say so.
1334
+ process.stderr.write(`WARNING: ${slug}: cannot stat pause sentinel ${path.relative(process.cwd(), file).split(path.sep).join('/')} (${error && error.message ? error.message : String(error)}); treating it as engaged.\n`);
1335
+ return { engaged: true, file: path.relative(process.cwd(), file).split(path.sep).join('/'), reason: 'sentinel stat failed' };
1336
+ }
1337
+ if (!stat || !stat.isFile()) continue;
1338
+ let reason = '';
1339
+ try {
1340
+ const raw = fs.readFileSync(file, 'utf8').trim();
1341
+ if (raw) {
1342
+ try {
1343
+ const parsed = JSON.parse(raw);
1344
+ reason = parsed && typeof parsed.reason === 'string' ? parsed.reason : raw;
1345
+ } catch {
1346
+ reason = raw;
1347
+ }
1348
+ }
1349
+ } catch { /* unreadable sentinel still counts as engaged */ }
1350
+ return {
1351
+ engaged: true,
1352
+ file: path.relative(process.cwd(), file).split(path.sep).join('/'),
1353
+ reason: reason.replace(/\s+/g, ' ').slice(0, 160),
1354
+ };
1355
+ }
1356
+ return { engaged: false, file: null, reason: '' };
1357
+ }
1358
+ function pausedNotice(pause) {
1359
+ const where = pause && pause.file ? pause.file : '.ai.local/STOP';
1360
+ const because = pause && pause.reason ? ` (${pause.reason})` : '';
1361
+ return `[chain-team-phases] ${slug}: paused — operator sentinel ${where} is engaged${because}. No step advanced and no handoff was emitted. Remove the sentinel and run /task-continue ${slug}.`;
1362
+ }
1363
+ function pauseBlocksAdvance() {
1364
+ const pause = readPauseSentinel();
1365
+ if (!pause.engaged) return null;
1366
+ writeStatus({ state: 'paused', phase: 'paused' });
1367
+ out(pausedNotice(pause));
1368
+ return pause;
1369
+ }
1370
+
1241
1371
  function out(message) {
1242
1372
  process.stdout.write(JSON.stringify({ followup_message: message }));
1243
1373
  }
@@ -1869,6 +1999,7 @@ function legacyFlow() {
1869
1999
 
1870
2000
 
1871
2001
  if (hookInput.action === 'end_human_gate') {
2002
+ if (pauseBlocksAdvance()) process.exit(0);
1872
2003
  // Only advance when a gate was actually open. A duplicate or retried
1873
2004
  // end_human_gate must be a no-op, not a silent pipeline skip.
1874
2005
  const gateWasOpen = Boolean(status.activeHumanGateEventId) || status.awaitingHumanGate === true;
@@ -1978,6 +2109,7 @@ if (hookInput.action === 'end_human_gate') {
1978
2109
  }
1979
2110
 
1980
2111
  if (!fs.existsSync(pipelinePath)) {
2112
+ if (pauseBlocksAdvance()) process.exit(0);
1981
2113
  legacyFlow();
1982
2114
  }
1983
2115
 
@@ -2034,11 +2166,21 @@ const reconcilingAttempt = resolvedAttempt();
2034
2166
  const wasWaitingForReceipt = status.state === 'awaiting_artifact_receipt';
2035
2167
  reconcileStatusFromManifest(completingAgentHint, initialStep, reconcilingAttempt);
2036
2168
  if (status.state === 'awaiting_artifact_receipt') {
2169
+ const pause = readPauseSentinel();
2170
+ if (pause.engaged) {
2171
+ if (artifactStallMessage) process.stderr.write(artifactStallMessage + '\n');
2172
+ writeStatus({ state: 'paused', phase: 'paused' });
2173
+ out(pausedNotice(pause));
2174
+ process.exit(0);
2175
+ }
2037
2176
  writeStatus({});
2038
2177
  emitArtifactStall(artifactStallMessage, !wasWaitingForReceipt);
2039
2178
  process.exit(0);
2040
2179
  }
2041
2180
  let finishedAttempt = finishActiveAttempt();
2181
+ // The just-finished attempt's metric is already written; a pause now blocks
2182
+ // every handoff, including the unattributable-stop repair path below.
2183
+ if (pauseBlocksAdvance()) process.exit(0);
2042
2184
  if (!finishedAttempt && activeAttemptCountBeforeFinish > 0) {
2043
2185
  if (!hookInput.attemptId) {
2044
2186
  const repaired = repairUnattributableStop();
@@ -37,6 +37,7 @@ A diff-shaped read is a floor, not a review. Run these five passes on every non-
37
37
  - **`finding`** — reported like any other finding, with `path:line`.
38
38
  - **`no finding`** — with one line of evidence: what was searched or read.
39
39
  - **`unable to run`** — with the reason: the pass does not apply to this diff, or an input is missing.
40
+ - **`partial`** — the breadth budget stopped the pass; name every unread path or glob. Use it only on the call-site sweep.
40
41
 
41
42
  An outcome word alone is not a record: `no finding` without its evidence line, or `unable to run` without its reason, is an unfinished pass.
42
43
 
@@ -46,6 +47,15 @@ An outcome word alone is not a record: `no finding` without its evidence line, o
46
47
  4. **Test gap** — not "is there a test" but "which behaviour change would still pass every existing test". That gap is the finding.
47
48
  5. **Half-life** — what breaks in six months: hidden coupling, implicit contract, missing migration, an unowned copy of the same rule.
48
49
 
50
+ ## Review breadth budget
51
+
52
+ - Bound **breadth**, not depth: the call-site sweep and the one-hop consumer read stop at this budget. The five depth passes still run on what was read.
53
+ - Budget: the changed exports, types, routes, and events in the diff, plus one hop of their consumers. Read no consumer that neither the diff nor a recorded finding names.
54
+ - Stop when either limit is reached: 40 changed-symbol call sites, or 15 minutes of breadth reads on one review.
55
+ - When the budget is exhausted, stop the sweep and record `partial` in `## Depth passes` for the call-site sweep, with every unread path or glob named inline.
56
+ - Never claim full coverage after a `partial` row. The verdict follows the findings actually recorded.
57
+ - A deliberate overrun (frozen contract, security boundary, migration) states the limit exceeded in one line; do not extend the budget silently.
58
+
49
59
  ## Constraints
50
60
 
51
61
  - The diff defines the **change under review**, not the boundary of the review. Follow the change one hop out: call sites, consumers, contracts, migrations, and the tests that already cover the touched path. Do not review unchanged code for its own sake — cite it only as evidence about the change.