stitchkit 0.127.0 → 0.129.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 +194 -6
- package/dist/agent-executor/acp/v1-connect.d.ts +9 -1
- package/dist/agent-executor/acp/v1-connect.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-driver.d.ts +8 -2
- package/dist/agent-executor/acp/v1-driver.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-map.d.ts.map +1 -1
- package/dist/agent-executor/acp/v1-session.d.ts +8 -0
- package/dist/agent-executor/acp/v1-session.d.ts.map +1 -1
- package/dist/agent-executor/claude/cli-driver.d.ts +4 -0
- package/dist/agent-executor/claude/cli-driver.d.ts.map +1 -1
- package/dist/agent-executor/claude/protocol.d.ts +20 -2
- package/dist/agent-executor/claude/protocol.d.ts.map +1 -1
- package/dist/agent-executor/claude/session.d.ts +2 -1
- package/dist/agent-executor/claude/session.d.ts.map +1 -1
- package/dist/agent-executor/claude/transcript.d.ts +9 -6
- package/dist/agent-executor/claude/transcript.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/controls.d.ts +19 -0
- package/dist/agent-executor/claude-sdk/controls.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/driver.d.ts +118 -4
- package/dist/agent-executor/claude-sdk/driver.d.ts.map +1 -1
- package/dist/agent-executor/claude-sdk/query-loop.d.ts +46 -0
- package/dist/agent-executor/claude-sdk/query-loop.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/query-options.d.ts +27 -0
- package/dist/agent-executor/claude-sdk/query-options.d.ts.map +1 -0
- package/dist/agent-executor/claude-sdk/session.d.ts +6 -5
- package/dist/agent-executor/claude-sdk/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/classify.d.ts.map +1 -1
- package/dist/agent-executor/codex/connect.d.ts +45 -0
- package/dist/agent-executor/codex/connect.d.ts.map +1 -0
- package/dist/agent-executor/codex/driver.d.ts +55 -10
- package/dist/agent-executor/codex/driver.d.ts.map +1 -1
- package/dist/agent-executor/codex/limits.d.ts +11 -2
- package/dist/agent-executor/codex/limits.d.ts.map +1 -1
- package/dist/agent-executor/codex/protocol.d.ts +75 -6
- package/dist/agent-executor/codex/protocol.d.ts.map +1 -1
- package/dist/agent-executor/codex/session-controls.d.ts +155 -0
- package/dist/agent-executor/codex/session-controls.d.ts.map +1 -0
- package/dist/agent-executor/codex/session.d.ts +28 -30
- package/dist/agent-executor/codex/session.d.ts.map +1 -1
- package/dist/agent-executor/codex/unix-socket-target.d.ts +26 -0
- package/dist/agent-executor/codex/unix-socket-target.d.ts.map +1 -0
- package/dist/agent-executor/codex/unix-socket.d.ts +26 -0
- package/dist/agent-executor/codex/unix-socket.d.ts.map +1 -0
- package/dist/agent-executor/codex/ws-frame.d.ts +15 -0
- package/dist/agent-executor/codex/ws-frame.d.ts.map +1 -0
- package/dist/agent-executor/contract.d.ts +2 -0
- package/dist/agent-executor/contract.d.ts.map +1 -1
- package/dist/agent-executor/engine-process.d.ts +9 -0
- package/dist/agent-executor/engine-process.d.ts.map +1 -1
- package/dist/agent-executor/hello.d.ts +8 -0
- package/dist/agent-executor/hello.d.ts.map +1 -1
- package/dist/agent-executor/image-input.d.ts +71 -0
- package/dist/agent-executor/image-input.d.ts.map +1 -0
- package/dist/agent-executor/session-primitives.d.ts +0 -3
- package/dist/agent-executor/session-primitives.d.ts.map +1 -1
- package/dist/agent-runtime/agent-tool.d.ts +21 -7
- package/dist/agent-runtime/agent-tool.d.ts.map +1 -1
- package/dist/agent-runtime/branch-contract.d.ts +1 -0
- package/dist/agent-runtime/branch-contract.d.ts.map +1 -1
- package/dist/agent-runtime/branch-identities.d.ts +5 -2
- package/dist/agent-runtime/branch-identities.d.ts.map +1 -1
- package/dist/agent-runtime/branch-messages.d.ts +9 -9
- package/dist/agent-runtime/branch-messages.d.ts.map +1 -1
- package/dist/agent-runtime/branch-observations.d.ts +49 -36
- package/dist/agent-runtime/branch-observations.d.ts.map +1 -1
- package/dist/agent-runtime/branch-provider.d.ts +14 -8
- package/dist/agent-runtime/branch-provider.d.ts.map +1 -1
- package/dist/agent-runtime/branch-source.d.ts +13 -1
- package/dist/agent-runtime/branch-source.d.ts.map +1 -1
- package/dist/agent-runtime/child-tools.d.ts +64 -0
- package/dist/agent-runtime/child-tools.d.ts.map +1 -1
- package/dist/agent-runtime/event-search-tools.d.ts +82 -5
- package/dist/agent-runtime/event-search-tools.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts +1 -1
- package/dist/agent-runtime/invocation-attempt.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-payload.d.ts +12 -0
- package/dist/agent-runtime/invocation-payload.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-read.d.ts +6 -3
- package/dist/agent-runtime/invocation-read.d.ts.map +1 -1
- package/dist/agent-runtime/invocation-schema.d.ts +50 -8
- package/dist/agent-runtime/invocation-schema.d.ts.map +1 -1
- package/dist/agent-runtime/invocations.d.ts +20 -9
- package/dist/agent-runtime/invocations.d.ts.map +1 -1
- package/dist/agent-runtime/postgres.d.ts.map +1 -1
- package/dist/agent-runtime/schedule-tools.d.ts +30 -0
- package/dist/agent-runtime/schedule-tools.d.ts.map +1 -1
- package/dist/agent-runtime/schemas-invocation-payload.d.ts +48 -0
- package/dist/agent-runtime/schemas-invocation-payload.d.ts.map +1 -0
- package/dist/agent-runtime/sql-events.d.ts.map +1 -1
- package/dist/agent-runtime/sql-rows.d.ts +10 -10
- package/dist/agent-runtime/sql-session.d.ts +11 -0
- package/dist/agent-runtime/sql-session.d.ts.map +1 -1
- package/dist/agent-runtime/sqlite-transactions.d.ts.map +1 -1
- package/dist/agent-runtime/state-tools.d.ts +55 -0
- package/dist/agent-runtime/state-tools.d.ts.map +1 -1
- package/dist/agent-runtime/store-branch.d.ts.map +1 -1
- 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/store-create.d.ts.map +1 -1
- package/dist/agent-runtime/store-driver-contract.d.ts +12 -0
- package/dist/agent-runtime/store-driver-contract.d.ts.map +1 -1
- package/dist/agent-runtime/store-memory-events.d.ts.map +1 -1
- package/dist/agent-runtime/store.d.ts +7 -0
- package/dist/agent-runtime/store.d.ts.map +1 -1
- package/dist/agent-runtime/terminal-commit.d.ts +10 -10
- package/dist/declaration/declaration.d.ts +6 -3
- package/dist/declaration/declaration.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts +1 -1
- package/dist/entrypoints/agent-executor/acp.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/acp.js +28 -17
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts +1 -1
- package/dist/entrypoints/agent-executor/claude-sdk.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/claude-sdk.js +543 -96
- package/dist/entrypoints/agent-executor/claude.js +40 -21
- package/dist/entrypoints/agent-executor/codex.d.ts +4 -0
- package/dist/entrypoints/agent-executor/codex.d.ts.map +1 -1
- package/dist/entrypoints/agent-executor/codex.js +1530 -207
- package/dist/entrypoints/agent-executor.js +7 -7
- package/dist/entrypoints/agent-runtime/browser.js +1 -1
- package/dist/entrypoints/agent-runtime/coding-tools.js +3 -3
- package/dist/entrypoints/agent-runtime/harness.js +10 -11
- package/dist/entrypoints/agent-runtime/openrouter.js +4 -4
- package/dist/entrypoints/agent-runtime/postgres.js +12 -7
- package/dist/entrypoints/agent-runtime/realtime.js +4 -4
- package/dist/entrypoints/agent-runtime/sandbox.js +7 -7
- package/dist/entrypoints/agent-runtime/sqlite/bun.js +7 -7
- package/dist/entrypoints/agent-runtime/sqlite/node.js +7 -7
- package/dist/entrypoints/agent-runtime/testing.js +9 -9
- package/dist/entrypoints/agent-runtime.d.ts +9 -7
- package/dist/entrypoints/agent-runtime.d.ts.map +1 -1
- package/dist/entrypoints/agent-runtime.js +254 -207
- package/dist/entrypoints/application/diagnostic-journal.js +4 -4
- package/dist/entrypoints/application/directory-inbox.js +8 -8
- package/dist/entrypoints/application/opentelemetry.js +2 -2
- package/dist/entrypoints/application.js +2 -2
- package/dist/entrypoints/cli/publish.js +8 -8
- package/dist/entrypoints/cli.js +12 -11
- package/dist/entrypoints/contract.js +2 -2
- package/dist/entrypoints/declaration.js +0 -1
- package/dist/entrypoints/files/packaging.js +2 -2
- package/dist/entrypoints/files.js +42 -19
- package/dist/entrypoints/handler.js +4 -4
- package/dist/entrypoints/http.js +5 -5
- package/dist/entrypoints/index.js +7 -7
- package/dist/entrypoints/node.js +7 -7
- package/dist/entrypoints/observability.js +4 -4
- package/dist/entrypoints/primitives.js +2 -2
- package/dist/entrypoints/process.js +6 -6
- package/dist/entrypoints/react.js +1 -1
- package/dist/entrypoints/remote.js +2 -2
- package/dist/entrypoints/server.js +10 -10
- package/dist/entrypoints/service-host/macos.js +6 -6
- package/dist/entrypoints/service-host.d.ts +4 -1
- package/dist/entrypoints/service-host.d.ts.map +1 -1
- package/dist/entrypoints/service-host.js +835 -224
- package/dist/entrypoints/spend.js +1 -1
- package/dist/entrypoints/sync/postgres.js +1 -1
- package/dist/entrypoints/sync.js +2 -2
- package/dist/entrypoints/telegram.js +5 -5
- package/dist/entrypoints/testing.js +5 -5
- package/dist/entrypoints/tools/agent.js +5 -4
- package/dist/entrypoints/tools/connections.js +2 -2
- package/dist/entrypoints/tools/invoker.js +4 -3
- package/dist/entrypoints/tools/mcp.js +5 -4
- package/dist/entrypoints/tools/toolkit.js +8 -7
- package/dist/entrypoints/tools.d.ts +1 -1
- package/dist/entrypoints/tools.d.ts.map +1 -1
- package/dist/entrypoints/tools.js +15 -13
- package/dist/entrypoints/tracking/contract.js +1 -1
- package/dist/entrypoints/xlsx.js +1 -1
- package/dist/files/directory-appearance.d.ts +20 -9
- package/dist/files/directory-appearance.d.ts.map +1 -1
- package/dist/files/polled-json.d.ts.map +1 -1
- package/dist/files/regular-file.d.ts +15 -5
- package/dist/files/regular-file.d.ts.map +1 -1
- package/dist/{index-prf6ayhf.js → index-13wmzpa6.js} +1 -1
- package/dist/{index-qnzhmk2s.js → index-17qgm6xe.js} +91 -48
- package/dist/{index-wv8dqy7q.js → index-205456mf.js} +1 -1
- package/dist/{index-3gwp8ez6.js → index-21cfxc4z.js} +13 -18
- package/dist/{index-xtkw9866.js → index-2c5w2d1d.js} +1 -1
- package/dist/{index-g1q7fwn9.js → index-2nwvn7m2.js} +1 -1
- package/dist/{index-d4svrknj.js → index-39c2hj6h.js} +2 -2
- package/dist/{index-sfzfd2m2.js → index-39rmc00v.js} +1 -1
- package/dist/{index-ky3ardqn.js → index-3fym4j8n.js} +1 -1
- package/dist/{index-d96c1n1q.js → index-5tdc0q43.js} +20 -19
- package/dist/{index-3ypvpkwr.js → index-669374qc.js} +1 -1
- package/dist/{index-x90w78yz.js → index-673drwkn.js} +23 -8
- package/dist/{index-83n766x4.js → index-7jqn3b3g.js} +16 -10
- package/dist/{index-5jyjb4s0.js → index-80acsm27.js} +1 -1
- package/dist/{index-xmr47znh.js → index-827bgv33.js} +1 -1
- package/dist/{index-xypxnzhp.js → index-93n6jwy0.js} +4 -4
- package/dist/{index-wbnpa8z6.js → index-9kpxz49v.js} +5 -5
- package/dist/{index-fcw255hd.js → index-9sfhje6y.js} +3 -3
- package/dist/{index-bh4pmtr9.js → index-afb6z77w.js} +3 -1
- package/dist/{index-9y0afd5f.js → index-apf5g7y9.js} +1 -1
- package/dist/{index-4qvyhn23.js → index-bjmj2q1z.js} +1 -1
- package/dist/{index-bbzvrq66.js → index-dcsxj68j.js} +457 -204
- package/dist/{index-j516jaaz.js → index-dnzxxf8a.js} +49 -2
- package/dist/{index-kmbpej2y.js → index-emgrmavr.js} +102 -61
- package/dist/index-fgahdc7s.js +100 -0
- package/dist/{index-kzavdze2.js → index-gr0kxymw.js} +5 -1
- package/dist/{index-e06z0tkb.js → index-gya4hwh3.js} +2 -2
- package/dist/{index-3djgv3ch.js → index-hab790s6.js} +26 -11
- package/dist/{index-j13gzgdv.js → index-j0ef04jw.js} +9 -5
- package/dist/{index-rhb33thr.js → index-jcge9tx3.js} +1 -1
- package/dist/{index-dvd1qdwa.js → index-ke02kxsr.js} +3 -3
- package/dist/{index-3agqmmrg.js → index-mkfhpk11.js} +7 -9
- package/dist/{index-a725ayvz.js → index-mttkdm5a.js} +1 -1
- package/dist/{index-9wh98cpa.js → index-n3bm7zqq.js} +131 -91
- package/dist/{index-7xp05h20.js → index-p06z7g7w.js} +7 -7
- package/dist/{index-kt6dh1n6.js → index-p16q492v.js} +1 -1
- package/dist/{index-5zwac8ft.js → index-pp97q86a.js} +3 -3
- package/dist/{index-39n02e0q.js → index-psye60qn.js} +1 -1
- package/dist/{index-5ptwb6ka.js → index-pzhqydxb.js} +1 -1
- package/dist/{index-7kfcb576.js → index-qa2jjb65.js} +1 -1
- package/dist/{index-0djnptn8.js → index-qhjmmsm2.js} +10 -3
- package/dist/{index-7grgs8cx.js → index-qpzyahe3.js} +2 -2
- package/dist/{index-8xr2eq99.js → index-r97ppg0g.js} +4 -4
- package/dist/{index-bmaz3jzy.js → index-rjs94dny.js} +1 -1
- package/dist/{index-p1m9djt6.js → index-rxh3qy4x.js} +33 -6
- package/dist/{index-en8e5zsj.js → index-ryxb427v.js} +1 -1
- package/dist/{index-nbv44x0x.js → index-s2e3h616.js} +137 -36
- package/dist/{index-dwa6pskj.js → index-sd4e5x5j.js} +86 -47
- package/dist/{index-g56ht6qf.js → index-t3qcac2a.js} +1 -1
- package/dist/index-vgzhw2zk.js +304 -0
- package/dist/{index-jrka9029.js → index-vmbxj75t.js} +2 -2
- package/dist/{index-caywx1c0.js → index-wv2amqm4.js} +109 -12
- package/dist/{index-5e0zsbf7.js → index-x2fb37t0.js} +2 -2
- package/dist/{index-z4k0hqp9.js → index-y71zn1gw.js} +137 -27
- package/dist/{index-wavv538x.js → index-ybdq8kk2.js} +3 -3
- package/dist/{index-4gk6k3zc.js → index-ycr4pk0z.js} +1 -1
- package/dist/{index-0tyt97nk.js → index-yrr3n391.js} +1 -1
- package/dist/{index-v37b2cd6.js → index-z20pdxeb.js} +2 -2
- package/dist/{index-0hdm5sx6.js → index-z9d74jmb.js} +8 -4
- package/dist/{index-4s2w4g37.js → index-zhshhxew.js} +80 -2
- package/dist/{index-3b31z0pc.js → index-znd1b57f.js} +12 -6
- package/dist/internal/bounded-file-confirm.d.ts +32 -0
- package/dist/internal/bounded-file-confirm.d.ts.map +1 -0
- package/dist/internal/bounded-file-read.d.ts +10 -7
- package/dist/internal/bounded-file-read.d.ts.map +1 -1
- package/dist/internal/file-observation.d.ts +5 -1
- package/dist/internal/file-observation.d.ts.map +1 -1
- package/dist/internal/positive-integer.d.ts +2 -0
- package/dist/internal/positive-integer.d.ts.map +1 -1
- package/dist/internal/process-instance.d.ts +8 -0
- package/dist/internal/process-instance.d.ts.map +1 -1
- package/dist/internal/unix-socket.d.ts +10 -1
- package/dist/internal/unix-socket.d.ts.map +1 -1
- package/dist/server/unix-client.d.ts +7 -0
- package/dist/server/unix-client.d.ts.map +1 -1
- package/dist/service-host/systemd-inspect.d.ts +3 -1
- package/dist/service-host/systemd-inspect.d.ts.map +1 -1
- package/dist/service-host/systemd-render-shared.d.ts +64 -0
- package/dist/service-host/systemd-render-shared.d.ts.map +1 -0
- package/dist/service-host/systemd-render.d.ts +31 -26
- package/dist/service-host/systemd-render.d.ts.map +1 -1
- package/dist/service-host/systemd-timer-render.d.ts +31 -0
- package/dist/service-host/systemd-timer-render.d.ts.map +1 -0
- package/dist/service-host/systemd-timer-rollback.d.ts +26 -0
- package/dist/service-host/systemd-timer-rollback.d.ts.map +1 -0
- package/dist/service-host/systemd-timer.d.ts +82 -0
- package/dist/service-host/systemd-timer.d.ts.map +1 -0
- package/dist/service-host/systemd-unit-ops.d.ts +26 -0
- package/dist/service-host/systemd-unit-ops.d.ts.map +1 -0
- package/dist/service-host/systemd.d.ts +1 -1
- package/dist/service-host/systemd.d.ts.map +1 -1
- package/dist/tools/access.d.ts +30 -1
- package/dist/tools/access.d.ts.map +1 -1
- package/dist/tools/agent.d.ts +2 -2
- package/dist/tools/agent.d.ts.map +1 -1
- package/dist/tools/cli/args-scan.d.ts +5 -0
- package/dist/tools/cli/args-scan.d.ts.map +1 -1
- package/dist/tools/cli/args.d.ts +11 -5
- package/dist/tools/cli/args.d.ts.map +1 -1
- package/dist/tools/cli/invoke.d.ts +2 -1
- package/dist/tools/cli/invoke.d.ts.map +1 -1
- package/dist/tools/cli/notices.d.ts.map +1 -1
- package/dist/tools/cli/run-managed.d.ts.map +1 -1
- package/dist/tools/cli/session.d.ts.map +1 -1
- package/dist/tools/execute.d.ts.map +1 -1
- package/dist/tools/invoker.d.ts +2 -1
- package/dist/tools/invoker.d.ts.map +1 -1
- package/dist/tools/list-names.d.ts +2 -3
- package/dist/tools/list-names.d.ts.map +1 -1
- package/dist/tools/manifest.d.ts +2 -3
- package/dist/tools/manifest.d.ts.map +1 -1
- package/dist/tools/mcp/mount.d.ts +5 -5
- package/dist/tools/mcp/mount.d.ts.map +1 -1
- package/dist/tools/mcp/register.d.ts +2 -1
- package/dist/tools/mcp/register.d.ts.map +1 -1
- package/dist/tools/mcp/runtime-tools.d.ts.map +1 -1
- package/llms/agent-executor-acp.txt +10 -6
- package/llms/agent-executor-claude-sdk.txt +13 -10
- package/llms/agent-executor-claude.txt +2 -2
- package/llms/agent-executor-codex.txt +9 -3
- package/llms/agent-executor.txt +2 -2
- package/llms/agent-runtime.4.txt +21 -9
- package/llms/cli.3.txt +4 -4
- package/llms/cli.txt +1 -0
- package/llms/declaration.txt +2 -2
- package/llms/files.txt +1 -1
- package/llms/node.txt +2 -2
- package/llms/server.5.txt +2 -2
- package/llms/service-host.txt +5 -5
- package/llms/stitchkit.txt +81 -77
- package/llms/tools.3.txt +3 -2
- package/llms/upgrading-0.128.0-0.129.0.txt +175 -0
- package/llms/upgrading.txt +1 -0
- package/llms-full.txt +323 -127
- package/llms.txt +15 -14
- package/package.json +1 -1
- package/dist/index-ajmtxsky.js +0 -193
- package/dist/index-ax3wns1a.js +0 -93
|
@@ -3,45 +3,289 @@ import {
|
|
|
3
3
|
InteractionReplySchema2,
|
|
4
4
|
engineProfile,
|
|
5
5
|
engineEnvironment2
|
|
6
|
-
} from "../../index-
|
|
6
|
+
} from "../../index-afb6z77w.js";
|
|
7
7
|
import"../../index-09f7w2qq.js";
|
|
8
8
|
import"../../index-v59pxmf1.js";
|
|
9
|
-
import"../../index-
|
|
9
|
+
import"../../index-qa2jjb65.js";
|
|
10
10
|
import"../../index-6kec3b14.js";
|
|
11
11
|
import {
|
|
12
12
|
nonEmptyString,
|
|
13
13
|
createTurnDeltaChannel,
|
|
14
14
|
offerTurnDelta,
|
|
15
|
-
extractTextOnlyInput,
|
|
16
15
|
sessionAbort,
|
|
17
16
|
safeJsonValue,
|
|
17
|
+
validateImageOptions,
|
|
18
|
+
imageTurnStarter,
|
|
18
19
|
holdEngineRequest,
|
|
19
20
|
answerEngineRequest,
|
|
20
21
|
drainEngineRequests,
|
|
21
22
|
endEngineTurn,
|
|
22
23
|
loseEngineTurn
|
|
23
|
-
} from "../../index-
|
|
24
|
+
} from "../../index-wv2amqm4.js";
|
|
24
25
|
import {
|
|
26
|
+
claudeUserContent,
|
|
25
27
|
newClaudeTurnState,
|
|
26
28
|
classifyClaudeRecord,
|
|
27
29
|
claudePlanWindows2,
|
|
28
30
|
claudeTranscriptPath2,
|
|
29
31
|
claudeTranscriptExists,
|
|
30
32
|
findTranscriptInput
|
|
31
|
-
} from "../../index-
|
|
32
|
-
import"../../index-
|
|
33
|
+
} from "../../index-y71zn1gw.js";
|
|
34
|
+
import"../../index-pzhqydxb.js";
|
|
33
35
|
import {
|
|
34
36
|
mergeRateLimitEvent2
|
|
35
|
-
} from "../../index-
|
|
37
|
+
} from "../../index-bjmj2q1z.js";
|
|
36
38
|
import {
|
|
37
|
-
|
|
39
|
+
isPositiveSafeInteger
|
|
40
|
+
} from "../../index-gr0kxymw.js";
|
|
41
|
+
import {
|
|
42
|
+
assertTimerMs,
|
|
43
|
+
withSignalDeadline
|
|
44
|
+
} from "../../index-agy5fqgf.js";
|
|
45
|
+
import {
|
|
46
|
+
abortReason,
|
|
47
|
+
raceAbort
|
|
38
48
|
} from "../../index-rptj3qnc.js";
|
|
39
49
|
|
|
50
|
+
// src/agent-executor/claude-sdk/query-options.ts
|
|
51
|
+
import { spawn } from "node:child_process";
|
|
52
|
+
import { StringDecoder } from "node:string_decoder";
|
|
53
|
+
var DEFAULT_DELEGATION_TIMEOUT_MS = 30000;
|
|
54
|
+
var FLAG_SETTINGS_REPLAY_TIMEOUT_MS = 30000;
|
|
55
|
+
function validateClaudeSdkConfig(config) {
|
|
56
|
+
validateImageOptions(config);
|
|
57
|
+
if (config.supportedDialogKinds !== undefined && config.supportedDialogKinds.length > 0 && config.onUserDialog === undefined) {
|
|
58
|
+
throw new TypeError("ClaudeSdkDriverConfig.supportedDialogKinds requires onUserDialog when non-empty");
|
|
59
|
+
}
|
|
60
|
+
if (config.verifyDelegation?.timeoutMs !== undefined) {
|
|
61
|
+
assertTimerMs("verifyDelegation.timeoutMs", config.verifyDelegation.timeoutMs);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function hasDelegationVerification(check) {
|
|
65
|
+
return check?.requireHooksApplied === true || check?.requireNoMcpServers === true;
|
|
66
|
+
}
|
|
67
|
+
function readPositivePid(spawned) {
|
|
68
|
+
if (typeof spawned !== "object" || spawned === null)
|
|
69
|
+
return;
|
|
70
|
+
const raw = Reflect.get(spawned, "pid");
|
|
71
|
+
return isPositiveSafeInteger(raw) ? raw : undefined;
|
|
72
|
+
}
|
|
73
|
+
function createDefaultSpawner(stderrCallback) {
|
|
74
|
+
return (opts) => {
|
|
75
|
+
const child = spawn(opts.command, opts.args, {
|
|
76
|
+
cwd: opts.cwd,
|
|
77
|
+
env: opts.env,
|
|
78
|
+
signal: opts.signal,
|
|
79
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
80
|
+
shell: false,
|
|
81
|
+
windowsHide: true
|
|
82
|
+
});
|
|
83
|
+
if (child.stderr !== null) {
|
|
84
|
+
const decoder = new StringDecoder("utf8");
|
|
85
|
+
const emit = (text) => {
|
|
86
|
+
if (text.length === 0 || stderrCallback === undefined)
|
|
87
|
+
return;
|
|
88
|
+
try {
|
|
89
|
+
stderrCallback(text);
|
|
90
|
+
} catch {}
|
|
91
|
+
};
|
|
92
|
+
child.stderr.on("error", () => {
|
|
93
|
+
return;
|
|
94
|
+
});
|
|
95
|
+
child.stderr.on("data", (chunk) => {
|
|
96
|
+
emit(typeof chunk === "string" ? chunk : decoder.write(chunk));
|
|
97
|
+
});
|
|
98
|
+
child.stderr.on("end", () => {
|
|
99
|
+
emit(decoder.end());
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return child;
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function buildSpawnHook(config, recordPid, onPidExit) {
|
|
106
|
+
if (config.spawnClaudeCodeProcess === undefined && config.onProviderPid === undefined) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const baseSpawner = config.spawnClaudeCodeProcess ?? createDefaultSpawner(config.stderr);
|
|
110
|
+
return (spawnOpts) => {
|
|
111
|
+
const proc = baseSpawner(spawnOpts);
|
|
112
|
+
const pid = readPositivePid(proc);
|
|
113
|
+
recordPid(pid);
|
|
114
|
+
if (pid !== undefined && typeof proc.once === "function") {
|
|
115
|
+
proc.once("exit", () => onPidExit(pid));
|
|
116
|
+
}
|
|
117
|
+
if (pid !== undefined && config.onProviderPid !== undefined) {
|
|
118
|
+
try {
|
|
119
|
+
config.onProviderPid(pid);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
try {
|
|
122
|
+
proc.kill("SIGTERM");
|
|
123
|
+
} catch {}
|
|
124
|
+
recordPid(undefined);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return proc;
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
function buildClaudeSdkQueryOptions(input) {
|
|
132
|
+
const { config } = input;
|
|
133
|
+
const spawnHook = buildSpawnHook(config, input.recordPid, input.onPidExit);
|
|
134
|
+
return {
|
|
135
|
+
cwd: input.cwd,
|
|
136
|
+
env: input.env,
|
|
137
|
+
includePartialMessages: true,
|
|
138
|
+
permissionMode: input.activePermissionMode,
|
|
139
|
+
canUseTool: input.canUseTool,
|
|
140
|
+
...input.activeModel !== undefined && { model: input.activeModel },
|
|
141
|
+
...config.allowDangerouslySkipPermissions !== undefined && {
|
|
142
|
+
allowDangerouslySkipPermissions: config.allowDangerouslySkipPermissions
|
|
143
|
+
},
|
|
144
|
+
...config.pathToClaudeCodeExecutable !== undefined && {
|
|
145
|
+
pathToClaudeCodeExecutable: config.pathToClaudeCodeExecutable
|
|
146
|
+
},
|
|
147
|
+
...config.systemPrompt !== undefined && { systemPrompt: config.systemPrompt },
|
|
148
|
+
...config.settingSources !== undefined && { settingSources: config.settingSources },
|
|
149
|
+
...config.enableFileCheckpointing !== undefined && {
|
|
150
|
+
enableFileCheckpointing: config.enableFileCheckpointing
|
|
151
|
+
},
|
|
152
|
+
...config.supportedDialogKinds !== undefined && {
|
|
153
|
+
supportedDialogKinds: [...config.supportedDialogKinds]
|
|
154
|
+
},
|
|
155
|
+
...config.onUserDialog !== undefined && { onUserDialog: config.onUserDialog },
|
|
156
|
+
...config.hooks !== undefined && { hooks: config.hooks },
|
|
157
|
+
...config.tools !== undefined && { tools: config.tools },
|
|
158
|
+
...config.allowedTools !== undefined && { allowedTools: config.allowedTools },
|
|
159
|
+
...config.disallowedTools !== undefined && { disallowedTools: config.disallowedTools },
|
|
160
|
+
...config.mcpServers !== undefined && { mcpServers: config.mcpServers },
|
|
161
|
+
...config.mcpServersDelivery !== undefined && {
|
|
162
|
+
mcpServersDelivery: config.mcpServersDelivery
|
|
163
|
+
},
|
|
164
|
+
...config.strictMcpConfig !== undefined && { strictMcpConfig: config.strictMcpConfig },
|
|
165
|
+
...config.plugins !== undefined && { plugins: config.plugins },
|
|
166
|
+
...config.agents !== undefined && { agents: config.agents },
|
|
167
|
+
...config.extraArgs !== undefined && { extraArgs: config.extraArgs },
|
|
168
|
+
...config.stderr !== undefined && { stderr: config.stderr },
|
|
169
|
+
...spawnHook !== undefined && { spawnClaudeCodeProcess: spawnHook },
|
|
170
|
+
...input.resume ? { resume: input.sessionId } : { sessionId: input.sessionId }
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
async function verifyClaudeSdkDelegation(query, check, signal) {
|
|
174
|
+
const timeoutMs = check.timeoutMs ?? DEFAULT_DELEGATION_TIMEOUT_MS;
|
|
175
|
+
await withSignalDeadline(timeoutMs, signal, () => new Error(`Claude SDK delegation verification timed out after ${timeoutMs} ms`), async (deadlineSignal) => {
|
|
176
|
+
if (check.requireHooksApplied === true) {
|
|
177
|
+
if (typeof query.initializationResult !== "function") {
|
|
178
|
+
throw new Error("Claude SDK delegation verification requires query.initializationResult()");
|
|
179
|
+
}
|
|
180
|
+
const initialized = await raceAbort(query.initializationResult(), deadlineSignal);
|
|
181
|
+
if (typeof initialized !== "object" || initialized === null || Reflect.get(initialized, "hooks_applied") !== true) {
|
|
182
|
+
throw new Error("Claude SDK did not acknowledge delegation hooks (initializationResult().hooks_applied !== true)");
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (check.requireNoMcpServers === true) {
|
|
186
|
+
if (typeof query.mcpServerStatus !== "function") {
|
|
187
|
+
throw new Error("Claude SDK delegation verification requires query.mcpServerStatus()");
|
|
188
|
+
}
|
|
189
|
+
const servers = await raceAbort(query.mcpServerStatus(), deadlineSignal);
|
|
190
|
+
if (!Array.isArray(servers)) {
|
|
191
|
+
throw new Error("Claude SDK delegation verification refused non-array mcpServerStatus() response");
|
|
192
|
+
}
|
|
193
|
+
if (servers.length > 0) {
|
|
194
|
+
throw new Error(`Claude SDK exposed ${servers.length} MCP server(s) under delegated policy`);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
async function replayClaudeSdkFlagSettings(query, overlay, signal) {
|
|
200
|
+
if (typeof query.applyFlagSettings !== "function") {
|
|
201
|
+
throw new Error("Claude SDK cannot replay flag settings on restart: query does not support applyFlagSettings()");
|
|
202
|
+
}
|
|
203
|
+
const applySettings = query.applyFlagSettings.bind(query);
|
|
204
|
+
await withSignalDeadline(FLAG_SETTINGS_REPLAY_TIMEOUT_MS, signal, () => new Error(`Claude SDK flag settings replay timed out after ${FLAG_SETTINGS_REPLAY_TIMEOUT_MS} ms`), (replaySignal) => raceAbort(applySettings(overlay), replaySignal).catch((error) => {
|
|
205
|
+
if (replaySignal.aborted)
|
|
206
|
+
throw abortReason(replaySignal);
|
|
207
|
+
throw error;
|
|
208
|
+
}));
|
|
209
|
+
}
|
|
210
|
+
|
|
40
211
|
// src/agent-executor/claude-sdk/session.ts
|
|
41
|
-
import { randomUUID } from "node:crypto";
|
|
42
|
-
|
|
43
|
-
|
|
212
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
213
|
+
|
|
214
|
+
// src/agent-executor/claude-sdk/controls.ts
|
|
215
|
+
function requireMethod(query, name) {
|
|
216
|
+
const fn = query[name];
|
|
217
|
+
if (typeof fn !== "function") {
|
|
218
|
+
throw new Error(`The configured Claude SDK query does not support ${String(name)}()`);
|
|
219
|
+
}
|
|
220
|
+
return fn;
|
|
221
|
+
}
|
|
222
|
+
function createClaudeSdkControls(host) {
|
|
223
|
+
const activeQuery = async () => {
|
|
224
|
+
if (host.isClosed())
|
|
225
|
+
throw new Error("The Claude SDK session is closed");
|
|
226
|
+
const active = await raceAbort(host.ensureQuery(), host.signal);
|
|
227
|
+
if (host.isClosed())
|
|
228
|
+
throw new Error("The Claude SDK session is closed");
|
|
229
|
+
return active.query;
|
|
230
|
+
};
|
|
231
|
+
const guarded = (promise) => raceAbort(promise, host.signal);
|
|
232
|
+
return {
|
|
233
|
+
async setModel(model) {
|
|
234
|
+
const query = await activeQuery();
|
|
235
|
+
await guarded(requireMethod(query, "setModel").call(query, model));
|
|
236
|
+
host.setActiveModel(model);
|
|
237
|
+
},
|
|
238
|
+
async setPermissionMode(mode) {
|
|
239
|
+
const query = await activeQuery();
|
|
240
|
+
await guarded(requireMethod(query, "setPermissionMode").call(query, mode));
|
|
241
|
+
host.setActivePermissionMode(mode);
|
|
242
|
+
},
|
|
243
|
+
async applyFlagSettings(settings) {
|
|
244
|
+
const query = await activeQuery();
|
|
245
|
+
await guarded(requireMethod(query, "applyFlagSettings").call(query, settings));
|
|
246
|
+
host.recordFlagSettings(settings);
|
|
247
|
+
},
|
|
248
|
+
async initializationResult() {
|
|
249
|
+
const query = await activeQuery();
|
|
250
|
+
return guarded(requireMethod(query, "initializationResult").call(query));
|
|
251
|
+
},
|
|
252
|
+
async supportedModels() {
|
|
253
|
+
const query = await activeQuery();
|
|
254
|
+
return guarded(requireMethod(query, "supportedModels").call(query));
|
|
255
|
+
},
|
|
256
|
+
async supportedCommands() {
|
|
257
|
+
const query = await activeQuery();
|
|
258
|
+
return guarded(requireMethod(query, "supportedCommands").call(query));
|
|
259
|
+
},
|
|
260
|
+
async accountInfo() {
|
|
261
|
+
const query = await activeQuery();
|
|
262
|
+
return guarded(requireMethod(query, "accountInfo").call(query));
|
|
263
|
+
},
|
|
264
|
+
async getContextUsage(opts) {
|
|
265
|
+
const query = await activeQuery();
|
|
266
|
+
return guarded(requireMethod(query, "getContextUsage").call(query, opts));
|
|
267
|
+
},
|
|
268
|
+
async mcpServerStatus() {
|
|
269
|
+
const query = await activeQuery();
|
|
270
|
+
return guarded(requireMethod(query, "mcpServerStatus").call(query));
|
|
271
|
+
},
|
|
272
|
+
async toggleMcpServer(serverName, enabled) {
|
|
273
|
+
const query = await activeQuery();
|
|
274
|
+
await guarded(requireMethod(query, "toggleMcpServer").call(query, serverName, enabled));
|
|
275
|
+
},
|
|
276
|
+
async reconnectMcpServer(serverName) {
|
|
277
|
+
const query = await activeQuery();
|
|
278
|
+
await guarded(requireMethod(query, "reconnectMcpServer").call(query, serverName));
|
|
279
|
+
},
|
|
280
|
+
async rewindFiles(userMessageId, options) {
|
|
281
|
+
const query = await activeQuery();
|
|
282
|
+
return guarded(requireMethod(query, "rewindFiles").call(query, userMessageId, options));
|
|
283
|
+
}
|
|
284
|
+
};
|
|
44
285
|
}
|
|
286
|
+
|
|
287
|
+
// src/agent-executor/claude-sdk/query-loop.ts
|
|
288
|
+
import { randomUUID } from "node:crypto";
|
|
45
289
|
var SDK_ANSWER = { source: "claude-sdk", type: "PermissionResult" };
|
|
46
290
|
var stoppedPermission = (message) => () => ({
|
|
47
291
|
behavior: "deny",
|
|
@@ -150,21 +394,195 @@ function sdkTurnHandle(turn, query) {
|
|
|
150
394
|
}
|
|
151
395
|
};
|
|
152
396
|
}
|
|
397
|
+
function runSdkQueryLoop(input) {
|
|
398
|
+
(async () => {
|
|
399
|
+
try {
|
|
400
|
+
for await (const record of input.handle.query) {
|
|
401
|
+
const turn = input.getTurn();
|
|
402
|
+
const verdict = classifyClaudeRecord(record, turn?.state ?? newClaudeTurnState("between-turns"));
|
|
403
|
+
if (verdict.kind === "limits") {
|
|
404
|
+
input.limits.set(input.profileId, mergeRateLimitEvent2({
|
|
405
|
+
previous: input.limits.get(input.profileId),
|
|
406
|
+
windows: claudePlanWindows2(verdict.info),
|
|
407
|
+
now: new Date
|
|
408
|
+
}));
|
|
409
|
+
} else if (verdict.kind === "deltas") {
|
|
410
|
+
for (const delta of verdict.deltas)
|
|
411
|
+
offerTurnDelta(turn?.channel, delta);
|
|
412
|
+
} else if (verdict.kind === "end") {
|
|
413
|
+
endEngineTurn(turn, stoppedPermission("The turn ended"), verdict.deltas);
|
|
414
|
+
input.clearTurn();
|
|
415
|
+
} else if (verdict.kind === "unhandled") {
|
|
416
|
+
offerTurnDelta(turn?.channel, verdict.delta);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
throw new Error("The Agent SDK query ended during the turn");
|
|
420
|
+
} catch (error) {
|
|
421
|
+
input.onExit(input.handle, error);
|
|
422
|
+
}
|
|
423
|
+
})();
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
// src/agent-executor/claude-sdk/session.ts
|
|
427
|
+
function isUuid(value) {
|
|
428
|
+
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
429
|
+
}
|
|
430
|
+
function createSdkStartTurn(input) {
|
|
431
|
+
return imageTurnStarter({
|
|
432
|
+
driverLabel: "The Agent SDK driver",
|
|
433
|
+
busyMessage: "A turn is already running in this Claude session",
|
|
434
|
+
imageOptions: input.config,
|
|
435
|
+
signal: input.signal,
|
|
436
|
+
check(turnInput) {
|
|
437
|
+
if (input.isClosed())
|
|
438
|
+
throw new Error("The Claude SDK session is closed");
|
|
439
|
+
if (input.getTurn() !== undefined || input.isStarting())
|
|
440
|
+
throw new Error("A turn is already running in this Claude session");
|
|
441
|
+
if (!isUuid(turnInput.clientId))
|
|
442
|
+
throw new TypeError("The Agent SDK driver needs a UUID client id");
|
|
443
|
+
},
|
|
444
|
+
async dispatch(turnInput, parts) {
|
|
445
|
+
const clientId = turnInput.clientId;
|
|
446
|
+
if (!isUuid(clientId))
|
|
447
|
+
throw new TypeError("The Agent SDK driver needs a UUID client id");
|
|
448
|
+
input.setStarting(true);
|
|
449
|
+
let active;
|
|
450
|
+
try {
|
|
451
|
+
active = await input.ensureQuery(false);
|
|
452
|
+
} finally {
|
|
453
|
+
input.setStarting(false);
|
|
454
|
+
}
|
|
455
|
+
if (input.isClosed())
|
|
456
|
+
throw new Error("The Claude SDK session is closed");
|
|
457
|
+
if (input.getTurn() !== undefined)
|
|
458
|
+
throw new Error("A turn is already running in this Claude session");
|
|
459
|
+
const turn = {
|
|
460
|
+
state: newClaudeTurnState(turnInput.turnId),
|
|
461
|
+
channel: createTurnDeltaChannel(),
|
|
462
|
+
pending: new Map
|
|
463
|
+
};
|
|
464
|
+
input.setTurn(turn);
|
|
465
|
+
try {
|
|
466
|
+
active.send({
|
|
467
|
+
type: "user",
|
|
468
|
+
message: { role: "user", content: claudeUserContent(parts) },
|
|
469
|
+
parent_tool_use_id: null,
|
|
470
|
+
uuid: clientId,
|
|
471
|
+
session_id: input.sessionId
|
|
472
|
+
});
|
|
473
|
+
input.markResumable();
|
|
474
|
+
active.startLoop();
|
|
475
|
+
return sdkTurnHandle(turn, active.query);
|
|
476
|
+
} catch (error) {
|
|
477
|
+
if (input.getTurn() === turn)
|
|
478
|
+
input.setTurn(undefined);
|
|
479
|
+
throw error;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
async function launchSingleSdkQuery(input) {
|
|
485
|
+
if (input.isClosed())
|
|
486
|
+
throw new Error("The Claude SDK session is closed");
|
|
487
|
+
input.signal.throwIfAborted();
|
|
488
|
+
const pushed = pushablePrompt();
|
|
489
|
+
let query;
|
|
490
|
+
try {
|
|
491
|
+
query = input.config.query({
|
|
492
|
+
prompt: pushed.prompt,
|
|
493
|
+
options: buildClaudeSdkQueryOptions({
|
|
494
|
+
config: input.config,
|
|
495
|
+
cwd: input.cwd,
|
|
496
|
+
env: input.env,
|
|
497
|
+
canUseTool: input.canUseTool,
|
|
498
|
+
sessionId: input.sessionId,
|
|
499
|
+
resume: input.resume,
|
|
500
|
+
activeModel: input.activeModel,
|
|
501
|
+
activePermissionMode: input.activePermissionMode,
|
|
502
|
+
recordPid: input.recordPid,
|
|
503
|
+
onPidExit: input.onPidExit
|
|
504
|
+
})
|
|
505
|
+
});
|
|
506
|
+
} catch (error) {
|
|
507
|
+
input.recordPid(undefined);
|
|
508
|
+
pushed.end();
|
|
509
|
+
throw error;
|
|
510
|
+
}
|
|
511
|
+
let closedOnce = false;
|
|
512
|
+
let loopStarted = false;
|
|
513
|
+
const closeHandle = () => {
|
|
514
|
+
if (closedOnce)
|
|
515
|
+
return;
|
|
516
|
+
closedOnce = true;
|
|
517
|
+
pushed.end();
|
|
518
|
+
closeQuerySafely(query);
|
|
519
|
+
};
|
|
520
|
+
const handle = {
|
|
521
|
+
query,
|
|
522
|
+
send: pushed.send,
|
|
523
|
+
startLoop() {
|
|
524
|
+
if (loopStarted || closedOnce)
|
|
525
|
+
return;
|
|
526
|
+
loopStarted = true;
|
|
527
|
+
runSdkQueryLoop({
|
|
528
|
+
handle,
|
|
529
|
+
profileId: input.profileId,
|
|
530
|
+
limits: input.limits,
|
|
531
|
+
getTurn: input.getTurn,
|
|
532
|
+
clearTurn: input.clearTurn,
|
|
533
|
+
onExit: input.onExit
|
|
534
|
+
});
|
|
535
|
+
},
|
|
536
|
+
close: closeHandle
|
|
537
|
+
};
|
|
538
|
+
input.setInFlightClose(closeHandle);
|
|
539
|
+
try {
|
|
540
|
+
if (hasDelegationVerification(input.config.verifyDelegation)) {
|
|
541
|
+
await verifyClaudeSdkDelegation(query, input.config.verifyDelegation, input.signal);
|
|
542
|
+
}
|
|
543
|
+
if (input.flagSettingsOverlay !== undefined) {
|
|
544
|
+
await replayClaudeSdkFlagSettings(query, input.flagSettingsOverlay, input.signal);
|
|
545
|
+
}
|
|
546
|
+
if (input.isClosed() || input.signal.aborted) {
|
|
547
|
+
throw input.isClosed() ? new Error("The Claude SDK session is closed") : abortReason(input.signal);
|
|
548
|
+
}
|
|
549
|
+
} catch (error) {
|
|
550
|
+
input.setInFlightClose(undefined);
|
|
551
|
+
input.recordPid(undefined);
|
|
552
|
+
closeHandle();
|
|
553
|
+
throw error;
|
|
554
|
+
}
|
|
555
|
+
input.setInFlightClose(undefined);
|
|
556
|
+
return handle;
|
|
557
|
+
}
|
|
153
558
|
async function openClaudeSdkSession(config, limits, input) {
|
|
154
559
|
const ambient = config.ambient ?? process.env;
|
|
155
560
|
const profile = engineProfile("claude-sdk", input.profile);
|
|
156
561
|
input.signal?.throwIfAborted();
|
|
157
|
-
const sessionId = input.nativeThreadId ??
|
|
562
|
+
const sessionId = input.nativeThreadId ?? randomUUID2();
|
|
158
563
|
const transcript = claudeTranscriptPath2({ home: profile.home, cwd: input.cwd, sessionId });
|
|
159
564
|
let resume = input.nativeThreadId !== undefined && await claudeTranscriptExists(transcript);
|
|
160
565
|
let current;
|
|
566
|
+
let startingTurn = false;
|
|
161
567
|
let closed = false;
|
|
568
|
+
let providerPid;
|
|
569
|
+
let activeModel = config.model;
|
|
570
|
+
let activePermissionMode = config.permissionMode ?? "default";
|
|
571
|
+
let flagSettingsOverlay;
|
|
162
572
|
let running;
|
|
573
|
+
let opening;
|
|
574
|
+
let inFlightClose;
|
|
163
575
|
const shutdown = (reason) => {
|
|
576
|
+
if (closed)
|
|
577
|
+
return;
|
|
164
578
|
closed = true;
|
|
579
|
+
providerPid = undefined;
|
|
165
580
|
const turn = current;
|
|
166
581
|
current = undefined;
|
|
167
582
|
loseEngineTurn(turn, stoppedPermission("The session was closed"), reason);
|
|
583
|
+
const pendingClose = inFlightClose;
|
|
584
|
+
inFlightClose = undefined;
|
|
585
|
+
pendingClose?.();
|
|
168
586
|
const active = running;
|
|
169
587
|
running = undefined;
|
|
170
588
|
active?.close();
|
|
@@ -177,108 +595,128 @@ async function openClaudeSdkSession(config, limits, input) {
|
|
|
177
595
|
getTurn: () => current,
|
|
178
596
|
isClosed: () => closed
|
|
179
597
|
});
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
598
|
+
const ensureQuery = async (startLoopImmediately) => {
|
|
599
|
+
if (closed)
|
|
600
|
+
throw new Error("The Claude SDK session is closed");
|
|
601
|
+
if (running !== undefined) {
|
|
602
|
+
if (startLoopImmediately)
|
|
603
|
+
running.startLoop();
|
|
604
|
+
return running;
|
|
605
|
+
}
|
|
606
|
+
if (opening === undefined) {
|
|
607
|
+
const promise = launchSingleSdkQuery({
|
|
608
|
+
config,
|
|
185
609
|
cwd: input.cwd,
|
|
186
610
|
env: engineEnvironment2(profile, ambient),
|
|
187
|
-
|
|
188
|
-
|
|
611
|
+
profileId: profile.profileId,
|
|
612
|
+
limits,
|
|
613
|
+
sessionId,
|
|
614
|
+
resume,
|
|
615
|
+
activeModel,
|
|
616
|
+
activePermissionMode,
|
|
617
|
+
flagSettingsOverlay,
|
|
618
|
+
signal: linked.signal,
|
|
189
619
|
canUseTool,
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (verdict.kind === "limits") {
|
|
211
|
-
limits.set(profile.profileId, mergeRateLimitEvent2({
|
|
212
|
-
previous: limits.get(profile.profileId),
|
|
213
|
-
windows: claudePlanWindows2(verdict.info),
|
|
214
|
-
now: new Date
|
|
215
|
-
}));
|
|
216
|
-
} else if (verdict.kind === "deltas") {
|
|
217
|
-
for (const delta of verdict.deltas)
|
|
218
|
-
offerTurnDelta(turn?.channel, delta);
|
|
219
|
-
} else if (verdict.kind === "end") {
|
|
220
|
-
endEngineTurn(turn, stoppedPermission("The turn ended"), verdict.deltas);
|
|
620
|
+
isClosed: () => closed,
|
|
621
|
+
getTurn: () => current,
|
|
622
|
+
clearTurn: () => {
|
|
623
|
+
current = undefined;
|
|
624
|
+
},
|
|
625
|
+
setInFlightClose: (fn) => {
|
|
626
|
+
inFlightClose = fn;
|
|
627
|
+
},
|
|
628
|
+
recordPid: (pid) => {
|
|
629
|
+
providerPid = pid;
|
|
630
|
+
},
|
|
631
|
+
onPidExit: (exitedPid) => {
|
|
632
|
+
if (providerPid === exitedPid)
|
|
633
|
+
providerPid = undefined;
|
|
634
|
+
},
|
|
635
|
+
onExit: (exited, error) => {
|
|
636
|
+
const ownsSession = running === exited;
|
|
637
|
+
const turn = ownsSession ? current : undefined;
|
|
638
|
+
if (ownsSession) {
|
|
639
|
+
running = undefined;
|
|
221
640
|
current = undefined;
|
|
222
|
-
|
|
223
|
-
offerTurnDelta(turn?.channel, verdict.delta);
|
|
641
|
+
providerPid = undefined;
|
|
224
642
|
}
|
|
643
|
+
loseEngineTurn(turn, stoppedPermission("The Claude SDK query ended"), error);
|
|
644
|
+
exited.close();
|
|
225
645
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
646
|
+
}).then((handle) => {
|
|
647
|
+
running = handle;
|
|
648
|
+
return handle;
|
|
649
|
+
}).finally(() => {
|
|
650
|
+
if (opening === promise)
|
|
651
|
+
opening = undefined;
|
|
652
|
+
});
|
|
653
|
+
opening = promise;
|
|
654
|
+
}
|
|
655
|
+
const handle = await opening;
|
|
656
|
+
if (startLoopImmediately)
|
|
657
|
+
handle.startLoop();
|
|
238
658
|
return handle;
|
|
239
659
|
};
|
|
660
|
+
if (hasDelegationVerification(config.verifyDelegation)) {
|
|
661
|
+
try {
|
|
662
|
+
await ensureQuery(true);
|
|
663
|
+
} catch (error) {
|
|
664
|
+
shutdown(error);
|
|
665
|
+
linked.abort();
|
|
666
|
+
linked.release();
|
|
667
|
+
throw error;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const startTurn = createSdkStartTurn({
|
|
671
|
+
config,
|
|
672
|
+
sessionId,
|
|
673
|
+
signal: linked.signal,
|
|
674
|
+
isClosed: () => closed,
|
|
675
|
+
getTurn: () => current,
|
|
676
|
+
setTurn: (turn) => {
|
|
677
|
+
current = turn;
|
|
678
|
+
},
|
|
679
|
+
isStarting: () => startingTurn,
|
|
680
|
+
setStarting: (value) => {
|
|
681
|
+
startingTurn = value;
|
|
682
|
+
},
|
|
683
|
+
markResumable: () => {
|
|
684
|
+
resume = true;
|
|
685
|
+
},
|
|
686
|
+
ensureQuery
|
|
687
|
+
});
|
|
688
|
+
const controls = createClaudeSdkControls({
|
|
689
|
+
signal: linked.signal,
|
|
690
|
+
isClosed: () => closed,
|
|
691
|
+
ensureQuery: () => ensureQuery(true),
|
|
692
|
+
setActiveModel: (model) => {
|
|
693
|
+
activeModel = model;
|
|
694
|
+
},
|
|
695
|
+
setActivePermissionMode: (mode) => {
|
|
696
|
+
activePermissionMode = mode;
|
|
697
|
+
},
|
|
698
|
+
recordFlagSettings: (settings) => {
|
|
699
|
+
flagSettingsOverlay = { ...flagSettingsOverlay, ...settings };
|
|
700
|
+
}
|
|
701
|
+
});
|
|
240
702
|
return {
|
|
241
703
|
nativeThreadId: sessionId,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
throw new Error("The Claude SDK session is closed");
|
|
245
|
-
if (current !== undefined)
|
|
246
|
-
throw new Error("A turn is already running in this Claude session");
|
|
247
|
-
const text = extractTextOnlyInput(turnInput.input, "The Agent SDK driver");
|
|
248
|
-
const clientId = turnInput.clientId;
|
|
249
|
-
if (!isUuid(clientId))
|
|
250
|
-
throw new TypeError("The Agent SDK driver needs a UUID client id");
|
|
251
|
-
const turn = {
|
|
252
|
-
state: newClaudeTurnState(turnInput.turnId),
|
|
253
|
-
channel: createTurnDeltaChannel(),
|
|
254
|
-
pending: new Map
|
|
255
|
-
};
|
|
256
|
-
current = turn;
|
|
257
|
-
try {
|
|
258
|
-
const active = running ?? start();
|
|
259
|
-
active.send({
|
|
260
|
-
type: "user",
|
|
261
|
-
message: { role: "user", content: text },
|
|
262
|
-
parent_tool_use_id: null,
|
|
263
|
-
uuid: clientId,
|
|
264
|
-
session_id: sessionId
|
|
265
|
-
});
|
|
266
|
-
return sdkTurnHandle(turn, active.query);
|
|
267
|
-
} catch (error) {
|
|
268
|
-
if (current === turn)
|
|
269
|
-
current = undefined;
|
|
270
|
-
throw error;
|
|
271
|
-
}
|
|
704
|
+
get providerPid() {
|
|
705
|
+
return providerPid;
|
|
272
706
|
},
|
|
707
|
+
startTurn,
|
|
708
|
+
...controls,
|
|
273
709
|
async close() {
|
|
274
|
-
linked.release();
|
|
275
710
|
shutdown(new Error("The Claude SDK session closed"));
|
|
711
|
+
linked.abort();
|
|
712
|
+
linked.release();
|
|
276
713
|
}
|
|
277
714
|
};
|
|
278
715
|
}
|
|
279
716
|
|
|
280
717
|
// src/agent-executor/claude-sdk/driver.ts
|
|
281
718
|
function createClaudeSdkDriver(config) {
|
|
719
|
+
validateClaudeSdkConfig(config);
|
|
282
720
|
const limits = new Map;
|
|
283
721
|
return {
|
|
284
722
|
engine: "claude-sdk",
|
|
@@ -301,7 +739,16 @@ function createClaudeSdkDriver(config) {
|
|
|
301
739
|
};
|
|
302
740
|
},
|
|
303
741
|
findInput: (input) => findTranscriptInput("claude-sdk", input),
|
|
304
|
-
open: (input) => openClaudeSdkSession(config, limits, input)
|
|
742
|
+
open: (input) => openClaudeSdkSession(config, limits, input),
|
|
743
|
+
async forkSession(sessionId, options) {
|
|
744
|
+
if (sessionId.trim().length === 0) {
|
|
745
|
+
throw new TypeError("Claude SDK forkSession requires a non-empty sessionId");
|
|
746
|
+
}
|
|
747
|
+
if (config.forkSession === undefined) {
|
|
748
|
+
throw new Error("Claude SDK driver was not configured with forkSession");
|
|
749
|
+
}
|
|
750
|
+
return config.forkSession(sessionId, options);
|
|
751
|
+
}
|
|
305
752
|
};
|
|
306
753
|
}
|
|
307
754
|
export {
|