@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
@@ -8,7 +8,7 @@ const SERVER_PORTS = [3000,6006];
8
8
  import fs from 'node:fs';
9
9
  import net from 'node:net';
10
10
  import path from 'node:path';
11
- import { fileURLToPath } from 'node:url';
11
+ import { fileURLToPath, pathToFileURL } from 'node:url';
12
12
 
13
13
  const allowed = () => ({ permission: 'allow' });
14
14
 
@@ -30,14 +30,706 @@ const portIsOpen = (port) =>
30
30
  socket.setTimeout(400, () => done(false));
31
31
  });
32
32
 
33
+ /**
34
+ * Default settings resolver: a dynamic import of the seeded parser under the
35
+ * project root. A missing, unreadable or unimportable module yields `null`, so
36
+ * the guard answers without a parser instead of carrying a copy of one.
37
+ *
38
+ * @returns {Promise<((key: string) => boolean) | null>} `get(key)`, or `null`
39
+ */
40
+ const importSettings = async ({ root, exists, readText }) => {
41
+ const file = path.join(root, '.ai.local', 'scripts', 'settings.mjs');
42
+ if (!exists(file)) return null;
43
+ try {
44
+ const module = await import(pathToFileURL(file).href);
45
+ if (typeof module.readSetting !== 'function') return null;
46
+ return (key) => module.readSetting(key, { root, exists, readText }).value === true;
47
+ } catch {
48
+ return null;
49
+ }
50
+ };
51
+
52
+ /**
53
+ * `git` global options that take the next token as their value. Every other
54
+ * option is skipped as a flag, so an undocumented flag cannot hide the
55
+ * subcommand; an undocumented value-taking option surfaces as an unresolved
56
+ * subcommand and is asked, never allowed.
57
+ */
58
+ const GIT_VALUE_GLOBALS = new Set([
59
+ '-c',
60
+ '-C',
61
+ '--git-dir',
62
+ '--work-tree',
63
+ '--namespace',
64
+ '--config-env',
65
+ '--super-prefix',
66
+ '--exec-path',
67
+ ]);
68
+
69
+ /**
70
+ * Join backslash line continuations, then split on shell separators outside
71
+ * quotes. Command substitution is split too, so `$(git push --force)` is a
72
+ * segment the classifier sees rather than an opaque token.
73
+ */
74
+ const splitShellSegments = (command) => {
75
+ const text = String(command).replace(/\\\r?\n/g, '');
76
+ const segments = [];
77
+ let current = '';
78
+ let quote = null;
79
+ for (let index = 0; index < text.length; index += 1) {
80
+ const char = text[index];
81
+ if (quote !== null) {
82
+ current += char;
83
+ if (char === '\\' && quote === '"' && index + 1 < text.length) {
84
+ index += 1;
85
+ current += text[index];
86
+ continue;
87
+ }
88
+ if (char === quote) quote = null;
89
+ continue;
90
+ }
91
+ if (char === "'" || char === '"') {
92
+ quote = char;
93
+ current += char;
94
+ continue;
95
+ }
96
+ if (
97
+ char === ';' ||
98
+ char === '\n' ||
99
+ char === '\r' ||
100
+ char === '|' ||
101
+ char === '&' ||
102
+ char === '(' ||
103
+ char === ')' ||
104
+ char === '`'
105
+ ) {
106
+ if ((char === '|' || char === '&') && text[index + 1] === char) index += 1;
107
+ segments.push(current);
108
+ current = '';
109
+ continue;
110
+ }
111
+ current += char;
112
+ }
113
+ segments.push(current);
114
+ return segments.filter((segment) => segment.trim() !== '');
115
+ };
116
+
117
+ /** Decode the escapes of a `$'…'` ANSI-C quoted span. */
118
+ const decodeAnsiC = (text) => {
119
+ let output = '';
120
+ for (let index = 0; index < text.length; index += 1) {
121
+ const char = text[index];
122
+ if (char !== '\\') {
123
+ output += char;
124
+ continue;
125
+ }
126
+ const next = text[index + 1];
127
+ if (next === undefined) {
128
+ output += '\\';
129
+ break;
130
+ }
131
+ index += 1;
132
+ if (next === 'n') output += '\n';
133
+ else if (next === 'r') output += '\r';
134
+ else if (next === 't') output += '\t';
135
+ else if (next === '\\' || next === "'" || next === '"' || next === '?') output += next;
136
+ else if (next === 'x') {
137
+ const hex = text.slice(index + 1, index + 3);
138
+ if (/^[0-9a-fA-F]{2}$/.test(hex)) {
139
+ output += String.fromCharCode(parseInt(hex, 16));
140
+ index += 2;
141
+ } else output += '\\x';
142
+ } else if (next === 'u') {
143
+ const hex = text.slice(index + 1, index + 5);
144
+ if (/^[0-9a-fA-F]{4}$/.test(hex)) {
145
+ output += String.fromCharCode(parseInt(hex, 16));
146
+ index += 4;
147
+ } else output += '\\u';
148
+ } else if (/[0-7]/.test(next)) {
149
+ const octal = text.slice(index, index + 3).match(/^[0-7]{1,3}/)?.[0] ?? next;
150
+ output += String.fromCharCode(parseInt(octal, 8));
151
+ index += octal.length - 1;
152
+ } else output += next;
153
+ }
154
+ return output;
155
+ };
156
+
157
+ /**
158
+ * Shell-word tokenizer: quotes and escapes concatenate into the token value,
159
+ * and `quoted` records that the token carried quoting. A quoted `git`/`push`/
160
+ * `--force` is therefore as visible as an unquoted one; an unterminated quote
161
+ * is reported so the caller asks.
162
+ */
163
+ const tokenizeSegment = (segment) => {
164
+ const tokens = [];
165
+ let value = '';
166
+ let quoted = false;
167
+ let started = false;
168
+ let quote = null;
169
+ let unterminated = false;
170
+ let index = 0;
171
+ const push = () => {
172
+ if (started) tokens.push({ value, quoted });
173
+ value = '';
174
+ quoted = false;
175
+ started = false;
176
+ };
177
+ while (index < segment.length) {
178
+ const char = segment[index];
179
+ if (quote === null && /\s/.test(char)) {
180
+ push();
181
+ index += 1;
182
+ continue;
183
+ }
184
+ if (quote === "'") {
185
+ if (char === "'") {
186
+ quote = null;
187
+ index += 1;
188
+ continue;
189
+ }
190
+ value += char;
191
+ started = true;
192
+ index += 1;
193
+ continue;
194
+ }
195
+ if (quote === '"') {
196
+ if (char === '"') {
197
+ quote = null;
198
+ index += 1;
199
+ continue;
200
+ }
201
+ if (char === '\\' && index + 1 < segment.length) {
202
+ const next = segment[index + 1];
203
+ if ('"\\$`\n'.includes(next)) {
204
+ if (next !== '\n') value += next;
205
+ index += 2;
206
+ started = true;
207
+ continue;
208
+ }
209
+ }
210
+ value += char;
211
+ started = true;
212
+ index += 1;
213
+ continue;
214
+ }
215
+ if (quote === 'ansi') {
216
+ let raw = '';
217
+ let cursor = index;
218
+ while (cursor < segment.length) {
219
+ if (segment[cursor] === '\\' && cursor + 1 < segment.length) {
220
+ raw += segment[cursor] + segment[cursor + 1];
221
+ cursor += 2;
222
+ continue;
223
+ }
224
+ if (segment[cursor] === "'") break;
225
+ raw += segment[cursor];
226
+ cursor += 1;
227
+ }
228
+ value += decodeAnsiC(raw);
229
+ started = true;
230
+ if (cursor < segment.length && segment[cursor] === "'") {
231
+ quote = null;
232
+ cursor += 1;
233
+ } else {
234
+ unterminated = true;
235
+ quote = null;
236
+ }
237
+ index = cursor;
238
+ continue;
239
+ }
240
+ if (char === "'") {
241
+ quote = "'";
242
+ quoted = true;
243
+ started = true;
244
+ index += 1;
245
+ continue;
246
+ }
247
+ if (char === '"') {
248
+ quote = '"';
249
+ quoted = true;
250
+ started = true;
251
+ index += 1;
252
+ continue;
253
+ }
254
+ if (char === '$' && segment[index + 1] === "'") {
255
+ quote = 'ansi';
256
+ quoted = true;
257
+ started = true;
258
+ index += 2;
259
+ continue;
260
+ }
261
+ if (char === '\\' && index + 1 < segment.length) {
262
+ value += segment[index + 1];
263
+ quoted = true;
264
+ started = true;
265
+ index += 2;
266
+ continue;
267
+ }
268
+ value += char;
269
+ started = true;
270
+ index += 1;
271
+ }
272
+ push();
273
+ return { tokens, unterminated: unterminated || quote !== null };
274
+ };
275
+
276
+ /**
277
+ * Benign option allowlist per git verb. Anything not on the list — including
278
+ * every abbreviation git would resolve — asks. `--amend` is deliberately absent
279
+ * (it rewrites a commit), so `commit --amend` asks.
280
+ */
281
+ const OPTION_SPECS = {
282
+ push: {
283
+ long: new Set([
284
+ '--set-upstream',
285
+ '--follow-tags',
286
+ '--dry-run',
287
+ '--no-verify',
288
+ '--porcelain',
289
+ '--progress',
290
+ '--no-progress',
291
+ '--quiet',
292
+ '--verbose',
293
+ '--atomic',
294
+ '--no-atomic',
295
+ '--thin',
296
+ '--no-thin',
297
+ '--ipv4',
298
+ '--ipv6',
299
+ '--signed',
300
+ '--no-signed',
301
+ '--recurse-submodules',
302
+ '--no-recurse-submodules',
303
+ ]),
304
+ longValue: new Set([
305
+ '--repo',
306
+ '--push-option',
307
+ '--recurse-submodules',
308
+ ]),
309
+ short: new Set(['u', 'v', 'q', 'n', '4', '6']),
310
+ shortValue: new Set(['o']),
311
+ },
312
+ commit: {
313
+ long: new Set([
314
+ '--message',
315
+ '--file',
316
+ '--author',
317
+ '--date',
318
+ '--signoff',
319
+ '--quiet',
320
+ '--verbose',
321
+ '--dry-run',
322
+ '--no-verify',
323
+ '--allow-empty',
324
+ '--allow-empty-message',
325
+ '--fixup',
326
+ '--squash',
327
+ '--reset-author',
328
+ '--include',
329
+ '--only',
330
+ '--pathspec-file-nul',
331
+ '--cleanup',
332
+ '--template',
333
+ '--edit',
334
+ '--no-edit',
335
+ '--reuse-message',
336
+ '--reedit-message',
337
+ '--gpg-sign',
338
+ '--no-gpg-sign',
339
+ '--all',
340
+ '--patch',
341
+ '--short',
342
+ '--branch',
343
+ '--long',
344
+ '--status',
345
+ '--no-status',
346
+ '--trailer',
347
+ ]),
348
+ longValue: new Set([
349
+ '--message',
350
+ '--file',
351
+ '--author',
352
+ '--date',
353
+ '--fixup',
354
+ '--squash',
355
+ '--pathspec-from-file',
356
+ '--cleanup',
357
+ '--template',
358
+ '--reuse-message',
359
+ '--reedit-message',
360
+ '--trailer',
361
+ ]),
362
+ short: new Set(['a', 'm', 's', 'q', 'v', 'n', 'e', 'i', 'p', 'o', 'F', 'C', 'c', 't', 'S']),
363
+ shortValue: new Set(['m', 'F', 'C', 'c', 't']),
364
+ shortOptionalValue: new Set(['S']),
365
+ },
366
+ clean: {
367
+ long: new Set([
368
+ '--dry-run',
369
+ '--quiet',
370
+ '--interactive',
371
+ '--ignored',
372
+ '--no-ignored',
373
+ '--pathspec-file-nul',
374
+ '--verbose',
375
+ ]),
376
+ longValue: new Set(['--exclude']),
377
+ short: new Set(['d', 'x', 'n', 'q', 'i', 'e', 'X', 'v']),
378
+ shortValue: new Set(['e']),
379
+ },
380
+ reset: {
381
+ long: new Set([
382
+ '--quiet',
383
+ '--no-refresh',
384
+ '--refresh',
385
+ '--mixed',
386
+ '--soft',
387
+ '--merge',
388
+ '--keep',
389
+ '--pathspec-file-nul',
390
+ '--patch',
391
+ ]),
392
+ longValue: new Set(['--pathspec-from-file']),
393
+ short: new Set(['q', 'p', 'h']),
394
+ shortValue: new Set(),
395
+ },
396
+ };
397
+
398
+ /** `null` when every option token is allowlisted, otherwise the unknown reason. */
399
+ const optionVerdict = (subcommand, tokens, startIndex) => {
400
+ const spec = OPTION_SPECS[subcommand];
401
+ if (!spec) return { unknown: false };
402
+ let unknown = false;
403
+ for (let index = startIndex; index < tokens.length; index += 1) {
404
+ const value = tokens[index].value;
405
+ if (value === '--') break;
406
+ if (!value.startsWith('-')) continue;
407
+ if (value.startsWith('--')) {
408
+ const name = value.split('=')[0];
409
+ if (spec.long.has(name) || spec.longValue.has(name)) {
410
+ if (!value.includes('=') && spec.longValue.has(name)) index += 1;
411
+ continue;
412
+ }
413
+ unknown = true;
414
+ continue;
415
+ }
416
+ const letters = value.slice(1);
417
+ for (let letterIndex = 0; letterIndex < letters.length; letterIndex += 1) {
418
+ const letter = letters[letterIndex];
419
+ if (!spec.short.has(letter)) {
420
+ unknown = true;
421
+ break;
422
+ }
423
+ if (spec.shortValue.has(letter)) {
424
+ if (letterIndex === letters.length - 1) index += 1;
425
+ break;
426
+ }
427
+ if (spec.shortOptionalValue?.has(letter)) {
428
+ if (letterIndex < letters.length - 1) break;
429
+ continue;
430
+ }
431
+ }
432
+ }
433
+ return { unknown };
434
+ };
435
+
436
+ /**
437
+ * `clean` needs its own decoded parse: `e` takes a value, so `-en` is the
438
+ * exclude pattern `n` (no dry-run), while `-ne foo` is `-n -e foo`. Only an
439
+ * explicit dry-run flag may allow; everything else asks.
440
+ */
441
+ const parseCleanOptions = (tokens, startIndex) => {
442
+ const spec = OPTION_SPECS.clean;
443
+ let unknown = false;
444
+ let dryRun = false;
445
+ for (let index = startIndex; index < tokens.length; index += 1) {
446
+ const value = tokens[index].value;
447
+ if (value === '--') break;
448
+ if (!value.startsWith('-')) continue;
449
+ if (value.startsWith('--')) {
450
+ if (value === '--dry-run') {
451
+ dryRun = true;
452
+ continue;
453
+ }
454
+ if (value === '--exclude') {
455
+ index += 1;
456
+ continue;
457
+ }
458
+ if (value.startsWith('--exclude=')) continue;
459
+ const name = value.split('=')[0];
460
+ if (spec.long.has(name)) continue;
461
+ unknown = true;
462
+ continue;
463
+ }
464
+ const letters = value.slice(1);
465
+ for (let letterIndex = 0; letterIndex < letters.length; letterIndex += 1) {
466
+ const letter = letters[letterIndex];
467
+ if (!spec.short.has(letter)) {
468
+ unknown = true;
469
+ break;
470
+ }
471
+ if (letter === 'e') {
472
+ if (letterIndex === letters.length - 1) index += 1;
473
+ break;
474
+ }
475
+ if (letter === 'n') dryRun = true;
476
+ }
477
+ }
478
+ return { unknown, dryRun };
479
+ };
480
+
481
+ const isDestructiveRefspec = (value) =>
482
+ /^\+/.test(value) || /^:/.test(value) || /^[^\s:]+:$/.test(value);
483
+
484
+ /**
485
+ * Classify one shell segment from its tokens. `write` is true when the segment
486
+ * may commit or push; `destructive`, `unresolved`, `alias`, `destructiveState`
487
+ * and `unknownOption` are the fail-closed reasons. The `-m` / `--message` value
488
+ * is not scanned as a command, so a quoted commit message stays inert.
489
+ */
490
+ const classifyGitSegment = (segment) => {
491
+ const { tokens, unterminated } = tokenizeSegment(segment.trim());
492
+ const gitIndex = tokens.findIndex(
493
+ (token) => token.value === 'git' || token.value.endsWith('/git'),
494
+ );
495
+ if (gitIndex < 0) {
496
+ return {
497
+ write: false,
498
+ destructive: false,
499
+ unresolved: false,
500
+ alias: false,
501
+ destructiveState: false,
502
+ unknownOption: false,
503
+ };
504
+ }
505
+
506
+ let subcommand = null;
507
+ let subcommandIndex = -1;
508
+ for (let index = gitIndex + 1; index < tokens.length; index += 1) {
509
+ const value = tokens[index].value;
510
+ if (GIT_VALUE_GLOBALS.has(value)) {
511
+ index += 1;
512
+ continue;
513
+ }
514
+ if (value.startsWith('-')) continue;
515
+ subcommand = value;
516
+ subcommandIndex = index;
517
+ break;
518
+ }
519
+
520
+ const known = subcommand === 'commit' || subcommand === 'push';
521
+ const valueIndexes = new Set();
522
+ if (subcommand === 'commit') {
523
+ for (let index = 0; index < tokens.length; index += 1) {
524
+ const value = tokens[index].value;
525
+ if (
526
+ value === '-m' ||
527
+ value === '--message' ||
528
+ (/^-[^-]+$/.test(value) && value.endsWith('m'))
529
+ ) {
530
+ valueIndexes.add(index + 1);
531
+ }
532
+ }
533
+ }
534
+ const alias = tokens.some(
535
+ (token, index) => !valueIndexes.has(index) && /^alias\.[A-Za-z0-9_-]+=/.test(token.value),
536
+ );
537
+ const writeToken = tokens.some(
538
+ (token, index) =>
539
+ index !== subcommandIndex &&
540
+ !valueIndexes.has(index) &&
541
+ (token.value === 'push' || token.value === 'commit'),
542
+ );
543
+ const write = known || alias || writeToken || unterminated;
544
+ const destructiveRefspec =
545
+ subcommand === 'push' &&
546
+ tokens.some((token, index) => {
547
+ if (index <= subcommandIndex) return false;
548
+ if (token.value.startsWith('-')) return false;
549
+ return isDestructiveRefspec(token.value);
550
+ });
551
+ const destructiveState =
552
+ subcommand === 'checkout' && tokens.some((token) => token.value === '--');
553
+ const cleanCheck =
554
+ subcommand === 'clean' ? parseCleanOptions(tokens, subcommandIndex + 1) : null;
555
+ const optionCheck = cleanCheck ?? optionVerdict(subcommand, tokens, subcommandIndex + 1);
556
+ return {
557
+ write,
558
+ destructive: write && destructiveRefspec,
559
+ unresolved: write && (!known || unterminated),
560
+ alias,
561
+ destructiveState,
562
+ unknownOption: optionCheck.unknown,
563
+ cleanAsk: subcommand === 'clean' && !cleanCheck.dryRun,
564
+ };
565
+ };
566
+
567
+ const MAX_SCAN_DEPTH = 3;
568
+
569
+ const mergeResults = (left, right) => ({
570
+ verdict: Math.max(left.verdict, right.verdict),
571
+ destructive: left.destructive || right.destructive,
572
+ });
573
+
574
+ const directSegmentResult = (segment) => {
575
+ const classified = classifyGitSegment(segment);
576
+ if (classified.destructiveState) return { verdict: 2, destructive: true };
577
+ if (classified.unknownOption || classified.cleanAsk) {
578
+ return { verdict: 2, destructive: false };
579
+ }
580
+ if (!classified.write) return { verdict: 0, destructive: false };
581
+ if (classified.destructive) return { verdict: 2, destructive: true };
582
+ if (classified.unresolved || classified.alias) return { verdict: 2, destructive: false };
583
+ return { verdict: 1, destructive: false };
584
+ };
585
+
586
+ /** Every quoted span with its content and the index of its opening quote. */
587
+ const extractQuotedSpans = (segment) => {
588
+ const spans = [];
589
+ let quote = null;
590
+ let start = -1;
591
+ let content = '';
592
+ for (let index = 0; index < segment.length; index += 1) {
593
+ const char = segment[index];
594
+ if (quote !== null) {
595
+ if (char === '\\' && quote === '"' && index + 1 < segment.length) {
596
+ index += 1;
597
+ content += segment[index];
598
+ continue;
599
+ }
600
+ if (char === quote) {
601
+ spans.push({ content, index: start });
602
+ quote = null;
603
+ content = '';
604
+ start = -1;
605
+ continue;
606
+ }
607
+ content += char;
608
+ continue;
609
+ }
610
+ if (char === "'" || char === '"') {
611
+ quote = char;
612
+ start = index;
613
+ }
614
+ }
615
+ return { spans, unterminated: quote !== null };
616
+ };
617
+
618
+ const isEvalPayload = (segment, quoteIndex) => {
619
+ const before = segment.slice(0, quoteIndex).trim();
620
+ return /\beval(?:\s+--)?\s*$/.test(before);
621
+ };
622
+
623
+ const SHELL_TOKEN = /(?:^|\/)(?:sh|bash|zsh|dash|ksh)$/;
624
+
625
+ const isShellCPayload = (segment, quoteIndex) => {
626
+ const before = segment.slice(0, quoteIndex).trim();
627
+ const tokens = before.split(/\s+/).filter(Boolean);
628
+ let shellIndex = -1;
629
+ for (let index = tokens.length - 1; index >= 0; index -= 1) {
630
+ if (SHELL_TOKEN.test(tokens[index])) {
631
+ shellIndex = index;
632
+ break;
633
+ }
634
+ }
635
+ if (shellIndex < 0) return false;
636
+ return tokens
637
+ .slice(shellIndex + 1)
638
+ .some((token) => token === '-c' || /^-[^-]*c/.test(token));
639
+ };
640
+
641
+ const nestedShellResult = (content, depth) => {
642
+ if (depth >= MAX_SCAN_DEPTH) return { verdict: 2, destructive: false };
643
+ const nested = scanGitCommand(content, depth + 1);
644
+ if (nested.verdict === 0) return { verdict: 0, destructive: false };
645
+ return { verdict: 2, destructive: nested.destructive };
646
+ };
647
+
648
+ const quotedSegmentResult = (segment, depth) => {
649
+ const { spans, unterminated } = extractQuotedSpans(segment);
650
+ if (unterminated) return { verdict: 2, destructive: false };
651
+ let result = { verdict: 0, destructive: false };
652
+ for (const span of spans) {
653
+ const trigger =
654
+ /\bgit\b/.test(span.content) ||
655
+ isEvalPayload(segment, span.index) ||
656
+ isShellCPayload(segment, span.index);
657
+ if (!trigger) continue;
658
+ result = mergeResults(result, nestedShellResult(span.content, depth));
659
+ }
660
+ return result;
661
+ };
662
+
663
+ /**
664
+ * `-c` / `--config-env` values are executed by git (pager, sshCommand,
665
+ * diff.external, hooks). Scan the value after the first `=`: a git write or a
666
+ * destructive token there asks. `-C`, `--git-dir`, `--work-tree`, `--namespace`,
667
+ * `--super-prefix` and `--exec-path` are paths/namespaces and stay inert.
668
+ */
669
+ const configSegmentResult = (segment, depth) => {
670
+ const { tokens } = tokenizeSegment(segment);
671
+ let result = { verdict: 0, destructive: false };
672
+ for (let index = 0; index < tokens.length; index += 1) {
673
+ const value = tokens[index].value;
674
+ let configValue = null;
675
+ if (value === '-c' || value === '--config-env') {
676
+ configValue = tokens[index + 1]?.value ?? null;
677
+ index += 1;
678
+ } else if (value.startsWith('--config-env=')) {
679
+ configValue = value.slice('--config-env='.length);
680
+ } else if (value.startsWith('-c') && value.length > 2) {
681
+ configValue = value.slice(2);
682
+ }
683
+ if (configValue === null) continue;
684
+ const separator = configValue.indexOf('=');
685
+ if (separator < 0) continue;
686
+ let payload = configValue.slice(separator + 1);
687
+ // Git strips a leading `!` (and whitespace around it) from an executed
688
+ // config value and shell-runs the rest; classify that remainder as a
689
+ // command. `!gh …` has no git write and stays inert.
690
+ payload = payload.replace(/^[\s!]+/, '');
691
+ if (!payload.trim()) continue;
692
+ result = mergeResults(result, nestedShellResult(payload, depth));
693
+ }
694
+ return result;
695
+ };
696
+
697
+ /** A quoted payload on the left of `| sh` / `| bash` is executed too. */
698
+ const pipeQuotedResult = (command, depth) => {
699
+ const text = String(command).replace(/\\\r?\n/g, '');
700
+ const pattern = /("(?:[^"\\]|\\.)*"|'[^']*')\s*\|\s*(?:sh|bash|zsh|dash|ksh)\b/g;
701
+ let result = { verdict: 0, destructive: false };
702
+ for (const match of text.matchAll(pattern)) {
703
+ const content = match[1].slice(1, -1);
704
+ if (!content.trim()) continue;
705
+ result = mergeResults(result, nestedShellResult(content, depth));
706
+ }
707
+ return result;
708
+ };
709
+
710
+ /**
711
+ * Recursive unwrap: every quoted span that can execute a git write is rescanned
712
+ * (depth ≤ 3) and any nested write is asked. The strictest verdict wins.
713
+ */
714
+ const scanGitCommand = (command, depth = 0) => {
715
+ if (depth > MAX_SCAN_DEPTH) return { verdict: 2, destructive: false };
716
+ let result = { verdict: 0, destructive: false };
717
+ for (const segment of splitShellSegments(command)) {
718
+ result = mergeResults(result, directSegmentResult(segment));
719
+ result = mergeResults(result, quotedSegmentResult(segment, depth));
720
+ result = mergeResults(result, configSegmentResult(segment, depth));
721
+ }
722
+ return mergeResults(result, pipeQuotedResult(command, depth));
723
+ };
724
+
33
725
  /**
34
726
  * The decision for one shell event: `{ permission, user_message, agent_message }`.
35
727
  *
36
728
  * Shared by the CLI below and any host that can import the rendered file, so
37
- * the verdict cannot drift between them. Two effects are injected — a project
38
- * file read and a TCP probe — because a plugin has no stdin to read and no
39
- * guaranteed working directory. Never throws: an unreadable event is an allow,
40
- * the same fail-open the hook always had.
729
+ * the verdict cannot drift between them. Three effects are injected — a project
730
+ * file read, a TCP probe and the settings resolver — because a plugin has no
731
+ * stdin to read and no guaranteed working directory. Never throws: an
732
+ * unreadable event is an allow, the same fail-open the hook always had.
41
733
  */
