@bonesofspring/ai-rules 0.2.87 → 0.2.91

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 (470) hide show
  1. package/CHANGELOG.md +83 -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-COMPATIBILITY.md +2 -1
  7. package/docs/OPENCODE.md +27 -5
  8. package/docs/openapi/team-db.v1.json +2 -2
  9. package/package.json +1 -1
  10. package/presets/_shared/ai-local/env.example +54 -0
  11. package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +34 -5
  12. package/presets/_shared/ai-local/scripts/check-task-repositories.mjs +25 -22
  13. package/presets/_shared/ai-local/scripts/process-lease.mjs +3 -2
  14. package/presets/_shared/ai-local/scripts/processes.mjs +52 -20
  15. package/presets/_shared/ai-local/scripts/run.mjs +38 -6
  16. package/presets/_shared/ai-local/scripts/settings.mjs +246 -0
  17. package/presets/_shared/ai-local/scripts/task-worktree.mjs +364 -0
  18. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +2 -2
  19. package/presets/_shared/ai-local/scripts/team-db-project.mjs +87 -14
  20. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +102 -12
  21. package/presets/_shared/ai-local/scripts/team-db-tracker.mjs +35 -0
  22. package/presets/_shared/ai-local/scripts/tracker-planned-drain.mjs +10 -1
  23. package/presets/_shared/ai-local/scripts/verification.mjs +106 -11
  24. package/presets/_shared/core/agent-team/agent-task-metrics.md +10 -2
  25. package/presets/_shared/core/agent-team/agent-team-intake.md +2 -0
  26. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +2 -2
  27. package/presets/_shared/core/meta/preset-writing-style.md +8 -0
  28. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +541 -61
  29. package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +733 -9
  30. package/presets/_shared/hooks/prompt-autoroute.mjs.tmpl +153 -0
  31. package/presets/claude/android-kotlin/CLAUDE.md +2 -4
  32. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +541 -61
  33. package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +733 -9
  34. package/presets/claude/android-kotlin/hooks/prompt-autoroute.mjs +153 -0
  35. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-intake.md +2 -0
  36. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  37. package/presets/claude/android-kotlin/rules/tooling-and-review/preset-writing-style.md +8 -0
  38. package/presets/claude/android-kotlin/settings.json +15 -5
  39. package/presets/claude/go/CLAUDE.md +2 -4
  40. package/presets/claude/go/hooks/chain-team-phases.sh +541 -61
  41. package/presets/claude/go/hooks/guard-shell-command.mjs +733 -9
  42. package/presets/claude/go/hooks/prompt-autoroute.mjs +153 -0
  43. package/presets/claude/go/rules/tooling-and-review/agent-team-intake.md +2 -0
  44. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  45. package/presets/claude/go/rules/tooling-and-review/preset-writing-style.md +8 -0
  46. package/presets/claude/go/settings.json +15 -5
  47. package/presets/claude/ios-swift/CLAUDE.md +2 -4
  48. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +541 -61
  49. package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +733 -9
  50. package/presets/claude/ios-swift/hooks/prompt-autoroute.mjs +153 -0
  51. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-intake.md +2 -0
  52. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  53. package/presets/claude/ios-swift/rules/tooling-and-review/preset-writing-style.md +8 -0
  54. package/presets/claude/ios-swift/settings.json +15 -5
  55. package/presets/claude/java/CLAUDE.md +2 -4
  56. package/presets/claude/java/hooks/chain-team-phases.sh +541 -61
  57. package/presets/claude/java/hooks/guard-shell-command.mjs +733 -9
  58. package/presets/claude/java/hooks/prompt-autoroute.mjs +153 -0
  59. package/presets/claude/java/rules/tooling-and-review/agent-team-intake.md +2 -0
  60. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  61. package/presets/claude/java/rules/tooling-and-review/preset-writing-style.md +8 -0
  62. package/presets/claude/java/settings.json +15 -5
  63. package/presets/claude/mcp-ts/CLAUDE.md +2 -4
  64. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +541 -61
  65. package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +733 -9
  66. package/presets/claude/mcp-ts/hooks/prompt-autoroute.mjs +153 -0
  67. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-intake.md +2 -0
  68. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  69. package/presets/claude/mcp-ts/rules/tooling-and-review/preset-writing-style.md +8 -0
  70. package/presets/claude/mcp-ts/settings.json +15 -5
  71. package/presets/claude/mol/CLAUDE.md +2 -4
  72. package/presets/claude/mol/agents/feature-developer.md +1 -1
  73. package/presets/claude/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  74. package/presets/claude/mol/commands/task-evil.md +8 -0
  75. package/presets/claude/mol/hooks/chain-team-phases.sh +541 -61
  76. package/presets/claude/mol/hooks/guard-shell-command.mjs +733 -9
  77. package/presets/claude/mol/hooks/prompt-autoroute.mjs +153 -0
  78. package/presets/claude/mol/rules/tooling-and-review/agent-team-intake.md +2 -0
  79. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  80. package/presets/claude/mol/rules/tooling-and-review/preset-writing-style.md +8 -0
  81. package/presets/claude/mol/settings.json +15 -4
  82. package/presets/claude/next/CLAUDE.md +2 -4
  83. package/presets/claude/next/REPO_AGENTS.md +2 -0
  84. package/presets/claude/next/agents/feature-developer.md +1 -1
  85. package/presets/claude/next/agents/task-analyst.md +1 -7
  86. package/presets/claude/next/agents/task-router.md +1 -1
  87. package/presets/claude/next/ai-local/rules-library/commit-hygiene.md +1 -1
  88. package/presets/claude/next/commands/spec-start.md +3 -4
  89. package/presets/claude/next/commands/task-continue.md +9 -8
  90. package/presets/claude/next/commands/task-evil.md +8 -0
  91. package/presets/claude/next/commands/task.md +1 -1
  92. package/presets/claude/next/hooks/chain-team-phases.sh +541 -61
  93. package/presets/claude/next/hooks/guard-shell-command.mjs +733 -9
  94. package/presets/claude/next/hooks/prompt-autoroute.mjs +153 -0
  95. package/presets/claude/next/rules/tooling-and-review/agent-team-intake.md +2 -0
  96. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  97. package/presets/claude/next/rules/tooling-and-review/preset-writing-style.md +8 -0
  98. package/presets/claude/next/settings.json +15 -4
  99. package/presets/claude/next/team/README.md +1 -1
  100. package/presets/claude/nuxt/CLAUDE.md +2 -4
  101. package/presets/claude/nuxt/hooks/chain-team-phases.sh +541 -61
  102. package/presets/claude/nuxt/hooks/guard-shell-command.mjs +733 -9
  103. package/presets/claude/nuxt/hooks/prompt-autoroute.mjs +153 -0
  104. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-intake.md +2 -0
  105. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  106. package/presets/claude/nuxt/rules/tooling-and-review/preset-writing-style.md +8 -0
  107. package/presets/claude/nuxt/settings.json +15 -4
  108. package/presets/claude/php-hexagonal/CLAUDE.md +2 -4
  109. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  110. package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
  111. package/presets/claude/php-hexagonal/hooks/prompt-autoroute.mjs +153 -0
  112. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-intake.md +2 -0
  113. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  114. package/presets/claude/php-hexagonal/rules/tooling-and-review/preset-writing-style.md +8 -0
  115. package/presets/claude/php-hexagonal/settings.json +15 -5
  116. package/presets/claude/php-laravel/CLAUDE.md +2 -4
  117. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +541 -61
  118. package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +733 -9
  119. package/presets/claude/php-laravel/hooks/prompt-autoroute.mjs +153 -0
  120. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-intake.md +2 -0
  121. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  122. package/presets/claude/php-laravel/rules/tooling-and-review/preset-writing-style.md +8 -0
  123. package/presets/claude/php-laravel/settings.json +15 -5
  124. package/presets/claude/svelte/CLAUDE.md +2 -4
  125. package/presets/claude/svelte/hooks/chain-team-phases.sh +541 -61
  126. package/presets/claude/svelte/hooks/guard-shell-command.mjs +733 -9
  127. package/presets/claude/svelte/hooks/prompt-autoroute.mjs +153 -0
  128. package/presets/claude/svelte/rules/tooling-and-review/agent-team-intake.md +2 -0
  129. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +2 -2
  130. package/presets/claude/svelte/rules/tooling-and-review/preset-writing-style.md +8 -0
  131. package/presets/claude/svelte/settings.json +15 -4
  132. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +541 -61
  133. package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +733 -9
  134. package/presets/cursor/android-kotlin/rules/agent-team-intake.mdc +2 -0
  135. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
  136. package/presets/cursor/android-kotlin/rules/preset-writing-style.mdc +8 -0
  137. package/presets/cursor/go/hooks/chain-team-phases.sh +541 -61
  138. package/presets/cursor/go/hooks/guard-shell-command.mjs +733 -9
  139. package/presets/cursor/go/rules/agent-team-intake.mdc +2 -0
  140. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
  141. package/presets/cursor/go/rules/preset-writing-style.mdc +8 -0
  142. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +541 -61
  143. package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +733 -9
  144. package/presets/cursor/ios-swift/rules/agent-team-intake.mdc +2 -0
  145. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
  146. package/presets/cursor/ios-swift/rules/preset-writing-style.mdc +8 -0
  147. package/presets/cursor/java/hooks/chain-team-phases.sh +541 -61
  148. package/presets/cursor/java/hooks/guard-shell-command.mjs +733 -9
  149. package/presets/cursor/java/rules/agent-team-intake.mdc +2 -0
  150. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
  151. package/presets/cursor/java/rules/preset-writing-style.mdc +8 -0
  152. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +541 -61
  153. package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +733 -9
  154. package/presets/cursor/mcp-ts/rules/agent-team-intake.mdc +2 -0
  155. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
  156. package/presets/cursor/mcp-ts/rules/preset-writing-style.mdc +8 -0
  157. package/presets/cursor/mol/agents/feature-developer.md +1 -1
  158. package/presets/cursor/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  159. package/presets/cursor/mol/commands/task-evil.md +8 -0
  160. package/presets/cursor/mol/hooks/chain-team-phases.sh +541 -61
  161. package/presets/cursor/mol/hooks/guard-shell-command.mjs +733 -9
  162. package/presets/cursor/mol/rules/agent-team-intake.mdc +2 -0
  163. package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
  164. package/presets/cursor/mol/rules/preset-writing-style.mdc +8 -0
  165. package/presets/cursor/next/REPO_AGENTS.md +2 -0
  166. package/presets/cursor/next/agents/feature-developer.md +1 -1
  167. package/presets/cursor/next/agents/task-analyst.md +1 -7
  168. package/presets/cursor/next/agents/task-router.md +1 -1
  169. package/presets/cursor/next/ai-local/rules-library/commit-hygiene.md +1 -1
  170. package/presets/cursor/next/commands/spec-start.md +3 -4
  171. package/presets/cursor/next/commands/task-continue.md +9 -8
  172. package/presets/cursor/next/commands/task-evil.md +8 -0
  173. package/presets/cursor/next/commands/task.md +1 -1
  174. package/presets/cursor/next/hooks/chain-team-phases.sh +541 -61
  175. package/presets/cursor/next/hooks/guard-shell-command.mjs +733 -9
  176. package/presets/cursor/next/rules/agent-team-intake.mdc +2 -0
  177. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +2 -2
  178. package/presets/cursor/next/rules/preset-writing-style.mdc +8 -0
  179. package/presets/cursor/next/team/README.md +1 -1
  180. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +541 -61
  181. package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +733 -9
  182. package/presets/cursor/nuxt/rules/agent-team-intake.mdc +2 -0
  183. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
  184. package/presets/cursor/nuxt/rules/preset-writing-style.mdc +8 -0
  185. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  186. package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
  187. package/presets/cursor/php-hexagonal/rules/agent-team-intake.mdc +2 -0
  188. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
  189. package/presets/cursor/php-hexagonal/rules/preset-writing-style.mdc +8 -0
  190. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +541 -61
  191. package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +733 -9
  192. package/presets/cursor/php-laravel/rules/agent-team-intake.mdc +2 -0
  193. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
  194. package/presets/cursor/php-laravel/rules/preset-writing-style.mdc +8 -0
  195. package/presets/cursor/svelte/hooks/chain-team-phases.sh +541 -61
  196. package/presets/cursor/svelte/hooks/guard-shell-command.mjs +733 -9
  197. package/presets/cursor/svelte/rules/agent-team-intake.mdc +2 -0
  198. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
  199. package/presets/cursor/svelte/rules/preset-writing-style.mdc +8 -0
  200. package/presets/mavis/android-kotlin/MAVIS.md +1 -1
  201. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  202. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +541 -61
  203. package/presets/mavis/android-kotlin/rules/agent-team-intake.md +2 -0
  204. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +2 -2
  205. package/presets/mavis/android-kotlin/rules/preset-writing-style.md +8 -0
  206. package/presets/mavis/go/MAVIS.md +1 -1
  207. package/presets/mavis/go/adapter-map.json +1 -1
  208. package/presets/mavis/go/hooks/chain-team-phases.sh +541 -61
  209. package/presets/mavis/go/rules/agent-team-intake.md +2 -0
  210. package/presets/mavis/go/rules/agent-team-orchestrator.md +2 -2
  211. package/presets/mavis/go/rules/preset-writing-style.md +8 -0
  212. package/presets/mavis/ios-swift/MAVIS.md +1 -1
  213. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  214. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +541 -61
  215. package/presets/mavis/ios-swift/rules/agent-team-intake.md +2 -0
  216. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +2 -2
  217. package/presets/mavis/ios-swift/rules/preset-writing-style.md +8 -0
  218. package/presets/mavis/java/MAVIS.md +1 -1
  219. package/presets/mavis/java/adapter-map.json +1 -1
  220. package/presets/mavis/java/hooks/chain-team-phases.sh +541 -61
  221. package/presets/mavis/java/rules/agent-team-intake.md +2 -0
  222. package/presets/mavis/java/rules/agent-team-orchestrator.md +2 -2
  223. package/presets/mavis/java/rules/preset-writing-style.md +8 -0
  224. package/presets/mavis/mcp-ts/MAVIS.md +1 -1
  225. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  226. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +541 -61
  227. package/presets/mavis/mcp-ts/rules/agent-team-intake.md +2 -0
  228. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +2 -2
  229. package/presets/mavis/mcp-ts/rules/preset-writing-style.md +8 -0
  230. package/presets/mavis/mol/MAVIS.md +1 -1
  231. package/presets/mavis/mol/adapter-map.json +1 -1
  232. package/presets/mavis/mol/agents/feature-developer.md +1 -1
  233. package/presets/mavis/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  234. package/presets/mavis/mol/commands/task-evil.md +8 -0
  235. package/presets/mavis/mol/hooks/chain-team-phases.sh +541 -61
  236. package/presets/mavis/mol/native-skills/task-evil/SKILL.md +8 -0
  237. package/presets/mavis/mol/rules/agent-team-intake.md +2 -0
  238. package/presets/mavis/mol/rules/agent-team-orchestrator.md +2 -2
  239. package/presets/mavis/mol/rules/preset-writing-style.md +8 -0
  240. package/presets/mavis/next/MAVIS.md +1 -1
  241. package/presets/mavis/next/REPO_AGENTS.md +2 -0
  242. package/presets/mavis/next/adapter-map.json +1 -1
  243. package/presets/mavis/next/agents/feature-developer.md +1 -1
  244. package/presets/mavis/next/agents/task-analyst.md +1 -7
  245. package/presets/mavis/next/agents/task-router.md +1 -1
  246. package/presets/mavis/next/ai-local/rules-library/commit-hygiene.md +1 -1
  247. package/presets/mavis/next/commands/spec-start.md +3 -4
  248. package/presets/mavis/next/commands/task-continue.md +9 -8
  249. package/presets/mavis/next/commands/task-evil.md +8 -0
  250. package/presets/mavis/next/commands/task.md +1 -1
  251. package/presets/mavis/next/hooks/chain-team-phases.sh +541 -61
  252. package/presets/mavis/next/native-skills/spec-start/SKILL.md +3 -4
  253. package/presets/mavis/next/native-skills/task/SKILL.md +1 -1
  254. package/presets/mavis/next/native-skills/task-continue/SKILL.md +9 -8
  255. package/presets/mavis/next/native-skills/task-evil/SKILL.md +8 -0
  256. package/presets/mavis/next/rules/agent-team-intake.md +2 -0
  257. package/presets/mavis/next/rules/agent-team-orchestrator.md +2 -2
  258. package/presets/mavis/next/rules/preset-writing-style.md +8 -0
  259. package/presets/mavis/next/team/README.md +1 -1
  260. package/presets/mavis/nuxt/MAVIS.md +1 -1
  261. package/presets/mavis/nuxt/adapter-map.json +1 -1
  262. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +541 -61
  263. package/presets/mavis/nuxt/rules/agent-team-intake.md +2 -0
  264. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +2 -2
  265. package/presets/mavis/nuxt/rules/preset-writing-style.md +8 -0
  266. package/presets/mavis/php-hexagonal/MAVIS.md +1 -1
  267. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  268. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  269. package/presets/mavis/php-hexagonal/rules/agent-team-intake.md +2 -0
  270. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
  271. package/presets/mavis/php-hexagonal/rules/preset-writing-style.md +8 -0
  272. package/presets/mavis/php-laravel/MAVIS.md +1 -1
  273. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  274. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +541 -61
  275. package/presets/mavis/php-laravel/rules/agent-team-intake.md +2 -0
  276. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +2 -2
  277. package/presets/mavis/php-laravel/rules/preset-writing-style.md +8 -0
  278. package/presets/mavis/svelte/MAVIS.md +1 -1
  279. package/presets/mavis/svelte/adapter-map.json +1 -1
  280. package/presets/mavis/svelte/hooks/chain-team-phases.sh +541 -61
  281. package/presets/mavis/svelte/rules/agent-team-intake.md +2 -0
  282. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +2 -2
  283. package/presets/mavis/svelte/rules/preset-writing-style.md +8 -0
  284. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  285. package/presets/opencode/android-kotlin/hooks/README.md +6 -5
  286. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +541 -61
  287. package/presets/opencode/android-kotlin/hooks/guard-shell-command.mjs +733 -9
  288. package/presets/opencode/android-kotlin/opencode.json +4 -4
  289. package/presets/opencode/android-kotlin/rules/agent-team-intake.md +2 -0
  290. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +2 -2
  291. package/presets/opencode/android-kotlin/rules/preset-writing-style.md +8 -0
  292. package/presets/opencode/go/adapter-map.json +1 -1
  293. package/presets/opencode/go/hooks/README.md +6 -5
  294. package/presets/opencode/go/hooks/chain-team-phases.sh +541 -61
  295. package/presets/opencode/go/hooks/guard-shell-command.mjs +733 -9
  296. package/presets/opencode/go/opencode.json +4 -4
  297. package/presets/opencode/go/rules/agent-team-intake.md +2 -0
  298. package/presets/opencode/go/rules/agent-team-orchestrator.md +2 -2
  299. package/presets/opencode/go/rules/preset-writing-style.md +8 -0
  300. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  301. package/presets/opencode/ios-swift/hooks/README.md +6 -5
  302. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +541 -61
  303. package/presets/opencode/ios-swift/hooks/guard-shell-command.mjs +733 -9
  304. package/presets/opencode/ios-swift/opencode.json +4 -4
  305. package/presets/opencode/ios-swift/rules/agent-team-intake.md +2 -0
  306. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +2 -2
  307. package/presets/opencode/ios-swift/rules/preset-writing-style.md +8 -0
  308. package/presets/opencode/java/adapter-map.json +1 -1
  309. package/presets/opencode/java/hooks/README.md +6 -5
  310. package/presets/opencode/java/hooks/chain-team-phases.sh +541 -61
  311. package/presets/opencode/java/hooks/guard-shell-command.mjs +733 -9
  312. package/presets/opencode/java/opencode.json +4 -4
  313. package/presets/opencode/java/rules/agent-team-intake.md +2 -0
  314. package/presets/opencode/java/rules/agent-team-orchestrator.md +2 -2
  315. package/presets/opencode/java/rules/preset-writing-style.md +8 -0
  316. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  317. package/presets/opencode/mcp-ts/hooks/README.md +6 -5
  318. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +541 -61
  319. package/presets/opencode/mcp-ts/hooks/guard-shell-command.mjs +733 -9
  320. package/presets/opencode/mcp-ts/opencode.json +4 -4
  321. package/presets/opencode/mcp-ts/rules/agent-team-intake.md +2 -0
  322. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +2 -2
  323. package/presets/opencode/mcp-ts/rules/preset-writing-style.md +8 -0
  324. package/presets/opencode/mol/adapter-map.json +1 -1
  325. package/presets/opencode/mol/agents/feature-developer.md +1 -1
  326. package/presets/opencode/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  327. package/presets/opencode/mol/commands/task-evil.md +8 -0
  328. package/presets/opencode/mol/hooks/README.md +6 -5
  329. package/presets/opencode/mol/hooks/chain-team-phases.sh +541 -61
  330. package/presets/opencode/mol/hooks/guard-shell-command.mjs +733 -9
  331. package/presets/opencode/mol/opencode.json +4 -4
  332. package/presets/opencode/mol/rules/agent-team-intake.md +2 -0
  333. package/presets/opencode/mol/rules/agent-team-orchestrator.md +2 -2
  334. package/presets/opencode/mol/rules/preset-writing-style.md +8 -0
  335. package/presets/opencode/next/REPO_AGENTS.md +2 -0
  336. package/presets/opencode/next/adapter-map.json +1 -1
  337. package/presets/opencode/next/agents/feature-developer.md +1 -1
  338. package/presets/opencode/next/agents/task-analyst.md +1 -7
  339. package/presets/opencode/next/agents/task-router.md +1 -1
  340. package/presets/opencode/next/ai-local/rules-library/commit-hygiene.md +1 -1
  341. package/presets/opencode/next/commands/spec-start.md +3 -4
  342. package/presets/opencode/next/commands/task-continue.md +9 -8
  343. package/presets/opencode/next/commands/task-evil.md +8 -0
  344. package/presets/opencode/next/commands/task.md +1 -1
  345. package/presets/opencode/next/hooks/README.md +6 -5
  346. package/presets/opencode/next/hooks/chain-team-phases.sh +541 -61
  347. package/presets/opencode/next/hooks/guard-shell-command.mjs +733 -9
  348. package/presets/opencode/next/opencode.json +4 -4
  349. package/presets/opencode/next/rules/agent-team-intake.md +2 -0
  350. package/presets/opencode/next/rules/agent-team-orchestrator.md +2 -2
  351. package/presets/opencode/next/rules/preset-writing-style.md +8 -0
  352. package/presets/opencode/next/team/README.md +1 -1
  353. package/presets/opencode/nuxt/adapter-map.json +1 -1
  354. package/presets/opencode/nuxt/hooks/README.md +6 -5
  355. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +541 -61
  356. package/presets/opencode/nuxt/hooks/guard-shell-command.mjs +733 -9
  357. package/presets/opencode/nuxt/opencode.json +4 -4
  358. package/presets/opencode/nuxt/rules/agent-team-intake.md +2 -0
  359. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +2 -2
  360. package/presets/opencode/nuxt/rules/preset-writing-style.md +8 -0
  361. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  362. package/presets/opencode/php-hexagonal/hooks/README.md +6 -5
  363. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  364. package/presets/opencode/php-hexagonal/hooks/guard-shell-command.mjs +733 -9
  365. package/presets/opencode/php-hexagonal/opencode.json +4 -4
  366. package/presets/opencode/php-hexagonal/rules/agent-team-intake.md +2 -0
  367. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
  368. package/presets/opencode/php-hexagonal/rules/preset-writing-style.md +8 -0
  369. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  370. package/presets/opencode/php-laravel/hooks/README.md +6 -5
  371. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +541 -61
  372. package/presets/opencode/php-laravel/hooks/guard-shell-command.mjs +733 -9
  373. package/presets/opencode/php-laravel/opencode.json +4 -4
  374. package/presets/opencode/php-laravel/rules/agent-team-intake.md +2 -0
  375. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +2 -2
  376. package/presets/opencode/php-laravel/rules/preset-writing-style.md +8 -0
  377. package/presets/opencode/plugins/output-guard/README.md +4 -3
  378. package/presets/opencode/plugins/output-guard/index.ts +4 -3
  379. package/presets/opencode/plugins/output-guard/rewrite.ts +1 -2
  380. package/presets/opencode/plugins/rule-attach/README.md +1 -1
  381. package/presets/opencode/plugins/rule-attach/index.ts +23 -4
  382. package/presets/opencode/plugins/settings-guard/README.md +28 -0
  383. package/presets/opencode/plugins/settings-guard/index.ts +114 -0
  384. package/presets/opencode/plugins/settings-guard/package.json +9 -0
  385. package/presets/opencode/plugins/settings-guard/policy.mjs +85 -0
  386. package/presets/opencode/plugins/settings-guard/prompt-face.mjs +153 -0
  387. package/presets/opencode/plugins/task-status/README.md +13 -8
  388. package/presets/opencode/plugins/task-status/deepseek.ts +23 -8
  389. package/presets/opencode/plugins/task-status/eta.ts +20 -7
  390. package/presets/opencode/plugins/task-status/index.ts +14 -1
  391. package/presets/opencode/plugins/task-status/task-view.ts +168 -9
  392. package/presets/opencode/plugins/task-status/timing.ts +244 -0
  393. package/presets/opencode/plugins/task-status/tui.tsx +12 -3
  394. package/presets/opencode/plugins/task-status/types.ts +6 -0
  395. package/presets/opencode/svelte/adapter-map.json +1 -1
  396. package/presets/opencode/svelte/hooks/README.md +6 -5
  397. package/presets/opencode/svelte/hooks/chain-team-phases.sh +541 -61
  398. package/presets/opencode/svelte/hooks/guard-shell-command.mjs +733 -9
  399. package/presets/opencode/svelte/opencode.json +4 -4
  400. package/presets/opencode/svelte/rules/agent-team-intake.md +2 -0
  401. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +2 -2
  402. package/presets/opencode/svelte/rules/preset-writing-style.md +8 -0
  403. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  404. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +541 -61
  405. package/presets/zcode/android-kotlin/rules/agent-team-intake.md +2 -0
  406. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +2 -2
  407. package/presets/zcode/android-kotlin/rules/preset-writing-style.md +8 -0
  408. package/presets/zcode/go/adapter-map.json +1 -1
  409. package/presets/zcode/go/hooks/chain-team-phases.sh +541 -61
  410. package/presets/zcode/go/rules/agent-team-intake.md +2 -0
  411. package/presets/zcode/go/rules/agent-team-orchestrator.md +2 -2
  412. package/presets/zcode/go/rules/preset-writing-style.md +8 -0
  413. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  414. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +541 -61
  415. package/presets/zcode/ios-swift/rules/agent-team-intake.md +2 -0
  416. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +2 -2
  417. package/presets/zcode/ios-swift/rules/preset-writing-style.md +8 -0
  418. package/presets/zcode/java/adapter-map.json +1 -1
  419. package/presets/zcode/java/hooks/chain-team-phases.sh +541 -61
  420. package/presets/zcode/java/rules/agent-team-intake.md +2 -0
  421. package/presets/zcode/java/rules/agent-team-orchestrator.md +2 -2
  422. package/presets/zcode/java/rules/preset-writing-style.md +8 -0
  423. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  424. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +541 -61
  425. package/presets/zcode/mcp-ts/rules/agent-team-intake.md +2 -0
  426. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +2 -2
  427. package/presets/zcode/mcp-ts/rules/preset-writing-style.md +8 -0
  428. package/presets/zcode/mol/adapter-map.json +1 -1
  429. package/presets/zcode/mol/agents/feature-developer.md +1 -1
  430. package/presets/zcode/mol/ai-local/rules-library/commit-hygiene.md +1 -1
  431. package/presets/zcode/mol/commands/task-evil.md +8 -0
  432. package/presets/zcode/mol/hooks/chain-team-phases.sh +541 -61
  433. package/presets/zcode/mol/rules/agent-team-intake.md +2 -0
  434. package/presets/zcode/mol/rules/agent-team-orchestrator.md +2 -2
  435. package/presets/zcode/mol/rules/preset-writing-style.md +8 -0
  436. package/presets/zcode/next/REPO_AGENTS.md +2 -0
  437. package/presets/zcode/next/adapter-map.json +1 -1
  438. package/presets/zcode/next/agents/feature-developer.md +1 -1
  439. package/presets/zcode/next/agents/task-analyst.md +1 -7
  440. package/presets/zcode/next/agents/task-router.md +1 -1
  441. package/presets/zcode/next/ai-local/rules-library/commit-hygiene.md +1 -1
  442. package/presets/zcode/next/commands/spec-start.md +3 -4
  443. package/presets/zcode/next/commands/task-continue.md +9 -8
  444. package/presets/zcode/next/commands/task-evil.md +8 -0
  445. package/presets/zcode/next/commands/task.md +1 -1
  446. package/presets/zcode/next/hooks/chain-team-phases.sh +541 -61
  447. package/presets/zcode/next/rules/agent-team-intake.md +2 -0
  448. package/presets/zcode/next/rules/agent-team-orchestrator.md +2 -2
  449. package/presets/zcode/next/rules/preset-writing-style.md +8 -0
  450. package/presets/zcode/next/team/README.md +1 -1
  451. package/presets/zcode/nuxt/adapter-map.json +1 -1
  452. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +541 -61
  453. package/presets/zcode/nuxt/rules/agent-team-intake.md +2 -0
  454. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +2 -2
  455. package/presets/zcode/nuxt/rules/preset-writing-style.md +8 -0
  456. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  457. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +541 -61
  458. package/presets/zcode/php-hexagonal/rules/agent-team-intake.md +2 -0
  459. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +2 -2
  460. package/presets/zcode/php-hexagonal/rules/preset-writing-style.md +8 -0
  461. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  462. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +541 -61
  463. package/presets/zcode/php-laravel/rules/agent-team-intake.md +2 -0
  464. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +2 -2
  465. package/presets/zcode/php-laravel/rules/preset-writing-style.md +8 -0
  466. package/presets/zcode/svelte/adapter-map.json +1 -1
  467. package/presets/zcode/svelte/hooks/chain-team-phases.sh +541 -61
  468. package/presets/zcode/svelte/rules/agent-team-intake.md +2 -0
  469. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +2 -2
  470. package/presets/zcode/svelte/rules/preset-writing-style.md +8 -0
