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,4780 @@
|
|
|
1
|
+
import { createHmac } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
const CANONICAL_STATE_HASH = /^[0-9a-f]{16}$/u;
|
|
4
|
+
const HMAC = /^[0-9a-f]{64}$/u;
|
|
5
|
+
const GENERATION = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,159}$/u;
|
|
6
|
+
const CLIENTS = new Set(["opentui", "web-a", "web-b"]);
|
|
7
|
+
const HOSTS = new Set(["opentui", "chromium", "electron"]);
|
|
8
|
+
const CLOCK_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,95}$/u;
|
|
9
|
+
|
|
10
|
+
function exactKeys(value, keys) {
|
|
11
|
+
return (
|
|
12
|
+
value !== null &&
|
|
13
|
+
typeof value === "object" &&
|
|
14
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0")
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function exactAuthorityOwners(value) {
|
|
19
|
+
return (
|
|
20
|
+
value !== null &&
|
|
21
|
+
typeof value === "object" &&
|
|
22
|
+
Object.keys(value).sort().join("\0") === "focus\0geometry\0input" &&
|
|
23
|
+
[value.input, value.focus, value.geometry].every(
|
|
24
|
+
(owner) => owner === null || (typeof owner === "string" && owner.length > 0),
|
|
25
|
+
)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function boundedInteger(value, maximum) {
|
|
30
|
+
return Number.isSafeInteger(value) && value >= 0 ? Math.min(value, maximum) : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function createCard5DiagnosticEvidenceBinding({
|
|
34
|
+
journeyEvidence,
|
|
35
|
+
journeyEvidenceKey,
|
|
36
|
+
privateEvidenceKey,
|
|
37
|
+
}) {
|
|
38
|
+
if (
|
|
39
|
+
!["crossClientHandoff", "daemonRestart"].includes(journeyEvidenceKey) ||
|
|
40
|
+
!HMAC.test(privateEvidenceKey ?? "") ||
|
|
41
|
+
journeyEvidence === null ||
|
|
42
|
+
typeof journeyEvidence !== "object" ||
|
|
43
|
+
!Object.hasOwn(journeyEvidence, journeyEvidenceKey)
|
|
44
|
+
)
|
|
45
|
+
throw new Error("Card5 diagnostic evidence binding was invalid");
|
|
46
|
+
const evidence = journeyEvidence[journeyEvidenceKey];
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
evidence,
|
|
49
|
+
correlate: (project) => project(evidence, privateEvidenceKey),
|
|
50
|
+
assess: (project) => project(evidence, privateEvidenceKey),
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const TUI_FENCE_TEXT = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,255}$/u;
|
|
55
|
+
|
|
56
|
+
function validTuiFrameFence(record) {
|
|
57
|
+
return (
|
|
58
|
+
record?.type === "performance.terminal-frame-fence" &&
|
|
59
|
+
TUI_FENCE_TEXT.test(record.generation ?? "") &&
|
|
60
|
+
TUI_FENCE_TEXT.test(record.semanticPaneId ?? "") &&
|
|
61
|
+
TUI_FENCE_TEXT.test(record.incarnation ?? "") &&
|
|
62
|
+
TUI_FENCE_TEXT.test(record.processId ?? "") &&
|
|
63
|
+
CLOCK_ID.test(record.clockId ?? "") &&
|
|
64
|
+
CANONICAL_STATE_HASH.test(record.stateHash ?? "") &&
|
|
65
|
+
Number.isSafeInteger(record.atMicros) &&
|
|
66
|
+
record.atMicros >= 0 &&
|
|
67
|
+
Number.isSafeInteger(record.revision) &&
|
|
68
|
+
record.revision >= 0 &&
|
|
69
|
+
record.acceptedRevision === record.revision &&
|
|
70
|
+
Number.isSafeInteger(record.cols) &&
|
|
71
|
+
record.cols > 0 &&
|
|
72
|
+
record.cols <= 65_535 &&
|
|
73
|
+
Number.isSafeInteger(record.rows) &&
|
|
74
|
+
record.rows > 0 &&
|
|
75
|
+
record.rows <= 65_535
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Fail-closed, per-pane projection of accepted OpenTUI host frame fences. */
|
|
80
|
+
export function createCard5TuiFrameFenceTracker() {
|
|
81
|
+
const byPane = new Map();
|
|
82
|
+
let valid = true;
|
|
83
|
+
return Object.freeze({
|
|
84
|
+
ingest(record) {
|
|
85
|
+
if (!validTuiFrameFence(record)) {
|
|
86
|
+
valid = false;
|
|
87
|
+
byPane.clear();
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
const previous = byPane.get(record.semanticPaneId);
|
|
91
|
+
if (
|
|
92
|
+
previous &&
|
|
93
|
+
previous.generation === record.generation &&
|
|
94
|
+
previous.incarnation === record.incarnation &&
|
|
95
|
+
(record.revision <= previous.revision || record.atMicros <= previous.atMicros)
|
|
96
|
+
) {
|
|
97
|
+
valid = false;
|
|
98
|
+
byPane.clear();
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
byPane.set(
|
|
102
|
+
record.semanticPaneId,
|
|
103
|
+
Object.freeze({
|
|
104
|
+
generation: record.generation,
|
|
105
|
+
revision: record.revision,
|
|
106
|
+
canonicalStateHash: record.stateHash,
|
|
107
|
+
connected: true,
|
|
108
|
+
processId: record.processId,
|
|
109
|
+
clockId: record.clockId,
|
|
110
|
+
atMicros: record.atMicros,
|
|
111
|
+
semanticPaneId: record.semanticPaneId,
|
|
112
|
+
incarnation: record.incarnation,
|
|
113
|
+
cols: record.cols,
|
|
114
|
+
rows: record.rows,
|
|
115
|
+
deliveryFence: record.acceptedRevision,
|
|
116
|
+
}),
|
|
117
|
+
);
|
|
118
|
+
return true;
|
|
119
|
+
},
|
|
120
|
+
latest(semanticPaneId) {
|
|
121
|
+
return valid && TUI_FENCE_TEXT.test(semanticPaneId ?? "")
|
|
122
|
+
? (byPane.get(semanticPaneId) ?? null)
|
|
123
|
+
: null;
|
|
124
|
+
},
|
|
125
|
+
valid: () => valid,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function card5CandidateSummary(observations) {
|
|
130
|
+
return Object.freeze({
|
|
131
|
+
clients: Object.freeze(
|
|
132
|
+
observations.map((entry) =>
|
|
133
|
+
Object.freeze({
|
|
134
|
+
client: entry.client,
|
|
135
|
+
correlationHmac: HMAC.test(entry.correlationHmac ?? "") ? entry.correlationHmac : null,
|
|
136
|
+
workspaceHmac: HMAC.test(entry.workspaceHmac ?? "") ? entry.workspaceHmac : null,
|
|
137
|
+
paneHmac: HMAC.test(entry.paneHmac ?? "") ? entry.paneHmac : null,
|
|
138
|
+
incarnationHmac: HMAC.test(entry.incarnationHmac ?? "") ? entry.incarnationHmac : null,
|
|
139
|
+
renditionHmac: HMAC.test(entry.renditionHmac ?? "") ? entry.renditionHmac : null,
|
|
140
|
+
revision: boundedInteger(entry.revision, 0xffff_ffff),
|
|
141
|
+
cols: boundedInteger(entry.cols, 65_535),
|
|
142
|
+
rows: boundedInteger(entry.rows, 65_535),
|
|
143
|
+
deliveryFence: boundedInteger(entry.deliveryFence, 0xffff_ffff),
|
|
144
|
+
}),
|
|
145
|
+
),
|
|
146
|
+
),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Bound one potentially wedged browser observation to the shared deadline. */
|
|
151
|
+
export async function observeCard5WithinDeadline(
|
|
152
|
+
observe,
|
|
153
|
+
{
|
|
154
|
+
deadline,
|
|
155
|
+
now = () => performance.now(),
|
|
156
|
+
scheduleDeadline = (callback, delayMs) => setTimeout(callback, delayMs),
|
|
157
|
+
cancelDeadline = (timer) => clearTimeout(timer),
|
|
158
|
+
},
|
|
159
|
+
) {
|
|
160
|
+
if (typeof observe !== "function" || !Number.isFinite(deadline)) {
|
|
161
|
+
throw new TypeError("Card5 observation deadline is malformed");
|
|
162
|
+
}
|
|
163
|
+
let before;
|
|
164
|
+
try {
|
|
165
|
+
before = now();
|
|
166
|
+
} catch {
|
|
167
|
+
return Object.freeze({ status: "clock-invalid", value: null });
|
|
168
|
+
}
|
|
169
|
+
if (!Number.isFinite(before)) return Object.freeze({ status: "clock-invalid", value: null });
|
|
170
|
+
const remaining = deadline - before;
|
|
171
|
+
if (remaining <= 0) return Object.freeze({ status: "deadline", value: null });
|
|
172
|
+
const controller = new AbortController();
|
|
173
|
+
const operation = Promise.resolve().then(() =>
|
|
174
|
+
observe(Object.freeze({ signal: controller.signal, deadline })),
|
|
175
|
+
);
|
|
176
|
+
const settled = operation.then(
|
|
177
|
+
(value) => ({ status: "ok", value }),
|
|
178
|
+
() => ({ status: "source-unavailable", value: null }),
|
|
179
|
+
);
|
|
180
|
+
let timer;
|
|
181
|
+
const timeout = new Promise((resolveTimeout) => {
|
|
182
|
+
timer = scheduleDeadline(() => {
|
|
183
|
+
controller.abort("card5-convergence-deadline");
|
|
184
|
+
resolveTimeout({ status: "deadline", value: null });
|
|
185
|
+
}, remaining);
|
|
186
|
+
});
|
|
187
|
+
const result = await Promise.race([settled, timeout]);
|
|
188
|
+
cancelDeadline(timer);
|
|
189
|
+
if (result.status === "deadline") void settled;
|
|
190
|
+
let after;
|
|
191
|
+
try {
|
|
192
|
+
after = now();
|
|
193
|
+
} catch {
|
|
194
|
+
return Object.freeze({ status: "clock-invalid", value: null });
|
|
195
|
+
}
|
|
196
|
+
if (!Number.isFinite(after) || after < before)
|
|
197
|
+
return Object.freeze({ status: "clock-invalid", value: null });
|
|
198
|
+
return after >= deadline
|
|
199
|
+
? Object.freeze({ status: "deadline", value: null })
|
|
200
|
+
: Object.freeze(result);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Resolve one exact raw pane identity only when both qualified Web hosts agree. */
|
|
204
|
+
export function exactSharedCard5WebPane(observations) {
|
|
205
|
+
if (!Array.isArray(observations) || observations.length !== 2) return null;
|
|
206
|
+
const [webA, webB] = observations;
|
|
207
|
+
const pane = webA?.semanticPaneId;
|
|
208
|
+
return typeof pane === "string" && pane.length > 0 && pane.length <= 256
|
|
209
|
+
? pane === webB?.semanticPaneId
|
|
210
|
+
? pane
|
|
211
|
+
: null
|
|
212
|
+
: null;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Keep every later phase on the pane accepted by the initial convergence. */
|
|
216
|
+
export function matchesExpectedCard5WebPane(observations, expectedPane) {
|
|
217
|
+
return (
|
|
218
|
+
typeof expectedPane === "string" &&
|
|
219
|
+
expectedPane.length > 0 &&
|
|
220
|
+
expectedPane.length <= 256 &&
|
|
221
|
+
exactSharedCard5WebPane(observations) === expectedPane
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Select one native geometry row by semantic identity, never by row order. */
|
|
226
|
+
export function selectExactCard5PaneGeometry(rows, expectedPane) {
|
|
227
|
+
if (!Array.isArray(rows) || typeof expectedPane !== "string" || expectedPane.length < 1) {
|
|
228
|
+
return null;
|
|
229
|
+
}
|
|
230
|
+
const matching = rows.filter((row) => row?.semanticPaneId === expectedPane);
|
|
231
|
+
return matching.length === 1 ? matching[0] : null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** Resolve one semantic pane to an immutable private-socket tmux target. */
|
|
235
|
+
export function selectExactCard5TmuxPaneBinding(rows, expectedPane, expectedSession) {
|
|
236
|
+
if (
|
|
237
|
+
!Array.isArray(rows) ||
|
|
238
|
+
typeof expectedPane !== "string" ||
|
|
239
|
+
expectedPane.length < 1 ||
|
|
240
|
+
expectedPane.length > 256 ||
|
|
241
|
+
typeof expectedSession !== "string" ||
|
|
242
|
+
expectedSession.length < 1 ||
|
|
243
|
+
expectedSession.length > 128
|
|
244
|
+
)
|
|
245
|
+
return null;
|
|
246
|
+
const matching = rows.filter(
|
|
247
|
+
(row) => row?.semanticPaneId === expectedPane && row?.sessionName === expectedSession,
|
|
248
|
+
);
|
|
249
|
+
if (matching.length !== 1) return null;
|
|
250
|
+
const row = matching[0];
|
|
251
|
+
if (
|
|
252
|
+
!/^%[0-9]+$/u.test(row.paneId ?? "") ||
|
|
253
|
+
!/^\$[0-9]+$/u.test(row.sessionId ?? "") ||
|
|
254
|
+
!Number.isSafeInteger(row.paneCreated) ||
|
|
255
|
+
row.paneCreated < 0 ||
|
|
256
|
+
![row.left, row.top, row.width, row.height].every(Number.isSafeInteger) ||
|
|
257
|
+
row.left < 0 ||
|
|
258
|
+
row.top < 0 ||
|
|
259
|
+
row.width < 1 ||
|
|
260
|
+
row.height < 1 ||
|
|
261
|
+
row.windowActive !== true
|
|
262
|
+
)
|
|
263
|
+
return null;
|
|
264
|
+
return Object.freeze({
|
|
265
|
+
paneId: row.paneId,
|
|
266
|
+
semanticPaneId: row.semanticPaneId,
|
|
267
|
+
sessionName: row.sessionName,
|
|
268
|
+
sessionId: row.sessionId,
|
|
269
|
+
paneCreated: row.paneCreated,
|
|
270
|
+
left: row.left,
|
|
271
|
+
top: row.top,
|
|
272
|
+
width: row.width,
|
|
273
|
+
height: row.height,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function sameExactCard5TmuxPaneBinding(left, right) {
|
|
278
|
+
return (
|
|
279
|
+
left !== null &&
|
|
280
|
+
right !== null &&
|
|
281
|
+
Object.keys(left).sort().join("\0") ===
|
|
282
|
+
[
|
|
283
|
+
"paneId",
|
|
284
|
+
"semanticPaneId",
|
|
285
|
+
"sessionName",
|
|
286
|
+
"sessionId",
|
|
287
|
+
"paneCreated",
|
|
288
|
+
"left",
|
|
289
|
+
"top",
|
|
290
|
+
"width",
|
|
291
|
+
"height",
|
|
292
|
+
]
|
|
293
|
+
.sort()
|
|
294
|
+
.join("\0") &&
|
|
295
|
+
Object.keys(right).sort().join("\0") === Object.keys(left).sort().join("\0") &&
|
|
296
|
+
Object.entries(left).every(([key, value]) => right[key] === value)
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
export function card5TmuxCapturePaneArgv(binding) {
|
|
301
|
+
if (!/^%[0-9]+$/u.test(binding?.paneId ?? "")) return null;
|
|
302
|
+
return Object.freeze(["capture-pane", "-p", "-J", "-t", binding.paneId]);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export function runExactCard5TmuxPaneCapture({ latchedBinding, observeBinding, capture }) {
|
|
306
|
+
if (typeof observeBinding !== "function" || typeof capture !== "function")
|
|
307
|
+
return Object.freeze({ status: "topology-changed", value: null });
|
|
308
|
+
const before = observeBinding();
|
|
309
|
+
if (!sameExactCard5TmuxPaneBinding(latchedBinding, before))
|
|
310
|
+
return Object.freeze({ status: "topology-changed", value: null });
|
|
311
|
+
const argv = card5TmuxCapturePaneArgv(before);
|
|
312
|
+
if (argv === null) return Object.freeze({ status: "topology-changed", value: null });
|
|
313
|
+
let value = null;
|
|
314
|
+
let captureError = null;
|
|
315
|
+
try {
|
|
316
|
+
value = capture(argv);
|
|
317
|
+
} catch (error) {
|
|
318
|
+
captureError = error;
|
|
319
|
+
}
|
|
320
|
+
const after = observeBinding();
|
|
321
|
+
if (!sameExactCard5TmuxPaneBinding(latchedBinding, after))
|
|
322
|
+
return Object.freeze({ status: "topology-changed", value: null });
|
|
323
|
+
if (captureError !== null) throw captureError;
|
|
324
|
+
return Object.freeze({ status: "ok", value });
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* Join one outer-host paste to the exact inner semantic input/paint/fence chain.
|
|
329
|
+
* Raw pane, trace, marker, and payload identities never leave this projection.
|
|
330
|
+
*/
|
|
331
|
+
export function isExactCard5TuiHostInputReceipt(hostReceipt, payload) {
|
|
332
|
+
if (typeof payload !== "string") return false;
|
|
333
|
+
const injected = `\x1b[200~${payload}\x1b[201~`;
|
|
334
|
+
return (
|
|
335
|
+
hostReceipt?.version === 1 &&
|
|
336
|
+
hostReceipt.kind === "paste" &&
|
|
337
|
+
hostReceipt.delivery === "exact-bytes-to-immutable-host-pane-pty" &&
|
|
338
|
+
/^%\d+$/u.test(hostReceipt.paneId ?? "") &&
|
|
339
|
+
hostReceipt.target === hostReceipt.paneId &&
|
|
340
|
+
/^\$\d+$/u.test(hostReceipt.sessionId ?? "") &&
|
|
341
|
+
hostReceipt.phases === 1 &&
|
|
342
|
+
hostReceipt.transportCalls === 1 &&
|
|
343
|
+
hostReceipt.physicalTransportCalls === 1 &&
|
|
344
|
+
hostReceipt.bytesInjected === Buffer.byteLength(injected)
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function exactCard5TuiFocusControlReceipt(receipt, action, status) {
|
|
349
|
+
return (
|
|
350
|
+
exactKeys(receipt, [
|
|
351
|
+
"version",
|
|
352
|
+
"status",
|
|
353
|
+
"action",
|
|
354
|
+
"nonceHmac",
|
|
355
|
+
"diagnosticEpoch",
|
|
356
|
+
"state",
|
|
357
|
+
"bindingHmac",
|
|
358
|
+
"receiptHmac",
|
|
359
|
+
]) &&
|
|
360
|
+
receipt?.version === 1 &&
|
|
361
|
+
receipt.status === status &&
|
|
362
|
+
receipt.action === action &&
|
|
363
|
+
receipt.state === (action === "focus" ? "foreground" : "background") &&
|
|
364
|
+
HMAC.test(receipt.nonceHmac ?? "") &&
|
|
365
|
+
HMAC.test(receipt.bindingHmac ?? "") &&
|
|
366
|
+
HMAC.test(receipt.receiptHmac ?? "") &&
|
|
367
|
+
(status === "changed"
|
|
368
|
+
? Number.isSafeInteger(receipt.diagnosticEpoch) && receipt.diagnosticEpoch >= 1
|
|
369
|
+
: receipt.diagnosticEpoch === null)
|
|
370
|
+
);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Qualify one explicit OpenTUI blur -> focus epoch after a passive authority
|
|
375
|
+
* loss. The outer PTY receipts and inner renderer lifecycle are separate
|
|
376
|
+
* identity domains and are joined only by the immutable host target and the
|
|
377
|
+
* exact post-baseline transition cardinality.
|
|
378
|
+
*/
|
|
379
|
+
export function assessCard5TuiFocusTransition({
|
|
380
|
+
records,
|
|
381
|
+
priorBlurRecords = [],
|
|
382
|
+
receipts,
|
|
383
|
+
expectedCanonical,
|
|
384
|
+
expectedBindingHmac,
|
|
385
|
+
expectedWorkspaceName,
|
|
386
|
+
expectedRendererEpoch,
|
|
387
|
+
expectedClientGeneration,
|
|
388
|
+
expectedRuntimeSession,
|
|
389
|
+
expectedAuthorityOwners,
|
|
390
|
+
expectedTuiClientId,
|
|
391
|
+
minimumBlurAuthorityRevision,
|
|
392
|
+
minimumFocusAuthorityRevision,
|
|
393
|
+
baselineClaimOrdinal,
|
|
394
|
+
evidenceKey,
|
|
395
|
+
stage = "complete",
|
|
396
|
+
}) {
|
|
397
|
+
const fail = (reason) => Object.freeze({ passed: false, reason, evidence: null });
|
|
398
|
+
if (
|
|
399
|
+
!Array.isArray(records) ||
|
|
400
|
+
!["blur", "focus", "complete"].includes(stage) ||
|
|
401
|
+
!Number.isSafeInteger(baselineClaimOrdinal) ||
|
|
402
|
+
baselineClaimOrdinal < 0 ||
|
|
403
|
+
!/^opentui:[1-9]\d*$/u.test(expectedCanonical?.processId ?? "") ||
|
|
404
|
+
expectedCanonical?.clockId !== "opentui-performance-now" ||
|
|
405
|
+
!GENERATION.test(expectedCanonical?.generation ?? "") ||
|
|
406
|
+
!Array.isArray(priorBlurRecords) ||
|
|
407
|
+
!HMAC.test(expectedBindingHmac ?? "") ||
|
|
408
|
+
typeof expectedWorkspaceName !== "string" ||
|
|
409
|
+
expectedWorkspaceName.length < 1 ||
|
|
410
|
+
expectedWorkspaceName.length > 256 ||
|
|
411
|
+
!Number.isSafeInteger(expectedRendererEpoch) ||
|
|
412
|
+
expectedRendererEpoch < 0 ||
|
|
413
|
+
!Number.isSafeInteger(expectedClientGeneration) ||
|
|
414
|
+
expectedClientGeneration < 0 ||
|
|
415
|
+
!GENERATION.test(expectedRuntimeSession ?? "") ||
|
|
416
|
+
!exactAuthorityOwners(expectedAuthorityOwners) ||
|
|
417
|
+
typeof expectedTuiClientId !== "string" ||
|
|
418
|
+
expectedTuiClientId.length === 0 ||
|
|
419
|
+
!Number.isSafeInteger(minimumBlurAuthorityRevision) ||
|
|
420
|
+
minimumBlurAuthorityRevision < 0 ||
|
|
421
|
+
!Number.isSafeInteger(minimumFocusAuthorityRevision) ||
|
|
422
|
+
minimumFocusAuthorityRevision < minimumBlurAuthorityRevision ||
|
|
423
|
+
!HMAC.test(evidenceKey ?? "")
|
|
424
|
+
)
|
|
425
|
+
return fail("focus-transition-contract-invalid");
|
|
426
|
+
const receiptKeys =
|
|
427
|
+
stage === "blur"
|
|
428
|
+
? ["blur"]
|
|
429
|
+
: stage === "focus"
|
|
430
|
+
? ["blur", "focus"]
|
|
431
|
+
: ["blur", "focus", "duplicateFocus"];
|
|
432
|
+
if (!exactKeys(receipts, receiptKeys))
|
|
433
|
+
return fail(stage === "blur" ? "focus-blur-receipt-invalid" : "focus-focus-receipt-invalid");
|
|
434
|
+
if (
|
|
435
|
+
!["changed", "no-op"].some((status) =>
|
|
436
|
+
exactCard5TuiFocusControlReceipt(receipts?.blur, "blur", status),
|
|
437
|
+
) ||
|
|
438
|
+
receipts.blur.bindingHmac !== expectedBindingHmac
|
|
439
|
+
)
|
|
440
|
+
return fail("focus-blur-receipt-invalid");
|
|
441
|
+
if (stage !== "blur") {
|
|
442
|
+
if (
|
|
443
|
+
!exactCard5TuiFocusControlReceipt(receipts?.focus, "focus", "changed") ||
|
|
444
|
+
receipts.focus.bindingHmac !== expectedBindingHmac ||
|
|
445
|
+
(stage === "complete" &&
|
|
446
|
+
(!exactCard5TuiFocusControlReceipt(receipts?.duplicateFocus, "focus", "no-op") ||
|
|
447
|
+
receipts.duplicateFocus.bindingHmac !== expectedBindingHmac))
|
|
448
|
+
)
|
|
449
|
+
return fail("focus-focus-receipt-invalid");
|
|
450
|
+
}
|
|
451
|
+
const postLifecycle = records.filter(
|
|
452
|
+
(record) => typeof record?.phase === "string" && record.phase.startsWith("terminal-host-"),
|
|
453
|
+
);
|
|
454
|
+
const priorLifecycle = priorBlurRecords.filter(
|
|
455
|
+
(record) => typeof record?.phase === "string" && record.phase.startsWith("terminal-host-"),
|
|
456
|
+
);
|
|
457
|
+
const blurLifecycle = receipts.blur.status === "no-op" ? priorLifecycle : postLifecycle;
|
|
458
|
+
const blurEpoch =
|
|
459
|
+
receipts.blur.status === "changed"
|
|
460
|
+
? receipts.blur.diagnosticEpoch
|
|
461
|
+
: blurLifecycle.findLast((record) => record.phase === "terminal-host-renderer-blur-event")
|
|
462
|
+
?.diagnosticEpoch;
|
|
463
|
+
const blurEvents = blurLifecycle.filter(
|
|
464
|
+
(record) =>
|
|
465
|
+
record.phase === "terminal-host-renderer-blur-event" && record.diagnosticEpoch === blurEpoch,
|
|
466
|
+
);
|
|
467
|
+
const blurSettlements = blurLifecycle.filter(
|
|
468
|
+
(record) =>
|
|
469
|
+
record.phase === "terminal-host-blur-authority-settled" &&
|
|
470
|
+
record.diagnosticEpoch === blurEpoch,
|
|
471
|
+
);
|
|
472
|
+
const blurFences = blurLifecycle.filter(
|
|
473
|
+
(record) =>
|
|
474
|
+
record.phase === "terminal-host-focus-fence" && record.diagnosticEpoch === blurEpoch,
|
|
475
|
+
);
|
|
476
|
+
const focusEpoch = receipts?.focus?.diagnosticEpoch;
|
|
477
|
+
const focusEvents = postLifecycle.filter(
|
|
478
|
+
(record) =>
|
|
479
|
+
record.phase === "terminal-host-renderer-focus-event" &&
|
|
480
|
+
record.diagnosticEpoch === focusEpoch,
|
|
481
|
+
);
|
|
482
|
+
const claims = postLifecycle.filter(
|
|
483
|
+
(record) => record.phase === "terminal-host-focus-claim-attempt",
|
|
484
|
+
);
|
|
485
|
+
const focusSettlements = postLifecycle.filter(
|
|
486
|
+
(record) =>
|
|
487
|
+
record.phase === "terminal-host-focus-authority-settled" &&
|
|
488
|
+
record.diagnosticEpoch === focusEpoch,
|
|
489
|
+
);
|
|
490
|
+
const focusFences = postLifecycle.filter(
|
|
491
|
+
(record) =>
|
|
492
|
+
record.phase === "terminal-host-focus-fence" && record.diagnosticEpoch === focusEpoch,
|
|
493
|
+
);
|
|
494
|
+
if (
|
|
495
|
+
blurEvents.length !== 1 ||
|
|
496
|
+
blurSettlements.length !== 1 ||
|
|
497
|
+
blurFences.length !== 1 ||
|
|
498
|
+
(receipts.blur.status === "no-op" &&
|
|
499
|
+
priorLifecycle.findLast((record) =>
|
|
500
|
+
["terminal-host-renderer-blur-event", "terminal-host-renderer-focus-event"].includes(
|
|
501
|
+
record.phase,
|
|
502
|
+
),
|
|
503
|
+
) !== blurEvents[0])
|
|
504
|
+
)
|
|
505
|
+
return fail("focus-blur-lifecycle-invalid");
|
|
506
|
+
const blurEvent = blurEvents[0];
|
|
507
|
+
const blurSettlement = blurSettlements[0];
|
|
508
|
+
const blurFence = blurFences[0];
|
|
509
|
+
const safePoint = (record) =>
|
|
510
|
+
Number.isSafeInteger(record?.monotonicMicros) && record.monotonicMicros >= 0;
|
|
511
|
+
const sameProcess = (record) =>
|
|
512
|
+
record?.processId === expectedCanonical.processId &&
|
|
513
|
+
record?.clockId === expectedCanonical.clockId &&
|
|
514
|
+
record?.daemonInstanceId === expectedCanonical.generation &&
|
|
515
|
+
record?.workspaceName === expectedWorkspaceName &&
|
|
516
|
+
record?.rendererEpoch === expectedRendererEpoch &&
|
|
517
|
+
record?.clientGeneration === expectedClientGeneration;
|
|
518
|
+
const healthyFence = (record, settlement) =>
|
|
519
|
+
record?.settledPhase === settlement?.phase?.slice("terminal-host-".length) &&
|
|
520
|
+
record?.writerHealth?.failed === false &&
|
|
521
|
+
record.writerHealth.droppedRecords === 0 &&
|
|
522
|
+
record.writerHealth.pendingCriticalRecords === 0;
|
|
523
|
+
const authorities = ["input", "focus", "geometry"];
|
|
524
|
+
const expectedOwnersAfterBlur = Object.fromEntries(
|
|
525
|
+
authorities.map((authority) => [
|
|
526
|
+
authority,
|
|
527
|
+
expectedAuthorityOwners[authority] === expectedTuiClientId
|
|
528
|
+
? null
|
|
529
|
+
: expectedAuthorityOwners[authority],
|
|
530
|
+
]),
|
|
531
|
+
);
|
|
532
|
+
const blurReceipts = blurSettlement.receipts;
|
|
533
|
+
const blurReceiptsExact =
|
|
534
|
+
Array.isArray(blurReceipts) &&
|
|
535
|
+
blurReceipts.length === authorities.length &&
|
|
536
|
+
authorities.every((authority) => {
|
|
537
|
+
const matching = blurReceipts.filter((receipt) => receipt?.authority === authority);
|
|
538
|
+
const receipt = matching[0];
|
|
539
|
+
return (
|
|
540
|
+
matching.length === 1 &&
|
|
541
|
+
exactKeys(receipt, [
|
|
542
|
+
"authority",
|
|
543
|
+
"status",
|
|
544
|
+
"generation",
|
|
545
|
+
"owners",
|
|
546
|
+
"revision",
|
|
547
|
+
"session",
|
|
548
|
+
]) &&
|
|
549
|
+
receipt.status === "fulfilled" &&
|
|
550
|
+
receipt.generation === expectedCanonical.generation &&
|
|
551
|
+
receipt.session === expectedRuntimeSession &&
|
|
552
|
+
Number.isSafeInteger(receipt.revision) &&
|
|
553
|
+
receipt.revision > minimumBlurAuthorityRevision &&
|
|
554
|
+
exactKeys(receipt.owners, ["input", "focus", "geometry"]) &&
|
|
555
|
+
receipt.owners[authority] === expectedOwnersAfterBlur[authority] &&
|
|
556
|
+
authorities.every((kind) =>
|
|
557
|
+
expectedAuthorityOwners[kind] === expectedTuiClientId
|
|
558
|
+
? [expectedTuiClientId, null].includes(receipt.owners[kind])
|
|
559
|
+
: receipt.owners[kind] === expectedAuthorityOwners[kind],
|
|
560
|
+
)
|
|
561
|
+
);
|
|
562
|
+
});
|
|
563
|
+
if (
|
|
564
|
+
!Number.isSafeInteger(blurEvent.diagnosticEpoch) ||
|
|
565
|
+
blurEvent.diagnosticEpoch < 1 ||
|
|
566
|
+
blurEvent.state !== "background" ||
|
|
567
|
+
blurSettlement.diagnosticEpoch !== blurEvent.diagnosticEpoch ||
|
|
568
|
+
blurSettlement.status !== "fulfilled" ||
|
|
569
|
+
blurSettlement.bindingCurrent !== true ||
|
|
570
|
+
!blurReceiptsExact ||
|
|
571
|
+
!sameProcess(blurEvent) ||
|
|
572
|
+
!sameProcess(blurSettlement) ||
|
|
573
|
+
!safePoint(blurEvent) ||
|
|
574
|
+
!safePoint(blurSettlement) ||
|
|
575
|
+
!safePoint(blurFence) ||
|
|
576
|
+
blurLifecycle.indexOf(blurSettlement) <= blurLifecycle.indexOf(blurEvent) ||
|
|
577
|
+
blurLifecycle.indexOf(blurFence) <= blurLifecycle.indexOf(blurSettlement) ||
|
|
578
|
+
blurSettlement.monotonicMicros < blurEvent.monotonicMicros ||
|
|
579
|
+
blurFence.monotonicMicros < blurSettlement.monotonicMicros ||
|
|
580
|
+
!healthyFence(blurFence, blurSettlement)
|
|
581
|
+
)
|
|
582
|
+
return fail("focus-blur-lifecycle-invalid");
|
|
583
|
+
const blurRevision = blurSettlement.settledIdentity?.authorityRevision;
|
|
584
|
+
const blurReceiptRevision = Math.max(...blurReceipts.map(({ revision }) => revision));
|
|
585
|
+
if (
|
|
586
|
+
!exactKeys(blurSettlement.settledIdentity?.authorityOwners, authorities) ||
|
|
587
|
+
!authorities.every((authority) =>
|
|
588
|
+
expectedAuthorityOwners[authority] === expectedTuiClientId
|
|
589
|
+
? [expectedTuiClientId, null].includes(
|
|
590
|
+
blurSettlement.settledIdentity.authorityOwners[authority],
|
|
591
|
+
)
|
|
592
|
+
: blurSettlement.settledIdentity.authorityOwners[authority] ===
|
|
593
|
+
expectedOwnersAfterBlur[authority],
|
|
594
|
+
) ||
|
|
595
|
+
!Number.isSafeInteger(blurRevision) ||
|
|
596
|
+
blurRevision <= minimumBlurAuthorityRevision ||
|
|
597
|
+
!Number.isSafeInteger(blurReceiptRevision) ||
|
|
598
|
+
blurReceiptRevision <= minimumBlurAuthorityRevision
|
|
599
|
+
)
|
|
600
|
+
return fail("focus-blur-lifecycle-invalid");
|
|
601
|
+
const hmac = (domain, value) =>
|
|
602
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
603
|
+
.update(`${domain}\0${value}`)
|
|
604
|
+
.digest("hex");
|
|
605
|
+
if (stage === "blur")
|
|
606
|
+
return Object.freeze({
|
|
607
|
+
passed: true,
|
|
608
|
+
reason: null,
|
|
609
|
+
evidence: Object.freeze({
|
|
610
|
+
blurRevision,
|
|
611
|
+
blurReceiptRevision,
|
|
612
|
+
blurSettlementHmac: hmac("tui-focus-blur-settlement", JSON.stringify(blurSettlement)),
|
|
613
|
+
clientHmac: hmac("authority-client", expectedTuiClientId),
|
|
614
|
+
settledOwnersHmac: hmac(
|
|
615
|
+
"tui-focus-blur-settled-owners",
|
|
616
|
+
JSON.stringify(blurSettlement.settledIdentity.authorityOwners),
|
|
617
|
+
),
|
|
618
|
+
}),
|
|
619
|
+
});
|
|
620
|
+
if (
|
|
621
|
+
focusEvents.length !== 1 ||
|
|
622
|
+
claims.length !== 1 ||
|
|
623
|
+
focusSettlements.length !== 1 ||
|
|
624
|
+
focusFences.length !== 1
|
|
625
|
+
)
|
|
626
|
+
return fail("focus-claim-cardinality");
|
|
627
|
+
const focusEvent = focusEvents[0];
|
|
628
|
+
const claim = claims[0];
|
|
629
|
+
const focusSettlement = focusSettlements[0];
|
|
630
|
+
const focusFence = focusFences[0];
|
|
631
|
+
const settlementReceipts = focusSettlement.receipts;
|
|
632
|
+
const exactReceipts =
|
|
633
|
+
Array.isArray(settlementReceipts) &&
|
|
634
|
+
settlementReceipts.length === authorities.length &&
|
|
635
|
+
authorities.every((authority) => {
|
|
636
|
+
const matching = settlementReceipts.filter((receipt) => receipt?.authority === authority);
|
|
637
|
+
return (
|
|
638
|
+
matching.length === 1 &&
|
|
639
|
+
exactKeys(matching[0], [
|
|
640
|
+
"authority",
|
|
641
|
+
"status",
|
|
642
|
+
"generation",
|
|
643
|
+
"granted",
|
|
644
|
+
"revision",
|
|
645
|
+
"session",
|
|
646
|
+
"clientId",
|
|
647
|
+
]) &&
|
|
648
|
+
matching[0].status === "fulfilled" &&
|
|
649
|
+
matching[0].granted === true &&
|
|
650
|
+
matching[0].generation === expectedCanonical.generation &&
|
|
651
|
+
matching[0].session === expectedRuntimeSession &&
|
|
652
|
+
typeof matching[0].clientId === "string" &&
|
|
653
|
+
matching[0].clientId.length > 0 &&
|
|
654
|
+
Number.isSafeInteger(matching[0].revision) &&
|
|
655
|
+
matching[0].revision > minimumFocusAuthorityRevision
|
|
656
|
+
);
|
|
657
|
+
});
|
|
658
|
+
const clientIds = new Set(settlementReceipts?.map((receipt) => receipt?.clientId) ?? []);
|
|
659
|
+
const revisions = settlementReceipts?.map((receipt) => receipt?.revision) ?? [];
|
|
660
|
+
const focusRevision = focusSettlement.settledIdentity?.authorityRevision;
|
|
661
|
+
if (
|
|
662
|
+
!Number.isSafeInteger(focusEvent.diagnosticEpoch) ||
|
|
663
|
+
focusEvent.diagnosticEpoch !== blurEvent.diagnosticEpoch + 1 ||
|
|
664
|
+
focusEvent.state !== "foreground" ||
|
|
665
|
+
claim.diagnosticEpoch !== focusEvent.diagnosticEpoch ||
|
|
666
|
+
claim.claimOrdinal !== baselineClaimOrdinal + 1 ||
|
|
667
|
+
focusSettlement.diagnosticEpoch !== focusEvent.diagnosticEpoch ||
|
|
668
|
+
focusSettlement.status !== "fulfilled" ||
|
|
669
|
+
focusSettlement.bindingCurrent !== true ||
|
|
670
|
+
![focusEvent, claim, focusSettlement].every(sameProcess) ||
|
|
671
|
+
![focusEvent, claim, focusSettlement, focusFence].every(safePoint) ||
|
|
672
|
+
!(postLifecycle.indexOf(focusEvent) < postLifecycle.indexOf(claim)) ||
|
|
673
|
+
!(postLifecycle.indexOf(claim) < postLifecycle.indexOf(focusSettlement)) ||
|
|
674
|
+
!(postLifecycle.indexOf(focusSettlement) < postLifecycle.indexOf(focusFence)) ||
|
|
675
|
+
(receipts.blur.status === "changed" &&
|
|
676
|
+
!(postLifecycle.indexOf(blurFence) < postLifecycle.indexOf(focusEvent))) ||
|
|
677
|
+
focusEvent.monotonicMicros < blurFence.monotonicMicros ||
|
|
678
|
+
claim.monotonicMicros < focusEvent.monotonicMicros ||
|
|
679
|
+
focusSettlement.monotonicMicros < claim.monotonicMicros ||
|
|
680
|
+
focusFence.monotonicMicros < focusSettlement.monotonicMicros ||
|
|
681
|
+
!healthyFence(focusFence, focusSettlement) ||
|
|
682
|
+
!exactReceipts ||
|
|
683
|
+
clientIds.size !== 1 ||
|
|
684
|
+
new Set(revisions).size !== revisions.length ||
|
|
685
|
+
!Number.isSafeInteger(blurRevision) ||
|
|
686
|
+
blurRevision < minimumBlurAuthorityRevision ||
|
|
687
|
+
!Number.isSafeInteger(focusRevision) ||
|
|
688
|
+
focusRevision <= Math.max(blurRevision, minimumFocusAuthorityRevision) ||
|
|
689
|
+
focusRevision !== Math.max(...revisions)
|
|
690
|
+
)
|
|
691
|
+
return fail("focus-claim-lifecycle-invalid");
|
|
692
|
+
return Object.freeze({
|
|
693
|
+
passed: true,
|
|
694
|
+
reason: null,
|
|
695
|
+
evidence: Object.freeze({
|
|
696
|
+
hostPaneHmac: expectedBindingHmac,
|
|
697
|
+
blurReceiptHmac: receipts.blur.receiptHmac,
|
|
698
|
+
focusReceiptHmac: receipts.focus.receiptHmac,
|
|
699
|
+
duplicateFocusReceiptHmac: stage === "complete" ? receipts.duplicateFocus.receiptHmac : null,
|
|
700
|
+
blurSettlementHmac: hmac("tui-focus-blur-settlement", JSON.stringify(blurSettlement)),
|
|
701
|
+
focusSettlementHmac: hmac("tui-focus-focus-settlement", JSON.stringify(focusSettlement)),
|
|
702
|
+
lifecycleHmac: hmac(
|
|
703
|
+
"tui-focus-lifecycle",
|
|
704
|
+
[
|
|
705
|
+
...(receipts.blur.status === "no-op" ? [blurEvent, blurSettlement, blurFence] : []),
|
|
706
|
+
...postLifecycle,
|
|
707
|
+
]
|
|
708
|
+
.map((record) => `${record.phase}:${record.diagnosticEpoch ?? ""}`)
|
|
709
|
+
.join("\0"),
|
|
710
|
+
),
|
|
711
|
+
blurEpoch: blurEvent.diagnosticEpoch,
|
|
712
|
+
focusEpoch: focusEvent.diagnosticEpoch,
|
|
713
|
+
claimOrdinal: claim.claimOrdinal,
|
|
714
|
+
blurRevision,
|
|
715
|
+
focusRevision,
|
|
716
|
+
clientHmac: hmac("authority-client", [...clientIds][0]),
|
|
717
|
+
claimCount: claims.length,
|
|
718
|
+
duplicateClaimCount: 0,
|
|
719
|
+
}),
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
export function boundedCard5TuiBlurTransitionObservation({
|
|
724
|
+
assessment,
|
|
725
|
+
records,
|
|
726
|
+
receipt = null,
|
|
727
|
+
evidenceKey,
|
|
728
|
+
}) {
|
|
729
|
+
const lifecycle = Array.isArray(records)
|
|
730
|
+
? records.filter(
|
|
731
|
+
(record) => typeof record?.phase === "string" && record.phase.startsWith("terminal-host-"),
|
|
732
|
+
)
|
|
733
|
+
: [];
|
|
734
|
+
const phaseCount = (phase) =>
|
|
735
|
+
Math.min(8, lifecycle.filter((record) => record.phase === phase).length);
|
|
736
|
+
const settlement = lifecycle.find(
|
|
737
|
+
(record) => record.phase === "terminal-host-blur-authority-settled",
|
|
738
|
+
);
|
|
739
|
+
const fence = lifecycle.find(
|
|
740
|
+
(record) =>
|
|
741
|
+
record.phase === "terminal-host-focus-fence" &&
|
|
742
|
+
record.diagnosticEpoch === settlement?.diagnosticEpoch,
|
|
743
|
+
);
|
|
744
|
+
const hmac = (domain, value) =>
|
|
745
|
+
HMAC.test(evidenceKey ?? "")
|
|
746
|
+
? createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
747
|
+
.update(`${domain}\0${value}`)
|
|
748
|
+
.digest("hex")
|
|
749
|
+
: null;
|
|
750
|
+
const revisions = Array.isArray(settlement?.receipts)
|
|
751
|
+
? settlement.receipts
|
|
752
|
+
.map(({ revision }) => (Number.isSafeInteger(revision) && revision >= 0 ? revision : null))
|
|
753
|
+
.slice(0, 3)
|
|
754
|
+
: [];
|
|
755
|
+
return Object.freeze({
|
|
756
|
+
reason:
|
|
757
|
+
typeof assessment?.reason === "string" && assessment.reason.length <= 64
|
|
758
|
+
? assessment.reason
|
|
759
|
+
: assessment?.passed === true
|
|
760
|
+
? "exact"
|
|
761
|
+
: "blur-assessment-unavailable",
|
|
762
|
+
passed: assessment?.passed === true,
|
|
763
|
+
controlStatus: ["changed", "no-op", "stale", "rejected"].includes(receipt?.status)
|
|
764
|
+
? receipt.status
|
|
765
|
+
: null,
|
|
766
|
+
controlEpoch:
|
|
767
|
+
Number.isSafeInteger(receipt?.diagnosticEpoch) && receipt.diagnosticEpoch >= 1
|
|
768
|
+
? receipt.diagnosticEpoch
|
|
769
|
+
: null,
|
|
770
|
+
controlBindingHmac: HMAC.test(receipt?.bindingHmac ?? "") ? receipt.bindingHmac : null,
|
|
771
|
+
recordCount: Math.min(lifecycle.length, 64),
|
|
772
|
+
recordOverflow: lifecycle.length > 64,
|
|
773
|
+
blurEventCount: phaseCount("terminal-host-renderer-blur-event"),
|
|
774
|
+
settlementCount: phaseCount("terminal-host-blur-authority-settled"),
|
|
775
|
+
fenceCount: phaseCount("terminal-host-focus-fence"),
|
|
776
|
+
diagnosticEpoch:
|
|
777
|
+
Number.isSafeInteger(settlement?.diagnosticEpoch) && settlement.diagnosticEpoch >= 0
|
|
778
|
+
? settlement.diagnosticEpoch
|
|
779
|
+
: null,
|
|
780
|
+
receiptCount: Math.min(settlement?.receipts?.length ?? 0, 4),
|
|
781
|
+
receiptOverflow: (settlement?.receipts?.length ?? 0) > 4,
|
|
782
|
+
receiptStatuses: Object.freeze(
|
|
783
|
+
Array.isArray(settlement?.receipts)
|
|
784
|
+
? settlement.receipts
|
|
785
|
+
.slice(0, 3)
|
|
786
|
+
.map(({ status }) => (["fulfilled", "rejected"].includes(status) ? status : "invalid"))
|
|
787
|
+
: [],
|
|
788
|
+
),
|
|
789
|
+
receiptRevisions: Object.freeze(revisions),
|
|
790
|
+
settledRevision:
|
|
791
|
+
Number.isSafeInteger(settlement?.settledIdentity?.authorityRevision) &&
|
|
792
|
+
settlement.settledIdentity.authorityRevision >= 0
|
|
793
|
+
? settlement.settledIdentity.authorityRevision
|
|
794
|
+
: null,
|
|
795
|
+
settledOwnersHmac:
|
|
796
|
+
settlement?.settledIdentity?.authorityOwners === null ||
|
|
797
|
+
typeof settlement?.settledIdentity?.authorityOwners !== "object"
|
|
798
|
+
? null
|
|
799
|
+
: hmac(
|
|
800
|
+
"tui-blur-observed-owners",
|
|
801
|
+
JSON.stringify(settlement.settledIdentity.authorityOwners),
|
|
802
|
+
),
|
|
803
|
+
writerHealthy:
|
|
804
|
+
fence?.writerHealth?.failed === false &&
|
|
805
|
+
fence?.writerHealth?.droppedRecords === 0 &&
|
|
806
|
+
fence?.writerHealth?.pendingCriticalRecords === 0,
|
|
807
|
+
tailPosition:
|
|
808
|
+
Number.isSafeInteger(lifecycle.at(-1)?.monotonicMicros) &&
|
|
809
|
+
lifecycle.at(-1).monotonicMicros >= 0
|
|
810
|
+
? lifecycle.at(-1).monotonicMicros
|
|
811
|
+
: null,
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/** Select the exact current lifecycle identity used to authenticate host-focus control. */
|
|
816
|
+
export function selectCard5TuiHostFocusBinding({
|
|
817
|
+
lifecycleRecords,
|
|
818
|
+
referenceRecords,
|
|
819
|
+
expectedCanonical,
|
|
820
|
+
expectedAuthority,
|
|
821
|
+
expectedWorkspaceName,
|
|
822
|
+
expectedTuiClientId,
|
|
823
|
+
evidenceKey,
|
|
824
|
+
}) {
|
|
825
|
+
const relevant = Array.isArray(lifecycleRecords)
|
|
826
|
+
? lifecycleRecords.filter((record) =>
|
|
827
|
+
[
|
|
828
|
+
"terminal-host-focus-authority-settled",
|
|
829
|
+
"terminal-host-blur-authority-settled",
|
|
830
|
+
"terminal-host-focus-authority-reconcile",
|
|
831
|
+
].includes(record?.phase),
|
|
832
|
+
)
|
|
833
|
+
: [];
|
|
834
|
+
const bindingRecords = Array.isArray(lifecycleRecords)
|
|
835
|
+
? lifecycleRecords.filter(
|
|
836
|
+
(record) => record?.phase === "terminal-host-focus-control-binding-ready",
|
|
837
|
+
)
|
|
838
|
+
: [];
|
|
839
|
+
const gateRecords = Array.isArray(lifecycleRecords)
|
|
840
|
+
? lifecycleRecords.filter(
|
|
841
|
+
(record) => record?.phase === "terminal-host-focus-control-gate-ready",
|
|
842
|
+
)
|
|
843
|
+
: [];
|
|
844
|
+
const bindingFrame = Array.isArray(referenceRecords)
|
|
845
|
+
? (referenceRecords.findLast(
|
|
846
|
+
(record) =>
|
|
847
|
+
record?.type === "performance.terminal-frame-fence" &&
|
|
848
|
+
record.semanticPaneId === expectedCanonical?.semanticPaneId &&
|
|
849
|
+
record.processId === expectedCanonical?.processId &&
|
|
850
|
+
record.clockId === expectedCanonical?.clockId &&
|
|
851
|
+
record.generation === expectedCanonical?.generation &&
|
|
852
|
+
record.incarnation === expectedCanonical?.incarnation &&
|
|
853
|
+
record.revision === expectedCanonical?.revision &&
|
|
854
|
+
record.stateHash === expectedCanonical?.canonicalStateHash &&
|
|
855
|
+
Number.isSafeInteger(record.rendererEpoch) &&
|
|
856
|
+
record.rendererEpoch >= 0,
|
|
857
|
+
) ?? null)
|
|
858
|
+
: null;
|
|
859
|
+
const hmac = (domain, value) =>
|
|
860
|
+
HMAC.test(evidenceKey ?? "")
|
|
861
|
+
? createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
862
|
+
.update(`${domain}\0${value}`)
|
|
863
|
+
.digest("hex")
|
|
864
|
+
: null;
|
|
865
|
+
const authorities = ["input", "focus", "geometry"];
|
|
866
|
+
const currentPresence = expectedAuthority?.clients?.find(
|
|
867
|
+
({ clientId }) => clientId === expectedTuiClientId,
|
|
868
|
+
);
|
|
869
|
+
const ownersExact = (owners) =>
|
|
870
|
+
exactAuthorityOwners(owners) &&
|
|
871
|
+
authorities.every((authority) => owners[authority] === expectedAuthority?.owners?.[authority]);
|
|
872
|
+
const lifecycleEnvelopeExact = (record, details) =>
|
|
873
|
+
exactKeys(record, [
|
|
874
|
+
"phase",
|
|
875
|
+
"elapsedMs",
|
|
876
|
+
"at",
|
|
877
|
+
...details,
|
|
878
|
+
"monotonicMicros",
|
|
879
|
+
"processId",
|
|
880
|
+
"clockId",
|
|
881
|
+
]) &&
|
|
882
|
+
Number.isSafeInteger(record?.elapsedMs) &&
|
|
883
|
+
record.elapsedMs >= 0 &&
|
|
884
|
+
typeof record?.at === "string" &&
|
|
885
|
+
record.at.length <= 40 &&
|
|
886
|
+
Number.isFinite(Date.parse(record.at)) &&
|
|
887
|
+
Number.isSafeInteger(record?.monotonicMicros) &&
|
|
888
|
+
record.monotonicMicros >= 0;
|
|
889
|
+
const bindingReadyExact = (record) =>
|
|
890
|
+
record?.phase === "terminal-host-focus-control-binding-ready" &&
|
|
891
|
+
lifecycleEnvelopeExact(record, [
|
|
892
|
+
"bindingEpoch",
|
|
893
|
+
"rendererEpoch",
|
|
894
|
+
"clientGeneration",
|
|
895
|
+
"clientPhase",
|
|
896
|
+
"authorityGeneration",
|
|
897
|
+
"runtimeSession",
|
|
898
|
+
"daemonInstanceId",
|
|
899
|
+
"workspaceName",
|
|
900
|
+
"clientId",
|
|
901
|
+
]) &&
|
|
902
|
+
record?.processId === expectedCanonical?.processId &&
|
|
903
|
+
record?.clockId === expectedCanonical?.clockId &&
|
|
904
|
+
record?.daemonInstanceId === expectedAuthority?.generation &&
|
|
905
|
+
record?.authorityGeneration === expectedAuthority?.generation &&
|
|
906
|
+
record?.runtimeSession === expectedAuthority?.session &&
|
|
907
|
+
record?.workspaceName === expectedWorkspaceName &&
|
|
908
|
+
record?.clientId === expectedTuiClientId &&
|
|
909
|
+
record?.clientPhase === "live" &&
|
|
910
|
+
record?.rendererEpoch === bindingFrame?.rendererEpoch &&
|
|
911
|
+
Number.isSafeInteger(record?.rendererEpoch) &&
|
|
912
|
+
record.rendererEpoch >= 0 &&
|
|
913
|
+
Number.isSafeInteger(record?.clientGeneration) &&
|
|
914
|
+
record.clientGeneration >= 0 &&
|
|
915
|
+
Number.isSafeInteger(record?.bindingEpoch) &&
|
|
916
|
+
record.bindingEpoch >= 1;
|
|
917
|
+
const gateDetails = ["capability", "detail", "path", "root", "key", "trace", "enabled"];
|
|
918
|
+
const gateExact = (record) =>
|
|
919
|
+
record?.phase === "terminal-host-focus-control-gate-ready" &&
|
|
920
|
+
lifecycleEnvelopeExact(record, gateDetails) &&
|
|
921
|
+
record?.processId === expectedCanonical?.processId &&
|
|
922
|
+
record?.clockId === expectedCanonical?.clockId &&
|
|
923
|
+
record?.capability === true &&
|
|
924
|
+
record?.detail === true &&
|
|
925
|
+
record?.path === true &&
|
|
926
|
+
record?.root === true &&
|
|
927
|
+
record?.key === true &&
|
|
928
|
+
record?.trace === true &&
|
|
929
|
+
record?.enabled === true;
|
|
930
|
+
const reconcileReceiptExact = (record, authority) => {
|
|
931
|
+
const matches = record.receipts.filter((receipt) => receipt?.authority === authority);
|
|
932
|
+
return (
|
|
933
|
+
matches.length === 1 &&
|
|
934
|
+
exactKeys(matches[0], ["authority", "status", "granted", "exact"]) &&
|
|
935
|
+
matches[0].status === "fulfilled" &&
|
|
936
|
+
matches[0].granted === true &&
|
|
937
|
+
matches[0].exact === true
|
|
938
|
+
);
|
|
939
|
+
};
|
|
940
|
+
const settlementExact = (record) => {
|
|
941
|
+
const settled = record?.settledIdentity;
|
|
942
|
+
if (
|
|
943
|
+
!["terminal-host-focus-authority-settled", "terminal-host-blur-authority-settled"].includes(
|
|
944
|
+
record?.phase,
|
|
945
|
+
) ||
|
|
946
|
+
!Number.isSafeInteger(record?.diagnosticEpoch) ||
|
|
947
|
+
record.diagnosticEpoch < 1 ||
|
|
948
|
+
record.status !== "fulfilled" ||
|
|
949
|
+
record.bindingCurrent !== true ||
|
|
950
|
+
!exactKeys(settled, [
|
|
951
|
+
"clientGeneration",
|
|
952
|
+
"clientPhase",
|
|
953
|
+
"authorityGeneration",
|
|
954
|
+
"runtimeSession",
|
|
955
|
+
"authorityOwners",
|
|
956
|
+
"authorityRevision",
|
|
957
|
+
"daemonInstanceId",
|
|
958
|
+
"workspaceName",
|
|
959
|
+
"opentuiPresence",
|
|
960
|
+
]) ||
|
|
961
|
+
settled.clientGeneration !== record.clientGeneration ||
|
|
962
|
+
settled.clientPhase !== "live" ||
|
|
963
|
+
settled.authorityGeneration !== expectedAuthority?.generation ||
|
|
964
|
+
settled.runtimeSession !== expectedAuthority?.session ||
|
|
965
|
+
settled.daemonInstanceId !== expectedAuthority?.generation ||
|
|
966
|
+
settled.workspaceName !== expectedWorkspaceName ||
|
|
967
|
+
!exactAuthorityOwners(settled.authorityOwners) ||
|
|
968
|
+
!Number.isSafeInteger(settled.authorityRevision) ||
|
|
969
|
+
settled.authorityRevision < 0 ||
|
|
970
|
+
!exactKeys(settled.opentuiPresence, [
|
|
971
|
+
"clientId",
|
|
972
|
+
"state",
|
|
973
|
+
"connectedRevision",
|
|
974
|
+
"activityRevision",
|
|
975
|
+
]) ||
|
|
976
|
+
settled.opentuiPresence.clientId !== expectedTuiClientId ||
|
|
977
|
+
!Array.isArray(record.receipts) ||
|
|
978
|
+
record.receipts.length !== 3
|
|
979
|
+
)
|
|
980
|
+
return false;
|
|
981
|
+
const receiptsExact = authorities.every((authority) => {
|
|
982
|
+
const matches = record.receipts.filter((receipt) => receipt?.authority === authority);
|
|
983
|
+
const receipt = matches[0];
|
|
984
|
+
return (
|
|
985
|
+
matches.length === 1 &&
|
|
986
|
+
exactKeys(
|
|
987
|
+
receipt,
|
|
988
|
+
record.phase === "terminal-host-focus-authority-settled"
|
|
989
|
+
? ["authority", "status", "generation", "granted", "revision", "session", "clientId"]
|
|
990
|
+
: ["authority", "status", "generation", "owners", "revision", "session"],
|
|
991
|
+
) &&
|
|
992
|
+
receipt?.status === "fulfilled" &&
|
|
993
|
+
receipt.generation === expectedAuthority?.generation &&
|
|
994
|
+
receipt.session === expectedAuthority?.session &&
|
|
995
|
+
(record.phase === "terminal-host-focus-authority-settled"
|
|
996
|
+
? receipt.granted === true && receipt.clientId === expectedTuiClientId
|
|
997
|
+
: exactAuthorityOwners(receipt.owners))
|
|
998
|
+
);
|
|
999
|
+
});
|
|
1000
|
+
if (!receiptsExact) return false;
|
|
1001
|
+
const receiptRevisions = record.receipts.map(({ revision }) => revision);
|
|
1002
|
+
if (
|
|
1003
|
+
receiptRevisions.some((revision) => !Number.isSafeInteger(revision) || revision < 0) ||
|
|
1004
|
+
settled.authorityRevision < Math.max(...receiptRevisions)
|
|
1005
|
+
)
|
|
1006
|
+
return false;
|
|
1007
|
+
return record.phase === "terminal-host-focus-authority-settled"
|
|
1008
|
+
? settled.opentuiPresence.state === "foreground" &&
|
|
1009
|
+
authorities.every(
|
|
1010
|
+
(authority) => settled.authorityOwners[authority] === expectedTuiClientId,
|
|
1011
|
+
)
|
|
1012
|
+
: settled.opentuiPresence.state === "background" &&
|
|
1013
|
+
authorities.every(
|
|
1014
|
+
(authority) => settled.authorityOwners[authority] !== expectedTuiClientId,
|
|
1015
|
+
);
|
|
1016
|
+
};
|
|
1017
|
+
const valid = bindingRecords.filter(bindingReadyExact);
|
|
1018
|
+
const selected = valid.at(-1) ?? null;
|
|
1019
|
+
const latestRelevant = bindingRecords.at(-1) ?? null;
|
|
1020
|
+
const validGates = gateRecords.filter(gateExact);
|
|
1021
|
+
const selectedGate = validGates.at(-1) ?? null;
|
|
1022
|
+
const latestGate = gateRecords.at(-1) ?? null;
|
|
1023
|
+
const gatePassed =
|
|
1024
|
+
gateRecords.length <= 64 && selectedGate !== null && selectedGate === latestGate;
|
|
1025
|
+
const passed =
|
|
1026
|
+
gatePassed && bindingRecords.length <= 64 && selected !== null && selected === latestRelevant;
|
|
1027
|
+
const source = passed ? "binding-ready" : null;
|
|
1028
|
+
const reason =
|
|
1029
|
+
gateRecords.length > 64
|
|
1030
|
+
? "binding-gate-overflow"
|
|
1031
|
+
: selectedGate === null
|
|
1032
|
+
? "binding-gate-invalid"
|
|
1033
|
+
: selectedGate !== latestGate
|
|
1034
|
+
? "binding-gate-stale"
|
|
1035
|
+
: bindingRecords.length > 64
|
|
1036
|
+
? "binding-record-overflow"
|
|
1037
|
+
: selected === null
|
|
1038
|
+
? "binding-record-invalid"
|
|
1039
|
+
: selected !== latestRelevant
|
|
1040
|
+
? "binding-record-stale"
|
|
1041
|
+
: "binding-record-ambiguous";
|
|
1042
|
+
const latestReconcile = relevant.findLast(
|
|
1043
|
+
(record) => record?.phase === "terminal-host-focus-authority-reconcile",
|
|
1044
|
+
);
|
|
1045
|
+
const authorityOutcome = (authority) => {
|
|
1046
|
+
if (!latestReconcile) return "missing-record";
|
|
1047
|
+
if (!Array.isArray(latestReconcile.receipts)) return "receipts-invalid";
|
|
1048
|
+
const matches = latestReconcile.receipts.filter((receipt) => receipt?.authority === authority);
|
|
1049
|
+
if (matches.length === 0) return "receipt-missing";
|
|
1050
|
+
if (matches.length !== 1) return "receipt-duplicate";
|
|
1051
|
+
const receipt = matches[0];
|
|
1052
|
+
if (!exactKeys(receipt, ["authority", "status", "granted", "exact"])) return "receipt-invalid";
|
|
1053
|
+
if (receipt.status !== "fulfilled") return "not-fulfilled";
|
|
1054
|
+
if (receipt.granted !== true) return "not-granted";
|
|
1055
|
+
return receipt.exact === true ? "granted-exact" : "granted-inexact";
|
|
1056
|
+
};
|
|
1057
|
+
const allTuiOwners = latestReconcile
|
|
1058
|
+
? exactAuthorityOwners(latestReconcile.authorityOwners) &&
|
|
1059
|
+
authorities.every(
|
|
1060
|
+
(authority) => latestReconcile.authorityOwners[authority] === expectedTuiClientId,
|
|
1061
|
+
)
|
|
1062
|
+
: null;
|
|
1063
|
+
return Object.freeze({
|
|
1064
|
+
passed,
|
|
1065
|
+
reason: passed ? null : reason,
|
|
1066
|
+
source,
|
|
1067
|
+
binding: passed
|
|
1068
|
+
? Object.freeze({
|
|
1069
|
+
rendererEpoch: selected.rendererEpoch,
|
|
1070
|
+
clientGeneration: selected.clientGeneration,
|
|
1071
|
+
bindingEpoch: selected.bindingEpoch,
|
|
1072
|
+
})
|
|
1073
|
+
: null,
|
|
1074
|
+
observation: Object.freeze({
|
|
1075
|
+
bindingSource: source,
|
|
1076
|
+
reason: passed ? "exact" : reason,
|
|
1077
|
+
gateCount: Math.min(gateRecords.length, 64),
|
|
1078
|
+
gateOverflow: gateRecords.length > 64,
|
|
1079
|
+
gateSchemaMismatch: latestGate !== null && !lifecycleEnvelopeExact(latestGate, gateDetails),
|
|
1080
|
+
gateProcessMismatch:
|
|
1081
|
+
latestGate !== null && latestGate?.processId !== expectedCanonical?.processId,
|
|
1082
|
+
gateClockMismatch: latestGate !== null && latestGate?.clockId !== expectedCanonical?.clockId,
|
|
1083
|
+
gateCapability: latestGate?.capability === true,
|
|
1084
|
+
gateDetail: latestGate?.detail === true,
|
|
1085
|
+
gatePath: latestGate?.path === true,
|
|
1086
|
+
gateRoot: latestGate?.root === true,
|
|
1087
|
+
gateKey: latestGate?.key === true,
|
|
1088
|
+
gateTrace: latestGate?.trace === true,
|
|
1089
|
+
gateEnabled: latestGate?.enabled === true,
|
|
1090
|
+
relevantCount: Math.min(bindingRecords.length, 64),
|
|
1091
|
+
overflow: bindingRecords.length > 64,
|
|
1092
|
+
processMismatch: bindingRecords.some(
|
|
1093
|
+
(record) => record?.processId !== expectedCanonical?.processId,
|
|
1094
|
+
),
|
|
1095
|
+
clockMismatch: bindingRecords.some(
|
|
1096
|
+
(record) => record?.clockId !== expectedCanonical?.clockId,
|
|
1097
|
+
),
|
|
1098
|
+
generationMismatch: bindingRecords.some(
|
|
1099
|
+
(record) => record?.daemonInstanceId !== expectedAuthority?.generation,
|
|
1100
|
+
),
|
|
1101
|
+
sessionMismatch: bindingRecords.some(
|
|
1102
|
+
(record) => record?.runtimeSession !== expectedAuthority?.session,
|
|
1103
|
+
),
|
|
1104
|
+
workspaceMismatch: bindingRecords.some(
|
|
1105
|
+
(record) => record?.workspaceName !== expectedWorkspaceName,
|
|
1106
|
+
),
|
|
1107
|
+
clientMismatch: bindingRecords.some((record) => record?.clientId !== expectedTuiClientId),
|
|
1108
|
+
epochMismatch:
|
|
1109
|
+
bindingFrame === null ||
|
|
1110
|
+
bindingRecords.some((record) => record?.rendererEpoch !== bindingFrame.rendererEpoch),
|
|
1111
|
+
clientGenerationMismatch: bindingRecords.some(
|
|
1112
|
+
(record) => !Number.isSafeInteger(record?.clientGeneration) || record.clientGeneration < 0,
|
|
1113
|
+
),
|
|
1114
|
+
diagnosticEpochMismatch: relevant.some(
|
|
1115
|
+
(record) =>
|
|
1116
|
+
record?.phase === "terminal-host-focus-authority-reconcile" &&
|
|
1117
|
+
record?.diagnosticEpoch !== null,
|
|
1118
|
+
),
|
|
1119
|
+
statusMismatch: relevant.some(
|
|
1120
|
+
(record) =>
|
|
1121
|
+
record?.phase === "terminal-host-focus-authority-reconcile" &&
|
|
1122
|
+
record?.status !== "applied",
|
|
1123
|
+
),
|
|
1124
|
+
presenceMismatch: relevant.some(
|
|
1125
|
+
(record) =>
|
|
1126
|
+
record?.phase === "terminal-host-focus-authority-reconcile" &&
|
|
1127
|
+
(record?.opentuiPresence?.state !== "foreground" ||
|
|
1128
|
+
currentPresence?.state !== "foreground"),
|
|
1129
|
+
),
|
|
1130
|
+
revisionRelationMismatch: relevant.some(
|
|
1131
|
+
(record) =>
|
|
1132
|
+
record?.phase === "terminal-host-focus-authority-reconcile" &&
|
|
1133
|
+
(!Number.isSafeInteger(record?.authorityRevision) ||
|
|
1134
|
+
!Number.isSafeInteger(expectedAuthority?.revision) ||
|
|
1135
|
+
record.authorityRevision < 0 ||
|
|
1136
|
+
record.authorityRevision > expectedAuthority.revision ||
|
|
1137
|
+
!Number.isSafeInteger(record?.opentuiPresence?.connectedRevision) ||
|
|
1138
|
+
!Number.isSafeInteger(record?.opentuiPresence?.activityRevision) ||
|
|
1139
|
+
record.opentuiPresence.connectedRevision < 0 ||
|
|
1140
|
+
record.opentuiPresence.activityRevision < record.opentuiPresence.connectedRevision ||
|
|
1141
|
+
record.opentuiPresence.activityRevision > record.authorityRevision ||
|
|
1142
|
+
!Number.isSafeInteger(currentPresence?.connectedRevision) ||
|
|
1143
|
+
!Number.isSafeInteger(currentPresence?.activityRevision) ||
|
|
1144
|
+
record.opentuiPresence.connectedRevision > currentPresence.connectedRevision ||
|
|
1145
|
+
record.opentuiPresence.activityRevision > currentPresence.activityRevision),
|
|
1146
|
+
),
|
|
1147
|
+
receiptMismatch: relevant.some(
|
|
1148
|
+
(record) =>
|
|
1149
|
+
record?.phase === "terminal-host-focus-authority-reconcile" &&
|
|
1150
|
+
(!Array.isArray(record?.receipts) ||
|
|
1151
|
+
record.receipts.length !== 3 ||
|
|
1152
|
+
!authorities.every((authority) => reconcileReceiptExact(record, authority))),
|
|
1153
|
+
),
|
|
1154
|
+
ownerMismatch: relevant.some((record) =>
|
|
1155
|
+
record?.phase === "terminal-host-focus-authority-reconcile"
|
|
1156
|
+
? !ownersExact(record?.authorityOwners)
|
|
1157
|
+
: !settlementExact(record),
|
|
1158
|
+
),
|
|
1159
|
+
authorityOutcome: Object.freeze({
|
|
1160
|
+
input: authorityOutcome("input"),
|
|
1161
|
+
focus: authorityOutcome("focus"),
|
|
1162
|
+
geometry: authorityOutcome("geometry"),
|
|
1163
|
+
}),
|
|
1164
|
+
allTuiOwners,
|
|
1165
|
+
recordHmac: selected ? hmac("host-focus-binding-record", JSON.stringify(selected)) : null,
|
|
1166
|
+
}),
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
export function advanceCard5AuthorityReleaseStability(previous, candidate, qualified) {
|
|
1171
|
+
if (typeof candidate !== "string" || candidate.length > 16_384 || qualified !== true)
|
|
1172
|
+
return Object.freeze({ candidate: null, samples: 0, passed: false });
|
|
1173
|
+
const samples = previous?.candidate === candidate ? (previous.samples ?? 0) + 1 : 1;
|
|
1174
|
+
return Object.freeze({ candidate, samples, passed: samples >= 2 });
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
export function advanceCard5RetainedFocusStability(previous, candidate, qualified) {
|
|
1178
|
+
return advanceCard5AuthorityReleaseStability(previous, candidate, qualified);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
export function assessCard5TuiFocusedPane({
|
|
1182
|
+
records,
|
|
1183
|
+
expectedPane,
|
|
1184
|
+
expectedCanonical,
|
|
1185
|
+
expectedAuthority = undefined,
|
|
1186
|
+
evidenceKey,
|
|
1187
|
+
}) {
|
|
1188
|
+
const hmac = (domain, value) =>
|
|
1189
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
1190
|
+
.update(`${domain}\0${value}`)
|
|
1191
|
+
.digest("hex");
|
|
1192
|
+
const emptyAxes = () => ({
|
|
1193
|
+
pane: true,
|
|
1194
|
+
generation: true,
|
|
1195
|
+
incarnation: true,
|
|
1196
|
+
revision: true,
|
|
1197
|
+
canonicalHash: true,
|
|
1198
|
+
process: true,
|
|
1199
|
+
clock: true,
|
|
1200
|
+
canonicalDimensions: true,
|
|
1201
|
+
viewportDimensions: true,
|
|
1202
|
+
presentationCount: true,
|
|
1203
|
+
followingFrame: true,
|
|
1204
|
+
frameHealth: true,
|
|
1205
|
+
authority: true,
|
|
1206
|
+
});
|
|
1207
|
+
const safeHmac = (domain, value) =>
|
|
1208
|
+
typeof value === "string" && value.length > 0 ? hmac(domain, value) : null;
|
|
1209
|
+
const candidateFor = (presentation, frame, axes) =>
|
|
1210
|
+
Object.freeze({
|
|
1211
|
+
paneHmac: safeHmac("focused-pane-candidate", presentation?.semanticPaneId),
|
|
1212
|
+
generationHmac: safeHmac("focused-generation-candidate", presentation?.generation),
|
|
1213
|
+
incarnationHmac: safeHmac("focused-incarnation-candidate", presentation?.incarnation),
|
|
1214
|
+
processHmac: safeHmac("focused-process-candidate", presentation?.processId),
|
|
1215
|
+
clockHmac: safeHmac("focused-clock-candidate", presentation?.clockId),
|
|
1216
|
+
canonicalHashHmac: safeHmac("focused-canonical-candidate", presentation?.stateHash),
|
|
1217
|
+
revision: boundedInteger(presentation?.revision, 0xffff_ffff),
|
|
1218
|
+
cols: boundedInteger(presentation?.cols, 65_535),
|
|
1219
|
+
rows: boundedInteger(presentation?.rows, 65_535),
|
|
1220
|
+
viewportCols: boundedInteger(presentation?.viewportCols, 65_535),
|
|
1221
|
+
viewportRows: boundedInteger(presentation?.viewportRows, 65_535),
|
|
1222
|
+
presentationCount: boundedInteger(presentation?.presentationCount, 0xffff_ffff),
|
|
1223
|
+
presentationHmac:
|
|
1224
|
+
Number.isSafeInteger(presentation?.atMicros) && presentation.atMicros >= 0
|
|
1225
|
+
? hmac(
|
|
1226
|
+
"focused-cursor-presentation",
|
|
1227
|
+
[presentation.atMicros, presentation.presentationCount].join("\0"),
|
|
1228
|
+
)
|
|
1229
|
+
: null,
|
|
1230
|
+
frameHmac:
|
|
1231
|
+
Number.isSafeInteger(frame?.atMicros) && frame.atMicros >= 0
|
|
1232
|
+
? hmac(
|
|
1233
|
+
"focused-frame-fence",
|
|
1234
|
+
[frame.atMicros, frame.revision, frame.stateHash].join("\0"),
|
|
1235
|
+
)
|
|
1236
|
+
: null,
|
|
1237
|
+
axes: Object.freeze({ ...axes }),
|
|
1238
|
+
});
|
|
1239
|
+
const fail = (reason, presentation = null, frame = null, axes = emptyAxes()) =>
|
|
1240
|
+
Object.freeze({
|
|
1241
|
+
passed: false,
|
|
1242
|
+
reason,
|
|
1243
|
+
evidence: null,
|
|
1244
|
+
axes: Object.freeze({ ...axes }),
|
|
1245
|
+
candidate: candidateFor(presentation, frame, axes),
|
|
1246
|
+
});
|
|
1247
|
+
if (
|
|
1248
|
+
!Array.isArray(records) ||
|
|
1249
|
+
!TUI_FENCE_TEXT.test(expectedPane ?? "") ||
|
|
1250
|
+
!expectedCanonical ||
|
|
1251
|
+
!GENERATION.test(expectedCanonical.generation ?? "") ||
|
|
1252
|
+
!TUI_FENCE_TEXT.test(expectedCanonical.incarnation ?? "") ||
|
|
1253
|
+
!Number.isSafeInteger(expectedCanonical.revision) ||
|
|
1254
|
+
!CANONICAL_STATE_HASH.test(expectedCanonical.canonicalStateHash ?? "") ||
|
|
1255
|
+
!/^opentui:[1-9]\d*$/u.test(expectedCanonical.processId ?? "") ||
|
|
1256
|
+
expectedCanonical.clockId !== "opentui-performance-now" ||
|
|
1257
|
+
!Number.isSafeInteger(expectedCanonical.cols) ||
|
|
1258
|
+
expectedCanonical.cols < 1 ||
|
|
1259
|
+
!Number.isSafeInteger(expectedCanonical.rows) ||
|
|
1260
|
+
expectedCanonical.rows < 1 ||
|
|
1261
|
+
!HMAC.test(evidenceKey ?? "")
|
|
1262
|
+
)
|
|
1263
|
+
return fail("focus-contract-invalid");
|
|
1264
|
+
const presentations = records.filter(
|
|
1265
|
+
(record) => record?.type === "performance.terminal-cursor-presentation",
|
|
1266
|
+
);
|
|
1267
|
+
if (presentations.length === 0) return fail("focus-presentation-missing");
|
|
1268
|
+
if (presentations.some(({ atMicros }) => !Number.isSafeInteger(atMicros) || atMicros < 0))
|
|
1269
|
+
return fail("focus-presentation-invalid");
|
|
1270
|
+
if (
|
|
1271
|
+
presentations.some(
|
|
1272
|
+
({ atMicros }, index) => index > 0 && atMicros <= presentations[index - 1].atMicros,
|
|
1273
|
+
)
|
|
1274
|
+
)
|
|
1275
|
+
return fail("focus-presentation-ambiguous");
|
|
1276
|
+
const presentation = presentations.at(-1);
|
|
1277
|
+
const authorityEvidence =
|
|
1278
|
+
expectedAuthority === undefined
|
|
1279
|
+
? null
|
|
1280
|
+
: sealCard5TuiFocusAuthority(expectedAuthority, expectedCanonical.generation, evidenceKey);
|
|
1281
|
+
const axes = {
|
|
1282
|
+
pane: presentation.semanticPaneId !== expectedPane,
|
|
1283
|
+
generation: presentation.generation !== expectedCanonical.generation,
|
|
1284
|
+
incarnation: presentation.incarnation !== expectedCanonical.incarnation,
|
|
1285
|
+
revision: presentation.revision !== expectedCanonical.revision,
|
|
1286
|
+
canonicalHash: presentation.stateHash !== expectedCanonical.canonicalStateHash,
|
|
1287
|
+
process: presentation.processId !== expectedCanonical.processId,
|
|
1288
|
+
clock:
|
|
1289
|
+
presentation.clockId !== expectedCanonical.clockId ||
|
|
1290
|
+
presentation.clockKind !== "performance-now",
|
|
1291
|
+
canonicalDimensions:
|
|
1292
|
+
presentation.cols !== expectedCanonical.cols || presentation.rows !== expectedCanonical.rows,
|
|
1293
|
+
viewportDimensions:
|
|
1294
|
+
!Number.isSafeInteger(presentation.viewportCols) ||
|
|
1295
|
+
presentation.viewportCols < 1 ||
|
|
1296
|
+
presentation.viewportCols > 65_535 ||
|
|
1297
|
+
!Number.isSafeInteger(presentation.viewportRows) ||
|
|
1298
|
+
presentation.viewportRows < 1 ||
|
|
1299
|
+
presentation.viewportRows > 65_535,
|
|
1300
|
+
presentationCount:
|
|
1301
|
+
!Number.isSafeInteger(presentation.presentationCount) || presentation.presentationCount < 1,
|
|
1302
|
+
followingFrame: true,
|
|
1303
|
+
frameHealth: true,
|
|
1304
|
+
authority: expectedAuthority !== undefined && authorityEvidence === null,
|
|
1305
|
+
};
|
|
1306
|
+
const presentationOrdinal = records.indexOf(presentation);
|
|
1307
|
+
const frame = records
|
|
1308
|
+
.filter(
|
|
1309
|
+
(record, ordinal) =>
|
|
1310
|
+
ordinal > presentationOrdinal &&
|
|
1311
|
+
record?.type === "performance.terminal-frame-fence" &&
|
|
1312
|
+
record.semanticPaneId === presentation.semanticPaneId &&
|
|
1313
|
+
record.generation === presentation.generation &&
|
|
1314
|
+
record.incarnation === presentation.incarnation &&
|
|
1315
|
+
record.revision === presentation.revision &&
|
|
1316
|
+
record.stateHash === presentation.stateHash &&
|
|
1317
|
+
record.processId === presentation.processId &&
|
|
1318
|
+
record.clockId === presentation.clockId &&
|
|
1319
|
+
record.clockKind === presentation.clockKind &&
|
|
1320
|
+
record.cols === presentation.cols &&
|
|
1321
|
+
record.rows === presentation.rows &&
|
|
1322
|
+
record.viewportCols === presentation.viewportCols &&
|
|
1323
|
+
record.viewportRows === presentation.viewportRows,
|
|
1324
|
+
)
|
|
1325
|
+
.at(-1);
|
|
1326
|
+
axes.followingFrame = frame === undefined;
|
|
1327
|
+
const frameOrdinal = frame === undefined ? -1 : records.indexOf(frame);
|
|
1328
|
+
const laterCursorPresentation = records.some(
|
|
1329
|
+
(record, ordinal) =>
|
|
1330
|
+
ordinal > frameOrdinal && record?.type === "performance.terminal-cursor-presentation",
|
|
1331
|
+
);
|
|
1332
|
+
const laterChangedSamePaneFrame = records.some(
|
|
1333
|
+
(record, ordinal) =>
|
|
1334
|
+
ordinal > frameOrdinal &&
|
|
1335
|
+
record?.type === "performance.terminal-frame-fence" &&
|
|
1336
|
+
record.semanticPaneId === presentation.semanticPaneId,
|
|
1337
|
+
);
|
|
1338
|
+
axes.frameHealth =
|
|
1339
|
+
frame === undefined ||
|
|
1340
|
+
laterCursorPresentation ||
|
|
1341
|
+
laterChangedSamePaneFrame ||
|
|
1342
|
+
!Number.isSafeInteger(frame.atMicros) ||
|
|
1343
|
+
frame.atMicros <= presentation.atMicros ||
|
|
1344
|
+
frame.acceptedRevision !== frame.revision ||
|
|
1345
|
+
frame.identityDrops !== 0 ||
|
|
1346
|
+
frame.writerHealth?.droppedRecords !== 0 ||
|
|
1347
|
+
frame.writerHealth?.oversizedRecords !== 0 ||
|
|
1348
|
+
frame.writerHealth?.failed !== false ||
|
|
1349
|
+
frame.writerHealth?.pendingCriticalRecords !== 0;
|
|
1350
|
+
if (Object.values(axes).some(Boolean))
|
|
1351
|
+
return fail("focus-presentation-mismatch", presentation, frame ?? null, axes);
|
|
1352
|
+
return Object.freeze({
|
|
1353
|
+
passed: true,
|
|
1354
|
+
reason: null,
|
|
1355
|
+
evidence: Object.freeze({
|
|
1356
|
+
paneHmac: hmac("pane", expectedPane),
|
|
1357
|
+
processHmac: hmac("process", expectedCanonical.processId),
|
|
1358
|
+
clockHmac: hmac("clock", expectedCanonical.clockId),
|
|
1359
|
+
authorityHmac: authorityEvidence?.authorityHmac ?? null,
|
|
1360
|
+
authorityOwnerHmac: authorityEvidence?.authorityOwnerHmac ?? null,
|
|
1361
|
+
authorityRevision: authorityEvidence?.authorityRevision ?? null,
|
|
1362
|
+
authorityTopologyHmac: authorityEvidence?.authorityTopologyHmac ?? null,
|
|
1363
|
+
authorityMutationHmac: authorityEvidence?.authorityMutationHmac ?? null,
|
|
1364
|
+
canonicalHmac: hmac(
|
|
1365
|
+
"focused-canonical-identity",
|
|
1366
|
+
[
|
|
1367
|
+
expectedCanonical.generation,
|
|
1368
|
+
expectedCanonical.incarnation,
|
|
1369
|
+
expectedCanonical.revision,
|
|
1370
|
+
expectedCanonical.canonicalStateHash,
|
|
1371
|
+
expectedCanonical.cols,
|
|
1372
|
+
expectedCanonical.rows,
|
|
1373
|
+
].join("\0"),
|
|
1374
|
+
),
|
|
1375
|
+
presentationHmac: hmac(
|
|
1376
|
+
"focused-cursor-presentation",
|
|
1377
|
+
[presentation.atMicros, presentation.presentationCount].join("\0"),
|
|
1378
|
+
),
|
|
1379
|
+
frameHmac: hmac(
|
|
1380
|
+
"focused-frame-fence",
|
|
1381
|
+
[frame.atMicros, frame.revision, frame.stateHash].join("\0"),
|
|
1382
|
+
),
|
|
1383
|
+
focusStateHmac: hmac(
|
|
1384
|
+
"focused-state",
|
|
1385
|
+
[
|
|
1386
|
+
expectedPane,
|
|
1387
|
+
expectedCanonical.processId,
|
|
1388
|
+
expectedCanonical.clockId,
|
|
1389
|
+
expectedCanonical.generation,
|
|
1390
|
+
expectedCanonical.incarnation,
|
|
1391
|
+
frame.revision,
|
|
1392
|
+
frame.stateHash,
|
|
1393
|
+
frame.cols,
|
|
1394
|
+
frame.rows,
|
|
1395
|
+
frame.viewportCols,
|
|
1396
|
+
frame.viewportRows,
|
|
1397
|
+
].join("\0"),
|
|
1398
|
+
),
|
|
1399
|
+
revision: frame.revision,
|
|
1400
|
+
cols: frame.cols,
|
|
1401
|
+
rows: frame.rows,
|
|
1402
|
+
viewportCols: frame.viewportCols,
|
|
1403
|
+
viewportRows: frame.viewportRows,
|
|
1404
|
+
}),
|
|
1405
|
+
axes: Object.freeze({ ...axes }),
|
|
1406
|
+
candidate: candidateFor(presentation, frame, axes),
|
|
1407
|
+
});
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
export function assessCard5TuiRetainedFocus({
|
|
1411
|
+
records,
|
|
1412
|
+
expectedPane,
|
|
1413
|
+
expectedCanonical,
|
|
1414
|
+
acceptedFocusEvidence,
|
|
1415
|
+
expectedDiagnosticEpoch,
|
|
1416
|
+
expectedRendererEpoch,
|
|
1417
|
+
evidenceKey,
|
|
1418
|
+
}) {
|
|
1419
|
+
const hmac = (domain, value) =>
|
|
1420
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
1421
|
+
.update(`${domain}\0${value}`)
|
|
1422
|
+
.digest("hex");
|
|
1423
|
+
const axes = {
|
|
1424
|
+
pane: false,
|
|
1425
|
+
generation: false,
|
|
1426
|
+
incarnation: false,
|
|
1427
|
+
revision: false,
|
|
1428
|
+
canonicalHash: false,
|
|
1429
|
+
process: false,
|
|
1430
|
+
clock: false,
|
|
1431
|
+
canonicalDimensions: false,
|
|
1432
|
+
viewportDimensions: false,
|
|
1433
|
+
presentationCount: false,
|
|
1434
|
+
followingFrame: false,
|
|
1435
|
+
frameHealth: false,
|
|
1436
|
+
authority: false,
|
|
1437
|
+
};
|
|
1438
|
+
const fail = (reason, presentation = null, fence = null) =>
|
|
1439
|
+
Object.freeze({
|
|
1440
|
+
passed: false,
|
|
1441
|
+
reason,
|
|
1442
|
+
evidence: null,
|
|
1443
|
+
axes: Object.freeze({ ...axes }),
|
|
1444
|
+
candidate: Object.freeze({
|
|
1445
|
+
paneHmac:
|
|
1446
|
+
typeof presentation?.semanticPaneId === "string"
|
|
1447
|
+
? hmac("retained-pane-candidate", presentation.semanticPaneId)
|
|
1448
|
+
: null,
|
|
1449
|
+
generationHmac:
|
|
1450
|
+
typeof presentation?.generation === "string"
|
|
1451
|
+
? hmac("retained-generation-candidate", presentation.generation)
|
|
1452
|
+
: null,
|
|
1453
|
+
incarnationHmac:
|
|
1454
|
+
typeof presentation?.incarnation === "string"
|
|
1455
|
+
? hmac("retained-incarnation-candidate", presentation.incarnation)
|
|
1456
|
+
: null,
|
|
1457
|
+
processHmac:
|
|
1458
|
+
typeof presentation?.processId === "string"
|
|
1459
|
+
? hmac("retained-process-candidate", presentation.processId)
|
|
1460
|
+
: null,
|
|
1461
|
+
clockHmac:
|
|
1462
|
+
typeof presentation?.clockId === "string"
|
|
1463
|
+
? hmac("retained-clock-candidate", presentation.clockId)
|
|
1464
|
+
: null,
|
|
1465
|
+
rendererEpoch: boundedInteger(presentation?.rendererEpoch, 0xffff_ffff),
|
|
1466
|
+
rendererEpochHmac:
|
|
1467
|
+
Number.isSafeInteger(presentation?.rendererEpoch) && presentation.rendererEpoch >= 1
|
|
1468
|
+
? hmac("retained-renderer-epoch", String(presentation.rendererEpoch))
|
|
1469
|
+
: null,
|
|
1470
|
+
canonicalHashHmac:
|
|
1471
|
+
typeof presentation?.stateHash === "string"
|
|
1472
|
+
? hmac("retained-canonical-candidate", presentation.stateHash)
|
|
1473
|
+
: null,
|
|
1474
|
+
revision: boundedInteger(presentation?.revision, 0xffff_ffff),
|
|
1475
|
+
cols: boundedInteger(presentation?.cols, 65_535),
|
|
1476
|
+
rows: boundedInteger(presentation?.rows, 65_535),
|
|
1477
|
+
viewportCols: boundedInteger(presentation?.viewportCols, 65_535),
|
|
1478
|
+
viewportRows: boundedInteger(presentation?.viewportRows, 65_535),
|
|
1479
|
+
presentationCount: boundedInteger(presentation?.presentationCount, 0xffff_ffff),
|
|
1480
|
+
presentationHmac:
|
|
1481
|
+
Number.isSafeInteger(presentation?.atMicros) && presentation.atMicros >= 0
|
|
1482
|
+
? hmac(
|
|
1483
|
+
"retained-cursor-presentation",
|
|
1484
|
+
`${presentation.atMicros}\0${presentation.presentationCount}`,
|
|
1485
|
+
)
|
|
1486
|
+
: null,
|
|
1487
|
+
frameHmac:
|
|
1488
|
+
Number.isSafeInteger(fence?.atMicros) && fence.atMicros >= 0
|
|
1489
|
+
? hmac(
|
|
1490
|
+
"retained-focus-fence",
|
|
1491
|
+
`${fence.atMicros}\0${fence.diagnosticEpoch}\0${fence.revision}\0${fence.stateHash}`,
|
|
1492
|
+
)
|
|
1493
|
+
: null,
|
|
1494
|
+
axes: Object.freeze({ ...axes }),
|
|
1495
|
+
}),
|
|
1496
|
+
});
|
|
1497
|
+
if (
|
|
1498
|
+
!Array.isArray(records) ||
|
|
1499
|
+
!TUI_FENCE_TEXT.test(expectedPane ?? "") ||
|
|
1500
|
+
!expectedCanonical ||
|
|
1501
|
+
!GENERATION.test(expectedCanonical.generation ?? "") ||
|
|
1502
|
+
!TUI_FENCE_TEXT.test(expectedCanonical.incarnation ?? "") ||
|
|
1503
|
+
!Number.isSafeInteger(expectedCanonical.revision) ||
|
|
1504
|
+
!CANONICAL_STATE_HASH.test(expectedCanonical.canonicalStateHash ?? "") ||
|
|
1505
|
+
!/^opentui:[1-9]\d*$/u.test(expectedCanonical.processId ?? "") ||
|
|
1506
|
+
expectedCanonical.clockId !== "opentui-performance-now" ||
|
|
1507
|
+
!Number.isSafeInteger(expectedDiagnosticEpoch) ||
|
|
1508
|
+
expectedDiagnosticEpoch < 1 ||
|
|
1509
|
+
!Number.isSafeInteger(expectedRendererEpoch) ||
|
|
1510
|
+
expectedRendererEpoch < 1 ||
|
|
1511
|
+
!HMAC.test(evidenceKey ?? "") ||
|
|
1512
|
+
!HMAC.test(acceptedFocusEvidence?.focusStateHmac ?? "")
|
|
1513
|
+
) {
|
|
1514
|
+
Object.keys(axes).forEach((key) => (axes[key] = true));
|
|
1515
|
+
return fail("focus-contract-invalid");
|
|
1516
|
+
}
|
|
1517
|
+
const presentations = records.filter(
|
|
1518
|
+
(record) => record?.type === "performance.terminal-cursor-presentation",
|
|
1519
|
+
);
|
|
1520
|
+
if (presentations.length === 0) {
|
|
1521
|
+
axes.presentationCount = true;
|
|
1522
|
+
axes.followingFrame = true;
|
|
1523
|
+
return fail("focus-presentation-missing");
|
|
1524
|
+
}
|
|
1525
|
+
if (
|
|
1526
|
+
presentations.some(
|
|
1527
|
+
({ atMicros }, index) =>
|
|
1528
|
+
!Number.isSafeInteger(atMicros) ||
|
|
1529
|
+
atMicros < 0 ||
|
|
1530
|
+
(index > 0 && atMicros <= presentations[index - 1].atMicros),
|
|
1531
|
+
)
|
|
1532
|
+
) {
|
|
1533
|
+
axes.presentationCount = true;
|
|
1534
|
+
return fail("focus-presentation-ambiguous", presentations.at(-1));
|
|
1535
|
+
}
|
|
1536
|
+
const presentation = presentations.at(-1);
|
|
1537
|
+
axes.pane = presentation.semanticPaneId !== expectedPane;
|
|
1538
|
+
axes.generation = presentation.generation !== expectedCanonical.generation;
|
|
1539
|
+
axes.incarnation = presentation.incarnation !== expectedCanonical.incarnation;
|
|
1540
|
+
axes.revision = presentation.revision !== expectedCanonical.revision;
|
|
1541
|
+
axes.canonicalHash = presentation.stateHash !== expectedCanonical.canonicalStateHash;
|
|
1542
|
+
axes.process = presentation.processId !== expectedCanonical.processId;
|
|
1543
|
+
axes.clock =
|
|
1544
|
+
presentation.clockId !== expectedCanonical.clockId ||
|
|
1545
|
+
presentation.clockKind !== "performance-now";
|
|
1546
|
+
axes.authority =
|
|
1547
|
+
!Number.isSafeInteger(presentation.rendererEpoch) ||
|
|
1548
|
+
presentation.rendererEpoch < 1 ||
|
|
1549
|
+
presentation.rendererEpoch !== expectedRendererEpoch;
|
|
1550
|
+
axes.canonicalDimensions =
|
|
1551
|
+
presentation.cols !== acceptedFocusEvidence.cols ||
|
|
1552
|
+
presentation.rows !== acceptedFocusEvidence.rows;
|
|
1553
|
+
axes.viewportDimensions =
|
|
1554
|
+
presentation.viewportCols !== acceptedFocusEvidence.viewportCols ||
|
|
1555
|
+
presentation.viewportRows !== acceptedFocusEvidence.viewportRows;
|
|
1556
|
+
axes.presentationCount =
|
|
1557
|
+
!Number.isSafeInteger(presentation.presentationCount) || presentation.presentationCount < 1;
|
|
1558
|
+
const presentationOrdinal = records.indexOf(presentation);
|
|
1559
|
+
const fences = records.filter(
|
|
1560
|
+
(record, ordinal) =>
|
|
1561
|
+
ordinal > presentationOrdinal &&
|
|
1562
|
+
record?.type === "performance.terminal-focus-fence" &&
|
|
1563
|
+
record.diagnosticEpoch === expectedDiagnosticEpoch &&
|
|
1564
|
+
record.focused === true &&
|
|
1565
|
+
record.rendererEpoch === expectedRendererEpoch &&
|
|
1566
|
+
record.semanticPaneId === presentation.semanticPaneId &&
|
|
1567
|
+
record.processId === presentation.processId &&
|
|
1568
|
+
record.clockId === presentation.clockId &&
|
|
1569
|
+
record.clockKind === presentation.clockKind &&
|
|
1570
|
+
record.generation === presentation.generation &&
|
|
1571
|
+
record.incarnation === presentation.incarnation &&
|
|
1572
|
+
record.revision === presentation.revision &&
|
|
1573
|
+
record.stateHash === presentation.stateHash &&
|
|
1574
|
+
record.cols === presentation.cols &&
|
|
1575
|
+
record.rows === presentation.rows &&
|
|
1576
|
+
record.viewportCols === presentation.viewportCols &&
|
|
1577
|
+
record.viewportRows === presentation.viewportRows &&
|
|
1578
|
+
record.sourceEpoch === presentation.sourceEpoch,
|
|
1579
|
+
);
|
|
1580
|
+
const fence = fences.length === 1 ? fences[0] : undefined;
|
|
1581
|
+
axes.followingFrame = fence === undefined;
|
|
1582
|
+
const changedCanonical = records.some(
|
|
1583
|
+
(record) =>
|
|
1584
|
+
record?.semanticPaneId === expectedPane &&
|
|
1585
|
+
((record.type === "performance.terminal-canonical-update" &&
|
|
1586
|
+
(record.revision !== expectedCanonical.revision ||
|
|
1587
|
+
record.stateHash !== expectedCanonical.canonicalStateHash)) ||
|
|
1588
|
+
(record.type === "performance.terminal-frame-fence" &&
|
|
1589
|
+
(record.revision !== expectedCanonical.revision ||
|
|
1590
|
+
record.stateHash !== expectedCanonical.canonicalStateHash ||
|
|
1591
|
+
record.cols !== acceptedFocusEvidence.cols ||
|
|
1592
|
+
record.rows !== acceptedFocusEvidence.rows ||
|
|
1593
|
+
record.viewportCols !== acceptedFocusEvidence.viewportCols ||
|
|
1594
|
+
record.viewportRows !== acceptedFocusEvidence.viewportRows))),
|
|
1595
|
+
);
|
|
1596
|
+
const focusStateHmac = hmac(
|
|
1597
|
+
"focused-state",
|
|
1598
|
+
[
|
|
1599
|
+
expectedPane,
|
|
1600
|
+
expectedCanonical.processId,
|
|
1601
|
+
expectedCanonical.clockId,
|
|
1602
|
+
expectedCanonical.generation,
|
|
1603
|
+
expectedCanonical.incarnation,
|
|
1604
|
+
presentation.revision,
|
|
1605
|
+
presentation.stateHash,
|
|
1606
|
+
presentation.cols,
|
|
1607
|
+
presentation.rows,
|
|
1608
|
+
presentation.viewportCols,
|
|
1609
|
+
presentation.viewportRows,
|
|
1610
|
+
].join("\0"),
|
|
1611
|
+
);
|
|
1612
|
+
axes.frameHealth =
|
|
1613
|
+
fence === undefined ||
|
|
1614
|
+
fences.length !== 1 ||
|
|
1615
|
+
!Number.isSafeInteger(presentation.sourceEpoch) ||
|
|
1616
|
+
presentation.sourceEpoch < 0 ||
|
|
1617
|
+
!Number.isSafeInteger(fence.atMicros) ||
|
|
1618
|
+
fence.atMicros <= presentation.atMicros ||
|
|
1619
|
+
fence.writerHealth?.droppedRecords !== 0 ||
|
|
1620
|
+
fence.writerHealth?.oversizedRecords !== 0 ||
|
|
1621
|
+
fence.writerHealth?.failed !== false ||
|
|
1622
|
+
fence.writerHealth?.pendingCriticalRecords !== 0 ||
|
|
1623
|
+
changedCanonical ||
|
|
1624
|
+
focusStateHmac !== acceptedFocusEvidence.focusStateHmac;
|
|
1625
|
+
if (Object.values(axes).some(Boolean))
|
|
1626
|
+
return fail("focus-presentation-mismatch", presentation, fence ?? null);
|
|
1627
|
+
return Object.freeze({
|
|
1628
|
+
passed: true,
|
|
1629
|
+
reason: null,
|
|
1630
|
+
axes: Object.freeze({ ...axes }),
|
|
1631
|
+
candidate: fail("focus-presentation-mismatch", presentation, fence).candidate,
|
|
1632
|
+
evidence: Object.freeze({
|
|
1633
|
+
...acceptedFocusEvidence,
|
|
1634
|
+
presentationHmac: hmac(
|
|
1635
|
+
"retained-cursor-presentation",
|
|
1636
|
+
`${presentation.atMicros}\0${presentation.presentationCount}`,
|
|
1637
|
+
),
|
|
1638
|
+
focusFenceHmac: hmac(
|
|
1639
|
+
"retained-focus-fence",
|
|
1640
|
+
`${fence.atMicros}\0${fence.diagnosticEpoch}\0${fence.revision}\0${fence.stateHash}`,
|
|
1641
|
+
),
|
|
1642
|
+
rendererEpoch: presentation.rendererEpoch,
|
|
1643
|
+
rendererEpochHmac: hmac("retained-renderer-epoch", String(presentation.rendererEpoch)),
|
|
1644
|
+
focusStateHmac,
|
|
1645
|
+
}),
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
export function hasExactCard5TuiFocusAuthority(authority, generation) {
|
|
1650
|
+
return sealCard5TuiFocusAuthority(authority, generation, "0".repeat(64)) !== null;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
export function assessCard5TuiFocusAuthority(
|
|
1654
|
+
authority,
|
|
1655
|
+
generation,
|
|
1656
|
+
evidenceKey,
|
|
1657
|
+
authorityRecords = [],
|
|
1658
|
+
) {
|
|
1659
|
+
const exactKeys = (value, keys) =>
|
|
1660
|
+
value !== null &&
|
|
1661
|
+
typeof value === "object" &&
|
|
1662
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
|
1663
|
+
const validClientId = (value) =>
|
|
1664
|
+
typeof value === "string" &&
|
|
1665
|
+
value.length >= 1 &&
|
|
1666
|
+
value.length <= 4_096 &&
|
|
1667
|
+
!/[\0\r\n]/u.test(value);
|
|
1668
|
+
const clients = Array.isArray(authority?.clients) ? authority.clients : [];
|
|
1669
|
+
const clientSchemaInvalid = clients.some(
|
|
1670
|
+
(client) =>
|
|
1671
|
+
!exactKeys(client, [
|
|
1672
|
+
"clientId",
|
|
1673
|
+
"surface",
|
|
1674
|
+
"state",
|
|
1675
|
+
"connectedRevision",
|
|
1676
|
+
"activityRevision",
|
|
1677
|
+
]) ||
|
|
1678
|
+
!validClientId(client?.clientId) ||
|
|
1679
|
+
!["web", "opentui", "cli", "sdk", "native-tmux", "unknown"].includes(client?.surface) ||
|
|
1680
|
+
!["foreground", "background"].includes(client?.state) ||
|
|
1681
|
+
!Number.isSafeInteger(client?.connectedRevision) ||
|
|
1682
|
+
client.connectedRevision < 1 ||
|
|
1683
|
+
!Number.isSafeInteger(client?.activityRevision) ||
|
|
1684
|
+
client.activityRevision < 0,
|
|
1685
|
+
);
|
|
1686
|
+
const duplicateClients =
|
|
1687
|
+
clients.length > 0 && new Set(clients.map(({ clientId }) => clientId)).size !== clients.length;
|
|
1688
|
+
const opentui = clients.filter(({ surface }) => surface === "opentui");
|
|
1689
|
+
const web = clients.filter(({ surface }) => surface === "web");
|
|
1690
|
+
const axes = Object.freeze({
|
|
1691
|
+
generation: !GENERATION.test(generation ?? "") || authority?.generation !== generation,
|
|
1692
|
+
session: !GENERATION.test(authority?.session ?? ""),
|
|
1693
|
+
revision: !Number.isSafeInteger(authority?.revision) || authority.revision < 0,
|
|
1694
|
+
nativeYield:
|
|
1695
|
+
!Number.isSafeInteger(authority?.nativeGeometryYieldUntilMs) ||
|
|
1696
|
+
authority.nativeGeometryYieldUntilMs < 0,
|
|
1697
|
+
authorityKeys: !exactKeys(authority, [
|
|
1698
|
+
"generation",
|
|
1699
|
+
"session",
|
|
1700
|
+
"revision",
|
|
1701
|
+
"owners",
|
|
1702
|
+
"nativeGeometryYieldUntilMs",
|
|
1703
|
+
"clients",
|
|
1704
|
+
]),
|
|
1705
|
+
ownerKeys: !exactKeys(authority?.owners, ["input", "focus", "geometry"]),
|
|
1706
|
+
clientCount: clients.length !== 3,
|
|
1707
|
+
clientSchema: clientSchemaInvalid,
|
|
1708
|
+
surfaceCardinality: opentui.length !== 1 || web.length !== 2,
|
|
1709
|
+
duplicateClients,
|
|
1710
|
+
inputOwner: opentui.length !== 1 || authority?.owners?.input !== opentui[0]?.clientId,
|
|
1711
|
+
focusOwner: opentui.length !== 1 || authority?.owners?.focus !== opentui[0]?.clientId,
|
|
1712
|
+
});
|
|
1713
|
+
const reasons = [
|
|
1714
|
+
["generation-mismatch", axes.generation],
|
|
1715
|
+
["session-invalid", axes.session],
|
|
1716
|
+
["revision-invalid", axes.revision],
|
|
1717
|
+
["native-yield-invalid", axes.nativeYield],
|
|
1718
|
+
["authority-keys-invalid", axes.authorityKeys],
|
|
1719
|
+
["owner-keys-invalid", axes.ownerKeys],
|
|
1720
|
+
["client-count-invalid", axes.clientCount],
|
|
1721
|
+
["client-schema-invalid", axes.clientSchema],
|
|
1722
|
+
["surface-cardinality-invalid", axes.surfaceCardinality],
|
|
1723
|
+
["duplicate-client", axes.duplicateClients],
|
|
1724
|
+
["input-owner-invalid", axes.inputOwner],
|
|
1725
|
+
["focus-owner-invalid", axes.focusOwner],
|
|
1726
|
+
];
|
|
1727
|
+
const reason = reasons.find(([, failed]) => failed)?.[0] ?? null;
|
|
1728
|
+
const hmac = (domain, value) =>
|
|
1729
|
+
HMAC.test(evidenceKey ?? "")
|
|
1730
|
+
? createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
1731
|
+
.update(`${domain}\0${value}`)
|
|
1732
|
+
.digest("hex")
|
|
1733
|
+
: null;
|
|
1734
|
+
const boundedRecords = Array.isArray(authorityRecords) ? authorityRecords.slice(-2) : [];
|
|
1735
|
+
const recordTransitions = boundedRecords.map((record) => {
|
|
1736
|
+
const recordClients = Array.isArray(record?.clients) ? record.clients : [];
|
|
1737
|
+
return Object.freeze({
|
|
1738
|
+
ordinal: boundedInteger(record?.ordinal, 0xffff_ffff),
|
|
1739
|
+
revision: boundedInteger(record?.revision, 0xffff_ffff),
|
|
1740
|
+
clientCount: Math.min(recordClients.length, 8),
|
|
1741
|
+
ownerHmac: hmac(
|
|
1742
|
+
"authority-record-owner",
|
|
1743
|
+
[record?.inputOwner, record?.focusOwner, record?.geometryOwner].join("\0"),
|
|
1744
|
+
),
|
|
1745
|
+
topologyHmac: hmac(
|
|
1746
|
+
"authority-record-topology",
|
|
1747
|
+
JSON.stringify(
|
|
1748
|
+
recordClients
|
|
1749
|
+
.map((client) => ({
|
|
1750
|
+
clientId: client?.clientId,
|
|
1751
|
+
surface: client?.surface,
|
|
1752
|
+
state: client?.state,
|
|
1753
|
+
connectedRevision: client?.connectedRevision,
|
|
1754
|
+
}))
|
|
1755
|
+
.sort((left, right) => String(left.clientId).localeCompare(String(right.clientId))),
|
|
1756
|
+
),
|
|
1757
|
+
),
|
|
1758
|
+
});
|
|
1759
|
+
});
|
|
1760
|
+
return Object.freeze({
|
|
1761
|
+
valid: reason === null,
|
|
1762
|
+
reason,
|
|
1763
|
+
axes,
|
|
1764
|
+
counts: Object.freeze({
|
|
1765
|
+
clients: Math.min(clients.length, 8),
|
|
1766
|
+
web: Math.min(web.length, 8),
|
|
1767
|
+
opentui: Math.min(opentui.length, 8),
|
|
1768
|
+
}),
|
|
1769
|
+
ownerHmac: hmac(
|
|
1770
|
+
"authority-assessment-owner",
|
|
1771
|
+
[authority?.owners?.input, authority?.owners?.focus, authority?.owners?.geometry].join("\0"),
|
|
1772
|
+
),
|
|
1773
|
+
clientsHmac: hmac(
|
|
1774
|
+
"authority-assessment-clients",
|
|
1775
|
+
JSON.stringify(
|
|
1776
|
+
clients
|
|
1777
|
+
.map((client) => ({
|
|
1778
|
+
clientId: client?.clientId,
|
|
1779
|
+
surface: client?.surface,
|
|
1780
|
+
state: client?.state,
|
|
1781
|
+
connectedRevision: client?.connectedRevision,
|
|
1782
|
+
}))
|
|
1783
|
+
.sort((left, right) => String(left.clientId).localeCompare(String(right.clientId))),
|
|
1784
|
+
),
|
|
1785
|
+
),
|
|
1786
|
+
recordTransitions: Object.freeze(recordTransitions),
|
|
1787
|
+
evidence:
|
|
1788
|
+
reason === null ? sealCard5TuiFocusAuthority(authority, generation, evidenceKey) : null,
|
|
1789
|
+
});
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
/** Exact, bounded and opaque authority topology used by Card5 focus proofs. */
|
|
1793
|
+
export function sealCard5TuiFocusAuthority(authority, generation, evidenceKey) {
|
|
1794
|
+
const exactKeys = (value, keys) =>
|
|
1795
|
+
value !== null &&
|
|
1796
|
+
typeof value === "object" &&
|
|
1797
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
|
1798
|
+
if (
|
|
1799
|
+
!GENERATION.test(generation ?? "") ||
|
|
1800
|
+
authority?.generation !== generation ||
|
|
1801
|
+
!HMAC.test(evidenceKey ?? "") ||
|
|
1802
|
+
!GENERATION.test(authority?.session ?? "") ||
|
|
1803
|
+
!Number.isSafeInteger(authority?.revision) ||
|
|
1804
|
+
authority.revision < 0 ||
|
|
1805
|
+
!Number.isSafeInteger(authority?.nativeGeometryYieldUntilMs) ||
|
|
1806
|
+
authority.nativeGeometryYieldUntilMs < 0 ||
|
|
1807
|
+
!Array.isArray(authority?.clients) ||
|
|
1808
|
+
authority.clients.length !== 3 ||
|
|
1809
|
+
!exactKeys(authority, [
|
|
1810
|
+
"generation",
|
|
1811
|
+
"session",
|
|
1812
|
+
"revision",
|
|
1813
|
+
"owners",
|
|
1814
|
+
"nativeGeometryYieldUntilMs",
|
|
1815
|
+
"clients",
|
|
1816
|
+
]) ||
|
|
1817
|
+
!exactKeys(authority.owners, ["input", "focus", "geometry"]) ||
|
|
1818
|
+
authority.clients.some(
|
|
1819
|
+
(client) =>
|
|
1820
|
+
!exactKeys(client, [
|
|
1821
|
+
"clientId",
|
|
1822
|
+
"surface",
|
|
1823
|
+
"state",
|
|
1824
|
+
"connectedRevision",
|
|
1825
|
+
"activityRevision",
|
|
1826
|
+
]),
|
|
1827
|
+
)
|
|
1828
|
+
)
|
|
1829
|
+
return null;
|
|
1830
|
+
const ownerValues = [
|
|
1831
|
+
authority.owners?.input,
|
|
1832
|
+
authority.owners?.focus,
|
|
1833
|
+
authority.owners?.geometry,
|
|
1834
|
+
];
|
|
1835
|
+
const validClientId = (value) =>
|
|
1836
|
+
typeof value === "string" &&
|
|
1837
|
+
value.length >= 1 &&
|
|
1838
|
+
value.length <= 4_096 &&
|
|
1839
|
+
!/[\0\r\n]/u.test(value);
|
|
1840
|
+
if (ownerValues.some((owner) => owner !== null && !validClientId(owner))) return null;
|
|
1841
|
+
const clients = authority.clients.map((client) => ({
|
|
1842
|
+
clientId: client?.clientId,
|
|
1843
|
+
surface: client?.surface,
|
|
1844
|
+
state: client?.state,
|
|
1845
|
+
connectedRevision: client?.connectedRevision,
|
|
1846
|
+
activityRevision: client?.activityRevision,
|
|
1847
|
+
}));
|
|
1848
|
+
if (
|
|
1849
|
+
clients.some(
|
|
1850
|
+
(client) =>
|
|
1851
|
+
!validClientId(client.clientId) ||
|
|
1852
|
+
!["web", "opentui", "cli", "sdk", "native-tmux", "unknown"].includes(client.surface) ||
|
|
1853
|
+
!["foreground", "background"].includes(client.state) ||
|
|
1854
|
+
!Number.isSafeInteger(client.connectedRevision) ||
|
|
1855
|
+
client.connectedRevision < 1 ||
|
|
1856
|
+
!Number.isSafeInteger(client.activityRevision) ||
|
|
1857
|
+
client.activityRevision < 0,
|
|
1858
|
+
) ||
|
|
1859
|
+
new Set(clients.map(({ clientId }) => clientId)).size !== clients.length
|
|
1860
|
+
)
|
|
1861
|
+
return null;
|
|
1862
|
+
const opentui = clients.filter(({ surface }) => surface === "opentui");
|
|
1863
|
+
if (
|
|
1864
|
+
opentui.length !== 1 ||
|
|
1865
|
+
clients.filter(({ surface }) => surface === "web").length !== 2 ||
|
|
1866
|
+
authority.owners.input !== opentui[0].clientId ||
|
|
1867
|
+
authority.owners.focus !== opentui[0].clientId
|
|
1868
|
+
)
|
|
1869
|
+
return null;
|
|
1870
|
+
const sortedClients = [...clients].sort((left, right) =>
|
|
1871
|
+
left.clientId.localeCompare(right.clientId),
|
|
1872
|
+
);
|
|
1873
|
+
const semanticTopology = JSON.stringify({
|
|
1874
|
+
generation: authority.generation,
|
|
1875
|
+
session: authority.session,
|
|
1876
|
+
owners: authority.owners,
|
|
1877
|
+
nativeGeometryYieldUntilMs: authority.nativeGeometryYieldUntilMs,
|
|
1878
|
+
clients: sortedClients.map(({ clientId, surface, state, connectedRevision }) => ({
|
|
1879
|
+
clientId,
|
|
1880
|
+
surface,
|
|
1881
|
+
state,
|
|
1882
|
+
connectedRevision,
|
|
1883
|
+
})),
|
|
1884
|
+
});
|
|
1885
|
+
const activityTopology = JSON.stringify({
|
|
1886
|
+
revision: authority.revision,
|
|
1887
|
+
clients: sortedClients.map(({ clientId, surface, activityRevision }) => ({
|
|
1888
|
+
clientId,
|
|
1889
|
+
surface,
|
|
1890
|
+
activityRevision,
|
|
1891
|
+
})),
|
|
1892
|
+
});
|
|
1893
|
+
const hmac = (domain, value) =>
|
|
1894
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
1895
|
+
.update(`${domain}\0${value}`)
|
|
1896
|
+
.digest("hex");
|
|
1897
|
+
return Object.freeze({
|
|
1898
|
+
authorityRevision: authority.revision,
|
|
1899
|
+
authorityOwnerHmac: hmac("focused-authority-owner", opentui[0].clientId),
|
|
1900
|
+
authorityTopologyHmac: hmac("focused-authority-topology", semanticTopology),
|
|
1901
|
+
authorityHmac: hmac("focused-authority", semanticTopology),
|
|
1902
|
+
authorityMutationHmac: hmac("focused-authority-mutation", activityTopology),
|
|
1903
|
+
});
|
|
1904
|
+
}
|
|
1905
|
+
|
|
1906
|
+
/** Validate current authority as a causal continuation of one completed handoff. */
|
|
1907
|
+
export function assessCard5PostHandoffAuthority({
|
|
1908
|
+
authority,
|
|
1909
|
+
authorityRecords,
|
|
1910
|
+
generation,
|
|
1911
|
+
expectedClientId,
|
|
1912
|
+
expectedSurface,
|
|
1913
|
+
grantRevision,
|
|
1914
|
+
inputProofHmac,
|
|
1915
|
+
evidenceKey,
|
|
1916
|
+
}) {
|
|
1917
|
+
const exactKeys = (value, keys) =>
|
|
1918
|
+
value !== null &&
|
|
1919
|
+
typeof value === "object" &&
|
|
1920
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
|
1921
|
+
const validClientId = (value) =>
|
|
1922
|
+
typeof value === "string" &&
|
|
1923
|
+
value.length >= 1 &&
|
|
1924
|
+
value.length <= 4_096 &&
|
|
1925
|
+
!/[\0\r\n]/u.test(value);
|
|
1926
|
+
const clients = Array.isArray(authority?.clients) ? authority.clients : [];
|
|
1927
|
+
const validAuthority =
|
|
1928
|
+
GENERATION.test(generation ?? "") &&
|
|
1929
|
+
authority?.generation === generation &&
|
|
1930
|
+
GENERATION.test(authority?.session ?? "") &&
|
|
1931
|
+
HMAC.test(evidenceKey ?? "") &&
|
|
1932
|
+
HMAC.test(inputProofHmac ?? "") &&
|
|
1933
|
+
Number.isSafeInteger(grantRevision) &&
|
|
1934
|
+
grantRevision >= 0 &&
|
|
1935
|
+
Number.isSafeInteger(authority?.revision) &&
|
|
1936
|
+
authority.revision >= grantRevision &&
|
|
1937
|
+
Number.isSafeInteger(authority?.nativeGeometryYieldUntilMs) &&
|
|
1938
|
+
authority.nativeGeometryYieldUntilMs >= 0 &&
|
|
1939
|
+
exactKeys(authority, [
|
|
1940
|
+
"generation",
|
|
1941
|
+
"session",
|
|
1942
|
+
"revision",
|
|
1943
|
+
"owners",
|
|
1944
|
+
"nativeGeometryYieldUntilMs",
|
|
1945
|
+
"clients",
|
|
1946
|
+
]) &&
|
|
1947
|
+
exactKeys(authority?.owners, ["input", "focus", "geometry"]) &&
|
|
1948
|
+
clients.length === 3 &&
|
|
1949
|
+
clients.every(
|
|
1950
|
+
(client) =>
|
|
1951
|
+
exactKeys(client, [
|
|
1952
|
+
"clientId",
|
|
1953
|
+
"surface",
|
|
1954
|
+
"state",
|
|
1955
|
+
"connectedRevision",
|
|
1956
|
+
"activityRevision",
|
|
1957
|
+
]) &&
|
|
1958
|
+
validClientId(client.clientId) &&
|
|
1959
|
+
["web", "opentui"].includes(client.surface) &&
|
|
1960
|
+
["foreground", "background"].includes(client.state) &&
|
|
1961
|
+
Number.isSafeInteger(client.connectedRevision) &&
|
|
1962
|
+
client.connectedRevision >= 1 &&
|
|
1963
|
+
Number.isSafeInteger(client.activityRevision) &&
|
|
1964
|
+
client.activityRevision >= 0,
|
|
1965
|
+
) &&
|
|
1966
|
+
new Set(clients.map(({ clientId }) => clientId)).size === 3 &&
|
|
1967
|
+
clients.filter(({ surface }) => surface === "web").length === 2 &&
|
|
1968
|
+
clients.filter(({ surface }) => surface === "opentui").length === 1 &&
|
|
1969
|
+
validClientId(expectedClientId) &&
|
|
1970
|
+
["web", "opentui"].includes(expectedSurface) &&
|
|
1971
|
+
clients.filter(
|
|
1972
|
+
({ clientId, surface }) => clientId === expectedClientId && surface === expectedSurface,
|
|
1973
|
+
).length === 1;
|
|
1974
|
+
if (!validAuthority)
|
|
1975
|
+
return Object.freeze({ valid: false, reason: "post-handoff-contract-invalid", evidence: null });
|
|
1976
|
+
const records = Array.isArray(authorityRecords) ? authorityRecords : [];
|
|
1977
|
+
const recordClientExact = (client) =>
|
|
1978
|
+
exactKeys(client, ["clientId", "surface", "state", "connectedRevision", "activityRevision"]) &&
|
|
1979
|
+
validClientId(client.clientId) &&
|
|
1980
|
+
["web", "opentui"].includes(client.surface) &&
|
|
1981
|
+
["foreground", "background"].includes(client.state) &&
|
|
1982
|
+
Number.isSafeInteger(client.connectedRevision) &&
|
|
1983
|
+
client.connectedRevision >= 1 &&
|
|
1984
|
+
Number.isSafeInteger(client.activityRevision) &&
|
|
1985
|
+
client.activityRevision >= 0;
|
|
1986
|
+
const recordTopologyExact = (record) =>
|
|
1987
|
+
exactKeys(record, [
|
|
1988
|
+
"ordinal",
|
|
1989
|
+
"generation",
|
|
1990
|
+
"session",
|
|
1991
|
+
"revision",
|
|
1992
|
+
"nativeGeometryYieldUntilMs",
|
|
1993
|
+
"inputOwner",
|
|
1994
|
+
"focusOwner",
|
|
1995
|
+
"geometryOwner",
|
|
1996
|
+
"clients",
|
|
1997
|
+
]) &&
|
|
1998
|
+
Number.isSafeInteger(record.ordinal) &&
|
|
1999
|
+
record.ordinal >= 1 &&
|
|
2000
|
+
record.generation === authority.generation &&
|
|
2001
|
+
record.session === authority.session &&
|
|
2002
|
+
Number.isSafeInteger(record.revision) &&
|
|
2003
|
+
record.revision >= grantRevision &&
|
|
2004
|
+
record.revision <= authority.revision &&
|
|
2005
|
+
Number.isSafeInteger(record.nativeGeometryYieldUntilMs) &&
|
|
2006
|
+
record.nativeGeometryYieldUntilMs >= 0 &&
|
|
2007
|
+
Array.isArray(record.clients) &&
|
|
2008
|
+
record.clients.length === clients.length &&
|
|
2009
|
+
record.clients.every(recordClientExact) &&
|
|
2010
|
+
new Set(record.clients.map(({ clientId }) => clientId)).size === clients.length &&
|
|
2011
|
+
record.clients.every((recordClient) => {
|
|
2012
|
+
const current = clients.find(({ clientId }) => clientId === recordClient.clientId);
|
|
2013
|
+
return (
|
|
2014
|
+
current !== undefined &&
|
|
2015
|
+
recordClient.surface === current.surface &&
|
|
2016
|
+
recordClient.connectedRevision === current.connectedRevision
|
|
2017
|
+
);
|
|
2018
|
+
});
|
|
2019
|
+
const firstSelectedIndex = records.findIndex(
|
|
2020
|
+
(record) => Number.isSafeInteger(record?.revision) && record.revision >= grantRevision,
|
|
2021
|
+
);
|
|
2022
|
+
const rawSequence = firstSelectedIndex < 0 ? [] : records.slice(firstSelectedIndex);
|
|
2023
|
+
const normalizeRecord = (record) =>
|
|
2024
|
+
JSON.stringify({
|
|
2025
|
+
generation: record.generation,
|
|
2026
|
+
session: record.session,
|
|
2027
|
+
revision: record.revision,
|
|
2028
|
+
nativeGeometryYieldUntilMs: record.nativeGeometryYieldUntilMs,
|
|
2029
|
+
owners: [record.inputOwner, record.focusOwner, record.geometryOwner],
|
|
2030
|
+
clients: [...record.clients].sort((left, right) =>
|
|
2031
|
+
left.clientId.localeCompare(right.clientId),
|
|
2032
|
+
),
|
|
2033
|
+
});
|
|
2034
|
+
const rawSequenceExact =
|
|
2035
|
+
rawSequence.length > 0 &&
|
|
2036
|
+
rawSequence.every(recordTopologyExact) &&
|
|
2037
|
+
rawSequence.every(
|
|
2038
|
+
(record, index) =>
|
|
2039
|
+
index === 0 ||
|
|
2040
|
+
(record.ordinal === rawSequence[index - 1].ordinal + 1 &&
|
|
2041
|
+
record.revision >= rawSequence[index - 1].revision),
|
|
2042
|
+
);
|
|
2043
|
+
if (!rawSequenceExact)
|
|
2044
|
+
return Object.freeze({
|
|
2045
|
+
valid: false,
|
|
2046
|
+
reason: "post-handoff-contract-invalid",
|
|
2047
|
+
evidence: null,
|
|
2048
|
+
});
|
|
2049
|
+
const sequence = [];
|
|
2050
|
+
const duplicateOrdinals = [];
|
|
2051
|
+
let duplicateConflict = false;
|
|
2052
|
+
for (const record of rawSequence) {
|
|
2053
|
+
const previous = sequence.at(-1);
|
|
2054
|
+
if (previous?.revision === record.revision) {
|
|
2055
|
+
if (normalizeRecord(previous) !== normalizeRecord(record)) duplicateConflict = true;
|
|
2056
|
+
else duplicateOrdinals.push(record.ordinal);
|
|
2057
|
+
} else {
|
|
2058
|
+
sequence.push(record);
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
const strictSequence =
|
|
2062
|
+
rawSequenceExact &&
|
|
2063
|
+
!duplicateConflict &&
|
|
2064
|
+
duplicateOrdinals.length <= 8 &&
|
|
2065
|
+
sequence.every(
|
|
2066
|
+
(record, index) => index === 0 || record.revision > sequence[index - 1].revision,
|
|
2067
|
+
) &&
|
|
2068
|
+
sequence.at(-1)?.revision === authority.revision;
|
|
2069
|
+
const grants = sequence.filter(
|
|
2070
|
+
(record) => record.revision === grantRevision && record.inputOwner === expectedClientId,
|
|
2071
|
+
);
|
|
2072
|
+
const grant = grants[0];
|
|
2073
|
+
if (
|
|
2074
|
+
!strictSequence ||
|
|
2075
|
+
grants.length !== 1 ||
|
|
2076
|
+
sequence[0] !== grant ||
|
|
2077
|
+
!grant.clients.some(
|
|
2078
|
+
({ clientId, surface, state }) =>
|
|
2079
|
+
clientId === expectedClientId && surface === expectedSurface && state === "foreground",
|
|
2080
|
+
)
|
|
2081
|
+
)
|
|
2082
|
+
return Object.freeze({ valid: false, reason: "post-handoff-grant-missing", evidence: null });
|
|
2083
|
+
const grantClients = new Map(grant.clients.map((client) => [client.clientId, client]));
|
|
2084
|
+
let release = null;
|
|
2085
|
+
let sequenceValid = true;
|
|
2086
|
+
for (const record of sequence) {
|
|
2087
|
+
const owners = [record.inputOwner, record.focusOwner, record.geometryOwner];
|
|
2088
|
+
const allNull = owners.every((owner) => owner === null);
|
|
2089
|
+
const expected = record.clients.find(({ clientId }) => clientId === expectedClientId);
|
|
2090
|
+
const otherTopologyStable = record.clients.every((client) => {
|
|
2091
|
+
const atGrant = grantClients.get(client.clientId);
|
|
2092
|
+
return (
|
|
2093
|
+
atGrant !== undefined &&
|
|
2094
|
+
client.surface === atGrant.surface &&
|
|
2095
|
+
client.connectedRevision === atGrant.connectedRevision &&
|
|
2096
|
+
(client.clientId === expectedClientId || client.state === atGrant.state)
|
|
2097
|
+
);
|
|
2098
|
+
});
|
|
2099
|
+
if (!otherTopologyStable) {
|
|
2100
|
+
sequenceValid = false;
|
|
2101
|
+
break;
|
|
2102
|
+
}
|
|
2103
|
+
if (allNull) {
|
|
2104
|
+
if (expected?.state !== "background") {
|
|
2105
|
+
sequenceValid = false;
|
|
2106
|
+
break;
|
|
2107
|
+
}
|
|
2108
|
+
release ??= record;
|
|
2109
|
+
} else if (
|
|
2110
|
+
release !== null ||
|
|
2111
|
+
record.inputOwner !== expectedClientId ||
|
|
2112
|
+
![null, expectedClientId].includes(record.focusOwner) ||
|
|
2113
|
+
![null, expectedClientId].includes(record.geometryOwner) ||
|
|
2114
|
+
expected?.state !== "foreground"
|
|
2115
|
+
) {
|
|
2116
|
+
sequenceValid = false;
|
|
2117
|
+
break;
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
const currentOwners = [authority.owners.input, authority.owners.focus, authority.owners.geometry];
|
|
2121
|
+
const currentExpected = clients.find(({ clientId }) => clientId === expectedClientId);
|
|
2122
|
+
const currentMatchesLast =
|
|
2123
|
+
sequence.at(-1).inputOwner === authority.owners.input &&
|
|
2124
|
+
sequence.at(-1).focusOwner === authority.owners.focus &&
|
|
2125
|
+
sequence.at(-1).geometryOwner === authority.owners.geometry &&
|
|
2126
|
+
sequence.at(-1).nativeGeometryYieldUntilMs === authority.nativeGeometryYieldUntilMs &&
|
|
2127
|
+
sequence.at(-1).clients.every((recordClient) => {
|
|
2128
|
+
const current = clients.find(({ clientId }) => clientId === recordClient.clientId);
|
|
2129
|
+
return current !== undefined && JSON.stringify(recordClient) === JSON.stringify(current);
|
|
2130
|
+
});
|
|
2131
|
+
const retained =
|
|
2132
|
+
release === null &&
|
|
2133
|
+
authority.owners.input === expectedClientId &&
|
|
2134
|
+
currentOwners.every((owner) => owner === null || owner === expectedClientId) &&
|
|
2135
|
+
currentExpected?.state === "foreground";
|
|
2136
|
+
const released =
|
|
2137
|
+
release !== null &&
|
|
2138
|
+
currentOwners.every((owner) => owner === null) &&
|
|
2139
|
+
currentExpected?.state === "background";
|
|
2140
|
+
const relation =
|
|
2141
|
+
sequenceValid && currentMatchesLast
|
|
2142
|
+
? retained
|
|
2143
|
+
? "retained-owner"
|
|
2144
|
+
: released
|
|
2145
|
+
? "released-null"
|
|
2146
|
+
: null
|
|
2147
|
+
: null;
|
|
2148
|
+
if (relation === null)
|
|
2149
|
+
return Object.freeze({
|
|
2150
|
+
valid: false,
|
|
2151
|
+
reason: "post-handoff-owner-unexplained",
|
|
2152
|
+
evidence: null,
|
|
2153
|
+
});
|
|
2154
|
+
const sortedClients = [...clients].sort((left, right) =>
|
|
2155
|
+
left.clientId.localeCompare(right.clientId),
|
|
2156
|
+
);
|
|
2157
|
+
const semanticTopology = JSON.stringify({
|
|
2158
|
+
generation: authority.generation,
|
|
2159
|
+
session: authority.session,
|
|
2160
|
+
owners: authority.owners,
|
|
2161
|
+
nativeGeometryYieldUntilMs: authority.nativeGeometryYieldUntilMs,
|
|
2162
|
+
clients: sortedClients.map(({ clientId, surface, state, connectedRevision }) => ({
|
|
2163
|
+
clientId,
|
|
2164
|
+
surface,
|
|
2165
|
+
state,
|
|
2166
|
+
connectedRevision,
|
|
2167
|
+
})),
|
|
2168
|
+
});
|
|
2169
|
+
const activityTopology = JSON.stringify({
|
|
2170
|
+
revision: authority.revision,
|
|
2171
|
+
clients: sortedClients.map(({ clientId, surface, activityRevision }) => ({
|
|
2172
|
+
clientId,
|
|
2173
|
+
surface,
|
|
2174
|
+
activityRevision,
|
|
2175
|
+
})),
|
|
2176
|
+
});
|
|
2177
|
+
const hmac = (domain, value) =>
|
|
2178
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
2179
|
+
.update(`${domain}\0${value}`)
|
|
2180
|
+
.digest("hex");
|
|
2181
|
+
const duplicateOrdinalHmac = hmac(
|
|
2182
|
+
"post-handoff-authority-duplicate-ordinals",
|
|
2183
|
+
duplicateOrdinals.join("\0"),
|
|
2184
|
+
);
|
|
2185
|
+
const normalizedSequence = JSON.stringify({
|
|
2186
|
+
records: sequence.map((record) => JSON.parse(normalizeRecord(record))),
|
|
2187
|
+
duplicateCount: duplicateOrdinals.length,
|
|
2188
|
+
duplicateOrdinalHmac,
|
|
2189
|
+
});
|
|
2190
|
+
const sequenceHmac = hmac("post-handoff-authority-sequence", normalizedSequence);
|
|
2191
|
+
return Object.freeze({
|
|
2192
|
+
valid: true,
|
|
2193
|
+
reason: null,
|
|
2194
|
+
relation,
|
|
2195
|
+
evidence: Object.freeze({
|
|
2196
|
+
authorityRevision: authority.revision,
|
|
2197
|
+
authorityOwnerHmac: hmac("post-handoff-expected-owner", expectedClientId),
|
|
2198
|
+
authorityTopologyHmac: hmac("post-handoff-authority-topology", semanticTopology),
|
|
2199
|
+
authorityHmac: hmac("post-handoff-authority", semanticTopology),
|
|
2200
|
+
authorityMutationHmac: hmac("post-handoff-authority-mutation", activityTopology),
|
|
2201
|
+
authorityRelationHmac: hmac(
|
|
2202
|
+
"post-handoff-authority-relation",
|
|
2203
|
+
[
|
|
2204
|
+
relation,
|
|
2205
|
+
grantRevision,
|
|
2206
|
+
release?.revision ?? authority.revision,
|
|
2207
|
+
inputProofHmac,
|
|
2208
|
+
sequenceHmac,
|
|
2209
|
+
].join("\0"),
|
|
2210
|
+
),
|
|
2211
|
+
authoritySequenceHmac: sequenceHmac,
|
|
2212
|
+
authorityDuplicateCount: duplicateOrdinals.length,
|
|
2213
|
+
inputProofHmac,
|
|
2214
|
+
grantRevision,
|
|
2215
|
+
releaseRevision: release?.revision ?? null,
|
|
2216
|
+
relation,
|
|
2217
|
+
}),
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
/** Select one exact null-to-grant join without conflating client identity with focus epoch. */
|
|
2222
|
+
export function selectCard5PostInputAuthorityJoin({
|
|
2223
|
+
records,
|
|
2224
|
+
nullRevision,
|
|
2225
|
+
expectedNullAuthority,
|
|
2226
|
+
expectedNullEvidence,
|
|
2227
|
+
expectedClientId,
|
|
2228
|
+
expectedSurface,
|
|
2229
|
+
expectedGrantRevision = null,
|
|
2230
|
+
expectedGrantRecord = null,
|
|
2231
|
+
receiptCandidates = [],
|
|
2232
|
+
requireReceipt,
|
|
2233
|
+
boundary,
|
|
2234
|
+
boundaryOverflow = false,
|
|
2235
|
+
evidenceKey,
|
|
2236
|
+
}) {
|
|
2237
|
+
const fail = (observation) =>
|
|
2238
|
+
Object.freeze({ passed: false, grant: null, receipt: null, observation });
|
|
2239
|
+
const exactKeys = (value, keys) =>
|
|
2240
|
+
value !== null &&
|
|
2241
|
+
typeof value === "object" &&
|
|
2242
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
|
2243
|
+
const normalizeClients = (clients) => {
|
|
2244
|
+
if (!Array.isArray(clients) || clients.length !== 3) return null;
|
|
2245
|
+
const normalized = clients.map((client) =>
|
|
2246
|
+
exactKeys(client, [
|
|
2247
|
+
"clientId",
|
|
2248
|
+
"surface",
|
|
2249
|
+
"state",
|
|
2250
|
+
"connectedRevision",
|
|
2251
|
+
"activityRevision",
|
|
2252
|
+
]) &&
|
|
2253
|
+
typeof client.clientId === "string" &&
|
|
2254
|
+
client.clientId.length >= 1 &&
|
|
2255
|
+
client.clientId.length <= 4_096 &&
|
|
2256
|
+
!/[\0\r\n]/u.test(client.clientId) &&
|
|
2257
|
+
["web", "opentui", "cli", "sdk", "native-tmux", "unknown"].includes(client.surface) &&
|
|
2258
|
+
["foreground", "background"].includes(client.state) &&
|
|
2259
|
+
Number.isSafeInteger(client.connectedRevision) &&
|
|
2260
|
+
client.connectedRevision >= 1 &&
|
|
2261
|
+
Number.isSafeInteger(client.activityRevision) &&
|
|
2262
|
+
client.activityRevision >= 0
|
|
2263
|
+
? { ...client }
|
|
2264
|
+
: null,
|
|
2265
|
+
);
|
|
2266
|
+
if (
|
|
2267
|
+
normalized.includes(null) ||
|
|
2268
|
+
new Set(normalized.map((client) => client.clientId)).size !== normalized.length
|
|
2269
|
+
)
|
|
2270
|
+
return null;
|
|
2271
|
+
return normalized.sort((left, right) => left.clientId.localeCompare(right.clientId));
|
|
2272
|
+
};
|
|
2273
|
+
const normalizeSnapshot = (snapshot) => {
|
|
2274
|
+
const clients = normalizeClients(snapshot?.clients);
|
|
2275
|
+
if (
|
|
2276
|
+
clients === null ||
|
|
2277
|
+
!exactKeys(snapshot, [
|
|
2278
|
+
"generation",
|
|
2279
|
+
"session",
|
|
2280
|
+
"revision",
|
|
2281
|
+
"owners",
|
|
2282
|
+
"nativeGeometryYieldUntilMs",
|
|
2283
|
+
"clients",
|
|
2284
|
+
]) ||
|
|
2285
|
+
!exactKeys(snapshot?.owners, ["input", "focus", "geometry"]) ||
|
|
2286
|
+
!GENERATION.test(snapshot.generation ?? "") ||
|
|
2287
|
+
!GENERATION.test(snapshot.session ?? "") ||
|
|
2288
|
+
!Number.isSafeInteger(snapshot.revision) ||
|
|
2289
|
+
snapshot.revision < 0 ||
|
|
2290
|
+
!Number.isSafeInteger(snapshot.nativeGeometryYieldUntilMs) ||
|
|
2291
|
+
snapshot.nativeGeometryYieldUntilMs < 0
|
|
2292
|
+
)
|
|
2293
|
+
return null;
|
|
2294
|
+
return JSON.stringify({
|
|
2295
|
+
generation: snapshot.generation,
|
|
2296
|
+
session: snapshot.session,
|
|
2297
|
+
revision: snapshot.revision,
|
|
2298
|
+
nativeGeometryYieldUntilMs: snapshot.nativeGeometryYieldUntilMs,
|
|
2299
|
+
inputOwner: snapshot.owners.input,
|
|
2300
|
+
focusOwner: snapshot.owners.focus,
|
|
2301
|
+
geometryOwner: snapshot.owners.geometry,
|
|
2302
|
+
clients,
|
|
2303
|
+
});
|
|
2304
|
+
};
|
|
2305
|
+
const normalizeRecord = (record) => {
|
|
2306
|
+
const clients = normalizeClients(record?.clients);
|
|
2307
|
+
if (
|
|
2308
|
+
clients === null ||
|
|
2309
|
+
!exactKeys(record, [
|
|
2310
|
+
"ordinal",
|
|
2311
|
+
"generation",
|
|
2312
|
+
"session",
|
|
2313
|
+
"revision",
|
|
2314
|
+
"nativeGeometryYieldUntilMs",
|
|
2315
|
+
"inputOwner",
|
|
2316
|
+
"focusOwner",
|
|
2317
|
+
"geometryOwner",
|
|
2318
|
+
"clients",
|
|
2319
|
+
]) ||
|
|
2320
|
+
!Number.isSafeInteger(record.ordinal) ||
|
|
2321
|
+
record.ordinal < 1 ||
|
|
2322
|
+
!GENERATION.test(record.generation ?? "") ||
|
|
2323
|
+
!GENERATION.test(record.session ?? "") ||
|
|
2324
|
+
!Number.isSafeInteger(record.revision) ||
|
|
2325
|
+
record.revision < 0 ||
|
|
2326
|
+
!Number.isSafeInteger(record.nativeGeometryYieldUntilMs) ||
|
|
2327
|
+
record.nativeGeometryYieldUntilMs < 0 ||
|
|
2328
|
+
![record.inputOwner, record.focusOwner, record.geometryOwner].every(
|
|
2329
|
+
(owner) => owner === null || (typeof owner === "string" && owner.length >= 1),
|
|
2330
|
+
)
|
|
2331
|
+
)
|
|
2332
|
+
return null;
|
|
2333
|
+
return JSON.stringify({
|
|
2334
|
+
generation: record.generation,
|
|
2335
|
+
session: record.session,
|
|
2336
|
+
revision: record.revision,
|
|
2337
|
+
nativeGeometryYieldUntilMs: record.nativeGeometryYieldUntilMs,
|
|
2338
|
+
inputOwner: record.inputOwner,
|
|
2339
|
+
focusOwner: record.focusOwner,
|
|
2340
|
+
geometryOwner: record.geometryOwner,
|
|
2341
|
+
clients,
|
|
2342
|
+
});
|
|
2343
|
+
};
|
|
2344
|
+
const expectedNullNormalized = normalizeSnapshot(expectedNullAuthority);
|
|
2345
|
+
const expectedNullSeal = sealCard5NullAuthority(
|
|
2346
|
+
expectedNullAuthority,
|
|
2347
|
+
expectedNullAuthority?.generation,
|
|
2348
|
+
evidenceKey,
|
|
2349
|
+
);
|
|
2350
|
+
const expectedNullSealExact =
|
|
2351
|
+
expectedNullSeal !== null &&
|
|
2352
|
+
exactKeys(expectedNullEvidence, [
|
|
2353
|
+
"authorityRevision",
|
|
2354
|
+
"authorityOwnerHmac",
|
|
2355
|
+
"authorityTopologyHmac",
|
|
2356
|
+
"authorityHmac",
|
|
2357
|
+
"authorityMutationHmac",
|
|
2358
|
+
]) &&
|
|
2359
|
+
Object.keys(expectedNullSeal).every(
|
|
2360
|
+
(key) => expectedNullSeal[key] === expectedNullEvidence[key],
|
|
2361
|
+
);
|
|
2362
|
+
const expectedGrantNormalized =
|
|
2363
|
+
expectedGrantRecord === null ? null : normalizeRecord(expectedGrantRecord);
|
|
2364
|
+
if (
|
|
2365
|
+
!Array.isArray(records) ||
|
|
2366
|
+
!records.every((record) => normalizeRecord(record) !== null) ||
|
|
2367
|
+
!Number.isSafeInteger(nullRevision) ||
|
|
2368
|
+
nullRevision < 0 ||
|
|
2369
|
+
expectedNullNormalized === null ||
|
|
2370
|
+
!expectedNullSealExact ||
|
|
2371
|
+
(expectedGrantRecord !== null && expectedGrantNormalized === null) ||
|
|
2372
|
+
typeof expectedClientId !== "string" ||
|
|
2373
|
+
expectedClientId.length < 1 ||
|
|
2374
|
+
expectedClientId.length > 4_096 ||
|
|
2375
|
+
!["opentui", "web"].includes(expectedSurface) ||
|
|
2376
|
+
(expectedGrantRevision !== null &&
|
|
2377
|
+
(!Number.isSafeInteger(expectedGrantRevision) || expectedGrantRevision <= nullRevision)) ||
|
|
2378
|
+
!Array.isArray(receiptCandidates) ||
|
|
2379
|
+
!receiptCandidates.every(
|
|
2380
|
+
(receipt) =>
|
|
2381
|
+
receipt !== null &&
|
|
2382
|
+
typeof receipt === "object" &&
|
|
2383
|
+
typeof receipt.authorityClientId === "string" &&
|
|
2384
|
+
receipt.authorityClientId.length >= 1 &&
|
|
2385
|
+
receipt.authorityClientId.length <= 4_096,
|
|
2386
|
+
) ||
|
|
2387
|
+
typeof requireReceipt !== "boolean" ||
|
|
2388
|
+
(requireReceipt && (expectedGrantNormalized === null || expectedGrantRevision === null)) ||
|
|
2389
|
+
!Number.isSafeInteger(boundary) ||
|
|
2390
|
+
boundary < 0 ||
|
|
2391
|
+
typeof boundaryOverflow !== "boolean" ||
|
|
2392
|
+
!HMAC.test(evidenceKey ?? "")
|
|
2393
|
+
)
|
|
2394
|
+
return fail(
|
|
2395
|
+
Object.freeze({
|
|
2396
|
+
nullCount: 0,
|
|
2397
|
+
nullOverflow: false,
|
|
2398
|
+
grantCount: 0,
|
|
2399
|
+
grantOverflow: false,
|
|
2400
|
+
receiptCount: 0,
|
|
2401
|
+
nullExact: false,
|
|
2402
|
+
grantExact: false,
|
|
2403
|
+
receiptExact: false,
|
|
2404
|
+
boundary: Number.isSafeInteger(boundary) ? boundary : null,
|
|
2405
|
+
boundaryOverflow: boundaryOverflow === true,
|
|
2406
|
+
nullReplayCount: 0,
|
|
2407
|
+
nullReplayOrdinalHmac: null,
|
|
2408
|
+
grantReplayCount: 0,
|
|
2409
|
+
grantReplayOrdinalHmac: null,
|
|
2410
|
+
stagingCount: 0,
|
|
2411
|
+
stagingOverflow: false,
|
|
2412
|
+
stagingExact: false,
|
|
2413
|
+
stagingOrdinalHmac: null,
|
|
2414
|
+
stagingSequenceHmac: null,
|
|
2415
|
+
lastRecords: Object.freeze([]),
|
|
2416
|
+
}),
|
|
2417
|
+
);
|
|
2418
|
+
const nullMatches = records.filter(
|
|
2419
|
+
({ inputOwner, focusOwner, geometryOwner, revision }) =>
|
|
2420
|
+
inputOwner === null &&
|
|
2421
|
+
focusOwner === null &&
|
|
2422
|
+
geometryOwner === null &&
|
|
2423
|
+
revision === nullRevision,
|
|
2424
|
+
);
|
|
2425
|
+
const nullIndexes = nullMatches.map((record) => records.indexOf(record));
|
|
2426
|
+
const nullOrdinalsExact = nullMatches.every(
|
|
2427
|
+
(record, index) =>
|
|
2428
|
+
index === 0 ||
|
|
2429
|
+
(nullIndexes[index] === nullIndexes[index - 1] + 1 &&
|
|
2430
|
+
record.ordinal === nullMatches[index - 1].ordinal + 1),
|
|
2431
|
+
);
|
|
2432
|
+
const nullRecordsExact =
|
|
2433
|
+
nullMatches.length >= 1 &&
|
|
2434
|
+
nullMatches.length <= 8 &&
|
|
2435
|
+
nullOrdinalsExact &&
|
|
2436
|
+
nullMatches.every((record) => normalizeRecord(record) === expectedNullNormalized);
|
|
2437
|
+
const nullIndex = records.indexOf(nullMatches[0]);
|
|
2438
|
+
const potentialGrantCandidates = records.filter(
|
|
2439
|
+
({ inputOwner, revision, clients }, index) =>
|
|
2440
|
+
index > nullIndex &&
|
|
2441
|
+
inputOwner === expectedClientId &&
|
|
2442
|
+
(expectedGrantRevision === null || revision === expectedGrantRevision) &&
|
|
2443
|
+
Array.isArray(clients) &&
|
|
2444
|
+
clients.some(
|
|
2445
|
+
({ clientId, surface }) => clientId === inputOwner && surface === expectedSurface,
|
|
2446
|
+
),
|
|
2447
|
+
);
|
|
2448
|
+
let grantCandidates;
|
|
2449
|
+
if (expectedGrantNormalized !== null) {
|
|
2450
|
+
grantCandidates = potentialGrantCandidates.filter(
|
|
2451
|
+
(candidate) => normalizeRecord(candidate) === expectedGrantNormalized,
|
|
2452
|
+
);
|
|
2453
|
+
} else {
|
|
2454
|
+
const firstCandidate = potentialGrantCandidates[0];
|
|
2455
|
+
const firstCandidateIndex = records.indexOf(firstCandidate);
|
|
2456
|
+
const firstCandidateNormalized = normalizeRecord(firstCandidate);
|
|
2457
|
+
grantCandidates = [];
|
|
2458
|
+
for (let index = firstCandidateIndex; index >= 0 && index < records.length; index += 1) {
|
|
2459
|
+
const record = records[index];
|
|
2460
|
+
if (normalizeRecord(record) !== firstCandidateNormalized) break;
|
|
2461
|
+
grantCandidates.push(record);
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
const grantBaseline = expectedGrantNormalized ?? normalizeRecord(grantCandidates[0]);
|
|
2465
|
+
const grantIndexes = grantCandidates.map((record) => records.indexOf(record));
|
|
2466
|
+
const grantOrdinalsExact = grantCandidates.every(
|
|
2467
|
+
(record, index) =>
|
|
2468
|
+
index === 0 ||
|
|
2469
|
+
(grantIndexes[index] === grantIndexes[index - 1] + 1 &&
|
|
2470
|
+
record.ordinal === grantCandidates[index - 1].ordinal + 1),
|
|
2471
|
+
);
|
|
2472
|
+
const grantRecordExact =
|
|
2473
|
+
grantCandidates.length >= 1 &&
|
|
2474
|
+
grantCandidates.length <= 8 &&
|
|
2475
|
+
grantOrdinalsExact &&
|
|
2476
|
+
grantBaseline !== null &&
|
|
2477
|
+
grantCandidates.every((candidate) => normalizeRecord(candidate) === grantBaseline);
|
|
2478
|
+
const matchingReceipts = receiptCandidates.filter(
|
|
2479
|
+
({ authorityClientId }) => authorityClientId === expectedClientId,
|
|
2480
|
+
);
|
|
2481
|
+
const hmac = (domain, value) =>
|
|
2482
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
2483
|
+
.update(`${domain}\0${value}`)
|
|
2484
|
+
.digest("hex");
|
|
2485
|
+
const firstNullIndex = nullIndexes[0] ?? -1;
|
|
2486
|
+
const lastGrantIndex = grantIndexes.at(-1) ?? -1;
|
|
2487
|
+
const stagingRecords =
|
|
2488
|
+
firstNullIndex >= 0 && lastGrantIndex >= firstNullIndex
|
|
2489
|
+
? records.slice(firstNullIndex, lastGrantIndex + 1)
|
|
2490
|
+
: [];
|
|
2491
|
+
const baseClients = [...(expectedNullAuthority?.clients ?? [])].sort((left, right) =>
|
|
2492
|
+
left.clientId.localeCompare(right.clientId),
|
|
2493
|
+
);
|
|
2494
|
+
const targetBaseIndex = baseClients.findIndex(
|
|
2495
|
+
({ clientId, surface }) => clientId === expectedClientId && surface === expectedSurface,
|
|
2496
|
+
);
|
|
2497
|
+
const acquired = { inputOwner: false, focusOwner: false, geometryOwner: false };
|
|
2498
|
+
let targetForeground = baseClients[targetBaseIndex]?.state === "foreground";
|
|
2499
|
+
let targetActivityRevision = baseClients[targetBaseIndex]?.activityRevision ?? -1;
|
|
2500
|
+
let priorRevision = null;
|
|
2501
|
+
let priorNormalized = null;
|
|
2502
|
+
let replayCount = 0;
|
|
2503
|
+
const stagingExact =
|
|
2504
|
+
stagingRecords.length >= 2 &&
|
|
2505
|
+
stagingRecords.length <= 16 &&
|
|
2506
|
+
targetBaseIndex >= 0 &&
|
|
2507
|
+
stagingRecords.every((record, index) => {
|
|
2508
|
+
const normalized = normalizeRecord(record);
|
|
2509
|
+
const sortedClients = [...record.clients].sort((left, right) =>
|
|
2510
|
+
left.clientId.localeCompare(right.clientId),
|
|
2511
|
+
);
|
|
2512
|
+
const ordinalExact = index === 0 || record.ordinal === stagingRecords[index - 1].ordinal + 1;
|
|
2513
|
+
const revisionExact =
|
|
2514
|
+
priorRevision === null ||
|
|
2515
|
+
record.revision > priorRevision ||
|
|
2516
|
+
(record.revision === priorRevision && normalized === priorNormalized && ++replayCount <= 8);
|
|
2517
|
+
const identityExact =
|
|
2518
|
+
record.generation === expectedNullAuthority.generation &&
|
|
2519
|
+
record.session === expectedNullAuthority.session &&
|
|
2520
|
+
record.nativeGeometryYieldUntilMs === expectedNullAuthority.nativeGeometryYieldUntilMs &&
|
|
2521
|
+
sortedClients.every(
|
|
2522
|
+
(client, clientIndex) =>
|
|
2523
|
+
client.clientId === baseClients[clientIndex].clientId &&
|
|
2524
|
+
client.surface === baseClients[clientIndex].surface &&
|
|
2525
|
+
client.connectedRevision === baseClients[clientIndex].connectedRevision,
|
|
2526
|
+
);
|
|
2527
|
+
let clientsExact = identityExact;
|
|
2528
|
+
for (const [clientIndex, client] of sortedClients.entries()) {
|
|
2529
|
+
const base = baseClients[clientIndex];
|
|
2530
|
+
if (clientIndex !== targetBaseIndex) {
|
|
2531
|
+
clientsExact &&=
|
|
2532
|
+
client.state === base.state && client.activityRevision === base.activityRevision;
|
|
2533
|
+
continue;
|
|
2534
|
+
}
|
|
2535
|
+
clientsExact &&= client.activityRevision >= targetActivityRevision;
|
|
2536
|
+
if (targetForeground && client.state !== "foreground") clientsExact = false;
|
|
2537
|
+
if (client.state === "foreground") targetForeground = true;
|
|
2538
|
+
targetActivityRevision = client.activityRevision;
|
|
2539
|
+
}
|
|
2540
|
+
let ownersExact = true;
|
|
2541
|
+
for (const key of ["inputOwner", "focusOwner", "geometryOwner"]) {
|
|
2542
|
+
const owner = record[key];
|
|
2543
|
+
if (owner !== null && owner !== expectedClientId) ownersExact = false;
|
|
2544
|
+
if (acquired[key] && owner !== expectedClientId) ownersExact = false;
|
|
2545
|
+
if (owner === expectedClientId) acquired[key] = true;
|
|
2546
|
+
}
|
|
2547
|
+
priorRevision = record.revision;
|
|
2548
|
+
priorNormalized = normalized;
|
|
2549
|
+
return ordinalExact && revisionExact && clientsExact && ownersExact;
|
|
2550
|
+
}) &&
|
|
2551
|
+
replayCount <= 8 &&
|
|
2552
|
+
grantRecordExact &&
|
|
2553
|
+
normalizeRecord(stagingRecords.at(-1)) === grantBaseline;
|
|
2554
|
+
const observation = Object.freeze({
|
|
2555
|
+
nullCount: Math.min(nullMatches.length, 8),
|
|
2556
|
+
nullOverflow: nullMatches.length > 8,
|
|
2557
|
+
grantCount: Math.min(grantCandidates.length, 8),
|
|
2558
|
+
grantOverflow: grantCandidates.length > 8,
|
|
2559
|
+
receiptCount: Math.min(receiptCandidates.length, 8),
|
|
2560
|
+
nullExact: nullRecordsExact,
|
|
2561
|
+
grantExact: grantRecordExact,
|
|
2562
|
+
receiptExact: requireReceipt
|
|
2563
|
+
? receiptCandidates.length === 1 && matchingReceipts.length === 1
|
|
2564
|
+
: receiptCandidates.length === 0,
|
|
2565
|
+
boundary: Number.isSafeInteger(boundary) ? boundary : null,
|
|
2566
|
+
boundaryOverflow,
|
|
2567
|
+
nullReplayCount: Math.max(0, Math.min(nullMatches.length - 1, 7)),
|
|
2568
|
+
nullReplayOrdinalHmac: hmac(
|
|
2569
|
+
"post-input-null-replay-ordinals",
|
|
2570
|
+
nullMatches.map(({ ordinal }) => ordinal).join("\0"),
|
|
2571
|
+
),
|
|
2572
|
+
grantReplayCount: Math.max(0, Math.min(grantCandidates.length - 1, 7)),
|
|
2573
|
+
grantReplayOrdinalHmac: hmac(
|
|
2574
|
+
"post-input-grant-replay-ordinals",
|
|
2575
|
+
grantCandidates.map(({ ordinal }) => ordinal).join("\0"),
|
|
2576
|
+
),
|
|
2577
|
+
stagingCount: Math.min(stagingRecords.length, 16),
|
|
2578
|
+
stagingOverflow: stagingRecords.length > 16,
|
|
2579
|
+
stagingExact,
|
|
2580
|
+
stagingOrdinalHmac: hmac(
|
|
2581
|
+
"post-input-staging-ordinals",
|
|
2582
|
+
stagingRecords.map(({ ordinal }) => ordinal).join("\0"),
|
|
2583
|
+
),
|
|
2584
|
+
stagingSequenceHmac: hmac(
|
|
2585
|
+
"post-input-staging-sequence",
|
|
2586
|
+
stagingRecords.map((record) => `${record.ordinal}\0${normalizeRecord(record)}`).join("\0"),
|
|
2587
|
+
),
|
|
2588
|
+
lastRecords: Object.freeze(
|
|
2589
|
+
records.slice(-2).map((record) =>
|
|
2590
|
+
Object.freeze({
|
|
2591
|
+
ordinal: Number.isSafeInteger(record?.ordinal) ? record.ordinal : null,
|
|
2592
|
+
revision: Number.isSafeInteger(record?.revision) ? record.revision : null,
|
|
2593
|
+
ownerHmac: hmac(
|
|
2594
|
+
"post-input-authority-owner",
|
|
2595
|
+
[record?.inputOwner, record?.focusOwner, record?.geometryOwner].join("\0"),
|
|
2596
|
+
),
|
|
2597
|
+
topologyHmac: hmac(
|
|
2598
|
+
"post-input-authority-topology",
|
|
2599
|
+
JSON.stringify(record?.clients ?? null),
|
|
2600
|
+
),
|
|
2601
|
+
}),
|
|
2602
|
+
),
|
|
2603
|
+
),
|
|
2604
|
+
});
|
|
2605
|
+
const passed =
|
|
2606
|
+
!boundaryOverflow &&
|
|
2607
|
+
observation.nullExact &&
|
|
2608
|
+
observation.grantExact &&
|
|
2609
|
+
stagingExact &&
|
|
2610
|
+
observation.receiptExact &&
|
|
2611
|
+
nullIndex >= 0;
|
|
2612
|
+
return passed
|
|
2613
|
+
? Object.freeze({
|
|
2614
|
+
passed: true,
|
|
2615
|
+
grant: grantCandidates[0],
|
|
2616
|
+
receipt: requireReceipt ? matchingReceipts[0] : null,
|
|
2617
|
+
observation,
|
|
2618
|
+
})
|
|
2619
|
+
: fail(observation);
|
|
2620
|
+
}
|
|
2621
|
+
|
|
2622
|
+
const CARD5_POST_INPUT_PRECONDITION_REASONS = Object.freeze([
|
|
2623
|
+
"receipt-missing",
|
|
2624
|
+
"receipt-ambiguous",
|
|
2625
|
+
"receipt-invalid",
|
|
2626
|
+
"receipt-target-mismatch",
|
|
2627
|
+
"web-observation-invalid",
|
|
2628
|
+
"web-observation-timeout",
|
|
2629
|
+
"web-current-mismatch",
|
|
2630
|
+
"target-web-absent",
|
|
2631
|
+
"target-web-wrong-surface",
|
|
2632
|
+
"input-owner-mismatch",
|
|
2633
|
+
"focus-owner-mismatch",
|
|
2634
|
+
"geometry-owner-mismatch",
|
|
2635
|
+
"current-revision-mismatch",
|
|
2636
|
+
"current-generation-mismatch",
|
|
2637
|
+
"current-session-mismatch",
|
|
2638
|
+
"current-native-yield-mismatch",
|
|
2639
|
+
"current-topology-mismatch",
|
|
2640
|
+
"terminal-record-missing",
|
|
2641
|
+
"terminal-record-mismatch",
|
|
2642
|
+
"boundary-overflow",
|
|
2643
|
+
"selector-contract-invalid",
|
|
2644
|
+
]);
|
|
2645
|
+
|
|
2646
|
+
/**
|
|
2647
|
+
* Project the producer-side prerequisites for the strict post-input selector.
|
|
2648
|
+
* This function is diagnostic only: callers must continue to use
|
|
2649
|
+
* selectCard5PostInputAuthorityJoin as the acceptance decision.
|
|
2650
|
+
*/
|
|
2651
|
+
export function boundedCard5PostInputAuthorityPreconditionObservation({
|
|
2652
|
+
webResults,
|
|
2653
|
+
receiptPage,
|
|
2654
|
+
receiptBoundary,
|
|
2655
|
+
rawReceipts,
|
|
2656
|
+
receiptCandidates,
|
|
2657
|
+
expectedInputSha256,
|
|
2658
|
+
expectedRequestHmac,
|
|
2659
|
+
requireReceipt,
|
|
2660
|
+
expectedPane,
|
|
2661
|
+
expectedGeneration,
|
|
2662
|
+
expectedBaselineAuthority,
|
|
2663
|
+
expectedClientId,
|
|
2664
|
+
expectedSurface,
|
|
2665
|
+
expectedGrantRecord,
|
|
2666
|
+
authorityRecords,
|
|
2667
|
+
authorityBoundary,
|
|
2668
|
+
boundaryOverflow,
|
|
2669
|
+
evidenceKey,
|
|
2670
|
+
}) {
|
|
2671
|
+
const exactKeys = (value, keys) =>
|
|
2672
|
+
value !== null &&
|
|
2673
|
+
typeof value === "object" &&
|
|
2674
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
|
2675
|
+
const safeIdentity = (value) =>
|
|
2676
|
+
typeof value === "string" &&
|
|
2677
|
+
value.length >= 1 &&
|
|
2678
|
+
value.length <= 4_096 &&
|
|
2679
|
+
!/[\0\r\n]/u.test(value);
|
|
2680
|
+
const hmac = (domain, value) =>
|
|
2681
|
+
HMAC.test(evidenceKey ?? "")
|
|
2682
|
+
? createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
2683
|
+
.update(`${domain}\0${String(value)}`)
|
|
2684
|
+
.digest("hex")
|
|
2685
|
+
: null;
|
|
2686
|
+
const normalizeClients = (clients) => {
|
|
2687
|
+
if (!Array.isArray(clients) || clients.length !== 3) return null;
|
|
2688
|
+
const normalized = clients.map((client) =>
|
|
2689
|
+
exactKeys(client, [
|
|
2690
|
+
"clientId",
|
|
2691
|
+
"surface",
|
|
2692
|
+
"state",
|
|
2693
|
+
"connectedRevision",
|
|
2694
|
+
"activityRevision",
|
|
2695
|
+
]) &&
|
|
2696
|
+
safeIdentity(client.clientId) &&
|
|
2697
|
+
["web", "opentui", "cli", "sdk", "native-tmux", "unknown"].includes(client.surface) &&
|
|
2698
|
+
["foreground", "background"].includes(client.state) &&
|
|
2699
|
+
Number.isSafeInteger(client.connectedRevision) &&
|
|
2700
|
+
client.connectedRevision >= 1 &&
|
|
2701
|
+
Number.isSafeInteger(client.activityRevision) &&
|
|
2702
|
+
client.activityRevision >= 0
|
|
2703
|
+
? { ...client }
|
|
2704
|
+
: null,
|
|
2705
|
+
);
|
|
2706
|
+
if (
|
|
2707
|
+
normalized.includes(null) ||
|
|
2708
|
+
new Set(normalized.map((client) => client.clientId)).size !== normalized.length
|
|
2709
|
+
)
|
|
2710
|
+
return null;
|
|
2711
|
+
return normalized;
|
|
2712
|
+
};
|
|
2713
|
+
const normalizeAuthority = (authority) => {
|
|
2714
|
+
const clients = normalizeClients(authority?.clients);
|
|
2715
|
+
if (
|
|
2716
|
+
clients === null ||
|
|
2717
|
+
!exactKeys(authority, [
|
|
2718
|
+
"generation",
|
|
2719
|
+
"session",
|
|
2720
|
+
"revision",
|
|
2721
|
+
"owners",
|
|
2722
|
+
"nativeGeometryYieldUntilMs",
|
|
2723
|
+
"clients",
|
|
2724
|
+
]) ||
|
|
2725
|
+
!exactKeys(authority?.owners, ["input", "focus", "geometry"]) ||
|
|
2726
|
+
!GENERATION.test(authority.generation ?? "") ||
|
|
2727
|
+
!GENERATION.test(authority.session ?? "") ||
|
|
2728
|
+
!Number.isSafeInteger(authority.revision) ||
|
|
2729
|
+
authority.revision < 0 ||
|
|
2730
|
+
!Number.isSafeInteger(authority.nativeGeometryYieldUntilMs) ||
|
|
2731
|
+
authority.nativeGeometryYieldUntilMs < 0 ||
|
|
2732
|
+
![authority.owners.input, authority.owners.focus, authority.owners.geometry].every(
|
|
2733
|
+
(owner) => owner === null || safeIdentity(owner),
|
|
2734
|
+
)
|
|
2735
|
+
)
|
|
2736
|
+
return null;
|
|
2737
|
+
return Object.freeze({
|
|
2738
|
+
generation: authority.generation,
|
|
2739
|
+
session: authority.session,
|
|
2740
|
+
revision: authority.revision,
|
|
2741
|
+
nativeGeometryYieldUntilMs: authority.nativeGeometryYieldUntilMs,
|
|
2742
|
+
owners: Object.freeze({ ...authority.owners }),
|
|
2743
|
+
clients: Object.freeze(clients),
|
|
2744
|
+
});
|
|
2745
|
+
};
|
|
2746
|
+
const normalizeRecord = (record) => {
|
|
2747
|
+
const authority = normalizeAuthority(
|
|
2748
|
+
record && typeof record === "object"
|
|
2749
|
+
? {
|
|
2750
|
+
generation: record.generation,
|
|
2751
|
+
session: record.session,
|
|
2752
|
+
revision: record.revision,
|
|
2753
|
+
nativeGeometryYieldUntilMs: record.nativeGeometryYieldUntilMs,
|
|
2754
|
+
owners: {
|
|
2755
|
+
input: record.inputOwner,
|
|
2756
|
+
focus: record.focusOwner,
|
|
2757
|
+
geometry: record.geometryOwner,
|
|
2758
|
+
},
|
|
2759
|
+
clients: record.clients,
|
|
2760
|
+
}
|
|
2761
|
+
: null,
|
|
2762
|
+
);
|
|
2763
|
+
return authority !== null &&
|
|
2764
|
+
exactKeys(record, [
|
|
2765
|
+
"ordinal",
|
|
2766
|
+
"generation",
|
|
2767
|
+
"session",
|
|
2768
|
+
"revision",
|
|
2769
|
+
"nativeGeometryYieldUntilMs",
|
|
2770
|
+
"inputOwner",
|
|
2771
|
+
"focusOwner",
|
|
2772
|
+
"geometryOwner",
|
|
2773
|
+
"clients",
|
|
2774
|
+
]) &&
|
|
2775
|
+
Number.isSafeInteger(record.ordinal) &&
|
|
2776
|
+
record.ordinal >= 1
|
|
2777
|
+
? Object.freeze({ ordinal: record.ordinal, authority })
|
|
2778
|
+
: null;
|
|
2779
|
+
};
|
|
2780
|
+
const expectedBaseline = normalizeAuthority(expectedBaselineAuthority);
|
|
2781
|
+
const contractValid =
|
|
2782
|
+
Array.isArray(webResults) &&
|
|
2783
|
+
webResults.length === 2 &&
|
|
2784
|
+
["none", "chromium", "electron"].includes(receiptPage) &&
|
|
2785
|
+
Number.isSafeInteger(receiptBoundary) &&
|
|
2786
|
+
receiptBoundary >= 0 &&
|
|
2787
|
+
Array.isArray(rawReceipts) &&
|
|
2788
|
+
Array.isArray(receiptCandidates) &&
|
|
2789
|
+
/^[0-9a-f]{64}$/u.test(expectedInputSha256 ?? "") &&
|
|
2790
|
+
(expectedRequestHmac === null || HMAC.test(expectedRequestHmac ?? "")) &&
|
|
2791
|
+
typeof requireReceipt === "boolean" &&
|
|
2792
|
+
safeIdentity(expectedPane) &&
|
|
2793
|
+
GENERATION.test(expectedGeneration ?? "") &&
|
|
2794
|
+
expectedBaseline !== null &&
|
|
2795
|
+
expectedBaseline.generation === expectedGeneration &&
|
|
2796
|
+
(expectedClientId === null || safeIdentity(expectedClientId)) &&
|
|
2797
|
+
["opentui", "web"].includes(expectedSurface) &&
|
|
2798
|
+
Array.isArray(authorityRecords) &&
|
|
2799
|
+
Number.isSafeInteger(authorityBoundary) &&
|
|
2800
|
+
authorityBoundary >= 0 &&
|
|
2801
|
+
typeof boundaryOverflow === "boolean" &&
|
|
2802
|
+
HMAC.test(evidenceKey ?? "");
|
|
2803
|
+
const statuses = contractValid
|
|
2804
|
+
? webResults.map((result) =>
|
|
2805
|
+
exactKeys(result, ["status", "value"]) &&
|
|
2806
|
+
["ok", "deadline", "source-unavailable", "clock-invalid"].includes(result.status)
|
|
2807
|
+
? result.status
|
|
2808
|
+
: "source-unavailable",
|
|
2809
|
+
)
|
|
2810
|
+
: ["source-unavailable", "source-unavailable"];
|
|
2811
|
+
const values = contractValid
|
|
2812
|
+
? webResults.map((result, index) => (statuses[index] === "ok" ? result.value : null))
|
|
2813
|
+
: [null, null];
|
|
2814
|
+
const authorities = values.map((value) =>
|
|
2815
|
+
normalizeAuthority(value?.workspaceEvidence?.authority),
|
|
2816
|
+
);
|
|
2817
|
+
const normalizedAuthority = authorities.map((authority) =>
|
|
2818
|
+
authority === null ? null : JSON.stringify(authority),
|
|
2819
|
+
);
|
|
2820
|
+
const currentExact =
|
|
2821
|
+
authorities.every((authority) => authority !== null) &&
|
|
2822
|
+
normalizedAuthority[0] === normalizedAuthority[1];
|
|
2823
|
+
const current = currentExact ? authorities[0] : null;
|
|
2824
|
+
const expectedGrant = normalizeRecord(expectedGrantRecord);
|
|
2825
|
+
const normalizedRecords = contractValid ? authorityRecords.map(normalizeRecord) : [];
|
|
2826
|
+
const terminalRecords =
|
|
2827
|
+
expectedGrant === null
|
|
2828
|
+
? []
|
|
2829
|
+
: normalizedRecords.filter(
|
|
2830
|
+
(record) =>
|
|
2831
|
+
record !== null &&
|
|
2832
|
+
JSON.stringify(record.authority) === JSON.stringify(expectedGrant.authority),
|
|
2833
|
+
);
|
|
2834
|
+
const receiptExactShape = (receipt) =>
|
|
2835
|
+
exactKeys(receipt, [
|
|
2836
|
+
"generation",
|
|
2837
|
+
"pane",
|
|
2838
|
+
"seq",
|
|
2839
|
+
"inputSha256",
|
|
2840
|
+
"requestId",
|
|
2841
|
+
"authorityClientId",
|
|
2842
|
+
"ordinal",
|
|
2843
|
+
]) &&
|
|
2844
|
+
GENERATION.test(receipt.generation ?? "") &&
|
|
2845
|
+
safeIdentity(receipt.pane) &&
|
|
2846
|
+
Number.isSafeInteger(receipt.seq) &&
|
|
2847
|
+
receipt.seq >= 0 &&
|
|
2848
|
+
/^[0-9a-f]{64}$/u.test(receipt.inputSha256 ?? "") &&
|
|
2849
|
+
safeIdentity(receipt.requestId) &&
|
|
2850
|
+
safeIdentity(receipt.authorityClientId) &&
|
|
2851
|
+
Number.isSafeInteger(receipt.ordinal) &&
|
|
2852
|
+
receipt.ordinal >= 0;
|
|
2853
|
+
const postBoundaryReceipts = contractValid
|
|
2854
|
+
? rawReceipts.filter(
|
|
2855
|
+
(receipt) => Number.isSafeInteger(receipt?.ordinal) && receipt.ordinal >= receiptBoundary,
|
|
2856
|
+
)
|
|
2857
|
+
: [];
|
|
2858
|
+
const validPostBoundaryReceipts = postBoundaryReceipts.filter(receiptExactShape);
|
|
2859
|
+
const producerFilteredReceipts = validPostBoundaryReceipts.filter(
|
|
2860
|
+
(receipt) =>
|
|
2861
|
+
receipt.generation === expectedGeneration &&
|
|
2862
|
+
receipt.pane === expectedPane &&
|
|
2863
|
+
receipt.inputSha256 === expectedInputSha256 &&
|
|
2864
|
+
expectedRequestHmac !== null &&
|
|
2865
|
+
hmac("request", receipt.requestId) === expectedRequestHmac,
|
|
2866
|
+
);
|
|
2867
|
+
const receiptCandidatesExact =
|
|
2868
|
+
receiptCandidates.every(receiptExactShape) &&
|
|
2869
|
+
JSON.stringify(receiptCandidates) === JSON.stringify(producerFilteredReceipts);
|
|
2870
|
+
const receiptInputMismatch = validPostBoundaryReceipts.some(
|
|
2871
|
+
(receipt) =>
|
|
2872
|
+
receipt.generation === expectedGeneration &&
|
|
2873
|
+
receipt.pane === expectedPane &&
|
|
2874
|
+
receipt.inputSha256 !== expectedInputSha256,
|
|
2875
|
+
);
|
|
2876
|
+
const receiptRequestMismatch = validPostBoundaryReceipts.some(
|
|
2877
|
+
(receipt) =>
|
|
2878
|
+
receipt.generation === expectedGeneration &&
|
|
2879
|
+
receipt.pane === expectedPane &&
|
|
2880
|
+
receipt.inputSha256 === expectedInputSha256 &&
|
|
2881
|
+
(expectedRequestHmac === null || hmac("request", receipt.requestId) !== expectedRequestHmac),
|
|
2882
|
+
);
|
|
2883
|
+
const matchingReceiptCount = receiptCandidates.filter(
|
|
2884
|
+
(receipt) => receiptExactShape(receipt) && receipt.authorityClientId === expectedClientId,
|
|
2885
|
+
).length;
|
|
2886
|
+
const targetClient =
|
|
2887
|
+
current?.clients.find(({ clientId }) => clientId === expectedClientId) ?? null;
|
|
2888
|
+
const currentTerminalRecords =
|
|
2889
|
+
current === null
|
|
2890
|
+
? []
|
|
2891
|
+
: normalizedRecords.filter(
|
|
2892
|
+
(record) =>
|
|
2893
|
+
record !== null && JSON.stringify(record.authority) === JSON.stringify(current),
|
|
2894
|
+
);
|
|
2895
|
+
const identityTopology = (authority) =>
|
|
2896
|
+
JSON.stringify(
|
|
2897
|
+
authority?.clients?.map(({ clientId, surface, connectedRevision }) => ({
|
|
2898
|
+
clientId,
|
|
2899
|
+
surface,
|
|
2900
|
+
connectedRevision,
|
|
2901
|
+
})) ?? null,
|
|
2902
|
+
);
|
|
2903
|
+
const currentAllExpected =
|
|
2904
|
+
current !== null &&
|
|
2905
|
+
expectedClientId !== null &&
|
|
2906
|
+
[current.owners.input, current.owners.focus, current.owners.geometry].every(
|
|
2907
|
+
(owner) => owner === expectedClientId,
|
|
2908
|
+
);
|
|
2909
|
+
const axes = Object.freeze({
|
|
2910
|
+
selectorContractInvalid:
|
|
2911
|
+
!contractValid ||
|
|
2912
|
+
(requireReceipt &&
|
|
2913
|
+
currentAllExpected &&
|
|
2914
|
+
expectedGrant === null &&
|
|
2915
|
+
currentTerminalRecords.length > 0),
|
|
2916
|
+
webObservationTimeout: statuses.some((status) => status === "deadline"),
|
|
2917
|
+
webObservationInvalid:
|
|
2918
|
+
statuses.some((status) => !["ok", "deadline"].includes(status)) ||
|
|
2919
|
+
values.some(
|
|
2920
|
+
(value, index) =>
|
|
2921
|
+
value === null ||
|
|
2922
|
+
typeof value !== "object" ||
|
|
2923
|
+
value.semanticPaneId !== expectedPane ||
|
|
2924
|
+
value.generation !== expectedGeneration ||
|
|
2925
|
+
authorities[index] === null,
|
|
2926
|
+
),
|
|
2927
|
+
webCurrentMismatch: authorities.every((authority) => authority !== null) && !currentExact,
|
|
2928
|
+
receiptMissing: requireReceipt && receiptCandidates.length === 0,
|
|
2929
|
+
receiptAmbiguous: requireReceipt && receiptCandidates.length > 1,
|
|
2930
|
+
receiptRawInvalid:
|
|
2931
|
+
requireReceipt && validPostBoundaryReceipts.length !== postBoundaryReceipts.length,
|
|
2932
|
+
receiptInputMismatch: requireReceipt && receiptInputMismatch,
|
|
2933
|
+
receiptRequestMismatch: requireReceipt && receiptRequestMismatch,
|
|
2934
|
+
receiptCandidateMismatch: requireReceipt && !receiptCandidatesExact,
|
|
2935
|
+
receiptInvalid:
|
|
2936
|
+
requireReceipt &&
|
|
2937
|
+
(expectedRequestHmac === null ||
|
|
2938
|
+
validPostBoundaryReceipts.length !== postBoundaryReceipts.length ||
|
|
2939
|
+
receiptInputMismatch ||
|
|
2940
|
+
receiptRequestMismatch ||
|
|
2941
|
+
!receiptCandidatesExact),
|
|
2942
|
+
receiptTargetMismatch:
|
|
2943
|
+
requireReceipt && receiptCandidates.length === 1 && matchingReceiptCount !== 1,
|
|
2944
|
+
targetWebAbsent: expectedSurface === "web" && current !== null && targetClient === null,
|
|
2945
|
+
targetWebWrongSurface:
|
|
2946
|
+
expectedSurface === "web" && targetClient !== null && targetClient.surface !== "web",
|
|
2947
|
+
inputOwnerMismatch:
|
|
2948
|
+
current !== null && expectedClientId !== null && current.owners.input !== expectedClientId,
|
|
2949
|
+
focusOwnerMismatch:
|
|
2950
|
+
current !== null && expectedClientId !== null && current.owners.focus !== expectedClientId,
|
|
2951
|
+
geometryOwnerMismatch:
|
|
2952
|
+
current !== null && expectedClientId !== null && current.owners.geometry !== expectedClientId,
|
|
2953
|
+
currentRevisionMismatch:
|
|
2954
|
+
current !== null &&
|
|
2955
|
+
(current.revision <= (expectedBaseline?.revision ?? Number.MAX_SAFE_INTEGER) ||
|
|
2956
|
+
(expectedGrant !== null && current.revision !== expectedGrant.authority.revision)),
|
|
2957
|
+
currentGenerationMismatch:
|
|
2958
|
+
current !== null &&
|
|
2959
|
+
(current.generation !== expectedGeneration ||
|
|
2960
|
+
(expectedGrant !== null && current.generation !== expectedGrant.authority.generation)),
|
|
2961
|
+
currentSessionMismatch:
|
|
2962
|
+
current !== null &&
|
|
2963
|
+
(current.session !== expectedBaseline?.session ||
|
|
2964
|
+
(expectedGrant !== null && current.session !== expectedGrant.authority.session)),
|
|
2965
|
+
currentNativeYieldMismatch:
|
|
2966
|
+
current !== null &&
|
|
2967
|
+
(current.nativeGeometryYieldUntilMs !== expectedBaseline?.nativeGeometryYieldUntilMs ||
|
|
2968
|
+
(expectedGrant !== null &&
|
|
2969
|
+
current.nativeGeometryYieldUntilMs !==
|
|
2970
|
+
expectedGrant.authority.nativeGeometryYieldUntilMs)),
|
|
2971
|
+
currentTopologyMismatch:
|
|
2972
|
+
current !== null &&
|
|
2973
|
+
(identityTopology(current) !== identityTopology(expectedBaseline) ||
|
|
2974
|
+
(expectedGrant !== null &&
|
|
2975
|
+
JSON.stringify(current.clients) !== JSON.stringify(expectedGrant.authority.clients))),
|
|
2976
|
+
terminalRecordMissing: currentAllExpected && currentTerminalRecords.length === 0,
|
|
2977
|
+
terminalRecordMismatch:
|
|
2978
|
+
expectedGrant !== null &&
|
|
2979
|
+
terminalRecords.length > 0 &&
|
|
2980
|
+
!terminalRecords.some(({ ordinal }) => ordinal === expectedGrant.ordinal),
|
|
2981
|
+
boundaryOverflow,
|
|
2982
|
+
});
|
|
2983
|
+
const reasonByAxis = [
|
|
2984
|
+
["selectorContractInvalid", "selector-contract-invalid"],
|
|
2985
|
+
["webObservationTimeout", "web-observation-timeout"],
|
|
2986
|
+
["webObservationInvalid", "web-observation-invalid"],
|
|
2987
|
+
["webCurrentMismatch", "web-current-mismatch"],
|
|
2988
|
+
["receiptInvalid", "receipt-invalid"],
|
|
2989
|
+
["receiptMissing", "receipt-missing"],
|
|
2990
|
+
["receiptAmbiguous", "receipt-ambiguous"],
|
|
2991
|
+
["receiptTargetMismatch", "receipt-target-mismatch"],
|
|
2992
|
+
["targetWebAbsent", "target-web-absent"],
|
|
2993
|
+
["targetWebWrongSurface", "target-web-wrong-surface"],
|
|
2994
|
+
["inputOwnerMismatch", "input-owner-mismatch"],
|
|
2995
|
+
["focusOwnerMismatch", "focus-owner-mismatch"],
|
|
2996
|
+
["geometryOwnerMismatch", "geometry-owner-mismatch"],
|
|
2997
|
+
["currentRevisionMismatch", "current-revision-mismatch"],
|
|
2998
|
+
["currentGenerationMismatch", "current-generation-mismatch"],
|
|
2999
|
+
["currentSessionMismatch", "current-session-mismatch"],
|
|
3000
|
+
["currentNativeYieldMismatch", "current-native-yield-mismatch"],
|
|
3001
|
+
["currentTopologyMismatch", "current-topology-mismatch"],
|
|
3002
|
+
["terminalRecordMissing", "terminal-record-missing"],
|
|
3003
|
+
["terminalRecordMismatch", "terminal-record-mismatch"],
|
|
3004
|
+
["boundaryOverflow", "boundary-overflow"],
|
|
3005
|
+
];
|
|
3006
|
+
const reason = reasonByAxis.find(([axis]) => axes[axis])?.[1] ?? null;
|
|
3007
|
+
const authorityProjection = (authority, index) =>
|
|
3008
|
+
Object.freeze({
|
|
3009
|
+
page: index === 0 ? "chromium" : "electron",
|
|
3010
|
+
status: statuses[index],
|
|
3011
|
+
valid: authority !== null,
|
|
3012
|
+
paneHmac: hmac("post-input-web-pane", values[index]?.semanticPaneId ?? "invalid"),
|
|
3013
|
+
generationHmac: hmac("post-input-web-generation", authority?.generation ?? "invalid"),
|
|
3014
|
+
sessionHmac: hmac("post-input-web-session", authority?.session ?? "invalid"),
|
|
3015
|
+
revision: Number.isSafeInteger(authority?.revision) ? authority.revision : null,
|
|
3016
|
+
ownerHmac: hmac("post-input-web-owners", JSON.stringify(authority?.owners ?? null)),
|
|
3017
|
+
topologyHmac: hmac("post-input-web-topology", JSON.stringify(authority?.clients ?? null)),
|
|
3018
|
+
mutationHmac: hmac(
|
|
3019
|
+
"post-input-web-mutation",
|
|
3020
|
+
JSON.stringify(
|
|
3021
|
+
authority?.clients?.map(({ clientId, state, activityRevision }) => ({
|
|
3022
|
+
clientId,
|
|
3023
|
+
state,
|
|
3024
|
+
activityRevision,
|
|
3025
|
+
})) ?? null,
|
|
3026
|
+
),
|
|
3027
|
+
),
|
|
3028
|
+
});
|
|
3029
|
+
const boundedReceipts = postBoundaryReceipts.slice(-8);
|
|
3030
|
+
const safeAuthorityRecords = Array.isArray(authorityRecords) ? authorityRecords : [];
|
|
3031
|
+
const boundedRecords = safeAuthorityRecords.slice(-2);
|
|
3032
|
+
return Object.freeze({
|
|
3033
|
+
reason:
|
|
3034
|
+
reason === null || CARD5_POST_INPUT_PRECONDITION_REASONS.includes(reason)
|
|
3035
|
+
? reason
|
|
3036
|
+
: "selector-contract-invalid",
|
|
3037
|
+
axes,
|
|
3038
|
+
web: Object.freeze(authorities.map(authorityProjection)),
|
|
3039
|
+
receipt: Object.freeze({
|
|
3040
|
+
page: receiptPage,
|
|
3041
|
+
count: Math.min(postBoundaryReceipts.length, 8),
|
|
3042
|
+
overflow: postBoundaryReceipts.length > 8,
|
|
3043
|
+
validCount: Math.min(validPostBoundaryReceipts.length, 8),
|
|
3044
|
+
rawInvalidCount: Math.min(postBoundaryReceipts.length - validPostBoundaryReceipts.length, 8),
|
|
3045
|
+
unrelatedCount: Math.min(
|
|
3046
|
+
validPostBoundaryReceipts.length - producerFilteredReceipts.length,
|
|
3047
|
+
8,
|
|
3048
|
+
),
|
|
3049
|
+
candidateCount: Math.min(receiptCandidates.length, 8),
|
|
3050
|
+
candidateOverflow: receiptCandidates.length > 8,
|
|
3051
|
+
candidateExact: receiptCandidatesExact,
|
|
3052
|
+
matchingCount: Math.min(matchingReceiptCount, 8),
|
|
3053
|
+
pageHmac: hmac("post-input-receipt-page", receiptPage),
|
|
3054
|
+
clientHmac: hmac(
|
|
3055
|
+
"post-input-receipt-client",
|
|
3056
|
+
boundedReceipts.map((receipt) => receipt?.authorityClientId ?? "invalid").join("\0"),
|
|
3057
|
+
),
|
|
3058
|
+
requestHmac: hmac(
|
|
3059
|
+
"post-input-receipt-request",
|
|
3060
|
+
boundedReceipts.map((receipt) => receipt?.requestId ?? "invalid").join("\0"),
|
|
3061
|
+
),
|
|
3062
|
+
paneHmac: hmac(
|
|
3063
|
+
"post-input-receipt-pane",
|
|
3064
|
+
boundedReceipts.map((receipt) => receipt?.pane ?? "invalid").join("\0"),
|
|
3065
|
+
),
|
|
3066
|
+
generationHmac: hmac(
|
|
3067
|
+
"post-input-receipt-generation",
|
|
3068
|
+
boundedReceipts.map((receipt) => receipt?.generation ?? "invalid").join("\0"),
|
|
3069
|
+
),
|
|
3070
|
+
}),
|
|
3071
|
+
records: Object.freeze({
|
|
3072
|
+
count: Math.min(safeAuthorityRecords.length, 16),
|
|
3073
|
+
overflow: safeAuthorityRecords.length > 16 || boundaryOverflow === true,
|
|
3074
|
+
last: Object.freeze(
|
|
3075
|
+
boundedRecords.map((record) =>
|
|
3076
|
+
Object.freeze({
|
|
3077
|
+
ordinal: Number.isSafeInteger(record?.ordinal) ? record.ordinal : null,
|
|
3078
|
+
revision: Number.isSafeInteger(record?.revision) ? record.revision : null,
|
|
3079
|
+
ownerHmac: hmac(
|
|
3080
|
+
"post-input-precondition-record-owner",
|
|
3081
|
+
[record?.inputOwner, record?.focusOwner, record?.geometryOwner].join("\0"),
|
|
3082
|
+
),
|
|
3083
|
+
topologyHmac: hmac(
|
|
3084
|
+
"post-input-precondition-record-topology",
|
|
3085
|
+
JSON.stringify(normalizeClients(record?.clients)),
|
|
3086
|
+
),
|
|
3087
|
+
recordHmac: hmac(
|
|
3088
|
+
"post-input-precondition-record",
|
|
3089
|
+
JSON.stringify(normalizeRecord(record)),
|
|
3090
|
+
),
|
|
3091
|
+
}),
|
|
3092
|
+
),
|
|
3093
|
+
),
|
|
3094
|
+
}),
|
|
3095
|
+
});
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
/** Retains causal post-input samples so a terminal deadline cannot erase them. */
|
|
3099
|
+
export function advanceCard5PostInputAuthorityPreconditionHistory(
|
|
3100
|
+
previous,
|
|
3101
|
+
observation,
|
|
3102
|
+
webResults,
|
|
3103
|
+
) {
|
|
3104
|
+
const prior = previous ?? {
|
|
3105
|
+
firstInformative: null,
|
|
3106
|
+
lastSuccessful: null,
|
|
3107
|
+
terminal: null,
|
|
3108
|
+
};
|
|
3109
|
+
const statuses = Array.isArray(webResults) ? webResults.map((result) => result?.status) : [];
|
|
3110
|
+
const informative = observation?.reason !== "web-observation-timeout";
|
|
3111
|
+
const successful = statuses.length === 2 && statuses.every((status) => status === "ok");
|
|
3112
|
+
return Object.freeze({
|
|
3113
|
+
firstInformative: prior.firstInformative ?? (informative ? observation : null),
|
|
3114
|
+
lastSuccessful: successful ? observation : prior.lastSuccessful,
|
|
3115
|
+
terminal: observation,
|
|
3116
|
+
});
|
|
3117
|
+
}
|
|
3118
|
+
|
|
3119
|
+
/** Exact null-owner authority snapshot used before an explicit focus epoch. */
|
|
3120
|
+
export function sealCard5NullAuthority(authority, generation, evidenceKey) {
|
|
3121
|
+
const exactKeys = (value, keys) =>
|
|
3122
|
+
value !== null &&
|
|
3123
|
+
typeof value === "object" &&
|
|
3124
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
|
3125
|
+
const validClientId = (value) =>
|
|
3126
|
+
typeof value === "string" &&
|
|
3127
|
+
value.length >= 1 &&
|
|
3128
|
+
value.length <= 4_096 &&
|
|
3129
|
+
!/[\0\r\n]/u.test(value);
|
|
3130
|
+
if (
|
|
3131
|
+
!GENERATION.test(generation ?? "") ||
|
|
3132
|
+
authority?.generation !== generation ||
|
|
3133
|
+
!HMAC.test(evidenceKey ?? "") ||
|
|
3134
|
+
!GENERATION.test(authority?.session ?? "") ||
|
|
3135
|
+
!Number.isSafeInteger(authority?.revision) ||
|
|
3136
|
+
authority.revision < 0 ||
|
|
3137
|
+
!Number.isSafeInteger(authority?.nativeGeometryYieldUntilMs) ||
|
|
3138
|
+
authority.nativeGeometryYieldUntilMs < 0 ||
|
|
3139
|
+
!exactKeys(authority, [
|
|
3140
|
+
"generation",
|
|
3141
|
+
"session",
|
|
3142
|
+
"revision",
|
|
3143
|
+
"owners",
|
|
3144
|
+
"nativeGeometryYieldUntilMs",
|
|
3145
|
+
"clients",
|
|
3146
|
+
]) ||
|
|
3147
|
+
!exactKeys(authority?.owners, ["input", "focus", "geometry"]) ||
|
|
3148
|
+
!["input", "focus", "geometry"].every((kind) => authority.owners[kind] === null) ||
|
|
3149
|
+
!Array.isArray(authority.clients) ||
|
|
3150
|
+
authority.clients.length !== 3
|
|
3151
|
+
)
|
|
3152
|
+
return null;
|
|
3153
|
+
const clients = authority.clients.map((client) => ({
|
|
3154
|
+
clientId: client?.clientId,
|
|
3155
|
+
surface: client?.surface,
|
|
3156
|
+
state: client?.state,
|
|
3157
|
+
connectedRevision: client?.connectedRevision,
|
|
3158
|
+
activityRevision: client?.activityRevision,
|
|
3159
|
+
exact: exactKeys(client, [
|
|
3160
|
+
"clientId",
|
|
3161
|
+
"surface",
|
|
3162
|
+
"state",
|
|
3163
|
+
"connectedRevision",
|
|
3164
|
+
"activityRevision",
|
|
3165
|
+
]),
|
|
3166
|
+
}));
|
|
3167
|
+
if (
|
|
3168
|
+
clients.some(
|
|
3169
|
+
(client) =>
|
|
3170
|
+
!client.exact ||
|
|
3171
|
+
!validClientId(client.clientId) ||
|
|
3172
|
+
!["web", "opentui", "cli", "sdk", "native-tmux", "unknown"].includes(client.surface) ||
|
|
3173
|
+
!["foreground", "background"].includes(client.state) ||
|
|
3174
|
+
!Number.isSafeInteger(client.connectedRevision) ||
|
|
3175
|
+
client.connectedRevision < 1 ||
|
|
3176
|
+
!Number.isSafeInteger(client.activityRevision) ||
|
|
3177
|
+
client.activityRevision < 0,
|
|
3178
|
+
) ||
|
|
3179
|
+
new Set(clients.map(({ clientId }) => clientId)).size !== clients.length ||
|
|
3180
|
+
clients.filter(({ surface }) => surface === "opentui").length !== 1 ||
|
|
3181
|
+
clients.filter(({ surface }) => surface === "web").length !== 2
|
|
3182
|
+
)
|
|
3183
|
+
return null;
|
|
3184
|
+
const sortedClients = [...clients].sort((left, right) =>
|
|
3185
|
+
left.clientId.localeCompare(right.clientId),
|
|
3186
|
+
);
|
|
3187
|
+
const semanticTopology = JSON.stringify({
|
|
3188
|
+
generation: authority.generation,
|
|
3189
|
+
session: authority.session,
|
|
3190
|
+
owners: authority.owners,
|
|
3191
|
+
nativeGeometryYieldUntilMs: authority.nativeGeometryYieldUntilMs,
|
|
3192
|
+
clients: sortedClients.map(({ clientId, surface, state, connectedRevision }) => ({
|
|
3193
|
+
clientId,
|
|
3194
|
+
surface,
|
|
3195
|
+
state,
|
|
3196
|
+
connectedRevision,
|
|
3197
|
+
})),
|
|
3198
|
+
});
|
|
3199
|
+
const mutationTopology = JSON.stringify({
|
|
3200
|
+
revision: authority.revision,
|
|
3201
|
+
clients: sortedClients.map(({ clientId, surface, activityRevision }) => ({
|
|
3202
|
+
clientId,
|
|
3203
|
+
surface,
|
|
3204
|
+
activityRevision,
|
|
3205
|
+
})),
|
|
3206
|
+
});
|
|
3207
|
+
const hmac = (domain, value) =>
|
|
3208
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
3209
|
+
.update(`${domain}\0${value}`)
|
|
3210
|
+
.digest("hex");
|
|
3211
|
+
return Object.freeze({
|
|
3212
|
+
authorityRevision: authority.revision,
|
|
3213
|
+
authorityOwnerHmac: hmac("null-authority-owner", "none"),
|
|
3214
|
+
authorityTopologyHmac: hmac("null-authority-topology", semanticTopology),
|
|
3215
|
+
authorityHmac: hmac("null-authority", semanticTopology),
|
|
3216
|
+
authorityMutationHmac: hmac("null-authority-mutation", mutationTopology),
|
|
3217
|
+
});
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
/** Bounded reason vector for the two-view exact null-authority join. */
|
|
3221
|
+
export function assessCard5NullAuthorityPair({
|
|
3222
|
+
authorities,
|
|
3223
|
+
generations,
|
|
3224
|
+
minimumRevision,
|
|
3225
|
+
releaseRevisions = [],
|
|
3226
|
+
evidenceKey,
|
|
3227
|
+
}) {
|
|
3228
|
+
const hmac = (domain, value) =>
|
|
3229
|
+
typeof value === "string" && value.length > 0 && HMAC.test(evidenceKey ?? "")
|
|
3230
|
+
? createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
3231
|
+
.update(`${domain}\0${value}`)
|
|
3232
|
+
.digest("hex")
|
|
3233
|
+
: null;
|
|
3234
|
+
const exactKeys = (value, keys) =>
|
|
3235
|
+
value !== null &&
|
|
3236
|
+
typeof value === "object" &&
|
|
3237
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
|
3238
|
+
const classify = (authority, generation) => {
|
|
3239
|
+
let reason = "exact";
|
|
3240
|
+
if (authority === null || typeof authority !== "object") reason = "authority-missing";
|
|
3241
|
+
else if (!GENERATION.test(generation ?? "") || authority.generation !== generation)
|
|
3242
|
+
reason = "generation-mismatch";
|
|
3243
|
+
else if (!GENERATION.test(authority.session ?? "")) reason = "session-invalid";
|
|
3244
|
+
else if (!Number.isSafeInteger(authority.revision) || authority.revision < 0)
|
|
3245
|
+
reason = "revision-invalid";
|
|
3246
|
+
else if (
|
|
3247
|
+
!exactKeys(authority, [
|
|
3248
|
+
"generation",
|
|
3249
|
+
"session",
|
|
3250
|
+
"revision",
|
|
3251
|
+
"owners",
|
|
3252
|
+
"nativeGeometryYieldUntilMs",
|
|
3253
|
+
"clients",
|
|
3254
|
+
]) ||
|
|
3255
|
+
!exactKeys(authority.owners, ["input", "focus", "geometry"])
|
|
3256
|
+
)
|
|
3257
|
+
reason = "schema-invalid";
|
|
3258
|
+
else if (
|
|
3259
|
+
![authority.owners.input, authority.owners.focus, authority.owners.geometry].every(
|
|
3260
|
+
(owner) => owner === null,
|
|
3261
|
+
)
|
|
3262
|
+
)
|
|
3263
|
+
reason = "owner-nonnull";
|
|
3264
|
+
else if (!Array.isArray(authority.clients) || authority.clients.length !== 3)
|
|
3265
|
+
reason = "client-cardinality";
|
|
3266
|
+
const sealed =
|
|
3267
|
+
reason === "exact" ? sealCard5NullAuthority(authority, generation, evidenceKey) : null;
|
|
3268
|
+
if (reason === "exact" && sealed === null) reason = "client-schema-invalid";
|
|
3269
|
+
return Object.freeze({
|
|
3270
|
+
reason,
|
|
3271
|
+
revision:
|
|
3272
|
+
Number.isSafeInteger(authority?.revision) && authority.revision >= 0
|
|
3273
|
+
? Math.min(authority.revision, 0xffff_ffff)
|
|
3274
|
+
: null,
|
|
3275
|
+
generationHmac: hmac("null-view-generation", authority?.generation),
|
|
3276
|
+
sessionHmac: hmac("null-view-session", authority?.session),
|
|
3277
|
+
ownerState: exactKeys(authority?.owners, ["input", "focus", "geometry"])
|
|
3278
|
+
? Object.freeze({
|
|
3279
|
+
input: authority.owners.input === null,
|
|
3280
|
+
focus: authority.owners.focus === null,
|
|
3281
|
+
geometry: authority.owners.geometry === null,
|
|
3282
|
+
})
|
|
3283
|
+
: null,
|
|
3284
|
+
clientCount: Array.isArray(authority?.clients) ? Math.min(authority.clients.length, 4) : null,
|
|
3285
|
+
sealed,
|
|
3286
|
+
});
|
|
3287
|
+
};
|
|
3288
|
+
if (
|
|
3289
|
+
!Array.isArray(authorities) ||
|
|
3290
|
+
authorities.length !== 2 ||
|
|
3291
|
+
!Array.isArray(generations) ||
|
|
3292
|
+
generations.length !== 2 ||
|
|
3293
|
+
!Number.isSafeInteger(minimumRevision) ||
|
|
3294
|
+
minimumRevision < 0 ||
|
|
3295
|
+
!Array.isArray(releaseRevisions) ||
|
|
3296
|
+
releaseRevisions.length > 4 ||
|
|
3297
|
+
releaseRevisions.some((revision) => !Number.isSafeInteger(revision) || revision < 0) ||
|
|
3298
|
+
!HMAC.test(evidenceKey ?? "")
|
|
3299
|
+
) {
|
|
3300
|
+
return Object.freeze({ passed: false, reason: "contract-invalid", evidence: null });
|
|
3301
|
+
}
|
|
3302
|
+
const views = authorities.map((authority, index) => classify(authority, generations[index]));
|
|
3303
|
+
let reason = views.find((view) => view.reason !== "exact")?.reason ?? null;
|
|
3304
|
+
const [left, right] = views.map((view) => view.sealed);
|
|
3305
|
+
const requiredReleaseRevision = Math.max(minimumRevision, ...releaseRevisions);
|
|
3306
|
+
if (reason === null && left.authorityRevision <= minimumRevision)
|
|
3307
|
+
reason = "revision-not-advanced";
|
|
3308
|
+
else if (reason === null && left.authorityRevision < requiredReleaseRevision)
|
|
3309
|
+
reason = "release-revision-not-settled";
|
|
3310
|
+
else if (reason === null && left.authorityRevision !== right.authorityRevision)
|
|
3311
|
+
reason = "cross-revision";
|
|
3312
|
+
else if (reason === null && left.authorityHmac !== right.authorityHmac)
|
|
3313
|
+
reason = "cross-authority";
|
|
3314
|
+
else if (reason === null && left.authorityOwnerHmac !== right.authorityOwnerHmac)
|
|
3315
|
+
reason = "cross-owner";
|
|
3316
|
+
else if (reason === null && left.authorityTopologyHmac !== right.authorityTopologyHmac)
|
|
3317
|
+
reason = "cross-topology";
|
|
3318
|
+
else if (reason === null && left.authorityMutationHmac !== right.authorityMutationHmac)
|
|
3319
|
+
reason = "cross-mutation";
|
|
3320
|
+
const observation = Object.freeze({
|
|
3321
|
+
reason: reason ?? "exact",
|
|
3322
|
+
views: Object.freeze(
|
|
3323
|
+
views.map(
|
|
3324
|
+
({ reason: viewReason, revision, generationHmac, sessionHmac, ownerState, clientCount }) =>
|
|
3325
|
+
Object.freeze({
|
|
3326
|
+
reason: viewReason,
|
|
3327
|
+
revision,
|
|
3328
|
+
generationHmac,
|
|
3329
|
+
sessionHmac,
|
|
3330
|
+
ownerState,
|
|
3331
|
+
clientCount,
|
|
3332
|
+
}),
|
|
3333
|
+
),
|
|
3334
|
+
),
|
|
3335
|
+
});
|
|
3336
|
+
return reason === null
|
|
3337
|
+
? Object.freeze({ passed: true, reason: null, evidence: left, observation })
|
|
3338
|
+
: Object.freeze({ passed: false, reason, evidence: null, observation });
|
|
3339
|
+
}
|
|
3340
|
+
|
|
3341
|
+
export function mergeCard5SemanticAuthorityEvidence(left, right, previousRevision = null) {
|
|
3342
|
+
const exact = (value) =>
|
|
3343
|
+
HMAC.test(value?.authorityHmac ?? "") &&
|
|
3344
|
+
HMAC.test(value?.authorityOwnerHmac ?? "") &&
|
|
3345
|
+
HMAC.test(value?.authorityTopologyHmac ?? "") &&
|
|
3346
|
+
HMAC.test(value?.authorityMutationHmac ?? "") &&
|
|
3347
|
+
Number.isSafeInteger(value?.authorityRevision) &&
|
|
3348
|
+
value.authorityRevision >= 0;
|
|
3349
|
+
if (!exact(left) || !exact(right)) {
|
|
3350
|
+
return Object.freeze({ status: "invalid", evidence: null });
|
|
3351
|
+
}
|
|
3352
|
+
if (
|
|
3353
|
+
left.authorityHmac !== right.authorityHmac ||
|
|
3354
|
+
left.authorityOwnerHmac !== right.authorityOwnerHmac ||
|
|
3355
|
+
left.authorityTopologyHmac !== right.authorityTopologyHmac
|
|
3356
|
+
) {
|
|
3357
|
+
return Object.freeze({ status: "semantic-mismatch", evidence: null });
|
|
3358
|
+
}
|
|
3359
|
+
const authorityRevision = Math.max(left.authorityRevision, right.authorityRevision);
|
|
3360
|
+
if (
|
|
3361
|
+
previousRevision !== null &&
|
|
3362
|
+
(!Number.isSafeInteger(previousRevision) ||
|
|
3363
|
+
previousRevision < 0 ||
|
|
3364
|
+
authorityRevision < previousRevision)
|
|
3365
|
+
) {
|
|
3366
|
+
return Object.freeze({ status: "revision-regressed", evidence: null });
|
|
3367
|
+
}
|
|
3368
|
+
const latest = left.authorityRevision >= right.authorityRevision ? left : right;
|
|
3369
|
+
return Object.freeze({
|
|
3370
|
+
status: "exact",
|
|
3371
|
+
evidence: Object.freeze({
|
|
3372
|
+
...left,
|
|
3373
|
+
authorityRevision,
|
|
3374
|
+
authorityMutationHmac: latest.authorityMutationHmac,
|
|
3375
|
+
}),
|
|
3376
|
+
});
|
|
3377
|
+
}
|
|
3378
|
+
|
|
3379
|
+
export function card5AuthorityActivityWithinCap(activity, cap = 64) {
|
|
3380
|
+
const exactKeys = (value, keys) =>
|
|
3381
|
+
value !== null &&
|
|
3382
|
+
typeof value === "object" &&
|
|
3383
|
+
Object.keys(value).sort().join("\0") === [...keys].sort().join("\0");
|
|
3384
|
+
if (
|
|
3385
|
+
!exactKeys(activity, ["count", "overflow", "events", "geometrySettlements"]) ||
|
|
3386
|
+
!Number.isSafeInteger(cap) ||
|
|
3387
|
+
cap < 1 ||
|
|
3388
|
+
cap > 64 ||
|
|
3389
|
+
!Number.isSafeInteger(activity?.count) ||
|
|
3390
|
+
activity.count < 0 ||
|
|
3391
|
+
activity.count > cap ||
|
|
3392
|
+
activity?.overflow !== false ||
|
|
3393
|
+
!Array.isArray(activity?.events) ||
|
|
3394
|
+
activity.events.length !== activity.count
|
|
3395
|
+
)
|
|
3396
|
+
return false;
|
|
3397
|
+
const HMAC = /^[0-9a-f]{64}$/u;
|
|
3398
|
+
const geometryOutcomes = new Set([
|
|
3399
|
+
"ok",
|
|
3400
|
+
"geometry-authority-conflict",
|
|
3401
|
+
"authority-timeout",
|
|
3402
|
+
"viewport-timeout",
|
|
3403
|
+
"stream-closed",
|
|
3404
|
+
"lifecycle-retired",
|
|
3405
|
+
"failed",
|
|
3406
|
+
]);
|
|
3407
|
+
let pendingGeometry = null;
|
|
3408
|
+
let geometryOperationOrdinal = 0;
|
|
3409
|
+
const successfulGeometry = [];
|
|
3410
|
+
for (const [index, event] of activity.events.entries()) {
|
|
3411
|
+
if (
|
|
3412
|
+
!exactKeys(event, [
|
|
3413
|
+
"ordinal",
|
|
3414
|
+
"surface",
|
|
3415
|
+
"kind",
|
|
3416
|
+
"outcome",
|
|
3417
|
+
"operationOrdinal",
|
|
3418
|
+
"dimensionsHmac",
|
|
3419
|
+
]) ||
|
|
3420
|
+
event.ordinal !== index + 1 ||
|
|
3421
|
+
!["web", "opentui"].includes(event.surface) ||
|
|
3422
|
+
!["focus", "geometry", "input"].includes(event.kind)
|
|
3423
|
+
)
|
|
3424
|
+
return false;
|
|
3425
|
+
if (event.surface === "opentui" && event.kind !== "focus") return false;
|
|
3426
|
+
if (event.kind !== "geometry") {
|
|
3427
|
+
if (
|
|
3428
|
+
pendingGeometry !== null ||
|
|
3429
|
+
event.outcome !== "ok" ||
|
|
3430
|
+
event.operationOrdinal !== null ||
|
|
3431
|
+
event.dimensionsHmac !== null
|
|
3432
|
+
)
|
|
3433
|
+
return false;
|
|
3434
|
+
continue;
|
|
3435
|
+
}
|
|
3436
|
+
if (
|
|
3437
|
+
!HMAC.test(event.dimensionsHmac ?? "") ||
|
|
3438
|
+
!Number.isSafeInteger(event.operationOrdinal) ||
|
|
3439
|
+
event.operationOrdinal < 1
|
|
3440
|
+
)
|
|
3441
|
+
return false;
|
|
3442
|
+
if (event.outcome === "attempt") {
|
|
3443
|
+
if (pendingGeometry !== null) return false;
|
|
3444
|
+
geometryOperationOrdinal += 1;
|
|
3445
|
+
if (event.operationOrdinal !== geometryOperationOrdinal) return false;
|
|
3446
|
+
pendingGeometry = Object.freeze({
|
|
3447
|
+
operationOrdinal: event.operationOrdinal,
|
|
3448
|
+
dimensionsHmac: event.dimensionsHmac,
|
|
3449
|
+
});
|
|
3450
|
+
continue;
|
|
3451
|
+
}
|
|
3452
|
+
if (
|
|
3453
|
+
pendingGeometry === null ||
|
|
3454
|
+
event.operationOrdinal !== pendingGeometry.operationOrdinal ||
|
|
3455
|
+
event.dimensionsHmac !== pendingGeometry.dimensionsHmac ||
|
|
3456
|
+
!geometryOutcomes.has(event.outcome)
|
|
3457
|
+
)
|
|
3458
|
+
return false;
|
|
3459
|
+
if (event.outcome === "ok") successfulGeometry.push(event);
|
|
3460
|
+
pendingGeometry = null;
|
|
3461
|
+
}
|
|
3462
|
+
// A single final attempt may still be in flight while the bounded observer
|
|
3463
|
+
// samples; every other attempt must have one adjacent terminal outcome.
|
|
3464
|
+
const settlements = activity.geometrySettlements;
|
|
3465
|
+
if (
|
|
3466
|
+
!Array.isArray(settlements) ||
|
|
3467
|
+
settlements.length !== successfulGeometry.length ||
|
|
3468
|
+
settlements.length > 16
|
|
3469
|
+
)
|
|
3470
|
+
return false;
|
|
3471
|
+
const requestHmacs = new Set();
|
|
3472
|
+
for (const [index, receipt] of settlements.entries()) {
|
|
3473
|
+
if (
|
|
3474
|
+
!exactKeys(receipt, [
|
|
3475
|
+
"ordinal",
|
|
3476
|
+
"operationOrdinal",
|
|
3477
|
+
"requestHmac",
|
|
3478
|
+
"clientHmac",
|
|
3479
|
+
"dimensionsHmac",
|
|
3480
|
+
]) ||
|
|
3481
|
+
receipt.ordinal !== index ||
|
|
3482
|
+
receipt.operationOrdinal !== successfulGeometry[index]?.operationOrdinal ||
|
|
3483
|
+
receipt.dimensionsHmac !== successfulGeometry[index]?.dimensionsHmac ||
|
|
3484
|
+
!HMAC.test(receipt.requestHmac ?? "") ||
|
|
3485
|
+
!HMAC.test(receipt.clientHmac ?? "") ||
|
|
3486
|
+
requestHmacs.has(receipt.requestHmac)
|
|
3487
|
+
)
|
|
3488
|
+
return false;
|
|
3489
|
+
requestHmacs.add(receipt.requestHmac);
|
|
3490
|
+
}
|
|
3491
|
+
return true;
|
|
3492
|
+
}
|
|
3493
|
+
|
|
3494
|
+
const CARD5_AUTHORITY_KINDS = Object.freeze(["input", "focus", "geometry"]);
|
|
3495
|
+
|
|
3496
|
+
/**
|
|
3497
|
+
* Fail-closed validation plus a bounded, identity-free projection of the exact
|
|
3498
|
+
* Web authority-release transaction. The `passed` predicate intentionally
|
|
3499
|
+
* mirrors the ProductRig acceptance contract; the projection exists only so a
|
|
3500
|
+
* terminal failure retains the rejected conjunct.
|
|
3501
|
+
*/
|
|
3502
|
+
export function assessCard5WebAuthorityRelease({
|
|
3503
|
+
results,
|
|
3504
|
+
expectedAuthorities,
|
|
3505
|
+
workspaceHmac,
|
|
3506
|
+
generationHmac,
|
|
3507
|
+
runtimeSessionHmac,
|
|
3508
|
+
paneHmac,
|
|
3509
|
+
requestHmacs,
|
|
3510
|
+
clientHmacs,
|
|
3511
|
+
}) {
|
|
3512
|
+
const expected = Array.isArray(expectedAuthorities)
|
|
3513
|
+
? expectedAuthorities.filter((authority) => CARD5_AUTHORITY_KINDS.includes(authority))
|
|
3514
|
+
: [];
|
|
3515
|
+
const expectedSet = new Set(expected);
|
|
3516
|
+
const expectedValid =
|
|
3517
|
+
expected.length === new Set(expected).size &&
|
|
3518
|
+
expected.length <= CARD5_AUTHORITY_KINDS.length &&
|
|
3519
|
+
HMAC.test(workspaceHmac ?? "") &&
|
|
3520
|
+
HMAC.test(generationHmac ?? "") &&
|
|
3521
|
+
HMAC.test(runtimeSessionHmac ?? "") &&
|
|
3522
|
+
HMAC.test(paneHmac ?? "") &&
|
|
3523
|
+
Array.isArray(requestHmacs) &&
|
|
3524
|
+
requestHmacs.length > 0 &&
|
|
3525
|
+
requestHmacs.length <= 2 &&
|
|
3526
|
+
requestHmacs.every((value) => HMAC.test(value ?? "")) &&
|
|
3527
|
+
exactKeys(clientHmacs, CARD5_AUTHORITY_KINDS) &&
|
|
3528
|
+
CARD5_AUTHORITY_KINDS.every((authority) =>
|
|
3529
|
+
expectedSet.has(authority) ? HMAC.test(clientHmacs[authority] ?? "") : true,
|
|
3530
|
+
);
|
|
3531
|
+
const sourceResults = Array.isArray(results) ? results : [];
|
|
3532
|
+
const resultOverflow = !Array.isArray(results) || sourceResults.length > 2;
|
|
3533
|
+
const pages = [];
|
|
3534
|
+
const receipts = [];
|
|
3535
|
+
let receiptOverflow = false;
|
|
3536
|
+
for (const [pageOrdinal, result] of sourceResults.slice(0, 2).entries()) {
|
|
3537
|
+
const sourceReceipts = Array.isArray(result?.receipts) ? result.receipts : [];
|
|
3538
|
+
const remaining = Math.max(0, 3 - receipts.length);
|
|
3539
|
+
if (!Array.isArray(result?.receipts) || sourceReceipts.length > remaining)
|
|
3540
|
+
receiptOverflow = true;
|
|
3541
|
+
const page = Object.freeze({
|
|
3542
|
+
pageOrdinal,
|
|
3543
|
+
pageHmac: HMAC.test(result?.pageHmac ?? "") ? result.pageHmac : null,
|
|
3544
|
+
localClientHmac: HMAC.test(result?.localClientHmac ?? "") ? result.localClientHmac : null,
|
|
3545
|
+
preOwnerTupleHmac: HMAC.test(result?.preOwnerTupleHmac ?? "")
|
|
3546
|
+
? result.preOwnerTupleHmac
|
|
3547
|
+
: null,
|
|
3548
|
+
preRevisionHmac: HMAC.test(result?.preRevisionHmac ?? "") ? result.preRevisionHmac : null,
|
|
3549
|
+
statusExact: result?.status === "exact",
|
|
3550
|
+
receiptCount: boundedInteger(sourceReceipts.length, 3),
|
|
3551
|
+
});
|
|
3552
|
+
pages.push(page);
|
|
3553
|
+
for (const receipt of sourceReceipts.slice(0, remaining)) {
|
|
3554
|
+
const authority = CARD5_AUTHORITY_KINDS.includes(receipt?.authority)
|
|
3555
|
+
? receipt.authority
|
|
3556
|
+
: null;
|
|
3557
|
+
receipts.push(
|
|
3558
|
+
Object.freeze({
|
|
3559
|
+
pageOrdinal,
|
|
3560
|
+
pageHmac: page.pageHmac,
|
|
3561
|
+
localClientHmac: page.localClientHmac,
|
|
3562
|
+
authority,
|
|
3563
|
+
released: receipt?.status === "released",
|
|
3564
|
+
operationOrdinalValid:
|
|
3565
|
+
Number.isSafeInteger(receipt?.operationOrdinal) && receipt.operationOrdinal >= 1,
|
|
3566
|
+
revisionOrderValid:
|
|
3567
|
+
Number.isSafeInteger(receipt?.beforeRevision) &&
|
|
3568
|
+
receipt.beforeRevision >= 0 &&
|
|
3569
|
+
Number.isSafeInteger(receipt?.afterRevision) &&
|
|
3570
|
+
receipt.afterRevision > receipt.beforeRevision,
|
|
3571
|
+
workspaceMatch: receipt?.workspaceHmac === workspaceHmac,
|
|
3572
|
+
generationMatch: receipt?.generationHmac === generationHmac,
|
|
3573
|
+
runtimeSessionMatch: receipt?.runtimeSessionHmac === runtimeSessionHmac,
|
|
3574
|
+
paneMatch: receipt?.paneHmac === paneHmac,
|
|
3575
|
+
requestMatch:
|
|
3576
|
+
HMAC.test(receipt?.requestHmac ?? "") && requestHmacs?.includes(receipt.requestHmac),
|
|
3577
|
+
clientMatch:
|
|
3578
|
+
authority !== null &&
|
|
3579
|
+
HMAC.test(receipt?.clientHmac ?? "") &&
|
|
3580
|
+
receipt.clientHmac === clientHmacs?.[authority],
|
|
3581
|
+
requestHmac: HMAC.test(receipt?.requestHmac ?? "") ? receipt.requestHmac : null,
|
|
3582
|
+
clientHmac: HMAC.test(receipt?.clientHmac ?? "") ? receipt.clientHmac : null,
|
|
3583
|
+
operationOrdinal: boundedInteger(receipt?.operationOrdinal, 0xffff_ffff),
|
|
3584
|
+
beforeRevision: boundedInteger(receipt?.beforeRevision, 0xffff_ffff),
|
|
3585
|
+
afterRevision: boundedInteger(receipt?.afterRevision, 0xffff_ffff),
|
|
3586
|
+
}),
|
|
3587
|
+
);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
const actualReceiptCount = sourceResults.reduce(
|
|
3591
|
+
(count, result) => count + (Array.isArray(result?.receipts) ? result.receipts.length : 0),
|
|
3592
|
+
0,
|
|
3593
|
+
);
|
|
3594
|
+
const authorityCardinality = Object.freeze(
|
|
3595
|
+
Object.fromEntries(
|
|
3596
|
+
CARD5_AUTHORITY_KINDS.map((authority) => [
|
|
3597
|
+
authority,
|
|
3598
|
+
receipts.filter((receipt) => receipt.authority === authority).length ===
|
|
3599
|
+
(expectedSet.has(authority) ? 1 : 0),
|
|
3600
|
+
]),
|
|
3601
|
+
),
|
|
3602
|
+
);
|
|
3603
|
+
const axes = Object.freeze({
|
|
3604
|
+
inputCardinality: !authorityCardinality.input,
|
|
3605
|
+
focusCardinality: !authorityCardinality.focus,
|
|
3606
|
+
geometryCardinality: !authorityCardinality.geometry,
|
|
3607
|
+
resultStatus: pages.some((page) => !page.statusExact),
|
|
3608
|
+
resultCount: sourceResults.length !== 2,
|
|
3609
|
+
receiptCount: actualReceiptCount !== expected.length,
|
|
3610
|
+
releasedStatus: receipts.some((receipt) => !receipt.released),
|
|
3611
|
+
operationOrdinal: receipts.some((receipt) => !receipt.operationOrdinalValid),
|
|
3612
|
+
revisionOrder: receipts.some((receipt) => !receipt.revisionOrderValid),
|
|
3613
|
+
workspace: receipts.some((receipt) => !receipt.workspaceMatch),
|
|
3614
|
+
generation: receipts.some((receipt) => !receipt.generationMatch),
|
|
3615
|
+
runtimeSession: receipts.some((receipt) => !receipt.runtimeSessionMatch),
|
|
3616
|
+
pane: receipts.some((receipt) => !receipt.paneMatch),
|
|
3617
|
+
request: receipts.some((receipt) => !receipt.requestMatch),
|
|
3618
|
+
client: receipts.some((receipt) => !receipt.clientMatch),
|
|
3619
|
+
overflow: resultOverflow || receiptOverflow,
|
|
3620
|
+
contract: !expectedValid,
|
|
3621
|
+
});
|
|
3622
|
+
const passed =
|
|
3623
|
+
expectedValid &&
|
|
3624
|
+
sourceResults.length === 2 &&
|
|
3625
|
+
!resultOverflow &&
|
|
3626
|
+
!receiptOverflow &&
|
|
3627
|
+
Object.values(axes).every((value) => value === false);
|
|
3628
|
+
return Object.freeze({
|
|
3629
|
+
passed,
|
|
3630
|
+
observation: Object.freeze({
|
|
3631
|
+
version: 1,
|
|
3632
|
+
operation: "card5-web-release",
|
|
3633
|
+
expectedReceiptCount: boundedInteger(expected.length, 3),
|
|
3634
|
+
actualReceiptCount: boundedInteger(actualReceiptCount, 3),
|
|
3635
|
+
resultCount: boundedInteger(sourceResults.length, 2),
|
|
3636
|
+
resultOverflow,
|
|
3637
|
+
receiptOverflow,
|
|
3638
|
+
authorityCardinality,
|
|
3639
|
+
axes,
|
|
3640
|
+
pages: Object.freeze(pages),
|
|
3641
|
+
receipts: Object.freeze(receipts),
|
|
3642
|
+
}),
|
|
3643
|
+
});
|
|
3644
|
+
}
|
|
3645
|
+
|
|
3646
|
+
export function boundedCard5TuiFocusFailureObservation(input) {
|
|
3647
|
+
const reasons = new Set([
|
|
3648
|
+
"focus-contract-invalid",
|
|
3649
|
+
"focus-presentation-missing",
|
|
3650
|
+
"focus-presentation-invalid",
|
|
3651
|
+
"focus-presentation-ambiguous",
|
|
3652
|
+
"focus-presentation-mismatch",
|
|
3653
|
+
"focus-convergence-changed",
|
|
3654
|
+
"focus-authority-unowned",
|
|
3655
|
+
"focus-release-unsettled",
|
|
3656
|
+
"focus-transition-contract-invalid",
|
|
3657
|
+
"focus-blur-receipt-invalid",
|
|
3658
|
+
"focus-focus-receipt-invalid",
|
|
3659
|
+
"focus-blur-lifecycle-invalid",
|
|
3660
|
+
"focus-claim-cardinality",
|
|
3661
|
+
"focus-claim-lifecycle-invalid",
|
|
3662
|
+
"focus-web-release-invalid",
|
|
3663
|
+
]);
|
|
3664
|
+
const projected = boundedCard5HostFailureObservation({
|
|
3665
|
+
reason: "stability-timeout",
|
|
3666
|
+
focusDivergenceAxes: input?.axes,
|
|
3667
|
+
focusCandidates: input?.candidate ? [input.candidate] : input?.candidates,
|
|
3668
|
+
});
|
|
3669
|
+
return Object.freeze({
|
|
3670
|
+
operation: "card5-tui-focused-pane",
|
|
3671
|
+
reason: reasons.has(input?.reason) ? input.reason : "focus-contract-invalid",
|
|
3672
|
+
focusDivergenceAxes: projected.focusDivergenceAxes,
|
|
3673
|
+
focusCandidates: projected.focusCandidates,
|
|
3674
|
+
webRelease:
|
|
3675
|
+
input?.webRelease?.version === 1 && input.webRelease?.operation === "card5-web-release"
|
|
3676
|
+
? input.webRelease
|
|
3677
|
+
: null,
|
|
3678
|
+
});
|
|
3679
|
+
}
|
|
3680
|
+
|
|
3681
|
+
export function assessCard5TuiHandoffInput({
|
|
3682
|
+
records,
|
|
3683
|
+
hostReceipt,
|
|
3684
|
+
payload,
|
|
3685
|
+
expectedPane,
|
|
3686
|
+
expectedCanonical,
|
|
3687
|
+
inputFingerprintKey,
|
|
3688
|
+
evidenceKey,
|
|
3689
|
+
}) {
|
|
3690
|
+
const fail = (reason) => Object.freeze({ passed: false, reason, evidence: null });
|
|
3691
|
+
if (
|
|
3692
|
+
!Array.isArray(records) ||
|
|
3693
|
+
typeof payload !== "string" ||
|
|
3694
|
+
typeof expectedPane !== "string" ||
|
|
3695
|
+
expectedPane.length < 1 ||
|
|
3696
|
+
!expectedCanonical ||
|
|
3697
|
+
!GENERATION.test(expectedCanonical.generation ?? "") ||
|
|
3698
|
+
typeof expectedCanonical.incarnation !== "string" ||
|
|
3699
|
+
expectedCanonical.incarnation.length < 1 ||
|
|
3700
|
+
!Number.isSafeInteger(expectedCanonical.revision) ||
|
|
3701
|
+
!CANONICAL_STATE_HASH.test(expectedCanonical.canonicalStateHash ?? "") ||
|
|
3702
|
+
!/^opentui:[1-9]\d*$/u.test(expectedCanonical.processId ?? "") ||
|
|
3703
|
+
expectedCanonical.clockId !== "opentui-performance-now" ||
|
|
3704
|
+
!/^[0-9a-f]{64}$/u.test(inputFingerprintKey ?? "") ||
|
|
3705
|
+
!/^[0-9a-f]{64}$/u.test(evidenceKey ?? "")
|
|
3706
|
+
)
|
|
3707
|
+
return fail("input-contract-invalid");
|
|
3708
|
+
if (!isExactCard5TuiHostInputReceipt(hostReceipt, payload)) return fail("host-receipt-invalid");
|
|
3709
|
+
const origins = records.filter((record) => record?.type === "performance.input-origin");
|
|
3710
|
+
if (origins.length !== 1)
|
|
3711
|
+
return fail(origins.length === 0 ? "input-origin-missing" : "input-origin-duplicate");
|
|
3712
|
+
const [origin] = origins;
|
|
3713
|
+
const fingerprint = createHmac("sha256", inputFingerprintKey)
|
|
3714
|
+
.update(origin.traceId ?? "")
|
|
3715
|
+
.update("\0")
|
|
3716
|
+
.update(payload)
|
|
3717
|
+
.digest("hex");
|
|
3718
|
+
if (
|
|
3719
|
+
typeof origin.traceId !== "string" ||
|
|
3720
|
+
origin.traceId.length < 1 ||
|
|
3721
|
+
origin.origin !== "bracketed-paste" ||
|
|
3722
|
+
origin.parserConsumption !== "paste-event" ||
|
|
3723
|
+
origin.clockKind !== "performance-now" ||
|
|
3724
|
+
!Number.isFinite(origin.atMicros) ||
|
|
3725
|
+
origin.payloadByteCount !== Buffer.byteLength(payload) ||
|
|
3726
|
+
origin.payloadFingerprint !== fingerprint ||
|
|
3727
|
+
origin.semanticPaneId !== expectedPane ||
|
|
3728
|
+
origin.generation !== expectedCanonical.generation ||
|
|
3729
|
+
origin.incarnation !== expectedCanonical.incarnation ||
|
|
3730
|
+
origin.revision !== expectedCanonical.revision ||
|
|
3731
|
+
origin.stateHash !== expectedCanonical.canonicalStateHash ||
|
|
3732
|
+
origin.processId !== expectedCanonical.processId ||
|
|
3733
|
+
origin.clockId !== expectedCanonical.clockId
|
|
3734
|
+
)
|
|
3735
|
+
return fail("input-origin-mismatch");
|
|
3736
|
+
const exactTrace = (type, predicate = () => true) =>
|
|
3737
|
+
records.filter(
|
|
3738
|
+
(record) => record?.type === type && record.traceId === origin.traceId && predicate(record),
|
|
3739
|
+
);
|
|
3740
|
+
const inputStages = exactTrace("performance.stage", (record) => record.stage === "input");
|
|
3741
|
+
const paintStages = exactTrace("performance.stage", (record) => record.stage === "paint");
|
|
3742
|
+
const fences = exactTrace("performance.input-fence");
|
|
3743
|
+
const projections = exactTrace("performance.terminal-framebuffer-projection");
|
|
3744
|
+
if (
|
|
3745
|
+
inputStages.length !== 1 ||
|
|
3746
|
+
paintStages.length !== 1 ||
|
|
3747
|
+
fences.length !== 1 ||
|
|
3748
|
+
projections.length !== 1
|
|
3749
|
+
)
|
|
3750
|
+
return fail("input-trace-cardinality");
|
|
3751
|
+
const [inputStage] = inputStages;
|
|
3752
|
+
const [paint] = paintStages;
|
|
3753
|
+
const [fence] = fences;
|
|
3754
|
+
const [projection] = projections;
|
|
3755
|
+
const sameCanonical = (record) =>
|
|
3756
|
+
record.semanticPaneId === expectedPane &&
|
|
3757
|
+
record.generation === expectedCanonical.generation &&
|
|
3758
|
+
record.incarnation === expectedCanonical.incarnation &&
|
|
3759
|
+
record.revision === fence.revision &&
|
|
3760
|
+
record.stateHash === fence.stateHash;
|
|
3761
|
+
const frameFences = records.filter(
|
|
3762
|
+
(record) => record?.type === "performance.terminal-frame-fence" && sameCanonical(record),
|
|
3763
|
+
);
|
|
3764
|
+
const sameProcessClock = (record) =>
|
|
3765
|
+
record.processId === origin.processId &&
|
|
3766
|
+
record.clockId === origin.clockId &&
|
|
3767
|
+
record.clockKind === "performance-now";
|
|
3768
|
+
const exactStage = (record) =>
|
|
3769
|
+
sameProcessClock(record) &&
|
|
3770
|
+
Number.isFinite(record.startedAtMicros) &&
|
|
3771
|
+
Number.isFinite(record.endedAtMicros) &&
|
|
3772
|
+
record.startedAtMicros <= record.endedAtMicros;
|
|
3773
|
+
const exactPoint = (record) => sameProcessClock(record) && Number.isFinite(record.atMicros);
|
|
3774
|
+
if (
|
|
3775
|
+
inputStage.authority?.generation !== expectedCanonical.generation ||
|
|
3776
|
+
inputStage.authority?.incarnation !== expectedCanonical.incarnation ||
|
|
3777
|
+
inputStage.scenario !== "terminal-input-to-paint" ||
|
|
3778
|
+
paint.scenario !== "terminal-input-to-paint" ||
|
|
3779
|
+
paint.paintStateIdentity !== "latest-canonical-state-blitted" ||
|
|
3780
|
+
inputStage.processId !== origin.processId ||
|
|
3781
|
+
inputStage.clockId !== origin.clockId ||
|
|
3782
|
+
!exactStage(inputStage) ||
|
|
3783
|
+
!exactStage(paint) ||
|
|
3784
|
+
!exactPoint(fence) ||
|
|
3785
|
+
!exactPoint(projection) ||
|
|
3786
|
+
origin.atMicros !== inputStage.startedAtMicros ||
|
|
3787
|
+
inputStage.endedAtMicros > paint.startedAtMicros ||
|
|
3788
|
+
paint.startedAtMicros > projection.atMicros ||
|
|
3789
|
+
projection.atMicros > paint.endedAtMicros ||
|
|
3790
|
+
paint.endedAtMicros > fence.atMicros ||
|
|
3791
|
+
!(
|
|
3792
|
+
records.indexOf(origin) < records.indexOf(projection) &&
|
|
3793
|
+
records.indexOf(projection) < records.indexOf(inputStage) &&
|
|
3794
|
+
records.indexOf(inputStage) < records.indexOf(paint) &&
|
|
3795
|
+
records.indexOf(paint) < records.indexOf(fence) &&
|
|
3796
|
+
records.indexOf(fence) < records.indexOf(frameFences[0])
|
|
3797
|
+
) ||
|
|
3798
|
+
!sameCanonical(paint) ||
|
|
3799
|
+
!sameCanonical(projection) ||
|
|
3800
|
+
fence.semanticPaneId !== expectedPane ||
|
|
3801
|
+
fence.generation !== expectedCanonical.generation ||
|
|
3802
|
+
fence.incarnation !== expectedCanonical.incarnation ||
|
|
3803
|
+
!Number.isSafeInteger(fence.revision) ||
|
|
3804
|
+
fence.revision <= origin.revision ||
|
|
3805
|
+
!CANONICAL_STATE_HASH.test(fence.stateHash ?? "") ||
|
|
3806
|
+
!Number.isSafeInteger(projection.cols) ||
|
|
3807
|
+
projection.cols < 1 ||
|
|
3808
|
+
!Number.isSafeInteger(projection.rows) ||
|
|
3809
|
+
projection.rows < 1 ||
|
|
3810
|
+
frameFences.length !== 1 ||
|
|
3811
|
+
!exactPoint(frameFences[0]) ||
|
|
3812
|
+
frameFences[0].atMicros < fence.atMicros ||
|
|
3813
|
+
frameFences[0].acceptedRevision !== frameFences[0].revision ||
|
|
3814
|
+
frameFences[0].identityDrops !== 0 ||
|
|
3815
|
+
frameFences[0].cols !== projection.cols ||
|
|
3816
|
+
frameFences[0].rows !== projection.rows ||
|
|
3817
|
+
[fence.writerHealth, frameFences[0].writerHealth].some(
|
|
3818
|
+
(health) =>
|
|
3819
|
+
health?.droppedRecords !== 0 ||
|
|
3820
|
+
health?.oversizedRecords !== 0 ||
|
|
3821
|
+
health?.failed !== false ||
|
|
3822
|
+
(health?.pendingCriticalRecords !== undefined && health.pendingCriticalRecords !== 0),
|
|
3823
|
+
)
|
|
3824
|
+
)
|
|
3825
|
+
return fail("input-trace-mismatch");
|
|
3826
|
+
const hmac = (domain, value) =>
|
|
3827
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
3828
|
+
.update(`${domain}\0${value}`)
|
|
3829
|
+
.digest("hex");
|
|
3830
|
+
return Object.freeze({
|
|
3831
|
+
passed: true,
|
|
3832
|
+
reason: null,
|
|
3833
|
+
evidence: Object.freeze({
|
|
3834
|
+
hostReceiptHmac: hmac("tui-host-receipt", JSON.stringify(hostReceipt)),
|
|
3835
|
+
hostPaneHmac: hmac("tui-host-pane", hostReceipt.paneId),
|
|
3836
|
+
traceHmac: hmac("tui-input-trace", origin.traceId),
|
|
3837
|
+
payloadHmac: hmac("tui-input-payload", payload),
|
|
3838
|
+
paneHmac: hmac("pane", expectedPane),
|
|
3839
|
+
canonicalHmac: hmac(
|
|
3840
|
+
"tui-input-canonical",
|
|
3841
|
+
[fence.generation, fence.incarnation, fence.revision, fence.stateHash].join("\0"),
|
|
3842
|
+
),
|
|
3843
|
+
originRevision: origin.revision,
|
|
3844
|
+
fenceRevision: fence.revision,
|
|
3845
|
+
cols: projection.cols,
|
|
3846
|
+
rows: projection.rows,
|
|
3847
|
+
}),
|
|
3848
|
+
});
|
|
3849
|
+
}
|
|
3850
|
+
|
|
3851
|
+
/** Privacy-safe projection of one production host's detailed-only observation. */
|
|
3852
|
+
export function sealCard5ProductionClientObservation(raw, evidenceKey) {
|
|
3853
|
+
if (
|
|
3854
|
+
!raw ||
|
|
3855
|
+
!CLIENTS.has(raw.client) ||
|
|
3856
|
+
!HOSTS.has(raw.host) ||
|
|
3857
|
+
!GENERATION.test(raw.generation ?? "") ||
|
|
3858
|
+
!CANONICAL_STATE_HASH.test(raw.canonicalStateHash ?? "") ||
|
|
3859
|
+
(raw.client === "opentui"
|
|
3860
|
+
? raw.contentHmac !== undefined && raw.contentHmac !== null
|
|
3861
|
+
: !HMAC.test(raw.contentHmac ?? "")) ||
|
|
3862
|
+
!CLOCK_ID.test(raw.clockId ?? "") ||
|
|
3863
|
+
!Number.isSafeInteger(raw.atMicros) ||
|
|
3864
|
+
raw.atMicros < 0 ||
|
|
3865
|
+
!Number.isSafeInteger(raw.cols) ||
|
|
3866
|
+
raw.cols < 1 ||
|
|
3867
|
+
!Number.isSafeInteger(raw.rows) ||
|
|
3868
|
+
raw.rows < 1 ||
|
|
3869
|
+
!Number.isSafeInteger(raw.deliveryFence) ||
|
|
3870
|
+
raw.deliveryFence < 0 ||
|
|
3871
|
+
[raw.workspaceName, raw.semanticPaneId, raw.incarnation, raw.processIdentity].some(
|
|
3872
|
+
(value) => typeof value !== "string" || value.length < 1 || value.length > 256,
|
|
3873
|
+
) ||
|
|
3874
|
+
!/^[0-9a-f]{64}$/u.test(evidenceKey ?? "")
|
|
3875
|
+
) {
|
|
3876
|
+
throw new TypeError("Card5 production client observation is malformed");
|
|
3877
|
+
}
|
|
3878
|
+
if (!["foreground", "background"].includes(raw.presence)) {
|
|
3879
|
+
throw new TypeError("Card5 production client presence is malformed");
|
|
3880
|
+
}
|
|
3881
|
+
const correlationHmac = createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
3882
|
+
.update(
|
|
3883
|
+
[raw.client, raw.host, raw.generation, raw.canonicalStateHash, String(raw.revision)].join(
|
|
3884
|
+
"\0",
|
|
3885
|
+
),
|
|
3886
|
+
)
|
|
3887
|
+
.digest("hex");
|
|
3888
|
+
const identityHmac = (domain, value) =>
|
|
3889
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
3890
|
+
.update(`${domain}\0${value}`)
|
|
3891
|
+
.digest("hex");
|
|
3892
|
+
return Object.freeze({
|
|
3893
|
+
client: raw.client,
|
|
3894
|
+
host: raw.host,
|
|
3895
|
+
generation: raw.generation,
|
|
3896
|
+
connected: raw.connected === true,
|
|
3897
|
+
canonicalStateHash: raw.canonicalStateHash,
|
|
3898
|
+
renditionHmac: raw.client === "opentui" ? null : raw.contentHmac,
|
|
3899
|
+
correlationHmac,
|
|
3900
|
+
workspaceHmac: identityHmac("workspace", raw.workspaceName),
|
|
3901
|
+
paneHmac: identityHmac("pane", raw.semanticPaneId),
|
|
3902
|
+
incarnationHmac: identityHmac("incarnation", raw.incarnation),
|
|
3903
|
+
processHmac: identityHmac("process", raw.processIdentity),
|
|
3904
|
+
clockHmac: identityHmac("clock", raw.clockId),
|
|
3905
|
+
atMicros: boundedInteger(raw.atMicros, 60_000_000_000),
|
|
3906
|
+
revision: boundedInteger(raw.revision, 0xffff_ffff),
|
|
3907
|
+
cols: boundedInteger(raw.cols, 65_535),
|
|
3908
|
+
rows: boundedInteger(raw.rows, 65_535),
|
|
3909
|
+
deliveryFence: boundedInteger(raw.deliveryFence, 0xffff_ffff),
|
|
3910
|
+
presence: raw.presence,
|
|
3911
|
+
passive: raw.passive === true,
|
|
3912
|
+
geometryOwner: raw.geometryOwner === true,
|
|
3913
|
+
queueCurrent: boundedInteger(raw.queueCurrent, 65_535),
|
|
3914
|
+
queuePeak: boundedInteger(raw.queuePeak, 65_535),
|
|
3915
|
+
queueCap: boundedInteger(raw.queueCap, 65_535),
|
|
3916
|
+
connectElapsedMs: boundedInteger(Math.round(raw.connectElapsedMs), 60_000),
|
|
3917
|
+
});
|
|
3918
|
+
}
|
|
3919
|
+
|
|
3920
|
+
/** Exact current physical Web lifecycle proof used at convergence and handoff boundaries. */
|
|
3921
|
+
export function assessCard5WebPhysicalLifecycle(observed, expectedPane, expectedGeneration) {
|
|
3922
|
+
const lifecycle = observed?.runtimeReplacement?.currentLifecycleRequest;
|
|
3923
|
+
const axes = lifecycle?.physicalBindingAxes;
|
|
3924
|
+
const exactAxisKeys = [
|
|
3925
|
+
"present",
|
|
3926
|
+
"epochSafe",
|
|
3927
|
+
"generationExact",
|
|
3928
|
+
"runtimeSessionExact",
|
|
3929
|
+
"workspaceExact",
|
|
3930
|
+
"paneExact",
|
|
3931
|
+
"stageExact",
|
|
3932
|
+
"clientExact",
|
|
3933
|
+
"epochActiveCount",
|
|
3934
|
+
"bindingRequestExact",
|
|
3935
|
+
"descriptorExact",
|
|
3936
|
+
];
|
|
3937
|
+
if (
|
|
3938
|
+
typeof expectedPane !== "string" ||
|
|
3939
|
+
expectedPane.length < 1 ||
|
|
3940
|
+
expectedPane.length > 256 ||
|
|
3941
|
+
!GENERATION.test(expectedGeneration ?? "") ||
|
|
3942
|
+
observed?.semanticPaneId !== expectedPane ||
|
|
3943
|
+
observed?.generation !== expectedGeneration ||
|
|
3944
|
+
lifecycle?.status !== "exact" ||
|
|
3945
|
+
lifecycle.physicalBindingExact !== true ||
|
|
3946
|
+
lifecycle.activeCount !== 1 ||
|
|
3947
|
+
lifecycle.descriptorCount !== 1 ||
|
|
3948
|
+
lifecycle.overflow !== false ||
|
|
3949
|
+
!Number.isSafeInteger(lifecycle.rawActiveCount) ||
|
|
3950
|
+
lifecycle.rawActiveCount < 1 ||
|
|
3951
|
+
lifecycle.rawActiveCount > 8 ||
|
|
3952
|
+
!Number.isSafeInteger(lifecycle.rawDescriptorCount) ||
|
|
3953
|
+
lifecycle.rawDescriptorCount < 1 ||
|
|
3954
|
+
lifecycle.rawDescriptorCount > 8 ||
|
|
3955
|
+
!HMAC.test(lifecycle.requestHmac ?? "") ||
|
|
3956
|
+
!HMAC.test(lifecycle.physicalEpochHmac ?? "") ||
|
|
3957
|
+
lifecycle.bindingRequestHmac !== lifecycle.requestHmac ||
|
|
3958
|
+
!HMAC.test(lifecycle.bindingClientHmac ?? "") ||
|
|
3959
|
+
!axes ||
|
|
3960
|
+
Object.keys(axes).sort().join("\0") !== [...exactAxisKeys].sort().join("\0") ||
|
|
3961
|
+
exactAxisKeys.slice(0, 8).some((key) => axes[key] !== true) ||
|
|
3962
|
+
axes.epochActiveCount !== 1 ||
|
|
3963
|
+
axes.bindingRequestExact !== true ||
|
|
3964
|
+
axes.descriptorExact !== true
|
|
3965
|
+
) {
|
|
3966
|
+
return Object.freeze({ valid: false, evidence: null });
|
|
3967
|
+
}
|
|
3968
|
+
return Object.freeze({
|
|
3969
|
+
valid: true,
|
|
3970
|
+
evidence: Object.freeze({
|
|
3971
|
+
requestHmac: lifecycle.requestHmac,
|
|
3972
|
+
physicalEpochHmac: lifecycle.physicalEpochHmac,
|
|
3973
|
+
clientHmac: lifecycle.bindingClientHmac,
|
|
3974
|
+
firstSeedOrdinal: Number.isSafeInteger(lifecycle.firstSeedOrdinal)
|
|
3975
|
+
? lifecycle.firstSeedOrdinal
|
|
3976
|
+
: null,
|
|
3977
|
+
}),
|
|
3978
|
+
});
|
|
3979
|
+
}
|
|
3980
|
+
|
|
3981
|
+
function exactCard5WebPhysicalLifecyclePair(pair) {
|
|
3982
|
+
const exactEvidence = (evidence) =>
|
|
3983
|
+
evidence &&
|
|
3984
|
+
Object.keys(evidence).sort().join("\0") ===
|
|
3985
|
+
["clientHmac", "firstSeedOrdinal", "physicalEpochHmac", "requestHmac"].sort().join("\0") &&
|
|
3986
|
+
HMAC.test(evidence.requestHmac ?? "") &&
|
|
3987
|
+
HMAC.test(evidence.physicalEpochHmac ?? "") &&
|
|
3988
|
+
HMAC.test(evidence.clientHmac ?? "") &&
|
|
3989
|
+
(evidence.firstSeedOrdinal === null ||
|
|
3990
|
+
(Number.isSafeInteger(evidence.firstSeedOrdinal) && evidence.firstSeedOrdinal >= 0));
|
|
3991
|
+
return (
|
|
3992
|
+
pair &&
|
|
3993
|
+
Object.keys(pair).sort().join("\0") === ["chromium", "electron"].sort().join("\0") &&
|
|
3994
|
+
exactEvidence(pair.chromium) &&
|
|
3995
|
+
exactEvidence(pair.electron) &&
|
|
3996
|
+
pair.chromium.clientHmac !== pair.electron.clientHmac &&
|
|
3997
|
+
pair.chromium.requestHmac !== pair.electron.requestHmac
|
|
3998
|
+
);
|
|
3999
|
+
}
|
|
4000
|
+
|
|
4001
|
+
export function advanceCard5WebPhysicalLifecycleStability(
|
|
4002
|
+
previousDigest,
|
|
4003
|
+
canonicalDigest,
|
|
4004
|
+
pair,
|
|
4005
|
+
evidenceKey,
|
|
4006
|
+
) {
|
|
4007
|
+
if (
|
|
4008
|
+
!HMAC.test(canonicalDigest ?? "") ||
|
|
4009
|
+
!HMAC.test(evidenceKey ?? "") ||
|
|
4010
|
+
!exactCard5WebPhysicalLifecyclePair(pair)
|
|
4011
|
+
) {
|
|
4012
|
+
return Object.freeze({ stable: false, digest: null, evidence: null });
|
|
4013
|
+
}
|
|
4014
|
+
const digest = createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
4015
|
+
.update("focused-convergence-with-physical-lifecycle\0")
|
|
4016
|
+
.update(canonicalDigest)
|
|
4017
|
+
.update("\0")
|
|
4018
|
+
.update(JSON.stringify(pair))
|
|
4019
|
+
.digest("hex");
|
|
4020
|
+
return Object.freeze({
|
|
4021
|
+
stable: previousDigest === digest,
|
|
4022
|
+
digest,
|
|
4023
|
+
evidence: Object.freeze({
|
|
4024
|
+
chromium: Object.freeze({ ...pair.chromium }),
|
|
4025
|
+
electron: Object.freeze({ ...pair.electron }),
|
|
4026
|
+
}),
|
|
4027
|
+
});
|
|
4028
|
+
}
|
|
4029
|
+
|
|
4030
|
+
export function sameCard5WebPhysicalLifecycleEvidence(accepted, current) {
|
|
4031
|
+
return (
|
|
4032
|
+
exactCard5WebPhysicalLifecyclePair(accepted) &&
|
|
4033
|
+
exactCard5WebPhysicalLifecyclePair(current) &&
|
|
4034
|
+
JSON.stringify(accepted) === JSON.stringify(current)
|
|
4035
|
+
);
|
|
4036
|
+
}
|
|
4037
|
+
|
|
4038
|
+
/** Two equal complete samples are required before a cross-host hash is called stable. */
|
|
4039
|
+
export function advanceCard5CanonicalStability(previousDigest, observations) {
|
|
4040
|
+
if (!Array.isArray(observations) || observations.length !== 3) {
|
|
4041
|
+
return Object.freeze({
|
|
4042
|
+
stable: false,
|
|
4043
|
+
digest: null,
|
|
4044
|
+
reason: "client-cardinality",
|
|
4045
|
+
axes: null,
|
|
4046
|
+
candidate: null,
|
|
4047
|
+
});
|
|
4048
|
+
}
|
|
4049
|
+
const clients = observations.map(({ client }) => client);
|
|
4050
|
+
if (new Set(clients).size !== 3 || clients.some((client) => !CLIENTS.has(client))) {
|
|
4051
|
+
return Object.freeze({
|
|
4052
|
+
stable: false,
|
|
4053
|
+
digest: null,
|
|
4054
|
+
reason: "client-identity",
|
|
4055
|
+
axes: null,
|
|
4056
|
+
candidate: null,
|
|
4057
|
+
});
|
|
4058
|
+
}
|
|
4059
|
+
const generations = new Set(observations.map(({ generation }) => generation));
|
|
4060
|
+
const hashes = new Set(observations.map(({ canonicalStateHash }) => canonicalStateHash));
|
|
4061
|
+
const revisions = new Set(observations.map(({ revision }) => revision));
|
|
4062
|
+
const dimensions = new Set(observations.map(({ cols, rows }) => `${cols}x${rows}`));
|
|
4063
|
+
const workspaces = new Set(observations.map(({ workspaceHmac }) => workspaceHmac));
|
|
4064
|
+
const panes = new Set(observations.map(({ paneHmac }) => paneHmac));
|
|
4065
|
+
const incarnations = new Set(observations.map(({ incarnationHmac }) => incarnationHmac));
|
|
4066
|
+
const webRenditions = new Set(
|
|
4067
|
+
observations
|
|
4068
|
+
.filter(({ client }) => client !== "opentui")
|
|
4069
|
+
.map(({ renditionHmac }) => renditionHmac),
|
|
4070
|
+
);
|
|
4071
|
+
const fieldsComplete = observations.every(
|
|
4072
|
+
({ connected, revision, deliveryFence, processHmac, clockHmac, atMicros }) =>
|
|
4073
|
+
connected === true &&
|
|
4074
|
+
revision !== null &&
|
|
4075
|
+
deliveryFence !== null &&
|
|
4076
|
+
HMAC.test(processHmac ?? "") &&
|
|
4077
|
+
HMAC.test(clockHmac ?? "") &&
|
|
4078
|
+
atMicros !== null,
|
|
4079
|
+
);
|
|
4080
|
+
const axes = Object.freeze({
|
|
4081
|
+
generation: generations.size === 1,
|
|
4082
|
+
canonicalHash: hashes.size === 1,
|
|
4083
|
+
revision: revisions.size === 1,
|
|
4084
|
+
dimensions: dimensions.size === 1,
|
|
4085
|
+
workspace: workspaces.size === 1,
|
|
4086
|
+
pane: panes.size === 1,
|
|
4087
|
+
incarnation: incarnations.size === 1,
|
|
4088
|
+
webRendition: webRenditions.size === 1,
|
|
4089
|
+
fieldsComplete,
|
|
4090
|
+
});
|
|
4091
|
+
const candidate = card5CandidateSummary(observations);
|
|
4092
|
+
if (
|
|
4093
|
+
generations.size !== 1 ||
|
|
4094
|
+
hashes.size !== 1 ||
|
|
4095
|
+
revisions.size !== 1 ||
|
|
4096
|
+
dimensions.size !== 1 ||
|
|
4097
|
+
workspaces.size !== 1 ||
|
|
4098
|
+
panes.size !== 1 ||
|
|
4099
|
+
incarnations.size !== 1 ||
|
|
4100
|
+
webRenditions.size !== 1 ||
|
|
4101
|
+
!fieldsComplete
|
|
4102
|
+
) {
|
|
4103
|
+
return Object.freeze({
|
|
4104
|
+
stable: false,
|
|
4105
|
+
digest: null,
|
|
4106
|
+
reason: "canonical-divergence",
|
|
4107
|
+
axes,
|
|
4108
|
+
candidate,
|
|
4109
|
+
});
|
|
4110
|
+
}
|
|
4111
|
+
const digest = observations
|
|
4112
|
+
.map(
|
|
4113
|
+
({
|
|
4114
|
+
client,
|
|
4115
|
+
generation,
|
|
4116
|
+
canonicalStateHash,
|
|
4117
|
+
revision,
|
|
4118
|
+
cols,
|
|
4119
|
+
rows,
|
|
4120
|
+
deliveryFence,
|
|
4121
|
+
workspaceHmac,
|
|
4122
|
+
paneHmac,
|
|
4123
|
+
incarnationHmac,
|
|
4124
|
+
processHmac,
|
|
4125
|
+
clockHmac,
|
|
4126
|
+
renditionHmac,
|
|
4127
|
+
}) =>
|
|
4128
|
+
[
|
|
4129
|
+
client,
|
|
4130
|
+
generation,
|
|
4131
|
+
canonicalStateHash,
|
|
4132
|
+
revision,
|
|
4133
|
+
cols,
|
|
4134
|
+
rows,
|
|
4135
|
+
deliveryFence,
|
|
4136
|
+
workspaceHmac,
|
|
4137
|
+
paneHmac,
|
|
4138
|
+
incarnationHmac,
|
|
4139
|
+
processHmac,
|
|
4140
|
+
clockHmac,
|
|
4141
|
+
renditionHmac,
|
|
4142
|
+
].join("\0"),
|
|
4143
|
+
)
|
|
4144
|
+
.sort()
|
|
4145
|
+
.join("\n");
|
|
4146
|
+
return Object.freeze({
|
|
4147
|
+
stable: previousDigest === digest,
|
|
4148
|
+
digest,
|
|
4149
|
+
reason: previousDigest === digest ? null : "stability-pending",
|
|
4150
|
+
axes,
|
|
4151
|
+
candidate,
|
|
4152
|
+
});
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4155
|
+
/** One exact canonical client tuple plus the exact focused OpenTUI presentation/frame tuple. */
|
|
4156
|
+
export function advanceCard5FocusedConvergenceStability(
|
|
4157
|
+
previousDigest,
|
|
4158
|
+
observations,
|
|
4159
|
+
focusEvidence,
|
|
4160
|
+
evidenceKey,
|
|
4161
|
+
) {
|
|
4162
|
+
const canonical = advanceCard5CanonicalStability(null, observations);
|
|
4163
|
+
const tui = Array.isArray(observations)
|
|
4164
|
+
? observations.find(({ client }) => client === "opentui")
|
|
4165
|
+
: null;
|
|
4166
|
+
const focusExact =
|
|
4167
|
+
HMAC.test(evidenceKey ?? "") &&
|
|
4168
|
+
HMAC.test(focusEvidence?.paneHmac ?? "") &&
|
|
4169
|
+
HMAC.test(focusEvidence?.processHmac ?? "") &&
|
|
4170
|
+
HMAC.test(focusEvidence?.clockHmac ?? "") &&
|
|
4171
|
+
HMAC.test(focusEvidence?.authorityHmac ?? "") &&
|
|
4172
|
+
HMAC.test(focusEvidence?.authorityOwnerHmac ?? "") &&
|
|
4173
|
+
Number.isSafeInteger(focusEvidence?.authorityRevision) &&
|
|
4174
|
+
focusEvidence.authorityRevision >= 0 &&
|
|
4175
|
+
HMAC.test(focusEvidence?.authorityTopologyHmac ?? "") &&
|
|
4176
|
+
HMAC.test(focusEvidence?.authorityMutationHmac ?? "") &&
|
|
4177
|
+
HMAC.test(focusEvidence?.canonicalHmac ?? "") &&
|
|
4178
|
+
HMAC.test(focusEvidence?.presentationHmac ?? "") &&
|
|
4179
|
+
HMAC.test(focusEvidence?.frameHmac ?? "") &&
|
|
4180
|
+
HMAC.test(focusEvidence?.focusStateHmac ?? "") &&
|
|
4181
|
+
Number.isSafeInteger(focusEvidence?.revision) &&
|
|
4182
|
+
focusEvidence.revision >= 0 &&
|
|
4183
|
+
Number.isSafeInteger(focusEvidence?.cols) &&
|
|
4184
|
+
focusEvidence.cols > 0 &&
|
|
4185
|
+
Number.isSafeInteger(focusEvidence?.rows) &&
|
|
4186
|
+
focusEvidence.rows > 0 &&
|
|
4187
|
+
Number.isSafeInteger(focusEvidence?.viewportCols) &&
|
|
4188
|
+
focusEvidence.viewportCols > 0 &&
|
|
4189
|
+
Number.isSafeInteger(focusEvidence?.viewportRows) &&
|
|
4190
|
+
focusEvidence.viewportRows > 0 &&
|
|
4191
|
+
focusEvidence.paneHmac === tui?.paneHmac &&
|
|
4192
|
+
focusEvidence.processHmac === tui?.processHmac &&
|
|
4193
|
+
focusEvidence.clockHmac === tui?.clockHmac &&
|
|
4194
|
+
focusEvidence.revision === tui?.revision &&
|
|
4195
|
+
focusEvidence.cols === tui?.cols &&
|
|
4196
|
+
focusEvidence.rows === tui?.rows;
|
|
4197
|
+
const postRelationFields = [
|
|
4198
|
+
focusEvidence?.authorityRelationHmac,
|
|
4199
|
+
focusEvidence?.authoritySequenceHmac,
|
|
4200
|
+
focusEvidence?.authorityDuplicateCount,
|
|
4201
|
+
focusEvidence?.inputProofHmac,
|
|
4202
|
+
focusEvidence?.grantRevision,
|
|
4203
|
+
focusEvidence?.releaseRevision,
|
|
4204
|
+
focusEvidence?.relation,
|
|
4205
|
+
];
|
|
4206
|
+
const postRelationExact =
|
|
4207
|
+
postRelationFields.every((value) => value === undefined) ||
|
|
4208
|
+
(HMAC.test(focusEvidence?.authorityRelationHmac ?? "") &&
|
|
4209
|
+
HMAC.test(focusEvidence?.authoritySequenceHmac ?? "") &&
|
|
4210
|
+
Number.isSafeInteger(focusEvidence?.authorityDuplicateCount) &&
|
|
4211
|
+
focusEvidence.authorityDuplicateCount >= 0 &&
|
|
4212
|
+
focusEvidence.authorityDuplicateCount <= 8 &&
|
|
4213
|
+
HMAC.test(focusEvidence?.inputProofHmac ?? "") &&
|
|
4214
|
+
Number.isSafeInteger(focusEvidence?.grantRevision) &&
|
|
4215
|
+
focusEvidence.grantRevision >= 0 &&
|
|
4216
|
+
["retained-owner", "released-null"].includes(focusEvidence?.relation) &&
|
|
4217
|
+
(focusEvidence.relation === "retained-owner"
|
|
4218
|
+
? focusEvidence.releaseRevision === null
|
|
4219
|
+
: Number.isSafeInteger(focusEvidence.releaseRevision) &&
|
|
4220
|
+
focusEvidence.releaseRevision > focusEvidence.grantRevision));
|
|
4221
|
+
if (canonical.digest === null || !focusExact || !postRelationExact)
|
|
4222
|
+
return Object.freeze({
|
|
4223
|
+
...canonical,
|
|
4224
|
+
stable: false,
|
|
4225
|
+
digest: null,
|
|
4226
|
+
reason: canonical.digest === null ? canonical.reason : "focused-pane-incomplete",
|
|
4227
|
+
});
|
|
4228
|
+
const digest = createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
4229
|
+
.update("card5-focused-convergence\0")
|
|
4230
|
+
.update(
|
|
4231
|
+
[
|
|
4232
|
+
canonical.digest,
|
|
4233
|
+
focusEvidence.paneHmac,
|
|
4234
|
+
focusEvidence.processHmac,
|
|
4235
|
+
focusEvidence.clockHmac,
|
|
4236
|
+
focusEvidence.authorityHmac,
|
|
4237
|
+
focusEvidence.authorityOwnerHmac,
|
|
4238
|
+
focusEvidence.authorityTopologyHmac,
|
|
4239
|
+
focusEvidence.canonicalHmac,
|
|
4240
|
+
focusEvidence.presentationHmac,
|
|
4241
|
+
focusEvidence.frameHmac,
|
|
4242
|
+
focusEvidence.focusStateHmac,
|
|
4243
|
+
focusEvidence.revision,
|
|
4244
|
+
focusEvidence.cols,
|
|
4245
|
+
focusEvidence.rows,
|
|
4246
|
+
focusEvidence.viewportCols,
|
|
4247
|
+
focusEvidence.viewportRows,
|
|
4248
|
+
focusEvidence.authorityRelationHmac ?? "initial",
|
|
4249
|
+
focusEvidence.authoritySequenceHmac ?? "initial",
|
|
4250
|
+
focusEvidence.authorityDuplicateCount ?? "initial",
|
|
4251
|
+
focusEvidence.inputProofHmac ?? "initial",
|
|
4252
|
+
focusEvidence.grantRevision ?? "initial",
|
|
4253
|
+
focusEvidence.releaseRevision ?? "initial",
|
|
4254
|
+
focusEvidence.relation ?? "initial",
|
|
4255
|
+
].join("\0"),
|
|
4256
|
+
)
|
|
4257
|
+
.digest("hex");
|
|
4258
|
+
return Object.freeze({
|
|
4259
|
+
...canonical,
|
|
4260
|
+
stable: previousDigest === digest,
|
|
4261
|
+
digest,
|
|
4262
|
+
reason: previousDigest === digest ? null : "stability-pending",
|
|
4263
|
+
});
|
|
4264
|
+
}
|
|
4265
|
+
|
|
4266
|
+
export function boundedCard5HostFailureObservation(input) {
|
|
4267
|
+
const reasons = new Set([
|
|
4268
|
+
"host-unavailable",
|
|
4269
|
+
"client-cardinality",
|
|
4270
|
+
"client-identity",
|
|
4271
|
+
"canonical-divergence",
|
|
4272
|
+
"stability-timeout",
|
|
4273
|
+
"queue-overflow",
|
|
4274
|
+
"generation-stale",
|
|
4275
|
+
"authority-activity-storm",
|
|
4276
|
+
]);
|
|
4277
|
+
return Object.freeze({
|
|
4278
|
+
operation: "card5-production-host-observation",
|
|
4279
|
+
reason: reasons.has(input?.reason) ? input.reason : "host-unavailable",
|
|
4280
|
+
host: HOSTS.has(input?.host) ? input.host : null,
|
|
4281
|
+
attempts: boundedInteger(input?.attempts, 4_096),
|
|
4282
|
+
elapsedMs: boundedInteger(Math.round(input?.elapsedMs), 60_000),
|
|
4283
|
+
observedClients: boundedInteger(input?.observedClients, 3),
|
|
4284
|
+
stableSamples: boundedInteger(input?.stableSamples, 2),
|
|
4285
|
+
queuePeak: boundedInteger(input?.queuePeak, 65_535),
|
|
4286
|
+
divergenceAxes:
|
|
4287
|
+
input?.divergenceAxes &&
|
|
4288
|
+
[
|
|
4289
|
+
"generation",
|
|
4290
|
+
"canonicalHash",
|
|
4291
|
+
"revision",
|
|
4292
|
+
"dimensions",
|
|
4293
|
+
"workspace",
|
|
4294
|
+
"pane",
|
|
4295
|
+
"incarnation",
|
|
4296
|
+
"webRendition",
|
|
4297
|
+
"fieldsComplete",
|
|
4298
|
+
].every((key) => typeof input.divergenceAxes[key] === "boolean")
|
|
4299
|
+
? Object.freeze({
|
|
4300
|
+
generation: input.divergenceAxes.generation,
|
|
4301
|
+
canonicalHash: input.divergenceAxes.canonicalHash,
|
|
4302
|
+
revision: input.divergenceAxes.revision,
|
|
4303
|
+
dimensions: input.divergenceAxes.dimensions,
|
|
4304
|
+
workspace: input.divergenceAxes.workspace,
|
|
4305
|
+
pane: input.divergenceAxes.pane,
|
|
4306
|
+
incarnation: input.divergenceAxes.incarnation,
|
|
4307
|
+
webRendition: input.divergenceAxes.webRendition,
|
|
4308
|
+
fieldsComplete: input.divergenceAxes.fieldsComplete,
|
|
4309
|
+
})
|
|
4310
|
+
: null,
|
|
4311
|
+
focusDivergenceAxes:
|
|
4312
|
+
input?.focusDivergenceAxes &&
|
|
4313
|
+
[
|
|
4314
|
+
"pane",
|
|
4315
|
+
"generation",
|
|
4316
|
+
"incarnation",
|
|
4317
|
+
"revision",
|
|
4318
|
+
"canonicalHash",
|
|
4319
|
+
"process",
|
|
4320
|
+
"clock",
|
|
4321
|
+
"canonicalDimensions",
|
|
4322
|
+
"viewportDimensions",
|
|
4323
|
+
"presentationCount",
|
|
4324
|
+
"followingFrame",
|
|
4325
|
+
"frameHealth",
|
|
4326
|
+
"authority",
|
|
4327
|
+
].every((key) => typeof input.focusDivergenceAxes[key] === "boolean")
|
|
4328
|
+
? Object.freeze({ ...input.focusDivergenceAxes })
|
|
4329
|
+
: null,
|
|
4330
|
+
focusCandidates: Object.freeze(
|
|
4331
|
+
Array.isArray(input?.focusCandidates)
|
|
4332
|
+
? input.focusCandidates.slice(-2).map((candidate) =>
|
|
4333
|
+
Object.freeze({
|
|
4334
|
+
paneHmac: HMAC.test(candidate?.paneHmac ?? "") ? candidate.paneHmac : null,
|
|
4335
|
+
generationHmac: HMAC.test(candidate?.generationHmac ?? "")
|
|
4336
|
+
? candidate.generationHmac
|
|
4337
|
+
: null,
|
|
4338
|
+
incarnationHmac: HMAC.test(candidate?.incarnationHmac ?? "")
|
|
4339
|
+
? candidate.incarnationHmac
|
|
4340
|
+
: null,
|
|
4341
|
+
processHmac: HMAC.test(candidate?.processHmac ?? "") ? candidate.processHmac : null,
|
|
4342
|
+
clockHmac: HMAC.test(candidate?.clockHmac ?? "") ? candidate.clockHmac : null,
|
|
4343
|
+
canonicalHashHmac: HMAC.test(candidate?.canonicalHashHmac ?? "")
|
|
4344
|
+
? candidate.canonicalHashHmac
|
|
4345
|
+
: null,
|
|
4346
|
+
revision: boundedInteger(candidate?.revision, 0xffff_ffff),
|
|
4347
|
+
cols: boundedInteger(candidate?.cols, 65_535),
|
|
4348
|
+
rows: boundedInteger(candidate?.rows, 65_535),
|
|
4349
|
+
viewportCols: boundedInteger(candidate?.viewportCols, 65_535),
|
|
4350
|
+
viewportRows: boundedInteger(candidate?.viewportRows, 65_535),
|
|
4351
|
+
presentationCount: boundedInteger(candidate?.presentationCount, 0xffff_ffff),
|
|
4352
|
+
presentationHmac: HMAC.test(candidate?.presentationHmac ?? "")
|
|
4353
|
+
? candidate.presentationHmac
|
|
4354
|
+
: null,
|
|
4355
|
+
frameHmac: HMAC.test(candidate?.frameHmac ?? "") ? candidate.frameHmac : null,
|
|
4356
|
+
authoritySequenceHmac: HMAC.test(candidate?.authoritySequenceHmac ?? "")
|
|
4357
|
+
? candidate.authoritySequenceHmac
|
|
4358
|
+
: null,
|
|
4359
|
+
}),
|
|
4360
|
+
)
|
|
4361
|
+
: [],
|
|
4362
|
+
),
|
|
4363
|
+
authorityViews: Object.freeze(
|
|
4364
|
+
Array.isArray(input?.authorityViews)
|
|
4365
|
+
? input.authorityViews.slice(-2).map((pair) => {
|
|
4366
|
+
const project = (view) =>
|
|
4367
|
+
Object.freeze(
|
|
4368
|
+
(() => {
|
|
4369
|
+
const evidence = view?.evidence ?? view;
|
|
4370
|
+
const reasons = new Set([
|
|
4371
|
+
"generation-mismatch",
|
|
4372
|
+
"session-invalid",
|
|
4373
|
+
"revision-invalid",
|
|
4374
|
+
"native-yield-invalid",
|
|
4375
|
+
"authority-keys-invalid",
|
|
4376
|
+
"owner-keys-invalid",
|
|
4377
|
+
"client-count-invalid",
|
|
4378
|
+
"client-schema-invalid",
|
|
4379
|
+
"surface-cardinality-invalid",
|
|
4380
|
+
"duplicate-client",
|
|
4381
|
+
"input-owner-invalid",
|
|
4382
|
+
"focus-owner-invalid",
|
|
4383
|
+
"post-handoff-contract-invalid",
|
|
4384
|
+
"post-handoff-grant-missing",
|
|
4385
|
+
"post-handoff-owner-unexplained",
|
|
4386
|
+
]);
|
|
4387
|
+
const axisKeys = [
|
|
4388
|
+
"generation",
|
|
4389
|
+
"session",
|
|
4390
|
+
"revision",
|
|
4391
|
+
"nativeYield",
|
|
4392
|
+
"authorityKeys",
|
|
4393
|
+
"ownerKeys",
|
|
4394
|
+
"clientCount",
|
|
4395
|
+
"clientSchema",
|
|
4396
|
+
"surfaceCardinality",
|
|
4397
|
+
"duplicateClients",
|
|
4398
|
+
"inputOwner",
|
|
4399
|
+
"focusOwner",
|
|
4400
|
+
];
|
|
4401
|
+
const evidenceValid = Boolean(
|
|
4402
|
+
HMAC.test(evidence?.authorityHmac ?? "") &&
|
|
4403
|
+
HMAC.test(evidence?.authorityTopologyHmac ?? "") &&
|
|
4404
|
+
HMAC.test(evidence?.authorityMutationHmac ?? "") &&
|
|
4405
|
+
Number.isSafeInteger(evidence?.authorityRevision) &&
|
|
4406
|
+
evidence.authorityRevision >= 0,
|
|
4407
|
+
);
|
|
4408
|
+
return {
|
|
4409
|
+
valid: view?.valid !== false && evidenceValid,
|
|
4410
|
+
reason: reasons.has(view?.reason)
|
|
4411
|
+
? view.reason
|
|
4412
|
+
: evidenceValid
|
|
4413
|
+
? null
|
|
4414
|
+
: "authority-keys-invalid",
|
|
4415
|
+
axes:
|
|
4416
|
+
view?.axes && axisKeys.every((key) => typeof view.axes[key] === "boolean")
|
|
4417
|
+
? Object.freeze(
|
|
4418
|
+
Object.fromEntries(axisKeys.map((key) => [key, view.axes[key]])),
|
|
4419
|
+
)
|
|
4420
|
+
: null,
|
|
4421
|
+
counts: Object.freeze({
|
|
4422
|
+
clients: boundedInteger(view?.counts?.clients, 8),
|
|
4423
|
+
web: boundedInteger(view?.counts?.web, 8),
|
|
4424
|
+
opentui: boundedInteger(view?.counts?.opentui, 8),
|
|
4425
|
+
}),
|
|
4426
|
+
ownerHmac: HMAC.test(view?.ownerHmac ?? "") ? view.ownerHmac : null,
|
|
4427
|
+
clientsHmac: HMAC.test(view?.clientsHmac ?? "") ? view.clientsHmac : null,
|
|
4428
|
+
recordTransitions: Object.freeze(
|
|
4429
|
+
Array.isArray(view?.recordTransitions)
|
|
4430
|
+
? view.recordTransitions.slice(-2).map((record) =>
|
|
4431
|
+
Object.freeze({
|
|
4432
|
+
ordinal: boundedInteger(record?.ordinal, 0xffff_ffff),
|
|
4433
|
+
revision: boundedInteger(record?.revision, 0xffff_ffff),
|
|
4434
|
+
clientCount: boundedInteger(record?.clientCount, 8),
|
|
4435
|
+
ownerHmac: HMAC.test(record?.ownerHmac ?? "")
|
|
4436
|
+
? record.ownerHmac
|
|
4437
|
+
: null,
|
|
4438
|
+
topologyHmac: HMAC.test(record?.topologyHmac ?? "")
|
|
4439
|
+
? record.topologyHmac
|
|
4440
|
+
: null,
|
|
4441
|
+
}),
|
|
4442
|
+
)
|
|
4443
|
+
: [],
|
|
4444
|
+
),
|
|
4445
|
+
revision: boundedInteger(evidence?.authorityRevision, 0xffff_ffff),
|
|
4446
|
+
semanticHmac: HMAC.test(evidence?.authorityHmac ?? "")
|
|
4447
|
+
? evidence.authorityHmac
|
|
4448
|
+
: null,
|
|
4449
|
+
topologyHmac: HMAC.test(evidence?.authorityTopologyHmac ?? "")
|
|
4450
|
+
? evidence.authorityTopologyHmac
|
|
4451
|
+
: null,
|
|
4452
|
+
mutationHmac: HMAC.test(evidence?.authorityMutationHmac ?? "")
|
|
4453
|
+
? evidence.authorityMutationHmac
|
|
4454
|
+
: null,
|
|
4455
|
+
mode: HMAC.test(evidence?.authorityRelationHmac ?? "")
|
|
4456
|
+
? "post-handoff"
|
|
4457
|
+
: "initial",
|
|
4458
|
+
relation: ["retained-owner", "released-null"].includes(evidence?.relation)
|
|
4459
|
+
? evidence.relation
|
|
4460
|
+
: null,
|
|
4461
|
+
grantRevision: boundedInteger(evidence?.grantRevision, 0xffff_ffff),
|
|
4462
|
+
releaseRevision: boundedInteger(evidence?.releaseRevision, 0xffff_ffff),
|
|
4463
|
+
relationHmac: HMAC.test(evidence?.authorityRelationHmac ?? "")
|
|
4464
|
+
? evidence.authorityRelationHmac
|
|
4465
|
+
: null,
|
|
4466
|
+
sequenceHmac: HMAC.test(evidence?.authoritySequenceHmac ?? "")
|
|
4467
|
+
? evidence.authoritySequenceHmac
|
|
4468
|
+
: null,
|
|
4469
|
+
duplicateCount: boundedInteger(evidence?.authorityDuplicateCount, 8),
|
|
4470
|
+
};
|
|
4471
|
+
})(),
|
|
4472
|
+
);
|
|
4473
|
+
const projectActivity = (activity) => {
|
|
4474
|
+
const outcomes = new Set([
|
|
4475
|
+
"attempt",
|
|
4476
|
+
"ok",
|
|
4477
|
+
"geometry-authority-conflict",
|
|
4478
|
+
"authority-timeout",
|
|
4479
|
+
"viewport-timeout",
|
|
4480
|
+
"stream-closed",
|
|
4481
|
+
"lifecycle-retired",
|
|
4482
|
+
"failed",
|
|
4483
|
+
]);
|
|
4484
|
+
const source = Array.isArray(activity?.events) ? activity.events.slice(-64) : [];
|
|
4485
|
+
const events = source
|
|
4486
|
+
.filter(
|
|
4487
|
+
(event) =>
|
|
4488
|
+
["web", "opentui"].includes(event?.surface) &&
|
|
4489
|
+
["focus", "geometry", "input"].includes(event?.kind) &&
|
|
4490
|
+
outcomes.has(event?.outcome) &&
|
|
4491
|
+
Number.isSafeInteger(event?.ordinal) &&
|
|
4492
|
+
event.ordinal >= 1,
|
|
4493
|
+
)
|
|
4494
|
+
.slice(-8)
|
|
4495
|
+
.map(({ ordinal, surface, kind, outcome, operationOrdinal, dimensionsHmac }) =>
|
|
4496
|
+
Object.freeze({
|
|
4497
|
+
ordinal,
|
|
4498
|
+
surface,
|
|
4499
|
+
kind,
|
|
4500
|
+
outcome,
|
|
4501
|
+
operationOrdinal: boundedInteger(operationOrdinal, 0xffff_ffff),
|
|
4502
|
+
dimensionsHmac:
|
|
4503
|
+
kind === "geometry" && HMAC.test(dimensionsHmac ?? "")
|
|
4504
|
+
? dimensionsHmac
|
|
4505
|
+
: null,
|
|
4506
|
+
}),
|
|
4507
|
+
);
|
|
4508
|
+
const byKind = { focus: 0, geometry: 0, input: 0 };
|
|
4509
|
+
for (const event of source) {
|
|
4510
|
+
if (
|
|
4511
|
+
["web", "opentui"].includes(event?.surface) &&
|
|
4512
|
+
Object.hasOwn(byKind, event?.kind)
|
|
4513
|
+
) {
|
|
4514
|
+
byKind[event.kind] = Math.min(byKind[event.kind] + 1, 64);
|
|
4515
|
+
}
|
|
4516
|
+
}
|
|
4517
|
+
return Object.freeze({
|
|
4518
|
+
available:
|
|
4519
|
+
Number.isSafeInteger(activity?.count) &&
|
|
4520
|
+
activity.count >= 0 &&
|
|
4521
|
+
typeof activity?.overflow === "boolean",
|
|
4522
|
+
count: boundedInteger(activity?.count, 0xffff_ffff),
|
|
4523
|
+
overflow: activity?.overflow === true,
|
|
4524
|
+
byKind: Object.freeze(byKind),
|
|
4525
|
+
events: Object.freeze(events),
|
|
4526
|
+
geometrySettlements: Object.freeze(
|
|
4527
|
+
Array.isArray(activity?.geometrySettlements)
|
|
4528
|
+
? activity.geometrySettlements.slice(-16).map((receipt) =>
|
|
4529
|
+
Object.freeze({
|
|
4530
|
+
ordinal: boundedInteger(receipt?.ordinal, 0xffff_ffff),
|
|
4531
|
+
operationOrdinal: boundedInteger(receipt?.operationOrdinal, 0xffff_ffff),
|
|
4532
|
+
requestHmac: HMAC.test(receipt?.requestHmac ?? "")
|
|
4533
|
+
? receipt.requestHmac
|
|
4534
|
+
: null,
|
|
4535
|
+
clientHmac: HMAC.test(receipt?.clientHmac ?? "")
|
|
4536
|
+
? receipt.clientHmac
|
|
4537
|
+
: null,
|
|
4538
|
+
dimensionsHmac: HMAC.test(receipt?.dimensionsHmac ?? "")
|
|
4539
|
+
? receipt.dimensionsHmac
|
|
4540
|
+
: null,
|
|
4541
|
+
}),
|
|
4542
|
+
)
|
|
4543
|
+
: [],
|
|
4544
|
+
),
|
|
4545
|
+
});
|
|
4546
|
+
};
|
|
4547
|
+
return Object.freeze({
|
|
4548
|
+
a: project(pair?.a),
|
|
4549
|
+
b: project(pair?.b),
|
|
4550
|
+
activityA: projectActivity(pair?.activityA),
|
|
4551
|
+
activityB: projectActivity(pair?.activityB),
|
|
4552
|
+
activityTui: projectActivity(pair?.activityTui),
|
|
4553
|
+
semanticEqual: pair?.semanticEqual === true,
|
|
4554
|
+
revisionMonotonic: pair?.revisionMonotonic === true,
|
|
4555
|
+
});
|
|
4556
|
+
})
|
|
4557
|
+
: [],
|
|
4558
|
+
),
|
|
4559
|
+
candidateSummaries: Object.freeze(
|
|
4560
|
+
Array.isArray(input?.candidateSummaries)
|
|
4561
|
+
? input.candidateSummaries.slice(-2).map((candidate) =>
|
|
4562
|
+
Object.freeze({
|
|
4563
|
+
clients: Object.freeze(
|
|
4564
|
+
Array.isArray(candidate?.clients)
|
|
4565
|
+
? candidate.clients.slice(0, 3).map((client) =>
|
|
4566
|
+
Object.freeze({
|
|
4567
|
+
client: CLIENTS.has(client?.client) ? client.client : null,
|
|
4568
|
+
correlationHmac: HMAC.test(client?.correlationHmac ?? "")
|
|
4569
|
+
? client.correlationHmac
|
|
4570
|
+
: null,
|
|
4571
|
+
workspaceHmac: HMAC.test(client?.workspaceHmac ?? "")
|
|
4572
|
+
? client.workspaceHmac
|
|
4573
|
+
: null,
|
|
4574
|
+
paneHmac: HMAC.test(client?.paneHmac ?? "") ? client.paneHmac : null,
|
|
4575
|
+
incarnationHmac: HMAC.test(client?.incarnationHmac ?? "")
|
|
4576
|
+
? client.incarnationHmac
|
|
4577
|
+
: null,
|
|
4578
|
+
renditionHmac: HMAC.test(client?.renditionHmac ?? "")
|
|
4579
|
+
? client.renditionHmac
|
|
4580
|
+
: null,
|
|
4581
|
+
revision: boundedInteger(client?.revision, 0xffff_ffff),
|
|
4582
|
+
cols: boundedInteger(client?.cols, 65_535),
|
|
4583
|
+
rows: boundedInteger(client?.rows, 65_535),
|
|
4584
|
+
deliveryFence: boundedInteger(client?.deliveryFence, 0xffff_ffff),
|
|
4585
|
+
}),
|
|
4586
|
+
)
|
|
4587
|
+
: [],
|
|
4588
|
+
),
|
|
4589
|
+
}),
|
|
4590
|
+
)
|
|
4591
|
+
: [],
|
|
4592
|
+
),
|
|
4593
|
+
});
|
|
4594
|
+
}
|
|
4595
|
+
|
|
4596
|
+
export function assessCard5ReplacementEnvelopeEvidence(input) {
|
|
4597
|
+
const after = input?.replacementGeneration;
|
|
4598
|
+
const before = input?.predecessorGeneration;
|
|
4599
|
+
const lanes = input?.lanes;
|
|
4600
|
+
if (
|
|
4601
|
+
typeof after !== "string" ||
|
|
4602
|
+
typeof before !== "string" ||
|
|
4603
|
+
after === before ||
|
|
4604
|
+
!Array.isArray(lanes) ||
|
|
4605
|
+
lanes.length !== 3
|
|
4606
|
+
) {
|
|
4607
|
+
return Object.freeze({ passed: false, reason: "generation-identity" });
|
|
4608
|
+
}
|
|
4609
|
+
for (const [laneOrdinal, lane] of lanes.entries()) {
|
|
4610
|
+
const events = lane?.events;
|
|
4611
|
+
const boundary = lane?.replacementBoundary;
|
|
4612
|
+
if (
|
|
4613
|
+
!Array.isArray(events) ||
|
|
4614
|
+
boundary?.predecessorGeneration !== before ||
|
|
4615
|
+
boundary?.replacementGeneration !== after ||
|
|
4616
|
+
!Number.isSafeInteger(boundary?.acceptedOrdinal) ||
|
|
4617
|
+
lane?.predecessorAcceptedAfterReplacement !== 0
|
|
4618
|
+
)
|
|
4619
|
+
return Object.freeze({ passed: false, reason: "replacement-boundary" });
|
|
4620
|
+
if (
|
|
4621
|
+
laneOrdinal < 2 &&
|
|
4622
|
+
(!Number.isSafeInteger(boundary.socketOrdinal) ||
|
|
4623
|
+
!Array.isArray(lane.socketEvents) ||
|
|
4624
|
+
!lane.socketEvents.some(
|
|
4625
|
+
({ generation, outcome, ordinal }) =>
|
|
4626
|
+
generation === before && outcome === "closed" && ordinal >= boundary.socketOrdinal,
|
|
4627
|
+
) ||
|
|
4628
|
+
!lane.socketEvents.some(
|
|
4629
|
+
({ generation, outcome, ordinal }) =>
|
|
4630
|
+
generation === after && outcome === "open" && ordinal <= boundary.socketOrdinal,
|
|
4631
|
+
))
|
|
4632
|
+
) {
|
|
4633
|
+
return Object.freeze({ passed: false, reason: "socket-replacement-order" });
|
|
4634
|
+
}
|
|
4635
|
+
if (
|
|
4636
|
+
events.some(
|
|
4637
|
+
({ generation, acceptedOrdinal }) =>
|
|
4638
|
+
generation === before && acceptedOrdinal >= boundary.acceptedOrdinal,
|
|
4639
|
+
)
|
|
4640
|
+
) {
|
|
4641
|
+
return Object.freeze({ passed: false, reason: "predecessor-accepted-after-replace" });
|
|
4642
|
+
}
|
|
4643
|
+
const firstReplacement = events.find(
|
|
4644
|
+
({ generation, acceptedOrdinal }) =>
|
|
4645
|
+
generation === after && acceptedOrdinal >= boundary.acceptedOrdinal,
|
|
4646
|
+
);
|
|
4647
|
+
if (firstReplacement?.type !== "terminal.seed") {
|
|
4648
|
+
return Object.freeze({ passed: false, reason: "replacement-not-seed-first" });
|
|
4649
|
+
}
|
|
4650
|
+
}
|
|
4651
|
+
if (
|
|
4652
|
+
!Array.isArray(input.staleRedemptions) ||
|
|
4653
|
+
input.staleRedemptions.length !== 2 ||
|
|
4654
|
+
input.staleRedemptions.some(
|
|
4655
|
+
(result) =>
|
|
4656
|
+
result?.rejected !== true ||
|
|
4657
|
+
result?.typed !== true ||
|
|
4658
|
+
!["redemption-rejected", "ticket-expired"].includes(result.reason),
|
|
4659
|
+
)
|
|
4660
|
+
) {
|
|
4661
|
+
return Object.freeze({ passed: false, reason: "retirement-not-typed" });
|
|
4662
|
+
}
|
|
4663
|
+
return Object.freeze({
|
|
4664
|
+
passed: true,
|
|
4665
|
+
reason: null,
|
|
4666
|
+
staleGenerationError: "generation-replaced",
|
|
4667
|
+
replacementFirstEnvelope: "seed",
|
|
4668
|
+
replacementSeedGeneration: after,
|
|
4669
|
+
predecessorEnvelopeAcceptedAfterReplace: false,
|
|
4670
|
+
});
|
|
4671
|
+
}
|
|
4672
|
+
|
|
4673
|
+
const CARD5_CORRELATION_KINDS = Object.freeze([
|
|
4674
|
+
"host-open",
|
|
4675
|
+
"canonical-before",
|
|
4676
|
+
"authority-handoff",
|
|
4677
|
+
"slow-isolation",
|
|
4678
|
+
"generation-replacement",
|
|
4679
|
+
"canonical-after",
|
|
4680
|
+
"native-observer",
|
|
4681
|
+
]);
|
|
4682
|
+
|
|
4683
|
+
/** Join already-bounded observed records without ever serializing raw authority. */
|
|
4684
|
+
export function sealCard5CorrelationEvidence(
|
|
4685
|
+
records,
|
|
4686
|
+
evidenceKey,
|
|
4687
|
+
requiredKinds = CARD5_CORRELATION_KINDS,
|
|
4688
|
+
) {
|
|
4689
|
+
if (
|
|
4690
|
+
!Array.isArray(records) ||
|
|
4691
|
+
!HMAC.test(evidenceKey ?? "") ||
|
|
4692
|
+
!Array.isArray(requiredKinds) ||
|
|
4693
|
+
requiredKinds.length < 1 ||
|
|
4694
|
+
requiredKinds.some((kind) => !CARD5_CORRELATION_KINDS.includes(kind)) ||
|
|
4695
|
+
new Set(requiredKinds).size !== requiredKinds.length
|
|
4696
|
+
) {
|
|
4697
|
+
throw new TypeError("Card5 correlation input is malformed");
|
|
4698
|
+
}
|
|
4699
|
+
const evidenceHmac = (domain, value) =>
|
|
4700
|
+
createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
4701
|
+
.update(`${domain}\0${value}`)
|
|
4702
|
+
.digest("hex");
|
|
4703
|
+
const expectedClients = ["opentui", "web-a", "web-b"];
|
|
4704
|
+
const validRecord = (record, ordinal) => {
|
|
4705
|
+
if (
|
|
4706
|
+
record?.kind !== requiredKinds[ordinal] ||
|
|
4707
|
+
record?.ordinal !== ordinal ||
|
|
4708
|
+
!HMAC.test(record?.valueHmac ?? "") ||
|
|
4709
|
+
!Array.isArray(record?.sourceBindings) ||
|
|
4710
|
+
record.sourceBindings.length !== 3
|
|
4711
|
+
)
|
|
4712
|
+
return false;
|
|
4713
|
+
const panes = new Set();
|
|
4714
|
+
const processes = new Set();
|
|
4715
|
+
for (const [clientOrdinal, binding] of record.sourceBindings.entries()) {
|
|
4716
|
+
if (
|
|
4717
|
+
binding?.client !== expectedClients[clientOrdinal] ||
|
|
4718
|
+
!HMAC.test(binding?.paneHmac ?? "") ||
|
|
4719
|
+
!HMAC.test(binding?.processHmac ?? "") ||
|
|
4720
|
+
!HMAC.test(binding?.clockHmac ?? "") ||
|
|
4721
|
+
binding?.bindingHmac !==
|
|
4722
|
+
evidenceHmac(
|
|
4723
|
+
"source-binding",
|
|
4724
|
+
[binding.client, binding.paneHmac, binding.processHmac, binding.clockHmac].join("\0"),
|
|
4725
|
+
)
|
|
4726
|
+
)
|
|
4727
|
+
return false;
|
|
4728
|
+
panes.add(binding.paneHmac);
|
|
4729
|
+
processes.add(binding.processHmac);
|
|
4730
|
+
}
|
|
4731
|
+
const expectedRecordHmac = evidenceHmac(
|
|
4732
|
+
"record",
|
|
4733
|
+
[
|
|
4734
|
+
record.kind,
|
|
4735
|
+
record.ordinal,
|
|
4736
|
+
record.valueHmac,
|
|
4737
|
+
...record.sourceBindings.map(({ bindingHmac }) => bindingHmac),
|
|
4738
|
+
].join("\0"),
|
|
4739
|
+
);
|
|
4740
|
+
return panes.size === 1 && processes.size === 3 && record.recordHmac === expectedRecordHmac;
|
|
4741
|
+
};
|
|
4742
|
+
const accepted = records.filter(validRecord);
|
|
4743
|
+
const recordIds = accepted.map(({ recordHmac }) => recordHmac);
|
|
4744
|
+
const kinds = new Set(accepted.map(({ kind }) => kind));
|
|
4745
|
+
const missingJoinCount = requiredKinds.filter((kind) => !kinds.has(kind)).length;
|
|
4746
|
+
const duplicateJoinCount = recordIds.length - new Set(recordIds).size;
|
|
4747
|
+
const malformedRecordCount = records.length - accepted.length;
|
|
4748
|
+
const serialized = JSON.stringify(records);
|
|
4749
|
+
const countMatches = (pattern) => [...serialized.matchAll(pattern)].length;
|
|
4750
|
+
const rawOwnerTokenCount = countMatches(/ownerToken|bearer/giu);
|
|
4751
|
+
const rawCapabilityCount = countMatches(/capability|redemptionTicket|subprotocol/giu);
|
|
4752
|
+
const rawPaneContentCount = countMatches(/paneContent|terminalBytes|rawContent/giu);
|
|
4753
|
+
const complete =
|
|
4754
|
+
records.length === requiredKinds.length &&
|
|
4755
|
+
malformedRecordCount === 0 &&
|
|
4756
|
+
missingJoinCount === 0 &&
|
|
4757
|
+
duplicateJoinCount === 0;
|
|
4758
|
+
const journeyHmac = createHmac("sha256", Buffer.from(evidenceKey, "hex"))
|
|
4759
|
+
.update(
|
|
4760
|
+
accepted
|
|
4761
|
+
.map(({ kind, ordinal, recordHmac }) => [kind, ordinal, recordHmac].join("\0"))
|
|
4762
|
+
.join("\n"),
|
|
4763
|
+
)
|
|
4764
|
+
.digest("hex");
|
|
4765
|
+
return Object.freeze({
|
|
4766
|
+
correlation: Object.freeze({
|
|
4767
|
+
complete,
|
|
4768
|
+
recordCount: Math.min(records.length, 256),
|
|
4769
|
+
missingJoinCount: Math.min(missingJoinCount + malformedRecordCount, 256),
|
|
4770
|
+
duplicateJoinCount: Math.min(Math.max(duplicateJoinCount, 0), 256),
|
|
4771
|
+
journeyHmac,
|
|
4772
|
+
}),
|
|
4773
|
+
privacy: Object.freeze({
|
|
4774
|
+
scannedRecordCount: Math.min(records.length, 256),
|
|
4775
|
+
rawOwnerTokenCount: Math.min(rawOwnerTokenCount, 256),
|
|
4776
|
+
rawCapabilityCount: Math.min(rawCapabilityCount, 256),
|
|
4777
|
+
rawPaneContentCount: Math.min(rawPaneContentCount, 256),
|
|
4778
|
+
}),
|
|
4779
|
+
});
|
|
4780
|
+
}
|