@bonesofspring/ai-rules 0.2.70 → 0.2.72

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 (249) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/bin/lib/engine-scripts.js +9 -0
  3. package/docs/OPENCODE.md +4 -2
  4. package/docs/TEAM-DB.md +10 -7
  5. package/package.json +1 -1
  6. package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +201 -0
  7. package/presets/_shared/ai-local/scripts/incidents.mjs +452 -0
  8. package/presets/_shared/ai-local/scripts/record-usage.mjs +163 -0
  9. package/presets/_shared/ai-local/scripts/team-db-api.mjs +4 -4
  10. package/presets/_shared/ai-local/scripts/team-db-project.mjs +2 -0
  11. package/presets/_shared/ai-local/scripts/verification.mjs +374 -0
  12. package/presets/_shared/core/agent-team/agent-task-metrics.md +61 -1
  13. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +5 -4
  14. package/presets/_shared/core/agent-team/incident-registry.md +47 -0
  15. package/presets/_shared/core/architecture/feature-delivery-workflow.md +1 -1
  16. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +108 -1
  17. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +108 -1
  18. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  19. package/presets/claude/go/hooks/chain-team-phases.sh +108 -1
  20. package/presets/claude/go/rules/architecture/feature-delivery.md +1 -1
  21. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  22. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +108 -1
  23. package/presets/claude/ios-swift/rules/architecture/feature-delivery.md +1 -1
  24. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  25. package/presets/claude/java/hooks/chain-team-phases.sh +108 -1
  26. package/presets/claude/java/rules/architecture/feature-delivery.md +1 -1
  27. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  28. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +108 -1
  29. package/presets/claude/mcp-ts/rules/architecture/feature-delivery.md +1 -1
  30. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  31. package/presets/claude/mol/hooks/chain-team-phases.sh +108 -1
  32. package/presets/claude/mol/rules/architecture/feature-delivery-workflow.md +1 -1
  33. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  34. package/presets/claude/next/agents/README.md +4 -3
  35. package/presets/claude/next/agents/api-contract-reviewer.md +1 -1
  36. package/presets/claude/next/agents/mockup-reviewer.md +1 -1
  37. package/presets/claude/next/agents/task-router.md +4 -4
  38. package/presets/claude/next/hooks/chain-team-phases.sh +108 -1
  39. package/presets/claude/next/rules/architecture/feature-delivery-workflow.md +2 -2
  40. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  41. package/presets/claude/nuxt/hooks/chain-team-phases.sh +108 -1
  42. package/presets/claude/nuxt/rules/architecture/feature-delivery-workflow.md +1 -1
  43. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  44. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +108 -1
  45. package/presets/claude/php-hexagonal/rules/architecture/feature-delivery.md +1 -1
  46. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  47. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +108 -1
  48. package/presets/claude/php-laravel/rules/architecture/feature-delivery.md +1 -1
  49. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  50. package/presets/claude/svelte/hooks/chain-team-phases.sh +108 -1
  51. package/presets/claude/svelte/rules/architecture/feature-delivery-workflow.md +1 -1
  52. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +5 -4
  53. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +108 -1
  54. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
  55. package/presets/cursor/go/hooks/chain-team-phases.sh +108 -1
  56. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
  57. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +108 -1
  58. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
  59. package/presets/cursor/java/hooks/chain-team-phases.sh +108 -1
  60. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
  61. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +108 -1
  62. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
  63. package/presets/cursor/mol/hooks/chain-team-phases.sh +108 -1
  64. package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
  65. package/presets/cursor/next/agents/README.md +4 -3
  66. package/presets/cursor/next/agents/api-contract-reviewer.md +1 -1
  67. package/presets/cursor/next/agents/mockup-reviewer.md +1 -1
  68. package/presets/cursor/next/agents/task-router.md +4 -4
  69. package/presets/cursor/next/hooks/chain-team-phases.sh +108 -1
  70. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +1 -1
  71. package/presets/cursor/next/rules/feature-delivery-workflow.mdc +1 -1
  72. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +108 -1
  73. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
  74. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +108 -1
  75. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
  76. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +108 -1
  77. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
  78. package/presets/cursor/svelte/hooks/chain-team-phases.sh +108 -1
  79. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
  80. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  81. package/presets/mavis/android-kotlin/agents/README.md +3 -3
  82. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +108 -1
  83. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +5 -4
  84. package/presets/mavis/go/adapter-map.json +1 -1
  85. package/presets/mavis/go/agents/README.md +2 -2
  86. package/presets/mavis/go/hooks/chain-team-phases.sh +108 -1
  87. package/presets/mavis/go/rules/agent-team-orchestrator.md +5 -4
  88. package/presets/mavis/go/rules/feature-delivery-workflow.md +1 -1
  89. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  90. package/presets/mavis/ios-swift/agents/README.md +3 -3
  91. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +108 -1
  92. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +5 -4
  93. package/presets/mavis/ios-swift/rules/feature-delivery-workflow.md +1 -1
  94. package/presets/mavis/java/adapter-map.json +1 -1
  95. package/presets/mavis/java/agents/README.md +2 -2
  96. package/presets/mavis/java/hooks/chain-team-phases.sh +108 -1
  97. package/presets/mavis/java/rules/agent-team-orchestrator.md +5 -4
  98. package/presets/mavis/java/rules/feature-delivery-workflow.md +1 -1
  99. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  100. package/presets/mavis/mcp-ts/agents/README.md +1 -1
  101. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +108 -1
  102. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +5 -4
  103. package/presets/mavis/mcp-ts/rules/feature-delivery-workflow.md +1 -1
  104. package/presets/mavis/mol/adapter-map.json +1 -1
  105. package/presets/mavis/mol/agents/README.md +3 -3
  106. package/presets/mavis/mol/hooks/chain-team-phases.sh +108 -1
  107. package/presets/mavis/mol/rules/agent-team-orchestrator.md +5 -4
  108. package/presets/mavis/mol/rules/feature-delivery-workflow.md +1 -1
  109. package/presets/mavis/next/adapter-map.json +1 -1
  110. package/presets/mavis/next/agents/README.md +3 -3
  111. package/presets/mavis/next/agents/task-router.md +4 -4
  112. package/presets/mavis/next/hooks/chain-team-phases.sh +108 -1
  113. package/presets/mavis/next/rules/agent-team-orchestrator.md +5 -4
  114. package/presets/mavis/next/rules/feature-delivery-workflow.md +2 -2
  115. package/presets/mavis/nuxt/adapter-map.json +1 -1
  116. package/presets/mavis/nuxt/agents/README.md +3 -3
  117. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +108 -1
  118. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +5 -4
  119. package/presets/mavis/nuxt/rules/feature-delivery-workflow.md +1 -1
  120. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  121. package/presets/mavis/php-hexagonal/agents/README.md +2 -2
  122. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +108 -1
  123. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
  124. package/presets/mavis/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
  125. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  126. package/presets/mavis/php-laravel/agents/README.md +2 -2
  127. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +108 -1
  128. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +5 -4
  129. package/presets/mavis/php-laravel/rules/feature-delivery-workflow.md +1 -1
  130. package/presets/mavis/svelte/adapter-map.json +1 -1
  131. package/presets/mavis/svelte/agents/README.md +3 -3
  132. package/presets/mavis/svelte/hooks/chain-team-phases.sh +108 -1
  133. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +5 -4
  134. package/presets/mavis/svelte/rules/feature-delivery-workflow.md +1 -1
  135. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  136. package/presets/opencode/android-kotlin/agents/README.md +4 -4
  137. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +108 -1
  138. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +5 -4
  139. package/presets/opencode/go/adapter-map.json +1 -1
  140. package/presets/opencode/go/agents/README.md +3 -3
  141. package/presets/opencode/go/hooks/chain-team-phases.sh +108 -1
  142. package/presets/opencode/go/rules/agent-team-orchestrator.md +5 -4
  143. package/presets/opencode/go/rules/feature-delivery-workflow.md +1 -1
  144. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  145. package/presets/opencode/ios-swift/agents/README.md +4 -4
  146. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +108 -1
  147. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +5 -4
  148. package/presets/opencode/ios-swift/rules/feature-delivery-workflow.md +1 -1
  149. package/presets/opencode/java/adapter-map.json +1 -1
  150. package/presets/opencode/java/agents/README.md +3 -3
  151. package/presets/opencode/java/hooks/chain-team-phases.sh +108 -1
  152. package/presets/opencode/java/rules/agent-team-orchestrator.md +5 -4
  153. package/presets/opencode/java/rules/feature-delivery-workflow.md +1 -1
  154. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  155. package/presets/opencode/mcp-ts/agents/README.md +2 -2
  156. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +108 -1
  157. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +5 -4
  158. package/presets/opencode/mcp-ts/rules/feature-delivery-workflow.md +1 -1
  159. package/presets/opencode/mol/adapter-map.json +1 -1
  160. package/presets/opencode/mol/agents/README.md +4 -4
  161. package/presets/opencode/mol/hooks/chain-team-phases.sh +108 -1
  162. package/presets/opencode/mol/rules/agent-team-orchestrator.md +5 -4
  163. package/presets/opencode/mol/rules/feature-delivery-workflow.md +1 -1
  164. package/presets/opencode/next/adapter-map.json +1 -1
  165. package/presets/opencode/next/agents/README.md +4 -4
  166. package/presets/opencode/next/agents/task-router.md +4 -4
  167. package/presets/opencode/next/hooks/chain-team-phases.sh +108 -1
  168. package/presets/opencode/next/rules/agent-team-orchestrator.md +5 -4
  169. package/presets/opencode/next/rules/feature-delivery-workflow.md +2 -2
  170. package/presets/opencode/nuxt/adapter-map.json +1 -1
  171. package/presets/opencode/nuxt/agents/README.md +4 -4
  172. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +108 -1
  173. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +5 -4
  174. package/presets/opencode/nuxt/rules/feature-delivery-workflow.md +1 -1
  175. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  176. package/presets/opencode/php-hexagonal/agents/README.md +3 -3
  177. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +108 -1
  178. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
  179. package/presets/opencode/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
  180. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  181. package/presets/opencode/php-laravel/agents/README.md +3 -3
  182. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +108 -1
  183. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +5 -4
  184. package/presets/opencode/php-laravel/rules/feature-delivery-workflow.md +1 -1
  185. package/presets/opencode/plugins/output-guard/README.md +25 -4
  186. package/presets/opencode/plugins/output-guard/index.ts +57 -11
  187. package/presets/opencode/plugins/output-guard/rewrite.ts +104 -1
  188. package/presets/opencode/svelte/adapter-map.json +1 -1
  189. package/presets/opencode/svelte/agents/README.md +4 -4
  190. package/presets/opencode/svelte/hooks/chain-team-phases.sh +108 -1
  191. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +5 -4
  192. package/presets/opencode/svelte/rules/feature-delivery-workflow.md +1 -1
  193. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  194. package/presets/zcode/android-kotlin/agents/README.md +3 -3
  195. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +108 -1
  196. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +5 -4
  197. package/presets/zcode/go/adapter-map.json +1 -1
  198. package/presets/zcode/go/agents/README.md +2 -2
  199. package/presets/zcode/go/hooks/chain-team-phases.sh +108 -1
  200. package/presets/zcode/go/rules/agent-team-orchestrator.md +5 -4
  201. package/presets/zcode/go/rules/feature-delivery-workflow.md +1 -1
  202. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  203. package/presets/zcode/ios-swift/agents/README.md +3 -3
  204. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +108 -1
  205. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +5 -4
  206. package/presets/zcode/ios-swift/rules/feature-delivery-workflow.md +1 -1
  207. package/presets/zcode/java/adapter-map.json +1 -1
  208. package/presets/zcode/java/agents/README.md +2 -2
  209. package/presets/zcode/java/hooks/chain-team-phases.sh +108 -1
  210. package/presets/zcode/java/rules/agent-team-orchestrator.md +5 -4
  211. package/presets/zcode/java/rules/feature-delivery-workflow.md +1 -1
  212. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  213. package/presets/zcode/mcp-ts/agents/README.md +1 -1
  214. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +108 -1
  215. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +5 -4
  216. package/presets/zcode/mcp-ts/rules/feature-delivery-workflow.md +1 -1
  217. package/presets/zcode/mol/adapter-map.json +1 -1
  218. package/presets/zcode/mol/agents/README.md +3 -3
  219. package/presets/zcode/mol/hooks/chain-team-phases.sh +108 -1
  220. package/presets/zcode/mol/rules/agent-team-orchestrator.md +5 -4
  221. package/presets/zcode/mol/rules/feature-delivery-workflow.md +1 -1
  222. package/presets/zcode/next/adapter-map.json +1 -1
  223. package/presets/zcode/next/agents/README.md +3 -3
  224. package/presets/zcode/next/agents/task-router.md +4 -4
  225. package/presets/zcode/next/hooks/chain-team-phases.sh +108 -1
  226. package/presets/zcode/next/rules/agent-team-orchestrator.md +5 -4
  227. package/presets/zcode/next/rules/feature-delivery-workflow.md +2 -2
  228. package/presets/zcode/nuxt/adapter-map.json +1 -1
  229. package/presets/zcode/nuxt/agents/README.md +3 -3
  230. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +108 -1
  231. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +5 -4
  232. package/presets/zcode/nuxt/rules/feature-delivery-workflow.md +1 -1
  233. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  234. package/presets/zcode/php-hexagonal/agents/README.md +2 -2
  235. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +108 -1
  236. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +5 -4
  237. package/presets/zcode/php-hexagonal/rules/feature-delivery-workflow.md +1 -1
  238. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  239. package/presets/zcode/php-laravel/agents/README.md +2 -2
  240. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +108 -1
  241. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +5 -4
  242. package/presets/zcode/php-laravel/rules/feature-delivery-workflow.md +1 -1
  243. package/presets/zcode/svelte/adapter-map.json +1 -1
  244. package/presets/zcode/svelte/agents/README.md +3 -3
  245. package/presets/zcode/svelte/hooks/chain-team-phases.sh +108 -1
  246. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +5 -4
  247. package/presets/zcode/svelte/rules/feature-delivery-workflow.md +1 -1
  248. package/scripts/aggregate-agent-task-metrics.mjs +201 -0
  249. package/scripts/report-context-cost.mjs +126 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,70 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.72
