@bonesofspring/ai-rules 0.2.63 → 0.2.65

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 (421) hide show
  1. package/CHANGELOG.md +96 -1
  2. package/README.md +11 -4
  3. package/bin/cli.js +7 -5
  4. package/bin/lib/ai-local-drift.js +7 -6
  5. package/bin/lib/engine-scripts.js +17 -4
  6. package/bin/lib/engine-upgrade.js +10 -2
  7. package/bin/lib/manifest-schema.js +12 -0
  8. package/bin/lib/seed-ai-local-team.js +20 -0
  9. package/bin/mavis-install.js +4 -3
  10. package/bin/opencode-install.js +22 -6
  11. package/bin/zcode-install.js +4 -3
  12. package/docs/MCP-CATALOG.md +1 -1
  13. package/docs/OPENCODE-COMPATIBILITY.md +3 -2
  14. package/docs/OPENCODE.md +22 -2
  15. package/docs/PRESET-CONTRIBUTION.md +43 -2
  16. package/docs/TEAM-DB.md +213 -5
  17. package/docs/openapi/team-db.v1.json +5928 -3045
  18. package/mcp/defectdojo-mcp.mjs +44 -12
  19. package/mcp/lib/defectdojo.mjs +57 -2
  20. package/package.json +27 -15
  21. package/presets/_shared/ai-local/scripts/aggregate-agent-task-metrics.mjs +279 -0
  22. package/presets/_shared/ai-local/scripts/process-lease.mjs +576 -0
  23. package/presets/_shared/ai-local/scripts/processes.mjs +1618 -0
  24. package/presets/_shared/ai-local/scripts/run.mjs +5 -5
  25. package/presets/_shared/ai-local/scripts/team-db-api.mjs +784 -7
  26. package/presets/_shared/ai-local/scripts/team-db-dashboard.mjs +235 -10
  27. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +813 -7
  28. package/presets/_shared/ai-local/scripts/team-db-project.mjs +397 -4
  29. package/presets/_shared/ai-local/scripts/team-db-scheduler.mjs +86 -10
  30. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +221 -0
  31. package/presets/_shared/ai-local/scripts/team-db-task-runner.mjs +567 -0
  32. package/presets/_shared/ai-local/scripts/team-db-tracker.mjs +2069 -0
  33. package/presets/_shared/ai-local/scripts/team-db-ui.mjs +750 -0
  34. package/presets/_shared/ai-local/scripts/team-db.mjs +151 -7
  35. package/presets/_shared/ai-local/scripts/upstream-research.mjs +3 -0
  36. package/presets/_shared/core/agent-team/agent-task-metrics.md +7 -2
  37. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +2 -1
  38. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +314 -1
  39. package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +40 -2
  40. package/presets/_shared/hooks/run-hook.mjs +2 -1
  41. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +314 -1
  42. package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +41 -2
  43. package/presets/claude/android-kotlin/hooks/run-hook.mjs +2 -1
  44. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  45. package/presets/claude/android-kotlin/settings.json +6 -1
  46. package/presets/claude/go/hooks/chain-team-phases.sh +314 -1
  47. package/presets/claude/go/hooks/guard-shell-command.mjs +41 -2
  48. package/presets/claude/go/hooks/run-hook.mjs +2 -1
  49. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  50. package/presets/claude/go/settings.json +6 -1
  51. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +314 -1
  52. package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +41 -2
  53. package/presets/claude/ios-swift/hooks/run-hook.mjs +2 -1
  54. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  55. package/presets/claude/ios-swift/settings.json +6 -1
  56. package/presets/claude/java/hooks/chain-team-phases.sh +314 -1
  57. package/presets/claude/java/hooks/guard-shell-command.mjs +41 -2
  58. package/presets/claude/java/hooks/run-hook.mjs +2 -1
  59. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  60. package/presets/claude/java/settings.json +6 -1
  61. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +314 -1
  62. package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +41 -2
  63. package/presets/claude/mcp-ts/hooks/run-hook.mjs +2 -1
  64. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  65. package/presets/claude/mcp-ts/settings.json +6 -1
  66. package/presets/claude/mol/hooks/chain-team-phases.sh +314 -1
  67. package/presets/claude/mol/hooks/guard-shell-command.mjs +41 -2
  68. package/presets/claude/mol/hooks/run-hook.mjs +2 -1
  69. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  70. package/presets/claude/mol/settings.json +6 -1
  71. package/presets/claude/next/MCP.md +2 -0
  72. package/presets/claude/next/REPO_AGENTS.md +2 -0
  73. package/presets/claude/next/agents/build-verifier.md +1 -1
  74. package/presets/claude/next/agents/ci-investigator.md +3 -0
  75. package/presets/claude/next/agents/code-reviewer.md +1 -0
  76. package/presets/claude/next/agents/debugger.md +3 -0
  77. package/presets/claude/next/agents/feature-developer.md +3 -0
  78. package/presets/claude/next/agents/mockup-reviewer.md +4 -1
  79. package/presets/claude/next/agents/performance-auditor.md +2 -0
  80. package/presets/claude/next/agents/playwright-test-generator.md +3 -0
  81. package/presets/claude/next/agents/playwright-test-healer.md +3 -0
  82. package/presets/claude/next/agents/playwright-test-planner.md +3 -0
  83. package/presets/claude/next/agents/qa-tester.md +3 -0
  84. package/presets/claude/next/agents/task-analyst.md +2 -0
  85. package/presets/claude/next/commands/README.md +6 -0
  86. package/presets/claude/next/commands/task.md +7 -1
  87. package/presets/claude/next/commands/technical-retro.md +7 -1
  88. package/presets/claude/next/commands/ui-start.md +78 -0
  89. package/presets/claude/next/commands/ui-stop.md +71 -0
  90. package/presets/claude/next/commands/upstream-research.md +1 -1
  91. package/presets/claude/next/hooks/chain-team-phases.sh +314 -1
  92. package/presets/claude/next/hooks/guard-shell-command.mjs +41 -2
  93. package/presets/claude/next/hooks/run-hook.mjs +2 -1
  94. package/presets/claude/next/rules/README.md +2 -1
  95. package/presets/claude/next/rules/stack/next-app-core.md +1 -0
  96. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  97. package/presets/claude/next/rules/tooling-and-review/dev-process-lifecycle.md +43 -0
  98. package/presets/claude/next/settings.json +6 -1
  99. package/presets/claude/next/skills/figma-fidelity/SKILL.md +4 -1
  100. package/presets/claude/next/skills/mockup-review/SKILL.md +4 -0
  101. package/presets/claude/next/team/README.md +5 -1
  102. package/presets/claude/next/team/upstream/jobs.json +34 -0
  103. package/presets/claude/nuxt/hooks/chain-team-phases.sh +314 -1
  104. package/presets/claude/nuxt/hooks/guard-shell-command.mjs +41 -2
  105. package/presets/claude/nuxt/hooks/run-hook.mjs +2 -1
  106. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  107. package/presets/claude/nuxt/settings.json +6 -1
  108. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +314 -1
  109. package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +41 -2
  110. package/presets/claude/php-hexagonal/hooks/run-hook.mjs +2 -1
  111. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  112. package/presets/claude/php-hexagonal/settings.json +6 -1
  113. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +315 -2
  114. package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +41 -2
  115. package/presets/claude/php-laravel/hooks/run-hook.mjs +2 -1
  116. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  117. package/presets/claude/php-laravel/settings.json +6 -1
  118. package/presets/claude/svelte/hooks/chain-team-phases.sh +314 -1
  119. package/presets/claude/svelte/hooks/guard-shell-command.mjs +41 -2
  120. package/presets/claude/svelte/hooks/run-hook.mjs +2 -1
  121. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +2 -1
  122. package/presets/claude/svelte/settings.json +6 -1
  123. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +314 -1
  124. package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +41 -2
  125. package/presets/cursor/android-kotlin/hooks/run-hook.mjs +2 -1
  126. package/presets/cursor/go/hooks/chain-team-phases.sh +314 -1
  127. package/presets/cursor/go/hooks/guard-shell-command.mjs +41 -2
  128. package/presets/cursor/go/hooks/run-hook.mjs +2 -1
  129. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +314 -1
  130. package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +41 -2
  131. package/presets/cursor/ios-swift/hooks/run-hook.mjs +2 -1
  132. package/presets/cursor/java/hooks/chain-team-phases.sh +314 -1
  133. package/presets/cursor/java/hooks/guard-shell-command.mjs +41 -2
  134. package/presets/cursor/java/hooks/run-hook.mjs +2 -1
  135. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +314 -1
  136. package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +41 -2
  137. package/presets/cursor/mcp-ts/hooks/run-hook.mjs +2 -1
  138. package/presets/cursor/mol/hooks/chain-team-phases.sh +314 -1
  139. package/presets/cursor/mol/hooks/guard-shell-command.mjs +41 -2
  140. package/presets/cursor/mol/hooks/run-hook.mjs +2 -1
  141. package/presets/cursor/next/MCP.md +2 -0
  142. package/presets/cursor/next/REPO_AGENTS.md +2 -0
  143. package/presets/cursor/next/agents/build-verifier.md +1 -1
  144. package/presets/cursor/next/agents/ci-investigator.md +2 -0
  145. package/presets/cursor/next/agents/code-reviewer.md +1 -0
  146. package/presets/cursor/next/agents/debugger.md +2 -0
  147. package/presets/cursor/next/agents/feature-developer.md +2 -0
  148. package/presets/cursor/next/agents/mockup-reviewer.md +4 -1
  149. package/presets/cursor/next/agents/performance-auditor.md +2 -0
  150. package/presets/cursor/next/agents/playwright-test-generator.md +2 -0
  151. package/presets/cursor/next/agents/playwright-test-healer.md +2 -0
  152. package/presets/cursor/next/agents/playwright-test-planner.md +2 -0
  153. package/presets/cursor/next/agents/qa-tester.md +2 -0
  154. package/presets/cursor/next/agents/task-analyst.md +2 -0
  155. package/presets/cursor/next/ai-local/rules-library/storybook-dev-compare-figma.md +2 -1
  156. package/presets/cursor/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
  157. package/presets/cursor/next/commands/README.md +6 -0
  158. package/presets/cursor/next/commands/task.md +7 -1
  159. package/presets/cursor/next/commands/technical-retro.md +7 -1
  160. package/presets/cursor/next/commands/ui-start.md +78 -0
  161. package/presets/cursor/next/commands/ui-stop.md +71 -0
  162. package/presets/cursor/next/commands/upstream-research.md +1 -1
  163. package/presets/cursor/next/hooks/chain-team-phases.sh +314 -1
  164. package/presets/cursor/next/hooks/guard-shell-command.mjs +41 -2
  165. package/presets/cursor/next/hooks/run-hook.mjs +2 -1
  166. package/presets/cursor/next/rules/README.md +2 -1
  167. package/presets/cursor/next/rules/dev-process-lifecycle.mdc +43 -0
  168. package/presets/cursor/next/rules/next-app-core.mdc +1 -0
  169. package/presets/cursor/next/skills/figma-fidelity/SKILL.md +4 -1
  170. package/presets/cursor/next/skills/mockup-review/SKILL.md +4 -0
  171. package/presets/cursor/next/team/README.md +5 -1
  172. package/presets/cursor/next/team/upstream/jobs.json +34 -0
  173. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +314 -1
  174. package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +41 -2
  175. package/presets/cursor/nuxt/hooks/run-hook.mjs +2 -1
  176. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +314 -1
  177. package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +41 -2
  178. package/presets/cursor/php-hexagonal/hooks/run-hook.mjs +2 -1
  179. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +315 -2
  180. package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +41 -2
  181. package/presets/cursor/php-laravel/hooks/run-hook.mjs +2 -1
  182. package/presets/cursor/svelte/hooks/chain-team-phases.sh +314 -1
  183. package/presets/cursor/svelte/hooks/guard-shell-command.mjs +41 -2
  184. package/presets/cursor/svelte/hooks/run-hook.mjs +2 -1
  185. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  186. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +314 -1
  187. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +2 -1
  188. package/presets/mavis/go/adapter-map.json +1 -1
  189. package/presets/mavis/go/hooks/chain-team-phases.sh +314 -1
  190. package/presets/mavis/go/rules/agent-team-orchestrator.md +2 -1
  191. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  192. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +314 -1
  193. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +2 -1
  194. package/presets/mavis/java/adapter-map.json +1 -1
  195. package/presets/mavis/java/hooks/chain-team-phases.sh +314 -1
  196. package/presets/mavis/java/rules/agent-team-orchestrator.md +2 -1
  197. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  198. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +314 -1
  199. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +2 -1
  200. package/presets/mavis/mol/adapter-map.json +1 -1
  201. package/presets/mavis/mol/hooks/chain-team-phases.sh +314 -1
  202. package/presets/mavis/mol/rules/agent-team-orchestrator.md +2 -1
  203. package/presets/mavis/next/MCP.md +2 -0
  204. package/presets/mavis/next/REPO_AGENTS.md +2 -0
  205. package/presets/mavis/next/adapter-map.json +33 -1
  206. package/presets/mavis/next/agents/build-verifier.md +1 -1
  207. package/presets/mavis/next/agents/ci-investigator.md +3 -0
  208. package/presets/mavis/next/agents/code-reviewer.md +1 -0
  209. package/presets/mavis/next/agents/debugger.md +3 -0
  210. package/presets/mavis/next/agents/feature-developer.md +3 -0
  211. package/presets/mavis/next/agents/mockup-reviewer.md +4 -1
  212. package/presets/mavis/next/agents/performance-auditor.md +2 -0
  213. package/presets/mavis/next/agents/playwright-test-generator.md +3 -0
  214. package/presets/mavis/next/agents/playwright-test-healer.md +3 -0
  215. package/presets/mavis/next/agents/playwright-test-planner.md +3 -0
  216. package/presets/mavis/next/agents/qa-tester.md +3 -0
  217. package/presets/mavis/next/agents/task-analyst.md +2 -0
  218. package/presets/mavis/next/ai-local/rules-library/storybook-dev-compare-figma.md +2 -1
  219. package/presets/mavis/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
  220. package/presets/mavis/next/commands/README.md +6 -0
  221. package/presets/mavis/next/commands/task.md +7 -1
  222. package/presets/mavis/next/commands/technical-retro.md +7 -1
  223. package/presets/mavis/next/commands/ui-start.md +73 -0
  224. package/presets/mavis/next/commands/ui-stop.md +66 -0
  225. package/presets/mavis/next/commands/upstream-research.md +1 -1
  226. package/presets/mavis/next/hooks/chain-team-phases.sh +314 -1
  227. package/presets/mavis/next/rules/agent-team-orchestrator.md +2 -1
  228. package/presets/mavis/next/rules/dev-process-lifecycle.md +38 -0
  229. package/presets/mavis/next/rules/next-app-core.md +1 -0
  230. package/presets/mavis/next/skills/figma-fidelity/SKILL.md +4 -1
  231. package/presets/mavis/next/skills/mockup-review/SKILL.md +4 -0
  232. package/presets/mavis/next/team/README.md +5 -1
  233. package/presets/mavis/next/team/upstream/jobs.json +34 -0
  234. package/presets/mavis/nuxt/adapter-map.json +1 -1
  235. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +314 -1
  236. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +2 -1
  237. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  238. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +314 -1
  239. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +2 -1
  240. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  241. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +315 -2
  242. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +2 -1
  243. package/presets/mavis/svelte/adapter-map.json +1 -1
  244. package/presets/mavis/svelte/hooks/chain-team-phases.sh +314 -1
  245. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +2 -1
  246. package/presets/opencode/android-kotlin/OPENCODE.md +4 -1
  247. package/presets/opencode/android-kotlin/README.md +1 -0
  248. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  249. package/presets/opencode/android-kotlin/hooks/README.md +4 -2
  250. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +314 -1
  251. package/presets/opencode/android-kotlin/opencode.json +5 -1
  252. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +2 -1
  253. package/presets/opencode/go/OPENCODE.md +4 -1
  254. package/presets/opencode/go/README.md +1 -0
  255. package/presets/opencode/go/adapter-map.json +1 -1
  256. package/presets/opencode/go/hooks/README.md +4 -2
  257. package/presets/opencode/go/hooks/chain-team-phases.sh +314 -1
  258. package/presets/opencode/go/opencode.json +5 -1
  259. package/presets/opencode/go/rules/agent-team-orchestrator.md +2 -1
  260. package/presets/opencode/ios-swift/OPENCODE.md +4 -1
  261. package/presets/opencode/ios-swift/README.md +1 -0
  262. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  263. package/presets/opencode/ios-swift/hooks/README.md +4 -2
  264. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +314 -1
  265. package/presets/opencode/ios-swift/opencode.json +5 -1
  266. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +2 -1
  267. package/presets/opencode/java/OPENCODE.md +4 -1
  268. package/presets/opencode/java/README.md +1 -0
  269. package/presets/opencode/java/adapter-map.json +1 -1
  270. package/presets/opencode/java/hooks/README.md +4 -2
  271. package/presets/opencode/java/hooks/chain-team-phases.sh +314 -1
  272. package/presets/opencode/java/opencode.json +5 -1
  273. package/presets/opencode/java/rules/agent-team-orchestrator.md +2 -1
  274. package/presets/opencode/mcp-ts/OPENCODE.md +4 -1
  275. package/presets/opencode/mcp-ts/README.md +1 -0
  276. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  277. package/presets/opencode/mcp-ts/hooks/README.md +4 -2
  278. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +314 -1
  279. package/presets/opencode/mcp-ts/opencode.json +5 -1
  280. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +2 -1
  281. package/presets/opencode/mol/OPENCODE.md +4 -1
  282. package/presets/opencode/mol/README.md +1 -0
  283. package/presets/opencode/mol/adapter-map.json +1 -1
  284. package/presets/opencode/mol/hooks/README.md +4 -2
  285. package/presets/opencode/mol/hooks/chain-team-phases.sh +314 -1
  286. package/presets/opencode/mol/opencode.json +4 -0
  287. package/presets/opencode/mol/rules/agent-team-orchestrator.md +2 -1
  288. package/presets/opencode/next/MCP.md +2 -0
  289. package/presets/opencode/next/OPENCODE.md +4 -1
  290. package/presets/opencode/next/README.md +1 -0
  291. package/presets/opencode/next/REPO_AGENTS.md +2 -0
  292. package/presets/opencode/next/adapter-map.json +33 -1
  293. package/presets/opencode/next/agents/build-verifier.md +1 -1
  294. package/presets/opencode/next/agents/ci-investigator.md +3 -0
  295. package/presets/opencode/next/agents/code-reviewer.md +1 -0
  296. package/presets/opencode/next/agents/debugger.md +3 -0
  297. package/presets/opencode/next/agents/feature-developer.md +3 -0
  298. package/presets/opencode/next/agents/mockup-reviewer.md +4 -1
  299. package/presets/opencode/next/agents/performance-auditor.md +2 -0
  300. package/presets/opencode/next/agents/playwright-test-generator.md +3 -0
  301. package/presets/opencode/next/agents/playwright-test-healer.md +3 -0
  302. package/presets/opencode/next/agents/playwright-test-planner.md +3 -0
  303. package/presets/opencode/next/agents/qa-tester.md +3 -0
  304. package/presets/opencode/next/agents/task-analyst.md +2 -0
  305. package/presets/opencode/next/ai-local/rules-library/storybook-dev-compare-figma.md +2 -1
  306. package/presets/opencode/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
  307. package/presets/opencode/next/commands/README.md +6 -0
  308. package/presets/opencode/next/commands/task.md +7 -1
  309. package/presets/opencode/next/commands/technical-retro.md +7 -1
  310. package/presets/opencode/next/commands/ui-start.md +81 -0
  311. package/presets/opencode/next/commands/ui-stop.md +74 -0
  312. package/presets/opencode/next/commands/upstream-research.md +1 -1
  313. package/presets/opencode/next/hooks/README.md +4 -2
  314. package/presets/opencode/next/hooks/chain-team-phases.sh +314 -1
  315. package/presets/opencode/next/opencode.json +4 -0
  316. package/presets/opencode/next/rules/agent-team-orchestrator.md +2 -1
  317. package/presets/opencode/next/rules/dev-process-lifecycle.md +38 -0
  318. package/presets/opencode/next/rules/next-app-core.md +1 -0
  319. package/presets/opencode/next/skills/figma-fidelity/SKILL.md +4 -1
  320. package/presets/opencode/next/skills/mockup-review/SKILL.md +4 -0
  321. package/presets/opencode/next/team/README.md +5 -1
  322. package/presets/opencode/next/team/upstream/jobs.json +34 -0
  323. package/presets/opencode/nuxt/OPENCODE.md +4 -1
  324. package/presets/opencode/nuxt/README.md +1 -0
  325. package/presets/opencode/nuxt/adapter-map.json +1 -1
  326. package/presets/opencode/nuxt/hooks/README.md +4 -2
  327. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +314 -1
  328. package/presets/opencode/nuxt/opencode.json +4 -0
  329. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +2 -1
  330. package/presets/opencode/php-hexagonal/OPENCODE.md +4 -1
  331. package/presets/opencode/php-hexagonal/README.md +1 -0
  332. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  333. package/presets/opencode/php-hexagonal/hooks/README.md +4 -2
  334. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +314 -1
  335. package/presets/opencode/php-hexagonal/opencode.json +5 -1
  336. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +2 -1
  337. package/presets/opencode/php-laravel/OPENCODE.md +4 -1
  338. package/presets/opencode/php-laravel/README.md +1 -0
  339. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  340. package/presets/opencode/php-laravel/hooks/README.md +4 -2
  341. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +315 -2
  342. package/presets/opencode/php-laravel/opencode.json +5 -1
  343. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +2 -1
  344. package/presets/opencode/platform-contract.json +6 -0
  345. package/presets/opencode/plugins/task-status/README.md +92 -0
  346. package/presets/opencode/plugins/task-status/details-data.ts +130 -0
  347. package/presets/opencode/plugins/task-status/details.tsx +84 -0
  348. package/presets/opencode/plugins/task-status/eta.ts +230 -0
  349. package/presets/opencode/plugins/task-status/index.ts +6 -0
  350. package/presets/opencode/plugins/task-status/package.json +10 -0
  351. package/presets/opencode/plugins/task-status/task-view.ts +606 -0
  352. package/presets/opencode/plugins/task-status/tui.tsx +139 -0
  353. package/presets/opencode/svelte/OPENCODE.md +4 -1
  354. package/presets/opencode/svelte/README.md +1 -0
  355. package/presets/opencode/svelte/adapter-map.json +1 -1
  356. package/presets/opencode/svelte/hooks/README.md +4 -2
  357. package/presets/opencode/svelte/hooks/chain-team-phases.sh +314 -1
  358. package/presets/opencode/svelte/opencode.json +4 -0
  359. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +2 -1
  360. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  361. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +314 -1
  362. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +2 -1
  363. package/presets/zcode/go/adapter-map.json +1 -1
  364. package/presets/zcode/go/hooks/chain-team-phases.sh +314 -1
  365. package/presets/zcode/go/rules/agent-team-orchestrator.md +2 -1
  366. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  367. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +314 -1
  368. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +2 -1
  369. package/presets/zcode/java/adapter-map.json +1 -1
  370. package/presets/zcode/java/hooks/chain-team-phases.sh +314 -1
  371. package/presets/zcode/java/rules/agent-team-orchestrator.md +2 -1
  372. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  373. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +314 -1
  374. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +2 -1
  375. package/presets/zcode/mol/adapter-map.json +1 -1
  376. package/presets/zcode/mol/hooks/chain-team-phases.sh +314 -1
  377. package/presets/zcode/mol/rules/agent-team-orchestrator.md +2 -1
  378. package/presets/zcode/next/MCP.md +2 -0
  379. package/presets/zcode/next/REPO_AGENTS.md +2 -0
  380. package/presets/zcode/next/adapter-map.json +33 -1
  381. package/presets/zcode/next/agents/build-verifier.md +1 -1
  382. package/presets/zcode/next/agents/ci-investigator.md +3 -0
  383. package/presets/zcode/next/agents/code-reviewer.md +1 -0
  384. package/presets/zcode/next/agents/debugger.md +3 -0
  385. package/presets/zcode/next/agents/feature-developer.md +3 -0
  386. package/presets/zcode/next/agents/mockup-reviewer.md +4 -1
  387. package/presets/zcode/next/agents/performance-auditor.md +2 -0
  388. package/presets/zcode/next/agents/playwright-test-generator.md +3 -0
  389. package/presets/zcode/next/agents/playwright-test-healer.md +3 -0
  390. package/presets/zcode/next/agents/playwright-test-planner.md +3 -0
  391. package/presets/zcode/next/agents/qa-tester.md +3 -0
  392. package/presets/zcode/next/agents/task-analyst.md +2 -0
  393. package/presets/zcode/next/ai-local/rules-library/storybook-dev-compare-figma.md +2 -1
  394. package/presets/zcode/next/ai-local/rules-library/ui-change-review-gate.md +1 -0
  395. package/presets/zcode/next/commands/README.md +6 -0
  396. package/presets/zcode/next/commands/task.md +7 -1
  397. package/presets/zcode/next/commands/technical-retro.md +7 -1
  398. package/presets/zcode/next/commands/ui-start.md +81 -0
  399. package/presets/zcode/next/commands/ui-stop.md +74 -0
  400. package/presets/zcode/next/commands/upstream-research.md +1 -1
  401. package/presets/zcode/next/hooks/chain-team-phases.sh +314 -1
  402. package/presets/zcode/next/rules/agent-team-orchestrator.md +2 -1
  403. package/presets/zcode/next/rules/dev-process-lifecycle.md +38 -0
  404. package/presets/zcode/next/rules/next-app-core.md +1 -0
  405. package/presets/zcode/next/skills/figma-fidelity/SKILL.md +4 -1
  406. package/presets/zcode/next/skills/mockup-review/SKILL.md +4 -0
  407. package/presets/zcode/next/team/README.md +5 -1
  408. package/presets/zcode/next/team/upstream/jobs.json +34 -0
  409. package/presets/zcode/nuxt/adapter-map.json +1 -1
  410. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +314 -1
  411. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +2 -1
  412. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  413. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +314 -1
  414. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +2 -1
  415. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  416. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +315 -2
  417. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +2 -1
  418. package/presets/zcode/svelte/adapter-map.json +1 -1
  419. package/presets/zcode/svelte/hooks/chain-team-phases.sh +314 -1
  420. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +2 -1
  421. package/scripts/aggregate-agent-task-metrics.mjs +48 -4
