visionclaw 0.1.219-dev.codex-issue-2805-worker-runtime.2 → 0.1.219-dev.codex-fix-2941-activity-foreground.1

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 (313) hide show
  1. package/dist/agent/api-proxy.d.ts +16 -0
  2. package/dist/agent/api-proxy.d.ts.map +1 -1
  3. package/dist/agent/api-proxy.js +8 -9
  4. package/dist/agent/api-proxy.js.map +1 -1
  5. package/dist/agent/browser-launcher.d.ts +0 -3
  6. package/dist/agent/browser-launcher.d.ts.map +1 -1
  7. package/dist/agent/browser-launcher.js +43 -101
  8. package/dist/agent/browser-launcher.js.map +1 -1
  9. package/dist/agent/coding-conventions.d.ts +3 -2
  10. package/dist/agent/coding-conventions.d.ts.map +1 -1
  11. package/dist/agent/coding-conventions.js +8 -7
  12. package/dist/agent/coding-conventions.js.map +1 -1
  13. package/dist/agent/command-handlers.d.ts.map +1 -1
  14. package/dist/agent/command-handlers.js +16 -4
  15. package/dist/agent/command-handlers.js.map +1 -1
  16. package/dist/agent/context-action-restart-fallback.d.ts.map +1 -1
  17. package/dist/agent/context-action-restart-fallback.js +3 -9
  18. package/dist/agent/context-action-restart-fallback.js.map +1 -1
  19. package/dist/agent/context-refresh.d.ts.map +1 -1
  20. package/dist/agent/context-refresh.js +7 -0
  21. package/dist/agent/context-refresh.js.map +1 -1
  22. package/dist/agent/context.d.ts.map +1 -1
  23. package/dist/agent/context.js +8 -6
  24. package/dist/agent/context.js.map +1 -1
  25. package/dist/agent/engine-fallback.d.ts +35 -0
  26. package/dist/agent/engine-fallback.d.ts.map +1 -1
  27. package/dist/agent/engine-fallback.js +3 -4
  28. package/dist/agent/engine-fallback.js.map +1 -1
  29. package/dist/agent/engines/browser-tool-policy.d.ts +1 -12
  30. package/dist/agent/engines/browser-tool-policy.d.ts.map +1 -1
  31. package/dist/agent/engines/browser-tool-policy.js +2 -17
  32. package/dist/agent/engines/browser-tool-policy.js.map +1 -1
  33. package/dist/agent/engines/claude/session.d.ts +0 -1
  34. package/dist/agent/engines/claude/session.d.ts.map +1 -1
  35. package/dist/agent/engines/claude/session.js +36 -21
  36. package/dist/agent/engines/claude/session.js.map +1 -1
  37. package/dist/agent/engines/pi/tools.d.ts.map +1 -1
  38. package/dist/agent/engines/pi/tools.js +10 -2
  39. package/dist/agent/engines/pi/tools.js.map +1 -1
  40. package/dist/agent/engines/pi-coding/session.d.ts +0 -3
  41. package/dist/agent/engines/pi-coding/session.d.ts.map +1 -1
  42. package/dist/agent/engines/pi-coding/session.js +22 -19
  43. package/dist/agent/engines/pi-coding/session.js.map +1 -1
  44. package/dist/agent/engines/session-types.d.ts +0 -6
  45. package/dist/agent/engines/session-types.d.ts.map +1 -1
  46. package/dist/agent/external-context/runtime.d.ts.map +1 -1
  47. package/dist/agent/external-context/runtime.js +14 -15
  48. package/dist/agent/external-context/runtime.js.map +1 -1
  49. package/dist/agent/fast-responder.d.ts +20 -4
  50. package/dist/agent/fast-responder.d.ts.map +1 -1
  51. package/dist/agent/fast-responder.js +39 -9
  52. package/dist/agent/fast-responder.js.map +1 -1
  53. package/dist/agent/interrupt-handler.d.ts +18 -4
  54. package/dist/agent/interrupt-handler.d.ts.map +1 -1
  55. package/dist/agent/interrupt-handler.js +284 -49
  56. package/dist/agent/interrupt-handler.js.map +1 -1
  57. package/dist/agent/lab-run-system-prompt.d.ts.map +1 -1
  58. package/dist/agent/lab-run-system-prompt.js +0 -3
  59. package/dist/agent/lab-run-system-prompt.js.map +1 -1
  60. package/dist/agent/lifecycle-trace.d.ts.map +1 -1
  61. package/dist/agent/lifecycle-trace.js +5 -6
  62. package/dist/agent/lifecycle-trace.js.map +1 -1
  63. package/dist/agent/loop.d.ts +1 -4
  64. package/dist/agent/loop.d.ts.map +1 -1
  65. package/dist/agent/loop.js +129 -105
  66. package/dist/agent/loop.js.map +1 -1
  67. package/dist/agent/memory-protocol.d.ts +2 -2
  68. package/dist/agent/memory-protocol.d.ts.map +1 -1
  69. package/dist/agent/memory-protocol.js +15 -3
  70. package/dist/agent/memory-protocol.js.map +1 -1
  71. package/dist/agent/memory-store.d.ts.map +1 -1
  72. package/dist/agent/memory-store.js +1 -11
  73. package/dist/agent/memory-store.js.map +1 -1
  74. package/dist/agent/model-provider.d.ts +0 -2
  75. package/dist/agent/model-provider.d.ts.map +1 -1
  76. package/dist/agent/model-provider.js +25 -31
  77. package/dist/agent/model-provider.js.map +1 -1
  78. package/dist/agent/product-identity.d.ts +4 -5
  79. package/dist/agent/product-identity.d.ts.map +1 -1
  80. package/dist/agent/product-identity.js +6 -7
  81. package/dist/agent/product-identity.js.map +1 -1
  82. package/dist/agent/public-activity.d.ts +1 -1
  83. package/dist/agent/public-activity.d.ts.map +1 -1
  84. package/dist/agent/public-activity.js.map +1 -1
  85. package/dist/agent/reply-watchdog.d.ts +3 -5
  86. package/dist/agent/reply-watchdog.d.ts.map +1 -1
  87. package/dist/agent/reply-watchdog.js +4 -6
  88. package/dist/agent/reply-watchdog.js.map +1 -1
  89. package/dist/agent/session-manager.d.ts +0 -5
  90. package/dist/agent/session-manager.d.ts.map +1 -1
  91. package/dist/agent/session-manager.js +0 -7
  92. package/dist/agent/session-manager.js.map +1 -1
  93. package/dist/agent/state.d.ts +0 -7
  94. package/dist/agent/state.d.ts.map +1 -1
  95. package/dist/agent/state.js +11 -21
  96. package/dist/agent/state.js.map +1 -1
  97. package/dist/agent/stream-handler.d.ts.map +1 -1
  98. package/dist/agent/stream-handler.js +17 -0
  99. package/dist/agent/stream-handler.js.map +1 -1
  100. package/dist/agent/system-prompt.d.ts.map +1 -1
  101. package/dist/agent/system-prompt.js +6 -10
  102. package/dist/agent/system-prompt.js.map +1 -1
  103. package/dist/agent/transcript/transcript-indexer.d.ts +28 -0
  104. package/dist/agent/transcript/transcript-indexer.d.ts.map +1 -1
  105. package/dist/agent/transcript/transcript-indexer.js +57 -58
  106. package/dist/agent/transcript/transcript-indexer.js.map +1 -1
  107. package/dist/agent/usage/usage-report-queue.d.ts.map +1 -1
  108. package/dist/agent/usage/usage-report-queue.js +52 -53
  109. package/dist/agent/usage/usage-report-queue.js.map +1 -1
  110. package/dist/agent/wake-cycle-runner.d.ts +8 -7
  111. package/dist/agent/wake-cycle-runner.d.ts.map +1 -1
  112. package/dist/agent/wake-cycle-runner.js +66 -105
  113. package/dist/agent/wake-cycle-runner.js.map +1 -1
  114. package/dist/builtin-skills/owner-manual/SKILL.md +2 -2
  115. package/dist/calendar/occurrence-ownership.d.ts.map +1 -1
  116. package/dist/calendar/occurrence-ownership.js +5 -6
  117. package/dist/calendar/occurrence-ownership.js.map +1 -1
  118. package/dist/calendar/scheduler.d.ts.map +1 -1
  119. package/dist/calendar/scheduler.js +3 -4
  120. package/dist/calendar/scheduler.js.map +1 -1
  121. package/dist/channels/interface.d.ts +2 -8
  122. package/dist/channels/interface.d.ts.map +1 -1
  123. package/dist/channels/interface.js +1 -8
  124. package/dist/channels/interface.js.map +1 -1
  125. package/dist/channels/manager.d.ts.map +1 -1
  126. package/dist/channels/manager.js +0 -2
  127. package/dist/channels/manager.js.map +1 -1
  128. package/dist/channels/qq-status.d.ts.map +1 -1
  129. package/dist/channels/qq-status.js +1 -0
  130. package/dist/channels/qq-status.js.map +1 -1
  131. package/dist/channels/queue.d.ts.map +1 -1
  132. package/dist/channels/queue.js +0 -8
  133. package/dist/channels/queue.js.map +1 -1
  134. package/dist/channels/telegram-status.d.ts.map +1 -1
  135. package/dist/channels/telegram-status.js +2 -0
  136. package/dist/channels/telegram-status.js.map +1 -1
  137. package/dist/channels/tui.d.ts +2 -2
  138. package/dist/channels/tui.d.ts.map +1 -1
  139. package/dist/channels/tui.js +2 -7
  140. package/dist/channels/tui.js.map +1 -1
  141. package/dist/config/index.d.ts.map +1 -1
  142. package/dist/config/index.js +15 -16
  143. package/dist/config/index.js.map +1 -1
  144. package/dist/config/types.d.ts +8 -16
  145. package/dist/config/types.d.ts.map +1 -1
  146. package/dist/config/types.js +24 -13
  147. package/dist/config/types.js.map +1 -1
  148. package/dist/email/email-route-store.d.ts.map +1 -1
  149. package/dist/email/email-route-store.js +5 -6
  150. package/dist/email/email-route-store.js.map +1 -1
  151. package/dist/i18n/messages.d.ts +0 -12
  152. package/dist/i18n/messages.d.ts.map +1 -1
  153. package/dist/i18n/messages.js +9 -21
  154. package/dist/i18n/messages.js.map +1 -1
  155. package/dist/logger.d.ts +0 -2
  156. package/dist/logger.d.ts.map +1 -1
  157. package/dist/logger.js +1 -19
  158. package/dist/logger.js.map +1 -1
  159. package/dist/threads/active-threads-store.d.ts.map +1 -1
  160. package/dist/threads/active-threads-store.js +27 -8
  161. package/dist/threads/active-threads-store.js.map +1 -1
  162. package/dist/threads/execution-host.d.ts.map +1 -1
  163. package/dist/threads/execution-host.js +0 -1
  164. package/dist/threads/execution-host.js.map +1 -1
  165. package/dist/threads/execution-scheduler.d.ts +0 -4
  166. package/dist/threads/execution-scheduler.d.ts.map +1 -1
  167. package/dist/threads/execution-scheduler.js +2 -38
  168. package/dist/threads/execution-scheduler.js.map +1 -1
  169. package/dist/threads/execution-store.d.ts +5 -20
  170. package/dist/threads/execution-store.d.ts.map +1 -1
  171. package/dist/threads/execution-store.js +8 -45
  172. package/dist/threads/execution-store.js.map +1 -1
  173. package/dist/threads/foreground-task.d.ts +6 -10
  174. package/dist/threads/foreground-task.d.ts.map +1 -1
  175. package/dist/threads/foreground-task.js +26 -34
  176. package/dist/threads/foreground-task.js.map +1 -1
  177. package/dist/threads/foreman-client.d.ts.map +1 -1
  178. package/dist/threads/foreman-client.js +1 -3
  179. package/dist/threads/foreman-client.js.map +1 -1
  180. package/dist/threads/foreman-execution.d.ts +12 -12
  181. package/dist/threads/foreman-execution.d.ts.map +1 -1
  182. package/dist/threads/foreman-execution.js +19 -30
  183. package/dist/threads/foreman-execution.js.map +1 -1
  184. package/dist/threads/foreman-host.d.ts +2 -17
  185. package/dist/threads/foreman-host.d.ts.map +1 -1
  186. package/dist/threads/foreman-host.js +59 -423
  187. package/dist/threads/foreman-host.js.map +1 -1
  188. package/dist/threads/foreman-protocol.d.ts +12 -109
  189. package/dist/threads/foreman-protocol.d.ts.map +1 -1
  190. package/dist/threads/foreman-protocol.js +15 -37
  191. package/dist/threads/foreman-protocol.js.map +1 -1
  192. package/dist/threads/foreman-store.d.ts +9 -36
  193. package/dist/threads/foreman-store.d.ts.map +1 -1
  194. package/dist/threads/foreman-store.js +19 -63
  195. package/dist/threads/foreman-store.js.map +1 -1
  196. package/dist/threads/generic-execution.d.ts +2 -2
  197. package/dist/threads/generic-execution.d.ts.map +1 -1
  198. package/dist/threads/generic-execution.js +6 -9
  199. package/dist/threads/generic-execution.js.map +1 -1
  200. package/dist/threads/ipc.d.ts +0 -3
  201. package/dist/threads/ipc.d.ts.map +1 -1
  202. package/dist/threads/ipc.js.map +1 -1
  203. package/dist/threads/relay-adapter.d.ts +2 -0
  204. package/dist/threads/relay-adapter.d.ts.map +1 -1
  205. package/dist/threads/relay-adapter.js +7 -1
  206. package/dist/threads/relay-adapter.js.map +1 -1
  207. package/dist/threads/supervisor.d.ts +51 -21
  208. package/dist/threads/supervisor.d.ts.map +1 -1
  209. package/dist/threads/supervisor.js +449 -160
  210. package/dist/threads/supervisor.js.map +1 -1
  211. package/dist/threads/task-contracts.d.ts +194 -0
  212. package/dist/threads/task-contracts.d.ts.map +1 -0
  213. package/dist/threads/task-contracts.js +82 -0
  214. package/dist/threads/task-contracts.js.map +1 -0
  215. package/dist/threads/task-sidecar.d.ts +145 -0
  216. package/dist/threads/task-sidecar.d.ts.map +1 -0
  217. package/dist/threads/task-sidecar.js +311 -0
  218. package/dist/threads/task-sidecar.js.map +1 -0
  219. package/dist/threads/task-store.d.ts +172 -0
  220. package/dist/threads/task-store.d.ts.map +1 -0
  221. package/dist/threads/task-store.js +599 -0
  222. package/dist/threads/task-store.js.map +1 -0
  223. package/dist/threads/thread-activity-controller.d.ts +7 -0
  224. package/dist/threads/thread-activity-controller.d.ts.map +1 -1
  225. package/dist/threads/thread-activity-controller.js +52 -2
  226. package/dist/threads/thread-activity-controller.js.map +1 -1
  227. package/dist/threads/thread-task-context.d.ts +40 -0
  228. package/dist/threads/thread-task-context.d.ts.map +1 -0
  229. package/dist/threads/thread-task-context.js +160 -0
  230. package/dist/threads/thread-task-context.js.map +1 -0
  231. package/dist/threads/thread-task-controller.d.ts +122 -0
  232. package/dist/threads/thread-task-controller.d.ts.map +1 -0
  233. package/dist/threads/thread-task-controller.js +276 -0
  234. package/dist/threads/thread-task-controller.js.map +1 -0
  235. package/dist/threads/thread-task-runtime.d.ts +350 -0
  236. package/dist/threads/thread-task-runtime.d.ts.map +1 -0
  237. package/dist/threads/thread-task-runtime.js +896 -0
  238. package/dist/threads/thread-task-runtime.js.map +1 -0
  239. package/dist/threads/worker-entry.d.ts.map +1 -1
  240. package/dist/threads/worker-entry.js +28 -29
  241. package/dist/threads/worker-entry.js.map +1 -1
  242. package/dist/threads/worker-execution-runtime.d.ts +2 -3
  243. package/dist/threads/worker-execution-runtime.d.ts.map +1 -1
  244. package/dist/threads/worker-execution-runtime.js +2 -5
  245. package/dist/threads/worker-execution-runtime.js.map +1 -1
  246. package/dist/tools/delegation.d.ts +2 -71
  247. package/dist/tools/delegation.d.ts.map +1 -1
  248. package/dist/tools/delegation.js +28 -62
  249. package/dist/tools/delegation.js.map +1 -1
  250. package/dist/tools/email.d.ts +1 -1
  251. package/dist/tools/execution-control.d.ts +0 -5
  252. package/dist/tools/execution-control.d.ts.map +1 -1
  253. package/dist/tools/execution-control.js +2 -9
  254. package/dist/tools/execution-control.js.map +1 -1
  255. package/dist/tools/index.d.ts.map +1 -1
  256. package/dist/tools/index.js +6 -2
  257. package/dist/tools/index.js.map +1 -1
  258. package/dist/tools/mcp-manager.d.ts +1 -1
  259. package/dist/tools/memory.d.ts +1 -1
  260. package/dist/tools/notify.d.ts +0 -2
  261. package/dist/tools/notify.d.ts.map +1 -1
  262. package/dist/tools/notify.js +5 -21
  263. package/dist/tools/notify.js.map +1 -1
  264. package/dist/tools/skill.d.ts +1 -1
  265. package/dist/tools/thread-tasks.d.ts +23 -0
  266. package/dist/tools/thread-tasks.d.ts.map +1 -0
  267. package/dist/tools/thread-tasks.js +122 -0
  268. package/dist/tools/thread-tasks.js.map +1 -0
  269. package/dist/tools/totp.d.ts +1 -1
  270. package/dist/tui/request-store.d.ts +1 -1
  271. package/dist/tui/request-store.d.ts.map +1 -1
  272. package/dist/tui/request-store.js +2 -2
  273. package/dist/tui/request-store.js.map +1 -1
  274. package/dist/tui/server.d.ts.map +1 -1
  275. package/dist/tui/server.js +2 -17
  276. package/dist/tui/server.js.map +1 -1
  277. package/dist/utils/restart.d.ts.map +1 -1
  278. package/dist/utils/restart.js +0 -6
  279. package/dist/utils/restart.js.map +1 -1
  280. package/dist-agent/bundle.cjs +2 -2
  281. package/package.json +1 -1
  282. package/dist/agent/runtime-context.d.ts +0 -27
  283. package/dist/agent/runtime-context.d.ts.map +0 -1
  284. package/dist/agent/runtime-context.js +0 -60
  285. package/dist/agent/runtime-context.js.map +0 -1
  286. package/dist/agent/runtime-disclosure-policy.d.ts +0 -6
  287. package/dist/agent/runtime-disclosure-policy.d.ts.map +0 -1
  288. package/dist/agent/runtime-disclosure-policy.js +0 -16
  289. package/dist/agent/runtime-disclosure-policy.js.map +0 -1
  290. package/dist/conversations/lazy-runtime.d.ts +0 -5
  291. package/dist/conversations/lazy-runtime.d.ts.map +0 -1
  292. package/dist/conversations/lazy-runtime.js +0 -12
  293. package/dist/conversations/lazy-runtime.js.map +0 -1
  294. package/dist/conversations/runtime.d.ts +0 -17
  295. package/dist/conversations/runtime.d.ts.map +0 -1
  296. package/dist/conversations/runtime.js +0 -92
  297. package/dist/conversations/runtime.js.map +0 -1
  298. package/dist/conversations/scheduler.d.ts +0 -57
  299. package/dist/conversations/scheduler.d.ts.map +0 -1
  300. package/dist/conversations/scheduler.js +0 -175
  301. package/dist/conversations/scheduler.js.map +0 -1
  302. package/dist/threads/foreman-business.d.ts +0 -9
  303. package/dist/threads/foreman-business.d.ts.map +0 -1
  304. package/dist/threads/foreman-business.js +0 -117
  305. package/dist/threads/foreman-business.js.map +0 -1
  306. package/dist/threads/foreman-delivery.d.ts +0 -5
  307. package/dist/threads/foreman-delivery.d.ts.map +0 -1
  308. package/dist/threads/foreman-delivery.js +0 -21
  309. package/dist/threads/foreman-delivery.js.map +0 -1
  310. package/dist/threads/task-workspace.d.ts +0 -8
  311. package/dist/threads/task-workspace.d.ts.map +0 -1
  312. package/dist/threads/task-workspace.js +0 -52
  313. package/dist/threads/task-workspace.js.map +0 -1