4
+
5
+ ### `team` — usage ledger, verification evidence, incident registry
6
+
7
+ - **Published engine modules.** `record-usage.mjs`, `verification.mjs`, and `incidents.mjs` join `ENGINE_SCRIPTS` and are seeded into `.ai.local/scripts/`. `record-usage` was repo-local; the CLI and the metrics prose now ship together.
8
+ - **Token usage.** `attempt_finished` keeps a host `usage` object only after an allowlist (`input`, `output`, `reasoning`, `cacheRead`, `cacheWrite`, `costUsd`, `model`, `origin`). `record-usage.mjs` appends one `usage_recorded` event per observable turn. A host object wins for that attempt; the two paths are never added. A missing count stays `null`. `aggregate-agent-task-metrics.mjs` reports usage at task, agent, and model level with `reportedAttempts / attempts`.
9
+ - **Verification evidence.** `verification.mjs record` stores the command, exit code, a capped secret-redacted log tail, and a git snapshot that ignores `.ai.local/**`. `check --strict` exits 1 when that snapshot is stale and 2 when it is missing. A `build-verifier` finish without an explicit record seeds `verification.json` once (`gate.status: snapshot-only`) and never refreshes it. Closure warns and writes one `verification_stale` event; it does not block.
10
+ - **Incident registry.** `incidents.mjs` appends to `<team>/incidents.jsonl`. The signature is `scope | failure | rule`. Two occurrences in 30 days stabilize a class. `promote` requires `ci`, `test`, `lint`, or `policy-check` and writes an inactive draft under `.ai.local/rules-library/`; a human moves it into `.ai.local/rules/`. Secrets are rejected at write time. `advise` is a targeted lookup.
11
+ - **Ledger.** `usage_recorded`, `verification_recorded`, and `verification_stale` join the allowed event types.
12
+ - **Tests.** `test-verification-evidence.mjs`, `test-incidents-registry.mjs`, and `test-agent-task-metrics-usage.mjs` run inside `check-preset-structure.sh`.
13
+
14
+ ### `orchestrator` — review roles on `cheap`, session handoff
15
+
16
+ - **Tiers.** `code-reviewer`, `build-verifier`, `api-contract-reviewer`, and `mockup-reviewer` resolve as `cheap`. `feature-developer` stays `standard`. `strong` is architecture, security, migration, and performance; `mockup-reviewer` is not on `strong`. The mapped id is passed as written — do not append `#high`. Without `.ai.local/team/model-tiers.json`, those four roles omit the model and the session model applies.
17
+ - **Dogfood map.** This repository's `model-tiers.json` sets `cheap` to `deepseek/deepseek-flash#max`. `standard` stays `deepseek/deepseek-flash` with no variant.
18
+ - **Handoff.** A session approaching ~50 turns finishes the current wave, checkpoints `focus.md` + `artifact-manifest.json` + `.memlog.md`, and continues in a fresh session. A wave that cannot finish before the cap checkpoints its partial state the same way.
19
+ - **Artifact reads.** Read the manifest entry, not a completed artifact body. A large artifact is read in offset/limit ranges.
20
+
21
+ ### `opencode` — structured output-guard band and model bench
22
+
23
+ - **8–20 KB.** A replaced tool result in that band names the gap: a whole-line gap is `sed -n`, a mid-line cut (including a one-line payload) is `tail -c`, and JSON keys are listed only when they sit in the gap. Above 20 KB stays the flat head + tail. `AI_RULES_OUTPUT_GUARD_SHAPE=flat` forces the flat renderer inside the band.
24
+ - **Error results.** A `tool-result` whose type is `error` is recorded. `results.jsonl` gains optional `error: true`; absence means non-error, including rows written before the field existed. `report-context-cost.mjs` prints `readCountPerPath` and `mcpErrors`.
25
+ - **Bench.** `bench-efficiency.mjs --model-b` compares two models with the guard on and returns an `owner-gate` verdict; the harness does not choose a route. `--shape flat|structured` selects the renderer under test.
26
+
27
+ ## 0.2.71
28
+
29
+ ### `team-tasks-ui` — catalog price tiers, model metadata, notes
30
+
31
+ - **Model record.** `version`, `releasedAt`, `notes`, `price.cacheReadPer1MTokens`, and named `price.tiers` (`time` / `context` / `promotion`) join the model contract: `catalog.schema.json`, the `catalog-refresh` write validator, the app schema, DTOs, mapper, model form, and `ModelDetailPage`. The form edits the scalar fields and carries scheduler-authored tiers through unchanged; the detail page lists each tier's kind and, for a context tier, its `from N tokens` boundary.
32
+ - **Providers and windows.** `notes` is written by both catalog writers, edited on the window form, and rendered on the provider detail page.
33
+ - **Validation.** Duplicate tier names, a `minContextTokens` on a non-context tier, a cache-read price without the input/output split, an over-long `version` / `notes`, and a non-ISO `releasedAt` are refused before a file lands.
34
+ - **Refresh keeps tiers.** `writeProviderModels` merges a refreshed `price` into the stored one instead of replacing it, so a scheduler run keeps the tiers and cache-read price the feed does not carry.
35
+ - **Tests.** `catalog.mapper.spec.ts` and `schema.spec.ts` extend, `catalogModelForm.data.spec.ts` is new: the added fields, the tier rules, and the write mapping.
36
+
37
+ ### `team-tasks-ui` — window summaries in Moscow time
38
+
39
+ - **One display zone.** `windowShapeLabel` renders every window in `Europe/Moscow`: a weekly window is shifted from its own zone at `now` (a DST zone changes the shift mid-year), its weekdays move with a midnight-crossing shift, and an absolute range is formatted in Moscow. An unknown source zone falls back to the stored hours and zone instead of failing the page.
40
+ - **`formatTimestamp`** takes an optional `timeZone`; formatters are cached per zone.
41
+ - **Tests.** `windowShapeLabel.spec.ts` covers the shift, the day wrap, DST, and the unknown-zone fallback.
42
+
43
+ ### `catalog` — provider-direct pricing sync (repo-local)
44
+
45
+ - **Sync runner.** `opencode-models-sync.mjs` reconciles `.ai.local/catalog/**` from the live OpenCode provider/model feed, adds the metadata the feed omits, and writes DeepSeek peak/off-peak prices plus provider-scoped peak windows. Manual records are never overwritten, and a record the source stops naming is frozen with its last committed note.
46
+ - **Provider-direct sources.** `deepseek-pricing.mjs` and `zai-pricing.mjs` read one markdown notice each. Z.AI's documented quota multipliers are recorded as notes, never as a USD price, and a document whose duplicated statements disagree throws instead of guessing — the last committed catalog stays.
47
+ - **Schedule.** The `opencode-models-sync` job runs at 08:00 and 20:00 `Europe/Moscow` with `concurrency: skip` through the repo's scheduler.
48
+ - **Tests.** `opencode-models-sync.test.mjs`, `deepseek-pricing.test.mjs`, `zai-pricing.test.mjs`, and the extended `catalog-refresh.test.mjs` cover ownership, freezing, offline runs, and the parsers.
49
+
50
+ ### `opencode` — output-guard discovery off the hot path
51
+
52
+ - **Detached walk.** The context hook no longer awaits usage discovery. After the in-place rewrite it starts one `session.get`, then at most 12 tracked sessions with one `session.context` and one `session.list` each (≤25 RPCs), and never awaits the walk, so the tool result cannot depend on it.
53
+ - **Bounded wait.** `AI_RULES_OUTPUT_GUARD_DISCOVERY_MS` (default 250 ms) bounds how long the hook waits, not the walk: the walk keeps running and a late response still appends its row. Nothing cancels an RPC already in flight, and the plugin README states both bounds.
54
+ - **Goldens and tests.** The 11 opencode CLI goldens are recaptured for the new `README.md` / `index.ts` hashes; `test-output-guard.mjs` grows to 33 cases and covers the detached walk, the deadline, and the isolation of a failing discovery.
55
+
56
+ ### `scripts` — `measure.mjs --strict`
57
+
58
+ - **Section verdicts.** Every `sections.rN` now pairs its `reported {at,text,figures}` claim with measured `data`, a `reproduced` boolean, `unreproducible` reasons, and the section's `ordering` claim, so a consumer reads the JSON instead of the prose.
59
+ - **Exit codes.** `--strict` exits 1 on a scored out-of-band check or a failed comparable `ordering` claim, after printing the report; `referenceOnly` totals and a bare `reproduced: false` never fail. `--strict --live` is refused — a grown ledger is not a reproduction.
60
+ - **Tests.** `test-measure.mjs` covers the verdict shape, the `r4.ordering` claim, `strictFailures`, and the usage error.
61
+
62
+ ### `team-db` — delete-refusal messages stop tripping the SQL-injection rule
63
+
64
+ - **Wording.** The API fallbacks for a refused `jobs delete` / `task delete` now read `removing <id> was refused` and `removal of <slug>` instead of `the delete of …`. The old template literal placed a SQL keyword next to an interpolated `context.params` value, so Semgrep's `tainted-sql-string` rule (CWE-89) reported the error text as a SQL string built from request input; every statement in the module is a parameterized `better-sqlite3` query, which made it a false positive.
65
+ - **Unchanged contract.** Error codes from `mapTeamDbCode`, HTTP statuses, `details`, and both delete operations are untouched — only the fallback `message` text.
66
+ - **Fixtures.** The CLI golden hash snapshots are recaptured by `fix:generated` for the new `team-db-api.mjs` and `.template-base.json` digests.
67
+
3
68
  ## 0.2.70