@@ -32,6 +32,7 @@ import {
32
32
  teamDbFail,
33
33
  } from './team-db-schema.mjs';
34
34
  import { projectScheduler, retainRuns } from './team-db-scheduler.mjs';
35
+ import { validateEntrySchema, validateItemSchema, validateLinkIdentity, validateLinkSchema } from './team-db-tracker.mjs';
35
36
 
36
37
  export const SLUG_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
37
38
  export const MAX_RAW_BYTES = 32 * 1024 * 1024;
@@ -1337,6 +1338,358 @@ const projectTask = ({ db, teamRoot, slug, now, searchMode, deadlineAt }) => {
1337
1338
  return { status: existing ? 'updated' : 'inserted', errors };
1338
1339
  };
1339
1340
 
1341
+ /* ------------------------------ tracker walker ----------------------------- */
1342
+
1343
+ const TRACKER_ITEM_DIR = 'tracker/items';
1344
+ const TRACKER_QUEUE_DIR = 'tracker/queue';
1345
+ const TRACKER_LINK_DIR = 'tracker/links';
1346
+
1347
+ const listTrackerJsonFiles = (teamRoot, dirName) => {
1348
+ const dir = path.join(teamRoot, dirName);
1349
+ if (!fs.existsSync(dir)) return [];
1350
+ return fs
1351
+ .readdirSync(dir)
1352
+ .filter((name) => name.endsWith('.json'))
1353
+ .map((name) => name.slice(0, -'.json'.length))
1354
+ .sort();
1355
+ };
1356
+
1357
+ const readTrackerJson = (file) => {
1358
+ try {
1359
+ return { text: fs.readFileSync(file, 'utf8'), error: null };
1360
+ } catch (error) {
1361
+ return { text: null, error: error.message };
1362
+ }
1363
+ };
1364
+
1365
+ const UPSERT_TRACKER_ITEM_SQL = `
1366
+ INSERT INTO tracker_items (
1367
+ id, title, status, priority, type, description, labels_json, source_task,
1368
+ source_refs_json, revision, created_at, updated_at, completed_at, cancelled_at,
1369
+ cancel_reason, superseded_by, history_json, content_hash, parse_error,
1370
+ projected_at, first_seen_at, last_seen_at, absent_at
1371
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)
1372
+ ON CONFLICT(id) DO UPDATE SET
1373
+ title = excluded.title,
1374
+ status = excluded.status,
1375
+ priority = excluded.priority,
1376
+ type = excluded.type,
1377
+ description = excluded.description,
1378
+ labels_json = excluded.labels_json,
1379
+ source_task = excluded.source_task,
1380
+ source_refs_json = excluded.source_refs_json,
1381
+ revision = excluded.revision,
1382
+ created_at = excluded.created_at,
1383
+ updated_at = excluded.updated_at,
1384
+ completed_at = excluded.completed_at,
1385
+ cancelled_at = excluded.cancelled_at,
1386
+ cancel_reason = excluded.cancel_reason,
1387
+ superseded_by = excluded.superseded_by,
1388
+ history_json = excluded.history_json,
1389
+ content_hash = excluded.content_hash,
1390
+ parse_error = excluded.parse_error,
1391
+ projected_at = excluded.projected_at,
1392
+ last_seen_at = excluded.last_seen_at,
1393
+ absent_at = NULL
1394
+ `;
1395
+
1396
+ const UPSERT_TRACKER_ENTRY_SQL = `
1397
+ INSERT INTO tracker_queue (
1398
+ entry_id, item_id, task_slug, link_id, status, reason, requested_by, command, revision,
1399
+ requested_at, claimed_at, finished_at, history_json, content_hash, parse_error,
1400
+ projected_at, first_seen_at, last_seen_at, absent_at
1401
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)
1402
+ ON CONFLICT(entry_id) DO UPDATE SET
1403
+ item_id = excluded.item_id,
1404
+ task_slug = excluded.task_slug,
1405
+ link_id = excluded.link_id,
1406
+ status = excluded.status,
1407
+ reason = excluded.reason,
1408
+ requested_by = excluded.requested_by,
1409
+ command = excluded.command,
1410
+ revision = excluded.revision,
1411
+ requested_at = excluded.requested_at,
1412
+ claimed_at = excluded.claimed_at,
1413
+ finished_at = excluded.finished_at,
1414
+ history_json = excluded.history_json,
1415
+ content_hash = excluded.content_hash,
1416
+ parse_error = excluded.parse_error,
1417
+ projected_at = excluded.projected_at,
1418
+ last_seen_at = excluded.last_seen_at,
1419
+ absent_at = NULL
1420
+ `;
1421
+
1422
+ const UPSERT_TRACKER_LINK_SQL = `
1423
+ INSERT INTO tracker_item_tasks (
1424
+ link_id, item_id, task_slug, entry_id, role, decision, prompt_path, language,
1425
+ revision, created_at, updated_at, history_json, content_hash, parse_error,
1426
+ projected_at, first_seen_at, last_seen_at, absent_at
1427
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NULL)
1428
+ ON CONFLICT(link_id) DO UPDATE SET
1429
+ item_id = excluded.item_id,
1430
+ task_slug = excluded.task_slug,
1431
+ entry_id = excluded.entry_id,
1432
+ role = excluded.role,
1433
+ decision = excluded.decision,
1434
+ prompt_path = excluded.prompt_path,
1435
+ language = excluded.language,
1436
+ revision = excluded.revision,
1437
+ created_at = excluded.created_at,
1438
+ updated_at = excluded.updated_at,
1439
+ history_json = excluded.history_json,
1440
+ content_hash = excluded.content_hash,
1441
+ parse_error = excluded.parse_error,
1442
+ projected_at = excluded.projected_at,
1443
+ last_seen_at = excluded.last_seen_at,
1444
+ absent_at = NULL
1445
+ `;
1446
+
1447
+ /**
1448
+ * One tracker item: parse, validate, upsert by natural key, replace its deps.
1449
+ * An unchanged `content_hash` only touches `last_seen_at`; a broken file
1450
+ * projects as a recorded `parse_error`, never aborts the run.
1451
+ */
1452
+ const projectTrackerItem = ({ db, teamRoot, stem, now, deadlineAt }) => {
1453
+ if (Date.now() > deadlineAt) teamDbFail('E_DEADLINE', 'projection deadline expired in the tracker walk', 4);
1454
+ const file = path.join(teamRoot, TRACKER_ITEM_DIR, `${stem}.json`);
1455
+ const read = readTrackerJson(file);
1456
+ const contentHash = sha256(read.text ?? '');
1457
+ const existing = db.prepare('SELECT content_hash, absent_at FROM tracker_items WHERE id = ?').get(stem);
1458
+ if (read.text !== null && existing && existing.content_hash === contentHash && existing.absent_at === null) {
1459
+ db.prepare('UPDATE tracker_items SET last_seen_at = ? WHERE id = ?').run(now, stem);
1460
+ return { status: 'unchanged', parseError: null };
1461
+ }
1462
+ let item = null;
1463
+ let parseError = read.error;
1464
+ if (read.text !== null) {
1465
+ try {
1466
+ item = JSON.parse(read.text);
1467
+ } catch (error) {
1468
+ parseError = error.message;
1469
+ }
1470
+ if (item !== null) {
1471
+ try {
1472
+ validateItemSchema(item);
1473
+ } catch (error) {
1474
+ parseError = error instanceof TeamDbError ? `${error.code}: ${error.message}` : error.message;
1475
+ }
1476
+ }
1477
+ }
1478
+ db.prepare(UPSERT_TRACKER_ITEM_SQL).run(
1479
+ stem,
1480
+ item?.title ?? null,
1481
+ item?.status ?? null,
1482
+ Number.isInteger(item?.priority) ? item.priority : null,
1483
+ item?.type ?? null,
1484
+ item?.description ?? null,
1485
+ Array.isArray(item?.labels) ? canonicalJson(item.labels) : null,
1486
+ item?.sourceTask ?? null,
1487
+ Array.isArray(item?.sourceRefs) ? canonicalJson(item.sourceRefs) : null,
1488
+ Number.isInteger(item?.revision) ? item.revision : null,
1489
+ isoTimestamp(item?.createdAt),
1490
+ isoTimestamp(item?.updatedAt),
1491
+ isoTimestamp(item?.completedAt),
1492
+ isoTimestamp(item?.cancelledAt),
1493
+ item?.cancelReason ?? null,
1494
+ item?.supersededBy ?? null,
1495
+ Array.isArray(item?.history) ? canonicalJson(item.history) : null,
1496
+ contentHash,
1497
+ parseError,
1498
+ now,
1499
+ now,
1500
+ now,
1501
+ );
1502
+ db.prepare('DELETE FROM tracker_item_deps WHERE item_id = ?').run(stem);
1503
+ if (Array.isArray(item?.dependsOn)) {
1504
+ const insert = db.prepare('INSERT INTO tracker_item_deps(item_id, dep_id, ordinal) VALUES (?, ?, ?)');
1505
+ item.dependsOn.forEach((dep, ordinal) => insert.run(stem, dep, ordinal));
1506
+ }
1507
+ return { status: existing ? 'updated' : 'inserted', parseError };
1508
+ };
1509
+
1510
+ /** One queue entry: upsert by entry id and replace its derived event rows. */
1511
+ const projectTrackerEntry = ({ db, teamRoot, stem, now, deadlineAt }) => {
1512
+ if (Date.now() > deadlineAt) teamDbFail('E_DEADLINE', 'projection deadline expired in the tracker walk', 4);
1513
+ const file = path.join(teamRoot, TRACKER_QUEUE_DIR, `${stem}.json`);
1514
+ const read = readTrackerJson(file);
1515
+ const contentHash = sha256(read.text ?? '');
1516
+ const existing = db.prepare('SELECT content_hash, absent_at FROM tracker_queue WHERE entry_id = ?').get(stem);
1517
+ if (read.text !== null && existing && existing.content_hash === contentHash && existing.absent_at === null) {
1518
+ db.prepare('UPDATE tracker_queue SET last_seen_at = ? WHERE entry_id = ?').run(now, stem);
1519
+ return { status: 'unchanged', parseError: null };
1520
+ }
1521
+ let entry = null;
1522
+ let parseError = read.error;
1523
+ if (read.text !== null) {
1524
+ try {
1525
+ entry = JSON.parse(read.text);
1526
+ } catch (error) {
1527
+ parseError = error.message;
1528
+ }
1529
+ if (entry !== null) {
1530
+ try {
1531
+ validateEntrySchema(entry);
1532
+ } catch (error) {
1533
+ parseError = error instanceof TeamDbError ? `${error.code}: ${error.message}` : error.message;
1534
+ }
1535
+ }
1536
+ }
1537
+ db.prepare(UPSERT_TRACKER_ENTRY_SQL).run(
1538
+ stem,
1539
+ entry?.itemId ?? null,
1540
+ entry?.taskSlug ?? null,
1541
+ entry?.linkId ?? null,
1542
+ entry?.status ?? null,
1543
+ entry?.reason ?? null,
1544
+ entry?.requestedBy ?? null,
1545
+ entry?.command ?? null,
1546
+ Number.isInteger(entry?.revision) ? entry.revision : null,
1547
+ isoTimestamp(entry?.requestedAt),
1548
+ isoTimestamp(entry?.claimedAt),
1549
+ isoTimestamp(entry?.finishedAt),
1550
+ Array.isArray(entry?.history) ? canonicalJson(entry.history) : null,
1551
+ contentHash,
1552
+ parseError,
1553
+ now,
1554
+ now,
1555
+ now,
1556
+ );
1557
+ db.prepare('DELETE FROM tracker_queue_events WHERE entry_id = ?').run(stem);
1558
+ if (Array.isArray(entry?.history)) {
1559
+ const insert = db.prepare(
1560
+ 'INSERT INTO tracker_queue_events(entry_id, seq, at, type, actor, detail) VALUES (?, ?, ?, ?, ?, ?)',
1561
+ );
1562
+ entry.history.forEach((event, index) => {
1563
+ insert.run(stem, index + 1, isoTimestamp(event?.at), event?.type ?? null, event?.actor ?? null, event?.detail ?? null);
1564
+ });
1565
+ }
1566
+ return { status: existing ? 'updated' : 'inserted', parseError };
1567
+ };
1568
+
1569
+ /** One tracker link: upsert by link id; the prompt file is read through the document plane. */
1570
+ const projectTrackerLink = ({ db, teamRoot, stem, now, deadlineAt }) => {
1571
+ if (Date.now() > deadlineAt) teamDbFail('E_DEADLINE', 'projection deadline expired in the tracker walk', 4);
1572
+ const file = path.join(teamRoot, TRACKER_LINK_DIR, `${stem}.json`);
1573
+ const read = readTrackerJson(file);
1574
+ const contentHash = sha256(read.text ?? '');
1575
+ const existing = db.prepare('SELECT content_hash, absent_at FROM tracker_item_tasks WHERE link_id = ?').get(stem);
1576
+ if (read.text !== null && existing && existing.content_hash === contentHash && existing.absent_at === null) {
1577
+ db.prepare('UPDATE tracker_item_tasks SET last_seen_at = ? WHERE link_id = ?').run(now, stem);
1578
+ return { status: 'unchanged', parseError: null };
1579
+ }
1580
+ let link = null;
1581
+ let parseError = read.error;
1582
+ if (read.text !== null) {
1583
+ try {
1584
+ link = JSON.parse(read.text);
1585
+ } catch (error) {
1586
+ parseError = error.message;
1587
+ }
1588
+ if (link !== null) {
1589
+ try {
1590
+ validateLinkSchema(link);
1591
+ validateLinkIdentity(link, stem);
1592
+ } catch (error) {
1593
+ parseError = error instanceof TeamDbError ? `${error.code}: ${error.message}` : error.message;
1594
+ }
1595
+ }
1596
+ }
1597
+ db.prepare(UPSERT_TRACKER_LINK_SQL).run(
1598
+ stem,
1599
+ link?.itemId ?? null,
1600
+ link?.taskSlug ?? null,
1601
+ link?.entryId ?? null,
1602
+ link?.role ?? null,
1603
+ link?.decision ?? null,
1604
+ link?.promptPath ?? null,
1605
+ link?.language ?? null,
1606
+ Number.isInteger(link?.revision) ? link.revision : null,
1607
+ isoTimestamp(link?.createdAt),
1608
+ isoTimestamp(link?.updatedAt),
1609
+ Array.isArray(link?.history) ? canonicalJson(link.history) : null,
1610
+ contentHash,
1611
+ parseError,
1612
+ now,
1613
+ now,
1614
+ now,
1615
+ );
1616
+ return { status: existing ? 'updated' : 'inserted', parseError };
1617
+ };
1618
+ export function projectTracker({ db, teamRoot, now, deadlineAt = Infinity }) {
1619
+ const seenItems = new Set();
1620
+ const seenEntries = new Set();
1621
+ const seenLinks = new Set();
1622
+ const counters = { inserted: 0, updated: 0, unchanged: 0, failed: 0, absent: 0 };
1623
+ const errors = [];
1624
+ db.exec('BEGIN IMMEDIATE');
1625
+ try {
1626
+ for (const stem of listTrackerJsonFiles(teamRoot, TRACKER_ITEM_DIR)) {
1627
+ seenItems.add(stem);
1628
+ try {
1629
+ const { status, parseError } = projectTrackerItem({ db, teamRoot, stem, now, deadlineAt });
1630
+ counters[status] += 1;
1631
+ if (parseError !== null) {
1632
+ counters.failed += 1;
1633
+ errors.push({ path: `${TRACKER_ITEM_DIR}/${stem}.json`, reason: parseError });
1634
+ }
1635
+ } catch (error) {
1636
+ if (error instanceof TeamDbError) throw error;
1637
+ counters.failed += 1;
1638
+ errors.push({ path: `${TRACKER_ITEM_DIR}/${stem}.json`, reason: error.message });
1639
+ }
1640
+ }
1641
+ for (const stem of listTrackerJsonFiles(teamRoot, TRACKER_QUEUE_DIR)) {
1642
+ seenEntries.add(stem);
1643
+ try {
1644
+ const { status, parseError } = projectTrackerEntry({ db, teamRoot, stem, now, deadlineAt });
1645
+ counters[status] += 1;
1646
+ if (parseError !== null) {
1647
+ counters.failed += 1;
1648
+ errors.push({ path: `${TRACKER_QUEUE_DIR}/${stem}.json`, reason: parseError });
1649
+ }
1650
+ } catch (error) {
1651
+ if (error instanceof TeamDbError) throw error;
1652
+ counters.failed += 1;
1653
+ errors.push({ path: `${TRACKER_QUEUE_DIR}/${stem}.json`, reason: error.message });
1654
+ }
1655
+ }
1656
+ for (const stem of listTrackerJsonFiles(teamRoot, TRACKER_LINK_DIR)) {
1657
+ seenLinks.add(stem);
1658
+ try {
1659
+ const { status, parseError } = projectTrackerLink({ db, teamRoot, stem, now, deadlineAt });
1660
+ counters[status] += 1;
1661
+ if (parseError !== null) {
1662
+ counters.failed += 1;
1663
+ errors.push({ path: `${TRACKER_LINK_DIR}/${stem}.json`, reason: parseError });
1664
+ }
1665
+ } catch (error) {
1666
+ if (error instanceof TeamDbError) throw error;
1667
+ counters.failed += 1;
1668
+ errors.push({ path: `${TRACKER_LINK_DIR}/${stem}.json`, reason: error.message });
1669
+ }
1670
+ }
1671
+ const markAbsent = (table, keyColumn, seen) => {
1672
+ for (const row of db.prepare(`SELECT ${keyColumn} AS key FROM ${table} WHERE absent_at IS NULL`).all()) {
1673
+ if (seen.has(String(row.key))) continue;
1674
+ db.prepare(`UPDATE ${table} SET absent_at = ? WHERE ${keyColumn} = ? AND absent_at IS NULL`).run(now, row.key);
1675
+ counters.absent += 1;
1676
+ }
1677
+ };
1678
+ markAbsent('tracker_items', 'id', seenItems);
1679
+ markAbsent('tracker_queue', 'entry_id', seenEntries);
1680
+ markAbsent('tracker_item_tasks', 'link_id', seenLinks);
1681
+ db.exec('COMMIT');
1682
+ } catch (error) {
1683
+ try {
1684
+ db.exec('ROLLBACK');
1685
+ } catch {
1686
+ /* the transaction may already be gone; the original error is the finding */
1687
+ }
1688
+ throw error;
1689
+ }
1690
+ return { ...counters, errors };
1691
+ }
1692
+
1340
1693
  /* --------------------------- search and lifecycle -------------------------- */
