@zvada/agent-server 0.3.21 → 0.3.23
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 +332 -0
- package/README.md +2 -1
- 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 +66 -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 +4 -3
- 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 +16 -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 +10 -4
- 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 +50 -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 +21 -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 +61 -14
- 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 +26 -5
- 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 +4 -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 +45 -20
- 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 +32 -5
- 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 +70 -33
- 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 +37 -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/plan.d.ts +2 -13
- package/dist/types/core/agents/plan.d.ts.map +1 -1
- package/dist/types/core/agents/process-pool.d.ts +193 -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 +6 -1
- 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 +18 -9
- 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 +14 -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 +15 -1
- package/dist/types/core/utils/errors.d.ts.map +1 -1
- package/dist/types/operator/index.d.ts +11 -0
- package/dist/types/operator/index.d.ts.map +1 -0
- package/dist/types/operator/mcp.d.ts +33 -0
- package/dist/types/operator/mcp.d.ts.map +1 -0
- package/dist/types/operator/operator.d.ts +206 -0
- package/dist/types/operator/operator.d.ts.map +1 -0
- package/dist/types/operator/render.d.ts +89 -0
- package/dist/types/operator/render.d.ts.map +1 -0
- package/dist/types/operator/view.d.ts +44 -0
- package/dist/types/operator/view.d.ts.map +1 -0
- 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/plan.d.ts +20 -0
- package/dist/types/protocol/plan.d.ts.map +1 -0
- 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/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.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/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/dist/types/sync/worker.d.ts.map +1 -1
- package/docs/consuming.md +464 -40
- package/docs/deploy.md +36 -8
- package/docs/durable-sessions.md +35 -5
- package/docs/harnesses.md +396 -30
- package/package.json +11 -1
- 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 +113 -22
- package/src/client/index.ts +1 -0
- package/src/client/logins.ts +24 -15
- 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 +6 -5
- package/src/core/agents/claude-code/claude-agent.ts +60 -30
- 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 +11 -3
- 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 +166 -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 +69 -10
- package/src/core/agents/codex-app-server/codex-agent.ts +141 -55
- 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 +59 -10
- package/src/core/agents/codex-app-server/items.ts +219 -31
- package/src/core/agents/codex-app-server/login.ts +14 -2
- package/src/core/agents/codex-app-server/mcp.ts +142 -26
- package/src/core/agents/codex-app-server/models.ts +9 -8
- package/src/core/agents/codex-app-server/options.ts +79 -11
- 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 +14 -6
- package/src/core/agents/codex-app-server/session.ts +156 -81
- 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 +96 -35
- 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/plan.ts +3 -19
- package/src/core/agents/process-pool.ts +432 -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 +12 -0
- package/src/core/presets.ts +99 -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 +70 -34
- 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 +53 -3
- package/src/core/utils/deadline.ts +23 -0
- package/src/core/utils/errors.ts +24 -4
- package/src/operator/index.ts +40 -0
- package/src/operator/mcp.ts +171 -0
- package/src/operator/operator.ts +782 -0
- package/src/operator/render.ts +473 -0
- package/src/operator/view.ts +82 -0
- 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/plan.ts +35 -0
- package/src/protocol/tool-state.ts +14 -1
- package/src/protocol/wire.ts +14 -0
- package/src/server/acp/binding.ts +113 -22
- package/src/server/acp/translate.ts +161 -8
- package/src/server/agent-server.ts +10 -1
- package/src/server/bin.ts +83 -9
- 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 +14 -0
- 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/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/src/sync/worker.ts +4 -0
- 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 { 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,
|
|
@@ -25,24 +27,42 @@ export interface CodexSession extends CodexProcessIdentity {
|
|
|
25
27
|
/** Native model connections retain the identity used at their first handshake. */
|
|
26
28
|
authFingerprint?: string;
|
|
27
29
|
mcp: CodexMcpState;
|
|
30
|
+
/**
|
|
31
|
+
* The `mcp_servers` table its thread was opened with
|
|
32
|
+
* (`threadServersFingerprint`): a turn that needs another runs in another
|
|
33
|
+
* process.
|
|
34
|
+
*/
|
|
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?: [];
|
|
28
41
|
/** The logical session's thread settings, which outlive this process. */
|
|
29
42
|
thread: CodexThread;
|
|
30
43
|
/** The turn that has the session: Codex's requests answer for it alone. */
|
|
31
44
|
turn?: CodexTurnScope;
|
|
32
45
|
/**
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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`).
|
|
35
49
|
*/
|
|
36
|
-
|
|
37
|
-
/** The
|
|
38
|
-
|
|
50
|
+
startedBeforeResume(): boolean;
|
|
51
|
+
/** The folder its `CODEX_HOME` was when it started (`homeIdentity`): another one's turn replaces it. */
|
|
52
|
+
home?: string;
|
|
39
53
|
/** What each model accepts, from this process's `model/list`; read once. */
|
|
40
54
|
modelThinking?: Promise<ReadonlyMap<string, CodexModelThinking> | undefined>;
|
|
41
|
-
|
|
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;
|
|
42
62
|
}
|
|
43
63
|
|
|
44
64
|
/** Starts a connection to a new `codex app-server` for a turn's folder, `env` and login. */
|
|
45
|
-
|
|
65
|
+
type CodexConnector = (
|
|
46
66
|
options: AgentExecuteOptions,
|
|
47
67
|
auth: CodexAuth | undefined,
|
|
48
68
|
signal: AbortSignal,
|
|
@@ -55,10 +75,9 @@ export type CodexConnector = (
|
|
|
55
75
|
async function openThread(
|
|
56
76
|
client: CodexConnection,
|
|
57
77
|
options: AgentExecuteOptions,
|
|
58
|
-
|
|
78
|
+
params: CodexThreadParams,
|
|
59
79
|
): Promise<CodexThreadOpened & { threadId: string }> {
|
|
60
80
|
const resume = options.resumeSessionId;
|
|
61
|
-
const params = threadParams(options, inheritConfig);
|
|
62
81
|
const opened = (await client
|
|
63
82
|
.request(
|
|
64
83
|
resume ? "thread/resume" : "thread/start",
|
|
@@ -82,26 +101,44 @@ async function openThread(
|
|
|
82
101
|
}
|
|
83
102
|
|
|
84
103
|
/**
|
|
85
|
-
* The Codex harness's sessions:
|
|
86
|
-
*
|
|
87
|
-
*
|
|
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.
|
|
88
109
|
*/
|
|
89
110
|
export class CodexSessions {
|
|
90
|
-
private readonly pool
|
|
111
|
+
private readonly pool: ProcessPool<CodexSession, CodexPoolTurn>;
|
|
91
112
|
private readonly threads = new Map<string, CodexThread>();
|
|
92
113
|
private readonly homes: CodexHomes;
|
|
93
114
|
/** Managed sessions whose process was not confirmed stopped: no successor runs until it is. */
|
|
94
115
|
private readonly unsettled = new Map<string, CodexConnection>();
|
|
95
|
-
/** Counts the login changes: a process keeps the login it read at its start. */
|
|
96
|
-
private login = 0;
|
|
97
116
|
|
|
98
117
|
constructor(
|
|
99
118
|
private readonly connect: CodexConnector,
|
|
100
|
-
|
|
101
|
-
/** The operator's: what a thread loads by itself,
|
|
102
|
-
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 = {},
|
|
103
122
|
) {
|
|
104
|
-
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
|
+
resumeOf: ({ options }) => options.resumeSessionId,
|
|
129
|
+
conversationsOf: (session) => [session.threadId],
|
|
130
|
+
fits: (session, { options, scope }) =>
|
|
131
|
+
codexSessionCompatible(session, options) &&
|
|
132
|
+
session.authFingerprint === authFingerprint(scope.auth) &&
|
|
133
|
+
// A home removed or made again under the process is not the one it
|
|
134
|
+
// runs in: a new process opens the thread there, or fails to, as a
|
|
135
|
+
// cold start would.
|
|
136
|
+
session.home === homeIdentity(options.env?.CODEX_HOME),
|
|
137
|
+
applyLiveChange: (session, turn, signal) => this.applyLiveChange(session, turn, signal),
|
|
138
|
+
spawn: (turn, own, signal) => this.spawn(turn, own, signal),
|
|
139
|
+
},
|
|
140
|
+
{ idleMs },
|
|
141
|
+
);
|
|
105
142
|
}
|
|
106
143
|
|
|
107
144
|
get(sessionId: string): CodexSession | undefined {
|
|
@@ -114,38 +151,31 @@ export class CodexSessions {
|
|
|
114
151
|
}
|
|
115
152
|
|
|
116
153
|
/**
|
|
117
|
-
* The session's process for the turn, which takes it
|
|
118
|
-
* the turn can run there as the same account, else a
|
|
119
|
-
* thread. Codex caches an authenticated model WebSocket across turns, so
|
|
154
|
+
* The session's process for the turn, which takes it (the pool's rule):
|
|
155
|
+
* the running one when the turn can run there as the same account, else a
|
|
156
|
+
* new one, on the same thread. Codex caches an authenticated model WebSocket across turns, so
|
|
120
157
|
* login alone cannot switch its identity: an account or key change
|
|
121
158
|
* restarts the process and resumes the thread. Same-account token renewal
|
|
122
|
-
* keeps it warm.
|
|
159
|
+
* keeps it warm. So does an unchanged `mcp_servers` table, the servers
|
|
160
|
+
* the thread carries. A thread's config is fixed once it is open, so
|
|
161
|
+
* another table resumes the thread in a new process, which checks them
|
|
162
|
+
* against Codex's configuration again before the thread opens: the user
|
|
163
|
+
* may change it while the old process exits. A home removed or made again
|
|
164
|
+
* under the process starts a new one too.
|
|
123
165
|
*/
|
|
124
|
-
|
|
166
|
+
acquire(
|
|
125
167
|
options: AgentExecuteOptions,
|
|
126
168
|
turn: CodexTurnScope,
|
|
127
169
|
mcp: CodexTurnMcp,
|
|
128
170
|
): Promise<CodexSession> {
|
|
129
|
-
turn.signal
|
|
130
|
-
const existing = this.pool.get(options.sessionId);
|
|
131
|
-
if (existing && !existing.client.closed) {
|
|
132
|
-
if (
|
|
133
|
-
codexSessionCompatible(existing, options) &&
|
|
134
|
-
existing.authFingerprint === authFingerprint(turn.auth) &&
|
|
135
|
-
!existing.stale &&
|
|
136
|
-
existing.login === this.login
|
|
137
|
-
)
|
|
138
|
-
return this.reuse(existing, turn);
|
|
139
|
-
this.pool.close(options.sessionId);
|
|
140
|
-
}
|
|
141
|
-
return this.spawn(options, turn, mcp);
|
|
171
|
+
return this.pool.acquire(options.sessionId, { options, scope: turn, mcp }, turn.signal);
|
|
142
172
|
}
|
|
143
173
|
|
|
144
174
|
/** The turn is done with the session: an open process waits for the next one, at most `idleMs`. */
|
|
145
175
|
leave(sessionId: string, session: CodexSession, turn: CodexTurnScope): void {
|
|
146
176
|
if (session.turn !== turn) return;
|
|
147
177
|
session.turn = undefined;
|
|
148
|
-
|
|
178
|
+
this.pool.leave(sessionId, session);
|
|
149
179
|
}
|
|
150
180
|
|
|
151
181
|
/** Keep a managed session whose process could not be confirmed stopped from another turn. */
|
|
@@ -174,67 +204,105 @@ export class CodexSessions {
|
|
|
174
204
|
|
|
175
205
|
/**
|
|
176
206
|
* Unchanged MCP config reloads retain dead remote connections after VM
|
|
177
|
-
* resume:
|
|
178
|
-
*
|
|
179
|
-
*
|
|
207
|
+
* resume: each session's next turn replaces its process and resumes its
|
|
208
|
+
* thread (the strict thread/resume path). Nothing is ended now; a turn
|
|
209
|
+
* still setting up sends no `turn/start` on its process (`CodexTurn`).
|
|
180
210
|
*/
|
|
181
211
|
invalidate(): void {
|
|
182
|
-
|
|
183
|
-
[...this.pool.values()].filter((session) => session.turn).map((session) => session.client),
|
|
184
|
-
);
|
|
185
|
-
for (const session of this.pool.values()) session.stale = true;
|
|
186
|
-
for (const client of this.pool.clients()) if (!active.has(client)) client.close();
|
|
212
|
+
this.pool.invalidate();
|
|
187
213
|
}
|
|
188
214
|
|
|
189
|
-
// @ref LLP 0011#a-login-change-starts-the-next-turn-on-a-new-cli — a generation, never a close under a turn
|
|
190
215
|
/**
|
|
191
|
-
* The login changed
|
|
192
|
-
*
|
|
216
|
+
* The login changed in `store` (every store when none is named): an
|
|
217
|
+
* app-server keeps the one it read at its start, so each of that store's
|
|
218
|
+
* sessions starts its next turn on a new one, resuming its thread. A turn
|
|
193
219
|
* already setting up or running finishes on its own.
|
|
194
220
|
*/
|
|
195
|
-
loginChanged(): void {
|
|
196
|
-
this.
|
|
221
|
+
loginChanged(store?: string): void {
|
|
222
|
+
this.pool.loginChanged(store);
|
|
197
223
|
}
|
|
198
224
|
|
|
199
|
-
/**
|
|
200
|
-
|
|
201
|
-
|
|
225
|
+
/**
|
|
226
|
+
* Forget the session: its process, its thread settings and its home.
|
|
227
|
+
* Settles once every app-server of the session has exited, one an idle
|
|
228
|
+
* eviction or a replacement ended earlier included (the pool's
|
|
229
|
+
* `release`): a product removes the session's home on this answer, and an
|
|
230
|
+
* exiting app-server still writes there.
|
|
231
|
+
*/
|
|
232
|
+
release(sessionId: string): Promise<void> {
|
|
233
|
+
const released = this.pool.release(sessionId);
|
|
202
234
|
this.threads.delete(sessionId);
|
|
203
235
|
this.homes.release(sessionId);
|
|
236
|
+
return released;
|
|
204
237
|
}
|
|
205
238
|
|
|
206
|
-
|
|
207
|
-
|
|
239
|
+
/** End every app-server, and settle once each has exited. */
|
|
240
|
+
terminateAll(): Promise<void> {
|
|
241
|
+
const closed = this.pool.closeAll();
|
|
208
242
|
this.threads.clear();
|
|
209
243
|
this.homes.clear();
|
|
244
|
+
return closed;
|
|
210
245
|
}
|
|
211
246
|
|
|
212
|
-
|
|
213
|
-
|
|
247
|
+
/**
|
|
248
|
+
* What changes on the warm process without a restart, for the turn: its
|
|
249
|
+
* account logged in again (a renewed token), and the `mcp_servers` table
|
|
250
|
+
* its thread needs checked against Codex's own configuration. Another
|
|
251
|
+
* table cannot be changed on an open thread, so the thread resumes in a
|
|
252
|
+
* new process. A cancel meanwhile ends the process, as Codex's answer is
|
|
253
|
+
* not waited for; a refused login ends it too, and a refused table read
|
|
254
|
+
* leaves it for the session's next turn.
|
|
255
|
+
*/
|
|
256
|
+
private async applyLiveChange(
|
|
257
|
+
session: CodexSession,
|
|
258
|
+
{ scope: turn, mcp }: CodexPoolTurn,
|
|
259
|
+
signal: AbortSignal,
|
|
260
|
+
): Promise<boolean> {
|
|
214
261
|
session.turn = turn;
|
|
215
|
-
const offAbort = onAbort(
|
|
262
|
+
const offAbort = onAbort(signal, () => session.client.close());
|
|
216
263
|
try {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
264
|
+
try {
|
|
265
|
+
await authenticate(session.client, turn);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
session.turn = undefined;
|
|
268
|
+
session.client.close();
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
let servers: Record<string, unknown> | undefined;
|
|
272
|
+
try {
|
|
273
|
+
servers = await session.mcp.threadServers(mcp);
|
|
274
|
+
turn.signal.throwIfAborted();
|
|
275
|
+
} catch (error) {
|
|
276
|
+
session.turn = undefined;
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
if (session.threadServers === threadServersFingerprint(servers)) return true;
|
|
220
280
|
session.turn = undefined;
|
|
221
|
-
|
|
222
|
-
throw error;
|
|
281
|
+
return false;
|
|
223
282
|
} finally {
|
|
224
283
|
offAbort();
|
|
225
284
|
}
|
|
226
285
|
}
|
|
227
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Start an app-server for the turn and open the session's thread on it.
|
|
289
|
+
* The pool starts it once every app-server of the session before it has
|
|
290
|
+
* exited.
|
|
291
|
+
*/
|
|
228
292
|
private async spawn(
|
|
229
|
-
options:
|
|
230
|
-
|
|
231
|
-
|
|
293
|
+
{ options, scope: turn, mcp }: CodexPoolTurn,
|
|
294
|
+
own: (client: CodexConnection) => void,
|
|
295
|
+
signal: AbortSignal,
|
|
232
296
|
): Promise<CodexSession> {
|
|
233
|
-
|
|
297
|
+
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — one writer to a thread
|
|
298
|
+
// Codex lets one process write a thread, and refuses a resume while the
|
|
299
|
+
// one before still exits: the pool waited for it.
|
|
234
300
|
const client = await this.connect(options, turn.auth, signal);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const
|
|
301
|
+
own(client);
|
|
302
|
+
// Held while the process lives, so the folder's identity stays its own.
|
|
303
|
+
const release = holdHome(options.env?.CODEX_HOME);
|
|
304
|
+
client.onClose(release);
|
|
305
|
+
const home = homeIdentity(options.env?.CODEX_HOME);
|
|
238
306
|
const offAbort = onAbort(signal, () => client.close());
|
|
239
307
|
let thread = this.threads.get(options.sessionId);
|
|
240
308
|
if (!thread) {
|
|
@@ -246,8 +314,12 @@ export class CodexSessions {
|
|
|
246
314
|
client,
|
|
247
315
|
threadId: "",
|
|
248
316
|
authFingerprint: authFingerprint(turn.auth),
|
|
249
|
-
|
|
317
|
+
startedBeforeResume: () => this.pool.startedBeforeResume(session),
|
|
318
|
+
...(home && { home }),
|
|
250
319
|
mcp: new CodexMcpState(client, options.cwd),
|
|
320
|
+
threadServers: "",
|
|
321
|
+
// @ref LLP 0017#each-turn-names-its-environments — a resumed thread is back on its local one
|
|
322
|
+
...(this.policy.builtInTools?.local === false && { environments: [] }),
|
|
251
323
|
thread,
|
|
252
324
|
turn,
|
|
253
325
|
};
|
|
@@ -257,22 +329,25 @@ export class CodexSessions {
|
|
|
257
329
|
signal.throwIfAborted();
|
|
258
330
|
await client.initialize();
|
|
259
331
|
await authenticate(client, turn);
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
|
|
332
|
+
// Before the thread opens: a home is cleared of the turn before's
|
|
333
|
+
// servers; a set the thread carries is checked against Codex's own.
|
|
334
|
+
await session.mcp.configure(mcp);
|
|
335
|
+
const servers = await session.mcp.threadServers(mcp);
|
|
336
|
+
session.threadServers = threadServersFingerprint(servers);
|
|
337
|
+
const opened = await openThread(client, options, threadParams(options, this.policy, servers));
|
|
263
338
|
signal.throwIfAborted();
|
|
264
339
|
session.threadId = opened.threadId;
|
|
265
340
|
thread.adopt(opened, options);
|
|
266
|
-
this.pool.set(options.sessionId, session);
|
|
267
341
|
return session;
|
|
268
342
|
} catch (error) {
|
|
269
343
|
session.turn = undefined;
|
|
270
344
|
client.setRequestHandler(undefined);
|
|
271
345
|
client.close();
|
|
346
|
+
// A client closed before its hold was taken does not call it.
|
|
347
|
+
release();
|
|
272
348
|
throw error;
|
|
273
349
|
} finally {
|
|
274
350
|
offAbort();
|
|
275
|
-
untrack();
|
|
276
351
|
}
|
|
277
352
|
}
|
|
278
353
|
}
|
|
@@ -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;
|