@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.87
4
+
5
+ ### OpenCode attaches each stack's globs, and step cost stops double-counting
6
+
7
+ - **Per-stack rule catalog.** `rule-attach` `globs.json` is generated from that stack's Cursor frontmatter and installed ahead of the shared plugin tree. A Go test file matches `**/*_test.go`, not the Next unit-test glob.
8
+ - **Shell path tokens.** A `bash` / `shell` / `sh` command contributes path tokens. The command is not executed. A quoted sentence with spaces is not a path, and neither is `NAME=$var`.
9
+ - **Step cost.** Attempt windows are clipped at the next later start. Attempts that share a start (a parallel step or a ready wave) are one phase, so the row is counted once. Rows with no dedupe id stay in `unattributed` and in the totals for the host window; a session lease moves them to `excluded`. A chain invocation is a shell token that runs `chain-team-phases.sh`. When a session lease names the task, other sessions are excluded; otherwise the report says the window is the host ledger. The text table shows the attempt id.
10
+ - **Unfilled tier template.** An OpenCode install still seeds an empty `model-tiers.json`. While `tiers` and `approvedBy` are empty, the session model applies. After the map is approved, a declared tier with no mapping still stops with `model-tier-unmapped`.
11
+ - **Tooling tier.** `yarn test:tooling` lists 85 suites. The four added rows are rule-attach, the OpenCode text contract, the model-tiers seed, and the step-cost report. `release-gate` phase 2 names that count.
12
+
13
+ ## 0.2.86
14
+
15
+ ### Project entity: registry, migration 0011, seven routes, derived task attribution
16
+
17
+ - **A project record groups repositories n:m.** `team/project-registry.json` (`{version: 1, projects[], links[]}`) is the local-only, git-ignored definition of record, mirroring the repository registry: deterministic serialization, `E_PROJECTS_PARSE` on an unknown key, a duplicate id, or a link naming an unknown endpoint, an absent file an empty valid store, and one lock-guarded verb family — `team-db.mjs projects put|delete|link|unlink|list|project` under `.project-registry.lock` (5 s, `E_PROJECTS_BUSY` → 503 `E_BUSY`), kill-switch-guarded except `list`. Membership rides the pair verbs and never moves the record `revision`. (ADR 0008; change-set `2026-11-23-project-entity-repository-links`.)
18
+ - **Migration `0011-project-registry`** adds `projects` and `project_repositories` (STRICT, `PRIMARY KEY (project_id, repository_id)`, both FKs `ON DELETE CASCADE`, no `CHECK` on `status`), moves `SCHEMA_VERSION` to 11, and keeps `0009`/`0010` byte-identical. The rebuild reproduces both tables from the file alone; `repositories delete` removes the deleted repository's project links in the same child (nested `.repositories.lock` → `.project-registry.lock`) and `RepositoryDeleteResult` gains required `membersRemoved` — the resurrection guard.
19
+ - **Seven operations on three paths.** `GET|POST /api/v1/projects`, `GET|PUT|DELETE /api/v1/projects/{id}`, `POST|DELETE /api/v1/projects/{id}/repositories/{repositoryId}`: reads answer `ProjectSummary` (record + ordered `repositories[]`), writes answer `Project`, membership returns the updated summary read from the projection in the same child, a project with N members refuses `DELETE` with `409 E_PROJECT_IN_USE` and `details.memberRepositories = N`, and `force` removes memberships only. The contract pin moves as one block: 60 operations, 45 paths, 90 schemas, 60 served routes, 22 mutating routes (`check-team-db-contract.mjs --write` regenerated the checked-in document).
20
+ - **Derived task attribution.** `GET /api/v1/tasks?project=<id>` mirrors `?repository=` through one `TASK_PROJECT_FILTER` EXISTS fragment at slot `?11`, included by `listTasks` and `countTasks` only: a task belongs to a project iff it is linked to a member repository; a repository in several projects lists its tasks on all of them; `unknown`/`ambiguous` verdict tasks appear on none; a well-shaped unknown id is an empty page.
21
+ - **Engine suites** `test-team-db-{schema,project,api,concurrency}` cover the migration from empty v0 and from a v10 fixture, registry round-trip/CAS/refusals, the delete guard 0/1/many + force, rebuild equality, all seven routes, the attribution cases (paging == count), lock serialization, the nested-lock cleanup and the dangling-link refusal.
22
+
23
+ ## 0.2.85
24
+
25
+ ### The structure composite keeps the preset checks; the tooling's own 80 suites get their own entry point
26
+
27
+ - **The composite stopped running its own regression suite.** `check-preset-structure.sh` interleaved two tiers: 54 preset checks and 80 `test-*` suites that guard the preset tooling. 93 % of the 1780.9 s release rung was the second tier. The composite now runs the 54 checks only — measured 66.8 s, 105.59 s and 120.24 s on one tree, so the 1780.9 s rung becomes roughly two minutes — and `--list` prints those 54 labels. The 80 blocks moved verbatim, in their original order, to `scripts/run-tooling-tests.sh` behind `yarn test:tooling` (80 suites, 1285.8 s, one exit code). Nothing was skipped or reordered: the two skip guards travel with their blocks, and `scripts/test-structure-tier-partition.mjs` pins the partition — 54 ⊎ 80 = the 134 labels the composite used to print, disjoint, with each label's tier fixed.
28
+ - **Known failures stay declared on the side that runs them.** All five entries in `scripts/_lib/structure-known-failures.json` are test-tier labels, so the composite matches none of them: it prints `Result: OK (all hard gates passed)` and one `NOTE: 5 allowlisted suite(s) belong to the test tier (yarn test:tooling)` instead of five false `no longer fails — remove it` warnings. The `Result: OK (… 5 known failure(s) allowlisted …)` line now comes from `yarn test:tooling`, which carries the same allowlist loader and the same aggregate. A row that is in neither tier is still warned about, so deleting a check-tier entry by mistake is not silent.
29
+ - **The release gate reports four phases.** `release-gate.sh` runs `preset-structure`, `tooling-tests`, `ai-local-tests` and `product-specs-strict`, each with its own `{label, exit, seconds}` row: a red tooling suite fails the release without hiding a green preset tier. `run_phase` and the report keys are unchanged, so older reports stay readable. `AI_RULES_SKIP_HOOK_TESTS` / `AI_RULES_SKIP_PACK_TESTS` still honoured by the runner and still refused in a release run.
30
+ - **The tooling tier is locked and PR-gated.** `test:tooling` runs through `run-locked.mjs` (`--label test:tooling`), the same `preset-tree-lock` the composite holds today, so a suite never reads `presets/**` while `fix:generated` rewrites it; a direct `bash scripts/run-tooling-tests.sh` now says out loud that it holds no lock. CI gains a `tooling-suites` job whose condition comes from `check-preset-delta.mjs` (`ci-tooling-tier-gate.sh`): it runs the 80 suites only when the change-set touches `preset-tooling`, `preset-generator`, `preset-install`, `preset-engine` or `team-db`. A prose-only `preset-content` change does not: the 54-check structure job covers that diff, and `yarn release:gate` still runs the 80 before a tag. A skip is written to the job summary instead of passing silently. The `check` job's inert `AI_RULES_SKIP_HOOK_TESTS` was dropped — the composite holds no hook blocks any more.
31
+ - **A preset-content edit names the gates that read the changed file.** `check-preset-delta.mjs` keeps a six-gate floor (twin map, twin drift, generated drift, token budget, leakage, frontmatter) and adds a path slice for agents, hooks, commands/skills, next rules, the router, plan, goal, language, or prompt. Semantic parity runs only when `feature-delivery-workflow` or `reference-features` changes. A hook edit also names hook-body-parity and the pause, stale-attempt, and resume-blocked suites. A checker edit runs that checker and its paired suite. `presets/cursor/next` and root `.cursor` name `check-dogfood-cursor`. `release:gate` is listed only for a `package.json` or `CHANGELOG.md` edit. This repository's app gates do not name `yarn test:e2e`. The structure composite drops the authoring-advisory and product-specs WARN rows (52 labels); strict product-specs stays on `yarn release:gate`. `validation-report.md` must contain `## AC evidence`. A hook edit also names chain-hook coverage and hook-token lock, a router edit names parallel-plan, and preset prose names hard i18n. `test-cli-init-clean` stays on install and generator changes. `check-task-repositories` runs when its script, its test, `repositories.json`, or a `pipeline.json` changes. `yarn preset:loop` is `fix:generated` then `check:classified`, which runs that list (or `check:fast` when it is empty) and does not run release or app gates. A stale allowlist row exits 1. `check:fast` includes twin map and leakage. `cli-mcp-merge` expects the shipped `.minimax` skills and hooks.
32
+
3
33
  ## 0.2.84
