@bonesofspring/ai-rules 0.2.87 → 0.2.90

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 (462) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +9 -1
  3. package/bin/lib/engine-scripts.js +7 -0
  4. package/bin/lib/seed-ai-local-team.js +40 -0
  5. package/bin/opencode-install.js +11 -10
  6. package/docs/OPENCODE.md +8 -4
  7. package/docs/openapi/team-db.v1.json +2 -2
  8. package/package.json +1 -1
  9. package/presets/_shared/ai-local/env.example +54 -0
  10. package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +34 -5
  11. package/presets/_shared/ai-local/scripts/check-task-repositories.mjs +25 -22
  12. package/presets/_shared/ai-local/scripts/process-lease.mjs +3 -2
  13. package/presets/_shared/ai-local/scripts/processes.mjs +52 -20
  14. package/presets/_shared/ai-local/scripts/run.mjs +38 -6
  15. package/presets/_shared/ai-local/scripts/settings.mjs +246 -0
  16. package/presets/_shared/ai-local/scripts/task-worktree.mjs +364 -0
  17. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +2 -2
  18. package/presets/_shared/ai-local/scripts/team-db-project.mjs +87 -14
  19. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +102 -12
  20. package/presets/_shared/ai-local/scripts/team-db-tracker.mjs +35 -0
  21. package/presets/_shared/ai-local/scripts/tracker-planned-drain.mjs +10 -1
  22. package/presets/_shared/ai-local/scripts/verification.mjs +106 -11
  23. package/presets/_shared/core/agent-team/agent-task-metrics.md +10 -2
  24. package/presets/_shared/core/agent-team/agent-team-intake.md +2 -0
  25. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +2 -2
  26. package/presets/_shared/core/meta/preset-writing-style.md +8 -0
  27. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +541 -61
  28. package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +733 -9
  29. package/presets/_shared/hooks/prompt-autoroute.mjs.tmpl +153 -0
  30. package/presets/claude/android-kotlin/CLAUDE.md +2 -4
  31. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +541 -61
  32. package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +733 -9
  33. package/presets/claude/android-kotlin/hooks/prompt-autoroute.mjs +153 -0
  34. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-intake.md +2 -0
  35. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  36. package/presets/claude/android-kotlin/rules/tooling-and-review/preset-writing-style.md +8 -0
  37. package/presets/claude/android-kotlin/settings.json +15 -5
  38. package/presets/claude/go/CLAUDE.md +2 -4
  39. package/presets/claude/go/hooks/chain-team-phases.sh +541 -61
  40. package/presets/claude/go/hooks/guard-shell-command.mjs +733 -9
  41. package/presets/claude/go/hooks/prompt-autoroute.mjs +153 -0
  42. package/presets/claude/go/rules/tooling-and-review/agent-team-intake.md +2 -0
  43. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  44. package/presets/claude/go/rules/tooling-and-review/preset-writing-style.md +8 -0
  45. package/presets/claude/go/settings.json +15 -5
  46. package/presets/claude/ios-swift/CLAUDE.md +2 -4
  47. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +541 -61
  48. package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +733 -9
  49. package/presets/claude/ios-swift/hooks/prompt-autoroute.mjs +153 -0
  50. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-intake.md +2 -0
  51. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  52. package/presets/claude/ios-swift/rules/tooling-and-review/preset-writing-style.md +8 -0
  53. package/presets/claude/ios-swift/settings.json +15 -5
  54. package/presets/claude/java/CLAUDE.md +2 -4
  55. package/presets/claude/java/hooks/chain-team-phases.sh +541 -61
  56. package/presets/claude/java/hooks/guard-shell-command.mjs +733 -9
  57. package/presets/claude/java/hooks/prompt-autoroute.mjs +153 -0
  58. package/presets/claude/java/rules/tooling-and-review/agent-team-intake.md +2 -0
  59. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  60. package/presets/claude/java/rules/tooling-and-review/preset-writing-style.md +8 -0
  61. package/presets/claude/java/settings.json +15 -5
  62. package/presets/claude/mcp-ts/CLAUDE.md +2 -4
  63. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +541 -61
  64. package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +733 -9
  65. package/presets/claude/mcp-ts/hooks/prompt-autoroute.mjs +153 -0
  66. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-intake.md +2 -0
  67. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  68. package/presets/claude/mcp-ts/rules/tooling-and-review/preset-writing-style.md +8 -0
  69. package/presets/claude/mcp-ts/settings.json +15 -5
  70. package/presets/claude/mol/CLAUDE.md +2 -4
  71. package/presets/claude/mol/agents/feature-developer.md +1 -1
  72. package/presets/claude/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  73. package/presets/claude/mol/commands/task-evil.md +8 -0
  74. package/presets/claude/mol/hooks/chain-team-phases.sh +541 -61
  75. package/presets/claude/mol/hooks/guard-shell-command.mjs +733 -9
  76. package/presets/claude/mol/hooks/prompt-autoroute.mjs +153 -0
  77. package/presets/claude/mol/rules/tooling-and-review/agent-team-intake.md +2 -0
  78. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  79. package/presets/claude/mol/rules/tooling-and-review/preset-writing-style.md +8 -0
  80. package/presets/claude/mol/settings.json +15 -4
  81. package/presets/claude/next/CLAUDE.md +2 -4
  82. package/presets/claude/next/REPO_AGENTS.md +2 -0
  83. package/presets/claude/next/agents/feature-developer.md +1 -1
  84. package/presets/claude/next/agents/task-analyst.md +1 -7
  85. package/presets/claude/next/agents/task-router.md +1 -1
  86. package/presets/claude/next/ai-local/rules-library/commit-hygiene.md +1 -1
  87. package/presets/claude/next/commands/spec-start.md +3 -4
  88. package/presets/claude/next/commands/task-continue.md +9 -8
  89. package/presets/claude/next/commands/task-evil.md +8 -0
  90. package/presets/claude/next/commands/task.md +1 -1
  91. package/presets/claude/next/hooks/chain-team-phases.sh +541 -61
  92. package/presets/claude/next/hooks/guard-shell-command.mjs +733 -9
  93. package/presets/claude/next/hooks/prompt-autoroute.mjs +153 -0
  94. package/presets/claude/next/rules/tooling-and-review/agent-team-intake.md +2 -0
  95. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  96. package/presets/claude/next/rules/tooling-and-review/preset-writing-style.md +8 -0
  97. package/presets/claude/next/settings.json +15 -4
  98. package/presets/claude/next/team/README.md +1 -1
  99. package/presets/claude/nuxt/CLAUDE.md +2 -4
  100. package/presets/claude/nuxt/hooks/chain-team-phases.sh +541 -61
  101. package/presets/claude/nuxt/hooks/guard-shell-command.mjs +733 -9
  102. package/presets/claude/nuxt/hooks/prompt-autoroute.mjs +153 -0
  103. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-intake.md +2 -0
  104. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  105. package/presets/claude/nuxt/rules/tooling-and-review/preset-writing-style.md +8 -0
  106. package/presets/claude/nuxt/settings.json +15 -4
  107. package/presets/claude/php-hexagonal/CLAUDE.md +2 -4
  108. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  109. package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
  110. package/presets/claude/php-hexagonal/hooks/prompt-autoroute.mjs +153 -0
  111. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-intake.md +2 -0
  112. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  113. package/presets/claude/php-hexagonal/rules/tooling-and-review/preset-writing-style.md +8 -0
  114. package/presets/claude/php-hexagonal/settings.json +15 -5
  115. package/presets/claude/php-laravel/CLAUDE.md +2 -4
  116. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +541 -61
  117. package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +733 -9
  118. package/presets/claude/php-laravel/hooks/prompt-autoroute.mjs +153 -0
  119. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-intake.md +2 -0
  120. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  121. package/presets/claude/php-laravel/rules/tooling-and-review/preset-writing-style.md +8 -0
  122. package/presets/claude/php-laravel/settings.json +15 -5
  123. package/presets/claude/svelte/CLAUDE.md +2 -4
  124. package/presets/claude/svelte/hooks/chain-team-phases.sh +541 -61
  125. package/presets/claude/svelte/hooks/guard-shell-command.mjs +733 -9
  126. package/presets/claude/svelte/hooks/prompt-autoroute.mjs +153 -0
  127. package/presets/claude/svelte/rules/tooling-and-review/agent-team-intake.md +2 -0
  128. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  129. package/presets/claude/svelte/rules/tooling-and-review/preset-writing-style.md +8 -0
  130. package/presets/claude/svelte/settings.json +15 -4
  131. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +541 -61
  132. package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +733 -9
  133. package/presets/cursor/android-kotlin/rules/agent-team-intake.mdc +2 -0
  134. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
  135. package/presets/cursor/android-kotlin/rules/preset-writing-style.mdc +8 -0
  136. package/presets/cursor/go/hooks/chain-team-phases.sh +541 -61
  137. package/presets/cursor/go/hooks/guard-shell-command.mjs +733 -9
  138. package/presets/cursor/go/rules/agent-team-intake.mdc +2 -0
  139. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
  140. package/presets/cursor/go/rules/preset-writing-style.mdc +8 -0
  141. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +541 -61
  142. package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +733 -9
  143. package/presets/cursor/ios-swift/rules/agent-team-intake.mdc +2 -0
  144. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
  145. package/presets/cursor/ios-swift/rules/preset-writing-style.mdc +8 -0
  146. package/presets/cursor/java/hooks/chain-team-phases.sh +541 -61
  147. package/presets/cursor/java/hooks/guard-shell-command.mjs +733 -9
  148. package/presets/cursor/java/rules/agent-team-intake.mdc +2 -0
  149. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
  150. package/presets/cursor/java/rules/preset-writing-style.mdc +8 -0
  151. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +541 -61
  152. package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +733 -9
  153. package/presets/cursor/mcp-ts/rules/agent-team-intake.mdc +2 -0
  154. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
  155. package/presets/cursor/mcp-ts/rules/preset-writing-style.mdc +8 -0
  156. package/presets/cursor/mol/agents/feature-developer.md +1 -1
  157. package/presets/cursor/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  158. package/presets/cursor/mol/commands/task-evil.md +8 -0
  159. package/presets/cursor/mol/hooks/chain-team-phases.sh +541 -61
  160. package/presets/cursor/mol/hooks/guard-shell-command.mjs +733 -9
  161. package/presets/cursor/mol/rules/agent-team-intake.mdc +2 -0
  162. package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
  163. package/presets/cursor/mol/rules/preset-writing-style.mdc +8 -0
  164. package/presets/cursor/next/REPO_AGENTS.md +2 -0
  165. package/presets/cursor/next/agents/feature-developer.md +1 -1
  166. package/presets/cursor/next/agents/task-analyst.md +1 -7
  167. package/presets/cursor/next/agents/task-router.md +1 -1
  168. package/presets/cursor/next/ai-local/rules-library/commit-hygiene.md +1 -1
  169. package/presets/cursor/next/commands/spec-start.md +3 -4
  170. package/presets/cursor/next/commands/task-continue.md +9 -8
  171. package/presets/cursor/next/commands/task-evil.md +8 -0
  172. package/presets/cursor/next/commands/task.md +1 -1
  173. package/presets/cursor/next/hooks/chain-team-phases.sh +541 -61
  174. package/presets/cursor/next/hooks/guard-shell-command.mjs +733 -9
  175. package/presets/cursor/next/rules/agent-team-intake.mdc +2 -0
  176. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +2 -2
  177. package/presets/cursor/next/rules/preset-writing-style.mdc +8 -0
  178. package/presets/cursor/next/team/README.md +1 -1
  179. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +541 -61
  180. package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +733 -9
  181. package/presets/cursor/nuxt/rules/agent-team-intake.mdc +2 -0
  182. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
  183. package/presets/cursor/nuxt/rules/preset-writing-style.mdc +8 -0
  184. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  185. package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
  186. package/presets/cursor/php-hexagonal/rules/agent-team-intake.mdc +2 -0
  187. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
  188. package/presets/cursor/php-hexagonal/rules/preset-writing-style.mdc +8 -0
  189. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +541 -61
  190. package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +733 -9
  191. package/presets/cursor/php-laravel/rules/agent-team-intake.mdc +2 -0
  192. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
  193. package/presets/cursor/php-laravel/rules/preset-writing-style.mdc +8 -0
  194. package/presets/cursor/svelte/hooks/chain-team-phases.sh +541 -61
  195. package/presets/cursor/svelte/hooks/guard-shell-command.mjs +733 -9
  196. package/presets/cursor/svelte/rules/agent-team-intake.mdc +2 -0
  197. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
  198. package/presets/cursor/svelte/rules/preset-writing-style.mdc +8 -0
  199. package/presets/mavis/android-kotlin/MAVIS.md +1 -1
  200. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  201. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +541 -61
  202. package/presets/mavis/android-kotlin/rules/agent-team-intake.md +2 -0
  203. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +2 -2
  204. package/presets/mavis/android-kotlin/rules/preset-writing-style.md +8 -0
  205. package/presets/mavis/go/MAVIS.md +1 -1
  206. package/presets/mavis/go/adapter-map.json +1 -1
  207. package/presets/mavis/go/hooks/chain-team-phases.sh +541 -61
  208. package/presets/mavis/go/rules/agent-team-intake.md +2 -0
  209. package/presets/mavis/go/rules/agent-team-orchestrator.md +2 -2
  210. package/presets/mavis/go/rules/preset-writing-style.md +8 -0
  211. package/presets/mavis/ios-swift/MAVIS.md +1 -1
  212. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  213. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +541 -61
  214. package/presets/mavis/ios-swift/rules/agent-team-intake.md +2 -0
  215. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +2 -2
  216. package/presets/mavis/ios-swift/rules/preset-writing-style.md +8 -0
  217. package/presets/mavis/java/MAVIS.md +1 -1
  218. package/presets/mavis/java/adapter-map.json +1 -1
  219. package/presets/mavis/java/hooks/chain-team-phases.sh +541 -61
  220. package/presets/mavis/java/rules/agent-team-intake.md +2 -0
  221. package/presets/mavis/java/rules/agent-team-orchestrator.md +2 -2
  222. package/presets/mavis/java/rules/preset-writing-style.md +8 -0
  223. package/presets/mavis/mcp-ts/MAVIS.md +1 -1
  224. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  225. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +541 -61
  226. package/presets/mavis/mcp-ts/rules/agent-team-intake.md +2 -0
  227. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +2 -2
  228. package/presets/mavis/mcp-ts/rules/preset-writing-style.md +8 -0
  229. package/presets/mavis/mol/MAVIS.md +1 -1
  230. package/presets/mavis/mol/adapter-map.json +1 -1
  231. package/presets/mavis/mol/agents/feature-developer.md +1 -1
  232. package/presets/mavis/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  233. package/presets/mavis/mol/commands/task-evil.md +8 -0
  234. package/presets/mavis/mol/hooks/chain-team-phases.sh +541 -61
  235. package/presets/mavis/mol/native-skills/task-evil/SKILL.md +8 -0
  236. package/presets/mavis/mol/rules/agent-team-intake.md +2 -0
  237. package/presets/mavis/mol/rules/agent-team-orchestrator.md +2 -2
  238. package/presets/mavis/mol/rules/preset-writing-style.md +8 -0
  239. package/presets/mavis/next/MAVIS.md +1 -1
  240. package/presets/mavis/next/REPO_AGENTS.md +2 -0
  241. package/presets/mavis/next/adapter-map.json +1 -1
  242. package/presets/mavis/next/agents/feature-developer.md +1 -1
  243. package/presets/mavis/next/agents/task-analyst.md +1 -7
  244. package/presets/mavis/next/agents/task-router.md +1 -1
  245. package/presets/mavis/next/ai-local/rules-library/commit-hygiene.md +1 -1
  246. package/presets/mavis/next/commands/spec-start.md +3 -4
  247. package/presets/mavis/next/commands/task-continue.md +9 -8
  248. package/presets/mavis/next/commands/task-evil.md +8 -0
  249. package/presets/mavis/next/commands/task.md +1 -1
  250. package/presets/mavis/next/hooks/chain-team-phases.sh +541 -61
  251. package/presets/mavis/next/native-skills/spec-start/SKILL.md +3 -4
  252. package/presets/mavis/next/native-skills/task/SKILL.md +1 -1
  253. package/presets/mavis/next/native-skills/task-continue/SKILL.md +9 -8
  254. package/presets/mavis/next/native-skills/task-evil/SKILL.md +8 -0
  255. package/presets/mavis/next/rules/agent-team-intake.md +2 -0
  256. package/presets/mavis/next/rules/agent-team-orchestrator.md +2 -2
  257. package/presets/mavis/next/rules/preset-writing-style.md +8 -0
  258. package/presets/mavis/next/team/README.md +1 -1
  259. package/presets/mavis/nuxt/MAVIS.md +1 -1
  260. package/presets/mavis/nuxt/adapter-map.json +1 -1
  261. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +541 -61
  262. package/presets/mavis/nuxt/rules/agent-team-intake.md +2 -0
  263. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +2 -2
  264. package/presets/mavis/nuxt/rules/preset-writing-style.md +8 -0
  265. package/presets/mavis/php-hexagonal/MAVIS.md +1 -1
  266. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  267. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  268. package/presets/mavis/php-hexagonal/rules/agent-team-intake.md +2 -0
  269. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
  270. package/presets/mavis/php-hexagonal/rules/preset-writing-style.md +8 -0
  271. package/presets/mavis/php-laravel/MAVIS.md +1 -1
  272. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  273. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +541 -61
  274. package/presets/mavis/php-laravel/rules/agent-team-intake.md +2 -0
  275. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +2 -2
  276. package/presets/mavis/php-laravel/rules/preset-writing-style.md +8 -0
  277. package/presets/mavis/svelte/MAVIS.md +1 -1
  278. package/presets/mavis/svelte/adapter-map.json +1 -1
  279. package/presets/mavis/svelte/hooks/chain-team-phases.sh +541 -61
  280. package/presets/mavis/svelte/rules/agent-team-intake.md +2 -0
  281. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +2 -2
  282. package/presets/mavis/svelte/rules/preset-writing-style.md +8 -0
  283. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  284. package/presets/opencode/android-kotlin/hooks/README.md +6 -5
  285. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +541 -61
  286. package/presets/opencode/android-kotlin/hooks/guard-shell-command.mjs +733 -9
  287. package/presets/opencode/android-kotlin/opencode.json +4 -4
  288. package/presets/opencode/android-kotlin/rules/agent-team-intake.md +2 -0
  289. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +2 -2
  290. package/presets/opencode/android-kotlin/rules/preset-writing-style.md +8 -0
  291. package/presets/opencode/go/adapter-map.json +1 -1
  292. package/presets/opencode/go/hooks/README.md +6 -5
  293. package/presets/opencode/go/hooks/chain-team-phases.sh +541 -61
  294. package/presets/opencode/go/hooks/guard-shell-command.mjs +733 -9
  295. package/presets/opencode/go/opencode.json +4 -4
  296. package/presets/opencode/go/rules/agent-team-intake.md +2 -0
  297. package/presets/opencode/go/rules/agent-team-orchestrator.md +2 -2
  298. package/presets/opencode/go/rules/preset-writing-style.md +8 -0
  299. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  300. package/presets/opencode/ios-swift/hooks/README.md +6 -5
  301. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +541 -61
  302. package/presets/opencode/ios-swift/hooks/guard-shell-command.mjs +733 -9
  303. package/presets/opencode/ios-swift/opencode.json +4 -4
  304. package/presets/opencode/ios-swift/rules/agent-team-intake.md +2 -0
  305. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +2 -2
  306. package/presets/opencode/ios-swift/rules/preset-writing-style.md +8 -0
  307. package/presets/opencode/java/adapter-map.json +1 -1
  308. package/presets/opencode/java/hooks/README.md +6 -5
  309. package/presets/opencode/java/hooks/chain-team-phases.sh +541 -61
  310. package/presets/opencode/java/hooks/guard-shell-command.mjs +733 -9
  311. package/presets/opencode/java/opencode.json +4 -4
  312. package/presets/opencode/java/rules/agent-team-intake.md +2 -0
  313. package/presets/opencode/java/rules/agent-team-orchestrator.md +2 -2
  314. package/presets/opencode/java/rules/preset-writing-style.md +8 -0
  315. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  316. package/presets/opencode/mcp-ts/hooks/README.md +6 -5
  317. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +541 -61
  318. package/presets/opencode/mcp-ts/hooks/guard-shell-command.mjs +733 -9
  319. package/presets/opencode/mcp-ts/opencode.json +4 -4
  320. package/presets/opencode/mcp-ts/rules/agent-team-intake.md +2 -0
  321. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +2 -2
  322. package/presets/opencode/mcp-ts/rules/preset-writing-style.md +8 -0
  323. package/presets/opencode/mol/adapter-map.json +1 -1
  324. package/presets/opencode/mol/agents/feature-developer.md +1 -1
  325. package/presets/opencode/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  326. package/presets/opencode/mol/commands/task-evil.md +8 -0
  327. package/presets/opencode/mol/hooks/README.md +6 -5
  328. package/presets/opencode/mol/hooks/chain-team-phases.sh +541 -61
  329. package/presets/opencode/mol/hooks/guard-shell-command.mjs +733 -9
  330. package/presets/opencode/mol/opencode.json +4 -4
  331. package/presets/opencode/mol/rules/agent-team-intake.md +2 -0
  332. package/presets/opencode/mol/rules/agent-team-orchestrator.md +2 -2
  333. package/presets/opencode/mol/rules/preset-writing-style.md +8 -0
  334. package/presets/opencode/next/REPO_AGENTS.md +2 -0
  335. package/presets/opencode/next/adapter-map.json +1 -1
  336. package/presets/opencode/next/agents/feature-developer.md +1 -1
  337. package/presets/opencode/next/agents/task-analyst.md +1 -7
  338. package/presets/opencode/next/agents/task-router.md +1 -1
  339. package/presets/opencode/next/ai-local/rules-library/commit-hygiene.md +1 -1
  340. package/presets/opencode/next/commands/spec-start.md +3 -4
  341. package/presets/opencode/next/commands/task-continue.md +9 -8
  342. package/presets/opencode/next/commands/task-evil.md +8 -0
  343. package/presets/opencode/next/commands/task.md +1 -1
  344. package/presets/opencode/next/hooks/README.md +6 -5
  345. package/presets/opencode/next/hooks/chain-team-phases.sh +541 -61
  346. package/presets/opencode/next/hooks/guard-shell-command.mjs +733 -9
  347. package/presets/opencode/next/opencode.json +4 -4
  348. package/presets/opencode/next/rules/agent-team-intake.md +2 -0
  349. package/presets/opencode/next/rules/agent-team-orchestrator.md +2 -2
  350. package/presets/opencode/next/rules/preset-writing-style.md +8 -0
  351. package/presets/opencode/next/team/README.md +1 -1
  352. package/presets/opencode/nuxt/adapter-map.json +1 -1
  353. package/presets/opencode/nuxt/hooks/README.md +6 -5
  354. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +541 -61
  355. package/presets/opencode/nuxt/hooks/guard-shell-command.mjs +733 -9
  356. package/presets/opencode/nuxt/opencode.json +4 -4
  357. package/presets/opencode/nuxt/rules/agent-team-intake.md +2 -0
  358. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +2 -2
  359. package/presets/opencode/nuxt/rules/preset-writing-style.md +8 -0
  360. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  361. package/presets/opencode/php-hexagonal/hooks/README.md +6 -5
  362. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  363. package/presets/opencode/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
  364. package/presets/opencode/php-hexagonal/opencode.json +4 -4
  365. package/presets/opencode/php-hexagonal/rules/agent-team-intake.md +2 -0
  366. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
  367. package/presets/opencode/php-hexagonal/rules/preset-writing-style.md +8 -0
  368. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  369. package/presets/opencode/php-laravel/hooks/README.md +6 -5
  370. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +541 -61
  371. package/presets/opencode/php-laravel/hooks/guard-shell-command.mjs +733 -9
  372. package/presets/opencode/php-laravel/opencode.json +4 -4
  373. package/presets/opencode/php-laravel/rules/agent-team-intake.md +2 -0
  374. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +2 -2
  375. package/presets/opencode/php-laravel/rules/preset-writing-style.md +8 -0
  376. package/presets/opencode/plugins/settings-guard/README.md +25 -0
  377. package/presets/opencode/plugins/settings-guard/index.ts +114 -0
  378. package/presets/opencode/plugins/settings-guard/package.json +9 -0
  379. package/presets/opencode/plugins/settings-guard/policy.mjs +85 -0
  380. package/presets/opencode/plugins/settings-guard/prompt-face.mjs +153 -0
  381. package/presets/opencode/plugins/task-status/README.md +9 -4
  382. package/presets/opencode/plugins/task-status/eta.ts +20 -7
  383. package/presets/opencode/plugins/task-status/index.ts +14 -1
  384. package/presets/opencode/plugins/task-status/task-view.ts +160 -5
  385. package/presets/opencode/plugins/task-status/timing.ts +244 -0
  386. package/presets/opencode/plugins/task-status/types.ts +6 -0
  387. package/presets/opencode/svelte/adapter-map.json +1 -1
  388. package/presets/opencode/svelte/hooks/README.md +6 -5
  389. package/presets/opencode/svelte/hooks/chain-team-phases.sh +541 -61
  390. package/presets/opencode/svelte/hooks/guard-shell-command.mjs +733 -9
  391. package/presets/opencode/svelte/opencode.json +4 -4
  392. package/presets/opencode/svelte/rules/agent-team-intake.md +2 -0
  393. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +2 -2
  394. package/presets/opencode/svelte/rules/preset-writing-style.md +8 -0
  395. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  396. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +541 -61
  397. package/presets/zcode/android-kotlin/rules/agent-team-intake.md +2 -0
  398. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +2 -2
  399. package/presets/zcode/android-kotlin/rules/preset-writing-style.md +8 -0
  400. package/presets/zcode/go/adapter-map.json +1 -1
  401. package/presets/zcode/go/hooks/chain-team-phases.sh +541 -61
  402. package/presets/zcode/go/rules/agent-team-intake.md +2 -0
  403. package/presets/zcode/go/rules/agent-team-orchestrator.md +2 -2
  404. package/presets/zcode/go/rules/preset-writing-style.md +8 -0
  405. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  406. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +541 -61
  407. package/presets/zcode/ios-swift/rules/agent-team-intake.md +2 -0
  408. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +2 -2
  409. package/presets/zcode/ios-swift/rules/preset-writing-style.md +8 -0
  410. package/presets/zcode/java/adapter-map.json +1 -1
  411. package/presets/zcode/java/hooks/chain-team-phases.sh +541 -61
  412. package/presets/zcode/java/rules/agent-team-intake.md +2 -0
  413. package/presets/zcode/java/rules/agent-team-orchestrator.md +2 -2
  414. package/presets/zcode/java/rules/preset-writing-style.md +8 -0
  415. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  416. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +541 -61
  417. package/presets/zcode/mcp-ts/rules/agent-team-intake.md +2 -0
  418. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +2 -2
  419. package/presets/zcode/mcp-ts/rules/preset-writing-style.md +8 -0
  420. package/presets/zcode/mol/adapter-map.json +1 -1
  421. package/presets/zcode/mol/agents/feature-developer.md +1 -1
  422. package/presets/zcode/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  423. package/presets/zcode/mol/commands/task-evil.md +8 -0
  424. package/presets/zcode/mol/hooks/chain-team-phases.sh +541 -61
  425. package/presets/zcode/mol/rules/agent-team-intake.md +2 -0
  426. package/presets/zcode/mol/rules/agent-team-orchestrator.md +2 -2
  427. package/presets/zcode/mol/rules/preset-writing-style.md +8 -0
  428. package/presets/zcode/next/REPO_AGENTS.md +2 -0
  429. package/presets/zcode/next/adapter-map.json +1 -1
  430. package/presets/zcode/next/agents/feature-developer.md +1 -1
  431. package/presets/zcode/next/agents/task-analyst.md +1 -7
  432. package/presets/zcode/next/agents/task-router.md +1 -1
  433. package/presets/zcode/next/ai-local/rules-library/commit-hygiene.md +1 -1
  434. package/presets/zcode/next/commands/spec-start.md +3 -4
  435. package/presets/zcode/next/commands/task-continue.md +9 -8
  436. package/presets/zcode/next/commands/task-evil.md +8 -0
  437. package/presets/zcode/next/commands/task.md +1 -1
  438. package/presets/zcode/next/hooks/chain-team-phases.sh +541 -61
  439. package/presets/zcode/next/rules/agent-team-intake.md +2 -0
  440. package/presets/zcode/next/rules/agent-team-orchestrator.md +2 -2
  441. package/presets/zcode/next/rules/preset-writing-style.md +8 -0
  442. package/presets/zcode/next/team/README.md +1 -1
  443. package/presets/zcode/nuxt/adapter-map.json +1 -1
  444. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +541 -61
  445. package/presets/zcode/nuxt/rules/agent-team-intake.md +2 -0
  446. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +2 -2
  447. package/presets/zcode/nuxt/rules/preset-writing-style.md +8 -0
  448. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  449. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  450. package/presets/zcode/php-hexagonal/rules/agent-team-intake.md +2 -0
  451. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
  452. package/presets/zcode/php-hexagonal/rules/preset-writing-style.md +8 -0
  453. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  454. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +541 -61
  455. package/presets/zcode/php-laravel/rules/agent-team-intake.md +2 -0
  456. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +2 -2
  457. package/presets/zcode/php-laravel/rules/preset-writing-style.md +8 -0
  458. package/presets/zcode/svelte/adapter-map.json +1 -1
  459. package/presets/zcode/svelte/hooks/chain-team-phases.sh +541 -61
  460. package/presets/zcode/svelte/rules/agent-team-intake.md +2 -0
  461. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +2 -2
  462. package/presets/zcode/svelte/rules/preset-writing-style.md +8 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,55 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.90
