@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,209 @@
|
|
|
1
|
+
import { withTimeout } from "../utils/deadline.js";
|
|
2
|
+
import { SessionResumeError, TurnActiveError } from "../utils/errors.js";
|
|
3
|
+
import { BaseAgent, CANCEL_CONFIRM_MS, } from "./base.js";
|
|
4
|
+
import { configFingerprint } from "./config-fingerprint.js";
|
|
5
|
+
/**
|
|
6
|
+
* The execution lifecycle the engine's own harnesses extend: one turn owns a
|
|
7
|
+
* logical session from preparation through native cleanup, with steering,
|
|
8
|
+
* the conversation it resumes and the answer to its cancel. It is not
|
|
9
|
+
* exported while its design is a Draft (LLP 0016); a product's own harness
|
|
10
|
+
* extends `BaseAgent`, the public base.
|
|
11
|
+
*/
|
|
12
|
+
export class SessionAgent extends BaseAgent {
|
|
13
|
+
terminated = false;
|
|
14
|
+
/**
|
|
15
|
+
* The turn each session executes. Cancel/release can return before
|
|
16
|
+
* execution drains; only finally relinquishes ownership.
|
|
17
|
+
*/
|
|
18
|
+
running = new Map();
|
|
19
|
+
/** Conversation identity outlives subprocess eviction and failed startup. */
|
|
20
|
+
conversations = new Map();
|
|
21
|
+
/** The running turn's input, per session. */
|
|
22
|
+
steering = new Map();
|
|
23
|
+
/** The last turn each session executed: a steer for it comes too late. */
|
|
24
|
+
executed = new Map();
|
|
25
|
+
cancelConfirmMs;
|
|
26
|
+
constructor(options = {}) {
|
|
27
|
+
super();
|
|
28
|
+
this.cancelConfirmMs = options.cancelConfirmMs ?? CANCEL_CONFIRM_MS;
|
|
29
|
+
}
|
|
30
|
+
async *execute(input, options) {
|
|
31
|
+
const { sessionId } = options;
|
|
32
|
+
if (this.terminated)
|
|
33
|
+
throw new Error("Agent has been terminated");
|
|
34
|
+
if (options.subagentMode && !this.capabilities.turnScopedSubagents) {
|
|
35
|
+
throw new Error(`${this.harness} does not support turn-scoped subagents`);
|
|
36
|
+
}
|
|
37
|
+
if (this.running.has(sessionId))
|
|
38
|
+
throw new TurnActiveError(sessionId);
|
|
39
|
+
let end = () => { };
|
|
40
|
+
const ended = new Promise((resolve) => {
|
|
41
|
+
end = resolve;
|
|
42
|
+
});
|
|
43
|
+
this.running.set(sessionId, { turnId: options.turnId, ended });
|
|
44
|
+
const controller = this.trackTurn(sessionId, options.signal);
|
|
45
|
+
// Steers sent since the runtime admitted this turn wait in its record.
|
|
46
|
+
const waiting = this.steering.get(sessionId);
|
|
47
|
+
const steering = {
|
|
48
|
+
turnId: options.turnId,
|
|
49
|
+
signal: controller.signal,
|
|
50
|
+
early: waiting?.turnId === options.turnId ? waiting.early : [],
|
|
51
|
+
};
|
|
52
|
+
this.steering.set(sessionId, steering);
|
|
53
|
+
try {
|
|
54
|
+
// The adapter still produces its native cancellation result for an
|
|
55
|
+
// already-aborted turn. It must not select a conversation or do setup.
|
|
56
|
+
const prepared = controller.signal.aborted ? options : this.prepareSessionOptions(options);
|
|
57
|
+
yield* this.executeTurn(input, prepared, controller);
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
this.executed.set(sessionId, options.turnId);
|
|
61
|
+
if (this.steering.get(sessionId) === steering)
|
|
62
|
+
this.steering.delete(sessionId);
|
|
63
|
+
this.endTurn(sessionId, controller);
|
|
64
|
+
this.running.delete(sessionId);
|
|
65
|
+
end();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// @ref LLP 0016.000#the-cancel-answer — one cancel answer, the harness says how its turn stops
|
|
69
|
+
/**
|
|
70
|
+
* Abort the session's turn, and answer whether it stopped within
|
|
71
|
+
* `cancelConfirmMs`: as its stop says (`cancelWith`), or, while it has
|
|
72
|
+
* none, by its end. A cancel while another is in flight shares its answer;
|
|
73
|
+
* one after it asks again, with a window of its own. With no turn, what
|
|
74
|
+
* the harness still has to stop (`stopWithoutTurn`) decides; with nothing
|
|
75
|
+
* to stop it is confirmed.
|
|
76
|
+
*/
|
|
77
|
+
async cancel(sessionId) {
|
|
78
|
+
const turn = this.running.get(sessionId);
|
|
79
|
+
await super.cancel(sessionId);
|
|
80
|
+
if (!turn) {
|
|
81
|
+
const stopping = this.stopWithoutTurn(sessionId);
|
|
82
|
+
return { confirmed: stopping ? await this.confirmed(stopping) : true, hadTurn: false };
|
|
83
|
+
}
|
|
84
|
+
turn.cancelling ??= this.confirmed(turn.stop ? turn.stop() : turn.ended.then(() => true)).finally(() => {
|
|
85
|
+
turn.cancelling = undefined;
|
|
86
|
+
});
|
|
87
|
+
return { confirmed: await turn.cancelling, hadTurn: true };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* How the turn stops for a cancel (`StopTurn`), from when it has a native
|
|
91
|
+
* stop to send. A cancel calls it once it aborted the turn; until a turn
|
|
92
|
+
* registers one, its cancel is confirmed by the turn's end.
|
|
93
|
+
*/
|
|
94
|
+
cancelWith(options, stop) {
|
|
95
|
+
const turn = this.running.get(options.sessionId);
|
|
96
|
+
if (turn?.turnId === options.turnId)
|
|
97
|
+
turn.stop = stop;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What a cancel with no turn running still has to stop, if anything:
|
|
101
|
+
* whether that stopped. Nothing by default.
|
|
102
|
+
*/
|
|
103
|
+
stopWithoutTurn(_sessionId) {
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
async confirmed(stopped) {
|
|
107
|
+
const answer = await withTimeout(stopped.catch(() => false), this.cancelConfirmMs);
|
|
108
|
+
return answer?.value === true;
|
|
109
|
+
}
|
|
110
|
+
// @ref LLP 0001#d13--input-while-a-turn-runs-steers-it — held until the native turn takes it
|
|
111
|
+
/**
|
|
112
|
+
* Steer the session's turn. The runtime steers only a turn it admitted, so
|
|
113
|
+
* a steer for a turn not executing yet waits for it; until the native turn
|
|
114
|
+
* can take input (`openSteering`) steers wait in order. A cancelled turn, or
|
|
115
|
+
* a turn other than the one executing, takes none.
|
|
116
|
+
*/
|
|
117
|
+
async steer(sessionId, request) {
|
|
118
|
+
const turn = this.steering.get(sessionId);
|
|
119
|
+
if (turn?.signal && (turn.turnId !== request.turnId || turn.signal.aborted)) {
|
|
120
|
+
return "no_active_turn";
|
|
121
|
+
}
|
|
122
|
+
if (this.executed.get(sessionId) === request.turnId)
|
|
123
|
+
return "no_active_turn";
|
|
124
|
+
this.checkSteerInput(request.input);
|
|
125
|
+
if (!turn || turn.turnId !== request.turnId) {
|
|
126
|
+
this.steering.set(sessionId, { turnId: request.turnId, early: [request] });
|
|
127
|
+
return "steered";
|
|
128
|
+
}
|
|
129
|
+
if (!turn.deliver) {
|
|
130
|
+
turn.early.push(request);
|
|
131
|
+
return "steered";
|
|
132
|
+
}
|
|
133
|
+
return await turn.deliver(request);
|
|
134
|
+
}
|
|
135
|
+
/** Throw for steer input this harness cannot take, as a turn's input would. */
|
|
136
|
+
checkSteerInput(_input) { }
|
|
137
|
+
/**
|
|
138
|
+
* The native turn takes input now: deliver the steers that came before it,
|
|
139
|
+
* in order, then every later one as it comes. A steer the turn refuses stays
|
|
140
|
+
* undelivered, and `turn.ended` says so.
|
|
141
|
+
*/
|
|
142
|
+
async openSteering(options, deliver) {
|
|
143
|
+
const turn = this.steering.get(options.sessionId);
|
|
144
|
+
if (!turn || turn.turnId !== options.turnId)
|
|
145
|
+
return;
|
|
146
|
+
// A cancelled turn reads nothing more: its early steers stay undelivered.
|
|
147
|
+
if (turn.signal?.aborted)
|
|
148
|
+
return;
|
|
149
|
+
while (turn.early.length > 0) {
|
|
150
|
+
const request = turn.early.shift();
|
|
151
|
+
try {
|
|
152
|
+
await deliver(request);
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// Undelivered; the turn's end reports it.
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
turn.deliver = deliver;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The native turn takes no more input: it ended, and another may follow in
|
|
162
|
+
* the same turn (Codex implementing an approved plan). Steers wait for the
|
|
163
|
+
* next `openSteering`, or the turn's end lists them undelivered.
|
|
164
|
+
*/
|
|
165
|
+
holdSteering(options) {
|
|
166
|
+
const turn = this.steering.get(options.sessionId);
|
|
167
|
+
if (turn?.turnId === options.turnId)
|
|
168
|
+
turn.deliver = undefined;
|
|
169
|
+
}
|
|
170
|
+
prepareSessionOptions(options) {
|
|
171
|
+
const boundary = configFingerprint({
|
|
172
|
+
cwd: options.cwd,
|
|
173
|
+
env: options.env,
|
|
174
|
+
apiKey: options.apiKey,
|
|
175
|
+
});
|
|
176
|
+
const previous = this.conversations.get(options.sessionId);
|
|
177
|
+
if (!options.resumeSessionId && previous?.id && previous.boundary !== boundary) {
|
|
178
|
+
throw new SessionResumeError(previous.id, "working directory or credentials changed; explicitly provide resumeSessionId to continue, or use a new sessionId for a new conversation");
|
|
179
|
+
}
|
|
180
|
+
const resumeSessionId = options.resumeSessionId ?? previous?.id;
|
|
181
|
+
// Remember intent before setup: a failed retry must keep targeting the same history.
|
|
182
|
+
const selection = { id: resumeSessionId, boundary };
|
|
183
|
+
this.conversations.set(options.sessionId, selection);
|
|
184
|
+
return {
|
|
185
|
+
...options,
|
|
186
|
+
resumeSessionId,
|
|
187
|
+
onNativeSession: (id, info) => {
|
|
188
|
+
if (this.conversations.get(options.sessionId) !== selection) {
|
|
189
|
+
throw new SessionResumeError(resumeSessionId ?? id, "session was released while this turn was preparing");
|
|
190
|
+
}
|
|
191
|
+
selection.id = id;
|
|
192
|
+
options.onNativeSession?.(id, info);
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
async release(sessionId) {
|
|
197
|
+
this.conversations.delete(sessionId);
|
|
198
|
+
this.steering.delete(sessionId);
|
|
199
|
+
this.executed.delete(sessionId);
|
|
200
|
+
await super.release(sessionId);
|
|
201
|
+
}
|
|
202
|
+
async terminateAll() {
|
|
203
|
+
this.terminated = true;
|
|
204
|
+
this.conversations.clear();
|
|
205
|
+
this.steering.clear();
|
|
206
|
+
this.executed.clear();
|
|
207
|
+
await super.terminateAll();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { StringDecoder } from "node:string_decoder";
|
|
2
|
+
/**
|
|
3
|
+
* The end of an agent subprocess's stderr: the only place a CLI says why it
|
|
4
|
+
* cannot run (a missing login, a bad flag), so its exit error carries it.
|
|
5
|
+
* Decoded across chunk boundaries, and bounded: the CLI's own error, never a
|
|
6
|
+
* log flood. What it gives is redacted (`redactSecrets`): it becomes part of
|
|
7
|
+
* an error, which the stream, the journal and every log carry.
|
|
8
|
+
*/
|
|
9
|
+
export class StderrTail {
|
|
10
|
+
max;
|
|
11
|
+
/** Twice the bound, so that a secret the cut would split is redacted whole first. */
|
|
12
|
+
tail = "";
|
|
13
|
+
decoder = new StringDecoder("utf8");
|
|
14
|
+
constructor(max) {
|
|
15
|
+
this.max = max;
|
|
16
|
+
}
|
|
17
|
+
/** Add a chunk. Returns the tail with it, unredacted, before the tail is cut to size. */
|
|
18
|
+
write(chunk) {
|
|
19
|
+
const text = this.tail + this.decoder.write(chunk);
|
|
20
|
+
this.tail = text.slice(-2 * this.max);
|
|
21
|
+
return text;
|
|
22
|
+
}
|
|
23
|
+
/** Once the stream closed: its last flush, which usually says why. */
|
|
24
|
+
end() {
|
|
25
|
+
this.tail = (this.tail + this.decoder.end()).slice(-2 * this.max);
|
|
26
|
+
return this.text;
|
|
27
|
+
}
|
|
28
|
+
/** The last `max` characters, redacted before the cut. */
|
|
29
|
+
get text() {
|
|
30
|
+
return redactSecrets(this.tail).slice(-this.max);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** What a secret's place reads once it is taken out. */
|
|
34
|
+
const REDACTED = "[REDACTED]";
|
|
35
|
+
/**
|
|
36
|
+
* What a CLI may print that must not reach an error: the stream, the journal
|
|
37
|
+
* and every log carry an exit error's words. Each family, then what of it is
|
|
38
|
+
* replaced; what surrounds a secret is kept.
|
|
39
|
+
*/
|
|
40
|
+
const SECRETS = [
|
|
41
|
+
// Anthropic API keys and OAuth tokens (`sk-ant-api03-…`, `sk-ant-oat01-…`).
|
|
42
|
+
[/\bsk-ant-[A-Za-z0-9_-]{8,}/g, REDACTED],
|
|
43
|
+
// OpenAI keys (`sk-…`, `sk-proj-…`).
|
|
44
|
+
[/\bsk-[A-Za-z0-9_-]{20,}/g, REDACTED],
|
|
45
|
+
// JWTs: three base64url segments, the first a JSON header.
|
|
46
|
+
[/\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g, REDACTED],
|
|
47
|
+
// HTTP credentials: the scheme stays, a credential of 20 or more characters goes.
|
|
48
|
+
[/\b(Bearer|Basic)(\s+)[A-Za-z0-9._~+/=-]{20,}/gi, `$1$2${REDACTED}`],
|
|
49
|
+
// AWS access keys.
|
|
50
|
+
[/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g, REDACTED],
|
|
51
|
+
// Credentials in a URL: `scheme://user:pass@host` keeps its scheme and host.
|
|
52
|
+
[/\b([a-z][a-z0-9+.-]*:\/\/)[^\s/@:]+:[^\s/@]+@/gi, `$1${REDACTED}@`],
|
|
53
|
+
// Assignments to a key, token, secret or password: `NAME=value`, `"name": "value"`.
|
|
54
|
+
[
|
|
55
|
+
/\b([A-Za-z0-9_.-]*(?:key|token|secret|password))(\s*=\s*)(["']?)[^\s"'`,;&]+/gi,
|
|
56
|
+
`$1$2$3${REDACTED}`,
|
|
57
|
+
],
|
|
58
|
+
[/("[A-Za-z0-9_.-]*(?:key|token|secret|password)"\s*:\s*")[^"]+"/gi, `$1${REDACTED}"`],
|
|
59
|
+
];
|
|
60
|
+
/**
|
|
61
|
+
* `text` with every secret it holds replaced by `[REDACTED]`, and everything
|
|
62
|
+
* else as it was. For whatever of a CLI's own output becomes part of an
|
|
63
|
+
* error: the Claude SDK redacts the stderr it quotes, and this engine's exit
|
|
64
|
+
* errors (Claude's restored tail, Codex's and ACP's) are redacted the same way.
|
|
65
|
+
*/
|
|
66
|
+
export function redactSecrets(text) {
|
|
67
|
+
let redacted = text;
|
|
68
|
+
for (const [pattern, replacement] of SECRETS)
|
|
69
|
+
redacted = redacted.replace(pattern, replacement);
|
|
70
|
+
return redacted;
|
|
71
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { THINKING_LEVELS, isThinkingLevel } from "../../protocol/index.js";
|
|
2
|
+
/** The values that are thinking levels, once each, lowest first. */
|
|
3
|
+
export function knownThinkingLevels(values) {
|
|
4
|
+
const levels = new Set();
|
|
5
|
+
for (const value of values)
|
|
6
|
+
if (typeof value === "string" && isThinkingLevel(value))
|
|
7
|
+
levels.add(value);
|
|
8
|
+
return THINKING_LEVELS.filter((level) => levels.has(level));
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The engine's diagnostics port: operational signals the engine used to
|
|
3
|
+
* swallow (best-effort paths that must not fail a turn) surfaced to the host
|
|
4
|
+
* instead. Products log/metric these; the engine never does its own logging.
|
|
5
|
+
* Handler errors are always swallowed — a diagnostics sink must never be able
|
|
6
|
+
* to break a turn.
|
|
7
|
+
*/
|
|
8
|
+
/** Invoke a handler without letting it break the calling path — sync throws
|
|
9
|
+
* AND async rejections are swallowed (the diagnostics sink owns its own
|
|
10
|
+
* reliability). Stamps the timestamp so call sites don't repeat it. */
|
|
11
|
+
export function emitDiagnostic(handler, diagnostic) {
|
|
12
|
+
if (!handler)
|
|
13
|
+
return;
|
|
14
|
+
try {
|
|
15
|
+
const result = handler({ ...diagnostic, timestamp: Date.now() });
|
|
16
|
+
if (result instanceof Promise) {
|
|
17
|
+
result.catch(() => { });
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// see above
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @zvada/agent-server/core — harness-agnostic agent execution engine.
|
|
2
|
+
// Runtime
|
|
3
|
+
export { AgentRuntime } from "./runtime/agent-runtime.js";
|
|
4
|
+
export { EventSinkError, callbackSink, CollectingSink, serialSink, teeSink, } from "./runtime/event-sink.js";
|
|
5
|
+
// Agent abstraction
|
|
6
|
+
export { BaseAgent, } from "./agents/base.js";
|
|
7
|
+
export { AgentRegistry } from "./agents/registry.js";
|
|
8
|
+
export { credentialsFromUrl } from "./agents/credentials.js";
|
|
9
|
+
export { INHERIT_CONFIGS, isInheritConfig, } from "./agents/inherit-config.js";
|
|
10
|
+
// Native processes: each CLI in a group of its own, held by the lifeline, recorded, swept at restart.
|
|
11
|
+
export { DEFAULT_GRACE_MS, NativeProcess, NativeProcesses, } from "./processes/native-processes.js";
|
|
12
|
+
export { PLAN_OPTIONS, PLAN_TITLE, approvedPlanMode } from "./agents/plan.js";
|
|
13
|
+
// CLI provisioning
|
|
14
|
+
export { CLI_TOOLS, CliProvisioner, DEFAULT_PINS, toolForHarness, } from "./provision/index.js";
|
|
15
|
+
// Harnesses
|
|
16
|
+
export { ClaudeCodeAgent } from "./agents/claude-code/claude-agent.js";
|
|
17
|
+
export { createClaudeCodeTransformer } from "./agents/claude-code/adapter.js";
|
|
18
|
+
export { CodexAppServerAgent, } from "./agents/codex-app-server/codex-agent.js";
|
|
19
|
+
export { createCodexAppServerTransformer } from "./agents/codex-app-server/adapter.js";
|
|
20
|
+
export { AcpAgent, } from "./agents/acp/acp-agent.js";
|
|
21
|
+
export { createAcpTransformer } from "./agents/acp/adapter.js";
|
|
22
|
+
export { ScriptedAgent, } from "./agents/scripted/scripted-agent.js";
|
|
23
|
+
export { createScriptedTransformer } from "./agents/scripted/adapter.js";
|
|
24
|
+
export { scriptedBySession, scriptedFile, scriptedQueue } from "./agents/scripted/scripts.js";
|
|
25
|
+
export { KNOWN_ACP_AGENTS, resolveAcpLaunch, resolveHarnessName, } from "./agents/acp/known-agents.js";
|
|
26
|
+
// Presets
|
|
27
|
+
export { createAgentRegistry, createAgentRuntime, } from "./presets.js";
|
|
28
|
+
// Utils
|
|
29
|
+
export { AgentServerError, McpUnavailableError, SessionResumeError, CliNotFoundError, CliProvisionError, HarnessNotAvailableError, InvalidRequestError, TurnConflictError, TurnForgottenError, UnknownLoginError, TurnActiveError, UnsupportedAttachmentError, } from "./utils/errors.js";
|
|
30
|
+
// Re-export the wire contract for convenience.
|
|
31
|
+
export * from "../protocol/index.js";
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { AGENT_HARNESSES } from "../protocol/index.js";
|
|
2
|
+
import { AcpAgent } from "./agents/acp/acp-agent.js";
|
|
3
|
+
import { createAcpTransformer } from "./agents/acp/adapter.js";
|
|
4
|
+
import { createClaudeCodeTransformer } from "./agents/claude-code/adapter.js";
|
|
5
|
+
import { ClaudeCodeAgent } from "./agents/claude-code/claude-agent.js";
|
|
6
|
+
import { createCodexAppServerTransformer } from "./agents/codex-app-server/adapter.js";
|
|
7
|
+
import { CodexAppServerAgent, } from "./agents/codex-app-server/codex-agent.js";
|
|
8
|
+
import { AgentRegistry } from "./agents/registry.js";
|
|
9
|
+
import { createScriptedTransformer } from "./agents/scripted/adapter.js";
|
|
10
|
+
import { ScriptedAgent } from "./agents/scripted/scripted-agent.js";
|
|
11
|
+
import { NativeProcesses } from "./processes/native-processes.js";
|
|
12
|
+
import { CliProvisioner } from "./provision/provisioner.js";
|
|
13
|
+
import { AgentRuntime } from "./runtime/agent-runtime.js";
|
|
14
|
+
/**
|
|
15
|
+
* How each harness is built: an agent and its adapter. Exhaustive, so a new
|
|
16
|
+
* `AgentHarness` fails to compile until it has an entry here.
|
|
17
|
+
*/
|
|
18
|
+
const HARNESSES = {
|
|
19
|
+
"claude-code": (opts, cliPath, processes) => [
|
|
20
|
+
new ClaudeCodeAgent({
|
|
21
|
+
onDiagnostic: opts.onDiagnostic,
|
|
22
|
+
...opts.claudeCode,
|
|
23
|
+
credentials: opts.credentials,
|
|
24
|
+
idleTimeoutMs: opts.idleTimeoutMs,
|
|
25
|
+
cancelConfirmMs: opts.cancelConfirmMs,
|
|
26
|
+
cancelGraceMs: opts.cancelGraceMs,
|
|
27
|
+
inheritConfig: opts.inheritConfig,
|
|
28
|
+
resolveCliPath: cliPath("claude"),
|
|
29
|
+
processes,
|
|
30
|
+
}),
|
|
31
|
+
createClaudeCodeTransformer,
|
|
32
|
+
],
|
|
33
|
+
"codex-app-server": (opts, cliPath, processes) => [
|
|
34
|
+
new CodexAppServerAgent({
|
|
35
|
+
...opts.codexAppServer,
|
|
36
|
+
credentials: opts.credentials,
|
|
37
|
+
idleTimeoutMs: opts.idleTimeoutMs,
|
|
38
|
+
cancelConfirmMs: opts.cancelConfirmMs,
|
|
39
|
+
cancelGraceMs: opts.cancelGraceMs,
|
|
40
|
+
inheritConfig: opts.inheritConfig,
|
|
41
|
+
resolveCliPath: cliPath("codex"),
|
|
42
|
+
processes,
|
|
43
|
+
}),
|
|
44
|
+
createCodexAppServerTransformer,
|
|
45
|
+
],
|
|
46
|
+
acp: (opts, _cliPath, processes) => {
|
|
47
|
+
if (!opts.acp) {
|
|
48
|
+
throw new Error("the acp harness requires CreateRegistryOptions.acp (resolveLaunch)");
|
|
49
|
+
}
|
|
50
|
+
const { idleTimeoutMs, cancelConfirmMs, cancelGraceMs } = opts;
|
|
51
|
+
return [
|
|
52
|
+
new AcpAgent({ ...opts.acp, idleTimeoutMs, cancelConfirmMs, cancelGraceMs, processes }),
|
|
53
|
+
createAcpTransformer,
|
|
54
|
+
];
|
|
55
|
+
},
|
|
56
|
+
scripted: (opts, _cliPath, processes) => {
|
|
57
|
+
if (!opts.scripted) {
|
|
58
|
+
throw new Error("the scripted harness requires CreateRegistryOptions.scripted (turn)");
|
|
59
|
+
}
|
|
60
|
+
// @ref LLP 0007#what-each-harness-does — it starts none, so a restart vouches for it
|
|
61
|
+
return [new ScriptedAgent({ ...opts.scripted, processes }), createScriptedTransformer];
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
const atTheTop = (option) => `set ${option} at the top level of the registry's options`;
|
|
65
|
+
/** Each option the registry says once, and where a caller says it instead. */
|
|
66
|
+
const SAID_ONCE = {
|
|
67
|
+
idleTimeoutMs: atTheTop("idleTimeoutMs"),
|
|
68
|
+
credentials: atTheTop("credentials"),
|
|
69
|
+
cancelConfirmMs: atTheTop("cancelConfirmMs"),
|
|
70
|
+
cancelGraceMs: atTheTop("cancelGraceMs"),
|
|
71
|
+
inheritConfig: atTheTop("inheritConfig"),
|
|
72
|
+
processes: "the registry gives every harness its processes; say how they are owned with nativeProcesses",
|
|
73
|
+
resolveCliPath: "the registry's provisioner finds each CLI; name one with provision.overrides",
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Refuse an option the registry says once that a caller the compiler does
|
|
77
|
+
* not check still sets on a harness, where the registry would override it.
|
|
78
|
+
* The scripted harness takes only `processes` of them.
|
|
79
|
+
*/
|
|
80
|
+
function refuseSaidOnce(opts) {
|
|
81
|
+
for (const harness of ["claudeCode", "codexAppServer", "acp", "scripted"]) {
|
|
82
|
+
const own = opts[harness] ?? {};
|
|
83
|
+
const options = harness === "scripted" ? ["processes"] : Object.keys(SAID_ONCE);
|
|
84
|
+
const option = options.find((name) => own[name] !== undefined);
|
|
85
|
+
if (option)
|
|
86
|
+
throw new Error(`${harness}.${option} is not taken: ${SAID_ONCE[option]} (LLP 0016, decision 5)`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** Build a registry with the standard harnesses wired to their adapters. */
|
|
90
|
+
export function createAgentRegistry(opts = {}) {
|
|
91
|
+
refuseSaidOnce(opts);
|
|
92
|
+
// Default: every harness that can run unconfigured — acp joins only when its
|
|
93
|
+
// operator launch config is present, scripted only when its script is
|
|
94
|
+
// (each has nothing to run otherwise).
|
|
95
|
+
const configured = {
|
|
96
|
+
acp: Boolean(opts.acp),
|
|
97
|
+
scripted: Boolean(opts.scripted),
|
|
98
|
+
};
|
|
99
|
+
const enabled = new Set(opts.harnesses ?? AGENT_HARNESSES.filter((h) => configured[h] ?? true));
|
|
100
|
+
// One provisioner per registry: resolution is memoized per tool, so every
|
|
101
|
+
// agent of a tool shares a single download and logs one source.
|
|
102
|
+
const provisioner = new CliProvisioner(opts.provision);
|
|
103
|
+
const cliPath = (tool) => () => provisioner.resolve(tool).then((cli) => cli?.path);
|
|
104
|
+
const registry = new AgentRegistry(new NativeProcesses(opts.nativeProcesses), provisioner);
|
|
105
|
+
for (const harness of AGENT_HARNESSES) {
|
|
106
|
+
if (enabled.has(harness))
|
|
107
|
+
registry.register(...HARNESSES[harness](opts, cliPath, registry.processes));
|
|
108
|
+
}
|
|
109
|
+
return registry;
|
|
110
|
+
}
|
|
111
|
+
/** Convenience: a ready-to-use runtime with the standard harnesses. */
|
|
112
|
+
export function createAgentRuntime(opts = {}) {
|
|
113
|
+
return new AgentRuntime(createAgentRegistry(opts), { onDiagnostic: opts.onDiagnostic });
|
|
114
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { basename } from "node:path";
|
|
4
|
+
import { POSIX, statFields } from "./process-table.js";
|
|
5
|
+
const LINUX = process.platform === "linux";
|
|
6
|
+
let boot;
|
|
7
|
+
/** This boot's id, read once: a record from another boot names a process that is gone. */
|
|
8
|
+
export function bootId() {
|
|
9
|
+
if (boot !== undefined)
|
|
10
|
+
return boot;
|
|
11
|
+
try {
|
|
12
|
+
boot = LINUX
|
|
13
|
+
? readFileSync("/proc/sys/kernel/random/boot_id", "utf8").trim()
|
|
14
|
+
: POSIX
|
|
15
|
+
? execFileSync("/usr/sbin/sysctl", ["-n", "kern.bootsessionuuid"], {
|
|
16
|
+
encoding: "utf8",
|
|
17
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
18
|
+
}).trim()
|
|
19
|
+
: null;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
boot = null;
|
|
23
|
+
}
|
|
24
|
+
return boot || null;
|
|
25
|
+
}
|
|
26
|
+
/** macOS: one `ps` call for the state, the start (in UTC, so the token never depends on a zone) and the command line. */
|
|
27
|
+
function psListing(pid) {
|
|
28
|
+
let out;
|
|
29
|
+
try {
|
|
30
|
+
out = execFileSync("/bin/ps", ["-o", "stat=,lstart=,command=", "-p", String(pid)], {
|
|
31
|
+
encoding: "utf8",
|
|
32
|
+
env: { ...process.env, TZ: "UTC", LC_ALL: "C" },
|
|
33
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
34
|
+
}).trim();
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return undefined; // ps exits 1 for a pid that is not there
|
|
38
|
+
}
|
|
39
|
+
const match = /^(\S+)\s+(\w{3} \w{3}\s+\d+ [\d:]+ \d{4})\s+(.*)$/.exec(out);
|
|
40
|
+
if (!match)
|
|
41
|
+
return out ? { zombie: out.startsWith("Z"), started: null, command: "" } : undefined;
|
|
42
|
+
return { zombie: match[1].startsWith("Z"), started: match[2], command: match[3] };
|
|
43
|
+
}
|
|
44
|
+
/** Linux: `/proc/<pid>/stat`'s state and start ticks, and its argv. */
|
|
45
|
+
function procListing(pid) {
|
|
46
|
+
const fields = statFields(pid);
|
|
47
|
+
if (!fields)
|
|
48
|
+
return undefined;
|
|
49
|
+
let command = "";
|
|
50
|
+
try {
|
|
51
|
+
command = readFileSync(`/proc/${pid}/cmdline`, "utf8").split("\0").join(" ").trim();
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
// A zombie has none; its state says enough.
|
|
55
|
+
}
|
|
56
|
+
return { zombie: fields[0] === "Z", started: fields[19] ?? null, command };
|
|
57
|
+
}
|
|
58
|
+
function listing(pid) {
|
|
59
|
+
if (!POSIX)
|
|
60
|
+
return undefined;
|
|
61
|
+
return LINUX ? procListing(pid) : psListing(pid);
|
|
62
|
+
}
|
|
63
|
+
/** When `pid` started, as its record keeps it; null when it cannot be read. */
|
|
64
|
+
export function startToken(pid) {
|
|
65
|
+
return listing(pid)?.started ?? null;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Whether a record still names a process this machine runs. `gone`: another
|
|
69
|
+
* boot, no such process, a zombie, or a process that is not the one recorded
|
|
70
|
+
* (its pid was reused; it is left alone). `ours`: the process recorded, still
|
|
71
|
+
* running. `not_verified`: nothing here can tell.
|
|
72
|
+
*/
|
|
73
|
+
export function verifyRecord(record) {
|
|
74
|
+
if (record.pid === null || !POSIX)
|
|
75
|
+
return "not_verified";
|
|
76
|
+
const now = bootId();
|
|
77
|
+
if (!now || !record.boot)
|
|
78
|
+
return "not_verified";
|
|
79
|
+
if (record.boot !== now)
|
|
80
|
+
return "gone";
|
|
81
|
+
const listed = listing(record.pid);
|
|
82
|
+
if (!listed || listed.zombie)
|
|
83
|
+
return "gone";
|
|
84
|
+
if (!listed.started || !record.started)
|
|
85
|
+
return "not_verified";
|
|
86
|
+
if (listed.started !== record.started)
|
|
87
|
+
return "gone";
|
|
88
|
+
// A script runs under its interpreter (`node …/npx`): its command line
|
|
89
|
+
// names the script, not the program launched first.
|
|
90
|
+
return listed.command.includes(basename(record.executable)) ? "ours" : "gone";
|
|
91
|
+
}
|