@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,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 {
|
|
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";
|
|
32
26
|
import { type EventSink, EventSinkError } from "./event-sink.ts";
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
harness: AgentHarness;
|
|
40
|
-
execution: TurnExecution;
|
|
41
|
-
/** Native session/thread id to persist for a future resume. */
|
|
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
|
-
}
|
|
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,78 +40,57 @@ export type TurnAdmission =
|
|
|
60
40
|
| { status: "inflight" }
|
|
61
41
|
| { status: "completed"; summary: RunSummary };
|
|
62
42
|
|
|
63
|
-
/**
|
|
64
|
-
* Deterministic JSON with sorted object keys and dropped `undefined` members —
|
|
65
|
-
* the identity of a turn's input for idempotent admission. Pure JS (no
|
|
66
|
-
* node:crypto): this module is part of the isolate-safe edge graph.
|
|
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
|
-
}
|
|
77
|
-
|
|
78
43
|
// Caller-supplied IDs need not be UUIDs; encode the tuple without delimiter collisions.
|
|
79
44
|
const turnKeyOf = (sessionId: string, turnId: string) => JSON.stringify([sessionId, turnId]);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
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
|
-
}
|
|
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));
|
|
47
|
+
|
|
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 settled turns per session (bounded LRU). Retries converge on the
|
|
118
|
-
* stored summary, or on the sink failure that stopped the turn mid-execution. */
|
|
119
|
-
private readonly completedTurns = new Map<
|
|
120
|
-
string,
|
|
121
|
-
Map<string, { inputKey: string } & ({ summary: RunSummary } | { failure: EventSinkError })>
|
|
122
|
-
>();
|
|
123
|
-
/** Per-session convergence window; old turns fall out and a stale retry would re-execute. */
|
|
124
|
-
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>();
|
|
125
67
|
private shutdownPromise?: Promise<void>;
|
|
126
68
|
/** Aborted as shutdown begins, and part of every run's signal: a run still
|
|
127
69
|
* setting up then, which its harness has not yet tracked, stops too. */
|
|
128
70
|
private readonly stopping = new AbortController();
|
|
129
71
|
private readonly modelLists = new ModelLists();
|
|
72
|
+
private readonly logins: HarnessLogins;
|
|
73
|
+
private readonly host: TurnHost;
|
|
130
74
|
|
|
131
75
|
constructor(
|
|
132
76
|
private readonly registry: AgentRegistry,
|
|
133
|
-
|
|
134
|
-
) {
|
|
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
|
+
}
|
|
135
94
|
|
|
136
95
|
get harnesses(): AgentHarness[] {
|
|
137
96
|
return this.registry.list();
|
|
@@ -148,19 +107,113 @@ export class AgentRuntime {
|
|
|
148
107
|
* catalog, with `error` saying why. Turns then fit their thinking level to
|
|
149
108
|
* the listed levels of the model they run.
|
|
150
109
|
*/
|
|
151
|
-
async models(query:
|
|
110
|
+
async models(query: ModelsListParams): Promise<ModelList> {
|
|
152
111
|
return await this.modelLists.get(this.registry.getAgent(query.harness), query);
|
|
153
112
|
}
|
|
154
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
|
+
|
|
155
194
|
/**
|
|
156
195
|
* Answer a pending `permission.requested` event. Returns false when the
|
|
157
196
|
* request is unknown (already resolved, cancelled, or a sessionId mismatch).
|
|
158
197
|
*/
|
|
159
198
|
respondPermission(sessionId: string, requestId: string, outcome: PermissionOutcome): boolean {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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));
|
|
164
217
|
}
|
|
165
218
|
|
|
166
219
|
/**
|
|
@@ -172,23 +225,25 @@ export class AgentRuntime {
|
|
|
172
225
|
* Wire seats use this to quick-ack a duplicate instead of starting it.
|
|
173
226
|
*/
|
|
174
227
|
admission(request: RunRequest): TurnAdmission {
|
|
175
|
-
const
|
|
176
|
-
if (
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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;
|
|
192
247
|
}
|
|
193
248
|
|
|
194
249
|
run(
|
|
@@ -197,368 +252,66 @@ export class AgentRuntime {
|
|
|
197
252
|
opts: { signal?: AbortSignal } = {},
|
|
198
253
|
): Promise<RunSummary> {
|
|
199
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
|
+
}
|
|
200
265
|
// Idempotent admission (the embed-tier guard a retried DO RPC needs): a
|
|
201
266
|
// duplicate {sessionId, turnId} with identical input converges on the
|
|
202
267
|
// original run — the in-flight promise or the memoized summary — and is
|
|
203
268
|
// never executed twice. The retry's sink receives no events; the first
|
|
204
269
|
// delivery (or a wire-tier replay) owns those. Same ids with different
|
|
205
270
|
// input is a caller bug, surfaced loudly instead of silently re-running.
|
|
206
|
-
let
|
|
271
|
+
let known: Turn | { summary: RunSummary } | undefined;
|
|
207
272
|
try {
|
|
208
|
-
|
|
273
|
+
known = this.known(parsed.data);
|
|
209
274
|
} catch (error) {
|
|
210
275
|
return Promise.reject(error);
|
|
211
276
|
}
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
|
|
220
|
-
//
|
|
221
|
-
// turn.started must converge, not double-execute.
|
|
222
|
-
const running = Promise.resolve().then(() => this.executeRun(request, sink, opts));
|
|
223
|
-
this.inflightTurns.set(turnKey, { inputKey, promise: running });
|
|
224
|
-
this.activeRuns.add(running);
|
|
225
|
-
// 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
|
|
226
286
|
// must be atomic within a single microtask, or a concurrent admission
|
|
227
|
-
// probe could observe the settled turn as still inflight.
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
this.activeRuns.delete(running);
|
|
233
|
-
},
|
|
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 }),
|
|
234
292
|
// A rejected run is NOT memoized: it died before executing the turn
|
|
235
293
|
// loop (registry/setup), so a retry is allowed to try again. Unless its
|
|
236
294
|
// durable sink stopped it, possibly after it had run tools.
|
|
237
|
-
(error) =>
|
|
238
|
-
|
|
239
|
-
this.rememberTurn(request.sessionId, request.turnId, { inputKey, failure: error });
|
|
240
|
-
this.inflightTurns.delete(turnKey);
|
|
241
|
-
this.activeRuns.delete(running);
|
|
242
|
-
},
|
|
295
|
+
(error) =>
|
|
296
|
+
this.settle(key, turn, error instanceof EventSinkError ? { failure: error } : undefined),
|
|
243
297
|
);
|
|
244
|
-
return running;
|
|
298
|
+
return turn.running;
|
|
245
299
|
}
|
|
246
300
|
|
|
247
|
-
private
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
settled: {
|
|
301
|
+
private settle(
|
|
302
|
+
key: string,
|
|
303
|
+
turn: Turn,
|
|
304
|
+
settled: { summary: RunSummary } | { failure: EventSinkError } | undefined,
|
|
251
305
|
): void {
|
|
252
|
-
|
|
253
|
-
if (!
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
perSession.delete(oldest);
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private async executeRun(
|
|
266
|
-
request: RunRequest,
|
|
267
|
-
sink: EventSink,
|
|
268
|
-
opts: { signal?: AbortSignal },
|
|
269
|
-
): Promise<RunSummary> {
|
|
270
|
-
const { sessionId, turnId, input, config } = request;
|
|
271
|
-
const agent = this.registry.getAgent(config.harness);
|
|
272
|
-
const transformer = this.registry.getAdapter(config.harness)({ sessionId });
|
|
273
|
-
const execution: TurnExecution = {
|
|
274
|
-
harness: config.harness,
|
|
275
|
-
...(config.model !== undefined && { model: config.model }),
|
|
276
|
-
...(config.thinkingLevel !== undefined && { thinkingLevel: config.thinkingLevel }),
|
|
277
|
-
};
|
|
278
|
-
const processor = new EventProcessor(sessionId, turnId, execution);
|
|
279
|
-
const modelThinking =
|
|
280
|
-
config.model !== undefined
|
|
281
|
-
? this.modelLists.thinkingFor(
|
|
282
|
-
{
|
|
283
|
-
harness: config.harness,
|
|
284
|
-
cwd: config.cwd,
|
|
285
|
-
sessionId,
|
|
286
|
-
env: config.env,
|
|
287
|
-
apiKey: config.apiKey,
|
|
288
|
-
},
|
|
289
|
-
config.model,
|
|
290
|
-
)
|
|
291
|
-
: undefined;
|
|
292
|
-
let applied: AppliedExecution | undefined;
|
|
293
|
-
|
|
294
|
-
// Isolate sink failures: a misbehaving transport must never break the
|
|
295
|
-
// turn's lifecycle bracketing (turn.started ... turn.ended). Except a
|
|
296
|
-
// sink's EventSinkError: its writes are a durability boundary, so the turn
|
|
297
|
-
// stops rather than run on unrecorded, and every later emit fails with it.
|
|
298
|
-
let fatal: EventSinkError | undefined;
|
|
299
|
-
const emit = async (e: LifecycleEvent) => {
|
|
300
|
-
if (fatal) throw fatal;
|
|
301
|
-
try {
|
|
302
|
-
await sink.emit(e);
|
|
303
|
-
} catch (err) {
|
|
304
|
-
if (err instanceof EventSinkError) {
|
|
305
|
-
fatal = err;
|
|
306
|
-
// Refuses pending permissions and interrupts the harness. Whether
|
|
307
|
-
// the native execution stopped stays unconfirmed.
|
|
308
|
-
void this.cancel(config.harness, sessionId).catch(() => {});
|
|
309
|
-
throw err;
|
|
310
|
-
}
|
|
311
|
-
// The turn must not fail on a misbehaving sink — but the host gets
|
|
312
|
-
// to know its sink dropped an event.
|
|
313
|
-
emitDiagnostic(this.options.onDiagnostic, {
|
|
314
|
-
type: "sinkError",
|
|
315
|
-
sessionId,
|
|
316
|
-
message: `sink emit failed for ${e.type}: ${err instanceof Error ? err.message : String(err)}`,
|
|
317
|
-
detail: err,
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
let nativeSessionId: string | undefined;
|
|
323
|
-
let resumed: boolean | undefined;
|
|
324
|
-
let sessionEmitted = false;
|
|
325
|
-
const flushSession = async () => {
|
|
326
|
-
if (nativeSessionId && !sessionEmitted) {
|
|
327
|
-
sessionEmitted = true;
|
|
328
|
-
await emit({
|
|
329
|
-
type: "session.created",
|
|
330
|
-
sessionId,
|
|
331
|
-
nativeSessionId,
|
|
332
|
-
harness: config.harness,
|
|
333
|
-
model: config.model,
|
|
334
|
-
...(resumed !== undefined && { resumed }),
|
|
335
|
-
timestamp: Date.now(),
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
// --- permission broker (one scope per turn) ----------------------------
|
|
341
|
-
const turnRequestIds = new Set<string>();
|
|
342
|
-
/** Every settle()'s `permission.resolved` emission, whichever caller
|
|
343
|
-
* settled it (broker answer, external respondPermission, cancel) — the
|
|
344
|
-
* turn-end drain awaits these so `turn.ended` NEVER starts before a
|
|
345
|
-
* resolved emission completed. */
|
|
346
|
-
const settleEmits: Array<Promise<void> | void> = [];
|
|
347
|
-
const requestPermission = async (
|
|
348
|
-
toolCall: PermissionToolCall,
|
|
349
|
-
permOpts?: { signal?: AbortSignal },
|
|
350
|
-
): Promise<PermissionDecision> => {
|
|
351
|
-
if (fatal || permOpts?.signal?.aborted) return { decision: "cancel" };
|
|
352
|
-
// A standing `*_always` rule from an earlier prompt in this session
|
|
353
|
-
// answers without a round-trip (and without fake prompt events). The
|
|
354
|
-
// rule carries the verdict only — an `updatedInput` edit belongs to the
|
|
355
|
-
// call it was made for, never to every later call to the same tool.
|
|
356
|
-
const standing = this.alwaysDecisions.get(sessionId)?.get(toolCall.toolName);
|
|
357
|
-
if (standing) {
|
|
358
|
-
return standing === "allow"
|
|
359
|
-
? { decision: "allow" }
|
|
360
|
-
: { decision: "deny", reason: "Denied by a standing rule" };
|
|
361
|
-
}
|
|
362
|
-
const requestId = generateUUIDv7();
|
|
363
|
-
// Register BEFORE emitting so even a sink that answers synchronously
|
|
364
|
-
// from its emit() finds the pending entry.
|
|
365
|
-
let resolveOutcome!: (o: PermissionOutcome) => void;
|
|
366
|
-
const outcomePromise = new Promise<PermissionOutcome>((resolve) => {
|
|
367
|
-
resolveOutcome = resolve;
|
|
368
|
-
});
|
|
369
|
-
const settle = (o: PermissionOutcome): Promise<void> | void => {
|
|
370
|
-
if (!this.pendingPermissions.delete(requestId)) return;
|
|
371
|
-
turnRequestIds.delete(requestId);
|
|
372
|
-
// The harness gets the decision once `permission.resolved` is
|
|
373
|
-
// written, so a durable sink records an approval before its tool
|
|
374
|
-
// runs and a failed write refuses it. Recorded so the in-run drain
|
|
375
|
-
// sequences it before turn.ended no matter WHO settled (broker,
|
|
376
|
-
// respondPermission, cancel) — external callers ignore the promise.
|
|
377
|
-
const settled = emit({
|
|
378
|
-
type: "permission.resolved",
|
|
379
|
-
sessionId,
|
|
380
|
-
turnId,
|
|
381
|
-
requestId,
|
|
382
|
-
outcome: o,
|
|
383
|
-
timestamp: Date.now(),
|
|
384
|
-
}).then(
|
|
385
|
-
() => resolveOutcome(o),
|
|
386
|
-
() => resolveOutcome({ outcome: "cancelled" }),
|
|
387
|
-
);
|
|
388
|
-
settleEmits.push(settled);
|
|
389
|
-
return settled;
|
|
390
|
-
};
|
|
391
|
-
this.pendingPermissions.set(requestId, { sessionId, settle });
|
|
392
|
-
turnRequestIds.add(requestId);
|
|
393
|
-
permOpts?.signal?.addEventListener("abort", () => void settle({ outcome: "cancelled" }), {
|
|
394
|
-
once: true,
|
|
395
|
-
});
|
|
396
|
-
await emit({
|
|
397
|
-
type: "permission.requested",
|
|
398
|
-
sessionId,
|
|
399
|
-
turnId,
|
|
400
|
-
requestId,
|
|
401
|
-
title: toolCall.title ?? `Allow tool: ${toolCall.toolName}`,
|
|
402
|
-
toolCall,
|
|
403
|
-
options: PERMISSION_OPTIONS,
|
|
404
|
-
timestamp: Date.now(),
|
|
405
|
-
});
|
|
406
|
-
const outcome = await outcomePromise;
|
|
407
|
-
if (outcome.outcome === "cancelled") return { decision: "cancel" };
|
|
408
|
-
const selected = PERMISSION_OPTIONS.find((o) => o.optionId === outcome.optionId);
|
|
409
|
-
const allowed = selected?.kind === "allow_once" || selected?.kind === "allow_always";
|
|
410
|
-
// An `*_always` answer becomes a standing per-session rule: later calls
|
|
411
|
-
// to the same tool skip the round-trip entirely (the user already gave
|
|
412
|
-
// a durable answer — re-asking would be noise, re-emitting events would
|
|
413
|
-
// fake a prompt that never happened). Cleared on session close.
|
|
414
|
-
if (selected?.kind === "allow_always" || selected?.kind === "reject_always") {
|
|
415
|
-
let rules = this.alwaysDecisions.get(sessionId);
|
|
416
|
-
if (!rules) {
|
|
417
|
-
rules = new Map();
|
|
418
|
-
this.alwaysDecisions.set(sessionId, rules);
|
|
419
|
-
}
|
|
420
|
-
rules.set(toolCall.toolName, allowed ? "allow" : "deny");
|
|
421
|
-
}
|
|
422
|
-
return allowed
|
|
423
|
-
? {
|
|
424
|
-
decision: "allow",
|
|
425
|
-
// What was approved is what runs (C1): an edited input replaces
|
|
426
|
-
// the original all the way into the harness.
|
|
427
|
-
...(outcome.updatedInput !== undefined && { updatedInput: outcome.updatedInput }),
|
|
428
|
-
}
|
|
429
|
-
: { decision: "deny", reason: "Denied by user" };
|
|
430
|
-
};
|
|
431
|
-
/** Cancellation / turn end resolves everything still pending as cancelled.
|
|
432
|
-
* Awaited so every `permission.resolved` is emitted before `turn.ended`. */
|
|
433
|
-
const drainPermissions = async () => {
|
|
434
|
-
const settles = [...turnRequestIds].map((requestId) =>
|
|
435
|
-
this.pendingPermissions.get(requestId)?.settle({ outcome: "cancelled" }),
|
|
436
|
-
);
|
|
437
|
-
// Also the already-settled requests whose resolved emission is still in
|
|
438
|
-
// flight (settle() removed them from the pending map immediately).
|
|
439
|
-
await Promise.all([...settles, ...settleEmits]);
|
|
440
|
-
};
|
|
441
|
-
|
|
442
|
-
await emit({ type: "turn.started", turnId, sessionId, execution, timestamp: Date.now() });
|
|
443
|
-
|
|
444
|
-
// The user echo (spec §7.2): the submitted input goes back onto the stream
|
|
445
|
-
// as a complete user message (outputIndex 0) before any harness output, so
|
|
446
|
-
// the stream is a complete transcript and multi-client attach works.
|
|
447
|
-
for (const le of processor.echoUserMessage(input)) await emit(le);
|
|
448
|
-
|
|
449
|
-
const options: AgentExecuteOptions = {
|
|
450
|
-
sessionId,
|
|
451
|
-
turnId,
|
|
452
|
-
cwd: config.cwd,
|
|
453
|
-
model: config.model,
|
|
454
|
-
thinkingLevel: config.thinkingLevel,
|
|
455
|
-
permissionMode: config.permissionMode,
|
|
456
|
-
maxTurns: config.maxTurns,
|
|
457
|
-
subagentMode: config.subagentMode,
|
|
458
|
-
systemPromptAppend: config.systemPromptAppend,
|
|
459
|
-
resumeSessionId: config.resumeSessionId,
|
|
460
|
-
resumeSessionAt: config.resumeSessionAt,
|
|
461
|
-
additionalDirectories: config.additionalDirectories,
|
|
462
|
-
mcpServers: config.mcpServers,
|
|
463
|
-
env: config.env,
|
|
464
|
-
apiKey: config.apiKey,
|
|
465
|
-
disableTools: config.disableTools,
|
|
466
|
-
...(modelThinking && { modelThinking }),
|
|
467
|
-
signal: opts.signal
|
|
468
|
-
? AbortSignal.any([opts.signal, this.stopping.signal])
|
|
469
|
-
: this.stopping.signal,
|
|
470
|
-
onNativeSession: (id, info) => {
|
|
471
|
-
// Agents report once the native conversation is confirmed; guard against a
|
|
472
|
-
// misbehaving harness re-reporting after emission. Agents always pass
|
|
473
|
-
// their honest `resumed` judgment — the runtime surfaces it only when
|
|
474
|
-
// this turn actually REQUESTED a resume.
|
|
475
|
-
if (sessionEmitted) return;
|
|
476
|
-
nativeSessionId = id;
|
|
477
|
-
if (config.resumeSessionId && info?.resumed !== undefined) resumed = info.resumed;
|
|
478
|
-
},
|
|
479
|
-
onPermissionRequest: requestPermission,
|
|
480
|
-
onExecution: (update) => {
|
|
481
|
-
applied = { ...applied, ...update };
|
|
482
|
-
},
|
|
483
|
-
};
|
|
484
|
-
|
|
485
|
-
let cancelled = false;
|
|
486
|
-
let errored: ErrorInfo | undefined;
|
|
487
|
-
|
|
488
|
-
try {
|
|
489
|
-
for await (const raw of agent.execute(input, options)) {
|
|
490
|
-
await flushSession();
|
|
491
|
-
if (config.includeRaw) {
|
|
492
|
-
await emit({
|
|
493
|
-
type: "raw",
|
|
494
|
-
sessionId,
|
|
495
|
-
turnId,
|
|
496
|
-
harness: config.harness,
|
|
497
|
-
data: raw,
|
|
498
|
-
timestamp: Date.now(),
|
|
499
|
-
});
|
|
500
|
-
}
|
|
501
|
-
for (const ae of transformer.process(raw)) {
|
|
502
|
-
for (const le of processor.handle(ae)) await emit(le);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
await flushSession();
|
|
506
|
-
} catch (err) {
|
|
507
|
-
cancelled = isCancellation(err);
|
|
508
|
-
if (!cancelled) {
|
|
509
|
-
const category = classifyError(err);
|
|
510
|
-
const message = readableErrorMessage(err instanceof Error ? err.message : String(err));
|
|
511
|
-
errored = { category, message };
|
|
512
|
-
await emit({
|
|
513
|
-
type: "error",
|
|
514
|
-
turnId,
|
|
515
|
-
sessionId,
|
|
516
|
-
category,
|
|
517
|
-
message,
|
|
518
|
-
recoverable: isRecoverable(category),
|
|
519
|
-
stack: err instanceof Error ? err.stack : undefined,
|
|
520
|
-
timestamp: Date.now(),
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
} finally {
|
|
524
|
-
await drainPermissions();
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
const result = transformer.finish();
|
|
528
|
-
cancelled = cancelled || Boolean(result.cancelled);
|
|
529
|
-
if (result.error && !errored && !cancelled) {
|
|
530
|
-
errored = {
|
|
531
|
-
category: classifyError(new Error(result.error)),
|
|
532
|
-
message: readableErrorMessage(result.error),
|
|
533
|
-
};
|
|
534
|
-
}
|
|
535
|
-
const stopReason: StopReason = cancelled
|
|
536
|
-
? "cancelled"
|
|
537
|
-
: errored
|
|
538
|
-
? "error"
|
|
539
|
-
: (result.stopReason ?? "end_turn");
|
|
540
|
-
// What the harness configured ran only if its model answered: a turn that
|
|
541
|
-
// failed or was cancelled first ran nothing.
|
|
542
|
-
const ran =
|
|
543
|
-
processor.modelAnswered || (stopReason !== "error" && stopReason !== "cancelled")
|
|
544
|
-
? applied
|
|
545
|
-
: undefined;
|
|
546
|
-
for (const le of processor.finish(result, stopReason, errored, ran)) await emit(le);
|
|
547
|
-
|
|
548
|
-
return {
|
|
549
|
-
sessionId,
|
|
550
|
-
turnId,
|
|
551
|
-
harness: config.harness,
|
|
552
|
-
nativeSessionId,
|
|
553
|
-
...(resumed !== undefined && { resumed }),
|
|
554
|
-
usage: result.usage ?? DEFAULT_TOKEN_USAGE,
|
|
555
|
-
execution: endedExecution(execution, result, ran),
|
|
556
|
-
stopReason,
|
|
557
|
-
finishReason: result.finishReason,
|
|
558
|
-
cost: result.cost,
|
|
559
|
-
error: errored,
|
|
560
|
-
cancelled,
|
|
561
|
-
};
|
|
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
|
+
);
|
|
562
315
|
}
|
|
563
316
|
|
|
564
317
|
/**
|
|
@@ -569,13 +322,56 @@ export class AgentRuntime {
|
|
|
569
322
|
*/
|
|
570
323
|
async cancel(harness: AgentHarness, sessionId: string): Promise<CancelResult> {
|
|
571
324
|
// Unblock any harness parked on an approval before (and regardless of)
|
|
572
|
-
// the agent-level abort.
|
|
573
|
-
for (const
|
|
574
|
-
if (pending.sessionId === sessionId) void pending.settle({ outcome: "cancelled" });
|
|
575
|
-
}
|
|
325
|
+
// the agent-level abort.
|
|
326
|
+
for (const turn of this.turnsOf(sessionId)) void turn.requestCancel();
|
|
576
327
|
return await this.registry.getAgent(harness).cancel(sessionId);
|
|
577
328
|
}
|
|
578
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
|
+
|
|
579
375
|
/**
|
|
580
376
|
* Call after the host resumes from suspension, before admitting new turns.
|
|
581
377
|
* Retains conversations and admission receipts. Claude and Codex app-server
|
|
@@ -588,15 +384,44 @@ export class AgentRuntime {
|
|
|
588
384
|
}
|
|
589
385
|
}
|
|
590
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
|
+
|
|
591
421
|
/** Dispose one idle logical session and its harness-native resources. */
|
|
592
422
|
async closeSession(harness: AgentHarness, sessionId: string): Promise<void> {
|
|
593
|
-
this.
|
|
594
|
-
this.
|
|
595
|
-
await Promise.all(
|
|
596
|
-
[...this.pendingPermissions.values()]
|
|
597
|
-
.filter((pending) => pending.sessionId === sessionId)
|
|
598
|
-
.map((pending) => pending.settle({ outcome: "cancelled" })),
|
|
599
|
-
);
|
|
423
|
+
this.sessions.delete(sessionId);
|
|
424
|
+
await Promise.all(this.turnsOf(sessionId).map((turn) => turn.requestCancel()));
|
|
600
425
|
// A harness this runtime does not run (a session restored from a journal
|
|
601
426
|
// written with another registry) holds nothing here to release.
|
|
602
427
|
if (!this.registry.has(harness)) return;
|
|
@@ -605,25 +430,17 @@ export class AgentRuntime {
|
|
|
605
430
|
else await agent.cancel(sessionId);
|
|
606
431
|
}
|
|
607
432
|
|
|
608
|
-
/** Give up on stragglers after this long; the process is exiting anyway. */
|
|
609
|
-
private static readonly DEFAULT_DRAIN_TIMEOUT_MS = 10_000;
|
|
610
|
-
|
|
611
433
|
shutdown(opts: { drainTimeoutMs?: number } = {}): Promise<void> {
|
|
612
434
|
// Memoized: the first caller's timeout wins.
|
|
613
|
-
this.shutdownPromise ??= this.performShutdown(
|
|
614
|
-
opts.drainTimeoutMs ?? AgentRuntime.DEFAULT_DRAIN_TIMEOUT_MS,
|
|
615
|
-
);
|
|
435
|
+
this.shutdownPromise ??= this.performShutdown(opts.drainTimeoutMs ?? DEFAULT_DRAIN_TIMEOUT_MS);
|
|
616
436
|
return this.shutdownPromise;
|
|
617
437
|
}
|
|
618
438
|
|
|
619
439
|
private async performShutdown(drainTimeoutMs: number): Promise<void> {
|
|
620
440
|
this.stopping.abort();
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
),
|
|
625
|
-
);
|
|
626
|
-
this.pendingPermissions.clear();
|
|
441
|
+
this.logins.shutdown();
|
|
442
|
+
const turns = [...this.turns.values()];
|
|
443
|
+
await Promise.all(turns.map((turn) => turn.requests.cancelAll()));
|
|
627
444
|
let terminationError: unknown;
|
|
628
445
|
try {
|
|
629
446
|
await this.registry.terminateAll();
|
|
@@ -632,14 +449,26 @@ export class AgentRuntime {
|
|
|
632
449
|
}
|
|
633
450
|
// Drain active runs, but don't let a harness that ignores its abort
|
|
634
451
|
// signal hang the process's shutdown forever.
|
|
635
|
-
await Promise.
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}),
|
|
641
|
-
]);
|
|
642
|
-
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();
|
|
643
457
|
if (terminationError !== undefined) throw terminationError;
|
|
644
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
|
+
}
|
|
645
474
|
}
|