@bonesofspring/ai-rules 0.2.86 → 0.2.87

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 (425) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/bin/lib/engine-scripts.js +4 -0
  3. package/bin/lib/seed-ai-local-team.js +39 -2
  4. package/bin/opencode-install.js +3 -2
  5. package/docs/OPENCODE-COMPATIBILITY.md +6 -4
  6. package/docs/OPENCODE.md +8 -5
  7. package/docs/PRESET-CONTRIBUTION.md +6 -6
  8. package/docs/TOKEN-ECONOMY.md +20 -0
  9. package/package.json +1 -1
  10. package/presets/_shared/ai-local/scripts/report-step-cost.mjs +544 -0
  11. package/presets/_shared/assets/model-tiers.json +6 -0
  12. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +3 -3
  13. package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +125 -105
  14. package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +125 -105
  15. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  16. package/presets/claude/go/hooks/guard-shell-command.mjs +125 -105
  17. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  18. package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +125 -105
  19. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  20. package/presets/claude/java/hooks/guard-shell-command.mjs +125 -105
  21. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  22. package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +125 -105
  23. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  24. package/presets/claude/mol/hooks/guard-shell-command.mjs +125 -105
  25. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  26. package/presets/claude/next/hooks/guard-shell-command.mjs +125 -105
  27. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  28. package/presets/claude/nuxt/hooks/guard-shell-command.mjs +125 -105
  29. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  30. package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +125 -105
  31. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  32. package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +125 -105
  33. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  34. package/presets/claude/svelte/hooks/guard-shell-command.mjs +125 -105
  35. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  36. package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +125 -105
  37. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +3 -3
  38. package/presets/cursor/go/hooks/guard-shell-command.mjs +125 -105
  39. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +3 -3
  40. package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +125 -105
  41. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +3 -3
  42. package/presets/cursor/java/hooks/guard-shell-command.mjs +125 -105
  43. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +3 -3
  44. package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +125 -105
  45. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +3 -3
  46. package/presets/cursor/mol/hooks/guard-shell-command.mjs +125 -105
  47. package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +3 -3
  48. package/presets/cursor/next/hooks/guard-shell-command.mjs +125 -105
  49. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +3 -3
  50. package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +125 -105
  51. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +3 -3
  52. package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +125 -105
  53. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +3 -3
  54. package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +125 -105
  55. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +3 -3
  56. package/presets/cursor/svelte/hooks/guard-shell-command.mjs +125 -105
  57. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +3 -3
  58. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  59. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +3 -3
  60. package/presets/mavis/go/adapter-map.json +1 -1
  61. package/presets/mavis/go/rules/agent-team-orchestrator.md +3 -3
  62. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  63. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +3 -3
  64. package/presets/mavis/java/adapter-map.json +1 -1
  65. package/presets/mavis/java/rules/agent-team-orchestrator.md +3 -3
  66. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  67. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +3 -3
  68. package/presets/mavis/mol/adapter-map.json +1 -1
  69. package/presets/mavis/mol/rules/agent-team-orchestrator.md +3 -3
  70. package/presets/mavis/next/adapter-map.json +1 -1
  71. package/presets/mavis/next/rules/agent-team-orchestrator.md +3 -3
  72. package/presets/mavis/nuxt/adapter-map.json +1 -1
  73. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +3 -3
  74. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  75. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +3 -3
  76. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  77. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +3 -3
  78. package/presets/mavis/svelte/adapter-map.json +1 -1
  79. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +3 -3
  80. package/presets/opencode/android-kotlin/OPENCODE.md +5 -66
  81. package/presets/opencode/android-kotlin/adapter-map.json +42 -42
  82. package/presets/opencode/android-kotlin/agents/accessibility-reviewer.md +1 -1
  83. package/presets/opencode/android-kotlin/agents/api-contract-reviewer.md +1 -1
  84. package/presets/opencode/android-kotlin/agents/build-verifier.md +1 -1
  85. package/presets/opencode/android-kotlin/agents/ci-investigator.md +1 -1
  86. package/presets/opencode/android-kotlin/agents/code-reviewer.md +1 -1
  87. package/presets/opencode/android-kotlin/agents/codebase-analyzer.md +1 -1
  88. package/presets/opencode/android-kotlin/agents/debugger.md +1 -1
  89. package/presets/opencode/android-kotlin/agents/feature-developer.md +1 -1
  90. package/presets/opencode/android-kotlin/agents/instrumentation-test-generator.md +1 -1
  91. package/presets/opencode/android-kotlin/agents/instrumentation-test-healer.md +1 -1
  92. package/presets/opencode/android-kotlin/agents/instrumentation-test-planner.md +1 -1
  93. package/presets/opencode/android-kotlin/agents/migration-specialist.md +1 -1
  94. package/presets/opencode/android-kotlin/agents/mockup-reviewer.md +1 -1
  95. package/presets/opencode/android-kotlin/agents/openspec-author.md +1 -1
  96. package/presets/opencode/android-kotlin/agents/performance-auditor.md +1 -1
  97. package/presets/opencode/android-kotlin/agents/qa-tester.md +1 -1
  98. package/presets/opencode/android-kotlin/agents/security-reviewer.md +1 -1
  99. package/presets/opencode/android-kotlin/agents/solution-architect.md +1 -1
  100. package/presets/opencode/android-kotlin/agents/task-analyst.md +1 -1
  101. package/presets/opencode/android-kotlin/agents/task-router.md +1 -1
  102. package/presets/opencode/android-kotlin/agents/tech-writer.md +1 -1
  103. package/presets/opencode/android-kotlin/agents/unit-test-generator.md +1 -1
  104. package/presets/opencode/android-kotlin/agents/unit-test-healer.md +1 -1
  105. package/presets/opencode/android-kotlin/agents/unit-test-planner.md +1 -1
  106. package/presets/opencode/android-kotlin/commands/task-continue.md +1 -1
  107. package/presets/opencode/android-kotlin/hooks/README.md +11 -1
  108. package/presets/opencode/android-kotlin/hooks/guard-shell-command.mjs +155 -0
  109. package/presets/opencode/android-kotlin/plugins/rule-attach/globs.json +167 -0
  110. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +5 -5
  111. package/presets/opencode/go/OPENCODE.md +5 -51
  112. package/presets/opencode/go/adapter-map.json +45 -45
  113. package/presets/opencode/go/agents/api-contract-reviewer.md +1 -1
  114. package/presets/opencode/go/agents/build-verifier.md +1 -1
  115. package/presets/opencode/go/agents/ci-investigator.md +1 -1
  116. package/presets/opencode/go/agents/code-reviewer.md +1 -1
  117. package/presets/opencode/go/agents/codebase-analyzer.md +1 -1
  118. package/presets/opencode/go/agents/debugger.md +1 -1
  119. package/presets/opencode/go/agents/feature-developer.md +1 -1
  120. package/presets/opencode/go/agents/integration-test-generator.md +1 -1
  121. package/presets/opencode/go/agents/integration-test-healer.md +1 -1
  122. package/presets/opencode/go/agents/integration-test-planner.md +1 -1
  123. package/presets/opencode/go/agents/migration-specialist.md +1 -1
  124. package/presets/opencode/go/agents/openspec-author.md +1 -1
  125. package/presets/opencode/go/agents/performance-auditor.md +1 -1
  126. package/presets/opencode/go/agents/qa-tester.md +1 -1
  127. package/presets/opencode/go/agents/security-reviewer.md +1 -1
  128. package/presets/opencode/go/agents/solution-architect.md +1 -1
  129. package/presets/opencode/go/agents/task-analyst.md +1 -1
  130. package/presets/opencode/go/agents/task-router.md +1 -1
  131. package/presets/opencode/go/agents/tech-writer.md +1 -1
  132. package/presets/opencode/go/agents/unit-test-generator.md +1 -1
  133. package/presets/opencode/go/agents/unit-test-healer.md +1 -1
  134. package/presets/opencode/go/agents/unit-test-planner.md +1 -1
  135. package/presets/opencode/go/commands/task-continue.md +1 -1
  136. package/presets/opencode/go/hooks/README.md +11 -1
  137. package/presets/opencode/go/hooks/guard-shell-command.mjs +154 -0
  138. package/presets/opencode/go/plugins/rule-attach/globs.json +198 -0
  139. package/presets/opencode/go/rules/agent-team-orchestrator.md +5 -5
  140. package/presets/opencode/ios-swift/OPENCODE.md +5 -66
  141. package/presets/opencode/ios-swift/adapter-map.json +41 -41
  142. package/presets/opencode/ios-swift/agents/accessibility-reviewer.md +1 -1
  143. package/presets/opencode/ios-swift/agents/api-contract-reviewer.md +1 -1
  144. package/presets/opencode/ios-swift/agents/build-verifier.md +1 -1
  145. package/presets/opencode/ios-swift/agents/ci-investigator.md +1 -1
  146. package/presets/opencode/ios-swift/agents/code-reviewer.md +1 -1
  147. package/presets/opencode/ios-swift/agents/codebase-analyzer.md +1 -1
  148. package/presets/opencode/ios-swift/agents/debugger.md +1 -1
  149. package/presets/opencode/ios-swift/agents/feature-developer.md +1 -1
  150. package/presets/opencode/ios-swift/agents/migration-specialist.md +1 -1
  151. package/presets/opencode/ios-swift/agents/mockup-reviewer.md +1 -1
  152. package/presets/opencode/ios-swift/agents/openspec-author.md +1 -1
  153. package/presets/opencode/ios-swift/agents/performance-auditor.md +1 -1
  154. package/presets/opencode/ios-swift/agents/qa-tester.md +1 -1
  155. package/presets/opencode/ios-swift/agents/security-reviewer.md +1 -1
  156. package/presets/opencode/ios-swift/agents/solution-architect.md +1 -1
  157. package/presets/opencode/ios-swift/agents/task-analyst.md +1 -1
  158. package/presets/opencode/ios-swift/agents/task-router.md +1 -1
  159. package/presets/opencode/ios-swift/agents/tech-writer.md +1 -1
  160. package/presets/opencode/ios-swift/agents/unit-test-generator.md +1 -1
  161. package/presets/opencode/ios-swift/agents/unit-test-healer.md +1 -1
  162. package/presets/opencode/ios-swift/agents/unit-test-planner.md +1 -1
  163. package/presets/opencode/ios-swift/agents/xcuitest-test-generator.md +1 -1
  164. package/presets/opencode/ios-swift/agents/xcuitest-test-healer.md +1 -1
  165. package/presets/opencode/ios-swift/agents/xcuitest-test-planner.md +1 -1
  166. package/presets/opencode/ios-swift/commands/task-continue.md +1 -1
  167. package/presets/opencode/ios-swift/hooks/README.md +11 -1
  168. package/presets/opencode/ios-swift/hooks/guard-shell-command.mjs +154 -0
  169. package/presets/opencode/ios-swift/plugins/rule-attach/globs.json +160 -0
  170. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +5 -5
  171. package/presets/opencode/java/OPENCODE.md +5 -58
  172. package/presets/opencode/java/adapter-map.json +45 -45
  173. package/presets/opencode/java/agents/api-contract-reviewer.md +1 -1
  174. package/presets/opencode/java/agents/build-verifier.md +1 -1
  175. package/presets/opencode/java/agents/ci-investigator.md +1 -1
  176. package/presets/opencode/java/agents/code-reviewer.md +1 -1
  177. package/presets/opencode/java/agents/codebase-analyzer.md +1 -1
  178. package/presets/opencode/java/agents/debugger.md +1 -1
  179. package/presets/opencode/java/agents/feature-developer.md +1 -1
  180. package/presets/opencode/java/agents/integration-test-generator.md +1 -1
  181. package/presets/opencode/java/agents/integration-test-healer.md +1 -1
  182. package/presets/opencode/java/agents/integration-test-planner.md +1 -1
  183. package/presets/opencode/java/agents/migration-specialist.md +1 -1
  184. package/presets/opencode/java/agents/openspec-author.md +1 -1
  185. package/presets/opencode/java/agents/performance-auditor.md +1 -1
  186. package/presets/opencode/java/agents/qa-tester.md +1 -1
  187. package/presets/opencode/java/agents/security-reviewer.md +1 -1
  188. package/presets/opencode/java/agents/solution-architect.md +1 -1
  189. package/presets/opencode/java/agents/task-analyst.md +1 -1
  190. package/presets/opencode/java/agents/task-router.md +1 -1
  191. package/presets/opencode/java/agents/tech-writer.md +1 -1
  192. package/presets/opencode/java/agents/unit-test-generator.md +1 -1
  193. package/presets/opencode/java/agents/unit-test-healer.md +1 -1
  194. package/presets/opencode/java/agents/unit-test-planner.md +1 -1
  195. package/presets/opencode/java/commands/task-continue.md +1 -1
  196. package/presets/opencode/java/hooks/README.md +11 -1
  197. package/presets/opencode/java/hooks/guard-shell-command.mjs +155 -0
  198. package/presets/opencode/java/plugins/rule-attach/globs.json +230 -0
  199. package/presets/opencode/java/rules/agent-team-orchestrator.md +5 -5
  200. package/presets/opencode/mcp-ts/OPENCODE.md +5 -48
  201. package/presets/opencode/mcp-ts/adapter-map.json +36 -36
  202. package/presets/opencode/mcp-ts/agents/build-verifier.md +1 -1
  203. package/presets/opencode/mcp-ts/agents/feature-developer.md +1 -1
  204. package/presets/opencode/mcp-ts/agents/security-reviewer.md +1 -1
  205. package/presets/opencode/mcp-ts/agents/solution-architect.md +1 -1
  206. package/presets/opencode/mcp-ts/agents/task-analyst.md +1 -1
  207. package/presets/opencode/mcp-ts/agents/task-router.md +1 -1
  208. package/presets/opencode/mcp-ts/commands/task-continue.md +1 -1
  209. package/presets/opencode/mcp-ts/hooks/README.md +11 -1
  210. package/presets/opencode/mcp-ts/hooks/guard-shell-command.mjs +154 -0
  211. package/presets/opencode/mcp-ts/plugins/rule-attach/globs.json +151 -0
  212. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +5 -5
  213. package/presets/opencode/mol/OPENCODE.md +5 -56
  214. package/presets/opencode/mol/adapter-map.json +31 -31
  215. package/presets/opencode/mol/agents/accessibility-reviewer.md +1 -1
  216. package/presets/opencode/mol/agents/api-contract-reviewer.md +1 -1
  217. package/presets/opencode/mol/agents/build-verifier.md +1 -1
  218. package/presets/opencode/mol/agents/ci-investigator.md +1 -1
  219. package/presets/opencode/mol/agents/code-reviewer.md +1 -1
  220. package/presets/opencode/mol/agents/codebase-analyzer.md +1 -1
  221. package/presets/opencode/mol/agents/debugger.md +1 -1
  222. package/presets/opencode/mol/agents/feature-developer.md +1 -1
  223. package/presets/opencode/mol/agents/migration-specialist.md +1 -1
  224. package/presets/opencode/mol/agents/mockup-reviewer.md +1 -1
  225. package/presets/opencode/mol/agents/openspec-author.md +1 -1
  226. package/presets/opencode/mol/agents/performance-auditor.md +1 -1
  227. package/presets/opencode/mol/agents/playwright-test-generator.md +1 -1
  228. package/presets/opencode/mol/agents/playwright-test-healer.md +1 -1
  229. package/presets/opencode/mol/agents/playwright-test-planner.md +1 -1
  230. package/presets/opencode/mol/agents/qa-tester.md +1 -1
  231. package/presets/opencode/mol/agents/security-reviewer.md +1 -1
  232. package/presets/opencode/mol/agents/solution-architect.md +1 -1
  233. package/presets/opencode/mol/agents/task-analyst.md +1 -1
  234. package/presets/opencode/mol/agents/task-router.md +1 -1
  235. package/presets/opencode/mol/agents/tech-writer.md +1 -1
  236. package/presets/opencode/mol/agents/unit-test-generator.md +1 -1
  237. package/presets/opencode/mol/agents/unit-test-healer.md +1 -1
  238. package/presets/opencode/mol/agents/unit-test-planner.md +1 -1
  239. package/presets/opencode/mol/commands/task-continue.md +1 -1
  240. package/presets/opencode/mol/hooks/README.md +11 -1
  241. package/presets/opencode/mol/hooks/guard-shell-command.mjs +153 -0
  242. package/presets/opencode/mol/plugins/rule-attach/globs.json +112 -0
  243. package/presets/opencode/mol/rules/agent-team-orchestrator.md +5 -5
  244. package/presets/opencode/next/OPENCODE.md +5 -55
  245. package/presets/opencode/next/adapter-map.json +56 -56
  246. package/presets/opencode/next/agents/accessibility-reviewer.md +1 -1
  247. package/presets/opencode/next/agents/api-contract-reviewer.md +1 -1
  248. package/presets/opencode/next/agents/build-verifier.md +1 -1
  249. package/presets/opencode/next/agents/ci-investigator.md +1 -1
  250. package/presets/opencode/next/agents/code-reviewer.md +1 -1
  251. package/presets/opencode/next/agents/codebase-analyzer.md +1 -1
  252. package/presets/opencode/next/agents/debugger.md +1 -1
  253. package/presets/opencode/next/agents/feature-developer.md +1 -1
  254. package/presets/opencode/next/agents/migration-specialist.md +1 -1
  255. package/presets/opencode/next/agents/mockup-reviewer.md +1 -1
  256. package/presets/opencode/next/agents/openspec-author.md +1 -1
  257. package/presets/opencode/next/agents/performance-auditor.md +1 -1
  258. package/presets/opencode/next/agents/playwright-test-generator.md +1 -1
  259. package/presets/opencode/next/agents/playwright-test-healer.md +1 -1
  260. package/presets/opencode/next/agents/playwright-test-planner.md +1 -1
  261. package/presets/opencode/next/agents/qa-tester.md +1 -1
  262. package/presets/opencode/next/agents/security-reviewer.md +1 -1
  263. package/presets/opencode/next/agents/solution-architect.md +1 -1
  264. package/presets/opencode/next/agents/task-analyst.md +1 -1
  265. package/presets/opencode/next/agents/task-router.md +1 -1
  266. package/presets/opencode/next/agents/tech-writer.md +1 -1
  267. package/presets/opencode/next/agents/unit-test-generator.md +1 -1
  268. package/presets/opencode/next/agents/unit-test-healer.md +1 -1
  269. package/presets/opencode/next/agents/unit-test-planner.md +1 -1
  270. package/presets/opencode/next/commands/task-continue.md +1 -1
  271. package/presets/opencode/next/hooks/README.md +11 -1
  272. package/presets/opencode/next/hooks/guard-shell-command.mjs +153 -0
  273. package/presets/opencode/next/plugins/rule-attach/globs.json +276 -0
  274. package/presets/opencode/next/rules/agent-team-orchestrator.md +5 -5
  275. package/presets/opencode/nuxt/OPENCODE.md +5 -54
  276. package/presets/opencode/nuxt/adapter-map.json +51 -51
  277. package/presets/opencode/nuxt/agents/accessibility-reviewer.md +1 -1
  278. package/presets/opencode/nuxt/agents/api-contract-reviewer.md +1 -1
  279. package/presets/opencode/nuxt/agents/build-verifier.md +1 -1
  280. package/presets/opencode/nuxt/agents/ci-investigator.md +1 -1
  281. package/presets/opencode/nuxt/agents/code-reviewer.md +1 -1
  282. package/presets/opencode/nuxt/agents/codebase-analyzer.md +1 -1
  283. package/presets/opencode/nuxt/agents/debugger.md +1 -1
  284. package/presets/opencode/nuxt/agents/feature-developer.md +1 -1
  285. package/presets/opencode/nuxt/agents/migration-specialist.md +1 -1
  286. package/presets/opencode/nuxt/agents/mockup-reviewer.md +1 -1
  287. package/presets/opencode/nuxt/agents/openspec-author.md +1 -1
  288. package/presets/opencode/nuxt/agents/performance-auditor.md +1 -1
  289. package/presets/opencode/nuxt/agents/playwright-test-generator.md +1 -1
  290. package/presets/opencode/nuxt/agents/playwright-test-healer.md +1 -1
  291. package/presets/opencode/nuxt/agents/playwright-test-planner.md +1 -1
  292. package/presets/opencode/nuxt/agents/qa-tester.md +1 -1
  293. package/presets/opencode/nuxt/agents/security-reviewer.md +1 -1
  294. package/presets/opencode/nuxt/agents/solution-architect.md +1 -1
  295. package/presets/opencode/nuxt/agents/task-analyst.md +1 -1
  296. package/presets/opencode/nuxt/agents/task-router.md +1 -1
  297. package/presets/opencode/nuxt/agents/tech-writer.md +1 -1
  298. package/presets/opencode/nuxt/agents/unit-test-generator.md +1 -1
  299. package/presets/opencode/nuxt/agents/unit-test-healer.md +1 -1
  300. package/presets/opencode/nuxt/agents/unit-test-planner.md +1 -1
  301. package/presets/opencode/nuxt/commands/task-continue.md +1 -1
  302. package/presets/opencode/nuxt/hooks/README.md +11 -1
  303. package/presets/opencode/nuxt/hooks/guard-shell-command.mjs +153 -0
  304. package/presets/opencode/nuxt/plugins/rule-attach/globs.json +266 -0
  305. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +5 -5
  306. package/presets/opencode/php-hexagonal/OPENCODE.md +5 -60
  307. package/presets/opencode/php-hexagonal/adapter-map.json +45 -45
  308. package/presets/opencode/php-hexagonal/agents/api-contract-reviewer.md +1 -1
  309. package/presets/opencode/php-hexagonal/agents/build-verifier.md +1 -1
  310. package/presets/opencode/php-hexagonal/agents/ci-investigator.md +1 -1
  311. package/presets/opencode/php-hexagonal/agents/code-reviewer.md +1 -1
  312. package/presets/opencode/php-hexagonal/agents/codebase-analyzer.md +1 -1
  313. package/presets/opencode/php-hexagonal/agents/debugger.md +1 -1
  314. package/presets/opencode/php-hexagonal/agents/feature-developer.md +1 -1
  315. package/presets/opencode/php-hexagonal/agents/integration-test-generator.md +1 -1
  316. package/presets/opencode/php-hexagonal/agents/integration-test-healer.md +1 -1
  317. package/presets/opencode/php-hexagonal/agents/integration-test-planner.md +1 -1
  318. package/presets/opencode/php-hexagonal/agents/migration-specialist.md +1 -1
  319. package/presets/opencode/php-hexagonal/agents/openspec-author.md +1 -1
  320. package/presets/opencode/php-hexagonal/agents/performance-auditor.md +1 -1
  321. package/presets/opencode/php-hexagonal/agents/qa-tester.md +1 -1
  322. package/presets/opencode/php-hexagonal/agents/security-reviewer.md +1 -1
  323. package/presets/opencode/php-hexagonal/agents/solution-architect.md +1 -1
  324. package/presets/opencode/php-hexagonal/agents/task-analyst.md +1 -1
  325. package/presets/opencode/php-hexagonal/agents/task-router.md +1 -1
  326. package/presets/opencode/php-hexagonal/agents/tech-writer.md +1 -1
  327. package/presets/opencode/php-hexagonal/agents/unit-test-generator.md +1 -1
  328. package/presets/opencode/php-hexagonal/agents/unit-test-healer.md +1 -1
  329. package/presets/opencode/php-hexagonal/agents/unit-test-planner.md +1 -1
  330. package/presets/opencode/php-hexagonal/commands/task-continue.md +1 -1
  331. package/presets/opencode/php-hexagonal/hooks/README.md +11 -1
  332. package/presets/opencode/php-hexagonal/hooks/guard-shell-command.mjs +155 -0
  333. package/presets/opencode/php-hexagonal/plugins/rule-attach/globs.json +242 -0
  334. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +5 -5
  335. package/presets/opencode/php-laravel/OPENCODE.md +5 -60
  336. package/presets/opencode/php-laravel/adapter-map.json +45 -45
  337. package/presets/opencode/php-laravel/agents/api-contract-reviewer.md +1 -1
  338. package/presets/opencode/php-laravel/agents/build-verifier.md +1 -1
  339. package/presets/opencode/php-laravel/agents/ci-investigator.md +1 -1
  340. package/presets/opencode/php-laravel/agents/code-reviewer.md +1 -1
  341. package/presets/opencode/php-laravel/agents/codebase-analyzer.md +1 -1
  342. package/presets/opencode/php-laravel/agents/debugger.md +1 -1
  343. package/presets/opencode/php-laravel/agents/feature-developer.md +1 -1
  344. package/presets/opencode/php-laravel/agents/integration-test-generator.md +1 -1
  345. package/presets/opencode/php-laravel/agents/integration-test-healer.md +1 -1
  346. package/presets/opencode/php-laravel/agents/integration-test-planner.md +1 -1
  347. package/presets/opencode/php-laravel/agents/migration-specialist.md +1 -1
  348. package/presets/opencode/php-laravel/agents/openspec-author.md +1 -1
  349. package/presets/opencode/php-laravel/agents/performance-auditor.md +1 -1
  350. package/presets/opencode/php-laravel/agents/qa-tester.md +1 -1
  351. package/presets/opencode/php-laravel/agents/security-reviewer.md +1 -1
  352. package/presets/opencode/php-laravel/agents/solution-architect.md +1 -1
  353. package/presets/opencode/php-laravel/agents/task-analyst.md +1 -1
  354. package/presets/opencode/php-laravel/agents/task-router.md +1 -1
  355. package/presets/opencode/php-laravel/agents/tech-writer.md +1 -1
  356. package/presets/opencode/php-laravel/agents/unit-test-generator.md +1 -1
  357. package/presets/opencode/php-laravel/agents/unit-test-healer.md +1 -1
  358. package/presets/opencode/php-laravel/agents/unit-test-planner.md +1 -1
  359. package/presets/opencode/php-laravel/commands/task-continue.md +1 -1
  360. package/presets/opencode/php-laravel/hooks/README.md +11 -1
  361. package/presets/opencode/php-laravel/hooks/guard-shell-command.mjs +155 -0
  362. package/presets/opencode/php-laravel/plugins/rule-attach/globs.json +232 -0
  363. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +5 -5
  364. package/presets/opencode/platform-contract.json +4 -0
  365. package/presets/opencode/plugins/output-guard/README.md +1 -1
  366. package/presets/opencode/plugins/output-guard/index.ts +8 -2
  367. package/presets/opencode/plugins/output-guard/rewrite.ts +37 -0
  368. package/presets/opencode/plugins/rule-attach/README.md +34 -0
  369. package/presets/opencode/plugins/rule-attach/attach.ts +224 -0
  370. package/presets/opencode/plugins/rule-attach/index.ts +169 -0
  371. package/presets/opencode/plugins/rule-attach/package.json +9 -0
  372. package/presets/opencode/svelte/OPENCODE.md +5 -54
  373. package/presets/opencode/svelte/adapter-map.json +51 -51
  374. package/presets/opencode/svelte/agents/accessibility-reviewer.md +1 -1
  375. package/presets/opencode/svelte/agents/api-contract-reviewer.md +1 -1
  376. package/presets/opencode/svelte/agents/build-verifier.md +1 -1
  377. package/presets/opencode/svelte/agents/ci-investigator.md +1 -1
  378. package/presets/opencode/svelte/agents/code-reviewer.md +1 -1
  379. package/presets/opencode/svelte/agents/codebase-analyzer.md +1 -1
  380. package/presets/opencode/svelte/agents/debugger.md +1 -1
  381. package/presets/opencode/svelte/agents/feature-developer.md +1 -1
  382. package/presets/opencode/svelte/agents/migration-specialist.md +1 -1
  383. package/presets/opencode/svelte/agents/mockup-reviewer.md +1 -1
  384. package/presets/opencode/svelte/agents/openspec-author.md +1 -1
  385. package/presets/opencode/svelte/agents/performance-auditor.md +1 -1
  386. package/presets/opencode/svelte/agents/playwright-test-generator.md +1 -1
  387. package/presets/opencode/svelte/agents/playwright-test-healer.md +1 -1
  388. package/presets/opencode/svelte/agents/playwright-test-planner.md +1 -1
  389. package/presets/opencode/svelte/agents/qa-tester.md +1 -1
  390. package/presets/opencode/svelte/agents/security-reviewer.md +1 -1
  391. package/presets/opencode/svelte/agents/solution-architect.md +1 -1
  392. package/presets/opencode/svelte/agents/task-analyst.md +1 -1
  393. package/presets/opencode/svelte/agents/task-router.md +1 -1
  394. package/presets/opencode/svelte/agents/tech-writer.md +1 -1
  395. package/presets/opencode/svelte/agents/unit-test-generator.md +1 -1
  396. package/presets/opencode/svelte/agents/unit-test-healer.md +1 -1
  397. package/presets/opencode/svelte/agents/unit-test-planner.md +1 -1
  398. package/presets/opencode/svelte/commands/task-continue.md +1 -1
  399. package/presets/opencode/svelte/hooks/README.md +11 -1
  400. package/presets/opencode/svelte/hooks/guard-shell-command.mjs +153 -0
  401. package/presets/opencode/svelte/plugins/rule-attach/globs.json +245 -0
  402. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +5 -5
  403. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  404. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +3 -3
  405. package/presets/zcode/go/adapter-map.json +1 -1
  406. package/presets/zcode/go/rules/agent-team-orchestrator.md +3 -3
  407. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  408. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +3 -3
  409. package/presets/zcode/java/adapter-map.json +1 -1
  410. package/presets/zcode/java/rules/agent-team-orchestrator.md +3 -3
  411. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  412. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +3 -3
  413. package/presets/zcode/mol/adapter-map.json +1 -1
  414. package/presets/zcode/mol/rules/agent-team-orchestrator.md +3 -3
  415. package/presets/zcode/next/adapter-map.json +1 -1
  416. package/presets/zcode/next/rules/agent-team-orchestrator.md +3 -3
  417. package/presets/zcode/nuxt/adapter-map.json +1 -1
  418. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +3 -3
  419. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  420. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +3 -3
  421. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  422. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +3 -3
  423. package/presets/zcode/svelte/adapter-map.json +1 -1
  424. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +3 -3
  425. package/scripts/report-context-cost.mjs +1 -20
