stitchkit 0.132.2 → 0.133.0
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 +181 -1
- package/dist/agent-executor/acp/v1-connect.d.ts +12 -1
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-driver.d.ts +3 -1
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-handlers.d.ts +9 -1
- package/dist/agent-executor/acp/v1-handlers.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-permission.d.ts +3 -2
- package/dist/agent-executor/acp/v1-permission.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-probe.d.ts +10 -1
- package/dist/agent-executor/acp/v1-probe.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts +11 -2
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-turn.d.ts +13 -10
- package/dist/agent-executor/acp/v1-turn.d.ts.map +1 -1
- package/dist/agent-executor/claude/cli-driver.d.ts +6 -0
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
- package/dist/agent-executor/claude/record-router.d.ts +44 -0
- package/dist/agent-executor/claude/record-router.d.ts.map +1 -0
- package/dist/agent-executor/claude/session.d.ts +2 -0
- package/dist/agent-executor/claude/session.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/controls.d.ts +1 -0
- package/dist/agent-executor/claude-sdk/controls.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/driver.d.ts +20 -2
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/engine-spawn.d.ts +18 -0
- package/dist/agent-executor/claude-sdk/engine-spawn.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/query-loop.d.ts +9 -7
- package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/query-manager.d.ts +42 -0
- package/dist/agent-executor/claude-sdk/query-manager.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/query-options.d.ts +4 -1
- package/dist/agent-executor/claude-sdk/query-options.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/capabilities.d.ts +8 -0
- package/dist/agent-executor/codex/capabilities.d.ts.map +1 -0
- package/dist/agent-executor/codex/connect.d.ts +6 -1
- package/dist/agent-executor/codex/connect.d.ts.map +1 -1
- package/dist/agent-executor/codex/driver.d.ts +10 -0
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/codex/event-routing.d.ts +23 -1
- package/dist/agent-executor/codex/event-routing.d.ts.map +1 -1
- package/dist/agent-executor/codex/handlers.d.ts +24 -4
- package/dist/agent-executor/codex/handlers.d.ts.map +1 -1
- package/dist/agent-executor/codex/limits.d.ts +17 -0
- package/dist/agent-executor/codex/limits.d.ts.map +1 -1
- package/dist/agent-executor/codex/request-answers.d.ts +23 -3
- package/dist/agent-executor/codex/request-answers.d.ts.map +1 -1
- package/dist/agent-executor/codex/session-bind.d.ts +6 -1
- package/dist/agent-executor/codex/session-bind.d.ts.map +1 -1
- package/dist/agent-executor/codex/session-types.d.ts +5 -1
- package/dist/agent-executor/codex/session-types.d.ts.map +1 -1
- package/dist/agent-executor/codex/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-server.d.ts.map +1 -1
- package/dist/agent-executor/codex/shared-thread.d.ts +7 -7
- package/dist/agent-executor/codex/shared-thread.d.ts.map +1 -1
- package/dist/agent-executor/codex/thread-open.d.ts +12 -3
- package/dist/agent-executor/codex/thread-open.d.ts.map +1 -1
- package/dist/agent-executor/engine-requests.d.ts +42 -0
- package/dist/agent-executor/engine-requests.d.ts.map +1 -1
- package/dist/agent-executor/handoff-schemas.d.ts.map +1 -1
- package/dist/agent-executor/handoff.d.ts.map +1 -1
- package/dist/agent-executor/image-input.d.ts +6 -5
- package/dist/agent-executor/image-input.d.ts.map +1 -1
- package/dist/agent-executor/profile.d.ts +3 -5
- package/dist/agent-executor/profile.d.ts.map +1 -1
- package/dist/agent-executor/session-primitives.d.ts +64 -3
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-executor/testing/claude-sdk-stubs.d.ts +5 -0
- package/dist/agent-executor/testing/claude-sdk-stubs.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance-lifecycle.d.ts +11 -0
- package/dist/agent-executor/testing/conformance-lifecycle.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance-support.d.ts +23 -0
- package/dist/agent-executor/testing/conformance-support.d.ts.map +1 -0
- package/dist/agent-executor/testing/conformance.d.ts +7 -2
- package/dist/agent-executor/testing/conformance.d.ts.map +1 -1
- package/dist/agent-executor/testing/consumer-stubs.d.ts +5 -3
- package/dist/agent-executor/testing/consumer-stubs.d.ts.map +1 -1
- package/dist/agent-executor/testing/fake-codex-app-server.d.ts +5 -1
- package/dist/agent-executor/testing/fake-codex-app-server.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-driver.d.ts +6 -0
- package/dist/agent-executor/testing/replay-driver.d.ts.map +1 -1
- package/dist/agent-executor/testing/replay-gate.d.ts +4 -1
- package/dist/agent-executor/testing/replay-gate.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tool-types.d.ts +2 -0
- package/dist/agent-runtime/deferred-tool-types.d.ts.map +1 -1
- package/dist/agent-runtime/deferred-tools.d.ts.map +1 -1
- package/dist/agent-runtime/sql-rows.d.ts +10 -10
- package/dist/agent-runtime/store-conformance-lifecycle.d.ts +20 -20
- package/dist/agent-runtime/store-conformance-support.d.ts +10 -10
- package/dist/agent-runtime/terminal-commit.d.ts +10 -10
- package/dist/browser/client.d.ts.map +1 -1
- package/dist/browser/operation-refusal.d.ts +10 -0
- package/dist/browser/operation-refusal.d.ts.map +1 -0
- package/dist/contract/client-types.d.ts +13 -4
- package/dist/contract/client-types.d.ts.map +1 -1
- package/dist/contract/define-validation.d.ts +6 -0
- package/dist/contract/define-validation.d.ts.map +1 -1
- package/dist/contract/define.d.ts +3 -0
- package/dist/contract/define.d.ts.map +1 -1
- package/dist/contract/errors-factory.d.ts +8 -2
- package/dist/contract/errors-factory.d.ts.map +1 -1
- package/dist/contract/errors.d.ts +9 -0
- package/dist/contract/errors.d.ts.map +1 -1
- package/dist/contract/fingerprint.d.ts +4 -1
- package/dist/contract/fingerprint.d.ts.map +1 -1
- package/dist/contract/operation-refusals.d.ts +51 -0
- package/dist/contract/operation-refusals.d.ts.map +1 -0
- package/dist/contract/tool-options.d.ts +4 -0
- package/dist/contract/tool-options.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +254 -196
- package/dist/entrypoints/agent-executor/claude-sdk.js +467 -294
- package/dist/entrypoints/agent-executor/claude.js +130 -99
- package/dist/entrypoints/agent-executor/codex.js +441 -314
- package/dist/entrypoints/agent-executor/testing/claude-sdk.d.ts +3 -0
- package/dist/entrypoints/agent-executor/testing/claude-sdk.d.ts.map +1 -0
- package/dist/entrypoints/agent-executor/testing/claude-sdk.js +329 -0
- package/dist/entrypoints/agent-executor/testing.d.ts +1 -2
- package/dist/entrypoints/agent-executor/testing.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/testing.js +413 -667
- package/dist/entrypoints/agent-executor.d.ts +1 -1
- package/dist/entrypoints/agent-executor.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor.js +12 -12
- package/dist/entrypoints/agent-runtime/browser.js +2 -2
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +8 -8
- package/dist/entrypoints/agent-runtime/postgres.js +5 -5
- package/dist/entrypoints/agent-runtime/realtime.js +2 -2
- package/dist/entrypoints/agent-runtime/sandbox.js +3 -3
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +6 -6
- package/dist/entrypoints/agent-runtime/sqlite/node.js +6 -6
- package/dist/entrypoints/agent-runtime/testing.js +5 -5
- package/dist/entrypoints/agent-runtime.js +26 -18
- package/dist/entrypoints/application/grammy.js +1 -1
- package/dist/entrypoints/application.js +2 -2
- package/dist/entrypoints/cli.js +8 -8
- package/dist/entrypoints/contract.d.ts +3 -2
- package/dist/entrypoints/contract.d.ts.map +1 -1
- package/dist/entrypoints/contract.js +6 -4
- package/dist/entrypoints/files/packaging.d.ts +4 -1
- package/dist/entrypoints/files/packaging.d.ts.map +1 -1
- package/dist/entrypoints/files/packaging.js +868 -167
- package/dist/entrypoints/files.js +1 -1
- package/dist/entrypoints/handler.js +7 -7
- package/dist/entrypoints/http.js +2 -2
- package/dist/entrypoints/index.js +10 -8
- package/dist/entrypoints/node.js +11 -11
- package/dist/entrypoints/observability.js +1 -1
- package/dist/entrypoints/process/bootstrap.d.ts +3 -0
- package/dist/entrypoints/process/bootstrap.d.ts.map +1 -0
- package/dist/entrypoints/process/bootstrap.js +16 -0
- package/dist/entrypoints/process.js +7 -7
- package/dist/entrypoints/realtime.js +3 -3
- package/dist/entrypoints/remote.js +8 -7
- package/dist/entrypoints/server.js +30 -14
- package/dist/entrypoints/service-host/macos.js +72 -206
- package/dist/entrypoints/service-host/work.d.ts +15 -0
- package/dist/entrypoints/service-host/work.d.ts.map +1 -0
- package/dist/entrypoints/service-host/work.js +676 -0
- package/dist/entrypoints/service-host.js +146 -536
- package/dist/entrypoints/telegram/screens.js +4 -4
- package/dist/entrypoints/telegram.js +4 -4
- package/dist/entrypoints/testing.d.ts +2 -1
- package/dist/entrypoints/testing.d.ts.map +1 -1
- package/dist/entrypoints/testing.js +27 -8
- package/dist/entrypoints/tools/agent.js +6 -6
- package/dist/entrypoints/tools/connections.js +2 -2
- package/dist/entrypoints/tools/invoker.js +5 -5
- package/dist/entrypoints/tools/mcp.js +8 -6
- package/dist/entrypoints/tools/toolkit.js +11 -9
- package/dist/entrypoints/tools.js +19 -17
- package/dist/entrypoints/tracking/contract.js +1 -1
- package/dist/entrypoints/tracking/performance.js +3 -3
- package/dist/files/client-artifact.d.ts +14 -42
- package/dist/files/client-artifact.d.ts.map +1 -1
- package/dist/files/client-build.d.ts +57 -0
- package/dist/files/client-build.d.ts.map +1 -0
- package/dist/files/client-declarations.d.ts +35 -0
- package/dist/files/client-declarations.d.ts.map +1 -0
- package/dist/files/client-package-contract.d.ts +162 -0
- package/dist/files/client-package-contract.d.ts.map +1 -0
- package/dist/files/client-package-proof.d.ts +38 -0
- package/dist/files/client-package-proof.d.ts.map +1 -0
- package/dist/files/client-package.d.ts +17 -0
- package/dist/files/client-package.d.ts.map +1 -0
- package/dist/files/declaration-specifiers.d.ts +30 -0
- package/dist/files/declaration-specifiers.d.ts.map +1 -0
- package/dist/{index-v759mzed.js → index-02r5sq9p.js} +36 -23
- package/dist/{index-0r15pkjq.js → index-0k1ba0ss.js} +1 -1
- package/dist/{index-znd1b57f.js → index-1dn2wjq6.js} +5 -4
- package/dist/{index-p06z7g7w.js → index-1p8q0yrt.js} +6 -5
- package/dist/{index-wa6h4tz6.js → index-1qwd54n3.js} +6 -5
- package/dist/index-2dzc7mv9.js +174 -0
- package/dist/index-2mz8hj58.js +155 -0
- package/dist/{index-17qgm6xe.js → index-34k82crg.js} +2 -2
- package/dist/index-3mcbr8sx.js +349 -0
- package/dist/{index-ybdq8kk2.js → index-3y2tzhr8.js} +3 -3
- package/dist/{index-fgahdc7s.js → index-5n3a8hd8.js} +5 -3
- package/dist/{index-jb4m241t.js → index-6918kxbf.js} +45 -1
- package/dist/{index-n3bm7zqq.js → index-6kmjcm81.js} +4 -4
- package/dist/{index-akf0xkrm.js → index-78da4g74.js} +1 -1
- package/dist/{index-9pv126eh.js → index-7fjbdga8.js} +7 -1
- package/dist/{index-zhshhxew.js → index-8jf4bt7v.js} +1 -1
- package/dist/{index-p16q492v.js → index-8t9dr41h.js} +18 -5
- package/dist/{index-xq4s9mka.js → index-8yt3rwe7.js} +1 -1
- package/dist/{index-39c2hj6h.js → index-9c76vfxf.js} +7 -3
- package/dist/index-9ft4n9j1.js +432 -0
- package/dist/{index-sd4e5x5j.js → index-9wdrwx3b.js} +8 -7
- package/dist/{index-z114ax5e.js → index-an7vcmwf.js} +49 -2
- package/dist/{index-pzhqydxb.js → index-d04w81fz.js} +1 -1
- package/dist/index-d2drhb9c.js +219 -0
- package/dist/{index-8gmmdz7k.js → index-dacxr7nf.js} +1 -1
- package/dist/{index-dnzxxf8a.js → index-dm6nxkn1.js} +1 -1
- package/dist/index-dxft2mnm.js +42 -0
- package/dist/{index-rxh3qy4x.js → index-fzd477xk.js} +1 -1
- package/dist/{index-xgae0bn7.js → index-g4gstmp1.js} +2 -2
- package/dist/{index-athc412x.js → index-g5fgeb6v.js} +1 -1
- package/dist/{index-z9d74jmb.js → index-gbhj370g.js} +3 -3
- package/dist/{index-3fym4j8n.js → index-gtaaxe9d.js} +1 -1
- package/dist/{index-v59pxmf1.js → index-jpecjm30.js} +2 -2
- package/dist/index-k9g061ma.js +164 -0
- package/dist/{index-669374qc.js → index-ma26mfnt.js} +84 -315
- package/dist/{index-ryxb427v.js → index-msxf2r8x.js} +16 -3
- package/dist/{index-rbd2rq3z.js → index-nr4fhfn4.js} +1 -1
- package/dist/{index-qa2jjb65.js → index-pbekeqzm.js} +1 -1
- package/dist/{index-mkfhpk11.js → index-pq6g1k9t.js} +2 -2
- package/dist/{index-gya4hwh3.js → index-pws5c3x6.js} +21 -1
- package/dist/{index-x2fb37t0.js → index-q427q23r.js} +3 -2
- package/dist/{index-jcrj0b8z.js → index-qggqqja2.js} +39 -2
- package/dist/{index-jxtg307y.js → index-rkjfzs0a.js} +1 -1
- package/dist/{index-5tdc0q43.js → index-rw8ze745.js} +5 -3
- package/dist/index-s43tr4my.js +129 -0
- package/dist/{index-f9p62ean.js → index-stpy56r3.js} +175 -249
- package/dist/index-t5g5rm9n.js +213 -0
- package/dist/{index-z20pdxeb.js → index-tmv3ez1h.js} +3 -3
- package/dist/{index-dcsxj68j.js → index-tqjamnax.js} +1 -1
- package/dist/{index-j15dhkda.js → index-wddcfbng.js} +1 -325
- package/dist/{index-9sfhje6y.js → index-wh70tmpd.js} +24 -234
- package/dist/index-wxjv4sqx.js +82 -0
- package/dist/{index-qhjmmsm2.js → index-x46y9z26.js} +2 -2
- package/dist/{index-nk0cy9g1.js → index-y53cqwke.js} +1 -1
- package/dist/{index-sv5svtq7.js → index-y68gavb5.js} +1 -1
- package/dist/{index-5y7j383h.js → index-yrhw10ef.js} +1 -1
- package/dist/process/bootstrap.d.ts +12 -0
- package/dist/process/bootstrap.d.ts.map +1 -0
- package/dist/process/owner-loss-guard.d.ts +2 -9
- package/dist/process/owner-loss-guard.d.ts.map +1 -1
- package/dist/process/work-root.d.ts +20 -0
- package/dist/process/work-root.d.ts.map +1 -0
- package/dist/server/contract-identity.d.ts.map +1 -1
- package/dist/server/contract-method.d.ts +12 -0
- package/dist/server/contract-method.d.ts.map +1 -1
- package/dist/server/implement.d.ts.map +1 -1
- package/dist/server/openapi.d.ts.map +1 -1
- package/dist/server/types.d.ts +10 -9
- package/dist/server/types.d.ts.map +1 -1
- package/dist/service-host/host-adapter.d.ts +2 -0
- package/dist/service-host/host-adapter.d.ts.map +1 -1
- package/dist/service-host/work/command.d.ts +72 -0
- package/dist/service-host/work/command.d.ts.map +1 -0
- package/dist/service-host/work/errors.d.ts +29 -0
- package/dist/service-host/work/errors.d.ts.map +1 -0
- package/dist/service-host/work/host.d.ts +38 -0
- package/dist/service-host/work/host.d.ts.map +1 -0
- package/dist/service-host/work/launch.d.ts +51 -0
- package/dist/service-host/work/launch.d.ts.map +1 -0
- package/dist/service-host/work/membership.d.ts +51 -0
- package/dist/service-host/work/membership.d.ts.map +1 -0
- package/dist/service-host/work/origin.d.ts +79 -0
- package/dist/service-host/work/origin.d.ts.map +1 -0
- package/dist/service-host/work/owner.d.ts +45 -0
- package/dist/service-host/work/owner.d.ts.map +1 -0
- package/dist/service-host/work/placement.d.ts +55 -0
- package/dist/service-host/work/placement.d.ts.map +1 -0
- package/dist/service-host/work/probe.d.ts +24 -0
- package/dist/service-host/work/probe.d.ts.map +1 -0
- package/dist/service-host/work/scope-command.d.ts +68 -0
- package/dist/service-host/work/scope-command.d.ts.map +1 -0
- package/dist/sync/session.d.ts +4 -1
- package/dist/sync/session.d.ts.map +1 -1
- package/dist/testing/surface-manifest-digest.d.ts +2 -0
- package/dist/testing/surface-manifest-digest.d.ts.map +1 -1
- package/dist/testing/surface-manifest.d.ts +32 -3
- package/dist/testing/surface-manifest.d.ts.map +1 -1
- package/dist/tools/agent.d.ts +2 -0
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/stream-surface.d.ts.map +1 -1
- package/dist/tools/internal/mcp-projection.d.ts +58 -0
- package/dist/tools/internal/mcp-projection.d.ts.map +1 -0
- package/dist/tools/internal/surface-projector.d.ts +3 -47
- package/dist/tools/internal/surface-projector.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +2 -0
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -0
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/handler.d.ts.map +1 -1
- package/dist/tools/mcp/lazy-discovery.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +4 -0
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/prepare.d.ts +5 -2
- package/dist/tools/mcp/prepare.d.ts.map +1 -1
- package/dist/tools/mount.d.ts +2 -0
- package/dist/tools/mount.d.ts.map +1 -1
- package/dist/tools/remote.d.ts.map +1 -1
- package/dist/tools/schema/nesting-limit.d.ts +8 -0
- package/dist/tools/schema/nesting-limit.d.ts.map +1 -0
- package/dist/tools/schema/presentation.d.ts +7 -0
- package/dist/tools/schema/presentation.d.ts.map +1 -1
- package/dist/tools/surface.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +3 -3
- package/llms/agent-executor-claude-sdk.txt +1 -1
- package/llms/agent-executor-claude.txt +1 -1
- package/llms/agent-executor-codex.txt +1 -1
- package/llms/agent-executor-testing-claude-sdk.txt +28 -0
- package/llms/agent-executor-testing.txt +7 -8
- package/llms/agent-executor.txt +27 -4
- package/llms/agent-runtime.txt +1 -1
- package/llms/contract.txt +8 -2
- package/llms/files-packaging.txt +11 -6
- package/llms/process-bootstrap.txt +18 -0
- package/llms/process.2.txt +215 -18
- package/llms/process.txt +130 -92
- package/llms/server.4.txt +49 -1
- package/llms/service-host-work.txt +34 -0
- package/llms/stitchkit.2.txt +31 -0
- package/llms/stitchkit.txt +78 -75
- package/llms/sync.txt +5 -2
- package/llms/testing.txt +1 -0
- package/llms/tools.2.txt +747 -775
- package/llms/tools.3.txt +846 -210
- package/llms/tools.4.txt +226 -0
- package/llms/tools.txt +3 -790
- package/llms/{upgrading-0.128.0-0.132.0.txt → upgrading-0.128.0-0.133.0.txt} +194 -6
- package/llms/upgrading.txt +1 -1
- package/llms-full.txt +746 -135
- package/llms.txt +18 -16
- package/package.json +12 -4
- package/dist/entrypoints/process/owner-loss.d.ts +0 -3
- package/dist/entrypoints/process/owner-loss.d.ts.map +0 -1
- package/dist/entrypoints/process/owner-loss.js +0 -7
- package/llms/process-owner-loss.txt +0 -18
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
import"../../index-09f7w2qq.js";
|
|
2
|
-
import"../../index-
|
|
3
|
-
import"../../index-
|
|
2
|
+
import"../../index-jpecjm30.js";
|
|
3
|
+
import"../../index-pbekeqzm.js";
|
|
4
4
|
import"../../index-6kec3b14.js";
|
|
5
5
|
import"../../index-2rf33y2h.js";
|
|
6
6
|
import {
|
|
7
|
-
ExecutorModelUsageSchema2
|
|
7
|
+
ExecutorModelUsageSchema2
|
|
8
|
+
} from "../../index-s43tr4my.js";
|
|
9
|
+
import {
|
|
8
10
|
PlanLimitsSchema2,
|
|
9
11
|
engineProfile,
|
|
10
12
|
engineEnvironment2,
|
|
11
13
|
nonEmptyString,
|
|
12
14
|
createTurnDeltaChannel,
|
|
13
|
-
offerTurnDelta,
|
|
14
15
|
sessionAbort,
|
|
16
|
+
sessionLiveness,
|
|
15
17
|
safeJsonValue,
|
|
16
|
-
|
|
18
|
+
reportObserverError,
|
|
19
|
+
invokeObserver,
|
|
17
20
|
emitStartupPhase
|
|
18
|
-
} from "../../index-
|
|
21
|
+
} from "../../index-stpy56r3.js";
|
|
19
22
|
import {
|
|
20
23
|
ClaudeTaskUsageSchema2,
|
|
21
24
|
ClaudeRuntimeEventSchema2,
|
|
22
25
|
claudeUserContent,
|
|
23
26
|
resolveClaudePermissionReply,
|
|
24
27
|
newClaudeTurnState,
|
|
25
|
-
classifyClaudeRecord,
|
|
26
28
|
claudeUsagePlanLimits2,
|
|
27
|
-
|
|
29
|
+
routeClaudeRecord,
|
|
28
30
|
claudeTranscriptPath2,
|
|
29
31
|
claudeTranscriptHasUuid2,
|
|
30
32
|
claudeTranscriptExists,
|
|
31
33
|
findTranscriptInput2
|
|
32
|
-
} from "../../index-
|
|
34
|
+
} from "../../index-an7vcmwf.js";
|
|
33
35
|
import {
|
|
34
36
|
JsonRpcRecordSchema2
|
|
35
37
|
} from "../../index-kwsr7j5k.js";
|
|
@@ -40,15 +42,17 @@ import {
|
|
|
40
42
|
import {
|
|
41
43
|
holdEngineRequest,
|
|
42
44
|
answerEngineRequest,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
} from "../../index-
|
|
45
|
+
loseEngineTurn,
|
|
46
|
+
interruptEngineTurn,
|
|
47
|
+
respondToEngineRequest
|
|
48
|
+
} from "../../index-qggqqja2.js";
|
|
49
|
+
import {
|
|
50
|
+
streamNativeCommand2
|
|
51
|
+
} from "../../index-gtaaxe9d.js";
|
|
47
52
|
import {
|
|
48
|
-
planLimitsReadFailed2
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
import"../../index-pzhqydxb.js";
|
|
53
|
+
planLimitsReadFailed2
|
|
54
|
+
} from "../../index-g5fgeb6v.js";
|
|
55
|
+
import"../../index-d04w81fz.js";
|
|
52
56
|
import {
|
|
53
57
|
isPositiveSafeInteger
|
|
54
58
|
} from "../../index-gr0kxymw.js";
|
|
@@ -98,15 +102,16 @@ function requireMethod(query, name) {
|
|
|
98
102
|
return fn;
|
|
99
103
|
}
|
|
100
104
|
function createClaudeSdkControls(host) {
|
|
105
|
+
const guarded = (promise) => raceAbort(promise, host.signal).catch((error) => {
|
|
106
|
+
host.ensureAlive();
|
|
107
|
+
throw error;
|
|
108
|
+
});
|
|
101
109
|
const activeQuery = async () => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (host.isClosed())
|
|
106
|
-
throw new Error("The Claude SDK session is closed");
|
|
110
|
+
host.ensureAlive();
|
|
111
|
+
const active = await guarded(host.ensureQuery());
|
|
112
|
+
host.ensureAlive();
|
|
107
113
|
return active.query;
|
|
108
114
|
};
|
|
109
|
-
const guarded = (promise) => raceAbort(promise, host.signal);
|
|
110
115
|
return {
|
|
111
116
|
async setModel(model) {
|
|
112
117
|
const query = await activeQuery();
|
|
@@ -158,13 +163,12 @@ function createClaudeSdkControls(host) {
|
|
|
158
163
|
try {
|
|
159
164
|
raw = await guarded(fn.call(query, opts));
|
|
160
165
|
} catch (error) {
|
|
161
|
-
if (!host.isClosed()
|
|
166
|
+
if (!host.isClosed()) {
|
|
162
167
|
host.recordPlanLimitsFailure(error);
|
|
163
168
|
}
|
|
164
169
|
throw error;
|
|
165
170
|
}
|
|
166
|
-
|
|
167
|
-
throw new Error("The Claude SDK session is closed");
|
|
171
|
+
host.ensureAlive();
|
|
168
172
|
return normalizeClaudeSdkUsageRead(raw, host.recordPlanLimits);
|
|
169
173
|
},
|
|
170
174
|
async mcpServerStatus() {
|
|
@@ -367,8 +371,8 @@ var stoppedPermission = (message) => () => ({
|
|
|
367
371
|
message,
|
|
368
372
|
interrupt: true
|
|
369
373
|
});
|
|
370
|
-
function closeQuerySafely(query) {
|
|
371
|
-
|
|
374
|
+
function closeQuerySafely(query, onObserverError) {
|
|
375
|
+
invokeObserver(onObserverError, "query.close", () => query?.close?.());
|
|
372
376
|
}
|
|
373
377
|
function pushablePrompt() {
|
|
374
378
|
const queue = [];
|
|
@@ -391,6 +395,8 @@ function pushablePrompt() {
|
|
|
391
395
|
return {
|
|
392
396
|
prompt: prompt(),
|
|
393
397
|
send(message) {
|
|
398
|
+
if (ended)
|
|
399
|
+
throw new Error("The Claude SDK query no longer reads input");
|
|
394
400
|
queue.push(message);
|
|
395
401
|
wake?.();
|
|
396
402
|
},
|
|
@@ -452,6 +458,11 @@ function createSdkCanUseTool(state) {
|
|
|
452
458
|
resolve: finish
|
|
453
459
|
});
|
|
454
460
|
if (turn.pending.has(interactionId)) {
|
|
461
|
+
if (state.isClosed()) {
|
|
462
|
+
turn.pending.delete(interactionId);
|
|
463
|
+
finish({ behavior: "deny", message: "The session was closed", interrupt: true });
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
455
466
|
options.signal.addEventListener("abort", onToolAbort, { once: true });
|
|
456
467
|
if (state.onPermissionRequest !== undefined) {
|
|
457
468
|
const meta = {
|
|
@@ -481,27 +492,24 @@ function createSdkCanUseTool(state) {
|
|
|
481
492
|
matchedAskRule: { ...options.matchedAskRule }
|
|
482
493
|
}
|
|
483
494
|
};
|
|
484
|
-
|
|
495
|
+
invokeObserver(state.onObserverError, "onPermissionRequest", () => state.onPermissionRequest?.(meta));
|
|
485
496
|
}
|
|
486
497
|
}
|
|
487
498
|
});
|
|
488
499
|
}
|
|
489
|
-
function sdkTurnHandle(turn, query) {
|
|
500
|
+
function sdkTurnHandle(turn, query, liveness) {
|
|
490
501
|
return {
|
|
491
502
|
deltas: turn.channel,
|
|
492
|
-
|
|
493
|
-
turn
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
},
|
|
503
|
+
interrupt: () => interruptEngineTurn(turn, liveness, {
|
|
504
|
+
refusal: stoppedPermission("The turn was interrupted"),
|
|
505
|
+
tell: () => query.interrupt()
|
|
506
|
+
}),
|
|
497
507
|
async respond(interactionId, rawReply) {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (decision.behavior === "allow") {
|
|
504
|
-
answerEngineRequest(turn, interactionId, {
|
|
508
|
+
respondToEngineRequest(turn, liveness, interactionId, (detail) => {
|
|
509
|
+
const decision = resolveClaudePermissionReply(detail, rawReply);
|
|
510
|
+
if (decision.behavior !== "allow")
|
|
511
|
+
return decision;
|
|
512
|
+
return {
|
|
505
513
|
behavior: "allow",
|
|
506
514
|
updatedInput: decision.input,
|
|
507
515
|
...decision.updatedPermissions !== undefined && {
|
|
@@ -512,10 +520,8 @@ function sdkTurnHandle(turn, query) {
|
|
|
512
520
|
destination: rule.destination
|
|
513
521
|
}))
|
|
514
522
|
}
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
answerEngineRequest(turn, interactionId, decision);
|
|
523
|
+
};
|
|
524
|
+
});
|
|
519
525
|
}
|
|
520
526
|
};
|
|
521
527
|
}
|
|
@@ -525,43 +531,46 @@ function runSdkQueryLoop(input) {
|
|
|
525
531
|
(async () => {
|
|
526
532
|
try {
|
|
527
533
|
for await (const record of input.handle.query) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
invokeSafely(() => input.onTurnUsage?.(summary));
|
|
534
|
+
if (input.isClosed())
|
|
535
|
+
break;
|
|
536
|
+
routeClaudeRecord(record, {
|
|
537
|
+
turn: input.getTurn(),
|
|
538
|
+
profileId: input.profileId,
|
|
539
|
+
limits: input.limits,
|
|
540
|
+
ended: stoppedPermission("The turn ended"),
|
|
541
|
+
clearTurn: input.clearTurn,
|
|
542
|
+
onSession(session) {
|
|
543
|
+
if (session.model !== undefined)
|
|
544
|
+
sessionModel = session.model;
|
|
545
|
+
},
|
|
546
|
+
onEvent(event) {
|
|
547
|
+
if (input.onEvent !== undefined)
|
|
548
|
+
invokeObserver(input.onObserverError, "onEvent", () => input.onEvent?.(event));
|
|
549
|
+
},
|
|
550
|
+
onEnd(turn, end) {
|
|
551
|
+
const usageDelta = end.deltas.find((delta) => delta.type === "usage");
|
|
552
|
+
const primaryModel = turn?.state.primaryModel ?? sessionModel;
|
|
553
|
+
const summary = turnUsageTracker.recordTurn({
|
|
554
|
+
turnId: turn?.state.turnId ?? "between-turns",
|
|
555
|
+
...primaryModel !== undefined && { primaryModel },
|
|
556
|
+
...usageDelta?.type === "usage" && { usageDelta }
|
|
557
|
+
});
|
|
558
|
+
if (turn !== undefined && input.onTurnUsage !== undefined) {
|
|
559
|
+
invokeObserver(input.onObserverError, "onTurnUsage", () => input.onTurnUsage?.(summary));
|
|
560
|
+
}
|
|
556
561
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
if (input.isClosed()) {
|
|
565
|
+
input.handle.close();
|
|
566
|
+
return;
|
|
562
567
|
}
|
|
563
568
|
throw new Error(input.getTurn() !== undefined ? "The Agent SDK query ended during the turn" : "The Agent SDK query ended while idle");
|
|
564
569
|
} catch (error) {
|
|
570
|
+
if (input.isClosed()) {
|
|
571
|
+
input.handle.close();
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
565
574
|
input.onExit(input.handle, error);
|
|
566
575
|
}
|
|
567
576
|
})();
|
|
@@ -677,14 +686,107 @@ async function probeClaudeSdkCapabilities(config, limits, input) {
|
|
|
677
686
|
deadlineSignal.removeEventListener("abort", onDeadlineAbort);
|
|
678
687
|
if (!probeAbort.signal.aborted)
|
|
679
688
|
probeAbort.abort();
|
|
680
|
-
closeQuerySafely(query);
|
|
689
|
+
closeQuerySafely(query, config.onObserverError);
|
|
681
690
|
}
|
|
682
691
|
});
|
|
683
692
|
}
|
|
684
693
|
|
|
694
|
+
// src/agent-executor/claude-sdk/engine-spawn.ts
|
|
695
|
+
import { EventEmitter } from "node:events";
|
|
696
|
+
import { Readable, Writable } from "node:stream";
|
|
697
|
+
var ENGINE_STDIN_BYTES = 256 * 1024 * 1024;
|
|
698
|
+
function spawnOwnedClaudeCode(options, hooks) {
|
|
699
|
+
const input = new TransformStream;
|
|
700
|
+
const env = {};
|
|
701
|
+
for (const [key, value] of Object.entries(options.env))
|
|
702
|
+
if (value !== undefined)
|
|
703
|
+
env[key] = value;
|
|
704
|
+
const command = streamNativeCommand2({
|
|
705
|
+
executable: options.command,
|
|
706
|
+
args: [...options.args],
|
|
707
|
+
cwd: options.cwd ?? process.cwd(),
|
|
708
|
+
env,
|
|
709
|
+
envPolicy: "declared-only",
|
|
710
|
+
ownerLoss: "terminate",
|
|
711
|
+
stdin: input.readable,
|
|
712
|
+
maxStdinBytes: ENGINE_STDIN_BYTES,
|
|
713
|
+
signal: options.signal,
|
|
714
|
+
onLeaderStarted: ({ pid }) => hooks.onLeader(pid)
|
|
715
|
+
});
|
|
716
|
+
(async () => {
|
|
717
|
+
const decoder = new TextDecoder;
|
|
718
|
+
try {
|
|
719
|
+
for await (const chunk of command.stderr) {
|
|
720
|
+
const text = decoder.decode(chunk, { stream: true });
|
|
721
|
+
if (text.length > 0)
|
|
722
|
+
invokeQuietly(hooks.onStderr, text);
|
|
723
|
+
}
|
|
724
|
+
} catch {}
|
|
725
|
+
})();
|
|
726
|
+
const events = new EventEmitter;
|
|
727
|
+
let exitCode = null;
|
|
728
|
+
let signalCode = null;
|
|
729
|
+
let killed = false;
|
|
730
|
+
const exited = command.result.then((result) => {
|
|
731
|
+
exitCode = result.exitCode;
|
|
732
|
+
signalCode = isSignal(result.signal) ? result.signal : null;
|
|
733
|
+
events.emit("exit", exitCode, signalCode);
|
|
734
|
+
}, (error) => {
|
|
735
|
+
if (events.listenerCount("error") > 0)
|
|
736
|
+
events.emit("error", error instanceof Error ? error : new Error(String(error)));
|
|
737
|
+
events.emit("exit", null, null);
|
|
738
|
+
});
|
|
739
|
+
const stdin = Writable.fromWeb(input.writable);
|
|
740
|
+
const stdout = Readable.from(command.stdout, { objectMode: false });
|
|
741
|
+
stdin.on("error", () => {
|
|
742
|
+
return;
|
|
743
|
+
});
|
|
744
|
+
stdout.on("error", () => {
|
|
745
|
+
return;
|
|
746
|
+
});
|
|
747
|
+
const spawned = {
|
|
748
|
+
stdin,
|
|
749
|
+
stdout,
|
|
750
|
+
get killed() {
|
|
751
|
+
return killed;
|
|
752
|
+
},
|
|
753
|
+
get exitCode() {
|
|
754
|
+
return exitCode;
|
|
755
|
+
},
|
|
756
|
+
get signalCode() {
|
|
757
|
+
return signalCode;
|
|
758
|
+
},
|
|
759
|
+
kill() {
|
|
760
|
+
if (!killed) {
|
|
761
|
+
killed = true;
|
|
762
|
+
command.stop().catch(() => {
|
|
763
|
+
return;
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
return true;
|
|
767
|
+
},
|
|
768
|
+
on: listen((event, listener) => events.on(event, listener)),
|
|
769
|
+
once: listen((event, listener) => events.once(event, listener)),
|
|
770
|
+
off: listen((event, listener) => events.off(event, listener))
|
|
771
|
+
};
|
|
772
|
+
return { process: spawned, exited };
|
|
773
|
+
}
|
|
774
|
+
function listen(register) {
|
|
775
|
+
function registered(event, listener) {
|
|
776
|
+
register(event, listener);
|
|
777
|
+
}
|
|
778
|
+
return registered;
|
|
779
|
+
}
|
|
780
|
+
function isSignal(value) {
|
|
781
|
+
return value?.startsWith("SIG") === true;
|
|
782
|
+
}
|
|
783
|
+
function invokeQuietly(callback, text) {
|
|
784
|
+
try {
|
|
785
|
+
callback?.(text);
|
|
786
|
+
} catch {}
|
|
787
|
+
}
|
|
788
|
+
|
|
685
789
|
// src/agent-executor/claude-sdk/query-options.ts
|
|
686
|
-
import { spawn } from "node:child_process";
|
|
687
|
-
import { StringDecoder } from "node:string_decoder";
|
|
688
790
|
var DEFAULT_DELEGATION_TIMEOUT_MS = 30000;
|
|
689
791
|
var FLAG_SETTINGS_REPLAY_TIMEOUT_MS = 30000;
|
|
690
792
|
function validateClaudeSdkConfig(config) {
|
|
@@ -696,6 +798,28 @@ function validateClaudeSdkConfig(config) {
|
|
|
696
798
|
assertTimerMs("verifyDelegation.timeoutMs", config.verifyDelegation.timeoutMs);
|
|
697
799
|
}
|
|
698
800
|
}
|
|
801
|
+
function validateClaudeSdkOpenInput(input) {
|
|
802
|
+
const hasNativeThreadId = typeof input.nativeThreadId === "string" && input.nativeThreadId.trim().length > 0;
|
|
803
|
+
if (input.resumeSessionAt !== undefined) {
|
|
804
|
+
if (typeof input.resumeSessionAt !== "string" || input.resumeSessionAt.trim().length === 0) {
|
|
805
|
+
throw new TypeError("Claude SDK open() requires a non-empty resumeSessionAt UUID when provided");
|
|
806
|
+
}
|
|
807
|
+
if (!hasNativeThreadId) {
|
|
808
|
+
throw new TypeError("Claude SDK open() requires nativeThreadId when resumeSessionAt is provided");
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
if (input.resumeDropsTurn !== undefined) {
|
|
812
|
+
if (typeof input.resumeDropsTurn !== "string" || input.resumeDropsTurn.trim().length === 0) {
|
|
813
|
+
throw new TypeError("Claude SDK open() requires a non-empty resumeDropsTurn prompt UUID when provided");
|
|
814
|
+
}
|
|
815
|
+
if (!hasNativeThreadId) {
|
|
816
|
+
throw new TypeError("Claude SDK open() requires nativeThreadId when resumeDropsTurn is provided");
|
|
817
|
+
}
|
|
818
|
+
if (input.resumeSessionAt === undefined) {
|
|
819
|
+
throw new TypeError("Claude SDK open() requires resumeSessionAt when resumeDropsTurn is provided");
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
699
823
|
function hasDelegationVerification(check) {
|
|
700
824
|
return check?.requireHooksApplied === true || check?.requireNoMcpServers === true;
|
|
701
825
|
}
|
|
@@ -705,45 +829,39 @@ function readPositivePid(spawned) {
|
|
|
705
829
|
const raw = Reflect.get(spawned, "pid");
|
|
706
830
|
return isPositiveSafeInteger(raw) ? raw : undefined;
|
|
707
831
|
}
|
|
708
|
-
function
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
});
|
|
730
|
-
child.stderr.on("data", (chunk) => {
|
|
731
|
-
emit(typeof chunk === "string" ? chunk : decoder.write(chunk));
|
|
832
|
+
function buildSpawnHook(config, recordPid, onPidExit, trackExit) {
|
|
833
|
+
const custom = config.spawnClaudeCodeProcess;
|
|
834
|
+
if (custom === undefined && config.onProviderPid === undefined)
|
|
835
|
+
return;
|
|
836
|
+
if (custom === undefined) {
|
|
837
|
+
return (spawnOpts) => {
|
|
838
|
+
let leader;
|
|
839
|
+
const owned = {};
|
|
840
|
+
const spawned = spawnOwnedClaudeCode(spawnOpts, {
|
|
841
|
+
onStderr: config.stderr,
|
|
842
|
+
onLeader: (pid) => {
|
|
843
|
+
leader = pid;
|
|
844
|
+
recordPid(pid);
|
|
845
|
+
try {
|
|
846
|
+
config.onProviderPid?.(pid);
|
|
847
|
+
} catch (error) {
|
|
848
|
+
reportObserverError(config.onObserverError, "onProviderPid", error);
|
|
849
|
+
recordPid(undefined);
|
|
850
|
+
owned.process?.kill("SIGTERM");
|
|
851
|
+
}
|
|
852
|
+
}
|
|
732
853
|
});
|
|
733
|
-
|
|
734
|
-
|
|
854
|
+
owned.process = spawned.process;
|
|
855
|
+
spawned.exited.then(() => {
|
|
856
|
+
if (leader !== undefined)
|
|
857
|
+
onPidExit(leader);
|
|
735
858
|
});
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
}
|
|
740
|
-
function buildSpawnHook(config, recordPid, onPidExit) {
|
|
741
|
-
if (config.spawnClaudeCodeProcess === undefined && config.onProviderPid === undefined) {
|
|
742
|
-
return;
|
|
859
|
+
trackExit(spawned.exited);
|
|
860
|
+
return spawned.process;
|
|
861
|
+
};
|
|
743
862
|
}
|
|
744
|
-
const baseSpawner = config.spawnClaudeCodeProcess ?? createDefaultSpawner(config.stderr);
|
|
745
863
|
return (spawnOpts) => {
|
|
746
|
-
const proc =
|
|
864
|
+
const proc = custom(spawnOpts);
|
|
747
865
|
const pid = readPositivePid(proc);
|
|
748
866
|
recordPid(pid);
|
|
749
867
|
if (pid !== undefined && typeof proc.once === "function") {
|
|
@@ -765,7 +883,7 @@ function buildSpawnHook(config, recordPid, onPidExit) {
|
|
|
765
883
|
}
|
|
766
884
|
function buildClaudeSdkQueryOptions(input) {
|
|
767
885
|
const { config } = input;
|
|
768
|
-
const spawnHook = buildSpawnHook(config, input.recordPid, input.onPidExit);
|
|
886
|
+
const spawnHook = buildSpawnHook(config, input.recordPid, input.onPidExit, input.trackExit);
|
|
769
887
|
return {
|
|
770
888
|
cwd: input.cwd,
|
|
771
889
|
env: input.env,
|
|
@@ -854,68 +972,12 @@ async function replayClaudeSdkFlagSettings(query, overlay, signal) {
|
|
|
854
972
|
|
|
855
973
|
// src/agent-executor/claude-sdk/session.ts
|
|
856
974
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
}
|
|
860
|
-
function createSdkStartTurn(input) {
|
|
861
|
-
return imageTurnStarter({
|
|
862
|
-
driverLabel: "The Agent SDK driver",
|
|
863
|
-
busyMessage: "A turn is already running in this Claude session",
|
|
864
|
-
imageOptions: input.config,
|
|
865
|
-
signal: input.signal,
|
|
866
|
-
check(turnInput) {
|
|
867
|
-
if (input.isClosed())
|
|
868
|
-
throw new Error("The Claude SDK session is closed");
|
|
869
|
-
if (input.getTurn() !== undefined || input.isStarting())
|
|
870
|
-
throw new Error("A turn is already running in this Claude session");
|
|
871
|
-
if (!isUuid(turnInput.clientId))
|
|
872
|
-
throw new TypeError("The Agent SDK driver needs a UUID client id");
|
|
873
|
-
},
|
|
874
|
-
async dispatch(turnInput, parts) {
|
|
875
|
-
const clientId = turnInput.clientId;
|
|
876
|
-
if (!isUuid(clientId))
|
|
877
|
-
throw new TypeError("The Agent SDK driver needs a UUID client id");
|
|
878
|
-
input.setStarting(true);
|
|
879
|
-
let active;
|
|
880
|
-
try {
|
|
881
|
-
active = await input.ensureQuery(false);
|
|
882
|
-
} finally {
|
|
883
|
-
input.setStarting(false);
|
|
884
|
-
}
|
|
885
|
-
if (input.isClosed())
|
|
886
|
-
throw new Error("The Claude SDK session is closed");
|
|
887
|
-
if (input.getTurn() !== undefined)
|
|
888
|
-
throw new Error("A turn is already running in this Claude session");
|
|
889
|
-
const turn = {
|
|
890
|
-
state: newClaudeTurnState(turnInput.turnId),
|
|
891
|
-
channel: createTurnDeltaChannel(),
|
|
892
|
-
pending: new Map
|
|
893
|
-
};
|
|
894
|
-
input.setTurn(turn);
|
|
895
|
-
try {
|
|
896
|
-
active.send({
|
|
897
|
-
type: "user",
|
|
898
|
-
message: { role: "user", content: claudeUserContent(parts) },
|
|
899
|
-
parent_tool_use_id: null,
|
|
900
|
-
uuid: clientId,
|
|
901
|
-
session_id: input.sessionId
|
|
902
|
-
});
|
|
903
|
-
input.markResumable();
|
|
904
|
-
active.startLoop();
|
|
905
|
-
return sdkTurnHandle(turn, active.query);
|
|
906
|
-
} catch (error) {
|
|
907
|
-
if (input.getTurn() === turn)
|
|
908
|
-
input.setTurn(undefined);
|
|
909
|
-
throw error;
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
});
|
|
913
|
-
}
|
|
975
|
+
|
|
976
|
+
// src/agent-executor/claude-sdk/query-manager.ts
|
|
914
977
|
async function launchSingleSdkQuery(input) {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
input.
|
|
918
|
-
emitStartupPhase(input.onStartupPhase, "spawning");
|
|
978
|
+
input.ensureAlive();
|
|
979
|
+
emitStartupPhase(input.onStartupPhase, "spawning", input.config.onObserverError);
|
|
980
|
+
input.ensureAlive();
|
|
919
981
|
const pushed = pushablePrompt();
|
|
920
982
|
let query;
|
|
921
983
|
try {
|
|
@@ -937,7 +999,8 @@ async function launchSingleSdkQuery(input) {
|
|
|
937
999
|
activeModel: input.activeModel,
|
|
938
1000
|
activePermissionMode: input.activePermissionMode,
|
|
939
1001
|
recordPid: input.recordPid,
|
|
940
|
-
onPidExit: input.onPidExit
|
|
1002
|
+
onPidExit: input.onPidExit,
|
|
1003
|
+
trackExit: input.trackExit
|
|
941
1004
|
})
|
|
942
1005
|
});
|
|
943
1006
|
} catch (error) {
|
|
@@ -952,7 +1015,7 @@ async function launchSingleSdkQuery(input) {
|
|
|
952
1015
|
return;
|
|
953
1016
|
closedOnce = true;
|
|
954
1017
|
pushed.end();
|
|
955
|
-
closeQuerySafely(query);
|
|
1018
|
+
closeQuerySafely(query, input.config.onObserverError);
|
|
956
1019
|
};
|
|
957
1020
|
const handle = {
|
|
958
1021
|
query,
|
|
@@ -965,12 +1028,16 @@ async function launchSingleSdkQuery(input) {
|
|
|
965
1028
|
handle,
|
|
966
1029
|
profileId: input.profileId,
|
|
967
1030
|
limits: input.limits,
|
|
1031
|
+
isClosed: input.isClosed,
|
|
968
1032
|
getTurn: input.getTurn,
|
|
969
1033
|
clearTurn: input.clearTurn,
|
|
970
1034
|
...input.config.onEvent !== undefined && { onEvent: input.config.onEvent },
|
|
971
1035
|
...input.config.onTurnUsage !== undefined && {
|
|
972
1036
|
onTurnUsage: input.config.onTurnUsage
|
|
973
1037
|
},
|
|
1038
|
+
...input.config.onObserverError !== undefined && {
|
|
1039
|
+
onObserverError: input.config.onObserverError
|
|
1040
|
+
},
|
|
974
1041
|
onExit: input.onExit
|
|
975
1042
|
});
|
|
976
1043
|
},
|
|
@@ -979,50 +1046,182 @@ async function launchSingleSdkQuery(input) {
|
|
|
979
1046
|
input.setInFlightClose(closeHandle);
|
|
980
1047
|
try {
|
|
981
1048
|
if (hasDelegationVerification(input.config.verifyDelegation)) {
|
|
982
|
-
emitStartupPhase(input.onStartupPhase, "verifying");
|
|
1049
|
+
emitStartupPhase(input.onStartupPhase, "verifying", input.config.onObserverError);
|
|
983
1050
|
await verifyClaudeSdkDelegation(query, input.config.verifyDelegation, input.signal);
|
|
984
1051
|
}
|
|
985
1052
|
if (input.flagSettingsOverlay !== undefined) {
|
|
986
1053
|
await replayClaudeSdkFlagSettings(query, input.flagSettingsOverlay, input.signal);
|
|
987
1054
|
}
|
|
988
|
-
|
|
989
|
-
throw input.isClosed() ? new Error("The Claude SDK session is closed") : abortReason(input.signal);
|
|
990
|
-
}
|
|
1055
|
+
input.ensureAlive();
|
|
991
1056
|
} catch (error) {
|
|
992
1057
|
input.setInFlightClose(undefined);
|
|
993
1058
|
input.recordPid(undefined);
|
|
994
1059
|
closeHandle();
|
|
995
1060
|
throw error;
|
|
996
1061
|
}
|
|
997
|
-
input.setInFlightClose(undefined);
|
|
998
1062
|
return handle;
|
|
999
1063
|
}
|
|
1000
|
-
function notifyQueryExit(callback, error, context) {
|
|
1064
|
+
function notifyQueryExit(callback, error, context, onObserverError) {
|
|
1001
1065
|
if (callback === undefined)
|
|
1002
1066
|
return;
|
|
1003
|
-
|
|
1067
|
+
invokeObserver(onObserverError, "onQueryExit", () => callback(error, context));
|
|
1004
1068
|
}
|
|
1005
|
-
function
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1069
|
+
function createSdkQueryManager(state) {
|
|
1070
|
+
let opening;
|
|
1071
|
+
const onExit = (exited, error) => {
|
|
1072
|
+
const ownsSession = state.getRunning() === exited;
|
|
1073
|
+
const shouldNotify = ownsSession && state.isOpened() && !state.isClosed();
|
|
1074
|
+
const turn = ownsSession ? state.getTurn() : undefined;
|
|
1075
|
+
const duringTurn = turn !== undefined;
|
|
1076
|
+
if (ownsSession) {
|
|
1077
|
+
state.setRunning(undefined);
|
|
1078
|
+
state.clearTurn();
|
|
1079
|
+
state.recordPid(undefined);
|
|
1010
1080
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1081
|
+
loseEngineTurn(turn, stoppedPermission("The Claude SDK query ended"), error);
|
|
1082
|
+
exited.close();
|
|
1083
|
+
if (shouldNotify) {
|
|
1084
|
+
notifyQueryExit(state.config.onQueryExit, error, { duringTurn, nativeThreadId: state.sessionId }, state.config.onObserverError);
|
|
1013
1085
|
}
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1086
|
+
};
|
|
1087
|
+
return async (startLoopImmediately) => {
|
|
1088
|
+
state.ensureAlive();
|
|
1089
|
+
const active = state.getRunning();
|
|
1090
|
+
if (active !== undefined) {
|
|
1091
|
+
if (startLoopImmediately)
|
|
1092
|
+
active.startLoop();
|
|
1093
|
+
return active;
|
|
1018
1094
|
}
|
|
1019
|
-
if (
|
|
1020
|
-
|
|
1095
|
+
if (opening === undefined) {
|
|
1096
|
+
const liveConfig = state.getLiveConfig();
|
|
1097
|
+
const promise = state.getResume().then((resumeState) => launchSingleSdkQuery({
|
|
1098
|
+
config: state.config,
|
|
1099
|
+
cwd: state.cwd,
|
|
1100
|
+
env: { ...state.env },
|
|
1101
|
+
profileId: state.profileId,
|
|
1102
|
+
limits: state.limits,
|
|
1103
|
+
sessionId: state.sessionId,
|
|
1104
|
+
resume: resumeState.resume,
|
|
1105
|
+
...resumeState.resumeSessionAt !== undefined && {
|
|
1106
|
+
resumeSessionAt: resumeState.resumeSessionAt
|
|
1107
|
+
},
|
|
1108
|
+
...resumeState.resumeDropsTurn !== undefined && {
|
|
1109
|
+
resumeDropsTurn: resumeState.resumeDropsTurn
|
|
1110
|
+
},
|
|
1111
|
+
activeModel: liveConfig.activeModel,
|
|
1112
|
+
activePermissionMode: liveConfig.activePermissionMode,
|
|
1113
|
+
flagSettingsOverlay: liveConfig.flagSettingsOverlay,
|
|
1114
|
+
signal: state.signal,
|
|
1115
|
+
canUseTool: state.canUseTool,
|
|
1116
|
+
isClosed: state.isClosed,
|
|
1117
|
+
ensureAlive: state.ensureAlive,
|
|
1118
|
+
getTurn: state.getTurn,
|
|
1119
|
+
clearTurn: state.clearTurn,
|
|
1120
|
+
setInFlightClose: state.setInFlightClose,
|
|
1121
|
+
recordPid: state.recordPid,
|
|
1122
|
+
onPidExit: state.onPidExit,
|
|
1123
|
+
trackExit: state.trackExit,
|
|
1124
|
+
...state.onStartupPhase !== undefined && {
|
|
1125
|
+
onStartupPhase: state.onStartupPhase
|
|
1126
|
+
},
|
|
1127
|
+
onExit
|
|
1128
|
+
})).then((handle) => {
|
|
1129
|
+
if (state.isClosed()) {
|
|
1130
|
+
if (state.getInFlightClose() === handle.close)
|
|
1131
|
+
state.setInFlightClose(undefined);
|
|
1132
|
+
state.recordPid(undefined);
|
|
1133
|
+
handle.close();
|
|
1134
|
+
state.ensureAlive();
|
|
1135
|
+
throw new Error("The Claude SDK session is closed");
|
|
1136
|
+
}
|
|
1137
|
+
state.setRunning(handle);
|
|
1138
|
+
if (state.getInFlightClose() === handle.close)
|
|
1139
|
+
state.setInFlightClose(undefined);
|
|
1140
|
+
return handle;
|
|
1141
|
+
}).finally(() => {
|
|
1142
|
+
if (opening === promise)
|
|
1143
|
+
opening = undefined;
|
|
1144
|
+
});
|
|
1145
|
+
opening = promise;
|
|
1021
1146
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1147
|
+
const handle = await opening;
|
|
1148
|
+
state.ensureAlive();
|
|
1149
|
+
if (startLoopImmediately)
|
|
1150
|
+
handle.startLoop();
|
|
1151
|
+
return handle;
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
// src/agent-executor/claude-sdk/session.ts
|
|
1156
|
+
var MAX_QUERY_RELAUNCHES = 3;
|
|
1157
|
+
function isUuid(value) {
|
|
1158
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
1159
|
+
}
|
|
1160
|
+
var ENGINE_EXIT_WAIT_MS = 1e4;
|
|
1161
|
+
async function waitForEngineExits(exits) {
|
|
1162
|
+
if (exits.size === 0)
|
|
1163
|
+
return;
|
|
1164
|
+
await raceAbort(Promise.all(exits), AbortSignal.timeout(ENGINE_EXIT_WAIT_MS)).catch(() => {
|
|
1165
|
+
throw new Error(`Claude Code did not exit within ${ENGINE_EXIT_WAIT_MS} ms of closing the SDK session`);
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
function createSdkStartTurn(input) {
|
|
1169
|
+
return imageTurnStarter({
|
|
1170
|
+
driverLabel: "The Agent SDK driver",
|
|
1171
|
+
busyMessage: "A turn is already running in this Claude session",
|
|
1172
|
+
imageOptions: input.config,
|
|
1173
|
+
signal: input.signal,
|
|
1174
|
+
check(turnInput) {
|
|
1175
|
+
input.liveness.ensureAlive();
|
|
1176
|
+
if (input.getTurn() !== undefined || input.isStarting())
|
|
1177
|
+
throw new Error("A turn is already running in this Claude session");
|
|
1178
|
+
if (!isUuid(turnInput.clientId))
|
|
1179
|
+
throw new TypeError("The Agent SDK driver needs a UUID client id");
|
|
1180
|
+
},
|
|
1181
|
+
async dispatch(turnInput, parts) {
|
|
1182
|
+
const clientId = turnInput.clientId;
|
|
1183
|
+
if (!isUuid(clientId))
|
|
1184
|
+
throw new TypeError("The Agent SDK driver needs a UUID client id");
|
|
1185
|
+
input.setStarting(true);
|
|
1186
|
+
let active;
|
|
1187
|
+
try {
|
|
1188
|
+
active = await input.ensureQuery(false);
|
|
1189
|
+
for (let attempt = 1;!input.isRunning(active); attempt += 1) {
|
|
1190
|
+
if (attempt > MAX_QUERY_RELAUNCHES)
|
|
1191
|
+
throw new Error("The Claude SDK query kept exiting before the turn could start");
|
|
1192
|
+
active = await input.ensureQuery(false);
|
|
1193
|
+
}
|
|
1194
|
+
} finally {
|
|
1195
|
+
input.setStarting(false);
|
|
1196
|
+
}
|
|
1197
|
+
input.liveness.ensureAlive();
|
|
1198
|
+
if (input.getTurn() !== undefined)
|
|
1199
|
+
throw new Error("A turn is already running in this Claude session");
|
|
1200
|
+
const turn = {
|
|
1201
|
+
state: newClaudeTurnState(turnInput.turnId),
|
|
1202
|
+
channel: createTurnDeltaChannel(),
|
|
1203
|
+
pending: new Map,
|
|
1204
|
+
settled: false
|
|
1205
|
+
};
|
|
1206
|
+
input.setTurn(turn);
|
|
1207
|
+
try {
|
|
1208
|
+
active.send({
|
|
1209
|
+
type: "user",
|
|
1210
|
+
message: { role: "user", content: claudeUserContent(parts) },
|
|
1211
|
+
parent_tool_use_id: null,
|
|
1212
|
+
uuid: clientId,
|
|
1213
|
+
session_id: input.sessionId
|
|
1214
|
+
});
|
|
1215
|
+
input.markResumable();
|
|
1216
|
+
active.startLoop();
|
|
1217
|
+
return sdkTurnHandle(turn, active.query, input.liveness);
|
|
1218
|
+
} catch (error) {
|
|
1219
|
+
if (input.getTurn() === turn)
|
|
1220
|
+
input.setTurn(undefined);
|
|
1221
|
+
throw error;
|
|
1222
|
+
}
|
|
1024
1223
|
}
|
|
1025
|
-
}
|
|
1224
|
+
});
|
|
1026
1225
|
}
|
|
1027
1226
|
function recordSdkPlanLimitsFailure(limits, profileId, error) {
|
|
1028
1227
|
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -1041,25 +1240,30 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1041
1240
|
const env = engineEnvironment2(profile, ambient);
|
|
1042
1241
|
const sessionId = input.nativeThreadId ?? randomUUID2();
|
|
1043
1242
|
const transcript = claudeTranscriptPath2({ home: profile.home, cwd: input.cwd, sessionId });
|
|
1044
|
-
const transcriptExists = input.nativeThreadId !== undefined && await claudeTranscriptExists(transcript);
|
|
1045
|
-
let resume = transcriptExists || input.resumeSessionAt !== undefined;
|
|
1046
1243
|
let pendingResumeSessionAt = input.resumeSessionAt;
|
|
1047
1244
|
let pendingResumeDropsTurn = input.resumeDropsTurn;
|
|
1048
1245
|
let current;
|
|
1049
1246
|
let startingTurn = false;
|
|
1050
1247
|
let opened = false;
|
|
1051
|
-
let closed = false;
|
|
1052
1248
|
let providerPid;
|
|
1053
1249
|
let activeModel = config.model;
|
|
1054
1250
|
let activePermissionMode = config.permissionMode ?? "default";
|
|
1055
1251
|
let flagSettingsOverlay;
|
|
1056
1252
|
let running;
|
|
1057
|
-
|
|
1253
|
+
const engineExits = new Set;
|
|
1058
1254
|
let inFlightClose;
|
|
1255
|
+
const linked = sessionAbort(input.signal);
|
|
1256
|
+
const liveness = sessionLiveness({
|
|
1257
|
+
closedMessage: "The Claude SDK session is closed",
|
|
1258
|
+
caller: input.signal,
|
|
1259
|
+
linked: linked.signal
|
|
1260
|
+
});
|
|
1261
|
+
const isClosed = () => !liveness.isAlive();
|
|
1262
|
+
const ensureSessionAlive = () => liveness.ensureAlive();
|
|
1059
1263
|
const shutdown = (reason) => {
|
|
1060
|
-
if (
|
|
1264
|
+
if (liveness.lost !== undefined)
|
|
1061
1265
|
return;
|
|
1062
|
-
|
|
1266
|
+
liveness.markLost(reason);
|
|
1063
1267
|
providerPid = undefined;
|
|
1064
1268
|
const turn = current;
|
|
1065
1269
|
current = undefined;
|
|
@@ -1071,94 +1275,60 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1071
1275
|
running = undefined;
|
|
1072
1276
|
active?.close();
|
|
1073
1277
|
};
|
|
1074
|
-
const linked = sessionAbort(input.signal);
|
|
1075
1278
|
linked.signal.addEventListener("abort", () => shutdown(abortReason(linked.signal)), {
|
|
1076
1279
|
once: true
|
|
1077
1280
|
});
|
|
1078
1281
|
const canUseTool = createSdkCanUseTool({
|
|
1079
1282
|
getTurn: () => current,
|
|
1080
|
-
isClosed
|
|
1283
|
+
isClosed,
|
|
1081
1284
|
...config.onPermissionRequest !== undefined && {
|
|
1082
1285
|
onPermissionRequest: config.onPermissionRequest
|
|
1083
|
-
}
|
|
1286
|
+
},
|
|
1287
|
+
...config.onObserverError !== undefined && { onObserverError: config.onObserverError }
|
|
1084
1288
|
});
|
|
1085
|
-
const ensureQuery =
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
providerPid = undefined;
|
|
1127
|
-
},
|
|
1128
|
-
...input.onStartupPhase !== undefined && { onStartupPhase: input.onStartupPhase },
|
|
1129
|
-
onExit: (exited, error) => {
|
|
1130
|
-
const ownsSession = running === exited;
|
|
1131
|
-
const shouldNotify = ownsSession && opened && !closed && !linked.signal.aborted;
|
|
1132
|
-
const turn = ownsSession ? current : undefined;
|
|
1133
|
-
const duringTurn = turn !== undefined;
|
|
1134
|
-
if (ownsSession) {
|
|
1135
|
-
running = undefined;
|
|
1136
|
-
current = undefined;
|
|
1137
|
-
providerPid = undefined;
|
|
1138
|
-
}
|
|
1139
|
-
loseEngineTurn(turn, stoppedPermission("The Claude SDK query ended"), error);
|
|
1140
|
-
exited.close();
|
|
1141
|
-
if (shouldNotify) {
|
|
1142
|
-
notifyQueryExit(config.onQueryExit, error, {
|
|
1143
|
-
duringTurn,
|
|
1144
|
-
nativeThreadId: sessionId
|
|
1145
|
-
});
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}).then((handle) => {
|
|
1149
|
-
running = handle;
|
|
1150
|
-
return handle;
|
|
1151
|
-
}).finally(() => {
|
|
1152
|
-
if (opening === promise)
|
|
1153
|
-
opening = undefined;
|
|
1154
|
-
});
|
|
1155
|
-
opening = promise;
|
|
1289
|
+
const ensureQuery = createSdkQueryManager({
|
|
1290
|
+
config,
|
|
1291
|
+
cwd: input.cwd,
|
|
1292
|
+
env,
|
|
1293
|
+
profileId: profile.profileId,
|
|
1294
|
+
limits,
|
|
1295
|
+
sessionId,
|
|
1296
|
+
signal: linked.signal,
|
|
1297
|
+
canUseTool,
|
|
1298
|
+
...input.onStartupPhase !== undefined && { onStartupPhase: input.onStartupPhase },
|
|
1299
|
+
isOpened: () => opened,
|
|
1300
|
+
isClosed,
|
|
1301
|
+
ensureAlive: ensureSessionAlive,
|
|
1302
|
+
getResume: async () => ({
|
|
1303
|
+
resume: pendingResumeSessionAt !== undefined || await claudeTranscriptExists(transcript),
|
|
1304
|
+
...pendingResumeSessionAt !== undefined && { resumeSessionAt: pendingResumeSessionAt },
|
|
1305
|
+
...pendingResumeDropsTurn !== undefined && { resumeDropsTurn: pendingResumeDropsTurn }
|
|
1306
|
+
}),
|
|
1307
|
+
getLiveConfig: () => ({ activeModel, activePermissionMode, flagSettingsOverlay }),
|
|
1308
|
+
getTurn: () => current,
|
|
1309
|
+
clearTurn: () => {
|
|
1310
|
+
current = undefined;
|
|
1311
|
+
},
|
|
1312
|
+
getRunning: () => running,
|
|
1313
|
+
setRunning: (handle) => {
|
|
1314
|
+
running = handle;
|
|
1315
|
+
},
|
|
1316
|
+
getInFlightClose: () => inFlightClose,
|
|
1317
|
+
setInFlightClose: (fn) => {
|
|
1318
|
+
inFlightClose = fn;
|
|
1319
|
+
},
|
|
1320
|
+
recordPid: (pid) => {
|
|
1321
|
+
providerPid = pid;
|
|
1322
|
+
},
|
|
1323
|
+
onPidExit: (exitedPid) => {
|
|
1324
|
+
if (providerPid === exitedPid)
|
|
1325
|
+
providerPid = undefined;
|
|
1326
|
+
},
|
|
1327
|
+
trackExit: (exited) => {
|
|
1328
|
+
engineExits.add(exited);
|
|
1329
|
+
exited.then(() => engineExits.delete(exited));
|
|
1156
1330
|
}
|
|
1157
|
-
|
|
1158
|
-
if (startLoopImmediately)
|
|
1159
|
-
handle.startLoop();
|
|
1160
|
-
return handle;
|
|
1161
|
-
};
|
|
1331
|
+
});
|
|
1162
1332
|
if (hasDelegationVerification(config.verifyDelegation)) {
|
|
1163
1333
|
try {
|
|
1164
1334
|
await ensureQuery(true);
|
|
@@ -1173,7 +1343,7 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1173
1343
|
config,
|
|
1174
1344
|
sessionId,
|
|
1175
1345
|
signal: linked.signal,
|
|
1176
|
-
|
|
1346
|
+
liveness,
|
|
1177
1347
|
getTurn: () => current,
|
|
1178
1348
|
setTurn: (turn) => {
|
|
1179
1349
|
current = turn;
|
|
@@ -1183,15 +1353,16 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1183
1353
|
startingTurn = value;
|
|
1184
1354
|
},
|
|
1185
1355
|
markResumable: () => {
|
|
1186
|
-
resume = true;
|
|
1187
1356
|
pendingResumeSessionAt = undefined;
|
|
1188
1357
|
pendingResumeDropsTurn = undefined;
|
|
1189
1358
|
},
|
|
1190
|
-
ensureQuery
|
|
1359
|
+
ensureQuery,
|
|
1360
|
+
isRunning: (handle) => running === handle
|
|
1191
1361
|
});
|
|
1192
1362
|
const controls = createClaudeSdkControls({
|
|
1193
1363
|
signal: linked.signal,
|
|
1194
|
-
isClosed
|
|
1364
|
+
isClosed,
|
|
1365
|
+
ensureAlive: ensureSessionAlive,
|
|
1195
1366
|
ensureQuery: () => ensureQuery(true),
|
|
1196
1367
|
setActiveModel: (model) => {
|
|
1197
1368
|
activeModel = model;
|
|
@@ -1216,9 +1387,11 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1216
1387
|
startTurn,
|
|
1217
1388
|
...controls,
|
|
1218
1389
|
async close() {
|
|
1219
|
-
|
|
1390
|
+
liveness.markClosing();
|
|
1391
|
+
shutdown(new Error("The Claude SDK session is closed"));
|
|
1220
1392
|
linked.abort();
|
|
1221
1393
|
linked.release();
|
|
1394
|
+
await waitForEngineExits(engineExits);
|
|
1222
1395
|
}
|
|
1223
1396
|
};
|
|
1224
1397
|
}
|