@bonesofspring/ai-rules 0.2.57 → 0.2.60

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 (289) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +41 -3
  3. package/bin/cli.js +399 -27
  4. package/bin/lib/engine-scripts.js +3 -0
  5. package/bin/lib/mcp/catalog.js +97 -0
  6. package/bin/lib/mcp/clients.js +35 -2
  7. package/bin/lib/mcp/credentials.js +85 -1
  8. package/bin/lib/mcp/doctor.js +93 -17
  9. package/bin/lib/mcp/registry.js +10 -4
  10. package/bin/lib/seed-ai-local-team.js +8 -5
  11. package/docs/MCP-CATALOG.md +56 -0
  12. package/docs/MCP-SETUP.md +38 -6
  13. package/docs/PRESET-CONTRIBUTION.md +1 -0
  14. package/mcp/github-proxy.mjs +133 -0
  15. package/mcp/lib/github.mjs +187 -0
  16. package/mcp/lib/streamable-http.mjs +185 -0
  17. package/mcp/lib/yandex.mjs +16 -137
  18. package/package.json +3 -1
  19. package/presets/_shared/ai-local/scripts/check-write-scope.mjs +212 -0
  20. package/presets/_shared/ai-local/scripts/rule-improver.mjs +343 -50
  21. package/presets/_shared/ai-local/scripts/run.mjs +122 -3
  22. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +12 -0
  23. package/presets/_shared/core/review/code-review-mr.md +10 -0
  24. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +143 -1
  25. package/presets/claude/android-kotlin/commands/update.md +1 -0
  26. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +143 -1
  27. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  28. package/presets/claude/android-kotlin/rules/tooling-and-review/code-review.md +10 -0
  29. package/presets/claude/go/commands/update.md +1 -0
  30. package/presets/claude/go/hooks/chain-team-phases.sh +143 -1
  31. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  32. package/presets/claude/go/rules/tooling-and-review/code-review.md +10 -0
  33. package/presets/claude/ios-swift/commands/update.md +1 -0
  34. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +143 -1
  35. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  36. package/presets/claude/ios-swift/rules/tooling-and-review/code-review.md +10 -0
  37. package/presets/claude/java/commands/update.md +1 -0
  38. package/presets/claude/java/hooks/chain-team-phases.sh +143 -1
  39. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  40. package/presets/claude/java/rules/tooling-and-review/code-review.md +10 -0
  41. package/presets/claude/mcp-ts/commands/update.md +1 -0
  42. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +143 -1
  43. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  44. package/presets/claude/mcp-ts/rules/tooling-and-review/code-review.md +10 -0
  45. package/presets/claude/mol/commands/update.md +1 -0
  46. package/presets/claude/mol/hooks/chain-team-phases.sh +143 -1
  47. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  48. package/presets/claude/mol/rules/tooling-and-review/code-review-mr.md +10 -0
  49. package/presets/claude/next/agents/build-verifier.md +2 -0
  50. package/presets/claude/next/agents/code-reviewer.md +8 -0
  51. package/presets/claude/next/commands/task-continue.md +3 -1
  52. package/presets/claude/next/commands/update.md +1 -0
  53. package/presets/claude/next/hooks/chain-team-phases.sh +143 -1
  54. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  55. package/presets/claude/next/rules/tooling-and-review/code-review-mr.md +10 -0
  56. package/presets/claude/nuxt/commands/update.md +1 -0
  57. package/presets/claude/nuxt/hooks/chain-team-phases.sh +143 -1
  58. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  59. package/presets/claude/nuxt/rules/tooling-and-review/code-review-mr.md +10 -0
  60. package/presets/claude/php-hexagonal/commands/update.md +1 -0
  61. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  62. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  63. package/presets/claude/php-hexagonal/rules/tooling-and-review/code-review.md +10 -0
  64. package/presets/claude/php-laravel/commands/update.md +1 -0
  65. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +143 -1
  66. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  67. package/presets/claude/php-laravel/rules/tooling-and-review/code-review.md +10 -0
  68. package/presets/claude/svelte/commands/update.md +1 -0
  69. package/presets/claude/svelte/hooks/chain-team-phases.sh +143 -1
  70. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +12 -0
  71. package/presets/claude/svelte/rules/tooling-and-review/code-review-mr.md +10 -0
  72. package/presets/cursor/android-kotlin/commands/update.md +1 -0
  73. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +143 -1
  74. package/presets/cursor/android-kotlin/rules/code-review-mr.mdc +10 -0
  75. package/presets/cursor/go/commands/update.md +1 -0
  76. package/presets/cursor/go/hooks/chain-team-phases.sh +143 -1
  77. package/presets/cursor/go/rules/code-review-mr.mdc +10 -0
  78. package/presets/cursor/ios-swift/commands/update.md +1 -0
  79. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +143 -1
  80. package/presets/cursor/ios-swift/rules/code-review-mr.mdc +10 -0
  81. package/presets/cursor/java/commands/update.md +1 -0
  82. package/presets/cursor/java/hooks/chain-team-phases.sh +143 -1
  83. package/presets/cursor/java/rules/code-review-mr.mdc +10 -0
  84. package/presets/cursor/mcp-ts/commands/update.md +1 -0
  85. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +143 -1
  86. package/presets/cursor/mcp-ts/rules/code-review-mr.mdc +10 -0
  87. package/presets/cursor/mol/MCP.md +4 -3
  88. package/presets/cursor/mol/commands/update.md +1 -0
  89. package/presets/cursor/mol/hooks/chain-team-phases.sh +143 -1
  90. package/presets/cursor/mol/rules/code-review-mr.mdc +10 -0
  91. package/presets/cursor/next/MCP.md +4 -3
  92. package/presets/cursor/next/agents/build-verifier.md +2 -0
  93. package/presets/cursor/next/agents/code-reviewer.md +8 -0
  94. package/presets/cursor/next/commands/task-continue.md +3 -1
  95. package/presets/cursor/next/commands/update.md +1 -0
  96. package/presets/cursor/next/hooks/chain-team-phases.sh +143 -1
  97. package/presets/cursor/next/rules/code-review-mr.mdc +10 -0
  98. package/presets/cursor/nuxt/commands/update.md +1 -0
  99. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +143 -1
  100. package/presets/cursor/nuxt/rules/code-review-mr.mdc +10 -0
  101. package/presets/cursor/php-hexagonal/commands/update.md +1 -0
  102. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  103. package/presets/cursor/php-hexagonal/rules/code-review-mr.mdc +10 -0
  104. package/presets/cursor/php-laravel/commands/update.md +1 -0
  105. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +143 -1
  106. package/presets/cursor/php-laravel/rules/code-review-mr.mdc +10 -0
  107. package/presets/cursor/svelte/commands/update.md +1 -0
  108. package/presets/cursor/svelte/hooks/chain-team-phases.sh +143 -1
  109. package/presets/cursor/svelte/rules/code-review-mr.mdc +10 -0
  110. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  111. package/presets/mavis/android-kotlin/commands/update.md +1 -0
  112. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +143 -1
  113. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  114. package/presets/mavis/android-kotlin/rules/code-review-mr.md +10 -0
  115. package/presets/mavis/go/adapter-map.json +1 -1
  116. package/presets/mavis/go/commands/update.md +1 -0
  117. package/presets/mavis/go/hooks/chain-team-phases.sh +143 -1
  118. package/presets/mavis/go/rules/agent-team-orchestrator.md +12 -0
  119. package/presets/mavis/go/rules/code-review-mr.md +10 -0
  120. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  121. package/presets/mavis/ios-swift/commands/update.md +1 -0
  122. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +143 -1
  123. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +12 -0
  124. package/presets/mavis/ios-swift/rules/code-review-mr.md +10 -0
  125. package/presets/mavis/java/adapter-map.json +1 -1
  126. package/presets/mavis/java/commands/update.md +1 -0
  127. package/presets/mavis/java/hooks/chain-team-phases.sh +143 -1
  128. package/presets/mavis/java/rules/agent-team-orchestrator.md +12 -0
  129. package/presets/mavis/java/rules/code-review-mr.md +10 -0
  130. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  131. package/presets/mavis/mcp-ts/commands/update.md +1 -0
  132. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +143 -1
  133. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  134. package/presets/mavis/mcp-ts/rules/code-review-mr.md +10 -0
  135. package/presets/mavis/mol/MCP.md +4 -3
  136. package/presets/mavis/mol/adapter-map.json +1 -1
  137. package/presets/mavis/mol/commands/update.md +1 -0
  138. package/presets/mavis/mol/hooks/chain-team-phases.sh +143 -1
  139. package/presets/mavis/mol/rules/agent-team-orchestrator.md +12 -0
  140. package/presets/mavis/mol/rules/code-review-mr.md +10 -0
  141. package/presets/mavis/next/MCP.md +4 -3
  142. package/presets/mavis/next/adapter-map.json +1 -1
  143. package/presets/mavis/next/agents/build-verifier.md +2 -0
  144. package/presets/mavis/next/agents/code-reviewer.md +8 -0
  145. package/presets/mavis/next/commands/task-continue.md +3 -1
  146. package/presets/mavis/next/commands/update.md +1 -0
  147. package/presets/mavis/next/hooks/chain-team-phases.sh +143 -1
  148. package/presets/mavis/next/rules/agent-team-orchestrator.md +12 -0
  149. package/presets/mavis/next/rules/code-review-mr.md +10 -0
  150. package/presets/mavis/nuxt/adapter-map.json +1 -1
  151. package/presets/mavis/nuxt/commands/update.md +1 -0
  152. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +143 -1
  153. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +12 -0
  154. package/presets/mavis/nuxt/rules/code-review-mr.md +10 -0
  155. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  156. package/presets/mavis/php-hexagonal/commands/update.md +1 -0
  157. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  158. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  159. package/presets/mavis/php-hexagonal/rules/code-review-mr.md +10 -0
  160. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  161. package/presets/mavis/php-laravel/commands/update.md +1 -0
  162. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +143 -1
  163. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +12 -0
  164. package/presets/mavis/php-laravel/rules/code-review-mr.md +10 -0
  165. package/presets/mavis/svelte/adapter-map.json +1 -1
  166. package/presets/mavis/svelte/commands/update.md +1 -0
  167. package/presets/mavis/svelte/hooks/chain-team-phases.sh +143 -1
  168. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +12 -0
  169. package/presets/mavis/svelte/rules/code-review-mr.md +10 -0
  170. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  171. package/presets/opencode/android-kotlin/commands/update.md +1 -0
  172. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +143 -1
  173. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  174. package/presets/opencode/android-kotlin/rules/code-review-mr.md +10 -0
  175. package/presets/opencode/go/adapter-map.json +1 -1
  176. package/presets/opencode/go/commands/update.md +1 -0
  177. package/presets/opencode/go/hooks/chain-team-phases.sh +143 -1
  178. package/presets/opencode/go/rules/agent-team-orchestrator.md +12 -0
  179. package/presets/opencode/go/rules/code-review-mr.md +10 -0
  180. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  181. package/presets/opencode/ios-swift/commands/update.md +1 -0
  182. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +143 -1
  183. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +12 -0
  184. package/presets/opencode/ios-swift/rules/code-review-mr.md +10 -0
  185. package/presets/opencode/java/adapter-map.json +1 -1
  186. package/presets/opencode/java/commands/update.md +1 -0
  187. package/presets/opencode/java/hooks/chain-team-phases.sh +143 -1
  188. package/presets/opencode/java/rules/agent-team-orchestrator.md +12 -0
  189. package/presets/opencode/java/rules/code-review-mr.md +10 -0
  190. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  191. package/presets/opencode/mcp-ts/commands/update.md +1 -0
  192. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +143 -1
  193. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  194. package/presets/opencode/mcp-ts/rules/code-review-mr.md +10 -0
  195. package/presets/opencode/mol/MCP.md +4 -3
  196. package/presets/opencode/mol/adapter-map.json +1 -1
  197. package/presets/opencode/mol/commands/update.md +1 -0
  198. package/presets/opencode/mol/hooks/chain-team-phases.sh +143 -1
  199. package/presets/opencode/mol/rules/agent-team-orchestrator.md +12 -0
  200. package/presets/opencode/mol/rules/code-review-mr.md +10 -0
  201. package/presets/opencode/next/MCP.md +4 -3
  202. package/presets/opencode/next/adapter-map.json +1 -1
  203. package/presets/opencode/next/agents/build-verifier.md +2 -0
  204. package/presets/opencode/next/agents/code-reviewer.md +8 -0
  205. package/presets/opencode/next/commands/task-continue.md +3 -1
  206. package/presets/opencode/next/commands/update.md +1 -0
  207. package/presets/opencode/next/hooks/chain-team-phases.sh +143 -1
  208. package/presets/opencode/next/rules/agent-team-orchestrator.md +12 -0
  209. package/presets/opencode/next/rules/code-review-mr.md +10 -0
  210. package/presets/opencode/nuxt/adapter-map.json +1 -1
  211. package/presets/opencode/nuxt/commands/update.md +1 -0
  212. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +143 -1
  213. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +12 -0
  214. package/presets/opencode/nuxt/rules/code-review-mr.md +10 -0
  215. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  216. package/presets/opencode/php-hexagonal/commands/update.md +1 -0
  217. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  218. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  219. package/presets/opencode/php-hexagonal/rules/code-review-mr.md +10 -0
  220. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  221. package/presets/opencode/php-laravel/commands/update.md +1 -0
  222. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +143 -1
  223. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +12 -0
  224. package/presets/opencode/php-laravel/rules/code-review-mr.md +10 -0
  225. package/presets/opencode/svelte/adapter-map.json +1 -1
  226. package/presets/opencode/svelte/commands/update.md +1 -0
  227. package/presets/opencode/svelte/hooks/chain-team-phases.sh +143 -1
  228. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +12 -0
  229. package/presets/opencode/svelte/rules/code-review-mr.md +10 -0
  230. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  231. package/presets/zcode/android-kotlin/commands/update.md +1 -0
  232. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +143 -1
  233. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +12 -0
  234. package/presets/zcode/android-kotlin/rules/code-review-mr.md +10 -0
  235. package/presets/zcode/go/adapter-map.json +1 -1
  236. package/presets/zcode/go/commands/update.md +1 -0
  237. package/presets/zcode/go/hooks/chain-team-phases.sh +143 -1
  238. package/presets/zcode/go/rules/agent-team-orchestrator.md +12 -0
  239. package/presets/zcode/go/rules/code-review-mr.md +10 -0
  240. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  241. package/presets/zcode/ios-swift/commands/update.md +1 -0
  242. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +143 -1
  243. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +12 -0
  244. package/presets/zcode/ios-swift/rules/code-review-mr.md +10 -0
  245. package/presets/zcode/java/adapter-map.json +1 -1
  246. package/presets/zcode/java/commands/update.md +1 -0
  247. package/presets/zcode/java/hooks/chain-team-phases.sh +143 -1
  248. package/presets/zcode/java/rules/agent-team-orchestrator.md +12 -0
  249. package/presets/zcode/java/rules/code-review-mr.md +10 -0
  250. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  251. package/presets/zcode/mcp-ts/commands/update.md +1 -0
  252. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +143 -1
  253. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +12 -0
  254. package/presets/zcode/mcp-ts/rules/code-review-mr.md +10 -0
  255. package/presets/zcode/mol/MCP.md +4 -3
  256. package/presets/zcode/mol/adapter-map.json +1 -1
  257. package/presets/zcode/mol/commands/update.md +1 -0
  258. package/presets/zcode/mol/hooks/chain-team-phases.sh +143 -1
  259. package/presets/zcode/mol/rules/agent-team-orchestrator.md +12 -0
  260. package/presets/zcode/mol/rules/code-review-mr.md +10 -0
  261. package/presets/zcode/next/MCP.md +4 -3
  262. package/presets/zcode/next/adapter-map.json +1 -1
  263. package/presets/zcode/next/agents/build-verifier.md +2 -0
  264. package/presets/zcode/next/agents/code-reviewer.md +8 -0
  265. package/presets/zcode/next/commands/task-continue.md +3 -1
  266. package/presets/zcode/next/commands/update.md +1 -0
  267. package/presets/zcode/next/hooks/chain-team-phases.sh +143 -1
  268. package/presets/zcode/next/rules/agent-team-orchestrator.md +12 -0
  269. package/presets/zcode/next/rules/code-review-mr.md +10 -0
  270. package/presets/zcode/nuxt/adapter-map.json +1 -1
  271. package/presets/zcode/nuxt/commands/update.md +1 -0
  272. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +143 -1
  273. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +12 -0
  274. package/presets/zcode/nuxt/rules/code-review-mr.md +10 -0
  275. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  276. package/presets/zcode/php-hexagonal/commands/update.md +1 -0
  277. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +143 -1
  278. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +12 -0
  279. package/presets/zcode/php-hexagonal/rules/code-review-mr.md +10 -0
  280. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  281. package/presets/zcode/php-laravel/commands/update.md +1 -0
  282. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +143 -1
  283. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +12 -0
  284. package/presets/zcode/php-laravel/rules/code-review-mr.md +10 -0
  285. package/presets/zcode/svelte/adapter-map.json +1 -1
  286. package/presets/zcode/svelte/commands/update.md +1 -0
  287. package/presets/zcode/svelte/hooks/chain-team-phases.sh +143 -1
  288. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +12 -0
  289. package/presets/zcode/svelte/rules/code-review-mr.md +10 -0
