@bonesofspring/ai-rules 0.2.65 → 0.2.66

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