@zvada/agent-server 0.3.22 → 0.3.24
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 +295 -0
- package/README.md +14 -5
- package/dist/accounts/chatgpt.js +144 -0
- package/dist/accounts/check.js +71 -0
- package/dist/accounts/claude.js +80 -0
- package/dist/accounts/endpoint.js +104 -0
- package/dist/accounts/http.js +58 -0
- package/dist/accounts/index.js +9 -0
- package/dist/client/client.js +686 -0
- package/dist/client/connection.js +338 -0
- package/dist/client/history.js +49 -0
- package/dist/client/index.js +6 -0
- package/dist/client/listeners.js +19 -0
- package/dist/client/logins.js +92 -0
- package/dist/client/rpc.js +105 -0
- package/dist/client/streams.js +432 -0
- package/dist/client/transports.js +118 -0
- package/dist/client/turns.js +122 -0
- package/dist/core/agents/acp/acp-agent.js +425 -0
- package/dist/core/agents/acp/adapter.js +231 -0
- package/dist/core/agents/acp/client.js +222 -0
- package/dist/core/agents/acp/known-agents.js +57 -0
- package/dist/core/agents/acp/mappings.js +164 -0
- package/dist/core/agents/acp/requests.js +79 -0
- package/dist/core/agents/attachments.js +14 -0
- package/dist/core/agents/base.js +64 -0
- package/dist/core/agents/claude-code/adapter.js +474 -0
- package/dist/core/agents/claude-code/approvals.js +245 -0
- package/dist/core/agents/claude-code/claude-agent.js +319 -0
- package/dist/core/agents/claude-code/credentials.js +142 -0
- package/dist/core/agents/claude-code/events.js +11 -0
- package/dist/core/agents/claude-code/login.js +217 -0
- package/dist/core/agents/claude-code/mcp.js +181 -0
- package/dist/core/agents/claude-code/models.js +74 -0
- package/dist/core/agents/claude-code/options.js +240 -0
- package/dist/core/agents/claude-code/outcome.js +204 -0
- package/dist/core/agents/claude-code/results.js +58 -0
- package/dist/core/agents/claude-code/sdk-pair.js +59 -0
- package/dist/core/agents/claude-code/session.js +593 -0
- package/dist/core/agents/claude-code/spawn.js +125 -0
- package/dist/core/agents/claude-code/spend.js +118 -0
- package/dist/core/agents/claude-code/tools.js +131 -0
- package/dist/core/agents/claude-code/turn-usage.js +121 -0
- package/dist/core/agents/claude-code/turn.js +199 -0
- package/dist/core/agents/codex-app-server/adapter.js +463 -0
- package/dist/core/agents/codex-app-server/client.js +338 -0
- package/dist/core/agents/codex-app-server/codex-agent.js +294 -0
- package/dist/core/agents/codex-app-server/commands.js +184 -0
- package/dist/core/agents/codex-app-server/credentials.js +92 -0
- package/dist/core/agents/codex-app-server/effort.js +13 -0
- package/dist/core/agents/codex-app-server/events.js +18 -0
- package/dist/core/agents/codex-app-server/homes.js +118 -0
- package/dist/core/agents/codex-app-server/input.js +52 -0
- package/dist/core/agents/codex-app-server/items.js +307 -0
- package/dist/core/agents/codex-app-server/login.js +183 -0
- package/dist/core/agents/codex-app-server/mcp.js +323 -0
- package/dist/core/agents/codex-app-server/models.js +160 -0
- package/dist/core/agents/codex-app-server/options.js +155 -0
- package/dist/core/agents/codex-app-server/plan-approval.js +124 -0
- package/dist/core/agents/codex-app-server/protocol.js +38 -0
- package/dist/core/agents/codex-app-server/requests.js +250 -0
- package/dist/core/agents/codex-app-server/session.js +278 -0
- package/dist/core/agents/codex-app-server/subagents.js +260 -0
- package/dist/core/agents/codex-app-server/thread-settings.js +214 -0
- package/dist/core/agents/codex-app-server/turn-items.js +69 -0
- package/dist/core/agents/codex-app-server/turn.js +448 -0
- package/dist/core/agents/codex-app-server/user-login.js +78 -0
- package/dist/core/agents/config-fingerprint.js +10 -0
- package/dist/core/agents/credentials.js +71 -0
- package/dist/core/agents/diffs.js +27 -0
- package/dist/core/agents/elicitation.js +42 -0
- package/dist/core/agents/inherit-config.js +5 -0
- package/dist/core/agents/login.js +56 -0
- package/dist/core/agents/mcp-config.js +109 -0
- package/dist/core/agents/plan.js +6 -0
- package/dist/core/agents/process-pool.js +307 -0
- package/dist/core/agents/registry.js +49 -0
- package/dist/core/agents/scripted/adapter.js +86 -0
- package/dist/core/agents/scripted/mcp-call.js +74 -0
- package/dist/core/agents/scripted/scripted-agent.js +330 -0
- package/dist/core/agents/scripted/scripts.js +154 -0
- package/dist/core/agents/scripted/steps.js +87 -0
- package/dist/core/agents/session-agent.js +209 -0
- package/dist/core/agents/stderr-tail.js +71 -0
- package/dist/core/agents/thinking-levels.js +9 -0
- package/dist/core/agents/types.js +1 -0
- package/dist/core/diagnostics.js +23 -0
- package/dist/core/index.js +31 -0
- package/dist/core/presets.js +114 -0
- package/dist/core/processes/identity.js +91 -0
- package/dist/core/processes/lifeline.js +210 -0
- package/dist/core/processes/native-processes.js +299 -0
- package/dist/core/processes/process-table.js +163 -0
- package/dist/core/provision/cache-trust.js +121 -0
- package/dist/core/provision/cache-usage.js +61 -0
- package/dist/core/provision/checksums.js +22 -0
- package/dist/core/provision/extract.js +28 -0
- package/dist/core/provision/index.js +4 -0
- package/dist/core/provision/install-build.js +99 -0
- package/dist/core/provision/npm.js +316 -0
- package/dist/core/provision/pins.js +35 -0
- package/dist/core/provision/platform.js +65 -0
- package/dist/core/provision/provisioner.js +372 -0
- package/dist/core/provision/releases.js +68 -0
- package/dist/core/provision/tools.js +279 -0
- package/dist/core/proxy/anthropic-proxy.js +163 -0
- package/dist/core/proxy/api-key-store.js +30 -0
- package/dist/core/proxy/index.js +3 -0
- package/dist/core/proxy/loopback.js +86 -0
- package/dist/core/runtime/agent-runtime.js +434 -0
- package/dist/core/runtime/event-processor.js +379 -0
- package/dist/core/runtime/event-sink.js +65 -0
- package/dist/core/runtime/harness-clis.js +83 -0
- package/dist/core/runtime/harness-logins.js +313 -0
- package/dist/core/runtime/login-reads.js +71 -0
- package/dist/core/runtime/model-lists.js +160 -0
- package/dist/core/runtime/permission-policy.js +84 -0
- package/dist/core/runtime/request-broker.js +139 -0
- package/dist/core/runtime/steering.js +79 -0
- package/dist/core/runtime/turn-outcome.js +16 -0
- package/dist/core/runtime/turn.js +329 -0
- package/dist/core/utils/bounded.js +13 -0
- package/dist/core/utils/deadline.js +57 -0
- package/dist/core/utils/errors.js +176 -0
- package/dist/core/utils/is-record.js +4 -0
- package/dist/core/utils/loopback.js +11 -0
- package/dist/index.js +4 -0
- package/dist/operator/index.js +10 -0
- package/dist/operator/mcp.js +139 -0
- package/dist/operator/operator.js +499 -0
- package/dist/operator/render.js +408 -0
- package/dist/operator/view.js +35 -0
- package/dist/protocol/account.js +96 -0
- package/dist/protocol/async-queue.js +65 -0
- package/dist/protocol/auth.js +169 -0
- package/dist/protocol/canonical.js +18 -0
- package/dist/protocol/clis.js +63 -0
- package/dist/protocol/config.js +137 -0
- package/dist/protocol/conversation.js +231 -0
- package/dist/protocol/credentials.js +141 -0
- package/dist/protocol/errors.js +181 -0
- package/dist/protocol/execution.js +28 -0
- package/dist/protocol/factories.js +231 -0
- package/dist/protocol/guards.js +71 -0
- package/dist/protocol/harness.js +93 -0
- package/dist/protocol/history.js +201 -0
- package/dist/protocol/ids.js +37 -0
- package/dist/protocol/index.js +36 -0
- package/dist/protocol/lifecycle.js +562 -0
- package/dist/protocol/meta-keys.js +17 -0
- package/dist/protocol/meta.js +13 -0
- package/dist/protocol/model-catalog.js +223 -0
- package/dist/protocol/models.js +84 -0
- package/dist/protocol/part-input.js +94 -0
- package/dist/protocol/parts.js +166 -0
- package/dist/protocol/plan.js +31 -0
- package/dist/protocol/reduce.js +484 -0
- package/dist/protocol/selectors.js +136 -0
- package/dist/protocol/seq-cursor.js +37 -0
- package/dist/protocol/stop-reasons.js +41 -0
- package/dist/protocol/thinking.js +31 -0
- package/dist/protocol/time.js +21 -0
- package/dist/protocol/tokens.js +57 -0
- package/dist/protocol/tool-closure.js +70 -0
- package/dist/protocol/tool-state.js +153 -0
- package/dist/protocol/verify.js +467 -0
- package/dist/protocol/vocabulary.js +27 -0
- package/dist/protocol/wire-api.js +94 -0
- package/dist/protocol/wire.js +669 -0
- package/dist/server/acp/binding.js +251 -0
- package/dist/server/acp/session-records.js +53 -0
- package/dist/server/acp/translate.js +401 -0
- package/dist/server/agent-server.js +338 -0
- package/dist/server/bin.js +492 -0
- package/dist/server/feedback.js +216 -0
- package/dist/server/history.js +123 -0
- package/dist/server/index.js +8 -0
- package/dist/server/install.js +171 -0
- package/dist/server/open-parts.js +87 -0
- package/dist/server/routes.js +291 -0
- package/dist/server/secrets.js +19 -0
- package/dist/server/session-gate.js +54 -0
- package/dist/server/session-log.js +66 -0
- package/dist/server/session-store.js +243 -0
- package/dist/server/subscriptions.js +189 -0
- package/dist/server/transports.js +214 -0
- package/dist/server/wire-error.js +26 -0
- package/dist/sync/event-log.js +89 -0
- package/dist/sync/fit.js +202 -0
- package/dist/sync/history-reader.js +33 -0
- package/dist/sync/history-sqlite.js +281 -0
- package/dist/sync/history.js +163 -0
- package/dist/sync/index.js +5 -0
- package/dist/sync/journal-sqlite.js +316 -0
- package/dist/sync/journal.js +10 -0
- package/dist/sync/live-tails.js +85 -0
- package/dist/sync/node-sqlite.js +27 -0
- package/dist/sync/projection.js +32 -0
- package/dist/sync/recovery.js +117 -0
- package/dist/sync/retry.js +45 -0
- package/dist/sync/schema.js +73 -0
- package/dist/sync/sql.js +94 -0
- package/dist/sync/sqlite-file.js +31 -0
- package/dist/sync/sqlite.js +18 -0
- package/dist/sync/worker.js +212 -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 +19 -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 +29 -10
- 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 +58 -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 +25 -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 +16 -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 +71 -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 +201 -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/bin.d.ts +3 -0
- package/dist/types/server/bin.d.ts.map +1 -0
- 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 +2 -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/node-sqlite.d.ts +4 -1
- package/dist/types/sync/node-sqlite.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 +304 -28
- package/docs/deploy.md +64 -8
- package/docs/durable-sessions.md +35 -5
- package/docs/harnesses.md +398 -25
- package/package.json +48 -18
- 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 +11 -6
- package/src/core/agents/claude-code/claude-agent.ts +89 -32
- 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 +30 -9
- 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 +179 -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 +54 -3
- package/src/core/agents/codex-app-server/items.ts +219 -31
- package/src/core/agents/codex-app-server/login.ts +44 -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 +17 -8
- package/src/core/agents/codex-app-server/session.ts +160 -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 +458 -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 +100 -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 +108 -19
- 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 +20 -1
- 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/node-sqlite.ts +19 -3
- 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
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { Readable, Writable } from "node:stream";
|
|
2
|
+
import { withTimeout } from "../../utils/deadline.js";
|
|
3
|
+
import { AgentExitedError } from "../../utils/errors.js";
|
|
4
|
+
/** How much of the agent's stderr tail an exit error carries: its last lines say why. */
|
|
5
|
+
const REASON_LINES = 2;
|
|
6
|
+
const REASON_MAX = 400;
|
|
7
|
+
/** How long an agent gets to stop on SIGTERM before it is killed. */
|
|
8
|
+
const KILL_GRACE_MS = 3_000;
|
|
9
|
+
/** How long a closed connection waits for the process's own exit, which says why. */
|
|
10
|
+
const EXIT_REASON_WAIT_MS = 500;
|
|
11
|
+
/**
|
|
12
|
+
* One ACP agent subprocess + its SDK connection. The engine talks to any
|
|
13
|
+
* ACP v1 agent through this: JSON-RPC framing, routing, and schema types come
|
|
14
|
+
* from `@agentclientprotocol/sdk` (dynamic-imported, optional peer dep);
|
|
15
|
+
* this wrapper owns the child process, close fan-out, and the mutable
|
|
16
|
+
* per-turn handlers (the SDK app's handlers are fixed at connect time, so
|
|
17
|
+
* they dispatch through this class's current fields — mirroring the
|
|
18
|
+
* codex-app-server client's `setRequestHandler` pattern).
|
|
19
|
+
*/
|
|
20
|
+
export class AcpClient {
|
|
21
|
+
opts;
|
|
22
|
+
native;
|
|
23
|
+
connection;
|
|
24
|
+
updateHandlers = new Set();
|
|
25
|
+
closeHandlers = new Set();
|
|
26
|
+
permissionHandler;
|
|
27
|
+
elicitationHandler;
|
|
28
|
+
exited = false;
|
|
29
|
+
/** The stop of its process, once one began: what `gone` waits for. */
|
|
30
|
+
leaving;
|
|
31
|
+
/** Why the agent stopped, once it has: its exit code and stderr tail. */
|
|
32
|
+
exitError;
|
|
33
|
+
connectionEnded = false;
|
|
34
|
+
constructor(opts) {
|
|
35
|
+
this.opts = opts;
|
|
36
|
+
}
|
|
37
|
+
/** Spawn the agent and connect. Fails if `@agentclientprotocol/sdk` is absent. */
|
|
38
|
+
static async create(opts) {
|
|
39
|
+
const client = new AcpClient(opts);
|
|
40
|
+
await client.start();
|
|
41
|
+
return client;
|
|
42
|
+
}
|
|
43
|
+
onSessionUpdate(handler) {
|
|
44
|
+
this.updateHandlers.add(handler);
|
|
45
|
+
return () => this.updateHandlers.delete(handler);
|
|
46
|
+
}
|
|
47
|
+
/** Install the answerer for permission round-trips (set once per session;
|
|
48
|
+
* per-turn context lives inside the handler's own closure). */
|
|
49
|
+
setPermissionHandler(handler) {
|
|
50
|
+
this.permissionHandler = handler;
|
|
51
|
+
}
|
|
52
|
+
/** Install the answerer for the agent's requests for user input. */
|
|
53
|
+
setElicitationHandler(handler) {
|
|
54
|
+
this.elicitationHandler = handler;
|
|
55
|
+
}
|
|
56
|
+
onClose(handler) {
|
|
57
|
+
this.closeHandlers.add(handler);
|
|
58
|
+
return () => this.closeHandlers.delete(handler);
|
|
59
|
+
}
|
|
60
|
+
get closed() {
|
|
61
|
+
return this.exited || this.connectionEnded;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Send a request to the agent (`initialize`, `session/new`, `session/prompt`, …).
|
|
65
|
+
* `timeoutMs` bounds the wait for handshake-style requests — a spawned-but-wedged
|
|
66
|
+
* agent must not stall the turn forever. The SDK's `cancellationSignal` is
|
|
67
|
+
* cooperative (the peer still decides when to respond), so the local race is
|
|
68
|
+
* what actually enforces the deadline. Turn-long requests (`session/prompt`)
|
|
69
|
+
* pass no timeout.
|
|
70
|
+
*/
|
|
71
|
+
async request(method, params, timeoutMs) {
|
|
72
|
+
if (!this.connection || this.exited)
|
|
73
|
+
throw this.exitError ?? new Error("acp agent not running");
|
|
74
|
+
try {
|
|
75
|
+
return await this.send(method, params, timeoutMs);
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
// Cut short by the agent's exit: say why it exited, not just that the
|
|
79
|
+
// connection closed. (The SDK marks the connection closed before it
|
|
80
|
+
// fails the requests it held.)
|
|
81
|
+
if (this.exited || this.connectionEnded)
|
|
82
|
+
throw (await this.whyExited()) ?? error;
|
|
83
|
+
throw error;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/** Why the agent exited, waiting briefly for its exit when the connection went first. */
|
|
87
|
+
async whyExited() {
|
|
88
|
+
if (!this.exitError && this.native)
|
|
89
|
+
await withTimeout(this.native.exited, EXIT_REASON_WAIT_MS);
|
|
90
|
+
return this.exitError;
|
|
91
|
+
}
|
|
92
|
+
async send(method, params, timeoutMs) {
|
|
93
|
+
if (!this.connection)
|
|
94
|
+
throw this.exitError ?? new Error("acp agent not running");
|
|
95
|
+
const agent = this.connection.agent;
|
|
96
|
+
if (!timeoutMs)
|
|
97
|
+
return agent.request(method, params);
|
|
98
|
+
const abort = new AbortController();
|
|
99
|
+
const answered = await withTimeout(agent.request(method, params, { cancellationSignal: abort.signal }), timeoutMs);
|
|
100
|
+
if (answered)
|
|
101
|
+
return answered.value;
|
|
102
|
+
abort.abort();
|
|
103
|
+
throw new Error(`acp agent '${method}' timed out after ${timeoutMs}ms`);
|
|
104
|
+
}
|
|
105
|
+
/** Send a notification to the agent (`session/cancel`). */
|
|
106
|
+
async notify(method, params) {
|
|
107
|
+
if (!this.connection || this.exited)
|
|
108
|
+
return;
|
|
109
|
+
await this.connection.agent.notify(method, params);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Settles once its process has exited after a close or its own exit, its
|
|
113
|
+
* tree stopped (bounded by the stop's grace and SIGKILL, LLP 0007); at
|
|
114
|
+
* once when no process was started or none is stopping.
|
|
115
|
+
*/
|
|
116
|
+
gone() {
|
|
117
|
+
return this.leaving ?? Promise.resolve();
|
|
118
|
+
}
|
|
119
|
+
close() {
|
|
120
|
+
const native = this.native;
|
|
121
|
+
const wasOpen = !this.exited;
|
|
122
|
+
this.exited = true;
|
|
123
|
+
this.native = undefined;
|
|
124
|
+
this.connection?.close();
|
|
125
|
+
this.connection = undefined;
|
|
126
|
+
if (native)
|
|
127
|
+
this.stop(native);
|
|
128
|
+
if (wasOpen)
|
|
129
|
+
this.notifyClosed();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* SIGTERM the agent's group and the tool sessions under it, and SIGKILL
|
|
133
|
+
* what is left after the grace. An agent that runs Claude through the SDK's
|
|
134
|
+
* own spawner keeps that `claude` in its group, which the SIGTERM reaches.
|
|
135
|
+
*/
|
|
136
|
+
stop(native) {
|
|
137
|
+
// `stop` never rejects, and every call shares one stop.
|
|
138
|
+
this.leaving = native.stop({ graceMs: KILL_GRACE_MS }).then(() => { });
|
|
139
|
+
}
|
|
140
|
+
async start() {
|
|
141
|
+
const acp = await import("@agentclientprotocol/sdk");
|
|
142
|
+
const { launch } = this.opts;
|
|
143
|
+
const native = this.opts.processes.spawn({
|
|
144
|
+
command: launch.command,
|
|
145
|
+
args: launch.args ?? [],
|
|
146
|
+
cwd: this.opts.cwd,
|
|
147
|
+
env: { ...process.env, ...launch.env, ...this.opts.env },
|
|
148
|
+
harness: "acp",
|
|
149
|
+
...(this.opts.sessionId !== undefined && { sessionId: this.opts.sessionId }),
|
|
150
|
+
});
|
|
151
|
+
this.native = native;
|
|
152
|
+
const proc = native.child;
|
|
153
|
+
if (!proc.stdin || !proc.stdout) {
|
|
154
|
+
this.stop(native);
|
|
155
|
+
throw new Error("acp agent subprocess has no stdio");
|
|
156
|
+
}
|
|
157
|
+
proc.on("error", (err) => this.onExit(err));
|
|
158
|
+
// Once its output closed, or a moment after its exit when a child it left
|
|
159
|
+
// running holds the pipes: its stderr's last lines usually say why.
|
|
160
|
+
void native.exited.then((exit) => this.onExit(exitedWith(exit, native.stderrTail)));
|
|
161
|
+
const stream = acp.ndJsonStream(Writable.toWeb(proc.stdin),
|
|
162
|
+
// Kept cast: some lib.dom versions type Readable.toWeb as
|
|
163
|
+
// ReadableStream<any>.
|
|
164
|
+
Readable.toWeb(proc.stdout));
|
|
165
|
+
this.connection = acp
|
|
166
|
+
.client({ name: this.opts.clientName ?? "agent-server" })
|
|
167
|
+
.onRequest("session/request_permission", async (ctx) => {
|
|
168
|
+
const handler = this.permissionHandler;
|
|
169
|
+
if (!handler)
|
|
170
|
+
return { outcome: { outcome: "cancelled" } };
|
|
171
|
+
return handler(ctx.params);
|
|
172
|
+
})
|
|
173
|
+
.onRequest("elicitation/create", async (ctx) => {
|
|
174
|
+
const handler = this.elicitationHandler;
|
|
175
|
+
if (!handler)
|
|
176
|
+
return { action: "decline" };
|
|
177
|
+
return handler(ctx.params);
|
|
178
|
+
})
|
|
179
|
+
.onNotification("session/update", (ctx) => {
|
|
180
|
+
for (const handler of this.updateHandlers)
|
|
181
|
+
handler(ctx.params);
|
|
182
|
+
})
|
|
183
|
+
.connect(stream);
|
|
184
|
+
// A closed connection without a process exit (stream error) still ends the
|
|
185
|
+
// client; a rejected `closed` must not become an unhandled rejection. The
|
|
186
|
+
// process's own exit usually follows at once and says why: let it.
|
|
187
|
+
const ended = async (error) => {
|
|
188
|
+
this.connectionEnded = true;
|
|
189
|
+
if (!(await withTimeout(native.exited, EXIT_REASON_WAIT_MS)))
|
|
190
|
+
this.onExit(error);
|
|
191
|
+
};
|
|
192
|
+
this.connection.closed.then(() => ended(new Error("acp connection closed")), (err) => ended(err instanceof Error ? err : new Error(`acp connection failed: ${err}`)));
|
|
193
|
+
}
|
|
194
|
+
onExit(error) {
|
|
195
|
+
this.exitError ??= error;
|
|
196
|
+
if (this.exited)
|
|
197
|
+
return;
|
|
198
|
+
this.exited = true;
|
|
199
|
+
// The connection can end while the process lives on: stop it.
|
|
200
|
+
if (this.native)
|
|
201
|
+
this.stop(this.native);
|
|
202
|
+
this.connection?.close(error);
|
|
203
|
+
this.connection = undefined;
|
|
204
|
+
this.notifyClosed(error);
|
|
205
|
+
}
|
|
206
|
+
notifyClosed(error) {
|
|
207
|
+
for (const handler of this.closeHandlers)
|
|
208
|
+
handler(error);
|
|
209
|
+
this.closeHandlers.clear();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Why the agent exited: its code, and the last lines of its stderr. */
|
|
213
|
+
function exitedWith({ code, signal }, stderr) {
|
|
214
|
+
const reason = stderr
|
|
215
|
+
.split("\n")
|
|
216
|
+
.map((line) => line.trim())
|
|
217
|
+
.filter(Boolean)
|
|
218
|
+
.slice(-REASON_LINES)
|
|
219
|
+
.join(" | ")
|
|
220
|
+
.slice(-REASON_MAX);
|
|
221
|
+
return new AgentExitedError(`acp agent exited (code=${code} signal=${signal})${reason ? `: ${reason}` : ""}`);
|
|
222
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { isAgentHarness } from "../../../protocol/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Advisory catalog of well-known ACP agents — UX sugar, not wire vocabulary
|
|
4
|
+
* (like the model catalog). On the wire the harness is always `acp`; these names
|
|
5
|
+
* let entry points offer "pi" or "gemini" as first-class choices and expand
|
|
6
|
+
* them to launch commands at the operator edge. Anything not listed here runs
|
|
7
|
+
* via an explicit launch command — any ACP-compatible agent works.
|
|
8
|
+
*/
|
|
9
|
+
export const KNOWN_ACP_AGENTS = {
|
|
10
|
+
pi: {
|
|
11
|
+
label: "pi.dev (Pi coding agent, via the pi-acp adapter)",
|
|
12
|
+
// Pinned: an unpinned `npx -y` runs whatever was published last, unreviewed.
|
|
13
|
+
// Bump after checking the new release.
|
|
14
|
+
launch: { command: "npx", args: ["-y", "pi-acp@0.0.34"] },
|
|
15
|
+
},
|
|
16
|
+
gemini: {
|
|
17
|
+
label: "Gemini CLI (native ACP mode)",
|
|
18
|
+
launch: { command: "gemini", args: ["--acp"] },
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Parse an operator-supplied launch spec (`"npx -y pi-acp"`) into an AcpLaunch.
|
|
23
|
+
* Naive whitespace split — no shell quoting; env vars come from the caller.
|
|
24
|
+
* The canonical parser for `--acp-agent` flags / `$AGENT_SERVER_ACP_AGENT`.
|
|
25
|
+
*/
|
|
26
|
+
export function parseAcpLaunch(spec) {
|
|
27
|
+
const [command, ...args] = spec?.trim().split(/\s+/).filter(Boolean) ?? [];
|
|
28
|
+
if (!command)
|
|
29
|
+
return undefined;
|
|
30
|
+
return { command, ...(args.length && { args }) };
|
|
31
|
+
}
|
|
32
|
+
/** A catalog entry by its own name; never one inherited from `Object.prototype`. */
|
|
33
|
+
function knownAgent(name) {
|
|
34
|
+
return Object.hasOwn(KNOWN_ACP_AGENTS, name) ? KNOWN_ACP_AGENTS[name] : undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Read a harness name typed at an operator edge (`--harness`, the CLI's
|
|
38
|
+
* `/harness`): a harness, or a known ACP agent's name, which rides the `acp`
|
|
39
|
+
* harness. Undefined for anything else.
|
|
40
|
+
*/
|
|
41
|
+
export function resolveHarnessName(name) {
|
|
42
|
+
if (isAgentHarness(name))
|
|
43
|
+
return { harness: name };
|
|
44
|
+
if (knownAgent(name))
|
|
45
|
+
return { harness: "acp", acpAgent: name };
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolve an operator spec that is either a known agent name (`"pi"`) or a
|
|
50
|
+
* raw launch command (`"npx -y pi-acp"`). The canonical resolver behind
|
|
51
|
+
* `--acp-agent` and `$AGENT_SERVER_ACP_AGENT`.
|
|
52
|
+
*/
|
|
53
|
+
export function resolveAcpLaunch(spec) {
|
|
54
|
+
if (!spec)
|
|
55
|
+
return undefined;
|
|
56
|
+
return knownAgent(spec.trim())?.launch ?? parseAcpLaunch(spec);
|
|
57
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { TOOL_KINDS } from "../../../protocol/index.js";
|
|
2
|
+
import { isRecord } from "../../utils/is-record.js";
|
|
3
|
+
import { UnsupportedAttachmentError, attachedText, inlineTextAttachment, isTextMedia, } from "../attachments.js";
|
|
4
|
+
/**
|
|
5
|
+
* The single bridge between ACP's vocabulary and the engine's. Everything here
|
|
6
|
+
* is a pure conversion shared by the agent (outbound requests, permission
|
|
7
|
+
* round-trips) and the adapter (inbound session updates) — the harness
|
|
8
|
+
* seat's single bridge, so its two halves cannot drift. (The ACP *server*
|
|
9
|
+
* binding in src/server/acp/ is the inverse direction, not a copy.)
|
|
10
|
+
*/
|
|
11
|
+
// @ref LLP 0001#d2--acp-supplies-the-vocabulary-wherever-concepts-overlap — ACP's names, so bridges pass through
|
|
12
|
+
/** ACP's ToolKind strings are ours verbatim; narrow with a membership check. */
|
|
13
|
+
export function toolKindOf(kind) {
|
|
14
|
+
return kind && TOOL_KINDS.includes(kind) ? kind : undefined;
|
|
15
|
+
}
|
|
16
|
+
/** ACP `ToolCallLocation[]` → engine `ToolLocation[]` (drop null lines, empty → absent). */
|
|
17
|
+
export function toToolLocations(locations) {
|
|
18
|
+
if (!locations?.length)
|
|
19
|
+
return undefined;
|
|
20
|
+
return locations.map((l) => ({ path: l.path, ...(l.line != null && { line: l.line }) }));
|
|
21
|
+
}
|
|
22
|
+
// @ref LLP 0002#tool-output-has-three-audiences — an agent's diff and terminal are display content
|
|
23
|
+
/**
|
|
24
|
+
* The display content of an ACP tool call: its `diff` entries (a creation's
|
|
25
|
+
* null `oldText` left out) and its `terminal`s, as the agent sent them. Text
|
|
26
|
+
* is the call's `output`, so it is not repeated here.
|
|
27
|
+
*/
|
|
28
|
+
export function toToolResultContent(content) {
|
|
29
|
+
return (content ?? []).flatMap((item) => {
|
|
30
|
+
if (item.type === "diff")
|
|
31
|
+
return [
|
|
32
|
+
{
|
|
33
|
+
type: "diff",
|
|
34
|
+
path: item.path,
|
|
35
|
+
...(item.oldText != null && { oldText: item.oldText }),
|
|
36
|
+
newText: item.newText,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
if (item.type === "terminal")
|
|
40
|
+
return [{ type: "terminal", terminalId: item.terminalId }];
|
|
41
|
+
return [];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** Engine MCP config map → ACP `McpServer[]` (names come from the record keys). */
|
|
45
|
+
export function toAcpMcpServers(mcpServers) {
|
|
46
|
+
if (!mcpServers)
|
|
47
|
+
return [];
|
|
48
|
+
return Object.entries(mcpServers).map(([name, config]) => {
|
|
49
|
+
if (config.type === "stdio") {
|
|
50
|
+
return {
|
|
51
|
+
name,
|
|
52
|
+
command: config.command,
|
|
53
|
+
args: config.args ?? [],
|
|
54
|
+
env: Object.entries(config.env ?? {}).map(([n, value]) => ({ name: n, value })),
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
type: config.type,
|
|
59
|
+
name,
|
|
60
|
+
url: config.url,
|
|
61
|
+
headers: Object.entries(config.headers ?? {}).map(([n, value]) => ({ name: n, value })),
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Engine turn input → ACP prompt content blocks. Every agent takes text and
|
|
67
|
+
* resource links; image data needs the `image` capability and inline files
|
|
68
|
+
* `embeddedContext`. A text file falls back to prompt text, and anything else
|
|
69
|
+
* the agent cannot take fails the turn instead of vanishing.
|
|
70
|
+
*/
|
|
71
|
+
export function toPromptBlocks(input, prompt) {
|
|
72
|
+
if (typeof input === "string")
|
|
73
|
+
return [{ type: "text", text: input }];
|
|
74
|
+
const blocks = [];
|
|
75
|
+
for (const part of input) {
|
|
76
|
+
if (part.type === "text") {
|
|
77
|
+
blocks.push({ type: "text", text: part.text });
|
|
78
|
+
}
|
|
79
|
+
else if (part.url !== undefined) {
|
|
80
|
+
const name = (part.type === "file" && part.filename) || part.url;
|
|
81
|
+
blocks.push({ type: "resource_link", uri: part.url, name, mimeType: part.mimeType });
|
|
82
|
+
}
|
|
83
|
+
else if (part.type === "image") {
|
|
84
|
+
if (!prompt.image)
|
|
85
|
+
throw new UnsupportedAttachmentError("This ACP agent does not accept images");
|
|
86
|
+
blocks.push({ type: "image", data: part.data ?? "", mimeType: part.mimeType });
|
|
87
|
+
}
|
|
88
|
+
else if (prompt.embeddedContext) {
|
|
89
|
+
const uri = `attachment:${encodeURIComponent(part.filename ?? "file")}`;
|
|
90
|
+
const data = part.data ?? "";
|
|
91
|
+
blocks.push({
|
|
92
|
+
type: "resource",
|
|
93
|
+
resource: isTextMedia(part.mimeType)
|
|
94
|
+
? { uri, mimeType: part.mimeType, text: attachedText(data) }
|
|
95
|
+
: { uri, mimeType: part.mimeType, blob: data },
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
else if (isTextMedia(part.mimeType)) {
|
|
99
|
+
blocks.push({ type: "text", text: inlineTextAttachment({ ...part, data: part.data ?? "" }) });
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
throw new UnsupportedAttachmentError(`This ACP agent cannot take ${part.mimeType} file attachments`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return blocks.length ? blocks : [{ type: "text", text: "" }];
|
|
106
|
+
}
|
|
107
|
+
/** ACP permission request → the engine's PermissionToolCall (SDK-validated, no casts). */
|
|
108
|
+
export function permissionToolCall(request) {
|
|
109
|
+
const toolCall = request.toolCall;
|
|
110
|
+
const kind = toolKindOf(toolCall.kind);
|
|
111
|
+
const locations = toToolLocations(toolCall.locations);
|
|
112
|
+
return {
|
|
113
|
+
...(toolCall.toolCallId && { toolCallId: toolCall.toolCallId }),
|
|
114
|
+
// No `mcp`: an ACP agent names its tools by no rule, so no server or tool can be read from it.
|
|
115
|
+
toolName: toolCall.name ?? toolCall.title ?? toolCall.kind ?? "tool",
|
|
116
|
+
...(kind && { kind }),
|
|
117
|
+
...(toolCall.title && { title: toolCall.title }),
|
|
118
|
+
...(locations && { locations }),
|
|
119
|
+
...(isRecord(toolCall.rawInput) && { rawInput: toolCall.rawInput }),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export const CANCELLED_OUTCOME = {
|
|
123
|
+
outcome: { outcome: "cancelled" },
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Pick the option matching the decision: allow → `allow_once` only, deny →
|
|
127
|
+
* `reject_once`, else `reject_always`; no matching option → cancelled. An
|
|
128
|
+
* allow never selects `allow_always`: that would leave a standing rule in the
|
|
129
|
+
* agent nobody chose, and the engine already keeps the user's own "always"
|
|
130
|
+
* answers.
|
|
131
|
+
*/
|
|
132
|
+
export function chooseOutcome(options, allow) {
|
|
133
|
+
const kinds = allow ? ["allow_once"] : ["reject_once", "reject_always"];
|
|
134
|
+
for (const kind of kinds) {
|
|
135
|
+
const match = options.find((o) => o.kind === kind);
|
|
136
|
+
if (match)
|
|
137
|
+
return { outcome: { outcome: "selected", optionId: match.optionId } };
|
|
138
|
+
}
|
|
139
|
+
return CANCELLED_OUTCOME;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Decide an ACP permission request without the engine broker: mirrors the
|
|
143
|
+
* codex posture where only `default` mode asks — every other mode auto-decides.
|
|
144
|
+
*/
|
|
145
|
+
export function autoDecide(request, mode) {
|
|
146
|
+
const kind = request.toolCall.kind;
|
|
147
|
+
const allowed = mode === "bypass_permissions" ||
|
|
148
|
+
(mode === "accept_edits" && (kind === "edit" || kind === "read"));
|
|
149
|
+
return chooseOutcome(request.options, allowed);
|
|
150
|
+
}
|
|
151
|
+
/** An ACP mode id the engine has a name for: its own, or Claude's (claude-agent-acp). */
|
|
152
|
+
export function permissionModeOf(modeId) {
|
|
153
|
+
const known = {
|
|
154
|
+
default: "default",
|
|
155
|
+
plan: "plan",
|
|
156
|
+
acceptEdits: "accept_edits",
|
|
157
|
+
accept_edits: "accept_edits",
|
|
158
|
+
dontAsk: "dont_ask",
|
|
159
|
+
dont_ask: "dont_ask",
|
|
160
|
+
bypassPermissions: "bypass_permissions",
|
|
161
|
+
bypass_permissions: "bypass_permissions",
|
|
162
|
+
};
|
|
163
|
+
return Object.hasOwn(known, modeId) ? known[modeId] : undefined;
|
|
164
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { inputReply, inputRequest } from "../elicitation.js";
|
|
2
|
+
import { CANCELLED_OUTCOME, autoDecide, chooseOutcome, permissionModeOf, permissionToolCall, } from "./mappings.js";
|
|
3
|
+
/** Answer an agent permission request against the session's current turn. */
|
|
4
|
+
export async function answerPermission(scope, request) {
|
|
5
|
+
if (request.sessionId !== scope.acpSessionId)
|
|
6
|
+
return CANCELLED_OUTCOME;
|
|
7
|
+
const turn = scope.turn;
|
|
8
|
+
// @ref LLP 0001#d4--permission-requests-are-first-class-protocol — a plan's approval picks the mode
|
|
9
|
+
// Leaving a mode (claude-agent-acp's plan approval) is the user's choice,
|
|
10
|
+
// from the agent's own options, in any mode that asks: they say how it
|
|
11
|
+
// goes on. A turn that never asks (`dont_ask`, `bypass_permissions`)
|
|
12
|
+
// decides it as before; other requests ask only in `default`.
|
|
13
|
+
const plan = request.toolCall.kind === "switch_mode" &&
|
|
14
|
+
turn?.mode !== "dont_ask" &&
|
|
15
|
+
turn?.mode !== "bypass_permissions";
|
|
16
|
+
if (!turn?.broker || !(plan || (turn.mode ?? "default") === "default")) {
|
|
17
|
+
return autoDecide(request, turn?.mode);
|
|
18
|
+
}
|
|
19
|
+
const decision = await turn.broker(permissionToolCall(request), {
|
|
20
|
+
signal: turn.signal,
|
|
21
|
+
...(plan && {
|
|
22
|
+
options: request.options.map(({ optionId, name, kind }) => ({ optionId, name, kind })),
|
|
23
|
+
}),
|
|
24
|
+
});
|
|
25
|
+
if (decision.decision === "cancel")
|
|
26
|
+
return CANCELLED_OUTCOME;
|
|
27
|
+
// `decision.updatedInput` is unrepresentable here: ACP v1's outcome carries
|
|
28
|
+
// an optionId and nothing else, so an edited input cannot be honoured — and
|
|
29
|
+
// silently running the ORIGINAL is exactly what the field exists to prevent.
|
|
30
|
+
// An edited approval therefore DENIES: the broker authorized a call this
|
|
31
|
+
// protocol cannot deliver. (The claude-code harness, via canUseTool, is the
|
|
32
|
+
// one that can execute the edit.)
|
|
33
|
+
if (decision.decision === "allow" && decision.updatedInput !== undefined) {
|
|
34
|
+
return chooseOutcome(request.options, false);
|
|
35
|
+
}
|
|
36
|
+
const picked = plan ? request.options.find((o) => o.optionId === decision.optionId) : undefined;
|
|
37
|
+
// A plain allow or reject: a tool's request, or a client that answered a
|
|
38
|
+
// plan with the standard ids.
|
|
39
|
+
const outcome = picked
|
|
40
|
+
? { outcome: { outcome: "selected", optionId: picked.optionId } }
|
|
41
|
+
: chooseOutcome(request.options, decision.decision === "allow");
|
|
42
|
+
if (plan && decision.decision === "allow")
|
|
43
|
+
adoptMode(scope, turn, outcome);
|
|
44
|
+
return outcome;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The agent left plan mode in the mode the user approved: the rest of the turn
|
|
48
|
+
* decides the agent's requests in it, as the agent now runs (never raised to
|
|
49
|
+
* bypassing permissions).
|
|
50
|
+
*/
|
|
51
|
+
function adoptMode(scope, turn, outcome) {
|
|
52
|
+
const picked = outcome.outcome.outcome === "selected" ? outcome.outcome.optionId : undefined;
|
|
53
|
+
const mode = picked === undefined ? undefined : permissionModeOf(picked);
|
|
54
|
+
if (!mode || mode === "bypass_permissions" || mode === "plan" || scope.turn !== turn)
|
|
55
|
+
return;
|
|
56
|
+
scope.turn = { ...turn, mode };
|
|
57
|
+
}
|
|
58
|
+
/** Answer an agent's request for user input against the session's current turn. */
|
|
59
|
+
export async function answerElicitation(scope, request) {
|
|
60
|
+
// The SDK's open request union types neither its scope nor a known mode's fields.
|
|
61
|
+
const scoped = request;
|
|
62
|
+
if (scoped.sessionId !== undefined && scoped.sessionId !== scope.acpSessionId) {
|
|
63
|
+
return { action: "decline" };
|
|
64
|
+
}
|
|
65
|
+
const turn = scope.turn;
|
|
66
|
+
const mode = request.mode;
|
|
67
|
+
if (!turn?.elicitation || (mode !== "form" && mode !== "url"))
|
|
68
|
+
return { action: "decline" };
|
|
69
|
+
const fields = request;
|
|
70
|
+
const outcome = await turn.elicitation(inputRequest({
|
|
71
|
+
mode,
|
|
72
|
+
message: request.message,
|
|
73
|
+
toolCallId: scoped.toolCallId ?? undefined,
|
|
74
|
+
requestedSchema: fields.requestedSchema,
|
|
75
|
+
url: fields.url,
|
|
76
|
+
elicitationId: fields.elicitationId,
|
|
77
|
+
}), { signal: turn.signal });
|
|
78
|
+
return inputReply(outcome);
|
|
79
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fileKind } from "../../protocol/index.js";
|
|
2
|
+
export { UnsupportedAttachmentError } from "../utils/errors.js";
|
|
3
|
+
/** A media type a model reads as text when a file arrives inline. */
|
|
4
|
+
export function isTextMedia(mimeType) {
|
|
5
|
+
return fileKind(mimeType) === "text";
|
|
6
|
+
}
|
|
7
|
+
/** The content of a text file attached as base64 data. */
|
|
8
|
+
export function attachedText(data) {
|
|
9
|
+
return Buffer.from(data, "base64").toString("utf8");
|
|
10
|
+
}
|
|
11
|
+
/** A text file as prompt text, for a harness with no file input of its own. */
|
|
12
|
+
export function inlineTextAttachment(part) {
|
|
13
|
+
return `Attached file${part.filename ? ` ${part.filename}` : ""}:\n\n${attachedText(part.data)}`;
|
|
14
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { onAbort } from "../utils/deadline.js";
|
|
2
|
+
/**
|
|
3
|
+
* How long a cancel waits for the harness to show its turn stopped before it
|
|
4
|
+
* answers `confirmed: false`, unless `cancelConfirmMs` says otherwise. One
|
|
5
|
+
* value for every built-in harness.
|
|
6
|
+
*/
|
|
7
|
+
export const CANCEL_CONFIRM_MS = 2_000;
|
|
8
|
+
export class BaseAgent {
|
|
9
|
+
/**
|
|
10
|
+
* In-flight turn controllers per logical sessionId. A set (not a single
|
|
11
|
+
* controller) so overlapping turns on one session can't clobber each other's
|
|
12
|
+
* cancellation — `cancel(sessionId)` aborts all of them, and `endTurn`
|
|
13
|
+
* removes only the specific controller it created.
|
|
14
|
+
*/
|
|
15
|
+
inflight = new Map();
|
|
16
|
+
unlinkAbort = new WeakMap();
|
|
17
|
+
async cancel(sessionId) {
|
|
18
|
+
const controllers = this.inflight.get(sessionId);
|
|
19
|
+
const hadTurn = (controllers?.size ?? 0) > 0;
|
|
20
|
+
for (const controller of controllers ?? [])
|
|
21
|
+
controller.abort();
|
|
22
|
+
// Idle sessions are a clean no-op ack, and the abort signal
|
|
23
|
+
// deterministically ends the engine's execute loop for tracked turns —
|
|
24
|
+
// both confirmed. `SessionAgent` answers for a harness whose backend
|
|
25
|
+
// has a stop of its own to confirm.
|
|
26
|
+
return { confirmed: true, hadTurn };
|
|
27
|
+
}
|
|
28
|
+
async release(sessionId) {
|
|
29
|
+
await this.cancel(sessionId);
|
|
30
|
+
this.inflight.delete(sessionId);
|
|
31
|
+
}
|
|
32
|
+
async terminateAll() {
|
|
33
|
+
for (const set of this.inflight.values()) {
|
|
34
|
+
for (const controller of set)
|
|
35
|
+
controller.abort();
|
|
36
|
+
}
|
|
37
|
+
this.inflight.clear();
|
|
38
|
+
}
|
|
39
|
+
/** Create a per-turn controller bound to `sessionId`, optionally chained to an external signal. */
|
|
40
|
+
trackTurn(sessionId, external) {
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
let set = this.inflight.get(sessionId);
|
|
43
|
+
if (!set) {
|
|
44
|
+
set = new Set();
|
|
45
|
+
this.inflight.set(sessionId, set);
|
|
46
|
+
}
|
|
47
|
+
set.add(controller);
|
|
48
|
+
if (external) {
|
|
49
|
+
const unlink = onAbort(external, () => controller.abort());
|
|
50
|
+
this.unlinkAbort.set(controller, unlink);
|
|
51
|
+
}
|
|
52
|
+
return controller;
|
|
53
|
+
}
|
|
54
|
+
endTurn(sessionId, controller) {
|
|
55
|
+
// release/terminateAll may already have removed the set while the turn
|
|
56
|
+
// was draining. Its external signal must still be detached on completion.
|
|
57
|
+
this.unlinkAbort.get(controller)?.();
|
|
58
|
+
this.unlinkAbort.delete(controller);
|
|
59
|
+
const set = this.inflight.get(sessionId);
|
|
60
|
+
set?.delete(controller);
|
|
61
|
+
if (set?.size === 0)
|
|
62
|
+
this.inflight.delete(sessionId);
|
|
63
|
+
}
|
|
64
|
+
}
|