@bonesofspring/ai-rules 0.2.64 → 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 (293) hide show
  1. package/CHANGELOG.md +46 -11
  2. package/README.md +6 -6
  3. package/bin/lib/engine-scripts.js +14 -5
  4. package/bin/lib/seed-ai-local-team.js +7 -0
  5. package/docs/PRESET-CONTRIBUTION.md +41 -0
  6. package/docs/TEAM-DB.md +193 -52
  7. package/docs/openapi/team-db.v1.json +1238 -377
  8. package/mcp/defectdojo-mcp.mjs +7 -5
  9. package/mcp/lib/defectdojo.mjs +26 -14
  10. package/package.json +26 -20
  11. package/presets/_shared/ai-local/scripts/process-lease.mjs +576 -0
  12. package/presets/_shared/ai-local/scripts/processes.mjs +1618 -0
  13. package/presets/_shared/ai-local/scripts/run.mjs +5 -5
  14. package/presets/_shared/ai-local/scripts/team-db-api.mjs +465 -152
  15. package/presets/_shared/ai-local/scripts/team-db-dashboard.mjs +235 -10
  16. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +416 -176
  17. package/presets/_shared/ai-local/scripts/team-db-project.mjs +171 -62
  18. package/presets/_shared/ai-local/scripts/team-db-scheduler.mjs +4 -0
  19. package/presets/_shared/ai-local/scripts/team-db-schema.mjs +143 -5
  20. package/presets/_shared/ai-local/scripts/team-db-task-runner.mjs +567 -0
  21. package/presets/_shared/ai-local/scripts/{team-db-backlog.mjs → team-db-tracker.mjs} +900 -197
  22. package/presets/_shared/ai-local/scripts/team-db-ui.mjs +750 -0
  23. package/presets/_shared/ai-local/scripts/team-db.mjs +104 -23
  24. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +1 -1
  25. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +105 -17
  26. package/presets/_shared/hooks/guard-shell-command.mjs.tmpl +40 -2
  27. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +105 -17
  28. package/presets/claude/android-kotlin/hooks/guard-shell-command.mjs +41 -2
  29. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  30. package/presets/claude/android-kotlin/settings.json +6 -1
  31. package/presets/claude/go/hooks/chain-team-phases.sh +105 -17
  32. package/presets/claude/go/hooks/guard-shell-command.mjs +41 -2
  33. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  34. package/presets/claude/go/settings.json +6 -1
  35. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +105 -17
  36. package/presets/claude/ios-swift/hooks/guard-shell-command.mjs +41 -2
  37. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  38. package/presets/claude/ios-swift/settings.json +6 -1
  39. package/presets/claude/java/hooks/chain-team-phases.sh +105 -17
  40. package/presets/claude/java/hooks/guard-shell-command.mjs +41 -2
  41. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  42. package/presets/claude/java/settings.json +6 -1
  43. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +105 -17
  44. package/presets/claude/mcp-ts/hooks/guard-shell-command.mjs +41 -2
  45. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  46. package/presets/claude/mcp-ts/settings.json +6 -1
  47. package/presets/claude/mol/hooks/chain-team-phases.sh +105 -17
  48. package/presets/claude/mol/hooks/guard-shell-command.mjs +41 -2
  49. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  50. package/presets/claude/mol/settings.json +6 -1
  51. package/presets/claude/next/MCP.md +2 -0
  52. package/presets/claude/next/REPO_AGENTS.md +2 -0
  53. package/presets/claude/next/agents/build-verifier.md +1 -1
  54. package/presets/claude/next/agents/ci-investigator.md +3 -0
  55. package/presets/claude/next/agents/debugger.md +3 -0
  56. package/presets/claude/next/agents/feature-developer.md +3 -0
  57. package/presets/claude/next/agents/mockup-reviewer.md +2 -0
  58. package/presets/claude/next/agents/performance-auditor.md +2 -0
  59. package/presets/claude/next/agents/playwright-test-generator.md +3 -0
  60. package/presets/claude/next/agents/playwright-test-healer.md +3 -0
  61. package/presets/claude/next/agents/playwright-test-planner.md +3 -0
  62. package/presets/claude/next/agents/qa-tester.md +3 -0
  63. package/presets/claude/next/commands/README.md +6 -0
  64. package/presets/claude/next/commands/ui-start.md +78 -0
  65. package/presets/claude/next/commands/ui-stop.md +71 -0
  66. package/presets/claude/next/hooks/chain-team-phases.sh +105 -17
  67. package/presets/claude/next/hooks/guard-shell-command.mjs +41 -2
  68. package/presets/claude/next/rules/README.md +2 -1
  69. package/presets/claude/next/rules/stack/next-app-core.md +1 -0
  70. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  71. package/presets/claude/next/rules/tooling-and-review/dev-process-lifecycle.md +43 -0
  72. package/presets/claude/next/settings.json +6 -1
  73. package/presets/claude/nuxt/hooks/chain-team-phases.sh +105 -17
  74. package/presets/claude/nuxt/hooks/guard-shell-command.mjs +41 -2
  75. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  76. package/presets/claude/nuxt/settings.json +6 -1
  77. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +105 -17
  78. package/presets/claude/php-hexagonal/hooks/guard-shell-command.mjs +41 -2
  79. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  80. package/presets/claude/php-hexagonal/settings.json +6 -1
  81. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +106 -18
  82. package/presets/claude/php-laravel/hooks/guard-shell-command.mjs +41 -2
  83. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  84. package/presets/claude/php-laravel/settings.json +6 -1
  85. package/presets/claude/svelte/hooks/chain-team-phases.sh +105 -17
  86. package/presets/claude/svelte/hooks/guard-shell-command.mjs +41 -2
  87. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +1 -1
  88. package/presets/claude/svelte/settings.json +6 -1
  89. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +105 -17
  90. package/presets/cursor/android-kotlin/hooks/guard-shell-command.mjs +41 -2
  91. package/presets/cursor/go/hooks/chain-team-phases.sh +105 -17
  92. package/presets/cursor/go/hooks/guard-shell-command.mjs +41 -2
  93. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +105 -17
  94. package/presets/cursor/ios-swift/hooks/guard-shell-command.mjs +41 -2
  95. package/presets/cursor/java/hooks/chain-team-phases.sh +105 -17
  96. package/presets/cursor/java/hooks/guard-shell-command.mjs +41 -2
  97. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +105 -17
  98. package/presets/cursor/mcp-ts/hooks/guard-shell-command.mjs +41 -2
  99. package/presets/cursor/mol/hooks/chain-team-phases.sh +105 -17
  100. package/presets/cursor/mol/hooks/guard-shell-command.mjs +41 -2
  101. package/presets/cursor/next/MCP.md +2 -0
  102. package/presets/cursor/next/REPO_AGENTS.md +2 -0
  103. package/presets/cursor/next/agents/build-verifier.md +1 -1
  104. package/presets/cursor/next/agents/ci-investigator.md +2 -0
  105. package/presets/cursor/next/agents/debugger.md +2 -0
  106. package/presets/cursor/next/agents/feature-developer.md +2 -0
  107. package/presets/cursor/next/agents/mockup-reviewer.md +2 -0
  108. package/presets/cursor/next/agents/performance-auditor.md +2 -0
  109. package/presets/cursor/next/agents/playwright-test-generator.md +2 -0
  110. package/presets/cursor/next/agents/playwright-test-healer.md +2 -0
  111. package/presets/cursor/next/agents/playwright-test-planner.md +2 -0
  112. package/presets/cursor/next/agents/qa-tester.md +2 -0
  113. package/presets/cursor/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -1
  114. package/presets/cursor/next/commands/README.md +6 -0
  115. package/presets/cursor/next/commands/ui-start.md +78 -0
  116. package/presets/cursor/next/commands/ui-stop.md +71 -0
  117. package/presets/cursor/next/hooks/chain-team-phases.sh +105 -17
  118. package/presets/cursor/next/hooks/guard-shell-command.mjs +41 -2
  119. package/presets/cursor/next/rules/README.md +2 -1
  120. package/presets/cursor/next/rules/dev-process-lifecycle.mdc +43 -0
  121. package/presets/cursor/next/rules/next-app-core.mdc +1 -0
  122. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +105 -17
  123. package/presets/cursor/nuxt/hooks/guard-shell-command.mjs +41 -2
  124. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +105 -17
  125. package/presets/cursor/php-hexagonal/hooks/guard-shell-command.mjs +41 -2
  126. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +106 -18
  127. package/presets/cursor/php-laravel/hooks/guard-shell-command.mjs +41 -2
  128. package/presets/cursor/svelte/hooks/chain-team-phases.sh +105 -17
  129. package/presets/cursor/svelte/hooks/guard-shell-command.mjs +41 -2
  130. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  131. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +105 -17
  132. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +1 -1
  133. package/presets/mavis/go/adapter-map.json +1 -1
  134. package/presets/mavis/go/hooks/chain-team-phases.sh +105 -17
  135. package/presets/mavis/go/rules/agent-team-orchestrator.md +1 -1
  136. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  137. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +105 -17
  138. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +1 -1
  139. package/presets/mavis/java/adapter-map.json +1 -1
  140. package/presets/mavis/java/hooks/chain-team-phases.sh +105 -17
  141. package/presets/mavis/java/rules/agent-team-orchestrator.md +1 -1
  142. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  143. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +105 -17
  144. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +1 -1
  145. package/presets/mavis/mol/adapter-map.json +1 -1
  146. package/presets/mavis/mol/hooks/chain-team-phases.sh +105 -17
  147. package/presets/mavis/mol/rules/agent-team-orchestrator.md +1 -1
  148. package/presets/mavis/next/MCP.md +2 -0
  149. package/presets/mavis/next/REPO_AGENTS.md +2 -0
  150. package/presets/mavis/next/adapter-map.json +25 -1
  151. package/presets/mavis/next/agents/build-verifier.md +1 -1
  152. package/presets/mavis/next/agents/ci-investigator.md +3 -0
  153. package/presets/mavis/next/agents/debugger.md +3 -0
  154. package/presets/mavis/next/agents/feature-developer.md +3 -0
  155. package/presets/mavis/next/agents/mockup-reviewer.md +2 -0
  156. package/presets/mavis/next/agents/performance-auditor.md +2 -0
  157. package/presets/mavis/next/agents/playwright-test-generator.md +3 -0
  158. package/presets/mavis/next/agents/playwright-test-healer.md +3 -0
  159. package/presets/mavis/next/agents/playwright-test-planner.md +3 -0
  160. package/presets/mavis/next/agents/qa-tester.md +3 -0
  161. package/presets/mavis/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -1
  162. package/presets/mavis/next/commands/README.md +6 -0
  163. package/presets/mavis/next/commands/ui-start.md +73 -0
  164. package/presets/mavis/next/commands/ui-stop.md +66 -0
  165. package/presets/mavis/next/hooks/chain-team-phases.sh +105 -17
  166. package/presets/mavis/next/rules/agent-team-orchestrator.md +1 -1
  167. package/presets/mavis/next/rules/dev-process-lifecycle.md +38 -0
  168. package/presets/mavis/next/rules/next-app-core.md +1 -0
  169. package/presets/mavis/nuxt/adapter-map.json +1 -1
  170. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +105 -17
  171. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +1 -1
  172. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  173. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +105 -17
  174. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
  175. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  176. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +106 -18
  177. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +1 -1
  178. package/presets/mavis/svelte/adapter-map.json +1 -1
  179. package/presets/mavis/svelte/hooks/chain-team-phases.sh +105 -17
  180. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +1 -1
  181. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  182. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +105 -17
  183. package/presets/opencode/android-kotlin/opencode.json +5 -1
  184. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +1 -1
  185. package/presets/opencode/go/adapter-map.json +1 -1
  186. package/presets/opencode/go/hooks/chain-team-phases.sh +105 -17
  187. package/presets/opencode/go/opencode.json +5 -1
  188. package/presets/opencode/go/rules/agent-team-orchestrator.md +1 -1
  189. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  190. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +105 -17
  191. package/presets/opencode/ios-swift/opencode.json +5 -1
  192. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +1 -1
  193. package/presets/opencode/java/adapter-map.json +1 -1
  194. package/presets/opencode/java/hooks/chain-team-phases.sh +105 -17
  195. package/presets/opencode/java/opencode.json +5 -1
  196. package/presets/opencode/java/rules/agent-team-orchestrator.md +1 -1
  197. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  198. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +105 -17
  199. package/presets/opencode/mcp-ts/opencode.json +5 -1
  200. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +1 -1
  201. package/presets/opencode/mol/adapter-map.json +1 -1
  202. package/presets/opencode/mol/hooks/chain-team-phases.sh +105 -17
  203. package/presets/opencode/mol/opencode.json +4 -0
  204. package/presets/opencode/mol/rules/agent-team-orchestrator.md +1 -1
  205. package/presets/opencode/next/MCP.md +2 -0
  206. package/presets/opencode/next/REPO_AGENTS.md +2 -0
  207. package/presets/opencode/next/adapter-map.json +25 -1
  208. package/presets/opencode/next/agents/build-verifier.md +1 -1
  209. package/presets/opencode/next/agents/ci-investigator.md +3 -0
  210. package/presets/opencode/next/agents/debugger.md +3 -0
  211. package/presets/opencode/next/agents/feature-developer.md +3 -0
  212. package/presets/opencode/next/agents/mockup-reviewer.md +2 -0
  213. package/presets/opencode/next/agents/performance-auditor.md +2 -0
  214. package/presets/opencode/next/agents/playwright-test-generator.md +3 -0
  215. package/presets/opencode/next/agents/playwright-test-healer.md +3 -0
  216. package/presets/opencode/next/agents/playwright-test-planner.md +3 -0
  217. package/presets/opencode/next/agents/qa-tester.md +3 -0
  218. package/presets/opencode/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -1
  219. package/presets/opencode/next/commands/README.md +6 -0
  220. package/presets/opencode/next/commands/ui-start.md +81 -0
  221. package/presets/opencode/next/commands/ui-stop.md +74 -0
  222. package/presets/opencode/next/hooks/chain-team-phases.sh +105 -17
  223. package/presets/opencode/next/opencode.json +4 -0
  224. package/presets/opencode/next/rules/agent-team-orchestrator.md +1 -1
  225. package/presets/opencode/next/rules/dev-process-lifecycle.md +38 -0
  226. package/presets/opencode/next/rules/next-app-core.md +1 -0
  227. package/presets/opencode/nuxt/adapter-map.json +1 -1
  228. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +105 -17
  229. package/presets/opencode/nuxt/opencode.json +4 -0
  230. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +1 -1
  231. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  232. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +105 -17
  233. package/presets/opencode/php-hexagonal/opencode.json +5 -1
  234. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
  235. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  236. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +106 -18
  237. package/presets/opencode/php-laravel/opencode.json +5 -1
  238. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +1 -1
  239. package/presets/opencode/svelte/adapter-map.json +1 -1
  240. package/presets/opencode/svelte/hooks/chain-team-phases.sh +105 -17
  241. package/presets/opencode/svelte/opencode.json +4 -0
  242. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +1 -1
  243. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  244. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +105 -17
  245. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +1 -1
  246. package/presets/zcode/go/adapter-map.json +1 -1
  247. package/presets/zcode/go/hooks/chain-team-phases.sh +105 -17
  248. package/presets/zcode/go/rules/agent-team-orchestrator.md +1 -1
  249. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  250. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +105 -17
  251. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +1 -1
  252. package/presets/zcode/java/adapter-map.json +1 -1
  253. package/presets/zcode/java/hooks/chain-team-phases.sh +105 -17
  254. package/presets/zcode/java/rules/agent-team-orchestrator.md +1 -1
  255. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  256. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +105 -17
  257. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +1 -1
  258. package/presets/zcode/mol/adapter-map.json +1 -1
  259. package/presets/zcode/mol/hooks/chain-team-phases.sh +105 -17
  260. package/presets/zcode/mol/rules/agent-team-orchestrator.md +1 -1
  261. package/presets/zcode/next/MCP.md +2 -0
  262. package/presets/zcode/next/REPO_AGENTS.md +2 -0
  263. package/presets/zcode/next/adapter-map.json +25 -1
  264. package/presets/zcode/next/agents/build-verifier.md +1 -1
  265. package/presets/zcode/next/agents/ci-investigator.md +3 -0
  266. package/presets/zcode/next/agents/debugger.md +3 -0
  267. package/presets/zcode/next/agents/feature-developer.md +3 -0
  268. package/presets/zcode/next/agents/mockup-reviewer.md +2 -0
  269. package/presets/zcode/next/agents/performance-auditor.md +2 -0
  270. package/presets/zcode/next/agents/playwright-test-generator.md +3 -0
  271. package/presets/zcode/next/agents/playwright-test-healer.md +3 -0
  272. package/presets/zcode/next/agents/playwright-test-planner.md +3 -0
  273. package/presets/zcode/next/agents/qa-tester.md +3 -0
  274. package/presets/zcode/next/ai-local/rules-library/storybook-dev-compare-figma.md +1 -1
  275. package/presets/zcode/next/commands/README.md +6 -0
  276. package/presets/zcode/next/commands/ui-start.md +81 -0
  277. package/presets/zcode/next/commands/ui-stop.md +74 -0
  278. package/presets/zcode/next/hooks/chain-team-phases.sh +105 -17
  279. package/presets/zcode/next/rules/agent-team-orchestrator.md +1 -1
  280. package/presets/zcode/next/rules/dev-process-lifecycle.md +38 -0
  281. package/presets/zcode/next/rules/next-app-core.md +1 -0
  282. package/presets/zcode/nuxt/adapter-map.json +1 -1
  283. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +105 -17
  284. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +1 -1
  285. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  286. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +105 -17
  287. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +1 -1
  288. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  289. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +106 -18
  290. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +1 -1
  291. package/presets/zcode/svelte/adapter-map.json +1 -1
  292. package/presets/zcode/svelte/hooks/chain-team-phases.sh +105 -17
  293. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +1 -1
