@astralyn/pi 1.4.10 → 1.4.11

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 (97) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/bundle/chunks/{chunk-MF3T3ETJ.js → chunk-NUQMVNKQ.js} +2 -2
  3. package/dist/bundle/chunks/{chunk-6GTUUUCJ.js → chunk-PUU43PDV.js} +14 -29
  4. package/dist/bundle/chunks/{chunk-UCH27AVQ.js → chunk-TH3QDDPD.js} +1 -1
  5. package/dist/bundle/chunks/{execute-FQKRO4XJ.js → execute-VLAIP26K.js} +1 -1
  6. package/dist/bundle/chunks/{virtual-modules-6IJ6V2CG.js → virtual-modules-63XNTSVN.js} +1 -1
  7. package/dist/bundle/cli.js +1 -1
  8. package/dist/bundle/index.js +1 -1
  9. package/dist/bundle/rpc-entry.js +1 -1
  10. package/dist/core/agent-session.d.ts.map +1 -1
  11. package/dist/core/agent-session.js +0 -3
  12. package/dist/core/agent-session.js.map +1 -1
  13. package/dist/core/extensions/index.d.ts +1 -1
  14. package/dist/core/extensions/index.d.ts.map +1 -1
  15. package/dist/core/extensions/index.js.map +1 -1
  16. package/dist/core/extensions/loader.d.ts.map +1 -1
  17. package/dist/core/extensions/loader.js +14 -7
  18. package/dist/core/extensions/loader.js.map +1 -1
  19. package/dist/core/tasks/delivery.d.ts +4 -20
  20. package/dist/core/tasks/delivery.d.ts.map +1 -1
  21. package/dist/core/tasks/delivery.js +5 -58
  22. package/dist/core/tasks/delivery.js.map +1 -1
  23. package/dist/core/tasks/limits.d.ts +3 -19
  24. package/dist/core/tasks/limits.d.ts.map +1 -1
  25. package/dist/core/tasks/limits.js +3 -24
  26. package/dist/core/tasks/limits.js.map +1 -1
  27. package/dist/core/tasks/runtime.d.ts +1 -12
  28. package/dist/core/tasks/runtime.d.ts.map +1 -1
  29. package/dist/core/tasks/runtime.js +1 -81
  30. package/dist/core/tasks/runtime.js.map +1 -1
  31. package/dist/core/tasks/session.d.ts +0 -3
  32. package/dist/core/tasks/session.d.ts.map +1 -1
  33. package/dist/core/tasks/session.js +0 -16
  34. package/dist/core/tasks/session.js.map +1 -1
  35. package/dist/core/tasks/types.d.ts +2 -74
  36. package/dist/core/tasks/types.d.ts.map +1 -1
  37. package/dist/core/tasks/types.js +2 -2
  38. package/dist/core/tasks/types.js.map +1 -1
  39. package/dist/core/tools/shell-tool.js +1 -1
  40. package/dist/core/tools/shell-tool.js.map +1 -1
  41. package/dist/extensions/cached-compaction/summary.d.ts +1 -1
  42. package/dist/extensions/cached-compaction/summary.d.ts.map +1 -1
  43. package/dist/extensions/cached-compaction/summary.js +13 -16
  44. package/dist/extensions/cached-compaction/summary.js.map +1 -1
  45. package/dist/extensions/tasks/tool/actions.d.ts +1 -2
  46. package/dist/extensions/tasks/tool/actions.d.ts.map +1 -1
  47. package/dist/extensions/tasks/tool/actions.js +7 -79
  48. package/dist/extensions/tasks/tool/actions.js.map +1 -1
  49. package/dist/extensions/tasks/tool/constants.d.ts +1 -3
  50. package/dist/extensions/tasks/tool/constants.d.ts.map +1 -1
  51. package/dist/extensions/tasks/tool/constants.js +1 -3
  52. package/dist/extensions/tasks/tool/constants.js.map +1 -1
  53. package/dist/extensions/tasks/tool/schema.d.ts +1 -2
  54. package/dist/extensions/tasks/tool/schema.d.ts.map +1 -1
  55. package/dist/extensions/tasks/tool/schema.js +6 -14
  56. package/dist/extensions/tasks/tool/schema.js.map +1 -1
  57. package/dist/extensions/tasks/tool/types.d.ts +1 -19
  58. package/dist/extensions/tasks/tool/types.d.ts.map +1 -1
  59. package/dist/extensions/tasks/tool/types.js.map +1 -1
  60. package/dist/extensions/tasks/tool.d.ts +1 -2
  61. package/dist/extensions/tasks/tool.d.ts.map +1 -1
  62. package/dist/extensions/tasks/tool.js +2 -4
  63. package/dist/extensions/tasks/tool.js.map +1 -1
  64. package/dist/extensions/tasks/ui/render.d.ts +2 -16
  65. package/dist/extensions/tasks/ui/render.d.ts.map +1 -1
  66. package/dist/extensions/tasks/ui/render.js +3 -79
  67. package/dist/extensions/tasks/ui/render.js.map +1 -1
  68. package/dist/index.d.ts +1 -1
  69. package/dist/index.d.ts.map +1 -1
  70. package/dist/index.js.map +1 -1
  71. package/dist/modes/print-mode.d.ts.map +1 -1
  72. package/dist/modes/print-mode.js +1 -0
  73. package/dist/modes/print-mode.js.map +1 -1
  74. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  75. package/dist/modes/rpc/rpc-mode.js +1 -0
  76. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  77. package/docs/bundled/extensions/agent.md +2 -2
  78. package/docs/bundled/extensions/statusline.md +1 -1
  79. package/docs/bundled/tasks.md +10 -23
  80. package/docs/bundled/tool-presentation.md +1 -1
  81. package/docs/extensions.md +5 -7
  82. package/docs/models-configuration.md +1 -1
  83. package/docs/models.md +7 -85
  84. package/docs/sdk.md +3 -3
  85. package/docs/session-format.md +1 -1
  86. package/package.json +3 -4
  87. package/dist/core/tasks/wait.d.ts +0 -19
  88. package/dist/core/tasks/wait.d.ts.map +0 -1
  89. package/dist/core/tasks/wait.js +0 -45
  90. package/dist/core/tasks/wait.js.map +0 -1
  91. package/dist/modes/interactive/tool-view/tool-execution.d.ts +0 -14
  92. package/dist/modes/interactive/tool-view/tool-execution.d.ts.map +0 -1
  93. package/dist/modes/interactive/tool-view/tool-execution.js +0 -13
  94. package/dist/modes/interactive/tool-view/tool-execution.js.map +0 -1
  95. package/docs/images/doom-extension.png +0 -0
  96. package/docs/images/exy.png +0 -0
  97. package/npm-shrinkwrap.json +0 -4207
