@bonesofspring/ai-rules 0.2.73 → 0.2.76

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 (419) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/README.md +2 -2
  3. package/bin/lib/engine-scripts.js +12 -0
  4. package/docs/TEAM-DB.md +96 -5
  5. package/docs/TOKEN-ECONOMY.md +18 -5
  6. package/docs/openapi/team-db.v1.json +1164 -224
  7. package/package.json +2 -2
  8. package/presets/_shared/ai-local/scripts/action-signals.mjs +225 -0
  9. package/presets/_shared/ai-local/scripts/actions-report.mjs +210 -0
  10. package/presets/_shared/ai-local/scripts/check-write-scope.mjs +56 -26
  11. package/presets/_shared/ai-local/scripts/lock.mjs +103 -30
  12. package/presets/_shared/ai-local/scripts/processes.mjs +5 -4
  13. package/presets/_shared/ai-local/scripts/rr-scheduler-start.mjs +161 -0
  14. package/presets/_shared/ai-local/scripts/rule-improver.mjs +4 -0
  15. package/presets/_shared/ai-local/scripts/run-compact.mjs +132 -0
  16. package/presets/_shared/ai-local/scripts/signals.mjs +3 -1
  17. package/presets/_shared/ai-local/scripts/team-db-api.mjs +354 -11
  18. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +309 -4
  19. package/presets/_shared/ai-local/scripts/team-db-project.mjs +515 -26
  20. package/presets/_shared/ai-local/scripts/team-db-scheduler.mjs +32 -2
  21. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +185 -1
  22. package/presets/_shared/ai-local/scripts/team-db-task-runner.mjs +3 -1
  23. package/presets/_shared/core/agent-team/agent-task-metrics.md +29 -0
  24. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +1 -1
  25. package/presets/_shared/core/meta/preset-pr-checklist.md +2 -2
  26. package/presets/_shared/core/quality/context-and-iteration.md +1 -1
  27. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +18 -1
  28. package/presets/_shared/hooks/compact-shell-output.mjs +68 -0
  29. package/presets/claude/android-kotlin/commands/README.md +4 -0
  30. package/presets/claude/android-kotlin/commands/rr-scheduler-start.md +32 -0
  31. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +18 -1
  32. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  33. package/presets/claude/android-kotlin/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  34. package/presets/claude/android-kotlin/team/README.md +1 -1
  35. package/presets/claude/go/commands/README.md +4 -0
  36. package/presets/claude/go/commands/rr-scheduler-start.md +32 -0
  37. package/presets/claude/go/hooks/chain-team-phases.sh +18 -1
  38. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  39. package/presets/claude/go/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  40. package/presets/claude/go/team/README.md +1 -1
  41. package/presets/claude/ios-swift/commands/README.md +4 -0
  42. package/presets/claude/ios-swift/commands/rr-scheduler-start.md +32 -0
  43. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +18 -1
  44. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  45. package/presets/claude/ios-swift/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  46. package/presets/claude/ios-swift/team/README.md +1 -1
  47. package/presets/claude/java/commands/README.md +4 -0
  48. package/presets/claude/java/commands/rr-scheduler-start.md +32 -0
  49. package/presets/claude/java/hooks/chain-team-phases.sh +18 -1
  50. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  51. package/presets/claude/java/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  52. package/presets/claude/java/team/README.md +1 -1
  53. package/presets/claude/mcp-ts/commands/README.md +4 -0
  54. package/presets/claude/mcp-ts/commands/rr-scheduler-start.md +32 -0
  55. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +18 -1
  56. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  57. package/presets/claude/mcp-ts/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  58. package/presets/claude/mcp-ts/team/README.md +1 -1
  59. package/presets/claude/mol/commands/README.md +4 -0
  60. package/presets/claude/mol/commands/rr-scheduler-start.md +32 -0
  61. package/presets/claude/mol/hooks/chain-team-phases.sh +18 -1
  62. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  63. package/presets/claude/mol/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  64. package/presets/claude/mol/team/README.md +1 -1
  65. package/presets/claude/next/agents/build-verifier.md +1 -1
  66. package/presets/claude/next/agents/code-reviewer.md +2 -0
  67. package/presets/claude/next/commands/README.md +4 -0
  68. package/presets/claude/next/commands/rr-scheduler-start.md +32 -0
  69. package/presets/claude/next/hooks/chain-team-phases.sh +18 -1
  70. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  71. package/presets/claude/next/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  72. package/presets/claude/next/team/README.md +1 -1
  73. package/presets/claude/nuxt/commands/README.md +4 -0
  74. package/presets/claude/nuxt/commands/rr-scheduler-start.md +32 -0
  75. package/presets/claude/nuxt/hooks/chain-team-phases.sh +18 -1
  76. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  77. package/presets/claude/nuxt/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  78. package/presets/claude/nuxt/team/README.md +1 -1
  79. package/presets/claude/php-hexagonal/commands/README.md +4 -0
  80. package/presets/claude/php-hexagonal/commands/rr-scheduler-start.md +32 -0
  81. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +18 -1
  82. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  83. package/presets/claude/php-hexagonal/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  84. package/presets/claude/php-hexagonal/team/README.md +1 -1
  85. package/presets/claude/php-laravel/commands/README.md +4 -0
  86. package/presets/claude/php-laravel/commands/rr-scheduler-start.md +32 -0
  87. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +18 -1
  88. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  89. package/presets/claude/php-laravel/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  90. package/presets/claude/php-laravel/team/README.md +1 -1
  91. package/presets/claude/svelte/commands/README.md +4 -0
  92. package/presets/claude/svelte/commands/rr-scheduler-start.md +32 -0
  93. package/presets/claude/svelte/hooks/chain-team-phases.sh +18 -1
  94. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  95. package/presets/claude/svelte/rules/tooling-and-review/preset-pr-checklist.md +2 -2
  96. package/presets/claude/svelte/team/README.md +1 -1
  97. package/presets/cursor/android-kotlin/commands/README.md +4 -0
  98. package/presets/cursor/android-kotlin/commands/rr-scheduler-start.md +32 -0
  99. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +18 -1
  100. package/presets/cursor/android-kotlin/hooks/compact-shell-output.mjs +68 -0
  101. package/presets/cursor/android-kotlin/hooks.json +7 -0
  102. package/presets/cursor/android-kotlin/rules/preset-pr-checklist.mdc +2 -2
  103. package/presets/cursor/android-kotlin/team/README.md +1 -1
  104. package/presets/cursor/go/commands/README.md +4 -0
  105. package/presets/cursor/go/commands/rr-scheduler-start.md +32 -0
  106. package/presets/cursor/go/hooks/chain-team-phases.sh +18 -1
  107. package/presets/cursor/go/hooks/compact-shell-output.mjs +68 -0
  108. package/presets/cursor/go/hooks.json +7 -0
  109. package/presets/cursor/go/rules/preset-pr-checklist.mdc +2 -2
  110. package/presets/cursor/go/team/README.md +1 -1
  111. package/presets/cursor/ios-swift/commands/README.md +4 -0
  112. package/presets/cursor/ios-swift/commands/rr-scheduler-start.md +32 -0
  113. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +18 -1
  114. package/presets/cursor/ios-swift/hooks/compact-shell-output.mjs +68 -0
  115. package/presets/cursor/ios-swift/hooks.json +7 -0
  116. package/presets/cursor/ios-swift/rules/preset-pr-checklist.mdc +2 -2
  117. package/presets/cursor/ios-swift/team/README.md +1 -1
  118. package/presets/cursor/java/commands/README.md +4 -0
  119. package/presets/cursor/java/commands/rr-scheduler-start.md +32 -0
  120. package/presets/cursor/java/hooks/chain-team-phases.sh +18 -1
  121. package/presets/cursor/java/hooks/compact-shell-output.mjs +68 -0
  122. package/presets/cursor/java/hooks.json +7 -0
  123. package/presets/cursor/java/rules/preset-pr-checklist.mdc +2 -2
  124. package/presets/cursor/java/team/README.md +1 -1
  125. package/presets/cursor/mcp-ts/commands/README.md +4 -0
  126. package/presets/cursor/mcp-ts/commands/rr-scheduler-start.md +32 -0
  127. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +18 -1
  128. package/presets/cursor/mcp-ts/hooks/compact-shell-output.mjs +68 -0
  129. package/presets/cursor/mcp-ts/hooks.json +7 -0
  130. package/presets/cursor/mcp-ts/rules/preset-pr-checklist.mdc +2 -2
  131. package/presets/cursor/mcp-ts/team/README.md +1 -1
  132. package/presets/cursor/mol/commands/README.md +4 -0
  133. package/presets/cursor/mol/commands/rr-scheduler-start.md +32 -0
  134. package/presets/cursor/mol/hooks/chain-team-phases.sh +18 -1
  135. package/presets/cursor/mol/hooks/compact-shell-output.mjs +68 -0
  136. package/presets/cursor/mol/hooks.json +7 -0
  137. package/presets/cursor/mol/rules/preset-pr-checklist.mdc +2 -2
  138. package/presets/cursor/mol/team/README.md +1 -1
  139. package/presets/cursor/next/agents/build-verifier.md +1 -1
  140. package/presets/cursor/next/agents/code-reviewer.md +2 -0
  141. package/presets/cursor/next/commands/README.md +4 -0
  142. package/presets/cursor/next/commands/rr-scheduler-start.md +32 -0
  143. package/presets/cursor/next/hooks/chain-team-phases.sh +18 -1
  144. package/presets/cursor/next/hooks/compact-shell-output.mjs +68 -0
  145. package/presets/cursor/next/hooks.json +7 -0
  146. package/presets/cursor/next/rules/preset-pr-checklist.mdc +2 -2
  147. package/presets/cursor/next/team/README.md +1 -1
  148. package/presets/cursor/nuxt/commands/README.md +4 -0
  149. package/presets/cursor/nuxt/commands/rr-scheduler-start.md +32 -0
  150. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +18 -1
  151. package/presets/cursor/nuxt/hooks/compact-shell-output.mjs +68 -0
  152. package/presets/cursor/nuxt/hooks.json +7 -0
  153. package/presets/cursor/nuxt/rules/preset-pr-checklist.mdc +2 -2
  154. package/presets/cursor/nuxt/team/README.md +1 -1
  155. package/presets/cursor/php-hexagonal/commands/README.md +4 -0
  156. package/presets/cursor/php-hexagonal/commands/rr-scheduler-start.md +32 -0
  157. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +18 -1
  158. package/presets/cursor/php-hexagonal/hooks/compact-shell-output.mjs +68 -0
  159. package/presets/cursor/php-hexagonal/hooks.json +7 -0
  160. package/presets/cursor/php-hexagonal/rules/preset-pr-checklist.mdc +2 -2
  161. package/presets/cursor/php-hexagonal/team/README.md +1 -1
  162. package/presets/cursor/php-laravel/commands/README.md +4 -0
  163. package/presets/cursor/php-laravel/commands/rr-scheduler-start.md +32 -0
  164. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +18 -1
  165. package/presets/cursor/php-laravel/hooks/compact-shell-output.mjs +68 -0
  166. package/presets/cursor/php-laravel/hooks.json +7 -0
  167. package/presets/cursor/php-laravel/rules/preset-pr-checklist.mdc +2 -2
  168. package/presets/cursor/php-laravel/team/README.md +1 -1
  169. package/presets/cursor/svelte/commands/README.md +4 -0
  170. package/presets/cursor/svelte/commands/rr-scheduler-start.md +32 -0
  171. package/presets/cursor/svelte/hooks/chain-team-phases.sh +18 -1
  172. package/presets/cursor/svelte/hooks/compact-shell-output.mjs +68 -0
  173. package/presets/cursor/svelte/hooks.json +7 -0
  174. package/presets/cursor/svelte/rules/preset-pr-checklist.mdc +2 -2
  175. package/presets/cursor/svelte/team/README.md +1 -1
  176. package/presets/mavis/android-kotlin/adapter-map.json +17 -1
  177. package/presets/mavis/android-kotlin/commands/README.md +4 -0
  178. package/presets/mavis/android-kotlin/commands/rr-scheduler-start.md +27 -0
  179. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +18 -1
  180. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +1 -1
  181. package/presets/mavis/android-kotlin/rules/preset-pr-checklist.md +2 -2
  182. package/presets/mavis/android-kotlin/team/README.md +1 -1
  183. package/presets/mavis/go/adapter-map.json +17 -1
  184. package/presets/mavis/go/commands/README.md +4 -0
  185. package/presets/mavis/go/commands/rr-scheduler-start.md +27 -0
  186. package/presets/mavis/go/hooks/chain-team-phases.sh +18 -1
  187. package/presets/mavis/go/rules/agent-team-orchestrator.md +1 -1
  188. package/presets/mavis/go/rules/preset-pr-checklist.md +2 -2
  189. package/presets/mavis/go/team/README.md +1 -1
  190. package/presets/mavis/ios-swift/adapter-map.json +17 -1
  191. package/presets/mavis/ios-swift/commands/README.md +4 -0
  192. package/presets/mavis/ios-swift/commands/rr-scheduler-start.md +27 -0
  193. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +18 -1
  194. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +1 -1
  195. package/presets/mavis/ios-swift/rules/preset-pr-checklist.md +2 -2
  196. package/presets/mavis/ios-swift/team/README.md +1 -1
  197. package/presets/mavis/java/adapter-map.json +17 -1
  198. package/presets/mavis/java/commands/README.md +4 -0
  199. package/presets/mavis/java/commands/rr-scheduler-start.md +27 -0
  200. package/presets/mavis/java/hooks/chain-team-phases.sh +18 -1
  201. package/presets/mavis/java/rules/agent-team-orchestrator.md +1 -1
  202. package/presets/mavis/java/rules/preset-pr-checklist.md +2 -2
  203. package/presets/mavis/java/team/README.md +1 -1
  204. package/presets/mavis/mcp-ts/adapter-map.json +17 -1
  205. package/presets/mavis/mcp-ts/commands/README.md +4 -0
  206. package/presets/mavis/mcp-ts/commands/rr-scheduler-start.md +27 -0
  207. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +18 -1
  208. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +1 -1
  209. package/presets/mavis/mcp-ts/rules/preset-pr-checklist.md +2 -2
  210. package/presets/mavis/mcp-ts/team/README.md +1 -1
  211. package/presets/mavis/mol/adapter-map.json +17 -1
  212. package/presets/mavis/mol/commands/README.md +4 -0
  213. package/presets/mavis/mol/commands/rr-scheduler-start.md +27 -0
  214. package/presets/mavis/mol/hooks/chain-team-phases.sh +18 -1
  215. package/presets/mavis/mol/rules/agent-team-orchestrator.md +1 -1
  216. package/presets/mavis/mol/rules/preset-pr-checklist.md +2 -2
  217. package/presets/mavis/mol/team/README.md +1 -1
  218. package/presets/mavis/next/adapter-map.json +17 -1
  219. package/presets/mavis/next/agents/build-verifier.md +1 -1
  220. package/presets/mavis/next/agents/code-reviewer.md +2 -0
  221. package/presets/mavis/next/commands/README.md +4 -0
  222. package/presets/mavis/next/commands/rr-scheduler-start.md +27 -0
  223. package/presets/mavis/next/hooks/chain-team-phases.sh +18 -1
  224. package/presets/mavis/next/rules/agent-team-orchestrator.md +1 -1
  225. package/presets/mavis/next/rules/preset-pr-checklist.md +2 -2
  226. package/presets/mavis/next/team/README.md +1 -1
  227. package/presets/mavis/nuxt/adapter-map.json +17 -1
  228. package/presets/mavis/nuxt/commands/README.md +4 -0
  229. package/presets/mavis/nuxt/commands/rr-scheduler-start.md +27 -0
  230. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +18 -1
  231. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +1 -1
  232. package/presets/mavis/nuxt/rules/preset-pr-checklist.md +2 -2
  233. package/presets/mavis/nuxt/team/README.md +1 -1
  234. package/presets/mavis/php-hexagonal/adapter-map.json +17 -1
  235. package/presets/mavis/php-hexagonal/commands/README.md +4 -0
  236. package/presets/mavis/php-hexagonal/commands/rr-scheduler-start.md +27 -0
  237. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +18 -1
  238. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
  239. package/presets/mavis/php-hexagonal/rules/preset-pr-checklist.md +2 -2
  240. package/presets/mavis/php-hexagonal/team/README.md +1 -1
  241. package/presets/mavis/php-laravel/adapter-map.json +17 -1
  242. package/presets/mavis/php-laravel/commands/README.md +4 -0
  243. package/presets/mavis/php-laravel/commands/rr-scheduler-start.md +27 -0
  244. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +18 -1
  245. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +1 -1
  246. package/presets/mavis/php-laravel/rules/preset-pr-checklist.md +2 -2
  247. package/presets/mavis/php-laravel/team/README.md +1 -1
  248. package/presets/mavis/svelte/adapter-map.json +17 -1
  249. package/presets/mavis/svelte/commands/README.md +4 -0
  250. package/presets/mavis/svelte/commands/rr-scheduler-start.md +27 -0
  251. package/presets/mavis/svelte/hooks/chain-team-phases.sh +18 -1
  252. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +1 -1
  253. package/presets/mavis/svelte/rules/preset-pr-checklist.md +2 -2
  254. package/presets/mavis/svelte/team/README.md +1 -1
  255. package/presets/opencode/android-kotlin/adapter-map.json +17 -1
  256. package/presets/opencode/android-kotlin/commands/README.md +4 -0
  257. package/presets/opencode/android-kotlin/commands/rr-scheduler-start.md +35 -0
  258. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +18 -1
  259. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +1 -1
  260. package/presets/opencode/android-kotlin/rules/preset-pr-checklist.md +2 -2
  261. package/presets/opencode/android-kotlin/team/README.md +1 -1
  262. package/presets/opencode/go/adapter-map.json +17 -1
  263. package/presets/opencode/go/commands/README.md +4 -0
  264. package/presets/opencode/go/commands/rr-scheduler-start.md +35 -0
  265. package/presets/opencode/go/hooks/chain-team-phases.sh +18 -1
  266. package/presets/opencode/go/rules/agent-team-orchestrator.md +1 -1
  267. package/presets/opencode/go/rules/preset-pr-checklist.md +2 -2
  268. package/presets/opencode/go/team/README.md +1 -1
  269. package/presets/opencode/ios-swift/adapter-map.json +17 -1
  270. package/presets/opencode/ios-swift/commands/README.md +4 -0
  271. package/presets/opencode/ios-swift/commands/rr-scheduler-start.md +35 -0
  272. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +18 -1
  273. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +1 -1
  274. package/presets/opencode/ios-swift/rules/preset-pr-checklist.md +2 -2
  275. package/presets/opencode/ios-swift/team/README.md +1 -1
  276. package/presets/opencode/java/adapter-map.json +17 -1
  277. package/presets/opencode/java/commands/README.md +4 -0
  278. package/presets/opencode/java/commands/rr-scheduler-start.md +35 -0
  279. package/presets/opencode/java/hooks/chain-team-phases.sh +18 -1
  280. package/presets/opencode/java/rules/agent-team-orchestrator.md +1 -1
  281. package/presets/opencode/java/rules/preset-pr-checklist.md +2 -2
  282. package/presets/opencode/java/team/README.md +1 -1
  283. package/presets/opencode/mcp-ts/adapter-map.json +17 -1
  284. package/presets/opencode/mcp-ts/commands/README.md +4 -0
  285. package/presets/opencode/mcp-ts/commands/rr-scheduler-start.md +35 -0
  286. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +18 -1
  287. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +1 -1
  288. package/presets/opencode/mcp-ts/rules/preset-pr-checklist.md +2 -2
  289. package/presets/opencode/mcp-ts/team/README.md +1 -1
  290. package/presets/opencode/mol/adapter-map.json +17 -1
  291. package/presets/opencode/mol/commands/README.md +4 -0
  292. package/presets/opencode/mol/commands/rr-scheduler-start.md +35 -0
  293. package/presets/opencode/mol/hooks/chain-team-phases.sh +18 -1
  294. package/presets/opencode/mol/rules/agent-team-orchestrator.md +1 -1
  295. package/presets/opencode/mol/rules/preset-pr-checklist.md +2 -2
  296. package/presets/opencode/mol/team/README.md +1 -1
  297. package/presets/opencode/next/adapter-map.json +17 -1
  298. package/presets/opencode/next/agents/build-verifier.md +1 -1
  299. package/presets/opencode/next/agents/code-reviewer.md +2 -0
  300. package/presets/opencode/next/commands/README.md +4 -0
  301. package/presets/opencode/next/commands/rr-scheduler-start.md +35 -0
  302. package/presets/opencode/next/hooks/chain-team-phases.sh +18 -1
  303. package/presets/opencode/next/rules/agent-team-orchestrator.md +1 -1
  304. package/presets/opencode/next/rules/preset-pr-checklist.md +2 -2
  305. package/presets/opencode/next/team/README.md +1 -1
  306. package/presets/opencode/nuxt/adapter-map.json +17 -1
  307. package/presets/opencode/nuxt/commands/README.md +4 -0
  308. package/presets/opencode/nuxt/commands/rr-scheduler-start.md +35 -0
  309. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +18 -1
  310. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +1 -1
  311. package/presets/opencode/nuxt/rules/preset-pr-checklist.md +2 -2
  312. package/presets/opencode/nuxt/team/README.md +1 -1
  313. package/presets/opencode/php-hexagonal/adapter-map.json +17 -1
  314. package/presets/opencode/php-hexagonal/commands/README.md +4 -0
  315. package/presets/opencode/php-hexagonal/commands/rr-scheduler-start.md +35 -0
  316. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +18 -1
  317. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
  318. package/presets/opencode/php-hexagonal/rules/preset-pr-checklist.md +2 -2
  319. package/presets/opencode/php-hexagonal/team/README.md +1 -1
  320. package/presets/opencode/php-laravel/adapter-map.json +17 -1
  321. package/presets/opencode/php-laravel/commands/README.md +4 -0
  322. package/presets/opencode/php-laravel/commands/rr-scheduler-start.md +35 -0
  323. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +18 -1
  324. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +1 -1
  325. package/presets/opencode/php-laravel/rules/preset-pr-checklist.md +2 -2
  326. package/presets/opencode/php-laravel/team/README.md +1 -1
  327. package/presets/opencode/plugins/output-guard/README.md +45 -3
  328. package/presets/opencode/plugins/output-guard/actions.ts +201 -0
  329. package/presets/opencode/plugins/output-guard/index.ts +147 -6
  330. package/presets/opencode/plugins/output-guard/rewrite.ts +10 -1
  331. package/presets/opencode/svelte/adapter-map.json +17 -1
  332. package/presets/opencode/svelte/commands/README.md +4 -0
  333. package/presets/opencode/svelte/commands/rr-scheduler-start.md +35 -0
  334. package/presets/opencode/svelte/hooks/chain-team-phases.sh +18 -1
  335. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +1 -1
  336. package/presets/opencode/svelte/rules/preset-pr-checklist.md +2 -2
  337. package/presets/opencode/svelte/team/README.md +1 -1
  338. package/presets/zcode/android-kotlin/adapter-map.json +17 -1
  339. package/presets/zcode/android-kotlin/commands/README.md +4 -0
  340. package/presets/zcode/android-kotlin/commands/rr-scheduler-start.md +35 -0
  341. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +18 -1
  342. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +1 -1
  343. package/presets/zcode/android-kotlin/rules/preset-pr-checklist.md +2 -2
  344. package/presets/zcode/android-kotlin/team/README.md +1 -1
  345. package/presets/zcode/go/adapter-map.json +17 -1
  346. package/presets/zcode/go/commands/README.md +4 -0
  347. package/presets/zcode/go/commands/rr-scheduler-start.md +35 -0
  348. package/presets/zcode/go/hooks/chain-team-phases.sh +18 -1
  349. package/presets/zcode/go/rules/agent-team-orchestrator.md +1 -1
  350. package/presets/zcode/go/rules/preset-pr-checklist.md +2 -2
  351. package/presets/zcode/go/team/README.md +1 -1
  352. package/presets/zcode/ios-swift/adapter-map.json +17 -1
  353. package/presets/zcode/ios-swift/commands/README.md +4 -0
  354. package/presets/zcode/ios-swift/commands/rr-scheduler-start.md +35 -0
  355. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +18 -1
  356. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +1 -1
  357. package/presets/zcode/ios-swift/rules/preset-pr-checklist.md +2 -2
  358. package/presets/zcode/ios-swift/team/README.md +1 -1
  359. package/presets/zcode/java/adapter-map.json +17 -1
  360. package/presets/zcode/java/commands/README.md +4 -0
  361. package/presets/zcode/java/commands/rr-scheduler-start.md +35 -0
  362. package/presets/zcode/java/hooks/chain-team-phases.sh +18 -1
  363. package/presets/zcode/java/rules/agent-team-orchestrator.md +1 -1
  364. package/presets/zcode/java/rules/preset-pr-checklist.md +2 -2
  365. package/presets/zcode/java/team/README.md +1 -1
  366. package/presets/zcode/mcp-ts/adapter-map.json +17 -1
  367. package/presets/zcode/mcp-ts/commands/README.md +4 -0
  368. package/presets/zcode/mcp-ts/commands/rr-scheduler-start.md +35 -0
  369. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +18 -1
  370. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +1 -1
  371. package/presets/zcode/mcp-ts/rules/preset-pr-checklist.md +2 -2
  372. package/presets/zcode/mcp-ts/team/README.md +1 -1
  373. package/presets/zcode/mol/adapter-map.json +17 -1
  374. package/presets/zcode/mol/commands/README.md +4 -0
  375. package/presets/zcode/mol/commands/rr-scheduler-start.md +35 -0
  376. package/presets/zcode/mol/hooks/chain-team-phases.sh +18 -1
  377. package/presets/zcode/mol/rules/agent-team-orchestrator.md +1 -1
  378. package/presets/zcode/mol/rules/preset-pr-checklist.md +2 -2
  379. package/presets/zcode/mol/team/README.md +1 -1
  380. package/presets/zcode/next/adapter-map.json +17 -1
  381. package/presets/zcode/next/agents/build-verifier.md +1 -1
  382. package/presets/zcode/next/agents/code-reviewer.md +2 -0
  383. package/presets/zcode/next/commands/README.md +4 -0
  384. package/presets/zcode/next/commands/rr-scheduler-start.md +35 -0
  385. package/presets/zcode/next/hooks/chain-team-phases.sh +18 -1
  386. package/presets/zcode/next/rules/agent-team-orchestrator.md +1 -1
  387. package/presets/zcode/next/rules/preset-pr-checklist.md +2 -2
  388. package/presets/zcode/next/team/README.md +1 -1
  389. package/presets/zcode/nuxt/adapter-map.json +17 -1
  390. package/presets/zcode/nuxt/commands/README.md +4 -0
  391. package/presets/zcode/nuxt/commands/rr-scheduler-start.md +35 -0
  392. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +18 -1
  393. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +1 -1
  394. package/presets/zcode/nuxt/rules/preset-pr-checklist.md +2 -2
  395. package/presets/zcode/nuxt/team/README.md +1 -1
  396. package/presets/zcode/php-hexagonal/adapter-map.json +17 -1
  397. package/presets/zcode/php-hexagonal/commands/README.md +4 -0
  398. package/presets/zcode/php-hexagonal/commands/rr-scheduler-start.md +35 -0
  399. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +18 -1
  400. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
  401. package/presets/zcode/php-hexagonal/rules/preset-pr-checklist.md +2 -2
  402. package/presets/zcode/php-hexagonal/team/README.md +1 -1
  403. package/presets/zcode/php-laravel/adapter-map.json +17 -1
  404. package/presets/zcode/php-laravel/commands/README.md +4 -0
  405. package/presets/zcode/php-laravel/commands/rr-scheduler-start.md +35 -0
  406. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +18 -1
  407. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +1 -1
  408. package/presets/zcode/php-laravel/rules/preset-pr-checklist.md +2 -2
  409. package/presets/zcode/php-laravel/team/README.md +1 -1
  410. package/presets/zcode/svelte/adapter-map.json +17 -1
  411. package/presets/zcode/svelte/commands/README.md +4 -0
  412. package/presets/zcode/svelte/commands/rr-scheduler-start.md +35 -0
  413. package/presets/zcode/svelte/hooks/chain-team-phases.sh +18 -1
  414. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +1 -1
  415. package/presets/zcode/svelte/rules/preset-pr-checklist.md +2 -2
  416. package/presets/zcode/svelte/team/README.md +1 -1
  417. package/scripts/close-agent-task-human-gate.mjs +3 -3
  418. package/scripts/report-context-cost.mjs +10 -3
  419. package/scripts/aggregate-agent-task-metrics.mjs +0 -480
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bonesofspring/ai-rules",
3
- "version": "0.2.73",
3
+ "version": "0.2.76",
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",
@@ -34,7 +34,7 @@
34
34
  "!presets/*/next/team/upstream/**",
