@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
@@ -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
+ }