stitchkit 0.132.3 → 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 +172 -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/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 +8 -11
- package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/query-manager.d.ts +4 -2
- package/dist/agent-executor/claude-sdk/query-manager.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/query-options.d.ts +1 -0
- 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 +23 -3
- 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 +6 -8
- 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/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 +253 -210
- package/dist/entrypoints/agent-executor/claude-sdk.js +248 -173
- package/dist/entrypoints/agent-executor/claude.js +57 -109
- package/dist/entrypoints/agent-executor/codex.js +412 -335
- 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";
|
|
@@ -159,7 +163,7 @@ function createClaudeSdkControls(host) {
|
|
|
159
163
|
try {
|
|
160
164
|
raw = await guarded(fn.call(query, opts));
|
|
161
165
|
} catch (error) {
|
|
162
|
-
if (!host.isClosed()
|
|
166
|
+
if (!host.isClosed()) {
|
|
163
167
|
host.recordPlanLimitsFailure(error);
|
|
164
168
|
}
|
|
165
169
|
throw error;
|
|
@@ -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
|
},
|
|
@@ -486,38 +492,24 @@ function createSdkCanUseTool(state) {
|
|
|
486
492
|
matchedAskRule: { ...options.matchedAskRule }
|
|
487
493
|
}
|
|
488
494
|
};
|
|
489
|
-
|
|
495
|
+
invokeObserver(state.onObserverError, "onPermissionRequest", () => state.onPermissionRequest?.(meta));
|
|
490
496
|
}
|
|
491
497
|
}
|
|
492
498
|
});
|
|
493
499
|
}
|
|
494
|
-
function sdkTurnHandle(turn, query,
|
|
500
|
+
function sdkTurnHandle(turn, query, liveness) {
|
|
495
501
|
return {
|
|
496
502
|
deltas: turn.channel,
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
ensureAlive();
|
|
502
|
-
} catch {
|
|
503
|
-
return;
|
|
504
|
-
}
|
|
505
|
-
turn.state.interruptRequested = true;
|
|
506
|
-
drainEngineRequests(turn, stoppedPermission("The turn was interrupted"));
|
|
507
|
-
await query.interrupt();
|
|
508
|
-
},
|
|
503
|
+
interrupt: () => interruptEngineTurn(turn, liveness, {
|
|
504
|
+
refusal: stoppedPermission("The turn was interrupted"),
|
|
505
|
+
tell: () => query.interrupt()
|
|
506
|
+
}),
|
|
509
507
|
async respond(interactionId, rawReply) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
if (waiting === undefined) {
|
|
516
|
-
throw new TypeError(`Unknown interaction ${interactionId} for this turn`);
|
|
517
|
-
}
|
|
518
|
-
const decision = resolveClaudePermissionReply(waiting.detail, rawReply);
|
|
519
|
-
if (decision.behavior === "allow") {
|
|
520
|
-
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 {
|
|
521
513
|
behavior: "allow",
|
|
522
514
|
updatedInput: decision.input,
|
|
523
515
|
...decision.updatedPermissions !== undefined && {
|
|
@@ -528,10 +520,8 @@ function sdkTurnHandle(turn, query, ensureAlive) {
|
|
|
528
520
|
destination: rule.destination
|
|
529
521
|
}))
|
|
530
522
|
}
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
}
|
|
534
|
-
answerEngineRequest(turn, interactionId, decision);
|
|
523
|
+
};
|
|
524
|
+
});
|
|
535
525
|
}
|
|
536
526
|
};
|
|
537
527
|
}
|
|
@@ -543,42 +533,33 @@ function runSdkQueryLoop(input) {
|
|
|
543
533
|
for await (const record of input.handle.query) {
|
|
544
534
|
if (input.isClosed())
|
|
545
535
|
break;
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
});
|
|
572
|
-
if (turn !== undefined && input.onTurnUsage !== undefined) {
|
|
573
|
-
invokeSafely(() => input.onTurnUsage?.(summary));
|
|
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
|
+
}
|
|
574
561
|
}
|
|
575
|
-
|
|
576
|
-
turn.settled = true;
|
|
577
|
-
endEngineTurn(turn, stoppedPermission("The turn ended"), verdict.deltas);
|
|
578
|
-
input.clearTurn();
|
|
579
|
-
} else if (verdict.kind === "unhandled") {
|
|
580
|
-
offerTurnDelta(turn?.channel, verdict.delta);
|
|
581
|
-
}
|
|
562
|
+
});
|
|
582
563
|
}
|
|
583
564
|
if (input.isClosed()) {
|
|
584
565
|
input.handle.close();
|
|
@@ -705,14 +686,107 @@ async function probeClaudeSdkCapabilities(config, limits, input) {
|
|
|
705
686
|
deadlineSignal.removeEventListener("abort", onDeadlineAbort);
|
|
706
687
|
if (!probeAbort.signal.aborted)
|
|
707
688
|
probeAbort.abort();
|
|
708
|
-
closeQuerySafely(query);
|
|
689
|
+
closeQuerySafely(query, config.onObserverError);
|
|
709
690
|
}
|
|
710
691
|
});
|
|
711
692
|
}
|
|
712
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
|
+
|
|
713
789
|
// src/agent-executor/claude-sdk/query-options.ts
|
|
714
|
-
import { spawn } from "node:child_process";
|
|
715
|
-
import { StringDecoder } from "node:string_decoder";
|
|
716
790
|
var DEFAULT_DELEGATION_TIMEOUT_MS = 30000;
|
|
717
791
|
var FLAG_SETTINGS_REPLAY_TIMEOUT_MS = 30000;
|
|
718
792
|
function validateClaudeSdkConfig(config) {
|
|
@@ -755,45 +829,39 @@ function readPositivePid(spawned) {
|
|
|
755
829
|
const raw = Reflect.get(spawned, "pid");
|
|
756
830
|
return isPositiveSafeInteger(raw) ? raw : undefined;
|
|
757
831
|
}
|
|
758
|
-
function
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
});
|
|
780
|
-
child.stderr.on("data", (chunk) => {
|
|
781
|
-
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
|
+
}
|
|
782
853
|
});
|
|
783
|
-
|
|
784
|
-
|
|
854
|
+
owned.process = spawned.process;
|
|
855
|
+
spawned.exited.then(() => {
|
|
856
|
+
if (leader !== undefined)
|
|
857
|
+
onPidExit(leader);
|
|
785
858
|
});
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
790
|
-
function buildSpawnHook(config, recordPid, onPidExit) {
|
|
791
|
-
if (config.spawnClaudeCodeProcess === undefined && config.onProviderPid === undefined) {
|
|
792
|
-
return;
|
|
859
|
+
trackExit(spawned.exited);
|
|
860
|
+
return spawned.process;
|
|
861
|
+
};
|
|
793
862
|
}
|
|
794
|
-
const baseSpawner = config.spawnClaudeCodeProcess ?? createDefaultSpawner(config.stderr);
|
|
795
863
|
return (spawnOpts) => {
|
|
796
|
-
const proc =
|
|
864
|
+
const proc = custom(spawnOpts);
|
|
797
865
|
const pid = readPositivePid(proc);
|
|
798
866
|
recordPid(pid);
|
|
799
867
|
if (pid !== undefined && typeof proc.once === "function") {
|
|
@@ -815,7 +883,7 @@ function buildSpawnHook(config, recordPid, onPidExit) {
|
|
|
815
883
|
}
|
|
816
884
|
function buildClaudeSdkQueryOptions(input) {
|
|
817
885
|
const { config } = input;
|
|
818
|
-
const spawnHook = buildSpawnHook(config, input.recordPid, input.onPidExit);
|
|
886
|
+
const spawnHook = buildSpawnHook(config, input.recordPid, input.onPidExit, input.trackExit);
|
|
819
887
|
return {
|
|
820
888
|
cwd: input.cwd,
|
|
821
889
|
env: input.env,
|
|
@@ -908,7 +976,7 @@ import { randomUUID as randomUUID2 } from "node:crypto";
|
|
|
908
976
|
// src/agent-executor/claude-sdk/query-manager.ts
|
|
909
977
|
async function launchSingleSdkQuery(input) {
|
|
910
978
|
input.ensureAlive();
|
|
911
|
-
emitStartupPhase(input.onStartupPhase, "spawning");
|
|
979
|
+
emitStartupPhase(input.onStartupPhase, "spawning", input.config.onObserverError);
|
|
912
980
|
input.ensureAlive();
|
|
913
981
|
const pushed = pushablePrompt();
|
|
914
982
|
let query;
|
|
@@ -931,7 +999,8 @@ async function launchSingleSdkQuery(input) {
|
|
|
931
999
|
activeModel: input.activeModel,
|
|
932
1000
|
activePermissionMode: input.activePermissionMode,
|
|
933
1001
|
recordPid: input.recordPid,
|
|
934
|
-
onPidExit: input.onPidExit
|
|
1002
|
+
onPidExit: input.onPidExit,
|
|
1003
|
+
trackExit: input.trackExit
|
|
935
1004
|
})
|
|
936
1005
|
});
|
|
937
1006
|
} catch (error) {
|
|
@@ -946,7 +1015,7 @@ async function launchSingleSdkQuery(input) {
|
|
|
946
1015
|
return;
|
|
947
1016
|
closedOnce = true;
|
|
948
1017
|
pushed.end();
|
|
949
|
-
closeQuerySafely(query);
|
|
1018
|
+
closeQuerySafely(query, input.config.onObserverError);
|
|
950
1019
|
};
|
|
951
1020
|
const handle = {
|
|
952
1021
|
query,
|
|
@@ -966,6 +1035,9 @@ async function launchSingleSdkQuery(input) {
|
|
|
966
1035
|
...input.config.onTurnUsage !== undefined && {
|
|
967
1036
|
onTurnUsage: input.config.onTurnUsage
|
|
968
1037
|
},
|
|
1038
|
+
...input.config.onObserverError !== undefined && {
|
|
1039
|
+
onObserverError: input.config.onObserverError
|
|
1040
|
+
},
|
|
969
1041
|
onExit: input.onExit
|
|
970
1042
|
});
|
|
971
1043
|
},
|
|
@@ -974,7 +1046,7 @@ async function launchSingleSdkQuery(input) {
|
|
|
974
1046
|
input.setInFlightClose(closeHandle);
|
|
975
1047
|
try {
|
|
976
1048
|
if (hasDelegationVerification(input.config.verifyDelegation)) {
|
|
977
|
-
emitStartupPhase(input.onStartupPhase, "verifying");
|
|
1049
|
+
emitStartupPhase(input.onStartupPhase, "verifying", input.config.onObserverError);
|
|
978
1050
|
await verifyClaudeSdkDelegation(query, input.config.verifyDelegation, input.signal);
|
|
979
1051
|
}
|
|
980
1052
|
if (input.flagSettingsOverlay !== undefined) {
|
|
@@ -989,10 +1061,10 @@ async function launchSingleSdkQuery(input) {
|
|
|
989
1061
|
}
|
|
990
1062
|
return handle;
|
|
991
1063
|
}
|
|
992
|
-
function notifyQueryExit(callback, error, context) {
|
|
1064
|
+
function notifyQueryExit(callback, error, context, onObserverError) {
|
|
993
1065
|
if (callback === undefined)
|
|
994
1066
|
return;
|
|
995
|
-
|
|
1067
|
+
invokeObserver(onObserverError, "onQueryExit", () => callback(error, context));
|
|
996
1068
|
}
|
|
997
1069
|
function createSdkQueryManager(state) {
|
|
998
1070
|
let opening;
|
|
@@ -1006,17 +1078,10 @@ function createSdkQueryManager(state) {
|
|
|
1006
1078
|
state.clearTurn();
|
|
1007
1079
|
state.recordPid(undefined);
|
|
1008
1080
|
}
|
|
1009
|
-
if (turn !== undefined) {
|
|
1010
|
-
turn.settled = true;
|
|
1011
|
-
turn.lost = { error };
|
|
1012
|
-
}
|
|
1013
1081
|
loseEngineTurn(turn, stoppedPermission("The Claude SDK query ended"), error);
|
|
1014
1082
|
exited.close();
|
|
1015
1083
|
if (shouldNotify) {
|
|
1016
|
-
notifyQueryExit(state.config.onQueryExit, error, {
|
|
1017
|
-
duringTurn,
|
|
1018
|
-
nativeThreadId: state.sessionId
|
|
1019
|
-
});
|
|
1084
|
+
notifyQueryExit(state.config.onQueryExit, error, { duringTurn, nativeThreadId: state.sessionId }, state.config.onObserverError);
|
|
1020
1085
|
}
|
|
1021
1086
|
};
|
|
1022
1087
|
return async (startLoopImmediately) => {
|
|
@@ -1028,9 +1093,8 @@ function createSdkQueryManager(state) {
|
|
|
1028
1093
|
return active;
|
|
1029
1094
|
}
|
|
1030
1095
|
if (opening === undefined) {
|
|
1031
|
-
const resumeState = state.getResume();
|
|
1032
1096
|
const liveConfig = state.getLiveConfig();
|
|
1033
|
-
const promise = launchSingleSdkQuery({
|
|
1097
|
+
const promise = state.getResume().then((resumeState) => launchSingleSdkQuery({
|
|
1034
1098
|
config: state.config,
|
|
1035
1099
|
cwd: state.cwd,
|
|
1036
1100
|
env: { ...state.env },
|
|
@@ -1056,9 +1120,12 @@ function createSdkQueryManager(state) {
|
|
|
1056
1120
|
setInFlightClose: state.setInFlightClose,
|
|
1057
1121
|
recordPid: state.recordPid,
|
|
1058
1122
|
onPidExit: state.onPidExit,
|
|
1059
|
-
|
|
1123
|
+
trackExit: state.trackExit,
|
|
1124
|
+
...state.onStartupPhase !== undefined && {
|
|
1125
|
+
onStartupPhase: state.onStartupPhase
|
|
1126
|
+
},
|
|
1060
1127
|
onExit
|
|
1061
|
-
}).then((handle) => {
|
|
1128
|
+
})).then((handle) => {
|
|
1062
1129
|
if (state.isClosed()) {
|
|
1063
1130
|
if (state.getInFlightClose() === handle.close)
|
|
1064
1131
|
state.setInFlightClose(undefined);
|
|
@@ -1086,9 +1153,18 @@ function createSdkQueryManager(state) {
|
|
|
1086
1153
|
}
|
|
1087
1154
|
|
|
1088
1155
|
// src/agent-executor/claude-sdk/session.ts
|
|
1156
|
+
var MAX_QUERY_RELAUNCHES = 3;
|
|
1089
1157
|
function isUuid(value) {
|
|
1090
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);
|
|
1091
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
|
+
}
|
|
1092
1168
|
function createSdkStartTurn(input) {
|
|
1093
1169
|
return imageTurnStarter({
|
|
1094
1170
|
driverLabel: "The Agent SDK driver",
|
|
@@ -1096,7 +1172,7 @@ function createSdkStartTurn(input) {
|
|
|
1096
1172
|
imageOptions: input.config,
|
|
1097
1173
|
signal: input.signal,
|
|
1098
1174
|
check(turnInput) {
|
|
1099
|
-
input.ensureAlive();
|
|
1175
|
+
input.liveness.ensureAlive();
|
|
1100
1176
|
if (input.getTurn() !== undefined || input.isStarting())
|
|
1101
1177
|
throw new Error("A turn is already running in this Claude session");
|
|
1102
1178
|
if (!isUuid(turnInput.clientId))
|
|
@@ -1110,10 +1186,15 @@ function createSdkStartTurn(input) {
|
|
|
1110
1186
|
let active;
|
|
1111
1187
|
try {
|
|
1112
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
|
+
}
|
|
1113
1194
|
} finally {
|
|
1114
1195
|
input.setStarting(false);
|
|
1115
1196
|
}
|
|
1116
|
-
input.ensureAlive();
|
|
1197
|
+
input.liveness.ensureAlive();
|
|
1117
1198
|
if (input.getTurn() !== undefined)
|
|
1118
1199
|
throw new Error("A turn is already running in this Claude session");
|
|
1119
1200
|
const turn = {
|
|
@@ -1133,9 +1214,8 @@ function createSdkStartTurn(input) {
|
|
|
1133
1214
|
});
|
|
1134
1215
|
input.markResumable();
|
|
1135
1216
|
active.startLoop();
|
|
1136
|
-
return sdkTurnHandle(turn, active.query, input.
|
|
1217
|
+
return sdkTurnHandle(turn, active.query, input.liveness);
|
|
1137
1218
|
} catch (error) {
|
|
1138
|
-
turn.settled = true;
|
|
1139
1219
|
if (input.getTurn() === turn)
|
|
1140
1220
|
input.setTurn(undefined);
|
|
1141
1221
|
throw error;
|
|
@@ -1160,44 +1240,33 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1160
1240
|
const env = engineEnvironment2(profile, ambient);
|
|
1161
1241
|
const sessionId = input.nativeThreadId ?? randomUUID2();
|
|
1162
1242
|
const transcript = claudeTranscriptPath2({ home: profile.home, cwd: input.cwd, sessionId });
|
|
1163
|
-
const transcriptExists = input.nativeThreadId !== undefined && await claudeTranscriptExists(transcript);
|
|
1164
|
-
let resume = transcriptExists || input.resumeSessionAt !== undefined;
|
|
1165
1243
|
let pendingResumeSessionAt = input.resumeSessionAt;
|
|
1166
1244
|
let pendingResumeDropsTurn = input.resumeDropsTurn;
|
|
1167
1245
|
let current;
|
|
1168
1246
|
let startingTurn = false;
|
|
1169
1247
|
let opened = false;
|
|
1170
|
-
let closing = false;
|
|
1171
|
-
let closed = false;
|
|
1172
|
-
let closeReason;
|
|
1173
1248
|
let providerPid;
|
|
1174
1249
|
let activeModel = config.model;
|
|
1175
1250
|
let activePermissionMode = config.permissionMode ?? "default";
|
|
1176
1251
|
let flagSettingsOverlay;
|
|
1177
1252
|
let running;
|
|
1253
|
+
const engineExits = new Set;
|
|
1178
1254
|
let inFlightClose;
|
|
1179
1255
|
const linked = sessionAbort(input.signal);
|
|
1180
|
-
const
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
throw abortReason(linked.signal);
|
|
1188
|
-
if (closed)
|
|
1189
|
-
throw closeReason ?? new Error("The Claude SDK session is closed");
|
|
1190
|
-
};
|
|
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();
|
|
1191
1263
|
const shutdown = (reason) => {
|
|
1192
|
-
if (
|
|
1264
|
+
if (liveness.lost !== undefined)
|
|
1193
1265
|
return;
|
|
1194
|
-
|
|
1195
|
-
closeReason = reason;
|
|
1266
|
+
liveness.markLost(reason);
|
|
1196
1267
|
providerPid = undefined;
|
|
1197
1268
|
const turn = current;
|
|
1198
1269
|
current = undefined;
|
|
1199
|
-
if (turn !== undefined)
|
|
1200
|
-
turn.settled = true;
|
|
1201
1270
|
loseEngineTurn(turn, stoppedPermission("The session was closed"), reason);
|
|
1202
1271
|
const pendingClose = inFlightClose;
|
|
1203
1272
|
inFlightClose = undefined;
|
|
@@ -1214,7 +1283,8 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1214
1283
|
isClosed,
|
|
1215
1284
|
...config.onPermissionRequest !== undefined && {
|
|
1216
1285
|
onPermissionRequest: config.onPermissionRequest
|
|
1217
|
-
}
|
|
1286
|
+
},
|
|
1287
|
+
...config.onObserverError !== undefined && { onObserverError: config.onObserverError }
|
|
1218
1288
|
});
|
|
1219
1289
|
const ensureQuery = createSdkQueryManager({
|
|
1220
1290
|
config,
|
|
@@ -1229,8 +1299,8 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1229
1299
|
isOpened: () => opened,
|
|
1230
1300
|
isClosed,
|
|
1231
1301
|
ensureAlive: ensureSessionAlive,
|
|
1232
|
-
getResume: () => ({
|
|
1233
|
-
resume,
|
|
1302
|
+
getResume: async () => ({
|
|
1303
|
+
resume: pendingResumeSessionAt !== undefined || await claudeTranscriptExists(transcript),
|
|
1234
1304
|
...pendingResumeSessionAt !== undefined && { resumeSessionAt: pendingResumeSessionAt },
|
|
1235
1305
|
...pendingResumeDropsTurn !== undefined && { resumeDropsTurn: pendingResumeDropsTurn }
|
|
1236
1306
|
}),
|
|
@@ -1253,6 +1323,10 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1253
1323
|
onPidExit: (exitedPid) => {
|
|
1254
1324
|
if (providerPid === exitedPid)
|
|
1255
1325
|
providerPid = undefined;
|
|
1326
|
+
},
|
|
1327
|
+
trackExit: (exited) => {
|
|
1328
|
+
engineExits.add(exited);
|
|
1329
|
+
exited.then(() => engineExits.delete(exited));
|
|
1256
1330
|
}
|
|
1257
1331
|
});
|
|
1258
1332
|
if (hasDelegationVerification(config.verifyDelegation)) {
|
|
@@ -1269,7 +1343,7 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1269
1343
|
config,
|
|
1270
1344
|
sessionId,
|
|
1271
1345
|
signal: linked.signal,
|
|
1272
|
-
|
|
1346
|
+
liveness,
|
|
1273
1347
|
getTurn: () => current,
|
|
1274
1348
|
setTurn: (turn) => {
|
|
1275
1349
|
current = turn;
|
|
@@ -1279,11 +1353,11 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1279
1353
|
startingTurn = value;
|
|
1280
1354
|
},
|
|
1281
1355
|
markResumable: () => {
|
|
1282
|
-
resume = true;
|
|
1283
1356
|
pendingResumeSessionAt = undefined;
|
|
1284
1357
|
pendingResumeDropsTurn = undefined;
|
|
1285
1358
|
},
|
|
1286
|
-
ensureQuery
|
|
1359
|
+
ensureQuery,
|
|
1360
|
+
isRunning: (handle) => running === handle
|
|
1287
1361
|
});
|
|
1288
1362
|
const controls = createClaudeSdkControls({
|
|
1289
1363
|
signal: linked.signal,
|
|
@@ -1313,10 +1387,11 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
1313
1387
|
startTurn,
|
|
1314
1388
|
...controls,
|
|
1315
1389
|
async close() {
|
|
1316
|
-
|
|
1390
|
+
liveness.markClosing();
|
|
1317
1391
|
shutdown(new Error("The Claude SDK session is closed"));
|
|
1318
1392
|
linked.abort();
|
|
1319
1393
|
linked.release();
|
|
1394
|
+
await waitForEngineExits(engineExits);
|
|
1320
1395
|
}
|
|
1321
1396
|
};
|
|
1322
1397
|
}
|