@adhdev/daemon-core 0.9.82-rc.43 → 0.9.82-rc.430
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/dist/boot/daemon-lifecycle.d.ts +9 -0
- package/dist/boot/process-hardening.d.ts +50 -0
- package/dist/build-info.d.ts +37 -0
- package/dist/chat/source-machine.d.ts +166 -0
- package/dist/chat/source-resolver.d.ts +104 -0
- package/dist/chat/subscription-updates.d.ts +1 -0
- package/dist/cli-adapter-types.d.ts +68 -2
- package/dist/cli-adapters/cli-script-runner.d.ts +117 -0
- package/dist/cli-adapters/cli-state-engine.d.ts +200 -0
- package/dist/cli-adapters/provider-cli-adapter.d.ts +126 -64
- package/dist/cli-adapters/provider-cli-parse.d.ts +5 -0
- package/dist/cli-adapters/provider-cli-runtime.d.ts +34 -0
- package/dist/cli-adapters/provider-cli-shared.d.ts +74 -0
- package/dist/cli-adapters/pty-write-chunking.d.ts +34 -0
- package/dist/cli-adapters/raw-terminal-io.d.ts +37 -0
- package/dist/cli-adapters/resolve-executable.d.ts +69 -0
- package/dist/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +6 -3
- package/dist/cli-adapters/terminal-backends/types.d.ts +10 -2
- package/dist/cli-adapters/terminal-screen.d.ts +4 -11
- package/dist/commands/chat-commands-debug-bundle.d.ts +14 -0
- package/dist/commands/chat-commands-read.d.ts +7 -0
- package/dist/commands/chat-commands-scope.d.ts +39 -0
- package/dist/commands/chat-commands-shared.d.ts +33 -0
- package/dist/commands/chat-commands-write.d.ts +14 -0
- package/dist/commands/chat-commands.d.ts +10 -23
- package/dist/commands/cli-manager.d.ts +15 -1
- package/dist/commands/handler.d.ts +125 -0
- package/dist/commands/high-family/index.d.ts +3 -0
- package/dist/commands/high-family/mesh-coordinator-launch.d.ts +2 -0
- package/dist/commands/high-family/mesh-events.d.ts +2 -0
- package/dist/commands/high-family/mesh-status.d.ts +2 -0
- package/dist/commands/high-family/types.d.ts +60 -0
- package/dist/commands/low-family/coordinator-prompt.d.ts +9 -0
- package/dist/commands/low-family/daemon-lifecycle.d.ts +2 -0
- package/dist/commands/low-family/diagnostics.d.ts +2 -0
- package/dist/commands/low-family/index.d.ts +3 -0
- package/dist/commands/low-family/mesh-ledger.d.ts +10 -0
- package/dist/commands/low-family/mesh-node-logs.d.ts +2 -0
- package/dist/commands/low-family/notification.d.ts +2 -0
- package/dist/commands/low-family/refine-config.d.ts +2 -0
- package/dist/commands/low-family/session-host.d.ts +2 -0
- package/dist/commands/low-family/spec-providerdev.d.ts +11 -0
- package/dist/commands/low-family/status-meta.d.ts +2 -0
- package/dist/commands/low-family/types.d.ts +33 -0
- package/dist/commands/med-family/cli-agent.d.ts +2 -0
- package/dist/commands/med-family/fast-forward.d.ts +2 -0
- package/dist/commands/med-family/ide.d.ts +10 -0
- package/dist/commands/med-family/index.d.ts +3 -0
- package/dist/commands/med-family/mesh-crud.d.ts +29 -0
- package/dist/commands/med-family/mesh-host-pairing.d.ts +2 -0
- package/dist/commands/med-family/mesh-queue.d.ts +2 -0
- package/dist/commands/med-family/mesh-restart.d.ts +2 -0
- package/dist/commands/med-family/types.d.ts +142 -0
- package/dist/commands/mesh-coordinator.d.ts +85 -1
- package/dist/commands/router.d.ts +276 -2
- package/dist/commands/upgrade-helper.d.ts +41 -1
- package/dist/config/chat-history.d.ts +9 -0
- package/dist/config/config.d.ts +5 -0
- package/dist/config/mesh-config.d.ts +100 -1
- package/dist/config/mesh-json-config.d.ts +199 -0
- package/dist/config/repo-settings.d.ts +77 -0
- package/dist/daemon/dev-server.d.ts +0 -2
- package/dist/detection/ide-detector.d.ts +13 -0
- package/dist/detection/win32-ide-version.d.ts +37 -0
- package/dist/git/change-impact-config.d.ts +159 -0
- package/dist/git/git-commands.d.ts +11 -1
- package/dist/git/git-diff.d.ts +6 -0
- package/dist/git/git-executor.d.ts +11 -0
- package/dist/git/git-status.d.ts +57 -0
- package/dist/git/git-types.d.ts +2 -50
- package/dist/git/git-worktree.d.ts +71 -1
- package/dist/git/index.d.ts +3 -1
- package/dist/index.d.ts +64 -14
- package/dist/index.js +49391 -19228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48574 -18570
- package/dist/index.mjs.map +1 -1
- package/dist/installer.d.ts +1 -4
- package/dist/ipc/local-ipc-server.d.ts +91 -0
- package/dist/launch.d.ts +1 -1
- package/dist/logging/async-batch-writer.d.ts +10 -0
- package/dist/logging/log-redactor.d.ts +24 -0
- package/dist/logging/log-tail-reader.d.ts +81 -0
- package/dist/logging/logger.d.ts +1 -1
- package/dist/mesh/contracts.d.ts +164 -0
- package/dist/mesh/coordinator-prompt.d.ts +89 -0
- package/dist/mesh/coordinator-registry.d.ts +59 -0
- package/dist/mesh/mesh-active-work.d.ts +174 -0
- package/dist/mesh/mesh-clone-grace.d.ts +8 -0
- package/dist/mesh/mesh-coordinator-config.d.ts +21 -0
- package/dist/mesh/mesh-delivery-policy.d.ts +131 -0
- package/dist/mesh/mesh-event-classify.d.ts +5 -0
- package/dist/mesh/mesh-event-forwarding.d.ts +41 -0
- package/dist/mesh/mesh-event-trace.d.ts +21 -0
- package/dist/mesh/mesh-events-coordinator.d.ts +4 -0
- package/dist/mesh/mesh-events-pending.d.ts +69 -0
- package/dist/mesh/mesh-events-stale.d.ts +61 -0
- package/dist/mesh/mesh-events-utils.d.ts +75 -0
- package/dist/mesh/mesh-events.d.ts +6 -49
- package/dist/mesh/mesh-fast-forward.d.ts +81 -0
- package/dist/mesh/mesh-host-ownership.d.ts +9 -0
- package/dist/mesh/mesh-init.d.ts +86 -0
- package/dist/mesh/mesh-ledger-reconciliation.d.ts +23 -4
- package/dist/mesh/mesh-ledger.d.ts +77 -1
- package/dist/mesh/mesh-magi-status.d.ts +63 -0
- package/dist/mesh/mesh-missions.d.ts +189 -0
- package/dist/mesh/mesh-node-identity.d.ts +289 -0
- package/dist/mesh/mesh-queue-assignment.d.ts +113 -0
- package/dist/mesh/mesh-reconcile-loop.d.ts +65 -0
- package/dist/mesh/mesh-refine-batch.d.ts +68 -0
- package/dist/mesh/mesh-refine-gates.d.ts +428 -0
- package/dist/mesh/mesh-refine-status.d.ts +62 -0
- package/dist/mesh/mesh-review-inbox.d.ts +90 -0
- package/dist/mesh/mesh-routing.d.ts +70 -0
- package/dist/mesh/mesh-runtime-store.d.ts +450 -0
- package/dist/mesh/mesh-scheduling-runtime.d.ts +78 -0
- package/dist/mesh/mesh-task-inflight.d.ts +46 -0
- package/dist/mesh/mesh-task-stats.d.ts +49 -0
- package/dist/mesh/mesh-unresolved-forward-outbox.d.ts +30 -0
- package/dist/mesh/mesh-warmup-deadline.d.ts +68 -0
- package/dist/mesh/mesh-work-queue.d.ts +290 -5
- package/dist/mesh/preview-freshness.d.ts +18 -0
- package/dist/mesh/refine-config.d.ts +216 -0
- package/dist/mesh/worktree-bootstrap-config.d.ts +145 -0
- package/dist/providers/acp-provider-instance.d.ts +5 -0
- package/dist/providers/approval-utils.d.ts +20 -0
- package/dist/providers/chat-message-normalization.d.ts +31 -1
- package/dist/providers/cli-provider-instance.d.ts +221 -3
- package/dist/providers/contracts.d.ts +139 -6
- package/dist/providers/external-sources.d.ts +71 -0
- package/dist/providers/manual-attendance.d.ts +63 -0
- package/dist/providers/native-history/antigravity-cli-transcript.d.ts +100 -0
- package/dist/providers/native-history/claude-cli-transcript.d.ts +70 -0
- package/dist/providers/native-history/codex-cli-transcript.d.ts +73 -0
- package/dist/providers/native-history/constants.d.ts +12 -0
- package/dist/providers/native-history/dispatcher.d.ts +27 -0
- package/dist/providers/native-history/hermes-cli-transcript.d.ts +30 -0
- package/dist/providers/native-history/index.d.ts +13 -0
- package/dist/providers/provider-instance-manager.d.ts +29 -0
- package/dist/providers/provider-instance.d.ts +23 -1
- package/dist/providers/provider-loader.d.ts +26 -4
- package/dist/providers/provider-trust.d.ts +31 -0
- package/dist/providers/read-chat-contract.d.ts +29 -0
- package/dist/providers/sdk/v1/builders/acp/detect-status.d.ts +68 -0
- package/dist/providers/sdk/v1/builders/cli/detect-status.d.ts +86 -0
- package/dist/providers/sdk/v1/builders/cli/parse-approval-squash.d.ts +59 -0
- package/dist/providers/sdk/v1/builders/cli/parse-approval.d.ts +65 -0
- package/dist/providers/sdk/v1/builders/cli/parse-session.d.ts +91 -0
- package/dist/providers/sdk/v1/builders/cli/visible-region.d.ts +42 -0
- package/dist/providers/sdk/v1/fixture-tooling/format.d.ts +126 -0
- package/dist/providers/sdk/v1/fixture-tooling/index.d.ts +8 -0
- package/dist/providers/sdk/v1/fixture-tooling/replay.d.ts +38 -0
- package/dist/providers/sdk/v1/index.d.ts +30 -0
- package/dist/providers/sdk/v1/sandbox/README-design.d.ts +193 -0
- package/dist/providers/sdk/v1/sandbox/require-whitelist.d.ts +74 -0
- package/dist/providers/sdk/v1/sandbox/script-runner.d.ts +98 -0
- package/dist/providers/sdk/v1/types/cli/index.d.ts +277 -0
- package/dist/providers/sdk/v1/types/common/index.d.ts +203 -0
- package/dist/providers/sdk/v1/validators/index.d.ts +5 -0
- package/dist/providers/sdk/v1/validators/manifest.d.ts +40 -0
- package/dist/providers/sdk/v1/validators/taint.d.ts +52 -0
- package/dist/providers/spec/adapter.d.ts +91 -0
- package/dist/providers/spec/cli-adapter.d.ts +223 -0
- package/dist/providers/spec/evaluator.d.ts +45 -0
- package/dist/providers/spec/fsm-driver.d.ts +422 -0
- package/dist/providers/spec/fsm-evaluator.d.ts +76 -0
- package/dist/providers/spec/fsm-loader.d.ts +14 -0
- package/dist/providers/spec/fsm-types.d.ts +174 -0
- package/dist/providers/spec/native-history-executor.d.ts +41 -0
- package/dist/providers/spec/pre-launch-trust.d.ts +16 -0
- package/dist/providers/spec/route.d.ts +4 -0
- package/dist/providers/spec/types.d.ts +222 -0
- package/dist/providers/status-monitor.d.ts +7 -7
- package/dist/providers/transcript-v2.d.ts +176 -0
- package/dist/providers/types/interactive-prompt.d.ts +84 -0
- package/dist/providers/working-dir.d.ts +17 -0
- package/dist/repo-mesh-types.d.ts +501 -13
- package/dist/runtime-defaults.d.ts +2 -0
- package/dist/sessions/registry.d.ts +6 -0
- package/dist/shared-types-extra.d.ts +2 -4
- package/dist/shared-types.d.ts +59 -2
- package/dist/status/normalize.d.ts +1 -1
- package/dist/status/normalize.js +1 -0
- package/dist/status/normalize.js.map +1 -1
- package/dist/status/normalize.mjs +1 -0
- package/dist/status/normalize.mjs.map +1 -1
- package/dist/status/reporter.d.ts +2 -0
- package/dist/status/snapshot.d.ts +26 -0
- package/dist/system/hash.d.ts +8 -0
- package/dist/system/load-better-sqlite3.d.ts +21 -0
- package/dist/types.d.ts +5 -0
- package/package.json +7 -3
- package/src/agent-stream/poller.ts +2 -3
- package/src/agent-stream/provider-adapter.ts +1 -1
- package/src/boot/daemon-lifecycle.ts +63 -12
- package/src/boot/process-hardening.ts +89 -0
- package/src/build-info.ts +73 -0
- package/src/chat/source-machine.ts +534 -0
- package/src/chat/source-resolver.ts +0 -0
- package/src/chat/subscription-updates.ts +20 -1
- package/src/cli-adapter-types.d.ts +3 -1
- package/src/cli-adapter-types.ts +68 -2
- package/src/cli-adapters/cli-script-runner.ts +421 -0
- package/src/cli-adapters/cli-state-engine.ts +1246 -0
- package/src/cli-adapters/provider-cli-adapter.d.ts +1 -1
- package/src/cli-adapters/provider-cli-adapter.ts +914 -1144
- package/src/cli-adapters/provider-cli-parse.d.ts +2 -0
- package/src/cli-adapters/provider-cli-parse.ts +19 -0
- package/src/cli-adapters/provider-cli-runtime.ts +56 -7
- package/src/cli-adapters/provider-cli-shared.d.ts +4 -0
- package/src/cli-adapters/provider-cli-shared.ts +121 -11
- package/src/cli-adapters/pty-transport.ts +2 -1
- package/src/cli-adapters/pty-write-chunking.ts +106 -0
- package/src/cli-adapters/raw-terminal-io.ts +252 -0
- package/src/cli-adapters/resolve-executable.ts +204 -0
- package/src/cli-adapters/session-host-transport.ts +2 -1
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.ts +63 -29
- package/src/cli-adapters/terminal-backends/types.ts +10 -3
- package/src/cli-adapters/terminal-screen.ts +16 -81
- package/src/commands/WINDOWS-UPGRADE-LOCK-FAILURE.md +198 -0
- package/src/commands/chat-commands-debug-bundle.ts +398 -0
- package/src/commands/chat-commands-read.ts +2327 -0
- package/src/commands/chat-commands-scope.ts +54 -0
- package/src/commands/chat-commands-shared.ts +114 -0
- package/src/commands/chat-commands-write.ts +891 -0
- package/src/commands/chat-commands.ts +19 -1841
- package/src/commands/cli-manager.ts +544 -26
- package/src/commands/handler.ts +841 -2
- package/src/commands/high-family/index.ts +28 -0
- package/src/commands/high-family/mesh-coordinator-launch.ts +678 -0
- package/src/commands/high-family/mesh-events.ts +80 -0
- package/src/commands/high-family/mesh-status.ts +710 -0
- package/src/commands/high-family/types.ts +76 -0
- package/src/commands/low-family/coordinator-prompt.ts +72 -0
- package/src/commands/low-family/daemon-lifecycle.ts +107 -0
- package/src/commands/low-family/diagnostics.ts +57 -0
- package/src/commands/low-family/index.ts +37 -0
- package/src/commands/low-family/mesh-ledger.ts +62 -0
- package/src/commands/low-family/mesh-node-logs.ts +87 -0
- package/src/commands/low-family/notification.ts +116 -0
- package/src/commands/low-family/refine-config.ts +106 -0
- package/src/commands/low-family/session-host.ts +274 -0
- package/src/commands/low-family/spec-providerdev.ts +217 -0
- package/src/commands/low-family/status-meta.ts +112 -0
- package/src/commands/low-family/types.ts +39 -0
- package/src/commands/med-family/cli-agent.ts +238 -0
- package/src/commands/med-family/fast-forward.ts +230 -0
- package/src/commands/med-family/ide.ts +163 -0
- package/src/commands/med-family/index.ts +37 -0
- package/src/commands/med-family/mesh-crud.ts +1066 -0
- package/src/commands/med-family/mesh-host-pairing.ts +234 -0
- package/src/commands/med-family/mesh-queue.ts +167 -0
- package/src/commands/med-family/mesh-restart.ts +92 -0
- package/src/commands/med-family/types.ts +143 -0
- package/src/commands/mesh-coordinator.ts +334 -124
- package/src/commands/router.ts +2711 -3254
- package/src/commands/stream-commands.ts +8 -0
- package/src/commands/upgrade-helper.ts +310 -45
- package/src/config/chat-history.ts +483 -24
- package/src/config/config.ts +12 -0
- package/src/config/mesh-config.ts +495 -22
- package/src/config/mesh-json-config.ts +376 -0
- package/src/config/recent-activity.ts +8 -2
- package/src/config/repo-settings.ts +111 -0
- package/src/daemon/dev-auto-implement.ts +3 -2
- package/src/daemon/dev-cli-debug.ts +10 -1
- package/src/daemon/dev-server.ts +0 -541
- package/src/detection/cli-detector.ts +28 -9
- package/src/detection/ide-detector.ts +55 -16
- package/src/detection/win32-ide-version.ts +106 -0
- package/src/git/change-impact-config.ts +354 -0
- package/src/git/git-commands.ts +59 -15
- package/src/git/git-diff.ts +81 -11
- package/src/git/git-executor.ts +12 -0
- package/src/git/git-status.ts +767 -48
- package/src/git/git-types.ts +14 -62
- package/src/git/git-worktree.ts +261 -4
- package/src/git/index.ts +17 -0
- package/src/index.ts +194 -12
- package/src/installer.d.ts +1 -1
- package/src/installer.ts +8 -6
- package/src/ipc/local-ipc-server.ts +278 -0
- package/src/launch.d.ts +1 -1
- package/src/launch.ts +37 -28
- package/src/logging/async-batch-writer.ts +55 -0
- package/src/logging/command-log.ts +7 -5
- package/src/logging/log-redactor.ts +100 -0
- package/src/logging/log-tail-reader.ts +341 -0
- package/src/logging/logger.ts +14 -7
- package/src/mesh/contracts.ts +338 -0
- package/src/mesh/coordinator-prompt.ts +381 -33
- package/src/mesh/coordinator-registry.ts +121 -0
- package/src/mesh/mesh-active-work.ts +645 -0
- package/src/mesh/mesh-clone-grace.ts +68 -0
- package/src/mesh/mesh-coordinator-config.ts +97 -0
- package/src/mesh/mesh-delivery-policy.ts +315 -0
- package/src/mesh/mesh-event-classify.ts +51 -0
- package/src/mesh/mesh-event-forwarding.ts +1888 -0
- package/src/mesh/mesh-event-trace.ts +67 -0
- package/src/mesh/mesh-events-coordinator.ts +32 -0
- package/src/mesh/mesh-events-pending.ts +656 -0
- package/src/mesh/mesh-events-stale.ts +389 -0
- package/src/mesh/mesh-events-utils.ts +443 -0
- package/src/mesh/mesh-events.ts +33 -1035
- package/src/mesh/mesh-fast-forward.ts +843 -0
- package/src/mesh/mesh-host-ownership.ts +73 -0
- package/src/mesh/mesh-init.ts +260 -0
- package/src/mesh/mesh-ledger-reconciliation.ts +12 -7
- package/src/mesh/mesh-ledger.ts +656 -102
- package/src/mesh/mesh-magi-status.ts +223 -0
- package/src/mesh/mesh-missions.ts +449 -0
- package/src/mesh/mesh-node-identity.ts +1887 -0
- package/src/mesh/mesh-queue-assignment.ts +1918 -0
- package/src/mesh/mesh-reconcile-loop.ts +1780 -0
- package/src/mesh/mesh-refine-batch.ts +205 -0
- package/src/mesh/mesh-refine-gates.ts +1673 -0
- package/src/mesh/mesh-refine-status.ts +231 -0
- package/src/mesh/mesh-review-inbox.ts +307 -0
- package/src/mesh/mesh-routing.ts +291 -0
- package/src/mesh/mesh-runtime-store.ts +1853 -0
- package/src/mesh/mesh-scheduling-runtime.ts +198 -0
- package/src/mesh/mesh-task-inflight.ts +70 -0
- package/src/mesh/mesh-task-stats.ts +161 -0
- package/src/mesh/mesh-unresolved-forward-outbox.ts +185 -0
- package/src/mesh/mesh-warmup-deadline.ts +152 -0
- package/src/mesh/mesh-work-queue.ts +1243 -141
- package/src/mesh/preview-freshness.ts +118 -0
- package/src/mesh/refine-config.ts +423 -0
- package/src/mesh/worktree-bootstrap-config.ts +450 -0
- package/src/providers/acp-provider-instance.ts +43 -10
- package/src/providers/approval-utils.d.ts +5 -0
- package/src/providers/approval-utils.ts +57 -5
- package/src/providers/chat-message-normalization.ts +92 -4
- package/src/providers/cli-provider-instance.ts +1933 -104
- package/src/providers/contracts.d.ts +55 -0
- package/src/providers/contracts.ts +150 -6
- package/src/providers/extension-provider-instance.ts +12 -7
- package/src/providers/external-sources.ts +218 -0
- package/src/providers/ide-provider-instance.ts +35 -12
- package/src/providers/manual-attendance.ts +85 -0
- package/src/providers/native-history/antigravity-cli-transcript.ts +643 -0
- package/src/providers/native-history/claude-cli-transcript.ts +396 -0
- package/src/providers/native-history/codex-cli-transcript.ts +479 -0
- package/src/providers/native-history/constants.ts +19 -0
- package/src/providers/native-history/dispatcher.ts +339 -0
- package/src/providers/native-history/hermes-cli-transcript.ts +230 -0
- package/src/providers/native-history/index.ts +30 -0
- package/src/providers/provider-instance-manager.ts +71 -0
- package/src/providers/provider-instance.ts +19 -1
- package/src/providers/provider-loader.ts +668 -50
- package/src/providers/provider-schema.ts +87 -14
- package/src/providers/provider-trust.ts +114 -0
- package/src/providers/read-chat-contract.ts +76 -16
- package/src/providers/sdk/README.md +49 -0
- package/src/providers/sdk/v1/builders/acp/detect-status.ts +144 -0
- package/src/providers/sdk/v1/builders/cli/detect-status.ts +313 -0
- package/src/providers/sdk/v1/builders/cli/parse-approval-squash.ts +158 -0
- package/src/providers/sdk/v1/builders/cli/parse-approval.ts +250 -0
- package/src/providers/sdk/v1/builders/cli/parse-session.ts +276 -0
- package/src/providers/sdk/v1/builders/cli/visible-region.ts +143 -0
- package/src/providers/sdk/v1/fixture-tooling/format.ts +130 -0
- package/src/providers/sdk/v1/fixture-tooling/index.ts +22 -0
- package/src/providers/sdk/v1/fixture-tooling/replay.ts +352 -0
- package/src/providers/sdk/v1/index.ts +152 -0
- package/src/providers/sdk/v1/sandbox/README-design.ts +195 -0
- package/src/providers/sdk/v1/sandbox/require-whitelist.ts +472 -0
- package/src/providers/sdk/v1/sandbox/script-runner.ts +150 -0
- package/src/providers/sdk/v1/schemas/cli/provider.schema.json +504 -0
- package/src/providers/sdk/v1/schemas/primitives/acp-session-protocol-v1.json +131 -0
- package/src/providers/sdk/v1/schemas/primitives/native-history-codex-rollout-v1.json +66 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-approval-squash-v1.json +91 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-assistant-block-v1.json +91 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-cue-ordering-v1.json +47 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-dispatch-order-v1.json +32 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-footer-chrome-v1.json +42 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-index-finder-v1.json +27 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-modal-v1.json +125 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-prompt-marker-v1.json +45 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-session-id-extraction-v1.json +46 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-settled-prompt-v1.json +71 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-spinner-v1.json +83 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-transcript-pty-v1.json +83 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-visible-region-v1.json +57 -0
- package/src/providers/sdk/v1/schemas/primitives/tui-welcome-screen-v1.json +35 -0
- package/src/providers/sdk/v1/types/cli/index.ts +365 -0
- package/src/providers/sdk/v1/types/common/index.ts +229 -0
- package/src/providers/sdk/v1/validators/index.ts +19 -0
- package/src/providers/sdk/v1/validators/manifest.ts +110 -0
- package/src/providers/sdk/v1/validators/taint.ts +309 -0
- package/src/providers/spec/adapter.ts +235 -0
- package/src/providers/spec/cli-adapter.ts +1056 -0
- package/src/providers/spec/evaluator.ts +407 -0
- package/src/providers/spec/fsm-driver.ts +1410 -0
- package/src/providers/spec/fsm-evaluator.ts +272 -0
- package/src/providers/spec/fsm-loader.ts +120 -0
- package/src/providers/spec/fsm-types.ts +273 -0
- package/src/providers/spec/native-history-executor.ts +1128 -0
- package/src/providers/spec/pre-launch-trust.ts +104 -0
- package/src/providers/spec/route.ts +51 -0
- package/src/providers/spec/types.ts +262 -0
- package/src/providers/status-monitor.d.ts +7 -7
- package/src/providers/status-monitor.ts +37 -22
- package/src/providers/transcript-v2.ts +567 -0
- package/src/providers/types/interactive-prompt.ts +536 -0
- package/src/providers/version-archive.ts +64 -24
- package/src/providers/working-dir.ts +23 -0
- package/src/repo-mesh-types.ts +740 -14
- package/src/runtime-defaults.ts +39 -0
- package/src/sessions/registry.ts +6 -0
- package/src/shared-types-extra.ts +2 -4
- package/src/shared-types.d.ts +8 -0
- package/src/shared-types.ts +64 -1
- package/src/status/builders.ts +26 -6
- package/src/status/normalize.ts +2 -0
- package/src/status/reporter.ts +19 -1
- package/src/status/snapshot.ts +95 -26
- package/src/system/hash.ts +23 -0
- package/src/system/host-memory.ts +29 -12
- package/src/system/load-better-sqlite3.ts +68 -0
- package/src/types.ts +5 -0
- package/dist/cli-adapters/terminal-backends/xterm-backend.d.ts +0 -17
- package/dist/mesh/mesh-sync.d.ts +0 -53
- package/src/cli-adapters/terminal-backends/ghostty-vt-backend.d.ts +0 -16
- package/src/cli-adapters/terminal-backends/xterm-backend.ts +0 -97
- package/src/mesh/mesh-sync.ts +0 -111
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat Transcript Contract v2
|
|
3
|
+
*
|
|
4
|
+
* First-class message identity, monotonic sequence, strict enums. Designed to
|
|
5
|
+
* replace the v1 contract (contracts.ts ReadChatResult + types.ts ChatMessage)
|
|
6
|
+
* during the A2 big-bang. This module defines the contract; it does not yet
|
|
7
|
+
* change runtime behaviour. v1 keeps working until A2 flips the switch.
|
|
8
|
+
*
|
|
9
|
+
* Invariants v2 enforces (and v1 does not):
|
|
10
|
+
* 1. Every ChatMessageV2 has providerUnitKey, bubbleId, sequence — none optional.
|
|
11
|
+
* 2. sequence is a monotonic integer per (sessionId, source) tuple. Producers
|
|
12
|
+
* never reuse it; consumers MAY assume strict ordering.
|
|
13
|
+
* 3. providerUnitKey is stable across re-reads: the same logical message
|
|
14
|
+
* always yields the same key even if its index shifts or content is
|
|
15
|
+
* edited mid-stream. Producers derive it from provider-owned identifiers
|
|
16
|
+
* (turn id, native message id), not from content hashes or array index.
|
|
17
|
+
* 4. timestamp is producer-asserted wall-clock; orderingTimestamp is monotonic
|
|
18
|
+
* and used for snapshot diffs. 1ms fallback increments are forbidden — if
|
|
19
|
+
* a producer cannot supply a stable monotonic value, the daemon assigns
|
|
20
|
+
* sequence at ingest and orderingTimestamp = ingestedAt.
|
|
21
|
+
* 5. visibility / source / role / kind are strict unions. No `(string & {})`
|
|
22
|
+
* escape hatches.
|
|
23
|
+
* 6. Coverage is exactly one of full/tail/current-turn. Mixing it with
|
|
24
|
+
* partialReason or unavailableReason is a contract violation.
|
|
25
|
+
* 7. workspace / sessionId are explicit on every ReadChatResultV2; the daemon
|
|
26
|
+
* no longer infers them from message bodies.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import type { MessagePart, ToolCallInfo } from './contracts.js';
|
|
30
|
+
|
|
31
|
+
// ─── Contract version ────────────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
export const CHAT_CONTRACT_VERSION_V1 = '1.0' as const;
|
|
34
|
+
export const CHAT_CONTRACT_VERSION_V2 = '2.0' as const;
|
|
35
|
+
|
|
36
|
+
export type ChatContractVersion =
|
|
37
|
+
| typeof CHAT_CONTRACT_VERSION_V1
|
|
38
|
+
| typeof CHAT_CONTRACT_VERSION_V2;
|
|
39
|
+
|
|
40
|
+
export const SUPPORTED_CHAT_CONTRACT_VERSIONS: readonly ChatContractVersion[] = [
|
|
41
|
+
CHAT_CONTRACT_VERSION_V1,
|
|
42
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
43
|
+
] as const;
|
|
44
|
+
|
|
45
|
+
// ─── Strict role / kind / visibility / source enums ─────────────────────
|
|
46
|
+
|
|
47
|
+
export const CHAT_ROLES_V2 = ['user', 'assistant', 'system'] as const;
|
|
48
|
+
export type ChatRoleV2 = typeof CHAT_ROLES_V2[number];
|
|
49
|
+
|
|
50
|
+
export const CHAT_MESSAGE_KINDS_V2 = [
|
|
51
|
+
'standard',
|
|
52
|
+
'thought',
|
|
53
|
+
'tool',
|
|
54
|
+
'terminal',
|
|
55
|
+
'system',
|
|
56
|
+
] as const;
|
|
57
|
+
export type ChatMessageKindV2 = typeof CHAT_MESSAGE_KINDS_V2[number];
|
|
58
|
+
|
|
59
|
+
export const CHAT_VISIBILITIES_V2 = ['user', 'debug', 'internal', 'hidden'] as const;
|
|
60
|
+
export type ChatVisibilityV2 = typeof CHAT_VISIBILITIES_V2[number];
|
|
61
|
+
|
|
62
|
+
export const CHAT_AUDIENCES_V2 = ['chat', 'debug', 'trace', 'internal'] as const;
|
|
63
|
+
export type ChatAudienceV2 = typeof CHAT_AUDIENCES_V2[number];
|
|
64
|
+
|
|
65
|
+
export const CHAT_SOURCES_V2 = [
|
|
66
|
+
'assistant_text',
|
|
67
|
+
'tool_call',
|
|
68
|
+
'terminal_command',
|
|
69
|
+
'runtime_activity',
|
|
70
|
+
'runtime_status',
|
|
71
|
+
'provider_chrome',
|
|
72
|
+
'control',
|
|
73
|
+
] as const;
|
|
74
|
+
export type ChatSourceV2 = typeof CHAT_SOURCES_V2[number];
|
|
75
|
+
|
|
76
|
+
export const CHAT_BUBBLE_STATES_V2 = ['draft', 'streaming', 'final', 'removed'] as const;
|
|
77
|
+
export type ChatBubbleStateV2 = typeof CHAT_BUBBLE_STATES_V2[number];
|
|
78
|
+
|
|
79
|
+
// ─── Message identity ────────────────────────────────────────────────────
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Stable identity of a single chat message. All fields are required in v2.
|
|
83
|
+
*
|
|
84
|
+
* - providerUnitKey: provider-owned canonical id. Must be derivable from
|
|
85
|
+
* provider primitives (native message id, turn id, bubble id), NOT from
|
|
86
|
+
* array index or content hash. Stable across re-reads of the same logical
|
|
87
|
+
* message even if neighbours change.
|
|
88
|
+
* - bubbleId: dashboard-owned bubble identity. May equal providerUnitKey when
|
|
89
|
+
* the provider already exposes a bubble-grained id; otherwise daemon
|
|
90
|
+
* derives it deterministically from providerUnitKey (e.g. `bubble:${key}`).
|
|
91
|
+
* - sequence: monotonic integer per (sessionId, source). Strictly increasing
|
|
92
|
+
* over the lifetime of the session. Used for snapshot diffs and dedup.
|
|
93
|
+
* - turnKey: stable identifier for the conversation turn this message belongs
|
|
94
|
+
* to. Required so consumers can group messages without re-deriving turns.
|
|
95
|
+
*/
|
|
96
|
+
export interface MessageIdentityV2 {
|
|
97
|
+
providerUnitKey: string;
|
|
98
|
+
bubbleId: string;
|
|
99
|
+
sequence: number;
|
|
100
|
+
turnKey: string;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// ─── Timing ──────────────────────────────────────────────────────────────
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Producer-asserted wall-clock time (ms since epoch). Forward jumps are
|
|
107
|
+
* permitted; consumers MUST NOT rely on this for ordering.
|
|
108
|
+
*/
|
|
109
|
+
export type ChatTimestampMs = number;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Monotonic ordering value (ms since epoch, but assigned by the daemon at
|
|
113
|
+
* ingest to guarantee monotonicity even if the producer's wall clock skews).
|
|
114
|
+
* Used by snapshot diffs in place of timestamp.
|
|
115
|
+
*/
|
|
116
|
+
export type ChatOrderingTimestampMs = number;
|
|
117
|
+
|
|
118
|
+
// ─── Message ─────────────────────────────────────────────────────────────
|
|
119
|
+
|
|
120
|
+
export interface ChatMessageV2 extends MessageIdentityV2 {
|
|
121
|
+
role: ChatRoleV2;
|
|
122
|
+
kind: ChatMessageKindV2;
|
|
123
|
+
content: string | MessagePart[];
|
|
124
|
+
bubbleState: ChatBubbleStateV2;
|
|
125
|
+
timestamp: ChatTimestampMs;
|
|
126
|
+
orderingTimestamp: ChatOrderingTimestampMs;
|
|
127
|
+
visibility: ChatVisibilityV2;
|
|
128
|
+
audience: ChatAudienceV2;
|
|
129
|
+
source: ChatSourceV2;
|
|
130
|
+
/** Sender display name (for shared sessions). Empty string when unused. */
|
|
131
|
+
senderName: string;
|
|
132
|
+
/** Tool calls associated with this message. Empty array when none. */
|
|
133
|
+
toolCalls: ToolCallInfo[];
|
|
134
|
+
/** Producer-defined metadata. Daemon never inspects this except for passthrough. */
|
|
135
|
+
meta: Readonly<Record<string, unknown>>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ─── Workspace / session context ─────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
export interface WorkspaceContextV2 {
|
|
141
|
+
/** Absolute realpath of the workspace the session is reading from. */
|
|
142
|
+
workspacePath: string;
|
|
143
|
+
/** Workspace the session was intended to operate on (may differ during cross-workspace ops). */
|
|
144
|
+
intendedWorkspacePath: string;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface SessionContextV2 {
|
|
148
|
+
/** Provider-owned session id (e.g. claude.jsonl uuid, codex session_meta.id). */
|
|
149
|
+
providerSessionId: string;
|
|
150
|
+
/** Optional daemon-side history alias used to disambiguate within a workspace. */
|
|
151
|
+
historySessionId?: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ─── Coverage (honest signal) ────────────────────────────────────────────
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* v1 allowed `coverage='full'` to coexist with `partialReason`/`unavailableReason`,
|
|
158
|
+
* which is a contract lie. v2 makes the three states mutually exclusive.
|
|
159
|
+
*/
|
|
160
|
+
export type CoverageHintV2 =
|
|
161
|
+
| { kind: 'full' }
|
|
162
|
+
| { kind: 'tail'; tailMessageCount: number }
|
|
163
|
+
| { kind: 'current-turn'; turnKey: string }
|
|
164
|
+
| { kind: 'partial'; partialReason: string }
|
|
165
|
+
| { kind: 'unavailable'; unavailableReason: string };
|
|
166
|
+
|
|
167
|
+
// ─── Canonical history declaration (provider.json) ───────────────────────
|
|
168
|
+
|
|
169
|
+
export type CanonicalHistoryModeV2 = 'native-source' | 'disabled' | 'materialized-mirror';
|
|
170
|
+
|
|
171
|
+
export interface CanonicalHistoryDeclarationV2 {
|
|
172
|
+
contractVersion: ChatContractVersion;
|
|
173
|
+
format: string;
|
|
174
|
+
mode: CanonicalHistoryModeV2;
|
|
175
|
+
watchPath?: string;
|
|
176
|
+
scripts: {
|
|
177
|
+
readSession: string;
|
|
178
|
+
listSessions: string;
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ─── ReadChat result ─────────────────────────────────────────────────────
|
|
183
|
+
|
|
184
|
+
export type ReadChatStatusV2 =
|
|
185
|
+
| 'idle'
|
|
186
|
+
| 'generating'
|
|
187
|
+
| 'waiting_approval'
|
|
188
|
+
| 'error'
|
|
189
|
+
| 'panel_hidden'
|
|
190
|
+
| 'streaming';
|
|
191
|
+
|
|
192
|
+
export type ReadChatTurnStatusV2 = 'open' | 'waiting_approval' | 'complete' | 'error';
|
|
193
|
+
|
|
194
|
+
export interface ReadChatResultV2 {
|
|
195
|
+
contractVersion: typeof CHAT_CONTRACT_VERSION_V2;
|
|
196
|
+
workspace: WorkspaceContextV2;
|
|
197
|
+
session: SessionContextV2;
|
|
198
|
+
coverage: CoverageHintV2;
|
|
199
|
+
status: ReadChatStatusV2;
|
|
200
|
+
messages: ChatMessageV2[];
|
|
201
|
+
currentTurnId: string;
|
|
202
|
+
turnStatus: ReadChatTurnStatusV2;
|
|
203
|
+
transcriptAuthority: 'provider' | 'daemon';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// ─── Validation primitives ───────────────────────────────────────────────
|
|
207
|
+
|
|
208
|
+
export class ChatContractViolationError extends Error {
|
|
209
|
+
readonly violationPath: string;
|
|
210
|
+
readonly contractVersion: ChatContractVersion;
|
|
211
|
+
constructor(
|
|
212
|
+
contractVersion: ChatContractVersion,
|
|
213
|
+
violationPath: string,
|
|
214
|
+
detail: string,
|
|
215
|
+
) {
|
|
216
|
+
super(`chat contract ${contractVersion} violation at ${violationPath}: ${detail}`);
|
|
217
|
+
this.name = 'ChatContractViolationError';
|
|
218
|
+
this.violationPath = violationPath;
|
|
219
|
+
this.contractVersion = contractVersion;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
224
|
+
return !!value && typeof value === 'object' && !Array.isArray(value);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function assertSequenceMonotonic(
|
|
228
|
+
messages: ReadonlyArray<{ sequence: number }>,
|
|
229
|
+
pathPrefix: string,
|
|
230
|
+
): void {
|
|
231
|
+
for (let i = 1; i < messages.length; i += 1) {
|
|
232
|
+
const prev = messages[i - 1]!.sequence;
|
|
233
|
+
const cur = messages[i]!.sequence;
|
|
234
|
+
if (!(cur > prev)) {
|
|
235
|
+
throw new ChatContractViolationError(
|
|
236
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
237
|
+
`${pathPrefix}[${i}].sequence`,
|
|
238
|
+
`sequence must be strictly increasing (prev=${prev}, current=${cur})`,
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function assertOrderingTimestampMonotonic(
|
|
245
|
+
messages: ReadonlyArray<{ orderingTimestamp: number }>,
|
|
246
|
+
pathPrefix: string,
|
|
247
|
+
): void {
|
|
248
|
+
for (let i = 1; i < messages.length; i += 1) {
|
|
249
|
+
const prev = messages[i - 1]!.orderingTimestamp;
|
|
250
|
+
const cur = messages[i]!.orderingTimestamp;
|
|
251
|
+
if (cur < prev) {
|
|
252
|
+
throw new ChatContractViolationError(
|
|
253
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
254
|
+
`${pathPrefix}[${i}].orderingTimestamp`,
|
|
255
|
+
`orderingTimestamp must be monotonic non-decreasing (prev=${prev}, current=${cur})`,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function assertIdentity(message: Record<string, unknown>, index: number): MessageIdentityV2 {
|
|
262
|
+
const providerUnitKey = message['providerUnitKey'];
|
|
263
|
+
const bubbleId = message['bubbleId'];
|
|
264
|
+
const sequence = message['sequence'];
|
|
265
|
+
const turnKey = message['turnKey'];
|
|
266
|
+
if (typeof providerUnitKey !== 'string' || !providerUnitKey.length) {
|
|
267
|
+
throw new ChatContractViolationError(
|
|
268
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
269
|
+
`messages[${index}].providerUnitKey`,
|
|
270
|
+
'must be a non-empty string',
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
if (typeof bubbleId !== 'string' || !bubbleId.length) {
|
|
274
|
+
throw new ChatContractViolationError(
|
|
275
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
276
|
+
`messages[${index}].bubbleId`,
|
|
277
|
+
'must be a non-empty string',
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
if (typeof sequence !== 'number' || !Number.isInteger(sequence) || sequence < 0) {
|
|
281
|
+
throw new ChatContractViolationError(
|
|
282
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
283
|
+
`messages[${index}].sequence`,
|
|
284
|
+
'must be a non-negative integer',
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
if (typeof turnKey !== 'string' || !turnKey.length) {
|
|
288
|
+
throw new ChatContractViolationError(
|
|
289
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
290
|
+
`messages[${index}].turnKey`,
|
|
291
|
+
'must be a non-empty string',
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
return { providerUnitKey, bubbleId, sequence, turnKey };
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
function assertEnum<T extends string>(
|
|
298
|
+
value: unknown,
|
|
299
|
+
allowed: readonly T[],
|
|
300
|
+
path: string,
|
|
301
|
+
): T {
|
|
302
|
+
if (typeof value !== 'string' || !(allowed as readonly string[]).includes(value)) {
|
|
303
|
+
throw new ChatContractViolationError(
|
|
304
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
305
|
+
path,
|
|
306
|
+
`must be one of ${allowed.join(', ')} (got ${JSON.stringify(value)})`,
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
return value as T;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function assertContent(value: unknown, path: string): string | MessagePart[] {
|
|
313
|
+
if (typeof value === 'string') return value;
|
|
314
|
+
if (Array.isArray(value)) return value as MessagePart[];
|
|
315
|
+
throw new ChatContractViolationError(
|
|
316
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
317
|
+
path,
|
|
318
|
+
'must be a string or MessagePart[]',
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function assertCoverage(value: unknown, path: string): CoverageHintV2 {
|
|
323
|
+
if (!isPlainObject(value)) {
|
|
324
|
+
throw new ChatContractViolationError(
|
|
325
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
326
|
+
path,
|
|
327
|
+
'must be a CoverageHintV2 object',
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
const kind = value['kind'];
|
|
331
|
+
switch (kind) {
|
|
332
|
+
case 'full':
|
|
333
|
+
return { kind: 'full' };
|
|
334
|
+
case 'tail': {
|
|
335
|
+
const n = value['tailMessageCount'];
|
|
336
|
+
if (typeof n !== 'number' || !Number.isInteger(n) || n < 0) {
|
|
337
|
+
throw new ChatContractViolationError(
|
|
338
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
339
|
+
`${path}.tailMessageCount`,
|
|
340
|
+
'must be a non-negative integer for tail coverage',
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
return { kind: 'tail', tailMessageCount: n };
|
|
344
|
+
}
|
|
345
|
+
case 'current-turn': {
|
|
346
|
+
const turnKey = value['turnKey'];
|
|
347
|
+
if (typeof turnKey !== 'string' || !turnKey.length) {
|
|
348
|
+
throw new ChatContractViolationError(
|
|
349
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
350
|
+
`${path}.turnKey`,
|
|
351
|
+
'current-turn coverage requires a non-empty turnKey',
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
return { kind: 'current-turn', turnKey };
|
|
355
|
+
}
|
|
356
|
+
case 'partial': {
|
|
357
|
+
const reason = value['partialReason'];
|
|
358
|
+
if (typeof reason !== 'string' || !reason.length) {
|
|
359
|
+
throw new ChatContractViolationError(
|
|
360
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
361
|
+
`${path}.partialReason`,
|
|
362
|
+
'partial coverage requires a non-empty partialReason',
|
|
363
|
+
);
|
|
364
|
+
}
|
|
365
|
+
return { kind: 'partial', partialReason: reason };
|
|
366
|
+
}
|
|
367
|
+
case 'unavailable': {
|
|
368
|
+
const reason = value['unavailableReason'];
|
|
369
|
+
if (typeof reason !== 'string' || !reason.length) {
|
|
370
|
+
throw new ChatContractViolationError(
|
|
371
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
372
|
+
`${path}.unavailableReason`,
|
|
373
|
+
'unavailable coverage requires a non-empty unavailableReason',
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
return { kind: 'unavailable', unavailableReason: reason };
|
|
377
|
+
}
|
|
378
|
+
default:
|
|
379
|
+
throw new ChatContractViolationError(
|
|
380
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
381
|
+
`${path}.kind`,
|
|
382
|
+
`must be one of full | tail | current-turn | partial | unavailable (got ${JSON.stringify(kind)})`,
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function assertMessageV2(raw: unknown, index: number): ChatMessageV2 {
|
|
388
|
+
if (!isPlainObject(raw)) {
|
|
389
|
+
throw new ChatContractViolationError(
|
|
390
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
391
|
+
`messages[${index}]`,
|
|
392
|
+
'must be an object',
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
const identity = assertIdentity(raw, index);
|
|
396
|
+
const role = assertEnum(raw['role'], CHAT_ROLES_V2, `messages[${index}].role`);
|
|
397
|
+
const kind = assertEnum(raw['kind'], CHAT_MESSAGE_KINDS_V2, `messages[${index}].kind`);
|
|
398
|
+
const content = assertContent(raw['content'], `messages[${index}].content`);
|
|
399
|
+
const bubbleState = assertEnum(
|
|
400
|
+
raw['bubbleState'],
|
|
401
|
+
CHAT_BUBBLE_STATES_V2,
|
|
402
|
+
`messages[${index}].bubbleState`,
|
|
403
|
+
);
|
|
404
|
+
const timestamp = raw['timestamp'];
|
|
405
|
+
if (typeof timestamp !== 'number' || !Number.isFinite(timestamp)) {
|
|
406
|
+
throw new ChatContractViolationError(
|
|
407
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
408
|
+
`messages[${index}].timestamp`,
|
|
409
|
+
'must be a finite number (ms since epoch)',
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
const orderingTimestamp = raw['orderingTimestamp'];
|
|
413
|
+
if (typeof orderingTimestamp !== 'number' || !Number.isFinite(orderingTimestamp)) {
|
|
414
|
+
throw new ChatContractViolationError(
|
|
415
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
416
|
+
`messages[${index}].orderingTimestamp`,
|
|
417
|
+
'must be a finite number (ms since epoch)',
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
const visibility = assertEnum(raw['visibility'], CHAT_VISIBILITIES_V2, `messages[${index}].visibility`);
|
|
421
|
+
const audience = assertEnum(raw['audience'], CHAT_AUDIENCES_V2, `messages[${index}].audience`);
|
|
422
|
+
const source = assertEnum(raw['source'], CHAT_SOURCES_V2, `messages[${index}].source`);
|
|
423
|
+
const senderName = typeof raw['senderName'] === 'string' ? (raw['senderName'] as string) : '';
|
|
424
|
+
const toolCalls = Array.isArray(raw['toolCalls']) ? (raw['toolCalls'] as ToolCallInfo[]) : [];
|
|
425
|
+
const meta = isPlainObject(raw['meta']) ? (raw['meta'] as Record<string, unknown>) : {};
|
|
426
|
+
|
|
427
|
+
return {
|
|
428
|
+
...identity,
|
|
429
|
+
role,
|
|
430
|
+
kind,
|
|
431
|
+
content,
|
|
432
|
+
bubbleState,
|
|
433
|
+
timestamp,
|
|
434
|
+
orderingTimestamp,
|
|
435
|
+
visibility,
|
|
436
|
+
audience,
|
|
437
|
+
source,
|
|
438
|
+
senderName,
|
|
439
|
+
toolCalls,
|
|
440
|
+
meta,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* Validate a v2 read_chat payload. Throws ChatContractViolationError on the
|
|
446
|
+
* first violation. v2 invariants beyond per-field checks:
|
|
447
|
+
* - messages[*].sequence strictly increasing
|
|
448
|
+
* - messages[*].orderingTimestamp monotonic non-decreasing
|
|
449
|
+
* - coverage union is well-formed
|
|
450
|
+
*/
|
|
451
|
+
export function assertReadChatResultV2Payload(raw: unknown): ReadChatResultV2 {
|
|
452
|
+
if (!isPlainObject(raw)) {
|
|
453
|
+
throw new ChatContractViolationError(
|
|
454
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
455
|
+
'$',
|
|
456
|
+
'must be an object',
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
if (raw['contractVersion'] !== CHAT_CONTRACT_VERSION_V2) {
|
|
460
|
+
throw new ChatContractViolationError(
|
|
461
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
462
|
+
'contractVersion',
|
|
463
|
+
`expected ${CHAT_CONTRACT_VERSION_V2}, got ${JSON.stringify(raw['contractVersion'])}`,
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
const workspace = raw['workspace'];
|
|
467
|
+
if (!isPlainObject(workspace) || typeof workspace['workspacePath'] !== 'string'
|
|
468
|
+
|| typeof workspace['intendedWorkspacePath'] !== 'string') {
|
|
469
|
+
throw new ChatContractViolationError(
|
|
470
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
471
|
+
'workspace',
|
|
472
|
+
'must have workspacePath and intendedWorkspacePath strings',
|
|
473
|
+
);
|
|
474
|
+
}
|
|
475
|
+
const session = raw['session'];
|
|
476
|
+
if (!isPlainObject(session) || typeof session['providerSessionId'] !== 'string') {
|
|
477
|
+
throw new ChatContractViolationError(
|
|
478
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
479
|
+
'session',
|
|
480
|
+
'must have providerSessionId string',
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
const coverage = assertCoverage(raw['coverage'], 'coverage');
|
|
484
|
+
const status = assertEnum(
|
|
485
|
+
raw['status'],
|
|
486
|
+
['idle', 'generating', 'waiting_approval', 'error', 'panel_hidden', 'streaming'] as const,
|
|
487
|
+
'status',
|
|
488
|
+
);
|
|
489
|
+
const turnStatus = assertEnum(
|
|
490
|
+
raw['turnStatus'],
|
|
491
|
+
['open', 'waiting_approval', 'complete', 'error'] as const,
|
|
492
|
+
'turnStatus',
|
|
493
|
+
);
|
|
494
|
+
const transcriptAuthority = assertEnum(
|
|
495
|
+
raw['transcriptAuthority'],
|
|
496
|
+
['provider', 'daemon'] as const,
|
|
497
|
+
'transcriptAuthority',
|
|
498
|
+
);
|
|
499
|
+
const currentTurnId = raw['currentTurnId'];
|
|
500
|
+
if (typeof currentTurnId !== 'string') {
|
|
501
|
+
throw new ChatContractViolationError(
|
|
502
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
503
|
+
'currentTurnId',
|
|
504
|
+
'must be a string',
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
if (!Array.isArray(raw['messages'])) {
|
|
508
|
+
throw new ChatContractViolationError(
|
|
509
|
+
CHAT_CONTRACT_VERSION_V2,
|
|
510
|
+
'messages',
|
|
511
|
+
'must be an array',
|
|
512
|
+
);
|
|
513
|
+
}
|
|
514
|
+
const messages = raw['messages'].map((m, i) => assertMessageV2(m, i));
|
|
515
|
+
assertSequenceMonotonic(messages, 'messages');
|
|
516
|
+
assertOrderingTimestampMonotonic(messages, 'messages');
|
|
517
|
+
|
|
518
|
+
const historySessionId = typeof session['historySessionId'] === 'string'
|
|
519
|
+
? (session['historySessionId'] as string)
|
|
520
|
+
: undefined;
|
|
521
|
+
|
|
522
|
+
return {
|
|
523
|
+
contractVersion: CHAT_CONTRACT_VERSION_V2,
|
|
524
|
+
workspace: {
|
|
525
|
+
workspacePath: workspace['workspacePath'] as string,
|
|
526
|
+
intendedWorkspacePath: workspace['intendedWorkspacePath'] as string,
|
|
527
|
+
},
|
|
528
|
+
session: historySessionId !== undefined
|
|
529
|
+
? { providerSessionId: session['providerSessionId'] as string, historySessionId }
|
|
530
|
+
: { providerSessionId: session['providerSessionId'] as string },
|
|
531
|
+
coverage,
|
|
532
|
+
status,
|
|
533
|
+
messages,
|
|
534
|
+
currentTurnId,
|
|
535
|
+
turnStatus,
|
|
536
|
+
transcriptAuthority,
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// ─── Contract version negotiation ────────────────────────────────────────
|
|
541
|
+
|
|
542
|
+
export function isSupportedChatContractVersion(value: unknown): value is ChatContractVersion {
|
|
543
|
+
return typeof value === 'string'
|
|
544
|
+
&& (SUPPORTED_CHAT_CONTRACT_VERSIONS as readonly string[]).includes(value);
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Read a provider's declared chat contract version from its parsed
|
|
549
|
+
* provider.json `canonicalHistory.contractVersion` field.
|
|
550
|
+
*
|
|
551
|
+
* - Absent or unrecognized → treated as v1 (legacy behaviour preserved during
|
|
552
|
+
* the A1 transition). A2 will tighten this to reject unsupported versions
|
|
553
|
+
* at provider load time.
|
|
554
|
+
* - Present and supported → returned as-is.
|
|
555
|
+
*
|
|
556
|
+
* The returned version drives which validator (assertReadChatResultV2Payload
|
|
557
|
+
* vs the legacy validateReadChatResultPayload) processes the provider's
|
|
558
|
+
* read_chat output.
|
|
559
|
+
*/
|
|
560
|
+
export function readDeclaredChatContractVersion(
|
|
561
|
+
canonicalHistory: unknown,
|
|
562
|
+
): ChatContractVersion {
|
|
563
|
+
if (!isPlainObject(canonicalHistory)) return CHAT_CONTRACT_VERSION_V1;
|
|
564
|
+
const declared = canonicalHistory['contractVersion'];
|
|
565
|
+
if (isSupportedChatContractVersion(declared)) return declared;
|
|
566
|
+
return CHAT_CONTRACT_VERSION_V1;
|
|
567
|
+
}
|