@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
@@ -0,0 +1,364 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Per-task git worktree bound to the one main team store.
4
+ *
5
+ * node .ai.local/scripts/task-worktree.mjs create <slug>
6
+ * node .ai.local/scripts/task-worktree.mjs list
7
+ * node .ai.local/scripts/task-worktree.mjs remove <slug> [--force]
8
+ *
9
+ * `create` checks the slug, refuses a missing task, an existing
10
+ * `.ai.local/worktrees/<slug>` directory, or an existing `task/<slug>` branch,
11
+ * then runs `git worktree add` from the repo root. It copies `scripts/`,
12
+ * `rules/`, `conventions.md`, and `.env` read-only and best-effort symlinks
13
+ * `.ai.local/team` at the main store. A refused symlink warns and continues
14
+ * env-only. The activation line names `AI_RULES_TEAM_ROOT=<abs main team root>`.
15
+ * A complete pair prints that line again and exits 0. Git failures are printed
16
+ * verbatim and left in place (`git worktree prune` is the remedy, not this script).
17
+ *
18
+ * `remove` refuses a live slug. An unmerged branch is refused unless `--force`,
19
+ * which says it is deleting that branch and uses `git branch -D`. An
20
+ * already-removed pair exits 0.
21
+ *
22
+ * Hold the create through the process manager so two creates cannot race:
23
+ * node .ai.local/scripts/processes.mjs run --name worktree --task <slug> -- node .ai.local/scripts/task-worktree.mjs create <slug>
24
+ *
25
+ * Exit 1 on refusal, usage, or git failure. Exit 0 on success, including the no-ops.
26
+ */
27
+ import { spawnSync } from 'node:child_process';
28
+ import fs from 'node:fs';
29
+ import path from 'node:path';
30
+ import { pathToFileURL } from 'node:url';
31
+
32
+ const invokedDirectly = () =>
33
+ process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href;
34
+
35
+ const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
36
+ const SLUG_MAX = 48;
37
+ const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
38
+ const SEED_DIRS = ['scripts', 'rules'];
39
+ const SEED_FILES = ['conventions.md', '.env'];
40
+ const USAGE = 'usage: create <slug> | list | remove <slug> [--force]';
41
+
42
+ const fail = (message) => {
43
+ process.stderr.write(`task-worktree: ${message}\n`);
44
+ process.exit(1);
45
+ };
46
+
47
+ const warn = (message) => {
48
+ process.stderr.write(`task-worktree: warning: ${message}\n`);
49
+ };
50
+
51
+ const git = (cwd, args) => spawnSync('git', args, { cwd, encoding: 'utf8' });
52
+
53
+ const failGit = (result) => {
54
+ const text = `${result.stderr || ''}${result.stdout || ''}`;
55
+ if (text !== '') process.stderr.write(text.endsWith('\n') ? text : `${text}\n`);
56
+ if (result.error) process.stderr.write(`${result.error.message}\n`);
57
+ process.exit(1);
58
+ };
59
+
60
+ const repoRootOf = (cwd) => {
61
+ const result = git(cwd, ['rev-parse', '--show-toplevel']);
62
+ if (result.status !== 0) failGit(result);
63
+ return result.stdout.trim();
64
+ };
65
+
66
+ const validSlug = (slug) =>
67
+ typeof slug === 'string' && slug.length > 0 && slug.length <= SLUG_MAX && SLUG_RE.test(slug);
68
+
69
+ const mainTeamRoot = (repoRoot, env) => {
70
+ if (env.AI_RULES_TEAM_ROOT) return path.resolve(env.AI_RULES_TEAM_ROOT);
71
+ if (env.AI_RULES_TEAM_DB_ROOT) return path.resolve(env.AI_RULES_TEAM_DB_ROOT);
72
+ return path.join(repoRoot, '.ai.local', 'team');
73
+ };
74
+
75
+ const worktreeDir = (repoRoot, slug) => path.join(repoRoot, '.ai.local', 'worktrees', slug);
76
+
77
+ const branchName = (slug) => `task/${slug}`;
78
+
79
+ const branchExists = (repoRoot, slug) => {
80
+ const result = git(repoRoot, ['show-ref', '--verify', '--quiet', `refs/heads/${branchName(slug)}`]);
81
+ if (result.status === 0) return true;
82
+ if (result.status === 1) return false;
83
+ failGit(result);
84
+ return false;
85
+ };
86
+
87
+ const worktreeEntries = (repoRoot) => {
88
+ const result = git(repoRoot, ['worktree', 'list', '--porcelain']);
89
+ if (result.status !== 0) failGit(result);
90
+ const entries = [];
91
+ let current = {};
92
+ const flush = () => {
93
+ if (current.worktree) entries.push(current);
94
+ current = {};
95
+ };
96
+ for (const line of String(result.stdout || '').split('\n')) {
97
+ if (line === '') {
98
+ flush();
99
+ continue;
100
+ }
101
+ const space = line.indexOf(' ');
102
+ const key = space === -1 ? line : line.slice(0, space);
103
+ const value = space === -1 ? '' : line.slice(space + 1);
104
+ if (key === 'worktree') current.worktree = value;
105
+ else if (key === 'branch') current.branch = value;
106
+ }
107
+ flush();
108
+ return entries;
109
+ };
110
+
111
+ const samePath = (left, right) => {
112
+ try {
113
+ return fs.realpathSync(left) === fs.realpathSync(right);
114
+ } catch {
115
+ return path.resolve(left) === path.resolve(right);
116
+ }
117
+ };
118
+
119
+ const completePair = (repoRoot, slug) => {
120
+ const dir = worktreeDir(repoRoot, slug);
121
+ if (!fs.existsSync(dir) || !fs.statSync(dir).isDirectory()) return false;
122
+ const branch = `refs/heads/${branchName(slug)}`;
123
+ return worktreeEntries(repoRoot).some((entry) => entry.branch === branch && samePath(entry.worktree, dir));
124
+ };
125
+
126
+ const taskLiveness = (teamRoot, slug) => {
127
+ let status;
128
+ try {
129
+ status = JSON.parse(fs.readFileSync(path.join(teamRoot, 'tasks', slug, 'status.json'), 'utf8'));
130
+ } catch {
131
+ return { kind: 'missing', state: '' };
132
+ }
133
+ if (!status || typeof status.state !== 'string' || status.state === '') return { kind: 'missing', state: '' };
134
+ return {
135
+ kind: TERMINAL_STATES.has(status.state) ? 'terminal' : 'live',
136
+ state: status.state,
137
+ };
138
+ };
139
+
140
+ const resolvedStore = (dir, env) => {
141
+ if (env.AI_RULES_TEAM_ROOT) return path.resolve(env.AI_RULES_TEAM_ROOT);
142
+ if (env.AI_RULES_TEAM_DB_ROOT) return path.resolve(env.AI_RULES_TEAM_DB_ROOT);
143
+ const local = path.join(dir, '.ai.local', 'team');
144
+ try {
145
+ return fs.realpathSync(local);
146
+ } catch {
147
+ return local;
148
+ }
149
+ };
150
+
151
+ const printActivation = (repoRoot, slug, teamRoot) => {
152
+ const dir = worktreeDir(repoRoot, slug);
153
+ process.stdout.write(`AI_RULES_TEAM_ROOT=${teamRoot}\n`);
154
+ process.stdout.write(`worktree=${dir} branch=${branchName(slug)}\n`);
155
+ process.stdout.write(
156
+ `hook: cd ${dir} && TEAM_TASK_SLUG=${slug} AI_RULES_TEAM_ROOT=${teamRoot} bash .cursor/hooks/chain-team-phases.sh\n`,
157
+ );
158
+ };
159
+
160
+ const chmodTree = (target, writable) => {
161
+ let stat;
162
+ try {
163
+ stat = fs.lstatSync(target);
164
+ } catch {
165
+ return;
166
+ }
167
+ if (stat.isSymbolicLink()) return;
168
+ fs.chmodSync(target, stat.isDirectory() ? (writable ? 0o755 : 0o555) : writable ? 0o644 : 0o444);
169
+ if (!stat.isDirectory()) return;
170
+ for (const name of fs.readdirSync(target)) chmodTree(path.join(target, name), writable);
171
+ };
172
+
173
+ const copyReadOnly = (source, dest) => {
174
+ const stat = fs.lstatSync(source);
175
+ if (stat.isSymbolicLink()) {
176
+ warn(`skipped symlink seed ${source}`);
177
+ return;
178
+ }
179
+ if (stat.isDirectory()) {
180
+ fs.mkdirSync(dest, { recursive: true });
181
+ for (const name of fs.readdirSync(source)) copyReadOnly(path.join(source, name), path.join(dest, name));
182
+ fs.chmodSync(dest, 0o555);
183
+ return;
184
+ }
185
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
186
+ fs.copyFileSync(source, dest);
187
+ fs.chmodSync(dest, 0o444);
188
+ };
189
+
190
+ const seedOverlay = (repoRoot, dir, teamRoot) => {
191
+ const sourceRoot = path.join(repoRoot, '.ai.local');
192
+ const destRoot = path.join(dir, '.ai.local');
193
+ fs.mkdirSync(destRoot, { recursive: true });
194
+ for (const name of [...SEED_DIRS, ...SEED_FILES]) {
195
+ const source = path.join(sourceRoot, name);
196
+ if (!fs.existsSync(source)) {
197
+ warn(`missing ${source}; skipped`);
198
+ continue;
199
+ }
200
+ copyReadOnly(source, path.join(destRoot, name));
201
+ }
202
+ const link = path.join(destRoot, 'team');
203
+ try {
204
+ fs.symlinkSync(teamRoot, link, 'dir');
205
+ } catch (error) {
206
+ warn(`team symlink refused (${error.code || error.message}); degrading to env-only`);
207
+ }
208
+ };
209
+
210
+ const listedPaths = (worktree, args) => {
211
+ const result = git(worktree, args);
212
+ if (result.status !== 0) return [];
213
+ return String(result.stdout || '')
214
+ .split('\n')
215
+ .map((line) => line.trim())
216
+ .filter(Boolean);
217
+ };
218
+
219
+ const clearOneSeed = (worktree, rel) => {
220
+ const abs = path.join(worktree, rel);
221
+ let stat;
222
+ try {
223
+ stat = fs.lstatSync(abs);
224
+ } catch {
225
+ return;
226
+ }
227
+ if (stat.isSymbolicLink()) {
228
+ fs.unlinkSync(abs);
229
+ return;
230
+ }
231
+ chmodTree(abs, true);
232
+ const tracked = listedPaths(worktree, ['ls-files', '--', rel]);
233
+ if (tracked.length === 0) {
234
+ fs.rmSync(abs, { recursive: true, force: true });
235
+ return;
236
+ }
237
+ const restored = git(worktree, ['checkout', '--', rel]);
238
+ if (restored.status !== 0) failGit(restored);
239
+ for (const extra of listedPaths(worktree, ['ls-files', '--others', '--exclude-standard', '--', rel])) {
240
+ fs.rmSync(path.join(worktree, extra), { recursive: true, force: true });
241
+ }
242
+ };
243
+
244
+ const clearSeeds = (dir) => {
245
+ const inside = git(dir, ['rev-parse', '--is-inside-work-tree']);
246
+ if (inside.status !== 0) return;
247
+ const link = path.join(dir, '.ai.local', 'team');
248
+ try {
249
+ if (fs.lstatSync(link).isSymbolicLink()) fs.unlinkSync(link);
250
+ } catch {
251
+ // No seed link. A real team directory is not a seed and is left alone.
252
+ }
253
+ for (const name of [...SEED_DIRS, ...SEED_FILES]) clearOneSeed(dir, path.join('.ai.local', name));
254
+ };
255
+
256
+ const branchMerged = (repoRoot, slug) => {
257
+ const result = git(repoRoot, ['merge-base', '--is-ancestor', branchName(slug), 'HEAD']);
258
+ if (result.status === 0) return true;
259
+ if (result.status === 1) return false;
260
+ failGit(result);
261
+ return false;
262
+ };
263
+
264
+ const requireTask = (teamRoot, slug) => {
265
+ const statusFile = path.join(teamRoot, 'tasks', slug, 'status.json');
266
+ if (!fs.existsSync(statusFile)) fail(`missing task ${slug}: ${statusFile} does not exist`);
267
+ };
268
+
269
+ const create = (repoRoot, slug, env) => {
270
+ const teamRoot = mainTeamRoot(repoRoot, env);
271
+ requireTask(teamRoot, slug);
272
+ if (completePair(repoRoot, slug)) {
273
+ process.stdout.write(`task-worktree: ${slug} already exists\n`);
274
+ printActivation(repoRoot, slug, teamRoot);
275
+ return;
276
+ }
277
+ const dir = worktreeDir(repoRoot, slug);
278
+ if (fs.existsSync(dir)) fail(`worktree directory already exists: ${dir}`);
279
+ if (branchExists(repoRoot, slug)) fail(`branch already exists: ${branchName(slug)}`);
280
+ const added = git(repoRoot, ['worktree', 'add', '-b', branchName(slug), '--', path.relative(repoRoot, dir)]);
281
+ if (added.status !== 0) failGit(added);
282
+ try {
283
+ seedOverlay(repoRoot, dir, teamRoot);
284
+ } catch (error) {
285
+ process.stderr.write(`task-worktree: seed failed (${error.message}); left for git worktree prune\n`);
286
+ process.exit(1);
287
+ }
288
+ printActivation(repoRoot, slug, teamRoot);
289
+ };
290
+
291
+ const list = (repoRoot, env) => {
292
+ const teamRoot = mainTeamRoot(repoRoot, env);
293
+ const root = path.join(repoRoot, '.ai.local', 'worktrees');
294
+ let names = [];
295
+ try {
296
+ names = fs
297
+ .readdirSync(root, { withFileTypes: true })
298
+ .filter((entry) => entry.isDirectory() && validSlug(entry.name))
299
+ .map((entry) => entry.name)
300
+ .sort();
301
+ } catch {
302
+ names = [];
303
+ }
304
+ for (const slug of names) {
305
+ const dir = worktreeDir(repoRoot, slug);
306
+ const branch = branchExists(repoRoot, slug) ? branchName(slug) : 'missing';
307
+ const liveness = taskLiveness(teamRoot, slug);
308
+ process.stdout.write(
309
+ `slug=${slug} branch=${branch} path=${dir} state=${liveness.kind} store=${resolvedStore(dir, env)}\n`,
310
+ );
311
+ }
312
+ };
313
+
314
+ const remove = (repoRoot, slug, force, env) => {
315
+ const teamRoot = mainTeamRoot(repoRoot, env);
316
+ const dir = worktreeDir(repoRoot, slug);
317
+ const dirExists = fs.existsSync(dir);
318
+ const hasBranch = branchExists(repoRoot, slug);
319
+ if (!dirExists && !hasBranch) {
320
+ process.stdout.write(`task-worktree: ${slug} already removed\n`);
321
+ return;
322
+ }
323
+ const liveness = taskLiveness(teamRoot, slug);
324
+ if (liveness.kind === 'live') fail(`refuse: slug ${slug} is live (${liveness.state})`);
325
+ const unmerged = hasBranch && !branchMerged(repoRoot, slug);
326
+ if (unmerged && !force) fail(`refuse: branch ${branchName(slug)} is unmerged; pass --force to delete it`);
327
+ if (unmerged && force) {
328
+ process.stdout.write(`task-worktree: --force: deleting unmerged branch ${branchName(slug)}\n`);
329
+ }
330
+ if (dirExists) {
331
+ clearSeeds(dir);
332
+ const removed = git(repoRoot, ['worktree', 'remove', dir]);
333
+ if (removed.status !== 0) failGit(removed);
334
+ }
335
+ if (hasBranch) {
336
+ const deleted = git(repoRoot, ['branch', unmerged ? '-D' : '-d', branchName(slug)]);
337
+ if (deleted.status !== 0) failGit(deleted);
338
+ }
339
+ process.stdout.write(`task-worktree: removed ${slug}\n`);
340
+ };
341
+
342
+ const parseArgs = (argv) => {
343
+ const force = argv.includes('--force');
344
+ const positionals = argv.filter((arg) => arg !== '--force');
345
+ return { command: positionals[0], slug: positionals[1], extra: positionals[2], force };
346
+ };
347
+
348
+ const main = () => {
349
+ const { command, slug, extra, force } = parseArgs(process.argv.slice(2));
350
+ if (!command || extra !== undefined) fail(USAGE);
351
+ if (force && command !== 'remove') fail(USAGE);
352
+ if (command === 'list') {
353
+ if (slug !== undefined) fail(USAGE);
354
+ list(repoRootOf(process.cwd()), process.env);
355
+ return;
356
+ }
357
+ if (command !== 'create' && command !== 'remove') fail(USAGE);
358
+ if (!validSlug(slug)) fail(`invalid slug "${slug ?? ''}"`);
359
+ const repoRoot = repoRootOf(process.cwd());
360
+ if (command === 'create') create(repoRoot, slug, process.env);
361
+ else remove(repoRoot, slug, force, process.env);
362
+ };
363
+
364
+ if (invokedDirectly()) main();
@@ -3751,7 +3751,7 @@ export const OPENAPI_DOCUMENT = {
3751
3751
  tags: ['tasks'],
3752
3752
  summary: 'Delete one task: the task folder first, then its projection rows',
3753
3753
  description:
3754
- '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.',
3754
+ '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.',
3755
3755
  operationId: 'deleteTask',
3756
3756
  parameters: [slugParameter],
3757
3757
  responses: {
@@ -3760,7 +3760,7 @@ export const OPENAPI_DOCUMENT = {
3760
3760
  403: errorResponse('A non-loopback Host or Origin was rejected before routing'),
3761
3761
  404: errorResponse('The task does not exist in the projection or on disk'),
3762
3762
  405: methodNotAllowedResponse,
3763
- 409: errorResponse('The slug is the active task; the delete is refused with `details.activeSlug` naming it'),
3763
+ 409: errorResponse('The slug is live (its own `status.json` state is not terminal); the delete is refused with `details.activeSlug` naming it'),
3764
3764
  503: errorResponse('The projection is disabled, the database is missing, unusable, busy, or the child exceeded its time bound'),
3765
3765
  },
3766
3766
  }),
