@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
|
@@ -16,7 +16,7 @@ import type { Message } from "./loop.ts";
|
|
|
16
16
|
/** Expected failures never require callers to inspect SQLite or exception text. */
|
|
17
17
|
export type StorageErrorCode =
|
|
18
18
|
| "already_exists" | "not_found" | "owner_conflict" | "incompatible"
|
|
19
|
-
| "invalid_input" | "invalid_state" | "invalid_policy" | "closed"
|
|
19
|
+
| "invalid_input" | "invalid_config" | "invalid_state" | "invalid_policy" | "closed"
|
|
20
20
|
/** The item ID was accepted earlier with a different payload signature. */
|
|
21
21
|
| "item_conflict"
|
|
22
22
|
/** The session lifecycle does not admit this work (suspending/suspended). */
|
|
@@ -30,7 +30,7 @@ export type StorageErrorCode =
|
|
|
30
30
|
/** Export refused: active or pending work exists and the session is not suspended. */
|
|
31
31
|
| "busy"
|
|
32
32
|
| "invalid_archive"
|
|
33
|
-
| "serialization_error" | "storage_failure" | "transfer_limit" | "invalid_cursor";
|
|
33
|
+
| "serialization_error" | "storage_failure" | "transfer_limit" | "invalid_cursor" | "unsupported_image" | "attachment_unavailable";
|
|
34
34
|
|
|
35
35
|
/** A failed mutation leaves no partial domain changes. Do not retry blindly. */
|
|
36
36
|
export interface StorageError { code: StorageErrorCode; message: string }
|
|
@@ -79,7 +79,7 @@ export interface StoredSession {
|
|
|
79
79
|
sessionId: string;
|
|
80
80
|
/** Storage contract/data format revision, distinct from RPC and archive versions.
|
|
81
81
|
* Revision 5 stores model calls and script reservations. Formats 2–4 upgrade on open. */
|
|
82
|
-
formatVersion: 6 | 7;
|
|
82
|
+
formatVersion: 6 | 7 | 8 | 9 | 10;
|
|
83
83
|
createdAt: string;
|
|
84
84
|
lifecycle: SessionLifecycle;
|
|
85
85
|
/** The key supplied at create. Immutable; open never rewrites it. */
|
|
@@ -133,6 +133,8 @@ export interface AcceptItem {
|
|
|
133
133
|
inheritedPolicyNames?: readonly string[];
|
|
134
134
|
/** Original payload, kept unrendered for the life of the item. */
|
|
135
135
|
text: string;
|
|
136
|
+
/** Ordered mixed input; absent for legacy text-only identity. */
|
|
137
|
+
parts?: readonly import("./attachments.ts").InputPart[];
|
|
136
138
|
}
|
|
137
139
|
|
|
138
140
|
/** An accepted input. While `milestone` is `received` it is pending: in the
|
|
@@ -222,6 +224,7 @@ export interface StorageSnapshot {
|
|
|
222
224
|
/** Decision 0021: names of revocable tools whose grant is revoked, sorted.
|
|
223
225
|
* Absent when none ever was. Carried by export and import. */
|
|
224
226
|
revokedTools?: string[];
|
|
227
|
+
webDispatches?: import("./web.ts").StoredWebDispatch[];
|
|
225
228
|
}
|
|
226
229
|
|
|
227
230
|
/** Logical, adapter-independent session copy. JSON-serializable. Versioned
|
|
@@ -229,7 +232,10 @@ export interface StorageSnapshot {
|
|
|
229
232
|
* Version 5 adds external notices. */
|
|
230
233
|
export interface SessionArchive {
|
|
231
234
|
format: "harness-session";
|
|
232
|
-
archiveVersion: 5 | 6;
|
|
235
|
+
archiveVersion: 5 | 6 | 7 | 8 | 9;
|
|
236
|
+
/** Complete retained managed bytes, only in logical archive 8. */
|
|
237
|
+
webState?: { baseFormat: 6 | 7 | 8 | 9 };
|
|
238
|
+
attachmentState?: { baseFormat: 6 | 7 | 8; files: Array<{ metadata: import("./attachments.ts").AttachmentMetadata; readyAt: string; bytes: Uint8Array }> };
|
|
233
239
|
reminderState?: import("./reminders.ts").ReminderArchiveState;
|
|
234
240
|
exportedAt: string;
|
|
235
241
|
snapshot: StorageSnapshot;
|
|
@@ -291,20 +297,30 @@ export interface TimelineRetrievalReads {
|
|
|
291
297
|
}
|
|
292
298
|
|
|
293
299
|
export interface ReminderStorage {
|
|
294
|
-
scheduleAgentReminder(turnId: number, invocationId: string, schedule: import("./reminders.ts").AgentReminderSchedule, text: string,
|
|
295
|
-
policyNames: readonly string[], expiresAfter: number | null | undefined, now: number): StorageResult<{ reminder: import("./reminders.ts").Reminder; created: boolean }>;
|
|
300
|
+
scheduleAgentReminder(turnId: number, invocationId: string, schedule: import("./reminders.ts").AgentReminderSchedule | import("./reminders.ts").RoutineSchedule, text: string,
|
|
301
|
+
policyNames: readonly string[], expiresAfter: number | null | undefined, now: number, delivery?: import("./reminders.ts").RoutineDeliveryOptions): StorageResult<{ reminder: import("./reminders.ts").Reminder; created: boolean }>;
|
|
296
302
|
cancelAgentReminder(turnId: number, id: string): StorageResult<{ id: string; alreadyQueued: boolean; changed: boolean }>;
|
|
297
|
-
changeReminder(change: import("./reminders.ts").
|
|
298
|
-
readReminder(id: string): StorageResult<import("./reminders.ts").
|
|
303
|
+
changeReminder(change: import("./reminders.ts").ReminderChange, now: number): StorageResult<import("./reminders.ts").ReminderChangeResult>;
|
|
304
|
+
readReminder(id: string): StorageResult<import("./reminders.ts").Reminder | undefined>;
|
|
299
305
|
listReminders(input: import("./reminders.ts").ReminderListParams): StorageResult<import("./reminders.ts").ReminderList>;
|
|
300
306
|
reminderWake(): StorageResult<import("./reminders.ts").ReminderWake>;
|
|
301
307
|
fireDueReminders(now: number): StorageResult<Array<{ channel: string; event: import("./reminders.ts").ReminderChannelEvent }>>;
|
|
302
308
|
}
|
|
303
309
|
|
|
304
310
|
export interface SessionStorage extends ModelCallStore, ReminderStorage, TimelineRetrievalReads, OperatorStorageReads, InferenceStorageReads, InspectionStorageReads {
|
|
311
|
+
/** Owner-only publication fence. The managed-byte owner calls this only
|
|
312
|
+
* after it has verified and durably published the immutable bytes. */
|
|
313
|
+
registerReadyAttachment(metadata: import("./attachments.ts").AttachmentMetadata): StorageResult<void>;
|
|
314
|
+
/** Owner-scoped metadata and timeline visibility; bytes are read separately. */
|
|
315
|
+
readManagedAttachment(id: string): StorageResult<{ metadata: import("./attachments.ts").AttachmentMetadata; timelineVisible: boolean } | undefined>;
|
|
316
|
+
/** IDs with committed ready metadata, for owner-only crash recovery. */
|
|
317
|
+
managedAttachmentIds(): StorageResult<string[]>;
|
|
318
|
+
/** Owner-only cleanup fence; accepted references prevent reclamation. */
|
|
319
|
+
unreferencedAttachments(readyBefore: string): StorageResult<import("./attachments.ts").AttachmentMetadata[]>;
|
|
320
|
+
reclaimAttachment(id: string, readyBefore: string): StorageResult<boolean>;
|
|
305
321
|
readSession(): StorageResult<StoredSession>;
|
|
306
322
|
readExecution(): StorageResult<Pick<StorageSnapshot, "revision" | "session" | "channels" | "turns" | "items">>;
|
|
307
|
-
readReadyChannels(): StorageResult<{ lifecycle: SessionLifecycle; channels: string[] }>;
|
|
323
|
+
readReadyChannels(intake?: IntakeLimit): StorageResult<{ lifecycle: SessionLifecycle; channels: string[] }>;
|
|
308
324
|
readRevokedTools(): StorageResult<string[]>;
|
|
309
325
|
/** Validated config supplied to this open, copied at bind time; undefined for
|
|
310
326
|
* legacy allow-only opens. Returns a defensive copy. It is independent of
|
|
@@ -315,9 +331,12 @@ export interface SessionStorage extends ModelCallStore, ReminderStorage, Timelin
|
|
|
315
331
|
* dispatched. Invalid or duplicate marks write nothing; failure cannot invoke
|
|
316
332
|
* the tool or emit started. After success its effect is uncertain until its
|
|
317
333
|
* result commits. This evidence is never an approval grant. */
|
|
318
|
-
markToolDispatched(turnId: number, callId: string): StorageResult<void>;
|
|
334
|
+
markToolDispatched(turnId: number, callId: string, evidence?: import("./web.ts").WebDispatchEvidence): StorageResult<void>;
|
|
319
335
|
/** False when stored policy references cannot be resolved by this owner. */
|
|
336
|
+
unattendedGuard(): StorageResult<number | undefined>;
|
|
320
337
|
executionCompatible(): StorageResult<boolean>;
|
|
338
|
+
/** Bind the current open catalog before any checkpoint can run. */
|
|
339
|
+
bindMcpCatalog?(fingerprint: string): void;
|
|
321
340
|
/** Imported configuration, or undefined for sessions not imported from a file. */
|
|
322
341
|
importedConfig(): StorageResult<import("./session-file.ts").PortableSessionConfig | undefined>;
|
|
323
342
|
/** Persist the validated configuration used by this owner. */
|
|
@@ -339,7 +358,7 @@ export interface SessionStorage extends ModelCallStore, ReminderStorage, Timelin
|
|
|
339
358
|
* Nothing is added to the timeline and no turn is created or changed. */
|
|
340
359
|
/** External notice retries compare durable identity before admission or
|
|
341
360
|
* policy validation for new work, through a path that writes nothing. */
|
|
342
|
-
acceptItem(input: AcceptItem, maxInputBytes?: number): StorageResult<{ item: StoredItem; duplicate: boolean }>;
|
|
361
|
+
acceptItem(input: AcceptItem, maxInputBytes?: number, options?: { imageInput?: boolean }): StorageResult<{ item: StoredItem; duplicate: boolean }>;
|
|
343
362
|
|
|
344
363
|
/** Start the channel's next turn by taking ALL its pending items, in
|
|
345
364
|
* acceptance order, in one transaction: create the running turn, move each
|
|
@@ -433,7 +452,7 @@ export interface SessionStorage extends ModelCallStore, ReminderStorage, Timelin
|
|
|
433
452
|
* pending items all unchanged), if any turn being resumed has a
|
|
434
453
|
* compatibilityKey different from the key passed to this open. Already running
|
|
435
454
|
* returns no turns; `suspending` is `invalid_state`. */
|
|
436
|
-
resume(): StorageResult<{ session: StoredSession; turns: StoredTurn[]; unblockedReminders?: import("./reminders.ts").
|
|
455
|
+
resume(): StorageResult<{ session: StoredSession; turns: StoredTurn[]; unblockedReminders?: import("./reminders.ts").Reminder[] }>;
|
|
437
456
|
|
|
438
457
|
/** Stop, in one transaction, by lifecycle:
|
|
439
458
|
* - `running`: every running turn becomes interrupted.
|
|
@@ -494,7 +513,7 @@ export interface SessionStorage extends ModelCallStore, ReminderStorage, Timelin
|
|
|
494
513
|
* the checkpoint stays under the session suspension, no turn runs, and the
|
|
495
514
|
* session's own resume continues it. Pending items become eligible once both
|
|
496
515
|
* lifecycles permit. */
|
|
497
|
-
resumeChannel(channelId: string): StorageResult<{ channel: StoredChannel; turn?: StoredTurn; unblockedReminders?: import("./reminders.ts").
|
|
516
|
+
resumeChannel(channelId: string): StorageResult<{ channel: StoredChannel; turn?: StoredTurn; unblockedReminders?: import("./reminders.ts").Reminder[] }>;
|
|
498
517
|
|
|
499
518
|
/** Retire the channel: `retired` is final and the ID is reserved. Refused with
|
|
500
519
|
* `channel_busy`, changing nothing, while the channel has a running or
|
|
@@ -82,6 +82,8 @@ export interface ToolInvocation {
|
|
|
82
82
|
* repeats such a call. `none`: it never dispatched. */
|
|
83
83
|
effect?: "none" | "unknown";
|
|
84
84
|
reference?: ResultReference;
|
|
85
|
+
/** Durable per-invocation provider usage, absent for legacy calls. */
|
|
86
|
+
webUsage?: import("./web.ts").WebUsageView;
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
/** What the turn is doing now, with the ID of the model call, approval request
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Immutable non-secret dispatch evidence, committed before external effects. */
|
|
2
|
+
export type WebDispatchEvidence = { backend: "exa"; operation: "web_search" | "web_fetch"; paid: true } | { backend: "http"; operation: "web_fetch"; paid: false };
|
|
3
|
+
/** Provider-reported metadata; committed atomically with the paired result. */
|
|
4
|
+
export interface WebResultUsage { requestId?: string; usd?: number }
|
|
5
|
+
export interface StoredWebDispatch { turnId: number; callId: string; evidence: WebDispatchEvidence }
|
|
6
|
+
export type WebCost = { kind: "none" } | { kind: "unknown" } | { kind: "provider_estimate"; usd: number };
|
|
7
|
+
export interface WebUsageView { backend?: "exa" | "http"; operation?: "web_search" | "web_fetch"; requestId?: string; cost: WebCost }
|
|
8
|
+
export type WebToolError = "blocked_destination" | "unsupported_content" | "invalid_arguments" | "rate_limited" | "provider_error" | "tool_timeout" | "page_unavailable" | "result_too_large" | "tool_interrupted" | "response_too_large";
|
|
9
|
+
export type WebToolResponse = { ok: true; content: string; usage: WebResultUsage } | { ok: false; code: WebToolError; message: string; usage: WebResultUsage };
|
|
10
|
+
/** Trusted local tool assembly; dispatch metadata is frozen for this open. */
|
|
11
|
+
export interface CheckedWebRegistration {
|
|
12
|
+
definition: import("./loop.ts").ToolDefinition;
|
|
13
|
+
validate(args: unknown): string | undefined;
|
|
14
|
+
dispatch: WebDispatchEvidence;
|
|
15
|
+
execute(args: unknown, signal: AbortSignal): Promise<WebToolResponse>;
|
|
16
|
+
}
|
|
@@ -88,7 +88,7 @@ export async function dispatchWithPolicy(options: {
|
|
|
88
88
|
* available, invalid arguments), or undefined. Read before authorization
|
|
89
89
|
* and again at the dispatch boundary. Policy denial retains precedence. */
|
|
90
90
|
refuse?(): { code: string; detail?: string } | undefined;
|
|
91
|
-
}): Promise<{ content: string; dispatched: boolean; outcome?: ToolOutcome }> {
|
|
91
|
+
}): Promise<{ content: string; dispatched: boolean; outcome?: ToolOutcome; usage?: import("../../contracts/web.ts").WebResultUsage }> {
|
|
92
92
|
const { call, signal, suspension } = options;
|
|
93
93
|
const skip = (code: string, detail?: string) => { const content = skipped(code, detail); options.recordSkip(content, code); return { content, dispatched: false }; };
|
|
94
94
|
signal.throwIfAborted();
|
|
@@ -117,6 +117,13 @@ export async function dispatchWithPolicy(options: {
|
|
|
117
117
|
if (request && !request.discard("tool_unavailable")) return { content: "", dispatched: false };
|
|
118
118
|
return skip(late.code, late.detail);
|
|
119
119
|
}
|
|
120
|
+
const currentRule = options.decide();
|
|
121
|
+
if (currentRule === "deny") {
|
|
122
|
+
if (request && !request.discard("tool_unavailable")) return { content: "", dispatched: false };
|
|
123
|
+
return skip("policy_denied");
|
|
124
|
+
}
|
|
125
|
+
// A rule that became ask cannot reuse an earlier allow without a grant.
|
|
126
|
+
if (rule === "allow" && currentRule === "ask") return dispatchWithPolicy(options);
|
|
120
127
|
if (request && !request.consume()) return { content: "", dispatched: false };
|
|
121
128
|
try { options.mark(); } catch (error) { request?.dispatchFailed(); throw error; }
|
|
122
129
|
let result: ReturnType<typeof options.execute>;
|
|
@@ -125,5 +132,5 @@ export async function dispatchWithPolicy(options: {
|
|
|
125
132
|
options.started();
|
|
126
133
|
request?.dispatchClosed();
|
|
127
134
|
const settled = await result;
|
|
128
|
-
return typeof settled === "string" ? { content: settled, dispatched: true } : { content: settled.content, dispatched: true, outcome: settled.outcome };
|
|
135
|
+
return typeof settled === "string" ? { content: settled, dispatched: true } : { content: settled.content, dispatched: true, outcome: settled.outcome, ...(settled.usage ? { usage: settled.usage } : {}) };
|
|
129
136
|
}
|
|
@@ -11,6 +11,10 @@ export function resolvePolicy(config: ManagedConfig, explicit?: string | null, c
|
|
|
11
11
|
}
|
|
12
12
|
/** A taken input contributes all its policy names; no pending input is passed. */
|
|
13
13
|
export function toolDecision(config: ManagedConfig, references: readonly string[], tool: string): ToolDecision {
|
|
14
|
+
if (tool.startsWith("mcp__")) {
|
|
15
|
+
return references.length > 0 && references.every(name => name !== "__legacy_allow" &&
|
|
16
|
+
Object.hasOwn(config.policies, name) && config.policies[name]?.mcp === "allow") ? "allow" : "deny";
|
|
17
|
+
}
|
|
14
18
|
if (!references.length) throw new Error("Cannot authorize a turn without taken-input policies");
|
|
15
19
|
let result: ToolDecision = "allow";
|
|
16
20
|
for (const reference of new Set(references)) {
|
|
@@ -27,6 +31,7 @@ export function policyFingerprint(config: ManagedConfig, references: readonly st
|
|
|
27
31
|
return JSON.stringify([...new Set(references)].sort().map(name => {
|
|
28
32
|
if (!Object.hasOwn(config.policies, name)) throw new PolicyError(name);
|
|
29
33
|
const policy = config.policies[name]!;
|
|
30
|
-
return [name, policy.fallback, Object.keys(policy.tools).sort().map(tool => [tool, policy.tools[tool]])
|
|
34
|
+
return [name, policy.fallback, Object.keys(policy.tools).sort().map(tool => [tool, policy.tools[tool]]),
|
|
35
|
+
...(policy.mcp === undefined ? [] : [["mcp-v1", policy.mcp]])];
|
|
31
36
|
}));
|
|
32
37
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isWebTool } from "./capabilities/tools/web/definitions.ts";
|
|
2
|
+
import { guardedReminderDefinitions, executeReminderTool, isReminderTool, reminderAction, reminderDefinitions } from "./capabilities/tools/reminders/index.ts";
|
|
2
3
|
import { createReminderRuntime } from "./runtime/reminders.ts";
|
|
3
4
|
import { wallReminderClock } from "./runtime/reminder-timer.ts";
|
|
4
5
|
import type { ReminderSessionEvent } from "./contracts/reminders.ts";
|
|
@@ -63,6 +64,9 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
63
64
|
const read = () => { const view = store.snapshot(); if (!view.ok) throw new Error(view.error.message); return view.value; };
|
|
64
65
|
// Every published event follows a commit, so it is also the moment the
|
|
65
66
|
// timeline projection may have changed.
|
|
67
|
+
const unattended = store.unattendedGuard();
|
|
68
|
+
if (!unattended.ok) throw new Error(unattended.error.message);
|
|
69
|
+
const sessionReminderDefinitions = unattended.value === undefined ? reminderDefinitions : guardedReminderDefinitions;
|
|
66
70
|
const identity = store.readSession();
|
|
67
71
|
if (!identity.ok) throw new Error(identity.error.message);
|
|
68
72
|
const context = createSessionContext(store, identity.value.sessionId, options.systemPrompt, CONTEXT_LIMITS, options.captureContext);
|
|
@@ -77,12 +81,21 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
77
81
|
};
|
|
78
82
|
const config = owner.value ?? { version: 1 as const, system: options.systemPrompt, model: { protocol: "scripted" as const, script: "legacy" },
|
|
79
83
|
defaultPolicy: "__legacy_allow", policies: { __legacy_allow: { fallback: "allow" as const, tools: {} } } };
|
|
84
|
+
if (options.imageInput && (config.model.protocol === "openai-compatible" || config.model.imageInput !== true)) throw new Error("Image input requires explicit model configuration");
|
|
85
|
+
if (options.config?.mcpServers !== undefined) {
|
|
86
|
+
const canonical = (value: unknown) => JSON.stringify(value, (_key, object) =>
|
|
87
|
+
object && typeof object === "object" && !Array.isArray(object)
|
|
88
|
+
? Object.fromEntries(Object.keys(object).sort().map(key => [key, object[key]])) : object);
|
|
89
|
+
store.bindMcpCatalog?.(canonical([options.config.mcpServers,
|
|
90
|
+
[...(options.mcpTools?.values() ?? [])].map(tool => tool.definition).sort((a, b) => a.name.localeCompare(b.name))]));
|
|
91
|
+
}
|
|
80
92
|
// ---- Tools, decision 0021. The catalog's definitions come from the open;
|
|
81
93
|
// the revoked set mirrors storage; the executor belongs to the connection.
|
|
82
|
-
const
|
|
94
|
+
const catalogInput = options.catalog ?? ((options.webTools?.length || options.mcpTools?.size) ? { catalog: [] } : undefined);
|
|
95
|
+
const revoked = catalogInput ? store.readRevokedTools() : undefined;
|
|
83
96
|
if (revoked && !revoked.ok) throw new Error(revoked.error.message);
|
|
84
|
-
if (options.catalog?.catalog.some(tool => isTimelineTool(tool.name) || isReminderTool(tool.name))) throw new Error("Native tool names are reserved");
|
|
85
|
-
const catalog =
|
|
97
|
+
if (options.catalog?.catalog.some(tool => isTimelineTool(tool.name) || isReminderTool(tool.name) || isWebTool(tool.name) || tool.name.startsWith("mcp__"))) throw new Error("Native tool names are reserved");
|
|
98
|
+
const catalog = catalogInput ? createToolCatalog(catalogInput, revoked?.value ?? []) : undefined;
|
|
86
99
|
const limits = { ...TOOL_LIMITS, ...options.toolLimits };
|
|
87
100
|
let executor: FunctionExecutor | undefined;
|
|
88
101
|
/** What each running turn is doing now. Process state, cleared when the turn's run ends. */
|
|
@@ -109,7 +122,8 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
109
122
|
const offer = (policies: readonly string[]): { tools: ToolDefinition[]; fixedToolCount?: number } => {
|
|
110
123
|
const allowed = <T extends ToolDefinition>(tools: readonly T[]) => tools.filter(tool => toolDecision(config, policies, tool.name) !== "deny");
|
|
111
124
|
const definition = ({ name, description, parameters }: ToolDefinition): ToolDefinition => ({ name, description, parameters });
|
|
112
|
-
const builtins = allowed([...services.tools.filter(tool => tool.name !== "notify_channel" && !isTimelineTool(tool.name) && !isReminderTool(tool.name)), notifyChannelDefinition, ...
|
|
125
|
+
const builtins = allowed([...services.tools.filter(tool => tool.name !== "notify_channel" && !isTimelineTool(tool.name) && !isReminderTool(tool.name) && !isWebTool(tool.name) && !tool.name.startsWith("mcp__")), notifyChannelDefinition, ...sessionReminderDefinitions, ...(options.webTools ?? []).map(value => value.definition),
|
|
126
|
+
...[...(options.mcpTools?.values() ?? [])].filter(tool => tool.available()).map(tool => tool.definition),
|
|
113
127
|
...((owner.value === undefined ? options.timelineTools : config.timelineTools) ? timelineDefinitions : [])]);
|
|
114
128
|
if (!catalog) { offered = new Set(builtins.map(tool => tool.name)); return { tools: [...builtins] }; }
|
|
115
129
|
const available = catalog.offered();
|
|
@@ -134,7 +148,9 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
134
148
|
append,
|
|
135
149
|
dispatchTool(call, execute) {
|
|
136
150
|
const registration = catalog?.get(call.name), reader = !!catalog && call.name === READ_TOOL_RESULT;
|
|
137
|
-
const retrieval = isTimelineTool(call.name), reminder = isReminderTool(call.name);
|
|
151
|
+
const retrieval = isTimelineTool(call.name), reminder = isReminderTool(call.name), webName = isWebTool(call.name);
|
|
152
|
+
const mcpName = call.name.startsWith("mcp__"), mcp = options.mcpTools?.get(call.name);
|
|
153
|
+
const web = options.webTools?.find(value => value.definition.name === call.name);
|
|
138
154
|
const action = reminder ? reminderAction(call.name, JSON.parse(call.arguments)) : undefined;
|
|
139
155
|
const id = invocationId(turn.turnId, call.id);
|
|
140
156
|
let policies: readonly string[];
|
|
@@ -143,8 +159,19 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
143
159
|
decide: () => toolDecision(config, policies = policySnapshot(), call.name),
|
|
144
160
|
// Catalog tools and the reader must have been offered by this request,
|
|
145
161
|
// still be available, and carry arguments their definition accepts.
|
|
146
|
-
...(registration || reader || retrieval || reminder ? { refuse: () => {
|
|
162
|
+
...(registration || reader || retrieval || reminder || webName || mcpName ? { refuse: () => {
|
|
147
163
|
if (!offered.has(call.name)) return { code: "tool_unavailable", detail: "it was not offered for this request" };
|
|
164
|
+
if (mcpName) {
|
|
165
|
+
if (!mcp?.available()) return { code: "tool_unavailable", detail: "MCP binding is unavailable" };
|
|
166
|
+
let args: unknown; try { args = JSON.parse(call.arguments); } catch { return { code: "invalid_arguments", detail: "Invalid JSON" }; }
|
|
167
|
+
return mcp.accepts(args) ? undefined : { code: "invalid_arguments", detail: "MCP schema rejected arguments" };
|
|
168
|
+
}
|
|
169
|
+
if (webName) {
|
|
170
|
+
if (!web) return { code: "tool_unavailable", detail: "web backend is disabled" };
|
|
171
|
+
let args: unknown; try { args = JSON.parse(call.arguments); } catch { return { code: "invalid_arguments", detail: "Invalid JSON" }; }
|
|
172
|
+
const problem = web.validate(args);
|
|
173
|
+
return problem ? { code: "invalid_arguments", detail: problem } : undefined;
|
|
174
|
+
}
|
|
148
175
|
if (reminder) return action ? undefined : { code: "invalid_arguments", detail: "Invalid reminder arguments" };
|
|
149
176
|
if (retrieval) {
|
|
150
177
|
const detail = timelineArgumentsProblem(call.name, JSON.parse(call.arguments));
|
|
@@ -156,7 +183,15 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
156
183
|
const problem = schemaProblem(registration.parameters, JSON.parse(call.arguments));
|
|
157
184
|
return problem ? { code: "invalid_arguments", detail: problem } : undefined;
|
|
158
185
|
} } : {}),
|
|
159
|
-
execute:
|
|
186
|
+
execute: mcp ? async (_call, signal) => {
|
|
187
|
+
const result = await mcp.call(JSON.parse(call.arguments), signal ?? port.signal);
|
|
188
|
+
return { content: result.content, outcome: result.code ? { status: "failed", code: result.code } : { status: "succeeded" } };
|
|
189
|
+
} : web ? async (_call, signal) => {
|
|
190
|
+
const result = await web.execute(JSON.parse(call.arguments), signal ?? port.signal);
|
|
191
|
+
const usage = web.dispatch.paid && Object.keys(result.usage).length ? { usage: result.usage } : {};
|
|
192
|
+
return result.ok ? { content: result.content, outcome: { status: "succeeded" as const }, ...usage }
|
|
193
|
+
: { content: JSON.stringify({ ok: false, code: result.code, message: result.message }), outcome: { status: "failed" as const, code: result.code }, ...usage };
|
|
194
|
+
} : reminder ? async () => {
|
|
160
195
|
if (!action) throw new Error("Invalid reminder arguments");
|
|
161
196
|
return executeReminderTool(store, action, turn.channelId, turn.turnId, id, policies, reminderClock.now(),
|
|
162
197
|
(event, revision) => emit({ channel: turn.channelId, event, revision }));
|
|
@@ -173,13 +208,13 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
173
208
|
catch (error) { return JSON.stringify({ ok: false, error: String(error) }); }
|
|
174
209
|
} : execute,
|
|
175
210
|
recordSkip: (content, code) => {
|
|
176
|
-
append({ role: "tool", callId: call.id, content, outcome: { status: "skipped", code } });
|
|
211
|
+
append({ role: "tool", callId: call.id, content, outcome: { status: "skipped", code }, ...(webName ? { webNoDispatch: true as const } : {}) });
|
|
177
212
|
// Built-in tools keep their event stream as it was: a skip is silent.
|
|
178
|
-
if (registration || reader || retrieval || reminder) emit({ channel: turn.channelId, ...(recorded ? { revision: recorded.revision } : {}),
|
|
213
|
+
if (registration || reader || retrieval || reminder || webName || mcpName) emit({ channel: turn.channelId, ...(recorded ? { revision: recorded.revision } : {}),
|
|
179
214
|
event: { type: "tool_call", turnId: String(turn.turnId), id: call.id, name: call.name, status: "skipped", output: content, invocationId: id } });
|
|
180
215
|
},
|
|
181
216
|
mark: () => {
|
|
182
|
-
const result = store.markToolDispatched(turn.turnId, call.id); if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
217
|
+
const result = store.markToolDispatched(turn.turnId, call.id, web?.dispatch); if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
183
218
|
phase(turn.turnId, "tool", id);
|
|
184
219
|
},
|
|
185
220
|
started: () => emit({ channel: turn.channelId, event: { type: "tool_call", turnId: String(turn.turnId), id: call.id, name: call.name, status: "started", input: call.arguments, invocationId: id } }) });
|
|
@@ -229,7 +264,7 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
229
264
|
}
|
|
230
265
|
}, services.executeTool).finally(() => { phases.delete(turn.turnId); });
|
|
231
266
|
};
|
|
232
|
-
const scheduler = createChannelScheduler(store, options.wrapTurn?.(run) ?? run, emit, lifecycle.publish, CONTEXT_LIMITS);
|
|
267
|
+
const scheduler = createChannelScheduler(store, options.wrapTurn?.(run) ?? run, emit, lifecycle.publish, CONTEXT_LIMITS, options.imageInput === true);
|
|
233
268
|
agent = scheduler.agent;
|
|
234
269
|
/** Status with each running turn's phase, which only this process knows. */
|
|
235
270
|
const status = () => {
|
|
@@ -295,6 +330,7 @@ export function createSession(options: Omit<PersistentSessionOptions, "storage">
|
|
|
295
330
|
...(tools ? { tools } : {}),
|
|
296
331
|
reminders: {
|
|
297
332
|
readReminder: id => store.readReminder(id), listReminders: params => store.listReminders(params),
|
|
333
|
+
unattendedGuard: () => store.unattendedGuard(),
|
|
298
334
|
reminderWake: () => store.reminderWake(), change: change => reminderRuntime.change(change),
|
|
299
335
|
executable: reminderExecutable, processStartup, releaseTimer: reminderRuntime.stop, subscribeWake: reminderWakeEvents.subscribe,
|
|
300
336
|
conditionalStop(windowMs) {
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { openMcpRegistry } from "../../capabilities/tools/mcp/registry.ts";
|
|
2
|
+
import { createWebRegistry, directWebFetch } from "../../capabilities/tools/web/registry.ts";
|
|
3
|
+
import { exaHttpsTransport } from "../../capabilities/tools/web/exa-transport.ts";
|
|
4
|
+
import { compatibleInferenceKey } from "../../runtime/config/inference-key.ts";
|
|
1
5
|
import { createHash } from "node:crypto";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
6
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
3
7
|
import { dirname, join } from "node:path";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
4
9
|
import { createSession } from "../../index.ts";
|
|
5
10
|
import type { Model } from "../../contracts/loop.ts";
|
|
6
11
|
import type { PersistentSession, TurnServices } from "../../contracts/session.ts";
|
|
@@ -8,7 +13,7 @@ import { openRouter } from "../../capabilities/model/openrouter.ts";
|
|
|
8
13
|
import { loadScenario, scriptedCompatibilityKey } from "../../capabilities/model/scenario-file.ts";
|
|
9
14
|
import { scenarioAttempt } from "../../capabilities/model/scenario-attempt.ts";
|
|
10
15
|
import { bindModelAttempt } from "../../capabilities/model/attempt.ts";
|
|
11
|
-
import { openRouterAttempt } from "../../capabilities/model/openrouter-stream.ts";
|
|
16
|
+
import { openAICompatibleAttempt, openRouterAttempt } from "../../capabilities/model/openrouter-stream.ts";
|
|
12
17
|
import { currentTimeDefinition, executeCurrentTime } from "../../capabilities/tools/builtin/current-time.ts";
|
|
13
18
|
import { debugToolDefinitions, debugToolHandlers } from "../../capabilities/tools/debug/index.ts";
|
|
14
19
|
import { notifyChannelDefinition } from "../../capabilities/tools/builtin/notify-channel.ts";
|
|
@@ -18,7 +23,9 @@ import { createInspection } from "../inspector/state.ts";
|
|
|
18
23
|
import { observeModel, observeSession } from "../inspector/observe.ts";
|
|
19
24
|
import type { ManagedConfig } from "../../contracts/config-permissions.ts";
|
|
20
25
|
import { chooseManagedConfig } from "../../runtime/config/paths.ts";
|
|
21
|
-
import { resolveCredential, validateManagedConfig } from "../../runtime/config/managed.ts";
|
|
26
|
+
import { resolveCompatibleCredential, resolveCredential, validateManagedConfig } from "../../runtime/config/managed.ts";
|
|
27
|
+
import { createManagedAttachmentService } from "../../capabilities/attachments/service.ts";
|
|
28
|
+
import { imageValidationAvailable, validateManagedImage } from "../../capabilities/attachments/image-validation.ts";
|
|
22
29
|
|
|
23
30
|
export interface DevelopmentOptions {
|
|
24
31
|
systemPrompt: string;
|
|
@@ -26,6 +33,8 @@ export interface DevelopmentOptions {
|
|
|
26
33
|
instructions?: string;
|
|
27
34
|
/** SQLite file for a durable session; memory when omitted. */
|
|
28
35
|
database?: string;
|
|
36
|
+
/** Managed session media root; explicit databases default to PATH.media. */
|
|
37
|
+
mediaRoot?: string;
|
|
29
38
|
/** Expected ID for a named session, or the ID to assign on creation. */
|
|
30
39
|
sessionId?: string;
|
|
31
40
|
/** Create the database (it must not exist) instead of opening it. */
|
|
@@ -40,6 +49,8 @@ export interface DevelopmentOptions {
|
|
|
40
49
|
managedConfig?: ManagedConfig;
|
|
41
50
|
/** Provider injection and environment are useful for offline tests and hosts. */
|
|
42
51
|
providerFactory?: (apiKey: string, model: string, onRequest?: (body: string) => void) => Model;
|
|
52
|
+
/** Trusted offline test assembly; unavailable through managed config. */
|
|
53
|
+
webTransport?: import("../../capabilities/tools/web/exa.ts").ExaTransport;
|
|
43
54
|
/** Expose safe diagnostic tools for this process. */
|
|
44
55
|
debugTools?: boolean;
|
|
45
56
|
timelineTools?: boolean;
|
|
@@ -52,8 +63,8 @@ export interface DevelopmentOptions {
|
|
|
52
63
|
* listener: storage, real or scripted inference, tools and the
|
|
53
64
|
* inspector's view. Opening executes nothing; the caller starts or resumes. */
|
|
54
65
|
export async function openDevelopment(options: DevelopmentOptions) {
|
|
55
|
-
const sqlite = options.database ? createSqliteStorageAdapter(options.database) : undefined;
|
|
56
|
-
|
|
66
|
+
const sqlite = options.database ? createSqliteStorageAdapter(options.database, { mediaRoot: options.mediaRoot ?? `${options.database}.media` }) : undefined;
|
|
67
|
+
let adapter = sqlite ?? createMemoryStorageAdapter();
|
|
57
68
|
let sessionId = options.sessionId ?? "development";
|
|
58
69
|
if (options.database && !options.create && !existsSync(options.database))
|
|
59
70
|
throw new Error(`No session database at ${options.database}. Pass --create to create it.`);
|
|
@@ -82,64 +93,108 @@ export async function openDevelopment(options: DevelopmentOptions) {
|
|
|
82
93
|
managedConfig = { ...managedConfig, system: options.debugInstructions };
|
|
83
94
|
const systemPrompt = options.instructions ?? options.debugInstructions ?? managedConfig?.system ?? options.systemPrompt;
|
|
84
95
|
const scriptPath = managedConfig?.model.protocol === "scripted" ? managedConfig.model.script : undefined;
|
|
96
|
+
const compatible = managedConfig?.model.protocol === "openai-compatible" ? managedConfig.model : undefined;
|
|
97
|
+
const creating = !options.database || !!options.create;
|
|
98
|
+
const environment = options.environment ?? process.env;
|
|
99
|
+
let compatibleKey = compatible && creating ? resolveCompatibleCredential(compatible, environment) : undefined;
|
|
85
100
|
const providerModel = managedConfig?.model.protocol === "openrouter" ? managedConfig.model : undefined;
|
|
86
101
|
const apiKey = providerModel ? (useLegacyCredential ? options.provider!.apiKey : resolveCredential(providerModel, options.environment ?? process.env)) : undefined;
|
|
87
102
|
if (providerModel && !apiKey) throw new Error(`config.model.apiKeyEnv: environment variable ${providerModel.apiKeyEnv} is missing or empty`);
|
|
88
103
|
const script = scriptPath ? await loadScenario(scriptPath) : undefined;
|
|
89
|
-
if (!script && !providerModel) throw new Error("Development needs provider credentials or a script");
|
|
104
|
+
if (!script && !providerModel && !compatible) throw new Error("Development needs provider credentials or a script");
|
|
90
105
|
const scriptedTools = script ? options.scriptedTools : undefined;
|
|
91
106
|
const tools = [currentTimeDefinition, ...(scriptedTools?.tools ?? []),
|
|
92
107
|
...(options.debugTools ? debugToolDefinitions : []), notifyChannelDefinition];
|
|
93
|
-
|
|
94
|
-
|
|
108
|
+
let imageInput = managedConfig?.model.protocol !== "openai-compatible" && managedConfig?.model.imageInput === true && (managedConfig.model.protocol === "scripted" || !options.providerFactory) && imageValidationAvailable();
|
|
109
|
+
const compatibilityKey = compatible ? compatibleInferenceKey(compatible, systemPrompt, tools.map(tool => tool.name)) : script ? scriptedCompatibilityKey(script.modelDigest, systemPrompt + (managedConfig?.model.protocol !== "openai-compatible" && managedConfig?.model.imageInput === true ? "\n[image-input-enabled]" : ""))
|
|
110
|
+
: createHash("sha256").update(JSON.stringify([systemPrompt, providerModel!.model, tools.map(tool => tool.name), ...(managedConfig?.model.protocol !== "openai-compatible" && managedConfig?.model.imageInput === true ? ["image-input-enabled"] : [])])).digest("hex");
|
|
111
|
+
const tempMedia = sqlite ? undefined : mkdtempSync(join(tmpdir(), "harness-media-"));
|
|
112
|
+
const mediaRoot = options.database ? options.mediaRoot ?? `${options.database}.media` : join(tempMedia!, "media");
|
|
113
|
+
if (!sqlite) adapter = createMemoryStorageAdapter({ mediaRoot });
|
|
114
|
+
const makeWebTools = () => {
|
|
115
|
+
const result = createWebRegistry(managedConfig ?? {}, environment, { exa: options.webTransport ?? exaHttpsTransport, http: directWebFetch });
|
|
116
|
+
if (!result.ok) throw new Error(`${result.error.code}: ${result.error.message}`);
|
|
117
|
+
return result.value;
|
|
118
|
+
};
|
|
119
|
+
let webTools = creating ? makeWebTools() : undefined;
|
|
95
120
|
const opened = adapter.open({ mode: options.database && !options.create ? "open" : "create",
|
|
96
121
|
identity: { sessionId, compatibilityKey }, config: managedConfig, requiredScriptDigest: script?.modelDigest });
|
|
97
|
-
if (!opened.ok) throw new Error(`Cannot open session storage (${opened.error.code}): ${opened.error.message}`);
|
|
122
|
+
if (!opened.ok) { if (tempMedia) rmSync(tempMedia, { recursive: true, force: true }); throw new Error(`Cannot open session storage (${opened.error.code}): ${opened.error.message}`); }
|
|
98
123
|
const storage = opened.value;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
124
|
+
let mcp: Awaited<ReturnType<typeof openMcpRegistry>> | undefined;
|
|
125
|
+
let attachments: ReturnType<typeof createManagedAttachmentService> | undefined;
|
|
126
|
+
try {
|
|
127
|
+
const execution = storage.executionCompatible();
|
|
128
|
+
if (!execution.ok) throw new Error(execution.error.message);
|
|
129
|
+
if (!execution.value) imageInput = false;
|
|
130
|
+
else {
|
|
131
|
+
if (!creating) { if (compatible) compatibleKey = resolveCompatibleCredential(compatible, environment); webTools = makeWebTools(); }
|
|
132
|
+
if (managedConfig?.mcpServers) mcp = await openMcpRegistry(managedConfig, environment);
|
|
133
|
+
attachments = createManagedAttachmentService(mediaRoot, storage, validateManagedImage);
|
|
134
|
+
}
|
|
135
|
+
if (savedConfig) {
|
|
136
|
+
const saved = storage.saveConfig(savedConfig);
|
|
137
|
+
if (!saved.ok && saved.error.code !== "incompatible") throw new Error(`Cannot save config: ${saved.error.message}`);
|
|
138
|
+
}
|
|
103
139
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
140
|
+
let session: PersistentSession;
|
|
141
|
+
const inspection = createInspection(systemPrompt, [...tools, ...(webTools ?? []).map(value => value.definition),
|
|
142
|
+
...[...(mcp?.bindings.values() ?? [])].map(value => value.definition)], storage, options.database ?? "memory",
|
|
143
|
+
turnId => session.tools?.invocations(turnId) ?? []);
|
|
144
|
+
const captureScript = (options.environment ?? process.env).HARNESS_CAPTURE_SCRIPT_REQUESTS === "1";
|
|
145
|
+
session = createSession({
|
|
146
|
+
systemPrompt, storage, config: managedConfig, imageInput, webTools, mcpTools: mcp?.bindings, captureContext: (!script || captureScript) ? inspection.capture : undefined,
|
|
147
|
+
observeModelCall: inspection.modelCall,
|
|
148
|
+
configureTurn(turn) {
|
|
149
|
+
const model = observeModel(inspection, turn.channelId, onRequest => {
|
|
150
|
+
if (script || compatible) return async () => { throw new Error("Model requires a reserved attempt"); };
|
|
151
|
+
const provider = (options.providerFactory ?? openRouter)(apiKey!, providerModel!.model, onRequest);
|
|
152
|
+
return provider;
|
|
153
|
+
}, turn.turnId);
|
|
154
|
+
if (script) {
|
|
155
|
+
bindModelAttempt(model, { scripted: true, create: step => {
|
|
156
|
+
const next = scenarioAttempt(script, turn.channelId, step!);
|
|
157
|
+
return async function* (request, signal) {
|
|
158
|
+
if (captureScript)
|
|
159
|
+
inspection.request(turn.channelId, JSON.stringify(request), turn.turnId);
|
|
160
|
+
for await (const event of next(request, signal)) { if (event.type === "response") inspection.response(turn.channelId, event.response); yield event; }
|
|
161
|
+
};
|
|
162
|
+
} });
|
|
163
|
+
} else if (compatible) {
|
|
164
|
+
bindModelAttempt(model, { scripted: false, create: () => openAICompatibleAttempt(compatible.baseUrl, compatible.model, compatibleKey, fetch,
|
|
165
|
+
body => inspection.request(turn.channelId, body, turn.turnId), attachments ? id => {
|
|
166
|
+
const value = storage.readManagedAttachment(id); return value.ok ? value.value?.metadata : undefined;
|
|
167
|
+
} : undefined) });
|
|
168
|
+
} else if (!options.providerFactory) bindModelAttempt(model, { scripted: false, create: () => {
|
|
169
|
+
const next = openRouterAttempt(apiKey!, providerModel!.model, fetch, body => inspection.request(turn.channelId, body, turn.turnId),
|
|
170
|
+
attachments ? { supported: imageInput, metadata(id) { const result = storage.readManagedAttachment(id); return result.ok ? result.value?.metadata : undefined; },
|
|
171
|
+
read(metadata) { return attachments!.readForInference(turn.channelId, metadata.id); },
|
|
172
|
+
verify(metadata, signal) { return attachments!.verifyForInference(turn.channelId, metadata.id, signal); } } : undefined);
|
|
173
|
+
return async function* (request, signal) { for await (const event of next(request, signal)) { if (event.type === "response") inspection.response(turn.channelId, event.response); yield event; } };
|
|
123
174
|
} });
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
175
|
+
return { model, tools, executeTool: (call, signal) => {
|
|
176
|
+
const debug = options.debugTools ? debugToolHandlers.get(call.name) : undefined;
|
|
177
|
+
if (debug) return debug(call, signal);
|
|
178
|
+
return call.name === currentTimeDefinition.name || !scriptedTools
|
|
179
|
+
? executeCurrentTime(call, signal) : scriptedTools.executeTool(call, signal);
|
|
180
|
+
} };
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
const observed = observeSession(session, inspection);
|
|
184
|
+
const stop = session.stop;
|
|
185
|
+
session.stop = reason => { const result = stop(reason); inspection.stopped(); return result; };
|
|
186
|
+
return {
|
|
187
|
+
session, inspection, attachments, imageInput, storage: options.database ?? "memory",
|
|
188
|
+
/** The session as local clients use it: acceptance also refreshes the inspector. */
|
|
189
|
+
local: { agent: observed.agent, subscribe: session.subscribe },
|
|
190
|
+
async close() { if (mcp) await mcp.close(); session.reminders?.releaseTimer(); observed.stop(); attachments?.close(); const closed = storage.close(); if (tempMedia) rmSync(tempMedia, { recursive: true, force: true }); if (!closed.ok) throw new Error(`Cannot close session storage (${closed.error.code}): ${closed.error.message}`); },
|
|
191
|
+
};
|
|
192
|
+
} catch (error) {
|
|
193
|
+
const rollback = [() => mcp?.close(), () => attachments?.close(), () => storage.close(),
|
|
194
|
+
() => { if (tempMedia) rmSync(tempMedia, { recursive: true, force: true }); }];
|
|
195
|
+
for (const cleanup of rollback) {
|
|
196
|
+
try { await cleanup(); } catch { /* Preserve the original startup failure. */ }
|
|
197
|
+
}
|
|
198
|
+
throw error;
|
|
199
|
+
}
|
|
145
200
|
}
|
|
@@ -7,7 +7,7 @@ import { join } from "node:path";
|
|
|
7
7
|
* HARNESS_TEST_* settings support deterministic offline process tests. */
|
|
8
8
|
export async function serve(home?: string) {
|
|
9
9
|
const { server } = createScriptedServer({ home: home ?? join(homedir(), ".harness"), fault: process.env.HARNESS_TEST_FAULT, effects: process.env.HARNESS_TEST_EFFECTS,
|
|
10
|
-
requests: process.env.HARNESS_TEST_REQUESTS, attempts: process.env.HARNESS_TEST_ATTEMPTS, snapshotLog: process.env.HARNESS_TEST_SNAPSHOT_LOG, stallChannel: process.env.HARNESS_TEST_STALL_CHANNEL,
|
|
10
|
+
requests: process.env.HARNESS_TEST_REQUESTS, attempts: process.env.HARNESS_TEST_ATTEMPTS, snapshotLog: process.env.HARNESS_TEST_SNAPSHOT_LOG, stallChannel: process.env.HARNESS_TEST_STALL_CHANNEL, providerEndpoint: process.env.HARNESS_TEST_PROVIDER_ENDPOINT, webEndpoint: process.env.HARNESS_TEST_WEB_ENDPOINT,
|
|
11
11
|
streamResponses: process.env.HARNESS_TEST_STREAM_RESPONSES === "1",
|
|
12
12
|
reminderTime: process.env.HARNESS_TEST_REMINDER_TIME === undefined ? undefined : Number(process.env.HARNESS_TEST_REMINDER_TIME),
|
|
13
13
|
modelTimeoutMs: process.env.HARNESS_TEST_MODEL_TIMEOUT_MS === undefined ? undefined : Number(process.env.HARNESS_TEST_MODEL_TIMEOUT_MS) });
|
|
@@ -16,6 +16,6 @@ export async function serve(home?: string) {
|
|
|
16
16
|
output.write(bytes);
|
|
17
17
|
await output.flush();
|
|
18
18
|
});
|
|
19
|
-
server.dispose();
|
|
19
|
+
await server.dispose();
|
|
20
20
|
await output.end();
|
|
21
21
|
}
|