@zvada/agent-server 0.3.18 → 0.3.20
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 +1041 -1
- package/README.md +40 -40
- 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 +45 -28
- 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 +155 -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,962 +0,0 @@
|
|
|
1
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
2
|
-
import { homedir } from "node:os";
|
|
3
|
-
import { isAbsolute, resolve } from "node:path";
|
|
4
|
-
import type {
|
|
5
|
-
AgentCapabilities,
|
|
6
|
-
AgentInput,
|
|
7
|
-
ModelDescriptor,
|
|
8
|
-
PermissionMode,
|
|
9
|
-
PermissionToolCall,
|
|
10
|
-
ThinkingLevel,
|
|
11
|
-
} from "../../../protocol/index.ts";
|
|
12
|
-
import { AsyncQueue, codexReasoningEffort, modelThinkingLevels } from "../../../protocol/index.ts";
|
|
13
|
-
import { SessionResumeError } from "../../utils/errors.ts";
|
|
14
|
-
import type {
|
|
15
|
-
AgentExecuteOptions,
|
|
16
|
-
CancelResult,
|
|
17
|
-
ListModelsOptions,
|
|
18
|
-
PermissionRequestHandler,
|
|
19
|
-
RawAgentEvent,
|
|
20
|
-
} from "../base.ts";
|
|
21
|
-
import { configFingerprint } from "../config-fingerprint.ts";
|
|
22
|
-
import { snapshotMcpServers } from "../mcp-config.ts";
|
|
23
|
-
import { SessionAgent } from "../session-agent.ts";
|
|
24
|
-
import { SessionStore } from "../session-store.ts";
|
|
25
|
-
import {
|
|
26
|
-
CodexAppServerClient,
|
|
27
|
-
type CodexAppServerClientOptions,
|
|
28
|
-
type CodexNotification,
|
|
29
|
-
} from "./client.ts";
|
|
30
|
-
import {
|
|
31
|
-
assertCodexMcpConfig,
|
|
32
|
-
assertCodexMcpReady,
|
|
33
|
-
codexMcpServers,
|
|
34
|
-
writeCodexMcpServers,
|
|
35
|
-
} from "./mcp.ts";
|
|
36
|
-
import {
|
|
37
|
-
type CodexModelThinking,
|
|
38
|
-
codexModelDescriptors,
|
|
39
|
-
codexModelThinking,
|
|
40
|
-
codexThinkingLevel,
|
|
41
|
-
listCodexModels,
|
|
42
|
-
readCodexListing,
|
|
43
|
-
readCodexModels,
|
|
44
|
-
} from "./models.ts";
|
|
45
|
-
import { CodexTurnSubagents } from "./subagents.ts";
|
|
46
|
-
|
|
47
|
-
export type { CodexModelThinking } from "./models.ts";
|
|
48
|
-
|
|
49
|
-
const CAPABILITIES: AgentCapabilities = {
|
|
50
|
-
multiTurn: true,
|
|
51
|
-
sessionResume: true,
|
|
52
|
-
// Model/effort are overridable per turn/start, so no restart is needed.
|
|
53
|
-
modelSwitch: "in-session",
|
|
54
|
-
thinkingLevels: true,
|
|
55
|
-
images: true,
|
|
56
|
-
mcpServers: true,
|
|
57
|
-
permissionRequests: true,
|
|
58
|
-
turnScopedSubagents: true,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export interface AppServerSession {
|
|
62
|
-
client: CodexAppServerClient;
|
|
63
|
-
threadId: string;
|
|
64
|
-
cwd: string;
|
|
65
|
-
approvalPolicy: string;
|
|
66
|
-
sandbox: string;
|
|
67
|
-
systemPromptAppend?: string;
|
|
68
|
-
subagentMode?: "turn";
|
|
69
|
-
envFingerprint: string;
|
|
70
|
-
/** Native model connections retain the identity used at their first handshake. */
|
|
71
|
-
authFingerprint?: string;
|
|
72
|
-
/** Last native config write; readiness is checked separately before every prompt. */
|
|
73
|
-
mcpFingerprint?: string;
|
|
74
|
-
/** Credentials and permission broker belong only to the current execute. */
|
|
75
|
-
turn?: AppServerTurn;
|
|
76
|
-
idleTimer?: ReturnType<typeof setTimeout>;
|
|
77
|
-
/** The thread's model, as Codex resolved it (config.toml included). */
|
|
78
|
-
model?: string;
|
|
79
|
-
/** The model Codex reported for the thread, until a turn selects another. */
|
|
80
|
-
reportedModel?: string;
|
|
81
|
-
/** The thread's reasoning effort: Codex's own, then the last one a turn sent (they persist). */
|
|
82
|
-
effort?: string;
|
|
83
|
-
/** What each model accepts, from this process's `model/list`; read once. */
|
|
84
|
-
modelEfforts?: Promise<ReadonlyMap<string, CodexModelThinking> | undefined>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
interface AppServerTurn {
|
|
88
|
-
auth?: CodexAppServerAuth;
|
|
89
|
-
permissionHandler?: PermissionRequestHandler;
|
|
90
|
-
signal: AbortSignal;
|
|
91
|
-
subagents?: CodexTurnSubagents;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function appServerSessionCompatible(
|
|
95
|
-
existing: AppServerSession | undefined,
|
|
96
|
-
options: AgentExecuteOptions,
|
|
97
|
-
): boolean {
|
|
98
|
-
return Boolean(
|
|
99
|
-
existing &&
|
|
100
|
-
!existing.client.closed &&
|
|
101
|
-
existing.cwd === options.cwd &&
|
|
102
|
-
existing.approvalPolicy === approvalPolicyFor(options) &&
|
|
103
|
-
existing.sandbox === mapSandbox(options.permissionMode) &&
|
|
104
|
-
(existing.systemPromptAppend ?? "") === (options.systemPromptAppend ?? "") &&
|
|
105
|
-
existing.subagentMode === options.subagentMode &&
|
|
106
|
-
existing.envFingerprint === configFingerprint(options.env) &&
|
|
107
|
-
(!options.resumeSessionId || options.resumeSessionId === existing.threadId),
|
|
108
|
-
);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
type UserInput = { type: "text"; text: string; text_elements: [] } | { type: "image"; url: string };
|
|
112
|
-
|
|
113
|
-
function mapSandbox(mode: PermissionMode | undefined): string {
|
|
114
|
-
switch (mode) {
|
|
115
|
-
case "bypass_permissions":
|
|
116
|
-
return "danger-full-access";
|
|
117
|
-
case "accept_edits":
|
|
118
|
-
case "dont_ask":
|
|
119
|
-
// Never-ask posture, but inside the normal sandbox — danger-full is
|
|
120
|
-
// reserved for the explicitly dangerous mode.
|
|
121
|
-
return "workspace-write";
|
|
122
|
-
default:
|
|
123
|
-
return "read-only";
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function toUserInput(input: AgentInput): UserInput[] {
|
|
128
|
-
if (typeof input === "string") return [{ type: "text", text: input, text_elements: [] }];
|
|
129
|
-
const out: UserInput[] = [];
|
|
130
|
-
for (const part of input) {
|
|
131
|
-
if (part.type === "text") out.push({ type: "text", text: part.text, text_elements: [] });
|
|
132
|
-
else if (part.url) out.push({ type: "image", url: part.url });
|
|
133
|
-
else if (part.type === "image" && part.data) {
|
|
134
|
-
// Codex's user input carries images by URL only; a pasted image arrives
|
|
135
|
-
// as base64 `data` and used to be dropped SILENTLY while the negotiated
|
|
136
|
-
// capability said supported. A data URL delivers it on the same field —
|
|
137
|
-
// and a Codex build that rejects it fails the turn loudly instead of
|
|
138
|
-
// the prompt losing its attachment with no trace.
|
|
139
|
-
out.push({ type: "image", url: `data:${part.mimeType};base64,${part.data}` });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
return out.length ? out : [{ type: "text", text: "", text_elements: [] }];
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Ask-the-user only makes sense in `default` mode with an engine broker
|
|
147
|
-
* attached; every other posture auto-decides (sandbox enforces safety).
|
|
148
|
-
*/
|
|
149
|
-
function approvalPolicyFor(options: AgentExecuteOptions): string {
|
|
150
|
-
const asks = (options.permissionMode ?? "default") === "default";
|
|
151
|
-
return asks && options.onPermissionRequest ? "on-request" : "never";
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/** Normalize a codex approval request into the engine's PermissionToolCall. */
|
|
155
|
-
function approvalToolCall(method: string, params: Record<string, unknown>): PermissionToolCall {
|
|
156
|
-
const id =
|
|
157
|
-
(typeof params.itemId === "string" && params.itemId) ||
|
|
158
|
-
(typeof params.callId === "string" && params.callId) ||
|
|
159
|
-
"approval";
|
|
160
|
-
const reason = typeof params.reason === "string" ? params.reason : undefined;
|
|
161
|
-
if (method.includes("commandExecution") || method === "execCommandApproval") {
|
|
162
|
-
const command = Array.isArray(params.command)
|
|
163
|
-
? (params.command as string[]).join(" ")
|
|
164
|
-
: typeof params.command === "string"
|
|
165
|
-
? params.command
|
|
166
|
-
: "";
|
|
167
|
-
return {
|
|
168
|
-
toolCallId: id,
|
|
169
|
-
toolName: "shell",
|
|
170
|
-
kind: "execute",
|
|
171
|
-
...(reason && { title: reason }),
|
|
172
|
-
rawInput: { command, ...(params.cwd ? { cwd: params.cwd } : {}) },
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
// v1 ApplyPatchApprovalParams carries `fileChanges`; v2
|
|
176
|
-
// FileChangeRequestApprovalParams does not (only itemId/reason/grantRoot),
|
|
177
|
-
// so `locations` is best-effort and may be empty for v2 edits.
|
|
178
|
-
const changes = (params.fileChanges ?? params.changes ?? {}) as Record<string, unknown>;
|
|
179
|
-
const paths = Object.keys(changes);
|
|
180
|
-
return {
|
|
181
|
-
toolCallId: id,
|
|
182
|
-
toolName: "apply_patch",
|
|
183
|
-
kind: "edit",
|
|
184
|
-
...(reason && { title: reason }),
|
|
185
|
-
...(paths.length && { locations: paths.map((path) => ({ path })) }),
|
|
186
|
-
rawInput: { changes },
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Idle time before an unused app-server subprocess is shut down. */
|
|
191
|
-
const IDLE_TIMEOUT_MS = 5 * 60_000;
|
|
192
|
-
|
|
193
|
-
/** How long a retryable error may go unanswered before the turn is failed. */
|
|
194
|
-
const RETRY_STALL_TIMEOUT_MS = 120_000;
|
|
195
|
-
|
|
196
|
-
/** Access credentials for Codex's experimental, externally managed ChatGPT auth mode. */
|
|
197
|
-
export interface CodexChatGptAuthTokens {
|
|
198
|
-
accessToken: string;
|
|
199
|
-
chatgptAccountId: string;
|
|
200
|
-
chatgptPlanType?: string | null;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/** The host owns login, durable token storage, refresh serialization, and revocation. */
|
|
204
|
-
export interface CodexChatGptAuth {
|
|
205
|
-
type: "chatgptAuthTokens";
|
|
206
|
-
tokens: CodexChatGptAuthTokens;
|
|
207
|
-
refresh(previousAccountId: string): Promise<CodexChatGptAuthTokens>;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export type CodexAppServerAuth = { type: "apiKey"; apiKey: string } | CodexChatGptAuth;
|
|
211
|
-
|
|
212
|
-
function loginParams(auth: CodexAppServerAuth): Record<string, unknown> {
|
|
213
|
-
return auth.type === "apiKey"
|
|
214
|
-
? { type: "apiKey", apiKey: auth.apiKey }
|
|
215
|
-
: {
|
|
216
|
-
type: "chatgptAuthTokens",
|
|
217
|
-
accessToken: auth.tokens.accessToken,
|
|
218
|
-
chatgptAccountId: auth.tokens.chatgptAccountId,
|
|
219
|
-
chatgptPlanType: auth.tokens.chatgptPlanType ?? null,
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
function authFingerprint(auth: CodexAppServerAuth | undefined): string | undefined {
|
|
224
|
-
if (!auth) return undefined;
|
|
225
|
-
return configFingerprint(
|
|
226
|
-
auth.type === "apiKey" ? auth : { type: auth.type, accountId: auth.tokens.chatgptAccountId },
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
export interface CodexAppServerAgentOptions {
|
|
231
|
-
createClient?: (options: CodexAppServerClientOptions) => CodexAppServerClient;
|
|
232
|
-
idleTimeoutMs?: number;
|
|
233
|
-
/** Fail a turn if the app-server goes silent this long after a retryable error. */
|
|
234
|
-
retryStallTimeoutMs?: number;
|
|
235
|
-
/** Deadline for interrupt acknowledgement and the cancelled turn to drain. */
|
|
236
|
-
cancelGraceMs?: number;
|
|
237
|
-
/**
|
|
238
|
-
* Resolve the `codex` binary to spawn (typically the provisioner's,
|
|
239
|
-
* memoized). Falls back to `$CODEX_CLI_PATH`, then PATH. Operator-level
|
|
240
|
-
* only — never sourced from the wire.
|
|
241
|
-
*/
|
|
242
|
-
resolveCliPath?: () => Promise<string | undefined>;
|
|
243
|
-
/**
|
|
244
|
-
* Resolve the selected API key or ChatGPT account before EVERY turn, including warm
|
|
245
|
-
* sessions. Operator-only: neither callbacks nor tokens belong in RunConfig.
|
|
246
|
-
* Return undefined to select native CLI auth; throw when the selected external
|
|
247
|
-
* account is unavailable. Changing accounts, API keys, or auth modes recreates
|
|
248
|
-
* the process and resumes the same conversation.
|
|
249
|
-
*/
|
|
250
|
-
resolveAuth?: (sessionId: string) => Promise<CodexAppServerAuth | undefined>;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/** Retryable v2 `error` notifications do not end the turn; Codex keeps going. */
|
|
254
|
-
export function appServerNotificationEndsTurn(notification: CodexNotification): boolean {
|
|
255
|
-
return (
|
|
256
|
-
notification.method === "turn/completed" ||
|
|
257
|
-
(notification.method === "error" && notification.params.willRetry !== true)
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* The thinking levels each model the logged-in account can run accepts, from
|
|
263
|
-
* `model/list`. `undefined` when the CLI cannot answer; callers fall back to
|
|
264
|
-
* `MODEL_CATALOG`.
|
|
265
|
-
*/
|
|
266
|
-
export async function listModelThinking(
|
|
267
|
-
client: Pick<CodexAppServerClient, "request">,
|
|
268
|
-
): Promise<ReadonlyMap<string, CodexModelThinking> | undefined> {
|
|
269
|
-
try {
|
|
270
|
-
const thinking = codexModelThinking(await readCodexModels(client));
|
|
271
|
-
return thinking.size ? thinking : undefined;
|
|
272
|
-
} catch {
|
|
273
|
-
// An older CLI, a slow answer or a closed process: the catalog decides.
|
|
274
|
-
return undefined;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Codex harness backed by a long-lived `codex app-server` subprocess speaking
|
|
280
|
-
* JSON-RPC. Unlike the SDK harness this streams token-level deltas. A client +
|
|
281
|
-
* thread is created per logical session and reused for multi-turn; model/effort
|
|
282
|
-
* are passed per `turn/start`. Resume uses `thread/resume` with the native id.
|
|
283
|
-
*/
|
|
284
|
-
export class CodexAppServerAgent extends SessionAgent {
|
|
285
|
-
readonly harness = "codex-app-server" as const;
|
|
286
|
-
readonly capabilities = CAPABILITIES;
|
|
287
|
-
private readonly sessions = new SessionStore<AppServerSession>();
|
|
288
|
-
private readonly invalidatedClients = new WeakSet<CodexAppServerClient>();
|
|
289
|
-
private readonly unsettledSessions = new Map<string, CodexAppServerClient>();
|
|
290
|
-
/** Home ownership outlives idle process eviction and failed preparation. */
|
|
291
|
-
private readonly mcpHomes = new Map<string, string>();
|
|
292
|
-
/** A cancel acknowledgement belongs to one invocation, even after it drains. */
|
|
293
|
-
private readonly turnInterruptState = new WeakMap<
|
|
294
|
-
AbortController,
|
|
295
|
-
{ acknowledgement?: Promise<boolean> }
|
|
296
|
-
>();
|
|
297
|
-
|
|
298
|
-
constructor(private readonly agentOptions: CodexAppServerAgentOptions = {}) {
|
|
299
|
-
super();
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/** With host-managed auth, each session may list as a different account. */
|
|
303
|
-
get modelsPerSession(): boolean {
|
|
304
|
-
return Boolean(this.agentOptions.resolveAuth);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
private async resolveSession(
|
|
308
|
-
options: AgentExecuteOptions,
|
|
309
|
-
turn: AppServerTurn,
|
|
310
|
-
mcpServers: Record<string, unknown> | undefined,
|
|
311
|
-
): Promise<AppServerSession> {
|
|
312
|
-
const { signal } = turn;
|
|
313
|
-
signal.throwIfAborted();
|
|
314
|
-
const approvalPolicy = approvalPolicyFor(options);
|
|
315
|
-
const sandbox = mapSandbox(options.permissionMode);
|
|
316
|
-
const existing = this.sessions.get(options.sessionId);
|
|
317
|
-
const identity = authFingerprint(turn.auth);
|
|
318
|
-
// Codex caches an authenticated model WebSocket across turns. Login alone
|
|
319
|
-
// cannot switch its identity: restart on account/key changes and resume
|
|
320
|
-
// the same thread. Same-account token renewal can keep the process warm.
|
|
321
|
-
const resumeThreadId = options.resumeSessionId;
|
|
322
|
-
if (existing && !existing.client.closed) {
|
|
323
|
-
if (
|
|
324
|
-
appServerSessionCompatible(existing, options) &&
|
|
325
|
-
existing.authFingerprint === identity &&
|
|
326
|
-
!this.invalidatedClients.has(existing.client)
|
|
327
|
-
) {
|
|
328
|
-
this.sessions.clearIdle(existing);
|
|
329
|
-
existing.turn = turn;
|
|
330
|
-
const onAbort = () => existing.client.close();
|
|
331
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
332
|
-
try {
|
|
333
|
-
await this.authenticate(existing);
|
|
334
|
-
return existing;
|
|
335
|
-
} catch (error) {
|
|
336
|
-
existing.turn = undefined;
|
|
337
|
-
existing.client.close();
|
|
338
|
-
throw error;
|
|
339
|
-
} finally {
|
|
340
|
-
signal.removeEventListener("abort", onAbort);
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
this.sessions.close(options.sessionId);
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
const clientOptions: CodexAppServerClientOptions = {
|
|
348
|
-
codexPath:
|
|
349
|
-
(await this.agentOptions.resolveCliPath?.()) ?? process.env.CODEX_CLI_PATH ?? "codex",
|
|
350
|
-
cwd: options.cwd,
|
|
351
|
-
env: options.env ? ({ ...process.env, ...options.env } as NodeJS.ProcessEnv) : process.env,
|
|
352
|
-
...((turn.auth?.type === "chatgptAuthTokens" || options.subagentMode === "turn") && {
|
|
353
|
-
experimentalApi: true,
|
|
354
|
-
}),
|
|
355
|
-
};
|
|
356
|
-
signal.throwIfAborted();
|
|
357
|
-
const client =
|
|
358
|
-
this.agentOptions.createClient?.(clientOptions) ?? new CodexAppServerClient(clientOptions);
|
|
359
|
-
// Self-heal: if the subprocess ever exits, drop it so the next turn respawns.
|
|
360
|
-
client.onClose(() => this.sessions.dropIfCurrent(options.sessionId, client));
|
|
361
|
-
const untrack = this.sessions.trackPending(options.sessionId, client);
|
|
362
|
-
const onAbort = () => client.close();
|
|
363
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
364
|
-
const session: AppServerSession = {
|
|
365
|
-
client,
|
|
366
|
-
threadId: "",
|
|
367
|
-
cwd: options.cwd,
|
|
368
|
-
approvalPolicy,
|
|
369
|
-
sandbox,
|
|
370
|
-
systemPromptAppend: options.systemPromptAppend,
|
|
371
|
-
subagentMode: options.subagentMode,
|
|
372
|
-
envFingerprint: configFingerprint(options.env),
|
|
373
|
-
authFingerprint: identity,
|
|
374
|
-
turn,
|
|
375
|
-
};
|
|
376
|
-
this.bindRequests(session);
|
|
377
|
-
try {
|
|
378
|
-
signal.throwIfAborted();
|
|
379
|
-
await client.initialize();
|
|
380
|
-
await this.authenticate(session);
|
|
381
|
-
// Clear stale per-turn credentials before thread startup can use them.
|
|
382
|
-
await this.configureMcp(session, mcpServers);
|
|
383
|
-
|
|
384
|
-
const startParams: Record<string, unknown> = {
|
|
385
|
-
cwd: options.cwd,
|
|
386
|
-
sandbox,
|
|
387
|
-
approvalPolicy,
|
|
388
|
-
experimentalRawEvents: false,
|
|
389
|
-
persistExtendedHistory: false,
|
|
390
|
-
};
|
|
391
|
-
if (options.model) startParams.model = options.model;
|
|
392
|
-
if (options.systemPromptAppend)
|
|
393
|
-
startParams.developerInstructions = options.systemPromptAppend;
|
|
394
|
-
if (options.subagentMode === "turn") {
|
|
395
|
-
startParams.config = { "features.multi_agent": true };
|
|
396
|
-
startParams.developerInstructions = [
|
|
397
|
-
options.systemPromptAppend,
|
|
398
|
-
"Collect the results of every subagent before ending your turn. Stop any worker you no longer need. Delegated work cannot continue after this task completes.",
|
|
399
|
-
]
|
|
400
|
-
.filter(Boolean)
|
|
401
|
-
.join("\n\n");
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
const method = resumeThreadId ? "thread/resume" : "thread/start";
|
|
405
|
-
const result = (await client
|
|
406
|
-
.request(
|
|
407
|
-
method,
|
|
408
|
-
resumeThreadId ? { threadId: resumeThreadId, ...startParams } : startParams,
|
|
409
|
-
)
|
|
410
|
-
.catch((cause: unknown) => {
|
|
411
|
-
if (!resumeThreadId) throw cause;
|
|
412
|
-
throw new SessionResumeError(
|
|
413
|
-
resumeThreadId,
|
|
414
|
-
cause instanceof Error ? cause.message : String(cause),
|
|
415
|
-
{ cause },
|
|
416
|
-
);
|
|
417
|
-
})) as { thread?: { id?: string }; model?: unknown; reasoningEffort?: unknown };
|
|
418
|
-
const threadId = result?.thread?.id;
|
|
419
|
-
if (resumeThreadId && threadId !== resumeThreadId) {
|
|
420
|
-
throw new SessionResumeError(
|
|
421
|
-
resumeThreadId,
|
|
422
|
-
`Codex returned ${threadId ? `a different thread: ${threadId}` : "no thread id"}`,
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
if (!threadId) throw new Error("codex app-server thread/start returned no thread id");
|
|
426
|
-
signal.throwIfAborted();
|
|
427
|
-
session.threadId = threadId;
|
|
428
|
-
session.model = typeof result.model === "string" ? result.model : options.model;
|
|
429
|
-
if (typeof result.model === "string") session.reportedModel = result.model;
|
|
430
|
-
if (typeof result.reasoningEffort === "string") session.effort = result.reasoningEffort;
|
|
431
|
-
this.sessions.set(options.sessionId, session);
|
|
432
|
-
return session;
|
|
433
|
-
} catch (error) {
|
|
434
|
-
session.turn = undefined;
|
|
435
|
-
client.setRequestHandler(undefined);
|
|
436
|
-
client.close();
|
|
437
|
-
throw error;
|
|
438
|
-
} finally {
|
|
439
|
-
signal.removeEventListener("abort", onAbort);
|
|
440
|
-
untrack();
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
private managedMcpHome(options: AgentExecuteOptions, hasServers: boolean): boolean {
|
|
445
|
-
const home = options.env?.CODEX_HOME;
|
|
446
|
-
if (!home) {
|
|
447
|
-
if (hasServers)
|
|
448
|
-
throw new Error("Codex per-turn MCP requires a session-specific env.CODEX_HOME");
|
|
449
|
-
return false;
|
|
450
|
-
}
|
|
451
|
-
if (!isAbsolute(home)) throw new Error("Codex session CODEX_HOME must be an absolute path");
|
|
452
|
-
const shared = resolve(process.env.CODEX_HOME ?? `${homedir()}/.codex`);
|
|
453
|
-
if (resolve(home) === shared) {
|
|
454
|
-
throw new Error("Codex per-turn MCP cannot use the shared user CODEX_HOME");
|
|
455
|
-
}
|
|
456
|
-
const path = realpathSync(home);
|
|
457
|
-
if (existsSync(shared) && path === realpathSync(shared)) {
|
|
458
|
-
throw new Error("Codex per-turn MCP cannot use the shared user CODEX_HOME");
|
|
459
|
-
}
|
|
460
|
-
const owner = this.mcpHomes.get(path);
|
|
461
|
-
if (owner && owner !== options.sessionId) {
|
|
462
|
-
throw new Error("Codex CODEX_HOME is already owned by another session");
|
|
463
|
-
}
|
|
464
|
-
this.mcpHomes.set(path, options.sessionId);
|
|
465
|
-
return true;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
private async configureMcp(
|
|
469
|
-
session: AppServerSession,
|
|
470
|
-
servers: Record<string, unknown> | undefined,
|
|
471
|
-
): Promise<void> {
|
|
472
|
-
if (servers === undefined) return;
|
|
473
|
-
const fingerprint = configFingerprint(servers);
|
|
474
|
-
const changed = session.mcpFingerprint !== fingerprint;
|
|
475
|
-
// A rejected write or changed project layer invalidates the cached identity.
|
|
476
|
-
session.mcpFingerprint = undefined;
|
|
477
|
-
if (changed) await writeCodexMcpServers(session.client, servers);
|
|
478
|
-
await assertCodexMcpConfig(session.client, session.cwd, servers);
|
|
479
|
-
if (changed) await session.client.request("config/mcpServer/reload", undefined);
|
|
480
|
-
session.mcpFingerprint = fingerprint;
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
/** What the thread's model accepts: live from this process, else what the engine knows. */
|
|
484
|
-
private async modelThinking(
|
|
485
|
-
session: AppServerSession,
|
|
486
|
-
known?: readonly ThinkingLevel[],
|
|
487
|
-
): Promise<CodexModelThinking | undefined> {
|
|
488
|
-
if (!session.model) return undefined;
|
|
489
|
-
session.modelEfforts ??= listModelThinking(session.client);
|
|
490
|
-
const live = (await session.modelEfforts)?.get(session.model);
|
|
491
|
-
if (live) return live;
|
|
492
|
-
const levels = known ?? modelThinkingLevels("codex-app-server", session.model);
|
|
493
|
-
return levels && { levels };
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
/**
|
|
497
|
-
* The models Codex offers this login. Reuses the session's process when
|
|
498
|
-
* `sessionId` has one started with the same `env` (its `CODEX_HOME` decides
|
|
499
|
-
* the login and config); otherwise starts `codex app-server` just to ask,
|
|
500
|
-
* with the account `resolveAuth` selects for that session.
|
|
501
|
-
*/
|
|
502
|
-
async listModels(options: ListModelsOptions): Promise<ModelDescriptor[]> {
|
|
503
|
-
const live = options.sessionId ? this.sessions.get(options.sessionId) : undefined;
|
|
504
|
-
if (live && !live.client.closed && live.envFingerprint === configFingerprint(options.env)) {
|
|
505
|
-
const listing = await readCodexListing(live.client, options.cwd);
|
|
506
|
-
return codexModelDescriptors(listing.models, this.harness, listing.configuredModel);
|
|
507
|
-
}
|
|
508
|
-
const auth =
|
|
509
|
-
options.sessionId && this.agentOptions.resolveAuth
|
|
510
|
-
? await this.agentOptions.resolveAuth(options.sessionId)
|
|
511
|
-
: undefined;
|
|
512
|
-
options.signal?.throwIfAborted();
|
|
513
|
-
const listing = await listCodexModels(
|
|
514
|
-
{
|
|
515
|
-
codexPath:
|
|
516
|
-
(await this.agentOptions.resolveCliPath?.()) ?? process.env.CODEX_CLI_PATH ?? "codex",
|
|
517
|
-
cwd: options.cwd,
|
|
518
|
-
env: options.env ? ({ ...process.env, ...options.env } as NodeJS.ProcessEnv) : process.env,
|
|
519
|
-
...(auth?.type === "chatgptAuthTokens" && { experimentalApi: true }),
|
|
520
|
-
},
|
|
521
|
-
{
|
|
522
|
-
signal: options.signal,
|
|
523
|
-
...(this.agentOptions.createClient && { createClient: this.agentOptions.createClient }),
|
|
524
|
-
...(auth && {
|
|
525
|
-
login: async (client) => {
|
|
526
|
-
await client.request("account/login/start", loginParams(auth));
|
|
527
|
-
},
|
|
528
|
-
}),
|
|
529
|
-
},
|
|
530
|
-
);
|
|
531
|
-
return codexModelDescriptors(listing.models, this.harness, listing.configuredModel);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
private async authenticate(session: AppServerSession): Promise<void> {
|
|
535
|
-
session.turn?.signal.throwIfAborted();
|
|
536
|
-
const auth = session.turn?.auth;
|
|
537
|
-
if (auth) await session.client.request("account/login/start", loginParams(auth));
|
|
538
|
-
session.turn?.signal.throwIfAborted();
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
private bindRequests(session: AppServerSession): void {
|
|
542
|
-
// Approval requests (server→client) resolve against the engine broker of
|
|
543
|
-
// whichever turn is current; thread mismatches and broker-less turns decline.
|
|
544
|
-
session.client.setRequestHandler(async (method, params) => {
|
|
545
|
-
const turn = session.turn;
|
|
546
|
-
if (method === "account/chatgptAuthTokens/refresh") {
|
|
547
|
-
if (
|
|
548
|
-
turn?.auth?.type !== "chatgptAuthTokens" ||
|
|
549
|
-
turn.signal.aborted ||
|
|
550
|
-
session.client.closed
|
|
551
|
-
) {
|
|
552
|
-
throw new Error("Codex ChatGPT refresh has no active authenticated turn");
|
|
553
|
-
}
|
|
554
|
-
const accountId = turn.auth.tokens.chatgptAccountId;
|
|
555
|
-
if (params.previousAccountId != null && params.previousAccountId !== accountId) {
|
|
556
|
-
throw new Error("Codex ChatGPT refresh account does not match the selected account");
|
|
557
|
-
}
|
|
558
|
-
const tokens = await turn.auth.refresh(accountId);
|
|
559
|
-
if (session.turn !== turn || turn.signal.aborted || session.client.closed) {
|
|
560
|
-
throw new Error("Codex ChatGPT refresh outlived its turn");
|
|
561
|
-
}
|
|
562
|
-
if (tokens.chatgptAccountId !== accountId) {
|
|
563
|
-
throw new Error("Codex ChatGPT refresh returned a different account");
|
|
564
|
-
}
|
|
565
|
-
return {
|
|
566
|
-
accessToken: tokens.accessToken,
|
|
567
|
-
chatgptAccountId: tokens.chatgptAccountId,
|
|
568
|
-
chatgptPlanType: tokens.chatgptPlanType ?? null,
|
|
569
|
-
};
|
|
570
|
-
}
|
|
571
|
-
// Elicitations and other server requests have their own response shapes.
|
|
572
|
-
// Sending them to the approval broker can leave a turn waiting forever.
|
|
573
|
-
if (
|
|
574
|
-
method !== "item/commandExecution/requestApproval" &&
|
|
575
|
-
method !== "item/fileChange/requestApproval" &&
|
|
576
|
-
method !== "execCommandApproval" &&
|
|
577
|
-
method !== "applyPatchApproval"
|
|
578
|
-
) {
|
|
579
|
-
throw new Error(`Unsupported Codex server request: ${method}`);
|
|
580
|
-
}
|
|
581
|
-
const requestThread = params.threadId ?? params.conversationId;
|
|
582
|
-
const v2 = method.startsWith("item/");
|
|
583
|
-
const decline = v2 ? { decision: "decline" } : { decision: "denied" };
|
|
584
|
-
if (requestThread && requestThread !== session.threadId) {
|
|
585
|
-
if (
|
|
586
|
-
typeof requestThread !== "string" ||
|
|
587
|
-
!turn?.subagents ||
|
|
588
|
-
!(await turn.subagents.owns(requestThread).catch(() => false))
|
|
589
|
-
)
|
|
590
|
-
return decline;
|
|
591
|
-
}
|
|
592
|
-
const handler = turn?.permissionHandler;
|
|
593
|
-
if (!handler || turn?.signal.aborted) return decline;
|
|
594
|
-
const decision = await handler(approvalToolCall(method, params));
|
|
595
|
-
if (session.turn !== turn || turn?.signal.aborted) return decline;
|
|
596
|
-
// Codex's approval reply is a bare verdict — no slot for
|
|
597
|
-
// `decision.updatedInput`, so an edited input cannot be honoured here
|
|
598
|
-
// (only claude-code's `canUseTool` can execute the edit). An edited
|
|
599
|
-
// approval therefore DECLINES: accepting would run input nobody
|
|
600
|
-
// approved.
|
|
601
|
-
switch (decision.decision) {
|
|
602
|
-
case "allow":
|
|
603
|
-
if (decision.updatedInput !== undefined) return decline;
|
|
604
|
-
return v2 ? { decision: "accept" } : { decision: "approved" };
|
|
605
|
-
case "cancel":
|
|
606
|
-
return v2 ? { decision: "cancel" } : { decision: "abort" };
|
|
607
|
-
default:
|
|
608
|
-
return decline;
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
protected override async *executeTurn(
|
|
614
|
-
input: AgentInput,
|
|
615
|
-
options: AgentExecuteOptions,
|
|
616
|
-
controller: AbortController,
|
|
617
|
-
): AsyncIterableIterator<RawAgentEvent> {
|
|
618
|
-
const turn: AppServerTurn = {
|
|
619
|
-
permissionHandler: options.onPermissionRequest,
|
|
620
|
-
signal: controller.signal,
|
|
621
|
-
};
|
|
622
|
-
const interruptState: { acknowledgement?: Promise<boolean> } = {};
|
|
623
|
-
this.turnInterruptState.set(controller, interruptState);
|
|
624
|
-
const queue = new AsyncQueue<CodexNotification>();
|
|
625
|
-
// A retryable error promises more notifications. If none arrive, the
|
|
626
|
-
// subprocess is wedged-but-alive and the turn would hang forever — bound it.
|
|
627
|
-
let stallTimer: ReturnType<typeof setTimeout> | undefined;
|
|
628
|
-
let cancelTimer: ReturnType<typeof setTimeout> | undefined;
|
|
629
|
-
const clearStall = () => {
|
|
630
|
-
if (stallTimer) clearTimeout(stallTimer);
|
|
631
|
-
stallTimer = undefined;
|
|
632
|
-
};
|
|
633
|
-
const unsubscribe: Array<() => void> = [];
|
|
634
|
-
let session: AppServerSession | undefined;
|
|
635
|
-
let turnEnded = false;
|
|
636
|
-
let parentEnded = false;
|
|
637
|
-
let managedCompletion: Promise<boolean> | undefined;
|
|
638
|
-
try {
|
|
639
|
-
controller.signal.throwIfAborted();
|
|
640
|
-
const unsettled = this.unsettledSessions.get(options.sessionId);
|
|
641
|
-
if (unsettled) {
|
|
642
|
-
if (!(await unsettled.closeAndWait()))
|
|
643
|
-
throw new Error("Previous Codex execution has not stopped");
|
|
644
|
-
this.unsettledSessions.delete(options.sessionId);
|
|
645
|
-
}
|
|
646
|
-
const requestedMcp = codexMcpServers(snapshotMcpServers(options.mcpServers));
|
|
647
|
-
const mcpServers = this.managedMcpHome(options, Object.keys(requestedMcp).length > 0)
|
|
648
|
-
? requestedMcp
|
|
649
|
-
: undefined;
|
|
650
|
-
if (this.agentOptions.resolveAuth) {
|
|
651
|
-
turn.auth = await this.agentOptions.resolveAuth(options.sessionId);
|
|
652
|
-
}
|
|
653
|
-
controller.signal.throwIfAborted();
|
|
654
|
-
session = await this.resolveSession(options, turn, mcpServers);
|
|
655
|
-
options.onNativeSession?.(session.threadId, {
|
|
656
|
-
resumed: session.threadId === options.resumeSessionId,
|
|
657
|
-
});
|
|
658
|
-
const threadId = session.threadId;
|
|
659
|
-
const client = session.client;
|
|
660
|
-
if (options.subagentMode === "turn") {
|
|
661
|
-
turn.subagents = new CodexTurnSubagents(
|
|
662
|
-
client,
|
|
663
|
-
threadId,
|
|
664
|
-
this.agentOptions.cancelGraceMs ?? 2_000,
|
|
665
|
-
);
|
|
666
|
-
}
|
|
667
|
-
const abortPreparation = () => {
|
|
668
|
-
if (turn.subagents) void client.closeAndWait();
|
|
669
|
-
else client.close();
|
|
670
|
-
};
|
|
671
|
-
controller.signal.addEventListener("abort", abortPreparation, { once: true });
|
|
672
|
-
try {
|
|
673
|
-
controller.signal.throwIfAborted();
|
|
674
|
-
await this.configureMcp(session, mcpServers);
|
|
675
|
-
try {
|
|
676
|
-
await assertCodexMcpReady(client, threadId, Object.keys(mcpServers ?? {}));
|
|
677
|
-
} catch (error) {
|
|
678
|
-
// A later explicit turn must reload failed clients even if config is unchanged.
|
|
679
|
-
session.mcpFingerprint = undefined;
|
|
680
|
-
throw error;
|
|
681
|
-
}
|
|
682
|
-
controller.signal.throwIfAborted();
|
|
683
|
-
} finally {
|
|
684
|
-
controller.signal.removeEventListener("abort", abortPreparation);
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
let turnId: string | undefined;
|
|
688
|
-
const finishManaged = (): Promise<boolean> => {
|
|
689
|
-
if (managedCompletion) return managedCompletion;
|
|
690
|
-
managedCompletion = (async () => {
|
|
691
|
-
let confirmed = true;
|
|
692
|
-
let failure: unknown;
|
|
693
|
-
const graceMs = this.agentOptions.cancelGraceMs ?? 2_000;
|
|
694
|
-
const deadline = setTimeout(() => {
|
|
695
|
-
void client.closeAndWait(graceMs);
|
|
696
|
-
}, graceMs * 5);
|
|
697
|
-
try {
|
|
698
|
-
if (!parentEnded) {
|
|
699
|
-
// A startup interrupt only acknowledges submission, not native settlement.
|
|
700
|
-
if (!turnId) throw new Error("Codex cancelled before turn admission was observed");
|
|
701
|
-
await client.request("turn/interrupt", { threadId, turnId }, graceMs);
|
|
702
|
-
}
|
|
703
|
-
const unfinished = await turn.subagents!.settle();
|
|
704
|
-
// Native terminal registration can land after turn/completed and
|
|
705
|
-
// after an empty terminal inventory. EOF awaits native thread/tool
|
|
706
|
-
// shutdown; an idle snapshot alone cannot release a managed turn.
|
|
707
|
-
confirmed = await client.closeAndWait(graceMs);
|
|
708
|
-
if (!confirmed) throw new Error("Codex native cleanup was not confirmed");
|
|
709
|
-
if (unfinished && !controller.signal.aborted) {
|
|
710
|
-
failure = new Error(
|
|
711
|
-
"Parent finished with outstanding subagent work; workers were stopped and the result is incomplete",
|
|
712
|
-
);
|
|
713
|
-
}
|
|
714
|
-
} catch (error) {
|
|
715
|
-
failure = error;
|
|
716
|
-
confirmed = await client.closeAndWait(graceMs);
|
|
717
|
-
if (!confirmed) this.unsettledSessions.set(options.sessionId, client);
|
|
718
|
-
} finally {
|
|
719
|
-
clearTimeout(deadline);
|
|
720
|
-
}
|
|
721
|
-
turnEnded = true;
|
|
722
|
-
if (controller.signal.aborted) queue.fail(new Error("turn aborted"));
|
|
723
|
-
else if (failure) queue.fail(failure);
|
|
724
|
-
else queue.end();
|
|
725
|
-
return confirmed;
|
|
726
|
-
})();
|
|
727
|
-
return managedCompletion;
|
|
728
|
-
};
|
|
729
|
-
const forceCancel = () => {
|
|
730
|
-
if (turnEnded) return;
|
|
731
|
-
queue.fail(new Error("turn aborted"));
|
|
732
|
-
client.close();
|
|
733
|
-
};
|
|
734
|
-
const onAbort = () => {
|
|
735
|
-
clearStall();
|
|
736
|
-
if (interruptState.acknowledgement) return;
|
|
737
|
-
if (turn.subagents) {
|
|
738
|
-
interruptState.acknowledgement = finishManaged();
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
if (!turnId) {
|
|
742
|
-
interruptState.acknowledgement = Promise.resolve(false);
|
|
743
|
-
forceCancel();
|
|
744
|
-
return;
|
|
745
|
-
}
|
|
746
|
-
const graceMs = this.agentOptions.cancelGraceMs ?? 2_000;
|
|
747
|
-
cancelTimer = setTimeout(forceCancel, graceMs);
|
|
748
|
-
cancelTimer.unref?.();
|
|
749
|
-
interruptState.acknowledgement = client
|
|
750
|
-
.request("turn/interrupt", { threadId, turnId }, graceMs)
|
|
751
|
-
.then(
|
|
752
|
-
() => true,
|
|
753
|
-
() => {
|
|
754
|
-
forceCancel();
|
|
755
|
-
return false;
|
|
756
|
-
},
|
|
757
|
-
);
|
|
758
|
-
};
|
|
759
|
-
|
|
760
|
-
unsubscribe.push(
|
|
761
|
-
client.onNotification((n) => {
|
|
762
|
-
turn.subagents?.observe(n);
|
|
763
|
-
if (n.params.threadId && n.params.threadId !== threadId) return;
|
|
764
|
-
if (n.method === "turn/started") {
|
|
765
|
-
const turn = n.params.turn as { id?: string } | undefined;
|
|
766
|
-
if (turn?.id) {
|
|
767
|
-
turnId = turn.id;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
if (appServerNotificationEndsTurn(n) && turn.subagents) {
|
|
771
|
-
parentEnded = n.method === "turn/completed";
|
|
772
|
-
queue.push(n);
|
|
773
|
-
void finishManaged();
|
|
774
|
-
return;
|
|
775
|
-
}
|
|
776
|
-
if (appServerNotificationEndsTurn(n)) turnEnded = true;
|
|
777
|
-
if (turnEnded && controller.signal.aborted) {
|
|
778
|
-
queue.fail(new Error("turn aborted"));
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
queue.push(n);
|
|
782
|
-
if (appServerNotificationEndsTurn(n)) queue.end();
|
|
783
|
-
if (!controller.signal.aborted && n.method === "error" && n.params.willRetry === true) {
|
|
784
|
-
clearStall();
|
|
785
|
-
stallTimer = setTimeout(() => {
|
|
786
|
-
queue.fail(new Error("codex app-server went silent after a retryable error"));
|
|
787
|
-
client.close();
|
|
788
|
-
}, this.agentOptions.retryStallTimeoutMs ?? RETRY_STALL_TIMEOUT_MS);
|
|
789
|
-
stallTimer.unref?.();
|
|
790
|
-
} else {
|
|
791
|
-
clearStall();
|
|
792
|
-
}
|
|
793
|
-
}),
|
|
794
|
-
);
|
|
795
|
-
// If the subprocess dies mid-turn, fail the turn instead of hanging.
|
|
796
|
-
unsubscribe.push(
|
|
797
|
-
client.onClose((err) => {
|
|
798
|
-
if (managedCompletion) return;
|
|
799
|
-
queue.fail(
|
|
800
|
-
controller.signal.aborted
|
|
801
|
-
? new Error("turn aborted")
|
|
802
|
-
: (err ?? new Error("codex app-server exited mid-turn")),
|
|
803
|
-
);
|
|
804
|
-
}),
|
|
805
|
-
);
|
|
806
|
-
|
|
807
|
-
controller.signal.addEventListener("abort", onAbort, { once: true });
|
|
808
|
-
unsubscribe.push(() => controller.signal.removeEventListener("abort", onAbort));
|
|
809
|
-
|
|
810
|
-
const turnParams: Record<string, unknown> = {
|
|
811
|
-
threadId,
|
|
812
|
-
input: toUserInput(input),
|
|
813
|
-
};
|
|
814
|
-
// A refused turn/start changes nothing on the thread.
|
|
815
|
-
const before = {
|
|
816
|
-
model: session.model,
|
|
817
|
-
reportedModel: session.reportedModel,
|
|
818
|
-
effort: session.effort,
|
|
819
|
-
};
|
|
820
|
-
const switched = Boolean(options.model) && options.model !== session.model;
|
|
821
|
-
if (options.model) {
|
|
822
|
-
turnParams.model = options.model;
|
|
823
|
-
session.model = options.model;
|
|
824
|
-
// A model this turn selects is requested, not reported.
|
|
825
|
-
if (options.model !== session.reportedModel) session.reportedModel = undefined;
|
|
826
|
-
}
|
|
827
|
-
if (options.thinkingLevel) {
|
|
828
|
-
const accepts = await this.modelThinking(
|
|
829
|
-
session,
|
|
830
|
-
options.model ? options.modelThinking : undefined,
|
|
831
|
-
);
|
|
832
|
-
turnParams.effort = codexReasoningEffort(
|
|
833
|
-
options.thinkingLevel,
|
|
834
|
-
accepts?.levels,
|
|
835
|
-
accepts?.off,
|
|
836
|
-
);
|
|
837
|
-
session.effort = turnParams.effort as string;
|
|
838
|
-
} else if (switched && session.effort) {
|
|
839
|
-
// The thread keeps its effort across a model switch. Fit it to the new
|
|
840
|
-
// model, so Codex is not asked for a level that model lacks.
|
|
841
|
-
const kept = codexThinkingLevel(session.effort);
|
|
842
|
-
const accepts = await this.modelThinking(session, options.modelThinking);
|
|
843
|
-
if (kept && accepts?.levels.length) {
|
|
844
|
-
const effort = codexReasoningEffort(kept, accepts.levels, accepts.off);
|
|
845
|
-
if (effort !== session.effort) {
|
|
846
|
-
turnParams.effort = effort;
|
|
847
|
-
session.effort = effort;
|
|
848
|
-
}
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
// Codex runs the effort it is given, and overrides persist on the
|
|
852
|
-
// thread, so the thread's effort is the one this turn runs.
|
|
853
|
-
const applied = codexThinkingLevel(session.effort);
|
|
854
|
-
if (applied || session.reportedModel)
|
|
855
|
-
options.onExecution?.({
|
|
856
|
-
...(applied && { thinkingLevel: applied }),
|
|
857
|
-
...(session.reportedModel && { model: session.reportedModel }),
|
|
858
|
-
});
|
|
859
|
-
|
|
860
|
-
if (controller.signal.aborted) throw new Error("turn aborted");
|
|
861
|
-
if (this.invalidatedClients.has(client)) {
|
|
862
|
-
client.close();
|
|
863
|
-
throw new Error("Codex process was invalidated before turn admission");
|
|
864
|
-
}
|
|
865
|
-
client.request("turn/start", turnParams).catch((err: unknown) => {
|
|
866
|
-
if (session) Object.assign(session, before);
|
|
867
|
-
if (controller.signal.aborted) {
|
|
868
|
-
if (turn.subagents) void finishManaged();
|
|
869
|
-
else forceCancel();
|
|
870
|
-
return;
|
|
871
|
-
}
|
|
872
|
-
queue.push({ method: "error", params: { message: String(err) } });
|
|
873
|
-
queue.end();
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
for await (const notification of queue) {
|
|
877
|
-
yield notification as RawAgentEvent;
|
|
878
|
-
}
|
|
879
|
-
} catch (error) {
|
|
880
|
-
throw controller.signal.aborted ? new Error("turn aborted") : error;
|
|
881
|
-
} finally {
|
|
882
|
-
if (managedCompletion) await managedCompletion;
|
|
883
|
-
// Every exit owns cleanup, including turn/start failure and iterator.return().
|
|
884
|
-
if (options.subagentMode === "turn" && session && !(await session.client.closeAndWait())) {
|
|
885
|
-
this.unsettledSessions.set(options.sessionId, session.client);
|
|
886
|
-
}
|
|
887
|
-
turnEnded = true;
|
|
888
|
-
clearStall();
|
|
889
|
-
if (cancelTimer) clearTimeout(cancelTimer);
|
|
890
|
-
for (const off of unsubscribe) off();
|
|
891
|
-
if (session?.turn === turn) {
|
|
892
|
-
session.turn = undefined;
|
|
893
|
-
if (!session.client.closed) {
|
|
894
|
-
this.sessions.armIdle(
|
|
895
|
-
options.sessionId,
|
|
896
|
-
session,
|
|
897
|
-
this.agentOptions.idleTimeoutMs ?? IDLE_TIMEOUT_MS,
|
|
898
|
-
);
|
|
899
|
-
}
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
override async cancel(sessionId: string): Promise<CancelResult> {
|
|
905
|
-
// Snapshot the in-flight controllers before super.cancel() aborts them:
|
|
906
|
-
// the abort unblocks execute()'s queue and finally's endTurn drains the
|
|
907
|
-
// set on a later microtask, so reading afterwards would race that drain.
|
|
908
|
-
const controllers = [...(this.inflight.get(sessionId) ?? [])];
|
|
909
|
-
const base = await super.cancel(sessionId);
|
|
910
|
-
if (!base.hadTurn) {
|
|
911
|
-
const unsettled = this.unsettledSessions.get(sessionId);
|
|
912
|
-
if (!unsettled) return base;
|
|
913
|
-
const confirmed = await unsettled.closeAndWait();
|
|
914
|
-
if (confirmed) this.unsettledSessions.delete(sessionId);
|
|
915
|
-
return { confirmed, hadTurn: false };
|
|
916
|
-
}
|
|
917
|
-
const acknowledgements = await Promise.all(
|
|
918
|
-
controllers.map(
|
|
919
|
-
(controller) => this.turnInterruptState.get(controller)?.acknowledgement ?? false,
|
|
920
|
-
),
|
|
921
|
-
);
|
|
922
|
-
const confirmed = acknowledgements.every(Boolean);
|
|
923
|
-
return { confirmed, hadTurn: true };
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
/** Unchanged MCP config reloads retain dead remote connections after VM resume. */
|
|
927
|
-
invalidateMcpConnections(): void {
|
|
928
|
-
// Keep SessionAgent's conversation targets and runtime admission receipts.
|
|
929
|
-
// Transport recovery can signal this while a turn is running: let that
|
|
930
|
-
// turn finish, then use the existing strict thread/resume path.
|
|
931
|
-
const active = new Set(
|
|
932
|
-
[...this.sessions.values()]
|
|
933
|
-
.filter((session) => session.turn)
|
|
934
|
-
.map((session) => session.client),
|
|
935
|
-
);
|
|
936
|
-
for (const client of this.sessions.clients()) {
|
|
937
|
-
this.invalidatedClients.add(client);
|
|
938
|
-
if (!active.has(client)) client.close();
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
|
|
942
|
-
override async release(sessionId: string): Promise<void> {
|
|
943
|
-
// A host may release this harness before switching providers. Do not let
|
|
944
|
-
// that path discard ownership while managed child cleanup is unconfirmed.
|
|
945
|
-
const managed =
|
|
946
|
-
this.unsettledSessions.has(sessionId) ||
|
|
947
|
-
this.sessions.get(sessionId)?.subagentMode === "turn";
|
|
948
|
-
if (managed && !(await this.cancel(sessionId)).confirmed)
|
|
949
|
-
throw new Error("Codex native cleanup was not confirmed; cannot release the session");
|
|
950
|
-
await super.release(sessionId);
|
|
951
|
-
this.sessions.close(sessionId);
|
|
952
|
-
for (const [home, owner] of this.mcpHomes) {
|
|
953
|
-
if (owner === sessionId) this.mcpHomes.delete(home);
|
|
954
|
-
}
|
|
955
|
-
}
|
|
956
|
-
|
|
957
|
-
override async terminateAll(): Promise<void> {
|
|
958
|
-
await super.terminateAll();
|
|
959
|
-
this.sessions.closeAll();
|
|
960
|
-
this.mcpHomes.clear();
|
|
961
|
-
}
|
|
962
|
-
}
|