35
35
  "presets/_shared/ai-local/scripts/check-write-scope.mjs",
36
36
  "scripts/check-product-specs.sh",
37
- "scripts/aggregate-agent-task-metrics.mjs",
37
+ "presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs",
38
38
  "scripts/close-agent-task-human-gate.mjs",
39
39
  "scripts/report-context-cost.mjs"
40
40
  ],
@@ -0,0 +1,225 @@
1
+ /**
2
+ * The action rollup and its signal set.
3
+ *
4
+ * `task_action_summary` and `action_signals` are views over `tool_calls` and
5
+ * `usage_turns`, so the numbers here are read-time facts of the base rows. This
6
+ * module is the one place the ratios, the thresholds and the rule text live: a
7
+ * recalibration is a code change with no migration and no backfill, which is why
8
+ * the views carry numerators only.
9
+ *
10
+ * The report CLI and the HTTP API both read this module, so a signal the report
11
+ * flags is a signal the API serves.
12
+ */
13
+
14
+ /** The seven intent values, in the order the interface lists them. */
15
+ export const ACTION_INTENTS = ['explore', 'mutate', 'execute', 'delegate', 'ask', 'meta', 'web'];
16
+
17
+ /** The five failure classes a captured action may name. */
18
+ export const ACTION_ERROR_CLASSES = ['validation', 'notfound', 'permission', 'timeout', 'upstream'];
19
+
20
+ /** The three severities of a fired signal, worst first. */
21
+ export const SIGNAL_SEVERITIES = ['critical', 'warn', 'info'];
22
+
23
+ /** The rung names of the attribution ladder, strongest first. */
24
+ export const ATTRIBUTION_RUNGS = ['lease', 'window', 'dir-mtime', 'unmapped'];
25
+
26
+ /**
27
+ * The calibrated thresholds.
28
+ *
29
+ * Calibration cases (`analysis.md` §5.11): the `agent-overhead-investigation`
30
+ * session — 155 turns, 277 tool calls, 0 changed files — must fire, and a clean
31
+ * single-work-package task must not. `test-team-db-efficiency.mjs` pins both.
32
+ */
33
+ export const SIGNAL_THRESHOLDS = {
34
+ /** `noop_actions`: actions and no mutated file. */
35
+ noopMinActions: 20,
36
+ /** `explore_without_mutate`: explore actions and no mutation. */
37
+ exploreMinActions: 20,
38
+ errorWarnRatio: 0.2,
39
+ errorCriticalRatio: 0.4,
40
+ repeatWarnRatio: 0.5,
41
+ guardInfoRatio: 0.25,
42
+ compactionWarnCount: 3,
43
+ weakAttributionInfoRatio: 0.5,
44
+ };
45
+
46
+ /** One line per signal: what fired, in the units of the value it carries. */
47
+ export const SIGNAL_RULES = {
48
+ noop_actions: '20 or more actions and no file was ever mutated',
49
+ explore_without_mutate: '20 or more explore actions and no mutation',
50
+ error_rate: 'a fifth or more of the actions failed',
51
+ repeat_churn: 'half or more of the actions repeated a target',
52
+ guard_pressure: 'a quarter or more of the results needed the guard rewrite',
53
+ context_thrash: 'three or more compactions in one task',
54
+ weak_attribution: 'half or more of the actions were mapped by a fuzzy rung',
55
+ };
56
+
57
+ /** The signal names, one per rule, in declaration order. */
58
+ export const ACTION_SIGNAL_NAMES = Object.keys(SIGNAL_RULES);
59
+
60
+ const SEVERITY_RANK = new Map(SIGNAL_SEVERITIES.map((severity, index) => [severity, index]));
61
+
62
+ /**
63
+ * The contract order of two fired signals: worst severity first, then by name.
64
+ *
65
+ * A window-wide read collects task by task, so a caller adds the task slug as
66
+ * the final tiebreak and gets one order for the whole array.
67
+ */
68
+ export const compareSignals = (left, right) =>
69
+ SEVERITY_RANK.get(left.severity) - SEVERITY_RANK.get(right.severity) ||
70
+ (left.signal < right.signal ? -1 : left.signal > right.signal ? 1 : 0);
71
+
72
+ const ratio = (numerator, denominator) => (denominator === 0 ? null : numerator / denominator);
73
+
74
+ /** A `task_action_summary` row as the readers use it, every ratio null-safe. */
75
+ export const summaryOf = (row) => {
76
+ if (!row) return null;
77
+ const actions = Number(row.actions ?? 0);
78
+ const turns = Number(row.turns ?? 0);
79
+ const changedFiles = Number(row.changed_files ?? 0);
80
+ const errorActions = Number(row.error_actions ?? 0);
81
+ const repeatActions = Number(row.repeat_actions ?? 0);
82
+ const guardHits = Number(row.guard_hits ?? 0);
83
+ const firstAt = row.first_at ?? null;
84
+ const lastAt = row.last_at ?? null;
85
+ const first = firstAt === null ? Number.NaN : Date.parse(firstAt);
86
+ const last = lastAt === null ? Number.NaN : Date.parse(lastAt);
87
+ const tokens = Number(row.tokens ?? 0);
88
+ const byRung = {
89
+ lease: Number(row.rung_lease ?? 0),
90
+ window: Number(row.rung_window ?? 0),
91
+ 'dir-mtime': Number(row.rung_dir_mtime ?? 0),
92
+ unmapped: Number(row.rung_unmapped ?? 0),
93
+ };
94
+ return {
95
+ actions,
96
+ turns,
97
+ changedFiles,
98
+ errorActions,
99
+ repeatActions,
100
+ guardHits,
101
+ tokens,
102
+ reasoningParts: Number(row.reasoning_parts ?? 0),
103
+ compactions: Number(row.compactions ?? 0),
104
+ measuredActions: Number(row.measured_actions ?? 0),
105
+ busyMs: Number(row.busy_ms ?? 0),
106
+ wallMs: Number.isFinite(first) && Number.isFinite(last) ? Math.max(0, last - first) : null,
107
+ firstAt,
108
+ lastAt,
109
+ errorRate: ratio(errorActions, actions),
110
+ repeatRatio: ratio(repeatActions, actions),
111
+ guardRatio: ratio(guardHits, actions),
112
+ unmappedRatio: ratio(byRung.unmapped, actions),
113
+ weakRatio: ratio(byRung.window + byRung['dir-mtime'], actions),
114
+ tokensPerAction: ratio(tokens, actions),
115
+ actionsPerChangedFile: ratio(actions, changedFiles),
116
+ byIntent: {
117
+ explore: Number(row.explore ?? 0),
118
+ mutate: Number(row.mutate ?? 0),
119
+ execute: Number(row.execute ?? 0),
120
+ delegate: Number(row.delegate ?? 0),
121
+ ask: Number(row.ask ?? 0),
122
+ meta: Number(row.meta ?? 0),
123
+ web: Number(row.web ?? 0),
124
+ },
125
+ byRung,
126
+ };
127
+ };
128
+
129
+ const RULES = [
130
+ {
131
+ signal: 'noop_actions',
132
+ fired: (summary) => summary.changedFiles === 0 && summary.actions >= SIGNAL_THRESHOLDS.noopMinActions,
133
+ severity: () => 'critical',
134
+ value: (summary) => summary.actions,
135
+ },
136
+ {
137
+ signal: 'explore_without_mutate',
138
+ fired: (summary) =>
139
+ summary.byIntent.mutate === 0 && summary.byIntent.explore >= SIGNAL_THRESHOLDS.exploreMinActions,
140
+ severity: () => 'warn',
141
+ value: (summary) => summary.byIntent.explore,
142
+ },
143
+ {
144
+ signal: 'error_rate',
145
+ fired: (summary) => summary.errorRate !== null && summary.errorRate >= SIGNAL_THRESHOLDS.errorWarnRatio,
146
+ severity: (summary) =>
147
+ summary.errorRate !== null && summary.errorRate >= SIGNAL_THRESHOLDS.errorCriticalRatio ? 'critical' : 'warn',
148
+ value: (summary) => summary.errorActions,
149
+ },
150
+ {
151
+ signal: 'repeat_churn',
152
+ fired: (summary) => summary.repeatRatio !== null && summary.repeatRatio >= SIGNAL_THRESHOLDS.repeatWarnRatio,
153
+ severity: () => 'warn',
154
+ value: (summary) => summary.repeatActions,
155
+ },
156
+ {
157
+ signal: 'guard_pressure',
158
+ fired: (summary) => summary.guardRatio !== null && summary.guardRatio >= SIGNAL_THRESHOLDS.guardInfoRatio,
159
+ severity: () => 'info',
160
+ value: (summary) => summary.guardHits,
161
+ },
162
+ {
163
+ signal: 'context_thrash',
164
+ fired: (summary) => summary.compactions >= SIGNAL_THRESHOLDS.compactionWarnCount,
165
+ severity: () => 'warn',
166
+ value: (summary) => summary.compactions,
167
+ },
168
+ {
169
+ signal: 'weak_attribution',
170
+ fired: (summary) => summary.weakRatio !== null && summary.weakRatio >= SIGNAL_THRESHOLDS.weakAttributionInfoRatio,
171
+ severity: () => 'info',
172
+ value: (summary) => summary.byRung.window + summary.byRung['dir-mtime'],
173
+ },
174
+ ];
175
+
176
+ /**
177
+ * The fired signals of one task, worst first and then by name.
178
+ *
179
+ * The order is part of the contract: the interface renders the array verbatim,
180
+ * so a reader never sorts it and two calls with the same rows agree.
181
+ */
182
+ export const evaluateSignals = (summary) => {
183
+ if (summary === null) return [];
184
+ const fired = [];
185
+ for (const rule of RULES) {
186
+ if (!rule.fired(summary)) continue;
187
+ fired.push({
188
+ signal: rule.signal,
189
+ severity: rule.severity(summary),
190
+ value: rule.value(summary),
191
+ rule: SIGNAL_RULES[rule.signal],
192
+ });
193
+ }
194
+ return fired.sort(compareSignals);
195
+ };
196
+
197
+ /** The rollup row of one task, or `null` when it has no attributed action. */
198
+ export const readActionSummary = (db, slug) =>
199
+ summaryOf(db.prepare('SELECT * FROM task_action_summary WHERE task_slug = ?1').get(slug));
200
+
201
+ /** The raw view row, for a caller that reports the view itself as evidence. */
202
+ export const readActionSummaryRow = (db, slug) =>
203
+ db.prepare('SELECT * FROM task_action_summary WHERE task_slug = ?1').get(slug) ?? null;
204
+
205
+ /** The non-zero signal numerators the view carries for one task. */
206
+ export const readSignalCandidates = (db, slug) =>
207
+ db.prepare('SELECT signal, value FROM action_signals WHERE task_slug = ?1 ORDER BY signal ASC').all(slug);
208
+
209
+ /**
210
+ * The attribution coverage of one task: the per-rung counts, the mapped share and
211
+ * an explicit "counts are a lower bound" flag. A task with no rows reports a null
212
+ * coverage rather than a confident `0`.
213
+ */
214
+ export const coverageOf = (summary) => {
215
+ const byRung = summary === null ? { lease: 0, window: 0, 'dir-mtime': 0, unmapped: 0 } : summary.byRung;
216
+ const total = Object.values(byRung).reduce((sum, value) => sum + value, 0);
217
+ const mapped = total - byRung.unmapped;
218
+ return {
219
+ byRung,
220
+ mapped,
221
+ total,
222
+ coverage: total === 0 ? null : mapped / total,
223
+ lowerBound: byRung.unmapped > 0,
224
+ };
225
+ };
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The per-task action rollup and its signal set, read from `team.db`.
4
+ *
5
+ * The database is a projection: this script reads it and writes nothing. Every
6
+ * figure it prints comes from `task_action_summary` / `action_signals` and is
7
+ * paired with a direct count over the base rows in `--json`, so a consumer reads
8
+ * the JSON and never the prose (the shape `measure.mjs` uses).
9
+ *
10
+ * Usage (any cwd, after `team-db.mjs sync`):
11
+ * node .ai.local/scripts/actions-report.mjs --slug <slug> [--since <instant>] [--json]
12
+ * [--root <team-root>]
13
+ *
14
+ * Exit codes: 0 whenever a report is produced — an unknown slug is an empty
15
+ * report with a null coverage, not an error. 2 when the projection cannot be
16
+ * read (missing, busy, older or newer than this code).
17
+ */
18
+ import path from 'node:path';
19
+ import { fileURLToPath } from 'node:url';
20
+
21
+ import { openTeamDb, TeamDbError, DEFAULT_TEAM_ROOT } from './team-db-schema.mjs';
22
+ import {
23
+ ACTION_INTENTS,
24
+ ATTRIBUTION_RUNGS,
25
+ coverageOf,
26
+ evaluateSignals,
27
+ readActionSummary,
28
+ readActionSummaryRow,
29
+ readSignalCandidates,
30
+ summaryOf,
31
+ } from './action-signals.mjs';
32
+
33
+ const USAGE =
34
+ 'usage: actions-report.mjs --slug <slug> [--since <instant> (recorded, does not filter)] [--json] [--root <team-root>]';
35
+
36
+ const parseArgs = (argv) => {
37
+ const options = { slug: null, since: null, json: false, root: null };
38
+ for (let index = 0; index < argv.length; index += 1) {
39
+ const arg = argv[index];
40
+ if (arg === '--json') options.json = true;
41
+ else if (arg === '--slug') options.slug = argv[++index] ?? null;
42
+ else if (arg === '--since') options.since = argv[++index] ?? null;
43
+ else if (arg === '--root') options.root = argv[++index] ?? null;
44
+ else if (arg === '--help' || arg === '-h') {
45
+ process.stdout.write(`${USAGE}\n`);
46
+ process.exit(0);
47
+ } else {
48
+ process.stderr.write(`actions-report: unknown argument ${arg}\n${USAGE}\n`);
49
+ process.exit(0);
50
+ }
51
+ }
52
+ return options;
53
+ };
54
+
55
+ const percent = (value) => (value === null ? '—' : `${Math.round(value * 100)}%`);
56
+
57
+ const number = (value) => (value === null || value === undefined ? '—' : String(value));
58
+
59
+ /**
60
+ * A direct count over the base rows: the evidence beside the view's own figure.
61
+ *
62
+ * `--since` is recorded on the report but never filters these counts: the rollup
63
+ * is a per-task view, and a view cannot take a bound parameter, so filtering one
64
+ * side would compare a window against an all-time figure.
65
+ */
66
+ const evidenceOf = (db, slug) => {
67
+ const calls = db.prepare('SELECT count(*) AS n FROM tool_calls WHERE task_slug = ?1').get(slug);
68
+ const turns = db.prepare('SELECT count(*) AS n FROM usage_turns WHERE task_slug = ?1').get(slug);
69
+ const changed = db
70
+ .prepare(
71
+ `SELECT count(DISTINCT target_key) AS n FROM tool_calls
72
+ WHERE task_slug = ?1 AND intent = 'mutate' AND target_key IS NOT NULL`,
73
+ )
74
+ .get(slug);
75
+ const rungs = {};
76
+ for (const rung of ATTRIBUTION_RUNGS) {
77
+ rungs[rung] = Number(
78
+ db
79
+ .prepare('SELECT count(*) AS n FROM tool_calls WHERE task_slug = ?1 AND attribution = ?2')
80
+ .get(slug, rung).n,
81
+ );
82
+ }
83
+ return {
84
+ actions: Number(calls.n),
85
+ turns: Number(turns.n),
86
+ changedFiles: Number(changed.n),
87
+ byRung: rungs,
88
+ };
89
+ };
90
+
91
+ const figure = (id, reported, data, extra = {}) => ({
92
+ id,
93
+ reported,
94
+ data,
95
+ reproduced: reported === data,
96
+ ...extra,
97
+ });
98
+
99
+ const buildReport = ({ db, slug, since }) => {
100
+ const view = readActionSummaryRow(db, slug);
101
+ const summary = summaryOf(view);
102
+ const evidence = evidenceOf(db, slug);
103
+ const signals = evaluateSignals(summary);
104
+ const candidates = new Map(readSignalCandidates(db, slug).map((row) => [row.signal, Number(row.value)]));
105
+ const coverage = coverageOf(summary);
106
+
107
+ const figures = [
108
+ figure('actions', summary === null ? 0 : summary.actions, evidence.actions),
109
+ figure('turns', summary === null ? 0 : summary.turns, evidence.turns),
110
+ figure('changedFiles', summary === null ? 0 : summary.changedFiles, evidence.changedFiles),
111
+ ...ATTRIBUTION_RUNGS.map((rung) =>
112
+ figure(`attribution.${rung}`, coverage.byRung[rung] ?? 0, evidence.byRung[rung]),
113
+ ),
114
+ {
115
+ id: 'signals',
116
+ reported: signals.map((entry) => entry.signal),
117
+ data: [...candidates.keys()].sort(),
118
+ // Every fired signal has a non-zero numerator in the view; the view may
119
+ // carry a numerator this task's thresholds do not fire on.
120
+ reproduced: signals.every((entry) => candidates.has(entry.signal)),
121
+ rule: 'every fired signal carries a non-zero numerator in action_signals',
122
+ },
123
+ ];
124
+
125
+ return {
126
+ slug,
127
+ since,
128
+ window: { from: summary?.firstAt ?? null, to: summary?.lastAt ?? null },
129
+ coverage,
130
+ summary,
131
+ signals,
132
+ figures,
133
+ reproduced: figures.every((entry) => entry.reproduced),
134
+ };
135
+ };
136
+
137
+ const printProse = (report) => {
138
+ const { slug, summary, coverage, signals, window } = report;
139
+ const lines = [`agent actions — ${slug}`];
140
+ lines.push(`window: ${number(window.from)} – ${number(window.to)}`);
141
+ if (summary === null) {
142
+ lines.push('no attributed action in this projection');
143
+ lines.push(`attribution: coverage — (0 rows); run team-db.mjs sync, then AI_RULES_ACTIONS is not 0`);
144
+ return lines.join('\n');
145
+ }
146
+ lines.push(
147
+ `actions ${summary.actions} turns ${summary.turns} changed files ${summary.changedFiles} tokens ${summary.tokens}`,
148
+ );
149
+ lines.push(
150
+ `by intent: ${ACTION_INTENTS.map((intent) => `${intent} ${summary.byIntent[intent]}`).join(' · ')}`,
151
+ );
152
+ lines.push(
153
+ `error rate ${percent(summary.errorRate)} (${summary.errorActions}/${summary.actions}) ` +
154
+ `repeat ratio ${percent(summary.repeatRatio)} (${summary.repeatActions}/${summary.actions}) ` +
155
+ `guard hits ${summary.guardHits}`,
156
+ );
157
+ lines.push(
158
+ `actions per changed file ${summary.actionsPerChangedFile === null ? '— (no mutated file)' : summary.actionsPerChangedFile.toFixed(1)} ` +
159
+ `tokens per action ${summary.tokensPerAction === null ? '—' : Math.round(summary.tokensPerAction)}`,
160
+ );
161
+ lines.push(
162
+ `wall ${summary.wallMs === null ? '—' : `${Math.round(summary.wallMs / 1000)}s`} ` +
163
+ `busy ${summary.measuredActions === 0 ? '— (no measured duration)' : `${Math.round(summary.busyMs / 1000)}s`}`,
164
+ );
165
+ const rungs = ATTRIBUTION_RUNGS.map((rung) => {
166
+ const share = coverage.total === 0 ? null : (coverage.byRung[rung] ?? 0) / coverage.total;
167
+ return `${rung} ${percent(share)}`;
168
+ });
169
+ lines.push(
170
+ `attribution: ${rungs.join(' · ')} mapped ${coverage.mapped}/${coverage.total} (${percent(coverage.coverage)})`,
171
+ );
172
+ if (coverage.lowerBound) lines.push('counts are a lower bound: some rows are not attributable');
173
+ if (signals.length === 0) lines.push('signals: none above its threshold');
174
+ else {
175
+ lines.push('signals:');
176
+ for (const entry of signals) lines.push(` ${entry.severity} ${entry.signal} = ${entry.value} (${entry.rule})`);
177
+ }
178
+ return lines.join('\n');
179
+ };
180
+
181
+ const main = () => {
182
+ const options = parseArgs(process.argv.slice(2));
183
+ if (options.slug === null || options.slug.trim() === '') {
184
+ process.stderr.write(`actions-report: --slug is required\n${USAGE}\n`);
185
+ process.exit(0);
186
+ }
187
+ const teamRoot = options.root === null ? DEFAULT_TEAM_ROOT : path.resolve(options.root);
188
+ let handle;
189
+ try {
190
+ handle = openTeamDb({ teamRoot, readOnly: true });
191
+ } catch (error) {
192
+ const code = error instanceof TeamDbError ? error.code : 'E_DB_OPEN';
193
+ process.stderr.write(`actions-report: ${code}: ${error.message}\n`);
194
+ process.exit(2);
195
+ }
196
+ try {
197
+ const report = buildReport({ db: handle.db, slug: options.slug, since: options.since });
198
+ process.stdout.write(`${options.json ? JSON.stringify(report, null, 2) : printProse(report)}\n`);
199
+ } finally {
200
+ try {
201
+ handle.db.close();
202
+ } catch {
203
+ /* the report is already printed */
204
+ }
205
+ }
206
+ };
207
+
208
+ if (process.argv[1] !== undefined && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url))) {
209
+ main();
210
+ }
@@ -23,7 +23,12 @@
23
23
  * 2. `--base <ref>` — a committed change-set.