4
69
 
5
70
  ### `next` — `/ui-start` and `/ui-stop` return
@@ -65,6 +65,15 @@ const ENGINE_SCRIPTS = [
65
65
  // Role/task metrics aggregation used by technical-retro; ships with the engine
66
66
  // so a consumer can run it from `.ai.local/scripts/` without the package.
67
67
  'aggregate-agent-task-metrics.mjs',
68
+ // Token usage per attempt: one `usage_recorded` event per observable turn.
69
+ // The host `usage` object on a receipt is the higher-precedence path; this CLI
70
+ // covers hosts that expose counts turn by turn.
71
+ 'record-usage.mjs',
72
+ // Persisted verification evidence: command + exit + capped log tail bound to a
73
+ // git snapshot, with a freshness check closure can read.
74
+ 'verification.mjs',
75
+ // Append-only incident registry: recurrence threshold, promotion gate, advice.
76
+ 'incidents.mjs',
68
77
  ];
69
78
 
70
79
  /** Package `presets/`-relative directory holding the engine source of truth. */
package/docs/OPENCODE.md CHANGED
@@ -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 model in this preset — use the operator’s OpenCode provider config.
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.
66
66
 
67
67
  ## Task pipeline (semi-auto)
68
68
 
@@ -88,7 +88,9 @@ Full team layout: `.ai.local/team/README.md`.
88
88
  `ctx.session.hook("context")`, which receives the assembled model messages before
