@zvada/agent-server 0.3.22 → 0.3.24
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/CHANGELOG.md +295 -0
- package/README.md +14 -5
- package/dist/accounts/chatgpt.js +144 -0
- package/dist/accounts/check.js +71 -0
- package/dist/accounts/claude.js +80 -0
- package/dist/accounts/endpoint.js +104 -0
- package/dist/accounts/http.js +58 -0
- package/dist/accounts/index.js +9 -0
- package/dist/client/client.js +686 -0
- package/dist/client/connection.js +338 -0
- package/dist/client/history.js +49 -0
- package/dist/client/index.js +6 -0
- package/dist/client/listeners.js +19 -0
- package/dist/client/logins.js +92 -0
- package/dist/client/rpc.js +105 -0
- package/dist/client/streams.js +432 -0
- package/dist/client/transports.js +118 -0
- package/dist/client/turns.js +122 -0
- package/dist/core/agents/acp/acp-agent.js +425 -0
- package/dist/core/agents/acp/adapter.js +231 -0
- package/dist/core/agents/acp/client.js +222 -0
- package/dist/core/agents/acp/known-agents.js +57 -0
- package/dist/core/agents/acp/mappings.js +164 -0
- package/dist/core/agents/acp/requests.js +79 -0
- package/dist/core/agents/attachments.js +14 -0
- package/dist/core/agents/base.js +64 -0
- package/dist/core/agents/claude-code/adapter.js +474 -0
- package/dist/core/agents/claude-code/approvals.js +245 -0
- package/dist/core/agents/claude-code/claude-agent.js +319 -0
- package/dist/core/agents/claude-code/credentials.js +142 -0
- package/dist/core/agents/claude-code/events.js +11 -0
- package/dist/core/agents/claude-code/login.js +217 -0
- package/dist/core/agents/claude-code/mcp.js +181 -0
- package/dist/core/agents/claude-code/models.js +74 -0
- package/dist/core/agents/claude-code/options.js +240 -0
- package/dist/core/agents/claude-code/outcome.js +204 -0
- package/dist/core/agents/claude-code/results.js +58 -0
- package/dist/core/agents/claude-code/sdk-pair.js +59 -0
- package/dist/core/agents/claude-code/session.js +593 -0
- package/dist/core/agents/claude-code/spawn.js +125 -0
- package/dist/core/agents/claude-code/spend.js +118 -0
- package/dist/core/agents/claude-code/tools.js +131 -0
- package/dist/core/agents/claude-code/turn-usage.js +121 -0
- package/dist/core/agents/claude-code/turn.js +199 -0
- package/dist/core/agents/codex-app-server/adapter.js +463 -0
- package/dist/core/agents/codex-app-server/client.js +338 -0
- package/dist/core/agents/codex-app-server/codex-agent.js +294 -0
- package/dist/core/agents/codex-app-server/commands.js +184 -0
- package/dist/core/agents/codex-app-server/credentials.js +92 -0
- package/dist/core/agents/codex-app-server/effort.js +13 -0
- package/dist/core/agents/codex-app-server/events.js +18 -0
- package/dist/core/agents/codex-app-server/homes.js +118 -0
- package/dist/core/agents/codex-app-server/input.js +52 -0
- package/dist/core/agents/codex-app-server/items.js +307 -0
- package/dist/core/agents/codex-app-server/login.js +183 -0
- package/dist/core/agents/codex-app-server/mcp.js +323 -0
- package/dist/core/agents/codex-app-server/models.js +160 -0
- package/dist/core/agents/codex-app-server/options.js +155 -0
- package/dist/core/agents/codex-app-server/plan-approval.js +124 -0
- package/dist/core/agents/codex-app-server/protocol.js +38 -0
- package/dist/core/agents/codex-app-server/requests.js +250 -0
- package/dist/core/agents/codex-app-server/session.js +278 -0
- package/dist/core/agents/codex-app-server/subagents.js +260 -0
- package/dist/core/agents/codex-app-server/thread-settings.js +214 -0
- package/dist/core/agents/codex-app-server/turn-items.js +69 -0
- package/dist/core/agents/codex-app-server/turn.js +448 -0
- package/dist/core/agents/codex-app-server/user-login.js +78 -0
- package/dist/core/agents/config-fingerprint.js +10 -0
- package/dist/core/agents/credentials.js +71 -0
- package/dist/core/agents/diffs.js +27 -0
- package/dist/core/agents/elicitation.js +42 -0
- package/dist/core/agents/inherit-config.js +5 -0
- package/dist/core/agents/login.js +56 -0
- package/dist/core/agents/mcp-config.js +109 -0
- package/dist/core/agents/plan.js +6 -0
- package/dist/core/agents/process-pool.js +307 -0
- package/dist/core/agents/registry.js +49 -0
- package/dist/core/agents/scripted/adapter.js +86 -0
- package/dist/core/agents/scripted/mcp-call.js +74 -0
- package/dist/core/agents/scripted/scripted-agent.js +330 -0
- package/dist/core/agents/scripted/scripts.js +154 -0
- package/dist/core/agents/scripted/steps.js +87 -0
- package/dist/core/agents/session-agent.js +209 -0
- package/dist/core/agents/stderr-tail.js +71 -0
- package/dist/core/agents/thinking-levels.js +9 -0
- package/dist/core/agents/types.js +1 -0
- package/dist/core/diagnostics.js +23 -0
- package/dist/core/index.js +31 -0
- package/dist/core/presets.js +114 -0
- package/dist/core/processes/identity.js +91 -0
- package/dist/core/processes/lifeline.js +210 -0
- package/dist/core/processes/native-processes.js +299 -0
- package/dist/core/processes/process-table.js +163 -0
- package/dist/core/provision/cache-trust.js +121 -0
- package/dist/core/provision/cache-usage.js +61 -0
- package/dist/core/provision/checksums.js +22 -0
- package/dist/core/provision/extract.js +28 -0
- package/dist/core/provision/index.js +4 -0
- package/dist/core/provision/install-build.js +99 -0
- package/dist/core/provision/npm.js +316 -0
- package/dist/core/provision/pins.js +35 -0
- package/dist/core/provision/platform.js +65 -0
- package/dist/core/provision/provisioner.js +372 -0
- package/dist/core/provision/releases.js +68 -0
- package/dist/core/provision/tools.js +279 -0
- package/dist/core/proxy/anthropic-proxy.js +163 -0
- package/dist/core/proxy/api-key-store.js +30 -0
- package/dist/core/proxy/index.js +3 -0
- package/dist/core/proxy/loopback.js +86 -0
- package/dist/core/runtime/agent-runtime.js +434 -0
- package/dist/core/runtime/event-processor.js +379 -0
- package/dist/core/runtime/event-sink.js +65 -0
- package/dist/core/runtime/harness-clis.js +83 -0
- package/dist/core/runtime/harness-logins.js +313 -0
- package/dist/core/runtime/login-reads.js +71 -0
- package/dist/core/runtime/model-lists.js +160 -0
- package/dist/core/runtime/permission-policy.js +84 -0
- package/dist/core/runtime/request-broker.js +139 -0
- package/dist/core/runtime/steering.js +79 -0
- package/dist/core/runtime/turn-outcome.js +16 -0
- package/dist/core/runtime/turn.js +329 -0
- package/dist/core/utils/bounded.js +13 -0
- package/dist/core/utils/deadline.js +57 -0
- package/dist/core/utils/errors.js +176 -0
- package/dist/core/utils/is-record.js +4 -0
- package/dist/core/utils/loopback.js +11 -0
- package/dist/index.js +4 -0
- package/dist/operator/index.js +10 -0
- package/dist/operator/mcp.js +139 -0
- package/dist/operator/operator.js +499 -0
- package/dist/operator/render.js +408 -0
- package/dist/operator/view.js +35 -0
- package/dist/protocol/account.js +96 -0
- package/dist/protocol/async-queue.js +65 -0
- package/dist/protocol/auth.js +169 -0
- package/dist/protocol/canonical.js +18 -0
- package/dist/protocol/clis.js +63 -0
- package/dist/protocol/config.js +137 -0
- package/dist/protocol/conversation.js +231 -0
- package/dist/protocol/credentials.js +141 -0
- package/dist/protocol/errors.js +181 -0
- package/dist/protocol/execution.js +28 -0
- package/dist/protocol/factories.js +231 -0
- package/dist/protocol/guards.js +71 -0
- package/dist/protocol/harness.js +93 -0
- package/dist/protocol/history.js +201 -0
- package/dist/protocol/ids.js +37 -0
- package/dist/protocol/index.js +36 -0
- package/dist/protocol/lifecycle.js +562 -0
- package/dist/protocol/meta-keys.js +17 -0
- package/dist/protocol/meta.js +13 -0
- package/dist/protocol/model-catalog.js +223 -0
- package/dist/protocol/models.js +84 -0
- package/dist/protocol/part-input.js +94 -0
- package/dist/protocol/parts.js +166 -0
- package/dist/protocol/plan.js +31 -0
- package/dist/protocol/reduce.js +484 -0
- package/dist/protocol/selectors.js +136 -0
- package/dist/protocol/seq-cursor.js +37 -0
- package/dist/protocol/stop-reasons.js +41 -0
- package/dist/protocol/thinking.js +31 -0
- package/dist/protocol/time.js +21 -0
- package/dist/protocol/tokens.js +57 -0
- package/dist/protocol/tool-closure.js +70 -0
- package/dist/protocol/tool-state.js +153 -0
- package/dist/protocol/verify.js +467 -0
- package/dist/protocol/vocabulary.js +27 -0
- package/dist/protocol/wire-api.js +94 -0
- package/dist/protocol/wire.js +669 -0
- package/dist/server/acp/binding.js +251 -0
- package/dist/server/acp/session-records.js +53 -0
- package/dist/server/acp/translate.js +401 -0
- package/dist/server/agent-server.js +338 -0
- package/dist/server/bin.js +492 -0
- package/dist/server/feedback.js +216 -0
- package/dist/server/history.js +123 -0
- package/dist/server/index.js +8 -0
- package/dist/server/install.js +171 -0
- package/dist/server/open-parts.js +87 -0
- package/dist/server/routes.js +291 -0
- package/dist/server/secrets.js +19 -0
- package/dist/server/session-gate.js +54 -0
- package/dist/server/session-log.js +66 -0
- package/dist/server/session-store.js +243 -0
- package/dist/server/subscriptions.js +189 -0
- package/dist/server/transports.js +214 -0
- package/dist/server/wire-error.js +26 -0
- package/dist/sync/event-log.js +89 -0
- package/dist/sync/fit.js +202 -0
- package/dist/sync/history-reader.js +33 -0
- package/dist/sync/history-sqlite.js +281 -0
- package/dist/sync/history.js +163 -0
- package/dist/sync/index.js +5 -0
- package/dist/sync/journal-sqlite.js +316 -0
- package/dist/sync/journal.js +10 -0
- package/dist/sync/live-tails.js +85 -0
- package/dist/sync/node-sqlite.js +27 -0
- package/dist/sync/projection.js +32 -0
- package/dist/sync/recovery.js +117 -0
- package/dist/sync/retry.js +45 -0
- package/dist/sync/schema.js +73 -0
- package/dist/sync/sql.js +94 -0
- package/dist/sync/sqlite-file.js +31 -0
- package/dist/sync/sqlite.js +18 -0
- package/dist/sync/worker.js +212 -0
- package/dist/types/accounts/chatgpt.d.ts +1 -1
- package/dist/types/accounts/chatgpt.d.ts.map +1 -1
- package/dist/types/accounts/http.d.ts +2 -4
- package/dist/types/accounts/http.d.ts.map +1 -1
- package/dist/types/client/client.d.ts +37 -11
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/connection.d.ts +64 -13
- package/dist/types/client/connection.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/logins.d.ts +2 -1
- package/dist/types/client/logins.d.ts.map +1 -1
- package/dist/types/client/streams.d.ts +9 -3
- package/dist/types/client/streams.d.ts.map +1 -1
- package/dist/types/client/turns.d.ts +1 -1
- package/dist/types/client/turns.d.ts.map +1 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/acp/client.d.ts +12 -3
- package/dist/types/core/agents/acp/client.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +8 -2
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/base.d.ts +22 -8
- package/dist/types/core/agents/base.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +19 -5
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/events.d.ts +9 -1
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/login.d.ts +4 -1
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/mcp.d.ts +21 -7
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/models.d.ts +5 -1
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/options.d.ts +29 -10
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/outcome.d.ts +3 -5
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/results.d.ts +16 -0
- package/dist/types/core/agents/claude-code/results.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/sdk-pair.d.ts +13 -0
- package/dist/types/core/agents/claude-code/sdk-pair.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +58 -12
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/spend.d.ts +2 -1
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/tools.d.ts +26 -3
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/client.d.ts +12 -2
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +58 -13
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/homes.d.ts +25 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts +16 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +15 -30
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/options.d.ts +27 -4
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/session.d.ts +71 -40
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn.d.ts +31 -8
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
- package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +3 -1
- package/dist/types/core/agents/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/diffs.d.ts +9 -0
- package/dist/types/core/agents/diffs.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +3 -2
- package/dist/types/core/agents/elicitation.d.ts.map +1 -1
- package/dist/types/core/agents/login.d.ts +6 -0
- package/dist/types/core/agents/login.d.ts.map +1 -1
- package/dist/types/core/agents/mcp-config.d.ts +0 -4
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
- package/dist/types/core/agents/process-pool.d.ts +201 -0
- package/dist/types/core/agents/process-pool.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/adapter.d.ts +68 -0
- package/dist/types/core/agents/scripted/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/mcp-call.d.ts +56 -0
- package/dist/types/core/agents/scripted/mcp-call.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/scripted-agent.d.ts +73 -0
- package/dist/types/core/agents/scripted/scripted-agent.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/scripts.d.ts +29 -0
- package/dist/types/core/agents/scripted/scripts.d.ts.map +1 -0
- package/dist/types/core/agents/scripted/steps.d.ts +132 -0
- package/dist/types/core/agents/scripted/steps.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +49 -6
- package/dist/types/core/agents/session-agent.d.ts.map +1 -1
- package/dist/types/core/diagnostics.d.ts +4 -1
- package/dist/types/core/diagnostics.d.ts.map +1 -1
- package/dist/types/core/index.d.ts +5 -0
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +32 -6
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/lifeline.d.ts +0 -20
- package/dist/types/core/processes/lifeline.d.ts.map +1 -1
- package/dist/types/core/provision/index.d.ts +2 -2
- package/dist/types/core/provision/index.d.ts.map +1 -1
- package/dist/types/core/provision/install-build.d.ts +2 -1
- package/dist/types/core/provision/install-build.d.ts.map +1 -1
- package/dist/types/core/provision/npm.d.ts +20 -8
- package/dist/types/core/provision/npm.d.ts.map +1 -1
- package/dist/types/core/provision/provisioner.d.ts +4 -1
- package/dist/types/core/provision/provisioner.d.ts.map +1 -1
- package/dist/types/core/provision/tools.d.ts +2 -1
- package/dist/types/core/provision/tools.d.ts.map +1 -1
- package/dist/types/core/runtime/agent-runtime.d.ts +16 -8
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts +5 -1
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-clis.d.ts +9 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-logins.d.ts +33 -5
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
- package/dist/types/core/runtime/model-lists.d.ts +2 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
- package/dist/types/core/runtime/permission-policy.d.ts +5 -3
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
- package/dist/types/core/runtime/request-broker.d.ts +2 -1
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
- package/dist/types/core/runtime/turn.d.ts +12 -1
- package/dist/types/core/runtime/turn.d.ts.map +1 -1
- package/dist/types/core/utils/deadline.d.ts +6 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -1
- package/dist/types/core/utils/errors.d.ts +7 -1
- package/dist/types/core/utils/errors.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/render.d.ts +6 -4
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/protocol/auth.d.ts +54 -24
- package/dist/types/protocol/auth.d.ts.map +1 -1
- package/dist/types/protocol/clis.d.ts +14 -7
- package/dist/types/protocol/clis.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +2 -0
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +40 -3
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/credentials.d.ts +7 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +2 -1
- package/dist/types/protocol/execution.d.ts.map +1 -1
- package/dist/types/protocol/factories.d.ts +12 -2
- package/dist/types/protocol/factories.d.ts.map +1 -1
- package/dist/types/protocol/harness.d.ts +6 -2
- package/dist/types/protocol/harness.d.ts.map +1 -1
- package/dist/types/protocol/history.d.ts +19 -0
- package/dist/types/protocol/history.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +47 -8
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/model-catalog.d.ts.map +1 -1
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/parts.d.ts +14 -0
- package/dist/types/protocol/parts.d.ts.map +1 -1
- package/dist/types/protocol/tool-state.d.ts +12 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +129 -23
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +70 -10
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/acp/binding.d.ts +6 -1
- package/dist/types/server/acp/binding.d.ts.map +1 -1
- package/dist/types/server/acp/translate.d.ts +33 -7
- package/dist/types/server/acp/translate.d.ts.map +1 -1
- package/dist/types/server/agent-server.d.ts +6 -0
- package/dist/types/server/agent-server.d.ts.map +1 -1
- package/dist/types/server/bin.d.ts +3 -0
- package/dist/types/server/bin.d.ts.map +1 -0
- package/dist/types/server/feedback.d.ts +2 -1
- package/dist/types/server/feedback.d.ts.map +1 -1
- package/dist/types/server/install.d.ts +11 -0
- package/dist/types/server/install.d.ts.map +1 -1
- package/dist/types/server/session-gate.d.ts +2 -1
- package/dist/types/server/session-gate.d.ts.map +1 -1
- package/dist/types/server/session-store.d.ts +1 -0
- package/dist/types/server/session-store.d.ts.map +1 -1
- package/dist/types/server/subscriptions.d.ts +2 -1
- package/dist/types/server/subscriptions.d.ts.map +1 -1
- package/dist/types/server/transports.d.ts +2 -1
- package/dist/types/server/transports.d.ts.map +1 -1
- package/dist/types/sync/fit.d.ts +8 -7
- package/dist/types/sync/fit.d.ts.map +1 -1
- package/dist/types/sync/history-sqlite.d.ts.map +1 -1
- package/dist/types/sync/index.d.ts +1 -0
- package/dist/types/sync/index.d.ts.map +1 -1
- package/dist/types/sync/journal-sqlite.d.ts +2 -1
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -1
- package/dist/types/sync/journal.d.ts +11 -3
- package/dist/types/sync/journal.d.ts.map +1 -1
- package/dist/types/sync/node-sqlite.d.ts +4 -1
- package/dist/types/sync/node-sqlite.d.ts.map +1 -1
- package/dist/types/sync/projection.d.ts +6 -0
- package/dist/types/sync/projection.d.ts.map +1 -1
- package/dist/types/sync/recovery.d.ts +2 -1
- package/dist/types/sync/recovery.d.ts.map +1 -1
- package/dist/types/sync/schema.d.ts +10 -0
- package/dist/types/sync/schema.d.ts.map +1 -1
- package/dist/types/sync/sql.d.ts +2 -1
- package/dist/types/sync/sql.d.ts.map +1 -1
- package/docs/consuming.md +304 -28
- package/docs/deploy.md +64 -8
- package/docs/durable-sessions.md +35 -5
- package/docs/harnesses.md +398 -25
- package/package.json +48 -18
- package/src/accounts/chatgpt.ts +2 -2
- package/src/accounts/http.ts +2 -16
- package/src/client/client.ts +92 -31
- package/src/client/connection.ts +103 -22
- package/src/client/index.ts +1 -0
- package/src/client/logins.ts +1 -1
- package/src/client/streams.ts +12 -4
- package/src/client/turns.ts +1 -1
- package/src/core/agents/acp/acp-agent.ts +181 -52
- package/src/core/agents/acp/adapter.ts +9 -1
- package/src/core/agents/acp/client.ts +16 -4
- package/src/core/agents/acp/mappings.ts +27 -0
- package/src/core/agents/base.ts +25 -10
- package/src/core/agents/claude-code/adapter.ts +47 -17
- package/src/core/agents/claude-code/approvals.ts +11 -6
- package/src/core/agents/claude-code/claude-agent.ts +89 -32
- package/src/core/agents/claude-code/events.ts +11 -1
- package/src/core/agents/claude-code/login.ts +14 -2
- package/src/core/agents/claude-code/mcp.ts +31 -15
- package/src/core/agents/claude-code/models.ts +7 -2
- package/src/core/agents/claude-code/options.ts +30 -9
- package/src/core/agents/claude-code/outcome.ts +10 -2
- package/src/core/agents/claude-code/results.ts +73 -0
- package/src/core/agents/claude-code/sdk-pair.ts +66 -0
- package/src/core/agents/claude-code/session.ts +179 -37
- package/src/core/agents/claude-code/spend.ts +1 -1
- package/src/core/agents/claude-code/tools.ts +108 -12
- package/src/core/agents/codex-app-server/adapter.ts +37 -12
- package/src/core/agents/codex-app-server/client.ts +37 -8
- package/src/core/agents/codex-app-server/codex-agent.ts +115 -50
- package/src/core/agents/codex-app-server/commands.ts +2 -2
- package/src/core/agents/codex-app-server/credentials.ts +10 -5
- package/src/core/agents/codex-app-server/effort.ts +1 -1
- package/src/core/agents/codex-app-server/homes.ts +54 -3
- package/src/core/agents/codex-app-server/items.ts +219 -31
- package/src/core/agents/codex-app-server/login.ts +44 -2
- package/src/core/agents/codex-app-server/mcp.ts +47 -32
- package/src/core/agents/codex-app-server/models.ts +9 -8
- package/src/core/agents/codex-app-server/options.ts +69 -10
- package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
- package/src/core/agents/codex-app-server/protocol.ts +14 -4
- package/src/core/agents/codex-app-server/requests.ts +17 -8
- package/src/core/agents/codex-app-server/session.ts +160 -113
- package/src/core/agents/codex-app-server/subagents.ts +21 -14
- package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
- package/src/core/agents/codex-app-server/turn-items.ts +1 -1
- package/src/core/agents/codex-app-server/turn.ts +79 -32
- package/src/core/agents/codex-app-server/user-login.ts +107 -0
- package/src/core/agents/credentials.ts +5 -2
- package/src/core/agents/diffs.ts +25 -0
- package/src/core/agents/elicitation.ts +2 -2
- package/src/core/agents/login.ts +6 -0
- package/src/core/agents/mcp-config.ts +2 -2
- package/src/core/agents/process-pool.ts +458 -0
- package/src/core/agents/scripted/adapter.ts +142 -0
- package/src/core/agents/scripted/mcp-call.ts +134 -0
- package/src/core/agents/scripted/scripted-agent.ts +418 -0
- package/src/core/agents/scripted/scripts.ts +171 -0
- package/src/core/agents/scripted/steps.ts +127 -0
- package/src/core/agents/session-agent.ts +105 -8
- package/src/core/diagnostics.ts +9 -1
- package/src/core/index.ts +11 -0
- package/src/core/presets.ts +100 -14
- package/src/core/processes/lifeline.ts +99 -25
- package/src/core/provision/index.ts +1 -2
- package/src/core/provision/install-build.ts +4 -1
- package/src/core/provision/npm.ts +309 -97
- package/src/core/provision/provisioner.ts +22 -8
- package/src/core/provision/tools.ts +44 -19
- package/src/core/runtime/agent-runtime.ts +48 -18
- package/src/core/runtime/event-processor.ts +18 -2
- package/src/core/runtime/harness-clis.ts +36 -1
- package/src/core/runtime/harness-logins.ts +82 -31
- package/src/core/runtime/model-lists.ts +1 -1
- package/src/core/runtime/permission-policy.ts +4 -3
- package/src/core/runtime/request-broker.ts +1 -1
- package/src/core/runtime/turn.ts +51 -3
- package/src/core/utils/deadline.ts +23 -0
- package/src/core/utils/errors.ts +11 -4
- package/src/operator/operator.ts +8 -4
- package/src/operator/render.ts +46 -8
- package/src/protocol/auth.ts +30 -23
- package/src/protocol/clis.ts +12 -4
- package/src/protocol/credentials.ts +19 -0
- package/src/protocol/execution.ts +5 -0
- package/src/protocol/factories.ts +25 -3
- package/src/protocol/harness.ts +11 -1
- package/src/protocol/history.ts +20 -0
- package/src/protocol/lifecycle.ts +10 -1
- package/src/protocol/model-catalog.ts +19 -8
- package/src/protocol/parts.ts +12 -1
- package/src/protocol/tool-state.ts +14 -1
- package/src/protocol/wire.ts +14 -0
- package/src/server/acp/binding.ts +113 -23
- package/src/server/acp/translate.ts +161 -8
- package/src/server/agent-server.ts +10 -1
- package/src/server/bin.ts +108 -19
- package/src/server/feedback.ts +1 -1
- package/src/server/install.ts +82 -4
- package/src/server/session-gate.ts +1 -1
- package/src/server/session-store.ts +5 -1
- package/src/server/subscriptions.ts +1 -1
- package/src/server/transports.ts +20 -1
- package/src/sync/fit.ts +115 -28
- package/src/sync/history-sqlite.ts +6 -2
- package/src/sync/index.ts +1 -0
- package/src/sync/journal-sqlite.ts +20 -2
- package/src/sync/journal.ts +10 -2
- package/src/sync/node-sqlite.ts +19 -3
- package/src/sync/projection.ts +10 -0
- package/src/sync/recovery.ts +11 -4
- package/src/sync/schema.ts +7 -5
- package/src/sync/sql.ts +1 -1
- package/dist/types/core/agents/claude-code/session-pool.d.ts +0 -36
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +0 -1
- package/dist/types/core/agents/session-pool.d.ts +0 -41
- package/dist/types/core/agents/session-pool.d.ts.map +0 -1
- package/src/core/agents/claude-code/session-pool.ts +0 -136
- package/src/core/agents/session-pool.ts +0 -111
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { onAbort } from "../../utils/deadline.ts";
|
|
2
2
|
import { SessionResumeError } from "../../utils/errors.ts";
|
|
3
3
|
import type { AgentExecuteOptions } from "../base.ts";
|
|
4
|
-
import
|
|
5
|
-
import { SessionPool } from "../session-pool.ts";
|
|
4
|
+
import { ProcessPool } from "../process-pool.ts";
|
|
6
5
|
import type { CodexConnection } from "./client.ts";
|
|
7
6
|
import { type CodexAuth, authFingerprint, logIn } from "./credentials.ts";
|
|
8
|
-
import { CodexHomes } from "./homes.ts";
|
|
9
|
-
import {
|
|
7
|
+
import { CodexHomes, holdHome, homeIdentity } from "./homes.ts";
|
|
8
|
+
import { codexLoginMark, codexLoginStore } from "./login.ts";
|
|
9
|
+
import { CodexMcpState, type CodexTurnMcp, codexTurnMcp, threadServersFingerprint } from "./mcp.ts";
|
|
10
10
|
import type { CodexModelThinking } from "./models.ts";
|
|
11
11
|
import {
|
|
12
12
|
type CodexProcessIdentity,
|
|
13
|
+
type CodexThreadParams,
|
|
14
|
+
type CodexThreadPolicy,
|
|
13
15
|
codexSessionCompatible,
|
|
14
16
|
processIdentity,
|
|
15
17
|
threadParams,
|
|
@@ -26,28 +28,41 @@ export interface CodexSession extends CodexProcessIdentity {
|
|
|
26
28
|
authFingerprint?: string;
|
|
27
29
|
mcp: CodexMcpState;
|
|
28
30
|
/**
|
|
29
|
-
* The
|
|
30
|
-
* (`
|
|
31
|
+
* The `mcp_servers` table its thread was opened with
|
|
32
|
+
* (`threadServersFingerprint`): a turn that needs another runs in another
|
|
33
|
+
* process.
|
|
31
34
|
*/
|
|
32
|
-
|
|
35
|
+
threadServers: string;
|
|
36
|
+
/**
|
|
37
|
+
* The environments each `turn/start` names, when the operator turned
|
|
38
|
+
* Codex's local tools off (`CodexTurn` sends them; it knows no policy).
|
|
39
|
+
*/
|
|
40
|
+
environments?: [];
|
|
33
41
|
/** The logical session's thread settings, which outlive this process. */
|
|
34
42
|
thread: CodexThread;
|
|
35
43
|
/** The turn that has the session: Codex's requests answer for it alone. */
|
|
36
44
|
turn?: CodexTurnScope;
|
|
37
45
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
46
|
+
* Whether a host resume came since it started, which left its MCP
|
|
47
|
+
* connections dead: no `turn/start` is sent on it, and the next turn
|
|
48
|
+
* replaces it (the pool's `startedBeforeResume`).
|
|
40
49
|
*/
|
|
41
|
-
|
|
42
|
-
/** The
|
|
43
|
-
|
|
50
|
+
startedBeforeResume(): boolean;
|
|
51
|
+
/** The folder its `CODEX_HOME` was when it started (`homeIdentity`): another one's turn replaces it. */
|
|
52
|
+
home?: string;
|
|
44
53
|
/** What each model accepts, from this process's `model/list`; read once. */
|
|
45
54
|
modelThinking?: Promise<ReadonlyMap<string, CodexModelThinking> | undefined>;
|
|
46
|
-
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** What a Codex turn brings to the pool: its options, its scope (the account it runs as) and its MCP servers. */
|
|
58
|
+
interface CodexPoolTurn {
|
|
59
|
+
options: AgentExecuteOptions;
|
|
60
|
+
scope: CodexTurnScope;
|
|
61
|
+
mcp: CodexTurnMcp;
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
/** Starts a connection to a new `codex app-server` for a turn's folder, `env` and login. */
|
|
50
|
-
|
|
65
|
+
type CodexConnector = (
|
|
51
66
|
options: AgentExecuteOptions,
|
|
52
67
|
auth: CodexAuth | undefined,
|
|
53
68
|
signal: AbortSignal,
|
|
@@ -55,17 +70,14 @@ export type CodexConnector = (
|
|
|
55
70
|
|
|
56
71
|
/**
|
|
57
72
|
* Start the session's thread, or resume the one it names: never a new one in
|
|
58
|
-
* its place, so a resume that fails fails the turn.
|
|
59
|
-
* servers the thread carries in its own config.
|
|
73
|
+
* its place, so a resume that fails fails the turn.
|
|
60
74
|
*/
|
|
61
75
|
async function openThread(
|
|
62
76
|
client: CodexConnection,
|
|
63
77
|
options: AgentExecuteOptions,
|
|
64
|
-
|
|
65
|
-
mcpServers: Record<string, unknown> | undefined,
|
|
78
|
+
params: CodexThreadParams,
|
|
66
79
|
): Promise<CodexThreadOpened & { threadId: string }> {
|
|
67
80
|
const resume = options.resumeSessionId;
|
|
68
|
-
const params = threadParams(options, inheritConfig, mcpServers);
|
|
69
81
|
const opened = (await client
|
|
70
82
|
.request(
|
|
71
83
|
resume ? "thread/resume" : "thread/start",
|
|
@@ -89,28 +101,50 @@ async function openThread(
|
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
/**
|
|
92
|
-
* The Codex harness's sessions:
|
|
93
|
-
*
|
|
94
|
-
*
|
|
104
|
+
* The Codex harness's sessions: what is Codex's own of each logical
|
|
105
|
+
* session's process (its thread, its home, its account, its MCP table), on
|
|
106
|
+
* the process pool, which decides when one is reused, replaced or ended;
|
|
107
|
+
* what outlives a process (its thread settings, its home); and the managed
|
|
108
|
+
* sessions whose native cleanup was not confirmed.
|
|
95
109
|
*/
|
|
96
110
|
export class CodexSessions {
|
|
97
|
-
private readonly pool
|
|
111
|
+
private readonly pool: ProcessPool<CodexSession, CodexPoolTurn>;
|
|
98
112
|
private readonly threads = new Map<string, CodexThread>();
|
|
99
113
|
private readonly homes: CodexHomes;
|
|
100
114
|
/** Managed sessions whose process was not confirmed stopped: no successor runs until it is. */
|
|
101
115
|
private readonly unsettled = new Map<string, CodexConnection>();
|
|
102
|
-
/** Counts the login changes: a process keeps the login it read at its start. */
|
|
103
|
-
private login = 0;
|
|
104
|
-
/** Each session's process that was ended and has not exited yet: when it has. */
|
|
105
|
-
private readonly leaving = new Map<string, Promise<void>>();
|
|
106
116
|
|
|
107
117
|
constructor(
|
|
108
118
|
private readonly connect: CodexConnector,
|
|
109
|
-
|
|
110
|
-
/** The operator's: what a thread loads by itself,
|
|
111
|
-
private readonly
|
|
119
|
+
idleMs: number,
|
|
120
|
+
/** The operator's: what a thread loads by itself, whether every turn needs a home, and Codex's own tools. */
|
|
121
|
+
private readonly policy: CodexThreadPolicy = {},
|
|
112
122
|
) {
|
|
113
|
-
this.homes = new CodexHomes(inheritConfig);
|
|
123
|
+
this.homes = new CodexHomes(policy.inheritConfig);
|
|
124
|
+
this.pool = new ProcessPool<CodexSession, CodexPoolTurn>(
|
|
125
|
+
{
|
|
126
|
+
// An app-server reads its login from its home at its start.
|
|
127
|
+
store: ({ options }) => codexLoginStore(options.env),
|
|
128
|
+
// A process on its store's own login keeps the one it read at its
|
|
129
|
+
// start, and no word of a change outside the engine reaches it: its
|
|
130
|
+
// store's file changing replaces it. One the engine hands a login to
|
|
131
|
+
// (a credential, the user's own login, the turn's key) does not run
|
|
132
|
+
// on the file, and is logged in again at each turn.
|
|
133
|
+
loginMark: ({ options, scope }) => (scope.auth ? undefined : codexLoginMark(options.env)),
|
|
134
|
+
resumeOf: ({ options }) => options.resumeSessionId,
|
|
135
|
+
conversationsOf: (session) => [session.threadId],
|
|
136
|
+
fits: (session, { options, scope }) =>
|
|
137
|
+
codexSessionCompatible(session, options) &&
|
|
138
|
+
session.authFingerprint === authFingerprint(scope.auth) &&
|
|
139
|
+
// A home removed or made again under the process is not the one it
|
|
140
|
+
// runs in: a new process opens the thread there, or fails to, as a
|
|
141
|
+
// cold start would.
|
|
142
|
+
session.home === homeIdentity(options.env?.CODEX_HOME),
|
|
143
|
+
applyLiveChange: (session, turn, signal) => this.applyLiveChange(session, turn, signal),
|
|
144
|
+
spawn: (turn, own, signal) => this.spawn(turn, own, signal),
|
|
145
|
+
},
|
|
146
|
+
{ idleMs },
|
|
147
|
+
);
|
|
114
148
|
}
|
|
115
149
|
|
|
116
150
|
get(sessionId: string): CodexSession | undefined {
|
|
@@ -123,41 +157,34 @@ export class CodexSessions {
|
|
|
123
157
|
}
|
|
124
158
|
|
|
125
159
|
/**
|
|
126
|
-
* The session's process for the turn, which takes it
|
|
127
|
-
* the turn can run there as the same account, else a
|
|
128
|
-
* thread. Codex caches an authenticated model WebSocket across turns, so
|
|
160
|
+
* The session's process for the turn, which takes it (the pool's rule):
|
|
161
|
+
* the running one when the turn can run there as the same account, else a
|
|
162
|
+
* new one, on the same thread. Codex caches an authenticated model WebSocket across turns, so
|
|
129
163
|
* login alone cannot switch its identity: an account or key change
|
|
130
164
|
* restarts the process and resumes the thread. Same-account token renewal
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
165
|
+
* of a login the engine hands it keeps it warm. One on its store's own
|
|
166
|
+
* login is replaced once the store's `auth.json` changed, whatever the
|
|
167
|
+
* change: the engine reads no login to tell a renewal from another
|
|
168
|
+
* account. An unchanged `mcp_servers` table keeps it warm, the servers
|
|
169
|
+
* the thread carries. A thread's config is fixed once it is open, so
|
|
170
|
+
* another table resumes the thread in a new process, which checks them
|
|
171
|
+
* against Codex's configuration again before the thread opens: the user
|
|
172
|
+
* may change it while the old process exits. A home removed or made again
|
|
173
|
+
* under the process starts a new one too.
|
|
134
174
|
*/
|
|
135
|
-
|
|
175
|
+
acquire(
|
|
136
176
|
options: AgentExecuteOptions,
|
|
137
177
|
turn: CodexTurnScope,
|
|
138
178
|
mcp: CodexTurnMcp,
|
|
139
179
|
): Promise<CodexSession> {
|
|
140
|
-
turn.signal
|
|
141
|
-
const existing = this.pool.get(options.sessionId);
|
|
142
|
-
if (existing && !existing.client.closed) {
|
|
143
|
-
if (
|
|
144
|
-
codexSessionCompatible(existing, options) &&
|
|
145
|
-
existing.authFingerprint === authFingerprint(turn.auth) &&
|
|
146
|
-
!existing.stale &&
|
|
147
|
-
existing.login === this.login &&
|
|
148
|
-
existing.threadMcp === threadMcpFingerprint(mcp)
|
|
149
|
-
)
|
|
150
|
-
return this.reuse(existing, turn);
|
|
151
|
-
this.pool.close(options.sessionId);
|
|
152
|
-
}
|
|
153
|
-
return this.spawn(options, turn, mcp);
|
|
180
|
+
return this.pool.acquire(options.sessionId, { options, scope: turn, mcp }, turn.signal);
|
|
154
181
|
}
|
|
155
182
|
|
|
156
183
|
/** The turn is done with the session: an open process waits for the next one, at most `idleMs`. */
|
|
157
184
|
leave(sessionId: string, session: CodexSession, turn: CodexTurnScope): void {
|
|
158
185
|
if (session.turn !== turn) return;
|
|
159
186
|
session.turn = undefined;
|
|
160
|
-
|
|
187
|
+
this.pool.leave(sessionId, session);
|
|
161
188
|
}
|
|
162
189
|
|
|
163
190
|
/** Keep a managed session whose process could not be confirmed stopped from another turn. */
|
|
@@ -186,90 +213,105 @@ export class CodexSessions {
|
|
|
186
213
|
|
|
187
214
|
/**
|
|
188
215
|
* Unchanged MCP config reloads retain dead remote connections after VM
|
|
189
|
-
* resume:
|
|
190
|
-
*
|
|
191
|
-
*
|
|
216
|
+
* resume: each session's next turn replaces its process and resumes its
|
|
217
|
+
* thread (the strict thread/resume path). Nothing is ended now; a turn
|
|
218
|
+
* still setting up sends no `turn/start` on its process (`CodexTurn`).
|
|
192
219
|
*/
|
|
193
220
|
invalidate(): void {
|
|
194
|
-
|
|
195
|
-
[...this.pool.values()].filter((session) => session.turn).map((session) => session.client),
|
|
196
|
-
);
|
|
197
|
-
for (const session of this.pool.values()) session.stale = true;
|
|
198
|
-
for (const client of this.pool.clients()) if (!active.has(client)) client.close();
|
|
221
|
+
this.pool.invalidate();
|
|
199
222
|
}
|
|
200
223
|
|
|
201
|
-
// @ref LLP 0011#a-login-change-starts-the-next-turn-on-a-new-cli — a generation, never a close under a turn
|
|
202
224
|
/**
|
|
203
|
-
* The login changed
|
|
204
|
-
*
|
|
225
|
+
* The login changed in `store` (every store when none is named): an
|
|
226
|
+
* app-server keeps the one it read at its start, so each of that store's
|
|
227
|
+
* sessions starts its next turn on a new one, resuming its thread. A turn
|
|
205
228
|
* already setting up or running finishes on its own.
|
|
206
229
|
*/
|
|
207
|
-
loginChanged(): void {
|
|
208
|
-
this.
|
|
230
|
+
loginChanged(store?: string): void {
|
|
231
|
+
this.pool.loginChanged(store);
|
|
209
232
|
}
|
|
210
233
|
|
|
211
|
-
/**
|
|
212
|
-
|
|
213
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Forget the session: its process, its thread settings and its home.
|
|
236
|
+
* Settles once every app-server of the session has exited, one an idle
|
|
237
|
+
* eviction or a replacement ended earlier included (the pool's
|
|
238
|
+
* `release`): a product removes the session's home on this answer, and an
|
|
239
|
+
* exiting app-server still writes there.
|
|
240
|
+
*/
|
|
241
|
+
release(sessionId: string): Promise<void> {
|
|
242
|
+
const released = this.pool.release(sessionId);
|
|
214
243
|
this.threads.delete(sessionId);
|
|
215
244
|
this.homes.release(sessionId);
|
|
245
|
+
return released;
|
|
216
246
|
}
|
|
217
247
|
|
|
218
|
-
|
|
219
|
-
|
|
248
|
+
/** End every app-server, and settle once each has exited. */
|
|
249
|
+
terminateAll(): Promise<void> {
|
|
250
|
+
const closed = this.pool.closeAll();
|
|
220
251
|
this.threads.clear();
|
|
221
252
|
this.homes.clear();
|
|
253
|
+
return closed;
|
|
222
254
|
}
|
|
223
255
|
|
|
224
|
-
|
|
225
|
-
|
|
256
|
+
/**
|
|
257
|
+
* What changes on the warm process without a restart, for the turn: its
|
|
258
|
+
* account logged in again (a renewed token), and the `mcp_servers` table
|
|
259
|
+
* its thread needs checked against Codex's own configuration. Another
|
|
260
|
+
* table cannot be changed on an open thread, so the thread resumes in a
|
|
261
|
+
* new process. A cancel meanwhile ends the process, as Codex's answer is
|
|
262
|
+
* not waited for; a refused login ends it too, and a refused table read
|
|
263
|
+
* leaves it for the session's next turn.
|
|
264
|
+
*/
|
|
265
|
+
private async applyLiveChange(
|
|
266
|
+
session: CodexSession,
|
|
267
|
+
{ scope: turn, mcp }: CodexPoolTurn,
|
|
268
|
+
signal: AbortSignal,
|
|
269
|
+
): Promise<boolean> {
|
|
226
270
|
session.turn = turn;
|
|
227
|
-
const offAbort = onAbort(
|
|
271
|
+
const offAbort = onAbort(signal, () => session.client.close());
|
|
228
272
|
try {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
273
|
+
try {
|
|
274
|
+
await authenticate(session.client, turn);
|
|
275
|
+
} catch (error) {
|
|
276
|
+
session.turn = undefined;
|
|
277
|
+
session.client.close();
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
let servers: Record<string, unknown> | undefined;
|
|
281
|
+
try {
|
|
282
|
+
servers = await session.mcp.threadServers(mcp);
|
|
283
|
+
turn.signal.throwIfAborted();
|
|
284
|
+
} catch (error) {
|
|
285
|
+
session.turn = undefined;
|
|
286
|
+
throw error;
|
|
287
|
+
}
|
|
288
|
+
if (session.threadServers === threadServersFingerprint(servers)) return true;
|
|
232
289
|
session.turn = undefined;
|
|
233
|
-
|
|
234
|
-
throw error;
|
|
290
|
+
return false;
|
|
235
291
|
} finally {
|
|
236
292
|
offAbort();
|
|
237
293
|
}
|
|
238
294
|
}
|
|
239
295
|
|
|
296
|
+
/**
|
|
297
|
+
* Start an app-server for the turn and open the session's thread on it.
|
|
298
|
+
* The pool starts it once every app-server of the session before it has
|
|
299
|
+
* exited.
|
|
300
|
+
*/
|
|
240
301
|
private async spawn(
|
|
241
|
-
options:
|
|
242
|
-
|
|
243
|
-
|
|
302
|
+
{ options, scope: turn, mcp }: CodexPoolTurn,
|
|
303
|
+
own: (client: CodexConnection) => void,
|
|
304
|
+
signal: AbortSignal,
|
|
244
305
|
): Promise<CodexSession> {
|
|
245
|
-
const { signal } = turn;
|
|
246
|
-
const { sessionId } = options;
|
|
247
306
|
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — one writer to a thread
|
|
248
307
|
// Codex lets one process write a thread, and refuses a resume while the
|
|
249
|
-
// one before still exits:
|
|
250
|
-
// wait is the stop's grace at most, and a cancelled turn does not sit it out.
|
|
251
|
-
const leaving = this.leaving.get(sessionId);
|
|
252
|
-
if (leaving) {
|
|
253
|
-
let offCancel = () => {};
|
|
254
|
-
const cancelled = new Promise<void>((resolve) => {
|
|
255
|
-
offCancel = onAbort(signal, resolve);
|
|
256
|
-
});
|
|
257
|
-
await Promise.race([leaving, cancelled]);
|
|
258
|
-
offCancel();
|
|
259
|
-
signal.throwIfAborted();
|
|
260
|
-
}
|
|
308
|
+
// one before still exits: the pool waited for it.
|
|
261
309
|
const client = await this.connect(options, turn.auth, signal);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
this.leaving.set(sessionId, gone);
|
|
268
|
-
void gone.then(() => {
|
|
269
|
-
if (this.leaving.get(sessionId) === gone) this.leaving.delete(sessionId);
|
|
270
|
-
});
|
|
271
|
-
});
|
|
272
|
-
const untrack = this.pool.trackPending(options.sessionId, client);
|
|
310
|
+
own(client);
|
|
311
|
+
// Held while the process lives, so the folder's identity stays its own.
|
|
312
|
+
const release = holdHome(options.env?.CODEX_HOME);
|
|
313
|
+
client.onClose(release);
|
|
314
|
+
const home = homeIdentity(options.env?.CODEX_HOME);
|
|
273
315
|
const offAbort = onAbort(signal, () => client.close());
|
|
274
316
|
let thread = this.threads.get(options.sessionId);
|
|
275
317
|
if (!thread) {
|
|
@@ -281,9 +323,12 @@ export class CodexSessions {
|
|
|
281
323
|
client,
|
|
282
324
|
threadId: "",
|
|
283
325
|
authFingerprint: authFingerprint(turn.auth),
|
|
284
|
-
|
|
326
|
+
startedBeforeResume: () => this.pool.startedBeforeResume(session),
|
|
327
|
+
...(home && { home }),
|
|
285
328
|
mcp: new CodexMcpState(client, options.cwd),
|
|
286
|
-
|
|
329
|
+
threadServers: "",
|
|
330
|
+
// @ref LLP 0017#each-turn-names-its-environments — a resumed thread is back on its local one
|
|
331
|
+
...(this.policy.builtInTools?.local === false && { environments: [] }),
|
|
287
332
|
thread,
|
|
288
333
|
turn,
|
|
289
334
|
};
|
|
@@ -294,22 +339,24 @@ export class CodexSessions {
|
|
|
294
339
|
await client.initialize();
|
|
295
340
|
await authenticate(client, turn);
|
|
296
341
|
// Before the thread opens: a home is cleared of the turn before's
|
|
297
|
-
// servers
|
|
342
|
+
// servers; a set the thread carries is checked against Codex's own.
|
|
298
343
|
await session.mcp.configure(mcp);
|
|
299
|
-
const
|
|
344
|
+
const servers = await session.mcp.threadServers(mcp);
|
|
345
|
+
session.threadServers = threadServersFingerprint(servers);
|
|
346
|
+
const opened = await openThread(client, options, threadParams(options, this.policy, servers));
|
|
300
347
|
signal.throwIfAborted();
|
|
301
348
|
session.threadId = opened.threadId;
|
|
302
349
|
thread.adopt(opened, options);
|
|
303
|
-
this.pool.set(options.sessionId, session);
|
|
304
350
|
return session;
|
|
305
351
|
} catch (error) {
|
|
306
352
|
session.turn = undefined;
|
|
307
353
|
client.setRequestHandler(undefined);
|
|
308
354
|
client.close();
|
|
355
|
+
// A client closed before its hold was taken does not call it.
|
|
356
|
+
release();
|
|
309
357
|
throw error;
|
|
310
358
|
} finally {
|
|
311
359
|
offAbort();
|
|
312
|
-
untrack();
|
|
313
360
|
}
|
|
314
361
|
}
|
|
315
362
|
}
|
|
@@ -23,6 +23,12 @@ function parentOf(thread: NativeThread): string | undefined {
|
|
|
23
23
|
/** How many threads a managed turn may own before its cleanup gives up. */
|
|
24
24
|
const MAX_DESCENDANTS = 512;
|
|
25
25
|
|
|
26
|
+
/** How long Codex has to answer each request of a managed turn's cleanup. */
|
|
27
|
+
const CLEANUP_REQUEST_MS = 2_000;
|
|
28
|
+
|
|
29
|
+
/** How long a managed turn's whole cleanup may take before Codex's process is ended. */
|
|
30
|
+
const CLEANUP_MS = 5 * CLEANUP_REQUEST_MS;
|
|
31
|
+
|
|
26
32
|
/** Native ownership and cleanup for ONE execution; scheduling stays in Codex. */
|
|
27
33
|
export class CodexTurnSubagents {
|
|
28
34
|
private readonly parents = new Map<string, string>();
|
|
@@ -33,7 +39,6 @@ export class CodexTurnSubagents {
|
|
|
33
39
|
constructor(
|
|
34
40
|
private readonly client: CodexConnection,
|
|
35
41
|
private readonly root: string,
|
|
36
|
-
private readonly timeoutMs: number,
|
|
37
42
|
) {}
|
|
38
43
|
|
|
39
44
|
observe(notification: CodexNotification): void {
|
|
@@ -75,7 +80,7 @@ export class CodexTurnSubagents {
|
|
|
75
80
|
const result = (await this.client.request(
|
|
76
81
|
"thread/read",
|
|
77
82
|
{ threadId: id, includeTurns: true },
|
|
78
|
-
|
|
83
|
+
CLEANUP_REQUEST_MS,
|
|
79
84
|
)) as { thread?: NativeThread };
|
|
80
85
|
if (result.thread?.id !== id)
|
|
81
86
|
throw new Error("Codex did not confirm the requested child thread");
|
|
@@ -104,7 +109,7 @@ export class CodexTurnSubagents {
|
|
|
104
109
|
this.client,
|
|
105
110
|
"thread/loaded/list",
|
|
106
111
|
{ limit: 100 },
|
|
107
|
-
{ timeoutMs:
|
|
112
|
+
{ timeoutMs: CLEANUP_REQUEST_MS },
|
|
108
113
|
)) {
|
|
109
114
|
for (const id of page) this.candidates.add(id);
|
|
110
115
|
if (this.candidates.size > MAX_DESCENDANTS)
|
|
@@ -143,7 +148,7 @@ export class CodexTurnSubagents {
|
|
|
143
148
|
.request(
|
|
144
149
|
"turn/interrupt",
|
|
145
150
|
{ threadId: thread.id, turnId: active?.id ?? "" },
|
|
146
|
-
|
|
151
|
+
CLEANUP_REQUEST_MS,
|
|
147
152
|
)
|
|
148
153
|
.catch(async (error) => {
|
|
149
154
|
if ((await this.read(thread.id)).status?.type !== "idle") throw error;
|
|
@@ -153,15 +158,15 @@ export class CodexTurnSubagents {
|
|
|
153
158
|
throw new Error("Codex child interrupt was not confirmed");
|
|
154
159
|
}
|
|
155
160
|
if (thread.status.type === "notLoaded") continue;
|
|
156
|
-
if ((await listBackgroundTerminals(this.client, thread.id,
|
|
161
|
+
if ((await listBackgroundTerminals(this.client, thread.id, CLEANUP_REQUEST_MS)).length) {
|
|
157
162
|
unfinished = true;
|
|
158
163
|
stoppedWork = true;
|
|
159
164
|
await this.client.request(
|
|
160
165
|
"thread/backgroundTerminals/clean",
|
|
161
166
|
{ threadId: thread.id },
|
|
162
|
-
|
|
167
|
+
CLEANUP_REQUEST_MS,
|
|
163
168
|
);
|
|
164
|
-
if ((await listBackgroundTerminals(this.client, thread.id,
|
|
169
|
+
if ((await listBackgroundTerminals(this.client, thread.id, CLEANUP_REQUEST_MS)).length)
|
|
165
170
|
throw new Error("Codex child terminals did not stop");
|
|
166
171
|
}
|
|
167
172
|
}
|
|
@@ -196,7 +201,10 @@ export class ManagedStop implements TurnStop {
|
|
|
196
201
|
private readonly threadId: string,
|
|
197
202
|
private readonly commands: TurnCommands,
|
|
198
203
|
private readonly signal: AbortSignal,
|
|
199
|
-
/**
|
|
204
|
+
/**
|
|
205
|
+
* How long Codex has to answer the `turn/interrupt` that stops its turn
|
|
206
|
+
* before its process is ended (`cancelGraceMs`).
|
|
207
|
+
*/
|
|
200
208
|
private readonly graceMs: number,
|
|
201
209
|
/** Keep the session from another turn until its process is confirmed stopped. */
|
|
202
210
|
private readonly quarantine: () => void,
|
|
@@ -224,12 +232,11 @@ export class ManagedStop implements TurnStop {
|
|
|
224
232
|
|
|
225
233
|
private finish(native: NativeTurn | undefined): Promise<boolean> {
|
|
226
234
|
this.finishing ??= (async () => {
|
|
227
|
-
const graceMs = this.graceMs;
|
|
228
235
|
let confirmed = true;
|
|
229
236
|
let failure: unknown;
|
|
230
237
|
const deadline = setTimeout(() => {
|
|
231
|
-
void this.client.closeAndWait(
|
|
232
|
-
},
|
|
238
|
+
void this.client.closeAndWait();
|
|
239
|
+
}, CLEANUP_MS);
|
|
233
240
|
try {
|
|
234
241
|
// An error ended Codex's turn for the stream, not for Codex.
|
|
235
242
|
if (!native?.outcome || native.outcome === "error") {
|
|
@@ -238,14 +245,14 @@ export class ManagedStop implements TurnStop {
|
|
|
238
245
|
await this.client.request(
|
|
239
246
|
"turn/interrupt",
|
|
240
247
|
{ threadId: this.threadId, turnId: native.id },
|
|
241
|
-
graceMs,
|
|
248
|
+
this.graceMs,
|
|
242
249
|
);
|
|
243
250
|
}
|
|
244
251
|
const unfinished = await this.subagents.settle();
|
|
245
252
|
// Native terminal registration can land after turn/completed and
|
|
246
253
|
// after an empty terminal inventory. EOF awaits native thread/tool
|
|
247
254
|
// shutdown; an idle snapshot alone cannot release a managed turn.
|
|
248
|
-
confirmed = await this.client.closeAndWait(
|
|
255
|
+
confirmed = await this.client.closeAndWait();
|
|
249
256
|
if (!confirmed) throw new Error("Codex native cleanup was not confirmed");
|
|
250
257
|
if (unfinished && !this.signal.aborted) {
|
|
251
258
|
failure = new Error(
|
|
@@ -254,7 +261,7 @@ export class ManagedStop implements TurnStop {
|
|
|
254
261
|
}
|
|
255
262
|
} catch (error) {
|
|
256
263
|
failure = error;
|
|
257
|
-
confirmed = await this.client.closeAndWait(
|
|
264
|
+
confirmed = await this.client.closeAndWait();
|
|
258
265
|
if (!confirmed) this.quarantine();
|
|
259
266
|
} finally {
|
|
260
267
|
clearTimeout(deadline);
|
|
@@ -15,6 +15,9 @@ import {
|
|
|
15
15
|
import type { CodexThreadOpened } from "./protocol.ts";
|
|
16
16
|
import type { CodexSession } from "./session.ts";
|
|
17
17
|
|
|
18
|
+
/** How long Codex has to put a thread's settings back after a failed turn. */
|
|
19
|
+
const RESTORE_TIMEOUT_MS = 2_000;
|
|
20
|
+
|
|
18
21
|
/**
|
|
19
22
|
* A thread's settings, as the engine knows them: what Codex reported when the
|
|
20
23
|
* process took the thread, and what turns sent since. Codex keeps a turn's
|
|
@@ -42,7 +45,7 @@ export interface ThreadSettings {
|
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
/** What a turn sends Codex to run as its options ask, and what it leaves the thread on. */
|
|
45
|
-
|
|
48
|
+
interface TurnSettings {
|
|
46
49
|
/** The `turn/start` params that carry them. */
|
|
47
50
|
params: Record<string, unknown>;
|
|
48
51
|
/** The thinking level and reported model the turn runs, as far as the engine knows. */
|
|
@@ -168,11 +171,17 @@ export class CodexThread {
|
|
|
168
171
|
if (switched) params.model = model;
|
|
169
172
|
next = { ...next, ...(switched && { model, reportedModel: undefined }), modelSet: false };
|
|
170
173
|
}
|
|
174
|
+
// A model known to have no reasoning control is sent no effort, and the
|
|
175
|
+
// turn reports no level: the thread's effort does not apply to it.
|
|
176
|
+
let noThinking = false;
|
|
171
177
|
if (options.thinkingLevel) {
|
|
172
178
|
const accepts = await modelThinking(session, next.model, known);
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
if (accepts && !accepts.levels.length) noThinking = true;
|
|
180
|
+
else {
|
|
181
|
+
const effort = codexReasoningEffort(options.thinkingLevel, accepts?.levels, accepts?.off);
|
|
182
|
+
params.effort = effort;
|
|
183
|
+
next = { ...next, effort, effortSet: true };
|
|
184
|
+
}
|
|
176
185
|
} else {
|
|
177
186
|
// Once a turn set the thread's effort, the default is worked out for
|
|
178
187
|
// this turn's model. Otherwise, and when Codex cannot say what the
|
|
@@ -190,14 +199,16 @@ export class CodexThread {
|
|
|
190
199
|
}
|
|
191
200
|
// Codex runs the effort it is given, and overrides persist on the
|
|
192
201
|
// thread, so the thread's effort is the one this turn runs.
|
|
193
|
-
const level = codexThinkingLevel(next.effort);
|
|
202
|
+
const level = noThinking ? undefined : codexThinkingLevel(next.effort);
|
|
194
203
|
const collaboration = inCollaborationMode(next, mode);
|
|
195
204
|
return {
|
|
196
205
|
params: { ...params, ...collaboration.params },
|
|
197
|
-
...((level || next.reportedModel) && {
|
|
206
|
+
...((level || next.reportedModel || noThinking) && {
|
|
198
207
|
applied: {
|
|
199
208
|
...(level && { thinkingLevel: level }),
|
|
200
209
|
...(next.reportedModel && { model: next.reportedModel }),
|
|
210
|
+
// The turn's level was not sent: its model has no reasoning control.
|
|
211
|
+
...(noThinking && { notApplied: ["thinkingLevel" as const] }),
|
|
201
212
|
},
|
|
202
213
|
}),
|
|
203
214
|
next: collaboration.next,
|
|
@@ -215,7 +226,6 @@ export class CodexThread {
|
|
|
215
226
|
session: CodexSession,
|
|
216
227
|
previous: ThreadSettings,
|
|
217
228
|
sent: Record<string, unknown>,
|
|
218
|
-
timeoutMs: number,
|
|
219
229
|
): Promise<void> {
|
|
220
230
|
const params: Record<string, unknown> = { threadId: session.threadId };
|
|
221
231
|
if (sent.model !== undefined && previous.model && sent.model !== previous.model)
|
|
@@ -225,7 +235,7 @@ export class CodexThread {
|
|
|
225
235
|
params.effort = previous.effort;
|
|
226
236
|
if (params.model === undefined && params.effort === undefined) return;
|
|
227
237
|
try {
|
|
228
|
-
await session.client.request("thread/settings/update", params,
|
|
238
|
+
await session.client.request("thread/settings/update", params, RESTORE_TIMEOUT_MS);
|
|
229
239
|
} catch {
|
|
230
240
|
return;
|
|
231
241
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type CodexFileChange, type CodexNotification, codexItem } from "./protocol.ts";
|
|
2
2
|
|
|
3
3
|
/** An MCP tool call Codex started and may ask consent for. */
|
|
4
|
-
|
|
4
|
+
interface CodexMcpCall {
|
|
5
5
|
id: string;
|
|
6
6
|
threadId?: string;
|
|
7
7
|
server: string;
|