package/CHANGELOG.md CHANGED
@@ -1,6 +1,49 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.2.65
4
+
5
+ ### Agent process manager
6
+
7
+ - **`processes.mjs` gives a checkout one view and one lease protocol.** New engine modules `processes.mjs` and `process-lease.mjs` (both in `ENGINE_SCRIPTS`, mirrored to `.ai.local/scripts/`) own `.ai.local/.processes/`: `leases/<name>.json` created with `open(…, 'wx')`, a single-line `events.jsonl`, and a `.reclaim/` guard per lease. `acquire` / `release` / `run` / `list` / `status` / `watch` / `scan` / `doctor` / `stop` / `serve`; exit codes are `0` ok, `1` held/timeout, `2` usage, `3` fatal, `4` refused.
8
+ - **Liveness defeats pid reuse; release is token-owned.** A holder is live only while its pid is alive **and** the recorded `pidStart` (`ps -o lstart=`, `/proc/<pid>/stat` without `ps`) still matches; a heartbeat never makes a live holder stale, and a different start time is reclaimed on the first attempt inside `.reclaim/<name>`. `release` refuses a foreign token, and `run` releases in `finally` and exits with the child's status (`128 + signo`).
9
+ - **One snapshot over the markers that already exist.** `list` / `watch` / `serve` read own leases plus `preset-tree` (`.preset-tree-lock/owner.json`), `dev:<name>` (`.ai.local/.dev/*.json`), `team-db-serve` (`.ai.local/.ui/api.json`), `scheduler`, `runner:<slug>` (active runs only), and `git-index`; a missing source is skipped and a malformed one is a `warnings[]` entry. `watch` refreshes every second (`--once`, `--json`, `--no-color`), and `serve` answers `GET /api/v1/processes`, an SSE `/api/v1/processes/stream` (initial snapshot, then one event per change), and a minimal HTML table on `127.0.0.1:4179`.
10
+ - **`scan` shows what bypasses the leases, `doctor` reports what is broken.** `scan` reads listening TCP ports (`lsof`, `ss` fallback) and the known command shapes (`fix-generated.mjs`, `check-preset-*.sh`, `team-db.mjs serve`, `storybook`, `next dev`, Playwright browsers), labels a lease-covered pid `leased` and everything else `foreign`; `doctor` exits non-zero on a stale lease, a dead marker, or a lease port with no listener. `stop` re-proves ownership (live pid + matching `pidStart` + command line or lease port) and never signals an unproven pid.
11
+ - **One lifecycle CLI.** `processes.mjs start` spawns a detached child, records a `port` lease, and reuses a live lease or a foreign listener; `list` / `status` / `stop` are the same CLI. `stop --task <slug>` filters leases by task, and the chain postflight calls it directly.
12
+ - **Wiring and fixtures.** `check:processes` runs `test-process-lease.mjs`, `test-process-adapters.mjs`, and `test-process-scan.mjs`; the composite gains the `process lease fixtures` and `process view fixtures` rows; `docs/PRESET-CONTRIBUTION.md` gains an "Agent process manager" section and the `dev-process-lifecycle` rule tells agents to start and inspect work through the manager.
13
+
14
+ ### Preset-tree lock and the loop
15
+
16
+ - **The preset-tree lock fails closed and can wait.** A fatal lock reason (`unwritable` / `reclaim-failed`) now stops `fix:generated` and both shell gates with exit 1 before any work instead of "continuing unlocked"; `--allow-unlocked` / `AI_RULES_ALLOW_UNLOCKED=1` is the loud opt-in. `--wait <ms>` / `AI_RULES_LOCK_WAIT_MS` polls every 500 ms (default fail-fast) in `fix:generated` and `run-locked.mjs` only — the shell gates stay fail-fast — and a dead named owner is still reclaimed on the first attempt. Every acquire result carries `fatal` and `code`; read `fatal` before `skipped`.
17
+ - **Read-side gates take the lock.** New `run-locked.mjs` acquires, runs the child with inherited stdio, releases in `finally`, and exits with the child's status (`128 + signo` on a signal death). Eleven package gates (generated drift, twin map, twin drift, token budget, leakage, frontmatter, consumer links, shared-core drift, reachability, i18n, CLI init clean) run through it; the composites and `preset:loop` are never wrapped.
18
+ - **`yarn preset:loop`** runs `fix:generated && check:changed && check:fast` in series and holds no lock across phases.
19
+ - **The delta classifier names four preset domains.** `check-preset-delta.mjs` splits the old `preset-core` into `preset-content`, `preset-generator`, `preset-install` and `preset-tooling`: a generator change demands `fix-generated` + drift + twin drift + init-clean, an install change demands init-clean + drift, a tooling change demands only the classifier `--self-test`, and `.ai.local/**` no longer counts as `docs`. `release:gate` is reserved for `preset-content`, `preset-generator` and release changes.
20
+ - **The engine mirror replaces atomically.** `mirrorEngineScripts` writes a same-directory temp file and renames it over `.ai.local/scripts/<name>`, so a live engine process never reads a torn `run.mjs` / `lock.mjs`.
21
+
22
+ ### Dev process lifecycle
23
+
24
+ - **`processes.mjs start` owns long-lived local servers.** It reuses a live lease or a foreign listener and spawns only on a free port, detached in its own process group; the lease `.ai.local/.processes/leases/<name>.json` records pid + start time, port, command, cwd, and task. `stop` proves ownership, clears stale leases, and offers `--task` cleanup.
25
+ - **The `dev-process-lifecycle` rule (next).** Reuse before start, own what you start, stop when done, never mass-kill unowned processes; the browser section covers the single-instance Playwright MCP profile, `--isolated` for one-off work, and the shared-Chrome CDP recipe launched through `processes.mjs start` so task-end cleanup closes only that instance. Wired into the implementer and e2e zone rules, the Storybook Figma-compare seed, `playwright-agents`, the five `MCP.md` files, and the root `AGENTS.md` entry. The description names the trigger so the main session can pull the rule on demand.
26
+ - **The chain postflight stops the task's servers.** When `status.json` reaches `completed` or `blocked`, the postflight runs `processes.mjs stop --task <slug>` in a bounded 8 s child; ownership refusal is a warning, never a hook failure. Manual sessions keep the rule.
27
+ - **The shell guard probes the port and always asks on mass-kill.** A per-stack `guard-ports.json` names the dev-server command shape and the ports to probe; an explicit `--port` probes that port only, and `pkill` / `killall` / `xargs kill` always ask. OpenCode enforces the same mass-kill family through `permission.bash` (`ask`); Mavis and ZCode have no shell hook, so the rule remains their only control.
28
+ - **Fixtures.** `test-dev-processes.mjs` (9 cases) and `test-guard-shell-command.mjs` (8 cases) run from `check-preset-structure.sh`; the engine mirror and CLI goldens are regenerated.
29
+
30
+ ### Dashboard lifecycle
31
+
32
+ - **`team-db.mjs ui start|stop|status|restart`.** The shipped no-build dashboard gets a lifecycle. `start` is probe-first and idempotent: a healthy server for this repository is a no-op with the same pid, and only a free port spawns a detached `serve` and writes `.ai.local/.ui/api.json` atomically with a hashed `rootId`. `stop` re-proves ownership from the live command line (pid **and** a `team-db.mjs serve` match), signals that leader pid only, escalates to `SIGKILL` after the 5 s `SIGTERM` window, and keeps the marker with exit 1 if the process survives. Exit codes are `0` ok/no-op, `1` refusal, `2` start failure, `3` usage; `--allow-remote` is refused, and the scheduler timer stays a separate foreground process. No Docker, no build step, no new runtime dependency.
33
+ - **Two `next` commands.** `/ui-start` and `/ui-stop` ship on the `next` stack — one authored pair, ten generated twins — while every other stack runs the verb directly, with `team-db.mjs serve` as the fallback for a fork that predates it. `ai-rules update --fix` is the upgrade step; a plain `update` leaves a stale engine module that answers `ui` with exit 3.
34
+ - **The dashboard closes task delete and a read-only tracker view.** The delete sits behind a confirmation, announces the `200` in the page-level live region with focus back on the list heading, and surfaces `409 E_ACTIVE_TASK` with its `activeSlug` in the detail live region; a third nav tab lists tracker items with the item panel and the queue, and carries no create, update, enqueue or cancel control. The task surface keeps a named two-call mutating allowlist (`POST /api/v1/sync`, `DELETE /api/v1/tasks/{slug}`) beside the four enumerated jobs writes, and the shipped seeder git-ignores `.ui/`.
35
+ - **`/health.rootId`.** One additive, optional field — `sha256(resolved team root).slice(0, 12)` — turns the cross-root case into `E_UI_OTHER_ROOT`. The contract document is regenerated by the checker; no route, operation, or error code changes.
36
+
37
+ ### Tracker
38
+
39
+ - **The tracker replaces the backlog module and renames its paths.** `.ai.local/team/tracker/` (`items/`, `queue/`, `links/`), `/api/v1/tracker*`, the `tracker` CLI verb family, the `tracker_items`/`tracker_queue`/`tracker_item_tasks` projection tables and the `/tracker` operator pages replace every `backlog` name. **Backlog is now one stored status** (`backlog`), the captured state that is not launchable until promoted to `planned`.
40
+ - **The file-authoritative plan store.** `tracker/items/<id>.json` and `tracker/links/` are committed; `tracker/queue/` and `team/task-runs/` are runtime state. `team-db.mjs tracker` ships the verb family `add`, `set`, `show`, `list`, `ready`, `validate`, `import` (the versioned envelope, idempotent by id, `--dry-run`), `enqueue`, `cancel`, `drain --claim`, `recover`, `prune`, `link`, `delete`, `adopt` and `migrate-ids`. Every operational status (`effectiveStatus`, `ready`, `waitingOn`) is derived from the items, links, queue entries and the hook-owned task state, never written; the deterministic total order is `priority` ascending (lower runs first, default 5) → `createdAt` → `id`.
41
+ - **The launch queue.** `tracker/config.json` carries `maxActive` (1…8, default 1); a task in a holding state (`in_progress`, `awaiting_artifact_receipt`, `blocked`) occupies a slot, one at a human gate does not. `tracker drain --claim` grants at most one claim and never starts a run; the hook stop seam consumes the claim, re-checks the graph at claim time, and `AI_RULES_TEAM_DB_TRACKER_DRAIN_DISABLE=1` stops only the auto-drain. A claim older than 90 s with no task row is released on the next drain or by `tracker recover`.
42
+ - **Tracker CRUD.** The item id is an opaque tracker key, the UI gains `/tracker/new`, `/tracker/[id]/edit`, a hard delete with active-link/live-queue protection, and the full item form; the API gains `DELETE /api/v1/tracker/{id}`. The item id no longer becomes the team-task slug.
43
+ - **Item ↔ task links.** `tracker/links/<itemId>--<taskSlug>.json` plus its prompt is the file-authoritative relation; one item may be closed by several tasks. A new `tracker_item_tasks` table, a link walker, `tracker link add|set|remove|list|adopt`, and the item detail `tasks[]` expose the relation. Legacy `tasks/<itemId>/` folders remain readable as implicit links.
44
+ - **Start/stop/continue.** The item detail starts a new task as one link + queue request (the queue entry carries its own `taskSlug`/`linkId`); the hook bootstrap copies the link prompt into `tasks/<taskSlug>/` and records the tracker provenance. Stop cancels a request and writes a per-task `STOP` sentinel; Continue starts the seeded `team/runner.json` supervisor (`task-run` verbs) with no shell, a confined cwd, an env allow-list, a timeout and a process-group kill.
45
+ - **`ui start` is probe-first.** A server that already answers `/health` for this repository is the no-op: same pid, untouched `startedAt`, nothing spawned. Only a free port leads to a detached `serve` and the marker; the path writes the marker plus at most one bounded `sync` (the missing-projection repair), never `migrate-tasks` and never `team/runner.json`. `ui restart` is the explicit stop-then-start verb.
46
+ - **Contract and projection.** The OpenAPI document moves to 43 operations and 14 mutations, migration `0004-tracker` renames the backlog tables and carries `tracker_item_tasks`, and the app operations table/DTO/mappers/service/store/forms follow the tracker schemas.
4
47
 
