@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
@@ -25,9 +25,11 @@
25
25
  * `prompt.md`, `goal.md`), because the chain hook rewrites `status.json` on
26
26
  * every step and a rewritten status must not make a legacy folder look new.
27
27
  *
28
- * The slug named by `active-task.json` is excluded and printed: its intake is
29
- * still in flight, the same exclusion the backfill applies (architecture §8.4),
30
- * so it is judged once the task closes.
28
+ * Every live slug is excluded and printed: its intake is still in flight, the
29
+ * same exclusion the backfill applies (architecture §8.4), so it is judged
30
+ * once the task closes. A slug is live when its own `status.json` parses to a
31
+ * non-terminal state — the pointer `active-task.json` is never read, so the
32
+ * audit stays correct with several slugs live in one repo.
31
33
  *
32
34
  * Usage: node scripts/check-task-repositories.mjs [--tasks-root <dir>]
33
35
  * [--registry <file>] [--cutoff YYYY-MM-DD] [--json]
@@ -37,6 +39,9 @@ import fs from 'node:fs';
37
39
  import path from 'node:path';
38
40
  import { fileURLToPath } from 'node:url';
39
41
 
42
+ /** Terminal `status.json` states — the set the hook and autoroute templates pin. */
43
+ const TERMINAL_STATES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed']);
44
+
40
45
  const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
41
46
  // Two homes: `packages/ai-rules/scripts` in this repository, and
42
47
  // `<repo>/.ai.local/scripts` once `init` ships it to a consumer, where the task
@@ -136,9 +141,6 @@ function readJson(file) {
136
141
  }
137
142
  }
138
143
 
139
- /** `readJson` returns `undefined` for a parse error and `null` for a non-object. */
140
- const unusableJson = (value) => value === undefined || value === null;
141
-
142
144
  /** The registry's view of one slug: the ids its links name, sorted. */