@@ -32,7 +32,22 @@ export const SEARCH_MODE_FTS5 = 'fts5';
32
32
  export const SEARCH_MODE_LIKE = 'like';
33
33
  export const INDEX_UNAVAILABLE_LINE = `team-db: node:sqlite unavailable (requires Node >= ${MIN_NODE}); file-only mode`;
34
34
 
35
- export const DEFAULT_TEAM_ROOT = path.join(process.cwd(), '.ai.local', 'team');
35
+ /**
36
+ * Team store path. `AI_RULES_TEAM_ROOT` wins, then the legacy
37
+ * `AI_RULES_TEAM_DB_ROOT`, then `<cwd>/.ai.local/team`. An empty string is unset.
38
+ * A worktree hook sets the first name so cwd does not open a second store.
39
+ */
40
+ export const resolveTeamRoot = (env = process.env, cwd = process.cwd()) => {
41
+ const named =
42
+ env && typeof env.AI_RULES_TEAM_ROOT === 'string' && env.AI_RULES_TEAM_ROOT !== ''
43
+ ? env.AI_RULES_TEAM_ROOT
44
+ : env && typeof env.AI_RULES_TEAM_DB_ROOT === 'string' && env.AI_RULES_TEAM_DB_ROOT !== ''
45
+ ? env.AI_RULES_TEAM_DB_ROOT
46
+ : '';
47
+ return path.resolve(named || path.join(cwd, '.ai.local', 'team'));
48
+ };
49
+
50
+ export const DEFAULT_TEAM_ROOT = resolveTeamRoot();
36
51
 
