@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
package/src/sync/fit.ts
CHANGED
|
@@ -2,6 +2,8 @@ import {
|
|
|
2
2
|
HISTORY_MAX_BYTES,
|
|
3
3
|
HistoryError,
|
|
4
4
|
type LifecycleEvent,
|
|
5
|
+
OMITTED_BINARY_META_KEY,
|
|
6
|
+
type OmittedBinary,
|
|
5
7
|
canonicalJson,
|
|
6
8
|
decodeLifecycleEvent,
|
|
7
9
|
jsonBytes,
|
|
@@ -25,39 +27,124 @@ export const REPLAY_PAGE_BYTES = HISTORY_MAX_BYTES - 64 * 1024;
|
|
|
25
27
|
const encoder = new TextEncoder();
|
|
26
28
|
const decoder = new TextDecoder();
|
|
27
29
|
|
|
30
|
+
/** An image or file as the protocol carries one: base64 `data` beside its `mimeType`. */
|
|
31
|
+
function isBinary(value: object): value is Record<string, unknown> & { data: string } {
|
|
32
|
+
const entry = value as Record<string, unknown>;
|
|
33
|
+
return (
|
|
34
|
+
(entry.type === "image" || entry.type === "file") &&
|
|
35
|
+
typeof entry.data === "string" &&
|
|
36
|
+
typeof entry.mimeType === "string"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** The size of what base64 `data` encodes. */
|
|
41
|
+
function decodedBytes(data: string): number {
|
|
42
|
+
const padding = data.endsWith("==") ? 2 : data.endsWith("=") ? 1 : 0;
|
|
43
|
+
return Math.max(0, Math.floor((data.length * 3) / 4) - padding);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The part fields that address a part, which its stand-in keeps. */
|
|
47
|
+
const ADDRESS = ["id", "sessionId", "messageId", "parentToolCallId"] as const;
|
|
48
|
+
|
|
28
49
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
50
|
+
* What a store keeps in place of `binary`: text saying what it was, in words
|
|
51
|
+
* and under `OMITTED_BINARY_META_KEY`. A part stays at its address as a text
|
|
52
|
+
* part; a tool result's entry becomes a text entry.
|
|
32
53
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
54
|
+
function omittedBinary(
|
|
55
|
+
binary: Record<string, unknown> & { data: string },
|
|
56
|
+
where: string,
|
|
57
|
+
): Record<string, unknown> {
|
|
58
|
+
const facts: OmittedBinary = {
|
|
59
|
+
type: binary.type as OmittedBinary["type"],
|
|
60
|
+
mimeType: binary.mimeType as string,
|
|
61
|
+
bytes: decodedBytes(binary.data),
|
|
62
|
+
...(typeof binary.filename === "string" && { filename: binary.filename }),
|
|
63
|
+
};
|
|
64
|
+
const meta =
|
|
65
|
+
binary._meta && typeof binary._meta === "object" && !Array.isArray(binary._meta)
|
|
66
|
+
? binary._meta
|
|
67
|
+
: {};
|
|
68
|
+
const named = facts.filename === undefined ? "" : ` ${facts.filename}`;
|
|
69
|
+
return {
|
|
70
|
+
type: "text",
|
|
71
|
+
...Object.fromEntries(
|
|
72
|
+
ADDRESS.filter((key) => typeof binary[key] === "string").map((key) => [key, binary[key]]),
|
|
73
|
+
),
|
|
74
|
+
text: `[agent-server: ${facts.mimeType} ${facts.type}${named} of ${facts.bytes} bytes omitted to fit ${where}]`,
|
|
75
|
+
_meta: { ...meta, [OMITTED_BINARY_META_KEY]: facts },
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// @ref LLP 0002#tool-output-has-three-audiences — a cut binary is no display at all: kept whole or replaced
|
|
80
|
+
/**
|
|
81
|
+
* `value` brought down to `maxBytes` by its longest strings, one at a time: a
|
|
82
|
+
* binary's `data` (an image or file, `isBinary`) is never cut, its whole entry
|
|
83
|
+
* is replaced by a text one saying what it was (`omittedBinary`); any other
|
|
84
|
+
* string is cut with a visible marker, when `cutText`. It stops when only
|
|
85
|
+
* short strings remain, so what it returns may still not fit. A value that
|
|
86
|
+
* already fits is returned as is.
|
|
87
|
+
*/
|
|
88
|
+
function shrink<T>(value: T, maxBytes: number, where: string, cutText: boolean): T {
|
|
89
|
+
let size = jsonBytes(value);
|
|
90
|
+
if (size <= maxBytes) return value;
|
|
91
|
+
const copy = structuredClone(value);
|
|
92
|
+
// Each replacement removes a binary; cuts are bounded as they always were.
|
|
93
|
+
let cuts = 0;
|
|
94
|
+
while (size > maxBytes) {
|
|
95
|
+
let longest:
|
|
96
|
+
| { holder: Record<string, unknown>; key: string; bytes: number; binary: boolean }
|
|
97
|
+
| undefined;
|
|
98
|
+
const consider = (holder: object, key: string, bytes: number, binary: boolean) => {
|
|
99
|
+
if (!longest || bytes > longest.bytes)
|
|
100
|
+
longest = { holder: holder as Record<string, unknown>, key, bytes, binary };
|
|
101
|
+
};
|
|
102
|
+
const visit = (node: object) => {
|
|
103
|
+
for (const [key, child] of Object.entries(node)) {
|
|
104
|
+
if (child && typeof child === "object") {
|
|
105
|
+
// Base64 is ASCII: its length is its size.
|
|
106
|
+
if (isBinary(child)) consider(node, key, child.data.length, true);
|
|
107
|
+
else visit(child);
|
|
108
|
+
} else if (cutText && typeof child === "string")
|
|
109
|
+
consider(node, key, encoder.encode(child).byteLength, false);
|
|
48
110
|
}
|
|
49
111
|
};
|
|
50
|
-
visit(copy);
|
|
51
|
-
if (!longest || longest.bytes < 1024)
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
112
|
+
if (copy && typeof copy === "object") visit(copy);
|
|
113
|
+
if (!longest || longest.bytes < 1024) break;
|
|
114
|
+
const { holder, key, bytes } = longest;
|
|
115
|
+
if (longest.binary)
|
|
116
|
+
holder[key] = omittedBinary(holder[key] as Record<string, unknown> & { data: string }, where);
|
|
117
|
+
else {
|
|
118
|
+
if (++cuts > 8) break;
|
|
119
|
+
const keep = Math.max(0, bytes - (size - maxBytes) - 256);
|
|
120
|
+
const head = decoder
|
|
121
|
+
.decode(encoder.encode(holder[key] as string).slice(0, keep))
|
|
122
|
+
.replace(/�$/, "");
|
|
123
|
+
holder[key] = `${head}\n[agent-server: ${bytes - keep} bytes omitted to fit ${where}]`;
|
|
124
|
+
}
|
|
58
125
|
size = jsonBytes(copy);
|
|
59
126
|
}
|
|
60
|
-
return
|
|
127
|
+
return copy;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* `event` cut down to `maxBytes`: its longest strings (usually a tool's
|
|
132
|
+
* output) are truncated with a visible marker until it fits, and an image or
|
|
133
|
+
* file it cannot keep whole is replaced by text saying what it was. `undefined`
|
|
134
|
+
* when only short strings remain. An event that already fits is returned as is.
|
|
135
|
+
*/
|
|
136
|
+
export function fitEvent<T>(event: T, maxBytes = MAX_EVENT_BYTES): T | undefined {
|
|
137
|
+
const fitted = shrink(event, maxBytes, "the journal", true);
|
|
138
|
+
return jsonBytes(fitted) <= maxBytes ? fitted : undefined;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* `value` with its largest images and files replaced by text saying what they
|
|
143
|
+
* were (as `fitEvent` replaces them) until it fits `maxBytes`, or until none
|
|
144
|
+
* is left. Nothing else is changed. A value that already fits is returned as is.
|
|
145
|
+
*/
|
|
146
|
+
export function omitBinaries<T>(value: T, maxBytes: number, where: string): T {
|
|
147
|
+
return shrink(value, maxBytes, where, false);
|
|
61
148
|
}
|
|
62
149
|
|
|
63
150
|
/**
|
|
@@ -65,7 +152,7 @@ export function fitEvent<T>(event: T, maxBytes = MAX_EVENT_BYTES): T | undefined
|
|
|
65
152
|
* every other session keep going. A turn or session end keeps its meaning;
|
|
66
153
|
* anything else becomes a recoverable error notice naming what was lost.
|
|
67
154
|
*/
|
|
68
|
-
|
|
155
|
+
function unrecordedEvent(event: LifecycleEvent, reason: string): LifecycleEvent {
|
|
69
156
|
const message = `agent-server could not record a ${event.type} event: ${reason.slice(0, 300)}`;
|
|
70
157
|
const timestamp = Date.now();
|
|
71
158
|
if (event.type === "turn.ended")
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
} from "../protocol/index.ts";
|
|
36
36
|
import { type EventLog, type EventRow, sha256 } from "./event-log.ts";
|
|
37
37
|
import { MAX_EVENT_BYTES, PAGE_SLACK_BYTES } from "./fit.ts";
|
|
38
|
-
import { checkCheckpointBytes, projectionFold } from "./projection.ts";
|
|
38
|
+
import { checkCheckpointBytes, fitCheckpoint, projectionFold } from "./projection.ts";
|
|
39
39
|
import type { Db } from "./sql.ts";
|
|
40
40
|
|
|
41
41
|
const conflict = (message: string) => new HistoryError("historyConflict", message);
|
|
@@ -322,7 +322,11 @@ export class SqliteHistory implements HistoryStore {
|
|
|
322
322
|
: emptyConversation();
|
|
323
323
|
for (const row of this.log.records(ref, prior?.version.seq ?? 0, target.seq))
|
|
324
324
|
conversation = fold(conversation, JSON.parse(row.body));
|
|
325
|
-
const checkpoint = {
|
|
325
|
+
const checkpoint = fitCheckpoint({
|
|
326
|
+
version: target,
|
|
327
|
+
format: CONVERSATION_CHECKPOINT_FORMAT,
|
|
328
|
+
conversation,
|
|
329
|
+
});
|
|
326
330
|
checkCheckpointBytes(checkpoint);
|
|
327
331
|
this.db.atomic(() =>
|
|
328
332
|
this.db.run(
|
package/src/sync/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
type AgentHarness,
|
|
3
3
|
type DurableSession,
|
|
4
4
|
HISTORY_MAX_RECORDS,
|
|
5
|
+
type LastTurn,
|
|
5
6
|
type LifecycleEvent,
|
|
6
7
|
type MessagePartDeltaEvent,
|
|
7
8
|
type RecoveryReason,
|
|
@@ -116,6 +117,18 @@ export class SqliteJournal implements SessionJournal {
|
|
|
116
117
|
}
|
|
117
118
|
);
|
|
118
119
|
}
|
|
120
|
+
lastTurn(sessionId: string): LastTurn | undefined {
|
|
121
|
+
// An admitted turn has no terminal yet: it sorts first, then the latest ended.
|
|
122
|
+
const row = this.db.one<{ turn_id: string; terminal: string | null }>(
|
|
123
|
+
"SELECT t.turn_id, e.body AS terminal FROM turns t LEFT JOIN events e ON e.source_id=? AND e.session_id=t.session_id AND e.seq=t.terminal_seq WHERE t.session_id=? ORDER BY t.state='admitted' DESC, t.terminal_seq DESC LIMIT 1",
|
|
124
|
+
this.sourceId,
|
|
125
|
+
sessionId,
|
|
126
|
+
);
|
|
127
|
+
if (!row) return undefined;
|
|
128
|
+
if (row.terminal === null) return { turnId: row.turn_id };
|
|
129
|
+
const { stopReason, error } = JSON.parse(row.terminal) as TurnEndedEvent;
|
|
130
|
+
return { turnId: row.turn_id, stopReason, ...(error && { error }) };
|
|
131
|
+
}
|
|
119
132
|
turn(sessionId: string, turnId: string): TurnReceipt | undefined {
|
|
120
133
|
const row = this.db.one<{
|
|
121
134
|
state: TurnReceipt["state"];
|
|
@@ -160,8 +173,13 @@ export class SqliteJournal implements SessionJournal {
|
|
|
160
173
|
"History branch is not a native execution session; prepare provider context explicitly",
|
|
161
174
|
);
|
|
162
175
|
const input = canonical(request.input);
|
|
163
|
-
|
|
164
|
-
|
|
176
|
+
const bytes = Buffer.byteLength(input);
|
|
177
|
+
if (bytes > MAX_EVENT_BYTES)
|
|
178
|
+
// `invalidParams` carries no data on the wire (`WIRE_REFUSAL_DATA`): the words say it.
|
|
179
|
+
throw new JournalError(
|
|
180
|
+
"invalidParams",
|
|
181
|
+
`Input is ${bytes} bytes; the durable record limit is ${MAX_EVENT_BYTES} bytes`,
|
|
182
|
+
);
|
|
165
183
|
return this.db.atomic(() => {
|
|
166
184
|
if (this.admission(request) === "duplicate") return "duplicate";
|
|
167
185
|
const state = this.session(sessionId);
|
package/src/sync/journal.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type AgentHarness,
|
|
3
3
|
type DurableSession,
|
|
4
|
+
type LastTurn,
|
|
4
5
|
type LifecycleEvent,
|
|
5
6
|
type MessagePartDeltaEvent,
|
|
6
7
|
type RunRequest,
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
export class JournalError extends WireRefusal<JournalRefusal, Record<string, unknown>> {
|
|
20
21
|
override readonly name = "JournalError";
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
type JournalRefusal = Extract<
|
|
23
24
|
WireErrorName,
|
|
24
25
|
| "turnConflict"
|
|
25
26
|
| "turnActive"
|
|
@@ -84,7 +85,13 @@ export interface SessionJournal {
|
|
|
84
85
|
* `not_verified`. Either way until `confirmStopped`. Returns the release.
|
|
85
86
|
*/
|
|
86
87
|
claim(options?: ClaimOptions): () => void;
|
|
88
|
+
/** What it knows of the session, less `lastTurn`: every admission and append reads it. */
|
|
87
89
|
session(sessionId: string): DurableSession | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* The session's admitted turn, or else the ended one whose `turn.ended` is
|
|
92
|
+
* latest, for `session/get`. Undefined before its first turn.
|
|
93
|
+
*/
|
|
94
|
+
lastTurn(sessionId: string): LastTurn | undefined;
|
|
88
95
|
turn(sessionId: string, turnId: string): TurnReceipt | undefined;
|
|
89
96
|
/** Whether this journal already admitted the turn. Throws `turnConflict` for other input. */
|
|
90
97
|
admission(request: RunRequest): "new" | "duplicate";
|
|
@@ -96,7 +103,8 @@ export interface SessionJournal {
|
|
|
96
103
|
*/
|
|
97
104
|
admit(request: RunRequest): "new" | "duplicate";
|
|
98
105
|
/** Commits `event`, or, when its content cannot be stored, a copy cut down to
|
|
99
|
-
* fit
|
|
106
|
+
* fit (a binary that does not fit is replaced whole by a marker, never cut)
|
|
107
|
+
* or a notice in its place. Deliver what it returns. Throws only when
|
|
100
108
|
* storage itself fails. */
|
|
101
109
|
append(event: LifecycleEvent): WireEventEnvelope;
|
|
102
110
|
/**
|
package/src/sync/node-sqlite.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { DatabaseSync } from "node:sqlite";
|
|
1
|
+
import type { DatabaseSync } from "node:sqlite";
|
|
2
2
|
import { SqliteJournal } from "./journal-sqlite.ts";
|
|
3
3
|
import { openJournalFile } from "./sqlite-file.ts";
|
|
4
4
|
|
|
5
5
|
/** Node >=22.16 adapter (node:sqlite). Same schema and guarantees as Bun.
|
|
6
|
-
*
|
|
6
|
+
* `node:sqlite` loads when a journal opens, not when this module does: a
|
|
7
|
+
* bundle holding both adapters (the bin, compiled by Bun into one binary)
|
|
8
|
+
* hoists a static import of it, which Bun, without the module, refuses at
|
|
9
|
+
* start; and Node 22 warns that it is experimental on its first load. */
|
|
7
10
|
export class NodeSqliteSessionJournal extends SqliteJournal {
|
|
8
11
|
constructor(path: string) {
|
|
9
12
|
super(
|
|
10
13
|
openJournalFile(path, (file) => {
|
|
11
|
-
const db = new DatabaseSync(file);
|
|
14
|
+
const db: DatabaseSync = new (nodeSqlite().DatabaseSync)(file);
|
|
12
15
|
return {
|
|
13
16
|
exec: (sql) => db.exec(sql),
|
|
14
17
|
prepare: (sql) => db.prepare(sql),
|
|
@@ -18,3 +21,16 @@ export class NodeSqliteSessionJournal extends SqliteJournal {
|
|
|
18
21
|
);
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
|
|
25
|
+
/** `node:sqlite`, loaded now: Bun answers undefined for a module it does not have. */
|
|
26
|
+
function nodeSqlite(): typeof import("node:sqlite") {
|
|
27
|
+
// @ref LLP 0001#d24--bun-runs-the-packages-sources-every-other-runtime-its-compiled-javascript — loaded when a journal opens
|
|
28
|
+
const sqlite = process.getBuiltinModule("node:sqlite") as
|
|
29
|
+
| typeof import("node:sqlite")
|
|
30
|
+
| undefined;
|
|
31
|
+
if (!sqlite)
|
|
32
|
+
throw new Error(
|
|
33
|
+
"this runtime has no node:sqlite: use Node >=22.16, or under Bun the bun:sqlite journal (./sync/sqlite)",
|
|
34
|
+
);
|
|
35
|
+
return sqlite;
|
|
36
|
+
}
|
package/src/sync/projection.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
jsonBytes,
|
|
8
8
|
reduceConversation,
|
|
9
9
|
} from "../protocol/index.ts";
|
|
10
|
+
import { omitBinaries } from "./fit.ts";
|
|
10
11
|
|
|
11
12
|
/** The most events a projection folds unless its caller says otherwise: it is built in memory. */
|
|
12
13
|
const MAX_PROJECTION_RECORDS = 100_000;
|
|
@@ -28,6 +29,15 @@ export function projectionFold(
|
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
31
|
|
|
32
|
+
/**
|
|
33
|
+
* `checkpoint` with its largest images and files replaced by text saying what
|
|
34
|
+
* they were until it fits a history page (`omitBinaries`): binaries alone never
|
|
35
|
+
* make a checkpoint too large to keep. The events keep what they kept.
|
|
36
|
+
*/
|
|
37
|
+
export function fitCheckpoint(checkpoint: HistoryCheckpoint): HistoryCheckpoint {
|
|
38
|
+
return omitBinaries(checkpoint, HISTORY_MAX_BYTES, "this checkpoint");
|
|
39
|
+
}
|
|
40
|
+
|
|
31
41
|
/** A checkpoint fits a history page, as all history does: no store keeps, and no reader takes, a larger one. */
|
|
32
42
|
export function checkCheckpointBytes(checkpoint: HistoryCheckpoint): void {
|
|
33
43
|
if (jsonBytes(checkpoint) > HISTORY_MAX_BYTES)
|
package/src/sync/recovery.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import type { SessionEvent } from "./fit.ts";
|
|
13
13
|
|
|
14
14
|
/** A turn a server restart cut off, as the journal holds it. */
|
|
15
|
-
|
|
15
|
+
interface CutOffTurn {
|
|
16
16
|
sessionId: string;
|
|
17
17
|
turnId: string;
|
|
18
18
|
/** The session's harness, which a turn cut off before its first event never named. */
|
|
@@ -76,6 +76,8 @@ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): Ses
|
|
|
76
76
|
outcome: { action: "cancel" },
|
|
77
77
|
timestamp: at,
|
|
78
78
|
});
|
|
79
|
+
// Whether a tool that may have run was open at the cut: only then is its outcome unknown.
|
|
80
|
+
let toolRan = false;
|
|
79
81
|
for (const entry of state.timeline) {
|
|
80
82
|
if (entry.kind !== "message" || entry.turnId !== turnId) continue;
|
|
81
83
|
// A tool keeps running after the model message that called it ends, and
|
|
@@ -84,6 +86,8 @@ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): Ses
|
|
|
84
86
|
if ("raw" in part) continue;
|
|
85
87
|
const where = address.get(part.id);
|
|
86
88
|
const closed = where && closePart(state, turnId, part, at, turn.tails.get(part.id));
|
|
89
|
+
if (closed?.type === "tool" && closed.state.status === "failed")
|
|
90
|
+
toolRan ||= closed.state.closure === "interrupted";
|
|
87
91
|
if (where && closed)
|
|
88
92
|
facts.push({
|
|
89
93
|
type: "message.part",
|
|
@@ -103,6 +107,11 @@ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): Ses
|
|
|
103
107
|
timestamp: at,
|
|
104
108
|
});
|
|
105
109
|
}
|
|
110
|
+
// @ref LLP 0003#commit-before-acknowledging — what the restart found, never what to do:
|
|
111
|
+
// the history outlives a fence, which `recoveryRequired` alone says is still up.
|
|
112
|
+
const agent = turn.fence
|
|
113
|
+
? `Its agent could not be confirmed stopped at restart (${turn.fence})`
|
|
114
|
+
: "Its agent was stopped at restart";
|
|
106
115
|
facts.push({
|
|
107
116
|
type: "turn.ended",
|
|
108
117
|
sessionId,
|
|
@@ -110,9 +119,7 @@ export function recoveryFacts(history: Iterable<unknown>, turn: CutOffTurn): Ses
|
|
|
110
119
|
stopReason: "error",
|
|
111
120
|
error: {
|
|
112
121
|
category: "server_restart",
|
|
113
|
-
message: turn.
|
|
114
|
-
? `Server restarted before the turn settled and could not confirm its agent stopped (${turn.fence}); check it before continuing.`
|
|
115
|
-
: "Server restarted before the turn settled. Its agent was stopped at restart; what its running tool did is unknown.",
|
|
122
|
+
message: `Server restarted before the turn settled. ${agent}${toolRan ? "; what its running tool did is unknown" : ""}.`,
|
|
116
123
|
},
|
|
117
124
|
timestamp: at,
|
|
118
125
|
});
|
package/src/sync/schema.ts
CHANGED
|
@@ -6,8 +6,10 @@ import type { Db } from "./sql.ts";
|
|
|
6
6
|
* tail is the whole part; version 5 keeps the native processes its owners
|
|
7
7
|
* started, and why a fence could not be lifted; version 4 keeps each
|
|
8
8
|
* streaming part's unsnapshotted tail for recovery; version 3 stored no token
|
|
9
|
-
* deltas (wire v3); version 2 journals kept them at their own seq.
|
|
10
|
-
|
|
9
|
+
* deltas (wire v3); version 2 journals kept them at their own seq. Exported
|
|
10
|
+
* from `./sync`, which loads no SQLite driver: a product that starts a new
|
|
11
|
+
* journal file per schema names the file from it. */
|
|
12
|
+
export const JOURNAL_SCHEMA_VERSION = 6;
|
|
11
13
|
|
|
12
14
|
const DDL = `
|
|
13
15
|
CREATE TABLE identity (id TEXT PRIMARY KEY);
|
|
@@ -57,15 +59,15 @@ CREATE TABLE checkpoints (
|
|
|
57
59
|
source_id TEXT NOT NULL, session_id TEXT NOT NULL, format TEXT NOT NULL,
|
|
58
60
|
seq INTEGER NOT NULL, body TEXT NOT NULL,
|
|
59
61
|
PRIMARY KEY (source_id, session_id, format));
|
|
60
|
-
PRAGMA user_version = ${
|
|
62
|
+
PRAGMA user_version = ${JOURNAL_SCHEMA_VERSION};
|
|
61
63
|
`;
|
|
62
64
|
|
|
63
65
|
/** Create or check the schema; returns the store's identity, minting it once. */
|
|
64
66
|
export function openSchema(db: Db, newId: () => string): string {
|
|
65
67
|
const { user_version: version } = db.one<{ user_version: number }>("PRAGMA user_version")!;
|
|
66
|
-
if (version !== 0 && version !==
|
|
68
|
+
if (version !== 0 && version !== JOURNAL_SCHEMA_VERSION)
|
|
67
69
|
throw new Error(
|
|
68
|
-
`Unsupported journal schema ${version}; this build reads schema ${
|
|
70
|
+
`Unsupported journal schema ${version}; this build reads schema ${JOURNAL_SCHEMA_VERSION}. Open it with the agent-server that wrote it, or start a new journal file`,
|
|
69
71
|
);
|
|
70
72
|
return db.atomic(() => {
|
|
71
73
|
if (version === 0) {
|
package/src/sync/sql.ts
CHANGED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { McpSetServersResult } from "@anthropic-ai/claude-agent-sdk";
|
|
2
|
-
import type { McpServerConfig } from "../../../protocol/index.ts";
|
|
3
|
-
import { type ClaudeCodeAgentOptions, type ClaudeSessionConfig, type ClaudeSessionSettings } from "./options.ts";
|
|
4
|
-
import { ClaudeSession } from "./session.ts";
|
|
5
|
-
/** The selected session and whether this invocation owns its new startup. */
|
|
6
|
-
export interface ClaudeSessionSpawn {
|
|
7
|
-
session: ClaudeSession;
|
|
8
|
-
spawned: boolean;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* One live `ClaudeSession` per logical session id. Decides, per turn, whether
|
|
12
|
-
* the existing session can be reused (hot-swapping model, mode and MCP) or
|
|
13
|
-
* must be replaced by a new process that resumes the conversation.
|
|
14
|
-
*/
|
|
15
|
-
export declare class ClaudeSessionPool {
|
|
16
|
-
private readonly settings;
|
|
17
|
-
private readonly sessions;
|
|
18
|
-
/** Started before the login last changed: the next turn replaces the process. */
|
|
19
|
-
private readonly priorLogin;
|
|
20
|
-
constructor(settings: ClaudeSessionSettings & Pick<ClaudeCodeAgentOptions, "onSessionEnd">);
|
|
21
|
-
getOrCreate(sessionId: string, config: ClaudeSessionConfig): Promise<ClaudeSessionSpawn>;
|
|
22
|
-
get(sessionId: string): ClaudeSession | undefined;
|
|
23
|
-
terminate(sessionId: string): Promise<void>;
|
|
24
|
-
terminateAll(): Promise<void>;
|
|
25
|
-
invalidateMcpConnections(): void;
|
|
26
|
-
/** A running CLI keeps the credentials it started with: each session's next turn starts a new one. */
|
|
27
|
-
loginChanged(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Explicit live MCP swap (e.g. mid-conversation app registration). NOTE:
|
|
30
|
-
* this syncs the session's servers, so the NEXT turn's wire config (if it
|
|
31
|
-
* still carries the old server set) will swap back — explicit swappers
|
|
32
|
-
* must keep their per-turn `mcpServers` in step.
|
|
33
|
-
*/
|
|
34
|
-
setMcpServers(sessionId: string, servers: Record<string, McpServerConfig>): Promise<McpSetServersResult | undefined>;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=session-pool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-pool.d.ts","sourceRoot":"","sources":["../../../../../src/core/agents/claude-code/session-pool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EACN,KAAK,sBAAsB,EAC3B,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAE1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,6EAA6E;AAC7E,MAAM,WAAW,kBAAkB;IAClC,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CACjB;AA6BD;;;;GAIG;AACH,qBAAa,iBAAiB;IAM5B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAL1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoC;IAC7D,iFAAiF;IACjF,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAgC;gBAGzC,QAAQ,EAAE,qBAAqB,GAAG,IAAI,CAAC,sBAAsB,EAAE,cAAc,CAAC;IAG1F,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAuC9F,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAI3C,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO3C,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAKnC,wBAAwB,IAAI,IAAI;IAIhC,sGAAsG;IACtG,YAAY,IAAI,IAAI;IAIpB;;;;;OAKG;IACG,aAAa,CAClB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GACtC,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;CAK3C"}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Idle time before an unused session's subprocess is shut down, unless its
|
|
3
|
-
* harness's `idleTimeoutMs` says otherwise.
|
|
4
|
-
*/
|
|
5
|
-
export declare const IDLE_TIMEOUT_MS: number;
|
|
6
|
-
/** The slice of a session a SessionPool manages: a closable client + idle timer. */
|
|
7
|
-
export interface PooledSession {
|
|
8
|
-
client: {
|
|
9
|
-
closed: boolean;
|
|
10
|
-
close(): void;
|
|
11
|
-
};
|
|
12
|
-
idleTimer?: ReturnType<typeof setTimeout>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Per-logical-session bookkeeping shared by subprocess-backed harnesses
|
|
16
|
-
* (codex-app-server, acp): the sessionId → session map, idle-eviction timers,
|
|
17
|
-
* self-healing when a client dies underneath us, and whole-pool teardown.
|
|
18
|
-
* Harnesses own what a session *is*; this owns when one goes away.
|
|
19
|
-
*/
|
|
20
|
-
export declare class SessionPool<S extends PooledSession> {
|
|
21
|
-
private readonly sessions;
|
|
22
|
-
private readonly pending;
|
|
23
|
-
private closed;
|
|
24
|
-
/** Own a client before its initialization RPCs have completed. */
|
|
25
|
-
trackPending(sessionId: string, client: S["client"]): () => void;
|
|
26
|
-
get(sessionId: string): S | undefined;
|
|
27
|
-
set(sessionId: string, session: S): void;
|
|
28
|
-
values(): IterableIterator<S>;
|
|
29
|
-
/** Native clients include both retained sessions and unfinished initialization. */
|
|
30
|
-
clients(): IterableIterator<S["client"]>;
|
|
31
|
-
/** Self-heal: drop the mapping when this exact client closed underneath us. */
|
|
32
|
-
dropIfCurrent(sessionId: string, client: S["client"]): void;
|
|
33
|
-
/** Tear down one session: cancel its idle timer, unmap it, close its client. */
|
|
34
|
-
close(sessionId: string): void;
|
|
35
|
-
/** Tear down ready and initializing clients; refuse subsequent registrations. */
|
|
36
|
-
closeAll(): void;
|
|
37
|
-
/** Shut the session down after `idleMs` unless another turn claims it first. */
|
|
38
|
-
armIdle(sessionId: string, session: S, idleMs: number): void;
|
|
39
|
-
clearIdle(session: S): void;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=session-pool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"session-pool.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/session-pool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,eAAe,QAAa,CAAC;AAE1C,oFAAoF;AACpF,MAAM,WAAW,aAAa;IAC7B,MAAM,EAAE;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,KAAK,IAAI,IAAI,CAAA;KAAE,CAAC;IAC3C,SAAS,CAAC,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;CAC1C;AAED;;;;;GAKG;AACH,qBAAa,WAAW,CAAC,CAAC,SAAS,aAAa;IAC/C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAwB;IACjD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuC;IAC/D,OAAO,CAAC,MAAM,CAAS;IAEvB,kEAAkE;IAClE,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,IAAI;IAmBhE,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAIrC,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;IAQxC,MAAM,IAAI,gBAAgB,CAAC,CAAC,CAAC;IAI7B,mFAAmF;IAClF,OAAO,IAAI,gBAAgB,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAKzC,+EAA+E;IAC/E,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,IAAI;IAQ3D,gFAAgF;IAChF,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAU9B,iFAAiF;IACjF,QAAQ,IAAI,IAAI;IAOhB,gFAAgF;IAChF,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAU5D,SAAS,CAAC,OAAO,EAAE,CAAC,GAAG,IAAI;CAM3B"}
|