4
+
5
+ Records the package commits after `## 0.2.89`: `59b43f32` (per-task worktree), `902fcb33` (OpenCode settings guard), `989ae95e` (attempt time split and session leases).
6
+
7
+ ### Per-task git worktree
8
+
9
+ - **`task-worktree.mjs`.** `create <slug>`, `list`, and `remove <slug>` join `ENGINE_SCRIPTS` and are mirrored to `.ai.local/scripts/`. `create` checks the slug, refuses a missing task, an existing `.ai.local/worktrees/<slug>` directory, or an existing `task/<slug>` branch, then runs `git worktree add` from the repo root. It copies `scripts/`, `rules/`, `conventions.md`, and `.env` read-only and best-effort symlinks `.ai.local/team` at the main store. A refused symlink warns and leaves env-only binding. The activation line is `AI_RULES_TEAM_ROOT=<abs main team root>`. A complete pair is a no-op success. Git failures are printed verbatim and left for `git worktree prune`.
10
+ - **`list` and `remove`.** `list` prints slug, branch, path, live or terminal state from the main store, and the resolved store. `remove` refuses a live slug and an unmerged branch. `--force` says it is deleting the unmerged branch (`git branch -D`). An already-removed pair exits 0.
11
+ - **One store.** The chain hook `TEAM_ROOT`, `team-db-schema.mjs` `resolveTeamRoot`, and `check-preset-delta.mjs` baseline resolution read `AI_RULES_TEAM_ROOT` before the cwd or script-dir default. `AI_RULES_TEAM_DB_ROOT` stays the legacy fallback. There is no `AI_RULES_REPO_ROOT`. The scheduler and `apps/team-tasks-ui` are unchanged.
12
+ - **Ignore.** The seeded `.ai.local/.gitignore` and this repo's copy gain `worktrees/`.
13
+
14
+ ### OpenCode applies `.ai.local/.env` from a plugin
15
+
16
+ - **Settings guard.** `.opencode/plugins/settings-guard/` is the enforcement layer. It calls `evaluate` from `guard-shell-command.mjs` on `ctx.permission.hook("evaluate")` and, when that hook is absent, on `ctx.tool.hook("execute.before")`. `opencode.json` `permission.bash` stays the static floor. A configured `deny` (the `task-evil` agent) never reaches the plugin. The unregistered CLI file is not the enforcement path.
17
+ - **Git writes.** An `allow` on a plain `git commit` / `git push` lifts the static ask. An `ask` keeps the prompt; on a host with no permission hook the tool hook throws, so the command does not run. `false`, a missing file, and a broken file stay `ask`. Destructive, alias, and indirect shapes stay `ask`.
18
+ - **Autoroute.** The plugin's `prompt` hook appends the same directive as Claude's `UserPromptSubmit` when `AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS` is `true` and the live-slug count is below `AI_RULES_MAX_PARALLEL_TASKS`. `generate-opencode` rewrites `prompt-face.mjs` from the prompt-autoroute template. Cursor, Mavis, and ZCode still follow the entry-prose check.
19
+ - **Boolean spelling.** `settings.mjs` treats `false` and `0` as silent off. Quoted `"true"`, an `export` prefix, a trailing comment, and every other value warn and stay `false`. `.env.example` names the OpenCode plugin, the integer cap, and which hosts have a prompt hook. `test-settings-guard.mjs` covers the plugin.
20
+
21
+ ### Attempt time splits into work, gate, pause, sleep, and idle
22
+
23
+ - **`attempt_finished` carries the split.** The chain hook writes `durationMs` / `wallMs`, `activeMs`, and `idleMs`. Active time is wall time minus proven non-work (a human gate, an operator pause, a host suspension in `<slug>/.suspend.jsonl`), capped by `AI_RULES_ATTEMPT_MAX_MS` (default 4h, floor 10 minutes). `idleMs` is the remainder, so wall = active + idle. A live `STOP` sentinel is charged from its mtime, before `task_paused` is written.
24
+ - **Pause is a ledger interval.** One `task_paused` per engagement and one `task_resumed` when the sentinel is gone. A second pause while one is open is not recorded.
25
+ - **Sidebar.** The OpenCode task-status `time` row reads `work` / `gate` / `paused` / `sleep` / `idle`. A zero bucket is hidden. Older ledgers without `activeMs` use `durationMs` capped at 4h. A parallel wave reads `N agents` and clocks from the oldest start. The plugin appends `.suspend.jsonl` when the wall clock outruns a monotonic clock by more than 60s; a suspend while OpenCode is closed stays in `idle`. ETA samples use `activeMs` and skip `stale` / `unknown` closes.
26
+ - **Session lease.** Slug resolution is `TEAM_TASK_SLUG`, then `.ai.local/team/.session-leases/<session>.json` (7-day mtime TTL), then `active-task.json`. Only an explicit env slug writes the lease from the hook. The task-status plugin writes the same file when it pins a tab and sets `AI_RULES_SESSION_ID` and `OPENCODE_SESSION_ID` on `shell.env`, so a later hook call in that tab resolves the pin when `TEAM_TASK_SLUG` is omitted. With more than one live slug the pointer fallback still refuses. `aggregate-agent-task-metrics.mjs` averages `activeMs` (legacy rows capped at 4h), reports `pausedMs`, and puts the unattributed remainder in `idleMs`. `longestAttemptMs` stays wall clock.
27
+
28
+ ## 0.2.89
29
+
30
+ Records commit `a3e7751c`, the parallel-slug tree that landed after `## 0.2.88`.
31
+
32
+ ### Parallel `/task` slugs: the pointer becomes a projection, autoroute learns a cap
33
+
34
+ - **`active-task.json` is a UI projection, not a routing pointer.** The schema is `{"schemaVersion": 1, "slugs": [...], "updatedAt"}` — sorted live slugs only, rebuilt atomically by `team-db sync` (both `--slug` and full) and refreshed by `team-db delete`; the only writer. Readers accept the legacy `{"slug"}` shape forever; an old hook reading the new shape degrades to the same no-op as a missing file. `/task`, `/task-continue`, `/spec-start`, `/task-evil`, task-router, and task-analyst no longer write it.
35
+ - **Slug routing binds to `TEAM_TASK_SLUG`.** The chain hook postflight (team-db projection, dev-server cleanup, self-learning ratchet) resolves the env slug first (grammar-validated, so `tasks/<slug>` cannot escape the tree); the pointer is a last resort that is skipped — loudly for the projection (`WARNING: pointer-resolved projection skipped; N live slugs`), silently for the ratchet — when any other live slug exists. Dev-server cleanup no longer falls back to the pointer at all.
36
+ - **The pointer fallback refuses under ambiguity.** When the slug resolved from `active-task.json` and at least one other slug is live (`status.json` state not in `completed`/`blocked`/`changes_requested`/`validation_failed`), the hook answers `{"ok":false,"reason":"active-task-pointer-ambiguous","slug",...}` with a stderr `ERROR:` line and exit 0 — the hook's refusal convention — so the caller re-runs with `TEAM_TASK_SLUG=<slug>`. With exactly one live slug the old warning-only behaviour is unchanged.
37
+ - **Autoroute wraps in parallel, bounded.** `prompt-autoroute` replaced the single-pointer `liveSlug()` with a `liveSlugs()` scan over `tasks/*/status.json` and wraps while the count is below `AI_RULES_MAX_PARALLEL_TASKS` — a new `settings.mjs` key (`get` prints the number): default `4`, non-numeric values warn and fall back to `4`, `0` = unlimited. The intake rule text carries the same predicate plus the new-vs-continue disambiguation (a named slug or a resume intent routes to `/task-continue <slug>` regardless of the cap); the orchestrator rule makes `TEAM_TASK_SLUG` on every hook call a MUST.
38
+ - **Delete guard per slug.** `team-db delete` refuses `E_ACTIVE_TASK` (same exit 1, same `details.activeSlug` in the API) when the *requested* slug's own `status.json` is non-terminal — no pointer involved — and `check-task-repositories` excludes every live slug from the audit (`excluding live: a, b` in the OK line), not just the pointer-named one.
39
+ - **Gate evidence is scoped to the task.** `worktreeHash` is renamed `environmentHash` (whole-tree capture, diagnostic only). New fields `scopeHash`, `scopePaths`, and `scopeBasis` (`write-scope` | `whole-tree` | `none`) bind freshness to the union of the task's `.write-scope` step baselines. Basis `none` (no baseline and more than one live slug) reports `scope-unbound` and is not fresh. Snapshots recorded before the rename still compare through `worktreeHash`. A file created after baseline activation outside the claimed path set stays invisible to `scopeHash`; the write-scope audit still attributes it at gate time.
40
+ - **A baseline-less gate list errors in parallel mode.** `yarn check:task <slug>` with no `.write-scope` baseline and more than one live slug exits 2 and writes `E_NO_TASK_BASELINE`, naming `yarn check:task <slug> --save-baseline`. At most one live slug keeps the warning and the repo-wide diff.
41
+ - **Resume is scoped to one slug.** `/task-continue <slug>` removes only `.ai.local/team/tasks/<slug>/STOP`. `/task-continue --all` removes `.ai.local/STOP`, `.ai.local/ESTOP`, and every per-slug `STOP`, appending one `.memlog.md` line per slug. The hook's sentinel reader is unchanged.
42
+ - **Repo-global locks queue instead of colliding.** `ensureWal` runs after migrations, outside any transaction, so an existing `team.db` reaches `journal_mode=WAL` on the next writable open without a table rewrite; `SQLITE_BUSY` retries once, then one `E_WAL_DEFERRED` line, and the next open retries. `check` prints `journalMode`. `AI_RULES_TEAM_DB_BUSY_MS` sets `busy_timeout` (integer milliseconds, default `5000`; an invalid value warns once and uses the default). The tracker drain returns before the lock when the queue directory is empty. `yarn fix:generated` waits 30000 ms when neither `--wait` nor `AI_RULES_LOCK_WAIT_MS` is set; `run-locked.mjs` and the shell gates stay fail-fast. `start` / `run` / `acquire --task <slug>` record `leases/<name>#<slug>.json`; `stop` / `list --name X` match `X.json` and every `X#*.json`; `stop --task` stays a tag filter. `run.mjs` holds one fail-fast `.self-learning.lock` across derive → append → improve and prints the existing skip line when the lock is held.
43
+
44
+ ## 0.2.88
45
+
46
+ ### Env settings, the shell-command guard, and prompt autoroute
47
+
48
+ Documents the package commits already on `HEAD` after `## 0.2.87` (`bc10f528`, `a5334707`). The parallel-slug work stays under `## Unreleased` until that tree is committed.
49
+
50
+ - **Settings module.** `AI_RULES_*` keys are read through `settings.mjs`; `.env.example` lists them. The shell-command guard and `prompt-autoroute` ship in the hook templates.
51
+ - **Writing style.** The preset-writing-style shell-guard section is in the shared core and the generated platform copies.
52
+
3
53
  ## 0.2.87