37
52
  /**
38
53
  * The released FTS layouts, oldest-first. The current shape is last.
@@ -1134,14 +1149,40 @@ export const pragmaValue = (db, pragma) => {
1134
1149
  return values.length > 0 ? values[0] : null;
1135
1150
  };
1136
1151
 
1152
+ export const DEFAULT_BUSY_TIMEOUT_MS = 5000;
1153
+
1154
+ let busyTimeoutWarned = false;
1155
+
1156
+ /**
1157
+ * `AI_RULES_TEAM_DB_BUSY_MS` is a non-negative integer millisecond busy
1158
+ * timeout. Absent uses the default with no warning. Anything else warns once
1159
+ * per process and uses the default.
1160
+ */
1161
+ export function readBusyTimeoutMs(env = process.env) {
1162
+ const raw = env?.AI_RULES_TEAM_DB_BUSY_MS;
1163
+ if (raw === undefined) return DEFAULT_BUSY_TIMEOUT_MS;
1164
+ const text = String(raw).trim();
1165
+ if (text === '' || !/^\d+$/.test(text) || !Number.isSafeInteger(Number(text))) {
1166
+ if (!busyTimeoutWarned) {
1167
+ busyTimeoutWarned = true;
1168
+ process.stderr.write(
1169
+ `warn: AI_RULES_TEAM_DB_BUSY_MS="${text}" is not a non-negative integer; using ${DEFAULT_BUSY_TIMEOUT_MS}\n`,
1170
+ );
1171
+ }
1172
+ return DEFAULT_BUSY_TIMEOUT_MS;
1173
+ }
1174
+ return Number(text);
1175
+ }
1176
+
1137
1177
  export function configureConnection(db, options = {}) {
1138
1178
  // The busy timeout must be set before the first lock-taking pragma: two first
1139
1179
  // projections both create the file, and a default 0 ms timeout turns the
1140
1180
  // WAL switch on the loser into an immediate SQLITE_BUSY.
1141
- db.exec('PRAGMA busy_timeout=5000');
1142
- // WAL is persistent. Only switch a freshly created database; re-issuing the
1143
- // switch on every open needs an exclusive lock and would wait the whole busy
1144
- // timeout behind another connection's transaction for no state change.
1181
+ const busyTimeoutMs = options.busyTimeoutMs ?? readBusyTimeoutMs(options.env);
1182
+ db.exec(`PRAGMA busy_timeout=${busyTimeoutMs}`);
1183
+ // A fresh file switches here. An existing file is switched by `ensureWal`
1184
+ // after migrations, so a no-op re-issue does not take the exclusive lock
1185
+ // on every open.
1145
1186
  if (options.setWal) db.exec('PRAGMA journal_mode=WAL');
1146
1187
  db.exec('PRAGMA foreign_keys=ON');
1147
1188
  db.exec('PRAGMA synchronous=NORMAL');
@@ -1411,13 +1452,61 @@ const sleepSync = (ms) => {
1411
1452
  Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
1412
1453
  };
1413
1454
 
1455
+ const appendTeamDbError = (env, dbPath, code, message) => {
1456
+ try {
1457
+ const override = typeof env?.AI_RULES_TEAM_DB_LOG === 'string' ? env.AI_RULES_TEAM_DB_LOG.trim() : '';
1458
+ const target = override
1459
+ ? path.resolve(override)
1460
+ : path.join(path.dirname(dbPath || DEFAULT_TEAM_ROOT), 'team-db-errors.log');
1461
+ fs.mkdirSync(path.dirname(target), { recursive: true });
1462
+ fs.appendFileSync(target, `${new Date().toISOString()} ${code} cli ${message}\n`);
1463
+ let lines = fs.readFileSync(target, 'utf8').split('\n').filter((entry) => entry.length > 0);
1464
+ if (lines.length > 200) lines = lines.slice(lines.length - 200);
1465
+ while (Buffer.byteLength(`${lines.join('\n')}\n`, 'utf8') > 65536 && lines.length > 1) lines.shift();
1466
+ fs.writeFileSync(target, lines.length > 0 ? `${lines.join('\n')}\n` : '');
1467
+ } catch {
1468
+ /* a log failure must not fail the open */
1469
+ }
1470
+ };
1471
+
1472
+ /**
1473
+ * Switch an existing database to WAL after migrations, outside any transaction
1474
+ * (`PRAGMA journal_mode` is a no-op inside one). Already-WAL is a no-op.
1475
+ * `SQLITE_BUSY` retries once, then one `E_WAL_DEFERRED` line and the open
1476
+ * continues; the next open retries. The pragma does not rewrite tables.
1477
+ */
1478
+ export function ensureWal(db, { dbPath, env = process.env } = {}) {
1479
+ const mode = () => String(pragmaValue(db, 'journal_mode') ?? '').toLowerCase();
1480
+ if (mode() === 'wal') return { switched: false, deferred: false };
1481
+ let lastError = null;
1482
+ for (let attempt = 0; attempt < 2; attempt += 1) {
1483
+ try {
1484
+ db.exec('PRAGMA journal_mode=WAL');
1485
+ if (mode() === 'wal') return { switched: true, deferred: false };
1486
+ lastError = null;
1487
+ break;
1488
+ } catch (error) {
1489
+ lastError = error;
1490
+ if (!isBusyError(error) || attempt === 1) break;
1491
+ }
1492
+ }
1493
+ if (lastError && !isBusyError(lastError)) throw lastError;
1494
+ appendTeamDbError(
1495
+ env,
1496
+ dbPath,
1497
+ 'E_WAL_DEFERRED',
1498
+ `journal_mode stayed ${mode() || 'unknown'}; next open retries`,
1499
+ );
1500
+ return { switched: false, deferred: true };
1501
+ }
1502
+
1414
1503
  /**
1415
1504
  * Open + configure with a bounded retry for the first-creation race. Two
1416
1505
  * processes can both create the file; the loser's WAL switch or migration can
1417
1506
  * return SQLITE_BUSY before the in-connection busy handler applies. Retry for
1418
- * five seconds, matching `busy_timeout`, then surface `E_DB_BUSY`.
1507
+ * five seconds, matching the default `busy_timeout`, then surface `E_DB_BUSY`.
1419
1508
  */
1420
- const openConfiguredDatabase = (sqlite, dbPath, readOnly, setWal = false) => {
1509
+ const openConfiguredDatabase = (sqlite, dbPath, readOnly, setWal = false, env = process.env) => {
1421
1510
  let lastError = null;
1422
1511
  const deadline = Date.now() + 5000;
1423
1512
  let attempt = 0;
@@ -1426,7 +1515,7 @@ const openConfiguredDatabase = (sqlite, dbPath, readOnly, setWal = false) => {
1426
1515
  let db;
1427
1516
  try {
1428
1517
  db = new sqlite.DatabaseSync(dbPath, readOnly ? { readOnly: true } : {});
1429
- configureConnection(db, { setWal: setWal && !readOnly });
1518
+ configureConnection(db, { setWal: setWal && !readOnly, env });
1430
1519
  return db;
1431
1520
  } catch (error) {
1432
1521
  lastError = error;
@@ -1512,9 +1601,7 @@ export function openTeamDb(options = {}) {
1512
1601
  const sqlite = loadSqlite(options.env ?? process.env);
1513
1602
  if (!sqlite) teamDbFail('E_SQLITE_UNAVAILABLE', `node:sqlite is unavailable; requires Node >= ${MIN_NODE}`, 0);
1514
1603
 
1515
- const teamRoot = path.resolve(
1516
- options.teamRoot || process.env.AI_RULES_TEAM_DB_ROOT || DEFAULT_TEAM_ROOT,
1517
- );
1604
+ const teamRoot = path.resolve(options.teamRoot || resolveTeamRoot(options.env ?? process.env));
1518
1605
  const dbPath = path.resolve(
1519
1606
  options.dbPath ||
1520
1607
  process.env.AI_RULES_TEAM_DB_PATH ||
@@ -1549,7 +1636,7 @@ export function openTeamDb(options = {}) {
1549
1636
  if (!readOnly) ensureDatabaseFile(dbPath);
1550
1637
  let db;
1551
1638
  try {
1552
- db = openConfiguredDatabase(sqlite, dbPath, readOnly, freshFile);
1639
+ db = openConfiguredDatabase(sqlite, dbPath, readOnly, freshFile, options.env ?? process.env);
1553
1640
  } catch (error) {
1554
1641
  if (isCorruptError(error) || error?.code === 'EISDIR') {
1555
1642
  // Corruption is never repaired implicitly; `--rebuild` moves the file
@@ -1589,6 +1676,7 @@ export function openTeamDb(options = {}) {
1589
1676
  ) {
1590
1677
  ensureSearchIndex(db, { searchMode: forceSearch });
1591
1678
  }
1679
+ ensureWal(db, { dbPath, env: options.env ?? process.env });
1592
1680
  } else if (current < SCHEMA_VERSION) {
1593
1681
  teamDbFail('E_SCHEMA_OUTDATED', `database schema v${current} is older than code v${SCHEMA_VERSION}`, 2);
1594
1682
  }
@@ -1647,6 +1735,7 @@ export function openTeamDb(options = {}) {
1647
1735
  fingerprint,
1648
1736
  searchMode,
1649
1737
  searchShape: detectFtsShapeDrift(db),
1738
+ journalMode: pragmaValue(db, 'journal_mode'),
1650
1739
  };
1651
1740
  } catch (error) {
1652
1741
  try {
@@ -1689,6 +1778,7 @@ export function describeHandle(handle) {
1689
1778
  `fingerprint ${handle.fingerprint.slice(0, 12)}`,
1690
1779
  `search ${handle.searchMode}`,
1691
1780
  'integrity ok',
1781
+ `journal ${String(handle.journalMode ?? 'unknown').toLowerCase()}`,
1692
1782
  ];
1693
1783
  // A drifted search layout is reported, never repaired: the state names what
1694
1784
  // is installed, and the rebuild path stays the remedy.
@@ -1587,7 +1587,42 @@ export function recoverTrackerEntries(teamRoot, options = {}) {
1587
1587
  return withTrackerLock(teamRoot, () => ({ recovered: releaseStaleClaims(teamRoot, options.actor ?? 'operator') }));
1588
1588
  }
1589
1589
 
1590
+ const queueDirIsEmpty = (teamRoot) => {
1591
+ const dir = trackerPaths(teamRoot).queue;
1592
+ try {
1593
+ return fs.readdirSync(dir).length === 0;
1594
+ } catch (error) {
1595
+ if (error && error.code === 'ENOENT') return true;
1596
+ throw error;
1597
+ }
1598
+ };
1599
+
1600
+ /** Capacity of an empty queue, read-only. No entries means no claimed count and no stale release. */
1601
+ const emptyQueueDrain = (teamRoot) => {
1602
+ const taskStates = readTaskStates(teamRoot);
1603
+ const config = readTrackerConfig(teamRoot);
1604
+ const activeCount = countActiveTasks(taskStates);
1605
+ return {
1606
+ ok: true,
1607
+ claim: null,
1608
+ reason: 'queue empty (pre-check)',
1609
+ claimable: activeCount < config.maxActive,
1610
+ maxActive: config.maxActive,
1611
+ activeCount,
1612
+ ready: [],
1613
+ drainOrder: [],
1614
+ };
1615
+ };
1616
+
1617
+ /**
1618
+ * Drain the launch queue.
1619
+ *
1620
+ * An empty queue returns before the tracker lock. An entry written between
1621
+ * this readdir and the lock waits for the next stop-seam drain — a drain
1622
+ * fires on every completed stop, so skip-on-loss is unchanged.
1623
+ */
1590
1624
  export function drainTracker(teamRoot, { claim = false, actor = 'operator' } = {}) {
1625
+ if (queueDirIsEmpty(teamRoot)) return emptyQueueDrain(teamRoot);
1591
1626
  return withTrackerLock(teamRoot, () => {
1592
1627
  releaseStaleClaims(teamRoot, actor);
1593
1628
  const snapshot = {
@@ -250,7 +250,16 @@ export async function runPlannedDrain(teamRoot, options = {}) {
250
250
  if (isKillSwitchSet(options.env ?? process.env)) return idle('disabled');
251
251
  reconcilePlannedItems(teamRoot);
252
252
  const preview = drainTracker(teamRoot, { claim: false, actor: ACTOR });
253
- if (!preview.claimable) {
253
+ if (preview.reason === 'queue empty (pre-check)') {
254
+ // The pre-check did not take the lock. A full slot still refuses before
255
+ // enqueue; an open slot falls through to the planned head.
256
+ if (!preview.claimable) {
257
+ const reason = preview.activeCount >= preview.maxActive
258
+ ? 'capacity: active tasks'
259
+ : 'capacity: claimed or active entries';
260
+ return idle(reason);
261
+ }
262
+ } else if (!preview.claimable) {
254
263
  // `claim: true` while the slot is full writes nothing; the reason is the
255
264
  // capacity string the tracker already returns.
256
265
  const refused = drainTracker(teamRoot, { claim: true, actor: ACTOR });
@@ -133,15 +133,75 @@ const git = (root, args) => {
133
133
  return String(result.stdout ?? '');
134
134
  };
135
135
 
136
+ const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
137
+
138
+ /** Live slugs over the task store — the same canonical predicate the hook uses. */
139
+ const liveTaskSlugs = (teamRoot) => {
140
+ let entries;
141
+ try {
142
+ entries = fs.readdirSync(path.join(teamRoot, 'tasks'), { withFileTypes: true });
143
+ } catch {
144
+ return [];
145
+ }
146
+ const live = [];
147
+ for (const entry of entries) {
148
+ if (!entry.isDirectory()) continue;
149
+ const status = readJson(path.join(teamRoot, 'tasks', entry.name, 'status.json'), null);
150
+ if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) live.push(entry.name);
151
+ }
152
+ return live.sort();
153
+ };
154
+
155
+ /**
156
+ * Union of `Object.keys(baseline.paths)` across the slug's step baselines
157
+ * (tolerant reader: invalid files skipped). `null` when the slug has no
158
+ * readable baseline or the union is empty — the caller falls back per the
159
+ * basis rules, matching `check-preset-delta.mjs` `readTaskBaselines`.
160
+ */
161
+ const writeScopeBaselinePaths = (teamRoot, slug) => {
162
+ if (!SLUG_RE.test(slug)) return null;
163
+ let entries;
164
+ try {
165
+ entries = fs.readdirSync(path.join(teamRoot, '.write-scope', slug));
166
+ } catch {
167
+ return null;
168
+ }
169
+ const paths = new Set();
170
+ for (const entry of entries) {
171
+ if (!entry.endsWith('.json')) continue;
172
+ const value = readJson(path.join(teamRoot, '.write-scope', slug, entry), null);
173
+ const record =
174
+ value && typeof value === 'object' && value.paths && typeof value.paths === 'object' && !Array.isArray(value.paths)
175
+ ? value.paths
176
+ : null;
177
+ if (!record) continue;
178
+ for (const key of Object.keys(record)) {
179
+ if (typeof key === 'string' && key !== '') paths.add(key.split(path.sep).join('/'));
180
+ }
181
+ }
182
+ return paths.size > 0 ? [...paths].sort() : null;
183
+ };
184
+
136
185
  /**
137
- * Worktree snapshot. `head` and `worktreeHash` are the freshness keys: the hash
138
- * covers tracked modifications and the untracked-name set, not untracked file
139
- * contents (which would make the check unbounded on a dirty tree).
186
+ * Worktree snapshot. `head` plus the scope binding are the freshness keys:
187
+ * `scopeHash` covers the task's write-scope baseline path set (tracked
188
+ * modifications and the untracked-name set, not untracked file contents —
189
+ * which would make the check unbounded on a dirty tree), so another live
190
+ * slug's uncommitted work cannot stale this task's evidence. Known limit: a
191
+ * file created after baseline activation outside the claimed path set is
192
+ * invisible to `scopeHash`; the write-scope audit and `check:task` still
193
+ * attribute such files at gate time (content-hash delta) — the scoped hash is
194
+ * a change detector, not an attribution tool. `environmentHash` (renamed from
195
+ * `worktreeHash`) keeps the whole-tree capture as diagnostics only.
196
+ * Basis: `write-scope` (baselines exist), `whole-tree` (none, ≤1 live slug —
197
+ * solo-tree semantics preserved), `none` (none, >1 live slug — no hash,
198
+ * freshness reports `scope-unbound`). Must hash identically to the chain
199
+ * hook's `gitSnapshot()`; the parity fixture pins the formula.
140
200
  */
141
- const captureSnapshot = (root) => {
201
+ const captureSnapshot = (root, teamRoot, slug) => {
142
202
  const head = git(root, ['rev-parse', 'HEAD']);
143
203
  if (head === null) {
144
- return { head: null, branch: null, dirtyFiles: null, worktreeHash: null, git: false, capturedAt: new Date().toISOString() };
204
+ return { head: null, branch: null, dirtyFiles: null, environmentHash: null, scopeBasis: 'none', scopePaths: 0, scopeHash: null, git: false, capturedAt: new Date().toISOString() };
145
205
  }
146
206
  const branch = git(root, ['rev-parse', '--abbrev-ref', 'HEAD']);
147
207
  // `.ai.local/` holds the evidence this module writes; including it would make
@@ -151,11 +211,27 @@ const captureSnapshot = (root) => {
151
211
  const diffText = git(root, ['diff', '--binary', 'HEAD', ...exclude]) ?? '';
152
212
  const untrackedText = git(root, ['ls-files', '--others', '--exclude-standard', ...exclude]) ?? '';
153
213
  const dirtyFiles = statusText === '' ? 0 : statusText.split('\n').filter((line) => line !== '').length;
214
+ const baselinePaths = writeScopeBaselinePaths(teamRoot, typeof slug === 'string' ? slug : '');
215
+ let scopeBasis = 'none';
216
+ let scopeHash = null;
217
+ if (baselinePaths !== null) {
218
+ scopeBasis = 'write-scope';
219
+ const spec = ['--', ...baselinePaths];
220
+ const scopedStatus = git(root, ['status', '--porcelain=v1', ...spec]) ?? '';
221
+ const scopedDiff = git(root, ['diff', '--binary', 'HEAD', ...spec]) ?? '';
222
+ const scopedUntracked = git(root, ['ls-files', '--others', '--exclude-standard', ...spec]) ?? '';
223
+ scopeHash = sha256(`${scopedStatus}\u0000${scopedDiff}\u0000${scopedUntracked}`);
224
+ } else if (liveTaskSlugs(teamRoot).length <= 1) {
225
+ scopeBasis = 'whole-tree';
226
+ }
154
227
  return {
155
228
  head: head.trim(),
156
229
  branch: branch === null ? null : branch.trim(),
157
230
  dirtyFiles,
158
- worktreeHash: sha256(`${statusText}\u0000${diffText}\u0000${untrackedText}`),
231
+ environmentHash: sha256(`${statusText}\u0000${diffText}\u0000${untrackedText}`),
232
+ scopeBasis,
233
+ scopePaths: baselinePaths === null ? 0 : baselinePaths.length,
234
+ scopeHash,
159
235
  git: true,
160
236
  capturedAt: new Date().toISOString(),
161
237
  };
@@ -270,7 +346,7 @@ const actionRecord = (args) => {
270
346
  };
271
347
  verification.commands.push(entry);
272
348
  verification.task = path.basename(taskDir);
273
- verification.snapshot = captureSnapshot(path.resolve(teamRoot, '..', '..'));
349
+ verification.snapshot = captureSnapshot(path.resolve(teamRoot, '..', '..'), teamRoot, path.basename(taskDir));
274
350
  verification.gate = { status: 'recorded', checkedAt: new Date().toISOString() };
275
351
  writeJsonAtomic(file, verification);
276
352
  } finally {
@@ -285,7 +361,7 @@ const actionRecord = (args) => {
285
361
  agent: entry.agent,
286
362
  attempt: entry.attempt,
287
363
  head: verification.snapshot.head,
288
- worktreeHash: verification.snapshot.worktreeHash,
364
+ environmentHash: verification.snapshot.environmentHash,
289
365
  });
290
366
 
291
367
  if (args.json) {
@@ -309,7 +385,7 @@ const actionSnapshot = (args) => {
309
385
  commands: [],
310
386
  gate: { status: 'recorded', checkedAt: null },
311
387
  };
312
- verification.snapshot = captureSnapshot(path.resolve(teamRoot, '..', '..'));
388
+ verification.snapshot = captureSnapshot(path.resolve(teamRoot, '..', '..'), teamRoot, path.basename(taskDir));
313
389
  writeJsonAtomic(file, verification);
314
390
  } finally {
315
391
  release();
@@ -330,12 +406,31 @@ const actionCheck = (args) => {
330
406
  else process.stdout.write('verification: missing\n');
331
407
  process.exit(args.strict ? 2 : 0);
332
408
  }
333
- const current = captureSnapshot(path.resolve(teamRoot, '..', '..'));
409
+ const current = captureSnapshot(path.resolve(teamRoot, '..', '..'), teamRoot, path.basename(taskDir));
334
410
  const reasons = [];
335
411
  if (!verification.snapshot) reasons.push('no-snapshot');
336
412
  else {
337
413
  if (verification.snapshot.head !== current.head) reasons.push('head-changed');
338
- if (verification.snapshot.worktreeHash !== current.worktreeHash) reasons.push('worktree-changed');
414
+ // The head comparison is global (HEAD is shared across live slugs); the
415
+ // dirty/hash dimension switches on the recorded `scopeBasis` the same way
416
+ // the chain hook's `verificationFreshness` does. `write-scope` binds to
417
+ // `scopeHash` (a scope that can no longer be recomputed reports
418
+ // `scope-unbound`); `none` is a loud not-fresh; legacy snapshots (no
419
+ // `scopeBasis`) and `whole-tree` keep the whole-tree comparison, reading
420
+ // the renamed field as `environmentHash ?? worktreeHash`.
421
+ const basis = typeof verification.snapshot.scopeBasis === 'string' ? verification.snapshot.scopeBasis : 'legacy';
422
+ if (basis === 'write-scope') {
423
+ if (current.scopeBasis !== 'write-scope') reasons.push('scope-unbound');
424
+ else if (current.scopeHash !== verification.snapshot.scopeHash) reasons.push('worktree-changed');
425
+ } else if (basis === 'none') {
426
+ reasons.push('scope-unbound');
427
+ } else {
428
+ const recorded =
429
+ typeof verification.snapshot.environmentHash === 'string'
430
+ ? verification.snapshot.environmentHash
431
+ : verification.snapshot.worktreeHash;
432
+ if (current.environmentHash !== recorded) reasons.push('worktree-changed');
433
+ }
339
434
  }
340
435
  if (verification.commands.length === 0) reasons.push('no-command-evidence');
341
436
  const fresh = reasons.length === 0;
@@ -132,10 +132,18 @@ node .ai.local/scripts/verification.mjs check --task <slug> [--strict]
132
132
  - `record` appends one command entry (`id`, `command`, `exit`, `at`, optional
133
133
  `logRef`/`logSha256`), stores a capped, secret-redacted log tail under
134
134
  `evidence/`, and snapshots the git state (`head`, `branch`, `dirtyFiles`,
135
- `worktreeHash`). `.ai.local/**` is excluded from the snapshot.
135
+ `environmentHash`) plus the task-scoped binding (`scopeHash`, `scopePaths`,
136
+ `scopeBasis`: `write-scope` | `whole-tree` | `none`). `.ai.local/**` is
137
+ excluded from the whole-tree capture. Gate freshness binds to `scopeHash` —
138
+ computed over the task's `.write-scope` baseline path set, so another live
139
+ slug's uncommitted work cannot stale this task's evidence; `environmentHash`
140
+ keeps the whole-tree capture as diagnostics only. A `none` basis (no
141
+ baselines, more than one slug live) is a loud not-fresh (`scope-unbound`).
136
142
  - `check` compares the stored snapshot with the current worktree:
137
143
  `head-changed` / `worktree-changed` mean the evidence belongs to an older
138
- tree. `--strict` exits `1` when stale and `2` when missing.
144
+ tree, `scope-unbound` means the scoped binding cannot be recomputed. Snapshots
145
+ recorded before the rename keep comparing via the legacy `worktreeHash` field.
146
+ `--strict` exits `1` when stale and `2` when missing.
139
147
  - When a `build-verifier` attempt finishes without an explicit `record`, the
140
148
  chain hook seeds the file once (`gate.status: snapshot-only`): the git snapshot
141
149
  plus a SHA-256 of `validation-report.md`, with `commands: []`. An existing file
@@ -10,4 +10,6 @@ When the user message looks like a **work request** (implement, add, fix, refact
10
10
  6. **Reuse the dialogue language already resolved on this turn** (always-on `ai-local-overlay` / **language-policy**). A question and a message without a slash command still resolve before you speak. When this request writes `prompt.md`, persist that tag once in the header (`language: <BCP-47>`) + a `.memlog.md` `event:` line. Development, reasoning, and artifacts stay English. The setting wins over a mid-task prompt switch (surface it once, never ask). See **language-policy**.
11
11
  7. **Project the intake write.** After `prompt.md` is written for an inline (non-`/task`) work request, run `node .ai.local/scripts/team-db.mjs sync --slug <slug> --deadline-ms 4500` once, so the new task row and its prompt reach the database. A projection failure is reported to the user, never blocks the request; the next full sync remains the convergence path. Do not run a full sync from intake.
12
12
 
13
+ On Cursor, Mavis, OpenCode and ZCode — the hosts without a verified prompt hook — run a request that is not already `/task` or `/task-continue` as `/task` when `node .ai.local/scripts/settings.mjs get AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS` prints `true` and the live-slug count (every `.ai.local/team/tasks/*/status.json` whose `state` is not one of `completed`, `blocked`, `changes_requested`, `validation_failed`) is below the `node .ai.local/scripts/settings.mjs get AI_RULES_MAX_PARALLEL_TASKS` cap (`4` by default; `0` = unlimited). A prompt that names an existing slug or is a resume intent (`continue` / `resume` / `продолжай` family, `.ai.local/rules/task-resume.md`) routes to `/task-continue <slug>` regardless of the cap. <!-- i18n-keep: E4 -->
14
+
13
15
  Exceptions: user explicitly says “no pipeline”, “just do it”, or continues an active slug.
@@ -237,7 +237,7 @@ On each `subagentStop`, the hook reconciles `status.state` from the completing p
237
237
  3. One role per Task call — **except** parallel steps: multiple Task calls in one message.
238
238
  4. **Never** skip `humanGates` without `/task-continue` or explicit user approval.
239
239
  5. Persist handoffs to disk (`brief.md`, `decomposition.md`, `debug-report.md`, `validation-report.md`, `architecture.md`, `migration-plan.md`, `ci-report.md`, `a11y-review.md`, `perf-report.md`, `security-review.md`, `api-contract-review.md`, `unit-test-plan.md`, `documentation.md`, `review.md`, `mockup-review.md`, `ux-design.md`) and update the producer-owned terminal receipt in `artifact-manifest.json`.
240
- 6. On `changes_requested` from reviewers: hook sets `retryAfterFix` → developer → `build-verifier` (delta) → same reviewer when the fix touches code/tests; a docs/artifacts-only fix returns to the same reviewer without a code gate. Exception: embedded `mockup-reviewer` FAIL (`changes_requested` while the completed/current agent is `mockup-reviewer`) → `awaiting_approval` / `/task-continue` only — do **not** `retryAfterFix` to developer. A `mockup-reviewer` verdict `mockup-change-requested` (a defect whose fix belongs in the design source, not the implementation) routes the same way — `awaiting_approval`, no developer retry.
240
+ 6. On `changes_requested` from reviewers: the first time that agent returns it, the hook sets `retryAfterFix` → developer → `build-verifier` (delta) → same reviewer when the fix touches code/tests; a docs/artifacts-only fix returns to the same reviewer without a code gate. The second `changes_requested` from the same agent is a human gate (`awaitingHumanGate`, `designEscalation`): do not dispatch the developer. Append `decision: replan rev N → N+1` to `.memlog.md` (the decision changes the model), then `/task-continue`, which the hook accepts only when that line is new. Exception: embedded `mockup-reviewer` FAIL (`changes_requested` while the completed/current agent is `mockup-reviewer`) → `awaiting_approval` / `/task-continue` only — do **not** `retryAfterFix` to developer. A `mockup-reviewer` verdict `mockup-change-requested` (a defect whose fix belongs in the design source, not the implementation) routes the same way — `awaiting_approval`, no developer retry.
241
241
  7. On `validation_failed` from `build-verifier`: hook sets `retryAfterFix: build-verifier` → developer → build-verifier (delta).
242
242
  8. When all steps complete, suggest `/technical-retro <slug>`.
243
243
  9. If `autoChain: false` in pipeline, do not rely on hook — manual step only.
@@ -281,7 +281,7 @@ node .ai.local/scripts/record-usage.mjs --task <slug> --attempt <attemptId> --in
281
281
 
282
282
  The chain hook also forwards a `usage` object from its input into the `attempt_finished` event. Never estimate or invent token counts; a missing usage record stays missing.
283
283
 
284
- After each agent completes, verify its terminal manifest receipt, then let the orchestration runtime/hook reconcile `status.json` (`completed`, a blocking outcome, or `awaiting_approval`) from that receipt. Pass the active slug explicitly: `TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh` (or the host's hook path). The `active-task.json` pointer is a single-slot fallback and a parallel session can overwrite it; do not rely on it alone. Do not ask the agent to mutate shared lifecycle fields, and do not invoke the next specialist until the hook has written the handoff / updated `status.json`.
284
+ After each agent completes, verify its terminal manifest receipt, then let the orchestration runtime/hook reconcile `status.json` (`completed`, a blocking outcome, or `awaiting_approval`) from that receipt. **MUST: pass `TEAM_TASK_SLUG=<slug>` on every hook call** — `TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh` (or the host's hook path). With more than one live slug, an omitted env is a hook refusal (`active-task-pointer-ambiguous`, `ok:false`), never a silent reroute: re-run with the env set. The OpenCode task-status plugin pins each tab in `.ai.local/team/.session-leases/<session>.json` and injects `AI_RULES_SESSION_ID` on `shell.env`, so a later hook call in that tab resolves through the lease when `TEAM_TASK_SLUG` is omitted. `active-task.json` is the live-slug list, not a tab binding. Do not ask the agent to mutate shared lifecycle fields, and do not invoke the next specialist until the hook has written the handoff / updated `status.json`.
285
285
 
286
286
  ## Legacy mode
287
287
 
@@ -23,6 +23,14 @@ Write for two readers at once: an **agent** loading one file out of context, and
23
23
  - No scenario storytelling, rhetorical questions, or meta-narration ("this section explains…").
24
24
  - No duplicated rule text across stems — link instead.
25
25
 
26
+ ## Shell guards
27
+
28
+ A write or execute guard allowlists the benign shapes and answers `ask` on anything it cannot classify. `allow` on an unknown shape is a defect.
29
+
30
+ - Name the bypass class — abbreviations, aliases, quoting, shell wrappers, config-injection options (`-c`, `--exec`, `--receive-pack`), value-consumption mismatch — not a list of spellings.
31
+ - Probe each shape with the flag on, the flag off, a sentinel, and an unreadable config. Quote the tool output. A green gate set is not that evidence.
32
+ - Compare every probed shape with the previous answer. A shape that asked before and allows now is a blocker.
33
+
26
34
  ## Size
27
35
 
28
36
  - Shortest form that still changes behavior: if a bullet fits as a clause, make it a clause.