143
145
  function linkedIds(registry, slug) {
144
146
  if (registry === null) return null;
@@ -159,16 +161,23 @@ function main() {
159
161
  console.log(`task-repositories: OK (no task store at ${args.tasksRoot})`);
160
162
  return;
161
163
  }
162
- const activeTaskFile = path.join(path.dirname(args.tasksRoot), 'active-task.json');
163
- let activeSlug = null;
164
- if (fs.existsSync(activeTaskFile)) {
165
- const active = readJson(activeTaskFile);
166
- if (active === undefined) {
167
- warnings.push('active-task.json is not valid JSON; no slug excluded as in-flight');
168
- } else if (!unusableJson(active) && typeof active.slug === 'string') {
169
- activeSlug = active.slug;
164
+ const folders = fs
165
+ .readdirSync(args.tasksRoot, { withFileTypes: true })
166
+ .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))
167
+ .map((entry) => entry.name)
168
+ .sort();
169
+
170
+ // The live-slug scan over the task store — never the `active-task.json`
171
+ // pointer, so several slugs can be in flight in one repo. An unreadable or
172
+ // missing `status.json` is not a live slug.
173
+ const liveSlugs = new Set();
174
+ for (const name of folders) {
175
+ const status = readJson(path.join(args.tasksRoot, name, 'status.json'));
176
+ if (status && typeof status.state === 'string' && !TERMINAL_STATES.has(status.state)) {
177
+ liveSlugs.add(name);
170
178
  }
171
179
  }
180
+
172
181
  let registry = fs.existsSync(args.registry) ? readJson(args.registry) : null;
173
182
  if (registry === undefined) usageError(`--registry is not valid JSON: ${args.registry}`);
174
183
  if (registry !== null && (!Array.isArray(registry.repositories) || !Array.isArray(registry.links))) {
@@ -177,12 +186,6 @@ function main() {
177
186
  }
178
187
  const knownIds = registry === null ? null : new Set(registry.repositories.map((record) => record.id));
179
188
 
180
- const folders = fs
181
- .readdirSync(args.tasksRoot, { withFileTypes: true })
182
- .filter((entry) => entry.isDirectory() && !entry.name.startsWith('.'))
183
- .map((entry) => entry.name)
184
- .sort();
185
-
186
189
  const violations = [];
187
190
  const legacy = [];
188
191
  const excluded = [];
@@ -191,7 +194,7 @@ function main() {
191
194
  const folder = path.join(args.tasksRoot, name);
192
195
  const pipelinePath = path.join(folder, 'pipeline.json');
193
196
  if (!fs.existsSync(pipelinePath)) continue;
194
- if (name === activeSlug) {
197
+ if (liveSlugs.has(name)) {
195
198
  excluded.push(name);
196
199
  continue;
197
200
  }
@@ -249,7 +252,7 @@ function main() {
249
252
 
250
253
  const summary = `${folders.length} task folders, ${checked} with pipeline.json${
251
254
  legacy.length > 0 ? `, legacy before ${args.cutoff}: ${legacy.length}` : ''
252
- }${excluded.length > 0 ? `, excluded (active): ${excluded.join(', ')}` : ''}`;
255
+ }${excluded.length > 0 ? `, excluding live: ${excluded.join(', ')}` : ''}`;
253
256
  for (const warning of warnings) console.error(`WARN ${warning}`);
254
257
  if (args.json) {
255
258
  console.log(
@@ -41,7 +41,7 @@ const GUARD_STALE_MS = 30000;
41
41
  * flight is never stolen.
42
42
  */
43
43
  const LEASE_WARM_MS = 5000;
44
- const NAME_PATTERN = /^[a-z0-9][a-z0-9._-]{0,63}$/;
44
+ const NAME_PATTERN = /^[a-z0-9][a-z0-9._#-]{0,63}$/;
45
45
  const KINDS = new Set(['exclusive', 'port', 'advisory']);
46
46
 
47
47
  const newToken = () => crypto.randomBytes(12).toString('hex');
@@ -293,6 +293,7 @@ const describeOwner = (record) => {
293
293
  export function acquireLease({
294
294
  aiLocalRoot,
295
295
  name,
296
+ storedName = null,
296
297
  kind = 'exclusive',
297
298
  port = null,
298
299
  label = null,
@@ -331,7 +332,7 @@ export function acquireLease({
331
332
  const startedAt = new Date().toISOString();
332
333
  return {
333
334
  schemaVersion: LEASE_SCHEMA_VERSION,
334
- name,
335
+ name: storedName ?? name,
335
336
  kind,
336
337
  owner: {
337
338
  pid,
@@ -7,7 +7,7 @@
7
7
  * [--allow-unlocked] [--json] [--root <dir>]
8
8
  * release --name <res> --token <t> [--root <dir>] [--json]
9
9
  * run --name <res> [acquire flags] -- <command> [args…]
10
- * list [--json] [--task <slug>] [--live] [--root <dir>]
10
+ * list [--json] [--name <res>] [--task <slug>] [--live] [--root <dir>]
11
11
  * status --name <res> [--json]
12
12
  * watch [--interval 1s] [--json] [--once] [--no-color]
13
13
  * scan [--json] [--known-only | --all]
@@ -98,7 +98,7 @@ const VERB_FLAGS = {
98
98
  'name', 'kind', 'port', 'label', 'task', 'agent', 'wait', 'ttl', 'allow-unlocked',
99
99
  'root', 'pid', 'token', 'cwd', 'command',
100
100
  ]),
101
- list: new Set(['json', 'root', 'task', 'live']),
101
+ list: new Set(['json', 'root', 'task', 'live', 'name']),
102
102
  status: new Set(['name', 'json', 'root']),
103
103
  watch: new Set(['interval', 'json', 'once', 'no-color', 'root', 'task']),
104
104
  scan: new Set(['json', 'known-only', 'all', 'root']),
@@ -771,12 +771,15 @@ export function buildSnapshot(roots) {
771
771
  }
772
772
 
773
773
  const filterSnapshot = (snapshot, flags) => {
774
- if (!flags.task && !flags.live) return snapshot;
774
+ if (!flags.task && !flags.live && !flags.name) return snapshot;
775
775
  return {
776
776
  ...snapshot,
777
- processes: snapshot.processes.filter(
778
- (item) => (!flags.task || item.task === flags.task) && (!flags.live || item.state === 'live'),
779
- ),
777
+ processes: snapshot.processes.filter((item) => {
778
+ if (flags.task && item.task !== flags.task) return false;
779
+ if (flags.live && item.state !== 'live') return false;
780
+ if (flags.name && item.name !== flags.name && !item.name.startsWith(`${flags.name}#`)) return false;
781
+ return true;
782
+ }),
780
783
  };
781
784
  };
