tmux-ide 2.8.0 → 2.9.0-beta.14
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/README.md +88 -125
- package/bin/cli.js +75949 -12803
- package/package.json +74 -37
- package/packages/contracts/package.json +9 -3
- package/packages/contracts/src/__tests__/actions-contract.test.ts +119 -0
- package/packages/contracts/src/__tests__/agent-graph-overlay.test.ts +428 -0
- package/packages/contracts/src/__tests__/app-window-mutation.test.ts +51 -0
- package/packages/contracts/src/__tests__/app-window-state.test.ts +34 -0
- package/packages/contracts/src/__tests__/application-shell.test.ts +635 -0
- package/packages/contracts/src/__tests__/causal-cell.test.ts +47 -0
- package/packages/contracts/src/__tests__/client-view-state.test.ts +115 -0
- package/packages/contracts/src/__tests__/cohesion-fixture.test.ts +106 -0
- package/packages/contracts/src/__tests__/commands.test.ts +86 -0
- package/packages/contracts/src/__tests__/daemon-events.test.ts +400 -0
- package/packages/contracts/src/__tests__/daemon-resources.test.ts +143 -0
- package/packages/contracts/src/__tests__/daemon-wire.test.ts +117 -0
- package/packages/contracts/src/__tests__/desktop-host.test.ts +269 -0
- package/packages/contracts/src/__tests__/desktop-missions.test.ts +211 -0
- package/packages/contracts/src/__tests__/experience-conformance.test.ts +153 -0
- package/packages/contracts/src/__tests__/experience-kernel-boundary.test.ts +109 -0
- package/packages/contracts/src/__tests__/experience-shell.test.ts +65 -0
- package/packages/contracts/src/__tests__/fixtures/daemon-wire-v2.json +35 -0
- package/packages/contracts/src/__tests__/fleet-agent-graph.test.ts +231 -0
- package/packages/contracts/src/__tests__/fleet-catalog.test.ts +268 -0
- package/packages/contracts/src/__tests__/fleet-lifecycle.test.ts +62 -0
- package/packages/contracts/src/__tests__/focus-overlay.test.ts +110 -0
- package/packages/contracts/src/__tests__/ide-config.test.ts +18 -0
- package/packages/contracts/src/__tests__/issue-error.test.ts +78 -0
- package/packages/contracts/src/__tests__/mission-projections.test.ts +186 -0
- package/packages/contracts/src/__tests__/missions.test.ts +272 -0
- package/packages/contracts/src/__tests__/multiplexer-verbs.test.ts +240 -0
- package/packages/contracts/src/__tests__/pane-appearance.test.ts +146 -0
- package/packages/contracts/src/__tests__/pane-stream.test.ts +488 -0
- package/packages/contracts/src/__tests__/pane-widget-marker.test.ts +327 -0
- package/packages/contracts/src/__tests__/performance-metrics.test.ts +73 -0
- package/packages/contracts/src/__tests__/performance-qualification.test.ts +137 -0
- package/packages/contracts/src/__tests__/rich-card-widget.test.ts +29 -0
- package/packages/contracts/src/__tests__/session-runtime.test.ts +504 -0
- package/packages/contracts/src/__tests__/startup-readiness.test.ts +409 -0
- package/packages/contracts/src/__tests__/terminal-attachment-stream.test.ts +72 -0
- package/packages/contracts/src/__tests__/terminal-attachments.test.ts +329 -0
- package/packages/contracts/src/__tests__/terminal-delivery.test.ts +88 -0
- package/packages/contracts/src/__tests__/terminal-runtime-inventory.test.ts +68 -0
- package/packages/contracts/src/__tests__/transport-contract-loading.test.ts +91 -0
- package/packages/contracts/src/__tests__/visual-tokens.test.ts +224 -0
- package/packages/contracts/src/__tests__/workspace-changes-resource.test.ts +317 -0
- package/packages/contracts/src/__tests__/workspace-changes-view.test.ts +122 -0
- package/packages/contracts/src/__tests__/workspace-config.test.ts +294 -0
- package/packages/contracts/src/__tests__/workspace-files-resource.test.ts +261 -0
- package/packages/contracts/src/__tests__/workspace-files-tree.test.ts +147 -0
- package/packages/contracts/src/__tests__/workspace-pane-creation.test.ts +249 -0
- package/packages/contracts/src/__tests__/workspace-promotion.test.ts +94 -0
- package/packages/contracts/src/__tests__/workspace-resource-identity.test.ts +90 -0
- package/packages/contracts/src/actions-contract.ts +205 -0
- package/packages/contracts/src/actions-errors.ts +20 -0
- package/packages/contracts/src/agent-graph-overlay.ts +425 -0
- package/packages/contracts/src/app-window-mutation.ts +101 -0
- package/packages/contracts/src/app-window-state.ts +446 -0
- package/packages/contracts/src/application-shell-resource.ts +54 -0
- package/packages/contracts/src/application-shell.ts +1094 -0
- package/packages/contracts/src/causal-cell.ts +168 -0
- package/packages/contracts/src/client-view-state.ts +156 -0
- package/packages/contracts/src/cohesion-fixture.ts +647 -0
- package/packages/contracts/src/commands.ts +153 -0
- package/packages/contracts/src/daemon-events.ts +374 -0
- package/packages/contracts/src/daemon-resource-request.test.ts +192 -0
- package/packages/contracts/src/daemon-resource-request.ts +397 -0
- package/packages/contracts/src/daemon-resources.ts +108 -0
- package/packages/contracts/src/daemon-wire.ts +100 -0
- package/packages/contracts/src/desktop-daemon-capability-error.ts +31 -0
- package/packages/contracts/src/desktop-daemon-issue.ts +83 -0
- package/packages/contracts/src/desktop-host.ts +728 -0
- package/packages/contracts/src/desktop-missions.ts +159 -0
- package/packages/contracts/src/desktop-update.ts +48 -0
- package/packages/contracts/src/desktop-workspace-name.ts +18 -0
- package/packages/contracts/src/domain.ts +493 -0
- package/packages/contracts/src/experience-identifiers.ts +53 -0
- package/packages/contracts/src/experience-shell.ts +249 -0
- package/packages/contracts/src/fleet-agent-graph.ts +171 -0
- package/packages/contracts/src/fleet-catalog.ts +190 -0
- package/packages/contracts/src/fleet-lifecycle.ts +136 -0
- package/packages/contracts/src/focus-overlay.ts +175 -0
- package/packages/contracts/src/ide-config.ts +40 -20
- package/packages/contracts/src/index.ts +70 -0
- package/packages/contracts/src/interaction-receipts.ts +438 -0
- package/packages/contracts/src/issue-error.ts +107 -0
- package/packages/contracts/src/mission-projections.ts +269 -0
- package/packages/contracts/src/multiplexer-verbs.ts +447 -0
- package/packages/contracts/src/pane-appearance.ts +248 -0
- package/packages/contracts/src/pane-stream.ts +711 -0
- package/packages/contracts/src/pane-widget-descriptor.ts +62 -0
- package/packages/contracts/src/pane-widget-marker.ts +301 -0
- package/packages/contracts/src/performance-metrics.ts +128 -0
- package/packages/contracts/src/performance-qualification.ts +276 -0
- package/packages/contracts/src/rich-card-widget.ts +72 -0
- package/packages/contracts/src/saved-machines.ts +50 -0
- package/packages/contracts/src/semantic-identity.ts +39 -0
- package/packages/contracts/src/session-runtime.ts +364 -0
- package/packages/contracts/src/shared-monotonic-clock.ts +18 -0
- package/packages/contracts/src/startup-readiness.ts +432 -0
- package/packages/contracts/src/terminal-attachment-stream.ts +119 -0
- package/packages/contracts/src/terminal-attachments.ts +347 -0
- package/packages/contracts/src/terminal-delivery.ts +245 -0
- package/packages/contracts/src/terminal-replica.ts +133 -0
- package/packages/contracts/src/terminal-runtime-inventory.ts +42 -0
- package/packages/contracts/src/visual-recipes.ts +126 -0
- package/packages/contracts/src/visual-theme-presets.ts +499 -0
- package/packages/contracts/src/visual-tokens.ts +883 -0
- package/packages/contracts/src/widget-asset.ts +43 -0
- package/packages/contracts/src/workspace-catalog-resource.test.ts +146 -0
- package/packages/contracts/src/workspace-catalog-resource.ts +180 -0
- package/packages/contracts/src/workspace-changes-resource.ts +405 -0
- package/packages/contracts/src/workspace-changes-view.ts +195 -0
- package/packages/contracts/src/workspace-config.ts +303 -0
- package/packages/contracts/src/workspace-files-resource.ts +310 -0
- package/packages/contracts/src/workspace-files-tree.ts +167 -0
- package/packages/contracts/src/workspace-missions-resource.ts +32 -0
- package/packages/contracts/src/workspace-multiplexer.ts +373 -0
- package/packages/contracts/src/workspace-open-handoff.ts +99 -0
- package/packages/contracts/src/workspace-open.ts +62 -0
- package/packages/contracts/src/workspace-pane-creation.ts +221 -0
- package/packages/contracts/src/workspace-promotion.ts +107 -0
- package/packages/contracts/src/workspace-resource-identity.ts +81 -0
- package/packages/contracts/src/workspace-state.ts +530 -0
- package/packages/contracts/src/workspace.ts +14 -2
- package/packages/core/package.json +35 -0
- package/packages/core/src/agent-provisioning.test.ts +42 -0
- package/packages/core/src/agent-provisioning.ts +112 -0
- package/packages/core/src/app-window-identity.ts +33 -0
- package/packages/core/src/application-shell-session.test.ts +105 -0
- package/packages/core/src/application-shell-session.ts +195 -0
- package/packages/core/src/index.ts +17 -0
- package/packages/core/src/interaction-flow.test.ts +66 -0
- package/packages/core/src/interaction-flow.ts +159 -0
- package/packages/core/src/interaction-receipts.test.ts +361 -0
- package/packages/core/src/interaction-receipts.ts +336 -0
- package/packages/core/src/navigator.test.ts +34 -0
- package/packages/core/src/navigator.ts +74 -0
- package/packages/core/src/optimistic-projection-conformance.test.ts +75 -0
- package/packages/core/src/optimistic-projection-conformance.ts +61 -0
- package/packages/core/src/optimistic-projection-store.ts +71 -0
- package/packages/core/src/optimistic-projection.test.ts +118 -0
- package/packages/core/src/optimistic-projection.ts +194 -0
- package/packages/core/src/performance-metrics.test.ts +121 -0
- package/packages/core/src/performance-metrics.ts +241 -0
- package/packages/core/src/performance-qualification.test.ts +283 -0
- package/packages/core/src/performance-qualification.ts +360 -0
- package/packages/core/src/saved-machines.test.ts +80 -0
- package/packages/core/src/saved-machines.ts +53 -0
- package/packages/core/src/terminal-compact-capability.ts +31 -0
- package/packages/core/src/terminal-compact-cold.test.ts +87 -0
- package/packages/core/src/terminal-conformance.test.ts +48 -0
- package/packages/core/src/terminal-conformance.ts +405 -0
- package/packages/core/src/terminal-delivery-cache-lifetime.test.ts +167 -0
- package/packages/core/src/terminal-delivery-encode-cooperative.test.ts +140 -0
- package/packages/core/src/terminal-delivery.test.ts +1471 -0
- package/packages/core/src/terminal-delivery.ts +3154 -0
- package/packages/core/src/terminal-fnv64-wasm-bytes.ts +20 -0
- package/packages/core/src/terminal-fnv64-wasm.test.ts +61 -0
- package/packages/core/src/terminal-fnv64-wasm.ts +110 -0
- package/packages/core/src/terminal-replica-cold.test.ts +31 -0
- package/packages/core/src/terminal-replica-cooperative.test.ts +170 -0
- package/packages/core/src/terminal-replica-hash-cache.test.ts +283 -0
- package/packages/core/src/terminal-replica-hash-cache.ts +399 -0
- package/packages/core/src/terminal-replica.test.ts +347 -0
- package/packages/core/src/terminal-replica.ts +1149 -0
- package/packages/core/src/workspace-selection.test.ts +63 -0
- package/packages/core/src/workspace-selection.ts +97 -0
- package/packages/daemon/dist/attach.js +2 -2
- package/packages/daemon/dist/canonical.js +1 -1
- package/packages/daemon/dist/cli.js +38 -37
- package/packages/daemon/dist/command-center/actions/command-definitions.js +70 -0
- package/packages/daemon/dist/command-center/actions/dispatcher.js +228 -10
- package/packages/daemon/dist/command-center/actions/handlers/_project-context.js +3 -4
- package/packages/daemon/dist/command-center/actions/handlers/app-set-remote-access.js +6 -2
- package/packages/daemon/dist/command-center/actions/handlers/app-window-mutate.js +39 -0
- package/packages/daemon/dist/command-center/actions/handlers/config-actions.js +44 -20
- package/packages/daemon/dist/command-center/actions/handlers/daemon-shutdown.js +11 -1
- package/packages/daemon/dist/command-center/actions/handlers/fleet-lifecycle.js +56 -0
- package/packages/daemon/dist/command-center/actions/handlers/project-launch.js +16 -4
- package/packages/daemon/dist/command-center/actions/handlers/workspace-multiplexer.js +55 -0
- package/packages/daemon/dist/command-center/actions/handlers/workspace-open.js +89 -0
- package/packages/daemon/dist/command-center/actions/handlers/workspace-pane-create.js +34 -0
- package/packages/daemon/dist/command-center/actions/handlers/workspace-promote.js +34 -0
- package/packages/daemon/dist/command-center/actions/registry.js +126 -0
- package/packages/daemon/dist/command-center/actions/semantic-multiplexer-actions.js +16 -0
- package/packages/daemon/dist/command-center/agent-status-watch.js +170 -0
- package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +395 -0
- package/packages/daemon/dist/command-center/discovery.js +262 -3
- package/packages/daemon/dist/command-center/owner-authority.js +46 -0
- package/packages/daemon/dist/command-center/pane-stream-issue.js +185 -0
- package/packages/daemon/dist/command-center/resources/agent-graph-overlay.js +234 -0
- package/packages/daemon/dist/command-center/resources/application-shell.js +641 -0
- package/packages/daemon/dist/command-center/resources/desktop-missions.js +132 -0
- package/packages/daemon/dist/command-center/resources/fleet-catalog.js +163 -0
- package/packages/daemon/dist/command-center/resources/fleet-resource-route.js +48 -0
- package/packages/daemon/dist/command-center/resources/startup-readiness-route.js +121 -0
- package/packages/daemon/dist/command-center/resources/startup-readiness.js +183 -0
- package/packages/daemon/dist/command-center/resources/terminal-native-backing-route.js +92 -0
- package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +24 -0
- package/packages/daemon/dist/command-center/resources/workspace-changes-authority.js +451 -0
- package/packages/daemon/dist/command-center/resources/workspace-changes-git.js +222 -0
- package/packages/daemon/dist/command-center/resources/workspace-files-authority.js +493 -0
- package/packages/daemon/dist/command-center/resources/workspace-missions-route.js +75 -0
- package/packages/daemon/dist/command-center/resources/workspace-resource-ids.js +69 -0
- package/packages/daemon/dist/command-center/resources/workspace-resource-routes.js +116 -0
- package/packages/daemon/dist/command-center/server.js +540 -51
- package/packages/daemon/dist/command-center/terminal-attachment-issue.js +191 -0
- package/packages/daemon/dist/command-center/workspace-resource-observer.js +453 -0
- package/packages/daemon/dist/command-center/ws-events.js +681 -63
- package/packages/daemon/dist/config.js +31 -25
- package/packages/daemon/dist/control/lifecycle.js +12 -2
- package/packages/daemon/dist/control/server.js +3 -3
- package/packages/daemon/dist/detect.js +23 -20
- package/packages/daemon/dist/doctor.js +25 -8
- package/packages/daemon/dist/index.js +20 -1
- package/packages/daemon/dist/init.js +24 -22
- package/packages/daemon/dist/inspect.js +33 -8
- package/packages/daemon/dist/launch.js +38 -26
- package/packages/daemon/dist/lib/__tests__/fixtures/workspace-state-writer.js +58 -0
- package/packages/daemon/dist/lib/agent-kind.js +24 -0
- package/packages/daemon/dist/lib/app-config.js +29 -1
- package/packages/daemon/dist/lib/app-window-kernel.js +556 -0
- package/packages/daemon/dist/lib/app-window-mutation.js +139 -0
- package/packages/daemon/dist/lib/app-window-repository.js +368 -0
- package/packages/daemon/dist/lib/app-window-state.js +415 -0
- package/packages/daemon/dist/lib/application-shell-app-windows.js +285 -0
- package/packages/daemon/dist/lib/auth/middleware.js +7 -3
- package/packages/daemon/dist/lib/bundled-tmux.js +93 -0
- package/packages/daemon/dist/lib/canonical-daemon-bootstrap.js +276 -0
- package/packages/daemon/dist/lib/canonical-daemon.js +507 -70
- package/packages/daemon/dist/lib/chrome-front-door.js +13 -0
- package/packages/daemon/dist/lib/cli-action-bridge.js +112 -82
- package/packages/daemon/dist/lib/command-registry.js +107 -0
- package/packages/daemon/dist/lib/config-context.js +34 -0
- package/packages/daemon/dist/lib/daemon-embed.js +1072 -363
- package/packages/daemon/dist/lib/daemon-session-monitor.js +194 -0
- package/packages/daemon/dist/lib/daemon.js +3 -47
- package/packages/daemon/dist/lib/directory-watcher.js +118 -0
- package/packages/daemon/dist/lib/embedded-daemon-lifecycle.js +102 -0
- package/packages/daemon/dist/lib/environment-identity.js +79 -0
- package/packages/daemon/dist/lib/fleet-agent-lifecycle.js +65 -0
- package/packages/daemon/dist/lib/fleet-lifecycle-authority.js +437 -0
- package/packages/daemon/dist/lib/headless-daemon.js +353 -0
- package/packages/daemon/dist/lib/launch-plan.js +96 -1
- package/packages/daemon/dist/lib/legacy-config-adapter.js +19 -0
- package/packages/daemon/dist/lib/legacy-config-migration.js +110 -0
- package/packages/daemon/dist/lib/legacy-theme-compat.js +25 -0
- package/packages/daemon/dist/lib/mission-projections.js +615 -0
- package/packages/daemon/dist/lib/mission-repository.js +775 -0
- package/packages/daemon/dist/lib/onboarding-marker.js +51 -0
- package/packages/daemon/dist/lib/pane-chrome.js +12 -0
- package/packages/daemon/dist/lib/pane-source-credentials.js +178 -0
- package/packages/daemon/dist/lib/pane-widget.js +126 -0
- package/packages/daemon/dist/lib/project-inspect.js +4 -0
- package/packages/daemon/dist/lib/project-onboard.js +17 -21
- package/packages/daemon/dist/lib/project-probe.js +28 -22
- package/packages/daemon/dist/lib/project-readiness-probe.js +425 -0
- package/packages/daemon/dist/lib/project-readiness.js +680 -0
- package/packages/daemon/dist/lib/project-registry.js +42 -9
- package/packages/daemon/dist/lib/project-resolver.js +245 -0
- package/packages/daemon/dist/lib/project-runtime-errors.js +21 -0
- package/packages/daemon/dist/lib/project-runtime-repository.js +876 -0
- package/packages/daemon/dist/lib/remote-daemon-info.js +21 -0
- package/packages/daemon/dist/lib/resolved-config.js +318 -0
- package/packages/daemon/dist/lib/runtime-namespace.js +136 -0
- package/packages/daemon/dist/lib/saved-machines.js +53 -0
- package/packages/daemon/dist/lib/semantic-resource-id.js +14 -0
- package/packages/daemon/dist/lib/session-monitor.js +29 -23
- package/packages/daemon/dist/lib/session-options.js +3 -10
- package/packages/daemon/dist/lib/ssh-daemon-transport.js +280 -0
- package/packages/daemon/dist/lib/state-home.js +2 -3
- package/packages/daemon/dist/lib/theme-mode.js +9 -0
- package/packages/daemon/dist/lib/tmux-authority-replacement.js +102 -0
- package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +534 -0
- package/packages/daemon/dist/lib/tmux-interaction-options.js +126 -0
- package/packages/daemon/dist/lib/tmux-named-socket-fence.js +61 -0
- package/packages/daemon/dist/lib/tmux-terminal-color.js +37 -0
- package/packages/daemon/dist/lib/tui-binary.js +291 -28
- package/packages/daemon/dist/lib/unix-socket-authority.js +48 -0
- package/packages/daemon/dist/lib/widget-asset-policy.js +3 -0
- package/packages/daemon/dist/lib/widget-asset-store.js +166 -0
- package/packages/daemon/dist/lib/workspace-config-loader.js +280 -0
- package/packages/daemon/dist/lib/workspace-multiplexer-verbs.js +1138 -0
- package/packages/daemon/dist/lib/workspace-open-handoff.js +219 -0
- package/packages/daemon/dist/lib/workspace-open.js +740 -0
- package/packages/daemon/dist/lib/workspace-pane-creation.js +1137 -0
- package/packages/daemon/dist/lib/workspace-promotion.js +809 -0
- package/packages/daemon/dist/lib/workspace-registry.js +150 -23
- package/packages/daemon/dist/lib/workspace-state-repository.js +790 -0
- package/packages/daemon/dist/lib/workspace-state.js +765 -0
- package/packages/daemon/dist/lib/yaml-io.js +4 -18
- package/packages/daemon/dist/migrate.js +105 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/COPYING +13 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/lib/libevent_core-2.1.7.dylib +0 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/lib/libncursesw.6.dylib +0 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/lib/libutf8proc.3.2.3.dylib +0 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/licenses/libevent_core-2.1.7.dylib.txt +99 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/licenses/libncursesw.6.dylib.txt +29 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/licenses/libutf8proc.3.2.3.dylib.txt +93 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/manifest.json +21 -0
- package/packages/daemon/dist/native/tmux/darwin-arm64/tmux +0 -0
- package/packages/daemon/dist/restart.js +2 -2
- package/packages/daemon/dist/restore.js +10 -6
- package/packages/daemon/dist/schemas/inspect.js +9 -1
- package/packages/daemon/dist/schemas/registry.js +5 -19
- package/packages/daemon/dist/schemas/ws-events.js +4 -107
- package/packages/daemon/dist/send.js +106 -3
- package/packages/daemon/dist/server/index.js +4 -2
- package/packages/daemon/dist/server/pane-stream-upgrade.js +117 -0
- package/packages/daemon/dist/server/terminal-attachment-upgrade.js +121 -0
- package/packages/daemon/dist/status.js +11 -8
- package/packages/daemon/dist/stop.js +2 -2
- package/packages/daemon/dist/terminal/MonotonicPtyInput.js +130 -0
- package/packages/daemon/dist/terminal/NodePtyAdapter.js +37 -10
- package/packages/daemon/dist/terminal/PtyAdapter.js +18 -0
- package/packages/daemon/dist/terminal/__tests__/MockPtyAdapter.js +33 -6
- package/packages/daemon/dist/terminal/attachments/admission-util.js +87 -0
- package/packages/daemon/dist/terminal/attachments/agent-status-probe.js +325 -0
- package/packages/daemon/dist/terminal/attachments/direct-websocket.js +1069 -0
- package/packages/daemon/dist/terminal/attachments/grouped-tmux.js +213 -0
- package/packages/daemon/dist/terminal/attachments/lease-manager.js +655 -0
- package/packages/daemon/dist/terminal/attachments/native-runtime.js +1597 -0
- package/packages/daemon/dist/terminal/attachments/pty-tmux-attachment-launcher.js +607 -0
- package/packages/daemon/dist/terminal/attachments/semantic-pane-catalog.js +208 -0
- package/packages/daemon/dist/terminal/attachments/tmux-view-executor.js +825 -0
- package/packages/daemon/dist/terminal/mirror/__tests__/scripted-channel.js +90 -0
- package/packages/daemon/dist/terminal/mirror/__tests__/simulated-channel.js +147 -0
- package/packages/daemon/dist/terminal/mirror/control-channel.js +768 -0
- package/packages/daemon/dist/terminal/mirror/control-mode-ownership.js +30 -0
- package/packages/daemon/dist/terminal/mirror/flow-ledger.js +56 -0
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +338 -0
- package/packages/daemon/dist/terminal/mirror/native-frozen-grid.js +128 -0
- package/packages/daemon/dist/terminal/mirror/native-grid-capture.js +179 -0
- package/packages/daemon/dist/terminal/mirror/native-grid-projection.js +99 -0
- package/packages/daemon/dist/terminal/mirror/native-grid-reader.js +81 -0
- package/packages/daemon/dist/terminal/mirror/native-grid-reflow.js +207 -0
- package/packages/daemon/dist/terminal/mirror/pane-feed.js +209 -0
- package/packages/daemon/dist/terminal/mirror/session-channel.js +2774 -0
- package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +245 -0
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +2067 -0
- package/packages/daemon/dist/terminal/pane-stream/runtime.js +53 -0
- package/packages/daemon/dist/terminal/pane-stream/wire-ledger.js +110 -0
- package/packages/daemon/dist/terminal/protocol/chunk-bytes.js +21 -0
- package/packages/daemon/dist/terminal/protocol/control.js +111 -0
- package/packages/daemon/dist/terminal/protocol/input-coalescer.js +125 -0
- package/packages/daemon/dist/terminal/protocol/layout-parse.js +127 -0
- package/packages/daemon/dist/terminal/protocol/native-backing-client.js +44 -0
- package/packages/daemon/dist/terminal/protocol/pane-display-name.js +155 -0
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +294 -0
- package/packages/daemon/dist/terminal/protocol/workspace-tmux-adapter.js +213 -0
- package/packages/daemon/dist/terminal/session-runtime/authority-arbiter.js +266 -0
- package/packages/daemon/dist/terminal/session-runtime/causal-cell-ledger.js +278 -0
- package/packages/daemon/dist/terminal/session-runtime/interaction-receipt-facts.js +147 -0
- package/packages/daemon/dist/terminal/session-runtime/multiplexer-backend.js +116 -0
- package/packages/daemon/dist/terminal/session-runtime/native-seed-backing.js +41 -0
- package/packages/daemon/dist/terminal/session-runtime/registry.js +1390 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-observability.js +72 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-scheduler.js +16 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-trace-correlator.js +48 -0
- package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-executor.js +353 -0
- package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-resource-changes.js +32 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +1770 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-observation-identity.js +9 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +582 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +568 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-shadow-projections.js +21 -0
- package/packages/daemon/dist/terminal/session-runtime/transport-binding.js +474 -0
- package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +515 -0
- package/packages/daemon/dist/tui/async-disposable-slot.js +57 -0
- package/packages/daemon/dist/tui/chrome/cheatsheet.js +211 -0
- package/packages/daemon/dist/tui/chrome/chip.js +25 -0
- package/packages/daemon/dist/tui/chrome/events.js +94 -0
- package/packages/daemon/dist/tui/chrome/front-door.js +16 -0
- package/packages/daemon/dist/tui/chrome/kitty-keys.js +54 -0
- package/packages/daemon/dist/tui/chrome/menu.js +251 -0
- package/packages/daemon/dist/tui/chrome/notify-prefs.js +13 -0
- package/packages/daemon/dist/tui/chrome/notify-state.js +77 -0
- package/packages/daemon/dist/tui/chrome/notify.js +711 -0
- package/packages/daemon/dist/tui/chrome/panels.js +60 -0
- package/packages/daemon/dist/tui/chrome/sidebar.js +183 -0
- package/packages/daemon/dist/tui/chrome/snapshot.js +290 -0
- package/packages/daemon/dist/tui/chrome/statusline.js +552 -0
- package/packages/daemon/dist/tui/chrome/updater.js +651 -0
- package/packages/daemon/dist/tui/chrome/welcome.js +117 -0
- package/packages/daemon/dist/tui/compiled.js +194 -0
- package/packages/daemon/dist/tui/detect/agent-resolution.js +60 -0
- package/packages/daemon/dist/tui/detect/classify.js +184 -0
- package/packages/daemon/dist/tui/detect/manifest-loader.js +242 -0
- package/packages/daemon/dist/tui/detect/manifest.js +126 -0
- package/packages/daemon/dist/tui/detect/manifests.js +535 -0
- package/packages/daemon/dist/tui/detect/process-tree.js +194 -0
- package/packages/daemon/dist/tui/detect/session-id.js +414 -0
- package/packages/daemon/dist/tui/detect/snapshot.js +81 -0
- package/packages/daemon/dist/tui/integrations/claude.js +151 -0
- package/packages/daemon/dist/tui/integrations/offer.js +134 -0
- package/packages/daemon/dist/tui/integrations/opencode.js +117 -0
- package/packages/daemon/dist/tui/mirror/ack-writer.js +78 -0
- package/packages/daemon/dist/tui/mirror/activity-surface-view.jsx +69 -0
- package/packages/daemon/dist/tui/mirror/activity-surface.js +271 -0
- package/packages/daemon/dist/tui/mirror/agent-chip.js +84 -0
- package/packages/daemon/dist/tui/mirror/agent-lifecycle.js +372 -0
- package/packages/daemon/dist/tui/mirror/agent-provisioning-executor.js +111 -0
- package/packages/daemon/dist/tui/mirror/agent-rows.js +126 -0
- package/packages/daemon/dist/tui/mirror/ansi-palette.js +3 -0
- package/packages/daemon/dist/tui/mirror/app-state.js +294 -0
- package/packages/daemon/dist/tui/mirror/application-keybindings.js +33 -0
- package/packages/daemon/dist/tui/mirror/application-shell-daemon-connection.js +270 -0
- package/packages/daemon/dist/tui/mirror/application-shell-daemon-session.js +45 -0
- package/packages/daemon/dist/tui/mirror/attention.js +59 -0
- package/packages/daemon/dist/tui/mirror/blit.js +120 -0
- package/packages/daemon/dist/tui/mirror/canonical-workspace-routing.js +54 -0
- package/packages/daemon/dist/tui/mirror/changes-surface-view.jsx +92 -0
- package/packages/daemon/dist/tui/mirror/changes-surface.js +210 -0
- package/packages/daemon/dist/tui/mirror/composite-layout.js +539 -0
- package/packages/daemon/dist/tui/mirror/configless-session-bootstrap.js +134 -0
- package/packages/daemon/dist/tui/mirror/dialog-model.js +183 -0
- package/packages/daemon/dist/tui/mirror/dialog-stack-core.js +232 -0
- package/packages/daemon/dist/tui/mirror/dialog-stack.js +2 -0
- package/packages/daemon/dist/tui/mirror/diff-model.js +332 -0
- package/packages/daemon/dist/tui/mirror/editor-buffer.js +47 -0
- package/packages/daemon/dist/tui/mirror/editor-open-policy.js +9 -0
- package/packages/daemon/dist/tui/mirror/features/changes/controller.js +454 -0
- package/packages/daemon/dist/tui/mirror/features/changes/feature.jsx +9 -0
- package/packages/daemon/dist/tui/mirror/features/dialogs/feature.jsx +123 -0
- package/packages/daemon/dist/tui/mirror/features/dialogs/session.js +160 -0
- package/packages/daemon/dist/tui/mirror/features/files/feature.jsx +15 -0
- package/packages/daemon/dist/tui/mirror/features/files/session.js +617 -0
- package/packages/daemon/dist/tui/mirror/features/home/feature.jsx +122 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/contract.js +3 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/feature.jsx +5 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/session.js +377 -0
- package/packages/daemon/dist/tui/mirror/features/palette/buffer-geometry.js +36 -0
- package/packages/daemon/dist/tui/mirror/features/palette/contract.js +9 -0
- package/packages/daemon/dist/tui/mirror/features/palette/feature.js +3 -0
- package/packages/daemon/dist/tui/mirror/features/palette/session.js +394 -0
- package/packages/daemon/dist/tui/mirror/features/palette/surface.jsx +50 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/contract.js +1 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/feature.jsx +2 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/session.js +148 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/surface.jsx +64 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/asset-loader.js +125 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/contract.js +1 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/feature.jsx +103 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/session.js +310 -0
- package/packages/daemon/dist/tui/mirror/features/settings/catalog.js +10 -0
- package/packages/daemon/dist/tui/mirror/features/settings/contract.js +1 -0
- package/packages/daemon/dist/tui/mirror/features/settings/feature.js +2 -0
- package/packages/daemon/dist/tui/mirror/features/settings/session.js +309 -0
- package/packages/daemon/dist/tui/mirror/file-tree.js +283 -0
- package/packages/daemon/dist/tui/mirror/files-surface-view.jsx +92 -0
- package/packages/daemon/dist/tui/mirror/files-surface.js +237 -0
- package/packages/daemon/dist/tui/mirror/focus-projection.js +80 -0
- package/packages/daemon/dist/tui/mirror/folder-picker.js +114 -0
- package/packages/daemon/dist/tui/mirror/frame-coalescer.js +74 -0
- package/packages/daemon/dist/tui/mirror/home-model.js +125 -0
- package/packages/daemon/dist/tui/mirror/home-surface-model.js +297 -0
- package/packages/daemon/dist/tui/mirror/home-surface.jsx +110 -0
- package/packages/daemon/dist/tui/mirror/hosted.js +239 -0
- package/packages/daemon/dist/tui/mirror/input-lifecycle.js +147 -0
- package/packages/daemon/dist/tui/mirror/interaction-flow.js +41 -0
- package/packages/daemon/dist/tui/mirror/legacy/missions-workspace-loader.js +84 -0
- package/packages/daemon/dist/tui/mirror/menu-model.js +143 -0
- package/packages/daemon/dist/tui/mirror/missions-dashboard.js +261 -0
- package/packages/daemon/dist/tui/mirror/missions-render-fixtures.js +330 -0
- package/packages/daemon/dist/tui/mirror/missions-surface-controller.js +314 -0
- package/packages/daemon/dist/tui/mirror/missions-surface.jsx +239 -0
- package/packages/daemon/dist/tui/mirror/missions-workspace.js +1399 -0
- package/packages/daemon/dist/tui/mirror/multiplexer-action-executor.js +252 -0
- package/packages/daemon/dist/tui/mirror/open-tui-pane-stream-socket.js +32 -0
- package/packages/daemon/dist/tui/mirror/open-tui-verified-routing.js +95 -0
- package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +1182 -0
- package/packages/daemon/dist/tui/mirror/palette-surface-adapter.js +384 -0
- package/packages/daemon/dist/tui/mirror/palette.js +522 -0
- package/packages/daemon/dist/tui/mirror/pane-frame-state.js +124 -0
- package/packages/daemon/dist/tui/mirror/pane-mirror.js +1 -0
- package/packages/daemon/dist/tui/mirror/pane-surface.jsx +950 -0
- package/packages/daemon/dist/tui/mirror/panel-host-reactive.js +13 -0
- package/packages/daemon/dist/tui/mirror/panel-host.js +242 -0
- package/packages/daemon/dist/tui/mirror/perf-tap.js +32 -0
- package/packages/daemon/dist/tui/mirror/performance-events.js +46 -0
- package/packages/daemon/dist/tui/mirror/recipe-components.jsx +135 -0
- package/packages/daemon/dist/tui/mirror/recipes.js +395 -0
- package/packages/daemon/dist/tui/mirror/reference-performance-trace.js +598 -0
- package/packages/daemon/dist/tui/mirror/renderer-commands.js +250 -0
- package/packages/daemon/dist/tui/mirror/resize-model.js +105 -0
- package/packages/daemon/dist/tui/mirror/resize-transaction.js +221 -0
- package/packages/daemon/dist/tui/mirror/rich-placement-projection.js +80 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-appearance-owner.js +176 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-bootstrap.js +51 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-daemon-authority-owner.js +235 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-daemon-authority.js +8 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-generation-starter.js +90 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-navigation.js +86 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-observer.js +301 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-roster.jsx +170 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-selection.js +83 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agent-transport.js +199 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agents-owner.js +221 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-agents.js +30 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog-owner.js +104 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog.js +329 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-binding.js +111 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-capability.js +25 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-presentation.js +129 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-test-control.js +242 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-input-readiness.js +20 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-lifecycle.js +297 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-agent-navigation.js +61 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-agents.js +158 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-authority.js +289 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-catalog.js +223 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-navigation.js +164 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-sidebar.jsx +215 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-machine-startup.js +35 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-optional-features.js +12 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.js +132 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-palette-input.js +69 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-palette-search-owner.js +67 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pane-activity-owner.js +61 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pane-menu-owner.js +82 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-input.js +41 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-owner.js +46 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pending-terminal-input.js +74 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-performance-log.js +126 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-post-render-runtime.js +117 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-root-configuration.js +21 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-root-renderer.js +160 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-session-focus-owner.js +65 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-shell-binding.js +313 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-shell-home.jsx +113 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-shell-viewport.js +14 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-frame-readiness-owner.js +20 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-host-focus-owner.js +25 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-input-ingress.js +102 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +1360 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-palette-owner.js +217 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-paste.js +22 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-renderer-sources.js +31 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-selection-owner.js +217 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace-policy.js +193 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace.jsx +1286 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-theme-repaint.js +34 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-transient-note-owner.js +29 -0
- package/packages/daemon/dist/tui/mirror/runtime/bounded-performance-record-writer.js +67 -0
- package/packages/daemon/dist/tui/mirror/runtime/causal-cell-client-ledger.js +281 -0
- package/packages/daemon/dist/tui/mirror/runtime/causal-cell-input-fixture.js +43 -0
- package/packages/daemon/dist/tui/mirror/runtime/changes-deferred-identity.js +17 -0
- package/packages/daemon/dist/tui/mirror/runtime/daemon-authority-rebind.js +128 -0
- package/packages/daemon/dist/tui/mirror/runtime/deferred-intent-queue.js +40 -0
- package/packages/daemon/dist/tui/mirror/runtime/editor-primitives.js +39 -0
- package/packages/daemon/dist/tui/mirror/runtime/file-content-primitives.js +9 -0
- package/packages/daemon/dist/tui/mirror/runtime/fleet-lifecycle-client.js +30 -0
- package/packages/daemon/dist/tui/mirror/runtime/focus-framebuffer-projection.js +53 -0
- package/packages/daemon/dist/tui/mirror/runtime/generation-bound-slot.js +23 -0
- package/packages/daemon/dist/tui/mirror/runtime/host-local-tmux-adapter.js +203 -0
- package/packages/daemon/dist/tui/mirror/runtime/hosted-tty-size-bridge.js +166 -0
- package/packages/daemon/dist/tui/mirror/runtime/latest-intent-fence.js +14 -0
- package/packages/daemon/dist/tui/mirror/runtime/local-view-controller.js +58 -0
- package/packages/daemon/dist/tui/mirror/runtime/modal-admission-coordinator.js +118 -0
- package/packages/daemon/dist/tui/mirror/runtime/modal-pointer-capture.js +12 -0
- package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +833 -0
- package/packages/daemon/dist/tui/mirror/runtime/open-tui-session-owner.js +178 -0
- package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.js +178 -0
- package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.typecheck.js +1 -0
- package/packages/daemon/dist/tui/mirror/runtime/palette-production-controller.js +126 -0
- package/packages/daemon/dist/tui/mirror/runtime/pane-resize-geometry.js +17 -0
- package/packages/daemon/dist/tui/mirror/runtime/pane-scoped-terminal-surface.jsx +67 -0
- package/packages/daemon/dist/tui/mirror/runtime/product-surface-policy.js +12 -0
- package/packages/daemon/dist/tui/mirror/runtime/renderer-cadence.js +7 -0
- package/packages/daemon/dist/tui/mirror/runtime/renderer-frame-optimizer.js +88 -0
- package/packages/daemon/dist/tui/mirror/runtime/renderer-output-transport.js +56 -0
- package/packages/daemon/dist/tui/mirror/runtime/resize-terminal-pane.js +91 -0
- package/packages/daemon/dist/tui/mirror/runtime/rich-preview-demand.js +14 -0
- package/packages/daemon/dist/tui/mirror/runtime/runtime-layout-presentation.js +111 -0
- package/packages/daemon/dist/tui/mirror/runtime/select-terminal-pane.js +90 -0
- package/packages/daemon/dist/tui/mirror/runtime/semantic-pane-publication.js +14 -0
- package/packages/daemon/dist/tui/mirror/runtime/semantic-shell-viewport-resize.js +56 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-copy-cursor.js +122 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-copy-selection.js +65 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-dimensions-owner.js +9 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-fast-lane-renderer-adapter.js +911 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-frame-readiness.js +84 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-host-focus.js +347 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-host-frame-diagnostics.js +37 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-input-adapter.js +50 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-layout-projection.js +105 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-link-opener.js +23 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-links.js +81 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-pane-input-router.js +83 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-row-projection-cache.js +88 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-selection-units.js +123 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-selection.js +202 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-session-handoff.js +89 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-tool-readiness.js +64 -0
- package/packages/daemon/dist/tui/mirror/runtime/tool-resource-controller.js +636 -0
- package/packages/daemon/dist/tui/mirror/runtime/tool-resource-projection.js +169 -0
- package/packages/daemon/dist/tui/mirror/runtime/viewport-fit-coordinator.js +7 -0
- package/packages/daemon/dist/tui/mirror/runtime/workspace-terminal-fast-lane.js +498 -0
- package/packages/daemon/dist/tui/mirror/scrollbar-model.js +64 -0
- package/packages/daemon/dist/tui/mirror/search-model.js +62 -0
- package/packages/daemon/dist/tui/mirror/selection.js +264 -0
- package/packages/daemon/dist/tui/mirror/semantic-pane-render-source.js +581 -0
- package/packages/daemon/dist/tui/mirror/semantic-session-view.js +269 -0
- package/packages/daemon/dist/tui/mirror/settings-model.js +304 -0
- package/packages/daemon/dist/tui/mirror/shell-chrome.js +313 -0
- package/packages/daemon/dist/tui/mirror/size-truth.js +104 -0
- package/packages/daemon/dist/tui/mirror/spans.js +31 -0
- package/packages/daemon/dist/tui/mirror/status-grammar.js +29 -0
- package/packages/daemon/dist/tui/mirror/terminal-native-reflow.js +1 -0
- package/packages/daemon/dist/tui/mirror/terminal-retained-row.js +10 -0
- package/packages/daemon/dist/tui/mirror/terminal-surface.js +92 -0
- package/packages/daemon/dist/tui/mirror/terminal-text.js +52 -0
- package/packages/daemon/dist/tui/mirror/terminal-viewport.js +462 -0
- package/packages/daemon/dist/tui/mirror/theme.js +765 -0
- package/packages/daemon/dist/tui/mirror/ui/agent-badge.jsx +14 -0
- package/packages/daemon/dist/tui/mirror/ui/badge.jsx +15 -0
- package/packages/daemon/dist/tui/mirror/ui/button.jsx +66 -0
- package/packages/daemon/dist/tui/mirror/ui/dialog.jsx +8 -0
- package/packages/daemon/dist/tui/mirror/ui/index.js +16 -0
- package/packages/daemon/dist/tui/mirror/ui/key-hint.jsx +39 -0
- package/packages/daemon/dist/tui/mirror/ui/keyboard-router.jsx +46 -0
- package/packages/daemon/dist/tui/mirror/ui/menu.jsx +24 -0
- package/packages/daemon/dist/tui/mirror/ui/navigation-row.jsx +62 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-frame.jsx +54 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-host.jsx +33 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-list-row.jsx +29 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-model.js +45 -0
- package/packages/daemon/dist/tui/mirror/ui/state.js +171 -0
- package/packages/daemon/dist/tui/mirror/ui/status-bar.jsx +102 -0
- package/packages/daemon/dist/tui/mirror/ui/surface.jsx +45 -0
- package/packages/daemon/dist/tui/mirror/ui/tabs.jsx +88 -0
- package/packages/daemon/dist/tui/mirror/widget-fallback.js +52 -0
- package/packages/daemon/dist/tui/mirror/widget-surface-model.js +145 -0
- package/packages/daemon/dist/tui/mirror/widget-surface.jsx +31 -0
- package/packages/daemon/dist/tui/mirror/workspace/agent-terminal-canvas.js +77 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-command-description.js +44 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-root-controller.js +99 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-shell-controller.js +292 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-shell-surface-commands.js +28 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-shell.js +97 -0
- package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface-view.jsx +158 -0
- package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface.js +353 -0
- package/packages/daemon/dist/tui/mirror/workspace/connection-feedback.js +99 -0
- package/packages/daemon/dist/tui/mirror/workspace/icons.js +43 -0
- package/packages/daemon/dist/tui/mirror/workspace/pane-action-menu-model.js +8 -0
- package/packages/daemon/dist/tui/mirror/workspace/pane-action-menu.jsx +15 -0
- package/packages/daemon/dist/tui/mirror/workspace/pane-frame.js +452 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-chrome.js +555 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-header.jsx +159 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-scrollback.js +183 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-window-strip.jsx +253 -0
- package/packages/daemon/dist/tui/mirror/workspace/text.js +27 -0
- package/packages/daemon/dist/tui/mirror/workspace/workbench-controller.js +34 -0
- package/packages/daemon/dist/tui/mirror/workspace/workbench-shell.js +286 -0
- package/packages/daemon/dist/tui/mirror/workspace-ui-state.js +885 -0
- package/packages/daemon/dist/tui/readiness.js +34 -0
- package/packages/daemon/dist/tui/team/entry.js +20 -0
- package/packages/daemon/dist/tui/team/fuzzy.js +141 -0
- package/packages/daemon/dist/tui/team/home.js +115 -0
- package/packages/daemon/dist/tui/team/input.js +21 -0
- package/packages/daemon/dist/tui/team/keymap.js +99 -0
- package/packages/daemon/dist/tui/team/mouse.js +17 -0
- package/packages/daemon/dist/tui/team/nav.js +33 -0
- package/packages/daemon/dist/tui/team/preview.js +35 -0
- package/packages/daemon/dist/tui/team/projects.js +159 -0
- package/packages/daemon/dist/tui/team/report.js +37 -0
- package/packages/daemon/dist/tui/team/sessions.js +292 -0
- package/packages/daemon/dist/tui/team/tree.js +42 -0
- package/packages/daemon/dist/tui/team/wait-receipts.js +153 -0
- package/packages/daemon/dist/tui/team/wait.js +90 -0
- package/packages/daemon/dist/validate.js +16 -10
- package/packages/daemon/dist/widgets/lib/watcher.js +5 -92
- package/packages/daemon/dist/widgets/resolve.js +12 -9
- package/packages/daemon/dist/widgets/setup/setup-model.js +7 -9
- package/packages/daemon/src/attach.ts +2 -2
- package/packages/daemon/src/canonical.ts +19 -2
- package/packages/daemon/src/cli.ts +39 -37
- package/packages/daemon/src/command-center/actions/command-definitions.ts +91 -0
- package/packages/daemon/src/command-center/actions/dispatcher.ts +291 -10
- package/packages/daemon/src/command-center/actions/errors.ts +40 -0
- package/packages/daemon/src/command-center/actions/handlers/_project-context.ts +4 -5
- package/packages/daemon/src/command-center/actions/handlers/app-set-remote-access.ts +9 -1
- package/packages/daemon/src/command-center/actions/handlers/app-window-mutate.ts +54 -0
- package/packages/daemon/src/command-center/actions/handlers/config-actions.ts +59 -29
- package/packages/daemon/src/command-center/actions/handlers/daemon-shutdown.ts +12 -0
- package/packages/daemon/src/command-center/actions/handlers/fleet-lifecycle.ts +104 -0
- package/packages/daemon/src/command-center/actions/handlers/project-launch.ts +20 -4
- package/packages/daemon/src/command-center/actions/handlers/workspace-multiplexer.ts +96 -0
- package/packages/daemon/src/command-center/actions/handlers/workspace-open.ts +141 -0
- package/packages/daemon/src/command-center/actions/handlers/workspace-pane-create.ts +48 -0
- package/packages/daemon/src/command-center/actions/handlers/workspace-promote.ts +48 -0
- package/packages/daemon/src/command-center/actions/registry.ts +200 -1
- package/packages/daemon/src/command-center/actions/semantic-multiplexer-actions.ts +26 -0
- package/packages/daemon/src/command-center/agent-status-watch.ts +222 -0
- package/packages/daemon/src/command-center/daemon-fleet-facts-observer.ts +465 -0
- package/packages/daemon/src/command-center/discovery.ts +310 -5
- package/packages/daemon/src/command-center/owner-authority.ts +118 -0
- package/packages/daemon/src/command-center/pane-stream-issue.ts +247 -0
- package/packages/daemon/src/command-center/resources/agent-graph-overlay.ts +270 -0
- package/packages/daemon/src/command-center/resources/application-shell.ts +909 -0
- package/packages/daemon/src/command-center/resources/desktop-missions.ts +171 -0
- package/packages/daemon/src/command-center/resources/fleet-catalog.ts +200 -0
- package/packages/daemon/src/command-center/resources/fleet-resource-route.ts +69 -0
- package/packages/daemon/src/command-center/resources/startup-readiness-route.ts +172 -0
- package/packages/daemon/src/command-center/resources/startup-readiness.ts +250 -0
- package/packages/daemon/src/command-center/resources/terminal-native-backing-route.ts +104 -0
- package/packages/daemon/src/command-center/resources/terminal-runtime-inventory.ts +45 -0
- package/packages/daemon/src/command-center/resources/workspace-changes-authority.ts +594 -0
- package/packages/daemon/src/command-center/resources/workspace-changes-git.ts +278 -0
- package/packages/daemon/src/command-center/resources/workspace-files-authority.ts +583 -0
- package/packages/daemon/src/command-center/resources/workspace-missions-route.ts +125 -0
- package/packages/daemon/src/command-center/resources/workspace-resource-ids.ts +81 -0
- package/packages/daemon/src/command-center/resources/workspace-resource-routes.ts +147 -0
- package/packages/daemon/src/command-center/server.ts +732 -59
- package/packages/daemon/src/command-center/terminal-attachment-issue.ts +257 -0
- package/packages/daemon/src/command-center/workspace-resource-observer.ts +560 -0
- package/packages/daemon/src/command-center/ws-events.ts +853 -66
- package/packages/daemon/src/config.ts +35 -25
- package/packages/daemon/src/control/lifecycle.ts +14 -2
- package/packages/daemon/src/control/server.ts +3 -3
- package/packages/daemon/src/detect.ts +25 -20
- package/packages/daemon/src/doctor.ts +24 -7
- package/packages/daemon/src/index.ts +244 -2
- package/packages/daemon/src/init.ts +23 -22
- package/packages/daemon/src/inspect.ts +41 -8
- package/packages/daemon/src/launch.ts +56 -28
- package/packages/daemon/src/lib/agent-kind.ts +23 -0
- package/packages/daemon/src/lib/app-config.ts +44 -5
- package/packages/daemon/src/lib/app-window-kernel.ts +777 -0
- package/packages/daemon/src/lib/app-window-mutation.ts +178 -0
- package/packages/daemon/src/lib/app-window-repository.ts +650 -0
- package/packages/daemon/src/lib/app-window-state.ts +599 -0
- package/packages/daemon/src/lib/application-shell-app-windows.ts +357 -0
- package/packages/daemon/src/lib/auth/middleware.ts +9 -3
- package/packages/daemon/src/lib/bundled-tmux.ts +103 -0
- package/packages/daemon/src/lib/canonical-daemon-bootstrap.ts +392 -0
- package/packages/daemon/src/lib/canonical-daemon.ts +695 -73
- package/packages/daemon/src/lib/chrome-front-door.ts +17 -0
- package/packages/daemon/src/lib/cli-action-bridge.ts +127 -91
- package/packages/daemon/src/lib/command-registry.ts +152 -0
- package/packages/daemon/src/lib/config-context.ts +61 -0
- package/packages/daemon/src/lib/daemon-embed.ts +1374 -390
- package/packages/daemon/src/lib/daemon-session-monitor.ts +274 -0
- package/packages/daemon/src/lib/daemon.ts +3 -46
- package/packages/daemon/src/lib/directory-watcher.ts +166 -0
- package/packages/daemon/src/lib/embedded-daemon-lifecycle.ts +106 -0
- package/packages/daemon/src/lib/environment-identity.ts +82 -0
- package/packages/daemon/src/lib/errors.ts +7 -1
- package/packages/daemon/src/lib/fleet-agent-lifecycle.ts +74 -0
- package/packages/daemon/src/lib/fleet-lifecycle-authority.ts +535 -0
- package/packages/daemon/src/lib/headless-daemon.ts +459 -0
- package/packages/daemon/src/lib/launch-plan.ts +123 -4
- package/packages/daemon/src/lib/legacy-config-adapter.ts +28 -0
- package/packages/daemon/src/lib/legacy-config-migration.ts +145 -0
- package/packages/daemon/src/lib/legacy-theme-compat.ts +40 -0
- package/packages/daemon/src/lib/mission-projections.ts +775 -0
- package/packages/daemon/src/lib/mission-repository.ts +1311 -0
- package/packages/daemon/src/lib/onboarding-marker.ts +51 -0
- package/packages/daemon/src/lib/pane-chrome.ts +14 -0
- package/packages/daemon/src/lib/pane-source-credentials.ts +200 -0
- package/packages/daemon/src/lib/pane-widget.ts +182 -0
- package/packages/daemon/src/lib/project-inspect.ts +4 -0
- package/packages/daemon/src/lib/project-onboard.ts +19 -24
- package/packages/daemon/src/lib/project-probe.ts +38 -30
- package/packages/daemon/src/lib/project-readiness-probe.ts +578 -0
- package/packages/daemon/src/lib/project-readiness.ts +1034 -0
- package/packages/daemon/src/lib/project-registry.ts +45 -9
- package/packages/daemon/src/lib/project-resolver.ts +350 -0
- package/packages/daemon/src/lib/project-runtime-errors.ts +41 -0
- package/packages/daemon/src/lib/project-runtime-repository.ts +1194 -0
- package/packages/daemon/src/lib/remote-daemon-info.ts +42 -0
- package/packages/daemon/src/lib/resolved-config.ts +425 -0
- package/packages/daemon/src/lib/runtime-namespace.ts +186 -0
- package/packages/daemon/src/lib/saved-machines.ts +63 -0
- package/packages/daemon/src/lib/semantic-resource-id.ts +17 -0
- package/packages/daemon/src/lib/session-monitor.ts +28 -20
- package/packages/daemon/src/lib/session-options.ts +3 -10
- package/packages/daemon/src/lib/ssh-daemon-transport.ts +303 -0
- package/packages/daemon/src/lib/state-home.ts +2 -3
- package/packages/daemon/src/lib/theme-mode.ts +11 -0
- package/packages/daemon/src/lib/tmux-authority-replacement.ts +119 -0
- package/packages/daemon/src/lib/tmux-external-interaction-observer.ts +632 -0
- package/packages/daemon/src/lib/tmux-interaction-options.ts +171 -0
- package/packages/daemon/src/lib/tmux-named-socket-fence.ts +66 -0
- package/packages/daemon/src/lib/tmux-terminal-color.ts +44 -0
- package/packages/daemon/src/lib/tui-binary.ts +354 -34
- package/packages/daemon/src/lib/unix-socket-authority.ts +65 -0
- package/packages/daemon/src/lib/widget-asset-policy.ts +3 -0
- package/packages/daemon/src/lib/widget-asset-store.ts +218 -0
- package/packages/daemon/src/lib/workspace-config-loader.ts +378 -0
- package/packages/daemon/src/lib/workspace-multiplexer-verbs.ts +1362 -0
- package/packages/daemon/src/lib/workspace-open-handoff.ts +340 -0
- package/packages/daemon/src/lib/workspace-open.ts +983 -0
- package/packages/daemon/src/lib/workspace-pane-creation.ts +1434 -0
- package/packages/daemon/src/lib/workspace-promotion.ts +1035 -0
- package/packages/daemon/src/lib/workspace-registry.ts +193 -25
- package/packages/daemon/src/lib/workspace-state-repository.ts +1204 -0
- package/packages/daemon/src/lib/workspace-state.ts +960 -0
- package/packages/daemon/src/lib/yaml-io.ts +8 -17
- package/packages/daemon/src/migrate.ts +134 -0
- package/packages/daemon/src/restart.ts +2 -2
- package/packages/daemon/src/restore.ts +14 -9
- package/packages/daemon/src/schemas/inspect.ts +9 -1
- package/packages/daemon/src/schemas/registry.ts +12 -22
- package/packages/daemon/src/schemas/ws-events.ts +14 -131
- package/packages/daemon/src/send.ts +138 -3
- package/packages/daemon/src/server/README.md +1 -1
- package/packages/daemon/src/server/index.ts +6 -2
- package/packages/daemon/src/server/pane-stream-upgrade.ts +141 -0
- package/packages/daemon/src/server/terminal-attachment-upgrade.ts +153 -0
- package/packages/daemon/src/status.ts +13 -8
- package/packages/daemon/src/stop.ts +2 -2
- package/packages/daemon/src/terminal/MonotonicPtyInput.ts +153 -0
- package/packages/daemon/src/terminal/NodePtyAdapter.ts +53 -11
- package/packages/daemon/src/terminal/PtyAdapter.ts +111 -3
- package/packages/daemon/src/terminal/README.md +34 -16
- package/packages/daemon/src/terminal/attachments/admission-util.ts +97 -0
- package/packages/daemon/src/terminal/attachments/agent-status-probe.ts +474 -0
- package/packages/daemon/src/terminal/attachments/direct-websocket.ts +1482 -0
- package/packages/daemon/src/terminal/attachments/grouped-tmux.ts +293 -0
- package/packages/daemon/src/terminal/attachments/lease-manager.ts +1042 -0
- package/packages/daemon/src/terminal/attachments/native-runtime.ts +2246 -0
- package/packages/daemon/src/terminal/attachments/pty-tmux-attachment-launcher.ts +750 -0
- package/packages/daemon/src/terminal/attachments/semantic-pane-catalog.ts +365 -0
- package/packages/daemon/src/terminal/attachments/tmux-view-executor.ts +1095 -0
- package/packages/daemon/src/terminal/mirror/control-channel.ts +1031 -0
- package/packages/daemon/src/terminal/mirror/control-mode-ownership.ts +34 -0
- package/packages/daemon/src/terminal/mirror/events.ts +164 -0
- package/packages/daemon/src/terminal/mirror/flow-ledger.ts +65 -0
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +503 -0
- package/packages/daemon/src/terminal/mirror/native-frozen-grid.ts +154 -0
- package/packages/daemon/src/terminal/mirror/native-grid-capture.ts +235 -0
- package/packages/daemon/src/terminal/mirror/native-grid-projection.ts +125 -0
- package/packages/daemon/src/terminal/mirror/native-grid-reader.ts +109 -0
- package/packages/daemon/src/terminal/mirror/native-grid-reflow.ts +241 -0
- package/packages/daemon/src/terminal/mirror/pane-feed.ts +272 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +3378 -0
- package/packages/daemon/src/terminal/mirror/trusted-inventory.ts +29 -0
- package/packages/daemon/src/terminal/pane-stream/lease-manager.ts +375 -0
- package/packages/daemon/src/terminal/pane-stream/pane-stream-websocket.ts +2625 -0
- package/packages/daemon/src/terminal/pane-stream/runtime.ts +78 -0
- package/packages/daemon/src/terminal/pane-stream/wire-ledger.ts +155 -0
- package/packages/daemon/src/terminal/protocol/README.md +14 -0
- package/packages/daemon/src/terminal/protocol/chunk-bytes.ts +20 -0
- package/packages/daemon/src/terminal/protocol/control.ts +130 -0
- package/packages/daemon/src/terminal/protocol/input-coalescer.ts +131 -0
- package/packages/daemon/src/terminal/protocol/native-backing-client.ts +65 -0
- package/packages/daemon/src/terminal/protocol/pane-display-name.ts +192 -0
- package/packages/daemon/src/terminal/protocol/session-descriptor-discovery.ts +382 -0
- package/packages/daemon/src/terminal/protocol/workspace-tmux-adapter.ts +470 -0
- package/packages/daemon/src/terminal/session-runtime/authority-arbiter.ts +318 -0
- package/packages/daemon/src/terminal/session-runtime/causal-cell-ledger.ts +359 -0
- package/packages/daemon/src/terminal/session-runtime/interaction-receipt-facts.ts +173 -0
- package/packages/daemon/src/terminal/session-runtime/multiplexer-backend.ts +194 -0
- package/packages/daemon/src/terminal/session-runtime/native-seed-backing.ts +80 -0
- package/packages/daemon/src/terminal/session-runtime/registry.ts +2084 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +267 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-scheduler.ts +30 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-trace-correlator.ts +58 -0
- package/packages/daemon/src/terminal/session-runtime/semantic-mutation-executor.ts +555 -0
- package/packages/daemon/src/terminal/session-runtime/semantic-mutation-resource-changes.ts +48 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-delivery-hub.ts +2324 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-delivery-observation-identity.ts +18 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-interpreter-backend.ts +78 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +765 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +698 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-shadow-projections.ts +36 -0
- package/packages/daemon/src/terminal/session-runtime/transport-binding.ts +682 -0
- package/packages/daemon/src/terminal/session-runtime/xterm-headless-provenance.json +51 -0
- package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +697 -0
- package/packages/daemon/src/tui/async-disposable-slot.ts +60 -0
- package/packages/daemon/src/tui/chrome/front-door.ts +11 -23
- package/packages/daemon/src/tui/chrome/sidebar.ts +11 -5
- package/packages/daemon/src/tui/chrome/statusline.ts +15 -6
- package/packages/daemon/src/tui/chrome/updater.ts +100 -3
- package/packages/daemon/src/tui/compiled.ts +132 -6
- package/packages/daemon/src/tui/detect/agent-resolution.ts +85 -0
- package/packages/daemon/src/tui/detect/process-tree.ts +17 -1
- package/packages/daemon/src/tui/detect/snapshot.ts +38 -3
- package/packages/daemon/src/tui/integrations/claude.ts +1 -0
- package/packages/daemon/src/tui/main.ts +56 -0
- package/packages/daemon/src/tui/mirror/RECIPES.md +59 -0
- package/packages/daemon/src/tui/mirror/SHELL_CHROME.md +39 -0
- package/packages/daemon/src/tui/mirror/THEME.md +48 -0
- package/packages/daemon/src/tui/mirror/__snapshots__/activity-surface-renderer.test.tsx.snap +42 -0
- package/packages/daemon/src/tui/mirror/__snapshots__/changes-terminal-surface-renderer.test.tsx.snap +267 -0
- package/packages/daemon/src/tui/mirror/__snapshots__/home-files-surface-renderer.test.tsx.snap +267 -0
- package/packages/daemon/src/tui/mirror/__snapshots__/missions-surface-renderer.test.tsx.snap +134 -0
- package/packages/daemon/src/tui/mirror/__snapshots__/recipes-gallery-renderer.test.tsx.snap +141 -0
- package/packages/daemon/src/tui/mirror/__snapshots__/shell-chrome-renderer.test.tsx.snap +134 -0
- package/packages/daemon/src/tui/mirror/activity-surface-view.tsx +169 -0
- package/packages/daemon/src/tui/mirror/activity-surface.ts +430 -0
- package/packages/daemon/src/tui/mirror/agent-lifecycle.ts +36 -5
- package/packages/daemon/src/tui/mirror/agent-provisioning-executor.ts +175 -0
- package/packages/daemon/src/tui/mirror/agent-rows.ts +34 -0
- package/packages/daemon/src/tui/mirror/ansi-palette.ts +3 -0
- package/packages/daemon/src/tui/mirror/app-state.ts +14 -1
- package/packages/daemon/src/tui/mirror/app.tsx +2 -7047
- package/packages/daemon/src/tui/mirror/application-keybindings.ts +54 -0
- package/packages/daemon/src/tui/mirror/application-shell-daemon-connection.ts +370 -0
- package/packages/daemon/src/tui/mirror/application-shell-daemon-session.ts +74 -0
- package/packages/daemon/src/tui/mirror/canonical-workspace-routing.ts +90 -0
- package/packages/daemon/src/tui/mirror/changes-surface-view.tsx +263 -0
- package/packages/daemon/src/tui/mirror/changes-surface.ts +338 -0
- package/packages/daemon/src/tui/mirror/composite-layout.ts +710 -0
- package/packages/daemon/src/tui/mirror/configless-session-bootstrap.ts +192 -0
- package/packages/daemon/src/tui/mirror/dialog-model.ts +2 -2
- package/packages/daemon/src/tui/mirror/dialog-stack-core.ts +264 -0
- package/packages/daemon/src/tui/mirror/dialog-stack.ts +2 -367
- package/packages/daemon/src/tui/mirror/editor-buffer.ts +9 -70
- package/packages/daemon/src/tui/mirror/editor-open-policy.ts +16 -0
- package/packages/daemon/src/tui/mirror/features/changes/contract.ts +84 -0
- package/packages/daemon/src/tui/mirror/features/changes/controller.ts +470 -0
- package/packages/daemon/src/tui/mirror/features/changes/feature.tsx +19 -0
- package/packages/daemon/src/tui/mirror/features/dialogs/contract.ts +64 -0
- package/packages/daemon/src/tui/mirror/features/dialogs/feature.tsx +227 -0
- package/packages/daemon/src/tui/mirror/features/dialogs/session.ts +186 -0
- package/packages/daemon/src/tui/mirror/features/files/feature.tsx +54 -0
- package/packages/daemon/src/tui/mirror/features/files/session.ts +694 -0
- package/packages/daemon/src/tui/mirror/features/home/feature.tsx +172 -0
- package/packages/daemon/src/tui/mirror/features/missions-activity/contract.ts +106 -0
- package/packages/daemon/src/tui/mirror/features/missions-activity/feature.tsx +19 -0
- package/packages/daemon/src/tui/mirror/features/missions-activity/session.ts +470 -0
- package/packages/daemon/src/tui/mirror/features/palette/buffer-geometry.ts +46 -0
- package/packages/daemon/src/tui/mirror/features/palette/contract.ts +121 -0
- package/packages/daemon/src/tui/mirror/features/palette/feature.ts +14 -0
- package/packages/daemon/src/tui/mirror/features/palette/session.ts +443 -0
- package/packages/daemon/src/tui/mirror/features/palette/surface.tsx +133 -0
- package/packages/daemon/src/tui/mirror/features/performance-hud/contract.ts +20 -0
- package/packages/daemon/src/tui/mirror/features/performance-hud/feature.tsx +8 -0
- package/packages/daemon/src/tui/mirror/features/performance-hud/session.ts +152 -0
- package/packages/daemon/src/tui/mirror/features/performance-hud/surface.tsx +137 -0
- package/packages/daemon/src/tui/mirror/features/rich-preview/asset-loader.ts +153 -0
- package/packages/daemon/src/tui/mirror/features/rich-preview/contract.ts +94 -0
- package/packages/daemon/src/tui/mirror/features/rich-preview/feature.tsx +141 -0
- package/packages/daemon/src/tui/mirror/features/rich-preview/session.ts +387 -0
- package/packages/daemon/src/tui/mirror/features/settings/catalog.ts +26 -0
- package/packages/daemon/src/tui/mirror/features/settings/contract.ts +41 -0
- package/packages/daemon/src/tui/mirror/features/settings/feature.ts +3 -0
- package/packages/daemon/src/tui/mirror/features/settings/session.ts +375 -0
- package/packages/daemon/src/tui/mirror/files-surface-view.tsx +242 -0
- package/packages/daemon/src/tui/mirror/files-surface.ts +371 -0
- package/packages/daemon/src/tui/mirror/focus-projection.ts +113 -0
- package/packages/daemon/src/tui/mirror/frame-coalescer.ts +87 -0
- package/packages/daemon/src/tui/mirror/home-model.ts +1 -1
- package/packages/daemon/src/tui/mirror/home-surface-model.ts +440 -0
- package/packages/daemon/src/tui/mirror/home-surface.tsx +254 -0
- package/packages/daemon/src/tui/mirror/hosted.ts +87 -6
- package/packages/daemon/src/tui/mirror/input-lifecycle.ts +248 -0
- package/packages/daemon/src/tui/mirror/interaction-flow.ts +83 -0
- package/packages/daemon/src/tui/mirror/legacy/missions-workspace-loader.ts +117 -0
- package/packages/daemon/src/tui/mirror/menu-model.ts +1 -14
- package/packages/daemon/src/tui/mirror/missions-dashboard.ts +451 -0
- package/packages/daemon/src/tui/mirror/missions-render-fixtures.ts +371 -0
- package/packages/daemon/src/tui/mirror/missions-surface-controller.ts +530 -0
- package/packages/daemon/src/tui/mirror/missions-surface.tsx +434 -0
- package/packages/daemon/src/tui/mirror/missions-workspace.ts +1996 -0
- package/packages/daemon/src/tui/mirror/multiplexer-action-executor.ts +393 -0
- package/packages/daemon/src/tui/mirror/open-tui-pane-stream-socket.ts +47 -0
- package/packages/daemon/src/tui/mirror/open-tui-verified-routing.ts +152 -0
- package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +1451 -0
- package/packages/daemon/src/tui/mirror/palette-surface-adapter.ts +465 -0
- package/packages/daemon/src/tui/mirror/palette.ts +189 -28
- package/packages/daemon/src/tui/mirror/pane-frame-state.ts +209 -0
- package/packages/daemon/src/tui/mirror/pane-mirror.ts +11 -593
- package/packages/daemon/src/tui/mirror/pane-surface.tsx +858 -53
- package/packages/daemon/src/tui/mirror/panel-host-reactive.ts +17 -0
- package/packages/daemon/src/tui/mirror/panel-host.ts +384 -0
- package/packages/daemon/src/tui/mirror/perf-tap.ts +1 -148
- package/packages/daemon/src/tui/mirror/performance-events.ts +494 -0
- package/packages/daemon/src/tui/mirror/recipe-components.tsx +310 -0
- package/packages/daemon/src/tui/mirror/recipes-gallery.tsx +256 -0
- package/packages/daemon/src/tui/mirror/recipes.ts +543 -0
- package/packages/daemon/src/tui/mirror/reference-performance-trace.ts +727 -0
- package/packages/daemon/src/tui/mirror/renderer-commands.ts +344 -0
- package/packages/daemon/src/tui/mirror/resize-model.ts +74 -9
- package/packages/daemon/src/tui/mirror/resize-transaction.ts +342 -0
- package/packages/daemon/src/tui/mirror/rich-placement-projection.ts +173 -0
- package/packages/daemon/src/tui/mirror/runtime/__snapshots__/application-shell-view-renderer.test.tsx.snap +87 -0
- package/packages/daemon/src/tui/mirror/runtime/application-add-machine-dialog.tsx +88 -0
- package/packages/daemon/src/tui/mirror/runtime/application-appearance-owner.ts +229 -0
- package/packages/daemon/src/tui/mirror/runtime/application-bootstrap.ts +118 -0
- package/packages/daemon/src/tui/mirror/runtime/application-daemon-authority-owner.ts +259 -0
- package/packages/daemon/src/tui/mirror/runtime/application-daemon-authority.ts +16 -0
- package/packages/daemon/src/tui/mirror/runtime/application-entry.ts +226 -0
- package/packages/daemon/src/tui/mirror/runtime/application-generation-starter.ts +130 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-navigation.ts +174 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-observer.ts +363 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-roster.tsx +276 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-selection.ts +99 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-agent-transport.ts +232 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-agents-owner.ts +295 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-agents.ts +70 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-catalog-owner.ts +130 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-catalog.ts +451 -0
- package/packages/daemon/src/tui/mirror/runtime/application-host-focus-control-binding.ts +143 -0
- package/packages/daemon/src/tui/mirror/runtime/application-host-focus-control-capability.ts +46 -0
- package/packages/daemon/src/tui/mirror/runtime/application-host-focus-presentation.ts +176 -0
- package/packages/daemon/src/tui/mirror/runtime/application-host-focus-test-control.ts +313 -0
- package/packages/daemon/src/tui/mirror/runtime/application-input-readiness.ts +28 -0
- package/packages/daemon/src/tui/mirror/runtime/application-lifecycle.ts +374 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-agent-navigation.ts +91 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-agents.ts +199 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-authority.ts +337 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-catalog.ts +256 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-navigation.ts +177 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-sidebar.tsx +356 -0
- package/packages/daemon/src/tui/mirror/runtime/application-machine-startup.ts +39 -0
- package/packages/daemon/src/tui/mirror/runtime/application-optional-features.ts +25 -0
- package/packages/daemon/src/tui/mirror/runtime/application-palette-command-owner.ts +162 -0
- package/packages/daemon/src/tui/mirror/runtime/application-palette-input.ts +108 -0
- package/packages/daemon/src/tui/mirror/runtime/application-palette-search-owner.ts +78 -0
- package/packages/daemon/src/tui/mirror/runtime/application-pane-activity-owner.ts +79 -0
- package/packages/daemon/src/tui/mirror/runtime/application-pane-menu-owner.ts +95 -0
- package/packages/daemon/src/tui/mirror/runtime/application-pane-rename-input.ts +61 -0
- package/packages/daemon/src/tui/mirror/runtime/application-pane-rename-owner.ts +50 -0
- package/packages/daemon/src/tui/mirror/runtime/application-pending-terminal-input.ts +117 -0
- package/packages/daemon/src/tui/mirror/runtime/application-performance-log.ts +166 -0
- package/packages/daemon/src/tui/mirror/runtime/application-post-render-runtime.ts +163 -0
- package/packages/daemon/src/tui/mirror/runtime/application-root-configuration.ts +47 -0
- package/packages/daemon/src/tui/mirror/runtime/application-root-renderer.ts +165 -0
- package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +632 -0
- package/packages/daemon/src/tui/mirror/runtime/application-session-focus-owner.ts +80 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-binding.ts +375 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-catalog.tsx +448 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-home.tsx +252 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-overlay-stack.tsx +37 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-overlays.tsx +381 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-sidebar.tsx +188 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-view.tsx +537 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-viewport.ts +18 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-frame-readiness-owner.ts +33 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-host-focus-owner.ts +36 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-input-ingress.ts +139 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +1673 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-palette-owner.ts +302 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-paste.ts +33 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-renderer-sources.ts +33 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-selection-owner.ts +277 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-workspace-policy.ts +311 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-workspace.tsx +1921 -0
- package/packages/daemon/src/tui/mirror/runtime/application-theme-repaint.ts +45 -0
- package/packages/daemon/src/tui/mirror/runtime/application-transient-note-owner.ts +42 -0
- package/packages/daemon/src/tui/mirror/runtime/bounded-performance-record-writer.ts +75 -0
- package/packages/daemon/src/tui/mirror/runtime/causal-cell-client-ledger.ts +406 -0
- package/packages/daemon/src/tui/mirror/runtime/causal-cell-input-fixture.ts +55 -0
- package/packages/daemon/src/tui/mirror/runtime/changes-deferred-identity.ts +34 -0
- package/packages/daemon/src/tui/mirror/runtime/daemon-authority-rebind.ts +163 -0
- package/packages/daemon/src/tui/mirror/runtime/deferred-intent-queue.ts +45 -0
- package/packages/daemon/src/tui/mirror/runtime/editor-primitives.ts +56 -0
- package/packages/daemon/src/tui/mirror/runtime/file-content-primitives.ts +8 -0
- package/packages/daemon/src/tui/mirror/runtime/fleet-lifecycle-client.ts +67 -0
- package/packages/daemon/src/tui/mirror/runtime/focus-framebuffer-projection.ts +71 -0
- package/packages/daemon/src/tui/mirror/runtime/generation-bound-slot.ts +23 -0
- package/packages/daemon/src/tui/mirror/runtime/host-local-tmux-adapter.ts +233 -0
- package/packages/daemon/src/tui/mirror/runtime/hosted-tty-size-bridge.ts +213 -0
- package/packages/daemon/src/tui/mirror/runtime/latest-intent-fence.ts +22 -0
- package/packages/daemon/src/tui/mirror/runtime/local-view-controller.ts +95 -0
- package/packages/daemon/src/tui/mirror/runtime/modal-admission-coordinator.ts +158 -0
- package/packages/daemon/src/tui/mirror/runtime/modal-pointer-capture.ts +23 -0
- package/packages/daemon/src/tui/mirror/runtime/open-tui-generation-host.ts +1003 -0
- package/packages/daemon/src/tui/mirror/runtime/open-tui-session-owner.ts +229 -0
- package/packages/daemon/src/tui/mirror/runtime/optional-feature-registry.ts +234 -0
- package/packages/daemon/src/tui/mirror/runtime/optional-feature-registry.typecheck.ts +14 -0
- package/packages/daemon/src/tui/mirror/runtime/palette-production-controller.ts +170 -0
- package/packages/daemon/src/tui/mirror/runtime/palette-production-overlay.tsx +65 -0
- package/packages/daemon/src/tui/mirror/runtime/pane-resize-geometry.ts +29 -0
- package/packages/daemon/src/tui/mirror/runtime/pane-scoped-terminal-surface.tsx +156 -0
- package/packages/daemon/src/tui/mirror/runtime/product-surface-policy.ts +16 -0
- package/packages/daemon/src/tui/mirror/runtime/renderer-cadence.ts +7 -0
- package/packages/daemon/src/tui/mirror/runtime/renderer-frame-optimizer.ts +92 -0
- package/packages/daemon/src/tui/mirror/runtime/renderer-output-transport.ts +57 -0
- package/packages/daemon/src/tui/mirror/runtime/resize-terminal-pane.ts +134 -0
- package/packages/daemon/src/tui/mirror/runtime/rich-preview-demand.ts +26 -0
- package/packages/daemon/src/tui/mirror/runtime/rich-preview-overlay.tsx +54 -0
- package/packages/daemon/src/tui/mirror/runtime/runtime-layout-presentation.ts +119 -0
- package/packages/daemon/src/tui/mirror/runtime/select-terminal-pane.ts +127 -0
- package/packages/daemon/src/tui/mirror/runtime/semantic-pane-publication.ts +26 -0
- package/packages/daemon/src/tui/mirror/runtime/semantic-shell-viewport-resize.ts +88 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-copy-cursor.ts +169 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-copy-selection.ts +79 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-dimensions-owner.ts +20 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-fast-lane-renderer-adapter.ts +1085 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-frame-readiness.ts +100 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-host-focus.ts +519 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-host-frame-diagnostics.ts +47 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-input-adapter.ts +69 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-layout-projection.ts +145 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-link-opener.ts +30 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-links.ts +97 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-pane-input-router.ts +95 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-row-projection-cache.ts +115 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-selection-units.ts +128 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-selection.ts +285 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-session-handoff.ts +143 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-tool-readiness.ts +72 -0
- package/packages/daemon/src/tui/mirror/runtime/tool-resource-controller.ts +799 -0
- package/packages/daemon/src/tui/mirror/runtime/tool-resource-projection.ts +223 -0
- package/packages/daemon/src/tui/mirror/runtime/viewport-fit-coordinator.ts +12 -0
- package/packages/daemon/src/tui/mirror/runtime/workspace-terminal-fast-lane.ts +597 -0
- package/packages/daemon/src/tui/mirror/selection.ts +0 -21
- package/packages/daemon/src/tui/mirror/semantic-pane-render-source.ts +786 -0
- package/packages/daemon/src/tui/mirror/semantic-session-view.ts +366 -0
- package/packages/daemon/src/tui/mirror/settings-model.ts +24 -66
- package/packages/daemon/src/tui/mirror/shell-chrome-view.tsx +346 -0
- package/packages/daemon/src/tui/mirror/shell-chrome.ts +509 -0
- package/packages/daemon/src/tui/mirror/sidebar.tsx +138 -35
- package/packages/daemon/src/tui/mirror/size-truth.ts +1 -1
- package/packages/daemon/src/tui/mirror/terminal-native-reflow.ts +1 -0
- package/packages/daemon/src/tui/mirror/terminal-retained-row.ts +24 -0
- package/packages/daemon/src/tui/mirror/terminal-surface.ts +157 -0
- package/packages/daemon/src/tui/mirror/terminal-surface.tsx +84 -0
- package/packages/daemon/src/tui/mirror/terminal-text.ts +54 -0
- package/packages/daemon/src/tui/mirror/terminal-viewport.ts +544 -0
- package/packages/daemon/src/tui/mirror/theme.ts +1069 -33
- package/packages/daemon/src/tui/mirror/ui/agent-badge.tsx +41 -0
- package/packages/daemon/src/tui/mirror/ui/badge.tsx +42 -0
- package/packages/daemon/src/tui/mirror/ui/button.tsx +127 -0
- package/packages/daemon/src/tui/mirror/ui/dialog.tsx +45 -0
- package/packages/daemon/src/tui/mirror/ui/index.ts +59 -0
- package/packages/daemon/src/tui/mirror/ui/key-hint.tsx +63 -0
- package/packages/daemon/src/tui/mirror/ui/keyboard-router.tsx +72 -0
- package/packages/daemon/src/tui/mirror/ui/menu.tsx +86 -0
- package/packages/daemon/src/tui/mirror/ui/navigation-row.tsx +114 -0
- package/packages/daemon/src/tui/mirror/ui/overlay-frame.tsx +117 -0
- package/packages/daemon/src/tui/mirror/ui/overlay-host.tsx +71 -0
- package/packages/daemon/src/tui/mirror/ui/overlay-list-row.tsx +68 -0
- package/packages/daemon/src/tui/mirror/ui/overlay-model.ts +75 -0
- package/packages/daemon/src/tui/mirror/ui/state.ts +218 -0
- package/packages/daemon/src/tui/mirror/ui/status-bar.tsx +208 -0
- package/packages/daemon/src/tui/mirror/ui/surface.tsx +71 -0
- package/packages/daemon/src/tui/mirror/ui/tabs.tsx +168 -0
- package/packages/daemon/src/tui/mirror/widget-fallback.ts +66 -0
- package/packages/daemon/src/tui/mirror/widget-surface-model.ts +170 -0
- package/packages/daemon/src/tui/mirror/widget-surface.tsx +79 -0
- package/packages/daemon/src/tui/mirror/workspace/README.md +79 -0
- package/packages/daemon/src/tui/mirror/workspace/__snapshots__/agent-terminal-canvas-renderer.test.tsx.snap +348 -0
- package/packages/daemon/src/tui/mirror/workspace/__snapshots__/application-shell-renderer.test.tsx.snap +134 -0
- package/packages/daemon/src/tui/mirror/workspace/__snapshots__/command-palette-surface-renderer.test.tsx.snap +255 -0
- package/packages/daemon/src/tui/mirror/workspace/__snapshots__/pane-frame-renderer.test.tsx.snap +525 -0
- package/packages/daemon/src/tui/mirror/workspace/__snapshots__/terminal-pane-header-polish-renderer.test.tsx.snap +31 -0
- package/packages/daemon/src/tui/mirror/workspace/__snapshots__/workbench-shell-renderer.test.tsx.snap +134 -0
- package/packages/daemon/src/tui/mirror/workspace/agent-terminal-canvas-view.tsx +61 -0
- package/packages/daemon/src/tui/mirror/workspace/agent-terminal-canvas.ts +131 -0
- package/packages/daemon/src/tui/mirror/workspace/application-command-description.ts +77 -0
- package/packages/daemon/src/tui/mirror/workspace/application-root-controller.ts +169 -0
- package/packages/daemon/src/tui/mirror/workspace/application-shell-controller.ts +430 -0
- package/packages/daemon/src/tui/mirror/workspace/application-shell-surface-commands.ts +64 -0
- package/packages/daemon/src/tui/mirror/workspace/application-shell-view.tsx +169 -0
- package/packages/daemon/src/tui/mirror/workspace/application-shell.ts +179 -0
- package/packages/daemon/src/tui/mirror/workspace/command-palette-surface-view.tsx +356 -0
- package/packages/daemon/src/tui/mirror/workspace/command-palette-surface.ts +557 -0
- package/packages/daemon/src/tui/mirror/workspace/connection-feedback.ts +105 -0
- package/packages/daemon/src/tui/mirror/workspace/icons.ts +56 -0
- package/packages/daemon/src/tui/mirror/workspace/pane-action-menu-model.ts +33 -0
- package/packages/daemon/src/tui/mirror/workspace/pane-action-menu.tsx +54 -0
- package/packages/daemon/src/tui/mirror/workspace/pane-frame.ts +675 -0
- package/packages/daemon/src/tui/mirror/workspace/pane-frame.tsx +490 -0
- package/packages/daemon/src/tui/mirror/workspace/terminal-pane-chrome-view.tsx +125 -0
- package/packages/daemon/src/tui/mirror/workspace/terminal-pane-chrome.ts +833 -0
- package/packages/daemon/src/tui/mirror/workspace/terminal-pane-header.tsx +326 -0
- package/packages/daemon/src/tui/mirror/workspace/terminal-scrollback.ts +220 -0
- package/packages/daemon/src/tui/mirror/workspace/terminal-window-strip.tsx +466 -0
- package/packages/daemon/src/tui/mirror/workspace/text.ts +28 -0
- package/packages/daemon/src/tui/mirror/workspace/workbench-controller.ts +75 -0
- package/packages/daemon/src/tui/mirror/workspace/workbench-dock-opentui.tsx +224 -0
- package/packages/daemon/src/tui/mirror/workspace/workbench-shell.ts +486 -0
- package/packages/daemon/src/tui/mirror/workspace/workbench-shell.tsx +95 -0
- package/packages/daemon/src/tui/mirror/workspace-ui-state.ts +1278 -0
- package/packages/daemon/src/tui/readiness.ts +52 -0
- package/packages/daemon/src/tui/team/entry.ts +23 -13
- package/packages/daemon/src/tui/team/home.ts +1 -1
- package/packages/daemon/src/tui/team/index.tsx +27 -8
- package/packages/daemon/src/tui/team/projects.ts +12 -0
- package/packages/daemon/src/tui/team/sessions.ts +43 -48
- package/packages/daemon/src/tui/team/wait-receipts.ts +192 -0
- package/packages/daemon/src/ui/pane-frame/fixture.ts +43 -0
- package/packages/daemon/src/ui/workbench-dock/fixture.ts +61 -0
- package/packages/daemon/src/validate.ts +21 -9
- package/packages/daemon/src/widgets/config/README.md +1 -1
- package/packages/daemon/src/widgets/config/index.tsx +15 -115
- package/packages/daemon/src/widgets/lib/watcher.ts +3 -130
- package/packages/daemon/src/widgets/resolve.ts +18 -9
- package/packages/daemon/src/widgets/setup/footer.tsx +0 -7
- package/packages/daemon/src/widgets/setup/index.tsx +18 -20
- package/packages/daemon/src/widgets/setup/review-panel.tsx +15 -10
- package/packages/daemon/src/widgets/setup/setup-model.ts +7 -10
- package/packages/daemon-client/package.json +42 -0
- package/packages/daemon-client/src/application-shell-session.test.ts +196 -0
- package/packages/daemon-client/src/application-shell-session.ts +450 -0
- package/packages/daemon-client/src/bootstrap-coordinator.test.ts +122 -0
- package/packages/daemon-client/src/bootstrap-coordinator.ts +293 -0
- package/packages/daemon-client/src/connection-supervisor.test.ts +109 -0
- package/packages/daemon-client/src/connection-supervisor.ts +216 -0
- package/packages/daemon-client/src/direct-application-shell-transport.test.ts +939 -0
- package/packages/daemon-client/src/direct-application-shell-transport.ts +1144 -0
- package/packages/daemon-client/src/first-latest-coordinator.test.ts +175 -0
- package/packages/daemon-client/src/first-latest-coordinator.ts +82 -0
- package/packages/daemon-client/src/generation-bound-store-timers.test.ts +74 -0
- package/packages/daemon-client/src/generation-bound-store.ts +908 -0
- package/packages/daemon-client/src/index.ts +25 -0
- package/packages/daemon-client/src/owner-action-client.test.ts +180 -0
- package/packages/daemon-client/src/owner-action-client.ts +113 -0
- package/packages/daemon-client/src/pane-stream-client.test.ts +2771 -0
- package/packages/daemon-client/src/pane-stream-client.ts +1665 -0
- package/packages/daemon-client/src/pane-stream-clock-calibration.test.ts +207 -0
- package/packages/daemon-client/src/pane-stream-clock-calibration.ts +161 -0
- package/packages/daemon-client/src/pane-stream-loopback-benchmark.test.ts +51 -0
- package/packages/daemon-client/src/push-resource-session.test.ts +509 -0
- package/packages/daemon-client/src/push-resource-session.ts +797 -0
- package/packages/daemon-client/src/resource-replica.test.ts +186 -0
- package/packages/daemon-client/src/resource-replica.ts +280 -0
- package/packages/daemon-client/src/runtime-resource-ledger.test.ts +18 -0
- package/packages/daemon-client/src/runtime-resource-ledger.ts +69 -0
- package/packages/daemon-client/src/terminal-fast-lane.test.ts +817 -0
- package/packages/daemon-client/src/terminal-fast-lane.ts +817 -0
- package/packages/daemon-client/src/terminal-fast-lane.typecheck.ts +16 -0
- package/packages/daemon-client/src/workspace-catalog-v2.test.ts +109 -0
- package/packages/daemon-client/src/workspace-catalog-v2.ts +66 -0
- package/packages/daemon-client/src/workspace-client-boundaries.test.ts +59 -0
- package/packages/daemon-client/src/workspace-client-conformance.ts +67 -0
- package/packages/daemon-client/src/workspace-client-operations.test.ts +47 -0
- package/packages/daemon-client/src/workspace-client-operations.ts +220 -0
- package/packages/daemon-client/src/workspace-client-types.ts +302 -0
- package/packages/daemon-client/src/workspace-client.test.ts +2752 -0
- package/packages/daemon-client/src/workspace-client.ts +1452 -0
- package/packages/daemon-client/src/workspace-event-supervisor.test.ts +1086 -0
- package/packages/daemon-client/src/workspace-event-supervisor.ts +719 -0
- package/packages/daemon-client/src/workspace-pane-client.test.ts +80 -0
- package/packages/daemon-client/src/workspace-pane-client.ts +63 -0
- package/packages/presentation/package.json +28 -0
- package/packages/presentation/src/index.ts +2 -0
- package/packages/presentation/src/pane-frame/action-state.ts +72 -0
- package/packages/presentation/src/pane-frame/index.ts +3 -0
- package/packages/presentation/src/pane-frame/model.ts +517 -0
- package/packages/presentation/src/pane-frame/presenter.tsx +335 -0
- package/packages/presentation/src/pane-frame/web-entry.tsx +22 -0
- package/packages/presentation/src/pane-frame/web-host-unstyled.tsx +280 -0
- package/packages/presentation/src/pane-frame/web-host.css +388 -0
- package/packages/presentation/src/pane-frame/web-host.tsx +3 -0
- package/packages/presentation/src/presentation-contract.test.ts +63 -0
- package/packages/presentation/src/workbench-dock/index.ts +2 -0
- package/packages/presentation/src/workbench-dock/navigation.ts +54 -0
- package/packages/presentation/src/workbench-dock/presenter.tsx +252 -0
- package/packages/presentation/src/workbench-dock/web-entry.tsx +19 -0
- package/packages/presentation/src/workbench-dock/web-host-unstyled.tsx +198 -0
- package/packages/presentation/src/workbench-dock/web-host.css +204 -0
- package/packages/presentation/src/workbench-dock/web-host.tsx +3 -0
- package/packages/tmux-bridge/src/index.ts +9 -1
- package/packages/tmux-bridge/src/panes.ts +4 -0
- package/packages/tmux-bridge/src/runner.test.ts +72 -0
- package/packages/tmux-bridge/src/runner.ts +43 -2
- package/packages/tmux-bridge/src/sessions.ts +8 -1
- package/scripts/postinstall.js +57 -6
- package/skill/SKILL.md +27 -28
- package/templates/agent-team-monorepo.yml +28 -30
- package/templates/agent-team-nextjs.yml +24 -26
- package/templates/agent-team.yml +24 -24
- package/templates/convex.yml +24 -16
- package/templates/default.yml +26 -21
- package/templates/go.yml +21 -14
- package/templates/missions.yml +25 -40
- package/templates/nextjs.yml +24 -16
- package/templates/python.yml +21 -14
- package/templates/vite.yml +21 -14
- package/bin/cli.ts +0 -1773
- package/packages/daemon/dist/__tests__/support.d.ts +0 -7
- package/packages/daemon/dist/agent-explain.d.ts +0 -52
- package/packages/daemon/dist/attach.d.ts +0 -3
- package/packages/daemon/dist/bin.d.ts +0 -2
- package/packages/daemon/dist/canonical.d.ts +0 -2
- package/packages/daemon/dist/cli.d.ts +0 -1
- package/packages/daemon/dist/command-center/actions/contract.d.ts +0 -1
- package/packages/daemon/dist/command-center/actions/dispatcher.d.ts +0 -27
- package/packages/daemon/dist/command-center/actions/errors.d.ts +0 -38
- package/packages/daemon/dist/command-center/actions/handlers/_project-context.d.ts +0 -12
- package/packages/daemon/dist/command-center/actions/handlers/_resolve-project.d.ts +0 -42
- package/packages/daemon/dist/command-center/actions/handlers/app-set-remote-access.d.ts +0 -23
- package/packages/daemon/dist/command-center/actions/handlers/config-actions.d.ts +0 -12
- package/packages/daemon/dist/command-center/actions/handlers/daemon-shutdown.d.ts +0 -6
- package/packages/daemon/dist/command-center/actions/handlers/project-activate.d.ts +0 -7
- package/packages/daemon/dist/command-center/actions/handlers/project-launch.d.ts +0 -18
- package/packages/daemon/dist/command-center/actions/handlers/project-open-terminal.d.ts +0 -32
- package/packages/daemon/dist/command-center/actions/handlers/project-restart.d.ts +0 -17
- package/packages/daemon/dist/command-center/actions/handlers/project-stop.d.ts +0 -24
- package/packages/daemon/dist/command-center/actions/handlers/terminal-respawn.d.ts +0 -24
- package/packages/daemon/dist/command-center/actions/handlers/terminal-stop.d.ts +0 -14
- package/packages/daemon/dist/command-center/actions/registry.d.ts +0 -35
- package/packages/daemon/dist/command-center/discovery.d.ts +0 -23
- package/packages/daemon/dist/command-center/index.d.ts +0 -10
- package/packages/daemon/dist/command-center/schemas.d.ts +0 -76
- package/packages/daemon/dist/command-center/server.d.ts +0 -26
- package/packages/daemon/dist/command-center/ws-events.d.ts +0 -59
- package/packages/daemon/dist/config.d.ts +0 -19
- package/packages/daemon/dist/control/client.d.ts +0 -23
- package/packages/daemon/dist/control/dispatch.d.ts +0 -34
- package/packages/daemon/dist/control/fanout.d.ts +0 -19
- package/packages/daemon/dist/control/frames.d.ts +0 -23
- package/packages/daemon/dist/control/lifecycle.d.ts +0 -45
- package/packages/daemon/dist/control/server.d.ts +0 -16
- package/packages/daemon/dist/control/verbs.d.ts +0 -11
- package/packages/daemon/dist/detect.d.ts +0 -15
- package/packages/daemon/dist/doctor.d.ts +0 -39
- package/packages/daemon/dist/embed.d.ts +0 -1
- package/packages/daemon/dist/index.d.ts +0 -3
- package/packages/daemon/dist/init.d.ts +0 -4
- package/packages/daemon/dist/inspect.d.ts +0 -54
- package/packages/daemon/dist/launch.d.ts +0 -23
- package/packages/daemon/dist/lib/active-projects.d.ts +0 -12
- package/packages/daemon/dist/lib/agent-discovery.d.ts +0 -68
- package/packages/daemon/dist/lib/app-config.d.ts +0 -253
- package/packages/daemon/dist/lib/app-settings.d.ts +0 -9
- package/packages/daemon/dist/lib/auth/auth-service.d.ts +0 -33
- package/packages/daemon/dist/lib/auth/middleware.d.ts +0 -16
- package/packages/daemon/dist/lib/auth/types.d.ts +0 -1
- package/packages/daemon/dist/lib/auth-token.d.ts +0 -1
- package/packages/daemon/dist/lib/authorship.d.ts +0 -62
- package/packages/daemon/dist/lib/canonical-daemon.d.ts +0 -21
- package/packages/daemon/dist/lib/cli-action-bridge.d.ts +0 -27
- package/packages/daemon/dist/lib/daemon-embed.d.ts +0 -31
- package/packages/daemon/dist/lib/daemon-watchdog.d.ts +0 -16
- package/packages/daemon/dist/lib/daemon.d.ts +0 -8
- package/packages/daemon/dist/lib/dot-path.d.ts +0 -2
- package/packages/daemon/dist/lib/errors.d.ts +0 -37
- package/packages/daemon/dist/lib/filesystem-browser.d.ts +0 -85
- package/packages/daemon/dist/lib/launch-plan.d.ts +0 -6
- package/packages/daemon/dist/lib/log.d.ts +0 -40
- package/packages/daemon/dist/lib/manifest-pack.d.ts +0 -79
- package/packages/daemon/dist/lib/output.d.ts +0 -9
- package/packages/daemon/dist/lib/project-init-runner.d.ts +0 -46
- package/packages/daemon/dist/lib/project-inspect.d.ts +0 -28
- package/packages/daemon/dist/lib/project-onboard.d.ts +0 -58
- package/packages/daemon/dist/lib/project-probe.d.ts +0 -35
- package/packages/daemon/dist/lib/project-registry.d.ts +0 -76
- package/packages/daemon/dist/lib/session-monitor.d.ts +0 -15
- package/packages/daemon/dist/lib/session-options.d.ts +0 -13
- package/packages/daemon/dist/lib/shell.d.ts +0 -5
- package/packages/daemon/dist/lib/sizes.d.ts +0 -16
- package/packages/daemon/dist/lib/skill-sync.d.ts +0 -60
- package/packages/daemon/dist/lib/slugify.d.ts +0 -4
- package/packages/daemon/dist/lib/state-home.d.ts +0 -2
- package/packages/daemon/dist/lib/terminals-store.d.ts +0 -27
- package/packages/daemon/dist/lib/tui-binary.d.ts +0 -57
- package/packages/daemon/dist/lib/update-check.d.ts +0 -118
- package/packages/daemon/dist/lib/update.d.ts +0 -65
- package/packages/daemon/dist/lib/workspace-registry.d.ts +0 -84
- package/packages/daemon/dist/lib/worktree.d.ts +0 -76
- package/packages/daemon/dist/lib/yaml-io.d.ts +0 -10
- package/packages/daemon/dist/ls.d.ts +0 -3
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Info.plist +0 -34
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/MacOS/tmux-ide-notifier +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/PkgInfo +0 -1
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/AppIcon.icns +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/Resources/Assets.car +0 -0
- package/packages/daemon/dist/native/TmuxIdeNotifier.app/Contents/_CodeSignature/CodeResources +0 -139
- package/packages/daemon/dist/restart.d.ts +0 -4
- package/packages/daemon/dist/restore.d.ts +0 -113
- package/packages/daemon/dist/schemas/domain.d.ts +0 -1
- package/packages/daemon/dist/schemas/filesystem.d.ts +0 -29
- package/packages/daemon/dist/schemas/ide-config.d.ts +0 -1
- package/packages/daemon/dist/schemas/index.d.ts +0 -12
- package/packages/daemon/dist/schemas/inspect.d.ts +0 -53
- package/packages/daemon/dist/schemas/registry.d.ts +0 -35
- package/packages/daemon/dist/schemas/ws-events.d.ts +0 -72
- package/packages/daemon/dist/send.d.ts +0 -59
- package/packages/daemon/dist/server/index.d.ts +0 -10
- package/packages/daemon/dist/server/pty-bridge.d.ts +0 -174
- package/packages/daemon/dist/server/ws-route.d.ts +0 -74
- package/packages/daemon/dist/status.d.ts +0 -3
- package/packages/daemon/dist/stop.d.ts +0 -3
- package/packages/daemon/dist/terminal/NodePtyAdapter.d.ts +0 -44
- package/packages/daemon/dist/terminal/PtyAdapter.d.ts +0 -124
- package/packages/daemon/dist/terminal/__tests__/MockPtyAdapter.d.ts +0 -77
- package/packages/daemon/dist/types.d.ts +0 -2
- package/packages/daemon/dist/validate.d.ts +0 -4
- package/packages/daemon/dist/widgets/changes/index.jsx +0 -575
- package/packages/daemon/dist/widgets/config/index.d.ts +0 -1
- package/packages/daemon/dist/widgets/config/index.jsx +0 -395
- package/packages/daemon/dist/widgets/explorer/breadcrumbs.d.ts +0 -10
- package/packages/daemon/dist/widgets/explorer/breadcrumbs.jsx +0 -51
- package/packages/daemon/dist/widgets/explorer/footer.d.ts +0 -6
- package/packages/daemon/dist/widgets/explorer/footer.jsx +0 -11
- package/packages/daemon/dist/widgets/explorer/index.jsx +0 -393
- package/packages/daemon/dist/widgets/explorer/tree-model.d.ts +0 -13
- package/packages/daemon/dist/widgets/explorer/tree.d.ts +0 -13
- package/packages/daemon/dist/widgets/explorer/tree.jsx +0 -108
- package/packages/daemon/dist/widgets/lib/config-model.d.ts +0 -22
- package/packages/daemon/dist/widgets/lib/files.d.ts +0 -11
- package/packages/daemon/dist/widgets/lib/git.d.ts +0 -11
- package/packages/daemon/dist/widgets/lib/grammar.d.ts +0 -79
- package/packages/daemon/dist/widgets/lib/help-overlay.d.ts +0 -19
- package/packages/daemon/dist/widgets/lib/help-overlay.jsx +0 -69
- package/packages/daemon/dist/widgets/lib/pane-comms.d.ts +0 -28
- package/packages/daemon/dist/widgets/lib/theme.d.ts +0 -44
- package/packages/daemon/dist/widgets/lib/watcher.d.ts +0 -9
- package/packages/daemon/dist/widgets/preview/index.jsx +0 -371
- package/packages/daemon/dist/widgets/resolve.d.ts +0 -20
- package/packages/daemon/dist/widgets/setup/agent-naming.d.ts +0 -9
- package/packages/daemon/dist/widgets/setup/agent-naming.jsx +0 -81
- package/packages/daemon/dist/widgets/setup/config-tree.d.ts +0 -13
- package/packages/daemon/dist/widgets/setup/config-tree.jsx +0 -203
- package/packages/daemon/dist/widgets/setup/detect-panel.d.ts +0 -14
- package/packages/daemon/dist/widgets/setup/detect-panel.jsx +0 -48
- package/packages/daemon/dist/widgets/setup/field-editor.d.ts +0 -12
- package/packages/daemon/dist/widgets/setup/field-editor.jsx +0 -163
- package/packages/daemon/dist/widgets/setup/footer.d.ts +0 -17
- package/packages/daemon/dist/widgets/setup/footer.jsx +0 -64
- package/packages/daemon/dist/widgets/setup/index.d.ts +0 -1
- package/packages/daemon/dist/widgets/setup/index.jsx +0 -261
- package/packages/daemon/dist/widgets/setup/layout-picker.d.ts +0 -9
- package/packages/daemon/dist/widgets/setup/layout-picker.jsx +0 -69
- package/packages/daemon/dist/widgets/setup/setup-model.d.ts +0 -15
- package/packages/daemon/dist/widgets/sidebar/index.jsx +0 -462
- package/packages/daemon/src/tui/mirror/control-client.ts +0 -214
- package/packages/daemon/src/tui/mirror/control.ts +0 -97
- package/packages/daemon/src/tui/mirror/focus-border.ts +0 -57
- package/packages/daemon/src/tui/mirror/host-terminal.ts +0 -49
- package/packages/daemon/src/tui/mirror/input-coalescer.ts +0 -105
- package/packages/daemon/src/tui/mirror/session-mirror.ts +0 -724
- package/packages/daemon/src/widgets/setup/orchestrator-panel.tsx +0 -200
- package/scripts/build-cli.mjs +0 -101
- package/scripts/build-macos-notifier.mjs +0 -160
- package/scripts/build-tui.mjs +0 -65
- package/scripts/capture-codex-traffic.mjs +0 -195
- package/scripts/check-src-additions.sh +0 -74
- package/scripts/coverage-summary.mjs +0 -68
- package/scripts/install-git-hooks.js +0 -53
- package/scripts/merge-update-manifests.mjs +0 -58
- package/scripts/merge-update-manifests.test.mjs +0 -82
- package/scripts/pack-check-run.mjs +0 -83
- package/scripts/perf-mirror.mjs +0 -313
- package/scripts/prepublish-check.mjs +0 -80
- package/scripts/publish-tap.sh +0 -55
- package/scripts/stress-test.ts +0 -141
- package/scripts/verify-endpoints.sh +0 -90
- /package/packages/daemon/dist/{server/standalone.d.ts → terminal/mirror/events.js} +0 -0
- /package/packages/daemon/dist/{widgets/changes/index.d.ts → terminal/mirror/trusted-inventory.js} +0 -0
- /package/packages/daemon/dist/{widgets/explorer/index.d.ts → terminal/session-runtime/terminal-interpreter-backend.js} +0 -0
- /package/packages/daemon/dist/{widgets/preview/index.d.ts → tui/mirror/features/changes/contract.js} +0 -0
- /package/packages/daemon/dist/{widgets/sidebar/index.d.ts → tui/mirror/features/dialogs/contract.js} +0 -0
- /package/packages/daemon/src/{tui/mirror → terminal/protocol}/layout-parse.ts +0 -0
|
@@ -0,0 +1,2324 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_RETAINED_NATIVE_BACKING_BYTES,
|
|
3
|
+
takeNativeSeedBacking,
|
|
4
|
+
type VerifiedNativeSeedBacking,
|
|
5
|
+
type NativeBackingIdentity,
|
|
6
|
+
type RetainedNativeBackingResult,
|
|
7
|
+
} from "./native-seed-backing.ts";
|
|
8
|
+
import {
|
|
9
|
+
TERMINAL_DELIVERY_PATCH_TO_SEED_BYTES,
|
|
10
|
+
TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES,
|
|
11
|
+
TerminalDeliveryEnvelopeSchemaZ,
|
|
12
|
+
TerminalDeliveryAckSchemaZ,
|
|
13
|
+
TerminalDeliveryNackSchemaZ,
|
|
14
|
+
TerminalDeliveryOfferSchemaZ,
|
|
15
|
+
TerminalDeliveryVisibilitySchemaZ,
|
|
16
|
+
type CanonicalTerminalReplicaUpdate,
|
|
17
|
+
type SessionRuntimeGeneration,
|
|
18
|
+
type TerminalDeliveryAck,
|
|
19
|
+
type TerminalDeliveryEnvelope,
|
|
20
|
+
type TerminalDeliveryNack,
|
|
21
|
+
type TerminalDeliveryNegotiationResult,
|
|
22
|
+
type TerminalDeliveryOffer,
|
|
23
|
+
type TerminalDeliveryServerMessage,
|
|
24
|
+
type TerminalDeliveryVisibility,
|
|
25
|
+
type TerminalReplicaSnapshot,
|
|
26
|
+
type TerminalSemanticDeliveryPayload,
|
|
27
|
+
} from "@tmux-ide/contracts";
|
|
28
|
+
import {
|
|
29
|
+
TerminalDeliveryStateTooLargeError,
|
|
30
|
+
applyTerminalReplicaUpdate,
|
|
31
|
+
applyTerminalReplicaUpdateCooperatively,
|
|
32
|
+
terminalReplicaUpdateNeedsCooperativeReduction,
|
|
33
|
+
encodeCompactSemanticTerminalUpdate,
|
|
34
|
+
encodeCompactSemanticTerminalUpdateCooperatively,
|
|
35
|
+
terminalSemanticUpdateNeedsCooperativeEncoding,
|
|
36
|
+
encodeAnsiTerminalRepresentation,
|
|
37
|
+
encodeSemanticTerminalUpdate,
|
|
38
|
+
hashTerminalDeliveryRepresentation,
|
|
39
|
+
negotiateTerminalDelivery,
|
|
40
|
+
preaccountSemanticTerminalUpdateBytes,
|
|
41
|
+
type TerminalReplicaState,
|
|
42
|
+
} from "@tmux-ide/core";
|
|
43
|
+
import type {
|
|
44
|
+
TerminalReplicaCommittedRaw,
|
|
45
|
+
TerminalReplicaSourceSubscription,
|
|
46
|
+
} from "./terminal-replica-owner.ts";
|
|
47
|
+
import {
|
|
48
|
+
SYSTEM_SESSION_RUNTIME_SCHEDULER,
|
|
49
|
+
type SessionRuntimeScheduler,
|
|
50
|
+
type SessionRuntimeTimer,
|
|
51
|
+
} from "./runtime-scheduler.ts";
|
|
52
|
+
import {
|
|
53
|
+
DISABLED_SESSION_RUNTIME_OBSERVABILITY,
|
|
54
|
+
type SessionRuntimeObservability,
|
|
55
|
+
type SessionRuntimeTraceContext,
|
|
56
|
+
} from "./runtime-observability.ts";
|
|
57
|
+
import { registerTerminalDeliveryObservationOrdinal } from "./terminal-delivery-observation-identity.ts";
|
|
58
|
+
|
|
59
|
+
export const MAX_CANONICAL_REVISIONS = 128;
|
|
60
|
+
export const MAX_RAW_JOURNAL_BYTES = 4 * 1024 * 1024;
|
|
61
|
+
/** Eight workload conditioning revisions fill the cache before measured samples begin. */
|
|
62
|
+
export const MAX_REPRESENTATION_CACHE_ENTRIES = 8;
|
|
63
|
+
export const MAX_REPRESENTATION_CACHE_BYTES = 16 * 1024 * 1024;
|
|
64
|
+
export const MAX_CLIENTS = 64;
|
|
65
|
+
const MAX_PANES = 32;
|
|
66
|
+
const MAX_PENDING_CANONICAL_CELLS = 1_000_000;
|
|
67
|
+
const MAX_CONNECTIONS = MAX_CLIENTS * MAX_PANES;
|
|
68
|
+
const BACKGROUND_CADENCE_MS = 100;
|
|
69
|
+
|
|
70
|
+
export interface TerminalDeliveryMetrics {
|
|
71
|
+
/** Unique delivery subscribers, independent of their pane count. */
|
|
72
|
+
readonly clients: number;
|
|
73
|
+
readonly connections: number;
|
|
74
|
+
readonly inFlight: number;
|
|
75
|
+
readonly latestPointers: number;
|
|
76
|
+
readonly coalesced: number;
|
|
77
|
+
readonly reseeds: number;
|
|
78
|
+
readonly nacks: number;
|
|
79
|
+
readonly representationCacheBytes: number;
|
|
80
|
+
readonly rawJournalBytes: number;
|
|
81
|
+
/** Canonical snapshots reachable by current delivery baselines and transactions. */
|
|
82
|
+
readonly canonicalRevisions: number;
|
|
83
|
+
/** Encoded payload bytes plus metadata for retained native backing, not RSS. */
|
|
84
|
+
readonly nativeBackingBytes: number;
|
|
85
|
+
readonly maxSlowClientMs: number;
|
|
86
|
+
readonly queueDepth: number;
|
|
87
|
+
readonly maxQueueDepth: number;
|
|
88
|
+
readonly inFlightBytes: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface TerminalDeliveryConvergenceSnapshot {
|
|
92
|
+
readonly panes: readonly {
|
|
93
|
+
readonly semanticPaneId: string;
|
|
94
|
+
readonly incarnation: string;
|
|
95
|
+
readonly revision: number;
|
|
96
|
+
readonly stateHash: string;
|
|
97
|
+
}[];
|
|
98
|
+
readonly clients: readonly {
|
|
99
|
+
readonly clientId: string;
|
|
100
|
+
readonly semanticPaneId: string;
|
|
101
|
+
readonly visibility: TerminalDeliveryVisibility;
|
|
102
|
+
readonly baselineRevision: number;
|
|
103
|
+
readonly baselineHash: string | null;
|
|
104
|
+
readonly inFlightRevision: number | null;
|
|
105
|
+
readonly latestRevision: number | null;
|
|
106
|
+
readonly queueDepth: number;
|
|
107
|
+
}[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface TerminalDeliveryConnection {
|
|
111
|
+
/** Local lifecycle notification; sink failure requires transport reconnection. */
|
|
112
|
+
readonly closed: Promise<"closed" | "sink-failed">;
|
|
113
|
+
readonly negotiation: TerminalDeliveryNegotiationResult;
|
|
114
|
+
ack(ack: TerminalDeliveryAck): void;
|
|
115
|
+
nack(nack: TerminalDeliveryNack): void;
|
|
116
|
+
setVisibility(visibility: TerminalDeliveryVisibility): void;
|
|
117
|
+
close(): Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
interface NativeBackingLease {
|
|
121
|
+
backing: VerifiedNativeSeedBacking | null;
|
|
122
|
+
committed: boolean;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface RevisionRecord {
|
|
126
|
+
readonly nativeBacking: NativeBackingLease | null;
|
|
127
|
+
readonly update: CanonicalTerminalReplicaUpdate;
|
|
128
|
+
readonly state: TerminalReplicaState;
|
|
129
|
+
readonly trace: SessionRuntimeTraceContext | null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
interface PendingCanonicalUpdate {
|
|
133
|
+
readonly nativeBacking: NativeBackingLease | null;
|
|
134
|
+
readonly cells: number;
|
|
135
|
+
readonly update: CanonicalTerminalReplicaUpdate;
|
|
136
|
+
readonly trace: SessionRuntimeTraceContext | null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
interface PaneState {
|
|
140
|
+
readonly owner: TerminalDeliverySourceOwner;
|
|
141
|
+
source: TerminalReplicaSourceSubscription | null;
|
|
142
|
+
start: Promise<void>;
|
|
143
|
+
current: TerminalReplicaState | null;
|
|
144
|
+
latest: RevisionRecord | null;
|
|
145
|
+
readonly revisions: Map<number, RevisionRecord>;
|
|
146
|
+
readonly raw: Map<number, Uint8Array>;
|
|
147
|
+
rawBytes: number;
|
|
148
|
+
rawFloorRevision: number;
|
|
149
|
+
lastRawRevision: number;
|
|
150
|
+
readonly pendingCanonical: PendingCanonicalUpdate[];
|
|
151
|
+
activeNativeBacking: NativeBackingLease | null;
|
|
152
|
+
pendingCanonicalCells: number;
|
|
153
|
+
canonicalScheduled: boolean;
|
|
154
|
+
readonly canonicalAbort: AbortController;
|
|
155
|
+
canonicalYieldStartedAt: number;
|
|
156
|
+
pendingDeliveryTrace: SessionRuntimeTraceContext | null;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export interface TerminalDeliverySourceOwner {
|
|
160
|
+
subscribeSource(
|
|
161
|
+
listener: (
|
|
162
|
+
update: CanonicalTerminalReplicaUpdate,
|
|
163
|
+
trace: SessionRuntimeTraceContext | null,
|
|
164
|
+
) => void,
|
|
165
|
+
onRaw: (record: TerminalReplicaCommittedRaw) => void,
|
|
166
|
+
): Promise<TerminalReplicaSourceSubscription>;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface ClientState {
|
|
170
|
+
readonly key: string;
|
|
171
|
+
readonly clientId: string;
|
|
172
|
+
readonly diagnosticClientId: string;
|
|
173
|
+
readonly diagnosticSurface: string;
|
|
174
|
+
readonly diagnosticLaneId: string;
|
|
175
|
+
readonly diagnosticRequestId: string;
|
|
176
|
+
readonly paneId: string;
|
|
177
|
+
readonly negotiated: Extract<TerminalDeliveryNegotiationResult, { accepted: true }>["negotiated"];
|
|
178
|
+
readonly accept: (message: TerminalDeliveryServerMessage) => void | Promise<void>;
|
|
179
|
+
visibility: TerminalDeliveryVisibility;
|
|
180
|
+
baselineRevision: number;
|
|
181
|
+
baselineHash: string | null;
|
|
182
|
+
reseedRequired: boolean;
|
|
183
|
+
inFlight: {
|
|
184
|
+
envelope: TerminalDeliveryEnvelope;
|
|
185
|
+
deliveryOrdinal: number;
|
|
186
|
+
bytes: Uint8Array;
|
|
187
|
+
nextChunk: number;
|
|
188
|
+
sentAt: number;
|
|
189
|
+
} | null;
|
|
190
|
+
latestRevision: number | null;
|
|
191
|
+
encoding: PendingClientEncoding | null;
|
|
192
|
+
scheduled: boolean;
|
|
193
|
+
closed: boolean;
|
|
194
|
+
lifecycleOpenRecorded: boolean;
|
|
195
|
+
readonly resolveClosed: (reason: "closed" | "sink-failed") => void;
|
|
196
|
+
readonly outgoing: Array<() => TerminalDeliveryServerMessage>;
|
|
197
|
+
sending: boolean;
|
|
198
|
+
retireAfterDrain: boolean;
|
|
199
|
+
lastAck: TerminalDeliveryAck | null;
|
|
200
|
+
/** Delivery displaced by authoritative source close; its racing ACK is benign. */
|
|
201
|
+
sourceClosedFlight: TerminalDeliveryEnvelope | null;
|
|
202
|
+
backgroundTimer: SessionRuntimeTimer | null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
type SeedEncodingOutcome = { readonly bytes: Uint8Array } | { readonly error: unknown };
|
|
206
|
+
interface PendingSeedEncoding {
|
|
207
|
+
readonly key: string;
|
|
208
|
+
readonly pane: PaneState;
|
|
209
|
+
readonly abort: AbortController;
|
|
210
|
+
readonly clients: Set<ClientState>;
|
|
211
|
+
yieldStartedAt: number;
|
|
212
|
+
}
|
|
213
|
+
interface PendingClientEncoding {
|
|
214
|
+
readonly job: PendingSeedEncoding;
|
|
215
|
+
readonly target: RevisionRecord;
|
|
216
|
+
readonly baselineRevision: number;
|
|
217
|
+
readonly baselineHash: string | null;
|
|
218
|
+
readonly reseedRequired: boolean;
|
|
219
|
+
readonly traceStarted: number;
|
|
220
|
+
}
|
|
221
|
+
class DeferredSeedEncoding extends Error {
|
|
222
|
+
constructor(readonly payload: TerminalSemanticDeliveryPayload) {
|
|
223
|
+
super("Deferred compact seed encoding");
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
interface CachedRepresentation {
|
|
228
|
+
readonly bytes: Uint8Array;
|
|
229
|
+
readonly encoding?: "semantic-v1" | "semantic-compact-v1";
|
|
230
|
+
readonly frame: "seed" | "patch" | "tombstone";
|
|
231
|
+
readonly canonicalEquivalent: boolean;
|
|
232
|
+
readonly history: "complete" | "truncated" | "not-applicable";
|
|
233
|
+
readonly representationHash?: string;
|
|
234
|
+
/** Internal reachability metadata; never serialized onto the wire. */
|
|
235
|
+
readonly cachePaneId?: string;
|
|
236
|
+
readonly cacheBaseRevision?: number;
|
|
237
|
+
readonly cacheTargetRevision?: number;
|
|
238
|
+
readonly selectionObservation?: Readonly<{
|
|
239
|
+
attemptedPatchBytes: number | null;
|
|
240
|
+
attemptedSeedBytes: number | null;
|
|
241
|
+
attemptedLegacyPatchBytes: number | null;
|
|
242
|
+
attemptedLegacySeedBytes: number | null;
|
|
243
|
+
attemptedLegacyPatchAtLeastBytes: number | null;
|
|
244
|
+
attemptedLegacySeedAtLeastBytes: number | null;
|
|
245
|
+
attemptedLegacyPatchSizeCapped: boolean;
|
|
246
|
+
attemptedLegacySeedSizeCapped: boolean;
|
|
247
|
+
attemptedCompactPatchBytes: number | null;
|
|
248
|
+
attemptedCompactSeedBytes: number | null;
|
|
249
|
+
selectedEncoding: "semantic-v1" | "semantic-compact-v1";
|
|
250
|
+
selectionStatus:
|
|
251
|
+
| "patch-preferred"
|
|
252
|
+
| "seed-preferred"
|
|
253
|
+
| "patch-fallback"
|
|
254
|
+
| "legacy-patch-fallback"
|
|
255
|
+
| "legacy-seed-fallback"
|
|
256
|
+
| "direct-seed"
|
|
257
|
+
| "direct-tombstone";
|
|
258
|
+
}>;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
type SemanticSelectionObservation = NonNullable<CachedRepresentation["selectionObservation"]>;
|
|
262
|
+
|
|
263
|
+
type ExactSemanticSelectionObservation = Pick<
|
|
264
|
+
SemanticSelectionObservation,
|
|
265
|
+
"attemptedPatchBytes" | "attemptedSeedBytes" | "selectionStatus"
|
|
266
|
+
>;
|
|
267
|
+
|
|
268
|
+
class ExactSemanticRepresentationSelectionError extends TerminalDeliveryStateTooLargeError {
|
|
269
|
+
readonly selectionObservation: ExactSemanticSelectionObservation;
|
|
270
|
+
|
|
271
|
+
constructor(bytes: number, selectionObservation: ExactSemanticSelectionObservation) {
|
|
272
|
+
super(bytes);
|
|
273
|
+
this.name = "ExactSemanticRepresentationSelectionError";
|
|
274
|
+
this.selectionObservation = selectionObservation;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
class TerminalDeliveryRepresentationSelectionError extends TerminalDeliveryStateTooLargeError {
|
|
279
|
+
readonly selectionObservation: SemanticSelectionObservation;
|
|
280
|
+
readonly sizeCapped: boolean;
|
|
281
|
+
readonly atLeastBytes: number | null;
|
|
282
|
+
|
|
283
|
+
constructor(bytes: number, selectionObservation: SemanticSelectionObservation) {
|
|
284
|
+
super(bytes);
|
|
285
|
+
this.name = "TerminalDeliveryRepresentationSelectionError";
|
|
286
|
+
this.selectionObservation = selectionObservation;
|
|
287
|
+
this.atLeastBytes =
|
|
288
|
+
selectionObservation.attemptedLegacyPatchAtLeastBytes ??
|
|
289
|
+
selectionObservation.attemptedLegacySeedAtLeastBytes;
|
|
290
|
+
this.sizeCapped = this.atLeastBytes !== null;
|
|
291
|
+
if (this.atLeastBytes !== null)
|
|
292
|
+
this.message = `Terminal delivery representation is at least ${this.atLeastBytes} bytes; maximum is ${TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES}`;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
class TerminalDeliveryPreaccountLimitError extends TerminalDeliveryStateTooLargeError {
|
|
297
|
+
readonly atLeastBytes: number;
|
|
298
|
+
readonly sizeCapped = true;
|
|
299
|
+
|
|
300
|
+
constructor(atLeastBytes: number) {
|
|
301
|
+
super(atLeastBytes);
|
|
302
|
+
this.name = "TerminalDeliveryPreaccountLimitError";
|
|
303
|
+
this.message = `Terminal delivery representation is at least ${atLeastBytes} bytes; maximum is ${TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES}`;
|
|
304
|
+
this.atLeastBytes = atLeastBytes;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
/** One bounded, renderer-independent delivery coordinator per SessionRuntime. */
|
|
309
|
+
export class SessionRuntimeTerminalDeliveryHub {
|
|
310
|
+
readonly #ownerForPane: (semanticPaneId: string) => TerminalDeliverySourceOwner;
|
|
311
|
+
readonly #scheduler: SessionRuntimeScheduler;
|
|
312
|
+
readonly #observability: SessionRuntimeObservability;
|
|
313
|
+
readonly #panes = new Map<string, PaneState>();
|
|
314
|
+
readonly #clients = new Map<string, ClientState>();
|
|
315
|
+
/** Synchronous reservations held while an async pane source is starting. */
|
|
316
|
+
readonly #pendingClients = new Map<string, string>();
|
|
317
|
+
readonly #cache = new Map<string, CachedRepresentation>();
|
|
318
|
+
readonly #pendingEncodings = new Map<string, PendingSeedEncoding>();
|
|
319
|
+
#cacheBytes = 0;
|
|
320
|
+
#nativeBackingBytes = 0;
|
|
321
|
+
#coalesced = 0;
|
|
322
|
+
#reseeds = 0;
|
|
323
|
+
#nacks = 0;
|
|
324
|
+
#maxSlowClientMs = 0;
|
|
325
|
+
#maxQueueDepth = 0;
|
|
326
|
+
#deliveryOrdinal = 0;
|
|
327
|
+
#deliveryLifecycleOrdinal = 0;
|
|
328
|
+
#deliveryStatusOrdinal = 0;
|
|
329
|
+
#closed = false;
|
|
330
|
+
|
|
331
|
+
constructor(
|
|
332
|
+
readonly generation: SessionRuntimeGeneration,
|
|
333
|
+
readonly workspaceName: string,
|
|
334
|
+
ownerForPane: (semanticPaneId: string) => TerminalDeliverySourceOwner,
|
|
335
|
+
options: {
|
|
336
|
+
readonly scheduler?: SessionRuntimeScheduler;
|
|
337
|
+
readonly observability?: SessionRuntimeObservability;
|
|
338
|
+
} = {},
|
|
339
|
+
) {
|
|
340
|
+
this.#ownerForPane = ownerForPane;
|
|
341
|
+
this.#scheduler = options.scheduler ?? SYSTEM_SESSION_RUNTIME_SCHEDULER;
|
|
342
|
+
this.#observability = options.observability ?? DISABLED_SESSION_RUNTIME_OBSERVABILITY;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async open(
|
|
346
|
+
clientId: string,
|
|
347
|
+
semanticPaneId: string,
|
|
348
|
+
offerInput: TerminalDeliveryOffer,
|
|
349
|
+
accept: (message: TerminalDeliveryServerMessage) => void | Promise<void>,
|
|
350
|
+
diagnosticIdentity: Readonly<{
|
|
351
|
+
clientId: string;
|
|
352
|
+
surface: string;
|
|
353
|
+
laneId: string;
|
|
354
|
+
requestId?: string;
|
|
355
|
+
}> = Object.freeze({ clientId, surface: "direct", laneId: clientId }),
|
|
356
|
+
): Promise<TerminalDeliveryConnection> {
|
|
357
|
+
if (this.#closed) throw new Error("Terminal delivery hub is closed");
|
|
358
|
+
const offer = TerminalDeliveryOfferSchemaZ.parse(offerInput);
|
|
359
|
+
const negotiation = negotiateTerminalDelivery(
|
|
360
|
+
offer,
|
|
361
|
+
this.generation,
|
|
362
|
+
this.#scheduler.createId(),
|
|
363
|
+
);
|
|
364
|
+
if (!negotiation.accepted) return rejectedConnection(negotiation);
|
|
365
|
+
const key = cacheKey([clientId, semanticPaneId]);
|
|
366
|
+
if (this.#clients.has(key) || this.#pendingClients.has(key))
|
|
367
|
+
throw new TypeError("Terminal delivery already open for client/pane");
|
|
368
|
+
const uniqueClients = new Set([
|
|
369
|
+
...[...this.#clients.values()].map((client) => client.clientId),
|
|
370
|
+
...this.#pendingClients.values(),
|
|
371
|
+
]);
|
|
372
|
+
if (!uniqueClients.has(clientId) && uniqueClients.size >= MAX_CLIENTS)
|
|
373
|
+
throw new Error("Terminal delivery client limit reached");
|
|
374
|
+
if (this.#clients.size + this.#pendingClients.size >= MAX_CONNECTIONS)
|
|
375
|
+
throw new Error("Terminal delivery connection limit reached");
|
|
376
|
+
|
|
377
|
+
// Reserve before the first await. Without this reservation, a burst of
|
|
378
|
+
// concurrent opens can all pass the capacity precheck while ensurePane is
|
|
379
|
+
// awaiting the source and oversubscribe the hub together afterwards.
|
|
380
|
+
this.#pendingClients.set(key, clientId);
|
|
381
|
+
try {
|
|
382
|
+
const pane = await this.#ensurePane(semanticPaneId);
|
|
383
|
+
if (this.#closed) throw new Error("Terminal delivery hub is closed");
|
|
384
|
+
let resolveClosed!: (reason: "closed" | "sink-failed") => void;
|
|
385
|
+
const closed = new Promise<"closed" | "sink-failed">((resolve) => {
|
|
386
|
+
resolveClosed = resolve;
|
|
387
|
+
});
|
|
388
|
+
const client: ClientState = {
|
|
389
|
+
key,
|
|
390
|
+
clientId,
|
|
391
|
+
diagnosticClientId: diagnosticIdentity.clientId,
|
|
392
|
+
diagnosticSurface: diagnosticIdentity.surface,
|
|
393
|
+
diagnosticLaneId: diagnosticIdentity.laneId,
|
|
394
|
+
diagnosticRequestId: diagnosticIdentity.requestId ?? diagnosticIdentity.laneId,
|
|
395
|
+
paneId: semanticPaneId,
|
|
396
|
+
negotiated: negotiation.negotiated,
|
|
397
|
+
accept,
|
|
398
|
+
visibility: "visible",
|
|
399
|
+
baselineRevision: -1,
|
|
400
|
+
baselineHash: null,
|
|
401
|
+
reseedRequired: false,
|
|
402
|
+
inFlight: null,
|
|
403
|
+
latestRevision: pane.latest?.update.revision ?? null,
|
|
404
|
+
encoding: null,
|
|
405
|
+
scheduled: false,
|
|
406
|
+
closed: false,
|
|
407
|
+
lifecycleOpenRecorded: false,
|
|
408
|
+
resolveClosed,
|
|
409
|
+
outgoing: [],
|
|
410
|
+
sending: false,
|
|
411
|
+
retireAfterDrain: false,
|
|
412
|
+
lastAck: null,
|
|
413
|
+
sourceClosedFlight: null,
|
|
414
|
+
backgroundTimer: null,
|
|
415
|
+
};
|
|
416
|
+
this.#clients.set(key, client);
|
|
417
|
+
client.lifecycleOpenRecorded = this.#recordDeliveryLifecycle(client, pane, "open");
|
|
418
|
+
this.#schedule(client);
|
|
419
|
+
this.#recordDeliveryStatus(client, pane);
|
|
420
|
+
return {
|
|
421
|
+
negotiation,
|
|
422
|
+
closed,
|
|
423
|
+
ack: (ack) => this.#ack(client, ack),
|
|
424
|
+
nack: (nack) => this.#nack(client, nack),
|
|
425
|
+
setVisibility: (visibilityInput) => {
|
|
426
|
+
if (client.closed) return;
|
|
427
|
+
client.visibility = TerminalDeliveryVisibilitySchemaZ.parse(visibilityInput);
|
|
428
|
+
if (client.visibility === "hidden" || client.visibility === "frozen")
|
|
429
|
+
this.#cancelEncoding(client);
|
|
430
|
+
if (client.visibility === "visible" || client.visibility === "background")
|
|
431
|
+
this.#schedule(client);
|
|
432
|
+
this.#recordDeliveryStatus(client, this.#panes.get(client.paneId));
|
|
433
|
+
},
|
|
434
|
+
close: async () => this.#closeClient(client),
|
|
435
|
+
};
|
|
436
|
+
} finally {
|
|
437
|
+
this.#pendingClients.delete(key);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
retainedNativeBacking(
|
|
442
|
+
paneId: string,
|
|
443
|
+
expected: NativeBackingIdentity,
|
|
444
|
+
): RetainedNativeBackingResult | null {
|
|
445
|
+
const pane = this.#panes.get(paneId);
|
|
446
|
+
const record = pane?.revisions.get(expected.revision);
|
|
447
|
+
const lease = record?.nativeBacking;
|
|
448
|
+
const backing = lease?.backing;
|
|
449
|
+
if (
|
|
450
|
+
this.#closed ||
|
|
451
|
+
!pane ||
|
|
452
|
+
!record ||
|
|
453
|
+
!backing ||
|
|
454
|
+
expected.generation !== this.generation ||
|
|
455
|
+
record.update.incarnation !== expected.incarnation ||
|
|
456
|
+
record.update.stateHash !== expected.stateHash
|
|
457
|
+
)
|
|
458
|
+
return null;
|
|
459
|
+
return {
|
|
460
|
+
status: "retained",
|
|
461
|
+
encodeBody: (prefix) => {
|
|
462
|
+
const encoded = lease.backing?.encoded;
|
|
463
|
+
if (!encoded) throw new Error("Native backing revision was retired");
|
|
464
|
+
const body = new Uint8Array(prefix.byteLength + encoded.byteLength);
|
|
465
|
+
body.set(prefix);
|
|
466
|
+
body.set(encoded, prefix.byteLength);
|
|
467
|
+
return body;
|
|
468
|
+
},
|
|
469
|
+
authority: {
|
|
470
|
+
generation: this.generation,
|
|
471
|
+
workspaceName: this.workspaceName,
|
|
472
|
+
semanticPaneId: paneId,
|
|
473
|
+
incarnation: expected.incarnation,
|
|
474
|
+
revision: expected.revision,
|
|
475
|
+
stateHash: expected.stateHash,
|
|
476
|
+
},
|
|
477
|
+
isCurrent: () =>
|
|
478
|
+
!this.#closed &&
|
|
479
|
+
this.#panes.get(paneId) === pane &&
|
|
480
|
+
pane.revisions.get(expected.revision) === record &&
|
|
481
|
+
lease.backing !== null,
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
#releaseNativeBacking(lease: NativeBackingLease | null | undefined): void {
|
|
486
|
+
if (!lease?.backing) return;
|
|
487
|
+
this.#nativeBackingBytes -= lease.backing.chargedBytes;
|
|
488
|
+
lease.backing = null;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
#clearPendingNativeBacking(pane: PaneState): void {
|
|
492
|
+
for (const pending of pane.pendingCanonical) this.#releaseNativeBacking(pending.nativeBacking);
|
|
493
|
+
if (!pane.activeNativeBacking?.committed) this.#releaseNativeBacking(pane.activeNativeBacking);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
#clearRetainedNativeBacking(pane: PaneState): void {
|
|
497
|
+
for (const record of pane.revisions.values()) this.#releaseNativeBacking(record.nativeBacking);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
metrics(): TerminalDeliveryMetrics {
|
|
501
|
+
const now = this.#scheduler.nowMs();
|
|
502
|
+
const currentSlow = [...this.#clients.values()].reduce(
|
|
503
|
+
(max, client) => Math.max(max, client.inFlight ? now - client.inFlight.sentAt : 0),
|
|
504
|
+
0,
|
|
505
|
+
);
|
|
506
|
+
return Object.freeze({
|
|
507
|
+
clients: new Set([...this.#clients.values()].map((client) => client.clientId)).size,
|
|
508
|
+
connections: this.#clients.size,
|
|
509
|
+
inFlight: [...this.#clients.values()].filter((client) => client.inFlight).length,
|
|
510
|
+
latestPointers: [...this.#clients.values()].filter((client) => client.latestRevision !== null)
|
|
511
|
+
.length,
|
|
512
|
+
coalesced: this.#coalesced,
|
|
513
|
+
reseeds: this.#reseeds,
|
|
514
|
+
nacks: this.#nacks,
|
|
515
|
+
canonicalRevisions: [...this.#panes.values()].reduce(
|
|
516
|
+
(sum, pane) => sum + pane.revisions.size,
|
|
517
|
+
0,
|
|
518
|
+
),
|
|
519
|
+
nativeBackingBytes: this.#nativeBackingBytes,
|
|
520
|
+
representationCacheBytes: this.#cacheBytes,
|
|
521
|
+
rawJournalBytes: [...this.#panes.values()].reduce((sum, pane) => sum + pane.rawBytes, 0),
|
|
522
|
+
maxSlowClientMs: Math.max(this.#maxSlowClientMs, currentSlow),
|
|
523
|
+
queueDepth: [...this.#clients.values()].reduce(
|
|
524
|
+
(sum, client) => sum + client.outgoing.length,
|
|
525
|
+
0,
|
|
526
|
+
),
|
|
527
|
+
maxQueueDepth: this.#maxQueueDepth,
|
|
528
|
+
inFlightBytes: [...this.#clients.values()].reduce(
|
|
529
|
+
(sum, client) => sum + (client.inFlight?.envelope.representationBytes ?? 0),
|
|
530
|
+
0,
|
|
531
|
+
),
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
convergenceSnapshot(): TerminalDeliveryConvergenceSnapshot {
|
|
536
|
+
return Object.freeze({
|
|
537
|
+
panes: Object.freeze(
|
|
538
|
+
[...this.#panes.entries()].flatMap(([semanticPaneId, pane]) =>
|
|
539
|
+
pane.latest
|
|
540
|
+
? [
|
|
541
|
+
Object.freeze({
|
|
542
|
+
semanticPaneId,
|
|
543
|
+
incarnation: pane.latest.update.incarnation,
|
|
544
|
+
revision: pane.latest.update.revision,
|
|
545
|
+
stateHash: pane.latest.update.stateHash,
|
|
546
|
+
}),
|
|
547
|
+
]
|
|
548
|
+
: [],
|
|
549
|
+
),
|
|
550
|
+
),
|
|
551
|
+
clients: Object.freeze(
|
|
552
|
+
[...this.#clients.values()].map((client) =>
|
|
553
|
+
Object.freeze({
|
|
554
|
+
clientId: client.clientId,
|
|
555
|
+
semanticPaneId: client.paneId,
|
|
556
|
+
visibility: client.visibility,
|
|
557
|
+
baselineRevision: client.baselineRevision,
|
|
558
|
+
baselineHash: client.baselineHash,
|
|
559
|
+
inFlightRevision: client.inFlight?.envelope.canonicalRevision ?? null,
|
|
560
|
+
latestRevision: client.latestRevision,
|
|
561
|
+
queueDepth: client.outgoing.length,
|
|
562
|
+
}),
|
|
563
|
+
),
|
|
564
|
+
),
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
async resetForSessionRestart(): Promise<void> {
|
|
569
|
+
for (const client of this.#clients.values()) {
|
|
570
|
+
this.#cancelEncoding(client);
|
|
571
|
+
client.outgoing.length = 0;
|
|
572
|
+
client.inFlight = null;
|
|
573
|
+
this.#enqueue(client, {
|
|
574
|
+
type: "terminal.delivery.fault",
|
|
575
|
+
reason: "source-closed",
|
|
576
|
+
message: "Terminal source restarted",
|
|
577
|
+
deliveryNonce: client.negotiated.deliveryNonce,
|
|
578
|
+
});
|
|
579
|
+
client.retireAfterDrain = true;
|
|
580
|
+
}
|
|
581
|
+
const panes = [...this.#panes.values()];
|
|
582
|
+
this.#panes.clear();
|
|
583
|
+
for (const pane of panes) {
|
|
584
|
+
this.#clearRetainedNativeBacking(pane);
|
|
585
|
+
pane.canonicalAbort.abort();
|
|
586
|
+
this.#clearPendingNativeBacking(pane);
|
|
587
|
+
pane.pendingCanonical.length = 0;
|
|
588
|
+
pane.pendingCanonicalCells = 0;
|
|
589
|
+
pane.canonicalScheduled = false;
|
|
590
|
+
}
|
|
591
|
+
await Promise.allSettled(panes.map((pane) => pane.source?.close()));
|
|
592
|
+
this.#clearCache();
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
async close(): Promise<void> {
|
|
596
|
+
if (this.#closed) return;
|
|
597
|
+
this.#closed = true;
|
|
598
|
+
await this.resetForSessionRestart();
|
|
599
|
+
await Promise.allSettled(
|
|
600
|
+
[...this.#clients.values()].map((client) => this.#closeClient(client)),
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
async #ensurePane(semanticPaneId: string): Promise<PaneState> {
|
|
605
|
+
let pane = this.#panes.get(semanticPaneId);
|
|
606
|
+
if (pane) {
|
|
607
|
+
await pane.start;
|
|
608
|
+
return pane;
|
|
609
|
+
}
|
|
610
|
+
if (this.#panes.size >= MAX_PANES) throw new Error("Terminal delivery pane limit reached");
|
|
611
|
+
const owner = this.#ownerForPane(semanticPaneId);
|
|
612
|
+
pane = {
|
|
613
|
+
owner,
|
|
614
|
+
source: null,
|
|
615
|
+
start: Promise.resolve(),
|
|
616
|
+
current: null,
|
|
617
|
+
latest: null,
|
|
618
|
+
revisions: new Map(),
|
|
619
|
+
raw: new Map(),
|
|
620
|
+
rawBytes: 0,
|
|
621
|
+
rawFloorRevision: 0,
|
|
622
|
+
lastRawRevision: -1,
|
|
623
|
+
pendingCanonical: [],
|
|
624
|
+
activeNativeBacking: null,
|
|
625
|
+
pendingCanonicalCells: 0,
|
|
626
|
+
canonicalScheduled: false,
|
|
627
|
+
canonicalAbort: new AbortController(),
|
|
628
|
+
canonicalYieldStartedAt: -Infinity,
|
|
629
|
+
pendingDeliveryTrace: null,
|
|
630
|
+
};
|
|
631
|
+
this.#panes.set(semanticPaneId, pane);
|
|
632
|
+
pane.start = owner
|
|
633
|
+
.subscribeSource(
|
|
634
|
+
(update, trace) => {
|
|
635
|
+
if (this.#panes.get(semanticPaneId) === pane)
|
|
636
|
+
this.#observeCanonical(semanticPaneId, update, trace);
|
|
637
|
+
else if (update.type === "terminal.seed") takeNativeSeedBacking(update.snapshot);
|
|
638
|
+
},
|
|
639
|
+
(record) => {
|
|
640
|
+
if (this.#panes.get(semanticPaneId) === pane) this.#observeRaw(semanticPaneId, record);
|
|
641
|
+
},
|
|
642
|
+
)
|
|
643
|
+
.then(async (source) => {
|
|
644
|
+
if (
|
|
645
|
+
this.#closed ||
|
|
646
|
+
this.#panes.get(semanticPaneId) !== pane ||
|
|
647
|
+
pane?.canonicalAbort.signal.aborted
|
|
648
|
+
) {
|
|
649
|
+
await source.close();
|
|
650
|
+
throw new Error("Terminal delivery source retired during startup");
|
|
651
|
+
}
|
|
652
|
+
pane!.source = source;
|
|
653
|
+
})
|
|
654
|
+
.catch((error) => {
|
|
655
|
+
if (this.#panes.get(semanticPaneId) === pane) {
|
|
656
|
+
this.#panes.delete(semanticPaneId);
|
|
657
|
+
this.#clearPendingNativeBacking(pane!);
|
|
658
|
+
this.#clearRetainedNativeBacking(pane!);
|
|
659
|
+
}
|
|
660
|
+
throw error;
|
|
661
|
+
});
|
|
662
|
+
await pane.start;
|
|
663
|
+
return pane;
|
|
664
|
+
}
|
|
665
|
+
|
|
666
|
+
#observeCanonical(
|
|
667
|
+
semanticPaneId: string,
|
|
668
|
+
update: CanonicalTerminalReplicaUpdate,
|
|
669
|
+
trace: SessionRuntimeTraceContext | null,
|
|
670
|
+
): void {
|
|
671
|
+
// Consume even rejected source updates; an uncharged handoff must not
|
|
672
|
+
// linger behind a still-reachable canonical snapshot.
|
|
673
|
+
const backing =
|
|
674
|
+
update.type === "terminal.seed" ? takeNativeSeedBacking(update.snapshot) : undefined;
|
|
675
|
+
const pane = this.#panes.get(semanticPaneId);
|
|
676
|
+
if (!pane || pane.canonicalAbort.signal.aborted || this.#closed) return;
|
|
677
|
+
if (
|
|
678
|
+
update.workspaceName !== this.workspaceName ||
|
|
679
|
+
update.semanticPaneId !== semanticPaneId ||
|
|
680
|
+
update.generation !== this.generation
|
|
681
|
+
)
|
|
682
|
+
return;
|
|
683
|
+
const cells = canonicalUpdateCellCost(update);
|
|
684
|
+
// A single authoritative state retains its existing representation limits
|
|
685
|
+
// (including legacy fallback); this budget limits additional queued work.
|
|
686
|
+
if (
|
|
687
|
+
!Number.isSafeInteger(cells) ||
|
|
688
|
+
cells < 0 ||
|
|
689
|
+
pane.pendingCanonical.length >= MAX_CANONICAL_REVISIONS ||
|
|
690
|
+
(pane.pendingCanonical.length > 0 &&
|
|
691
|
+
cells > MAX_PENDING_CANONICAL_CELLS - pane.pendingCanonicalCells)
|
|
692
|
+
) {
|
|
693
|
+
pane.canonicalAbort.abort();
|
|
694
|
+
this.#clearPendingNativeBacking(pane);
|
|
695
|
+
pane.pendingCanonical.length = 0;
|
|
696
|
+
pane.pendingCanonicalCells = 0;
|
|
697
|
+
for (const client of this.#clients.values())
|
|
698
|
+
if (client.paneId === semanticPaneId && !client.closed)
|
|
699
|
+
this.#fault(
|
|
700
|
+
client,
|
|
701
|
+
"state-too-large",
|
|
702
|
+
"Terminal source exceeded the pending update budget; reopen for a fresh snapshot",
|
|
703
|
+
);
|
|
704
|
+
return;
|
|
705
|
+
}
|
|
706
|
+
const nativeBacking: NativeBackingLease | null =
|
|
707
|
+
backing &&
|
|
708
|
+
backing.chargedBytes <= MAX_RETAINED_NATIVE_BACKING_BYTES - this.#nativeBackingBytes
|
|
709
|
+
? { backing, committed: false }
|
|
710
|
+
: null;
|
|
711
|
+
if (nativeBacking) this.#nativeBackingBytes += backing!.chargedBytes;
|
|
712
|
+
pane.pendingCanonical.push({ update, trace, cells, nativeBacking });
|
|
713
|
+
pane.pendingCanonicalCells += cells;
|
|
714
|
+
if (pane.canonicalScheduled) return;
|
|
715
|
+
pane.canonicalScheduled = true;
|
|
716
|
+
this.#scheduler.microtask(() => {
|
|
717
|
+
void this.#drainCanonical(semanticPaneId, pane);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
async #drainCanonical(semanticPaneId: string, pane: PaneState): Promise<void> {
|
|
722
|
+
try {
|
|
723
|
+
while (
|
|
724
|
+
!this.#closed &&
|
|
725
|
+
this.#panes.get(semanticPaneId) === pane &&
|
|
726
|
+
!pane.canonicalAbort.signal.aborted
|
|
727
|
+
) {
|
|
728
|
+
const pending = pane.pendingCanonical.shift();
|
|
729
|
+
if (!pending) break;
|
|
730
|
+
pane.pendingCanonicalCells -= pending.cells;
|
|
731
|
+
pane.activeNativeBacking = pending.nativeBacking;
|
|
732
|
+
try {
|
|
733
|
+
const work = this.#applyCanonical(
|
|
734
|
+
semanticPaneId,
|
|
735
|
+
pane,
|
|
736
|
+
pending.update,
|
|
737
|
+
pending.trace,
|
|
738
|
+
pending.nativeBacking,
|
|
739
|
+
);
|
|
740
|
+
// Keep the ordinary update burst synchronous; only large seeds yield.
|
|
741
|
+
if (work) await work;
|
|
742
|
+
} finally {
|
|
743
|
+
if (!pending.nativeBacking?.committed) this.#releaseNativeBacking(pending.nativeBacking);
|
|
744
|
+
pane.activeNativeBacking = null;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
} catch {
|
|
748
|
+
if (!pane.canonicalAbort.signal.aborted && this.#panes.get(semanticPaneId) === pane) {
|
|
749
|
+
pane.canonicalAbort.abort();
|
|
750
|
+
this.#clearPendingNativeBacking(pane);
|
|
751
|
+
pane.pendingCanonical.length = 0;
|
|
752
|
+
pane.pendingCanonicalCells = 0;
|
|
753
|
+
for (const client of this.#clients.values())
|
|
754
|
+
if (client.paneId === semanticPaneId && !client.closed)
|
|
755
|
+
this.#fault(
|
|
756
|
+
client,
|
|
757
|
+
"protocol-violation",
|
|
758
|
+
"Terminal source update could not be validated",
|
|
759
|
+
);
|
|
760
|
+
}
|
|
761
|
+
} finally {
|
|
762
|
+
pane.canonicalScheduled = false;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
#yieldCanonical(pane: PaneState): Promise<void> {
|
|
767
|
+
// Core checkpoints are finer than an event-loop turn. Preserve cancellation
|
|
768
|
+
// checks there without paying a timer tick for every 256 cells.
|
|
769
|
+
if (this.#scheduler.nowMs() - pane.canonicalYieldStartedAt < 2) return Promise.resolve();
|
|
770
|
+
return new Promise((resolve) => {
|
|
771
|
+
let timer: SessionRuntimeTimer | undefined;
|
|
772
|
+
const finish = () => {
|
|
773
|
+
timer?.cancel();
|
|
774
|
+
pane.canonicalYieldStartedAt = this.#scheduler.nowMs();
|
|
775
|
+
pane.canonicalAbort.signal.removeEventListener("abort", finish);
|
|
776
|
+
resolve();
|
|
777
|
+
};
|
|
778
|
+
pane.canonicalAbort.signal.addEventListener("abort", finish, { once: true });
|
|
779
|
+
if (pane.canonicalAbort.signal.aborted) finish();
|
|
780
|
+
else
|
|
781
|
+
timer = this.#scheduler.yieldTask
|
|
782
|
+
? this.#scheduler.yieldTask(finish)
|
|
783
|
+
: this.#scheduler.timer(finish, 0);
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
#applyCanonical(
|
|
788
|
+
semanticPaneId: string,
|
|
789
|
+
pane: PaneState,
|
|
790
|
+
update: CanonicalTerminalReplicaUpdate,
|
|
791
|
+
trace: SessionRuntimeTraceContext | null,
|
|
792
|
+
nativeBacking: NativeBackingLease | null,
|
|
793
|
+
): void | Promise<void> {
|
|
794
|
+
if (
|
|
795
|
+
update.workspaceName !== this.workspaceName ||
|
|
796
|
+
update.semanticPaneId !== semanticPaneId ||
|
|
797
|
+
update.generation !== this.generation
|
|
798
|
+
)
|
|
799
|
+
return;
|
|
800
|
+
if (terminalReplicaUpdateNeedsCooperativeReduction(update)) {
|
|
801
|
+
const baseline = pane.current;
|
|
802
|
+
pane.canonicalYieldStartedAt = -Infinity;
|
|
803
|
+
return applyTerminalReplicaUpdateCooperatively(baseline, update, {
|
|
804
|
+
yieldControl: () => this.#yieldCanonical(pane),
|
|
805
|
+
signal: pane.canonicalAbort.signal,
|
|
806
|
+
}).then((result) => {
|
|
807
|
+
if (
|
|
808
|
+
this.#closed ||
|
|
809
|
+
pane.canonicalAbort.signal.aborted ||
|
|
810
|
+
this.#panes.get(semanticPaneId) !== pane ||
|
|
811
|
+
pane.current !== baseline
|
|
812
|
+
)
|
|
813
|
+
return;
|
|
814
|
+
this.#publishCanonical(semanticPaneId, pane, update, trace, result, nativeBacking);
|
|
815
|
+
});
|
|
816
|
+
}
|
|
817
|
+
this.#publishCanonical(
|
|
818
|
+
semanticPaneId,
|
|
819
|
+
pane,
|
|
820
|
+
update,
|
|
821
|
+
trace,
|
|
822
|
+
applyTerminalReplicaUpdate(pane.current, update),
|
|
823
|
+
nativeBacking,
|
|
824
|
+
);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
#publishCanonical(
|
|
828
|
+
semanticPaneId: string,
|
|
829
|
+
pane: PaneState,
|
|
830
|
+
update: CanonicalTerminalReplicaUpdate,
|
|
831
|
+
trace: SessionRuntimeTraceContext | null,
|
|
832
|
+
result: ReturnType<typeof applyTerminalReplicaUpdate>,
|
|
833
|
+
nativeBacking: NativeBackingLease | null,
|
|
834
|
+
): void {
|
|
835
|
+
if (result.status !== "applied" && result.status !== "idempotent") return;
|
|
836
|
+
pane.current = result.state;
|
|
837
|
+
if (trace) pane.pendingDeliveryTrace = trace;
|
|
838
|
+
const previous = pane.revisions.get(update.revision);
|
|
839
|
+
// Idempotent replay may not carry a new handoff; preserve the existing lease.
|
|
840
|
+
const retained = nativeBacking ?? previous?.nativeBacking ?? null;
|
|
841
|
+
if (previous?.nativeBacking !== retained) this.#releaseNativeBacking(previous?.nativeBacking);
|
|
842
|
+
if (retained) retained.committed = true;
|
|
843
|
+
const record = {
|
|
844
|
+
update,
|
|
845
|
+
state: result.state,
|
|
846
|
+
trace: pane.pendingDeliveryTrace,
|
|
847
|
+
nativeBacking: retained,
|
|
848
|
+
};
|
|
849
|
+
pane.latest = record;
|
|
850
|
+
pane.revisions.set(update.revision, record);
|
|
851
|
+
this.#pruneCanonicalRevisions(semanticPaneId);
|
|
852
|
+
for (const client of this.#clients.values()) {
|
|
853
|
+
if (client.paneId !== semanticPaneId || client.closed) continue;
|
|
854
|
+
if (!client.lifecycleOpenRecorded)
|
|
855
|
+
client.lifecycleOpenRecorded = this.#recordDeliveryLifecycle(client, pane, "open");
|
|
856
|
+
if (
|
|
857
|
+
update.type === "terminal.tombstone" &&
|
|
858
|
+
(client.inFlight !== null || client.encoding !== null || client.visibility !== "visible")
|
|
859
|
+
) {
|
|
860
|
+
this.#fault(client, "source-closed", "Terminal source closed before final state delivery");
|
|
861
|
+
continue;
|
|
862
|
+
}
|
|
863
|
+
if (client.encoding && client.encoding.target.update.incarnation !== update.incarnation)
|
|
864
|
+
this.#cancelEncoding(client);
|
|
865
|
+
if (client.latestRevision !== null && client.latestRevision !== update.revision)
|
|
866
|
+
this.#coalesced += 1;
|
|
867
|
+
client.latestRevision = update.revision;
|
|
868
|
+
this.#schedule(client);
|
|
869
|
+
}
|
|
870
|
+
if (update.type === "terminal.tombstone") {
|
|
871
|
+
pane.canonicalAbort.abort();
|
|
872
|
+
this.#clearPendingNativeBacking(pane);
|
|
873
|
+
pane.pendingCanonical.length = 0;
|
|
874
|
+
pane.pendingCanonicalCells = 0;
|
|
875
|
+
this.#scheduler.timer(() => {
|
|
876
|
+
if (this.#panes.get(semanticPaneId) !== pane) return;
|
|
877
|
+
this.#panes.delete(semanticPaneId);
|
|
878
|
+
this.#clearRetainedNativeBacking(pane);
|
|
879
|
+
this.#clearPendingNativeBacking(pane);
|
|
880
|
+
pane.pendingCanonical.length = 0;
|
|
881
|
+
pane.pendingCanonicalCells = 0;
|
|
882
|
+
pane.canonicalScheduled = false;
|
|
883
|
+
void pane.source?.close().catch(() => undefined);
|
|
884
|
+
this.#clearCache();
|
|
885
|
+
}, 0);
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
#observeRaw(semanticPaneId: string, record: TerminalReplicaCommittedRaw): void {
|
|
890
|
+
const pane = this.#panes.get(semanticPaneId);
|
|
891
|
+
if (!pane || pane.canonicalAbort.signal.aborted) return;
|
|
892
|
+
if (record.revision <= pane.lastRawRevision) return;
|
|
893
|
+
if (
|
|
894
|
+
record.baseRevision === record.revision ||
|
|
895
|
+
record.baseRevision !== record.revision - 1 ||
|
|
896
|
+
(pane.lastRawRevision >= 0 && record.baseRevision !== pane.lastRawRevision)
|
|
897
|
+
) {
|
|
898
|
+
pane.raw.clear();
|
|
899
|
+
pane.rawBytes = 0;
|
|
900
|
+
pane.rawFloorRevision = Math.max(pane.rawFloorRevision, record.revision + 1);
|
|
901
|
+
pane.lastRawRevision = record.revision;
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
if (!record.contiguous || record.bytes.byteLength > MAX_RAW_JOURNAL_BYTES) {
|
|
905
|
+
pane.raw.clear();
|
|
906
|
+
pane.rawBytes = 0;
|
|
907
|
+
pane.rawFloorRevision = Math.max(pane.rawFloorRevision, record.revision + 1);
|
|
908
|
+
pane.lastRawRevision = record.revision;
|
|
909
|
+
return;
|
|
910
|
+
}
|
|
911
|
+
pane.raw.set(record.revision, record.bytes);
|
|
912
|
+
pane.lastRawRevision = record.revision;
|
|
913
|
+
pane.rawBytes += record.bytes.byteLength;
|
|
914
|
+
while (pane.rawBytes > MAX_RAW_JOURNAL_BYTES || pane.raw.size > MAX_CANONICAL_REVISIONS) {
|
|
915
|
+
const first = pane.raw.entries().next().value as [number, Uint8Array] | undefined;
|
|
916
|
+
if (!first) break;
|
|
917
|
+
pane.raw.delete(first[0]);
|
|
918
|
+
pane.rawBytes -= first[1].byteLength;
|
|
919
|
+
pane.rawFloorRevision = Math.max(pane.rawFloorRevision, first[0] + 1);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
#schedule(client: ClientState): void {
|
|
924
|
+
if (
|
|
925
|
+
client.closed ||
|
|
926
|
+
client.inFlight ||
|
|
927
|
+
client.encoding ||
|
|
928
|
+
client.latestRevision === null ||
|
|
929
|
+
client.latestRevision === client.baselineRevision ||
|
|
930
|
+
client.visibility === "hidden" ||
|
|
931
|
+
client.visibility === "frozen"
|
|
932
|
+
)
|
|
933
|
+
return;
|
|
934
|
+
if (client.visibility === "background") {
|
|
935
|
+
if (client.backgroundTimer) return;
|
|
936
|
+
client.backgroundTimer = this.#scheduler.timer(() => {
|
|
937
|
+
client.backgroundTimer = null;
|
|
938
|
+
if (!client.closed && !client.inFlight && client.latestRevision !== null)
|
|
939
|
+
this.#deliver(client);
|
|
940
|
+
}, BACKGROUND_CADENCE_MS);
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
if (client.scheduled) return;
|
|
944
|
+
client.scheduled = true;
|
|
945
|
+
this.#scheduler.microtask(() => {
|
|
946
|
+
client.scheduled = false;
|
|
947
|
+
if (!client.closed && client.visibility === "visible" && !client.inFlight)
|
|
948
|
+
this.#deliver(client);
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
#deliver(
|
|
953
|
+
client: ClientState,
|
|
954
|
+
completed?: {
|
|
955
|
+
readonly target: RevisionRecord;
|
|
956
|
+
readonly outcome: SeedEncodingOutcome;
|
|
957
|
+
readonly traceStarted: number;
|
|
958
|
+
},
|
|
959
|
+
): void {
|
|
960
|
+
const pane = this.#panes.get(client.paneId);
|
|
961
|
+
const target = completed?.target ?? pane?.latest;
|
|
962
|
+
if (
|
|
963
|
+
!pane ||
|
|
964
|
+
!target ||
|
|
965
|
+
client.closed ||
|
|
966
|
+
client.inFlight ||
|
|
967
|
+
client.encoding ||
|
|
968
|
+
client.visibility === "hidden" ||
|
|
969
|
+
client.visibility === "frozen" ||
|
|
970
|
+
(!completed && target.update.revision !== client.latestRevision)
|
|
971
|
+
)
|
|
972
|
+
return;
|
|
973
|
+
const traceStarted =
|
|
974
|
+
completed?.traceStarted ??
|
|
975
|
+
(this.#observability.enabled ? this.#observability.nowMicros() : 0);
|
|
976
|
+
let deferred = false;
|
|
977
|
+
let encodedRepresentation: CachedRepresentation | null = null;
|
|
978
|
+
let failedSelectionObservation: SemanticSelectionObservation | null = null;
|
|
979
|
+
let deliveryEnvelope: TerminalDeliveryEnvelope | null = null;
|
|
980
|
+
let deliveryOrdinal: number | null = null;
|
|
981
|
+
try {
|
|
982
|
+
const representation = this.#representation(client, pane, target, completed?.outcome);
|
|
983
|
+
encodedRepresentation = representation;
|
|
984
|
+
const transactionId = this.#scheduler.createId();
|
|
985
|
+
const chunkCount = Math.max(1, Math.ceil(representation.bytes.byteLength / (256 * 1024)));
|
|
986
|
+
const envelope = TerminalDeliveryEnvelopeSchemaZ.parse({
|
|
987
|
+
type: "terminal.delivery",
|
|
988
|
+
workspaceName: target.update.workspaceName,
|
|
989
|
+
semanticPaneId: target.update.semanticPaneId,
|
|
990
|
+
generation: target.update.generation,
|
|
991
|
+
incarnation: target.update.incarnation,
|
|
992
|
+
deliveryNonce: client.negotiated.deliveryNonce,
|
|
993
|
+
transactionId,
|
|
994
|
+
...(target.trace ? { performanceTraceId: target.trace.traceId } : {}),
|
|
995
|
+
protocolVersion: 1,
|
|
996
|
+
encoding: representation.encoding ?? client.negotiated.encoding,
|
|
997
|
+
frame: representation.frame,
|
|
998
|
+
baseRevision: representation.frame === "seed" ? null : Math.max(0, client.baselineRevision),
|
|
999
|
+
canonicalRevision: target.update.revision,
|
|
1000
|
+
canonicalStateHash: target.update.stateHash,
|
|
1001
|
+
representationHash:
|
|
1002
|
+
representation.representationHash ??
|
|
1003
|
+
hashTerminalDeliveryRepresentation(representation.bytes),
|
|
1004
|
+
representationBytes: representation.bytes.byteLength,
|
|
1005
|
+
chunkCount,
|
|
1006
|
+
canonicalEquivalent: representation.canonicalEquivalent,
|
|
1007
|
+
history: representation.history,
|
|
1008
|
+
richPlacements: client.negotiated.richPlacements,
|
|
1009
|
+
});
|
|
1010
|
+
deliveryEnvelope = envelope;
|
|
1011
|
+
deliveryOrdinal = ++this.#deliveryOrdinal;
|
|
1012
|
+
registerTerminalDeliveryObservationOrdinal(envelope, deliveryOrdinal);
|
|
1013
|
+
client.inFlight = {
|
|
1014
|
+
envelope,
|
|
1015
|
+
deliveryOrdinal,
|
|
1016
|
+
bytes: representation.bytes,
|
|
1017
|
+
nextChunk: 0,
|
|
1018
|
+
sentAt: this.#scheduler.nowMs(),
|
|
1019
|
+
};
|
|
1020
|
+
this.#enqueue(client, envelope);
|
|
1021
|
+
this.#recordDeliveryStatus(client, pane);
|
|
1022
|
+
if (target.trace?.traceId === pane.pendingDeliveryTrace?.traceId)
|
|
1023
|
+
pane.pendingDeliveryTrace = null;
|
|
1024
|
+
} catch (error) {
|
|
1025
|
+
if (error instanceof DeferredSeedEncoding) {
|
|
1026
|
+
deferred = true;
|
|
1027
|
+
this.#startEncoding(client, pane, target, error.payload, traceStarted);
|
|
1028
|
+
return;
|
|
1029
|
+
}
|
|
1030
|
+
failedSelectionObservation = semanticSelectionObservationFromError(error);
|
|
1031
|
+
this.#fault(
|
|
1032
|
+
client,
|
|
1033
|
+
error instanceof TerminalDeliveryStateTooLargeError
|
|
1034
|
+
? "state-too-large"
|
|
1035
|
+
: "protocol-violation",
|
|
1036
|
+
error instanceof Error ? error.message : String(error),
|
|
1037
|
+
failedSelectionObservation,
|
|
1038
|
+
);
|
|
1039
|
+
} finally {
|
|
1040
|
+
if (this.#observability.enabled && !deferred)
|
|
1041
|
+
try {
|
|
1042
|
+
const metrics = this.metrics();
|
|
1043
|
+
this.#observability.recordSpan(
|
|
1044
|
+
"transport",
|
|
1045
|
+
"terminal-delivery-encode-enqueue",
|
|
1046
|
+
traceStarted,
|
|
1047
|
+
this.#observability.nowMicros(),
|
|
1048
|
+
target.trace,
|
|
1049
|
+
undefined,
|
|
1050
|
+
Object.freeze({
|
|
1051
|
+
representationCacheBytes: metrics.representationCacheBytes,
|
|
1052
|
+
rawJournalBytes: metrics.rawJournalBytes,
|
|
1053
|
+
queueDepth: metrics.queueDepth,
|
|
1054
|
+
maxQueueDepth: metrics.maxQueueDepth,
|
|
1055
|
+
inFlight: metrics.inFlight,
|
|
1056
|
+
inFlightBytes: metrics.inFlightBytes,
|
|
1057
|
+
...(encodedRepresentation
|
|
1058
|
+
? {
|
|
1059
|
+
representation: encodedRepresentation.frame,
|
|
1060
|
+
representationBytes: encodedRepresentation.bytes.byteLength,
|
|
1061
|
+
}
|
|
1062
|
+
: {}),
|
|
1063
|
+
attemptedPatchBytes:
|
|
1064
|
+
encodedRepresentation?.selectionObservation?.attemptedPatchBytes ??
|
|
1065
|
+
failedSelectionObservation?.attemptedPatchBytes ??
|
|
1066
|
+
null,
|
|
1067
|
+
attemptedSeedBytes:
|
|
1068
|
+
encodedRepresentation?.selectionObservation?.attemptedSeedBytes ??
|
|
1069
|
+
failedSelectionObservation?.attemptedSeedBytes ??
|
|
1070
|
+
null,
|
|
1071
|
+
...((encodedRepresentation?.selectionObservation ?? failedSelectionObservation)
|
|
1072
|
+
? terminalSelectionObservation(
|
|
1073
|
+
encodedRepresentation?.selectionObservation ?? failedSelectionObservation!,
|
|
1074
|
+
)
|
|
1075
|
+
: {}),
|
|
1076
|
+
...(deliveryEnvelope && deliveryOrdinal !== null
|
|
1077
|
+
? {
|
|
1078
|
+
workspaceName: deliveryEnvelope.workspaceName,
|
|
1079
|
+
semanticPaneId: deliveryEnvelope.semanticPaneId,
|
|
1080
|
+
canonicalGeneration: deliveryEnvelope.generation,
|
|
1081
|
+
canonicalIncarnation: deliveryEnvelope.incarnation,
|
|
1082
|
+
canonicalRevision: deliveryEnvelope.canonicalRevision,
|
|
1083
|
+
canonicalStateHash: deliveryEnvelope.canonicalStateHash,
|
|
1084
|
+
deliveryOrdinal,
|
|
1085
|
+
transactionId: deliveryEnvelope.transactionId,
|
|
1086
|
+
deliveryClientId: client.diagnosticClientId,
|
|
1087
|
+
deliverySurface: client.diagnosticSurface,
|
|
1088
|
+
deliveryLaneId: client.diagnosticLaneId,
|
|
1089
|
+
deliveryRequestId: client.diagnosticRequestId,
|
|
1090
|
+
deliveryNonce: deliveryEnvelope.deliveryNonce,
|
|
1091
|
+
}
|
|
1092
|
+
: {}),
|
|
1093
|
+
}),
|
|
1094
|
+
);
|
|
1095
|
+
} catch {
|
|
1096
|
+
// Detailed resource diagnostics never own terminal delivery.
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
#startEncoding(
|
|
1102
|
+
client: ClientState,
|
|
1103
|
+
pane: PaneState,
|
|
1104
|
+
target: RevisionRecord,
|
|
1105
|
+
payload: TerminalSemanticDeliveryPayload,
|
|
1106
|
+
traceStarted: number,
|
|
1107
|
+
): void {
|
|
1108
|
+
const key = cacheKey([
|
|
1109
|
+
target.update.workspaceName,
|
|
1110
|
+
client.paneId,
|
|
1111
|
+
target.update.generation,
|
|
1112
|
+
target.update.incarnation,
|
|
1113
|
+
target.update.revision,
|
|
1114
|
+
target.update.stateHash,
|
|
1115
|
+
client.negotiated.encoding,
|
|
1116
|
+
client.negotiated.richPlacements ? "rich" : "plain",
|
|
1117
|
+
]);
|
|
1118
|
+
let job = this.#pendingEncodings.get(key);
|
|
1119
|
+
let created = false;
|
|
1120
|
+
if (!job) {
|
|
1121
|
+
if (this.#pendingEncodings.size >= MAX_PANES) {
|
|
1122
|
+
this.#fault(
|
|
1123
|
+
client,
|
|
1124
|
+
"state-too-large",
|
|
1125
|
+
"Too many terminal representations are pending; reopen to retry",
|
|
1126
|
+
);
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
job = {
|
|
1130
|
+
key,
|
|
1131
|
+
pane,
|
|
1132
|
+
abort: new AbortController(),
|
|
1133
|
+
clients: new Set(),
|
|
1134
|
+
yieldStartedAt: -Infinity,
|
|
1135
|
+
};
|
|
1136
|
+
this.#pendingEncodings.set(key, job);
|
|
1137
|
+
created = true;
|
|
1138
|
+
}
|
|
1139
|
+
const owned = job;
|
|
1140
|
+
client.encoding = {
|
|
1141
|
+
job: owned,
|
|
1142
|
+
target,
|
|
1143
|
+
baselineRevision: client.baselineRevision,
|
|
1144
|
+
baselineHash: client.baselineHash,
|
|
1145
|
+
reseedRequired: client.reseedRequired,
|
|
1146
|
+
traceStarted,
|
|
1147
|
+
};
|
|
1148
|
+
owned.clients.add(client);
|
|
1149
|
+
if (!created) return;
|
|
1150
|
+
void encodeCompactSemanticTerminalUpdateCooperatively(payload, {
|
|
1151
|
+
signal: owned.abort.signal,
|
|
1152
|
+
yieldControl: () => this.#yieldEncoding(owned),
|
|
1153
|
+
}).then(
|
|
1154
|
+
(bytes) => this.#completeEncoding(owned, { bytes }),
|
|
1155
|
+
(error) => this.#completeEncoding(owned, { error }),
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
#yieldEncoding(job: PendingSeedEncoding): Promise<void> {
|
|
1160
|
+
if (this.#scheduler.nowMs() - job.yieldStartedAt < 2) return Promise.resolve();
|
|
1161
|
+
return new Promise((resolve) => {
|
|
1162
|
+
let timer: SessionRuntimeTimer | undefined;
|
|
1163
|
+
const finish = () => {
|
|
1164
|
+
timer?.cancel();
|
|
1165
|
+
job.yieldStartedAt = this.#scheduler.nowMs();
|
|
1166
|
+
job.abort.signal.removeEventListener("abort", finish);
|
|
1167
|
+
resolve();
|
|
1168
|
+
};
|
|
1169
|
+
job.abort.signal.addEventListener("abort", finish, { once: true });
|
|
1170
|
+
if (job.abort.signal.aborted) finish();
|
|
1171
|
+
else
|
|
1172
|
+
timer = this.#scheduler.yieldTask
|
|
1173
|
+
? this.#scheduler.yieldTask(finish)
|
|
1174
|
+
: this.#scheduler.timer(finish, 0);
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
#completeEncoding(job: PendingSeedEncoding, outcome: SeedEncodingOutcome): void {
|
|
1179
|
+
if (this.#pendingEncodings.get(job.key) === job) this.#pendingEncodings.delete(job.key);
|
|
1180
|
+
for (const client of job.clients) {
|
|
1181
|
+
const encoding = client.encoding;
|
|
1182
|
+
if (!encoding || encoding.job !== job) continue;
|
|
1183
|
+
client.encoding = null;
|
|
1184
|
+
if (
|
|
1185
|
+
job.abort.signal.aborted ||
|
|
1186
|
+
this.#closed ||
|
|
1187
|
+
client.closed ||
|
|
1188
|
+
this.#clients.get(client.key) !== client ||
|
|
1189
|
+
this.#panes.get(client.paneId) !== job.pane ||
|
|
1190
|
+
client.baselineRevision !== encoding.baselineRevision ||
|
|
1191
|
+
client.baselineHash !== encoding.baselineHash ||
|
|
1192
|
+
client.reseedRequired !== encoding.reseedRequired ||
|
|
1193
|
+
client.inFlight ||
|
|
1194
|
+
client.visibility === "hidden" ||
|
|
1195
|
+
client.visibility === "frozen" ||
|
|
1196
|
+
job.pane.latest?.update.incarnation !== encoding.target.update.incarnation
|
|
1197
|
+
)
|
|
1198
|
+
continue;
|
|
1199
|
+
this.#deliver(client, {
|
|
1200
|
+
target: encoding.target,
|
|
1201
|
+
outcome,
|
|
1202
|
+
traceStarted: encoding.traceStarted,
|
|
1203
|
+
});
|
|
1204
|
+
this.#pruneCanonicalRevisions(client.paneId);
|
|
1205
|
+
}
|
|
1206
|
+
job.clients.clear();
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
#cancelEncoding(client: ClientState): void {
|
|
1210
|
+
const encoding = client.encoding;
|
|
1211
|
+
if (!encoding) return;
|
|
1212
|
+
client.encoding = null;
|
|
1213
|
+
const job = encoding.job;
|
|
1214
|
+
job.clients.delete(client);
|
|
1215
|
+
if (job.clients.size === 0) {
|
|
1216
|
+
job.abort.abort();
|
|
1217
|
+
if (this.#pendingEncodings.get(job.key) === job) this.#pendingEncodings.delete(job.key);
|
|
1218
|
+
}
|
|
1219
|
+
this.#pruneCanonicalRevisions(client.paneId);
|
|
1220
|
+
}
|
|
1221
|
+
|
|
1222
|
+
#representation(
|
|
1223
|
+
client: ClientState,
|
|
1224
|
+
pane: PaneState,
|
|
1225
|
+
target: RevisionRecord,
|
|
1226
|
+
seedOutcome?: SeedEncodingOutcome,
|
|
1227
|
+
): CachedRepresentation {
|
|
1228
|
+
const key = cacheKey([
|
|
1229
|
+
target.update.workspaceName,
|
|
1230
|
+
target.update.semanticPaneId,
|
|
1231
|
+
target.update.generation,
|
|
1232
|
+
target.update.incarnation,
|
|
1233
|
+
client.negotiated.encoding,
|
|
1234
|
+
client.negotiated.fallbackEncoding ?? "no-fallback",
|
|
1235
|
+
client.negotiated.richPlacements ? "rich" : "plain",
|
|
1236
|
+
client.baselineRevision,
|
|
1237
|
+
client.baselineHash ?? "none",
|
|
1238
|
+
client.reseedRequired ? "reseed" : "incremental",
|
|
1239
|
+
target.update.revision,
|
|
1240
|
+
target.update.stateHash,
|
|
1241
|
+
]);
|
|
1242
|
+
const cached = this.#cache.get(key);
|
|
1243
|
+
if (cached) return cached;
|
|
1244
|
+
const baseline = client.reseedRequired
|
|
1245
|
+
? null
|
|
1246
|
+
: (pane.revisions.get(client.baselineRevision)?.state.snapshot ?? null);
|
|
1247
|
+
const snapshot = target.state.snapshot;
|
|
1248
|
+
let result: CachedRepresentation | null = null;
|
|
1249
|
+
if (
|
|
1250
|
+
client.negotiated.encoding === "semantic-v1" ||
|
|
1251
|
+
client.negotiated.encoding === "semantic-compact-v1"
|
|
1252
|
+
) {
|
|
1253
|
+
const encodeSemantic = (payload: TerminalSemanticDeliveryPayload): Uint8Array => {
|
|
1254
|
+
if (client.negotiated.encoding !== "semantic-compact-v1")
|
|
1255
|
+
return encodeSemanticTerminalUpdate(payload);
|
|
1256
|
+
if (terminalSemanticUpdateNeedsCooperativeEncoding(payload)) {
|
|
1257
|
+
if (!seedOutcome) throw new DeferredSeedEncoding(payload);
|
|
1258
|
+
if ("error" in seedOutcome) throw seedOutcome.error;
|
|
1259
|
+
return seedOutcome.bytes;
|
|
1260
|
+
}
|
|
1261
|
+
return encodeCompactSemanticTerminalUpdate(payload);
|
|
1262
|
+
};
|
|
1263
|
+
if (client.reseedRequired) {
|
|
1264
|
+
const payload = semanticSeed(target);
|
|
1265
|
+
let bytes: Uint8Array;
|
|
1266
|
+
let actualEncoding = client.negotiated.encoding;
|
|
1267
|
+
let fallbackObservation: SemanticSelectionObservation | null = null;
|
|
1268
|
+
try {
|
|
1269
|
+
bytes = encodeSemantic(payload);
|
|
1270
|
+
} catch (error) {
|
|
1271
|
+
if (!(error instanceof TerminalDeliveryStateTooLargeError)) throw error;
|
|
1272
|
+
if (
|
|
1273
|
+
client.negotiated.encoding === "semantic-compact-v1" &&
|
|
1274
|
+
client.negotiated.fallbackEncoding === "semantic-v1"
|
|
1275
|
+
) {
|
|
1276
|
+
try {
|
|
1277
|
+
bytes = encodeLegacySemanticCandidate(payload);
|
|
1278
|
+
actualEncoding = "semantic-v1";
|
|
1279
|
+
fallbackObservation = legacyFallbackObservation(
|
|
1280
|
+
"seed",
|
|
1281
|
+
error.bytes,
|
|
1282
|
+
bytes.byteLength,
|
|
1283
|
+
);
|
|
1284
|
+
} catch (legacyError) {
|
|
1285
|
+
if (!(legacyError instanceof TerminalDeliveryStateTooLargeError)) throw legacyError;
|
|
1286
|
+
throw new TerminalDeliveryRepresentationSelectionError(
|
|
1287
|
+
legacyError.bytes,
|
|
1288
|
+
failedCompactAndLegacyObservation("seed", error.bytes, legacyError),
|
|
1289
|
+
);
|
|
1290
|
+
}
|
|
1291
|
+
} else {
|
|
1292
|
+
throw new TerminalDeliveryRepresentationSelectionError(error.bytes, {
|
|
1293
|
+
attemptedPatchBytes: null,
|
|
1294
|
+
attemptedSeedBytes: error.bytes,
|
|
1295
|
+
attemptedLegacyPatchBytes: null,
|
|
1296
|
+
attemptedLegacySeedBytes:
|
|
1297
|
+
client.negotiated.encoding === "semantic-v1" ? error.bytes : null,
|
|
1298
|
+
attemptedLegacyPatchAtLeastBytes: null,
|
|
1299
|
+
attemptedLegacySeedAtLeastBytes: null,
|
|
1300
|
+
attemptedLegacyPatchSizeCapped: false,
|
|
1301
|
+
attemptedLegacySeedSizeCapped: false,
|
|
1302
|
+
attemptedCompactPatchBytes: null,
|
|
1303
|
+
attemptedCompactSeedBytes:
|
|
1304
|
+
client.negotiated.encoding === "semantic-compact-v1" ? error.bytes : null,
|
|
1305
|
+
selectedEncoding: client.negotiated.encoding,
|
|
1306
|
+
selectionStatus: "direct-seed",
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1309
|
+
}
|
|
1310
|
+
const selectionObservation =
|
|
1311
|
+
fallbackObservation ??
|
|
1312
|
+
(this.#observability.enabled
|
|
1313
|
+
? completeSemanticSelectionObservation(
|
|
1314
|
+
{
|
|
1315
|
+
attemptedPatchBytes: null,
|
|
1316
|
+
attemptedSeedBytes: bytes.byteLength,
|
|
1317
|
+
selectionStatus: "direct-seed",
|
|
1318
|
+
},
|
|
1319
|
+
client.negotiated.encoding,
|
|
1320
|
+
null,
|
|
1321
|
+
)
|
|
1322
|
+
: null);
|
|
1323
|
+
result = {
|
|
1324
|
+
bytes,
|
|
1325
|
+
encoding: actualEncoding,
|
|
1326
|
+
frame: payload.frame,
|
|
1327
|
+
canonicalEquivalent: true,
|
|
1328
|
+
history: payload.frame === "tombstone" ? "not-applicable" : "complete",
|
|
1329
|
+
...(selectionObservation ? { selectionObservation } : {}),
|
|
1330
|
+
};
|
|
1331
|
+
this.#reseeds += 1;
|
|
1332
|
+
} else {
|
|
1333
|
+
const patchPayload = semanticPayload(client.baselineRevision, baseline, target);
|
|
1334
|
+
const seedPayload = patchPayload.frame === "tombstone" ? null : semanticSeed(target);
|
|
1335
|
+
const legacyAttempts = null;
|
|
1336
|
+
if (patchPayload.frame !== "patch") {
|
|
1337
|
+
let bytes: Uint8Array;
|
|
1338
|
+
let actualEncoding = client.negotiated.encoding;
|
|
1339
|
+
let fallbackObservation: SemanticSelectionObservation | null = null;
|
|
1340
|
+
try {
|
|
1341
|
+
bytes = encodeSemantic(patchPayload);
|
|
1342
|
+
} catch (error) {
|
|
1343
|
+
if (!(error instanceof TerminalDeliveryStateTooLargeError)) throw error;
|
|
1344
|
+
if (
|
|
1345
|
+
client.negotiated.encoding === "semantic-compact-v1" &&
|
|
1346
|
+
client.negotiated.fallbackEncoding === "semantic-v1" &&
|
|
1347
|
+
patchPayload.frame === "seed"
|
|
1348
|
+
) {
|
|
1349
|
+
try {
|
|
1350
|
+
bytes = encodeLegacySemanticCandidate(patchPayload);
|
|
1351
|
+
actualEncoding = "semantic-v1";
|
|
1352
|
+
fallbackObservation = legacyFallbackObservation(
|
|
1353
|
+
"seed",
|
|
1354
|
+
error.bytes,
|
|
1355
|
+
bytes.byteLength,
|
|
1356
|
+
);
|
|
1357
|
+
} catch (legacyError) {
|
|
1358
|
+
if (!(legacyError instanceof TerminalDeliveryStateTooLargeError)) throw legacyError;
|
|
1359
|
+
const directObservation = failedCompactAndLegacyObservation(
|
|
1360
|
+
"seed",
|
|
1361
|
+
error.bytes,
|
|
1362
|
+
legacyError,
|
|
1363
|
+
);
|
|
1364
|
+
throw new TerminalDeliveryRepresentationSelectionError(
|
|
1365
|
+
legacyError.bytes,
|
|
1366
|
+
directObservation,
|
|
1367
|
+
);
|
|
1368
|
+
}
|
|
1369
|
+
} else {
|
|
1370
|
+
const directObservation = completeSemanticSelectionObservation(
|
|
1371
|
+
{
|
|
1372
|
+
attemptedPatchBytes: null,
|
|
1373
|
+
attemptedSeedBytes: patchPayload.frame === "seed" ? error.bytes : null,
|
|
1374
|
+
selectionStatus:
|
|
1375
|
+
patchPayload.frame === "seed" ? "direct-seed" : "direct-tombstone",
|
|
1376
|
+
},
|
|
1377
|
+
client.negotiated.encoding,
|
|
1378
|
+
legacyAttempts,
|
|
1379
|
+
);
|
|
1380
|
+
throw new TerminalDeliveryRepresentationSelectionError(
|
|
1381
|
+
error.bytes,
|
|
1382
|
+
directObservation,
|
|
1383
|
+
);
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
const directObservation =
|
|
1387
|
+
fallbackObservation ??
|
|
1388
|
+
(this.#observability.enabled
|
|
1389
|
+
? completeSemanticSelectionObservation(
|
|
1390
|
+
{
|
|
1391
|
+
attemptedPatchBytes: null,
|
|
1392
|
+
attemptedSeedBytes: patchPayload.frame === "seed" ? bytes.byteLength : null,
|
|
1393
|
+
selectionStatus:
|
|
1394
|
+
patchPayload.frame === "seed" ? "direct-seed" : "direct-tombstone",
|
|
1395
|
+
},
|
|
1396
|
+
client.negotiated.encoding,
|
|
1397
|
+
legacyAttempts,
|
|
1398
|
+
)
|
|
1399
|
+
: null);
|
|
1400
|
+
if (patchPayload.frame === "seed") this.#reseeds += 1;
|
|
1401
|
+
result = {
|
|
1402
|
+
bytes,
|
|
1403
|
+
encoding: actualEncoding,
|
|
1404
|
+
frame: patchPayload.frame,
|
|
1405
|
+
canonicalEquivalent: true,
|
|
1406
|
+
history: patchPayload.frame === "tombstone" ? "not-applicable" : "complete",
|
|
1407
|
+
...(directObservation ? { selectionObservation: directObservation } : {}),
|
|
1408
|
+
};
|
|
1409
|
+
} else {
|
|
1410
|
+
let selected: ReturnType<
|
|
1411
|
+
typeof selectExactSemanticRepresentation<TerminalSemanticDeliveryPayload>
|
|
1412
|
+
> | null = null;
|
|
1413
|
+
try {
|
|
1414
|
+
selected = selectExactSemanticRepresentation(
|
|
1415
|
+
() => ({ payload: patchPayload, bytes: encodeSemantic(patchPayload) }),
|
|
1416
|
+
() => {
|
|
1417
|
+
if (!seedPayload) throw new TypeError("Patch has no seed representation");
|
|
1418
|
+
return { payload: seedPayload, bytes: encodeSemantic(seedPayload) };
|
|
1419
|
+
},
|
|
1420
|
+
this.#observability.enabled,
|
|
1421
|
+
);
|
|
1422
|
+
} catch (error) {
|
|
1423
|
+
if (!(error instanceof ExactSemanticRepresentationSelectionError)) throw error;
|
|
1424
|
+
if (
|
|
1425
|
+
client.negotiated.encoding === "semantic-compact-v1" &&
|
|
1426
|
+
client.negotiated.fallbackEncoding === "semantic-v1"
|
|
1427
|
+
) {
|
|
1428
|
+
try {
|
|
1429
|
+
const legacySelected = selectExactSemanticRepresentation(
|
|
1430
|
+
() => ({
|
|
1431
|
+
payload: patchPayload,
|
|
1432
|
+
bytes: encodeLegacySemanticCandidate(patchPayload),
|
|
1433
|
+
}),
|
|
1434
|
+
() => {
|
|
1435
|
+
if (!seedPayload)
|
|
1436
|
+
throw new TypeError("Patch has no legacy seed representation");
|
|
1437
|
+
return {
|
|
1438
|
+
payload: seedPayload,
|
|
1439
|
+
bytes: encodeLegacySemanticCandidate(seedPayload),
|
|
1440
|
+
};
|
|
1441
|
+
},
|
|
1442
|
+
true,
|
|
1443
|
+
);
|
|
1444
|
+
const fallbackObservation = legacyFallbackFromSelection(
|
|
1445
|
+
legacySelected.observation!,
|
|
1446
|
+
error.selectionObservation,
|
|
1447
|
+
legacySelected.payload.frame,
|
|
1448
|
+
);
|
|
1449
|
+
if (legacySelected.payload.frame === "seed") this.#reseeds += 1;
|
|
1450
|
+
result = {
|
|
1451
|
+
bytes: legacySelected.bytes,
|
|
1452
|
+
encoding: "semantic-v1",
|
|
1453
|
+
frame: legacySelected.payload.frame,
|
|
1454
|
+
canonicalEquivalent: true,
|
|
1455
|
+
history:
|
|
1456
|
+
legacySelected.payload.frame === "tombstone" ? "not-applicable" : "complete",
|
|
1457
|
+
selectionObservation: fallbackObservation,
|
|
1458
|
+
};
|
|
1459
|
+
} catch (legacyError) {
|
|
1460
|
+
if (!(legacyError instanceof ExactSemanticRepresentationSelectionError))
|
|
1461
|
+
throw legacyError;
|
|
1462
|
+
throw new TerminalDeliveryRepresentationSelectionError(
|
|
1463
|
+
legacyError.bytes,
|
|
1464
|
+
failedCompactAndLegacySelectionObservation(
|
|
1465
|
+
error.selectionObservation,
|
|
1466
|
+
legacyError.selectionObservation,
|
|
1467
|
+
),
|
|
1468
|
+
);
|
|
1469
|
+
}
|
|
1470
|
+
} else {
|
|
1471
|
+
throw new TerminalDeliveryRepresentationSelectionError(
|
|
1472
|
+
error.bytes,
|
|
1473
|
+
completeSemanticSelectionObservation(
|
|
1474
|
+
error.selectionObservation,
|
|
1475
|
+
client.negotiated.encoding,
|
|
1476
|
+
legacyAttempts,
|
|
1477
|
+
),
|
|
1478
|
+
);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
if (selected) {
|
|
1482
|
+
if (selected.payload.frame === "seed") this.#reseeds += 1;
|
|
1483
|
+
const selectionObservation = selected.observation
|
|
1484
|
+
? completeSemanticSelectionObservation(
|
|
1485
|
+
selected.observation,
|
|
1486
|
+
client.negotiated.encoding,
|
|
1487
|
+
legacyAttempts,
|
|
1488
|
+
)
|
|
1489
|
+
: null;
|
|
1490
|
+
result = {
|
|
1491
|
+
bytes: selected.bytes,
|
|
1492
|
+
encoding: client.negotiated.encoding,
|
|
1493
|
+
frame: selected.payload.frame,
|
|
1494
|
+
canonicalEquivalent: true,
|
|
1495
|
+
history: selected.payload.frame === "tombstone" ? "not-applicable" : "complete",
|
|
1496
|
+
...(selectionObservation ? { selectionObservation } : {}),
|
|
1497
|
+
};
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
} else if (client.negotiated.encoding === "ansi-diff-v1") {
|
|
1502
|
+
if (!snapshot) result = emptyTombstone();
|
|
1503
|
+
else {
|
|
1504
|
+
const patch = baseline !== null;
|
|
1505
|
+
result = {
|
|
1506
|
+
bytes: encodeAnsiTerminalRepresentation(patch ? baseline : null, snapshot),
|
|
1507
|
+
frame: patch ? "patch" : "seed",
|
|
1508
|
+
canonicalEquivalent: false,
|
|
1509
|
+
history: snapshot.history.length > 0 ? "truncated" : "complete",
|
|
1510
|
+
};
|
|
1511
|
+
if (!patch) this.#reseeds += 1;
|
|
1512
|
+
}
|
|
1513
|
+
} else result = this.#rawRepresentation(client, pane, target);
|
|
1514
|
+
if (!result) throw new TypeError("Terminal delivery representation selection was incomplete");
|
|
1515
|
+
const hashed = {
|
|
1516
|
+
...result,
|
|
1517
|
+
representationHash: hashTerminalDeliveryRepresentation(result.bytes),
|
|
1518
|
+
cachePaneId: client.paneId,
|
|
1519
|
+
cacheBaseRevision: client.baselineRevision,
|
|
1520
|
+
cacheTargetRevision: target.update.revision,
|
|
1521
|
+
};
|
|
1522
|
+
this.#cacheSet(key, hashed);
|
|
1523
|
+
return hashed;
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
#rawRepresentation(
|
|
1527
|
+
client: ClientState,
|
|
1528
|
+
pane: PaneState,
|
|
1529
|
+
target: RevisionRecord,
|
|
1530
|
+
): CachedRepresentation {
|
|
1531
|
+
if (client.baselineRevision >= pane.rawFloorRevision - 1) {
|
|
1532
|
+
const parts: Uint8Array[] = [];
|
|
1533
|
+
let contiguous = true;
|
|
1534
|
+
for (
|
|
1535
|
+
let revision = client.baselineRevision + 1;
|
|
1536
|
+
revision <= target.update.revision;
|
|
1537
|
+
revision += 1
|
|
1538
|
+
) {
|
|
1539
|
+
const raw = pane.raw.get(revision);
|
|
1540
|
+
if (!raw) {
|
|
1541
|
+
contiguous = false;
|
|
1542
|
+
break;
|
|
1543
|
+
}
|
|
1544
|
+
parts.push(raw);
|
|
1545
|
+
}
|
|
1546
|
+
if (contiguous)
|
|
1547
|
+
return {
|
|
1548
|
+
bytes: joinBytes(parts),
|
|
1549
|
+
frame: "patch",
|
|
1550
|
+
canonicalEquivalent: false,
|
|
1551
|
+
history: "not-applicable",
|
|
1552
|
+
};
|
|
1553
|
+
}
|
|
1554
|
+
this.#reseeds += 1;
|
|
1555
|
+
return target.state.snapshot
|
|
1556
|
+
? {
|
|
1557
|
+
bytes: encodeAnsiTerminalRepresentation(null, target.state.snapshot),
|
|
1558
|
+
frame: "seed",
|
|
1559
|
+
canonicalEquivalent: false,
|
|
1560
|
+
history: "not-applicable",
|
|
1561
|
+
}
|
|
1562
|
+
: emptyTombstone();
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
#ack(client: ClientState, input: TerminalDeliveryAck): void {
|
|
1566
|
+
const ack = TerminalDeliveryAckSchemaZ.parse(input);
|
|
1567
|
+
const flight = client.inFlight;
|
|
1568
|
+
if (!flight) {
|
|
1569
|
+
if (client.lastAck && JSON.stringify(client.lastAck) === JSON.stringify(ack)) return;
|
|
1570
|
+
const closed = client.sourceClosedFlight;
|
|
1571
|
+
if (
|
|
1572
|
+
closed &&
|
|
1573
|
+
ack.workspaceName === closed.workspaceName &&
|
|
1574
|
+
ack.semanticPaneId === closed.semanticPaneId &&
|
|
1575
|
+
ack.generation === closed.generation &&
|
|
1576
|
+
ack.incarnation === closed.incarnation &&
|
|
1577
|
+
ack.deliveryNonce === closed.deliveryNonce &&
|
|
1578
|
+
ack.transactionId === closed.transactionId &&
|
|
1579
|
+
ack.canonicalRevision === closed.canonicalRevision &&
|
|
1580
|
+
ack.canonicalStateHash === closed.canonicalStateHash &&
|
|
1581
|
+
ack.representationHash === closed.representationHash
|
|
1582
|
+
)
|
|
1583
|
+
return;
|
|
1584
|
+
this.#fault(client, "protocol-violation", "ACK has no in-flight transaction");
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
const envelope = flight.envelope;
|
|
1588
|
+
if (
|
|
1589
|
+
flight.nextChunk !== envelope.chunkCount ||
|
|
1590
|
+
ack.workspaceName !== envelope.workspaceName ||
|
|
1591
|
+
ack.semanticPaneId !== envelope.semanticPaneId ||
|
|
1592
|
+
ack.generation !== envelope.generation ||
|
|
1593
|
+
ack.incarnation !== envelope.incarnation ||
|
|
1594
|
+
ack.deliveryNonce !== envelope.deliveryNonce ||
|
|
1595
|
+
ack.transactionId !== envelope.transactionId ||
|
|
1596
|
+
ack.canonicalRevision !== envelope.canonicalRevision ||
|
|
1597
|
+
ack.canonicalStateHash !== envelope.canonicalStateHash ||
|
|
1598
|
+
ack.representationHash !== envelope.representationHash
|
|
1599
|
+
) {
|
|
1600
|
+
this.#fault(client, "protocol-violation", "ACK does not identify the in-flight delivery");
|
|
1601
|
+
return;
|
|
1602
|
+
}
|
|
1603
|
+
this.#maxSlowClientMs = Math.max(
|
|
1604
|
+
this.#maxSlowClientMs,
|
|
1605
|
+
this.#scheduler.nowMs() - flight.sentAt,
|
|
1606
|
+
);
|
|
1607
|
+
client.baselineRevision = ack.canonicalRevision;
|
|
1608
|
+
client.baselineHash = ack.canonicalStateHash;
|
|
1609
|
+
client.reseedRequired = false;
|
|
1610
|
+
client.inFlight = null;
|
|
1611
|
+
client.lastAck = ack;
|
|
1612
|
+
if (client.latestRevision === ack.canonicalRevision) client.latestRevision = null;
|
|
1613
|
+
this.#pruneAckSupersededCache(client.paneId);
|
|
1614
|
+
this.#pruneCanonicalRevisions(client.paneId);
|
|
1615
|
+
if (this.#observability.enabled)
|
|
1616
|
+
try {
|
|
1617
|
+
const atMicros = this.#observability.nowMicros();
|
|
1618
|
+
const metrics = this.metrics();
|
|
1619
|
+
this.#observability.recordSpan(
|
|
1620
|
+
"transport",
|
|
1621
|
+
"terminal-delivery-settled",
|
|
1622
|
+
atMicros,
|
|
1623
|
+
atMicros,
|
|
1624
|
+
envelope.performanceTraceId
|
|
1625
|
+
? Object.freeze({
|
|
1626
|
+
traceId: envelope.performanceTraceId,
|
|
1627
|
+
scenario: "terminal-input-to-paint",
|
|
1628
|
+
authority: Object.freeze({
|
|
1629
|
+
generation: envelope.generation,
|
|
1630
|
+
incarnation: envelope.incarnation,
|
|
1631
|
+
}),
|
|
1632
|
+
})
|
|
1633
|
+
: null,
|
|
1634
|
+
undefined,
|
|
1635
|
+
Object.freeze({
|
|
1636
|
+
representationCacheBytes: metrics.representationCacheBytes,
|
|
1637
|
+
rawJournalBytes: metrics.rawJournalBytes,
|
|
1638
|
+
queueDepth: metrics.queueDepth,
|
|
1639
|
+
maxQueueDepth: metrics.maxQueueDepth,
|
|
1640
|
+
inFlight: metrics.inFlight,
|
|
1641
|
+
inFlightBytes: metrics.inFlightBytes,
|
|
1642
|
+
workspaceName: envelope.workspaceName,
|
|
1643
|
+
semanticPaneId: envelope.semanticPaneId,
|
|
1644
|
+
canonicalGeneration: envelope.generation,
|
|
1645
|
+
canonicalIncarnation: envelope.incarnation,
|
|
1646
|
+
canonicalRevision: envelope.canonicalRevision,
|
|
1647
|
+
canonicalStateHash: envelope.canonicalStateHash,
|
|
1648
|
+
deliveryOrdinal: flight.deliveryOrdinal,
|
|
1649
|
+
transactionId: envelope.transactionId,
|
|
1650
|
+
deliveryClientId: client.diagnosticClientId,
|
|
1651
|
+
deliverySurface: client.diagnosticSurface,
|
|
1652
|
+
deliveryLaneId: client.diagnosticLaneId,
|
|
1653
|
+
deliveryRequestId: client.diagnosticRequestId,
|
|
1654
|
+
deliveryNonce: envelope.deliveryNonce,
|
|
1655
|
+
}),
|
|
1656
|
+
);
|
|
1657
|
+
} catch {
|
|
1658
|
+
// Detailed settlement diagnostics never own ACK adoption.
|
|
1659
|
+
}
|
|
1660
|
+
this.#schedule(client);
|
|
1661
|
+
this.#recordDeliveryStatus(client, this.#panes.get(client.paneId));
|
|
1662
|
+
}
|
|
1663
|
+
|
|
1664
|
+
#nack(client: ClientState, input: TerminalDeliveryNack): void {
|
|
1665
|
+
const nack = TerminalDeliveryNackSchemaZ.parse(input);
|
|
1666
|
+
const envelope = client.inFlight?.envelope;
|
|
1667
|
+
if (
|
|
1668
|
+
!envelope ||
|
|
1669
|
+
nack.workspaceName !== envelope.workspaceName ||
|
|
1670
|
+
nack.semanticPaneId !== envelope.semanticPaneId ||
|
|
1671
|
+
nack.generation !== envelope.generation ||
|
|
1672
|
+
nack.incarnation !== envelope.incarnation ||
|
|
1673
|
+
nack.deliveryNonce !== envelope.deliveryNonce ||
|
|
1674
|
+
nack.transactionId !== envelope.transactionId
|
|
1675
|
+
) {
|
|
1676
|
+
this.#fault(client, "protocol-violation", "NACK does not identify the in-flight delivery");
|
|
1677
|
+
return;
|
|
1678
|
+
}
|
|
1679
|
+
this.#nacks += 1;
|
|
1680
|
+
client.reseedRequired = true;
|
|
1681
|
+
client.inFlight = null;
|
|
1682
|
+
this.#pruneCanonicalRevisions(client.paneId);
|
|
1683
|
+
this.#schedule(client);
|
|
1684
|
+
this.#recordDeliveryStatus(client, this.#panes.get(client.paneId));
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
#fault(
|
|
1688
|
+
client: ClientState,
|
|
1689
|
+
reason: "state-too-large" | "source-closed" | "protocol-violation",
|
|
1690
|
+
message: string,
|
|
1691
|
+
selectionObservation: SemanticSelectionObservation | null = null,
|
|
1692
|
+
): void {
|
|
1693
|
+
if (this.#observability.enabled)
|
|
1694
|
+
try {
|
|
1695
|
+
const atMicros = this.#observability.nowMicros();
|
|
1696
|
+
const flight = client.inFlight;
|
|
1697
|
+
const metrics = this.metrics();
|
|
1698
|
+
this.#observability.recordSpan(
|
|
1699
|
+
"transport",
|
|
1700
|
+
"terminal-delivery-fault",
|
|
1701
|
+
atMicros,
|
|
1702
|
+
atMicros,
|
|
1703
|
+
null,
|
|
1704
|
+
undefined,
|
|
1705
|
+
Object.freeze({
|
|
1706
|
+
representationCacheBytes: metrics.representationCacheBytes,
|
|
1707
|
+
rawJournalBytes: metrics.rawJournalBytes,
|
|
1708
|
+
queueDepth: metrics.queueDepth,
|
|
1709
|
+
maxQueueDepth: metrics.maxQueueDepth,
|
|
1710
|
+
inFlight: metrics.inFlight,
|
|
1711
|
+
inFlightBytes: metrics.inFlightBytes,
|
|
1712
|
+
workspaceName: this.workspaceName,
|
|
1713
|
+
semanticPaneId: client.paneId,
|
|
1714
|
+
faultReason: reason,
|
|
1715
|
+
...(selectionObservation ? terminalSelectionObservation(selectionObservation) : {}),
|
|
1716
|
+
...(flight
|
|
1717
|
+
? {
|
|
1718
|
+
canonicalGeneration: flight.envelope.generation,
|
|
1719
|
+
canonicalIncarnation: flight.envelope.incarnation,
|
|
1720
|
+
canonicalRevision: flight.envelope.canonicalRevision,
|
|
1721
|
+
canonicalStateHash: flight.envelope.canonicalStateHash,
|
|
1722
|
+
deliveryOrdinal: flight.deliveryOrdinal,
|
|
1723
|
+
transactionId: flight.envelope.transactionId,
|
|
1724
|
+
}
|
|
1725
|
+
: {}),
|
|
1726
|
+
}),
|
|
1727
|
+
);
|
|
1728
|
+
} catch {
|
|
1729
|
+
// Detailed fault diagnostics never own delivery failure handling.
|
|
1730
|
+
}
|
|
1731
|
+
this.#cancelEncoding(client);
|
|
1732
|
+
client.outgoing.length = 0;
|
|
1733
|
+
if (reason === "source-closed") client.sourceClosedFlight = client.inFlight?.envelope ?? null;
|
|
1734
|
+
client.inFlight = null;
|
|
1735
|
+
const fault: TerminalDeliveryServerMessage = {
|
|
1736
|
+
type: "terminal.delivery.fault",
|
|
1737
|
+
reason,
|
|
1738
|
+
message: message.slice(0, 1024),
|
|
1739
|
+
deliveryNonce: client.negotiated.deliveryNonce,
|
|
1740
|
+
};
|
|
1741
|
+
if (reason === "source-closed" && client.sending) {
|
|
1742
|
+
// A data callback may be waiting for renderer credit. Source closure is
|
|
1743
|
+
// authoritative control state, so send it out-of-band and retire after
|
|
1744
|
+
// that small frame has reached the transport instead of waiting behind
|
|
1745
|
+
// a transaction which can no longer become current.
|
|
1746
|
+
void Promise.resolve(client.accept(fault)).then(
|
|
1747
|
+
() => this.#closeClient(client),
|
|
1748
|
+
() => this.#closeClient(client),
|
|
1749
|
+
);
|
|
1750
|
+
return;
|
|
1751
|
+
}
|
|
1752
|
+
this.#enqueue(client, fault);
|
|
1753
|
+
client.retireAfterDrain = true;
|
|
1754
|
+
}
|
|
1755
|
+
|
|
1756
|
+
#enqueue(client: ClientState, message: TerminalDeliveryServerMessage): void {
|
|
1757
|
+
this.#enqueueFactory(client, () => message);
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
#enqueueFactory(client: ClientState, create: () => TerminalDeliveryServerMessage): void {
|
|
1761
|
+
if (client.closed) return;
|
|
1762
|
+
client.outgoing.push(create);
|
|
1763
|
+
this.#maxQueueDepth = Math.max(this.#maxQueueDepth, client.outgoing.length);
|
|
1764
|
+
if (client.sending) return;
|
|
1765
|
+
client.sending = true;
|
|
1766
|
+
this.#scheduler.microtask(async () => {
|
|
1767
|
+
try {
|
|
1768
|
+
while (!client.closed) {
|
|
1769
|
+
const queued = client.outgoing.shift();
|
|
1770
|
+
let next = queued?.();
|
|
1771
|
+
const flight = client.inFlight;
|
|
1772
|
+
if (!next && flight && flight.nextChunk < flight.envelope.chunkCount) {
|
|
1773
|
+
const index = flight.nextChunk;
|
|
1774
|
+
flight.nextChunk += 1;
|
|
1775
|
+
next = {
|
|
1776
|
+
type: "terminal.delivery.chunk",
|
|
1777
|
+
transactionId: flight.envelope.transactionId,
|
|
1778
|
+
index,
|
|
1779
|
+
bytes: flight.bytes.slice(
|
|
1780
|
+
index * 256 * 1024,
|
|
1781
|
+
Math.min(flight.bytes.byteLength, (index + 1) * 256 * 1024),
|
|
1782
|
+
),
|
|
1783
|
+
};
|
|
1784
|
+
}
|
|
1785
|
+
if (!next) break;
|
|
1786
|
+
await this.#withDeadline(Promise.resolve(client.accept(next)), 5_000);
|
|
1787
|
+
}
|
|
1788
|
+
} catch {
|
|
1789
|
+
client.outgoing.length = 0;
|
|
1790
|
+
try {
|
|
1791
|
+
client.outgoing.length = 0;
|
|
1792
|
+
await this.#closeClient(client, "sink-failed");
|
|
1793
|
+
} catch {
|
|
1794
|
+
// Closing a failed source is best effort and cannot escape this task.
|
|
1795
|
+
}
|
|
1796
|
+
} finally {
|
|
1797
|
+
client.sending = false;
|
|
1798
|
+
if (client.retireAfterDrain) await this.#closeClient(client).catch(() => undefined);
|
|
1799
|
+
}
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
|
|
1803
|
+
async #closeClient(
|
|
1804
|
+
client: ClientState,
|
|
1805
|
+
reason: "closed" | "sink-failed" = "closed",
|
|
1806
|
+
): Promise<void> {
|
|
1807
|
+
if (client.closed) return;
|
|
1808
|
+
client.closed = true;
|
|
1809
|
+
this.#cancelEncoding(client);
|
|
1810
|
+
client.resolveClosed(reason);
|
|
1811
|
+
if (client.lifecycleOpenRecorded)
|
|
1812
|
+
this.#recordDeliveryLifecycle(client, this.#panes.get(client.paneId), "close");
|
|
1813
|
+
client.backgroundTimer?.cancel();
|
|
1814
|
+
client.outgoing.length = 0;
|
|
1815
|
+
this.#clients.delete(client.key);
|
|
1816
|
+
this.#pruneCanonicalRevisions(client.paneId);
|
|
1817
|
+
if ([...this.#clients.values()].some((candidate) => candidate.paneId === client.paneId)) return;
|
|
1818
|
+
const pane = this.#panes.get(client.paneId);
|
|
1819
|
+
this.#panes.delete(client.paneId);
|
|
1820
|
+
if (pane) {
|
|
1821
|
+
this.#clearRetainedNativeBacking(pane);
|
|
1822
|
+
pane.canonicalAbort.abort();
|
|
1823
|
+
this.#clearPendingNativeBacking(pane);
|
|
1824
|
+
pane.pendingCanonical.length = 0;
|
|
1825
|
+
pane.pendingCanonicalCells = 0;
|
|
1826
|
+
pane.canonicalScheduled = false;
|
|
1827
|
+
}
|
|
1828
|
+
await pane?.source?.close().catch(() => undefined);
|
|
1829
|
+
this.#clearCache();
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
#recordDeliveryLifecycle(
|
|
1833
|
+
client: ClientState,
|
|
1834
|
+
pane: PaneState | undefined,
|
|
1835
|
+
event: "open" | "close",
|
|
1836
|
+
): boolean {
|
|
1837
|
+
if (!this.#observability.enabled) return false;
|
|
1838
|
+
const canonical = pane?.latest?.update;
|
|
1839
|
+
if (!canonical) return false;
|
|
1840
|
+
try {
|
|
1841
|
+
const atMicros = this.#observability.nowMicros();
|
|
1842
|
+
this.#observability.recordSpan(
|
|
1843
|
+
"transport",
|
|
1844
|
+
"terminal-delivery-subscriber-lifecycle",
|
|
1845
|
+
atMicros,
|
|
1846
|
+
atMicros,
|
|
1847
|
+
null,
|
|
1848
|
+
undefined,
|
|
1849
|
+
Object.freeze({
|
|
1850
|
+
workspaceName: this.workspaceName,
|
|
1851
|
+
semanticPaneId: client.paneId,
|
|
1852
|
+
canonicalGeneration: this.generation,
|
|
1853
|
+
canonicalIncarnation: canonical.incarnation,
|
|
1854
|
+
canonicalRevision: canonical.revision,
|
|
1855
|
+
canonicalStateHash: canonical.stateHash,
|
|
1856
|
+
deliveryClientId: client.diagnosticClientId,
|
|
1857
|
+
deliverySurface: client.diagnosticSurface,
|
|
1858
|
+
deliveryLaneId: client.diagnosticLaneId,
|
|
1859
|
+
deliveryRequestId: client.diagnosticRequestId,
|
|
1860
|
+
deliveryLifecycleEvent: event,
|
|
1861
|
+
deliveryPurpose: "terminal-surface",
|
|
1862
|
+
deliveryLifecycleOrdinal: ++this.#deliveryLifecycleOrdinal,
|
|
1863
|
+
}),
|
|
1864
|
+
);
|
|
1865
|
+
return true;
|
|
1866
|
+
} catch {
|
|
1867
|
+
// Detailed lifecycle evidence is fail-open for product delivery.
|
|
1868
|
+
return false;
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
#recordDeliveryStatus(client: ClientState, pane: PaneState | undefined): boolean {
|
|
1873
|
+
if (!this.#observability.enabled || client.closed) return false;
|
|
1874
|
+
const canonical = pane?.latest?.update;
|
|
1875
|
+
if (!canonical) return false;
|
|
1876
|
+
try {
|
|
1877
|
+
const atMicros = this.#observability.nowMicros();
|
|
1878
|
+
this.#observability.recordSpan(
|
|
1879
|
+
"transport",
|
|
1880
|
+
"terminal-delivery-subscriber-status",
|
|
1881
|
+
atMicros,
|
|
1882
|
+
atMicros,
|
|
1883
|
+
null,
|
|
1884
|
+
undefined,
|
|
1885
|
+
Object.freeze({
|
|
1886
|
+
workspaceName: this.workspaceName,
|
|
1887
|
+
semanticPaneId: client.paneId,
|
|
1888
|
+
canonicalGeneration: this.generation,
|
|
1889
|
+
canonicalIncarnation: canonical.incarnation,
|
|
1890
|
+
canonicalRevision: canonical.revision,
|
|
1891
|
+
canonicalStateHash: canonical.stateHash,
|
|
1892
|
+
deliveryClientId: client.diagnosticClientId,
|
|
1893
|
+
deliverySurface: client.diagnosticSurface,
|
|
1894
|
+
deliveryLaneId: client.diagnosticLaneId,
|
|
1895
|
+
deliveryRequestId: client.diagnosticRequestId,
|
|
1896
|
+
deliveryPurpose: "terminal-surface",
|
|
1897
|
+
deliveryStatusOrdinal: ++this.#deliveryStatusOrdinal,
|
|
1898
|
+
deliveryVisibility: client.visibility,
|
|
1899
|
+
deliveryBaselineRevision: client.baselineRevision,
|
|
1900
|
+
deliveryBaselineHash: client.baselineHash,
|
|
1901
|
+
deliveryInFlightRevision: client.inFlight?.envelope.canonicalRevision ?? null,
|
|
1902
|
+
deliveryInFlightHash: client.inFlight?.envelope.canonicalStateHash ?? null,
|
|
1903
|
+
deliveryLatestRevision: client.latestRevision,
|
|
1904
|
+
deliveryClientQueueDepth: client.outgoing.length,
|
|
1905
|
+
}),
|
|
1906
|
+
);
|
|
1907
|
+
return true;
|
|
1908
|
+
} catch {
|
|
1909
|
+
// Detailed readiness evidence never owns terminal delivery.
|
|
1910
|
+
return false;
|
|
1911
|
+
}
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
async #withDeadline<T>(promise: Promise<T>, milliseconds: number): Promise<T> {
|
|
1915
|
+
let timer: SessionRuntimeTimer | undefined;
|
|
1916
|
+
try {
|
|
1917
|
+
return await Promise.race([
|
|
1918
|
+
promise,
|
|
1919
|
+
new Promise<never>((_, reject) => {
|
|
1920
|
+
timer = this.#scheduler.timer(
|
|
1921
|
+
() => reject(new Error("Terminal delivery sink timed out")),
|
|
1922
|
+
milliseconds,
|
|
1923
|
+
);
|
|
1924
|
+
}),
|
|
1925
|
+
]);
|
|
1926
|
+
} finally {
|
|
1927
|
+
timer?.cancel();
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
#cacheSet(key: string, value: CachedRepresentation): void {
|
|
1932
|
+
if (value.bytes.byteLength > MAX_REPRESENTATION_CACHE_BYTES) return;
|
|
1933
|
+
const previous = this.#cache.get(key);
|
|
1934
|
+
if (previous) this.#cacheBytes -= previous.bytes.byteLength;
|
|
1935
|
+
this.#cache.set(key, value);
|
|
1936
|
+
this.#cacheBytes += value.bytes.byteLength;
|
|
1937
|
+
while (
|
|
1938
|
+
this.#cache.size > MAX_REPRESENTATION_CACHE_ENTRIES ||
|
|
1939
|
+
this.#cacheBytes > MAX_REPRESENTATION_CACHE_BYTES
|
|
1940
|
+
) {
|
|
1941
|
+
const first = this.#cache.entries().next().value as
|
|
1942
|
+
| [string, CachedRepresentation]
|
|
1943
|
+
| undefined;
|
|
1944
|
+
if (!first) break;
|
|
1945
|
+
this.#cache.delete(first[0]);
|
|
1946
|
+
this.#cacheBytes -= first[1].bytes.byteLength;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
#clearCache(): void {
|
|
1951
|
+
this.#cache.clear();
|
|
1952
|
+
this.#cacheBytes = 0;
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
#pruneCanonicalRevisions(paneId: string): void {
|
|
1956
|
+
const pane = this.#panes.get(paneId);
|
|
1957
|
+
if (!pane?.latest) return;
|
|
1958
|
+
const latest = pane.latest.update;
|
|
1959
|
+
const reachable = new Set([latest.revision]);
|
|
1960
|
+
for (const client of this.#clients.values()) {
|
|
1961
|
+
if (client.closed || client.paneId !== paneId) continue;
|
|
1962
|
+
const baseline = pane.revisions.get(client.baselineRevision)?.update;
|
|
1963
|
+
if (
|
|
1964
|
+
!client.reseedRequired &&
|
|
1965
|
+
baseline?.incarnation === latest.incarnation &&
|
|
1966
|
+
baseline.stateHash === client.baselineHash
|
|
1967
|
+
)
|
|
1968
|
+
reachable.add(client.baselineRevision);
|
|
1969
|
+
const encoding = client.encoding?.target.update;
|
|
1970
|
+
if (encoding?.incarnation === latest.incarnation) reachable.add(encoding.revision);
|
|
1971
|
+
const flight = client.inFlight?.envelope;
|
|
1972
|
+
if (flight?.incarnation === latest.incarnation) reachable.add(flight.canonicalRevision);
|
|
1973
|
+
}
|
|
1974
|
+
// A hidden or slow reader owns at most one baseline and one transaction.
|
|
1975
|
+
// Historical redraws with no reader cannot help a future delivery: new
|
|
1976
|
+
// readers and skipped revisions already receive an atomic current seed.
|
|
1977
|
+
// MAX_CLIENTS bounds this set to 2 * MAX_CLIENTS + 1 per pane.
|
|
1978
|
+
for (const revision of pane.revisions.keys())
|
|
1979
|
+
if (!reachable.has(revision)) {
|
|
1980
|
+
this.#releaseNativeBacking(pane.revisions.get(revision)?.nativeBacking);
|
|
1981
|
+
pane.revisions.delete(revision);
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
#pruneAckSupersededCache(paneId: string): void {
|
|
1986
|
+
const clients = [...this.#clients.values()].filter(
|
|
1987
|
+
(candidate) => !candidate.closed && candidate.paneId === paneId,
|
|
1988
|
+
);
|
|
1989
|
+
for (const [key, cached] of this.#cache) {
|
|
1990
|
+
if (cached.cachePaneId !== paneId) continue;
|
|
1991
|
+
const reachable = clients.some(
|
|
1992
|
+
(candidate) =>
|
|
1993
|
+
cached.cacheBaseRevision === candidate.baselineRevision ||
|
|
1994
|
+
(Number.isSafeInteger(cached.cacheTargetRevision) &&
|
|
1995
|
+
cached.cacheTargetRevision! > candidate.baselineRevision) ||
|
|
1996
|
+
cached.cacheTargetRevision === candidate.inFlight?.envelope.canonicalRevision,
|
|
1997
|
+
);
|
|
1998
|
+
if (reachable) continue;
|
|
1999
|
+
this.#cache.delete(key);
|
|
2000
|
+
this.#cacheBytes -= cached.bytes.byteLength;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
}
|
|
2004
|
+
|
|
2005
|
+
export function selectExactSemanticRepresentation<T extends { readonly frame: string }>(
|
|
2006
|
+
encodePatch: () => { readonly payload: T; readonly bytes: Uint8Array },
|
|
2007
|
+
encodeSeed: () => { readonly payload: T; readonly bytes: Uint8Array },
|
|
2008
|
+
observe = true,
|
|
2009
|
+
): {
|
|
2010
|
+
readonly payload: T;
|
|
2011
|
+
readonly bytes: Uint8Array;
|
|
2012
|
+
readonly observation?: Readonly<{
|
|
2013
|
+
attemptedPatchBytes: number | null;
|
|
2014
|
+
attemptedSeedBytes: number | null;
|
|
2015
|
+
selectionStatus:
|
|
2016
|
+
| "patch-preferred"
|
|
2017
|
+
| "seed-preferred"
|
|
2018
|
+
| "patch-fallback"
|
|
2019
|
+
| "legacy-patch-fallback"
|
|
2020
|
+
| "legacy-seed-fallback"
|
|
2021
|
+
| "direct-seed"
|
|
2022
|
+
| "direct-tombstone";
|
|
2023
|
+
}>;
|
|
2024
|
+
} {
|
|
2025
|
+
let patch: { readonly payload: T; readonly bytes: Uint8Array };
|
|
2026
|
+
try {
|
|
2027
|
+
patch = encodePatch();
|
|
2028
|
+
} catch (error) {
|
|
2029
|
+
if (!(error instanceof TerminalDeliveryStateTooLargeError)) throw error;
|
|
2030
|
+
let seed;
|
|
2031
|
+
try {
|
|
2032
|
+
seed = encodeSeed();
|
|
2033
|
+
} catch (seedError) {
|
|
2034
|
+
if (!(seedError instanceof TerminalDeliveryStateTooLargeError)) throw seedError;
|
|
2035
|
+
throw new ExactSemanticRepresentationSelectionError(seedError.bytes, {
|
|
2036
|
+
attemptedPatchBytes: error.bytes,
|
|
2037
|
+
attemptedSeedBytes: seedError.bytes,
|
|
2038
|
+
selectionStatus: "seed-preferred",
|
|
2039
|
+
});
|
|
2040
|
+
}
|
|
2041
|
+
if (!observe) return seed;
|
|
2042
|
+
return {
|
|
2043
|
+
...seed,
|
|
2044
|
+
observation: Object.freeze({
|
|
2045
|
+
attemptedPatchBytes: error.bytes,
|
|
2046
|
+
attemptedSeedBytes: seed.bytes.byteLength,
|
|
2047
|
+
selectionStatus: "seed-preferred" as const,
|
|
2048
|
+
}),
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
if (patch.payload.frame !== "patch") {
|
|
2052
|
+
if (!observe) return patch;
|
|
2053
|
+
return {
|
|
2054
|
+
...patch,
|
|
2055
|
+
observation: Object.freeze({
|
|
2056
|
+
attemptedPatchBytes: null,
|
|
2057
|
+
attemptedSeedBytes: patch.payload.frame === "seed" ? patch.bytes.byteLength : null,
|
|
2058
|
+
selectionStatus:
|
|
2059
|
+
patch.payload.frame === "seed" ? ("direct-seed" as const) : ("direct-tombstone" as const),
|
|
2060
|
+
}),
|
|
2061
|
+
};
|
|
2062
|
+
}
|
|
2063
|
+
if (patch.bytes.byteLength <= TERMINAL_DELIVERY_PATCH_TO_SEED_BYTES) {
|
|
2064
|
+
if (!observe) return patch;
|
|
2065
|
+
return {
|
|
2066
|
+
...patch,
|
|
2067
|
+
observation: Object.freeze({
|
|
2068
|
+
attemptedPatchBytes: patch.bytes.byteLength,
|
|
2069
|
+
attemptedSeedBytes: null,
|
|
2070
|
+
selectionStatus: "patch-preferred" as const,
|
|
2071
|
+
}),
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
try {
|
|
2075
|
+
const seed = encodeSeed();
|
|
2076
|
+
const selected = patch.bytes.byteLength <= seed.bytes.byteLength ? patch : seed;
|
|
2077
|
+
if (!observe) return selected;
|
|
2078
|
+
return {
|
|
2079
|
+
...selected,
|
|
2080
|
+
observation: Object.freeze({
|
|
2081
|
+
attemptedPatchBytes: patch.bytes.byteLength,
|
|
2082
|
+
attemptedSeedBytes: seed.bytes.byteLength,
|
|
2083
|
+
selectionStatus:
|
|
2084
|
+
selected === patch ? ("patch-preferred" as const) : ("seed-preferred" as const),
|
|
2085
|
+
}),
|
|
2086
|
+
};
|
|
2087
|
+
} catch (error) {
|
|
2088
|
+
if (!(error instanceof TerminalDeliveryStateTooLargeError)) throw error;
|
|
2089
|
+
if (!observe) return patch;
|
|
2090
|
+
return {
|
|
2091
|
+
...patch,
|
|
2092
|
+
observation: Object.freeze({
|
|
2093
|
+
attemptedPatchBytes: patch.bytes.byteLength,
|
|
2094
|
+
attemptedSeedBytes: error.bytes,
|
|
2095
|
+
selectionStatus: "patch-fallback" as const,
|
|
2096
|
+
}),
|
|
2097
|
+
};
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
|
|
2101
|
+
function completeSemanticSelectionObservation(
|
|
2102
|
+
observation: ExactSemanticSelectionObservation,
|
|
2103
|
+
selectedEncoding: "semantic-v1" | "semantic-compact-v1",
|
|
2104
|
+
legacyAttempts: Readonly<{ patchBytes: number | null; seedBytes: number | null }> | null,
|
|
2105
|
+
): SemanticSelectionObservation {
|
|
2106
|
+
const compact = selectedEncoding === "semantic-compact-v1";
|
|
2107
|
+
return Object.freeze({
|
|
2108
|
+
...observation,
|
|
2109
|
+
attemptedLegacyPatchBytes: compact
|
|
2110
|
+
? (legacyAttempts?.patchBytes ?? null)
|
|
2111
|
+
: observation.attemptedPatchBytes,
|
|
2112
|
+
attemptedLegacySeedBytes: compact
|
|
2113
|
+
? (legacyAttempts?.seedBytes ?? null)
|
|
2114
|
+
: observation.attemptedSeedBytes,
|
|
2115
|
+
attemptedLegacyPatchAtLeastBytes: null,
|
|
2116
|
+
attemptedLegacySeedAtLeastBytes: null,
|
|
2117
|
+
attemptedLegacyPatchSizeCapped: false,
|
|
2118
|
+
attemptedLegacySeedSizeCapped: false,
|
|
2119
|
+
attemptedCompactPatchBytes: compact ? observation.attemptedPatchBytes : null,
|
|
2120
|
+
attemptedCompactSeedBytes: compact ? observation.attemptedSeedBytes : null,
|
|
2121
|
+
selectedEncoding,
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
|
|
2125
|
+
function legacyFallbackObservation(
|
|
2126
|
+
frame: "seed" | "patch",
|
|
2127
|
+
compactBytes: number,
|
|
2128
|
+
legacyBytes: number,
|
|
2129
|
+
): SemanticSelectionObservation {
|
|
2130
|
+
return Object.freeze({
|
|
2131
|
+
attemptedPatchBytes: frame === "patch" ? legacyBytes : null,
|
|
2132
|
+
attemptedSeedBytes: frame === "seed" ? legacyBytes : null,
|
|
2133
|
+
attemptedLegacyPatchBytes: frame === "patch" ? legacyBytes : null,
|
|
2134
|
+
attemptedLegacySeedBytes: frame === "seed" ? legacyBytes : null,
|
|
2135
|
+
attemptedLegacyPatchAtLeastBytes: null,
|
|
2136
|
+
attemptedLegacySeedAtLeastBytes: null,
|
|
2137
|
+
attemptedLegacyPatchSizeCapped: false,
|
|
2138
|
+
attemptedLegacySeedSizeCapped: false,
|
|
2139
|
+
attemptedCompactPatchBytes: frame === "patch" ? compactBytes : null,
|
|
2140
|
+
attemptedCompactSeedBytes: frame === "seed" ? compactBytes : null,
|
|
2141
|
+
selectedEncoding: "semantic-v1",
|
|
2142
|
+
selectionStatus: frame === "patch" ? "legacy-patch-fallback" : "legacy-seed-fallback",
|
|
2143
|
+
});
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
function legacyFallbackFromSelection(
|
|
2147
|
+
legacy: ExactSemanticSelectionObservation,
|
|
2148
|
+
compact: ExactSemanticSelectionObservation,
|
|
2149
|
+
frame: string,
|
|
2150
|
+
): SemanticSelectionObservation {
|
|
2151
|
+
return Object.freeze({
|
|
2152
|
+
attemptedPatchBytes: legacy.attemptedPatchBytes,
|
|
2153
|
+
attemptedSeedBytes: legacy.attemptedSeedBytes,
|
|
2154
|
+
attemptedLegacyPatchBytes: legacy.attemptedPatchBytes,
|
|
2155
|
+
attemptedLegacySeedBytes: legacy.attemptedSeedBytes,
|
|
2156
|
+
attemptedLegacyPatchAtLeastBytes: null,
|
|
2157
|
+
attemptedLegacySeedAtLeastBytes: null,
|
|
2158
|
+
attemptedLegacyPatchSizeCapped: false,
|
|
2159
|
+
attemptedLegacySeedSizeCapped: false,
|
|
2160
|
+
attemptedCompactPatchBytes: compact.attemptedPatchBytes,
|
|
2161
|
+
attemptedCompactSeedBytes: compact.attemptedSeedBytes,
|
|
2162
|
+
selectedEncoding: "semantic-v1",
|
|
2163
|
+
selectionStatus: frame === "patch" ? "legacy-patch-fallback" : "legacy-seed-fallback",
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
function failedCompactAndLegacyObservation(
|
|
2168
|
+
frame: "seed" | "patch",
|
|
2169
|
+
compactBytes: number,
|
|
2170
|
+
legacyError: TerminalDeliveryStateTooLargeError,
|
|
2171
|
+
): SemanticSelectionObservation {
|
|
2172
|
+
const capped = legacyError instanceof TerminalDeliveryPreaccountLimitError;
|
|
2173
|
+
return Object.freeze({
|
|
2174
|
+
attemptedPatchBytes: frame === "patch" ? compactBytes : null,
|
|
2175
|
+
attemptedSeedBytes: frame === "seed" ? compactBytes : null,
|
|
2176
|
+
attemptedLegacyPatchBytes: !capped && frame === "patch" ? legacyError.bytes : null,
|
|
2177
|
+
attemptedLegacySeedBytes: !capped && frame === "seed" ? legacyError.bytes : null,
|
|
2178
|
+
attemptedLegacyPatchAtLeastBytes: capped && frame === "patch" ? legacyError.atLeastBytes : null,
|
|
2179
|
+
attemptedLegacySeedAtLeastBytes: capped && frame === "seed" ? legacyError.atLeastBytes : null,
|
|
2180
|
+
attemptedLegacyPatchSizeCapped: capped && frame === "patch",
|
|
2181
|
+
attemptedLegacySeedSizeCapped: capped && frame === "seed",
|
|
2182
|
+
attemptedCompactPatchBytes: frame === "patch" ? compactBytes : null,
|
|
2183
|
+
attemptedCompactSeedBytes: frame === "seed" ? compactBytes : null,
|
|
2184
|
+
selectedEncoding: "semantic-compact-v1",
|
|
2185
|
+
selectionStatus: frame === "patch" ? "patch-preferred" : "direct-seed",
|
|
2186
|
+
});
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
function failedCompactAndLegacySelectionObservation(
|
|
2190
|
+
compact: ExactSemanticSelectionObservation,
|
|
2191
|
+
legacy: ExactSemanticSelectionObservation,
|
|
2192
|
+
): SemanticSelectionObservation {
|
|
2193
|
+
return Object.freeze({
|
|
2194
|
+
attemptedPatchBytes: compact.attemptedPatchBytes,
|
|
2195
|
+
attemptedSeedBytes: compact.attemptedSeedBytes,
|
|
2196
|
+
attemptedLegacyPatchBytes: legacy.attemptedPatchBytes,
|
|
2197
|
+
attemptedLegacySeedBytes: legacy.attemptedSeedBytes,
|
|
2198
|
+
attemptedLegacyPatchAtLeastBytes: null,
|
|
2199
|
+
attemptedLegacySeedAtLeastBytes: null,
|
|
2200
|
+
attemptedLegacyPatchSizeCapped: false,
|
|
2201
|
+
attemptedLegacySeedSizeCapped: false,
|
|
2202
|
+
attemptedCompactPatchBytes: compact.attemptedPatchBytes,
|
|
2203
|
+
attemptedCompactSeedBytes: compact.attemptedSeedBytes,
|
|
2204
|
+
selectedEncoding: "semantic-compact-v1",
|
|
2205
|
+
selectionStatus: compact.selectionStatus,
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
function terminalSelectionObservation(observation: SemanticSelectionObservation) {
|
|
2210
|
+
return Object.freeze({
|
|
2211
|
+
selectionStatus: observation.selectionStatus,
|
|
2212
|
+
selectedEncoding: observation.selectedEncoding,
|
|
2213
|
+
attemptedLegacyPatchBytes: observation.attemptedLegacyPatchBytes,
|
|
2214
|
+
attemptedLegacySeedBytes: observation.attemptedLegacySeedBytes,
|
|
2215
|
+
attemptedLegacyPatchAtLeastBytes: observation.attemptedLegacyPatchAtLeastBytes,
|
|
2216
|
+
attemptedLegacySeedAtLeastBytes: observation.attemptedLegacySeedAtLeastBytes,
|
|
2217
|
+
attemptedLegacyPatchSizeCapped: observation.attemptedLegacyPatchSizeCapped,
|
|
2218
|
+
attemptedLegacySeedSizeCapped: observation.attemptedLegacySeedSizeCapped,
|
|
2219
|
+
attemptedCompactPatchBytes: observation.attemptedCompactPatchBytes,
|
|
2220
|
+
attemptedCompactSeedBytes: observation.attemptedCompactSeedBytes,
|
|
2221
|
+
});
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
function semanticSelectionObservationFromError(
|
|
2225
|
+
error: unknown,
|
|
2226
|
+
): SemanticSelectionObservation | null {
|
|
2227
|
+
return error instanceof TerminalDeliveryRepresentationSelectionError
|
|
2228
|
+
? error.selectionObservation
|
|
2229
|
+
: null;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
function semanticPayload(
|
|
2233
|
+
baselineRevision: number,
|
|
2234
|
+
baseline: TerminalReplicaSnapshot | null,
|
|
2235
|
+
target: RevisionRecord,
|
|
2236
|
+
): TerminalSemanticDeliveryPayload {
|
|
2237
|
+
const update = target.update;
|
|
2238
|
+
if (!target.state.snapshot) {
|
|
2239
|
+
if (update.type !== "terminal.tombstone") throw new TypeError("Missing tombstone update");
|
|
2240
|
+
return {
|
|
2241
|
+
frame: "tombstone",
|
|
2242
|
+
baseRevision: Math.max(0, baselineRevision),
|
|
2243
|
+
revision: update.revision,
|
|
2244
|
+
tombstone: update.tombstone,
|
|
2245
|
+
};
|
|
2246
|
+
}
|
|
2247
|
+
// Adjacent canonical patches are already the cheapest exact diff. A skipped
|
|
2248
|
+
// revision uses an atomic seed; the m56.2 adjacent reducer is never weakened.
|
|
2249
|
+
if (baseline && update.type === "terminal.patch" && update.baseRevision === baselineRevision)
|
|
2250
|
+
return {
|
|
2251
|
+
frame: "patch",
|
|
2252
|
+
baseRevision: baselineRevision,
|
|
2253
|
+
revision: update.revision,
|
|
2254
|
+
patch: update.patch,
|
|
2255
|
+
};
|
|
2256
|
+
return semanticSeed(target);
|
|
2257
|
+
}
|
|
2258
|
+
|
|
2259
|
+
/** Account represented cells without traversing/serializing the snapshot. */
|
|
2260
|
+
function canonicalUpdateCellCost(update: CanonicalTerminalReplicaUpdate): number {
|
|
2261
|
+
if (update.type === "terminal.tombstone") return 0;
|
|
2262
|
+
if (update.type === "terminal.seed")
|
|
2263
|
+
return update.snapshot.cols * (update.snapshot.grid.length + update.snapshot.history.length);
|
|
2264
|
+
const rows =
|
|
2265
|
+
update.patch.rows.length +
|
|
2266
|
+
(update.patch.history?.length ?? 0) +
|
|
2267
|
+
(update.patch.historyDelta?.append.length ?? 0);
|
|
2268
|
+
return Math.max(update.cols, update.patch.dimensions?.cols ?? update.cols) * rows;
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
function encodeLegacySemanticCandidate(payload: TerminalSemanticDeliveryPayload): Uint8Array {
|
|
2272
|
+
const preaccounted = preaccountSemanticTerminalUpdateBytes(
|
|
2273
|
+
payload,
|
|
2274
|
+
TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES,
|
|
2275
|
+
);
|
|
2276
|
+
if (!preaccounted.exact)
|
|
2277
|
+
throw new TerminalDeliveryPreaccountLimitError(preaccounted.atLeastBytes);
|
|
2278
|
+
const bytes = encodeSemanticTerminalUpdate(payload);
|
|
2279
|
+
if (bytes.byteLength !== preaccounted.bytes)
|
|
2280
|
+
throw new TypeError("Legacy semantic byte preaccount did not match encoding");
|
|
2281
|
+
return bytes;
|
|
2282
|
+
}
|
|
2283
|
+
|
|
2284
|
+
function semanticSeed(target: RevisionRecord): TerminalSemanticDeliveryPayload {
|
|
2285
|
+
if (!target.state.snapshot) throw new TypeError("Cannot seed a tombstone");
|
|
2286
|
+
return { frame: "seed", revision: target.update.revision, snapshot: target.state.snapshot };
|
|
2287
|
+
}
|
|
2288
|
+
|
|
2289
|
+
function emptyTombstone(): CachedRepresentation {
|
|
2290
|
+
return {
|
|
2291
|
+
bytes: new Uint8Array(),
|
|
2292
|
+
frame: "tombstone",
|
|
2293
|
+
canonicalEquivalent: false,
|
|
2294
|
+
history: "not-applicable",
|
|
2295
|
+
};
|
|
2296
|
+
}
|
|
2297
|
+
|
|
2298
|
+
function cacheKey(parts: readonly (string | number)[]): string {
|
|
2299
|
+
return JSON.stringify(parts);
|
|
2300
|
+
}
|
|
2301
|
+
|
|
2302
|
+
function rejectedConnection(
|
|
2303
|
+
negotiation: TerminalDeliveryNegotiationResult,
|
|
2304
|
+
): TerminalDeliveryConnection {
|
|
2305
|
+
return {
|
|
2306
|
+
negotiation,
|
|
2307
|
+
closed: Promise.resolve("closed"),
|
|
2308
|
+
ack: () => undefined,
|
|
2309
|
+
nack: () => undefined,
|
|
2310
|
+
setVisibility: () => undefined,
|
|
2311
|
+
close: async () => undefined,
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
function joinBytes(chunks: readonly Uint8Array[]): Uint8Array {
|
|
2316
|
+
const total = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0);
|
|
2317
|
+
const joined = new Uint8Array(total);
|
|
2318
|
+
let offset = 0;
|
|
2319
|
+
for (const chunk of chunks) {
|
|
2320
|
+
joined.set(chunk, offset);
|
|
2321
|
+
offset += chunk.byteLength;
|
|
2322
|
+
}
|
|
2323
|
+
return joined;
|
|
2324
|
+
}
|