@bastani/atomic 0.9.20-alpha.3 → 0.9.20-alpha.4
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 +131 -0
- package/README.md +15 -7
- package/dist/builtin/intercom/CHANGELOG.md +18 -0
- package/dist/builtin/intercom/README.md +2 -2
- package/dist/builtin/intercom/broker/send-handler.ts +59 -2
- package/dist/builtin/intercom/index.bundle.mjs +101 -16
- package/dist/builtin/intercom/package.json +3 -3
- package/dist/builtin/intercom/session-target.ts +34 -9
- package/dist/builtin/intercom/skills/intercom/SKILL.md +4 -4
- package/dist/builtin/mcp/CHANGELOG.md +13 -0
- package/dist/builtin/mcp/OAUTH.md +1 -1
- package/dist/builtin/mcp/README.md +3 -1
- package/dist/builtin/mcp/index.bundle.mjs +412 -64
- package/dist/builtin/mcp/package.json +3 -3
- package/dist/builtin/subagents/CHANGELOG.md +27 -0
- package/dist/builtin/subagents/README.md +2 -2
- package/dist/builtin/subagents/agents/code-simplifier.md +2 -3
- package/dist/builtin/subagents/agents/codebase-analyzer.md +2 -3
- package/dist/builtin/subagents/agents/codebase-locator.md +2 -3
- package/dist/builtin/subagents/agents/codebase-online-researcher.md +2 -3
- package/dist/builtin/subagents/agents/codebase-pattern-finder.md +2 -3
- package/dist/builtin/subagents/agents/codebase-research-analyzer.md +2 -3
- package/dist/builtin/subagents/agents/codebase-research-locator.md +2 -3
- package/dist/builtin/subagents/agents/debugger.md +1 -2
- package/dist/builtin/subagents/agents/worker.md +1 -2
- package/dist/builtin/subagents/package.json +4 -8
- package/dist/builtin/subagents/skills/subagent/SKILL.md +15 -13
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +249 -63
- package/dist/builtin/web-access/CHANGELOG.md +12 -0
- package/dist/builtin/web-access/index.bundle.mjs +367 -295
- package/dist/builtin/web-access/package.json +3 -3
- package/dist/builtin/workflows/CHANGELOG.md +68 -0
- package/dist/builtin/workflows/README.md +29 -30
- package/dist/builtin/workflows/builtin/adversarial-verification.js +3 -3
- package/dist/builtin/workflows/builtin/{chunk-yeee2jrc.js → chunk-119kxb28.js} +5 -46
- package/dist/builtin/workflows/builtin/chunk-1dydq7w3.js +9722 -0
- package/dist/builtin/workflows/builtin/{chunk-31j2gs7h.js → chunk-9y0f90rd.js} +4 -6
- package/dist/builtin/workflows/builtin/{chunk-z29qbehr.js → chunk-d1xqh1rd.js} +4 -6
- package/dist/builtin/workflows/builtin/{chunk-zqtm1d2c.js → chunk-hnbbb5r0.js} +12 -217
- package/dist/builtin/workflows/builtin/{chunk-wf741bv3.js → chunk-k18g9me8.js} +4 -6
- package/dist/builtin/workflows/builtin/{chunk-g0csgs7w.js → chunk-kf5xpbkz.js} +8 -10
- package/dist/builtin/workflows/builtin/{chunk-a2kdsqn8.js → chunk-n4yxrsm9.js} +1 -1
- package/dist/builtin/workflows/builtin/{chunk-xtxcq5tj.js → chunk-n8g2da69.js} +17 -1
- package/dist/builtin/workflows/builtin/{chunk-fg9esgkj.js → chunk-scgprmdj.js} +4 -6
- package/dist/builtin/workflows/builtin/{chunk-6w6cvk6b.js → chunk-sn5mchnx.js} +4 -6
- package/dist/builtin/workflows/builtin/{chunk-ewkkkbak.js → chunk-vt9zgr9d.js} +9 -91
- package/dist/builtin/workflows/builtin/classify-and-act.js +3 -3
- package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +3 -3
- package/dist/builtin/workflows/builtin/generate-and-filter.js +3 -3
- package/dist/builtin/workflows/builtin/goal.js +4 -4
- package/dist/builtin/workflows/builtin/index.js +12 -12
- package/dist/builtin/workflows/builtin/loop-until-done.js +3 -3
- package/dist/builtin/workflows/builtin/open-claude-design.js +3 -3
- package/dist/builtin/workflows/builtin/ralph.js +4 -4
- package/dist/builtin/workflows/builtin/steering-context.js +1 -1
- package/dist/builtin/workflows/builtin/tournament.js +3 -3
- package/dist/builtin/workflows/package.json +3 -3
- package/dist/builtin/workflows/src/authoring.d.ts +2 -0
- package/dist/builtin/workflows/src/durable/dependency-doctor-types.d.ts +42 -0
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +82005 -78701
- package/dist/builtin/workflows/src/index.js +8900 -1200
- package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +11 -0
- package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +4 -1
- package/dist/cli/args.js +2 -2
- package/dist/cli/args.js.map +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +1 -0
- package/dist/config.js.map +1 -1
- package/dist/core/agent-session-accessors.d.ts.map +1 -1
- package/dist/core/agent-session-accessors.js +2 -1
- package/dist/core/agent-session-accessors.js.map +1 -1
- package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-auto-compaction.js +9 -2
- package/dist/core/agent-session-auto-compaction.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts +3 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +18 -6
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +25 -8
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-events.d.ts +6 -6
- package/dist/core/agent-session-events.d.ts.map +1 -1
- package/dist/core/agent-session-events.js +145 -62
- package/dist/core/agent-session-events.js.map +1 -1
- package/dist/core/agent-session-export.d.ts +1 -1
- package/dist/core/agent-session-export.d.ts.map +1 -1
- package/dist/core/agent-session-export.js +18 -19
- package/dist/core/agent-session-export.js.map +1 -1
- package/dist/core/agent-session-extension-bindings.d.ts +3 -2
- package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
- package/dist/core/agent-session-extension-bindings.js +274 -70
- package/dist/core/agent-session-extension-bindings.js.map +1 -1
- package/dist/core/agent-session-message-queue.d.ts +1 -1
- package/dist/core/agent-session-message-queue.d.ts.map +1 -1
- package/dist/core/agent-session-message-queue.js +30 -4
- package/dist/core/agent-session-message-queue.js.map +1 -1
- package/dist/core/agent-session-methods.d.ts +19 -11
- package/dist/core/agent-session-methods.d.ts.map +1 -1
- package/dist/core/agent-session-methods.js.map +1 -1
- package/dist/core/agent-session-models.d.ts +2 -2
- package/dist/core/agent-session-models.d.ts.map +1 -1
- package/dist/core/agent-session-models.js +38 -29
- package/dist/core/agent-session-models.js.map +1 -1
- package/dist/core/agent-session-persistent-custom-messages.d.ts +1 -1
- package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-post-tool-compaction.js +18 -1
- package/dist/core/agent-session-post-tool-compaction.js.map +1 -1
- package/dist/core/agent-session-prompt.d.ts +1 -1
- package/dist/core/agent-session-prompt.d.ts.map +1 -1
- package/dist/core/agent-session-prompt.js +104 -22
- package/dist/core/agent-session-prompt.js.map +1 -1
- package/dist/core/agent-session-queue-pause.d.ts +2 -0
- package/dist/core/agent-session-queue-pause.d.ts.map +1 -1
- package/dist/core/agent-session-queue-pause.js +13 -2
- package/dist/core/agent-session-queue-pause.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts +0 -3
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +24 -11
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime-auth.d.ts.map +1 -1
- package/dist/core/agent-session-runtime-auth.js +10 -0
- package/dist/core/agent-session-runtime-auth.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts +17 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +428 -197
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +4 -0
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js +31 -2
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-state.d.ts +10 -2
- package/dist/core/agent-session-state.d.ts.map +1 -1
- package/dist/core/agent-session-state.js +32 -22
- package/dist/core/agent-session-state.js.map +1 -1
- package/dist/core/agent-session-summary.d.ts.map +1 -1
- package/dist/core/agent-session-summary.js +9 -2
- package/dist/core/agent-session-summary.js.map +1 -1
- package/dist/core/agent-session-tasks.d.ts +1 -0
- package/dist/core/agent-session-tasks.d.ts.map +1 -1
- package/dist/core/agent-session-tasks.js +24 -3
- package/dist/core/agent-session-tasks.js.map +1 -1
- package/dist/core/agent-session-tool-hooks.d.ts.map +1 -1
- package/dist/core/agent-session-tool-hooks.js +26 -3
- package/dist/core/agent-session-tool-hooks.js.map +1 -1
- package/dist/core/agent-session-tool-registry.d.ts.map +1 -1
- package/dist/core/agent-session-tool-registry.js +0 -2
- package/dist/core/agent-session-tool-registry.js.map +1 -1
- package/dist/core/agent-session-transfer.js.map +1 -1
- package/dist/core/agent-session-tree.d.ts.map +1 -1
- package/dist/core/agent-session-tree.js +6 -0
- package/dist/core/agent-session-tree.js.map +1 -1
- package/dist/core/agent-session-types.d.ts +5 -0
- package/dist/core/agent-session-types.d.ts.map +1 -1
- package/dist/core/agent-session-types.js.map +1 -1
- package/dist/core/agent-session.d.ts +15 -8
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +113 -66
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-storage.d.ts +5 -3
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +18 -5
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/builtin-diagnostics.d.ts +2 -0
- package/dist/core/builtin-diagnostics.d.ts.map +1 -0
- package/dist/core/builtin-diagnostics.js +14 -0
- package/dist/core/builtin-diagnostics.js.map +1 -0
- package/dist/core/builtin-packages.d.ts +5 -2
- package/dist/core/builtin-packages.d.ts.map +1 -1
- package/dist/core/builtin-packages.js +24 -3
- package/dist/core/builtin-packages.js.map +1 -1
- package/dist/core/builtin-resource-loader.d.ts +4 -0
- package/dist/core/builtin-resource-loader.d.ts.map +1 -0
- package/dist/core/builtin-resource-loader.js +239 -0
- package/dist/core/builtin-resource-loader.js.map +1 -0
- package/dist/core/cache-retention.d.ts +4 -0
- package/dist/core/cache-retention.d.ts.map +1 -0
- package/dist/core/cache-retention.js +58 -0
- package/dist/core/cache-retention.js.map +1 -0
- package/dist/core/cache-stats.d.ts.map +1 -1
- package/dist/core/cache-stats.js +11 -0
- package/dist/core/cache-stats.js.map +1 -1
- package/dist/core/cache-warmer.d.ts +66 -0
- package/dist/core/cache-warmer.d.ts.map +1 -0
- package/dist/core/cache-warmer.js +313 -0
- package/dist/core/cache-warmer.js.map +1 -0
- package/dist/core/child-session-options.d.ts +5 -0
- package/dist/core/child-session-options.d.ts.map +1 -0
- package/dist/core/child-session-options.js +30 -0
- package/dist/core/child-session-options.js.map +1 -0
- package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
- package/dist/core/compaction/branch-summarization.js +2 -2
- package/dist/core/compaction/branch-summarization.js.map +1 -1
- package/dist/core/compaction/compaction-boundary.d.ts.map +1 -1
- package/dist/core/compaction/compaction-boundary.js +2 -1
- package/dist/core/compaction/compaction-boundary.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +18 -0
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/compaction/fallback-planner.d.ts +1 -0
- package/dist/core/compaction/fallback-planner.d.ts.map +1 -1
- package/dist/core/compaction/fallback-planner.js +2 -0
- package/dist/core/compaction/fallback-planner.js.map +1 -1
- package/dist/core/compaction/range-planner.d.ts.map +1 -1
- package/dist/core/compaction/range-planner.js +3 -3
- package/dist/core/compaction/range-planner.js.map +1 -1
- package/dist/core/compaction/session-summarization.d.ts.map +1 -1
- package/dist/core/compaction/session-summarization.js +2 -1
- package/dist/core/compaction/session-summarization.js.map +1 -1
- package/dist/core/credential-screening.d.ts +17 -0
- package/dist/core/credential-screening.d.ts.map +1 -0
- package/dist/core/credential-screening.js +30 -0
- package/dist/core/credential-screening.js.map +1 -0
- package/dist/core/decision-provider.d.ts +4 -0
- package/dist/core/decision-provider.d.ts.map +1 -0
- package/dist/core/decision-provider.js +12 -0
- package/dist/core/decision-provider.js.map +1 -0
- package/dist/core/execution-model-router.d.ts +28 -0
- package/dist/core/execution-model-router.d.ts.map +1 -0
- package/dist/core/execution-model-router.js +165 -0
- package/dist/core/execution-model-router.js.map +1 -0
- package/dist/core/extensions/agent-events.d.ts +4 -4
- package/dist/core/extensions/agent-events.d.ts.map +1 -1
- package/dist/core/extensions/agent-events.js.map +1 -1
- package/dist/core/extensions/api-types.d.ts +46 -40
- package/dist/core/extensions/api-types.d.ts.map +1 -1
- package/dist/core/extensions/api-types.js.map +1 -1
- package/dist/core/extensions/context-types.d.ts +7 -1
- package/dist/core/extensions/context-types.d.ts.map +1 -1
- package/dist/core/extensions/context-types.js.map +1 -1
- package/dist/core/extensions/event-results.d.ts +7 -6
- package/dist/core/extensions/event-results.d.ts.map +1 -1
- package/dist/core/extensions/event-results.js.map +1 -1
- package/dist/core/extensions/event-types.d.ts +2 -1
- package/dist/core/extensions/event-types.d.ts.map +1 -1
- package/dist/core/extensions/event-types.js.map +1 -1
- package/dist/core/extensions/extension-work.d.ts +14 -0
- package/dist/core/extensions/extension-work.d.ts.map +1 -0
- package/dist/core/extensions/extension-work.js +73 -0
- package/dist/core/extensions/extension-work.js.map +1 -0
- package/dist/core/extensions/herdr-file-integration.d.ts +36 -0
- package/dist/core/extensions/herdr-file-integration.d.ts.map +1 -0
- package/dist/core/extensions/herdr-file-integration.js +60 -0
- package/dist/core/extensions/herdr-file-integration.js.map +1 -0
- package/dist/core/extensions/host-input.d.ts +51 -0
- package/dist/core/extensions/host-input.d.ts.map +1 -0
- package/dist/core/extensions/host-input.js +211 -0
- package/dist/core/extensions/host-input.js.map +1 -0
- package/dist/core/extensions/index.d.ts +4 -2
- package/dist/core/extensions/index.d.ts.map +1 -1
- package/dist/core/extensions/index.js +0 -3
- package/dist/core/extensions/index.js.map +1 -1
- package/dist/core/extensions/jiti-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-loader.js +3 -0
- package/dist/core/extensions/jiti-loader.js.map +1 -0
- package/dist/core/extensions/jiti-static-loader.d.ts +2 -0
- package/dist/core/extensions/jiti-static-loader.d.ts.map +1 -0
- package/dist/core/extensions/jiti-static-loader.js +3 -0
- package/dist/core/extensions/jiti-static-loader.js.map +1 -0
- package/dist/core/extensions/loader-api.d.ts +7 -0
- package/dist/core/extensions/loader-api.d.ts.map +1 -1
- package/dist/core/extensions/loader-api.js +154 -28
- package/dist/core/extensions/loader-api.js.map +1 -1
- package/dist/core/extensions/loader-bindings.d.ts +24 -0
- package/dist/core/extensions/loader-bindings.d.ts.map +1 -0
- package/dist/core/extensions/loader-bindings.js +128 -0
- package/dist/core/extensions/loader-bindings.js.map +1 -0
- package/dist/core/extensions/loader-core.d.ts +2 -1
- package/dist/core/extensions/loader-core.d.ts.map +1 -1
- package/dist/core/extensions/loader-core.js +91 -14
- package/dist/core/extensions/loader-core.js.map +1 -1
- package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-host-modules.js +3 -1
- package/dist/core/extensions/loader-host-modules.js.map +1 -1
- package/dist/core/extensions/loader-rollback.d.ts +14 -0
- package/dist/core/extensions/loader-rollback.d.ts.map +1 -0
- package/dist/core/extensions/loader-rollback.js +95 -0
- package/dist/core/extensions/loader-rollback.js.map +1 -0
- package/dist/core/extensions/loader-runtime.d.ts +3 -1
- package/dist/core/extensions/loader-runtime.d.ts.map +1 -1
- package/dist/core/extensions/loader-runtime.js +38 -14
- package/dist/core/extensions/loader-runtime.js.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
- package/dist/core/extensions/loader-virtual-modules.js +9 -2
- package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
- package/dist/core/extensions/loader.d.ts +1 -1
- package/dist/core/extensions/loader.d.ts.map +1 -1
- package/dist/core/extensions/loader.js +1 -1
- package/dist/core/extensions/loader.js.map +1 -1
- package/dist/core/extensions/reactive-widget.d.ts +1 -1
- package/dist/core/extensions/reactive-widget.js.map +1 -1
- package/dist/core/extensions/runner-context.d.ts +4 -0
- package/dist/core/extensions/runner-context.d.ts.map +1 -1
- package/dist/core/extensions/runner-context.js +25 -0
- package/dist/core/extensions/runner-context.js.map +1 -1
- package/dist/core/extensions/runner-events.d.ts +8 -4
- package/dist/core/extensions/runner-events.d.ts.map +1 -1
- package/dist/core/extensions/runner-events.js +55 -53
- package/dist/core/extensions/runner-events.js.map +1 -1
- package/dist/core/extensions/runner-project-trust.d.ts.map +1 -1
- package/dist/core/extensions/runner-project-trust.js +2 -4
- package/dist/core/extensions/runner-project-trust.js.map +1 -1
- package/dist/core/extensions/runner.d.ts +31 -4
- package/dist/core/extensions/runner.d.ts.map +1 -1
- package/dist/core/extensions/runner.js +219 -23
- package/dist/core/extensions/runner.js.map +1 -1
- package/dist/core/extensions/runtime-types.d.ts +2 -0
- package/dist/core/extensions/runtime-types.d.ts.map +1 -1
- package/dist/core/extensions/runtime-types.js.map +1 -1
- package/dist/core/extensions/types.d.ts +3 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js +0 -12
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/extensions/workflow-activity-hub.d.ts +2 -0
- package/dist/core/extensions/workflow-activity-hub.d.ts.map +1 -1
- package/dist/core/extensions/workflow-activity-hub.js +5 -3
- package/dist/core/extensions/workflow-activity-hub.js.map +1 -1
- package/dist/core/extensions/wrapper.d.ts.map +1 -1
- package/dist/core/extensions/wrapper.js +5 -3
- package/dist/core/extensions/wrapper.js.map +1 -1
- package/dist/core/fast-model-routing.d.ts +3 -3
- package/dist/core/fast-model-routing.d.ts.map +1 -1
- package/dist/core/fast-model-routing.js +3 -3
- package/dist/core/fast-model-routing.js.map +1 -1
- package/dist/core/fast-model-variants.d.ts +4 -0
- package/dist/core/fast-model-variants.d.ts.map +1 -1
- package/dist/core/fast-model-variants.js +3 -0
- package/dist/core/fast-model-variants.js.map +1 -1
- package/dist/core/index.d.ts +4 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +2 -0
- package/dist/core/index.js.map +1 -1
- package/dist/core/mandatory-resource-loader.d.ts +4 -0
- package/dist/core/mandatory-resource-loader.d.ts.map +1 -1
- package/dist/core/mandatory-resource-loader.js +29 -1
- package/dist/core/mandatory-resource-loader.js.map +1 -1
- package/dist/core/mandatory-runtime-tools.d.ts +1 -4
- package/dist/core/mandatory-runtime-tools.d.ts.map +1 -1
- package/dist/core/mandatory-runtime-tools.js +1 -9
- package/dist/core/mandatory-runtime-tools.js.map +1 -1
- package/dist/core/messages.d.ts.map +1 -1
- package/dist/core/messages.js +8 -1
- package/dist/core/messages.js.map +1 -1
- package/dist/core/model-config.d.ts +41 -10
- package/dist/core/model-config.d.ts.map +1 -1
- package/dist/core/model-config.js +11 -2
- package/dist/core/model-config.js.map +1 -1
- package/dist/core/model-registry.d.ts +4 -2
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +6 -2
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-routing-constraints.d.ts +24 -0
- package/dist/core/model-routing-constraints.d.ts.map +1 -0
- package/dist/core/model-routing-constraints.js +46 -0
- package/dist/core/model-routing-constraints.js.map +1 -0
- package/dist/core/model-routing-task.d.ts +4 -0
- package/dist/core/model-routing-task.d.ts.map +1 -0
- package/dist/core/model-routing-task.js +76 -0
- package/dist/core/model-routing-task.js.map +1 -0
- package/dist/core/model-runtime-streaming.d.ts +13 -3
- package/dist/core/model-runtime-streaming.d.ts.map +1 -1
- package/dist/core/model-runtime-streaming.js +15 -5
- package/dist/core/model-runtime-streaming.js.map +1 -1
- package/dist/core/model-runtime-types.d.ts +2 -2
- package/dist/core/model-runtime-types.d.ts.map +1 -1
- package/dist/core/model-runtime-types.js.map +1 -1
- package/dist/core/model-runtime.d.ts +6 -3
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +29 -2
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/provider-composer-internal.d.ts +3 -2
- package/dist/core/provider-composer-internal.d.ts.map +1 -1
- package/dist/core/provider-composer-internal.js +2 -0
- package/dist/core/provider-composer-internal.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts +2 -0
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +23 -1
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/resource-loader-core.d.ts +6 -0
- package/dist/core/resource-loader-core.d.ts.map +1 -1
- package/dist/core/resource-loader-core.js +37 -6
- package/dist/core/resource-loader-core.js.map +1 -1
- package/dist/core/resource-loader-extensions.d.ts.map +1 -1
- package/dist/core/resource-loader-extensions.js +2 -0
- package/dist/core/resource-loader-extensions.js.map +1 -1
- package/dist/core/resource-loader-reload.d.ts.map +1 -1
- package/dist/core/resource-loader-reload.js +7 -2
- package/dist/core/resource-loader-reload.js.map +1 -1
- package/dist/core/resource-loader.d.ts +1 -1
- package/dist/core/resource-loader.d.ts.map +1 -1
- package/dist/core/resource-loader.js +1 -1
- package/dist/core/resource-loader.js.map +1 -1
- package/dist/core/runtime-credentials.d.ts +2 -0
- package/dist/core/runtime-credentials.d.ts.map +1 -1
- package/dist/core/runtime-credentials.js +15 -0
- package/dist/core/runtime-credentials.js.map +1 -1
- package/dist/core/sdk-types.d.ts +13 -5
- package/dist/core/sdk-types.d.ts.map +1 -1
- package/dist/core/sdk-types.js.map +1 -1
- package/dist/core/sdk.d.ts +3 -1
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +211 -37
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-lifecycle-scope.d.ts +15 -0
- package/dist/core/session-lifecycle-scope.d.ts.map +1 -0
- package/dist/core/session-lifecycle-scope.js +13 -0
- package/dist/core/session-lifecycle-scope.js.map +1 -0
- package/dist/core/session-lifecycle-work.d.ts +17 -0
- package/dist/core/session-lifecycle-work.d.ts.map +1 -0
- package/dist/core/session-lifecycle-work.js +144 -0
- package/dist/core/session-lifecycle-work.js.map +1 -0
- package/dist/core/session-manager-core.d.ts +8 -4
- package/dist/core/session-manager-core.d.ts.map +1 -1
- package/dist/core/session-manager-core.js +27 -3
- package/dist/core/session-manager-core.js.map +1 -1
- package/dist/core/session-manager-history.d.ts.map +1 -1
- package/dist/core/session-manager-history.js +3 -0
- package/dist/core/session-manager-history.js.map +1 -1
- package/dist/core/session-manager-list.d.ts +3 -3
- package/dist/core/session-manager-list.d.ts.map +1 -1
- package/dist/core/session-manager-list.js +89 -74
- package/dist/core/session-manager-list.js.map +1 -1
- package/dist/core/session-manager-storage.d.ts.map +1 -1
- package/dist/core/session-manager-storage.js +10 -7
- package/dist/core/session-manager-storage.js.map +1 -1
- package/dist/core/session-manager-types.d.ts +13 -3
- package/dist/core/session-manager-types.d.ts.map +1 -1
- package/dist/core/session-manager-types.js.map +1 -1
- package/dist/core/session-manager.d.ts +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-startup-rollback.d.ts +5 -0
- package/dist/core/session-startup-rollback.d.ts.map +1 -0
- package/dist/core/session-startup-rollback.js +16 -0
- package/dist/core/session-startup-rollback.js.map +1 -0
- package/dist/core/settings-manager-basic-accessors.d.ts +5 -0
- package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
- package/dist/core/settings-manager-basic-accessors.js +35 -0
- package/dist/core/settings-manager-basic-accessors.js.map +1 -1
- package/dist/core/settings-manager-core.d.ts.map +1 -1
- package/dist/core/settings-manager-core.js +4 -0
- package/dist/core/settings-manager-core.js.map +1 -1
- package/dist/core/settings-manager.d.ts +1 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +1 -0
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/settings-types.d.ts +4 -0
- package/dist/core/settings-types.d.ts.map +1 -1
- package/dist/core/settings-types.js +1 -1
- package/dist/core/settings-types.js.map +1 -1
- package/dist/core/settings-write-ownership.d.ts +7 -0
- package/dist/core/settings-write-ownership.d.ts.map +1 -0
- package/dist/core/settings-write-ownership.js +24 -0
- package/dist/core/settings-write-ownership.js.map +1 -0
- package/dist/core/slash-commands.js +1 -1
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/structured-output/index.d.ts +12 -0
- package/dist/core/structured-output/index.d.ts.map +1 -0
- package/dist/core/structured-output/index.js +251 -0
- package/dist/core/structured-output/index.js.map +1 -0
- package/dist/core/structured-output/invalid-output.d.ts +8 -0
- package/dist/core/structured-output/invalid-output.d.ts.map +1 -0
- package/dist/core/structured-output/invalid-output.js +4 -0
- package/dist/core/structured-output/invalid-output.js.map +1 -0
- package/dist/core/structured-output/jev-client.d.ts +20 -0
- package/dist/core/structured-output/jev-client.d.ts.map +1 -0
- package/dist/core/structured-output/jev-client.js +116 -0
- package/dist/core/structured-output/jev-client.js.map +1 -0
- package/dist/core/structured-output/jev.d.ts +5 -0
- package/dist/core/structured-output/jev.d.ts.map +1 -0
- package/dist/core/structured-output/jev.js +275 -0
- package/dist/core/structured-output/jev.js.map +1 -0
- package/dist/core/structured-output/resolver.d.ts +41 -0
- package/dist/core/structured-output/resolver.d.ts.map +1 -0
- package/dist/core/structured-output/resolver.js +56 -0
- package/dist/core/structured-output/resolver.js.map +1 -0
- package/dist/core/structured-output/types.d.ts +68 -0
- package/dist/core/structured-output/types.d.ts.map +1 -0
- package/dist/core/structured-output/types.js +2 -0
- package/dist/core/structured-output/types.js.map +1 -0
- package/dist/core/system-prompt.d.ts +48 -5
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +130 -99
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tasks/contracts.d.ts +6 -0
- package/dist/core/tasks/contracts.d.ts.map +1 -1
- package/dist/core/tasks/contracts.js.map +1 -1
- package/dist/core/tasks/supervisor.d.ts.map +1 -1
- package/dist/core/tasks/supervisor.js +7 -0
- package/dist/core/tasks/supervisor.js.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts +4 -1
- package/dist/core/tools/ask-user-question/ask-user-question.d.ts.map +1 -1
- package/dist/core/tools/ask-user-question/ask-user-question.js +31 -35
- package/dist/core/tools/ask-user-question/ask-user-question.js.map +1 -1
- package/dist/core/tools/ask-user-question/index.d.ts +1 -1
- package/dist/core/tools/ask-user-question/index.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/build-questionnaire.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/key-router.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/key-router.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/questionnaire-session.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/row-intent.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/row-intent.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/contract.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/contract.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/derivations.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/selectors/derivations.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/state-reducer.js.map +1 -1
- package/dist/core/tools/ask-user-question/state/state.d.ts +1 -1
- package/dist/core/tools/ask-user-question/state/state.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/format-answer.d.ts +1 -1
- package/dist/core/tools/ask-user-question/tool/format-answer.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/response-envelope.d.ts +1 -1
- package/dist/core/tools/ask-user-question/tool/response-envelope.js.map +1 -1
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.d.ts +1 -1
- package/dist/core/tools/ask-user-question/tool/validate-questionnaire.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/multi-select-view.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/markdown-content-cache.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-block-renderer.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-layout-decider.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/components/preview/preview-pane.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/submit-picker.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/components/wrapping-select.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/dialog-builder.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/dialog-builder.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/props-adapter.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/props-adapter.js.map +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.d.ts +1 -1
- package/dist/core/tools/ask-user-question/view/tab-content-strategy.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +16 -11
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/find.d.ts +2 -2
- package/dist/core/tools/find.d.ts.map +1 -1
- package/dist/core/tools/find.js +1 -1
- package/dist/core/tools/find.js.map +1 -1
- package/dist/core/usage-totals.d.ts.map +1 -1
- package/dist/core/usage-totals.js +4 -0
- package/dist/core/usage-totals.js.map +1 -1
- package/dist/extensions/herdr/index.d.ts.map +1 -1
- package/dist/extensions/herdr/index.js +0 -7
- package/dist/extensions/herdr/index.js.map +1 -1
- package/dist/extensions/llama/client.d.ts +2 -0
- package/dist/extensions/llama/client.d.ts.map +1 -1
- package/dist/extensions/llama/client.js +6 -2
- package/dist/extensions/llama/client.js.map +1 -1
- package/dist/extensions/llama/provider.d.ts.map +1 -1
- package/dist/extensions/llama/provider.js +18 -4
- package/dist/extensions/llama/provider.js.map +1 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/main-session.d.ts.map +1 -1
- package/dist/main-session.js +19 -10
- package/dist/main-session.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +4 -5
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +12 -5
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts +5 -1
- package/dist/modes/interactive/components/chat-message-renderer.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-message-renderer.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host-events.d.ts +2 -2
- package/dist/modes/interactive/components/chat-session-host-events.js.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-boundary-message.js +17 -9
- package/dist/modes/interactive/components/compaction-boundary-message.js.map +1 -1
- package/dist/modes/interactive/components/custom-editor.d.ts +6 -0
- package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-editor.js +17 -0
- package/dist/modes/interactive/components/custom-editor.js.map +1 -1
- package/dist/modes/interactive/components/host-input-form-mount.d.ts +1 -1
- package/dist/modes/interactive/components/host-input-form-mount.js.map +1 -1
- package/dist/modes/interactive/components/host-input-form.d.ts +1 -1
- package/dist/modes/interactive/components/host-input-form.js.map +1 -1
- package/dist/modes/interactive/components/host-session-picker.d.ts +1 -1
- package/dist/modes/interactive/components/host-session-picker.js.map +1 -1
- package/dist/modes/interactive/components/reserved-bottom-overlay.d.ts +1 -1
- package/dist/modes/interactive/components/reserved-bottom-overlay.js.map +1 -1
- package/dist/modes/interactive/components/scroll-widget.d.ts +1 -1
- package/dist/modes/interactive/components/scroll-widget.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-handlers.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-handlers.js +3 -0
- package/dist/modes/interactive/components/settings-selector-handlers.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-items.js +50 -1
- package/dist/modes/interactive/components/settings-selector-items.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-submenus.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-submenus.js +2 -1
- package/dist/modes/interactive/components/settings-selector-submenus.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts +6 -1
- package/dist/modes/interactive/components/settings-selector-types.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +11 -4
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +14 -9
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-login.js +1 -1
- package/dist/modes/interactive/interactive-auth-login.js.map +1 -1
- package/dist/modes/interactive/interactive-auth-routing.js +2 -2
- package/dist/modes/interactive/interactive-auth-routing.js.map +1 -1
- package/dist/modes/interactive/interactive-autocomplete.js +4 -0
- package/dist/modes/interactive/interactive-autocomplete.js.map +1 -1
- package/dist/modes/interactive/interactive-bash-compact.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-bash-compact.js +13 -6
- package/dist/modes/interactive/interactive-bash-compact.js.map +1 -1
- package/dist/modes/interactive/interactive-extension-runtime.js +5 -0
- package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
- package/dist/modes/interactive/interactive-input-handling.js +2 -2
- package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-deps.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js +1 -1
- package/dist/modes/interactive/interactive-mode-deps.js.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
- package/dist/modes/interactive/interactive-render-chat.js +27 -25
- package/dist/modes/interactive/interactive-render-chat.js.map +1 -1
- package/dist/modes/interactive/interactive-selectors.js +10 -0
- package/dist/modes/interactive/interactive-selectors.js.map +1 -1
- package/dist/modes/interactive/interactive-startup.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-startup.js +2 -2
- package/dist/modes/interactive/interactive-startup.js.map +1 -1
- package/dist/modes/interactive/interactive-tui.js.map +1 -1
- package/dist/modes/interactive-engine/engine-custom-ui.d.ts.map +1 -1
- package/dist/modes/interactive-engine/engine-custom-ui.js +3 -1
- package/dist/modes/interactive-engine/engine-custom-ui.js.map +1 -1
- package/dist/modes/interactive-engine/engine-input-form.d.ts +1 -1
- package/dist/modes/interactive-engine/engine-input-form.js.map +1 -1
- package/dist/modes/interactive-engine/engine-session-picker.d.ts +1 -1
- package/dist/modes/interactive-engine/engine-session-picker.js.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
- package/dist/modes/interactive-engine/isolated-runtime.js +10 -1
- package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
- package/dist/modes/interactive-engine/protocol.d.ts +1 -1
- package/dist/modes/interactive-engine/protocol.js.map +1 -1
- package/dist/modes/interactive-engine/remote-component.js.map +1 -1
- package/dist/modes/rpc/rpc-keybindings-reload.d.ts +1 -1
- package/dist/modes/rpc/rpc-keybindings-reload.js.map +1 -1
- package/dist/modes/rpc/rpc-provider-auth.d.ts +1 -1
- package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
- package/dist/session-id-target.d.ts +31 -0
- package/dist/session-id-target.d.ts.map +1 -0
- package/dist/session-id-target.js +57 -0
- package/dist/session-id-target.js.map +1 -0
- package/dist/utils/abort.d.ts.map +1 -1
- package/dist/utils/abort.js +29 -4
- package/dist/utils/abort.js.map +1 -1
- package/dist/utils/clipboard-image.d.ts.map +1 -1
- package/dist/utils/clipboard-image.js +1 -12
- package/dist/utils/clipboard-image.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +87 -23
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/wsl.d.ts +3 -0
- package/dist/utils/wsl.d.ts.map +1 -0
- package/dist/utils/wsl.js +15 -0
- package/dist/utils/wsl.js.map +1 -0
- package/docs/background-tasks.md +24 -14
- package/docs/build.md +6 -16
- package/docs/compaction/reference.md +10 -12
- package/docs/compaction.md +30 -112
- package/docs/computer-use.md +1 -3
- package/docs/containerization.md +4 -5
- package/docs/custom-provider/api-reference.md +10 -1
- package/docs/custom-provider/oauth.md +4 -2
- package/docs/custom-provider/streaming.md +8 -3
- package/docs/custom-provider.md +1 -1
- package/docs/development.md +13 -138
- package/docs/docs.json +19 -5
- package/docs/environment-variables.md +20 -4
- package/docs/extensions/api-reference.md +6 -2
- package/docs/extensions/authoring.md +10 -7
- package/docs/extensions/events.md +14 -24
- package/docs/extensions/ui.md +3 -4
- package/docs/extensions.md +22 -18
- package/docs/getting-started/authentication.md +4 -1
- package/docs/getting-started/first-session.md +8 -6
- package/docs/getting-started/installation.md +8 -4
- package/docs/getting-started/project-instructions.md +5 -1
- package/docs/guides/configuration.md +10 -5
- package/docs/guides/non-interactive.md +2 -2
- package/docs/guides.md +8 -17
- package/docs/herdr.md +2 -1
- package/docs/index.md +2 -2
- package/docs/intercom/operations.md +16 -70
- package/docs/intercom/reference.md +15 -5
- package/docs/intercom.md +10 -6
- package/docs/json.md +12 -2
- package/docs/keybindings.md +13 -8
- package/docs/llama-cpp.md +5 -1
- package/docs/{mcp.md → mcp-servers.md} +21 -2
- package/docs/models/evals.md +133 -465
- package/docs/models/model-selection.md +27 -116
- package/docs/models/reference.md +18 -21
- package/docs/models.md +7 -4
- package/docs/packages/authoring.md +5 -1
- package/docs/packages/reference.md +5 -1
- package/docs/packages.md +5 -3
- package/docs/programmatic.md +3 -1
- package/docs/prompt-templates.md +2 -10
- package/docs/providers/reference.md +2 -2
- package/docs/providers.md +41 -16
- package/docs/quickstart.md +7 -3
- package/docs/reference/cli.md +19 -11
- package/docs/reference.md +3 -6
- package/docs/rpc/protocol.md +11 -13
- package/docs/rpc.md +5 -1
- package/docs/sdk/reference.md +59 -239
- package/docs/sdk/structured-decisions.md +132 -0
- package/docs/sdk.md +181 -17
- package/docs/security.md +7 -4
- package/docs/session-format.md +18 -5
- package/docs/sessions.md +12 -6
- package/docs/settings.md +68 -16
- package/docs/skills/authoring.md +7 -1
- package/docs/skills.md +25 -6
- package/docs/subagents/authoring.md +11 -1
- package/docs/subagents/reference.md +98 -10
- package/docs/subagents.md +45 -35
- package/docs/terminal-setup.md +4 -2
- package/docs/termux.md +3 -1
- package/docs/themes/reference.md +4 -1
- package/docs/themes.md +1 -1
- package/docs/tools.md +431 -20
- package/docs/tui/reference.md +13 -14
- package/docs/tui.md +10 -6
- package/docs/usage.md +19 -7
- package/docs/web-access.md +5 -1
- package/docs/windows.md +18 -11
- package/docs/workflows/api-reference.md +135 -25
- package/docs/workflows/authoring.md +48 -39
- package/docs/workflows/builtins.md +20 -26
- package/docs/workflows/operations.md +284 -137
- package/docs/workflows/reliable-design.md +62 -129
- package/docs/workflows.md +10 -16
- package/examples/extensions/custom-provider-anthropic/index.ts +15 -10
- package/examples/extensions/custom-provider-gitlab-duo/index.ts +2 -2
- package/examples/extensions/prompt-customizer.ts +17 -37
- package/npm-shrinkwrap.json +502 -709
- package/package.json +12 -10
- package/dist/builtin/workflows/builtin/chunk-m0xfsef8.js +0 -2813
- package/docs/models/artificial-analysis-index.md +0 -89
- package/docs/models/pareto-efficiency.md +0 -90
- package/docs/tools/edit.md +0 -378
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-state.js","sourceRoot":"","sources":["../../src/core/agent-session-state.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,8BAA8B,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtG,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAEvD,MAAM,UAAU,kBAAkB;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AAEH,MAAM,UAAU,WAAW;IAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QACtF,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,qBAAqB,CAAC;YACnD,CAAC,CAAC,EAAE,mBAAmB,EAAE,UAAU,CAAC,mBAAmB,EAAE;YACzD,CAAC,CAAC,EAAE,CAAC;QACN,gBAAgB,EAAE,UAAU,CAAC,gBAAgB;Q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BAAgB,CAAC;AACvG,CAAC;AAED,MAAM,UAAU,uCAAuC;IACtD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAC9E,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,YAAY,GAAG,IAAI,CAAC,qBAAqB,IAAI,IAAI,CAAC,iBAAiB,CAAC;AACtF,CAAC;AAED,4EAA4E;AAC5E,YAAY;AACZ,4EAA4E;AAE5E;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,kBAAkB;IAClB,WAAW;IACX,iBAAiB;IACjB,oBAAoB;IACpB,eAAe;IACf,uBAAuB;IACvB,0BAA0B;IAC1B,oBAAoB;IACpB,uCAAuC;CACvC,CAAC","sourcesContent":["import type { Api, Model } from \"@bastani/pi-ai/compat\";\nimport type { AgentTool, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport type { ToolDefinition, ToolInfo } from \"./extensions/index.js\";\nimport { appendRegisteredMandatoryTools, isMandatoryRuntimeTool } from \"./mandatory-runtime-tools.ts\";\nimport { getSkillCatalog } from \"./skill-catalog.ts\";\nimport { buildSystemPrompt } from \"./system-prompt.ts\";\n\nexport function getActiveToolNames(this: AgentSession): string[] {\n\treturn this.agent.state.tools.map((t) => t.name);\n}\n\n/**\n * Get all configured tools with name, description, parameter schema, and source metadata.\n */\n\nexport function getAllTools(this: AgentSession): ToolInfo[] {\n\treturn Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({\n\t\tname: definition.name,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\t...(Object.hasOwn(definition, \"constrainedSampling\")\n\t\t\t? { constrainedSampling: definition.constrainedSampling }\n\t\t\t: {}),\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t\tsourceInfo,\n\t}));\n}\n\nexport function getToolDefinition(this: AgentSession, name: string): ToolDefinition | undefined {\n\treturn this._toolDefinitions.get(name)?.definition;\n}\n\n/**\n * Set active tools by name.\n * Only tools in the registry can be enabled. Unknown tool names are ignored.\n * Also rebuilds the system prompt to reflect the new tool set.\n * Changes take effect on the next agent turn.\n */\n\nexport function setActiveToolsByName(this: AgentSession, toolNames: string[]): void {\n\tconst tools: AgentTool[] = [];\n\tfor (const name of toolNames) {\n\t\tconst tool = this._toolRegistry.get(name);\n\t\tif (tool) tools.push(tool);\n\t}\n\tappendRegisteredMandatoryTools(tools, this._toolRegistry);\n\tconst validToolNames = tools.map((tool) => tool.name);\n\tthis.agent.state.tools = tools;\n\n\t// Rebuild base system prompt with new tool set\n\tthis._baseSystemPrompt = this._rebuildSystemPrompt(validToolNames);\n\tthis.agent.state.systemPrompt = this._systemPromptOverride ?? this._baseSystemPrompt;\n}\n\n/** Whether compaction or branch summarization is currently running */\n\nexport function setScopedModels(\n\tthis: AgentSession,\n\tscopedModels: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>,\n): void {\n\tthis._scopedModels = scopedModels;\n}\n\n/** File-based prompt templates */\n\nexport function _normalizePromptSnippet(this: AgentSession, text: string | undefined): string | undefined {\n\tif (!text) return undefined;\n\tconst oneLine = text\n\t\t.replace(/[\\r\\n]+/g, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n\treturn oneLine.length > 0 ? oneLine : undefined;\n}\n\nexport function _normalizePromptGuidelines(this: AgentSession, guidelines: string[] | undefined): string[] {\n\tif (!guidelines || guidelines.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst unique = new Set<string>();\n\tfor (const guideline of guidelines) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\tunique.add(normalized);\n\t\t}\n\t}\n\treturn Array.from(unique);\n}\n\nexport function _rebuildSystemPrompt(this: AgentSession, toolNames: string[]): string {\n\tconst validToolNames = toolNames.filter((name) => this._toolRegistry.has(name));\n\tconst toolSnippets: Record<string, string> = {};\n\tconst promptGuidelines: string[] = [];\n\tfor (const name of validToolNames) {\n\t\tconst snippet = this._toolPromptSnippets.get(name);\n\t\tif (snippet) {\n\t\t\ttoolSnippets[name] = snippet;\n\t\t}\n\n\t\tconst toolGuidelines = this._toolPromptGuidelines.get(name);\n\t\tif (toolGuidelines) {\n\t\t\tpromptGuidelines.push(...toolGuidelines);\n\t\t}\n\t}\n\n\tconst loaderSystemPrompt = this._resourceLoader.getSystemPrompt();\n\tconst loaderAppendSystemPrompt = this._resourceLoader.getAppendSystemPrompt();\n\tconst appendSystemPrompt = loaderAppendSystemPrompt.length > 0 ? loaderAppendSystemPrompt.join(\"\\n\\n\") : undefined;\n\tconst loadedSkills = getSkillCatalog(this._resourceLoader).modelSkills();\n\tconst loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;\n\n\tthis._baseSystemPromptOptions = {\n\t\tcwd: this._cwd,\n\t\tselectedModel: this.model,\n\t\tselectedThinkingLevel: this.thinkingLevel,\n\t\tskills: loadedSkills,\n\t\tcontextFiles: loadedContextFiles,\n\t\tcustomPrompt: loaderSystemPrompt,\n\t\tappendSystemPrompt,\n\t\tselectedTools: validToolNames,\n\t\texcludedTools: this._excludedToolNames\n\t\t\t? Array.from(this._excludedToolNames).filter((name) => !isMandatoryRuntimeTool(name))\n\t\t\t: undefined,\n\t\ttoolSnippets,\n\t\tpromptGuidelines,\n\t};\n\tconst baseSystemPrompt = buildSystemPrompt(this._baseSystemPromptOptions);\n\treturn this._systemPromptTransform ? this._systemPromptTransform(baseSystemPrompt) : baseSystemPrompt;\n}\n\nexport function _refreshBaseSystemPromptFromActiveTools(this: AgentSession): void {\n\tthis._baseSystemPrompt = this._rebuildSystemPrompt(this.getActiveToolNames());\n\tthis.agent.state.systemPrompt = this._systemPromptOverride ?? this._baseSystemPrompt;\n}\n\n// =========================================================================\n// Prompting\n// =========================================================================\n\n/**\n * Send a prompt to the agent.\n * - Handles extension commands (registered via pi.registerCommand) immediately, even during streaming\n * - Expands file-based prompt templates by default\n * - During streaming, queues via steer() or followUp() based on streamingBehavior option\n * - Validates model and API key before sending (when not streaming)\n * @throws Error if streaming and no streamingBehavior specified\n * @throws Error if no model selected or no API key available (when not streaming)\n */\n\nexport const agentSessionStateMethods = {\n\tgetActiveToolNames,\n\tgetAllTools,\n\tgetToolDefinition,\n\tsetActiveToolsByName,\n\tsetScopedModels,\n\t_normalizePromptSnippet,\n\t_normalizePromptGuidelines,\n\t_rebuildSystemPrompt,\n\t_refreshBaseSystemPromptFromActiveTools,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-state.js","sourceRoot":"","sources":["../../src/core/agent-session-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAsB,MAAM,gBAAgB,CAAC;AAK7E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EACN,iBAAiB,EACjB,yBAAyB,EACzB,wBAAwB,EAExB,iCAAiC,GACjC,MAAM,oBAAoB,CAAC;AAE5B,MAAM,UAAU,kBAAkB;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AAEH,MAAM,UAAU,WAAW;IAC1B,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC;QACtF,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,WAAW,EAAE,UAAU,CAAC,WAAW;QACnC,UAAU,EAAE,UAAU,CAAC,UAAU;QACjC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,qBAAqB,CAAC;YACnD,CAAC,CAAC,EAAE,mBAAmB,EAAE,UAAU,CAAC,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AAED,4EAA4E;AAC5E,YAAY;AACZ,4EAA4E;AAE5E;;;;;;;;GAQG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACvC,kBAAkB;IAClB,WAAW;IACX,iBAAiB;IACjB,oBAAoB;IACpB,eAAe;IACf,uBAAuB;IACvB,0BAA0B;IAC1B,oBAAoB;IACpB,4BAA4B;IAC5B,2BAA2B;IAC3B,uCAAuC;CACvC,CAAC","sourcesContent":["import { getCurrentSystemMessage, type SystemMessage } from \"@bastani/pi-ai\";\nimport type { Api, Model } from \"@bastani/pi-ai/compat\";\nimport type { AgentMessage, AgentTool, ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport type { ToolDefinition, ToolInfo } from \"./extensions/index.js\";\nimport { getSkillCatalog } from \"./skill-catalog.ts\";\nimport {\n\tbuildSystemPrompt,\n\tbuildSystemPromptSections,\n\tdiffSystemPromptSections,\n\ttype NormalizedBuildSystemPromptOptions,\n\tnormalizeBuildSystemPromptOptions,\n} from \"./system-prompt.ts\";\n\nexport function getActiveToolNames(this: AgentSession): string[] {\n\treturn this.agent.state.tools.map((t) => t.name);\n}\n\n/**\n * Get all configured tools with name, description, parameter schema, and source metadata.\n */\n\nexport function getAllTools(this: AgentSession): ToolInfo[] {\n\treturn Array.from(this._toolDefinitions.values()).map(({ definition, sourceInfo }) => ({\n\t\tname: definition.name,\n\t\tdescription: definition.description,\n\t\tparameters: definition.parameters,\n\t\t...(Object.hasOwn(definition, \"constrainedSampling\")\n\t\t\t? { constrainedSampling: definition.constrainedSampling }\n\t\t\t: {}),\n\t\tpromptGuidelines: definition.promptGuidelines,\n\t\tsourceInfo,\n\t}));\n}\n\nexport function getToolDefinition(this: AgentSession, name: string): ToolDefinition | undefined {\n\treturn this._toolDefinitions.get(name)?.definition;\n}\n\n/**\n * Set active tools by name.\n * Only tools in the registry can be enabled. Unknown tool names are ignored.\n * Also rebuilds the system prompt to reflect the new tool set.\n * Changes take effect on the next agent turn.\n */\n\nexport function setActiveToolsByName(this: AgentSession, toolNames: string[]): void {\n\tconst tools: AgentTool[] = [];\n\tfor (const name of toolNames) {\n\t\tconst tool = this._toolRegistry.get(name);\n\t\tif (tool) tools.push(tool);\n\t}\n\tconst validToolNames = tools.map((tool) => tool.name);\n\tthis.agent.state.tools = tools;\n\n\tthis._rebuildSystemPrompt(validToolNames);\n}\n\n/** Whether compaction or branch summarization is currently running */\n\nexport function setScopedModels(\n\tthis: AgentSession,\n\tscopedModels: Array<{ model: Model<Api>; thinkingLevel?: ThinkingLevel }>,\n): void {\n\tthis._scopedModels = scopedModels;\n}\n\n/** File-based prompt templates */\n\nexport function _normalizePromptSnippet(this: AgentSession, text: string | undefined): string | undefined {\n\tif (!text) return undefined;\n\tconst oneLine = text\n\t\t.replace(/[\\r\\n]+/g, \" \")\n\t\t.replace(/\\s+/g, \" \")\n\t\t.trim();\n\treturn oneLine.length > 0 ? oneLine : undefined;\n}\n\nexport function _normalizePromptGuidelines(this: AgentSession, guidelines: string[] | undefined): string[] {\n\tif (!guidelines || guidelines.length === 0) {\n\t\treturn [];\n\t}\n\n\tconst unique = new Set<string>();\n\tfor (const guideline of guidelines) {\n\t\tconst normalized = guideline.trim();\n\t\tif (normalized.length > 0) {\n\t\t\tunique.add(normalized);\n\t\t}\n\t}\n\treturn Array.from(unique);\n}\n\nexport function _rebuildSystemPrompt(this: AgentSession, toolNames: string[]): void {\n\tconst validToolNames = toolNames.filter((name) => this._toolRegistry.has(name));\n\tconst toolSnippets: Record<string, string> = {};\n\tfor (const name of this._toolRegistry.keys()) {\n\t\tconst snippet = this._toolPromptSnippets.get(name);\n\t\tif (snippet) {\n\t\t\ttoolSnippets[name] = snippet;\n\t\t}\n\t}\n\n\tconst loaderSystemPrompt = this._resourceLoader.getSystemPrompt();\n\tconst loaderAppendSystemPrompt = this._resourceLoader.getAppendSystemPrompt();\n\tconst appendSystemPrompt = loaderAppendSystemPrompt.length > 0 ? loaderAppendSystemPrompt.join(\"\\n\\n\") : undefined;\n\tconst loadedSkills = getSkillCatalog(this._resourceLoader).modelSkills();\n\tconst loadedContextFiles = this._resourceLoader.getAgentsFiles().agentsFiles;\n\n\tthis._baseSystemPromptOptions = normalizeBuildSystemPromptOptions({\n\t\tcwd: this._cwd,\n\t\tselectedModel: this.model,\n\t\tselectedThinkingLevel: this.thinkingLevel,\n\t\tskills: loadedSkills,\n\t\tcontextFiles: loadedContextFiles,\n\t\tcustomPrompt: loaderSystemPrompt,\n\t\tappendSystemPrompt,\n\t\tselectedTools: validToolNames,\n\t\texcludedTools: this._excludedToolNames ? Array.from(this._excludedToolNames) : undefined,\n\t\ttoolSnippets,\n\t\ttoolGuidelines: Object.fromEntries(this._toolPromptGuidelines),\n\t});\n\tif (this._systemPromptTransform) {\n\t\tthis._baseSystemPromptOptions.forceSystemPrompt = this._systemPromptTransform(\n\t\t\tbuildSystemPrompt(this._baseSystemPromptOptions),\n\t\t);\n\t}\n}\n\nexport function _refreshBaseSystemPromptFromActiveTools(this: AgentSession): void {\n\tthis._rebuildSystemPrompt(this.getActiveToolNames());\n}\n\n/** Diff structured prompt state; executable tool changes are declared by the agent loop. */\nexport function _preparePromptAndToolLoadout(\n\tthis: AgentSession,\n\toptions: NormalizedBuildSystemPromptOptions,\n\tmessages: AgentMessage[] = this.agent.state.messages,\n): SystemMessage | undefined {\n\toptions.selectedTools = [...new Set(options.selectedTools)].filter((name) => this._toolRegistry.has(name));\n\tthis.agent.state.tools = options.selectedTools.flatMap((name) => {\n\t\tconst tool = this._toolRegistry.get(name);\n\t\treturn tool ? [tool] : [];\n\t});\n\tconst sections = diffSystemPromptSections(\n\t\tgetCurrentSystemMessage(messages)?.sections ?? {},\n\t\tbuildSystemPromptSections(options),\n\t);\n\treturn sections ? { role: \"system\", content: \"\", sections, timestamp: Date.now() } : undefined;\n}\n\n/** Restore registered tools from the selected transcript, not another branch's live state. */\nexport function _restoreToolsFromTranscript(this: AgentSession): void {\n\tconst current = getCurrentSystemMessage(this.sessionManager.buildSessionContext().messages);\n\tif (!current) return;\n\tconst names = (current.toolsAdded ?? []).map((tool) => tool.name).filter((name) => this._toolRegistry.has(name));\n\tthis.setActiveToolsByName(names);\n}\n\n// =========================================================================\n// Prompting\n// =========================================================================\n\n/**\n * Send a prompt to the agent.\n * - Handles extension commands (registered via pi.registerCommand) immediately, even during streaming\n * - Expands file-based prompt templates by default\n * - During streaming, queues via steer() or followUp() based on streamingBehavior option\n * - Validates model and API key before sending (when not streaming)\n * @throws Error if streaming and no streamingBehavior specified\n * @throws Error if no model selected or no API key available (when not streaming)\n */\n\nexport const agentSessionStateMethods = {\n\tgetActiveToolNames,\n\tgetAllTools,\n\tgetToolDefinition,\n\tsetActiveToolsByName,\n\tsetScopedModels,\n\t_normalizePromptSnippet,\n\t_normalizePromptGuidelines,\n\t_rebuildSystemPrompt,\n\t_preparePromptAndToolLoadout,\n\t_restoreToolsFromTranscript,\n\t_refreshBaseSystemPromptFromActiveTools,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-summary.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-summary.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-session-summary.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-summary.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAQ9F,gGAAgG;AAChG,MAAM,MAAM,iBAAiB,GAAG;IAC/B,qDAAqD;IACrD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B,CAAC;AAEF,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAI9E;AAiID,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAe5D;AAED,eAAO,MAAM,0BAA0B;;;CAAwD,CAAC"}
|
|
@@ -5,10 +5,17 @@
|
|
|
5
5
|
* persists the result. Generation itself lives in core/compaction/session-summarization.ts.
|
|
6
6
|
*/
|
|
7
7
|
import { generateSessionSummary } from "./compaction/index.js";
|
|
8
|
+
import { sessionGenerationClosing, sessionLifetime, trackSessionWork } from "./session-lifecycle-work.js";
|
|
8
9
|
import { getLastConversationMessageId, getLatestSessionSummary } from "./session-manager-entries.js";
|
|
9
10
|
/** Sessions shorter than this are already legible from their first message. */
|
|
10
11
|
const MIN_ENTRIES_FOR_SUMMARY = 4;
|
|
11
|
-
export
|
|
12
|
+
export function _maybeGenerateSessionSummary() {
|
|
13
|
+
if (this._disposed || sessionGenerationClosing.has(this))
|
|
14
|
+
return Promise.resolve();
|
|
15
|
+
// Keep every launch, including superseded providers, owned until actual settlement.
|
|
16
|
+
return trackSessionWork(this, () => generateOwnedSessionSummary.call(this));
|
|
17
|
+
}
|
|
18
|
+
async function generateOwnedSessionSummary() {
|
|
12
19
|
// Held rather than read from the session in `finally`, so an early return can never clear a
|
|
13
20
|
// controller or run belonging to a different launch.
|
|
14
21
|
let controller;
|
|
@@ -74,7 +81,7 @@ export async function _maybeGenerateSessionSummary() {
|
|
|
74
81
|
this._sessionSummaryAbortController?.abort();
|
|
75
82
|
controller = new AbortController();
|
|
76
83
|
this._sessionSummaryAbortController = controller;
|
|
77
|
-
const signal = controller.signal;
|
|
84
|
+
const signal = AbortSignal.any([controller.signal, sessionLifetime(this)]);
|
|
78
85
|
// Publish this run before the first await that another launch can overlap. From here on
|
|
79
86
|
// ownership of the slot, not the token, is what licenses a write: a joiner bumps the token
|
|
80
87
|
// on its way in, and must not invalidate the very run it is waiting for.
|
|
@@ -1 +1 @@
|
|
|
1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,8BAA8B,KAAK,UAAU,EAAE,CAAC;YACpF,IAAI,CAAC,8BAA8B,GAAG,SAAS,CAAC;QACjD,CAAC;QACD,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,kBAAkB,KAAK,GAAG,EAAE,CAAC;YAC1D,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;QACrC,CAAC;QACD,yFAAyF;QACzF,kCAAkC;QAClC,MAAM,EAAE,EAAE,CAAC;IACZ,CAAC;AACF,CAAC;AAED,MAAM,UAAU,mBAAmB;IAClC,8FAA8F;IAC9F,wEAAwE;IACxE,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC5B,IAAI,CAAC,8BAA8B,EAAE,KAAK,EAAE,CAAC;IAC7C,IAAI,CAAC,8BAA8B,GAAG,SAAS,CAAC;IAChD,8FAA8F;IAC9F,2FAA2F;IAC3F,oDAAoD;IACpD,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;IACpC,wFAAwF;IACxF,yFAAyF;IACzF,2FAA2F;IAC3F,oFAAoF;IACpF,IAAI,CAAC,wBAAwB,GAAG,SAAS,CAAC;AAC3C,CAAC;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAG,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["/**\n * Session summary generation for the resume picker.\n *\n * Runs once the agent goes idle, decides whether a fresh summary is worth generating, and\n * persists the result. Generation itself lives in core/compaction/session-summarization.ts.\n */\n\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { generateSessionSummary } from \"./compaction/index.ts\";\nimport { getLastConversationMessageId, getLatestSessionSummary } from \"./session-manager-entries.ts\";\n\n/** Sessions shorter than this are already legible from their first message. */\nconst MIN_ENTRIES_FOR_SUMMARY = 4;\n\n/** A summary request in flight, published so a launch describing the same state can join it. */\nexport type SessionSummaryRun = {\n\t/** The conversation state this request describes. */\n\treadonly throughId: string;\n\t/** Settles when the request finishes, whatever the outcome. */\n\treadonly done: Promise<void>;\n};\n\nexport async function _maybeGenerateSessionSummary(this: AgentSession): Promise<void> {\n\t// Held rather than read from the session in `finally`, so an early return can never clear a\n\t// controller or run belonging to a different launch.\n\tlet controller: AbortController | undefined;\n\tlet run: SessionSummaryRun | undefined;\n\tlet finish: (() => void) | undefined;\n\ttry {\n\t\t// --- Bail-outs that cannot change while we wait ---------------------------------\n\t\tif (this._disposed) return;\n\t\tif (!this.settingsManager.getSessionSummarySettings().enabled) return;\n\n\t\t// One-shot scripted runs should not pay for a background call; the process may exit before\n\t\t// it lands. \"tui\" and \"rpc\" are the resumable, interactive modes.\n\t\tif (this._extensionMode === \"print\" || this._extensionMode === \"json\") return;\n\n\t\tconst model = this.model;\n\t\tif (!model) return;\n\n\t\t// Workflow-stage sessions are excluded from /resume entirely.\n\t\tif (this.sessionManager.getHeader()?.internal) return;\n\n\t\t// Claim the launch before waiting, so a later turn supersedes this one while both are\n\t\t// parked below.\n\t\tconst sessionSummaryToken = ++this._sessionSummaryToken;\n\n\t\t// `agent_end` fires while the agent still reports isStreaming, and that flag survives the\n\t\t// entire microtask queue — it only clears a macrotask later. Testing it here without\n\t\t// waiting made generation depend on whether `_checkCompaction` happened to cross a\n\t\t// macrotask boundary: green under test, silently skipped in the real TUI, and nothing\n\t\t// retries it.\n\t\tawait this.agent.waitForIdle();\n\n\t\tif (this._disposed) return;\n\t\tif (this._sessionSummaryToken !== sessionSummaryToken) return;\n\t\tif (this.isStreaming || this.isCompacting) return;\n\n\t\tconst branch = this.sessionManager.getBranch();\n\t\tif (branch.length < MIN_ENTRIES_FOR_SUMMARY) return;\n\n\t\tconst throughId = getLastConversationMessageId(branch);\n\t\tif (!throughId) return;\n\n\t\t// On a resumed session the in-memory anchor starts empty, so fall back to the persisted\n\t\t// summary. Without this the first idle after every resume regenerates a summary that is\n\t\t// already current.\n\t\tconst lastSummarized =\n\t\t\tthis._lastSummarizedMessageId ??\n\t\t\tgetLatestSessionSummary(this.sessionManager.getEntries())?.summarizedThroughId;\n\t\tif (throughId === lastSummarized) return;\n\n\t\t// A request already covering this exact conversation state will store the line this launch\n\t\t// would ask for, so wait for it instead of aborting it and paying for a second one.\n\t\t// Overlap is routine rather than exceptional: every turn schedules a launch, and the\n\t\t// previous turn's can still be in flight when the next one wakes.\n\t\tconst inFlight = this._sessionSummaryRun;\n\t\tif (inFlight !== undefined && inFlight.throughId === throughId) {\n\t\t\tawait inFlight.done;\n\t\t\treturn;\n\t\t}\n\n\t\t// Anything still running describes an older conversation state, so retire it and take the\n\t\t// controller. Abort the previous one directly rather than via abortSessionSummary(), which\n\t\t// bumps the token and would invalidate the claim made above. The controller lives on the\n\t\t// session so the prompt, tree-navigation, and shutdown paths can reach it.\n\t\tthis._sessionSummaryAbortController?.abort();\n\t\tcontroller = new AbortController();\n\t\tthis._sessionSummaryAbortController = controller;\n\t\tconst signal = controller.signal;\n\n\t\t// Publish this run before the first await that another launch can overlap. From here on\n\t\t// ownership of the slot, not the token, is what licenses a write: a joiner bumps the token\n\t\t// on its way in, and must not invalidate the very run it is waiting for.\n\t\t// Hand-rolled deferred rather than Promise.withResolvers: coding-agent is the one compiled\n\t\t// package and its lib target predates ES2024, the same reason `_retryPromise` is built this\n\t\t// way. The executor runs synchronously, so `finish` is assigned before the constructor returns.\n\t\tconst done = new Promise<void>((resolve) => {\n\t\t\tfinish = resolve;\n\t\t});\n\t\trun = { throughId, done };\n\t\tthis._sessionSummaryRun = run;\n\n\t\tconst { apiKey, headers, baseUrl } = await this._getRequiredRequestAuth(model);\n\n\t\t// Disposal or a newer turn can land while credentials resolve; nothing past this point\n\t\t// should reach the provider.\n\t\tif (this._disposed || signal.aborted) return;\n\t\tif (this._sessionSummaryRun !== run) return;\n\n\t\tconst result = await generateSessionSummary(branch, {\n\t\t\tmodel,\n\t\t\tapiKey,\n\t\t\theaders,\n\t\t\tbaseUrl,\n\t\t\tsignal,\n\t\t\tstreamFn: this.agent.streamFunction,\n\t\t\tretry: this.settingsManager.getRetrySettings(),\n\t\t});\n\t\t// Failures stay silent: nothing awaits this, and the picker falls back on its own.\n\t\tif (result.aborted || result.error || !result.summary) return;\n\n\t\t// Disposal, cancellation, a newer run, or a newer message all mean this summary no longer\n\t\t// describes the session. The signal is checked directly as well as the token because a\n\t\t// provider that ignores the signal still returns an ordinary result.\n\t\tif (this._disposed) return;\n\t\tif (signal.aborted) return;\n\t\tif (this._sessionSummaryRun !== run) return;\n\t\tif (getLastConversationMessageId(this.sessionManager.getBranch()) !== throughId) return;\n\n\t\tthis.sessionManager.appendSessionSummary(result.summary, throughId, result.usage);\n\t\tthis._lastSummarizedMessageId = throughId;\n\t} catch {\n\t\t// Nothing awaits this call, so an escaping rejection would surface as an unhandled\n\t\t// rejection and can take the process down. Credential resolution throws outright when no\n\t\t// key is configured, which is an ordinary state for a session that never prompts.\n\t} finally {\n\t\tif (controller !== undefined && this._sessionSummaryAbortController === controller) {\n\t\t\tthis._sessionSummaryAbortController = undefined;\n\t\t}\n\t\tif (run !== undefined && this._sessionSummaryRun === run) {\n\t\t\tthis._sessionSummaryRun = undefined;\n\t\t}\n\t\t// Settled on every path, including a throw and every early return above: a joiner parked\n\t\t// on `done` has no other way out.\n\t\tfinish?.();\n\t}\n}\n\nexport function abortSessionSummary(this: AgentSession): void {\n\t// Bump the token as well as aborting: a launch parked on waitForIdle() has no controller yet,\n\t// and would otherwise survive a prompt, a tree navigation, or disposal.\n\tthis._sessionSummaryToken++;\n\tthis._sessionSummaryAbortController?.abort();\n\tthis._sessionSummaryAbortController = undefined;\n\t// Retire the published run too. It is what licenses a write once a request is in flight, so a\n\t// provider that ignores its signal must still fail the ownership check, and a later launch\n\t// must not join a run that has just been cancelled.\n\tthis._sessionSummaryRun = undefined;\n\t// Drop the in-memory anchor as well. It is only a cache of the persisted state, and the\n\t// persisted lookup is retirement-aware where the cache is not: after branchWithSummary()\n\t// retires the stored summary, a cached anchor that still matches the last message id would\n\t// skip regeneration and leave the picker on fallback text until the next real turn.\n\tthis._lastSummarizedMessageId = undefined;\n}\n\nexport const agentSessionSummaryMethods = { _maybeGenerateSessionSummary, abortSessionSummary };\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-summary.js","sourceRoot":"","sources":["../../src/core/agent-session-summary.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC1G,OAAO,EAAE,4BAA4B,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAErG,+EAA+E;AAC/E,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAUlC,MAAM,UAAU,4BAA4B;IAC3C,IAAI,IAAI,CAAC,SAAS,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IACnF,oFAAoF;IACpF,OAAO,gBAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,2BAA2B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;AAC7E,CAAC;AAED,KAAK,UAAU,2BAA2B;IACzC,4FAA4F;IAC5F,qDAAqD;IACrD,IAAI,UAAuC,CAAC;IAC5C,IAAI,GAAkC,CAAC;IACvC,IAAI,MAAgC,CAAC;IACrC,IAAI,CAAC;QACJ,mFAAmF;QACnF,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAC3B,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,yBAAyB,EAAE,CAAC,OAAO;YAAE,OAAO;QAEtE,2FAA2F;QAC3F,kEAAkE;QAClE,IAAI,IAAI,CAAC,cAAc,KAAK,OAAO,IAAI,IAAI,CAAC,cAAc,KAAK,MAAM;YAAE,OAAO;QAE9E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACzB,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,8DAA8D;QAC9D,IAAI,I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G,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,CAAC","sourcesContent":["/**\n * Session summary generation for the resume picker.\n *\n * Runs once the agent goes idle, decides whether a fresh summary is worth generating, and\n * persists the result. Generation itself lives in core/compaction/session-summarization.ts.\n */\n\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { generateSessionSummary } from \"./compaction/index.ts\";\nimport { sessionGenerationClosing, sessionLifetime, trackSessionWork } from \"./session-lifecycle-work.ts\";\nimport { getLastConversationMessageId, getLatestSessionSummary } from \"./session-manager-entries.ts\";\n\n/** Sessions shorter than this are already legible from their first message. */\nconst MIN_ENTRIES_FOR_SUMMARY = 4;\n\n/** A summary request in flight, published so a launch describing the same state can join it. */\nexport type SessionSummaryRun = {\n\t/** The conversation state this request describes. */\n\treadonly throughId: string;\n\t/** Settles when the request finishes, whatever the outcome. */\n\treadonly done: Promise<void>;\n};\n\nexport function _maybeGenerateSessionSummary(this: AgentSession): Promise<void> {\n\tif (this._disposed || sessionGenerationClosing.has(this)) return Promise.resolve();\n\t// Keep every launch, including superseded providers, owned until actual settlement.\n\treturn trackSessionWork(this, () => generateOwnedSessionSummary.call(this));\n}\n\nasync function generateOwnedSessionSummary(this: AgentSession): Promise<void> {\n\t// Held rather than read from the session in `finally`, so an early return can never clear a\n\t// controller or run belonging to a different launch.\n\tlet controller: AbortController | undefined;\n\tlet run: SessionSummaryRun | undefined;\n\tlet finish: (() => void) | undefined;\n\ttry {\n\t\t// --- Bail-outs that cannot change while we wait ---------------------------------\n\t\tif (this._disposed) return;\n\t\tif (!this.settingsManager.getSessionSummarySettings().enabled) return;\n\n\t\t// One-shot scripted runs should not pay for a background call; the process may exit before\n\t\t// it lands. \"tui\" and \"rpc\" are the resumable, interactive modes.\n\t\tif (this._extensionMode === \"print\" || this._extensionMode === \"json\") return;\n\n\t\tconst model = this.model;\n\t\tif (!model) return;\n\n\t\t// Workflow-stage sessions are excluded from /resume entirely.\n\t\tif (this.sessionManager.getHeader()?.internal) return;\n\n\t\t// Claim the launch before waiting, so a later turn supersedes this one while both are\n\t\t// parked below.\n\t\tconst sessionSummaryToken = ++this._sessionSummaryToken;\n\n\t\t// `agent_end` fires while the agent still reports isStreaming, and that flag survives the\n\t\t// entire microtask queue — it only clears a macrotask later. Testing it here without\n\t\t// waiting made generation depend on whether `_checkCompaction` happened to cross a\n\t\t// macrotask boundary: green under test, silently skipped in the real TUI, and nothing\n\t\t// retries it.\n\t\tawait this.agent.waitForIdle();\n\n\t\tif (this._disposed) return;\n\t\tif (this._sessionSummaryToken !== sessionSummaryToken) return;\n\t\tif (this.isStreaming || this.isCompacting) return;\n\n\t\tconst branch = this.sessionManager.getBranch();\n\t\tif (branch.length < MIN_ENTRIES_FOR_SUMMARY) return;\n\n\t\tconst throughId = getLastConversationMessageId(branch);\n\t\tif (!throughId) return;\n\n\t\t// On a resumed session the in-memory anchor starts empty, so fall back to the persisted\n\t\t// summary. Without this the first idle after every resume regenerates a summary that is\n\t\t// already current.\n\t\tconst lastSummarized =\n\t\t\tthis._lastSummarizedMessageId ??\n\t\t\tgetLatestSessionSummary(this.sessionManager.getEntries())?.summarizedThroughId;\n\t\tif (throughId === lastSummarized) return;\n\n\t\t// A request already covering this exact conversation state will store the line this launch\n\t\t// would ask for, so wait for it instead of aborting it and paying for a second one.\n\t\t// Overlap is routine rather than exceptional: every turn schedules a launch, and the\n\t\t// previous turn's can still be in flight when the next one wakes.\n\t\tconst inFlight = this._sessionSummaryRun;\n\t\tif (inFlight !== undefined && inFlight.throughId === throughId) {\n\t\t\tawait inFlight.done;\n\t\t\treturn;\n\t\t}\n\n\t\t// Anything still running describes an older conversation state, so retire it and take the\n\t\t// controller. Abort the previous one directly rather than via abortSessionSummary(), which\n\t\t// bumps the token and would invalidate the claim made above. The controller lives on the\n\t\t// session so the prompt, tree-navigation, and shutdown paths can reach it.\n\t\tthis._sessionSummaryAbortController?.abort();\n\t\tcontroller = new AbortController();\n\t\tthis._sessionSummaryAbortController = controller;\n\t\tconst signal = AbortSignal.any([controller.signal, sessionLifetime(this)]);\n\n\t\t// Publish this run before the first await that another launch can overlap. From here on\n\t\t// ownership of the slot, not the token, is what licenses a write: a joiner bumps the token\n\t\t// on its way in, and must not invalidate the very run it is waiting for.\n\t\t// Hand-rolled deferred rather than Promise.withResolvers: coding-agent is the one compiled\n\t\t// package and its lib target predates ES2024, the same reason `_retryPromise` is built this\n\t\t// way. The executor runs synchronously, so `finish` is assigned before the constructor returns.\n\t\tconst done = new Promise<void>((resolve) => {\n\t\t\tfinish = resolve;\n\t\t});\n\t\trun = { throughId, done };\n\t\tthis._sessionSummaryRun = run;\n\n\t\tconst { apiKey, headers, baseUrl } = await this._getRequiredRequestAuth(model);\n\n\t\t// Disposal or a newer turn can land while credentials resolve; nothing past this point\n\t\t// should reach the provider.\n\t\tif (this._disposed || signal.aborted) return;\n\t\tif (this._sessionSummaryRun !== run) return;\n\n\t\tconst result = await generateSessionSummary(branch, {\n\t\t\tmodel,\n\t\t\tapiKey,\n\t\t\theaders,\n\t\t\tbaseUrl,\n\t\t\tsignal,\n\t\t\tstreamFn: this.agent.streamFunction,\n\t\t\tretry: this.settingsManager.getRetrySettings(),\n\t\t});\n\t\t// Failures stay silent: nothing awaits this, and the picker falls back on its own.\n\t\tif (result.aborted || result.error || !result.summary) return;\n\n\t\t// Disposal, cancellation, a newer run, or a newer message all mean this summary no longer\n\t\t// describes the session. The signal is checked directly as well as the token because a\n\t\t// provider that ignores the signal still returns an ordinary result.\n\t\tif (this._disposed) return;\n\t\tif (signal.aborted) return;\n\t\tif (this._sessionSummaryRun !== run) return;\n\t\tif (getLastConversationMessageId(this.sessionManager.getBranch()) !== throughId) return;\n\n\t\tthis.sessionManager.appendSessionSummary(result.summary, throughId, result.usage);\n\t\tthis._lastSummarizedMessageId = throughId;\n\t} catch {\n\t\t// Nothing awaits this call, so an escaping rejection would surface as an unhandled\n\t\t// rejection and can take the process down. Credential resolution throws outright when no\n\t\t// key is configured, which is an ordinary state for a session that never prompts.\n\t} finally {\n\t\tif (controller !== undefined && this._sessionSummaryAbortController === controller) {\n\t\t\tthis._sessionSummaryAbortController = undefined;\n\t\t}\n\t\tif (run !== undefined && this._sessionSummaryRun === run) {\n\t\t\tthis._sessionSummaryRun = undefined;\n\t\t}\n\t\t// Settled on every path, including a throw and every early return above: a joiner parked\n\t\t// on `done` has no other way out.\n\t\tfinish?.();\n\t}\n}\n\nexport function abortSessionSummary(this: AgentSession): void {\n\t// Bump the token as well as aborting: a launch parked on waitForIdle() has no controller yet,\n\t// and would otherwise survive a prompt, a tree navigation, or disposal.\n\tthis._sessionSummaryToken++;\n\tthis._sessionSummaryAbortController?.abort();\n\tthis._sessionSummaryAbortController = undefined;\n\t// Retire the published run too. It is what licenses a write once a request is in flight, so a\n\t// provider that ignores its signal must still fail the ownership check, and a later launch\n\t// must not join a run that has just been cancelled.\n\tthis._sessionSummaryRun = undefined;\n\t// Drop the in-memory anchor as well. It is only a cache of the persisted state, and the\n\t// persisted lookup is retirement-aware where the cache is not: after branchWithSummary()\n\t// retires the stored summary, a cached anchor that still matches the last message id would\n\t// skip regeneration and leave the picker on fallback text until the next real turn.\n\tthis._lastSummarizedMessageId = undefined;\n}\n\nexport const agentSessionSummaryMethods = { _maybeGenerateSessionSummary, abortSessionSummary };\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentSessionInternalSurface as AgentSession } from "./agent-session-methods.ts";
|
|
2
2
|
import { AgentTaskHost } from "./tasks/agent-adapter.js";
|
|
3
|
+
export declare function replaceSessionTaskOwner(session: AgentSession): void;
|
|
3
4
|
export declare function getAgentTaskHost(this: AgentSession): AgentTaskHost;
|
|
4
5
|
export declare function closeSessionTasks(this: AgentSession): Promise<void>;
|
|
5
6
|
/** Workflow controller only: main-chat message pause does not stop owned tasks. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tasks.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tasks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"agent-session-tasks.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tasks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG9F,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAiBzD,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAMnE;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,YAAY,GAAG,aAAa,CAwHlE;AAED,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAMzE;AAED,mFAAmF;AACnF,wBAAsB,UAAU,CAAC,IAAI,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAElE;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAEpD;AAED,eAAO,MAAM,uBAAuB;;;;;CAAmE,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
1
2
|
import { getExtensionRuntimeEventBus } from "./extensions/loader-core.js";
|
|
3
|
+
import { sessionGenerationClosing } from "./session-lifecycle-work.js";
|
|
2
4
|
import { AgentTaskHost } from "./tasks/agent-adapter.js";
|
|
3
5
|
import { COMMAND_DETAIL_TAIL_BYTES, taskOutputText } from "./tasks/command-output.js";
|
|
4
6
|
import { formatTaskCompletion, TASK_COMPLETION_MESSAGE_TYPE, TaskCompletionOutbox, taskCompletionNotice, } from "./tasks/completion.js";
|
|
@@ -6,8 +8,19 @@ import { flushTaskCompletionMessages } from "./tasks/completion-ordering.js";
|
|
|
6
8
|
import { bindOwnerTaskStore, OwnerTaskStore } from "./tasks/owner-store.js";
|
|
7
9
|
import { taskTranscriptSource } from "./tasks/supervisor.js";
|
|
8
10
|
import { WorkflowStageAdmissionBoundary } from "./workflow-stage-admission.js";
|
|
11
|
+
// Native owners identify live generations, never borrowed persisted storage.
|
|
12
|
+
// Explicit workflow-stage owners remain borrowed across session replacement.
|
|
13
|
+
const replacementOwnerScopes = new WeakMap();
|
|
14
|
+
export function replaceSessionTaskOwner(session) {
|
|
15
|
+
if (session._workflowStageAdmission)
|
|
16
|
+
return;
|
|
17
|
+
replacementOwnerScopes.set(session, randomUUID());
|
|
18
|
+
session._agentTaskHost = undefined;
|
|
19
|
+
session._taskAdmission = undefined;
|
|
20
|
+
session._taskCompletionOutbox = undefined;
|
|
21
|
+
}
|
|
9
22
|
export function getAgentTaskHost() {
|
|
10
|
-
if (this._disposed)
|
|
23
|
+
if (this._disposed || sessionGenerationClosing.has(this))
|
|
11
24
|
throw new Error("Task owner is closed");
|
|
12
25
|
if (this._agentTaskHost)
|
|
13
26
|
return this._agentTaskHost;
|
|
@@ -77,7 +90,7 @@ export function getAgentTaskHost() {
|
|
|
77
90
|
this._taskCompletionOutbox = outbox;
|
|
78
91
|
const binding = {
|
|
79
92
|
authorizeLaunch: () => {
|
|
80
|
-
if (this._disposed || !admission.isOpen())
|
|
93
|
+
if (this._disposed || sessionGenerationClosing.has(this) || !admission.isOpen())
|
|
81
94
|
throw new Error("Task owner is closed");
|
|
82
95
|
// Top-level sessions (main chat, workflow stages) may carry a policy without `depth`;
|
|
83
96
|
// only an admitted in-process child (depth >= 1) is refused delegation.
|
|
@@ -89,9 +102,17 @@ export function getAgentTaskHost() {
|
|
|
89
102
|
void outbox.flush();
|
|
90
103
|
},
|
|
91
104
|
};
|
|
105
|
+
if (!this._workflowStageAdmission && !replacementOwnerScopes.has(this))
|
|
106
|
+
replacementOwnerScopes.set(this, randomUUID());
|
|
92
107
|
this._agentTaskHost = this._workflowStageAdmission
|
|
93
108
|
? this._workflowStageAdmission.bindAgentTaskHost(binding)
|
|
94
|
-
: new AgentTaskHost({
|
|
109
|
+
: new AgentTaskHost({
|
|
110
|
+
...binding,
|
|
111
|
+
scope: {
|
|
112
|
+
kind: "session",
|
|
113
|
+
sessionId: replacementOwnerScopes.get(this),
|
|
114
|
+
},
|
|
115
|
+
});
|
|
95
116
|
const { supervisor, owner } = this._agentTaskHost.ownerBinding;
|
|
96
117
|
const store = new OwnerTaskStore(supervisor, owner);
|
|
97
118
|
const connected = store.connect();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tasks.js","sourceRoot":"","sources":["../../src/core/agent-session-tasks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EACN,oBAAoB,EACpB,4BAA4B,EAC5B,oBAAoB,EACpB,oBAAoB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAE/E,MAAM,UAAU,gBAAgB;IAC/B,IAAI,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC5D,IAAI,IAAI,CAAC,cAAc;QAAE,OAAO,IAAI,CAAC,cAAc,CAAC;IACpD,MAAM,SAAS,GACd,IAAI,CAAC,uBAAuB,IAAI,8BAA8B,CAAC,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC;IAC1G,IAAI,CAAC,cAAc,GAAG,SAAS,CAAC;IAChC,MAAM,MAAM,GAAG,IAAI,oBAAoB,CACtC,IAAI,CAAC,cAAc,EACnB,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,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I,CAAC,uBAAuB;QAAE,OAAO;IACzC,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,eAAe,CAAC,CAAC;IACjE,IAAI,MAAM,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;AAC5F,CAAC;AAED,mFAAmF;AACnF,MAAM,CAAC,KAAK,UAAU,UAAU;IAC/B,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC,UAAU,EAAE,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,WAAW;IAC1B,IAAI,CAAC,cAAc,EAAE,WAAW,EAAE,CAAC;AACpC,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,UAAU,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { getExtensionRuntimeEventBus } from \"./extensions/loader-core.js\";\nimport { AgentTaskHost } from \"./tasks/agent-adapter.js\";\nimport { COMMAND_DETAIL_TAIL_BYTES, taskOutputText } from \"./tasks/command-output.js\";\nimport {\n\tformatTaskCompletion,\n\tTASK_COMPLETION_MESSAGE_TYPE,\n\tTaskCompletionOutbox,\n\ttaskCompletionNotice,\n} from \"./tasks/completion.js\";\nimport { flushTaskCompletionMessages } from \"./tasks/completion-ordering.js\";\nimport { bindOwnerTaskStore, OwnerTaskStore } from \"./tasks/owner-store.js\";\nimport { taskTranscriptSource } from \"./tasks/supervisor.js\";\nimport { WorkflowStageAdmissionBoundary } from \"./workflow-stage-admission.ts\";\n\nexport function getAgentTaskHost(this: AgentSession): AgentTaskHost {\n\tif (this._disposed) throw new Error(\"Task owner is closed\");\n\tif (this._agentTaskHost) return this._agentTaskHost;\n\tconst admission =\n\t\tthis._workflowStageAdmission ?? WorkflowStageAdmissionBoundary.restore(this.sessionManager.getEntries());\n\tthis._taskAdmission = admission;\n\tconst outbox = new TaskCompletionOutbox(\n\t\tthis.sessionManager,\n\t\t() => !this._disposed && admission.isOpen(),\n\t\tasync (envelope) => {\n\t\t\t// Settlement can precede the UI projection's next drain. Read the owner\n\t\t\t// snapshot, not the display store, when attaching completion context.\n\t\t\tconst host = this._agentTaskHost;\n\t\t\tconst watched = host?.watchOwnerTasks();\n\t\t\tconst task = watched?.ok\n\t\t\t\t? watched.value.snapshot.tasks.find(\n\t\t\t\t\t\t(item) => item.ref.taskId === envelope.taskId && item.ref.ownerId === envelope.ownerId,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t\tif (watched?.ok) watched.value.dispose();\n\t\t\t// Foreground shell results already return through their tool call. Do not\n\t\t\t// create a second model turn or background card for that same execution.\n\t\t\tif (task?.kind === \"command\" && !task.wasBackground) return;\n\t\t\tconst lease = task ? host?.resolveTask(envelope.taskId) : undefined;\n\t\t\tconst source = lease?.ok ? taskTranscriptSource(lease.value) : undefined;\n\t\t\tconst response = source?.ok\n\t\t\t\t? source.value.session\n\t\t\t\t\t\t.getEntries()\n\t\t\t\t\t\t.slice()\n\t\t\t\t\t\t.reverse()\n\t\t\t\t\t\t.find(\n\t\t\t\t\t\t\t(entry) =>\n\t\t\t\t\t\t\t\tentry.type === \"message\" &&\n\t\t\t\t\t\t\t\tentry.message.role === \"assistant\" &&\n\t\t\t\t\t\t\t\tentry.message.content.some((block) => block.type === \"text\" && block.text.trim()),\n\t\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t\tlet output =\n\t\t\t\tresponse?.type === \"message\" && response.message.role === \"assistant\"\n\t\t\t\t\t? response.message.content\n\t\t\t\t\t\t\t.filter((block) => block.type === \"text\")\n\t\t\t\t\t\t\t.map((block) => block.text)\n\t\t\t\t\t\t\t.join(\"\\n\")\n\t\t\t\t\t: undefined;\n\t\t\tif (task?.kind === \"command\" && lease?.ok && host) {\n\t\t\t\ttry {\n\t\t\t\t\tconst bytes = BigInt(task.output.byteCount);\n\t\t\t\t\tconst start = bytes > BigInt(COMMAND_DETAIL_TAIL_BYTES) ? bytes - BigInt(COMMAND_DETAIL_TAIL_BYTES) : 0n;\n\t\t\t\t\tconst page = await host.ownerBinding.supervisor.readTaskOutput(lease.value, {\n\t\t\t\t\t\tstart: String(start),\n\t\t\t\t\t\tmaximumBytes: COMMAND_DETAIL_TAIL_BYTES,\n\t\t\t\t\t});\n\t\t\t\t\toutput = page.ok\n\t\t\t\t\t\t? `${start > 0n ? \"[Earlier output omitted]\\n\" : \"\"}${taskOutputText(page.value)}`\n\t\t\t\t\t\t: \"Output unavailable\";\n\t\t\t\t} catch {\n\t\t\t\t\t// Missing retained output must not suppress a terminal notification.\n\t\t\t\t\toutput = \"Output unavailable\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst completionSource = source?.ok ? source.value.session.completionSource : undefined;\n\t\t\tif (completionSource) {\n\t\t\t\tawait flushTaskCompletionMessages(\n\t\t\t\t\tgetExtensionRuntimeEventBus(this._resourceLoader.getExtensions().runtime),\n\t\t\t\t\tcompletionSource,\n\t\t\t\t\tenvelope.completionId,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait admission.admit(\n\t\t\t\tenvelope.completionId,\n\t\t\t\t() =>\n\t\t\t\t\tthis.sendCustomMessage(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustomType: TASK_COMPLETION_MESSAGE_TYPE,\n\t\t\t\t\t\t\tcontent: formatTaskCompletion(envelope, task, output),\n\t\t\t\t\t\t\tdetails: { ...envelope, notification: taskCompletionNotice(envelope, task, output) },\n\t\t\t\t\t\t\tdisplay: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ triggerTurn: true, persistWhenStreaming: true, stageAdmissionKey: envelope.completionId },\n\t\t\t\t\t),\n\t\t\t\t() => {\n\t\t\t\t\tthrow new Error(\"Task owner is closed\");\n\t\t\t\t},\n\t\t\t).completion;\n\t\t},\n\t);\n\tthis._taskCompletionOutbox = outbox;\n\tconst binding = {\n\t\tauthorizeLaunch: () => {\n\t\t\tif (this._disposed || !admission.isOpen()) throw new Error(\"Task owner is closed\");\n\t\t\t// Top-level sessions (main chat, workflow stages) may carry a policy without `depth`;\n\t\t\t// only an admitted in-process child (depth >= 1) is refused delegation.\n\t\t\tif ((this._subagentPolicy?.depth ?? 0) >= 1)\n\t\t\t\tthrow new Error(\"Subagent delegation is not available inside a subagent\");\n\t\t},\n\t\tonTaskSettled: (\n\t\t\t...[ref, receipt]: Parameters<NonNullable<import(\"./tasks/supervisor.js\").TrustedTaskHost[\"onTaskSettled\"]>>\n\t\t) => {\n\t\t\toutbox.record(ref.ownerId, receipt);\n\t\t\tvoid outbox.flush();\n\t\t},\n\t};\n\tthis._agentTaskHost = this._workflowStageAdmission\n\t\t? this._workflowStageAdmission.bindAgentTaskHost(binding)\n\t\t: new AgentTaskHost({ ...binding, scope: { kind: \"session\", sessionId: this.sessionManager.getSessionId() } });\n\tconst { supervisor, owner } = this._agentTaskHost.ownerBinding;\n\tconst store = new OwnerTaskStore(supervisor, owner);\n\tconst connected = store.connect();\n\tif (!connected.ok) throw new Error(connected.error.message);\n\tbindOwnerTaskStore(this, store);\n\treturn this._agentTaskHost;\n}\n\nexport async function closeSessionTasks(this: AgentSession): Promise<void> {\n\t// Replacement stage sessions share generation lifetime; disposal is not stage closure.\n\tif (this._workflowStageAdmission) return;\n\tthis._taskAdmission?.seal();\n\tconst closed = await this._agentTaskHost?.close(\"session-close\");\n\tif (closed && !closed.ok) throw new Error(`${closed.error.code}: ${closed.error.message}`);\n}\n\n/** Workflow controller only: main-chat message pause does not stop owned tasks. */\nexport async function pauseTasks(this: AgentSession): Promise<void> {\n\tawait this.getAgentTaskHost().pauseTasks();\n}\n\nexport function resumeTasks(this: AgentSession): void {\n\tthis._agentTaskHost?.resumeTasks();\n}\n\nexport const agentSessionTaskMethods = { getAgentTaskHost, closeSessionTasks, pauseTasks, resumeTasks };\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-tasks.js","sourceRoot":"","sources":["../../src/core/agent-session-tasks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,2BAA2B,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACtF,OAAO,EACN,oBAAoB,EACpB,4BAA4B,EAC5B,oBAAoB,EACpB,oBAAoB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAE/E,6EAA6E;AAC7E,6EAA6E;AAC7E,MAAM,sBAAsB,GAAG,IAAI,OAAO,EAAkB,CAAC;AAE7D,MAAM,UAAU,uBAAuB,CAAC,OAAqB;IAC5D,IAAI,OAAO,CAAC,uBAAuB;QAAE,OAAO;IAC5C,sBAAsB,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IAClD,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IACnC,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC;IACnC,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;AAC3C,CAAC;AAED,MAAM,UAAU,gBAAgB;IAC/B,IAAI,IAAI,CAAC,SAAS,IAAI,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAA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,WAAW,EAAE,CAAC","sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { getExtensionRuntimeEventBus } from \"./extensions/loader-core.js\";\nimport { sessionGenerationClosing } from \"./session-lifecycle-work.ts\";\nimport { AgentTaskHost } from \"./tasks/agent-adapter.js\";\nimport { COMMAND_DETAIL_TAIL_BYTES, taskOutputText } from \"./tasks/command-output.js\";\nimport {\n\tformatTaskCompletion,\n\tTASK_COMPLETION_MESSAGE_TYPE,\n\tTaskCompletionOutbox,\n\ttaskCompletionNotice,\n} from \"./tasks/completion.js\";\nimport { flushTaskCompletionMessages } from \"./tasks/completion-ordering.js\";\nimport { bindOwnerTaskStore, OwnerTaskStore } from \"./tasks/owner-store.js\";\nimport { taskTranscriptSource } from \"./tasks/supervisor.js\";\nimport { WorkflowStageAdmissionBoundary } from \"./workflow-stage-admission.ts\";\n\n// Native owners identify live generations, never borrowed persisted storage.\n// Explicit workflow-stage owners remain borrowed across session replacement.\nconst replacementOwnerScopes = new WeakMap<object, string>();\n\nexport function replaceSessionTaskOwner(session: AgentSession): void {\n\tif (session._workflowStageAdmission) return;\n\treplacementOwnerScopes.set(session, randomUUID());\n\tsession._agentTaskHost = undefined;\n\tsession._taskAdmission = undefined;\n\tsession._taskCompletionOutbox = undefined;\n}\n\nexport function getAgentTaskHost(this: AgentSession): AgentTaskHost {\n\tif (this._disposed || sessionGenerationClosing.has(this)) throw new Error(\"Task owner is closed\");\n\tif (this._agentTaskHost) return this._agentTaskHost;\n\tconst admission =\n\t\tthis._workflowStageAdmission ?? WorkflowStageAdmissionBoundary.restore(this.sessionManager.getEntries());\n\tthis._taskAdmission = admission;\n\tconst outbox = new TaskCompletionOutbox(\n\t\tthis.sessionManager,\n\t\t() => !this._disposed && admission.isOpen(),\n\t\tasync (envelope) => {\n\t\t\t// Settlement can precede the UI projection's next drain. Read the owner\n\t\t\t// snapshot, not the display store, when attaching completion context.\n\t\t\tconst host = this._agentTaskHost;\n\t\t\tconst watched = host?.watchOwnerTasks();\n\t\t\tconst task = watched?.ok\n\t\t\t\t? watched.value.snapshot.tasks.find(\n\t\t\t\t\t\t(item) => item.ref.taskId === envelope.taskId && item.ref.ownerId === envelope.ownerId,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t\tif (watched?.ok) watched.value.dispose();\n\t\t\t// Foreground shell results already return through their tool call. Do not\n\t\t\t// create a second model turn or background card for that same execution.\n\t\t\tif (task?.kind === \"command\" && !task.wasBackground) return;\n\t\t\tconst lease = task ? host?.resolveTask(envelope.taskId) : undefined;\n\t\t\tconst source = lease?.ok ? taskTranscriptSource(lease.value) : undefined;\n\t\t\tconst response = source?.ok\n\t\t\t\t? source.value.session\n\t\t\t\t\t\t.getEntries()\n\t\t\t\t\t\t.slice()\n\t\t\t\t\t\t.reverse()\n\t\t\t\t\t\t.find(\n\t\t\t\t\t\t\t(entry) =>\n\t\t\t\t\t\t\t\tentry.type === \"message\" &&\n\t\t\t\t\t\t\t\tentry.message.role === \"assistant\" &&\n\t\t\t\t\t\t\t\tentry.message.content.some((block) => block.type === \"text\" && block.text.trim()),\n\t\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t\tlet output =\n\t\t\t\tresponse?.type === \"message\" && response.message.role === \"assistant\"\n\t\t\t\t\t? response.message.content\n\t\t\t\t\t\t\t.filter((block) => block.type === \"text\")\n\t\t\t\t\t\t\t.map((block) => block.text)\n\t\t\t\t\t\t\t.join(\"\\n\")\n\t\t\t\t\t: undefined;\n\t\t\tif (task?.kind === \"command\" && lease?.ok && host) {\n\t\t\t\ttry {\n\t\t\t\t\tconst bytes = BigInt(task.output.byteCount);\n\t\t\t\t\tconst start = bytes > BigInt(COMMAND_DETAIL_TAIL_BYTES) ? bytes - BigInt(COMMAND_DETAIL_TAIL_BYTES) : 0n;\n\t\t\t\t\tconst page = await host.ownerBinding.supervisor.readTaskOutput(lease.value, {\n\t\t\t\t\t\tstart: String(start),\n\t\t\t\t\t\tmaximumBytes: COMMAND_DETAIL_TAIL_BYTES,\n\t\t\t\t\t});\n\t\t\t\t\toutput = page.ok\n\t\t\t\t\t\t? `${start > 0n ? \"[Earlier output omitted]\\n\" : \"\"}${taskOutputText(page.value)}`\n\t\t\t\t\t\t: \"Output unavailable\";\n\t\t\t\t} catch {\n\t\t\t\t\t// Missing retained output must not suppress a terminal notification.\n\t\t\t\t\toutput = \"Output unavailable\";\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst completionSource = source?.ok ? source.value.session.completionSource : undefined;\n\t\t\tif (completionSource) {\n\t\t\t\tawait flushTaskCompletionMessages(\n\t\t\t\t\tgetExtensionRuntimeEventBus(this._resourceLoader.getExtensions().runtime),\n\t\t\t\t\tcompletionSource,\n\t\t\t\t\tenvelope.completionId,\n\t\t\t\t);\n\t\t\t}\n\t\t\tawait admission.admit(\n\t\t\t\tenvelope.completionId,\n\t\t\t\t() =>\n\t\t\t\t\tthis.sendCustomMessage(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcustomType: TASK_COMPLETION_MESSAGE_TYPE,\n\t\t\t\t\t\t\tcontent: formatTaskCompletion(envelope, task, output),\n\t\t\t\t\t\t\tdetails: { ...envelope, notification: taskCompletionNotice(envelope, task, output) },\n\t\t\t\t\t\t\tdisplay: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{ triggerTurn: true, persistWhenStreaming: true, stageAdmissionKey: envelope.completionId },\n\t\t\t\t\t),\n\t\t\t\t() => {\n\t\t\t\t\tthrow new Error(\"Task owner is closed\");\n\t\t\t\t},\n\t\t\t).completion;\n\t\t},\n\t);\n\tthis._taskCompletionOutbox = outbox;\n\tconst binding = {\n\t\tauthorizeLaunch: () => {\n\t\t\tif (this._disposed || sessionGenerationClosing.has(this) || !admission.isOpen())\n\t\t\t\tthrow new Error(\"Task owner is closed\");\n\t\t\t// Top-level sessions (main chat, workflow stages) may carry a policy without `depth`;\n\t\t\t// only an admitted in-process child (depth >= 1) is refused delegation.\n\t\t\tif ((this._subagentPolicy?.depth ?? 0) >= 1)\n\t\t\t\tthrow new Error(\"Subagent delegation is not available inside a subagent\");\n\t\t},\n\t\tonTaskSettled: (\n\t\t\t...[ref, receipt]: Parameters<NonNullable<import(\"./tasks/supervisor.js\").TrustedTaskHost[\"onTaskSettled\"]>>\n\t\t) => {\n\t\t\toutbox.record(ref.ownerId, receipt);\n\t\t\tvoid outbox.flush();\n\t\t},\n\t};\n\tif (!this._workflowStageAdmission && !replacementOwnerScopes.has(this))\n\t\treplacementOwnerScopes.set(this, randomUUID());\n\tthis._agentTaskHost = this._workflowStageAdmission\n\t\t? this._workflowStageAdmission.bindAgentTaskHost(binding)\n\t\t: new AgentTaskHost({\n\t\t\t\t...binding,\n\t\t\t\tscope: {\n\t\t\t\t\tkind: \"session\",\n\t\t\t\t\tsessionId: replacementOwnerScopes.get(this)!,\n\t\t\t\t},\n\t\t\t});\n\tconst { supervisor, owner } = this._agentTaskHost.ownerBinding;\n\tconst store = new OwnerTaskStore(supervisor, owner);\n\tconst connected = store.connect();\n\tif (!connected.ok) throw new Error(connected.error.message);\n\tbindOwnerTaskStore(this, store);\n\treturn this._agentTaskHost;\n}\n\nexport async function closeSessionTasks(this: AgentSession): Promise<void> {\n\t// Replacement stage sessions share generation lifetime; disposal is not stage closure.\n\tif (this._workflowStageAdmission) return;\n\tthis._taskAdmission?.seal();\n\tconst closed = await this._agentTaskHost?.close(\"session-close\");\n\tif (closed && !closed.ok) throw new Error(`${closed.error.code}: ${closed.error.message}`);\n}\n\n/** Workflow controller only: main-chat message pause does not stop owned tasks. */\nexport async function pauseTasks(this: AgentSession): Promise<void> {\n\tawait this.getAgentTaskHost().pauseTasks();\n}\n\nexport function resumeTasks(this: AgentSession): void {\n\tthis._agentTaskHost?.resumeTasks();\n}\n\nexport const agentSessionTaskMethods = { getAgentTaskHost, closeSessionTasks, pauseTasks, resumeTasks };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tool-hooks.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-session-tool-hooks.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAK9F,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAiF/D;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CA8ErE;AAsBD,eAAO,MAAM,4BAA4B;;;CAGxC,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { getCurrentSystemMessage } from "@bastani/pi-ai";
|
|
1
2
|
import { normalizeToolResultImages } from "../utils/tool-result-images.js";
|
|
2
3
|
import { assertToolPairingInvariant } from "./context-tool-pairing.js";
|
|
4
|
+
import { normalizeBuildSystemPromptOptions } from "./system-prompt.js";
|
|
3
5
|
import { redirectOversizedToolResult } from "./tools/oversized-tool-result.js";
|
|
4
6
|
export function _installAgentToolHooks() {
|
|
5
7
|
this.agent.beforeToolCall = async ({ toolCall, args }) => {
|
|
@@ -41,7 +43,7 @@ export function _installAgentToolHooks() {
|
|
|
41
43
|
content: result.content,
|
|
42
44
|
details: result.details,
|
|
43
45
|
isError,
|
|
44
|
-
})
|
|
46
|
+
}, true)
|
|
45
47
|
: undefined;
|
|
46
48
|
const hookContent = hookResult?.content ?? result.content;
|
|
47
49
|
// Run after extension hooks so extension-injected images enter history at provider-safe sizes.
|
|
@@ -108,7 +110,17 @@ export function _installAgentNextTurnRefresh() {
|
|
|
108
110
|
// Last checkpoint before provider conversion: a structurally invalid context
|
|
109
111
|
// here becomes an unrecoverable provider 400, so surface it as an Atomic error.
|
|
110
112
|
assertToolPairingInvariant(guarded);
|
|
111
|
-
|
|
113
|
+
const forced = this._runSystemPromptOptions?.forceSystemPrompt ?? this._baseSystemPromptOptions.forceSystemPrompt;
|
|
114
|
+
if (forced === undefined)
|
|
115
|
+
return guarded;
|
|
116
|
+
const current = getCurrentSystemMessage(guarded);
|
|
117
|
+
const head = {
|
|
118
|
+
role: "system",
|
|
119
|
+
content: forced,
|
|
120
|
+
...(current?.toolsAdded ? { toolsAdded: current.toolsAdded } : {}),
|
|
121
|
+
timestamp: current?.timestamp ?? Date.now(),
|
|
122
|
+
};
|
|
123
|
+
return [head, ...guarded.filter((message) => message.role !== "system")];
|
|
112
124
|
};
|
|
113
125
|
const prepareTurn = async (turn, signal) => {
|
|
114
126
|
const compactedMessages = turn.toolResults.length > 0
|
|
@@ -118,14 +130,25 @@ export function _installAgentNextTurnRefresh() {
|
|
|
118
130
|
const preparedTurn = compactedContext === turn.context ? turn : { ...turn, context: compactedContext };
|
|
119
131
|
const previousSnapshot = await previousPrepareNextTurnWithContext?.(preparedTurn, signal);
|
|
120
132
|
const previousContext = previousSnapshot?.context ?? compactedContext;
|
|
133
|
+
const runOptions = this._runSystemPromptOptions ?? this._baseSystemPromptOptions;
|
|
134
|
+
const options = normalizeBuildSystemPromptOptions({
|
|
135
|
+
...runOptions,
|
|
136
|
+
selectedModel: this.model,
|
|
137
|
+
selectedThinkingLevel: this.thinkingLevel,
|
|
138
|
+
selectedTools: this.getActiveToolNames(),
|
|
139
|
+
toolSnippets: { ...this._baseSystemPromptOptions.toolSnippets, ...runOptions.toolSnippets },
|
|
140
|
+
toolGuidelines: { ...this._baseSystemPromptOptions.toolGuidelines, ...runOptions.toolGuidelines },
|
|
141
|
+
});
|
|
142
|
+
const updateMessage = this._preparePromptAndToolLoadout(options, previousContext.messages);
|
|
143
|
+
this._runSystemPromptOptions = options;
|
|
121
144
|
return {
|
|
122
145
|
...previousSnapshot,
|
|
123
146
|
context: {
|
|
124
147
|
...previousContext,
|
|
125
148
|
messages: previousContext.messages,
|
|
126
|
-
systemPrompt: this._systemPromptOverride ?? this._baseSystemPrompt,
|
|
127
149
|
tools: this.agent.state.tools.slice(),
|
|
128
150
|
},
|
|
151
|
+
messages: updateMessage ? [...(previousSnapshot?.messages ?? []), updateMessage] : previousSnapshot?.messages,
|
|
129
152
|
model: this.agent.state.model,
|
|
130
153
|
thinkingLevel: this.agent.state.thinkingLevel,
|
|
131
154
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tool-hooks.js","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,MAAM,UAAU,sBAAsB;IACrC,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,EAAE;QACxD,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC;QACrC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAAW,CAAC,EAAE,CAAC;YACtC,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,MAAM,IAAI,CAAC,gBAAgB,CAAC;QAE5B,IAAI,CAAC;YACJ,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC;gBACxC,IAAI,EAAE,WAAW;gBACjB,QAAQ,EAAE,QAAQ,CAAC,IAAI;gBACvB,UAAU,EAAE,QAAQ,CAAC,EAAE;gBACvB,KAAK,EAAE,IAA+B;aACtC,CAAC,CAAC;YACH,IAAI,MAAM,EAAE,KAAK,IAAI,MAAM,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;gBAChD,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,QAAQ,CAAC,E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n\nimport { normalizeToolResultImages } from \"../utils/tool-result-images.js\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { assertToolPairingInvariant } from \"./context-tool-pairing.js\";\nimport { redirectOversizedToolResult } from \"./tools/oversized-tool-result.js\";\n\nexport function _installAgentToolHooks(this: AgentSession): void {\n\tthis.agent.beforeToolCall = async ({ toolCall, args }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tif (!runner.hasHandlers(\"tool_call\")) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tawait this._agentEventQueue;\n\n\t\ttry {\n\t\t\tconst result = await runner.emitToolCall({\n\t\t\t\ttype: \"tool_call\",\n\t\t\t\ttoolName: toolCall.name,\n\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t});\n\t\t\tif (result?.block && result.terminate === true) {\n\t\t\t\tthis._terminatingToolCallIds.add(toolCall.id);\n\t\t\t} else {\n\t\t\t\tthis._terminatingToolCallIds.delete(toolCall.id);\n\t\t\t}\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tif (err instanceof Error) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tthrow new Error(`Extension failed, blocking execution: ${String(err)}`);\n\t\t}\n\t};\n\n\tthis.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tconst hookResult = runner.hasHandlers(\"tool_result\")\n\t\t\t? await runner.emitToolResult({\n\t\t\t\t\ttype: \"tool_result\",\n\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t\t\tcontent: result.content,\n\t\t\t\t\tdetails: result.details,\n\t\t\t\t\tisError,\n\t\t\t\t})\n\t\t\t: undefined;\n\n\t\tconst hookContent = hookResult?.content ?? result.content;\n\t\t// Run after extension hooks so extension-injected images enter history at provider-safe sizes.\n\t\tconst normalizedContent = await normalizeToolResultImages(hookContent, {\n\t\t\tautoResizeImages: this.settingsManager.getImageAutoResize(),\n\t\t});\n\t\tconst resultReplacement =\n\t\t\thookResult || normalizedContent !== hookContent\n\t\t\t\t? {\n\t\t\t\t\t\tcontent: normalizedContent,\n\t\t\t\t\t\tdetails: hookResult?.details,\n\t\t\t\t\t\tisError: hookResult?.isError ?? isError,\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tconst finalResult = {\n\t\t\tcontent: normalizedContent,\n\t\t\t// Preserve original details when an extension hook rewrites only content;\n\t\t\t// the redirect check only replaces model-visible content blocks.\n\t\t\tdetails: hookResult?.details ?? result.details,\n\t\t};\n\t\tconst finalIsError = hookResult?.isError ?? isError;\n\t\tconst redirectReplacement = await redirectOversizedToolResult({\n\t\t\ttoolName: toolCall.name,\n\t\t\ttoolCallId: toolCall.id,\n\t\t\tresult: finalResult,\n\t\t\tisError: finalIsError,\n\t\t\tsessionId: this.sessionManager.getSessionId(),\n\t\t\tsessionDir: this.sessionManager.getSessionDir() || undefined,\n\t\t\tmaxResultSizeChars: this.getToolDefinition(toolCall.name)?.maxResultSizeChars,\n\t\t});\n\n\t\tif (result.terminate === true) this._terminatingToolCallIds.add(toolCall.id);\n\t\telse this._terminatingToolCallIds.delete(toolCall.id);\n\t\treturn redirectReplacement ?? resultReplacement;\n\t};\n}\n\n/**\n * Install a prepareNextTurnWithContext hook so that extension tool changes\n * (e.g. setActiveTools) and before_agent_start systemPrompt overrides are\n * applied to the next provider request within the same run.\n */\nexport function _installAgentNextTurnRefresh(this: AgentSession): void {\n\tconst previousPrepareNextTurnWithContext =\n\t\tthis.agent.prepareNextTurnWithContext ??\n\t\t(this.agent.prepareNextTurn\n\t\t\t? async (_turn: PrepareNextTurnContext, signal?: AbortSignal) => await this.agent.prepareNextTurn?.(signal)\n\t\t\t: undefined);\n\n\tconst previousShouldStopAfterTurn = this.agent.shouldStopAfterTurn;\n\tthis.agent.shouldStopAfterTurn = async (turn, signal) => {\n\t\tconst toolCallIds = turn.message.content.filter((part) => part.type === \"toolCall\").map((part) => part.id);\n\t\tconst terminatingBatch =\n\t\t\ttoolCallIds.length > 0 && toolCallIds.every((id) => this._terminatingToolCallIds.has(id));\n\t\tfor (const id of toolCallIds) this._terminatingToolCallIds.delete(id);\n\n\t\tconst shouldStop = (await previousShouldStopAfterTurn?.(turn, signal)) ?? false;\n\t\tthis._stopAfterTurnBlockedContinuation = shouldStop;\n\t\tawait settleFallbackAfterTurn(this, turn, terminatingBatch);\n\t\tif (this._subagentMessageAdmission) await this._subagentMessageAdmission.waitForPendingDeliveries();\n\t\treturn shouldStop;\n\t};\n\n\tconst previousTransformContext = this.agent.transformContext;\n\tthis.agent.transformContext = async (messages, signal) => {\n\t\tconst transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;\n\t\tconst guarded = this._finishPostToolCompactionPreflight(transformed);\n\t\t// Last checkpoint before provider conversion: a structurally invalid context\n\t\t// here becomes an unrecoverable provider 400, so surface it as an Atomic error.\n\t\tassertToolPairingInvariant(guarded);\n\t\treturn guarded;\n\t};\n\n\tconst prepareTurn = async (turn: PrepareNextTurnContext, signal?: AbortSignal): Promise<AgentLoopTurnUpdate> => {\n\t\tconst compactedMessages =\n\t\t\tturn.toolResults.length > 0\n\t\t\t\t? await this._preflightPostToolContext(turn.context.messages, signal)\n\t\t\t\t: turn.context.messages;\n\t\tconst compactedContext =\n\t\t\tcompactedMessages === turn.context.messages ? turn.context : { ...turn.context, messages: compactedMessages };\n\t\tconst preparedTurn = compactedContext === turn.context ? turn : { ...turn, context: compactedContext };\n\t\tconst previousSnapshot = await previousPrepareNextTurnWithContext?.(preparedTurn, signal);\n\t\tconst previousContext = previousSnapshot?.context ?? compactedContext;\n\n\t\treturn {\n\t\t\t...previousSnapshot,\n\t\t\tcontext: {\n\t\t\t\t...previousContext,\n\t\t\t\tmessages: previousContext.messages,\n\t\t\t\tsystemPrompt: this._systemPromptOverride ?? this._baseSystemPrompt,\n\t\t\t\ttools: this.agent.state.tools.slice(),\n\t\t\t},\n\t\t\tmodel: this.agent.state.model,\n\t\t\tthinkingLevel: this.agent.state.thinkingLevel,\n\t\t};\n\t};\n\n\t// pi-agent-core 0.85.0 runs the stop hook before queue polling and invokes\n\t// preparation only after that polling establishes that another turn will run.\n\tthis.agent.prepareNextTurnWithContext = prepareTurn;\n}\n\nasync function settleFallbackAfterTurn(\n\tsession: AgentSession,\n\tturn: PrepareNextTurnContext,\n\tterminatingBatch: boolean,\n): Promise<void> {\n\t// Settle before queued follow-up messages are polled, but keep the fallback\n\t// lifecycle open for deceptive completions that event processing must retry\n\t// on the same model (safety refusal, empty completion, or length truncation).\n\tconst preserveFallbackForFailure =\n\t\tturn.message.role === \"assistant\" &&\n\t\t!session.agent.hasQueuedMessages() &&\n\t\t(turn.message.stopReason === \"length\" ||\n\t\t\tsession._isEmptyCompletion?.(turn.message) === true ||\n\t\t\tsession._isSafetyRefusal?.(turn.message) === true);\n\tif (!preserveFallbackForFailure && (turn.toolResults.length === 0 || terminatingBatch)) {\n\t\tawait session._agentEventQueue;\n\t\tawait session._settleFallbackModelScope();\n\t}\n}\n\nexport const agentSessionToolHooksMethods = {\n\t_installAgentToolHooks,\n\t_installAgentNextTurnRefresh,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-tool-hooks.js","sourceRoot":"","sources":["../../src/core/agent-session-tool-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAsB,MAAM,gBAAgB,CAAC;AAE7E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAE3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AAE/E,MAAM,UAAU,sBAAsB;IACrC,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,KAAK,EAAE,EAAE,QAAQ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C,OAAO,CAAC,IAAI,KAAK,WAAW;QACjC,CAAC,OAAO,CAAC,KAAK,CAAC,iBAAiB,EAAE;QAClC,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,KAAK,QAAQ;YACpC,OAAO,CAAC,kBAAkB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI;YACnD,OAAO,CAAC,gBAAgB,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC;IACrD,IAAI,CAAC,0BAA0B,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,IAAI,gBAAgB,CAAC,EAAE,CAAC;QACxF,MAAM,OAAO,CAAC,gBAAgB,CAAC;QAC/B,MAAM,OAAO,CAAC,yBAAyB,EAAE,CAAC;IAC3C,CAAC;AACF,CAAC;AAED,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC3C,sBAAsB;IACtB,4BAA4B;CAC5B,CAAC","sourcesContent":["import { getCurrentSystemMessage, type SystemMessage } from \"@bastani/pi-ai\";\nimport type { AgentLoopTurnUpdate, PrepareNextTurnContext } from \"@earendil-works/pi-agent-core\";\nimport { normalizeToolResultImages } from \"../utils/tool-result-images.js\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { assertToolPairingInvariant } from \"./context-tool-pairing.js\";\nimport { normalizeBuildSystemPromptOptions } from \"./system-prompt.ts\";\nimport { redirectOversizedToolResult } from \"./tools/oversized-tool-result.js\";\n\nexport function _installAgentToolHooks(this: AgentSession): void {\n\tthis.agent.beforeToolCall = async ({ toolCall, args }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tif (!runner.hasHandlers(\"tool_call\")) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tawait this._agentEventQueue;\n\n\t\ttry {\n\t\t\tconst result = await runner.emitToolCall({\n\t\t\t\ttype: \"tool_call\",\n\t\t\t\ttoolName: toolCall.name,\n\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t});\n\t\t\tif (result?.block && result.terminate === true) {\n\t\t\t\tthis._terminatingToolCallIds.add(toolCall.id);\n\t\t\t} else {\n\t\t\t\tthis._terminatingToolCallIds.delete(toolCall.id);\n\t\t\t}\n\t\t\treturn result;\n\t\t} catch (err) {\n\t\t\tif (err instanceof Error) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tthrow new Error(`Extension failed, blocking execution: ${String(err)}`);\n\t\t}\n\t};\n\n\tthis.agent.afterToolCall = async ({ toolCall, args, result, isError }) => {\n\t\tconst runner = this._extensionRunner;\n\t\tconst hookResult = runner.hasHandlers(\"tool_result\")\n\t\t\t? await runner.emitToolResult(\n\t\t\t\t\t{\n\t\t\t\t\t\ttype: \"tool_result\",\n\t\t\t\t\t\ttoolName: toolCall.name,\n\t\t\t\t\t\ttoolCallId: toolCall.id,\n\t\t\t\t\t\tinput: args as Record<string, unknown>,\n\t\t\t\t\t\tcontent: result.content,\n\t\t\t\t\t\tdetails: result.details,\n\t\t\t\t\t\tisError,\n\t\t\t\t\t},\n\t\t\t\t\ttrue,\n\t\t\t\t)\n\t\t\t: undefined;\n\n\t\tconst hookContent = hookResult?.content ?? result.content;\n\t\t// Run after extension hooks so extension-injected images enter history at provider-safe sizes.\n\t\tconst normalizedContent = await normalizeToolResultImages(hookContent, {\n\t\t\tautoResizeImages: this.settingsManager.getImageAutoResize(),\n\t\t});\n\t\tconst resultReplacement =\n\t\t\thookResult || normalizedContent !== hookContent\n\t\t\t\t? {\n\t\t\t\t\t\tcontent: normalizedContent,\n\t\t\t\t\t\tdetails: hookResult?.details,\n\t\t\t\t\t\tisError: hookResult?.isError ?? isError,\n\t\t\t\t\t}\n\t\t\t\t: undefined;\n\t\tconst finalResult = {\n\t\t\tcontent: normalizedContent,\n\t\t\t// Preserve original details when an extension hook rewrites only content;\n\t\t\t// the redirect check only replaces model-visible content blocks.\n\t\t\tdetails: hookResult?.details ?? result.details,\n\t\t};\n\t\tconst finalIsError = hookResult?.isError ?? isError;\n\t\tconst redirectReplacement = await redirectOversizedToolResult({\n\t\t\ttoolName: toolCall.name,\n\t\t\ttoolCallId: toolCall.id,\n\t\t\tresult: finalResult,\n\t\t\tisError: finalIsError,\n\t\t\tsessionId: this.sessionManager.getSessionId(),\n\t\t\tsessionDir: this.sessionManager.getSessionDir() || undefined,\n\t\t\tmaxResultSizeChars: this.getToolDefinition(toolCall.name)?.maxResultSizeChars,\n\t\t});\n\n\t\tif (result.terminate === true) this._terminatingToolCallIds.add(toolCall.id);\n\t\telse this._terminatingToolCallIds.delete(toolCall.id);\n\t\treturn redirectReplacement ?? resultReplacement;\n\t};\n}\n\n/**\n * Install a prepareNextTurnWithContext hook so that extension tool changes\n * (e.g. setActiveTools) and before_agent_start systemPrompt overrides are\n * applied to the next provider request within the same run.\n */\nexport function _installAgentNextTurnRefresh(this: AgentSession): void {\n\tconst previousPrepareNextTurnWithContext =\n\t\tthis.agent.prepareNextTurnWithContext ??\n\t\t(this.agent.prepareNextTurn\n\t\t\t? async (_turn: PrepareNextTurnContext, signal?: AbortSignal) => await this.agent.prepareNextTurn?.(signal)\n\t\t\t: undefined);\n\n\tconst previousShouldStopAfterTurn = this.agent.shouldStopAfterTurn;\n\tthis.agent.shouldStopAfterTurn = async (turn, signal) => {\n\t\tconst toolCallIds = turn.message.content.filter((part) => part.type === \"toolCall\").map((part) => part.id);\n\t\tconst terminatingBatch =\n\t\t\ttoolCallIds.length > 0 && toolCallIds.every((id) => this._terminatingToolCallIds.has(id));\n\t\tfor (const id of toolCallIds) this._terminatingToolCallIds.delete(id);\n\n\t\tconst shouldStop = (await previousShouldStopAfterTurn?.(turn, signal)) ?? false;\n\t\tthis._stopAfterTurnBlockedContinuation = shouldStop;\n\t\tawait settleFallbackAfterTurn(this, turn, terminatingBatch);\n\t\tif (this._subagentMessageAdmission) await this._subagentMessageAdmission.waitForPendingDeliveries();\n\t\treturn shouldStop;\n\t};\n\n\tconst previousTransformContext = this.agent.transformContext;\n\tthis.agent.transformContext = async (messages, signal) => {\n\t\tconst transformed = previousTransformContext ? await previousTransformContext(messages, signal) : messages;\n\t\tconst guarded = this._finishPostToolCompactionPreflight(transformed);\n\t\t// Last checkpoint before provider conversion: a structurally invalid context\n\t\t// here becomes an unrecoverable provider 400, so surface it as an Atomic error.\n\t\tassertToolPairingInvariant(guarded);\n\t\tconst forced = this._runSystemPromptOptions?.forceSystemPrompt ?? this._baseSystemPromptOptions.forceSystemPrompt;\n\t\tif (forced === undefined) return guarded;\n\t\tconst current = getCurrentSystemMessage(guarded);\n\t\tconst head: SystemMessage = {\n\t\t\trole: \"system\",\n\t\t\tcontent: forced,\n\t\t\t...(current?.toolsAdded ? { toolsAdded: current.toolsAdded } : {}),\n\t\t\ttimestamp: current?.timestamp ?? Date.now(),\n\t\t};\n\t\treturn [head, ...guarded.filter((message) => message.role !== \"system\")];\n\t};\n\n\tconst prepareTurn = async (turn: PrepareNextTurnContext, signal?: AbortSignal): Promise<AgentLoopTurnUpdate> => {\n\t\tconst compactedMessages =\n\t\t\tturn.toolResults.length > 0\n\t\t\t\t? await this._preflightPostToolContext(turn.context.messages, signal)\n\t\t\t\t: turn.context.messages;\n\t\tconst compactedContext =\n\t\t\tcompactedMessages === turn.context.messages ? turn.context : { ...turn.context, messages: compactedMessages };\n\t\tconst preparedTurn = compactedContext === turn.context ? turn : { ...turn, context: compactedContext };\n\t\tconst previousSnapshot = await previousPrepareNextTurnWithContext?.(preparedTurn, signal);\n\t\tconst previousContext = previousSnapshot?.context ?? compactedContext;\n\t\tconst runOptions = this._runSystemPromptOptions ?? this._baseSystemPromptOptions;\n\t\tconst options = normalizeBuildSystemPromptOptions({\n\t\t\t...runOptions,\n\t\t\tselectedModel: this.model,\n\t\t\tselectedThinkingLevel: this.thinkingLevel,\n\t\t\tselectedTools: this.getActiveToolNames(),\n\t\t\ttoolSnippets: { ...this._baseSystemPromptOptions.toolSnippets, ...runOptions.toolSnippets },\n\t\t\ttoolGuidelines: { ...this._baseSystemPromptOptions.toolGuidelines, ...runOptions.toolGuidelines },\n\t\t});\n\t\tconst updateMessage = this._preparePromptAndToolLoadout(options, previousContext.messages);\n\t\tthis._runSystemPromptOptions = options;\n\n\t\treturn {\n\t\t\t...previousSnapshot,\n\t\t\tcontext: {\n\t\t\t\t...previousContext,\n\t\t\t\tmessages: previousContext.messages,\n\t\t\t\ttools: this.agent.state.tools.slice(),\n\t\t\t},\n\t\t\tmessages: updateMessage ? [...(previousSnapshot?.messages ?? []), updateMessage] : previousSnapshot?.messages,\n\t\t\tmodel: this.agent.state.model,\n\t\t\tthinkingLevel: this.agent.state.thinkingLevel,\n\t\t};\n\t};\n\n\t// pi-agent-core 0.85.0 runs the stop hook before queue polling and invokes\n\t// preparation only after that polling establishes that another turn will run.\n\tthis.agent.prepareNextTurnWithContext = prepareTurn;\n}\n\nasync function settleFallbackAfterTurn(\n\tsession: AgentSession,\n\tturn: PrepareNextTurnContext,\n\tterminatingBatch: boolean,\n): Promise<void> {\n\t// Settle before queued follow-up messages are polled, but keep the fallback\n\t// lifecycle open for deceptive completions that event processing must retry\n\t// on the same model (safety refusal, empty completion, or length truncation).\n\tconst preserveFallbackForFailure =\n\t\tturn.message.role === \"assistant\" &&\n\t\t!session.agent.hasQueuedMessages() &&\n\t\t(turn.message.stopReason === \"length\" ||\n\t\t\tsession._isEmptyCompletion?.(turn.message) === true ||\n\t\t\tsession._isSafetyRefusal?.(turn.message) === true);\n\tif (!preserveFallbackForFailure && (turn.toolResults.length === 0 || terminatingBatch)) {\n\t\tawait session._agentEventQueue;\n\t\tawait session._settleFallbackModelScope();\n\t}\n}\n\nexport const agentSessionToolHooksMethods = {\n\t_installAgentToolHooks,\n\t_installAgentNextTurnRefresh,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tool-registry.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tool-registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAa9F,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,wBAAwB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1E,IAAI,
|
|
1
|
+
{"version":3,"file":"agent-session-tool-registry.d.ts","sourceRoot":"","sources":["../../src/core/agent-session-tool-registry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,IAAI,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAa9F,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,YAAY,EAClB,OAAO,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,wBAAwB,CAAC,EAAE,OAAO,CAAA;CAAE,GAC1E,IAAI,CAsGN;AAED,wBAAgB,aAAa,CAC5B,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE;IACR,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,UAAU,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC;IAC3C,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB,GACC,IAAI,CA+HN;AAED,eAAO,MAAM,+BAA+B;;;CAG3C,CAAC"}
|
|
@@ -14,8 +14,6 @@ export function _refreshToolRegistry(options) {
|
|
|
14
14
|
const allowedToolNames = this._allowedToolNames;
|
|
15
15
|
const excludedToolNames = this._excludedToolNames;
|
|
16
16
|
const isExposedTool = (name) => {
|
|
17
|
-
if (isMandatoryRuntimeTool(name))
|
|
18
|
-
return true;
|
|
19
17
|
if (allowedToolNames && !allowedToolNames.has(name)) {
|
|
20
18
|
return false;
|
|
21
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-tool-regist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AAE,CAAC;QAC7B,IAAI,CAAC,gBAAgB,GAAG,IAAI,eAAe,CAC1C,gBAAgB,CAAC,UAAU,EAC3B,gBAAgB,CAAC,OAAO,EACxB,IAAI,CAAC,IAAI,EACT,IAAI,CAAC,cAAc,EACnB,IAAI,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,EACrC,IAAI,CAAC,qBAAqB,EAC1B,IAAI,CAAC,eAAe,CACpB,CAAC;QACF,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC9B,IAAI,CAAC,mBAAmB,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC/C,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,sBAAsB,GAAG,IAAI,CAAC,kBAAkB;QACrD,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACtC,CAAC,CAAC,CAAC,GAAG,mBAAmB,EAAE,CAAC,CAAC;IAC9B,MAAM,mBAAmB,GAAG,OAAO,CAAC,eAAe,IAAI,sBAAsB,CAAC;IAC9E,IAAI,CAAC,oBAAoB,CAAC;QACzB,eAAe,EAAE,mBAAmB;QACpC,wBAAwB,EAAE,OAAO,CAAC,wBAAwB;KAC1D,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC9C,oBAAoB;IACpB,aAAa;CACb,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport type { ToolDefinitionEntry } from \"./agent-session-types.ts\";\nimport { ExtensionRunner, type ToolDefinition, wrapRegisteredTools } from \"./extensions/index.js\";\nimport { isMandatoryRuntimeTool, isTrustedMandatoryRuntimeTool } from \"./mandatory-runtime-tools.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { createSyntheticSourceInfo } from \"./source-info.ts\";\nimport { createLocalBashOperations } from \"./tools/bash.js\";\nimport { buildMutationRequester } from \"./tools/file-mutation-coordinator.ts\";\nimport { createAllToolDefinitions, getDefaultToolNames } from \"./tools/index.ts\";\nimport { createLocalPowerShellOperations } from \"./tools/powershell.ts\";\nimport { resolveSessionTempDirPath } from \"./tools/session-temp-dir.ts\";\nimport { createToolDefinitionFromAgentTool } from \"./tools/tool-definition-wrapper.ts\";\n\nexport function _refreshToolRegistry(\n\tthis: AgentSession,\n\toptions?: { activeToolNames?: string[]; includeAllExtensionTools?: boolean },\n): void {\n\tconst previousRegistryNames = new Set(this._toolRegistry.keys());\n\tconst previousActiveToolNames = this.getActiveToolNames();\n\tconst allowedToolNames = this._allowedToolNames;\n\tconst excludedToolNames = this._excludedToolNames;\n\tconst isExposedTool = (name: string): boolean => {\n\t\tif (isMandatoryRuntimeTool(name)) return true;\n\t\tif (allowedToolNames && !allowedToolNames.has(name)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (excludedToolNames?.has(name)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t};\n\n\tconst registeredTools = this._extensionRunner\n\t\t.getAllRegisteredTools()\n\t\t.filter((tool) => !isMandatoryRuntimeTool(tool.definition.name) || isTrustedMandatoryRuntimeTool(tool));\n\tconst allCustomTools = [\n\t\t...registeredTools,\n\t\t...this._customTools\n\t\t\t.filter((definition) => !isMandatoryRuntimeTool(definition.name))\n\t\t\t.map((definition) => ({\n\t\t\t\tdefinition,\n\t\t\t\tsourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: \"sdk\" }),\n\t\t\t})),\n\t].filter((tool) => isExposedTool(tool.definition.name));\n\tconst definitionRegistry = new Map<string, ToolDefinitionEntry>(\n\t\tArray.from(this._baseToolDefinitions.entries())\n\t\t\t.filter(([name]) => isExposedTool(name))\n\t\t\t.map(([name, definition]) => [\n\t\t\t\tname,\n\t\t\t\t{\n\t\t\t\t\tdefinition,\n\t\t\t\t\tsourceInfo: createSyntheticSourceInfo(`<builtin:${name}>`, { source: \"builtin\" }),\n\t\t\t\t},\n\t\t\t]),\n\t);\n\tfor (const tool of allCustomTools) {\n\t\tdefinitionRegistry.set(tool.definition.name, {\n\t\t\tdefinition: tool.definition,\n\t\t\tsourceInfo: tool.sourceInfo,\n\t\t});\n\t}\n\tthis._toolDefinitions = definitionRegistry;\n\tthis._toolPromptSnippets = new Map(\n\t\tArray.from(definitionRegistry.values())\n\t\t\t.map(({ definition }) => {\n\t\t\t\tconst snippet = this._normalizePromptSnippet(definition.promptSnippet);\n\t\t\t\treturn snippet ? ([definition.name, snippet] as const) : undefined;\n\t\t\t})\n\t\t\t.filter((entry): entry is readonly [string, string] => entry !== undefined),\n\t);\n\tthis._toolPromptGuidelines = new Map(\n\t\tArray.from(definitionRegistry.values())\n\t\t\t.map(({ definition }) => {\n\t\t\t\tconst guidelines = this._normalizePromptGuidelines(definition.promptGuidelines);\n\t\t\t\treturn guidelines.length > 0 ? ([definition.name, guidelines] as const) : undefined;\n\t\t\t})\n\t\t\t.filter((entry): entry is readonly [string, string[]] => entry !== undefined),\n\t);\n\tconst runner = this._extensionRunner;\n\tconst wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);\n\tconst wrappedBuiltInTools = wrapRegisteredTools(\n\t\tArray.from(this._baseToolDefinitions.values())\n\t\t\t.filter((definition) => isExposedTool(definition.name))\n\t\t\t.map((definition) => ({\n\t\t\t\tdefinition,\n\t\t\t\tsourceInfo: createSyntheticSourceInfo(`<builtin:${definition.name}>`, { source: \"builtin\" }),\n\t\t\t})),\n\t\trunner,\n\t);\n\n\tconst toolRegistry = new Map(wrappedBuiltInTools.map((tool) => [tool.name, tool]));\n\tfor (const tool of wrappedExtensionTools as AgentTool[]) {\n\t\ttoolRegistry.set(tool.name, tool);\n\t}\n\tthis._toolRegistry = toolRegistry;\n\n\tconst nextActiveToolNames = (\n\t\toptions?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]\n\t).filter((name) => isExposedTool(name));\n\n\tif (allowedToolNames) {\n\t\tfor (const toolName of this._toolRegistry.keys()) {\n\t\t\tif (allowedToolNames.has(toolName)) {\n\t\t\t\tnextActiveToolNames.push(toolName);\n\t\t\t}\n\t\t}\n\t} else if (options?.includeAllExtensionTools) {\n\t\tfor (const tool of wrappedExtensionTools) {\n\t\t\tnextActiveToolNames.push(tool.name);\n\t\t}\n\t} else if (!options?.activeToolNames) {\n\t\tfor (const toolName of this._toolRegistry.keys()) {\n\t\t\tif (!previousRegistryNames.has(toolName)) {\n\t\t\t\tnextActiveToolNames.push(toolName);\n\t\t\t}\n\t\t}\n\t}\n\n\tthis.setActiveToolsByName([...new Set(nextActiveToolNames)]);\n}\n\nexport function _buildRuntime(\n\tthis: AgentSession,\n\toptions: {\n\t\tactiveToolNames?: string[];\n\t\tflagValues?: Map<string, boolean | string>;\n\t\tincludeAllExtensionTools?: boolean;\n\t\tpreserveRunner?: boolean;\n\t},\n): void {\n\tconst autoResizeImages = this.settingsManager.getImageAutoResize();\n\tconst shellCommandPrefix = this.settingsManager.getShellCommandPrefix();\n\tconst shellPath = this.settingsManager.getShellPath();\n\tconst isAllowedBuiltinTool = (name: string): boolean => {\n\t\tif (this._allowedToolNames && !this._allowedToolNames.has(name)) return false;\n\t\tif (this._excludedToolNames?.has(name)) return false;\n\t\treturn true;\n\t};\n\tconst activeBuiltinTools = (options.activeToolNames ?? [...getDefaultToolNames()]).filter(isAllowedBuiltinTool);\n\t// Resolve ownership per call, just like command execution. Each wait receives\n\t// a stable binding so observation cleanup can finish after session disposal.\n\tconst getTaskOwner = () =>\n\t\tthis._subagentPolicy?.depth && this._subagentPolicy.depth >= 1 ? undefined : this.getAgentTaskHost().ownerBinding;\n\tconst baseToolDefinitions = this._baseToolsOverride\n\t\t? Object.fromEntries(\n\t\t\t\tObject.entries(this._baseToolsOverride).map(([name, tool]) => [\n\t\t\t\t\tname,\n\t\t\t\t\tcreateToolDefinitionFromAgentTool(tool),\n\t\t\t\t]),\n\t\t\t)\n\t\t: createAllToolDefinitions(this._cwd, {\n\t\t\t\t// Resolved per execution for the same reason as `sessionTempDir` below: a\n\t\t\t\t// requester captured at construction would keep a stale session id across\n\t\t\t\t// fork/branch/resume, which is exactly the relaunch this makes legible.\n\t\t\t\tresolveMutationRequester: (toolCallId) =>\n\t\t\t\t\tbuildMutationRequester({\n\t\t\t\t\t\tsessionId: this.sessionManager.getSessionId(),\n\t\t\t\t\t\t...(this._orchestrationContext ? { orchestration: this._orchestrationContext } : {}),\n\t\t\t\t\t\t...(this._subagentPolicy?.intercom ? { intercom: this._subagentPolicy.intercom } : {}),\n\t\t\t\t\t\ttoolCallId,\n\t\t\t\t\t}),\n\t\t\t\tread: { autoResizeImages },\n\t\t\t\tbash: {\n\t\t\t\t\tcommandPrefix: shellCommandPrefix,\n\t\t\t\t\tshellPath,\n\t\t\t\t\tget taskOwner() {\n\t\t\t\t\t\treturn getTaskOwner();\n\t\t\t\t\t},\n\t\t\t\t\t...(!(this._subagentPolicy?.depth && this._subagentPolicy.depth >= 1)\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\toperations: {\n\t\t\t\t\t\t\t\t\texec: (command, cwd, options) =>\n\t\t\t\t\t\t\t\t\t\tcreateLocalBashOperations({\n\t\t\t\t\t\t\t\t\t\t\tshellPath,\n\t\t\t\t\t\t\t\t\t\t\ttaskOwner: this.getAgentTaskHost().ownerBinding,\n\t\t\t\t\t\t\t\t\t\t}).exec(command, cwd, options),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t\tinterceptorEnabled: () => this.settingsManager.getBashInterceptorEnabled(),\n\t\t\t\t\tavailableTools: activeBuiltinTools,\n\t\t\t\t\t// Resolved per execution so bash spill files follow the live\n\t\t\t\t\t// transcript session across fork/branch/resume.\n\t\t\t\t\tsessionTempDir: () => resolveSessionTempDirPath(this.sessionManager.getSessionId()),\n\t\t\t\t\tinterceptor: async (context) => {\n\t\t\t\t\t\tconst result = await this._extensionRunner.emitUserBash({\n\t\t\t\t\t\t\ttype: \"user_bash\",\n\t\t\t\t\t\t\tcommand: context.command,\n\t\t\t\t\t\t\texcludeFromContext: false,\n\t\t\t\t\t\t\tcwd: context.cwd,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tpowershell: {\n\t\t\t\t\tget taskOwner() {\n\t\t\t\t\t\treturn getTaskOwner();\n\t\t\t\t\t},\n\t\t\t\t\t...(!(this._subagentPolicy?.depth && this._subagentPolicy.depth >= 1)\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\toperations: {\n\t\t\t\t\t\t\t\t\texec: (command, cwd, options) =>\n\t\t\t\t\t\t\t\t\t\tcreateLocalPowerShellOperations({\n\t\t\t\t\t\t\t\t\t\t\ttaskOwner: this.getAgentTaskHost().ownerBinding,\n\t\t\t\t\t\t\t\t\t\t}).exec(command, cwd, options),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t\tkill: {\n\t\t\t\t\ttaskOwner: () => this.getAgentTaskHost().ownerBinding,\n\t\t\t\t},\n\t\t\t\tsearch: {\n\t\t\t\t\tcontextBefore: this.settingsManager.getSearchContextBefore(),\n\t\t\t\t\tcontextAfter: this.settingsManager.getSearchContextAfter(),\n\t\t\t\t},\n\t\t\t});\n\n\tthis._baseToolDefinitions = new Map(\n\t\tObject.entries(baseToolDefinitions).map(([name, tool]) => [name, tool as ToolDefinition]),\n\t);\n\n\tconst extensionsResult = this._resourceLoader.getExtensions();\n\tif (options.flagValues) {\n\t\tfor (const [name, value] of options.flagValues) {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\textensionsResult.runtime.explicitFlagNames ??= new Set();\n\t\t\textensionsResult.runtime.explicitFlagNames.add(name);\n\t\t}\n\t}\n\n\tif (!options.preserveRunner) {\n\t\tthis._extensionRunner = new ExtensionRunner(\n\t\t\textensionsResult.extensions,\n\t\t\textensionsResult.runtime,\n\t\t\tthis._cwd,\n\t\t\tthis.sessionManager,\n\t\t\tnew ModelRegistry(this._modelRuntime),\n\t\t\tthis._orchestrationContext,\n\t\t\tthis._subagentPolicy,\n\t\t);\n\t\tif (this._extensionRunnerRef) {\n\t\t\tthis._extensionRunnerRef.current = this._extensionRunner;\n\t\t}\n\t\tthis._bindExtensionCore(this._extensionRunner);\n\t\tthis._applyExtensionBindings(this._extensionRunner);\n\t}\n\n\tconst defaultActiveToolNames = this._baseToolsOverride\n\t\t? Object.keys(this._baseToolsOverride)\n\t\t: [...getDefaultToolNames()];\n\tconst baseActiveToolNames = options.activeToolNames ?? defaultActiveToolNames;\n\tthis._refreshToolRegistry({\n\t\tactiveToolNames: baseActiveToolNames,\n\t\tincludeAllExtensionTools: options.includeAllExtensionTools,\n\t});\n}\n\nexport const agentSessionToolRegistryMethods = {\n\t_refreshToolRegistry,\n\t_buildRuntime,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"agent-session-tool-registry.js","sourceRoot":"","sources":["../../src/core/agent-session-tool-registry.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAuB,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAClG,OAAO,EAAE,sBAAsB,EAAE,6BAA6B,EAAE,MAAM,8BAA8B,CAAC;AACrG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,+BAA+B,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AG,IAAI,CAAC,kBAAkB;QACrD,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC;QACtC,CAAC,CAAC,CAAC,GAAG,mBAAmB,EAAE,CAAC,CAAC;IAC9B,MAAM,mBAAmB,GAAG,OAAO,CAAC,eAAe,IAAI,sBAAsB,CAAC;IAC9E,IAAI,CAAC,oBAAoB,CAAC;QACzB,eAAe,EAAE,mBAAmB;QACpC,wBAAwB,EAAE,OAAO,CAAC,wBAAwB;KAC1D,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,CAAC,MAAM,+BAA+B,GAAG;IAC9C,oBAAoB;IACpB,aAAa;CACb,CAAC","sourcesContent":["import type { AgentTool } from \"@earendil-works/pi-agent-core\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport type { ToolDefinitionEntry } from \"./agent-session-types.js\";\nimport { ExtensionRunner, type ToolDefinition, wrapRegisteredTools } from \"./extensions/index.js\";\nimport { isMandatoryRuntimeTool, isTrustedMandatoryRuntimeTool } from \"./mandatory-runtime-tools.ts\";\nimport { ModelRegistry } from \"./model-registry.ts\";\nimport { createSyntheticSourceInfo } from \"./source-info.ts\";\nimport { createLocalBashOperations } from \"./tools/bash.js\";\nimport { buildMutationRequester } from \"./tools/file-mutation-coordinator.ts\";\nimport { createAllToolDefinitions, getDefaultToolNames } from \"./tools/index.ts\";\nimport { createLocalPowerShellOperations } from \"./tools/powershell.ts\";\nimport { resolveSessionTempDirPath } from \"./tools/session-temp-dir.ts\";\nimport { createToolDefinitionFromAgentTool } from \"./tools/tool-definition-wrapper.ts\";\n\nexport function _refreshToolRegistry(\n\tthis: AgentSession,\n\toptions?: { activeToolNames?: string[]; includeAllExtensionTools?: boolean },\n): void {\n\tconst previousRegistryNames = new Set(this._toolRegistry.keys());\n\tconst previousActiveToolNames = this.getActiveToolNames();\n\tconst allowedToolNames = this._allowedToolNames;\n\tconst excludedToolNames = this._excludedToolNames;\n\tconst isExposedTool = (name: string): boolean => {\n\t\tif (allowedToolNames && !allowedToolNames.has(name)) {\n\t\t\treturn false;\n\t\t}\n\t\tif (excludedToolNames?.has(name)) {\n\t\t\treturn false;\n\t\t}\n\t\treturn true;\n\t};\n\n\tconst registeredTools = this._extensionRunner\n\t\t.getAllRegisteredTools()\n\t\t.filter((tool) => !isMandatoryRuntimeTool(tool.definition.name) || isTrustedMandatoryRuntimeTool(tool));\n\tconst allCustomTools = [\n\t\t...registeredTools,\n\t\t...this._customTools\n\t\t\t.filter((definition) => !isMandatoryRuntimeTool(definition.name))\n\t\t\t.map((definition) => ({\n\t\t\t\tdefinition,\n\t\t\t\tsourceInfo: createSyntheticSourceInfo(`<sdk:${definition.name}>`, { source: \"sdk\" }),\n\t\t\t})),\n\t].filter((tool) => isExposedTool(tool.definition.name));\n\tconst definitionRegistry = new Map<string, ToolDefinitionEntry>(\n\t\tArray.from(this._baseToolDefinitions.entries())\n\t\t\t.filter(([name]) => isExposedTool(name))\n\t\t\t.map(([name, definition]) => [\n\t\t\t\tname,\n\t\t\t\t{\n\t\t\t\t\tdefinition,\n\t\t\t\t\tsourceInfo: createSyntheticSourceInfo(`<builtin:${name}>`, { source: \"builtin\" }),\n\t\t\t\t},\n\t\t\t]),\n\t);\n\tfor (const tool of allCustomTools) {\n\t\tdefinitionRegistry.set(tool.definition.name, {\n\t\t\tdefinition: tool.definition,\n\t\t\tsourceInfo: tool.sourceInfo,\n\t\t});\n\t}\n\tthis._toolDefinitions = definitionRegistry;\n\tthis._toolPromptSnippets = new Map(\n\t\tArray.from(definitionRegistry.values())\n\t\t\t.map(({ definition }) => {\n\t\t\t\tconst snippet = this._normalizePromptSnippet(definition.promptSnippet);\n\t\t\t\treturn snippet ? ([definition.name, snippet] as const) : undefined;\n\t\t\t})\n\t\t\t.filter((entry): entry is readonly [string, string] => entry !== undefined),\n\t);\n\tthis._toolPromptGuidelines = new Map(\n\t\tArray.from(definitionRegistry.values())\n\t\t\t.map(({ definition }) => {\n\t\t\t\tconst guidelines = this._normalizePromptGuidelines(definition.promptGuidelines);\n\t\t\t\treturn guidelines.length > 0 ? ([definition.name, guidelines] as const) : undefined;\n\t\t\t})\n\t\t\t.filter((entry): entry is readonly [string, string[]] => entry !== undefined),\n\t);\n\tconst runner = this._extensionRunner;\n\tconst wrappedExtensionTools = wrapRegisteredTools(allCustomTools, runner);\n\tconst wrappedBuiltInTools = wrapRegisteredTools(\n\t\tArray.from(this._baseToolDefinitions.values())\n\t\t\t.filter((definition) => isExposedTool(definition.name))\n\t\t\t.map((definition) => ({\n\t\t\t\tdefinition,\n\t\t\t\tsourceInfo: createSyntheticSourceInfo(`<builtin:${definition.name}>`, { source: \"builtin\" }),\n\t\t\t})),\n\t\trunner,\n\t);\n\n\tconst toolRegistry = new Map(wrappedBuiltInTools.map((tool) => [tool.name, tool]));\n\tfor (const tool of wrappedExtensionTools as AgentTool[]) {\n\t\ttoolRegistry.set(tool.name, tool);\n\t}\n\tthis._toolRegistry = toolRegistry;\n\n\tconst nextActiveToolNames = (\n\t\toptions?.activeToolNames ? [...options.activeToolNames] : [...previousActiveToolNames]\n\t).filter((name) => isExposedTool(name));\n\n\tif (allowedToolNames) {\n\t\tfor (const toolName of this._toolRegistry.keys()) {\n\t\t\tif (allowedToolNames.has(toolName)) {\n\t\t\t\tnextActiveToolNames.push(toolName);\n\t\t\t}\n\t\t}\n\t} else if (options?.includeAllExtensionTools) {\n\t\tfor (const tool of wrappedExtensionTools) {\n\t\t\tnextActiveToolNames.push(tool.name);\n\t\t}\n\t} else if (!options?.activeToolNames) {\n\t\tfor (const toolName of this._toolRegistry.keys()) {\n\t\t\tif (!previousRegistryNames.has(toolName)) {\n\t\t\t\tnextActiveToolNames.push(toolName);\n\t\t\t}\n\t\t}\n\t}\n\n\tthis.setActiveToolsByName([...new Set(nextActiveToolNames)]);\n}\n\nexport function _buildRuntime(\n\tthis: AgentSession,\n\toptions: {\n\t\tactiveToolNames?: string[];\n\t\tflagValues?: Map<string, boolean | string>;\n\t\tincludeAllExtensionTools?: boolean;\n\t\tpreserveRunner?: boolean;\n\t},\n): void {\n\tconst autoResizeImages = this.settingsManager.getImageAutoResize();\n\tconst shellCommandPrefix = this.settingsManager.getShellCommandPrefix();\n\tconst shellPath = this.settingsManager.getShellPath();\n\tconst isAllowedBuiltinTool = (name: string): boolean => {\n\t\tif (this._allowedToolNames && !this._allowedToolNames.has(name)) return false;\n\t\tif (this._excludedToolNames?.has(name)) return false;\n\t\treturn true;\n\t};\n\tconst activeBuiltinTools = (options.activeToolNames ?? [...getDefaultToolNames()]).filter(isAllowedBuiltinTool);\n\t// Resolve ownership per call, just like command execution. Each wait receives\n\t// a stable binding so observation cleanup can finish after session disposal.\n\tconst getTaskOwner = () =>\n\t\tthis._subagentPolicy?.depth && this._subagentPolicy.depth >= 1 ? undefined : this.getAgentTaskHost().ownerBinding;\n\tconst baseToolDefinitions = this._baseToolsOverride\n\t\t? Object.fromEntries(\n\t\t\t\tObject.entries(this._baseToolsOverride).map(([name, tool]) => [\n\t\t\t\t\tname,\n\t\t\t\t\tcreateToolDefinitionFromAgentTool(tool),\n\t\t\t\t]),\n\t\t\t)\n\t\t: createAllToolDefinitions(this._cwd, {\n\t\t\t\t// Resolved per execution for the same reason as `sessionTempDir` below: a\n\t\t\t\t// requester captured at construction would keep a stale session id across\n\t\t\t\t// fork/branch/resume, which is exactly the relaunch this makes legible.\n\t\t\t\tresolveMutationRequester: (toolCallId) =>\n\t\t\t\t\tbuildMutationRequester({\n\t\t\t\t\t\tsessionId: this.sessionManager.getSessionId(),\n\t\t\t\t\t\t...(this._orchestrationContext ? { orchestration: this._orchestrationContext } : {}),\n\t\t\t\t\t\t...(this._subagentPolicy?.intercom ? { intercom: this._subagentPolicy.intercom } : {}),\n\t\t\t\t\t\ttoolCallId,\n\t\t\t\t\t}),\n\t\t\t\tread: { autoResizeImages },\n\t\t\t\tbash: {\n\t\t\t\t\tcommandPrefix: shellCommandPrefix,\n\t\t\t\t\tshellPath,\n\t\t\t\t\tget taskOwner() {\n\t\t\t\t\t\treturn getTaskOwner();\n\t\t\t\t\t},\n\t\t\t\t\t...(!(this._subagentPolicy?.depth && this._subagentPolicy.depth >= 1)\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\toperations: {\n\t\t\t\t\t\t\t\t\texec: (command, cwd, options) =>\n\t\t\t\t\t\t\t\t\t\tcreateLocalBashOperations({\n\t\t\t\t\t\t\t\t\t\t\tshellPath,\n\t\t\t\t\t\t\t\t\t\t\ttaskOwner: this.getAgentTaskHost().ownerBinding,\n\t\t\t\t\t\t\t\t\t\t}).exec(command, cwd, options),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t\tinterceptorEnabled: () => this.settingsManager.getBashInterceptorEnabled(),\n\t\t\t\t\tavailableTools: activeBuiltinTools,\n\t\t\t\t\t// Resolved per execution so bash spill files follow the live\n\t\t\t\t\t// transcript session across fork/branch/resume.\n\t\t\t\t\tsessionTempDir: () => resolveSessionTempDirPath(this.sessionManager.getSessionId()),\n\t\t\t\t\tinterceptor: async (context) => {\n\t\t\t\t\t\tconst result = await this._extensionRunner.emitUserBash({\n\t\t\t\t\t\t\ttype: \"user_bash\",\n\t\t\t\t\t\t\tcommand: context.command,\n\t\t\t\t\t\t\texcludeFromContext: false,\n\t\t\t\t\t\t\tcwd: context.cwd,\n\t\t\t\t\t\t});\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tpowershell: {\n\t\t\t\t\tget taskOwner() {\n\t\t\t\t\t\treturn getTaskOwner();\n\t\t\t\t\t},\n\t\t\t\t\t...(!(this._subagentPolicy?.depth && this._subagentPolicy.depth >= 1)\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\toperations: {\n\t\t\t\t\t\t\t\t\texec: (command, cwd, options) =>\n\t\t\t\t\t\t\t\t\t\tcreateLocalPowerShellOperations({\n\t\t\t\t\t\t\t\t\t\t\ttaskOwner: this.getAgentTaskHost().ownerBinding,\n\t\t\t\t\t\t\t\t\t\t}).exec(command, cwd, options),\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {}),\n\t\t\t\t},\n\t\t\t\tkill: {\n\t\t\t\t\ttaskOwner: () => this.getAgentTaskHost().ownerBinding,\n\t\t\t\t},\n\t\t\t\tsearch: {\n\t\t\t\t\tcontextBefore: this.settingsManager.getSearchContextBefore(),\n\t\t\t\t\tcontextAfter: this.settingsManager.getSearchContextAfter(),\n\t\t\t\t},\n\t\t\t});\n\n\tthis._baseToolDefinitions = new Map(\n\t\tObject.entries(baseToolDefinitions).map(([name, tool]) => [name, tool as ToolDefinition]),\n\t);\n\n\tconst extensionsResult = this._resourceLoader.getExtensions();\n\tif (options.flagValues) {\n\t\tfor (const [name, value] of options.flagValues) {\n\t\t\textensionsResult.runtime.flagValues.set(name, value);\n\t\t\textensionsResult.runtime.explicitFlagNames ??= new Set();\n\t\t\textensionsResult.runtime.explicitFlagNames.add(name);\n\t\t}\n\t}\n\n\tif (!options.preserveRunner) {\n\t\tthis._extensionRunner = new ExtensionRunner(\n\t\t\textensionsResult.extensions,\n\t\t\textensionsResult.runtime,\n\t\t\tthis._cwd,\n\t\t\tthis.sessionManager,\n\t\t\tnew ModelRegistry(this._modelRuntime),\n\t\t\tthis._orchestrationContext,\n\t\t\tthis._subagentPolicy,\n\t\t);\n\t\tif (this._extensionRunnerRef) {\n\t\t\tthis._extensionRunnerRef.current = this._extensionRunner;\n\t\t}\n\t\tthis._bindExtensionCore(this._extensionRunner);\n\t\tthis._applyExtensionBindings(this._extensionRunner);\n\t}\n\n\tconst defaultActiveToolNames = this._baseToolsOverride\n\t\t? Object.keys(this._baseToolsOverride)\n\t\t: [...getDefaultToolNames()];\n\tconst baseActiveToolNames = options.activeToolNames ?? defaultActiveToolNames;\n\tthis._refreshToolRegistry({\n\t\tactiveToolNames: baseActiveToolNames,\n\t\tincludeAllExtensionTools: options.includeAllExtensionTools,\n\t});\n}\n\nexport const agentSessionToolRegistryMethods = {\n\t_refreshToolRegistry,\n\t_buildRuntime,\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-session-transfer.js","sourceRoot":"","sources":["../../src/core/agent-session-transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,8BAA8B,EAC9B,kCAAkC,GAClC,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,wCAAwC,EAAE,MAAM,+CAA+C,CAAC;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,wGAAwG;AACxG,MAAM,UAAU,iCAAiC,CAAqB,MAAc;IACnF,MAAM,eAAe,GAAG,MAAsB,CAAC;IAC/C,MAAM,MAAM,GAAG,8BAA8B,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACrE,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO;IACjC,MAAM,IAAI,GAAG,kCAAkC,CAAC,eAAe,CAAC,CAAC;IACjE,MAAM,YAAY,GAAG,MAAM,CAAC,qBAAqB,CAAC;IAClD,MAAM,YAAY,GAAG,IAAI,CAAC,qBAAqB,CAAC;IAChD,MAAM,oBAAoB,GAAG,MAAM,CAAC,uBAAuB,CAAC;IAC5D,MAAM,oBAAoB,GAAG,IAAI,CAAC,uBAAuB,CAAC;IAC1D,MAAM,uBAAuB,GAAG,MAAM,CAAC,2BAA2B,CAAC;IACnE,MAAM,UAAU,GAAG,MAAM,CAAC,yBAAyB,EAAE,CAAC;IACtD,MAAM,mBAAmB,GAAG,MAAM,CAAC,iCAAiC,CAAC;IACrE,MAAM,mBAAmB,GAAG,IAAI,CAAC,iCAAiC,CAAC;IACnE,MAAM,UAAU,GAAG,IAAI,CAAC,yBAAyB,EAAE,CAAC;IACpD,MAAM,UAAU,GAAG,MAAM,CAAC,yBAAyB,IAAI,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C;YACtB,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,mBAAmB;YACpD,CAAC,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAC5C,CAAC;IACH,CAAC;SAAM,CAAC;QACP,IAAI,CAAC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IACD,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAC1B,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import {\n\tforwardWorkflowStageDeliveries,\n\tresolveWorkflowStageDeliveryTarget,\n} from \"./agent-session-delivery-forwarding.ts\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { transferProtectedStreamingCustomMessages } from \"./agent-session-persistent-custom-messages.ts\";\nimport { composePauseAbortBoundaries } from \"./agent-session-queue-pause.ts\";\nimport { priorityHoldCounts } from \"./agent-session-types.
|
|
1
|
+
{"version":3,"file":"agent-session-transfer.js","sourceRoot":"","sources":["../../src/core/agent-session-transfer.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,8BAA8B,EAC9B,kCAAkC,GAClC,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAE,wCAAwC,EAAE,MAAM,+CAA+C,CAAC;AACzG,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D,wGAAwG;AACxG,MAAM,UAAU,iCAAiC,CAAqB,MAAc;IACnF,MAAM,eAAe,GAAG,MAAsB,CAAC;IAC/C,MAAM,MAAM,GAAG,8BAA8B,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACrE,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO;IACjC,MAAM,IAAI,GAAG,kCAAkC,CAAC,eAAe,CAAC,CAAC;IACjE,MAAM,YAAY,GAAG,MAAM,CAAC,qBAAqB,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AE,KAAK,wBAAwB,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC1F,MAAM,aAAa,GAAG,YAAY,IAAI,YAAY,CAAC;IACnD,IAAI,CAAC,qBAAqB,GAAG,aAAa,CAAC;IAC3C,IAAI,aAAa,IAAI,IAAI,CAAC,2BAA2B,GAAG,CAAC,EAAE,CAAC;QAC3D,0EAA0E;QAC1E,2EAA2E;QAC3E,IAAI,CAAC,yBAAyB,GAAG,WAAW,CAAC;QAC7C,sEAAsE;QACtE,wEAAwE;QACxE,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACpE,kBAAkB,CAAC,GAAG,CACrB,WAAW,EACX,mBAAmB,GAAG,CAAC;YACtB,CAAC,CAAC,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,mBAAmB;YACpD,CAAC,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAC5C,CAAC;IACH,CAAC;SAAM,CAAC;QACP,IAAI,CAAC,2BAA2B,CAAC,WAAW,CAAC,CAAC;IAC/C,CAAC;IACD,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAC1B,IAAI,CAAC,gBAAgB,EAAE,CAAC;AACzB,CAAC","sourcesContent":["import {\n\tforwardWorkflowStageDeliveries,\n\tresolveWorkflowStageDeliveryTarget,\n} from \"./agent-session-delivery-forwarding.ts\";\nimport type { AgentSessionInternalSurface as AgentSession } from \"./agent-session-methods.ts\";\nimport { transferProtectedStreamingCustomMessages } from \"./agent-session-persistent-custom-messages.ts\";\nimport { composePauseAbortBoundaries } from \"./agent-session-queue-pause.ts\";\nimport { priorityHoldCounts } from \"./agent-session-types.js\";\n\n/** Atomically retire one stage session and prepend all of its delivery ownership to the replacement. */\nexport function transferWorkflowStageDeliveriesTo(this: AgentSession, target: object): void {\n\tconst requestedTarget = target as AgentSession;\n\tconst source = forwardWorkflowStageDeliveries(this, requestedTarget);\n\tif (source === undefined) return;\n\tconst next = resolveWorkflowStageDeliveryTarget(requestedTarget);\n\tconst sourcePaused = source._queuedMessagesPaused;\n\tconst targetPaused = next._queuedMessagesPaused;\n\tconst sourceInterruptQueue = source._interruptDeliveryQueue;\n\tconst targetInterruptQueue = next._interruptDeliveryQueue;\n\tconst sourcePendingInterrupts = source._pendingInterruptDeliveries;\n\tconst sourceLive = source._drainQueuedAgentMessages();\n\tconst sourceAbortBoundary = source._queuedMessagesPauseAbortBoundary;\n\tconst targetAbortBoundary = next._queuedMessagesPauseAbortBoundary;\n\tconst targetLive = next._drainQueuedAgentMessages();\n\tconst sourceHeld = source._activeInterruptQueueHold ?? { steering: [], followUp: [] };\n\tconst targetHeld = next._activeInterruptQueueHold ?? { steering: [], followUp: [] };\n\tconst sourceQueues = {\n\t\tsteering: [...sourceHeld.steering, ...sourceLive.steering],\n\t\tfollowUp: [...sourceHeld.followUp, ...sourceLive.followUp],\n\t};\n\tconst transferred = {\n\t\tsteering: [...sourceQueues.steering, ...targetHeld.steering, ...targetLive.steering],\n\t\tfollowUp: [...sourceQueues.followUp, ...targetHeld.followUp, ...targetLive.followUp],\n\t};\n\ttransferProtectedStreamingCustomMessages(source, next, sourceQueues);\n\tnext._pendingNextTurnMessages.unshift(...source._pendingNextTurnMessages.splice(0));\n\tnext._pendingCustomMessages.unshift(...source._pendingCustomMessages.splice(0));\n\tnext._steeringMessages = [...source._steeringMessages.splice(0), ...next._steeringMessages];\n\tnext._followUpMessages = [...source._followUpMessages.splice(0), ...next._followUpMessages];\n\tsource._activeInterruptQueueHold = undefined;\n\tsource._queuedMessagesPaused = false;\n\tsource._queuedMessagesPauseAbortBoundary = undefined;\n\tsource._pendingInterruptDeliveries = 0;\n\tif (sourcePendingInterrupts > 0) {\n\t\tnext._pendingInterruptDeliveries += sourcePendingInterrupts;\n\t\t// Existing source and replacement deliveries may already be running. Future\n\t\t// interrupts and resume must wait for both settlement chains without making\n\t\t// the forwarded source callback wait on a chain that contains itself.\n\t\tnext._interruptDeliveryQueue = Promise.all([sourceInterruptQueue, targetInterruptQueue])\n\t\t\t.then(() => undefined)\n\t\t\t.catch(() => undefined);\n\t}\n\tnext._activeInterruptQueueHold = undefined;\n\tconst transferredAbortBoundary = composePauseAbortBoundaries([sourceAbortBoundary, targetAbortBoundary]);\n\tnext._queuedMessagesPauseAbortBoundary = transferredAbortBoundary;\n\tif (transferredAbortBoundary !== undefined) void transferredAbortBoundary.catch(() => {});\n\tconst remainsPaused = sourcePaused || targetPaused;\n\tnext._queuedMessagesPaused = remainsPaused;\n\tif (remainsPaused || next._pendingInterruptDeliveries > 0) {\n\t\t// A transferred interrupt keeps exclusive ownership of the combined hold.\n\t\t// Its finalizer restores the hold only after the last live-owner delivery.\n\t\tnext._activeInterruptQueueHold = transferred;\n\t\t// Keep the insertion boundary after older priority input, including a\n\t\t// replacement's own priority prefix behind the prepended source queues.\n\t\tconst targetPriorityCount = priorityHoldCounts.get(targetHeld) ?? 0;\n\t\tpriorityHoldCounts.set(\n\t\t\ttransferred,\n\t\t\ttargetPriorityCount > 0\n\t\t\t\t? sourceQueues.steering.length + targetPriorityCount\n\t\t\t\t: (priorityHoldCounts.get(sourceHeld) ?? 0),\n\t\t);\n\t} else {\n\t\tnext._restoreQueuedAgentMessages(transferred);\n\t}\n\tsource._emitQueueUpdate();\n\tnext._emitQueueUpdate();\n}\n"]}
|