24
24
  * 3. The step baseline written by `--save-baseline` (agents never commit, so
25
25
  * `HEAD` alone would attribute every earlier step to the current one).
26
- * 4. `HEAD` — the whole uncommitted change-set, reported with a notice.
26
+ * 4. No step baseline — the whole uncommitted change-set cannot be attributed to
27
+ * this step, so the audit skips (exit `3`) and reports the change-set as
28
+ * suspects; an empty change-set reconciles to a pass.
29
+ *
30
+ * Automatic selection only considers steps with an `id`, because the baseline
31
+ * file is keyed by it; a scoped step without an id is a `no-step-ids` skip.
27
32
  *
28
33
  * A step baseline records every dirty path with its content hash; the audit
29
34
  * keeps a path only when it is new since the baseline or when its content
@@ -55,8 +60,9 @@ const BASELINE_PREFIX = `${BASELINE_DIRECTORY.split(path.sep).join('/')}/`;
55
60
 
56
61
  const SKIP_HINTS = {
57
62
  'no-steps': 'pipeline.json has no steps; write the plan with task-router before auditing',
58
- 'no-step-ids': 'pipeline.json predates step ids; backfill them with "team-db.mjs migrate-tasks" and pass --step',
63
+ 'no-step-ids': 'pipeline.json predates step ids and the baseline is keyed by id; re-run the task-router to regenerate pipeline.json with steps[].id, then resume via /task-continue <slug>',
59
64
  'no-write-scopes': 'pipeline.json predates writeScopes; only task-router can declare a step write surface, so this step is not auditable',
65
+ 'no-baseline': 'the step wrote without a saved baseline, so no path can be attributed to it; the orchestrator saves it before the step writes (--step <id> --save-baseline), or pass the step paths (--paths a,b), then re-run',
60
66
  };
