@bonesofspring/ai-rules 0.2.65 → 0.2.67

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 (396) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.md +21 -11
  3. package/bin/cli.js +9 -1
  4. package/bin/lib/engine-scripts.js +34 -7
  5. package/bin/lib/engine-upgrade.js +5 -2
  6. package/bin/lib/seed-ai-local-team.js +32 -3
  7. package/docs/OPENCODE-COMPATIBILITY.md +1 -0
  8. package/docs/OPENCODE.md +31 -10
  9. package/docs/TEAM-DB.md +54 -14
  10. package/docs/TOKEN-ECONOMY.md +110 -0
  11. package/docs/openapi/team-db.v1.json +5 -5
  12. package/package.json +16 -3
  13. package/presets/_shared/ai-local/scripts/dump-output.mjs +422 -0
  14. package/presets/_shared/ai-local/scripts/team-db-openapi.mjs +3 -3
  15. package/presets/_shared/ai-local/scripts/team-db-tracker.mjs +2 -0
  16. package/presets/_shared/ai-local/scripts/team-db.mjs +82 -2
  17. package/presets/_shared/core/agent-team/agent-team-orchestrator.md +3 -1
  18. package/presets/_shared/core/architecture/feature-delivery-workflow.md +4 -0
  19. package/presets/_shared/core/quality/context-and-iteration.md +1 -0
  20. package/presets/_shared/hooks/chain-team-phases.sh.tmpl +9 -2
  21. package/presets/_shared/hooks/list-ai-local.mjs +17 -0
  22. package/presets/claude/android-kotlin/agents/task-analyst.md +1 -1
  23. package/presets/claude/android-kotlin/hooks/chain-team-phases.sh +9 -2
  24. package/presets/claude/android-kotlin/hooks/list-ai-local.mjs +17 -0
  25. package/presets/claude/android-kotlin/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  26. package/presets/claude/go/agents/task-analyst.md +1 -1
  27. package/presets/claude/go/hooks/chain-team-phases.sh +9 -2
  28. package/presets/claude/go/hooks/list-ai-local.mjs +17 -0
  29. package/presets/claude/go/rules/architecture/feature-delivery.md +4 -0
  30. package/presets/claude/go/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  31. package/presets/claude/ios-swift/agents/task-analyst.md +1 -1
  32. package/presets/claude/ios-swift/hooks/chain-team-phases.sh +9 -2
  33. package/presets/claude/ios-swift/hooks/list-ai-local.mjs +17 -0
  34. package/presets/claude/ios-swift/rules/architecture/feature-delivery.md +4 -0
  35. package/presets/claude/ios-swift/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  36. package/presets/claude/java/agents/task-analyst.md +1 -1
  37. package/presets/claude/java/hooks/chain-team-phases.sh +9 -2
  38. package/presets/claude/java/hooks/list-ai-local.mjs +17 -0
  39. package/presets/claude/java/rules/architecture/feature-delivery.md +4 -0
  40. package/presets/claude/java/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  41. package/presets/claude/mcp-ts/agents/task-analyst.md +1 -1
  42. package/presets/claude/mcp-ts/hooks/chain-team-phases.sh +9 -2
  43. package/presets/claude/mcp-ts/hooks/list-ai-local.mjs +17 -0
  44. package/presets/claude/mcp-ts/rules/architecture/feature-delivery.md +4 -0
  45. package/presets/claude/mcp-ts/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  46. package/presets/claude/mol/agents/task-analyst.md +1 -1
  47. package/presets/claude/mol/hooks/chain-team-phases.sh +9 -2
  48. package/presets/claude/mol/hooks/list-ai-local.mjs +17 -0
  49. package/presets/claude/mol/rules/architecture/feature-delivery-workflow.md +4 -0
  50. package/presets/claude/mol/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  51. package/presets/claude/next/agents/ci-investigator.md +5 -2
  52. package/presets/claude/next/agents/debugger.md +5 -2
  53. package/presets/claude/next/agents/feature-developer.md +5 -2
  54. package/presets/claude/next/agents/task-analyst.md +1 -1
  55. package/presets/claude/next/commands/README.md +1 -1
  56. package/presets/claude/next/commands/task.md +1 -1
  57. package/presets/claude/next/hooks/chain-team-phases.sh +9 -2
  58. package/presets/claude/next/hooks/list-ai-local.mjs +17 -0
  59. package/presets/claude/next/rules/architecture/feature-delivery-workflow.md +8 -0
  60. package/presets/claude/next/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  61. package/presets/claude/next/team/README.md +7 -3
  62. package/presets/claude/nuxt/agents/task-analyst.md +1 -1
  63. package/presets/claude/nuxt/hooks/chain-team-phases.sh +9 -2
  64. package/presets/claude/nuxt/hooks/list-ai-local.mjs +17 -0
  65. package/presets/claude/nuxt/rules/architecture/feature-delivery-workflow.md +4 -0
  66. package/presets/claude/nuxt/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  67. package/presets/claude/php-hexagonal/agents/task-analyst.md +1 -1
  68. package/presets/claude/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  69. package/presets/claude/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  70. package/presets/claude/php-hexagonal/rules/architecture/feature-delivery.md +4 -0
  71. package/presets/claude/php-hexagonal/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  72. package/presets/claude/php-laravel/agents/task-analyst.md +1 -1
  73. package/presets/claude/php-laravel/hooks/chain-team-phases.sh +9 -2
  74. package/presets/claude/php-laravel/hooks/list-ai-local.mjs +17 -0
  75. package/presets/claude/php-laravel/rules/architecture/feature-delivery.md +4 -0
  76. package/presets/claude/php-laravel/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  77. package/presets/claude/svelte/agents/task-analyst.md +1 -1
  78. package/presets/claude/svelte/hooks/chain-team-phases.sh +9 -2
  79. package/presets/claude/svelte/hooks/list-ai-local.mjs +17 -0
  80. package/presets/claude/svelte/rules/architecture/feature-delivery-workflow.md +4 -0
  81. package/presets/claude/svelte/rules/tooling-and-review/agent-team-orchestrator.md +3 -1
  82. package/presets/cursor/android-kotlin/agents/task-analyst.md +1 -1
  83. package/presets/cursor/android-kotlin/hooks/chain-team-phases.sh +9 -2
  84. package/presets/cursor/android-kotlin/hooks/list-ai-local.mjs +17 -0
  85. package/presets/cursor/android-kotlin/rules/agent-team-orchestrator.mdc +1 -1
  86. package/presets/cursor/go/agents/task-analyst.md +1 -1
  87. package/presets/cursor/go/hooks/chain-team-phases.sh +9 -2
  88. package/presets/cursor/go/hooks/list-ai-local.mjs +17 -0
  89. package/presets/cursor/go/rules/agent-team-orchestrator.mdc +1 -1
  90. package/presets/cursor/ios-swift/agents/task-analyst.md +1 -1
  91. package/presets/cursor/ios-swift/hooks/chain-team-phases.sh +9 -2
  92. package/presets/cursor/ios-swift/hooks/list-ai-local.mjs +17 -0
  93. package/presets/cursor/ios-swift/rules/agent-team-orchestrator.mdc +1 -1
  94. package/presets/cursor/java/agents/task-analyst.md +1 -1
  95. package/presets/cursor/java/hooks/chain-team-phases.sh +9 -2
  96. package/presets/cursor/java/hooks/list-ai-local.mjs +17 -0
  97. package/presets/cursor/java/rules/agent-team-orchestrator.mdc +1 -1
  98. package/presets/cursor/mcp-ts/agents/task-analyst.md +1 -1
  99. package/presets/cursor/mcp-ts/hooks/chain-team-phases.sh +9 -2
  100. package/presets/cursor/mcp-ts/hooks/list-ai-local.mjs +17 -0
  101. package/presets/cursor/mcp-ts/rules/agent-team-orchestrator.mdc +1 -1
  102. package/presets/cursor/mol/agents/task-analyst.md +1 -1
  103. package/presets/cursor/mol/hooks/chain-team-phases.sh +9 -2
  104. package/presets/cursor/mol/hooks/list-ai-local.mjs +17 -0
  105. package/presets/cursor/mol/rules/agent-team-orchestrator.mdc +1 -1
  106. package/presets/cursor/next/agents/task-analyst.md +1 -1
  107. package/presets/cursor/next/commands/README.md +1 -1
  108. package/presets/cursor/next/commands/task.md +1 -1
  109. package/presets/cursor/next/hooks/chain-team-phases.sh +9 -2
  110. package/presets/cursor/next/hooks/list-ai-local.mjs +17 -0
  111. package/presets/cursor/next/rules/agent-team-orchestrator.mdc +3 -1
  112. package/presets/cursor/next/rules/feature-delivery-workflow.mdc +4 -0
  113. package/presets/cursor/next/team/README.md +7 -3
  114. package/presets/cursor/nuxt/agents/task-analyst.md +1 -1
  115. package/presets/cursor/nuxt/hooks/chain-team-phases.sh +9 -2
  116. package/presets/cursor/nuxt/hooks/list-ai-local.mjs +17 -0
  117. package/presets/cursor/nuxt/rules/agent-team-orchestrator.mdc +1 -1
  118. package/presets/cursor/php-hexagonal/agents/task-analyst.md +1 -1
  119. package/presets/cursor/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  120. package/presets/cursor/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  121. package/presets/cursor/php-hexagonal/rules/agent-team-orchestrator.mdc +1 -1
  122. package/presets/cursor/php-laravel/agents/task-analyst.md +1 -1
  123. package/presets/cursor/php-laravel/hooks/chain-team-phases.sh +9 -2
  124. package/presets/cursor/php-laravel/hooks/list-ai-local.mjs +17 -0
  125. package/presets/cursor/php-laravel/rules/agent-team-orchestrator.mdc +1 -1
  126. package/presets/cursor/svelte/agents/task-analyst.md +1 -1
  127. package/presets/cursor/svelte/hooks/chain-team-phases.sh +9 -2
  128. package/presets/cursor/svelte/hooks/list-ai-local.mjs +17 -0
  129. package/presets/cursor/svelte/rules/agent-team-orchestrator.mdc +1 -1
  130. package/presets/mavis/android-kotlin/adapter-map.json +1 -1
  131. package/presets/mavis/android-kotlin/agents/task-analyst.md +1 -1
  132. package/presets/mavis/android-kotlin/hooks/chain-team-phases.sh +9 -2
  133. package/presets/mavis/android-kotlin/hooks/list-ai-local.mjs +17 -0
  134. package/presets/mavis/android-kotlin/rules/agent-team-orchestrator.md +3 -1
  135. package/presets/mavis/go/adapter-map.json +1 -1
  136. package/presets/mavis/go/agents/task-analyst.md +1 -1
  137. package/presets/mavis/go/hooks/chain-team-phases.sh +9 -2
  138. package/presets/mavis/go/hooks/list-ai-local.mjs +17 -0
  139. package/presets/mavis/go/rules/agent-team-orchestrator.md +3 -1
  140. package/presets/mavis/go/rules/feature-delivery-workflow.md +4 -0
  141. package/presets/mavis/ios-swift/adapter-map.json +1 -1
  142. package/presets/mavis/ios-swift/agents/task-analyst.md +1 -1
  143. package/presets/mavis/ios-swift/hooks/chain-team-phases.sh +9 -2
  144. package/presets/mavis/ios-swift/hooks/list-ai-local.mjs +17 -0
  145. package/presets/mavis/ios-swift/rules/agent-team-orchestrator.md +3 -1
  146. package/presets/mavis/ios-swift/rules/feature-delivery-workflow.md +4 -0
  147. package/presets/mavis/java/adapter-map.json +1 -1
  148. package/presets/mavis/java/agents/task-analyst.md +1 -1
  149. package/presets/mavis/java/hooks/chain-team-phases.sh +9 -2
  150. package/presets/mavis/java/hooks/list-ai-local.mjs +17 -0
  151. package/presets/mavis/java/rules/agent-team-orchestrator.md +3 -1
  152. package/presets/mavis/java/rules/feature-delivery-workflow.md +4 -0
  153. package/presets/mavis/mcp-ts/adapter-map.json +1 -1
  154. package/presets/mavis/mcp-ts/agents/task-analyst.md +1 -1
  155. package/presets/mavis/mcp-ts/hooks/chain-team-phases.sh +9 -2
  156. package/presets/mavis/mcp-ts/hooks/list-ai-local.mjs +17 -0
  157. package/presets/mavis/mcp-ts/rules/agent-team-orchestrator.md +3 -1
  158. package/presets/mavis/mcp-ts/rules/feature-delivery-workflow.md +4 -0
  159. package/presets/mavis/mol/adapter-map.json +1 -1
  160. package/presets/mavis/mol/agents/task-analyst.md +1 -1
  161. package/presets/mavis/mol/hooks/chain-team-phases.sh +9 -2
  162. package/presets/mavis/mol/hooks/list-ai-local.mjs +17 -0
  163. package/presets/mavis/mol/rules/agent-team-orchestrator.md +3 -1
  164. package/presets/mavis/mol/rules/feature-delivery-workflow.md +4 -0
  165. package/presets/mavis/next/adapter-map.json +9 -1
  166. package/presets/mavis/next/agents/ci-investigator.md +5 -2
  167. package/presets/mavis/next/agents/debugger.md +5 -2
  168. package/presets/mavis/next/agents/feature-developer.md +5 -2
  169. package/presets/mavis/next/agents/task-analyst.md +1 -1
  170. package/presets/mavis/next/commands/README.md +1 -1
  171. package/presets/mavis/next/commands/task.md +1 -1
  172. package/presets/mavis/next/hooks/chain-team-phases.sh +9 -2
  173. package/presets/mavis/next/hooks/list-ai-local.mjs +17 -0
  174. package/presets/mavis/next/rules/agent-team-orchestrator.md +3 -1
  175. package/presets/mavis/next/rules/feature-delivery-workflow.md +8 -0
  176. package/presets/mavis/next/team/README.md +7 -3
  177. package/presets/mavis/nuxt/adapter-map.json +1 -1
  178. package/presets/mavis/nuxt/agents/task-analyst.md +1 -1
  179. package/presets/mavis/nuxt/hooks/chain-team-phases.sh +9 -2
  180. package/presets/mavis/nuxt/hooks/list-ai-local.mjs +17 -0
  181. package/presets/mavis/nuxt/rules/agent-team-orchestrator.md +3 -1
  182. package/presets/mavis/nuxt/rules/feature-delivery-workflow.md +4 -0
  183. package/presets/mavis/php-hexagonal/adapter-map.json +1 -1
  184. package/presets/mavis/php-hexagonal/agents/task-analyst.md +1 -1
  185. package/presets/mavis/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  186. package/presets/mavis/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  187. package/presets/mavis/php-hexagonal/rules/agent-team-orchestrator.md +3 -1
  188. package/presets/mavis/php-hexagonal/rules/feature-delivery-workflow.md +4 -0
  189. package/presets/mavis/php-laravel/adapter-map.json +1 -1
  190. package/presets/mavis/php-laravel/agents/task-analyst.md +1 -1
  191. package/presets/mavis/php-laravel/hooks/chain-team-phases.sh +9 -2
  192. package/presets/mavis/php-laravel/hooks/list-ai-local.mjs +17 -0
  193. package/presets/mavis/php-laravel/rules/agent-team-orchestrator.md +3 -1
  194. package/presets/mavis/php-laravel/rules/feature-delivery-workflow.md +4 -0
  195. package/presets/mavis/svelte/adapter-map.json +1 -1
  196. package/presets/mavis/svelte/agents/task-analyst.md +1 -1
  197. package/presets/mavis/svelte/hooks/chain-team-phases.sh +9 -2
  198. package/presets/mavis/svelte/hooks/list-ai-local.mjs +17 -0
  199. package/presets/mavis/svelte/rules/agent-team-orchestrator.md +3 -1
  200. package/presets/mavis/svelte/rules/feature-delivery-workflow.md +4 -0
  201. package/presets/opencode/android-kotlin/adapter-map.json +1 -1
  202. package/presets/opencode/android-kotlin/agents/task-analyst.md +1 -1
  203. package/presets/opencode/android-kotlin/hooks/chain-team-phases.sh +9 -2
  204. package/presets/opencode/android-kotlin/hooks/list-ai-local.mjs +17 -0
  205. package/presets/opencode/android-kotlin/rules/agent-team-orchestrator.md +3 -1
  206. package/presets/opencode/go/adapter-map.json +1 -1
  207. package/presets/opencode/go/agents/task-analyst.md +1 -1
  208. package/presets/opencode/go/hooks/chain-team-phases.sh +9 -2
  209. package/presets/opencode/go/hooks/list-ai-local.mjs +17 -0
  210. package/presets/opencode/go/rules/agent-team-orchestrator.md +3 -1
  211. package/presets/opencode/go/rules/feature-delivery-workflow.md +4 -0
  212. package/presets/opencode/ios-swift/adapter-map.json +1 -1
  213. package/presets/opencode/ios-swift/agents/task-analyst.md +1 -1
  214. package/presets/opencode/ios-swift/hooks/chain-team-phases.sh +9 -2
  215. package/presets/opencode/ios-swift/hooks/list-ai-local.mjs +17 -0
  216. package/presets/opencode/ios-swift/rules/agent-team-orchestrator.md +3 -1
  217. package/presets/opencode/ios-swift/rules/feature-delivery-workflow.md +4 -0
  218. package/presets/opencode/java/adapter-map.json +1 -1
  219. package/presets/opencode/java/agents/task-analyst.md +1 -1
  220. package/presets/opencode/java/hooks/chain-team-phases.sh +9 -2
  221. package/presets/opencode/java/hooks/list-ai-local.mjs +17 -0
  222. package/presets/opencode/java/rules/agent-team-orchestrator.md +3 -1
  223. package/presets/opencode/java/rules/feature-delivery-workflow.md +4 -0
  224. package/presets/opencode/mcp-ts/adapter-map.json +1 -1
  225. package/presets/opencode/mcp-ts/agents/task-analyst.md +1 -1
  226. package/presets/opencode/mcp-ts/hooks/chain-team-phases.sh +9 -2
  227. package/presets/opencode/mcp-ts/hooks/list-ai-local.mjs +17 -0
  228. package/presets/opencode/mcp-ts/rules/agent-team-orchestrator.md +3 -1
  229. package/presets/opencode/mcp-ts/rules/feature-delivery-workflow.md +4 -0
  230. package/presets/opencode/mol/adapter-map.json +1 -1
  231. package/presets/opencode/mol/agents/task-analyst.md +1 -1
  232. package/presets/opencode/mol/hooks/chain-team-phases.sh +9 -2
  233. package/presets/opencode/mol/hooks/list-ai-local.mjs +17 -0
  234. package/presets/opencode/mol/rules/agent-team-orchestrator.md +3 -1
  235. package/presets/opencode/mol/rules/feature-delivery-workflow.md +4 -0
  236. package/presets/opencode/next/adapter-map.json +9 -1
  237. package/presets/opencode/next/agents/ci-investigator.md +5 -2
  238. package/presets/opencode/next/agents/debugger.md +5 -2
  239. package/presets/opencode/next/agents/feature-developer.md +5 -2
  240. package/presets/opencode/next/agents/task-analyst.md +1 -1
  241. package/presets/opencode/next/commands/README.md +1 -1
  242. package/presets/opencode/next/commands/task.md +1 -1
  243. package/presets/opencode/next/hooks/chain-team-phases.sh +9 -2
  244. package/presets/opencode/next/hooks/list-ai-local.mjs +17 -0
  245. package/presets/opencode/next/rules/agent-team-orchestrator.md +3 -1
  246. package/presets/opencode/next/rules/feature-delivery-workflow.md +8 -0
  247. package/presets/opencode/next/team/README.md +7 -3
  248. package/presets/opencode/nuxt/adapter-map.json +1 -1
  249. package/presets/opencode/nuxt/agents/task-analyst.md +1 -1
  250. package/presets/opencode/nuxt/hooks/chain-team-phases.sh +9 -2
  251. package/presets/opencode/nuxt/hooks/list-ai-local.mjs +17 -0
  252. package/presets/opencode/nuxt/rules/agent-team-orchestrator.md +3 -1
  253. package/presets/opencode/nuxt/rules/feature-delivery-workflow.md +4 -0
  254. package/presets/opencode/php-hexagonal/adapter-map.json +1 -1
  255. package/presets/opencode/php-hexagonal/agents/task-analyst.md +1 -1
  256. package/presets/opencode/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  257. package/presets/opencode/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  258. package/presets/opencode/php-hexagonal/rules/agent-team-orchestrator.md +3 -1
  259. package/presets/opencode/php-hexagonal/rules/feature-delivery-workflow.md +4 -0
  260. package/presets/opencode/php-laravel/adapter-map.json +1 -1
  261. package/presets/opencode/php-laravel/agents/task-analyst.md +1 -1
  262. package/presets/opencode/php-laravel/hooks/chain-team-phases.sh +9 -2
  263. package/presets/opencode/php-laravel/hooks/list-ai-local.mjs +17 -0
  264. package/presets/opencode/php-laravel/rules/agent-team-orchestrator.md +3 -1
  265. package/presets/opencode/php-laravel/rules/feature-delivery-workflow.md +4 -0
  266. package/presets/opencode/plugins/output-guard/README.md +43 -0
  267. package/presets/opencode/plugins/output-guard/index.ts +300 -0
  268. package/presets/opencode/plugins/output-guard/package.json +9 -0
  269. package/presets/opencode/plugins/output-guard/rewrite.ts +149 -0
  270. package/presets/opencode/plugins/task-status/README.md +23 -11
  271. package/presets/opencode/plugins/task-status/details-data.ts +64 -46
  272. package/presets/opencode/plugins/task-status/details.tsx +12 -2
  273. package/presets/opencode/plugins/task-status/format.ts +16 -0
  274. package/presets/opencode/plugins/task-status/prompt-text.ts +37 -0
  275. package/presets/opencode/plugins/task-status/task-view.ts +281 -179
  276. package/presets/opencode/plugins/task-status/tui.tsx +60 -16
  277. package/presets/opencode/plugins/task-status/types.ts +74 -0
  278. package/presets/opencode/svelte/adapter-map.json +1 -1
  279. package/presets/opencode/svelte/agents/task-analyst.md +1 -1
  280. package/presets/opencode/svelte/hooks/chain-team-phases.sh +9 -2
  281. package/presets/opencode/svelte/hooks/list-ai-local.mjs +17 -0
  282. package/presets/opencode/svelte/rules/agent-team-orchestrator.md +3 -1
  283. package/presets/opencode/svelte/rules/feature-delivery-workflow.md +4 -0
  284. package/presets/zcode/android-kotlin/adapter-map.json +1 -1
  285. package/presets/zcode/android-kotlin/agents/task-analyst.md +1 -1
  286. package/presets/zcode/android-kotlin/hooks/chain-team-phases.sh +9 -2
  287. package/presets/zcode/android-kotlin/hooks/list-ai-local.mjs +17 -0
  288. package/presets/zcode/android-kotlin/rules/agent-team-orchestrator.md +3 -1
  289. package/presets/zcode/go/adapter-map.json +1 -1
  290. package/presets/zcode/go/agents/task-analyst.md +1 -1
  291. package/presets/zcode/go/hooks/chain-team-phases.sh +9 -2
  292. package/presets/zcode/go/hooks/list-ai-local.mjs +17 -0
  293. package/presets/zcode/go/rules/agent-team-orchestrator.md +3 -1
  294. package/presets/zcode/go/rules/feature-delivery-workflow.md +4 -0
  295. package/presets/zcode/ios-swift/adapter-map.json +1 -1
  296. package/presets/zcode/ios-swift/agents/task-analyst.md +1 -1
  297. package/presets/zcode/ios-swift/hooks/chain-team-phases.sh +9 -2
  298. package/presets/zcode/ios-swift/hooks/list-ai-local.mjs +17 -0
  299. package/presets/zcode/ios-swift/rules/agent-team-orchestrator.md +3 -1
  300. package/presets/zcode/ios-swift/rules/feature-delivery-workflow.md +4 -0
  301. package/presets/zcode/java/adapter-map.json +1 -1
  302. package/presets/zcode/java/agents/task-analyst.md +1 -1
  303. package/presets/zcode/java/hooks/chain-team-phases.sh +9 -2
  304. package/presets/zcode/java/hooks/list-ai-local.mjs +17 -0
  305. package/presets/zcode/java/rules/agent-team-orchestrator.md +3 -1
  306. package/presets/zcode/java/rules/feature-delivery-workflow.md +4 -0
  307. package/presets/zcode/mcp-ts/adapter-map.json +1 -1
  308. package/presets/zcode/mcp-ts/agents/task-analyst.md +1 -1
  309. package/presets/zcode/mcp-ts/hooks/chain-team-phases.sh +9 -2
  310. package/presets/zcode/mcp-ts/hooks/list-ai-local.mjs +17 -0
  311. package/presets/zcode/mcp-ts/rules/agent-team-orchestrator.md +3 -1
  312. package/presets/zcode/mcp-ts/rules/feature-delivery-workflow.md +4 -0
  313. package/presets/zcode/mol/adapter-map.json +1 -1
  314. package/presets/zcode/mol/agents/task-analyst.md +1 -1
  315. package/presets/zcode/mol/hooks/chain-team-phases.sh +9 -2
  316. package/presets/zcode/mol/hooks/list-ai-local.mjs +17 -0
  317. package/presets/zcode/mol/rules/agent-team-orchestrator.md +3 -1
  318. package/presets/zcode/mol/rules/feature-delivery-workflow.md +4 -0
  319. package/presets/zcode/next/adapter-map.json +9 -1
  320. package/presets/zcode/next/agents/ci-investigator.md +5 -2
  321. package/presets/zcode/next/agents/debugger.md +5 -2
  322. package/presets/zcode/next/agents/feature-developer.md +5 -2
  323. package/presets/zcode/next/agents/task-analyst.md +1 -1
  324. package/presets/zcode/next/commands/README.md +1 -1
  325. package/presets/zcode/next/commands/task.md +1 -1
  326. package/presets/zcode/next/hooks/chain-team-phases.sh +9 -2
  327. package/presets/zcode/next/hooks/list-ai-local.mjs +17 -0
  328. package/presets/zcode/next/rules/agent-team-orchestrator.md +3 -1
  329. package/presets/zcode/next/rules/feature-delivery-workflow.md +8 -0
  330. package/presets/zcode/next/team/README.md +7 -3
  331. package/presets/zcode/nuxt/adapter-map.json +1 -1
  332. package/presets/zcode/nuxt/agents/task-analyst.md +1 -1
  333. package/presets/zcode/nuxt/hooks/chain-team-phases.sh +9 -2
  334. package/presets/zcode/nuxt/hooks/list-ai-local.mjs +17 -0
  335. package/presets/zcode/nuxt/rules/agent-team-orchestrator.md +3 -1
  336. package/presets/zcode/nuxt/rules/feature-delivery-workflow.md +4 -0
  337. package/presets/zcode/php-hexagonal/adapter-map.json +1 -1
  338. package/presets/zcode/php-hexagonal/agents/task-analyst.md +1 -1
  339. package/presets/zcode/php-hexagonal/hooks/chain-team-phases.sh +9 -2
  340. package/presets/zcode/php-hexagonal/hooks/list-ai-local.mjs +17 -0
  341. package/presets/zcode/php-hexagonal/rules/agent-team-orchestrator.md +3 -1
  342. package/presets/zcode/php-hexagonal/rules/feature-delivery-workflow.md +4 -0
  343. package/presets/zcode/php-laravel/adapter-map.json +1 -1
  344. package/presets/zcode/php-laravel/agents/task-analyst.md +1 -1
  345. package/presets/zcode/php-laravel/hooks/chain-team-phases.sh +9 -2
  346. package/presets/zcode/php-laravel/hooks/list-ai-local.mjs +17 -0
  347. package/presets/zcode/php-laravel/rules/agent-team-orchestrator.md +3 -1
  348. package/presets/zcode/php-laravel/rules/feature-delivery-workflow.md +4 -0
  349. package/presets/zcode/svelte/adapter-map.json +1 -1
  350. package/presets/zcode/svelte/agents/task-analyst.md +1 -1
  351. package/presets/zcode/svelte/hooks/chain-team-phases.sh +9 -2
  352. package/presets/zcode/svelte/hooks/list-ai-local.mjs +17 -0
  353. package/presets/zcode/svelte/rules/agent-team-orchestrator.md +3 -1
  354. package/presets/zcode/svelte/rules/feature-delivery-workflow.md +4 -0
  355. package/scripts/report-context-cost.mjs +432 -0
  356. package/presets/_shared/ai-local/scripts/upstream-research.mjs +0 -2964
  357. package/presets/claude/next/commands/upstream-research.md +0 -23
  358. package/presets/claude/next/team/upstream/config.json +0 -31
  359. package/presets/claude/next/team/upstream/digest-template.md +0 -55
  360. package/presets/claude/next/team/upstream/jobs.json +0 -34
  361. package/presets/claude/next/team/upstream/opencode.json +0 -34
  362. package/presets/claude/next/team/upstream/projects.json +0 -4
  363. package/presets/claude/next/team/upstream/prompt.md +0 -77
  364. package/presets/claude/next/team/upstream/signatures.json +0 -9
  365. package/presets/cursor/next/commands/upstream-research.md +0 -23
  366. package/presets/cursor/next/team/upstream/config.json +0 -31
  367. package/presets/cursor/next/team/upstream/digest-template.md +0 -55
  368. package/presets/cursor/next/team/upstream/jobs.json +0 -34
  369. package/presets/cursor/next/team/upstream/opencode.json +0 -34
  370. package/presets/cursor/next/team/upstream/projects.json +0 -4
  371. package/presets/cursor/next/team/upstream/prompt.md +0 -77
  372. package/presets/cursor/next/team/upstream/signatures.json +0 -9
  373. package/presets/mavis/next/commands/upstream-research.md +0 -18
  374. package/presets/mavis/next/team/upstream/config.json +0 -31
  375. package/presets/mavis/next/team/upstream/digest-template.md +0 -55
  376. package/presets/mavis/next/team/upstream/jobs.json +0 -34
  377. package/presets/mavis/next/team/upstream/opencode.json +0 -34
  378. package/presets/mavis/next/team/upstream/projects.json +0 -4
  379. package/presets/mavis/next/team/upstream/prompt.md +0 -77
  380. package/presets/mavis/next/team/upstream/signatures.json +0 -9
  381. package/presets/opencode/next/commands/upstream-research.md +0 -26
  382. package/presets/opencode/next/team/upstream/config.json +0 -31
  383. package/presets/opencode/next/team/upstream/digest-template.md +0 -55
  384. package/presets/opencode/next/team/upstream/jobs.json +0 -34
  385. package/presets/opencode/next/team/upstream/opencode.json +0 -34
  386. package/presets/opencode/next/team/upstream/projects.json +0 -4
  387. package/presets/opencode/next/team/upstream/prompt.md +0 -77
  388. package/presets/opencode/next/team/upstream/signatures.json +0 -9
  389. package/presets/zcode/next/commands/upstream-research.md +0 -26
  390. package/presets/zcode/next/team/upstream/config.json +0 -31
  391. package/presets/zcode/next/team/upstream/digest-template.md +0 -55
  392. package/presets/zcode/next/team/upstream/jobs.json +0 -34
  393. package/presets/zcode/next/team/upstream/opencode.json +0 -34
  394. package/presets/zcode/next/team/upstream/projects.json +0 -4
  395. package/presets/zcode/next/team/upstream/prompt.md +0 -77
  396. package/presets/zcode/next/team/upstream/signatures.json +0 -9
