@bonesofspring/ai-rules 0.2.84 → 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 (445) hide show
  1. package/CHANGELOG.md +30 -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 +19 -10
  8. package/docs/TEAM-DB.md +76 -3
  9. package/docs/TOKEN-ECONOMY.md +20 -0
  10. package/docs/openapi/team-db.v1.json +7069 -5895
  11. package/package.json +5 -2
  12. package/presets/_shared/ai-local/scripts/report-step-cost.mjs +544 -0
  13. package/presets/_shared/ai-local/scripts/team-db-api.mjs +253 -15
  14. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +310 -4
  15. package/presets/_shared/ai-local/scripts/team-db-project.mjs +733 -8
  16. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +44 -0
  17. package/presets/_shared/ai-local/scripts/team-db.mjs +43 -3
  18. package/presets/_shared/assets/model-tiers.json +6 -0
  19. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +3 -3
  20. package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +125 -105
  21. package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +125 -105
  22. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  23. package/presets/claude/go/hooks/guard-shell-command.mjs +125 -105
  24. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  25. package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +125 -105
  26. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  27. package/presets/claude/java/hooks/guard-shell-command.mjs +125 -105
  28. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  29. package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +125 -105
  30. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  31. package/presets/claude/mol/hooks/guard-shell-command.mjs +125 -105
  32. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  33. package/presets/claude/next/agents/build-verifier.md +2 -1
  34. package/presets/claude/next/agents/feature-developer.md +1 -1
  35. package/presets/claude/next/hooks/guard-shell-command.mjs +125 -105
  36. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  37. package/presets/claude/nuxt/hooks/guard-shell-command.mjs +125 -105
  38. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  39. package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +125 -105
  40. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  41. package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +125 -105
  42. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  43. package/presets/claude/svelte/hooks/guard-shell-command.mjs +125 -105
  44. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +3 -3
  45. package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +125 -105
  46. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +3 -3
  47. package/presets/cursor/go/hooks/guard-shell-command.mjs +125 -105
  48. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +3 -3
  49. package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +125 -105
  50. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +3 -3
  51. package/presets/cursor/java/hooks/guard-shell-command.mjs +125 -105
  52. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +3 -3
  53. package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +125 -105
  54. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +3 -3
  55. package/presets/cursor/mol/hooks/guard-shell-command.mjs +125 -105
  56. package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +3 -3
  57. package/presets/cursor/next/agents/build-verifier.md +2 -1
  58. package/presets/cursor/next/agents/feature-developer.md +1 -1
  59. package/presets/cursor/next/hooks/guard-shell-command.mjs +125 -105
  60. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +3 -3
  61. package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +125 -105
  62. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +3 -3
  63. package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +125 -105
  64. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +3 -3
  65. package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +125 -105
  66. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +3 -3
  67. package/presets/cursor/svelte/hooks/guard-shell-command.mjs +125 -105
  68. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +3 -3
  69. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  70. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +3 -3
  71. package/presets/mavis/go/adapter-map.json +1 -1
  72. package/presets/mavis/go/rules/agent-team-orchestrator.md +3 -3
  73. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  74. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +3 -3
  75. package/presets/mavis/java/adapter-map.json +1 -1
  76. package/presets/mavis/java/rules/agent-team-orchestrator.md +3 -3
  77. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  78. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +3 -3
  79. package/presets/mavis/mol/adapter-map.json +1 -1
  80. package/presets/mavis/mol/rules/agent-team-orchestrator.md +3 -3
  81. package/presets/mavis/next/adapter-map.json +1 -1
  82. package/presets/mavis/next/agents/build-verifier.md +2 -1
  83. package/presets/mavis/next/agents/feature-developer.md +1 -1
  84. package/presets/mavis/next/rules/agent-team-orchestrator.md +3 -3
  85. package/presets/mavis/nuxt/adapter-map.json +1 -1
  86. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +3 -3
  87. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  88. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +3 -3
  89. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  90. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +3 -3
  91. package/presets/mavis/svelte/adapter-map.json +1 -1
  92. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +3 -3
  93. package/presets/opencode/android-kotlin/OPENCODE.md +5 -66
  94. package/presets/opencode/android-kotlin/adapter-map.json +42 -42
  95. package/presets/opencode/android-kotlin/agents/accessibility-reviewer.md +1 -1
  96. package/presets/opencode/android-kotlin/agents/api-contract-reviewer.md +1 -1
  97. package/presets/opencode/android-kotlin/agents/build-verifier.md +1 -1
  98. package/presets/opencode/android-kotlin/agents/ci-investigator.md +1 -1
  99. package/presets/opencode/android-kotlin/agents/code-reviewer.md +1 -1
  100. package/presets/opencode/android-kotlin/agents/codebase-analyzer.md +1 -1
  101. package/presets/opencode/android-kotlin/agents/debugger.md +1 -1
  102. package/presets/opencode/android-kotlin/agents/feature-developer.md +1 -1
  103. package/presets/opencode/android-kotlin/agents/instrumentation-test-generator.md +1 -1
  104. package/presets/opencode/android-kotlin/agents/instrumentation-test-healer.md +1 -1
  105. package/presets/opencode/android-kotlin/agents/instrumentation-test-planner.md +1 -1
  106. package/presets/opencode/android-kotlin/agents/migration-specialist.md +1 -1
  107. package/presets/opencode/android-kotlin/agents/mockup-reviewer.md +1 -1
  108. package/presets/opencode/android-kotlin/agents/openspec-author.md +1 -1
  109. package/presets/opencode/android-kotlin/agents/performance-auditor.md +1 -1
  110. package/presets/opencode/android-kotlin/agents/qa-tester.md +1 -1
  111. package/presets/opencode/android-kotlin/agents/security-reviewer.md +1 -1
  112. package/presets/opencode/android-kotlin/agents/solution-architect.md +1 -1
  113. package/presets/opencode/android-kotlin/agents/task-analyst.md +1 -1
  114. package/presets/opencode/android-kotlin/agents/task-router.md +1 -1
  115. package/presets/opencode/android-kotlin/agents/tech-writer.md +1 -1
  116. package/presets/opencode/android-kotlin/agents/unit-test-generator.md +1 -1
  117. package/presets/opencode/android-kotlin/agents/unit-test-healer.md +1 -1
  118. package/presets/opencode/android-kotlin/agents/unit-test-planner.md +1 -1
  119. package/presets/opencode/android-kotlin/commands/task-continue.md +1 -1
  120. package/presets/opencode/android-kotlin/hooks/README.md +11 -1
  121. package/presets/opencode/android-kotlin/hooks/guard-shell-command.mjs +155 -0
  122. package/presets/opencode/android-kotlin/plugins/rule-attach/globs.json +167 -0
  123. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +5 -5
  124. package/presets/opencode/go/OPENCODE.md +5 -51
  125. package/presets/opencode/go/adapter-map.json +45 -45
  126. package/presets/opencode/go/agents/api-contract-reviewer.md +1 -1
  127. package/presets/opencode/go/agents/build-verifier.md +1 -1
  128. package/presets/opencode/go/agents/ci-investigator.md +1 -1
  129. package/presets/opencode/go/agents/code-reviewer.md +1 -1
  130. package/presets/opencode/go/agents/codebase-analyzer.md +1 -1
  131. package/presets/opencode/go/agents/debugger.md +1 -1
  132. package/presets/opencode/go/agents/feature-developer.md +1 -1
  133. package/presets/opencode/go/agents/integration-test-generator.md +1 -1
  134. package/presets/opencode/go/agents/integration-test-healer.md +1 -1
  135. package/presets/opencode/go/agents/integration-test-planner.md +1 -1
  136. package/presets/opencode/go/agents/migration-specialist.md +1 -1
  137. package/presets/opencode/go/agents/openspec-author.md +1 -1
  138. package/presets/opencode/go/agents/performance-auditor.md +1 -1
  139. package/presets/opencode/go/agents/qa-tester.md +1 -1
  140. package/presets/opencode/go/agents/security-reviewer.md +1 -1
  141. package/presets/opencode/go/agents/solution-architect.md +1 -1
  142. package/presets/opencode/go/agents/task-analyst.md +1 -1
  143. package/presets/opencode/go/agents/task-router.md +1 -1
  144. package/presets/opencode/go/agents/tech-writer.md +1 -1
  145. package/presets/opencode/go/agents/unit-test-generator.md +1 -1
  146. package/presets/opencode/go/agents/unit-test-healer.md +1 -1
  147. package/presets/opencode/go/agents/unit-test-planner.md +1 -1
  148. package/presets/opencode/go/commands/task-continue.md +1 -1
  149. package/presets/opencode/go/hooks/README.md +11 -1
  150. package/presets/opencode/go/hooks/guard-shell-command.mjs +154 -0
  151. package/presets/opencode/go/plugins/rule-attach/globs.json +198 -0
  152. package/presets/opencode/go/rules/agent-team-orchestrator.md +5 -5
  153. package/presets/opencode/ios-swift/OPENCODE.md +5 -66
  154. package/presets/opencode/ios-swift/adapter-map.json +41 -41
  155. package/presets/opencode/ios-swift/agents/accessibility-reviewer.md +1 -1
  156. package/presets/opencode/ios-swift/agents/api-contract-reviewer.md +1 -1
  157. package/presets/opencode/ios-swift/agents/build-verifier.md +1 -1
  158. package/presets/opencode/ios-swift/agents/ci-investigator.md +1 -1
  159. package/presets/opencode/ios-swift/agents/code-reviewer.md +1 -1
  160. package/presets/opencode/ios-swift/agents/codebase-analyzer.md +1 -1
  161. package/presets/opencode/ios-swift/agents/debugger.md +1 -1
  162. package/presets/opencode/ios-swift/agents/feature-developer.md +1 -1
  163. package/presets/opencode/ios-swift/agents/migration-specialist.md +1 -1
  164. package/presets/opencode/ios-swift/agents/mockup-reviewer.md +1 -1
  165. package/presets/opencode/ios-swift/agents/openspec-author.md +1 -1
  166. package/presets/opencode/ios-swift/agents/performance-auditor.md +1 -1
  167. package/presets/opencode/ios-swift/agents/qa-tester.md +1 -1
  168. package/presets/opencode/ios-swift/agents/security-reviewer.md +1 -1
  169. package/presets/opencode/ios-swift/agents/solution-architect.md +1 -1
  170. package/presets/opencode/ios-swift/agents/task-analyst.md +1 -1
  171. package/presets/opencode/ios-swift/agents/task-router.md +1 -1
  172. package/presets/opencode/ios-swift/agents/tech-writer.md +1 -1
  173. package/presets/opencode/ios-swift/agents/unit-test-generator.md +1 -1
  174. package/presets/opencode/ios-swift/agents/unit-test-healer.md +1 -1
  175. package/presets/opencode/ios-swift/agents/unit-test-planner.md +1 -1
  176. package/presets/opencode/ios-swift/agents/xcuitest-test-generator.md +1 -1
  177. package/presets/opencode/ios-swift/agents/xcuitest-test-healer.md +1 -1
  178. package/presets/opencode/ios-swift/agents/xcuitest-test-planner.md +1 -1
  179. package/presets/opencode/ios-swift/commands/task-continue.md +1 -1
  180. package/presets/opencode/ios-swift/hooks/README.md +11 -1
  181. package/presets/opencode/ios-swift/hooks/guard-shell-command.mjs +154 -0
  182. package/presets/opencode/ios-swift/plugins/rule-attach/globs.json +160 -0
  183. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +5 -5
  184. package/presets/opencode/java/OPENCODE.md +5 -58
  185. package/presets/opencode/java/adapter-map.json +45 -45
  186. package/presets/opencode/java/agents/api-contract-reviewer.md +1 -1
  187. package/presets/opencode/java/agents/build-verifier.md +1 -1
  188. package/presets/opencode/java/agents/ci-investigator.md +1 -1
  189. package/presets/opencode/java/agents/code-reviewer.md +1 -1
  190. package/presets/opencode/java/agents/codebase-analyzer.md +1 -1
  191. package/presets/opencode/java/agents/debugger.md +1 -1
  192. package/presets/opencode/java/agents/feature-developer.md +1 -1
  193. package/presets/opencode/java/agents/integration-test-generator.md +1 -1
  194. package/presets/opencode/java/agents/integration-test-healer.md +1 -1
  195. package/presets/opencode/java/agents/integration-test-planner.md +1 -1
  196. package/presets/opencode/java/agents/migration-specialist.md +1 -1
  197. package/presets/opencode/java/agents/openspec-author.md +1 -1
  198. package/presets/opencode/java/agents/performance-auditor.md +1 -1
  199. package/presets/opencode/java/agents/qa-tester.md +1 -1
  200. package/presets/opencode/java/agents/security-reviewer.md +1 -1
  201. package/presets/opencode/java/agents/solution-architect.md +1 -1
  202. package/presets/opencode/java/agents/task-analyst.md +1 -1
  203. package/presets/opencode/java/agents/task-router.md +1 -1
  204. package/presets/opencode/java/agents/tech-writer.md +1 -1
  205. package/presets/opencode/java/agents/unit-test-generator.md +1 -1
  206. package/presets/opencode/java/agents/unit-test-healer.md +1 -1
  207. package/presets/opencode/java/agents/unit-test-planner.md +1 -1
  208. package/presets/opencode/java/commands/task-continue.md +1 -1
  209. package/presets/opencode/java/hooks/README.md +11 -1
  210. package/presets/opencode/java/hooks/guard-shell-command.mjs +155 -0
  211. package/presets/opencode/java/plugins/rule-attach/globs.json +230 -0
  212. package/presets/opencode/java/rules/agent-team-orchestrator.md +5 -5
  213. package/presets/opencode/mcp-ts/OPENCODE.md +5 -48
  214. package/presets/opencode/mcp-ts/adapter-map.json +36 -36
  215. package/presets/opencode/mcp-ts/agents/build-verifier.md +1 -1
  216. package/presets/opencode/mcp-ts/agents/feature-developer.md +1 -1
  217. package/presets/opencode/mcp-ts/agents/security-reviewer.md +1 -1
  218. package/presets/opencode/mcp-ts/agents/solution-architect.md +1 -1
  219. package/presets/opencode/mcp-ts/agents/task-analyst.md +1 -1
  220. package/presets/opencode/mcp-ts/agents/task-router.md +1 -1
  221. package/presets/opencode/mcp-ts/commands/task-continue.md +1 -1
  222. package/presets/opencode/mcp-ts/hooks/README.md +11 -1
  223. package/presets/opencode/mcp-ts/hooks/guard-shell-command.mjs +154 -0
  224. package/presets/opencode/mcp-ts/plugins/rule-attach/globs.json +151 -0
  225. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +5 -5
  226. package/presets/opencode/mol/OPENCODE.md +5 -56
  227. package/presets/opencode/mol/adapter-map.json +31 -31
  228. package/presets/opencode/mol/agents/accessibility-reviewer.md +1 -1
  229. package/presets/opencode/mol/agents/api-contract-reviewer.md +1 -1
  230. package/presets/opencode/mol/agents/build-verifier.md +1 -1
  231. package/presets/opencode/mol/agents/ci-investigator.md +1 -1
  232. package/presets/opencode/mol/agents/code-reviewer.md +1 -1
  233. package/presets/opencode/mol/agents/codebase-analyzer.md +1 -1
  234. package/presets/opencode/mol/agents/debugger.md +1 -1
  235. package/presets/opencode/mol/agents/feature-developer.md +1 -1
  236. package/presets/opencode/mol/agents/migration-specialist.md +1 -1
  237. package/presets/opencode/mol/agents/mockup-reviewer.md +1 -1
  238. package/presets/opencode/mol/agents/openspec-author.md +1 -1
  239. package/presets/opencode/mol/agents/performance-auditor.md +1 -1
  240. package/presets/opencode/mol/agents/playwright-test-generator.md +1 -1
  241. package/presets/opencode/mol/agents/playwright-test-healer.md +1 -1
  242. package/presets/opencode/mol/agents/playwright-test-planner.md +1 -1
  243. package/presets/opencode/mol/agents/qa-tester.md +1 -1
  244. package/presets/opencode/mol/agents/security-reviewer.md +1 -1
  245. package/presets/opencode/mol/agents/solution-architect.md +1 -1
  246. package/presets/opencode/mol/agents/task-analyst.md +1 -1
  247. package/presets/opencode/mol/agents/task-router.md +1 -1
  248. package/presets/opencode/mol/agents/tech-writer.md +1 -1
  249. package/presets/opencode/mol/agents/unit-test-generator.md +1 -1
  250. package/presets/opencode/mol/agents/unit-test-healer.md +1 -1
  251. package/presets/opencode/mol/agents/unit-test-planner.md +1 -1
  252. package/presets/opencode/mol/commands/task-continue.md +1 -1
  253. package/presets/opencode/mol/hooks/README.md +11 -1
  254. package/presets/opencode/mol/hooks/guard-shell-command.mjs +153 -0
  255. package/presets/opencode/mol/plugins/rule-attach/globs.json +112 -0
  256. package/presets/opencode/mol/rules/agent-team-orchestrator.md +5 -5
  257. package/presets/opencode/next/OPENCODE.md +5 -55
  258. package/presets/opencode/next/adapter-map.json +56 -56
  259. package/presets/opencode/next/agents/accessibility-reviewer.md +1 -1
  260. package/presets/opencode/next/agents/api-contract-reviewer.md +1 -1
  261. package/presets/opencode/next/agents/build-verifier.md +3 -2
  262. package/presets/opencode/next/agents/ci-investigator.md +1 -1
  263. package/presets/opencode/next/agents/code-reviewer.md +1 -1
  264. package/presets/opencode/next/agents/codebase-analyzer.md +1 -1
  265. package/presets/opencode/next/agents/debugger.md +1 -1
  266. package/presets/opencode/next/agents/feature-developer.md +2 -2
  267. package/presets/opencode/next/agents/migration-specialist.md +1 -1
  268. package/presets/opencode/next/agents/mockup-reviewer.md +1 -1
  269. package/presets/opencode/next/agents/openspec-author.md +1 -1
  270. package/presets/opencode/next/agents/performance-auditor.md +1 -1
  271. package/presets/opencode/next/agents/playwright-test-generator.md +1 -1
  272. package/presets/opencode/next/agents/playwright-test-healer.md +1 -1
  273. package/presets/opencode/next/agents/playwright-test-planner.md +1 -1
  274. package/presets/opencode/next/agents/qa-tester.md +1 -1
  275. package/presets/opencode/next/agents/security-reviewer.md +1 -1
  276. package/presets/opencode/next/agents/solution-architect.md +1 -1
  277. package/presets/opencode/next/agents/task-analyst.md +1 -1
  278. package/presets/opencode/next/agents/task-router.md +1 -1
  279. package/presets/opencode/next/agents/tech-writer.md +1 -1
  280. package/presets/opencode/next/agents/unit-test-generator.md +1 -1
  281. package/presets/opencode/next/agents/unit-test-healer.md +1 -1
  282. package/presets/opencode/next/agents/unit-test-planner.md +1 -1
  283. package/presets/opencode/next/commands/task-continue.md +1 -1
  284. package/presets/opencode/next/hooks/README.md +11 -1
  285. package/presets/opencode/next/hooks/guard-shell-command.mjs +153 -0
  286. package/presets/opencode/next/plugins/rule-attach/globs.json +276 -0
  287. package/presets/opencode/next/rules/agent-team-orchestrator.md +5 -5
  288. package/presets/opencode/nuxt/OPENCODE.md +5 -54
  289. package/presets/opencode/nuxt/adapter-map.json +51 -51
  290. package/presets/opencode/nuxt/agents/accessibility-reviewer.md +1 -1
  291. package/presets/opencode/nuxt/agents/api-contract-reviewer.md +1 -1
  292. package/presets/opencode/nuxt/agents/build-verifier.md +1 -1
  293. package/presets/opencode/nuxt/agents/ci-investigator.md +1 -1
  294. package/presets/opencode/nuxt/agents/code-reviewer.md +1 -1
  295. package/presets/opencode/nuxt/agents/codebase-analyzer.md +1 -1
  296. package/presets/opencode/nuxt/agents/debugger.md +1 -1
  297. package/presets/opencode/nuxt/agents/feature-developer.md +1 -1
  298. package/presets/opencode/nuxt/agents/migration-specialist.md +1 -1
  299. package/presets/opencode/nuxt/agents/mockup-reviewer.md +1 -1
  300. package/presets/opencode/nuxt/agents/openspec-author.md +1 -1
  301. package/presets/opencode/nuxt/agents/performance-auditor.md +1 -1
  302. package/presets/opencode/nuxt/agents/playwright-test-generator.md +1 -1
  303. package/presets/opencode/nuxt/agents/playwright-test-healer.md +1 -1
  304. package/presets/opencode/nuxt/agents/playwright-test-planner.md +1 -1
  305. package/presets/opencode/nuxt/agents/qa-tester.md +1 -1
  306. package/presets/opencode/nuxt/agents/security-reviewer.md +1 -1
  307. package/presets/opencode/nuxt/agents/solution-architect.md +1 -1
  308. package/presets/opencode/nuxt/agents/task-analyst.md +1 -1
  309. package/presets/opencode/nuxt/agents/task-router.md +1 -1
  310. package/presets/opencode/nuxt/agents/tech-writer.md +1 -1
  311. package/presets/opencode/nuxt/agents/unit-test-generator.md +1 -1
  312. package/presets/opencode/nuxt/agents/unit-test-healer.md +1 -1
  313. package/presets/opencode/nuxt/agents/unit-test-planner.md +1 -1
  314. package/presets/opencode/nuxt/commands/task-continue.md +1 -1
  315. package/presets/opencode/nuxt/hooks/README.md +11 -1
  316. package/presets/opencode/nuxt/hooks/guard-shell-command.mjs +153 -0
  317. package/presets/opencode/nuxt/plugins/rule-attach/globs.json +266 -0
  318. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +5 -5
  319. package/presets/opencode/php-hexagonal/OPENCODE.md +5 -60
  320. package/presets/opencode/php-hexagonal/adapter-map.json +45 -45
  321. package/presets/opencode/php-hexagonal/agents/api-contract-reviewer.md +1 -1
  322. package/presets/opencode/php-hexagonal/agents/build-verifier.md +1 -1
  323. package/presets/opencode/php-hexagonal/agents/ci-investigator.md +1 -1
  324. package/presets/opencode/php-hexagonal/agents/code-reviewer.md +1 -1
  325. package/presets/opencode/php-hexagonal/agents/codebase-analyzer.md +1 -1
  326. package/presets/opencode/php-hexagonal/agents/debugger.md +1 -1
  327. package/presets/opencode/php-hexagonal/agents/feature-developer.md +1 -1
  328. package/presets/opencode/php-hexagonal/agents/integration-test-generator.md +1 -1
  329. package/presets/opencode/php-hexagonal/agents/integration-test-healer.md +1 -1
  330. package/presets/opencode/php-hexagonal/agents/integration-test-planner.md +1 -1
  331. package/presets/opencode/php-hexagonal/agents/migration-specialist.md +1 -1
  332. package/presets/opencode/php-hexagonal/agents/openspec-author.md +1 -1
  333. package/presets/opencode/php-hexagonal/agents/performance-auditor.md +1 -1
  334. package/presets/opencode/php-hexagonal/agents/qa-tester.md +1 -1
  335. package/presets/opencode/php-hexagonal/agents/security-reviewer.md +1 -1
  336. package/presets/opencode/php-hexagonal/agents/solution-architect.md +1 -1
  337. package/presets/opencode/php-hexagonal/agents/task-analyst.md +1 -1
  338. package/presets/opencode/php-hexagonal/agents/task-router.md +1 -1
  339. package/presets/opencode/php-hexagonal/agents/tech-writer.md +1 -1
  340. package/presets/opencode/php-hexagonal/agents/unit-test-generator.md +1 -1
  341. package/presets/opencode/php-hexagonal/agents/unit-test-healer.md +1 -1
  342. package/presets/opencode/php-hexagonal/agents/unit-test-planner.md +1 -1
  343. package/presets/opencode/php-hexagonal/commands/task-continue.md +1 -1
  344. package/presets/opencode/php-hexagonal/hooks/README.md +11 -1
  345. package/presets/opencode/php-hexagonal/hooks/guard-shell-command.mjs +155 -0
  346. package/presets/opencode/php-hexagonal/plugins/rule-attach/globs.json +242 -0
  347. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +5 -5
  348. package/presets/opencode/php-laravel/OPENCODE.md +5 -60
  349. package/presets/opencode/php-laravel/adapter-map.json +45 -45
  350. package/presets/opencode/php-laravel/agents/api-contract-reviewer.md +1 -1
  351. package/presets/opencode/php-laravel/agents/build-verifier.md +1 -1
  352. package/presets/opencode/php-laravel/agents/ci-investigator.md +1 -1
  353. package/presets/opencode/php-laravel/agents/code-reviewer.md +1 -1
  354. package/presets/opencode/php-laravel/agents/codebase-analyzer.md +1 -1
  355. package/presets/opencode/php-laravel/agents/debugger.md +1 -1
  356. package/presets/opencode/php-laravel/agents/feature-developer.md +1 -1
  357. package/presets/opencode/php-laravel/agents/integration-test-generator.md +1 -1
  358. package/presets/opencode/php-laravel/agents/integration-test-healer.md +1 -1
  359. package/presets/opencode/php-laravel/agents/integration-test-planner.md +1 -1
  360. package/presets/opencode/php-laravel/agents/migration-specialist.md +1 -1
  361. package/presets/opencode/php-laravel/agents/openspec-author.md +1 -1
  362. package/presets/opencode/php-laravel/agents/performance-auditor.md +1 -1
  363. package/presets/opencode/php-laravel/agents/qa-tester.md +1 -1
  364. package/presets/opencode/php-laravel/agents/security-reviewer.md +1 -1
  365. package/presets/opencode/php-laravel/agents/solution-architect.md +1 -1
  366. package/presets/opencode/php-laravel/agents/task-analyst.md +1 -1
  367. package/presets/opencode/php-laravel/agents/task-router.md +1 -1
  368. package/presets/opencode/php-laravel/agents/tech-writer.md +1 -1
  369. package/presets/opencode/php-laravel/agents/unit-test-generator.md +1 -1
  370. package/presets/opencode/php-laravel/agents/unit-test-healer.md +1 -1
  371. package/presets/opencode/php-laravel/agents/unit-test-planner.md +1 -1
  372. package/presets/opencode/php-laravel/commands/task-continue.md +1 -1
  373. package/presets/opencode/php-laravel/hooks/README.md +11 -1
  374. package/presets/opencode/php-laravel/hooks/guard-shell-command.mjs +155 -0
  375. package/presets/opencode/php-laravel/plugins/rule-attach/globs.json +232 -0
  376. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +5 -5
  377. package/presets/opencode/platform-contract.json +4 -0
  378. package/presets/opencode/plugins/output-guard/README.md +1 -1
  379. package/presets/opencode/plugins/output-guard/index.ts +8 -2
  380. package/presets/opencode/plugins/output-guard/rewrite.ts +37 -0
  381. package/presets/opencode/plugins/rule-attach/README.md +34 -0
  382. package/presets/opencode/plugins/rule-attach/attach.ts +224 -0
  383. package/presets/opencode/plugins/rule-attach/index.ts +169 -0
  384. package/presets/opencode/plugins/rule-attach/package.json +9 -0
  385. package/presets/opencode/plugins/task-status/README.md +1 -1
  386. package/presets/opencode/plugins/task-status/deepseek.ts +13 -3
  387. package/presets/opencode/plugins/task-status/task-view.ts +4 -1
  388. package/presets/opencode/plugins/task-status/tui.tsx +4 -6
  389. package/presets/opencode/plugins/task-status/types.ts +5 -1
  390. package/presets/opencode/svelte/OPENCODE.md +5 -54
  391. package/presets/opencode/svelte/adapter-map.json +51 -51
  392. package/presets/opencode/svelte/agents/accessibility-reviewer.md +1 -1
  393. package/presets/opencode/svelte/agents/api-contract-reviewer.md +1 -1
  394. package/presets/opencode/svelte/agents/build-verifier.md +1 -1
  395. package/presets/opencode/svelte/agents/ci-investigator.md +1 -1
  396. package/presets/opencode/svelte/agents/code-reviewer.md +1 -1
  397. package/presets/opencode/svelte/agents/codebase-analyzer.md +1 -1
  398. package/presets/opencode/svelte/agents/debugger.md +1 -1
  399. package/presets/opencode/svelte/agents/feature-developer.md +1 -1
  400. package/presets/opencode/svelte/agents/migration-specialist.md +1 -1
  401. package/presets/opencode/svelte/agents/mockup-reviewer.md +1 -1
  402. package/presets/opencode/svelte/agents/openspec-author.md +1 -1
  403. package/presets/opencode/svelte/agents/performance-auditor.md +1 -1
  404. package/presets/opencode/svelte/agents/playwright-test-generator.md +1 -1
  405. package/presets/opencode/svelte/agents/playwright-test-healer.md +1 -1
  406. package/presets/opencode/svelte/agents/playwright-test-planner.md +1 -1
  407. package/presets/opencode/svelte/agents/qa-tester.md +1 -1
  408. package/presets/opencode/svelte/agents/security-reviewer.md +1 -1
  409. package/presets/opencode/svelte/agents/solution-architect.md +1 -1
  410. package/presets/opencode/svelte/agents/task-analyst.md +1 -1
  411. package/presets/opencode/svelte/agents/task-router.md +1 -1
  412. package/presets/opencode/svelte/agents/tech-writer.md +1 -1
  413. package/presets/opencode/svelte/agents/unit-test-generator.md +1 -1
  414. package/presets/opencode/svelte/agents/unit-test-healer.md +1 -1
  415. package/presets/opencode/svelte/agents/unit-test-planner.md +1 -1
  416. package/presets/opencode/svelte/commands/task-continue.md +1 -1
  417. package/presets/opencode/svelte/hooks/README.md +11 -1
  418. package/presets/opencode/svelte/hooks/guard-shell-command.mjs +153 -0
  419. package/presets/opencode/svelte/plugins/rule-attach/globs.json +245 -0
  420. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +5 -5
  421. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  422. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +3 -3
  423. package/presets/zcode/go/adapter-map.json +1 -1
  424. package/presets/zcode/go/rules/agent-team-orchestrator.md +3 -3
  425. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  426. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +3 -3
  427. package/presets/zcode/java/adapter-map.json +1 -1
  428. package/presets/zcode/java/rules/agent-team-orchestrator.md +3 -3
  429. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  430. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +3 -3
  431. package/presets/zcode/mol/adapter-map.json +1 -1
  432. package/presets/zcode/mol/rules/agent-team-orchestrator.md +3 -3
  433. package/presets/zcode/next/adapter-map.json +1 -1
  434. package/presets/zcode/next/agents/build-verifier.md +2 -1
  435. package/presets/zcode/next/agents/feature-developer.md +1 -1
  436. package/presets/zcode/next/rules/agent-team-orchestrator.md +3 -3
  437. package/presets/zcode/nuxt/adapter-map.json +1 -1
  438. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +3 -3
  439. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  440. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +3 -3
  441. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  442. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +3 -3
  443. package/presets/zcode/svelte/adapter-map.json +1 -1
  444. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +3 -3
  445. package/scripts/report-context-cost.mjs +1 -20
