@qlairoslabs/acp-client 0.12.0 → 0.13.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG-consumer-fixes.md +17 -3
- package/CHANGELOG-controller-interface.md +258 -0
- package/CHANGELOG-metering.md +29 -0
- package/CHANGELOG-operation-lifecycle.md +15 -1
- package/CONSUMER_GUIDE.md +847 -7
- package/MIGRATION-0.10-to-0.12.md +4 -1
- package/MIGRATION-0.12-to-0.13.md +275 -0
- package/README.md +17 -16
- package/package.json +4 -2
- package/src/acp-client-handlers.ts +48 -0
- package/src/activity.ts +3 -0
- package/src/adapters.ts +30 -0
- package/src/agent/adoption/provider-attachment.ts +33 -0
- package/src/agent/adoption/provider-session-delete.ts +1 -1
- package/src/agent/adoption/provider-sessions.ts +3 -2
- package/src/agent/append-assistant-message.ts +91 -0
- package/src/agent/config.ts +54 -6
- package/src/agent/conversation-manager.ts +94 -158
- package/src/agent/manager-settings.ts +1 -0
- package/src/agent/native-channel-lifecycle.ts +111 -0
- package/src/agent/persisted-lifecycle.ts +44 -4
- package/src/agent/persistence-policy/context.ts +13 -0
- package/src/agent/persistence-policy/resolver.ts +7 -0
- package/src/agent/persistence-policy/types.ts +1 -0
- package/src/agent/record-capture.ts +1 -0
- package/src/agent-adapter-registry.ts +33 -7
- package/src/agent-conversation-contracts.ts +14 -1
- package/src/agent-conversation-errors.ts +8 -0
- package/src/agent-conversation-owner.ts +9 -4
- package/src/agent-session-config.ts +135 -0
- package/src/agent-session.ts +439 -934
- package/src/agent.ts +73 -0
- package/src/capabilities.ts +2 -0
- package/src/checkpointing/recovery.ts +10 -0
- package/src/cli/index.ts +3 -3
- package/src/cli/managed.ts +2 -2
- package/src/client.ts +68 -98
- package/src/connection-attempt.ts +95 -0
- package/src/controller-connection.ts +114 -0
- package/src/controller.ts +156 -148
- package/src/conversation-controller/capabilities.ts +88 -0
- package/src/conversation-controller/contracts.ts +208 -0
- package/src/conversation-controller/factory.ts +39 -0
- package/src/conversation-controller/guards.ts +98 -0
- package/src/conversation-controller/index.ts +20 -0
- package/src/conversation-startup.ts +35 -0
- package/src/conversation-turns/backend-turns.ts +373 -0
- package/src/conversation-turns/clear-operations.ts +37 -0
- package/src/conversation-turns/context.ts +135 -0
- package/src/conversation-turns/index.ts +4 -0
- package/src/conversation-turns/record-helpers.ts +75 -0
- package/src/conversation-turns/recording.ts +235 -0
- package/src/conversation-turns/run-turn.ts +367 -0
- package/src/conversation-turns/turn-run.ts +57 -0
- package/src/errors.ts +41 -0
- package/src/handoff-options.ts +81 -0
- package/src/identity/checkpoint-backed.ts +1 -1
- package/src/index.ts +58 -3
- package/src/internal-inference/coordination/manager.ts +11 -0
- package/src/internal-inference/runtime/harness-runtime.ts +4 -4
- package/src/launcher.ts +35 -2
- package/src/media/parts.ts +5 -0
- package/src/message-status.ts +83 -0
- package/src/metering/engine.ts +39 -64
- package/src/metering/measurement-provenance.ts +36 -0
- package/src/metering/native/durability.ts +115 -0
- package/src/metering/native/ledger.ts +104 -0
- package/src/metering/native/operation.ts +85 -0
- package/src/metering/native/projection.ts +114 -0
- package/src/metering/native/proof.ts +51 -0
- package/src/metering/native/requirements.ts +10 -0
- package/src/metering/native/retirement.ts +92 -0
- package/src/metering/native/source.ts +90 -0
- package/src/metering/record.ts +38 -1
- package/src/metering/state.ts +13 -3
- package/src/native/approvals.ts +169 -0
- package/src/native/capabilities.ts +17 -0
- package/src/native/channel-changes.ts +211 -0
- package/src/native/connection.ts +56 -0
- package/src/native/controller.ts +591 -0
- package/src/native/delegation-sender.ts +26 -0
- package/src/native/errors.ts +35 -0
- package/src/native/functions.ts +156 -0
- package/src/native/host-config.ts +59 -0
- package/src/native/host.ts +909 -0
- package/src/native/item-receipts.ts +15 -0
- package/src/native/metering.ts +12 -0
- package/src/native/records.ts +166 -0
- package/src/native/recovery.ts +186 -0
- package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
- package/src/native/reminders/idle.ts +70 -0
- package/src/native/reminders/limits.ts +19 -0
- package/src/native/reminders/notifications.ts +29 -0
- package/src/native/reminders/reminders.test.ts +553 -0
- package/src/native/reminders/routine-config.typecheck.ts +13 -0
- package/src/native/reminders/routine-guard.ts +66 -0
- package/src/native/reminders/routine-schedule.ts +25 -0
- package/src/native/reminders/routine-wire.ts +21 -0
- package/src/native/reminders/schedule.ts +97 -0
- package/src/native/reminders/service.ts +280 -0
- package/src/native/reminders/supervisor.ts +91 -0
- package/src/native/reminders/sync.ts +301 -0
- package/src/native/reminders/wire.ts +197 -0
- package/src/native/reminders/wire.typecheck.ts +13 -0
- package/src/native/submission-withdrawal.ts +65 -0
- package/src/native/usage.ts +15 -0
- package/src/native/worker-delivery.ts +61 -0
- package/src/native-harness/.res/README.md +1 -0
- package/src/native-harness/.res/architecture/README.md +21 -0
- package/src/native-harness/.res/architecture/context-and-data.md +31 -0
- package/src/native-harness/.res/architecture/execution.md +42 -0
- package/src/native-harness/.res/architecture/overview.md +44 -0
- package/src/native-harness/.res/architecture/persistence.md +56 -0
- package/src/native-harness/.res/architecture/suspend-and-resume.md +45 -0
- package/src/native-harness/.res/architecture/technical-architecture.md +50 -0
- package/src/native-harness/.res/decisions/0001-basic-loop.md +11 -0
- package/src/native-harness/.res/decisions/0002-channel-input.md +17 -0
- package/src/native-harness/.res/decisions/0003-inference-inspection.md +14 -0
- package/src/native-harness/.res/decisions/0004-shared-context.md +21 -0
- package/src/native-harness/.res/decisions/0005-notice-inbox.md +20 -0
- package/src/native-harness/.res/decisions/0006-explicit-notices.md +12 -0
- package/src/native-harness/.res/decisions/0007-channel-output.md +12 -0
- package/src/native-harness/.res/decisions/0008-browser-client.md +16 -0
- package/src/native-harness/.res/decisions/0009-scripted-model.md +18 -0
- package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +19 -0
- package/src/native-harness/.res/decisions/0011-stdio-transport.md +21 -0
- package/src/native-harness/.res/decisions/0012-session-storage-contract.md +37 -0
- package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +64 -0
- package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +73 -0
- package/src/native-harness/.res/decisions/0015-session-file-contract.md +72 -0
- package/src/native-harness/.res/decisions/0016-configuration-permissions.md +159 -0
- package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +69 -0
- package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +78 -0
- package/src/native-harness/.res/decisions/0019-model-execution.md +188 -0
- package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +71 -0
- package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +100 -0
- package/src/native-harness/.res/decisions/0022-operator-controls.md +115 -0
- package/src/native-harness/.res/decisions/0023-long-running-mock.md +82 -0
- package/src/native-harness/.res/decisions/0024-callback-policy-names.md +46 -0
- package/src/native-harness/.res/decisions/0025-external-notices.md +364 -0
- package/src/native-harness/.res/decisions/0026-bounded-context.md +81 -0
- package/src/native-harness/.res/decisions/0027-development-instructions.md +22 -0
- package/src/native-harness/.res/decisions/0028-debug-tools.md +16 -0
- package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +37 -0
- package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +145 -0
- package/src/native-harness/.res/decisions/0031-one-off-reminders.md +173 -0
- package/src/native-harness/.res/docs/11-15.md +148 -0
- package/src/native-harness/.res/docs/BUSINESS_RULES.md +111 -0
- package/src/native-harness/.res/docs/WORK.md +65 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +312 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +77 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +313 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +160 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +89 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +135 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +143 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +93 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +181 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +433 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +60 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +141 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +168 -0
- package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +111 -0
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +129 -0
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +135 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +437 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +127 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +203 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +292 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +91 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +187 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +148 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +95 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +200 -0
- package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +80 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +206 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +106 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +297 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +41 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +36 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +84 -0
- package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +147 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +15 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +107 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +114 -0
- package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +24 -0
- package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +23 -0
- package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +103 -0
- package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +50 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +337 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +76 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +204 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +73 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +64 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +58 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +45 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +108 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +169 -0
- package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +128 -0
- package/src/native-harness/.res/marketing-draft.md +22 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/README.md +285 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +19 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +138 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +148 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +172 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +194 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +233 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +249 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +265 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +279 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +293 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +307 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +29 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +317 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +327 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +40 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +59 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +69 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +79 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +89 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +102 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +116 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +49 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +87 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +289 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +221 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +287 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +165 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/state.json +22 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +2 -0
- package/src/native-harness/AGENTS.md +70 -0
- package/src/native-harness/ARCHITECTURE.md +249 -0
- package/src/native-harness/README.md +726 -0
- package/src/native-harness/bun.lock +26 -0
- package/src/native-harness/package.json +24 -0
- package/src/native-harness/src/capabilities/context/build.ts +59 -0
- package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
- package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
- package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
- package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
- package/src/native-harness/src/capabilities/context/session.ts +92 -0
- package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
- package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
- package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
- package/src/native-harness/src/capabilities/model/runner.ts +116 -0
- package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
- package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
- package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
- package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
- package/src/native-harness/src/capabilities/model/usage.ts +15 -0
- package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
- package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
- package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
- package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
- package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
- package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
- package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
- package/src/native-harness/src/capabilities/tools/reminders/index.ts +75 -0
- package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
- package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
- package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
- package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
- package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
- package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
- package/src/native-harness/src/client.ts +18 -0
- package/src/native-harness/src/contracts/agent.ts +105 -0
- package/src/native-harness/src/contracts/config-permissions.ts +47 -0
- package/src/native-harness/src/contracts/context.ts +112 -0
- package/src/native-harness/src/contracts/events.ts +47 -0
- package/src/native-harness/src/contracts/input-limits.ts +7 -0
- package/src/native-harness/src/contracts/inspection.ts +22 -0
- package/src/native-harness/src/contracts/loop.ts +31 -0
- package/src/native-harness/src/contracts/model-execution.ts +83 -0
- package/src/native-harness/src/contracts/operator-controls.ts +106 -0
- package/src/native-harness/src/contracts/output.ts +13 -0
- package/src/native-harness/src/contracts/protocol.ts +320 -0
- package/src/native-harness/src/contracts/reminders.ts +132 -0
- package/src/native-harness/src/contracts/scenario.ts +42 -0
- package/src/native-harness/src/contracts/session-file.ts +19 -0
- package/src/native-harness/src/contracts/session.ts +184 -0
- package/src/native-harness/src/contracts/storage.ts +596 -0
- package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
- package/src/native-harness/src/contracts/tools.ts +133 -0
- package/src/native-harness/src/governance/permissions/gate.ts +129 -0
- package/src/native-harness/src/governance/policy/resolve.ts +32 -0
- package/src/native-harness/src/index.ts +318 -0
- package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
- package/src/native-harness/src/interfaces/cli/development.ts +145 -0
- package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
- package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
- package/src/native-harness/src/interfaces/cli/main.ts +47 -0
- package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
- package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
- package/src/native-harness/src/interfaces/cli/start.ts +106 -0
- package/src/native-harness/src/interfaces/client.ts +225 -0
- package/src/native-harness/src/interfaces/inspector/index.html +283 -0
- package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
- package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
- package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
- package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
- package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
- package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
- package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
- package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
- package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
- package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
- package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
- package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
- package/src/native-harness/src/interfaces/protocol/server.ts +517 -0
- package/src/native-harness/src/interfaces/protocol/stdio-client.ts +119 -0
- package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
- package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
- package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
- package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
- package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
- package/src/native-harness/src/kernel/channels.ts +405 -0
- package/src/native-harness/src/kernel/loop.ts +45 -0
- package/src/native-harness/src/runtime/config/development.ts +23 -0
- package/src/native-harness/src/runtime/config/managed.ts +2 -0
- package/src/native-harness/src/runtime/config/paths.ts +27 -0
- package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
- package/src/native-harness/src/runtime/reminder-validation.ts +104 -0
- package/src/native-harness/src/runtime/reminders.ts +66 -0
- package/src/native-harness/src/state/storage/archive.ts +239 -0
- package/src/native-harness/src/state/storage/engine.ts +1013 -0
- package/src/native-harness/src/state/storage/inference.ts +124 -0
- package/src/native-harness/src/state/storage/memory-reminders.ts +78 -0
- package/src/native-harness/src/state/storage/memory.ts +341 -0
- package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
- package/src/native-harness/src/state/storage/reminder-archive.ts +63 -0
- package/src/native-harness/src/state/storage/reminder-change.ts +92 -0
- package/src/native-harness/src/state/storage/reminder-tables.ts +27 -0
- package/src/native-harness/src/state/storage/retrieval.ts +122 -0
- package/src/native-harness/src/state/storage/script-identity.ts +7 -0
- package/src/native-harness/src/state/storage/session-file.ts +85 -0
- package/src/native-harness/src/state/storage/sqlite-reminders.ts +134 -0
- package/src/native-harness/src/state/storage/sqlite.ts +625 -0
- package/src/native-harness/src/testing.ts +190 -0
- package/src/native-harness/src/util/config.ts +58 -0
- package/src/native-harness/src/util/json.ts +41 -0
- package/src/native-harness/src/util/message-position.ts +3 -0
- package/src/native-harness/src/util/reminder-schedule.ts +44 -0
- package/src/native-harness/src/util/schema.ts +40 -0
- package/src/native-harness/src/util/timeline-text.ts +72 -0
- package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
- package/src/native-harness/test/agent.test.ts +130 -0
- package/src/native-harness/test/approval-gate.test.ts +255 -0
- package/src/native-harness/test/approval-protocol.test.ts +94 -0
- package/src/native-harness/test/boundaries.test.ts +18 -0
- package/src/native-harness/test/channel-controls.test.ts +322 -0
- package/src/native-harness/test/client-abort.test.ts +136 -0
- package/src/native-harness/test/config-policy.test.ts +301 -0
- package/src/native-harness/test/conformance/storage.ts +1141 -0
- package/src/native-harness/test/context.test.ts +177 -0
- package/src/native-harness/test/crash.test.ts +187 -0
- package/src/native-harness/test/debug-tools.test.ts +67 -0
- package/src/native-harness/test/development-cli.test.ts +67 -0
- package/src/native-harness/test/development.test.ts +171 -0
- package/src/native-harness/test/dispatch-evidence.test.ts +58 -0
- package/src/native-harness/test/e2e.test.ts +186 -0
- package/src/native-harness/test/external-notices.test.ts +101 -0
- package/src/native-harness/test/fixtures/approval-e2e.jsonl +4 -0
- package/src/native-harness/test/fixtures/crash-scenario.jsonl +5 -0
- package/src/native-harness/test/fixtures/development-lifecycle.jsonl +10 -0
- package/src/native-harness/test/fixtures/echo-scenario.jsonl +3 -0
- package/src/native-harness/test/fixtures/format2-schema.ts +27 -0
- package/src/native-harness/test/fixtures/format3-schema.ts +16 -0
- package/src/native-harness/test/fixtures/hold-scenario.jsonl +4 -0
- package/src/native-harness/test/fixtures/model-e2e.jsonl +3 -0
- package/src/native-harness/test/fixtures/storage-owner.ts +20 -0
- package/src/native-harness/test/format-reply.test.ts +10 -0
- package/src/native-harness/test/helpers/operator-view.ts +41 -0
- package/src/native-harness/test/helpers/scenario.ts +9 -0
- package/src/native-harness/test/helpers/session.ts +38 -0
- package/src/native-harness/test/helpers/stdio.ts +46 -0
- package/src/native-harness/test/inspector.test.ts +77 -0
- package/src/native-harness/test/listeners.test.ts +49 -0
- package/src/native-harness/test/loop.test.ts +88 -0
- package/src/native-harness/test/model-channel-double.test.ts +87 -0
- package/src/native-harness/test/model-crash.test.ts +62 -0
- package/src/native-harness/test/model-delivery-regressions.test.ts +55 -0
- package/src/native-harness/test/model-e2e.test.ts +71 -0
- package/src/native-harness/test/model-final-filter.test.ts +30 -0
- package/src/native-harness/test/model-large-reply.test.ts +28 -0
- package/src/native-harness/test/model-live-queue.test.ts +33 -0
- package/src/native-harness/test/model-runner.test.ts +117 -0
- package/src/native-harness/test/model-storage.test.ts +99 -0
- package/src/native-harness/test/model-stream-adapter.test.ts +26 -0
- package/src/native-harness/test/model-stream-public.test.ts +77 -0
- package/src/native-harness/test/notices.test.ts +64 -0
- package/src/native-harness/test/openrouter-config.test.ts +218 -0
- package/src/native-harness/test/operator-controls.test.ts +132 -0
- package/src/native-harness/test/output.test.ts +44 -0
- package/src/native-harness/test/owner-config.test.ts +64 -0
- package/src/native-harness/test/permissions-e2e.test.ts +68 -0
- package/src/native-harness/test/persistence.test.ts +236 -0
- package/src/native-harness/test/portability.test.ts +337 -0
- package/src/native-harness/test/protocol.test.ts +160 -0
- package/src/native-harness/test/reminder-clock.test.ts +61 -0
- package/src/native-harness/test/reminder-stdio.test.ts +140 -0
- package/src/native-harness/test/reminder-storage.test.ts +124 -0
- package/src/native-harness/test/scenario-jsonl.test.ts +112 -0
- package/src/native-harness/test/scripted.test.ts +92 -0
- package/src/native-harness/test/session-file.test.ts +51 -0
- package/src/native-harness/test/startup-channel-changes.test.ts +256 -0
- package/src/native-harness/test/stdio.test.ts +132 -0
- package/src/native-harness/test/storage-memory.test.ts +4 -0
- package/src/native-harness/test/storage-sqlite.test.ts +420 -0
- package/src/native-harness/test/suspension.test.ts +430 -0
- package/src/native-harness/test/timeline-retrieval.test.ts +211 -0
- package/src/native-harness/test/tools-catalog.test.ts +468 -0
- package/src/native-harness/test/tools-protocol.test.ts +418 -0
- package/src/native-harness/test/transfers.test.ts +94 -0
- package/src/native-harness/test/web-chat.test.ts +35 -0
- package/src/native-harness/tsconfig.json +20 -0
- package/src/observation/agent-event-bus.ts +44 -18
- package/src/observation/index.ts +1 -0
- package/src/operations/contracts.ts +11 -3
- package/src/operations/errors.ts +5 -0
- package/src/operations/stale-policy.ts +1 -1
- package/src/operations/supervisor.ts +34 -10
- package/src/orchestrator/acp-delivery.ts +68 -0
- package/src/orchestrator/assignments.ts +27 -0
- package/src/orchestrator/busy.ts +15 -0
- package/src/orchestrator/config.ts +41 -0
- package/src/orchestrator/consumer-api.ts +24 -0
- package/src/orchestrator/contracts.ts +71 -0
- package/src/orchestrator/durable-assignments.ts +111 -0
- package/src/orchestrator/native-delegation.ts +103 -0
- package/src/orchestrator/orchestrator.ts +318 -0
- package/src/orchestrator/permissions.ts +25 -0
- package/src/orchestrator/policy.ts +44 -0
- package/src/orchestrator/pool.ts +123 -0
- package/src/orchestrator/tool-descriptions.ts +11 -0
- package/src/permissions/acp.ts +18 -0
- package/src/permissions/arrival.ts +13 -0
- package/src/permissions/consumer-config.ts +19 -0
- package/src/permissions/conversation.ts +280 -0
- package/src/permissions/matcher.ts +85 -0
- package/src/permissions/outcome.ts +15 -0
- package/src/permissions/policy.ts +81 -0
- package/src/permissions/request.ts +26 -0
- package/src/persistence/activity-projection.ts +1 -0
- package/src/persistence/backend.ts +34 -1
- package/src/persistence/channels.ts +23 -0
- package/src/persistence/index.ts +4 -0
- package/src/persistence/protocol-method.ts +5 -0
- package/src/persistence/reminder-wake.ts +49 -0
- package/src/persistence/reminders.ts +385 -0
- package/src/persistence/sqlite-backend.ts +84 -6
- package/src/persistence/sqlite-channels.ts +65 -0
- package/src/persistence/sqlite-reminders.ts +85 -0
- package/src/persistence/sqlite-schema.ts +108 -3
- package/src/persistence/sqlite-worker-delivery.ts +374 -0
- package/src/persistence/sqlite-workers.ts +59 -0
- package/src/persistence/worker-delivery-contract.ts +104 -0
- package/src/persistence/worker-terminal-reason.ts +29 -0
- package/src/persistence/workers.ts +19 -0
- package/src/provider-notices.ts +137 -0
- package/src/repl/commands.ts +2 -2
- package/src/steering/combine.ts +3 -1
- package/src/steering/contracts.ts +11 -2
- package/src/steering/controller.ts +3 -2
- package/src/transport/acp-transport.ts +24 -14
- package/src/types.ts +15 -12
- package/src/updates.ts +14 -2
- package/src/wire-log.ts +1 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Neutral capabilities of a conversation's backend (controller-interface spec, Capabilities).
|
|
3
|
+
*
|
|
4
|
+
* Two kinds of support are kept apart: what the *controller type* supports is the presence of its
|
|
5
|
+
* optional methods (the compiler forces the check), and what the *backend offers* is data, which can
|
|
6
|
+
* change and may be unknown: `ConversationCapabilities`. The raw ACP `Capabilities` stays on the
|
|
7
|
+
* `HarnessController`, the session and the conversation with its shape unchanged.
|
|
8
|
+
*/
|
|
9
|
+
import type { Capabilities } from "../capabilities.ts";
|
|
10
|
+
import { NotConnectedError } from "../errors.ts";
|
|
11
|
+
import type { MediaCapabilities } from "../media/acp.ts";
|
|
12
|
+
|
|
13
|
+
export interface ConversationCapabilities {
|
|
14
|
+
/** Steer by injecting into the running turn; false for the `HarnessController`. */
|
|
15
|
+
nativeSteering: boolean;
|
|
16
|
+
reminders?: boolean;
|
|
17
|
+
/** True once an executable native open confirms an unattended-turn guard. */
|
|
18
|
+
routines?: boolean;
|
|
19
|
+
/** Null when unknown: before the agent's `initialize`, and in PTY mode. */
|
|
20
|
+
backend: BackendCapabilities | null;
|
|
21
|
+
/**
|
|
22
|
+
* `false`: the backend cannot start a fresh context, so `startFresh` (and whatever needs it: a context
|
|
23
|
+
* reset, recovery onto a new provider session) is unsupported and throws `UnsupportedError` before
|
|
24
|
+
* changing anything. Absent: it can. A native conversation shares its agent's session and timeline,
|
|
25
|
+
* and has no context reset.
|
|
26
|
+
*/
|
|
27
|
+
freshContext?: false;
|
|
28
|
+
/**
|
|
29
|
+
* `"backend"`: the backend enforces its own deadlines at the model, approval and tool boundaries and
|
|
30
|
+
* reports each turn's outcome, so the host's output-silence limits do not apply to its turns. A
|
|
31
|
+
* tool can run for a long time while producing no output. Absent: the host's stall limits apply.
|
|
32
|
+
*/
|
|
33
|
+
supervision?: "backend";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface BackendCapabilities {
|
|
37
|
+
/** Can reattach to a provider session with its context. */
|
|
38
|
+
loadSession: boolean;
|
|
39
|
+
forkSession: boolean;
|
|
40
|
+
listSessions: boolean;
|
|
41
|
+
media: { image: boolean; audio: boolean; file: boolean };
|
|
42
|
+
mcpServers: { stdio: boolean; http: boolean; sse: boolean };
|
|
43
|
+
/** The raw ACP `initialize` result. */
|
|
44
|
+
acp?: Capabilities;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The backend capabilities of an ACP agent, from its `initialize` result. `file` is the agent's
|
|
49
|
+
* `embeddedContext` (how ACP carries a file's content); every ACP agent accepts stdio MCP servers.
|
|
50
|
+
*/
|
|
51
|
+
export function fromAcp(capabilities: Capabilities): BackendCapabilities {
|
|
52
|
+
const agent = capabilities.agent;
|
|
53
|
+
return {
|
|
54
|
+
loadSession: agent.loadSession,
|
|
55
|
+
forkSession: agent.sessionCapabilities.fork,
|
|
56
|
+
listSessions: agent.sessionCapabilities.list,
|
|
57
|
+
media: {
|
|
58
|
+
image: agent.promptCapabilities.image,
|
|
59
|
+
audio: agent.promptCapabilities.audio,
|
|
60
|
+
file: agent.promptCapabilities.embeddedContext,
|
|
61
|
+
},
|
|
62
|
+
mcpServers: { stdio: true, http: agent.mcpCapabilities.http, sse: agent.mcpCapabilities.sse },
|
|
63
|
+
acp: capabilities,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What an ACP controller reports: no native steering; `backend` unknown until the agent has answered. */
|
|
68
|
+
export function conversationCapabilitiesFromAcp(capabilities: Capabilities | null): ConversationCapabilities {
|
|
69
|
+
return { nativeSteering: false, reminders: false, backend: capabilities ? fromAcp(capabilities) : null };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The same, read from an ACP client that may be absent (PTY mode) or not connected yet. */
|
|
73
|
+
export function conversationCapabilitiesOf(client: { readonly capabilities: Capabilities } | null | undefined): ConversationCapabilities {
|
|
74
|
+
let capabilities: Capabilities | null = null;
|
|
75
|
+
if (client) {
|
|
76
|
+
try {
|
|
77
|
+
capabilities = client.capabilities;
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (!(error instanceof NotConnectedError)) throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return conversationCapabilitiesFromAcp(capabilities);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The media a backend accepts, in the shape the prompt builder reads (`file` is ACP's `embeddedContext`); none when unknown. */
|
|
86
|
+
export function mediaCapabilitiesOf(backend: BackendCapabilities | null): MediaCapabilities | undefined {
|
|
87
|
+
return backend ? { image: backend.media.image, audio: backend.media.audio, embeddedContext: backend.media.file } : undefined;
|
|
88
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a conversation needs from its backend: the turn members of `ConversationController`
|
|
3
|
+
* (controller-interface spec, `library/11-11-SPEC-controller-interface.md`, The interface).
|
|
4
|
+
*
|
|
5
|
+
* The ownership rule: **the controller owns provider execution; the session owns the conversation's
|
|
6
|
+
* outcome.** A run of messages goes in with `send`; the controller reports when a turn starts (and,
|
|
7
|
+
* for backend-scheduled controllers, when more items are folded into a running one), never when it
|
|
8
|
+
* ends; the session prepares each reported turn with `prepareTurn`, runs it under its supervisor,
|
|
9
|
+
* and announces its completion or failure after finalization.
|
|
10
|
+
*
|
|
11
|
+
* The turn members (Brief A2), then the lifecycle, settings and capability members and the optional
|
|
12
|
+
* members (Brief B1). `HarnessController implements ConversationController`; a native controller
|
|
13
|
+
* (later) implements the core and leaves the optional members absent.
|
|
14
|
+
*/
|
|
15
|
+
import type { NativeTurnMetering } from "../metering/native/source.ts";
|
|
16
|
+
import type { ClientPrompt } from "../agent-client.ts";
|
|
17
|
+
import type { ConnectResult } from "../client.ts";
|
|
18
|
+
import type { AgentMode, ControllerStartEvent, HarnessController } from "../controller.ts";
|
|
19
|
+
import type { ConfigOptions } from "../config-options.ts";
|
|
20
|
+
import type { ConversationCapabilities } from "./capabilities.ts";
|
|
21
|
+
import type { MeteredOperationKind } from "../metering/record.ts";
|
|
22
|
+
import type { OutputListener, SupervisedProvider } from "../operations/contracts.ts";
|
|
23
|
+
import type { CombinedMessage } from "../steering/contracts.ts";
|
|
24
|
+
import type { InternalSessionCommand, PromptHandlers, ResponseMessage, SessionListPage } from "../types.ts";
|
|
25
|
+
|
|
26
|
+
/** The turn path of a conversation's backend. */
|
|
27
|
+
export interface ConversationController {
|
|
28
|
+
/**
|
|
29
|
+
* Puts a run of messages in. Resolves when the backend has accepted the run.
|
|
30
|
+
*
|
|
31
|
+
* Session-scheduled (the `HarnessController`): makes no provider call; reports `turn_started` for
|
|
32
|
+
* the run synchronously, inside the call, with `sentBySession: true`, and returns an already
|
|
33
|
+
* resolved promise. `run.turnId` is required (a run without one is an error). So the session
|
|
34
|
+
* registers the run's state before calling `send`.
|
|
35
|
+
*
|
|
36
|
+
* Backend-scheduled (native, later): pushes each message to the backend and resolves once it has
|
|
37
|
+
* accepted them; the backend starts turns as it decides and assigns their ids, so `send` promises
|
|
38
|
+
* no turn and ignores `run.turnId`.
|
|
39
|
+
*
|
|
40
|
+
* `run.messageIds` is non-empty and in queue order; an id that is repeated is an error (the
|
|
41
|
+
* controller throws).
|
|
42
|
+
*/
|
|
43
|
+
send(run: TurnRun): Promise<void>;
|
|
44
|
+
/** Requests withdrawal of a submitted input, true only when confirmed. */
|
|
45
|
+
withdrawInput?(messageId: string, onTaken?: (turnId?: string) => void): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Turn reports: `turn_started` whenever a turn starts (because of a `send`, or on the backend's
|
|
48
|
+
* own), and, for backend-scheduled controllers only, `turn_took` when more items are folded into
|
|
49
|
+
* a running turn. Native controllers also report committed item receipts and confirmed input withdrawal.
|
|
50
|
+
* The controller never reports a turn's end: that is its prepared turn's
|
|
51
|
+
* `prompt()` settling.
|
|
52
|
+
*/
|
|
53
|
+
subscribeTurns(listener: (event: TurnEvent) => void): () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Prepares a reported turn for the supervisor. **Starts nothing:** the provider work (or, for a
|
|
56
|
+
* held turn, the replay of its output) starts when the returned turn's `prompt()` is called, after
|
|
57
|
+
* the supervisor has subscribed to its output (the attachment barrier).
|
|
58
|
+
*/
|
|
59
|
+
prepareTurn(turnId: string, content: TurnContent): PreparedTurn;
|
|
60
|
+
/**
|
|
61
|
+
* Ends a reported turn the session won't run (provider connection failed, a pre-dispatch record
|
|
62
|
+
* failed, the conversation stopped): releases the controller's bookkeeping for it and discards any
|
|
63
|
+
* output held for it. Idempotent; a call for an unknown or already executed turn does nothing.
|
|
64
|
+
* Not a cancel: it never stops provider work (that is `cancel` / `forceStop`).
|
|
65
|
+
*/
|
|
66
|
+
abandonTurn(turnId: string, reason: unknown): void;
|
|
67
|
+
/** Controller-wide supervision signals, as today. A prepared turn's own `subscribeOutput` is per turn. */
|
|
68
|
+
subscribeOutput(listener: OutputListener): () => void;
|
|
69
|
+
/** Cancels the turn executing now, as today. */
|
|
70
|
+
cancel(): void;
|
|
71
|
+
/** Stops the backend itself (controller-wide); every open prepared turn rejects. */
|
|
72
|
+
forceStop(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Prepares an internal prompt (handoff summary, recap, recovery seed): not a turn, no turn events.
|
|
75
|
+
* Starts nothing until `prompt()`; the session runs it under the same supervisor with its own stall
|
|
76
|
+
* limits. Absent when the controller type doesn't support internal prompts.
|
|
77
|
+
*/
|
|
78
|
+
prepareInternalPrompt?(content: TurnContent): SupervisedProvider;
|
|
79
|
+
|
|
80
|
+
// --- lifecycle --------------------------------------------------------------------------------
|
|
81
|
+
/**
|
|
82
|
+
* Starts the backend (resuming its context when it can). Resolves with `{ sessionId, resumed }`:
|
|
83
|
+
* `resumed: true` means the backend reattached an existing context. A start can succeed without a
|
|
84
|
+
* context (PTY mode; a working connection whose session creation failed, e.g. for authentication):
|
|
85
|
+
* `{ sessionId: "", resumed: false }`. `onProgress` gets `initialized` once the backend answered its
|
|
86
|
+
* handshake, and `internal_session_acquired` only when a context actually exists.
|
|
87
|
+
*/
|
|
88
|
+
/** Optional observation-only attachment. Disposing it leaves the backend turn running. */
|
|
89
|
+
readonly attachmentConnected?: boolean;
|
|
90
|
+
attachObservation?(): Promise<{ dispose(): void }>;
|
|
91
|
+
start(onProgress?: (event: ControllerStartEvent) => void): Promise<StartResult>;
|
|
92
|
+
/** Starts with a fresh context, never resuming. Same result and progress as `start`. */
|
|
93
|
+
startFresh(onProgress?: (event: ControllerStartEvent) => void): Promise<StartResult>;
|
|
94
|
+
stop(): Promise<void>;
|
|
95
|
+
readonly isConnected: boolean;
|
|
96
|
+
subscribeConnection(listener: () => void): () => void;
|
|
97
|
+
/** How long a cancelled turn gets before the supervisor escalates; undefined when the adapter sets none. */
|
|
98
|
+
readonly cancelGraceMs: number | undefined;
|
|
99
|
+
|
|
100
|
+
// --- settings and usage -----------------------------------------------------------------------
|
|
101
|
+
/** May be non-empty before `start`, and change after it. */
|
|
102
|
+
readonly configOptions: ConfigOptions;
|
|
103
|
+
setConfig(id: string, value: unknown): Promise<void>;
|
|
104
|
+
subscribeUsageUpdate(listener: UsageListener): () => void;
|
|
105
|
+
readonly currentSessionId: string | null;
|
|
106
|
+
/** What the backend offers, in neutral terms. Safe to read before connecting and in PTY mode. */
|
|
107
|
+
readonly conversationCapabilities: ConversationCapabilities;
|
|
108
|
+
|
|
109
|
+
// --- optional: absent when the controller type doesn't support them ---------------------------
|
|
110
|
+
// Paired members are present together or not at all. A present member says the controller type
|
|
111
|
+
// can do it; whether it can right now depends on the connection (`conversationCapabilities`).
|
|
112
|
+
readonly availableCommands?: readonly InternalSessionCommand[];
|
|
113
|
+
subscribeAvailableCommands?(listener: (commands: readonly InternalSessionCommand[]) => void): () => void;
|
|
114
|
+
readonly currentMode?: AgentMode;
|
|
115
|
+
setMode?(mode: AgentMode): Promise<StartResult>;
|
|
116
|
+
reconnect?(sessionId: string): Promise<StartResult>;
|
|
117
|
+
listSessions?(): Promise<SessionListPage>;
|
|
118
|
+
bridge?(...args: Parameters<HarnessController["bridge"]>): ReturnType<HarnessController["bridge"]>;
|
|
119
|
+
authenticate?(...args: Parameters<HarnessController["authenticate"]>): ReturnType<HarnessController["authenticate"]>;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A listener for raw usage updates (`usage_update` for ACP) with the session they came from. */
|
|
123
|
+
export type UsageListener = (update: unknown, sessionId: string | null) => void;
|
|
124
|
+
|
|
125
|
+
/** A run of messages put in by the session. */
|
|
126
|
+
export interface TurnRun {
|
|
127
|
+
/**
|
|
128
|
+
* Session-scheduled: the session's id for the run, its first message's id (required).
|
|
129
|
+
* Backend-scheduled: absent; the backend assigns turn ids.
|
|
130
|
+
*/
|
|
131
|
+
readonly turnId?: string;
|
|
132
|
+
/** Every message the run carries, in queue order: one, or several for a combined steer run. */
|
|
133
|
+
readonly messageIds: readonly string[];
|
|
134
|
+
/**
|
|
135
|
+
* The messages themselves, in `messageIds` order: the objects the queue holds (a combined steer run lists each original
|
|
136
|
+
* message), so a backend-scheduled controller gets what the user wrote without reaching back into the session. ACP
|
|
137
|
+
* controllers ignore it: the session builds their content and passes it in `prepareTurn`.
|
|
138
|
+
*/
|
|
139
|
+
readonly messages: readonly CombinedMessage[];
|
|
140
|
+
readonly operationKind: MeteredOperationKind;
|
|
141
|
+
/** Claims the local dispatch boundary for a native input, false if already withdrawn. */
|
|
142
|
+
readonly beginInput?: (messageId: string) => boolean;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** What a prepared turn runs with. */
|
|
146
|
+
export interface TurnContent {
|
|
147
|
+
/** What the backend is told. ACP only; built by the session at turn time. */
|
|
148
|
+
readonly input?: ClientPrompt;
|
|
149
|
+
/** The session's recording handlers (stream, activity, permissions); used by every backend. */
|
|
150
|
+
readonly handlers: PromptHandlers;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* One reported turn, prepared. `prompt()` starts it and settles with its result: the single
|
|
155
|
+
* authority for the provider's outcome. `subscribeOutput`, `cancel` and `forceStop` are this turn's
|
|
156
|
+
* own (per-turn supervision): its signals reach only it; `cancel` cancels only it and does nothing
|
|
157
|
+
* once it has ended in the backend; `forceStop` stops the backend itself.
|
|
158
|
+
*/
|
|
159
|
+
export interface PreparedTurn extends SupervisedProvider {
|
|
160
|
+
readonly turnId: string;
|
|
161
|
+
/** Pulls usage for this exact wire turn at the operation's close. */
|
|
162
|
+
readonly nativeMetering?: NativeTurnMetering;
|
|
163
|
+
/** Committed replies missed by a graceful stop, for persistence only. */
|
|
164
|
+
recoverStoppedReplies?(seen: readonly ResponseMessage[]): Promise<readonly ResponseMessage[] | undefined>;
|
|
165
|
+
/** False while replaying output held for a turn that already ended; the stall check applies only while live. */
|
|
166
|
+
readonly live: boolean;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** A reference to one backend item that started or joined a turn (a worker reply, another channel's message...). */
|
|
170
|
+
export type ItemRef = unknown;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Why a turn started: the messages it carries, the backend items it took, or both (a native backend takes everything
|
|
174
|
+
* waiting at a model call, so a worker reply and a user message often land in one turn). At least one is present.
|
|
175
|
+
*/
|
|
176
|
+
export type TurnCause =
|
|
177
|
+
| { readonly messageIds: readonly string[]; readonly items?: readonly ItemRef[] }
|
|
178
|
+
| { readonly messageIds?: readonly string[]; readonly items: readonly ItemRef[] };
|
|
179
|
+
|
|
180
|
+
/** A turn started. `sentBySession` is true for a turn started by the session's `send`. */
|
|
181
|
+
export interface TurnStarted {
|
|
182
|
+
readonly kind: "turn_started";
|
|
183
|
+
readonly turnId: string;
|
|
184
|
+
readonly cause: TurnCause;
|
|
185
|
+
readonly sentBySession: boolean;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** More items folded into a running turn (backend-scheduled controllers only; native steering). */
|
|
189
|
+
export interface TurnTook {
|
|
190
|
+
readonly kind: "turn_took";
|
|
191
|
+
readonly turnId: string;
|
|
192
|
+
readonly cause: TurnCause;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** A live advance in the harness's evidence for one or more items. */
|
|
196
|
+
export interface ItemsReceipt {
|
|
197
|
+
readonly kind: "items_receipt";
|
|
198
|
+
readonly turnId: string;
|
|
199
|
+
readonly itemIds: readonly string[];
|
|
200
|
+
readonly milestone: "delivered" | "seen";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export type TurnEvent = TurnStarted | TurnTook | ItemsReceipt | { readonly kind: "input_withdrawn"; readonly messageId: string };
|
|
204
|
+
|
|
205
|
+
/** A start's result: `{ sessionId, resumed }`, as today. */
|
|
206
|
+
export type StartResult = ConnectResult;
|
|
207
|
+
|
|
208
|
+
export type { ControllerStartEvent };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { idleMilliseconds } from "../native/reminders/idle.ts";
|
|
2
|
+
import type { WireReminderEvent } from "../native/reminders/wire.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Where a conversation's controller is created (controller-interface spec, Seams and files). A
|
|
5
|
+
* conversation bound to a native harness channel gets a `NativeController`; every other conversation
|
|
6
|
+
* gets a `HarnessController` for its adapter's external harness command, exactly as before. The
|
|
7
|
+
* native path is opt-in: nothing selects it unless a binding is passed.
|
|
8
|
+
*/
|
|
9
|
+
import { HarnessController, type AgentControllerConfig } from "../controller.ts";
|
|
10
|
+
import { NativeController } from "../native/controller.ts";
|
|
11
|
+
import type { NativeHarnessHost } from "../native/host.ts";
|
|
12
|
+
import type { ConversationController } from "./contracts.ts";
|
|
13
|
+
|
|
14
|
+
/** Binds a conversation to one channel of its Agent's shared native harness. */
|
|
15
|
+
export interface NativeControllerBinding {
|
|
16
|
+
readonly host: NativeHarnessHost;
|
|
17
|
+
/** The conversation's stable id. */
|
|
18
|
+
readonly channelId: string;
|
|
19
|
+
readonly defaultSender?: string;
|
|
20
|
+
readonly idleStopWindowMs?: number;
|
|
21
|
+
readonly onReminderEvent?: (event: WireReminderEvent) => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createController(config: AgentControllerConfig & { native?: NativeControllerBinding }): ConversationController {
|
|
25
|
+
if (config.native) {
|
|
26
|
+
if (config.mode && config.mode !== "normal") throw new Error("a native conversation has no degraded or bridge mode");
|
|
27
|
+
return new NativeController({
|
|
28
|
+
host: config.native.host,
|
|
29
|
+
channelId: config.native.channelId,
|
|
30
|
+
onReminderEvent: config.native.onReminderEvent,
|
|
31
|
+
idleStopWindowMs: idleMilliseconds(config.native.idleStopWindowMs, "idleStopWindowMs"),
|
|
32
|
+
...(config.native.defaultSender ? { defaultSender: config.native.defaultSender } : {}),
|
|
33
|
+
// A conversation that asked to load its provider session has history of its own.
|
|
34
|
+
resumed: config.sessionId !== undefined,
|
|
35
|
+
...(config.logger ? { logger: config.logger } : {}),
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return new HarnessController(config);
|
|
39
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Small guards over a `ConversationController`'s optional members, so the session never depends on
|
|
3
|
+
* the concrete `HarnessController` type (controller-interface spec, Capabilities: every optional
|
|
4
|
+
* member and its guard).
|
|
5
|
+
*/
|
|
6
|
+
import type { Capabilities } from "../capabilities.ts";
|
|
7
|
+
import { HarnessController } from "../controller.ts";
|
|
8
|
+
import { ProviderSessionReloadUnsupportedError, UnsupportedError } from "../errors.ts";
|
|
9
|
+
import type { ConnectResult } from "../client.ts";
|
|
10
|
+
import type { StaleLimits } from "../operations/contracts.ts";
|
|
11
|
+
import type { InternalSessionCommand, SessionListEntry } from "../types.ts";
|
|
12
|
+
import type { ConversationController } from "./contracts.ts";
|
|
13
|
+
|
|
14
|
+
/** Whether the controller talks to a screen-scraped (PTY) harness: only a controller with a mode can. */
|
|
15
|
+
export function isDegradedController(controller: ConversationController): boolean {
|
|
16
|
+
return controller.currentMode === "degraded";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The controller as a `HarnessController` (an external harness over ACP or a PTY), or null for any other backend. */
|
|
20
|
+
export function harnessControllerOf(controller: ConversationController): HarnessController | null {
|
|
21
|
+
return controller instanceof HarnessController ? controller : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type OptionalMember = "bridge" | "authenticate" | "setMode" | "reconnect" | "prepareInternalPrompt";
|
|
25
|
+
|
|
26
|
+
/** An optional method of the controller, bound to it; `UnsupportedError` (naming `what`) when the controller doesn't have it. */
|
|
27
|
+
export function requireMember<K extends OptionalMember>(
|
|
28
|
+
controller: ConversationController,
|
|
29
|
+
name: K,
|
|
30
|
+
what: string,
|
|
31
|
+
): NonNullable<ConversationController[K]> {
|
|
32
|
+
const member = controller[name];
|
|
33
|
+
if (typeof member !== "function") throw new UnsupportedError(`this conversation's controller does not support ${what}`);
|
|
34
|
+
return member.bind(controller) as NonNullable<ConversationController[K]>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const NO_COMMANDS: readonly InternalSessionCommand[] = Object.freeze([]);
|
|
38
|
+
|
|
39
|
+
/** The commands the backend advertises; none for a controller without them. */
|
|
40
|
+
export function availableCommandsOf(controller: ConversationController): readonly InternalSessionCommand[] {
|
|
41
|
+
return controller.availableCommands ?? NO_COMMANDS;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The agent's own session list, for a controller that is connected, not degraded, lists sessions and whose
|
|
46
|
+
* backend says it can. An unknown backend (not connected yet) is not an unsupported one: the ACP getter
|
|
47
|
+
* throws `NotConnectedError`, as it always did here. Otherwise empty.
|
|
48
|
+
*/
|
|
49
|
+
export async function listAgentSessions(controller: ConversationController): Promise<SessionListEntry[]> {
|
|
50
|
+
if (isDegradedController(controller)) return [];
|
|
51
|
+
const backend = controller.conversationCapabilities.backend;
|
|
52
|
+
if (!backend) void harnessControllerOf(controller)?.capabilities;
|
|
53
|
+
return backend?.listSessions && controller.listSessions ? (await controller.listSessions()).sessions : [];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The raw ACP capabilities, through the `HarnessController`; `UnsupportedError` for a backend that has none (use `conversationCapabilities`). */
|
|
57
|
+
export function acpCapabilitiesOf(controller: ConversationController): Capabilities {
|
|
58
|
+
const harness = harnessControllerOf(controller);
|
|
59
|
+
if (!harness) throw new UnsupportedError("this conversation's controller has no ACP capabilities; use conversationCapabilities");
|
|
60
|
+
return harness.capabilities;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Checked before anything is torn down for a fresh context: a backend that cannot start one
|
|
65
|
+
* (`conversationCapabilities.freshContext === false`) is refused here, with its state untouched.
|
|
66
|
+
*/
|
|
67
|
+
export function requireFreshContext(controller: ConversationController, what: string): void {
|
|
68
|
+
if (controller.conversationCapabilities.freshContext === false) {
|
|
69
|
+
throw new UnsupportedError(`this conversation's controller cannot start a fresh context, so it does not support ${what}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Reloads the provider session, for a controller that can. One that can't throws, so recovery takes over:
|
|
75
|
+
* it is handled as a session the provider no longer has, under the conversation's continuation rule.
|
|
76
|
+
*/
|
|
77
|
+
export function reloadProviderSession(controller: ConversationController, sessionId: string): Promise<ConnectResult> {
|
|
78
|
+
if (!controller.reconnect) throw new ProviderSessionReloadUnsupportedError();
|
|
79
|
+
return controller.reconnect(sessionId);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The stall limits a provider request runs under. A screen-scraped (PTY) harness can't report tools or permissions, so
|
|
84
|
+
* silence explains nothing: no limit by default (a configured one still applies). A turn that is replaying held output
|
|
85
|
+
* is handled by the supervisor itself (`isReplaying`), which reads `live` as time goes on.
|
|
86
|
+
*/
|
|
87
|
+
export function stallLimitsFor(controller: ConversationController, limits: StaleLimits | undefined): StaleLimits | undefined {
|
|
88
|
+
// A backend that supervises its own turns (the native harness) is never cancelled for silence,
|
|
89
|
+
// even with configured limits: a quiet host function is not a stalled provider.
|
|
90
|
+
if (controller.conversationCapabilities.supervision === "backend") return { firstOutputMs: false, nextOutputMs: false, toolMs: false };
|
|
91
|
+
return isDegradedController(controller) ? { firstOutputMs: false, nextOutputMs: false, ...limits } : limits;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Reopens only after the controller confirms its stop. */
|
|
95
|
+
export async function restartConversation(controller: Pick<ConversationController, "stop" | "start">) {
|
|
96
|
+
await controller.stop();
|
|
97
|
+
return controller.start();
|
|
98
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { conversationCapabilitiesFromAcp, conversationCapabilitiesOf, fromAcp, mediaCapabilitiesOf } from "./capabilities.ts";
|
|
2
|
+
export type { BackendCapabilities, ConversationCapabilities } from "./capabilities.ts";
|
|
3
|
+
export type {
|
|
4
|
+
ControllerStartEvent,
|
|
5
|
+
ConversationController,
|
|
6
|
+
PreparedTurn,
|
|
7
|
+
StartResult,
|
|
8
|
+
ItemRef,
|
|
9
|
+
ItemsReceipt,
|
|
10
|
+
TurnCause,
|
|
11
|
+
TurnContent,
|
|
12
|
+
TurnEvent,
|
|
13
|
+
TurnRun,
|
|
14
|
+
TurnStarted,
|
|
15
|
+
TurnTook,
|
|
16
|
+
UsageListener,
|
|
17
|
+
} from "./contracts.ts";
|
|
18
|
+
export { createController } from "./factory.ts";
|
|
19
|
+
export type { NativeControllerBinding } from "./factory.ts";
|
|
20
|
+
export { acpCapabilitiesOf, availableCommandsOf, harnessControllerOf, isDegradedController, stallLimitsFor, listAgentSessions, reloadProviderSession, restartConversation, requireFreshContext, requireMember } from "./guards.ts";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ConnectionCancelledError } from "./errors.ts";
|
|
2
|
+
import type { AgentConversationRuntimeDefaults, OpenAgentConversationConfig, ProviderStart } from "./agent/config.ts";
|
|
3
|
+
|
|
4
|
+
export function resolveProviderStart(value: ProviderStart | undefined): ProviderStart {
|
|
5
|
+
if (value === undefined) return "on_open";
|
|
6
|
+
if (value === "on_open" || value === "on_first_use") return value;
|
|
7
|
+
throw new TypeError("providerStart must be on_open or on_first_use");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function defersProvider(
|
|
11
|
+
config: Pick<OpenAgentConversationConfig, "runtime" | "mode">, defaults: AgentConversationRuntimeDefaults, native: boolean,
|
|
12
|
+
): boolean {
|
|
13
|
+
return (config.runtime?.providerStart ?? defaults.providerStart) === "on_first_use" && !native
|
|
14
|
+
&& (config.mode ?? config.runtime?.mode ?? defaults.mode) !== "degraded";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The factory can be cancelled before it hands its session back to the caller. */
|
|
18
|
+
export async function withStartupCancellation<T>(
|
|
19
|
+
signal: AbortSignal | undefined, stop: () => Promise<void>, start: () => Promise<T>,
|
|
20
|
+
): Promise<T> {
|
|
21
|
+
if (!signal) return start();
|
|
22
|
+
if (signal.aborted) throw new ConnectionCancelledError();
|
|
23
|
+
const cancel = () => { void stop().catch(() => undefined); };
|
|
24
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
25
|
+
try {
|
|
26
|
+
const result = await start();
|
|
27
|
+
if (signal.aborted) throw new ConnectionCancelledError();
|
|
28
|
+
return result;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (signal.aborted && !(error instanceof ConnectionCancelledError)) throw new ConnectionCancelledError();
|
|
31
|
+
throw error;
|
|
32
|
+
} finally {
|
|
33
|
+
signal.removeEventListener("abort", cancel);
|
|
34
|
+
}
|
|
35
|
+
}
|