@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
|
@@ -1,55 +1,35 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ErrorInfo,
|
|
3
|
-
classifyError,
|
|
4
|
-
isCancellation,
|
|
5
|
-
isRecoverable,
|
|
6
|
-
readableErrorMessage,
|
|
7
|
-
} from "../../protocol/errors.ts";
|
|
8
1
|
import type {
|
|
9
2
|
AgentCapabilities,
|
|
10
3
|
AgentHarness,
|
|
11
|
-
|
|
4
|
+
AuthLogin,
|
|
5
|
+
AuthLoginParams,
|
|
6
|
+
AuthUpdated,
|
|
7
|
+
ElicitationOutcome,
|
|
8
|
+
HarnessAuth,
|
|
9
|
+
HarnessCli,
|
|
10
|
+
HarnessCliProgress,
|
|
12
11
|
ModelList,
|
|
13
|
-
|
|
12
|
+
ModelsListParams,
|
|
14
13
|
PermissionOutcome,
|
|
15
|
-
PermissionToolCall,
|
|
16
14
|
RunRequest,
|
|
17
|
-
|
|
18
|
-
TokenUsage,
|
|
19
|
-
TurnExecution,
|
|
15
|
+
TurnSteerResult,
|
|
20
16
|
} from "../../protocol/index.ts";
|
|
21
|
-
import {
|
|
22
|
-
import type {
|
|
23
|
-
AgentExecuteOptions,
|
|
24
|
-
AppliedExecution,
|
|
25
|
-
CancelResult,
|
|
26
|
-
PermissionDecision,
|
|
27
|
-
} from "../agents/base.ts";
|
|
17
|
+
import { RunRequestSchema, canonicalJson, turnIdentity } from "../../protocol/index.ts";
|
|
18
|
+
import type { CancelResult, SteerRequest } from "../agents/base.ts";
|
|
28
19
|
import type { AgentRegistry } from "../agents/registry.ts";
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
nativeSessionId?: string;
|
|
43
|
-
/** When the turn requested a resume: whether the harness honored it. */
|
|
44
|
-
resumed?: boolean;
|
|
45
|
-
usage: TokenUsage;
|
|
46
|
-
/** Normalized terminal status (same value as the `turn.ended` event). */
|
|
47
|
-
stopReason: StopReason;
|
|
48
|
-
finishReason?: string;
|
|
49
|
-
cost?: number;
|
|
50
|
-
error?: ErrorInfo;
|
|
51
|
-
cancelled: boolean;
|
|
52
|
-
}
|
|
20
|
+
import type { DiagnosticHandler } from "../diagnostics.ts";
|
|
21
|
+
import type { NativeRecord } from "../processes/identity.ts";
|
|
22
|
+
import type { NativeProcessEvent, OrphanOutcome } from "../processes/native-processes.ts";
|
|
23
|
+
import { setBounded } from "../utils/bounded.ts";
|
|
24
|
+
import { withTimeout } from "../utils/deadline.ts";
|
|
25
|
+
import { InvalidRequestError, TurnConflictError } from "../utils/errors.ts";
|
|
26
|
+
import { type EventSink, EventSinkError } from "./event-sink.ts";
|
|
27
|
+
import { harnessCliProgress, harnessClis } from "./harness-clis.ts";
|
|
28
|
+
import { HarnessLogins } from "./harness-logins.ts";
|
|
29
|
+
import { ModelLists } from "./model-lists.ts";
|
|
30
|
+
import { StandingRules } from "./permission-policy.ts";
|
|
31
|
+
import type { RequestAnswers, RequestKind } from "./request-broker.ts";
|
|
32
|
+
import { type RunSummary, type SessionMemory, Turn, type TurnHost } from "./turn.ts";
|
|
53
33
|
|
|
54
34
|
/**
|
|
55
35
|
* How `run()` would treat a request: execute it (`new`), or converge a retry
|
|
@@ -60,74 +40,57 @@ export type TurnAdmission =
|
|
|
60
40
|
| { status: "inflight" }
|
|
61
41
|
| { status: "completed"; summary: RunSummary };
|
|
62
42
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*/
|
|
68
|
-
function canonicalJson(value: unknown): string {
|
|
69
|
-
if (value === null || typeof value !== "object") return JSON.stringify(value) ?? '"undefined"';
|
|
70
|
-
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
71
|
-
const entries = Object.entries(value as Record<string, unknown>)
|
|
72
|
-
.filter(([, v]) => v !== undefined)
|
|
73
|
-
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))
|
|
74
|
-
.map(([k, v]) => `${JSON.stringify(k)}:${canonicalJson(v)}`);
|
|
75
|
-
return `{${entries.join(",")}}`;
|
|
76
|
-
}
|
|
43
|
+
// Caller-supplied IDs need not be UUIDs; encode the tuple without delimiter collisions.
|
|
44
|
+
const turnKeyOf = (sessionId: string, turnId: string) => JSON.stringify([sessionId, turnId]);
|
|
45
|
+
// @ref LLP 0003#commit-before-acknowledging — a turn sent again converges when it is the same turn
|
|
46
|
+
const inputKeyOf = (request: RunRequest) => canonicalJson(turnIdentity(request));
|
|
77
47
|
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/** The standard options offered for every brokered permission request (§6.4:
|
|
84
|
-
* the broker must actually offer the `*_always` kinds the schema advertises —
|
|
85
|
-
* a "don't ask again" answer becomes a standing per-session rule). */
|
|
86
|
-
const PERMISSION_OPTIONS: PermissionOption[] = [
|
|
87
|
-
{ optionId: "allow", name: "Allow", kind: "allow_once" },
|
|
88
|
-
{ optionId: "allow_always", name: "Always allow", kind: "allow_always" },
|
|
89
|
-
{ optionId: "reject", name: "Reject", kind: "reject_once" },
|
|
90
|
-
{ optionId: "reject_always", name: "Always reject", kind: "reject_always" },
|
|
91
|
-
];
|
|
92
|
-
|
|
93
|
-
interface PendingPermission {
|
|
94
|
-
sessionId: string;
|
|
95
|
-
/** Resolves the request and emits `permission.resolved`; await the returned
|
|
96
|
-
* promise to order that emit (the turn-end drain does, so it lands before
|
|
97
|
-
* `turn.ended`). */
|
|
98
|
-
settle: (outcome: PermissionOutcome) => void | Promise<void>;
|
|
99
|
-
}
|
|
48
|
+
/** Per-session convergence window; old turns fall out and a stale retry would re-execute. */
|
|
49
|
+
const SETTLED_TURNS = 16;
|
|
50
|
+
/** Give up on stragglers after this long; the process is exiting anyway. */
|
|
51
|
+
const DEFAULT_DRAIN_TIMEOUT_MS = 10_000;
|
|
100
52
|
|
|
101
53
|
/**
|
|
102
|
-
* The engine. Owns no transport and no harness specifics: it
|
|
103
|
-
* RunRequest
|
|
104
|
-
*
|
|
54
|
+
* The engine. Owns no transport and no harness specifics: it admits each
|
|
55
|
+
* RunRequest once as a `Turn`, which runs it on its harness and streams
|
|
56
|
+
* normalized LifecycleEvents to a sink, and routes cancels, answers and
|
|
57
|
+
* steers to the turns they are for.
|
|
105
58
|
*/
|
|
106
59
|
export class AgentRuntime {
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
private readonly
|
|
112
|
-
/**
|
|
113
|
-
private readonly
|
|
114
|
-
string,
|
|
115
|
-
{ inputKey: string; promise: Promise<RunSummary> }
|
|
116
|
-
>();
|
|
117
|
-
/** Recently completed turns per session (bounded LRU) — retries converge on the stored summary. */
|
|
118
|
-
private readonly completedTurns = new Map<
|
|
119
|
-
string,
|
|
120
|
-
Map<string, { inputKey: string; summary: RunSummary }>
|
|
121
|
-
>();
|
|
122
|
-
/** Per-session convergence window; old turns fall out and a stale retry would re-execute. */
|
|
123
|
-
private static readonly COMPLETED_TURN_MEMORY = 16;
|
|
60
|
+
/**
|
|
61
|
+
* Admitted turns by turn key, until they settle: what a retried run
|
|
62
|
+
* converges on, and what cancels, answers and steers reach.
|
|
63
|
+
*/
|
|
64
|
+
private readonly turns = new Map<string, Turn>();
|
|
65
|
+
/** What each logical session remembers across its turns, until it closes. */
|
|
66
|
+
private readonly sessions = new Map<string, SessionMemory>();
|
|
124
67
|
private shutdownPromise?: Promise<void>;
|
|
68
|
+
/** Aborted as shutdown begins, and part of every run's signal: a run still
|
|
69
|
+
* setting up then, which its harness has not yet tracked, stops too. */
|
|
70
|
+
private readonly stopping = new AbortController();
|
|
125
71
|
private readonly modelLists = new ModelLists();
|
|
72
|
+
private readonly logins: HarnessLogins;
|
|
73
|
+
private readonly host: TurnHost;
|
|
126
74
|
|
|
127
75
|
constructor(
|
|
128
76
|
private readonly registry: AgentRegistry,
|
|
129
|
-
|
|
130
|
-
) {
|
|
77
|
+
options: { onDiagnostic?: DiagnosticHandler } = {},
|
|
78
|
+
) {
|
|
79
|
+
this.logins = new HarnessLogins(
|
|
80
|
+
(harness) => registry.getAgent(harness),
|
|
81
|
+
(harness) => {
|
|
82
|
+
registry.getAgent(harness).loginChanged?.();
|
|
83
|
+
this.modelLists.forget(harness);
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
this.host = {
|
|
87
|
+
registry,
|
|
88
|
+
modelLists: this.modelLists,
|
|
89
|
+
onDiagnostic: options.onDiagnostic,
|
|
90
|
+
memory: (sessionId) => this.memoryOf(sessionId),
|
|
91
|
+
cancel: (harness, sessionId) => this.cancel(harness, sessionId),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
131
94
|
|
|
132
95
|
get harnesses(): AgentHarness[] {
|
|
133
96
|
return this.registry.list();
|
|
@@ -144,44 +107,143 @@ export class AgentRuntime {
|
|
|
144
107
|
* catalog, with `error` saying why. Turns then fit their thinking level to
|
|
145
108
|
* the listed levels of the model they run.
|
|
146
109
|
*/
|
|
147
|
-
async models(query:
|
|
110
|
+
async models(query: ModelsListParams): Promise<ModelList> {
|
|
148
111
|
return await this.modelLists.get(this.registry.getAgent(query.harness), query);
|
|
149
112
|
}
|
|
150
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Where each harness's CLI is (every registered harness when `harnesses`
|
|
116
|
+
* is absent), found without installing anything: `ready`, `missing` (what
|
|
117
|
+
* its first turn would install), `installing`, `failed` (why), or
|
|
118
|
+
* `unmanaged` (ACP's agent is the operator's command).
|
|
119
|
+
*/
|
|
120
|
+
async listClis(harnesses: readonly AgentHarness[] = this.harnesses): Promise<HarnessCli[]> {
|
|
121
|
+
for (const harness of harnesses) this.registry.getAgent(harness);
|
|
122
|
+
return harnessClis(this.registry.provisioner, harnesses, false);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// @ref LLP 0010#p3--ready-before-the-first-turn-and-visible — a product installs at setup, not in a turn
|
|
126
|
+
/**
|
|
127
|
+
* Install each harness's CLI now rather than at its first turn, joining an
|
|
128
|
+
* install already running, and answer where each one is after: a failed
|
|
129
|
+
* install is reported with its error, not thrown. Progress goes to
|
|
130
|
+
* `onCliProgress`.
|
|
131
|
+
*/
|
|
132
|
+
async prepareClis(harnesses: readonly AgentHarness[] = this.harnesses): Promise<HarnessCli[]> {
|
|
133
|
+
for (const harness of harnesses) this.registry.getAgent(harness);
|
|
134
|
+
return harnessClis(this.registry.provisioner, harnesses, true);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Every install of a harness's CLI, whoever caused it (a turn, a model
|
|
139
|
+
* list, `prepareClis`): at most four a second, and always its last phase.
|
|
140
|
+
* Returns the unsubscribe.
|
|
141
|
+
*/
|
|
142
|
+
onCliProgress(observer: (progress: HarnessCliProgress) => void): () => void {
|
|
143
|
+
const provisioner = this.registry.provisioner;
|
|
144
|
+
if (!provisioner) return () => {};
|
|
145
|
+
return provisioner.observe((progress) => {
|
|
146
|
+
for (const event of harnessCliProgress(progress, this.harnesses)) observer(event);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Each harness's login, as its CLI says it for the store and environment a
|
|
152
|
+
* turn with `env` would use (every registered harness when `harnesses` is
|
|
153
|
+
* absent): signed in, with what and as whom, signed out, or unknown and
|
|
154
|
+
* why; and the logins it offers. A login made elsewhere (a terminal) that
|
|
155
|
+
* a read notices counts as a change, as `login` and `logout` do: each
|
|
156
|
+
* session's next turn starts a new CLI, and `onAuthUpdated` hears it.
|
|
157
|
+
*/
|
|
158
|
+
authStatus(
|
|
159
|
+
harnesses: readonly AgentHarness[] = this.harnesses,
|
|
160
|
+
env?: Record<string, string>,
|
|
161
|
+
): Promise<HarnessAuth[]> {
|
|
162
|
+
return this.logins.status(harnesses, env);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Start one of a harness's logins through its CLI's own flow, answered as
|
|
167
|
+
* soon as the CLI says where the user signs in; `onAuthUpdated` says how
|
|
168
|
+
* it ended. A login under way to the same harness and store is cancelled.
|
|
169
|
+
*/
|
|
170
|
+
login(params: AuthLoginParams): Promise<AuthLogin> {
|
|
171
|
+
return this.logins.login(params);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Finish a login with the code its `codeUrl` page showed: how it ended. */
|
|
175
|
+
completeLogin(loginId: string, code: string): Promise<AuthUpdated> {
|
|
176
|
+
return this.logins.complete(loginId, code);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Stop a login under way. */
|
|
180
|
+
cancelLogin(loginId: string): "cancelled" | "not_found" {
|
|
181
|
+
return this.logins.cancel(loginId);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Remove a harness's CLI login; answers its login after. */
|
|
185
|
+
logout(harness: AgentHarness, env?: Record<string, string>): Promise<HarnessAuth> {
|
|
186
|
+
return this.logins.logout(harness, env);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Every change of a harness's login and every login's end. Returns the unsubscribe. */
|
|
190
|
+
onAuthUpdated(listener: (update: AuthUpdated) => void): () => void {
|
|
191
|
+
return this.logins.onUpdated(listener);
|
|
192
|
+
}
|
|
193
|
+
|
|
151
194
|
/**
|
|
152
195
|
* Answer a pending `permission.requested` event. Returns false when the
|
|
153
196
|
* request is unknown (already resolved, cancelled, or a sessionId mismatch).
|
|
154
197
|
*/
|
|
155
198
|
respondPermission(sessionId: string, requestId: string, outcome: PermissionOutcome): boolean {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
199
|
+
return this.respond("permission", sessionId, requestId, outcome);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Answer a pending `elicitation.requested` event. Returns false when the
|
|
204
|
+
* request is unknown (already resolved, cancelled, or a sessionId mismatch).
|
|
205
|
+
*/
|
|
206
|
+
respondElicitation(sessionId: string, requestId: string, outcome: ElicitationOutcome): boolean {
|
|
207
|
+
return this.respond("elicitation", sessionId, requestId, outcome);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private respond<K extends RequestKind>(
|
|
211
|
+
kind: K,
|
|
212
|
+
sessionId: string,
|
|
213
|
+
requestId: string,
|
|
214
|
+
answer: RequestAnswers[K],
|
|
215
|
+
): boolean {
|
|
216
|
+
return this.turnsOf(sessionId).some((turn) => turn.requests.respond(kind, requestId, answer));
|
|
160
217
|
}
|
|
161
218
|
|
|
162
219
|
/**
|
|
163
220
|
* Probe how `run()` would admit this request WITHOUT executing anything:
|
|
164
221
|
* `new` (would run), `inflight`/`completed` (an identical request was
|
|
165
222
|
* already admitted — a retry must converge, not re-execute). Throws
|
|
166
|
-
* `TurnConflictError` when this turnId was admitted with DIFFERENT input
|
|
223
|
+
* `TurnConflictError` when this turnId was admitted with DIFFERENT input,
|
|
224
|
+
* and the turn's `EventSinkError` when its durable sink stopped it.
|
|
167
225
|
* Wire seats use this to quick-ack a duplicate instead of starting it.
|
|
168
226
|
*/
|
|
169
227
|
admission(request: RunRequest): TurnAdmission {
|
|
170
|
-
const
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
228
|
+
const known = this.known(request);
|
|
229
|
+
if (!known) return { status: "new" };
|
|
230
|
+
return known instanceof Turn
|
|
231
|
+
? { status: "inflight" }
|
|
232
|
+
: { status: "completed", summary: known.summary };
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** The admitted turn a request names, in flight or settled; throws as `admission` says. */
|
|
236
|
+
private known(request: RunRequest): Turn | { summary: RunSummary } | undefined {
|
|
237
|
+
const { sessionId, turnId } = request;
|
|
238
|
+
const known =
|
|
239
|
+
this.turns.get(turnKeyOf(sessionId, turnId)) ??
|
|
240
|
+
this.sessions.get(sessionId)?.settled.get(turnId);
|
|
241
|
+
if (!known) return undefined;
|
|
242
|
+
if (known.inputKey !== inputKeyOf(request)) throw new TurnConflictError(sessionId, turnId);
|
|
243
|
+
if (known instanceof Turn) return known;
|
|
244
|
+
// It may have run tools before its sink failed: never run it again.
|
|
245
|
+
if ("failure" in known) throw known.failure;
|
|
246
|
+
return known;
|
|
185
247
|
}
|
|
186
248
|
|
|
187
249
|
run(
|
|
@@ -190,349 +252,66 @@ export class AgentRuntime {
|
|
|
190
252
|
opts: { signal?: AbortSignal } = {},
|
|
191
253
|
): Promise<RunSummary> {
|
|
192
254
|
if (this.shutdownPromise) return Promise.reject(new Error("agent runtime is shutting down"));
|
|
255
|
+
// Checked once, here: the wire refuses an invalid request before it
|
|
256
|
+
// reaches the engine, and an embedder's is refused the same way.
|
|
257
|
+
const parsed = RunRequestSchema.safeParse(request);
|
|
258
|
+
if (!parsed.success) {
|
|
259
|
+
const issues = parsed.error.issues.map((issue) => ({
|
|
260
|
+
path: issue.path.join("."),
|
|
261
|
+
message: issue.message,
|
|
262
|
+
}));
|
|
263
|
+
return Promise.reject(new InvalidRequestError(issues));
|
|
264
|
+
}
|
|
193
265
|
// Idempotent admission (the embed-tier guard a retried DO RPC needs): a
|
|
194
266
|
// duplicate {sessionId, turnId} with identical input converges on the
|
|
195
267
|
// original run — the in-flight promise or the memoized summary — and is
|
|
196
268
|
// never executed twice. The retry's sink receives no events; the first
|
|
197
269
|
// delivery (or a wire-tier replay) owns those. Same ids with different
|
|
198
270
|
// input is a caller bug, surfaced loudly instead of silently re-running.
|
|
199
|
-
let
|
|
271
|
+
let known: Turn | { summary: RunSummary } | undefined;
|
|
200
272
|
try {
|
|
201
|
-
|
|
273
|
+
known = this.known(parsed.data);
|
|
202
274
|
} catch (error) {
|
|
203
275
|
return Promise.reject(error);
|
|
204
276
|
}
|
|
205
|
-
if (
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
const
|
|
212
|
-
|
|
213
|
-
//
|
|
214
|
-
// turn.started must converge, not double-execute.
|
|
215
|
-
const running = Promise.resolve().then(() => this.executeRun(request, sink, opts));
|
|
216
|
-
this.inflightTurns.set(turnKey, { inputKey, promise: running });
|
|
217
|
-
this.activeRuns.add(running);
|
|
218
|
-
// One handler, not a .finally chain: the inflight→completed transition
|
|
277
|
+
if (known instanceof Turn) return known.running;
|
|
278
|
+
if (known) return Promise.resolve(known.summary);
|
|
279
|
+
const signal = opts.signal
|
|
280
|
+
? AbortSignal.any([opts.signal, this.stopping.signal])
|
|
281
|
+
: this.stopping.signal;
|
|
282
|
+
const turn = new Turn(parsed.data, inputKeyOf(parsed.data), sink, signal, this.host);
|
|
283
|
+
const key = turnKeyOf(turn.sessionId, turn.turnId);
|
|
284
|
+
this.turns.set(key, turn);
|
|
285
|
+
// One handler, not a .finally chain: the inflight→settled transition
|
|
219
286
|
// must be atomic within a single microtask, or a concurrent admission
|
|
220
|
-
// probe could observe the settled turn as still inflight.
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
this.activeRuns.delete(running);
|
|
226
|
-
},
|
|
287
|
+
// probe could observe the settled turn as still inflight. Remembered in
|
|
288
|
+
// the same step it leaves `turns`: a retried steer always finds the
|
|
289
|
+
// turn's answers.
|
|
290
|
+
turn.running.then(
|
|
291
|
+
(summary) => this.settle(key, turn, { summary }),
|
|
227
292
|
// A rejected run is NOT memoized: it died before executing the turn
|
|
228
|
-
// loop (registry/setup), so a retry is allowed to try again.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
this.
|
|
232
|
-
},
|
|
293
|
+
// loop (registry/setup), so a retry is allowed to try again. Unless its
|
|
294
|
+
// durable sink stopped it, possibly after it had run tools.
|
|
295
|
+
(error) =>
|
|
296
|
+
this.settle(key, turn, error instanceof EventSinkError ? { failure: error } : undefined),
|
|
233
297
|
);
|
|
234
|
-
return running;
|
|
298
|
+
return turn.running;
|
|
235
299
|
}
|
|
236
300
|
|
|
237
|
-
private
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
summary: RunSummary,
|
|
301
|
+
private settle(
|
|
302
|
+
key: string,
|
|
303
|
+
turn: Turn,
|
|
304
|
+
settled: { summary: RunSummary } | { failure: EventSinkError } | undefined,
|
|
242
305
|
): void {
|
|
243
|
-
|
|
244
|
-
if (!
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
perSession.delete(oldest);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
private async executeRun(
|
|
257
|
-
request: RunRequest,
|
|
258
|
-
sink: EventSink,
|
|
259
|
-
opts: { signal?: AbortSignal },
|
|
260
|
-
): Promise<RunSummary> {
|
|
261
|
-
const { sessionId, turnId, input, config } = request;
|
|
262
|
-
const agent = this.registry.getAgent(config.harness);
|
|
263
|
-
const transformer = this.registry.getAdapter(config.harness)({ sessionId });
|
|
264
|
-
const execution: TurnExecution = {
|
|
265
|
-
harness: config.harness,
|
|
266
|
-
...(config.model !== undefined && { model: config.model }),
|
|
267
|
-
...(config.thinkingLevel !== undefined && { thinkingLevel: config.thinkingLevel }),
|
|
268
|
-
};
|
|
269
|
-
const processor = new EventProcessor(sessionId, turnId, execution);
|
|
270
|
-
const modelThinking =
|
|
271
|
-
config.model !== undefined
|
|
272
|
-
? this.modelLists.thinkingFor(
|
|
273
|
-
{
|
|
274
|
-
harness: config.harness,
|
|
275
|
-
cwd: config.cwd,
|
|
276
|
-
sessionId,
|
|
277
|
-
env: config.env,
|
|
278
|
-
apiKey: config.apiKey,
|
|
279
|
-
},
|
|
280
|
-
config.model,
|
|
281
|
-
)
|
|
282
|
-
: undefined;
|
|
283
|
-
let applied: AppliedExecution | undefined;
|
|
284
|
-
|
|
285
|
-
// Isolate sink failures: a misbehaving transport must never break the
|
|
286
|
-
// turn's lifecycle bracketing (turn.started ... turn.ended).
|
|
287
|
-
const emit = async (e: LifecycleEvent) => {
|
|
288
|
-
try {
|
|
289
|
-
await sink.emit(e);
|
|
290
|
-
} catch (err) {
|
|
291
|
-
// The turn must not fail on a misbehaving sink — but the host gets
|
|
292
|
-
// to know its sink dropped an event.
|
|
293
|
-
emitDiagnostic(this.options.onDiagnostic, {
|
|
294
|
-
type: "sinkError",
|
|
295
|
-
sessionId,
|
|
296
|
-
message: `sink emit failed for ${e.type}: ${err instanceof Error ? err.message : String(err)}`,
|
|
297
|
-
detail: err,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
let nativeSessionId: string | undefined;
|
|
303
|
-
let resumed: boolean | undefined;
|
|
304
|
-
let sessionEmitted = false;
|
|
305
|
-
const flushSession = async () => {
|
|
306
|
-
if (nativeSessionId && !sessionEmitted) {
|
|
307
|
-
sessionEmitted = true;
|
|
308
|
-
await emit({
|
|
309
|
-
type: "session.created",
|
|
310
|
-
sessionId,
|
|
311
|
-
nativeSessionId,
|
|
312
|
-
harness: config.harness,
|
|
313
|
-
model: config.model,
|
|
314
|
-
...(resumed !== undefined && { resumed }),
|
|
315
|
-
timestamp: Date.now(),
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
// --- permission broker (one scope per turn) ----------------------------
|
|
321
|
-
const turnRequestIds = new Set<string>();
|
|
322
|
-
/** Every settle()'s `permission.resolved` emission, whichever caller
|
|
323
|
-
* settled it (broker answer, external respondPermission, cancel) — the
|
|
324
|
-
* turn-end drain awaits these so `turn.ended` NEVER starts before a
|
|
325
|
-
* resolved emission completed. */
|
|
326
|
-
const settleEmits: Array<Promise<void> | void> = [];
|
|
327
|
-
const requestPermission = async (
|
|
328
|
-
toolCall: PermissionToolCall,
|
|
329
|
-
permOpts?: { signal?: AbortSignal },
|
|
330
|
-
): Promise<PermissionDecision> => {
|
|
331
|
-
if (permOpts?.signal?.aborted) return { decision: "cancel" };
|
|
332
|
-
// A standing `*_always` rule from an earlier prompt in this session
|
|
333
|
-
// answers without a round-trip (and without fake prompt events). The
|
|
334
|
-
// rule carries the verdict only — an `updatedInput` edit belongs to the
|
|
335
|
-
// call it was made for, never to every later call to the same tool.
|
|
336
|
-
const standing = this.alwaysDecisions.get(sessionId)?.get(toolCall.toolName);
|
|
337
|
-
if (standing) {
|
|
338
|
-
return standing === "allow"
|
|
339
|
-
? { decision: "allow" }
|
|
340
|
-
: { decision: "deny", reason: "Denied by a standing rule" };
|
|
341
|
-
}
|
|
342
|
-
const requestId = generateUUIDv7();
|
|
343
|
-
// Register BEFORE emitting so even a sink that answers synchronously
|
|
344
|
-
// from its emit() finds the pending entry.
|
|
345
|
-
let resolveOutcome!: (o: PermissionOutcome) => void;
|
|
346
|
-
const outcomePromise = new Promise<PermissionOutcome>((resolve) => {
|
|
347
|
-
resolveOutcome = resolve;
|
|
348
|
-
});
|
|
349
|
-
const settle = (o: PermissionOutcome): Promise<void> | void => {
|
|
350
|
-
if (!this.pendingPermissions.delete(requestId)) return;
|
|
351
|
-
turnRequestIds.delete(requestId);
|
|
352
|
-
resolveOutcome(o);
|
|
353
|
-
// Recorded so the in-run drain sequences it before turn.ended no
|
|
354
|
-
// matter WHO settled (broker, respondPermission, cancel) — external
|
|
355
|
-
// callers themselves ignore the returned promise.
|
|
356
|
-
const emitted = emit({
|
|
357
|
-
type: "permission.resolved",
|
|
358
|
-
sessionId,
|
|
359
|
-
turnId,
|
|
360
|
-
requestId,
|
|
361
|
-
outcome: o,
|
|
362
|
-
timestamp: Date.now(),
|
|
363
|
-
});
|
|
364
|
-
settleEmits.push(emitted);
|
|
365
|
-
return emitted;
|
|
366
|
-
};
|
|
367
|
-
this.pendingPermissions.set(requestId, { sessionId, settle });
|
|
368
|
-
turnRequestIds.add(requestId);
|
|
369
|
-
permOpts?.signal?.addEventListener("abort", () => void settle({ outcome: "cancelled" }), {
|
|
370
|
-
once: true,
|
|
371
|
-
});
|
|
372
|
-
await emit({
|
|
373
|
-
type: "permission.requested",
|
|
374
|
-
sessionId,
|
|
375
|
-
turnId,
|
|
376
|
-
requestId,
|
|
377
|
-
title: toolCall.title ?? `Allow tool: ${toolCall.toolName}`,
|
|
378
|
-
toolCall,
|
|
379
|
-
options: PERMISSION_OPTIONS,
|
|
380
|
-
timestamp: Date.now(),
|
|
381
|
-
});
|
|
382
|
-
const outcome = await outcomePromise;
|
|
383
|
-
if (outcome.outcome === "cancelled") return { decision: "cancel" };
|
|
384
|
-
const selected = PERMISSION_OPTIONS.find((o) => o.optionId === outcome.optionId);
|
|
385
|
-
const allowed = selected?.kind === "allow_once" || selected?.kind === "allow_always";
|
|
386
|
-
// An `*_always` answer becomes a standing per-session rule: later calls
|
|
387
|
-
// to the same tool skip the round-trip entirely (the user already gave
|
|
388
|
-
// a durable answer — re-asking would be noise, re-emitting events would
|
|
389
|
-
// fake a prompt that never happened). Cleared on session close.
|
|
390
|
-
if (selected?.kind === "allow_always" || selected?.kind === "reject_always") {
|
|
391
|
-
let rules = this.alwaysDecisions.get(sessionId);
|
|
392
|
-
if (!rules) {
|
|
393
|
-
rules = new Map();
|
|
394
|
-
this.alwaysDecisions.set(sessionId, rules);
|
|
395
|
-
}
|
|
396
|
-
rules.set(toolCall.toolName, allowed ? "allow" : "deny");
|
|
397
|
-
}
|
|
398
|
-
return allowed
|
|
399
|
-
? {
|
|
400
|
-
decision: "allow",
|
|
401
|
-
// What was approved is what runs (C1): an edited input replaces
|
|
402
|
-
// the original all the way into the harness.
|
|
403
|
-
...(outcome.updatedInput !== undefined && { updatedInput: outcome.updatedInput }),
|
|
404
|
-
}
|
|
405
|
-
: { decision: "deny", reason: "Denied by user" };
|
|
406
|
-
};
|
|
407
|
-
/** Cancellation / turn end resolves everything still pending as cancelled.
|
|
408
|
-
* Awaited so every `permission.resolved` is emitted before `turn.ended`. */
|
|
409
|
-
const drainPermissions = async () => {
|
|
410
|
-
const settles = [...turnRequestIds].map((requestId) =>
|
|
411
|
-
this.pendingPermissions.get(requestId)?.settle({ outcome: "cancelled" }),
|
|
412
|
-
);
|
|
413
|
-
// Also the already-settled requests whose resolved emission is still in
|
|
414
|
-
// flight (settle() removed them from the pending map immediately).
|
|
415
|
-
await Promise.all([...settles, ...settleEmits]);
|
|
416
|
-
};
|
|
417
|
-
|
|
418
|
-
await emit({ type: "turn.started", turnId, sessionId, execution, timestamp: Date.now() });
|
|
419
|
-
|
|
420
|
-
// The user echo (spec §7.2): the submitted input goes back onto the stream
|
|
421
|
-
// as a complete user message (outputIndex 0) before any harness output, so
|
|
422
|
-
// the stream is a complete transcript and multi-client attach works.
|
|
423
|
-
for (const le of processor.echoUserMessage(input)) await emit(le);
|
|
424
|
-
|
|
425
|
-
const options: AgentExecuteOptions = {
|
|
426
|
-
sessionId,
|
|
427
|
-
turnId,
|
|
428
|
-
cwd: config.cwd,
|
|
429
|
-
model: config.model,
|
|
430
|
-
thinkingLevel: config.thinkingLevel,
|
|
431
|
-
permissionMode: config.permissionMode,
|
|
432
|
-
maxTurns: config.maxTurns,
|
|
433
|
-
subagentMode: config.subagentMode,
|
|
434
|
-
systemPromptAppend: config.systemPromptAppend,
|
|
435
|
-
resumeSessionId: config.resumeSessionId,
|
|
436
|
-
resumeSessionAt: config.resumeSessionAt,
|
|
437
|
-
additionalDirectories: config.additionalDirectories,
|
|
438
|
-
mcpServers: config.mcpServers,
|
|
439
|
-
env: config.env,
|
|
440
|
-
apiKey: config.apiKey,
|
|
441
|
-
disableTools: config.disableTools,
|
|
442
|
-
...(modelThinking && { modelThinking }),
|
|
443
|
-
signal: opts.signal,
|
|
444
|
-
onNativeSession: (id, info) => {
|
|
445
|
-
// Agents report once the native conversation is confirmed; guard against a
|
|
446
|
-
// misbehaving harness re-reporting after emission. Agents always pass
|
|
447
|
-
// their honest `resumed` judgment — the runtime surfaces it only when
|
|
448
|
-
// this turn actually REQUESTED a resume.
|
|
449
|
-
if (sessionEmitted) return;
|
|
450
|
-
nativeSessionId = id;
|
|
451
|
-
if (config.resumeSessionId && info?.resumed !== undefined) resumed = info.resumed;
|
|
452
|
-
},
|
|
453
|
-
onPermissionRequest: requestPermission,
|
|
454
|
-
onExecution: (update) => {
|
|
455
|
-
applied = { ...applied, ...update };
|
|
456
|
-
},
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
let cancelled = false;
|
|
460
|
-
let errored: ErrorInfo | undefined;
|
|
461
|
-
|
|
462
|
-
try {
|
|
463
|
-
for await (const raw of agent.execute(input, options)) {
|
|
464
|
-
await flushSession();
|
|
465
|
-
if (config.includeRaw) {
|
|
466
|
-
await emit({
|
|
467
|
-
type: "raw",
|
|
468
|
-
sessionId,
|
|
469
|
-
turnId,
|
|
470
|
-
harness: config.harness,
|
|
471
|
-
data: raw,
|
|
472
|
-
timestamp: Date.now(),
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
for (const ae of transformer.process(raw)) {
|
|
476
|
-
for (const le of processor.handle(ae)) await emit(le);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
await flushSession();
|
|
480
|
-
} catch (err) {
|
|
481
|
-
cancelled = isCancellation(err);
|
|
482
|
-
if (!cancelled) {
|
|
483
|
-
const category = classifyError(err);
|
|
484
|
-
const message = readableErrorMessage(err instanceof Error ? err.message : String(err));
|
|
485
|
-
errored = { category, message };
|
|
486
|
-
await emit({
|
|
487
|
-
type: "error",
|
|
488
|
-
turnId,
|
|
489
|
-
sessionId,
|
|
490
|
-
category,
|
|
491
|
-
message,
|
|
492
|
-
recoverable: isRecoverable(category),
|
|
493
|
-
stack: err instanceof Error ? err.stack : undefined,
|
|
494
|
-
timestamp: Date.now(),
|
|
495
|
-
});
|
|
496
|
-
}
|
|
497
|
-
} finally {
|
|
498
|
-
await drainPermissions();
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
const result = transformer.finish();
|
|
502
|
-
cancelled = cancelled || Boolean(result.cancelled);
|
|
503
|
-
if (result.error && !errored && !cancelled) {
|
|
504
|
-
errored = {
|
|
505
|
-
category: classifyError(new Error(result.error)),
|
|
506
|
-
message: readableErrorMessage(result.error),
|
|
507
|
-
};
|
|
508
|
-
}
|
|
509
|
-
const stopReason: StopReason = cancelled
|
|
510
|
-
? "cancelled"
|
|
511
|
-
: errored
|
|
512
|
-
? "error"
|
|
513
|
-
: (result.stopReason ?? "end_turn");
|
|
514
|
-
// What the harness configured ran only if its model answered: a turn that
|
|
515
|
-
// failed or was cancelled first ran nothing.
|
|
516
|
-
const ran =
|
|
517
|
-
processor.modelAnswered || (stopReason !== "error" && stopReason !== "cancelled")
|
|
518
|
-
? applied
|
|
519
|
-
: undefined;
|
|
520
|
-
for (const le of processor.finish(result, stopReason, errored, ran)) await emit(le);
|
|
521
|
-
|
|
522
|
-
return {
|
|
523
|
-
sessionId,
|
|
524
|
-
turnId,
|
|
525
|
-
harness: config.harness,
|
|
526
|
-
nativeSessionId,
|
|
527
|
-
...(resumed !== undefined && { resumed }),
|
|
528
|
-
usage: result.usage ?? DEFAULT_TOKEN_USAGE,
|
|
529
|
-
execution: endedExecution(execution, result, ran),
|
|
530
|
-
stopReason,
|
|
531
|
-
finishReason: result.finishReason,
|
|
532
|
-
cost: result.cost,
|
|
533
|
-
error: errored,
|
|
534
|
-
cancelled,
|
|
535
|
-
};
|
|
306
|
+
if (this.turns.get(key) === turn) this.turns.delete(key);
|
|
307
|
+
if (!settled) return;
|
|
308
|
+
const { settled: window } = this.memoryOf(turn.sessionId);
|
|
309
|
+
setBounded(
|
|
310
|
+
window,
|
|
311
|
+
turn.turnId,
|
|
312
|
+
{ inputKey: turn.inputKey, steers: turn.steers.answers(), ...settled },
|
|
313
|
+
SETTLED_TURNS,
|
|
314
|
+
);
|
|
536
315
|
}
|
|
537
316
|
|
|
538
317
|
/**
|
|
@@ -543,13 +322,56 @@ export class AgentRuntime {
|
|
|
543
322
|
*/
|
|
544
323
|
async cancel(harness: AgentHarness, sessionId: string): Promise<CancelResult> {
|
|
545
324
|
// Unblock any harness parked on an approval before (and regardless of)
|
|
546
|
-
// the agent-level abort.
|
|
547
|
-
for (const
|
|
548
|
-
if (pending.sessionId === sessionId) void pending.settle({ outcome: "cancelled" });
|
|
549
|
-
}
|
|
325
|
+
// the agent-level abort.
|
|
326
|
+
for (const turn of this.turnsOf(sessionId)) void turn.requestCancel();
|
|
550
327
|
return await this.registry.getAgent(harness).cancel(sessionId);
|
|
551
328
|
}
|
|
552
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Add input to a running turn (`turn/steer`). The agent reads it at its
|
|
332
|
+
* next step, where the stream shows it as a user message; a turn that ends
|
|
333
|
+
* first lists it in `turn.ended.undeliveredSteers`. A retry (same
|
|
334
|
+
* `steerId`, same input) converges on the first answer, also after the turn
|
|
335
|
+
* ended; the same id with other input throws `TurnConflictError`. Input the
|
|
336
|
+
* harness cannot take throws, as it would fail a turn.
|
|
337
|
+
*/
|
|
338
|
+
async steer(sessionId: string, request: SteerRequest): Promise<TurnSteerResult> {
|
|
339
|
+
const { turnId, steerId, input } = request;
|
|
340
|
+
if (typeof input === "string" ? input.trim() === "" : input.length === 0) {
|
|
341
|
+
throw new Error("a steer carries input");
|
|
342
|
+
}
|
|
343
|
+
const inputKey = canonicalJson(input);
|
|
344
|
+
const turn = this.turns.get(turnKeyOf(sessionId, turnId));
|
|
345
|
+
const known = turn
|
|
346
|
+
? turn.steers.find(steerId)
|
|
347
|
+
: this.sessions.get(sessionId)?.settled.get(turnId)?.steers.get(steerId);
|
|
348
|
+
if (known) {
|
|
349
|
+
if (known.inputKey !== inputKey) throw new TurnConflictError(sessionId, turnId, steerId);
|
|
350
|
+
const first = await known.result;
|
|
351
|
+
return first.outcome === "steered" ? { ...first, deduplicated: true } : first;
|
|
352
|
+
}
|
|
353
|
+
// A steer id names a message in the session, as a turn id does.
|
|
354
|
+
if (this.steerIdTaken(sessionId, steerId))
|
|
355
|
+
throw new TurnConflictError(sessionId, turnId, steerId);
|
|
356
|
+
if (!turn?.steers.open) {
|
|
357
|
+
const active = this.turnsOf(sessionId).find((t) => t.steers.open);
|
|
358
|
+
return { outcome: "no_active_turn", ...(active && { activeTurnId: active.turnId }) };
|
|
359
|
+
}
|
|
360
|
+
const agent = this.registry.getAgent(turn.harness);
|
|
361
|
+
const deliver = agent.capabilities.steering ? agent.steer?.bind(agent) : undefined;
|
|
362
|
+
if (!deliver) return { outcome: "unsupported" };
|
|
363
|
+
return await turn.steers.accept(steerId, inputKey, input, () => deliver(sessionId, request));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Whether another turn of the session, live or remembered, took this steer id. */
|
|
367
|
+
private steerIdTaken(sessionId: string, steerId: string): boolean {
|
|
368
|
+
const settled = [...(this.sessions.get(sessionId)?.settled.values() ?? [])];
|
|
369
|
+
return (
|
|
370
|
+
this.turnsOf(sessionId).some((turn) => turn.steers.find(steerId)) ||
|
|
371
|
+
settled.some((turn) => turn.steers.has(steerId))
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
553
375
|
/**
|
|
554
376
|
* Call after the host resumes from suspension, before admitting new turns.
|
|
555
377
|
* Retains conversations and admission receipts. Claude and Codex app-server
|
|
@@ -562,38 +384,63 @@ export class AgentRuntime {
|
|
|
562
384
|
}
|
|
563
385
|
}
|
|
564
386
|
|
|
387
|
+
/**
|
|
388
|
+
* Watch the native processes this runtime's harnesses start for sessions,
|
|
389
|
+
* and see each gone: what a host keeps (a journal does) so that its next
|
|
390
|
+
* start can call `stopOrphans`. Returns the unsubscribe. Throwing at
|
|
391
|
+
* `started` fails that spawn.
|
|
392
|
+
*/
|
|
393
|
+
onNativeProcess(observer: (event: NativeProcessEvent) => void): () => void {
|
|
394
|
+
return this.registry.processes.observe(observer);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* The harnesses whose agents start their native processes through this
|
|
399
|
+
* runtime's, which records them: a restart can vouch for their sessions.
|
|
400
|
+
* A session of any other harness stays fenced when a restart cuts it off.
|
|
401
|
+
*/
|
|
402
|
+
recordedHarnesses(): Set<AgentHarness> {
|
|
403
|
+
return new Set(
|
|
404
|
+
this.registry
|
|
405
|
+
.list()
|
|
406
|
+
.filter((harness) => this.registry.getAgent(harness).processes === this.registry.processes),
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// @ref LLP 0007#records-and-the-restart-sweep — verify, then stop what is still ours
|
|
411
|
+
/**
|
|
412
|
+
* The restart sweep, for records a previous owner of the host's store left:
|
|
413
|
+
* each that still names its running process (same boot, start time and
|
|
414
|
+
* executable) is stopped with its tool sessions; one whose pid now names
|
|
415
|
+
* another process is left alone. Says what became of each.
|
|
416
|
+
*/
|
|
417
|
+
stopOrphans<R extends NativeRecord>(records: readonly R[]): Promise<Map<R, OrphanOutcome>> {
|
|
418
|
+
return this.registry.processes.stopOrphans(records);
|
|
419
|
+
}
|
|
420
|
+
|
|
565
421
|
/** Dispose one idle logical session and its harness-native resources. */
|
|
566
422
|
async closeSession(harness: AgentHarness, sessionId: string): Promise<void> {
|
|
567
|
-
this.
|
|
568
|
-
this.
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
.map((pending) => pending.settle({ outcome: "cancelled" })),
|
|
573
|
-
);
|
|
423
|
+
this.sessions.delete(sessionId);
|
|
424
|
+
await Promise.all(this.turnsOf(sessionId).map((turn) => turn.requestCancel()));
|
|
425
|
+
// A harness this runtime does not run (a session restored from a journal
|
|
426
|
+
// written with another registry) holds nothing here to release.
|
|
427
|
+
if (!this.registry.has(harness)) return;
|
|
574
428
|
const agent = this.registry.getAgent(harness);
|
|
575
429
|
if (agent.release) await agent.release(sessionId);
|
|
576
430
|
else await agent.cancel(sessionId);
|
|
577
431
|
}
|
|
578
432
|
|
|
579
|
-
/** Give up on stragglers after this long; the process is exiting anyway. */
|
|
580
|
-
private static readonly DEFAULT_DRAIN_TIMEOUT_MS = 10_000;
|
|
581
|
-
|
|
582
433
|
shutdown(opts: { drainTimeoutMs?: number } = {}): Promise<void> {
|
|
583
434
|
// Memoized: the first caller's timeout wins.
|
|
584
|
-
this.shutdownPromise ??= this.performShutdown(
|
|
585
|
-
opts.drainTimeoutMs ?? AgentRuntime.DEFAULT_DRAIN_TIMEOUT_MS,
|
|
586
|
-
);
|
|
435
|
+
this.shutdownPromise ??= this.performShutdown(opts.drainTimeoutMs ?? DEFAULT_DRAIN_TIMEOUT_MS);
|
|
587
436
|
return this.shutdownPromise;
|
|
588
437
|
}
|
|
589
438
|
|
|
590
439
|
private async performShutdown(drainTimeoutMs: number): Promise<void> {
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
);
|
|
596
|
-
this.pendingPermissions.clear();
|
|
440
|
+
this.stopping.abort();
|
|
441
|
+
this.logins.shutdown();
|
|
442
|
+
const turns = [...this.turns.values()];
|
|
443
|
+
await Promise.all(turns.map((turn) => turn.requests.cancelAll()));
|
|
597
444
|
let terminationError: unknown;
|
|
598
445
|
try {
|
|
599
446
|
await this.registry.terminateAll();
|
|
@@ -602,14 +449,26 @@ export class AgentRuntime {
|
|
|
602
449
|
}
|
|
603
450
|
// Drain active runs, but don't let a harness that ignores its abort
|
|
604
451
|
// signal hang the process's shutdown forever.
|
|
605
|
-
await Promise.
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
}),
|
|
611
|
-
]);
|
|
612
|
-
this.completedTurns.clear();
|
|
452
|
+
await withTimeout(Promise.allSettled(turns.map((turn) => turn.running)), drainTimeoutMs);
|
|
453
|
+
this.sessions.clear();
|
|
454
|
+
// No CLI outlives the runtime that started it, nor a tool it ran: a
|
|
455
|
+
// host that shuts one runtime down and keeps running relies on no lifeline.
|
|
456
|
+
await this.registry.processes.stopAll();
|
|
613
457
|
if (terminationError !== undefined) throw terminationError;
|
|
614
458
|
}
|
|
459
|
+
|
|
460
|
+
/** The session's admitted turns that have not settled. */
|
|
461
|
+
private turnsOf(sessionId: string): Turn[] {
|
|
462
|
+
return [...this.turns.values()].filter((turn) => turn.sessionId === sessionId);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/** The session's memory, made on first use, and again after `closeSession` forgot it. */
|
|
466
|
+
private memoryOf(sessionId: string): SessionMemory {
|
|
467
|
+
let memory = this.sessions.get(sessionId);
|
|
468
|
+
if (!memory) {
|
|
469
|
+
memory = { standingRules: new StandingRules(), settled: new Map() };
|
|
470
|
+
this.sessions.set(sessionId, memory);
|
|
471
|
+
}
|
|
472
|
+
return memory;
|
|
473
|
+
}
|
|
615
474
|
}
|