@@ -0,0 +1,155 @@
1
+ #!/usr/bin/env node
2
+ // Shell guard for Cursor `beforeShellExecution` and Claude `PreToolUse`.
3
+ // Rendered from `presets/_shared/hooks/guard-shell-command.mjs.tmpl`; edit the
4
+ // template, never a rendered copy.
5
+ // PHP: do NOT blanket-block php artisan test / composer test / compiler/IDE inspections / configured static analysis / repo static analysis.
6
+ // Package-manager mismatch checks apply only when a JS lockfile/package.json exists.
7
+ // PHP_PRESET_GUARD: allow composer/composer test; no Playwright/XCUITest assumptions
8
+ const SERVER_COMMAND = new RegExp("artisan\\s+serve|php\\s+-S");
9
+ const SERVER_PORTS = [8000];
10
+ import fs from 'node:fs';
11
+ import net from 'node:net';
12
+ import path from 'node:path';
13
+ import { fileURLToPath } from 'node:url';
14
+
15
+ const allowed = () => ({ permission: 'allow' });
16
+
17
+ const ask = (userMessage, agentMessage) => ({
18
+ permission: 'ask',
19
+ user_message: userMessage,
20
+ agent_message: agentMessage || userMessage,
21
+ });
22
+
23
+ const portIsOpen = (port) =>
24
+ new Promise((resolve) => {
25
+ const socket = net.createConnection({ host: '127.0.0.1', port });
26
+ const done = (open) => {
27
+ socket.destroy();
28
+ resolve(open);
29
+ };
30
+ socket.once('connect', () => done(true));
31
+ socket.once('error', () => done(false));
32
+ socket.setTimeout(400, () => done(false));
33
+ });
34
+
35
+ /**
36
+ * The decision for one shell event: `{ permission, user_message, agent_message }`.
37
+ *
38
+ * Shared by the CLI below and any host that can import the rendered file, so
39
+ * the verdict cannot drift between them. Two effects are injected — a project
40
+ * file read and a TCP probe — because a plugin has no stdin to read and no
41
+ * guaranteed working directory. Never throws: an unreadable event is an allow,
42
+ * the same fail-open the hook always had.
43
+ */
44
+ export const evaluate = async (event, options = {}) => {
45
+ const {
46
+ root = process.cwd(),
47
+ exists = (file) => fs.existsSync(file),
48
+ readText = (file) => fs.readFileSync(file, 'utf8'),
49
+ canConnect = portIsOpen,
50
+ } = options;
51
+ const at = (file) => path.join(root, file);
52
+ if (!event || typeof event !== 'object') return allowed();
53
+
54
+ const command = String(event.command || event.input?.command || event.tool_input?.command || '');
55
+ if (!command.trim()) return allowed();
56
+
57
+ const dangerousGit = /\bgit\s+(reset\s+--hard|clean\s+-[^\n]*f|push\s+--force|push\s+-f|checkout\s+--\s+)/;
58
+ if (dangerousGit.test(command)) {
59
+ return ask(
60
+ 'This command looks destructive for git state. Review it before continuing.',
61
+ 'A project hook flagged a destructive git command. Ask the user before running it.',
62
+ );
63
+ }
64
+
65
+ if (/\b(?:pkill|killall)\b|\bxargs\s+kill\b/.test(command)) {
66
+ return ask(
67
+ 'This command can stop processes the task does not own. Name the process you started, or use `node .ai.local/scripts/processes.mjs stop`.',
68
+ 'Never mass-kill processes. Stop the recorded pid through processes.mjs; ask before pkill, killall, or xargs kill.',
69
+ );
70
+ }
71
+
72
+ const managerByFile = [
73
+ ['yarn.lock', 'yarn'],
74
+ ['pnpm-lock.yaml', 'pnpm'],
75
+ ['package-lock.json', 'npm'],
76
+ ].find(([file]) => exists(at(file)));
77
+
78
+ let expected = managerByFile?.[1];
79
+ if (!expected && exists(at('package.json'))) {
80
+ try {
81
+ const pkg = JSON.parse(readText(at('package.json')));
82
+ const pm = typeof pkg.packageManager === 'string' ? pkg.packageManager : '';
83
+ expected = pm.split('@')[0] || undefined;
84
+ } catch {
85
+ // Ignore invalid package.json in the hook; the agent can diagnose it later.
86
+ }
87
+ }
88
+
89
+ const used = expected ? command.match(/(^|[;&|]\s*)(npm|yarn|pnpm)\s+/)?.[2] : undefined;
90
+ if (used && used !== expected) {
91
+ return ask(
92
+ `This repository appears to use ${expected}, but the command uses ${used}. Confirm before continuing.`,
93
+ `Use ${expected} for package scripts and installs unless the user explicitly approves ${used}.`,
94
+ );
95
+ }
96
+
97
+ // Only a server-start shaped command is worth probing: the hook must not slow
98
+ // down or interrogate every shell call.
99
+ const explicitPortMatch = command.match(/--port[=\s]+(\d{2,5})|\bPORT=(\d{2,5})/);
100
+ const explicitPort = Number(explicitPortMatch?.[1] || explicitPortMatch?.[2] || 0) || null;
101
+ const startsServer = SERVER_COMMAND ? SERVER_COMMAND.test(command) : false;
102
+ const portsToProbe = startsServer ? (explicitPort ? [explicitPort] : SERVER_PORTS) : [];
103
+
104
+ for (const port of portsToProbe) {
105
+ if (!(await canConnect(port))) continue;
106
+ return ask(
107
+ `Port ${port} is already listening. Reuse the running server, or stop the recorded process before starting another.`,
108
+ `A server may already serve port ${port}. Probe it first, reuse it, or stop it with \`node .ai.local/scripts/processes.mjs stop\`; never start a duplicate.`,
109
+ );
110
+ }
111
+
112
+ return allowed();
113
+ };
114
+
115
+ /** The host answers: Claude's `PreToolUse` envelope, or the neutral decision. */
116
+ const answer = (event, decision) => {
117
+ const claudePreTool = event !== null && event.hook_event_name === 'PreToolUse';
118
+ if (!claudePreTool) {
119
+ process.stdout.write(JSON.stringify(decision));
120
+ } else {
121
+ const verdict = decision.permission === 'ask' || decision.permission === 'deny' ? decision.permission : 'allow';
122
+ const hookSpecificOutput = { hookEventName: 'PreToolUse', permissionDecision: verdict };
123
+ if (decision.user_message && verdict !== 'allow') {
124
+ hookSpecificOutput.permissionDecisionReason = decision.user_message;
125
+ }
126
+ process.stdout.write(JSON.stringify({ hookSpecificOutput }));
127
+ }
128
+ process.exit(0);
129
+ };
130
+
131
+ const main = async () => {
132
+ let event = null;
133
+ try {
134
+ const parsed = JSON.parse(fs.readFileSync(0, 'utf8'));
135
+ event = parsed && typeof parsed === 'object' ? parsed : null;
136
+ } catch {
137
+ event = null;
138
+ }
139
+ answer(event, await evaluate(event));
140
+ };
141
+
142
+ const invokedDirectly = (() => {
143
+ if (process.argv[1] === undefined) return false;
144
+ // Realpath on both sides: `os.tmpdir()` and `/tmp` are symlinks on macOS, so a
145
+ // plain resolve marks a script it cannot start.
146
+ try {
147
+ return fs.realpathSync(process.argv[1]) === fs.realpathSync(fileURLToPath(import.meta.url));
148
+ } catch {
149
+ return path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url));
150
+ }
151
+ })();
152
+
153
+ if (invokedDirectly) {
154
+ await main();
155
+ }
@@ -0,0 +1,232 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "source": "presets/cursor/php-laravel/rules/*.mdc frontmatter (alwaysApply: true excluded)",
4
+ "rules": [
5
+ {
6
+ "stem": "actions-services",
7
+ "globs": [
8
+ "**/Actions/**/*",
9
+ "**/Services/**/*"
10
+ ]
11
+ },
12
+ {
13
+ "stem": "domain-layer",
14
+ "globs": [
15
+ "**/Domain/**/*",
16
+ "**/domain/**/*"
17
+ ]
18
+ },
19
+ {
20
+ "stem": "eloquent-persistence",
21
+ "globs": [
22
+ "**/Models/**/*",
23
+ "**/database/migrations/**/*",
24
+ "**/database/factories/**/*",
25
+ "**/database/seeders/**/*"
26
+ ]
27
+ },
28
+ {
29
+ "stem": "events-listeners",
30
+ "globs": [
31
+ "**/Events/**/*",
32
+ "**/Listeners/**/*",
33
+ "**/*Event.php",
34
+ "**/*Listener.php"
35
+ ]
36
+ },
37
+ {
38
+ "stem": "form-requests",
39
+ "globs": [
40
+ "**/Http/Requests/**/*",
41
+ "**/*Request.php"
42
+ ]
43
+ },
44
+ {
45
+ "stem": "http-layer",
46
+ "globs": [
47
+ "**/Http/Controllers/**/*",
48
+ "**/Http/Resources/**/*",
49
+ "**/Http/Middleware/**/*",
50
+ "**/*Controller.php"
51
+ ]
52
+ },
53
+ {
54
+ "stem": "jobs-queues",
55
+ "globs": [
56
+ "**/Jobs/**/*",
57
+ "**/*Job.php"
58
+ ]
59
+ },
60
+ {
61
+ "stem": "language-policy",
62
+ "globs": [
63
+ ".ai.local/**/*",
64
+ "AGENTS.md",
65
+ ".cursor/**/*"
66
+ ]
67
+ },
68
+ {
69
+ "stem": "laravel-conventions",
70
+ "globs": [
71
+ "**/*.php"
72
+ ]
73
+ },
74
+ {
75
+ "stem": "module-public-api",
76
+ "globs": [
77
+ "**/composer.json",
78
+ "**/app/**/*.php"
79
+ ]
80
+ },
81
+ {
82
+ "stem": "php-tooling",
83
+ "globs": [
84
+ "**/*.php",
85
+ "**/composer.json",
86
+ "**/composer.lock",
87
+ "**/phpunit.xml*",
88
+ "**/artisan",
89
+ "**/pint.json",
90
+ "**/phpstan*"
91
+ ]
92
+ },
93
+ {
94
+ "stem": "policies-authorization",
95
+ "globs": [
96
+ "**/Policies/**/*",
97
+ "**/*Policy.php"
98
+ ]
99
+ },
100
+ {
101
+ "stem": "post-change-test",
102
+ "globs": [
103
+ "**/*.php",
104
+ "**/composer.json",
105
+ "**/composer.lock",
106
+ "**/phpunit.xml*",
107
+ "**/artisan"
108
+ ]
109
+ },
110
+ {
111
+ "stem": "preset-goals",
112
+ "globs": [
113
+ "packages/ai-rules/presets/**/*",
114
+ "packages/ai-rules/scripts/**/*",
115
+ "packages/ai-rules/docs/**/*"
116
+ ]
117
+ },
118
+ {
119
+ "stem": "preset-layering",
120
+ "globs": [
121
+ "packages/ai-rules/presets/**/*",
122
+ "packages/ai-rules/scripts/**/*",
123
+ "packages/ai-rules/docs/**/*"
124
+ ]
125
+ },
126
+ {
127
+ "stem": "preset-no-cross-stack-leakage",
128
+ "globs": [
129
+ "packages/ai-rules/presets/**/*",
130
+ "packages/ai-rules/scripts/**/*",
131
+ "packages/ai-rules/docs/**/*"
132
+ ]
133
+ },
134
+ {
135
+ "stem": "preset-pr-checklist",
136
+ "globs": [
137
+ "packages/ai-rules/presets/**/*",
138
+ "packages/ai-rules/scripts/**/*",
139
+ "packages/ai-rules/docs/**/*"
140
+ ]
141
+ },
142
+ {
143
+ "stem": "preset-token-budget",
144
+ "globs": [
145
+ "packages/ai-rules/presets/**/*",
146
+ "packages/ai-rules/scripts/**/*",
147
+ "packages/ai-rules/docs/**/*"
148
+ ]
149
+ },
150
+ {
151
+ "stem": "preset-twin-sync",
152
+ "globs": [
153
+ "packages/ai-rules/presets/**/*",
154
+ "packages/ai-rules/scripts/**/*",
155
+ "packages/ai-rules/docs/**/*"
156
+ ]
157
+ },
158
+ {
159
+ "stem": "preset-writing-style",
160
+ "globs": [
161
+ "packages/ai-rules/presets/**/*",
162
+ "packages/ai-rules/scripts/**/*",
163
+ "packages/ai-rules/docs/**/*"
164
+ ]
165
+ },
166
+ {
167
+ "stem": "product-specs-authoring",
168
+ "globs": [
169
+ "docs/specs/**/*"
170
+ ]
171
+ },
172
+ {
173
+ "stem": "product-specs",
174
+ "globs": [
175
+ "docs/specs/**/*"
176
+ ]
177
+ },
178
+ {
179
+ "stem": "routes-api",
180
+ "globs": [
181
+ "**/routes/**/*",
182
+ "**/bootstrap/app.php"
183
+ ]
184
+ },
185
+ {
186
+ "stem": "security-php",
187
+ "globs": [
188
+ "**/Http/**/*",
189
+ "**/routes/**/*",
190
+ "**/Policies/**/*",
191
+ "**/Models/**/*",
192
+ "**/Jobs/**/*",
193
+ "**/*Job.php",
194
+ "**/config/**/*",
195
+ "**/.env*"
196
+ ]
197
+ },
198
+ {
199
+ "stem": "service-providers",
200
+ "globs": [
201
+ "**/Providers/**/*",
202
+ "**/bootstrap/providers.php"
203
+ ]
204
+ },
205
+ {
206
+ "stem": "tests-e2e",
207
+ "globs": [
208
+ "**/tests/E2E/**/*",
209
+ "**/tests/e2e/**/*",
210
+ "**/*E2ETest.php",
211
+ "**/*SmokeTest.php"
212
+ ]
213
+ },
214
+ {
215
+ "stem": "tests-integration",
216
+ "globs": [
217
+ "**/tests/Feature/**/*",
218
+ "**/tests/Integration/**/*",
219
+ "**/*FeatureTest.php",
220
+ "**/*IT.php"
221
+ ]
222
+ },
223
+ {
224
+ "stem": "tests-unit",
225
+ "globs": [
226
+ "**/tests/Unit/**/*",
227
+ "**/tests/unit/**/*",
228
+ "**/*Test.php"
229
+ ]
230
+ }
231
+ ]
232
+ }
@@ -64,7 +64,7 @@ flowchart TD
64
64
  pipeline["pipeline.json"]
