@zvada/agent-server 0.3.17 → 0.3.19
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/AGENTS.md +11 -26
- package/CHANGELOG.md +1060 -0
- package/README.md +50 -26
- package/dist/types/accounts/chatgpt.d.ts +34 -0
- package/dist/types/accounts/chatgpt.d.ts.map +1 -0
- package/dist/types/accounts/check.d.ts +24 -0
- package/dist/types/accounts/check.d.ts.map +1 -0
- package/dist/types/accounts/claude.d.ts +21 -0
- package/dist/types/accounts/claude.d.ts.map +1 -0
- package/dist/types/accounts/endpoint.d.ts +50 -0
- package/dist/types/accounts/endpoint.d.ts.map +1 -0
- package/dist/types/accounts/http.d.ts +38 -0
- package/dist/types/accounts/http.d.ts.map +1 -0
- package/dist/types/accounts/index.d.ts +6 -0
- package/dist/types/accounts/index.d.ts.map +1 -0
- package/dist/types/client/client.d.ts +272 -0
- package/dist/types/client/client.d.ts.map +1 -0
- package/dist/types/client/connection.d.ts +160 -0
- package/dist/types/client/connection.d.ts.map +1 -0
- package/dist/types/client/history.d.ts +8 -0
- package/dist/types/client/history.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +5 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/listeners.d.ts +8 -0
- package/dist/types/client/listeners.d.ts.map +1 -0
- package/dist/types/client/logins.d.ts +35 -0
- package/dist/types/client/logins.d.ts.map +1 -0
- package/dist/types/client/rpc.d.ts +46 -0
- package/dist/types/client/rpc.d.ts.map +1 -0
- package/dist/types/client/streams.d.ts +150 -0
- package/dist/types/client/streams.d.ts.map +1 -0
- package/dist/types/client/transports.d.ts +35 -0
- package/dist/types/client/transports.d.ts.map +1 -0
- package/dist/types/client/turns.d.ts +81 -0
- package/dist/types/client/turns.d.ts.map +1 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts +68 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -0
- package/dist/types/core/agents/acp/adapter.d.ts +39 -0
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/acp/client.d.ts +90 -0
- package/dist/types/core/agents/acp/client.d.ts.map +1 -0
- package/dist/types/core/agents/acp/known-agents.d.ts +35 -0
- package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -0
- package/dist/types/core/agents/acp/mappings.d.ts +46 -0
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -0
- package/dist/types/core/agents/acp/requests.d.ts +26 -0
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -0
- package/dist/types/core/agents/attachments.d.ts +11 -0
- package/dist/types/core/agents/attachments.d.ts.map +1 -0
- package/dist/types/core/agents/base.d.ts +227 -0
- package/dist/types/core/agents/base.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts +58 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts +26 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +70 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts +54 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/events.d.ts +42 -0
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/login.d.ts +61 -0
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts +52 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/models.d.ts +30 -0
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/options.d.ts +183 -0
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts +50 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts +36 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +148 -0
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts +29 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spend.d.ts +58 -0
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/tools.d.ts +4 -0
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts +52 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn.d.ts +121 -0
- package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +59 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts +116 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +113 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts +66 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +49 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts +12 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts +45 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts +20 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts +26 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts +31 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts +38 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +62 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts +67 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts +40 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +19 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +99 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts +42 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts +96 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +53 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +87 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +33 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts +163 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -0
- package/dist/types/core/agents/config-fingerprint.d.ts +5 -0
- package/dist/types/core/agents/config-fingerprint.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +28 -0
- package/dist/types/core/agents/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +37 -0
- package/dist/types/core/agents/elicitation.d.ts.map +1 -0
- package/dist/types/core/agents/inherit-config.d.ts +18 -0
- package/dist/types/core/agents/inherit-config.d.ts.map +1 -0
- package/dist/types/core/agents/login.d.ts +67 -0
- package/dist/types/core/agents/login.d.ts.map +1 -0
- package/dist/types/core/agents/mcp-config.d.ts +57 -0
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -0
- package/dist/types/core/agents/plan.d.ts +16 -0
- package/dist/types/core/agents/plan.d.ts.map +1 -0
- package/dist/types/core/agents/registry.d.ts +30 -0
- package/dist/types/core/agents/registry.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +48 -0
- package/dist/types/core/agents/session-agent.d.ts.map +1 -0
- package/dist/types/core/agents/session-pool.d.ts +41 -0
- package/dist/types/core/agents/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/stderr-tail.d.ts +28 -0
- package/dist/types/core/agents/stderr-tail.d.ts.map +1 -0
- package/dist/types/core/agents/thinking-levels.d.ts +4 -0
- package/dist/types/core/agents/thinking-levels.d.ts.map +1 -0
- package/dist/types/core/agents/types.d.ts +124 -0
- package/dist/types/core/agents/types.d.ts.map +1 -0
- package/dist/types/core/diagnostics.d.ts +36 -0
- package/dist/types/core/diagnostics.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +29 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/presets.d.ts +80 -0
- package/dist/types/core/presets.d.ts.map +1 -0
- package/dist/types/core/processes/identity.d.ts +31 -0
- package/dist/types/core/processes/identity.d.ts.map +1 -0
- package/dist/types/core/processes/lifeline.d.ts +47 -0
- package/dist/types/core/processes/lifeline.d.ts.map +1 -0
- package/dist/types/core/processes/native-processes.d.ts +130 -0
- package/dist/types/core/processes/native-processes.d.ts.map +1 -0
- package/dist/types/core/processes/process-table.d.ts +43 -0
- package/dist/types/core/processes/process-table.d.ts.map +1 -0
- package/dist/types/core/provision/cache-trust.d.ts +13 -0
- package/dist/types/core/provision/cache-trust.d.ts.map +1 -0
- package/dist/types/core/provision/cache-usage.d.ts +14 -0
- package/dist/types/core/provision/cache-usage.d.ts.map +1 -0
- package/dist/types/core/provision/checksums.d.ts +46 -0
- package/dist/types/core/provision/checksums.d.ts.map +1 -0
- package/dist/types/core/provision/extract.d.ts +7 -0
- package/dist/types/core/provision/extract.d.ts.map +1 -0
- package/dist/types/core/provision/index.d.ts +5 -0
- package/dist/types/core/provision/index.d.ts.map +1 -0
- package/dist/types/core/provision/install-build.d.ts +36 -0
- package/dist/types/core/provision/install-build.d.ts.map +1 -0
- package/dist/types/core/provision/npm.d.ts +40 -0
- package/dist/types/core/provision/npm.d.ts.map +1 -0
- package/dist/types/core/provision/pins.d.ts +24 -0
- package/dist/types/core/provision/pins.d.ts.map +1 -0
- package/dist/types/core/provision/platform.d.ts +28 -0
- package/dist/types/core/provision/platform.d.ts.map +1 -0
- package/dist/types/core/provision/provisioner.d.ts +189 -0
- package/dist/types/core/provision/provisioner.d.ts.map +1 -0
- package/dist/types/core/provision/releases.d.ts +8 -0
- package/dist/types/core/provision/releases.d.ts.map +1 -0
- package/dist/types/core/provision/tools.d.ts +81 -0
- package/dist/types/core/provision/tools.d.ts.map +1 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts +52 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts.map +1 -0
- package/dist/types/core/proxy/api-key-store.d.ts +37 -0
- package/dist/types/core/proxy/api-key-store.d.ts.map +1 -0
- package/dist/types/core/proxy/index.d.ts +3 -0
- package/dist/types/core/proxy/index.d.ts.map +1 -0
- package/dist/types/core/proxy/loopback.d.ts +14 -0
- package/dist/types/core/proxy/loopback.d.ts.map +1 -0
- package/dist/types/core/runtime/agent-runtime.d.ts +181 -0
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -0
- package/dist/types/core/runtime/event-processor.d.ts +87 -0
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -0
- package/dist/types/core/runtime/event-sink.d.ts +44 -0
- package/dist/types/core/runtime/event-sink.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-clis.d.ts +10 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-logins.d.ts +68 -0
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -0
- package/dist/types/core/runtime/login-reads.d.ts +28 -0
- package/dist/types/core/runtime/login-reads.d.ts.map +1 -0
- package/dist/types/core/runtime/model-lists.d.ts +37 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -0
- package/dist/types/core/runtime/permission-policy.d.ts +61 -0
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -0
- package/dist/types/core/runtime/request-broker.d.ts +49 -0
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -0
- package/dist/types/core/runtime/steering.d.ts +38 -0
- package/dist/types/core/runtime/steering.d.ts.map +1 -0
- package/dist/types/core/runtime/turn-outcome.d.ts +21 -0
- package/dist/types/core/runtime/turn-outcome.d.ts.map +1 -0
- package/dist/types/core/runtime/turn.d.ts +121 -0
- package/dist/types/core/runtime/turn.d.ts.map +1 -0
- package/dist/types/core/utils/bounded.d.ts +6 -0
- package/dist/types/core/utils/bounded.d.ts.map +1 -0
- package/dist/types/core/utils/deadline.d.ts +14 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -0
- package/dist/types/core/utils/errors.d.ts +104 -0
- package/dist/types/core/utils/errors.d.ts.map +1 -0
- package/dist/types/core/utils/is-record.d.ts +3 -0
- package/dist/types/core/utils/is-record.d.ts.map +1 -0
- package/dist/types/core/utils/loopback.d.ts +6 -0
- package/dist/types/core/utils/loopback.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/protocol/account.d.ts +26 -0
- package/dist/types/protocol/account.d.ts.map +1 -0
- package/dist/types/protocol/async-queue.d.ts +21 -0
- package/dist/types/protocol/async-queue.d.ts.map +1 -0
- package/dist/types/protocol/auth.d.ts +228 -0
- package/dist/types/protocol/auth.d.ts.map +1 -0
- package/dist/types/protocol/canonical.d.ts +9 -0
- package/dist/types/protocol/canonical.d.ts.map +1 -0
- package/dist/types/protocol/clis.d.ts +74 -0
- package/dist/types/protocol/clis.d.ts.map +1 -0
- package/dist/types/protocol/config.d.ts +200 -0
- package/dist/types/protocol/config.d.ts.map +1 -0
- package/dist/types/protocol/conversation.d.ts +942 -0
- package/dist/types/protocol/conversation.d.ts.map +1 -0
- package/dist/types/protocol/credentials.d.ts +145 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -0
- package/dist/types/protocol/errors.d.ts +36 -0
- package/dist/types/protocol/errors.d.ts.map +1 -0
- package/dist/types/protocol/execution.d.ts +28 -0
- package/dist/types/protocol/execution.d.ts.map +1 -0
- package/dist/types/protocol/factories.d.ts +94 -0
- package/dist/types/protocol/factories.d.ts.map +1 -0
- package/dist/types/protocol/guards.d.ts +55 -0
- package/dist/types/protocol/guards.d.ts.map +1 -0
- package/dist/types/protocol/harness.d.ts +70 -0
- package/dist/types/protocol/harness.d.ts.map +1 -0
- package/dist/types/protocol/history.d.ts +318 -0
- package/dist/types/protocol/history.d.ts.map +1 -0
- package/dist/types/protocol/ids.d.ts +9 -0
- package/dist/types/protocol/ids.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +35 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/lifecycle.d.ts +1190 -0
- package/dist/types/protocol/lifecycle.d.ts.map +1 -0
- package/dist/types/protocol/meta-keys.d.ts +17 -0
- package/dist/types/protocol/meta-keys.d.ts.map +1 -0
- package/dist/types/protocol/meta.d.ts +13 -0
- package/dist/types/protocol/meta.d.ts.map +1 -0
- package/dist/types/protocol/model-catalog.d.ts +11 -0
- package/dist/types/protocol/model-catalog.d.ts.map +1 -0
- package/dist/types/protocol/models.d.ts +107 -0
- package/dist/types/protocol/models.d.ts.map +1 -0
- package/dist/types/protocol/part-input.d.ts +101 -0
- package/dist/types/protocol/part-input.d.ts.map +1 -0
- package/dist/types/protocol/parts.d.ts +357 -0
- package/dist/types/protocol/parts.d.ts.map +1 -0
- package/dist/types/protocol/reduce.d.ts +26 -0
- package/dist/types/protocol/reduce.d.ts.map +1 -0
- package/dist/types/protocol/selectors.d.ts +64 -0
- package/dist/types/protocol/selectors.d.ts.map +1 -0
- package/dist/types/protocol/seq-cursor.d.ts +66 -0
- package/dist/types/protocol/seq-cursor.d.ts.map +1 -0
- package/dist/types/protocol/stop-reasons.d.ts +33 -0
- package/dist/types/protocol/stop-reasons.d.ts.map +1 -0
- package/dist/types/protocol/thinking.d.ts +28 -0
- package/dist/types/protocol/thinking.d.ts.map +1 -0
- package/dist/types/protocol/time.d.ts +21 -0
- package/dist/types/protocol/time.d.ts.map +1 -0
- package/dist/types/protocol/tokens.d.ts +29 -0
- package/dist/types/protocol/tokens.d.ts.map +1 -0
- package/dist/types/protocol/tool-closure.d.ts +25 -0
- package/dist/types/protocol/tool-closure.d.ts.map +1 -0
- package/dist/types/protocol/tool-state.d.ts +209 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -0
- package/dist/types/protocol/verify.d.ts +52 -0
- package/dist/types/protocol/verify.d.ts.map +1 -0
- package/dist/types/protocol/vocabulary.d.ts +19 -0
- package/dist/types/protocol/vocabulary.d.ts.map +1 -0
- package/dist/types/protocol/wire-api.d.ts +1983 -0
- package/dist/types/protocol/wire-api.d.ts.map +1 -0
- package/dist/types/protocol/wire.d.ts +1758 -0
- package/dist/types/protocol/wire.d.ts.map +1 -0
- package/dist/types/server/acp/binding.d.ts +33 -0
- package/dist/types/server/acp/binding.d.ts.map +1 -0
- package/dist/types/server/acp/session-records.d.ts +17 -0
- package/dist/types/server/acp/session-records.d.ts.map +1 -0
- package/dist/types/server/acp/translate.d.ts +48 -0
- package/dist/types/server/acp/translate.d.ts.map +1 -0
- package/dist/types/server/agent-server.d.ts +121 -0
- package/dist/types/server/agent-server.d.ts.map +1 -0
- package/dist/types/server/feedback.d.ts +37 -0
- package/dist/types/server/feedback.d.ts.map +1 -0
- package/dist/types/server/history.d.ts +15 -0
- package/dist/types/server/history.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +7 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/server/install.d.ts +42 -0
- package/dist/types/server/install.d.ts.map +1 -0
- package/dist/types/server/open-parts.d.ts +27 -0
- package/dist/types/server/open-parts.d.ts.map +1 -0
- package/dist/types/server/routes.d.ts +61 -0
- package/dist/types/server/routes.d.ts.map +1 -0
- package/dist/types/server/secrets.d.ts +11 -0
- package/dist/types/server/secrets.d.ts.map +1 -0
- package/dist/types/server/session-gate.d.ts +32 -0
- package/dist/types/server/session-gate.d.ts.map +1 -0
- package/dist/types/server/session-log.d.ts +39 -0
- package/dist/types/server/session-log.d.ts.map +1 -0
- package/dist/types/server/session-store.d.ts +119 -0
- package/dist/types/server/session-store.d.ts.map +1 -0
- package/dist/types/server/subscriptions.d.ts +74 -0
- package/dist/types/server/subscriptions.d.ts.map +1 -0
- package/dist/types/server/transports.d.ts +74 -0
- package/dist/types/server/transports.d.ts.map +1 -0
- package/dist/types/server/wire-error.d.ts +9 -0
- package/dist/types/server/wire-error.d.ts.map +1 -0
- package/dist/types/sync/event-log.d.ts +45 -0
- package/dist/types/sync/event-log.d.ts.map +1 -0
- package/dist/types/sync/fit.d.ts +40 -0
- package/dist/types/sync/fit.d.ts.map +1 -0
- package/dist/types/sync/history-reader.d.ts +8 -0
- package/dist/types/sync/history-reader.d.ts.map +1 -0
- package/dist/types/sync/history-sqlite.d.ts +37 -0
- package/dist/types/sync/history-sqlite.d.ts.map +1 -0
- package/dist/types/sync/history.d.ts +70 -0
- package/dist/types/sync/history.d.ts.map +1 -0
- package/dist/types/sync/index.d.ts +4 -0
- package/dist/types/sync/index.d.ts.map +1 -0
- package/dist/types/sync/journal-sqlite.d.ts +51 -0
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -0
- package/dist/types/sync/journal.d.ts +107 -0
- package/dist/types/sync/journal.d.ts.map +1 -0
- package/dist/types/sync/live-tails.d.ts +30 -0
- package/dist/types/sync/live-tails.d.ts.map +1 -0
- package/dist/types/sync/node-sqlite.d.ts +7 -0
- package/dist/types/sync/node-sqlite.d.ts.map +1 -0
- package/dist/types/sync/projection.d.ts +10 -0
- package/dist/types/sync/projection.d.ts.map +1 -0
- package/dist/types/sync/recovery.d.ts +25 -0
- package/dist/types/sync/recovery.d.ts.map +1 -0
- package/dist/types/sync/retry.d.ts +25 -0
- package/dist/types/sync/retry.d.ts.map +1 -0
- package/dist/types/sync/schema.d.ts +4 -0
- package/dist/types/sync/schema.d.ts.map +1 -0
- package/dist/types/sync/sql.d.ts +38 -0
- package/dist/types/sync/sql.d.ts.map +1 -0
- package/dist/types/sync/sqlite-file.d.ts +9 -0
- package/dist/types/sync/sqlite-file.d.ts.map +1 -0
- package/dist/types/sync/sqlite.d.ts +6 -0
- package/dist/types/sync/sqlite.d.ts.map +1 -0
- package/dist/types/sync/worker.d.ts +63 -0
- package/dist/types/sync/worker.d.ts.map +1 -0
- package/docs/consuming.md +460 -54
- package/docs/deploy.md +218 -47
- package/docs/durable-sessions.md +195 -0
- package/docs/feedback.md +116 -0
- package/docs/harnesses.md +219 -87
- package/docs/sync-history.md +197 -0
- package/docs/sync-integration.md +119 -0
- package/package.json +53 -23
- package/src/accounts/chatgpt.ts +194 -0
- package/src/accounts/check.ts +112 -0
- package/src/accounts/claude.ts +111 -0
- package/src/accounts/endpoint.ts +151 -0
- package/src/accounts/http.ts +97 -0
- package/src/accounts/index.ts +19 -0
- package/src/client/client.ts +641 -602
- package/src/client/connection.ts +371 -0
- package/src/client/history.ts +65 -0
- package/src/client/index.ts +11 -2
- package/src/client/listeners.ts +20 -0
- package/src/client/logins.ts +105 -0
- package/src/client/rpc.ts +144 -0
- package/src/client/streams.ts +488 -0
- package/src/client/transports.ts +62 -8
- package/src/client/turns.ts +171 -0
- package/src/core/agents/acp/acp-agent.ts +94 -118
- package/src/core/agents/acp/adapter.ts +20 -9
- package/src/core/agents/acp/client.ts +125 -47
- package/src/core/agents/acp/known-agents.ts +36 -4
- package/src/core/agents/acp/mappings.ts +64 -18
- package/src/core/agents/acp/requests.ts +125 -0
- package/src/core/agents/attachments.ts +18 -0
- package/src/core/agents/base.ts +120 -42
- package/src/core/agents/claude-code/adapter.ts +177 -238
- package/src/core/agents/claude-code/approvals.ts +270 -0
- package/src/core/agents/claude-code/claude-agent.ts +175 -158
- package/src/core/agents/claude-code/credentials.ts +171 -0
- package/src/core/agents/claude-code/events.ts +55 -0
- package/src/core/agents/claude-code/login.ts +269 -0
- package/src/core/agents/claude-code/mcp.ts +206 -0
- package/src/core/agents/claude-code/models.ts +15 -9
- package/src/core/agents/claude-code/options.ts +326 -39
- package/src/core/agents/claude-code/outcome.ts +209 -0
- package/src/core/agents/claude-code/session-pool.ts +136 -0
- package/src/core/agents/claude-code/session.ts +513 -0
- package/src/core/agents/claude-code/spawn.ts +144 -0
- package/src/core/agents/claude-code/spend.ts +160 -0
- package/src/core/agents/claude-code/tools.ts +47 -0
- package/src/core/agents/claude-code/turn-usage.ts +135 -0
- package/src/core/agents/claude-code/turn.ts +232 -0
- package/src/core/agents/codex-app-server/adapter.ts +314 -117
- package/src/core/agents/codex-app-server/client.ts +186 -84
- package/src/core/agents/codex-app-server/codex-agent.ts +343 -0
- package/src/core/agents/codex-app-server/commands.ts +228 -0
- package/src/core/agents/codex-app-server/credentials.ts +126 -0
- package/src/core/agents/codex-app-server/effort.ts +29 -0
- package/src/core/agents/codex-app-server/events.ts +47 -0
- package/src/core/agents/codex-app-server/homes.ts +64 -0
- package/src/core/agents/codex-app-server/input.ts +60 -0
- package/src/core/agents/codex-app-server/items.ts +149 -0
- package/src/core/agents/codex-app-server/login.ts +180 -0
- package/src/core/agents/codex-app-server/mcp.ts +182 -37
- package/src/core/agents/codex-app-server/models.ts +99 -46
- package/src/core/agents/codex-app-server/options.ts +146 -0
- package/src/core/agents/codex-app-server/plan-approval.ts +135 -0
- package/src/core/agents/codex-app-server/protocol.ts +117 -0
- package/src/core/agents/codex-app-server/requests.ts +332 -0
- package/src/core/agents/codex-app-server/session.ts +285 -0
- package/src/core/agents/codex-app-server/subagents.ts +108 -42
- package/src/core/agents/codex-app-server/thread-settings.ts +279 -0
- package/src/core/agents/codex-app-server/turn-items.ts +88 -0
- package/src/core/agents/codex-app-server/turn.ts +463 -0
- package/src/core/agents/config-fingerprint.ts +7 -14
- package/src/core/agents/credentials.ts +98 -0
- package/src/core/agents/elicitation.ts +75 -0
- package/src/core/agents/inherit-config.ts +21 -0
- package/src/core/agents/login.ts +116 -0
- package/src/core/agents/mcp-config.ts +112 -8
- package/src/core/agents/plan.ts +25 -0
- package/src/core/agents/registry.ts +21 -4
- package/src/core/agents/session-agent.ts +96 -4
- package/src/core/agents/{session-store.ts → session-pool.ts} +11 -5
- package/src/core/agents/stderr-tail.ts +75 -0
- package/src/core/agents/types.ts +40 -5
- package/src/core/index.ts +60 -48
- package/src/core/presets.ts +100 -39
- package/src/core/processes/identity.ts +113 -0
- package/src/core/processes/lifeline.ts +170 -0
- package/src/core/processes/native-processes.ts +379 -0
- package/src/core/processes/process-table.ts +174 -0
- package/src/core/provision/cache-trust.ts +121 -0
- package/src/core/provision/cache-usage.ts +69 -0
- package/src/core/provision/checksums.ts +64 -0
- package/src/core/provision/extract.ts +11 -2
- package/src/core/provision/index.ts +4 -1
- package/src/core/provision/install-build.ts +136 -0
- package/src/core/provision/npm.ts +112 -17
- package/src/core/provision/pins.ts +11 -34
- package/src/core/provision/platform.ts +12 -1
- package/src/core/provision/provisioner.ts +329 -397
- package/src/core/provision/releases.ts +86 -0
- package/src/core/provision/tools.ts +329 -0
- package/src/core/proxy/anthropic-proxy.ts +55 -25
- package/src/core/proxy/api-key-store.ts +2 -12
- package/src/core/proxy/loopback.ts +106 -0
- package/src/core/runtime/agent-runtime.ts +340 -481
- package/src/core/runtime/event-processor.ts +207 -75
- package/src/core/runtime/event-sink.ts +45 -2
- package/src/core/runtime/harness-clis.ts +61 -0
- package/src/core/runtime/harness-logins.ts +328 -0
- package/src/core/runtime/login-reads.ts +78 -0
- package/src/core/runtime/model-lists.ts +57 -57
- package/src/core/runtime/permission-policy.ts +113 -0
- package/src/core/runtime/request-broker.ts +204 -0
- package/src/core/runtime/steering.ts +112 -0
- package/src/core/runtime/turn-outcome.ts +30 -0
- package/src/core/runtime/turn.ts +360 -0
- package/src/core/utils/bounded.ts +12 -0
- package/src/core/utils/deadline.ts +38 -0
- package/src/core/utils/errors.ts +113 -21
- package/src/core/utils/is-record.ts +4 -0
- package/src/core/utils/loopback.ts +10 -0
- package/src/protocol/account.ts +104 -0
- package/src/protocol/auth.ts +199 -0
- package/src/protocol/canonical.ts +16 -0
- package/src/protocol/clis.ts +69 -0
- package/src/protocol/config.ts +60 -6
- package/src/protocol/conversation.ts +272 -0
- package/src/protocol/credentials.ts +145 -0
- package/src/protocol/errors.ts +78 -20
- package/src/protocol/execution.ts +5 -2
- package/src/protocol/factories.ts +55 -7
- package/src/protocol/guards.ts +55 -2
- package/src/protocol/harness.ts +56 -6
- package/src/protocol/history.ts +275 -0
- package/src/protocol/ids.ts +4 -17
- package/src/protocol/index.ts +10 -0
- package/src/protocol/lifecycle.ts +250 -79
- package/src/protocol/meta-keys.ts +17 -0
- package/src/protocol/meta.ts +3 -3
- package/src/protocol/models.ts +2 -43
- package/src/protocol/part-input.ts +2 -1
- package/src/protocol/parts.ts +12 -3
- package/src/protocol/reduce.ts +302 -413
- package/src/protocol/selectors.ts +1 -20
- package/src/protocol/seq-cursor.ts +14 -0
- package/src/protocol/stop-reasons.ts +1 -1
- package/src/protocol/thinking.ts +1 -30
- package/src/protocol/time.ts +2 -2
- package/src/protocol/tool-closure.ts +93 -0
- package/src/protocol/tool-state.ts +19 -4
- package/src/protocol/verify.ts +222 -92
- package/src/protocol/vocabulary.ts +21 -5
- package/src/protocol/wire-api.ts +232 -0
- package/src/protocol/wire.ts +425 -57
- package/src/server/acp/binding.ts +63 -103
- package/src/server/acp/session-records.ts +53 -0
- package/src/server/acp/translate.ts +129 -20
- package/src/server/agent-server.ts +275 -366
- package/src/server/bin.ts +295 -72
- package/src/server/feedback.ts +204 -14
- package/src/server/history.ts +160 -0
- package/src/server/index.ts +4 -8
- package/src/server/install.ts +107 -8
- package/src/server/open-parts.ts +95 -0
- package/src/server/routes.ts +391 -0
- package/src/server/secrets.ts +24 -0
- package/src/server/session-gate.ts +69 -0
- package/src/server/session-log.ts +14 -2
- package/src/server/session-store.ts +289 -0
- package/src/server/subscriptions.ts +232 -0
- package/src/server/transports.ts +125 -25
- package/src/server/wire-error.ts +38 -0
- package/src/sync/event-log.ts +160 -0
- package/src/sync/fit.ts +140 -0
- package/src/sync/history-reader.ts +57 -0
- package/src/sync/history-sqlite.ts +339 -0
- package/src/sync/history.ts +220 -0
- package/src/sync/index.ts +18 -0
- package/src/sync/journal-sqlite.ts +439 -0
- package/src/sync/journal.ts +132 -0
- package/src/sync/live-tails.ts +107 -0
- package/src/sync/node-sqlite.ts +20 -0
- package/src/sync/projection.ts +35 -0
- package/src/sync/recovery.ts +141 -0
- package/src/sync/retry.ts +49 -0
- package/src/sync/schema.ts +77 -0
- package/src/sync/sql.ts +106 -0
- package/src/sync/sqlite-file.ts +38 -0
- package/src/sync/sqlite.ts +21 -0
- package/src/sync/worker.ts +259 -0
- package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
- package/docs/rfds/0002-native-subagents.md +0 -197
- package/src/core/agents/claude-code/generator-session.ts +0 -572
- package/src/core/agents/claude-code/session-manager.ts +0 -166
- package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
- package/src/core/agents/codex-items.ts +0 -149
- package/src/core/agents/codex-sdk/adapter.ts +0 -237
- package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
- package/src/core/agents/tool-meta.ts +0 -68
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { McpSetServersResult } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import type { McpServerConfig } from "../../../protocol/index.ts";
|
|
3
|
+
import {
|
|
4
|
+
type ClaudeCodeAgentOptions,
|
|
5
|
+
type ClaudeSessionConfig,
|
|
6
|
+
type ClaudeSessionSettings,
|
|
7
|
+
claudeSpawnKey,
|
|
8
|
+
} from "./options.ts";
|
|
9
|
+
import { ClaudeSession } from "./session.ts";
|
|
10
|
+
|
|
11
|
+
/** The selected session and whether this invocation owns its new startup. */
|
|
12
|
+
export interface ClaudeSessionSpawn {
|
|
13
|
+
session: ClaudeSession;
|
|
14
|
+
spawned: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether the live `session` cannot serve a turn asking for `config`: what its
|
|
19
|
+
* process was started with changed, the turn names another conversation (a
|
|
20
|
+
* warm process cannot switch), or host suspension left it a stale network pool.
|
|
21
|
+
*/
|
|
22
|
+
function mustReplace(session: ClaudeSession, config: ClaudeSessionConfig): boolean {
|
|
23
|
+
const otherConversation =
|
|
24
|
+
Boolean(config.resumeSessionId) &&
|
|
25
|
+
config.resumeSessionId !== session.currentSessionId &&
|
|
26
|
+
config.resumeSessionId !== session.currentConfig.resumeSessionId;
|
|
27
|
+
return (
|
|
28
|
+
otherConversation || session.mcp.respawnRequired || session.spawnKey !== claudeSpawnKey(config)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Switch what the live process can switch: its model, its permission mode, its MCP servers. */
|
|
33
|
+
async function hotSwap(session: ClaudeSession, next: ClaudeSessionConfig): Promise<void> {
|
|
34
|
+
if (next.model !== session.currentConfig.model) await session.setModel(next.model);
|
|
35
|
+
if ((next.permissionMode ?? "default") !== (session.currentConfig.permissionMode ?? "default")) {
|
|
36
|
+
await session.setPermissionMode(next.permissionMode);
|
|
37
|
+
}
|
|
38
|
+
// Text-only sessions must stay tool-free when the MCP configuration changes.
|
|
39
|
+
if (!next.disableTools && session.mcp.needsUpdate(next.mcpServers)) {
|
|
40
|
+
await session.setMcpServers(next.mcpServers ?? {});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* One live `ClaudeSession` per logical session id. Decides, per turn, whether
|
|
46
|
+
* the existing session can be reused (hot-swapping model, mode and MCP) or
|
|
47
|
+
* must be replaced by a new process that resumes the conversation.
|
|
48
|
+
*/
|
|
49
|
+
export class ClaudeSessionPool {
|
|
50
|
+
private readonly sessions = new Map<string, ClaudeSession>();
|
|
51
|
+
/** Started before the login last changed: the next turn replaces the process. */
|
|
52
|
+
private readonly priorLogin = new WeakSet<ClaudeSession>();
|
|
53
|
+
|
|
54
|
+
constructor(
|
|
55
|
+
private readonly settings: ClaudeSessionSettings & Pick<ClaudeCodeAgentOptions, "onSessionEnd">,
|
|
56
|
+
) {}
|
|
57
|
+
|
|
58
|
+
async getOrCreate(sessionId: string, config: ClaudeSessionConfig): Promise<ClaudeSessionSpawn> {
|
|
59
|
+
const existing = this.sessions.get(sessionId);
|
|
60
|
+
let replaced: ClaudeSession | undefined;
|
|
61
|
+
// One ending meanwhile (idle eviction) is stopped before another
|
|
62
|
+
// process resumes its conversation (LLP 0001, D10).
|
|
63
|
+
if (existing?.currentState === "terminated") await existing.terminate();
|
|
64
|
+
else if (existing) {
|
|
65
|
+
if (!mustReplace(existing, config) && !this.priorLogin.has(existing)) {
|
|
66
|
+
await hotSwap(existing, config);
|
|
67
|
+
return { session: existing, spawned: false };
|
|
68
|
+
}
|
|
69
|
+
// Host suspension invalidates the process-wide HTTP pool, including
|
|
70
|
+
// sockets for removed MCP servers. Use the same strict saved-history
|
|
71
|
+
// resume as idle eviction, with the next turn's prepared config.
|
|
72
|
+
await existing.terminate("replaced");
|
|
73
|
+
this.sessions.delete(sessionId);
|
|
74
|
+
replaced = existing;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const session = new ClaudeSession(sessionId, config, this.settings, (reason) => {
|
|
78
|
+
if (this.sessions.get(sessionId) === session) this.sessions.delete(sessionId);
|
|
79
|
+
this.settings.onSessionEnd?.(sessionId, reason);
|
|
80
|
+
});
|
|
81
|
+
// The same native conversation continues in a new process, and so does
|
|
82
|
+
// its running cost: the new process restores the total the old one saved.
|
|
83
|
+
if (replaced?.currentSessionId && replaced.currentSessionId === config.resumeSessionId)
|
|
84
|
+
session.spend.continueFrom(replaced.spend);
|
|
85
|
+
this.sessions.set(sessionId, session);
|
|
86
|
+
try {
|
|
87
|
+
await session.start();
|
|
88
|
+
} catch (err) {
|
|
89
|
+
// Don't leave a half-started session in the map — it could never serve a turn.
|
|
90
|
+
await session.terminate();
|
|
91
|
+
if (this.sessions.get(sessionId) === session) this.sessions.delete(sessionId);
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
return { session, spawned: true };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get(sessionId: string): ClaudeSession | undefined {
|
|
98
|
+
return this.sessions.get(sessionId);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async terminate(sessionId: string): Promise<void> {
|
|
102
|
+
const session = this.sessions.get(sessionId);
|
|
103
|
+
if (!session) return;
|
|
104
|
+
await session.terminate();
|
|
105
|
+
if (this.sessions.get(sessionId) === session) this.sessions.delete(sessionId);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async terminateAll(): Promise<void> {
|
|
109
|
+
await Promise.all([...this.sessions.values()].map((s) => s.terminate("shutdown")));
|
|
110
|
+
this.sessions.clear();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
invalidateMcpConnections(): void {
|
|
114
|
+
for (const session of this.sessions.values()) session.invalidateMcpConnections();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** A running CLI keeps the credentials it started with: each session's next turn starts a new one. */
|
|
118
|
+
loginChanged(): void {
|
|
119
|
+
for (const session of this.sessions.values()) this.priorLogin.add(session);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Explicit live MCP swap (e.g. mid-conversation app registration). NOTE:
|
|
124
|
+
* this syncs the session's servers, so the NEXT turn's wire config (if it
|
|
125
|
+
* still carries the old server set) will swap back — explicit swappers
|
|
126
|
+
* must keep their per-turn `mcpServers` in step.
|
|
127
|
+
*/
|
|
128
|
+
async setMcpServers(
|
|
129
|
+
sessionId: string,
|
|
130
|
+
servers: Record<string, McpServerConfig>,
|
|
131
|
+
): Promise<McpSetServersResult | undefined> {
|
|
132
|
+
const session = this.sessions.get(sessionId);
|
|
133
|
+
if (!session || session.currentState === "terminated") return undefined;
|
|
134
|
+
return session.setMcpServers(servers);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import type { UUID } from "node:crypto";
|
|
2
|
+
import type {
|
|
3
|
+
McpSetServersResult,
|
|
4
|
+
Query,
|
|
5
|
+
SDKControlInterruptResponse,
|
|
6
|
+
SDKMessage,
|
|
7
|
+
SDKRateLimitEvent,
|
|
8
|
+
SDKResultMessage,
|
|
9
|
+
SDKUserMessage,
|
|
10
|
+
} from "@anthropic-ai/claude-agent-sdk";
|
|
11
|
+
import { AsyncQueue, generateUUIDv7 } from "../../../protocol/index.ts";
|
|
12
|
+
import type { McpServerConfig, PermissionMode } from "../../../protocol/index.ts";
|
|
13
|
+
import type { NativeProcess } from "../../processes/native-processes.ts";
|
|
14
|
+
import { withTimeout } from "../../utils/deadline.ts";
|
|
15
|
+
import { SessionResumeError } from "../../utils/errors.ts";
|
|
16
|
+
import { IDLE_TIMEOUT_MS } from "../session-pool.ts";
|
|
17
|
+
import { createCanUseTool, createOnElicitation } from "./approvals.ts";
|
|
18
|
+
import { commandStarted } from "./events.ts";
|
|
19
|
+
import { ClaudeMcpConnections } from "./mcp.ts";
|
|
20
|
+
import {
|
|
21
|
+
type ClaudeSessionConfig,
|
|
22
|
+
type ClaudeSessionEndReason,
|
|
23
|
+
type ClaudeSessionSettings,
|
|
24
|
+
buildClaudeOptions,
|
|
25
|
+
claudeSpawnKey,
|
|
26
|
+
fromSdkPermissionMode,
|
|
27
|
+
toSdkPermissionMode,
|
|
28
|
+
} from "./options.ts";
|
|
29
|
+
import { planUsedUp } from "./outcome.ts";
|
|
30
|
+
import { withStderr } from "./spawn.ts";
|
|
31
|
+
import { ClaudeSpend } from "./spend.ts";
|
|
32
|
+
import { ClaudeTurn, type ClaudeTurnStart } from "./turn.ts";
|
|
33
|
+
|
|
34
|
+
type SessionState = "starting" | "idle" | "busy" | "terminated";
|
|
35
|
+
type ClaudeContent = SDKUserMessage["message"]["content"];
|
|
36
|
+
|
|
37
|
+
/** How long Claude has to confirm an interrupt before the turn counts as still running. */
|
|
38
|
+
export const INTERRUPT_TIMEOUT_MS = 2_000;
|
|
39
|
+
|
|
40
|
+
/** Claude repeats a message it was sent, where it reads it (`--replay-user-messages`). */
|
|
41
|
+
function isReplay(event: SDKMessage): event is Extract<SDKMessage, { isReplay: true }> {
|
|
42
|
+
return event.type === "user" && "isReplay" in event && event.isReplay === true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The messages a frame says its query consumed. */
|
|
46
|
+
function consumed(event: SDKMessage): readonly string[] {
|
|
47
|
+
return ("user_message_uuids" in event && event.user_message_uuids) || [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Wraps one long-lived Claude `query()` call. The prompt input is an AsyncQueue
|
|
52
|
+
* that stays open across turns, so the same subprocess (and its context) is
|
|
53
|
+
* reused turn to turn. A background loop reads SDK output, learns what it says
|
|
54
|
+
* of the session (`observe`) and hands it to the running turn (`route`); the
|
|
55
|
+
* `result` answering the turn ends it.
|
|
56
|
+
*
|
|
57
|
+
* Lifecycle: starting → idle ⇄ busy → terminated.
|
|
58
|
+
*/
|
|
59
|
+
export class ClaudeSession {
|
|
60
|
+
private state: SessionState = "starting";
|
|
61
|
+
/** What the session runs with; its MCP servers are `mcp`'s. */
|
|
62
|
+
private config: Omit<ClaudeSessionConfig, "mcpServers">;
|
|
63
|
+
/** What the process was started with and cannot change (`claudeSpawnKey`). */
|
|
64
|
+
readonly spawnKey: string;
|
|
65
|
+
readonly mcp: ClaudeMcpConnections;
|
|
66
|
+
/** What the conversation has spent, across the processes that ran it. */
|
|
67
|
+
readonly spend: ClaudeSpend;
|
|
68
|
+
|
|
69
|
+
private readonly promptQueue = new AsyncQueue<SDKUserMessage>();
|
|
70
|
+
private query?: Query;
|
|
71
|
+
private nativeSessionId: string | null = null;
|
|
72
|
+
/** Set by the CLI's first message; until then it has begun no turn. */
|
|
73
|
+
private cliStarted = false;
|
|
74
|
+
private startupError: unknown;
|
|
75
|
+
/** The operator's `sdkOptions` set the effort or thinking, not the engine. */
|
|
76
|
+
private thinkingOverridden = false;
|
|
77
|
+
/** The running turn: where its events go, and what its requests ask. */
|
|
78
|
+
private turn: ClaudeTurn | null = null;
|
|
79
|
+
/** The CLI can drop queued messages with its interrupt (`interrupt_cancel_queued_v1`). */
|
|
80
|
+
private cancelsQueued = false;
|
|
81
|
+
/** A query has begun in this process: before one, nothing of Claude's own can run. */
|
|
82
|
+
private queryBegun = false;
|
|
83
|
+
/**
|
|
84
|
+
* Each plan window's last report. Claude repeats a rejection only when it
|
|
85
|
+
* changes, so a turn after a used-up window starts from that report.
|
|
86
|
+
*/
|
|
87
|
+
private readonly planWindows = new Map<string, SDKRateLimitEvent>();
|
|
88
|
+
private idleTimer?: ReturnType<typeof setTimeout>;
|
|
89
|
+
/** The `claude` process the engine started for it; none under an operator's spawner. */
|
|
90
|
+
private native?: NativeProcess;
|
|
91
|
+
/** Its end, once it began: settles when its process is stopped. */
|
|
92
|
+
private ending?: Promise<void>;
|
|
93
|
+
|
|
94
|
+
constructor(
|
|
95
|
+
readonly id: string,
|
|
96
|
+
config: ClaudeSessionConfig,
|
|
97
|
+
private readonly settings: ClaudeSessionSettings,
|
|
98
|
+
private readonly onTerminated?: (reason: ClaudeSessionEndReason) => void,
|
|
99
|
+
) {
|
|
100
|
+
const { mcpServers, ...spawn } = config;
|
|
101
|
+
this.config = spawn;
|
|
102
|
+
this.spawnKey = claudeSpawnKey(config);
|
|
103
|
+
this.mcp = new ClaudeMcpConnections(mcpServers);
|
|
104
|
+
this.spend = config.resumeSessionId ? ClaudeSpend.unknown() : ClaudeSpend.fresh();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
get currentState(): SessionState {
|
|
108
|
+
return this.state;
|
|
109
|
+
}
|
|
110
|
+
get currentSessionId(): string | null {
|
|
111
|
+
return this.nativeSessionId;
|
|
112
|
+
}
|
|
113
|
+
get currentConfig(): Readonly<Omit<ClaudeSessionConfig, "mcpServers">> {
|
|
114
|
+
return this.config;
|
|
115
|
+
}
|
|
116
|
+
/** Whether the operator's `sdkOptions` chose the thinking settings this session runs. */
|
|
117
|
+
get operatorThinking(): boolean {
|
|
118
|
+
return this.thinkingOverridden;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Hot-swap the model without losing context (Claude `setModel`). */
|
|
122
|
+
async setModel(model: string | undefined): Promise<void> {
|
|
123
|
+
if (this.state === "terminated" || !this.query) return;
|
|
124
|
+
await this.query.setModel(model);
|
|
125
|
+
this.config = { ...this.config, model };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Switch the permission mode without a restart (plan, default, accept edits,
|
|
130
|
+
* don't ask). Bypass needs its flag at spawn, so the pool restarts for it.
|
|
131
|
+
*/
|
|
132
|
+
async setPermissionMode(mode: PermissionMode | undefined): Promise<void> {
|
|
133
|
+
if (this.state === "terminated" || !this.query) return;
|
|
134
|
+
await this.query.setPermissionMode(toSdkPermissionMode(mode) ?? "default");
|
|
135
|
+
this.config = { ...this.config, permissionMode: mode };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Hot-swap the wire-configured MCP servers on the LIVE session (no restart,
|
|
140
|
+
* context intact). In-process servers are re-merged so a swap can never drop
|
|
141
|
+
* the host's own tools. A text-only session stays tool-free.
|
|
142
|
+
*/
|
|
143
|
+
setMcpServers(
|
|
144
|
+
servers: Record<string, McpServerConfig>,
|
|
145
|
+
): Promise<McpSetServersResult | undefined> {
|
|
146
|
+
return this.mcp.update(servers, () =>
|
|
147
|
+
this.config.disableTools || this.state === "terminated" ? undefined : this.query,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Host suspension: the next turn resumes the saved conversation in a new process. */
|
|
152
|
+
invalidateMcpConnections(): void {
|
|
153
|
+
this.mcp.invalidate();
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async start(): Promise<void> {
|
|
157
|
+
if (this.state !== "starting") throw new Error(`Cannot start in state: ${this.state}`);
|
|
158
|
+
const sdk = await import("@anthropic-ai/claude-agent-sdk");
|
|
159
|
+
const spawn = { sessionId: this.id, cwd: this.config.cwd };
|
|
160
|
+
const hostServers = await this.settings.sdkMcpServers?.(spawn);
|
|
161
|
+
this.mcp.useHostServers(hostServers);
|
|
162
|
+
const overrides = await this.settings.sdkOptions?.(spawn);
|
|
163
|
+
this.thinkingOverridden = Boolean(
|
|
164
|
+
overrides && ("effort" in overrides || "thinking" in overrides),
|
|
165
|
+
);
|
|
166
|
+
const options = buildClaudeOptions(this.config, hostServers, overrides, {
|
|
167
|
+
processes: this.settings.processes,
|
|
168
|
+
sessionId: this.id,
|
|
169
|
+
onSpawned: (native) => {
|
|
170
|
+
this.native = native;
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
if (this.settings.hooks) {
|
|
174
|
+
options.hooks = this.settings.hooks({
|
|
175
|
+
sessionId: this.id,
|
|
176
|
+
currentTurnId: () => this.turn?.id,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// The SDK's callbacks are fixed at spawn: each asks the turn running when
|
|
180
|
+
// it is called, so a turn's brokers never answer for another.
|
|
181
|
+
const turn = () => this.turn;
|
|
182
|
+
options.canUseTool = createCanUseTool({
|
|
183
|
+
sessionId: this.id,
|
|
184
|
+
policy: this.settings.toolPolicy,
|
|
185
|
+
turn,
|
|
186
|
+
});
|
|
187
|
+
options.onElicitation = createOnElicitation(turn);
|
|
188
|
+
// Release/shutdown may finish while an async options/tool factory is
|
|
189
|
+
// pending. Never create a query after its owner has already terminated.
|
|
190
|
+
if (this.currentState === "terminated") throw new Error("Session terminated during startup");
|
|
191
|
+
this.query = sdk.query({ prompt: this.promptQueue, options });
|
|
192
|
+
const events = this.consumeEvents();
|
|
193
|
+
if (!this.config.disableTools && Object.keys(this.mcp.servers).length) {
|
|
194
|
+
try {
|
|
195
|
+
// Every wire server gets one owner: it is attached here, before the
|
|
196
|
+
// first prompt, never at spawn (`buildClaudeOptions`).
|
|
197
|
+
await this.setMcpServers(this.mcp.servers);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
// A CLI that fails its startup while the servers attach (a
|
|
200
|
+
// conversation it cannot load) says why in a result the SDK delivers
|
|
201
|
+
// only after it rejected the attach: close, and read to the end, so
|
|
202
|
+
// that reason wins.
|
|
203
|
+
await this.terminate();
|
|
204
|
+
await events;
|
|
205
|
+
throw this.startupError ?? error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (this.startupError) throw this.startupError;
|
|
209
|
+
// TypeScript retains the pre-query narrowing across await; termination can
|
|
210
|
+
// happen while the initial MCP attachment is in flight.
|
|
211
|
+
if ((this.state as SessionState) === "terminated")
|
|
212
|
+
throw new Error("Session terminated during startup");
|
|
213
|
+
this.state = "idle";
|
|
214
|
+
this.resetIdleTimer();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Send a turn's prompt: the turn's events stream until its result. One turn
|
|
219
|
+
* runs at a time (LLP 0001, D10): a turn's generator stops its native turn
|
|
220
|
+
* before it releases the session, so the session is idle here.
|
|
221
|
+
*/
|
|
222
|
+
sendMessage(content: ClaudeContent, start: ClaudeTurnStart): ClaudeTurn {
|
|
223
|
+
if (this.state === "terminated") throw this.startupError ?? new Error("Session is terminated");
|
|
224
|
+
if (this.state !== "idle") throw new Error(`Claude session is ${this.state}, not idle`);
|
|
225
|
+
// Invalidation can land during preparation. Never enqueue a prompt on a
|
|
226
|
+
// process whose network pool predates suspension.
|
|
227
|
+
if (this.mcp.respawnRequired || (!this.config.disableTools && this.mcp.uncertain)) {
|
|
228
|
+
throw new Error(
|
|
229
|
+
"MCP network connections changed during turn preparation; session is not ready",
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
this.clearIdleTimer();
|
|
233
|
+
this.state = "busy";
|
|
234
|
+
const prompt = this.userMessage(content);
|
|
235
|
+
const turn = new ClaudeTurn(start, prompt.uuid);
|
|
236
|
+
this.turn = turn;
|
|
237
|
+
for (const report of this.rejectedWindowReports()) turn.events.push(report);
|
|
238
|
+
this.promptQueue.push(prompt);
|
|
239
|
+
return turn;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// @ref LLP 0002#steering — Claude reads a steer at its next step, or runs it next
|
|
243
|
+
/**
|
|
244
|
+
* Send more input into the running turn. Claude reads it after the step it
|
|
245
|
+
* is on (the tool it runs), or, when it was already giving its final
|
|
246
|
+
* answer, runs it as its next query; the turn lasts until that query ends.
|
|
247
|
+
* False when no turn takes input.
|
|
248
|
+
*/
|
|
249
|
+
steer(content: ClaudeContent, steerId: string): boolean {
|
|
250
|
+
if (this.state !== "busy" || !this.turn) return false;
|
|
251
|
+
const message = this.userMessage(content);
|
|
252
|
+
this.turn.sendSteer(message.uuid, steerId);
|
|
253
|
+
this.promptQueue.push(message);
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** The last report of each plan window still used up, and not past its reset. */
|
|
258
|
+
private *rejectedWindowReports(): Generator<SDKRateLimitEvent> {
|
|
259
|
+
const now = Date.now() / 1000;
|
|
260
|
+
for (const [id, report] of this.planWindows) {
|
|
261
|
+
const info = report.rate_limit_info;
|
|
262
|
+
if (!info || !planUsedUp(info)) continue;
|
|
263
|
+
if (info.resetsAt !== undefined && info.resetsAt <= now) this.planWindows.delete(id);
|
|
264
|
+
else yield report;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** A uuid-stamped user message: Claude names it when it replays or consumes it. */
|
|
269
|
+
private userMessage(content: ClaudeContent): SDKUserMessage & { uuid: UUID } {
|
|
270
|
+
return {
|
|
271
|
+
type: "user",
|
|
272
|
+
message: { role: "user", content },
|
|
273
|
+
parent_tool_use_id: null,
|
|
274
|
+
// A UUIDv7 is a UUID: the SDK types it as `crypto.randomUUID()`'s.
|
|
275
|
+
uuid: generateUUIDv7() as UUID,
|
|
276
|
+
...(this.nativeSessionId ? { session_id: this.nativeSessionId } : {}),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Stop the in-flight turn without killing the session. Returns whether the
|
|
282
|
+
* interrupt was CONFIRMED: true when there was nothing to interrupt or the
|
|
283
|
+
* SDK acknowledged it; false when the round-trip timed out or failed — the
|
|
284
|
+
* subprocess may still be running its turn and the caller must report that
|
|
285
|
+
* honestly instead of assuming a clean cancel.
|
|
286
|
+
*
|
|
287
|
+
* A session still starting, or whose CLI has sent nothing yet, is terminated
|
|
288
|
+
* instead: it has begun no turn, an interrupt would wait out its startup, and
|
|
289
|
+
* a prompt the CLI has not dequeued survives an interrupt and runs anyway.
|
|
290
|
+
*/
|
|
291
|
+
interruptTurn(timeoutMs = INTERRUPT_TIMEOUT_MS): Promise<boolean> {
|
|
292
|
+
const turn = this.turn;
|
|
293
|
+
if (!turn) return this.interrupt(undefined, timeoutMs);
|
|
294
|
+
return turn.interruptOnce(() => this.interrupt(turn, timeoutMs));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Stop `turn` unless it ended, for a generator that stopped reading it before
|
|
299
|
+
* its result (a transformer that threw, a sink that failed): interrupt it,
|
|
300
|
+
* and end the process when the turn has not ended within the interrupt
|
|
301
|
+
* timeout. The session is idle or terminated when this returns.
|
|
302
|
+
*/
|
|
303
|
+
async stopTurn(turn: ClaudeTurn, timeoutMs = INTERRUPT_TIMEOUT_MS): Promise<void> {
|
|
304
|
+
if (this.turn !== turn) return;
|
|
305
|
+
await Promise.all([this.interruptTurn(timeoutMs), withTimeout(turn.ended, timeoutMs)]);
|
|
306
|
+
if (this.turn === turn) await this.terminate("replaced");
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
private async interrupt(turn: ClaudeTurn | undefined, timeoutMs: number): Promise<boolean> {
|
|
310
|
+
if (this.state === "idle" || this.state === "terminated") return true;
|
|
311
|
+
if (this.state === "starting" || !this.cliStarted || !this.query) {
|
|
312
|
+
await this.terminate();
|
|
313
|
+
return true;
|
|
314
|
+
}
|
|
315
|
+
if (turn?.mustDropQueued(this.queryBegun)) return await this.interruptQueued(turn, timeoutMs);
|
|
316
|
+
try {
|
|
317
|
+
return (await withTimeout(this.query.interrupt(), timeoutMs)) !== undefined;
|
|
318
|
+
} catch {
|
|
319
|
+
return false; // best-effort dispatched, unconfirmed
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Interrupt and drop the turn's queued messages with the CLI's queue cancel
|
|
325
|
+
* (`ClaudeTurn.mustDropQueued` says why a plain interrupt would not do).
|
|
326
|
+
* Until its receipt they stay tracked, so one Claude reads meanwhile is
|
|
327
|
+
* still shown where it read it, and the turn's end waits. A CLI that cannot
|
|
328
|
+
* cancel queued messages, or does not account for every one, is replaced:
|
|
329
|
+
* the next turn resumes the conversation without them.
|
|
330
|
+
*/
|
|
331
|
+
private async interruptQueued(turn: ClaudeTurn, timeoutMs: number): Promise<boolean> {
|
|
332
|
+
if (!this.cancelsQueued || !this.query) {
|
|
333
|
+
await this.terminate("replaced");
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
turn.dropQueued();
|
|
337
|
+
const verdict = turn.dropped(await this.cancelQueued(this.query, timeoutMs));
|
|
338
|
+
// The turn ended meanwhile, or the session with it.
|
|
339
|
+
if (this.turn !== turn) return true;
|
|
340
|
+
if (verdict === "replace") await this.terminate("replaced");
|
|
341
|
+
else if (verdict === "end") this.endTurn();
|
|
342
|
+
return true;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** The queue cancel's receipt; undefined when none came in time. */
|
|
346
|
+
private async cancelQueued(
|
|
347
|
+
query: Query,
|
|
348
|
+
timeoutMs: number,
|
|
349
|
+
): Promise<SDKControlInterruptResponse | undefined> {
|
|
350
|
+
// The SDK sends `{ cancelQueued }` (0.3.288) but types `interrupt()` without it.
|
|
351
|
+
const cancel = query as Query & {
|
|
352
|
+
interrupt(options: { cancelQueued: true }): Promise<SDKControlInterruptResponse | undefined>;
|
|
353
|
+
};
|
|
354
|
+
try {
|
|
355
|
+
return (await withTimeout(cancel.interrupt({ cancelQueued: true }), timeoutMs))?.value;
|
|
356
|
+
} catch {
|
|
357
|
+
return undefined;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* End the session: close its query, and stop its process with its tool
|
|
363
|
+
* sessions and MCP servers. Settles once they are gone (at most the grace);
|
|
364
|
+
* every call shares that end.
|
|
365
|
+
*/
|
|
366
|
+
terminate(reason: ClaudeSessionEndReason = "released"): Promise<void> {
|
|
367
|
+
this.ending ??= this.end(reason);
|
|
368
|
+
return this.ending;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
private async end(reason: ClaudeSessionEndReason): Promise<void> {
|
|
372
|
+
this.clearIdleTimer();
|
|
373
|
+
this.state = "terminated";
|
|
374
|
+
const query = this.query;
|
|
375
|
+
this.query = undefined;
|
|
376
|
+
this.promptQueue.end();
|
|
377
|
+
this.turn?.end();
|
|
378
|
+
this.turn = null;
|
|
379
|
+
try {
|
|
380
|
+
// The SDK documents close() as the forceful subprocess/MCP cleanup path.
|
|
381
|
+
query?.close();
|
|
382
|
+
// @ref LLP 0007#turn-ownership-d10 — the session is released once its process is gone
|
|
383
|
+
// close() ends its stdin, which Claude reads as "finish, then exit",
|
|
384
|
+
// and signals it two seconds later. SIGTERM now: Claude stops its own
|
|
385
|
+
// tools and MCP servers on it, and the next process to resume the
|
|
386
|
+
// conversation never meets this one still working.
|
|
387
|
+
await this.native?.stop();
|
|
388
|
+
} finally {
|
|
389
|
+
try {
|
|
390
|
+
this.onTerminated?.(reason);
|
|
391
|
+
} catch {
|
|
392
|
+
// Observer failures (incl. the host's onSessionEnd) must never make
|
|
393
|
+
// terminate() reject — the idle timer calls it unawaited.
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
private async consumeEvents(): Promise<void> {
|
|
399
|
+
if (!this.query) return;
|
|
400
|
+
try {
|
|
401
|
+
for await (const event of this.query) {
|
|
402
|
+
this.cliStarted = true;
|
|
403
|
+
this.observe(event);
|
|
404
|
+
this.route(event);
|
|
405
|
+
}
|
|
406
|
+
} catch (thrown) {
|
|
407
|
+
// The SDK words an exit from its own spawner with the CLI's stderr; ours keeps that tail.
|
|
408
|
+
const err = withStderr(thrown, this.native?.stderrTail ?? "");
|
|
409
|
+
if (this.turn) this.turn.fail(err);
|
|
410
|
+
else this.startupError = err;
|
|
411
|
+
} finally {
|
|
412
|
+
await this.terminate();
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** What an event says of the session: its native id, its mode, plan windows, spend, steers read. */
|
|
417
|
+
private observe(event: SDKMessage): void {
|
|
418
|
+
if (event.type === "system" && event.subtype === "init") {
|
|
419
|
+
this.queryBegun = true;
|
|
420
|
+
if (event.session_id) this.nativeSessionId = event.session_id;
|
|
421
|
+
this.cancelsQueued = (event.capabilities ?? []).includes("interrupt_cancel_queued_v1");
|
|
422
|
+
}
|
|
423
|
+
// The mode Claude runs in now: approving a plan switches it mid-turn,
|
|
424
|
+
// so the next turn compares against this, not the mode it asked for.
|
|
425
|
+
if (event.type === "system" && event.subtype === "status") {
|
|
426
|
+
const mode = fromSdkPermissionMode(event.permissionMode);
|
|
427
|
+
if (mode) this.config = { ...this.config, permissionMode: mode };
|
|
428
|
+
}
|
|
429
|
+
if (event.type === "rate_limit_event")
|
|
430
|
+
this.planWindows.set(event.rate_limit_info?.rateLimitType ?? "plan", event);
|
|
431
|
+
if (event.type === "conversation_reset") this.spend.reset();
|
|
432
|
+
// Claude takes a message: a frame names it as started.
|
|
433
|
+
const taken = commandStarted(event);
|
|
434
|
+
if (taken !== undefined) this.turn?.took(taken);
|
|
435
|
+
// Claude replays each message it was sent where it reads it: a steer's
|
|
436
|
+
// replay marks the steer's place. A frame naming the messages its query
|
|
437
|
+
// consumed marks a steer read too, in case its replay never came.
|
|
438
|
+
this.turn?.read(isReplay(event) ? [event.uuid] : consumed(event));
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/** Hand an event to the running turn; a result answering it settles the turn. */
|
|
442
|
+
private route(event: SDKMessage): void {
|
|
443
|
+
// A replay repeats what the session sent; `observe` took its place.
|
|
444
|
+
if (isReplay(event)) return;
|
|
445
|
+
const turn = this.turn;
|
|
446
|
+
if (event.type !== "result") {
|
|
447
|
+
turn?.events.push(event);
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
if (!turn) {
|
|
451
|
+
this.settleUnshown(event);
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
// @ref LLP 0001#d14--nothing-the-agent-does-is-off-the-stream — a query Claude began itself
|
|
455
|
+
// Claude answers a finished background task with a query of its own. Its
|
|
456
|
+
// result is not this turn's end, and its cost stays in the turn whose
|
|
457
|
+
// stream showed it.
|
|
458
|
+
if (!turn.answeredBy(event)) return;
|
|
459
|
+
switch (turn.settle(event, this.spend.charge(event))) {
|
|
460
|
+
case "end":
|
|
461
|
+
this.endTurn();
|
|
462
|
+
break;
|
|
463
|
+
case "await-steers":
|
|
464
|
+
// The turn ends without them if their query never begins, and a new
|
|
465
|
+
// process keeps them out of the next.
|
|
466
|
+
turn.awaitSteerQuery(() => void this.terminate("replaced"));
|
|
467
|
+
break;
|
|
468
|
+
case "hold":
|
|
469
|
+
// The interrupt's receipt decides (`interruptQueued`).
|
|
470
|
+
break;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* A result while no turn runs: Claude failed its startup, or answered a
|
|
476
|
+
* query it began itself between turns. Its spend counts in no turn.
|
|
477
|
+
*/
|
|
478
|
+
private settleUnshown(result: SDKResultMessage): void {
|
|
479
|
+
if (result.subtype !== "success" && result.origin === undefined) {
|
|
480
|
+
const reason = result.errors.join("; ") || "Claude failed during startup";
|
|
481
|
+
throw this.config.resumeSessionId
|
|
482
|
+
? new SessionResumeError(this.config.resumeSessionId, reason, {
|
|
483
|
+
cause: new Error(reason),
|
|
484
|
+
})
|
|
485
|
+
: new Error(reason);
|
|
486
|
+
}
|
|
487
|
+
this.spend.charge(result);
|
|
488
|
+
if (this.state === "idle") this.resetIdleTimer();
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
private endTurn(): void {
|
|
492
|
+
this.turn?.end();
|
|
493
|
+
this.turn = null;
|
|
494
|
+
this.state = "idle";
|
|
495
|
+
this.resetIdleTimer();
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
private resetIdleTimer(): void {
|
|
499
|
+
this.clearIdleTimer();
|
|
500
|
+
const idleTimeoutMs = this.settings.idleTimeoutMs ?? IDLE_TIMEOUT_MS;
|
|
501
|
+
if (idleTimeoutMs > 0) {
|
|
502
|
+
this.idleTimer = setTimeout(() => void this.terminate("idle"), idleTimeoutMs);
|
|
503
|
+
this.idleTimer.unref?.();
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
private clearIdleTimer(): void {
|
|
508
|
+
if (this.idleTimer) {
|
|
509
|
+
clearTimeout(this.idleTimer);
|
|
510
|
+
this.idleTimer = undefined;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|