@qlairoslabs/acp-client 0.12.0 → 0.13.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG-consumer-fixes.md +17 -3
- package/CHANGELOG-controller-interface.md +258 -0
- package/CHANGELOG-metering.md +29 -0
- package/CHANGELOG-operation-lifecycle.md +15 -1
- package/CONSUMER_GUIDE.md +847 -7
- package/MIGRATION-0.10-to-0.12.md +4 -1
- package/MIGRATION-0.12-to-0.13.md +275 -0
- package/README.md +17 -16
- package/package.json +4 -2
- package/src/acp-client-handlers.ts +48 -0
- package/src/activity.ts +3 -0
- package/src/adapters.ts +30 -0
- package/src/agent/adoption/provider-attachment.ts +33 -0
- package/src/agent/adoption/provider-session-delete.ts +1 -1
- package/src/agent/adoption/provider-sessions.ts +3 -2
- package/src/agent/append-assistant-message.ts +91 -0
- package/src/agent/config.ts +54 -6
- package/src/agent/conversation-manager.ts +94 -158
- package/src/agent/manager-settings.ts +1 -0
- package/src/agent/native-channel-lifecycle.ts +111 -0
- package/src/agent/persisted-lifecycle.ts +44 -4
- package/src/agent/persistence-policy/context.ts +13 -0
- package/src/agent/persistence-policy/resolver.ts +7 -0
- package/src/agent/persistence-policy/types.ts +1 -0
- package/src/agent/record-capture.ts +1 -0
- package/src/agent-adapter-registry.ts +33 -7
- package/src/agent-conversation-contracts.ts +14 -1
- package/src/agent-conversation-errors.ts +8 -0
- package/src/agent-conversation-owner.ts +9 -4
- package/src/agent-session-config.ts +135 -0
- package/src/agent-session.ts +439 -934
- package/src/agent.ts +73 -0
- package/src/capabilities.ts +2 -0
- package/src/checkpointing/recovery.ts +10 -0
- package/src/cli/index.ts +3 -3
- package/src/cli/managed.ts +2 -2
- package/src/client.ts +68 -98
- package/src/connection-attempt.ts +95 -0
- package/src/controller-connection.ts +114 -0
- package/src/controller.ts +156 -148
- package/src/conversation-controller/capabilities.ts +88 -0
- package/src/conversation-controller/contracts.ts +208 -0
- package/src/conversation-controller/factory.ts +39 -0
- package/src/conversation-controller/guards.ts +98 -0
- package/src/conversation-controller/index.ts +20 -0
- package/src/conversation-startup.ts +35 -0
- package/src/conversation-turns/backend-turns.ts +373 -0
- package/src/conversation-turns/clear-operations.ts +37 -0
- package/src/conversation-turns/context.ts +135 -0
- package/src/conversation-turns/index.ts +4 -0
- package/src/conversation-turns/record-helpers.ts +75 -0
- package/src/conversation-turns/recording.ts +235 -0
- package/src/conversation-turns/run-turn.ts +367 -0
- package/src/conversation-turns/turn-run.ts +57 -0
- package/src/errors.ts +41 -0
- package/src/handoff-options.ts +81 -0
- package/src/identity/checkpoint-backed.ts +1 -1
- package/src/index.ts +58 -3
- package/src/internal-inference/coordination/manager.ts +11 -0
- package/src/internal-inference/runtime/harness-runtime.ts +4 -4
- package/src/launcher.ts +35 -2
- package/src/media/parts.ts +5 -0
- package/src/message-status.ts +83 -0
- package/src/metering/engine.ts +39 -64
- package/src/metering/measurement-provenance.ts +36 -0
- package/src/metering/native/durability.ts +115 -0
- package/src/metering/native/ledger.ts +104 -0
- package/src/metering/native/operation.ts +85 -0
- package/src/metering/native/projection.ts +114 -0
- package/src/metering/native/proof.ts +51 -0
- package/src/metering/native/requirements.ts +10 -0
- package/src/metering/native/retirement.ts +92 -0
- package/src/metering/native/source.ts +90 -0
- package/src/metering/record.ts +38 -1
- package/src/metering/state.ts +13 -3
- package/src/native/approvals.ts +169 -0
- package/src/native/capabilities.ts +17 -0
- package/src/native/channel-changes.ts +211 -0
- package/src/native/connection.ts +56 -0
- package/src/native/controller.ts +591 -0
- package/src/native/delegation-sender.ts +26 -0
- package/src/native/errors.ts +35 -0
- package/src/native/functions.ts +156 -0
- package/src/native/host-config.ts +59 -0
- package/src/native/host.ts +909 -0
- package/src/native/item-receipts.ts +15 -0
- package/src/native/metering.ts +12 -0
- package/src/native/records.ts +166 -0
- package/src/native/recovery.ts +186 -0
- package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
- package/src/native/reminders/idle.ts +70 -0
- package/src/native/reminders/limits.ts +19 -0
- package/src/native/reminders/notifications.ts +29 -0
- package/src/native/reminders/reminders.test.ts +553 -0
- package/src/native/reminders/routine-config.typecheck.ts +13 -0
- package/src/native/reminders/routine-guard.ts +66 -0
- package/src/native/reminders/routine-schedule.ts +25 -0
- package/src/native/reminders/routine-wire.ts +21 -0
- package/src/native/reminders/schedule.ts +97 -0
- package/src/native/reminders/service.ts +280 -0
- package/src/native/reminders/supervisor.ts +91 -0
- package/src/native/reminders/sync.ts +301 -0
- package/src/native/reminders/wire.ts +197 -0
- package/src/native/reminders/wire.typecheck.ts +13 -0
- package/src/native/submission-withdrawal.ts +65 -0
- package/src/native/usage.ts +15 -0
- package/src/native/worker-delivery.ts +61 -0
- package/src/native-harness/.res/README.md +1 -0
- package/src/native-harness/.res/architecture/README.md +21 -0
- package/src/native-harness/.res/architecture/context-and-data.md +31 -0
- package/src/native-harness/.res/architecture/execution.md +42 -0
- package/src/native-harness/.res/architecture/overview.md +44 -0
- package/src/native-harness/.res/architecture/persistence.md +56 -0
- package/src/native-harness/.res/architecture/suspend-and-resume.md +45 -0
- package/src/native-harness/.res/architecture/technical-architecture.md +50 -0
- package/src/native-harness/.res/decisions/0001-basic-loop.md +11 -0
- package/src/native-harness/.res/decisions/0002-channel-input.md +17 -0
- package/src/native-harness/.res/decisions/0003-inference-inspection.md +14 -0
- package/src/native-harness/.res/decisions/0004-shared-context.md +21 -0
- package/src/native-harness/.res/decisions/0005-notice-inbox.md +20 -0
- package/src/native-harness/.res/decisions/0006-explicit-notices.md +12 -0
- package/src/native-harness/.res/decisions/0007-channel-output.md +12 -0
- package/src/native-harness/.res/decisions/0008-browser-client.md +16 -0
- package/src/native-harness/.res/decisions/0009-scripted-model.md +18 -0
- package/src/native-harness/.res/decisions/0010-inprocess-protocol.md +19 -0
- package/src/native-harness/.res/decisions/0011-stdio-transport.md +21 -0
- package/src/native-harness/.res/decisions/0012-session-storage-contract.md +37 -0
- package/src/native-harness/.res/decisions/0013-durable-delivery-contract.md +64 -0
- package/src/native-harness/.res/decisions/0014-channel-controls-contract.md +73 -0
- package/src/native-harness/.res/decisions/0015-session-file-contract.md +72 -0
- package/src/native-harness/.res/decisions/0016-configuration-permissions.md +159 -0
- package/src/native-harness/.res/decisions/0017-openrouter-managed-config.md +69 -0
- package/src/native-harness/.res/decisions/0018-tool-dispatch-evidence.md +78 -0
- package/src/native-harness/.res/decisions/0019-model-execution.md +188 -0
- package/src/native-harness/.res/decisions/0020-startup-channel-changes.md +71 -0
- package/src/native-harness/.res/decisions/0021-tools-and-host-callbacks.md +100 -0
- package/src/native-harness/.res/decisions/0022-operator-controls.md +115 -0
- package/src/native-harness/.res/decisions/0023-long-running-mock.md +82 -0
- package/src/native-harness/.res/decisions/0024-callback-policy-names.md +46 -0
- package/src/native-harness/.res/decisions/0025-external-notices.md +364 -0
- package/src/native-harness/.res/decisions/0026-bounded-context.md +81 -0
- package/src/native-harness/.res/decisions/0027-development-instructions.md +22 -0
- package/src/native-harness/.res/decisions/0028-debug-tools.md +16 -0
- package/src/native-harness/.res/decisions/0029-bounded-model-call-pages.md +37 -0
- package/src/native-harness/.res/decisions/0030-timeline-retrieval.md +145 -0
- package/src/native-harness/.res/decisions/0031-one-off-reminders.md +173 -0
- package/src/native-harness/.res/docs/11-15.md +148 -0
- package/src/native-harness/.res/docs/BUSINESS_RULES.md +111 -0
- package/src/native-harness/.res/docs/WORK.md +65 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/LOG.md +312 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/PLAN.md +77 -0
- package/src/native-harness/.res/docs/_/11-16-persistence/SPEC.md +313 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/LOG.md +160 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/PLAN.md +89 -0
- package/src/native-harness/.res/docs/_/11-19-channel-controls/SPEC.md +135 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/LOG.md +143 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/PLAN.md +93 -0
- package/src/native-harness/.res/docs/_/11-19-config-permissions/SPEC.md +181 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/11-20-LOG.md +433 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PLAN.md +60 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/PROTOCOL.md +141 -0
- package/src/native-harness/.res/docs/acp-client-integration/0001-DESIGN/SPEC.md +168 -0
- package/src/native-harness/.res/docs/attachments/0001-DESIGN/SPEC.md +111 -0
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/PLAN.md +129 -0
- package/src/native-harness/.res/docs/bounded-context/0001-DESIGN/SPEC.md +135 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/LOG.md +437 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/PLAN.md +127 -0
- package/src/native-harness/.res/docs/channel-messaging/0001-DESIGN-external-notices/SPEC.md +203 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/LOG.md +292 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/PLAN.md +91 -0
- package/src/native-harness/.res/docs/long-running-mock/0001-DESIGN/SPEC.md +187 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/LOG.md +148 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/PLAN.md +95 -0
- package/src/native-harness/.res/docs/model-execution/0001-DESIGN/SPEC.md +200 -0
- package/src/native-harness/.res/docs/model-execution/0002-AMENDMENT-accounting/SPEC.md +80 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/LOG.md +206 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/PLAN.md +106 -0
- package/src/native-harness/.res/docs/operator-controls/0001-DESIGN/SPEC.md +297 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/LOG.md +41 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/PLAN.md +36 -0
- package/src/native-harness/.res/docs/persistence/0002-AMENDMENT-session-file/SPEC.md +84 -0
- package/src/native-harness/.res/docs/shell-execution/0001-DESIGN/SPEC.md +147 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/LOG.md +15 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/PLAN.md +107 -0
- package/src/native-harness/.res/docs/timeline-retrieval/0001-DESIGN/SPEC.md +114 -0
- package/src/native-harness/.res/docs/todos/11-19-TODO-auto_review-approve.md +24 -0
- package/src/native-harness/.res/docs/todos/11-20-TODO-user-entered-tool-code.md +23 -0
- package/src/native-harness/.res/docs/todos/11-21-TODO-node-resource-coordination.md +103 -0
- package/src/native-harness/.res/docs/todos/11-22-TODO-harness-m1-sequence.md +50 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/LOG.md +337 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/PLAN.md +76 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0001-DESIGN/SPEC.md +204 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/LOG.md +73 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0002-AMENDMENT-callback-policy/SPEC.md +64 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0003-DESIGN-attachment-tools/SPEC.md +58 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/LOG.md +45 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/PLAN.md +108 -0
- package/src/native-harness/.res/docs/tools-and-callbacks/0004-DESIGN-reminder-tools/SPEC.md +169 -0
- package/src/native-harness/.res/docs/web-tools/0001-DESIGN/SPEC.md +128 -0
- package/src/native-harness/.res/marketing-draft.md +22 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/README.md +285 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-1.md +19 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-10.md +138 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-11.md +148 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-12.md +172 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-13.md +194 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-14.md +233 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-15.md +249 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-16.md +265 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-17.md +279 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-18.md +293 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-19.md +307 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-2.md +29 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-20.md +317 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-21.md +327 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-3.md +40 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-4.md +59 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-5.md +69 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-6.md +79 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-7.md +89 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-8.md +102 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation/context-9.md +116 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/conversation.jsonl +49 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/doc.md +87 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/harness.py +289 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 2.py +221 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy 3.py +287 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/local/harness copy.py +165 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/state.json +22 -0
- package/src/native-harness/.res/sandbox/1-simple-harness/system-prompt.md +2 -0
- package/src/native-harness/AGENTS.md +70 -0
- package/src/native-harness/ARCHITECTURE.md +249 -0
- package/src/native-harness/README.md +726 -0
- package/src/native-harness/bun.lock +26 -0
- package/src/native-harness/package.json +24 -0
- package/src/native-harness/src/capabilities/context/build.ts +59 -0
- package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
- package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
- package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
- package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
- package/src/native-harness/src/capabilities/context/session.ts +92 -0
- package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
- package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
- package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
- package/src/native-harness/src/capabilities/model/runner.ts +116 -0
- package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
- package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
- package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
- package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
- package/src/native-harness/src/capabilities/model/usage.ts +15 -0
- package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
- package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
- package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
- package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
- package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
- package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
- package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
- package/src/native-harness/src/capabilities/tools/reminders/index.ts +75 -0
- package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
- package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
- package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
- package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
- package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
- package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
- package/src/native-harness/src/client.ts +18 -0
- package/src/native-harness/src/contracts/agent.ts +105 -0
- package/src/native-harness/src/contracts/config-permissions.ts +47 -0
- package/src/native-harness/src/contracts/context.ts +112 -0
- package/src/native-harness/src/contracts/events.ts +47 -0
- package/src/native-harness/src/contracts/input-limits.ts +7 -0
- package/src/native-harness/src/contracts/inspection.ts +22 -0
- package/src/native-harness/src/contracts/loop.ts +31 -0
- package/src/native-harness/src/contracts/model-execution.ts +83 -0
- package/src/native-harness/src/contracts/operator-controls.ts +106 -0
- package/src/native-harness/src/contracts/output.ts +13 -0
- package/src/native-harness/src/contracts/protocol.ts +320 -0
- package/src/native-harness/src/contracts/reminders.ts +132 -0
- package/src/native-harness/src/contracts/scenario.ts +42 -0
- package/src/native-harness/src/contracts/session-file.ts +19 -0
- package/src/native-harness/src/contracts/session.ts +184 -0
- package/src/native-harness/src/contracts/storage.ts +596 -0
- package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
- package/src/native-harness/src/contracts/tools.ts +133 -0
- package/src/native-harness/src/governance/permissions/gate.ts +129 -0
- package/src/native-harness/src/governance/policy/resolve.ts +32 -0
- package/src/native-harness/src/index.ts +318 -0
- package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
- package/src/native-harness/src/interfaces/cli/development.ts +145 -0
- package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
- package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
- package/src/native-harness/src/interfaces/cli/main.ts +47 -0
- package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
- package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
- package/src/native-harness/src/interfaces/cli/start.ts +106 -0
- package/src/native-harness/src/interfaces/client.ts +225 -0
- package/src/native-harness/src/interfaces/inspector/index.html +283 -0
- package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
- package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
- package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
- package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
- package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
- package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
- package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
- package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
- package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
- package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
- package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
- package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
- package/src/native-harness/src/interfaces/protocol/server.ts +517 -0
- package/src/native-harness/src/interfaces/protocol/stdio-client.ts +119 -0
- package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
- package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
- package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
- package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
- package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
- package/src/native-harness/src/kernel/channels.ts +405 -0
- package/src/native-harness/src/kernel/loop.ts +45 -0
- package/src/native-harness/src/runtime/config/development.ts +23 -0
- package/src/native-harness/src/runtime/config/managed.ts +2 -0
- package/src/native-harness/src/runtime/config/paths.ts +27 -0
- package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
- package/src/native-harness/src/runtime/reminder-validation.ts +104 -0
- package/src/native-harness/src/runtime/reminders.ts +66 -0
- package/src/native-harness/src/state/storage/archive.ts +239 -0
- package/src/native-harness/src/state/storage/engine.ts +1013 -0
- package/src/native-harness/src/state/storage/inference.ts +124 -0
- package/src/native-harness/src/state/storage/memory-reminders.ts +78 -0
- package/src/native-harness/src/state/storage/memory.ts +341 -0
- package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
- package/src/native-harness/src/state/storage/reminder-archive.ts +63 -0
- package/src/native-harness/src/state/storage/reminder-change.ts +92 -0
- package/src/native-harness/src/state/storage/reminder-tables.ts +27 -0
- package/src/native-harness/src/state/storage/retrieval.ts +122 -0
- package/src/native-harness/src/state/storage/script-identity.ts +7 -0
- package/src/native-harness/src/state/storage/session-file.ts +85 -0
- package/src/native-harness/src/state/storage/sqlite-reminders.ts +134 -0
- package/src/native-harness/src/state/storage/sqlite.ts +625 -0
- package/src/native-harness/src/testing.ts +190 -0
- package/src/native-harness/src/util/config.ts +58 -0
- package/src/native-harness/src/util/json.ts +41 -0
- package/src/native-harness/src/util/message-position.ts +3 -0
- package/src/native-harness/src/util/reminder-schedule.ts +44 -0
- package/src/native-harness/src/util/schema.ts +40 -0
- package/src/native-harness/src/util/timeline-text.ts +72 -0
- package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
- package/src/native-harness/test/agent.test.ts +130 -0
- package/src/native-harness/test/approval-gate.test.ts +255 -0
- package/src/native-harness/test/approval-protocol.test.ts +94 -0
- package/src/native-harness/test/boundaries.test.ts +18 -0
- package/src/native-harness/test/channel-controls.test.ts +322 -0
- package/src/native-harness/test/client-abort.test.ts +136 -0
- package/src/native-harness/test/config-policy.test.ts +301 -0
- package/src/native-harness/test/conformance/storage.ts +1141 -0
- package/src/native-harness/test/context.test.ts +177 -0
- package/src/native-harness/test/crash.test.ts +187 -0
- package/src/native-harness/test/debug-tools.test.ts +67 -0
- package/src/native-harness/test/development-cli.test.ts +67 -0
- package/src/native-harness/test/development.test.ts +171 -0
- package/src/native-harness/test/dispatch-evidence.test.ts +58 -0
- package/src/native-harness/test/e2e.test.ts +186 -0
- package/src/native-harness/test/external-notices.test.ts +101 -0
- package/src/native-harness/test/fixtures/approval-e2e.jsonl +4 -0
- package/src/native-harness/test/fixtures/crash-scenario.jsonl +5 -0
- package/src/native-harness/test/fixtures/development-lifecycle.jsonl +10 -0
- package/src/native-harness/test/fixtures/echo-scenario.jsonl +3 -0
- package/src/native-harness/test/fixtures/format2-schema.ts +27 -0
- package/src/native-harness/test/fixtures/format3-schema.ts +16 -0
- package/src/native-harness/test/fixtures/hold-scenario.jsonl +4 -0
- package/src/native-harness/test/fixtures/model-e2e.jsonl +3 -0
- package/src/native-harness/test/fixtures/storage-owner.ts +20 -0
- package/src/native-harness/test/format-reply.test.ts +10 -0
- package/src/native-harness/test/helpers/operator-view.ts +41 -0
- package/src/native-harness/test/helpers/scenario.ts +9 -0
- package/src/native-harness/test/helpers/session.ts +38 -0
- package/src/native-harness/test/helpers/stdio.ts +46 -0
- package/src/native-harness/test/inspector.test.ts +77 -0
- package/src/native-harness/test/listeners.test.ts +49 -0
- package/src/native-harness/test/loop.test.ts +88 -0
- package/src/native-harness/test/model-channel-double.test.ts +87 -0
- package/src/native-harness/test/model-crash.test.ts +62 -0
- package/src/native-harness/test/model-delivery-regressions.test.ts +55 -0
- package/src/native-harness/test/model-e2e.test.ts +71 -0
- package/src/native-harness/test/model-final-filter.test.ts +30 -0
- package/src/native-harness/test/model-large-reply.test.ts +28 -0
- package/src/native-harness/test/model-live-queue.test.ts +33 -0
- package/src/native-harness/test/model-runner.test.ts +117 -0
- package/src/native-harness/test/model-storage.test.ts +99 -0
- package/src/native-harness/test/model-stream-adapter.test.ts +26 -0
- package/src/native-harness/test/model-stream-public.test.ts +77 -0
- package/src/native-harness/test/notices.test.ts +64 -0
- package/src/native-harness/test/openrouter-config.test.ts +218 -0
- package/src/native-harness/test/operator-controls.test.ts +132 -0
- package/src/native-harness/test/output.test.ts +44 -0
- package/src/native-harness/test/owner-config.test.ts +64 -0
- package/src/native-harness/test/permissions-e2e.test.ts +68 -0
- package/src/native-harness/test/persistence.test.ts +236 -0
- package/src/native-harness/test/portability.test.ts +337 -0
- package/src/native-harness/test/protocol.test.ts +160 -0
- package/src/native-harness/test/reminder-clock.test.ts +61 -0
- package/src/native-harness/test/reminder-stdio.test.ts +140 -0
- package/src/native-harness/test/reminder-storage.test.ts +124 -0
- package/src/native-harness/test/scenario-jsonl.test.ts +112 -0
- package/src/native-harness/test/scripted.test.ts +92 -0
- package/src/native-harness/test/session-file.test.ts +51 -0
- package/src/native-harness/test/startup-channel-changes.test.ts +256 -0
- package/src/native-harness/test/stdio.test.ts +132 -0
- package/src/native-harness/test/storage-memory.test.ts +4 -0
- package/src/native-harness/test/storage-sqlite.test.ts +420 -0
- package/src/native-harness/test/suspension.test.ts +430 -0
- package/src/native-harness/test/timeline-retrieval.test.ts +211 -0
- package/src/native-harness/test/tools-catalog.test.ts +468 -0
- package/src/native-harness/test/tools-protocol.test.ts +418 -0
- package/src/native-harness/test/transfers.test.ts +94 -0
- package/src/native-harness/test/web-chat.test.ts +35 -0
- package/src/native-harness/tsconfig.json +20 -0
- package/src/observation/agent-event-bus.ts +44 -18
- package/src/observation/index.ts +1 -0
- package/src/operations/contracts.ts +11 -3
- package/src/operations/errors.ts +5 -0
- package/src/operations/stale-policy.ts +1 -1
- package/src/operations/supervisor.ts +34 -10
- package/src/orchestrator/acp-delivery.ts +68 -0
- package/src/orchestrator/assignments.ts +27 -0
- package/src/orchestrator/busy.ts +15 -0
- package/src/orchestrator/config.ts +41 -0
- package/src/orchestrator/consumer-api.ts +24 -0
- package/src/orchestrator/contracts.ts +71 -0
- package/src/orchestrator/durable-assignments.ts +111 -0
- package/src/orchestrator/native-delegation.ts +103 -0
- package/src/orchestrator/orchestrator.ts +318 -0
- package/src/orchestrator/permissions.ts +25 -0
- package/src/orchestrator/policy.ts +44 -0
- package/src/orchestrator/pool.ts +123 -0
- package/src/orchestrator/tool-descriptions.ts +11 -0
- package/src/permissions/acp.ts +18 -0
- package/src/permissions/arrival.ts +13 -0
- package/src/permissions/consumer-config.ts +19 -0
- package/src/permissions/conversation.ts +280 -0
- package/src/permissions/matcher.ts +85 -0
- package/src/permissions/outcome.ts +15 -0
- package/src/permissions/policy.ts +81 -0
- package/src/permissions/request.ts +26 -0
- package/src/persistence/activity-projection.ts +1 -0
- package/src/persistence/backend.ts +34 -1
- package/src/persistence/channels.ts +23 -0
- package/src/persistence/index.ts +4 -0
- package/src/persistence/protocol-method.ts +5 -0
- package/src/persistence/reminder-wake.ts +49 -0
- package/src/persistence/reminders.ts +385 -0
- package/src/persistence/sqlite-backend.ts +84 -6
- package/src/persistence/sqlite-channels.ts +65 -0
- package/src/persistence/sqlite-reminders.ts +85 -0
- package/src/persistence/sqlite-schema.ts +108 -3
- package/src/persistence/sqlite-worker-delivery.ts +374 -0
- package/src/persistence/sqlite-workers.ts +59 -0
- package/src/persistence/worker-delivery-contract.ts +104 -0
- package/src/persistence/worker-terminal-reason.ts +29 -0
- package/src/persistence/workers.ts +19 -0
- package/src/provider-notices.ts +137 -0
- package/src/repl/commands.ts +2 -2
- package/src/steering/combine.ts +3 -1
- package/src/steering/contracts.ts +11 -2
- package/src/steering/controller.ts +3 -2
- package/src/transport/acp-transport.ts +24 -14
- package/src/types.ts +15 -12
- package/src/updates.ts +14 -2
- package/src/wire-log.ts +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { SESSION_INPUT_MAX_BYTES } from "../../contracts/input-limits.ts";
|
|
2
|
+
import { createInterface, clearLine, cursorTo } from "node:readline";
|
|
3
|
+
import { once } from "node:events";
|
|
4
|
+
import { localConnection } from "../../runtime/config/development.ts";
|
|
5
|
+
import { sendLocal } from "../protocol/local.ts";
|
|
6
|
+
import { subscribeLocal } from "../protocol/subscribe.ts";
|
|
7
|
+
import { formatReply } from "./format-reply.ts";
|
|
8
|
+
|
|
9
|
+
export async function chat(channelId: string, participantId: string) {
|
|
10
|
+
const { socketPath } = localConnection();
|
|
11
|
+
let terminal: ReturnType<typeof createInterface> | undefined;
|
|
12
|
+
let pending = 0;
|
|
13
|
+
let frame = 0;
|
|
14
|
+
let spinner: ReturnType<typeof setInterval> | undefined;
|
|
15
|
+
const drawPrompt = () => {
|
|
16
|
+
if (!terminal || !process.stdout.isTTY) return;
|
|
17
|
+
const draft = terminal.line;
|
|
18
|
+
const cursor = terminal.cursor;
|
|
19
|
+
const suffix = pending ? ` ${['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'][frame++ % 10]} working` : '';
|
|
20
|
+
clearLine(process.stdout, 0); cursorTo(process.stdout, 0);
|
|
21
|
+
process.stdout.write(`> ${draft}${suffix}`);
|
|
22
|
+
const back = draft.length - cursor + suffix.length;
|
|
23
|
+
if (back > 0) process.stdout.write(`\x1b[${back}D`);
|
|
24
|
+
};
|
|
25
|
+
const print = (text: string) => {
|
|
26
|
+
if (terminal && process.stdout.isTTY) {
|
|
27
|
+
clearLine(process.stdout, 0);
|
|
28
|
+
cursorTo(process.stdout, 0);
|
|
29
|
+
}
|
|
30
|
+
console.log(`\n${text}\n`);
|
|
31
|
+
// Redraw the current draft after unsolicited output instead of consuming it.
|
|
32
|
+
if (terminal && process.stdout.isTTY) {
|
|
33
|
+
// Redraw without writing the draft back into readline: it still owns the
|
|
34
|
+
// original input buffer, and terminal.write would duplicate those bytes.
|
|
35
|
+
drawPrompt();
|
|
36
|
+
} else terminal?.prompt();
|
|
37
|
+
};
|
|
38
|
+
const subscription = await subscribeLocal(socketPath, channelId, output => {
|
|
39
|
+
print(output.type === "error" ? output.text : formatReply(output.text));
|
|
40
|
+
});
|
|
41
|
+
terminal = createInterface({ input: process.stdin, output: process.stdout, prompt: "> " });
|
|
42
|
+
const closed = once(terminal, "close");
|
|
43
|
+
const requests = new AbortController();
|
|
44
|
+
let closing = false;
|
|
45
|
+
terminal.once("close", () => { closing = true; clearInterval(spinner); requests.abort(); subscription.close(); });
|
|
46
|
+
void subscription.done.catch(error => {
|
|
47
|
+
if (closing) return;
|
|
48
|
+
print(`${String(error)}. Reconnect with bun run chat ${channelId} ${participantId}.`);
|
|
49
|
+
terminal?.close();
|
|
50
|
+
});
|
|
51
|
+
console.log(`Channel ${channelId}, participant ${participantId}. /clear clears the screen; /exit disconnects.`);
|
|
52
|
+
terminal.on("line", text => {
|
|
53
|
+
const command = text.trim();
|
|
54
|
+
if (command === "/exit") { terminal?.close(); return; }
|
|
55
|
+
if (command === "/clear") {
|
|
56
|
+
// Purely local: neither channel state nor its output subscription changes.
|
|
57
|
+
if (process.stdout.isTTY) process.stdout.write("\x1b[2J\x1b[3J\x1b[H");
|
|
58
|
+
} else if (Buffer.byteLength(text, "utf8") > SESSION_INPUT_MAX_BYTES) {
|
|
59
|
+
print(`Input exceeds the ${SESSION_INPUT_MAX_BYTES}-byte UTF-8 limit`);
|
|
60
|
+
} else if (command) {
|
|
61
|
+
pending++;
|
|
62
|
+
if (process.stdout.isTTY && !spinner) spinner = setInterval(drawPrompt, 100);
|
|
63
|
+
// Reply text comes only from the subscription, including this request's
|
|
64
|
+
// answer, so HTTP acknowledgements cannot print it a second time.
|
|
65
|
+
void sendLocal(socketPath, { channelId, participantId, text }, requests.signal).catch(error => {
|
|
66
|
+
if (!closing) print(String(error));
|
|
67
|
+
}).finally(() => {
|
|
68
|
+
pending--;
|
|
69
|
+
if (!pending) { clearInterval(spinner); spinner = undefined; }
|
|
70
|
+
if (!closing) drawPrompt();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
terminal?.prompt();
|
|
74
|
+
drawPrompt();
|
|
75
|
+
});
|
|
76
|
+
terminal.prompt();
|
|
77
|
+
try { await closed; }
|
|
78
|
+
finally {
|
|
79
|
+
subscription.close();
|
|
80
|
+
terminal.close();
|
|
81
|
+
await subscription.done;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { createSession } from "../../index.ts";
|
|
5
|
+
import type { Model } from "../../contracts/loop.ts";
|
|
6
|
+
import type { PersistentSession, TurnServices } from "../../contracts/session.ts";
|
|
7
|
+
import { openRouter } from "../../capabilities/model/openrouter.ts";
|
|
8
|
+
import { loadScenario, scriptedCompatibilityKey } from "../../capabilities/model/scenario-file.ts";
|
|
9
|
+
import { scenarioAttempt } from "../../capabilities/model/scenario-attempt.ts";
|
|
10
|
+
import { bindModelAttempt } from "../../capabilities/model/attempt.ts";
|
|
11
|
+
import { openRouterAttempt } from "../../capabilities/model/openrouter-stream.ts";
|
|
12
|
+
import { currentTimeDefinition, executeCurrentTime } from "../../capabilities/tools/builtin/current-time.ts";
|
|
13
|
+
import { debugToolDefinitions, debugToolHandlers } from "../../capabilities/tools/debug/index.ts";
|
|
14
|
+
import { notifyChannelDefinition } from "../../capabilities/tools/builtin/notify-channel.ts";
|
|
15
|
+
import { createMemoryStorageAdapter } from "../../state/storage/memory.ts";
|
|
16
|
+
import { createSqliteStorageAdapter } from "../../state/storage/sqlite.ts";
|
|
17
|
+
import { createInspection } from "../inspector/state.ts";
|
|
18
|
+
import { observeModel, observeSession } from "../inspector/observe.ts";
|
|
19
|
+
import type { ManagedConfig } from "../../contracts/config-permissions.ts";
|
|
20
|
+
import { chooseManagedConfig } from "../../runtime/config/paths.ts";
|
|
21
|
+
import { resolveCredential, validateManagedConfig } from "../../runtime/config/managed.ts";
|
|
22
|
+
|
|
23
|
+
export interface DevelopmentOptions {
|
|
24
|
+
systemPrompt: string;
|
|
25
|
+
/** Explicit replacement of the selected config's system text for this open. */
|
|
26
|
+
instructions?: string;
|
|
27
|
+
/** SQLite file for a durable session; memory when omitted. */
|
|
28
|
+
database?: string;
|
|
29
|
+
/** Expected ID for a named session, or the ID to assign on creation. */
|
|
30
|
+
sessionId?: string;
|
|
31
|
+
/** Create the database (it must not exist) instead of opening it. */
|
|
32
|
+
create?: boolean;
|
|
33
|
+
/** Provider credentials, or `script` for offline runs without a key. */
|
|
34
|
+
provider?: { apiKey: string; model: string };
|
|
35
|
+
/** A scripted-model file: one script, or `{ channels: { <id>: script }, default?: script }`. */
|
|
36
|
+
script?: string;
|
|
37
|
+
/** Optional tools supplied by a scripted test. */
|
|
38
|
+
scriptedTools?: Pick<TurnServices, "tools" | "executeTool">;
|
|
39
|
+
/** Validated portable config selected by the development host. */
|
|
40
|
+
managedConfig?: ManagedConfig;
|
|
41
|
+
/** Provider injection and environment are useful for offline tests and hosts. */
|
|
42
|
+
providerFactory?: (apiKey: string, model: string, onRequest?: (body: string) => void) => Model;
|
|
43
|
+
/** Expose safe diagnostic tools for this process. */
|
|
44
|
+
debugTools?: boolean;
|
|
45
|
+
timelineTools?: boolean;
|
|
46
|
+
/** Process-local prompt override used by the development debug mode. */
|
|
47
|
+
debugInstructions?: string;
|
|
48
|
+
environment?: Record<string, string | undefined>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The development session exactly as `bun run start` runs it, without any
|
|
52
|
+
* listener: storage, real or scripted inference, tools and the
|
|
53
|
+
* inspector's view. Opening executes nothing; the caller starts or resumes. */
|
|
54
|
+
export async function openDevelopment(options: DevelopmentOptions) {
|
|
55
|
+
const sqlite = options.database ? createSqliteStorageAdapter(options.database) : undefined;
|
|
56
|
+
const adapter = sqlite ?? createMemoryStorageAdapter();
|
|
57
|
+
let sessionId = options.sessionId ?? "development";
|
|
58
|
+
if (options.database && !options.create && !existsSync(options.database))
|
|
59
|
+
throw new Error(`No session database at ${options.database}. Pass --create to create it.`);
|
|
60
|
+
let managedConfig = options.managedConfig;
|
|
61
|
+
let hadSaved = false, hasSidecar = false;
|
|
62
|
+
if (options.database && !options.create) {
|
|
63
|
+
const saved = sqlite!.readSavedHeader();
|
|
64
|
+
if (!saved.ok) throw new Error(`Cannot read saved config (${saved.error.code}): ${saved.error.message}`);
|
|
65
|
+
sessionId = options.sessionId ?? saved.value.sessionId;
|
|
66
|
+
hadSaved = saved.value.config !== undefined;
|
|
67
|
+
const sidecar = join(dirname(options.database), "config.json"); hasSidecar = existsSync(sidecar);
|
|
68
|
+
const inline = managedConfig ?? (options.script ? { version: 1, system: options.systemPrompt, model: { protocol: "scripted", script: options.script },
|
|
69
|
+
defaultPolicy: "__legacy_allow", policies: { __legacy_allow: { fallback: "allow", tools: {} } } } : undefined);
|
|
70
|
+
if (inline || hadSaved || hasSidecar) managedConfig = chooseManagedConfig({ mode: "open", sidecar, inline, saved: saved.value.config });
|
|
71
|
+
}
|
|
72
|
+
const useLegacyCredential = !!options.provider && !hadSaved && !hasSidecar && !options.managedConfig;
|
|
73
|
+
if (!managedConfig && options.script) managedConfig = validateManagedConfig({ version: 1, system: options.systemPrompt,
|
|
74
|
+
model: { protocol: "scripted", script: options.script }, defaultPolicy: "__legacy_allow", policies: { __legacy_allow: { fallback: "allow", tools: {} } } });
|
|
75
|
+
if (!managedConfig && options.provider) managedConfig = validateManagedConfig({ version: 1, system: options.systemPrompt,
|
|
76
|
+
model: { protocol: "openrouter", model: options.provider.model, apiKeyEnv: "OPENROUTER_API_KEY" }, defaultPolicy: "__legacy_allow",
|
|
77
|
+
policies: { __legacy_allow: { fallback: "allow", tools: {} } } });
|
|
78
|
+
if (managedConfig && options.instructions !== undefined) managedConfig = { ...managedConfig, system: options.instructions };
|
|
79
|
+
if (managedConfig && options.timelineTools) managedConfig = { ...managedConfig, timelineTools: true };
|
|
80
|
+
const savedConfig = managedConfig;
|
|
81
|
+
if (managedConfig && options.debugInstructions !== undefined && options.instructions === undefined)
|
|
82
|
+
managedConfig = { ...managedConfig, system: options.debugInstructions };
|
|
83
|
+
const systemPrompt = options.instructions ?? options.debugInstructions ?? managedConfig?.system ?? options.systemPrompt;
|
|
84
|
+
const scriptPath = managedConfig?.model.protocol === "scripted" ? managedConfig.model.script : undefined;
|
|
85
|
+
const providerModel = managedConfig?.model.protocol === "openrouter" ? managedConfig.model : undefined;
|
|
86
|
+
const apiKey = providerModel ? (useLegacyCredential ? options.provider!.apiKey : resolveCredential(providerModel, options.environment ?? process.env)) : undefined;
|
|
87
|
+
if (providerModel && !apiKey) throw new Error(`config.model.apiKeyEnv: environment variable ${providerModel.apiKeyEnv} is missing or empty`);
|
|
88
|
+
const script = scriptPath ? await loadScenario(scriptPath) : undefined;
|
|
89
|
+
if (!script && !providerModel) throw new Error("Development needs provider credentials or a script");
|
|
90
|
+
const scriptedTools = script ? options.scriptedTools : undefined;
|
|
91
|
+
const tools = [currentTimeDefinition, ...(scriptedTools?.tools ?? []),
|
|
92
|
+
...(options.debugTools ? debugToolDefinitions : []), notifyChannelDefinition];
|
|
93
|
+
const compatibilityKey = script ? scriptedCompatibilityKey(script.modelDigest, systemPrompt)
|
|
94
|
+
: createHash("sha256").update(JSON.stringify([systemPrompt, providerModel!.model, tools.map(tool => tool.name)])).digest("hex");
|
|
95
|
+
const opened = adapter.open({ mode: options.database && !options.create ? "open" : "create",
|
|
96
|
+
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}`);
|
|
98
|
+
const storage = opened.value;
|
|
99
|
+
if (savedConfig) {
|
|
100
|
+
const saved = storage.saveConfig(savedConfig);
|
|
101
|
+
if (!saved.ok && saved.error.code !== "incompatible") { storage.close(); throw new Error(`Cannot save config: ${saved.error.message}`); }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const inspection = createInspection(systemPrompt, tools, storage, options.database ?? "memory");
|
|
105
|
+
const captureScript = (options.environment ?? process.env).HARNESS_CAPTURE_SCRIPT_REQUESTS === "1";
|
|
106
|
+
const session: PersistentSession = createSession({
|
|
107
|
+
systemPrompt, storage, config: managedConfig, captureContext: (!script || captureScript) ? inspection.capture : undefined,
|
|
108
|
+
observeModelCall: inspection.modelCall,
|
|
109
|
+
configureTurn(turn) {
|
|
110
|
+
const model = observeModel(inspection, turn.channelId, onRequest => {
|
|
111
|
+
if (script) return async () => { throw new Error("Scripted model requires a reserved attempt"); };
|
|
112
|
+
const provider = (options.providerFactory ?? openRouter)(apiKey!, providerModel!.model, onRequest);
|
|
113
|
+
return provider;
|
|
114
|
+
}, turn.turnId);
|
|
115
|
+
if (script) {
|
|
116
|
+
bindModelAttempt(model, { scripted: true, create: step => {
|
|
117
|
+
const next = scenarioAttempt(script, turn.channelId, step!);
|
|
118
|
+
return async function* (request, signal) {
|
|
119
|
+
if (captureScript)
|
|
120
|
+
inspection.request(turn.channelId, JSON.stringify(request), turn.turnId);
|
|
121
|
+
for await (const event of next(request, signal)) { if (event.type === "response") inspection.response(turn.channelId, event.response); yield event; }
|
|
122
|
+
};
|
|
123
|
+
} });
|
|
124
|
+
} else if (!options.providerFactory) bindModelAttempt(model, { scripted: false, create: () => {
|
|
125
|
+
const next = openRouterAttempt(apiKey!, providerModel!.model, fetch, body => inspection.request(turn.channelId, body, turn.turnId));
|
|
126
|
+
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; } };
|
|
127
|
+
} });
|
|
128
|
+
return { model, tools, executeTool: (call, signal) => {
|
|
129
|
+
const debug = options.debugTools ? debugToolHandlers.get(call.name) : undefined;
|
|
130
|
+
if (debug) return debug(call, signal);
|
|
131
|
+
return call.name === currentTimeDefinition.name || !scriptedTools
|
|
132
|
+
? executeCurrentTime(call, signal) : scriptedTools.executeTool(call, signal);
|
|
133
|
+
} };
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
const observed = observeSession(session, inspection);
|
|
137
|
+
const stop = session.stop;
|
|
138
|
+
session.stop = reason => { const result = stop(reason); inspection.stopped(); return result; };
|
|
139
|
+
return {
|
|
140
|
+
session, inspection, storage: options.database ?? "memory",
|
|
141
|
+
/** The session as local clients use it: acceptance also refreshes the inspector. */
|
|
142
|
+
local: { agent: observed.agent, subscribe: session.subscribe },
|
|
143
|
+
close() { session.reminders?.releaseTimer(); observed.stop(); const closed = storage.close(); if (!closed.ok) throw new Error(`Cannot close session storage (${closed.error.code}): ${closed.error.message}`); },
|
|
144
|
+
};
|
|
145
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Small terminal renderer for common Markdown, preserving fenced code verbatim. */
|
|
2
|
+
export function formatReply(markdown: string, color = process.stdout.isTTY && !process.env.NO_COLOR): string {
|
|
3
|
+
const style = (text: string, code: string) => color ? `\x1b[${code}m${text}\x1b[0m` : text;
|
|
4
|
+
const inline = (text: string) => text.replace(
|
|
5
|
+
/`([^`]+)`|\*\*(.+?)\*\*|__(.+?)__|\*([^*\n]+)\*|~~(.+?)~~|\[([^\]]+)\]\(([^)]+)\)/g,
|
|
6
|
+
(_match, code, bold, underscoreBold, italic, strike, label, url) => {
|
|
7
|
+
if (code !== undefined) return style(code, "36");
|
|
8
|
+
if (bold !== undefined || underscoreBold !== undefined) return style(bold ?? underscoreBold, "1");
|
|
9
|
+
if (italic !== undefined) return style(italic, "3");
|
|
10
|
+
if (strike !== undefined) return style(strike, "9");
|
|
11
|
+
return label === url ? style(url, "4") : `${label} (${url})`;
|
|
12
|
+
},
|
|
13
|
+
);
|
|
14
|
+
let fence: string | undefined;
|
|
15
|
+
return markdown.split("\n").map(line => {
|
|
16
|
+
const marker = line.match(/^\s*(`{3,}|~{3,})(.*)$/);
|
|
17
|
+
if (marker && (!fence || (marker[1]![0] === fence[0] && marker[1]!.length >= fence.length && !marker[2]!.trim()))) {
|
|
18
|
+
if (fence) { fence = undefined; return ""; }
|
|
19
|
+
fence = marker[1];
|
|
20
|
+
return marker[2]!.trim() ? style(marker[2]!.trim(), "2") : "";
|
|
21
|
+
}
|
|
22
|
+
if (fence) return ` ${line}`;
|
|
23
|
+
const heading = line.match(/^#{1,6}\s+(.+?)\s*#*$/);
|
|
24
|
+
if (heading) return style(inline(heading[1]!), "1");
|
|
25
|
+
return inline(line.replace(/^(\s*)[-*+]\s+/, "$1• ").replace(/^>\s?/, "│ "));
|
|
26
|
+
}).join("\n");
|
|
27
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { Database } from "bun:sqlite";
|
|
2
|
+
import { lstatSync, unlinkSync } from "node:fs";
|
|
3
|
+
import { createConnection } from "node:net";
|
|
4
|
+
|
|
5
|
+
function code(error: unknown) {
|
|
6
|
+
return (error as NodeJS.ErrnoException | undefined)?.code;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function atPath(path: string) {
|
|
10
|
+
try { return lstatSync(path, { bigint: true }); }
|
|
11
|
+
catch (error) { if (code(error) !== "ENOENT") throw error; }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A live listener can use any protocol. Only a Unix connect refusal is
|
|
15
|
+
* evidence of a stale socket. Timeouts and permission errors stay ambiguous. */
|
|
16
|
+
function isRefused(path: string) {
|
|
17
|
+
return new Promise<boolean>((resolve, reject) => {
|
|
18
|
+
const socket = createConnection({ path });
|
|
19
|
+
socket.setTimeout(500);
|
|
20
|
+
socket.once("timeout", () => { socket.destroy(); resolve(false); });
|
|
21
|
+
socket.once("connect", () => { socket.destroy(); resolve(false); });
|
|
22
|
+
socket.once("error", error => {
|
|
23
|
+
if (code(error) === "ECONNREFUSED" || code(error) === "ENOENT") resolve(true);
|
|
24
|
+
else reject(error);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function bindLocalSocket<T>(path: string, bind: () => T): Promise<T> {
|
|
30
|
+
try { return bind(); }
|
|
31
|
+
catch (error) { if (code(error) !== "EADDRINUSE") throw error; }
|
|
32
|
+
|
|
33
|
+
const old = atPath(path);
|
|
34
|
+
if (!old) return bind();
|
|
35
|
+
if (!old.isSocket() || (process.getuid && BigInt(process.getuid()) !== old.uid))
|
|
36
|
+
throw new Error(`Cannot listen at ${path}: the path is occupied by another file or owner`);
|
|
37
|
+
|
|
38
|
+
if (!await isRefused(path)) {
|
|
39
|
+
throw new Error(`A server already listens at ${path}. Connect with bun run chat, or choose a different HARNESS_SOCKET.`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Serialize recovering starters with an OS-released SQLite lock. A normal
|
|
43
|
+
// bind stays atomic and needs no lock. The empty lock file is kept so every
|
|
44
|
+
// recovering process opens the same inode, even after a crash.
|
|
45
|
+
const lockPath = `${path}.recovery.sqlite`;
|
|
46
|
+
const existingLock = atPath(lockPath);
|
|
47
|
+
if (existingLock && (!existingLock.isFile() || existingLock.uid !== old.uid))
|
|
48
|
+
throw new Error(`Cannot recover ${path}: the socket recovery lock has a different owner or file type`);
|
|
49
|
+
const lock = new Database(lockPath);
|
|
50
|
+
try {
|
|
51
|
+
lock.exec("BEGIN IMMEDIATE");
|
|
52
|
+
const current = atPath(path);
|
|
53
|
+
if (current?.isSocket() && current.ino === old.ino && current.dev === old.dev && current.ctimeNs === old.ctimeNs)
|
|
54
|
+
unlinkSync(path);
|
|
55
|
+
return bind();
|
|
56
|
+
} catch (error) {
|
|
57
|
+
if (code(error) === "EADDRINUSE" || code(error) === "SQLITE_BUSY")
|
|
58
|
+
throw new Error(`Another server is starting or already listening at ${path}. Connect with bun run chat, or choose a different HARNESS_SOCKET.`);
|
|
59
|
+
throw error;
|
|
60
|
+
} finally {
|
|
61
|
+
lock.close();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Keep the usual browser ports when available. A port chosen explicitly by
|
|
66
|
+
* the caller should either bind exactly or report which setting conflicted. */
|
|
67
|
+
export function bindWebPort<T>(port: number, variable: string, bind: (port: number) => T): T {
|
|
68
|
+
try { return bind(port); }
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (code(error) !== "EADDRINUSE") throw error;
|
|
71
|
+
if (process.env[variable] === undefined && port !== 0) return bind(0);
|
|
72
|
+
throw new Error(`Port ${port} is already in use. Set ${variable}=0 to choose an available port.`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { chat } from "./chat.ts";
|
|
2
|
+
import { start, type StartOptions } from "./start.ts";
|
|
3
|
+
import { serve } from "./serve.ts";
|
|
4
|
+
import { controlLocal } from "../protocol/local.ts";
|
|
5
|
+
import { localConnection } from "../../runtime/config/development.ts";
|
|
6
|
+
|
|
7
|
+
const USAGE = "Usage: start [--db <path> | --session <id>] [--create] [--resume] [--script <path>] [--instructions <path>] [--debug] [--debug-tools] [--timeline-tools] | chat <channelId> <participantId> | suspend | resume | status | serve --stdio [--home <directory>]";
|
|
8
|
+
|
|
9
|
+
function startOptions(args: string[]) {
|
|
10
|
+
const options: StartOptions = {};
|
|
11
|
+
for (let i = 0; i < args.length; i++) {
|
|
12
|
+
const flag = args[i], value = args[i + 1];
|
|
13
|
+
if (flag === "--create") options.create = true;
|
|
14
|
+
else if (flag === "--resume") options.resume = true;
|
|
15
|
+
else if (flag === "--debug") options.debug = true;
|
|
16
|
+
else if (flag === "--timeline-tools") options.timelineTools = true;
|
|
17
|
+
else if (flag === "--debug-tools") options.debugTools = true;
|
|
18
|
+
else if ((flag === "--db" || flag === "--session" || flag === "--script" || flag === "--instructions") && value && !value.startsWith("--")) {
|
|
19
|
+
const key = flag === "--db" ? "database" : flag === "--session" ? "sessionId" : flag === "--script" ? "script" : "instructions";
|
|
20
|
+
options[key] = value;
|
|
21
|
+
i++;
|
|
22
|
+
}
|
|
23
|
+
else throw new Error(USAGE);
|
|
24
|
+
}
|
|
25
|
+
return options;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function main() {
|
|
29
|
+
const [command, channelId, participantId, home, ...rest] = process.argv.slice(2);
|
|
30
|
+
if (command === "start") return start(startOptions(process.argv.slice(3)));
|
|
31
|
+
if ((command === "suspend" || command === "resume" || command === "status") && !channelId) {
|
|
32
|
+
console.log(JSON.stringify(await controlLocal(localConnection().socketPath, command), null, 2));
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (command === "serve" && channelId === "--stdio" && (!participantId || (participantId === "--home" && home && !rest.length))) {
|
|
36
|
+
try { await serve(home); }
|
|
37
|
+
catch (error) { console.error(String(error)); process.exit(1); }
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (command === "chat" && channelId && participantId) return chat(channelId, participantId);
|
|
41
|
+
throw new Error(USAGE);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
main().catch((error) => {
|
|
45
|
+
console.error(String(error));
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { loadScenario } from "../../capabilities/model/scenario-file.ts";
|
|
2
|
+
import { scenarioAttempt } from "../../capabilities/model/scenario-attempt.ts";
|
|
3
|
+
import { bindModelAttempt } from "../../capabilities/model/attempt.ts";
|
|
4
|
+
import type { ModelRequest } from "../../contracts/model-execution.ts";
|
|
5
|
+
import { echoDefinition, executeEcho } from "../../capabilities/tools/testing/echo.ts";
|
|
6
|
+
import { createSession } from "../../index.ts";
|
|
7
|
+
|
|
8
|
+
async function main() {
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const timelineTools = args[0] === "--timeline-tools";
|
|
11
|
+
const [path, ...prompt] = timelineTools ? args.slice(1) : args;
|
|
12
|
+
if (!path) throw new Error('Usage: bun run test:scenario [--timeline-tools] <script.jsonl> [prompt]');
|
|
13
|
+
const scenario = await loadScenario(path);
|
|
14
|
+
const requests: ModelRequest[] = [];
|
|
15
|
+
let position = 0;
|
|
16
|
+
const model = bindModelAttempt(async () => { throw new Error("Scripted model requires a reserved attempt"); }, {
|
|
17
|
+
scripted: true, create: step => scenarioAttempt(scenario, "test", step!, request => {
|
|
18
|
+
position = step! + 1;
|
|
19
|
+
if (process.env.HARNESS_CAPTURE_SCRIPT_REQUESTS === "1") requests.push(structuredClone(request));
|
|
20
|
+
}),
|
|
21
|
+
});
|
|
22
|
+
const session = createSession({ timelineTools, systemPrompt: "You are a test assistant.", configureTurn: () => ({
|
|
23
|
+
model, tools: [echoDefinition], executeTool: executeEcho,
|
|
24
|
+
}) });
|
|
25
|
+
let answer = "";
|
|
26
|
+
const ended = new Promise<void>((resolve, reject) => session.subscribe(({ event }) => {
|
|
27
|
+
if (event.type === "message_completed") answer = (event.parts ?? []).map(part => part.text).join("");
|
|
28
|
+
if (event.type === "turn_ended") event.outcome === "completed" ? resolve() : reject(new Error(event.error ?? event.outcome));
|
|
29
|
+
}));
|
|
30
|
+
session.start();
|
|
31
|
+
const accepted = session.agent.send({ channelId: "test", participantId: "tester", text: prompt.join(" ") || "Echo hello" });
|
|
32
|
+
if (!accepted.accepted) throw new Error(accepted.error);
|
|
33
|
+
await ended;
|
|
34
|
+
console.log(JSON.stringify({ answer, remainingResponses: Math.max(0, (scenario.channelModels.get("test") ?? scenario.defaultModels).length - position), requests, entries: session.store.snapshot() }, null, 2));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
main().catch(error => { console.error(error); process.exitCode = 1; });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createScriptedServer } from "../../testing.ts";
|
|
2
|
+
import { serveProtocolStdio } from "../protocol/stdio-server.ts";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
/** `home` selects durable SQLite sessions; the default is ~/.harness.
|
|
7
|
+
* HARNESS_TEST_* settings support deterministic offline process tests. */
|
|
8
|
+
export async function serve(home?: string) {
|
|
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,
|
|
11
|
+
streamResponses: process.env.HARNESS_TEST_STREAM_RESPONSES === "1",
|
|
12
|
+
reminderTime: process.env.HARNESS_TEST_REMINDER_TIME === undefined ? undefined : Number(process.env.HARNESS_TEST_REMINDER_TIME),
|
|
13
|
+
modelTimeoutMs: process.env.HARNESS_TEST_MODEL_TIMEOUT_MS === undefined ? undefined : Number(process.env.HARNESS_TEST_MODEL_TIMEOUT_MS) });
|
|
14
|
+
const output = Bun.stdout.writer();
|
|
15
|
+
await serveProtocolStdio(server, Bun.stdin.stream(), async bytes => {
|
|
16
|
+
output.write(bytes);
|
|
17
|
+
await output.flush();
|
|
18
|
+
});
|
|
19
|
+
server.dispose();
|
|
20
|
+
await output.end();
|
|
21
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { mkdir, readFile } from "node:fs/promises";
|
|
2
|
+
import { agentConfiguration, localConnection } from "../../runtime/config/development.ts";
|
|
3
|
+
import { serveInspector } from "../inspector/server.ts";
|
|
4
|
+
import { createChannelHandler, serveLocal } from "../protocol/local.ts";
|
|
5
|
+
import { createChannelOutputs, publishChannelEvent } from "../protocol/output.ts";
|
|
6
|
+
import { serveWebChat } from "../web-chat/server.ts";
|
|
7
|
+
import { loadInstructions } from "../../capabilities/context/load-instructions.ts";
|
|
8
|
+
import { openDevelopment } from "./development.ts";
|
|
9
|
+
import { bindLocalSocket, bindWebPort } from "./listeners.ts";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { dirname, join, resolve } from "node:path";
|
|
12
|
+
import { existsSync } from "node:fs";
|
|
13
|
+
import { createSqliteStorageAdapter } from "../../state/storage/sqlite.ts";
|
|
14
|
+
import { chooseManagedConfig, managedSessionPaths } from "../../runtime/config/paths.ts";
|
|
15
|
+
|
|
16
|
+
export interface StartOptions { database?: string; sessionId?: string; create?: boolean; resume?: boolean; script?: string; instructions?: string; debug?: boolean; debugTools?: boolean; timelineTools?: boolean }
|
|
17
|
+
|
|
18
|
+
export async function start(options: StartOptions = {}) {
|
|
19
|
+
if (options.database !== undefined && options.sessionId !== undefined)
|
|
20
|
+
throw new Error("Choose either --db <path> or --session <id>");
|
|
21
|
+
const generated = options.database === undefined && options.sessionId === undefined;
|
|
22
|
+
const sessionId = options.database === undefined ? options.sessionId ?? crypto.randomUUID() : undefined;
|
|
23
|
+
const managed = sessionId === undefined ? undefined : managedSessionPaths(sessionId, join(homedir(), ".harness", "sessions"));
|
|
24
|
+
const database = options.database ?? managed!.database;
|
|
25
|
+
const create = generated || !!options.create;
|
|
26
|
+
if (!create && !existsSync(database)) throw new Error(`No session database at ${database}. Pass --create to create it.`);
|
|
27
|
+
|
|
28
|
+
const instructions = options.instructions === undefined ? undefined : await readFile(options.instructions, "utf8");
|
|
29
|
+
const systemPrompt = instructions ?? loadInstructions(options.script ? "agent-demo" : "agent");
|
|
30
|
+
let managedConfig;
|
|
31
|
+
if (options.script) managedConfig = { version: 1 as const, system: systemPrompt,
|
|
32
|
+
model: { protocol: "scripted" as const, script: resolve(options.script) }, defaultPolicy: "__legacy_allow",
|
|
33
|
+
policies: { __legacy_allow: { fallback: "allow" as const, tools: {} } } };
|
|
34
|
+
if (create && !managedConfig) {
|
|
35
|
+
const sidecar = join(dirname(database), "config.json");
|
|
36
|
+
if (existsSync(sidecar)) managedConfig = chooseManagedConfig({ mode: "create", sidecar });
|
|
37
|
+
}
|
|
38
|
+
if (!create) {
|
|
39
|
+
const saved = createSqliteStorageAdapter(database).readSavedConfig();
|
|
40
|
+
const sidecar = join(dirname(database), "config.json");
|
|
41
|
+
if (existsSync(sidecar) || managedConfig || (saved.ok && saved.value))
|
|
42
|
+
managedConfig = chooseManagedConfig({ mode: "open", sidecar, inline: managedConfig, saved: saved.ok ? saved.value : undefined });
|
|
43
|
+
}
|
|
44
|
+
const script = managedConfig ? (managedConfig.model.protocol === "scripted" ? managedConfig.model.script : undefined) : options.script;
|
|
45
|
+
// Managed OpenRouter resolves its named credential inside openDevelopment;
|
|
46
|
+
// scripted runs do not need a provider key at all.
|
|
47
|
+
const config = (script || managedConfig) ? { ...localConnection(), apiKey: "", model: "",
|
|
48
|
+
inspectorPort: Number(process.env.HARNESS_INSPECTOR_PORT ?? 3000), webChatPort: Number(process.env.HARNESS_CHAT_PORT ?? 3001) } : agentConfiguration();
|
|
49
|
+
if (config.managedDirectory) await mkdir(config.managedDirectory, { recursive: true, mode: 0o700 });
|
|
50
|
+
if (managed && create) await mkdir(managed.directory, { recursive: true, mode: 0o700 });
|
|
51
|
+
const development = await openDevelopment({ systemPrompt, database, sessionId, create, script, managedConfig, instructions,
|
|
52
|
+
debugTools: options.debug || options.debugTools,
|
|
53
|
+
timelineTools: options.timelineTools,
|
|
54
|
+
debugInstructions: options.debug && instructions === undefined ? loadInstructions("agent-demo") : undefined,
|
|
55
|
+
provider: script || managedConfig ? undefined : { apiKey: config.apiKey, model: config.model } });
|
|
56
|
+
const { session, inspection, local } = development;
|
|
57
|
+
const outputs = createChannelOutputs();
|
|
58
|
+
const stopOutput = session.subscribe(event => publishChannelEvent(outputs, event));
|
|
59
|
+
|
|
60
|
+
// Restrict the socket itself as well as the default parent directory.
|
|
61
|
+
process.umask(0o077);
|
|
62
|
+
let server: ReturnType<typeof serveLocal> | undefined;
|
|
63
|
+
let inspector: ReturnType<typeof serveInspector> | undefined;
|
|
64
|
+
let webChat: ReturnType<typeof serveWebChat>;
|
|
65
|
+
try {
|
|
66
|
+
const port = config.inspectorPort;
|
|
67
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error("Invalid HARNESS_INSPECTOR_PORT");
|
|
68
|
+
if (!Number.isInteger(config.webChatPort) || config.webChatPort < 0 || config.webChatPort > 65535) throw new Error("Invalid HARNESS_CHAT_PORT");
|
|
69
|
+
server = await bindLocalSocket(config.socketPath, () => serveLocal(local, config.socketPath, outputs, session));
|
|
70
|
+
inspector = bindWebPort(port, "HARNESS_INSPECTOR_PORT", chosen => serveInspector(inspection, chosen));
|
|
71
|
+
// Lifecycle control stays on the owner's Unix socket; the LAN chat gets messages only.
|
|
72
|
+
const handleChat = createChannelHandler(local, outputs);
|
|
73
|
+
webChat = bindWebPort(config.webChatPort, "HARNESS_CHAT_PORT", chosen => serveWebChat(handleChat, chosen));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
// Startup is all-or-nothing: do not leave an agent listening if the inspector
|
|
76
|
+
// could not bind its port and the command reports a startup failure.
|
|
77
|
+
stopOutput();
|
|
78
|
+
await server?.stop(true);
|
|
79
|
+
await inspector?.stop(true);
|
|
80
|
+
development.close();
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
const status = session.status();
|
|
84
|
+
console.log(`Agent listening at ${config.socketPath}. Session ID: ${status.sessionId}. Session storage: ${development.storage}.`);
|
|
85
|
+
console.log(`Context inspector: ${inspector.url}`);
|
|
86
|
+
for (const url of webChat.urls) console.log(`Web chat pairing link: ${url}`);
|
|
87
|
+
// Opening never resumes. A suspended session stays paused, and inspectable, until asked.
|
|
88
|
+
if (status.lifecycle === "suspended" && !options.resume) console.log("Session is suspended and paused. Run `bun run resume` to continue it.");
|
|
89
|
+
else if (status.lifecycle === "suspended") {
|
|
90
|
+
const resumed = session.resume();
|
|
91
|
+
console.log(resumed.ok ? "Resumed the suspended session." : `Cannot resume (${resumed.error.code}): ${resumed.error.message}. The session stays suspended.`);
|
|
92
|
+
} else {
|
|
93
|
+
const interrupted = status.channels.filter(channel => channel.unresolvedInterruption);
|
|
94
|
+
if (interrupted.length) console.log(`Turns left unfinished by a previous run are marked interrupted on: ${interrupted.map(channel => channel.channelId).join(", ")}. They are not retried.`);
|
|
95
|
+
session.start();
|
|
96
|
+
}
|
|
97
|
+
console.log("Ctrl+C stops the agent: running turns are recorded as interrupted. Run `bun run suspend` first to pause cleanly.");
|
|
98
|
+
const stop = () => {
|
|
99
|
+
// Stop is immediate and is not suspension; a cleanly suspended session keeps its checkpoints.
|
|
100
|
+
session.stop("Agent process stopped");
|
|
101
|
+
stopOutput(); server?.stop(true); inspector?.stop(true); webChat.server.stop(true);
|
|
102
|
+
development.close();
|
|
103
|
+
};
|
|
104
|
+
process.once("SIGINT", stop);
|
|
105
|
+
process.once("SIGTERM", stop);
|
|
106
|
+
}
|