4
34
 
5
35
  ### A 25-minute gate that stops at the first failure, names known ones, and survives two runs at once
@@ -97,6 +97,10 @@ const ENGINE_SCRIPTS = [
97
97
  'check-verification.mjs',
98
98
  // Append-only incident registry: recurrence threshold, promotion gate, advice.
99
99
  'incidents.mjs',
100
+ // Per-phase step cost for one task: turns, calls by tool and chain
101
+ // invocations, grouped by the attempt windows `metrics.json` records. Reads
102
+ // the output-guard ledgers and writes nothing, so it ships with the engine.
103
+ 'report-step-cost.mjs',
100
104
  ];
101
105
 
102
106
  /** Package `presets/`-relative directory holding the engine source of truth. */
@@ -422,6 +422,36 @@ function copyTemplates(presetTeamSrc, dest) {
422
422
  return written;
423
423
  }
424
424
 
425
+ /** The shared-asset tier map an OpenCode install seeds; other platforms pin in frontmatter. */
426
+ function modelTiersTemplate(presetTeamSrc) {
427
+ return path.resolve(path.dirname(presetTeamSrc), '..', '..', '_shared', 'assets', 'model-tiers.json');
428
+ }
429
+
430
+ /**
431
+ * Seed `.ai.local/team/model-tiers.json` for an OpenCode install, absent-only.
432
+ *
433
+ * The map names provider model ids only the consumer can approve, so this is
434
+ * the same contract as the research data beside it: a re-init never rewrites a
435
+ * file the consumer has filled in.
436
+ *
437
+ * @returns {string | null} the rel this call wrote
438
+ */
439
+ function seedModelTiers(presetTeamSrc, dest, source) {
440
+ if (!presetTeamSrc || typeof source !== 'string' || !source.startsWith('opencode/')) {
441
+ return null;
442
+ }
443
+ const template = modelTiersTemplate(presetTeamSrc);
444
+ if (!fs.existsSync(template)) {
445
+ return null;
446
+ }
447
+ const target = path.join(dest, 'model-tiers.json');
448
+ if (fs.existsSync(target)) {
449
+ return null;
450
+ }
451
+ copyFile(template, target);
452
+ return '.ai.local/team/model-tiers.json';
453
+ }
454
+
425
455
  /**
426
456
  * Seed `.ai.local/conventions.md` (the living-conventions file the overlay probes)
427
457
  * from the preset template. Never overwrites an existing consumer file.
@@ -704,7 +734,7 @@ function migrateLegacyTeams(cwd, dest) {
704
734
  *
705
735
  * @returns {Map<string, Buffer>} rel → template bytes
706
736
  */
