@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
|
@@ -60,12 +60,27 @@ function codexError(value: unknown): { message?: string; codexErrorInfo?: unknow
|
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Which attempt a Codex retry is, of how many. Codex 0.160 sends the count
|
|
65
|
+
* only in its text ("Reconnecting... 2/5"), with no field for it and no
|
|
66
|
+
* wait: a text of any other shape, or a count past its total, gives none.
|
|
67
|
+
*/
|
|
68
|
+
// @ref LLP 0002#plan-usage-and-retries — a field the harness did not say is left out
|
|
69
|
+
function codexRetryCount(message: string): { attempt?: number; maxAttempts?: number } {
|
|
70
|
+
const match = /^Reconnecting\.\.\. (\d{1,3})\/(\d{1,3})$/.exec(message);
|
|
71
|
+
if (!match) return {};
|
|
72
|
+
const attempt = Number(match[1]);
|
|
73
|
+
const maxAttempts = Number(match[2]);
|
|
74
|
+
if (attempt < 1 || attempt > maxAttempts) return {};
|
|
75
|
+
return { attempt, maxAttempts };
|
|
76
|
+
}
|
|
77
|
+
|
|
63
78
|
/**
|
|
64
79
|
* Parses `codex app-server` v2 notifications into AdapterEvents. This harness
|
|
65
80
|
* streams token-level deltas (item/agentMessage/delta, item/reasoning/*Delta),
|
|
66
81
|
* so no diffing is needed. Items carry camelCase fields. Tool-like items
|
|
67
|
-
* (commandExecution/fileChange/mcpToolCall/webSearch) become
|
|
68
|
-
* complete on item/completed.
|
|
82
|
+
* (commandExecution/fileChange/mcpToolCall/webSearch/imageGeneration) become
|
|
83
|
+
* tool parts that complete on item/completed.
|
|
69
84
|
*/
|
|
70
85
|
export class CodexAppServerTransformer implements EventTransformer<unknown> {
|
|
71
86
|
private readonly ctx: StreamContext;
|
|
@@ -166,13 +181,14 @@ export class CodexAppServerTransformer implements EventTransformer<unknown> {
|
|
|
166
181
|
case "account/rateLimits/updated":
|
|
167
182
|
return codexLimits(params.rateLimits);
|
|
168
183
|
case "turn/completed": {
|
|
169
|
-
//
|
|
170
|
-
// the agent
|
|
184
|
+
// A failed turn's `error` that Codex will not retry comes before this,
|
|
185
|
+
// some time before on 0.160, and the agent holds the turn open until
|
|
186
|
+
// this comes: what that error said stays the turn's.
|
|
171
187
|
const turn = codexTurn(n);
|
|
172
|
-
if (turn?.error) {
|
|
188
|
+
if (!this.error && turn?.error) {
|
|
173
189
|
this.error = turn.error.message ?? "codex turn error";
|
|
174
190
|
this.errorCategory = codexErrorCategory(turn.error.codexErrorInfo);
|
|
175
|
-
} else if (turn?.status === "failed") {
|
|
191
|
+
} else if (!this.error && turn?.status === "failed") {
|
|
176
192
|
this.error = "Codex ended the turn as failed without saying why";
|
|
177
193
|
}
|
|
178
194
|
// @ref LLP 0001#d4--permission-requests-are-first-class-protocol — a cancelled answer stops the turn
|
|
@@ -185,15 +201,22 @@ export class CodexAppServerTransformer implements EventTransformer<unknown> {
|
|
|
185
201
|
}
|
|
186
202
|
case "error": {
|
|
187
203
|
// v2 errors carry a nested TurnError and may be transient. A retrying
|
|
188
|
-
// one tells the user why the turn is waiting;
|
|
189
|
-
//
|
|
204
|
+
// one tells the user why the turn is waiting; one Codex will not
|
|
205
|
+
// retry says why its turn failed, and its turn/completed follows.
|
|
190
206
|
const error = codexError(params.error);
|
|
191
207
|
const message =
|
|
192
208
|
error?.message ??
|
|
193
209
|
(typeof params.message === "string" ? params.message : "codex app-server error");
|
|
194
210
|
const category = codexErrorCategory(error?.codexErrorInfo);
|
|
195
211
|
if (params.willRetry) {
|
|
196
|
-
return [
|
|
212
|
+
return [
|
|
213
|
+
{
|
|
214
|
+
kind: "retry",
|
|
215
|
+
category: category ?? classifyError(message),
|
|
216
|
+
message,
|
|
217
|
+
...codexRetryCount(message),
|
|
218
|
+
},
|
|
219
|
+
];
|
|
197
220
|
}
|
|
198
221
|
this.error = message;
|
|
199
222
|
this.errorCategory = category;
|
|
@@ -227,9 +250,9 @@ export class CodexAppServerTransformer implements EventTransformer<unknown> {
|
|
|
227
250
|
return [{ kind: "part-open", part }];
|
|
228
251
|
}
|
|
229
252
|
default: {
|
|
230
|
-
// commandExecution / fileChange / mcpToolCall / webSearch
|
|
231
|
-
// descriptor vocabulary; userMessage and
|
|
232
|
-
// no assistant output.
|
|
253
|
+
// commandExecution / fileChange / mcpToolCall / webSearch /
|
|
254
|
+
// imageGeneration share one descriptor vocabulary; userMessage and
|
|
255
|
+
// unknown item types produce no assistant output.
|
|
233
256
|
const d = codexToolDescriptor(item.type);
|
|
234
257
|
return d ? [{ kind: "part-open", part: this.openTool(item, d) }] : [];
|
|
235
258
|
}
|
|
@@ -271,6 +294,8 @@ export class CodexAppServerTransformer implements EventTransformer<unknown> {
|
|
|
271
294
|
const d = codexToolDescriptor(item.type);
|
|
272
295
|
if (!d) return [];
|
|
273
296
|
const tool = this.tools.get(item.id) ?? this.openTool(item, d);
|
|
297
|
+
if (d.inputAtCompletion && tool.state.status === "in_progress")
|
|
298
|
+
tool.state = { ...tool.state, input: d.input(item) };
|
|
274
299
|
setToolMeta(tool, d.meta(item));
|
|
275
300
|
completeToolPart(tool, d.result(item));
|
|
276
301
|
return [{ kind: "part-update", part: tool }];
|
|
@@ -8,6 +8,8 @@ const SHUTDOWN_FAILED =
|
|
|
8
8
|
/failed to submit Shutdown|timed out waiting for .*shut down|shutdown timed out/;
|
|
9
9
|
/** The stderr the shutdown sniff keeps between chunks: a line split across two is still read. */
|
|
10
10
|
const SNIFF_MAX = 4096;
|
|
11
|
+
/** How long Codex's own shutdown (EOF) has before its process is stopped. */
|
|
12
|
+
const SHUTDOWN_TIMEOUT_MS = 2_000;
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* How the harness introduces itself to Codex. It has no version of its own to
|
|
@@ -46,12 +48,22 @@ export interface CodexConnection {
|
|
|
46
48
|
onClose(handler: (error?: Error) => void): () => void;
|
|
47
49
|
/** End the app-server now. Nothing confirms that what it ran stopped. */
|
|
48
50
|
close(): void;
|
|
49
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* End the app-server by its own shutdown: whether that confirmed its
|
|
53
|
+
* threads and tools stopped. It is stopped after `timeoutMs`
|
|
54
|
+
* (`SHUTDOWN_TIMEOUT_MS` by default) and given as long again to exit.
|
|
55
|
+
*/
|
|
50
56
|
closeAndWait(timeoutMs?: number): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Settles once an app-server that was ended has exited, or could not be
|
|
59
|
+
* made to: Codex lets one process write a thread, so another resumes it
|
|
60
|
+
* after this. A connection without it has nothing to wait for.
|
|
61
|
+
*/
|
|
62
|
+
gone?(): Promise<void>;
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
/** How far `pages` reads a list. */
|
|
54
|
-
|
|
66
|
+
interface PageLimits {
|
|
55
67
|
/** Each page's deadline. */
|
|
56
68
|
timeoutMs?: number;
|
|
57
69
|
/** Past this many pages the list did not end. */
|
|
@@ -123,6 +135,12 @@ export interface CodexAppServerClientOptions {
|
|
|
123
135
|
* it would replace that home's own login.
|
|
124
136
|
*/
|
|
125
137
|
ephemeralCredentials?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Start with Codex's plugins off (`-c features.plugins=false`): set on the
|
|
140
|
+
* command line because a fresh `CODEX_HOME` clones the plugin catalogue
|
|
141
|
+
* as the process starts, before any thread's config is read.
|
|
142
|
+
*/
|
|
143
|
+
pluginsOff?: boolean;
|
|
126
144
|
startupTimeoutMs?: number;
|
|
127
145
|
/** Default deadline for every JSON-RPC request. */
|
|
128
146
|
requestTimeoutMs?: number;
|
|
@@ -156,6 +174,8 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
156
174
|
private exited = false;
|
|
157
175
|
private lastExit?: Error;
|
|
158
176
|
private nativeShutdownFailed = false;
|
|
177
|
+
/** The app-server's exit, or the end of a stop that could not end it. */
|
|
178
|
+
private leaving?: Promise<unknown>;
|
|
159
179
|
|
|
160
180
|
constructor(private readonly opts: CodexAppServerClientOptions) {}
|
|
161
181
|
|
|
@@ -201,7 +221,7 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
201
221
|
const deadline = timeoutMs ?? this.opts.requestTimeoutMs ?? 30_000;
|
|
202
222
|
const timer = setTimeout(() => {
|
|
203
223
|
this.pending.delete(id);
|
|
204
|
-
reject(new Error(`codex app-server '${method}' timed out`));
|
|
224
|
+
reject(new Error(`codex app-server '${method}' timed out after ${deadline}ms`));
|
|
205
225
|
}, deadline);
|
|
206
226
|
this.pending.set(id, { method, resolve, reject, timer });
|
|
207
227
|
try {
|
|
@@ -225,12 +245,19 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
225
245
|
this.rejectPending((method) => new Error(`codex app-server closed before '${method}'`));
|
|
226
246
|
// SIGTERM stops its command at once (0.07 s, measured); the walk and the
|
|
227
247
|
// SIGKILL after the grace cover an app-server that cannot act on it.
|
|
228
|
-
|
|
248
|
+
if (native) this.leaving = Promise.race([native.exited, native.stop()]);
|
|
229
249
|
if (wasOpen) this.notifyClosed();
|
|
230
250
|
}
|
|
231
251
|
|
|
252
|
+
gone(): Promise<void> {
|
|
253
|
+
return Promise.resolve(this.leaving).then(
|
|
254
|
+
() => {},
|
|
255
|
+
() => {},
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
232
259
|
/** EOF invokes native thread/tool cleanup. Killing the server alone proves nothing about workers. */
|
|
233
|
-
closeAndWait(timeoutMs =
|
|
260
|
+
closeAndWait(timeoutMs = SHUTDOWN_TIMEOUT_MS): Promise<boolean> {
|
|
234
261
|
if (this.shutdown) return this.shutdown;
|
|
235
262
|
const native = this.native;
|
|
236
263
|
if (!native) return Promise.resolve(true);
|
|
@@ -240,6 +267,15 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
240
267
|
return this.shutdown;
|
|
241
268
|
}
|
|
242
269
|
this.exited = true;
|
|
270
|
+
// Gone when it exited, or when the stop a slow shutdown falls back to is
|
|
271
|
+
// done: that can outlast the answer this returns.
|
|
272
|
+
let stopped = () => {};
|
|
273
|
+
this.leaving = Promise.race([
|
|
274
|
+
native.exited,
|
|
275
|
+
new Promise<void>((resolve) => {
|
|
276
|
+
stopped = resolve;
|
|
277
|
+
}),
|
|
278
|
+
]);
|
|
243
279
|
this.shutdown = new Promise<boolean>((resolve) => {
|
|
244
280
|
let forced = false;
|
|
245
281
|
const finish = (confirmed: boolean) => {
|
|
@@ -254,7 +290,7 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
254
290
|
// @ref LLP 0007#what-each-harness-does — a SIGKILLed app-server leaves its commands running
|
|
255
291
|
const killTimer = setTimeout(() => {
|
|
256
292
|
forced = true;
|
|
257
|
-
void native.stop();
|
|
293
|
+
void native.stop().then(stopped, stopped);
|
|
258
294
|
}, timeoutMs);
|
|
259
295
|
const deadline = setTimeout(() => finish(false), timeoutMs * 2);
|
|
260
296
|
// In stdio mode SIGTERM bypasses Codex's async shutdown. EOF drains
|
|
@@ -288,15 +324,18 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
288
324
|
this.nativeShutdownFailed = false;
|
|
289
325
|
const native = this.opts.processes.spawn({
|
|
290
326
|
command: this.opts.codexPath ?? "codex",
|
|
291
|
-
args:
|
|
292
|
-
|
|
293
|
-
|
|
327
|
+
args: [
|
|
328
|
+
"app-server",
|
|
329
|
+
...(this.opts.ephemeralCredentials ? ["-c", 'cli_auth_credentials_store="ephemeral"'] : []),
|
|
330
|
+
...(this.opts.pluginsOff ? ["-c", "features.plugins=false"] : []),
|
|
331
|
+
],
|
|
294
332
|
cwd: this.opts.cwd,
|
|
295
333
|
env: this.opts.env ?? process.env,
|
|
296
334
|
harness: "codex-app-server",
|
|
297
335
|
...(this.opts.sessionId !== undefined && { sessionId: this.opts.sessionId }),
|
|
298
336
|
});
|
|
299
337
|
this.native = native;
|
|
338
|
+
this.leaving = native.exited;
|
|
300
339
|
const proc = native.child;
|
|
301
340
|
proc.stdout?.on("data", (chunk: Buffer) => this.onStdout(chunk));
|
|
302
341
|
// A broken pipe usually means the process died: its exit, which says
|
|
@@ -394,11 +433,31 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
394
433
|
if (this.exited) return;
|
|
395
434
|
this.exited = true;
|
|
396
435
|
this.lastExit = error;
|
|
436
|
+
// A broken pipe closes it while the app-server may still run (wedged,
|
|
437
|
+
// its stdin gone). It is stopped, so the process that takes its thread
|
|
438
|
+
// waits the stop's grace at most, not for an exit that never comes.
|
|
439
|
+
const native = this.native;
|
|
440
|
+
if (native) this.leaving = Promise.race([native.exited, native.stop()]);
|
|
397
441
|
this.rejectPending(() => error);
|
|
398
442
|
this.notifyClosed(error);
|
|
399
443
|
}
|
|
400
444
|
|
|
401
445
|
private write(payload: unknown): void {
|
|
402
|
-
this.native?.child.stdin?.write(`${JSON.stringify(payload)}\n`);
|
|
446
|
+
this.native?.child.stdin?.write(`${JSON.stringify(payload, wellFormed)}\n`);
|
|
403
447
|
}
|
|
404
448
|
}
|
|
449
|
+
|
|
450
|
+
// @ref LLP 0013#f12-a-lone-surrogate-hung-codex — a line Codex cannot read is never answered
|
|
451
|
+
/**
|
|
452
|
+
* A `JSON.stringify` replacer that makes every string and every key
|
|
453
|
+
* well-formed (a lone UTF-16 surrogate becomes U+FFFD). JSON.stringify
|
|
454
|
+
* writes a lone surrogate as its `\ud83d` escape, which Codex 0.160 cannot
|
|
455
|
+
* parse ("unexpected end of hex escape"): it drops the line and never answers.
|
|
456
|
+
* A key is an MCP server's name, say.
|
|
457
|
+
*/
|
|
458
|
+
function wellFormed(_key: string, value: unknown): unknown {
|
|
459
|
+
if (typeof value === "string") return value.toWellFormed();
|
|
460
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return value;
|
|
461
|
+
if (Object.keys(value).every((key) => key.isWellFormed())) return value;
|
|
462
|
+
return Object.fromEntries(Object.entries(value).map(([key, v]) => [key.toWellFormed(), v]));
|
|
463
|
+
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { AgentCapabilities, AgentInput, ModelDescriptor } from "../../../protocol/index.ts";
|
|
2
|
-
import { type NativeProcesses, sharedNativeProcesses } from "../../processes/native-processes.ts";
|
|
3
|
-
import { onAbort } from "../../utils/deadline.ts";
|
|
4
1
|
import type {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from "
|
|
2
|
+
AgentCapabilities,
|
|
3
|
+
AgentInput,
|
|
4
|
+
ModelDescriptor,
|
|
5
|
+
RunConfig,
|
|
6
|
+
} from "../../../protocol/index.ts";
|
|
7
|
+
import { type NativeProcesses, sharedNativeProcesses } from "../../processes/native-processes.ts";
|
|
8
|
+
import { onAbort, untilAborted } from "../../utils/deadline.ts";
|
|
9
|
+
import type { AgentExecuteOptions, ListModelsOptions, RawAgentEvent } from "../base.ts";
|
|
10
10
|
import { configFingerprint } from "../config-fingerprint.ts";
|
|
11
11
|
import type { CredentialSource } from "../credentials.ts";
|
|
12
12
|
import type { InheritConfig } from "../inherit-config.ts";
|
|
13
|
+
import { IDLE_TIMEOUT_MS } from "../process-pool.ts";
|
|
13
14
|
import { type DeliverSteer, SessionAgent } from "../session-agent.ts";
|
|
14
|
-
import { IDLE_TIMEOUT_MS } from "../session-pool.ts";
|
|
15
15
|
import {
|
|
16
16
|
CodexAppServerClient,
|
|
17
17
|
type CodexAppServerClientOptions,
|
|
@@ -22,12 +22,13 @@ import { type CodexAuth, authFor, logIn } from "./credentials.ts";
|
|
|
22
22
|
import { toUserInput } from "./input.ts";
|
|
23
23
|
import { CodexCliLogin } from "./login.ts";
|
|
24
24
|
import { codexModelDescriptors, listCodexModels, readCodexListing } from "./models.ts";
|
|
25
|
-
import { CODEX_TOOLS_REQUIRED, clientOptionsFor } from "./options.ts";
|
|
25
|
+
import { CODEX_TOOLS_REQUIRED, type CodexBuiltInTools, clientOptionsFor } from "./options.ts";
|
|
26
26
|
import type { CodexTurnScope } from "./requests.ts";
|
|
27
27
|
import { type CodexSession, CodexSessions } from "./session.ts";
|
|
28
28
|
import { CodexTurnSubagents, ManagedStop } from "./subagents.ts";
|
|
29
29
|
import { TurnItems } from "./turn-items.ts";
|
|
30
30
|
import { CodexTurn, type CodexTurnTiming, InterruptStop, type TurnStop } from "./turn.ts";
|
|
31
|
+
import { type ReadUserLogin, userAuth, userLoginReader } from "./user-login.ts";
|
|
31
32
|
|
|
32
33
|
const CAPABILITIES: AgentCapabilities = {
|
|
33
34
|
multiTurn: true,
|
|
@@ -44,28 +45,39 @@ const CAPABILITIES: AgentCapabilities = {
|
|
|
44
45
|
rejectionMessages: false,
|
|
45
46
|
turnScopedSubagents: true,
|
|
46
47
|
steering: true,
|
|
48
|
+
ignoredSettings: [
|
|
49
|
+
// Nothing in this harness sends a turn limit to the app-server.
|
|
50
|
+
"maxTurns",
|
|
51
|
+
// thread/resume continues a thread at its end; nothing here names a message in it.
|
|
52
|
+
"resumeSessionAt",
|
|
53
|
+
] satisfies Array<keyof RunConfig>,
|
|
47
54
|
};
|
|
48
55
|
|
|
49
56
|
/** How long a retryable error may go unanswered before the turn is failed. */
|
|
50
57
|
const RETRY_STALL_TIMEOUT_MS = 120_000;
|
|
51
58
|
|
|
52
|
-
/** How long
|
|
59
|
+
/** How long a cancelled turn has to stop before Codex's process is ended, unless `cancelGraceMs` says otherwise. */
|
|
53
60
|
const CANCEL_GRACE_MS = 2_000;
|
|
54
61
|
|
|
55
62
|
export interface CodexAppServerAgentOptions {
|
|
56
63
|
/** Make the connection to `codex app-server` (a test's fake); a `CodexAppServerClient` by default. */
|
|
57
64
|
createClient?: (options: CodexAppServerClientOptions) => CodexConnection;
|
|
65
|
+
/** Idle time before a session's app-server is ended (5 minutes by default); 0 never ends one for idleness. */
|
|
58
66
|
idleTimeoutMs?: number;
|
|
59
67
|
/** Fail a turn if the app-server goes silent this long after a retryable error. */
|
|
60
68
|
retryStallTimeoutMs?: number;
|
|
61
69
|
/**
|
|
62
|
-
* How long
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
* How long a cancel waits for Codex to confirm its turn stopped before it
|
|
71
|
+
* answers `confirmed: false` (`CANCEL_CONFIRM_MS`, 2 s, by default), and
|
|
72
|
+
* how long a failed turn waits for Codex to say it ended before its process
|
|
73
|
+
* is ended.
|
|
74
|
+
*/
|
|
75
|
+
cancelConfirmMs?: number;
|
|
76
|
+
/**
|
|
77
|
+
* How long after a cancel Codex's process is ended when its turn has not
|
|
78
|
+
* stopped (2 s by default): its `turn/interrupt` unanswered, or the
|
|
79
|
+
* commands the turn started not confirmed stopped, which Codex's own
|
|
80
|
+
* shutdown then stops.
|
|
69
81
|
*/
|
|
70
82
|
cancelGraceMs?: number;
|
|
71
83
|
/**
|
|
@@ -90,7 +102,9 @@ export interface CodexAppServerAgentOptions {
|
|
|
90
102
|
processes?: NativeProcesses;
|
|
91
103
|
/**
|
|
92
104
|
* What a thread loads by itself (LLP 0001, D17). At `all` (the default) a
|
|
93
|
-
* turn runs in the `CODEX_HOME` it names, else the process's
|
|
105
|
+
* turn runs in the `CODEX_HOME` it names, else the process's, which the
|
|
106
|
+
* engine never writes: there a turn's MCP servers go in its thread's own
|
|
107
|
+
* config (D21). At `project`
|
|
94
108
|
* every turn must name a home of its session's own (absolute, not the
|
|
95
109
|
* shared one, one session to a home): the user's configuration stays out,
|
|
96
110
|
* the repository's `AGENTS.md` and skills load. `none` also keeps the
|
|
@@ -98,6 +112,30 @@ export interface CodexAppServerAgentOptions {
|
|
|
98
112
|
* the repository's skills and `~/.agents/skills` at every level.
|
|
99
113
|
*/
|
|
100
114
|
inheritConfig?: InheritConfig;
|
|
115
|
+
/**
|
|
116
|
+
* Codex's own tools the model gets, each on unless set `false` (LLP 0017):
|
|
117
|
+
* `local` its shell, `apply_patch`, `view_image` and `write_stdin`, so
|
|
118
|
+
* that nothing it runs reads or writes the disk; `webSearch`; and
|
|
119
|
+
* `imageGeneration`, whose pictures come as an `image_generation` tool
|
|
120
|
+
* part, saying where Codex saved each, when it is on. `local: false` holds
|
|
121
|
+
* for the sub-agents Codex spawns too. A product whose agent works only
|
|
122
|
+
* through its own MCP tools turns all three off. Code mode's `exec`, its
|
|
123
|
+
* sub-agent tools and questions stay: `disableTools` is still refused.
|
|
124
|
+
* Operator-level only.
|
|
125
|
+
*/
|
|
126
|
+
builtInTools?: CodexBuiltInTools;
|
|
127
|
+
/**
|
|
128
|
+
* A turn that names a `CODEX_HOME` of its session's own (every turn below
|
|
129
|
+
* `inheritConfig: "all"` does) runs on the user's own Codex login: the one
|
|
130
|
+
* of the engine's own Codex home (`$CODEX_HOME`, else `~/.codex`), read
|
|
131
|
+
* from Codex before each turn and held in the session's process's memory,
|
|
132
|
+
* never written to the session's home (LLP 0017). A product's
|
|
133
|
+
* `credentials` and the turn's `apiKey` come first; with no login there
|
|
134
|
+
* the turn fails (`auth`) before its process starts. A product reads
|
|
135
|
+
* that login's status and signs it in with no `env` (`auth/*`). Off by
|
|
136
|
+
* default. Operator-level only.
|
|
137
|
+
*/
|
|
138
|
+
userLogin?: boolean;
|
|
101
139
|
}
|
|
102
140
|
|
|
103
141
|
/**
|
|
@@ -113,18 +151,24 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
113
151
|
readonly processes: NativeProcesses;
|
|
114
152
|
private readonly timing: CodexTurnTiming;
|
|
115
153
|
private readonly sessions: CodexSessions;
|
|
116
|
-
/** A cancel's acknowledgement belongs to one invocation, even after it drains. */
|
|
117
|
-
private readonly turns = new WeakMap<AbortController, CodexTurn>();
|
|
118
154
|
readonly login = new CodexCliLogin({
|
|
119
155
|
connect: (env) =>
|
|
120
156
|
this.connect({ cwd: process.cwd(), ...(env && { env }) }, { experimentalApi: false }),
|
|
121
157
|
cliPath: async () => (await this.cliPath()) ?? "codex",
|
|
122
158
|
});
|
|
159
|
+
/**
|
|
160
|
+
* The user's own login (`userLogin`), read from an app-server with the
|
|
161
|
+
* engine's own environment: never a session's `CODEX_HOME`.
|
|
162
|
+
*/
|
|
163
|
+
private readonly readUserLogin: ReadUserLogin = userLoginReader(() =>
|
|
164
|
+
this.connect({ cwd: process.cwd() }, { experimentalApi: false }),
|
|
165
|
+
);
|
|
123
166
|
|
|
124
167
|
constructor(private readonly agentOptions: CodexAppServerAgentOptions = {}) {
|
|
125
|
-
super();
|
|
168
|
+
super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
|
|
126
169
|
this.processes = agentOptions.processes ?? sharedNativeProcesses();
|
|
127
170
|
this.timing = {
|
|
171
|
+
confirmMs: this.cancelConfirmMs,
|
|
128
172
|
graceMs: agentOptions.cancelGraceMs ?? CANCEL_GRACE_MS,
|
|
129
173
|
retryStallMs: agentOptions.retryStallTimeoutMs ?? RETRY_STALL_TIMEOUT_MS,
|
|
130
174
|
};
|
|
@@ -141,7 +185,10 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
141
185
|
sessionId: options.sessionId,
|
|
142
186
|
}),
|
|
143
187
|
agentOptions.idleTimeoutMs ?? IDLE_TIMEOUT_MS,
|
|
144
|
-
|
|
188
|
+
{
|
|
189
|
+
inheritConfig: agentOptions.inheritConfig,
|
|
190
|
+
builtInTools: agentOptions.builtInTools,
|
|
191
|
+
},
|
|
145
192
|
);
|
|
146
193
|
}
|
|
147
194
|
|
|
@@ -166,6 +213,18 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
166
213
|
let session: CodexSession | undefined;
|
|
167
214
|
let stop: TurnStop | undefined;
|
|
168
215
|
let turn: CodexTurn | undefined;
|
|
216
|
+
// @ref LLP 0001#d21--a-codex-turn-that-names-no-home-carries-its-mcp-servers-in-its-thread — a thread is the session's once Codex takes a turn on it
|
|
217
|
+
// The thread the turn asked for is the session's already. One this turn
|
|
218
|
+
// started is not yet: Codex writes a thread at its first turn, so until
|
|
219
|
+
// then nothing of it can be resumed, and a turn that fails before
|
|
220
|
+
// leaves the session without a conversation, not with one no later
|
|
221
|
+
// process could resume.
|
|
222
|
+
let named = false;
|
|
223
|
+
const nameStarted = () => {
|
|
224
|
+
if (named || !session || !turn?.taken) return;
|
|
225
|
+
named = true;
|
|
226
|
+
options.onNativeSession?.(session.threadId, { resumed: false });
|
|
227
|
+
};
|
|
169
228
|
try {
|
|
170
229
|
signal.throwIfAborted();
|
|
171
230
|
// @ref LLP 0001#d5--messages-map-to-model-messages-no-silent-surface — no silent surface
|
|
@@ -183,17 +242,21 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
183
242
|
sessionId: options.sessionId,
|
|
184
243
|
turnId: options.turnId,
|
|
185
244
|
apiKey: options.apiKey,
|
|
245
|
+
userLogin: this.userLoginFor(options.env),
|
|
186
246
|
signal,
|
|
187
247
|
});
|
|
188
248
|
signal.throwIfAborted();
|
|
189
249
|
session = await this.sessions.acquire(options, scope, mcp);
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
});
|
|
250
|
+
named = session.threadId === options.resumeSessionId;
|
|
251
|
+
if (named) options.onNativeSession?.(session.threadId, { resumed: true });
|
|
193
252
|
const commands = new TurnCommands(session.client, session.threadId, this.timing.graceMs);
|
|
194
|
-
|
|
253
|
+
const turnStop = this.stopFor(session, scope, commands, options.sessionId);
|
|
254
|
+
stop = turnStop;
|
|
255
|
+
// Codex's turn, once there is one; before, its process, or a managed
|
|
256
|
+
// turn's cleanup.
|
|
257
|
+
this.cancelWith(options, () => turn?.cancel() ?? turnStop.cancel());
|
|
195
258
|
signal.throwIfAborted();
|
|
196
|
-
const offPreparing = onAbort(signal, () => void
|
|
259
|
+
const offPreparing = onAbort(signal, () => void turnStop.cancel());
|
|
197
260
|
try {
|
|
198
261
|
await session.mcp.prepare(session.threadId, mcp, options.onWarning);
|
|
199
262
|
signal.throwIfAborted();
|
|
@@ -204,10 +267,17 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
204
267
|
open: (deliver: DeliverSteer) => void this.openSteering(options, deliver),
|
|
205
268
|
hold: () => this.holdSteering(options),
|
|
206
269
|
};
|
|
207
|
-
turn = new CodexTurn(session, scope, options, commands,
|
|
208
|
-
|
|
209
|
-
|
|
270
|
+
turn = new CodexTurn(session, scope, options, commands, turnStop, steering, this.timing);
|
|
271
|
+
for await (const event of turn.run(userInput)) {
|
|
272
|
+
nameStarted();
|
|
273
|
+
yield event;
|
|
274
|
+
}
|
|
210
275
|
} catch (error) {
|
|
276
|
+
// A turn Codex took is on the thread, whatever came of it. A session
|
|
277
|
+
// released meanwhile refuses the name; the turn ends as it was ending.
|
|
278
|
+
try {
|
|
279
|
+
nameStarted();
|
|
280
|
+
} catch {}
|
|
211
281
|
if (!signal.aborted) throw error;
|
|
212
282
|
if (turn) yield* turn.endCancelled();
|
|
213
283
|
throw new Error("turn aborted");
|
|
@@ -218,6 +288,19 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
218
288
|
}
|
|
219
289
|
}
|
|
220
290
|
|
|
291
|
+
/**
|
|
292
|
+
* The user's own login, for a turn (or a model list) whose `env` names a
|
|
293
|
+
* home, when the operator set `userLogin`: read again for each, so a login
|
|
294
|
+
* the user changed is the next turn's. None otherwise: a turn that names
|
|
295
|
+
* no home runs on its home's own login.
|
|
296
|
+
*/
|
|
297
|
+
private userLoginFor(
|
|
298
|
+
env: Record<string, string> | undefined,
|
|
299
|
+
): ((signal?: AbortSignal) => Promise<CodexAuth>) | undefined {
|
|
300
|
+
if (!this.agentOptions.userLogin || !env?.CODEX_HOME) return undefined;
|
|
301
|
+
return (signal) => userAuth(this.readUserLogin, signal);
|
|
302
|
+
}
|
|
303
|
+
|
|
221
304
|
/** How the turn stops: by Codex's interrupt, or, managed, with its native cleanup. */
|
|
222
305
|
private stopFor(
|
|
223
306
|
session: CodexSession,
|
|
@@ -229,7 +312,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
229
312
|
const { graceMs } = this.timing;
|
|
230
313
|
if (session.subagentMode !== "turn")
|
|
231
314
|
return new InterruptStop(session, commands, scope.signal, graceMs);
|
|
232
|
-
scope.subagents = new CodexTurnSubagents(client, threadId
|
|
315
|
+
scope.subagents = new CodexTurnSubagents(client, threadId);
|
|
233
316
|
return new ManagedStop(scope.subagents, client, threadId, commands, scope.signal, graceMs, () =>
|
|
234
317
|
this.sessions.quarantine(sessionId, client),
|
|
235
318
|
);
|
|
@@ -256,6 +339,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
256
339
|
credentials: this.agentOptions.credentials,
|
|
257
340
|
sessionId: options.sessionId,
|
|
258
341
|
apiKey: options.apiKey,
|
|
342
|
+
userLogin: this.userLoginFor(options.env),
|
|
259
343
|
...(options.signal && { signal: options.signal }),
|
|
260
344
|
});
|
|
261
345
|
options.signal?.throwIfAborted();
|
|
@@ -270,20 +354,9 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
270
354
|
return codexModelDescriptors(listing.models, this.harness, listing.configuredModel);
|
|
271
355
|
}
|
|
272
356
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
// set on a later microtask, so reading afterwards would race that drain.
|
|
277
|
-
const controllers = [...(this.inflight.get(sessionId) ?? [])];
|
|
278
|
-
const base = await super.cancel(sessionId);
|
|
279
|
-
if (!base.hadTurn) {
|
|
280
|
-
const stopping = this.sessions.stopUnsettled(sessionId);
|
|
281
|
-
return stopping ? { confirmed: await stopping, hadTurn: false } : base;
|
|
282
|
-
}
|
|
283
|
-
const acknowledgements = await Promise.all(
|
|
284
|
-
controllers.map((controller) => this.turns.get(controller)?.acknowledgement ?? false),
|
|
285
|
-
);
|
|
286
|
-
return { confirmed: acknowledgements.every(Boolean), hadTurn: true };
|
|
357
|
+
/** With no turn running, a managed session's process not yet confirmed stopped. */
|
|
358
|
+
protected override stopWithoutTurn(sessionId: string): Promise<boolean> | undefined {
|
|
359
|
+
return this.sessions.stopUnsettled(sessionId);
|
|
287
360
|
}
|
|
288
361
|
|
|
289
362
|
/** Unchanged MCP config reloads retain dead remote connections after VM resume. */
|
|
@@ -291,8 +364,8 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
291
364
|
this.sessions.invalidate();
|
|
292
365
|
}
|
|
293
366
|
|
|
294
|
-
loginChanged(): void {
|
|
295
|
-
this.sessions.loginChanged();
|
|
367
|
+
loginChanged(store?: string): void {
|
|
368
|
+
this.sessions.loginChanged(store);
|
|
296
369
|
}
|
|
297
370
|
|
|
298
371
|
override async release(sessionId: string): Promise<void> {
|
|
@@ -301,17 +374,24 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
301
374
|
if (this.sessions.managed(sessionId) && !(await this.cancel(sessionId)).confirmed)
|
|
302
375
|
throw new Error("Codex native cleanup was not confirmed; cannot release the session");
|
|
303
376
|
await super.release(sessionId);
|
|
304
|
-
|
|
377
|
+
// @ref LLP 0001#d10--built-in-turns-own-their-logical-session-through-cleanup — released once its process has exited, as a Claude session is
|
|
378
|
+
await this.sessions.release(sessionId);
|
|
305
379
|
}
|
|
306
380
|
|
|
307
381
|
override async terminateAll(): Promise<void> {
|
|
308
382
|
await super.terminateAll();
|
|
309
|
-
this.sessions.terminateAll();
|
|
383
|
+
await this.sessions.terminateAll();
|
|
310
384
|
}
|
|
311
385
|
|
|
312
|
-
/**
|
|
313
|
-
|
|
314
|
-
|
|
386
|
+
/**
|
|
387
|
+
* The CLI to run: the provisioner's, else `$CODEX_CLI_PATH`; PATH's `codex`
|
|
388
|
+
* when neither. A turn waits for it until the turn is cancelled.
|
|
389
|
+
*/
|
|
390
|
+
private async cliPath(signal?: AbortSignal): Promise<string | undefined> {
|
|
391
|
+
// @ref LLP 0010#a-turn-waits-for-its-cli-until-it-is-cancelled — the install is the server's
|
|
392
|
+
const { resolveCliPath } = this.agentOptions;
|
|
393
|
+
const resolved = resolveCliPath && (await untilAborted(resolveCliPath(), signal));
|
|
394
|
+
return resolved ?? process.env.CODEX_CLI_PATH;
|
|
315
395
|
}
|
|
316
396
|
|
|
317
397
|
/**
|
|
@@ -329,10 +409,16 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
329
409
|
},
|
|
330
410
|
): Promise<CodexConnection> {
|
|
331
411
|
const { auth, experimentalApi, signal, sessionId } = spawn;
|
|
332
|
-
const codexPath = (await this.cliPath()) ?? "codex";
|
|
412
|
+
const codexPath = (await this.cliPath(signal)) ?? "codex";
|
|
333
413
|
signal?.throwIfAborted();
|
|
334
414
|
const clientOptions = {
|
|
335
|
-
...clientOptionsFor(
|
|
415
|
+
...clientOptionsFor(
|
|
416
|
+
codexPath,
|
|
417
|
+
options,
|
|
418
|
+
auth,
|
|
419
|
+
experimentalApi,
|
|
420
|
+
this.agentOptions.inheritConfig,
|
|
421
|
+
),
|
|
336
422
|
processes: this.processes,
|
|
337
423
|
...(sessionId !== undefined && { sessionId }),
|
|
338
424
|
};
|
|
@@ -134,7 +134,7 @@ export class TurnCommands {
|
|
|
134
134
|
constructor(
|
|
135
135
|
private readonly client: CodexConnection,
|
|
136
136
|
private readonly threadId: string,
|
|
137
|
-
/** How long
|
|
137
|
+
/** How long the commands have to stop before Codex's own shutdown stops them (`cancelGraceMs`). */
|
|
138
138
|
private readonly timeoutMs: number,
|
|
139
139
|
) {}
|
|
140
140
|
|
|
@@ -206,7 +206,7 @@ export class TurnCommands {
|
|
|
206
206
|
this.commands,
|
|
207
207
|
this.timeoutMs,
|
|
208
208
|
);
|
|
209
|
-
return unstopped.length && (await this.client.closeAndWait(
|
|
209
|
+
return unstopped.length && (await this.client.closeAndWait()) ? [] : unstopped;
|
|
210
210
|
})();
|
|
211
211
|
return this.stopping;
|
|
212
212
|
}
|
|
@@ -32,7 +32,9 @@ const chatGptTokens = (credential: Extract<CodexCredential, { type: "chatgpt" }>
|
|
|
32
32
|
* holds (`credentials`), an API key or a ChatGPT access token kept in the
|
|
33
33
|
* app-server's memory, which asks the product again (with the token it
|
|
34
34
|
* refused) when it needs a fresher one; without one, the turn's own `apiKey`;
|
|
35
|
-
* without that, the
|
|
35
|
+
* without that, the user's own login (`userLogin`, given for a turn that
|
|
36
|
+
* names a home of its session's own when the operator set it); without
|
|
37
|
+
* that, the CLI's own login.
|
|
36
38
|
*/
|
|
37
39
|
export async function authFor(ask: {
|
|
38
40
|
credentials: CredentialSource | undefined;
|
|
@@ -40,14 +42,17 @@ export async function authFor(ask: {
|
|
|
40
42
|
sessionId: string | undefined;
|
|
41
43
|
turnId?: string;
|
|
42
44
|
apiKey: string | undefined;
|
|
45
|
+
/** The user's own login, read from Codex (`user-login.ts`); it throws when there is none. */
|
|
46
|
+
userLogin?: (signal?: AbortSignal) => Promise<CodexAuth>;
|
|
43
47
|
signal?: AbortSignal;
|
|
44
48
|
}): Promise<CodexAuth | undefined> {
|
|
45
|
-
const { credentials, sessionId, turnId, apiKey, signal } = ask;
|
|
46
|
-
const
|
|
47
|
-
|
|
49
|
+
const { credentials, sessionId, turnId, apiKey, userLogin, signal } = ask;
|
|
50
|
+
const uncredentialed = async (): Promise<CodexAuth | undefined> =>
|
|
51
|
+
apiKey ? { type: "apiKey", apiKey } : userLogin?.(signal);
|
|
52
|
+
if (!credentials || !sessionId) return uncredentialed();
|
|
48
53
|
const request = { harness: "codex-app-server" as const, sessionId, ...(turnId && { turnId }) };
|
|
49
54
|
const credential = await credentialFor(credentials, request, signal);
|
|
50
|
-
if (!credential) return
|
|
55
|
+
if (!credential) return uncredentialed();
|
|
51
56
|
if (credential.type === "api_key") return { type: "apiKey", apiKey: credential.apiKey };
|
|
52
57
|
let current = credential;
|
|
53
58
|
return {
|