@@ -0,0 +1,224 @@
1
+ /**
2
+ * OpenCode rule attach: the pure half.
3
+ *
4
+ * The host has no path-glob rule delivery, so a rule only reaches the model if
5
+ * the agent spends a `Read` on it. This module decides *which* rule bodies a
6
+ * session earns from the files it touched, and the adapter in `index.ts` reads
7
+ * the bytes and asks the host to carry them.
8
+ *
9
+ * Three invariants, each pinned by `scripts/test-rule-attach.mjs`:
10
+ * - a stem is attached only when one of its globs matches a touched path;
11
+ * - a stem is attached at most once per session;
12
+ * - the attached bodies stay inside the `MAX_ATTACH_LINES` budget — the same
13
+ * unit and ceiling `check-next-attached-budget.mjs` caps Cursor with.
14
+ *
15
+ * The glob engine is a port of that gate's matcher (`**` crosses directories,
16
+ * `*` does not, one `{a,b}` group expands), never an import: the gate lives in
17
+ * the package, this file ships into a consumer's `.opencode/plugins/`.
18
+ */
19
+
20
+ export type RuleGlob = { stem: string; globs: string[] }
21
+
22
+ export type RuleCatalog = {
23
+ schemaVersion: number
24
+ source?: string
25
+ rules: RuleGlob[]
26
+ }
27
+
28
+ export const MARKER = "[ai-rules rule-attach]"
29
+
30
+ /** `check-next-attached-budget.mjs` FIXTURES: UI 420 / STORE 400 / API 400 / APP 261 / E2E 258 / UNIT 218 / CONFIG 135. */
31
+ export const MAX_ATTACH_LINES = 420
32
+
33
+ export const RULE_ATTACH_ENV = "AI_RULES_RULE_ATTACH"
34
+
35
+ /** Kill switch, same contract as the output guard's `AI_RULES_OUTPUT_GUARD=0`. */
36
+ export const ruleAttachEnabled = (env: Record<string, string | undefined> = process.env): boolean =>
37
+ env[RULE_ATTACH_ENV] !== "0"
38
+
39
+ const expandBraces = (glob: string): string[] => {
40
+ const match = glob.match(/\{([^{}]+)\}/)
41
+ if (!match || match.index === undefined) return [glob]
42
+ const prefix = glob.slice(0, match.index)
43
+ const suffix = glob.slice(match.index + match[0].length)
44
+ return match[1].split(",").map((alternative) => `${prefix}${alternative}${suffix}`)
45
+ }
46
+
47
+ const globToRegExp = (glob: string): RegExp => {
48
+ let source = "^"
49
+ for (let index = 0; index < glob.length; index += 1) {
50
+ if (glob.startsWith("**/", index)) {
51
+ source += "(?:.*/)?"
52
+ index += 2
53
+ continue
54
+ }
55
+ if (glob.startsWith("**", index)) {
56
+ source += ".*"
57
+ index += 1
58
+ continue
59
+ }
60
+ if (glob[index] === "*") {
61
+ source += "[^/]*"
62
+ continue
63
+ }
64
+ if ("\\^$+?.()|[]{}".includes(glob[index])) source += `\\${glob[index]}`
65
+ else source += glob[index]
66
+ }
67
+ return new RegExp(`${source}$`)
68
+ }
69
+
70
+ const matchGlobs = (globs: string[], file: string): boolean =>
71
+ globs.some((glob) => expandBraces(glob).some((expanded) => globToRegExp(expanded).test(file)))
72
+
73
+ /** Stems whose glob table matches a repo-relative path, in catalog order. */
74
+ export const matchStems = (rules: RuleGlob[], file: string): string[] =>
75
+ rules.filter((rule) => rule.globs.length > 0 && matchGlobs(rule.globs, file)).map((rule) => rule.stem)
76
+
77
+ /** Non-empty lines, the unit `check-next-attached-budget.mjs` charges. */
78
+ export const nonemptyLines = (text: string): number =>
79
+ text.split("\n").filter((line) => line.trim() !== "").length
80
+
81
+ /** One attached body: the marker names the file so a later turn can see it. */
82
+ export const renderRule = (stem: string, body: string): string =>
83
+ `${MARKER} .opencode/rules/${stem}.md\n\n${body.trimEnd()}\n`
84
+
85
+ const PATH_EXTENSION = /\.[A-Za-z0-9]{1,8}$/
86
+
87
+ /** Quoted or bare shell tokens. A quoted sentence stays one token. */
88
+ export function shellTokens(command: string): string[] {
89
+ const tokens: string[] = []
90
+ const pattern = /"([^"]*)"|'([^']*)'|`([^`]*)`|(\S+)/g
91
+ for (let match = pattern.exec(command); match !== null; match = pattern.exec(command)) {
92
+ const token = match[1] ?? match[2] ?? match[3] ?? match[4] ?? ""
93
+ if (token !== "") tokens.push(token)
94
+ }
95
+ return tokens
96
+ }
97
+
98
+ /**
99
+ * Path-like tokens in a shell command. No process is spawned. A token counts
100
+ * when it contains `/` or a short extension. A quoted sentence that contains
101
+ * spaces does not. Flags, URLs, and `$vars` do not, including the value of
102
+ * `NAME=$var`.
103
+ */
104
+ export function shellPaths(command: string): string[] {
105
+ const paths: string[] = []
106
+ for (const token of shellTokens(command)) {
107
+ if (token.startsWith("-") || token.includes("://") || token.startsWith("$")) continue
108
+ const value = /^[A-Za-z_][A-Za-z0-9_]*=/.test(token) ? token.slice(token.indexOf("=") + 1) : token
109
+ if (value === "" || value.startsWith("-") || value.startsWith("$") || value.includes("://") || /\s/.test(value)) continue
110
+ if (!value.includes("/") && !PATH_EXTENSION.test(value)) continue
111
+ paths.push(value.replace(/^\.\//, ""))
112
+ }
113
+ return paths
114
+ }
115
+
116
+ /**
117
+ * A repo-relative path for a tool target. An absolute path outside the project
118
+ * root reads as `null`: a glob never matches a file the glob table cannot name.
119
+ */
120
+ export function toRepoPath(target: unknown, root: string): string | null {
121
+ if (typeof target !== "string" || target.trim() === "") return null
122
+ const normalized = target.replace(/\\/g, "/")
123
+ const base = root.replace(/\\/g, "/").replace(/\/+$/, "")
124
+ if (normalized === base) return ""
125
+ if (normalized.startsWith(`${base}/`)) return normalized.slice(base.length + 1)
126
+ if (normalized.startsWith("/")) return null
127
+ return normalized.replace(/^\.\//, "")
128
+ }
129
+
130
+ export type SkippedRule = { stem: string; reason: "attached" | "unreadable" | "cap" }
131
+
132
+ export type AttachPlan = {
133
+ inject: Array<{ stem: string; text: string; lines: number }>
134
+ skipped: SkippedRule[]
135
+ }
136
+
137
+ /**
138
+ * The attach decision for one turn: candidates from every touched path, minus
139
+ * the stems this session already carries, stopping at the line budget.
140
+ *
141
+ * A stem that does not fit the remaining budget is skipped, never truncated —
142
+ * half a rule is the failure mode the output guard was fixed for.
143
+ */
144
+ export function planAttachment({
145
+ paths,
146
+ catalog,
147
+ attached,
148
+ readRule,
149
+ maxLines = MAX_ATTACH_LINES,
150
+ }: {
151
+ paths: readonly string[]
152
+ catalog: RuleCatalog
153
+ attached: ReadonlySet<string>
154
+ readRule: (stem: string) => string | null
155
+ maxLines?: number
156
+ }): AttachPlan {
157
+ const inject: AttachPlan["inject"] = []
158
+ const skipped: SkippedRule[] = []
159
+ const seen = new Set<string>()
160
+ let used = 0
161
+ for (const file of paths) {
162
+ for (const stem of matchStems(catalog.rules, file)) {
163
+ if (seen.has(stem)) continue
164
+ seen.add(stem)
165
+ if (attached.has(stem)) {
166
+ skipped.push({ stem, reason: "attached" })
167
+ continue
168
+ }
169
+ const body = readRule(stem)
170
+ if (body === null) {
171
+ skipped.push({ stem, reason: "unreadable" })
172
+ continue
173
+ }
174
+ const lines = nonemptyLines(body)
175
+ if (lines === 0) {
176
+ skipped.push({ stem, reason: "unreadable" })
177
+ continue
178
+ }
179
+ if (used + lines > maxLines) {
180
+ skipped.push({ stem, reason: "cap" })
181
+ continue
182
+ }
183
+ used += lines
184
+ inject.push({ stem, text: renderRule(stem, body), lines })
185
+ }
186
+ }
187
+ return { inject, skipped }
188
+ }
189
+
190
+ /** A stem is a file name, never a path: `path.join(rulesDir, stem + ".md")` must stay inside it. */
191
+ export const RULE_STEM_PATTERN = /^[a-z0-9][a-z0-9-]*$/
192
+
193
+ /**
194
+ * Parse the shipped catalog; a malformed file yields an empty table, never a
195
+ * throw. A stem that is not a plain rule name is dropped, because it would
196
+ * otherwise resolve a rule body outside `rules/`.
197
+ */
198
+ export function parseCatalog(text: string, onInvalidStem?: (stem: string) => void): RuleCatalog {
199
+ let parsed: unknown
200
+ try {
201
+ parsed = JSON.parse(text)
202
+ } catch {
203
+ return { schemaVersion: 0, rules: [] }
204
+ }
205
+ const record = (parsed ?? {}) as { schemaVersion?: unknown; source?: unknown; rules?: unknown }
206
+ const rules: RuleGlob[] = []
207
+ for (const entry of Array.isArray(record.rules) ? record.rules : []) {
208
+ const row = (entry ?? {}) as { stem?: unknown; globs?: unknown }
209
+ if (typeof row.stem !== "string" || row.stem === "") continue
210
+ if (!RULE_STEM_PATTERN.test(row.stem)) {
211
+ onInvalidStem?.(row.stem)
212
+ continue
213
+ }
214
+ const globs = (Array.isArray(row.globs) ? row.globs : []).filter(
215
+ (glob): glob is string => typeof glob === "string" && glob !== "",
216
+ )
217
+ rules.push({ stem: row.stem, globs })
218
+ }
219
+ return {
220
+ schemaVersion: typeof record.schemaVersion === "number" ? record.schemaVersion : 0,
221
+ ...(typeof record.source === "string" ? { source: record.source } : {}),
222
+ rules,
223
+ }
224
+ }
@@ -0,0 +1,169 @@
1
+ /**
2
+ * OpenCode rule attach: the host adapter.
3
+ *
4
+ * The host dispatches `ctx.session.hook("context")` with the assembled messages
5
+ * before dispatch. That payload already carries the session's tool calls, so the
6
+ * adapter walks it for a target path instead of registering an event the bridge
7
+ * never fires (`tool.execute.after` is internal-only on v2.4.1).
8
+ *
9
+ * Three bounds, all in `attach.ts`: only a stem whose glob matches a touched
10
+ * path is attached, each stem once per session, and the bodies stay inside the
11
+ * line budget. `AI_RULES_RULE_ATTACH=0` disables the plugin; debug output goes
12
+ * to `.ai.local/team/output-guard/debug.log` through `AI_RULES_RULE_ATTACH_DEBUG=1`.
13
+ *
14
+ * Injected text is a trailing user message carrying `[ai-rules rule-attach]`
15
+ * and the rule body. It carries text only — no shell, no `child_process`, and
16
+ * nothing the model wrote is executed. A host without `ctx.session.hook` no-ops,
17
+ * the same degradation contract as the output guard.
18
+ */
19
+ import fs from "node:fs"
20
+ import path from "node:path"
21
+ import { Plugin } from "@opencode/plugin"
22
+ import {
23
+ MARKER,
24
+ parseCatalog,
25
+ planAttachment,
26
+ ruleAttachEnabled,
27
+ shellPaths,
28
+ toRepoPath,
29
+ type RuleCatalog,
30
+ } from "./attach.ts"
31
+
32
+ const TOOL_TARGET_KEYS = ["filePath", "path", "file"] as const
33
+ const TARGET_TOOLS = new Set(["read", "edit", "write", "grep", "glob"])
34
+
35
+ const recordOf = (value: unknown): Record<string, unknown> =>
36
+ value !== null && typeof value === "object" ? (value as Record<string, unknown>) : {}
37
+
38
+ const targetOf = (input: Record<string, unknown>): string | null => {
39
+ for (const key of TOOL_TARGET_KEYS) {
40
+ const value = input[key]
41
+ if (typeof value === "string" && value !== "") return value
42
+ }
43
+ return null
44
+ }
45
+
46
+ const SHELL_TOOLS = new Set(["bash", "shell", "sh"])
47
+
48
+ /**
49
+ * The repo-relative targets of this request's `tool-call` parts. A `tool-call`
50
+ * carries `{ type: "tool-call", name, input }`. File tools contribute their
51
+ * path field. `bash` / `shell` / `sh` contribute path tokens from the command
52
+ * string; the command is not executed.
53
+ */
54
+ const touchedPaths = (messages: unknown, projectRoot: string): string[] => {
55
+ const paths = new Set<string>()
56
+ if (!Array.isArray(messages)) return []
57
+ const add = (target: string) => {
58
+ const rel = toRepoPath(target, projectRoot)
59
+ if (rel !== null && rel !== "") paths.add(rel)
60
+ }
61
+ for (const message of messages) {
62
+ const content = recordOf(message).content
63
+ if (!Array.isArray(content)) continue
64
+ for (const item of content) {
65
+ const call = recordOf(item)
66
+ if (call.type !== "tool-call") continue
67
+ const tool = typeof call.name === "string" ? call.name : ""
68
+ const input = recordOf(call.input)
69
+ if (SHELL_TOOLS.has(tool)) {
70
+ const command = typeof input.command === "string" ? input.command : ""
71
+ for (const token of shellPaths(command)) add(token)
72
+ continue
73
+ }
74
+ if (!TARGET_TOOLS.has(tool)) continue
75
+ const target = targetOf(input)
76
+ if (target === null) continue
77
+ add(target)
78
+ }
79
+ }
80
+ return [...paths]
81
+ }
82
+
83
+ /** A message text part that already carries this stem's marker. */
84
+ const carries = (messages: unknown, stem: string): boolean => {
85
+ const needle = `${MARKER} .opencode/rules/${stem}.md`
86
+ if (!Array.isArray(messages)) return false
87
+ for (const message of messages) {
88
+ const content = recordOf(message).content
89
+ if (!Array.isArray(content)) continue
90
+ for (const part of content) {
91
+ const text = recordOf(part).text
92
+ if (typeof text === "string" && text.includes(needle)) return true
93
+ }
94
+ }
95
+ return false
96
+ }
97
+
98
+ const debugLog = (projectRoot: string, message: string): void => {
99
+ if (process.env.AI_RULES_RULE_ATTACH_DEBUG !== "1") return
100
+ try {
101
+ const dir = path.join(projectRoot, ".ai.local", "team", "output-guard")
102
+ fs.mkdirSync(dir, { recursive: true })
103
+ fs.appendFileSync(path.join(dir, "debug.log"), `${new Date().toISOString()} rule-attach ${message}\n`)
104
+ } catch {
105
+ /* an unlogged attach is still a correct attach */
106
+ }
107
+ }
108
+
109
+ export default Plugin.define({
110
+ id: "ai-rules.rule-attach",
111
+ async setup(ctx) {
112
+ try {
113
+ if (!ruleAttachEnabled()) return
114
+ if (typeof ctx.session?.hook !== "function") return
115
+ const projectRoot = path.resolve(ctx.location.directory)
116
+ const catalogFile = path.join(projectRoot, ".opencode", "plugins", "rule-attach", "globs.json")
117
+ let catalog: RuleCatalog
118
+ try {
119
+ catalog = parseCatalog(fs.readFileSync(catalogFile, "utf8"), (stem) =>
120
+ debugLog(projectRoot, `skipped catalog stem ${JSON.stringify(stem)}: not a rule name`),
121
+ )
122
+ } catch {
123
+ return
124
+ }
125
+ if (catalog.rules.length === 0) return
126
+ const rulesDir = path.join(projectRoot, ".opencode", "rules")
127
+ const attached = new Map<string, Set<string>>()
128
+
129
+ const readRule = (stem: string): string | null => {
130
+ try {
131
+ return fs.readFileSync(path.join(rulesDir, `${stem}.md`), "utf8")
132
+ } catch {
133
+ return null
134
+ }
135
+ }
136
+
137
+ await ctx.session.hook("context", async (event: unknown) => {
138
+ try {
139
+ const record = recordOf(event)
140
+ const sessionID = typeof record.sessionID === "string" ? record.sessionID : "session"
141
+ const paths = touchedPaths(record.messages, projectRoot)
142
+ if (paths.length === 0) return
143
+ const already = attached.get(sessionID) ?? new Set<string>()
144
+ const plan = planAttachment({
145
+ paths,
146
+ catalog,
147
+ attached: already,
148
+ readRule,
149
+ })
150
+ const fresh = plan.inject.filter((entry) => !carries(record.messages, entry.stem))
151
+ if (fresh.length === 0) return
152
+ for (const entry of fresh) already.add(entry.stem)
153
+ attached.set(sessionID, already)
154
+ const messages = record.messages
155
+ if (!Array.isArray(messages)) return
156
+ messages.push({
157
+ role: "user",
158
+ content: [{ type: "text", text: fresh.map((entry) => entry.text).join("\n") }],
159
+ })
160
+ debugLog(projectRoot, `attached ${fresh.map((entry) => entry.stem).join(",")} (session ${sessionID})`)
161
+ } catch (error) {
162
+ debugLog(projectRoot, `attach failed: ${error instanceof Error ? error.message : String(error)}`)
163
+ }
164
+ })
165
+ } catch {
166
+ /* a host that rejects the hook names keeps working without attach */
167
+ }
168
+ },
169
+ })
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "ai-rules-rule-attach",
3
+ "version": "0.1.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "exports": {
7
+ ".": "./index.ts"
8
+ }
9
+ }
@@ -92,7 +92,7 @@ No build, no dependencies:
92
92
 
93
93
  Relative imports carry explicit `.ts` / `.tsx` extensions. A local plugin directory resolves files rather than the package `exports` map, and an extensionless import of a `.tsx` sibling is skipped by the loader without a message.
94
94
 
95
- Do not import `solid-js` here. A local plugin resolves its own copy, and signals created by that copy are not tracked by the host renderer, so the UI renders once and never updates. Reactive state goes through `context.storage.memory`, refreshed once per second.
95
+ Do not import `solid-js` here. A local plugin resolves its own copy, and signals created by that copy are not tracked by the host renderer, so the UI renders once and never updates. Reactive state goes through `context.storage.memory`, refreshed once per second. The billing rows read `taskStore.tick` inside `content()`, so they follow that same write.
96
96
 
97
97
  ## Update
98
98
 
@@ -144,17 +144,22 @@ const loadPeakWindows = (providerName: string, root: string): readonly PeakWindo
144
144
  return peak.length > 0 ? peak : null
145
145
  }