@@ -1,23 +1,23 @@
1
1
  import fs from "node:fs"
2
2
  import type { Dirent } from "node:fs"
3
+ import os from "node:os"
3
4
  import path from "node:path"
4
- import { createEtaStats, estimateEta } from "./eta"
5
- import type { EtaStats } from "./eta"
6
-
7
- export type TaskTone = "success" | "warning" | "error" | "muted"
8
-
9
- export type TaskField = { label: string; value: string; tone?: TaskTone }
10
-
11
- export type TaskView = {
12
- fields: TaskField[]
13
- summary: string
14
- tone: TaskTone
15
- slug?: string
16
- root?: string
17
- stoppable?: boolean
18
- }
19
-
20
- export type TaskStore = { view: TaskView | null | undefined }
5
+ import { createEtaStats, estimateEta } from "./eta.ts"
6
+ import type { EtaStats } from "./eta.ts"
7
+ import { formatAge, formatDuration, formatEta } from "./format.ts"
8
+ import { logTexts, normalize, verbatimPrompt } from "./prompt-text.ts"
9
+ import type {
10
+ Metrics,
11
+ MetricEvent,
12
+ PauseScope,
13
+ Pipeline,
14
+ Status,
15
+ TaskStore,
16
+ TaskTone,
17
+ TaskView,
18
+ } from "./types.ts"
19
+
20
+ export type { TaskStore, TaskTone, TaskView, TaskField } from "./types.ts"
21
21
 