89
89
  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
- head + tail, the path, and one `grep` / `sed` hint. It works for every prompt,
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
+ `AI_RULES_OUTPUT_GUARD_SHAPE=flat` forces the flat renderer inside the band.
93
+ It works for every prompt,
92
94
  including one without `/task`.
93
95
 
94
96
  - `AI_RULES_OUTPUT_GUARD=0` disables it; `AI_RULES_OUTPUT_GUARD_BYTES` changes the threshold.
package/docs/TEAM-DB.md CHANGED
@@ -19,10 +19,11 @@ The projection is installed by `init` as eight `team-db*.mjs` modules under `.ai
19
19
 
20
20
  The same seeded set is `ENGINE_SCRIPTS` in `bin/lib/engine-scripts.js`: the eight `team-db*.mjs`
21
21
  modules plus the self-learning engine, `manifest.mjs`, `dump-output.mjs`,
22
- `check-write-scope.mjs`, `aggregate-agent-task-metrics.mjs`, and the `processes.mjs` +
23
- `process-lease.mjs` process manager (twenty published entries;
24
- `node -e "require('./bin/lib/engine-scripts.js').SHIPPED_ENGINE_SCRIPTS.length"` prints the
25
- shipped count). One further module, `upstream-research.mjs`, is declared in
22
+ `check-write-scope.mjs`, `aggregate-agent-task-metrics.mjs`, `record-usage.mjs`,
23
+ `verification.mjs`, `incidents.mjs`, and the `processes.mjs` + `process-lease.mjs` process
24
+ manager (twenty-four published entries;
25
+ `node -e "require('./bin/lib/engine-scripts.js').ENGINE_SCRIPTS.length"` prints the shipped
26
+ count). One further module, `upstream-research.mjs`, is declared in
26
27
  `REPO_ONLY_ENGINE_SCRIPTS`: it exists in this repository's preset source and dogfood mirror but
27
28
  is excluded from the published tarball, and a consumer install skips it without a warning.
28
29
 
@@ -668,9 +669,11 @@ node scripts/test-team-db-efficiency.mjs
668
669
  planted defect, not only on the happy path. `test-team-db-efficiency.mjs` pins the v5
669
670
  telemetry plane: usage precedence, duplicate observation days, coverage `null` at `0/0`, the
670
671
  watermark re-run, the lease window, classifier parity with `report-efficiency.mjs`, and the
671
- `record-usage` CLI surface. `record-usage.mjs` is repo-local: it has no preset twin and
672
- `package.json#files` excludes `.ai.local/**`, so an installed package gets the orchestrator
673
- prose without the CLI until P2 ships a twin or drops the prose.
672
+ `record-usage` CLI surface. `record-usage.mjs` is a published engine module: it ships from
673
+ `presets/_shared/ai-local/scripts/` and is seeded into a consumer's `.ai.local/scripts/`, so the
674
+ orchestrator prose and the CLI travel together. The same seeding carries `verification.mjs`
675
+ (persisted gate evidence with a freshness check) and `incidents.mjs` (recurrence threshold and
676
+ promotion gate).
674
677
 
