tmux-ide 2.7.0 → 2.9.0-beta.5
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 +95 -115
- package/bin/cli.js +69987 -11819
- package/bin/cli.ts +772 -114
- package/package.json +64 -30
- package/packages/contracts/package.json +3 -2
- 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__/control.test.ts +154 -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 +466 -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 +490 -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__/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 +103 -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/control.ts +217 -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-issue.ts +83 -0
- package/packages/contracts/src/desktop-host.ts +746 -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 +60 -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 +709 -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/semantic-identity.ts +39 -0
- package/packages/contracts/src/session-runtime.ts +351 -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-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 +64 -0
- package/packages/contracts/src/workspace-pane-creation.ts +223 -0
- package/packages/contracts/src/workspace-promotion.ts +109 -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 +15 -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 +335 -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/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.test.ts +1196 -0
- package/packages/core/src/terminal-delivery.ts +2918 -0
- package/packages/core/src/terminal-replica-cold.test.ts +31 -0
- package/packages/core/src/terminal-replica-hash-cache.test.ts +201 -0
- package/packages/core/src/terminal-replica-hash-cache.ts +367 -0
- package/packages/core/src/terminal-replica.test.ts +282 -0
- package/packages/core/src/terminal-replica.ts +943 -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.d.ts +2 -2
- package/packages/daemon/dist/canonical.js +1 -1
- package/packages/daemon/dist/cli.js +37 -36
- package/packages/daemon/dist/command-center/actions/command-definitions.d.ts +4 -0
- package/packages/daemon/dist/command-center/actions/command-definitions.js +70 -0
- package/packages/daemon/dist/command-center/actions/dispatcher.d.ts +29 -0
- package/packages/daemon/dist/command-center/actions/dispatcher.js +228 -10
- package/packages/daemon/dist/command-center/actions/errors.d.ts +1 -1
- package/packages/daemon/dist/command-center/actions/handlers/_project-context.d.ts +1 -1
- package/packages/daemon/dist/command-center/actions/handlers/_project-context.js +3 -4
- package/packages/daemon/dist/command-center/actions/handlers/app-window-mutate.d.ts +8 -0
- package/packages/daemon/dist/command-center/actions/handlers/app-window-mutate.js +39 -0
- package/packages/daemon/dist/command-center/actions/handlers/config-actions.d.ts +6 -6
- package/packages/daemon/dist/command-center/actions/handlers/config-actions.js +44 -20
- package/packages/daemon/dist/command-center/actions/handlers/daemon-shutdown.d.ts +2 -1
- package/packages/daemon/dist/command-center/actions/handlers/daemon-shutdown.js +11 -1
- package/packages/daemon/dist/command-center/actions/handlers/fleet-lifecycle.d.ts +10 -0
- 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.d.ts +186 -0
- package/packages/daemon/dist/command-center/actions/handlers/workspace-multiplexer.js +55 -0
- package/packages/daemon/dist/command-center/actions/handlers/workspace-open.d.ts +16 -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.d.ts +8 -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.d.ts +8 -0
- package/packages/daemon/dist/command-center/actions/handlers/workspace-promote.js +34 -0
- package/packages/daemon/dist/command-center/actions/registry.d.ts +33 -2
- package/packages/daemon/dist/command-center/actions/registry.js +126 -0
- package/packages/daemon/dist/command-center/actions/semantic-multiplexer-actions.d.ts +3 -0
- package/packages/daemon/dist/command-center/actions/semantic-multiplexer-actions.js +16 -0
- package/packages/daemon/dist/command-center/agent-status-watch.d.ts +100 -0
- package/packages/daemon/dist/command-center/agent-status-watch.js +170 -0
- package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.d.ts +57 -0
- package/packages/daemon/dist/command-center/daemon-fleet-facts-observer.js +395 -0
- package/packages/daemon/dist/command-center/discovery.d.ts +98 -1
- package/packages/daemon/dist/command-center/discovery.js +262 -3
- package/packages/daemon/dist/command-center/owner-authority.d.ts +71 -0
- package/packages/daemon/dist/command-center/owner-authority.js +46 -0
- package/packages/daemon/dist/command-center/pane-stream-issue.d.ts +26 -0
- package/packages/daemon/dist/command-center/pane-stream-issue.js +185 -0
- package/packages/daemon/dist/command-center/resources/agent-graph-overlay.d.ts +45 -0
- package/packages/daemon/dist/command-center/resources/agent-graph-overlay.js +234 -0
- package/packages/daemon/dist/command-center/resources/application-shell.d.ts +201 -0
- package/packages/daemon/dist/command-center/resources/application-shell.js +641 -0
- package/packages/daemon/dist/command-center/resources/desktop-missions.d.ts +10 -0
- package/packages/daemon/dist/command-center/resources/desktop-missions.js +132 -0
- package/packages/daemon/dist/command-center/resources/fleet-catalog.d.ts +25 -0
- package/packages/daemon/dist/command-center/resources/fleet-catalog.js +163 -0
- package/packages/daemon/dist/command-center/resources/fleet-resource-route.d.ts +25 -0
- package/packages/daemon/dist/command-center/resources/fleet-resource-route.js +46 -0
- package/packages/daemon/dist/command-center/resources/startup-readiness-route.d.ts +38 -0
- package/packages/daemon/dist/command-center/resources/startup-readiness-route.js +121 -0
- package/packages/daemon/dist/command-center/resources/startup-readiness.d.ts +57 -0
- package/packages/daemon/dist/command-center/resources/startup-readiness.js +183 -0
- package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.d.ts +5 -0
- package/packages/daemon/dist/command-center/resources/terminal-runtime-inventory.js +24 -0
- package/packages/daemon/dist/command-center/resources/workspace-changes-authority.d.ts +39 -0
- package/packages/daemon/dist/command-center/resources/workspace-changes-authority.js +451 -0
- package/packages/daemon/dist/command-center/resources/workspace-changes-git.d.ts +63 -0
- package/packages/daemon/dist/command-center/resources/workspace-changes-git.js +222 -0
- package/packages/daemon/dist/command-center/resources/workspace-files-authority.d.ts +44 -0
- package/packages/daemon/dist/command-center/resources/workspace-files-authority.js +493 -0
- package/packages/daemon/dist/command-center/resources/workspace-missions-route.d.ts +22 -0
- package/packages/daemon/dist/command-center/resources/workspace-missions-route.js +75 -0
- package/packages/daemon/dist/command-center/resources/workspace-resource-ids.d.ts +24 -0
- package/packages/daemon/dist/command-center/resources/workspace-resource-ids.js +69 -0
- package/packages/daemon/dist/command-center/resources/workspace-resource-routes.d.ts +17 -0
- package/packages/daemon/dist/command-center/resources/workspace-resource-routes.js +116 -0
- package/packages/daemon/dist/command-center/schemas.d.ts +1 -1
- package/packages/daemon/dist/command-center/server.d.ts +57 -1
- package/packages/daemon/dist/command-center/server.js +540 -51
- package/packages/daemon/dist/command-center/terminal-attachment-issue.d.ts +22 -0
- package/packages/daemon/dist/command-center/terminal-attachment-issue.js +191 -0
- package/packages/daemon/dist/command-center/workspace-resource-observer.d.ts +50 -0
- package/packages/daemon/dist/command-center/workspace-resource-observer.js +453 -0
- package/packages/daemon/dist/command-center/ws-events.d.ts +82 -7
- package/packages/daemon/dist/command-center/ws-events.js +681 -63
- package/packages/daemon/dist/config.js +31 -25
- package/packages/daemon/dist/control/client.d.ts +23 -0
- package/packages/daemon/dist/control/client.js +105 -0
- package/packages/daemon/dist/control/dispatch.d.ts +34 -0
- package/packages/daemon/dist/control/dispatch.js +83 -0
- package/packages/daemon/dist/control/fanout.d.ts +19 -0
- package/packages/daemon/dist/control/fanout.js +37 -0
- package/packages/daemon/dist/control/frames.d.ts +23 -0
- package/packages/daemon/dist/control/frames.js +37 -0
- package/packages/daemon/dist/control/lifecycle.d.ts +45 -0
- package/packages/daemon/dist/control/lifecycle.js +124 -0
- package/packages/daemon/dist/control/server.d.ts +16 -0
- package/packages/daemon/dist/control/server.js +214 -0
- package/packages/daemon/dist/control/verbs.d.ts +11 -0
- package/packages/daemon/dist/control/verbs.js +91 -0
- package/packages/daemon/dist/detect.js +23 -20
- package/packages/daemon/dist/doctor.d.ts +18 -0
- package/packages/daemon/dist/doctor.js +127 -21
- package/packages/daemon/dist/index.d.ts +21 -2
- package/packages/daemon/dist/index.js +20 -1
- package/packages/daemon/dist/init.js +24 -22
- package/packages/daemon/dist/inspect.d.ts +7 -1
- package/packages/daemon/dist/inspect.js +33 -8
- package/packages/daemon/dist/launch.d.ts +2 -0
- 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-discovery.d.ts +27 -2
- package/packages/daemon/dist/lib/agent-discovery.js +29 -14
- package/packages/daemon/dist/lib/agent-kind.d.ts +7 -0
- package/packages/daemon/dist/lib/agent-kind.js +24 -0
- package/packages/daemon/dist/lib/app-config.d.ts +111 -0
- package/packages/daemon/dist/lib/app-config.js +130 -5
- package/packages/daemon/dist/lib/app-window-kernel.d.ts +64 -0
- package/packages/daemon/dist/lib/app-window-kernel.js +556 -0
- package/packages/daemon/dist/lib/app-window-mutation.d.ts +28 -0
- package/packages/daemon/dist/lib/app-window-mutation.js +139 -0
- package/packages/daemon/dist/lib/app-window-repository.d.ts +81 -0
- package/packages/daemon/dist/lib/app-window-repository.js +368 -0
- package/packages/daemon/dist/lib/app-window-state.d.ts +57 -0
- package/packages/daemon/dist/lib/app-window-state.js +415 -0
- package/packages/daemon/dist/lib/application-shell-app-windows.d.ts +16 -0
- package/packages/daemon/dist/lib/application-shell-app-windows.js +285 -0
- package/packages/daemon/dist/lib/auth/middleware.d.ts +1 -1
- package/packages/daemon/dist/lib/auth/middleware.js +7 -3
- package/packages/daemon/dist/lib/canonical-daemon-bootstrap.d.ts +25 -0
- package/packages/daemon/dist/lib/canonical-daemon-bootstrap.js +174 -0
- package/packages/daemon/dist/lib/canonical-daemon.d.ts +80 -14
- package/packages/daemon/dist/lib/canonical-daemon.js +507 -70
- package/packages/daemon/dist/lib/chrome-front-door.d.ts +7 -0
- package/packages/daemon/dist/lib/chrome-front-door.js +13 -0
- package/packages/daemon/dist/lib/cli-action-bridge.d.ts +8 -3
- package/packages/daemon/dist/lib/cli-action-bridge.js +112 -82
- package/packages/daemon/dist/lib/command-registry.d.ts +37 -0
- package/packages/daemon/dist/lib/command-registry.js +107 -0
- package/packages/daemon/dist/lib/config-context.d.ts +18 -0
- package/packages/daemon/dist/lib/config-context.js +34 -0
- package/packages/daemon/dist/lib/daemon-embed.d.ts +30 -0
- package/packages/daemon/dist/lib/daemon-embed.js +1060 -356
- package/packages/daemon/dist/lib/daemon-session-monitor.d.ts +50 -0
- 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.d.ts +12 -0
- package/packages/daemon/dist/lib/directory-watcher.js +118 -0
- package/packages/daemon/dist/lib/environment-identity.d.ts +9 -0
- package/packages/daemon/dist/lib/environment-identity.js +79 -0
- package/packages/daemon/dist/lib/errors.d.ts +1 -1
- package/packages/daemon/dist/lib/fleet-agent-lifecycle.d.ts +8 -0
- package/packages/daemon/dist/lib/fleet-agent-lifecycle.js +65 -0
- package/packages/daemon/dist/lib/fleet-lifecycle-authority.d.ts +21 -0
- package/packages/daemon/dist/lib/fleet-lifecycle-authority.js +437 -0
- package/packages/daemon/dist/lib/headless-daemon.d.ts +33 -0
- package/packages/daemon/dist/lib/headless-daemon.js +306 -0
- package/packages/daemon/dist/lib/launch-plan.d.ts +20 -1
- package/packages/daemon/dist/lib/launch-plan.js +96 -1
- package/packages/daemon/dist/lib/legacy-config-adapter.d.ts +12 -0
- package/packages/daemon/dist/lib/legacy-config-adapter.js +19 -0
- package/packages/daemon/dist/lib/legacy-config-migration.d.ts +15 -0
- package/packages/daemon/dist/lib/legacy-config-migration.js +110 -0
- package/packages/daemon/dist/lib/legacy-theme-compat.d.ts +14 -0
- package/packages/daemon/dist/lib/legacy-theme-compat.js +25 -0
- package/packages/daemon/dist/lib/manifest-pack.d.ts +79 -0
- package/packages/daemon/dist/lib/manifest-pack.js +232 -0
- package/packages/daemon/dist/lib/mission-projections.d.ts +24 -0
- package/packages/daemon/dist/lib/mission-projections.js +615 -0
- package/packages/daemon/dist/lib/mission-repository.d.ts +941 -0
- package/packages/daemon/dist/lib/mission-repository.js +775 -0
- package/packages/daemon/dist/lib/onboarding-marker.d.ts +13 -0
- package/packages/daemon/dist/lib/onboarding-marker.js +51 -0
- package/packages/daemon/dist/lib/pane-chrome.d.ts +12 -0
- package/packages/daemon/dist/lib/pane-chrome.js +12 -0
- package/packages/daemon/dist/lib/pane-source-credentials.d.ts +32 -0
- package/packages/daemon/dist/lib/pane-source-credentials.js +178 -0
- package/packages/daemon/dist/lib/pane-widget.d.ts +61 -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.d.ts +5 -5
- package/packages/daemon/dist/lib/project-onboard.js +17 -21
- package/packages/daemon/dist/lib/project-probe.d.ts +9 -3
- package/packages/daemon/dist/lib/project-probe.js +28 -22
- package/packages/daemon/dist/lib/project-readiness-probe.d.ts +60 -0
- package/packages/daemon/dist/lib/project-readiness-probe.js +425 -0
- package/packages/daemon/dist/lib/project-readiness.d.ts +157 -0
- package/packages/daemon/dist/lib/project-readiness.js +680 -0
- package/packages/daemon/dist/lib/project-registry.d.ts +8 -0
- package/packages/daemon/dist/lib/project-registry.js +42 -9
- package/packages/daemon/dist/lib/project-resolver.d.ts +77 -0
- package/packages/daemon/dist/lib/project-resolver.js +245 -0
- package/packages/daemon/dist/lib/project-runtime-errors.d.ts +13 -0
- package/packages/daemon/dist/lib/project-runtime-errors.js +21 -0
- package/packages/daemon/dist/lib/project-runtime-repository.d.ts +193 -0
- package/packages/daemon/dist/lib/project-runtime-repository.js +876 -0
- package/packages/daemon/dist/lib/resolved-config.d.ts +48 -0
- package/packages/daemon/dist/lib/resolved-config.js +318 -0
- package/packages/daemon/dist/lib/runtime-namespace.d.ts +34 -0
- package/packages/daemon/dist/lib/runtime-namespace.js +136 -0
- package/packages/daemon/dist/lib/semantic-resource-id.d.ts +7 -0
- package/packages/daemon/dist/lib/semantic-resource-id.js +14 -0
- package/packages/daemon/dist/lib/session-monitor.d.ts +2 -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/state-home.d.ts +2 -0
- package/packages/daemon/dist/lib/state-home.js +11 -0
- package/packages/daemon/dist/lib/theme-mode.d.ts +10 -0
- package/packages/daemon/dist/lib/theme-mode.js +9 -0
- package/packages/daemon/dist/lib/tmux-external-interaction-observer.d.ts +88 -0
- package/packages/daemon/dist/lib/tmux-external-interaction-observer.js +534 -0
- package/packages/daemon/dist/lib/tmux-interaction-options.d.ts +34 -0
- package/packages/daemon/dist/lib/tmux-interaction-options.js +126 -0
- package/packages/daemon/dist/lib/tmux-terminal-color.d.ts +18 -0
- package/packages/daemon/dist/lib/tmux-terminal-color.js +37 -0
- package/packages/daemon/dist/lib/tui-binary.d.ts +30 -5
- package/packages/daemon/dist/lib/tui-binary.js +291 -28
- package/packages/daemon/dist/lib/unix-socket-authority.d.ts +9 -0
- package/packages/daemon/dist/lib/unix-socket-authority.js +48 -0
- package/packages/daemon/dist/lib/update-check.js +5 -0
- package/packages/daemon/dist/lib/widget-asset-policy.d.ts +3 -0
- package/packages/daemon/dist/lib/widget-asset-policy.js +3 -0
- package/packages/daemon/dist/lib/widget-asset-store.d.ts +22 -0
- package/packages/daemon/dist/lib/widget-asset-store.js +166 -0
- package/packages/daemon/dist/lib/workspace-config-loader.d.ts +68 -0
- package/packages/daemon/dist/lib/workspace-config-loader.js +280 -0
- package/packages/daemon/dist/lib/workspace-multiplexer-verbs.d.ts +109 -0
- package/packages/daemon/dist/lib/workspace-multiplexer-verbs.js +1138 -0
- package/packages/daemon/dist/lib/workspace-open-handoff.d.ts +41 -0
- package/packages/daemon/dist/lib/workspace-open-handoff.js +219 -0
- package/packages/daemon/dist/lib/workspace-open.d.ts +44 -0
- package/packages/daemon/dist/lib/workspace-open.js +740 -0
- package/packages/daemon/dist/lib/workspace-pane-creation.d.ts +64 -0
- package/packages/daemon/dist/lib/workspace-pane-creation.js +1107 -0
- package/packages/daemon/dist/lib/workspace-promotion.d.ts +41 -0
- package/packages/daemon/dist/lib/workspace-promotion.js +804 -0
- package/packages/daemon/dist/lib/workspace-registry.d.ts +49 -2
- package/packages/daemon/dist/lib/workspace-registry.js +150 -23
- package/packages/daemon/dist/lib/workspace-state-repository.d.ts +139 -0
- package/packages/daemon/dist/lib/workspace-state-repository.js +790 -0
- package/packages/daemon/dist/lib/workspace-state.d.ts +37 -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.d.ts +11 -0
- package/packages/daemon/dist/migrate.js +105 -0
- package/packages/daemon/dist/restart.js +2 -2
- package/packages/daemon/dist/restore.d.ts +40 -13
- package/packages/daemon/dist/restore.js +62 -21
- package/packages/daemon/dist/schemas/inspect.d.ts +8 -0
- package/packages/daemon/dist/schemas/inspect.js +9 -1
- package/packages/daemon/dist/schemas/registry.d.ts +18 -4
- package/packages/daemon/dist/schemas/registry.js +5 -19
- package/packages/daemon/dist/schemas/ws-events.d.ts +5 -69
- package/packages/daemon/dist/schemas/ws-events.js +4 -107
- package/packages/daemon/dist/send.d.ts +41 -1
- package/packages/daemon/dist/send.js +136 -20
- package/packages/daemon/dist/server/pane-stream-upgrade.d.ts +12 -0
- package/packages/daemon/dist/server/pane-stream-upgrade.js +117 -0
- package/packages/daemon/dist/server/terminal-attachment-upgrade.d.ts +11 -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.d.ts +30 -0
- package/packages/daemon/dist/terminal/MonotonicPtyInput.js +130 -0
- package/packages/daemon/dist/terminal/NodePtyAdapter.d.ts +9 -3
- package/packages/daemon/dist/terminal/NodePtyAdapter.js +37 -10
- package/packages/daemon/dist/terminal/PtyAdapter.d.ts +93 -3
- package/packages/daemon/dist/terminal/PtyAdapter.js +18 -0
- package/packages/daemon/dist/terminal/__tests__/MockPtyAdapter.d.ts +14 -4
- package/packages/daemon/dist/terminal/__tests__/MockPtyAdapter.js +33 -6
- package/packages/daemon/dist/terminal/attachments/admission-util.d.ts +14 -0
- package/packages/daemon/dist/terminal/attachments/admission-util.js +87 -0
- package/packages/daemon/dist/terminal/attachments/agent-status-probe.d.ts +102 -0
- package/packages/daemon/dist/terminal/attachments/agent-status-probe.js +325 -0
- package/packages/daemon/dist/terminal/attachments/direct-websocket.d.ts +141 -0
- package/packages/daemon/dist/terminal/attachments/direct-websocket.js +1069 -0
- package/packages/daemon/dist/terminal/attachments/grouped-tmux.d.ts +106 -0
- package/packages/daemon/dist/terminal/attachments/grouped-tmux.js +213 -0
- package/packages/daemon/dist/terminal/attachments/lease-manager.d.ts +188 -0
- package/packages/daemon/dist/terminal/attachments/lease-manager.js +655 -0
- package/packages/daemon/dist/terminal/attachments/native-runtime.d.ts +196 -0
- package/packages/daemon/dist/terminal/attachments/native-runtime.js +1564 -0
- package/packages/daemon/dist/terminal/attachments/pty-tmux-attachment-launcher.d.ts +66 -0
- package/packages/daemon/dist/terminal/attachments/pty-tmux-attachment-launcher.js +607 -0
- package/packages/daemon/dist/terminal/attachments/semantic-pane-catalog.d.ts +81 -0
- package/packages/daemon/dist/terminal/attachments/semantic-pane-catalog.js +208 -0
- package/packages/daemon/dist/terminal/attachments/tmux-view-executor.d.ts +111 -0
- package/packages/daemon/dist/terminal/attachments/tmux-view-executor.js +825 -0
- package/packages/daemon/dist/terminal/mirror/__tests__/scripted-channel.d.ts +25 -0
- package/packages/daemon/dist/terminal/mirror/__tests__/scripted-channel.js +80 -0
- package/packages/daemon/dist/terminal/mirror/__tests__/simulated-channel.d.ts +66 -0
- package/packages/daemon/dist/terminal/mirror/__tests__/simulated-channel.js +133 -0
- package/packages/daemon/dist/terminal/mirror/control-channel.d.ts +188 -0
- package/packages/daemon/dist/terminal/mirror/control-channel.js +624 -0
- package/packages/daemon/dist/terminal/mirror/control-mode-ownership.d.ts +14 -0
- package/packages/daemon/dist/terminal/mirror/control-mode-ownership.js +30 -0
- package/packages/daemon/dist/terminal/mirror/events.d.ts +115 -0
- package/packages/daemon/dist/terminal/mirror/events.js +18 -0
- package/packages/daemon/dist/terminal/mirror/flow-ledger.d.ts +40 -0
- package/packages/daemon/dist/terminal/mirror/flow-ledger.js +56 -0
- package/packages/daemon/dist/terminal/mirror/mirror-service.d.ts +137 -0
- package/packages/daemon/dist/terminal/mirror/mirror-service.js +329 -0
- package/packages/daemon/dist/terminal/mirror/pane-feed.d.ts +90 -0
- package/packages/daemon/dist/terminal/mirror/pane-feed.js +140 -0
- package/packages/daemon/dist/terminal/mirror/session-channel.d.ts +216 -0
- package/packages/daemon/dist/terminal/mirror/session-channel.js +2301 -0
- package/packages/daemon/dist/terminal/mirror/trusted-inventory.d.ts +28 -0
- package/packages/daemon/dist/terminal/pane-stream/lease-manager.d.ts +72 -0
- package/packages/daemon/dist/terminal/pane-stream/lease-manager.js +245 -0
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.d.ts +208 -0
- package/packages/daemon/dist/terminal/pane-stream/pane-stream-websocket.js +2058 -0
- package/packages/daemon/dist/terminal/pane-stream/runtime.d.ts +26 -0
- package/packages/daemon/dist/terminal/pane-stream/runtime.js +53 -0
- package/packages/daemon/dist/terminal/pane-stream/wire-ledger.d.ts +59 -0
- package/packages/daemon/dist/terminal/pane-stream/wire-ledger.js +110 -0
- package/packages/daemon/dist/terminal/protocol/chunk-bytes.d.ts +3 -0
- package/packages/daemon/dist/terminal/protocol/chunk-bytes.js +21 -0
- package/packages/daemon/dist/terminal/protocol/control.d.ts +66 -0
- package/packages/daemon/dist/terminal/protocol/control.js +111 -0
- package/packages/daemon/dist/terminal/protocol/input-coalescer.d.ts +55 -0
- package/packages/daemon/dist/terminal/protocol/input-coalescer.js +111 -0
- package/packages/daemon/dist/terminal/protocol/layout-parse.d.ts +68 -0
- package/packages/daemon/dist/terminal/protocol/layout-parse.js +127 -0
- package/packages/daemon/dist/terminal/protocol/pane-display-name.d.ts +16 -0
- package/packages/daemon/dist/terminal/protocol/pane-display-name.js +153 -0
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.d.ts +78 -0
- package/packages/daemon/dist/terminal/protocol/session-descriptor-discovery.js +294 -0
- package/packages/daemon/dist/terminal/protocol/workspace-tmux-adapter.d.ts +90 -0
- package/packages/daemon/dist/terminal/protocol/workspace-tmux-adapter.js +213 -0
- package/packages/daemon/dist/terminal/session-runtime/authority-arbiter.d.ts +36 -0
- package/packages/daemon/dist/terminal/session-runtime/authority-arbiter.js +260 -0
- package/packages/daemon/dist/terminal/session-runtime/causal-cell-ledger.d.ts +29 -0
- package/packages/daemon/dist/terminal/session-runtime/causal-cell-ledger.js +278 -0
- package/packages/daemon/dist/terminal/session-runtime/interaction-receipt-facts.d.ts +12 -0
- package/packages/daemon/dist/terminal/session-runtime/interaction-receipt-facts.js +147 -0
- package/packages/daemon/dist/terminal/session-runtime/multiplexer-backend.d.ts +16 -0
- package/packages/daemon/dist/terminal/session-runtime/multiplexer-backend.js +116 -0
- package/packages/daemon/dist/terminal/session-runtime/registry.d.ts +148 -0
- package/packages/daemon/dist/terminal/session-runtime/registry.js +1368 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-observability.d.ts +118 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-observability.js +72 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-scheduler.d.ts +11 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-scheduler.js +10 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-trace-correlator.d.ts +18 -0
- package/packages/daemon/dist/terminal/session-runtime/runtime-trace-correlator.js +48 -0
- package/packages/daemon/dist/terminal/session-runtime/semantic-mutation-executor.d.ts +69 -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.d.ts +8 -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.d.ts +91 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-hub.js +1362 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-observation-identity.d.ts +3 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-delivery-observation-identity.js +9 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-interpreter-backend.d.ts +55 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.d.ts +91 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-interpreter.js +528 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.d.ts +50 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-owner.js +387 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-shadow-projections.d.ts +37 -0
- package/packages/daemon/dist/terminal/session-runtime/terminal-replica-shadow-projections.js +21 -0
- package/packages/daemon/dist/terminal/session-runtime/transport-binding.d.ts +75 -0
- package/packages/daemon/dist/terminal/session-runtime/transport-binding.js +474 -0
- package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.d.ts +26 -0
- package/packages/daemon/dist/terminal/session-runtime/xterm-terminal-interpreter-backend.js +276 -0
- package/packages/daemon/dist/tui/async-disposable-slot.d.ts +18 -0
- package/packages/daemon/dist/tui/async-disposable-slot.js +57 -0
- package/packages/daemon/dist/tui/chrome/cheatsheet.d.ts +59 -0
- package/packages/daemon/dist/tui/chrome/cheatsheet.js +211 -0
- package/packages/daemon/dist/tui/chrome/chip.d.ts +21 -0
- package/packages/daemon/dist/tui/chrome/chip.js +25 -0
- package/packages/daemon/dist/tui/chrome/events.d.ts +51 -0
- package/packages/daemon/dist/tui/chrome/events.js +94 -0
- package/packages/daemon/dist/tui/chrome/front-door.d.ts +16 -0
- package/packages/daemon/dist/tui/chrome/front-door.js +16 -0
- package/packages/daemon/dist/tui/chrome/kitty-keys.d.ts +41 -0
- package/packages/daemon/dist/tui/chrome/kitty-keys.js +54 -0
- package/packages/daemon/dist/tui/chrome/menu.d.ts +92 -0
- package/packages/daemon/dist/tui/chrome/menu.js +251 -0
- package/packages/daemon/dist/tui/chrome/notify-prefs.d.ts +47 -0
- package/packages/daemon/dist/tui/chrome/notify-prefs.js +13 -0
- package/packages/daemon/dist/tui/chrome/notify-state.d.ts +13 -0
- package/packages/daemon/dist/tui/chrome/notify-state.js +77 -0
- package/packages/daemon/dist/tui/chrome/notify.d.ts +361 -0
- package/packages/daemon/dist/tui/chrome/notify.js +711 -0
- package/packages/daemon/dist/tui/chrome/panels.d.ts +72 -0
- package/packages/daemon/dist/tui/chrome/panels.js +60 -0
- package/packages/daemon/dist/tui/chrome/sidebar.d.ts +77 -0
- package/packages/daemon/dist/tui/chrome/sidebar.js +183 -0
- package/packages/daemon/dist/tui/chrome/snapshot.d.ts +110 -0
- package/packages/daemon/dist/tui/chrome/snapshot.js +290 -0
- package/packages/daemon/dist/tui/chrome/statusline.d.ts +237 -0
- package/packages/daemon/dist/tui/chrome/statusline.js +552 -0
- package/packages/daemon/dist/tui/chrome/updater.d.ts +230 -0
- package/packages/daemon/dist/tui/chrome/updater.js +651 -0
- package/packages/daemon/dist/tui/chrome/welcome.d.ts +41 -0
- package/packages/daemon/dist/tui/chrome/welcome.js +117 -0
- package/packages/daemon/dist/tui/compiled.d.ts +86 -0
- package/packages/daemon/dist/tui/compiled.js +165 -0
- package/packages/daemon/dist/tui/detect/agent-resolution.d.ts +56 -0
- package/packages/daemon/dist/tui/detect/agent-resolution.js +60 -0
- package/packages/daemon/dist/tui/detect/classify.d.ts +107 -0
- package/packages/daemon/dist/tui/detect/classify.js +184 -0
- package/packages/daemon/dist/tui/detect/manifest-loader.d.ts +54 -0
- package/packages/daemon/dist/tui/detect/manifest-loader.js +242 -0
- package/packages/daemon/dist/tui/detect/manifest.d.ts +111 -0
- package/packages/daemon/dist/tui/detect/manifest.js +126 -0
- package/packages/daemon/dist/tui/detect/manifests.d.ts +40 -0
- package/packages/daemon/dist/tui/detect/manifests.js +535 -0
- package/packages/daemon/dist/tui/detect/process-tree.d.ts +96 -0
- package/packages/daemon/dist/tui/detect/process-tree.js +194 -0
- package/packages/daemon/dist/tui/detect/session-id.d.ts +110 -0
- package/packages/daemon/dist/tui/detect/session-id.js +414 -0
- package/packages/daemon/dist/tui/detect/snapshot.d.ts +27 -0
- package/packages/daemon/dist/tui/detect/snapshot.js +81 -0
- package/packages/daemon/dist/tui/integrations/claude.d.ts +65 -0
- package/packages/daemon/dist/tui/integrations/claude.js +151 -0
- package/packages/daemon/dist/tui/integrations/offer.d.ts +47 -0
- package/packages/daemon/dist/tui/integrations/offer.js +134 -0
- package/packages/daemon/dist/tui/integrations/opencode.d.ts +37 -0
- package/packages/daemon/dist/tui/integrations/opencode.js +117 -0
- package/packages/daemon/dist/tui/mirror/ack-writer.d.ts +36 -0
- package/packages/daemon/dist/tui/mirror/ack-writer.js +78 -0
- package/packages/daemon/dist/tui/mirror/activity-surface-view.d.ts +8 -0
- package/packages/daemon/dist/tui/mirror/activity-surface-view.jsx +69 -0
- package/packages/daemon/dist/tui/mirror/activity-surface.d.ts +103 -0
- package/packages/daemon/dist/tui/mirror/activity-surface.js +271 -0
- package/packages/daemon/dist/tui/mirror/agent-chip.d.ts +76 -0
- package/packages/daemon/dist/tui/mirror/agent-chip.js +84 -0
- package/packages/daemon/dist/tui/mirror/agent-lifecycle.d.ts +217 -0
- package/packages/daemon/dist/tui/mirror/agent-lifecycle.js +372 -0
- package/packages/daemon/dist/tui/mirror/agent-provisioning-executor.d.ts +42 -0
- package/packages/daemon/dist/tui/mirror/agent-provisioning-executor.js +86 -0
- package/packages/daemon/dist/tui/mirror/agent-rows.d.ts +119 -0
- package/packages/daemon/dist/tui/mirror/agent-rows.js +126 -0
- package/packages/daemon/dist/tui/mirror/ansi-palette.d.ts +3 -0
- package/packages/daemon/dist/tui/mirror/ansi-palette.js +3 -0
- package/packages/daemon/dist/tui/mirror/app-state.d.ts +114 -0
- package/packages/daemon/dist/tui/mirror/app-state.js +294 -0
- package/packages/daemon/dist/tui/mirror/application-keybindings.d.ts +18 -0
- package/packages/daemon/dist/tui/mirror/application-keybindings.js +33 -0
- package/packages/daemon/dist/tui/mirror/application-shell-daemon-connection.d.ts +53 -0
- package/packages/daemon/dist/tui/mirror/application-shell-daemon-connection.js +253 -0
- package/packages/daemon/dist/tui/mirror/application-shell-daemon-session.d.ts +22 -0
- package/packages/daemon/dist/tui/mirror/application-shell-daemon-session.js +45 -0
- package/packages/daemon/dist/tui/mirror/attention.d.ts +63 -0
- package/packages/daemon/dist/tui/mirror/attention.js +59 -0
- package/packages/daemon/dist/tui/mirror/blit.d.ts +82 -0
- package/packages/daemon/dist/tui/mirror/blit.js +120 -0
- package/packages/daemon/dist/tui/mirror/canonical-workspace-routing.d.ts +11 -0
- package/packages/daemon/dist/tui/mirror/canonical-workspace-routing.js +45 -0
- package/packages/daemon/dist/tui/mirror/changes-surface-view.d.ts +19 -0
- package/packages/daemon/dist/tui/mirror/changes-surface-view.jsx +92 -0
- package/packages/daemon/dist/tui/mirror/changes-surface.d.ts +115 -0
- package/packages/daemon/dist/tui/mirror/changes-surface.js +210 -0
- package/packages/daemon/dist/tui/mirror/composite-layout.d.ts +91 -0
- package/packages/daemon/dist/tui/mirror/composite-layout.js +539 -0
- package/packages/daemon/dist/tui/mirror/configless-session-bootstrap.d.ts +39 -0
- package/packages/daemon/dist/tui/mirror/configless-session-bootstrap.js +133 -0
- package/packages/daemon/dist/tui/mirror/dialog-model.d.ts +154 -0
- package/packages/daemon/dist/tui/mirror/dialog-model.js +183 -0
- package/packages/daemon/dist/tui/mirror/dialog-stack-core.d.ts +45 -0
- package/packages/daemon/dist/tui/mirror/dialog-stack-core.js +232 -0
- package/packages/daemon/dist/tui/mirror/dialog-stack.d.ts +2 -0
- package/packages/daemon/dist/tui/mirror/dialog-stack.js +2 -0
- package/packages/daemon/dist/tui/mirror/diff-model.d.ts +169 -0
- package/packages/daemon/dist/tui/mirror/diff-model.js +332 -0
- package/packages/daemon/dist/tui/mirror/editor-buffer.d.ts +24 -0
- package/packages/daemon/dist/tui/mirror/editor-buffer.js +47 -0
- package/packages/daemon/dist/tui/mirror/editor-open-policy.d.ts +9 -0
- package/packages/daemon/dist/tui/mirror/editor-open-policy.js +9 -0
- package/packages/daemon/dist/tui/mirror/features/changes/contract.d.ts +75 -0
- package/packages/daemon/dist/tui/mirror/features/changes/controller.d.ts +10 -0
- package/packages/daemon/dist/tui/mirror/features/changes/controller.js +454 -0
- package/packages/daemon/dist/tui/mirror/features/changes/feature.d.ts +10 -0
- package/packages/daemon/dist/tui/mirror/features/changes/feature.jsx +9 -0
- package/packages/daemon/dist/tui/mirror/features/dialogs/contract.d.ts +47 -0
- package/packages/daemon/dist/tui/mirror/features/dialogs/contract.js +1 -0
- package/packages/daemon/dist/tui/mirror/features/dialogs/feature.d.ts +12 -0
- package/packages/daemon/dist/tui/mirror/features/dialogs/feature.jsx +123 -0
- package/packages/daemon/dist/tui/mirror/features/dialogs/session.d.ts +9 -0
- package/packages/daemon/dist/tui/mirror/features/dialogs/session.js +160 -0
- package/packages/daemon/dist/tui/mirror/features/files/feature.d.ts +16 -0
- package/packages/daemon/dist/tui/mirror/features/files/feature.jsx +15 -0
- package/packages/daemon/dist/tui/mirror/features/files/session.d.ts +133 -0
- package/packages/daemon/dist/tui/mirror/features/files/session.js +617 -0
- package/packages/daemon/dist/tui/mirror/features/home/feature.d.ts +28 -0
- package/packages/daemon/dist/tui/mirror/features/home/feature.jsx +122 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/contract.d.ts +84 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/contract.js +3 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/feature.d.ts +6 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/feature.jsx +5 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/session.d.ts +5 -0
- package/packages/daemon/dist/tui/mirror/features/missions-activity/session.js +377 -0
- package/packages/daemon/dist/tui/mirror/features/palette/contract.d.ts +116 -0
- package/packages/daemon/dist/tui/mirror/features/palette/contract.js +9 -0
- package/packages/daemon/dist/tui/mirror/features/palette/feature.d.ts +4 -0
- package/packages/daemon/dist/tui/mirror/features/palette/feature.js +3 -0
- package/packages/daemon/dist/tui/mirror/features/palette/session.d.ts +2 -0
- package/packages/daemon/dist/tui/mirror/features/palette/session.js +393 -0
- package/packages/daemon/dist/tui/mirror/features/palette/surface.d.ts +7 -0
- package/packages/daemon/dist/tui/mirror/features/palette/surface.jsx +48 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/contract.d.ts +17 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/contract.js +1 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/feature.d.ts +3 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/feature.jsx +2 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/session.d.ts +8 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/session.js +148 -0
- package/packages/daemon/dist/tui/mirror/features/performance-hud/surface.d.ts +17 -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.d.ts +9 -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.d.ts +71 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/contract.js +1 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/feature.d.ts +23 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/feature.jsx +103 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/session.d.ts +23 -0
- package/packages/daemon/dist/tui/mirror/features/rich-preview/session.js +310 -0
- package/packages/daemon/dist/tui/mirror/features/settings/catalog.d.ts +7 -0
- package/packages/daemon/dist/tui/mirror/features/settings/catalog.js +10 -0
- package/packages/daemon/dist/tui/mirror/features/settings/contract.d.ts +35 -0
- package/packages/daemon/dist/tui/mirror/features/settings/contract.js +1 -0
- package/packages/daemon/dist/tui/mirror/features/settings/feature.d.ts +3 -0
- package/packages/daemon/dist/tui/mirror/features/settings/feature.js +2 -0
- package/packages/daemon/dist/tui/mirror/features/settings/session.d.ts +3 -0
- package/packages/daemon/dist/tui/mirror/features/settings/session.js +309 -0
- package/packages/daemon/dist/tui/mirror/file-tree.d.ts +142 -0
- package/packages/daemon/dist/tui/mirror/file-tree.js +283 -0
- package/packages/daemon/dist/tui/mirror/files-surface-view.d.ts +17 -0
- package/packages/daemon/dist/tui/mirror/files-surface-view.jsx +92 -0
- package/packages/daemon/dist/tui/mirror/files-surface.d.ts +123 -0
- package/packages/daemon/dist/tui/mirror/files-surface.js +237 -0
- package/packages/daemon/dist/tui/mirror/focus-projection.d.ts +20 -0
- package/packages/daemon/dist/tui/mirror/focus-projection.js +80 -0
- package/packages/daemon/dist/tui/mirror/folder-picker.d.ts +38 -0
- package/packages/daemon/dist/tui/mirror/folder-picker.js +114 -0
- package/packages/daemon/dist/tui/mirror/frame-coalescer.d.ts +29 -0
- package/packages/daemon/dist/tui/mirror/frame-coalescer.js +74 -0
- package/packages/daemon/dist/tui/mirror/home-model.d.ts +81 -0
- package/packages/daemon/dist/tui/mirror/home-model.js +125 -0
- package/packages/daemon/dist/tui/mirror/home-surface-model.d.ts +113 -0
- package/packages/daemon/dist/tui/mirror/home-surface-model.js +297 -0
- package/packages/daemon/dist/tui/mirror/home-surface.d.ts +11 -0
- package/packages/daemon/dist/tui/mirror/home-surface.jsx +110 -0
- package/packages/daemon/dist/tui/mirror/host-terminal.d.ts +28 -0
- package/packages/daemon/dist/tui/mirror/host-terminal.js +33 -0
- package/packages/daemon/dist/tui/mirror/hosted.d.ts +179 -0
- package/packages/daemon/dist/tui/mirror/hosted.js +239 -0
- package/packages/daemon/dist/tui/mirror/input-lifecycle.d.ts +140 -0
- package/packages/daemon/dist/tui/mirror/input-lifecycle.js +147 -0
- package/packages/daemon/dist/tui/mirror/interaction-flow.d.ts +30 -0
- package/packages/daemon/dist/tui/mirror/interaction-flow.js +41 -0
- package/packages/daemon/dist/tui/mirror/legacy/missions-workspace-loader.d.ts +19 -0
- package/packages/daemon/dist/tui/mirror/legacy/missions-workspace-loader.js +84 -0
- package/packages/daemon/dist/tui/mirror/menu-model.d.ts +89 -0
- package/packages/daemon/dist/tui/mirror/menu-model.js +143 -0
- package/packages/daemon/dist/tui/mirror/missions-dashboard.d.ts +68 -0
- package/packages/daemon/dist/tui/mirror/missions-dashboard.js +261 -0
- package/packages/daemon/dist/tui/mirror/missions-render-fixtures.d.ts +13 -0
- package/packages/daemon/dist/tui/mirror/missions-render-fixtures.js +330 -0
- package/packages/daemon/dist/tui/mirror/missions-surface-controller.d.ts +84 -0
- package/packages/daemon/dist/tui/mirror/missions-surface-controller.js +314 -0
- package/packages/daemon/dist/tui/mirror/missions-surface.d.ts +17 -0
- package/packages/daemon/dist/tui/mirror/missions-surface.jsx +239 -0
- package/packages/daemon/dist/tui/mirror/missions-workspace.d.ts +341 -0
- package/packages/daemon/dist/tui/mirror/missions-workspace.js +1399 -0
- package/packages/daemon/dist/tui/mirror/multiplexer-action-executor.d.ts +71 -0
- package/packages/daemon/dist/tui/mirror/multiplexer-action-executor.js +233 -0
- package/packages/daemon/dist/tui/mirror/open-tui-pane-stream-socket.d.ts +16 -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.d.ts +19 -0
- package/packages/daemon/dist/tui/mirror/open-tui-verified-routing.js +45 -0
- package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.d.ts +36 -0
- package/packages/daemon/dist/tui/mirror/open-tui-workspace-runtime-port.js +1069 -0
- package/packages/daemon/dist/tui/mirror/palette-surface-adapter.d.ts +58 -0
- package/packages/daemon/dist/tui/mirror/palette-surface-adapter.js +384 -0
- package/packages/daemon/dist/tui/mirror/palette.d.ts +315 -0
- package/packages/daemon/dist/tui/mirror/palette.js +522 -0
- package/packages/daemon/dist/tui/mirror/pane-frame-state.d.ts +68 -0
- package/packages/daemon/dist/tui/mirror/pane-frame-state.js +124 -0
- package/packages/daemon/dist/tui/mirror/pane-mirror.d.ts +205 -0
- package/packages/daemon/dist/tui/mirror/pane-mirror.js +584 -0
- package/packages/daemon/dist/tui/mirror/pane-surface.d.ts +257 -0
- package/packages/daemon/dist/tui/mirror/pane-surface.jsx +855 -0
- package/packages/daemon/dist/tui/mirror/panel-host-reactive.d.ts +7 -0
- package/packages/daemon/dist/tui/mirror/panel-host-reactive.js +13 -0
- package/packages/daemon/dist/tui/mirror/panel-host.d.ts +69 -0
- package/packages/daemon/dist/tui/mirror/panel-host.js +242 -0
- package/packages/daemon/dist/tui/mirror/perf-tap.d.ts +13 -0
- package/packages/daemon/dist/tui/mirror/perf-tap.js +32 -0
- package/packages/daemon/dist/tui/mirror/performance-events.d.ts +404 -0
- package/packages/daemon/dist/tui/mirror/performance-events.js +46 -0
- package/packages/daemon/dist/tui/mirror/recipe-components.d.ts +93 -0
- package/packages/daemon/dist/tui/mirror/recipe-components.jsx +135 -0
- package/packages/daemon/dist/tui/mirror/recipes.d.ts +90 -0
- package/packages/daemon/dist/tui/mirror/recipes.js +395 -0
- package/packages/daemon/dist/tui/mirror/reference-performance-trace.d.ts +80 -0
- package/packages/daemon/dist/tui/mirror/reference-performance-trace.js +597 -0
- package/packages/daemon/dist/tui/mirror/renderer-commands.d.ts +60 -0
- package/packages/daemon/dist/tui/mirror/renderer-commands.js +250 -0
- package/packages/daemon/dist/tui/mirror/resize-model.d.ts +76 -0
- package/packages/daemon/dist/tui/mirror/resize-model.js +105 -0
- package/packages/daemon/dist/tui/mirror/resize-transaction.d.ts +102 -0
- package/packages/daemon/dist/tui/mirror/resize-transaction.js +221 -0
- package/packages/daemon/dist/tui/mirror/rich-placement-projection.d.ts +64 -0
- package/packages/daemon/dist/tui/mirror/rich-placement-projection.js +80 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-appearance-owner.d.ts +22 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-appearance-owner.js +79 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-bootstrap.d.ts +61 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-bootstrap.js +51 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-generation-starter.d.ts +26 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-generation-starter.js +80 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog-owner.d.ts +21 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog-owner.js +88 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog.d.ts +60 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-home-catalog.js +320 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-host-focus-control-binding.d.ts +28 -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.d.ts +16 -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.d.ts +38 -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.d.ts +43 -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.d.ts +5 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-input-readiness.js +20 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-lifecycle.d.ts +72 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-lifecycle.js +297 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-optional-features.d.ts +14 -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.d.ts +23 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-palette-command-owner.js +61 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-palette-input.d.ts +31 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-palette-input.js +60 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-input.d.ts +22 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-input.js +30 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-owner.d.ts +14 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pane-rename-owner.js +38 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-pending-terminal-input.d.ts +53 -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.d.ts +20 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-performance-log.js +81 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-post-render-runtime.d.ts +37 -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.d.ts +21 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-root-configuration.js +21 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-root-renderer.d.ts +9 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-root-renderer.js +27 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-session-focus-owner.d.ts +14 -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.d.ts +34 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-shell-binding.js +307 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-shell-viewport.d.ts +8 -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.d.ts +6 -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.d.ts +3 -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.d.ts +15 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-input-ingress.js +96 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.d.ts +65 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-interaction-controller.js +1326 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-palette-owner.d.ts +65 -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.d.ts +4 -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.d.ts +15 -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.d.ts +47 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-selection-owner.js +161 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace-policy.d.ts +44 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace-policy.js +177 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace.d.ts +103 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-terminal-workspace.jsx +720 -0
- package/packages/daemon/dist/tui/mirror/runtime/application-theme-repaint.d.ts +24 -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.d.ts +15 -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.d.ts +17 -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.d.ts +64 -0
- package/packages/daemon/dist/tui/mirror/runtime/causal-cell-client-ledger.js +271 -0
- package/packages/daemon/dist/tui/mirror/runtime/causal-cell-input-fixture.d.ts +12 -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.d.ts +15 -0
- package/packages/daemon/dist/tui/mirror/runtime/changes-deferred-identity.js +17 -0
- package/packages/daemon/dist/tui/mirror/runtime/daemon-authority-rebind.d.ts +29 -0
- package/packages/daemon/dist/tui/mirror/runtime/daemon-authority-rebind.js +128 -0
- package/packages/daemon/dist/tui/mirror/runtime/deferred-intent-queue.d.ts +12 -0
- package/packages/daemon/dist/tui/mirror/runtime/deferred-intent-queue.js +40 -0
- package/packages/daemon/dist/tui/mirror/runtime/editor-primitives.d.ts +23 -0
- package/packages/daemon/dist/tui/mirror/runtime/editor-primitives.js +39 -0
- package/packages/daemon/dist/tui/mirror/runtime/file-content-primitives.d.ts +3 -0
- package/packages/daemon/dist/tui/mirror/runtime/file-content-primitives.js +9 -0
- package/packages/daemon/dist/tui/mirror/runtime/fleet-lifecycle-client.d.ts +4 -0
- package/packages/daemon/dist/tui/mirror/runtime/fleet-lifecycle-client.js +27 -0
- package/packages/daemon/dist/tui/mirror/runtime/focus-framebuffer-projection.d.ts +16 -0
- package/packages/daemon/dist/tui/mirror/runtime/focus-framebuffer-projection.js +53 -0
- package/packages/daemon/dist/tui/mirror/runtime/generation-bound-slot.d.ts +7 -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.d.ts +17 -0
- package/packages/daemon/dist/tui/mirror/runtime/host-local-tmux-adapter.js +90 -0
- package/packages/daemon/dist/tui/mirror/runtime/hosted-tty-size-bridge.d.ts +55 -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.d.ts +11 -0
- package/packages/daemon/dist/tui/mirror/runtime/latest-intent-fence.js +14 -0
- package/packages/daemon/dist/tui/mirror/runtime/local-view-controller.d.ts +30 -0
- package/packages/daemon/dist/tui/mirror/runtime/local-view-controller.js +58 -0
- package/packages/daemon/dist/tui/mirror/runtime/modal-admission-coordinator.d.ts +44 -0
- package/packages/daemon/dist/tui/mirror/runtime/modal-admission-coordinator.js +118 -0
- package/packages/daemon/dist/tui/mirror/runtime/modal-pointer-capture.d.ts +13 -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.d.ts +68 -0
- package/packages/daemon/dist/tui/mirror/runtime/open-tui-generation-host.js +834 -0
- package/packages/daemon/dist/tui/mirror/runtime/open-tui-session-owner.d.ts +19 -0
- package/packages/daemon/dist/tui/mirror/runtime/open-tui-session-owner.js +146 -0
- package/packages/daemon/dist/tui/mirror/runtime/optional-feature-registry.d.ts +45 -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.d.ts +11 -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.d.ts +55 -0
- package/packages/daemon/dist/tui/mirror/runtime/palette-production-controller.js +126 -0
- package/packages/daemon/dist/tui/mirror/runtime/pane-resize-geometry.d.ts +11 -0
- package/packages/daemon/dist/tui/mirror/runtime/pane-resize-geometry.js +13 -0
- package/packages/daemon/dist/tui/mirror/runtime/pane-scoped-terminal-surface.d.ts +42 -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.d.ts +11 -0
- package/packages/daemon/dist/tui/mirror/runtime/product-surface-policy.js +12 -0
- package/packages/daemon/dist/tui/mirror/runtime/renderer-cadence.d.ts +4 -0
- package/packages/daemon/dist/tui/mirror/runtime/renderer-cadence.js +4 -0
- package/packages/daemon/dist/tui/mirror/runtime/resize-terminal-pane.d.ts +35 -0
- package/packages/daemon/dist/tui/mirror/runtime/resize-terminal-pane.js +91 -0
- package/packages/daemon/dist/tui/mirror/runtime/rich-preview-demand.d.ts +14 -0
- package/packages/daemon/dist/tui/mirror/runtime/rich-preview-demand.js +14 -0
- package/packages/daemon/dist/tui/mirror/runtime/runtime-layout-presentation.d.ts +20 -0
- package/packages/daemon/dist/tui/mirror/runtime/runtime-layout-presentation.js +111 -0
- package/packages/daemon/dist/tui/mirror/runtime/select-terminal-pane.d.ts +25 -0
- package/packages/daemon/dist/tui/mirror/runtime/select-terminal-pane.js +90 -0
- package/packages/daemon/dist/tui/mirror/runtime/semantic-pane-publication.d.ts +10 -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.d.ts +15 -0
- package/packages/daemon/dist/tui/mirror/runtime/semantic-shell-viewport-resize.js +56 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-dimensions-owner.d.ts +9 -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.d.ts +52 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-fast-lane-renderer-adapter.js +610 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-frame-readiness.d.ts +16 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-frame-readiness.js +84 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-host-focus.d.ts +41 -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.d.ts +3 -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.d.ts +10 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-input-adapter.js +50 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-layout-projection.d.ts +22 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-layout-projection.js +28 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-pane-input-router.d.ts +23 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-pane-input-router.js +82 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-selection.d.ts +66 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-selection.js +141 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-session-handoff.d.ts +50 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-session-handoff.js +89 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-tool-readiness.d.ts +31 -0
- package/packages/daemon/dist/tui/mirror/runtime/terminal-tool-readiness.js +64 -0
- package/packages/daemon/dist/tui/mirror/runtime/tool-resource-controller.d.ts +92 -0
- package/packages/daemon/dist/tui/mirror/runtime/tool-resource-controller.js +636 -0
- package/packages/daemon/dist/tui/mirror/runtime/tool-resource-projection.d.ts +59 -0
- package/packages/daemon/dist/tui/mirror/runtime/tool-resource-projection.js +169 -0
- package/packages/daemon/dist/tui/mirror/runtime/viewport-fit-coordinator.d.ts +8 -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.d.ts +22 -0
- package/packages/daemon/dist/tui/mirror/runtime/workspace-terminal-fast-lane.js +498 -0
- package/packages/daemon/dist/tui/mirror/scrollbar-model.d.ts +35 -0
- package/packages/daemon/dist/tui/mirror/scrollbar-model.js +64 -0
- package/packages/daemon/dist/tui/mirror/search-model.d.ts +41 -0
- package/packages/daemon/dist/tui/mirror/search-model.js +62 -0
- package/packages/daemon/dist/tui/mirror/selection.d.ts +175 -0
- package/packages/daemon/dist/tui/mirror/selection.js +264 -0
- package/packages/daemon/dist/tui/mirror/semantic-pane-render-source.d.ts +147 -0
- package/packages/daemon/dist/tui/mirror/semantic-pane-render-source.js +562 -0
- package/packages/daemon/dist/tui/mirror/semantic-session-view.d.ts +86 -0
- package/packages/daemon/dist/tui/mirror/semantic-session-view.js +269 -0
- package/packages/daemon/dist/tui/mirror/settings-model.d.ts +108 -0
- package/packages/daemon/dist/tui/mirror/settings-model.js +304 -0
- package/packages/daemon/dist/tui/mirror/shell-chrome.d.ts +151 -0
- package/packages/daemon/dist/tui/mirror/shell-chrome.js +313 -0
- package/packages/daemon/dist/tui/mirror/size-truth.d.ts +92 -0
- package/packages/daemon/dist/tui/mirror/size-truth.js +104 -0
- package/packages/daemon/dist/tui/mirror/spans.d.ts +26 -0
- package/packages/daemon/dist/tui/mirror/spans.js +31 -0
- package/packages/daemon/dist/tui/mirror/status-grammar.d.ts +18 -0
- package/packages/daemon/dist/tui/mirror/status-grammar.js +29 -0
- package/packages/daemon/dist/tui/mirror/terminal-surface.d.ts +55 -0
- package/packages/daemon/dist/tui/mirror/terminal-surface.js +92 -0
- package/packages/daemon/dist/tui/mirror/terminal-text.d.ts +9 -0
- package/packages/daemon/dist/tui/mirror/terminal-text.js +38 -0
- package/packages/daemon/dist/tui/mirror/theme.d.ts +207 -0
- package/packages/daemon/dist/tui/mirror/theme.js +744 -0
- package/packages/daemon/dist/tui/mirror/ui/agent-badge.d.ts +11 -0
- package/packages/daemon/dist/tui/mirror/ui/agent-badge.jsx +14 -0
- package/packages/daemon/dist/tui/mirror/ui/badge.d.ts +13 -0
- package/packages/daemon/dist/tui/mirror/ui/badge.jsx +15 -0
- package/packages/daemon/dist/tui/mirror/ui/button.d.ts +26 -0
- package/packages/daemon/dist/tui/mirror/ui/button.jsx +66 -0
- package/packages/daemon/dist/tui/mirror/ui/dialog.d.ts +19 -0
- package/packages/daemon/dist/tui/mirror/ui/dialog.jsx +8 -0
- package/packages/daemon/dist/tui/mirror/ui/index.d.ts +16 -0
- package/packages/daemon/dist/tui/mirror/ui/index.js +16 -0
- package/packages/daemon/dist/tui/mirror/ui/key-hint.d.ts +13 -0
- package/packages/daemon/dist/tui/mirror/ui/key-hint.jsx +39 -0
- package/packages/daemon/dist/tui/mirror/ui/keyboard-router.d.ts +25 -0
- package/packages/daemon/dist/tui/mirror/ui/keyboard-router.jsx +46 -0
- package/packages/daemon/dist/tui/mirror/ui/menu.d.ts +24 -0
- package/packages/daemon/dist/tui/mirror/ui/menu.jsx +15 -0
- package/packages/daemon/dist/tui/mirror/ui/navigation-row.d.ts +21 -0
- package/packages/daemon/dist/tui/mirror/ui/navigation-row.jsx +62 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-frame.d.ts +25 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-frame.jsx +52 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-host.d.ts +24 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-host.jsx +33 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-list-row.d.ts +13 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-list-row.jsx +23 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-model.d.ts +29 -0
- package/packages/daemon/dist/tui/mirror/ui/overlay-model.js +45 -0
- package/packages/daemon/dist/tui/mirror/ui/state.d.ts +27 -0
- package/packages/daemon/dist/tui/mirror/ui/state.js +171 -0
- package/packages/daemon/dist/tui/mirror/ui/status-bar.d.ts +43 -0
- package/packages/daemon/dist/tui/mirror/ui/status-bar.jsx +102 -0
- package/packages/daemon/dist/tui/mirror/ui/surface.d.ts +14 -0
- package/packages/daemon/dist/tui/mirror/ui/surface.jsx +45 -0
- package/packages/daemon/dist/tui/mirror/ui/tabs.d.ts +26 -0
- package/packages/daemon/dist/tui/mirror/ui/tabs.jsx +88 -0
- package/packages/daemon/dist/tui/mirror/widget-fallback.d.ts +15 -0
- package/packages/daemon/dist/tui/mirror/widget-fallback.js +52 -0
- package/packages/daemon/dist/tui/mirror/widget-surface-model.d.ts +26 -0
- package/packages/daemon/dist/tui/mirror/widget-surface-model.js +145 -0
- package/packages/daemon/dist/tui/mirror/widget-surface.d.ts +13 -0
- package/packages/daemon/dist/tui/mirror/widget-surface.jsx +31 -0
- package/packages/daemon/dist/tui/mirror/workspace/agent-terminal-canvas.d.ts +53 -0
- package/packages/daemon/dist/tui/mirror/workspace/agent-terminal-canvas.js +77 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-root-controller.d.ts +266 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-root-controller.js +99 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-shell-controller.d.ts +83 -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.d.ts +5 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-shell-surface-commands.js +28 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-shell.d.ts +49 -0
- package/packages/daemon/dist/tui/mirror/workspace/application-shell.js +97 -0
- package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface-view.d.ts +11 -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.d.ts +128 -0
- package/packages/daemon/dist/tui/mirror/workspace/command-palette-surface.js +342 -0
- package/packages/daemon/dist/tui/mirror/workspace/icons.d.ts +154 -0
- package/packages/daemon/dist/tui/mirror/workspace/icons.js +43 -0
- package/packages/daemon/dist/tui/mirror/workspace/pane-action-menu.d.ts +24 -0
- package/packages/daemon/dist/tui/mirror/workspace/pane-action-menu.jsx +20 -0
- package/packages/daemon/dist/tui/mirror/workspace/pane-frame.d.ts +143 -0
- package/packages/daemon/dist/tui/mirror/workspace/pane-frame.js +452 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-chrome.d.ts +152 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-chrome.js +555 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-header.d.ts +58 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-pane-header.jsx +93 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-window-strip.d.ts +75 -0
- package/packages/daemon/dist/tui/mirror/workspace/terminal-window-strip.jsx +253 -0
- package/packages/daemon/dist/tui/mirror/workspace/text.d.ts +2 -0
- package/packages/daemon/dist/tui/mirror/workspace/text.js +27 -0
- package/packages/daemon/dist/tui/mirror/workspace/workbench-controller.d.ts +23 -0
- package/packages/daemon/dist/tui/mirror/workspace/workbench-controller.js +34 -0
- package/packages/daemon/dist/tui/mirror/workspace/workbench-shell.d.ts +123 -0
- package/packages/daemon/dist/tui/mirror/workspace/workbench-shell.js +286 -0
- package/packages/daemon/dist/tui/mirror/workspace-ui-state.d.ts +174 -0
- package/packages/daemon/dist/tui/mirror/workspace-ui-state.js +885 -0
- package/packages/daemon/dist/tui/readiness.d.ts +22 -0
- package/packages/daemon/dist/tui/readiness.js +34 -0
- package/packages/daemon/dist/tui/team/entry.d.ts +37 -0
- package/packages/daemon/dist/tui/team/entry.js +20 -0
- package/packages/daemon/dist/tui/team/fuzzy.d.ts +38 -0
- package/packages/daemon/dist/tui/team/fuzzy.js +141 -0
- package/packages/daemon/dist/tui/team/home.d.ts +94 -0
- package/packages/daemon/dist/tui/team/home.js +115 -0
- package/packages/daemon/dist/tui/team/input.d.ts +22 -0
- package/packages/daemon/dist/tui/team/input.js +21 -0
- package/packages/daemon/dist/tui/team/keymap.d.ts +33 -0
- package/packages/daemon/dist/tui/team/keymap.js +99 -0
- package/packages/daemon/dist/tui/team/mouse.d.ts +18 -0
- package/packages/daemon/dist/tui/team/mouse.js +17 -0
- package/packages/daemon/dist/tui/team/nav.d.ts +21 -0
- package/packages/daemon/dist/tui/team/nav.js +33 -0
- package/packages/daemon/dist/tui/team/preview.d.ts +19 -0
- package/packages/daemon/dist/tui/team/preview.js +35 -0
- package/packages/daemon/dist/tui/team/projects.d.ts +52 -0
- package/packages/daemon/dist/tui/team/projects.js +159 -0
- package/packages/daemon/dist/tui/team/report.d.ts +51 -0
- package/packages/daemon/dist/tui/team/report.js +37 -0
- package/packages/daemon/dist/tui/team/sessions.d.ts +235 -0
- package/packages/daemon/dist/tui/team/sessions.js +292 -0
- package/packages/daemon/dist/tui/team/tree.d.ts +41 -0
- package/packages/daemon/dist/tui/team/tree.js +42 -0
- package/packages/daemon/dist/tui/team/wait-receipts.d.ts +60 -0
- package/packages/daemon/dist/tui/team/wait-receipts.js +153 -0
- package/packages/daemon/dist/tui/team/wait.d.ts +62 -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.d.ts +5 -9
- package/packages/daemon/dist/widgets/lib/watcher.js +5 -92
- package/packages/daemon/dist/widgets/resolve.js +10 -7
- 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 +38 -36
- 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-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 +61 -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-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/client.ts +128 -0
- package/packages/daemon/src/control/dispatch.ts +107 -0
- package/packages/daemon/src/control/fanout.ts +44 -0
- package/packages/daemon/src/control/frames.ts +40 -0
- package/packages/daemon/src/control/lifecycle.ts +163 -0
- package/packages/daemon/src/control/server.ts +237 -0
- package/packages/daemon/src/control/verbs.ts +118 -0
- package/packages/daemon/src/detect.ts +25 -20
- package/packages/daemon/src/doctor.ts +133 -33
- 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-discovery.ts +53 -13
- package/packages/daemon/src/lib/agent-kind.ts +23 -0
- package/packages/daemon/src/lib/app-config.ts +143 -9
- 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/canonical-daemon-bootstrap.ts +266 -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 +1347 -387
- 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/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 +406 -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/manifest-pack.ts +255 -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/resolved-config.ts +425 -0
- package/packages/daemon/src/lib/runtime-namespace.ts +186 -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/state-home.ts +12 -0
- package/packages/daemon/src/lib/theme-mode.ts +11 -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-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/update-check.ts +5 -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 +1406 -0
- package/packages/daemon/src/lib/workspace-promotion.ts +1031 -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 +67 -24
- 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 +191 -22
- 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 +2206 -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 +827 -0
- package/packages/daemon/src/terminal/mirror/control-mode-ownership.ts +34 -0
- package/packages/daemon/src/terminal/mirror/events.ts +128 -0
- package/packages/daemon/src/terminal/mirror/flow-ledger.ts +65 -0
- package/packages/daemon/src/terminal/mirror/mirror-service.ts +480 -0
- package/packages/daemon/src/terminal/mirror/pane-feed.ts +193 -0
- package/packages/daemon/src/terminal/mirror/session-channel.ts +2820 -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 +2612 -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/{tui/mirror → terminal/protocol}/control.ts +39 -6
- package/packages/daemon/src/{tui/mirror → terminal/protocol}/input-coalescer.ts +18 -7
- package/packages/daemon/src/terminal/protocol/layout-parse.ts +154 -0
- package/packages/daemon/src/terminal/protocol/pane-display-name.ts +185 -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 +312 -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/registry.ts +2047 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-observability.ts +267 -0
- package/packages/daemon/src/terminal/session-runtime/runtime-scheduler.ts +22 -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 +1806 -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 +64 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-interpreter.ts +690 -0
- package/packages/daemon/src/terminal/session-runtime/terminal-replica-owner.ts +498 -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 +25 -0
- package/packages/daemon/src/terminal/session-runtime/xterm-terminal-interpreter-backend.ts +379 -0
- package/packages/daemon/src/tui/async-disposable-slot.ts +60 -0
- package/packages/daemon/src/tui/chrome/events.ts +4 -4
- package/packages/daemon/src/tui/chrome/front-door.ts +27 -0
- package/packages/daemon/src/tui/chrome/notify-prefs.ts +58 -0
- package/packages/daemon/src/tui/chrome/notify-state.ts +76 -0
- package/packages/daemon/src/tui/chrome/notify.ts +582 -84
- package/packages/daemon/src/tui/chrome/sidebar.ts +9 -4
- package/packages/daemon/src/tui/chrome/statusline.ts +15 -6
- package/packages/daemon/src/tui/chrome/updater.ts +367 -64
- package/packages/daemon/src/tui/compiled.ts +102 -6
- package/packages/daemon/src/tui/detect/agent-resolution.ts +85 -0
- package/packages/daemon/src/tui/detect/classify.ts +34 -0
- package/packages/daemon/src/tui/detect/manifest-loader.ts +54 -5
- package/packages/daemon/src/tui/detect/manifest.ts +24 -3
- package/packages/daemon/src/tui/detect/manifests.ts +240 -6
- package/packages/daemon/src/tui/detect/process-tree.ts +30 -4
- package/packages/daemon/src/tui/detect/session-id.ts +503 -0
- 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/integrations/opencode.ts +121 -0
- package/packages/daemon/src/tui/main.ts +53 -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-chip.ts +40 -11
- package/packages/daemon/src/tui/mirror/agent-lifecycle.ts +468 -0
- package/packages/daemon/src/tui/mirror/agent-provisioning-executor.ts +151 -0
- package/packages/daemon/src/tui/mirror/agent-rows.ts +61 -5
- package/packages/daemon/src/tui/mirror/ansi-palette.ts +3 -0
- package/packages/daemon/src/tui/mirror/app-state.ts +185 -9
- package/packages/daemon/src/tui/mirror/app.tsx +2 -5264
- package/packages/daemon/src/tui/mirror/application-keybindings.ts +54 -0
- package/packages/daemon/src/tui/mirror/application-shell-daemon-connection.ts +344 -0
- package/packages/daemon/src/tui/mirror/application-shell-daemon-session.ts +74 -0
- package/packages/daemon/src/tui/mirror/attention.ts +110 -0
- package/packages/daemon/src/tui/mirror/canonical-workspace-routing.ts +63 -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 -354
- package/packages/daemon/src/tui/mirror/diff-model.ts +279 -4
- 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/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 +427 -0
- package/packages/daemon/src/tui/mirror/features/palette/surface.tsx +92 -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/file-tree.ts +231 -6
- 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/host-terminal.ts +49 -0
- package/packages/daemon/src/tui/mirror/hosted.ts +286 -0
- 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 +28 -18
- 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 +379 -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 +83 -0
- package/packages/daemon/src/tui/mirror/open-tui-workspace-runtime-port.ts +1314 -0
- package/packages/daemon/src/tui/mirror/palette-surface-adapter.ts +465 -0
- package/packages/daemon/src/tui/mirror/palette.ts +485 -34
- package/packages/daemon/src/tui/mirror/pane-frame-state.ts +209 -0
- package/packages/daemon/src/tui/mirror/pane-mirror.ts +215 -50
- package/packages/daemon/src/tui/mirror/pane-surface.tsx +720 -51
- 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 -122
- package/packages/daemon/src/tui/mirror/performance-events.ts +488 -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 +726 -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-appearance-owner.ts +121 -0
- package/packages/daemon/src/tui/mirror/runtime/application-bootstrap.ts +118 -0
- package/packages/daemon/src/tui/mirror/runtime/application-entry.ts +194 -0
- package/packages/daemon/src/tui/mirror/runtime/application-generation-starter.ts +116 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-catalog-owner.ts +112 -0
- package/packages/daemon/src/tui/mirror/runtime/application-home-catalog.ts +440 -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-optional-features.ts +25 -0
- package/packages/daemon/src/tui/mirror/runtime/application-palette-command-owner.ts +87 -0
- package/packages/daemon/src/tui/mirror/runtime/application-palette-input.ts +105 -0
- package/packages/daemon/src/tui/mirror/runtime/application-pane-rename-input.ts +43 -0
- package/packages/daemon/src/tui/mirror/runtime/application-pane-rename-owner.ts +43 -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 +110 -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 +32 -0
- package/packages/daemon/src/tui/mirror/runtime/application-root-v2.tsx +506 -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 +365 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-catalog.tsx +372 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-home.tsx +161 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-overlay-stack.tsx +42 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-overlays.tsx +154 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-sidebar.tsx +140 -0
- package/packages/daemon/src/tui/mirror/runtime/application-shell-view.tsx +425 -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 +133 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-interaction-controller.ts +1630 -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 +218 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-workspace-policy.ts +285 -0
- package/packages/daemon/src/tui/mirror/runtime/application-terminal-workspace.tsx +1150 -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 +394 -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 +61 -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 +105 -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 +996 -0
- package/packages/daemon/src/tui/mirror/runtime/open-tui-session-owner.ts +195 -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 +22 -0
- package/packages/daemon/src/tui/mirror/runtime/pane-scoped-terminal-surface.tsx +146 -0
- package/packages/daemon/src/tui/mirror/runtime/product-surface-policy.ts +16 -0
- package/packages/daemon/src/tui/mirror/runtime/renderer-cadence.ts +4 -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 +78 -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 +719 -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 +45 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-pane-input-router.ts +94 -0
- package/packages/daemon/src/tui/mirror/runtime/terminal-selection.ts +218 -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 +122 -29
- package/packages/daemon/src/tui/mirror/semantic-pane-render-source.ts +767 -0
- package/packages/daemon/src/tui/mirror/semantic-session-view.ts +366 -0
- package/packages/daemon/src/tui/mirror/settings-model.ts +95 -57
- package/packages/daemon/src/tui/mirror/shell-chrome-view.tsx +346 -0
- package/packages/daemon/src/tui/mirror/shell-chrome.ts +508 -0
- package/packages/daemon/src/tui/mirror/sidebar.tsx +321 -0
- package/packages/daemon/src/tui/mirror/size-truth.ts +53 -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 +42 -0
- package/packages/daemon/src/tui/mirror/theme.ts +1059 -0
- 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 +68 -0
- package/packages/daemon/src/tui/mirror/ui/navigation-row.tsx +114 -0
- package/packages/daemon/src/tui/mirror/ui/overlay-frame.tsx +115 -0
- package/packages/daemon/src/tui/mirror/ui/overlay-host.tsx +71 -0
- package/packages/daemon/src/tui/mirror/ui/overlay-list-row.tsx +59 -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__/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-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 +544 -0
- package/packages/daemon/src/tui/mirror/workspace/icons.ts +56 -0
- package/packages/daemon/src/tui/mirror/workspace/pane-action-menu.tsx +68 -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 +225 -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/fuzzy.ts +20 -0
- 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 +119 -46
- package/packages/daemon/src/tui/team/wait-receipts.ts +192 -0
- package/packages/daemon/src/tui/team/wait.ts +144 -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 +15 -7
- 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 +2754 -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.ts +203 -0
- package/packages/daemon-client/src/workspace-client-types.ts +302 -0
- package/packages/daemon-client/src/workspace-client.test.ts +2626 -0
- package/packages/daemon-client/src/workspace-client.ts +1421 -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/architecture-debt-budget.json +10 -0
- package/scripts/architecture-debt-inventory.mjs +98 -0
- package/scripts/build-cli.mjs +22 -1
- package/scripts/build-macos-notifier.mjs +160 -0
- package/scripts/build-tui.mjs +59 -3
- package/scripts/check-control-bytes.mjs +70 -0
- package/scripts/dev-web.mjs +66 -0
- package/scripts/lib/bounded-child-command.mjs +59 -0
- package/scripts/lib/bounded-child-command.test.mjs +148 -0
- package/scripts/lib/bounded-diagnostic-tail.mjs +82 -0
- package/scripts/lib/bounded-diagnostic-tail.test.mjs +97 -0
- package/scripts/lib/npm-release-tag.mjs +27 -0
- package/scripts/lib/npm-release-tag.test.mjs +116 -0
- package/scripts/lib/packed-opentui-frame.mjs +18 -0
- package/scripts/lib/packed-opentui-frame.test.mjs +40 -0
- package/scripts/lib/performance-reference-budgets.mjs +36 -0
- package/scripts/lib/performance-reference-report.mjs +157 -0
- package/scripts/lib/performance-reference-report.test.mjs +62 -0
- package/scripts/lib/portable-performance-evidence.mjs +210 -0
- package/scripts/lib/portable-performance-evidence.test.mjs +208 -0
- package/scripts/lib/product-ansi-cursor-alt-screen-fixture.mjs +132 -0
- package/scripts/lib/product-ansi-cursor-alt-screen.mjs +4618 -0
- package/scripts/lib/product-ansi-cursor-alt-screen.test.mjs +4120 -0
- package/scripts/lib/product-ansi-tmux-precondition.mjs +159 -0
- package/scripts/lib/product-ansi-tmux-precondition.test.mjs +147 -0
- package/scripts/lib/product-card5-host-topology.mjs +873 -0
- package/scripts/lib/product-card5-host-topology.test.mjs +1070 -0
- package/scripts/lib/product-card5-production-host-owner.mjs +4864 -0
- package/scripts/lib/product-card5-production-host-owner.test.mjs +5051 -0
- package/scripts/lib/product-configless-owner.mjs +1578 -0
- package/scripts/lib/product-configless-owner.test.mjs +2169 -0
- package/scripts/lib/product-cross-client-handoff.mjs +1165 -0
- package/scripts/lib/product-cross-client-handoff.test.mjs +1062 -0
- package/scripts/lib/product-cross-client-host-evidence.mjs +4780 -0
- package/scripts/lib/product-cross-client-host-evidence.test.mjs +3897 -0
- package/scripts/lib/product-first-input.mjs +1546 -0
- package/scripts/lib/product-first-input.test.mjs +1731 -0
- package/scripts/lib/product-focus-tmux.mjs +46 -0
- package/scripts/lib/product-focus.mjs +1198 -0
- package/scripts/lib/product-focus.test.mjs +1504 -0
- package/scripts/lib/product-idle-process-proof.mjs +270 -0
- package/scripts/lib/product-idle-process-proof.test.mjs +210 -0
- package/scripts/lib/product-keyboard-pointer-resize.mjs +471 -0
- package/scripts/lib/product-keyboard-pointer-resize.test.mjs +363 -0
- package/scripts/lib/product-rig-causal-cell-fixture.mjs +91 -0
- package/scripts/lib/product-rig-causal-fixture-geometry.mjs +27 -0
- package/scripts/lib/product-rig-causal-fixture-geometry.test.mjs +45 -0
- package/scripts/lib/product-rig-sleep-assertion.mjs +179 -0
- package/scripts/lib/product-selection-copy-app-mouse.mjs +1585 -0
- package/scripts/lib/product-selection-copy-app-mouse.test.mjs +1602 -0
- package/scripts/lib/product-tui-host-readiness.mjs +133 -0
- package/scripts/lib/product-tui-host-readiness.test.mjs +258 -0
- package/scripts/lib/product-window-lifecycle.mjs +1351 -0
- package/scripts/lib/product-window-lifecycle.test.mjs +1305 -0
- package/scripts/lib/release-source-state.mjs +28 -0
- package/scripts/lib/release-source-state.test.mjs +26 -0
- package/scripts/lib/tui-diagnostics.mjs +159 -0
- package/scripts/lib/tui-host-publication.mjs +38 -0
- package/scripts/lib/tui-testdrive-clipboard-hook.mjs +543 -0
- package/scripts/lib/tui-testdrive-clipboard-hook.test.mjs +626 -0
- package/scripts/lib/tui-testdrive-input.mjs +1940 -0
- package/scripts/lib/tui-testdrive-input.test.mjs +3434 -0
- package/scripts/lib/tui-testdrive-launch.mjs +180 -0
- package/scripts/lib/tui-testdrive-launch.test.mjs +294 -0
- package/scripts/opentui-release-check.mjs +209 -0
- package/scripts/pack-check-run.mjs +1779 -30
- package/scripts/pack-tui-check.mjs +73 -0
- package/scripts/pack-web-check.mjs +19 -0
- package/scripts/performance-portable-evidence.mjs +419 -0
- package/scripts/performance-qualification.mjs +456 -0
- package/scripts/performance-reference-memory.ts +177 -0
- package/scripts/performance-reference-pane-stream.ts +74 -0
- package/scripts/performance-reference.mjs +681 -0
- package/scripts/postinstall.js +14 -6
- package/scripts/prepublish-check.mjs +37 -1
- package/scripts/prepublish-opentui-check.mjs +24 -0
- package/scripts/product-test-rig-journeys.mjs +2700 -0
- package/scripts/product-test-rig-journeys.test.mjs +3959 -0
- package/scripts/product-test-rig-lib.mjs +2359 -0
- package/scripts/product-test-rig-multiclient.ts +434 -0
- package/scripts/product-test-rig-native-client.mjs +45 -0
- package/scripts/product-test-rig.mjs +20260 -0
- package/scripts/product-test-rig.test.mjs +3634 -0
- package/scripts/publish-tap.sh +55 -0
- package/scripts/smoke-tui-missions.mjs +329 -0
- package/scripts/tui-diagnose.mjs +258 -0
- package/scripts/tui-diagnose.test.mjs +200 -0
- package/scripts/tui-testdrive-capture.test.mjs +161 -0
- package/scripts/tui-testdrive.mjs +1955 -0
- package/skill/SKILL.md +115 -30
- 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/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.d.ts +0 -13
- package/packages/daemon/dist/widgets/explorer/tree.jsx +0 -108
- 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/preview/index.jsx +0 -371
- 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/sidebar/index.jsx +0 -462
- package/packages/daemon/src/tui/mirror/control-client.ts +0 -214
- package/packages/daemon/src/tui/mirror/focus-border.ts +0 -57
- package/packages/daemon/src/tui/mirror/session-mirror.ts +0 -443
- package/packages/daemon/src/widgets/setup/orchestrator-panel.tsx +0 -200
- package/scripts/perf-mirror.mjs +0 -313
- package/scripts/verify-endpoints.sh +0 -90
- /package/packages/daemon/dist/{widgets/changes/index.d.ts → lib/__tests__/fixtures/workspace-state-writer.d.ts} +0 -0
- /package/packages/daemon/dist/{widgets/explorer/index.d.ts → terminal/mirror/trusted-inventory.js} +0 -0
- /package/packages/daemon/dist/{widgets/preview/index.d.ts → terminal/session-runtime/terminal-interpreter-backend.js} +0 -0
- /package/packages/daemon/dist/{widgets/sidebar/index.d.ts → tui/mirror/features/changes/contract.js} +0 -0
|
@@ -0,0 +1,2918 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TERMINAL_DELIVERY_CHUNK_BYTES,
|
|
3
|
+
TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES,
|
|
4
|
+
TERMINAL_DELIVERY_PROTOCOL_VERSION,
|
|
5
|
+
TerminalDeliveryEnvelopeSchemaZ,
|
|
6
|
+
TerminalDeliveryChunkSchemaZ,
|
|
7
|
+
TerminalDeliveryNegotiatedSchemaZ,
|
|
8
|
+
TerminalDeliveryNackSchemaZ,
|
|
9
|
+
TerminalSemanticDeliveryPayloadSchemaZ,
|
|
10
|
+
type TerminalDeliveryAck,
|
|
11
|
+
type TerminalDeliveryChunk,
|
|
12
|
+
type TerminalDeliveryEnvelope,
|
|
13
|
+
type TerminalDeliveryNegotiated,
|
|
14
|
+
type TerminalDeliveryNegotiationResult,
|
|
15
|
+
type TerminalDeliveryNack,
|
|
16
|
+
type TerminalDeliveryOffer,
|
|
17
|
+
type TerminalReplicaPatchPayload,
|
|
18
|
+
type TerminalReplicaCell,
|
|
19
|
+
type TerminalReplicaColor,
|
|
20
|
+
type TerminalReplicaRow,
|
|
21
|
+
type TerminalReplicaSnapshot,
|
|
22
|
+
type TerminalSemanticDeliveryPayload,
|
|
23
|
+
} from "@tmux-ide/contracts";
|
|
24
|
+
import {
|
|
25
|
+
applyTerminalReplicaPatch,
|
|
26
|
+
freezeTerminalReplicaSnapshot,
|
|
27
|
+
hashTerminalReplicaSnapshot,
|
|
28
|
+
hashTerminalReplicaTombstone,
|
|
29
|
+
hashTerminalReplicaSnapshotCooperatively,
|
|
30
|
+
registerTerminalReplicaRowsDeltaHash,
|
|
31
|
+
terminalReplicaRowsEqual,
|
|
32
|
+
} from "./terminal-replica.ts";
|
|
33
|
+
import { grantCompactReplicaCapability } from "./terminal-compact-capability.ts";
|
|
34
|
+
import {
|
|
35
|
+
hashTerminalReplicaRowCooperatively,
|
|
36
|
+
hashTerminalReplicaRowRunsCooperatively,
|
|
37
|
+
isTerminalReplicaRowDeeplyFrozen,
|
|
38
|
+
primeTerminalReplicaRowHash,
|
|
39
|
+
TerminalReplicaRunEncodingCache,
|
|
40
|
+
} from "./terminal-replica-hash-cache.ts";
|
|
41
|
+
|
|
42
|
+
export class TerminalDeliveryStateTooLargeError extends Error {
|
|
43
|
+
readonly bytes: number;
|
|
44
|
+
|
|
45
|
+
constructor(bytes: number) {
|
|
46
|
+
super(
|
|
47
|
+
`Terminal delivery representation is ${bytes} bytes; maximum is ${TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES}`,
|
|
48
|
+
);
|
|
49
|
+
this.name = "TerminalDeliveryStateTooLargeError";
|
|
50
|
+
this.bytes = bytes;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function negotiateTerminalDelivery(
|
|
55
|
+
offer: TerminalDeliveryOffer,
|
|
56
|
+
generation: string,
|
|
57
|
+
deliveryNonce: string,
|
|
58
|
+
): TerminalDeliveryNegotiationResult {
|
|
59
|
+
if (!offer.protocolVersions.includes(TERMINAL_DELIVERY_PROTOCOL_VERSION))
|
|
60
|
+
return { accepted: false, reason: "protocol-version-mismatch" };
|
|
61
|
+
const encoding = (
|
|
62
|
+
["semantic-compact-v1", "semantic-v1", "ansi-diff-v1", "ansi-raw-v1"] as const
|
|
63
|
+
).find((value) => offer.encodings.includes(value));
|
|
64
|
+
if (!encoding) return { accepted: false, reason: "encoding-mismatch" };
|
|
65
|
+
if (offer.richPlacements && encoding !== "semantic-v1" && encoding !== "semantic-compact-v1")
|
|
66
|
+
return { accepted: false, reason: "unsupported-capability-combination" };
|
|
67
|
+
return {
|
|
68
|
+
accepted: true,
|
|
69
|
+
negotiated: {
|
|
70
|
+
protocolVersion: TERMINAL_DELIVERY_PROTOCOL_VERSION,
|
|
71
|
+
encoding,
|
|
72
|
+
...(encoding === "semantic-compact-v1" && offer.encodings.includes("semantic-v1")
|
|
73
|
+
? { fallbackEncoding: "semantic-v1" as const }
|
|
74
|
+
: {}),
|
|
75
|
+
richPlacements:
|
|
76
|
+
offer.richPlacements && (encoding === "semantic-v1" || encoding === "semantic-compact-v1"),
|
|
77
|
+
generation,
|
|
78
|
+
deliveryNonce,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function encodeSemanticTerminalUpdate(update: TerminalSemanticDeliveryPayload): Uint8Array {
|
|
84
|
+
const bytes = new TextEncoder().encode(
|
|
85
|
+
canonicalJson(TerminalSemanticDeliveryPayloadSchemaZ.parse(update)),
|
|
86
|
+
);
|
|
87
|
+
assertRepresentationSize(bytes);
|
|
88
|
+
return bytes;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Non-materializing exact counter for the legacy semantic JSON wire. It stops
|
|
93
|
+
* at cap + 1 without building the canonical JSON string or UTF-8 buffer; a
|
|
94
|
+
* candidate within the cap is subsequently encoded and cross-checked.
|
|
95
|
+
*/
|
|
96
|
+
export function preaccountSemanticTerminalUpdateBytes(
|
|
97
|
+
input: TerminalSemanticDeliveryPayload,
|
|
98
|
+
maximum = TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES,
|
|
99
|
+
): Readonly<{ exact: true; bytes: number } | { exact: false; atLeastBytes: number }> {
|
|
100
|
+
let bytes = 0;
|
|
101
|
+
const saturated = {};
|
|
102
|
+
const add = (amount: number) => {
|
|
103
|
+
bytes += amount;
|
|
104
|
+
if (bytes > maximum) throw saturated;
|
|
105
|
+
};
|
|
106
|
+
const stringBytes = (value: string) => {
|
|
107
|
+
add(2);
|
|
108
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
109
|
+
const code = value.charCodeAt(index);
|
|
110
|
+
if (
|
|
111
|
+
code === 0x22 ||
|
|
112
|
+
code === 0x5c ||
|
|
113
|
+
code === 0x08 ||
|
|
114
|
+
code === 0x0c ||
|
|
115
|
+
code === 0x0a ||
|
|
116
|
+
code === 0x0d ||
|
|
117
|
+
code === 0x09
|
|
118
|
+
)
|
|
119
|
+
add(2);
|
|
120
|
+
else if (code <= 0x1f) add(6);
|
|
121
|
+
else if (code <= 0x7f) add(1);
|
|
122
|
+
else if (code <= 0x7ff) add(2);
|
|
123
|
+
else if (code >= 0xd800 && code <= 0xdbff) {
|
|
124
|
+
const next = value.charCodeAt(index + 1);
|
|
125
|
+
if (next >= 0xdc00 && next <= 0xdfff) {
|
|
126
|
+
add(4);
|
|
127
|
+
index += 1;
|
|
128
|
+
} else add(6);
|
|
129
|
+
} else if (code >= 0xdc00 && code <= 0xdfff) add(6);
|
|
130
|
+
else add(3);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
const visit = (value: unknown): void => {
|
|
134
|
+
if (value === null) {
|
|
135
|
+
add(4);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (typeof value === "string") {
|
|
139
|
+
stringBytes(value);
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (typeof value === "number" || typeof value === "boolean") {
|
|
143
|
+
add(String(value).length);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (Array.isArray(value)) {
|
|
147
|
+
add(1);
|
|
148
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
149
|
+
if (index > 0) add(1);
|
|
150
|
+
visit(value[index]);
|
|
151
|
+
}
|
|
152
|
+
add(1);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (typeof value !== "object" || value === undefined)
|
|
156
|
+
throw new TypeError("Unsupported canonical JSON value");
|
|
157
|
+
add(1);
|
|
158
|
+
const record = value as Record<string, unknown>;
|
|
159
|
+
const keys = Object.keys(record).sort();
|
|
160
|
+
let emitted = 0;
|
|
161
|
+
for (const key of keys) {
|
|
162
|
+
const member = record[key];
|
|
163
|
+
if (member === undefined) continue;
|
|
164
|
+
if (emitted > 0) add(1);
|
|
165
|
+
stringBytes(key);
|
|
166
|
+
add(1);
|
|
167
|
+
visit(member);
|
|
168
|
+
emitted += 1;
|
|
169
|
+
}
|
|
170
|
+
add(1);
|
|
171
|
+
};
|
|
172
|
+
try {
|
|
173
|
+
visit(input);
|
|
174
|
+
return Object.freeze({ exact: true, bytes });
|
|
175
|
+
} catch (error) {
|
|
176
|
+
if (error !== saturated) throw error;
|
|
177
|
+
return Object.freeze({ exact: false, atLeastBytes: maximum + 1 });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function decodeSemanticTerminalUpdate(bytes: Uint8Array): TerminalSemanticDeliveryPayload {
|
|
182
|
+
assertRepresentationSize(bytes);
|
|
183
|
+
return TerminalSemanticDeliveryPayloadSchemaZ.parse(
|
|
184
|
+
JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes)),
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const COMPACT_SEMANTIC_KIND = "terminal-semantic-compact";
|
|
189
|
+
const COMPACT_SEMANTIC_VERSION = 1;
|
|
190
|
+
const COMPACT_MAX_DIMENSION = 4_096;
|
|
191
|
+
const COMPACT_MAX_ROWS = 10_000;
|
|
192
|
+
const COMPACT_MAX_RUNS = 1_000_000;
|
|
193
|
+
const COMPACT_MAX_EXPANDED_CELLS = 1_000_000;
|
|
194
|
+
const COMPACT_MAX_EXPANSION_RATIO = 64;
|
|
195
|
+
const COMPACT_MAX_PLACEMENTS = 4_096;
|
|
196
|
+
const COMPACT_MAX_STRING_BYTES = 4_096;
|
|
197
|
+
const UTF8_ENCODER = new TextEncoder();
|
|
198
|
+
const COMPACT_DEFAULT_COLOR = Object.freeze({ kind: "default" as const });
|
|
199
|
+
const compactCommitCapabilities = new WeakMap<
|
|
200
|
+
TerminalSemanticDeliveryPayload,
|
|
201
|
+
Readonly<{ snapshot: TerminalReplicaSnapshot | null; hash: string }>
|
|
202
|
+
>();
|
|
203
|
+
|
|
204
|
+
type CompactColor = 0 | readonly [1 | 2, number];
|
|
205
|
+
type CompactCellRun = [number, string, 0 | 1 | 2, CompactColor, CompactColor, number];
|
|
206
|
+
type CompactRow = readonly [0 | 1, readonly CompactCellRun[]];
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* A negotiated exact semantic representation. It changes only the wire shape:
|
|
210
|
+
* decode always returns the same strict canonical payload and hash authority.
|
|
211
|
+
*/
|
|
212
|
+
export function encodeCompactSemanticTerminalUpdate(
|
|
213
|
+
input: TerminalSemanticDeliveryPayload,
|
|
214
|
+
): Uint8Array {
|
|
215
|
+
const update = TerminalSemanticDeliveryPayloadSchemaZ.parse(input);
|
|
216
|
+
const wire =
|
|
217
|
+
update.frame === "seed"
|
|
218
|
+
? {
|
|
219
|
+
v: 1,
|
|
220
|
+
k: COMPACT_SEMANTIC_KIND,
|
|
221
|
+
f: "s",
|
|
222
|
+
r: update.revision,
|
|
223
|
+
s: compactSnapshot(update.snapshot),
|
|
224
|
+
}
|
|
225
|
+
: update.frame === "patch"
|
|
226
|
+
? {
|
|
227
|
+
v: 1,
|
|
228
|
+
k: COMPACT_SEMANTIC_KIND,
|
|
229
|
+
f: "p",
|
|
230
|
+
b: update.baseRevision,
|
|
231
|
+
r: update.revision,
|
|
232
|
+
p: compactPatch(update.patch),
|
|
233
|
+
}
|
|
234
|
+
: {
|
|
235
|
+
v: 1,
|
|
236
|
+
k: COMPACT_SEMANTIC_KIND,
|
|
237
|
+
f: "t",
|
|
238
|
+
b: update.baseRevision,
|
|
239
|
+
r: update.revision,
|
|
240
|
+
t: update.tombstone.reason,
|
|
241
|
+
};
|
|
242
|
+
const bytes = UTF8_ENCODER.encode(canonicalJson(wire));
|
|
243
|
+
assertRepresentationSize(bytes);
|
|
244
|
+
return bytes;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export function decodeCompactSemanticTerminalUpdate(
|
|
248
|
+
bytes: Uint8Array,
|
|
249
|
+
): TerminalSemanticDeliveryPayload {
|
|
250
|
+
return decodeCompactSemanticTerminalUpdateInternal(bytes);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function decodeCompactSemanticTerminalUpdateInternal(
|
|
254
|
+
bytes: Uint8Array,
|
|
255
|
+
suppliedBudget?: CompactDecodeBudget,
|
|
256
|
+
): TerminalSemanticDeliveryPayload {
|
|
257
|
+
assertRepresentationSize(bytes);
|
|
258
|
+
const wire: unknown = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
259
|
+
const frame =
|
|
260
|
+
wire !== null && typeof wire === "object" && !Array.isArray(wire)
|
|
261
|
+
? (wire as Record<string, unknown>).f
|
|
262
|
+
: null;
|
|
263
|
+
if (
|
|
264
|
+
!recordWithKeys(
|
|
265
|
+
wire,
|
|
266
|
+
frame === "s"
|
|
267
|
+
? ["v", "k", "f", "r", "s"]
|
|
268
|
+
: ["v", "k", "f", "b", "r", frame === "p" ? "p" : "t"],
|
|
269
|
+
)
|
|
270
|
+
)
|
|
271
|
+
throw new TypeError("Invalid compact semantic envelope");
|
|
272
|
+
if (wire.v !== COMPACT_SEMANTIC_VERSION || wire.k !== COMPACT_SEMANTIC_KIND)
|
|
273
|
+
throw new TypeError("Unsupported compact semantic version");
|
|
274
|
+
const revision = compactInteger(wire.r, 0, Number.MAX_SAFE_INTEGER, "revision");
|
|
275
|
+
const budget = suppliedBudget ?? compactDecodeBudget(bytes.byteLength);
|
|
276
|
+
let update: TerminalSemanticDeliveryPayload;
|
|
277
|
+
if (wire.f === "s") {
|
|
278
|
+
update = { frame: "seed", revision, snapshot: expandSnapshot(wire.s, budget) };
|
|
279
|
+
} else {
|
|
280
|
+
const baseRevision = compactInteger(wire.b, 0, Number.MAX_SAFE_INTEGER, "base revision");
|
|
281
|
+
if (revision <= baseRevision) throw new TypeError("Compact semantic revision did not advance");
|
|
282
|
+
if (wire.f === "p")
|
|
283
|
+
update = {
|
|
284
|
+
frame: "patch",
|
|
285
|
+
baseRevision,
|
|
286
|
+
revision,
|
|
287
|
+
patch: expandPatch(wire.p, budget),
|
|
288
|
+
};
|
|
289
|
+
else if (
|
|
290
|
+
wire.f === "t" &&
|
|
291
|
+
["pane-closed", "session-restarted", "runtime-disposed"].includes(String(wire.t))
|
|
292
|
+
)
|
|
293
|
+
update = {
|
|
294
|
+
frame: "tombstone",
|
|
295
|
+
baseRevision,
|
|
296
|
+
revision,
|
|
297
|
+
tombstone: Object.freeze({
|
|
298
|
+
reason: wire.t as "pane-closed" | "session-restarted" | "runtime-disposed",
|
|
299
|
+
}),
|
|
300
|
+
};
|
|
301
|
+
else throw new TypeError("Invalid compact semantic frame");
|
|
302
|
+
}
|
|
303
|
+
return Object.freeze(update);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
function compactDecodeBudget(bytes: number): CompactDecodeBudget {
|
|
307
|
+
return {
|
|
308
|
+
rows: 0,
|
|
309
|
+
runs: 0,
|
|
310
|
+
cells: 0,
|
|
311
|
+
placements: 0,
|
|
312
|
+
maxCells: Math.min(COMPACT_MAX_EXPANDED_CELLS, bytes * COMPACT_MAX_EXPANSION_RATIO),
|
|
313
|
+
rowCache: new Map(),
|
|
314
|
+
reusedRows: 0,
|
|
315
|
+
allocatedCells: 0,
|
|
316
|
+
canonicalUtf8Allocations: 0,
|
|
317
|
+
canonicalUtf8Bytes: 0,
|
|
318
|
+
validatedCellAllocations: 0,
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function compactSnapshot(snapshot: TerminalReplicaSnapshot): readonly unknown[] {
|
|
323
|
+
const budget: CompactDecodeBudget = {
|
|
324
|
+
rows: 0,
|
|
325
|
+
runs: 0,
|
|
326
|
+
cells: 0,
|
|
327
|
+
placements: 0,
|
|
328
|
+
maxCells: COMPACT_MAX_EXPANDED_CELLS,
|
|
329
|
+
reusedRows: 0,
|
|
330
|
+
allocatedCells: 0,
|
|
331
|
+
canonicalUtf8Allocations: 0,
|
|
332
|
+
canonicalUtf8Bytes: 0,
|
|
333
|
+
validatedCellAllocations: 0,
|
|
334
|
+
};
|
|
335
|
+
if (
|
|
336
|
+
snapshot.cols > COMPACT_MAX_DIMENSION ||
|
|
337
|
+
snapshot.rows > COMPACT_MAX_DIMENSION ||
|
|
338
|
+
snapshot.grid.length !== snapshot.rows
|
|
339
|
+
)
|
|
340
|
+
compactEncodingLimit();
|
|
341
|
+
return [
|
|
342
|
+
snapshot.cols,
|
|
343
|
+
snapshot.rows,
|
|
344
|
+
compactRows(snapshot.grid, snapshot.cols, budget),
|
|
345
|
+
compactRows(snapshot.history, snapshot.cols, budget),
|
|
346
|
+
compactCursor(snapshot.cursor),
|
|
347
|
+
compactModes(snapshot.modes),
|
|
348
|
+
compactPlacements(snapshot.placements, budget),
|
|
349
|
+
compactBootstrap(snapshot.bootstrap),
|
|
350
|
+
];
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function compactPatch(patch: TerminalReplicaPatchPayload): readonly unknown[] {
|
|
354
|
+
const budget: CompactDecodeBudget = {
|
|
355
|
+
rows: 0,
|
|
356
|
+
runs: 0,
|
|
357
|
+
cells: 0,
|
|
358
|
+
placements: 0,
|
|
359
|
+
maxCells: COMPACT_MAX_EXPANDED_CELLS,
|
|
360
|
+
reusedRows: 0,
|
|
361
|
+
allocatedCells: 0,
|
|
362
|
+
canonicalUtf8Allocations: 0,
|
|
363
|
+
canonicalUtf8Bytes: 0,
|
|
364
|
+
validatedCellAllocations: 0,
|
|
365
|
+
};
|
|
366
|
+
const cols = patch.dimensions?.cols ?? null;
|
|
367
|
+
if (
|
|
368
|
+
patch.dimensions &&
|
|
369
|
+
(patch.dimensions.cols > COMPACT_MAX_DIMENSION || patch.dimensions.rows > COMPACT_MAX_DIMENSION)
|
|
370
|
+
)
|
|
371
|
+
compactEncodingLimit();
|
|
372
|
+
if (patch.rows.length > COMPACT_MAX_DIMENSION) compactEncodingLimit();
|
|
373
|
+
return [
|
|
374
|
+
patch.dimensions ? [patch.dimensions.cols, patch.dimensions.rows] : null,
|
|
375
|
+
patch.rows.map(({ index, row }) => [index, compactRow(row, cols, budget)]),
|
|
376
|
+
patch.history ? compactRows(patch.history, cols, budget) : null,
|
|
377
|
+
patch.historyDelta
|
|
378
|
+
? [patch.historyDelta.trim, compactRows(patch.historyDelta.append, cols, budget)]
|
|
379
|
+
: null,
|
|
380
|
+
patch.cursor ? compactCursor(patch.cursor) : null,
|
|
381
|
+
patch.modes ? compactModes(patch.modes) : null,
|
|
382
|
+
patch.placements ? compactPlacements(patch.placements, budget) : null,
|
|
383
|
+
patch.bootstrap ? compactBootstrap(patch.bootstrap) : null,
|
|
384
|
+
];
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function compactRows(
|
|
388
|
+
rows: readonly TerminalReplicaRow[],
|
|
389
|
+
cols: number | null,
|
|
390
|
+
budget: CompactDecodeBudget,
|
|
391
|
+
): CompactRow[] {
|
|
392
|
+
return rows.map((row) => compactRow(row, cols, budget));
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
function compactRow(
|
|
396
|
+
row: TerminalReplicaRow,
|
|
397
|
+
cols: number | null,
|
|
398
|
+
budget: CompactDecodeBudget,
|
|
399
|
+
): CompactRow {
|
|
400
|
+
if (++budget.rows > COMPACT_MAX_ROWS) compactEncodingLimit();
|
|
401
|
+
if (row.cells.length > COMPACT_MAX_EXPANDED_CELLS || (cols !== null && row.cells.length !== cols))
|
|
402
|
+
compactEncodingLimit();
|
|
403
|
+
budget.cells += row.cells.length;
|
|
404
|
+
if (budget.cells > COMPACT_MAX_EXPANDED_CELLS) compactEncodingLimit();
|
|
405
|
+
const runs: CompactCellRun[] = [];
|
|
406
|
+
for (const cell of row.cells) {
|
|
407
|
+
const prior = runs.at(-1);
|
|
408
|
+
const encoded = compactCell(cell);
|
|
409
|
+
if (prior && compactRunCellEqual(prior, encoded)) prior[0] += 1;
|
|
410
|
+
else {
|
|
411
|
+
if (++budget.runs > COMPACT_MAX_RUNS) compactEncodingLimit();
|
|
412
|
+
runs.push(encoded);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
return [row.wrapped ? 1 : 0, runs];
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
function compactCell(
|
|
419
|
+
cell: TerminalReplicaCell,
|
|
420
|
+
): [number, string, 0 | 1 | 2, CompactColor, CompactColor, number] {
|
|
421
|
+
return [
|
|
422
|
+
1,
|
|
423
|
+
compactEncodeString(cell.grapheme),
|
|
424
|
+
cell.width,
|
|
425
|
+
compactColor(cell.foreground),
|
|
426
|
+
compactColor(cell.background),
|
|
427
|
+
cell.attributes,
|
|
428
|
+
];
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
function compactRunCellEqual(a: CompactCellRun, b: CompactCellRun): boolean {
|
|
432
|
+
return (
|
|
433
|
+
a[1] === b[1] &&
|
|
434
|
+
a[2] === b[2] &&
|
|
435
|
+
compactColorEqual(a[3], b[3]) &&
|
|
436
|
+
compactColorEqual(a[4], b[4]) &&
|
|
437
|
+
a[5] === b[5]
|
|
438
|
+
);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
function compactColor(color: TerminalReplicaColor): CompactColor {
|
|
442
|
+
return color.kind === "default"
|
|
443
|
+
? 0
|
|
444
|
+
: [color.kind === "indexed" ? 1 : 2, color.kind === "indexed" ? color.index : color.value];
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function compactColorEqual(a: CompactColor, b: CompactColor): boolean {
|
|
448
|
+
return a === 0 ? b === 0 : b !== 0 && a[0] === b[0] && a[1] === b[1];
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function compactCursor(cursor: TerminalReplicaSnapshot["cursor"]): readonly unknown[] {
|
|
452
|
+
return [cursor.x, cursor.y, cursor.hidden ? 1 : 0, cursor.style, cursor.blink ? 1 : 0];
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function compactModes(modes: TerminalReplicaSnapshot["modes"]): readonly unknown[] {
|
|
456
|
+
return [
|
|
457
|
+
modes.alternateScreen ? 1 : 0,
|
|
458
|
+
modes.applicationCursor ? 1 : 0,
|
|
459
|
+
modes.applicationKeypad ? 1 : 0,
|
|
460
|
+
modes.bracketedPaste ? 1 : 0,
|
|
461
|
+
modes.insert ? 1 : 0,
|
|
462
|
+
modes.origin ? 1 : 0,
|
|
463
|
+
modes.wraparound ? 1 : 0,
|
|
464
|
+
modes.mouseTracking ? 1 : 0,
|
|
465
|
+
modes.mouseProtocol ?? null,
|
|
466
|
+
modes.mouseEncoding ?? null,
|
|
467
|
+
modes.synchronizedOutput ? 1 : 0,
|
|
468
|
+
];
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
function compactPlacement(
|
|
472
|
+
placement: TerminalReplicaSnapshot["placements"][number],
|
|
473
|
+
): readonly unknown[] {
|
|
474
|
+
return [
|
|
475
|
+
compactEncodeString(placement.id),
|
|
476
|
+
compactEncodeString(placement.kind),
|
|
477
|
+
placement.row,
|
|
478
|
+
placement.column,
|
|
479
|
+
placement.columns,
|
|
480
|
+
placement.rows,
|
|
481
|
+
compactEncodeString(placement.contentDigest),
|
|
482
|
+
];
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function compactPlacements(
|
|
486
|
+
placements: TerminalReplicaSnapshot["placements"],
|
|
487
|
+
budget: CompactDecodeBudget,
|
|
488
|
+
): readonly unknown[] {
|
|
489
|
+
budget.placements += placements.length;
|
|
490
|
+
if (budget.placements > COMPACT_MAX_PLACEMENTS) compactEncodingLimit();
|
|
491
|
+
return placements.map(compactPlacement);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
function compactBootstrap(bootstrap: TerminalReplicaSnapshot["bootstrap"]): readonly unknown[] {
|
|
495
|
+
return [bootstrap.kind, bootstrap.hiddenState];
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
function expandSnapshot(value: unknown, budget: CompactDecodeBudget): TerminalReplicaSnapshot {
|
|
499
|
+
const input = compactArray(value, 8, "snapshot");
|
|
500
|
+
const cols = compactInteger(input[0], 1, COMPACT_MAX_DIMENSION, "columns");
|
|
501
|
+
const rows = compactInteger(input[1], 1, COMPACT_MAX_DIMENSION, "rows");
|
|
502
|
+
const grid = expandRows(input[2], budget, cols, rows, "grid");
|
|
503
|
+
const history = expandRows(input[3], budget, cols, COMPACT_MAX_ROWS, "history");
|
|
504
|
+
const snapshot = Object.freeze({
|
|
505
|
+
cols,
|
|
506
|
+
rows,
|
|
507
|
+
grid,
|
|
508
|
+
history,
|
|
509
|
+
cursor: expandCursor(input[4], cols, rows),
|
|
510
|
+
modes: expandModes(input[5]),
|
|
511
|
+
placements: expandPlacements(input[6], budget),
|
|
512
|
+
bootstrap: expandBootstrap(input[7]),
|
|
513
|
+
});
|
|
514
|
+
if (
|
|
515
|
+
snapshot.placements.some(
|
|
516
|
+
(placement) =>
|
|
517
|
+
placement.row + placement.rows > rows || placement.column + placement.columns > cols,
|
|
518
|
+
)
|
|
519
|
+
)
|
|
520
|
+
throw new TypeError("Compact placement is outside the viewport");
|
|
521
|
+
return snapshot as unknown as TerminalReplicaSnapshot;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
function expandPatch(value: unknown, budget: CompactDecodeBudget): TerminalReplicaPatchPayload {
|
|
525
|
+
const input = compactArray(value, 8, "patch");
|
|
526
|
+
const dimensions =
|
|
527
|
+
input[0] === null
|
|
528
|
+
? undefined
|
|
529
|
+
: (() => {
|
|
530
|
+
const pair = compactArray(input[0], 2, "dimensions");
|
|
531
|
+
return Object.freeze({
|
|
532
|
+
cols: compactInteger(pair[0], 1, COMPACT_MAX_DIMENSION, "columns"),
|
|
533
|
+
rows: compactInteger(pair[1], 1, COMPACT_MAX_DIMENSION, "rows"),
|
|
534
|
+
});
|
|
535
|
+
})();
|
|
536
|
+
const rowInputs = compactArrayAtMost(input[1], COMPACT_MAX_DIMENSION, "dirty rows");
|
|
537
|
+
const rows = rowInputs.map((entry) => {
|
|
538
|
+
const pair = compactArray(entry, 2, "dirty row");
|
|
539
|
+
return Object.freeze({
|
|
540
|
+
index: compactInteger(pair[0], 0, COMPACT_MAX_DIMENSION - 1, "row index"),
|
|
541
|
+
row: expandRow(pair[1], budget, dimensions?.cols ?? null),
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
const history =
|
|
545
|
+
input[2] === null ? undefined : expandRows(input[2], budget, null, COMPACT_MAX_ROWS, "history");
|
|
546
|
+
const historyDelta =
|
|
547
|
+
input[3] === null
|
|
548
|
+
? undefined
|
|
549
|
+
: (() => {
|
|
550
|
+
const pair = compactArray(input[3], 2, "history delta");
|
|
551
|
+
return Object.freeze({
|
|
552
|
+
trim: compactInteger(pair[0], 0, COMPACT_MAX_ROWS, "history trim"),
|
|
553
|
+
append: expandRows(pair[1], budget, null, COMPACT_MAX_ROWS, "history append"),
|
|
554
|
+
});
|
|
555
|
+
})();
|
|
556
|
+
if (history && historyDelta) throw new TypeError("Compact patch has two history representations");
|
|
557
|
+
return Object.freeze({
|
|
558
|
+
...(dimensions ? { dimensions } : {}),
|
|
559
|
+
rows: Object.freeze(rows.map((row) => Object.freeze(row))),
|
|
560
|
+
...(history ? { history } : {}),
|
|
561
|
+
...(historyDelta ? { historyDelta } : {}),
|
|
562
|
+
...(input[4] === null
|
|
563
|
+
? {}
|
|
564
|
+
: { cursor: expandCursor(input[4], dimensions?.cols ?? null, dimensions?.rows ?? null) }),
|
|
565
|
+
...(input[5] === null ? {} : { modes: expandModes(input[5]) }),
|
|
566
|
+
...(input[6] === null ? {} : { placements: expandPlacements(input[6], budget) }),
|
|
567
|
+
...(input[7] === null ? {} : { bootstrap: expandBootstrap(input[7]) }),
|
|
568
|
+
}) as unknown as TerminalReplicaPatchPayload;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
interface CompactDecodeBudget {
|
|
572
|
+
rows: number;
|
|
573
|
+
runs: number;
|
|
574
|
+
cells: number;
|
|
575
|
+
placements: number;
|
|
576
|
+
maxCells: number;
|
|
577
|
+
rowCache?: Map<string, Readonly<{ row: TerminalReplicaRow; runs: number; cells: number }>>;
|
|
578
|
+
rowReuseIndex?: ReadonlyMap<string, TerminalReplicaRow | readonly TerminalReplicaRow[]>;
|
|
579
|
+
rawRowReuseIndex?: ValidatedCompactRawRowIndex;
|
|
580
|
+
reusedRows: number;
|
|
581
|
+
allocatedCells: number;
|
|
582
|
+
canonicalUtf8Allocations: number;
|
|
583
|
+
canonicalUtf8Bytes: number;
|
|
584
|
+
runEncodingCache?: TerminalReplicaRunEncodingCache;
|
|
585
|
+
decodedCellCache?: Map<
|
|
586
|
+
string,
|
|
587
|
+
Map<number, Map<number, Map<number, Map<number, TerminalReplicaCell>>>>
|
|
588
|
+
>;
|
|
589
|
+
validatedCellAllocations: number;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const VALIDATED_COMPACT_RAW_ROW = new WeakMap<
|
|
593
|
+
TerminalReplicaRow,
|
|
594
|
+
Readonly<{
|
|
595
|
+
row: TerminalReplicaRow;
|
|
596
|
+
raw: Uint8Array;
|
|
597
|
+
rawHash: number;
|
|
598
|
+
runs: number;
|
|
599
|
+
cells: number;
|
|
600
|
+
}>
|
|
601
|
+
>();
|
|
602
|
+
interface ValidatedCompactRawRowCandidate {
|
|
603
|
+
readonly row: TerminalReplicaRow;
|
|
604
|
+
readonly raw: Uint8Array;
|
|
605
|
+
readonly runs: number;
|
|
606
|
+
readonly cells: number;
|
|
607
|
+
readonly collisions?: readonly ValidatedCompactRawRowCandidate[];
|
|
608
|
+
}
|
|
609
|
+
type ValidatedCompactRawRowIndex = ReadonlyMap<number, ValidatedCompactRawRowCandidate>;
|
|
610
|
+
const VALIDATED_COMPACT_RAW_ROW_INDEX = new WeakMap<
|
|
611
|
+
TerminalReplicaRow,
|
|
612
|
+
ValidatedCompactRawRowIndex
|
|
613
|
+
>();
|
|
614
|
+
|
|
615
|
+
function expandRows(
|
|
616
|
+
value: unknown,
|
|
617
|
+
budget: CompactDecodeBudget,
|
|
618
|
+
cols: number | null,
|
|
619
|
+
maximum: number,
|
|
620
|
+
label: string,
|
|
621
|
+
): TerminalReplicaRow[] {
|
|
622
|
+
const inputs = compactArrayAtMost(value, maximum, label);
|
|
623
|
+
if (label === "grid" && cols !== null && inputs.length !== maximum)
|
|
624
|
+
throw new TypeError("Compact grid cardinality mismatch");
|
|
625
|
+
return Object.freeze(inputs.map((row) => expandRow(row, budget, cols))) as TerminalReplicaRow[];
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
function expandRow(
|
|
629
|
+
value: unknown,
|
|
630
|
+
budget: CompactDecodeBudget,
|
|
631
|
+
cols: number | null,
|
|
632
|
+
): TerminalReplicaRow {
|
|
633
|
+
if (++budget.rows > COMPACT_MAX_ROWS) throw new TypeError("Compact semantic row budget exceeded");
|
|
634
|
+
const input = compactArray(value, 2, "row");
|
|
635
|
+
const wrapped = compactBit(input[0], "wrapped");
|
|
636
|
+
const runs = compactArrayAtMost(input[1], COMPACT_MAX_RUNS, "cell runs");
|
|
637
|
+
const cacheKey = budget.rowCache ? JSON.stringify(input) : null;
|
|
638
|
+
const cached = cacheKey === null ? undefined : budget.rowCache?.get(cacheKey);
|
|
639
|
+
if (cached) {
|
|
640
|
+
budget.runs += cached.runs;
|
|
641
|
+
budget.cells += cached.cells;
|
|
642
|
+
if (budget.runs > COMPACT_MAX_RUNS) throw new TypeError("Compact semantic run budget exceeded");
|
|
643
|
+
if (budget.cells > budget.maxCells)
|
|
644
|
+
throw new TypeError("Compact semantic expanded cell budget exceeded");
|
|
645
|
+
budget.reusedRows += 1;
|
|
646
|
+
return cached.row;
|
|
647
|
+
}
|
|
648
|
+
const runsBefore = budget.runs;
|
|
649
|
+
const cellsBefore = budget.cells;
|
|
650
|
+
const cells: TerminalReplicaCell[] = [];
|
|
651
|
+
for (const valueRun of runs) {
|
|
652
|
+
if (++budget.runs > COMPACT_MAX_RUNS)
|
|
653
|
+
throw new TypeError("Compact semantic run budget exceeded");
|
|
654
|
+
const run = compactArray(valueRun, 6, "cell run");
|
|
655
|
+
const count = compactInteger(run[0], 1, COMPACT_MAX_DIMENSION, "cell run count");
|
|
656
|
+
budget.cells += count;
|
|
657
|
+
if (budget.cells > budget.maxCells)
|
|
658
|
+
throw new TypeError("Compact semantic expanded cell budget exceeded");
|
|
659
|
+
const grapheme = compactString(run[1], "grapheme");
|
|
660
|
+
const width = compactInteger(run[2], 0, 2, "cell width") as 0 | 1 | 2;
|
|
661
|
+
const cell = Object.freeze({
|
|
662
|
+
grapheme,
|
|
663
|
+
width,
|
|
664
|
+
foreground: expandColor(run[3]),
|
|
665
|
+
background: expandColor(run[4]),
|
|
666
|
+
attributes: compactInteger(run[5], 0, 0xff, "cell attributes"),
|
|
667
|
+
});
|
|
668
|
+
for (let index = 0; index < count; index += 1) cells.push(cell);
|
|
669
|
+
}
|
|
670
|
+
if (cols !== null && cells.length !== cols) throw new TypeError("Compact row width mismatch");
|
|
671
|
+
if (cells.length < 1 || cells.length > COMPACT_MAX_DIMENSION)
|
|
672
|
+
throw new TypeError("Compact row width is out of bounds");
|
|
673
|
+
for (let index = 0; index < cells.length; index += 1) {
|
|
674
|
+
if (cells[index]!.width === 2 && cells[index + 1]?.width !== 0)
|
|
675
|
+
throw new TypeError("Malformed compact wide cell");
|
|
676
|
+
if (cells[index]!.width === 0 && (index === 0 || cells[index - 1]?.width !== 2))
|
|
677
|
+
throw new TypeError("Malformed compact continuation cell");
|
|
678
|
+
}
|
|
679
|
+
const row = Object.freeze({
|
|
680
|
+
cells: Object.freeze(cells),
|
|
681
|
+
wrapped,
|
|
682
|
+
}) as unknown as TerminalReplicaRow;
|
|
683
|
+
budget.allocatedCells += cells.length;
|
|
684
|
+
if (cacheKey !== null)
|
|
685
|
+
budget.rowCache?.set(
|
|
686
|
+
cacheKey,
|
|
687
|
+
Object.freeze({
|
|
688
|
+
row,
|
|
689
|
+
runs: budget.runs - runsBefore,
|
|
690
|
+
cells: budget.cells - cellsBefore,
|
|
691
|
+
}),
|
|
692
|
+
);
|
|
693
|
+
return row;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
function expandColor(value: unknown): TerminalReplicaColor {
|
|
697
|
+
if (value === 0) return COMPACT_DEFAULT_COLOR;
|
|
698
|
+
const pair = compactArray(value, 2, "color");
|
|
699
|
+
if (pair[0] === 1)
|
|
700
|
+
return Object.freeze({
|
|
701
|
+
kind: "indexed",
|
|
702
|
+
index: compactInteger(pair[1], 0, 255, "indexed color"),
|
|
703
|
+
});
|
|
704
|
+
if (pair[0] === 2)
|
|
705
|
+
return Object.freeze({
|
|
706
|
+
kind: "rgb",
|
|
707
|
+
value: compactInteger(pair[1], 0, 0xffffff, "rgb color"),
|
|
708
|
+
});
|
|
709
|
+
throw new TypeError("Invalid compact color kind");
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
function expandCursor(
|
|
713
|
+
value: unknown,
|
|
714
|
+
cols: number | null,
|
|
715
|
+
rows: number | null,
|
|
716
|
+
): TerminalReplicaSnapshot["cursor"] {
|
|
717
|
+
const input = compactArray(value, 5, "cursor");
|
|
718
|
+
const x = compactInteger(input[0], 0, COMPACT_MAX_DIMENSION - 1, "cursor x");
|
|
719
|
+
const y = compactInteger(input[1], 0, COMPACT_MAX_DIMENSION - 1, "cursor y");
|
|
720
|
+
if ((cols !== null && x >= cols) || (rows !== null && y >= rows))
|
|
721
|
+
throw new TypeError("Compact cursor is outside the viewport");
|
|
722
|
+
if (!(["block", "underline", "bar"] as unknown[]).includes(input[3]))
|
|
723
|
+
throw new TypeError("Invalid compact cursor style");
|
|
724
|
+
return Object.freeze({
|
|
725
|
+
x,
|
|
726
|
+
y,
|
|
727
|
+
hidden: compactBit(input[2], "cursor hidden"),
|
|
728
|
+
style: input[3] as "block" | "underline" | "bar",
|
|
729
|
+
blink: compactBit(input[4], "cursor blink"),
|
|
730
|
+
});
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
function expandModes(value: unknown): TerminalReplicaSnapshot["modes"] {
|
|
734
|
+
const input = compactArray(value, 11, "modes");
|
|
735
|
+
const mouseProtocol = input[8];
|
|
736
|
+
const mouseEncoding = input[9];
|
|
737
|
+
if (
|
|
738
|
+
mouseProtocol !== null &&
|
|
739
|
+
!["none", "x10", "vt200", "drag", "any"].includes(String(mouseProtocol))
|
|
740
|
+
)
|
|
741
|
+
throw new TypeError("Invalid compact mouse protocol");
|
|
742
|
+
if (
|
|
743
|
+
mouseEncoding !== null &&
|
|
744
|
+
!["default", "utf8", "sgr", "sgr-pixels"].includes(String(mouseEncoding))
|
|
745
|
+
)
|
|
746
|
+
throw new TypeError("Invalid compact mouse encoding");
|
|
747
|
+
return Object.freeze({
|
|
748
|
+
alternateScreen: compactBit(input[0], "alternate screen"),
|
|
749
|
+
applicationCursor: compactBit(input[1], "application cursor"),
|
|
750
|
+
applicationKeypad: compactBit(input[2], "application keypad"),
|
|
751
|
+
bracketedPaste: compactBit(input[3], "bracketed paste"),
|
|
752
|
+
insert: compactBit(input[4], "insert"),
|
|
753
|
+
origin: compactBit(input[5], "origin"),
|
|
754
|
+
wraparound: compactBit(input[6], "wraparound"),
|
|
755
|
+
mouseTracking: compactBit(input[7], "mouse tracking"),
|
|
756
|
+
...(mouseProtocol === null
|
|
757
|
+
? {}
|
|
758
|
+
: { mouseProtocol: mouseProtocol as TerminalReplicaSnapshot["modes"]["mouseProtocol"] }),
|
|
759
|
+
...(mouseEncoding === null
|
|
760
|
+
? {}
|
|
761
|
+
: { mouseEncoding: mouseEncoding as TerminalReplicaSnapshot["modes"]["mouseEncoding"] }),
|
|
762
|
+
synchronizedOutput: compactBit(input[10], "synchronized output"),
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
function expandPlacements(
|
|
767
|
+
value: unknown,
|
|
768
|
+
budget: CompactDecodeBudget,
|
|
769
|
+
): TerminalReplicaSnapshot["placements"] {
|
|
770
|
+
const inputs = compactArrayAtMost(value, COMPACT_MAX_PLACEMENTS, "placements");
|
|
771
|
+
budget.placements += inputs.length;
|
|
772
|
+
if (budget.placements > COMPACT_MAX_PLACEMENTS)
|
|
773
|
+
throw new TypeError("Compact placement budget exceeded");
|
|
774
|
+
return Object.freeze(
|
|
775
|
+
inputs.map((value) => {
|
|
776
|
+
const input = compactArray(value, 7, "placement");
|
|
777
|
+
return Object.freeze({
|
|
778
|
+
id: compactString(input[0], "placement id", true),
|
|
779
|
+
kind: compactString(input[1], "placement kind", true),
|
|
780
|
+
row: compactInteger(input[2], 0, COMPACT_MAX_DIMENSION - 1, "placement row"),
|
|
781
|
+
column: compactInteger(input[3], 0, COMPACT_MAX_DIMENSION - 1, "placement column"),
|
|
782
|
+
columns: compactInteger(input[4], 1, COMPACT_MAX_DIMENSION, "placement columns"),
|
|
783
|
+
rows: compactInteger(input[5], 1, COMPACT_MAX_DIMENSION, "placement rows"),
|
|
784
|
+
contentDigest: compactString(input[6], "placement digest", true),
|
|
785
|
+
});
|
|
786
|
+
}),
|
|
787
|
+
) as unknown as TerminalReplicaSnapshot["placements"];
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
async function expandPlacementsCooperatively(
|
|
791
|
+
value: unknown,
|
|
792
|
+
budget: CompactDecodeBudget,
|
|
793
|
+
control: CompactCooperativeControl,
|
|
794
|
+
): Promise<TerminalReplicaSnapshot["placements"]> {
|
|
795
|
+
const inputs = compactArrayAtMost(value, COMPACT_MAX_PLACEMENTS, "placements");
|
|
796
|
+
budget.placements += inputs.length;
|
|
797
|
+
if (budget.placements > COMPACT_MAX_PLACEMENTS)
|
|
798
|
+
throw new TypeError("Compact placement budget exceeded");
|
|
799
|
+
const placements: TerminalReplicaSnapshot["placements"][number][] = [];
|
|
800
|
+
for (let index = 0; index < inputs.length; index += 1) {
|
|
801
|
+
const input = compactArray(inputs[index], 7, "placement");
|
|
802
|
+
placements.push(
|
|
803
|
+
Object.freeze({
|
|
804
|
+
id: compactString(input[0], "placement id", true),
|
|
805
|
+
kind: compactString(input[1], "placement kind", true),
|
|
806
|
+
row: compactInteger(input[2], 0, COMPACT_MAX_DIMENSION - 1, "placement row"),
|
|
807
|
+
column: compactInteger(input[3], 0, COMPACT_MAX_DIMENSION - 1, "placement column"),
|
|
808
|
+
columns: compactInteger(input[4], 1, COMPACT_MAX_DIMENSION, "placement columns"),
|
|
809
|
+
rows: compactInteger(input[5], 1, COMPACT_MAX_DIMENSION, "placement rows"),
|
|
810
|
+
contentDigest: compactString(input[6], "placement digest", true),
|
|
811
|
+
}),
|
|
812
|
+
);
|
|
813
|
+
// The parsed wire container is private and single-use. Drop each expanded
|
|
814
|
+
// placement immediately so a large validated prefix cannot coexist with
|
|
815
|
+
// its canonical replacement until the complete envelope finishes.
|
|
816
|
+
inputs[index] = null;
|
|
817
|
+
if ((index + 1) % 16 === 0) await control.yieldControl();
|
|
818
|
+
}
|
|
819
|
+
return Object.freeze(placements) as unknown as TerminalReplicaSnapshot["placements"];
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function expandBootstrap(value: unknown): TerminalReplicaSnapshot["bootstrap"] {
|
|
823
|
+
const input = compactArray(value, 2, "bootstrap");
|
|
824
|
+
if (
|
|
825
|
+
!["painted-capture", "authoritative-stream"].includes(String(input[0])) ||
|
|
826
|
+
!["unknown", "observed-from-start"].includes(String(input[1]))
|
|
827
|
+
)
|
|
828
|
+
throw new TypeError("Invalid compact bootstrap");
|
|
829
|
+
return Object.freeze({
|
|
830
|
+
kind: input[0] as "painted-capture" | "authoritative-stream",
|
|
831
|
+
hiddenState: input[1] as "unknown" | "observed-from-start",
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
function compactArray(value: unknown, length: number, label: string): unknown[] {
|
|
836
|
+
if (!Array.isArray(value) || value.length !== length)
|
|
837
|
+
throw new TypeError(`Invalid compact ${label}`);
|
|
838
|
+
return value;
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
function compactArrayAtMost(value: unknown, maximum: number, label: string): unknown[] {
|
|
842
|
+
if (!Array.isArray(value) || value.length > maximum)
|
|
843
|
+
throw new TypeError(`Invalid compact ${label}`);
|
|
844
|
+
return value;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
function compactInteger(value: unknown, minimum: number, maximum: number, label: string): number {
|
|
848
|
+
if (!Number.isSafeInteger(value) || (value as number) < minimum || (value as number) > maximum)
|
|
849
|
+
throw new TypeError(`Invalid compact ${label}`);
|
|
850
|
+
return value as number;
|
|
851
|
+
}
|
|
852
|
+
|
|
853
|
+
function compactBit(value: unknown, label: string): boolean {
|
|
854
|
+
if (value !== 0 && value !== 1) throw new TypeError(`Invalid compact ${label}`);
|
|
855
|
+
return value === 1;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
function compactString(value: unknown, label: string, nonempty = false): string {
|
|
859
|
+
if (
|
|
860
|
+
typeof value !== "string" ||
|
|
861
|
+
(nonempty && value.length === 0) ||
|
|
862
|
+
UTF8_ENCODER.encode(value).byteLength > COMPACT_MAX_STRING_BYTES
|
|
863
|
+
)
|
|
864
|
+
throw new TypeError(`Invalid compact ${label}`);
|
|
865
|
+
return value;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
function compactEncodeString(value: string): string {
|
|
869
|
+
if (
|
|
870
|
+
value.length > COMPACT_MAX_STRING_BYTES / 4 &&
|
|
871
|
+
UTF8_ENCODER.encode(value).byteLength > COMPACT_MAX_STRING_BYTES
|
|
872
|
+
)
|
|
873
|
+
compactEncodingLimit();
|
|
874
|
+
return value;
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
function compactEncodingLimit(): never {
|
|
878
|
+
throw new TerminalDeliveryStateTooLargeError(TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES + 1);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
function applyDecodedCompactPatch(
|
|
882
|
+
current: TerminalReplicaSnapshot,
|
|
883
|
+
patch: TerminalReplicaPatchPayload,
|
|
884
|
+
): TerminalReplicaSnapshot {
|
|
885
|
+
const cols = patch.dimensions?.cols ?? current.cols;
|
|
886
|
+
const rows = patch.dimensions?.rows ?? current.rows;
|
|
887
|
+
if (patch.history !== undefined && patch.historyDelta !== undefined)
|
|
888
|
+
throw new TypeError("Compact patch has two history representations");
|
|
889
|
+
if ((patch.historyDelta?.trim ?? 0) > current.history.length)
|
|
890
|
+
throw new TypeError("Compact history trim is out of bounds");
|
|
891
|
+
const resizedBlank =
|
|
892
|
+
cols === current.cols && rows === current.rows ? null : compactBlankRow(cols);
|
|
893
|
+
const nextGrid: TerminalReplicaRow[] =
|
|
894
|
+
cols === current.cols && rows === current.rows && patch.rows.length === 0
|
|
895
|
+
? current.grid
|
|
896
|
+
: cols === current.cols && rows === current.rows
|
|
897
|
+
? [...current.grid]
|
|
898
|
+
: Array.from({ length: rows }, (_, index) => {
|
|
899
|
+
const prior = current.grid[index];
|
|
900
|
+
return prior?.cells.length === cols ? prior : resizedBlank!;
|
|
901
|
+
});
|
|
902
|
+
const seen = new Set<number>();
|
|
903
|
+
for (const change of patch.rows) {
|
|
904
|
+
if (
|
|
905
|
+
change.index < 0 ||
|
|
906
|
+
change.index >= rows ||
|
|
907
|
+
seen.has(change.index) ||
|
|
908
|
+
change.row.cells.length !== cols
|
|
909
|
+
)
|
|
910
|
+
throw new TypeError("Malformed compact terminal row patch");
|
|
911
|
+
seen.add(change.index);
|
|
912
|
+
nextGrid[change.index] = change.row;
|
|
913
|
+
}
|
|
914
|
+
const history = patch.history
|
|
915
|
+
? patch.history
|
|
916
|
+
: patch.historyDelta
|
|
917
|
+
? (() => {
|
|
918
|
+
const retained = current.history.length - patch.historyDelta.trim;
|
|
919
|
+
const nextLength = retained + patch.historyDelta.append.length;
|
|
920
|
+
const unchanged =
|
|
921
|
+
nextLength === current.history.length &&
|
|
922
|
+
current.history.every((row, index) =>
|
|
923
|
+
index < retained
|
|
924
|
+
? row === current.history[index + patch.historyDelta!.trim]
|
|
925
|
+
: row === patch.historyDelta!.append[index - retained],
|
|
926
|
+
);
|
|
927
|
+
return unchanged
|
|
928
|
+
? current.history
|
|
929
|
+
: Object.freeze([
|
|
930
|
+
...current.history.slice(patch.historyDelta.trim),
|
|
931
|
+
...patch.historyDelta.append,
|
|
932
|
+
]);
|
|
933
|
+
})()
|
|
934
|
+
: current.history;
|
|
935
|
+
if (patch.historyDelta && history !== current.history)
|
|
936
|
+
registerTerminalReplicaRowsDeltaHash(
|
|
937
|
+
current.history,
|
|
938
|
+
history,
|
|
939
|
+
patch.historyDelta.trim,
|
|
940
|
+
patch.historyDelta.append,
|
|
941
|
+
);
|
|
942
|
+
if (history.length > COMPACT_MAX_ROWS || history.some((row) => row.cells.length !== cols))
|
|
943
|
+
throw new TypeError("Compact patch retained wrong-width history");
|
|
944
|
+
const cursor = patch.cursor ?? current.cursor;
|
|
945
|
+
if (cursor.x >= cols || cursor.y >= rows) throw new TypeError("Compact cursor is out of bounds");
|
|
946
|
+
const placements = patch.placements ?? current.placements;
|
|
947
|
+
if (
|
|
948
|
+
placements.some(
|
|
949
|
+
(placement) =>
|
|
950
|
+
placement.row + placement.rows > rows || placement.column + placement.columns > cols,
|
|
951
|
+
)
|
|
952
|
+
)
|
|
953
|
+
throw new TypeError("Compact placement is outside the viewport");
|
|
954
|
+
return Object.freeze({
|
|
955
|
+
cols,
|
|
956
|
+
rows,
|
|
957
|
+
grid: Object.freeze(nextGrid) as TerminalReplicaRow[],
|
|
958
|
+
history,
|
|
959
|
+
cursor,
|
|
960
|
+
modes: patch.modes ?? current.modes,
|
|
961
|
+
placements,
|
|
962
|
+
bootstrap: patch.bootstrap ?? current.bootstrap,
|
|
963
|
+
}) as unknown as TerminalReplicaSnapshot;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
function compactBlankRow(cols: number): TerminalReplicaRow {
|
|
967
|
+
const cell = Object.freeze({
|
|
968
|
+
grapheme: " ",
|
|
969
|
+
width: 1 as const,
|
|
970
|
+
foreground: COMPACT_DEFAULT_COLOR,
|
|
971
|
+
background: COMPACT_DEFAULT_COLOR,
|
|
972
|
+
attributes: 0,
|
|
973
|
+
});
|
|
974
|
+
return Object.freeze({
|
|
975
|
+
cells: Object.freeze(Array.from({ length: cols }, () => cell)),
|
|
976
|
+
wrapped: false,
|
|
977
|
+
}) as unknown as TerminalReplicaRow;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
export interface CompactSemanticCommitProfile {
|
|
981
|
+
readonly reusedCompactPayload: boolean;
|
|
982
|
+
readonly expandedRows: number;
|
|
983
|
+
readonly expandedRuns: number;
|
|
984
|
+
readonly expandedCells: number;
|
|
985
|
+
readonly reusedRows: number;
|
|
986
|
+
readonly allocatedCells: number;
|
|
987
|
+
readonly canonicalUtf8Allocations: number;
|
|
988
|
+
readonly canonicalUtf8Bytes: number;
|
|
989
|
+
readonly validatedCellAllocations: number;
|
|
990
|
+
readonly placements: number;
|
|
991
|
+
readonly schemaTraversals: 1;
|
|
992
|
+
readonly hashTraversals: 1;
|
|
993
|
+
readonly applyTraversals: 0 | 1;
|
|
994
|
+
readonly trustedAdoption: true;
|
|
995
|
+
readonly retainedSnapshots: 0;
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
export function decodeVerifiedCompactSemanticTerminalUpdate(
|
|
999
|
+
bytes: Uint8Array,
|
|
1000
|
+
baseline: TerminalReplicaSnapshot | null,
|
|
1001
|
+
expectedHash: string,
|
|
1002
|
+
options?: {
|
|
1003
|
+
readonly grantReducerAdoption?: boolean;
|
|
1004
|
+
readonly onComplete?: (profile: CompactSemanticCommitProfile) => void;
|
|
1005
|
+
},
|
|
1006
|
+
): Readonly<{
|
|
1007
|
+
payload: TerminalSemanticDeliveryPayload;
|
|
1008
|
+
canonicalSnapshot: TerminalReplicaSnapshot | null;
|
|
1009
|
+
}> {
|
|
1010
|
+
const decodeBudget = options?.onComplete ? compactDecodeBudget(bytes.byteLength) : undefined;
|
|
1011
|
+
const payload = decodeCompactSemanticTerminalUpdateInternal(bytes, decodeBudget);
|
|
1012
|
+
const snapshot =
|
|
1013
|
+
payload.frame === "seed"
|
|
1014
|
+
? payload.snapshot
|
|
1015
|
+
: payload.frame === "patch"
|
|
1016
|
+
? baseline
|
|
1017
|
+
? applyDecodedCompactPatch(baseline, payload.patch)
|
|
1018
|
+
: (() => {
|
|
1019
|
+
throw new TypeError("Semantic delivery baseline gap");
|
|
1020
|
+
})()
|
|
1021
|
+
: null;
|
|
1022
|
+
const hash = snapshot
|
|
1023
|
+
? hashTerminalReplicaSnapshot(snapshot)
|
|
1024
|
+
: hashTerminalReplicaTombstone(
|
|
1025
|
+
payload.frame === "tombstone" ? payload.tombstone.reason : "protocol",
|
|
1026
|
+
);
|
|
1027
|
+
if (hash !== expectedHash) throw new TypeError("Canonical state hash mismatch");
|
|
1028
|
+
compactCommitCapabilities.set(payload, Object.freeze({ snapshot, hash }));
|
|
1029
|
+
if (options?.grantReducerAdoption)
|
|
1030
|
+
grantCompactReplicaCapability(
|
|
1031
|
+
payload.frame === "seed"
|
|
1032
|
+
? payload.snapshot
|
|
1033
|
+
: payload.frame === "patch"
|
|
1034
|
+
? payload.patch
|
|
1035
|
+
: payload.tombstone,
|
|
1036
|
+
baseline,
|
|
1037
|
+
snapshot,
|
|
1038
|
+
hash,
|
|
1039
|
+
);
|
|
1040
|
+
if (options?.onComplete && decodeBudget) {
|
|
1041
|
+
try {
|
|
1042
|
+
options.onComplete(
|
|
1043
|
+
Object.freeze({
|
|
1044
|
+
reusedCompactPayload: false,
|
|
1045
|
+
expandedRows: decodeBudget.rows,
|
|
1046
|
+
expandedRuns: decodeBudget.runs,
|
|
1047
|
+
expandedCells: decodeBudget.cells,
|
|
1048
|
+
reusedRows: decodeBudget.reusedRows,
|
|
1049
|
+
allocatedCells: decodeBudget.allocatedCells,
|
|
1050
|
+
canonicalUtf8Allocations: decodeBudget.canonicalUtf8Allocations,
|
|
1051
|
+
canonicalUtf8Bytes: decodeBudget.canonicalUtf8Bytes,
|
|
1052
|
+
validatedCellAllocations: decodeBudget.validatedCellAllocations,
|
|
1053
|
+
placements: decodeBudget.placements,
|
|
1054
|
+
schemaTraversals: 1,
|
|
1055
|
+
hashTraversals: 1,
|
|
1056
|
+
applyTraversals: payload.frame === "patch" ? 1 : 0,
|
|
1057
|
+
trustedAdoption: true,
|
|
1058
|
+
retainedSnapshots: 0,
|
|
1059
|
+
}),
|
|
1060
|
+
);
|
|
1061
|
+
} catch {
|
|
1062
|
+
// Detailed observers never own canonical delivery.
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
return Object.freeze({ payload, canonicalSnapshot: snapshot });
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
/**
|
|
1069
|
+
* Large compact states are expanded a bounded row slice at a time. Nothing is
|
|
1070
|
+
* published or capability-branded until the complete canonical hash matches.
|
|
1071
|
+
*/
|
|
1072
|
+
export async function decodeVerifiedCompactSemanticTerminalUpdateCooperatively(
|
|
1073
|
+
bytes: Uint8Array,
|
|
1074
|
+
baseline: TerminalReplicaSnapshot | null,
|
|
1075
|
+
expectedHash: string,
|
|
1076
|
+
options: {
|
|
1077
|
+
readonly yieldControl: () => Promise<void>;
|
|
1078
|
+
readonly rowsPerSlice?: number;
|
|
1079
|
+
readonly grantReducerAdoption?: boolean;
|
|
1080
|
+
readonly onComplete?: (profile: CompactSemanticCommitProfile) => void;
|
|
1081
|
+
},
|
|
1082
|
+
): Promise<
|
|
1083
|
+
Readonly<{
|
|
1084
|
+
payload: TerminalSemanticDeliveryPayload;
|
|
1085
|
+
canonicalSnapshot: TerminalReplicaSnapshot | null;
|
|
1086
|
+
}>
|
|
1087
|
+
> {
|
|
1088
|
+
assertRepresentationSize(bytes);
|
|
1089
|
+
const wire = await parseCompactJsonCooperatively(bytes, options.yieldControl);
|
|
1090
|
+
const frame =
|
|
1091
|
+
wire !== null && typeof wire === "object" && !Array.isArray(wire)
|
|
1092
|
+
? (wire as Record<string, unknown>).f
|
|
1093
|
+
: null;
|
|
1094
|
+
if (
|
|
1095
|
+
!recordWithKeys(
|
|
1096
|
+
wire,
|
|
1097
|
+
frame === "s"
|
|
1098
|
+
? ["v", "k", "f", "r", "s"]
|
|
1099
|
+
: ["v", "k", "f", "b", "r", frame === "p" ? "p" : "t"],
|
|
1100
|
+
)
|
|
1101
|
+
)
|
|
1102
|
+
throw new TypeError("Invalid compact semantic envelope");
|
|
1103
|
+
const qualifiedWire = wire as Record<string, unknown>;
|
|
1104
|
+
if (qualifiedWire.v !== COMPACT_SEMANTIC_VERSION || qualifiedWire.k !== COMPACT_SEMANTIC_KIND)
|
|
1105
|
+
throw new TypeError("Unsupported compact semantic version");
|
|
1106
|
+
const revision = compactInteger(qualifiedWire.r, 0, Number.MAX_SAFE_INTEGER, "revision");
|
|
1107
|
+
const budget = compactDecodeBudget(bytes.byteLength);
|
|
1108
|
+
// Cooperative validation never serializes a whole row to form an interning
|
|
1109
|
+
// key; that would recreate an unbounded synchronous phase.
|
|
1110
|
+
budget.rowCache = undefined;
|
|
1111
|
+
budget.runEncodingCache = new TerminalReplicaRunEncodingCache();
|
|
1112
|
+
budget.decodedCellCache = new Map();
|
|
1113
|
+
const control = {
|
|
1114
|
+
yieldControl: options.yieldControl,
|
|
1115
|
+
rowsPerSlice: Math.min(Math.max(options.rowsPerSlice ?? 64, 1), 64),
|
|
1116
|
+
rowsSinceYield: 0,
|
|
1117
|
+
};
|
|
1118
|
+
if (baseline) {
|
|
1119
|
+
budget.rowReuseIndex = await compactBaselineRowReuseIndex(baseline, control);
|
|
1120
|
+
let rawRows: ValidatedCompactRawRowIndex | undefined;
|
|
1121
|
+
for (const rows of [baseline.grid, baseline.history])
|
|
1122
|
+
for (const row of rows) {
|
|
1123
|
+
rawRows = VALIDATED_COMPACT_RAW_ROW_INDEX.get(row);
|
|
1124
|
+
if (rawRows) break;
|
|
1125
|
+
}
|
|
1126
|
+
if (!rawRows) {
|
|
1127
|
+
const nextRawRows = new Map<number, ValidatedCompactRawRowCandidate>();
|
|
1128
|
+
let indexedRows = 0;
|
|
1129
|
+
for (const rows of [baseline.grid, baseline.history])
|
|
1130
|
+
for (const row of rows) {
|
|
1131
|
+
const cached = VALIDATED_COMPACT_RAW_ROW.get(row);
|
|
1132
|
+
if (cached) {
|
|
1133
|
+
const existing = nextRawRows.get(cached.rawHash);
|
|
1134
|
+
if (!existing) nextRawRows.set(cached.rawHash, cached);
|
|
1135
|
+
else if (
|
|
1136
|
+
existing.row !== row &&
|
|
1137
|
+
!existing.collisions?.some((entry) => entry.row === row)
|
|
1138
|
+
)
|
|
1139
|
+
nextRawRows.set(
|
|
1140
|
+
cached.rawHash,
|
|
1141
|
+
Object.freeze({
|
|
1142
|
+
...existing,
|
|
1143
|
+
collisions: Object.freeze([...(existing.collisions ?? []), cached]),
|
|
1144
|
+
}),
|
|
1145
|
+
);
|
|
1146
|
+
}
|
|
1147
|
+
indexedRows += 1;
|
|
1148
|
+
if (indexedRows % control.rowsPerSlice === 0) await control.yieldControl();
|
|
1149
|
+
}
|
|
1150
|
+
rawRows = nextRawRows;
|
|
1151
|
+
let installedRows = 0;
|
|
1152
|
+
for (const rows of [baseline.grid, baseline.history])
|
|
1153
|
+
for (const row of rows) {
|
|
1154
|
+
VALIDATED_COMPACT_RAW_ROW_INDEX.set(row, rawRows);
|
|
1155
|
+
installedRows += 1;
|
|
1156
|
+
if (installedRows % control.rowsPerSlice === 0) await control.yieldControl();
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
budget.rawRowReuseIndex = rawRows;
|
|
1160
|
+
}
|
|
1161
|
+
let payload: TerminalSemanticDeliveryPayload;
|
|
1162
|
+
if (qualifiedWire.f === "s") {
|
|
1163
|
+
const encodedSnapshot = qualifiedWire.s;
|
|
1164
|
+
qualifiedWire.s = null;
|
|
1165
|
+
payload = Object.freeze({
|
|
1166
|
+
frame: "seed" as const,
|
|
1167
|
+
revision,
|
|
1168
|
+
snapshot: await expandSnapshotCooperatively(encodedSnapshot, budget, control),
|
|
1169
|
+
});
|
|
1170
|
+
} else {
|
|
1171
|
+
const baseRevision = compactInteger(
|
|
1172
|
+
qualifiedWire.b,
|
|
1173
|
+
0,
|
|
1174
|
+
Number.MAX_SAFE_INTEGER,
|
|
1175
|
+
"base revision",
|
|
1176
|
+
);
|
|
1177
|
+
if (revision <= baseRevision) throw new TypeError("Compact semantic revision did not advance");
|
|
1178
|
+
if (qualifiedWire.f === "p") {
|
|
1179
|
+
const encodedPatch = qualifiedWire.p;
|
|
1180
|
+
qualifiedWire.p = null;
|
|
1181
|
+
payload = Object.freeze({
|
|
1182
|
+
frame: "patch" as const,
|
|
1183
|
+
baseRevision,
|
|
1184
|
+
revision,
|
|
1185
|
+
patch: await expandPatchCooperatively(encodedPatch, budget, control),
|
|
1186
|
+
});
|
|
1187
|
+
} else if (
|
|
1188
|
+
qualifiedWire.f === "t" &&
|
|
1189
|
+
["pane-closed", "session-restarted", "runtime-disposed"].includes(String(qualifiedWire.t))
|
|
1190
|
+
)
|
|
1191
|
+
payload = Object.freeze({
|
|
1192
|
+
frame: "tombstone" as const,
|
|
1193
|
+
baseRevision,
|
|
1194
|
+
revision,
|
|
1195
|
+
tombstone: Object.freeze({
|
|
1196
|
+
reason: qualifiedWire.t as "pane-closed" | "session-restarted" | "runtime-disposed",
|
|
1197
|
+
}),
|
|
1198
|
+
});
|
|
1199
|
+
else throw new TypeError("Invalid compact semantic frame");
|
|
1200
|
+
}
|
|
1201
|
+
const snapshot =
|
|
1202
|
+
payload.frame === "seed"
|
|
1203
|
+
? payload.snapshot
|
|
1204
|
+
: payload.frame === "patch"
|
|
1205
|
+
? baseline
|
|
1206
|
+
? applyDecodedCompactPatch(baseline, payload.patch)
|
|
1207
|
+
: (() => {
|
|
1208
|
+
throw new TypeError("Semantic delivery baseline gap");
|
|
1209
|
+
})()
|
|
1210
|
+
: null;
|
|
1211
|
+
// Expansion has either adopted immutable baseline rows or constructed the
|
|
1212
|
+
// bounded changed rows. Parser/reuse scratch cannot affect canonical hashing
|
|
1213
|
+
// or publication, so release it before the longest cooperative phase.
|
|
1214
|
+
budget.rowReuseIndex = undefined;
|
|
1215
|
+
budget.rawRowReuseIndex = undefined;
|
|
1216
|
+
budget.runEncodingCache = undefined;
|
|
1217
|
+
budget.decodedCellCache = undefined;
|
|
1218
|
+
const hash = snapshot
|
|
1219
|
+
? await hashTerminalReplicaSnapshotCooperatively(snapshot, options.yieldControl)
|
|
1220
|
+
: hashTerminalReplicaTombstone(
|
|
1221
|
+
payload.frame === "tombstone" ? payload.tombstone.reason : "protocol",
|
|
1222
|
+
);
|
|
1223
|
+
if (hash !== expectedHash) throw new TypeError("Canonical state hash mismatch");
|
|
1224
|
+
if (options.grantReducerAdoption)
|
|
1225
|
+
grantCompactReplicaCapability(
|
|
1226
|
+
payload.frame === "seed"
|
|
1227
|
+
? payload.snapshot
|
|
1228
|
+
: payload.frame === "patch"
|
|
1229
|
+
? payload.patch
|
|
1230
|
+
: payload.tombstone,
|
|
1231
|
+
baseline,
|
|
1232
|
+
snapshot,
|
|
1233
|
+
hash,
|
|
1234
|
+
);
|
|
1235
|
+
if (options.onComplete) {
|
|
1236
|
+
try {
|
|
1237
|
+
options.onComplete(
|
|
1238
|
+
Object.freeze({
|
|
1239
|
+
reusedCompactPayload: false,
|
|
1240
|
+
expandedRows: budget.rows,
|
|
1241
|
+
expandedRuns: budget.runs,
|
|
1242
|
+
expandedCells: budget.cells,
|
|
1243
|
+
reusedRows: budget.reusedRows,
|
|
1244
|
+
allocatedCells: budget.allocatedCells,
|
|
1245
|
+
canonicalUtf8Allocations: budget.canonicalUtf8Allocations,
|
|
1246
|
+
canonicalUtf8Bytes: budget.canonicalUtf8Bytes,
|
|
1247
|
+
validatedCellAllocations: budget.validatedCellAllocations,
|
|
1248
|
+
placements: budget.placements,
|
|
1249
|
+
schemaTraversals: 1,
|
|
1250
|
+
hashTraversals: 1,
|
|
1251
|
+
applyTraversals: payload.frame === "patch" ? 1 : 0,
|
|
1252
|
+
trustedAdoption: true,
|
|
1253
|
+
retainedSnapshots: 0,
|
|
1254
|
+
}),
|
|
1255
|
+
);
|
|
1256
|
+
} catch {
|
|
1257
|
+
// Detailed observers never own canonical delivery.
|
|
1258
|
+
}
|
|
1259
|
+
}
|
|
1260
|
+
return Object.freeze({ payload, canonicalSnapshot: snapshot });
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
const COOPERATIVE_JSON_WORK_CHARS = 16 * 1_024;
|
|
1264
|
+
const COOPERATIVE_JSON_MAX_STRING_CHARS = COMPACT_MAX_STRING_BYTES * 6 + 2;
|
|
1265
|
+
const COOPERATIVE_CELL_WORK = 256;
|
|
1266
|
+
|
|
1267
|
+
async function parseCompactJsonCooperatively(
|
|
1268
|
+
bytes: Uint8Array,
|
|
1269
|
+
yieldControl: () => Promise<void>,
|
|
1270
|
+
): Promise<unknown> {
|
|
1271
|
+
const parser = new CooperativeJsonParser(new CooperativeJsonSource(bytes), yieldControl, true);
|
|
1272
|
+
return parser.parse();
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
const COMPACT_PARSED_ROW_SLICE = Symbol("compact-parsed-row-slice");
|
|
1276
|
+
interface CompactParsedRowSlice {
|
|
1277
|
+
readonly kind: typeof COMPACT_PARSED_ROW_SLICE;
|
|
1278
|
+
readonly source: CooperativeJsonSource;
|
|
1279
|
+
readonly start: number;
|
|
1280
|
+
readonly end: number;
|
|
1281
|
+
}
|
|
1282
|
+
const COMPACT_PARSED_ROWS_SLICE = Symbol("compact-parsed-rows-slice");
|
|
1283
|
+
interface CompactParsedRowsSlice {
|
|
1284
|
+
readonly kind: typeof COMPACT_PARSED_ROWS_SLICE;
|
|
1285
|
+
readonly source: CooperativeJsonSource;
|
|
1286
|
+
readonly start: number;
|
|
1287
|
+
readonly end: number;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
class CooperativeJsonSource {
|
|
1291
|
+
readonly #bytes: Uint8Array;
|
|
1292
|
+
readonly length: number;
|
|
1293
|
+
|
|
1294
|
+
constructor(bytes: Uint8Array) {
|
|
1295
|
+
this.#bytes = bytes;
|
|
1296
|
+
this.length = bytes.byteLength;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
byteAt(index: number): number {
|
|
1300
|
+
return this.#bytes[index] ?? -1;
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
startsWithAscii(value: string, index: number): boolean {
|
|
1304
|
+
for (let offset = 0; offset < value.length; offset += 1)
|
|
1305
|
+
if (this.byteAt(index + offset) !== value.charCodeAt(offset)) return false;
|
|
1306
|
+
return true;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
slice(start: number, end: number): string {
|
|
1310
|
+
return new TextDecoder("utf-8", { fatal: true }).decode(this.#bytes.subarray(start, end));
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
bytes(start: number, end: number): Uint8Array {
|
|
1314
|
+
return this.#bytes.subarray(start, end);
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
hash(start: number, end: number): number {
|
|
1318
|
+
let hash = 0x811c9dc5;
|
|
1319
|
+
for (let index = start; index < end; index += 1) {
|
|
1320
|
+
hash ^= this.#bytes[index]!;
|
|
1321
|
+
hash = Math.imul(hash, 0x01000193);
|
|
1322
|
+
}
|
|
1323
|
+
return hash >>> 0;
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
equals(start: number, end: number, expected: Uint8Array): boolean {
|
|
1327
|
+
if (end - start !== expected.byteLength) return false;
|
|
1328
|
+
for (let index = 0; index < expected.byteLength; index += 1)
|
|
1329
|
+
if (this.#bytes[start + index] !== expected[index]) return false;
|
|
1330
|
+
return true;
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
|
|
1334
|
+
const compactJsonWhitespaceByte = (byte: number): boolean =>
|
|
1335
|
+
byte === 0x20 || byte === 0x09 || byte === 0x0a || byte === 0x0d;
|
|
1336
|
+
|
|
1337
|
+
const compactJsonNumberByte = (byte: number): boolean =>
|
|
1338
|
+
(byte >= 0x30 && byte <= 0x39) ||
|
|
1339
|
+
byte === 0x65 ||
|
|
1340
|
+
byte === 0x45 ||
|
|
1341
|
+
byte === 0x2b ||
|
|
1342
|
+
byte === 0x2d ||
|
|
1343
|
+
byte === 0x2e;
|
|
1344
|
+
|
|
1345
|
+
class CooperativeJsonParser {
|
|
1346
|
+
readonly #source: CooperativeJsonSource;
|
|
1347
|
+
readonly #yieldControl: () => Promise<void>;
|
|
1348
|
+
#index = 0;
|
|
1349
|
+
#work = 0;
|
|
1350
|
+
readonly #retainRowsAsSlices: boolean;
|
|
1351
|
+
|
|
1352
|
+
constructor(
|
|
1353
|
+
source: CooperativeJsonSource,
|
|
1354
|
+
yieldControl: () => Promise<void>,
|
|
1355
|
+
retainRowsAsSlices = false,
|
|
1356
|
+
) {
|
|
1357
|
+
this.#source = source;
|
|
1358
|
+
this.#yieldControl = yieldControl;
|
|
1359
|
+
this.#retainRowsAsSlices = retainRowsAsSlices;
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
async parse(): Promise<unknown> {
|
|
1363
|
+
await this.#space();
|
|
1364
|
+
const value = await this.#value(0);
|
|
1365
|
+
await this.#space();
|
|
1366
|
+
if (this.#index !== this.#source.length) throw new SyntaxError("Trailing compact JSON input");
|
|
1367
|
+
return value;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
#checkpoint(amount = 1): Promise<void> | null {
|
|
1371
|
+
this.#work += amount;
|
|
1372
|
+
if (this.#work < COOPERATIVE_JSON_WORK_CHARS) return null;
|
|
1373
|
+
this.#work = 0;
|
|
1374
|
+
return this.#yieldControl();
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
async #space(): Promise<void> {
|
|
1378
|
+
while (compactJsonWhitespaceByte(this.#source.byteAt(this.#index))) {
|
|
1379
|
+
this.#index += 1;
|
|
1380
|
+
const checkpoint = this.#checkpoint();
|
|
1381
|
+
if (checkpoint) await checkpoint;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
async #value(depth: number): Promise<unknown> {
|
|
1386
|
+
if (depth > 64) throw new SyntaxError("Compact JSON nesting exceeded");
|
|
1387
|
+
await this.#space();
|
|
1388
|
+
const head = this.#source.byteAt(this.#index);
|
|
1389
|
+
if (head === 0x22) return this.#string();
|
|
1390
|
+
if (head === 0x5b) return this.#array(depth + 1);
|
|
1391
|
+
if (head === 0x7b) return this.#object(depth + 1);
|
|
1392
|
+
if (head === 0x74 && this.#source.startsWithAscii("true", this.#index)) {
|
|
1393
|
+
this.#index += 4;
|
|
1394
|
+
const checkpoint = this.#checkpoint(4);
|
|
1395
|
+
if (checkpoint) await checkpoint;
|
|
1396
|
+
return true;
|
|
1397
|
+
}
|
|
1398
|
+
if (head === 0x66 && this.#source.startsWithAscii("false", this.#index)) {
|
|
1399
|
+
this.#index += 5;
|
|
1400
|
+
const checkpoint = this.#checkpoint(5);
|
|
1401
|
+
if (checkpoint) await checkpoint;
|
|
1402
|
+
return false;
|
|
1403
|
+
}
|
|
1404
|
+
if (head === 0x6e && this.#source.startsWithAscii("null", this.#index)) {
|
|
1405
|
+
this.#index += 4;
|
|
1406
|
+
const checkpoint = this.#checkpoint(4);
|
|
1407
|
+
if (checkpoint) await checkpoint;
|
|
1408
|
+
return null;
|
|
1409
|
+
}
|
|
1410
|
+
return this.#number();
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
async #string(): Promise<string> {
|
|
1414
|
+
const start = this.#index;
|
|
1415
|
+
this.#index += 1;
|
|
1416
|
+
let checkpoint = this.#checkpoint();
|
|
1417
|
+
if (checkpoint) await checkpoint;
|
|
1418
|
+
let escaped = false;
|
|
1419
|
+
while (this.#index < this.#source.length) {
|
|
1420
|
+
const character = this.#source.byteAt(this.#index);
|
|
1421
|
+
this.#index += 1;
|
|
1422
|
+
checkpoint = this.#checkpoint();
|
|
1423
|
+
if (checkpoint) await checkpoint;
|
|
1424
|
+
if (!escaped && character === 0x22) {
|
|
1425
|
+
const token = this.#source.slice(start, this.#index);
|
|
1426
|
+
return JSON.parse(token) as string;
|
|
1427
|
+
}
|
|
1428
|
+
escaped = !escaped && character === 0x5c;
|
|
1429
|
+
if (character !== 0x5c) escaped = false;
|
|
1430
|
+
if (this.#index - start > COOPERATIVE_JSON_MAX_STRING_CHARS)
|
|
1431
|
+
throw new SyntaxError("Compact JSON string exceeded");
|
|
1432
|
+
}
|
|
1433
|
+
throw new SyntaxError("Unterminated compact JSON string");
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
async #number(): Promise<number> {
|
|
1437
|
+
const start = this.#index;
|
|
1438
|
+
while (compactJsonNumberByte(this.#source.byteAt(this.#index))) {
|
|
1439
|
+
this.#index += 1;
|
|
1440
|
+
const checkpoint = this.#checkpoint();
|
|
1441
|
+
if (checkpoint) await checkpoint;
|
|
1442
|
+
if (this.#index - start > 64) throw new SyntaxError("Compact JSON number exceeded");
|
|
1443
|
+
}
|
|
1444
|
+
if (this.#index === start) throw new SyntaxError("Invalid compact JSON value");
|
|
1445
|
+
const token = this.#source.slice(start, this.#index);
|
|
1446
|
+
const value = Number(token);
|
|
1447
|
+
if (!Number.isFinite(value) || JSON.parse(token) !== value)
|
|
1448
|
+
throw new SyntaxError("Invalid compact JSON number");
|
|
1449
|
+
return value;
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
async #array(depth: number): Promise<unknown> {
|
|
1453
|
+
const start = this.#index;
|
|
1454
|
+
if (
|
|
1455
|
+
this.#retainRowsAsSlices &&
|
|
1456
|
+
(this.#source.startsWithAscii("[[0,[[", start) ||
|
|
1457
|
+
this.#source.startsWithAscii("[[1,[[", start))
|
|
1458
|
+
)
|
|
1459
|
+
return this.#rowsSlice(start);
|
|
1460
|
+
if (this.#retainRowsAsSlices && this.#looksLikeCompactRow(start)) return this.#rowSlice(start);
|
|
1461
|
+
this.#index += 1;
|
|
1462
|
+
let checkpoint = this.#checkpoint();
|
|
1463
|
+
if (checkpoint) await checkpoint;
|
|
1464
|
+
const values: unknown[] = [];
|
|
1465
|
+
await this.#space();
|
|
1466
|
+
if (this.#source.byteAt(this.#index) === 0x5d) {
|
|
1467
|
+
this.#index += 1;
|
|
1468
|
+
checkpoint = this.#checkpoint();
|
|
1469
|
+
if (checkpoint) await checkpoint;
|
|
1470
|
+
return values;
|
|
1471
|
+
}
|
|
1472
|
+
while (true) {
|
|
1473
|
+
values.push(await this.#value(depth));
|
|
1474
|
+
await this.#space();
|
|
1475
|
+
const separator = this.#source.byteAt(this.#index);
|
|
1476
|
+
this.#index += 1;
|
|
1477
|
+
checkpoint = this.#checkpoint();
|
|
1478
|
+
if (checkpoint) await checkpoint;
|
|
1479
|
+
if (separator === 0x5d) {
|
|
1480
|
+
if (
|
|
1481
|
+
this.#retainRowsAsSlices &&
|
|
1482
|
+
values.length === 2 &&
|
|
1483
|
+
(values[0] === 0 || values[0] === 1) &&
|
|
1484
|
+
Array.isArray(values[1]) &&
|
|
1485
|
+
values[1].every(
|
|
1486
|
+
(run) =>
|
|
1487
|
+
Array.isArray(run) &&
|
|
1488
|
+
run.length === 6 &&
|
|
1489
|
+
typeof run[0] === "number" &&
|
|
1490
|
+
typeof run[1] === "string",
|
|
1491
|
+
)
|
|
1492
|
+
)
|
|
1493
|
+
return Object.freeze({
|
|
1494
|
+
kind: COMPACT_PARSED_ROW_SLICE,
|
|
1495
|
+
source: this.#source,
|
|
1496
|
+
start,
|
|
1497
|
+
end: this.#index,
|
|
1498
|
+
}) satisfies CompactParsedRowSlice;
|
|
1499
|
+
return values;
|
|
1500
|
+
}
|
|
1501
|
+
if (separator !== 0x2c) throw new SyntaxError("Invalid compact JSON array");
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
|
|
1505
|
+
#looksLikeCompactRow(start: number): boolean {
|
|
1506
|
+
if (
|
|
1507
|
+
!this.#source.startsWithAscii("[0,[[", start) &&
|
|
1508
|
+
!this.#source.startsWithAscii("[1,[[", start)
|
|
1509
|
+
)
|
|
1510
|
+
return false;
|
|
1511
|
+
let index = start + 5;
|
|
1512
|
+
const countStart = index;
|
|
1513
|
+
while (this.#source.byteAt(index) >= 0x30 && this.#source.byteAt(index) <= 0x39) index += 1;
|
|
1514
|
+
return (
|
|
1515
|
+
index > countStart &&
|
|
1516
|
+
this.#source.byteAt(index) === 0x2c &&
|
|
1517
|
+
this.#source.byteAt(index + 1) === 0x22
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
|
|
1521
|
+
async #rowSlice(start: number): Promise<CompactParsedRowSlice> {
|
|
1522
|
+
const slice = await this.#balancedArraySlice(start);
|
|
1523
|
+
return Object.freeze({ kind: COMPACT_PARSED_ROW_SLICE, ...slice });
|
|
1524
|
+
}
|
|
1525
|
+
|
|
1526
|
+
async #rowsSlice(start: number): Promise<CompactParsedRowsSlice> {
|
|
1527
|
+
const slice = await this.#balancedArraySlice(start);
|
|
1528
|
+
return Object.freeze({ kind: COMPACT_PARSED_ROWS_SLICE, ...slice });
|
|
1529
|
+
}
|
|
1530
|
+
|
|
1531
|
+
async #balancedArraySlice(
|
|
1532
|
+
start: number,
|
|
1533
|
+
): Promise<{ source: CooperativeJsonSource; start: number; end: number }> {
|
|
1534
|
+
let arrayDepth = 0;
|
|
1535
|
+
let inString = false;
|
|
1536
|
+
let escaped = false;
|
|
1537
|
+
while (this.#index < this.#source.length) {
|
|
1538
|
+
const character = this.#source.byteAt(this.#index);
|
|
1539
|
+
this.#index += 1;
|
|
1540
|
+
const checkpoint = this.#checkpoint();
|
|
1541
|
+
if (checkpoint) await checkpoint;
|
|
1542
|
+
if (inString) {
|
|
1543
|
+
if (!escaped && character === 0x22) inString = false;
|
|
1544
|
+
escaped = !escaped && character === 0x5c;
|
|
1545
|
+
if (character !== 0x5c) escaped = false;
|
|
1546
|
+
continue;
|
|
1547
|
+
}
|
|
1548
|
+
if (character === 0x22) {
|
|
1549
|
+
inString = true;
|
|
1550
|
+
continue;
|
|
1551
|
+
}
|
|
1552
|
+
if (character === 0x5b) arrayDepth += 1;
|
|
1553
|
+
else if (character === 0x5d) {
|
|
1554
|
+
arrayDepth -= 1;
|
|
1555
|
+
if (arrayDepth === 0) return { source: this.#source, start, end: this.#index };
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
throw new SyntaxError("Unterminated compact JSON array");
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
async #object(depth: number): Promise<Record<string, unknown>> {
|
|
1562
|
+
this.#index += 1;
|
|
1563
|
+
let checkpoint = this.#checkpoint();
|
|
1564
|
+
if (checkpoint) await checkpoint;
|
|
1565
|
+
const value: Record<string, unknown> = {};
|
|
1566
|
+
await this.#space();
|
|
1567
|
+
if (this.#source.byteAt(this.#index) === 0x7d) {
|
|
1568
|
+
this.#index += 1;
|
|
1569
|
+
checkpoint = this.#checkpoint();
|
|
1570
|
+
if (checkpoint) await checkpoint;
|
|
1571
|
+
return value;
|
|
1572
|
+
}
|
|
1573
|
+
while (true) {
|
|
1574
|
+
if (this.#source.byteAt(this.#index) !== 0x22)
|
|
1575
|
+
throw new SyntaxError("Invalid compact JSON key");
|
|
1576
|
+
const key = await this.#string();
|
|
1577
|
+
await this.#space();
|
|
1578
|
+
if (this.#source.byteAt(this.#index) !== 0x3a)
|
|
1579
|
+
throw new SyntaxError("Invalid compact JSON object");
|
|
1580
|
+
this.#index += 1;
|
|
1581
|
+
checkpoint = this.#checkpoint();
|
|
1582
|
+
if (checkpoint) await checkpoint;
|
|
1583
|
+
Object.defineProperty(value, key, {
|
|
1584
|
+
configurable: true,
|
|
1585
|
+
enumerable: true,
|
|
1586
|
+
value: await this.#value(depth),
|
|
1587
|
+
writable: true,
|
|
1588
|
+
});
|
|
1589
|
+
await this.#space();
|
|
1590
|
+
const separator = this.#source.byteAt(this.#index);
|
|
1591
|
+
this.#index += 1;
|
|
1592
|
+
checkpoint = this.#checkpoint();
|
|
1593
|
+
if (checkpoint) await checkpoint;
|
|
1594
|
+
if (separator === 0x7d) return value;
|
|
1595
|
+
if (separator !== 0x2c) throw new SyntaxError("Invalid compact JSON object");
|
|
1596
|
+
await this.#space();
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
interface CompactCooperativeControl {
|
|
1602
|
+
readonly yieldControl: () => Promise<void>;
|
|
1603
|
+
readonly rowsPerSlice: number;
|
|
1604
|
+
rowsSinceYield: number;
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1607
|
+
type ValidatedCompactRun = readonly [number, TerminalReplicaCell];
|
|
1608
|
+
|
|
1609
|
+
const compactDecodedColorKey = (color: TerminalReplicaColor): number =>
|
|
1610
|
+
color.kind === "default" ? -1 : color.kind === "indexed" ? color.index : 256 + color.value;
|
|
1611
|
+
|
|
1612
|
+
function compactInternDecodedCell(
|
|
1613
|
+
budget: CompactDecodeBudget,
|
|
1614
|
+
grapheme: string,
|
|
1615
|
+
width: 0 | 1 | 2,
|
|
1616
|
+
foreground: TerminalReplicaColor,
|
|
1617
|
+
background: TerminalReplicaColor,
|
|
1618
|
+
attributesValue: number,
|
|
1619
|
+
): TerminalReplicaCell {
|
|
1620
|
+
const cache = budget.decodedCellCache;
|
|
1621
|
+
if (!cache)
|
|
1622
|
+
return Object.freeze({ grapheme, width, foreground, background, attributes: attributesValue });
|
|
1623
|
+
const widths = cache.get(grapheme) ?? new Map();
|
|
1624
|
+
cache.set(grapheme, widths);
|
|
1625
|
+
const foregroundKey = compactDecodedColorKey(foreground);
|
|
1626
|
+
const foregrounds = widths.get(width) ?? new Map();
|
|
1627
|
+
widths.set(width, foregrounds);
|
|
1628
|
+
const backgroundKey = compactDecodedColorKey(background);
|
|
1629
|
+
const backgrounds = foregrounds.get(foregroundKey) ?? new Map();
|
|
1630
|
+
foregrounds.set(foregroundKey, backgrounds);
|
|
1631
|
+
const attributes = backgrounds.get(backgroundKey) ?? new Map();
|
|
1632
|
+
backgrounds.set(backgroundKey, attributes);
|
|
1633
|
+
const cached = attributes.get(attributesValue);
|
|
1634
|
+
if (cached) return cached;
|
|
1635
|
+
const cell = Object.freeze({
|
|
1636
|
+
grapheme,
|
|
1637
|
+
width,
|
|
1638
|
+
foreground,
|
|
1639
|
+
background,
|
|
1640
|
+
attributes: attributesValue,
|
|
1641
|
+
});
|
|
1642
|
+
attributes.set(attributesValue, cell);
|
|
1643
|
+
budget.validatedCellAllocations += 1;
|
|
1644
|
+
return cell;
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1647
|
+
function compactRowReuseCollision(
|
|
1648
|
+
value: TerminalReplicaRow | readonly TerminalReplicaRow[],
|
|
1649
|
+
): value is readonly TerminalReplicaRow[] {
|
|
1650
|
+
return Array.isArray(value);
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
async function compactBaselineRowReuseIndex(
|
|
1654
|
+
baseline: TerminalReplicaSnapshot,
|
|
1655
|
+
control: CompactCooperativeControl,
|
|
1656
|
+
): Promise<ReadonlyMap<string, TerminalReplicaRow | readonly TerminalReplicaRow[]>> {
|
|
1657
|
+
const index = new Map<string, TerminalReplicaRow | readonly TerminalReplicaRow[]>();
|
|
1658
|
+
let rowsSinceYield = 0;
|
|
1659
|
+
for (const rows of [baseline.grid, baseline.history]) {
|
|
1660
|
+
for (const row of rows) {
|
|
1661
|
+
if (VALIDATED_COMPACT_RAW_ROW.has(row)) continue;
|
|
1662
|
+
if (!isTerminalReplicaRowDeeplyFrozen(row)) continue;
|
|
1663
|
+
const digest = await hashTerminalReplicaRowCooperatively(row, control.yieldControl);
|
|
1664
|
+
const existing = index.get(digest);
|
|
1665
|
+
if (!existing) index.set(digest, row);
|
|
1666
|
+
else if (compactRowReuseCollision(existing)) {
|
|
1667
|
+
if (!existing.includes(row)) index.set(digest, Object.freeze([...existing, row]));
|
|
1668
|
+
} else if (existing !== row) index.set(digest, Object.freeze([existing, row]));
|
|
1669
|
+
rowsSinceYield += 1;
|
|
1670
|
+
if (rowsSinceYield >= control.rowsPerSlice) {
|
|
1671
|
+
rowsSinceYield = 0;
|
|
1672
|
+
await control.yieldControl();
|
|
1673
|
+
}
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
return index;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
function compactColorsEqual(left: TerminalReplicaColor, right: TerminalReplicaColor): boolean {
|
|
1680
|
+
return (
|
|
1681
|
+
left.kind === right.kind &&
|
|
1682
|
+
(left.kind === "default" ||
|
|
1683
|
+
(left.kind === "indexed" && right.kind === "indexed" && left.index === right.index) ||
|
|
1684
|
+
(left.kind === "rgb" && right.kind === "rgb" && left.value === right.value))
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
async function compactRowMatchesRuns(
|
|
1689
|
+
row: TerminalReplicaRow,
|
|
1690
|
+
wrapped: boolean,
|
|
1691
|
+
runs: readonly ValidatedCompactRun[],
|
|
1692
|
+
cellCount: number,
|
|
1693
|
+
control: CompactCooperativeControl,
|
|
1694
|
+
): Promise<boolean> {
|
|
1695
|
+
if (row.wrapped !== wrapped || row.cells.length !== cellCount) return false;
|
|
1696
|
+
let offset = 0;
|
|
1697
|
+
let work = 0;
|
|
1698
|
+
for (const [count, cell] of runs) {
|
|
1699
|
+
for (let index = 0; index < count; index += 1) {
|
|
1700
|
+
const candidate = row.cells[offset++];
|
|
1701
|
+
if (
|
|
1702
|
+
!candidate ||
|
|
1703
|
+
candidate.grapheme !== cell.grapheme ||
|
|
1704
|
+
candidate.width !== cell.width ||
|
|
1705
|
+
candidate.attributes !== cell.attributes ||
|
|
1706
|
+
!compactColorsEqual(candidate.foreground, cell.foreground) ||
|
|
1707
|
+
!compactColorsEqual(candidate.background, cell.background)
|
|
1708
|
+
)
|
|
1709
|
+
return false;
|
|
1710
|
+
work += 1;
|
|
1711
|
+
if (work >= COOPERATIVE_CELL_WORK) {
|
|
1712
|
+
work = 0;
|
|
1713
|
+
await control.yieldControl();
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
return offset === cellCount;
|
|
1718
|
+
}
|
|
1719
|
+
|
|
1720
|
+
async function expandRowsCooperatively(
|
|
1721
|
+
value: unknown,
|
|
1722
|
+
budget: CompactDecodeBudget,
|
|
1723
|
+
cols: number | null,
|
|
1724
|
+
maximum: number,
|
|
1725
|
+
label: string,
|
|
1726
|
+
control: CompactCooperativeControl,
|
|
1727
|
+
): Promise<TerminalReplicaRow[]> {
|
|
1728
|
+
if (
|
|
1729
|
+
value !== null &&
|
|
1730
|
+
typeof value === "object" &&
|
|
1731
|
+
(value as Partial<CompactParsedRowsSlice>).kind === COMPACT_PARSED_ROWS_SLICE
|
|
1732
|
+
)
|
|
1733
|
+
return expandRowsSliceCooperatively(
|
|
1734
|
+
value as CompactParsedRowsSlice,
|
|
1735
|
+
budget,
|
|
1736
|
+
cols,
|
|
1737
|
+
maximum,
|
|
1738
|
+
label,
|
|
1739
|
+
control,
|
|
1740
|
+
);
|
|
1741
|
+
const inputs = compactArrayAtMost(value, maximum, label);
|
|
1742
|
+
if (label === "grid" && cols !== null && inputs.length !== maximum)
|
|
1743
|
+
throw new TypeError("Compact grid cardinality mismatch");
|
|
1744
|
+
const rows: TerminalReplicaRow[] = [];
|
|
1745
|
+
for (let index = 0; index < inputs.length; index += 1) {
|
|
1746
|
+
const input = inputs[index];
|
|
1747
|
+
const row = await expandRowCooperatively(input, budget, cols, control);
|
|
1748
|
+
// Prime only immutable, structurally validated rows. A failed envelope
|
|
1749
|
+
// cannot expose these WeakMap keys or mint a reducer capability.
|
|
1750
|
+
rows.push(row);
|
|
1751
|
+
// Release the parsed run/container graph as soon as its immutable row has
|
|
1752
|
+
// either been reused or constructed. The wire tree is never published.
|
|
1753
|
+
inputs[index] = null;
|
|
1754
|
+
control.rowsSinceYield += 1;
|
|
1755
|
+
if (control.rowsSinceYield >= control.rowsPerSlice) {
|
|
1756
|
+
control.rowsSinceYield = 0;
|
|
1757
|
+
await control.yieldControl();
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
return Object.freeze(rows) as TerminalReplicaRow[];
|
|
1761
|
+
}
|
|
1762
|
+
|
|
1763
|
+
async function expandRowsSliceCooperatively(
|
|
1764
|
+
slice: CompactParsedRowsSlice,
|
|
1765
|
+
budget: CompactDecodeBudget,
|
|
1766
|
+
cols: number | null,
|
|
1767
|
+
maximum: number,
|
|
1768
|
+
label: string,
|
|
1769
|
+
control: CompactCooperativeControl,
|
|
1770
|
+
): Promise<TerminalReplicaRow[]> {
|
|
1771
|
+
const rows: TerminalReplicaRow[] = [];
|
|
1772
|
+
let index = slice.start + 1;
|
|
1773
|
+
const rowSlice = {
|
|
1774
|
+
kind: COMPACT_PARSED_ROW_SLICE,
|
|
1775
|
+
source: slice.source,
|
|
1776
|
+
start: index,
|
|
1777
|
+
end: index,
|
|
1778
|
+
};
|
|
1779
|
+
while (index < slice.end - 1) {
|
|
1780
|
+
if (rows.length >= maximum) throw new TypeError(`Invalid compact ${label}`);
|
|
1781
|
+
const start = index;
|
|
1782
|
+
let depth = 0;
|
|
1783
|
+
let inString = false;
|
|
1784
|
+
let escaped = false;
|
|
1785
|
+
let work = 0;
|
|
1786
|
+
while (index < slice.end) {
|
|
1787
|
+
const character = slice.source.byteAt(index++);
|
|
1788
|
+
work += 1;
|
|
1789
|
+
if (work >= COOPERATIVE_JSON_WORK_CHARS) {
|
|
1790
|
+
work = 0;
|
|
1791
|
+
await control.yieldControl();
|
|
1792
|
+
}
|
|
1793
|
+
if (inString) {
|
|
1794
|
+
if (!escaped && character === 0x22) inString = false;
|
|
1795
|
+
escaped = !escaped && character === 0x5c;
|
|
1796
|
+
if (character !== 0x5c) escaped = false;
|
|
1797
|
+
continue;
|
|
1798
|
+
}
|
|
1799
|
+
if (character === 0x22) inString = true;
|
|
1800
|
+
else if (character === 0x5b) depth += 1;
|
|
1801
|
+
else if (character === 0x5d) {
|
|
1802
|
+
depth -= 1;
|
|
1803
|
+
if (depth === 0) break;
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
if (depth !== 0) throw new SyntaxError("Unterminated compact JSON row");
|
|
1807
|
+
rowSlice.start = start;
|
|
1808
|
+
rowSlice.end = index;
|
|
1809
|
+
rows.push(await expandRowCooperatively(rowSlice, budget, cols, control));
|
|
1810
|
+
const separator = slice.source.byteAt(index++);
|
|
1811
|
+
if (separator === 0x5d) break;
|
|
1812
|
+
if (separator !== 0x2c) throw new SyntaxError("Invalid compact JSON rows");
|
|
1813
|
+
}
|
|
1814
|
+
if (label === "grid" && cols !== null && rows.length !== maximum)
|
|
1815
|
+
throw new TypeError("Compact grid cardinality mismatch");
|
|
1816
|
+
return Object.freeze(rows) as TerminalReplicaRow[];
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
async function expandRowCooperatively(
|
|
1820
|
+
value: unknown,
|
|
1821
|
+
budget: CompactDecodeBudget,
|
|
1822
|
+
cols: number | null,
|
|
1823
|
+
control: CompactCooperativeControl,
|
|
1824
|
+
): Promise<TerminalReplicaRow> {
|
|
1825
|
+
if (++budget.rows > COMPACT_MAX_ROWS) throw new TypeError("Compact semantic row budget exceeded");
|
|
1826
|
+
const parsedSlice =
|
|
1827
|
+
value !== null &&
|
|
1828
|
+
typeof value === "object" &&
|
|
1829
|
+
(value as Partial<CompactParsedRowSlice>).kind === COMPACT_PARSED_ROW_SLICE
|
|
1830
|
+
? (value as CompactParsedRowSlice)
|
|
1831
|
+
: null;
|
|
1832
|
+
const rawHash = parsedSlice ? parsedSlice.source.hash(parsedSlice.start, parsedSlice.end) : null;
|
|
1833
|
+
const rawIndexed = rawHash === null ? undefined : budget.rawRowReuseIndex?.get(rawHash);
|
|
1834
|
+
const rawReuse = !rawIndexed
|
|
1835
|
+
? undefined
|
|
1836
|
+
: parsedSlice!.source.equals(parsedSlice!.start, parsedSlice!.end, rawIndexed.raw)
|
|
1837
|
+
? rawIndexed
|
|
1838
|
+
: rawIndexed.collisions?.find((candidate) =>
|
|
1839
|
+
parsedSlice!.source.equals(parsedSlice!.start, parsedSlice!.end, candidate.raw),
|
|
1840
|
+
);
|
|
1841
|
+
if (rawReuse) {
|
|
1842
|
+
if (cols !== null && rawReuse.cells !== cols) throw new TypeError("Compact row width mismatch");
|
|
1843
|
+
budget.runs += rawReuse.runs;
|
|
1844
|
+
budget.cells += rawReuse.cells;
|
|
1845
|
+
if (budget.runs > COMPACT_MAX_RUNS) throw new TypeError("Compact semantic run budget exceeded");
|
|
1846
|
+
if (budget.cells > budget.maxCells)
|
|
1847
|
+
throw new TypeError("Compact semantic expanded cell budget exceeded");
|
|
1848
|
+
budget.reusedRows += 1;
|
|
1849
|
+
return rawReuse.row;
|
|
1850
|
+
}
|
|
1851
|
+
const parsedValue = await expandParsedRowSlice(value, control);
|
|
1852
|
+
const input = compactArray(parsedValue, 2, "row");
|
|
1853
|
+
const wrapped = compactBit(input[0], "wrapped");
|
|
1854
|
+
const runs = compactArrayAtMost(input[1], COMPACT_MAX_RUNS, "cell runs");
|
|
1855
|
+
const validatedRuns: ValidatedCompactRun[] = [];
|
|
1856
|
+
let cellCount = 0;
|
|
1857
|
+
let cellWork = 0;
|
|
1858
|
+
for (const valueRun of runs) {
|
|
1859
|
+
if (++budget.runs > COMPACT_MAX_RUNS)
|
|
1860
|
+
throw new TypeError("Compact semantic run budget exceeded");
|
|
1861
|
+
const run = compactArray(valueRun, 6, "cell run");
|
|
1862
|
+
const count = compactInteger(run[0], 1, COMPACT_MAX_DIMENSION, "cell run count");
|
|
1863
|
+
budget.cells += count;
|
|
1864
|
+
cellCount += count;
|
|
1865
|
+
if (budget.cells > budget.maxCells)
|
|
1866
|
+
throw new TypeError("Compact semantic expanded cell budget exceeded");
|
|
1867
|
+
const cell = compactInternDecodedCell(
|
|
1868
|
+
budget,
|
|
1869
|
+
compactString(run[1], "grapheme"),
|
|
1870
|
+
compactInteger(run[2], 0, 2, "cell width") as 0 | 1 | 2,
|
|
1871
|
+
expandColor(run[3]),
|
|
1872
|
+
expandColor(run[4]),
|
|
1873
|
+
compactInteger(run[5], 0, 0xff, "cell attributes"),
|
|
1874
|
+
);
|
|
1875
|
+
run.length = 2;
|
|
1876
|
+
run[0] = count;
|
|
1877
|
+
run[1] = cell;
|
|
1878
|
+
validatedRuns.push(run as unknown as ValidatedCompactRun);
|
|
1879
|
+
for (let index = 0; index < count; index += 1) {
|
|
1880
|
+
cellWork += 1;
|
|
1881
|
+
if (cellWork >= COOPERATIVE_CELL_WORK) {
|
|
1882
|
+
cellWork = 0;
|
|
1883
|
+
await control.yieldControl();
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
if (cols !== null && cellCount !== cols) throw new TypeError("Compact row width mismatch");
|
|
1888
|
+
if (cellCount < 1 || cellCount > COMPACT_MAX_DIMENSION)
|
|
1889
|
+
throw new TypeError("Compact row width is out of bounds");
|
|
1890
|
+
let previousWidth: 0 | 1 | 2 | null = null;
|
|
1891
|
+
let validatedCells = 0;
|
|
1892
|
+
for (const [count, cell] of validatedRuns) {
|
|
1893
|
+
for (let index = 0; index < count; index += 1) {
|
|
1894
|
+
if (previousWidth === 2 && cell.width !== 0)
|
|
1895
|
+
throw new TypeError("Malformed compact wide cell");
|
|
1896
|
+
if (cell.width === 0 && previousWidth !== 2)
|
|
1897
|
+
throw new TypeError("Malformed compact continuation cell");
|
|
1898
|
+
previousWidth = cell.width;
|
|
1899
|
+
validatedCells += 1;
|
|
1900
|
+
if (validatedCells % COOPERATIVE_CELL_WORK === 0) await control.yieldControl();
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
if (previousWidth === 2) throw new TypeError("Malformed compact wide cell");
|
|
1904
|
+
const digest = await hashTerminalReplicaRowRunsCooperatively(
|
|
1905
|
+
wrapped,
|
|
1906
|
+
cellCount,
|
|
1907
|
+
validatedRuns,
|
|
1908
|
+
control.yieldControl,
|
|
1909
|
+
64,
|
|
1910
|
+
(bytes) => {
|
|
1911
|
+
budget.canonicalUtf8Allocations += 1;
|
|
1912
|
+
budget.canonicalUtf8Bytes += bytes;
|
|
1913
|
+
},
|
|
1914
|
+
budget.runEncodingCache,
|
|
1915
|
+
);
|
|
1916
|
+
const indexed = budget.rowReuseIndex?.get(digest);
|
|
1917
|
+
if (
|
|
1918
|
+
indexed &&
|
|
1919
|
+
!compactRowReuseCollision(indexed) &&
|
|
1920
|
+
(await compactRowMatchesRuns(indexed, wrapped, validatedRuns, cellCount, control))
|
|
1921
|
+
) {
|
|
1922
|
+
budget.reusedRows += 1;
|
|
1923
|
+
if (parsedSlice !== null && rawHash !== null)
|
|
1924
|
+
VALIDATED_COMPACT_RAW_ROW.set(
|
|
1925
|
+
indexed,
|
|
1926
|
+
Object.freeze({
|
|
1927
|
+
row: indexed,
|
|
1928
|
+
raw: parsedSlice.source.bytes(parsedSlice.start, parsedSlice.end).slice(),
|
|
1929
|
+
rawHash,
|
|
1930
|
+
runs: validatedRuns.length,
|
|
1931
|
+
cells: cellCount,
|
|
1932
|
+
}),
|
|
1933
|
+
);
|
|
1934
|
+
return indexed;
|
|
1935
|
+
}
|
|
1936
|
+
if (indexed && compactRowReuseCollision(indexed)) {
|
|
1937
|
+
for (const candidate of indexed) {
|
|
1938
|
+
if (!(await compactRowMatchesRuns(candidate, wrapped, validatedRuns, cellCount, control)))
|
|
1939
|
+
continue;
|
|
1940
|
+
budget.reusedRows += 1;
|
|
1941
|
+
if (parsedSlice !== null && rawHash !== null)
|
|
1942
|
+
VALIDATED_COMPACT_RAW_ROW.set(
|
|
1943
|
+
candidate,
|
|
1944
|
+
Object.freeze({
|
|
1945
|
+
row: candidate,
|
|
1946
|
+
raw: parsedSlice.source.bytes(parsedSlice.start, parsedSlice.end).slice(),
|
|
1947
|
+
rawHash,
|
|
1948
|
+
runs: validatedRuns.length,
|
|
1949
|
+
cells: cellCount,
|
|
1950
|
+
}),
|
|
1951
|
+
);
|
|
1952
|
+
return candidate;
|
|
1953
|
+
}
|
|
1954
|
+
}
|
|
1955
|
+
const cells: TerminalReplicaCell[] = [];
|
|
1956
|
+
let allocatedWork = 0;
|
|
1957
|
+
for (const [count, cell] of validatedRuns) {
|
|
1958
|
+
for (let index = 0; index < count; index += 1) {
|
|
1959
|
+
cells.push(cell);
|
|
1960
|
+
allocatedWork += 1;
|
|
1961
|
+
if (allocatedWork >= COOPERATIVE_CELL_WORK) {
|
|
1962
|
+
allocatedWork = 0;
|
|
1963
|
+
await control.yieldControl();
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1967
|
+
const row = Object.freeze({
|
|
1968
|
+
cells: Object.freeze(cells),
|
|
1969
|
+
wrapped,
|
|
1970
|
+
}) as unknown as TerminalReplicaRow;
|
|
1971
|
+
budget.allocatedCells += cells.length;
|
|
1972
|
+
primeTerminalReplicaRowHash(row, digest);
|
|
1973
|
+
if (parsedSlice !== null && rawHash !== null)
|
|
1974
|
+
VALIDATED_COMPACT_RAW_ROW.set(
|
|
1975
|
+
row,
|
|
1976
|
+
Object.freeze({
|
|
1977
|
+
row,
|
|
1978
|
+
raw: parsedSlice.source.bytes(parsedSlice.start, parsedSlice.end).slice(),
|
|
1979
|
+
rawHash,
|
|
1980
|
+
runs: validatedRuns.length,
|
|
1981
|
+
cells: cellCount,
|
|
1982
|
+
}),
|
|
1983
|
+
);
|
|
1984
|
+
return row;
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
async function expandParsedRowSlice(
|
|
1988
|
+
value: unknown,
|
|
1989
|
+
control: CompactCooperativeControl,
|
|
1990
|
+
): Promise<unknown> {
|
|
1991
|
+
if (
|
|
1992
|
+
value === null ||
|
|
1993
|
+
typeof value !== "object" ||
|
|
1994
|
+
(value as Partial<CompactParsedRowSlice>).kind !== COMPACT_PARSED_ROW_SLICE
|
|
1995
|
+
)
|
|
1996
|
+
return value;
|
|
1997
|
+
const slice = value as CompactParsedRowSlice;
|
|
1998
|
+
const rowSource = new CooperativeJsonSource(slice.source.bytes(slice.start, slice.end));
|
|
1999
|
+
return new CooperativeJsonParser(rowSource, control.yieldControl).parse();
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
async function expandSnapshotCooperatively(
|
|
2003
|
+
value: unknown,
|
|
2004
|
+
budget: CompactDecodeBudget,
|
|
2005
|
+
control: CompactCooperativeControl,
|
|
2006
|
+
): Promise<TerminalReplicaSnapshot> {
|
|
2007
|
+
const input = compactArray(value, 8, "snapshot");
|
|
2008
|
+
const cols = compactInteger(input[0], 1, COMPACT_MAX_DIMENSION, "columns");
|
|
2009
|
+
const rows = compactInteger(input[1], 1, COMPACT_MAX_DIMENSION, "rows");
|
|
2010
|
+
const grid = await expandRowsCooperatively(input[2], budget, cols, rows, "grid", control);
|
|
2011
|
+
input[2] = null;
|
|
2012
|
+
const history = await expandRowsCooperatively(
|
|
2013
|
+
input[3],
|
|
2014
|
+
budget,
|
|
2015
|
+
cols,
|
|
2016
|
+
COMPACT_MAX_ROWS,
|
|
2017
|
+
"history",
|
|
2018
|
+
control,
|
|
2019
|
+
);
|
|
2020
|
+
input[3] = null;
|
|
2021
|
+
const snapshot = Object.freeze({
|
|
2022
|
+
cols,
|
|
2023
|
+
rows,
|
|
2024
|
+
grid,
|
|
2025
|
+
history,
|
|
2026
|
+
cursor: expandCursor(input[4], cols, rows),
|
|
2027
|
+
modes: expandModes(input[5]),
|
|
2028
|
+
placements: await expandPlacementsCooperatively(input[6], budget, control),
|
|
2029
|
+
bootstrap: expandBootstrap(input[7]),
|
|
2030
|
+
});
|
|
2031
|
+
if (
|
|
2032
|
+
snapshot.placements.some(
|
|
2033
|
+
(placement) =>
|
|
2034
|
+
placement.row + placement.rows > rows || placement.column + placement.columns > cols,
|
|
2035
|
+
)
|
|
2036
|
+
)
|
|
2037
|
+
throw new TypeError("Compact placement is outside the viewport");
|
|
2038
|
+
return snapshot as unknown as TerminalReplicaSnapshot;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
async function expandPatchCooperatively(
|
|
2042
|
+
value: unknown,
|
|
2043
|
+
budget: CompactDecodeBudget,
|
|
2044
|
+
control: CompactCooperativeControl,
|
|
2045
|
+
): Promise<TerminalReplicaPatchPayload> {
|
|
2046
|
+
const input = compactArray(value, 8, "patch");
|
|
2047
|
+
const dimensions =
|
|
2048
|
+
input[0] === null
|
|
2049
|
+
? undefined
|
|
2050
|
+
: (() => {
|
|
2051
|
+
const pair = compactArray(input[0], 2, "dimensions");
|
|
2052
|
+
return Object.freeze({
|
|
2053
|
+
cols: compactInteger(pair[0], 1, COMPACT_MAX_DIMENSION, "columns"),
|
|
2054
|
+
rows: compactInteger(pair[1], 1, COMPACT_MAX_DIMENSION, "rows"),
|
|
2055
|
+
});
|
|
2056
|
+
})();
|
|
2057
|
+
const rowInputs = compactArrayAtMost(input[1], COMPACT_MAX_DIMENSION, "dirty rows");
|
|
2058
|
+
const rows = [];
|
|
2059
|
+
for (let index = 0; index < rowInputs.length; index += 1) {
|
|
2060
|
+
const entry = rowInputs[index];
|
|
2061
|
+
const pair = compactArray(entry, 2, "dirty row");
|
|
2062
|
+
const row = await expandRowCooperatively(pair[1], budget, dimensions?.cols ?? null, control);
|
|
2063
|
+
rows.push(
|
|
2064
|
+
Object.freeze({
|
|
2065
|
+
index: compactInteger(pair[0], 0, COMPACT_MAX_DIMENSION - 1, "row index"),
|
|
2066
|
+
row,
|
|
2067
|
+
}),
|
|
2068
|
+
);
|
|
2069
|
+
rowInputs[index] = null;
|
|
2070
|
+
control.rowsSinceYield += 1;
|
|
2071
|
+
if (control.rowsSinceYield >= control.rowsPerSlice) {
|
|
2072
|
+
control.rowsSinceYield = 0;
|
|
2073
|
+
await control.yieldControl();
|
|
2074
|
+
}
|
|
2075
|
+
}
|
|
2076
|
+
const history =
|
|
2077
|
+
input[2] === null
|
|
2078
|
+
? undefined
|
|
2079
|
+
: await expandRowsCooperatively(input[2], budget, null, COMPACT_MAX_ROWS, "history", control);
|
|
2080
|
+
const historyDelta =
|
|
2081
|
+
input[3] === null
|
|
2082
|
+
? undefined
|
|
2083
|
+
: await (async () => {
|
|
2084
|
+
const pair = compactArray(input[3], 2, "history delta");
|
|
2085
|
+
return Object.freeze({
|
|
2086
|
+
trim: compactInteger(pair[0], 0, COMPACT_MAX_ROWS, "history trim"),
|
|
2087
|
+
append: await expandRowsCooperatively(
|
|
2088
|
+
pair[1],
|
|
2089
|
+
budget,
|
|
2090
|
+
null,
|
|
2091
|
+
COMPACT_MAX_ROWS,
|
|
2092
|
+
"history append",
|
|
2093
|
+
control,
|
|
2094
|
+
),
|
|
2095
|
+
});
|
|
2096
|
+
})();
|
|
2097
|
+
if (history && historyDelta) throw new TypeError("Compact patch has two history representations");
|
|
2098
|
+
return Object.freeze({
|
|
2099
|
+
...(dimensions ? { dimensions } : {}),
|
|
2100
|
+
rows: Object.freeze(rows),
|
|
2101
|
+
...(history ? { history } : {}),
|
|
2102
|
+
...(historyDelta ? { historyDelta } : {}),
|
|
2103
|
+
...(input[4] === null
|
|
2104
|
+
? {}
|
|
2105
|
+
: { cursor: expandCursor(input[4], dimensions?.cols ?? null, dimensions?.rows ?? null) }),
|
|
2106
|
+
...(input[5] === null ? {} : { modes: expandModes(input[5]) }),
|
|
2107
|
+
...(input[6] === null
|
|
2108
|
+
? {}
|
|
2109
|
+
: { placements: await expandPlacementsCooperatively(input[6], budget, control) }),
|
|
2110
|
+
...(input[7] === null ? {} : { bootstrap: expandBootstrap(input[7]) }),
|
|
2111
|
+
}) as unknown as TerminalReplicaPatchPayload;
|
|
2112
|
+
}
|
|
2113
|
+
|
|
2114
|
+
/**
|
|
2115
|
+
* OpenTUI fallback seam. Legacy JSON still pays its full Zod decode, deep
|
|
2116
|
+
* freeze/apply, and canonical hash verification before receiving a one-shot
|
|
2117
|
+
* reducer grant; the reducer never trusts an ordinary legacy object.
|
|
2118
|
+
*/
|
|
2119
|
+
export function decodeVerifiedLegacySemanticTerminalUpdate(
|
|
2120
|
+
bytes: Uint8Array,
|
|
2121
|
+
baseline: TerminalReplicaSnapshot | null,
|
|
2122
|
+
expectedHash: string,
|
|
2123
|
+
): Readonly<{
|
|
2124
|
+
payload: TerminalSemanticDeliveryPayload;
|
|
2125
|
+
canonicalSnapshot: TerminalReplicaSnapshot | null;
|
|
2126
|
+
}> {
|
|
2127
|
+
const payload = decodeSemanticTerminalUpdate(bytes);
|
|
2128
|
+
const snapshot =
|
|
2129
|
+
payload.frame === "seed"
|
|
2130
|
+
? freezeTerminalReplicaSnapshot(payload.snapshot)
|
|
2131
|
+
: payload.frame === "patch"
|
|
2132
|
+
? baseline
|
|
2133
|
+
? applyTerminalReplicaPatch(baseline, payload.patch)
|
|
2134
|
+
: (() => {
|
|
2135
|
+
throw new TypeError("Semantic delivery baseline gap");
|
|
2136
|
+
})()
|
|
2137
|
+
: null;
|
|
2138
|
+
const hash = snapshot
|
|
2139
|
+
? hashTerminalReplicaSnapshot(snapshot)
|
|
2140
|
+
: hashTerminalReplicaTombstone(
|
|
2141
|
+
payload.frame === "tombstone" ? payload.tombstone.reason : "protocol",
|
|
2142
|
+
);
|
|
2143
|
+
if (hash !== expectedHash) throw new TypeError("Canonical state hash mismatch");
|
|
2144
|
+
grantCompactReplicaCapability(
|
|
2145
|
+
payload.frame === "seed"
|
|
2146
|
+
? snapshot!
|
|
2147
|
+
: payload.frame === "patch"
|
|
2148
|
+
? payload.patch
|
|
2149
|
+
: payload.tombstone,
|
|
2150
|
+
baseline,
|
|
2151
|
+
snapshot,
|
|
2152
|
+
hash,
|
|
2153
|
+
);
|
|
2154
|
+
return Object.freeze({ payload, canonicalSnapshot: snapshot });
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
function recordWithKeys(value: unknown, keys: readonly string[]): value is Record<string, unknown> {
|
|
2158
|
+
return (
|
|
2159
|
+
value !== null &&
|
|
2160
|
+
typeof value === "object" &&
|
|
2161
|
+
!Array.isArray(value) &&
|
|
2162
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0")
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
export function splitTerminalDeliveryChunks(
|
|
2167
|
+
transactionId: string,
|
|
2168
|
+
bytes: Uint8Array,
|
|
2169
|
+
): TerminalDeliveryChunk[] {
|
|
2170
|
+
assertRepresentationSize(bytes);
|
|
2171
|
+
const chunks: TerminalDeliveryChunk[] = [];
|
|
2172
|
+
const count = Math.max(1, Math.ceil(bytes.byteLength / TERMINAL_DELIVERY_CHUNK_BYTES));
|
|
2173
|
+
for (let index = 0; index < count; index += 1) {
|
|
2174
|
+
chunks.push({
|
|
2175
|
+
type: "terminal.delivery.chunk",
|
|
2176
|
+
transactionId,
|
|
2177
|
+
index,
|
|
2178
|
+
bytes: bytes.slice(
|
|
2179
|
+
index * TERMINAL_DELIVERY_CHUNK_BYTES,
|
|
2180
|
+
Math.min(bytes.byteLength, (index + 1) * TERMINAL_DELIVERY_CHUNK_BYTES),
|
|
2181
|
+
),
|
|
2182
|
+
});
|
|
2183
|
+
}
|
|
2184
|
+
return chunks;
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
class TerminalDeliveryRepresentationHasher {
|
|
2188
|
+
// Two independent 32-bit lanes avoid BigInt's per-byte allocation cost while
|
|
2189
|
+
// retaining a deterministic 64-bit wire fingerprint in browser and daemon.
|
|
2190
|
+
#high = 0x811c9dc5;
|
|
2191
|
+
#low = 0x9e3779b9;
|
|
2192
|
+
|
|
2193
|
+
write(bytes: Uint8Array): void {
|
|
2194
|
+
for (const byte of bytes) {
|
|
2195
|
+
this.#high = Math.imul(this.#high ^ byte, 0x01000193) >>> 0;
|
|
2196
|
+
this.#low = Math.imul(this.#low ^ byte, 0x85ebca6b) >>> 0;
|
|
2197
|
+
}
|
|
2198
|
+
}
|
|
2199
|
+
|
|
2200
|
+
digest(): string {
|
|
2201
|
+
return this.#high.toString(16).padStart(8, "0") + this.#low.toString(16).padStart(8, "0");
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
export function hashTerminalDeliveryRepresentation(bytes: Uint8Array): string {
|
|
2206
|
+
const hasher = new TerminalDeliveryRepresentationHasher();
|
|
2207
|
+
hasher.write(bytes);
|
|
2208
|
+
return hasher.digest();
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
export function diffTerminalReplicaSnapshots(
|
|
2212
|
+
baseline: TerminalReplicaSnapshot,
|
|
2213
|
+
target: TerminalReplicaSnapshot,
|
|
2214
|
+
): TerminalReplicaPatchPayload {
|
|
2215
|
+
const dimensionsChanged = baseline.cols !== target.cols || baseline.rows !== target.rows;
|
|
2216
|
+
const rows = target.grid.flatMap((row, index) =>
|
|
2217
|
+
dimensionsChanged || !terminalReplicaRowsEqual(baseline.grid[index], row)
|
|
2218
|
+
? [{ index, row }]
|
|
2219
|
+
: [],
|
|
2220
|
+
);
|
|
2221
|
+
return {
|
|
2222
|
+
...(dimensionsChanged ? { dimensions: { cols: target.cols, rows: target.rows } } : {}),
|
|
2223
|
+
rows,
|
|
2224
|
+
...(historyEqual(baseline.history, target.history) ? {} : { history: target.history }),
|
|
2225
|
+
cursor: target.cursor,
|
|
2226
|
+
modes: target.modes,
|
|
2227
|
+
placements: target.placements,
|
|
2228
|
+
bootstrap: target.bootstrap,
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
export function encodeAnsiTerminalRepresentation(
|
|
2233
|
+
baseline: TerminalReplicaSnapshot | null,
|
|
2234
|
+
target: TerminalReplicaSnapshot,
|
|
2235
|
+
): Uint8Array {
|
|
2236
|
+
let output = "";
|
|
2237
|
+
// A seed replaces an unknown renderer, which may still be sitting in either
|
|
2238
|
+
// DEC buffer. Emit the target buffer explicitly in both directions before
|
|
2239
|
+
// clearing/repainting so reconnecting while alternate is active cannot paint
|
|
2240
|
+
// alternate cells into normal (and a normal reseed cannot remain in 1049).
|
|
2241
|
+
const alternateScreenChanged =
|
|
2242
|
+
baseline === null || baseline.modes.alternateScreen !== target.modes.alternateScreen;
|
|
2243
|
+
if (alternateScreenChanged)
|
|
2244
|
+
output += target.modes.alternateScreen ? "\u001b[?1049h" : "\u001b[?1049l";
|
|
2245
|
+
if (
|
|
2246
|
+
!baseline ||
|
|
2247
|
+
baseline.cols !== target.cols ||
|
|
2248
|
+
baseline.rows !== target.rows ||
|
|
2249
|
+
alternateScreenChanged ||
|
|
2250
|
+
!historyEqual(baseline.history, target.history)
|
|
2251
|
+
) {
|
|
2252
|
+
output += "\u001b[0m\u001b[2J\u001b[3J\u001b[H";
|
|
2253
|
+
if (target.history.length > 0) output += renderAnsiSeedRows(target);
|
|
2254
|
+
else {
|
|
2255
|
+
output += prepareAnsiTopWrappedRow(target);
|
|
2256
|
+
output += renderAnsiRowChains(
|
|
2257
|
+
target,
|
|
2258
|
+
target.grid.map((_, index) => index),
|
|
2259
|
+
false,
|
|
2260
|
+
);
|
|
2261
|
+
}
|
|
2262
|
+
} else {
|
|
2263
|
+
const changedRows = new Map<number, TerminalReplicaRow>();
|
|
2264
|
+
for (let row = 0; row < target.rows; row += 1) {
|
|
2265
|
+
if (terminalReplicaRowsEqual(baseline.grid[row], target.grid[row]!)) continue;
|
|
2266
|
+
changedRows.set(row, target.grid[row]!);
|
|
2267
|
+
}
|
|
2268
|
+
if (
|
|
2269
|
+
[...changedRows].some(([index, row]) => row.wrapped || baseline.grid[index]?.wrapped === true)
|
|
2270
|
+
)
|
|
2271
|
+
return encodeAnsiTerminalRepresentation(null, target);
|
|
2272
|
+
output += renderAnsiPatchRows(target, changedRows);
|
|
2273
|
+
if (changedRows.size === 0 && baseline.modes.wraparound !== target.modes.wraparound)
|
|
2274
|
+
output += ansiWraparoundPresentation(target);
|
|
2275
|
+
}
|
|
2276
|
+
output += ansiInputModesPresentation(target, baseline);
|
|
2277
|
+
output += ansiCursorPresentation(target);
|
|
2278
|
+
const bytes = new TextEncoder().encode(output);
|
|
2279
|
+
assertRepresentationSize(bytes);
|
|
2280
|
+
return bytes;
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
/**
|
|
2284
|
+
* Reconstruct an unknown emulator from canonical scrollback plus viewport.
|
|
2285
|
+
* Writing the rows in wire order lets xterm itself create scrollback and soft
|
|
2286
|
+
* wraps; repainting only addressable viewport rows would silently discard the
|
|
2287
|
+
* selection/search identity carried by `snapshot.history`.
|
|
2288
|
+
*/
|
|
2289
|
+
function renderAnsiSeedRows(target: TerminalReplicaSnapshot): string {
|
|
2290
|
+
const rows = [...target.history, ...target.grid];
|
|
2291
|
+
let output = "\u001b[?7h";
|
|
2292
|
+
rows.forEach((row, index) => {
|
|
2293
|
+
if (index > 0 && !row.wrapped) output += "\r\n";
|
|
2294
|
+
output += renderAnsiRow(row);
|
|
2295
|
+
});
|
|
2296
|
+
output += ansiWraparoundPresentation(target);
|
|
2297
|
+
return output;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
/**
|
|
2301
|
+
* Encode an admitted semantic patch from its explicit dirty rows.
|
|
2302
|
+
*
|
|
2303
|
+
* The patch is the canonical change set; comparing every immutable grid row
|
|
2304
|
+
* again in the renderer turns a one-line terminal update into O(screen rows)
|
|
2305
|
+
* work. Dimension changes remain a full repaint, while ordinary deltas touch
|
|
2306
|
+
* only `patch.rows` plus the cursor.
|
|
2307
|
+
*/
|
|
2308
|
+
export function encodeAnsiTerminalPatchRepresentation(
|
|
2309
|
+
patch: TerminalReplicaPatchPayload,
|
|
2310
|
+
target: TerminalReplicaSnapshot,
|
|
2311
|
+
baseline: TerminalReplicaSnapshot,
|
|
2312
|
+
): Uint8Array {
|
|
2313
|
+
if (patch.dimensions || baseline.modes.alternateScreen !== target.modes.alternateScreen)
|
|
2314
|
+
return encodeAnsiTerminalRepresentation(baseline, target);
|
|
2315
|
+
const patchedRows = new Map(patch.rows.map(({ index, row }) => [index, row] as const));
|
|
2316
|
+
// xterm's `isWrapped` is line topology, not cell content. Clearing/repainting
|
|
2317
|
+
// a line is not a portable way to change that bit after an unrelated prior
|
|
2318
|
+
// frame (notably workload -> baseline -> rich). Whenever a dirty row touches
|
|
2319
|
+
// either side of a soft-wrap transition, rebuild the exact buffer so stale
|
|
2320
|
+
// topology cannot survive or be manufactured by a partial repaint.
|
|
2321
|
+
if (
|
|
2322
|
+
[...patchedRows].some(([index, row]) => row.wrapped || baseline.grid[index]?.wrapped === true)
|
|
2323
|
+
)
|
|
2324
|
+
return encodeAnsiTerminalRepresentation(null, target);
|
|
2325
|
+
let output = "";
|
|
2326
|
+
const historyDelta = patch.historyDelta;
|
|
2327
|
+
const appendedRows = historyDelta?.append.length ?? 0;
|
|
2328
|
+
const incrementalScroll =
|
|
2329
|
+
historyDelta &&
|
|
2330
|
+
historyDelta.trim === 0 &&
|
|
2331
|
+
appendedRows > 0 &&
|
|
2332
|
+
appendedRows <= baseline.rows &&
|
|
2333
|
+
patchedRows.size === patch.rows.length &&
|
|
2334
|
+
[...patchedRows].every(
|
|
2335
|
+
([index, row]) =>
|
|
2336
|
+
index >= 0 && index < target.rows && terminalReplicaRowsEqual(row, target.grid[index]!),
|
|
2337
|
+
) &&
|
|
2338
|
+
historyDelta.append.every((row, index) =>
|
|
2339
|
+
terminalReplicaRowsEqual(row, baseline.grid[index]!),
|
|
2340
|
+
) &&
|
|
2341
|
+
target.grid.every((row, index) => {
|
|
2342
|
+
const shiftedIndex = index + appendedRows;
|
|
2343
|
+
if (shiftedIndex < baseline.rows) {
|
|
2344
|
+
return (
|
|
2345
|
+
terminalReplicaRowsEqual(row, baseline.grid[shiftedIndex]!) || patchedRows.has(index)
|
|
2346
|
+
);
|
|
2347
|
+
}
|
|
2348
|
+
// LF creates emulator-owned blank bottom rows. Requiring an exact dirty
|
|
2349
|
+
// replacement avoids depending on an implicit blank-row representation.
|
|
2350
|
+
return patchedRows.has(index);
|
|
2351
|
+
});
|
|
2352
|
+
if (incrementalScroll) {
|
|
2353
|
+
// A line-feed at the viewport bottom asks xterm to perform the same scroll
|
|
2354
|
+
// that moved these canonical rows into history. This preserves existing
|
|
2355
|
+
// selection/viewport state and lets xterm enforce its own scrollback cap;
|
|
2356
|
+
// replaying all 5k history rows on every append would be destructive and
|
|
2357
|
+
// quadratic over a sustained terminal stream.
|
|
2358
|
+
output += `\u001b[${target.rows};1H`;
|
|
2359
|
+
output += "\n".repeat(appendedRows);
|
|
2360
|
+
} else if (
|
|
2361
|
+
(patch.history !== undefined || patch.historyDelta !== undefined) &&
|
|
2362
|
+
!historyEqual(baseline.history, target.history)
|
|
2363
|
+
) {
|
|
2364
|
+
// Full history replacement has no incremental authority. It is rare and
|
|
2365
|
+
// must remain exact rather than synthesizing an unsafe delta.
|
|
2366
|
+
return encodeAnsiTerminalRepresentation(null, target);
|
|
2367
|
+
}
|
|
2368
|
+
output += renderAnsiPatchRows(target, patchedRows);
|
|
2369
|
+
if (patchedRows.size === 0 && baseline.modes.wraparound !== target.modes.wraparound)
|
|
2370
|
+
output += ansiWraparoundPresentation(target);
|
|
2371
|
+
output += ansiInputModesPresentation(target, baseline);
|
|
2372
|
+
output += ansiCursorPresentation(target);
|
|
2373
|
+
const bytes = new TextEncoder().encode(output);
|
|
2374
|
+
assertRepresentationSize(bytes);
|
|
2375
|
+
return bytes;
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
function renderAnsiPatchRows(
|
|
2379
|
+
target: TerminalReplicaSnapshot,
|
|
2380
|
+
patchedRows: ReadonlyMap<number, TerminalReplicaRow>,
|
|
2381
|
+
): string {
|
|
2382
|
+
const affectedRows = new Set(patchedRows.keys());
|
|
2383
|
+
for (const index of patchedRows.keys()) {
|
|
2384
|
+
let dependency = index;
|
|
2385
|
+
while (dependency > 0 && (patchedRows.get(dependency) ?? target.grid[dependency])?.wrapped) {
|
|
2386
|
+
dependency -= 1;
|
|
2387
|
+
affectedRows.add(dependency);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
return renderAnsiRowChains(
|
|
2391
|
+
target,
|
|
2392
|
+
[...affectedRows].sort((left, right) => left - right),
|
|
2393
|
+
true,
|
|
2394
|
+
patchedRows,
|
|
2395
|
+
);
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
function ansiCursorPresentation(target: TerminalReplicaSnapshot): string {
|
|
2399
|
+
const cursorShape =
|
|
2400
|
+
target.cursor.style === "underline"
|
|
2401
|
+
? target.cursor.blink
|
|
2402
|
+
? 3
|
|
2403
|
+
: 4
|
|
2404
|
+
: target.cursor.style === "bar"
|
|
2405
|
+
? target.cursor.blink
|
|
2406
|
+
? 5
|
|
2407
|
+
: 6
|
|
2408
|
+
: target.cursor.blink
|
|
2409
|
+
? 1
|
|
2410
|
+
: 2;
|
|
2411
|
+
return (
|
|
2412
|
+
`\u001b[${target.cursor.y + 1};${target.cursor.x + 1}H` +
|
|
2413
|
+
`\u001b[${cursorShape} q` +
|
|
2414
|
+
(target.cursor.hidden ? "\u001b[?25l" : "\u001b[?25h")
|
|
2415
|
+
);
|
|
2416
|
+
}
|
|
2417
|
+
|
|
2418
|
+
function ansiWraparoundPresentation(target: TerminalReplicaSnapshot): string {
|
|
2419
|
+
return target.modes.wraparound ? "\u001b[?7h" : "\u001b[?7l";
|
|
2420
|
+
}
|
|
2421
|
+
|
|
2422
|
+
/**
|
|
2423
|
+
* Restore the emulator modes that affect subsequent input and parsing. These
|
|
2424
|
+
* are deliberately emitted after painting/cursor placement: origin, insert,
|
|
2425
|
+
* and synchronized-output modes must describe the resulting terminal without
|
|
2426
|
+
* changing how the reconstruction itself is interpreted.
|
|
2427
|
+
*/
|
|
2428
|
+
function ansiInputModesPresentation(
|
|
2429
|
+
target: TerminalReplicaSnapshot,
|
|
2430
|
+
baseline: TerminalReplicaSnapshot | null,
|
|
2431
|
+
): string {
|
|
2432
|
+
const prior = baseline?.modes;
|
|
2433
|
+
const modes = target.modes;
|
|
2434
|
+
let output = "";
|
|
2435
|
+
const decMode = (code: number, enabled: boolean): string =>
|
|
2436
|
+
`\u001b[?${code}${enabled ? "h" : "l"}`;
|
|
2437
|
+
const ansiMode = (code: number, enabled: boolean): string =>
|
|
2438
|
+
`\u001b[${code}${enabled ? "h" : "l"}`;
|
|
2439
|
+
if (!prior || prior.applicationCursor !== modes.applicationCursor)
|
|
2440
|
+
output += decMode(1, modes.applicationCursor);
|
|
2441
|
+
if (!prior || prior.applicationKeypad !== modes.applicationKeypad)
|
|
2442
|
+
output += modes.applicationKeypad ? "\u001b=" : "\u001b>";
|
|
2443
|
+
if (!prior || prior.bracketedPaste !== modes.bracketedPaste)
|
|
2444
|
+
output += decMode(2004, modes.bracketedPaste);
|
|
2445
|
+
if (!prior || prior.insert !== modes.insert) output += ansiMode(4, modes.insert);
|
|
2446
|
+
if (!prior || prior.origin !== modes.origin) output += decMode(6, modes.origin);
|
|
2447
|
+
const mouseChanged =
|
|
2448
|
+
!prior ||
|
|
2449
|
+
prior.mouseTracking !== modes.mouseTracking ||
|
|
2450
|
+
prior.mouseProtocol !== modes.mouseProtocol ||
|
|
2451
|
+
prior.mouseEncoding !== modes.mouseEncoding;
|
|
2452
|
+
if (mouseChanged) {
|
|
2453
|
+
output += decMode(9, false);
|
|
2454
|
+
output += decMode(1000, false);
|
|
2455
|
+
output += decMode(1002, false);
|
|
2456
|
+
output += decMode(1003, false);
|
|
2457
|
+
output += decMode(1005, false);
|
|
2458
|
+
output += decMode(1006, false);
|
|
2459
|
+
output += decMode(1016, false);
|
|
2460
|
+
if (modes.mouseTracking) {
|
|
2461
|
+
const protocol = modes.mouseProtocol ?? "vt200";
|
|
2462
|
+
if (protocol === "x10") output += decMode(9, true);
|
|
2463
|
+
else if (protocol === "drag") output += decMode(1002, true);
|
|
2464
|
+
else if (protocol === "any") output += decMode(1003, true);
|
|
2465
|
+
else if (protocol !== "none") output += decMode(1000, true);
|
|
2466
|
+
}
|
|
2467
|
+
if (modes.mouseEncoding === "utf8") output += decMode(1005, true);
|
|
2468
|
+
else if (modes.mouseEncoding === "sgr") output += decMode(1006, true);
|
|
2469
|
+
else if (modes.mouseEncoding === "sgr-pixels") output += decMode(1016, true);
|
|
2470
|
+
}
|
|
2471
|
+
if (!prior || prior.synchronizedOutput !== modes.synchronizedOutput)
|
|
2472
|
+
output += decMode(2026, modes.synchronizedOutput);
|
|
2473
|
+
return output;
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
export interface TerminalDeliveryClientState {
|
|
2477
|
+
readonly negotiated: TerminalDeliveryNegotiated;
|
|
2478
|
+
readonly workspaceName: string;
|
|
2479
|
+
readonly semanticPaneId: string;
|
|
2480
|
+
readonly incarnation: string | null;
|
|
2481
|
+
readonly appliedRevision: number;
|
|
2482
|
+
readonly appliedHash: string | null;
|
|
2483
|
+
readonly canonicalSnapshot: TerminalReplicaSnapshot | null;
|
|
2484
|
+
readonly inFlight: TerminalDeliveryEnvelope | null;
|
|
2485
|
+
readonly nextChunk: number;
|
|
2486
|
+
readonly receivedBytes: number;
|
|
2487
|
+
readonly reseedRequired: boolean;
|
|
2488
|
+
readonly failed: boolean;
|
|
2489
|
+
readonly tombstoned: boolean;
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
export function createTerminalDeliveryClientState(
|
|
2493
|
+
negotiated: TerminalDeliveryNegotiated,
|
|
2494
|
+
workspaceName: string,
|
|
2495
|
+
semanticPaneId: string,
|
|
2496
|
+
): TerminalDeliveryClientState {
|
|
2497
|
+
return Object.freeze({
|
|
2498
|
+
negotiated: Object.freeze(TerminalDeliveryNegotiatedSchemaZ.parse(negotiated)),
|
|
2499
|
+
workspaceName,
|
|
2500
|
+
semanticPaneId,
|
|
2501
|
+
incarnation: null,
|
|
2502
|
+
appliedRevision: -1,
|
|
2503
|
+
appliedHash: null,
|
|
2504
|
+
canonicalSnapshot: null,
|
|
2505
|
+
inFlight: null,
|
|
2506
|
+
nextChunk: 0,
|
|
2507
|
+
receivedBytes: 0,
|
|
2508
|
+
reseedRequired: false,
|
|
2509
|
+
failed: false,
|
|
2510
|
+
tombstoned: false,
|
|
2511
|
+
});
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
export function admitTerminalDeliveryEnvelope(
|
|
2515
|
+
state: TerminalDeliveryClientState,
|
|
2516
|
+
envelope: TerminalDeliveryEnvelope,
|
|
2517
|
+
): TerminalDeliveryClientState {
|
|
2518
|
+
envelope = Object.freeze(TerminalDeliveryEnvelopeSchemaZ.parse(envelope));
|
|
2519
|
+
if (
|
|
2520
|
+
state.failed ||
|
|
2521
|
+
state.inFlight ||
|
|
2522
|
+
!terminalDeliveryEncodingAccepted(state.negotiated, envelope.encoding) ||
|
|
2523
|
+
envelope.generation !== state.negotiated.generation ||
|
|
2524
|
+
envelope.deliveryNonce !== state.negotiated.deliveryNonce ||
|
|
2525
|
+
envelope.protocolVersion !== state.negotiated.protocolVersion ||
|
|
2526
|
+
envelope.richPlacements !== state.negotiated.richPlacements ||
|
|
2527
|
+
state.workspaceName !== envelope.workspaceName ||
|
|
2528
|
+
state.semanticPaneId !== envelope.semanticPaneId
|
|
2529
|
+
)
|
|
2530
|
+
return failClient(state);
|
|
2531
|
+
if (envelope.frame === "seed") {
|
|
2532
|
+
if (state.tombstoned && state.incarnation === envelope.incarnation) return failClient(state);
|
|
2533
|
+
if (
|
|
2534
|
+
state.incarnation === envelope.incarnation &&
|
|
2535
|
+
state.appliedRevision >= 0 &&
|
|
2536
|
+
envelope.canonicalRevision <= state.appliedRevision
|
|
2537
|
+
)
|
|
2538
|
+
return failClient(state);
|
|
2539
|
+
if (
|
|
2540
|
+
state.incarnation !== null &&
|
|
2541
|
+
state.incarnation !== envelope.incarnation &&
|
|
2542
|
+
(!isNewerIncarnation(state.incarnation, envelope.incarnation) ||
|
|
2543
|
+
envelope.canonicalRevision <= state.appliedRevision)
|
|
2544
|
+
)
|
|
2545
|
+
return failClient(state);
|
|
2546
|
+
} else if (
|
|
2547
|
+
state.incarnation !== envelope.incarnation ||
|
|
2548
|
+
envelope.baseRevision !== state.appliedRevision ||
|
|
2549
|
+
state.reseedRequired
|
|
2550
|
+
) {
|
|
2551
|
+
return failClient(state);
|
|
2552
|
+
}
|
|
2553
|
+
if (envelope.frame !== "seed" && state.appliedRevision < 0) return failClient(state);
|
|
2554
|
+
return Object.freeze({ ...state, inFlight: envelope, nextChunk: 0, receivedBytes: 0 });
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
export function terminalDeliveryEncodingAccepted(
|
|
2558
|
+
negotiated: TerminalDeliveryNegotiated,
|
|
2559
|
+
encoding: TerminalDeliveryEnvelope["encoding"],
|
|
2560
|
+
): boolean {
|
|
2561
|
+
return (
|
|
2562
|
+
encoding === negotiated.encoding ||
|
|
2563
|
+
(negotiated.encoding === "semantic-compact-v1" &&
|
|
2564
|
+
negotiated.fallbackEncoding === "semantic-v1" &&
|
|
2565
|
+
encoding === "semantic-v1")
|
|
2566
|
+
);
|
|
2567
|
+
}
|
|
2568
|
+
|
|
2569
|
+
export function admitTerminalDeliveryChunk(
|
|
2570
|
+
state: TerminalDeliveryClientState,
|
|
2571
|
+
chunk: TerminalDeliveryChunk,
|
|
2572
|
+
): TerminalDeliveryClientState {
|
|
2573
|
+
chunk = TerminalDeliveryChunkSchemaZ.parse(chunk);
|
|
2574
|
+
const envelope = state.inFlight;
|
|
2575
|
+
const expectedBytes = envelope
|
|
2576
|
+
? Math.min(
|
|
2577
|
+
TERMINAL_DELIVERY_CHUNK_BYTES,
|
|
2578
|
+
Math.max(0, envelope.representationBytes - chunk.index * TERMINAL_DELIVERY_CHUNK_BYTES),
|
|
2579
|
+
)
|
|
2580
|
+
: -1;
|
|
2581
|
+
if (
|
|
2582
|
+
state.failed ||
|
|
2583
|
+
!state.inFlight ||
|
|
2584
|
+
chunk.transactionId !== state.inFlight.transactionId ||
|
|
2585
|
+
chunk.index !== state.nextChunk ||
|
|
2586
|
+
chunk.index >= state.inFlight.chunkCount ||
|
|
2587
|
+
chunk.bytes.byteLength !== expectedBytes ||
|
|
2588
|
+
state.receivedBytes + chunk.bytes.byteLength > state.inFlight.representationBytes
|
|
2589
|
+
)
|
|
2590
|
+
return failClient(state);
|
|
2591
|
+
return Object.freeze({
|
|
2592
|
+
...state,
|
|
2593
|
+
nextChunk: state.nextChunk + 1,
|
|
2594
|
+
receivedBytes: state.receivedBytes + chunk.bytes.byteLength,
|
|
2595
|
+
});
|
|
2596
|
+
}
|
|
2597
|
+
|
|
2598
|
+
export class TerminalDeliveryAssembler {
|
|
2599
|
+
readonly #storage: Uint8Array;
|
|
2600
|
+
readonly #buffer: Uint8Array;
|
|
2601
|
+
readonly #representationHasher = new TerminalDeliveryRepresentationHasher();
|
|
2602
|
+
readonly envelope: TerminalDeliveryEnvelope;
|
|
2603
|
+
#nextChunk = 0;
|
|
2604
|
+
#offset = 0;
|
|
2605
|
+
constructor(envelope: TerminalDeliveryEnvelope, reusableStorage?: Uint8Array) {
|
|
2606
|
+
this.envelope = Object.freeze(TerminalDeliveryEnvelopeSchemaZ.parse(envelope));
|
|
2607
|
+
this.#storage =
|
|
2608
|
+
reusableStorage && reusableStorage.byteLength >= this.envelope.representationBytes
|
|
2609
|
+
? reusableStorage
|
|
2610
|
+
: new Uint8Array(this.envelope.representationBytes);
|
|
2611
|
+
this.#buffer = this.#storage.subarray(0, this.envelope.representationBytes);
|
|
2612
|
+
}
|
|
2613
|
+
write(chunk: TerminalDeliveryChunk): void {
|
|
2614
|
+
chunk = TerminalDeliveryChunkSchemaZ.parse(chunk);
|
|
2615
|
+
const expected = Math.min(
|
|
2616
|
+
TERMINAL_DELIVERY_CHUNK_BYTES,
|
|
2617
|
+
this.envelope.representationBytes - this.#offset,
|
|
2618
|
+
);
|
|
2619
|
+
if (
|
|
2620
|
+
chunk.transactionId !== this.envelope.transactionId ||
|
|
2621
|
+
chunk.index !== this.#nextChunk ||
|
|
2622
|
+
chunk.bytes.byteLength !== expected
|
|
2623
|
+
)
|
|
2624
|
+
throw new TypeError("Invalid terminal delivery chunk");
|
|
2625
|
+
this.#buffer.set(chunk.bytes, this.#offset);
|
|
2626
|
+
this.#representationHasher.write(chunk.bytes);
|
|
2627
|
+
this.#offset += chunk.bytes.byteLength;
|
|
2628
|
+
this.#nextChunk += 1;
|
|
2629
|
+
}
|
|
2630
|
+
complete(): Uint8Array {
|
|
2631
|
+
if (
|
|
2632
|
+
this.#offset !== this.envelope.representationBytes ||
|
|
2633
|
+
this.#nextChunk !== this.envelope.chunkCount
|
|
2634
|
+
)
|
|
2635
|
+
throw new TypeError("Terminal delivery transaction is incomplete");
|
|
2636
|
+
if (this.#representationHasher.digest() !== this.envelope.representationHash)
|
|
2637
|
+
throw new TypeError("Terminal delivery representation hash mismatch");
|
|
2638
|
+
return this.#buffer;
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
releaseStorage(): Uint8Array {
|
|
2642
|
+
if (
|
|
2643
|
+
this.#offset !== this.envelope.representationBytes ||
|
|
2644
|
+
this.#nextChunk !== this.envelope.chunkCount
|
|
2645
|
+
)
|
|
2646
|
+
throw new TypeError("Terminal delivery transaction is incomplete");
|
|
2647
|
+
return this.#storage;
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2651
|
+
export interface StagedTerminalDelivery {
|
|
2652
|
+
readonly envelope: TerminalDeliveryEnvelope;
|
|
2653
|
+
readonly bytes: Uint8Array;
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
export function completeTerminalDelivery(
|
|
2657
|
+
state: TerminalDeliveryClientState,
|
|
2658
|
+
assembler: TerminalDeliveryAssembler,
|
|
2659
|
+
): StagedTerminalDelivery {
|
|
2660
|
+
const envelope = state.inFlight;
|
|
2661
|
+
if (
|
|
2662
|
+
!envelope ||
|
|
2663
|
+
state.failed ||
|
|
2664
|
+
!sameEnvelope(assembler.envelope, envelope) ||
|
|
2665
|
+
state.nextChunk !== envelope.chunkCount ||
|
|
2666
|
+
state.receivedBytes !== envelope.representationBytes
|
|
2667
|
+
)
|
|
2668
|
+
throw new TypeError("Terminal delivery transaction is incomplete");
|
|
2669
|
+
return { envelope, bytes: assembler.complete() };
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
export function commitTerminalDelivery(
|
|
2673
|
+
state: TerminalDeliveryClientState,
|
|
2674
|
+
staged: StagedTerminalDelivery,
|
|
2675
|
+
options: { readonly presentationApplied?: boolean } = {},
|
|
2676
|
+
): {
|
|
2677
|
+
readonly state: TerminalDeliveryClientState;
|
|
2678
|
+
readonly ack: TerminalDeliveryAck;
|
|
2679
|
+
/** The one authenticated semantic decode used to produce `state`. */
|
|
2680
|
+
readonly semanticUpdate: TerminalSemanticDeliveryPayload | null;
|
|
2681
|
+
} {
|
|
2682
|
+
const envelope = state.inFlight;
|
|
2683
|
+
if (!envelope || !sameEnvelope(envelope, staged.envelope))
|
|
2684
|
+
throw new TypeError("Delivery was not staged from this state");
|
|
2685
|
+
if (hashTerminalDeliveryRepresentation(staged.bytes) !== envelope.representationHash)
|
|
2686
|
+
throw new TypeError("Terminal delivery representation hash mismatch");
|
|
2687
|
+
let canonicalSnapshot = state.canonicalSnapshot;
|
|
2688
|
+
let semanticUpdate: TerminalSemanticDeliveryPayload | null = null;
|
|
2689
|
+
if (envelope.encoding === "semantic-v1" || envelope.encoding === "semantic-compact-v1") {
|
|
2690
|
+
const payload =
|
|
2691
|
+
envelope.encoding === "semantic-compact-v1"
|
|
2692
|
+
? decodeVerifiedCompactSemanticTerminalUpdate(
|
|
2693
|
+
staged.bytes,
|
|
2694
|
+
canonicalSnapshot,
|
|
2695
|
+
envelope.canonicalStateHash,
|
|
2696
|
+
).payload
|
|
2697
|
+
: decodeSemanticTerminalUpdate(staged.bytes);
|
|
2698
|
+
semanticUpdate = payload;
|
|
2699
|
+
if (payload.frame !== envelope.frame || payload.revision !== envelope.canonicalRevision)
|
|
2700
|
+
throw new TypeError("Semantic frame or revision mismatch");
|
|
2701
|
+
if (
|
|
2702
|
+
payload.frame !== "seed" &&
|
|
2703
|
+
(payload.baseRevision !== envelope.baseRevision ||
|
|
2704
|
+
payload.baseRevision !== state.appliedRevision)
|
|
2705
|
+
)
|
|
2706
|
+
throw new TypeError("Semantic delivery baseline gap");
|
|
2707
|
+
const compactCapability = compactCommitCapabilities.get(payload);
|
|
2708
|
+
if (envelope.encoding === "semantic-compact-v1") {
|
|
2709
|
+
if (!compactCapability || compactCapability.hash !== envelope.canonicalStateHash)
|
|
2710
|
+
throw new TypeError("Compact semantic capability was unavailable");
|
|
2711
|
+
canonicalSnapshot = compactCapability.snapshot;
|
|
2712
|
+
compactCommitCapabilities.delete(payload);
|
|
2713
|
+
} else {
|
|
2714
|
+
if (payload.frame === "seed")
|
|
2715
|
+
canonicalSnapshot = freezeTerminalReplicaSnapshot(payload.snapshot);
|
|
2716
|
+
else if (payload.frame === "patch") {
|
|
2717
|
+
if (!canonicalSnapshot) throw new TypeError("Semantic delivery baseline gap");
|
|
2718
|
+
canonicalSnapshot = applyTerminalReplicaPatch(canonicalSnapshot, payload.patch);
|
|
2719
|
+
} else canonicalSnapshot = null;
|
|
2720
|
+
const hash = canonicalSnapshot
|
|
2721
|
+
? hashTerminalReplicaSnapshot(canonicalSnapshot)
|
|
2722
|
+
: hashTerminalReplicaTombstone(
|
|
2723
|
+
payload.frame === "tombstone" ? payload.tombstone.reason : "protocol",
|
|
2724
|
+
);
|
|
2725
|
+
if (hash !== envelope.canonicalStateHash)
|
|
2726
|
+
throw new TypeError("Canonical state hash mismatch");
|
|
2727
|
+
}
|
|
2728
|
+
} else if (!options.presentationApplied) {
|
|
2729
|
+
throw new TypeError("ANSI presentation must be applied before ACK");
|
|
2730
|
+
}
|
|
2731
|
+
const next = Object.freeze({
|
|
2732
|
+
...state,
|
|
2733
|
+
workspaceName: envelope.workspaceName,
|
|
2734
|
+
semanticPaneId: envelope.semanticPaneId,
|
|
2735
|
+
incarnation: envelope.incarnation,
|
|
2736
|
+
appliedRevision: envelope.canonicalRevision,
|
|
2737
|
+
appliedHash: envelope.canonicalStateHash,
|
|
2738
|
+
canonicalSnapshot,
|
|
2739
|
+
tombstoned: envelope.frame === "tombstone",
|
|
2740
|
+
inFlight: null,
|
|
2741
|
+
nextChunk: 0,
|
|
2742
|
+
receivedBytes: 0,
|
|
2743
|
+
reseedRequired: false,
|
|
2744
|
+
});
|
|
2745
|
+
return {
|
|
2746
|
+
state: next,
|
|
2747
|
+
semanticUpdate,
|
|
2748
|
+
ack: {
|
|
2749
|
+
type: "terminal.delivery.ack",
|
|
2750
|
+
workspaceName: envelope.workspaceName,
|
|
2751
|
+
semanticPaneId: envelope.semanticPaneId,
|
|
2752
|
+
generation: envelope.generation,
|
|
2753
|
+
incarnation: envelope.incarnation,
|
|
2754
|
+
deliveryNonce: envelope.deliveryNonce,
|
|
2755
|
+
transactionId: envelope.transactionId,
|
|
2756
|
+
canonicalRevision: envelope.canonicalRevision,
|
|
2757
|
+
canonicalStateHash: envelope.canonicalStateHash,
|
|
2758
|
+
representationHash: envelope.representationHash,
|
|
2759
|
+
},
|
|
2760
|
+
};
|
|
2761
|
+
}
|
|
2762
|
+
|
|
2763
|
+
export function nackTerminalDelivery(
|
|
2764
|
+
state: TerminalDeliveryClientState,
|
|
2765
|
+
nack: TerminalDeliveryNack,
|
|
2766
|
+
): TerminalDeliveryClientState {
|
|
2767
|
+
nack = TerminalDeliveryNackSchemaZ.parse(nack);
|
|
2768
|
+
if (
|
|
2769
|
+
nack.generation !== state.negotiated.generation ||
|
|
2770
|
+
nack.deliveryNonce !== state.negotiated.deliveryNonce ||
|
|
2771
|
+
nack.workspaceName !== state.workspaceName ||
|
|
2772
|
+
nack.semanticPaneId !== state.semanticPaneId
|
|
2773
|
+
)
|
|
2774
|
+
return failClient(state);
|
|
2775
|
+
if (state.inFlight && nack.transactionId !== state.inFlight.transactionId)
|
|
2776
|
+
return failClient(state);
|
|
2777
|
+
return Object.freeze({
|
|
2778
|
+
...state,
|
|
2779
|
+
inFlight: null,
|
|
2780
|
+
nextChunk: 0,
|
|
2781
|
+
receivedBytes: 0,
|
|
2782
|
+
reseedRequired: true,
|
|
2783
|
+
failed: false,
|
|
2784
|
+
});
|
|
2785
|
+
}
|
|
2786
|
+
|
|
2787
|
+
function failClient(state: TerminalDeliveryClientState): TerminalDeliveryClientState {
|
|
2788
|
+
return Object.freeze({ ...state, failed: true, inFlight: null, receivedBytes: 0 });
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
function sameEnvelope(left: TerminalDeliveryEnvelope, right: TerminalDeliveryEnvelope): boolean {
|
|
2792
|
+
return JSON.stringify(left) === JSON.stringify(right);
|
|
2793
|
+
}
|
|
2794
|
+
|
|
2795
|
+
function historyEqual(
|
|
2796
|
+
left: readonly TerminalReplicaRow[],
|
|
2797
|
+
right: readonly TerminalReplicaRow[],
|
|
2798
|
+
): boolean {
|
|
2799
|
+
return (
|
|
2800
|
+
left === right ||
|
|
2801
|
+
(left.length === right.length &&
|
|
2802
|
+
left.every((row, index) => terminalReplicaRowsEqual(row, right[index]!)))
|
|
2803
|
+
);
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
function renderAnsiRow(row: TerminalReplicaRow): string {
|
|
2807
|
+
let output = "\u001b[0m";
|
|
2808
|
+
for (const cell of row.cells) {
|
|
2809
|
+
if (cell.width === 0) continue;
|
|
2810
|
+
output += ansiCellStyle(cell);
|
|
2811
|
+
output += cell.grapheme;
|
|
2812
|
+
}
|
|
2813
|
+
return `${output}\u001b[0m`;
|
|
2814
|
+
}
|
|
2815
|
+
|
|
2816
|
+
/**
|
|
2817
|
+
* Repaint rows while preserving the emulator's soft-wrap topology. A wrapped
|
|
2818
|
+
* row can only be created by letting a printable cell cross the preceding
|
|
2819
|
+
* row's right margin; CUP/CRLF reconstruction loses that bit even when every
|
|
2820
|
+
* cell is otherwise exact. Patch callers therefore include the unchanged
|
|
2821
|
+
* predecessor of a dirty wrapped row and repaint the whole wrapped chain.
|
|
2822
|
+
*/
|
|
2823
|
+
function renderAnsiRowChains(
|
|
2824
|
+
target: TerminalReplicaSnapshot,
|
|
2825
|
+
indices: readonly number[],
|
|
2826
|
+
clearRows: boolean,
|
|
2827
|
+
patchedRows: ReadonlyMap<number, TerminalReplicaRow> = new Map(),
|
|
2828
|
+
): string {
|
|
2829
|
+
if (indices.length === 0) return "";
|
|
2830
|
+
const rowAt = (index: number): TerminalReplicaRow =>
|
|
2831
|
+
patchedRows.get(index) ?? target.grid[index]!;
|
|
2832
|
+
let output = "\u001b[?7h";
|
|
2833
|
+
if (clearRows) {
|
|
2834
|
+
for (const index of indices) output += `\u001b[${index + 1};1H\u001b[2K`;
|
|
2835
|
+
}
|
|
2836
|
+
let previous = -2;
|
|
2837
|
+
for (const index of indices) {
|
|
2838
|
+
const row = rowAt(index);
|
|
2839
|
+
const continuesPrevious = index === previous + 1 && row.wrapped;
|
|
2840
|
+
if (!continuesPrevious) output += `\u001b[${index + 1};1H`;
|
|
2841
|
+
output += renderAnsiRow(row);
|
|
2842
|
+
previous = index;
|
|
2843
|
+
}
|
|
2844
|
+
output += ansiWraparoundPresentation(target);
|
|
2845
|
+
return output;
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
/**
|
|
2849
|
+
* CUP cannot manufacture a wrapped first viewport row because its predecessor
|
|
2850
|
+
* lives above the addressable viewport. Build that bit once through a bounded
|
|
2851
|
+
* bottom-row wrap, move the line to the top, and discard the synthetic
|
|
2852
|
+
* scrollback before the ordinary exact repaint. Patch callers fall back to
|
|
2853
|
+
* this seed whenever row zero itself must be repainted as wrapped.
|
|
2854
|
+
*/
|
|
2855
|
+
function prepareAnsiTopWrappedRow(target: TerminalReplicaSnapshot): string {
|
|
2856
|
+
const first = target.grid[0];
|
|
2857
|
+
if (!first?.wrapped) return "";
|
|
2858
|
+
let output = `\u001b[?7h\u001b[${target.rows};1H\u001b[2K`;
|
|
2859
|
+
output += renderAnsiRow(first);
|
|
2860
|
+
output += renderAnsiRow(first);
|
|
2861
|
+
if (target.rows > 1) output += `\u001b[${target.rows - 1}S`;
|
|
2862
|
+
return `${output}\u001b[3J`;
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
function ansiCellStyle(cell: TerminalReplicaRow["cells"][number]): string {
|
|
2866
|
+
const codes: number[] = [0];
|
|
2867
|
+
if (cell.attributes & 1) codes.push(1);
|
|
2868
|
+
if (cell.attributes & 2) codes.push(2);
|
|
2869
|
+
if (cell.attributes & 4) codes.push(3);
|
|
2870
|
+
if (cell.attributes & 8) codes.push(4);
|
|
2871
|
+
if (cell.attributes & 32) codes.push(7);
|
|
2872
|
+
if (cell.attributes & 128) codes.push(9);
|
|
2873
|
+
if (cell.foreground.kind === "indexed") codes.push(38, 5, cell.foreground.index);
|
|
2874
|
+
if (cell.foreground.kind === "rgb")
|
|
2875
|
+
codes.push(
|
|
2876
|
+
38,
|
|
2877
|
+
2,
|
|
2878
|
+
(cell.foreground.value >> 16) & 255,
|
|
2879
|
+
(cell.foreground.value >> 8) & 255,
|
|
2880
|
+
cell.foreground.value & 255,
|
|
2881
|
+
);
|
|
2882
|
+
if (cell.background.kind === "indexed") codes.push(48, 5, cell.background.index);
|
|
2883
|
+
if (cell.background.kind === "rgb")
|
|
2884
|
+
codes.push(
|
|
2885
|
+
48,
|
|
2886
|
+
2,
|
|
2887
|
+
(cell.background.value >> 16) & 255,
|
|
2888
|
+
(cell.background.value >> 8) & 255,
|
|
2889
|
+
cell.background.value & 255,
|
|
2890
|
+
);
|
|
2891
|
+
return `\u001b[${codes.join(";")}m`;
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
function canonicalJson(value: unknown): string {
|
|
2895
|
+
if (value === null || typeof value !== "object") return JSON.stringify(value);
|
|
2896
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
2897
|
+
const record = value as Record<string, unknown>;
|
|
2898
|
+
return `{${Object.keys(record)
|
|
2899
|
+
.sort()
|
|
2900
|
+
.filter((key) => record[key] !== undefined)
|
|
2901
|
+
.map((key) => `${JSON.stringify(key)}:${canonicalJson(record[key])}`)
|
|
2902
|
+
.join(",")}}`;
|
|
2903
|
+
}
|
|
2904
|
+
|
|
2905
|
+
function assertRepresentationSize(bytes: Uint8Array): void {
|
|
2906
|
+
if (bytes.byteLength > TERMINAL_DELIVERY_MAX_REPRESENTATION_BYTES)
|
|
2907
|
+
throw new TerminalDeliveryStateTooLargeError(bytes.byteLength);
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
function isNewerIncarnation(current: string, candidate: string): boolean {
|
|
2911
|
+
const currentEpoch = /:([0-9]+)$/u.exec(current)?.[1];
|
|
2912
|
+
const candidateEpoch = /:([0-9]+)$/u.exec(candidate)?.[1];
|
|
2913
|
+
return (
|
|
2914
|
+
currentEpoch !== undefined &&
|
|
2915
|
+
candidateEpoch !== undefined &&
|
|
2916
|
+
Number(candidateEpoch) > Number(currentEpoch)
|
|
2917
|
+
);
|
|
2918
|
+
}
|