@zvada/agent-server 0.3.18 → 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 +1005 -1
- package/README.md +35 -39
- 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 +452 -53
- package/docs/deploy.md +218 -47
- package/docs/{sync-experiment.md → durable-sessions.md} +77 -72
- package/docs/feedback.md +116 -0
- package/docs/harnesses.md +212 -88
- package/docs/sync-history.md +29 -13
- package/docs/sync-integration.md +52 -66
- package/package.json +43 -25
- 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 +604 -670
- package/src/client/connection.ts +371 -0
- package/src/client/history.ts +29 -52
- 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 +58 -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 +9 -33
- 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 +327 -498
- package/src/core/runtime/event-processor.ts +197 -70
- 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 +33 -48
- 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 +72 -64
- package/src/protocol/ids.ts +0 -12
- package/src/protocol/index.ts +9 -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 +351 -64
- 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 +223 -387
- package/src/server/bin.ts +280 -78
- package/src/server/feedback.ts +204 -14
- package/src/server/history.ts +116 -122
- package/src/server/index.ts +3 -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 +136 -72
- package/src/server/subscriptions.ts +232 -0
- package/src/server/transports.ts +125 -25
- package/src/server/wire-error.ts +31 -45
- package/src/sync/event-log.ts +31 -3
- package/src/sync/fit.ts +27 -11
- package/src/sync/history-reader.ts +10 -5
- package/src/sync/history-sqlite.ts +37 -42
- package/src/sync/history.ts +9 -15
- package/src/sync/index.ts +17 -5
- package/src/sync/journal-sqlite.ts +162 -76
- package/src/sync/journal.ts +91 -32
- package/src/sync/live-tails.ts +107 -0
- package/src/sync/projection.ts +35 -0
- package/src/sync/recovery.ts +80 -51
- package/src/sync/schema.ts +27 -6
- package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
- package/docs/rfds/0002-native-subagents.md +0 -197
- package/src/client/request.ts +0 -19
- 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
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
Options as CCOptions,
|
|
3
3
|
McpSdkServerConfigWithInstance,
|
|
4
|
+
PermissionResult,
|
|
5
|
+
PermissionUpdate,
|
|
6
|
+
SettingSource,
|
|
4
7
|
} from "@anthropic-ai/claude-agent-sdk";
|
|
5
|
-
import type {
|
|
8
|
+
import type { PermissionMode } from "../../../protocol/index.ts";
|
|
9
|
+
import type { DiagnosticHandler } from "../../diagnostics.ts";
|
|
10
|
+
import type { NativeProcesses } from "../../processes/native-processes.ts";
|
|
11
|
+
import type { AgentExecuteOptions } from "../base.ts";
|
|
12
|
+
import { configFingerprint, directoriesFingerprint } from "../config-fingerprint.ts";
|
|
13
|
+
import type { CredentialSource } from "../credentials.ts";
|
|
14
|
+
import type { InheritConfig } from "../inherit-config.ts";
|
|
15
|
+
import { type ClaudeSpawn, claudeSpawner } from "./spawn.ts";
|
|
6
16
|
|
|
7
17
|
/**
|
|
8
18
|
* In-process MCP servers (the SDK's `createSdkMcpServer` output). Operator
|
|
@@ -18,12 +28,13 @@ export type SdkMcpServers = Record<string, McpSdkServerConfigWithInstance>;
|
|
|
18
28
|
* The Omit list is the engine's own wiring — fields whose silent clobber would
|
|
19
29
|
* desync session diffing (cwd/env/permissionMode/resume), break the adapter
|
|
20
30
|
* (includePartialMessages), or bypass engine merges (mcpServers, hooks,
|
|
21
|
-
* canUseTool) — so "cannot be overridden" is compiler-enforced.
|
|
31
|
+
* canUseTool, onElicitation) — so "cannot be overridden" is compiler-enforced.
|
|
22
32
|
*/
|
|
23
33
|
export type ClaudeSdkOptionOverrides = Partial<
|
|
24
34
|
Omit<
|
|
25
35
|
CCOptions,
|
|
26
36
|
| "canUseTool"
|
|
37
|
+
| "onElicitation"
|
|
27
38
|
| "hooks"
|
|
28
39
|
| "mcpServers"
|
|
29
40
|
| "resume"
|
|
@@ -36,30 +47,244 @@ export type ClaudeSdkOptionOverrides = Partial<
|
|
|
36
47
|
>
|
|
37
48
|
>;
|
|
38
49
|
|
|
39
|
-
/**
|
|
40
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Pre-broker tool policy: the host's programmatic say on every tool call,
|
|
52
|
+
* questions (AskUserQuestion) and plan approvals (ExitPlanMode) included,
|
|
53
|
+
* BEFORE the interactive permission broker and elicitation. Returns the SDK's own
|
|
54
|
+
* `PermissionResult` (so hosts keep full native power: `updatedInput`,
|
|
55
|
+
* `updatedPermissions`) or undefined to fall through to the broker.
|
|
56
|
+
* Operator embed-tier only — never wire-sourced.
|
|
57
|
+
*/
|
|
58
|
+
export type ClaudeToolPolicy = (
|
|
59
|
+
toolName: string,
|
|
60
|
+
input: Record<string, unknown>,
|
|
61
|
+
ctx: {
|
|
62
|
+
sessionId: string;
|
|
63
|
+
toolUseId: string;
|
|
64
|
+
agentId?: string;
|
|
65
|
+
/** Aborts when the turn is cancelled — a policy that waits on a remote approval must race this. */
|
|
66
|
+
signal: AbortSignal;
|
|
67
|
+
/** SDK permission-update suggestions; return them as `updatedPermissions` to honor an "always allow". */
|
|
68
|
+
suggestions?: PermissionUpdate[];
|
|
69
|
+
/** File path that triggered the request (e.g. access outside allowed directories). */
|
|
70
|
+
blockedPath?: string;
|
|
71
|
+
/** The SDK's explanation for why this permission request fired, when it gives one. */
|
|
72
|
+
decisionReason?: string;
|
|
73
|
+
},
|
|
74
|
+
) => PermissionResult | undefined | Promise<PermissionResult | undefined>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* SDK lifecycle hooks factory (decision-capable; a Stop hook may return
|
|
78
|
+
* `{decision: "block"}`); runs once at session spawn. `currentTurnId` names
|
|
79
|
+
* the turn running when a hook fires, and is undefined between turns: a hook
|
|
80
|
+
* then fires in a query Claude began itself, which no turn on the stream shows.
|
|
81
|
+
*/
|
|
82
|
+
export type ClaudeHooksFactory = (ctx: {
|
|
83
|
+
sessionId: string;
|
|
84
|
+
currentTurnId: () => string | undefined;
|
|
85
|
+
}) => CCOptions["hooks"];
|
|
86
|
+
|
|
87
|
+
/** Why a live claude session's subprocess ended (see `onSessionEnd`). */
|
|
88
|
+
export type ClaudeSessionEndReason = "idle" | "replaced" | "released" | "shutdown";
|
|
89
|
+
|
|
90
|
+
/** What the factories an operator gives get to know of the session they serve. */
|
|
91
|
+
interface SessionSpawn {
|
|
92
|
+
sessionId: string;
|
|
41
93
|
cwd: string;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface ClaudeCodeAgentOptions {
|
|
97
|
+
/**
|
|
98
|
+
* Resolve the `claude` binary to spawn (typically the provisioner's,
|
|
99
|
+
* memoized). `undefined` defers to the SDK's own platform-package
|
|
100
|
+
* resolution. Operator-level only — never sourced from the wire.
|
|
101
|
+
*/
|
|
102
|
+
resolveCliPath?: () => Promise<string | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
* Credentials the product holds (LLP 0012), asked before each turn: one
|
|
105
|
+
* runs the turn through the engine's own proxy, none on the CLI's own
|
|
106
|
+
* login. Operator-level only.
|
|
107
|
+
*/
|
|
108
|
+
credentials?: CredentialSource;
|
|
109
|
+
/** Idle time before an unused session's subprocess is shut down (default 5 minutes). */
|
|
54
110
|
idleTimeoutMs?: number;
|
|
55
|
-
/**
|
|
56
|
-
|
|
111
|
+
/**
|
|
112
|
+
* In-process MCP servers to attach to every session (the SDK's
|
|
113
|
+
* `createSdkMcpServer` output). Called once per session spawn. Operator
|
|
114
|
+
* embed-tier only — never wire-sourced; instances win name conflicts with
|
|
115
|
+
* wire-configured servers.
|
|
116
|
+
*/
|
|
117
|
+
sdkMcpServers?: (ctx: SessionSpawn) => SdkMcpServers | Promise<SdkMcpServers>;
|
|
118
|
+
/**
|
|
119
|
+
* Pre-broker tool policy (SDK PermissionResult or undefined = fall through
|
|
120
|
+
* to the interactive broker). Operator embed-tier only.
|
|
121
|
+
*/
|
|
122
|
+
toolPolicy?: ClaudeToolPolicy;
|
|
123
|
+
/** SDK lifecycle hooks factory (decision-capable). Operator embed-tier only. */
|
|
124
|
+
hooks?: ClaudeHooksFactory;
|
|
125
|
+
/**
|
|
126
|
+
* Called exactly once when a live session's subprocess ends, with why:
|
|
127
|
+
* `idle` (idle-timeout eviction), `replaced` (config change or host resume
|
|
128
|
+
* required a new process), `released` (explicit release/close), `shutdown`
|
|
129
|
+
* (terminateAll). The seam for host-managed per-session resources — BYOK
|
|
130
|
+
* proxy keys, recorders — instead of re-deriving termination from side
|
|
131
|
+
* effects. NOTE: `replaced` sessions usually respawn immediately with
|
|
132
|
+
* context preserved; drop only resources bound to the dead subprocess.
|
|
133
|
+
*/
|
|
134
|
+
onSessionEnd?: (sessionId: string, reason: ClaudeSessionEndReason) => void;
|
|
135
|
+
/** Operational diagnostics (interrupt timeouts). */
|
|
136
|
+
onDiagnostic?: DiagnosticHandler;
|
|
137
|
+
/**
|
|
138
|
+
* Raw SDK option overrides merged over the engine's options at session
|
|
139
|
+
* spawn (embedder escape hatch for SDK surface the engine does not model:
|
|
140
|
+
* disallowedTools, forwardSubagentText, extraArgs, ...). Its
|
|
141
|
+
* `settingSources` and `strictMcpConfig` win over `inheritConfig`'s, for an
|
|
142
|
+
* exact combination of Claude's sources; the level still decides
|
|
143
|
+
* auto-memory and the account's claude.ai connectors. Operator embed-tier
|
|
144
|
+
* only — never wire-sourced.
|
|
145
|
+
*/
|
|
146
|
+
sdkOptions?: (ctx: SessionSpawn) => ClaudeSdkOptionOverrides | Promise<ClaudeSdkOptionOverrides>;
|
|
147
|
+
/**
|
|
148
|
+
* Where the `claude` processes start: in a group of their own, held by the
|
|
149
|
+
* lifeline and recorded (`createAgentRegistry` passes the runtime's). An
|
|
150
|
+
* operator `spawnClaudeCodeProcess` in `sdkOptions` replaces it; its
|
|
151
|
+
* session's process is then the host's to stop.
|
|
152
|
+
*/
|
|
153
|
+
processes?: NativeProcesses;
|
|
154
|
+
/**
|
|
155
|
+
* What a session loads by itself (LLP 0001, D17): `all` (the default) every
|
|
156
|
+
* settings source, user, project and local, with auto-memory; `project` the
|
|
157
|
+
* repository's settings, instructions, hooks and `.mcp.json` servers;
|
|
158
|
+
* `none` nothing but the servers the host and the turn name. Below `all`
|
|
159
|
+
* the user's auto-memory and the account's claude.ai connectors stay off
|
|
160
|
+
* whatever the environment says. A `disableTools` turn runs at `none`.
|
|
161
|
+
*/
|
|
162
|
+
inheritConfig?: InheritConfig;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Embed-tier extras threaded from ClaudeCodeAgentOptions into each session. */
|
|
166
|
+
export type ClaudeSessionExtras = Pick<
|
|
167
|
+
ClaudeCodeAgentOptions,
|
|
168
|
+
"sdkMcpServers" | "toolPolicy" | "hooks" | "sdkOptions" | "processes"
|
|
169
|
+
>;
|
|
170
|
+
|
|
171
|
+
/** What every session of an agent runs with: fixed when the agent is made. */
|
|
172
|
+
export type ClaudeSessionSettings = ClaudeSessionExtras &
|
|
173
|
+
Pick<ClaudeCodeAgentOptions, "idleTimeoutMs"> & {
|
|
174
|
+
/** The agent's: where its sessions' `claude` processes start. */
|
|
175
|
+
processes: NativeProcesses;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/** What a turn asks of the Claude session it runs on. */
|
|
179
|
+
export type ClaudeSessionConfig = Pick<
|
|
180
|
+
AgentExecuteOptions,
|
|
181
|
+
| "cwd"
|
|
182
|
+
| "additionalDirectories"
|
|
183
|
+
| "model"
|
|
184
|
+
| "thinkingLevel"
|
|
185
|
+
| "permissionMode"
|
|
186
|
+
| "maxTurns"
|
|
187
|
+
| "subagentMode"
|
|
188
|
+
| "systemPromptAppend"
|
|
189
|
+
| "resumeSessionId"
|
|
190
|
+
| "resumeSessionAt"
|
|
191
|
+
| "mcpServers"
|
|
192
|
+
| "env"
|
|
193
|
+
| "apiKey"
|
|
194
|
+
| "disableTools"
|
|
195
|
+
> & {
|
|
57
196
|
/**
|
|
58
197
|
* Explicit `claude` binary (from the provisioner / operator override).
|
|
59
198
|
* Unset lets the SDK resolve its sibling platform package — which fails
|
|
60
199
|
* inside compiled binaries, where this must be provided.
|
|
61
200
|
*/
|
|
62
201
|
cliPath?: string;
|
|
202
|
+
/** The operator's: what the process loads by itself (`all` unless set). */
|
|
203
|
+
inheritConfig?: InheritConfig;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* A turn's session config. Picked field by field: the long-lived session must
|
|
208
|
+
* not keep a turn's abort signal or callbacks.
|
|
209
|
+
*/
|
|
210
|
+
export function claudeSessionConfig(
|
|
211
|
+
options: AgentExecuteOptions,
|
|
212
|
+
cliPath: string | undefined,
|
|
213
|
+
inheritConfig?: InheritConfig,
|
|
214
|
+
): ClaudeSessionConfig {
|
|
215
|
+
const { cwd, additionalDirectories, model, thinkingLevel, permissionMode, maxTurns } = options;
|
|
216
|
+
const { subagentMode, systemPromptAppend, resumeSessionId, resumeSessionAt } = options;
|
|
217
|
+
const { mcpServers, env, apiKey, disableTools } = options;
|
|
218
|
+
return {
|
|
219
|
+
cwd,
|
|
220
|
+
additionalDirectories,
|
|
221
|
+
model,
|
|
222
|
+
thinkingLevel,
|
|
223
|
+
permissionMode,
|
|
224
|
+
maxTurns,
|
|
225
|
+
subagentMode,
|
|
226
|
+
systemPromptAppend,
|
|
227
|
+
resumeSessionId,
|
|
228
|
+
resumeSessionAt,
|
|
229
|
+
mcpServers,
|
|
230
|
+
env,
|
|
231
|
+
apiKey,
|
|
232
|
+
disableTools: disableTools === true,
|
|
233
|
+
cliPath,
|
|
234
|
+
inheritConfig,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** How many model turns a query may take unless the turn says otherwise. */
|
|
239
|
+
export const DEFAULT_MAX_TURNS = 100;
|
|
240
|
+
|
|
241
|
+
/** The settings sources each level loads; built-in plugins and skills load whatever they say. */
|
|
242
|
+
const SETTING_SOURCES: Record<InheritConfig, readonly SettingSource[]> = {
|
|
243
|
+
all: ["user", "project", "local"],
|
|
244
|
+
project: ["project"],
|
|
245
|
+
none: [],
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/** What a process loads by itself: the operator's level, and nothing for a turn without tools. */
|
|
249
|
+
function inherited(
|
|
250
|
+
config: Pick<ClaudeSessionConfig, "inheritConfig" | "disableTools">,
|
|
251
|
+
): InheritConfig {
|
|
252
|
+
return config.disableTools ? "none" : (config.inheritConfig ?? "all");
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Everything a Claude process is started with that it cannot change while it
|
|
257
|
+
* runs. A turn whose key differs from its session's needs a new process, which
|
|
258
|
+
* resumes the conversation. The model, the permission mode and the MCP servers
|
|
259
|
+
* switch on the live process instead, and a different resume target is the
|
|
260
|
+
* pool's own rule. Unset and empty name the same thing, as do directories in
|
|
261
|
+
* any order; credentials are hashed, never kept in the key.
|
|
262
|
+
*/
|
|
263
|
+
export function claudeSpawnKey(config: ClaudeSessionConfig): string {
|
|
264
|
+
return configFingerprint({
|
|
265
|
+
cwd: config.cwd,
|
|
266
|
+
cliPath: config.cliPath ?? "",
|
|
267
|
+
// Other mode changes switch the live session (`setPermissionMode`);
|
|
268
|
+
// bypass needs its dangerous flag at spawn.
|
|
269
|
+
bypass: config.permissionMode === "bypass_permissions",
|
|
270
|
+
// thinking/effort are fixed at spawn in the modern SDK vocabulary (the
|
|
271
|
+
// old setMaxThinkingTokens hot-swap is deprecated and effort-blind).
|
|
272
|
+
thinkingLevel: config.thinkingLevel ?? "",
|
|
273
|
+
systemPromptAppend: config.systemPromptAppend ?? "",
|
|
274
|
+
// The SDK applies a rewind only at spawn, so any change restarts, a set
|
|
275
|
+
// point clearing too: one extra (context-preserving) respawn after a
|
|
276
|
+
// revert keeps the gate correct even if the stored config lags a turn.
|
|
277
|
+
resumeSessionAt: config.resumeSessionAt ?? "",
|
|
278
|
+
directories: directoriesFingerprint(config.additionalDirectories),
|
|
279
|
+
apiKey: config.apiKey ?? "",
|
|
280
|
+
maxTurns: config.maxTurns ?? DEFAULT_MAX_TURNS,
|
|
281
|
+
disableTools: config.disableTools === true,
|
|
282
|
+
inheritConfig: inherited(config),
|
|
283
|
+
subagentMode: config.subagentMode,
|
|
284
|
+
// No environment and an empty one differ, as they do for the
|
|
285
|
+
// conversation's boundary (`SessionAgent`).
|
|
286
|
+
env: config.env,
|
|
287
|
+
});
|
|
63
288
|
}
|
|
64
289
|
|
|
65
290
|
/**
|
|
@@ -67,7 +292,7 @@ export interface ClaudeSessionConfig {
|
|
|
67
292
|
* auto-approves every tool and is dangerous outside a sandbox, so it must be
|
|
68
293
|
* requested explicitly — an unset/unknown mode falls back to the safe `default`.
|
|
69
294
|
*/
|
|
70
|
-
function toSdkPermissionMode(mode: PermissionMode | undefined): CCOptions["permissionMode"] {
|
|
295
|
+
export function toSdkPermissionMode(mode: PermissionMode | undefined): CCOptions["permissionMode"] {
|
|
71
296
|
switch (mode) {
|
|
72
297
|
case "bypass_permissions":
|
|
73
298
|
return "bypassPermissions";
|
|
@@ -85,6 +310,24 @@ function toSdkPermissionMode(mode: PermissionMode | undefined): CCOptions["permi
|
|
|
85
310
|
}
|
|
86
311
|
}
|
|
87
312
|
|
|
313
|
+
/** The engine's name for a mode the CLI reports itself in; undefined for one it has none for. */
|
|
314
|
+
export function fromSdkPermissionMode(mode: string | undefined): PermissionMode | undefined {
|
|
315
|
+
switch (mode) {
|
|
316
|
+
case "bypassPermissions":
|
|
317
|
+
return "bypass_permissions";
|
|
318
|
+
case "plan":
|
|
319
|
+
return "plan";
|
|
320
|
+
case "acceptEdits":
|
|
321
|
+
return "accept_edits";
|
|
322
|
+
case "dontAsk":
|
|
323
|
+
return "dont_ask";
|
|
324
|
+
case "default":
|
|
325
|
+
return "default";
|
|
326
|
+
default:
|
|
327
|
+
return undefined;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
88
331
|
/**
|
|
89
332
|
* Build the env handed to the Claude subprocess. The SDK REPLACES the child env
|
|
90
333
|
* entirely when `env` is set, so we must spread `process.env` to preserve PATH/
|
|
@@ -92,36 +335,74 @@ function toSdkPermissionMode(mode: PermissionMode | undefined): CCOptions["permi
|
|
|
92
335
|
* when an explicit key is supplied — otherwise the CLI's own auth is used.
|
|
93
336
|
*
|
|
94
337
|
* A subscription login also brings that account's claude.ai connectors (Drive,
|
|
95
|
-
* Gmail, …) into every session
|
|
96
|
-
*
|
|
338
|
+
* Gmail, …) into every session; at `all` they stay off unless the operator's
|
|
339
|
+
* or the turn's env turns them on. Below `all` they stay off, and so does the
|
|
340
|
+
* auto-memory Claude keeps per repository, whatever either env says: both are
|
|
341
|
+
* the host user's, which no settings source decides (`settingSources: []`
|
|
342
|
+
* still loads the memory).
|
|
343
|
+
*
|
|
344
|
+
* Background tasks and scheduled prompts stay off the same way: Claude answers
|
|
345
|
+
* one that finishes after its turn with a query of its own, which no turn on
|
|
346
|
+
* the stream shows. The CLI's updater stays off whatever either env says: the
|
|
347
|
+
* build that runs is the one the provisioner chose.
|
|
97
348
|
*/
|
|
98
|
-
function buildEnv(
|
|
349
|
+
function buildEnv(
|
|
350
|
+
config: Pick<ClaudeSessionConfig, "apiKey" | "env" | "subagentMode">,
|
|
351
|
+
level: InheritConfig,
|
|
352
|
+
): Record<string, string | undefined> {
|
|
99
353
|
return {
|
|
100
354
|
ENABLE_CLAUDEAI_MCP_SERVERS: "false",
|
|
355
|
+
// @ref LLP 0001#d14--nothing-the-agent-does-is-off-the-stream — off until the stream can show it
|
|
356
|
+
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: "1",
|
|
357
|
+
CLAUDE_CODE_DISABLE_CRON: "1",
|
|
101
358
|
...process.env,
|
|
102
359
|
...(config.apiKey ? { ANTHROPIC_API_KEY: config.apiKey } : {}),
|
|
103
360
|
...config.env,
|
|
361
|
+
// The engine runs the build it pinned: the CLI must not replace itself.
|
|
362
|
+
DISABLE_AUTOUPDATER: "1",
|
|
104
363
|
...(config.subagentMode === "turn" && { CLAUDE_CODE_DISABLE_BACKGROUND_TASKS: "1" }),
|
|
364
|
+
// @ref LLP 0001#d17--a-turn-inherits-what-the-operator-chooses-all-the-projects-or-none — after the spread
|
|
365
|
+
...(level !== "all" && {
|
|
366
|
+
CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1",
|
|
367
|
+
ENABLE_CLAUDEAI_MCP_SERVERS: "false",
|
|
368
|
+
}),
|
|
105
369
|
};
|
|
106
370
|
}
|
|
107
371
|
|
|
372
|
+
/** The environment Claude Code runs a turn with this `env` in, which decides whose login it runs on. */
|
|
373
|
+
export function claudeEnv(
|
|
374
|
+
config: Pick<ClaudeSessionConfig, "env" | "inheritConfig">,
|
|
375
|
+
): Record<string, string | undefined> {
|
|
376
|
+
return buildEnv(config, inherited(config));
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* The SDK options a Claude process starts with. Its MCP servers are only the
|
|
381
|
+
* host's in-process ones: the session attaches the turn's own after spawn
|
|
382
|
+
* (`ClaudeMcpConnections`), since CLI startup entries can survive the first
|
|
383
|
+
* dynamic removal and reconnect-by-name can reuse their original credentials.
|
|
384
|
+
*/
|
|
108
385
|
export function buildClaudeOptions(
|
|
109
|
-
config: ClaudeSessionConfig,
|
|
386
|
+
config: Omit<ClaudeSessionConfig, "mcpServers">,
|
|
110
387
|
sdkMcpServers?: SdkMcpServers,
|
|
111
388
|
overrides?: ClaudeSdkOptionOverrides,
|
|
389
|
+
spawn?: ClaudeSpawn,
|
|
112
390
|
): CCOptions {
|
|
113
391
|
const mode = toSdkPermissionMode(config.permissionMode);
|
|
392
|
+
const level = inherited(config);
|
|
114
393
|
|
|
115
394
|
const options: CCOptions = {
|
|
116
395
|
cwd: config.cwd,
|
|
117
|
-
maxTurns: config.maxTurns ??
|
|
396
|
+
maxTurns: config.maxTurns ?? DEFAULT_MAX_TURNS,
|
|
118
397
|
permissionMode: mode,
|
|
119
398
|
// Streaming input mode + partial messages give us token-level deltas.
|
|
120
399
|
includePartialMessages: true,
|
|
121
400
|
systemPrompt: config.systemPromptAppend
|
|
122
401
|
? { type: "preset", preset: "claude_code", append: config.systemPromptAppend }
|
|
123
402
|
: { type: "preset", preset: "claude_code" },
|
|
124
|
-
|
|
403
|
+
// Explicit at every level: the SDK's default for unset must not decide it.
|
|
404
|
+
settingSources: [...SETTING_SOURCES[level]],
|
|
405
|
+
env: buildEnv(config, level),
|
|
125
406
|
};
|
|
126
407
|
|
|
127
408
|
if (config.cliPath) options.pathToClaudeCodeExecutable = config.cliPath;
|
|
@@ -146,35 +427,41 @@ export function buildClaudeOptions(
|
|
|
146
427
|
// pass it alone (the CLI would get a bare --resume-session-at).
|
|
147
428
|
if (config.resumeSessionAt) options.resumeSessionAt = config.resumeSessionAt;
|
|
148
429
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
options.strictMcpConfig = true;
|
|
157
|
-
} else if (config.mcpServers || sdkMcpServers) {
|
|
158
|
-
// Our McpServerConfig is structurally assignable to the SDK's stdio/http/sse
|
|
159
|
-
// shapes; in-process servers merge beside them (operator wins conflicts).
|
|
160
|
-
options.mcpServers = { ...config.mcpServers, ...sdkMcpServers };
|
|
161
|
-
}
|
|
430
|
+
// Only the servers the host and the turn name: no plugin's, connector's
|
|
431
|
+
// or settings file's. The turn's still attach (`setMcpServers`).
|
|
432
|
+
if (level === "none") options.strictMcpConfig = true;
|
|
433
|
+
// Text-only: no built-in tools and no MCP servers, the host's included; it
|
|
434
|
+
// runs at `none`, so nothing ambient brings tools back.
|
|
435
|
+
if (config.disableTools) options.tools = [];
|
|
436
|
+
else options.mcpServers = { ...sdkMcpServers };
|
|
162
437
|
|
|
163
438
|
// Operator overrides land last; the engine wires hooks/canUseTool after
|
|
164
439
|
// this function returns, so those can never be clobbered (and the
|
|
165
440
|
// ClaudeSdkOptionOverrides type excludes them anyway).
|
|
166
441
|
if (overrides) Object.assign(options, overrides);
|
|
167
442
|
if (config.subagentMode === "turn") options.forwardSubagentText = true;
|
|
443
|
+
// Engine wiring over the operator's: their spawner still runs, as theirs.
|
|
444
|
+
if (spawn)
|
|
445
|
+
options.spawnClaudeCodeProcess = claudeSpawner(
|
|
446
|
+
spawn,
|
|
447
|
+
overrides?.spawnClaudeCodeProcess,
|
|
448
|
+
overrides?.stderr,
|
|
449
|
+
);
|
|
168
450
|
|
|
169
451
|
// Fable-class models withhold thinking plaintext by default: blocks stream
|
|
170
452
|
// structure + token estimates only, so every reasoning part arrives with
|
|
171
453
|
// empty text. The hidden `--thinking-display summarized` flag opts into
|
|
172
|
-
// summary text
|
|
454
|
+
// summary text. Applied after operator
|
|
173
455
|
// overrides so an unrelated operator extraArgs can't drop it, while an
|
|
174
456
|
// explicit operator `thinking-display` key still wins.
|
|
175
457
|
if (config.thinkingLevel !== "off") {
|
|
176
458
|
options.extraArgs = { "thinking-display": "summarized", ...options.extraArgs };
|
|
177
459
|
}
|
|
460
|
+
// @ref LLP 0002#steering — Claude replays each steer where it reads it
|
|
461
|
+
// Replay echoes every uuid-stamped user message back at the step Claude
|
|
462
|
+
// reads it, which is where a steer's user message belongs. Engine wiring:
|
|
463
|
+
// applied last, so no operator `extraArgs` can drop it.
|
|
464
|
+
options.extraArgs = { ...options.extraArgs, "replay-user-messages": null };
|
|
178
465
|
|
|
179
466
|
return options;
|
|
180
467
|
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import type { SDKRateLimitInfo, SDKResultMessage } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
+
import { type ErrorCategory, type StopReason, classifyError } from "../../../protocol/index.ts";
|
|
3
|
+
import type { AdapterEvent, TransformResult } from "../types.ts";
|
|
4
|
+
|
|
5
|
+
/** Map Anthropic stop reasons / result subtypes onto the normalized enum. */
|
|
6
|
+
export function mapClaudeStopReason(
|
|
7
|
+
stopReason: string | null | undefined,
|
|
8
|
+
subtype: string | undefined,
|
|
9
|
+
): StopReason | undefined {
|
|
10
|
+
if (subtype === "error_max_turns") return "max_turn_requests";
|
|
11
|
+
switch (stopReason) {
|
|
12
|
+
case "end_turn":
|
|
13
|
+
case "stop_sequence":
|
|
14
|
+
case "tool_use":
|
|
15
|
+
case "pause_turn":
|
|
16
|
+
return "end_turn";
|
|
17
|
+
case "max_tokens":
|
|
18
|
+
return "max_tokens";
|
|
19
|
+
case "refusal":
|
|
20
|
+
return "refusal";
|
|
21
|
+
default:
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Claude's typed API failure codes, and HTTP statuses, as engine error
|
|
28
|
+
* categories. A code or status this build does not know returns `undefined`,
|
|
29
|
+
* so the message decides rather than a guess. `status === null` is a request
|
|
30
|
+
* that got no HTTP response at all.
|
|
31
|
+
*/
|
|
32
|
+
export function claudeErrorCategory(
|
|
33
|
+
code: string | undefined,
|
|
34
|
+
status?: number | null,
|
|
35
|
+
): ErrorCategory | undefined {
|
|
36
|
+
switch (code) {
|
|
37
|
+
case "authentication_failed":
|
|
38
|
+
case "oauth_org_not_allowed":
|
|
39
|
+
case "account_on_hold":
|
|
40
|
+
case "verification_required":
|
|
41
|
+
case "cloud_credential_error":
|
|
42
|
+
return "auth";
|
|
43
|
+
case "billing_error":
|
|
44
|
+
return "usage_limit";
|
|
45
|
+
case "rate_limit":
|
|
46
|
+
return "rate_limit";
|
|
47
|
+
case "overloaded":
|
|
48
|
+
return "overloaded";
|
|
49
|
+
case "invalid_request":
|
|
50
|
+
case "model_not_found":
|
|
51
|
+
return "invalid_request";
|
|
52
|
+
case "server_error":
|
|
53
|
+
return "internal";
|
|
54
|
+
}
|
|
55
|
+
if (status === 429) return "rate_limit";
|
|
56
|
+
if (status === 529 || status === 503) return "overloaded";
|
|
57
|
+
if (status === 401 || status === 403) return "auth";
|
|
58
|
+
if (status === null) return "network";
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** A window used up, and no extra usage (overage) answering in its place. */
|
|
63
|
+
export function planUsedUp(info: SDKRateLimitInfo): boolean {
|
|
64
|
+
return (
|
|
65
|
+
info.status === "rejected" &&
|
|
66
|
+
info.isUsingOverage !== true &&
|
|
67
|
+
info.overageStatus !== "allowed" &&
|
|
68
|
+
info.overageStatus !== "allowed_warning"
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** A `rate_limit_event`: one window of the claude.ai plan (`resetsAt` is in seconds). */
|
|
73
|
+
export function claudeLimits(info: SDKRateLimitInfo | undefined): AdapterEvent[] {
|
|
74
|
+
if (!info) return [];
|
|
75
|
+
// The status is the reported window's own: another window may still be limited.
|
|
76
|
+
const status =
|
|
77
|
+
info.status === "rejected" ? "limited" : info.status === "allowed_warning" ? "warning" : "ok";
|
|
78
|
+
return [
|
|
79
|
+
{
|
|
80
|
+
kind: "limits",
|
|
81
|
+
windows: [
|
|
82
|
+
{
|
|
83
|
+
id: info.rateLimitType ?? "plan",
|
|
84
|
+
status,
|
|
85
|
+
...(info.utilization !== undefined && { usedPercent: info.utilization * 100 }),
|
|
86
|
+
...(info.resetsAt !== undefined && { resetsAt: info.resetsAt * 1000 }),
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* How a Claude turn ended, from its results: its stop reason, its failure and
|
|
95
|
+
* that failure's category, and whether an interrupt stopped it. A turn runs
|
|
96
|
+
* one more query for each steer it got too late; the last query decides.
|
|
97
|
+
*/
|
|
98
|
+
export class ClaudeTurnOutcome {
|
|
99
|
+
private stopReason?: StopReason;
|
|
100
|
+
private finishReason?: string;
|
|
101
|
+
private error?: string;
|
|
102
|
+
/** The typed code of the last failed API request the turn reported. */
|
|
103
|
+
private errorCode?: string;
|
|
104
|
+
/** Plan windows Claude reports used up, with no extra usage serving requests. */
|
|
105
|
+
private readonly usedUpWindows = new Set<string>();
|
|
106
|
+
private interrupted = false;
|
|
107
|
+
private execFailure = false;
|
|
108
|
+
private succeeded = false;
|
|
109
|
+
/** The last result left steers for Claude's next query, still this turn. */
|
|
110
|
+
private steersPending = false;
|
|
111
|
+
|
|
112
|
+
/** One plan window's report: another window may still be used up. */
|
|
113
|
+
limits(info: SDKRateLimitInfo | undefined): AdapterEvent[] {
|
|
114
|
+
const id = info?.rateLimitType ?? "plan";
|
|
115
|
+
if (info && planUsedUp(info)) this.usedUpWindows.add(id);
|
|
116
|
+
else this.usedUpWindows.delete(id);
|
|
117
|
+
return claudeLimits(info);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** The turn's own request failed: a top-level assistant message says so with a typed code. */
|
|
121
|
+
requestFailed(code: string): void {
|
|
122
|
+
this.errorCode = code;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** The streaming model message said why it stopped (`message_delta`). */
|
|
126
|
+
messageStopped(reason: string): void {
|
|
127
|
+
this.finishReason = reason;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The turn was asked to stop (`agentServer/turnInterrupted`, after its result). */
|
|
131
|
+
interrupt(): void {
|
|
132
|
+
this.interrupted = true;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** A query's result; `steersPending`: Claude runs one more query, still this turn. */
|
|
136
|
+
settle(result: SDKResultMessage, steersPending: boolean): void {
|
|
137
|
+
// With steers pending, Claude's next query is still this turn: only the
|
|
138
|
+
// turn's last result says how it ended, so an earlier query's failure
|
|
139
|
+
// gives way to the next one's outcome.
|
|
140
|
+
if (this.steersPending) {
|
|
141
|
+
this.error = undefined;
|
|
142
|
+
this.errorCode = undefined;
|
|
143
|
+
this.execFailure = false;
|
|
144
|
+
}
|
|
145
|
+
this.steersPending = steersPending;
|
|
146
|
+
this.succeeded = result.subtype === "success" && !result.is_error && !steersPending;
|
|
147
|
+
this.finishReason = result.stop_reason ?? result.subtype ?? this.finishReason;
|
|
148
|
+
this.stopReason = mapClaudeStopReason(result.stop_reason, result.subtype);
|
|
149
|
+
if (result.subtype && result.subtype !== "success") {
|
|
150
|
+
if (result.subtype === "error_during_execution" && result.stop_reason === null) {
|
|
151
|
+
// Ambiguous shape: an interrupt AND an execution failure (e.g. a bad
|
|
152
|
+
// resume id) both surface this way. The agent's `turnInterrupted`
|
|
153
|
+
// marker (which arrives after this message) disambiguates in finish(),
|
|
154
|
+
// as it does for an interrupt that aborted a tool (stop reason "tool_use").
|
|
155
|
+
this.execFailure = true;
|
|
156
|
+
} else if (result.subtype === "error_max_turns") {
|
|
157
|
+
// Hitting the turn budget is a stop condition, not a failure.
|
|
158
|
+
} else {
|
|
159
|
+
this.error = `Claude turn ended: ${result.subtype}`;
|
|
160
|
+
}
|
|
161
|
+
} else if (result.is_error) {
|
|
162
|
+
// A failed API call (a rejected key, an exhausted quota, an overloaded
|
|
163
|
+
// provider) ends the turn as a "success" whose text is the error. The
|
|
164
|
+
// text names the failure, so the runtime classifies it (401 -> auth).
|
|
165
|
+
this.error = result.result || "Claude turn ended with an API error";
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** How the turn ended. */
|
|
170
|
+
finish(): Pick<
|
|
171
|
+
TransformResult,
|
|
172
|
+
"stopReason" | "finishReason" | "error" | "errorCategory" | "cancelled"
|
|
173
|
+
> {
|
|
174
|
+
// An interrupted turn that did not succeed was cancelled. Claude ends it with
|
|
175
|
+
// error_during_execution and the stop reason of the step it aborted (null
|
|
176
|
+
// while streaming, "tool_use" while a tool runs), or with no result when
|
|
177
|
+
// the process was stopped first. Without an interrupt, error_during_execution
|
|
178
|
+
// is a real failure (a silent "cancelled" here is how a bad resume id used
|
|
179
|
+
// to vanish without a trace).
|
|
180
|
+
const cancelled = this.interrupted && !this.succeeded;
|
|
181
|
+
const error = cancelled
|
|
182
|
+
? undefined
|
|
183
|
+
: (this.error ??
|
|
184
|
+
(this.execFailure
|
|
185
|
+
? "Claude turn failed during execution (error_during_execution — e.g. an invalid resumeSessionId fails this way)"
|
|
186
|
+
: undefined));
|
|
187
|
+
const errorCategory = error ? this.errorCategory() : undefined;
|
|
188
|
+
return {
|
|
189
|
+
stopReason: this.stopReason,
|
|
190
|
+
finishReason: this.finishReason,
|
|
191
|
+
error,
|
|
192
|
+
...(errorCategory && { errorCategory }),
|
|
193
|
+
cancelled,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** The turn's failure category: Claude's typed code, made finer where it is coarse. */
|
|
198
|
+
private errorCategory(): ErrorCategory | undefined {
|
|
199
|
+
const typed = this.errorCode ? claudeErrorCategory(this.errorCode) : undefined;
|
|
200
|
+
// Claude's code for a 429 is `rate_limit` when the plan itself is used up
|
|
201
|
+
// too; the turn's limit report says so, and a used-up plan waits for its
|
|
202
|
+
// reset rather than a backoff.
|
|
203
|
+
if (typed === "rate_limit" && this.usedUpWindows.size > 0) return "usage_limit";
|
|
204
|
+
// `invalid_request` is any 400, a prompt too long for the model among them.
|
|
205
|
+
if (typed === "invalid_request" && this.error && classifyError(this.error) === "context_limit")
|
|
206
|
+
return "context_limit";
|
|
207
|
+
return typed;
|
|
208
|
+
}
|
|
209
|
+
}
|