@zvada/agent-server 0.3.22 → 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 +261 -0
- package/dist/types/accounts/chatgpt.d.ts +1 -1
- package/dist/types/accounts/chatgpt.d.ts.map +1 -1
- package/dist/types/accounts/http.d.ts +2 -4
- package/dist/types/accounts/http.d.ts.map +1 -1
- package/dist/types/client/client.d.ts +37 -11
- package/dist/types/client/client.d.ts.map +1 -1
- package/dist/types/client/connection.d.ts +64 -13
- package/dist/types/client/connection.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -1
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/logins.d.ts +2 -1
- package/dist/types/client/logins.d.ts.map +1 -1
- package/dist/types/client/streams.d.ts +9 -3
- package/dist/types/client/streams.d.ts.map +1 -1
- package/dist/types/client/turns.d.ts +1 -1
- package/dist/types/client/turns.d.ts.map +1 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts +34 -1
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -1
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/acp/client.d.ts +12 -3
- package/dist/types/core/agents/acp/client.d.ts.map +1 -1
- package/dist/types/core/agents/acp/mappings.d.ts +8 -2
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -1
- package/dist/types/core/agents/base.d.ts +22 -8
- package/dist/types/core/agents/base.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/adapter.d.ts +7 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts +4 -1
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -1
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +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 +12 -2
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +58 -13
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/commands.d.ts +2 -2
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +5 -1
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/homes.d.ts +19 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/items.d.ts +27 -2
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/login.d.ts +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 +15 -30
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/models.d.ts +3 -10
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/options.d.ts +27 -4
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +16 -3
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/session.d.ts +68 -40
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +9 -4
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +3 -2
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +2 -1
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/turn.d.ts +31 -8
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -1
- package/dist/types/core/agents/codex-app-server/user-login.d.ts +28 -0
- package/dist/types/core/agents/codex-app-server/user-login.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +3 -1
- package/dist/types/core/agents/credentials.d.ts.map +1 -1
- package/dist/types/core/agents/diffs.d.ts +9 -0
- package/dist/types/core/agents/diffs.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +3 -2
- package/dist/types/core/agents/elicitation.d.ts.map +1 -1
- package/dist/types/core/agents/login.d.ts +6 -0
- package/dist/types/core/agents/login.d.ts.map +1 -1
- package/dist/types/core/agents/mcp-config.d.ts +0 -4
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -1
- package/dist/types/core/agents/process-pool.d.ts +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 +5 -0
- package/dist/types/core/index.d.ts.map +1 -1
- package/dist/types/core/presets.d.ts +32 -6
- package/dist/types/core/presets.d.ts.map +1 -1
- package/dist/types/core/processes/lifeline.d.ts +0 -20
- package/dist/types/core/processes/lifeline.d.ts.map +1 -1
- package/dist/types/core/provision/index.d.ts +2 -2
- package/dist/types/core/provision/index.d.ts.map +1 -1
- package/dist/types/core/provision/install-build.d.ts +2 -1
- package/dist/types/core/provision/install-build.d.ts.map +1 -1
- package/dist/types/core/provision/npm.d.ts +20 -8
- package/dist/types/core/provision/npm.d.ts.map +1 -1
- package/dist/types/core/provision/provisioner.d.ts +4 -1
- package/dist/types/core/provision/provisioner.d.ts.map +1 -1
- package/dist/types/core/provision/tools.d.ts +2 -1
- package/dist/types/core/provision/tools.d.ts.map +1 -1
- package/dist/types/core/runtime/agent-runtime.d.ts +16 -8
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -1
- package/dist/types/core/runtime/event-processor.d.ts +5 -1
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-clis.d.ts +9 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -1
- package/dist/types/core/runtime/harness-logins.d.ts +33 -5
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -1
- package/dist/types/core/runtime/model-lists.d.ts +2 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -1
- package/dist/types/core/runtime/permission-policy.d.ts +5 -3
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -1
- package/dist/types/core/runtime/request-broker.d.ts +2 -1
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -1
- package/dist/types/core/runtime/turn.d.ts +12 -1
- package/dist/types/core/runtime/turn.d.ts.map +1 -1
- package/dist/types/core/utils/deadline.d.ts +6 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -1
- package/dist/types/core/utils/errors.d.ts +7 -1
- package/dist/types/core/utils/errors.d.ts.map +1 -1
- package/dist/types/operator/operator.d.ts.map +1 -1
- package/dist/types/operator/render.d.ts +6 -4
- package/dist/types/operator/render.d.ts.map +1 -1
- package/dist/types/protocol/auth.d.ts +54 -24
- package/dist/types/protocol/auth.d.ts.map +1 -1
- package/dist/types/protocol/clis.d.ts +14 -7
- package/dist/types/protocol/clis.d.ts.map +1 -1
- package/dist/types/protocol/config.d.ts +2 -0
- package/dist/types/protocol/config.d.ts.map +1 -1
- package/dist/types/protocol/conversation.d.ts +40 -3
- package/dist/types/protocol/conversation.d.ts.map +1 -1
- package/dist/types/protocol/credentials.d.ts +7 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -1
- package/dist/types/protocol/execution.d.ts +2 -1
- package/dist/types/protocol/execution.d.ts.map +1 -1
- package/dist/types/protocol/factories.d.ts +12 -2
- package/dist/types/protocol/factories.d.ts.map +1 -1
- package/dist/types/protocol/harness.d.ts +6 -2
- package/dist/types/protocol/harness.d.ts.map +1 -1
- package/dist/types/protocol/history.d.ts +19 -0
- package/dist/types/protocol/history.d.ts.map +1 -1
- package/dist/types/protocol/lifecycle.d.ts +47 -8
- package/dist/types/protocol/lifecycle.d.ts.map +1 -1
- package/dist/types/protocol/model-catalog.d.ts.map +1 -1
- package/dist/types/protocol/models.d.ts +3 -0
- package/dist/types/protocol/models.d.ts.map +1 -1
- package/dist/types/protocol/parts.d.ts +14 -0
- package/dist/types/protocol/parts.d.ts.map +1 -1
- package/dist/types/protocol/tool-state.d.ts +12 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -1
- package/dist/types/protocol/wire-api.d.ts +129 -23
- package/dist/types/protocol/wire-api.d.ts.map +1 -1
- package/dist/types/protocol/wire.d.ts +70 -10
- package/dist/types/protocol/wire.d.ts.map +1 -1
- package/dist/types/server/acp/binding.d.ts +6 -1
- package/dist/types/server/acp/binding.d.ts.map +1 -1
- package/dist/types/server/acp/translate.d.ts +33 -7
- package/dist/types/server/acp/translate.d.ts.map +1 -1
- package/dist/types/server/agent-server.d.ts +6 -0
- package/dist/types/server/agent-server.d.ts.map +1 -1
- package/dist/types/server/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/docs/consuming.md +278 -28
- package/docs/deploy.md +36 -8
- package/docs/durable-sessions.md +35 -5
- package/docs/harnesses.md +385 -24
- package/package.json +6 -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 +103 -22
- package/src/client/index.ts +1 -0
- package/src/client/logins.ts +1 -1
- package/src/client/streams.ts +12 -4
- package/src/client/turns.ts +1 -1
- package/src/core/agents/acp/acp-agent.ts +181 -52
- package/src/core/agents/acp/adapter.ts +9 -1
- package/src/core/agents/acp/client.ts +16 -4
- package/src/core/agents/acp/mappings.ts +27 -0
- package/src/core/agents/base.ts +25 -10
- package/src/core/agents/claude-code/adapter.ts +47 -17
- package/src/core/agents/claude-code/approvals.ts +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 +37 -8
- package/src/core/agents/codex-app-server/codex-agent.ts +115 -50
- package/src/core/agents/codex-app-server/commands.ts +2 -2
- package/src/core/agents/codex-app-server/credentials.ts +10 -5
- package/src/core/agents/codex-app-server/effort.ts +1 -1
- package/src/core/agents/codex-app-server/homes.ts +43 -1
- 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 +47 -32
- package/src/core/agents/codex-app-server/models.ts +9 -8
- package/src/core/agents/codex-app-server/options.ts +69 -10
- package/src/core/agents/codex-app-server/plan-approval.ts +1 -1
- package/src/core/agents/codex-app-server/protocol.ts +14 -4
- package/src/core/agents/codex-app-server/requests.ts +14 -6
- package/src/core/agents/codex-app-server/session.ts +151 -113
- package/src/core/agents/codex-app-server/subagents.ts +21 -14
- package/src/core/agents/codex-app-server/thread-settings.ts +18 -8
- package/src/core/agents/codex-app-server/turn-items.ts +1 -1
- package/src/core/agents/codex-app-server/turn.ts +79 -32
- package/src/core/agents/codex-app-server/user-login.ts +107 -0
- package/src/core/agents/credentials.ts +5 -2
- package/src/core/agents/diffs.ts +25 -0
- package/src/core/agents/elicitation.ts +2 -2
- package/src/core/agents/login.ts +6 -0
- package/src/core/agents/mcp-config.ts +2 -2
- package/src/core/agents/process-pool.ts +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 +11 -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 +48 -18
- package/src/core/runtime/event-processor.ts +18 -2
- package/src/core/runtime/harness-clis.ts +36 -1
- package/src/core/runtime/harness-logins.ts +82 -31
- package/src/core/runtime/model-lists.ts +1 -1
- package/src/core/runtime/permission-policy.ts +4 -3
- package/src/core/runtime/request-broker.ts +1 -1
- package/src/core/runtime/turn.ts +51 -3
- package/src/core/utils/deadline.ts +23 -0
- package/src/core/utils/errors.ts +11 -4
- package/src/operator/operator.ts +8 -4
- package/src/operator/render.ts +46 -8
- package/src/protocol/auth.ts +30 -23
- package/src/protocol/clis.ts +12 -4
- package/src/protocol/credentials.ts +19 -0
- package/src/protocol/execution.ts +5 -0
- package/src/protocol/factories.ts +25 -3
- package/src/protocol/harness.ts +11 -1
- package/src/protocol/history.ts +20 -0
- package/src/protocol/lifecycle.ts +10 -1
- package/src/protocol/model-catalog.ts +19 -8
- package/src/protocol/parts.ts +12 -1
- package/src/protocol/tool-state.ts +14 -1
- package/src/protocol/wire.ts +14 -0
- package/src/server/acp/binding.ts +113 -23
- package/src/server/acp/translate.ts +161 -8
- package/src/server/agent-server.ts +10 -1
- package/src/server/bin.ts +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/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,7 +48,11 @@ 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>;
|
|
51
57
|
/**
|
|
52
58
|
* Settles once an app-server that was ended has exited, or could not be
|
|
@@ -57,7 +63,7 @@ export interface CodexConnection {
|
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
/** How far `pages` reads a list. */
|
|
60
|
-
|
|
66
|
+
interface PageLimits {
|
|
61
67
|
/** Each page's deadline. */
|
|
62
68
|
timeoutMs?: number;
|
|
63
69
|
/** Past this many pages the list did not end. */
|
|
@@ -129,6 +135,12 @@ export interface CodexAppServerClientOptions {
|
|
|
129
135
|
* it would replace that home's own login.
|
|
130
136
|
*/
|
|
131
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;
|
|
132
144
|
startupTimeoutMs?: number;
|
|
133
145
|
/** Default deadline for every JSON-RPC request. */
|
|
134
146
|
requestTimeoutMs?: number;
|
|
@@ -209,7 +221,7 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
209
221
|
const deadline = timeoutMs ?? this.opts.requestTimeoutMs ?? 30_000;
|
|
210
222
|
const timer = setTimeout(() => {
|
|
211
223
|
this.pending.delete(id);
|
|
212
|
-
reject(new Error(`codex app-server '${method}' timed out`));
|
|
224
|
+
reject(new Error(`codex app-server '${method}' timed out after ${deadline}ms`));
|
|
213
225
|
}, deadline);
|
|
214
226
|
this.pending.set(id, { method, resolve, reject, timer });
|
|
215
227
|
try {
|
|
@@ -245,7 +257,7 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
245
257
|
}
|
|
246
258
|
|
|
247
259
|
/** EOF invokes native thread/tool cleanup. Killing the server alone proves nothing about workers. */
|
|
248
|
-
closeAndWait(timeoutMs =
|
|
260
|
+
closeAndWait(timeoutMs = SHUTDOWN_TIMEOUT_MS): Promise<boolean> {
|
|
249
261
|
if (this.shutdown) return this.shutdown;
|
|
250
262
|
const native = this.native;
|
|
251
263
|
if (!native) return Promise.resolve(true);
|
|
@@ -312,9 +324,11 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
312
324
|
this.nativeShutdownFailed = false;
|
|
313
325
|
const native = this.opts.processes.spawn({
|
|
314
326
|
command: this.opts.codexPath ?? "codex",
|
|
315
|
-
args:
|
|
316
|
-
|
|
317
|
-
|
|
327
|
+
args: [
|
|
328
|
+
"app-server",
|
|
329
|
+
...(this.opts.ephemeralCredentials ? ["-c", 'cli_auth_credentials_store="ephemeral"'] : []),
|
|
330
|
+
...(this.opts.pluginsOff ? ["-c", "features.plugins=false"] : []),
|
|
331
|
+
],
|
|
318
332
|
cwd: this.opts.cwd,
|
|
319
333
|
env: this.opts.env ?? process.env,
|
|
320
334
|
harness: "codex-app-server",
|
|
@@ -429,6 +443,21 @@ export class CodexAppServerClient implements CodexConnection {
|
|
|
429
443
|
}
|
|
430
444
|
|
|
431
445
|
private write(payload: unknown): void {
|
|
432
|
-
this.native?.child.stdin?.write(`${JSON.stringify(payload)}\n`);
|
|
446
|
+
this.native?.child.stdin?.write(`${JSON.stringify(payload, wellFormed)}\n`);
|
|
433
447
|
}
|
|
434
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
|
/**
|
|
@@ -100,6 +112,30 @@ export interface CodexAppServerAgentOptions {
|
|
|
100
112
|
* the repository's skills and `~/.agents/skills` at every level.
|
|
101
113
|
*/
|
|
102
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;
|
|
103
139
|
}
|
|
104
140
|
|
|
105
141
|
/**
|
|
@@ -115,18 +151,24 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
115
151
|
readonly processes: NativeProcesses;
|
|
116
152
|
private readonly timing: CodexTurnTiming;
|
|
117
153
|
private readonly sessions: CodexSessions;
|
|
118
|
-
/** A cancel's acknowledgement belongs to one invocation, even after it drains. */
|
|
119
|
-
private readonly turns = new WeakMap<AbortController, CodexTurn>();
|
|
120
154
|
readonly login = new CodexCliLogin({
|
|
121
155
|
connect: (env) =>
|
|
122
156
|
this.connect({ cwd: process.cwd(), ...(env && { env }) }, { experimentalApi: false }),
|
|
123
157
|
cliPath: async () => (await this.cliPath()) ?? "codex",
|
|
124
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
|
+
);
|
|
125
166
|
|
|
126
167
|
constructor(private readonly agentOptions: CodexAppServerAgentOptions = {}) {
|
|
127
|
-
super();
|
|
168
|
+
super({ cancelConfirmMs: agentOptions.cancelConfirmMs });
|
|
128
169
|
this.processes = agentOptions.processes ?? sharedNativeProcesses();
|
|
129
170
|
this.timing = {
|
|
171
|
+
confirmMs: this.cancelConfirmMs,
|
|
130
172
|
graceMs: agentOptions.cancelGraceMs ?? CANCEL_GRACE_MS,
|
|
131
173
|
retryStallMs: agentOptions.retryStallTimeoutMs ?? RETRY_STALL_TIMEOUT_MS,
|
|
132
174
|
};
|
|
@@ -143,7 +185,10 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
143
185
|
sessionId: options.sessionId,
|
|
144
186
|
}),
|
|
145
187
|
agentOptions.idleTimeoutMs ?? IDLE_TIMEOUT_MS,
|
|
146
|
-
|
|
188
|
+
{
|
|
189
|
+
inheritConfig: agentOptions.inheritConfig,
|
|
190
|
+
builtInTools: agentOptions.builtInTools,
|
|
191
|
+
},
|
|
147
192
|
);
|
|
148
193
|
}
|
|
149
194
|
|
|
@@ -197,6 +242,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
197
242
|
sessionId: options.sessionId,
|
|
198
243
|
turnId: options.turnId,
|
|
199
244
|
apiKey: options.apiKey,
|
|
245
|
+
userLogin: this.userLoginFor(options.env),
|
|
200
246
|
signal,
|
|
201
247
|
});
|
|
202
248
|
signal.throwIfAborted();
|
|
@@ -204,9 +250,13 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
204
250
|
named = session.threadId === options.resumeSessionId;
|
|
205
251
|
if (named) options.onNativeSession?.(session.threadId, { resumed: true });
|
|
206
252
|
const commands = new TurnCommands(session.client, session.threadId, this.timing.graceMs);
|
|
207
|
-
|
|
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());
|
|
208
258
|
signal.throwIfAborted();
|
|
209
|
-
const offPreparing = onAbort(signal, () => void
|
|
259
|
+
const offPreparing = onAbort(signal, () => void turnStop.cancel());
|
|
210
260
|
try {
|
|
211
261
|
await session.mcp.prepare(session.threadId, mcp, options.onWarning);
|
|
212
262
|
signal.throwIfAborted();
|
|
@@ -217,8 +267,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
217
267
|
open: (deliver: DeliverSteer) => void this.openSteering(options, deliver),
|
|
218
268
|
hold: () => this.holdSteering(options),
|
|
219
269
|
};
|
|
220
|
-
turn = new CodexTurn(session, scope, options, commands,
|
|
221
|
-
this.turns.set(controller, turn);
|
|
270
|
+
turn = new CodexTurn(session, scope, options, commands, turnStop, steering, this.timing);
|
|
222
271
|
for await (const event of turn.run(userInput)) {
|
|
223
272
|
nameStarted();
|
|
224
273
|
yield event;
|
|
@@ -239,6 +288,19 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
239
288
|
}
|
|
240
289
|
}
|
|
241
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
|
+
|
|
242
304
|
/** How the turn stops: by Codex's interrupt, or, managed, with its native cleanup. */
|
|
243
305
|
private stopFor(
|
|
244
306
|
session: CodexSession,
|
|
@@ -250,7 +312,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
250
312
|
const { graceMs } = this.timing;
|
|
251
313
|
if (session.subagentMode !== "turn")
|
|
252
314
|
return new InterruptStop(session, commands, scope.signal, graceMs);
|
|
253
|
-
scope.subagents = new CodexTurnSubagents(client, threadId
|
|
315
|
+
scope.subagents = new CodexTurnSubagents(client, threadId);
|
|
254
316
|
return new ManagedStop(scope.subagents, client, threadId, commands, scope.signal, graceMs, () =>
|
|
255
317
|
this.sessions.quarantine(sessionId, client),
|
|
256
318
|
);
|
|
@@ -277,6 +339,7 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
277
339
|
credentials: this.agentOptions.credentials,
|
|
278
340
|
sessionId: options.sessionId,
|
|
279
341
|
apiKey: options.apiKey,
|
|
342
|
+
userLogin: this.userLoginFor(options.env),
|
|
280
343
|
...(options.signal && { signal: options.signal }),
|
|
281
344
|
});
|
|
282
345
|
options.signal?.throwIfAborted();
|
|
@@ -291,20 +354,9 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
291
354
|
return codexModelDescriptors(listing.models, this.harness, listing.configuredModel);
|
|
292
355
|
}
|
|
293
356
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
// set on a later microtask, so reading afterwards would race that drain.
|
|
298
|
-
const controllers = [...(this.inflight.get(sessionId) ?? [])];
|
|
299
|
-
const base = await super.cancel(sessionId);
|
|
300
|
-
if (!base.hadTurn) {
|
|
301
|
-
const stopping = this.sessions.stopUnsettled(sessionId);
|
|
302
|
-
return stopping ? { confirmed: await stopping, hadTurn: false } : base;
|
|
303
|
-
}
|
|
304
|
-
const acknowledgements = await Promise.all(
|
|
305
|
-
controllers.map((controller) => this.turns.get(controller)?.acknowledgement ?? false),
|
|
306
|
-
);
|
|
307
|
-
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);
|
|
308
360
|
}
|
|
309
361
|
|
|
310
362
|
/** Unchanged MCP config reloads retain dead remote connections after VM resume. */
|
|
@@ -312,8 +364,8 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
312
364
|
this.sessions.invalidate();
|
|
313
365
|
}
|
|
314
366
|
|
|
315
|
-
loginChanged(): void {
|
|
316
|
-
this.sessions.loginChanged();
|
|
367
|
+
loginChanged(store?: string): void {
|
|
368
|
+
this.sessions.loginChanged(store);
|
|
317
369
|
}
|
|
318
370
|
|
|
319
371
|
override async release(sessionId: string): Promise<void> {
|
|
@@ -322,17 +374,24 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
322
374
|
if (this.sessions.managed(sessionId) && !(await this.cancel(sessionId)).confirmed)
|
|
323
375
|
throw new Error("Codex native cleanup was not confirmed; cannot release the session");
|
|
324
376
|
await super.release(sessionId);
|
|
325
|
-
|
|
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);
|
|
326
379
|
}
|
|
327
380
|
|
|
328
381
|
override async terminateAll(): Promise<void> {
|
|
329
382
|
await super.terminateAll();
|
|
330
|
-
this.sessions.terminateAll();
|
|
383
|
+
await this.sessions.terminateAll();
|
|
331
384
|
}
|
|
332
385
|
|
|
333
|
-
/**
|
|
334
|
-
|
|
335
|
-
|
|
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;
|
|
336
395
|
}
|
|
337
396
|
|
|
338
397
|
/**
|
|
@@ -350,10 +409,16 @@ export class CodexAppServerAgent extends SessionAgent {
|
|
|
350
409
|
},
|
|
351
410
|
): Promise<CodexConnection> {
|
|
352
411
|
const { auth, experimentalApi, signal, sessionId } = spawn;
|
|
353
|
-
const codexPath = (await this.cliPath()) ?? "codex";
|
|
412
|
+
const codexPath = (await this.cliPath(signal)) ?? "codex";
|
|
354
413
|
signal?.throwIfAborted();
|
|
355
414
|
const clientOptions = {
|
|
356
|
-
...clientOptionsFor(
|
|
415
|
+
...clientOptionsFor(
|
|
416
|
+
codexPath,
|
|
417
|
+
options,
|
|
418
|
+
auth,
|
|
419
|
+
experimentalApi,
|
|
420
|
+
this.agentOptions.inheritConfig,
|
|
421
|
+
),
|
|
357
422
|
processes: this.processes,
|
|
358
423
|
...(sessionId !== undefined && { sessionId }),
|
|
359
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 {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ThinkingLevel, clampThinkingLevel } from "../../../protocol/index.ts";
|
|
2
2
|
|
|
3
3
|
/** Codex reasoning-effort string for a level (matches the `ReasoningEffort` enum). */
|
|
4
|
-
|
|
4
|
+
type CodexReasoningEffort =
|
|
5
5
|
| "none"
|
|
6
6
|
| "minimal"
|
|
7
7
|
| "low"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, realpathSync } from "node:fs";
|
|
1
|
+
import { closeSync, existsSync, openSync, realpathSync, statSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { isAbsolute, resolve } from "node:path";
|
|
4
4
|
import { InvalidRequestError } from "../../utils/errors.ts";
|
|
@@ -69,3 +69,45 @@ export class CodexHomes {
|
|
|
69
69
|
this.owners.clear();
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Which folder a `CODEX_HOME` is now (its device and inode), `"gone"` when
|
|
75
|
+
* there is none; nothing when the turn names no home. A process keeps the
|
|
76
|
+
* files it opened in the home it started in, so a home removed or replaced
|
|
77
|
+
* under it is another home: the conversation it writes is in deleted files,
|
|
78
|
+
* and the `config.toml` it reads is not the one there. The comparison holds
|
|
79
|
+
* only while the session holds its home open (`holdHome`): on ext4 a removed
|
|
80
|
+
* folder's inode number goes to the next folder made, at once, unless a
|
|
81
|
+
* handle on the old one is open (measured under Node 22 and Bun 1.3.14), so
|
|
82
|
+
* `rm -rf home; mkdir home` would otherwise read as the same folder.
|
|
83
|
+
*/
|
|
84
|
+
export function homeIdentity(home: string | undefined): string | undefined {
|
|
85
|
+
if (!home) return undefined;
|
|
86
|
+
try {
|
|
87
|
+
const { dev, ino } = statSync(home);
|
|
88
|
+
return `${dev}:${ino}`;
|
|
89
|
+
} catch {
|
|
90
|
+
return "gone";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Hold the folder a `CODEX_HOME` is now open, keeping its inode number its
|
|
96
|
+
* own (`homeIdentity`), until the answer is called; calling it again does
|
|
97
|
+
* nothing. A turn that names no home, or a home that cannot be opened (no
|
|
98
|
+
* folder, a platform that does not open directories), holds nothing.
|
|
99
|
+
*/
|
|
100
|
+
export function holdHome(home: string | undefined): () => void {
|
|
101
|
+
if (!home) return () => {};
|
|
102
|
+
let fd: number | undefined;
|
|
103
|
+
try {
|
|
104
|
+
fd = openSync(home, "r");
|
|
105
|
+
} catch {
|
|
106
|
+
return () => {};
|
|
107
|
+
}
|
|
108
|
+
return () => {
|
|
109
|
+
if (fd === undefined) return;
|
|
110
|
+
closeSync(fd);
|
|
111
|
+
fd = undefined;
|
|
112
|
+
};
|
|
113
|
+
}
|