675
678
  Links: [`../README.md`](../README.md), [`PRESET-CONTRIBUTION.md`](PRESET-CONTRIBUTION.md),
676
679
  the OpenSpec change `openspec/changes/2026-11-10-preset-task-scheduler-impl/`, and ADRs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.70",
3
+ "version": "0.2.72",
4
4
  "description": "Presets of Cursor, Claude, Mavis, OpenCode, and ZCode rules/commands for Revy Ross personal use",
5
5
  "license": "MIT",
6
6
  "author": "Revy Ross",
@@ -81,11 +81,127 @@ function readMetrics(filePath) {
81
81
  }
82
82
  }
83
83
 
84
+ /**
85
+ * Usage math for the report. The SQLite projection owns the same AD-3 rules
86
+ * (host `attempt_finished.usage` wins; `usage_recorded` rows collapse per turn)
87
+ * in `team-db-project.mjs`. Keep the two in step: a token kind nobody reported
88
+ * stays `null`, never `0`.
89
+ */
90
+ const usageNumber = (value) =>
91
+ typeof value === 'number' && Number.isFinite(value) && value >= 0 ? value : null;
92
+
93
+ const usageEventAt = (event) => {
94
+ const at = Date.parse(event.at ?? '');
95
+ return Number.isFinite(at) ? at : null;
96
+ };
97
+
98
+ const collapseUsageTurns = (events) => {
99
+ const winners = new Map();
100
+ events.forEach((event, index) => {
101
+ if (typeof event.turn !== 'string' || event.turn === '') {
102
+ winners.set(`#${index}`, index);
103
+ return;
104
+ }
105
+ const current = winners.get(event.turn);
106
+ if (current === undefined) {
107
+ winners.set(event.turn, index);
108
+ return;
109
+ }
110
+ const at = usageEventAt(event);
111
+ const currentAt = usageEventAt(events[current]);
112
+ const later = at === null || currentAt === null || at === currentAt ? index > current : at > currentAt;
113
+ if (later) winners.set(event.turn, index);
114
+ });
115
+ const kept = new Set(winners.values());
116
+ return events.filter((event, index) => kept.has(index) || typeof event.turn !== 'string' || event.turn === '');
117
+ };
118
+
119
+ const EMPTY_USAGE = {
120
+ input: null,
121
+ output: null,
122
+ reasoning: null,
123
+ cacheRead: null,
124
+ cacheWrite: null,
125
+ costUsd: null,
126
+ source: null,
127
+ model: null,
128
+ turns: 0,
129
+ };
130
+
131
+ const normalizeUsage = (hostUsage, usageEvents = []) => {
132
+ if (hostUsage && typeof hostUsage === 'object' && !Array.isArray(hostUsage)) {
133
+ const usage = {
134
+ input: usageNumber(hostUsage.input),
135
+ output: usageNumber(hostUsage.output),
136
+ reasoning: usageNumber(hostUsage.reasoning),
137
+ cacheRead: usageNumber(hostUsage.cacheRead),
138
+ cacheWrite: usageNumber(hostUsage.cacheWrite),
139
+ costUsd: usageNumber(hostUsage.costUsd),
140
+ source: 'host',
141
+ model: typeof hostUsage.model === 'string' && hostUsage.model !== '' ? hostUsage.model : null,
142
+ turns: 0,
143
+ };
144
+ const reported = Object.entries(usage).some(
145
+ ([key, value]) => !['source', 'model', 'turns'].includes(key) && value !== null,
146
+ );
147
+ return reported ? usage : { ...EMPTY_USAGE };
148
+ }
149
+ const events = collapseUsageTurns(usageEvents.filter((event) => event && typeof event === 'object'));
150
+ if (events.length === 0) return { ...EMPTY_USAGE };
151
+ const sum = (key) => {
152
+ let total = null;
153
+ for (const event of events) {
154
+ const value = usageNumber(event[key]);
155
+ if (value !== null) total = (total ?? 0) + value;
156
+ }
157
+ return total;
158
+ };
159
+ const model = events.find((event) => typeof event.model === 'string' && event.model !== '')?.model ?? null;
160
+ return {
161
+ ...EMPTY_USAGE,
162
+ input: sum('input'),
163
+ output: sum('output'),
164
+ reasoning: sum('reasoning'),
165
+ cacheRead: sum('cached'),
166
+ cacheWrite: sum('cacheWrite'),
167
+ source: 'cli',
168
+ model,
169
+ turns: events.length,
170
+ };
171
+ };
172
+
173
+ const hasUsage = (usage) =>
174
+ Boolean(usage) &&
175
+ ['input', 'output', 'reasoning', 'cacheRead', 'cacheWrite', 'costUsd'].some((key) => usage[key] !== null);
176
+
177
+ const addUsage = (total, usage) => {
178
+ if (!hasUsage(usage)) return total;
179
+ const next = { ...total };
180
+ for (const key of ['input', 'output', 'reasoning', 'cacheRead', 'cacheWrite', 'costUsd']) {
181
+ if (usage[key] === null) continue;
182
+ next[key] = (next[key] ?? 0) + usage[key];
183
+ }
184
+ next.reported += 1;
185
+ return next;
186
+ };
187
+
188
+ const emptyUsageTotal = () => ({
189
+ input: null,
190
+ output: null,
191
+ reasoning: null,
192
+ cacheRead: null,
193
+ cacheWrite: null,
194
+ costUsd: null,
195
+ reported: 0,
196
+ });
197
+
84
198
  function collect(metrics, filePath) {
85
199
  const starts = new Map();
86
200
  const gateStarts = new Map();
87
201
  const terminalAttempts = new Set();
88
202
  const attemptDurations = [];
203
+ const hostUsage = new Map();
204
+ const usageEventsByAttempt = new Map();
89
205
  let taskCompleted = false;
90
206
  let ledgerIncomplete = false;
91
207
  let taskStartedAt = null;
@@ -93,6 +209,7 @@ function collect(metrics, filePath) {
93
209
  let taskGateWaitMs = 0;
94
210
  let taskOutOfBandMs = 0;
95
211
  let taskOutOfBandCount = 0;
212
+ let taskUsage = emptyUsageTotal();
96
213
 
97
214
  for (const event of metrics.events) {
98
215
  if (event.type === 'task_started') taskStartedAt = event.at;
@@ -143,6 +260,12 @@ function collect(metrics, filePath) {
143
260
  (attributionConfidenceCounts.get(attributionConfidence) ?? 0) + 1,
144
261
  );
145
262
  if (Number.isFinite(event.durationMs)) attemptDurations.push(event.durationMs);
263
+ const usage = normalizeUsage(
264
+ hostUsage.get(event.attemptId) ??
265
+ (event.usage && typeof event.usage === 'object' ? event.usage : null),
266
+ usageEventsByAttempt.get(event.attemptId) ?? [],
267
+ );
268
+ taskUsage = addUsage(taskUsage, usage);
146
269
  attempts.push({
147
270
  ...metrics.task,
148
271
  agent: start.agent ?? 'unknown',
@@ -150,7 +273,25 @@ function collect(metrics, filePath) {
150
273
  durationMs: Number.isFinite(event.durationMs) ? event.durationMs : null,
151
274
  outcome: event.outcome ?? 'unknown',
152
275
  attributionConfidence,
276
+ usage,
277
+ });
278
+ }
279
+ if (event.type === 'attempt_finished' && event.attemptId && event.usage && typeof event.usage === 'object') {
280
+ hostUsage.set(event.attemptId, event.usage);
281
+ }
282
+ if (event.type === 'usage_recorded' && event.attemptId) {
283
+ const list = usageEventsByAttempt.get(event.attemptId) ?? [];
284
+ list.push({
285
+ at: event.at,
286
+ turn: event.turn,
287
+ model: event.model,
288
+ input: event.input,
289
+ output: event.output,
290
+ cached: event.cached,
291
+ cacheWrite: event.cacheWrite,
292
+ reasoning: event.reasoning,
153
293
  });
294
+ usageEventsByAttempt.set(event.attemptId, list);
154
295
  }
155
296
  if (event.type === 'human_gate_started' && event.eventId) {
156
297
  gateStarts.set(event.eventId, event);
@@ -192,6 +333,18 @@ function collect(metrics, filePath) {
192
333
  attemptCount: terminalAttempts.size,
193
334
  completed: taskCompleted,
194
335
  incomplete: ledgerIncomplete,
336
+ usage: {
337
+ reportedAttempts: taskUsage.reported,
338
+ coverage: terminalAttempts.size ? taskUsage.reported / terminalAttempts.size : null,
339
+ tokens: {
340
+ input: taskUsage.input,
341
+ output: taskUsage.output,
342
+ reasoning: taskUsage.reasoning,
343
+ cacheRead: taskUsage.cacheRead,
344
+ cacheWrite: taskUsage.cacheWrite,
345
+ },
346
+ costUsd: taskUsage.costUsd,
347
+ },
195
348
  });
196
349
  }
197
350
  }
@@ -223,6 +376,7 @@ const byAgentRole = groupBy(
223
376
  const sample = group[0];
224
377
  const durations = group.map((item) => item.durationMs).filter((value) => value !== null);
225
378
  const sumDurationMs = durations.reduce((sum, value) => sum + value, 0);
379
+ const usageTotal = group.reduce((total, item) => addUsage(total, item.usage), emptyUsageTotal());
226
380
  return {
227
381
  platform: sample.platform,
228
382
  stack: sample.stack,
@@ -233,6 +387,17 @@ const byAgentRole = groupBy(
233
387
  completedCount: group.filter((item) => item.outcome === 'completed').length,
234
388
  sumDurationMs,
235
389
  avgDurationMs: durations.length ? sumDurationMs / durations.length : null,
390
+ usage: {
391
+ reportedAttempts: usageTotal.reported,
392
+ tokens: {
393
+ input: usageTotal.input,
394
+ output: usageTotal.output,
395
+ reasoning: usageTotal.reasoning,
396
+ cacheRead: usageTotal.cacheRead,
397
+ cacheWrite: usageTotal.cacheWrite,
398
+ },
399
+ costUsd: usageTotal.costUsd,
400
+ },
236
401
  };
237
402
  });
238
403
 
@@ -245,11 +410,47 @@ const taskCountsByRunId = [...new Map(tasks.map((task) => [task.runId, task])).v
245
410
  intent: task.intent,
246
411
  }));