5
48
  ### Upstream research
6
49
 
@@ -32,19 +75,11 @@
32
75
 
33
76
  - **The job form runs on one resolver.** The private `apps/team-tasks-ui` create/edit form uses `react-hook-form` with a yup resolver (`mode: 'onTouched'`): submit stays disabled while the model is invalid, a field the API names is marked in place, a create-mode `409` names the duplicate id, and an edit-mode `409` renders the reload banner that re-reads the stored revision.
34
77
  - **A lossy write is refused, not invented.** `toJobWrite` returns `null` when a stored definition lacks the field its own kind requires (cron `expression`, interval `everySeconds`, command `argv`, pipeline `promptTemplate`/`runner`); the job detail toggle rejects with `E_VALIDATION` and says to rewrite the definition instead of substituting `''`, `0`, or `[]` into a `PUT`.
35
- - **Backlog actions validate in place.** The dialog renders a field error through the DS control (`errorMessage`/`note`) and takes `SLUG_PATTERN` from the API layer, so the client and the service share one slug grammar.
36
-
37
- ### Backlog tracker
38
-
39
- - **The `backlog` verb family.** `team-db.mjs backlog` adds the file-authoritative plan store (`backlog/items/*.json` committed, `backlog/queue/` ignored): `add`, `set`, `show`, `list`, `ready`, `validate`, `import` (the versioned envelope, idempotent by id, `--dry-run`), `enqueue`, `cancel`, `drain --claim`, `recover` and `prune`. The stored status lattice is the decision; every operational status (`effectiveStatus`, `ready`, `waitingOn`) is derived from the items, the queue entries and the hook-owned task state. The deterministic total order is `priority` ascending (lower runs first, default 5) → `createdAt` → `id`.
40
- - **The launch queue.** `backlog/config.json` carries `maxActive` (1…8, default 1); a task in a holding state (`in_progress`, `awaiting_artifact_receipt`, `blocked`) occupies a slot, one at a human gate does not. `backlog drain --claim` grants at most one claim and never starts a run; the hook stop seam consumes the claim, re-checks the graph at claim time, and `AI_RULES_TEAM_DB_BACKLOG_DRAIN_DISABLE=1` stops only the auto-drain. Claims older than 90 s with no task row are released on the next drain.
41
- - **Seven backlog routes.** `GET/POST /api/v1/backlog`, `GET/POST /api/v1/backlog/queue` + `POST …/queue/{entryId}/cancel`, and `GET/PUT /api/v1/backlog/{id}` take the HTTP API from 32 to **39 operations**; migration `0003-backlog` projects the store, and the kill switch `AI_RULES_TEAM_DB_DISABLE=1` turns the projection off while the backlog file verbs stay usable.
42
- - **Operator pages.** The private `apps/team-tasks-ui` app gains `/backlog` (the ordered list and the queue section of one snapshot, five states at three viewports) and `/backlog/[id]` (dependency state, queue history and the `stored` vs `task` completion source). The no-build `team-db-dashboard.mjs` is unchanged.
43
- - **Gates.** `test-team-db-backlog.mjs`, `test-team-db-backlog-order.mjs`, `-project`, `-queue`, and `-import` join `yarn test:team-db`, and `test-team-db-schema.mjs` covers migration `0003-backlog`.
78
+ - **Tracker actions validate in place.** The dialog renders a field error through the DS control (`errorMessage`/`note`) and takes `ITEM_ID_PATTERN` from the API layer, so the client and the service share one item-id grammar.
44
79
 
