@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,73 @@
|
|
|
1
|
+
# Channel controls contract (storage revision 3)
|
|
2
|
+
|
|
3
|
+
## Problem and options
|
|
4
|
+
|
|
5
|
+
A session suspends as a whole (0013). Consumers also need to suspend, resume,
|
|
6
|
+
create, rename and delete one channel, withdraw an untaken input, and interrupt
|
|
7
|
+
one turn, while other channels run. Options for individual suspension: (a) reuse
|
|
8
|
+
the session lifecycle per channel and key checkpoints to an owner marker;
|
|
9
|
+
(b) a channel lifecycle that composes with the session lifecycle and decides
|
|
10
|
+
checkpoint survival from the two states. Chosen: (b), no owner marker.
|
|
11
|
+
|
|
12
|
+
## Choice
|
|
13
|
+
|
|
14
|
+
- **Channel lifecycle** (`StoredChannel.lifecycle`): `open | suspending | suspended
|
|
15
|
+
| retired`, independent of session lifecycle and turn status. `suspending`
|
|
16
|
+
always has a running turn. Effective **admission** needs session `running` and
|
|
17
|
+
channel `open` (notices also while the session is `suspending`). Effective
|
|
18
|
+
**execution** (take, begin, resume of a turn) needs session `running` and
|
|
19
|
+
channel `open`. Session check comes first, so a send during both is `not_running`.
|
|
20
|
+
- **Checkpoint survival** needs no new field: a checkpointed turn is kept across
|
|
21
|
+
reopen and `interruptActive` iff the session is `suspended` or its channel is
|
|
22
|
+
`suspended`. A turn is resumed by `resume()` iff its channel is not `suspended`,
|
|
23
|
+
and by `resumeChannel` iff the session is `running`.
|
|
24
|
+
- **Atomic completion.** The transaction that checkpoints, completes, fails or
|
|
25
|
+
interrupts the running turn of a `suspending` channel also makes it `suspended`.
|
|
26
|
+
There is no separate "complete" call and no window between the two.
|
|
27
|
+
- **New operations** on `SessionStorage` (each one transaction, allowed in every
|
|
28
|
+
session lifecycle): `createChannel`, `editChannel`, `beginChannelSuspend`,
|
|
29
|
+
`resumeChannel`, `deleteChannel`, `withdrawItem`, `interruptTurn`. Session API:
|
|
30
|
+
`PersistentSession.channels` (`create/edit/suspend/resume/delete/withdraw/
|
|
31
|
+
interrupt`). Wire: `channel/{create,edit,suspend,resume,delete,withdraw,interrupt}`.
|
|
32
|
+
- **Errors.** New `channel_suspended` (send, notice, take, begin on a suspending or
|
|
33
|
+
suspended channel), `channel_retired`, `channel_busy` (delete). Create of an
|
|
34
|
+
existing channel with a different name is `already_exists`; the same request
|
|
35
|
+
returns `created: false`. Retry of an accepted input never gets
|
|
36
|
+
`channel_suspended`; it returns the recorded outcome.
|
|
37
|
+
- **Withdraw.** Pending `received` becomes terminal `withdrawn` (new
|
|
38
|
+
`ItemMilestone`): not pending, no turn, no timeline entry, kept for dedup, so a
|
|
39
|
+
retry with the same ID and payload returns it withdrawn. If take committed first
|
|
40
|
+
the result is `taken` with the turn ID and nothing changes. Messages and notices
|
|
41
|
+
alike (a pending notice would otherwise block delete).
|
|
42
|
+
- **Interrupt** names `(channelId, turnId)`. Only `running` is interrupted; a
|
|
43
|
+
checkpointed or ended turn returns `interrupted: false` and is untouched, so a
|
|
44
|
+
stale ID cannot reach a newer turn. A `suspending` channel is `suspended` in the
|
|
45
|
+
same transaction without a checkpoint. `interruptActive` (stop, crash recovery)
|
|
46
|
+
keeps an individually `suspended` channel and its checkpoint and returns a
|
|
47
|
+
`suspending` channel to `open`.
|
|
48
|
+
- **Delete** retires the ID (`retired` is final, record and timeline kept) only
|
|
49
|
+
with no running or checkpointed turn and no pending item; otherwise `channel_busy`.
|
|
50
|
+
A retired ID rejects send, notice, create. First send to an unknown ID still
|
|
51
|
+
creates the channel. Idle explicit create and edit never start work.
|
|
52
|
+
- **Status.** `ChannelStatus` adds `lifecycle`, `displayName`, `waitingForResume`.
|
|
53
|
+
Pending work on a suspended channel is `waitingForResume` and does not make
|
|
54
|
+
`execution` `working`.
|
|
55
|
+
- **Export/import.** Running-session export also requires no checkpointed turn
|
|
56
|
+
and no `suspending` channel. Import rejects `suspending` channels, a running or
|
|
57
|
+
checkpointed turn on a retired channel, and other states `open` would interrupt;
|
|
58
|
+
`resume()` and `resumeChannel` never run a retired channel's turn. Interrupt
|
|
59
|
+
without a reason stores `"interrupted by request"`.
|
|
60
|
+
|
|
61
|
+
## Compatibility and verification
|
|
62
|
+
|
|
63
|
+
Revision 3 is format 3 and archive version 2. `open` accepts format 2 and
|
|
64
|
+
upgrades it in the recovery transaction: every channel `open`, unnamed, no
|
|
65
|
+
withdrawn items, no retired IDs; existing session-wide suspensions and
|
|
66
|
+
checkpoints keep their behavior because no channel is `suspended`. Format 3 is
|
|
67
|
+
not readable by the earlier revision. `importArchive` accepts archive versions 1
|
|
68
|
+
and 2 (`SessionArchiveV1` is import-only); export writes 2. Wire additions are
|
|
69
|
+
optional or new: old clients ignore `lifecycle`/`waitingForResume` and unknown
|
|
70
|
+
milestone `withdrawn` appears only for items they cannot have withdrawn.
|
|
71
|
+
Verification: conformance tests on memory and SQLite adapters, SQLite reopen,
|
|
72
|
+
interrupted suspend, persistence-revision fixtures, archive round trip, then
|
|
73
|
+
scheduler and end-to-end barriers per the SPEC.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Session file and imported configuration
|
|
2
|
+
|
|
3
|
+
## Problem and options
|
|
4
|
+
|
|
5
|
+
The JSON export omits the active configuration. A portable file must retain it
|
|
6
|
+
and publish it atomically with the snapshot. Options are a JSON wrapper, a ZIP
|
|
7
|
+
container, or a versioned binary envelope with CBOR. Choose the envelope in
|
|
8
|
+
amendment 0002. It has no ZIP, encryption, embedded credentials, or embedded
|
|
9
|
+
destination resources. Managed reopen remains the configuration slice's work.
|
|
10
|
+
|
|
11
|
+
## Choice
|
|
12
|
+
|
|
13
|
+
- File version 1 is `HARNSESS` (eight ASCII bytes), uint16 version 1, uint32
|
|
14
|
+
payload length, both big-endian, followed by exactly one CBOR item. The
|
|
15
|
+
Validation order: a file shorter than the 14-byte header, a wrong marker,
|
|
16
|
+
or an unknown version is `invalid_archive`. Next compare bytes actually
|
|
17
|
+
present to exactly 14 plus the declared payload length; any mismatch is
|
|
18
|
+
`invalid_archive`, including a short file declaring a huge length and any
|
|
19
|
+
trailing bytes. Never allocate or read based on the declared length. Only
|
|
20
|
+
after lengths match, reject files over `maxBytes` (268435456 bytes by
|
|
21
|
+
default), header included, as `transfer_limit`. Only then decode one CBOR
|
|
22
|
+
item and validate the logical records. Malformed CBOR or records and old
|
|
23
|
+
standalone JSON files are `invalid_archive`. Path and stdio use the same
|
|
24
|
+
order and whole-file limit.
|
|
25
|
+
- The payload is a map with exactly `archive` (logical archive version 2) and
|
|
26
|
+
`config` (the active portable config). Logical archive version 1 remains an
|
|
27
|
+
adapter-level import compatibility feature, not a legacy session-file format.
|
|
28
|
+
Validate the entire payload before publishing either record.
|
|
29
|
+
- CBOR supports JSON data only: null, booleans, finite IEEE-754 numbers, UTF-8
|
|
30
|
+
text, arrays, and maps with unique string keys. Reject tags, byte strings,
|
|
31
|
+
undefined, non-finite numbers, duplicate keys, indefinite lengths, invalid
|
|
32
|
+
UTF-8, non-string keys, unsafe integers, extra CBOR items, and nesting beyond
|
|
33
|
+
128 containers. Encoder emits definite lengths and interoperable standard
|
|
34
|
+
CBOR; canonical map ordering is not required. Decode a bounded file in memory.
|
|
35
|
+
Implement the small profile in the storage module, with independent byte-vector
|
|
36
|
+
tests; no runtime package or native codec dependency is required. A stored
|
|
37
|
+
snapshot outside this profile fails export with `serialization_error`; a
|
|
38
|
+
file outside it fails import with `invalid_archive`.
|
|
39
|
+
- The active config is the exact validated `ProtocolConfig` value captured
|
|
40
|
+
when the source session is opened: `{ version: 1, system, model: { protocol:
|
|
41
|
+
"scripted", script } }`. No subsequent sidecar or script read can change the
|
|
42
|
+
exported value. Unknown config fields, invalid types and empty script paths
|
|
43
|
+
fail validation, including empty or whitespace-only script paths. Paths are retained verbatim, not rewritten or dereferenced by
|
|
44
|
+
export or import. The destination must supply the referenced scripted model
|
|
45
|
+
file at that path (relative paths resolve in the destination process working
|
|
46
|
+
directory) with compatible content before opening/resuming; its contents are
|
|
47
|
+
not carried by the file. The existing compatibility key prevents resuming a
|
|
48
|
+
checkpoint with different script content or system prompt. Import validates
|
|
49
|
+
config structure without requiring the resource to exist. Other future config
|
|
50
|
+
schemas, credential references and host functions require a separate decision;
|
|
51
|
+
credential values and host functions are destination-owned and never exported.
|
|
52
|
+
- Add a storage adapter operation to import the validated logical archive and
|
|
53
|
+
portable config as one atomic publication, and a storage read for the imported
|
|
54
|
+
config. Reads return defensive copies. Existing logical archive operations
|
|
55
|
+
remain for adapter compatibility. A fresh imported SQLite session keeps the
|
|
56
|
+
config in its database; memory storage keeps it with its session. Failed
|
|
57
|
+
validation, occupied destinations, or failed publication leave no partial
|
|
58
|
+
destination and never modify an existing one. Legacy sessions have no saved
|
|
59
|
+
imported config: a read succeeds with an absent value. This slice does not automatically load the saved config for
|
|
60
|
+
session open; callers still supply config until the configuration integration.
|
|
61
|
+
- Export eligibility and channel/session lifecycle rules remain those of 0014.
|
|
62
|
+
Path and chunked transfer use the same codec and hash the complete file bytes.
|
|
63
|
+
|
|
64
|
+
## Compatibility and verification
|
|
65
|
+
|
|
66
|
+
SQLite `formatVersion` stays 3. Format 2 upgrades once as before and format 3
|
|
67
|
+
continues to open; saved config is extra storage beside the logical snapshot,
|
|
68
|
+
not a new schema revision. The external JSON archive encoding is intentionally no
|
|
69
|
+
longer accepted. Verify the CBOR profile against fixed independent vectors,
|
|
70
|
+
malformed inputs and the whole-file bound, plus atomicity on both adapters,
|
|
71
|
+
fresh-home public path and chunked stdio round trips, active config after source
|
|
72
|
+
file removal, destination script requirements, and suspended channel checkpoints.
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# Configuration, policy and approval contract
|
|
2
|
+
|
|
3
|
+
## Problem and options
|
|
4
|
+
|
|
5
|
+
Tool instructions cannot enforce permissions, and pending inputs and notices
|
|
6
|
+
must retain the restrictions under which they were admitted. Choose durable
|
|
7
|
+
policy references and a synchronous dispatch gate. The older protocol proposes
|
|
8
|
+
harness-to-host permission callbacks; this increment instead uses an always-on
|
|
9
|
+
approval event plus an answer request keyed by request ID. It fits the existing
|
|
10
|
+
one-way notification and host request transports; it is an experimental subset,
|
|
11
|
+
not the older callback's wire shape. Disconnect explicitly closes this owner's
|
|
12
|
+
outstanding requests. No model-supplied text or tool argument grants rights.
|
|
13
|
+
|
|
14
|
+
## Configuration and persistence
|
|
15
|
+
|
|
16
|
+
- Version 1 config is `{version:1, system:string, model:{protocol:"scripted",
|
|
17
|
+
script:string}, defaultPolicy:string, policies:Record<string,{fallback:
|
|
18
|
+
"allow"|"ask"|"deny", tools:Record<string,"allow"|"ask"|"deny">}>}`.
|
|
19
|
+
Names and script path are nonempty after trimming, names and exact tool keys
|
|
20
|
+
are retained verbatim, duplicate/unknown fields and unknown policy references
|
|
21
|
+
are validation errors naming the field. `tools` may be empty. `system` may be
|
|
22
|
+
empty. No secret values or functions are stored. The scripted path is a
|
|
23
|
+
destination resource under decision 0015; credentials in later providers are
|
|
24
|
+
environment references, resolved at runtime, never copied as values.
|
|
25
|
+
- `config/validate` accepts `{config}` and returns `{valid:true}` or a typed
|
|
26
|
+
`invalid_config` error with field and message, without opening a session or
|
|
27
|
+
starting inference. The typed client exposes it. On create an inline config
|
|
28
|
+
wins when supplied; otherwise the per-session `config.json` is required.
|
|
29
|
+
On open a present sidecar wins; otherwise an explicitly supplied inline config
|
|
30
|
+
is used, and otherwise the saved config is required. Both `session/load` and
|
|
31
|
+
development open use saved config when neither inline config nor sidecar is
|
|
32
|
+
supplied, for managed directories and explicit `--db` files. The
|
|
33
|
+
open session owns a defensive copy, saved atomically with successful open;
|
|
34
|
+
invalid sidecar, missing resource, incompatible stored references, or failed
|
|
35
|
+
open leaves the previous saved config and session unchanged. Edits are read only
|
|
36
|
+
at the next open. `session/load` needs no inline config for managed sessions.
|
|
37
|
+
Managed path is `<home>/<sessionId>/{config.json,session.sqlite}`; IDs cannot
|
|
38
|
+
escape the home. Default home is `~/.harness`, `--home` overrides it. The
|
|
39
|
+
old flat managed path is not migrated; explicit development `--db` remains.
|
|
40
|
+
- Save active config with a created or opened session, and export the in-memory
|
|
41
|
+
copy in the session-file payload. Import publishes config and snapshot as one
|
|
42
|
+
unit; imported sessions open from it without a sidecar. SQLite and memory
|
|
43
|
+
share the same rules. SQLite formatVersion 4 and logical archive revision 3
|
|
44
|
+
add policy fields. Opening format 2 or 3 first applies its existing recovery
|
|
45
|
+
rules, then publishes format 4. Adapter-level import still accepts logical
|
|
46
|
+
archive 1. A session-file envelope still rejects archive 1; archive 2 and
|
|
47
|
+
the scripted config without policy fields from `7e49bd5` migrate to archive
|
|
48
|
+
3 and the legacy policy. The envelope stays version 1; new exports contain
|
|
49
|
+
archive 3 and full ManagedConfig. Standalone JSON remains `invalid_archive`.
|
|
50
|
+
- Name the legacy policy `__legacy_allow`. An upgraded config sets
|
|
51
|
+
`defaultPolicy` to that name and defines it with fallback `allow` and empty
|
|
52
|
+
`tools`. Migrated channels have no channel policy; migrated items have no
|
|
53
|
+
explicit policy, resolved `__legacy_allow`, and inherited `[]`. Accept the
|
|
54
|
+
pre-0016 signature `JSON.stringify([kind, channelId, senderId,
|
|
55
|
+
sourceChannelId ?? null, text])` during migration, then rewrite it to
|
|
56
|
+
`JSON.stringify([kind, channelId, senderId, sourceChannelId ?? null, text,
|
|
57
|
+
explicitPolicy ?? null])` under the existing SHA-256 encoding. New acceptance
|
|
58
|
+
and archive 3 use only the extended signature. Omitted and null explicit
|
|
59
|
+
policy are the same absence, so an unchanged retry still matches.
|
|
60
|
+
- On reopen validate every stored channel, item and inherited policy reference
|
|
61
|
+
against the candidate config before enabling execution. Missing references
|
|
62
|
+
produce an `incompatible` execution state without changing saved config or
|
|
63
|
+
starting work; status, timeline and checkpoint reads still succeed. While
|
|
64
|
+
incompatible, `acceptItem`, `beginTurn`, `resume`, and `resumeChannel` report
|
|
65
|
+
`incompatible` and write nothing. Pending inputs and checkpoints remain
|
|
66
|
+
untouched. The config may change rules for future turns. A checkpoint's
|
|
67
|
+
fingerprint is the existing compatibility key (SHA-256 of
|
|
68
|
+
`JSON.stringify([system, parsedScriptContent])`) plus definitions of its
|
|
69
|
+
contributing policy names, canonically compared by sorted policy names and
|
|
70
|
+
sorted tool keys within each policy. A changed contributing definition makes
|
|
71
|
+
resume `incompatible` with no writes; unrelated policy changes do not block it.
|
|
72
|
+
Compare only when that checkpoint would actually continue: session resume
|
|
73
|
+
checks the channels it restarts; channel resume checks when the session is
|
|
74
|
+
running. An individually suspended incompatible channel does not block session
|
|
75
|
+
resume or change its checkpoint. Migration records the existing turn key and
|
|
76
|
+
legacy allow definition, so an unchanged upgraded session can resume.
|
|
77
|
+
|
|
78
|
+
## Policy and identity
|
|
79
|
+
|
|
80
|
+
- Channel create with an omitted policy stores no channel policy. On edit,
|
|
81
|
+
omitted leaves it unchanged, null clears it, and a string sets it. An unknown
|
|
82
|
+
name is `invalid_policy`, with no change. Participant input accepts
|
|
83
|
+
an optional trusted-consumer `policy`, never one derived from its text.
|
|
84
|
+
Resolve explicit, then channel, then session default when accepting. Store
|
|
85
|
+
`explicit` including absence and the resolved name. Dedup identity extends the
|
|
86
|
+
existing signature with explicit policy or null: identical retry is answered
|
|
87
|
+
before current policy validation, retains the original resolution even after
|
|
88
|
+
edit, and a different explicit policy is `item_conflict`, even if equivalent.
|
|
89
|
+
- A notice is emitted with the actual source turn identity from the executor,
|
|
90
|
+
not a model-provided policy or caller-supplied claim. In its acceptance
|
|
91
|
+
transaction store the deduplicated union of all source turn taken items'
|
|
92
|
+
resolved and inherited policy references, as well as the target policy
|
|
93
|
+
resolved at acceptance. Inherited references propagate transitively to later
|
|
94
|
+
notices. Reopen/export/import preserve them. A notice cannot grant rights the
|
|
95
|
+
source lacked under the current open config. A waiting item contributes
|
|
96
|
+
nothing until take; each taken item's resolved and inherited names contribute
|
|
97
|
+
for the remainder of that turn, including subsequent notices. Tool-specific
|
|
98
|
+
decisions combine as `deny > ask > allow`; exact override precedes fallback.
|
|
99
|
+
Already-dispatched tools are unaffected; a fresh turn starts with its own
|
|
100
|
+
taken inputs. Shared-history read access is unchanged.
|
|
101
|
+
|
|
102
|
+
## Approval and lifecycle ordering
|
|
103
|
+
|
|
104
|
+
- The gate evaluates immediately before each tool dispatch against the current
|
|
105
|
+
taken-item policies. `deny` produces one paired tool result with code
|
|
106
|
+
`policy_denied`, no dispatch and no `tool_call:started`. `allow` dispatches
|
|
107
|
+
once. `ask` publishes an always-on `approval_requested` event containing
|
|
108
|
+
`{requestId, channel, turnId, toolCallId, tool, arguments}`; IDs identify
|
|
109
|
+
exact calls, including argument text, and are never reused during the server
|
|
110
|
+
lifetime. One `approval/respond` request `{requestId, decision:"allow_once"|
|
|
111
|
+
"deny"}` returns `{accepted:true}` only for the first live answer. Unknown,
|
|
112
|
+
late or duplicate IDs return `not_found` and cannot dispatch. The client
|
|
113
|
+
declares approval handling at initialize; no handler produces a paired
|
|
114
|
+
`approval_unhandled` result without waiting. A disconnect closes its requests
|
|
115
|
+
with `approval_disconnected`; timeout defaults to 10 minutes and closes with
|
|
116
|
+
`approval_timeout`. Explicit deny produces `approval_denied`. These results
|
|
117
|
+
include `{ok:false,code,message}`, explain no execution, and are recorded as
|
|
118
|
+
the matching tool result before the loop continues. No skipped call emits
|
|
119
|
+
`started`. Initialize keeps `callbacks` an empty array, rejecting any
|
|
120
|
+
nonempty list, and adds optional `approval:boolean`: only `true` declares
|
|
121
|
+
the connection to be the approval consumer. Without it an ask immediately
|
|
122
|
+
closes as `approval_unhandled`; with it, disconnect closes its outstanding
|
|
123
|
+
requests as `approval_disconnected`. An unanswered approval is never durable
|
|
124
|
+
or executable on restart.
|
|
125
|
+
- Decision, lifecycle cancellation and dispatch are serialized without an await
|
|
126
|
+
between the final cancellation check, grant consumption, `started` emission
|
|
127
|
+
and invoking the executor. The linearization point is that dispatch step.
|
|
128
|
+
A grant answers the request but is unused until that step; it is consumed once.
|
|
129
|
+
If channel or session suspension wins first, close a pending request or discard
|
|
130
|
+
the grant and record `approval_cancelled_by_suspension`, with no started event
|
|
131
|
+
or effect. Any later ask in that finishing iteration gets the same paired
|
|
132
|
+
result without opening a request. If dispatch wins first, the started event
|
|
133
|
+
appears once and the running tool finishes under existing suspension rules.
|
|
134
|
+
Suspension waits for the iteration, then completes or checkpoints normally.
|
|
135
|
+
A later retry after resume is a new call and new request. A second channel
|
|
136
|
+
continues while one turn awaits approval.
|
|
137
|
+
- Interrupt and stop cancel requests for their affected turns, fence grants and
|
|
138
|
+
late answers, abort running tools and fence late results under decision 0014.
|
|
139
|
+
An undispatched request is not added to `uncertainCallIds`: its tool did not
|
|
140
|
+
run. A call that already emitted `started` retains decision 0014's uncertain
|
|
141
|
+
effect semantics. No paired result is written after a turn has ended. Denial, timeout and disconnect
|
|
142
|
+
cannot cause a dispatch. No request or grant survives a restart.
|
|
143
|
+
|
|
144
|
+
## Traces and verification
|
|
145
|
+
|
|
146
|
+
1. Accept ID `x` with no explicit policy under channel `A`; edit channel to
|
|
147
|
+
`B`; retry identical `x` returns its original receipt and `A`. Retry with
|
|
148
|
+
explicit `A` conflicts because absence and explicit override differ.
|
|
149
|
+
2. Source turn has taken `strict`, including `inherited`; its notice stores
|
|
150
|
+
those names plus the target's resolved policy. Restart, take the notice,
|
|
151
|
+
and evaluate the union for each tool; `deny` wins even if target allows.
|
|
152
|
+
3. Ask resolves allow-once. If suspend commits before dispatch, discard grant,
|
|
153
|
+
record cancellation result and checkpoint; no started/effect. If dispatch
|
|
154
|
+
commits first, emit started once, finish the tool and checkpoint. Late or
|
|
155
|
+
repeated answer cannot start another call.
|
|
156
|
+
|
|
157
|
+
Run validation and typecheck at this contract gate, then the stage-specific
|
|
158
|
+
storage, scheduler, transport and end-to-end gates in the plan. Review each
|
|
159
|
+
named revision independently before starting its dependent stage.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Managed OpenRouter configuration
|
|
2
|
+
|
|
3
|
+
## Problem and options
|
|
4
|
+
|
|
5
|
+
Decision 0016 restricted managed configuration to scripted models, but the
|
|
6
|
+
existing explicit development `--db` flow also runs OpenRouter. The user chose
|
|
7
|
+
to preserve that flow and make it portable without saving credential values.
|
|
8
|
+
Options are to exclude it, embed credentials, or save provider and model data
|
|
9
|
+
with a reference to a destination environment variable. Choose the reference;
|
|
10
|
+
this amends decision 0016 without adding a configured tool adapter.
|
|
11
|
+
|
|
12
|
+
## Choice
|
|
13
|
+
|
|
14
|
+
- `ManagedConfig.model` is a tagged union: the existing
|
|
15
|
+
`{protocol:"scripted",script:string}` or
|
|
16
|
+
`{protocol:"openrouter",model:string,apiKeyEnv:string}`. OpenRouter's model
|
|
17
|
+
is a nonempty model identifier retained verbatim. `apiKeyEnv` names a
|
|
18
|
+
destination environment variable matching `[A-Za-z_][A-Za-z0-9_]*`; the name
|
|
19
|
+
is portable, its nonempty value is a runtime secret. Unknown fields and raw
|
|
20
|
+
credential values fail validation. Do not include credential values in the
|
|
21
|
+
saved config, SQLite session, session file, events, errors or logs.
|
|
22
|
+
The default model is `deepseek/deepseek-v4.1-flash`, and the default reference
|
|
23
|
+
is `OPENROUTER_API_KEY`. Ports and socket paths remain process settings.
|
|
24
|
+
- `config/validate` and session-file import validate the reference without
|
|
25
|
+
requiring its value. The execution host resolves it from its own environment
|
|
26
|
+
at open, before enabling execution; a missing or empty value produces an
|
|
27
|
+
actionable `invalid_config` error naming the variable, without replacing the
|
|
28
|
+
saved config. Import does not require the credential; managed execution and
|
|
29
|
+
reopen need the destination to provide it. The endpoint remains the existing
|
|
30
|
+
OpenRouter adapter endpoint.
|
|
31
|
+
- OpenRouter compatibility remains exactly the existing development key:
|
|
32
|
+
SHA-256 of `JSON.stringify([systemPrompt,modelId,scenarioToolNames])`, plus
|
|
33
|
+
decision 0016's canonical contributing policy definitions. Neither the key
|
|
34
|
+
value nor its environment-variable name enters either fingerprint. A change
|
|
35
|
+
to a credential reference alone does not block a checkpoint; a model or
|
|
36
|
+
system change does. An unchanged pre-managed OpenRouter checkpoint resumes
|
|
37
|
+
with the same key and needs no legacy marker. Scripted compatibility remains
|
|
38
|
+
SHA-256 of `JSON.stringify([system,parsedScriptContent])`.
|
|
39
|
+
- Preserve existing `openDevelopment` provider options and the CLI's
|
|
40
|
+
`OPENROUTER_MODEL` and `OPENROUTER_API_KEY` behavior. A newly created managed
|
|
41
|
+
OpenRouter database saves the selected model and an environment-variable
|
|
42
|
+
reference (default `OPENROUTER_API_KEY`), never the key. An existing
|
|
43
|
+
pre-managed provider database with no saved config may still open using its
|
|
44
|
+
explicit runtime provider settings. When managed config is available, the
|
|
45
|
+
sidecar/open precedence of 0016 applies, and saved config supplies provider
|
|
46
|
+
and model on a later open without a sidecar or inline config. Caller-supplied
|
|
47
|
+
legacy `provider.apiKey` remains usable for that current development open;
|
|
48
|
+
it is never saved and a later saved-config reopen requires the named env var.
|
|
49
|
+
- At open, sidecar wins over inline config, then saved config is used. The
|
|
50
|
+
`OPENROUTER_MODEL` environment value supplies the model only if no saved model
|
|
51
|
+
exists, including a format 2/3 development database. It never overrides a
|
|
52
|
+
saved model. The referenced credential variable, defaulting to
|
|
53
|
+
`OPENROUTER_API_KEY`, is resolved at every OpenRouter open. A missing key
|
|
54
|
+
fails before inference and leaves an existing database unchanged. `--script`
|
|
55
|
+
continues to require no key. No tool or approval is replayed by migration.
|
|
56
|
+
|
|
57
|
+
## Compatibility and verification
|
|
58
|
+
|
|
59
|
+
The existing scripted session file and SQLite migration behavior is unchanged.
|
|
60
|
+
The session-file envelope remains version 1; the saved config carries the
|
|
61
|
+
OpenRouter tag and reference as data. A fresh destination must supply the named
|
|
62
|
+
credential; import does not need it. Verify create/export/import/reopen with no
|
|
63
|
+
sidecar and a fake or injected provider, assert the selected model and secret
|
|
64
|
+
are used only at dispatch, and assert the secret is absent from persisted bytes,
|
|
65
|
+
wire data and logs. Exercise missing environment, sidecar precedence, model
|
|
66
|
+
changes, reference changes that preserve compatibility, legacy checkpoint resume,
|
|
67
|
+
and unrelated policy changes. Scripted saved-config reopen remains an offline
|
|
68
|
+
acceptance gate and never needs a provider key.
|
|
69
|
+
No live provider keys or network are used in automated tests.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# Durable evidence at the approval dispatch boundary
|
|
2
|
+
|
|
3
|
+
## Problem and choice
|
|
4
|
+
|
|
5
|
+
Decision 0016 requires interruption or a crash while approval is pending to
|
|
6
|
+
report no uncertain effect, while a dispatched call with no result remains
|
|
7
|
+
uncertain. An assistant's durable call record alone cannot distinguish these
|
|
8
|
+
states. Alternatives are volatile tracking (lost on crash), recording a skipped
|
|
9
|
+
result after interruption (violates the turn fence), or durable dispatch evidence.
|
|
10
|
+
Choose evidence in the existing turn state, without a schema-format bump.
|
|
11
|
+
|
|
12
|
+
Every append of an assistant message with calls to a running turn ensures
|
|
13
|
+
`dispatchedCallIds` exists in that same transaction. If absent, set it to `[]`;
|
|
14
|
+
do not add the new calls. This includes the next such append on a resumed legacy
|
|
15
|
+
checkpoint: absence is conservative only until that write. `markToolDispatched`
|
|
16
|
+
succeeds only when the turn is running, the call belongs to that turn, no tool
|
|
17
|
+
result exists for it, and its ID is not already listed. Every other mark,
|
|
18
|
+
including a duplicate, fails and writes nothing; failure neither invokes the tool
|
|
19
|
+
nor emits `started`. The marker is evidence, not a grant.
|
|
20
|
+
|
|
21
|
+
Any `beforeToolDispatch` barrier resolves before the final cancellation check.
|
|
22
|
+
After it resolves, the gate reads both interrupt and suspension signals again.
|
|
23
|
+
The no-await span starts at that check: commit evidence, invoke the executor
|
|
24
|
+
synchronously, and publish `tool_call:started` before awaiting the returned
|
|
25
|
+
promise. Invoking before event publication prevents a reentrant event listener
|
|
26
|
+
from interrupting between the started event and the invocation. A crash after
|
|
27
|
+
evidence commits but before invocation can conservatively report an uncertain
|
|
28
|
+
effect; it never causes an automatic replay.
|
|
29
|
+
|
|
30
|
+
Carry dispatch IDs through checkpoint/resume. If the list is present,
|
|
31
|
+
`uncertainCallIds` is the unanswered call IDs in that list; if absent, every
|
|
32
|
+
unanswered call is uncertain. Crash recovery neither appends a tool result nor
|
|
33
|
+
replays a call. Live interrupt, stop, suspension, deny, timeout, disconnect, and
|
|
34
|
+
missing consumer write the one paired result for a closed, undispatched approval
|
|
35
|
+
while its turn is still running, before the turn ends. Interrupt and stop close
|
|
36
|
+
the request and commit that result before committing the turn's terminal state;
|
|
37
|
+
after that state no result is appended. Dispatched calls without results retain
|
|
38
|
+
the existing uncertain-effect rule.
|
|
39
|
+
|
|
40
|
+
The paired result for an undispatched approval closed by a single-turn interrupt
|
|
41
|
+
uses `approval_cancelled_by_interrupt`; session stop uses
|
|
42
|
+
`approval_cancelled_by_stop`. These are distinct from
|
|
43
|
+
`approval_cancelled_by_suspension` and are not the turn's interrupt reason.
|
|
44
|
+
Already-dispatched calls receive neither code and keep the uncertain-effect rule.
|
|
45
|
+
|
|
46
|
+
Import accepts an absent list. A present list must consist of unique nonempty
|
|
47
|
+
strings, each naming a call belonging to the same turn; otherwise import writes
|
|
48
|
+
nothing. A suspended turn still cannot contain an unanswered call. The marker is
|
|
49
|
+
internal evidence, not an approval record. SQLite `formatVersion` stays 4,
|
|
50
|
+
logical archive version stays 3 and session-file envelope version stays 1.
|
|
51
|
+
|
|
52
|
+
The scheduler exposes a per-turn suspension signal that aborts for session
|
|
53
|
+
suspension or this turn's own channel suspension only. It is distinct from the
|
|
54
|
+
interrupt signal and is never passed to `ExecuteTool`. Once marking succeeds,
|
|
55
|
+
suspension does not abort that call; interrupt still does. Any later ask in the
|
|
56
|
+
finishing iteration gets `approval_cancelled_by_suspension` without opening a
|
|
57
|
+
request. The gate consumes approval only at dispatch; its last check observes
|
|
58
|
+
both signals. The loop receives a gated result and never directly invokes a tool.
|
|
59
|
+
`approval_requested` is an always-on channel event; `approval/respond` answers
|
|
60
|
+
once. A connection disconnect closes its requests.
|
|
61
|
+
|
|
62
|
+
Storage's `ownerConfig()` returns the validated config supplied to this open,
|
|
63
|
+
copied at bind time, or `undefined` for a legacy allow-only open. It is not
|
|
64
|
+
`readSavedConfig()` or `importedConfig()`; `saveConfig()` does not retarget it,
|
|
65
|
+
and later mutation of the caller's object cannot change it. Legacy absence is
|
|
66
|
+
not the internal placeholder with an empty system and script `"legacy"`.
|
|
67
|
+
|
|
68
|
+
Session assembly takes its gate policy from that owner snapshot. Omitting the
|
|
69
|
+
session config uses the snapshot; legacy allow applies only if `ownerConfig()`
|
|
70
|
+
succeeds with an absent value. A supplied config is accepted only if it deeply
|
|
71
|
+
matches the snapshot, ignoring object key order. If the snapshot exists,
|
|
72
|
+
`systemPrompt` must equal its `system`; when absent, `systemPrompt` is the
|
|
73
|
+
legacy model prompt and is not compared. A failed `ownerConfig()` fails assembly
|
|
74
|
+
before the session starts: failure is not absence and the caller's config is not
|
|
75
|
+
a substitute. When assembly creates storage it passes that same selected config
|
|
76
|
+
into open, omitting it only for a legacy allow-only session. This prevents input
|
|
77
|
+
resolution under one set of policies and dispatch under a looser set. No config
|
|
78
|
+
comes from model text or mutable caller-owned objects after assembly.
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# 0019: Model calls, evidence, and live replies
|
|
2
|
+
|
|
3
|
+
## Problem
|
|
4
|
+
|
|
5
|
+
Complete-response inference cannot bound attempts, expose streaming without
|
|
6
|
+
retrying visible text, or recover call cost and response identity after a crash.
|
|
7
|
+
The existing tool permission and storage fences must remain authoritative.
|
|
8
|
+
|
|
9
|
+
## Options
|
|
10
|
+
|
|
11
|
+
Put retries and streams in the kernel, provider adapters, or a neutral call
|
|
12
|
+
runner; persist only final text or persist attempt evidence; block execution on
|
|
13
|
+
consumer writes or bound each connection's queue.
|
|
14
|
+
|
|
15
|
+
## Choice
|
|
16
|
+
|
|
17
|
+
Use the neutral contracts in `contracts/model-execution.ts` and a call runner
|
|
18
|
+
outside the kernel. One logical call freezes the request and reserves a stable
|
|
19
|
+
call ID and assistant message ID. Attempts have distinct IDs and ordinal order.
|
|
20
|
+
An adapter runs one attempt, emits ordered neutral signals and at most one
|
|
21
|
+
terminal, assembles provider tool fragments privately, and honors abort. EOF
|
|
22
|
+
without terminal is incomplete; malformed or duplicate tool IDs, malformed JSON
|
|
23
|
+
arguments, invalid response/stop combinations, or tool fragments without a
|
|
24
|
+
valid terminal never dispatch. Provider state remains opaque and unchanged.
|
|
25
|
+
A complete response validates as one assistant message; `complete` has no tool
|
|
26
|
+
calls, `tool_calls` has at least one, and `output_limit` is terminal without
|
|
27
|
+
committing that response or dispatching any of its tools. Non-streaming adapters
|
|
28
|
+
can return a response without deltas. Empty deltas have no effect.
|
|
29
|
+
|
|
30
|
+
The default logical deadline is 120000ms from the first durable attempt start, shared by all attempts
|
|
31
|
+
and the retry wait. A single transient failure before cutoff may retry once,
|
|
32
|
+
after 1000ms, with the identical frozen request and only remaining time. No
|
|
33
|
+
retry occurs for invalid input/config, cancellation, incomplete EOF, output
|
|
34
|
+
limit, or other failures. The cutoff is the first nonempty text delta accepted
|
|
35
|
+
by the runner, before subscription filtering, queuing or backpressure, or a
|
|
36
|
+
committed response. Privately buffered tool fragments can confirm Seen without
|
|
37
|
+
closing retry. Interrupt and stop abort the attempt or retry delay and fence all
|
|
38
|
+
late signals and writes; suspension permits the current logical call and an
|
|
39
|
+
eligible retry within the original deadline, then handles the iteration under
|
|
40
|
+
existing tool and approval rules and checkpoints before another call.
|
|
41
|
+
|
|
42
|
+
`accepted` confirms Delivered; nonempty text or adapter `seen` confirms Seen
|
|
43
|
+
(and Delivered). A validated complete response confirms both. Evidence applies
|
|
44
|
+
only to the call's frozen set of items taken into that turn and included in the
|
|
45
|
+
request, never shared-history items or inbox items not taken. Each advancing
|
|
46
|
+
receipt commits before its event and survives an attempt failure. The attempt
|
|
47
|
+
start, provider ID and reported usage are durable; usage is an absolute report
|
|
48
|
+
for that attempt, not a delta, so a later report replaces its previous report
|
|
49
|
+
and aggregation sums each attempt once. Absent counts remain unknown; never
|
|
50
|
+
invent zero. Usage must be emitted before the attempt terminal to be accepted;
|
|
51
|
+
usage arriving after a timeout or cancellation is fenced even if the provider
|
|
52
|
+
reports it later. A started attempt with no confirmed usage stays unknown. Usage accepted before termination survives a crash. Ignore all
|
|
53
|
+
signals after a terminal, timeout, cancellation, or a failed storage fence.
|
|
54
|
+
|
|
55
|
+
A running call's successful attempt and complete response, including all tool
|
|
56
|
+
calls and the reserved message ID, commit in one storage transaction. Only
|
|
57
|
+
after that succeeds can completion be queued and tool dispatch begin. Failed
|
|
58
|
+
commit publishes neither completion nor tool effects. Marking dispatch still
|
|
59
|
+
follows 0018. On interrupt or crash after success, retain the successful call
|
|
60
|
+
and message even if the enclosing turn ends interrupted. Before success commit,
|
|
61
|
+
no assistant response or tool calls are durable or executable. On recovery,
|
|
62
|
+
unfinished calls and running attempts become interrupted, preserving committed
|
|
63
|
+
receipts and usage, without replay. Both memory and SQLite implement the same
|
|
64
|
+
atomic boundaries. Each scripted attempt reserves and increments its channel's
|
|
65
|
+
zero-based script position in the durable start-attempt transaction, including
|
|
66
|
+
retries; a crash consumes the reservation even if no adapter code ran. Reopen
|
|
67
|
+
uses the durable position, never the count of completed messages.
|
|
68
|
+
|
|
69
|
+
Messages is the default text subscription (`final` remains its wire spelling
|
|
70
|
+
for compatibility); streaming is opt-in as `stream`. Both run identical calls
|
|
71
|
+
and commit identical history. Stream events carry the reserved message ID;
|
|
72
|
+
completion uses that same ID and precedes tool events. A tool-only response
|
|
73
|
+
emits no text completion. Failure after any published draft emits one incomplete
|
|
74
|
+
event if the connection remains deliverable; final mode filters both deltas and
|
|
75
|
+
incomplete events. After reconnect, look up that ID: committed text replaces a
|
|
76
|
+
local draft; otherwise mark it incomplete. Drafts are not durable history.
|
|
77
|
+
|
|
78
|
+
Each connection has a 1 MiB live-event queue in addition to the existing 1 MiB
|
|
79
|
+
frame maximum. Producers never await a reader. Coalesce queued text deltas for
|
|
80
|
+
the same message when they fit; on overflow drop further deltas for that
|
|
81
|
+
message and enqueue one `text_gap` before its completion. If a required gap,
|
|
82
|
+
completion, or other nondroppable event cannot fit, fail the connection and
|
|
83
|
+
apply existing disconnect/stop rules; committed data remains recoverable. A
|
|
84
|
+
`message_completed` fitting the frame is inline; otherwise it carries `reference: true`
|
|
85
|
+
and its ID. `session/message/read` retrieves committed UTF-8 text by ID as
|
|
86
|
+
base64 pages of at most 524288 raw bytes, with byte offsets and `nextOffset`;
|
|
87
|
+
concatenate bytes before decoding. Unknown IDs are `not_found`, invalid offsets
|
|
88
|
+
are `invalid_input`, and paging does not alter history. `session/load` and
|
|
89
|
+
`session/messages` use the same reference representation for oversized text
|
|
90
|
+
instead of failing solely because one message is too large. `session/model-calls` summary pagination
|
|
91
|
+
is in durable call-creation order using a stable call ID as cursor, with a maximum of 100 calls per page and a 1 MiB frame;
|
|
92
|
+
when a page cannot fit, return fewer entries and a continuation, never a partial
|
|
93
|
+
summary. A single summary too large for a frame fails `transfer_limit`.
|
|
94
|
+
|
|
95
|
+
## Compatibility and traces
|
|
96
|
+
|
|
97
|
+
SQLite format becomes 5 and logical archive becomes 4; session-file envelope
|
|
98
|
+
stays 1. Upgrade formats 2/3 through their existing recovery and migration to
|
|
99
|
+
4, then to 5 transactionally. Existing format 4 opens with empty call records
|
|
100
|
+
and scripted position initialized from its prior assistant-response count per
|
|
101
|
+
channel, preserving the old scripted continuation behavior. New exports carry
|
|
102
|
+
format 5/archive 4, summaries, usage, and script positions. Adapter imports of
|
|
103
|
+
archives 1–3 and session files with archives 2–3 migrate equivalently; archive
|
|
104
|
+
1 inside an envelope remains invalid. Standalone JSON stays invalid. Validate
|
|
105
|
+
all references, IDs, attempt ordering, states and usage before atomic import;
|
|
106
|
+
no failed upgrade/import may partly publish. Export eligibility and saved config
|
|
107
|
+
are unchanged. Unfinished calls cannot be exported because export requires a
|
|
108
|
+
clean suspension or idle session.
|
|
109
|
+
|
|
110
|
+
Trace retry: no text, transient attempt 1 persists evidence/usage, attempt 2
|
|
111
|
+
uses the same request; a successful atomic commit yields one message and two
|
|
112
|
+
attempt summaries in either delivery mode. Text before failure instead closes
|
|
113
|
+
retry in both modes, leaves no completed message, and only streaming receives
|
|
114
|
+
incomplete. Interrupt during a wait or attempt records interrupted and fences
|
|
115
|
+
late output. A slow reader loses deltas, not committed data; if its queue cannot
|
|
116
|
+
hold required events it disconnects, while already committed results remain.
|
|
117
|
+
Crash after script reservation but before response commit leaves an interrupted
|
|
118
|
+
call and consumed script step, with no response or tool effect. Crash after
|
|
119
|
+
response commit preserves the successful call and message with the same ID;
|
|
120
|
+
tool effects obey dispatch evidence 0018 and are never replayed.
|
|
121
|
+
|
|
122
|
+
## Contract locks following review
|
|
123
|
+
|
|
124
|
+
The following details resolve the wire and lifecycle choices above. The existing
|
|
125
|
+
completion event is `message_completed`, never a second completion event. It
|
|
126
|
+
carries the reserved message ID in both subscription modes. Streaming adds only
|
|
127
|
+
`text_delta`, `text_gap`, and `text_incomplete`; `final` filters those three,
|
|
128
|
+
while receiving completions, tool events and turn outcomes. Receipts remain
|
|
129
|
+
`items_receipt`, emitted after their commit only for items that advanced.
|
|
130
|
+
Inline `message_completed` has the complete text in parts; a reference omits
|
|
131
|
+
parts. Oversized entries in load and message listing use the same reference.
|
|
132
|
+
`session/model-calls` and `session/message/read` are protocol methods. Turn
|
|
133
|
+
outcomes remain completed, failed and interrupted: only interrupt and stop
|
|
134
|
+
produce interrupted; timeout, failed, incomplete and output_limit end the turn
|
|
135
|
+
failed with that call outcome as its reason, with no further call in that turn.
|
|
136
|
+
|
|
137
|
+
The deadline starts when the first attempt's durable start commits, not at
|
|
138
|
+
startCall. If less than the 1000ms retry delay remains, finish timeout without
|
|
139
|
+
starting the retry. Defaults are 120000ms, 1000ms and one retry; tests may
|
|
140
|
+
shorten timeoutMs. Tool execution, approval and inbox time are outside the limit.
|
|
141
|
+
|
|
142
|
+
The script counter denotes the next zero-based step. Starting a scripted
|
|
143
|
+
attempt atomically records that step and increments the counter; a non-scripted
|
|
144
|
+
start does not. A failed start writes nothing. A call has at most one running
|
|
145
|
+
attempt and two attempts total; an excess start fails and writes nothing. A
|
|
146
|
+
failed response commit does not undo a reservation. Migration counts all prior
|
|
147
|
+
assistant timeline messages on the channel, including tool-only messages; reopen
|
|
148
|
+
uses the stored counter without recounting.
|
|
149
|
+
|
|
150
|
+
A call reserves a message ID that is never reused even if it does not commit.
|
|
151
|
+
`commitResponse` accepts only validated `complete` without calls or validated
|
|
152
|
+
`tool_calls` with calls; other stop reasons or invalid tool payloads fail without
|
|
153
|
+
writes. The same transaction ensures dispatchedCallIds exists for responses
|
|
154
|
+
containing calls without marking new call IDs, as in 0018. The transaction does
|
|
155
|
+
not mark or invoke tools. The existing permission gate follows it. Completion
|
|
156
|
+
is emitted only for nonempty committed text. Non-streaming adapters emit a
|
|
157
|
+
validated response through the runner; the kernel does not take receipt evidence
|
|
158
|
+
or dispatch from a resolved Model promise.
|
|
159
|
+
|
|
160
|
+
Milestones only advance; seen includes delivered, and repeated or lower evidence
|
|
161
|
+
writes nothing. startCall rejects any item that is not taken by that turn with no
|
|
162
|
+
write. A provider request ID is committed on its first report, including accepted
|
|
163
|
+
before terminal, and survives crash. Usage reports replace absolute per-attempt
|
|
164
|
+
values; negative, fractional or unsafe counts are rejected without replacing a
|
|
165
|
+
prior report. Missing fields stay unknown. Sum each present field once per
|
|
166
|
+
attempt without inventing a total. Reports after terminal, timeout or cancellation
|
|
167
|
+
are ignored.
|
|
168
|
+
|
|
169
|
+
Format 2/3 performs existing upgrade through 4 and existing recovery, then the
|
|
170
|
+
format 5 migration in one transaction. Format 4 performs existing recovery first:
|
|
171
|
+
a suspended session keeps its turns; otherwise running turns and checkpoints
|
|
172
|
+
outside individually suspended channels are interrupted, and a suspending channel
|
|
173
|
+
returns open. The same transaction adds empty call records, initializes script
|
|
174
|
+
positions and publishes format 5, including for suspended sessions. Failure leaves
|
|
175
|
+
the owned file at its old version. Import and export reject running calls or
|
|
176
|
+
attempts. A succeeded call has exactly one assistant timeline message at its
|
|
177
|
+
reserved ID with its committed tool calls; other outcomes have none. Attempt
|
|
178
|
+
ordinals are contiguous from zero. Adapter archives 1–3 and session-file archives
|
|
179
|
+
2–3 migrate equivalently; envelope 1 remains, and archive 1 inside it is invalid.
|
|
180
|
+
A summary page contains whole calls; a single call too large for a frame fails
|
|
181
|
+
`transfer_limit`, never an empty page.
|
|
182
|
+
|
|
183
|
+
The runner never awaits a transport write. The per-connection 1 MiB live queue
|
|
184
|
+
coalesces deltas in order, drops further deltas for a lagging message and enqueues
|
|
185
|
+
one gap. The existing 1 MiB frame and 4 MiB queued-write limits remain. If a
|
|
186
|
+
nondroppable event cannot fit the live queue or the existing writer rejects it,
|
|
187
|
+
fail that connection and apply existing disconnect and stop rules. Already
|
|
188
|
+
committed records remain recoverable.
|