@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
|
@@ -7,7 +7,9 @@ import {
|
|
|
7
7
|
realpathSync,
|
|
8
8
|
} from "node:fs";
|
|
9
9
|
import { readdir } from "node:fs/promises";
|
|
10
|
-
import {
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
|
+
import { dirname, join, resolve } from "node:path";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
11
13
|
import type { AgentHarness } from "../../protocol/index.ts";
|
|
12
14
|
import { CliNotFoundError, CliProvisionError } from "../utils/errors.ts";
|
|
13
15
|
import type { LocalBuild } from "./checksums.ts";
|
|
@@ -22,20 +24,22 @@ import {
|
|
|
22
24
|
/**
|
|
23
25
|
* The managed CLIs. Each native harness maps onto exactly one of these; the
|
|
24
26
|
* `acp` harness maps onto none (its agent binaries are arbitrary third-party
|
|
25
|
-
* commands the operator supplies, not something we pin or download)
|
|
27
|
+
* commands the operator supplies, not something we pin or download), nor does
|
|
28
|
+
* `scripted`, which runs no process.
|
|
26
29
|
*/
|
|
27
30
|
export const CLI_TOOLS = ["claude", "codex"] as const;
|
|
28
31
|
export type CliTool = (typeof CLI_TOOLS)[number];
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* Which managed CLI a harness runs on — `undefined` for unmanaged harnesses
|
|
32
|
-
* (`acp`). Exhaustive by construction: adding a harness fails to
|
|
33
|
-
* until someone decides whether it is provisioner-managed.
|
|
35
|
+
* (`acp`, `scripted`). Exhaustive by construction: adding a harness fails to
|
|
36
|
+
* compile here until someone decides whether it is provisioner-managed.
|
|
34
37
|
*/
|
|
35
38
|
const TOOL_FOR_HARNESS: Record<AgentHarness, CliTool | undefined> = {
|
|
36
39
|
"claude-code": "claude",
|
|
37
40
|
"codex-app-server": "codex",
|
|
38
41
|
acp: undefined,
|
|
42
|
+
scripted: undefined,
|
|
39
43
|
};
|
|
40
44
|
|
|
41
45
|
export function toolForHarness(harness: AgentHarness): CliTool | undefined {
|
|
@@ -136,21 +140,33 @@ function findPackageDir(name: string, fromDir: string): string | undefined {
|
|
|
136
140
|
|
|
137
141
|
/**
|
|
138
142
|
* Where this package lives on disk — the walk anchor: this module's folder,
|
|
139
|
-
* or a bundle's when bundled (Bun defines `__dirname` in ESM too)
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
143
|
+
* or a bundle's when bundled (Bun defines `__dirname` in ESM too). Under
|
|
144
|
+
* Node's ESM (tsx, an ESM bundle), which has neither `__dirname` nor
|
|
145
|
+
* `require`, a `require` made from the entry script resolves this package's
|
|
146
|
+
* own manifest (an explicit export; the product's install, or the package
|
|
147
|
+
* itself by self-reference). Anything unresolvable is `undefined`, and pins
|
|
148
|
+
* take over. The walk never starts from the working folder, whose project
|
|
149
|
+
* may hold another Claude SDK than the one that runs. A compiled binary's
|
|
150
|
+
* modules are in `$bunfs`, nowhere on disk. NOTE: this must not mention
|
|
151
|
+
* `import` `.meta` (the meta-property; spelled apart here so the check in
|
|
152
|
+
* `test/core/provision/module-dir.test.ts` holds for comments too) —
|
|
153
|
+
* consumers bundle these sources to CJS, where that token is a parse error
|
|
154
|
+
* (and older bundlers, Bun 1.2.x, don't rewrite it).
|
|
146
155
|
*/
|
|
147
156
|
function moduleDir(): string | undefined {
|
|
157
|
+
if (inCompiledBinary()) return undefined;
|
|
148
158
|
// CJS bundle output: anchor at the bundle location.
|
|
149
159
|
if (typeof __dirname !== "undefined") return __dirname;
|
|
150
160
|
try {
|
|
151
|
-
// Bun/ESM
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
// Bun/ESM provides `require`; Node's ESM gets one from its entry script.
|
|
162
|
+
const entry = process.argv[1];
|
|
163
|
+
const resolver =
|
|
164
|
+
typeof require !== "undefined"
|
|
165
|
+
? require
|
|
166
|
+
: entry
|
|
167
|
+
? createRequire(pathToFileURL(resolve(entry)).href)
|
|
168
|
+
: undefined;
|
|
169
|
+
return resolver && dirname(resolver.resolve("@zvada/agent-server/package.json"));
|
|
154
170
|
} catch {
|
|
155
171
|
return undefined;
|
|
156
172
|
}
|
|
@@ -175,7 +191,10 @@ function versionOf(packageDir: string): string | undefined {
|
|
|
175
191
|
* never skew. Unresolvable inside compiled binaries — pins take over there.
|
|
176
192
|
*/
|
|
177
193
|
export function claudeSdkOnDisk(): { dir: string; version?: string } | undefined {
|
|
178
|
-
|
|
194
|
+
return claudeSdkFrom(moduleDir());
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function claudeSdkFrom(from: string | undefined): { dir: string; version?: string } | undefined {
|
|
179
198
|
if (!from) return undefined;
|
|
180
199
|
try {
|
|
181
200
|
const dir = findPackageDir("@anthropic-ai/claude-agent-sdk", from);
|
|
@@ -237,10 +256,16 @@ export const CLI_TOOL_SPECS: Record<CliTool, CliToolSpec> = {
|
|
|
237
256
|
// @ref LLP 0010#p2--claudes-build-follows-the-sdk-that-runs — a bundled SDK's version is the host's to say
|
|
238
257
|
// The compiled agent-server binary bundles the SDK it pins, so only
|
|
239
258
|
// another product's bundle runs an SDK nothing here can name.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
259
|
+
// Said only as it is: where the engine looked and found none, or that it could not look.
|
|
260
|
+
defaultVersionNote: () => {
|
|
261
|
+
if (inCompiledBinary()) return undefined;
|
|
262
|
+
const from = moduleDir();
|
|
263
|
+
if (claudeSdkFrom(from)) return undefined;
|
|
264
|
+
const why = from
|
|
265
|
+
? `no Claude SDK is installed beside agent-server (looked up from ${from})`
|
|
266
|
+
: "agent-server cannot tell where it runs from here and could not look for a Claude SDK";
|
|
267
|
+
return `claude: ${why}, so this runs the CLI of agent-server's pin ${DEFAULT_PINS.claude}; a product that bundles the SDK sets provision.pins.claude to its version`;
|
|
268
|
+
},
|
|
244
269
|
// The platform package beside the installed Claude SDK: the build that
|
|
245
270
|
// SDK would spawn itself.
|
|
246
271
|
hostInstall: ({ platform }) => {
|
|
@@ -20,16 +20,21 @@ import type { AgentRegistry } from "../agents/registry.ts";
|
|
|
20
20
|
import type { DiagnosticHandler } from "../diagnostics.ts";
|
|
21
21
|
import type { NativeRecord } from "../processes/identity.ts";
|
|
22
22
|
import type { NativeProcessEvent, OrphanOutcome } from "../processes/native-processes.ts";
|
|
23
|
-
import { setBounded } from "../utils/bounded.ts";
|
|
24
23
|
import { withTimeout } from "../utils/deadline.ts";
|
|
25
|
-
import { InvalidRequestError, TurnConflictError } from "../utils/errors.ts";
|
|
24
|
+
import { InvalidRequestError, TurnConflictError, TurnForgottenError } from "../utils/errors.ts";
|
|
26
25
|
import { type EventSink, EventSinkError } from "./event-sink.ts";
|
|
27
|
-
import { harnessCliProgress, harnessClis } from "./harness-clis.ts";
|
|
26
|
+
import { awaitingInstall, harnessCliProgress, harnessClis } from "./harness-clis.ts";
|
|
28
27
|
import { HarnessLogins } from "./harness-logins.ts";
|
|
29
|
-
import { ModelLists } from "./model-lists.ts";
|
|
28
|
+
import { ModelLists, catalogModelList } from "./model-lists.ts";
|
|
30
29
|
import { StandingRules } from "./permission-policy.ts";
|
|
31
30
|
import type { RequestAnswers, RequestKind } from "./request-broker.ts";
|
|
32
|
-
import {
|
|
31
|
+
import {
|
|
32
|
+
type RunSummary,
|
|
33
|
+
type SessionMemory,
|
|
34
|
+
Turn,
|
|
35
|
+
type TurnHost,
|
|
36
|
+
wellFormedInput,
|
|
37
|
+
} from "./turn.ts";
|
|
33
38
|
|
|
34
39
|
/**
|
|
35
40
|
* How `run()` would treat a request: execute it (`new`), or converge a retry
|
|
@@ -45,7 +50,11 @@ const turnKeyOf = (sessionId: string, turnId: string) => JSON.stringify([session
|
|
|
45
50
|
// @ref LLP 0003#commit-before-acknowledging — a turn sent again converges when it is the same turn
|
|
46
51
|
const inputKeyOf = (request: RunRequest) => canonicalJson(turnIdentity(request));
|
|
47
52
|
|
|
48
|
-
/**
|
|
53
|
+
/**
|
|
54
|
+
* Per-session convergence window. An older turn keeps only its id: a retry
|
|
55
|
+
* of it is refused (`TurnForgottenError`), since a turn id names one turn in
|
|
56
|
+
* the session's stream (LLP 0002) and a turn that ran never runs again.
|
|
57
|
+
*/
|
|
49
58
|
const SETTLED_TURNS = 16;
|
|
50
59
|
/** Give up on stragglers after this long; the process is exiting anyway. */
|
|
51
60
|
const DEFAULT_DRAIN_TIMEOUT_MS = 10_000;
|
|
@@ -78,8 +87,8 @@ export class AgentRuntime {
|
|
|
78
87
|
) {
|
|
79
88
|
this.logins = new HarnessLogins(
|
|
80
89
|
(harness) => registry.getAgent(harness),
|
|
81
|
-
(harness) => {
|
|
82
|
-
registry.getAgent(harness).loginChanged?.();
|
|
90
|
+
(harness, store) => {
|
|
91
|
+
registry.getAgent(harness).loginChanged?.(store);
|
|
83
92
|
this.modelLists.forget(harness);
|
|
84
93
|
},
|
|
85
94
|
);
|
|
@@ -97,7 +106,8 @@ export class AgentRuntime {
|
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
capabilities(harness: AgentHarness): AgentCapabilities {
|
|
100
|
-
|
|
109
|
+
// A custom agent that declares none says it ignores nothing.
|
|
110
|
+
return { ignoredSettings: [], ...this.registry.getAgent(harness).capabilities };
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
/**
|
|
@@ -105,10 +115,17 @@ export class AgentRuntime {
|
|
|
105
115
|
* turn with the same `cwd`, `env` and `apiKey` would use, and cached. Never
|
|
106
116
|
* rejects for a registered harness: without a live list it returns the
|
|
107
117
|
* catalog, with `error` saying why. Turns then fit their thinking level to
|
|
108
|
-
* the listed levels of the model they run.
|
|
118
|
+
* the listed levels of the model they run. A read installs nothing: while
|
|
119
|
+
* the harness's CLI is not installed yet, being installed or failed to,
|
|
120
|
+
* the answer is the catalog with that `error`, kept by no cache, so the
|
|
121
|
+
* first read after the install is live.
|
|
109
122
|
*/
|
|
110
123
|
async models(query: ModelsListParams): Promise<ModelList> {
|
|
111
|
-
|
|
124
|
+
const agent = this.registry.getAgent(query.harness);
|
|
125
|
+
// @ref LLP 0010#a-read-installs-nothing — a model picker opened downloads no CLI
|
|
126
|
+
const awaiting = await awaitingInstall(this.registry.provisioner, query.harness);
|
|
127
|
+
if (awaiting) return { ...catalogModelList(query.harness, Date.now()), error: awaiting };
|
|
128
|
+
return await this.modelLists.get(agent, query);
|
|
112
129
|
}
|
|
113
130
|
|
|
114
131
|
/**
|
|
@@ -135,9 +152,9 @@ export class AgentRuntime {
|
|
|
135
152
|
}
|
|
136
153
|
|
|
137
154
|
/**
|
|
138
|
-
* Every install of a harness's CLI, whoever caused it (a turn,
|
|
139
|
-
*
|
|
140
|
-
* Returns the unsubscribe.
|
|
155
|
+
* Every install of a harness's CLI, whoever caused it (a turn,
|
|
156
|
+
* `prepareClis`, a login or logout; a read installs nothing): at most four
|
|
157
|
+
* a second, and always its last phase. Returns the unsubscribe.
|
|
141
158
|
*/
|
|
142
159
|
onCliProgress(observer: (progress: HarnessCliProgress) => void): () => void {
|
|
143
160
|
const provisioner = this.registry.provisioner;
|
|
@@ -153,13 +170,25 @@ export class AgentRuntime {
|
|
|
153
170
|
* absent): signed in, with what and as whom, signed out, or unknown and
|
|
154
171
|
* why; and the logins it offers. A login made elsewhere (a terminal) that
|
|
155
172
|
* a read notices counts as a change, as `login` and `logout` do: each
|
|
156
|
-
* session's next turn starts a new CLI, and `onAuthUpdated` hears it.
|
|
173
|
+
* session's next turn starts a new CLI, and `onAuthUpdated` hears it. A
|
|
174
|
+
* login under way to the store is `loginUnderWay`. A read installs
|
|
175
|
+
* nothing: a harness whose CLI is not installed yet, being installed or
|
|
176
|
+
* failed to is `unknown`, with no methods and `error` saying which, and
|
|
177
|
+
* its CLI is not run.
|
|
157
178
|
*/
|
|
158
|
-
authStatus(
|
|
179
|
+
async authStatus(
|
|
159
180
|
harnesses: readonly AgentHarness[] = this.harnesses,
|
|
160
181
|
env?: Record<string, string>,
|
|
161
182
|
): Promise<HarnessAuth[]> {
|
|
162
|
-
|
|
183
|
+
for (const harness of harnesses) this.registry.getAgent(harness);
|
|
184
|
+
return Promise.all(
|
|
185
|
+
harnesses.map(async (harness): Promise<HarnessAuth> => {
|
|
186
|
+
// @ref LLP 0010#a-read-installs-nothing — a settings page opened downloads no CLI
|
|
187
|
+
const error = await awaitingInstall(this.registry.provisioner, harness);
|
|
188
|
+
if (error === undefined) return this.logins.statusOf(harness, env);
|
|
189
|
+
return { harness, state: "unknown", methods: [], error };
|
|
190
|
+
}),
|
|
191
|
+
);
|
|
163
192
|
}
|
|
164
193
|
|
|
165
194
|
/**
|
|
@@ -221,7 +250,8 @@ export class AgentRuntime {
|
|
|
221
250
|
* `new` (would run), `inflight`/`completed` (an identical request was
|
|
222
251
|
* already admitted — a retry must converge, not re-execute). Throws
|
|
223
252
|
* `TurnConflictError` when this turnId was admitted with DIFFERENT input,
|
|
224
|
-
*
|
|
253
|
+
* or ran too long ago to converge on (`TurnForgottenError`), and the turn's
|
|
254
|
+
* `EventSinkError` when its durable sink stopped it.
|
|
225
255
|
* Wire seats use this to quick-ack a duplicate instead of starting it.
|
|
226
256
|
*/
|
|
227
257
|
admission(request: RunRequest): TurnAdmission {
|
|
@@ -235,10 +265,12 @@ export class AgentRuntime {
|
|
|
235
265
|
/** The admitted turn a request names, in flight or settled; throws as `admission` says. */
|
|
236
266
|
private known(request: RunRequest): Turn | { summary: RunSummary } | undefined {
|
|
237
267
|
const { sessionId, turnId } = request;
|
|
238
|
-
const
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
268
|
+
const memory = this.sessions.get(sessionId);
|
|
269
|
+
const known = this.turns.get(turnKeyOf(sessionId, turnId)) ?? memory?.settled.get(turnId);
|
|
270
|
+
if (!known) {
|
|
271
|
+
if (memory?.forgotten.has(turnId)) throw new TurnForgottenError(sessionId, turnId);
|
|
272
|
+
return undefined;
|
|
273
|
+
}
|
|
242
274
|
if (known.inputKey !== inputKeyOf(request)) throw new TurnConflictError(sessionId, turnId);
|
|
243
275
|
if (known instanceof Turn) return known;
|
|
244
276
|
// It may have run tools before its sink failed: never run it again.
|
|
@@ -305,13 +337,13 @@ export class AgentRuntime {
|
|
|
305
337
|
): void {
|
|
306
338
|
if (this.turns.get(key) === turn) this.turns.delete(key);
|
|
307
339
|
if (!settled) return;
|
|
308
|
-
const { settled: window } = this.memoryOf(turn.sessionId);
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
340
|
+
const { settled: window, forgotten } = this.memoryOf(turn.sessionId);
|
|
341
|
+
window.set(turn.turnId, { inputKey: turn.inputKey, steers: turn.steers.answers(), ...settled });
|
|
342
|
+
for (const oldest of window.keys()) {
|
|
343
|
+
if (window.size <= SETTLED_TURNS) break;
|
|
344
|
+
window.delete(oldest);
|
|
345
|
+
forgotten.add(oldest);
|
|
346
|
+
}
|
|
315
347
|
}
|
|
316
348
|
|
|
317
349
|
/**
|
|
@@ -360,7 +392,10 @@ export class AgentRuntime {
|
|
|
360
392
|
const agent = this.registry.getAgent(turn.harness);
|
|
361
393
|
const deliver = agent.capabilities.steering ? agent.steer?.bind(agent) : undefined;
|
|
362
394
|
if (!deliver) return { outcome: "unsupported" };
|
|
363
|
-
|
|
395
|
+
// Its echo is the caller's input; the agent is given it well-formed.
|
|
396
|
+
return await turn.steers.accept(steerId, inputKey, input, () =>
|
|
397
|
+
deliver(sessionId, { ...request, input: wellFormedInput(input) }),
|
|
398
|
+
);
|
|
364
399
|
}
|
|
365
400
|
|
|
366
401
|
/** Whether another turn of the session, live or remembered, took this steer id. */
|
|
@@ -374,9 +409,10 @@ export class AgentRuntime {
|
|
|
374
409
|
|
|
375
410
|
/**
|
|
376
411
|
* Call after the host resumes from suspension, before admitting new turns.
|
|
377
|
-
* Retains conversations and admission receipts
|
|
378
|
-
*
|
|
379
|
-
*
|
|
412
|
+
* Retains conversations and admission receipts, and ends no process: Claude,
|
|
413
|
+
* Codex app-server and ACP replace each retained subprocess before its
|
|
414
|
+
* session's next prompt and strictly resume saved history. Their MCP
|
|
415
|
+
* reset/reload controls can retain dead connections.
|
|
380
416
|
*/
|
|
381
417
|
invalidateMcpConnections(): void {
|
|
382
418
|
for (const harness of this.registry.list()) {
|
|
@@ -466,7 +502,7 @@ export class AgentRuntime {
|
|
|
466
502
|
private memoryOf(sessionId: string): SessionMemory {
|
|
467
503
|
let memory = this.sessions.get(sessionId);
|
|
468
504
|
if (!memory) {
|
|
469
|
-
memory = { standingRules: new StandingRules(), settled: new Map() };
|
|
505
|
+
memory = { standingRules: new StandingRules(), settled: new Map(), forgotten: new Set() };
|
|
470
506
|
this.sessions.set(sessionId, memory);
|
|
471
507
|
}
|
|
472
508
|
return memory;
|
|
@@ -28,6 +28,7 @@ import type { TurnOutcome } from "./turn-outcome.ts";
|
|
|
28
28
|
function endedExecution(
|
|
29
29
|
execution: TurnExecution,
|
|
30
30
|
result: Pick<TransformResult, "reportedModels">,
|
|
31
|
+
notApplied: ReadonlySet<string>,
|
|
31
32
|
applied?: AppliedExecution,
|
|
32
33
|
): TurnExecution {
|
|
33
34
|
const reportedModels = result.reportedModels?.length
|
|
@@ -39,6 +40,8 @@ function endedExecution(
|
|
|
39
40
|
...execution,
|
|
40
41
|
...(applied?.thinkingLevel !== undefined && { appliedThinkingLevel: applied.thinkingLevel }),
|
|
41
42
|
...(reportedModels.length > 0 && { reportedModels }),
|
|
43
|
+
// Whether or not the model ran: what was not applied never was.
|
|
44
|
+
...(notApplied.size > 0 && { notApplied: [...notApplied] }),
|
|
42
45
|
};
|
|
43
46
|
}
|
|
44
47
|
|
|
@@ -91,6 +94,8 @@ export class EventProcessor {
|
|
|
91
94
|
private permissionMode: string;
|
|
92
95
|
/** What the harness runs the turn with, once it says (`AgentExecuteOptions.onExecution`). */
|
|
93
96
|
private applied?: AppliedExecution;
|
|
97
|
+
/** The settings the turn set that were not applied, in the order they were found. */
|
|
98
|
+
private readonly notApplied = new Set<string>();
|
|
94
99
|
/** The model writing what follows, by sub-agent tool call ("" for the turn's own). */
|
|
95
100
|
private readonly writtenBy = new Map<string, string>();
|
|
96
101
|
/** The model the open message named. */
|
|
@@ -107,8 +112,14 @@ export class EventProcessor {
|
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
/** What the harness runs the turn with, as it learns it: its model names the messages no event names. */
|
|
110
|
-
applyExecution(update: AppliedExecution): void {
|
|
115
|
+
applyExecution({ notApplied, ...update }: AppliedExecution): void {
|
|
111
116
|
this.applied = { ...this.applied, ...update };
|
|
117
|
+
this.markNotApplied(notApplied ?? []);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Settings the turn set that were not applied: `turn.ended.execution.notApplied`. */
|
|
121
|
+
markNotApplied(fields: Iterable<string>): void {
|
|
122
|
+
for (const field of fields) this.notApplied.add(field);
|
|
112
123
|
}
|
|
113
124
|
|
|
114
125
|
/**
|
|
@@ -287,7 +298,12 @@ export class EventProcessor {
|
|
|
287
298
|
finishReason: result.finishReason,
|
|
288
299
|
tokens: result.usage,
|
|
289
300
|
cost: result.cost,
|
|
290
|
-
execution: endedExecution(
|
|
301
|
+
execution: endedExecution(
|
|
302
|
+
this.execution,
|
|
303
|
+
result,
|
|
304
|
+
this.notApplied,
|
|
305
|
+
ran ? this.applied : undefined,
|
|
306
|
+
),
|
|
291
307
|
error: outcome.error,
|
|
292
308
|
...(undelivered.length > 0 && { undeliveredSteers: undelivered }),
|
|
293
309
|
timestamp: Date.now(),
|
|
@@ -20,7 +20,13 @@ function harnessCli(harness: AgentHarness, status: CliStatus | undefined): Harne
|
|
|
20
20
|
...(status.totalBytes !== undefined && { totalBytes: status.totalBytes }),
|
|
21
21
|
};
|
|
22
22
|
case "failed":
|
|
23
|
-
return {
|
|
23
|
+
return {
|
|
24
|
+
harness,
|
|
25
|
+
state: "failed",
|
|
26
|
+
...version,
|
|
27
|
+
error: status.error,
|
|
28
|
+
category: status.category,
|
|
29
|
+
};
|
|
24
30
|
}
|
|
25
31
|
}
|
|
26
32
|
|
|
@@ -43,6 +49,34 @@ export async function harnessClis(
|
|
|
43
49
|
);
|
|
44
50
|
}
|
|
45
51
|
|
|
52
|
+
// @ref LLP 0010#a-read-installs-nothing — a read answers without the CLI rather than install it
|
|
53
|
+
/**
|
|
54
|
+
* Why a read (a model list, a login's status) of this harness waits for an
|
|
55
|
+
* install it does not start: its CLI is not ready and the provisioner names
|
|
56
|
+
* the version an install would fetch (`missing` where the engine installs,
|
|
57
|
+
* `installing`, or `failed` after an install). `undefined` where a read goes
|
|
58
|
+
* ahead: the CLI is ready, nothing installs (`system`, which names no
|
|
59
|
+
* version), or the harness has no managed CLI.
|
|
60
|
+
*/
|
|
61
|
+
export async function awaitingInstall(
|
|
62
|
+
provisioner: CliProvisioner | undefined,
|
|
63
|
+
harness: AgentHarness,
|
|
64
|
+
): Promise<string | undefined> {
|
|
65
|
+
const tool = toolForHarness(harness);
|
|
66
|
+
if (!provisioner || !tool) return undefined;
|
|
67
|
+
const status = await provisioner.status(tool).catch(() => undefined);
|
|
68
|
+
if (!status || status.state === "ready" || status.version === undefined) return undefined;
|
|
69
|
+
const cli = `The ${harness} CLI ${status.version}`;
|
|
70
|
+
switch (status.state) {
|
|
71
|
+
case "missing":
|
|
72
|
+
return `${cli} is not installed yet.`;
|
|
73
|
+
case "installing":
|
|
74
|
+
return `${cli} is being installed.`;
|
|
75
|
+
case "failed":
|
|
76
|
+
return `${cli} failed to install: ${status.error}`;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
46
80
|
/** An install's progress, once per harness that runs its CLI. */
|
|
47
81
|
export function harnessCliProgress(
|
|
48
82
|
progress: CliProgress,
|
|
@@ -57,5 +91,6 @@ export function harnessCliProgress(
|
|
|
57
91
|
receivedBytes: progress.receivedBytes,
|
|
58
92
|
...(progress.totalBytes !== undefined && { totalBytes: progress.totalBytes }),
|
|
59
93
|
...(progress.error !== undefined && { error: progress.error }),
|
|
94
|
+
...(progress.category !== undefined && { category: progress.category }),
|
|
60
95
|
}));
|
|
61
96
|
}
|
|
@@ -22,7 +22,7 @@ const LOGIN_TTL_MS = 10 * 60_000;
|
|
|
22
22
|
const LOGIN_START_TIMEOUT_MS = 20_000;
|
|
23
23
|
/** A status read is reused this long once it answered: a settings page that polls starts no CLI each time. */
|
|
24
24
|
const STATUS_TTL_MS = 2_000;
|
|
25
|
-
/** A status read that takes longer (a CLI
|
|
25
|
+
/** A status read that takes longer (a CLI slow to start) answers `unknown`. */
|
|
26
26
|
const STATUS_TIMEOUT_MS = 20_000;
|
|
27
27
|
|
|
28
28
|
interface Login {
|
|
@@ -40,7 +40,7 @@ interface Login {
|
|
|
40
40
|
readonly settle: (update: AuthUpdated) => void;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
interface HarnessLoginsOptions {
|
|
44
44
|
now?: () => number;
|
|
45
45
|
newId?: () => string;
|
|
46
46
|
loginTtlMs?: number;
|
|
@@ -63,8 +63,13 @@ const storeKey = (harness: AgentHarness, env: Record<string, string> | undefined
|
|
|
63
63
|
* Each harness's login, read from its CLI, and the logins under way. A login
|
|
64
64
|
* that succeeds and a logout change the login, and so does a read that
|
|
65
65
|
* differs from the last one of its store (a login in a terminal): `onChanged`
|
|
66
|
-
* hears it
|
|
67
|
-
*
|
|
66
|
+
* hears it, with the store as the harness names it (each of that store's
|
|
67
|
+
* sessions starts its next turn on a new CLI, model lists are read again),
|
|
68
|
+
* and `onUpdated` listeners are told, as they are when a login starts
|
|
69
|
+
* and when it ends. Every login that leaves here carries the store's login
|
|
70
|
+
* under way (`loginUnderWay`), added as it leaves: a reading kept for its
|
|
71
|
+
* store never holds it, so a login starting or ending is no change of the
|
|
72
|
+
* login.
|
|
68
73
|
*/
|
|
69
74
|
export class HarnessLogins {
|
|
70
75
|
/** Logins under way, until their end is told. */
|
|
@@ -75,7 +80,7 @@ export class HarnessLogins {
|
|
|
75
80
|
|
|
76
81
|
constructor(
|
|
77
82
|
private readonly agentFor: (harness: AgentHarness) => Agent,
|
|
78
|
-
private readonly onChanged: (harness: AgentHarness) => void,
|
|
83
|
+
private readonly onChanged: (harness: AgentHarness, store: string | undefined) => void,
|
|
79
84
|
private readonly options: HarnessLoginsOptions = {},
|
|
80
85
|
) {
|
|
81
86
|
this.reads = new LoginReads(() => this.now(), options.statusTtlMs ?? STATUS_TTL_MS);
|
|
@@ -85,24 +90,49 @@ export class HarnessLogins {
|
|
|
85
90
|
return this.options.now?.() ?? Date.now();
|
|
86
91
|
}
|
|
87
92
|
|
|
93
|
+
/**
|
|
94
|
+
* The login changed in the store a turn with this `env` uses, as its
|
|
95
|
+
* harness names it. Status reads stay keyed by the whole `env`, which can
|
|
96
|
+
* differ in more than the store.
|
|
97
|
+
*/
|
|
98
|
+
private changed(harness: AgentHarness, env: Record<string, string> | undefined): void {
|
|
99
|
+
// @ref LLP 0011#a-login-change-starts-the-next-turn-on-a-new-cli — the person's own store is every store's
|
|
100
|
+
// A change in the default store (no store variable: the person's own)
|
|
101
|
+
// is a change in every store, none named: a product may link or hand
|
|
102
|
+
// that login into stores of its sessions' own (Deus links
|
|
103
|
+
// `~/.codex/auth.json` into each session's `CODEX_HOME`).
|
|
104
|
+
const store = this.agentFor(harness).login?.store?.(env) || undefined;
|
|
105
|
+
this.onChanged(harness, store);
|
|
106
|
+
}
|
|
107
|
+
|
|
88
108
|
/** Each harness's login: a read under way, or one a moment old, is shared. */
|
|
89
|
-
|
|
90
|
-
harnesses
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
status(harnesses: readonly AgentHarness[], env?: Record<string, string>): Promise<HarnessAuth[]> {
|
|
110
|
+
return Promise.all(harnesses.map((harness) => this.statusOf(harness, env)));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** One harness's login, with the store's login under way. */
|
|
114
|
+
async statusOf(harness: AgentHarness, env?: Record<string, string>): Promise<HarnessAuth> {
|
|
115
|
+
const store = storeKey(harness, env);
|
|
116
|
+
const recent = this.reads.recent(store);
|
|
117
|
+
if (recent) return this.withLogin((await recent).auth, store);
|
|
118
|
+
const { auth, differs } = await this.reread(harness, env);
|
|
119
|
+
// Changed where the engine did not change it: a login in a terminal.
|
|
120
|
+
if (differs) {
|
|
121
|
+
this.changed(harness, env);
|
|
122
|
+
this.emit({ auth: this.withLogin(auth, store) });
|
|
123
|
+
}
|
|
124
|
+
return this.withLogin(auth, store);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// @ref LLP 0011#the-wire — every reader sees a login under way, and can cancel it
|
|
128
|
+
/**
|
|
129
|
+
* The login as it leaves here: with the store's login under way, as
|
|
130
|
+
* `auth/login` answered it, when there is one. Made at the moment it is
|
|
131
|
+
* told, so no answer or update shows a login a newer one replaced.
|
|
132
|
+
*/
|
|
133
|
+
private withLogin(auth: HarnessAuth, store: string): HarnessAuth {
|
|
134
|
+
const login = this.underWay().find((candidate) => candidate.store === store);
|
|
135
|
+
return login ? { ...auth, loginUnderWay: { ...login.answer } } : auth;
|
|
106
136
|
}
|
|
107
137
|
|
|
108
138
|
private reread(harness: AgentHarness, env: Record<string, string> | undefined): Promise<Reading> {
|
|
@@ -188,7 +218,26 @@ export class HarnessLogins {
|
|
|
188
218
|
for (const login of this.underWay()) {
|
|
189
219
|
if (login.store === store) this.end(login, "cancelled");
|
|
190
220
|
}
|
|
191
|
-
|
|
221
|
+
const login = this.track(harness, method, store, env, native);
|
|
222
|
+
void this.tellStarted(login);
|
|
223
|
+
return login.answer;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Tell every listener a login started, after `auth/login` is answered:
|
|
228
|
+
* the store's login (its recent reading, else a new one) with this one
|
|
229
|
+
* under way. Nothing when it ended meanwhile, as its end says it; a read
|
|
230
|
+
* of its own that noticed a change is told all the same. A recent
|
|
231
|
+
* reading's change is its reader's, who told it already.
|
|
232
|
+
*/
|
|
233
|
+
private async tellStarted(login: Login): Promise<void> {
|
|
234
|
+
const recent = this.reads.recent(login.store);
|
|
235
|
+
const reading = await (recent ?? this.reread(login.harness, login.env)).catch(() => undefined);
|
|
236
|
+
if (!reading || this.stopped) return;
|
|
237
|
+
const noticed = !recent && reading.differs;
|
|
238
|
+
if (noticed) this.changed(login.harness, login.env);
|
|
239
|
+
else if (login.end) return;
|
|
240
|
+
this.emit({ auth: this.withLogin(reading.auth, login.store) });
|
|
192
241
|
}
|
|
193
242
|
|
|
194
243
|
/** Keep a started login until it ends, and expire it. */
|
|
@@ -198,7 +247,7 @@ export class HarnessLogins {
|
|
|
198
247
|
store: string,
|
|
199
248
|
env: Record<string, string> | undefined,
|
|
200
249
|
native: NativeLogin,
|
|
201
|
-
):
|
|
250
|
+
): Login {
|
|
202
251
|
const loginId = this.options.newId?.() ?? generateUUIDv7();
|
|
203
252
|
const ttl = this.options.loginTtlMs ?? LOGIN_TTL_MS;
|
|
204
253
|
const answer: AuthLogin = {
|
|
@@ -230,7 +279,7 @@ export class HarnessLogins {
|
|
|
230
279
|
() => this.finish(login, { loginId, outcome: "succeeded" }),
|
|
231
280
|
(error: unknown) => this.finish(login, { loginId, outcome: "failed", error: message(error) }),
|
|
232
281
|
);
|
|
233
|
-
return
|
|
282
|
+
return login;
|
|
234
283
|
}
|
|
235
284
|
|
|
236
285
|
/**
|
|
@@ -264,13 +313,14 @@ export class HarnessLogins {
|
|
|
264
313
|
/** Remove the CLI's own login: the harness's login after it. */
|
|
265
314
|
async logout(harness: AgentHarness, env?: Record<string, string>): Promise<HarnessAuth> {
|
|
266
315
|
await this.cliOf(harness).logout({ ...(env && { env }) });
|
|
267
|
-
this.
|
|
268
|
-
const { auth } = await this.reread(harness, env);
|
|
316
|
+
this.changed(harness, env);
|
|
317
|
+
const { auth: read } = await this.reread(harness, env);
|
|
318
|
+
const auth = this.withLogin(read, storeKey(harness, env));
|
|
269
319
|
this.emit({ auth });
|
|
270
320
|
return auth;
|
|
271
321
|
}
|
|
272
322
|
|
|
273
|
-
/** Every change of a harness's login, and every login's end. Returns the unsubscribe. */
|
|
323
|
+
/** Every change of a harness's login, and every login's start and end. Returns the unsubscribe. */
|
|
274
324
|
onUpdated(listener: (update: AuthUpdated) => void): () => void {
|
|
275
325
|
this.listeners.add(listener);
|
|
276
326
|
return () => this.listeners.delete(listener);
|
|
@@ -304,13 +354,14 @@ export class HarnessLogins {
|
|
|
304
354
|
const { harness } = login;
|
|
305
355
|
const succeeded = end.outcome === "succeeded";
|
|
306
356
|
// Before the read: a turn that starts meanwhile already runs a new CLI.
|
|
307
|
-
if (succeeded) this.
|
|
357
|
+
if (succeeded) this.changed(harness, login.env);
|
|
308
358
|
// Shutting down starts no CLI to read it.
|
|
309
359
|
const { auth, differs }: Reading = this.stopped
|
|
310
360
|
? { auth: { harness, state: "unknown", methods: [] }, differs: false }
|
|
311
361
|
: await this.reread(harness, login.env);
|
|
312
|
-
if (differs && !succeeded) this.
|
|
313
|
-
|
|
362
|
+
if (differs && !succeeded) this.changed(harness, login.env);
|
|
363
|
+
// Ended already, so it is no longer under way: a newer login that replaced it is.
|
|
364
|
+
const update: AuthUpdated = { auth: this.withLogin(auth, login.store), login: end };
|
|
314
365
|
this.logins.delete(end.loginId);
|
|
315
366
|
if (!this.stopped) this.emit(update);
|
|
316
367
|
login.settle(update);
|
|
@@ -33,7 +33,7 @@ interface Read {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/** The catalog's models for a harness, as a list (`source: "catalog"`). */
|
|
36
|
-
function catalogModelList(harness: AgentHarness, fetchedAt: number): ModelList {
|
|
36
|
+
export function catalogModelList(harness: AgentHarness, fetchedAt: number): ModelList {
|
|
37
37
|
return {
|
|
38
38
|
harness,
|
|
39
39
|
models: CATALOG_MODELS.filter((model) => model.harness === harness),
|
|
@@ -10,7 +10,7 @@ import type { PermissionDecision, PermissionRequestHandler } from "../agents/bas
|
|
|
10
10
|
* What a harness's request offers, and so who keeps an "always" answer: read
|
|
11
11
|
* once from `PermissionRequestHandler`'s `options` and `always`.
|
|
12
12
|
*/
|
|
13
|
-
|
|
13
|
+
type PermissionAsk =
|
|
14
14
|
/** The harness's own choices (a plan's approval: the mode to go on in). */
|
|
15
15
|
| { kind: "own_options"; options: PermissionOption[] }
|
|
16
16
|
/** The standard four; the engine keeps "always" as a standing rule for the tool. */
|
|
@@ -26,8 +26,9 @@ export type PermissionAsk =
|
|
|
26
26
|
* standing answer covers. "Always" covers what the harness says it does,
|
|
27
27
|
* never every call to the tool: one `npm test` must not approve every later
|
|
28
28
|
* command, so a harness that keeps it itself, or cannot scope one, says so,
|
|
29
|
-
* and the engine keeps no standing rule for its requests
|
|
30
|
-
*
|
|
29
|
+
* and the engine keeps no standing rule for its requests. A request no
|
|
30
|
+
* "always" is kept for at all (an ACP agent's, Codex's consent for an MCP
|
|
31
|
+
* tool call) leaves the engine one per tool.
|
|
31
32
|
*/
|
|
32
33
|
export function permissionAsk(opts: Parameters<PermissionRequestHandler>[1]): PermissionAsk {
|
|
33
34
|
if (opts?.options) return { kind: "own_options", options: opts.options };
|