61
67
 
62
68
  const DERIVED_RULES = [
@@ -139,6 +145,10 @@ const skipResult = (reason, step = null) => ({ skip: { reason, step } });
139
145
  * Pick the audited step. A legacy pipeline is a **skip**, not a failure: the
140
146
  * audit cannot invent an id or a write surface, and a mandatory gate must not
141
147
  * become unsatisfiable for work that predates the schema.
148
+ *
149
+ * A step baseline is keyed by `id`, so a step without one is never selected:
150
+ * selecting it made `--save-baseline` a usage error and left the whole
151
+ * uncommitted change-set unattributed.
142
152
  */
143
153
  function chooseStep(pipeline, requested) {
144
154
  const steps = Array.isArray(pipeline.steps) ? pipeline.steps : [];
@@ -150,12 +160,14 @@ function chooseStep(pipeline, requested) {
150
160
  if (identified.length === 0) return skipResult('no-step-ids');
151
161
  fail(`unknown step "${requested}" (available: ${identified.map((item) => item.id).join(', ')})`);
152
162
  }
153
- const implementation = steps.find((item) => hasWriteScopes(item)
154
- && agentsOf(item).some((agent) => /feature-developer|debugger|ci-investigator/i.test(agent)));
163
+ const scoped = identified.filter(hasWriteScopes);
164
+ const implementation = scoped.find((item) => agentsOf(item)
165
+ .some((agent) => /feature-developer|debugger|ci-investigator/i.test(agent)));
155
166
  if (implementation) return { step: implementation };
156
- const scoped = steps.filter(hasWriteScopes);
157
167
  if (scoped.length === 1) return { step: scoped[0] };
158
- if (scoped.length === 0) return skipResult('no-write-scopes');
168
+ if (scoped.length === 0) {
169
+ return steps.some(hasWriteScopes) ? skipResult('no-step-ids') : skipResult('no-write-scopes');
170
+ }
159
171
  fail('cannot choose a step; pass --step <id>');
160
172
  return null;
161
173
  }
@@ -220,18 +232,19 @@ function classify(changed, writeScopes, slug) {
220
232
  });
