@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
@@ -3,11 +3,12 @@
3
3
  *
4
4
  * `node:http` only. The surface is loopback-only by default, sends no CORS
5
5
  * header, and reads files through SQLite rows (never through a request path).
6
- * The six mutating operations — the idempotent rescan, the confirmed task
7
- * delete, and the four job writes (create, update, delete, run-now) — each run
8
- * one bounded child process; the server itself never opens a writable
9
- * connection and the kill switch stops every mutation before a child is
10
- * spawned.
6
+ * The fourteen mutating operations — the idempotent rescan, the confirmed task
7
+ * delete, the four job writes (create, update, delete, run-now), and the eight
8
+ * tracker writes (item create, item update, item delete, enqueue, cancel, task
9
+ * start, task stop, task continue) — each run one bounded child process; the
10
+ * server itself never opens a writable connection and the kill switch stops
11
+ * every mutation before a child is spawned.
11
12
  *
12
13
  * Every SQL statement in this module is a static string with bound parameters.
13
14
  * The only interpolated fragments are the module-level constants `TASK_FILTER`,
@@ -31,6 +32,7 @@ import {
31
32
  readSearchMode,
32
33
  readUserVersion,
33
34
  computeSchemaFingerprint,
35
+ teamRootId,
34
36
  } from './team-db-schema.mjs';