@@ -0,0 +1,212 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Post-step write-scope reconciliation (read-only).
4
+ *
5
+ * Compares the paths a step actually changed with that step's declared
6
+ * `pipeline.json` `writeScopes`, and labels every path `declared`, `derived`
7
+ * (a generated mirror, the task folder, or another declared derived output), or
8
+ * `out-of-scope`. This is the missing audit between the plan (`check-parallel-plan.sh`)
9
+ * and the diff; it never writes and never gates a hook.
10
+ *
11
+ * Usage:
12
+ * node .ai.local/scripts/check-write-scope.mjs --slug <slug> [--step <id>] [--base <ref>] [--json]
13
+ * node .ai.local/scripts/check-write-scope.mjs --slug <slug> --paths a,b [--step <id>] [--json]
14
+ * node .ai.local/scripts/check-write-scope.mjs --slug <slug> --root <project> ...
15
+ *
16
+ * `--root` is the project root (the directory holding `.ai.local/`), not
17
+ * necessarily the git top level; a nested project works because the git
18
+ * baseline is emitted relative to that root.
19
+ *
20
+ * Baseline: `--base` defaults to `HEAD`, so the default audit covers the
21
+ * uncommitted change-set (tracked diff + untracked files). Pass a ref for a
22
+ * committed change-set: `--base origin/main`.
23
+ *
24
+ * Exit codes:
25
+ * 0 PASS, no changed paths, or an advisory (reviewer/verifier) step
26
+ * 1 FAIL — an implementation step changed an out-of-scope path
27
+ * 2 usage/config error (missing pipeline, unknown step, bad git ref)
28
+ *
29
+ * `--json` prints one object; the human report prints one labelled line per path.
30
+ */
31
+ import { spawnSync } from 'node:child_process';
32
+ import fs from 'node:fs';
33
+ import path from 'node:path';
34
+
35
+ const USAGE = `Usage: node .ai.local/scripts/check-write-scope.mjs --slug <slug> [--step <id>] [--base <ref>] [--root <project>] [--paths a,b] [--json]`;
36
+
37
+ const REVIEW_AGENT_RE = /reviewer|auditor|verifier/i;
38
+ const DERIVED_RULES = [
39
+ { name: 'task-folder', test: (file, slug) => file.startsWith(`.ai.local/team/tasks/${slug}/`) },
40
+ { name: 'team-state', test: (file) => file.startsWith('.ai.local/team/') },
41
+ { name: 'engine-mirror', test: (file) => file.startsWith('.ai.local/scripts/') },
42
+ { name: 'generated-platform', test: (file) => /^packages\/ai-rules\/presets\/(?:claude|mavis|opencode|zcode)\//.test(file) },
43
+ { name: 'generated-hook', test: (file) => /^packages\/ai-rules\/presets\/cursor\/[^/]+\/hooks\/chain-team-phases\.sh$/.test(file) },
44
+ { name: 'generated-golden', test: (file) => file.startsWith('packages/ai-rules/scripts/fixtures/cli-golden/') },
45
+ { name: 'dogfood-tree', test: (file) => /^\.(?:cursor|claude|mavis|opencode|zcode)\//.test(file) },
46
+ { name: 'generated-root-agents', test: (file) => file === 'AGENTS.md' },
47
+ { name: 'generated-adapter-map', test: (file) => /adapter-map\.json$/.test(file) },
48
+ ];
49
+
50
+ function fail(message) {
51
+ console.error(`check-write-scope: ${message}`);
52
+ process.exit(2);
53
+ }
54
+
55
+ function parseArgs(argv) {
56
+ const args = { _: [] };
57
+ for (let index = 0; index < argv.length; index += 1) {
58
+ const token = argv[index];
59
+ const readValue = () => {
60
+ const value = argv[index + 1];
61
+ if (value === undefined || value.startsWith('-')) fail(`${token} needs a value`);
62
+ index += 1;
63
+ return value;
64
+ };
65
+ if (token === '--slug') args.slug = readValue();
66
+ else if (token === '--step') args.step = readValue();
67
+ else if (token === '--base') args.base = readValue();
68
+ else if (token === '--root') args.root = readValue();
69
+ else if (token === '--paths') args.paths = readValue();
70
+ else if (token === '--json') args.json = true;
71
+ else if (token === '--help' || token === '-h') {
72
+ console.log(USAGE);
73
+ process.exit(0);
74
+ } else if (token.startsWith('-')) fail(`unknown option ${token}`);
75
+ else args._.push(token);
76
+ }
77
+ return args;
78
+ }
79
+
80
+ function normalizePath(value) {
81
+ let text = String(value ?? '').trim().replace(/\\/g, '/');
82
+ while (text.startsWith('./')) text = text.slice(2);
83
+ return text;
84
+ }
85
+
86
+ function inScope(file, scope) {
87
+ const target = normalizePath(file);
88
+ const normalized = normalizePath(scope);
89
+ if (!target || !normalized) return false;
90
+ if (normalized === target) return true;
91
+ if (normalized.endsWith('/**')) {
92
+ const prefix = normalized.slice(0, -3);
93
+ return target === prefix || target.startsWith(`${prefix}/`);
94
+ }
95
+ if (normalized.endsWith('/*')) {
96
+ const prefix = normalized.slice(0, -2);
97
+ const rest = target.startsWith(`${prefix}/`) ? target.slice(prefix.length + 1) : '';
98
+ return Boolean(rest) && !rest.includes('/');
99
+ }
100
+ return false;
101
+ }
102
+
103
+ function agentsOf(step) {
104
+ if (!step) return [];
105
+ return Array.isArray(step.agent) ? step.agent.filter((agent) => typeof agent === 'string') : [step.agent];
106
+ }
107
+
108
+ function chooseStep(pipeline, requested) {
109
+ const steps = Array.isArray(pipeline.steps) ? pipeline.steps : [];
110
+ if (requested) {
111
+ const step = steps.find((item) => item && item.id === requested);
112
+ if (!step) fail(`unknown step "${requested}" (available: ${steps.map((item) => item?.id ?? '(no id)').join(', ') || 'none'})`);
113
+ return step;
114
+ }
115
+ const implementation = steps.find((item) => Array.isArray(item?.writeScopes)
116
+ && item.writeScopes.length > 0
117
+ && agentsOf(item).some((agent) => /feature-developer|debugger|ci-investigator/i.test(agent)));
118
+ if (implementation) return implementation;
119
+ const scoped = steps.filter((item) => Array.isArray(item?.writeScopes) && item.writeScopes.length > 0);
120
+ if (scoped.length === 1) return scoped[0];
121
+ fail('cannot choose a step; pass --step <id>');
122
+ return null;
123
+ }
124
+
125
+ function gitChangedPaths(root, base) {
126
+ // `--relative` emits the diff against `root` (the project root), matching the
127
+ // cwd-relative `ls-files` output below even when `root` is not the git root.
128
+ const diff = spawnSync('git', ['-C', root, 'diff', '--relative', '--name-only', base, '--', '.'], { encoding: 'utf8' });
129
+ if (diff.status !== 0) {
130
+ fail(`git diff ${base} failed: ${(diff.stderr || '').trim() || `exit ${diff.status}`}`);
131
+ }
132
+ const untracked = spawnSync('git', ['-C', root, 'ls-files', '--others', '--exclude-standard'], { encoding: 'utf8' });
133
+ if (untracked.status !== 0) {
134
+ fail(`git ls-files failed: ${(untracked.stderr || '').trim() || `exit ${untracked.status}`}`);
135
+ }
136
+ return [...String(diff.stdout || '').split('\n'), ...String(untracked.stdout || '').split('\n')]
137
+ .map(normalizePath)
138
+ .filter(Boolean);
139
+ }
140
+
141
+ function classify(changed, writeScopes, slug) {
142
+ return changed.map((file) => {
143
+ const derived = DERIVED_RULES.find((rule) => rule.test(file, slug));
144
+ if (derived) return { path: file, classification: 'derived', source: `derived: ${derived.name}` };
145
+ const scope = writeScopes.find((candidate) => inScope(file, candidate));
146
+ if (scope) return { path: file, classification: 'declared', source: `writeScopes: ${scope}` };
147
+ return { path: file, classification: 'out-of-scope', source: 'not in step writeScopes' };
148
+ });
149
+ }
150
+
151
+ function renderReport({ slug, step, base, verdict, rows }) {
152
+ const counts = {
153
+ declared: rows.filter((row) => row.classification === 'declared').length,
154
+ derived: rows.filter((row) => row.classification === 'derived').length,
155
+ outOfScope: rows.filter((row) => row.classification === 'out-of-scope').length,
156
+ };
157
+ const lines = [
158
+ `Write-scope reconciliation — slug ${slug}, step ${step.id ?? '(no id)'} (${agentsOf(step).join(', ')})`,
159
+ `base: ${base}${base === 'HEAD' ? ' (uncommitted change-set)' : ''}`,
160
+ `paths: ${rows.length} — declared ${counts.declared}, derived ${counts.derived}, out-of-scope ${counts.outOfScope}`,
161
+ ];
162
+ for (const row of rows) {
163
+ lines.push(` ${row.classification.padEnd(12)} ${row.path} — ${row.source}`);
164
+ }
165
+ lines.push(`verdict: ${verdict.toUpperCase()}`);
166
+ return { counts, text: `${lines.join('\n')}\n` };
167
+ }
168
+
169
+ function main() {
170
+ const args = parseArgs(process.argv.slice(2));
171
+ if (!args.slug) fail('--slug <slug> is required');
172
+ if (args._.length > 0) fail(`unexpected positional argument "${args._[0]}"`);
173
+ const root = path.resolve(args.root ?? process.cwd());
174
+ const pipelinePath = path.join(root, '.ai.local', 'team', 'tasks', args.slug, 'pipeline.json');
175
+ if (!fs.existsSync(pipelinePath)) fail(`no pipeline.json at ${path.relative(root, pipelinePath)}`);
176
+ let pipeline;
177
+ try {
178
+ pipeline = JSON.parse(fs.readFileSync(pipelinePath, 'utf8'));
179
+ } catch (error) {
180
+ fail(`pipeline.json is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
181
+ }
182
+ const step = chooseStep(pipeline, args.step);
183
+ const writeScopes = Array.isArray(step.writeScopes) ? step.writeScopes.filter((scope) => typeof scope === 'string' && scope) : [];
184
+ if (writeScopes.length === 0) fail(`step ${step.id ?? '(no id)'} declares no writeScopes`);
185
+
186
+ const base = args.base ?? 'HEAD';
187
+ const changed = args.paths !== undefined
188
+ ? String(args.paths).split(',').map(normalizePath).filter(Boolean)
189
+ : gitChangedPaths(root, base);
190
+ const rows = classify(changed, writeScopes, args.slug);
191
+ const outOfScope = rows.filter((row) => row.classification === 'out-of-scope');
192
+ const advisory = agentsOf(step).some((agent) => REVIEW_AGENT_RE.test(agent));
193
+ const verdict = outOfScope.length === 0 ? 'pass' : advisory ? 'advisory' : 'fail';
194
+ const { counts, text } = renderReport({ slug: args.slug, step, base, verdict, rows });
195
+
196
+ if (args.json) {
197
+ console.log(JSON.stringify({
198
+ schemaVersion: 1,
199
+ slug: args.slug,
200
+ step: { id: step.id ?? null, agent: step.agent ?? null, writeScopes },
201
+ base,
202
+ verdict,
203
+ counts,
204
+ paths: rows,
205
+ }, null, 2));
206
+ } else {
207
+ process.stdout.write(text);
208
+ }
209
+ process.exit(verdict === 'fail' ? 1 : 0);
210
+ }
211
+
212
+ main();