707
- function templateEntries(presetTeamSrc) {
737
+ function templateEntries(presetTeamSrc, source) {
708
738
  const out = new Map();
709
739
  const addFile = (rel, abs) => {
710
740
  let stat;
@@ -752,6 +782,11 @@ function templateEntries(presetTeamSrc) {
752
782
  addFile(`.ai.local/scripts/${name}`, path.join(engineDir, name));
753
783
  }
754
784
  }
785
+ // OpenCode resolves a tier through the map; the file is a template byte there
786
+ // so a consumer edit reports drift instead of being rewritten by a re-init.
787
+ if (typeof source === 'string' && source.startsWith('opencode/')) {
788
+ addFile('.ai.local/team/model-tiers.json', modelTiersTemplate(presetTeamSrc));
789
+ }
755
790
  out.set('.ai.local/.gitignore', Buffer.from(AI_LOCAL_GITIGNORE));
756
791
  return out;
757
792
  }
@@ -817,6 +852,7 @@ function seedAiLocalTeam({ cwd, presetTeamSrc, source, packageVersion, mergeAiLo
817
852
  ];
818
853
  const migrated = migrateLegacyTeams(cwd, dest);
819
854
  const templateWritten = copyTemplates(presetTeamSrc, dest);
855
+ const modelTiersRel = seedModelTiers(presetTeamSrc, dest, source);
820
856
  const conventionsRel = seedConventions(presetTeamSrc, cwd);
821
857
  const rulesSeed = seedAiLocalRules(presetTeamSrc, cwd);
822
858
  const rulesLibrarySeeded = rulesSeed.seeded;
@@ -826,6 +862,7 @@ function seedAiLocalTeam({ cwd, presetTeamSrc, source, packageVersion, mergeAiLo
826
862
 
827
863
  const written = [
828
864
  ...templateWritten,
865
+ ...(modelTiersRel ? [modelTiersRel] : []),
829
866
  ...(conventionsRel ? [conventionsRel] : []),
830
867
  ...rulesSeed.written,
831
868
  ...engine.written,
@@ -834,7 +871,7 @@ function seedAiLocalTeam({ cwd, presetTeamSrc, source, packageVersion, mergeAiLo
834
871
  runTemplateDrift({
835
872
  cwd,
836
873
  written,
837
- templates: templateEntries(presetTeamSrc),
874
+ templates: templateEntries(presetTeamSrc, source),
838
875
  source,
839
876
  packageVersion,
840
877
  mergeAiLocal,
@@ -98,8 +98,9 @@ function buildPlan({ contract, sourceBase, sharedSourceBase, cwd }) {
98
98
  }
99
99
  }
100
100
 
101
- // Shared platform assets (for example the TUI plugins) live beside the stack
102
- // directories, so every released preset installs the same copy.
101
+ // Stack directory mappings run first. A stack `plugins/rule-attach/globs.json`
102
+ // therefore wins over the shared plugin tree; every other plugin file still
103
+ // comes from the shared copy.
103
104
  for (const mapping of contract.sharedDirectoryMappings || []) {
104
105
  const sourceDir = path.join(sharedSourceBase, mapping.source);
105
106
  if (!fs.existsSync(sourceDir)) {
@@ -30,14 +30,14 @@ Allowed status values are `confirmed`, `partial`, `unknown`, `manual`, and `no-e
30
30
  | Explicit role file | `confirmed` | opencode.ai/docs/agents | `.opencode/agents/<name>.md` | Native `@name` / Task |
31
31
  | Deterministic structured output | `unknown` | no probe | — | Do not require a JSON schema from agents |
32
32
  | `opencode` `/init` | `unknown` | docs describe `/init`; not used by this package | TTY / interactive | Use `ai-rules init opencode` |
33
- | Project rule discovery (no reference) | `no-equivalent` | no `.opencode/rules` alwaysApply/globs engine | `.mdc` globs do not exist | Lazy `Read` from `AGENTS.md` catalog |
33
+ | Project rule discovery (no reference) | `no-equivalent` | no `.opencode/rules` alwaysApply/globs engine | `.mdc` globs do not exist | `rule-attach` plugin injects a matched stem; the four essential rules stay in `opencode.json` `instructions` |
34
34
  | Project rule discovery (explicit root reference) | `confirmed` | docs “Referencing External Files” | Agent can `Read` listed paths | Essential four rules in `AGENTS.md` |
35
35
  | Workspace agent discovery | `confirmed` | opencode.ai/docs/agents | `.opencode/agents/` | Native |
36
36
  | Workspace Skill discovery | `confirmed` | opencode.ai/docs/skills | `.opencode/skills/<name>/SKILL.md` | Native `skill` tool |
37
37
  | Project MCP | `confirmed` | opencode.ai/docs/mcp-servers | `opencode.json` `mcp` | Merge on init |
38
- | TUI plugin discovery | `confirmed` | opencode.ai/docs/plugins | `.opencode/plugins/<name>/` loads automatically | Ships `task-status` TUI sidebar |
38
+ | TUI plugin discovery | `confirmed` | opencode.ai/docs/plugins | `.opencode/plugins/<name>/` loads automatically | Ships `task-status` TUI sidebar, `output-guard`, `rule-attach` |
39
39
  | Tool-output guard (server plugin) | `confirmed` | opencode.ai/docs/build/plugins/server + live probe 2026-11-13 | `ctx.session.hook("context")` mutates assembled messages before dispatch | Ships `output-guard`; a host without the hook no-ops |
40
- | Project hooks (`hooks.json`) | `manual` | plugins exist; this preset ships a TUI viewer, not a hook plugin | No confirmed `subagentStop` analog was opened | Manual `chain-team-phases.sh` |
40
+ | Project hooks (`hooks.json`) | `manual` | probe 2026-11-25 on OpenCode v2.4.1: `ctx.session.hook` dispatches `context` / `compaction` / `generate` / `prompt` and passes other names through unvalidated to a bus nothing triggers; no `subagentStop`, and `tool.execute.after` produced 0 timing rows in 32,841 ledger rows (575 `subagent` calls) | The event that would end a step carries no attemptId | Manual `chain-team-phases.sh` |
41
41
  | Slash commands | `confirmed` | opencode.ai/docs/commands | `.opencode/commands/<name>.md` | Native `/task` |
42
42
  | Plugin / skill / MCP combo | `confirmed` | skills + mcp docs | MCP inflates context | Gate unused servers in operator config |
43
43
  | Native Team lifecycle | `partial` | file pipeline is ai-rules SoT | No native team runtime | Hook owns `status.json` / `metrics.json` |
@@ -45,9 +45,11 @@ Allowed status values are `confirmed`, `partial`, `unknown`, `manual`, and `no-e
45
45
 
46
46
  ## What we do not claim
47
47
 
48
- - Cursor `alwaysApply` / `globs` on OpenCode
48
+ - Cursor `alwaysApply` / `globs` on OpenCode (the `rule-attach` plugin reproduces the outcome, not the mechanism)
49
49
  - Claude topic-folder twins as the OpenCode source
50
50
  - Auto-registration of `hooks.json` or a hook plugin in v1
51
+ - A plugin-side `subagentStop` / `tool.execute.*` event: the name is not on the
52
+ host's plugin bus, so the chain stays manual
51
53
  - `init opencode --dry-run` / manifest preview (v1 is apply + rollback only)
52
54
  - Writes to `~/.config/opencode/**` or `~/.opencode/**`
53
55
 
package/docs/OPENCODE.md CHANGED
@@ -45,14 +45,14 @@ OpenCode has **no** `.mdc` `alwaysApply` / `globs` engine. The preset uses three
45
45
  |-----------|------|----------|
46
46
  | Root `AGENTS.md` + `.opencode/AGENTS.md` | Always-on core (essential rules + entry maps) for the **parent** | yes |
47
47
  | `opencode.json` `instructions` | Compact hedge (`alwaysOn` paths + `.opencode/AGENTS.md`) for the **parent**; re-init unions preset paths into the consumer list | V1 yes, V2 uncertain (kept narrow) |
48
- | `## Rules to load (subagent context)` block in every `.opencode/agents/*.md` | Authoritative for **subagents** (`Task`/`@name`); alwaysOn + stack zone rules filtered to existing stems | yes |
48
+ | `## Rules to load (subagent context)` block in every `.opencode/agents/*.md` | Authoritative for **subagents** (`Task`/`@name`); alwaysOn + stack zone rules filtered to existing stems. A stem `rule-attach` already attached need not be Read again | yes |
49
49
 
50
50
  `bin/opencode-install.js` `mergeOpencodeConfig` on re-init **unions** preset `instructions` paths into the existing list, **fills missing** `permission.bash` keys, and re-applies the universal `git commit` / `git push` deny rows even when the consumer file already set that key. Other bash keys stay consumer-wins. An empty `instructions: []` receives the preset paths. A non-array `instructions` value is left as-is. A top-level `policies` array is not a tool deny; re-init leaves it untouched. The v1 tool key is `bash` ([permissions](https://opencode.ai/docs/permissions/)). v2 is a different document: a `permissions` array whose action is `shell`. This preset emits the v1 object, not `permission.shell`.
51
51
 
52
52
  | Kind | How it loads |
53
53
  |------|----------------|
54
54
  | Essential rules | Root `AGENTS.md` + `.opencode/AGENTS.md` list four paths — **Read immediately** |
55
- | Other rules | Lazy `Read` of `.opencode/rules/<stem>.md` when the task matches |
55
+ | Other rules | `rule-attach` injects stems whose stack `globs.json` matches a touched path, including a path token in a `bash` or `shell` command. The catalog is that stack's Cursor `globs:`. A stem with no glob stays a lazy `Read` |
56
56
  | Agents | Native `.opencode/agents/*.md` (`@name` / Task). `mode: subagent`. Each ships the **rules-to-load block** so subagents see the always-on + zone set |
57
57
  | MCP | `opencode.json` `mcp` — preset ships context7 / playwright / chrome-devtools / figma; merge keeps extras |
58
58
  | Harness enforcement | `opencode.json` `permission.bash` — universal `git commit/push deny` + JS-stack `npm/npx/pnpm/bun ask` + `npx jest* deny`. An agent-level `permission` block can override the global map |
@@ -62,7 +62,7 @@ OpenCode has **no** `.mdc` `alwaysApply` / `globs` engine. The preset uses three
62
62
 
63
63
  **Every turn:** read root `AGENTS.md`, then `.opencode/AGENTS.md`, then the four essential rules. Probe `.ai.local` (see [`LOCAL-OVERLAY.md`](./LOCAL-OVERLAY.md)).
64
64
 
65
- Do not pin a provider model in agent frontmatter. A tier resolves through `.ai.local/team/model-tiers.json` when that file exists; otherwise the session model applies.
65
+ Do not pin a provider model in agent frontmatter. `init` seeds `.ai.local/team/model-tiers.json` absent-only with an empty `tiers` map and an empty `approvedBy`. That template is not a map yet: the session model applies. After `approvedBy` or any tier is set, a declared tier with no mapping stops the step with `model-tier-unmapped`. A re-init leaves a filled file byte-identical.
66
66
 
67
67
  ## Task pipeline (semi-auto)
68
68
 
@@ -78,7 +78,7 @@ printf '%s\n' '{"status":"completed","attemptId":"<from-status.json>"}' \
78
78
  | TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh
79
79
  ```
80
80
 
81
- Human gates pause with `awaitingHumanGate: true`. Resume with `/task-continue`. There is **no** shipped `hooks.json`; the shipped OpenCode plugins are the TUI viewer and the output guard.
81
+ Human gates pause with `awaitingHumanGate: true`. Resume with `/task-continue`. There is **no** shipped `hooks.json`: on OpenCode v2.4.1 `ctx.session.hook` dispatches `context` / `compaction` / `generate` / `prompt` only, so no plugin observes a subagent return and the chain stays a manual run. The shipped plugins are `task-status` (TUI), `output-guard` (compaction) and `rule-attach` (path-glob rule delivery).
82
82
 
83
83
  Full team layout: `.ai.local/team/README.md`.
84
84
 
@@ -90,6 +90,9 @@ dispatch. A `tool-result` over 8 KB is written to
90
90
  `.ai.local/team/output-guard/<sessionID>/outputs/` and replaced with a bounded
91
91
  head + tail. The 8–20 KB band uses the structured shape: a whole-line gap is a `sed -n` range, a mid-line cut is a `tail -c` byte window, and JSON keys are listed only when they sit in that gap. Above 20 KB stays the flat renderer.
92
92
  `AI_RULES_OUTPUT_GUARD_SHAPE=flat` forces the flat renderer inside the band.
93
+ A `read` of `.opencode/rules/**` or `.ai.local/rules/**` is never replaced: a rule
94
+ is the instruction the agent follows, and a compacted rule is a contract read at
95
+ a fraction of its bytes. Every other `read` stays guarded.
93
96
  It works for every prompt,
94
97
  including one without `/task`.
95
98
 
@@ -135,7 +138,7 @@ Labels from official OpenCode docs (live CLI probe not yet run). Full matrix: [`
135
138
  | Root `AGENTS.md` | **confirmed** (docs) | Native always-on; reference rules explicitly |
136
139
  | `.opencode/agents` / `skills` / `commands` | **confirmed** (docs) | Native discovery |
137
140
  | `opencode.json` MCP | **confirmed** (docs) | Merge `mcp` |
138
- | Glob / alwaysApply rules | **no-equivalent** | Lazy Read catalog under `.opencode/rules/` |
141
+ | Glob / alwaysApply rules | **no-equivalent** | No host glob engine; `rule-attach` injects the stems whose stack `globs.json` matches a touched path (file tools and a `bash`/`shell` path token), and a stem with no glob stays a lazy Read |
139
142
  | `hooks.json` / subagentStop | **manual** | `TEAM_TASK_SLUG=<slug> bash .opencode/hooks/chain-team-phases.sh` after receipts; the `task-status` TUI plugin is a viewer, not a hook |
140
143
  | Native Team lifecycle | **partial** | File pipeline is SoT; hook is single lifecycle writer |
141
144
 
@@ -174,7 +174,7 @@ Summary:
174
174
  - [ ] Twin drift: after editing a Claude `commands/**` or `skills/**` file, `node scripts/check-preset-twin-drift.mjs` passes — mirror the change in the Cursor twin (delta and divergence unchanged) or record a deliberate divergence with `--update`. A deliberate divergence that **raises** an allowance needs `--update --widen`; dropping a baseline row needs `--update --prune`. A plain `--update` refuses both.
175
175
  - [ ] Generated trees regenerated (`generate-claude.mjs` + `generate-mavis.mjs` + `generate-opencode.mjs` + `generate-zcode.mjs`, or `yarn fix:generated`) and CLI goldens recaptured (`capture-cli-golden.mjs`) after any preset-installed file changes
176
176
 
177
- Validation: `yarn check:task <slug>` (or `yarn check:changed` on a clean tree) + the `preset-pr-checklist` rule; the full composite runs in `yarn release:gate`. CI workflows: `preset-structure.yml` (`check`, `hooks`, `ai-local-engine-tests`), `platform-smoke.yml` (3-OS smoke: `init multi`/`update`/`doctor`, platform suites, script gate), `rule-eval.yml` (opt-in next rule-eval), and `release-gate.yml` (manual `yarn release:gate` run + report artifact).
177
+ Validation: `yarn check:task <slug>` (or `yarn check:changed` on a clean tree) + the `preset-pr-checklist` rule; the full composite runs in `yarn release:gate`. CI workflows: `preset-structure.yml` (`classify`, `check`, `tooling-suites`, `hooks`, `ai-local-engine-tests`), `platform-smoke.yml` (3-OS smoke: `init multi`/`update`/`doctor`, platform suites, script gate), `rule-eval.yml` (opt-in next rule-eval), and `release-gate.yml` (manual `yarn release:gate` run + report artifact).
178
178
 
179
179
  ## Release order
180
180
 
@@ -406,6 +406,12 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
406
406
 
407
407
  ## Dogfood & structure scripts (this monorepo)
408
408
 
409
+ Every gate in this table renders through the green/red output contract: one `ok <unit> (…)` line on
410
+ stdout, or a pointer `FAIL <unit>: <file>[:<line>]: expected X, got Y` plus a capped list and a `re-run:`
411
+ line. `scripts/lib/gate-output.mjs` (node) and `scripts/lib/gate_output.py` (the five `python3` heredocs)
412
+ own the line and block shapes, pinned byte-for-byte by `scripts/lib/gate-output.golden.json`; a new gate
413
+ uses the carrier instead of printing.
414
+
409
415
  | Script / npm | Purpose |
410
416
  |--------------|---------|
411
417
  | `yarn fix:generated` | Regenerate every released generated platform and recapture the CLI goldens it owns (`cursor/next`, `claude/next`, and every Mavis/OpenCode/ZCode stack). Claude's stack set is the Cursor stack directories, not the OpenCode contract. Run after changing Cursor SoT, before fail-only checks. Capture a non-`next` Cursor/Claude golden explicitly with `node scripts/capture-cli-golden.mjs <cursor|claude> <stack>`; never hand-edit one. Dogfood sync remains separate. |
@@ -427,7 +433,8 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
427
433
  | `scripts/check-preset-self-review-contract.sh` / `yarn check:preset-structure` | **FAIL** if the producer-side self-review / context-hygiene contract is absent: the core `_shared/core/quality/self-review-and-context-hygiene.md` tokens (G0 non-vacuous guard), the `<!-- shared-core: quality/self-review-and-context-hygiene.md -->` marker on `task-analyst` / `feature-developer` / `build-verifier` (×10) and on `debugger` / `code-reviewer` where present (skip-if-absent → `mcp-ts`), the `Self-review` + `re-anchor` tokens on every orchestrator rule, `Self-review` in `team/README.md` + `commands/task.md`, and leakage-free core + docs; **refuses vacuous PASS** when the iteration set is empty. Also holds two prose contracts: the canonical self-learning-loop sentence must not be followed by unsanctioned prose (an allowlist of sanctioned clauses; the tail is bounded by the carrier's **section**, not by a blank line, so prose moved one paragraph down still fails — a tail in a later `## ` section is out of scope), and every retro carrier (command, skill, rule) must state `finding_category`. Wired into `check-preset-structure.sh` next to `goal-contract`; fixture `test-preset-self-review-contract-fixtures.mjs`. |
428
434
  | `scripts/check-anti-hallucination-coverage.mjs` | **FAIL** when the shared contract, a Cursor load-line embed, a writer stack floor, or a generated Rules-to-load stem is missing. Writer roles are `implementer`, `unit-test`, `e2e`, `qa`, and `reviewer` (`code-reviewer` loads `STACK_FLOOR_STEMS` plus the contract). `/task` and the orchestrator must not name a floor stem. Does not scan consumer `app/**` and does not call Context7. Fixture `test-anti-hallucination-coverage.mjs` deletes `anti-hallucination-contract` from `next.reviewer` in memory and expects FAIL mentioning `next` and `reviewer`. Wired into `check-preset-structure.sh` immediately after `check-claude-agent-blocks.mjs`. |
429
435
  | `presets/_shared/ai-local/scripts/check-write-scope.mjs` | Read-only post-step audit: compares the actual changed paths with the current `pipeline.json` step's `writeScopes` and labels each path `declared`, `derived` (task folder, engine mirror, generated platform tree/golden/hook, dogfood tree, adapter map), or `out-of-scope`, with the source named. Shipped to consumers as `.ai.local/scripts/check-write-scope.mjs` (`ENGINE_SCRIPTS`). `--slug <slug> [--step <id>] [--base <ref>] [--root <project>] [--paths a,b] [--save-baseline] [--json]`. Baseline resolution: `--paths`, then `--base <ref>`, then the step baseline written by `--step <id> --save-baseline` (every dirty path with its content hash, plus the files its declared `writeScopes` cover — passed as `--paths` — so a step armed on a clean tree still owns its surface), then `HEAD` (whole uncommitted change-set, reported with a notice). Exit `1` for an out-of-scope path on an implementation step, `0` for a reviewer/verifier step (advisory), `2` on a usage/config error, `3` (SKIP) when the pipeline predates step ids or `writeScopes` and is therefore not auditable. Fixture `test-write-scope.mjs`; wired into the build-verifier and code-reviewer prompts, never a hook. |
430
- | `scripts/check-preset-structure.sh` / `yarn check:preset-structure` | Low-level orchestrator: twin-map + token-budget + leakage + shared-core drift + anti-hallucination coverage + rule-eval (**all hard**; drift via `AI_RULES_DRIFT_FAIL=1`). Invoked by `yarn release:gate` and CI; not a feature-task gate. |
436
+ | `scripts/check-preset-structure.sh` / `yarn check:preset-structure` | Low-level orchestrator: twin-map + token-budget + leakage + shared-core drift + anti-hallucination coverage + rule-eval (**all hard**; drift via `AI_RULES_DRIFT_FAIL=1`). Runs the 52 preset checks only (~2 min); `--list` prints their labels. Invoked by `yarn release:gate` and CI; not a feature-task gate. |
437
+ | `scripts/run-tooling-tests.sh` / `yarn test:tooling` | The tooling self-test tier: the 85 `test-*` suites that guard the preset tooling itself (preset fixtures, CLI install, team-db, hook lifecycle, contract guards, tooling core). One command, one exit code, ~21 min; `--list` prints the 85 labels. Reached through `run-locked.mjs --label test:tooling`, so it holds the same `preset-tree-lock` as the composite; a direct `bash` run warns that it holds none. Its failures are downgraded only by `scripts/_lib/structure-known-failures.json`, and it is the second phase of `yarn release:gate`. CI runs it from the `tooling-suites` job when the change-set touches the tooling domains (`ci-tooling-tier-gate.sh`). |
431
438
  | `scripts/check-product-specs.sh` / `yarn check:product-specs` | Opt-in consumer tree check: frontmatter v1 keys + required body headings on `docs/specs/**` (bash; does **not** run JSON Schema). Ships in the npm package `files` (`scripts/`). **WARN** by default; **`--strict`** exits non-zero. |
432
439
  | `yarn check:product-specs:dogfood` | Same script against monorepo `dogfood/mcp-ts-sample`. Soft WARN inside the composite + CI step (`continue-on-error`); the release gate runs `--strict`; not a hard consumer CI gate. |
433
440
  | `scripts/check-rule-eval.mjs` / `yarn check:rule-eval` | **Hard gate** inside `check-preset-structure.sh`: validates Incorrect/Correct pairs + `impact:` on **next-only** golden stems (`eval/next/manifest.json`). Backend / ios / php-hexagonal / php-laravel stems are out of scope until a stack adds `eval/<stack>/`. |
@@ -439,12 +446,12 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
439
446
 
440
447
  The ladder, one composite run per change-set:
441
448
 
442
- 1. **Targeted (seconds):** `node scripts/check-preset-twin-drift.mjs`, `check-claude-agent-parity.mjs`, `test-cli-init-clean.mjs`, `test-generated-cache.mjs` — a source edit that is not mirrored in the Claude twin fails here, not 25 minutes later.
449
+ 1. **Targeted (seconds):** `node scripts/check-preset-twin-drift.mjs`, `check-claude-agent-parity.mjs`, `test-cli-init-clean.mjs`, `test-generated-cache.mjs` — a source edit that is not mirrored in the Claude twin fails here, not after the ~2-minute composite, and not 21 minutes into `yarn test:tooling`.
443
450
  2. **Regenerate:** `yarn fix:generated` after a source or generator edit; it rewrites every platform stack and the CLI goldens.
444
451
  3. **Classified:** `yarn check:changed` — the classifier names the gates the change-set affects.
445
- 4. **Composite, once:** `bash scripts/check-preset-structure.sh` after the last edit. `--fail-fast` stops at the first failure the allowlist does not declare (a known one is printed and the sweep continues), `--list` prints all 134 labels, and a single gate is its own script under `scripts/` — run that directly rather than filtering the composite.
452
+ 4. **Composite, once:** `bash scripts/check-preset-structure.sh` after the last edit. `--fail-fast` stops at the first failure the allowlist does not declare (a known one is printed and the sweep continues), `--list` prints the 52 preset checks, and a single gate is its own script under `scripts/` — run that directly rather than filtering the composite. The 85 tooling self-test suites (`test-*`) run from `yarn test:tooling` (~23 min, one command, one exit code); `--list` on `scripts/run-tooling-tests.sh` prints those 85 labels. The union of the two label sets is the 137 the two entry points now carry, pinned by `test-structure-tier-partition.mjs`.
446
453
 
447
- The composite exits 0 when every failure is already listed in `scripts/_lib/structure-known-failures.json` (each entry carries owner, reason, and date); a known failure that starts passing prints a stale-entry warning. A malformed allowlist exits 2. Two runs may fill the same cache key at once — `generated-cache.mjs` publishes with one rename — while the preset-tree lock still keeps a gate away from a running `fix:generated`.
454
+ The composite exits 0 when every failure is already listed in `scripts/_lib/structure-known-failures.json` (each entry carries owner, reason, and date). A known failure that starts passing prints a stale-entry warning and the aggregate exits 1, so the row cannot hide the next regression. Both entry points read that file, but each tier reports only its own labels: the composite prints one `NOTE:` line for an allowlisted suite that belongs to the tooling tier, and `yarn test:tooling` owns the stale-entry warning for its 85. A malformed allowlist exits 2. Two runs may fill the same cache key at once — `generated-cache.mjs` publishes with one rename — while the preset-tree lock still keeps a gate away from a running `fix:generated`.
448
455
 
449
456
  Run from `packages/ai-rules/`:
450
457
 
@@ -457,19 +464,21 @@ yarn check:changed
457
464
  yarn check:fast
458
465
  # release only, from the repo root:
459
466
  yarn release:gate
467
+ # release only, the tooling self-test tier on its own:
468
+ yarn test:tooling
460
469
  ```
461
470
 
462
471
  Iteration versus release:
463
472
 
464
473
  - **`yarn check:task <slug>`** — the task-scoped classifier (`check-preset-delta.mjs --since-task <slug>`). It reads `.ai.local/team/.write-scope/<slug>/*.json`, unions the step baselines, and returns only this task's change-set; `--save-baseline` snapshots an inline task before its first write. A missing baseline falls back to `--base HEAD` with a warning.
465
474
  - **`yarn check:changed`** — the repo-wide classifier (`check-preset-delta.mjs --base HEAD`, or `--paths a,b`). Use it on a clean tree or pass the task paths explicitly; otherwise earlier uncommitted batches are attributed to this task. It prints `affected loop gates` and a separate `release-only gates` line.
466
- - **`yarn check:fast`** — the ~50-second fallback gate (`check-preset-fast.sh`: generated drift, twin drift, token budget, frontmatter, consumer links, next attached budget, OpenCode platform contract self-test); run it only when the classifier names no gate. `test-cli-init-clean` stays in the delta gates and CI.
467
- - **`yarn release:gate`** — the full release gate: `check-preset-structure.sh` with the hook suites, `test:ai-local`, and the strict product-specs dogfood. Run it alone on the release commit before a tag.
468
- - **`yarn check:preset-structure`** — the low-level composite; CI and `release:gate` call it. Do not run it in a feature task.
475
+ - **`yarn check:fast`** — the fallback gate (`check-preset-fast.sh`: the content floor — twin map, twin drift, generated drift, semantic parity, token budget, leakage, frontmatter — plus frontmatter dogfood, consumer links, next attached budget, and the OpenCode platform-contract self-test). Run it only when the classifier names no gate. A `preset-content` diff names that floor plus the path slice for the file that changed: hooks also name chain-hook coverage and hook-token lock, a router edit names parallel-plan, and preset prose names hard i18n. `test-cli-init-clean` stays on `preset-install` / `preset-generator` and in `yarn test:tooling`, not on a rule edit.
476
+ - **`yarn release:gate`** — the full release gate, four phases: `preset-structure` (the 52 preset checks), `tooling-tests` (`yarn test:tooling`, the 85 tooling suites — `AI_RULES_SKIP_HOOK_TESTS` / `AI_RULES_SKIP_PACK_TESTS` are refused), `test:ai-local`, and the strict product-specs dogfood. Each phase writes its own `exit`, so a red tooling suite fails the release without hiding a green preset tier. Run it alone on the release commit before a tag.
477
+ - **`yarn check:preset-structure`** — the low-level composite; CI and `release:gate` call it. It runs the preset tier only. Do not run it in a feature task.
469
478
 
470
479
  `check-generated-drift` caches generated trees in the OS temp directory, keyed by a digest of the Cursor/`_shared` sources and the generator libraries. A source or generator edit misses the cache and regenerates; the cache is disposable and never hides drift.
471
480
 
472
- CI: [`.github/workflows/preset-structure.yml`](../../../.github/workflows/preset-structure.yml) runs the orchestrator on PRs touching `packages/ai-rules/**`. The other workflows in `.github/workflows/`: `platform-smoke.yml` (3-OS smoke: `init multi`, `update`, `doctor`, platform suites, script gate), `rule-eval.yml` (opt-in next rule-eval via `scripts/check-rule-eval.mjs`), and `release-gate.yml` (manual `yarn release:gate` run on a chosen ref; uploads the `.release-gate/` report as an artifact).
481
+ CI: [`.github/workflows/preset-structure.yml`](../../../.github/workflows/preset-structure.yml) runs the 52 preset checks on PRs touching `packages/ai-rules/**`; its `classify` job reads the change-set domains from `check-preset-delta.mjs` and the `tooling-suites` job runs `yarn test:tooling` only when they touch `preset-tooling`, `preset-generator`, `preset-install`, `preset-engine`, or `team-db` (a prose-only `preset-content` change stays on the 52-check job; a skip is announced in the job summary). The other workflows in `.github/workflows/`: `platform-smoke.yml` (3-OS smoke: `init multi`, `update`, `doctor`, platform suites, script gate), `rule-eval.yml` (opt-in next rule-eval via `scripts/check-rule-eval.mjs`), `team-tasks-ui.yml` (lint, type-check, and unit tests for `apps/team-tasks-ui`; no e2e), and `release-gate.yml` (`yarn release:gate` on a `v*` tag or a chosen ref; uploads the `.release-gate/` report as an artifact).
473
482
 
474
483
  ---
475
484
 
@@ -478,7 +487,7 @@ CI: [`.github/workflows/preset-structure.yml`](../../../.github/workflows/preset
478
487
  `yarn fix:generated` deletes and rebuilds every platform stack, so the writer and every gate that reads `presets/**` take one exclusive lock (`scripts/lib/preset-tree-lock.mjs`; lock directory `.preset-tree-lock/` with `owner.json` pid + token). From `packages/ai-rules/`:
479
488
 
480
489
  ```bash
481
- yarn preset:loop # fix:generated && check:changed && check:fast, in series
490
+ yarn preset:loop # fix:generated && check:classified, in series
482
491
  yarn fix:generated --wait 600000 # opt in to waiting for a live holder
483
492
  ```
484
493
 
package/docs/TEAM-DB.md CHANGED
@@ -45,7 +45,8 @@ is excluded from the published tarball, and a consumer install skips it without
45
45
  envelope, or one stderr line on the CLI.
46
46
  - **Bounded mutations.** `POST /api/v1/sync` re-runs the projector and `DELETE
47
47
  /api/v1/tasks/{slug}` deletes one confirmed task (the folder first, then the rows); every
48
- other route is `GET`/`HEAD` apart from the four job writes and the three repository writes.
48
+ other route is `GET`/`HEAD` apart from the four job writes, the three repository writes and
49
+ the five project writes (create, update, delete and the two membership pairs).
49
50
  Each mutation runs as an asynchronous child process — the server never opens a writable
50
51
  connection, and the kill switch answers before a child is spawned. Job writes carry
51
52
  `application/json` and at most 64 KiB, run-now an absent body or `{}`; repository writes
@@ -481,6 +482,76 @@ cutoff is counted as legacy — the chain hook rewrites `status.json` on every s
481
482
  rewritten status never makes a legacy folder new. The slug named by `active-task.json` is
482
483
  excluded and printed, because its intake is still in flight; it is judged once the task closes.
483
484
 
485
+ ## Project registry
486
+
487
+ `team/project-registry.json` is **local-only and git-ignored**; it is the definition of record
488
+ for the project records and their n:m memberships:
489
+
490
+ ```json
491
+ {
492
+ "version": 1,
493
+ "projects": [ { "id": "emedcard", "name": "Медкарта", "description": null,
494
+ "status": "active", "revision": 1,
495
+ "createdAt": "…", "updatedAt": "…" } ],
496
+ "links": [ { "projectId": "emedcard", "repositoryId": "emedcard-web", "addedAt": "…" } ]
497
+ }
498
+ ```
499
+
500
+ `version` must be `1`; an unknown top-level key, an unknown record key, two records with one
501
+ id, a duplicate `(projectId, repositoryId)` pair, or a link naming an unknown project or
502
+ repository is a parse error (`E_PROJECTS_PARSE`) and the caller never writes over it. An
503
+ absent file is an empty valid store — `init` seeds nothing and nothing backfills from
504
+ `repositories.json`; an operator may hand-edit the file, and the reader is strict about
505
+ shapes and permissive about the `status` vocabulary. The writer serializes deterministically
506
+ (declared key order, projects by `id`, links by `(projectId, repositoryId)`, two-space indent,
507
+ one trailing newline); an unchanged rewrite performs no write.
508
+
509
+ One lock-guarded verb family serves the writes:
510
+
511
+ ```bash
512
+ node .ai.local/scripts/team-db.mjs projects put --file <path|-> [--dry-run]
513
+ node .ai.local/scripts/team-db.mjs projects delete <id> [--force] [--revision <n>]
514
+ node .ai.local/scripts/team-db.mjs projects link|unlink <projectId> <repositoryId>
515
+ node .ai.local/scripts/team-db.mjs projects list [--json]
516
+ node .ai.local/scripts/team-db.mjs projects project [--json]
517
+ ```
518
+
519
+ The order is kill switch (`list` still reads) → `.project-registry.lock` (5 s,
520
+ `E_PROJECTS_BUSY` / 503 `E_BUSY`) → read → validate and CAS → file write by temp file plus
521
+ rename → projection of the touched rows → release in `finally`. `status` is validated on
522
+ write (`active | archived`, 422 with `parameter: "status"`) and is not a SQL `CHECK`.
523
+ Membership never moves the record `revision`: the CAS token belongs to the record, and a
524
+ membership is one idempotent pair write under the lock. A project linked to N member
525
+ repositories answers `409 E_PROJECT_IN_USE` with `details.memberRepositories = N`;
526
+ `force=true` removes the record and only its membership rows in the same write and reports
527
+ `membersRemoved` — the member repositories and their tasks stay.
528
+
529
+ **Repository-delete cleanup.** Deleting a repository also removes its project links in the
530
+ same child: `repositories delete` holds `.repositories.lock` first and takes
531
+ `.project-registry.lock` second (always that nested order; project verbs never take the
532
+ repositories lock), filters the links, writes both files and projects both scopes, and
533
+ reports `membersRemoved` on `RepositoryDeleteResult`. This is the resurrection guard:
534
+ re-registering a deleted repository id never silently resurrects stale memberships.
535
+
536
+ The projection adds two tables through migration `0011-project-registry`: `projects` (the
537
+ record plus the inventory columns) and `project_repositories` (`PRIMARY KEY (project_id,
538
+ repository_id)`, both foreign keys `ON DELETE CASCADE`). A malformed file records its error
539
+ and tombstones nothing; `rm team.db* && node .ai.local/scripts/team-db.mjs init --rebuild`
540
+ reproduces both tables from the file alone.
541
+
542
+ Seven operations, three paths: `GET|POST /api/v1/projects`,
543
+ `GET|PUT|DELETE /api/v1/projects/{id}`, and
544
+ `POST|DELETE /api/v1/projects/{id}/repositories/{repositoryId}`. Reads answer
545
+ `ProjectSummary` — the record plus `repositories[]`, the member refs ordered
546
+ `name COLLATE NOCASE, id` (the count is `repositories.length`; nothing counts twice) —
547
+ writes answer `Project`, and both membership routes return the updated `ProjectSummary` so
548
+ the UI updates the section in place. The task list accepts `?project=<id>` mirroring
549
+ `?repository=`: a task belongs to a project iff it is linked to at least one member
550
+ repository (the derived attribution — no task field exists). A repository in several
551
+ projects lists its tasks on every such project page; tasks whose repository verdict is
552
+ `unknown`/`ambiguous` appear on no project page; a well-shaped unknown project id answers an
553
+ empty page, and an invalid shape is 422.
554
+
484
555
  ## Start or restart
485
556
 
486
557
  `/rr-scheduler-start` runs `node .ai.local/scripts/rr-scheduler-start.mjs`. `init` seeds that
@@ -770,8 +841,10 @@ document chunks at 1 MiB, exports at 5 MiB, parameterized SQL only, and no outbo
770
841
  `--allow-remote` also exposes the four job mutations — `POST /api/v1/jobs`,
771
842
  `PUT /api/v1/jobs/{id}`, `DELETE /api/v1/jobs/{id}`, and `POST /api/v1/jobs/{id}/run` —
772
843
  the three repository writes (`POST /api/v1/repositories`, `PUT /api/v1/repositories/{id}`,
773
- `DELETE /api/v1/repositories/{id}`), the confirmed task delete and the rescan to the named
774
- interface without authentication.
844
+ `DELETE /api/v1/repositories/{id}`), the five project writes (`POST /api/v1/projects`,
845
+ `PUT /api/v1/projects/{id}`, `DELETE /api/v1/projects/{id}`,
846
+ `POST|DELETE /api/v1/projects/{id}/repositories/{repositoryId}`), the confirmed task delete
847
+ and the rescan to the named interface without authentication.
775
848
  A job definition carries arbitrary `argv` and run-now enqueues it, so that surface
776
849
  executes operator-supplied commands as the API user; see `## Scheduled jobs`.
777
850
 
@@ -105,6 +105,26 @@ The OpenCode row counts `instructions` only; the root `AGENTS.md` is loaded nati
105
105
 
106
106
  Re-run the command for the current tree; these numbers move with any rule edit.
107
107
 
108
+ ## Step cost
109
+
110
+ Bytes are the fixed part; `report-step-cost.mjs` counts the per-run part — how
111
+ many turns and tool calls each pipeline phase spent, and how many of those calls
112
+ were the manual `chain-team-phases.sh` step:
113
+
114
+ ```bash
115
+ node .ai.local/scripts/report-step-cost.mjs --task <slug> --json
116
+ ```
117
+
118
+ The phases are the task's own `attempt_started` / `attempt_finished` windows from
119
+ `metrics.json`, clipped so they do not overlap. Attempts that share a start are
120
+ one phase. The counts are the deduped `usage.jsonl` turns and `results.jsonl`
121
+ tool calls inside each window. A row with no id stays in `unattributed` for the
122
+ host window; a session lease moves it to `excluded` with the other sessions.
123
+ With no lease the text says the window is the whole host ledger. A chain
124
+ invocation is a shell command that runs the script. A task with no ledger rows
125
+ prints zeros. Read-only, writes nothing. This is the before/after measure for
126
+ the step-count work; it is not a latency claim.
127
+
108
128
  ## Bytes are not tokens
109
129
 
110
130
  `estimatedTokens` is `Math.round(bytes / 4)` for every host. The JSON key, the human output, and this page call it an estimate. No tokenizer runs, no model is called, no session is observed.