22
22
  export type MemoryStorage = {
23
23
  memory: <T>(key: string, options: { initial: T }) => [T, (mutate: (draft: T) => void) => void]
@@ -30,52 +30,33 @@ export type TaskWatcherOptions = {
30
30
  userTexts: (sessionID: string) => Promise<string[]>
31
31
  }
32
32
 
33
- type Attempt = {
34
- agent?: string
35
- stepIndex?: number
36
- attempt?: number
37
- startedAt?: string
38
- }
39
-
40
- type Status = {
41
- state?: string
42
- pipelineIndex?: number
43
- currentAgent?: string | null
44
- awaitingHumanGate?: boolean
45
- activeHumanGateEventId?: string | null
46
- activeAttempts?: Record<string, Attempt>
47
- lastCompletedAttempt?: { attemptId?: string; completedAt?: string }
48
- updatedAt?: string
49
- }
50
-
51
- type Pipeline = {
52
- steps?: { agent?: string | string[]; label?: string; parallel?: boolean }[]
53
- }
54
-
55
- type MetricEvent = {
56
- type?: string
57
- at?: string
58
- eventId?: string
59
- attemptId?: string
60
- agent?: string
61
- role?: string
62
- durationMs?: number
63
- stepIndex?: number
64
- }
65
-
66
- type Metrics = { events?: MetricEvent[] }
67
-
68
33
  type PromptEntry = { slug: string; texts: string[]; updatedAt: number }
69
34
 
70
35
  const TEAM_REL = path.join(".ai.local", "team")
71
36
  const TICK_MS = 1000
72
37
  const SYNC_MS = 5000
73
38
  const INDEX_MS = 30000
39
+ const ROOT_MS = 30000
40
+ const OFFLINE_MS = 60000
41
+ const SESSION_CACHE = 4
74
42
  const STALE_ATTEMPT_MS = 6 * 60 * 60 * 1000
75
43
  const STALE_GATE_MS = 24 * 60 * 60 * 1000
44
+ const STALE_P90_FACTOR = 2
76
45
  const MIN_PARTIAL = 24
77
46
  const TERMINAL = new Set(["completed"])
78
47
 
48
+ const DEBUG = process.env.OPENCODE_TASK_STATUS_DEBUG === "1"
49
+ const DEBUG_FILE = path.join(os.tmpdir(), "ai-rules-task-status-debug.log")
50
+
51
+ export const logTaskDebug = (line: string): void => {
52
+ if (!DEBUG) return
53
+ try {
54
+ fs.appendFileSync(DEBUG_FILE, `${new Date().toISOString()} ${line}\n`)
55
+ } catch {
56
+ // Debug output must never affect the sidebar.
57
+ }
58
+ }
59
+
79
60
  const MARKER: Record<string, string> = {
80
61
  in_progress: "●",
81
62
  awaiting_approval: "⏸",
@@ -125,6 +106,15 @@ const findTeamRoot = (start: string): string | null => {
125
106
  }
126
107
  }
127
108
 
109
+ let rootCache: { start: string; root: string | null; at: number } | undefined
110
+
111
+ const cachedTeamRoot = (start: string, now: number): string | null => {
112
+ if (rootCache && rootCache.start === start && now - rootCache.at < ROOT_MS) return rootCache.root
113
+ const root = findTeamRoot(start)
114
+ rootCache = { start, root, at: now }
115
+ return root
116
+ }
117
+
128
118
  const statusFile = (root: string, slug: string) => path.join(root, "tasks", slug, "status.json")
129
119
 
130
120
  const overlayDir = (root: string): string | null => {
@@ -132,45 +122,84 @@ const overlayDir = (root: string): string | null => {
132
122
  return path.basename(overlay) === ".ai.local" ? overlay : null
133
123
  }
134
124
 
135
- const pauseSentinel = (root: string): boolean => {
125
+ const isPresent = (file: string): boolean => {
126
+ try {
127
+ return fs.statSync(file).isFile()
128
+ } catch (error) {
129
+ return (error as { code?: string }).code !== "ENOENT"
130
+ }
131
+ }
132
+
133
+ const taskSentinel = (root: string, slug: string) => path.join(root, "tasks", slug, "STOP")
134
+
135
+ /**
136
+ * A task-scoped STOP wins over the overlay sentinel: the tracker writes the
137
+ * first, the operator pause writes the second.
138
+ */
139
+ export const pauseState = (root: string, slug?: string): PauseScope | null => {
140
+ if (slug && isPresent(taskSentinel(root, slug))) return "task"
136
141
  const overlay = overlayDir(root)
137
- if (!overlay) return false
138
- return ["STOP", "ESTOP"].some((name) => {
139
- try {
140
- return fs.statSync(path.join(overlay, name)).isFile()
141
- } catch (error) {
142
- return (error as { code?: string }).code !== "ENOENT"
143
- }
144
- })
142
+ if (!overlay) return null
143
+ return ["STOP", "ESTOP"].some((name) => isPresent(path.join(overlay, name))) ? "repo" : null
145
144
  }
146
145
 
147
- export const engagePause = (root: string): boolean => {
146
+ const pausePayload = (scope: PauseScope) =>
147
+ JSON.stringify({ reason: "soft stop requested from the task sidebar", scope })
148
+
149
+ /** The scope actually written, or `null` when no sentinel could be written. */
150
+ export const engagePause = (root: string, slug?: string): PauseScope | null => {
151
+ if (slug) {
152
+ try {
153
+ fs.writeFileSync(taskSentinel(root, slug), pausePayload("task"), "utf8")
154
+ return "task"
155
+ } catch {
156
+ // A task directory can disappear under a stale view; fall back to the repo sentinel.
157
+ }
158
+ }
148
159
  const overlay = overlayDir(root)
149
- if (!overlay) return false
160
+ if (!overlay) return null
150
161
  try {
151
- fs.writeFileSync(
152
- path.join(overlay, "STOP"),
153
- JSON.stringify({ reason: "soft stop requested from the task sidebar" }),
154
- "utf8",
155
- )
156
- return true
162
+ fs.writeFileSync(path.join(overlay, "STOP"), pausePayload("repo"), "utf8")
163
+ return "repo"
157
164
  } catch {
158
- return false
165
+ return null
159
166
  }
160
167
  }
161
168
 
162
- export const clearPause = (root: string): boolean => {
169
+ /**
170
+ * What a sidebar affordance or a resume word may lift: a task sentinel or a
171
+ * repo `STOP`. A repo `ESTOP` alone is emergency-stop semantics — it is
172
+ * displayed as a repo pause, but nothing automatic clears it.
173
+ */
174
+ export const resumableScope = (root: string, slug?: string): PauseScope | null => {
175
+ if (slug && isPresent(taskSentinel(root, slug))) return "task"
163
176
  const overlay = overlayDir(root)
164
- if (!overlay) return false
177
+ if (!overlay) return null
178
+ return isPresent(path.join(overlay, "STOP")) ? "repo" : null
179
+ }
180
+
181
+ /**
182
+ * Clear exactly the named scope's sentinel. A repo resume lifts the operator
183
+ * `STOP` only: an `ESTOP` is removed by hand alone, never by a resume word or
184
+ * a sidebar button.
185
+ */
186
+ export const clearPause = (root: string, slug: string | undefined, scope: PauseScope): boolean => {
165
187
  let cleared = false
166
- for (const name of ["STOP", "ESTOP"]) {
167
- const file = path.join(overlay, name)
188
+ const targets: string[] = []
189
+ if (scope === "task") {
190
+ if (!slug) return false
191
+ targets.push(taskSentinel(root, slug))
192
+ } else {
193
+ const overlay = overlayDir(root)
194
+ if (overlay) targets.push(path.join(overlay, "STOP"))
195
+ }
196
+ for (const file of targets) {
168
197
  if (!fs.existsSync(file)) continue
169
198
  try {
170
199
  fs.rmSync(file, { force: true })
171
200
  cleared = true
172
201
  } catch {
173
- // leave an undeletable sentinel for the hook to report
202
+ // Leave an undeletable sentinel for the hook to report.
174
203
  }
175
204
  }
176
205
  return cleared
@@ -188,22 +217,8 @@ const toMs = (value?: string): number | undefined => {
188
217
  return Number.isFinite(parsed) ? parsed : undefined
189
218
  }
190
219
 
191
- const formatDuration = (ms: number): string => {
192
- const seconds = Math.max(0, Math.floor(ms / 1000))
193
- if (seconds < 60) return `${seconds}s`
194
- const minutes = Math.floor(seconds / 60)
195
- if (minutes < 60) return `${minutes}m`
196
- const hours = Math.floor(minutes / 60)
197
- if (hours < 48) return `${hours}h ${String(minutes % 60).padStart(2, "0")}m`
198
- return `${Math.floor(hours / 24)}d ${hours % 24}h`
199
- }
200
-
201
- const formatAge = (ms: number): string => `${formatDuration(ms)} ago`
202
-
203
- const formatEta = (eta: { p50Ms: number; p90Ms: number }): string =>
204
- eta.p90Ms > eta.p50Ms * 1.5
205
- ? `~${formatDuration(eta.p50Ms)} · p90 ${formatDuration(eta.p90Ms)}`
206
- : `~${formatDuration(eta.p50Ms)}`
220
+ const truncate = (value: string, max: number): string =>
221
+ value.length > max ? `${value.slice(0, max - 1)}…` : value
207
222
 
208
223
  const progressBar = (value: number, total: number, width = 8): string => {
209
224
  if (total <= 0) return ""
@@ -211,35 +226,6 @@ const progressBar = (value: number, total: number, width = 8): string => {
211
226
  return `${"█".repeat(filled)}${"░".repeat(width - filled)}`
212
227
  }
213
228
 
214
- const truncate = (value: string, max: number): string =>
215
- value.length > max ? `${value.slice(0, max - 1)}…` : value
216
-
217
- const normalize = (text: string): string => text.toLowerCase().replace(/\s+/g, " ").trim()
218
-
219
- const stripFrontmatter = (text: string): string =>
220
- text.startsWith("---") ? text.replace(/^---[\s\S]*?\n---\s*/, "") : text
221
-
222
- const promptText = (raw: string): string => {
223
- const lines = stripFrontmatter(raw).split("\n")
224
- const start = lines.findIndex((line) => /^#+\s*Verbatim prompt\s*$/i.test(line.trim()))
225
- const slice = start >= 0 ? lines.slice(start + 1) : lines
226
- const kept: string[] = []
227
- for (const line of slice) {
228
- if (/^#+\s/.test(line)) {
229
- if (start >= 0) break
230
- continue
231
- }
232
- const trimmed = line.trim()
233
- const meta = /^(language|slug|created|source|command|capturedAt):/i.test(trimmed)
234
- if (trimmed === "" || trimmed.startsWith("```") || meta) continue
235
- kept.push(trimmed)
236
- }
237
- return kept.join("\n")
238
- }
239
-
240
- const logTexts = (raw: string): string[] =>
241
- [...raw.matchAll(/```(?:text)?\n([\s\S]*?)```/g)].map((match) => match[1])
242
-
243
229
  const buildPromptIndex = (root: string): PromptEntry[] => {
244
230
  const dir = path.join(root, "tasks")
245
231
  let entries: Dirent[]
@@ -260,7 +246,7 @@ const buildPromptIndex = (root: string): PromptEntry[] => {
260
246
  const stat = fs.statSync(filePath)
261
247
  updatedAt = Math.max(updatedAt, stat.mtimeMs)
262
248
  const raw = fs.readFileSync(filePath, "utf8")
263
- const parts = file === "prompt.md" ? [promptText(raw)] : logTexts(raw)
249
+ const parts = file === "prompt.md" ? [verbatimPrompt(raw)] : logTexts(raw)
264
250
  for (const part of parts) {
265
251
  const text = normalize(part)
266
252
  if (text.length > 0) texts.push(text)
@@ -277,35 +263,53 @@ const buildPromptIndex = (root: string): PromptEntry[] => {
277
263
  return index
278
264
  }
279
265
 
280
- const matches = (message: string, prompt: string): boolean => {
281
- if (message === prompt) return true
282
- if (prompt.length >= MIN_PARTIAL && message.includes(prompt)) return true
283
- if (message.length >= MIN_PARTIAL && prompt.includes(message)) return true
284
- return false
266
+ /**
267
+ * Tier-monotonic: a stronger tier always outscores a weaker one, so a longer
268
+ * substring can never outrank a shorter match from a better tier, and an
269
+ * exact match (handled outright in `computeMatch`) always wins.
270
+ */
271
+ const scoreFor = (message: string, prompt: string): number => {
272
+ if (message === prompt) return 3000 + prompt.length
273
+ if (prompt.length >= MIN_PARTIAL && message.includes(prompt)) {
274
+ return 2000 + Math.min(prompt.length, 999)
275
+ }
276
+ if (message.length >= MIN_PARTIAL && prompt.includes(message)) {
277
+ return 1000 + Math.min(message.length, 999)
278
+ }
279
+ return 0
285
280
  }
286
281
 
287
- const matchTask = (index: PromptEntry[], messages: string[]): string | undefined => {
288
- const normalized = messages.map(normalize).filter(Boolean)
289
- if (normalized.length === 0) return undefined
282
+ const computeMatch = (index: PromptEntry[], messages: string[]): string | undefined => {
283
+ if (messages.length === 0) return undefined
290
284
 
291
285
  let continued: string | undefined
292
- for (const message of normalized) {
286
+ for (const message of messages) {
293
287
  const match = /(?:^|\s)\/task-continue\s+([a-z0-9][a-z0-9-]*)/i.exec(message)
294
288
  if (match) continued = match[1]
295
289
  }
296
290
  if (continued) return continued
297
291
 
292
+ // An exact prompt match wins outright whatever the lengths involved; the
293
+ // substring tiers only rank the remaining candidates. Newest exact wins.
294
+ let exact: PromptEntry | undefined
295
+ for (const entry of index) {
296
+ if (!entry.texts.some((prompt) => messages.includes(prompt))) continue
297
+ if (!exact || entry.updatedAt > exact.updatedAt) exact = entry
298
+ }
299
+ if (exact) return exact.slug
300
+
298
301
  let best: PromptEntry | undefined
299
302
  let bestScore = 0
300
303
  for (const entry of index) {
301
304
  let score = 0
302
- for (const message of normalized) {
305
+ for (const message of messages) {
303
306
  for (const prompt of entry.texts) {
304
- if (matches(message, prompt)) score = Math.max(score, prompt.length)
307
+ score = Math.max(score, scoreFor(message, prompt))
305
308
  }
306
309
  }
307
310
  if (score === 0) continue
308
- if (!best || entry.updatedAt > best.updatedAt || (entry.updatedAt === best.updatedAt && score > bestScore)) {
311
+ // Recency breaks ties inside a tier; `scoreFor` keeps the tiers monotonic.
312
+ if (!best || score > bestScore || (score === bestScore && entry.updatedAt > best.updatedAt)) {
309
313
  best = entry
310
314
  bestScore = score
311
315
  }
@@ -313,25 +317,43 @@ const matchTask = (index: PromptEntry[], messages: string[]): string | undefined
313
317
  return best?.slug
314
318
  }
315
319
 
316
- const roleForAgent = (agent: string): string => {
317
- if (/analyst|architect|router|migration/.test(agent)) return "planning"
318
- if (/verifier/.test(agent)) return "validation"
319
- if (/reviewer|auditor/.test(agent)) return "review"
320
- if (/test|qa/.test(agent)) return "testing"
321
- if (/writer/.test(agent)) return "docs"
322
- return "implementation"
320
+ const matchCache = new WeakMap<PromptEntry[], { key: string; slug: string | undefined }>()
321
+
322
+ /**
323
+ * The sidebar re-renders every second, so matching is memoized on the index
324
+ * generation and the message fingerprint; a rebuilt index (every 30s) drops it.
325
+ */
326
+ const matchTask = (index: PromptEntry[], messages: string[]): string | undefined => {
327
+ const key = `${messages.length}:${messages[0] ?? ""}:${messages[messages.length - 1] ?? ""}`
328
+ const hit = matchCache.get(index)
329
+ if (hit && hit.key === key) return hit.slug
330
+ const slug = computeMatch(index, messages)
331
+ matchCache.set(index, { key, slug })
332
+ return slug
323
333
  }
324
334
 
335
+ const ROLE_RULES: [RegExp, string][] = [
336
+ [/analyst|architect|router|migration|openspec/, "planning"],
337
+ [/verifier/, "validation"],
338
+ [/reviewer|auditor/, "review"],
339
+ [/test|qa|playwright/, "testing"],
340
+ [/writer/, "docs"],
341
+ [/developer|debugger|investigator|analyzer/, "implementation"],
342
+ ]
343
+
344
+ const roleForAgent = (agent: string): string | undefined =>
345
+ ROLE_RULES.find(([pattern]) => pattern.test(agent))?.[1]
346
+
325
347
  const actorOf = (
326
348
  events: MetricEvent[],
327
349
  attemptId: string | undefined,
328
350
  fallbackAgent: string | undefined,
329
- ): { agent: string | undefined; role: string | null } => {
351
+ ): { agent: string | undefined; role: string | undefined } => {
330
352
  const event = attemptId
331
353
  ? events.findLast((item) => item.type === "attempt_started" && item.attemptId === attemptId)
332
354
  : undefined
333
355
  const agent = event?.agent ?? fallbackAgent
334
- return { agent, role: event?.role ?? (agent ? roleForAgent(agent) : null) }
356
+ return { agent, role: event?.role ?? (agent ? roleForAgent(agent) : undefined) }
335
357
  }
336
358
 
337
359
  // Agent-written metrics can carry a `task_started` in the future; a future clock would freeze elapsed at 0s.
@@ -358,6 +380,7 @@ const buildTaskView = (
358
380
  status: Status,
359
381
  now: number,
360
382
  etaStats?: EtaStats,
383
+ offline = false,
361
384
  ): TaskView => {
362
385
  const taskDir = path.join(root, "tasks", slug)
363
386
  const pipeline = readJson<Pipeline>(path.join(taskDir, "pipeline.json"))
@@ -365,8 +388,10 @@ const buildTaskView = (
365
388
 
366
389
  const state = status.state ?? "in_progress"
367
390
  const done = TERMINAL.has(state)
368
- const sentinel = !done && pauseSentinel(root)
369
- const paused = state === "paused" || sentinel
391
+ const pauseScope = done ? null : pauseState(root, slug)
392
+ const paused = state === "paused" || pauseScope !== null
393
+ const blocked = state === "blocked"
394
+ const awaitingReceipt = state === "awaiting_artifact_receipt"
370
395
 
371
396
  const attempts = Object.entries(status.activeAttempts ?? {})
372
397
  .map(([id, attempt]) => ({ id, ...attempt }))
@@ -389,12 +414,21 @@ const buildTaskView = (
389
414
  const elapsed = startedAt === undefined ? undefined : Math.max(0, finishedAt - startedAt)
390
415
 
391
416
  const freshness = currentStart ?? gateStart ?? updatedAt
392
- const stale = !done && !paused && now - freshness > (status.awaitingHumanGate ? STALE_GATE_MS : STALE_ATTEMPT_MS)
417
+ // A long real step must not be called stale: the agent's own p90 raises the floor.
418
+ const agentP90 = current?.agent ? etaStats?.byAgent.get(current.agent)?.p90Ms : undefined
419
+ const staleAfter = Math.max(
420
+ status.awaitingHumanGate ? STALE_GATE_MS : STALE_ATTEMPT_MS,
421
+ (agentP90 ?? 0) * STALE_P90_FACTOR,
422
+ )
423
+ const stale = !done && !paused && now - freshness > staleAfter
424
+
425
+ const plannedStep = status.pipelineIndex === undefined ? undefined : pipeline?.steps?.[status.pipelineIndex]
426
+ const plannedAgent = Array.isArray(plannedStep?.agent) ? plannedStep?.agent[0] : plannedStep?.agent
393
427
 
394
428
  const actor = actorOf(
395
429
  events,
396
430
  current?.id ?? status.lastCompletedAttempt?.attemptId,
397
- current?.agent ?? status.currentAgent ?? undefined,
431
+ current?.agent ?? status.currentAgent ?? plannedAgent,
398
432
  )
399
433
  const totalSteps = pipeline?.steps?.length
400
434
  const stepNumber = done
@@ -407,10 +441,10 @@ const buildTaskView = (
407
441
 
408
442
  const staleFor = now - freshness
409
443
 
410
- const statusLine =
444
+ const baseState =
411
445
  state === "paused"
412
446
  ? `⏸ paused${elapsed === undefined ? "" : ` · ${formatDuration(elapsed)}`}`
413
- : sentinel
447
+ : pauseScope !== null
414
448
  ? "⏸ stopping · in-flight attempt finishes"
415
449
  : stale
416
450
  ? `◌ stale · ${formatAge(staleFor)}`
@@ -421,6 +455,8 @@ const buildTaskView = (
421
455
  .filter(Boolean)
422
456
  .join(" · ")
423
457
 
458
+ const statusLine = offline ? `${baseState} · offline` : baseState
459
+
424
460
  const agents = attempts.map((attempt) => attempt.agent).filter((agent): agent is string => Boolean(agent))
425
461
  const agentText = agents.length > 1 ? `${agents[0]} +${agents.length - 1}` : agents[0] ?? actor.agent
426
462
 
@@ -442,20 +478,20 @@ const buildTaskView = (
442
478
  ]
443
479
  .filter(Boolean)
444
480
  .join(" · ")
481
+ } else if (state === "in_progress") {
482
+ stepLine = `${stepNumber ? `${stepNumber}/${totalSteps ?? "?"}` : "?"} · no attempt started`
445
483
  } else {
446
484
  stepLine = `updated ${formatAge(now - updatedAt)}`
447
485
  }
448
486
 
449
- const tone = paused ? "warning" : toneFor(state, stale)
450
- const eta =
451
- etaStats && !done && !paused && !stale && !status.awaitingHumanGate
452
- ? estimateEta(pipeline?.steps ?? [], status, events, etaStats, now)
453
- : null
487
+ const tone = paused ? "warning" : blocked ? "error" : toneFor(state, stale)
488
+ const showEta = !done && !paused && !blocked && !awaitingReceipt && !status.awaitingHumanGate && (totalSteps ?? 0) > 0
489
+ const eta = showEta && etaStats ? estimateEta(pipeline?.steps ?? [], status, events, etaStats, now) : null
454
490
  const progressLabel = !done && totalSteps && stepNumber ? `${stepNumber}/${totalSteps}` : null
455
491
  const summary =
456
492
  state === "paused"
457
493
  ? ["paused", elapsed === undefined ? null : formatDuration(elapsed)].filter(Boolean).join(" · ")
458
- : sentinel
494
+ : pauseScope !== null
459
495
  ? "stopping"
460
496
  : stale
461
497
  ? `stale · ${formatAge(staleFor)}`
@@ -466,17 +502,22 @@ const buildTaskView = (
466
502
  return {
467
503
  fields: [
468
504
  { label: "task", value: truncate(slug, 34) },
469
- { label: "state", value: statusLine, tone },
505
+ { label: "state", value: statusLine, tone: offline ? "muted" : tone },
470
506
  { label: "role", value: actor.role ?? "—" },
471
507
  { label: "agent", value: agentText ?? "—" },
472
508
  { label: "step", value: stepLine },
473
- ...(eta ? [{ label: "eta", value: formatEta(eta) }] : []),
509
+ ...(showEta
510
+ ? [{ label: "eta", value: eta ? formatEta(eta) : "—", tone: eta ? undefined : ("muted" as const) }]
511
+ : []),
474
512
  ],
475
- summary,
476
- tone,
513
+ summary: offline ? `offline · ${summary}` : summary,
514
+ tone: offline ? "muted" : tone,
477
515
  slug,
478
516
  root,
479
- stoppable: !done && !paused,
517
+ stoppable: !done && !paused && !blocked && !status.awaitingHumanGate && state !== "awaiting_approval",
518
+ resumable: resumableScope(root, slug) !== null,
519
+ pausedScope: pauseScope ?? undefined,
520
+ offline,
480
521
  }
481
522
  }
482
523
 
@@ -519,32 +560,75 @@ const buildSessionView = (
519
560
  sessionID: string,
520
561
  texts: string[],
521
562
  now: number,
522
- options: TaskWatcherOptions,
563
+ options: Pick<TaskWatcherOptions, "sessionTitle">,
523
564
  index: PromptEntry[],
524
565
  etaStats?: EtaStats,
566
+ offline = false,
567
+ normalized?: string[],
525
568
  ): TaskView => {
526
- const slug = matchTask(index, texts)
569
+ const slug = matchTask(index, normalized ?? texts.map(normalize).filter(Boolean))
527
570
  if (slug && fs.existsSync(path.join(root, "tasks", slug))) {
528
571
  const status = readJson<Status>(statusFile(root, slug))
529
- return status ? buildTaskView(root, slug, status, now, etaStats) : buildNoteView(root, slug, now)
572
+ return status ? buildTaskView(root, slug, status, now, etaStats, offline) : buildNoteView(root, slug, now)
530
573
  }
531
574
  return buildPromptView(options.sessionTitle(sessionID) ?? "", texts)
532
575
  }
533
576
 
577
+ export const resolveTaskView = (
578
+ root: string,
579
+ sessionID: string,
580
+ texts: string[],
581
+ now: number,
582
+ sessionTitle: (sessionID: string) => string | undefined,
583
+ offline = false,
584
+ ): TaskView =>
585
+ buildSessionView(
586
+ root,
587
+ sessionID,
588
+ texts,
589
+ now,
590
+ { sessionTitle },
591
+ buildPromptIndex(root),
592
+ createEtaStats(root, readJson),
593
+ offline,
594
+ )
595
+
596
+ type SessionState = {
597
+ id: string
598
+ texts: string[]
599
+ textsNorm: string[]
600
+ fetchedAt: number
601
+ loading: boolean
602
+ errorAt?: number
603
+ resumeFor?: string
604
+ }
605
+
534
606
  export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOptions) => {
535
607
  const [state, update] = storage.memory<TaskStore>("view", { initial: { view: undefined } })
536
608
  let index: PromptEntry[] = []
537
609
  let indexAt = 0
538
610
  let etaStats: EtaStats | undefined
539
611
  let etaAt = 0
540
- let session: { id: string; texts: string[]; fetchedAt: number; loading: boolean; resumeFor?: string } | undefined
541
-
542
- const sessionState = (id: string) => {
543
- if (!session || session.id !== id) session = { id, texts: [], fetchedAt: 0, loading: false }
544
- return session
612
+ const sessions = new Map<string, SessionState>()
613
+
614
+ const sessionState = (id: string): SessionState => {
615
+ const existing = sessions.get(id)
616
+ if (existing) {
617
+ sessions.delete(id)
618
+ sessions.set(id, existing)
619
+ return existing
620
+ }
621
+ const created: SessionState = { id, texts: [], textsNorm: [], fetchedAt: 0, loading: false }
622
+ sessions.set(id, created)
623
+ while (sessions.size > SESSION_CACHE) {
624
+ const oldest = sessions.keys().next().value
625
+ if (oldest === undefined) break
626
+ sessions.delete(oldest)
627
+ }
628
+ return created
545
629
  }
546
630
 
547
- const syncSession = (root: string, id: string) => {
631
+ const syncSession = (id: string) => {
548
632
  const current = sessionState(id)
549
633
  if (current.loading || Date.now() - current.fetchedAt < SYNC_MS) return
550
634
  current.loading = true
@@ -552,32 +636,43 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
552
636
  .userTexts(id)
553
637
  .then((texts) => {
554
638
  current.texts = texts
639
+ current.textsNorm = texts.map(normalize).filter(Boolean)
555
640
  current.fetchedAt = Date.now()
556
- const latest = texts.at(-1)?.trim() ?? ""
557
- const key = `${texts.length}:${latest}`
558
- if (latest && current.resumeFor !== key && resumeIntent(latest)) {
559
- current.resumeFor = key
560
- if (pauseSentinel(root)) clearPause(root)
561
- }
641
+ current.errorAt = undefined
562
642
  })
563
- .catch(() => {
643
+ .catch((error: unknown) => {
644
+ current.errorAt = Date.now()
564
645
  current.fetchedAt = Date.now() - SYNC_MS + 1000
646
+ logTaskDebug(`message.list failed for ${id}: ${error instanceof Error ? error.message : String(error)}`)
565
647
  })
566
648
  .finally(() => {
567
649
  current.loading = false
568
650
  })
569
651
  }
570
652
 
653
+ const resume = (root: string, current: SessionState, slug: string | undefined) => {
654
+ if (!slug) return
655
+ const latest = current.texts.at(-1)?.trim() ?? ""
656
+ const key = `${current.texts.length}:${latest}`
657
+ if (!latest || current.resumeFor === key || !resumeIntent(latest)) return
658
+ current.resumeFor = key
659
+ const scope = resumableScope(root, slug)
660
+ if (scope && clearPause(root, slug, scope)) {
661
+ logTaskDebug(`resume intent cleared ${scope} pause for ${slug}`)
662
+ }
663
+ }
664
+
571
665
  const refresh = () => {
572
666
  const start = options.directory()
573
- const root = start ? findTeamRoot(start) : null
667
+ const now = Date.now()
668
+ const root = start ? cachedTeamRoot(start, now) : null
574
669
  if (!root) {
670
+ logTaskDebug(`no team root from ${start ?? "unknown directory"}`)
575
671
  update((draft) => {
576
672
  draft.view = undefined
577
673
  })
578
674
  return
579
675
  }
580
- const now = Date.now()
581
676
  if (now - indexAt > INDEX_MS) {
582
677
  index = buildPromptIndex(root)
583
678
  indexAt = now
@@ -588,16 +683,23 @@ export const createTaskWatcher = (storage: MemoryStorage, options: TaskWatcherOp
588
683
  }
589
684
  const sessionID = options.sessionID()
590
685
  if (!sessionID) {
686
+ logTaskDebug("no session id")
591
687
  update((draft) => {
592
688
  draft.view = undefined
593
689
  })
594
690
  return
595
691
  }
596
692
  const current = sessionState(sessionID)
597
- syncSession(root, sessionID)
693
+ syncSession(sessionID)
694
+ const offline = current.errorAt !== undefined && now - current.errorAt < OFFLINE_MS
695
+ const view = buildSessionView(root, sessionID, current.texts, now, options, index, etaStats, offline, current.textsNorm)
696
+ resume(root, current, view.slug)
598
697
  update((draft) => {
599
- draft.view = buildSessionView(root, sessionID, current.texts, now, options, index, etaStats)
698
+ draft.view = view
600
699
  })
700
+ logTaskDebug(
701
+ `session=${sessionID} messages=${current.texts.length} matched=${view.slug ?? "-"} view=${view.summary}`,
702
+ )
601
703
  }
602
704
 
603
705
  refresh()