45
80
  ### Gates
46
81
 
47
- - **The new seams are covered.** `test-team-db-scheduler.mjs` races two starts (one `E_BUSY`, exit `4`), refuses an unknown placeholder, and pins the cmd.exe quote convention; `test-preset-tree-lock.mjs` covers token-guarded release, the warming window, the guard re-read, and a two-contender race; `test-generated-cache.mjs` asserts real-generator equivalence; `test-engine-upgrade.mjs` covers the empty/missing source and the duplicate-line fix; `test-cli-mcp-registration.mjs` covers import containment and error sanitization; `test-cli-update.mjs` covers the seed-when-absent job; `test-chain-team-phases-coverage.mjs` covers bootstrap `skipIf`; `test-upstream-research.mjs` runs from `test:upstream` and the preset-structure composite. Platform smoke runs `doctor` on the five-platform multi install instead of a separate Cursor project.
82
+ - **The new seams are covered.** `test-team-db-scheduler.mjs` races two starts (one `E_BUSY`, exit `4`), refuses an unknown placeholder, and pins the cmd.exe quote convention; `test-preset-tree-lock.mjs` covers token-guarded release, the warming window, the guard re-read, and a two-contender race; `test-generated-cache.mjs` asserts real-generator equivalence; `test-engine-upgrade.mjs` covers the empty/missing source and the duplicate-line fix; `test-cli-mcp-registration.mjs` covers import containment and error sanitization; `test-cli-update.mjs` covers the seed-when-absent job; `test-chain-team-phases-coverage.mjs` covers bootstrap `skipIf`; `test-upstream-research.mjs` runs from `test:upstream` and the preset-structure composite. The tracker family (`test-team-db-tracker.mjs`, `-tracker-order`, `-tracker-project`, `-tracker-queue`, `-tracker-import`, `-task-runner`) and `test-team-db-ui.mjs` join `yarn test:team-db`, and `test-team-db-schema.mjs` covers migration `0004-tracker`. Platform smoke runs `doctor` on the five-platform multi install instead of a separate Cursor project.
48
83
 
49
84
  ## 0.2.64
50
85
 
package/README.md CHANGED
@@ -25,7 +25,7 @@ Run `init` from the **app root** (`--cwd` if needed). Default `--preset` is `nex
25
25
  | Root agents | `REPO_AGENTS.md` → `AGENTS.md` (same file on all five; ZCode loads it natively) | | | | |
26
26
  | `/task` artifacts | **`.ai.local/team/`** (shared; templates refreshed; `tasks/<slug>/` never overwritten) | | | |
27
27
  | Template drift | **`.ai.local/.template-base.json`** (shared; one record per tree of files that hold a shipped template byte; `update` prints one drift line, `update --merge-ai-local` fast-forwards a file only when its recorded base still matches and reports the rest) | | | |
28
- | Self-learning engine | **`.ai.local/scripts/`** (shared; sixteen scripts — the six self-learning engine modules, `manifest.mjs`, the seven `team-db*.mjs` projection and scheduler modules, the `upstream-research.mjs` review, and the read-only `check-write-scope.mjs` write audit; existing files never overwritten) | | | |
28
+ | Self-learning engine | **`.ai.local/scripts/`** (shared; twenty-two scripts — the six self-learning engine modules, `manifest.mjs`, the ten `team-db*.mjs` projection, scheduler and lifecycle modules, the `upstream-research.mjs` review, the read-only `check-write-scope.mjs` write audit, the `aggregate-agent-task-metrics.mjs` aggregator, and the `processes.mjs` + `process-lease.mjs` process manager; existing files never overwritten) | | | |
29
29
  | Specs seed | `docs/specs/` copied only if the directory is **absent** | | | |
30
30
 
31
31
  OpenCode also ships **`.opencode/plugins/task-status/`**, a TUI sidebar for the active `/task` run (slug, state, elapsed time, step, remaining-time estimate, soft-stop). OpenCode auto-loads it; it needs no `opencode.json` entry, is refreshed by `update`, and is a viewer only — the chain hook stays manual.
@@ -138,9 +138,9 @@ node .ai.local/scripts/team-db.mjs check # schema, fingerprint, i
138
138
  node .ai.local/scripts/team-db.mjs serve # http://127.0.0.1:4178 + dashboard
139
139
  node .ai.local/scripts/team-db.mjs schedule # the timer: claims, runs, captures, reconciles
140
140
  node .ai.local/scripts/team-db.mjs jobs list # definitions + next fire, file-authoritative
141
- node .ai.local/scripts/team-db.mjs backlog list # the ordered backlog: items, ready set, waiting-on
142
- node .ai.local/scripts/team-db.mjs backlog enqueue --file <path|-> # record one launch request
143
- node .ai.local/scripts/team-db.mjs backlog drain --claim # grant one claim, never start a run
141
+ node .ai.local/scripts/team-db.mjs tracker list # the ordered tracker: items, ready set, waiting-on
142
+ node .ai.local/scripts/team-db.mjs tracker enqueue --file <path|-> # record one launch request
143
+ node .ai.local/scripts/team-db.mjs tracker drain --claim # grant one claim, never start a run
144
144
  AI_RULES_TEAM_DB_DISABLE=1 node .ai.local/scripts/team-db.mjs sync # no-op: file-only mode
145
145
  ```
146
146
 
@@ -148,8 +148,8 @@ Requires Node 22.13.0+ for `node:sqlite`; older runtimes stay file-only with one
148
148
  `migrate-tasks` is the one-command path: it creates the database when it is absent and writes
149
149
  only the delta against an existing one, so a fresh workspace and a populated database converge
150
150
  in one invocation.
151
- `team-db.mjs serve` binds loopback only, is read-only apart from the ten documented mutations
152
- (`POST /api/v1/sync`, the task delete, the four job writes and the four backlog writes), and serves the OpenAPI 3.1
151
+ `team-db.mjs serve` binds loopback only, is read-only apart from the fourteen documented mutations
152
+ (`POST /api/v1/sync`, the task delete, the four job writes and the eight tracker writes), and serves the OpenAPI 3.1
153
153
  document at `/openapi.json`. Details, environment names, retention, and rollback:
154
154
  [`docs/TEAM-DB.md`](docs/TEAM-DB.md).
155
155
 
@@ -13,10 +13,10 @@ const path = require('path');
13
13
  * `.ai.local/team/tasks/<slug>/artifact-manifest.json`; producers call it
14
14
  * instead of patching the JSON, which is a whole-file merge target.
15
15
  *
16
- * The seven `team-db*.mjs` modules are the rebuildable SQLite projection, its
17
- * read-only dashboard, and the scheduler. `team-db.mjs` is the CLI; the others
18
- * are loaded by it on demand, so a runtime without `node:sqlite` never imports
19
- * them.
16
+ * The `team-db*.mjs` modules are the rebuildable SQLite projection, its
17
+ * read-only dashboard, the scheduler, and the `ui` lifecycle supervisor.
18
+ * `team-db.mjs` is the CLI; the others are loaded by it on demand, so a runtime
19
+ * without `node:sqlite` never imports them.
20
20
  */