@@ -747,6 +747,70 @@ export function listTaskDirectories(teamRoot) {
747
747
  .sort();
748
748
  }
749
749
 
750
+ /**
751
+ * Terminal `status.json` states — the exact set the hook and autoroute
752
+ * templates pin (`prompt-autoroute.mjs.tmpl`, `chain-team-phases.sh.tmpl`).
753
+ * A slug whose state is in this set is closed and is not live.
754
+ */
755
+ export const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
756
+
757
+ /**
758
+ * The live slugs in the team root: every task directory whose `status.json`
759
+ * parses to a non-terminal `state`. This is the canonical live-slug predicate
760
+ * — computed from the task store, never from `active-task.json`. A missing or
761
+ * unreadable status is not a live slug.
762
+ *
763
+ * @param {string} teamRoot
764
+ * @returns {string[]} sorted live slugs
765
+ */
766
+ export function liveTaskSlugs(teamRoot) {
767
+ const live = [];
768
+ for (const slug of listTaskDirectories(teamRoot)) {
769
+ try {
770
+ const status = parseStatusJson(readTextFile(path.join(teamRoot, 'tasks', slug, KNOWN_FILES.status)));
771
+ const state = status && typeof status.state === 'string' ? status.state : null;
772
+ if (state !== null && !TERMINAL_STATES.has(state)) live.push(slug);
773
+ } catch {
774
+ /* an unreadable status is not a live slug */
775
+ }
776
+ }
777
+ return live;
778
+ }
779
+
780
+ /**
781
+ * Rebuild `active-task.json` as the UI projection of the live slugs:
782
+ * `{"schemaVersion":1,"slugs":[...],"updatedAt"}` — sorted, deduped, live
783
+ * slugs only; an empty array means "no pointer" for every reader. `team-db
784
+ * sync` (both faces) and `delete` are the only writers, so the projection
785
+ * self-heals on every projection run; readers accept the legacy single-slot
786
+ * `{"slug"}` shape forever. Atomic tmp + rename, best-effort: a failure is a
787
+ * logged finding, never a failed sync or delete.
788
+ *
789
+ * @param {string} teamRoot
790
+ * @param {{ env?: Record<string, string | undefined> }} [options]
791
+ * @returns {boolean} whether the file was (re)written
792
+ */
793
+ export function rebuildActiveTaskPointer(teamRoot, options = {}) {
794
+ try {
795
+ const slugs = liveTaskSlugs(teamRoot);
796
+ const file = path.join(teamRoot, 'active-task.json');
797
+ const content = `${JSON.stringify({ schemaVersion: 1, slugs, updatedAt: new Date().toISOString() })}\n`;
798
+ try {
799
+ if (fs.readFileSync(file, 'utf8') === content) return false;
800
+ } catch {
801
+ /* absent or unreadable: write it */
802
+ }
803
+ fs.mkdirSync(teamRoot, { recursive: true });
804
+ const temporary = `${file}.tmp`;
805
+ fs.writeFileSync(temporary, content, { encoding: 'utf8', mode: 0o600 });
806
+ fs.renameSync(temporary, file);
807
+ return true;
808
+ } catch (error) {
809
+ logProjectionFailure('E_POINTER_REBUILD', error.message, options.env);
810
+ return false;
811
+ }
812
+ }
813
+
750
814
  const hashFile = (absolute) => {
751
815
  const hash = crypto.createHash('sha256');
752
816
  const fd = fs.openSync(absolute, 'r');
@@ -4963,6 +5027,10 @@ export function syncProjection(options = {}) {
4963
5027
  result.error = result.errors[0] ? `${result.errors[0].path}: ${result.errors[0].reason}` : null;
4964
5028
  updateRun(db, runId, result);
4965
5029
  chmodDatabaseFiles(handle.dbPath);
5030
+ // The active-task pointer is a UI projection: rebuild it on every sync
5031
+ // face (slug and full) so it self-heals. Best-effort — a rebuild failure
5032
+ // is a logged finding, never a failed sync.
5033
+ rebuildActiveTaskPointer(handle.teamRoot, { env: options.env });
4966
5034
  return result;
4967
5035
  } catch (error) {
4968
5036
  result.exitCode = error instanceof TeamDbError ? error.exitCode : 2;
@@ -4988,16 +5056,17 @@ export function syncProjection(options = {}) {
4988
5056
  * The two legs converge prior partial states: a folder without rows loses
4989
5057
  * only the folder; rows without a folder lose only the rows. The row leg is
4990
5058
  * one transaction — the task row plus every child row by foreign-key cascade,
4991
- * plus the task's standalone search rows. The active-task guard and the slug
5059
+ * plus the task's standalone search rows. The live-status guard and the slug
4992
5060
  * confinement run before any leg, and a symlink at `tasks/<slug>` is refused,
4993
5061
  * never followed or removed.
4994
5062
  *
4995
5063
  * Returns the one-line result the CLI prints and the API child parses:
4996
5064
  * `{ ok: true, slug, folderRemoved, rowsDeleted }`. Throws `TeamDbError`:
4997
5065
  * `E_DISABLED` (kill switch, exit 1), `E_USAGE` (bad slug, exit 3),
4998
- * `E_NOT_FOUND` (nothing to delete, exit 1), `E_ACTIVE_TASK` (the guard,
4999
- * exit 1), `E_INTERNAL` (the folder leg failed, exit 1), and the
5000
- * database-level `E_DB_BUSY` (exit 4) / `E_DB_CORRUPT` (exit 2).
5066
+ * `E_NOT_FOUND` (nothing to delete, exit 1), `E_ACTIVE_TASK` (the requested
5067
+ * slug's own `status.json` is live, exit 1), `E_INTERNAL` (the folder leg
5068
+ * failed, exit 1), and the database-level `E_DB_BUSY` (exit 4) /
5069
+ * `E_DB_CORRUPT` (exit 2).
5001
5070
  */
5002
5071
  export function deleteTaskProjection(options = {}) {
5003
5072
  const slug = typeof options.slug === 'string' ? options.slug : '';
@@ -5011,21 +5080,22 @@ export function deleteTaskProjection(options = {}) {
5011
5080
  const tasksRoot = path.join(teamRoot, 'tasks');
5012
5081
  const taskDir = path.join(tasksRoot, slug);
5013
5082
 
5014
- // The guard reads the team root, not the database, and runs before any leg.
5015
- // The parse stays inside the try; the refusal lives outside it, so a named
5016
- // guard failure is never mistaken for an unreadable guard file. An
5017
- // unreadable or missing guard file does not block the delete.
5018
- let guardSlug = null;
5083
+ // The guard reads the requested slug's own `status.json` — not the pointer,
5084
+ // not the database — and runs before any leg. The parse stays inside the
5085
+ // try; the refusal lives outside it, so a live-state refusal is never
5086
+ // mistaken for an unreadable status. A missing or unreadable status does
5087
+ // not block the delete.
5088
+ let liveState = null;
5019
5089
  try {
5020
- const guard = JSON.parse(fs.readFileSync(path.join(teamRoot, 'active-task.json'), 'utf8'));
5021
- guardSlug = guard && typeof guard.slug === 'string' ? guard.slug : null;
5090
+ const status = parseStatusJson(readTextFile(path.join(taskDir, KNOWN_FILES.status)));
5091
+ liveState = typeof status.state === 'string' ? status.state : null;
5022
5092
  } catch {
5023
- guardSlug = null;
5093
+ liveState = null;
5024
5094
  }
5025
- if (guardSlug === slug) {
5095
+ if (liveState !== null && !TERMINAL_STATES.has(liveState)) {
5026
5096
  teamDbFail(
5027
5097
  'E_ACTIVE_TASK',
5028
- `${slug} is the active task; a pipeline may be writing into it, and deletion is blocked while it is active`,
5098
+ `${slug} is live (state ${liveState}); deletion is blocked until the task reaches a terminal state`,
5029
5099
  1,
5030
5100
  );
5031
5101
  }
@@ -5108,6 +5178,9 @@ export function deleteTaskProjection(options = {}) {
5108
5178
  }
5109
5179
 
5110
5180
  chmodDatabaseFiles(handle.dbPath);
5181
+ // The deleted slug leaves the UI projection on this delete; best-effort,
5182
+ // like every pointer rebuild.
5183
+ rebuildActiveTaskPointer(teamRoot, { env: options.env });
5111
5184
  return { ok: true, slug, folderRemoved: dirState === 'present', rowsDeleted };
5112
5185
  } finally {
5113
5186
  try {