4
54
 
5
55
  ### OpenCode attaches each stack's globs, and step cost stops double-counting
package/README.md CHANGED
@@ -25,13 +25,21 @@ Run `init` from the **app root** (`--cwd` if needed). Default `--preset` is `nex
25
25
  | Root agents | `REPO_AGENTS.md` → `AGENTS.md` (same file on all five; ZCode loads it natively) | | | | |
26
26
  | `/task` artifacts | **`.ai.local/team/`** (shared; templates refreshed; `tasks/<slug>/` never overwritten) | | | |
27
27
  | Template drift | **`.ai.local/.template-base.json`** (shared; one record per tree of files that hold a shipped template byte; `update` prints one drift line, `update --merge-ai-local` fast-forwards a file only when its recorded base still matches and reports the rest) | | | |
28
- | Self-learning engine | **`.ai.local/scripts/`** (shared; thirty published scripts — the six self-learning engine modules, `manifest.mjs`, `dump-output.mjs`, `run-compact.mjs`, the eight `team-db*.mjs` modules, `action-signals.mjs`, `actions-report.mjs`, `check-write-scope.mjs`, `aggregate-agent-task-metrics.mjs`, `record-usage.mjs`, `verification.mjs`, `check-verification.mjs`, `incidents.mjs`, `processes.mjs`, `process-lease.mjs`, `rr-scheduler-start.mjs`, `rr-migrate-repositories.mjs`, and `tracker-planned-drain.mjs`; existing files never overwritten. The repository-only `upstream-research.mjs` is not published) | | | |
28
+ | Self-learning engine | **`.ai.local/scripts/`** (shared; thirty-four published scripts — the six self-learning engine modules, `manifest.mjs`, `dump-output.mjs`, `run-compact.mjs`, the eight `team-db*.mjs` modules, `action-signals.mjs`, `actions-report.mjs`, `check-write-scope.mjs`, `aggregate-agent-task-metrics.mjs`, `record-usage.mjs`, `verification.mjs`, `check-verification.mjs`, `incidents.mjs`, `processes.mjs`, `process-lease.mjs`, `rr-scheduler-start.mjs`, `rr-migrate-repositories.mjs`, `tracker-planned-drain.mjs`, and `task-worktree.mjs`; existing files never overwritten. The repository-only `upstream-research.mjs` is not published) | | | |
29
29
  | Specs seed | `docs/specs/` copied only if the directory is **absent** | | | |
30
30
 
31
31
  OpenCode also ships **`.opencode/plugins/task-status/`**, a TUI sidebar for the active `/task` run (slug, state, elapsed time, step, remaining-time estimate, soft-stop). OpenCode auto-loads it; it needs no `opencode.json` entry, is refreshed by `update`, and is a viewer only — the chain hook stays manual.
32
32
 
33
33
  **`.opencode/plugins/output-guard/`** is the server counterpart: a `tool-result` over 8 KB is stored under `.ai.local/team/output-guard/` and replaced with a bounded head + tail, the path, and one `grep` hint. It registers `ctx.session.hook("context")`, so it works for a prompt without `/task`; `AI_RULES_OUTPUT_GUARD=0` disables it and a host without the hook no-ops. It is a token-economy mechanism, not a security boundary. Measure it with `yarn report:efficiency` (text/JSON/HTML) and `yarn bench:efficiency --model <provider/model> --runs 5` (A/B with a deterministic oracle); a byte saving is never reported as a token saving.
34
34
 
35
+ **Parallel `/task` slugs.** Several tasks can be live in one repo. `.ai.local/team/active-task.json` is no longer a routing pointer: it is a UI projection of the live slugs — `{"schemaVersion": 1, "slugs": [...], "updatedAt"}`, rebuilt atomically by `team-db sync` (and refreshed by `team-db delete`); readers accept the legacy `{"slug"}` shape forever, and nothing but the projection writes the file. Hooks take the slug from `TEAM_TASK_SLUG` (the orchestrator passes it on every hook call); the pointer fallback refuses with `ok:false` / `active-task-pointer-ambiguous` when more than one slug is live, so an omitted env can never act on the wrong task. The Claude autoroute prompt face wraps unchained prompts while the live-slug count is below `AI_RULES_MAX_PARALLEL_TASKS` (read through `node .ai.local/scripts/settings.mjs get AI_RULES_MAX_PARALLEL_TASKS`; default `4`, `0` = unlimited); a prompt that names an existing slug or is a resume intent routes to `/task-continue <slug>` regardless of the cap.
36
+
37
+ Gate evidence is scoped to the task. `gitSnapshot()` keeps `environmentHash` as the whole-tree capture (diagnostic only) and adds `scopeHash`, `scopePaths`, and `scopeBasis` (`write-scope` when `.ai.local/team/.write-scope/<slug>/` baselines exist, `whole-tree` when none exist and at most one slug is live, `none` otherwise). Freshness binds to `scopeHash` on a `write-scope` basis; basis `none` is not fresh (`scope-unbound`). `yarn check:task <slug>` with no baseline and more than one live slug exits 2 with `E_NO_TASK_BASELINE` and names `yarn check:task <slug> --save-baseline`; a solo tree keeps today's warning and the repo-wide diff. `/task-continue <slug>` removes only `.ai.local/team/tasks/<slug>/STOP`. `/task-continue --all` is the repo-level resume: it removes `.ai.local/STOP`, `.ai.local/ESTOP`, and every per-slug `STOP`, with one `.memlog.md` line per slug.
38
+
39
+ A task can run in its own git worktree without a second team store. `node .ai.local/scripts/task-worktree.mjs create <slug>` (also `list`, `remove <slug> [--force]`) adds `.ai.local/worktrees/<slug>` on branch `task/<slug>`, copies `scripts/`, `rules/`, `conventions.md`, and `.env` read-only, and best-effort symlinks `.ai.local/team` at the main store. A refused symlink warns and leaves env-only binding. The activation line is `AI_RULES_TEAM_ROOT=<abs main team root>`; the chain hook, `team-db` open, and `check-preset-delta` read that name before the cwd default (`AI_RULES_TEAM_DB_ROOT` stays the legacy fallback). `list` shows slug, branch, path, live or terminal state, and the resolved store. `remove` refuses a live slug and an unmerged branch; `--force` says it is deleting that branch. Re-creating a complete pair and removing an already-removed pair both exit 0. Git failures are printed verbatim and left for `git worktree prune`. Hold create through `processes.mjs run --name worktree --task <slug> --`. The scheduler stays in the main checkout. `.ai.local/.gitignore` ignores `worktrees/`.
40
+
41
+ Repo-global locks queue instead of colliding. An existing `team.db` switches to `journal_mode=WAL` on the next writable open (`ensureWal` after migrations, outside any transaction; a contended switch retries once on `SQLITE_BUSY`, logs one `E_WAL_DEFERRED` line, and the next open retries). `AI_RULES_TEAM_DB_BUSY_MS` is the connection `busy_timeout` in milliseconds (integer, default `5000`; an invalid value warns once and uses the default). `yarn fix:generated` waits up to 30000 ms for the preset-tree lock when neither `--wait` nor `AI_RULES_LOCK_WAIT_MS` is set (`--wait` wins over the env, and `0` stays fail-fast); `run-locked.mjs` and the shell gates stay fail-fast. `processes.mjs start`, `run`, and `acquire` with `--task <slug>` hold `leases/<name>#<slug>.json` (the JSON `name` stays `<name>`, `owner.task` stays the slug), so two tasks can hold `dev-server#a` and `dev-server#b`. `stop` and `list --name <name>` match `<name>.json` and every `<name>#*.json`. `stop --task <slug>` stays a tag filter.
42
+
35
43
  ### Project MCP catalog