65
65
  step0["steps 0..N"]
66
66
  gate{"humanGates?"}
67
- hook["subagentStop hook"]
67
+ hook["chain hook (run by hand)"]
68
68
  retro["/technical-retro"]
69
69
 
70
70
  task --> router
@@ -217,7 +217,7 @@ Additional states: `blocked` — a step (or a parallel producer) cannot proceed;
217
217
  - The reclaim runs only inside the hook, immediately before a new attempt is activated. Never hand-reclaim an attempt by editing `.ai.local/team/tasks/<slug>` lifecycle files.
218
218
  - In graph mode, a stale attempt on an in-flight step of another agent is reclaimed by that step's own activation or terminal receipt, not by an unrelated step; recovery is a receipt or `/task-continue <slug>`.
219
219
 
220
- On each `subagentStop`, the hook reconciles `status.state` from the completing producer's terminal `artifact-manifest.json` receipt (`completed` \| `changes_requested` \| `validation_failed`) when agents left lifecycle fields untouched. Parent orchestrators must wait for that handoff before invoking the next step.
220
+ No `subagentStop` event exists on this host: after each producer receipt the agent runs `chain-team-phases.sh`, and that run reconciles `status.state` from the completing producer's terminal `artifact-manifest.json` receipt (`completed` \| `changes_requested` \| `validation_failed`) when agents left lifecycle fields untouched. Do not invoke the next step until the run lands that handoff.
221
221
 