35
37
  import {
36
38
  AGENT_PATTERN,
@@ -60,6 +62,16 @@ import {
60
62
  readLogChunk,
61
63
  readStateFile,
62
64
  } from './team-db-scheduler.mjs';
65
+ import {
66
+ EFFECTIVE_ENTRY_STATUSES,
67
+ EFFECTIVE_ITEM_STATUSES,
68
+ countActiveTasks,
69
+ deriveTrackerOrdering,
70
+ effectiveEntryStatus,
71
+ effectiveLinkState,
72
+ rankCompare,
73
+ readTrackerConfig,
74
+ } from './team-db-tracker.mjs';
63
75
 
64
76
  export const DEFAULT_HOST = '127.0.0.1';
65
77
  export const DEFAULT_PORT = 4178;
@@ -76,6 +88,14 @@ export const JOB_BODY_MAX = 65536;
76
88
  export const JOB_WRITE_CHILD_TIMEOUT_MS = 10000;
77
89
  export const JOB_DELETE_CHILD_TIMEOUT_MS = 30000;
78
90
  export const JOB_RUN_CHILD_TIMEOUT_MS = 10000;
91
+ export const TRACKER_ITEM_BODY_MAX = 16384;
92
+ export const TRACKER_TASK_BODY_MAX = 65536;
93
+ export const TRACKER_TASK_ACTION_BODY_MAX = 1024;
94
+ export const TRACKER_QUEUE_BODY_MAX = 1024;
95
+ export const TRACKER_WRITE_CHILD_TIMEOUT_MS = 10000;
96
+ export const TRACKER_DELETE_CHILD_TIMEOUT_MS = 30000;
97
+ export const TRACKER_DEFAULT_LIMIT = 50;
98
+ export const TRACKER_MAX_LIMIT = 200;
79
99
  export const SCHEDULER_HINT = 'start team-db.mjs schedule';
80
100
  export const LOOPBACK_HOSTS = ['127.0.0.1', 'localhost', '::1'];
81
101
  const CLIENT_HEADERS = {
@@ -96,6 +116,8 @@ const TASK_STATE_SET = new Set(TASK_STATES);
96
116
  const PROFILE_SET = new Set(PROFILES);
97
117
  const EVENT_TYPE_SET = new Set(EVENT_TYPES);
98
118
  const OUTCOME_VALUES = new Set(['completed', 'blocked', 'changes_requested', 'validation_failed', 'skipped']);
119
+ const TRACKER_EFFECTIVE_SET = new Set(EFFECTIVE_ITEM_STATUSES);
120
+ const TRACKER_EFFECTIVE_ENTRY_SET = new Set(EFFECTIVE_ENTRY_STATUSES);
99
121
  const CODE_STATUS_ROWS = [
100
122
  ['E_BAD_REQUEST', 400],
101
123
  ['E_FORBIDDEN_HOST', 403],
@@ -316,6 +338,27 @@ const SQL = {
316
338
  SELECT DISTINCT slug FROM tasks
317
339
  WHERE slug LIKE ?1 ESCAPE '\\' OR title LIKE ?1 ESCAPE '\\'
318
340
  LIMIT ?2`,
341
+ // The tracker read plane: projected rows only, a broken row (parse_error)
342
+ // is recorded in the projection but never served, mirroring the CLI path
343
+ // which records the error and drops the record from the snapshot.
344
+ listTrackerItems: `SELECT * FROM tracker_items
345
+ WHERE absent_at IS NULL AND parse_error IS NULL ORDER BY id`,
346
+ getTrackerItem: 'SELECT * FROM tracker_items WHERE id = ?1 AND absent_at IS NULL AND parse_error IS NULL',
347
+ listTrackerDeps: 'SELECT item_id, dep_id FROM tracker_item_deps ORDER BY item_id, ordinal',
348
+ listTrackerEntries: `SELECT * FROM tracker_queue
349
+ WHERE absent_at IS NULL AND parse_error IS NULL ORDER BY entry_id`,
350
+ getTrackerEntry: 'SELECT * FROM tracker_queue WHERE entry_id = ?1 AND absent_at IS NULL AND parse_error IS NULL',
351
+ listTrackerEntriesForItem: `SELECT * FROM tracker_queue
352
+ WHERE item_id = ?1 AND absent_at IS NULL AND parse_error IS NULL ORDER BY entry_id`,
353
+ listTrackerLinks: `SELECT * FROM tracker_item_tasks
354
+ WHERE absent_at IS NULL AND parse_error IS NULL ORDER BY item_id, created_at, link_id`,
355
+ getTrackerLink: 'SELECT * FROM tracker_item_tasks WHERE link_id = ?1 AND absent_at IS NULL AND parse_error IS NULL',
356
+ listTrackerLinksForItem: `SELECT * FROM tracker_item_tasks
357
+ WHERE item_id = ?1 AND absent_at IS NULL AND parse_error IS NULL ORDER BY created_at, link_id`,
358
+ listTrackerLinksForTask: `SELECT * FROM tracker_item_tasks
359
+ WHERE task_slug = ?1 AND absent_at IS NULL AND parse_error IS NULL ORDER BY created_at, link_id`,
360
+ listTrackerTaskRows: 'SELECT slug, state, start_at, end_at FROM tasks WHERE absent_at IS NULL',
361
+ getTrackerTaskRow: 'SELECT state, start_at, end_at FROM tasks WHERE slug = ?1 AND absent_at IS NULL',
319
362
  };
320
363
 
321
364
  /* ------------------------------- validation -------------------------------- */
@@ -372,6 +415,14 @@ const parseQuery = (value, name) => {
372
415
  return value;
373
416
  };
374
417
 
418
+ const parseItemId = (value, parameter = 'id') => {
419
+ const id = typeof value === 'number' ? value : /^[0-9]+$/.test(String(value)) ? Number(value) : NaN;
420
+ if (!Number.isInteger(id) || id < 1) {
421
+ fail('E_VALIDATION', 422, `${parameter} must be a positive integer`, { parameter });
422
+ }
423
+ return id;
424
+ };
425
+
375
426
  const parseSlug = (value) => {
376
427
  if (typeof value !== 'string' || !slugPattern.test(value)) fail('E_BAD_REQUEST', 400, 'slug must match ^[a-z0-9]+(?:-[a-z0-9]+)*$');
377
428
  return value;
@@ -944,6 +995,9 @@ const getHealth = (handle, settings) => {
944
995
  }).length;
945
996
  return {
946
997
  status: 'ok',
998
+ // Repository identity: the hash, never the path. Additive and optional, so a
999
+ // v1 consumer that predates the field ignores it.
1000
+ rootId: teamRootId(settings.teamRoot),
947
1001
  db: {
948
1002
  file: path.basename(settings.dbPath),
949
1003
  present: true,
@@ -953,7 +1007,7 @@ const getHealth = (handle, settings) => {
953
1007
  },
954
1008
  tasks: { total: Number(totals.total), absent: Number(totals.absent) },
955
1009
  projectedAt: totals.projected_at ?? null,
956
- capabilities: ['sync', 'delete', 'jobs', 'schedule'],
1010
+ capabilities: ['sync', 'delete', 'jobs', 'schedule', 'tracker'],
957
1011
  scheduler: {
958
1012
  state: lease.state,
959
1013
  pid: lease.lease?.pid === undefined ? null : Number(lease.lease.pid),
@@ -1403,6 +1457,686 @@ const runDeleteChild = async (slug, context) => {
1403
1457
  return { slug: parsed.slug };
1404
1458
  };
1405
1459
 
1460
+ /* --------------------------------- tracker -------------------------------- */
1461
+
1462
+ const parseJsonArrayColumn = (text) => {
1463
+ try {
1464
+ const parsed = JSON.parse(text ?? '[]');
1465
+ return Array.isArray(parsed) ? parsed : [];
1466
+ } catch {
1467
+ return [];
1468
+ }
1469
+ };
1470
+
1471
+ /** A projected row back into the file shape the shared ordering consumes. */
1472
+ const trackerItemFromRow = (row, dependsOn) => ({
1473
+ schemaVersion: 1,
1474
+ id: Number(row.id),
1475
+ revision: Number.isInteger(row.revision) ? row.revision : 1,
1476
+ title: row.title ?? '',
1477
+ status: row.status ?? 'planned',
1478
+ priority: Number.isInteger(row.priority) ? row.priority : 5,
1479
+ type: row.type ?? 'feature',
1480
+ description: row.description ?? null,
1481
+ labels: parseJsonArrayColumn(row.labels_json),
1482
+ history: parseJsonArrayColumn(row.history_json),
1483
+ dependsOn,
1484
+ sourceTask: row.source_task ?? null,
1485
+ sourceRefs: parseJsonArrayColumn(row.source_refs_json),
1486
+ createdAt: row.created_at ?? '1970-01-01T00:00:00.000Z',
1487
+ updatedAt: row.updated_at ?? '1970-01-01T00:00:00.000Z',
1488
+ completedAt: row.completed_at ?? null,
1489
+ cancelledAt: row.cancelled_at ?? null,
1490
+ cancelReason: row.cancel_reason ?? null,
1491
+ supersededBy: row.superseded_by ?? null,
1492
+ });
1493
+
1494
+ const trackerEntryFromRow = (row) => ({
1495
+ schemaVersion: 1,
1496
+ entryId: row.entry_id,
1497
+ itemId: Number(row.item_id),
1498
+ taskSlug: row.task_slug ?? null,
1499
+ linkId: row.link_id ?? null,
1500
+ status: row.status ?? 'queued',
1501
+ reason: row.reason ?? '',
1502
+ requestedBy: row.requested_by ?? '',
1503
+ command: row.command ?? null,
1504
+ revision: Number.isInteger(row.revision) ? row.revision : 1,
1505
+ requestedAt: row.requested_at ?? '1970-01-01T00:00:00.000Z',
1506
+ claimedAt: row.claimed_at ?? null,
1507
+ finishedAt: row.finished_at ?? null,
1508
+ history: parseJsonArrayColumn(row.history_json),
1509
+ });
1510
+
1511
+ const trackerLinkFromRow = (row) => ({
1512
+ schemaVersion: 1,
1513
+ linkId: row.link_id,
1514
+ itemId: Number(row.item_id),
1515
+ taskSlug: row.task_slug,
1516
+ entryId: row.entry_id ?? null,
1517
+ role: row.role ?? 'primary',
1518
+ decision: row.decision ?? 'requested',
1519
+ promptPath: row.prompt_path ?? null,
1520
+ language: row.language ?? null,
1521
+ revision: Number.isInteger(row.revision) ? row.revision : 1,
1522
+ createdAt: row.created_at ?? '1970-01-01T00:00:00.000Z',
1523
+ updatedAt: row.updated_at ?? '1970-01-01T00:00:00.000Z',
1524
+ history: parseJsonArrayColumn(row.history_json),
1525
+ });
1526
+
1527
+ /**
1528
+ * One snapshot of the projected tracker. The record shapes are the files'
1529
+ * own, so the shared `deriveTrackerOrdering` sees the same input on the CLI
1530
+ * path and the SQL read plane and the two can never disagree (D-4).
1531
+ */
1532
+ const readTrackerSnapshotRows = (db) => {
1533
+ const items = new Map();
1534
+ const entries = new Map();
1535
+ const links = new Map();
1536
+ const taskRows = new Map();
1537
+ for (const row of db.prepare(SQL.listTrackerTaskRows).all()) {
1538
+ taskRows.set(row.slug, { state: row.state ?? null, startAt: row.start_at ?? null, endAt: row.end_at ?? null });
1539
+ }
1540
+ const depsByItem = new Map();
1541
+ for (const dep of db.prepare(SQL.listTrackerDeps).all()) {
1542
+ if (!depsByItem.has(dep.item_id)) depsByItem.set(dep.item_id, []);
1543
+ depsByItem.get(dep.item_id).push(dep.dep_id);
1544
+ }
1545
+ for (const row of db.prepare(SQL.listTrackerItems).all()) {
1546
+ items.set(row.id, trackerItemFromRow(row, depsByItem.get(row.id) ?? []));
1547
+ }
1548
+ for (const row of db.prepare(SQL.listTrackerEntries).all()) {
1549
+ entries.set(row.entry_id, trackerEntryFromRow(row));
1550
+ }
1551
+ for (const row of db.prepare(SQL.listTrackerLinks).all()) {
1552
+ links.set(row.link_id, trackerLinkFromRow(row));
1553
+ }
1554
+ const taskStates = new Map();
1555
+ for (const [slug, row] of taskRows) taskStates.set(slug, row.state);
1556
+ return { items, entries, links, taskRows, taskStates };
1557
+ };
1558
+
1559
+ const trackerItemJson = (annotated) => {
1560
+ const item = annotated.item;
1561
+ return {
1562
+ schemaVersion: 1,
1563
+ id: item.id,
1564
+ revision: item.revision,
1565
+ title: item.title,
1566
+ status: item.status,
1567
+ priority: item.priority,
1568
+ type: item.type,
1569
+ description: item.description,
1570
+ labels: item.labels,
1571
+ history: item.history,
1572
+ dependsOn: item.dependsOn,
1573
+ sourceTask: item.sourceTask,
1574
+ sourceRefs: item.sourceRefs,
1575
+ createdAt: item.createdAt,
1576
+ updatedAt: item.updatedAt,
1577
+ completedAt: item.completedAt,
1578
+ cancelledAt: item.cancelledAt,
1579
+ cancelReason: item.cancelReason,
1580
+ supersededBy: item.supersededBy,
1581
+ effectiveStatus: annotated.effectiveStatus,
1582
+ taskState: annotated.taskState,
1583
+ ready: annotated.ready,
1584
+ waitingOn: annotated.waitingOn,
1585
+ queueEntryId: annotated.queueEntryId,
1586
+ queuedAt: annotated.queuedAt,
1587
+ };
1588
+ };
1589
+
1590
+ const trackerItemSummaryJson = (annotated) => {
1591
+ const item = annotated.item;
1592
+ return {
1593
+ id: item.id,
1594
+ title: item.title,
1595
+ status: item.status,
1596
+ effectiveStatus: annotated.effectiveStatus,
1597
+ priority: item.priority,
1598
+ type: item.type,
1599
+ description: item.description,
1600
+ labels: item.labels,
1601
+ dependsOn: item.dependsOn,
1602
+ waitingOn: annotated.waitingOn,
1603
+ ready: annotated.ready,
1604
+ sourceTask: item.sourceTask,
1605
+ sourceRefs: item.sourceRefs,
1606
+ taskState: annotated.taskState,
1607
+ createdAt: item.createdAt,
1608
+ updatedAt: item.updatedAt,
1609
+ queueEntryId: annotated.queueEntryId,
1610
+ linkCount: annotated.links?.length ?? 0,
1611
+ linkedTasks: annotated.links?.map((link) => link.taskSlug) ?? [],
1612
+ };
1613
+ };
1614
+
1615
+ const trackerQueueEntryJson = (entry, taskRows, itemTitle) => {
1616
+ const taskSlug = entry.taskSlug ?? `tracker-${entry.itemId}`;
1617
+ const taskRow = taskRows.get(taskSlug);
1618
+ const taskState = taskRow?.state ?? null;
1619
+ return {
1620
+ entryId: entry.entryId,
1621
+ itemId: entry.itemId,
1622
+ taskSlug,
1623
+ linkId: entry.linkId ?? null,
1624
+ status: effectiveEntryStatus(entry, taskState),
1625
+ reason: entry.reason,
1626
+ requestedBy: entry.requestedBy,
1627
+ command: entry.command,
1628
+ revision: entry.revision,
1629
+ requestedAt: entry.requestedAt,
1630
+ claimedAt: entry.claimedAt,
1631
+ finishedAt: entry.finishedAt,
1632
+ history: entry.history,
1633
+ itemTitle,
1634
+ taskState,
1635
+ taskStartAt: taskRow?.startAt ?? null,
1636
+ taskEndAt: taskRow?.endAt ?? null,
1637
+ };
1638
+ };
1639
+
1640
+ const trackerOrdering = (db) => {
1641
+ const snapshot = readTrackerSnapshotRows(db);
1642
+ const asOf = new Date().toISOString();
1643
+ const ordering = deriveTrackerOrdering({ ...snapshot, asOf });
1644
+ return { snapshot, ordering, asOf };
1645
+ };
1646
+
1647
+ const listTrackerItems = (db, query, settings) => {
1648
+ const limit = parseInteger(query.get('limit'), 'limit', { min: 1, max: TRACKER_MAX_LIMIT, fallback: TRACKER_DEFAULT_LIMIT });
1649
+ const offset = parseInteger(query.get('offset'), 'offset', { min: 0, max: MAX_OFFSET, fallback: 0 });
1650
+ const statuses = parseCsv(query.get('status'), 'status', TRACKER_EFFECTIVE_SET);
1651
+ const ready = parseBoolean(query.get('ready'), 'ready', null);
1652
+ const sourceTask = parsePattern(query.get('sourceTask'), 'sourceTask', slugPattern, 64);
1653
+ const { snapshot, ordering, asOf } = trackerOrdering(db);
1654
+ let ranked = [...ordering.byId.values()].sort((left, right) => rankCompare(left.item, right.item));
1655
+ if (statuses.length > 0) ranked = ranked.filter((annotated) => statuses.includes(annotated.effectiveStatus));
1656
+ if (ready !== null) ranked = ranked.filter((annotated) => annotated.ready === ready);
1657
+ if (sourceTask !== '') ranked = ranked.filter((annotated) => annotated.item.sourceTask === sourceTask);
1658
+ const total = ranked.length;
1659
+ const items = ranked.slice(offset, offset + limit).map(trackerItemSummaryJson);
1660
+ return {
1661
+ items,
1662
+ total,
1663
+ limit,
1664
+ offset,
1665
+ nextOffset: offset + items.length < total ? offset + items.length : null,
1666
+ asOf,
1667
+ readyCount: ordering.readyIds.length,
1668
+ criticalPathIds: ordering.criticalPathIds,
1669
+ maxActive: readTrackerConfig(settings.teamRoot).maxActive,
1670
+ activeCount: countActiveTasks(snapshot.taskStates),
1671
+ };
1672
+ };
1673
+
1674
+ const readLatestTaskRun = (teamRoot, taskSlug) => {
1675
+ if (typeof teamRoot !== 'string' || teamRoot === '') return null;
1676
+ const dir = path.join(teamRoot, 'task-runs', taskSlug);
1677
+ if (!fs.existsSync(dir)) return null;
1678
+ const runIds = fs
1679
+ .readdirSync(dir)
1680
+ .filter((name) => RUN_ID_RE.test(name))
1681
+ .sort()
1682
+ .reverse();
1683
+ for (const runId of runIds) {
1684
+ try {
1685
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, runId, 'run.json'), 'utf8'));
1686
+ return {
1687
+ runId,
1688
+ state: typeof manifest.state === 'string' ? manifest.state : 'unknown',
1689
+ startedAt: manifest.startedAt ?? null,
1690
+ finishedAt: manifest.finishedAt ?? null,
1691
+ error: manifest.error ?? null,
1692
+ };
1693
+ } catch {
1694
+ /* an incomplete run directory is not a run record */
1695
+ }
1696
+ }
1697
+ return null;
1698
+ };
1699
+
1700
+ const trackerItemDetail = (db, id, teamRoot = null) => {
1701
+ const { snapshot, ordering } = trackerOrdering(db);
1702
+ const annotated = ordering.byId.get(id);
1703
+ if (!annotated) fail('E_NOT_FOUND', 404, `no tracker item "${id}"`);
1704
+ const dependencies = (annotated.item.dependsOn ?? []).map((depId) => {
1705
+ const dep = ordering.byId.get(depId);
1706
+ return {
1707
+ id: depId,
1708
+ title: dep?.item.title ?? String(depId),
1709
+ status: dep?.effectiveStatus ?? 'planned',
1710
+ satisfied: dep?.effectiveStatus === 'completed',
1711
+ };
1712
+ });
1713
+ const dependents = [...ordering.byId.values()]
1714
+ .filter((other) => (other.item.dependsOn ?? []).includes(id))
1715
+ .sort((left, right) => rankCompare(left.item, right.item))
1716
+ .map((other) => ({
1717
+ id: other.item.id,
1718
+ title: other.item.title,
1719
+ status: other.effectiveStatus,
1720
+ satisfied: annotated.effectiveStatus === 'completed',
1721
+ }));
1722
+ const links = [...snapshot.links.values()].filter((link) => link.itemId === id);
1723
+ if (links.length === 0 && snapshot.taskRows.has(String(id))) {
1724
+ links.push({
1725
+ schemaVersion: 1,
1726
+ linkId: `${id}--${id}`,
1727
+ itemId: id,
1728
+ taskSlug: String(id),
1729
+ entryId: null,
1730
+ role: 'primary',
1731
+ decision: 'requested',
1732
+ promptPath: null,
1733
+ language: null,
1734
+ revision: 0,
1735
+ createdAt: annotated.item.createdAt,
1736
+ updatedAt: annotated.item.updatedAt,
1737
+ history: [],
1738
+ legacy: true,
1739
+ });
1740
+ }
1741
+ const tasks = links
1742
+ .map((link) => {
1743
+ const taskRow = snapshot.taskRows.get(link.taskSlug) ?? null;
1744
+ const entry = link.entryId === null ? null : (snapshot.entries.get(link.entryId) ?? null);
1745
+ return {
1746
+ ...link,
1747
+ effectiveState: effectiveLinkState(link, entry, taskRow?.state ?? null),
1748
+ latestRun: readLatestTaskRun(teamRoot, link.taskSlug),
1749
+ taskState: taskRow?.state ?? null,
1750
+ taskStartAt: taskRow?.startAt ?? null,
1751
+ taskEndAt: taskRow?.endAt ?? null,
1752
+ entryStatus: entry === null ? null : effectiveEntryStatus(entry, taskRow?.state ?? null),
1753
+ };
1754
+ })
1755
+ .sort((left, right) => left.createdAt.localeCompare(right.createdAt) || left.linkId.localeCompare(right.linkId));
1756
+ const queue = [...snapshot.entries.values()]
1757
+ .filter((entry) => entry.itemId === id)
1758
+ .map((entry) => trackerQueueEntryJson(entry, snapshot.taskRows, annotated.item.title));
1759
+ return {
1760
+ item: trackerItemJson(annotated),
1761
+ dependencies,
1762
+ dependents,
1763
+ queue,
1764
+ tasks,
1765
+ criticalPath: ordering.criticalPathIds,
1766
+ };
1767
+ };
1768
+
1769
+ const listTrackerQueue = (db, query) => {
1770
+ const limit = parseInteger(query.get('limit'), 'limit', { min: 1, max: TRACKER_MAX_LIMIT, fallback: TRACKER_DEFAULT_LIMIT });
1771
+ const offset = parseInteger(query.get('offset'), 'offset', { min: 0, max: MAX_OFFSET, fallback: 0 });
1772
+ const statuses = parseCsv(query.get('status'), 'status', TRACKER_EFFECTIVE_ENTRY_SET);
1773
+ const itemId = query.get('itemId') === null ? null : parseItemId(query.get('itemId'), 'itemId');
1774
+ const snapshot = readTrackerSnapshotRows(db);
1775
+ let items = [...snapshot.entries.values()]
1776
+ .filter((entry) => itemId === null || entry.itemId === itemId)
1777
+ .map((entry) => trackerQueueEntryJson(entry, snapshot.taskRows, snapshot.items.get(entry.itemId)?.title ?? String(entry.itemId)));
1778
+ if (statuses.length > 0) items = items.filter((entry) => statuses.includes(entry.status));
1779
+ const total = items.length;
1780
+ const pageItems = items.slice(offset, offset + limit);
1781
+ const activeEntryId = items.find((entry) => entry.status === 'active')?.entryId ?? null;
1782
+ return {
1783
+ items: pageItems,
1784
+ total,
1785
+ limit,
1786
+ offset,
1787
+ nextOffset: offset + pageItems.length < total ? offset + pageItems.length : null,
1788
+ asOf: new Date().toISOString(),
1789
+ activeEntryId,
1790
+ };
1791
+ };
1792
+
1793
+ const parseTrackerBody = (context, noun) => {
1794
+ const text = context.body.toString('utf8').trim();
1795
+ if (text === '') fail('E_VALIDATION', 422, `${noun} is required`, { parameter: 'body' });
1796
+ try {
1797
+ return JSON.parse(text);
1798
+ } catch {
1799
+ fail('E_VALIDATION', 422, `${noun} is not valid JSON`, { parameter: 'body' });
1800
+ }
1801
+ return null;
1802
+ };
1803
+
1804
+ const parseEntryId = (value) => {
1805
+ if (typeof value !== 'string' || !RUN_ID_RE.test(value)) {
1806
+ fail('E_VALIDATION', 422, 'the entry id has an invalid shape', { parameter: 'entryId' });
1807
+ }
1808
+ return value;
1809
+ };
1810
+
1811
+ /**
1812
+ * One child refusal back into the documented envelope. The CLI code travels in
1813
+ * `details.code` (additionalProperties); the transport code is per mutation
1814
+ * because the same CLI code means a different refusal on a different verb.
1815
+ */
1816
+ const failTrackerRefusal = (result, transportByCode) => {
1817
+ const code = typeof result.code === 'string' ? result.code : 'E_INTERNAL';
1818
+ const [transport, status] = transportByCode.get(code) ?? ['E_INTERNAL', 500];
1819
+ fail(transport, status, String(result.message ?? 'the tracker write was refused'), { code });
1820
+ };
1821
+
1822
+ const CREATE_ITEM_REFUSALS = new Map([
1823
+ ['E_TRACKER_DUPLICATE_ID', ['E_CONFLICT', 409]],
1824
+ ['E_ID_COLLISION', ['E_VALIDATION', 422]],
1825
+ ['E_SCHEMA', ['E_VALIDATION', 422]],
1826
+ ['E_TRACKER_UNKNOWN_DEP', ['E_VALIDATION', 422]],
1827
+ ['E_TRACKER_CYCLE', ['E_VALIDATION', 422]],
1828
+ ['E_TRACKER_SELF_DEP', ['E_VALIDATION', 422]],
1829
+ ['E_TRACKER_BUSY', ['E_BUSY', 503]],
1830
+ ]);
1831
+
1832
+ const UPDATE_ITEM_REFUSALS = new Map([
1833
+ ['E_TRACKER_REVISION', ['E_CONFLICT', 409]],
1834
+ ['E_TRACKER_TRANSITION', ['E_CONFLICT', 409]],
1835
+ ['E_SCHEMA', ['E_VALIDATION', 422]],
1836
+ ['E_TRACKER_UNKNOWN_DEP', ['E_VALIDATION', 422]],
1837
+ ['E_TRACKER_CYCLE', ['E_VALIDATION', 422]],
1838
+ ['E_TRACKER_SELF_DEP', ['E_VALIDATION', 422]],
1839
+ ['E_TRACKER_BUSY', ['E_BUSY', 503]],
1840
+ ]);
1841
+
1842
+ const ENQUEUE_REFUSALS = new Map([
1843
+ ['E_TRACKER_TRANSITION', ['E_CONFLICT', 409]],
1844
+ ['E_SCHEMA', ['E_VALIDATION', 422]],
1845
+ ['E_TRACKER_UNKNOWN_DEP', ['E_VALIDATION', 422]],
1846
+ ['E_TRACKER_BUSY', ['E_BUSY', 503]],
1847
+ ]);
1848
+
1849
+ const CANCEL_REFUSALS = new Map([
1850
+ ['E_TRACKER_TRANSITION', ['E_CONFLICT', 409]],
1851
+ ['E_SCHEMA', ['E_VALIDATION', 422]],
1852
+ ['E_TRACKER_UNKNOWN_DEP', ['E_NOT_FOUND', 404]],
1853
+ ['E_TRACKER_BUSY', ['E_BUSY', 503]],
1854
+ ]);
1855
+
1856
+ const DELETE_ITEM_REFUSALS = new Map([
1857
+ ['E_TRACKER_UNKNOWN_DEP', ['E_NOT_FOUND', 404]],
1858
+ ['E_TRACKER_LINK_ACTIVE', ['E_CONFLICT', 409]],
1859
+ ['E_TRACKER_QUEUE_ACTIVE', ['E_CONFLICT', 409]],
1860
+ ['E_SCHEMA', ['E_VALIDATION', 422]],
1861
+ ['E_TRACKER_BUSY', ['E_BUSY', 503]],
1862
+ ]);
1863
+
1864
+ const START_TASK_REFUSALS = new Map([
1865
+ ['E_TRACKER_UNKNOWN_DEP', ['E_NOT_FOUND', 404]],
1866
+ ['E_TRACKER_LINK_EXISTS', ['E_CONFLICT', 409]],
1867
+ ['E_TRACKER_TRANSITION', ['E_CONFLICT', 409]],
1868
+ ['E_SCHEMA', ['E_VALIDATION', 422]],
1869
+ ['E_TRACKER_BUSY', ['E_BUSY', 503]],
1870
+ ]);
1871
+
1872
+ const STOP_TASK_REFUSALS = new Map([
1873
+ ['E_TRACKER_UNKNOWN_DEP', ['E_NOT_FOUND', 404]],
1874
+ ['E_TRACKER_LINK_UNKNOWN', ['E_NOT_FOUND', 404]],
1875
+ ['E_TRACKER_TRANSITION', ['E_CONFLICT', 409]],
1876
+ ['E_SCHEMA', ['E_VALIDATION', 422]],
1877
+ ['E_TRACKER_BUSY', ['E_BUSY', 503]],
1878
+ ['E_RUNNER_OFFLINE', ['E_CONFLICT', 409]],
1879
+ ['E_RUNNER_BUSY', ['E_CONFLICT', 409]],
1880
+ ['E_RUNNER_PID_MISMATCH', ['E_CONFLICT', 409]],
1881
+ ]);
1882
+
1883
+ const parseTaskSlug = (value) => {
1884
+ if (typeof value !== 'string' || !slugPattern.test(value) || value.length < 3 || value.length > 48) {
1885
+ fail('E_VALIDATION', 422, 'taskSlug must match the slug grammar with 3-48 characters', { parameter: 'taskSlug' });
1886
+ }
1887
+ return value;
1888
+ };
1889
+
1890
+ const trackerQueueEntryById = (db, entryId) => {
1891
+ const row = db.prepare(SQL.getTrackerEntry).get(entryId);
1892
+ if (!row) fail('E_NOT_FOUND', 404, `no queue entry "${entryId}"`);
1893
+ const entry = trackerEntryFromRow(row);
1894
+ const taskSlug = entry.taskSlug ?? `tracker-${entry.itemId}`;
1895
+ const taskRow = db.prepare(SQL.getTrackerTaskRow).get(taskSlug);
1896
+ const item = db.prepare(SQL.getTrackerItem).get(entry.itemId);
1897
+ const taskRows = new Map();
1898
+ if (taskRow) {
1899
+ taskRows.set(taskSlug, { state: taskRow.state ?? null, startAt: taskRow.start_at ?? null, endAt: taskRow.end_at ?? null });
1900
+ }
1901
+ return trackerQueueEntryJson(entry, taskRows, item?.title ?? String(entry.itemId));
1902
+ };
1903
+
1904
+ const createTrackerItem = async (context) => {
1905
+ const parsed = parseTrackerBody(context, 'an item body');
1906
+ const result = await runTeamDbChild(['tracker', 'add', '--file', '-'], {
1907
+ settings: context.settings,
1908
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
1909
+ input: JSON.stringify(parsed),
1910
+ label: 'tracker create',
1911
+ });
1912
+ if (result.ok !== true || typeof result.item?.id !== 'number') {
1913
+ failTrackerRefusal(result, CREATE_ITEM_REFUSALS);
1914
+ }
1915
+ return { json: trackerItemDetail(context.db(), result.item.id, context.settings.teamRoot), status: 201 };
1916
+ };
1917
+
1918
+ const updateTrackerItem = async (context) => {
1919
+ const id = parseItemId(context.params.id);
1920
+ const parsed = parseTrackerBody(context, 'an item body');
1921
+ if (parsed && parsed.id !== undefined && parsed.id !== id) {
1922
+ fail('E_CONFLICT', 409, 'the body id differs from the path id; the id is immutable');
1923
+ }
1924
+ const db = context.db();
1925
+ if (!db.prepare(SQL.getTrackerItem).get(id)) fail('E_NOT_FOUND', 404, `no tracker item "${id}"`);
1926
+ // The frozen route table refuses an update while a live entry exists: the
1927
+ // launch request must be cancelled before the item it targets can change.
1928
+ const live = db
1929
+ .prepare(SQL.listTrackerEntriesForItem)
1930
+ .all(id)
1931
+ .map((row) => trackerEntryFromRow(row))
1932
+ .some((entry) => {
1933
+ const taskRow = db.prepare(SQL.getTrackerTaskRow).get(entry.taskSlug ?? `tracker-${entry.itemId}`);
1934
+ return !['cancelled', 'expired', 'done'].includes(effectiveEntryStatus(entry, taskRow?.state ?? null));
1935
+ });
1936
+ if (live) fail('E_CONFLICT', 409, `item "${id}" has a live queue entry; cancel it first`);
1937
+ const result = await runTeamDbChild(['tracker', 'set', id, '--file', '-'], {
1938
+ settings: context.settings,
1939
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
1940
+ input: JSON.stringify(parsed),
1941
+ label: 'tracker update',
1942
+ });
1943
+ if (result.ok !== true || typeof result.item?.id !== 'number') {
1944
+ failTrackerRefusal(result, UPDATE_ITEM_REFUSALS);
1945
+ }
1946
+ return { json: trackerItemDetail(db, id, context.settings.teamRoot) };
1947
+ };
1948
+
1949
+ const enqueueTrackerItem = async (context) => {
1950
+ const parsed = parseTrackerBody(context, 'an enqueue body');
1951
+ const itemId = parseItemId(parsed?.itemId, 'itemId');
1952
+ const db = context.db();
1953
+ if (!db.prepare(SQL.getTrackerItem).get(itemId)) fail('E_NOT_FOUND', 404, `no tracker item "${itemId}"`);
1954
+ const result = await runTeamDbChild(['tracker', 'enqueue', '--file', '-'], {
1955
+ settings: context.settings,
1956
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
1957
+ input: JSON.stringify(parsed),
1958
+ label: 'tracker enqueue',
1959
+ });
1960
+ if (result.ok !== true || typeof result.entry?.entryId !== 'string') {
1961
+ failTrackerRefusal(result, ENQUEUE_REFUSALS);
1962
+ }
1963
+ return { json: trackerQueueEntryById(db, result.entry.entryId), status: result.existing ? 200 : 201 };
1964
+ };
1965
+
1966
+ const cancelTrackerQueueEntry = async (context) => {
1967
+ const entryId = parseEntryId(context.params.entryId);
1968
+ const text = context.body.toString('utf8').trim();
1969
+ if (text !== '' && text !== '{}') {
1970
+ fail('E_VALIDATION', 422, 'the cancel accepts no request body', { parameter: 'body' });
1971
+ }
1972
+ const db = context.db();
1973
+ if (!db.prepare(SQL.getTrackerEntry).get(entryId)) fail('E_NOT_FOUND', 404, `no queue entry "${entryId}"`);
1974
+ const result = await runTeamDbChild(['tracker', 'cancel', entryId], {
1975
+ settings: context.settings,
1976
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
1977
+ label: 'tracker cancel',
1978
+ });
1979
+ if (result.ok !== true || typeof result.entry?.entryId !== 'string') {
1980
+ failTrackerRefusal(result, CANCEL_REFUSALS);
1981
+ }
1982
+ return { json: trackerQueueEntryById(db, entryId) };
1983
+ };
1984
+
1985
+ const deleteTrackerItem = async (context) => {
1986
+ const id = parseItemId(context.params.id);
1987
+ if (isKillSwitchSet()) fail('E_DISABLED', 503, 'the projection is disabled by AI_RULES_TEAM_DB_DISABLE');
1988
+ const db = context.db();
1989
+ if (!db.prepare(SQL.getTrackerItem).get(id)) fail('E_NOT_FOUND', 404, `no tracker item "${id}"`);
1990
+ const result = await runTeamDbChild(['tracker', 'delete', id, '--json'], {
1991
+ settings: context.settings,
1992
+ timeoutMs: TRACKER_DELETE_CHILD_TIMEOUT_MS,
1993
+ label: 'tracker delete',
1994
+ });
1995
+ if (result.ok !== true || result.id !== id) {
1996
+ failTrackerRefusal(result, DELETE_ITEM_REFUSALS);
1997
+ }
1998
+ return { json: { id } };
1999
+ };
2000
+
2001
+ const startTrackerTask = async (context) => {
2002
+ const id = parseItemId(context.params.id);
2003
+ const parsed = parseTrackerBody(context, 'a task start body');
2004
+ const taskSlug = parseTaskSlug(parsed?.taskSlug ?? `tracker-${id}`);
2005
+ const db = context.db();
2006
+ const itemRow = db.prepare(SQL.getTrackerItem).get(id);
2007
+ if (!itemRow) fail('E_NOT_FOUND', 404, `no tracker item "${id}"`);
2008
+ const existingTaskDir = path.join(context.settings.teamRoot, 'tasks', taskSlug);
2009
+ if (fs.existsSync(existingTaskDir)) {
2010
+ fail(
2011
+ 'E_CONFLICT',
2012
+ 409,
2013
+ `task ${taskSlug} already exists; choose another taskSlug or link the existing task explicitly`,
2014
+ );
2015
+ }
2016
+ const linkId = `${id}--${taskSlug}`;
2017
+ if (db.prepare(SQL.getTrackerLink).get(linkId)) fail('E_CONFLICT', 409, `link ${linkId} already exists`);
2018
+ const reason = typeof parsed?.reason === 'string' && parsed.reason.trim() !== ''
2019
+ ? parsed.reason
2020
+ : `Start ${taskSlug} from tracker item ${id}`;
2021
+ const requestedBy = typeof parsed?.requestedBy === 'string' && parsed.requestedBy.trim() !== ''
2022
+ ? parsed.requestedBy
2023
+ : 'operator';
2024
+ const linkResult = await runTeamDbChild(['tracker', 'link', '--file', '-'], {
2025
+ settings: context.settings,
2026
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2027
+ input: JSON.stringify({
2028
+ action: 'add',
2029
+ itemId: id,
2030
+ taskSlug,
2031
+ prompt: parsed?.prompt,
2032
+ language: parsed?.language,
2033
+ role: parsed?.role,
2034
+ }),
2035
+ label: 'tracker link add',
2036
+ });
2037
+ if (linkResult.ok !== true || typeof linkResult.link?.linkId !== 'string') {
2038
+ failTrackerRefusal(linkResult, START_TASK_REFUSALS);
2039
+ }
2040
+ const enqueueResult = await runTeamDbChild(['tracker', 'enqueue', '--file', '-'], {
2041
+ settings: context.settings,
2042
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2043
+ input: JSON.stringify({ itemId: id, taskSlug, linkId: linkResult.link.linkId, reason, requestedBy }),
2044
+ label: 'tracker enqueue',
2045
+ });
2046
+ if (enqueueResult.ok !== true || typeof enqueueResult.entry?.entryId !== 'string') {
2047
+ await runTeamDbChild(['tracker', 'link', '--file', '-'], {
2048
+ settings: context.settings,
2049
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2050
+ input: JSON.stringify({ action: 'remove', linkId: linkResult.link.linkId }),
2051
+ label: 'tracker link rollback',
2052
+ });
2053
+ failTrackerRefusal(enqueueResult, START_TASK_REFUSALS);
2054
+ }
2055
+ return { json: trackerItemDetail(db, id, context.settings.teamRoot), status: 201 };
2056
+ };
2057
+
2058
+ const stopTrackerTask = async (context) => {
2059
+ const id = parseItemId(context.params.id);
2060
+ const taskSlug = parseTaskSlug(context.params.taskSlug);
2061
+ const db = context.db();
2062
+ if (!db.prepare(SQL.getTrackerItem).get(id)) fail('E_NOT_FOUND', 404, `no tracker item "${id}"`);
2063
+ const linkId = `${id}--${taskSlug}`;
2064
+ const linkRow = db.prepare(SQL.getTrackerLink).get(linkId);
2065
+ if (!linkRow) fail('E_NOT_FOUND', 404, `no tracker link "${linkId}"`);
2066
+ const link = trackerLinkFromRow(linkRow);
2067
+ if (link.entryId !== null) {
2068
+ const entryRow = db.prepare(SQL.getTrackerEntry).get(link.entryId);
2069
+ if (entryRow) {
2070
+ const entry = trackerEntryFromRow(entryRow);
2071
+ const taskRow = db.prepare(SQL.getTrackerTaskRow).get(taskSlug);
2072
+ const status = effectiveEntryStatus(entry, taskRow?.state ?? null);
2073
+ if (status === 'queued' || status === 'claimed') {
2074
+ const cancelResult = await runTeamDbChild(['tracker', 'cancel', link.entryId], {
2075
+ settings: context.settings,
2076
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2077
+ label: 'tracker task stop cancel',
2078
+ });
2079
+ if (cancelResult.ok !== true) failTrackerRefusal(cancelResult, STOP_TASK_REFUSALS);
2080
+ }
2081
+ }
2082
+ }
2083
+ const stopResult = await runTeamDbChild(['task-run', 'stop', '--task', taskSlug], {
2084
+ settings: context.settings,
2085
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2086
+ label: 'tracker task stop runner',
2087
+ });
2088
+ if (stopResult.ok !== true && stopResult.code !== 'E_RUNNER_OFFLINE') {
2089
+ failTrackerRefusal(stopResult, STOP_TASK_REFUSALS);
2090
+ }
2091
+ const setResult = await runTeamDbChild(['tracker', 'link', '--file', '-'], {
2092
+ settings: context.settings,
2093
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2094
+ input: JSON.stringify({ action: 'set', linkId, decision: 'stopped', revision: link.revision }),
2095
+ label: 'tracker task stop link',
2096
+ });
2097
+ if (setResult.ok !== true) failTrackerRefusal(setResult, STOP_TASK_REFUSALS);
2098
+ return { json: trackerItemDetail(db, id, context.settings.teamRoot) };
2099
+ };
2100
+
2101
+ const continueTrackerTask = async (context) => {
2102
+ const id = parseItemId(context.params.id);
2103
+ const taskSlug = parseTaskSlug(context.params.taskSlug);
2104
+ const text = context.body.toString('utf8').trim();
2105
+ if (text !== '' && text !== '{}') parseTrackerBody(context, 'a task continue body');
2106
+ const db = context.db();
2107
+ if (!db.prepare(SQL.getTrackerItem).get(id)) fail('E_NOT_FOUND', 404, `no tracker item "${id}"`);
2108
+ const linkId = `${id}--${taskSlug}`;
2109
+ const linkRow = db.prepare(SQL.getTrackerLink).get(linkId);
2110
+ if (!linkRow) fail('E_NOT_FOUND', 404, `no tracker link "${linkId}"`);
2111
+ const link = trackerLinkFromRow(linkRow);
2112
+ const taskRow = db.prepare(SQL.getTrackerTaskRow).get(taskSlug);
2113
+ if (!taskRow) fail('E_CONFLICT', 409, `task ${taskSlug} has not been bootstrapped yet`);
2114
+ const startResult = await runTeamDbChild(
2115
+ ['task-run', 'start', '--task', taskSlug, '--item', id, '--link', linkId],
2116
+ {
2117
+ settings: context.settings,
2118
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2119
+ label: 'tracker task continue runner',
2120
+ },
2121
+ );
2122
+ if (startResult.ok !== true) failTrackerRefusal(startResult, STOP_TASK_REFUSALS);
2123
+ const setResult = await runTeamDbChild(['tracker', 'link', '--file', '-'], {
2124
+ settings: context.settings,
2125
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2126
+ input: JSON.stringify({ action: 'set', linkId, decision: 'requested', revision: link.revision }),
2127
+ label: 'tracker task continue link',
2128
+ });
2129
+ if (setResult.ok !== true) {
2130
+ await runTeamDbChild(['task-run', 'stop', '--task', taskSlug], {
2131
+ settings: context.settings,
2132
+ timeoutMs: TRACKER_WRITE_CHILD_TIMEOUT_MS,
2133
+ label: 'tracker task continue rollback',
2134
+ });
2135
+ failTrackerRefusal(setResult, STOP_TASK_REFUSALS);
2136
+ }
2137
+ return { json: trackerItemDetail(db, id, context.settings.teamRoot), status: 202 };
2138
+ };
2139
+
1406
2140
  /* --------------------------------- routing -------------------------------- */
1407
2141
 
1408
2142
  const route = (method, routePath, operationId, handler, options = {}) => ({
@@ -1508,6 +2242,47 @@ export const ROUTES = [
1508
2242
  route('POST', '/api/v1/jobs/{id}/run', 'runJobNow', (context) => runJobNow(context), {
1509
2243
  bodyLimit: MAX_REQUEST_BODY_BYTES,
1510
2244
  }),
2245
+ // The tracker entries: `/api/v1/tracker/queue` sits before
2246
+ // `/api/v1/tracker/{id}` so the `{id}` pattern can never shadow the literal
2247
+ // `queue` segment — the same discipline that keeps `/api/v1/jobs/{id}` from
2248
+ // shadowing `/api/v1/jobs/{id}/runs`.
2249
+ route('GET', '/api/v1/tracker', 'listTrackerItems', (context) => ({
2250
+ json: listTrackerItems(context.db(), context.query, context.settings),
2251
+ })),
2252
+ route('POST', '/api/v1/tracker', 'createTrackerItem', (context) => createTrackerItem(context), {
2253
+ bodyLimit: TRACKER_ITEM_BODY_MAX,
2254
+ requireJson: true,
2255
+ }),
2256
+ route('GET', '/api/v1/tracker/queue', 'listTrackerQueue', (context) => ({
2257
+ json: listTrackerQueue(context.db(), context.query),
2258
+ })),
2259
+ route('POST', '/api/v1/tracker/queue', 'enqueueTrackerItem', (context) => enqueueTrackerItem(context), {
2260
+ bodyLimit: TRACKER_QUEUE_BODY_MAX,
2261
+ requireJson: true,
2262
+ }),
2263
+ route('POST', '/api/v1/tracker/queue/{entryId}/cancel', 'cancelTrackerQueueEntry', (context) => cancelTrackerQueueEntry(context), {
2264
+ bodyLimit: TRACKER_QUEUE_BODY_MAX,
2265
+ }),
2266
+ route('GET', '/api/v1/tracker/{id}', 'getTrackerItem', (context) => ({
2267
+ json: trackerItemDetail(context.db(), parseItemId(context.params.id), context.settings.teamRoot),
2268
+ })),
2269
+ route('PUT', '/api/v1/tracker/{id}', 'updateTrackerItem', (context) => updateTrackerItem(context), {
2270
+ bodyLimit: TRACKER_ITEM_BODY_MAX,
2271
+ requireJson: true,
2272
+ }),
2273
+ route('DELETE', '/api/v1/tracker/{id}', 'deleteTrackerItem', (context) => deleteTrackerItem(context), {
2274
+ bodyLimit: MAX_REQUEST_BODY_BYTES,
2275
+ }),
2276
+ route('POST', '/api/v1/tracker/{id}/tasks', 'startTrackerTask', (context) => startTrackerTask(context), {
2277
+ bodyLimit: TRACKER_TASK_BODY_MAX,
2278
+ requireJson: true,
2279
+ }),
2280
+ route('POST', '/api/v1/tracker/{id}/tasks/{taskSlug}/stop', 'stopTrackerTask', (context) => stopTrackerTask(context), {
2281
+ bodyLimit: TRACKER_TASK_ACTION_BODY_MAX,
2282
+ }),
2283
+ route('POST', '/api/v1/tracker/{id}/tasks/{taskSlug}/continue', 'continueTrackerTask', (context) => continueTrackerTask(context), {
2284
+ bodyLimit: TRACKER_TASK_BODY_MAX,
2285
+ }),
1511
2286
  ];
1512
2287
 
1513
2288
  /** The documented `METHOD path` pairs, for the contract gate's route parity. */
@@ -1695,7 +2470,9 @@ const handle = async (req, res, settings) => {
1695
2470
  handle: handleOnce,
1696
2471
  });
1697
2472
  if (result.json !== undefined) {
1698
- sendJson(req, res, 200, result.json);
2473
+ // A mutation may pin its own status: the tracker create answers 201
2474
+ // and the idempotent enqueue answers 200 or 201.
2475
+ sendJson(req, res, result.status ?? 200, result.json);
1699
2476
  return;
1700
2477
  }
1701
2478
  send(req, res, 200, { 'Content-Type': result.type, 'Cache-Control': result.cache }, result.body);