@@ -0,0 +1,276 @@
1
+ /**
2
+ * ThreadTaskController (issue #1996, PR 2): the plain-TypeScript owner of a
3
+ * thread's task maintenance. Not an agent. It decides when to call the
4
+ * sidecar, validates the output and commits it with the consume position.
5
+ *
6
+ * Guarantees:
7
+ * - One maintenance run per thread at a time (a promise chain).
8
+ * - No events after the consume position → no model call.
9
+ * - Timeouts, model errors, malformed output and rejected commits leave the
10
+ * consume position where it was; the same events are retried later.
11
+ * - A version or position conflict (something else committed while the
12
+ * model was thinking) discards the output and re-runs on fresh state, so
13
+ * a stale result never overrides a cancellation or modification.
14
+ * - Events appended during a call go to the next batch: a run consumes
15
+ * exactly the events it read.
16
+ * - A fenced-out writer (replaced worker) stops instead of retrying.
17
+ *
18
+ * Standalone in this PR: nothing in the loop creates a controller yet.
19
+ */
20
+ import { logger } from "../logger.js";
21
+ import { SidecarOutputError, selectSidecarTasks, toTaskChanges } from "./task-sidecar.js";
22
+ class SidecarTimeoutError extends Error {
23
+ }
24
+ class ControllerClosedError extends Error {
25
+ }
26
+ export class ThreadTaskController {
27
+ store;
28
+ model;
29
+ batchDelayMs;
30
+ maxBatchEvents;
31
+ callTimeoutMs;
32
+ retryDelayMs;
33
+ maxRetryDelayMs;
34
+ budget;
35
+ ownerReserve;
36
+ chain = Promise.resolve();
37
+ running = false;
38
+ closed = false;
39
+ fenced = false;
40
+ timer = null;
41
+ timerAt = Infinity;
42
+ pendingSince = null;
43
+ consecutiveFailures = 0;
44
+ callTimes = [];
45
+ currentCall = null;
46
+ constructor(options) {
47
+ this.store = options.store;
48
+ this.model = options.model;
49
+ this.batchDelayMs = options.batchDelayMs ?? 10_000;
50
+ this.maxBatchEvents = options.maxBatchEvents ?? 20;
51
+ this.callTimeoutMs = options.callTimeoutMs ?? 60_000;
52
+ this.retryDelayMs = options.retryDelayMs ?? 5_000;
53
+ this.maxRetryDelayMs = options.maxRetryDelayMs ?? 5 * 60_000;
54
+ this.budget = options.budget ?? { maxCalls: 30, windowMs: 10 * 60_000 };
55
+ this.ownerReserve = Math.min(options.ownerReserve ?? 0, this.budget.maxCalls - 1);
56
+ }
57
+ /** Pick up events left unconsumed by a previous process. */
58
+ start() {
59
+ this.reschedule();
60
+ }
61
+ /**
62
+ * Tell the controller events were appended. `immediate` (owner messages)
63
+ * runs as soon as the current run and the budget allow; otherwise events
64
+ * wait up to `batchDelayMs` from the first unprocessed one, so a burst of
65
+ * tool results costs one call, not one per result.
66
+ */
67
+ notify(options = {}) {
68
+ if (this.closed || this.fenced)
69
+ return;
70
+ const now = Date.now();
71
+ this.pendingSince ??= now;
72
+ if (options.immediate) {
73
+ this.scheduleAt(now);
74
+ }
75
+ else {
76
+ this.reschedule();
77
+ }
78
+ }
79
+ /** Run one maintenance pass now, after any run already in progress. */
80
+ runOnce() {
81
+ const run = this.chain.then(() => this.runAndReschedule());
82
+ this.chain = run.catch(() => undefined);
83
+ return run;
84
+ }
85
+ /**
86
+ * Stop scheduling. An in-flight call gets `graceMs` to finish (and commit);
87
+ * after that it is aborted and its events stay unconsumed for next start.
88
+ */
89
+ async close(graceMs = 5_000) {
90
+ this.closed = true;
91
+ this.clearTimer();
92
+ const grace = setTimeout(() => this.currentCall?.abort(new ControllerClosedError("controller closed")), graceMs);
93
+ try {
94
+ await this.chain;
95
+ }
96
+ finally {
97
+ clearTimeout(grace);
98
+ }
99
+ }
100
+ get isFenced() {
101
+ return this.fenced;
102
+ }
103
+ async runAndReschedule() {
104
+ this.running = true;
105
+ let outcome;
106
+ try {
107
+ outcome = await this.runBatch();
108
+ }
109
+ finally {
110
+ this.running = false;
111
+ }
112
+ this.afterRun(outcome);
113
+ return outcome;
114
+ }
115
+ async runBatch() {
116
+ if (this.closed)
117
+ return { status: "closed" };
118
+ if (this.fenced)
119
+ return { status: "fenced", detail: "writer was replaced" };
120
+ const position = this.store.getPosition();
121
+ const events = this.store.readEventsAfter(position, this.maxBatchEvents);
122
+ if (events.length === 0)
123
+ return { status: "idle" };
124
+ const retryAt = this.takeBudget(events.some((event) => event.kind === "user_message"));
125
+ if (retryAt !== null)
126
+ return { status: "budget_exhausted", retryAt };
127
+ // Events appended from here on belong to the next batch.
128
+ this.pendingSince = null;
129
+ const tasks = selectSidecarTasks(this.store.listTasks());
130
+ let raw;
131
+ try {
132
+ raw = await this.callModel(tasks, events);
133
+ }
134
+ catch (error) {
135
+ if (error instanceof ControllerClosedError)
136
+ return { status: "closed" };
137
+ const detail = error instanceof Error ? error.message : String(error);
138
+ return { status: "failed", reason: error instanceof SidecarTimeoutError ? "timeout" : "model_error", detail };
139
+ }
140
+ let changes;
141
+ try {
142
+ changes = toTaskChanges(raw, tasks, events);
143
+ }
144
+ catch (error) {
145
+ if (!(error instanceof SidecarOutputError))
146
+ throw error;
147
+ return { status: "failed", reason: "invalid_output", detail: error.message };
148
+ }
149
+ // readEventsAfter returns ascending seq, so the last event bounds the batch.
150
+ const throughSeq = events[events.length - 1].seq;
151
+ let result;
152
+ try {
153
+ result = this.store.commit({ expectedPosition: position, throughSeq, changes });
154
+ }
155
+ catch (error) {
156
+ // e.g. SQLITE_BUSY: queue.db is shared with the message queue. The
157
+ // transaction rolled back, so the position is untouched; retry later.
158
+ return { status: "failed", reason: "commit_error", detail: error instanceof Error ? error.message : String(error) };
159
+ }
160
+ if (result.ok)
161
+ return { status: "committed", position: result.position, changes: changes.length };
162
+ switch (result.reason) {
163
+ case "stale_writer":
164
+ this.fenced = true;
165
+ return { status: "fenced", detail: result.detail };
166
+ case "version_conflict":
167
+ case "position_conflict":
168
+ return { status: "conflict", detail: result.detail };
169
+ default:
170
+ return { status: "failed", reason: "rejected", detail: `${result.reason}: ${result.detail}` };
171
+ }
172
+ }
173
+ async callModel(tasks, events) {
174
+ const abort = new AbortController();
175
+ this.currentCall = abort;
176
+ let timer;
177
+ const aborted = new Promise((_, reject) => {
178
+ abort.signal.addEventListener("abort", () => { reject(abort.signal.reason); }, { once: true });
179
+ timer = setTimeout(() => {
180
+ abort.abort(new SidecarTimeoutError(`sidecar call exceeded ${this.callTimeoutMs}ms`));
181
+ }, this.callTimeoutMs);
182
+ });
183
+ const call = this.model({ tasks, events }, { timeoutMs: this.callTimeoutMs, signal: abort.signal });
184
+ // The losing side of the race must not surface as an unhandled rejection.
185
+ call.catch(() => undefined);
186
+ aborted.catch(() => undefined);
187
+ try {
188
+ return await Promise.race([call, aborted]);
189
+ }
190
+ finally {
191
+ clearTimeout(timer);
192
+ this.currentCall = null;
193
+ }
194
+ }
195
+ afterRun(outcome) {
196
+ switch (outcome.status) {
197
+ case "committed":
198
+ case "idle":
199
+ this.consecutiveFailures = 0;
200
+ this.reschedule();
201
+ return;
202
+ case "conflict":
203
+ logger.debug(`[task-controller] thread=${this.store.threadId} commit conflict, re-reading: ${outcome.detail}`);
204
+ this.scheduleAt(Date.now());
205
+ return;
206
+ case "failed": {
207
+ this.consecutiveFailures += 1;
208
+ // TODO: a batch that fails deterministically retries forever (bounded
209
+ // by the budget). Add a dead-letter path if that shows up in practice.
210
+ const delay = Math.min(this.retryDelayMs * 2 ** (this.consecutiveFailures - 1), this.maxRetryDelayMs);
211
+ logger.warn(`[task-controller] thread=${this.store.threadId} sidecar ${outcome.reason}, retry in ${delay}ms: ${outcome.detail}`);
212
+ this.scheduleAt(Date.now() + delay);
213
+ return;
214
+ }
215
+ case "budget_exhausted":
216
+ this.scheduleAt(outcome.retryAt);
217
+ return;
218
+ case "fenced":
219
+ this.clearTimer();
220
+ logger.system(`[task-controller] thread=${this.store.threadId} stopped: ${outcome.detail}`);
221
+ return;
222
+ case "closed":
223
+ return;
224
+ }
225
+ }
226
+ /** Schedule the next run from what is actually unconsumed in the store. */
227
+ reschedule() {
228
+ if (this.closed || this.fenced || this.running)
229
+ return;
230
+ const pending = this.store.readEventsAfter(this.store.getPosition(), this.maxBatchEvents).length;
231
+ if (pending === 0) {
232
+ this.pendingSince = null;
233
+ return;
234
+ }
235
+ const now = Date.now();
236
+ this.pendingSince ??= now;
237
+ this.scheduleAt(pending >= this.maxBatchEvents ? now : this.pendingSince + this.batchDelayMs);
238
+ }
239
+ scheduleAt(at) {
240
+ if (this.closed || this.fenced)
241
+ return;
242
+ if (this.timer && this.timerAt <= at)
243
+ return;
244
+ this.clearTimer();
245
+ this.timerAt = at;
246
+ this.timer = setTimeout(() => {
247
+ this.timer = null;
248
+ this.timerAt = Infinity;
249
+ this.runOnce().catch((error) => {
250
+ logger.err(`[task-controller] thread=${this.store.threadId} run crashed: ${error instanceof Error ? error.message : String(error)}`);
251
+ });
252
+ }, Math.max(0, at - Date.now()));
253
+ }
254
+ clearTimer() {
255
+ if (this.timer)
256
+ clearTimeout(this.timer);
257
+ this.timer = null;
258
+ this.timerAt = Infinity;
259
+ }
260
+ /**
261
+ * Take one call from the sliding window, or return when one frees up. A
262
+ * batch without an owner message stops short of the owner reserve.
263
+ */
264
+ takeBudget(hasOwnerMessage) {
265
+ const now = Date.now();
266
+ this.callTimes = this.callTimes.filter((at) => at > now - this.budget.windowMs);
267
+ const limit = hasOwnerMessage ? this.budget.maxCalls : this.budget.maxCalls - this.ownerReserve;
268
+ if (this.callTimes.length >= limit) {
269
+ // The call that has to expire for the count to drop below the limit.
270
+ return this.callTimes[this.callTimes.length - limit] + this.budget.windowMs;
271
+ }
272
+ this.callTimes.push(now);
273
+ return null;
274
+ }
275
+ }
276
+ //# sourceMappingURL=thread-task-controller.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread-task-controller.js","sourceRoot":"","s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ACL,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACnC,CAAC;IAEO,UAAU;QAChB,IAAI,IAAI,CAAC,KAAK;YAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAED;;;OAGG;IACK,UAAU,CAAC,eAAwB;QACzC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAChF,MAAM,KAAK,GAAG,eAAe,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC;QAChG,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;YACnC,qEAAqE;YACrE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;QAC9E,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,350 @@
1
+ /**
2
+ * ThreadTaskRuntime (issue #1996, PR 3): the one object the live loop talks
3
+ * to. It owns this process's {@link ThreadTaskStore} and
4
+ * {@link ThreadTaskController} for the thread it serves — the default thread
5
+ * in the main process, a business thread in its worker.
6
+ *
7
+ * Hot-path rule: every method is fail-safe. A store, controller or model
8
+ * error is logged and swallowed; it must never break message handling, a
9
+ * wake or a reply. The cost of a failure is a missed task update that the
10
+ * next run can still recover from the persisted events, never a lost message.
11
+ */
12
+ import type { VisionClawConfig } from "../config/types.js";
13
+ import { type CommandMessage } from "../channels/interface.js";
14
+ import { type MessageQueue } from "../channels/queue.js";
15
+ import { type TaskEventInput, type TaskStatus, type ThreadTask } from "./task-contracts.js";
16
+ import { type SidecarModel } from "./task-sidecar.js";
17
+ import { type ThreadTaskControllerOptions } from "./thread-task-controller.js";
18
+ /**
19
+ * How long a fast reply waits for the sidecar before it settles for
20
+ * "received". Added in front of the fast responder's own 5 s budget.
21
+ */
22
+ export declare const REGISTRATION_WAIT_MS = 6000;
23
+ /**
24
+ * How long a lifecycle boundary waits for the sidecar to catch up (#1996 PR 4).
25
+ * Wake end is short because the next message waits behind it; compaction
26
+ * and refresh are already slow.
27
+ */
28
+ export declare const RECONCILE_WAIT_MS: {
29
+ readonly wakeEnd: 5000;
30
+ readonly boundary: 10000;
31
+ };
32
+ export type ReconcilePhase = "wake_end" | "compaction" | "refresh" | "stop";
33
+ /** `meta.kind` of a queued resume (PR 5). A system row: no fast reply, watchdog or gate reply. */
34
+ export declare const TASK_RESUME_KIND = "thread-task-resume";
35
+ /** A resume pass waits for the sidecar to catch up; if it cannot, it retries after this. */
36
+ export declare const RESUME_RETRY_MS = 60000;
37
+ /** How the loop lets the runtime queue and start resumes. */
38
+ export interface ResumeHooks {
39
+ queue: Pick<MessageQueue, "enqueue">;
40
+ /** A wake is running or work is queued; the end of that wake starts the next pass. */
41
+ isBusy: () => boolean;
42
+ /** Execution is stopped (service gate, league hold); the pass retries later. */
43
+ isGated: () => boolean;
44
+ /** Wake the loop after a resume was queued (works with proactive wake off). */
45
+ wake: () => void;
46
+ }
47
+ /** The queue, as `/stop` needs it: read and drop rows that are still pending. */
48
+ export type StopQueue = Pick<MessageQueue, "snapshot" | "remove" | "markHandled">;
49
+ /** What `/stop` did. */
50
+ export interface StopOutcome {
51
+ /** Tasks moved to `cancelled`. */
52
+ cancelled: ThreadTask[];
53
+ /** Queued owner messages dropped before they could become tasks. */
54
+ droppedQueued: number;
55
+ }
56
+ /** What `close_thread_task` did: the closed task, or why it was refused. */
57
+ export type CloseTaskOutcome = {
58
+ ok: true;
59
+ task: ThreadTask;
60
+ } | {
61
+ ok: false;
62
+ reason: string;
63
+ };
64
+ /** What a resume pass did; for logs and tests. */
65
+ export interface ResumeOutcome {
66
+ /** Resumes handed to the queue in this pass (new or re-sent reservations). */
67
+ queued: string[];
68
+ }
69
+ /** Where a reconcile left the consume position relative to its target. */
70
+ export interface ReconcileOutcome {
71
+ reached: boolean;
72
+ /** Latest event seq when the boundary was hit. */
73
+ target: number;
74
+ position: number;
75
+ }
76
+ export interface ThreadTaskRuntimeOptions {
77
+ threadId: string;
78
+ /** Worker instance id in workers (same fence as the queue); a per-process id in the main process. */
79
+ writerId: string;
80
+ config: VisionClawConfig;
81
+ /** Overrides for tests. */
82
+ dbPath?: string;
83
+ model?: SidecarModel;
84
+ controller?: Partial<ThreadTaskControllerOptions>;
85
+ }
86
+ /** What a fast reply may claim about a batch of messages. */
87
+ export interface RegistrationOutcome {
88
+ /** Every message's event is durable, so the request survives a crash. */
89
+ recorded: boolean;
90
+ /** Open tasks whose sources include one of the messages, after the sidecar ran. */
91
+ registered: ThreadTask[];
92
+ }
93
+ export declare class ThreadTaskRuntime {
94
+ readonly threadId: string;
95
+ private readonly store;
96
+ private readonly controller;
97
+ /**
98
+ * Latest event seq when this process started. A task whose last committed
99
+ * change came from events up to here was moved by a previous process.
100
+ */
101
+ private readonly startSeq;
102
+ /** Resumes this process accepted, by task id: a resume runs once per task per process. Released when its message goes back on the queue. */
103
+ private readonly resumesAccepted;
104
+ private closed;
105
+ private resumeHooks;
106
+ private resumeRetry;
107
+ private resumeRunning;
108
+ private constructor();
109
+ /**
110
+ * Open the thread's store next to its queue.db, take the writer slot and
111
+ * start the controller (which picks up events a previous process left).
112
+ * Returns null instead of throwing: without a runtime the agent runs
113
+ * exactly as before.
114
+ */
115
+ static start(options: ThreadTaskRuntimeOptions): ThreadTaskRuntime | null;
116
+ /**
117
+ * Persist owner messages as events. Idempotent per message (queue dedup
118
+ * key), so a redelivered message, the watchdog and the wake path can all
119
+ * call it. Returns false if any message could not be recorded.
120
+ */
121
+ recordMessages(messages: readonly CommandMessage[], options?: {
122
+ notify?: boolean;
123
+ }): boolean;
124
+ /** Persist an execution event (response, tool result, todo update, status report). */
125
+ recordExecution(input: TaskEventInput): void;
126
+ /**
127
+ * Record the messages, then wait up to `waitMs` for the sidecar to consume
128
+ * them. `registered` lists the open tasks the commit tied to these messages;
129
+ * empty means a reply may only acknowledge receipt.
130
+ *
131
+ * A run that started before these events cannot commit them (it snapshotted
132
+ * its batch), and a batch is a contiguous prefix, so the message may need
133
+ * more than one run: an execution-event backlog in front of it is folded
134
+ * first. The loop therefore waits for this message's events to be consumed,
135
+ * not for a single run, and stops as soon as the deadline passes or a run
136
+ * fails (the controller keeps retrying those events on its own schedule).
137
+ */
138
+ registerMessages(messages: readonly CommandMessage[], waitMs?: number): Promise<RegistrationOutcome>;
139
+ /** `close()` may run while a wait awaits; a method read is not narrowed away. */
140
+ private isClosed;
141
+ /** Open tasks already tied to any of these messages (no model call). */
142
+ tasksForMessages(messages: readonly CommandMessage[]): ThreadTask[];
143
+ /** Tasks of this thread for the query tool; `[]` on error. */
144
+ listTasks(statuses?: readonly TaskStatus[]): ThreadTask[];
145
+ /**
146
+ * Let the sidecar fold every event up to the latest one (the explicit
147
+ * position of this boundary), waiting at most `waitMs`. No events past the
148
+ * position means no model call. On timeout, budget exhaustion or failure
149
+ * the events simply stay unconsumed: the controller keeps retrying them,
150
+ * and {@link contextBlock} shows them raw to the next recovery.
151
+ */
152
+ reconcile(phase: ReconcilePhase, waitMs: number): Promise<ReconcileOutcome>;
153
+ /**
154
+ * Tasks a previous process left `in_progress`: their last change came from
155
+ * events recorded before this process started. That includes a task those
156
+ * events only move to `in_progress` when this process folds them at
157
+ * startup (the sidecar batches, so a crash usually leaves some). Once this
158
+ * process's own events move the task, it is no longer interrupted.
159
+ * TODO: a startup fold whose batch also holds events of this process
160
+ * stamps the task with the later seq and drops the flag early.
161
+ */
162
+ interruptedTaskIds(): Set<string>;
163
+ /** The recovery context for this thread, or null when it owes nothing. Never throws. */
164
+ contextBlock(): string | null;
165
+ /**
166
+ * Queue a resume for the next runnable task (PR 5), so the thread keeps
167
+ * working without a new owner message. Crash-safe in three steps:
168
+ * reserve the delivery record (`recovery:<task>:v<version>`), enqueue a
169
+ * system message whose id is that key, then mark it delivered. A crash
170
+ * before the enqueue leaves a reservation that the next pass re-sends; a
171
+ * crash after it is harmless because the queue dedups the id. A resume
172
+ * that was already delivered is never queued again for the same version.
173
+ *
174
+ * Never throws. Returns what it queued.
175
+ */
176
+ deliverResumes(queue: Pick<MessageQueue, "enqueue">, now?: number): ResumeOutcome;
177
+ /**
178
+ * Whether a dequeued resume may still run (the re-check before execution).
179
+ * Yes when its task is still pending at the version it was queued for and
180
+ * is due: a cancel, modification, wait or block since then makes it stale.
181
+ * Also yes, once per task per process, when a previous process left the
182
+ * task `in_progress` ({@link interruptedTaskIds}): that is a resume replayed
183
+ * after a crash, or one queued for the interrupted task. Its version is not
184
+ * compared, because folding the previous process's last events at startup
185
+ * bumps it.
186
+ *
187
+ * The "once" test is against {@link resumesAccepted}, which a requeue
188
+ * releases ({@link releaseResume}): an accepted resume whose message went
189
+ * back on the queue must still run when it is dequeued again, or the
190
+ * interrupted task keeps its only recovery row forever.
191
+ * Fail-closed: any error means no.
192
+ */
193
+ isResumeRunnable(msg: CommandMessage, now?: number): boolean;
194
+ /**
195
+ * The re-check at dequeue: {@link isResumeRunnable}, and if yes, record
196
+ * that this process is now working on the task so a second copy of its
197
+ * resume is stale.
198
+ */
199
+ acceptResume(msg: CommandMessage, now?: number): boolean;
200
+ /**
201
+ * The resume was accepted but its message went back on the queue (a failed
202
+ * inject, an orphaned injection, a failed wake). Takes the acceptance back
203
+ * so the next dequeue may run it. Safe for any message: not a resume, or
204
+ * never accepted, does nothing. #2664 review P1-B.
205
+ */
206
+ releaseResume(messages: readonly CommandMessage[]): void;
207
+ /** Install the loop's hooks. Resumes are only queued once this is set. */
208
+ enableResumes(hooks: ResumeHooks): void;
209
+ /**
210
+ * The owner sent `/stop` (option B, owner 10-04): cancel every unfinished
211
+ * task of this thread. Cancelled is a stored status, so nothing queued
212
+ * starts on its own, a restart cannot bring it back, and resumes already
213
+ * queued are retired at dequeue.
214
+ *
215
+ * The open tasks are cancelled at once. A message sent just before
216
+ * `/stop` may not be folded yet: the sidecar then folds up to the stop
217
+ * (bounded by `waitMs`) and the tasks those events created are cancelled
218
+ * too. Tasks from messages after the `/stop` are kept. Returns every
219
+ * cancelled task, for the reply. Never throws.
220
+ * TODO: a fold that misses `waitMs` (or more than {@link STOP_EVENTS}
221
+ * unfolded events) can still create a task from a pre-stop message later.
222
+ */
223
+ cancelOpenTasks(waitMs?: number, queue?: StopQueue): Promise<StopOutcome>;
224
+ /**
225
+ * Drop queued owner messages: rows not claimed by a wake, that are not
226
+ * system rows (a resume, or the stop command itself) and that the task
227
+ * sidecar would read as owner input. Returns how many were dropped.
228
+ * Fail-safe: a row that cannot be read is left alone.
229
+ */
230
+ private dropQueuedMessages;
231
+ /**
232
+ * Commit `cancelled` for these tasks without consuming any event, so the
233
+ * sidecar still folds everything. Read and commit run in one synchronous
234
+ * stretch, so no sidecar commit lands between them; a sidecar call in
235
+ * flight hits a version conflict and re-reads.
236
+ */
237
+ private cancelTasks;
238
+ /**
239
+ * Close one open task of this thread for the agent's `close_thread_task`
240
+ * tool (#2822). The sidecar completes a task only with evidence from the
241
+ * batch it folds, so finished work it missed stayed open and kept being
242
+ * resumed; this is the explicit way out. Commits like {@link cancelTasks}:
243
+ * no event is consumed, and a sidecar call in flight hits a version
244
+ * conflict and re-reads. Never throws.
245
+ */
246
+ closeTask(input: {
247
+ taskId: string;
248
+ status: "completed" | "cancelled";
249
+ summary: string;
250
+ evidenceRef: string;
251
+ }): CloseTaskOutcome;
252
+ /**
253
+ * Fold the events up to now, then queue the next runnable task. Called at
254
+ * wake end and at startup; never throws and never blocks the caller's
255
+ * loop. Without the fold a task the wake just finished could still look
256
+ * pending, so a pass that cannot catch up delivers nothing and retries
257
+ * after {@link RESUME_RETRY_MS} instead. A fold that needs a slow sidecar
258
+ * call therefore starts the next task about a minute later, not at once.
259
+ */
260
+ requestResume(waitMs?: number): Promise<ResumeOutcome>;
261
+ private scheduleResumeRetry;
262
+ private clearResumeRetry;
263
+ /** Enqueue one reserved resume and mark it delivered. False when nothing was handed over. */
264
+ private enqueueResume;
265
+ /** Events not yet folded into tasks (the sidecar is behind or failing). */
266
+ pendingEventCount(): number;
267
+ close(graceMs?: number): Promise<void>;
268
+ private safeNotify;
269
+ }
270
+ /**
271
+ * A task whose checkpoint lists nothing remaining and no blockers: the work
272
+ * is done but the sidecar did not complete it (no evidence in its batch).
273
+ * Resuming it only wakes the agent to find nothing to do (#2822). A task
274
+ * with no checkpoint yet has not been worked on, so it still resumes.
275
+ * TODO: a checkpoint that empties `remaining` too early stops auto-resume;
276
+ * the task stays open and visible in the context block.
277
+ */
278
+ export declare function hasNoRemainingWork(task: Pick<ThreadTask, "checkpoint">): boolean;
279
+ /** True for a queued thread-task resume row. */
280
+ export declare function isTaskResumeMessage(msg: CommandMessage): boolean;
281
+ /**
282
+ * The re-check before execution, at every place a wake takes rows off the
283
+ * queue: a resume whose task was cancelled, changed, put on hold or already
284
+ * started since it was queued is retired unexecuted. Without a runtime (the
285
+ * switch was turned off) every resume is stale. Returns true when retired.
286
+ */
287
+ export declare function retireStaleResume(queue: Pick<MessageQueue, "markHandled">, runtime: ThreadTaskRuntime | null, msg: CommandMessage): boolean;
288
+ /**
289
+ * Messages the task store tracks: anything from a real channel. System
290
+ * messages (heartbeats, internal continuations) and external-wake markers
291
+ * carry no owner request. Email and group chats are included; the sidecar
292
+ * decides whether they hold a request.
293
+ */
294
+ export declare function isTaskRelevantMessage(msg: CommandMessage): boolean;
295
+ /**
296
+ * The end-of-wake handoff (issue #1996 PR 1 rule): a claim is released as
297
+ * handled only after its message is a durable task event, so the follow-up
298
+ * belongs to the task store instead of vanishing with the queue row.
299
+ *
300
+ * Fail-safe: if recording fails the claims are still released. The agent
301
+ * already processed them in this wake; replaying them would redo the work.
302
+ * The error is logged. `handled` never means a task is completed.
303
+ */
304
+ export declare function releaseClaimsAfterRecording(queue: Pick<MessageQueue, "currentCycleClaims" | "markAllInFlightHandled">, runtime: ThreadTaskRuntime | null): void;
305
+ /**
306
+ * Wake end. A wake cut short by an engine failover restart leaves its claims
307
+ * in flight for the replacement process (issue #2519) and folds nothing.
308
+ * Otherwise release the claims, fold this wake's events into the
309
+ * checkpoints and queue the next runnable task (PR 5). Not awaited: the
310
+ * session keeps its transcript, so the loop need not hold the next message
311
+ * for it. Bounded; leftovers stay unconsumed and the next wake's context
312
+ * shows them raw.
313
+ */
314
+ export declare function endWakeThreadTasks(queue: Pick<MessageQueue, "currentCycleClaims" | "markAllInFlightHandled">, runtime: ThreadTaskRuntime | null, options: {
315
+ failoverRestartPending: boolean;
316
+ }): void;
317
+ /**
318
+ * Engine-neutral execution events. Both engines feed the same stream
319
+ * handler, so these are called from there. Each id is unique per call, so
320
+ * keys never collide across wakes or retries.
321
+ */
322
+ export declare const executionEvents: {
323
+ toolResult(toolUseId: string, toolName: string, output: string, isError: boolean): TaskEventInput | null;
324
+ todos(toolUseId: string, todos: readonly {
325
+ content: string;
326
+ status: string;
327
+ }[]): TaskEventInput | null;
328
+ response(turnId: string, text: string): TaskEventInput | null;
329
+ /** What the agent told the owner through notify_user: an explicit status report. */
330
+ statusReport(toolUseId: string, message: string): TaskEventInput | null;
331
+ };
332
+ /**
333
+ * The fast responder's reading of a batch, as one candidate event. It shares
334
+ * the message's dedup key, so the sidecar's origin key matches the message's
335
+ * and the same task is never created twice. Only for a single-message batch:
336
+ * a brief over several messages cannot be keyed to the right one, and the
337
+ * messages themselves are already events.
338
+ */
339
+ export declare function fastResponderCandidate(messages: readonly CommandMessage[], brief: unknown): TaskEventInput | null;
340
+ /** Record the fast responder's brief as a candidate event. Never throws. */
341
+ export declare function recordFastResponderCandidate(messages: readonly CommandMessage[], brief: unknown): void;
342
+ /** Record an execution event on the process runtime, if there is one. Never throws. */
343
+ export declare function recordExecutionEvent(input: TaskEventInput | null): void;
344
+ /** The process runtime's recovery context, or null without a runtime (then nothing is injected). */
345
+ export declare function buildThreadTaskContext(): string | null;
346
+ /** Bounded reconcile on the process runtime; resolves immediately without one. */
347
+ export declare function reconcileThreadTasks(phase: ReconcilePhase, waitMs?: number): Promise<void>;
348
+ export declare function setThreadTaskRuntime(runtime: ThreadTaskRuntime | null): void;
349
+ export declare function getThreadTaskRuntime(): ThreadTaskRuntime | null;
350
+ //# sourceMappingURL=thread-task-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"thread-task-runtime.d.ts","sourceRoot":"","sources":["../../src/threads/thread-task-runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAElF,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAE7E,OAAO,EAAsB,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAChH,OAAO,EAAsB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAE1E,OAAO,EAAwB,KAAK,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAerG;;;GAGG;AACH,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAE1C;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;CAAgD,CAAC;AAK/E,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,YAA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