@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,4 +1,6 @@
|
|
|
1
1
|
import { AsyncQueue, type ErrorInfo, type McpServerConfig } from "../../../protocol/index.ts";
|
|
2
|
+
import { InvalidRequestError } from "../../utils/errors.ts";
|
|
3
|
+
import { isRecord } from "../../utils/is-record.ts";
|
|
2
4
|
import type { AgentExecuteOptions } from "../base.ts";
|
|
3
5
|
import { configFingerprint } from "../config-fingerprint.ts";
|
|
4
6
|
import {
|
|
@@ -12,7 +14,7 @@ import type { CodexHomes } from "./homes.ts";
|
|
|
12
14
|
import type { CodexNotification } from "./protocol.ts";
|
|
13
15
|
|
|
14
16
|
/** Codex supports stdio and Streamable HTTP, not the legacy SSE transport. */
|
|
15
|
-
|
|
17
|
+
function codexMcpServers(servers: Record<string, McpServerConfig>): Record<string, unknown> {
|
|
16
18
|
return Object.fromEntries(
|
|
17
19
|
Object.entries(servers).map(([name, server]) => {
|
|
18
20
|
if (name === "codex_apps") throw new Error("MCP server name codex_apps is reserved by Codex");
|
|
@@ -34,7 +36,7 @@ export function codexMcpServers(servers: Record<string, McpServerConfig>): Recor
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/** Only call against an explicitly isolated, engine-managed CODEX_HOME. */
|
|
37
|
-
|
|
39
|
+
async function writeCodexMcpServers(
|
|
38
40
|
client: Pick<CodexConnection, "request">,
|
|
39
41
|
servers: Record<string, unknown>,
|
|
40
42
|
): Promise<void> {
|
|
@@ -67,7 +69,7 @@ function normalizedConfig(value: unknown): unknown {
|
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
/** User-layer write acknowledgements do not account for repository overrides. */
|
|
70
|
-
|
|
72
|
+
async function assertCodexMcpConfig(
|
|
71
73
|
client: Pick<CodexConnection, "request">,
|
|
72
74
|
cwd: string,
|
|
73
75
|
servers: Record<string, unknown>,
|
|
@@ -86,6 +88,45 @@ export async function assertCodexMcpConfig(
|
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
/** A higher layer of Codex's configuration over a lower: tables key by key, anything else replaced. */
|
|
92
|
+
function mergedOver(base: unknown, over: unknown): unknown {
|
|
93
|
+
if (!isRecord(base) || !isRecord(over)) return over;
|
|
94
|
+
const merged: Record<string, unknown> = { ...base };
|
|
95
|
+
for (const [key, value] of Object.entries(over)) merged[key] = mergedOver(base[key], value);
|
|
96
|
+
return merged;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — a name Codex's own configuration has
|
|
100
|
+
/**
|
|
101
|
+
* Refuse a turn's server that Codex's own configuration (`native`) would
|
|
102
|
+
* change. A server in a thread's config is the top layer of Codex's, merged
|
|
103
|
+
* table by table over one of the same name in the user's or the
|
|
104
|
+
* repository's: the turn's values win, and whatever else the other sets
|
|
105
|
+
* stays (its headers and environment sent to the turn's server, its tool
|
|
106
|
+
* filter, `enabled = false`). One that sets nothing more is the turn's
|
|
107
|
+
* server whole, and goes on.
|
|
108
|
+
*/
|
|
109
|
+
function assertCodexThreadMcp(
|
|
110
|
+
native: Record<string, unknown>,
|
|
111
|
+
servers: Record<string, unknown>,
|
|
112
|
+
): void {
|
|
113
|
+
const changed = Object.entries(servers).flatMap(([name, server]) =>
|
|
114
|
+
native[name] !== undefined &&
|
|
115
|
+
configFingerprint(normalizedConfig(mergedOver(native[name], server))) !==
|
|
116
|
+
configFingerprint(normalizedConfig(server))
|
|
117
|
+
? [name]
|
|
118
|
+
: [],
|
|
119
|
+
);
|
|
120
|
+
if (changed.length)
|
|
121
|
+
throw new InvalidRequestError(
|
|
122
|
+
changed.map((name) => ({
|
|
123
|
+
path: `mcpServers.${name}`,
|
|
124
|
+
message:
|
|
125
|
+
"Codex's own configuration (the user's or the repository's) has a server of this name, whose settings would apply to the turn's; rename one of them",
|
|
126
|
+
})),
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
89
130
|
/**
|
|
90
131
|
* Codex's startup error for a server, readable: its Rust type paths out, a
|
|
91
132
|
* chain it repeats said once, and no prefix naming the server again.
|
|
@@ -111,7 +152,7 @@ const MCP_STARTUP_MS = 30_000;
|
|
|
111
152
|
* without. `servers` is the turn's wire configuration, by name, and `causes`
|
|
112
153
|
* why each server last failed, as Codex said.
|
|
113
154
|
*/
|
|
114
|
-
|
|
155
|
+
async function settleCodexMcp(
|
|
115
156
|
client: CodexConnection,
|
|
116
157
|
threadId: string,
|
|
117
158
|
servers: Readonly<Record<string, McpServerConfig>>,
|
|
@@ -147,7 +188,7 @@ export async function settleCodexMcp(
|
|
|
147
188
|
const statuses: Array<{ name: string; status: string | null; error?: string }> = [];
|
|
148
189
|
// Asked by name, Codex answers from the thread's own connection.
|
|
149
190
|
// Asked for every server, it connects to each again (initialize,
|
|
150
|
-
// tools/list) on every turn (0.160,
|
|
191
|
+
// tools/list) on every turn (observed on Codex 0.160, 2026-10-28).
|
|
151
192
|
for (const serverName of names) {
|
|
152
193
|
for await (const page of pages<{ name: string; runtimeStatus: string | null }>(
|
|
153
194
|
client,
|
|
@@ -193,28 +234,49 @@ export async function settleCodexMcp(
|
|
|
193
234
|
}
|
|
194
235
|
}
|
|
195
236
|
|
|
196
|
-
/**
|
|
237
|
+
/**
|
|
238
|
+
* A turn's MCP servers: as the wire gave them, and as Codex takes them, by
|
|
239
|
+
* where they go. A turn that names a home has them written there
|
|
240
|
+
* (`servers`); one that names none has them in its thread's own config
|
|
241
|
+
* (`thread`), which is fixed when the thread is opened.
|
|
242
|
+
*/
|
|
197
243
|
export interface CodexTurnMcp {
|
|
198
244
|
wire: Record<string, McpServerConfig>;
|
|
199
|
-
/**
|
|
245
|
+
/** For the home the turn names, `{}` when it has none: that home's servers are the turn's. */
|
|
200
246
|
servers?: Record<string, unknown>;
|
|
247
|
+
/** For the thread's own config: a turn with servers that names no home, which the engine never writes. */
|
|
248
|
+
thread?: Record<string, unknown>;
|
|
201
249
|
}
|
|
202
250
|
|
|
203
251
|
/** The turn's servers, snapshotted before anything asynchronous can let the caller change them. */
|
|
204
252
|
export function codexTurnMcp(options: AgentExecuteOptions, homes: CodexHomes): CodexTurnMcp {
|
|
205
253
|
const wire = snapshotMcpServers(options.mcpServers);
|
|
206
254
|
const servers = codexMcpServers(wire);
|
|
207
|
-
|
|
255
|
+
if (homes.claim(options)) return { wire, servers };
|
|
256
|
+
return Object.keys(servers).length ? { wire, thread: servers } : { wire };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — a thread's config is fixed once it is open
|
|
260
|
+
/**
|
|
261
|
+
* Which `mcp_servers` table a thread was opened with (`threadServers`): a
|
|
262
|
+
* turn that needs another runs on the thread opened again in a new process.
|
|
263
|
+
*/
|
|
264
|
+
export function threadServersFingerprint(table: Record<string, unknown> | undefined): string {
|
|
265
|
+
return configFingerprint(table ?? {});
|
|
208
266
|
}
|
|
209
267
|
|
|
210
268
|
/**
|
|
211
|
-
* A session's MCP servers on Codex: the configuration last
|
|
212
|
-
* home, why each server last failed to start, and the ones
|
|
213
|
-
* without.
|
|
269
|
+
* A session's MCP servers on Codex, for one process: the configuration last
|
|
270
|
+
* written to its home, why each server last failed to start, and the ones
|
|
271
|
+
* its turns went without.
|
|
214
272
|
*/
|
|
215
273
|
export class CodexMcpState {
|
|
216
274
|
/** Last native config write; readiness is checked separately before every prompt. */
|
|
217
275
|
private fingerprint?: string;
|
|
276
|
+
/** A turn was prepared on this process: the servers its thread carries started when it opened. */
|
|
277
|
+
private prepared = false;
|
|
278
|
+
/** The last turn's servers did not settle: the next one starts them again. */
|
|
279
|
+
private unsettled = false;
|
|
218
280
|
/**
|
|
219
281
|
* Why each MCP server last failed to start, as Codex said, from the
|
|
220
282
|
* client's first notification: a fast failure can come before a turn asks.
|
|
@@ -239,8 +301,12 @@ export class CodexMcpState {
|
|
|
239
301
|
else if (params.status === "ready" || params.status === "starting") this.causes.delete(name);
|
|
240
302
|
}
|
|
241
303
|
|
|
242
|
-
/**
|
|
243
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Before the thread opens, and before each turn: servers for the home the
|
|
306
|
+
* turn names are written there, checked as Codex took them, and reloaded
|
|
307
|
+
* when they changed.
|
|
308
|
+
*/
|
|
309
|
+
async configure({ servers }: CodexTurnMcp): Promise<void> {
|
|
244
310
|
if (servers === undefined) return;
|
|
245
311
|
const fingerprint = configFingerprint(servers);
|
|
246
312
|
const changed = this.fingerprint !== fingerprint;
|
|
@@ -252,6 +318,26 @@ export class CodexMcpState {
|
|
|
252
318
|
this.fingerprint = fingerprint;
|
|
253
319
|
}
|
|
254
320
|
|
|
321
|
+
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — checked against Codex's own
|
|
322
|
+
/**
|
|
323
|
+
* The `mcp_servers` table the thread carries, for a turn that names no
|
|
324
|
+
* home: the turn's servers, checked against Codex's own configuration.
|
|
325
|
+
* Read before the thread opens, so no connection is made first, and
|
|
326
|
+
* before each turn.
|
|
327
|
+
*/
|
|
328
|
+
async threadServers({
|
|
329
|
+
servers,
|
|
330
|
+
thread,
|
|
331
|
+
}: CodexTurnMcp): Promise<Record<string, unknown> | undefined> {
|
|
332
|
+
// A home the turn names holds the turn's servers, written there.
|
|
333
|
+
if (servers !== undefined || !thread) return undefined;
|
|
334
|
+
const result = (await this.client.request("config/read", { cwd: this.cwd })) as {
|
|
335
|
+
config?: { mcp_servers?: Record<string, unknown> };
|
|
336
|
+
};
|
|
337
|
+
assertCodexThreadMcp(result.config?.mcp_servers ?? {}, thread);
|
|
338
|
+
return thread;
|
|
339
|
+
}
|
|
340
|
+
|
|
255
341
|
/**
|
|
256
342
|
* Get the thread's servers ready for a turn: configured, started, and the
|
|
257
343
|
* ones it goes on without said through `onWarning`. A required server that
|
|
@@ -259,26 +345,56 @@ export class CodexMcpState {
|
|
|
259
345
|
*/
|
|
260
346
|
async prepare(
|
|
261
347
|
threadId: string,
|
|
262
|
-
|
|
348
|
+
mcp: CodexTurnMcp,
|
|
263
349
|
onWarning: ((warning: ErrorInfo) => Promise<void>) | undefined,
|
|
264
350
|
): Promise<void> {
|
|
265
|
-
// A server the last turn went without is
|
|
266
|
-
//
|
|
267
|
-
// when this turn requires it: its old failure must
|
|
268
|
-
|
|
269
|
-
const
|
|
270
|
-
|
|
351
|
+
// A server the last turn went without is started again once it is due
|
|
352
|
+
// (not on every turn: a reload is a round trip to every server that is
|
|
353
|
+
// down), or at once when this turn requires it: its old failure must
|
|
354
|
+
// not decide. So is every server after a turn whose servers did not settle.
|
|
355
|
+
const again = this.unavailable.retryNow(mcp.wire).length > 0 || this.unsettled;
|
|
356
|
+
const started = mcp.thread
|
|
357
|
+
? await this.startThreadServers(again)
|
|
358
|
+
: await this.startHomeServers(mcp, again);
|
|
271
359
|
let unavailable: Record<string, string>;
|
|
272
360
|
try {
|
|
273
|
-
unavailable = await settleCodexMcp(this.client, threadId,
|
|
361
|
+
unavailable = await settleCodexMcp(this.client, threadId, mcp.wire, this.causes);
|
|
274
362
|
} catch (error) {
|
|
275
|
-
|
|
276
|
-
this.fingerprint = undefined;
|
|
363
|
+
this.unsettled = true;
|
|
277
364
|
throw error;
|
|
278
365
|
}
|
|
279
|
-
|
|
280
|
-
//
|
|
281
|
-
this
|
|
366
|
+
this.unsettled = false;
|
|
367
|
+
// The turn goes on without a server it does not require, and says so.
|
|
368
|
+
// `started`: this turn tried the ones that were down, so their clock starts now.
|
|
369
|
+
this.unavailable.record(unavailable, () => started);
|
|
282
370
|
await this.unavailable.announce(onWarning);
|
|
283
371
|
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* The servers of a home the turn names: written, checked and reloaded when
|
|
375
|
+
* they changed or are to be started `again`. Whether this turn started them.
|
|
376
|
+
*/
|
|
377
|
+
private async startHomeServers(mcp: CodexTurnMcp, again: boolean): Promise<boolean> {
|
|
378
|
+
// Forgetting the last write makes `configure` write and reload it again.
|
|
379
|
+
if (again) this.fingerprint = undefined;
|
|
380
|
+
const starting =
|
|
381
|
+
mcp.servers !== undefined && this.fingerprint !== configFingerprint(mcp.servers);
|
|
382
|
+
await this.configure(mcp);
|
|
383
|
+
return starting;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — a reload starts a thread's own servers again
|
|
387
|
+
/**
|
|
388
|
+
* The servers a thread carries: they started when it opened, on the first
|
|
389
|
+
* turn this process prepares. After that a reload starts the ones that are
|
|
390
|
+
* not running `again` and leaves the others connected. Whether this turn
|
|
391
|
+
* started them.
|
|
392
|
+
*/
|
|
393
|
+
private async startThreadServers(again: boolean): Promise<boolean> {
|
|
394
|
+
const reloading = this.prepared && again;
|
|
395
|
+
if (reloading) await this.client.request("config/mcpServer/reload", undefined);
|
|
396
|
+
const started = reloading || !this.prepared;
|
|
397
|
+
this.prepared = true;
|
|
398
|
+
return started;
|
|
399
|
+
}
|
|
284
400
|
}
|
|
@@ -10,7 +10,7 @@ const MODEL_LIST_TIMEOUT_MS = 5_000;
|
|
|
10
10
|
const MODEL_LIST_PAGES = 10;
|
|
11
11
|
|
|
12
12
|
/** One `model/list` entry, as far as agent-server reads it. */
|
|
13
|
-
|
|
13
|
+
type CodexModel = Record<string, unknown>;
|
|
14
14
|
|
|
15
15
|
/** A model's thinking levels, and the native effort that `off` means for it. */
|
|
16
16
|
export interface CodexModelThinking {
|
|
@@ -37,9 +37,7 @@ function efforts(model: CodexModel): unknown[] {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/** Every page of `model/list`, hidden models included. Throws when the CLI cannot answer. */
|
|
40
|
-
|
|
41
|
-
client: Pick<CodexConnection, "request">,
|
|
42
|
-
): Promise<CodexModel[]> {
|
|
40
|
+
async function readCodexModels(client: Pick<CodexConnection, "request">): Promise<CodexModel[]> {
|
|
43
41
|
const models: CodexModel[] = [];
|
|
44
42
|
for await (const page of pages<CodexModel>(
|
|
45
43
|
client,
|
|
@@ -54,9 +52,11 @@ export async function readCodexModels(
|
|
|
54
52
|
/**
|
|
55
53
|
* What each model accepts, by its `model` and `id`. Codex's `none` or
|
|
56
54
|
* `minimal` is `off`, remembered so `off` sends the value the model
|
|
57
|
-
* advertised (`none` when it offers both).
|
|
55
|
+
* advertised (`none` when it offers both). A model that lists no efforts at
|
|
56
|
+
* all has none (`levels: []`); one that lists only efforts this build does not
|
|
57
|
+
* know, or says nothing, is left out, so what it accepts stays unknown.
|
|
58
58
|
*/
|
|
59
|
-
|
|
59
|
+
function codexModelThinking(models: readonly CodexModel[]): Map<string, CodexModelThinking> {
|
|
60
60
|
const thinking = new Map<string, CodexModelThinking>();
|
|
61
61
|
for (const model of models) {
|
|
62
62
|
const native = efforts(model);
|
|
@@ -66,7 +66,8 @@ export function codexModelThinking(models: readonly CodexModel[]): Map<string, C
|
|
|
66
66
|
? "minimal"
|
|
67
67
|
: undefined;
|
|
68
68
|
const levels = knownThinkingLevels(native.map(codexThinkingLevel));
|
|
69
|
-
|
|
69
|
+
const none = Array.isArray(model.supportedReasoningEfforts) && native.length === 0;
|
|
70
|
+
if (!levels.length && !none) continue;
|
|
70
71
|
const defaultEffort =
|
|
71
72
|
typeof model.defaultReasoningEffort === "string" ? model.defaultReasoningEffort : undefined;
|
|
72
73
|
for (const name of [model.model, model.id])
|
|
@@ -180,7 +181,7 @@ export function codexModelDescriptors(
|
|
|
180
181
|
}
|
|
181
182
|
|
|
182
183
|
/** What one `codex app-server` says about its models. */
|
|
183
|
-
|
|
184
|
+
interface CodexModelListing {
|
|
184
185
|
models: CodexModel[];
|
|
185
186
|
/**
|
|
186
187
|
* The model a new thread in the listing's folder runs when the turn names
|
|
@@ -9,7 +9,8 @@ import type { CodexAuth } from "./credentials.ts";
|
|
|
9
9
|
* Why a turn without tools (`disableTools`) fails on Codex. With every
|
|
10
10
|
* feature that offers one turned off, Codex 0.160 still gives a code-mode
|
|
11
11
|
* model its `exec` and `wait`, `apply_patch` inside `exec`, its sub-agent
|
|
12
|
-
* tools and `request_user_input` (
|
|
12
|
+
* tools and `request_user_input` (LLP 0017, Codex's own tools, which found
|
|
13
|
+
* the same with every `builtInTools` group off), so the
|
|
13
14
|
* model would still act: the turn is refused instead of running tools the
|
|
14
15
|
* caller turned off.
|
|
15
16
|
*/
|
|
@@ -91,12 +92,16 @@ export function codexSessionCompatible(
|
|
|
91
92
|
);
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
/**
|
|
95
|
+
/**
|
|
96
|
+
* How the harness starts `codex app-server` for a folder, its `env` and a
|
|
97
|
+
* login, at the operator's `inheritConfig`.
|
|
98
|
+
*/
|
|
95
99
|
export function clientOptionsFor(
|
|
96
100
|
codexPath: string,
|
|
97
101
|
{ cwd, env }: { cwd: string; env?: Record<string, string> },
|
|
98
102
|
auth: CodexAuth | undefined,
|
|
99
103
|
experimentalApi: boolean,
|
|
104
|
+
inheritConfig: InheritConfig = "all",
|
|
100
105
|
): Omit<CodexAppServerClientOptions, "processes"> {
|
|
101
106
|
return {
|
|
102
107
|
codexPath,
|
|
@@ -104,6 +109,12 @@ export function clientOptionsFor(
|
|
|
104
109
|
env: env ? { ...process.env, ...env } : process.env,
|
|
105
110
|
...(experimentalApi && { experimentalApi: true }),
|
|
106
111
|
...(auth && { ephemeralCredentials: true }),
|
|
112
|
+
// @ref LLP 0001#d17--a-turn-inherits-what-the-operator-chooses-all-the-projects-or-none — a session's home loads no plugins
|
|
113
|
+
// Below `all` a home a turn names is its session's own: none of the
|
|
114
|
+
// user's plugins belong there, and a fresh home clones Codex's plugin
|
|
115
|
+
// catalogue (about 84 MB) as the process starts, before a thread's
|
|
116
|
+
// config could turn it off.
|
|
117
|
+
...(inheritConfig !== "all" && env?.CODEX_HOME && { pluginsOff: true }),
|
|
107
118
|
};
|
|
108
119
|
}
|
|
109
120
|
|
|
@@ -111,24 +122,81 @@ export function clientOptionsFor(
|
|
|
111
122
|
const MANAGED_SUBAGENTS =
|
|
112
123
|
"Collect the results of every subagent before ending your turn. Stop any worker you no longer need. Delegated work cannot continue after this task completes.";
|
|
113
124
|
|
|
114
|
-
/**
|
|
125
|
+
/**
|
|
126
|
+
* Codex's own tools, by group, that the operator leaves on (the default for
|
|
127
|
+
* each, Codex's own behaviour) or turns off for every thread (LLP 0017).
|
|
128
|
+
*/
|
|
129
|
+
export interface CodexBuiltInTools {
|
|
130
|
+
/** The local environment: the shell, unified exec, `apply_patch`, `view_image`, `write_stdin`. */
|
|
131
|
+
local?: boolean;
|
|
132
|
+
webSearch?: boolean;
|
|
133
|
+
imageGeneration?: boolean;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** What the operator decides for every thread the harness opens. Never from the wire. */
|
|
137
|
+
export interface CodexThreadPolicy {
|
|
138
|
+
inheritConfig?: InheritConfig;
|
|
139
|
+
builtInTools?: CodexBuiltInTools;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** `thread/start` and `thread/resume` params, as far as the engine reads them. */
|
|
143
|
+
export interface CodexThreadParams extends Record<string, unknown> {
|
|
144
|
+
config: Record<string, unknown>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The params `thread/start` and `thread/resume` take for a turn with these
|
|
149
|
+
* options. `mcpServers`: the servers the thread carries in its own config,
|
|
150
|
+
* for a turn that names no home.
|
|
151
|
+
*/
|
|
115
152
|
export function threadParams(
|
|
116
153
|
options: AgentExecuteOptions,
|
|
117
|
-
|
|
118
|
-
|
|
154
|
+
policy: CodexThreadPolicy = {},
|
|
155
|
+
mcpServers?: Record<string, unknown>,
|
|
156
|
+
): CodexThreadParams {
|
|
119
157
|
const identity = processIdentity(options);
|
|
120
|
-
|
|
121
|
-
//
|
|
122
|
-
|
|
158
|
+
const tools = policy.builtInTools ?? {};
|
|
159
|
+
// @ref LLP 0017#one-nested-config — dotted keys beside a table apply in no fixed order
|
|
160
|
+
// One nested object, never a dotted key: Codex applies a dotted key and a
|
|
161
|
+
// table of the same root in an order that varies.
|
|
162
|
+
const features: Record<string, boolean> = {
|
|
163
|
+
// @ref LLP 0001#d14--nothing-the-agent-does-is-off-the-stream — Codex continues a goal by itself
|
|
164
|
+
// While a thread goal is active, Codex starts the next turn itself.
|
|
165
|
+
goals: false,
|
|
166
|
+
// @ref LLP 0001#d12--what-the-agent-asks-the-user-is-first-class-protocol-opted-into-per-turn — questions outside plan mode
|
|
167
|
+
// Outside plan mode Codex answers its question tool "unavailable"
|
|
168
|
+
// without this. With it a question reaches the engine, which declines
|
|
169
|
+
// it for a turn whose client answers none, as in plan mode.
|
|
170
|
+
default_mode_request_user_input: true,
|
|
171
|
+
};
|
|
172
|
+
if (options.subagentMode === "turn") features.multi_agent = true;
|
|
173
|
+
if (tools.local === false) {
|
|
174
|
+
features.shell_tool = false;
|
|
175
|
+
features.unified_exec = false;
|
|
176
|
+
}
|
|
177
|
+
if (tools.imageGeneration === false) features.image_generation = false;
|
|
178
|
+
// @ref LLP 0001#d17--a-turn-inherits-what-the-operator-chooses-all-the-projects-or-none — the account's connectors
|
|
179
|
+
// Codex's apps (`codex_apps`) are the ChatGPT account's connectors, which
|
|
180
|
+
// follow the login into any home: below `all` they stay out, as Claude's
|
|
181
|
+
// claude.ai connectors do. Plugins are off there too, on the command line
|
|
182
|
+
// (`clientOptionsFor`).
|
|
183
|
+
if (policy.inheritConfig !== undefined && policy.inheritConfig !== "all") features.apps = false;
|
|
184
|
+
const config: Record<string, unknown> = { features };
|
|
123
185
|
// Extra directories become writable roots of the workspace-write sandbox;
|
|
124
186
|
// read-only reads everywhere already, full access writes too.
|
|
125
187
|
if (options.additionalDirectories?.length)
|
|
126
|
-
config
|
|
127
|
-
|
|
188
|
+
config.sandbox_workspace_write = {
|
|
189
|
+
writable_roots: [...new Set(options.additionalDirectories)],
|
|
190
|
+
};
|
|
191
|
+
if (tools.webSearch === false) config.web_search = "disabled";
|
|
128
192
|
// @ref LLP 0001#d17--a-turn-inherits-what-the-operator-chooses-all-the-projects-or-none — the repository's AGENTS.md
|
|
129
193
|
// Codex reads every AGENTS.md from the repository's root to the working
|
|
130
194
|
// folder by itself; at `none`, none of them. The home's own still loads.
|
|
131
|
-
if (inheritConfig === "none") config.project_doc_max_bytes = 0;
|
|
195
|
+
if (policy.inheritConfig === "none") config.project_doc_max_bytes = 0;
|
|
196
|
+
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — the thread's own config
|
|
197
|
+
// Beside the servers of Codex's own configuration, by name; no file is
|
|
198
|
+
// written, and a resume without them has none of them.
|
|
199
|
+
if (mcpServers) config.mcp_servers = mcpServers;
|
|
132
200
|
const instructions =
|
|
133
201
|
options.subagentMode === "turn"
|
|
134
202
|
? [options.systemPromptAppend, MANAGED_SUBAGENTS].filter(Boolean).join("\n\n")
|
|
@@ -19,7 +19,7 @@ const WORKSPACE_PROFILE = ":workspace";
|
|
|
19
19
|
const IMPLEMENT_THE_PLAN = "Implement the plan.";
|
|
20
20
|
|
|
21
21
|
/** Codex's turn that carries out the user's answer to its plan. */
|
|
22
|
-
|
|
22
|
+
interface NextTurn {
|
|
23
23
|
params: Record<string, unknown>;
|
|
24
24
|
settings: ThreadSettings;
|
|
25
25
|
/** The thread's sandbox once it runs. */
|
|
@@ -48,6 +48,13 @@ export interface CodexItem {
|
|
|
48
48
|
error?: { message?: string } | string;
|
|
49
49
|
/** A `webSearch`. */
|
|
50
50
|
query?: string;
|
|
51
|
+
/**
|
|
52
|
+
* An `imageGeneration`: the prompt Codex wrote, once done; where Codex
|
|
53
|
+
* saved the picture; why it failed. (Its base64 `result` is not read.)
|
|
54
|
+
*/
|
|
55
|
+
revisedPrompt?: string | null;
|
|
56
|
+
savedPath?: string;
|
|
57
|
+
failure?: { type?: string } | null;
|
|
51
58
|
/** A `collabAgentToolCall`: a sub-agent spawned, messaged or waited on. */
|
|
52
59
|
receiverThreadIds?: string[];
|
|
53
60
|
prompt?: string | null;
|
|
@@ -62,7 +69,7 @@ export interface CodexItem {
|
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
/** A turn as `turn/started` and `turn/completed` name it (`Turn`). */
|
|
65
|
-
|
|
72
|
+
interface CodexTurnInfo {
|
|
66
73
|
id?: string;
|
|
67
74
|
/** `completed`, `interrupted` (stopped: a cancel, or an approval answered cancel), `failed`. */
|
|
68
75
|
status?: string;
|
|
@@ -106,9 +113,12 @@ export function codexTurn(n: CodexNotification): CodexTurnInfo | undefined {
|
|
|
106
113
|
};
|
|
107
114
|
}
|
|
108
115
|
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
-
|
|
116
|
+
/**
|
|
117
|
+
* An `error` Codex will not retry: its turn failed, and it ends that turn with
|
|
118
|
+
* `turn/completed` next. Seen on 0.160, some time later.
|
|
119
|
+
*/
|
|
120
|
+
export function failing(n: CodexNotification): boolean {
|
|
121
|
+
return n.method === "error" && n.params.willRetry !== true;
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
/** An `error` Codex retries what failed after: the turn goes on, and more is to come. */
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
unanswered,
|
|
14
14
|
} from "../elicitation.ts";
|
|
15
15
|
import { type CodexAuth, refreshTokens } from "./credentials.ts";
|
|
16
|
-
import { CODEX_TOOL_KINDS } from "./items.ts";
|
|
16
|
+
import { CODEX_TOOL_KINDS, codexChangeView, codexCommandLine } from "./items.ts";
|
|
17
17
|
import type { CodexSession } from "./session.ts";
|
|
18
18
|
import type { CodexTurnSubagents } from "./subagents.ts";
|
|
19
19
|
import type { TurnItems } from "./turn-items.ts";
|
|
@@ -161,6 +161,10 @@ function mcpConsentToolCall(params: Record<string, unknown>, items: TurnItems):
|
|
|
161
161
|
toolCallId: call?.id ?? generateUUIDv7(),
|
|
162
162
|
toolName: `${server}.${call?.tool ?? named ?? "tool"}`,
|
|
163
163
|
kind: CODEX_TOOL_KINDS.mcp,
|
|
164
|
+
// Both as Codex names them: the consent's server, and the tool of the
|
|
165
|
+
// call it was linked to. Its message's words are no name.
|
|
166
|
+
...(typeof params.serverName === "string" &&
|
|
167
|
+
call?.tool !== undefined && { mcp: { server: params.serverName, tool: call.tool } }),
|
|
164
168
|
...(message && { title: message }),
|
|
165
169
|
rawInput: isRecord(input) ? input : { arguments: input },
|
|
166
170
|
};
|
|
@@ -278,27 +282,31 @@ function approvalToolCall(
|
|
|
278
282
|
items: TurnItems,
|
|
279
283
|
): PermissionToolCall {
|
|
280
284
|
const id = typeof params.itemId === "string" ? params.itemId : "approval";
|
|
285
|
+
// @ref LLP 0002#a-tool-call-says-what-it-acts-on — Codex's reason is why it asks, not the call's title
|
|
281
286
|
const reason = typeof params.reason === "string" ? params.reason : undefined;
|
|
282
287
|
if (method === "item/commandExecution/requestApproval") {
|
|
283
288
|
const command = typeof params.command === "string" ? params.command : "";
|
|
289
|
+
const line = codexCommandLine(command);
|
|
284
290
|
return {
|
|
285
291
|
toolCallId: id,
|
|
286
292
|
toolName: "shell",
|
|
287
|
-
kind:
|
|
288
|
-
...(
|
|
293
|
+
kind: CODEX_TOOL_KINDS.shell,
|
|
294
|
+
...(line && { command: line }),
|
|
295
|
+
...(reason && { reason }),
|
|
289
296
|
rawInput: { command, ...(params.cwd ? { cwd: params.cwd } : {}) },
|
|
290
297
|
};
|
|
291
298
|
}
|
|
292
299
|
// A file-change request names its item, not the edits: those arrived on the
|
|
293
300
|
// item, which Codex starts before it asks. The approval shows them.
|
|
294
301
|
const changes = items.changesOf(id);
|
|
302
|
+
const { locations } = codexChangeView(changes);
|
|
295
303
|
const grantRoot = typeof params.grantRoot === "string" ? params.grantRoot : undefined;
|
|
296
304
|
return {
|
|
297
305
|
toolCallId: id,
|
|
298
306
|
toolName: "apply_patch",
|
|
299
|
-
kind:
|
|
300
|
-
...(reason && {
|
|
301
|
-
...(
|
|
307
|
+
kind: CODEX_TOOL_KINDS.apply_patch,
|
|
308
|
+
...(reason && { reason }),
|
|
309
|
+
...(locations.length && { locations }),
|
|
302
310
|
rawInput: { changes, ...(grantRoot && { grantRoot }) },
|
|
303
311
|
};
|
|
304
312
|
}
|