@zvada/agent-server 0.3.18 → 0.3.19
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 +1005 -1
- package/README.md +35 -39
- 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 +43 -25
- 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 +144 -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
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AgentHarness,
|
|
3
|
+
type AuthLogin,
|
|
4
|
+
type AuthLoginEnd,
|
|
5
|
+
type AuthLoginParams,
|
|
6
|
+
type AuthUpdated,
|
|
7
|
+
type HarnessAuth,
|
|
8
|
+
type LoginOutcome,
|
|
9
|
+
accountLabel,
|
|
10
|
+
canonicalJson,
|
|
11
|
+
generateUUIDv7,
|
|
12
|
+
} from "../../protocol/index.ts";
|
|
13
|
+
import type { Agent } from "../agents/base.ts";
|
|
14
|
+
import type { CliLogin, LoginStatus, NativeLogin } from "../agents/login.ts";
|
|
15
|
+
import { withTimeout } from "../utils/deadline.ts";
|
|
16
|
+
import { AgentServerError, InvalidRequestError, UnknownLoginError } from "../utils/errors.ts";
|
|
17
|
+
import { LoginReads, type Reading } from "./login-reads.ts";
|
|
18
|
+
|
|
19
|
+
/** How long a login waits for its user. */
|
|
20
|
+
const LOGIN_TTL_MS = 10 * 60_000;
|
|
21
|
+
/** How long the CLI has to say where to sign in, inside a client's 30 s request deadline. */
|
|
22
|
+
const LOGIN_START_TIMEOUT_MS = 20_000;
|
|
23
|
+
/** A status read is reused this long once it answered: a settings page that polls starts no CLI each time. */
|
|
24
|
+
const STATUS_TTL_MS = 2_000;
|
|
25
|
+
/** A status read that takes longer (a CLI still installing) answers `unknown`. */
|
|
26
|
+
const STATUS_TIMEOUT_MS = 20_000;
|
|
27
|
+
|
|
28
|
+
interface Login {
|
|
29
|
+
readonly harness: AgentHarness;
|
|
30
|
+
readonly answer: AuthLogin;
|
|
31
|
+
/** The harness and the store it logs in to: one login at a time each. */
|
|
32
|
+
readonly store: string;
|
|
33
|
+
readonly env: Record<string, string> | undefined;
|
|
34
|
+
readonly native: NativeLogin;
|
|
35
|
+
readonly timer: ReturnType<typeof setTimeout>;
|
|
36
|
+
/** How it ended, once it did: it is under way until the harness's login is read again and told. */
|
|
37
|
+
end?: AuthLoginEnd;
|
|
38
|
+
/** Settles once its end is told. */
|
|
39
|
+
readonly ended: Promise<AuthUpdated>;
|
|
40
|
+
readonly settle: (update: AuthUpdated) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface HarnessLoginsOptions {
|
|
44
|
+
now?: () => number;
|
|
45
|
+
newId?: () => string;
|
|
46
|
+
loginTtlMs?: number;
|
|
47
|
+
loginStartTimeoutMs?: number;
|
|
48
|
+
statusTtlMs?: number;
|
|
49
|
+
statusTimeoutMs?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const message = (error: unknown) => (error instanceof Error ? error.message : String(error));
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The harness and the store a turn with this `env` would use, by the whole
|
|
56
|
+
* `env`: two envs that reach one store by different variables count as two,
|
|
57
|
+
* which a product that sends its turns' `env` each time never meets.
|
|
58
|
+
*/
|
|
59
|
+
const storeKey = (harness: AgentHarness, env: Record<string, string> | undefined) =>
|
|
60
|
+
canonicalJson([harness, env ?? {}]);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Each harness's login, read from its CLI, and the logins under way. A login
|
|
64
|
+
* that succeeds and a logout change the login, and so does a read that
|
|
65
|
+
* differs from the last one of its store (a login in a terminal): `onChanged`
|
|
66
|
+
* hears it (each session's next turn starts a new CLI, model lists are read
|
|
67
|
+
* again) and `onUpdated` listeners are told, as they are when a login ends.
|
|
68
|
+
*/
|
|
69
|
+
export class HarnessLogins {
|
|
70
|
+
/** Logins under way, until their end is told. */
|
|
71
|
+
private readonly logins = new Map<string, Login>();
|
|
72
|
+
private readonly reads: LoginReads;
|
|
73
|
+
private readonly listeners = new Set<(update: AuthUpdated) => void>();
|
|
74
|
+
private stopped = false;
|
|
75
|
+
|
|
76
|
+
constructor(
|
|
77
|
+
private readonly agentFor: (harness: AgentHarness) => Agent,
|
|
78
|
+
private readonly onChanged: (harness: AgentHarness) => void,
|
|
79
|
+
private readonly options: HarnessLoginsOptions = {},
|
|
80
|
+
) {
|
|
81
|
+
this.reads = new LoginReads(() => this.now(), options.statusTtlMs ?? STATUS_TTL_MS);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private now(): number {
|
|
85
|
+
return this.options.now?.() ?? Date.now();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Each harness's login: a read under way, or one a moment old, is shared. */
|
|
89
|
+
async status(
|
|
90
|
+
harnesses: readonly AgentHarness[],
|
|
91
|
+
env?: Record<string, string>,
|
|
92
|
+
): Promise<HarnessAuth[]> {
|
|
93
|
+
return Promise.all(
|
|
94
|
+
harnesses.map(async (harness) => {
|
|
95
|
+
const recent = this.reads.recent(storeKey(harness, env));
|
|
96
|
+
if (recent) return (await recent).auth;
|
|
97
|
+
const { auth, differs } = await this.reread(harness, env);
|
|
98
|
+
// Changed where the engine did not change it: a login in a terminal.
|
|
99
|
+
if (differs) {
|
|
100
|
+
this.onChanged(harness);
|
|
101
|
+
this.emit({ auth });
|
|
102
|
+
}
|
|
103
|
+
return auth;
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private reread(harness: AgentHarness, env: Record<string, string> | undefined): Promise<Reading> {
|
|
109
|
+
return this.reads.read(storeKey(harness, env), () => this.read(harness, env));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Its login and the ways to sign in, each read apart: a login that cannot be read can still be made. */
|
|
113
|
+
private async read(
|
|
114
|
+
harness: AgentHarness,
|
|
115
|
+
env: Record<string, string> | undefined,
|
|
116
|
+
): Promise<HarnessAuth> {
|
|
117
|
+
const cli = this.agentFor(harness).login;
|
|
118
|
+
if (!cli) {
|
|
119
|
+
return {
|
|
120
|
+
harness,
|
|
121
|
+
state: "unknown",
|
|
122
|
+
methods: [],
|
|
123
|
+
error: "This harness's agent signs in on its own.",
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const timeout = this.options.statusTimeoutMs ?? STATUS_TIMEOUT_MS;
|
|
127
|
+
const stop = new AbortController();
|
|
128
|
+
const [methods, status] = await Promise.all([
|
|
129
|
+
withTimeout(cli.methods({ ...(env && { env }) }), timeout).then(
|
|
130
|
+
(read) => read?.value ?? [],
|
|
131
|
+
() => [],
|
|
132
|
+
),
|
|
133
|
+
withTimeout(cli.status({ ...(env && { env }), signal: stop.signal }), timeout).then(
|
|
134
|
+
(read): LoginStatus => {
|
|
135
|
+
if (read) return read.value;
|
|
136
|
+
stop.abort();
|
|
137
|
+
return { state: "unknown", error: "The CLI did not say in time." };
|
|
138
|
+
},
|
|
139
|
+
(error): LoginStatus => ({ state: "unknown", error: message(error) }),
|
|
140
|
+
),
|
|
141
|
+
]);
|
|
142
|
+
const label = accountLabel(harness, status);
|
|
143
|
+
return { harness, ...status, ...(label && { label }), methods };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private cliOf(harness: AgentHarness): CliLogin {
|
|
147
|
+
const cli = this.agentFor(harness).login;
|
|
148
|
+
if (cli) return cli;
|
|
149
|
+
throw new InvalidRequestError([{ path: "harness", message: "its agent signs in on its own" }]);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Start one of a harness's logins, answered once the CLI says where the
|
|
154
|
+
* user signs in. Once it has, a login under way to the same harness and
|
|
155
|
+
* store is cancelled: each CLI runs one at a time, and the latest start
|
|
156
|
+
* wins.
|
|
157
|
+
*/
|
|
158
|
+
async login({ harness, method, apiKey, env }: AuthLoginParams): Promise<AuthLogin> {
|
|
159
|
+
const cli = this.cliOf(harness);
|
|
160
|
+
const shuttingDown = () => new AgentServerError("The server is shutting down.", "shuttingDown");
|
|
161
|
+
if (this.stopped) throw shuttingDown();
|
|
162
|
+
const stop = new AbortController();
|
|
163
|
+
const starting = cli.start(method, {
|
|
164
|
+
...(env && { env }),
|
|
165
|
+
...(apiKey && { apiKey }),
|
|
166
|
+
signal: stop.signal,
|
|
167
|
+
});
|
|
168
|
+
const started = await withTimeout(
|
|
169
|
+
starting,
|
|
170
|
+
this.options.loginStartTimeoutMs ?? LOGIN_START_TIMEOUT_MS,
|
|
171
|
+
);
|
|
172
|
+
if (!started) {
|
|
173
|
+
// Its CLI is stopped; one that starts all the same is cancelled, as no one holds its id.
|
|
174
|
+
stop.abort();
|
|
175
|
+
void starting.then(
|
|
176
|
+
(late) => late.cancel(),
|
|
177
|
+
() => {},
|
|
178
|
+
);
|
|
179
|
+
throw new AgentServerError("The CLI did not start the login in time.", "loginTimeout");
|
|
180
|
+
}
|
|
181
|
+
const native = started.value;
|
|
182
|
+
if (this.stopped) {
|
|
183
|
+
native.cancel();
|
|
184
|
+
throw shuttingDown();
|
|
185
|
+
}
|
|
186
|
+
// Only once it started: a start the CLI refuses cancels nothing.
|
|
187
|
+
const store = storeKey(harness, env);
|
|
188
|
+
for (const login of this.underWay()) {
|
|
189
|
+
if (login.store === store) this.end(login, "cancelled");
|
|
190
|
+
}
|
|
191
|
+
return this.track(harness, method, store, env, native);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** Keep a started login until it ends, and expire it. */
|
|
195
|
+
private track(
|
|
196
|
+
harness: AgentHarness,
|
|
197
|
+
method: string,
|
|
198
|
+
store: string,
|
|
199
|
+
env: Record<string, string> | undefined,
|
|
200
|
+
native: NativeLogin,
|
|
201
|
+
): AuthLogin {
|
|
202
|
+
const loginId = this.options.newId?.() ?? generateUUIDv7();
|
|
203
|
+
const ttl = this.options.loginTtlMs ?? LOGIN_TTL_MS;
|
|
204
|
+
const answer: AuthLogin = {
|
|
205
|
+
loginId,
|
|
206
|
+
harness,
|
|
207
|
+
method,
|
|
208
|
+
...(native.url && { url: native.url }),
|
|
209
|
+
...(native.codeUrl && { codeUrl: native.codeUrl }),
|
|
210
|
+
...(native.userCode && { userCode: native.userCode }),
|
|
211
|
+
expiresAt: this.now() + ttl,
|
|
212
|
+
};
|
|
213
|
+
let settle!: (update: AuthUpdated) => void;
|
|
214
|
+
const ended = new Promise<AuthUpdated>((resolve) => {
|
|
215
|
+
settle = resolve;
|
|
216
|
+
});
|
|
217
|
+
const login: Login = {
|
|
218
|
+
harness,
|
|
219
|
+
answer,
|
|
220
|
+
store,
|
|
221
|
+
env,
|
|
222
|
+
native,
|
|
223
|
+
ended,
|
|
224
|
+
settle,
|
|
225
|
+
timer: setTimeout(() => this.end(login, "expired"), ttl),
|
|
226
|
+
};
|
|
227
|
+
login.timer.unref?.();
|
|
228
|
+
this.logins.set(loginId, login);
|
|
229
|
+
native.done.then(
|
|
230
|
+
() => this.finish(login, { loginId, outcome: "succeeded" }),
|
|
231
|
+
(error: unknown) => this.finish(login, { loginId, outcome: "failed", error: message(error) }),
|
|
232
|
+
);
|
|
233
|
+
return answer;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Finish a login with the code its `codeUrl` page showed: how it ended. A
|
|
238
|
+
* code the CLI could not be sent is refused, and the login goes on.
|
|
239
|
+
*/
|
|
240
|
+
async complete(loginId: string, code: string): Promise<AuthUpdated> {
|
|
241
|
+
const login = this.logins.get(loginId);
|
|
242
|
+
if (!login) throw new UnknownLoginError(loginId);
|
|
243
|
+
if (login.end) return login.ended;
|
|
244
|
+
if (!login.native.complete) {
|
|
245
|
+
throw new InvalidRequestError([{ path: "loginId", message: "this login takes no code" }]);
|
|
246
|
+
}
|
|
247
|
+
try {
|
|
248
|
+
await login.native.complete(code);
|
|
249
|
+
} catch (error) {
|
|
250
|
+
if (error instanceof InvalidRequestError) throw error;
|
|
251
|
+
this.end(login, "failed", message(error));
|
|
252
|
+
}
|
|
253
|
+
return login.ended;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Stop a login under way. */
|
|
257
|
+
cancel(loginId: string): "cancelled" | "not_found" {
|
|
258
|
+
const login = this.logins.get(loginId);
|
|
259
|
+
if (!login || login.end) return "not_found";
|
|
260
|
+
this.end(login, "cancelled");
|
|
261
|
+
return "cancelled";
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** Remove the CLI's own login: the harness's login after it. */
|
|
265
|
+
async logout(harness: AgentHarness, env?: Record<string, string>): Promise<HarnessAuth> {
|
|
266
|
+
await this.cliOf(harness).logout({ ...(env && { env }) });
|
|
267
|
+
this.onChanged(harness);
|
|
268
|
+
const { auth } = await this.reread(harness, env);
|
|
269
|
+
this.emit({ auth });
|
|
270
|
+
return auth;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/** Every change of a harness's login, and every login's end. Returns the unsubscribe. */
|
|
274
|
+
onUpdated(listener: (update: AuthUpdated) => void): () => void {
|
|
275
|
+
this.listeners.add(listener);
|
|
276
|
+
return () => this.listeners.delete(listener);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/** Stop every login under way, and start none: its CLI goes, and no other starts to say so. */
|
|
280
|
+
shutdown(): void {
|
|
281
|
+
this.stopped = true;
|
|
282
|
+
for (const login of this.underWay()) this.end(login, "cancelled");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private underWay(): Login[] {
|
|
286
|
+
return [...this.logins.values()].filter((login) => !login.end);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/** End it here (cancelled, expired, a refused code): its CLI stops. */
|
|
290
|
+
private end(login: Login, outcome: LoginOutcome, error?: string): void {
|
|
291
|
+
void this.finish(login, { loginId: login.answer.loginId, outcome, ...(error && { error }) });
|
|
292
|
+
login.native.cancel();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* It ended: read the harness's login again and tell everyone how. It stays
|
|
297
|
+
* a login under way until then, so a code pasted just after a browser
|
|
298
|
+
* finished it is answered with its end, not as unknown.
|
|
299
|
+
*/
|
|
300
|
+
private async finish(login: Login, end: AuthLoginEnd): Promise<void> {
|
|
301
|
+
if (login.end) return;
|
|
302
|
+
login.end = end;
|
|
303
|
+
clearTimeout(login.timer);
|
|
304
|
+
const { harness } = login;
|
|
305
|
+
const succeeded = end.outcome === "succeeded";
|
|
306
|
+
// Before the read: a turn that starts meanwhile already runs a new CLI.
|
|
307
|
+
if (succeeded) this.onChanged(harness);
|
|
308
|
+
// Shutting down starts no CLI to read it.
|
|
309
|
+
const { auth, differs }: Reading = this.stopped
|
|
310
|
+
? { auth: { harness, state: "unknown", methods: [] }, differs: false }
|
|
311
|
+
: await this.reread(harness, login.env);
|
|
312
|
+
if (differs && !succeeded) this.onChanged(harness);
|
|
313
|
+
const update: AuthUpdated = { auth, login: end };
|
|
314
|
+
this.logins.delete(end.loginId);
|
|
315
|
+
if (!this.stopped) this.emit(update);
|
|
316
|
+
login.settle(update);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
private emit(update: AuthUpdated): void {
|
|
320
|
+
for (const listener of this.listeners) {
|
|
321
|
+
try {
|
|
322
|
+
listener(update);
|
|
323
|
+
} catch {
|
|
324
|
+
// One listener's failure is not the login's.
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type HarnessAuth, canonicalJson } from "../../protocol/index.ts";
|
|
2
|
+
import { setBounded } from "../utils/bounded.ts";
|
|
3
|
+
|
|
4
|
+
/** Stores whose reads are remembered; the oldest go first. */
|
|
5
|
+
const MAX_ENTRIES = 64;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* What makes two reads of a login the same login. A key replaced by another
|
|
9
|
+
* outside the engine (in a terminal) reads the same, as no CLI says which key
|
|
10
|
+
* it holds: sessions notice a login the engine runs, or a change of kind or
|
|
11
|
+
* account.
|
|
12
|
+
*/
|
|
13
|
+
const loginPrint = (auth: HarnessAuth) =>
|
|
14
|
+
canonicalJson([
|
|
15
|
+
auth.state,
|
|
16
|
+
auth.credential,
|
|
17
|
+
auth.source,
|
|
18
|
+
auth.provider,
|
|
19
|
+
auth.email,
|
|
20
|
+
auth.organization,
|
|
21
|
+
auth.plan,
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
/** A read of a store's login: whether it differs from the store's last one. */
|
|
25
|
+
export interface Reading {
|
|
26
|
+
readonly auth: HarnessAuth;
|
|
27
|
+
readonly differs: boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Each store's login as last read. A read under way, or one a moment old, is
|
|
32
|
+
* shared, and only the latest read of a store counts: one that answers after
|
|
33
|
+
* a newer one began says nothing of a change, so a slow read from before a
|
|
34
|
+
* logout cannot announce the login back.
|
|
35
|
+
*/
|
|
36
|
+
export class LoginReads {
|
|
37
|
+
private readonly reads = new Map<string, { n: number; reading: Promise<Reading>; at?: number }>();
|
|
38
|
+
private readonly seen = new Map<string, string>();
|
|
39
|
+
private count = 0;
|
|
40
|
+
|
|
41
|
+
constructor(
|
|
42
|
+
private readonly now: () => number,
|
|
43
|
+
private readonly ttlMs: number,
|
|
44
|
+
) {}
|
|
45
|
+
|
|
46
|
+
/** The store's read under way, or one a moment old. */
|
|
47
|
+
recent(key: string): Promise<Reading> | undefined {
|
|
48
|
+
const recent = this.reads.get(key);
|
|
49
|
+
if (recent && (recent.at === undefined || this.now() - recent.at < this.ttlMs)) {
|
|
50
|
+
return recent.reading;
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Read it now: it differs when it is the latest read and not the login last
|
|
57
|
+
* seen. One that a newer read overtook answers with the newer one's login.
|
|
58
|
+
*/
|
|
59
|
+
read(key: string, read: () => Promise<HarnessAuth>): Promise<Reading> {
|
|
60
|
+
const n = ++this.count;
|
|
61
|
+
const reading = read().then(async (auth): Promise<Reading> => {
|
|
62
|
+
const latest = this.reads.get(key);
|
|
63
|
+
if (latest && latest.n !== n) return { auth: (await latest.reading).auth, differs: false };
|
|
64
|
+
if (!latest) return { auth, differs: false };
|
|
65
|
+
latest.at = this.now();
|
|
66
|
+
if (auth.state === "unknown") return { auth, differs: false };
|
|
67
|
+
const before = this.seen.get(key);
|
|
68
|
+
setBounded(this.seen, key, loginPrint(auth), MAX_ENTRIES);
|
|
69
|
+
return { auth, differs: before !== undefined && before !== loginPrint(auth) };
|
|
70
|
+
});
|
|
71
|
+
setBounded(this.reads, key, { n, reading }, MAX_ENTRIES);
|
|
72
|
+
// A read that failed is not shared: the next one tries again.
|
|
73
|
+
reading.catch(() => {
|
|
74
|
+
if (this.reads.get(key)?.n === n) this.reads.delete(key);
|
|
75
|
+
});
|
|
76
|
+
return reading;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -3,24 +3,15 @@ import {
|
|
|
3
3
|
CATALOG_MODELS,
|
|
4
4
|
type ModelDescriptor,
|
|
5
5
|
type ModelList,
|
|
6
|
+
type ModelsListParams,
|
|
6
7
|
type ThinkingLevel,
|
|
8
|
+
canonicalJson,
|
|
7
9
|
} from "../../protocol/index.ts";
|
|
8
10
|
import type { Agent } from "../agents/base.ts";
|
|
11
|
+
import { setBounded } from "../utils/bounded.ts";
|
|
12
|
+
import { withTimeout } from "../utils/deadline.ts";
|
|
9
13
|
|
|
10
|
-
/**
|
|
11
|
-
export interface ModelsQuery {
|
|
12
|
-
harness: AgentHarness;
|
|
13
|
-
/** The folder whose settings apply. Defaults to the process's working directory. */
|
|
14
|
-
cwd?: string;
|
|
15
|
-
/** List with this session's credentials (host-managed Codex auth resolves per session). */
|
|
16
|
-
sessionId?: string;
|
|
17
|
-
env?: Record<string, string>;
|
|
18
|
-
apiKey?: string;
|
|
19
|
-
/** Read the CLI again instead of the cache, e.g. after the user logs in. */
|
|
20
|
-
refresh?: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** A live list is reused this long. Logins change outside agent-server; `refresh` reads sooner. */
|
|
14
|
+
/** A live list is reused this long. A login can change outside agent-server; `refresh` reads sooner. */
|
|
24
15
|
const LIVE_TTL_MS = 10 * 60_000;
|
|
25
16
|
/** A failed read is reused this long, so a logged-out CLI is not started on every call. */
|
|
26
17
|
const FAILURE_TTL_MS = 30_000;
|
|
@@ -35,13 +26,14 @@ interface Entry {
|
|
|
35
26
|
}
|
|
36
27
|
|
|
37
28
|
interface Read {
|
|
29
|
+
harness: AgentHarness;
|
|
38
30
|
generation: number;
|
|
39
31
|
refresh: boolean;
|
|
40
32
|
list: Promise<ModelList>;
|
|
41
33
|
}
|
|
42
34
|
|
|
43
35
|
/** The catalog's models for a harness, as a list (`source: "catalog"`). */
|
|
44
|
-
|
|
36
|
+
function catalogModelList(harness: AgentHarness, fetchedAt: number): ModelList {
|
|
45
37
|
return {
|
|
46
38
|
harness,
|
|
47
39
|
models: CATALOG_MODELS.filter((model) => model.harness === harness),
|
|
@@ -90,18 +82,12 @@ export class ModelLists {
|
|
|
90
82
|
harness: AgentHarness,
|
|
91
83
|
cwd: string,
|
|
92
84
|
sessionId: string | undefined,
|
|
93
|
-
query: Pick<
|
|
85
|
+
query: Pick<ModelsListParams, "apiKey" | "env">,
|
|
94
86
|
): string {
|
|
95
|
-
return
|
|
96
|
-
harness,
|
|
97
|
-
cwd,
|
|
98
|
-
sessionId ?? null,
|
|
99
|
-
query.apiKey ?? null,
|
|
100
|
-
query.env ? Object.entries(query.env).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)) : null,
|
|
101
|
-
]);
|
|
87
|
+
return canonicalJson([harness, cwd, sessionId, query.apiKey, query.env]);
|
|
102
88
|
}
|
|
103
89
|
|
|
104
|
-
get(agent: Agent, query:
|
|
90
|
+
get(agent: Agent, query: ModelsListParams): Promise<ModelList> {
|
|
105
91
|
const listModels = agent.listModels?.bind(agent);
|
|
106
92
|
if (!listModels) return Promise.resolve(catalogModelList(query.harness, this.now()));
|
|
107
93
|
const cwd = query.cwd ?? globalThis.process?.cwd?.() ?? "/";
|
|
@@ -137,23 +123,27 @@ export class ModelLists {
|
|
|
137
123
|
: read;
|
|
138
124
|
if (this.reads.get(key)?.generation === generation) {
|
|
139
125
|
this.reads.delete(key);
|
|
140
|
-
this.
|
|
141
|
-
this.entries
|
|
142
|
-
list: result,
|
|
143
|
-
expiresAt: this.now() + (read.source === "live" ? LIVE_TTL_MS : FAILURE_TTL_MS),
|
|
144
|
-
});
|
|
145
|
-
while (this.entries.size > MAX_ENTRIES) {
|
|
146
|
-
const oldest = this.entries.keys().next().value;
|
|
147
|
-
if (oldest === undefined) break;
|
|
148
|
-
this.entries.delete(oldest);
|
|
149
|
-
}
|
|
126
|
+
const expiresAt = this.now() + (read.source === "live" ? LIVE_TTL_MS : FAILURE_TTL_MS);
|
|
127
|
+
setBounded(this.entries, key, { list: result, expiresAt }, MAX_ENTRIES);
|
|
150
128
|
}
|
|
151
129
|
return result;
|
|
152
130
|
});
|
|
153
|
-
this.reads.set(key, {
|
|
131
|
+
this.reads.set(key, {
|
|
132
|
+
harness: query.harness,
|
|
133
|
+
generation,
|
|
134
|
+
refresh: Boolean(query.refresh),
|
|
135
|
+
list,
|
|
136
|
+
});
|
|
154
137
|
return list;
|
|
155
138
|
}
|
|
156
139
|
|
|
140
|
+
/** The harness's login changed: its lists are read again, and no read under way is kept. */
|
|
141
|
+
forget(harness: AgentHarness): void {
|
|
142
|
+
for (const [key, entry] of this.entries)
|
|
143
|
+
if (entry.list.harness === harness) this.entries.delete(key);
|
|
144
|
+
for (const [key, read] of this.reads) if (read.harness === harness) this.reads.delete(key);
|
|
145
|
+
}
|
|
146
|
+
|
|
157
147
|
/**
|
|
158
148
|
* The levels `model` runs on a turn with this login and folder. First the
|
|
159
149
|
* list read for that login; failing that, any login's list or the catalog,
|
|
@@ -164,7 +154,7 @@ export class ModelLists {
|
|
|
164
154
|
* `undefined` when nothing known applies.
|
|
165
155
|
*/
|
|
166
156
|
thinkingFor(
|
|
167
|
-
query: Omit<
|
|
157
|
+
query: Omit<ModelsListParams, "refresh" | "cwd"> & { cwd: string },
|
|
168
158
|
model: string,
|
|
169
159
|
): readonly ThinkingLevel[] | undefined {
|
|
170
160
|
const own = [query.sessionId, undefined].map((sessionId) =>
|
|
@@ -193,27 +183,22 @@ export class ModelLists {
|
|
|
193
183
|
): Promise<ModelList> {
|
|
194
184
|
const controller = new AbortController();
|
|
195
185
|
const timeoutMs = this.options.timeoutMs ?? LIST_TIMEOUT_MS;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
186
|
+
try {
|
|
187
|
+
const listed = await withTimeout(list(controller.signal), timeoutMs);
|
|
188
|
+
if (!listed) {
|
|
199
189
|
const error = new Error(
|
|
200
190
|
`the ${harness} CLI did not list its models within ${timeoutMs} ms`,
|
|
201
191
|
);
|
|
202
192
|
controller.abort(error);
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const models = await Promise.race([list(controller.signal), deadline]);
|
|
208
|
-
if (!models.length) throw new Error(`the ${harness} CLI listed no models`);
|
|
209
|
-
return { harness, models, source: "live", fetchedAt: this.now() };
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
if (!listed.value.length) throw new Error(`the ${harness} CLI listed no models`);
|
|
196
|
+
return { harness, models: listed.value, source: "live", fetchedAt: this.now() };
|
|
210
197
|
} catch (error) {
|
|
211
198
|
return {
|
|
212
199
|
...catalogModelList(harness, this.now()),
|
|
213
200
|
error: error instanceof Error ? error.message : String(error),
|
|
214
201
|
};
|
|
215
|
-
} finally {
|
|
216
|
-
clearTimeout(timer);
|
|
217
202
|
}
|
|
218
203
|
}
|
|
219
204
|
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PermissionOption,
|
|
3
|
+
PermissionOptionKind,
|
|
4
|
+
PermissionOutcome,
|
|
5
|
+
} from "../../protocol/index.ts";
|
|
6
|
+
import { STANDARD_PERMISSION_OPTIONS, isAllowKind } from "../../protocol/index.ts";
|
|
7
|
+
import type { PermissionDecision, PermissionRequestHandler } from "../agents/base.ts";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* What a harness's request offers, and so who keeps an "always" answer: read
|
|
11
|
+
* once from `PermissionRequestHandler`'s `options` and `always`.
|
|
12
|
+
*/
|
|
13
|
+
export type PermissionAsk =
|
|
14
|
+
/** The harness's own choices (a plan's approval: the mode to go on in). */
|
|
15
|
+
| { kind: "own_options"; options: PermissionOption[] }
|
|
16
|
+
/** The standard four; the engine keeps "always" as a standing rule for the tool. */
|
|
17
|
+
| { kind: "engine_always" }
|
|
18
|
+
/** The harness keeps "always" itself, as narrowly as `rule` says. */
|
|
19
|
+
| { kind: "harness_always"; rule: string }
|
|
20
|
+
/** No "always" can be scoped: allow or reject this call. */
|
|
21
|
+
| { kind: "once" };
|
|
22
|
+
|
|
23
|
+
// @ref LLP 0001#d4--permission-requests-are-first-class-protocol — a harness's own choices
|
|
24
|
+
/**
|
|
25
|
+
* Read what a request offers. A harness's own choices ask something no
|
|
26
|
+
* standing answer covers. "Always" covers what the harness says it does,
|
|
27
|
+
* never every call to the tool: one `npm test` must not approve every later
|
|
28
|
+
* command, so a harness that keeps it itself, or cannot scope one, says so,
|
|
29
|
+
* and the engine keeps no standing rule for its requests (only a harness
|
|
30
|
+
* with no memory of its own, ACP, leaves the engine one).
|
|
31
|
+
*/
|
|
32
|
+
export function permissionAsk(opts: Parameters<PermissionRequestHandler>[1]): PermissionAsk {
|
|
33
|
+
if (opts?.options) return { kind: "own_options", options: opts.options };
|
|
34
|
+
if (opts?.always === undefined) return { kind: "engine_always" };
|
|
35
|
+
if (opts.always === null) return { kind: "once" };
|
|
36
|
+
return { kind: "harness_always", rule: opts.always.rule };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The standard option of this kind. */
|
|
40
|
+
const standard = (kind: PermissionOptionKind) =>
|
|
41
|
+
STANDARD_PERMISSION_OPTIONS.find((option) => option.kind === kind);
|
|
42
|
+
|
|
43
|
+
/** The options a request offers. A harness that keeps "always" keeps no refusal: there is no "always reject" for it. */
|
|
44
|
+
export function optionsFor(ask: PermissionAsk): PermissionOption[] {
|
|
45
|
+
switch (ask.kind) {
|
|
46
|
+
case "own_options":
|
|
47
|
+
return ask.options;
|
|
48
|
+
case "engine_always":
|
|
49
|
+
return [...STANDARD_PERMISSION_OPTIONS];
|
|
50
|
+
case "harness_always":
|
|
51
|
+
return STANDARD_PERMISSION_OPTIONS.filter((o) => o.kind !== "reject_always").map((o) =>
|
|
52
|
+
o.kind === "allow_always" ? { ...o, name: `Always allow ${ask.rule}` } : o,
|
|
53
|
+
);
|
|
54
|
+
case "once":
|
|
55
|
+
return STANDARD_PERMISSION_OPTIONS.filter(
|
|
56
|
+
(o) => o.kind === "allow_once" || o.kind === "reject_once",
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* What the harness is told for a selected answer, and the option it counts
|
|
63
|
+
* as. A client that renders no options answers with the standard ids: one
|
|
64
|
+
* that was not offered means a plain allow or reject, never "always".
|
|
65
|
+
*/
|
|
66
|
+
export function decisionFor(
|
|
67
|
+
outcome: Extract<PermissionOutcome, { outcome: "selected" }>,
|
|
68
|
+
offered: PermissionOption[],
|
|
69
|
+
): { decision: PermissionDecision; selected?: PermissionOption } {
|
|
70
|
+
const plain = STANDARD_PERMISSION_OPTIONS.find((o) => o.optionId === outcome.optionId);
|
|
71
|
+
const selected =
|
|
72
|
+
offered.find((o) => o.optionId === outcome.optionId) ??
|
|
73
|
+
(plain && standard(isAllowKind(plain.kind) ? "allow_once" : "reject_once"));
|
|
74
|
+
const chosen = {
|
|
75
|
+
...(selected && { optionId: selected.optionId }),
|
|
76
|
+
...(outcome.message && { message: outcome.message }),
|
|
77
|
+
};
|
|
78
|
+
const decision: PermissionDecision = isAllowKind(selected?.kind)
|
|
79
|
+
? {
|
|
80
|
+
decision: "allow",
|
|
81
|
+
// What was approved is what runs: an edited input replaces the
|
|
82
|
+
// original all the way into the harness.
|
|
83
|
+
...(outcome.updatedInput !== undefined && { updatedInput: outcome.updatedInput }),
|
|
84
|
+
...chosen,
|
|
85
|
+
}
|
|
86
|
+
: { decision: "deny", reason: "Denied by user", ...chosen };
|
|
87
|
+
return { decision, selected };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* A session's standing answers: an "always" the user gave for a tool answers
|
|
92
|
+
* its later calls without a round trip (and without a prompt event that never
|
|
93
|
+
* happened). A rule carries the verdict only: an edited input belongs to the
|
|
94
|
+
* call it was made for. Kept until the session closes.
|
|
95
|
+
*/
|
|
96
|
+
export class StandingRules {
|
|
97
|
+
private readonly verdicts = new Map<string, "allow" | "deny">();
|
|
98
|
+
|
|
99
|
+
/** The decision a standing rule gives this tool, if there is one. */
|
|
100
|
+
answer(toolName: string): PermissionDecision | undefined {
|
|
101
|
+
const verdict = this.verdicts.get(toolName);
|
|
102
|
+
if (!verdict) return undefined;
|
|
103
|
+
return verdict === "allow"
|
|
104
|
+
? { decision: "allow" }
|
|
105
|
+
: { decision: "deny", reason: "Denied by a standing rule" };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** An `*_always` answer becomes the tool's standing rule. */
|
|
109
|
+
learn(toolName: string, selected: PermissionOption | undefined): void {
|
|
110
|
+
if (selected?.kind === "allow_always") this.verdicts.set(toolName, "allow");
|
|
111
|
+
else if (selected?.kind === "reject_always") this.verdicts.set(toolName, "deny");
|
|
112
|
+
}
|
|
113
|
+
}
|