247
412
 
413
+ const usageTotal = attempts.reduce((total, item) => addUsage(total, item.usage), emptyUsageTotal());
414
+ const usageModels = new Map();
415
+ for (const item of attempts) {
416
+ if (!hasUsage(item.usage) || typeof item.usage.model !== 'string') continue;
417
+ const key = item.usage.model;
418
+ const current = usageModels.get(key) ?? { model: key, attempts: 0, usage: emptyUsageTotal() };
419
+ current.attempts += 1;
420
+ current.usage = addUsage(current.usage, item.usage);
421
+ usageModels.set(key, current);
422
+ }
423
+
248
424
  process.stdout.write(
249
425
  `${JSON.stringify(
250
426
  {
251
427
  schemaVersion: 1,
252
428
  teamRoot,
429
+ usage: {
430
+ attempts: attempts.length,
431
+ reportedAttempts: usageTotal.reported,
432
+ coverage: attempts.length ? usageTotal.reported / attempts.length : null,
433
+ tokens: {
434
+ input: usageTotal.input,
435
+ output: usageTotal.output,
436
+ reasoning: usageTotal.reasoning,
437
+ cacheRead: usageTotal.cacheRead,
438
+ cacheWrite: usageTotal.cacheWrite,
439
+ },
440
+ costUsd: usageTotal.costUsd,
441
+ byModel: [...usageModels.values()].map((entry) => ({
442
+ model: entry.model,
443
+ attempts: entry.attempts,
444
+ tokens: {
445
+ input: entry.usage.input,
446
+ output: entry.usage.output,
447
+ reasoning: entry.usage.reasoning,
448
+ cacheRead: entry.usage.cacheRead,
449
+ cacheWrite: entry.usage.cacheWrite,
450
+ },
451
+ costUsd: entry.usage.costUsd,
452
+ })),
453
+ },
253
454
  agentRole: byAgentRole,
254
455
  taskCountsByRunId,
255
456
  taskReports,