146
146
 
147
- let cache: { key: string; atMs: number; windows: readonly PeakWindow[] } | undefined
147
+ const cache = new Map<string, { atMs: number; windows: readonly PeakWindow[] }>()
148
+
149
+ export const clearPeakWindowCache = (): void => {
150
+ cache.clear()
151
+ }
148
152
 
149
153
  const peakWindows = (providerName: string, directory: string | undefined): readonly PeakWindow[] => {
150
154
  const fallback = DEFAULT_WINDOWS[providerName] ?? []
151
155
  const root = resolveModelsRoot(directory)
152
156
  if (root === undefined) return fallback
153
157
  const key = `${providerName}|${root}`
154
- if (cache?.key === key && Date.now() - cache.atMs < MODELS_TTL_MS) return cache.windows
158
+ const hit = cache.get(key)
159
+ if (hit !== undefined && Date.now() - hit.atMs < MODELS_TTL_MS) return hit.windows
155
160
 
156
161
  const windows = loadPeakWindows(providerName, root) ?? fallback
157
- cache = { key, atMs: Date.now(), windows }
162
+ cache.set(key, { atMs: Date.now(), windows })
158
163
  return windows
159
164
  }
160
165
 
@@ -215,3 +220,8 @@ export const deepseekRate = (now: Date, directory?: string): DeepseekRate =>
215
220
 