1341
1694
 
1342
1695
  const escapeLike = (value) => value.replace(/[\\%_]/g, '\\$&');
@@ -1464,6 +1817,26 @@ const defaultDeadline = (slug) => (slug ? DEFAULT_SLUG_DEADLINE_MS : Infinity);
1464
1817
  * Returns the `SyncResult` shape; throws `TeamDbError` for database-level
1465
1818
  * failures, usage errors, and deadline expiry.
1466
1819
  */
1820
+ /**
1821
+ * Project only the tracker store. The write verbs call this after a tracker
1822
+ * write so the read-only API sees the new rows without paying for a full task
1823
+ * walk; the next full sync reconciles every other surface.
1824
+ */
1825
+ export function syncTrackerProjection(options = {}) {
1826
+ const handle = openTeamDb({
1827
+ teamRoot: options.teamRoot,
1828
+ dbPath: options.dbPath,
1829
+ env: options.env,
1830
+ });
1831
+ try {
1832
+ const now = (options.now ?? new Date()).toISOString();
1833
+ const deadlineAt = Date.now() + (options.deadlineMs ?? 4_000);
1834
+ return projectTracker({ db: handle.db, teamRoot: handle.teamRoot, now, deadlineAt });
1835
+ } finally {
1836
+ handle.db.close();
1837
+ }
1838
+ }
1839
+
1467
1840
  export function syncProjection(options = {}) {
1468
1841
  const slug = options.slug ?? null;
1469
1842
  const maintain = Boolean(options.maintain || options.vacuum);
@@ -1550,10 +1923,30 @@ export function syncProjection(options = {}) {
1550
1923
  : db.prepare('UPDATE tasks SET absent_at = ? WHERE absent_at IS NULL');
1551
1924
  result.absent += slugs.length ? statement.run(startedAt, ...slugs).changes : statement.run(startedAt).changes;
1552
1925
  }
1553
- if (prune) result.pruned += db.prepare('DELETE FROM tasks WHERE absent_at IS NOT NULL').run().changes;
1554
- // Projection order is tasks -> jobs.json -> runs/** (FK-safe) -> retention.
1555
- // `sync --slug` skips the scheduler so the hook's 4.5 s deadline holds; a
1556
- // full sync reconciles.
1926
+ if (prune) {
1927
+ result.pruned += db.prepare('DELETE FROM tasks WHERE absent_at IS NOT NULL').run().changes;
1928
+ // Tracker rows follow their files: pruning deletes rows marked absent.
1929
+ result.pruned += db.prepare('DELETE FROM tracker_queue WHERE absent_at IS NOT NULL').run().changes;
1930
+ result.pruned += db.prepare('DELETE FROM tracker_items WHERE absent_at IS NOT NULL').run().changes;
1931
+ }
1932
+ // Projection order is tasks -> tracker -> jobs.json -> runs/** (FK-safe)
1933
+ // -> retention. The tracker walk is two bounded listings, runs in slug
1934
+ // mode too, and stays inside the deadline budget (WP3 VERIFY: 200 items
1935
+ // must cost well under 250 ms).
1936
+ {
1937
+ const trackerProjection = projectTracker({
1938
+ db,
1939
+ teamRoot: handle.teamRoot,
1940
+ now: new Date().toISOString(),
1941
+ deadlineAt,
1942
+ });
1943
+ result.inserted += trackerProjection.inserted;
1944
+ result.updated += trackerProjection.updated;
1945
+ result.unchanged += trackerProjection.unchanged;
1946
+ result.absent += trackerProjection.absent;
1947
+ result.failed += trackerProjection.failed;
1948
+ for (const error of trackerProjection.errors) result.errors.push(error);
1949
+ }
1557
1950
  if (!slug) {
1558
1951
  const schedulerProjection = projectScheduler(db, { teamRoot: handle.teamRoot });
1559
1952
  result.failed += schedulerProjection.failed;
@@ -48,6 +48,14 @@ export const STDOUT_FILE = 'stdout.log';
48
48
  export const STDERR_FILE = 'stderr.log';
49
49
  export const PROMPT_FILE = 'prompt.md';
50
50
 
51
+ /**
52
+ * The `{{...}}` vocabulary a pipeline prompt may use: `validateJob` refuses any
53
+ * other token (the definition would render verbatim) and `executeRun` renders
54
+ * exactly this list. One list owns the contract between `payload.promptTemplate`
55
+ * and the render pass.
56
+ */
57
+ export const PROMPT_TOKENS = ['{{job.id}}', '{{run.id}}', '{{run.dir}}', '{{team.root}}', '{{now}}'];
58
+
51
59
  export const JOB_ID_RE = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
52
60
  export const RUN_ID_RE = /^[0-9]{8}T[0-9]{6}Z-[0-9a-f]{8}$/;
53
61
  export const ENV_NAME_RE = /^[A-Z_][A-Z0-9_]{0,63}$/;
@@ -666,6 +674,22 @@ export function validateJob(input, options = {}) {
666
674
  if (fs.existsSync(resolved.resolved) && fs.statSync(resolved.resolved).size > MAX_PROMPT_BYTES) {
667
675
  failField('payload.promptTemplate', `must be at most ${MAX_PROMPT_BYTES} bytes`);
668
676
  }
677
+ // The `{{placeholder}}` contract: every token in the template must be one
678
+ // the scheduler renders, or the definition would run with the raw token
679
+ // left in the prompt. An absent file stays a runtime reason
680
+ // (E_PROMPT_MISSING), not a definition error.
681
+ if (fs.existsSync(resolved.resolved)) {
682
+ const template = fs.readFileSync(resolved.resolved, 'utf8');
683
+ for (const match of template.matchAll(/\{\{([^{}]*)\}\}/g)) {
684
+ const token = match[0];
685
+ if (!PROMPT_TOKENS.includes(token)) {
686
+ failField(
687
+ 'payload.promptTemplate',
688
+ `unknown placeholder ${token}; a pipeline prompt may use ${PROMPT_TOKENS.join(', ')}`,
689
+ );
690
+ }
691
+ }
692
+ }
669
693
  promptTemplate = resolved.value;
670
694
  if (payload.runner === undefined) {
671
695
  failField('payload.runner', 'no runner configured: kind "pipeline" needs payload.runner');
@@ -815,7 +839,7 @@ export function writeStateFile(teamRoot, state) {
815
839
  /**
816
840
  * Read the lease without creating anything. A lease older than
817
841
  * `LEASE_STALE_MS` is reported `stale`, never deleted: the next scheduler start
818
- * overwrites it only after taking its own lock.
842
+ * re-claims it only through its own exclusive create (`wx`).
819
843
  */
820
844
  export function readLease(teamRoot, options = {}) {
821
845
  const paths = schedulerPaths(teamRoot);
@@ -855,6 +879,33 @@ const writeLease = (teamRoot, lease) => {
855
879
  writeAtomic(paths.lock, `${JSON.stringify(lease, null, 2)}\n`);
856
880
  };
857
881
 
882
+ /**
883
+ * Claim the lease with one exclusive create (`wx`): two simultaneous starts
884
+ * cannot both observe no lease and both write one, so the loser refuses
885
+ * exactly like a sequential second start (E_BUSY, exit 4). Returns false when
886
+ * the create lost a race; the caller re-reads and refuses.
887
+ */
888
+ const claimLease = (teamRoot, lease) => {
889
+ const paths = schedulerPaths(teamRoot);
890
+ // The replaced writeLease created the directory through writeAtomic; the
891
+ // exclusive create must do the same, or a bare team root fails with ENOENT.
892
+ // Two contenders both mkdir recursively, then exactly one `wx` wins.
893
+ fs.mkdirSync(path.dirname(paths.lock), { recursive: true, mode: 0o700 });
894
+ let fd;
895
+ try {
896
+ fd = fs.openSync(paths.lock, 'wx', 0o600);
897
+ } catch (error) {
898
+ if (error && error.code === 'EEXIST') return false;
899
+ throw error;
900
+ }
901
+ try {
902
+ fs.writeFileSync(fd, `${JSON.stringify(lease, null, 2)}\n`, 'utf8');
903
+ } finally {
904
+ fs.closeSync(fd);
905
+ }
906
+ return true;
907
+ };
908
+
858
909
  const releaseLease = (teamRoot, pid) => {
859
910
  const paths = schedulerPaths(teamRoot);
860
911
  try {
@@ -1412,8 +1463,12 @@ export function resolveExecutable(command, { platform = process.platform, env =
1412
1463
  return command;
1413
1464
  }
1414
1465
 
1415
- /** A `.cmd`/`.bat` runs through `cmd.exe`, which joins argv into one line. */
1416
- export const quoteWindowsArg = (value) => (/[\s"]/.test(value) ? `"${value.replace(/"/g, '\\"')}"` : value);
1466
+ /**
1467
+ * A `.cmd`/`.bat` runs through `cmd.exe`, which joins argv into one line. The
1468
+ * cmd.exe doubling convention (`""`) keeps an embedded quote inside the
1469
+ * argument; `\"` would end the quoted argument instead.
1470
+ */
1471
+ export const quoteWindowsArg = (value) => (/[\s"]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value);
1417
1472
 
1418
1473
  /* -------------------------------- CLI surface ------------------------------ */
1419
1474
 
@@ -1865,12 +1920,17 @@ async function executeRun(context, job, manifest) {
1865
1920
  if (stats.size > MAX_PROMPT_BYTES) reason = 'E_PROMPT_TOO_LARGE';
1866
1921
  else {
1867
1922
  const template = fs.readFileSync(templatePath, 'utf8');
1868
- const rendered = template
1869
- .replaceAll('{{job.id}}', job.id)
1870
- .replaceAll('{{run.id}}', manifest.runId)
1871
- .replaceAll('{{run.dir}}', runDir)
1872
- .replaceAll('{{team.root}}', teamRoot)
1873
- .replaceAll('{{now}}', startedAt);
1923
+ const tokenValues = {
1924
+ '{{job.id}}': job.id,
1925
+ '{{run.id}}': manifest.runId,
1926
+ '{{run.dir}}': runDir,
1927
+ '{{team.root}}': teamRoot,
1928
+ '{{now}}': startedAt,
1929
+ };
1930
+ const rendered = PROMPT_TOKENS.reduce(
1931
+ (text, token) => text.replaceAll(token, tokenValues[token]),
1932
+ template,
1933
+ );
1874
1934
  const promptPath = path.join(runDir, PROMPT_FILE);
1875
1935
  fs.writeFileSync(promptPath, rendered, { encoding: 'utf8', mode: 0o600 });
1876
1936
  promptRecord = {
@@ -2142,9 +2202,25 @@ export async function runScheduler(options = {}) {
2142
2202
  );
2143
2203
  }
2144
2204
 
2205
+ // Stale takeover stays remove-then-create (D-6): re-read before the delete so
2206
+ // a lease another start reclaimed in the meantime is left standing, and the
2207
+ // exclusive create below refuses instead.
2208
+ if (existing.state === 'stale' && readLease(teamRoot).state === 'stale') {
2209
+ fs.rmSync(schedulerPaths(teamRoot).lock, { force: true });
2210
+ }
2211
+
2145
2212
  const startedAt = new Date().toISOString();
2146
2213
  const lease = { version: LEASE_VERSION, pid: process.pid, host: os.hostname(), startedAt, heartbeatAt: startedAt };
2147
- writeLease(teamRoot, lease);
2214
+ // One exclusive create decides the claim (C3): an EEXIST here means a
2215
+ // simultaneous start created the lease between our read and ours.
2216
+ if (!claimLease(teamRoot, lease)) {
2217
+ const raced = readLease(teamRoot);
2218
+ teamDbFail(
2219
+ 'E_BUSY',
2220
+ `${schedulerPaths(teamRoot).lock} is held by pid ${raced.lease?.pid ?? '?'}; one scheduler per team root`,
2221
+ 4,
2222
+ );
2223
+ }
2148
2224
  fs.mkdirSync(schedulerPaths(teamRoot).runs, { recursive: true, mode: 0o700 });
2149
2225
 
2150
2226
  const handle = openTeamDb({ teamRoot });