@qlairoslabs/acp-client 0.13.0-alpha.1 → 0.13.2-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/CONSUMER_GUIDE.md +181 -8
- package/MIGRATION-0.12-to-0.13.md +20 -7
- package/package.json +13 -2
- package/src/agent/config.ts +2 -0
- package/src/agent/conversation-manager.ts +1 -0
- package/src/agent/native-operations.ts +40 -0
- package/src/agent-session-config.ts +2 -0
- package/src/agent-session.ts +12 -2
- package/src/agent.ts +100 -2
- package/src/client.ts +5 -3
- package/src/controller-connection.ts +1 -0
- package/src/controller.ts +2 -0
- package/src/index.ts +3 -0
- package/src/launcher.ts +2 -0
- package/src/native/approvals.ts +20 -3
- package/src/native/capabilities.ts +2 -2
- package/src/native/connection.ts +1 -1
- package/src/native/controller.ts +5 -3
- package/src/native/host-config.ts +2 -0
- package/src/native/host.ts +83 -4
- package/src/native/mcp.ts +47 -0
- package/src/native/recovery.ts +8 -7
- package/src/native/reminders/routine-guard.ts +4 -3
- package/src/native/reminders/routine-wire.ts +1 -1
- package/src/native-harness/README.md +58 -1
- package/src/native-harness/package.json +4 -0
- package/src/native-harness/scripts/build-routine-zones.py +47 -0
- package/src/native-harness/src/capabilities/attachments/admission.ts +42 -0
- package/src/native-harness/src/capabilities/attachments/image-validation.ts +98 -0
- package/src/native-harness/src/capabilities/attachments/input.ts +1 -0
- package/src/native-harness/src/capabilities/attachments/read.ts +76 -0
- package/src/native-harness/src/capabilities/attachments/recovery.ts +26 -0
- package/src/native-harness/src/capabilities/attachments/selection.ts +37 -0
- package/src/native-harness/src/capabilities/attachments/service.ts +75 -0
- package/src/native-harness/src/capabilities/attachments/upload.ts +164 -0
- package/src/native-harness/src/capabilities/attachments/vision.ts +45 -0
- package/src/native-harness/src/capabilities/context/build.ts +5 -0
- package/src/native-harness/src/capabilities/context/session.ts +2 -1
- package/src/native-harness/src/capabilities/model/openrouter-stream.ts +80 -17
- package/src/native-harness/src/capabilities/model/runner.ts +6 -3
- package/src/native-harness/src/capabilities/reminders/cron-calendar.ts +50 -0
- package/src/native-harness/src/capabilities/reminders/cron-fields.ts +46 -0
- package/src/native-harness/src/capabilities/reminders/cron-proof.ts +32 -0
- package/src/native-harness/src/capabilities/reminders/cron-zone.ts +53 -0
- package/src/native-harness/src/capabilities/reminders/iana-zones.json.gz +0 -0
- package/src/native-harness/src/capabilities/reminders/iana-zones.ts +34 -0
- package/src/native-harness/src/capabilities/reminders/interval.ts +30 -0
- package/src/native-harness/src/capabilities/reminders/routine-advance.ts +47 -0
- package/src/native-harness/src/capabilities/reminders/routine-backlog.ts +47 -0
- package/src/native-harness/src/capabilities/reminders/routine-expiry.ts +15 -0
- package/src/native-harness/src/capabilities/reminders/routine-occurrence.ts +65 -0
- package/src/native-harness/src/capabilities/reminders/routine-schedule.ts +70 -0
- package/src/native-harness/src/capabilities/reminders/unattended.ts +8 -0
- package/src/native-harness/src/capabilities/tools/mcp/client.ts +97 -0
- package/src/native-harness/src/capabilities/tools/mcp/http.ts +183 -0
- package/src/native-harness/src/capabilities/tools/mcp/registry.ts +62 -0
- package/src/native-harness/src/capabilities/tools/mcp/result.ts +33 -0
- package/src/native-harness/src/capabilities/tools/mcp/schema.ts +77 -0
- package/src/native-harness/src/capabilities/tools/mcp/secrets.ts +28 -0
- package/src/native-harness/src/capabilities/tools/mcp/stdio.ts +105 -0
- package/src/native-harness/src/capabilities/tools/reminders/index.ts +27 -5
- package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +4 -1
- package/src/native-harness/src/capabilities/tools/web/config.ts +1 -0
- package/src/native-harness/src/capabilities/tools/web/definitions.ts +18 -0
- package/src/native-harness/src/capabilities/tools/web/direct-address.ts +56 -0
- package/src/native-harness/src/capabilities/tools/web/direct-transport.ts +235 -0
- package/src/native-harness/src/capabilities/tools/web/direct.ts +149 -0
- package/src/native-harness/src/capabilities/tools/web/exa-transport.ts +41 -0
- package/src/native-harness/src/capabilities/tools/web/exa.ts +71 -0
- package/src/native-harness/src/capabilities/tools/web/preview.ts +44 -0
- package/src/native-harness/src/capabilities/tools/web/registry.ts +47 -0
- package/src/native-harness/src/capabilities/tools/web/usage.ts +1 -0
- package/src/native-harness/src/contracts/agent.ts +3 -1
- package/src/native-harness/src/contracts/attachments.ts +62 -0
- package/src/native-harness/src/contracts/config-permissions.ts +14 -3
- package/src/native-harness/src/contracts/context.ts +1 -1
- package/src/native-harness/src/contracts/events.ts +2 -2
- package/src/native-harness/src/contracts/loop.ts +3 -3
- package/src/native-harness/src/contracts/mcp.ts +22 -0
- package/src/native-harness/src/contracts/model-execution.ts +2 -1
- package/src/native-harness/src/contracts/operator-controls.ts +8 -1
- package/src/native-harness/src/contracts/protocol.ts +21 -5
- package/src/native-harness/src/contracts/reminders.ts +4 -2
- package/src/native-harness/src/contracts/routines.ts +20 -0
- package/src/native-harness/src/contracts/session-file.ts +2 -0
- package/src/native-harness/src/contracts/session.ts +8 -3
- package/src/native-harness/src/contracts/storage.ts +32 -13
- package/src/native-harness/src/contracts/tools.ts +2 -0
- package/src/native-harness/src/contracts/web.ts +16 -0
- package/src/native-harness/src/governance/permissions/gate.ts +9 -2
- package/src/native-harness/src/governance/policy/resolve.ts +6 -1
- package/src/native-harness/src/index.ts +48 -12
- package/src/native-harness/src/interfaces/cli/development.ts +108 -53
- package/src/native-harness/src/interfaces/cli/serve.ts +2 -2
- package/src/native-harness/src/interfaces/cli/start.ts +22 -13
- package/src/native-harness/src/interfaces/client.ts +8 -2
- package/src/native-harness/src/interfaces/inspector/index.html +7 -1
- package/src/native-harness/src/interfaces/inspector/state.ts +6 -2
- package/src/native-harness/src/interfaces/protocol/load.ts +3 -1
- package/src/native-harness/src/interfaces/protocol/local.ts +13 -4
- package/src/native-harness/src/interfaces/protocol/operator.ts +8 -2
- package/src/native-harness/src/interfaces/protocol/server.ts +102 -36
- package/src/native-harness/src/interfaces/protocol/stdio-client.ts +8 -0
- package/src/native-harness/src/interfaces/web-chat/index.html +65 -12
- package/src/native-harness/src/interfaces/web-chat/server.ts +30 -3
- package/src/native-harness/src/kernel/channels.ts +27 -15
- package/src/native-harness/src/kernel/loop.ts +1 -1
- package/src/native-harness/src/runtime/config/inference-key.ts +7 -0
- package/src/native-harness/src/runtime/config/managed.ts +1 -1
- package/src/native-harness/src/runtime/config/paths.ts +8 -1
- package/src/native-harness/src/runtime/execution/mcp-stdio.ts +31 -0
- package/src/native-harness/src/runtime/reminder-validation.ts +31 -10
- package/src/native-harness/src/runtime/reminders.ts +2 -2
- package/src/native-harness/src/state/storage/archive.ts +113 -12
- package/src/native-harness/src/state/storage/attachment-files.ts +58 -0
- package/src/native-harness/src/state/storage/attachment-import.ts +106 -0
- package/src/native-harness/src/state/storage/attachment-tables.ts +123 -0
- package/src/native-harness/src/state/storage/engine.ts +396 -45
- package/src/native-harness/src/state/storage/inference.ts +30 -2
- package/src/native-harness/src/state/storage/memory-attachments.ts +56 -0
- package/src/native-harness/src/state/storage/memory-reminders.ts +31 -6
- package/src/native-harness/src/state/storage/memory.ts +32 -4
- package/src/native-harness/src/state/storage/reminder-archive.ts +53 -12
- package/src/native-harness/src/state/storage/reminder-change.ts +60 -14
- package/src/native-harness/src/state/storage/reminder-tables.ts +11 -3
- package/src/native-harness/src/state/storage/routine-row.ts +25 -0
- package/src/native-harness/src/state/storage/session-file.ts +22 -9
- package/src/native-harness/src/state/storage/sqlite-reminders.ts +48 -8
- package/src/native-harness/src/state/storage/sqlite.ts +59 -11
- package/src/native-harness/src/state/storage/web-tables.ts +47 -0
- package/src/native-harness/src/testing.ts +151 -56
- package/src/native-harness/src/util/attachment-input.ts +42 -0
- package/src/native-harness/src/util/config.ts +64 -9
- package/src/native-harness/src/util/intake.ts +7 -0
- package/src/native-harness/src/util/mcp-config.ts +102 -0
- package/src/native-harness/src/util/web-config.ts +34 -0
- package/src/native-harness/src/util/web-usage.ts +33 -0
- package/src/orchestrator/permissions.ts +6 -3
- package/src/permissions/conversation.ts +13 -5
- package/src/permissions/matcher.ts +2 -0
- package/src/permissions/outcome.ts +12 -1
- package/src/permissions/policy.ts +13 -8
- package/src/steering/combine.ts +1 -0
- package/src/steering/contracts.ts +3 -0
- package/src/terminals.ts +9 -6
- package/src/native/reminders/reminders.test.ts +0 -553
- package/src/native/reminders/routine-config.typecheck.ts +0 -13
- package/src/native/reminders/wire.typecheck.ts +0 -13
- package/src/native-harness/.res/README.md +0 -1
- package/src/native-harness/.res/architecture/README.md +0 -21
- package/src/native-harness/.res/architecture/context-and-data.md +0 -31
- package/src/native-harness/.res/architecture/execution.md +0 -42
- package/src/native-harness/.res/architecture/overview.md +0 -44
- package/src/native-harness/.res/architecture/persistence.md +0 -56
- package/src/native-harness/.res/architecture/suspend-and-resume.md +0 -45
- package/src/native-harness/.res/architecture/technical-architecture.md +0 -50
- package/src/native-harness/.res/decisions/0001-basic-loop.md +0 -11
- package/src/native-harness/.res/decisions/0002-channel-input.md +0 -17
- package/src/native-harness/.res/decisions/0003-inference-inspection.md +0 -14
- package/src/native-harness/.res/decisions/0004-shared-context.md +0 -21
- package/src/native-harness/.res/decisions/0005-notice-inbox.md +0 -20
- package/src/native-harness/.res/decisions/0006-explicit-notices.md +0 -12
- package/src/native-harness/.res/decisions/0007-channel-output.md +0 -12
- package/src/native-harness/.res/decisions/0008-browser-client.md +0 -16
- package/src/native-harness/.res/decisions/0009-scripted-model.md +0 -18
- package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +0 -19
- package/src/native-harness/.res/decisions/0011-stdio-transport.md +0 -21
- package/src/native-harness/.res/decisions/0012-session-storage-contract.md +0 -37
- package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +0 -64
- package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +0 -73
- package/src/native-harness/.res/decisions/0015-session-file-contract.md +0 -72
- package/src/native-harness/.res/decisions/0016-configuration-permissions.md +0 -159
- package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +0 -69
- package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +0 -78
- package/src/native-harness/.res/decisions/0019-model-execution.md +0 -188
- package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +0 -71
- package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +0 -100
- package/src/native-harness/.res/decisions/0022-operator-controls.md +0 -115
- package/src/native-harness/.res/decisions/0023-long-running-mock.md +0 -82
- package/src/native-harness/.res/decisions/0024-callback-policy-names.md +0 -46
- package/src/native-harness/.res/decisions/0025-external-notices.md +0 -364
- package/src/native-harness/.res/decisions/0026-bounded-context.md +0 -81
- package/src/native-harness/.res/decisions/0027-development-instructions.md +0 -22
- package/src/native-harness/.res/decisions/0028-debug-tools.md +0 -16
- package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +0 -37
- package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +0 -145
- package/src/native-harness/.res/decisions/0031-one-off-reminders.md +0 -173
- package/src/native-harness/.res/docs/11-15.md +0 -148
- package/src/native-harness/.res/docs/BUSINESS_RULES.md +0 -111
- package/src/native-harness/.res/docs/WORK.md +0 -65
- package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +0 -312
- package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +0 -77
- package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +0 -313
- package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +0 -160
- package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +0 -89
- package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +0 -135
- package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +0 -143
- package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +0 -93
- package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +0 -181
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +0 -433
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +0 -60
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +0 -141
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +0 -168
- package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +0 -111
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +0 -129
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +0 -135
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +0 -437
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +0 -127
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +0 -203
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +0 -292
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +0 -91
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +0 -187
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +0 -148
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +0 -95
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +0 -200
- package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +0 -80
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +0 -206
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +0 -106
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +0 -297
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +0 -41
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +0 -36
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +0 -84
- package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +0 -147
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +0 -15
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +0 -107
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +0 -114
- package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +0 -24
- package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +0 -23
- package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +0 -103
- package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +0 -50
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +0 -337
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +0 -76
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +0 -204
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +0 -73
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +0 -64
- package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +0 -58
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +0 -45
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +0 -108
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +0 -169
- package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +0 -128
- package/src/native-harness/.res/marketing-draft.md +0 -22
- package/src/native-harness/.res/sandbox/1-simple-harness/README.md +0 -285
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +0 -19
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +0 -138
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +0 -148
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +0 -172
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +0 -194
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +0 -233
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +0 -249
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +0 -265
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +0 -279
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +0 -293
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +0 -307
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +0 -29
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +0 -317
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +0 -327
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +0 -40
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +0 -59
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +0 -69
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +0 -79
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +0 -89
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +0 -102
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +0 -116
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +0 -49
- package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +0 -87
- package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +0 -289
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +0 -221
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +0 -287
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +0 -165
- package/src/native-harness/.res/sandbox/1-simple-harness/state.json +0 -22
- package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +0 -2
- package/src/native-harness/AGENTS.md +0 -70
- package/src/native-harness/ARCHITECTURE.md +0 -249
- package/src/native-harness/bun.lock +0 -26
- package/src/native-harness/test/agent.test.ts +0 -130
- package/src/native-harness/test/approval-gate.test.ts +0 -255
- package/src/native-harness/test/approval-protocol.test.ts +0 -94
- package/src/native-harness/test/boundaries.test.ts +0 -18
- package/src/native-harness/test/channel-controls.test.ts +0 -322
- package/src/native-harness/test/client-abort.test.ts +0 -136
- package/src/native-harness/test/config-policy.test.ts +0 -301
- package/src/native-harness/test/conformance/storage.ts +0 -1141
- package/src/native-harness/test/context.test.ts +0 -177
- package/src/native-harness/test/crash.test.ts +0 -187
- package/src/native-harness/test/debug-tools.test.ts +0 -67
- package/src/native-harness/test/development-cli.test.ts +0 -67
- package/src/native-harness/test/development.test.ts +0 -171
- package/src/native-harness/test/dispatch-evidence.test.ts +0 -58
- package/src/native-harness/test/e2e.test.ts +0 -186
- package/src/native-harness/test/external-notices.test.ts +0 -101
- package/src/native-harness/test/fixtures/approval-e2e.jsonl +0 -4
- package/src/native-harness/test/fixtures/crash-scenario.jsonl +0 -5
- package/src/native-harness/test/fixtures/development-lifecycle.jsonl +0 -10
- package/src/native-harness/test/fixtures/echo-scenario.jsonl +0 -3
- package/src/native-harness/test/fixtures/format2-schema.ts +0 -27
- package/src/native-harness/test/fixtures/format3-schema.ts +0 -16
- package/src/native-harness/test/fixtures/hold-scenario.jsonl +0 -4
- package/src/native-harness/test/fixtures/model-e2e.jsonl +0 -3
- package/src/native-harness/test/fixtures/storage-owner.ts +0 -20
- package/src/native-harness/test/format-reply.test.ts +0 -10
- package/src/native-harness/test/helpers/operator-view.ts +0 -41
- package/src/native-harness/test/helpers/scenario.ts +0 -9
- package/src/native-harness/test/helpers/session.ts +0 -38
- package/src/native-harness/test/helpers/stdio.ts +0 -46
- package/src/native-harness/test/inspector.test.ts +0 -77
- package/src/native-harness/test/listeners.test.ts +0 -49
- package/src/native-harness/test/loop.test.ts +0 -88
- package/src/native-harness/test/model-channel-double.test.ts +0 -87
- package/src/native-harness/test/model-crash.test.ts +0 -62
- package/src/native-harness/test/model-delivery-regressions.test.ts +0 -55
- package/src/native-harness/test/model-e2e.test.ts +0 -71
- package/src/native-harness/test/model-final-filter.test.ts +0 -30
- package/src/native-harness/test/model-large-reply.test.ts +0 -28
- package/src/native-harness/test/model-live-queue.test.ts +0 -33
- package/src/native-harness/test/model-runner.test.ts +0 -117
- package/src/native-harness/test/model-storage.test.ts +0 -99
- package/src/native-harness/test/model-stream-adapter.test.ts +0 -26
- package/src/native-harness/test/model-stream-public.test.ts +0 -77
- package/src/native-harness/test/notices.test.ts +0 -64
- package/src/native-harness/test/openrouter-config.test.ts +0 -218
- package/src/native-harness/test/operator-controls.test.ts +0 -132
- package/src/native-harness/test/output.test.ts +0 -44
- package/src/native-harness/test/owner-config.test.ts +0 -64
- package/src/native-harness/test/permissions-e2e.test.ts +0 -68
- package/src/native-harness/test/persistence.test.ts +0 -236
- package/src/native-harness/test/portability.test.ts +0 -337
- package/src/native-harness/test/protocol.test.ts +0 -160
- package/src/native-harness/test/reminder-clock.test.ts +0 -61
- package/src/native-harness/test/reminder-stdio.test.ts +0 -140
- package/src/native-harness/test/reminder-storage.test.ts +0 -124
- package/src/native-harness/test/scenario-jsonl.test.ts +0 -112
- package/src/native-harness/test/scripted.test.ts +0 -92
- package/src/native-harness/test/session-file.test.ts +0 -51
- package/src/native-harness/test/startup-channel-changes.test.ts +0 -256
- package/src/native-harness/test/stdio.test.ts +0 -132
- package/src/native-harness/test/storage-memory.test.ts +0 -4
- package/src/native-harness/test/storage-sqlite.test.ts +0 -420
- package/src/native-harness/test/suspension.test.ts +0 -430
- package/src/native-harness/test/timeline-retrieval.test.ts +0 -211
- package/src/native-harness/test/tools-catalog.test.ts +0 -468
- package/src/native-harness/test/tools-protocol.test.ts +0 -418
- package/src/native-harness/test/transfers.test.ts +0 -94
- package/src/native-harness/test/web-chat.test.ts +0 -35
|
@@ -1,255 +0,0 @@
|
|
|
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 { ManagedConfig, ToolDecision } from "../src/contracts/config-permissions.ts";
|
|
5
|
-
import type { ChannelEvent } from "../src/contracts/events.ts";
|
|
6
|
-
|
|
7
|
-
function deferred() { let resolve!: () => void; const promise = new Promise<void>(r => { resolve = r; }); return { promise, resolve }; }
|
|
8
|
-
async function until(check: () => boolean, label: string) { for (let i = 0; i < 400; i++) { if (check()) return; await new Promise(r => setTimeout(r, 5)); } throw new Error(`Timed out: ${label}`); }
|
|
9
|
-
function rig(rule: ToolDecision, options: { timeout?: number; beforeDispatch?: () => Promise<void>; toolWait?: Promise<void> } = {}) {
|
|
10
|
-
const config: ManagedConfig = { version: 1, system: "test", model: { protocol: "scripted", script: "fixture" }, defaultPolicy: "main",
|
|
11
|
-
policies: { main: { fallback: rule, tools: {} } } };
|
|
12
|
-
const adapter = createMemoryStorageAdapter(), opened = adapter.open({ mode: "create", identity: { sessionId: "s", compatibilityKey: "k" }, config });
|
|
13
|
-
if (!opened.ok) throw new Error(opened.error.message);
|
|
14
|
-
const effects: string[] = [], events: ChannelEvent[] = [];
|
|
15
|
-
const session = createSession({ systemPrompt: "test", storage: opened.value, config, approvalTimeoutMs: options.timeout, beforeToolDispatch: options.beforeDispatch,
|
|
16
|
-
configureTurn(turn) { return { tools: [], model: async messages => turn.channelId === "bob" || messages.at(-1)?.role === "tool"
|
|
17
|
-
? { role: "assistant", content: "done", calls: [] }
|
|
18
|
-
: { role: "assistant", content: null, calls: [{ id: `call-${turn.turnId}`, name: "work", arguments: '{"value":1}' }] },
|
|
19
|
-
executeTool: async () => { effects.push("started"); if (options.toolWait) await options.toolWait; effects.push("finished"); return "effect"; } }; } });
|
|
20
|
-
session.subscribe(event => events.push(event)); session.start();
|
|
21
|
-
const send = (channel: string, id: string) => session.agent.send({ channelId: channel, participantId: "u", text: id, itemId: id });
|
|
22
|
-
const approval = () => events.findLast(e => e.event.type === "approval_requested")?.event;
|
|
23
|
-
const ended = (channel = "a") => events.some(e => e.channel === channel && e.event.type === "turn_ended");
|
|
24
|
-
const tools = () => session.snapshot().timeline.filter(e => e.message.role === "tool").map(e => e.message.role === "tool" ? e.message.content : "");
|
|
25
|
-
const close = () => { session.stop("done"); opened.value.close(); };
|
|
26
|
-
return { session, events, effects, send, approval, ended, tools, close };
|
|
27
|
-
}
|
|
28
|
-
function id(event: ReturnType<ReturnType<typeof rig>["approval"]>) { if (!event || event.type !== "approval_requested") throw new Error("missing approval"); return event.requestId; }
|
|
29
|
-
|
|
30
|
-
test("allow dispatches once; policy denial and an unhandled ask produce paired results without started", async () => {
|
|
31
|
-
for (const rule of ["allow", "deny", "ask"] as const) {
|
|
32
|
-
const r = rig(rule); try {
|
|
33
|
-
r.send("a", "one"); await until(() => r.ended(), "turn");
|
|
34
|
-
expect(r.effects).toEqual(rule === "allow" ? ["started", "finished"] : []);
|
|
35
|
-
expect(r.events.filter(e => e.event.type === "tool_call" && e.event.status === "started")).toHaveLength(rule === "allow" ? 1 : 0);
|
|
36
|
-
expect(r.tools()).toHaveLength(1);
|
|
37
|
-
if (rule !== "allow") expect(JSON.parse(r.tools()[0]!).code).toBe(rule === "deny" ? "policy_denied" : "approval_unhandled");
|
|
38
|
-
} finally { r.close(); }
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test("one-time approval, deny, timeout and disconnect never authorize another call; another channel continues", async () => {
|
|
43
|
-
for (const outcome of ["allow_once", "deny", "timeout", "disconnect"] as const) {
|
|
44
|
-
const r = rig("ask", { timeout: 40 }); r.session.approvals.setConsumer(true);
|
|
45
|
-
try {
|
|
46
|
-
r.send("a", "one"); await until(() => !!r.approval(), "request"); const requestId = id(r.approval());
|
|
47
|
-
r.send("bob", "bob"); await until(() => r.ended("bob"), "bob while approval waits");
|
|
48
|
-
if (outcome === "disconnect") r.session.approvals.disconnect();
|
|
49
|
-
else if (outcome !== "timeout") expect(r.session.approvals.respond(requestId, outcome)).toBe(true);
|
|
50
|
-
await until(() => r.ended(), "approval outcome");
|
|
51
|
-
expect(r.session.approvals.respond(requestId, "allow_once")).toBe(false);
|
|
52
|
-
expect(r.effects).toEqual(outcome === "allow_once" ? ["started", "finished"] : []);
|
|
53
|
-
expect(r.tools()).toHaveLength(1);
|
|
54
|
-
if (outcome !== "allow_once") expect(JSON.parse(r.tools()[0]!).code).toBe({ deny: "approval_denied", timeout: "approval_timeout", disconnect: "approval_disconnected" }[outcome]);
|
|
55
|
-
} finally { r.close(); }
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test("suspension before granted dispatch records a cancellation and no started event", async () => {
|
|
60
|
-
const entered = deferred(), release = deferred();
|
|
61
|
-
const r = rig("ask", { beforeDispatch: () => { entered.resolve(); return release.promise; } }); r.session.approvals.setConsumer(true);
|
|
62
|
-
try {
|
|
63
|
-
r.send("a", "one"); await until(() => !!r.approval(), "request"); const requestId = id(r.approval());
|
|
64
|
-
expect(r.session.approvals.respond(requestId, "allow_once")).toBe(true); await entered.promise;
|
|
65
|
-
const suspended = r.session.channels.suspend("a");
|
|
66
|
-
expect(r.session.approvals.respond(requestId, "allow_once")).toBe(false);
|
|
67
|
-
expect(JSON.parse(r.tools()[0]!).code).toBe("approval_cancelled_by_suspension");
|
|
68
|
-
release.resolve(); expect((await suspended).ok).toBe(true);
|
|
69
|
-
expect(r.effects).toEqual([]); expect(r.events.filter(e => e.event.type === "tool_call" && e.event.status === "started")).toHaveLength(0);
|
|
70
|
-
expect(r.session.snapshot().turns[0]!.state.status).toBe("suspended");
|
|
71
|
-
} finally { release.resolve(); r.close(); }
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("suspension after dispatch waits for the running tool and records exactly one started event", async () => {
|
|
75
|
-
const release = deferred(), r = rig("ask", { toolWait: release.promise }); r.session.approvals.setConsumer(true);
|
|
76
|
-
try {
|
|
77
|
-
r.send("a", "one"); await until(() => !!r.approval(), "request");
|
|
78
|
-
expect(r.session.approvals.respond(id(r.approval()), "allow_once")).toBe(true);
|
|
79
|
-
await until(() => r.effects.includes("started"), "tool dispatch");
|
|
80
|
-
let done = false; const suspended = r.session.channels.suspend("a").then(value => { done = true; return value; });
|
|
81
|
-
await new Promise(resolve => setTimeout(resolve, 20)); expect(done).toBe(false);
|
|
82
|
-
release.resolve(); expect((await suspended).ok).toBe(true);
|
|
83
|
-
expect(r.effects).toEqual(["started", "finished"]);
|
|
84
|
-
expect(r.events.filter(e => e.event.type === "tool_call" && e.event.status === "started")).toHaveLength(1);
|
|
85
|
-
expect(r.session.snapshot().turns[0]!.state.status).toBe("suspended");
|
|
86
|
-
} finally { release.resolve(); r.close(); }
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test("interrupt after a grant but before dispatch records exactly one result before termination", async () => {
|
|
90
|
-
const entered = deferred(), release = deferred();
|
|
91
|
-
const r = rig("ask", { beforeDispatch: () => { entered.resolve(); return release.promise; } }); r.session.approvals.setConsumer(true);
|
|
92
|
-
try {
|
|
93
|
-
r.send("a", "one"); await until(() => !!r.approval(), "request"); const requestId = id(r.approval());
|
|
94
|
-
expect(r.session.approvals.respond(requestId, "allow_once")).toBe(true); await entered.promise;
|
|
95
|
-
expect(r.session.channels.interrupt("a", 1).ok).toBe(true);
|
|
96
|
-
expect(r.tools()).toHaveLength(1); expect(r.session.snapshot().turns[0]!.state).toMatchObject({ status: "interrupted", uncertainCallIds: [] });
|
|
97
|
-
release.resolve(); await new Promise(resolve => setTimeout(resolve, 15));
|
|
98
|
-
expect(r.tools()).toHaveLength(1); expect(r.effects).toEqual([]);
|
|
99
|
-
expect(r.events.filter(e => e.event.type === "tool_call" && e.event.status === "started")).toHaveLength(0);
|
|
100
|
-
} finally { release.resolve(); r.close(); }
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("disconnect after a grant but before dispatch discards it and records one result", async () => {
|
|
104
|
-
const entered = deferred(), release = deferred();
|
|
105
|
-
const r = rig("ask", { beforeDispatch: () => { entered.resolve(); return release.promise; } }); r.session.approvals.setConsumer(true);
|
|
106
|
-
try {
|
|
107
|
-
r.send("a", "one"); await until(() => !!r.approval(), "request"); const requestId = id(r.approval());
|
|
108
|
-
expect(r.session.approvals.respond(requestId, "allow_once")).toBe(true); await entered.promise;
|
|
109
|
-
r.session.approvals.disconnect(); expect(r.tools()).toHaveLength(1);
|
|
110
|
-
expect(JSON.parse(r.tools()[0]!).code).toBe("approval_disconnected");
|
|
111
|
-
release.resolve(); await until(() => r.ended(), "closed turn");
|
|
112
|
-
expect(r.tools()).toHaveLength(1); expect(r.effects).toEqual([]);
|
|
113
|
-
expect(r.events.filter(e => e.event.type === "tool_call" && e.event.status === "started")).toHaveLength(0);
|
|
114
|
-
} finally { release.resolve(); r.close(); }
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test("suspending another channel does not cancel the waiting approval", async () => {
|
|
118
|
-
const r = rig("ask"); r.session.approvals.setConsumer(true);
|
|
119
|
-
try {
|
|
120
|
-
r.send("a", "one"); r.send("bob", "bob");
|
|
121
|
-
await until(() => !!r.approval() && r.ended("bob"), "both channels");
|
|
122
|
-
expect((await r.session.channels.suspend("bob")).ok).toBe(true);
|
|
123
|
-
expect(r.session.approvals.respond(id(r.approval()), "allow_once")).toBe(true);
|
|
124
|
-
await until(() => r.ended(), "approved turn"); expect(r.effects).toEqual(["started", "finished"]);
|
|
125
|
-
} finally { r.close(); }
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test("a failed durable dispatch mark cannot invoke the executor or emit started", async () => {
|
|
129
|
-
const { createApprovalService, dispatchWithPolicy } = await import("../src/governance/permissions/gate.ts");
|
|
130
|
-
let invoked = false, started = false;
|
|
131
|
-
const abort = new AbortController(), suspend = new AbortController();
|
|
132
|
-
await expect(dispatchWithPolicy({ decide: () => "allow", channel: "a", turnId: 1, call: { id: "c", name: "t", arguments: "{}" },
|
|
133
|
-
signal: abort.signal, suspension: suspend.signal, approvals: createApprovalService(() => {}), recordSkip: () => {},
|
|
134
|
-
mark: () => { throw new Error("mark failed"); }, started: () => { started = true; }, execute: async () => { invoked = true; return "x"; } })).rejects.toThrow("mark failed");
|
|
135
|
-
expect(invoked).toBe(false); expect(started).toBe(false);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
test("a failed pre-dispatch barrier discards the grant before the turn fails", async () => {
|
|
139
|
-
const r = rig("ask", { beforeDispatch: async () => { throw new Error("barrier failed"); } }); r.session.approvals.setConsumer(true);
|
|
140
|
-
try {
|
|
141
|
-
r.send("a", "one"); await until(() => !!r.approval(), "request"); const requestId = id(r.approval());
|
|
142
|
-
expect(r.session.approvals.respond(requestId, "allow_once")).toBe(true);
|
|
143
|
-
await until(() => r.ended(), "failed turn");
|
|
144
|
-
expect(r.session.approvals.respond(requestId, "allow_once")).toBe(false);
|
|
145
|
-
expect(() => r.session.approvals.disconnect()).not.toThrow();
|
|
146
|
-
expect(r.effects).toEqual([]); expect(r.tools()).toEqual([]);
|
|
147
|
-
expect(r.session.snapshot().turns[0]!.state).toMatchObject({ status: "failed", uncertainCallIds: [] });
|
|
148
|
-
} finally { r.close(); }
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test("a reentrant started listener cannot interrupt before the already-marked executor is invoked", async () => {
|
|
152
|
-
const release = deferred(), r = rig("allow", { toolWait: release.promise });
|
|
153
|
-
r.session.subscribe(event => { if (event.event.type === "tool_call" && event.event.status === "started") r.session.channels.interrupt("a", 1); });
|
|
154
|
-
try {
|
|
155
|
-
r.send("a", "one"); await until(() => r.ended(), "interruption");
|
|
156
|
-
expect(r.effects).toEqual(["started"]);
|
|
157
|
-
expect(r.session.snapshot().turns[0]!.state).toMatchObject({ status: "interrupted", uncertainCallIds: ["call-1"] });
|
|
158
|
-
release.resolve(); await until(() => r.effects.includes("finished"), "late tool return");
|
|
159
|
-
expect(r.tools()).toEqual([]);
|
|
160
|
-
} finally { release.resolve(); r.close(); }
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
for (const action of ["interrupt", "stop", "session suspend"] as const) test(`${action} closes a waiting approval before the turn rests`, async () => {
|
|
164
|
-
const r = rig("ask"); r.session.approvals.setConsumer(true);
|
|
165
|
-
try {
|
|
166
|
-
r.send("a", "one"); await until(() => !!r.approval(), "request"); const requestId = id(r.approval());
|
|
167
|
-
if (action === "interrupt") expect(r.session.channels.interrupt("a", 1).ok).toBe(true);
|
|
168
|
-
else if (action === "stop") r.session.stop("stop");
|
|
169
|
-
else expect((await r.session.suspend()).ok).toBe(true);
|
|
170
|
-
expect(r.session.approvals.respond(requestId, "allow_once")).toBe(false);
|
|
171
|
-
expect(r.effects).toEqual([]); expect(r.tools()).toHaveLength(1);
|
|
172
|
-
if (action === "session suspend") expect(JSON.parse(r.tools()[0]!).code).toBe("approval_cancelled_by_suspension");
|
|
173
|
-
else {
|
|
174
|
-
expect(JSON.parse(r.tools()[0]!).code).toBe(action === "stop" ? "approval_cancelled_by_stop" : "approval_cancelled_by_interrupt");
|
|
175
|
-
expect(r.session.snapshot().turns[0]!.state).toMatchObject({ status: "interrupted", uncertainCallIds: [] });
|
|
176
|
-
}
|
|
177
|
-
} finally { r.close(); }
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
test("a taken restrictive input tightens later calls without changing a running tool", async () => {
|
|
181
|
-
const config: ManagedConfig = { version: 1, system: "test", model: { protocol: "scripted", script: "fixture" }, defaultPolicy: "open",
|
|
182
|
-
policies: { open: { fallback: "allow", tools: {} }, strict: { fallback: "deny", tools: { hold: "allow" } } } };
|
|
183
|
-
const adapter = createMemoryStorageAdapter(), opened = adapter.open({ mode: "create", identity: { sessionId: "s", compatibilityKey: "k" }, config });
|
|
184
|
-
if (!opened.ok) throw new Error(opened.error.message);
|
|
185
|
-
const release = deferred(), effects: string[] = []; let step = 0;
|
|
186
|
-
const session = createSession({ systemPrompt: "test", storage: opened.value, config, configureTurn() { return { tools: [],
|
|
187
|
-
model: async () => ++step === 1 ? { role: "assistant", content: null, calls: [{ id: "hold", name: "hold", arguments: "{}" }] }
|
|
188
|
-
: step === 2 ? { role: "assistant", content: null, calls: [{ id: "blocked", name: "work", arguments: "{}" }] }
|
|
189
|
-
: { role: "assistant", content: "done", calls: [] },
|
|
190
|
-
executeTool: async call => { effects.push(call.name); if (call.name === "hold") await release.promise; return "ok"; } }; } });
|
|
191
|
-
try {
|
|
192
|
-
session.start(); session.agent.send({ channelId: "a", participantId: "u", text: "first", itemId: "first" });
|
|
193
|
-
await until(() => effects.includes("hold"), "first tool");
|
|
194
|
-
session.agent.send({ channelId: "a", participantId: "u", text: "tighten", itemId: "later", policy: "strict" });
|
|
195
|
-
expect(effects).toEqual(["hold"]); release.resolve();
|
|
196
|
-
await until(() => session.snapshot().turns[0]?.state.status === "completed", "turn completion");
|
|
197
|
-
expect(effects).toEqual(["hold"]);
|
|
198
|
-
const result = session.snapshot().timeline.find(entry => entry.message.role === "tool" && entry.message.callId === "blocked")!.message;
|
|
199
|
-
expect(result.role === "tool" && JSON.parse(result.content).code).toBe("policy_denied");
|
|
200
|
-
} finally { release.resolve(); session.stop("done"); opened.value.close(); }
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
test("a notice inherits source restrictions and cannot grant its target a denied tool", async () => {
|
|
204
|
-
const config: ManagedConfig = { version: 1, system: "test", model: { protocol: "scripted", script: "fixture" }, defaultPolicy: "open",
|
|
205
|
-
policies: { open: { fallback: "allow", tools: {} }, strict: { fallback: "deny", tools: { notify: "allow" } } } };
|
|
206
|
-
const opened = createMemoryStorageAdapter().open({ mode: "create", identity: { sessionId: "s", compatibilityKey: "k" }, config });
|
|
207
|
-
if (!opened.ok) throw new Error(opened.error.message);
|
|
208
|
-
const effects: string[] = [];
|
|
209
|
-
const session = createSession({ systemPrompt: "test", storage: opened.value, config, configureTurn(turn, notify) { return { tools: [],
|
|
210
|
-
model: async messages => messages.at(-1)?.role === "tool" ? { role: "assistant", content: "done", calls: [] }
|
|
211
|
-
: { role: "assistant", content: null, calls: [{ id: `call-${turn.turnId}`, name: turn.channelId === "source" ? "notify" : "work", arguments: "{}" }] },
|
|
212
|
-
executeTool: async call => { effects.push(call.name); if (call.name === "notify") notify({ channelId: "target", fromChannelId: "source", text: "inherited" }); return "ok"; } }; } });
|
|
213
|
-
try {
|
|
214
|
-
expect(session.channels.create({ channelId: "target", policy: "open" }).ok).toBe(true);
|
|
215
|
-
session.start(); session.agent.send({ channelId: "source", participantId: "u", text: "hi", itemId: "m", policy: "strict" });
|
|
216
|
-
await until(() => session.snapshot().turns.some(turn => turn.channelId === "target" && turn.state.status === "completed"), "target notice turn");
|
|
217
|
-
expect(effects).toEqual(["notify"]);
|
|
218
|
-
const notice = session.snapshot().items.find(item => item.kind === "channel_notice")!;
|
|
219
|
-
expect(notice.policy).toMatchObject({ resolved: "open", inherited: ["strict"] });
|
|
220
|
-
const targetResult = session.snapshot().timeline.find(entry => entry.channelId === "target" && entry.message.role === "tool")!.message;
|
|
221
|
-
expect(targetResult.role === "tool" && JSON.parse(targetResult.content).code).toBe("policy_denied");
|
|
222
|
-
} finally { session.stop("done"); opened.value.close(); }
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
test("later approval-gated calls in a suspending iteration are paired without new requests", async () => {
|
|
226
|
-
const config: ManagedConfig = { version: 1, system: "test", model: { protocol: "scripted", script: "fixture" }, defaultPolicy: "ask",
|
|
227
|
-
policies: { ask: { fallback: "ask", tools: {} } } };
|
|
228
|
-
const opened = createMemoryStorageAdapter().open({ mode: "create", identity: { sessionId: "s", compatibilityKey: "k" }, config });
|
|
229
|
-
if (!opened.ok) throw new Error(opened.error.message);
|
|
230
|
-
const events: ChannelEvent[] = [], effects: string[] = [];
|
|
231
|
-
const session = createSession({ systemPrompt: "test", storage: opened.value, config, configureTurn() { return { tools: [],
|
|
232
|
-
model: async () => ({ role: "assistant", content: null, calls: [{ id: "one", name: "work", arguments: "{}" }, { id: "two", name: "work", arguments: "{}" }] }),
|
|
233
|
-
executeTool: async call => { effects.push(call.id); return "ok"; } }; } });
|
|
234
|
-
session.subscribe(event => events.push(event)); session.approvals.setConsumer(true);
|
|
235
|
-
try {
|
|
236
|
-
session.start(); session.agent.send({ channelId: "a", participantId: "u", text: "hi" });
|
|
237
|
-
await until(() => events.some(e => e.event.type === "approval_requested"), "first request");
|
|
238
|
-
expect((await session.channels.suspend("a")).ok).toBe(true);
|
|
239
|
-
expect(events.filter(e => e.event.type === "approval_requested")).toHaveLength(1);
|
|
240
|
-
const results = session.snapshot().timeline.filter(e => e.message.role === "tool").map(e => e.message.role === "tool" ? JSON.parse(e.message.content).code : "");
|
|
241
|
-
expect(results).toEqual(["approval_cancelled_by_suspension", "approval_cancelled_by_suspension"]); expect(effects).toEqual([]);
|
|
242
|
-
} finally { session.stop("done"); opened.value.close(); }
|
|
243
|
-
});
|
|
244
|
-
|
|
245
|
-
for (const scope of ["channel", "session"] as const) test(`reentrant stop while ${scope} suspension closes an approval settles the suspension`, async () => {
|
|
246
|
-
const r = rig("ask"); r.session.approvals.setConsumer(true);
|
|
247
|
-
try {
|
|
248
|
-
r.send("a", "one"); await until(() => !!r.approval(), "request");
|
|
249
|
-
const unsubscribe = r.session.store.subscribe(() => r.session.stop("reentrant stop"));
|
|
250
|
-
const result = scope === "channel" ? await r.session.channels.suspend("a") : await r.session.suspend();
|
|
251
|
-
unsubscribe(); expect(result).toMatchObject({ ok: false, error: { code: "stopped" } });
|
|
252
|
-
expect(r.effects).toEqual([]); expect(r.tools()).toHaveLength(1);
|
|
253
|
-
expect(r.session.snapshot().turns[0]!.state).toMatchObject({ status: "interrupted", uncertainCallIds: [] });
|
|
254
|
-
} finally { r.close(); }
|
|
255
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { inspectOperatorView } from "./helpers/operator-view.ts";
|
|
2
|
-
import { expect, spyOn, test } from "bun:test";
|
|
3
|
-
import { createInProcessHarness } from "../src/testing.ts";
|
|
4
|
-
import { spawnHarness } from "./helpers/stdio.ts";
|
|
5
|
-
import { createApprovalService } from "../src/governance/permissions/gate.ts";
|
|
6
|
-
import type { ChannelEvent } from "../src/contracts/events.ts";
|
|
7
|
-
import { mkdtempSync, rmSync } from "node:fs";
|
|
8
|
-
import { tmpdir } from "node:os";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
|
|
11
|
-
const script = new URL("./fixtures/echo-scenario.jsonl", import.meta.url).pathname;
|
|
12
|
-
const config = { version: 1 as const, system: "test", model: { protocol: "scripted" as const, script }, defaultPolicy: "ask",
|
|
13
|
-
policies: { ask: { fallback: "ask" as const, tools: {} } } };
|
|
14
|
-
const init = { protocolVersion: 1, host: { name: "test", version: "0" }, callbacks: [], subscription: { text: "final" as const, tools: "none" as const } };
|
|
15
|
-
const push = { channel: "a", item: { id: "m", kind: "user_message" as const, sender: "u", content: [{ type: "text" as const, text: "hello" }] } };
|
|
16
|
-
const until = async (check: () => boolean) => { for (let i = 0; i < 500; i++) { if (check()) return; await new Promise(r => setTimeout(r, 5)); } throw new Error("timed out"); };
|
|
17
|
-
for (const transport of ["in-process", "stdio"] as const) test(`${transport}: approval event is always sent and answer is one-time`, async () => {
|
|
18
|
-
const harness = transport === "stdio" ? spawnHarness() : createInProcessHarness();
|
|
19
|
-
try {
|
|
20
|
-
await harness.client.initialize({ ...init, approval: true });
|
|
21
|
-
await harness.client.createSession({ sessionId: "s", config, participants: [], channels: {} });
|
|
22
|
-
const events: ChannelEvent[] = []; harness.client.onChannelEvent(event => events.push(event));
|
|
23
|
-
await harness.client.push(push); await until(() => events.some(event => event.event.type === "approval_requested"));
|
|
24
|
-
const request = events.find(event => event.event.type === "approval_requested")!.event;
|
|
25
|
-
if (request.type !== "approval_requested") throw new Error("missing request");
|
|
26
|
-
expect(request).toMatchObject({ channel: "a", turnId: "1", toolCallId: "echo-1", tool: "echo" });
|
|
27
|
-
expect(await harness.client.respondApproval(request.requestId, "allow_once")).toEqual({ accepted: true });
|
|
28
|
-
await expect(harness.client.respondApproval(request.requestId, "allow_once")).rejects.toMatchObject({ code: "not_found" });
|
|
29
|
-
await until(() => events.some(event => event.event.type === "turn_ended"));
|
|
30
|
-
expect(events.some(event => event.event.type === "tool_call")).toBe(false); // subscription hides tools, not approvals
|
|
31
|
-
} finally { await harness.close(); }
|
|
32
|
-
}, 10000);
|
|
33
|
-
|
|
34
|
-
for (const approval of [undefined, false, "true"] as const) test(`only boolean true declares approval handling (${String(approval)})`, async () => {
|
|
35
|
-
const harness = createInProcessHarness();
|
|
36
|
-
try {
|
|
37
|
-
await harness.client.initialize({ ...init, ...(approval === undefined ? {} : { approval }) } as any);
|
|
38
|
-
await harness.client.createSession({ sessionId: "s", config, participants: [], channels: {} });
|
|
39
|
-
const events: ChannelEvent[] = []; harness.client.onChannelEvent(event => events.push(event));
|
|
40
|
-
await harness.client.push(push); await until(() => events.some(event => event.event.type === "turn_ended"));
|
|
41
|
-
expect(events.some(event => event.event.type === "approval_requested")).toBe(false);
|
|
42
|
-
} finally { harness.close(); }
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("default approval timer is ten minutes and disconnect records once", async () => {
|
|
46
|
-
const delays: number[] = [], original = globalThis.setTimeout;
|
|
47
|
-
const timer = spyOn(globalThis, "setTimeout").mockImplementation(((callback: (...args: any[]) => void, delay?: number, ...args: any[]) => {
|
|
48
|
-
delays.push(delay ?? 0); return original(callback, delay, ...args);
|
|
49
|
-
}) as typeof setTimeout);
|
|
50
|
-
try {
|
|
51
|
-
const recorded: string[] = [], service = createApprovalService(() => {}); service.setConsumer(true);
|
|
52
|
-
const signal = new AbortController(), suspension = new AbortController();
|
|
53
|
-
const request = service.request({ requestId: "r", channel: "a", turnId: "1", toolCallId: "c", tool: "work", arguments: "{}" }, signal.signal, suspension.signal, content => recorded.push(content));
|
|
54
|
-
expect(delays).toContain(600_000); service.disconnect();
|
|
55
|
-
expect((await request.answer).allowed).toBe(false); expect(recorded).toHaveLength(1);
|
|
56
|
-
expect(JSON.parse(recorded[0]!).code).toBe("approval_disconnected");
|
|
57
|
-
} finally { timer.mockRestore(); }
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
test("closing the in-process approval consumer records disconnect and lets the turn continue", async () => {
|
|
61
|
-
const harness = createInProcessHarness({ captureRequests: true }), events: ChannelEvent[] = [];
|
|
62
|
-
harness.server.subscribe(notification => events.push(notification.params));
|
|
63
|
-
try {
|
|
64
|
-
await harness.client.initialize({ ...init, approval: true });
|
|
65
|
-
await harness.client.createSession({ sessionId: "s", config, participants: [], channels: {} });
|
|
66
|
-
await harness.client.push(push); await until(() => events.some(event => event.event.type === "approval_requested"));
|
|
67
|
-
harness.client.close();
|
|
68
|
-
await until(() => events.some(event => event.event.type === "turn_ended"));
|
|
69
|
-
const request = harness.models.get("a")![1]!;
|
|
70
|
-
const result = request.messages.findLast(message => message.role === "tool");
|
|
71
|
-
expect(result?.role === "tool" && JSON.parse(result.content).code).toBe("approval_disconnected");
|
|
72
|
-
expect(events.some(event => event.event.type === "tool_call" && event.event.status === "started")).toBe(false);
|
|
73
|
-
} finally { harness.close(); }
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test("an approval pending at a real process crash cannot authorize work after restart", async () => {
|
|
77
|
-
const home = mkdtempSync(join(tmpdir(), "approval-crash-")), first = spawnHarness({ home });
|
|
78
|
-
try {
|
|
79
|
-
await first.client.initialize({ ...init, approval: true });
|
|
80
|
-
await first.client.createSession({ sessionId: "s", config, participants: [], channels: {} });
|
|
81
|
-
const events: ChannelEvent[] = []; first.client.onChannelEvent(event => events.push(event));
|
|
82
|
-
await first.client.push(push); await until(() => events.some(event => event.event.type === "approval_requested"));
|
|
83
|
-
const request = events.find(event => event.event.type === "approval_requested")!.event;
|
|
84
|
-
if (request.type !== "approval_requested") throw new Error("missing request");
|
|
85
|
-
first.child.kill("SIGKILL"); await first.child.exited; first.client.close();
|
|
86
|
-
const second = spawnHarness({ home });
|
|
87
|
-
try {
|
|
88
|
-
await second.client.initialize({ ...init, approval: true });
|
|
89
|
-
const loaded = await inspectOperatorView(second.client, { sessionId: "s" });
|
|
90
|
-
expect(loaded.turns).toMatchObject([{ turnId: "1", state: "interrupted", uncertainCalls: [] }]);
|
|
91
|
-
await expect(second.client.respondApproval(request.requestId, "allow_once")).rejects.toMatchObject({ code: "not_found" });
|
|
92
|
-
} finally { await second.close(); }
|
|
93
|
-
} finally { first.client.close(); first.child.kill(); rmSync(home, { recursive: true, force: true }); }
|
|
94
|
-
}, 10000);
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "bun:test";
|
|
2
|
-
|
|
3
|
-
test("kernel imports only contracts, and contracts have no runtime dependencies", async () => {
|
|
4
|
-
const root = new URL("../src/", import.meta.url).pathname;
|
|
5
|
-
for (const folder of ["kernel", "contracts"]) {
|
|
6
|
-
for await (const relative of new Bun.Glob("**/*.ts").scan(`${root}${folder}`)) {
|
|
7
|
-
const source = await Bun.file(`${root}${folder}/${relative}`).text();
|
|
8
|
-
const imports = [...source.matchAll(/import\s+(type\s+)?[^;]*?from\s+["']([^"']+)["']/g)];
|
|
9
|
-
for (const match of imports) {
|
|
10
|
-
if (folder === "kernel") expect(match[2]?.startsWith("../contracts/")).toBe(true);
|
|
11
|
-
else {
|
|
12
|
-
expect(match[1]).toBe("type ");
|
|
13
|
-
expect(match[2]?.startsWith("./")).toBe(true);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
});
|