36
44
 
37
45
  `init mcp` writes the third-party servers this package ships plus Storybook, DefectDojo, and the packaged GitLab / GitHub / Yandex runtime entries into every installed client; `--tools` narrows the list to the clients you name. Entries render in each client's native shape and merge like `init`: extra servers, the consumer's `env` / `headers`, and other top-level keys stay. Names: `context7`, `playwright` (Claude's id is `playwright-test`), `chrome-devtools`, `next-devtools`, `semgrep`, `sentry`, `figma-desktop` (alias `figma`, the local `http://127.0.0.1:3845/mcp` server), `figma-cloud` (the remote `https://mcp.figma.com/mcp` server), `storybook` (`http://localhost:6200/mcp`), `defectdojo`, `gitlab`, `github`, `yandex-tracker`, and `yandex-wiki`; `--all` selects every one. The last five are packaged runtime entries: they are registered without credentials and need `mcp setup <provider>` once (DefectDojo reads `.env.defectdojo`). Next.js DevTools needs a running `next dev` on Next.js 16+; Semgrep needs the `semgrep` CLI; Sentry uses OAuth.
@@ -76,6 +76,10 @@ const ENGINE_SCRIPTS = [
76
76
  // of the self-learning loop modules.
77
77
  'process-lease.mjs',
78
78
  'processes.mjs',
79
+ // Per-task git worktree: `create` / `list` / `remove`. Seeds the worktree
80
+ // `.ai.local` and prints `AI_RULES_TEAM_ROOT` for the one main store. Shells
81
+ // out to git, so it is not part of the self-learning loop modules.
82
+ 'task-worktree.mjs',
79
83
  // `/rr-scheduler-start`: stop a recorded scheduler, then start
80
84
  // `team-db.mjs schedule` through the process manager.
81
85
  'rr-scheduler-start.mjs',
@@ -101,6 +105,9 @@ const ENGINE_SCRIPTS = [
101
105
  // invocations, grouped by the attempt windows `metrics.json` records. Reads
102
106
  // the output-guard ledgers and writes nothing, so it ships with the engine.
103
107
  'report-step-cost.mjs',
108
+ // The only reader of `.ai.local/.env` (`get <key>` / `list [--json]`). A hook
109
+ // imports it through an injected resolver; a broken file resolves to `false`.
110
+ 'settings.mjs',
104
111
  ];
105
112
 
106
113
  /** Package `presets/`-relative directory holding the engine source of truth. */
@@ -55,8 +55,13 @@ const AI_LOCAL_GITIGNORE = [
55
55
  '.ui/',
56
56
  '# Dev-server lifecycle markers (`.ai.local/.dev/<name>.json`); local runtime state, never commit.',
57
57
  '.dev/',
58
+ '# Per-machine settings. A committed `true` enables git writes on every clone.',
59
+ '# `.env.example` stays tracked. Remove this line to opt in to committing `.env`.',
60
+ '.env',
58
61
  // Process leases, their event log, and captured logs; local runtime state.
59
62
  '.processes/',
63
+ '# Per-task git worktrees; local checkouts, never commit.',
64
+ 'worktrees/',
60
65
  '',
61
66
  ].join('\n');
62
67
  const POINTER_README = `# Agent team artifacts moved
@@ -475,6 +480,38 @@ function seedConventions(presetTeamSrc, cwd) {
475
480
  return '.ai.local/conventions.md';
476
481
  }
477
482
 
483
+ /**
484
+ * `<presets>/_shared/ai-local` for a `<presets>/<platform>/<stack>/team` source.
485
+ * The settings template and the engine scripts are shared across platforms, so
486
+ * they are read from `_shared/` rather than the per-stack `ai-local/` tree.
487
+ */
488
+ function sharedAiLocalDir(presetTeamSrc) {
489
+ return path.join(path.resolve(presetTeamSrc, '..', '..', '..'), '_shared', 'ai-local');
490
+ }
491
+
492
+ /**
493
+ * Seed `.ai.local/.env.example` from the shared preset template. Never
494
+ * overwrites an existing consumer file and never creates `.ai.local/.env`.
495
+ *
496
+ * @returns {string | null} the rel this call wrote
497
+ */
498
+ function seedSettings(presetTeamSrc, cwd) {
499
+ if (!presetTeamSrc) {
500
+ return null;
501
+ }
502
+ const template = path.join(sharedAiLocalDir(presetTeamSrc), 'env.example');
503
+ if (!fs.existsSync(template)) {
504
+ return null;
505
+ }
506
+ const dest = path.join(cwd, '.ai.local', '.env.example');
507
+ if (fs.existsSync(dest)) {
508
+ return null;
509
+ }
510
+ copyFile(template, dest);
511
+ console.log('Seeded .ai.local/.env.example');
512
+ return '.ai.local/.env.example';
513
+ }
514
+
478
515
  /**
479
516
  * Seed `.ai.local/rules-library/` from `presets/<opt>/<stack>/ai-local/rules-library/`.
480
517
  * Opt-in discipline rules the consumer enables by moving a file into
@@ -770,6 +807,7 @@ function templateEntries(presetTeamSrc, source) {
770
807
  const presetBase = path.dirname(presetTeamSrc);
771
808
  const libraryDir = path.join(presetBase, 'ai-local', 'rules-library');
772
809
  addFile('.ai.local/conventions.md', path.join(presetBase, 'ai-local', 'conventions.md'));
810
+ addFile('.ai.local/.env.example', path.join(sharedAiLocalDir(presetTeamSrc), 'env.example'));
773
811
  addDir('.ai.local/rules-library/', libraryDir, (name) => name.endsWith('.md'));
774
812
  // The activation seed is a template byte too: `activateRouterPagesSeed` copies it
775
813
  // into `rules/` when the repo shape matches, and an active copy shipped by the
@@ -854,6 +892,7 @@ function seedAiLocalTeam({ cwd, presetTeamSrc, source, packageVersion, mergeAiLo
854
892
  const templateWritten = copyTemplates(presetTeamSrc, dest);
855
893
  const modelTiersRel = seedModelTiers(presetTeamSrc, dest, source);
856
894
  const conventionsRel = seedConventions(presetTeamSrc, cwd);
895
+ const settingsRel = seedSettings(presetTeamSrc, cwd);
857
896
  const rulesSeed = seedAiLocalRules(presetTeamSrc, cwd);
858
897
  const rulesLibrarySeeded = rulesSeed.seeded;
859
898
  if (!freshPaths.includes(path.join(aiLocalRoot, 'rules'))) {
@@ -864,6 +903,7 @@ function seedAiLocalTeam({ cwd, presetTeamSrc, source, packageVersion, mergeAiLo
864
903
  ...templateWritten,
865
904
  ...(modelTiersRel ? [modelTiersRel] : []),
866
905
  ...(conventionsRel ? [conventionsRel] : []),
906
+ ...(settingsRel ? [settingsRel] : []),
867
907
  ...rulesSeed.written,
868
908
  ...engine.written,
869
909
  ...(ignoreCreated ? ['.ai.local/.gitignore'] : []),
@@ -212,11 +212,12 @@ function mergeInstructionList(existingInstructions, presetInstructions) {
212
212
  }
213
213
 
214
214
  /**
215
- * Universal "human commits" guards. Source of truth is
216
- * `scripts/lib/stack-platform-profiles.mjs` (`UNIVERSAL_BASH_PERMISSION`); the
217
- * published `files` allowlist does not ship `scripts/`, so the list is duplicated
218
- * and set-equality is asserted by `scripts/check-opencode-platform-contract.mjs`.
219
- * The bare forms are listed because `git commit *` does not match `git commit`.
215
+ * Universal git-write guards. Source of truth is
216
+ * `scripts/lib/stack-platform-profiles.mjs` (`UNIVERSAL_GUARD_ROWS`); the
217
+ * published `files` allowlist does not ship `scripts/`, so the list is
218
+ * duplicated and set-equality is asserted by
219
+ * `scripts/check-opencode-platform-contract.mjs`. The bare forms are listed
220
+ * because `git commit *` does not match `git commit`.
220
221
  */
221
222
  const UNIVERSAL_GUARD_PATTERNS = ['git commit', 'git commit *', 'git push', 'git push *'];
222
223
 
@@ -245,12 +246,12 @@ function mergePermission(existingPermission, presetPermission) {
245
246
  return merged;
246
247
  }
247
248
  merged.bash = { ...presetBash, ...prior };
248
- // The universal guards are the exception to consumer-wins: a pre-existing
249
- // `"git push *": "allow"` must not defeat them. Scoped to these rows only —
250
- // every other key, including the package-manager `ask` guards, stays
249
+ // The universal guard rows are the exception to consumer-wins: a pre-existing
250
+ // `"git push *": "allow"` must not defeat the static `ask`. Scoped to these
251
+ // rows only — every other key, including the package-manager guards, stays
251
252
  // consumer-wins, so this is not a global precedence inversion.
252
253
  for (const pattern of UNIVERSAL_GUARD_PATTERNS) {
253
- if (presetBash[pattern] === 'deny') merged.bash[pattern] = 'deny';
254
+ if (presetBash[pattern]) merged.bash[pattern] = presetBash[pattern];
254
255
  }
255
256
  if (foldedShell) delete merged.shell;
256
257
  return merged;
@@ -282,7 +283,7 @@ function mergeOpencodeConfig(presetObj, existingObj) {
282
283
  merged.mcp = mergedMcp;
283
284
  // Re-init re-asserts preset instruction paths and missing bash keys so an
284
285
  // upgrade is picked up. Consumer extras and same-key overrides stay, except the
285
- // universal guard rows, which mergePermission re-applies as `deny`.
286
+ // universal guard rows, which mergePermission re-applies from the preset.
286
287
  // A non-array `instructions` or non-object `permission` is left untouched.
287
288
  const prevInstructions = merged.instructions;
288
289
  const instructions = mergeInstructionList(prevInstructions, preset.instructions);
package/docs/OPENCODE.md CHANGED
@@ -78,7 +78,7 @@ printf '%s\n' '{"status":"completed","attemptId":"<from-status.json>"}' \
78
78
  | TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh
79
79
  ```
80
80
 
81
- Human gates pause with `awaitingHumanGate: true`. Resume with `/task-continue`. There is **no** shipped `hooks.json`: on OpenCode v2.4.1 `ctx.session.hook` dispatches `context` / `compaction` / `generate` / `prompt` only, so no plugin observes a subagent return and the chain stays a manual run. The shipped plugins are `task-status` (TUI), `output-guard` (compaction) and `rule-attach` (path-glob rule delivery).
81
+ Human gates pause with `awaitingHumanGate: true`. Resume with `/task-continue`. There is **no** shipped `hooks.json`: on OpenCode v2.4.1 `ctx.session.hook` dispatches `context` / `compaction` / `generate` / `prompt` only, so no plugin observes a subagent return and the chain stays a manual run. The `task-status` plugin writes this tab's pin to `.ai.local/team/.session-leases/<sessionID>.json` and tries to set `AI_RULES_SESSION_ID` on `shell.env`. That registration is best-effort: if the host rejects the name, the lease file remains, and a later hook call in the same tab resolves the pin when the session id is already in the environment. `active-task.json` stays the list of live slugs. The other shipped plugins are `output-guard` (compaction) and `rule-attach` (path-glob rule delivery).
82
82
 
83
83
  Full team layout: `.ai.local/team/README.md`.
84
84
 
@@ -108,8 +108,12 @@ including one without `/task`.
108
108
 
109
109
  - Reads the nearest `.ai.local/team/` above the session directory and maps the
110
110
  active session to a task by its user messages.
111
- - Renders slug, state, elapsed time, current step, and a soft-stop button in the
112
- TUI `sidebar.content` slot. Toggle the sidebar with `ctrl+x b`.
111
+ - Renders slug, state, the `work`/`gate`/`paused`/`sleep`/`idle` time split, current
112
+ step, and a soft-stop button in the TUI `sidebar.content` slot. Toggle the sidebar
113
+ with `ctrl+x b`. The split comes from `metrics.json`: `attempt_finished.activeMs`
114
+ (wall time minus gate, pause and host-suspension intervals), paired gate and
115
+ `task_paused`/`task_resumed` events, and the `.suspend.jsonl` gaps the plugin
116
+ records when the wall clock outruns a monotonic clock by more than 60s.
113
117
  - Shows a `~p50 · p90` estimate for the remaining steps, built from the attempt
114
118
  durations of every ledger under the team root; hidden on a human gate, pause,
115
119
  stale run, or completion. It estimates agent work, not wall-clock time.
@@ -139,7 +143,7 @@ Labels from official OpenCode docs (live CLI probe not yet run). Full matrix: [`
139
143
  | `.opencode/agents` / `skills` / `commands` | **confirmed** (docs) | Native discovery |
140
144
  | `opencode.json` MCP | **confirmed** (docs) | Merge `mcp` |
141
145
  | Glob / alwaysApply rules | **no-equivalent** | No host glob engine; `rule-attach` injects the stems whose stack `globs.json` matches a touched path (file tools and a `bash`/`shell` path token), and a stem with no glob stays a lazy Read |
142
- | `hooks.json` / subagentStop | **manual** | `TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh` after receipts; the `task-status` TUI plugin is a viewer, not a hook |
146
+ | `hooks.json` / subagentStop | **manual** | `TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh` after receipts. `task-status` pins the tab in `.session-leases/<sessionID>.json`; it does not run the chain |
143
147
  | Native Team lifecycle | **partial** | File pipeline is SoT; hook is single lifecycle writer |
144
148
 
145
149
  Do not pin OpenCode CLI or TUI versions in the contract.
@@ -623,7 +623,7 @@
623
623
  "tasks"
624
624
  ],
625
625
  "summary": "Delete one task: the task folder first, then its projection rows",
626
- "description": "Confirmed, destructive and irreversible. The task folder `.ai.local/team/tasks/{slug}` is removed before the database rows, so a crash between the two legs converges toward deleted on the next rescan and never resurrects content. The row delete is one transaction: the task row plus every child row by cascade, plus the task's search rows. The slug in `active-task.json` is refused with 409 `E_ACTIVE_TASK`. An unknown slug answers 404 `E_NOT_FOUND` and touches nothing. The request body is ignored and no query parameters are declared. Executed as a bounded child process; `AI_RULES_TEAM_DB_DISABLE=1` answers 503 `E_DISABLED` before anything runs.",
626
+ "description": "Confirmed, destructive and irreversible. The task folder `.ai.local/team/tasks/{slug}` is removed before the database rows, so a crash between the two legs converges toward deleted on the next rescan and never resurrects content. The row delete is one transaction: the task row plus every child row by cascade, plus the task's search rows. A slug whose own `status.json` state is live (not one of the terminal states) is refused with 409 `E_ACTIVE_TASK` — the guard reads the requested slug's status, never the `active-task.json` pointer. An unknown slug answers 404 `E_NOT_FOUND` and touches nothing. The request body is ignored and no query parameters are declared. Executed as a bounded child process; `AI_RULES_TEAM_DB_DISABLE=1` answers 503 `E_DISABLED` before anything runs.",
627
627
  "operationId": "deleteTask",
628
628
  "parameters": [
629
629
  {
@@ -697,7 +697,7 @@
697
697
  }
698
698
  },
699
699
  "409": {
700
- "description": "The slug is the active task; the delete is refused with `details.activeSlug` naming it",
700
+ "description": "The slug is live (its own `status.json` state is not terminal); the delete is refused with `details.activeSlug` naming it",
701
701
  "content": {
702
702
  "application/json": {
703
703
  "schema": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.87",
3
+ "version": "0.2.90",
4
4
  "description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
5
5
  "license": "MIT",
6
6
  "author": "Revy Ross",
@@ -0,0 +1,54 @@
1
+ # ai-rules settings — `.ai.local/.env`
2
+ #
3
+ # Consumer-owned. `init` seeds this example once (skip-if-exists) and never
4
+ # creates or edits `.ai.local/.env`; copy the keys you want into that file.
5
+ # Two keys are booleans, both default to `false`. Only a bare `true` or `1`
6
+ # turns one on. `false` and `0` are the silent off spellings. Quoted `"true"`,
7
+ # an `export` prefix, a trailing comment, and every other value warn and read
8
+ # as `false`. A broken or missing `.ai.local/.env` also reads as `false`,
9
+ # never as a permission.
10
+ #
11
+ # The third key is `AI_RULES_MAX_PARALLEL_TASKS`, a non-negative integer
12
+ # (default `4`, `0` = unlimited). A non-numeric value warns and stays `4`.
13
+ #
14
+ # The seeded `.ai.local/.gitignore` ignores `.env` and tracks `.env.example`.
15
+ # Committing `.env` is an opt-in: remove that line, then add the file. A
16
+ # committed `true` enables git writes on every clone.
17
+ #
18
+ # AI_RULES_ALLOW_GIT_WRITES (boolean, default false)
19
+ # true — a plain `git commit` / `git push` is answered `allow`; destructive,
20
+ # delete/force, alias and autonomous shapes are asked instead.
21
+ # false — `git commit` / `git push` are asked. Cursor (`beforeShellExecution`)
22
+ # and Claude (`PreToolUse`) run the shell guard. OpenCode applies the
23
+ # same verdict from `.opencode/plugins/settings-guard/` (`allow` lifts
24
+ # the static ask; `ask` keeps the prompt). An OpenCode host that has
25
+ # no permission hook throws instead, so the command does not run.
26
+ # Mavis and ZCode have no blocking hook; the flag is prose there.
27
+ # Verbs outside `commit`/`push`/`reset`/`clean`/`checkout` are not gated by this flag.
28
+ # A `true` value does not force an unattended commit: destructive and
29
+ # autonomous shapes are asked, and the host may still gate by its own static
30
+ # layer (G-OQ1).
31
+ # An autonomous `/task-evil` run also ignores this key: the command refuses to
32
+ # start at `true` and writes `.ai.local/team/.task-evil`, which makes the shell
33
+ # guard ask for git writes; the OpenCode profile keeps a hard `deny`.
34
+ #
35
+ # Limit: this is a pattern-based guard. Deliberate token-splitting or
36
+ # indirection — `g""it`, `g\it`, `\git`, `gi\<newline>t`, `eval "\x69t…"`,
37
+ # `C=git; $C`, `base64 -d | sh` — is outside its reach by design.
38
+ #
39
+ # AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS (boolean, default false)
40
+ # true — a prompt that arrives outside the task chain is wrapped into `/task`
41
+ # while the live-slug count is below `AI_RULES_MAX_PARALLEL_TASKS`.
42
+ # Claude does this in `UserPromptSubmit`. OpenCode does it in the
43
+ # settings-guard plugin's `prompt` hook. Cursor, Mavis and ZCode have
44
+ # no prompt hook; the agent follows the same check in the entry prose.
45
+ # false — the prompt face writes nothing.
46
+ #
47
+ # AI_RULES_MAX_PARALLEL_TASKS (integer, default 4)
48
+ # How many live slugs the autoroute may wrap at once. `0` is unlimited.
49
+ # Absent, blank, or non-numeric values stay at `4` (a non-numeric value warns).
50
+ #
51
+ # Accepted spelling, uncommented in `.ai.local/.env`:
52
+ # AI_RULES_ALLOW_GIT_WRITES=false
53
+ # AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS=false
54
+ # AI_RULES_MAX_PARALLEL_TASKS=4
@@ -39,6 +39,10 @@ const tasksDir = path.join(teamRoot, 'tasks');
39
39
  // An attempt this long almost always contains human wait (an overnight pause, a
40
40
  // gate decision answered between attempts) that no gate event covers.
41
41
  const LONG_ATTEMPT_MS = 3 * 60 * 60 * 1000;
42
+ // Mirrors the hook's `AI_RULES_ATTEMPT_MAX_MS`: work beyond it is suspension, a
43
+ // hang, or a stop that arrived days after the agent died. Legacy events without
44
+ // `activeMs` are capped here, so old ledgers stop poisoning the averages.
45
+ const MAX_ATTEMPT_MS = 4 * 60 * 60 * 1000;
42
46
  const incomplete = [];
43
47
  const attempts = [];
44
48
  const tasks = [];
@@ -204,6 +208,7 @@ function collect(metrics, filePath) {
204
208
  const gateStarts = new Map();
205
209
  const terminalAttempts = new Set();
206
210
  const attemptDurations = [];
211
+ const attemptWalls = [];
207
212
  const taskLongAttempts = [];
208
213
  const hostUsage = new Map();
209
214
  const usageEventsByAttempt = new Map();
@@ -212,6 +217,8 @@ function collect(metrics, filePath) {
212
217
  let taskStartedAt = null;
213
218
  let taskCompletedAt = null;
214
219
  let taskGateWaitMs = 0;
220
+ let taskPausedMs = 0;
221
+ let pauseStartedAt = null;
215
222
  let taskOutOfBandMs = 0;
216
223
  let taskOutOfBandCount = 0;
217
224
  let taskUsage = emptyUsageTotal();
@@ -264,13 +271,20 @@ function collect(metrics, filePath) {
264
271
  attributionConfidence,
265
272
  (attributionConfidenceCounts.get(attributionConfidence) ?? 0) + 1,
266
273
  );
267
- if (Number.isFinite(event.durationMs)) attemptDurations.push(event.durationMs);
274
+ const activeMs = Number.isFinite(event.activeMs)
275
+ ? event.activeMs
276
+ : Number.isFinite(event.durationMs)
277
+ ? Math.min(event.durationMs, MAX_ATTEMPT_MS)
278
+ : null;
279
+ if (activeMs !== null) attemptDurations.push(activeMs);
280
+ if (Number.isFinite(event.durationMs)) attemptWalls.push(event.durationMs);
268
281
  if (Number.isFinite(event.durationMs) && event.durationMs > LONG_ATTEMPT_MS) {
269
282
  const longAttempt = {
270
283
  slug: metrics.task.slug,
271
284
  attemptId: event.attemptId,
272
285
  agent: start.agent ?? 'unknown',
273
286
  durationMs: event.durationMs,
287
+ activeMs,
274
288
  };
275
289
  taskLongAttempts.push(longAttempt);
276
290
  longAttempts.push(longAttempt);
@@ -286,6 +300,8 @@ function collect(metrics, filePath) {
286
300
  agent: start.agent ?? 'unknown',
287
301
  role: start.role ?? 'unknown',
288
302
  durationMs: Number.isFinite(event.durationMs) ? event.durationMs : null,
303
+ activeMs,
304
+ idleMs: Number.isFinite(event.idleMs) ? event.idleMs : null,
289
305
  outcome: event.outcome ?? 'unknown',
290
306
  attributionConfidence,
291
307
  usage,
@@ -311,6 +327,12 @@ function collect(metrics, filePath) {
311
327
  if (event.type === 'human_gate_started' && event.eventId) {
312
328
  gateStarts.set(event.eventId, event);
313
329
  }
330
+ if (event.type === 'task_paused' && pauseStartedAt === null) pauseStartedAt = event.at;
331
+ if (event.type === 'task_resumed' && pauseStartedAt !== null) {
332
+ const paused = Date.parse(event.at) - Date.parse(pauseStartedAt);
333
+ if (Number.isFinite(paused) && paused >= 0) taskPausedMs += paused;
334
+ pauseStartedAt = null;
335
+ }
314
336
  if (event.type === 'human_gate_ended') {
315
337
  const start = event.gateStartedEventId ? gateStarts.get(event.gateStartedEventId) : undefined;
316
338
  const elapsed = start ? Date.parse(event.at) - Date.parse(start.at) : NaN;
@@ -338,15 +360,22 @@ function collect(metrics, filePath) {
338
360
 
339
361
  if (taskCompleted && !ledgerIncomplete) tasks.push(metrics.task);
340
362
  if (taskStartedAt) {
363
+ const elapsedMs = taskCompletedAt ? Date.parse(taskCompletedAt) - Date.parse(taskStartedAt) : null;
364
+ const activeMs = attemptDurations.reduce((sum, value) => sum + value, 0);
341
365
  taskReports.push({
342
366
  ...metrics.task,
343
- elapsedMs: taskCompletedAt ? Date.parse(taskCompletedAt) - Date.parse(taskStartedAt) : null,
344
- activeMs: attemptDurations.reduce((sum, value) => sum + value, 0),
367
+ elapsedMs,
368
+ activeMs,
345
369
  gateWaitMs: taskGateWaitMs,
370
+ pausedMs: taskPausedMs,
371
+ // Whatever the ledger cannot attribute to work, a gate or a pause.
372
+ idleMs: elapsedMs === null ? null : Math.max(0, elapsedMs - activeMs - taskGateWaitMs - taskPausedMs - taskOutOfBandMs),
346
373
  outOfBandMs: taskOutOfBandMs,
347
374
  outOfBandCount: taskOutOfBandCount,
348
375
  attemptCount: terminalAttempts.size,
349
- longestAttemptMs: attemptDurations.length ? Math.max(...attemptDurations) : null,
376
+ // Wall clock, so a flagged long attempt still reports what it was.
377
+ longestAttemptMs: attemptWalls.length ? Math.max(...attemptWalls) : null,
378
+ longestActiveAttemptMs: attemptDurations.length ? Math.max(...attemptDurations) : null,
350
379
  longAttemptCount: taskLongAttempts.length,
351
380
  completed: taskCompleted,
352
381
  incomplete: ledgerIncomplete,
@@ -391,7 +420,7 @@ const byAgentRole = groupBy(
391
420
  (item) => `${item.platform}|${item.stack}|${item.preset}|${item.agent}|${item.role}`,
392
421
  ).map((group) => {
393
422
  const sample = group[0];
394
- const durations = group.map((item) => item.durationMs).filter((value) => value !== null);
423
+ const durations = group.map((item) => item.activeMs).filter((value) => value !== null);
395
424
  const sumDurationMs = durations.reduce((sum, value) => sum + value, 0);
396
425
  const usageTotal = group.reduce((total, item) => addUsage(total, item.usage), emptyUsageTotal());
397
426
  return {
@@ -25,9 +25,11 @@
25
25
  * `prompt.md`, `goal.md`), because the chain hook rewrites `status.json` on
26
26
  * every step and a rewritten status must not make a legacy folder look new.
27
27
  *
28
- * The slug named by `active-task.json` is excluded and printed: its intake is
29
- * still in flight, the same exclusion the backfill applies (architecture §8.4),
30
- * so it is judged once the task closes.
28
+ * Every live slug is excluded and printed: its intake is still in flight, the
29
+ * same exclusion the backfill applies (architecture §8.4), so it is judged
30
+ * once the task closes. A slug is live when its own `status.json` parses to a
31
+ * non-terminal state — the pointer `active-task.json` is never read, so the
32
+ * audit stays correct with several slugs live in one repo.
31
33
  *
32
34
  * Usage: node scripts/check-task-repositories.mjs [--tasks-root <dir>]
33
35
  * [--registry <file>] [--cutoff YYYY-MM-DD] [--json]
@@ -37,6 +39,9 @@ import fs from 'node:fs';
37
39
  import path from 'node:path';
38
40
  import { fileURLToPath } from 'node:url';
39
41
 
42
+ /** Terminal `status.json` states — the set the hook and autoroute templates pin. */
43
+ const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
44
+
40
45
  const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
41
46
  // Two homes: `packages/ai-rules/scripts` in this repository, and
42
47
  // `<repo>/.ai.local/scripts` once `init` ships it to a consumer, where the task
@@ -136,9 +141,6 @@ function readJson(file) {
136
141
  }
137
142
  }
138
143
 
139
- /** `readJson` returns `undefined` for a parse error and `null` for a non-object. */
140
- const unusableJson = (value) => value === undefined || value === null;
141
-
142
144
  /** The registry's view of one slug: the ids its links name, sorted. */
143
145
  function linkedIds(registry, slug) {
144
146
  if (registry === null) return null;
@@ -159,16 +161,23 @@ function main() {
159
161
  console.log(`task-repositories: OK (no task store at ${args.tasksRoot})`);
160
162
  return;
161
163
  }
162
- const activeTaskFile = path.join(path.dirname(args.tasksRoot), 'active-task.json');
163
- let activeSlug = null;
164
- if (fs.existsSync(activeTaskFile)) {
165
- const active = readJson(activeTaskFile);
166
- if (active === undefined) {
167
- warnings.push('active-task.json is not valid JSON; no slug excluded as in-flight');
168
- } else if (!unusableJson(active) && typeof active.slug === 'string') {
169
- activeSlug = active.slug;
164
+ const folders = fs
165
+ .readdirSync(args.tasksRoot, { withFileTypes: true })
166
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))
167
+ .map((entry) => entry.name)
168
+ .sort();
169
+
170
+ // The live-slug scan over the task store — never the `active-task.json`
171
+ // pointer, so several slugs can be in flight in one repo. An unreadable or
172
+ // missing `status.json` is not a live slug.
173
+ const liveSlugs = new Set();
174
+ for (const name of folders) {
175
+ const status = readJson(path.join(args.tasksRoot, name, 'status.json'));
176
+ if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) {
177
+ liveSlugs.add(name);
170
178
  }
171
179
  }
180
+
172
181
  let registry = fs.existsSync(args.registry) ? readJson(args.registry) : null;
173
182
  if (registry === undefined) usageError(`--registry is not valid JSON: ${args.registry}`);
174
183
  if (registry !== null && (!Array.isArray(registry.repositories) || !Array.isArray(registry.links))) {
@@ -177,12 +186,6 @@ function main() {
177
186
  }
178
187
  const knownIds = registry === null ? null : new Set(registry.repositories.map((record) => record.id));
179
188
 
180
- const folders = fs
181
- .readdirSync(args.tasksRoot, { withFileTypes: true })
182
- .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))
183
- .map((entry) => entry.name)
184
- .sort();
185
-
186
189
  const violations = [];
187
190
  const legacy = [];
188
191
  const excluded = [];
@@ -191,7 +194,7 @@ function main() {
191
194
  const folder = path.join(args.tasksRoot, name);
192
195
  const pipelinePath = path.join(folder, 'pipeline.json');
193
196
  if (!fs.existsSync(pipelinePath)) continue;
194
- if (name === activeSlug) {
197
+ if (liveSlugs.has(name)) {
195
198
  excluded.push(name);
196
199
  continue;
197
200
  }
@@ -249,7 +252,7 @@ function main() {
249
252
 
250
253
  const summary = `${folders.length} task folders, ${checked} with pipeline.json${
251
254
  legacy.length > 0 ? `, legacy before ${args.cutoff}: ${legacy.length}` : ''
252
- }${excluded.length > 0 ? `, excluded (active): ${excluded.join(', ')}` : ''}`;
255
+ }${excluded.length > 0 ? `, excluding live: ${excluded.join(', ')}` : ''}`;
253
256
  for (const warning of warnings) console.error(`WARN ${warning}`);
254
257
  if (args.json) {
255
258
  console.log(
@@ -41,7 +41,7 @@ const GUARD_STALE_MS = 30000;
41
41
  * flight is never stolen.
42
42
  */
43
43
  const LEASE_WARM_MS = 5000;
44
- const NAME_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
44
+ const NAME_PATTERN = /^[a-z0-9][a-z0-9._#-]{0,63}$/;
45
45
  const KINDS = new Set(['exclusive', 'port', 'advisory']);
46
46
 
47
47
  const newToken = () => crypto.randomBytes(12).toString('hex');
@@ -293,6 +293,7 @@ const describeOwner = (record) => {
293
293
  export function acquireLease({
294
294
  aiLocalRoot,
295
295
  name,
296
+ storedName = null,
296
297
  kind = 'exclusive',
297
298
  port = null,
298
299
  label = null,
@@ -331,7 +332,7 @@ export function acquireLease({
331
332
  const startedAt = new Date().toISOString();
332
333
  return {
333
334
  schemaVersion: LEASE_SCHEMA_VERSION,
334
- name,
335
+ name: storedName ?? name,
335
336
  kind,
336
337
  owner: {
337
338
  pid,