21
21
  const ENGINE_SCRIPTS = [
22
22
  'run.mjs',
@@ -27,7 +27,9 @@ const ENGINE_SCRIPTS = [
27
27
  'efficacy-oracle.mjs',
28
28
  'manifest.mjs',
29
29
  'team-db.mjs',
30
- 'team-db-backlog.mjs',
30
+ 'team-db-ui.mjs',
31
+ 'team-db-tracker.mjs',
32
+ 'team-db-task-runner.mjs',
31
33
  'team-db-schema.mjs',
32
34
  'team-db-project.mjs',
33
35
  'team-db-api.mjs',
@@ -40,6 +42,13 @@ const ENGINE_SCRIPTS = [
40
42
  // Read-only post-step write-scope audit used by build-verifier and code-reviewer.
41
43
  // Shells out to git, so it is not part of the self-learning loop module set.
42
44
  'check-write-scope.mjs',
45
+ // Process leases and the one view over them (`start|acquire|run|list|watch|
46
+ // scan|doctor|stop|serve`). `processes.mjs` owns a detached dev-server start
47
+ // and reuses `process-lease.mjs` for the protocol; both spawn `ps`/`lsof` and
48
+ // `processes.mjs` listens on loopback, so they are process tooling, not part
49
+ // of the self-learning loop modules.
50
+ 'process-lease.mjs',
51
+ 'processes.mjs',
43
52
  // Role/task metrics aggregation used by technical-retro; ships with the engine
44
53
  // so a consumer can run it from `.ai.local/scripts/` without the package.
45
54
  'aggregate-agent-task-metrics.mjs',
@@ -37,9 +37,16 @@ const AI_LOCAL_GITIGNORE = [
37
37
  '# Scheduler runtime state; jobs.json stays tracked (jobs as code).',
38
38
  'team/scheduler/runs/',
39
39
  'team/scheduler/state.json',
40
+ '# Tracker launch queue and opt-in runner runtime state; items and links stay tracked.',
41
+ 'team/tracker/queue/',
42
+ 'team/task-runs/',
40
43
  '# Per-step write-scope baselines; derived from git, never a project input.',
41
44
  'team/.write-scope/',
42
45
  'team/upstream/cursor.json',
46
+ '# Dashboard lifecycle marker (`.ai.local/.ui/api.json`); local runtime state, never commit.',
47
+ '.ui/',
48
+ '# Dev-server lifecycle markers (`.ai.local/.dev/<name>.json`); local runtime state, never commit.',
49
+ '.dev/',
43
50
  '',
44
51
  ].join('\n');
45
52
  const POINTER_README = `# Agent team artifacts moved
@@ -429,6 +429,7 @@ Load these when editing files under `packages/ai-rules/presets/**`, `.cursor/**`
429
429
  | `scripts/check-rule-eval.mjs` / `yarn check:rule-eval` | **Hard gate** inside `check-preset-structure.sh`: validates Incorrect/Correct pairs + `impact:` on **next-only** golden stems (`eval/next/manifest.json`). Backend / ios / php-hexagonal / php-laravel stems are out of scope until a stack adds `eval/<stack>/`. |
430
430
  | `scripts/check-release-consistency.mjs` / `yarn check:release-consistency` | **FAIL** when `packages/ai-rules/package.json` version and the newest `## <version>` heading in `CHANGELOG.md` disagree — a tag must not ship the previous release's notes. Wired into `check-preset-structure.sh`; fixture `test-release-consistency.mjs`. |
431
431
  | `scripts/check-team-db-contract.mjs` / `yarn check:team-db-contract` | **FAIL** when the checked-in OpenAPI 3.1 document (`docs/openapi/team-db.v1.json`) drifts from `team-db-openapi.mjs`, fails the vendored 3.1 meta-schema (sha256-pinned), loses an `operationId`, diverges from `ROUTE_TABLE` in either direction, carries an invalid example, or leaves a `$ref` unresolved. `--write` is the only writer; no network at gate time. Wired into `check-preset-structure.sh`. |
432
+ | `presets/_shared/hooks/guard-shell-command.mjs.tmpl` + `<stack>/guard-ports.json` | The shell guard asks before a server start whose port already listens: `startCommands` names the stack's dev-server command shape, `defaultPorts` the ports to probe when the command has no `--port`, and an explicit `--port` probes that port only. `pkill`, `killall`, and `xargs kill` always ask. Fixture `test-guard-shell-command.mjs`; rendered into every `hooks/guard-shell-command.mjs` by `generate-hooks.mjs`. |
432
433
  | `presets/_shared/ai-local/scripts/team-db-scheduler.mjs` | The scheduled-jobs module, shipped to consumers as `.ai.local/scripts/team-db-scheduler.mjs` (`ENGINE_SCRIPTS`): the job validator, a dependency-free five-field cron parser and next-fire on `Intl` zone math (both DST transitions are fixtures), the deterministic atomic `scheduler/jobs.json` store, the run-manifest and capped-capture helpers (the recorded sha256 covers exactly the pre-marker bytes, so a capped stream is not reported `E_LOG_HASH`), the projection into `scheduled_jobs` / `job_runs` / `job_run_events`, retention (1 MiB per stream, 200 runs, 30 days, 2 GiB; a pruned run directory takes its row with it; an active run is never pruned), restart reconciliation to `interrupted`, and `runScheduler` — the lease, the `BEGIN IMMEDIATE` claim, a durable run-now queue the timer re-reads and merges at every tick, the detached child with a process-group kill, `catch-up` bounded to five occurrences per gap with the truncation recorded (`E_CATCH_UP_TRUNCATED`), and the kill-switch drain. Fixture `test-team-db-scheduler.mjs`; concurrency fixtures live in `test-team-db-concurrency.mjs`. |
433
434
  | `scripts/test-team-db-*.mjs` | The team-db suite family: schema (17), project (18), migrate-tasks (5), dual-write (13), API (27), security (17), dashboard (10), concurrency (10), scheduler (34), and FAIL-direction fixtures (22). The fixtures prove each gate fails on its planted defect; `test-team-db-concurrency.mjs` covers first-creation races, a mixed writer/reader load, `SIGKILL` recovery, a held lock, the 5 s hook budget, and the scheduler's four seams (scheduler versus projector on one database, a `SIGKILL`ed scheduler reconciled to one `interrupted` row, 50 finalized runs inside the WAL bound, and a held exclusive lock that neither hangs nor leaves a lease). Wired into `check-preset-structure.sh`; `yarn test:team-db` runs the family. |
434
435
 
@@ -454,6 +455,46 @@ CI: [`.github/workflows/preset-structure.yml`](../../../.github/workflows/preset
454
455
 
455
456
  ---
456
457
 
458
+ ## Preset-tree lock and the loop
459
+
460
+ `yarn fix:generated` deletes and rebuilds every platform stack, so the writer and every gate that reads `presets/**` take one exclusive lock (`scripts/lib/preset-tree-lock.mjs`; lock directory `.preset-tree-lock/` with `owner.json` pid + token). From `packages/ai-rules/`:
461
+
462
+ ```bash
463
+ yarn preset:loop # fix:generated && check:changed && check:fast, in series
464
+ yarn fix:generated --wait 600000 # opt in to waiting for a live holder
465
+ ```
466
+
467
+ - **Fail closed.** A fatal reason (`unwritable`, `reclaim-failed`) stops the generator and both shell gates with exit 1 before any work. `--allow-unlocked` (generator, `run-locked.mjs`) or `AI_RULES_ALLOW_UNLOCKED=1` (both gates) proceeds with a loud `warn:` line. Read `fatal` before `skipped` in a caller: `skipped` is only the explicit opt-in.
468
+ - **Fail fast by default.** A live holder returns exit 1 with the held owner; `--wait <ms>` (or `AI_RULES_LOCK_WAIT_MS`) polls every 500 ms, `0` is the default. `--wait` is read by `fix:generated` and `run-locked.mjs`; the shell gates read only `AI_RULES_ALLOW_UNLOCKED` and stay fail-fast. A dead named owner is reclaimed on the first attempt, never waited on.
469
+ - **One holder per process chain.** A process that already holds the lock must not run a command that acquires it again: the owner pid is alive, so the child never goes stale and either fails fast or burns the whole wait budget. `fix:generated`, `check:fast`, `check:preset-structure`, `preset:loop`, and `release:gate` are never wrapped; `check:changed` / `check:preset-delta` stay usable while diagnosing a stuck lock.
470
+ - **Locked readers.** `scripts/run-locked.mjs [--label <l>] [--wait <ms>] [--allow-unlocked] [--root <dir>] -- <command> [args…]` acquires, runs with inherited stdio, releases in `finally`, and exits with the child's status (`128 + signo` on signal death). The package scripts wrap `check:generated-drift`, `check:preset-twin-map`, `check:preset-twin-drift`, `check:preset-token-budget`, `check:preset-leakage`, `check:frontmatter`, `check:consumer-links`, `check:shared-core-drift`, `check:preset-reachability`, `check:preset-i18n`, and `test:cli-init-clean`.
471
+ - **Residual unlocked readers.** Other `check:*` scripts and `.husky/pre-commit` call scripts directly; the composites and CI reach them through the lock. Inspect a blocked run with `cat .preset-tree-lock/owner.json` — a dead pid is reclaimed by the next run.
472
+ - **Atomic engine mirror.** `scripts/lib/engine-mirror.mjs` writes a same-directory temp file and `fs.renameSync`s it into `.ai.local/scripts/`, so a live engine process never reads a torn `run.mjs`; the mirror stays outside this lock (it copies the same bytes from a different root).
473
+ - **Announcing work.** `processes.mjs run --name <res> -- <command>` holds a manager lease for the child's lifetime and `processes.mjs watch` lists every holder; that lease is separate from the lock above — see § Agent process manager.
474
+
475
+ ---
476
+
477
+ ## Agent process manager
478
+
479
+ `processes.mjs` (with `process-lease.mjs`) is the one place that answers "who is doing what in this checkout". It owns `.ai.local/.processes/` (`leases/<name>.json`, a single-line `events.jsonl`, a `.reclaim/` guard per lease) and reads the markers other tools already write. `start` spawns a detached dev server and records a lease; `stop` / `status` / `list` prove ownership over the same record. From the repo root:
480
+
481
+ ```bash
482
+ node .ai.local/scripts/processes.mjs run --name preset-tree -- node scripts/fix-generated.mjs
483
+ node .ai.local/scripts/processes.mjs watch # live table, 1 s refresh
484
+ node .ai.local/scripts/processes.mjs list --json # one snapshot per line
485
+ node .ai.local/scripts/processes.mjs scan # listening ports + known shapes
486
+ node .ai.local/scripts/processes.mjs doctor # stale lease, dead marker, empty lease port
487
+ node .ai.local/scripts/processes.mjs serve # 127.0.0.1:4179 — JSON, SSE, HTML
488
+ ```
489
+
490
+ - **One protocol.** `acquire` creates `leases/<name>.json` with an exclusive `open(…, 'wx')` and records the **parent** process as the owner, because the CLI exits immediately — `--pid <n>` overrides it, and an owner that is not provably alive is refused with exit 2 (`acquire: a lease needs a live owner; pass --pid $$ (or use run)`); a second acquire is `held` (exit 1) unless `--wait <ms>`. `run` acquires, spawns with inherited stdio, releases in `finally`, and exits with the child's status (`128 + signo` on a signal death).
491
+ - **Liveness is pid + start time.** `pidStart` (`ps -o lstart=`, `/proc/<pid>/stat` on a host without `ps`) defeats pid reuse, and a heartbeat never makes a live holder stale. A stale lease is reclaimed on the first attempt inside `.processes/.reclaim/<name>`; `release` refuses a token that is not the owner's.
492
+ - **One snapshot, three surfaces.** `list` / `watch` / `serve` read own leases plus `preset-tree` (`.preset-tree-lock/owner.json`), `dev:<name>` (`.ai.local/.dev/*.json`), `team-db-serve` (`.ai.local/.ui/api.json`), `scheduler`, `runner:<slug>` (active runs only), and `git-index`. A missing source is skipped, a malformed one is a `warnings[]` entry; the snapshot never crashes.
493
+ - **Foreign is a label, never a kill.** `scan` reports listening TCP ports and the known command shapes (`fix-generated.mjs`, `check-preset-*.sh`, `team-db.mjs serve`, `storybook`, `next dev`, Playwright browsers); `--known-only` is the default. `stop --name <res>` or `stop --task <slug>` signals only a lease whose owner it can prove (live pid + matching `pidStart` + command line or lease port) and exits 4 with `stop: refused: …` otherwise; a stale lease is cleared without a signal.
494
+ - **Exit codes.** 0 ok · 1 held/timeout · 2 usage · 3 fatal (state directory unwritable, no `--allow-unlocked`) · 4 refused. `serve` binds a loopback host only.
495
+
496
+ ---
497
+
457
498
  ## Building blocks — what to add where
458
499
 
459
500
  When packaging a new habit for agents, pick **one** primary artifact. Prefer the lightest option that fits.
package/docs/TEAM-DB.md CHANGED
@@ -4,12 +4,14 @@
4
4
  The task files remain the source of truth; the database exists so an operator or a tool can
5
5
  query history without walking JSON on every request.
6
6
 
7
- The projection is installed by `init` as seven modules under `.ai.local/scripts/`:
7
+ The projection is installed by `init` as ten `team-db*.mjs` modules under `.ai.local/scripts/`:
8
8
 
9
9
  | Module | Role |
10
10
  |---|---|
11
- | `team-db.mjs` | CLI: `init`, `sync`, `delete`, `migrate-tasks`, `check`, `serve`, `jobs`, `schedule`, `backlog` |
12
- | `team-db-backlog.mjs` | the file-authoritative backlog: items, the launch queue, eligibility order, import |
11
+ | `team-db.mjs` | CLI: `init`, `sync`, `delete`, `migrate-tasks`, `check`, `serve`, `jobs`, `schedule`, `tracker`, `task-run`, `ui` |
12
+ | `team-db-ui.mjs` | the `ui` supervisor: probe-first `start`, `stop`, `status`, `restart`, the ownership marker, leader-only termination |
13
+ | `team-db-tracker.mjs` | the file-authoritative tracker: items, links, the launch queue, eligibility order, import |
14
+ | `team-db-task-runner.mjs` | the opt-in `team/runner.json` supervisor behind tracker Continue |
13
15
  | `team-db-schema.mjs` | capability probe, embedded migrations, pragmas, fingerprint, integrity |
14
16
  | `team-db-project.mjs` | parsers, idempotent projector, confirmed task deletion, retention, search |
15
17
  | `team-db-api.mjs` | `node:http` server (reads plus the bounded mutations), query layer, security boundary |
@@ -17,6 +19,12 @@ The projection is installed by `init` as seven modules under `.ai.local/scripts/
17
19
  | `team-db-dashboard.mjs` | the no-build dashboard (HTML, CSS, JS strings) |
18
20
  | `team-db-scheduler.mjs` | job model, cron/interval math, the file store, the projection, and the timer |
19
21
 
22
+ The same seeded set is `ENGINE_SCRIPTS` in `bin/lib/engine-scripts.js`: the ten `team-db*.mjs`
23
+ modules plus the self-learning engine, `manifest.mjs`, `upstream-research.mjs`,
24
+ `check-write-scope.mjs`, `aggregate-agent-task-metrics.mjs`, and the `processes.mjs` + `process-lease.mjs` process manager
25
+ (twenty-two entries; `node -e "require('./bin/lib/engine-scripts.js').ENGINE_SCRIPTS.length"`
26
+ prints the shipped count).
27
+
20
28
  ## Behavior contract
21
29
 
22
30
  - **Files are authoritative.** `status.json`, `pipeline.json`, `metrics.json`,
@@ -108,6 +116,9 @@ node .ai.local/scripts/team-db.mjs migrate-tasks [--root <team-dir>] [--quiet] [
108
116
  node .ai.local/scripts/team-db.mjs check [--root <team-dir>]
109
117
  node .ai.local/scripts/team-db.mjs serve [--root <team-dir>] [--host <addr>] [--port <n>]
110
118
  [--allow-remote] [--open]
119
+ node .ai.local/scripts/team-db.mjs ui start|restart [--root <team-dir>] [--json] [--quiet]
120
+ [--host <loopback>] [--port <n>] [--open]
121
+ node .ai.local/scripts/team-db.mjs ui stop|status [--root <team-dir>] [--json] [--quiet]
111
122
  node .ai.local/scripts/team-db.mjs jobs list [--enabled] [--sort <key>] [--json] [--quiet]
112
123
  node .ai.local/scripts/team-db.mjs jobs get <id> [--json]
113
124
  node .ai.local/scripts/team-db.mjs jobs put --file <path|-> [--dry-run] [--json]
@@ -117,12 +128,13 @@ node .ai.local/scripts/team-db.mjs jobs reconcile [--json]
117
128
  node .ai.local/scripts/team-db.mjs jobs run --id <id> [--json]
118
129
  node .ai.local/scripts/team-db.mjs schedule [--once] [--interval-ms <n>] [--grace-ms <n>]
119
130
  [--drain-ms <n>] [--json] [--quiet]
120
- node .ai.local/scripts/team-db.mjs backlog add --file <path|-> [--json] [--quiet]
121
- node .ai.local/scripts/team-db.mjs backlog set <id> --file <path|-> [--json]
122
- node .ai.local/scripts/team-db.mjs backlog show <id> | list [--status <csv>] [--ready] | ready | validate
131
+ node .ai.local/scripts/team-db.mjs tracker add --file <path|-> [--json] [--quiet]
132
+ node .ai.local/scripts/team-db.mjs tracker set <id> --file <path|-> [--json]
133
+ node .ai.local/scripts/team-db.mjs tracker show <id> | list [--status <csv>] [--ready] | ready | validate
123
134
  [--json]
124
- node .ai.local/scripts/team-db.mjs backlog import --file <path|-> [--dry-run] [--json]
125
- node .ai.local/scripts/team-db.mjs backlog enqueue --file <path|-> | cancel <entryId> | drain [--claim]
135
+ node .ai.local/scripts/team-db.mjs tracker import --file <path|-> [--dry-run] [--json]
136
+ node .ai.local/scripts/team-db.mjs tracker migrate-ids [--json] [--quiet]
137
+ node .ai.local/scripts/team-db.mjs tracker enqueue --file <path|-> | cancel <entryId> | drain [--claim]
126
138
  | recover | prune [--older-than <days>] [--json] [--quiet]
127
139
  ```
128
140
 
@@ -130,11 +142,11 @@ Exit codes: `0` ok, `1` at least one task failed, a delete refusal (unknown slug
130
142
  task, kill switch, folder-delete failure) or a migration checksum drifted, `2`
131
143
  database-level failure — a `delete` without `node:sqlite` refuses here rather than deleting
132
144
  the folder only, `3` usage, `4` deadline or busy database (the hook-shaped `sync --slug`
133
- deadline, or a delete that meets a locked database). The `backlog` verbs reuse the same
134
- vocabulary: `0` ok, `1` a validation refusal carrying its named code (`E_BACKLOG_CYCLE`,
135
- `E_BACKLOG_SELF_DEP`, `E_BACKLOG_UNKNOWN_DEP`, `E_BACKLOG_DUPLICATE_ID`, `E_ID_COLLISION`,
136
- `E_BACKLOG_TRANSITION`, `E_BACKLOG_REVISION`, `E_SCHEMA`), `3` usage, `4` the tree lock was
137
- contended (`E_BACKLOG_BUSY`).
145
+ deadline, or a delete that meets a locked database). The `tracker` verbs reuse the same
146
+ vocabulary: `0` ok, `1` a validation refusal carrying its named code (`E_TRACKER_CYCLE`,
147
+ `E_TRACKER_SELF_DEP`, `E_TRACKER_UNKNOWN_DEP`, `E_TRACKER_DUPLICATE_ID`, `E_ID_COLLISION`,
148
+ `E_TRACKER_TRANSITION`, `E_TRACKER_REVISION`, `E_SCHEMA`), `3` usage, `4` the tree lock was
149
+ contended (`E_TRACKER_BUSY`).
138
150
 
139
151
  `sync` is idempotent: a second run reports `inserted=0 updated=0 unchanged=<n>`. One changed
140
152
  byte changes exactly one document hash and one task content hash. A removed task directory is
@@ -170,57 +182,96 @@ targets must be on the same host.
170
182
 
171
183
  | Name | Effect |
172
184
  |---|---|
173
- | `AI_RULES_TEAM_DB_DISABLE` | truthy value turns the **projection** off — the database write points and `serve` stop; the task files and the `backlog` file verbs stay usable (the backlog is not disabled by this switch, R3-7) |
185
+ | `AI_RULES_TEAM_DB_DISABLE` | truthy value turns the **projection** off — the database write points, the `task-run ensure` seed and `serve` stop; `ui start`/`ui restart` refuse with `E_DISABLED` before any probe, write or signal; the task files and the `tracker` file verbs stay usable (the tracker is not disabled by this switch, R3-7) |
174
186
  | `AI_RULES_TEAM_DB_FORCE_FALLBACK` | truthy value forces the file-only path even on a supported runtime |
175
187
  | `AI_RULES_TEAM_DB_ROOT` | team directory when `--root` is absent |
176
188
  | `AI_RULES_TEAM_DB_PATH` | database file path (default `<teamRoot>/team.db`) |
177
189
  | `AI_RULES_TEAM_DB_LOG` | error-log path (default `<cwd>/.ai.local/team/team-db-errors.log`) |
178
190
  | `AI_RULES_TEAM_DB_SEAM` | phase label in the error log: `hook`, `receipt`, `cli`, `serve` |
179
- | `AI_RULES_TEAM_DB_BACKLOG_DRAIN_DISABLE` | truthy value stops the hook stop-seam auto-drain only; the `backlog` file verbs stay usable |
191
+ | `AI_RULES_TEAM_DB_TRACKER_DRAIN_DISABLE` | truthy value stops the hook stop-seam auto-drain only; the `tracker` file verbs stay usable |
180
192
 
181
193
  No other environment value is read or persisted. The error log stores a timestamp, a code,
182
194
  a phase, and a message; it never stores prompt content or an environment value, and it is
183
195
  trimmed to the newest 200 lines / 64 KiB.
184
196
 
185
- ## Backlog
186
-
187
- `team/backlog/` is a file-authoritative store with one writer: `team-db-backlog.mjs`.
188
- `backlog/items/<id>.json` is committed (the plan the team executes); `backlog/queue/` is
189
- runtime state and git-ignored. The stored status lattice is `planned|completed|cancelled|
190
- superseded`; every operational status (`effectiveStatus`, `ready`, `waitingOn`) is derived
191
- from the item files, the queue entries and the hook-owned `tasks/*/status.json` state, and
192
- is never written to a file. The total order is `priority` ascending — **lower runs
193
- first**, with the default priority 5 — then `createdAt`, then `id`; there is no `sort`
194
- parameter, so the list, the drain and the ready set can never disagree.
195
-
196
- An item's `id` matches the slug grammar, is immutable, and becomes the `/task` slug at
197
- launch; creating an item whose id already names a `tasks/<id>/` folder is refused with
198
- `E_ID_COLLISION`. Writes validate schema → identity → graph (first failure wins) and bump
199
- the `revision` CAS token; `backlog set` refuses a stale `revision` with `E_BACKLOG_REVISION`.
200
-
201
- The launch queue serializes task starts: `backlog enqueue` records a request (idempotent
202
- per item — a duplicate appends its reason to the entry history), `backlog drain --claim`
203
- grants at most one claim in drain order and never starts a run, and the hook stop seam
204
- consumes the claim and bootstraps `tasks/<slug>/pipeline.json` (the recorded `command` is
205
- never executed). `backlog/config.json` carries `maxActive` (1…8, default 1): a task in a
206
- holding state (`in_progress`, `awaiting_artifact_receipt`, `blocked`) occupies a slot, a
207
- task at a human gate does not. A claim older than 90 s with no task row is released on the
208
- next drain or by `backlog recover`; `backlog prune --older-than <days>` deletes aged
209
- terminal entry files only. The backlog module never writes `status.json`, `metrics.json`,
197
+ ## Tracker
198
+
199
+ `team/tracker/` is a file-authoritative store with one writer: `team-db-tracker.mjs`.
200
+ `tracker/items/<id>.json` is committed (the plan the team executes); `tracker/links/` is
201
+ committed (one relation record and prompt per item ↔ task pair); `tracker/queue/` and
202
+ `team/task-runs/` are runtime state and git-ignored. The stored status lattice is
203
+ `backlog|planned|completed|cancelled|superseded`; **backlog is the captured state** and is
204
+ not launchable until promoted to `planned`. Every operational status (`effectiveStatus`,
205
+ `ready`, `waitingOn`) is derived from the item files, the links, the queue entries and the
206
+ hook-owned `tasks/*/status.json` state, and is never written to a file. The total order is
207
+ `priority` ascending — **lower runs first**, with the default priority 5 — then
208
+ `createdAt`, then `id`; there is no `sort` parameter, so the list, the drain and the ready
209
+ set can never disagree.
210
+
211
+ An item's `id` is a positive integer assigned by the store and immutable. The store keeps
212
+ `tracker/sequence.json` (`{schemaVersion, nextId}`) and falls back to the highest existing
213
+ item file, so ids are monotonic and never reused. The id is **not** the team-task slug:
214
+ `tracker/link add` writes `tracker/links/<itemId>--<taskSlug>.json` plus its prompt, and one
215
+ item may carry several linked tasks. A task started from an item without an explicit slug
216
+ defaults to `tracker-<itemId>`. The link stores only the operator decision
217
+ (`requested|stopped|unlinked`); its effective state (`requested|claimed|active|paused|
218
+ stopped|completed|failed|unlinked`) is derived from the queue entry and the task row. A
219
+ legacy `tasks/<itemId>/` without a link file is shown as an implicit primary link;
220
+ `tracker link adopt` materializes it. `tracker delete <id>` removes the item, its links and
221
+ prompts, but never the team tasks; it refuses while a linked task is active or a queue
222
+ entry is non-terminal. Writes validate schema → identity → graph (first failure wins) and
223
+ bump the `revision` CAS token; `tracker set` refuses a stale `revision` with
224
+ `E_TRACKER_REVISION`.
225
+
226
+ The launch queue serializes task starts: `tracker enqueue` records a request with its own
227
+ `taskSlug` and `linkId` (a duplicate for the same task appends its reason to the entry
228
+ history), `tracker drain --claim` grants at most one claim in drain order and never starts
229
+ a run, and the hook stop seam consumes the claim and bootstraps `tasks/<taskSlug>/` with a
230
+ `pipeline.json` naming `trackerItemId`/`trackerLinkId` and the link prompt (the recorded
231
+ `command` is never executed). `tracker/config.json` carries `maxActive` (1…8, default 1): a
232
+ task in a holding state (`in_progress`, `awaiting_artifact_receipt`, `blocked`) occupies a
233
+ slot, a task at a human gate does not. A claim older than 90 s with no task row is released
234
+ on the next drain or by `tracker recover`; `tracker prune --older-than <days>` deletes aged
235
+ terminal entry files only. The tracker module never writes `status.json`, `metrics.json`,
210
236
  or `scheduler/jobs.json`.
211
237
 
212
- **Import envelope (D-8).** `backlog import --file <path|->` reads a versioned envelope
238
+ **Task control.** The tracker item detail can start a new linked task (link + queue
239
+ request), stop a link (cancel the queued request, write the per-task `tasks/<slug>/STOP`
240
+ sentinel, and terminate the active runner process group), and continue a paused/stopped
241
+ link. Continue uses the committed `team/runner.json`; `team-db.mjs task-run ensure` seeds it
242
+ with the OpenCode default when absent (the `ui` verbs never write it, and the kill switch
243
+ skips the seed), so an operator never edits the file by hand. The runner is supervised by
244
+ `team-db-task-runner.mjs` with an argv array, no shell, a repository-confined cwd, an env
245
+ allow-list, a timeout, capped logs and a process-group kill. A missing file still answers
246
+ `409 E_RUNNER_OFFLINE` and the UI disables Continue. The runner never writes `status.json`
247
+ or `metrics.json`. The seeded config is:
248
+
249
+ ```json
250
+ {
251
+ "schemaVersion": 1,
252
+ "runner": ["opencode", "run", "--format", "json", "/task-continue", "{taskSlug}"],
253
+ "cwd": "../..",
254
+ "timeoutMs": 1800000,
255
+ "envPassthrough": []
256
+ }
257
+ ```
258
+
259
+ Replace `runner` only when the host CLI differs; the argv array may use `{promptFile}`,
260
+ `{taskSlug}` or `{teamRoot}`, never a shell string.
261
+
262
+ **Import envelope (D-8).** `tracker import --file <path|->` reads a versioned envelope
213
263
  `{ schemaVersion: 1, source: { task, generatedAt }, items: [...] }`, validates every item
214
264
  as one transaction (a failure writes nothing), upserts by id, writes nothing on `--dry-run`,
215
265
  and an idle re-import (content-hash equality over the envelope fields) writes nothing.
216
266
  `revision` and `history` are store-owned and never part of that comparison.
217
267
 
218
- **Kill switch.** `AI_RULES_TEAM_DB_DISABLE=1` disables the **projection**, not the backlog:
219
- `backlog add|set|show|list|ready|validate|import|enqueue|cancel|drain|recover|prune` stay
220
- usable because they are file writes to the authoritative tree; the projection child each
221
- write verb spawns is skipped silently, and a runtime without `node:sqlite` keeps the store
222
- file-only end to end. `AI_RULES_TEAM_DB_BACKLOG_DRAIN_DISABLE=1` stops only the hook's
223
- automatic drain.
268
+ **Kill switch.** `AI_RULES_TEAM_DB_DISABLE=1` disables the **projection**, not the tracker:
269
+ `tracker add|set|show|list|ready|validate|import|enqueue|cancel|drain|recover|prune|link|delete|adopt`
270
+ stay usable because they are file writes to the authoritative tree; the projection child
271
+ each write verb spawns is skipped silently, and a runtime without `node:sqlite` keeps the
272
+ store file-only end to end. `AI_RULES_TEAM_DB_TRACKER_DRAIN_DISABLE=1` stops only the hook's
273
+ automatic drain. The API's `E_DISABLED` guard refuses every tracker mutation, including
274
+ `task-run`, before a child is spawned.
224
275
 
225
276
  ## Scheduled jobs
226
277
 
@@ -355,15 +406,22 @@ schema, so the next open moves the file aside as `team.db.mismatch-<stamp>`, reb
355
406
  reprojects from the task files — database-only rows are discarded by design, which is why the
356
407
  files are the source of truth. Run `sync` after an upgrade and the counters reconverge.
357
408
 
358
- Migration `0003-backlog` adds the backlog projection — `backlog_items`, `backlog_item_deps`,
359
- `backlog_queue`, `backlog_queue_events` — and five indexes, and moves `SCHEMA_VERSION` to 3.
409
+ Migration `0003-backlog` stays immutable; migration `0004-tracker` creates the tracker
410
+ tables (`tracker_items`, `tracker_item_deps`, `tracker_queue`, `tracker_queue_events`,
411
+ `tracker_item_tasks`) with **INTEGER** item ids, adds the queue task/link columns, drops the
412
+ backlog tables and moves `SCHEMA_VERSION` to 4. The projection is derived, so v4 does not
413
+ copy backlog rows: the next `sync` rebuilds the tracker rows from the files. On a tree that
414
+ still has the shipped slug store, run `tracker migrate-ids` once before that sync — it moves
415
+ `backlog/items` and `backlog/queue` into `tracker/`, converts every slug id to the integer
416
+ sequence, rewrites dependencies, links and queue entries, and records the reserved mapping
417
+ in `tracker/id-migration.json` until the conversion completes.
360
418
  It is additive and sha256-pinned like the first two: no `ALTER` of the `tasks` or scheduler
361
419
  tables, so a wrong v3 costs a v4, never an edit. `active`/`done` are derived from the joined
362
- task row, never stored; `backlog_item_deps` has no foreign key on `dep_id`, so a broken file
363
- set projects as a recorded `parse_error` instead of aborting the run. The backlog walker runs
420
+ task row, never stored; `tracker_item_deps` has no foreign key on `dep_id`, so a broken file
421
+ set projects as a recorded `parse_error` instead of aborting the run. The tracker walker runs
364
422
  two bounded directory listings inside the existing sync deadline — 200 items measure well
365
423
  under 250 ms — and is idempotent by `content_hash` with `absent_at` marking like the task
366
- walker; `sync --prune` removes tombstoned backlog rows.
424
+ walker; `sync --prune` removes tombstoned tracker rows.
367
425
 
368
426
  Each connection sets `journal_mode=WAL`, `busy_timeout=5000`, `foreign_keys=ON`, and
369
427
  `synchronous=NORMAL`. One task is projected in one transaction; a `SIGKILL` mid-sync
@@ -434,6 +492,89 @@ the confirmed task delete and the rescan to the named interface without authenti
434
492
  A job definition carries arbitrary `argv` and run-now enqueues it, so that surface
435
493
  executes operator-supplied commands as the API user; see `## Scheduled jobs`.
436
494
 
495
+ ## Dashboard lifecycle
496
+
497
+ `ui` runs the same server `serve` does, detached, with a marker the next call can prove:
498
+
499
+ ```bash
500
+ node .ai.local/scripts/team-db.mjs ui start [--host <loopback>] [--port <n>] [--open] [--json] [--quiet]
501
+ node .ai.local/scripts/team-db.mjs ui status [--json]
502
+ node .ai.local/scripts/team-db.mjs ui stop [--json]
503
+ node .ai.local/scripts/team-db.mjs ui restart [--host <loopback>] [--port <n>] [--open] [--json] [--quiet]
504
+ ```
505
+
506
+ Exit codes: `0` started, already running, stopped, or nothing running; `1` a refusal
507
+ (`E_UI_OTHER_ROOT`, `E_UI_PORT_FOREIGN`, `E_UI_DISABLED`, `E_UI_UNAVAILABLE`, `E_UI_DB_MISSING`),
508
+ or a leader that outlived `SIGKILL` (the marker is kept); `2` a start failure
509
+ (`E_UI_START_TIMEOUT`, `E_UI_CHILD_EXIT`, `E_UI_MARKER_UNWRITABLE`, `E_UI_PORT_IN_USE`); `3` usage.
510
+
511
+ The bind address is loopback (`127.0.0.1` by default): `--allow-remote` and any non-loopback
512
+ `--host` are usage errors, so the verb never exposes the dashboard.
513
+
514
+ **`start` is probe-first.** A server that already answers `200` on the requested target with this
515
+ repository's `rootId` is the no-op: the command prints the same pid, leaves `startedAt` untouched
516
+ and writes nothing. A live marker for this root on another port is reused the same way instead of
517
+ starting a second server. Only a free port leads to a detached `serve` and the marker; `restart` is
518
+ the verb that stops and replaces an owned server. The `ui` path writes the marker plus at most one
519
+ bounded `sync` — the missing-projection repair (`503 E_DB_MISSING` → one `team-db.mjs sync`, 30 s
520
+ cap) — and nothing under `team/`: no `migrate-tasks`, no `runner.json`. The `E_DISABLED` and
521
+ `E_UI_UNAVAILABLE` preflights run before any probe, write or signal, so a disabled runtime never
522
+ stops a live server.
523
+
524
+ The marker is `.ai.local/.ui/api.json` —
525
+ `{schemaVersion,pid,host,port,root,rootId,startedAt,command}` — written `0600` through
526
+ `api.json.tmp` + rename, with `rootId = sha256(realpath(resolved team root)).slice(0, 12)`: a hash,
527
+ never a path, and never transmitted. A marker whose `host` is outside `LOOPBACK_HOSTS`, or whose
528
+ port is not an integer in `0..65535`, is treated as unreadable: no probe ever targets it, and `stop`
529
+ removes it as stale.
530
+
531
+ **Ownership is the authorization.** A signal needs the marker pid alive **and**
532
+ `ps -p <pid> -o command=` matching `/team-db\.mjs\s+serve\b/`; the marker alone never authorizes one.
533
+ `stop` re-proves ownership immediately before each signal, signals that leader pid only — never the
534
+ process group, because `serve` spawns bounded delete children — sends `SIGTERM`, polls every 100 ms
535
+ for at most 5 000 ms, then `SIGKILL`s and verifies the pid is gone. A process that survives keeps its
536
+ marker and the command exits `1`. A live pid whose command does not match is left running with its
537
+ marker intact. A server answering with a different `rootId` is `E_UI_OTHER_ROOT`; a port answered by
538
+ something that is not a team-db health document is `E_UI_PORT_FOREIGN`; neither writes a marker.
539
+
540
+ **Platform.** `ui` is POSIX only: the ownership proof reads `ps`, and no equivalent command-line
541
+ reader exists on Windows, so no signal is ever sent there and `stop` reports the pid as unowned.
542
+ Use the foreground `serve` on Windows.
543
+
544
+ **The root override.** `--root <team-dir>` wins; otherwise `AI_RULES_TEAM_DB_ROOT`; otherwise
545
+ `<cwd>/.ai.local/team` — the same precedence as the projection layers, so `ui status` and `ui stop`
546
+ find a server started through the environment variable.
547
+
548
+ **The timer stays separate.** `ui start` never starts `team-db.mjs schedule`: the timer is one
549
+ foreground process holding a lease, and it is started explicitly. `ui start` and `ui status --json`
550
+ report the read-only `/health.scheduler` block instead.
551
+
552
+ A consumer tree installed from an older release needs `ai-rules update --fix`. A plain `update`
553
+ refreshes the command files but leaves an existing engine module alone, so a stale `team-db.mjs`
554
+ answers `ui` with exit `3`. A fork whose engine predates the verb uses the foreground
555
+ `node .ai.local/scripts/team-db.mjs serve`.
556
+
557
+ ### Dashboard parity
558
+
559
+ | Surface | Dashboard | Excluded, with the reason |
560
+ |---|---|---|
561
+ | Tasks | list, detail, rescan, confirmed delete | — |
562
+ | Task delete | `DELETE /api/v1/tasks/{slug}` behind `confirm()`; the `200` success is announced in the page-level live region and focus returns to the list heading; `409 E_ACTIVE_TASK` names `activeSlug` in the detail live region | — |
563
+ | Tracker | read-only list, item panel (dependencies, dependents, linked tasks), queue section | create, update, enqueue and cancel stay in `team-db.mjs tracker` and the API: the dashboard is a read-plus-two-mutations operator surface, and the four writes carry graph and lease rules a browser page must not own |
564
+ | Jobs | definitions, next fire, run-now, runs, logs | unchanged |
565
+ | Mutating calls | exactly two on the task surface: `POST /api/v1/sync`, `DELETE /api/v1/tasks/{slug}` | pinned by `test-team-db-dashboard.mjs`, which also enumerates the four pre-existing jobs writes (`POST`/`PUT`/`DELETE /api/v1/jobs*`, run-now) and fails on a seventh `method:` site; together with no inline style or handler, no absolute URL, and the unchanged CSP |
566
+
567
+ ### Delivery surface
568
+
569
+ | Platform | `next` commands | Other stacks |
570
+ |---|---|---|
571
+ | cursor | `ui-start.md`, `ui-stop.md` (authored) | — |
572
+ | claude, mavis, opencode, zcode | the same two files (generated twins) | — |
573
+ | every released stack | — | the verb: `node .ai.local/scripts/team-db.mjs ui start\|status\|stop\|restart` |
574
+
575
+ Ten twins across five platforms: `find presets -path '*/next/commands/ui-start.md' | wc -l` prints 5,
576
+ and the same for `ui-stop.md`. The verb is the contract on every stack; the command is discoverability.
577
+
437
578
  ## Prompt capture
438
579
 
439
580
  `prompt.md` and `prompt-log.md` are read by the existing projection. An inline work request calls `sync --slug <slug>` once after writing `prompt.md`; a post-terminal entry calls the same once after appending to `prompt-log.md`. Both are bounded, off the critical path, and never fail the file write. A missed projection is staleness, not data loss — the next full sync rebuilds the row.