221
233
  }
222
234
 
223
- function renderReport({ slug, step, base, baseline, notice, verdict, rows }) {
224
- const counts = {
225
- declared: rows.filter((row) => row.classification === 'declared').length,
226
- derived: rows.filter((row) => row.classification === 'derived').length,
227
- outOfScope: rows.filter((row) => row.classification === 'out-of-scope').length,
228
- };
235
+ const countRows = (rows) => ({
236
+ declared: rows.filter((row) => row.classification === 'declared').length,
237
+ derived: rows.filter((row) => row.classification === 'derived').length,
238
+ outOfScope: rows.filter((row) => row.classification === 'out-of-scope').length,
239
+ });
240
+
241
+ function renderReport({ slug, step, base, baseline, verdict, rows }) {
242
+ const counts = countRows(rows);
229
243
  const lines = [
230
244
  `Write-scope reconciliation — slug ${slug}, step ${step?.id ?? '(no id)'} (${agentsOf(step).join(', ')})`,
231
245
  `base: ${base}${base === 'HEAD' ? ' (uncommitted change-set)' : ''}`,
232
246
  ];
233
247
  if (baseline) lines.push(`baseline: ${baseline}`);
234
- if (notice) lines.push(`notice: ${notice}`);
235
248
  lines.push(`paths: ${rows.length} — declared ${counts.declared}, derived ${counts.derived}, out-of-scope ${counts.outOfScope}`);
236
249
  for (const row of rows) {
237
250
  lines.push(` ${row.classification.padEnd(12)} ${row.path} — ${row.source}`);
@@ -240,31 +253,38 @@ function renderReport({ slug, step, base, baseline, notice, verdict, rows }) {
240
253
  return { counts, text: `${lines.join('\n')}\n` };
241
254
  }
242
255
 
243
- function reportSkip({ slug, skip, asJson }) {
256
+ function reportSkip({ slug, skip, asJson, rows = [], writeScopes = [] }) {
244
257
  const hint = SKIP_HINTS[skip.reason] ?? 'the pipeline does not declare a write surface for this step';
245
258
  const step = skip.step;
259
+ const counts = countRows(rows);
246
260
  if (asJson) {
247
261
  console.log(JSON.stringify({
248
262
  schemaVersion: 1,
249
263
  slug,
250
- step: { id: step?.id ?? null, agent: step?.agent ?? null, writeScopes: [] },
264
+ step: { id: step?.id ?? null, agent: step?.agent ?? null, writeScopes },
251
265
  base: null,
252
266
  baseline: null,
253
267
  verdict: 'skip',
254
268
  skipped: true,
255
269
  skipReason: skip.reason,
256
270
  hint,
257
- counts: { declared: 0, derived: 0, outOfScope: 0 },
258
- paths: [],
271
+ counts,
272
+ paths: rows,
259
273
  }, null, 2));
260
274
  } else {
261
- process.stdout.write([
275
+ const lines = [
262
276
  `Write-scope reconciliation — slug ${slug}, step ${step?.id ?? '(no id)'} (${agentsOf(step).join(', ')})`,
263
277
  `skip: ${skip.reason}`,
264
278
  `hint: ${hint}`,
265
- 'verdict: SKIP',
266
- '',
267
- ].join('\n'));
279
+ ];
280
+ if (rows.length > 0) {
281
+ lines.push(`paths: ${rows.length} — declared ${counts.declared}, derived ${counts.derived}, out-of-scope ${counts.outOfScope} (unattributed: the whole uncommitted change-set)`);
282
+ for (const row of rows) {
283
+ lines.push(` ${row.classification.padEnd(12)} ${row.path} — ${row.source}`);
284
+ }
285
+ }
286
+ lines.push('verdict: SKIP', '');
287
+ process.stdout.write(lines.join('\n'));
268
288
  }
269
289
  process.exit(EXIT_SKIP);
270
290
  }
@@ -313,7 +333,6 @@ function main() {
313
333
 
314
334
  let base = args.base ?? 'HEAD';
315
335
  let baseline = null;
316
- let notice = null;
317
336
  let changed;
318
337
  if (args.paths !== undefined) {
319
338
  changed = String(args.paths).split(',').map(normalizePath).filter(Boolean);
@@ -327,8 +346,20 @@ function main() {
327
346
  baseline = path.relative(root, file).replace(/\\/g, '/');
328
347
  changed = baselineDelta(root, saved, base);
329
348
  } else {
330
- changed = gitChangedPaths(root, base);
331
- notice = `no baseline saved for step ${step.id ?? '(no id)'}; auditing the whole uncommitted change-set, which may include earlier steps`;
349
+ // No step baseline: the whole change-set may carry earlier steps and other
350
+ // tasks, so no path can be attributed to this step. The audit skips instead
351
+ // of failing a step on writes it cannot own.
352
+ const wholeTree = gitChangedPaths(root, base);
353
+ if (wholeTree.length > 0) {
354
+ reportSkip({
355
+ slug: args.slug,
356
+ skip: { reason: 'no-baseline', step },
357
+ asJson: args.json,
358
+ rows: classify(wholeTree, writeScopes, args.slug),
359
+ writeScopes,
360
+ });
361
+ }
362
+ changed = wholeTree;
332
363
  }
333
364
  }
334
365
 
@@ -336,7 +367,7 @@ function main() {
336
367
  const outOfScope = rows.filter((row) => row.classification === 'out-of-scope');
337
368
  const advisory = agentsOf(step).some((agent) => REVIEW_AGENT_RE.test(agent));
338
369
  const verdict = outOfScope.length === 0 ? 'pass' : advisory ? 'advisory' : 'fail';
339
- const { counts, text } = renderReport({ slug: args.slug, step, base, baseline, notice, verdict, rows });
370
+ const { counts, text } = renderReport({ slug: args.slug, step, base, baseline, verdict, rows });
340
371
 
341
372
  if (args.json) {
342
373
  console.log(JSON.stringify({
@@ -347,7 +378,6 @@ function main() {
347
378
  baseline,
348
379
  verdict,
349
380
  skipped: false,
350
- ...(notice ? { notice } : {}),
351
381
  counts,
352
382
  paths: rows,
353
383
  }, null, 2));