222
222
  **A dispatch is not a completion.** When the host hands back a session handle, a job id, or control before the specialist's turn ends, the step is still open: do not dispatch the next step, do not report the step done, and do not run the chain hook until the specialist reports back and the hook records the receipt. A background handle is a start signal only.
223
223
 
@@ -269,12 +269,12 @@ Use Task tool or `/agent-name`. Pass: slug, artifact paths, step `scope` if set.
269
269
  ### Model when invoking (Task)
270
270
 
271
271
  1. Read `steps[i].model` if present; else use the agent’s frontmatter `model` (see `agents/README.md` matrix).
272
- 2. Resolve the tier through `.ai.local/team/model-tiers.json` → `tiers.<tier>` when that file exists. The user approved that map, so passing an explicit model is allowed. Pass the resolved `providerID/modelID` (or `providerID/modelID#variant`) to the Task/subagent tool.
272
+ 2. Resolve the tier through `.ai.local/team/model-tiers.json` → `tiers.<tier>` when that file is an approved map. An empty `tiers` object with an empty `approvedBy` is the unfilled template: omit the model and the session model applies. Once `approvedBy` is set or any tier value is set, the file is the map, so passing an explicit model is allowed. Pass the resolved `providerID/modelID` (or `providerID/modelID#variant`) to the Task/subagent tool.
273
273
  - **`cheap`** → router, analyst, tech-writer, codebase-analyzer, and the review roles `code-reviewer`, `build-verifier`, `api-contract-reviewer`, `mockup-reviewer`. Resolve the provider through `.ai.local/team/model-tiers.json`. Do not write a provider id into the agent file. Pass the mapped id as written; do not append `#high`.