@@ -1 +1 @@
1
- {"version":3,"file":"delivery.js","sourceRoot":"","sources":["../../../src/core/tasks/delivery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AA8B1D;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAaxB,YAAY,OAA4B;QAXhC,aAAQ,GAAG,KAAK,CAAC;QACjB,W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AAG,SAAS,CAAC;QACvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CACD","sourcesContent":["import type { AgentMessage } from \"@earendil-works/pi-agent-core\";\nimport type { CustomMessage } from \"../messages.ts\";\nimport { taskCompletionMessage } from \"./presentation.ts\";\nimport type { TaskSnapshot, TasksContext } from \"./types.ts\";\n\n/** All the delivery policy needs from a runtime: its public, session-independent surface. */\nexport type TaskDeliveryService = Pick<TasksContext, \"enabled\" | \"closed\" | \"list\" | \"retain\">;\n\nexport interface TaskDeliveryOptions {\n\tservice(): TaskDeliveryService;\n\tcanDeliver(): boolean;\n\tdeliver(message: CustomMessage, waitForPersistence: () => Promise<void>): Promise<void>;\n\twarn(event: string, message: string): void;\n}\n\n/** A settled handoff the model has not yet seen, kept retained by a lease until it has. */\ninterface Completion {\n\tservice: TaskDeliveryService;\n\t/** The retention lease: the record and its output stay available until delivery or acknowledgement. */\n\trelease(): void;\n\t/** Handed to the host and awaiting persistence. */\n\tclaimed: boolean;\n}\n\ninterface Delivery {\n\tid: string;\n\t/** Agent-core preserves message identity; extension rewrites mutate it in place. */\n\tmessage: CustomMessage;\n\tphase: \"pending\" | \"started\" | \"persisted\";\n\tqueued?: { resolve(): void; reject(reason: Error): void };\n}\n\n/**\n * Sole owner of \"has this completion reached the model\": the pending queue, claims, the in-flight\n * completion, failures, pauses, wait receipts and observation holds. An undelivered completion is\n * a retention lease on its task, so the runtime keeps the record and its output exactly as long\n * as delivery needs them, and a bare runtime carries no delivery concept at all.\n */\nexport class TaskDelivery {\n\tprivate readonly options: TaskDeliveryOptions;\n\tprivate disposed = false;\n\tprivate pauses = 0;\n\tprivate timer?: ReturnType<typeof setTimeout>;\n\tprivate delivery?: Delivery;\n\t/** Settlement order. */\n\tprivate readonly completions = new Map<string, Completion>();\n\t/** Task IDs under an observation hold or wait receipt, with the number of holders. */\n\tprivate readonly holds = new Map<string, number>();\n\tprivate readonly failures = new Set<string>();\n\tprivate readonly waits = new Map<string, { taskId: string; release(): void }>();\n\tprivate readonly listeners = new Set<() => void>();\n\tconstructor(options: TaskDeliveryOptions) {\n\t\tthis.options = options;\n\t}\n\tprivate get service(): TaskDeliveryService {\n\t\treturn this.options.service();\n\t}\n\tprivate warn(event: string, message: string): void {\n\t\tthis.options.warn(event, message);\n\t}\n\t/** Called whenever what `hasDeliverableWork()` reads may have changed. */\n\tsubscribe(listener: () => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\tprivate changed(): void {\n\t\tfor (const listener of [...this.listeners]) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// Observers cannot interrupt delivery.\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Whether a completion is in flight or will be delivered without further input: queued on the\n\t * current runtime, visible on the branch and not failed. A failed delivery only retries on the\n\t * next input, so it does not count. Held completions count: releasing the hold, or the\n\t * acknowledgement that replaces it, always follows.\n\t */\n\thasDeliverableWork(): boolean {\n\t\tif (this.disposed) return false;\n\t\tconst service = this.service;\n\t\tif (service.closed) return false;\n\t\tif (this.delivery) return true;\n\t\tif (!service.enabled || this.completions.size === 0) return false;\n\t\treturn service.list().some((task) => {\n\t\t\tconst completion = this.completions.get(task.id);\n\t\t\treturn completion?.service === service && !this.failures.has(task.id);\n\t\t});\n\t}\n\n\t/** Nestable across asynchronous preflight and service replacement. */\n\tpause(): () => void {\n\t\tthis.pauses++;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tthis.pauses--;\n\t\t\tthis.schedule();\n\t\t};\n\t}\n\n\tretry(): void {\n\t\tthis.failures.clear();\n\t\tthis.schedule();\n\t\tthis.changed();\n\t}\n\n\t/** A handed-off task settled on `service`; it awaits automatic delivery under a retention lease. */\n\tenqueue(service: TaskDeliveryService, taskId: string): void {\n\t\tif (this.disposed || service.closed || this.completions.has(taskId)) return;\n\t\tthis.completions.set(taskId, { service, release: service.retain(taskId), claimed: false });\n\t\tthis.schedule();\n\t\tthis.changed();\n\t}\n\n\t/** The model has the result (or the host consumed it): stop waiting to deliver and release the lease. */\n\tacknowledge(taskId: string): void {\n\t\tconst completion = this.completions.get(taskId);\n\t\tif (!completion) return;\n\t\tthis.completions.delete(taskId);\n\t\tcompletion.release();\n\t\tthis.changed();\n\t}\n\n\t/** Release every lease held for a runtime that closed or was replaced, so its output cleanup can run. */\n\tdiscard(service: TaskDeliveryService): void {\n\t\tfor (const [id, completion] of [...this.completions]) {\n\t\t\tif (completion.service !== service) continue;\n\t\t\tthis.completions.delete(id);\n\t\t\tcompletion.release();\n\t\t}\n\t\tthis.changed();\n\t}\n\n\t/**\n\t * Keep `taskIds` out of automatic delivery until the release runs. Holds may precede\n\t * settlement, and releasing one re-evaluates the queue.\n\t */\n\thold(taskIds: readonly string[]): () => void {\n\t\tconst ids = [...taskIds];\n\t\tfor (const id of ids) this.holds.set(id, (this.holds.get(id) ?? 0) + 1);\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tfor (const id of ids) {\n\t\t\t\tconst count = (this.holds.get(id) ?? 1) - 1;\n\t\t\t\tif (count > 0) this.holds.set(id, count);\n\t\t\t\telse this.holds.delete(id);\n\t\t\t}\n\t\t\tthis.schedule();\n\t\t\tthis.changed();\n\t\t};\n\t}\n\n\t/**\n\t * Completions that would be delivered next, oldest launch first: on the visible branch, not\n\t * claimed and not held. Failed deliveries stay listed until the next retry.\n\t */\n\tpending(): TaskSnapshot[] {\n\t\tconst service = this.service;\n\t\tif (service.closed) return [];\n\t\treturn service.list().filter((task) => {\n\t\t\tconst completion = this.completions.get(task.id);\n\t\t\treturn completion?.service === service && !completion.claimed && !this.holds.has(task.id);\n\t\t});\n\t}\n\n\tschedule(): void {\n\t\tif (this.disposed || this.timer || this.delivery) return;\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.timer = undefined;\n\t\t\tvoid this.drain().catch(() =>\n\t\t\t\tthis.warn(\"task_delivery\", \"Background notification drain failed; delivery was not confirmed.\"),\n\t\t\t);\n\t\t}, 0);\n\t\tthis.timer.unref?.();\n\t}\n\n\tprivate canDeliver(service: TaskDeliveryService): boolean {\n\t\treturn (\n\t\t\t!this.disposed && service === this.service && service.enabled && this.pauses === 0 && this.options.canDeliver()\n\t\t);\n\t}\n\n\tprivate async drain(): Promise<void> {\n\t\tconst service = this.service;\n\t\tif (this.delivery || !this.canDeliver(service)) return;\n\t\tif (this.failures.size) {\n\t\t\tconst retained = new Set(service.list().map((task) => task.id));\n\t\t\tfor (const id of this.failures) if (!retained.has(id)) this.failures.delete(id);\n\t\t}\n\t\tconst task = this.pending().find((task) => !this.failures.has(task.id));\n\t\tif (!task) return;\n\t\tconst completion = this.completions.get(task.id)!;\n\t\tconst message = taskCompletionMessage(task);\n\t\tcompletion.claimed = true;\n\t\t// Exactly one completion may be in flight, whether queued for steering or running its\n\t\t// own turn; there is no separate claim registry.\n\t\tconst delivery: Delivery = {\n\t\t\tid: task.id,\n\t\t\tmessage,\n\t\t\tphase: \"pending\",\n\t\t};\n\t\tthis.delivery = delivery;\n\t\tlet deliveryError: unknown;\n\t\ttry {\n\t\t\tawait this.options.deliver(\n\t\t\t\tdelivery.message,\n\t\t\t\t() =>\n\t\t\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\t\t\tif (delivery.phase === \"persisted\") resolve();\n\t\t\t\t\t\telse delivery.queued = { resolve, reject };\n\t\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tdeliveryError = error;\n\t\t} finally {\n\t\t\tif (delivery.phase !== \"persisted\") {\n\t\t\t\tcompletion.claimed = false;\n\t\t\t\tif (service === this.service) this.failures.add(task.id);\n\t\t\t\tconst reason = deliveryError instanceof Error ? `: ${deliveryError.message}` : \"\";\n\t\t\t\tthis.warn(\n\t\t\t\t\t\"task_delivery\",\n\t\t\t\t\t`Background completion delivery failed for ${task.id}${reason}; it will retry on the next input.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.delivery = undefined;\n\t\t\tif (this.canDeliver(this.service) && this.pending().some((task) => !this.failures.has(task.id)))\n\t\t\t\tthis.schedule();\n\t\t\tthis.changed();\n\t\t}\n\t}\n\n\t/** Record dequeueing before message hooks can fail or rewrite the notification. */\n\tmessageStarted(message: AgentMessage): void {\n\t\tconst delivery = this.delivery;\n\t\tif (delivery?.message === message && delivery.phase === \"pending\") delivery.phase = \"started\";\n\t}\n\n\t/** A queued message that was never emitted remains claimed for the next run. */\n\tagentEnded(): void {\n\t\tthis.releaseWaits();\n\t\tconst delivery = this.delivery;\n\t\tif (delivery?.phase === \"started\") {\n\t\t\tdelivery.queued?.reject(new Error(\"the completion message was not persisted\"));\n\t\t}\n\t}\n\n\tqueueCleared(): void {\n\t\tthis.delivery?.queued?.reject(new Error(\"the completion message was dequeued before delivery\"));\n\t}\n\n\t/** Acknowledge only successful appends, using identity even when metadata was rewritten. */\n\tmessagePersisted(message: AgentMessage): void {\n\t\tconst delivery = this.delivery;\n\t\tif (delivery?.message === message && delivery.phase !== \"persisted\") {\n\t\t\tdelivery.phase = \"persisted\";\n\t\t\tthis.acknowledge(delivery.id);\n\t\t\tdelivery.queued?.resolve();\n\t\t}\n\t\tif (message.role === \"toolResult\") this.acknowledgeWait(message.toolCallId);\n\t}\n\n\t/**\n\t * A wait observed a settled background task. Its observation hold is still in place; take over\n\t * the hold until the wait's tool result is persisted, then acknowledge it instead of notifying.\n\t */\n\tbindWait(toolCallId: string, taskId: string): void {\n\t\tthis.waits.get(toolCallId)?.release();\n\t\tthis.waits.set(toolCallId, { taskId, release: this.hold([taskId]) });\n\t}\n\n\tprivate acknowledgeWait(toolCallId: string): void {\n\t\tconst receipt = this.waits.get(toolCallId);\n\t\tif (!receipt) return;\n\t\tthis.waits.delete(toolCallId);\n\t\tthis.acknowledge(receipt.taskId);\n\t\treceipt.release();\n\t}\n\n\tprivate releaseWaits(): void {\n\t\tfor (const receipt of this.waits.values()) receipt.release();\n\t\tthis.waits.clear();\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.releaseWaits();\n\t\tfor (const completion of this.completions.values()) completion.release();\n\t\tthis.completions.clear();\n\t\tthis.delivery?.queued?.reject(new Error(\"the session was disposed\"));\n\t\tif (this.timer) clearTimeout(this.timer);\n\t\tthis.timer = undefined;\n\t\tthis.changed();\n\t\tthis.listeners.clear();\n\t}\n}\n"]}
1
+ {"version":3,"file":"delivery.js","sourceRoot":"","sources":["../../../src/core/tasks/delivery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AA8B1D;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAUxB,YAAY,OAA4B;QARhC,aAAQ,GAAG,KAAK,CAAC;QACjB,WAAM,GAAG,CAAC,CAAC;QAGnB,wBAAwB;QACP,gBAAW,GAAG,IAAI,GAAG,EAAsB,CAAC;QAC5C,aAAQ,GAAG,IAAI,GAAG,EAAU,CAAC;QAC7B,cAAS,GAAG,IAAI,GAAG,EAAc,CAAC;QAElD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;IACD,IAAY,OAAO;QAClB,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;IAC/B,CAAC;IACO,IAAI,CAAC,KAAa,EAAE,OAAe;QAC1C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IACD,0EAA0E;IAC1E,SAAS,CAAC,QAAoB;QAC7B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE;YACX,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC,CAAC;IACH,CAAC;IAEO,OAAO;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Message } from \"../messages.ts\";\nimport { taskCompletionMessage } from \"./presentation.ts\";\nimport type { TaskSnapshot, TasksContext } from \"./types.ts\";\n\n/** All the delivery policy needs from a runtime: its public, session-independent surface. */\nexport type TaskDeliveryService = Pick<TasksContext, \"enabled\" | \"closed\" | \"list\" | \"retain\">;\n\nexport interface TaskDeliveryOptions {\n\tservice(): TaskDeliveryService;\n\tcanDeliver(): boolean;\n\tdeliver(message: CustomMessage, waitForPersistence: () => Promise<void>): Promise<void>;\n\twarn(event: string, message: string): void;\n}\n\n/** A settled handoff the model has not yet seen, kept retained by a lease until it has. */\ninterface Completion {\n\tservice: TaskDeliveryService;\n\t/** The retention lease: the record and its output stay available until delivery or acknowledgement. */\n\trelease(): void;\n\t/** Handed to the host and awaiting persistence. */\n\tclaimed: boolean;\n}\n\ninterface Delivery {\n\tid: string;\n\t/** Agent-core preserves message identity; extension rewrites mutate it in place. */\n\tmessage: CustomMessage;\n\tphase: \"pending\" | \"started\" | \"persisted\";\n\tqueued?: { resolve(): void; reject(reason: Error): void };\n}\n\n/**\n * Sole owner of \"has this completion reached the model\": the pending queue, claims, the in-flight\n * completion, failures and pauses. An undelivered completion is\n * a retention lease on its task, so the runtime keeps the record and its output exactly as long\n * as delivery needs them, and a bare runtime carries no delivery concept at all.\n */\nexport class TaskDelivery {\n\tprivate readonly options: TaskDeliveryOptions;\n\tprivate disposed = false;\n\tprivate pauses = 0;\n\tprivate timer?: ReturnType<typeof setTimeout>;\n\tprivate delivery?: Delivery;\n\t/** Settlement order. */\n\tprivate readonly completions = new Map<string, Completion>();\n\tprivate readonly failures = new Set<string>();\n\tprivate readonly listeners = new Set<() => void>();\n\tconstructor(options: TaskDeliveryOptions) {\n\t\tthis.options = options;\n\t}\n\tprivate get service(): TaskDeliveryService {\n\t\treturn this.options.service();\n\t}\n\tprivate warn(event: string, message: string): void {\n\t\tthis.options.warn(event, message);\n\t}\n\t/** Called whenever what `hasDeliverableWork()` reads may have changed. */\n\tsubscribe(listener: () => void): () => void {\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\tprivate changed(): void {\n\t\tfor (const listener of [...this.listeners]) {\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t// Observers cannot interrupt delivery.\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Whether a completion is in flight or will be delivered without further input: queued on the\n\t * current runtime, visible on the branch and not failed. A failed delivery only retries on the\n\t * next input, so it does not count.\n\t */\n\thasDeliverableWork(): boolean {\n\t\tif (this.disposed) return false;\n\t\tconst service = this.service;\n\t\tif (service.closed) return false;\n\t\tif (this.delivery) return true;\n\t\tif (!service.enabled || this.completions.size === 0) return false;\n\t\treturn service.list().some((task) => {\n\t\t\tconst completion = this.completions.get(task.id);\n\t\t\treturn completion?.service === service && !this.failures.has(task.id);\n\t\t});\n\t}\n\n\t/** Nestable across asynchronous preflight and service replacement. */\n\tpause(): () => void {\n\t\tthis.pauses++;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\tthis.pauses--;\n\t\t\tthis.schedule();\n\t\t};\n\t}\n\n\tretry(): void {\n\t\tthis.failures.clear();\n\t\tthis.schedule();\n\t\tthis.changed();\n\t}\n\n\t/** A handed-off task settled on `service`; it awaits automatic delivery under a retention lease. */\n\tenqueue(service: TaskDeliveryService, taskId: string): void {\n\t\tif (this.disposed || service.closed || this.completions.has(taskId)) return;\n\t\tthis.completions.set(taskId, { service, release: service.retain(taskId), claimed: false });\n\t\tthis.schedule();\n\t\tthis.changed();\n\t}\n\n\t/** The model has the result (or the host consumed it): stop waiting to deliver and release the lease. */\n\tacknowledge(taskId: string): void {\n\t\tconst completion = this.completions.get(taskId);\n\t\tif (!completion) return;\n\t\tthis.completions.delete(taskId);\n\t\tcompletion.release();\n\t\tthis.changed();\n\t}\n\n\t/** Release every lease held for a runtime that closed or was replaced, so its output cleanup can run. */\n\tdiscard(service: TaskDeliveryService): void {\n\t\tfor (const [id, completion] of [...this.completions]) {\n\t\t\tif (completion.service !== service) continue;\n\t\t\tthis.completions.delete(id);\n\t\t\tcompletion.release();\n\t\t}\n\t\tthis.changed();\n\t}\n\n\t/**\n\t * Completions that would be delivered next, oldest launch first: on the visible branch and not\n\t * claimed. Failed deliveries stay listed until the next retry.\n\t */\n\tpending(): TaskSnapshot[] {\n\t\tconst service = this.service;\n\t\tif (service.closed) return [];\n\t\treturn service.list().filter((task) => {\n\t\t\tconst completion = this.completions.get(task.id);\n\t\t\treturn completion?.service === service && !completion.claimed;\n\t\t});\n\t}\n\n\tschedule(): void {\n\t\tif (this.disposed || this.timer || this.delivery) return;\n\t\tthis.timer = setTimeout(() => {\n\t\t\tthis.timer = undefined;\n\t\t\tvoid this.drain().catch(() =>\n\t\t\t\tthis.warn(\"task_delivery\", \"Background notification drain failed; delivery was not confirmed.\"),\n\t\t\t);\n\t\t}, 0);\n\t\tthis.timer.unref?.();\n\t}\n\n\tprivate canDeliver(service: TaskDeliveryService): boolean {\n\t\treturn (\n\t\t\t!this.disposed && service === this.service && service.enabled && this.pauses === 0 && this.options.canDeliver()\n\t\t);\n\t}\n\n\tprivate async drain(): Promise<void> {\n\t\tconst service = this.service;\n\t\tif (this.delivery || !this.canDeliver(service)) return;\n\t\tif (this.failures.size) {\n\t\t\tconst retained = new Set(service.list().map((task) => task.id));\n\t\t\tfor (const id of this.failures) if (!retained.has(id)) this.failures.delete(id);\n\t\t}\n\t\tconst task = this.pending().find((task) => !this.failures.has(task.id));\n\t\tif (!task) return;\n\t\tconst completion = this.completions.get(task.id)!;\n\t\tconst message = taskCompletionMessage(task);\n\t\tcompletion.claimed = true;\n\t\t// Exactly one completion may be in flight, whether queued for steering or running its\n\t\t// own turn; there is no separate claim registry.\n\t\tconst delivery: Delivery = {\n\t\t\tid: task.id,\n\t\t\tmessage,\n\t\t\tphase: \"pending\",\n\t\t};\n\t\tthis.delivery = delivery;\n\t\tlet deliveryError: unknown;\n\t\ttry {\n\t\t\tawait this.options.deliver(\n\t\t\t\tdelivery.message,\n\t\t\t\t() =>\n\t\t\t\t\tnew Promise<void>((resolve, reject) => {\n\t\t\t\t\t\tif (delivery.phase === \"persisted\") resolve();\n\t\t\t\t\t\telse delivery.queued = { resolve, reject };\n\t\t\t\t\t}),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tdeliveryError = error;\n\t\t} finally {\n\t\t\tif (delivery.phase !== \"persisted\") {\n\t\t\t\tcompletion.claimed = false;\n\t\t\t\tif (service === this.service) this.failures.add(task.id);\n\t\t\t\tconst reason = deliveryError instanceof Error ? `: ${deliveryError.message}` : \"\";\n\t\t\t\tthis.warn(\n\t\t\t\t\t\"task_delivery\",\n\t\t\t\t\t`Background completion delivery failed for ${task.id}${reason}; it will retry on the next input.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tthis.delivery = undefined;\n\t\t\tif (this.canDeliver(this.service) && this.pending().some((task) => !this.failures.has(task.id)))\n\t\t\t\tthis.schedule();\n\t\t\tthis.changed();\n\t\t}\n\t}\n\n\t/** Record dequeueing before message hooks can fail or rewrite the notification. */\n\tmessageStarted(message: AgentMessage): void {\n\t\tconst delivery = this.delivery;\n\t\tif (delivery?.message === message && delivery.phase === \"pending\") delivery.phase = \"started\";\n\t}\n\n\t/** A queued message that was never emitted remains claimed for the next run. */\n\tagentEnded(): void {\n\t\tconst delivery = this.delivery;\n\t\tif (delivery?.phase === \"started\") {\n\t\t\tdelivery.queued?.reject(new Error(\"the completion message was not persisted\"));\n\t\t}\n\t}\n\n\tqueueCleared(): void {\n\t\tthis.delivery?.queued?.reject(new Error(\"the completion message was dequeued before delivery\"));\n\t}\n\n\t/** Acknowledge only successful appends, using identity even when metadata was rewritten. */\n\tmessagePersisted(message: AgentMessage): void {\n\t\tconst delivery = this.delivery;\n\t\tif (delivery?.message === message && delivery.phase !== \"persisted\") {\n\t\t\tdelivery.phase = \"persisted\";\n\t\t\tthis.acknowledge(delivery.id);\n\t\t\tdelivery.queued?.resolve();\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tfor (const completion of this.completions.values()) completion.release();\n\t\tthis.completions.clear();\n\t\tthis.delivery?.queued?.reject(new Error(\"the session was disposed\"));\n\t\tif (this.timer) clearTimeout(this.timer);\n\t\tthis.timer = undefined;\n\t\tthis.changed();\n\t\tthis.listeners.clear();\n\t}\n}\n"]}
@@ -1,28 +1,12 @@
1
1
  import type { TaskSnapshot } from "./types.ts";
2
- /**
3
- * Shared observation-window limits, the one definition used by the runtime and the tasks tool.
4
- * Execution timeouts are configured separately by each executor.
5
- *
6
- * A wait returns as soon as its task settles, and steering or another completion interrupts it, so
7
- * the default only bounds how long a wait on unfinished work blocks before the model has control
8
- * again. It is the longest window that stays inside the common five-minute prompt-cache lifetime,
9
- * with a minute's margin for the request around it: a longer one makes the next request miss the
10
- * cache or need a warming refresh.
11
- */
12
- export declare const TASKS_WAIT_DEFAULT_MS: number;
13
- export declare const TASKS_WAIT_MIN_MS = 1000;
14
- export declare const TASKS_WAIT_MAX_MS: number;
2
+ /** Shared read limits, the one definition used by the runtime and the tasks tool. */
15
3
  /** Floor for a model-requested read slice; the default and ceiling are TASK_READ_BYTES and TASK_RESULT_BYTES. */
16
4
  export declare const TASKS_READ_MIN_BYTES = 256;
17
- /** The wait window the runtime honours: any finite value up to the ceiling, including 0. */
18
- export declare function boundWaitMs(waitMs: number | undefined): number;
19
- /** The wait window a tool call runs, which the pending-call renderer also shows. */
20
- export declare function clampWaitMs(waitMs: number | undefined): number;
21
5
  /** The read size a tool call runs. */
22
6
  export declare function clampReadBytes(bytes: number | undefined): number;
23
7
  /**
24
- * The end a read starts from when the caller names none, the one definition every read,
25
- * wait and projection shares: a report's beginning is its summary, a log's end is its outcome.
8
+ * The end a read starts from when the caller names none, the one definition every read
9
+ * and projection shares: a report's beginning is its summary, a log's end is its outcome.
26
10
  */
27
11
  export declare function defaultReadMode(task: Pick<TaskSnapshot, "output">): "head" | "tail";
28
12
  //# sourceMappingURL=limits.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/limits.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C;;;;;;;;;GASG;AACH,eAAO,MAAM,qBAAqB,QAAa,CAAC;AAChD,eAAO,MAAM,iBAAiB,OAAQ,CAAC;AACvC,eAAO,MAAM,iBAAiB,QAAc,CAAC;AAC7C,iHAAiH;AACjH,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,4FAA4F;AAC5F,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAE9D;AAED,oFAAoF;AACpF,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAE9D;AAED,sCAAsC;AACtC,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAEhE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG,MAAM,GAAG,MAAM,CAEnF"}
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/limits.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,qFAAqF;AACrF,iHAAiH;AACjH,eAAO,MAAM,oBAAoB,MAAM,CAAC;AAExC,sCAAsC;AACtC,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAEhE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,QAAQ,CAAC,GAAG,MAAM,GAAG,MAAM,CAEnF"}
@@ -1,35 +1,14 @@
1
- import { finiteLimit } from "../../utils/number.js";
2
1
  import { boundReadBytes } from "./output.js";
3
- /**
4
- * Shared observation-window limits, the one definition used by the runtime and the tasks tool.
5
- * Execution timeouts are configured separately by each executor.
6
- *
7
- * A wait returns as soon as its task settles, and steering or another completion interrupts it, so
8
- * the default only bounds how long a wait on unfinished work blocks before the model has control
9
- * again. It is the longest window that stays inside the common five-minute prompt-cache lifetime,
10
- * with a minute's margin for the request around it: a longer one makes the next request miss the
11
- * cache or need a warming refresh.
12
- */
13
- export const TASKS_WAIT_DEFAULT_MS = 4 * 60_000;
14
- export const TASKS_WAIT_MIN_MS = 1_000;
15
- export const TASKS_WAIT_MAX_MS = 10 * 60_000;
2
+ /** Shared read limits, the one definition used by the runtime and the tasks tool. */
16
3
  /** Floor for a model-requested read slice; the default and ceiling are TASK_READ_BYTES and TASK_RESULT_BYTES. */
17
4
  export const TASKS_READ_MIN_BYTES = 256;
18
- /** The wait window the runtime honours: any finite value up to the ceiling, including 0. */
19
- export function boundWaitMs(waitMs) {
20
- return finiteLimit(waitMs, TASKS_WAIT_DEFAULT_MS, TASKS_WAIT_MAX_MS);
21
- }
22
- /** The wait window a tool call runs, which the pending-call renderer also shows. */
23
- export function clampWaitMs(waitMs) {
24
- return Math.max(TASKS_WAIT_MIN_MS, boundWaitMs(waitMs));
25
- }
26
5
  /** The read size a tool call runs. */
27
6
  export function clampReadBytes(bytes) {
28
7
  return Math.max(TASKS_READ_MIN_BYTES, boundReadBytes(bytes));
29
8
  }
30
9
  /**
31
- * The end a read starts from when the caller names none, the one definition every read,
32
- * wait and projection shares: a report's beginning is its summary, a log's end is its outcome.
10
+ * The end a read starts from when the caller names none, the one definition every read
11
+ * and projection shares: a report's beginning is its summary, a log's end is its outcome.
33
12
  */
34
13
  export function defaultReadMode(task) {
35
14
  return task.output === "report" ? "head" : "tail";
@@ -1 +1 @@
1
- {"version":3,"file":"limits.js","sourceRoot":"","sources":["../../../src/core/tasks/limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAG,MAAM,CAAC;AAChD,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,GAAG,MAAM,CAAC;AAC7C,iHAAiH;AACjH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,4FAA4F;AAC5F,MAAM,UAAU,WAAW,CAAC,MAA0B;IACrD,OAAO,WAAW,CAAC,MAAM,EAAE,qBAAqB,EAAE,iBAAiB,CAAC,CAAC;AACtE,CAAC;AAED,oFAAoF;AACpF,MAAM,UAAU,WAAW,CAAC,MAA0B;IACrD,OAAO,IAAI,CAAC,GAAG,CAAC,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACzD,CAAC;AAED,sCAAsC;AACtC,MAAM,UAAU,cAAc,CAAC,KAAyB;IACvD,OAAO,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAkC;IACjE,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC","sourcesContent":["import { finiteLimit } from \"../../utils/number.ts\";\nimport { boundReadBytes } from \"./output.ts\";\nimport type { TaskSnapshot } from \"./types.ts\";\n\n/**\n * Shared observation-window limits, the one definition used by the runtime and the tasks tool.\n * Execution timeouts are configured separately by each executor.\n *\n * A wait returns as soon as its task settles, and steering or another completion interrupts it, so\n * the default only bounds how long a wait on unfinished work blocks before the model has control\n * again. It is the longest window that stays inside the common five-minute prompt-cache lifetime,\n * with a minute's margin for the request around it: a longer one makes the next request miss the\n * cache or need a warming refresh.\n */\nexport const TASKS_WAIT_DEFAULT_MS = 4 * 60_000;\nexport const TASKS_WAIT_MIN_MS = 1_000;\nexport const TASKS_WAIT_MAX_MS = 10 * 60_000;\n/** Floor for a model-requested read slice; the default and ceiling are TASK_READ_BYTES and TASK_RESULT_BYTES. */\nexport const TASKS_READ_MIN_BYTES = 256;\n\n/** The wait window the runtime honours: any finite value up to the ceiling, including 0. */\nexport function boundWaitMs(waitMs: number | undefined): number {\n\treturn finiteLimit(waitMs, TASKS_WAIT_DEFAULT_MS, TASKS_WAIT_MAX_MS);\n}\n\n/** The wait window a tool call runs, which the pending-call renderer also shows. */\nexport function clampWaitMs(waitMs: number | undefined): number {\n\treturn Math.max(TASKS_WAIT_MIN_MS, boundWaitMs(waitMs));\n}\n\n/** The read size a tool call runs. */\nexport function clampReadBytes(bytes: number | undefined): number {\n\treturn Math.max(TASKS_READ_MIN_BYTES, boundReadBytes(bytes));\n}\n\n/**\n * The end a read starts from when the caller names none, the one definition every read,\n * wait and projection shares: a report's beginning is its summary, a log's end is its outcome.\n */\nexport function defaultReadMode(task: Pick<TaskSnapshot, \"output\">): \"head\" | \"tail\" {\n\treturn task.output === \"report\" ? \"head\" : \"tail\";\n}\n"]}
1
+ {"version":3,"file":"limits.js","sourceRoot":"","sources":["../../../src/core/tasks/limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,qFAAqF;AACrF,iHAAiH;AACjH,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AAExC,sCAAsC;AACtC,MAAM,UAAU,cAAc,CAAC,KAAyB;IACvD,OAAO,IAAI,CAAC,GAAG,CAAC,oBAAoB,EAAE,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,IAAkC;IACjE,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC;AACnD,CAAC","sourcesContent":["import { boundReadBytes } from \"./output.ts\";\nimport type { TaskSnapshot } from \"./types.ts\";\n\n/** Shared read limits, the one definition used by the runtime and the tasks tool. */\n/** Floor for a model-requested read slice; the default and ceiling are TASK_READ_BYTES and TASK_RESULT_BYTES. */\nexport const TASKS_READ_MIN_BYTES = 256;\n\n/** The read size a tool call runs. */\nexport function clampReadBytes(bytes: number | undefined): number {\n\treturn Math.max(TASKS_READ_MIN_BYTES, boundReadBytes(bytes));\n}\n\n/**\n * The end a read starts from when the caller names none, the one definition every read\n * and projection shares: a report's beginning is its summary, a log's end is its outcome.\n */\nexport function defaultReadMode(task: Pick<TaskSnapshot, \"output\">): \"head\" | \"tail\" {\n\treturn task.output === \"report\" ? \"head\" : \"tail\";\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { AgentToolResult } from "@earendil-works/pi-agent-core";
2
2
  import type { Theme } from "../../modes/interactive/theme/theme.ts";
3
- import { type TaskExecution, type TaskRead, type TaskReadOptions, type TaskRuntimeOptions, type TaskSnapshot, type TasksContext, type TaskToolOutcome, type TaskWaitAnyOptions, type TaskWaitAnyResult, type TaskWaitOptions, type TaskWaitResult } from "./types.ts";
3
+ import { type TaskExecution, type TaskRead, type TaskReadOptions, type TaskRuntimeOptions, type TaskSnapshot, type TasksContext, type TaskToolOutcome } from "./types.ts";
4
4
  /** Session-local supervision. Executors own their processes, items and output files. */
5
5
  export declare class TaskRuntime implements TasksContext {
6
6
  private readonly store;
@@ -12,7 +12,6 @@ export declare class TaskRuntime implements TasksContext {
12
12
  private readonly maxHistory;
13
13
  private readonly maxRetained;
14
14
  private readonly options;
15
- private readonly closing;
16
15
  private configuredEnabled;
17
16
  private _closed;
18
17
  constructor(options?: TaskRuntimeOptions);
@@ -32,8 +31,6 @@ export declare class TaskRuntime implements TasksContext {
32
31
  refresh(): void;
33
32
  /** Whether new work may move to or start in the background: enabled, and the host can manage it. */
34
33
  private get admitsBackground();
35
- /** Handed-off work that has not settled: the waitAny cohort and the statusline count. */
36
- private activeBackground;
37
34
  /**
38
35
  * Foreground work is bounded by its caller; only background work holds a slot, including work
39
36
  * whose caller is still waiting for the executor to accept (a detaching task).
@@ -53,14 +50,6 @@ export declare class TaskRuntime implements TasksContext {
53
50
  read(id: string, options?: TaskReadOptions): Promise<TaskRead>;
54
51
  presentOutput(id: string, width: number, theme: Theme): string[] | undefined;
55
52
  private resultText;
56
- /**
57
- * One observation: hold delivery for the observed records, wait, read, then register the
58
- * receipt with the host, and only then release. Nothing the caller does between those steps
59
- * can leak a settled result into an automatic notification or lose it.
60
- */
61
- private observe;
62
- wait(id: string, options?: TaskWaitOptions): Promise<TaskWaitResult>;
63
- waitAny(options?: TaskWaitAnyOptions): Promise<TaskWaitAnyResult>;
64
53
  kill(id: string): boolean;
65
54
  private cancel;
66
55
  subscribe(listener: () => void): () => void;
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/runtime.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAiBpE,OAAO,EAIN,KAAK,aAAa,EAElB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,eAAe,EAEpB,KAAK,cAAc,EACnB,MAAM,YAAY,CAAC;AAGpB,wFAAwF;AACxF,qBAAa,WAAY,YAAW,YAAY;IAC/C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyC;IACpE,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAuB;IACjD,OAAO,CAAC,QAAQ,C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20 +1,18 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { finiteLimit } from "../../utils/number.js";
3
3
  import { Execution } from "./execution.js";
4
- import { defaultReadMode, TASKS_WAIT_DEFAULT_MS } from "./limits.js";
4
+ import { defaultReadMode } from "./limits.js";
5
5
  import { boundFacts, boundInput, boundText, errorText, readOutputSlice, sliceText, TASK_LABEL_BYTES, TASK_TITLE_BYTES, } from "./output.js";
6
6
  import { TaskRecord } from "./record.js";
7
7
  import { TaskScheduler } from "./scheduler.js";
8
8
  import { TaskStore } from "./store.js";
9
9
  import { TASK_BACKGROUND_REJECTION, TASK_KIND_PATTERN, TASK_MANAGEMENT_REJECTION, TaskLookupError, } from "./types.js";
10
- import { waitForFirst } from "./wait.js";
11
10
  /** Session-local supervision. Executors own their processes, items and output files. */
12
11
  export class TaskRuntime {
13
12
  constructor(options = {}) {
14
13
  this.executions = new Map();
15
14
  this.scheduler = new TaskScheduler();
16
15
  this.listeners = new Set();
17
- this.closing = new AbortController();
18
16
  this._closed = false;
19
17
  this.options = options;
20
18
  this.configuredEnabled = options.enabled ?? false;
@@ -69,10 +67,6 @@ export class TaskRuntime {
69
67
  get admitsBackground() {
70
68
  return this.enabled && (this.options.canManageBackground?.() ?? true);
71
69
  }
72
- /** Handed-off work that has not settled: the waitAny cohort and the statusline count. */
73
- activeBackground() {
74
- return this.store.unsettled().filter((record) => record.task.mode === "background");
75
- }
76
70
  /**
77
71
  * Foreground work is bounded by its caller; only background work holds a slot, including work
78
72
  * whose caller is still waiting for the executor to accept (a detaching task).
@@ -225,79 +219,6 @@ export class TaskRuntime {
225
219
  resultText(task) {
226
220
  return task.result?.text || task.error || "No output yet.";
227
221
  }
228
- /**
229
- * One observation: hold delivery for the observed records, wait, read, then register the
230
- * receipt with the host, and only then release. Nothing the caller does between those steps
231
- * can leak a settled result into an automatic notification or lose it.
232
- */
233
- async observe(records, options,
234
- /** Record to read when none settled; a cohort has none. */
235
- fallback) {
236
- const { signal } = options;
237
- // Retention pins the records; the host keeps them out of automatic delivery until released.
238
- const releases = records.map((record) => this.pin(record));
239
- releases.push(this.options.waits?.hold(records.map((record) => record.task.id)) ?? (() => { }));
240
- try {
241
- const start = Date.now();
242
- const interrupt = this.options.waits?.interruptSignal;
243
- await waitForFirst({
244
- hasSettled: () => records.some((record) => record.settled),
245
- subscribe: (listener) => this.subscribe(listener),
246
- timeoutMs: options.timeoutMs ?? TASKS_WAIT_DEFAULT_MS,
247
- signal,
248
- interrupt,
249
- closed: this.closing.signal,
250
- });
251
- const waitedMs = Date.now() - start;
252
- const settled = records
253
- .filter((record) => record.settled)
254
- .sort((left, right) => (left.task.endedAt ?? 0) - (right.task.endedAt ?? 0))[0];
255
- const outcome = settled
256
- ? "settled"
257
- : this.closed
258
- ? "closed"
259
- : interrupt?.aborted
260
- ? "interrupted"
261
- : "timed_out";
262
- const running = records
263
- .filter((record) => record.visible && !record.settled)
264
- .map((record) => record.snapshot());
265
- const observed = settled ?? fallback;
266
- const read = options.read && observed && outcome !== "interrupted"
267
- ? await this.read(observed.task.id, options.read)
268
- : undefined;
269
- signal?.throwIfAborted();
270
- if (settled && settled.task.mode === "background" && options.toolCallId)
271
- this.options.waits?.bind(options.toolCallId, settled.task.id);
272
- return { outcome, waitedMs, settled, running, read };
273
- }
274
- finally {
275
- for (const release of releases)
276
- release();
277
- }
278
- }
279
- async wait(id, options = {}) {
280
- if (options.signal?.aborted)
281
- throw options.signal.reason ?? new Error("Wait aborted");
282
- const record = this.lookup(id);
283
- const { outcome, waitedMs, read } = await this.observe([record], options, record);
284
- return { outcome, waitedMs, task: record.snapshot(), ...(read ? { read } : {}) };
285
- }
286
- async waitAny(options = {}) {
287
- if (options.signal?.aborted)
288
- throw options.signal.reason ?? new Error("Wait aborted");
289
- const records = this.activeBackground().filter((record) => record.visible);
290
- if (records.length === 0)
291
- return { outcome: "no_tasks", waitedMs: 0, running: [] };
292
- const { outcome, waitedMs, settled, running, read } = await this.observe(records, options);
293
- return {
294
- outcome,
295
- waitedMs,
296
- running,
297
- ...(settled ? { task: settled.snapshot() } : {}),
298
- ...(read ? { read } : {}),
299
- };
300
- }
301
222
  kill(id) {
302
223
  return this.cancel(this.lookup(id));
303
224
  }
@@ -332,7 +253,6 @@ export class TaskRuntime {
332
253
  this.executions.get(record.task.id)?.releaseParent();
333
254
  this.cancel(record);
334
255
  }
335
- this.closing.abort();
336
256
  this.options.onClosed?.();
337
257
  this.store.trim();
338
258
  }
@@ -1 +1 @@
1
- {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/core/tasks/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAsB,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EACN,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACN,yBAAyB,EACzB,iBAAiB,EACjB,yBAAyB,EAEzB,eAAe,GAYf,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,wFAAwF;AACxF,MAAM,OAAO,WAAW;IAcvB,YAAY,UAA8B,EAAE;QAZ3B,eAAU,GAAG,IAAI,GAAG,EAA8B,CAAC;QACnD,cAAS,GAAG,IAAI,aAAa,EAAE,CAAC;QAChC,cAAS,GAAG,IAAI,GAAG,EAAc,CAAC;QAMlC,YAAO,GAAG,IAAI,eAAe,EAAE,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,CAAC;YAAC,MAAM,CAAC;gBACR,iDAAiD;YAClD,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { finiteLimit } from \"../../utils/number.ts\";\nimport { Execution, type ExecutionHost } from \"./execution.ts\";\nimport { defaultReadMode, TASKS_WAIT_DEFAULT_MS } from \"./limits.ts\";\nimport {\n\tboundFacts,\n\tboundInput,\n\tboundText,\n\terrorText,\n\treadOutputSlice,\n\tsliceText,\n\tTASK_LABEL_BYTES,\n\tTASK_TITLE_BYTES,\n} from \"./output.ts\";\nimport { TaskRecord } from \"./record.ts\";\nimport { TaskScheduler } from \"./scheduler.ts\";\nimport { TaskStore } from \"./store.ts\";\nimport {\n\tTASK_BACKGROUND_REJECTION,\n\tTASK_KIND_PATTERN,\n\tTASK_MANAGEMENT_REJECTION,\n\ttype TaskExecution,\n\tTaskLookupError,\n\ttype TaskRead,\n\ttype TaskReadOptions,\n\ttype TaskRuntimeOptions,\n\ttype TaskSnapshot,\n\ttype TasksContext,\n\ttype TaskToolOutcome,\n\ttype TaskWaitAnyOptions,\n\ttype TaskWaitAnyResult,\n\ttype TaskWaitOptions,\n\ttype TaskWaitOutcome,\n\ttype TaskWaitResult,\n} from \"./types.ts\";\nimport { waitForFirst } from \"./wait.ts\";\n\n/** Session-local supervision. Executors own their processes, items and output files. */\nexport class TaskRuntime implements TasksContext {\n\tprivate readonly store: TaskStore;\n\tprivate readonly executions = new Map<string, Execution<unknown>>();\n\tprivate readonly scheduler = new TaskScheduler();\n\tprivate readonly listeners = new Set<() => void>();\n\tprivate readonly host: ExecutionHost;\n\tprivate readonly maxBackground: number;\n\tprivate readonly maxHistory: number;\n\tprivate readonly maxRetained: number;\n\tprivate readonly options: TaskRuntimeOptions;\n\tprivate readonly closing = new AbortController();\n\tprivate configuredEnabled: boolean;\n\tprivate _closed = false;\n\n\tconstructor(options: TaskRuntimeOptions = {}) {\n\t\tthis.options = options;\n\t\tthis.configuredEnabled = options.enabled ?? false;\n\t\tthis.maxBackground = Math.max(1, finiteLimit(options.maxBackground, 8, 128));\n\t\tthis.maxHistory = finiteLimit(options.maxHistory, 32, 1024);\n\t\t// Separate foreground and background histories, plus the protected-record allowance.\n\t\tthis.maxRetained = this.maxBackground + 2 * Math.max(1, this.maxHistory) + this.maxHistory;\n\t\tthis.store = new TaskStore(this.maxHistory, this.maxRetained, () => this.closed, options.onCleanupError);\n\t\tconst runtime = this;\n\t\tthis.host = {\n\t\t\tget closed() {\n\t\t\t\treturn runtime.closed;\n\t\t\t},\n\t\t\temit: () => this.emit(),\n\t\t\tsettle: (task, usage) => this.options.onSettled?.(task, usage),\n\t\t\treleased: (execution) => {\n\t\t\t\tthis.executions.delete(execution.task.id);\n\t\t\t\tthis.scheduler.release(execution);\n\t\t\t\tthis.store.trim();\n\t\t\t\tthis.emit();\n\t\t\t},\n\t\t};\n\t}\n\n\tget closed(): boolean {\n\t\treturn this._closed;\n\t}\n\n\tget session(): TaskRuntimeOptions[\"session\"] {\n\t\treturn this.options.session;\n\t}\n\n\t/**\n\t * Rehydrate terminal snapshots only, newest endedAt in each history (later input wins\n\t * ties). Existing runtime records win ID collisions. No execution, accounting,\n\t * notification, or deletion ownership is restored. Foreground records take their output\n\t * from the branch's tool results. The host supplies the current branch; closed services\n\t * ignore restoration.\n\t */\n\trestoreHistory(\n\t\trecords: readonly unknown[],\n\t\ttoolResults?: ReadonlyMap<string, AgentToolResult<unknown>[\"content\"]>,\n\t): void {\n\t\tthis.store.restoreHistory(records, toolResults);\n\t}\n\n\tget enabled(): boolean {\n\t\treturn this.configuredEnabled && !this.closed && this.options.backgroundAllowed !== false;\n\t}\n\n\tsetEnabled(enabled: boolean): void {\n\t\tthis.configuredEnabled = enabled;\n\t\tthis.emit();\n\t}\n\n\t/** Tell subscribers that something the runtime reads from its host changed, such as `canManageBackground`. */\n\trefresh(): void {\n\t\tthis.emit();\n\t}\n\n\t/** Whether new work may move to or start in the background: enabled, and the host can manage it. */\n\tprivate get admitsBackground(): boolean {\n\t\treturn this.enabled && (this.options.canManageBackground?.() ?? true);\n\t}\n\n\t/** Handed-off work that has not settled: the waitAny cohort and the statusline count. */\n\tprivate activeBackground(): TaskRecord[] {\n\t\treturn this.store.unsettled().filter((record) => record.task.mode === \"background\");\n\t}\n\n\t/**\n\t * Foreground work is bounded by its caller; only background work holds a slot, including work\n\t * whose caller is still waiting for the executor to accept (a detaching task).\n\t */\n\tprivate backgroundActive(): number {\n\t\treturn [...this.executions.values()].filter((execution) => execution.holdsBackgroundSlot).length;\n\t}\n\n\tprivate limitError(): Error {\n\t\treturn new Error(\n\t\t\t`Background task limit reached (${this.maxBackground}); stop or wait for a background task, or run in the foreground.`,\n\t\t);\n\t}\n\n\tasync execute<T>(execution: TaskExecution<T>): Promise<TaskToolOutcome<T>> {\n\t\t// Admission and registration happen synchronously, before invoking user code or awaiting anything.\n\t\tif (execution.background && this.options.backgroundAllowed === false) throw new Error(TASK_BACKGROUND_REJECTION);\n\t\tif (this.closed) throw new Error(\"Task service is closed\");\n\t\tif (execution.background) {\n\t\t\tif (!this.enabled) throw new Error(\"Background execution is not available in this host\");\n\t\t\tif (!this.admitsBackground) throw new Error(TASK_MANAGEMENT_REJECTION);\n\t\t\tif (this.backgroundActive() >= this.maxBackground) throw this.limitError();\n\t\t\tif (this.store.retainedCount() >= this.maxRetained) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Task history retention limit reached; deliver pending notifications or release task pins and delivery leases\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (execution.signal?.aborted) throw execution.signal.reason ?? new Error(\"Execution aborted\");\n\t\tif (!TASK_KIND_PATTERN.test(execution.kind)) throw new Error(\"Invalid task source\");\n\t\tconst concurrency = execution.concurrency;\n\t\tif (concurrency && (!concurrency.key || !Number.isSafeInteger(concurrency.limit) || concurrency.limit < 1))\n\t\t\tthrow new Error(\"Invalid task concurrency\");\n\t\tconst anchorId = this.options.anchor?.() ?? null;\n\t\tif (anchorId !== null && Buffer.byteLength(anchorId) > 8192) throw new Error(\"Task branch anchor is too large\");\n\t\tconst task: TaskSnapshot = {\n\t\t\tid: `${execution.kind}-${randomUUID()}`,\n\t\t\tkind: execution.kind,\n\t\t\tlabel: boundText(execution.label ?? execution.kind, TASK_LABEL_BYTES),\n\t\t\ttitle: boundText(execution.title, TASK_TITLE_BYTES),\n\t\t\toutput: execution.output ?? \"log\",\n\t\t\t...(execution.input ? { input: boundInput(execution.input) } : {}),\n\t\t\t...(execution.facts?.length ? { facts: boundFacts(execution.facts) } : {}),\n\t\t\ttoolCallId: boundText(execution.toolCallId, 512),\n\t\t\tanchorId,\n\t\t\tmode: \"foreground\",\n\t\t\tstatus: \"queued\",\n\t\t\tstartedAt: Date.now(),\n\t\t};\n\t\tconst record = new TaskRecord(task);\n\t\trecord.setPresenter(execution.present);\n\t\tconst active = new Execution(this.host, record, execution);\n\t\tthis.store.add(record);\n\t\tthis.executions.set(task.id, active as Execution<unknown>);\n\t\tthis.scheduler.schedule(active);\n\t\t// Queued background work returns at once; started work hands off after its own accept().\n\t\tactive.handOffIfQueued();\n\t\tthis.emit();\n\t\treturn active.caller;\n\t}\n\n\tprivate detachable(record: TaskRecord): boolean {\n\t\treturn this.executions.get(record.task.id)?.detachable ?? false;\n\t}\n\n\tdetachForeground(): number {\n\t\tif (!this.admitsBackground) return 0;\n\t\tconst eligible = [...this.executions.values()]\n\t\t\t.filter((execution) => execution.detachable)\n\t\t\t.sort((left, right) => left.task.startedAt - right.task.startedAt);\n\t\tif (!eligible.length) return 0;\n\t\tconst free = this.maxBackground - this.backgroundActive();\n\t\tif (free <= 0) throw this.limitError();\n\t\treturn this.detachAll(eligible.slice(0, free));\n\t}\n\n\tcanDetach(id: string): boolean {\n\t\tconst record = this.lookup(id);\n\t\treturn this.admitsBackground && this.backgroundActive() < this.maxBackground && this.detachable(record);\n\t}\n\n\tdetach(id: string): boolean {\n\t\tconst record = this.lookup(id);\n\t\tif (!this.admitsBackground || !this.detachable(record)) return false;\n\t\tif (this.backgroundActive() >= this.maxBackground) throw this.limitError();\n\t\tthis.detachAll([this.executions.get(record.task.id)!]);\n\t\treturn true;\n\t}\n\n\t/** Every placement changes before any listener hears about it. */\n\tprivate detachAll(executions: Execution<unknown>[]): number {\n\t\tconst notifications = executions.map((execution) => execution.detach());\n\t\tfor (const notify of notifications) notify();\n\t\tthis.emit();\n\t\treturn executions.length;\n\t}\n\n\tlist(): TaskSnapshot[] {\n\t\treturn this.store.visible().map((record) => record.snapshot());\n\t}\n\n\tprivate lookup(id: string): TaskRecord {\n\t\tconst exact = this.store.get(id);\n\t\tif (exact) return exact;\n\t\tconst matches = this.store.match(id);\n\t\tif (!id || matches.length !== 1) {\n\t\t\tthrow new TaskLookupError(\n\t\t\t\tmatches.length > 1 ? \"ambiguous\" : \"unknown\",\n\t\t\t\tmatches.map((record) => record.snapshot()),\n\t\t\t);\n\t\t}\n\t\treturn matches[0]!;\n\t}\n\n\tget(id: string): TaskSnapshot {\n\t\treturn this.lookup(id).snapshot();\n\t}\n\n\tasync read(id: string, options: TaskReadOptions = {}): Promise<TaskRead> {\n\t\tconst record = this.lookup(id);\n\t\tconst release = this.retain(record.task.id);\n\t\ttry {\n\t\t\tconst task = record.snapshot();\n\t\t\tconst window = { ...options, mode: options.mode ?? defaultReadMode(task) };\n\t\t\tif (task.outputPath) {\n\t\t\t\ttry {\n\t\t\t\t\treturn { task, ...(await readOutputSlice(task.outputPath, window)) };\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttask,\n\t\t\t\t\t\treadError: boundText(`Output could not be read: ${errorText(error)}`, 4096),\n\t\t\t\t\t\t...sliceText(this.resultText(task), window),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { task, readError: record.readError, ...sliceText(this.resultText(task), window) };\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t}\n\n\tpresentOutput(id: string, width: number, theme: Theme): string[] | undefined {\n\t\tlet record: TaskRecord;\n\t\ttry {\n\t\t\trecord = this.lookup(id);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn record.present(width, theme);\n\t}\n\n\tprivate resultText(task: TaskSnapshot): string {\n\t\treturn task.result?.text || task.error || \"No output yet.\";\n\t}\n\n\t/**\n\t * One observation: hold delivery for the observed records, wait, read, then register the\n\t * receipt with the host, and only then release. Nothing the caller does between those steps\n\t * can leak a settled result into an automatic notification or lose it.\n\t */\n\tprivate async observe(\n\t\trecords: readonly TaskRecord[],\n\t\toptions: TaskWaitOptions,\n\t\t/** Record to read when none settled; a cohort has none. */\n\t\tfallback?: TaskRecord,\n\t): Promise<{\n\t\toutcome: TaskWaitOutcome;\n\t\twaitedMs: number;\n\t\tsettled?: TaskRecord;\n\t\trunning: TaskSnapshot[];\n\t\tread?: TaskRead;\n\t}> {\n\t\tconst { signal } = options;\n\t\t// Retention pins the records; the host keeps them out of automatic delivery until released.\n\t\tconst releases = records.map((record) => this.pin(record));\n\t\treleases.push(this.options.waits?.hold(records.map((record) => record.task.id)) ?? (() => {}));\n\t\ttry {\n\t\t\tconst start = Date.now();\n\t\t\tconst interrupt = this.options.waits?.interruptSignal;\n\t\t\tawait waitForFirst({\n\t\t\t\thasSettled: () => records.some((record) => record.settled),\n\t\t\t\tsubscribe: (listener) => this.subscribe(listener),\n\t\t\t\ttimeoutMs: options.timeoutMs ?? TASKS_WAIT_DEFAULT_MS,\n\t\t\t\tsignal,\n\t\t\t\tinterrupt,\n\t\t\t\tclosed: this.closing.signal,\n\t\t\t});\n\t\t\tconst waitedMs = Date.now() - start;\n\t\t\tconst settled = records\n\t\t\t\t.filter((record) => record.settled)\n\t\t\t\t.sort((left, right) => (left.task.endedAt ?? 0) - (right.task.endedAt ?? 0))[0];\n\t\t\tconst outcome: TaskWaitOutcome = settled\n\t\t\t\t? \"settled\"\n\t\t\t\t: this.closed\n\t\t\t\t\t? \"closed\"\n\t\t\t\t\t: interrupt?.aborted\n\t\t\t\t\t\t? \"interrupted\"\n\t\t\t\t\t\t: \"timed_out\";\n\t\t\tconst running = records\n\t\t\t\t.filter((record) => record.visible && !record.settled)\n\t\t\t\t.map((record) => record.snapshot());\n\t\t\tconst observed = settled ?? fallback;\n\t\t\tconst read =\n\t\t\t\toptions.read && observed && outcome !== \"interrupted\"\n\t\t\t\t\t? await this.read(observed.task.id, options.read)\n\t\t\t\t\t: undefined;\n\t\t\tsignal?.throwIfAborted();\n\t\t\tif (settled && settled.task.mode === \"background\" && options.toolCallId)\n\t\t\t\tthis.options.waits?.bind(options.toolCallId, settled.task.id);\n\t\t\treturn { outcome, waitedMs, settled, running, read };\n\t\t} finally {\n\t\t\tfor (const release of releases) release();\n\t\t}\n\t}\n\n\tasync wait(id: string, options: TaskWaitOptions = {}): Promise<TaskWaitResult> {\n\t\tif (options.signal?.aborted) throw options.signal.reason ?? new Error(\"Wait aborted\");\n\t\tconst record = this.lookup(id);\n\t\tconst { outcome, waitedMs, read } = await this.observe([record], options, record);\n\t\treturn { outcome, waitedMs, task: record.snapshot(), ...(read ? { read } : {}) };\n\t}\n\n\tasync waitAny(options: TaskWaitAnyOptions = {}): Promise<TaskWaitAnyResult> {\n\t\tif (options.signal?.aborted) throw options.signal.reason ?? new Error(\"Wait aborted\");\n\t\tconst records = this.activeBackground().filter((record) => record.visible);\n\t\tif (records.length === 0) return { outcome: \"no_tasks\", waitedMs: 0, running: [] };\n\t\tconst { outcome, waitedMs, settled, running, read } = await this.observe(records, options);\n\t\treturn {\n\t\t\toutcome,\n\t\t\twaitedMs,\n\t\t\trunning,\n\t\t\t...(settled ? { task: settled.snapshot() } : {}),\n\t\t\t...(read ? { read } : {}),\n\t\t};\n\t}\n\n\tkill(id: string): boolean {\n\t\treturn this.cancel(this.lookup(id));\n\t}\n\n\tprivate cancel(record: TaskRecord): boolean {\n\t\treturn this.executions.get(record.task.id)?.cancel() ?? false;\n\t}\n\n\tsubscribe(listener: () => void): () => void {\n\t\tif (this.closed) return () => {};\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\t/** Retention protects snapshots and logs only; completion delivery never waits on it. */\n\tretain(id: string): () => void {\n\t\treturn this.pin(this.lookup(id));\n\t}\n\n\tprivate pin(record: TaskRecord): () => void {\n\t\tconst release = record.pin();\n\t\treturn () => {\n\t\t\trelease();\n\t\t\tthis.store.trim();\n\t\t};\n\t}\n\n\tclose(): void {\n\t\tif (this.closed) return;\n\t\tthis._closed = true;\n\t\tthis.listeners.clear();\n\t\tfor (const record of this.store.all()) {\n\t\t\tthis.executions.get(record.task.id)?.releaseParent();\n\t\t\tthis.cancel(record);\n\t\t}\n\t\tthis.closing.abort();\n\t\tthis.options.onClosed?.();\n\t\tthis.store.trim();\n\t}\n\n\tasync shutdown(graceMs = 2000): Promise<void> {\n\t\tthis.close();\n\t\tawait this.drain(this.store.all(), graceMs);\n\t}\n\n\t/** Running tasks whose launch anchor is outside the branch made of `ancestors`. */\n\tactiveOutsideBranch(ancestors: ReadonlySet<string>): TaskSnapshot[] {\n\t\treturn this.store\n\t\t\t.unsettled()\n\t\t\t.filter((record) => record.task.anchorId !== null && !ancestors.has(record.task.anchorId))\n\t\t\t.map((record) => record.snapshot());\n\t}\n\n\t/**\n\t * Hidden results stay pending: returning to their branch delivers them again.\n\t * Restored history is already delivered.\n\t */\n\tasync cancelOutsideBranch(ancestors: ReadonlySet<string>): Promise<void> {\n\t\tconst records = this.store.all();\n\t\tfor (const record of records)\n\t\t\trecord.setVisible(record.task.anchorId === null || ancestors.has(record.task.anchorId));\n\t\tconst outside = records.filter((record) => !record.visible);\n\t\tfor (const record of outside) this.cancel(record);\n\t\tthis.store.trim();\n\t\tthis.emit();\n\t\tawait this.drain(outside, 2000);\n\t}\n\n\tprivate async drain(records: TaskRecord[], graceMs: number): Promise<void> {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait Promise.race([\n\t\t\t\tPromise.all(records.map((record) => this.executions.get(record.task.id)?.done)).then(() =>\n\t\t\t\t\tthis.store.cleanupsDone(),\n\t\t\t\t),\n\t\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\t\ttimer = setTimeout(resolve, finiteLimit(graceMs, 2000, 60_000));\n\t\t\t\t}),\n\t\t\t]);\n\t\t} finally {\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t}\n\t}\n\n\tprivate emit(): void {\n\t\tif (this.closed) return;\n\t\tfor (const listener of [...this.listeners]) {\n\t\t\tif (this.closed) break;\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t/* Observers do not own execution or delivery. */\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../../src/core/tasks/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAsB,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACN,UAAU,EACV,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,SAAS,EACT,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACN,yBAAyB,EACzB,iBAAiB,EACjB,yBAAyB,EAEzB,eAAe,GAOf,MAAM,YAAY,CAAC;AAEpB,wFAAwF;AACxF,MAAM,OAAO,WAAW;IAavB,YAAY,UAA8B,EAAE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IAAI,CAAC;gBAClB,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CACzF,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CACzB;gBACD,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;oBAC7B,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;gBACjE,CAAC,CAAC;aACF,CAAC,CAAC;QACJ,CAAC;gBAAS,CAAC;YACV,IAAI,KAAK,KAAK,SAAS;gBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;IAEO,IAAI;QACX,IAAI,IAAI,CAAC,MAAM;YAAE,OAAO;QACxB,KAAK,MAAM,QAAQ,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5C,IAAI,IAAI,CAAC,MAAM;gBAAE,MAAM;YACvB,IAAI,CAAC;gBACJ,QAAQ,EAAE,CAAC;YACZ,CAAC;YAAC,MAAM,CAAC;gBACR,iDAAiD;YAClD,CAAC;QACF,CAAC;IACF,CAAC;CACD","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport type { Theme } from \"../../modes/interactive/theme/theme.ts\";\nimport { finiteLimit } from \"../../utils/number.ts\";\nimport { Execution, type ExecutionHost } from \"./execution.ts\";\nimport { defaultReadMode } from \"./limits.ts\";\nimport {\n\tboundFacts,\n\tboundInput,\n\tboundText,\n\terrorText,\n\treadOutputSlice,\n\tsliceText,\n\tTASK_LABEL_BYTES,\n\tTASK_TITLE_BYTES,\n} from \"./output.ts\";\nimport { TaskRecord } from \"./record.ts\";\nimport { TaskScheduler } from \"./scheduler.ts\";\nimport { TaskStore } from \"./store.ts\";\nimport {\n\tTASK_BACKGROUND_REJECTION,\n\tTASK_KIND_PATTERN,\n\tTASK_MANAGEMENT_REJECTION,\n\ttype TaskExecution,\n\tTaskLookupError,\n\ttype TaskRead,\n\ttype TaskReadOptions,\n\ttype TaskRuntimeOptions,\n\ttype TaskSnapshot,\n\ttype TasksContext,\n\ttype TaskToolOutcome,\n} from \"./types.ts\";\n\n/** Session-local supervision. Executors own their processes, items and output files. */\nexport class TaskRuntime implements TasksContext {\n\tprivate readonly store: TaskStore;\n\tprivate readonly executions = new Map<string, Execution<unknown>>();\n\tprivate readonly scheduler = new TaskScheduler();\n\tprivate readonly listeners = new Set<() => void>();\n\tprivate readonly host: ExecutionHost;\n\tprivate readonly maxBackground: number;\n\tprivate readonly maxHistory: number;\n\tprivate readonly maxRetained: number;\n\tprivate readonly options: TaskRuntimeOptions;\n\tprivate configuredEnabled: boolean;\n\tprivate _closed = false;\n\n\tconstructor(options: TaskRuntimeOptions = {}) {\n\t\tthis.options = options;\n\t\tthis.configuredEnabled = options.enabled ?? false;\n\t\tthis.maxBackground = Math.max(1, finiteLimit(options.maxBackground, 8, 128));\n\t\tthis.maxHistory = finiteLimit(options.maxHistory, 32, 1024);\n\t\t// Separate foreground and background histories, plus the protected-record allowance.\n\t\tthis.maxRetained = this.maxBackground + 2 * Math.max(1, this.maxHistory) + this.maxHistory;\n\t\tthis.store = new TaskStore(this.maxHistory, this.maxRetained, () => this.closed, options.onCleanupError);\n\t\tconst runtime = this;\n\t\tthis.host = {\n\t\t\tget closed() {\n\t\t\t\treturn runtime.closed;\n\t\t\t},\n\t\t\temit: () => this.emit(),\n\t\t\tsettle: (task, usage) => this.options.onSettled?.(task, usage),\n\t\t\treleased: (execution) => {\n\t\t\t\tthis.executions.delete(execution.task.id);\n\t\t\t\tthis.scheduler.release(execution);\n\t\t\t\tthis.store.trim();\n\t\t\t\tthis.emit();\n\t\t\t},\n\t\t};\n\t}\n\n\tget closed(): boolean {\n\t\treturn this._closed;\n\t}\n\n\tget session(): TaskRuntimeOptions[\"session\"] {\n\t\treturn this.options.session;\n\t}\n\n\t/**\n\t * Rehydrate terminal snapshots only, newest endedAt in each history (later input wins\n\t * ties). Existing runtime records win ID collisions. No execution, accounting,\n\t * notification, or deletion ownership is restored. Foreground records take their output\n\t * from the branch's tool results. The host supplies the current branch; closed services\n\t * ignore restoration.\n\t */\n\trestoreHistory(\n\t\trecords: readonly unknown[],\n\t\ttoolResults?: ReadonlyMap<string, AgentToolResult<unknown>[\"content\"]>,\n\t): void {\n\t\tthis.store.restoreHistory(records, toolResults);\n\t}\n\n\tget enabled(): boolean {\n\t\treturn this.configuredEnabled && !this.closed && this.options.backgroundAllowed !== false;\n\t}\n\n\tsetEnabled(enabled: boolean): void {\n\t\tthis.configuredEnabled = enabled;\n\t\tthis.emit();\n\t}\n\n\t/** Tell subscribers that something the runtime reads from its host changed, such as `canManageBackground`. */\n\trefresh(): void {\n\t\tthis.emit();\n\t}\n\n\t/** Whether new work may move to or start in the background: enabled, and the host can manage it. */\n\tprivate get admitsBackground(): boolean {\n\t\treturn this.enabled && (this.options.canManageBackground?.() ?? true);\n\t}\n\n\t/**\n\t * Foreground work is bounded by its caller; only background work holds a slot, including work\n\t * whose caller is still waiting for the executor to accept (a detaching task).\n\t */\n\tprivate backgroundActive(): number {\n\t\treturn [...this.executions.values()].filter((execution) => execution.holdsBackgroundSlot).length;\n\t}\n\n\tprivate limitError(): Error {\n\t\treturn new Error(\n\t\t\t`Background task limit reached (${this.maxBackground}); stop or wait for a background task, or run in the foreground.`,\n\t\t);\n\t}\n\n\tasync execute<T>(execution: TaskExecution<T>): Promise<TaskToolOutcome<T>> {\n\t\t// Admission and registration happen synchronously, before invoking user code or awaiting anything.\n\t\tif (execution.background && this.options.backgroundAllowed === false) throw new Error(TASK_BACKGROUND_REJECTION);\n\t\tif (this.closed) throw new Error(\"Task service is closed\");\n\t\tif (execution.background) {\n\t\t\tif (!this.enabled) throw new Error(\"Background execution is not available in this host\");\n\t\t\tif (!this.admitsBackground) throw new Error(TASK_MANAGEMENT_REJECTION);\n\t\t\tif (this.backgroundActive() >= this.maxBackground) throw this.limitError();\n\t\t\tif (this.store.retainedCount() >= this.maxRetained) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Task history retention limit reached; deliver pending notifications or release task pins and delivery leases\",\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tif (execution.signal?.aborted) throw execution.signal.reason ?? new Error(\"Execution aborted\");\n\t\tif (!TASK_KIND_PATTERN.test(execution.kind)) throw new Error(\"Invalid task source\");\n\t\tconst concurrency = execution.concurrency;\n\t\tif (concurrency && (!concurrency.key || !Number.isSafeInteger(concurrency.limit) || concurrency.limit < 1))\n\t\t\tthrow new Error(\"Invalid task concurrency\");\n\t\tconst anchorId = this.options.anchor?.() ?? null;\n\t\tif (anchorId !== null && Buffer.byteLength(anchorId) > 8192) throw new Error(\"Task branch anchor is too large\");\n\t\tconst task: TaskSnapshot = {\n\t\t\tid: `${execution.kind}-${randomUUID()}`,\n\t\t\tkind: execution.kind,\n\t\t\tlabel: boundText(execution.label ?? execution.kind, TASK_LABEL_BYTES),\n\t\t\ttitle: boundText(execution.title, TASK_TITLE_BYTES),\n\t\t\toutput: execution.output ?? \"log\",\n\t\t\t...(execution.input ? { input: boundInput(execution.input) } : {}),\n\t\t\t...(execution.facts?.length ? { facts: boundFacts(execution.facts) } : {}),\n\t\t\ttoolCallId: boundText(execution.toolCallId, 512),\n\t\t\tanchorId,\n\t\t\tmode: \"foreground\",\n\t\t\tstatus: \"queued\",\n\t\t\tstartedAt: Date.now(),\n\t\t};\n\t\tconst record = new TaskRecord(task);\n\t\trecord.setPresenter(execution.present);\n\t\tconst active = new Execution(this.host, record, execution);\n\t\tthis.store.add(record);\n\t\tthis.executions.set(task.id, active as Execution<unknown>);\n\t\tthis.scheduler.schedule(active);\n\t\t// Queued background work returns at once; started work hands off after its own accept().\n\t\tactive.handOffIfQueued();\n\t\tthis.emit();\n\t\treturn active.caller;\n\t}\n\n\tprivate detachable(record: TaskRecord): boolean {\n\t\treturn this.executions.get(record.task.id)?.detachable ?? false;\n\t}\n\n\tdetachForeground(): number {\n\t\tif (!this.admitsBackground) return 0;\n\t\tconst eligible = [...this.executions.values()]\n\t\t\t.filter((execution) => execution.detachable)\n\t\t\t.sort((left, right) => left.task.startedAt - right.task.startedAt);\n\t\tif (!eligible.length) return 0;\n\t\tconst free = this.maxBackground - this.backgroundActive();\n\t\tif (free <= 0) throw this.limitError();\n\t\treturn this.detachAll(eligible.slice(0, free));\n\t}\n\n\tcanDetach(id: string): boolean {\n\t\tconst record = this.lookup(id);\n\t\treturn this.admitsBackground && this.backgroundActive() < this.maxBackground && this.detachable(record);\n\t}\n\n\tdetach(id: string): boolean {\n\t\tconst record = this.lookup(id);\n\t\tif (!this.admitsBackground || !this.detachable(record)) return false;\n\t\tif (this.backgroundActive() >= this.maxBackground) throw this.limitError();\n\t\tthis.detachAll([this.executions.get(record.task.id)!]);\n\t\treturn true;\n\t}\n\n\t/** Every placement changes before any listener hears about it. */\n\tprivate detachAll(executions: Execution<unknown>[]): number {\n\t\tconst notifications = executions.map((execution) => execution.detach());\n\t\tfor (const notify of notifications) notify();\n\t\tthis.emit();\n\t\treturn executions.length;\n\t}\n\n\tlist(): TaskSnapshot[] {\n\t\treturn this.store.visible().map((record) => record.snapshot());\n\t}\n\n\tprivate lookup(id: string): TaskRecord {\n\t\tconst exact = this.store.get(id);\n\t\tif (exact) return exact;\n\t\tconst matches = this.store.match(id);\n\t\tif (!id || matches.length !== 1) {\n\t\t\tthrow new TaskLookupError(\n\t\t\t\tmatches.length > 1 ? \"ambiguous\" : \"unknown\",\n\t\t\t\tmatches.map((record) => record.snapshot()),\n\t\t\t);\n\t\t}\n\t\treturn matches[0]!;\n\t}\n\n\tget(id: string): TaskSnapshot {\n\t\treturn this.lookup(id).snapshot();\n\t}\n\n\tasync read(id: string, options: TaskReadOptions = {}): Promise<TaskRead> {\n\t\tconst record = this.lookup(id);\n\t\tconst release = this.retain(record.task.id);\n\t\ttry {\n\t\t\tconst task = record.snapshot();\n\t\t\tconst window = { ...options, mode: options.mode ?? defaultReadMode(task) };\n\t\t\tif (task.outputPath) {\n\t\t\t\ttry {\n\t\t\t\t\treturn { task, ...(await readOutputSlice(task.outputPath, window)) };\n\t\t\t\t} catch (error) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttask,\n\t\t\t\t\t\treadError: boundText(`Output could not be read: ${errorText(error)}`, 4096),\n\t\t\t\t\t\t...sliceText(this.resultText(task), window),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn { task, readError: record.readError, ...sliceText(this.resultText(task), window) };\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t}\n\n\tpresentOutput(id: string, width: number, theme: Theme): string[] | undefined {\n\t\tlet record: TaskRecord;\n\t\ttry {\n\t\t\trecord = this.lookup(id);\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn record.present(width, theme);\n\t}\n\n\tprivate resultText(task: TaskSnapshot): string {\n\t\treturn task.result?.text || task.error || \"No output yet.\";\n\t}\n\n\tkill(id: string): boolean {\n\t\treturn this.cancel(this.lookup(id));\n\t}\n\n\tprivate cancel(record: TaskRecord): boolean {\n\t\treturn this.executions.get(record.task.id)?.cancel() ?? false;\n\t}\n\n\tsubscribe(listener: () => void): () => void {\n\t\tif (this.closed) return () => {};\n\t\tthis.listeners.add(listener);\n\t\treturn () => {\n\t\t\tthis.listeners.delete(listener);\n\t\t};\n\t}\n\n\t/** Retention protects snapshots and logs only; completion delivery never waits on it. */\n\tretain(id: string): () => void {\n\t\treturn this.pin(this.lookup(id));\n\t}\n\n\tprivate pin(record: TaskRecord): () => void {\n\t\tconst release = record.pin();\n\t\treturn () => {\n\t\t\trelease();\n\t\t\tthis.store.trim();\n\t\t};\n\t}\n\n\tclose(): void {\n\t\tif (this.closed) return;\n\t\tthis._closed = true;\n\t\tthis.listeners.clear();\n\t\tfor (const record of this.store.all()) {\n\t\t\tthis.executions.get(record.task.id)?.releaseParent();\n\t\t\tthis.cancel(record);\n\t\t}\n\t\tthis.options.onClosed?.();\n\t\tthis.store.trim();\n\t}\n\n\tasync shutdown(graceMs = 2000): Promise<void> {\n\t\tthis.close();\n\t\tawait this.drain(this.store.all(), graceMs);\n\t}\n\n\t/** Running tasks whose launch anchor is outside the branch made of `ancestors`. */\n\tactiveOutsideBranch(ancestors: ReadonlySet<string>): TaskSnapshot[] {\n\t\treturn this.store\n\t\t\t.unsettled()\n\t\t\t.filter((record) => record.task.anchorId !== null && !ancestors.has(record.task.anchorId))\n\t\t\t.map((record) => record.snapshot());\n\t}\n\n\t/**\n\t * Hidden results stay pending: returning to their branch delivers them again.\n\t * Restored history is already delivered.\n\t */\n\tasync cancelOutsideBranch(ancestors: ReadonlySet<string>): Promise<void> {\n\t\tconst records = this.store.all();\n\t\tfor (const record of records)\n\t\t\trecord.setVisible(record.task.anchorId === null || ancestors.has(record.task.anchorId));\n\t\tconst outside = records.filter((record) => !record.visible);\n\t\tfor (const record of outside) this.cancel(record);\n\t\tthis.store.trim();\n\t\tthis.emit();\n\t\tawait this.drain(outside, 2000);\n\t}\n\n\tprivate async drain(records: TaskRecord[], graceMs: number): Promise<void> {\n\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\ttry {\n\t\t\tawait Promise.race([\n\t\t\t\tPromise.all(records.map((record) => this.executions.get(record.task.id)?.done)).then(() =>\n\t\t\t\t\tthis.store.cleanupsDone(),\n\t\t\t\t),\n\t\t\t\tnew Promise<void>((resolve) => {\n\t\t\t\t\ttimer = setTimeout(resolve, finiteLimit(graceMs, 2000, 60_000));\n\t\t\t\t}),\n\t\t\t]);\n\t\t} finally {\n\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t}\n\t}\n\n\tprivate emit(): void {\n\t\tif (this.closed) return;\n\t\tfor (const listener of [...this.listeners]) {\n\t\t\tif (this.closed) break;\n\t\t\ttry {\n\t\t\t\tlistener();\n\t\t\t} catch {\n\t\t\t\t/* Observers do not own execution or delivery. */\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -37,7 +37,6 @@ export declare class TaskSession {
37
37
  private enabled;
38
38
  private disposed;
39
39
  private generation;
40
- private waitInterrupt;
41
40
  private readonly contextReminder;
42
41
  readonly delivery: TaskDelivery;
43
42
  private readonly quarantine;
@@ -49,8 +48,6 @@ export declare class TaskSession {
49
48
  /** Handed-off tasks of the current runtime that have not settled. */
50
49
  runningBackground(): TaskSnapshot[];
51
50
  get service(): TaskRuntime;
52
- /** End only current task waits; the next wait observes a fresh signal. */
53
- interruptWaits(): void;
54
51
  /** The active tools changed: availability of background detaching may have too. */
55
52
  toolsChanged(): void;
56
53
  noteCompaction(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAmB,MAAM,+BAA+B,CAAC;AACnF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAA2B,KAAK,YAAY,EAAE,KAAK,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIxG,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAkB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/D,UAAU,kBAAkB;IAC3B,OAAO,EAAE,cAAc,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,oEAAoE;IACpE,UAAU,IAAI,OAAO,CAAC;IACtB,gHAAgH;IAChH,gBAAgB,CAAC,IAAI,OAAO,CAAC;IAC7B;;;OAGG;IACH,O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cAAc,IAAI,IAAI;IAItB,sBAAsB,CAAC,QAAQ,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE;IAIhE,sBAAsB,IAAI,IAAI;IAI9B,IAAI,sBAAsB,IAAI,SAAS,yBAAyB,EAAE,CAEjE;IAED,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAKlC;;;;OAIG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,cAAe,GAAG,YAAY,EAAE;IAUjF,2EAA2E;IAC3E,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD,OAAO,CAAC,SAAS;IAIjB;;;OAGG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzC,2FAA2F;IAC3F,cAAc,IAAI,IAAI;IAQtB,wGAAwG;IACxG,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAIzC,OAAO,CAAC,aAAa;IAsCrB,cAAc,CAAC,OAAO,cAAe,GAAG,IAAI;IAW5C,OAAO,CAAC,oBAAoB;IAuB5B,8FAA8F;IAC9F,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,IAAI;IAQZ,OAAO,IAAI,IAAI;CAOf"}
@@ -18,7 +18,6 @@ export class TaskSession {
18
18
  this.enabled = false;
19
19
  this.disposed = false;
20
20
  this.generation = 0;
21
- this.waitInterrupt = new AbortController();
22
21
  this.contextReminder = new TaskContextReminder();
23
22
  this.quarantine = [];
24
23
  this.changeListeners = new Set();
@@ -59,12 +58,6 @@ export class TaskSession {
59
58
  get service() {
60
59
  return this._service;
61
60
  }
62
- /** End only current task waits; the next wait observes a fresh signal. */
63
- interruptWaits() {
64
- const previous = this.waitInterrupt;
65
- this.waitInterrupt = new AbortController();
66
- previous.abort();
67
- }
68
61
  /** The active tools changed: availability of background detaching may have too. */
69
62
  toolsChanged() {
70
63
  this.service.refresh();
@@ -130,7 +123,6 @@ export class TaskSession {
130
123
  const generation = ++this.generation;
131
124
  const sessionId = manager.getSessionId();
132
125
  const sessionFile = manager.getSessionFile();
133
- const interrupts = () => this.waitInterrupt.signal;
134
126
  const service = new TaskRuntime({
135
127
  enabled: this.enabled,
136
128
  backgroundAllowed,
@@ -138,13 +130,6 @@ export class TaskSession {
138
130
  session: {
139
131
  stoppedByTreeNavigation: (targetId) => this.stoppedByTreeNavigation(targetId, service),
140
132
  },
141
- waits: {
142
- get interruptSignal() {
143
- return interrupts();
144
- },
145
- hold: (taskIds) => this.delivery.hold(taskIds),
146
- bind: (toolCallId, taskId) => this.delivery.bindWait(toolCallId, taskId),
147
- },
148
133
  anchor: () => manager.getLeafId(),
149
134
  onCleanupError: (message) => this.warn("task_cleanup", message),
150
135
  onClosed: () => this.delivery.discard(service),
@@ -233,7 +218,6 @@ export class TaskSession {
233
218
  dispose() {
234
219
  this.disposed = true;
235
220
  this.contextReminder.reset();
236
- this.interruptWaits();
237
221
  this.service.close();
238
222
  this.delivery.dispose();
239
223
  this.changeListeners.clear();