@astralyn/pi 1.4.5 → 1.4.7
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.
- package/CHANGELOG.md +42 -0
- package/dist/bundle/chunks/chunk-FODCTZXW.js +230 -0
- package/dist/bundle/chunks/{chunk-I5S7H7GA.js → chunk-FYKNSJG6.js} +1 -1
- package/dist/bundle/chunks/{chunk-AXFWZIHH.js → chunk-MG5XDTXV.js} +1 -1
- package/dist/bundle/chunks/{chunk-ALHAFUHP.js → chunk-PU2IWWXV.js} +1 -1
- package/dist/bundle/chunks/{chunk-5M3YJ54Z.js → chunk-RO2VH6UZ.js} +1 -1
- package/dist/bundle/chunks/chunk-YJTSOLP2.js +1499 -0
- package/dist/bundle/chunks/{cli-FH77R7JR.js → cli-MEL7SGJD.js} +1 -1
- package/dist/bundle/chunks/{execute-GMFGC27P.js → execute-4CWRNHPO.js} +1 -1
- package/dist/bundle/chunks/{runtime-R5CMHJ5P.js → runtime-R3X67XMR.js} +1 -1
- package/dist/bundle/chunks/{virtual-modules-6FUV7ZDV.js → virtual-modules-PKEOKGYI.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/index.js +1 -1
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/core/agent-session.d.ts +0 -3
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +0 -4
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/extensions/index.d.ts +1 -1
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/isolated-session.d.ts +23 -0
- package/dist/core/isolated-session.d.ts.map +1 -0
- package/dist/core/isolated-session.js +55 -0
- package/dist/core/isolated-session.js.map +1 -0
- package/dist/core/package-manager.d.ts +7 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +72 -1
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/resource-loader.d.ts +1 -0
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +23 -7
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/settings-manager.d.ts +4 -2
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +11 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-schema.d.ts +7 -0
- package/dist/core/settings-schema.d.ts.map +1 -1
- package/dist/core/settings-schema.js +6 -0
- package/dist/core/settings-schema.js.map +1 -1
- package/dist/core/skills.d.ts +10 -0
- package/dist/core/skills.d.ts.map +1 -1
- package/dist/core/skills.js +23 -0
- package/dist/core/skills.js.map +1 -1
- package/dist/core/tasks/codec.d.ts +12 -0
- package/dist/core/tasks/codec.d.ts.map +1 -0
- package/dist/core/tasks/codec.js +139 -0
- package/dist/core/tasks/codec.js.map +1 -0
- package/dist/core/tasks/delivery.d.ts +11 -4
- package/dist/core/tasks/delivery.d.ts.map +1 -1
- package/dist/core/tasks/delivery.js +9 -9
- package/dist/core/tasks/delivery.js.map +1 -1
- package/dist/core/tasks/execution.d.ts +71 -0
- package/dist/core/tasks/execution.d.ts.map +1 -0
- package/dist/core/tasks/execution.js +292 -0
- package/dist/core/tasks/execution.js.map +1 -0
- package/dist/core/tasks/format.d.ts +0 -2
- package/dist/core/tasks/format.d.ts.map +1 -1
- package/dist/core/tasks/format.js +1 -16
- package/dist/core/tasks/format.js.map +1 -1
- package/dist/core/tasks/limits.d.ts +12 -1
- package/dist/core/tasks/limits.d.ts.map +1 -1
- package/dist/core/tasks/limits.js +20 -1
- package/dist/core/tasks/limits.js.map +1 -1
- package/dist/core/tasks/output.d.ts +17 -17
- package/dist/core/tasks/output.d.ts.map +1 -1
- package/dist/core/tasks/output.js +72 -69
- package/dist/core/tasks/output.js.map +1 -1
- package/dist/core/tasks/presentation.d.ts +14 -5
- package/dist/core/tasks/presentation.d.ts.map +1 -1
- package/dist/core/tasks/presentation.js +56 -185
- package/dist/core/tasks/presentation.js.map +1 -1
- package/dist/core/tasks/record.d.ts +45 -0
- package/dist/core/tasks/record.d.ts.map +1 -0
- package/dist/core/tasks/record.js +80 -0
- package/dist/core/tasks/record.js.map +1 -0
- package/dist/core/tasks/runtime.d.ts +22 -22
- package/dist/core/tasks/runtime.d.ts.map +1 -1
- package/dist/core/tasks/runtime.js +170 -343
- package/dist/core/tasks/runtime.js.map +1 -1
- package/dist/core/tasks/scheduler.d.ts +16 -0
- package/dist/core/tasks/scheduler.d.ts.map +1 -0
- package/dist/core/tasks/scheduler.js +42 -0
- package/dist/core/tasks/scheduler.js.map +1 -0
- package/dist/core/tasks/session.d.ts +1 -1
- package/dist/core/tasks/session.d.ts.map +1 -1
- package/dist/core/tasks/session.js +22 -35
- package/dist/core/tasks/session.js.map +1 -1
- package/dist/core/tasks/store.d.ts +18 -25
- package/dist/core/tasks/store.d.ts.map +1 -1
- package/dist/core/tasks/store.js +45 -43
- package/dist/core/tasks/store.js.map +1 -1
- package/dist/core/tasks/types.d.ts +159 -70
- package/dist/core/tasks/types.d.ts.map +1 -1
- package/dist/core/tasks/types.js +3 -9
- package/dist/core/tasks/types.js.map +1 -1
- package/dist/core/tools/shell-execution.d.ts +8 -7
- package/dist/core/tools/shell-execution.d.ts.map +1 -1
- package/dist/core/tools/shell-execution.js +19 -27
- package/dist/core/tools/shell-execution.js.map +1 -1
- package/dist/core/tools/shell-tool.d.ts.map +1 -1
- package/dist/core/tools/shell-tool.js +42 -47
- package/dist/core/tools/shell-tool.js.map +1 -1
- package/dist/core/usage-totals.d.ts +4 -3
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +32 -8
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/agent/activity.d.ts +4 -4
- package/dist/extensions/agent/activity.d.ts.map +1 -1
- package/dist/extensions/agent/activity.js +15 -24
- package/dist/extensions/agent/activity.js.map +1 -1
- package/dist/extensions/agent/index.d.ts +2 -11
- package/dist/extensions/agent/index.d.ts.map +1 -1
- package/dist/extensions/agent/index.js +3 -88
- package/dist/extensions/agent/index.js.map +1 -1
- package/dist/extensions/agent/progress.d.ts +31 -0
- package/dist/extensions/agent/progress.d.ts.map +1 -0
- package/dist/extensions/agent/progress.js +135 -0
- package/dist/extensions/agent/progress.js.map +1 -0
- package/dist/extensions/agent/render.d.ts.map +1 -1
- package/dist/extensions/agent/render.js +8 -17
- package/dist/extensions/agent/render.js.map +1 -1
- package/dist/extensions/agent/report.d.ts +9 -0
- package/dist/extensions/agent/report.d.ts.map +1 -0
- package/dist/extensions/agent/report.js +40 -0
- package/dist/extensions/agent/report.js.map +1 -0
- package/dist/extensions/agent/settings-panel.d.ts +43 -0
- package/dist/extensions/agent/settings-panel.d.ts.map +1 -0
- package/dist/extensions/agent/settings-panel.js +125 -0
- package/dist/extensions/agent/settings-panel.js.map +1 -0
- package/dist/extensions/agent/settings.d.ts +1 -1
- package/dist/extensions/agent/settings.d.ts.map +1 -1
- package/dist/extensions/agent/settings.js +101 -83
- package/dist/extensions/agent/settings.js.map +1 -1
- package/dist/extensions/agent/tool.d.ts +13 -0
- package/dist/extensions/agent/tool.d.ts.map +1 -0
- package/dist/extensions/agent/tool.js +88 -0
- package/dist/extensions/agent/tool.js.map +1 -0
- package/dist/extensions/agent/types.d.ts +19 -21
- package/dist/extensions/agent/types.d.ts.map +1 -1
- package/dist/extensions/agent/types.js +2 -10
- package/dist/extensions/agent/types.js.map +1 -1
- package/dist/extensions/agent/worker.d.ts +16 -0
- package/dist/extensions/agent/worker.d.ts.map +1 -0
- package/dist/extensions/agent/worker.js +66 -0
- package/dist/extensions/agent/worker.js.map +1 -0
- package/dist/extensions/btw/agent.d.ts +1 -1
- package/dist/extensions/btw/agent.d.ts.map +1 -1
- package/dist/extensions/btw/agent.js +3 -20
- package/dist/extensions/btw/agent.js.map +1 -1
- package/dist/extensions/cached-compaction/index.d.ts.map +1 -1
- package/dist/extensions/cached-compaction/index.js +3 -22
- package/dist/extensions/cached-compaction/index.js.map +1 -1
- package/dist/extensions/cached-compaction/render.d.ts +1 -0
- package/dist/extensions/cached-compaction/render.d.ts.map +1 -1
- package/dist/extensions/cached-compaction/render.js +42 -14
- package/dist/extensions/cached-compaction/render.js.map +1 -1
- package/dist/extensions/deepwiki/client.d.ts.map +1 -1
- package/dist/extensions/deepwiki/client.js +6 -78
- package/dist/extensions/deepwiki/client.js.map +1 -1
- package/dist/extensions/deepwiki/transport.d.ts +3 -0
- package/dist/extensions/deepwiki/transport.d.ts.map +1 -0
- package/dist/extensions/deepwiki/transport.js +96 -0
- package/dist/extensions/deepwiki/transport.js.map +1 -0
- package/dist/extensions/provider/ui/builtin-data.d.ts +3 -3
- package/dist/extensions/provider/ui/builtin-data.d.ts.map +1 -1
- package/dist/extensions/provider/ui/builtin-data.js.map +1 -1
- package/dist/extensions/provider/ui/compat.d.ts +3 -3
- package/dist/extensions/provider/ui/compat.d.ts.map +1 -1
- package/dist/extensions/provider/ui/compat.js.map +1 -1
- package/dist/extensions/provider/ui/controls.d.ts +2 -2
- package/dist/extensions/provider/ui/controls.d.ts.map +1 -1
- package/dist/extensions/provider/ui/controls.js.map +1 -1
- package/dist/extensions/provider/ui/dialogs.d.ts +3 -3
- package/dist/extensions/provider/ui/dialogs.d.ts.map +1 -1
- package/dist/extensions/provider/ui/dialogs.js.map +1 -1
- package/dist/extensions/provider/ui/dictionary.d.ts +2 -2
- package/dist/extensions/provider/ui/dictionary.d.ts.map +1 -1
- package/dist/extensions/provider/ui/dictionary.js.map +1 -1
- package/dist/extensions/provider/ui/editor.d.ts.map +1 -1
- package/dist/extensions/provider/ui/editor.js +1 -3
- package/dist/extensions/provider/ui/editor.js.map +1 -1
- package/dist/extensions/provider/ui/fetch-models.d.ts +2 -2
- package/dist/extensions/provider/ui/fetch-models.d.ts.map +1 -1
- package/dist/extensions/provider/ui/fetch-models.js.map +1 -1
- package/dist/extensions/provider/ui/model-fields.d.ts +2 -2
- package/dist/extensions/provider/ui/model-fields.d.ts.map +1 -1
- package/dist/extensions/provider/ui/model-fields.js.map +1 -1
- package/dist/extensions/provider/ui/model-options.d.ts +6 -6
- package/dist/extensions/provider/ui/model-options.d.ts.map +1 -1
- package/dist/extensions/provider/ui/model-options.js.map +1 -1
- package/dist/extensions/provider/ui/pane.d.ts +21 -12
- package/dist/extensions/provider/ui/pane.d.ts.map +1 -1
- package/dist/extensions/provider/ui/pane.js.map +1 -1
- package/dist/extensions/provider/ui/provider-fields.d.ts +3 -3
- package/dist/extensions/provider/ui/provider-fields.d.ts.map +1 -1
- package/dist/extensions/provider/ui/provider-fields.js.map +1 -1
- package/dist/extensions/provider/ui/thinking-map.d.ts +2 -2
- package/dist/extensions/provider/ui/thinking-map.d.ts.map +1 -1
- package/dist/extensions/provider/ui/thinking-map.js.map +1 -1
- package/dist/extensions/run-summary/format.js +1 -1
- package/dist/extensions/run-summary/format.js.map +1 -1
- package/dist/extensions/statusline/usage.d.ts.map +1 -1
- package/dist/extensions/statusline/usage.js +2 -6
- package/dist/extensions/statusline/usage.js.map +1 -1
- package/dist/extensions/tasks/tool/actions.d.ts +1 -1
- package/dist/extensions/tasks/tool/actions.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/actions.js +50 -115
- package/dist/extensions/tasks/tool/actions.js.map +1 -1
- package/dist/extensions/tasks/tool/constants.d.ts +1 -6
- package/dist/extensions/tasks/tool/constants.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/constants.js +1 -6
- package/dist/extensions/tasks/tool/constants.js.map +1 -1
- package/dist/extensions/tasks/tool/schema.d.ts +0 -3
- package/dist/extensions/tasks/tool/schema.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/schema.js +5 -14
- package/dist/extensions/tasks/tool/schema.js.map +1 -1
- package/dist/extensions/tasks/tool/types.d.ts +2 -8
- package/dist/extensions/tasks/tool/types.d.ts.map +1 -1
- package/dist/extensions/tasks/tool/types.js +0 -2
- package/dist/extensions/tasks/tool/types.js.map +1 -1
- package/dist/extensions/tasks/tool.d.ts.map +1 -1
- package/dist/extensions/tasks/tool.js +2 -2
- package/dist/extensions/tasks/tool.js.map +1 -1
- package/dist/extensions/tasks/ui/completion-render.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/completion-render.js +46 -47
- package/dist/extensions/tasks/ui/completion-render.js.map +1 -1
- package/dist/extensions/tasks/ui/inspector.d.ts +5 -3
- package/dist/extensions/tasks/ui/inspector.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/inspector.js +18 -6
- package/dist/extensions/tasks/ui/inspector.js.map +1 -1
- package/dist/extensions/tasks/ui/layout.d.ts +7 -7
- package/dist/extensions/tasks/ui/layout.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/layout.js +118 -84
- package/dist/extensions/tasks/ui/layout.js.map +1 -1
- package/dist/extensions/tasks/ui/list.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/list.js +45 -31
- package/dist/extensions/tasks/ui/list.js.map +1 -1
- package/dist/extensions/tasks/ui/manager.d.ts +16 -7
- package/dist/extensions/tasks/ui/manager.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/manager.js +167 -129
- package/dist/extensions/tasks/ui/manager.js.map +1 -1
- package/dist/extensions/tasks/ui/model.d.ts +29 -0
- package/dist/extensions/tasks/ui/model.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/model.js +16 -1
- package/dist/extensions/tasks/ui/model.js.map +1 -1
- package/dist/extensions/tasks/ui/render.d.ts +1 -1
- package/dist/extensions/tasks/ui/render.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/render.js +12 -9
- package/dist/extensions/tasks/ui/render.js.map +1 -1
- package/dist/extensions/tasks/ui/status.d.ts +15 -0
- package/dist/extensions/tasks/ui/status.d.ts.map +1 -0
- package/dist/extensions/tasks/ui/status.js +16 -0
- package/dist/extensions/tasks/ui/status.js.map +1 -0
- package/dist/extensions/tasks/ui/tree.js +1 -1
- package/dist/extensions/tasks/ui/tree.js.map +1 -1
- package/dist/extensions/tasks/ui/views.d.ts +10 -5
- package/dist/extensions/tasks/ui/views.d.ts.map +1 -1
- package/dist/extensions/tasks/ui/views.js +61 -36
- package/dist/extensions/tasks/ui/views.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts +14 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +258 -7
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +2 -1
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +7 -4
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/status-marker.d.ts +2 -1
- package/dist/modes/interactive/components/status-marker.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-marker.js +0 -1
- package/dist/modes/interactive/components/status-marker.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +10 -3
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +7 -1
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/utils/duration.d.ts +3 -0
- package/dist/utils/duration.d.ts.map +1 -0
- package/dist/utils/duration.js +17 -0
- package/dist/utils/duration.js.map +1 -0
- package/dist/utils/number.d.ts +3 -0
- package/dist/utils/number.d.ts.map +1 -0
- package/dist/utils/number.js +5 -0
- package/dist/utils/number.js.map +1 -0
- package/docs/bundled/extensions/agent.md +14 -12
- package/docs/bundled/extensions/cached-compaction.md +13 -4
- package/docs/bundled/extensions/deepwiki.md +3 -1
- package/docs/bundled/extensions/statusline.md +1 -1
- package/docs/bundled/tasks.md +15 -14
- package/docs/extensions.md +26 -10
- package/docs/packages.md +5 -3
- package/docs/sdk.md +3 -3
- package/docs/session-format.md +28 -24
- package/docs/settings.md +11 -0
- package/docs/skills.md +23 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/schemas/settings.schema.json +36 -0
- package/dist/bundle/chunks/chunk-FSJ45CRP.js +0 -229
- package/dist/bundle/chunks/chunk-W3FIUMGM.js +0 -1501
- package/dist/core/tasks/history.d.ts +0 -4
- package/dist/core/tasks/history.d.ts.map +0 -1
- package/dist/core/tasks/history.js +0 -131
- package/dist/core/tasks/history.js.map +0 -1
- package/dist/extensions/agent/runner.d.ts +0 -24
- package/dist/extensions/agent/runner.d.ts.map +0 -1
- package/dist/extensions/agent/runner.js +0 -274
- package/dist/extensions/agent/runner.js.map +0 -1
- package/dist/extensions/deepwiki/http.d.ts +0 -13
- package/dist/extensions/deepwiki/http.d.ts.map +0 -1
- package/dist/extensions/deepwiki/http.js +0 -88
- package/dist/extensions/deepwiki/http.js.map +0 -1
- package/dist/extensions/tasks/ui/task-view.d.ts +0 -13
- package/dist/extensions/tasks/ui/task-view.d.ts.map +0 -1
- package/dist/extensions/tasks/ui/task-view.js +0 -20
- package/dist/extensions/tasks/ui/task-view.js.map +0 -1
|
@@ -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,qBAAqB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvE,OAAO,EACN,SAAS,EACT,WAAW,EACX,eAAe,EACf,YAAY,EACZ,SAAS,EACT,eAAe,EACf,gBAAgB,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,EAAE,UAAU,EAAmB,SAAS,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EACN,yBAAyB,EAIzB,kBAAkB,EAClB,eAAe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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 { Usage } from \"@earendil-works/pi-ai/compat\";\nimport { TASKS_WAIT_DEFAULT_MS, TASKS_WAIT_MAX_MS } from \"./limits.ts\";\nimport {\n\tboundText,\n\tfiniteLimit,\n\treadOutputSlice,\n\tretainResult,\n\tsliceText,\n\tTASK_INFO_BYTES,\n\tTASK_TITLE_BYTES,\n} from \"./output.ts\";\nimport { changed, snapshotOf, type TaskRecord, TaskStore } from \"./store.ts\";\nimport {\n\tTASK_BACKGROUND_REJECTION,\n\ttype TaskCompletion,\n\ttype TaskControl,\n\ttype TaskExecution,\n\tTaskExecutionError,\n\tTaskLookupError,\n\ttype TaskMode,\n\ttype TaskRead,\n\ttype TaskRuntimeOptions,\n\ttype TaskSnapshot,\n\ttype TasksContext,\n\ttype TaskToolOutcome,\n} from \"./types.ts\";\n\ninterface ActiveTask {\n\tcontroller: AbortController;\n\taccepted: boolean;\n\thandedOff: boolean;\n\tdetachRequested: boolean;\n\tpublishedUsage?: Usage;\n\tmodeListeners: Set<(mode: TaskMode) => void>;\n\tremoveParent(): void;\n\thandoff(): void;\n\tdone: Promise<void>;\n}\n\nfunction errorText(error: unknown): string {\n\ttry {\n\t\treturn boundText(error instanceof Error ? error.message : String(error), 4096);\n\t} catch {\n\t\treturn \"Task execution failed (unprintable error)\";\n\t}\n}\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, ActiveTask>();\n\tprivate readonly listeners = new Set<() => void>();\n\tprivate readonly maxActive: number;\n\tprivate readonly maxHistory: number;\n\tprivate readonly maxRetained: number;\n\tprivate configuredEnabled: boolean;\n\tprivate _closed = false;\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\tprivate pauses = 0;\n\n\tprivate readonly options: TaskRuntimeOptions;\n\n\tconstructor(options: TaskRuntimeOptions = {}) {\n\t\tthis.options = options;\n\t\tthis.configuredEnabled = options.enabled ?? false;\n\t\tthis.maxActive = Math.max(1, finiteLimit(options.maxActive, 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.maxActive + 2 * Math.max(1, this.maxHistory) + this.maxHistory;\n\t\tthis.store = new TaskStore(this.maxHistory, this.maxRetained, () => this.closed, options.onCleanupError);\n\t}\n\n\t/**\n\t * Rehydrate terminal version-2 custom data only, newest endedAt in each history\n\t * (later input wins 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/** Foreground work is bounded by its caller; only background work holds a slot. */\n\tprivate backgroundActive(): number {\n\t\tlet count = 0;\n\t\tfor (const record of this.store.records.values())\n\t\t\tif (!record.settled && record.task.mode === \"background\") count++;\n\t\treturn count;\n\t}\n\n\tprivate limitError(): Error {\n\t\treturn new Error(\n\t\t\t`Background task limit reached (${this.maxActive}); 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.backgroundActive() >= this.maxActive) throw this.limitError();\n\t\t\tif (this.store.records.size + this.store.cleanups.size >= 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 pinned or claimed records\",\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 (!/^[a-z][a-z0-9-]{0,63}$/.test(execution.kind)) throw new Error(\"Invalid task source\");\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 info = execution.info === undefined ? undefined : boundText(execution.info, TASK_INFO_BYTES);\n\t\tconst task: TaskSnapshot = {\n\t\t\tid: `${execution.kind}-${randomUUID()}`,\n\t\t\tkind: execution.kind,\n\t\t\ttitle: boundText(execution.title, TASK_TITLE_BYTES),\n\t\t\ttoolCallId: boundText(execution.toolCallId, 512),\n\t\t\tanchorId,\n\t\t\tmode: execution.background ? \"background\" : \"foreground\",\n\t\t\tstatus: \"queued\",\n\t\t\tstartedAt: Date.now(),\n\t\t\tcommand: execution.command === undefined ? undefined : boundText(execution.command, 8192),\n\t\t\tcommandTruncated:\n\t\t\t\texecution.command === undefined ? undefined : boundText(execution.command, 8192) !== execution.command,\n\t\t\tcwd: execution.cwd === undefined ? undefined : boundText(execution.cwd, 4096),\n\t\t\tinfo: info === undefined ? undefined : { text: info, truncated: info !== execution.info },\n\t\t};\n\t\tlet resolveCaller!: (outcome: TaskToolOutcome<T>) => void;\n\t\tlet rejectCaller!: (error: unknown) => void;\n\t\tconst caller = new Promise<TaskToolOutcome<T>>((resolve, reject) => {\n\t\t\tresolveCaller = resolve;\n\t\t\trejectCaller = reject;\n\t\t});\n\t\tlet resolveDone!: () => void;\n\t\tconst record: TaskRecord = {\n\t\t\ttask,\n\t\t\tsettled: false,\n\t\t\tvisible: true,\n\t\t\tdelivery: \"none\",\n\t\t\tpins: 0,\n\t\t\tdeliveryHolds: 0,\n\t\t\twaiters: new Set(),\n\t\t};\n\t\tconst active: ActiveTask = {\n\t\t\tcontroller: new AbortController(),\n\t\t\taccepted: false,\n\t\t\thandedOff: false,\n\t\t\tdetachRequested: execution.background ?? false,\n\t\t\tmodeListeners: new Set(),\n\t\t\tremoveParent: () => {},\n\t\t\thandoff: () => {\n\t\t\t\tif (\n\t\t\t\t\t!active.accepted ||\n\t\t\t\t\t!active.detachRequested ||\n\t\t\t\t\trecord.settled ||\n\t\t\t\t\tactive.handedOff ||\n\t\t\t\t\tthis.closed ||\n\t\t\t\t\t!record.visible ||\n\t\t\t\t\tactive.controller.signal.aborted\n\t\t\t\t)\n\t\t\t\t\treturn;\n\t\t\t\tactive.handedOff = true;\n\t\t\t\ttask.mode = \"background\";\n\t\t\t\tchanged(record);\n\t\t\t\tactive.removeParent();\n\t\t\t\tresolveCaller({ kind: \"background\", task: snapshotOf(record) });\n\t\t\t\tthis.emit();\n\t\t\t},\n\t\t\tdone: new Promise<void>((resolve) => {\n\t\t\t\tresolveDone = resolve;\n\t\t\t}),\n\t\t};\n\t\tconst parentSignal = execution.signal;\n\t\tlet onUpdate = execution.background ? undefined : execution.onUpdate;\n\t\tconst parentAbort = () => {\n\t\t\tif (!active.detachRequested || !active.accepted) this.cancel(record);\n\t\t};\n\t\tparentSignal?.addEventListener(\"abort\", parentAbort, { once: true });\n\t\tactive.removeParent = () => {\n\t\t\tparentSignal?.removeEventListener(\"abort\", parentAbort);\n\t\t\tonUpdate = undefined;\n\t\t};\n\t\tthis.store.records.set(task.id, record);\n\t\tthis.executions.set(task.id, active);\n\t\tconst control: TaskControl<T> = {\n\t\t\tid: task.id,\n\t\t\tsignal: active.controller.signal,\n\t\t\tget mode() {\n\t\t\t\treturn task.mode;\n\t\t\t},\n\t\t\tonModeChange: (listener) => {\n\t\t\t\tif (record.settled || this.closed) return () => {};\n\t\t\t\tactive.modeListeners.add(listener);\n\t\t\t\treturn () => {\n\t\t\t\t\tactive.modeListeners.delete(listener);\n\t\t\t\t};\n\t\t\t},\n\t\t\trequestCancel: () => this.cancel(record),\n\t\t\taccept: () => {\n\t\t\t\tif (record.settled || active.accepted || this.closed || active.controller.signal.aborted) return;\n\t\t\t\tactive.accepted = true;\n\t\t\t\tif (task.status === \"queued\") task.status = \"running\";\n\t\t\t\tchanged(record);\n\t\t\t\tif (active.detachRequested) active.removeParent();\n\t\t\t\t// Let an already available final result win over a handoff.\n\t\t\t\tqueueMicrotask(() => queueMicrotask(active.handoff));\n\t\t\t\tthis.emit();\n\t\t\t},\n\t\t\tpublish: (result) => {\n\t\t\t\tif (record.settled || this.closed) return;\n\t\t\t\tretainResult(task, result);\n\t\t\t\tchanged(record);\n\t\t\t\tif (result.usage !== undefined) active.publishedUsage = structuredClone(result.usage);\n\t\t\t\tif (!active.detachRequested && !active.handedOff) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tonUpdate?.(result);\n\t\t\t\t\t} catch {\n\t\t\t\t\t\t/* UI observers cannot stop execution. */\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.emit();\n\t\t\t},\n\t\t\tsetOutputPath: (path, cleanup) => {\n\t\t\t\tif (record.settled) {\n\t\t\t\t\tif (cleanup) throw new Error(\"Task execution has settled\");\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tif (record.cleanup) throw new Error(\"Managed output is already registered\");\n\t\t\t\t// Never truncate a real filesystem path into a different path.\n\t\t\t\tif (Buffer.byteLength(path) > 8192) throw new Error(\"Task output path is too large\");\n\t\t\t\trecord.cleanup = cleanup;\n\t\t\t\ttask.outputPath = path;\n\t\t\t\tchanged(record);\n\t\t\t\tthis.emit();\n\t\t\t},\n\t\t};\n\t\tconst finish = (completion: TaskCompletion<T> | undefined, error?: unknown) => {\n\t\t\tif (record.settled) return;\n\t\t\trecord.settled = true;\n\t\t\tactive.modeListeners.clear();\n\t\t\tactive.removeParent();\n\t\t\ttask.endedAt = Date.now();\n\t\t\tconst failed = completion === undefined;\n\t\t\ttask.status =\n\t\t\t\tcompletion?.status ??\n\t\t\t\t(error instanceof TaskExecutionError\n\t\t\t\t\t? error.status\n\t\t\t\t\t: active.controller.signal.aborted\n\t\t\t\t\t\t? \"cancelled\"\n\t\t\t\t\t\t: failed\n\t\t\t\t\t\t\t? \"failed\"\n\t\t\t\t\t\t\t: \"completed\");\n\t\t\tif (completion) {\n\t\t\t\tretainResult(task, completion.result);\n\t\t\t\tif (completion.error !== undefined) task.error = boundText(completion.error, 4096);\n\t\t\t\tif (completion.exitCode !== undefined) task.exitCode = completion.exitCode;\n\t\t\t}\n\t\t\tif (failed) {\n\t\t\t\ttask.error = errorText(error);\n\t\t\t\tretainResult(\n\t\t\t\t\ttask,\n\t\t\t\t\t{ content: [{ type: \"text\", text: task.error }, ...(task.result?.content ?? [])], details: undefined },\n\t\t\t\t\ttask.resultTruncated,\n\t\t\t\t);\n\t\t\t}\n\t\t\tchanged(record);\n\t\t\tlet settlementWarning: string | undefined;\n\t\t\ttry {\n\t\t\t\tthis.options.onSettled?.(\n\t\t\t\t\tsnapshotOf(record),\n\t\t\t\t\tcompletion?.usage ?? completion?.result.usage ?? active.publishedUsage,\n\t\t\t\t);\n\t\t\t} catch (accountingError) {\n\t\t\t\tconst warning = `Usage settlement failed: ${errorText(accountingError)}`;\n\t\t\t\tsettlementWarning = warning;\n\t\t\t\ttask.error = boundText([task.error, warning].filter(Boolean).join(\"\\n\"), 8192);\n\t\t\t\tretainResult(\n\t\t\t\t\ttask,\n\t\t\t\t\t{ content: [{ type: \"text\", text: warning }, ...(task.result?.content ?? [])], details: undefined },\n\t\t\t\t\ttask.resultTruncated,\n\t\t\t\t);\n\t\t\t\tchanged(record);\n\t\t\t}\n\t\t\tactive.publishedUsage = undefined;\n\t\t\t// Delivery becomes eligible only after settlement is persisted.\n\t\t\trecord.delivery = active.handedOff ? \"pending\" : \"delivered\";\n\t\t\tif (!active.handedOff) {\n\t\t\t\tif (failed) rejectCaller(error);\n\t\t\t\telse {\n\t\t\t\t\tconst { usage: _usage, ...result } = completion.result;\n\t\t\t\t\tif (settlementWarning) result.content = [{ type: \"text\", text: settlementWarning }, ...result.content];\n\t\t\t\t\tresolveCaller({ kind: \"result\", result, status: task.status, error: task.error });\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const waiter of [...record.waiters]) waiter();\n\t\t\tresolveDone();\n\t\t\tthis.executions.delete(task.id);\n\t\t\tthis.store.trim();\n\t\t\tthis.emit();\n\t\t};\n\t\t// The rejection handler is installed immediately, including for synchronous preflight throws.\n\t\ttry {\n\t\t\tconst running = execution.run(control);\n\t\t\tvoid Promise.resolve(running).then(\n\t\t\t\t(result) => finish(result),\n\t\t\t\t(error: unknown) => finish(undefined, error),\n\t\t\t);\n\t\t} catch (error) {\n\t\t\tfinish(undefined, error);\n\t\t}\n\t\tthis.emit();\n\t\treturn caller;\n\t}\n\n\tprivate detachable(record: TaskRecord): boolean {\n\t\tconst active = this.executions.get(record.task.id);\n\t\treturn !!active && !record.settled && !active.detachRequested && !active.controller.signal.aborted;\n\t}\n\n\tdetachForeground(): number {\n\t\tif (!this.enabled) return 0;\n\t\tconst eligible = [...this.store.records.values()]\n\t\t\t.filter((record) => this.detachable(record))\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.maxActive - this.backgroundActive();\n\t\tif (free <= 0) throw this.limitError();\n\t\tconst records = eligible.slice(0, free);\n\t\tfor (const record of records) this.prepareDetach(record);\n\t\tfor (const record of records) this.finishDetach(record);\n\t\tthis.emit();\n\t\treturn records.length;\n\t}\n\n\tcanDetach(id: string): boolean {\n\t\tconst record = this.lookup(id);\n\t\treturn this.enabled && this.backgroundActive() < this.maxActive && this.detachable(record);\n\t}\n\n\tdetach(id: string): boolean {\n\t\tconst record = this.lookup(id);\n\t\tif (!this.enabled || !this.detachable(record)) return false;\n\t\tif (this.backgroundActive() >= this.maxActive) throw this.limitError();\n\t\tthis.prepareDetach(record);\n\t\tthis.finishDetach(record);\n\t\tthis.emit();\n\t\treturn true;\n\t}\n\n\tprivate prepareDetach(record: TaskRecord): void {\n\t\tconst active = this.executions.get(record.task.id)!;\n\t\tactive.detachRequested = true;\n\t\trecord.task.mode = \"background\";\n\t\tchanged(record);\n\t\tif (active.accepted) active.removeParent();\n\t}\n\n\tprivate finishDetach(record: TaskRecord): void {\n\t\tconst active = this.executions.get(record.task.id)!;\n\t\tactive.handoff();\n\t\tfor (const listener of active.modeListeners) {\n\t\t\ttry {\n\t\t\t\tlistener(record.task.mode);\n\t\t\t} catch {\n\t\t\t\t/* Executors own their diagnostics. */\n\t\t\t}\n\t\t}\n\t}\n\n\tlist(): TaskSnapshot[] {\n\t\treturn [...this.store.records.values()].filter((record) => record.visible).map(snapshotOf);\n\t}\n\n\tprivate lookup(id: string): TaskRecord {\n\t\tconst exact = this.store.records.get(id);\n\t\tif (exact) return exact;\n\t\tconst matches = [...this.store.records.values()].filter(\n\t\t\t({ task }) => task.id.startsWith(id) || task.id.slice(task.kind.length + 1).startsWith(id),\n\t\t);\n\t\tif (!id || matches.length !== 1) {\n\t\t\tthrow new TaskLookupError(matches.length > 1 ? \"ambiguous\" : \"unknown\", matches.map(snapshotOf));\n\t\t}\n\t\treturn matches[0]!;\n\t}\n\n\tget(id: string): TaskSnapshot {\n\t\treturn snapshotOf(this.lookup(id));\n\t}\n\n\tasync read(\n\t\tid: string,\n\t\toptions: { mode?: \"head\" | \"tail\"; bytes?: number; sinceBytes?: number } = {},\n\t): 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 = snapshotOf(record);\n\t\t\tif (task.outputPath) {\n\t\t\t\ttry {\n\t\t\t\t\treturn { task, ...(await readOutputSlice(task.outputPath, options)) };\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), options),\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), options) };\n\t\t} finally {\n\t\t\trelease();\n\t\t}\n\t}\n\n\tprivate resultText(task: TaskSnapshot): string {\n\t\treturn boundText(\n\t\t\ttask.result?.content\n\t\t\t\t.filter((block) => block.type === \"text\")\n\t\t\t\t.map((block) => block.text)\n\t\t\t\t.join(\"\\n\") ||\n\t\t\t\ttask.error ||\n\t\t\t\t\"No output yet.\",\n\t\t);\n\t}\n\n\t/** One event-driven waiter can observe a whole waitAny cohort without per-task timers. */\n\tprivate waitForRecords(\n\t\trecords: readonly TaskRecord[],\n\t\ttimeoutMs: number,\n\t\tsignal?: AbortSignal,\n\t\tinterruptSignal?: AbortSignal,\n\t): Promise<void> {\n\t\tif (records.some((record) => record.settled) || interruptSignal?.aborted) return Promise.resolve();\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet finished = false;\n\t\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t\tconst complete = (aborted = false) => {\n\t\t\t\tif (finished) return;\n\t\t\t\tfinished = true;\n\t\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\t\tinterruptSignal?.removeEventListener(\"abort\", interrupt);\n\t\t\t\tfor (const record of records) record.waiters.delete(wake);\n\t\t\t\tif (aborted) reject(signal?.reason ?? new Error(\"Wait aborted\"));\n\t\t\t\telse resolve();\n\t\t\t\tthis.store.trim();\n\t\t\t\tthis.emit();\n\t\t\t};\n\t\t\tconst wake = () => complete();\n\t\t\tconst abort = () => complete(true);\n\t\t\tconst interrupt = () => complete();\n\t\t\tfor (const record of records) record.waiters.add(wake);\n\t\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\t\tinterruptSignal?.addEventListener(\"abort\", interrupt, { once: true });\n\t\t\ttimer = setTimeout(wake, finiteLimit(timeoutMs, TASKS_WAIT_DEFAULT_MS, TASKS_WAIT_MAX_MS));\n\t\t\tif (this.closed || interruptSignal?.aborted) wake();\n\t\t\tif (signal?.aborted) abort();\n\t\t});\n\t}\n\n\t/** Observe completion without consuming delivery; the host acknowledges only persisted tool results. */\n\tasync wait(\n\t\tid: string,\n\t\ttimeoutMs = TASKS_WAIT_DEFAULT_MS,\n\t\tsignal?: AbortSignal,\n\t\tinterruptSignal?: AbortSignal,\n\t): Promise<TaskSnapshot> {\n\t\tif (signal?.aborted) throw signal.reason ?? new Error(\"Wait aborted\");\n\t\tconst record = this.lookup(id);\n\t\tif (record.settled) return snapshotOf(record);\n\t\tawait this.waitForRecords([record], timeoutMs, signal, interruptSignal);\n\t\treturn snapshotOf(record);\n\t}\n\n\tasync waitAny(\n\t\ttimeoutMs = TASKS_WAIT_DEFAULT_MS,\n\t\tsignal?: AbortSignal,\n\t\tinterruptSignal?: AbortSignal,\n\t): Promise<TaskSnapshot | undefined> {\n\t\tif (signal?.aborted) throw signal.reason ?? new Error(\"Wait aborted\");\n\t\tconst records = [...this.store.records.values()].filter(\n\t\t\t(record) => record.visible && record.task.mode === \"background\" && !record.settled,\n\t\t);\n\t\tif (records.length === 0 || interruptSignal?.aborted) return undefined;\n\t\tawait this.waitForRecords(records, timeoutMs, signal, interruptSignal);\n\t\tconst settled = records\n\t\t\t.filter((record) => record.settled)\n\t\t\t.sort((left, right) => (left.task.endedAt ?? 0) - (right.task.endedAt ?? 0))[0];\n\t\treturn settled ? snapshotOf(settled) : undefined;\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\tconst active = this.executions.get(record.task.id);\n\t\tif (!active || record.settled || active.controller.signal.aborted) return false;\n\t\trecord.task.status = \"stopping\";\n\t\tchanged(record);\n\t\tactive.controller.abort();\n\t\tthis.emit();\n\t\treturn true;\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/**\n\t * Retention protects snapshots and logs only. Delivery has its own explicit hold.\n\t */\n\tretain(id: string): () => void {\n\t\tconst record = this.lookup(id);\n\t\trecord.pins++;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\trecord.pins--;\n\t\t\tthis.store.trim();\n\t\t\tif (!this.closed && this.pauses === 0 && this.candidate(record)) this.emit();\n\t\t};\n\t}\n\n\tholdDelivery(id: string): () => void {\n\t\tconst record = this.lookup(id);\n\t\tconst releaseRetention = this.retain(id);\n\t\trecord.deliveryHolds++;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\trecord.deliveryHolds--;\n\t\t\treleaseRetention();\n\t\t};\n\t}\n\n\tpause(): () => void {\n\t\tthis.pauses++;\n\t\tlet resumed = false;\n\t\treturn () => {\n\t\t\tif (resumed) return;\n\t\t\tresumed = true;\n\t\t\tthis.pauses--;\n\t\t\tthis.emit();\n\t\t};\n\t}\n\n\tpendingNotifications(): TaskSnapshot[] {\n\t\tif (this.closed || this.pauses > 0) return [];\n\t\treturn [...this.store.records.values()].filter((record) => this.candidate(record)).map(snapshotOf);\n\t}\n\n\t/** Only explicit result-delivery holds delay an automatic completion. */\n\tprivate candidate(record: TaskRecord): boolean {\n\t\treturn record.visible && record.delivery === \"pending\" && record.waiters.size === 0 && record.deliveryHolds === 0;\n\t}\n\n\tclaimNotification(id: string): boolean {\n\t\tif (this.closed || this.pauses > 0) return false;\n\t\tconst record = this.store.records.get(id);\n\t\tif (!record || !this.candidate(record)) return false;\n\t\trecord.delivery = \"claimed\";\n\t\treturn true;\n\t}\n\n\tmarkDelivered(id: string): void {\n\t\tconst record = this.store.records.get(id);\n\t\tif (!record) return;\n\t\trecord.delivery = \"delivered\";\n\t\tthis.store.trim();\n\t}\n\n\treleaseNotification(id: string): void {\n\t\tconst record = this.store.records.get(id);\n\t\tif (!record || record.delivery !== \"claimed\") return;\n\t\trecord.delivery = \"pending\";\n\t\tthis.store.trim();\n\t\tthis.emit();\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.records.values()) {\n\t\t\tthis.executions.get(record.task.id)?.removeParent();\n\t\t\tthis.cancel(record);\n\t\t\tfor (const waiter of [...record.waiters]) waiter();\n\t\t}\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.records.values()], 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.records.values()]\n\t\t\t.filter((record) => !record.settled && record.task.anchorId !== null && !ancestors.has(record.task.anchorId))\n\t\t\t.map(snapshotOf);\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\tfor (const record of this.store.records.values())\n\t\t\trecord.visible = record.task.anchorId === null || ancestors.has(record.task.anchorId);\n\t\tconst outside = [...this.store.records.values()].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\tPromise.all(this.store.cleanups),\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;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAsB,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACjE,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,OAA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E,CAAC;QAClB,IAAI,CAAC,IAAI,EAAE,CAAC;QACZ,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IAEO,KAAK,CAAC,KAAK,CAAC,OAAqB,EAAE,OAAe;QACzD,IAAI,KAAgD,CAAC;QACrD,IAAI,CAAC;YACJ,MAAM,OAAO,CAAC,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 { finiteLimit } from \"../../utils/number.ts\";\nimport { Execution, type ExecutionHost } from \"./execution.ts\";\nimport { boundWaitMs, 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\ttype TaskDeliveryLedger,\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\";\n\n/** Session-local supervision. Executors own their processes, items and output files. */\nexport class TaskRuntime implements TasksContext, TaskDeliveryLedger {\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/** Foreground work is bounded by its caller; only background work, queued or running, holds a slot. */\n\tprivate activeBackground(): TaskRecord[] {\n\t\treturn this.store.unsettled().filter((record) => record.task.mode === \"background\");\n\t}\n\n\tprivate backgroundActive(): number {\n\t\treturn this.activeBackground().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.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 pinned or claimed records\",\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: execution.background ? \"background\" : \"foreground\",\n\t\t\tstatus: \"queued\",\n\t\t\tstartedAt: Date.now(),\n\t\t};\n\t\tconst record = new TaskRecord(task);\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\tif (active.queued) active.handoff();\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.enabled) 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\tconst executions = eligible.slice(0, free);\n\t\tfor (const execution of executions) execution.requestDetach();\n\t\tfor (const execution of executions) execution.completeDetach();\n\t\tthis.emit();\n\t\treturn executions.length;\n\t}\n\n\tcanDetach(id: string): boolean {\n\t\tconst record = this.lookup(id);\n\t\treturn this.enabled && 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.enabled || !this.detachable(record)) return false;\n\t\tif (this.backgroundActive() >= this.maxBackground) throw this.limitError();\n\t\tconst execution = this.executions.get(record.task.id)!;\n\t\texecution.requestDetach();\n\t\texecution.completeDetach();\n\t\tthis.emit();\n\t\treturn true;\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\tif (task.outputPath) {\n\t\t\t\ttry {\n\t\t\t\t\treturn { task, ...(await readOutputSlice(task.outputPath, options)) };\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), options),\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), options) };\n\t\t} finally {\n\t\t\trelease();\n\t\t}\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/** One event-driven waiter can observe a whole waitAny cohort without per-task timers. */\n\tprivate waitForRecords(\n\t\trecords: readonly TaskRecord[],\n\t\ttimeoutMs: number,\n\t\tsignal?: AbortSignal,\n\t\tinterruptSignal?: AbortSignal,\n\t): Promise<void> {\n\t\tif (records.some((record) => record.settled) || interruptSignal?.aborted) return Promise.resolve();\n\t\treturn new Promise<void>((resolve, reject) => {\n\t\t\tlet finished = false;\n\t\t\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\t\t\tconst complete = (aborted = false) => {\n\t\t\t\tif (finished) return;\n\t\t\t\tfinished = true;\n\t\t\t\tif (timer !== undefined) clearTimeout(timer);\n\t\t\t\tsignal?.removeEventListener(\"abort\", abort);\n\t\t\t\tinterruptSignal?.removeEventListener(\"abort\", interrupt);\n\t\t\t\tfor (const record of records) record.waiters.delete(wake);\n\t\t\t\tif (aborted) reject(signal?.reason ?? new Error(\"Wait aborted\"));\n\t\t\t\telse resolve();\n\t\t\t\tthis.store.trim();\n\t\t\t\tthis.emit();\n\t\t\t};\n\t\t\tconst wake = () => complete();\n\t\t\tconst abort = () => complete(true);\n\t\t\tconst interrupt = () => complete();\n\t\t\tfor (const record of records) record.waiters.add(wake);\n\t\t\tsignal?.addEventListener(\"abort\", abort, { once: true });\n\t\t\tinterruptSignal?.addEventListener(\"abort\", interrupt, { once: true });\n\t\t\ttimer = setTimeout(wake, boundWaitMs(timeoutMs));\n\t\t\tif (this.closed || interruptSignal?.aborted) wake();\n\t\t\tif (signal?.aborted) abort();\n\t\t});\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\tconst releases = records.map((record) => this.holdRecord(record));\n\t\ttry {\n\t\t\tconst start = Date.now();\n\t\t\tconst interrupt = this.options.waits?.interruptSignal;\n\t\t\tawait this.waitForRecords(records, options.timeoutMs ?? TASKS_WAIT_DEFAULT_MS, signal, interrupt);\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/**\n\t * Retention protects snapshots and logs only. Delivery has its own explicit hold.\n\t */\n\tretain(id: string): () => void {\n\t\treturn this.pin(this.lookup(id));\n\t}\n\n\tprivate pin(record: TaskRecord): () => void {\n\t\trecord.pins++;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\trecord.pins--;\n\t\t\tthis.store.trim();\n\t\t\t// Listeners decide whether delivery may proceed; TaskDelivery owns pausing.\n\t\t\tif (!this.closed && record.deliverable) this.emit();\n\t\t};\n\t}\n\n\tholdDelivery(id: string): () => void {\n\t\treturn this.holdRecord(this.lookup(id));\n\t}\n\n\tprivate holdRecord(record: TaskRecord): () => void {\n\t\tconst releasePin = this.pin(record);\n\t\trecord.deliveryHolds++;\n\t\tlet released = false;\n\t\treturn () => {\n\t\t\tif (released) return;\n\t\t\treleased = true;\n\t\t\trecord.deliveryHolds--;\n\t\t\treleasePin();\n\t\t};\n\t}\n\n\tpendingNotifications(): TaskSnapshot[] {\n\t\tif (this.closed) return [];\n\t\treturn this.store.deliverable().map((record) => record.snapshot());\n\t}\n\n\tclaimNotification(id: string): boolean {\n\t\treturn !this.closed && (this.store.get(id)?.claim() ?? false);\n\t}\n\n\tmarkDelivered(id: string): void {\n\t\tconst record = this.store.get(id);\n\t\tif (!record) return;\n\t\trecord.acknowledge();\n\t\tthis.store.trim();\n\t}\n\n\treleaseNotification(id: string): void {\n\t\tif (!this.store.get(id)?.unclaim()) return;\n\t\tthis.store.trim();\n\t\tthis.emit();\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\tfor (const waiter of [...record.waiters]) waiter();\n\t\t}\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.visible = 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"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Per-key concurrency lanes. Executions without a concurrency key start immediately. */
|
|
2
|
+
export interface Schedulable {
|
|
3
|
+
readonly concurrency?: {
|
|
4
|
+
key: string;
|
|
5
|
+
limit: number;
|
|
6
|
+
};
|
|
7
|
+
start(): void;
|
|
8
|
+
}
|
|
9
|
+
export declare class TaskScheduler {
|
|
10
|
+
private readonly lanes;
|
|
11
|
+
schedule(execution: Schedulable): void;
|
|
12
|
+
/** A settled execution frees its slot or leaves the queue; the next waiting one starts. */
|
|
13
|
+
release(execution: Schedulable): void;
|
|
14
|
+
private pump;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=scheduler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/scheduler.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,MAAM,WAAW,WAAW;IAC3B,QAAQ,CAAC,WAAW,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACtD,KAAK,IAAI,IAAI,CAAC;CACd;AAOD,qBAAa,aAAa;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2B;IAEjD,QAAQ,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;IAetC,2FAA2F;IAC3F,OAAO,CAAC,SAAS,EAAE,WAAW,GAAG,IAAI;IAUrC,OAAO,CAAC,IAAI;CASZ"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class TaskScheduler {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.lanes = new Map();
|
|
4
|
+
}
|
|
5
|
+
schedule(execution) {
|
|
6
|
+
const concurrency = execution.concurrency;
|
|
7
|
+
if (!concurrency) {
|
|
8
|
+
execution.start();
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
let lane = this.lanes.get(concurrency.key);
|
|
12
|
+
if (!lane) {
|
|
13
|
+
lane = { running: new Set(), waiting: [] };
|
|
14
|
+
this.lanes.set(concurrency.key, lane);
|
|
15
|
+
}
|
|
16
|
+
lane.waiting.push(execution);
|
|
17
|
+
this.pump(concurrency.key, lane);
|
|
18
|
+
}
|
|
19
|
+
/** A settled execution frees its slot or leaves the queue; the next waiting one starts. */
|
|
20
|
+
release(execution) {
|
|
21
|
+
const key = execution.concurrency?.key;
|
|
22
|
+
const lane = key === undefined ? undefined : this.lanes.get(key);
|
|
23
|
+
if (!lane || key === undefined)
|
|
24
|
+
return;
|
|
25
|
+
lane.running.delete(execution);
|
|
26
|
+
const index = lane.waiting.indexOf(execution);
|
|
27
|
+
if (index >= 0)
|
|
28
|
+
lane.waiting.splice(index, 1);
|
|
29
|
+
this.pump(key, lane);
|
|
30
|
+
}
|
|
31
|
+
pump(key, lane) {
|
|
32
|
+
// Starting can settle synchronously and re-enter release(); the loop rereads lane state.
|
|
33
|
+
while (lane.waiting.length > 0 && lane.running.size < lane.waiting[0].concurrency.limit) {
|
|
34
|
+
const next = lane.waiting.shift();
|
|
35
|
+
lane.running.add(next);
|
|
36
|
+
next.start();
|
|
37
|
+
}
|
|
38
|
+
if (lane.running.size === 0 && lane.waiting.length === 0 && this.lanes.get(key) === lane)
|
|
39
|
+
this.lanes.delete(key);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../../../src/core/tasks/scheduler.ts"],"names":[],"mappings":"AAWA,MAAM,OAAO,aAAa;IAA1B;QACkB,UAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;IAqClD,CAAC;IAnCA,QAAQ,CAAC,SAAsB;QAC9B,MAAM,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,WAAW,EAAE,CAAC;YAClB,SAAS,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO;QACR,CAAC;QACD,IAAI,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;QAC3C,IAAI,CAAC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C,KAAK,EAAG,CAAC;YACnC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YACvB,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,IAAI;YAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAClH,CAAC;CACD","sourcesContent":["/** Per-key concurrency lanes. Executions without a concurrency key start immediately. */\nexport interface Schedulable {\n\treadonly concurrency?: { key: string; limit: number };\n\tstart(): void;\n}\n\ninterface Lane {\n\trunning: Set<Schedulable>;\n\twaiting: Schedulable[];\n}\n\nexport class TaskScheduler {\n\tprivate readonly lanes = new Map<string, Lane>();\n\n\tschedule(execution: Schedulable): void {\n\t\tconst concurrency = execution.concurrency;\n\t\tif (!concurrency) {\n\t\t\texecution.start();\n\t\t\treturn;\n\t\t}\n\t\tlet lane = this.lanes.get(concurrency.key);\n\t\tif (!lane) {\n\t\t\tlane = { running: new Set(), waiting: [] };\n\t\t\tthis.lanes.set(concurrency.key, lane);\n\t\t}\n\t\tlane.waiting.push(execution);\n\t\tthis.pump(concurrency.key, lane);\n\t}\n\n\t/** A settled execution frees its slot or leaves the queue; the next waiting one starts. */\n\trelease(execution: Schedulable): void {\n\t\tconst key = execution.concurrency?.key;\n\t\tconst lane = key === undefined ? undefined : this.lanes.get(key);\n\t\tif (!lane || key === undefined) return;\n\t\tlane.running.delete(execution);\n\t\tconst index = lane.waiting.indexOf(execution);\n\t\tif (index >= 0) lane.waiting.splice(index, 1);\n\t\tthis.pump(key, lane);\n\t}\n\n\tprivate pump(key: string, lane: Lane): void {\n\t\t// Starting can settle synchronously and re-enter release(); the loop rereads lane state.\n\t\twhile (lane.waiting.length > 0 && lane.running.size < lane.waiting[0]!.concurrency!.limit) {\n\t\t\tconst next = lane.waiting.shift()!;\n\t\t\tlane.running.add(next);\n\t\t\tnext.start();\n\t\t}\n\t\tif (lane.running.size === 0 && lane.waiting.length === 0 && this.lanes.get(key) === lane) this.lanes.delete(key);\n\t}\n}\n"]}
|
|
@@ -37,7 +37,6 @@ export declare class TaskSession {
|
|
|
37
37
|
private readonly quarantine;
|
|
38
38
|
constructor(options: TaskSessionOptions);
|
|
39
39
|
get service(): TaskRuntime;
|
|
40
|
-
get waitInterruptSignal(): AbortSignal;
|
|
41
40
|
/** End only current task waits; the next wait observes a fresh signal. */
|
|
42
41
|
interruptWaits(): void;
|
|
43
42
|
noteCompaction(): void;
|
|
@@ -59,6 +58,7 @@ export declare class TaskSession {
|
|
|
59
58
|
private createService;
|
|
60
59
|
restoreHistory(service?: TaskRuntime): void;
|
|
61
60
|
private quarantineSettlement;
|
|
61
|
+
/** One entry per settlement: the bounded terminal snapshot and its first usage settlement. */
|
|
62
62
|
private persistSettlement;
|
|
63
63
|
private warn;
|
|
64
64
|
dispose(): 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,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;
|
|
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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AAI,OAAO,IAAI,WAAW,CAEzB;IAED,0EAA0E;IAC1E,cAAc,IAAI,IAAI;IAMtB,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,2FAA2F;IAC3F,cAAc,IAAI,IAAI;IAOtB,OAAO,CAAC,aAAa;IAoCrB,cAAc,CAAC,OAAO,cAAe,GAAG,IAAI;IAW5C,OAAO,CAAC,oBAAoB;IAsB5B,8FAA8F;IAC9F,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,IAAI;IAQZ,OAAO,IAAI,IAAI;CAOf"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { appendFileSync, mkdirSync } from "node:fs";
|
|
2
2
|
import { dirname } from "node:path";
|
|
3
3
|
import { truncateHead } from "../tools/truncate.js";
|
|
4
|
-
import { getTaskUsageRecord
|
|
4
|
+
import { getTaskUsageRecord } from "../usage-totals.js";
|
|
5
|
+
import { TASK_RECORD_TYPE, TASK_SNAPSHOT_VERSION } from "./codec.js";
|
|
5
6
|
import { TaskDelivery } from "./delivery.js";
|
|
6
|
-
import { TASK_HISTORY_VERSION } from "./history.js";
|
|
7
7
|
import { TaskContextReminder } from "./reminder.js";
|
|
8
8
|
import { TaskRuntime } from "./runtime.js";
|
|
9
9
|
/** Session persistence and completion delivery; execution supervision stays in TaskRuntime. */
|
|
@@ -27,9 +27,6 @@ export class TaskSession {
|
|
|
27
27
|
get service() {
|
|
28
28
|
return this._service;
|
|
29
29
|
}
|
|
30
|
-
get waitInterruptSignal() {
|
|
31
|
-
return this.waitInterrupt.signal;
|
|
32
|
-
}
|
|
33
30
|
/** End only current task waits; the next wait observes a fresh signal. */
|
|
34
31
|
interruptWaits() {
|
|
35
32
|
const previous = this.waitInterrupt;
|
|
@@ -85,17 +82,19 @@ export class TaskSession {
|
|
|
85
82
|
const generation = ++this.generation;
|
|
86
83
|
const sessionId = manager.getSessionId();
|
|
87
84
|
const sessionFile = manager.getSessionFile();
|
|
88
|
-
const
|
|
85
|
+
const interrupts = () => this.waitInterrupt.signal;
|
|
89
86
|
const service = new TaskRuntime({
|
|
90
87
|
enabled: this.enabled,
|
|
91
88
|
backgroundAllowed,
|
|
92
89
|
session: {
|
|
93
|
-
get waitInterruptSignal() {
|
|
94
|
-
return waitInterruptSignal();
|
|
95
|
-
},
|
|
96
|
-
prepareWait: (toolCallId, taskId) => this.delivery.prepareWait(toolCallId, taskId),
|
|
97
90
|
stoppedByTreeNavigation: (targetId) => this.stoppedByTreeNavigation(targetId, service),
|
|
98
91
|
},
|
|
92
|
+
waits: {
|
|
93
|
+
get interruptSignal() {
|
|
94
|
+
return interrupts();
|
|
95
|
+
},
|
|
96
|
+
bind: (toolCallId, taskId) => this.delivery.bindWait(service, toolCallId, taskId),
|
|
97
|
+
},
|
|
99
98
|
anchor: () => manager.getLeafId(),
|
|
100
99
|
onCleanupError: (message) => this.warn("task_cleanup", message),
|
|
101
100
|
onSettled: (task, usage) => {
|
|
@@ -116,7 +115,7 @@ export class TaskSession {
|
|
|
116
115
|
const records = [];
|
|
117
116
|
const toolResults = new Map();
|
|
118
117
|
for (const entry of this.options.manager.getBranch()) {
|
|
119
|
-
if (entry.type === "custom" && entry.customType ===
|
|
118
|
+
if (entry.type === "custom" && entry.customType === TASK_RECORD_TYPE)
|
|
120
119
|
records.push(entry.data);
|
|
121
120
|
else if (entry.type === "message" && entry.message.role === "toolResult")
|
|
122
121
|
toolResults.set(entry.message.toolCallId, entry.message.content);
|
|
@@ -142,34 +141,22 @@ export class TaskSession {
|
|
|
142
141
|
}
|
|
143
142
|
this.warn("task_settlement_quarantined", `Late background settlement ${record.task.id} was quarantined. ${persistence}`);
|
|
144
143
|
}
|
|
144
|
+
/** One entry per settlement: the bounded terminal snapshot and its first usage settlement. */
|
|
145
145
|
persistSettlement(task, usage) {
|
|
146
146
|
const manager = this.options.manager;
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
147
|
+
const accounted = usage && manager.getEntries().some((entry) => getTaskUsageRecord(entry)?.taskId === task.id);
|
|
148
|
+
// A foreground result is the tool result the transcript already saves; restoration reads it from there.
|
|
149
|
+
const { result: _result, ...metadata } = task;
|
|
150
|
+
const saved = task.mode === "foreground" ? metadata : task;
|
|
151
|
+
const data = JSON.parse(JSON.stringify({ version: TASK_SNAPSHOT_VERSION, task: saved, ...(usage && !accounted ? { usage } : {}) }));
|
|
152
|
+
const entry = manager.getEntry(manager.appendCustomEntry(TASK_RECORD_TYPE, data));
|
|
153
|
+
if (!entry)
|
|
154
|
+
return;
|
|
153
155
|
try {
|
|
154
|
-
|
|
155
|
-
append(TASK_USAGE_TYPE, { version: 1, taskId: task.id, usage });
|
|
156
|
-
}
|
|
157
|
-
// A foreground result is the tool result the transcript already saves; restoration reads it from there.
|
|
158
|
-
const { result: _result, resultTruncated: _truncated, ...metadata } = task;
|
|
159
|
-
const saved = task.mode === "foreground" ? metadata : task;
|
|
160
|
-
append("task-result", JSON.parse(JSON.stringify({ version: TASK_HISTORY_VERSION, task: saved })));
|
|
156
|
+
this.options.onEntry(entry);
|
|
161
157
|
}
|
|
162
|
-
|
|
163
|
-
//
|
|
164
|
-
// If a write fails, still report entries that were successfully appended.
|
|
165
|
-
for (const entry of appended) {
|
|
166
|
-
try {
|
|
167
|
-
this.options.onEntry(entry);
|
|
168
|
-
}
|
|
169
|
-
catch {
|
|
170
|
-
// Observers cannot interrupt settlement or result publication.
|
|
171
|
-
}
|
|
172
|
-
}
|
|
158
|
+
catch {
|
|
159
|
+
// Observers cannot interrupt settlement or result publication.
|
|
173
160
|
}
|
|
174
161
|
}
|
|
175
162
|
warn(event, message) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/core/tasks/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAwB3C,+FAA+F;AAC/F,MAAM,OAAO,WAAW;IAWvB,YAAY,OAA2B;QAR/B,YAAO,GAAG,KAAK,CAAC;QAChB,aAAQ,GAAG,KAAK,CAAC;QACjB,eAAU,GAAG,CAAC,CAAC;QACf,kBAAa,GAAG,IAAI,eAAe,EAAE,CAAC;QAC7B,oBAAe,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAE5C,eAAU,GAAgC,EAAE,CAAC;QAG7D,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,CAAC;YAChC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO;YAC3B,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,IAAI,EAAE,CAAC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,OAAO,EAAE,CAAC;IACzB,CAAC;CACD","sourcesContent":["import { appendFileSync, mkdirSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport type { AgentMessage, AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport type { Usage } from \"@earendil-works/pi-ai/compat\";\nimport type { CustomMessage } from \"../messages.ts\";\nimport type { SessionEntry, SessionManager } from \"../session-manager.ts\";\nimport { truncateHead } from \"../tools/truncate.ts\";\nimport { getTaskUsageRecord, TASK_USAGE_TYPE } from \"../usage-totals.ts\";\nimport { TaskDelivery } from \"./delivery.ts\";\nimport { TASK_HISTORY_VERSION } from \"./history.ts\";\nimport { TaskContextReminder } from \"./reminder.ts\";\nimport { TaskRuntime } from \"./runtime.ts\";\nimport type { TaskSnapshot } from \"./types.ts\";\n\ninterface TaskSessionOptions {\n\tmanager: SessionManager;\n\tbackgroundAllowed?: boolean;\n\t/** The main session owns input queues, preflight and idle state. */\n\tcanDeliver(): boolean;\n\t/**\n\t * Start a completion turn, or enqueue the message and return waitForPersistence().\n\t * The host owns input routing; this adapter owns the queued delivery's lifetime.\n\t */\n\tdeliver(message: CustomMessage, waitForPersistence: () => Promise<void>): Promise<void>;\n\tonEntry(entry: SessionEntry): void;\n\tonError(event: string, message: string): void;\n}\n\nexport interface QuarantinedTaskSettlement {\n\tsessionId: string;\n\tgeneration: number;\n\ttask: TaskSnapshot;\n\tusage?: Usage;\n}\n\n/** Session persistence and completion delivery; execution supervision stays in TaskRuntime. */\nexport class TaskSession {\n\tprivate readonly options: TaskSessionOptions;\n\tprivate _service: TaskRuntime;\n\tprivate enabled = false;\n\tprivate disposed = false;\n\tprivate generation = 0;\n\tprivate waitInterrupt = new AbortController();\n\tprivate readonly contextReminder = new TaskContextReminder();\n\treadonly delivery: TaskDelivery;\n\tprivate readonly quarantine: QuarantinedTaskSettlement[] = [];\n\n\tconstructor(options: TaskSessionOptions) {\n\t\tthis.options = options;\n\t\tthis.delivery = new TaskDelivery({\n\t\t\tservice: () => this.service,\n\t\t\tcanDeliver: options.canDeliver,\n\t\t\tdeliver: options.deliver,\n\t\t\twarn: (event, message) => this.warn(event, message),\n\t\t});\n\t\tthis._service = this.createService();\n\t}\n\n\tget service(): TaskRuntime {\n\t\treturn this._service;\n\t}\n\n\tget waitInterruptSignal(): AbortSignal {\n\t\treturn this.waitInterrupt.signal;\n\t}\n\n\t/** End only current task waits; the next wait observes a fresh signal. */\n\tinterruptWaits(): void {\n\t\tconst previous = this.waitInterrupt;\n\t\tthis.waitInterrupt = new AbortController();\n\t\tprevious.abort();\n\t}\n\n\tnoteCompaction(): void {\n\t\tthis.contextReminder.compacted();\n\t}\n\n\tprojectContextReminder(messages: AgentMessage[]): AgentMessage[] {\n\t\treturn this.contextReminder.project(this.service, messages);\n\t}\n\n\tnoteAssistantCompleted(): void {\n\t\tthis.contextReminder.assistantCompleted();\n\t}\n\n\tget quarantinedSettlements(): readonly QuarantinedTaskSettlement[] {\n\t\treturn structuredClone(this.quarantine);\n\t}\n\n\tsetEnabled(enabled: boolean): void {\n\t\tthis.enabled = enabled && this.options.backgroundAllowed !== false;\n\t\tthis.service.setEnabled(this.enabled);\n\t}\n\n\t/**\n\t * Running tasks that navigating to `targetId` would cancel, since results are saved on their\n\t * launch branch. Mirrors navigateTree's destination: selecting a user or custom message moves\n\t * the leaf to its parent.\n\t */\n\tstoppedByTreeNavigation(targetId: string, service = this.service): TaskSnapshot[] {\n\t\tconst target = this.options.manager.getEntry(targetId);\n\t\tif (!target) return [];\n\t\tconst leafId =\n\t\t\t(target.type === \"message\" && target.message.role === \"user\") || target.type === \"custom_message\"\n\t\t\t\t? target.parentId\n\t\t\t\t: targetId;\n\t\treturn service.activeOutsideBranch(this.branchIds(leafId));\n\t}\n\n\t/** Cancel running tasks launched outside the branch ending at `leafId`. */\n\tcancelOutsideBranch(leafId: string | null): Promise<void> {\n\t\treturn this.service.cancelOutsideBranch(this.branchIds(leafId));\n\t}\n\n\tprivate branchIds(leafId: string | null): Set<string> {\n\t\treturn new Set(leafId === null ? [] : this.options.manager.getBranch(leafId).map((entry) => entry.id));\n\t}\n\n\t/** Called after the old service's bounded shutdown, while lifecycle delivery is paused. */\n\treplaceService(): void {\n\t\tthis.contextReminder.reset();\n\t\tthis.service.close();\n\t\tthis._service = this.createService();\n\t\tthis.delivery.retry();\n\t}\n\n\tprivate createService(): TaskRuntime {\n\t\tconst { manager, backgroundAllowed } = this.options;\n\t\tconst generation = ++this.generation;\n\t\tconst sessionId = manager.getSessionId();\n\t\tconst sessionFile = manager.getSessionFile();\n\t\tconst waitInterruptSignal = () => this.waitInterruptSignal;\n\t\tconst service: TaskRuntime = new TaskRuntime({\n\t\t\tenabled: this.enabled,\n\t\t\tbackgroundAllowed,\n\t\t\tsession: {\n\t\t\t\tget waitInterruptSignal() {\n\t\t\t\t\treturn waitInterruptSignal();\n\t\t\t\t},\n\t\t\t\tprepareWait: (toolCallId, taskId) => this.delivery.prepareWait(toolCallId, taskId),\n\t\t\t\tstoppedByTreeNavigation: (targetId): TaskSnapshot[] => this.stoppedByTreeNavigation(targetId, service),\n\t\t\t},\n\t\t\tanchor: () => manager.getLeafId(),\n\t\t\tonCleanupError: (message) => this.warn(\"task_cleanup\", message),\n\t\t\tonSettled: (task, usage) => {\n\t\t\t\tconst onBranch =\n\t\t\t\t\tmanager.getSessionId() === sessionId &&\n\t\t\t\t\t(task.anchorId === null || manager.getBranch().some((entry) => entry.id === task.anchorId));\n\t\t\t\tif (this.disposed || this.service !== service || !onBranch) {\n\t\t\t\t\tthis.quarantineSettlement({ sessionId, generation, task, usage }, sessionFile);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.persistSettlement(task, usage);\n\t\t\t},\n\t\t});\n\t\tthis.restoreHistory(service);\n\t\tservice.subscribe(() => this.delivery.schedule());\n\t\treturn service;\n\t}\n\n\trestoreHistory(service = this.service): void {\n\t\tconst records: unknown[] = [];\n\t\tconst toolResults = new Map<string, AgentToolResult<unknown>[\"content\"]>();\n\t\tfor (const entry of this.options.manager.getBranch()) {\n\t\t\tif (entry.type === \"custom\" && entry.customType === \"task-result\") records.push(entry.data);\n\t\t\telse if (entry.type === \"message\" && entry.message.role === \"toolResult\")\n\t\t\t\ttoolResults.set(entry.message.toolCallId, entry.message.content);\n\t\t}\n\t\tservice.restoreHistory(records, toolResults);\n\t}\n\n\tprivate quarantineSettlement(record: QuarantinedTaskSettlement, sessionFile: string | undefined): void {\n\t\t// Never move the active leaf to append late usage: JSONL's last entry also\n\t\t// selects its resumed branch. The sidecar is diagnostic evidence only.\n\t\tthis.quarantine.push(structuredClone(record));\n\t\tif (this.quarantine.length > 32) this.quarantine.shift();\n\t\tlet persistence =\n\t\t\t\"Not persisted: only the latest 32 snapshots are retained in quarantinedTaskSettlements; late usage is not accounted in session totals.\";\n\t\tif (sessionFile) {\n\t\t\ttry {\n\t\t\t\tmkdirSync(dirname(sessionFile), { recursive: true });\n\t\t\t\tappendFileSync(`${sessionFile}.tasks-late.jsonl`, `${JSON.stringify({ version: 1, ...record })}\\n`);\n\t\t\t\tpersistence = `Saved diagnostic sidecar: ${sessionFile}.tasks-late.jsonl (not included in normal session totals).`;\n\t\t\t} catch {\n\t\t\t\tpersistence = `Sidecar write failed. ${persistence}`;\n\t\t\t}\n\t\t}\n\t\tthis.warn(\n\t\t\t\"task_settlement_quarantined\",\n\t\t\t`Late background settlement ${record.task.id} was quarantined. ${persistence}`,\n\t\t);\n\t}\n\n\tprivate persistSettlement(task: TaskSnapshot, usage: Usage | undefined): void {\n\t\tconst manager = this.options.manager;\n\t\tconst appended: SessionEntry[] = [];\n\t\tconst append = (customType: string, data: unknown) => {\n\t\t\tconst entry = manager.getEntry(manager.appendCustomEntry(customType, data));\n\t\t\tif (entry) appended.push(entry);\n\t\t};\n\t\ttry {\n\t\t\tif (usage && !manager.getEntries().some((entry) => getTaskUsageRecord(entry)?.taskId === task.id)) {\n\t\t\t\tappend(TASK_USAGE_TYPE, { version: 1, taskId: task.id, usage });\n\t\t\t}\n\t\t\t// A foreground result is the tool result the transcript already saves; restoration reads it from there.\n\t\t\tconst { result: _result, resultTruncated: _truncated, ...metadata } = task;\n\t\t\tconst saved = task.mode === \"foreground\" ? metadata : task;\n\t\t\tappend(\"task-result\", JSON.parse(JSON.stringify({ version: TASK_HISTORY_VERSION, task: saved })));\n\t\t} finally {\n\t\t\t// Complete the writes before observers can replace the runtime or its manager.\n\t\t\t// If a write fails, still report entries that were successfully appended.\n\t\t\tfor (const entry of appended) {\n\t\t\t\ttry {\n\t\t\t\t\tthis.options.onEntry(entry);\n\t\t\t\t} catch {\n\t\t\t\t\t// Observers cannot interrupt settlement or result publication.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate warn(event: string, message: string): void {\n\t\ttry {\n\t\t\tthis.options.onError(event, truncateHead(message, { maxBytes: 4096, maxLines: 32 }).content);\n\t\t} catch {\n\t\t\t// Diagnostics cannot reject settlement, cleanup or scheduled callbacks.\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.contextReminder.reset();\n\t\tthis.interruptWaits();\n\t\tthis.service.close();\n\t\tthis.delivery.dispose();\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/core/tasks/session.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CA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AC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACD","sourcesContent":["import { appendFileSync, mkdirSync } from \"node:fs\";\nimport { dirname } from \"node:path\";\nimport type { AgentMessage, AgentToolResult } from \"@earendil-works/pi-agent-core\";\nimport type { Usage } from \"@earendil-works/pi-ai/compat\";\nimport type { CustomMessage } from \"../messages.ts\";\nimport type { SessionEntry, SessionManager } from \"../session-manager.ts\";\nimport { truncateHead } from \"../tools/truncate.ts\";\nimport { getTaskUsageRecord } from \"../usage-totals.ts\";\nimport { TASK_RECORD_TYPE, TASK_SNAPSHOT_VERSION } from \"./codec.ts\";\nimport { TaskDelivery } from \"./delivery.ts\";\nimport { TaskContextReminder } from \"./reminder.ts\";\nimport { TaskRuntime } from \"./runtime.ts\";\nimport type { TaskSnapshot } from \"./types.ts\";\n\ninterface TaskSessionOptions {\n\tmanager: SessionManager;\n\tbackgroundAllowed?: boolean;\n\t/** The main session owns input queues, preflight and idle state. */\n\tcanDeliver(): boolean;\n\t/**\n\t * Start a completion turn, or enqueue the message and return waitForPersistence().\n\t * The host owns input routing; this adapter owns the queued delivery's lifetime.\n\t */\n\tdeliver(message: CustomMessage, waitForPersistence: () => Promise<void>): Promise<void>;\n\tonEntry(entry: SessionEntry): void;\n\tonError(event: string, message: string): void;\n}\n\nexport interface QuarantinedTaskSettlement {\n\tsessionId: string;\n\tgeneration: number;\n\ttask: TaskSnapshot;\n\tusage?: Usage;\n}\n\n/** Session persistence and completion delivery; execution supervision stays in TaskRuntime. */\nexport class TaskSession {\n\tprivate readonly options: TaskSessionOptions;\n\tprivate _service: TaskRuntime;\n\tprivate enabled = false;\n\tprivate disposed = false;\n\tprivate generation = 0;\n\tprivate waitInterrupt = new AbortController();\n\tprivate readonly contextReminder = new TaskContextReminder();\n\treadonly delivery: TaskDelivery;\n\tprivate readonly quarantine: QuarantinedTaskSettlement[] = [];\n\n\tconstructor(options: TaskSessionOptions) {\n\t\tthis.options = options;\n\t\tthis.delivery = new TaskDelivery({\n\t\t\tservice: () => this.service,\n\t\t\tcanDeliver: options.canDeliver,\n\t\t\tdeliver: options.deliver,\n\t\t\twarn: (event, message) => this.warn(event, message),\n\t\t});\n\t\tthis._service = this.createService();\n\t}\n\n\tget service(): TaskRuntime {\n\t\treturn this._service;\n\t}\n\n\t/** End only current task waits; the next wait observes a fresh signal. */\n\tinterruptWaits(): void {\n\t\tconst previous = this.waitInterrupt;\n\t\tthis.waitInterrupt = new AbortController();\n\t\tprevious.abort();\n\t}\n\n\tnoteCompaction(): void {\n\t\tthis.contextReminder.compacted();\n\t}\n\n\tprojectContextReminder(messages: AgentMessage[]): AgentMessage[] {\n\t\treturn this.contextReminder.project(this.service, messages);\n\t}\n\n\tnoteAssistantCompleted(): void {\n\t\tthis.contextReminder.assistantCompleted();\n\t}\n\n\tget quarantinedSettlements(): readonly QuarantinedTaskSettlement[] {\n\t\treturn structuredClone(this.quarantine);\n\t}\n\n\tsetEnabled(enabled: boolean): void {\n\t\tthis.enabled = enabled && this.options.backgroundAllowed !== false;\n\t\tthis.service.setEnabled(this.enabled);\n\t}\n\n\t/**\n\t * Running tasks that navigating to `targetId` would cancel, since results are saved on their\n\t * launch branch. Mirrors navigateTree's destination: selecting a user or custom message moves\n\t * the leaf to its parent.\n\t */\n\tstoppedByTreeNavigation(targetId: string, service = this.service): TaskSnapshot[] {\n\t\tconst target = this.options.manager.getEntry(targetId);\n\t\tif (!target) return [];\n\t\tconst leafId =\n\t\t\t(target.type === \"message\" && target.message.role === \"user\") || target.type === \"custom_message\"\n\t\t\t\t? target.parentId\n\t\t\t\t: targetId;\n\t\treturn service.activeOutsideBranch(this.branchIds(leafId));\n\t}\n\n\t/** Cancel running tasks launched outside the branch ending at `leafId`. */\n\tcancelOutsideBranch(leafId: string | null): Promise<void> {\n\t\treturn this.service.cancelOutsideBranch(this.branchIds(leafId));\n\t}\n\n\tprivate branchIds(leafId: string | null): Set<string> {\n\t\treturn new Set(leafId === null ? [] : this.options.manager.getBranch(leafId).map((entry) => entry.id));\n\t}\n\n\t/** Called after the old service's bounded shutdown, while lifecycle delivery is paused. */\n\treplaceService(): void {\n\t\tthis.contextReminder.reset();\n\t\tthis.service.close();\n\t\tthis._service = this.createService();\n\t\tthis.delivery.retry();\n\t}\n\n\tprivate createService(): TaskRuntime {\n\t\tconst { manager, backgroundAllowed } = this.options;\n\t\tconst generation = ++this.generation;\n\t\tconst sessionId = manager.getSessionId();\n\t\tconst sessionFile = manager.getSessionFile();\n\t\tconst interrupts = () => this.waitInterrupt.signal;\n\t\tconst service: TaskRuntime = new TaskRuntime({\n\t\t\tenabled: this.enabled,\n\t\t\tbackgroundAllowed,\n\t\t\tsession: {\n\t\t\t\tstoppedByTreeNavigation: (targetId): TaskSnapshot[] => this.stoppedByTreeNavigation(targetId, service),\n\t\t\t},\n\t\t\twaits: {\n\t\t\t\tget interruptSignal() {\n\t\t\t\t\treturn interrupts();\n\t\t\t\t},\n\t\t\t\tbind: (toolCallId, taskId) => this.delivery.bindWait(service, toolCallId, taskId),\n\t\t\t},\n\t\t\tanchor: () => manager.getLeafId(),\n\t\t\tonCleanupError: (message) => this.warn(\"task_cleanup\", message),\n\t\t\tonSettled: (task, usage) => {\n\t\t\t\tconst onBranch =\n\t\t\t\t\tmanager.getSessionId() === sessionId &&\n\t\t\t\t\t(task.anchorId === null || manager.getBranch().some((entry) => entry.id === task.anchorId));\n\t\t\t\tif (this.disposed || this.service !== service || !onBranch) {\n\t\t\t\t\tthis.quarantineSettlement({ sessionId, generation, task, usage }, sessionFile);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tthis.persistSettlement(task, usage);\n\t\t\t},\n\t\t});\n\t\tthis.restoreHistory(service);\n\t\tservice.subscribe(() => this.delivery.schedule());\n\t\treturn service;\n\t}\n\n\trestoreHistory(service = this.service): void {\n\t\tconst records: unknown[] = [];\n\t\tconst toolResults = new Map<string, AgentToolResult<unknown>[\"content\"]>();\n\t\tfor (const entry of this.options.manager.getBranch()) {\n\t\t\tif (entry.type === \"custom\" && entry.customType === TASK_RECORD_TYPE) records.push(entry.data);\n\t\t\telse if (entry.type === \"message\" && entry.message.role === \"toolResult\")\n\t\t\t\ttoolResults.set(entry.message.toolCallId, entry.message.content);\n\t\t}\n\t\tservice.restoreHistory(records, toolResults);\n\t}\n\n\tprivate quarantineSettlement(record: QuarantinedTaskSettlement, sessionFile: string | undefined): void {\n\t\t// Never move the active leaf to append late usage: JSONL's last entry also\n\t\t// selects its resumed branch. The sidecar is diagnostic evidence only.\n\t\tthis.quarantine.push(structuredClone(record));\n\t\tif (this.quarantine.length > 32) this.quarantine.shift();\n\t\tlet persistence =\n\t\t\t\"Not persisted: only the latest 32 snapshots are retained in quarantinedTaskSettlements; late usage is not accounted in session totals.\";\n\t\tif (sessionFile) {\n\t\t\ttry {\n\t\t\t\tmkdirSync(dirname(sessionFile), { recursive: true });\n\t\t\t\tappendFileSync(`${sessionFile}.tasks-late.jsonl`, `${JSON.stringify({ version: 1, ...record })}\\n`);\n\t\t\t\tpersistence = `Saved diagnostic sidecar: ${sessionFile}.tasks-late.jsonl (not included in normal session totals).`;\n\t\t\t} catch {\n\t\t\t\tpersistence = `Sidecar write failed. ${persistence}`;\n\t\t\t}\n\t\t}\n\t\tthis.warn(\n\t\t\t\"task_settlement_quarantined\",\n\t\t\t`Late background settlement ${record.task.id} was quarantined. ${persistence}`,\n\t\t);\n\t}\n\n\t/** One entry per settlement: the bounded terminal snapshot and its first usage settlement. */\n\tprivate persistSettlement(task: TaskSnapshot, usage: Usage | undefined): void {\n\t\tconst manager = this.options.manager;\n\t\tconst accounted = usage && manager.getEntries().some((entry) => getTaskUsageRecord(entry)?.taskId === task.id);\n\t\t// A foreground result is the tool result the transcript already saves; restoration reads it from there.\n\t\tconst { result: _result, ...metadata } = task;\n\t\tconst saved = task.mode === \"foreground\" ? metadata : task;\n\t\tconst data = JSON.parse(\n\t\t\tJSON.stringify({ version: TASK_SNAPSHOT_VERSION, task: saved, ...(usage && !accounted ? { usage } : {}) }),\n\t\t);\n\t\tconst entry = manager.getEntry(manager.appendCustomEntry(TASK_RECORD_TYPE, data));\n\t\tif (!entry) return;\n\t\ttry {\n\t\t\tthis.options.onEntry(entry);\n\t\t} catch {\n\t\t\t// Observers cannot interrupt settlement or result publication.\n\t\t}\n\t}\n\n\tprivate warn(event: string, message: string): void {\n\t\ttry {\n\t\t\tthis.options.onError(event, truncateHead(message, { maxBytes: 4096, maxLines: 32 }).content);\n\t\t} catch {\n\t\t\t// Diagnostics cannot reject settlement, cleanup or scheduled callbacks.\n\t\t}\n\t}\n\n\tdispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.contextReminder.reset();\n\t\tthis.interruptWaits();\n\t\tthis.service.close();\n\t\tthis.delivery.dispose();\n\t}\n}\n"]}
|
|
@@ -1,38 +1,31 @@
|
|
|
1
1
|
import type { AgentToolResult } from "@earendil-works/pi-agent-core";
|
|
2
|
-
import
|
|
3
|
-
export interface TaskRecord {
|
|
4
|
-
/** The runtime's working copy. Call changed() after every mutation. */
|
|
5
|
-
task: TaskSnapshot;
|
|
6
|
-
settled: boolean;
|
|
7
|
-
/** Whether the launch anchor is on the selected branch. */
|
|
8
|
-
visible: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* none: running, or answered inline by its tool call; pending: a settled handoff
|
|
11
|
-
* awaiting automatic delivery; claimed: handed to the host; delivered: acknowledged.
|
|
12
|
-
*/
|
|
13
|
-
delivery: "none" | "pending" | "claimed" | "delivered";
|
|
14
|
-
pins: number;
|
|
15
|
-
deliveryHolds: number;
|
|
16
|
-
cleanup?: () => void | Promise<void>;
|
|
17
|
-
readError?: string;
|
|
18
|
-
waiters: Set<() => void>;
|
|
19
|
-
/** Frozen snapshot shared by readers until the task changes. */
|
|
20
|
-
snapshot?: TaskSnapshot;
|
|
21
|
-
}
|
|
2
|
+
import { TaskRecord } from "./record.ts";
|
|
22
3
|
export declare const EXPIRED_OUTPUT = "Output has expired: the managed log was released; showing the stored result.";
|
|
23
|
-
/** Readers share one frozen copy, so polling and status rendering never clone unchanged output. */
|
|
24
|
-
export declare function snapshotOf(record: TaskRecord): TaskSnapshot;
|
|
25
|
-
export declare function changed(record: TaskRecord): void;
|
|
26
4
|
/** Retained snapshots and output leases. This store never owns executable handles. */
|
|
27
5
|
export declare class TaskStore {
|
|
28
|
-
readonly records
|
|
29
|
-
readonly cleanups
|
|
6
|
+
private readonly records;
|
|
7
|
+
private readonly cleanups;
|
|
30
8
|
private readonly maxHistory;
|
|
31
9
|
private readonly maxRetained;
|
|
32
10
|
private readonly isClosed;
|
|
33
11
|
private readonly onCleanupError?;
|
|
34
12
|
constructor(maxHistory: number, maxRetained: number, isClosed: () => boolean, onCleanupError?: (message: string) => void);
|
|
35
13
|
private get closed();
|
|
14
|
+
get(id: string): TaskRecord | undefined;
|
|
15
|
+
/** Records whose ID, or whose ID without its kind prefix, starts with `prefix`. */
|
|
16
|
+
match(prefix: string): TaskRecord[];
|
|
17
|
+
add(record: TaskRecord): void;
|
|
18
|
+
all(): TaskRecord[];
|
|
19
|
+
/** Records whose execution has not settled, queued or running. */
|
|
20
|
+
unsettled(): TaskRecord[];
|
|
21
|
+
/** Records on the selected branch. */
|
|
22
|
+
visible(): TaskRecord[];
|
|
23
|
+
/** Settled handoffs eligible for automatic delivery. */
|
|
24
|
+
deliverable(): TaskRecord[];
|
|
25
|
+
/** Records plus output cleanups still running; admission bounds this. */
|
|
26
|
+
retainedCount(): number;
|
|
27
|
+
/** Settles once every output cleanup started so far has finished. */
|
|
28
|
+
cleanupsDone(): Promise<unknown>;
|
|
36
29
|
/**
|
|
37
30
|
* Foreground records save no output of their own: their tool result already holds it,
|
|
38
31
|
* so `toolResults` maps each tool call ID on the branch to that content.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGrE,OAAO,
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../../src/core/tasks/store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,eAAO,MAAM,cAAc,iFAAiF,CAAC;AAY7G,sFAAsF;AACtF,qBAAa,SAAS;IACrB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAA4B;gBAE3D,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,OAAO,EACvB,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI;IAO3C,OAAO,KAAK,MAAM,GAEjB;IAED,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAIvC,mFAAmF;IACnF,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE;IAMnC,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAI7B,GAAG,IAAI,UAAU,EAAE;IAInB,kEAAkE;IAClE,SAAS,IAAI,UAAU,EAAE;IAIzB,sCAAsC;IACtC,OAAO,IAAI,UAAU,EAAE;IAIvB,wDAAwD;IACxD,WAAW,IAAI,UAAU,EAAE;IAI3B,yEAAyE;IACzE,aAAa,IAAI,MAAM;IAIvB,qEAAq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