274
274
  - **`standard`** → implementation and the other non-review specialists. `feature-developer` stays on this tier.
275
275
  - **`strong`** → architecture, security, migration, performance. Never downgrade a `strong` step to the parent default, and do not put `mockup-reviewer` on `strong`.
276
- - When `steps[i].model` is omitted and the agent file has no `model`, those four review roles stay `cheap` when `.ai.local/team/model-tiers.json` exists. Without that file, omit the model and the session model applies.
277
- - If a tier is declared but the file has no mapping, **STOP** and report `model-tier-unmapped`; do not silently inherit the parent model.
276
+ - When `steps[i].model` is omitted and the agent file has no `model`, those four review roles stay `cheap` when the map has a `cheap` value. Without the file, or while the template is still empty, omit the model and the session model applies.
277
+ - If a tier is declared, the map is approved, and that tier has no mapping, **STOP** and report `model-tier-unmapped`; do not silently inherit the parent model.
278
278
  3. If the tool does not accept a model (Cursor/Claude adapters), record the resolved tier in the handoff and let the platform pin apply.
279
279
  4. Parallel steps: apply the step-level `model` to **each** agent in the array (or omit → each agent’s own frontmatter).
280
280
  5. The tier never changes the step order, gates, receipts, or retry policy.
@@ -47,6 +47,10 @@
47
47
  {
48
48
  "source": "hooks",
49
49
  "destination": ".opencode/hooks"
50
+ },
51
+ {
52
+ "source": "plugins",
53
+ "destination": ".opencode/plugins"
50
54
  }
