@zvada/agent-server 0.3.18 → 0.3.20
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/AGENTS.md +11 -26
- package/CHANGELOG.md +1041 -1
- package/README.md +40 -40
- package/dist/types/accounts/chatgpt.d.ts +34 -0
- package/dist/types/accounts/chatgpt.d.ts.map +1 -0
- package/dist/types/accounts/check.d.ts +24 -0
- package/dist/types/accounts/check.d.ts.map +1 -0
- package/dist/types/accounts/claude.d.ts +21 -0
- package/dist/types/accounts/claude.d.ts.map +1 -0
- package/dist/types/accounts/endpoint.d.ts +50 -0
- package/dist/types/accounts/endpoint.d.ts.map +1 -0
- package/dist/types/accounts/http.d.ts +38 -0
- package/dist/types/accounts/http.d.ts.map +1 -0
- package/dist/types/accounts/index.d.ts +6 -0
- package/dist/types/accounts/index.d.ts.map +1 -0
- package/dist/types/client/client.d.ts +272 -0
- package/dist/types/client/client.d.ts.map +1 -0
- package/dist/types/client/connection.d.ts +160 -0
- package/dist/types/client/connection.d.ts.map +1 -0
- package/dist/types/client/history.d.ts +8 -0
- package/dist/types/client/history.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +5 -0
- package/dist/types/client/index.d.ts.map +1 -0
- package/dist/types/client/listeners.d.ts +8 -0
- package/dist/types/client/listeners.d.ts.map +1 -0
- package/dist/types/client/logins.d.ts +35 -0
- package/dist/types/client/logins.d.ts.map +1 -0
- package/dist/types/client/rpc.d.ts +46 -0
- package/dist/types/client/rpc.d.ts.map +1 -0
- package/dist/types/client/streams.d.ts +150 -0
- package/dist/types/client/streams.d.ts.map +1 -0
- package/dist/types/client/transports.d.ts +35 -0
- package/dist/types/client/transports.d.ts.map +1 -0
- package/dist/types/client/turns.d.ts +81 -0
- package/dist/types/client/turns.d.ts.map +1 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts +68 -0
- package/dist/types/core/agents/acp/acp-agent.d.ts.map +1 -0
- package/dist/types/core/agents/acp/adapter.d.ts +39 -0
- package/dist/types/core/agents/acp/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/acp/client.d.ts +90 -0
- package/dist/types/core/agents/acp/client.d.ts.map +1 -0
- package/dist/types/core/agents/acp/known-agents.d.ts +35 -0
- package/dist/types/core/agents/acp/known-agents.d.ts.map +1 -0
- package/dist/types/core/agents/acp/mappings.d.ts +46 -0
- package/dist/types/core/agents/acp/mappings.d.ts.map +1 -0
- package/dist/types/core/agents/acp/requests.d.ts +26 -0
- package/dist/types/core/agents/acp/requests.d.ts.map +1 -0
- package/dist/types/core/agents/attachments.d.ts +11 -0
- package/dist/types/core/agents/attachments.d.ts.map +1 -0
- package/dist/types/core/agents/base.d.ts +227 -0
- package/dist/types/core/agents/base.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts +58 -0
- package/dist/types/core/agents/claude-code/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts +26 -0
- package/dist/types/core/agents/claude-code/approvals.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts +70 -0
- package/dist/types/core/agents/claude-code/claude-agent.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts +54 -0
- package/dist/types/core/agents/claude-code/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/events.d.ts +42 -0
- package/dist/types/core/agents/claude-code/events.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/login.d.ts +61 -0
- package/dist/types/core/agents/claude-code/login.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts +52 -0
- package/dist/types/core/agents/claude-code/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/models.d.ts +30 -0
- package/dist/types/core/agents/claude-code/models.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/options.d.ts +183 -0
- package/dist/types/core/agents/claude-code/options.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts +50 -0
- package/dist/types/core/agents/claude-code/outcome.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts +36 -0
- package/dist/types/core/agents/claude-code/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/session.d.ts +148 -0
- package/dist/types/core/agents/claude-code/session.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts +29 -0
- package/dist/types/core/agents/claude-code/spawn.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/spend.d.ts +58 -0
- package/dist/types/core/agents/claude-code/spend.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/tools.d.ts +4 -0
- package/dist/types/core/agents/claude-code/tools.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts +52 -0
- package/dist/types/core/agents/claude-code/turn-usage.d.ts.map +1 -0
- package/dist/types/core/agents/claude-code/turn.d.ts +121 -0
- package/dist/types/core/agents/claude-code/turn.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts +59 -0
- package/dist/types/core/agents/codex-app-server/adapter.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts +116 -0
- package/dist/types/core/agents/codex-app-server/client.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts +113 -0
- package/dist/types/core/agents/codex-app-server/codex-agent.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts +66 -0
- package/dist/types/core/agents/codex-app-server/commands.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts +49 -0
- package/dist/types/core/agents/codex-app-server/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts +12 -0
- package/dist/types/core/agents/codex-app-server/effort.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts +45 -0
- package/dist/types/core/agents/codex-app-server/events.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts +20 -0
- package/dist/types/core/agents/codex-app-server/homes.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts +26 -0
- package/dist/types/core/agents/codex-app-server/input.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts +31 -0
- package/dist/types/core/agents/codex-app-server/items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts +38 -0
- package/dist/types/core/agents/codex-app-server/login.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts +62 -0
- package/dist/types/core/agents/codex-app-server/mcp.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts +67 -0
- package/dist/types/core/agents/codex-app-server/models.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts +40 -0
- package/dist/types/core/agents/codex-app-server/options.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts +19 -0
- package/dist/types/core/agents/codex-app-server/plan-approval.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts +99 -0
- package/dist/types/core/agents/codex-app-server/protocol.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts +42 -0
- package/dist/types/core/agents/codex-app-server/requests.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts +96 -0
- package/dist/types/core/agents/codex-app-server/session.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts +53 -0
- package/dist/types/core/agents/codex-app-server/subagents.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts +87 -0
- package/dist/types/core/agents/codex-app-server/thread-settings.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts +33 -0
- package/dist/types/core/agents/codex-app-server/turn-items.d.ts.map +1 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts +163 -0
- package/dist/types/core/agents/codex-app-server/turn.d.ts.map +1 -0
- package/dist/types/core/agents/config-fingerprint.d.ts +5 -0
- package/dist/types/core/agents/config-fingerprint.d.ts.map +1 -0
- package/dist/types/core/agents/credentials.d.ts +28 -0
- package/dist/types/core/agents/credentials.d.ts.map +1 -0
- package/dist/types/core/agents/elicitation.d.ts +37 -0
- package/dist/types/core/agents/elicitation.d.ts.map +1 -0
- package/dist/types/core/agents/inherit-config.d.ts +18 -0
- package/dist/types/core/agents/inherit-config.d.ts.map +1 -0
- package/dist/types/core/agents/login.d.ts +67 -0
- package/dist/types/core/agents/login.d.ts.map +1 -0
- package/dist/types/core/agents/mcp-config.d.ts +57 -0
- package/dist/types/core/agents/mcp-config.d.ts.map +1 -0
- package/dist/types/core/agents/plan.d.ts +16 -0
- package/dist/types/core/agents/plan.d.ts.map +1 -0
- package/dist/types/core/agents/registry.d.ts +30 -0
- package/dist/types/core/agents/registry.d.ts.map +1 -0
- package/dist/types/core/agents/session-agent.d.ts +48 -0
- package/dist/types/core/agents/session-agent.d.ts.map +1 -0
- package/dist/types/core/agents/session-pool.d.ts +41 -0
- package/dist/types/core/agents/session-pool.d.ts.map +1 -0
- package/dist/types/core/agents/stderr-tail.d.ts +28 -0
- package/dist/types/core/agents/stderr-tail.d.ts.map +1 -0
- package/dist/types/core/agents/thinking-levels.d.ts +4 -0
- package/dist/types/core/agents/thinking-levels.d.ts.map +1 -0
- package/dist/types/core/agents/types.d.ts +124 -0
- package/dist/types/core/agents/types.d.ts.map +1 -0
- package/dist/types/core/diagnostics.d.ts +36 -0
- package/dist/types/core/diagnostics.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +29 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/core/presets.d.ts +80 -0
- package/dist/types/core/presets.d.ts.map +1 -0
- package/dist/types/core/processes/identity.d.ts +31 -0
- package/dist/types/core/processes/identity.d.ts.map +1 -0
- package/dist/types/core/processes/lifeline.d.ts +47 -0
- package/dist/types/core/processes/lifeline.d.ts.map +1 -0
- package/dist/types/core/processes/native-processes.d.ts +130 -0
- package/dist/types/core/processes/native-processes.d.ts.map +1 -0
- package/dist/types/core/processes/process-table.d.ts +43 -0
- package/dist/types/core/processes/process-table.d.ts.map +1 -0
- package/dist/types/core/provision/cache-trust.d.ts +13 -0
- package/dist/types/core/provision/cache-trust.d.ts.map +1 -0
- package/dist/types/core/provision/cache-usage.d.ts +14 -0
- package/dist/types/core/provision/cache-usage.d.ts.map +1 -0
- package/dist/types/core/provision/checksums.d.ts +46 -0
- package/dist/types/core/provision/checksums.d.ts.map +1 -0
- package/dist/types/core/provision/extract.d.ts +7 -0
- package/dist/types/core/provision/extract.d.ts.map +1 -0
- package/dist/types/core/provision/index.d.ts +5 -0
- package/dist/types/core/provision/index.d.ts.map +1 -0
- package/dist/types/core/provision/install-build.d.ts +36 -0
- package/dist/types/core/provision/install-build.d.ts.map +1 -0
- package/dist/types/core/provision/npm.d.ts +40 -0
- package/dist/types/core/provision/npm.d.ts.map +1 -0
- package/dist/types/core/provision/pins.d.ts +24 -0
- package/dist/types/core/provision/pins.d.ts.map +1 -0
- package/dist/types/core/provision/platform.d.ts +28 -0
- package/dist/types/core/provision/platform.d.ts.map +1 -0
- package/dist/types/core/provision/provisioner.d.ts +189 -0
- package/dist/types/core/provision/provisioner.d.ts.map +1 -0
- package/dist/types/core/provision/releases.d.ts +8 -0
- package/dist/types/core/provision/releases.d.ts.map +1 -0
- package/dist/types/core/provision/tools.d.ts +81 -0
- package/dist/types/core/provision/tools.d.ts.map +1 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts +52 -0
- package/dist/types/core/proxy/anthropic-proxy.d.ts.map +1 -0
- package/dist/types/core/proxy/api-key-store.d.ts +37 -0
- package/dist/types/core/proxy/api-key-store.d.ts.map +1 -0
- package/dist/types/core/proxy/index.d.ts +3 -0
- package/dist/types/core/proxy/index.d.ts.map +1 -0
- package/dist/types/core/proxy/loopback.d.ts +14 -0
- package/dist/types/core/proxy/loopback.d.ts.map +1 -0
- package/dist/types/core/runtime/agent-runtime.d.ts +181 -0
- package/dist/types/core/runtime/agent-runtime.d.ts.map +1 -0
- package/dist/types/core/runtime/event-processor.d.ts +87 -0
- package/dist/types/core/runtime/event-processor.d.ts.map +1 -0
- package/dist/types/core/runtime/event-sink.d.ts +44 -0
- package/dist/types/core/runtime/event-sink.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-clis.d.ts +10 -0
- package/dist/types/core/runtime/harness-clis.d.ts.map +1 -0
- package/dist/types/core/runtime/harness-logins.d.ts +68 -0
- package/dist/types/core/runtime/harness-logins.d.ts.map +1 -0
- package/dist/types/core/runtime/login-reads.d.ts +28 -0
- package/dist/types/core/runtime/login-reads.d.ts.map +1 -0
- package/dist/types/core/runtime/model-lists.d.ts +37 -0
- package/dist/types/core/runtime/model-lists.d.ts.map +1 -0
- package/dist/types/core/runtime/permission-policy.d.ts +61 -0
- package/dist/types/core/runtime/permission-policy.d.ts.map +1 -0
- package/dist/types/core/runtime/request-broker.d.ts +49 -0
- package/dist/types/core/runtime/request-broker.d.ts.map +1 -0
- package/dist/types/core/runtime/steering.d.ts +38 -0
- package/dist/types/core/runtime/steering.d.ts.map +1 -0
- package/dist/types/core/runtime/turn-outcome.d.ts +21 -0
- package/dist/types/core/runtime/turn-outcome.d.ts.map +1 -0
- package/dist/types/core/runtime/turn.d.ts +121 -0
- package/dist/types/core/runtime/turn.d.ts.map +1 -0
- package/dist/types/core/utils/bounded.d.ts +6 -0
- package/dist/types/core/utils/bounded.d.ts.map +1 -0
- package/dist/types/core/utils/deadline.d.ts +14 -0
- package/dist/types/core/utils/deadline.d.ts.map +1 -0
- package/dist/types/core/utils/errors.d.ts +104 -0
- package/dist/types/core/utils/errors.d.ts.map +1 -0
- package/dist/types/core/utils/is-record.d.ts +3 -0
- package/dist/types/core/utils/is-record.d.ts.map +1 -0
- package/dist/types/core/utils/loopback.d.ts +6 -0
- package/dist/types/core/utils/loopback.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/protocol/account.d.ts +26 -0
- package/dist/types/protocol/account.d.ts.map +1 -0
- package/dist/types/protocol/async-queue.d.ts +21 -0
- package/dist/types/protocol/async-queue.d.ts.map +1 -0
- package/dist/types/protocol/auth.d.ts +228 -0
- package/dist/types/protocol/auth.d.ts.map +1 -0
- package/dist/types/protocol/canonical.d.ts +9 -0
- package/dist/types/protocol/canonical.d.ts.map +1 -0
- package/dist/types/protocol/clis.d.ts +74 -0
- package/dist/types/protocol/clis.d.ts.map +1 -0
- package/dist/types/protocol/config.d.ts +200 -0
- package/dist/types/protocol/config.d.ts.map +1 -0
- package/dist/types/protocol/conversation.d.ts +942 -0
- package/dist/types/protocol/conversation.d.ts.map +1 -0
- package/dist/types/protocol/credentials.d.ts +145 -0
- package/dist/types/protocol/credentials.d.ts.map +1 -0
- package/dist/types/protocol/errors.d.ts +36 -0
- package/dist/types/protocol/errors.d.ts.map +1 -0
- package/dist/types/protocol/execution.d.ts +28 -0
- package/dist/types/protocol/execution.d.ts.map +1 -0
- package/dist/types/protocol/factories.d.ts +94 -0
- package/dist/types/protocol/factories.d.ts.map +1 -0
- package/dist/types/protocol/guards.d.ts +55 -0
- package/dist/types/protocol/guards.d.ts.map +1 -0
- package/dist/types/protocol/harness.d.ts +70 -0
- package/dist/types/protocol/harness.d.ts.map +1 -0
- package/dist/types/protocol/history.d.ts +318 -0
- package/dist/types/protocol/history.d.ts.map +1 -0
- package/dist/types/protocol/ids.d.ts +9 -0
- package/dist/types/protocol/ids.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +35 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/lifecycle.d.ts +1190 -0
- package/dist/types/protocol/lifecycle.d.ts.map +1 -0
- package/dist/types/protocol/meta-keys.d.ts +17 -0
- package/dist/types/protocol/meta-keys.d.ts.map +1 -0
- package/dist/types/protocol/meta.d.ts +13 -0
- package/dist/types/protocol/meta.d.ts.map +1 -0
- package/dist/types/protocol/model-catalog.d.ts +11 -0
- package/dist/types/protocol/model-catalog.d.ts.map +1 -0
- package/dist/types/protocol/models.d.ts +107 -0
- package/dist/types/protocol/models.d.ts.map +1 -0
- package/dist/types/protocol/part-input.d.ts +101 -0
- package/dist/types/protocol/part-input.d.ts.map +1 -0
- package/dist/types/protocol/parts.d.ts +357 -0
- package/dist/types/protocol/parts.d.ts.map +1 -0
- package/dist/types/protocol/reduce.d.ts +26 -0
- package/dist/types/protocol/reduce.d.ts.map +1 -0
- package/dist/types/protocol/selectors.d.ts +64 -0
- package/dist/types/protocol/selectors.d.ts.map +1 -0
- package/dist/types/protocol/seq-cursor.d.ts +66 -0
- package/dist/types/protocol/seq-cursor.d.ts.map +1 -0
- package/dist/types/protocol/stop-reasons.d.ts +33 -0
- package/dist/types/protocol/stop-reasons.d.ts.map +1 -0
- package/dist/types/protocol/thinking.d.ts +28 -0
- package/dist/types/protocol/thinking.d.ts.map +1 -0
- package/dist/types/protocol/time.d.ts +21 -0
- package/dist/types/protocol/time.d.ts.map +1 -0
- package/dist/types/protocol/tokens.d.ts +29 -0
- package/dist/types/protocol/tokens.d.ts.map +1 -0
- package/dist/types/protocol/tool-closure.d.ts +25 -0
- package/dist/types/protocol/tool-closure.d.ts.map +1 -0
- package/dist/types/protocol/tool-state.d.ts +209 -0
- package/dist/types/protocol/tool-state.d.ts.map +1 -0
- package/dist/types/protocol/verify.d.ts +52 -0
- package/dist/types/protocol/verify.d.ts.map +1 -0
- package/dist/types/protocol/vocabulary.d.ts +19 -0
- package/dist/types/protocol/vocabulary.d.ts.map +1 -0
- package/dist/types/protocol/wire-api.d.ts +1983 -0
- package/dist/types/protocol/wire-api.d.ts.map +1 -0
- package/dist/types/protocol/wire.d.ts +1758 -0
- package/dist/types/protocol/wire.d.ts.map +1 -0
- package/dist/types/server/acp/binding.d.ts +33 -0
- package/dist/types/server/acp/binding.d.ts.map +1 -0
- package/dist/types/server/acp/session-records.d.ts +17 -0
- package/dist/types/server/acp/session-records.d.ts.map +1 -0
- package/dist/types/server/acp/translate.d.ts +48 -0
- package/dist/types/server/acp/translate.d.ts.map +1 -0
- package/dist/types/server/agent-server.d.ts +121 -0
- package/dist/types/server/agent-server.d.ts.map +1 -0
- package/dist/types/server/feedback.d.ts +37 -0
- package/dist/types/server/feedback.d.ts.map +1 -0
- package/dist/types/server/history.d.ts +15 -0
- package/dist/types/server/history.d.ts.map +1 -0
- package/dist/types/server/index.d.ts +7 -0
- package/dist/types/server/index.d.ts.map +1 -0
- package/dist/types/server/install.d.ts +42 -0
- package/dist/types/server/install.d.ts.map +1 -0
- package/dist/types/server/open-parts.d.ts +27 -0
- package/dist/types/server/open-parts.d.ts.map +1 -0
- package/dist/types/server/routes.d.ts +61 -0
- package/dist/types/server/routes.d.ts.map +1 -0
- package/dist/types/server/secrets.d.ts +11 -0
- package/dist/types/server/secrets.d.ts.map +1 -0
- package/dist/types/server/session-gate.d.ts +32 -0
- package/dist/types/server/session-gate.d.ts.map +1 -0
- package/dist/types/server/session-log.d.ts +39 -0
- package/dist/types/server/session-log.d.ts.map +1 -0
- package/dist/types/server/session-store.d.ts +119 -0
- package/dist/types/server/session-store.d.ts.map +1 -0
- package/dist/types/server/subscriptions.d.ts +74 -0
- package/dist/types/server/subscriptions.d.ts.map +1 -0
- package/dist/types/server/transports.d.ts +74 -0
- package/dist/types/server/transports.d.ts.map +1 -0
- package/dist/types/server/wire-error.d.ts +9 -0
- package/dist/types/server/wire-error.d.ts.map +1 -0
- package/dist/types/sync/event-log.d.ts +45 -0
- package/dist/types/sync/event-log.d.ts.map +1 -0
- package/dist/types/sync/fit.d.ts +40 -0
- package/dist/types/sync/fit.d.ts.map +1 -0
- package/dist/types/sync/history-reader.d.ts +8 -0
- package/dist/types/sync/history-reader.d.ts.map +1 -0
- package/dist/types/sync/history-sqlite.d.ts +37 -0
- package/dist/types/sync/history-sqlite.d.ts.map +1 -0
- package/dist/types/sync/history.d.ts +70 -0
- package/dist/types/sync/history.d.ts.map +1 -0
- package/dist/types/sync/index.d.ts +4 -0
- package/dist/types/sync/index.d.ts.map +1 -0
- package/dist/types/sync/journal-sqlite.d.ts +51 -0
- package/dist/types/sync/journal-sqlite.d.ts.map +1 -0
- package/dist/types/sync/journal.d.ts +107 -0
- package/dist/types/sync/journal.d.ts.map +1 -0
- package/dist/types/sync/live-tails.d.ts +30 -0
- package/dist/types/sync/live-tails.d.ts.map +1 -0
- package/dist/types/sync/node-sqlite.d.ts +7 -0
- package/dist/types/sync/node-sqlite.d.ts.map +1 -0
- package/dist/types/sync/projection.d.ts +10 -0
- package/dist/types/sync/projection.d.ts.map +1 -0
- package/dist/types/sync/recovery.d.ts +25 -0
- package/dist/types/sync/recovery.d.ts.map +1 -0
- package/dist/types/sync/retry.d.ts +25 -0
- package/dist/types/sync/retry.d.ts.map +1 -0
- package/dist/types/sync/schema.d.ts +4 -0
- package/dist/types/sync/schema.d.ts.map +1 -0
- package/dist/types/sync/sql.d.ts +38 -0
- package/dist/types/sync/sql.d.ts.map +1 -0
- package/dist/types/sync/sqlite-file.d.ts +9 -0
- package/dist/types/sync/sqlite-file.d.ts.map +1 -0
- package/dist/types/sync/sqlite.d.ts +6 -0
- package/dist/types/sync/sqlite.d.ts.map +1 -0
- package/dist/types/sync/worker.d.ts +63 -0
- package/dist/types/sync/worker.d.ts.map +1 -0
- package/docs/consuming.md +452 -53
- package/docs/deploy.md +218 -47
- package/docs/{sync-experiment.md → durable-sessions.md} +77 -72
- package/docs/feedback.md +116 -0
- package/docs/harnesses.md +212 -88
- package/docs/sync-history.md +29 -13
- package/docs/sync-integration.md +52 -66
- package/package.json +45 -28
- package/src/accounts/chatgpt.ts +194 -0
- package/src/accounts/check.ts +112 -0
- package/src/accounts/claude.ts +111 -0
- package/src/accounts/endpoint.ts +151 -0
- package/src/accounts/http.ts +97 -0
- package/src/accounts/index.ts +19 -0
- package/src/client/client.ts +604 -670
- package/src/client/connection.ts +371 -0
- package/src/client/history.ts +29 -52
- package/src/client/index.ts +11 -2
- package/src/client/listeners.ts +20 -0
- package/src/client/logins.ts +105 -0
- package/src/client/rpc.ts +155 -0
- package/src/client/streams.ts +488 -0
- package/src/client/transports.ts +62 -8
- package/src/client/turns.ts +171 -0
- package/src/core/agents/acp/acp-agent.ts +94 -118
- package/src/core/agents/acp/adapter.ts +20 -9
- package/src/core/agents/acp/client.ts +125 -47
- package/src/core/agents/acp/known-agents.ts +36 -4
- package/src/core/agents/acp/mappings.ts +64 -18
- package/src/core/agents/acp/requests.ts +125 -0
- package/src/core/agents/attachments.ts +18 -0
- package/src/core/agents/base.ts +120 -42
- package/src/core/agents/claude-code/adapter.ts +177 -238
- package/src/core/agents/claude-code/approvals.ts +270 -0
- package/src/core/agents/claude-code/claude-agent.ts +175 -158
- package/src/core/agents/claude-code/credentials.ts +171 -0
- package/src/core/agents/claude-code/events.ts +55 -0
- package/src/core/agents/claude-code/login.ts +269 -0
- package/src/core/agents/claude-code/mcp.ts +206 -0
- package/src/core/agents/claude-code/models.ts +15 -9
- package/src/core/agents/claude-code/options.ts +326 -39
- package/src/core/agents/claude-code/outcome.ts +209 -0
- package/src/core/agents/claude-code/session-pool.ts +136 -0
- package/src/core/agents/claude-code/session.ts +513 -0
- package/src/core/agents/claude-code/spawn.ts +144 -0
- package/src/core/agents/claude-code/spend.ts +160 -0
- package/src/core/agents/claude-code/tools.ts +47 -0
- package/src/core/agents/claude-code/turn-usage.ts +135 -0
- package/src/core/agents/claude-code/turn.ts +232 -0
- package/src/core/agents/codex-app-server/adapter.ts +314 -117
- package/src/core/agents/codex-app-server/client.ts +186 -84
- package/src/core/agents/codex-app-server/codex-agent.ts +343 -0
- package/src/core/agents/codex-app-server/commands.ts +228 -0
- package/src/core/agents/codex-app-server/credentials.ts +126 -0
- package/src/core/agents/codex-app-server/effort.ts +29 -0
- package/src/core/agents/codex-app-server/events.ts +47 -0
- package/src/core/agents/codex-app-server/homes.ts +64 -0
- package/src/core/agents/codex-app-server/input.ts +60 -0
- package/src/core/agents/codex-app-server/items.ts +149 -0
- package/src/core/agents/codex-app-server/login.ts +180 -0
- package/src/core/agents/codex-app-server/mcp.ts +182 -37
- package/src/core/agents/codex-app-server/models.ts +99 -46
- package/src/core/agents/codex-app-server/options.ts +146 -0
- package/src/core/agents/codex-app-server/plan-approval.ts +135 -0
- package/src/core/agents/codex-app-server/protocol.ts +117 -0
- package/src/core/agents/codex-app-server/requests.ts +332 -0
- package/src/core/agents/codex-app-server/session.ts +285 -0
- package/src/core/agents/codex-app-server/subagents.ts +108 -42
- package/src/core/agents/codex-app-server/thread-settings.ts +279 -0
- package/src/core/agents/codex-app-server/turn-items.ts +88 -0
- package/src/core/agents/codex-app-server/turn.ts +463 -0
- package/src/core/agents/config-fingerprint.ts +7 -14
- package/src/core/agents/credentials.ts +98 -0
- package/src/core/agents/elicitation.ts +75 -0
- package/src/core/agents/inherit-config.ts +21 -0
- package/src/core/agents/login.ts +116 -0
- package/src/core/agents/mcp-config.ts +112 -8
- package/src/core/agents/plan.ts +25 -0
- package/src/core/agents/registry.ts +21 -4
- package/src/core/agents/session-agent.ts +96 -4
- package/src/core/agents/{session-store.ts → session-pool.ts} +11 -5
- package/src/core/agents/stderr-tail.ts +75 -0
- package/src/core/agents/types.ts +40 -5
- package/src/core/index.ts +58 -48
- package/src/core/presets.ts +100 -39
- package/src/core/processes/identity.ts +113 -0
- package/src/core/processes/lifeline.ts +170 -0
- package/src/core/processes/native-processes.ts +379 -0
- package/src/core/processes/process-table.ts +174 -0
- package/src/core/provision/cache-trust.ts +121 -0
- package/src/core/provision/cache-usage.ts +69 -0
- package/src/core/provision/checksums.ts +64 -0
- package/src/core/provision/extract.ts +11 -2
- package/src/core/provision/index.ts +4 -1
- package/src/core/provision/install-build.ts +136 -0
- package/src/core/provision/npm.ts +112 -17
- package/src/core/provision/pins.ts +9 -33
- package/src/core/provision/platform.ts +12 -1
- package/src/core/provision/provisioner.ts +329 -397
- package/src/core/provision/releases.ts +86 -0
- package/src/core/provision/tools.ts +329 -0
- package/src/core/proxy/anthropic-proxy.ts +55 -25
- package/src/core/proxy/api-key-store.ts +2 -12
- package/src/core/proxy/loopback.ts +106 -0
- package/src/core/runtime/agent-runtime.ts +327 -498
- package/src/core/runtime/event-processor.ts +197 -70
- package/src/core/runtime/harness-clis.ts +61 -0
- package/src/core/runtime/harness-logins.ts +328 -0
- package/src/core/runtime/login-reads.ts +78 -0
- package/src/core/runtime/model-lists.ts +33 -48
- package/src/core/runtime/permission-policy.ts +113 -0
- package/src/core/runtime/request-broker.ts +204 -0
- package/src/core/runtime/steering.ts +112 -0
- package/src/core/runtime/turn-outcome.ts +30 -0
- package/src/core/runtime/turn.ts +360 -0
- package/src/core/utils/bounded.ts +12 -0
- package/src/core/utils/deadline.ts +38 -0
- package/src/core/utils/errors.ts +113 -21
- package/src/core/utils/is-record.ts +4 -0
- package/src/core/utils/loopback.ts +10 -0
- package/src/protocol/account.ts +104 -0
- package/src/protocol/auth.ts +199 -0
- package/src/protocol/canonical.ts +16 -0
- package/src/protocol/clis.ts +69 -0
- package/src/protocol/config.ts +60 -6
- package/src/protocol/conversation.ts +272 -0
- package/src/protocol/credentials.ts +145 -0
- package/src/protocol/errors.ts +78 -20
- package/src/protocol/execution.ts +5 -2
- package/src/protocol/factories.ts +55 -7
- package/src/protocol/guards.ts +55 -2
- package/src/protocol/harness.ts +56 -6
- package/src/protocol/history.ts +72 -64
- package/src/protocol/ids.ts +0 -12
- package/src/protocol/index.ts +9 -0
- package/src/protocol/lifecycle.ts +250 -79
- package/src/protocol/meta-keys.ts +17 -0
- package/src/protocol/meta.ts +3 -3
- package/src/protocol/models.ts +2 -43
- package/src/protocol/part-input.ts +2 -1
- package/src/protocol/parts.ts +12 -3
- package/src/protocol/reduce.ts +302 -413
- package/src/protocol/selectors.ts +1 -20
- package/src/protocol/seq-cursor.ts +14 -0
- package/src/protocol/stop-reasons.ts +1 -1
- package/src/protocol/thinking.ts +1 -30
- package/src/protocol/time.ts +2 -2
- package/src/protocol/tool-closure.ts +93 -0
- package/src/protocol/tool-state.ts +19 -4
- package/src/protocol/verify.ts +222 -92
- package/src/protocol/vocabulary.ts +21 -5
- package/src/protocol/wire-api.ts +232 -0
- package/src/protocol/wire.ts +351 -64
- package/src/server/acp/binding.ts +63 -103
- package/src/server/acp/session-records.ts +53 -0
- package/src/server/acp/translate.ts +129 -20
- package/src/server/agent-server.ts +223 -387
- package/src/server/bin.ts +280 -78
- package/src/server/feedback.ts +204 -14
- package/src/server/history.ts +116 -122
- package/src/server/index.ts +3 -8
- package/src/server/install.ts +107 -8
- package/src/server/open-parts.ts +95 -0
- package/src/server/routes.ts +391 -0
- package/src/server/secrets.ts +24 -0
- package/src/server/session-gate.ts +69 -0
- package/src/server/session-log.ts +14 -2
- package/src/server/session-store.ts +136 -72
- package/src/server/subscriptions.ts +232 -0
- package/src/server/transports.ts +125 -25
- package/src/server/wire-error.ts +31 -45
- package/src/sync/event-log.ts +31 -3
- package/src/sync/fit.ts +27 -11
- package/src/sync/history-reader.ts +10 -5
- package/src/sync/history-sqlite.ts +37 -42
- package/src/sync/history.ts +9 -15
- package/src/sync/index.ts +17 -5
- package/src/sync/journal-sqlite.ts +162 -76
- package/src/sync/journal.ts +91 -32
- package/src/sync/live-tails.ts +107 -0
- package/src/sync/projection.ts +35 -0
- package/src/sync/recovery.ts +80 -51
- package/src/sync/schema.ts +27 -6
- package/docs/rfds/0001-deterministic-echo-ids.md +0 -44
- package/docs/rfds/0002-native-subagents.md +0 -197
- package/src/client/request.ts +0 -19
- package/src/core/agents/claude-code/generator-session.ts +0 -572
- package/src/core/agents/claude-code/session-manager.ts +0 -166
- package/src/core/agents/codex-app-server/codex-app-server-agent.ts +0 -962
- package/src/core/agents/codex-items.ts +0 -149
- package/src/core/agents/codex-sdk/adapter.ts +0 -237
- package/src/core/agents/codex-sdk/codex-sdk-agent.ts +0 -330
- package/src/core/agents/tool-meta.ts +0 -68
package/src/sync/history.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
CONVERSATION_CHECKPOINT_FORMAT,
|
|
3
3
|
type ConversationState,
|
|
4
4
|
ConversationStateSchema,
|
|
5
|
-
HISTORY_MAX_BYTES,
|
|
6
5
|
type HistoryApi,
|
|
7
6
|
type HistoryArchive,
|
|
8
7
|
HistoryCheckpointSchema,
|
|
@@ -11,14 +10,13 @@ import {
|
|
|
11
10
|
type HistorySlice,
|
|
12
11
|
type HistoryVersion,
|
|
13
12
|
type SessionRef,
|
|
14
|
-
decodeLifecycleEvent,
|
|
15
13
|
emptyConversation,
|
|
16
14
|
jsonBytes,
|
|
17
|
-
reduceConversation,
|
|
18
15
|
sameHistory,
|
|
19
16
|
sameVersion,
|
|
20
17
|
} from "../protocol/index.ts";
|
|
21
18
|
import { historyPath, readHistoryPage } from "./history-reader.ts";
|
|
19
|
+
import { checkCheckpointBytes, projectionFold } from "./projection.ts";
|
|
22
20
|
import { RetryBudget, type RetryPolicy, idleAfter, pause } from "./retry.ts";
|
|
23
21
|
|
|
24
22
|
export interface HistoryTransferOptions {
|
|
@@ -41,7 +39,8 @@ function checkBudget(name: string, value: number | undefined) {
|
|
|
41
39
|
if (value !== undefined && (!Number.isSafeInteger(value) || value < 0))
|
|
42
40
|
throw new Error(`${name} must be a nonnegative safe integer`);
|
|
43
41
|
}
|
|
44
|
-
const missing = (error: unknown) =>
|
|
42
|
+
const missing = (error: unknown) =>
|
|
43
|
+
error instanceof HistoryError && error.code === "unknownHistory";
|
|
45
44
|
/** Pull from source into a durable destination, or push by passing a remote
|
|
46
45
|
* destination. The destination's committed prefix is authoritative after lost ACKs.
|
|
47
46
|
* Ancestors are copied only through the fork's pinned version. A destination
|
|
@@ -101,7 +100,8 @@ export async function transferHistory(
|
|
|
101
100
|
return { version, complete: false, ...stats };
|
|
102
101
|
options.signal?.throwIfAborted();
|
|
103
102
|
const receipt = await destination.import(page);
|
|
104
|
-
if (!sameVersion(receipt, page.next))
|
|
103
|
+
if (!sameVersion(receipt, page.next))
|
|
104
|
+
throw new HistoryError("historyConflict", "History receipt mismatch");
|
|
105
105
|
stats.pages++;
|
|
106
106
|
stats.bytes += bytes;
|
|
107
107
|
stats.records += page.records.length;
|
|
@@ -187,9 +187,8 @@ export async function openHistory(
|
|
|
187
187
|
ref: SessionRef,
|
|
188
188
|
options: { signal?: AbortSignal; maxRecords?: number; checkpoints?: boolean } = {},
|
|
189
189
|
) {
|
|
190
|
-
|
|
190
|
+
const fold = projectionFold(options.maxRecords);
|
|
191
191
|
const segments: { version: HistoryVersion; conversation: ConversationState }[] = [];
|
|
192
|
-
let records = 0;
|
|
193
192
|
for (const target of await historyPath(source, ref, options.signal)) {
|
|
194
193
|
let after: HistoryVersion | undefined;
|
|
195
194
|
let conversation = emptyConversation();
|
|
@@ -197,10 +196,9 @@ export async function openHistory(
|
|
|
197
196
|
const value = await source.checkpoint({ through: target });
|
|
198
197
|
if (value) {
|
|
199
198
|
const checkpoint = HistoryCheckpointSchema.parse(value);
|
|
200
|
-
|
|
201
|
-
throw new Error("Checkpoint exceeds byte limit");
|
|
199
|
+
checkCheckpointBytes(checkpoint);
|
|
202
200
|
if (!sameHistory(checkpoint.version, target) || checkpoint.version.seq > target.seq)
|
|
203
|
-
throw new
|
|
201
|
+
throw new HistoryError("invalidParams", "Checkpoint is outside the requested history");
|
|
204
202
|
if (checkpoint.format === CONVERSATION_CHECKPOINT_FORMAT) {
|
|
205
203
|
// Bind the cached state to an available prefix before applying its tail.
|
|
206
204
|
await source.read({ ...target, after: checkpoint.version, through: checkpoint.version });
|
|
@@ -212,11 +210,7 @@ export async function openHistory(
|
|
|
212
210
|
for (;;) {
|
|
213
211
|
options.signal?.throwIfAborted();
|
|
214
212
|
const page = await readHistoryPage(source, { ...target, after, through: target });
|
|
215
|
-
|
|
216
|
-
if (records > (options.maxRecords ?? 100_000))
|
|
217
|
-
throw new Error("History projection limit exceeded; use paged reads");
|
|
218
|
-
for (const record of page.records)
|
|
219
|
-
conversation = reduceConversation(conversation, decodeLifecycleEvent(record.event));
|
|
213
|
+
for (const record of page.records) conversation = fold(conversation, record.event);
|
|
220
214
|
after = page.next;
|
|
221
215
|
if (!page.hasMore) break;
|
|
222
216
|
}
|
package/src/sync/index.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
// Storage/transport-neutral host contracts. SQLite is an optional subpath.
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
export { JournalError, type SessionJournal } from "./journal.ts";
|
|
3
|
+
export {
|
|
4
|
+
type FollowHistoryOptions,
|
|
5
|
+
type HistoryTransfer,
|
|
6
|
+
type HistoryTransferOptions,
|
|
7
|
+
followHistory,
|
|
8
|
+
openHistory,
|
|
9
|
+
transferHistory,
|
|
10
|
+
} from "./history.ts";
|
|
11
|
+
export {
|
|
12
|
+
type HistorySync,
|
|
13
|
+
type HistorySyncOptions,
|
|
14
|
+
type HistorySyncState,
|
|
15
|
+
type HistorySyncStatus,
|
|
16
|
+
type SyncBarrierOptions,
|
|
17
|
+
startHistorySync,
|
|
18
|
+
} from "./worker.ts";
|
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import {
|
|
3
2
|
type AgentHarness,
|
|
4
3
|
type DurableSession,
|
|
5
|
-
HISTORY_MAX_BYTES,
|
|
6
4
|
HISTORY_MAX_RECORDS,
|
|
7
5
|
type LifecycleEvent,
|
|
6
|
+
type MessagePartDeltaEvent,
|
|
7
|
+
type RecoveryReason,
|
|
8
8
|
type RunRequest,
|
|
9
9
|
type SessionRef,
|
|
10
10
|
type TurnEndedEvent,
|
|
11
11
|
type TurnReceipt,
|
|
12
12
|
type WireEventEnvelope,
|
|
13
|
-
|
|
13
|
+
canonicalJson as canonical,
|
|
14
14
|
generateUUIDv7,
|
|
15
|
+
isLiveOnlyEvent,
|
|
16
|
+
turnIdentity,
|
|
15
17
|
} from "../protocol/index.ts";
|
|
16
|
-
import { EventLog } from "./event-log.ts";
|
|
17
|
-
import { MAX_EVENT_BYTES, recordable } from "./fit.ts";
|
|
18
|
+
import { EventLog, sha256 } from "./event-log.ts";
|
|
19
|
+
import { MAX_EVENT_BYTES, REPLAY_PAGE_BYTES, type SessionEvent, recordable } from "./fit.ts";
|
|
18
20
|
import { SqliteHistory } from "./history-sqlite.ts";
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
+
import {
|
|
22
|
+
type ClaimOptions,
|
|
23
|
+
JournalError,
|
|
24
|
+
type NativeProcessRecord,
|
|
25
|
+
type SessionJournal,
|
|
26
|
+
type StoredNativeProcess,
|
|
27
|
+
} from "./journal.ts";
|
|
28
|
+
import { LiveTails } from "./live-tails.ts";
|
|
29
|
+
import { recoveryFacts } from "./recovery.ts";
|
|
21
30
|
import { openSchema } from "./schema.ts";
|
|
22
31
|
import { Db, type SqlConnection } from "./sql.ts";
|
|
23
32
|
|
|
24
|
-
const fingerprint = (request: RunRequest) =>
|
|
25
|
-
createHash("sha256")
|
|
26
|
-
.update(canonical({ input: request.input, config: request.config }))
|
|
27
|
-
.digest("hex");
|
|
33
|
+
const fingerprint = (request: RunRequest) => sha256(canonical(turnIdentity(request)));
|
|
28
34
|
/** Ids name histories, whose wire schema bounds them. */
|
|
29
35
|
const storableId = (value: string) => value.length > 0 && value.length <= 512;
|
|
30
36
|
type SessionRow = {
|
|
@@ -33,9 +39,24 @@ type SessionRow = {
|
|
|
33
39
|
native_id: string | null;
|
|
34
40
|
closed: number;
|
|
35
41
|
recovery_required: number;
|
|
42
|
+
recovery_reason: RecoveryReason | null;
|
|
36
43
|
head_seq: number;
|
|
37
44
|
};
|
|
38
|
-
type
|
|
45
|
+
type NativeRow = {
|
|
46
|
+
id: number;
|
|
47
|
+
session_id: string;
|
|
48
|
+
harness: AgentHarness;
|
|
49
|
+
pid: number | null;
|
|
50
|
+
boot: string | null;
|
|
51
|
+
started: string | null;
|
|
52
|
+
executable: string;
|
|
53
|
+
};
|
|
54
|
+
/** Which reason a session's fence names when several of its records leave it fenced. */
|
|
55
|
+
const REASON_WEIGHT: Record<RecoveryReason, number> = {
|
|
56
|
+
not_owned: 1,
|
|
57
|
+
not_verified: 2,
|
|
58
|
+
not_stopped: 3,
|
|
59
|
+
};
|
|
39
60
|
|
|
40
61
|
/** The journal over any synchronous SQLite connection: the Bun and Node
|
|
41
62
|
* adapters open a private, exclusively locked file for it (`openJournalFile`).
|
|
@@ -49,6 +70,7 @@ export class SqliteJournal implements SessionJournal {
|
|
|
49
70
|
private claimed = false;
|
|
50
71
|
/** Sessions whose native conversation this owner has started or resumed. */
|
|
51
72
|
private readonly live = new Set<string>();
|
|
73
|
+
private readonly tails: LiveTails;
|
|
52
74
|
|
|
53
75
|
constructor(connection: SqlConnection) {
|
|
54
76
|
this.db = new Db(connection);
|
|
@@ -56,6 +78,7 @@ export class SqliteJournal implements SessionJournal {
|
|
|
56
78
|
this.sourceId = openSchema(this.db, generateUUIDv7);
|
|
57
79
|
this.log = new EventLog(this.db);
|
|
58
80
|
this.history = new SqliteHistory(this.sourceId, this.db, this.log);
|
|
81
|
+
this.tails = new LiveTails(this.db);
|
|
59
82
|
} catch (error) {
|
|
60
83
|
this.db.close();
|
|
61
84
|
throw error;
|
|
@@ -65,9 +88,9 @@ export class SqliteJournal implements SessionJournal {
|
|
|
65
88
|
return { sourceId: this.sourceId, sessionId };
|
|
66
89
|
}
|
|
67
90
|
|
|
68
|
-
claim(): () => void {
|
|
91
|
+
claim(options: ClaimOptions = {}): () => void {
|
|
69
92
|
if (this.claimed) throw new Error("Journal already has an executing owner");
|
|
70
|
-
this.recoverInterrupted();
|
|
93
|
+
this.recoverInterrupted(options);
|
|
71
94
|
this.claimed = true;
|
|
72
95
|
this.live.clear();
|
|
73
96
|
return () => {
|
|
@@ -88,6 +111,8 @@ export class SqliteJournal implements SessionJournal {
|
|
|
88
111
|
nativeSessionId: row.native_id,
|
|
89
112
|
closed: Boolean(row.closed),
|
|
90
113
|
recoveryRequired: Boolean(row.recovery_required),
|
|
114
|
+
...(row.recovery_required &&
|
|
115
|
+
row.recovery_reason && { recoveryReason: row.recovery_reason }),
|
|
91
116
|
}
|
|
92
117
|
);
|
|
93
118
|
}
|
|
@@ -128,15 +153,15 @@ export class SqliteJournal implements SessionJournal {
|
|
|
128
153
|
admit(request: RunRequest): "new" | "duplicate" {
|
|
129
154
|
const { sessionId, turnId, config } = request;
|
|
130
155
|
if (!storableId(sessionId) || !storableId(turnId))
|
|
131
|
-
throw new JournalError("
|
|
156
|
+
throw new JournalError("invalidParams", "Durable session and turn IDs are 1-512 characters");
|
|
132
157
|
if (this.history.isBranch(sessionId))
|
|
133
158
|
throw new JournalError(
|
|
134
|
-
"
|
|
159
|
+
"invalidParams",
|
|
135
160
|
"History branch is not a native execution session; prepare provider context explicitly",
|
|
136
161
|
);
|
|
137
162
|
const input = canonical(request.input);
|
|
138
163
|
if (Buffer.byteLength(input) > MAX_EVENT_BYTES)
|
|
139
|
-
throw new JournalError("
|
|
164
|
+
throw new JournalError("invalidParams", "Input exceeds durable record limit");
|
|
140
165
|
return this.db.atomic(() => {
|
|
141
166
|
if (this.admission(request) === "duplicate") return "duplicate";
|
|
142
167
|
const state = this.session(sessionId);
|
|
@@ -146,7 +171,7 @@ export class SqliteJournal implements SessionJournal {
|
|
|
146
171
|
throw new JournalError(
|
|
147
172
|
"recoveryRequired",
|
|
148
173
|
"Confirm the interrupted native execution stopped before starting another turn",
|
|
149
|
-
{ headSeq: state.headSeq },
|
|
174
|
+
{ headSeq: state.headSeq, reason: state.recoveryReason ?? "not_verified" },
|
|
150
175
|
);
|
|
151
176
|
// Without its native conversation, a turn would silently start a new one.
|
|
152
177
|
if (
|
|
@@ -160,9 +185,9 @@ export class SqliteJournal implements SessionJournal {
|
|
|
160
185
|
{ nativeSessionId: state.nativeSessionId },
|
|
161
186
|
);
|
|
162
187
|
if (state && state.harness !== config.harness)
|
|
163
|
-
throw new JournalError("
|
|
188
|
+
throw new JournalError("invalidParams", "Session harness cannot change");
|
|
164
189
|
if (config.includeRaw)
|
|
165
|
-
throw new JournalError("
|
|
190
|
+
throw new JournalError("invalidParams", "Durable sessions require includeRaw=false");
|
|
166
191
|
const active = this.activeTurn(sessionId);
|
|
167
192
|
if (active)
|
|
168
193
|
throw new JournalError("turnActive", "Session already has an admitted turn", {
|
|
@@ -195,7 +220,12 @@ export class SqliteJournal implements SessionJournal {
|
|
|
195
220
|
|
|
196
221
|
append(event: LifecycleEvent): WireEventEnvelope {
|
|
197
222
|
const { sessionId } = event;
|
|
198
|
-
if (!sessionId) throw new JournalError("
|
|
223
|
+
if (!sessionId) throw new JournalError("invalidParams", "Durable events require a session ID");
|
|
224
|
+
if (isLiveOnlyEvent(event))
|
|
225
|
+
throw new JournalError(
|
|
226
|
+
"invalidParams",
|
|
227
|
+
"Token deltas are live only; a journal never stores them",
|
|
228
|
+
);
|
|
199
229
|
const stored = recordable({ ...event, sessionId });
|
|
200
230
|
const envelope = this.db.atomic(() => {
|
|
201
231
|
const recorded = this.record(stored.event, stored.body);
|
|
@@ -206,6 +236,10 @@ export class SqliteJournal implements SessionJournal {
|
|
|
206
236
|
this.history.changed(this.ref(sessionId));
|
|
207
237
|
return envelope;
|
|
208
238
|
}
|
|
239
|
+
keepTail(event: MessagePartDeltaEvent): void {
|
|
240
|
+
this.tails.keep(event);
|
|
241
|
+
}
|
|
242
|
+
|
|
209
243
|
/** Inside a transaction: record one storable event of an open session. */
|
|
210
244
|
private record(event: SessionEvent, body: string): WireEventEnvelope {
|
|
211
245
|
const { sessionId } = event;
|
|
@@ -231,11 +265,18 @@ export class SqliteJournal implements SessionJournal {
|
|
|
231
265
|
event.sessionId,
|
|
232
266
|
);
|
|
233
267
|
break;
|
|
268
|
+
case "message.part":
|
|
269
|
+
// A kept snapshot holds what its part streamed so far.
|
|
270
|
+
this.tails.dropPart(event.sessionId, event.part.id);
|
|
271
|
+
break;
|
|
234
272
|
case "turn.ended":
|
|
235
273
|
this.settle(event.sessionId, event.turnId, "completed", seq);
|
|
274
|
+
this.tails.dropTurn(event.sessionId, event.turnId);
|
|
236
275
|
break;
|
|
237
276
|
case "session.ended":
|
|
238
277
|
this.db.run("UPDATE sessions SET closed=1 WHERE session_id=?", event.sessionId);
|
|
278
|
+
// A closed session's processes were released with it.
|
|
279
|
+
this.db.run("DELETE FROM native_processes WHERE session_id=?", event.sessionId);
|
|
239
280
|
break;
|
|
240
281
|
}
|
|
241
282
|
}
|
|
@@ -261,91 +302,136 @@ export class SqliteJournal implements SessionJournal {
|
|
|
261
302
|
): { events: WireEventEnvelope[]; hasMore: boolean } {
|
|
262
303
|
const ref = this.ref(sessionId);
|
|
263
304
|
const head = this.log.head(ref)?.version.seq ?? 0;
|
|
264
|
-
const events: WireEventEnvelope[] = [];
|
|
265
305
|
// Each envelope: {"sessionId":…,"seq":…,"event":BODY} and its comma.
|
|
266
306
|
const envelope = Buffer.byteLength(JSON.stringify(sessionId)) + 48;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
)
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
307
|
+
const rows = this.log.page(ref, fromSeq - 1, head, {
|
|
308
|
+
limit: Math.min(limit, HISTORY_MAX_RECORDS),
|
|
309
|
+
maxBytes: REPLAY_PAGE_BYTES,
|
|
310
|
+
overhead: () => envelope,
|
|
311
|
+
// Every stored event fits a page alone; a page holds as many as fit together.
|
|
312
|
+
oversizedFirst: true,
|
|
313
|
+
});
|
|
314
|
+
return {
|
|
315
|
+
events: rows.map((row) => ({
|
|
316
|
+
sessionId,
|
|
317
|
+
seq: row.seq,
|
|
318
|
+
event: JSON.parse(row.body) as LifecycleEvent,
|
|
319
|
+
})),
|
|
320
|
+
hasMore: (rows.at(-1)?.seq ?? fromSeq - 1) < head,
|
|
321
|
+
};
|
|
280
322
|
}
|
|
281
323
|
|
|
282
324
|
/** End each turn a previous owner left admitted, closing what it left open first,
|
|
283
|
-
* so its history stays a valid stream; fence its session until confirmed
|
|
284
|
-
|
|
325
|
+
* so its history stays a valid stream; fence its session until confirmed
|
|
326
|
+
* unless the restart sweep stopped every process it recorded for it. */
|
|
327
|
+
private recoverInterrupted(options: ClaimOptions): void {
|
|
285
328
|
this.db.atomic(() => {
|
|
286
|
-
const
|
|
287
|
-
|
|
329
|
+
const fences = this.sweptFences(options);
|
|
330
|
+
const admitted = this.db.all<{ session_id: string; turn_id: string; harness: AgentHarness }>(
|
|
331
|
+
"SELECT t.session_id, t.turn_id, s.harness FROM turns t JOIN sessions s USING (session_id) WHERE t.state='admitted'",
|
|
288
332
|
);
|
|
289
|
-
for (const { session_id: sessionId, turn_id: turnId } of admitted) {
|
|
290
|
-
const at = Date.now();
|
|
333
|
+
for (const { session_id: sessionId, turn_id: turnId, harness } of admitted) {
|
|
291
334
|
const history = [...this.log.records(this.ref(sessionId), 0, Number.MAX_SAFE_INTEGER)].map(
|
|
292
335
|
(row) => JSON.parse(row.body),
|
|
293
336
|
);
|
|
294
|
-
const
|
|
295
|
-
|
|
337
|
+
const tails = this.tails.ofTurn(sessionId, turnId);
|
|
338
|
+
// @ref LLP 0007#records-and-the-restart-sweep — fenced only when its agent was not seen stopped
|
|
339
|
+
const unrecorded = options.recorded && !options.recorded.has(harness);
|
|
340
|
+
const fence = fences && !unrecorded ? fences.get(sessionId) : "not_verified";
|
|
341
|
+
let seq = 0;
|
|
342
|
+
for (const fact of recoveryFacts(history, {
|
|
296
343
|
sessionId,
|
|
297
344
|
turnId,
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
timestamp: at,
|
|
305
|
-
};
|
|
306
|
-
// A turn cut off before its first event still reads as started, then ended.
|
|
307
|
-
const started = history.some(
|
|
308
|
-
(event) => event?.type === "turn.started" && event.turnId === turnId,
|
|
309
|
-
);
|
|
310
|
-
const opened: LifecycleEvent[] = started
|
|
311
|
-
? []
|
|
312
|
-
: [
|
|
313
|
-
{
|
|
314
|
-
type: "turn.started",
|
|
315
|
-
sessionId,
|
|
316
|
-
turnId,
|
|
317
|
-
execution: { harness: this.session(sessionId)!.harness },
|
|
318
|
-
timestamp: at,
|
|
319
|
-
},
|
|
320
|
-
];
|
|
321
|
-
let seq = 0;
|
|
322
|
-
for (const fact of [
|
|
323
|
-
...opened,
|
|
324
|
-
...interruptionFacts(history, sessionId, turnId, at),
|
|
325
|
-
ended,
|
|
326
|
-
]) {
|
|
327
|
-
const stored = recordable({ ...fact, sessionId });
|
|
345
|
+
harness,
|
|
346
|
+
at: Date.now(),
|
|
347
|
+
tails,
|
|
348
|
+
...(fence && { fence }),
|
|
349
|
+
})) {
|
|
350
|
+
const stored = recordable(fact);
|
|
328
351
|
seq = this.record(stored.event, stored.body).seq;
|
|
329
352
|
}
|
|
330
353
|
this.settle(sessionId, turnId, "interrupted", seq);
|
|
331
|
-
|
|
354
|
+
if (fence)
|
|
355
|
+
this.db.run(
|
|
356
|
+
"UPDATE sessions SET recovery_required=1, recovery_reason=? WHERE session_id=?",
|
|
357
|
+
fence,
|
|
358
|
+
sessionId,
|
|
359
|
+
);
|
|
332
360
|
}
|
|
361
|
+
this.tails.clear();
|
|
333
362
|
});
|
|
334
363
|
}
|
|
364
|
+
/** Inside a transaction: drop the records the sweep saw stopped, and say which
|
|
365
|
+
* sessions the others leave fenced, and why. Undefined: no sweep ran. */
|
|
366
|
+
private sweptFences(options: ClaimOptions): Map<string, RecoveryReason> | undefined {
|
|
367
|
+
if (!options.stopped) return undefined;
|
|
368
|
+
const fences = new Map<string, RecoveryReason>();
|
|
369
|
+
for (const row of this.db.all<NativeRow>("SELECT * FROM native_processes")) {
|
|
370
|
+
if (options.stopped.has(row.id)) {
|
|
371
|
+
this.db.run("DELETE FROM native_processes WHERE id=?", row.id);
|
|
372
|
+
continue;
|
|
373
|
+
}
|
|
374
|
+
const reason: RecoveryReason =
|
|
375
|
+
row.pid === null
|
|
376
|
+
? "not_owned"
|
|
377
|
+
: options.notStopped?.has(row.id)
|
|
378
|
+
? "not_stopped"
|
|
379
|
+
: "not_verified";
|
|
380
|
+
const known = fences.get(row.session_id);
|
|
381
|
+
if (!known || REASON_WEIGHT[reason] > REASON_WEIGHT[known])
|
|
382
|
+
fences.set(row.session_id, reason);
|
|
383
|
+
}
|
|
384
|
+
return fences;
|
|
385
|
+
}
|
|
335
386
|
confirmStopped(sessionId: string, expectedHeadSeq: number): boolean {
|
|
336
387
|
return this.db.atomic(() => {
|
|
337
388
|
const state = this.session(sessionId);
|
|
338
389
|
if (!state || state.headSeq !== expectedHeadSeq)
|
|
339
390
|
throw new JournalError(
|
|
340
|
-
state ? "
|
|
391
|
+
state ? "historyConflict" : "unknownSession",
|
|
341
392
|
state ? "Recovery confirmation names an old history position" : "Unknown durable session",
|
|
342
393
|
state && { headSeq: state.headSeq },
|
|
343
394
|
);
|
|
344
395
|
if (!state.recoveryRequired) return false;
|
|
345
|
-
this.db.run(
|
|
396
|
+
this.db.run(
|
|
397
|
+
"UPDATE sessions SET recovery_required=0, recovery_reason=NULL WHERE session_id=?",
|
|
398
|
+
sessionId,
|
|
399
|
+
);
|
|
400
|
+
// The host's word covers what the sweep could not verify.
|
|
401
|
+
this.db.run("DELETE FROM native_processes WHERE session_id=?", sessionId);
|
|
346
402
|
return true;
|
|
347
403
|
});
|
|
348
404
|
}
|
|
405
|
+
releaseNative(sessionId: string): void {
|
|
406
|
+
this.live.delete(sessionId);
|
|
407
|
+
}
|
|
408
|
+
recordNative(record: NativeProcessRecord): number {
|
|
409
|
+
const row = this.db.one<{ id: number }>(
|
|
410
|
+
"INSERT INTO native_processes(session_id,harness,pid,boot,started,executable) VALUES (?,?,?,?,?,?) RETURNING id",
|
|
411
|
+
record.sessionId,
|
|
412
|
+
record.harness,
|
|
413
|
+
record.pid,
|
|
414
|
+
record.boot,
|
|
415
|
+
record.started,
|
|
416
|
+
record.executable,
|
|
417
|
+
);
|
|
418
|
+
if (!row) throw new Error("The journal kept no record of the native process");
|
|
419
|
+
return row.id;
|
|
420
|
+
}
|
|
421
|
+
forgetNative(id: number): void {
|
|
422
|
+
this.db.run("DELETE FROM native_processes WHERE id=?", id);
|
|
423
|
+
}
|
|
424
|
+
nativeProcesses(): StoredNativeProcess[] {
|
|
425
|
+
return this.db.all<NativeRow>("SELECT * FROM native_processes ORDER BY id").map((row) => ({
|
|
426
|
+
id: row.id,
|
|
427
|
+
sessionId: row.session_id,
|
|
428
|
+
harness: row.harness,
|
|
429
|
+
pid: row.pid,
|
|
430
|
+
boot: row.boot,
|
|
431
|
+
started: row.started,
|
|
432
|
+
executable: row.executable,
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
349
435
|
close(): void {
|
|
350
436
|
this.history.close();
|
|
351
437
|
this.db.close();
|
package/src/sync/journal.ts
CHANGED
|
@@ -1,35 +1,71 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import {
|
|
2
|
+
type AgentHarness,
|
|
3
|
+
type DurableSession,
|
|
4
|
+
type LifecycleEvent,
|
|
5
|
+
type MessagePartDeltaEvent,
|
|
6
|
+
type RunRequest,
|
|
7
|
+
type TurnReceipt,
|
|
8
|
+
type WireErrorName,
|
|
9
|
+
type WireEventEnvelope,
|
|
10
|
+
WireRefusal,
|
|
7
11
|
} from "../protocol/index.ts";
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* What a journal refuses, as opposed to failing to store: the request itself
|
|
11
15
|
* is the problem, nothing was written, and the journal stays usable. Any other
|
|
12
|
-
* error a journal throws means its storage failed.
|
|
16
|
+
* error a journal throws means its storage failed. Its code is the wire error
|
|
17
|
+
* the server answers with.
|
|
13
18
|
*/
|
|
14
|
-
export class JournalError extends
|
|
19
|
+
export class JournalError extends WireRefusal<JournalRefusal, Record<string, unknown>> {
|
|
15
20
|
override readonly name = "JournalError";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
}
|
|
22
|
+
export type JournalRefusal = Extract<
|
|
23
|
+
WireErrorName,
|
|
24
|
+
| "turnConflict"
|
|
25
|
+
| "turnActive"
|
|
26
|
+
| "sessionClosed"
|
|
27
|
+
| "recoveryRequired"
|
|
28
|
+
| "resumeRequired"
|
|
29
|
+
| "unknownSession"
|
|
30
|
+
| "historyConflict"
|
|
31
|
+
| "invalidParams"
|
|
32
|
+
>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A native process an owner of this journal started for a session: what a
|
|
36
|
+
* restart verifies and stops before it decides whether to fence. The same
|
|
37
|
+
* shape as the engine's `NativeRecord`; it comes only from what the engine
|
|
38
|
+
* itself spawned, never from the wire.
|
|
39
|
+
*/
|
|
40
|
+
export interface NativeProcessRecord {
|
|
41
|
+
sessionId: string;
|
|
42
|
+
harness: AgentHarness;
|
|
43
|
+
/** Its pid, also its process group. Null: a host's own spawner started it. */
|
|
44
|
+
pid: number | null;
|
|
45
|
+
boot: string | null;
|
|
46
|
+
started: string | null;
|
|
47
|
+
executable: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** A kept record, by the id `recordNative` gave it. */
|
|
51
|
+
export interface StoredNativeProcess extends NativeProcessRecord {
|
|
52
|
+
id: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* What the restart sweep found of the kept records (`nativeProcesses()`), by
|
|
57
|
+
* id. A record in neither set is `not_verified`, or `not_owned` without a pid.
|
|
58
|
+
*/
|
|
59
|
+
export interface ClaimOptions {
|
|
60
|
+
/** Gone or stopped: they fence nothing, and are dropped. */
|
|
61
|
+
stopped?: ReadonlySet<number>;
|
|
62
|
+
/** Still there after SIGKILL (`not_stopped`). */
|
|
63
|
+
notStopped?: ReadonlySet<number>;
|
|
64
|
+
/**
|
|
65
|
+
* The harnesses whose processes are recorded: an interrupted session of any
|
|
66
|
+
* other is fenced (`not_verified`) though it has no record. Absent: all are.
|
|
67
|
+
*/
|
|
68
|
+
recorded?: ReadonlySet<AgentHarness>;
|
|
33
69
|
}
|
|
34
70
|
|
|
35
71
|
/**
|
|
@@ -41,11 +77,13 @@ export interface SessionJournal {
|
|
|
41
77
|
readonly sourceId: string;
|
|
42
78
|
/**
|
|
43
79
|
* Take execution ownership: one executing owner per journal. Ends the turns
|
|
44
|
-
* a previous owner left running as interrupted
|
|
45
|
-
*
|
|
46
|
-
* the
|
|
80
|
+
* a previous owner left running as interrupted, closing what they left open
|
|
81
|
+
* with the tails `keepTail` kept and never rerunning them. With the restart
|
|
82
|
+
* sweep's result it fences only the sessions with a record it could not
|
|
83
|
+
* confirm stopped, saying why; without one, every interrupted session, as
|
|
84
|
+
* `not_verified`. Either way until `confirmStopped`. Returns the release.
|
|
47
85
|
*/
|
|
48
|
-
claim(): () => void;
|
|
86
|
+
claim(options?: ClaimOptions): () => void;
|
|
49
87
|
session(sessionId: string): DurableSession | undefined;
|
|
50
88
|
turn(sessionId: string, turnId: string): TurnReceipt | undefined;
|
|
51
89
|
/** Whether this journal already admitted the turn. Throws `turnConflict` for other input. */
|
|
@@ -57,10 +95,16 @@ export interface SessionJournal {
|
|
|
57
95
|
* active turn.
|
|
58
96
|
*/
|
|
59
97
|
admit(request: RunRequest): "new" | "duplicate";
|
|
60
|
-
/** Commits `event`, or, when its content cannot be stored, a
|
|
61
|
-
* notice in its place
|
|
62
|
-
*
|
|
98
|
+
/** Commits `event`, or, when its content cannot be stored, a copy cut down to
|
|
99
|
+
* fit or a notice in its place. Deliver what it returns. Throws only when
|
|
100
|
+
* storage itself fails. */
|
|
63
101
|
append(event: LifecycleEvent): WireEventEnvelope;
|
|
102
|
+
/**
|
|
103
|
+
* Keep what a token delta streamed until its part's next kept snapshot or
|
|
104
|
+
* its turn's end, so recovery closes the part with what was shown (`claim`).
|
|
105
|
+
* Called before the delta is delivered; never part of a history.
|
|
106
|
+
*/
|
|
107
|
+
keepTail(event: MessagePartDeltaEvent): void;
|
|
64
108
|
/** Committed events from `fromSeq`, a bounded page at a time. */
|
|
65
109
|
replay(
|
|
66
110
|
sessionId: string,
|
|
@@ -69,5 +113,20 @@ export interface SessionJournal {
|
|
|
69
113
|
): { events: WireEventEnvelope[]; hasMore: boolean };
|
|
70
114
|
/** Lift the fence `claim` put on an interrupted session. False when there was none. */
|
|
71
115
|
confirmStopped(sessionId: string, expectedHeadSeq: number): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* This owner let the session's native conversation go (`session/release`):
|
|
118
|
+
* its next admission must name it again (`resumeRequired`), as after a
|
|
119
|
+
* restart. Nothing is written.
|
|
120
|
+
*/
|
|
121
|
+
releaseNative(sessionId: string): void;
|
|
122
|
+
/**
|
|
123
|
+
* Keep a native process the owner started for a session, until
|
|
124
|
+
* `forgetNative`: written before the process is sent any input. Returns its id.
|
|
125
|
+
*/
|
|
126
|
+
recordNative(record: NativeProcessRecord): number;
|
|
127
|
+
/** The process is gone: drop its record. */
|
|
128
|
+
forgetNative(id: number): void;
|
|
129
|
+
/** The kept records, for the restart sweep before `claim`. */
|
|
130
|
+
nativeProcesses(): StoredNativeProcess[];
|
|
72
131
|
close(): void;
|
|
73
132
|
}
|