@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,20 @@
|
|
|
1
|
+
// Child process for SQLite ownership and crash tests. Holds a real owner,
|
|
2
|
+
// commits a known amount of work, reports readiness, then waits to be killed.
|
|
3
|
+
import { createSqliteStorageAdapter } from "../../src/state/storage/sqlite.ts";
|
|
4
|
+
|
|
5
|
+
const [path, mode] = process.argv.slice(2);
|
|
6
|
+
const opened = createSqliteStorageAdapter(path!).open({ mode: "create", identity: { sessionId: "s1", compatibilityKey: "k1" } });
|
|
7
|
+
if (!opened.ok) { console.log(`error ${opened.error.code}`); process.exit(1); }
|
|
8
|
+
const s = opened.value;
|
|
9
|
+
s.acceptItem({ itemId: "taken", kind: "participant_message", channelId: "c1", senderId: "ana", text: "run the tool" });
|
|
10
|
+
const begun = s.beginTurn("c1");
|
|
11
|
+
if (!begun.ok || !begun.value) process.exit(1);
|
|
12
|
+
const turnId = begun.value.turn.turnId;
|
|
13
|
+
s.appendMessage(turnId, { role: "assistant", content: null, calls: [{ id: "done", name: "echo", arguments: "{}" }, { id: "effect", name: "echo", arguments: "{}" }] });
|
|
14
|
+
s.markToolDispatched(turnId, "done");
|
|
15
|
+
s.appendMessage(turnId, { role: "tool", callId: "done", content: "recorded" });
|
|
16
|
+
s.markToolDispatched(turnId, "effect");
|
|
17
|
+
s.acceptItem({ itemId: "pending", kind: "participant_message", channelId: "c1", senderId: "ana", text: "never taken" });
|
|
18
|
+
if (mode === "suspending") s.beginSuspend();
|
|
19
|
+
console.log("ready");
|
|
20
|
+
setInterval(() => {}, 1000);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { formatReply } from "../src/interfaces/cli/format-reply.ts";
|
|
3
|
+
|
|
4
|
+
test("terminal prose renders emphasis and bullets while fenced code retains literal markers", () => {
|
|
5
|
+
const text = formatReply('**Exercise status:** `completed`\n- **Done**\n\n```ts\nconst pattern = "**literal**";\n```', false);
|
|
6
|
+
expect(text).toContain("Exercise status: completed\n• Done");
|
|
7
|
+
expect(text).toContain('const pattern = "**literal**";');
|
|
8
|
+
expect(text).not.toContain("```");
|
|
9
|
+
expect(formatReply("**Done**", true)).toBe("\x1b[1mDone\x1b[0m");
|
|
10
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { HarnessClient, LoadResult, StoredMessage } from "../../src/client.ts";
|
|
2
|
+
|
|
3
|
+
/** Test-only reconstruction for fixtures which assert on several independent
|
|
4
|
+
* views. Production open leaves history fetching to the consumer. */
|
|
5
|
+
export async function inspectOperatorView(client: HarnessClient, params: Parameters<HarnessClient["openSession"]>[0]): Promise<LoadResult> {
|
|
6
|
+
const opened = await client.openSession(params);
|
|
7
|
+
const status = await client.status();
|
|
8
|
+
const items: LoadResult["items"] = [], turns: LoadResult["turns"] = [];
|
|
9
|
+
const takenOrder = new Map<string, number>();
|
|
10
|
+
const messages: { message: StoredMessage; seq: number }[] = [];
|
|
11
|
+
for (const channel of status.channels) {
|
|
12
|
+
const itemIds = new Set(channel.pending), turnIds = new Set<string>();
|
|
13
|
+
if (channel.activeTurn) turnIds.add(channel.activeTurn.turnId);
|
|
14
|
+
if (channel.unresolved) turnIds.add(channel.unresolved.turnId);
|
|
15
|
+
let cursor: string | undefined;
|
|
16
|
+
do {
|
|
17
|
+
const page = await client.channelMessages(cursor ? { channel: channel.channel, cursor } : { channel: channel.channel });
|
|
18
|
+
for (const message of page.messages) {
|
|
19
|
+
turnIds.add(message.turnId);
|
|
20
|
+
if (message.itemId) {
|
|
21
|
+
itemIds.add(message.itemId);
|
|
22
|
+
const [, , seq] = JSON.parse(Buffer.from(message.position, "base64url").toString()) as [string, string, number];
|
|
23
|
+
takenOrder.set(message.itemId, seq);
|
|
24
|
+
}
|
|
25
|
+
else if (!("omitted" in message)) {
|
|
26
|
+
const { position, actor: _actor, ...wire } = message;
|
|
27
|
+
const [, , seq] = JSON.parse(Buffer.from(position, "base64url").toString()) as [string, string, number];
|
|
28
|
+
messages.push({ message: wire, seq });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
cursor = page.next;
|
|
32
|
+
} while (cursor);
|
|
33
|
+
const tracked = await client.reconcileChannel({ channel: channel.channel, itemIds: [...itemIds], turnIds: [...turnIds] });
|
|
34
|
+
items.push(...tracked.items);
|
|
35
|
+
turns.push(...tracked.turns.map(turn => ({ ...turn, items: tracked.items.filter(item => item.turnId === turn.turnId).sort((a, b) => (takenOrder.get(a.id) ?? Infinity) - (takenOrder.get(b.id) ?? Infinity)).map(item => item.id) })));
|
|
36
|
+
}
|
|
37
|
+
const linked = new Map(turns.map(turn => [turn.turnId, turn]));
|
|
38
|
+
return { status, items: items.sort((a, b) => (takenOrder.get(a.id) ?? Infinity) - (takenOrder.get(b.id) ?? Infinity)), turns: [...linked.values()].sort((a, b) => Number(a.turnId) - Number(b.turnId)),
|
|
39
|
+
messages: messages.sort((a, b) => a.seq - b.seq).map(value => value.message),
|
|
40
|
+
...(opened.channelChanges ? { channelChanges: opened.channelChanges } : {}) };
|
|
41
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ScenarioModelRecord } from "../../src/contracts/scenario.ts";
|
|
2
|
+
|
|
3
|
+
type WithoutType<Record> = Record extends ScenarioModelRecord ? Omit<Record, "type"> : never;
|
|
4
|
+
export type ModelScenarioStep = WithoutType<ScenarioModelRecord>;
|
|
5
|
+
|
|
6
|
+
export function modelScenario(responses: readonly ModelScenarioStep[], name = "test"): string {
|
|
7
|
+
return [{ type: "scenario", version: 1, name }, ...responses.map(response => ({ type: "model", ...response }))]
|
|
8
|
+
.map(record => JSON.stringify(record)).join("\n") + "\n";
|
|
9
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ChannelEvent } from "../../src/contracts/events.ts";
|
|
2
|
+
import type { ChannelInput } from "../../src/contracts/agent.ts";
|
|
3
|
+
import type { Message } from "../../src/contracts/loop.ts";
|
|
4
|
+
import type { PersistentSession } from "../../src/contracts/session.ts";
|
|
5
|
+
|
|
6
|
+
/** Text of the newest input in a request, without its attribution prefix. */
|
|
7
|
+
export function lastInput(messages: readonly Message[]): string {
|
|
8
|
+
const content = messages.findLast(message => message.role === "user")?.content ?? "";
|
|
9
|
+
return content.startsWith("Participant: ") ? content.slice(content.indexOf("\n\n") + 2) : content.slice(content.indexOf("\n") + 1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Collect events until `count` turns have ended. */
|
|
13
|
+
export function turnsEnd(session: Pick<PersistentSession, "subscribe">, count = 1) {
|
|
14
|
+
const events: ChannelEvent[] = [];
|
|
15
|
+
let resolve!: (events: ChannelEvent[]) => void;
|
|
16
|
+
const done = new Promise<ChannelEvent[]>(r => { resolve = r; });
|
|
17
|
+
const stop = session.subscribe(event => {
|
|
18
|
+
events.push(event);
|
|
19
|
+
if (events.filter(e => e.event.type === "turn_ended").length === count) { stop(); resolve(events); }
|
|
20
|
+
});
|
|
21
|
+
return { events, done };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Test-only correlation: send, then follow the turn that took the item. */
|
|
25
|
+
export async function ask(session: PersistentSession, input: ChannelInput): Promise<string> {
|
|
26
|
+
let turnId: string | undefined, answer = "", itemId = "";
|
|
27
|
+
return new Promise<string>((resolve, reject) => {
|
|
28
|
+
const stop = session.subscribe(({ event }) => {
|
|
29
|
+
if ((event.type === "turn_started" || event.type === "turn_took") && event.items.includes(itemId)) turnId = event.turnId;
|
|
30
|
+
if (turnId === undefined || !("turnId" in event) || event.turnId !== turnId) return;
|
|
31
|
+
if (event.type === "message_completed") answer = (event.parts ?? []).map(part => part.text).join("");
|
|
32
|
+
if (event.type === "turn_ended") { stop(); event.outcome === "completed" ? resolve(answer) : reject(new Error(event.error ?? event.outcome)); }
|
|
33
|
+
});
|
|
34
|
+
const accepted = session.agent.send(input);
|
|
35
|
+
if (!accepted.accepted) { stop(); reject(new Error(accepted.error)); return; }
|
|
36
|
+
itemId = accepted.itemId;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { HarnessClient, createStdioTransport } from "../../src/client.ts";
|
|
2
|
+
import type { ClientTransport, RpcNotification, RpcResponse } from "../../src/contracts/protocol.ts";
|
|
3
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
/** Record everything the transport delivers, in wire order. A client resolves
|
|
8
|
+
* responses a microtask after listeners run, so only this log shows the order
|
|
9
|
+
* in which a response and the notifications around it actually arrived. */
|
|
10
|
+
export function recordWire(transport: ClientTransport) {
|
|
11
|
+
const wire: (RpcResponse | RpcNotification)[] = [];
|
|
12
|
+
transport.subscribe(message => { wire.push(message); });
|
|
13
|
+
return wire;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface SpawnOptions { home?: string; fault?: string; effects?: string; requests?: string; stallChannel?: string; snapshotLog?: string; streamResponses?: boolean; modelTimeoutMs?: number; reminderTime?: number }
|
|
17
|
+
export function spawnHarness(options: SpawnOptions = {}) {
|
|
18
|
+
const temporaryHome = options.home ? undefined : mkdtempSync(join(tmpdir(), "harness-stdio-"));
|
|
19
|
+
const child = Bun.spawn([process.execPath, new URL("../../src/interfaces/cli/main.ts", import.meta.url).pathname, "serve", "--stdio",
|
|
20
|
+
"--home", options.home ?? temporaryHome!], {
|
|
21
|
+
stdin: "pipe", stdout: "pipe", stderr: "pipe",
|
|
22
|
+
env: { ...process.env, OPENROUTER_API_KEY: undefined, HARNESS_TEST_FAULT: options.fault, HARNESS_TEST_EFFECTS: options.effects, HARNESS_TEST_REQUESTS: options.requests, HARNESS_TEST_STALL_CHANNEL: options.stallChannel, HARNESS_TEST_SNAPSHOT_LOG: options.snapshotLog, HARNESS_TEST_STREAM_RESPONSES: options.streamResponses ? "1" : undefined, HARNESS_TEST_MODEL_TIMEOUT_MS: options.modelTimeoutMs?.toString(), HARNESS_TEST_REMINDER_TIME: options.reminderTime?.toString() },
|
|
23
|
+
});
|
|
24
|
+
const [protocol, capture] = child.stdout.tee();
|
|
25
|
+
const stdout = new Response(capture).text();
|
|
26
|
+
const stderr = new Response(child.stderr).text();
|
|
27
|
+
const transport = createStdioTransport({ readable: protocol, exited: child.exited,
|
|
28
|
+
async write(bytes) { child.stdin.write(bytes); await child.stdin.flush(); },
|
|
29
|
+
async end() { await child.stdin.end(); },
|
|
30
|
+
});
|
|
31
|
+
const wire = recordWire(transport);
|
|
32
|
+
const client = new HarnessClient(transport, 2000);
|
|
33
|
+
if (temporaryHome) void child.exited.then(() => rmSync(temporaryHome, { recursive: true, force: true }));
|
|
34
|
+
return {
|
|
35
|
+
client, child, stdout, stderr, wire,
|
|
36
|
+
async close() {
|
|
37
|
+
client.close();
|
|
38
|
+
const timer = setTimeout(() => child.kill("SIGKILL"), 2000);
|
|
39
|
+
try {
|
|
40
|
+
const code = await child.exited;
|
|
41
|
+
if (code !== 0) throw new Error(`Harness exit ${code}: ${await stderr}`);
|
|
42
|
+
for (const line of (await stdout).trim().split("\n").filter(Boolean)) JSON.parse(line);
|
|
43
|
+
} finally { clearTimeout(timer); child.kill(); }
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { expect, spyOn, test } from "bun:test";
|
|
2
|
+
import { createInspection } from "../src/interfaces/inspector/state.ts";
|
|
3
|
+
import { serveInspector } from "../src/interfaces/inspector/server.ts";
|
|
4
|
+
import { createSession } from "../src/index.ts";
|
|
5
|
+
import { observeSession } from "../src/interfaces/inspector/observe.ts";
|
|
6
|
+
import { createMemoryStorageAdapter } from "../src/state/storage/memory.ts";
|
|
7
|
+
import { ask } from "./helpers/session.ts";
|
|
8
|
+
|
|
9
|
+
function fixture() {
|
|
10
|
+
const opened = createMemoryStorageAdapter().open({ mode: "create", identity: { sessionId: "inspector", compatibilityKey: "" } });
|
|
11
|
+
if (!opened.ok) throw new Error(opened.error.message);
|
|
12
|
+
const storage = opened.value;
|
|
13
|
+
const session = createSession({ systemPrompt: "system", storage,
|
|
14
|
+
configureTurn: () => ({ tools: [], executeTool: async () => "unused",
|
|
15
|
+
model: async () => ({ role: "assistant", calls: [], content: "ok" }) }) });
|
|
16
|
+
const inspection = createInspection("system", [], storage, "memory");
|
|
17
|
+
const observer = observeSession(session, inspection);
|
|
18
|
+
return { storage, inspection, session, observer };
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
test("the inspector invalidates without reading storage and fetches only the requested view", async () => {
|
|
22
|
+
const { storage, inspection, session, observer } = fixture();
|
|
23
|
+
const full = spyOn(storage, "snapshot"), status = spyOn(storage, "readInspectionStatus");
|
|
24
|
+
const page = spyOn(storage, "readInspectionPage"), calls = spyOn(storage, "readInspectionCalls");
|
|
25
|
+
const server = serveInspector(inspection, 0);
|
|
26
|
+
const request = (path: string) => fetch(new URL(path, server.url));
|
|
27
|
+
let cancel = async () => {};
|
|
28
|
+
try {
|
|
29
|
+
expect(await (await request("/")).text()).toContain("Harness context inspector");
|
|
30
|
+
expect((await fetch(new URL("/state", server.url), { method: "POST" })).status).toBe(405);
|
|
31
|
+
const events = await request("/events");
|
|
32
|
+
const reader = events.body!.getReader();
|
|
33
|
+
cancel = () => reader.cancel();
|
|
34
|
+
const decode = new TextDecoder();
|
|
35
|
+
expect(decode.decode((await reader.read()).value)).toBe("data: changed\n\n");
|
|
36
|
+
observer.agent.send({ channelId: "a", participantId: "alice", text: "early", itemId: "early" });
|
|
37
|
+
expect(decode.decode((await reader.read()).value)).toBe("data: changed\n\n");
|
|
38
|
+
expect(status).not.toHaveBeenCalled();
|
|
39
|
+
expect(page).not.toHaveBeenCalled();
|
|
40
|
+
expect(calls).not.toHaveBeenCalled();
|
|
41
|
+
expect(await (await request("/state")).json()).toMatchObject({ channels: [{ id: "a", pending: 1, running: false }] });
|
|
42
|
+
expect(status).toHaveBeenCalledTimes(1);
|
|
43
|
+
expect(page).not.toHaveBeenCalled();
|
|
44
|
+
session.start();
|
|
45
|
+
await ask(session, { channelId: "b", participantId: "bob", text: "second" });
|
|
46
|
+
expect((await (await request("/context")).json() as ReturnType<typeof inspection.liveContext>).base[1]!.content).toContain("second");
|
|
47
|
+
expect((await (await request("/timeline")).json() as ReturnType<typeof inspection.timeline>).entries[0]).toMatchObject({ channelId: "b", message: { role: "assistant" } });
|
|
48
|
+
expect((await request("/timeline?before=0")).status).toBe(400);
|
|
49
|
+
expect(await (await request("/channel?id=b")).json()).toEqual({ requests: [] });
|
|
50
|
+
expect(calls).not.toHaveBeenCalled();
|
|
51
|
+
expect((await (await request("/calls?id=b")).json() as ReturnType<typeof inspection.modelCalls>).modelCalls).toHaveLength(1);
|
|
52
|
+
expect(calls).toHaveBeenCalledTimes(1);
|
|
53
|
+
expect(full).not.toHaveBeenCalled();
|
|
54
|
+
await reader.cancel();
|
|
55
|
+
const reconnected = (await request("/events")).body!.getReader();
|
|
56
|
+
cancel = () => reconnected.cancel();
|
|
57
|
+
expect(decode.decode((await reconnected.read()).value)).toBe("data: changed\n\n");
|
|
58
|
+
expect((await (await request("/state")).json() as ReturnType<typeof inspection.status>).session.execution).toBe("idle");
|
|
59
|
+
} finally {
|
|
60
|
+
await cancel(); await server.stop(true); observer.stop(); storage.close();
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("inspector captures remain detached and bounded per channel", () => {
|
|
65
|
+
const { inspection, observer, storage } = fixture();
|
|
66
|
+
const message = { role: "assistant" as const, content: "B answer", calls: [] };
|
|
67
|
+
for (let i = 0; i < 12; i++) inspection.request("a", JSON.stringify({ messages: [], tools: [] }), i);
|
|
68
|
+
inspection.request("b", "x".repeat(150_000), 2);
|
|
69
|
+
inspection.response("b", message);
|
|
70
|
+
message.content = "mutated";
|
|
71
|
+
const a = inspection.channel("a"), b = inspection.channel("b");
|
|
72
|
+
expect(a.requests.map(request => request.number)).toEqual([5, 6, 7, 8, 9, 10, 11, 12]);
|
|
73
|
+
a.requests.pop();
|
|
74
|
+
expect(inspection.channel("a").requests).toHaveLength(8);
|
|
75
|
+
expect(b.requests[0]).toMatchObject({ turnId: 2, body: { omitted: true }, response: { content: "B answer" } });
|
|
76
|
+
observer.stop(); storage.close();
|
|
77
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { lstatSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { bindLocalSocket, bindWebPort } from "../src/interfaces/cli/listeners.ts";
|
|
6
|
+
|
|
7
|
+
test("stale Unix socket recovery preserves regular files and refuses a live listener", async () => {
|
|
8
|
+
const directory = mkdtempSync(join(tmpdir(), "harness-listeners-"));
|
|
9
|
+
const path = join(directory, "agent.sock");
|
|
10
|
+
const fetch = () => new Response("ready");
|
|
11
|
+
const bind = () => Bun.serve({ unix: path, fetch });
|
|
12
|
+
let listener: ReturnType<typeof bind> | undefined;
|
|
13
|
+
try {
|
|
14
|
+
writeFileSync(path, "keep");
|
|
15
|
+
await expect(bindLocalSocket(path, bind)).rejects.toThrow("occupied");
|
|
16
|
+
expect(readFileSync(path, "utf8")).toBe("keep");
|
|
17
|
+
rmSync(path);
|
|
18
|
+
const child = Bun.spawn([process.execPath, "-e",
|
|
19
|
+
'Bun.serve({unix: process.argv[1], fetch: () => new Response("child")}); console.log("ready");', path],
|
|
20
|
+
{ stdout: "pipe" });
|
|
21
|
+
const reader = child.stdout.getReader();
|
|
22
|
+
try { expect(new TextDecoder().decode((await reader.read()).value).trim()).toBe("ready"); }
|
|
23
|
+
finally { await reader.cancel(); child.kill("SIGKILL"); await child.exited; }
|
|
24
|
+
expect(lstatSync(path).isSocket()).toBe(true);
|
|
25
|
+
|
|
26
|
+
const attempts = await Promise.allSettled([bindLocalSocket(path, bind), bindLocalSocket(path, bind)]);
|
|
27
|
+
const started = attempts.filter(result => result.status === "fulfilled");
|
|
28
|
+
expect(started).toHaveLength(1);
|
|
29
|
+
listener = started[0]!.value;
|
|
30
|
+
await expect(bindLocalSocket(path, bind)).rejects.toThrow("already listens");
|
|
31
|
+
expect(await (await globalThis.fetch("http://localhost", { unix: path })).text()).toBe("ready");
|
|
32
|
+
} finally { await listener?.stop(true); rmSync(directory, { recursive: true, force: true }); }
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("occupied browser defaults fall back and explicit ports report the setting", async () => {
|
|
36
|
+
const bind = (port: number) => Bun.serve({ hostname: "127.0.0.1", port, fetch: () => new Response() });
|
|
37
|
+
const occupied = bind(0);
|
|
38
|
+
const variable = "HARNESS_TEST_EXPLICIT_PORT";
|
|
39
|
+
const fallback = bindWebPort(occupied.port!, variable, bind);
|
|
40
|
+
try {
|
|
41
|
+
expect(fallback.port).not.toBe(occupied.port);
|
|
42
|
+
process.env[variable] = String(occupied.port);
|
|
43
|
+
expect(() => bindWebPort(occupied.port!, variable, bind)).toThrow(`Set ${variable}=0`);
|
|
44
|
+
} finally {
|
|
45
|
+
delete process.env[variable];
|
|
46
|
+
await fallback.stop(true);
|
|
47
|
+
await occupied.stop(true);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import type { Message, Model } from "../src/contracts/loop.ts";
|
|
3
|
+
import { runTurn } from "../src/kernel/loop.ts";
|
|
4
|
+
import { openRouter } from "../src/capabilities/model/openrouter.ts";
|
|
5
|
+
import type { ExecuteTurnTool, ToolCall } from "../src/contracts/loop.ts";
|
|
6
|
+
|
|
7
|
+
const dispatchTool = async (call: ToolCall, execute: ExecuteTurnTool) => {
|
|
8
|
+
const result = await execute(call);
|
|
9
|
+
return { ...(typeof result === "string" ? { content: result } : result), dispatched: true };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
test("continues through multiple tools and retains history for the next turn", async () => {
|
|
13
|
+
const messages: Message[] = [{ role: "system", content: "Test" }];
|
|
14
|
+
let calls = 0;
|
|
15
|
+
const model: Model = async (history) => {
|
|
16
|
+
calls++;
|
|
17
|
+
if (calls === 1) return {
|
|
18
|
+
role: "assistant", content: null,
|
|
19
|
+
calls: [{ id: "a", name: "clock", arguments: "{}" }, { id: "b", name: "unknown", arguments: "{}" }],
|
|
20
|
+
};
|
|
21
|
+
if (calls === 2) {
|
|
22
|
+
expect(history.slice(-2)).toEqual([
|
|
23
|
+
{ role: "tool", callId: "a", content: "time" },
|
|
24
|
+
{ role: "tool", callId: "b", content: "not allowed" },
|
|
25
|
+
]);
|
|
26
|
+
} else {
|
|
27
|
+
expect(history.some((m) => m.content === "Done")).toBe(true);
|
|
28
|
+
}
|
|
29
|
+
return { role: "assistant", content: "Done", calls: [] };
|
|
30
|
+
};
|
|
31
|
+
const execute = async (call: { name: string }) => call.name === "clock" ? "time" : "not allowed";
|
|
32
|
+
const context = { append: (message: Message) => { messages.push(message); }, dispatchTool };
|
|
33
|
+
messages.push({ role: "user", content: "First" });
|
|
34
|
+
const infer = async (signal?: AbortSignal) => { const answer = await model(structuredClone(messages), [], signal); context.append(answer); return answer; };
|
|
35
|
+
expect(await runTurn(context, infer, execute)).toBe("completed");
|
|
36
|
+
messages.push({ role: "user", content: "Second" });
|
|
37
|
+
expect(await runTurn(context, infer, execute)).toBe("completed");
|
|
38
|
+
expect(messages.at(-1)).toEqual({ role: "assistant", content: "Done", calls: [] });
|
|
39
|
+
expect(calls).toBe(3);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("the loop checkpoints at a boundary instead of inferring, and an aborted turn records nothing more", async () => {
|
|
43
|
+
const recorded: Message[] = [];
|
|
44
|
+
let boundaries = 0, inferences = 0;
|
|
45
|
+
const outcome = await runTurn({
|
|
46
|
+
append: message => { recorded.push(message); }, dispatchTool,
|
|
47
|
+
// Suspension is requested while the first iteration's tool is running.
|
|
48
|
+
checkpoint: () => ++boundaries === 2,
|
|
49
|
+
}, async () => { inferences++; const answer: Message & { role: "assistant" } = { role: "assistant", content: null, calls: [{ id: "a", name: "clock", arguments: "{}" }] }; recorded.push(answer); return answer; }, async () => "time");
|
|
50
|
+
expect(outcome).toBe("suspended");
|
|
51
|
+
expect(inferences).toBe(1);
|
|
52
|
+
expect(recorded.map(message => message.role)).toEqual(["assistant", "tool"]);
|
|
53
|
+
|
|
54
|
+
const abort = new AbortController(), late: Message[] = [];
|
|
55
|
+
const stopped = runTurn({ append: message => { late.push(message); }, signal: abort.signal, dispatchTool },
|
|
56
|
+
async signal => { expect(signal).toBe(abort.signal); abort.abort(new Error("stopped")); return { role: "assistant", content: "late", calls: [] }; },
|
|
57
|
+
async () => "unused");
|
|
58
|
+
await expect(stopped).rejects.toThrow("stopped");
|
|
59
|
+
expect(late).toEqual([]);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("OpenRouter maps neutral messages and preserves opaque assistant state", async () => {
|
|
63
|
+
const original = globalThis.fetch;
|
|
64
|
+
const raw = {
|
|
65
|
+
role: "assistant", content: null, reasoning_details: [{ opaque: "preserve" }],
|
|
66
|
+
tool_calls: [{ id: "a", type: "function", function: { name: "clock", arguments: "{}" } }],
|
|
67
|
+
};
|
|
68
|
+
const bodies: any[] = [];
|
|
69
|
+
globalThis.fetch = (async (_url: unknown, init: RequestInit) => {
|
|
70
|
+
bodies.push(JSON.parse(init.body as string));
|
|
71
|
+
return Response.json({ choices: [{ finish_reason: "tool_calls", message: raw }] });
|
|
72
|
+
}) as typeof fetch;
|
|
73
|
+
try {
|
|
74
|
+
const observed: unknown[] = [];
|
|
75
|
+
const model = openRouter("fake-key", "test-model", (body) => observed.push(JSON.parse(body)));
|
|
76
|
+
const tools = [{ name: "clock", description: "Time", parameters: { type: "object" } }];
|
|
77
|
+
const first = await model([{ role: "user", content: "Time?" }], tools);
|
|
78
|
+
expect(first.calls).toEqual([{ id: "a", name: "clock", arguments: "{}" }]);
|
|
79
|
+
await model([first, { role: "tool", callId: "a", content: "now" }], tools);
|
|
80
|
+
expect(bodies[1]).toEqual({
|
|
81
|
+
model: "test-model",
|
|
82
|
+
messages: [raw, { role: "tool", tool_call_id: "a", content: "now" }],
|
|
83
|
+
tools: [{ type: "function", function: tools[0] }],
|
|
84
|
+
});
|
|
85
|
+
expect(observed).toEqual(bodies);
|
|
86
|
+
expect(JSON.stringify(observed)).not.toContain("fake-key");
|
|
87
|
+
} finally { globalThis.fetch = original; }
|
|
88
|
+
});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { createSession } from "../src/index.ts";
|
|
3
|
+
import { createMemoryStorageAdapter } from "../src/state/storage/memory.ts";
|
|
4
|
+
import type { SessionStorage } from "../src/contracts/storage.ts";
|
|
5
|
+
import type { ChannelEvent } from "../src/contracts/events.ts";
|
|
6
|
+
|
|
7
|
+
const until = async (fn: () => boolean) => { for (let i = 0; i < 400; i++) { if (fn()) return; await new Promise(resolve => setTimeout(resolve, 5)); } throw new Error("timed out"); };
|
|
8
|
+
|
|
9
|
+
/** Stage 2 stand-in: real scheduler and existing memory lifecycle, with only the
|
|
10
|
+
* new model-call transactions doubled. Stage 3 tests the real adapters. */
|
|
11
|
+
function callStoreDouble(base: SessionStorage): SessionStorage {
|
|
12
|
+
let next = 0;
|
|
13
|
+
const calls = new Map<string, { turn: number; message: string }>();
|
|
14
|
+
return Object.assign(base, {
|
|
15
|
+
startCall(turn: string) { const id = String(++next), call = { turn: Number(turn), message: `m${id}` }; calls.set(id, call);
|
|
16
|
+
return { ok: true, revision: 0, value: { callId: id, messageId: call.message } }; },
|
|
17
|
+
startAttempt(id: string) { return { ok: true, revision: 0, value: { attemptId: `a${id}` } }; },
|
|
18
|
+
recordProviderRequestId() { return { ok: true, revision: 0, value: undefined }; },
|
|
19
|
+
confirm(id: string, _attempt: string, milestone: "delivered" | "seen") {
|
|
20
|
+
const result = base.confirmReceipts(calls.get(id)!.turn, milestone);
|
|
21
|
+
return result.ok ? { ...result, value: result.value.map(item => item.itemId) } : result;
|
|
22
|
+
},
|
|
23
|
+
recordUsage() { return { ok: true, revision: 0, value: undefined }; },
|
|
24
|
+
finishAttempt() { return { ok: true, revision: 0, value: undefined }; },
|
|
25
|
+
finishCall() { return { ok: true, revision: 0, value: undefined }; },
|
|
26
|
+
commitResponse(id: string, _attempt: string, response: { role: "assistant"; content: string | null; calls: [] }) {
|
|
27
|
+
return base.appendMessage(calls.get(id)!.turn, { role: "assistant", content: response.content, calls: response.calls });
|
|
28
|
+
},
|
|
29
|
+
}) as SessionStorage;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
test("interrupt ends one turn and the same channel takes and completes later work", async () => {
|
|
33
|
+
const opened = createMemoryStorageAdapter().open({ mode: "create", identity: { sessionId: "stage2-double", compatibilityKey: "key" } });
|
|
34
|
+
if (!opened.ok) throw new Error(opened.error.message);
|
|
35
|
+
const storage = callStoreDouble(opened.value), events: ChannelEvent[] = [];
|
|
36
|
+
let runs = 0, release!: () => void;
|
|
37
|
+
const session = createSession({ systemPrompt: "test", storage, configureTurn() {
|
|
38
|
+
return { tools: [], executeTool: async () => "unused", model: async () => {
|
|
39
|
+
if (++runs === 1) { await new Promise<void>(resolve => { release = resolve; }); return { role: "assistant", content: "late", calls: [] }; }
|
|
40
|
+
return { role: "assistant", content: "fresh", calls: [] };
|
|
41
|
+
} };
|
|
42
|
+
} });
|
|
43
|
+
session.subscribe(e => events.push(e)); session.start();
|
|
44
|
+
expect(session.agent.send({ channelId: "alice", participantId: "a", itemId: "first", text: "one" }).accepted).toBe(true);
|
|
45
|
+
await until(() => runs === 1);
|
|
46
|
+
const turn = events.find(e => e.event.type === "turn_started")!.event;
|
|
47
|
+
if (turn.type !== "turn_started") throw new Error("missing turn");
|
|
48
|
+
expect(session.channels.interrupt("alice", Number(turn.turnId)).ok).toBe(true);
|
|
49
|
+
await until(() => events.some(e => e.event.type === "turn_ended" && e.event.turnId === turn.turnId && e.event.outcome === "interrupted"));
|
|
50
|
+
expect(session.agent.send({ channelId: "alice", participantId: "a", itemId: "second", text: "two" }).accepted).toBe(true);
|
|
51
|
+
await until(() => events.some(e => e.event.type === "turn_ended" && e.event.turnId !== turn.turnId && e.event.outcome === "completed"));
|
|
52
|
+
release(); await new Promise(resolve => setTimeout(resolve, 5));
|
|
53
|
+
const replies = session.snapshot().timeline.filter(entry => entry.message.role === "assistant").map(entry => entry.message.content);
|
|
54
|
+
expect(replies).toEqual(["fresh"]); session.stop("test complete"); storage.close();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test("session stop cancels an active attempt and fences its late response", async () => {
|
|
58
|
+
const opened = createMemoryStorageAdapter().open({ mode: "create", identity: { sessionId: "stop-double", compatibilityKey: "key" } });
|
|
59
|
+
if (!opened.ok) throw new Error(opened.error.message);
|
|
60
|
+
const storage = callStoreDouble(opened.value); let release!: () => void, entered = false;
|
|
61
|
+
const session = createSession({ systemPrompt: "test", storage, configureTurn: () => ({ tools: [], executeTool: async () => "unused", model: async () => {
|
|
62
|
+
entered = true; await new Promise<void>(resolve => { release = resolve; }); return { role: "assistant", content: "late", calls: [] };
|
|
63
|
+
} }) });
|
|
64
|
+
session.start(); session.agent.send({ channelId: "a", participantId: "a", text: "one" }); await until(() => entered);
|
|
65
|
+
session.stop("stop test"); release(); await new Promise(resolve => setTimeout(resolve, 5));
|
|
66
|
+
expect(session.snapshot().timeline.some(entry => entry.message.role === "assistant")).toBe(false); storage.close();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("the real permission gate denies a committed tool request without dispatch", async () => {
|
|
70
|
+
const config = { version: 1 as const, system: "test", model: { protocol: "scripted" as const, script: "fake" }, defaultPolicy: "deny",
|
|
71
|
+
policies: { deny: { fallback: "deny" as const, tools: {} } } };
|
|
72
|
+
const opened = createMemoryStorageAdapter().open({ mode: "create", identity: { sessionId: "policy-double", compatibilityKey: "key" }, config });
|
|
73
|
+
if (!opened.ok) throw new Error(opened.error.message);
|
|
74
|
+
const storage = callStoreDouble(opened.value), events: ChannelEvent[] = []; let invocation = 0, effects = 0;
|
|
75
|
+
const session = createSession({ systemPrompt: "test", config, storage, configureTurn: () => ({ tools: [], executeTool: async () => { effects++; return "effect"; }, model: async () => ++invocation === 1
|
|
76
|
+
? { role: "assistant", content: "request", calls: [{ id: "tool", name: "danger", arguments: "{}" }] }
|
|
77
|
+
: { role: "assistant", content: "done", calls: [] } }) });
|
|
78
|
+
session.subscribe(e => events.push(e)); session.start(); session.agent.send({ channelId: "a", participantId: "a", text: "one" });
|
|
79
|
+
await until(() => events.some(e => e.event.type === "turn_ended" && e.event.outcome === "completed"));
|
|
80
|
+
const timeline = session.snapshot().timeline;
|
|
81
|
+
expect(timeline.find(entry => entry.message.role === "assistant" && entry.message.calls.length)).toBeDefined();
|
|
82
|
+
const result = timeline.find(entry => entry.message.role === "tool");
|
|
83
|
+
expect(result?.message).toMatchObject({ role: "tool", callId: "tool" });
|
|
84
|
+
expect(result && result.message.role === "tool" ? JSON.parse(result.message.content).code : "missing").toBe("policy_denied");
|
|
85
|
+
expect(effects).toBe(0); expect(events.some(e => e.event.type === "tool_call" && e.event.status === "started")).toBe(false);
|
|
86
|
+
session.stop("test complete"); storage.close();
|
|
87
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { spawnHarness } from "./helpers/stdio.ts";
|
|
6
|
+
import { modelScenario } from "./helpers/scenario.ts";
|
|
7
|
+
const config = { version: 1 as const, system: "test", model: { protocol: "scripted" as const, script: new URL("./fixtures/crash-scenario.jsonl", import.meta.url).pathname },
|
|
8
|
+
defaultPolicy: "__legacy_allow", policies: { __legacy_allow: { fallback: "allow" as const, tools: {} } } };
|
|
9
|
+
for (const point of ["startAttempt", "commitResponse"] as const) test(`SQLite process crash after ${point} keeps matching call and reply state`, async () => {
|
|
10
|
+
const home = mkdtempSync(join(tmpdir(), "model-crash-")), first = spawnHarness({ home, fault: `${point}:1` });
|
|
11
|
+
try {
|
|
12
|
+
await first.client.initialize(); await first.client.createSession({ sessionId: "s", config, participants: [], channels: {} });
|
|
13
|
+
void first.client.push({ channel: "a", item: { id: "i", kind: "user_message", sender: "u", content: [{ type: "text", text: "hello" }] } }).catch(() => {});
|
|
14
|
+
expect(await first.child.exited).not.toBe(0); first.client.close();
|
|
15
|
+
const next = spawnHarness({ home });
|
|
16
|
+
try {
|
|
17
|
+
await next.client.initialize(); await next.client.openSession({ sessionId: "s" });
|
|
18
|
+
const loaded = await next.client.reconcileChannel({ channel: "a", turnIds: ["1"] });
|
|
19
|
+
const calls = (await next.client.request("session/model-calls", {})).calls;
|
|
20
|
+
expect(calls).toHaveLength(1); expect(calls[0]?.attempts[0]?.scriptStep).toBe(0);
|
|
21
|
+
if (point === "startAttempt") { expect(calls[0]?.outcome).toBe("interrupted"); expect(loaded.replies).toEqual([]); }
|
|
22
|
+
else { expect(calls[0]?.outcome).toBe("succeeded"); expect(loaded.replies[0]?.messageId).toBe(calls[0]?.messageId); }
|
|
23
|
+
const seen: string[] = []; next.client.onChannelEvent(event => { if (event.event.type === "message_completed" && event.event.parts) seen.push(event.event.parts[0]!.text); });
|
|
24
|
+
await next.client.push({ channel: "a", item: { id: "fresh", kind: "user_message", sender: "u", content: [{ type: "text", text: "again" }] } });
|
|
25
|
+
for (let i = 0; i < 500 && !seen.length; i++) await new Promise(resolve => setTimeout(resolve, 5));
|
|
26
|
+
expect(seen).toEqual(["First reply."]);
|
|
27
|
+
const after = (await next.client.modelCalls()).calls; expect(after[1]?.attempts[0]?.scriptStep).toBe(1);
|
|
28
|
+
} finally { await next.close(); }
|
|
29
|
+
} finally { first.child.kill(); rmSync(home, { recursive: true, force: true }); }
|
|
30
|
+
}, 15000);
|
|
31
|
+
|
|
32
|
+
test("changed scripted sequences are refused after a crash with pending input and no checkpoint", async () => {
|
|
33
|
+
const home = mkdtempSync(join(tmpdir(), "script-identity-crash-")), script = join(home, "fixture.jsonl");
|
|
34
|
+
const source = modelScenario([{ content: "original reply" }]);
|
|
35
|
+
writeFileSync(script, source);
|
|
36
|
+
const first = spawnHarness({ home, fault: "acceptItem:1" });
|
|
37
|
+
const db = join(home, "s", "session.sqlite");
|
|
38
|
+
try {
|
|
39
|
+
await first.client.initialize();
|
|
40
|
+
await first.client.createSession({ sessionId: "s", config: { ...config, model: { protocol: "scripted", script } }, participants: [], channels: {} });
|
|
41
|
+
await first.client.push({ channel: "a", item: { id: "pending", kind: "user_message", sender: "p", content: [{ type: "text", text: "go" }] } }).catch(() => undefined);
|
|
42
|
+
expect(await first.child.exited).not.toBe(0);
|
|
43
|
+
const before = readFileSync(db);
|
|
44
|
+
writeFileSync(script, modelScenario([{ content: "changed reply" }]));
|
|
45
|
+
const changed = spawnHarness({ home });
|
|
46
|
+
try {
|
|
47
|
+
await changed.client.initialize();
|
|
48
|
+
await expect(changed.client.openSession({ sessionId: "s" })).rejects.toMatchObject({ code: "incompatible" });
|
|
49
|
+
expect(readFileSync(db).equals(before)).toBe(true);
|
|
50
|
+
} finally { await changed.close(); }
|
|
51
|
+
writeFileSync(script, source);
|
|
52
|
+
const same = spawnHarness({ home });
|
|
53
|
+
try {
|
|
54
|
+
const completed: string[] = [];
|
|
55
|
+
same.client.onChannelEvent(({ event }) => { if (event.type === "message_completed") completed.push(event.parts![0]!.text); });
|
|
56
|
+
await same.client.initialize(); await same.client.openSession({ sessionId: "s" });
|
|
57
|
+
for (let i = 0; i < 500 && !completed.length; i++) await Bun.sleep(5);
|
|
58
|
+
expect(completed).toEqual(["original reply"]);
|
|
59
|
+
expect((await same.client.modelCalls()).calls[0]?.attempts[0]?.scriptStep).toBe(0);
|
|
60
|
+
} finally { await same.close(); }
|
|
61
|
+
} finally { first.client.close(); first.child.kill(); rmSync(home, { recursive: true, force: true }); }
|
|
62
|
+
}, 15000);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { expect, test } from "bun:test";
|
|
2
|
+
import { createProtocolServer } from "../src/interfaces/protocol/server.ts";
|
|
3
|
+
import { HarnessClient, createInProcessTransport } from "../src/client.ts";
|
|
4
|
+
import type { PersistentSession } from "../src/contracts/session.ts";
|
|
5
|
+
import type { ProtocolEndpoint, RpcNotification } from "../src/contracts/protocol.ts";
|
|
6
|
+
|
|
7
|
+
test("summary paging returns earlier whole calls before an oversized call", async () => {
|
|
8
|
+
const call = (id: string, providerRequestId?: string) => ({ callId: id, turnId: "1", channel: "a", messageId: `model:${id}`,
|
|
9
|
+
startedAt: "start", endedAt: "end", outcome: "succeeded", attempts: [{ attemptId: `${id}:0`, ordinal: 0, startedAt: "start", endedAt: "end", outcome: "succeeded", ...(providerRequestId ? { providerRequestId } : {}) }] });
|
|
10
|
+
const modelCalls = [call("1"), call("2", "x".repeat(1_048_576)), call("3")];
|
|
11
|
+
const session = { subscribe() { return () => {}; }, subscribeSession() { return () => {}; }, approvals: { setConsumer() {}, disconnect() {} }, start() {}, snapshot() { throw new Error("Unexpected snapshot"); }, readModelCalls(after?: string, limit = 100) {
|
|
12
|
+
const index = after === undefined ? -1 : modelCalls.findIndex(call => call.callId === after);
|
|
13
|
+
if (after !== undefined && index < 0) return { ok: false, error: { code: "not_found", message: "Unknown call cursor" } };
|
|
14
|
+
const calls = modelCalls.slice(index + 1, index + 1 + limit);
|
|
15
|
+
return { ok: true, value: { calls, ...(index + 1 + calls.length < modelCalls.length ? { next: calls.at(-1)!.callId } : {}) } };
|
|
16
|
+
} } as unknown as PersistentSession;
|
|
17
|
+
const server = createProtocolServer(async () => ({ session, close() {} })), client = new HarnessClient(createInProcessTransport(server));
|
|
18
|
+
try {
|
|
19
|
+
await client.initialize(); await client.createSession({ sessionId: "s", participants: [], channels: {} });
|
|
20
|
+
await expect(client.modelCalls({ after: "unknown" })).rejects.toMatchObject({ code: "not_found" });
|
|
21
|
+
const page = await client.modelCalls(); expect(page.calls.map(item => item.callId)).toEqual(["1"]); expect(page.next).toBe("1");
|
|
22
|
+
expect((await client.modelCalls({ limit: 1 })).calls.map(item => item.callId)).toEqual(["1"]);
|
|
23
|
+
await expect(client.modelCalls({ after: "1" })).rejects.toMatchObject({ code: "transfer_limit" });
|
|
24
|
+
expect((await client.modelCalls({ after: "2" })).calls.map(item => item.callId)).toEqual(["3"]);
|
|
25
|
+
} finally { client.close(); server.dispose(); }
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
function endpointDouble() {
|
|
29
|
+
let notify!: (event: RpcNotification) => void, disconnected = 0, stopped = 0;
|
|
30
|
+
const endpoint = { subscribe(listener: typeof notify) { notify = listener; return () => {}; }, disconnect() { disconnected++; },
|
|
31
|
+
async request(request: { method: string }) { if (request.method === "session/stop") stopped++; return { jsonrpc: "2.0", id: 1, result: {} }; } } as unknown as ProtocolEndpoint;
|
|
32
|
+
const send = (event: object) => notify({ jsonrpc: "2.0", method: "channel/event", params: { channel: "a", event } } as RpcNotification);
|
|
33
|
+
return { endpoint, send, counts: () => ({ disconnected, stopped }) };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
test("in-process transport bounds synchronous delta bursts and preserves a gap before completion", async () => {
|
|
37
|
+
const source = endpointDouble(), transport = createInProcessTransport(source.endpoint), seen: RpcNotification[] = [];
|
|
38
|
+
transport.subscribe(message => { if ("method" in message) seen.push(message); });
|
|
39
|
+
source.send({ type: "text_delta", turnId: "1", messageId: "m", text: "a".repeat(600_000) });
|
|
40
|
+
source.send({ type: "text_delta", turnId: "1", messageId: "m", text: "b".repeat(600_000) });
|
|
41
|
+
source.send({ type: "text_delta", turnId: "1", messageId: "m", text: "ignored" });
|
|
42
|
+
source.send({ type: "message_completed", turnId: "1", messageId: "m", reference: true });
|
|
43
|
+
for (let i = 0; i < 100 && seen.length < 3; i++) await new Promise(resolve => setTimeout(resolve, 0));
|
|
44
|
+
expect(seen.map(value => value.params.event.type)).toEqual(["text_delta", "text_gap", "message_completed"]);
|
|
45
|
+
expect(source.counts()).toEqual({ disconnected: 0, stopped: 0 }); transport.close();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test("in-process nondroppable overflow closes the connection and stops the session", async () => {
|
|
49
|
+
const source = endpointDouble(), transport = createInProcessTransport(source.endpoint); let closed: Error | undefined;
|
|
50
|
+
transport.onClose(error => { closed = error; });
|
|
51
|
+
const event = { type: "turn_ended", turnId: "1", outcome: "failed", error: "x".repeat(700_000) };
|
|
52
|
+
source.send(event); source.send(event);
|
|
53
|
+
expect(closed?.message).toContain("queue"); expect(source.counts()).toEqual({ disconnected: 1, stopped: 1 });
|
|
54
|
+
expect(() => transport.send({ jsonrpc: "2.0", id: 1, method: "session/status", params: {} })).toThrow("closed");
|
|
55
|
+
});
|