216
221
  export const zaiRate = (now: Date, directory?: string): DeepseekRate =>
217
222
  providerRate("Z.AI", now, directory)
223
+
224
+ export const billingRates = (at: Date, directory?: string) => [
225
+ { label: "DeepSeek" as const, rate: deepseekRate(at, directory) },
226
+ { label: "Z.AI" as const, rate: zaiRate(at, directory) },
227
+ ]
@@ -781,7 +781,7 @@ const economyForSession = (root: string, sessionID: string): SessionEconomy => {
781
781
  }
782
782
 
783
783
  export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOptions) => {
784
- const [state, update] = storage.memory<TaskStore>("view", { initial: { view: undefined } })
784
+ const [state, update] = storage.memory<TaskStore>("view", { initial: { view: undefined, tick: 0 } })
785
785
  let index: PromptEntry[] = []
786
786
  let indexAt = 0
787
787
  let etaStats: EtaStats | undefined
@@ -857,6 +857,7 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
857
857
  update((draft) => {
858
858
  draft.view = undefined
859
859
  draft.economy = undefined
860
+ draft.tick = now
860
861
  })
861
862
  return
862
863
  }
@@ -874,6 +875,7 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
874
875
  update((draft) => {
875
876
  draft.view = undefined
876
877
  draft.economy = undefined
878
+ draft.tick = now
877
879
  })