782
785
 
@@ -927,7 +930,7 @@ const parseFlags = (verb, argv) => {
927
930
  const requireName = (flags) => {
928
931
  if (!flags.name) fail('--name is required');
929
932
  if (!isValidLeaseName(flags.name)) {
930
- fail(`--name must be a lowercase resource name (a-z, 0-9, ".", "_", "-"), got "${flags.name}"`);
933
+ fail(`--name must be a lowercase resource name (a-z, 0-9, ".", "_", "#", "-"), got "${flags.name}"`);
931
934
  }
932
935
  return flags.name;
933
936
  };
@@ -981,11 +984,32 @@ const requireLiveOwner = (flags, fallback) => {
981
984
  return pid;
982
985
  };
983
986
 
984
- const leaseOptions = (flags, roots, name, pid) => {
987
+ /**
988
+ * `start` / `run` / `acquire` with `--task <slug>` record `leases/<name>#<slug>.json`.
989
+ * The JSON `name` stays the requested resource; `owner.task` stays the slug.
990
+ */
991
+ const leaseIdentity = (flags) => {
992
+ const requested = requireName(flags);
993
+ const task = typeof flags.task === 'string' ? flags.task : '';
994
+ if (task === '') return { requested, effective: requested };
995
+ const effective = `${requested}#${task}`;
996
+ if (!isValidLeaseName(effective)) {
997
+ fail(`effective lease name "${effective}" must be a lowercase lease name of at most 64 characters`);
998
+ }
999
+ return { requested, effective };
1000
+ };
1001
+
1002
+ const namesMatching = (aiLocalRoot, requested) =>
1003
+ listLeases(aiLocalRoot)
1004
+ .map((entry) => entry.name)
1005
+ .filter((name) => name === requested || name.startsWith(`${requested}#`));
1006
+
1007
+ const leaseOptions = (flags, roots, identity, pid) => {
985
1008
  const port = parsePort(flags, null);
986
1009
  return {
987
1010
  aiLocalRoot: roots.aiLocalRoot,
988
- name,
1011
+ name: identity.effective,
1012
+ storedName: identity.requested,
989
1013
  kind: flags.kind ? parseKind(flags) : port === null ? 'exclusive' : 'port',
990
1014
  port,
991
1015
  label: flags.label ?? null,
@@ -1018,8 +1042,8 @@ const describeAcquire = (result) => {
1018
1042
 
1019
1043
  const acquireVerb = (flags) => {
1020
1044
  const roots = resolveRoots(flags);
1021
- const name = requireName(flags);
1022
- const result = acquireLease(leaseOptions(flags, roots, name, requireLiveOwner(flags, process.ppid)));
1045
+ const identity = leaseIdentity(flags);
1046
+ const result = acquireLease(leaseOptions(flags, roots, identity, requireLiveOwner(flags, process.ppid)));
1023
1047
  if (flags.json) {
1024
1048
  out(renderJson(result));
1025
1049
  return result.acquired || (result.fatal && result.skipped) ? 0 : result.fatal ? 3 : 1;
@@ -1064,10 +1088,11 @@ const releaseVerb = (flags) => {
1064
1088
  const runVerb = async (flags, tail) => {
1065
1089
  if (!tail || tail.length === 0) fail('run needs a command after --');
1066
1090
  const roots = resolveRoots(flags);
1067
- const name = requireName(flags);
1091
+ const identity = leaseIdentity(flags);
1092
+ const name = identity.effective;
1068
1093
  // `run` owns the lease for the child's lifetime, so the manager — not the
1069
1094
  // parent shell — is the recorded holder.
1070
- const options = leaseOptions(flags, roots, name, flags.pid ? positiveInt(flags.pid, '--pid') : process.pid);
1095
+ const options = leaseOptions(flags, roots, identity, flags.pid ? positiveInt(flags.pid, '--pid') : process.pid);
1071
1096
  const command = flags.command ?? tail.join(' ');
1072
1097
  const acquired = acquireLease({ ...options, command });
1073
1098
  if (!acquired.acquired) {
@@ -1161,6 +1186,7 @@ const runVerb = async (flags, tail) => {
1161
1186
 
1162
1187
  const listVerb = (flags) => {
1163
1188
  const roots = resolveRoots(flags);
1189
+ if (flags.name) requireName(flags);
1164
1190
  const snapshot = filterSnapshot(buildSnapshot(roots), flags);
1165
1191
  if (flags.json) {
1166
1192
  out(renderJson(snapshot));
@@ -1172,14 +1198,16 @@ const listVerb = (flags) => {
1172
1198
 
1173
1199
  const statusVerb = (flags) => {
1174
1200
  const roots = resolveRoots(flags);
1175
- const name = requireName(flags);
1201
+ const requested = requireName(flags);
1202
+ const matched = namesMatching(roots.aiLocalRoot, requested);
1203
+ const name = matched.includes(requested) || matched.length !== 1 ? requested : matched[0];
1176
1204
  const record = readLease(roots.aiLocalRoot, name);
1177
1205
  const state = record === null ? null : leaseState(record);
1178
1206
  const payload = {
1179
1207
  schemaVersion: SNAPSHOT_SCHEMA_VERSION,
1180
1208
  generatedAt: new Date().toISOString(),
1181
1209
  root: roots.repoRoot,
1182
- name,
1210
+ name: requested,
1183
1211
  path: leasePath(roots.aiLocalRoot, name),
1184
1212
  present: record !== null,
1185
1213
  state: state?.state ?? 'absent',
@@ -1191,10 +1219,10 @@ const statusVerb = (flags) => {
1191
1219
  return 0;
1192
1220
  }
1193
1221
  if (record === null) {
1194
- out(`processes: ${name} is not recorded`);
1222
+ out(`processes: ${requested} is not recorded`);
1195
1223
  return 0;
1196
1224
  }
1197
- out(`processes: ${name} is ${payload.state} (${payload.why}), pid ${payload.owner?.pid ?? '?'}`);
1225
+ out(`processes: ${requested} is ${payload.state} (${payload.why}), pid ${payload.owner?.pid ?? '?'}`);
1198
1226
  return 0;
1199
1227
  };
1200
1228
 
@@ -1449,7 +1477,9 @@ const stopVerb = async (flags) => {
1449
1477
  }
1450
1478
  } else {
1451
1479
  if (!flags.name) fail('stop needs --name <res> or --task <slug>');
1452
- names.push(requireName(flags));
1480
+ const requested = requireName(flags);
1481
+ const matched = namesMatching(roots.aiLocalRoot, requested);
1482
+ names.push(...(matched.length > 0 ? matched : [requested]));
1453
1483
  }
1454
1484
  if (names.length === 0) {
1455
1485
  if (flags.json) {
@@ -1676,7 +1706,8 @@ const terminateDetached = async (pid) => {
1676
1706
 
1677
1707
  const startVerb = async (flags) => {
1678
1708
  const roots = resolveRoots(flags);
1679
- const name = requireName(flags);
1709
+ const identity = leaseIdentity(flags);
1710
+ const name = identity.effective;
1680
1711
  if (!flags.command) fail('start needs --command');
1681
1712
  const port = flags.port === undefined ? 0 : positiveInt(flags.port, '--port', { max: 65535, allowZero: true });
1682
1713
  const waitMs = parseReadyWait(flags);
@@ -1757,6 +1788,7 @@ const startVerb = async (flags) => {
1757
1788
  const lease = acquireLease({
1758
1789
  aiLocalRoot: roots.aiLocalRoot,
1759
1790
  name,
1791
+ storedName: identity.requested,
1760
1792
  kind: 'port',
1761
1793
  port: port > 0 ? port : null,
1762
1794
  label: flags.label ?? 'dev-server',
@@ -1979,7 +2011,7 @@ const USAGE = [
1979
2011
  ' the owner is the parent shell (--pid $$ overrides); use run for a command',
1980
2012
  ' release --name <res> --token <t> [--root <dir>] [--json]',
1981
2013
  ' run --name <res> [acquire flags] -- <command> [args…]',
1982
- ' list [--json] [--task <slug>] [--live] [--root <dir>]',
2014
+ ' list [--json] [--name <res>] [--task <slug>] [--live] [--root <dir>]',
1983
2015
  ' status --name <res> [--json] [--root <dir>]',
1984
2016
  ' watch [--interval 1s] [--json] [--once] [--no-color] [--root <dir>]',
1985
2017
  ' scan [--json] [--known-only | --all] [--root <dir>]',
@@ -9,9 +9,10 @@
9
9
  * 4. print a combined report (derive summary + improver report + a read-only
10
10
  * seed-tracker notice when staged seeds ≥ SEED_TRACKER_THRESHOLD).
11
11
  *
12
- * No lock is held across the chain, and the loop never writes
13
- * `status.json` / `metrics.json`; the seed report is read-only over
14
- * `rules-library/`.
12
+ * The chain itself is one fail-fast mkdir lock (`.self-learning.lock`,
13
+ * `timeoutMs: 0`). A contender prints the skip line and does not interleave.
14
+ * The loop never writes `status.json` / `metrics.json`; the seed report is
15
+ * read-only over `rules-library/`.
15
16
  *
16
17
  * Two read-only modes inspect capture without running it:
17
18
  * `node run.mjs --status` — per signature: distinct slugs, tier + next
@@ -47,6 +48,7 @@ import {
47
48
  } from './rule-improver.mjs';
48
49
  import { deriveGateSignals } from './derive-gate-signals.mjs';
49
50
  import { MIN_COHORT_SIZE, oracle, readAllTasks } from './efficacy-oracle.mjs';
51
+ import { acquireLock, releaseLock } from './lock.mjs';
50
52
 
51
53
  export const DEFAULT_BASE_DIR = path.join(process.cwd(), '.ai.local');
52
54
  export const SEED_TRACKER_THRESHOLD = 20;
@@ -105,12 +107,42 @@ export function renderReport({ derived, appended, appendErrors, improver, seedCo
105
107
  return `${lines.join('\n')}\n`;
106
108
  }
107
109
 
110
+ const SELF_LEARNING_LOCK = '.self-learning.lock';
111
+ const SELF_LEARNING_BUSY = 'self-learning loop busy';
112
+
113
+ const skippedLoop = () => ({
114
+ skipped: true,
115
+ reason: SELF_LEARNING_BUSY,
116
+ derived: { signals: [], skipped: [], errors: [] },
117
+ appended: [],
118
+ appendErrors: [],
119
+ improver: { applied: [], staged: [], rejected: [], errors: [], report: '' },
120
+ seedCount: 0,
121
+ report: `WARNING: self-learning loop skipped: ${SELF_LEARNING_BUSY}\n`,
122
+ });
123
+
108
124
  /**
109
- * Run the full loop. Every write (each `appendSignal`, `runImprover`) owns its
110
- * own lock; nothing is held across the chain. Returns the derive/append/
111
- * improver results, the seed count, and the combined report.
125
+ * Run the full loop under one fail-fast lock. Each `appendSignal` and
126
+ * `runImprover` still takes its own lock inside the chain. A contender
127
+ * returns the skip line and does not derive, append, or improve.
112
128
  */
113
129
  export function runLoop({ baseDir = DEFAULT_BASE_DIR } = {}) {
130
+ const lockPath = path.join(baseDir, SELF_LEARNING_LOCK);
131
+ let token;
132
+ try {
133
+ token = acquireLock(lockPath, { timeoutMs: 0 });
134
+ } catch (error) {
135
+ if (error instanceof Error && error.message === 'lock timeout') return skippedLoop();
136
+ throw error;
137
+ }
138
+ try {
139
+ return runLoopBody(baseDir);
140
+ } finally {
141
+ releaseLock(lockPath, token);
142
+ }
143
+ }
144
+
145
+ function runLoopBody(baseDir) {
114
146
  const signalsPath = path.join(baseDir, 'signals.jsonl');
115
147
  const libraryDir = path.join(baseDir, 'rules-library');
116
148
 
@@ -0,0 +1,246 @@
1
+ /**
2
+ * `.ai.local/.env` settings: two booleans, both `false` by default, and one
3
+ * non-negative integer.
4
+ *
5
+ * `AI_RULES_ALLOW_GIT_WRITES` lifts the shell guard's git-write stop;
6
+ * `AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS` switches the autoroute prompt face on;
7
+ * `AI_RULES_MAX_PARALLEL_TASKS` caps how many live slugs the autoroute wraps in
8
+ * parallel (default 4; `0` = unlimited).
9
+ * This module is the only reader of the file: importing it has no effect, and
10
+ * `readSetting` is a pure function of the file's bytes plus injected `exists` /
11
+ * `readText` effects, so a hook can import it with its own root and a test can
12
+ * resolve a fixture without touching the disk.
13
+ *
14
+ * Invocation: settings.mjs get <key> | list [--json] [--root <dir>]
15
+ *
16
+ * Exit code is always 0. An absent, unreadable or malformed file resolves to
17
+ * `false` (booleans) or the default (the numeric cap). A boolean that is not
18
+ * `true`/`1` or `false`/`0` warns and stays `false`, so no failure path can
19
+ * resolve to `true`.
20
+ */
21
+
22
+ import fs from 'node:fs';
23
+ import path from 'node:path';
24
+ import { fileURLToPath } from 'node:url';
25
+
26
+ /** The keys this module resolves; every other name is unknown. */
27
+ const SETTING_KEYS = [
28
+ 'AI_RULES_ALLOW_GIT_WRITES',
29
+ 'AI_RULES_AUTOROUTE_UNCHAINED_PROMPTS',
30
+ 'AI_RULES_MAX_PARALLEL_TASKS',
31
+ ];
32
+ /** Keys resolved as non-negative integers instead of booleans. */
33
+ const NUMERIC_KEYS = new Set(['AI_RULES_MAX_PARALLEL_TASKS']);
34
+ /** The cap value when the key is absent or rejected. */
35
+ const DEFAULT_MAX_PARALLEL_TASKS = 4;
36
+
37
+ const ENV_REL = path.join('.ai.local', '.env');
38
+ const TRUE_VALUES = new Set(['true', '1']);
39
+ /** Accepted off spellings. Anything else warns and still resolves to false. */
40
+ const FALSE_VALUES = new Set(['false', '0']);
41
+ const USAGE = 'usage: node .ai.local/scripts/settings.mjs get <key> | list [--json] [--root <dir>]';
42
+
43
+ /**
44
+ * Parse `.env` text into the known values that appear in it, plus one warning
45
+ * per anomaly. The last occurrence of a duplicated key wins.
46
+ *
47
+ * @param {string} text
48
+ * @returns {{ values: Map<string, string>, warnings: string[] }}
49
+ */
50
+ const parseEnv = (text) => {
51
+ const values = new Map();
52
+ const warnings = [];
53
+ const lines = String(text).split(/\r?\n/);
54
+ for (let index = 0; index < lines.length; index += 1) {
55
+ const line = lines[index].trim();
56
+ if (!line || line.startsWith('#')) continue;
57
+ const separator = line.indexOf('=');
58
+ if (separator < 0) {
59
+ warnings.push(`line ${index + 1} has no "="; skipped`);
60
+ continue;
61
+ }
62
+ const key = line.slice(0, separator).trim();
63
+ if (!SETTING_KEYS.includes(key)) {
64
+ warnings.push(`unknown key "${key}" on line ${index + 1}; skipped`);
65
+ continue;
66
+ }
67
+ if (values.has(key)) {
68
+ warnings.push(`duplicate key "${key}" on line ${index + 1}; the last value wins`);
69
+ }
70
+ values.set(key, line.slice(separator + 1).trim());
71
+ }
72
+ return { values, warnings };
73
+ };
74
+
75
+ /**
76
+ * A boolean setting. `true` / `1` enable it. `false` / `0` stay off without a
77
+ * warning. Every other spelling warns and stays off, so a typo cannot enable it.
78
+ *
79
+ * @param {string} key
80
+ * @param {string} raw
81
+ * @param {string[]} warnings
82
+ * @returns {boolean}
83
+ */
84
+ const resolveBoolean = (key, raw, warnings) => {
85
+ const normalized = raw.toLowerCase();
86
+ if (TRUE_VALUES.has(normalized)) return true;
87
+ if (!FALSE_VALUES.has(normalized)) {
88
+ warnings.push(`"${key}" = "${raw}" is not true or false; treating it as false`);
89
+ }
90
+ return false;
91
+ };
92
+
93
+ /**
94
+ * Read and parse the settings file once. Absent is silent; an unreadable path
95
+ * (permission error, a directory) is one warning and no values.
96
+ *
97
+ * @param {{ root?: string, exists?: (file: string) => boolean, readText?: (file: string) => string }} options
98
+ * @returns {{ parsed: { values: Map<string, string>, warnings: string[] }, warning: string | null }}
99
+ */
100
+ const readEnv = (options) => {
101
+ const {
102
+ root = process.cwd(),
103
+ exists = (file) => fs.existsSync(file),
104
+ readText = (file) => fs.readFileSync(file, 'utf8'),
105
+ } = options;
106
+ const file = path.join(root, ENV_REL);
107
+ if (!exists(file)) {
108
+ return { parsed: { values: new Map(), warnings: [] }, warning: null };
109
+ }
110
+ try {
111
+ return { parsed: parseEnv(readText(file)), warning: null };
112
+ } catch (error) {
113
+ const message = error instanceof Error ? error.message : String(error);
114
+ return { parsed: { values: new Map(), warnings: [] }, warning: `cannot read ${ENV_REL}: ${message}` };
115
+ }
116
+ };
117
+
118
+ /**
119
+ * All keys with their resolved value and whether the file supplied it, plus
120
+ * every file-level warning (duplicate key, unknown key, line without `=`).
121
+ * Booleans resolve through `TRUE_VALUES`; the numeric cap resolves through
122
+ * `readSetting`'s integer rule.
123
+ *
124
+ * @param {{ root?: string, exists?: (file: string) => boolean, readText?: (file: string) => string }} [options]
125
+ * @returns {{ keys: Array<{ key: string, value: boolean | number, source: 'file' | 'default' }>, warnings: string[] }}
126
+ */
127
+ export const listSettings = (options = {}) => {
128
+ const { parsed, warning } = readEnv(options);
129
+ const warnings = warning === null ? [...parsed.warnings] : [warning];
130
+ const keys = SETTING_KEYS.map((key) => {
131
+ if (!parsed.values.has(key)) {
132
+ return { key, value: NUMERIC_KEYS.has(key) ? DEFAULT_MAX_PARALLEL_TASKS : false, source: 'default' };
133
+ }
134
+ const raw = parsed.values.get(key);
135
+ if (NUMERIC_KEYS.has(key)) {
136
+ if (!/^\d+$/.test(raw)) {
137
+ warnings.push(`"${key}" = "${raw}" is not a non-negative integer; using the default ${DEFAULT_MAX_PARALLEL_TASKS}`);
138
+ return { key, value: DEFAULT_MAX_PARALLEL_TASKS, source: 'default' };
139
+ }
140
+ return { key, value: Number(raw), source: 'file' };
141
+ }
142
+ return { key, value: resolveBoolean(key, raw, warnings), source: 'file' };
143
+ });
144
+ return { keys, warnings };
145
+ };
146
+
147
+ /**
148
+ * Resolve one key. Never throws: a missing key, a missing file, an unreadable
149
+ * file and a rejected value all resolve to `false` (booleans) or to the
150
+ * default `4` (the numeric cap, which also accepts `0` = unlimited). A cap
151
+ * value that is not a non-negative integer warns and resolves to the default.
152
+ * Warnings carry every file-level anomaly (duplicate, unknown, no `=`) plus a
153
+ * rejected value, so `get` and `list` report the same states.
154
+ *
155
+ * @param {string} key
156
+ * @param {{ root?: string, exists?: (file: string) => boolean, readText?: (file: string) => string }} [options]
157
+ * @returns {{ value: boolean | number, source: 'file' | 'default', warnings: string[] }}
158
+ */
159
+ export const readSetting = (key, options = {}) => {
160
+ if (!SETTING_KEYS.includes(key)) {
161
+ return { value: false, source: 'default', warnings: [`unknown key "${key}"`] };
162
+ }
163
+ const { parsed, warning } = readEnv(options);
164
+ if (warning !== null) {
165
+ return NUMERIC_KEYS.has(key)
166
+ ? { value: DEFAULT_MAX_PARALLEL_TASKS, source: 'default', warnings: [warning] }
167
+ : { value: false, source: 'default', warnings: [warning] };
168
+ }
169
+ const warnings = [...parsed.warnings];
170
+ if (!parsed.values.has(key)) {
171
+ return NUMERIC_KEYS.has(key)
172
+ ? { value: DEFAULT_MAX_PARALLEL_TASKS, source: 'default', warnings }
173
+ : { value: false, source: 'default', warnings };
174
+ }
175
+ const raw = parsed.values.get(key);
176
+ if (NUMERIC_KEYS.has(key)) {
177
+ if (/^\d+$/.test(raw)) {
178
+ return { value: Number(raw), source: 'file', warnings };
179
+ }
180
+ warnings.push(`"${key}" = "${raw}" is not a non-negative integer; using the default ${DEFAULT_MAX_PARALLEL_TASKS}`);
181
+ return { value: DEFAULT_MAX_PARALLEL_TASKS, source: 'default', warnings };
182
+ }
183
+ return { value: resolveBoolean(key, raw, warnings), source: 'file', warnings };
184
+ };
185
+
186
+ /** Resolved options from `--root <dir>`; no flag keeps the working directory. */
187
+ const parseArgs = (argv) => {
188
+ const args = { command: argv[0] ?? null, key: null, json: false, root: undefined };
189
+ const rest = [];
190
+ for (let index = 1; index < argv.length; index += 1) {
191
+ if (argv[index] === '--json') {
192
+ args.json = true;
193
+ } else if (argv[index] === '--root') {
194
+ args.root = argv[index + 1];
195
+ index += 1;
196
+ } else {
197
+ rest.push(argv[index]);
198
+ }
199
+ }
200
+ args.key = rest[0] ?? null;
201
+ return args;
202
+ };
203
+
204
+ const warnLines = (warnings) => {
205
+ for (const message of warnings) process.stderr.write(`warn: ${message}\n`);
206
+ };
207
+
208
+ const main = (argv) => {
209
+ const args = parseArgs(argv);
210
+ const options = args.root === undefined ? {} : { root: args.root };
211
+
212
+ if (args.command === 'get' && args.key !== null) {
213
+ const resolved = readSetting(args.key, options);
214
+ process.stdout.write(`${resolved.value}\n`);
215
+ warnLines(resolved.warnings);
216
+ return;
217
+ }
218
+
219
+ if (args.command === 'list') {
220
+ const report = listSettings(options);
221
+ warnLines(report.warnings);
222
+ if (args.json) {
223
+ process.stdout.write(`${JSON.stringify(report)}\n`);
224
+ } else {
225
+ for (const row of report.keys) {
226
+ process.stdout.write(`${row.key}=${row.value} (${row.source})\n`);
227
+ }
228
+ }
229
+ return;
230
+ }
231
+
232
+ process.stderr.write(`${USAGE}\n`);
233
+ };
234
+
235
+ const invokedDirectly = (() => {
236
+ if (process.argv[1] === undefined) return false;
237
+ try {
238
+ return fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
239
+ } catch {
240
+ return path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
241
+ }
242
+ })();
243
+
244
+ if (invokedDirectly) {
245
+ main(process.argv.slice(2));
246
+ }