@qlairoslabs/acp-client 0.12.1 → 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 -10
- package/CHANGELOG-controller-interface.md +258 -0
- package/CHANGELOG-metering.md +29 -0
- package/CHANGELOG-operation-lifecycle.md +15 -1
- package/CONSUMER_GUIDE.md +845 -6
- 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 +25 -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 +3 -0
- package/src/cli/index.ts +3 -3
- package/src/cli/managed.ts +2 -2
- package/src/client.ts +52 -94
- 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,160 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { spawnHarness } from "./helpers/stdio.ts";
|
|
3
|
+
import { createInProcessHarness } from "../src/testing.ts";
|
|
4
|
+
import { createSession } from "../src/index.ts";
|
|
5
|
+
import { HarnessClient, createInProcessTransport } from "../src/client.ts";
|
|
6
|
+
import { createProtocolServer } from "../src/interfaces/protocol/server.ts";
|
|
7
|
+
import { publishChannelEvent, createChannelOutputs } from "../src/interfaces/protocol/output.ts";
|
|
8
|
+
import type { ChannelEvent } from "../src/contracts/events.ts";
|
|
9
|
+
import type { CreateParams, ClientTransport } from "../src/contracts/protocol.ts";
|
|
10
|
+
import { lastInput } from "./helpers/session.ts";
|
|
11
|
+
|
|
12
|
+
const setup: CreateParams = { sessionId: "test", participants: [], channels: {}, config: {
|
|
13
|
+
version: 1, system: "Test system", model: { protocol: "scripted", script: new URL("./fixtures/echo-scenario.jsonl", import.meta.url).pathname }, defaultPolicy: "__legacy_allow", policies: { __legacy_allow: { fallback: "allow", tools: {} } },
|
|
14
|
+
} };
|
|
15
|
+
const push = (channel: string, id: string, text = "hello") => ({ channel, item: {
|
|
16
|
+
id, kind: "user_message" as const, sender: channel, content: [{ type: "text" as const, text }],
|
|
17
|
+
} });
|
|
18
|
+
function collect(client: HarnessClient, count = 1) {
|
|
19
|
+
const events: ChannelEvent[] = [];
|
|
20
|
+
let resolve!: () => void;
|
|
21
|
+
const done = new Promise<void>(r => { resolve = r; });
|
|
22
|
+
client.onChannelEvent(event => {
|
|
23
|
+
events.push(event);
|
|
24
|
+
if (events.filter(e => e.event.type === "turn_ended").length === count) resolve();
|
|
25
|
+
});
|
|
26
|
+
return { events, done };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
for (const transport of ["in-process", "stdio"] as const) test(`${transport}: public client drives two independent scripted channels and idempotent pushes`, async () => {
|
|
30
|
+
const harness = transport === "in-process" ? createInProcessHarness({ captureRequests: true }) : spawnHarness(); const { client } = harness;
|
|
31
|
+
try {
|
|
32
|
+
const init = await client.initialize();
|
|
33
|
+
expect(init.description.capabilities).toMatchObject({ experimental: true, persistence: transport === "stdio", acceptance: transport === "stdio" ? "durable" : "memory" });
|
|
34
|
+
await client.createSession(setup);
|
|
35
|
+
const log = collect(client, 2);
|
|
36
|
+
const acks = await Promise.all([client.push(push("a", "a1")), client.push(push("b", "b1"))]);
|
|
37
|
+
expect(acks[0]).toEqual({ accepted: true, duplicate: false, item: { id: "a1", channel: "a", kind: "participant_message", sender: "a", milestone: "received", policy: { resolved: "__legacy_allow", inherited: [] } } });
|
|
38
|
+
await log.done;
|
|
39
|
+
expect(await client.idle()).toEqual({ idle: true });
|
|
40
|
+
expect(await client.status()).toMatchObject({ sessionId: "test", lifecycle: "running", execution: "idle",
|
|
41
|
+
channels: [{ channel: "a", pending: [] }, { channel: "b", pending: [] }] });
|
|
42
|
+
for (const channel of ["a", "b"]) {
|
|
43
|
+
const events = log.events.filter(e => e.channel === channel).map(e => e.event);
|
|
44
|
+
expect(events[0]).toMatchObject({ type: "turn_started", items: [`${channel}1`] });
|
|
45
|
+
expect(events.at(-1)).toMatchObject({ type: "turn_ended", outcome: "completed" });
|
|
46
|
+
expect(events.filter(e => e.type === "message_completed")).toHaveLength(2);
|
|
47
|
+
expect(events.filter(e => e.type === "tool_call").map(e => e.status)).toEqual(["started", "completed"]);
|
|
48
|
+
if ("models" in harness) {
|
|
49
|
+
expect(harness.models.get(channel)).toHaveLength(2);
|
|
50
|
+
expect(harness.models.get(channel)?.[1]?.messages.at(-1)).toMatchObject({ role: "tool", content: '{"ok":true,"text":"hello"}' });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const before = log.events.length;
|
|
54
|
+
// A retry is answered from storage with the original item's current state.
|
|
55
|
+
expect(await client.push(push("a", "a1"))).toEqual({ accepted: true, duplicate: true,
|
|
56
|
+
item: { id: "a1", channel: "a", kind: "participant_message", sender: "a", milestone: "seen", turnId: expect.any(String), policy: { resolved: "__legacy_allow", inherited: [] } } });
|
|
57
|
+
expect(log.events).toHaveLength(before);
|
|
58
|
+
await expect(client.push(push("b", "a1"))).rejects.toMatchObject({ code: "item_conflict" });
|
|
59
|
+
const failure = collect(client);
|
|
60
|
+
await client.push(push("a", "a2")); await failure.done;
|
|
61
|
+
expect(failure.events.at(-1)?.event).toMatchObject({ type: "turn_ended", outcome: "failed" });
|
|
62
|
+
expect(failure.events.filter(e => e.event.type === "turn_ended")).toHaveLength(1);
|
|
63
|
+
} finally { await harness.close(); }
|
|
64
|
+
}, 5000);
|
|
65
|
+
|
|
66
|
+
test("notice continuation preserves both completed replies and emits turn_took", async () => {
|
|
67
|
+
let calls = 0;
|
|
68
|
+
const session = createSession({ systemPrompt: "test", configureTurn: () => ({
|
|
69
|
+
tools: [], executeTool: async () => "unused", model: async () => {
|
|
70
|
+
calls++;
|
|
71
|
+
if (calls === 1) session.agent.notify({ channelId: "a", fromChannelId: "b", text: "Greeting" });
|
|
72
|
+
return { role: "assistant", content: calls === 1 ? "Activity report" : "Greeting received", calls: [] };
|
|
73
|
+
},
|
|
74
|
+
}) });
|
|
75
|
+
const outputs = createChannelOutputs(); const delivered: string[] = [];
|
|
76
|
+
outputs.subscribe("a", event => delivered.push(event.text));
|
|
77
|
+
session.subscribe(event => publishChannelEvent(outputs, event));
|
|
78
|
+
const server = createProtocolServer(async () => ({ session, close() {} }));
|
|
79
|
+
const client = new HarnessClient(createInProcessTransport(server));
|
|
80
|
+
try {
|
|
81
|
+
await client.initialize(); await client.createSession(setup);
|
|
82
|
+
const log = collect(client);
|
|
83
|
+
await client.push(push("a", "item")); await log.done;
|
|
84
|
+
expect(delivered).toEqual(["Activity report", "Greeting received"]);
|
|
85
|
+
expect(log.events.map(e => e.event.type)).toEqual(["turn_started", "items_receipt", "message_completed", "turn_took", "items_receipt", "message_completed", "turn_ended"]);
|
|
86
|
+
// Every one of these reports a commit, in commit order.
|
|
87
|
+
const revisions = log.events.map(e => e.revision);
|
|
88
|
+
expect(revisions.every(revision => Number.isSafeInteger(revision))).toBe(true);
|
|
89
|
+
expect(revisions).toEqual([...revisions].sort((x, y) => x! - y!));
|
|
90
|
+
expect(log.events[1]?.event).toMatchObject({ items: ["item"], milestone: "seen" });
|
|
91
|
+
const ids = log.events.map(e => e.event).filter(e => e.type === "message_completed").map(e => e.messageId);
|
|
92
|
+
expect(new Set(ids).size).toBe(2);
|
|
93
|
+
} finally { client.close(); }
|
|
94
|
+
}, 5000);
|
|
95
|
+
|
|
96
|
+
test("acceptance does not await inference; idle includes pending work and values cross a copy boundary", async () => {
|
|
97
|
+
let release!: () => void;
|
|
98
|
+
const gate = new Promise<void>(r => { release = r; });
|
|
99
|
+
let entered!: () => void;
|
|
100
|
+
const firstInference = new Promise<void>(resolve => { entered = resolve; });
|
|
101
|
+
const session = createSession({ systemPrompt: "test", configureTurn: () => ({ tools: [], executeTool: async () => "unused",
|
|
102
|
+
model: async messages => { entered(); await gate; return { role: "assistant", content: lastInput(messages), calls: [] }; },
|
|
103
|
+
}) });
|
|
104
|
+
const client = new HarnessClient(createInProcessTransport(createProtocolServer(async () => ({ session, close() {} }))));
|
|
105
|
+
try {
|
|
106
|
+
await client.initialize(); await client.createSession(setup);
|
|
107
|
+
// The second message arrives while the first inference is in flight and joins that turn.
|
|
108
|
+
const log = collect(client, 1);
|
|
109
|
+
const input = push("a", "1");
|
|
110
|
+
const accepted = client.push(input); input.item.content[0]!.text = "mutated";
|
|
111
|
+
await accepted; await firstInference; await client.push(push("a", "2"));
|
|
112
|
+
expect(await client.idle()).toEqual({ idle: false });
|
|
113
|
+
release(); await log.done;
|
|
114
|
+
expect(log.events.map(e => e.event).filter(e => e.type === "message_completed").map(e => e.parts![0]?.text)).toEqual(["hello", "hello"]);
|
|
115
|
+
expect(log.events.map(e => e.event).flatMap(e => e.type === "turn_started" || e.type === "turn_took" ? [e.items] : [])).toEqual([["1"], ["2"]]);
|
|
116
|
+
expect(await client.idle()).toEqual({ idle: true });
|
|
117
|
+
} finally { release(); client.close(); }
|
|
118
|
+
}, 5000);
|
|
119
|
+
|
|
120
|
+
for (const transport of ["in-process", "stdio"] as const) test(`${transport}: protocol rejects lifecycle misuse, unsupported methods/options and mismatched versions`, async () => {
|
|
121
|
+
const harness = transport === "in-process" ? createInProcessHarness() : spawnHarness();
|
|
122
|
+
try {
|
|
123
|
+
await expect(harness.client.idle()).rejects.toMatchObject({ code: "not_ready" });
|
|
124
|
+
await expect(harness.client.initialize({ protocolVersion: 2, host: { name: "test", version: "0" }, callbacks: [], subscription: { text: "final", tools: "none" } })).rejects.toMatchObject({ code: "version_mismatch" });
|
|
125
|
+
await harness.client.initialize();
|
|
126
|
+
await expect(harness.client.push(push("a", "1"))).rejects.toMatchObject({ code: "not_ready" });
|
|
127
|
+
const invalid = structuredClone(setup) as any; invalid.config.policies = {};
|
|
128
|
+
await expect(harness.client.createSession(invalid)).rejects.toMatchObject({ code: "invalid_config" });
|
|
129
|
+
await harness.client.createSession(setup);
|
|
130
|
+
await expect(harness.client.createSession(setup)).rejects.toMatchObject({ code: "already_exists" });
|
|
131
|
+
await expect(harness.client.request("session/load" as any, {})).rejects.toMatchObject({ code: "method_not_found" });
|
|
132
|
+
if ("server" in harness) expect(await harness.server.request(null as any)).toMatchObject({ error: { code: -32600, data: { code: "invalid_request" } } });
|
|
133
|
+
await expect(harness.client.push({ ...push("a", "1"), item: { ...push("a", "1").item, delivery: "steer" } } as any)).rejects.toMatchObject({ code: "invalid_params" });
|
|
134
|
+
} finally { await harness.close(); }
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
for (const transport of ["in-process", "stdio"] as const) test(`${transport}: subscription tool summaries omit payloads and none omits tool events`, async () => {
|
|
138
|
+
for (const tools of ["summary", "none"] as const) {
|
|
139
|
+
const harness = transport === "in-process" ? createInProcessHarness() : spawnHarness();
|
|
140
|
+
try {
|
|
141
|
+
await harness.client.initialize({ protocolVersion: 1, host: { name: "test", version: "0" }, callbacks: [], subscription: { text: "final", tools } });
|
|
142
|
+
await harness.client.createSession(setup);
|
|
143
|
+
const log = collect(harness.client);
|
|
144
|
+
await harness.client.push(push("a", "1")); await log.done;
|
|
145
|
+
const calls = log.events.map(e => e.event).filter(e => e.type === "tool_call");
|
|
146
|
+
expect(calls).toHaveLength(tools === "none" ? 0 : 2);
|
|
147
|
+
for (const call of calls) { expect(call.input).toBeUndefined(); expect(call.output).toBeUndefined(); }
|
|
148
|
+
expect(log.events.filter(e => e.event.type === "message_completed")).toHaveLength(2);
|
|
149
|
+
} finally { await harness.close(); }
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("client bounds request waits and rejects pending work on close", async () => {
|
|
154
|
+
const transport: ClientTransport = { send() {}, subscribe: () => () => {}, onClose: () => () => {}, close() {} };
|
|
155
|
+
const client = new HarnessClient(transport, 5);
|
|
156
|
+
await expect(client.idle()).rejects.toMatchObject({ code: "timeout" });
|
|
157
|
+
const pending = client.idle(); client.close();
|
|
158
|
+
await expect(pending).rejects.toMatchObject({ code: "closed" });
|
|
159
|
+
await expect(client.idle()).rejects.toMatchObject({ code: "closed" });
|
|
160
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createSession } from "../src/index.ts";
|
|
2
|
+
import { expect, test } from "bun:test";
|
|
3
|
+
import { createReminderTimer } from "../src/runtime/reminder-timer.ts";
|
|
4
|
+
import { normalizeReminderSchedule, resolveAgentReminder } from "../src/util/reminder-schedule.ts";
|
|
5
|
+
|
|
6
|
+
test("reminder timer chunks long waits and rechecks early, backward and forward wakes", () => {
|
|
7
|
+
let now = 1000, wakeCount = 0;
|
|
8
|
+
let pending: { callback: () => void; delay: number } | undefined;
|
|
9
|
+
const timer = createReminderTimer({
|
|
10
|
+
now: () => now,
|
|
11
|
+
setTimer(callback, delay) {
|
|
12
|
+
expect(pending).toBeUndefined();
|
|
13
|
+
const scheduled = { callback, delay };
|
|
14
|
+
pending = scheduled;
|
|
15
|
+
return () => { if (pending === scheduled) pending = undefined; };
|
|
16
|
+
},
|
|
17
|
+
}, () => { wakeCount++; });
|
|
18
|
+
const fire = () => { const current = pending!; pending = undefined; current.callback(); };
|
|
19
|
+
const due = now + 30 * 86_400_000;
|
|
20
|
+
timer.arm(new Date(due).toISOString());
|
|
21
|
+
expect(pending?.delay).toBe(60_000);
|
|
22
|
+
fire();
|
|
23
|
+
expect(wakeCount).toBe(0);
|
|
24
|
+
now = 0;
|
|
25
|
+
fire();
|
|
26
|
+
expect(wakeCount).toBe(0);
|
|
27
|
+
expect(pending?.delay).toBe(60_000);
|
|
28
|
+
now = due;
|
|
29
|
+
fire();
|
|
30
|
+
expect(wakeCount).toBe(1);
|
|
31
|
+
timer.arm(new Date(due + 1).toISOString());
|
|
32
|
+
const replaced = pending!.callback;
|
|
33
|
+
timer.stop();
|
|
34
|
+
replaced();
|
|
35
|
+
expect(wakeCount).toBe(1);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("offline lead and expiry are derived from the original acceptance anchor", () => {
|
|
39
|
+
const anchor = Date.parse("2026-11-24T12:00:00Z");
|
|
40
|
+
const due = "2026-11-24T12:02:00Z", accepted = "2026-11-24T12:00:00Z";
|
|
41
|
+
expect(normalizeReminderSchedule(due, accepted, undefined, anchor + 600_000)).toEqual({
|
|
42
|
+
schedule: { at: "2026-11-24T12:02:00.000Z" }, acceptedAt: "2026-11-24T12:00:00.000Z",
|
|
43
|
+
expiresAfter: 300_000, expiresAt: "2026-11-24T12:07:00.000Z",
|
|
44
|
+
});
|
|
45
|
+
expect(normalizeReminderSchedule(due, accepted, null, anchor)?.expiresAt).toBeNull();
|
|
46
|
+
expect(normalizeReminderSchedule(due, accepted, undefined, anchor - 30_001)).toBeUndefined();
|
|
47
|
+
expect(normalizeReminderSchedule("2026-11-24T12:01:59Z", accepted, undefined, anchor)).toBeUndefined();
|
|
48
|
+
expect(normalizeReminderSchedule("2026-11-31T12:02:00Z", accepted, undefined, anchor)).toBeUndefined();
|
|
49
|
+
expect(resolveAgentReminder({ in: "2m" }, anchor)).toBe("2026-11-24T12:02:00.000Z");
|
|
50
|
+
expect(resolveAgentReminder({ in: "0m" }, anchor)).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("conditional stop refuses runnable work before the scheduler starts", () => {
|
|
54
|
+
const session = createSession({ systemPrompt: "test", configureTurn: () => {
|
|
55
|
+
throw new Error("The scheduler has not started");
|
|
56
|
+
} });
|
|
57
|
+
expect(session.agent.send({ channelId: "alice", participantId: "Rin", text: "Waiting" }).accepted).toBe(true);
|
|
58
|
+
expect(session.reminders!.conditionalStop(0)).toEqual({ stopped: false, reason: "busy" });
|
|
59
|
+
expect(session.status().execution).toBe("working");
|
|
60
|
+
session.stop("test complete");
|
|
61
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import type { ChannelEvent } from "../src/contracts/events.ts";
|
|
6
|
+
import type { ReminderChange } from "../src/contracts/reminders.ts";
|
|
7
|
+
import { spawnHarness } from "./helpers/stdio.ts";
|
|
8
|
+
|
|
9
|
+
test("stdio: offline reminder fires once during startup and replay returns the frozen receipt", async () => {
|
|
10
|
+
const home = mkdtempSync(join(tmpdir(), "reminder-cold-"));
|
|
11
|
+
const now = Date.parse("2026-11-24T12:00:00.000Z");
|
|
12
|
+
const due = new Date(now + 120_000).toISOString();
|
|
13
|
+
const script = new URL("./fixtures/echo-scenario.jsonl", import.meta.url).pathname;
|
|
14
|
+
const change: ReminderChange = { reminderId: "one", changeId: 1, op: "create", payload: {
|
|
15
|
+
channel: "alice", schedule: { at: due }, text: "Check the result", acceptedAt: new Date(now).toISOString(),
|
|
16
|
+
} };
|
|
17
|
+
try {
|
|
18
|
+
const first = spawnHarness({ home, reminderTime: now });
|
|
19
|
+
try {
|
|
20
|
+
const initialized = await first.client.initialize();
|
|
21
|
+
expect(initialized.description.capabilities.reminders).toBe(true);
|
|
22
|
+
expect(initialized.description.reminderLimits?.minLeadMs).toBe(120_000);
|
|
23
|
+
await first.client.createSession({ sessionId: "s", participants: [], channels: {},
|
|
24
|
+
channelChanges: [{ changeId: "create-alice", channel: "alice" }],
|
|
25
|
+
config: { version: 1, system: "test", model: { protocol: "scripted", script }, defaultPolicy: "allow", policies: { allow: { fallback: "allow", tools: {} } } },
|
|
26
|
+
});
|
|
27
|
+
expect(await first.client.stopIfIdle()).toEqual({ stopped: true });
|
|
28
|
+
} finally { await first.close(); }
|
|
29
|
+
const second = spawnHarness({ home, reminderTime: now + 120_000 });
|
|
30
|
+
try {
|
|
31
|
+
const events: ChannelEvent[] = [];
|
|
32
|
+
second.client.onChannelEvent(event => events.push(event));
|
|
33
|
+
await second.client.initialize();
|
|
34
|
+
const opened = await second.client.openSession({ sessionId: "s", reminderChanges: [change] });
|
|
35
|
+
expect(opened.reminders?.[0]).toMatchObject({ id: "one", state: "done", noticeId: `reminder-notice:one:${due}` });
|
|
36
|
+
expect(opened.reminderChanges?.[0]).toMatchObject({ outcome: "applied", reminder: { state: "active", nextRunAt: due } });
|
|
37
|
+
expect(opened.nextDueAt).toBeNull();
|
|
38
|
+
expect(await second.client.changeReminder(change)).toEqual(opened.reminderChanges![0]!);
|
|
39
|
+
const deadline = performance.now() + 3000;
|
|
40
|
+
while (!events.some(event => event.event.type === "turn_ended") && performance.now() < deadline) await Bun.sleep(5);
|
|
41
|
+
expect(events.filter(event => event.event.type === "reminder_fired")).toHaveLength(1);
|
|
42
|
+
expect(events.filter(event => event.event.type === "turn_ended")).toHaveLength(1);
|
|
43
|
+
const item = await second.client.reconcileChannel({ channel: "alice", itemIds: [`reminder-notice:one:${due}`] });
|
|
44
|
+
expect(item.items).toHaveLength(1);
|
|
45
|
+
expect(item.items[0]?.turnId).toBe("1");
|
|
46
|
+
} finally { await second.close(); }
|
|
47
|
+
} finally { rmSync(home, { recursive: true, force: true }); }
|
|
48
|
+
}, 15000);
|
|
49
|
+
|
|
50
|
+
for (const point of ["changeReminder", "fireDueReminders"]) {
|
|
51
|
+
test(`stdio: SIGKILL after ${point} preserves exactly one reminder notice on reopen`, async () => {
|
|
52
|
+
const home = mkdtempSync(join(tmpdir(), "reminder-crash-"));
|
|
53
|
+
const now = Date.parse("2026-11-24T12:00:00.000Z"), wakeTime = now + 120_000;
|
|
54
|
+
const at = new Date(wakeTime).toISOString();
|
|
55
|
+
const script = new URL("./fixtures/echo-scenario.jsonl", import.meta.url).pathname;
|
|
56
|
+
const change: ReminderChange = { reminderId: "crash", changeId: 1, op: "create", payload: {
|
|
57
|
+
channel: "alice", schedule: { at }, text: "Crash reminder", acceptedAt: new Date(now).toISOString(),
|
|
58
|
+
} };
|
|
59
|
+
try {
|
|
60
|
+
const first = spawnHarness({ home, reminderTime: now });
|
|
61
|
+
try {
|
|
62
|
+
await first.client.initialize();
|
|
63
|
+
await first.client.createSession({ sessionId: "s", participants: [], channels: {},
|
|
64
|
+
channelChanges: [{ channel: "alice", changeId: "create" }],
|
|
65
|
+
config: { version: 1, system: "test", model: { protocol: "scripted", script }, defaultPolicy: "allow", policies: { allow: { fallback: "allow", tools: {} } } },
|
|
66
|
+
});
|
|
67
|
+
} finally { await first.close(); }
|
|
68
|
+
const crashed = spawnHarness({ home, reminderTime: wakeTime, fault: `${point}:1` });
|
|
69
|
+
try {
|
|
70
|
+
await crashed.client.initialize();
|
|
71
|
+
await expect(crashed.client.openSession({ sessionId: "s", reminderChanges: [change] })).rejects.toMatchObject({ code: "transport_closed" });
|
|
72
|
+
expect(await crashed.child.exited).toBe(137);
|
|
73
|
+
} finally { crashed.client.close(); crashed.child.kill(); await crashed.child.exited; }
|
|
74
|
+
const recovered = spawnHarness({ home, reminderTime: wakeTime });
|
|
75
|
+
try {
|
|
76
|
+
await recovered.client.initialize();
|
|
77
|
+
const opened = await recovered.client.openSession({ sessionId: "s", reminderChanges: [change] });
|
|
78
|
+
const id = `reminder-notice:crash:${at}`;
|
|
79
|
+
expect(opened.reminders?.[0]).toMatchObject({ state: "done", noticeId: id });
|
|
80
|
+
expect(opened.reminderChanges?.[0]).toMatchObject({ outcome: "applied", reminder: { state: "active" } });
|
|
81
|
+
const read = await recovered.client.reconcileChannel({ channel: "alice", itemIds: [id] });
|
|
82
|
+
expect(read.items.map(item => item.id)).toEqual([id]);
|
|
83
|
+
} finally { await recovered.close(); }
|
|
84
|
+
} finally { rmSync(home, { recursive: true, force: true }); }
|
|
85
|
+
}, 15000);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
test("stdio: checked reminder tool schedules for its own channel and fences idle stop", async () => {
|
|
89
|
+
const home = mkdtempSync(join(tmpdir(), "reminder-tool-"));
|
|
90
|
+
const now = Date.parse("2026-11-24T12:00:00.000Z");
|
|
91
|
+
const script = join(home, "reminder.jsonl");
|
|
92
|
+
const records = [
|
|
93
|
+
{ type: "scenario", version: 1, name: "reminder-tool" },
|
|
94
|
+
{ type: "model", content: null, calls: [
|
|
95
|
+
{ id: "invalid", name: "schedule_reminder", arguments: { schedule: { in: "5m" }, text: "wrong", channel: "other" } },
|
|
96
|
+
{ id: "schedule", name: "schedule_reminder", arguments: { schedule: { in: "5m" }, text: "Check the result" } },
|
|
97
|
+
] },
|
|
98
|
+
{ type: "model", content: "Scheduled." },
|
|
99
|
+
{ type: "model", content: "Checked." },
|
|
100
|
+
];
|
|
101
|
+
try {
|
|
102
|
+
await Bun.write(script, records.map(record => JSON.stringify(record)).join("\n") + "\n");
|
|
103
|
+
const first = spawnHarness({ home, reminderTime: now });
|
|
104
|
+
try {
|
|
105
|
+
const events: ChannelEvent[] = [];
|
|
106
|
+
first.client.onChannelEvent(event => events.push(event));
|
|
107
|
+
await first.client.initialize({ protocolVersion: 1, host: { name: "test", version: "0" }, callbacks: [],
|
|
108
|
+
approval: true, subscription: { text: "final", tools: "full" } });
|
|
109
|
+
await first.client.createSession({ sessionId: "s", participants: [], channels: {},
|
|
110
|
+
config: { version: 1, system: "test", model: { protocol: "scripted", script }, defaultPolicy: "ask",
|
|
111
|
+
policies: { ask: { fallback: "ask", tools: {} } } } });
|
|
112
|
+
await first.client.push({ channel: "alice", item: { id: "seed", kind: "user_message", sender: "Rin",
|
|
113
|
+
content: [{ type: "text", text: "Remind me" }] } });
|
|
114
|
+
const findApproval = () => events.map(event => event.event).find(event => event.type === "approval_requested");
|
|
115
|
+
const deadline = performance.now() + 3000;
|
|
116
|
+
while (!findApproval() && performance.now() < deadline) await Bun.sleep(5);
|
|
117
|
+
const approval = findApproval();
|
|
118
|
+
if (!approval || approval.type !== "approval_requested") throw new Error("Expected schedule approval");
|
|
119
|
+
expect(approval.toolCallId).toBe("schedule");
|
|
120
|
+
expect(await first.client.stopIfIdle()).toEqual({ stopped: false, reason: "busy" });
|
|
121
|
+
await first.client.respondApproval(approval.requestId, "allow_once");
|
|
122
|
+
while (!events.some(event => event.event.type === "turn_ended") && performance.now() < deadline) await Bun.sleep(5);
|
|
123
|
+
expect(events.filter(event => event.event.type === "approval_requested")).toHaveLength(1);
|
|
124
|
+
expect(events.filter(event => event.event.type === "tool_call" && event.event.status === "started")).toHaveLength(1);
|
|
125
|
+
expect((await first.client.listReminders()).reminders).toMatchObject([{ text: "Check the result", channel: "alice",
|
|
126
|
+
createdBy: "agent", creatorId: "Rin", policyNames: ["ask"], state: "active" }]);
|
|
127
|
+
expect(await first.client.stopIfIdle({ ifIdle: true, unlessDueWithinMs: 300_000 })).toEqual({ stopped: false, reason: "next_due_soon" });
|
|
128
|
+
expect(await first.client.stopIfIdle({ ifIdle: true, unlessDueWithinMs: 299_999 })).toEqual({ stopped: true });
|
|
129
|
+
} finally { await first.close(); }
|
|
130
|
+
const second = spawnHarness({ home, reminderTime: now + 300_000 });
|
|
131
|
+
try {
|
|
132
|
+
await second.client.initialize();
|
|
133
|
+
const opened = await second.client.openSession({ sessionId: "s" });
|
|
134
|
+
expect(opened.reminders?.[0]).toMatchObject({ state: "done" });
|
|
135
|
+
const notice = opened.reminders?.[0]?.noticeId;
|
|
136
|
+
expect(notice).toBeDefined();
|
|
137
|
+
expect((await second.client.reconcileChannel({ channel: "alice", itemIds: [notice!] })).items).toHaveLength(1);
|
|
138
|
+
} finally { await second.close(); }
|
|
139
|
+
} finally { rmSync(home, { recursive: true, force: true }); }
|
|
140
|
+
}, 15000);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { Database } from "bun:sqlite";
|
|
3
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { createMemoryStorageAdapter } from "../src/state/storage/memory.ts";
|
|
7
|
+
import { createSqliteStorageAdapter } from "../src/state/storage/sqlite.ts";
|
|
8
|
+
import type { StorageResult } from "../src/contracts/storage.ts";
|
|
9
|
+
import type { OneOffReminderChange } from "../src/contracts/reminders.ts";
|
|
10
|
+
|
|
11
|
+
const identity = { sessionId: "reminders", compatibilityKey: "test" };
|
|
12
|
+
const instant = Date.parse("2026-11-24T12:00:00.000Z");
|
|
13
|
+
const due = new Date(instant + 120_000).toISOString();
|
|
14
|
+
|
|
15
|
+
function value<T>(result: StorageResult<T>): T {
|
|
16
|
+
if (!result.ok) throw new Error(result.error.message);
|
|
17
|
+
return result.value;
|
|
18
|
+
}
|
|
19
|
+
function create(id: string): OneOffReminderChange {
|
|
20
|
+
return { reminderId: id, changeId: 1, op: "create", payload: {
|
|
21
|
+
channel: "alpha", schedule: { at: due }, text: "Check the result", acceptedAt: new Date(instant).toISOString(),
|
|
22
|
+
} };
|
|
23
|
+
}
|
|
24
|
+
for (const kind of ["memory", "sqlite"] as const) test(`${kind}: replay and due processing preserve an atomic one-off across reopen`, () => {
|
|
25
|
+
const dir = mkdtempSync(join(tmpdir(), "reminder-state-"));
|
|
26
|
+
const path = join(dir, "s.db"), adapter = kind === "memory" ? createMemoryStorageAdapter() : createSqliteStorageAdapter(path);
|
|
27
|
+
let store = value(adapter.open({ mode: "create", identity }));
|
|
28
|
+
try {
|
|
29
|
+
value(store.close());
|
|
30
|
+
if (kind === "sqlite") {
|
|
31
|
+
using db = new Database(path);
|
|
32
|
+
expect(db.query("SELECT value FROM meta WHERE key='formatVersion'").get()).toEqual({ value: "6" });
|
|
33
|
+
expect(db.query("SELECT 1 FROM sqlite_schema WHERE name='reminder_rows'").get()).toBeNull();
|
|
34
|
+
}
|
|
35
|
+
store = value(adapter.open({ mode: "open", identity }));
|
|
36
|
+
value(store.acceptItem({ kind: "participant_message", channelId: "alpha", senderId: "Rin", itemId: "seed", text: "seed" }));
|
|
37
|
+
const first = value(store.changeReminder(create("one"), instant));
|
|
38
|
+
expect(first).toMatchObject({ outcome: "applied", reminder: { nextRunAt: due } });
|
|
39
|
+
expect(value(store.changeReminder(create("one"), instant + 10_000))).toEqual(first);
|
|
40
|
+
expect(value(store.reminderWake())).toEqual({ nextDueAt: due, reminderRevision: 1 });
|
|
41
|
+
expect(value(store.fireDueReminders(instant + 119_999))).toEqual([]);
|
|
42
|
+
expect(value(store.fireDueReminders(instant + 120_000))).toMatchObject([
|
|
43
|
+
{ channel: "alpha", event: { type: "reminder_fired", reminderId: "one", noticeId: `reminder-notice:one:${due}` } },
|
|
44
|
+
]);
|
|
45
|
+
expect(value(store.readReminder("one"))?.state).toBe("done");
|
|
46
|
+
value(store.close());
|
|
47
|
+
store = value(adapter.open({ mode: "open", identity }));
|
|
48
|
+
expect(value(store.fireDueReminders(instant + 140_000))).toEqual([]);
|
|
49
|
+
expect(value(store.reminderWake())).toEqual({ nextDueAt: null, reminderRevision: 2 });
|
|
50
|
+
expect(value(store.snapshot()).items.filter(item => item.kind === "external_notice")).toHaveLength(1);
|
|
51
|
+
expect(value(store.changeReminder({ reminderId: "one", changeId: 2, op: "cancel", payload: {} }, instant + 140_000)))
|
|
52
|
+
.toMatchObject({ outcome: "applied", alreadyQueued: true });
|
|
53
|
+
} finally { store.close(); rmSync(dir, { recursive: true, force: true }); }
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
for (const kind of ["memory", "sqlite"] as const) test(`${kind}: format activation, expiry provenance and held expiry survive archive import`, () => {
|
|
57
|
+
const dir = mkdtempSync(join(tmpdir(), "reminder-archive-"));
|
|
58
|
+
const adapterFor = (name: string) => kind === "memory" ? createMemoryStorageAdapter() : createSqliteStorageAdapter(join(dir, name));
|
|
59
|
+
const source = adapterFor("source.db"), destination = adapterFor("destination.db");
|
|
60
|
+
let store = value(source.open({ mode: "create", identity }));
|
|
61
|
+
try {
|
|
62
|
+
expect(value(store.exportArchive()).archiveVersion).toBe(5);
|
|
63
|
+
const blocked = create("blocked");
|
|
64
|
+
expect(value(store.changeReminder(blocked, instant))).toMatchObject({ outcome: "blocked", reason: "channel_missing" });
|
|
65
|
+
expect(value(store.exportArchive()).archiveVersion).toBe(6);
|
|
66
|
+
value(store.createChannel({ channelId: "alpha" }));
|
|
67
|
+
expect(value(store.changeReminder(blocked, instant))).toMatchObject({ outcome: "blocked", reason: "channel_missing" });
|
|
68
|
+
const changed: OneOffReminderChange = { ...blocked, changeId: 2, op: "create", payload: {
|
|
69
|
+
channel: "alpha", text: "corrected", schedule: { at: due }, acceptedAt: new Date(instant).toISOString(),
|
|
70
|
+
} };
|
|
71
|
+
expect(value(store.changeReminder(changed, instant))).toMatchObject({ outcome: "blocked", reason: "conflict" });
|
|
72
|
+
const seeded = create("defaulted");
|
|
73
|
+
const original = value(store.changeReminder(seeded, instant));
|
|
74
|
+
const archive = value(store.exportArchive());
|
|
75
|
+
expect(archive.archiveVersion).toBe(6);
|
|
76
|
+
value(store.close());
|
|
77
|
+
if (archive.archiveVersion !== 6 || !archive.reminderState) throw new Error("Expected reminder archive");
|
|
78
|
+
const invalid = structuredClone(archive);
|
|
79
|
+
invalid.reminderState!.rows[0]!.reminder.expiresAfter = null;
|
|
80
|
+
invalid.reminderState!.rows[0]!.reminder.expiresAt = null;
|
|
81
|
+
expect(destination.importArchive(invalid)).toMatchObject({ ok: false, error: { code: "invalid_archive" } });
|
|
82
|
+
value(destination.importArchive(archive));
|
|
83
|
+
store = value(destination.open({ mode: "open", identity }));
|
|
84
|
+
const next = new Date(instant + 600_000).toISOString();
|
|
85
|
+
expect(value(store.changeReminder({ reminderId: "defaulted", changeId: 2, op: "update", payload: {
|
|
86
|
+
schedule: { at: next }, acceptedAt: new Date(instant).toISOString(),
|
|
87
|
+
} }, instant))).toMatchObject({ outcome: "applied", reminder: { expiresAfter: 1_200_000 } });
|
|
88
|
+
expect(value(store.changeReminder(seeded, instant))).toEqual(original);
|
|
89
|
+
// A backwards wall-clock jump does not invalidate a saved acceptance anchor.
|
|
90
|
+
expect(value(store.changeReminder({ reminderId: "defaulted", changeId: 3, op: "update",
|
|
91
|
+
payload: { expiresAfter: 1_200_000 } }, instant - 60_000))).toMatchObject({ outcome: "applied", reminder: { expiresAfter: 1_200_000 } });
|
|
92
|
+
|
|
93
|
+
value(store.beginChannelSuspend("alpha"));
|
|
94
|
+
expect(value(store.fireDueReminders(instant + 600_000))).toEqual([]);
|
|
95
|
+
expect(value(store.reminderWake()).nextDueAt).toBeNull();
|
|
96
|
+
value(store.resumeChannel("alpha"));
|
|
97
|
+
expect(value(store.fireDueReminders(instant + 1_800_000))).toMatchObject([{ event: { type: "reminder_expired" } }]);
|
|
98
|
+
expect(value(store.snapshot()).items).toHaveLength(0);
|
|
99
|
+
} finally { store.close(); rmSync(dir, { recursive: true, force: true }); }
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test("SQLite: due rows are indexed, capped and leave a remaining wake across batches", () => {
|
|
103
|
+
const dir = mkdtempSync(join(tmpdir(), "reminder-batch-")), path = join(dir, "session.db");
|
|
104
|
+
const adapter = createSqliteStorageAdapter(path);
|
|
105
|
+
const store = value(adapter.open({ mode: "create", identity }));
|
|
106
|
+
try {
|
|
107
|
+
value(store.createChannel({ channelId: "alpha" }));
|
|
108
|
+
for (let index = 0; index < 101; index++) value(store.changeReminder(create(String(index)), instant));
|
|
109
|
+
const page = value(store.listReminders({ limit: 50 }));
|
|
110
|
+
expect(page.reminders).toHaveLength(50);
|
|
111
|
+
expect(page.next).toBeDefined();
|
|
112
|
+
value(store.changeReminder(create("0"), instant));
|
|
113
|
+
expect(value(store.listReminders({ after: page.next })).reminders[0]?.id).toBe("50");
|
|
114
|
+
expect(value(store.fireDueReminders(instant + 120_000))).toHaveLength(100);
|
|
115
|
+
expect(value(store.reminderWake()).nextDueAt).toBe(due);
|
|
116
|
+
expect(store.listReminders({ after: page.next })).toMatchObject({ ok: false, error: { code: "invalid_cursor" } });
|
|
117
|
+
expect(value(store.fireDueReminders(instant + 120_000))).toMatchObject([{ event: { reminderId: "100" } }]);
|
|
118
|
+
expect(value(store.reminderWake()).nextDueAt).toBeNull();
|
|
119
|
+
value(store.close());
|
|
120
|
+
using db = new Database(path);
|
|
121
|
+
const plan = db.query("EXPLAIN QUERY PLAN SELECT json FROM reminder_rows WHERE runnable_at <= ? ORDER BY runnable_at, creation_seq LIMIT 100").all(due);
|
|
122
|
+
expect(JSON.stringify(plan)).toContain("USING INDEX reminder_deadlines");
|
|
123
|
+
} finally { store.close(); rmSync(dir, { recursive: true, force: true }); }
|
|
124
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { expect, spyOn, test } from "bun:test";
|
|
2
|
+
import { createInProcessHarness, loadScenario, parseScenario } from "../src/testing.ts";
|
|
3
|
+
import { scenarioAttempt } from "../src/capabilities/model/scenario-attempt.ts";
|
|
4
|
+
import type { ModelAttemptEvent } from "../src/contracts/model-execution.ts";
|
|
5
|
+
import type { ChannelEvent } from "../src/contracts/events.ts";
|
|
6
|
+
|
|
7
|
+
const header = '{"type":"scenario","version":1,"name":"scenario"}';
|
|
8
|
+
const bytes = (text: string) => new TextEncoder().encode(text);
|
|
9
|
+
const parse = (...records: string[]) => parseScenario(bytes([header, ...records].join("\r\n") + "\r\n"), "sample.jsonl");
|
|
10
|
+
const model = (value: object) => JSON.stringify({ type: "model", ...value });
|
|
11
|
+
const send = '{"type":"send","atMs":0,"channelId":"a","participantId":"p","inputId":"i","text":"go"}';
|
|
12
|
+
|
|
13
|
+
test("scenario validation identifies bad lines, including invalid UTF-8", () => {
|
|
14
|
+
for (const record of ["", "{", '{"type":"other"}', model({ content: null, chunks: [{ afterMs: 0, text: "" }] }),
|
|
15
|
+
model({ content: "a", chunks: [{ afterMs: 0, text: "b" }] }), model({ wait: "cancel", content: "" }),
|
|
16
|
+
model({ content: "", chunks: [{ afterMs: 0, text: "" }] }),
|
|
17
|
+
model({ content: "x", usage: { outputTokens: -1 } }), model({ content: "x", delayMs: 0.5 }),
|
|
18
|
+
'{"type":"model","content":"x","extra":true}',
|
|
19
|
+
'{"type":"model","content":"x","calls":[{"name":"echo","id":"x","arguments":{"key":1,"key":2}}]}',
|
|
20
|
+
]) expect(() => parse(model({ content: "valid" }), record, model({ content: "tail" }))).toThrow("sample.jsonl:3:");
|
|
21
|
+
expect(() => parse(model({ content: "x" }), send, send)).toThrow("sample.jsonl:4: Duplicate input ID");
|
|
22
|
+
expect(() => parseScenario(bytes(header.replace('"version":1', '"version":2')), "v.jsonl")).toThrow("v.jsonl:1:");
|
|
23
|
+
expect(() => parseScenario(bytes("\uFEFF" + header), "bom.jsonl")).toThrow("bom.jsonl:1:");
|
|
24
|
+
expect(() => parseScenario(Buffer.concat([bytes(header + "\n"), Buffer.from([255])]), "utf8.jsonl")).toThrow("utf8.jsonl:2:");
|
|
25
|
+
expect(() => parse(send)).toThrow("sample.jsonl:2: Expected at least one model record");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("model digest ignores scheduling and framing but includes explicit usage and model ordering", () => {
|
|
29
|
+
const first = parse(model({ content: "a" }), send);
|
|
30
|
+
const edited = parseScenario(bytes(header.replace("scenario\"}", "edited\"}") + '\n' + model({ delayMs: 0, content: "a", calls: [], chunks: [] })));
|
|
31
|
+
expect(edited.modelDigest).toBe(first.modelDigest);
|
|
32
|
+
expect(edited.fileDigest).not.toBe(first.fileDigest);
|
|
33
|
+
expect(parse(model({ content: "a", usage: { outputTokens: 0 } })).modelDigest).not.toBe(first.modelDigest);
|
|
34
|
+
expect(parse(model({ content: "a" }), model({ content: "b" })).modelDigest).not.toBe(parse(model({ content: "b" }), model({ content: "a" })).modelDigest);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("validated playback emits usage, timed chunks and tools, and a wait aborts without a terminal", async () => {
|
|
38
|
+
const scenario = parse(model({ content: "fallback" }), model({ channelId: "a", content: "ab", chunks: [{ afterMs: 1, text: "a" }, { afterMs: 0, text: "b" }],
|
|
39
|
+
usage: { outputTokens: 2 }, calls: [{ id: "a", name: "echo", arguments: {} }] }), model({ channelId: "a", wait: "cancel" }));
|
|
40
|
+
const request = { messages: [], tools: [] };
|
|
41
|
+
const collect = async (channel: string, step: number, signal = new AbortController().signal) => {
|
|
42
|
+
const events: ModelAttemptEvent[] = [];
|
|
43
|
+
for await (const event of scenarioAttempt(scenario, channel, step)(request, signal)) events.push(event);
|
|
44
|
+
return events;
|
|
45
|
+
};
|
|
46
|
+
expect((await collect("a", 0)).map(event => event.type)).toEqual(["accepted", "usage", "text_delta", "text_delta", "response"]);
|
|
47
|
+
expect((await collect("a", 0)).at(-1)).toMatchObject({ response: { stopReason: "tool_calls" } });
|
|
48
|
+
expect((await collect("b", 0)).at(-1)).toMatchObject({ response: { content: "fallback" } });
|
|
49
|
+
expect(await collect("b", 1)).toEqual([{ type: "failure", kind: "provider", message: "script_exhausted" }]);
|
|
50
|
+
const abort = new AbortController();
|
|
51
|
+
const iterator = scenarioAttempt(scenario, "a", 1)(request, abort.signal)[Symbol.asyncIterator]();
|
|
52
|
+
expect(await iterator.next()).toMatchObject({ value: { type: "accepted" }, done: false });
|
|
53
|
+
const pending = iterator.next(); abort.abort();
|
|
54
|
+
expect((await pending).done).toBe(true);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("one scenario is loaded across channel positions and capture off does not clone a diagnostic request", async () => {
|
|
58
|
+
let loaded = 0, requestCopies = 0;
|
|
59
|
+
const clone = globalThis.structuredClone;
|
|
60
|
+
const observe = spyOn(globalThis, "structuredClone").mockImplementation(value => {
|
|
61
|
+
if (value && typeof value === "object" && "messages" in value && "takenItemIds" in value) requestCopies++;
|
|
62
|
+
return clone(value);
|
|
63
|
+
});
|
|
64
|
+
const scenario = parse(model({ content: "default" }), model({ channelId: "a", content: "specific" }));
|
|
65
|
+
const harness = createInProcessHarness({ scenarioLoader: async () => { loaded++; return scenario; } });
|
|
66
|
+
const events: ChannelEvent[] = [];
|
|
67
|
+
harness.client.onChannelEvent(event => events.push(event));
|
|
68
|
+
try {
|
|
69
|
+
await harness.client.initialize();
|
|
70
|
+
await harness.client.createSession({ sessionId: "scenario", participants: [], channels: {}, config: {
|
|
71
|
+
version: 1, system: "test", model: { protocol: "scripted", script: "seam.jsonl" },
|
|
72
|
+
defaultPolicy: "open", policies: { open: { fallback: "allow", tools: {} } },
|
|
73
|
+
} });
|
|
74
|
+
for (const [index, channel] of ["a", "b", "c", "b"].entries()) {
|
|
75
|
+
await harness.client.push({ channel, item: { id: String(index), kind: "user_message", sender: "p", content: [{ type: "text", text: "go" }] } });
|
|
76
|
+
for (let wait = 0; wait < 100 && events.filter(({ event }) => event.type === "turn_ended").length <= index; wait++) await Bun.sleep(5);
|
|
77
|
+
}
|
|
78
|
+
expect(loaded).toBe(1);
|
|
79
|
+
expect(harness.models.size).toBe(0);
|
|
80
|
+
expect(requestCopies).toBe(8); // one frozen request plus one adapter copy per call
|
|
81
|
+
expect(events.flatMap(({ event }) => event.type === "message_completed" ? event.parts?.map(part => part.text) ?? [] : []))
|
|
82
|
+
.toEqual(["specific", "default", "default"]);
|
|
83
|
+
expect(events.at(-1)?.event).toMatchObject({ type: "turn_ended", outcome: "failed", error: "script_exhausted" });
|
|
84
|
+
expect((await harness.client.modelCalls()).calls.at(-1)?.attempts[0]?.outcome).toBe("provider_failure");
|
|
85
|
+
} finally { harness.close(); observe.mockRestore(); }
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test("the checked-in echo fixture is JSONL", async () => {
|
|
89
|
+
const scenario = await loadScenario(new URL("./fixtures/echo-scenario.jsonl", import.meta.url).pathname);
|
|
90
|
+
expect(scenario.defaultModels[0]?.calls?.[0]?.name).toBe("echo");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test("a transient retry reserves the next record and keeps the boundary inputs", async () => {
|
|
94
|
+
const scenario = parse(model({ failure: { kind: "transient", message: "retry me" } }), model({ content: "after retry" }));
|
|
95
|
+
const harness = createInProcessHarness({ scenarioLoader: async () => scenario, captureRequests: true });
|
|
96
|
+
try {
|
|
97
|
+
await harness.client.initialize();
|
|
98
|
+
await harness.client.createSession({ sessionId: "retry", participants: [], channels: {}, config: {
|
|
99
|
+
version: 1, system: "test", model: { protocol: "scripted", script: "retry.jsonl" },
|
|
100
|
+
defaultPolicy: "open", policies: { open: { fallback: "allow", tools: {} } },
|
|
101
|
+
} });
|
|
102
|
+
const completed: string[] = [];
|
|
103
|
+
harness.client.onChannelEvent(({ event }) => { if (event.type === "message_completed") completed.push(event.parts![0]!.text); });
|
|
104
|
+
await harness.client.push({ channel: "a", item: { id: "input", kind: "user_message", sender: "p", content: [{ type: "text", text: "go" }] } });
|
|
105
|
+
for (let wait = 0; wait < 500 && !completed.length; wait++) await Bun.sleep(5);
|
|
106
|
+
expect(completed).toEqual(["after retry"]);
|
|
107
|
+
expect(harness.models.get("a")?.map(request => request.takenItemIds)).toEqual([["input"], ["input"]]);
|
|
108
|
+
expect((await harness.client.modelCalls()).calls[0]?.attempts).toMatchObject([
|
|
109
|
+
{ ordinal: 0, scriptStep: 0, outcome: "transient_failure" }, { ordinal: 1, scriptStep: 1, outcome: "succeeded" },
|
|
110
|
+
]);
|
|
111
|
+
} finally { harness.close(); }
|
|
112
|
+
});
|