878
880
  return
879
881
  }
@@ -905,6 +907,7 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
905
907
  update((draft) => {
906
908
  draft.view = view
907
909
  draft.economy = economy
910
+ draft.tick = now
908
911
  })
909
912
  logTaskDebug(
910
913
  `session=${sessionID} messages=${current.texts.length} matched=${view.slug ?? "-"} view=${view.summary}`,
@@ -1,11 +1,11 @@
1
1
  import { Plugin, usePlugin } from "@opencode/plugin/tui"
2
- import { deepseekRate, zaiRate } from "./deepseek.ts"
2
+ import { billingRates } from "./deepseek.ts"
3
3
  import { sessionEconomy } from "./economy.ts"
4
4
  import { clearPause, createTaskWatcher, engagePause, logTaskDebug } from "./task-view.ts"
5
5
  import { TaskDetails } from "./details.tsx"
6
6
  import type { TaskStore, TaskTone } from "./task-view.ts"
7
7
 
8
- let taskStore: TaskStore = { view: undefined }
8
+ let taskStore: TaskStore = { view: undefined, tick: 0 }
9
9
  let slot: { readonly sessionID?: string } | undefined
10
10
  let lastSessionKey = ""
11
11
  // Rebound in setup(); the DeepSeek rate reads the catalog under the live project directory.
@@ -25,10 +25,6 @@ const TaskSidebar = () => {
25
25
 
26
26
  const rateColor = (rate: string) =>
27
27
  rate === "peak" ? theme.text.feedback.error.base : theme.text.feedback.success.base
28
- const billingRows = [
29
- { label: "DeepSeek", rate: deepseekRate(new Date(), projectDirectory()) },
30
- { label: "Z.AI", rate: zaiRate(new Date(), projectDirectory()) },
31
- ]
32
28
 
33
29
  const toggle = () => {
34
30
  void updatePanel((draft) => {
@@ -84,6 +80,8 @@ const TaskSidebar = () => {
84
80
 
85
81
  const content = () => {
86
82
  const view = taskStore.view
83
+ const at = new Date(taskStore.tick || Date.now())
84
+ const billingRows = billingRates(at, projectDirectory())
87
85
  if (view === undefined) return null
88
86
  const economy = taskStore.economy ?? sessionEconomy("", [])
89
87
  return (
@@ -18,7 +18,11 @@ export type TaskView = {
18
18
  offline?: boolean
19
19
  }
20
20
 
21
- export type TaskStore = { view: TaskView | null | undefined; economy?: SessionEconomy }
21
+ export type TaskStore = {
22
+ view: TaskView | null | undefined
23
+ economy?: SessionEconomy
24
+ tick: number
25
+ }
22
26
 
23
27
  export type Attempt = {
24
28
  agent?: string
@@ -1,57 +1,8 @@
1
1
  # SvelteKit stack — OpenCode agent team
2
2
 
3
- Short OpenCode entry. Native discovery: `.opencode/agents/`,
4
- `.opencode/skills/`, `.opencode/commands/`. Rule files under
5
- `.opencode/rules/*.md` are **not** auto-loaded.
3
+ Docs: `docs/OPENCODE.md`.
6
4
 
7
- Root `AGENTS.md` is native always-on. Read it first, then this file.
8
-
9
- ## How to load
10
-
11
- - Essential rules: Read immediately (paths below). Do not preload the catalog.
12
- - Other rules: lazy `Read` `.opencode/rules/<stem>.md` when the task matches.
13
- - Agents: native `@name` / Task from `.opencode/agents/`.
14
- - Commands: native `/task` from `.opencode/commands/`.
15
- - After a producer receipt, run the chain by hand (`projectHooks` is `manual`): `printf '%s\n' '{"status":"completed"}' | TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh`. Agents never write `status.json` / `metrics.json`.
16
-
17
- ## Essential rules (read every turn)
18
-
19
- - `.opencode/rules/svelte-app-core.md`
20
- - `.opencode/rules/package-manager.md`
21
- - `.opencode/rules/code-quality-and-refactoring.md`
22
- - `.opencode/rules/ai-local-overlay.md`
23
-
24
- Every turn, run `list-ai-local.mjs` from the host hooks directory with the paths this step will touch, then apply the printed `.ai.local/rules/*.md` and
25
- `.ai.local/conventions.md`. Acknowledge `Using .ai.local: <rule-name>`.
26
- Guide: `docs/LOCAL-OVERLAY.md`. These essential rules are a prompt contract.
27
- `nativeProjectRules` is `no-equivalent` — do not claim engine `alwaysApply`.
28
-
29
- See `.opencode/rules/README.md` for the full catalog and loading strategy.
30
-
31
- **Platform docs:** published with the `@bonesofspring/ai-rules` package
32
- (`docs/OPENCODE.md`, `docs/OPENCODE-COMPATIBILITY.md`) — **not** copied into
33
- the consumer repo. Source: https://github.com/bonesofspring/ai-rules
34
-
35
- **Repo-root agents:** see [`AGENTS.md`](../../AGENTS.md) at the project root (cross-tool setup, commands, security, living conventions pointers).
36
-
37
- ## Quick start
38
-
39
- | Task | Where to look |
40
- |------|----------------|
41
- | Any new work task | `/task` → `commands/task.md` + `agent-team-orchestrator.md` (+ `agent-team-intake.md` on-demand) |
42
- | New end-to-end feature | skill `feature-delivery` + `feature-delivery-workflow.md` |
43
- | Stack and layers | `svelte-app-core.md` |
44
- | At implementation closure | `post-change-lint.md` (**requestable**; `build-verifier` owns the one full run; do not run it after each edit) |
45
- | Code review MR | skill `code-review` + `code-review-mr.md` |
46
- | Security (auth/forms/env) | `security-sveltekit.md` + agent `security-reviewer` |
47
- | Technical retro | `/technical-retro` + skill `technical-retro` |
48
-
49
- ## When to use `/task`
50
-
51
- - Implementation, bugfix, migration, tests, MR review, CI-fix — **prefer `/task`**.
52
- - Simple one-liner with no architecture risk — may skip the pipeline if the user explicitly asks.
53
- - “How does X work?” questions — agent `codebase-analyzer` (explain-as-is) or answer without `/task`.
54
-
55
- ## Pipeline routing
56
-
57
- Intent detection, profiles (`full` / `standard` / `light`), and default steps — **only** in `agents/task-router.md`. Schema and examples — `agents/README.md`.
5
+ - Discovery: `.opencode/{agents,skills,commands}/` native; the engine never auto-loads `.opencode/rules/*.md` — `rule-attach` attaches a glob-matched rule once per `(sessionID, stem)` (stack globs, `bash`/`shell`).
6
+ - Essentials: `opencode.json` `instructions` — svelte-app-core, package-manager, code-quality-and-refactoring, ai-local-overlay; `nativeProjectRules` is `no-equivalent`.
7
+ - Overlay: `node .opencode/hooks/list-ai-local.mjs <paths>` → `.ai.local/rules/*.md`, `.ai.local/conventions.md`, ack `Using .ai.local: <rule-name>` (`docs/LOCAL-OVERLAY.md`).
8
+ - Chain: `projectHooks` is `manual` — `printf '%s\n' '{"status":"completed"}' | TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh`.