42
734
  export const evaluate = async (event, options = {}) => {
43
735
  const {
@@ -45,6 +737,7 @@ export const evaluate = async (event, options = {}) => {
45
737
  exists = (file) => fs.existsSync(file),
46
738
  readText = (file) => fs.readFileSync(file, 'utf8'),
47
739
  canConnect = portIsOpen,
740
+ settings = importSettings,
48
741
  } = options;
49
742
  const at = (file) => path.join(root, file);
50
743
  if (!event || typeof event !== 'object') return allowed();
@@ -52,11 +745,42 @@ export const evaluate = async (event, options = {}) => {
52
745
  const command = String(event.command || event.input?.command || event.tool_input?.command || '');
53
746
  if (!command.trim()) return allowed();
54
747
 
55
- const dangerousGit = /\bgit\s+(reset\s+--hard|clean\s+-[^\n]*f|push\s+--force|push\s+-f|checkout\s+--\s+)/;
56
- if (dangerousGit.test(command)) {
748
+ // Recursively unwrap quoted inner shells before deciding: a quoted span that
749
+ // contains `git` (or is an `eval` / shell `-c` / pipe-to-shell payload) is
750
+ // rescanned at depth + 1, and any nested write asks. The strictest verdict
751
+ // across all segments and levels wins; the flag may only lift a positively
752
+ // recognised plain `commit`/`push`.
753
+ const gitScan = scanGitCommand(command, 0);
754
+ if (gitScan.verdict > 0) {
755
+ // An autonomous `/task-evil` run writes this marker before its first action;
756
+ // no human is attached, so the flag's `allow` must not reach it.
757
+ if (exists(at('.ai.local/team/.task-evil'))) {
758
+ return ask(
759
+ 'An autonomous /task-evil run cannot commit or push. Remove .ai.local/team/.task-evil only after the run ends.',
760
+ 'Do not commit or push in an autonomous run. Return a Human commits block; a human removes the marker and commits.',
761
+ );
762
+ }
763
+ if (gitScan.verdict === 2) {
764
+ return ask(
765
+ gitScan.destructive
766
+ ? 'This command looks destructive for git state. Review it before continuing.'
767
+ : 'This command wraps a git write in a quoted or indirect shell; confirm before running it.',
768
+ gitScan.destructive
769
+ ? 'A project hook flagged a destructive git command. Ask the user before running it.'
770
+ : 'A quoted or indirect shell command contains a git write. Ask the user before running it.',
771
+ );
772
+ }
773
+ let gitWritesAllowed = false;
774
+ try {
775
+ const getSetting = await settings({ root, exists, readText });
776
+ gitWritesAllowed = typeof getSetting === 'function' && getSetting('AI_RULES_ALLOW_GIT_WRITES') === true;
777
+ } catch {
778
+ gitWritesAllowed = false;
779
+ }
780
+ if (gitWritesAllowed) return allowed();
57
781
  return ask(
58
- 'This command looks destructive for git state. Review it before continuing.',
59
- 'A project hook flagged a destructive git command. Ask the user before running it.',
782
+ 'Commits and pushes are gated. Set AI_RULES_ALLOW_GIT_WRITES=true in .ai.local/.env to allow them.',
783
+ 'Do not commit or push while AI_RULES_ALLOW_GIT_WRITES is not true. Return a Human commits block instead.',
60
784
  );
61
785
  }
62
786