51
55
  ],
52
56
  "sharedDirectoryMappings": [
@@ -13,7 +13,7 @@ call; persisted history is untouched.
13
13
  | Item | Value |
14
14
  |---|---|
15
15
  | Trigger | `tool-result` text over **8192 B** (`AI_RULES_OUTPUT_GUARD_BYTES`) |
16
- | Tools | `shell`, `bash`, `read`, `grep`, `glob`, `webfetch` |
16
+ | Tools | `shell`, `bash`, `read`, `grep`, `glob`, `webfetch` — a `read` of `.opencode/rules/**` or `.ai.local/rules/**` is never replaced |
17
17
  | Replacement (8–20 KB band) | structured head + tail: named elision, top-level JSON keys that sit in the gap, a `grep -n '<term>'` hint for a whole-line gap that carries a usable term, or `tail -c` when a line is cut mid-way |
18
18
  | Replacement (over 20 KB) | 40-line / 2 KB head + 15-line / 1 KB tail + path + hints |
19
19
  | Shape override | `AI_RULES_OUTPUT_GUARD_SHAPE=flat` forces the legacy renderer in the band |
@@ -13,6 +13,10 @@
13
13
  * AI_RULES_OUTPUT_GUARD_DEBUG=1. Ledger rotation: once in `setup()` at
14
14
  * AI_RULES_OUTPUT_GUARD_ROTATE_BYTES (default 8 MiB, 0 disables), two archives.
15
15
  *
16
+ * Rule bodies are the one exception: a `read` of `.opencode/rules/**` or
17
+ * `.ai.local/rules/**` is never replaced. The rule is the instruction the agent
18
+ * follows, so a compacted rule is a contract read at 18% of its bytes.
19
+ *
16
20
  * Telemetry beside the guard: `usage.jsonl` reads the token rows of the session
17
21
  * and of the child sessions it discovers, and `context.jsonl` keeps one row per
18
22
  * `(sessionID, toolset)` for the MCP schema split. Neither rotates. Child
@@ -34,7 +38,7 @@ import {
34
38
  turnCounters,
35
39
  } from "./actions.ts"
36
40
  import { parseRotateBytes, rotateLedger, ROTATE_BYTES_ENV } from "./ledger.ts"
37
- import { rewriteMessages } from "./rewrite.ts"
41
+ import { isRuleReadPath, rewriteMessages } from "./rewrite.ts"
38
42
 
39
43
  const MARKER = "[ai-rules output-guard]"
40
44
  const DEFAULT_THRESHOLD_BYTES = 8192
@@ -573,7 +577,9 @@ export default Plugin.define({
573
577
  if (file) savedPaths.set(key, file)
574
578
  return file
575
579
  }
576
- const result = rewriteMessages(event.messages, options, save)
580
+ const result = rewriteMessages(event.messages, options, save, ({ tool, id }) =>
581
+ tool === "read" && isRuleReadPath(calls.get(id)?.command ?? "", projectRoot),
582
+ )
577
583
  const changedById = new Map(result.changed.map((stat) => [stat.id, stat]))
578
584
  for (const stat of result.changed) {
579
585
  if (statsRecorded.has(stat.path)) continue
@@ -3,6 +3,8 @@
3
3
  * adapter in `index.ts` supplies the writer, and the fixture test imports this
4
4
  * module directly.
5
5
  */
6
+ import fs from "node:fs"
7
+ import path from "node:path"
6
8
 
7
9
  export type OutputGuardOptions = {
8
10
  thresholdBytes: number
@@ -44,6 +46,35 @@ const DEFAULT_MARKER = "[ai-rules output-guard]"
44
46
  export const isOutputGuardText = (value: string, marker = DEFAULT_MARKER): boolean =>
45
47
  value.startsWith(marker)
46
48
 
49
+ /**
50
+ * A shipped rule body: the instruction the agent is supposed to follow. The
51
+ * guard exists to keep *tool output* out of the window, and compacting a rule
52
+ * leaves the agent acting on a head and a tail of its own contract, so these
53
+ * two trees are never replaced. Matched on a path segment, never a substring:
54
+ * `.opencode/rules-backup/x.md` stays guarded.
55
+ */
56
+ const RULE_READ_PATTERN = /(?:^|\/)\.opencode\/rules\/|(?:^|\/)\.ai\.local\/rules\//
57
+
58
+ const realTarget = (target: string): string => {
59
+ try {
60
+ return fs.realpathSync.native(target)
61
+ } catch {
62
+ return target
63
+ }
64
+ }
65
+
66
+ /**
67
+ * The caller supplies a `read` target, not a trusted path: resolve it against
68
+ * the project root (so `..` cannot smuggle a non-rule file into the tree) and,
69
+ * when it exists, follow a symlink before matching. Without a root the check
70
+ * stays lexical, which is all the unit fixtures need.
71
+ */
72
+ export const isRuleReadPath = (value: unknown, projectRoot?: string): boolean => {
73
+ if (typeof value !== "string" || value.trim() === "") return false
74
+ const resolved = projectRoot ? path.resolve(projectRoot, value) : value
75
+ return RULE_READ_PATTERN.test(realTarget(resolved).replace(/\\/g, "/"))
76
+ }
77
+
47
78
  const bytes = (value: string): number => Buffer.byteLength(value, "utf8")
48
79
 
49
80
  const takeHead = (value: string, maxBytes: number, maxLines: number): string => {
@@ -217,11 +248,16 @@ export const renderReplacement = (
217
248
  * Replace every large, allow-listed `tool-result` text in the assembled model
218
249
  * messages. Mutates the result objects in place (the host assembles them per
219
250
  * request) and returns the stats the adapter records.
251
+ *
252
+ * `isExempt` is the adapter's rule-read check: the read tool's target lives in
253
+ * the paired `tool-call` input, which the adapter already has, so the pure
254
+ * module asks rather than parses a path it cannot see.
220
255
  */
221
256
  export function rewriteMessages(
222
257
  messages: unknown,
223
258
  options: OutputGuardOptions,
224
259
  save: SaveOutput,
260
+ isExempt?: (input: { tool: string; id: string }) => boolean,
225
261
  ): RewriteResult {
226
262
  const changed: OutputGuardStats[] = []
227
263
  if (!Array.isArray(messages)) return { changed }
@@ -239,6 +275,7 @@ export function rewriteMessages(
239
275
  if (isOutputGuardText(value, options.marker)) continue
240
276
  const beforeBytes = bytes(value)
241
277
  if (beforeBytes <= options.thresholdBytes) continue
278
+ if (isExempt?.({ tool, id: typeof item.id === "string" ? item.id : "" })) continue
242
279
 
243
280
  let file: string | null = null
244
281
  try {
@@ -0,0 +1,34 @@
1
+ # Rule attach (OpenCode server plugin)
2
+
3
+ Delivers a rule body from a touched path, the way Cursor's `globs:` frontmatter
4
+ does. The host has no path-glob rule delivery, so without this plugin a rule
5
+ reaches the model only when the agent spends a `Read` on it.
6
+
7
+ `ctx.session.hook("context")` walks the assembled messages for `tool-call` parts
8
+ and reads the `filePath` / `path` / `file` target of a `read` / `edit` / `write`
9
+ / `grep` / `glob` call, plus a path token in a `bash` / `shell` / `sh` command.
10
+ It then appends the bodies of the stems whose globs match those targets as one
11
+ trailing `user` message. The model reads the rule from the message it already
12
+ has, so the conditional `Read` disappears. The context payload is the only
13
+ source: OpenCode v2.4.1 never dispatches a `tool.execute.after` registration
14
+ to a plugin.
15
+
16
+ ## Behaviour
17
+
18
+ | Item | Value |
19
+ |---|---|
20
+ | Table | `.opencode/plugins/rule-attach/globs.json` — this stack's `presets/cursor/<stack>/rules/*.mdc` frontmatter, `alwaysApply: true` excluded (those ship as `opencode.json` `instructions`). Install copies the stack file ahead of the shared plugin tree |
21
+ | Trigger | a repo-relative path a `read` / `edit` / `write` / `grep` / `glob` call touched, or a path token in a `bash` / `shell` / `sh` command. The command is not executed. A quoted sentence with spaces is not a path |
22
+ | Injected | one trailing `user` message, one part, each body prefixed `[ai-rules rule-attach] .opencode/rules/<stem>.md` |
23
+ | Dedupe | per `(sessionID, stem)`, and the marker in the assembled messages wins over the in-memory set |
24
+ | Budget | `MAX_ATTACH_LINES = 420` non-empty lines per attach — the largest `check-next-attached-budget.mjs` fixture cap. A stem that does not fit is skipped, never truncated |
25
+ | Kill switch | `AI_RULES_RULE_ATTACH=0` |
26
+ | Debug | `AI_RULES_RULE_ATTACH_DEBUG=1` → `.ai.local/team/output-guard/debug.log` |
27
+ | Host | OpenCode V2 with `ctx.session.hook`; a host without it no-ops |
28
+
29
+ Injects text only: no shell, no `child_process`, nothing the model wrote is
30
+ executed. The tool-target keys read are `filePath`, `path`, `file`; a target
31
+ outside the project root is ignored.
32
+
33
+ **Limit.** A stem with an empty glob list is not in the catalog and stays a
34
+ lazy `Read`. The command tokenizer does not expand globs or follow redirects.