@plurnk/plurnk-xr 0.0.0-stage → 1.0.0

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/.env.defaults ADDED
@@ -0,0 +1,9 @@
1
+ # {§xr-host} {§xr-configuration} @plurnk/plurnk-xr — optional WebXR & spatial-audio peripheral module (`--omit=optional` omits it).
2
+ # Human-readable surface name rendered in document titles and `_meta.plurnk.surfaces` (1–80 chars, no control chars).
3
+ PLURNK_XR_APP_NAME="Plurnk XR"
4
+ # Initial Web Audio master gain percentage (0–100) unlocked on entering VR/AR.
5
+ PLURNK_XR_INITIAL_GAIN=35
6
+ # Initial constellation visibility posture (`on` = always visible, `passive` = fade in on activity/gates, `off` = audio only).
7
+ PLURNK_XR_INITIAL_VISIBILITY=on
8
+ # Lifetime in milliseconds (1000–60000) for transient reply/termination callouts (open human gates stay pinned until settled).
9
+ PLURNK_XR_CALLOUT_MS=8000
@@ -0,0 +1,112 @@
1
+ # Architecture
2
+
3
+ `@plurnk/plurnk-xr` is an independently packaged optional Plurnk daemon module
4
+ mounted at `/xr`. Rather than rebuilding editors, terminals, or virtual monitors
5
+ inside WebGL—where browser shaders lose to OS-composited 2D windows on text
6
+ clarity, input ergonomics, latency, and thermals—`plurnk-xr` claims the 360°
7
+ visual and auditory periphery *around* foreground 2D windows (`plurnk-web`,
8
+ `plurnk` Term, Remote Desktop) as a **synesthetic supervisory attention channel**
9
+ across concurrent workspaces, sessions, delegated workers, and human consent
10
+ gates.
11
+
12
+ ```mermaid
13
+ flowchart LR
14
+ subgraph Daemon["@plurnk/plurnk-service (:1066)"]
15
+ Core["Core VM & SessionOverview"]
16
+ SSE["GET /notifications Watch Plane SSE<br/>Snapshot ⊕ Deltas"]
17
+ ACP["/acp (Control & Stream Plane)"]
18
+ WebMount["/ (@plurnk/plurnk-web)"]
19
+ XrMount["/xr (@plurnk/plurnk-xr)"]
20
+ Core --> SSE & ACP
21
+ end
22
+
23
+ subgraph Foreground["Interactive 2D Foreground (Prompts · Diffs · Gate Decisions)"]
24
+ WebUI["plurnk-web · Termux · Remote Desktop"]
25
+ end
26
+
27
+ subgraph Periphery["360° Peripheral Constellation (/xr)"]
28
+ Shell["xr/ Minimalist OTM 2D Airlock, Auth & sse()<br/>3D-Glasses Mascot · [Enter VR] [Enter AR]"]
29
+ Store["xr/engine/watch-store.js<br/>WatchState + SalienceCue[]"]
30
+ Topo["xr/engine/topology.js + palette.js<br/>OKLCH Hues & Cylindrical (x, y, z)"]
31
+ Audio["xr/engine/audio.js<br/>Web Audio HRTF PannerNode (x, y, z)"]
32
+ Visuals["xr/engine/constellation-math.js + xr-renderer.js<br/>Direct WebXR · WebGL2 Instanced SDF Orbs & Tethers"]
33
+ Input["xr/engine/xr-input.js<br/>tracked-pointer Grab + X/Y Quick Toggles"]
34
+ Shell -->|"DaemonNotificationEnvelope"| Store
35
+ Store -->|"level state + edge cues"| Topo
36
+ Topo -->|"1:1 (x, y, z) + cues"| Audio & Visuals
37
+ Input -->|"anchor/offset + visibility/mute"| Topo & Audio
38
+ end
39
+
40
+ ACP & WebMount <-->|"interactive control"| WebUI
41
+ XrMount -->|"airlock HTML & dist/ assets"| Shell
42
+ SSE -->|"notifications/snapshot + 19 deltas"| Shell
43
+ ```
44
+
45
+ ## One owner per fact
46
+
47
+ | Concern | Authority | `plurnk-xr` responsibility |
48
+ | :--- | :--- | :--- |
49
+ | Listener, `/xr` prefix routing, startup/shutdown | Plurnk host (`@plurnk/plurnk-modules`) | Claim `mounts: ["/xr"]`; reject new requests on `stop()` and settle admitted route work before `close()` returns. |
50
+ | Workspaces, sessions, loops, consent gates, Watch snapshots | Daemon (`@plurnk/plurnk-service`) | Replicate `GET /notifications` (`notifications/snapshot` + 19 discrete deltas) passively with zero `/acp` dependency; own no daemon policy, database, or agent lifecycle. |
51
+ | Credential issuance, verification, sign-in posture | Daemon credential authority | Respect loopback, BFF `HttpOnly` cookie, and same-origin OIDC Bearer (`plurnk_oidc_grant`) postures on `/xr` and `GET /notifications`; never mint credentials or host a second login flow. |
52
+ | Prompts, code review, gate decisions, URL navigation | Foreground 2D clients (`plurnk-web`, `plurnk` Term, IDEs) | Open no links and mutate no prompts or gates in XR; surface canonical `<workspace>#<session>` addresses so operators act directly in their 2D window. |
53
+ | 2D airlock, capability posture & SSE transport | `on_the_money` (`xr/`, 5-S CSS, `on_the_money/live` `sse()`) | Centered 3D-glasses Plurnk mascot, independent `[Enter VR]` / `[Enter AR]` launch buttons, preference persistence, and authenticated SSE intake. |
54
+ | Synesthetic constellation, audio, shaders & controller input | `xr/engine/` (`palette.js`, `watch-store.js`, `topology.js`, `audio.js`, `constellation-math.js`, `xr-input.js`, `xr-renderer.js`) | Pure DOM-free, OTM-free JS computing one shared `(x, y, z)` + OKLCH + timbre model consumed identically by HRTF `PannerNode`s and instanced WebGL2 SDF shaders. |
55
+ | Asset compilation and packaging | `otm-build` (`esbuild`) and `dist/` asset inventory | Bundle local OTM + engine modules into pre-compressed `dist/` assets with `@plurnk/plurnk-meta` as the sole runtime npm dependency. |
56
+
57
+ ## Core invariants
58
+
59
+ ### 1. Strict `xr/` (OTM Airlock) vs. `xr/engine/` (Spatial/Audio) firewall
60
+
61
+ `on_the_money` owns the minimalist 2D airlock page (`/xr/`), capability gating,
62
+ and SSE transport (`on_the_money/live`), whereas inside an active `immersive-ar`
63
+ or `immersive-vr` session the DOM is invisible and stereo rendering runs at
64
+ 72–120 Hz on an `XRWebGLLayer` framebuffer:
65
+
66
+ - **`xr/` (`index.html`, `styles/*.css`, `app.js`, `auth.js`, `watch-client.js`):** Pure OTM (5-S `@layer schema, scheme, structure, style, state;`, `the`, `on`, `sse`, `otm-lint`, `stylelint`). `/xr/` renders no 2D constellation canvas or dashboard clutter—only the 3D-glasses Plurnk hamster, `[Enter VR]` / `[Enter AR]` buttons, and a quiet single-line diagnostic when needed.
67
+ - **`xr/engine/`:** Pure JavaScript over Web Audio API, WebXR, WebGL2, and `OffscreenCanvas` (zero `three` or third-party 3D libraries). ESLint forbids importing `on_the_money` or accessing `document` inside `xr/engine/`; structured graph state and frame/audio loops never pass through DOM attributes or `MutationObserver`.
68
+
69
+ ### 2. Synesthetic spatial binding (`Orb (x, y, z) === PannerNode (x, y, z)`)
70
+
71
+ Human HRTF localization binds sharply to remembered peripheral slots once a
72
+ synchronous visual transient and spatialized sound share one 3D world coordinate:
73
+
74
+ - **Clear `±28°` front foveal corridor:** Default workspace anchors occupy slot-pinned left and right peripheral wings (`[-115°, -28°]` and `[+28°, +115°]` in right-handed `local-floor` `-Z`-forward coordinates) so floating 2D work windows dead ahead stay unobstructed and workspaces never jump ears as siblings come and go.
75
+ - **Parent-relative cylindrical constellation:** Each workspace hub sits at $(\theta_w, y_w, r_w)$; tethered root session bubbles and `work`/`fork` child satellites store local $(\Delta\theta, \Delta y, \Delta r)$ offsets so moving a workspace hub moves its entire session subtree and HRTF `PannerNode`s rigidly, while individual session bubbles can also be offset independently.
76
+ - **Equal-luminance OKLCH identity ring:** Workspaces receive deterministic hues from an equal-luminance OKLCH cool/mid ring (Teal, Azure, Emerald, Violet, Cyan, Magenta, Mint, Indigo) paired 1:1 with consonant D-major add6/add9 timbre registers (`146.83 Hz`–`440 Hz`). **Amber (`~75°` OKLCH)** and **Crimson (`~25°` OKLCH)** are strictly excluded from workspace colors and reserved for open human review gates and `>= 400` loop failures.
77
+ - **Visibility postures (`on | passive | off`):** Operators can keep constellations continuously visible at calm ambient opacity (`on`), fade idle bubbles out completely until activity or a gate occurs (`passive`), or run pure spatial audio with visuals off (`off`).
78
+ - **Physical `tracked-pointer` controller manipulation:** `xr-input.js` enables Trigger grab-and-drag (with thumbstick vertical depth adjustment), `X`/`A` (`buttons[4]`) visibility cycling (`on | passive | off`), and `Y`/`B` (`buttons[5]`) audio mute toggling—strictly gated on `xrSession.visibilityState === "visible"`, `targetRayMode === "tracked-pointer"`, and `!source.hand` so backgrounded Seamless Multitasking focus and bare hand gestures never misfire.
79
+
80
+ ### 3. Level state vs. edge salience over the Watch Plane
81
+
82
+ `GET /notifications` streams `notifications/snapshot` followed by 19 compact
83
+ `DAEMON_NOTIFICATION_EVENTS`:
84
+
85
+ | Watch Plane Frame | Level State (`WatchState`) | Edge Cue (`SalienceCue`) & Peripheral Consequence |
86
+ | :--- | :--- | :--- |
87
+ | `notifications/snapshot` | Hydrates non-archived workspaces, active/recent sessions, and open `proposals` / `interactions` | **Zero edge cues** (historical completions never chime on connect; already-open gates immediately sustain amber SDF halo + `sus4` harmonic suspension + pinned callout state) |
88
+ | `workspace/*`, `session/{created,archived,deleted,titled,policy}` | Updates workspace hubs, tethered session bubbles, and `work`/`fork` child satellites | Quiet exponentially smoothed materialization/fold-in ($\tau = 180\text{ ms}$) at the workspace's `(x, y, z)` |
89
+ | `loop/started`, `stream/concluded` | Marks session `running` (materializing woken `data.session` snapshots in place) | `activity` cue: rate-bounded `< 900 Hz` micro-pluck + synchronous chromatic ripple on the session bubble |
90
+ | `loop/proposal` (`decision === "review"`), `loop/interaction` | Adds open gate to session (`gates > 0`) | `gate-opened` cue + breathing `75°` Amber SDF halo + `0.25 Hz` `sus4` harmonic suspension + pinned `<workspace>#<session>` callout entry |
91
+ | `loop/gate-settled` | Removes settled gate from session | `gate-settled` cue: immediate consonant harmonic resolution; amber gate halo releases |
92
+ | `session/replied` | Updates session's latest `reply` (`completion`, `excerpt`) | `replied` cue: records `<workspace>#<session>` reply excerpt callout |
93
+ | `loop/parked`, `loop/terminated`, `notice/event` | Updates session `lifecycle` (`parked`, `completed`, `cancelled`, `failed`) and clears stale gates | `terminated` / `notice` cue: consonant cadence (`200`), soft park (`202`), muted release (`499`), or `25°` Crimson flash + `< 220 Hz` fifth drop (`>= 400`) |
94
+
95
+ ### 4. Immersive postures and Secure Context airlock
96
+
97
+ | Mode | Target environment | Behavior |
98
+ | :--- | :--- | :--- |
99
+ | `immersive-ar` | Meta Quest Browser (Horizon OS Seamless Multitasking), Android XR Chrome | Transparent passthrough (`rgba(0, 0, 0, 0)`) behind floating 2D work windows with world-anchored peripheral constellations and HRTF audio. |
100
+ | `immersive-vr` | Apple Vision Pro (visionOS Safari), Meta Quest VR, standalone VR headsets | Minimal dark horizon (`#050807`) peripheral constellation + full head-tracked HRTF spatial audio. |
101
+ | 2D airlock (`2d` / `2d-insecure`) | Browser tab prior to entering XR | Minimalist airlock featuring the 3D-glasses Plurnk hamster, capability-gated `[Enter VR]` / `[Enter AR]` buttons, and HTTPS / sign-in guidance when required. |
102
+
103
+ `navigator.xr` requires a browser **Secure Context** (`https://` or
104
+ `http://localhost` / `127.0.0.1`). Over insecure non-loopback HTTP, `/xr/`
105
+ disables the XR entry buttons and surfaces a concise TLS / `localhost` note.
106
+
107
+ ## Configuration authority
108
+
109
+ Behavioral choices live in `.env.defaults` (`PLURNK_XR_*`), assembled into the
110
+ daemon's environment floor and read via `@plurnk/plurnk-meta` `Knob` with zero
111
+ inline fallback literals. Invalid settings isolate to `module.contained` so
112
+ unrelated daemon surfaces keep running.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Plurnk contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,35 @@
1
- # Temporary Holding Version
1
+ # @plurnk/plurnk-xr
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional WebXR and HRTF spatial-audio peripheral module for [`@plurnk/plurnk-service`](https://github.com/plurnk/plurnk-service), mounted at `/xr` (`npm install --omit=optional` omits it). Contract: [`SPEC.md`](SPEC.md). Boundaries: [`ARCHITECTURE.md`](ARCHITECTURE.md). Knobs: [`.env.defaults`](.env.defaults).
4
+
5
+ Primary engineering work—reading diffs, writing prompts, running terminals, and approving gates—stays in crisp native 2D foreground windows (`@plurnk/plurnk-web` at `/`, `plurnk` Term, Remote Desktop). `/xr/` opens as a minimalist 2D airlock (the Plurnk hamster in red/cyan 3D glasses with **Enter VR** and **Enter AR** buttons) that launches a 360° tethered bubble constellation and HRTF audio field around your floating 2D windows with zero `/acp` connections and zero third-party runtime dependencies.
6
+
7
+ ## Immersive Modes & Controls
8
+
9
+ | Mode / Control | Behavior |
10
+ | :--- | :--- |
11
+ | **`Enter AR` (`immersive-ar`)** | Transparent passthrough peripheral orbs, `work`/`fork` child satellites, gradient tethers, and head-tracked HRTF audio behind floating 2D windows (Meta Quest Horizon OS Seamless Multitasking, Android XR). |
12
+ | **`Enter VR` (`immersive-vr`)** | Calm dark-horizon (`#050807`) peripheral constellation + head-tracked HRTF audio (Apple Vision Pro, VR headsets). |
13
+ | **Controller Trigger + Thumbstick** | Grab a workspace hub to move its tethered session subtree and HRTF `PannerNode`s rigidly, or grab an individual session bubble (`tracked-pointer` controllers while `visibilityState === "visible"`). |
14
+ | **Controller `X`/`A` · `Y`/`B`** | `X`/`A` cycles constellation visibility (`on -> passive -> off`); `Y`/`B` toggles master audio mute. |
15
+
16
+ > **Headset Secure Context note:** Browser WebXR APIs (`navigator.xr`) require `https://` or `localhost`. When connecting a standalone headset to a workstation daemon over LAN, serve via TLS (e.g., Tailscale HTTPS or reverse proxy) or forward loopback (`adb reverse tcp:1066 tcp:1066`).
17
+
18
+ ## Development
19
+
20
+ ```sh
21
+ npm ci --no-audit --no-fund
22
+ npm run build # compile production OTM + WebXR assets into dist/
23
+ npm test # spec-check, tsc, eslint, otm-lint, stylelint, and unit/HTTP suite
24
+ npm run deps:drift # verify manifest floors and lockfile match npm latest
25
+ ```
26
+
27
+ To serve live `xr/` and `src/documents.js` edits directly from a running development daemon without manual builds or daemon restarts, preload `./scripts/dev-loader.mjs`:
28
+
29
+ ```sh
30
+ node --conditions=plurnk-dev --import /path/to/plurnk-xr/scripts/dev-loader.mjs src/service.ts start
31
+ ```
32
+
33
+ ## License
34
+
35
+ Code: [MIT](LICENSE). Hamster artwork in `/xr/icons/plurnk-3d.svg` derives from Google Noto Emoji (Apache-2.0; see `/xr/icons/NOTO-NOTICE.txt` and `/xr/icons/APACHE-2.0.txt`).
package/SPEC.md ADDED
@@ -0,0 +1,172 @@
1
+ # XR module specification
2
+
3
+ ## §xr-host Hosting and `/xr` mount
4
+
5
+ `@plurnk/plurnk-xr` is an independently packaged optional Plurnk daemon module
6
+ designed for inclusion in `@plurnk/plurnk-service` `optionalDependencies` and
7
+ dynamic discovery via `"plurnk": { "kind": "module", "export": "./module" }`.
8
+ `@plurnk/plurnk-xr/module` exports a zero-argument `DaemonModule` factory that
9
+ claims `mounts: ["/xr"]`, advertises `surfaces: [{ id: "xr", path: "/xr/", label, glyph: "🥽" }]`
10
+ when configuration is valid (so `/acp` `initialize` projects `_meta.plurnk.surfaces`
11
+ for header launchers in `@plurnk/plurnk-web`), and registers `/xr` on the daemon's
12
+ existing HTTP listener at `start()`. It owns no listener, process, database, or
13
+ session lifecycle.
14
+
15
+ | Installation | Behavior |
16
+ | :--- | :--- |
17
+ | `@plurnk/plurnk-xr` composed | Discovered via `plurnk.kind === "module"`, claims `/xr` and `/xr/*`, and advertises `surfaces[0]` while leaving `/` (`@plurnk/plurnk-web`), `/acp`, `/mcp`, and `/notifications` untouched. |
18
+ | Omitted (`npm install --omit=optional`) | Absent from daemon composition; `/xr` remains unclaimed and absent from `_meta.plurnk.surfaces`. |
19
+
20
+ ## §xr-route-settlement Shutdown admission and route settlement
21
+
22
+ | Boundary | Contract |
23
+ | :--- | :--- |
24
+ | `stop()` | Refuses every subsequent request to `/xr` with a private `503` RFC 9457 Problem (`xr/service-stopping`) before reading assets, omitting the response body on `HEAD` and draining the request stream. Already admitted requests continue until their handlers settle. |
25
+ | `close()` | Invokes `stop()`, joins all admitted in-flight route handlers (`Promise.allSettled`), and releases any injected asset source (`assets.close?.()`). Safe to call without a preceding `stop()` or completed `start()`. |
26
+ | Errors | Unexpected handler rejections still propagate to the HTTP host; joining in-flight requests in `close()` never masks cleanup failures or leaves admitted work running after `close()` resolves. |
27
+
28
+ ## §xr-configuration Configuration boundary and containment
29
+
30
+ | Knob | Owner | Contract |
31
+ | :--- | :--- | :--- |
32
+ | `PLURNK_XR_APP_NAME` | `.env.defaults` | Trimmed non-empty string (`1`–`80` characters, no Unicode control characters) stamped on `<title>`, `<html data-app-name>`, and `surfaces[0].label`. |
33
+ | `PLURNK_XR_INITIAL_GAIN` | `.env.defaults` | Integer percentage `0`–`100` read through `@plurnk/plurnk-meta` `Knob.integer` with no inline fallback, stamped on `<body data-gain>` to initialize Web Audio master gain (`0.0`–`1.0`). |
34
+ | `PLURNK_XR_INITIAL_VISIBILITY` | `.env.defaults` | Case-insensitive enum `on \| passive \| off` read through `Knob.text`, stamped on `<body data-visibility>` and selecting the initial constellation visibility posture when no persisted preference exists. |
35
+ | `PLURNK_XR_CALLOUT_MS` | `.env.defaults` | Integer duration `1000`–`60000` milliseconds read through `Knob.integer`, stamped on `<html data-callout-ms>` to bound transient reply/termination callout lifetime while open review gates remain pinned. |
36
+ | `PLURNK_ACP_URL` | Daemon / operator environment | Optional same-origin path or `http(s):` URL (without embedded credentials or fragments) from which `/xr` derives the daemon `/notifications` URL (`data-notifications-url` on `<html>`) and external `connect-src` origin; empty or unset selects same-origin `/notifications`. |
37
+
38
+ Invalid values for `PLURNK_XR_*` or `PLURNK_ACP_URL` are recorded in
39
+ `module.contained` (`{ key, message }`) and answer `503` HTML error documents on
40
+ `/xr/` document routes without failing daemon boot or interfering with other
41
+ daemon mounts. Missing `.env.defaults` floor keys throw at startup rather than
42
+ substituting hidden defaults.
43
+
44
+ ## §xr-assets Static resource inventory and index resolution
45
+
46
+ | Request | Resolution |
47
+ | :--- | :--- |
48
+ | `GET /xr[?query]` | `303` redirect to `/xr/[?query]` so relative `assets/*` and `icons/*` references inside `otm-build` HTML resolve beneath `/xr/`. |
49
+ | `GET /xr/`, `GET /xr/index.html` | Serves the configured 2D airlock HTML (`200`, `text/html; charset=utf-8`). |
50
+ | `GET /xr/assets/<build-generated-name>` | Serves the `otm-build`-compiled JavaScript or 5-S CSS asset from `dist/assets.json`. |
51
+ | `GET /xr/icons/plurnk-3d.svg` | Serves the 3D-glasses Plurnk hamster mascot SVG (`image/svg+xml`) alongside `/xr/icons/NOTO-NOTICE.txt` and `/xr/icons/APACHE-2.0.txt`. |
52
+ | `GET /xr/vendor/OTM-LICENSE.txt` | Serves the bundled `on_the_money` MIT license attribution. |
53
+ | `HEAD` on any served path | Same status and headers as `GET`, with an empty body. |
54
+ | Unlisted path under `/xr/*` | `404` HTML error document, never a SPA fallback to `index.html` or a filesystem path lookup. |
55
+ | Method other than `GET` or `HEAD` | `405` HTML error document with `Allow: GET, HEAD`. |
56
+
57
+ Query strings do not alter asset lookup. Every asset and encoded representation
58
+ listed in `dist/assets.json` is verified as a regular file during `start()`
59
+ before routes serve traffic, and bytes are read on demand from the OS page cache
60
+ rather than pinned in private heap memory.
61
+
62
+ ## §xr-asset-encoding Pre-compressed static content encoding
63
+
64
+ | Boundary | Contract |
65
+ | :--- | :--- |
66
+ | Build | Runs `otm-build ./xr --out ./dist`, retains the identity file for every emitted asset, and generates `.br` (Brotli) and `.gz` (gzip) sidecars for non-HTML assets only when strictly smaller than the original. Sidecars are referenced inside `dist/assets.json`, never exposed as public URLs. |
67
+ | Negotiation | Negotiates `Accept-Encoding` per RFC 9110 §12.5.3 (`q=` weights, `x-gzip` alias, `*` wildcard, and explicit `q=0` exclusions) with zero third-party runtime dependencies. Absent or empty `Accept-Encoding` selects `identity`; ties select the smallest representation; when all available representations are excluded (`q=0`), responds `406` HTML error document. |
68
+ | Headers | Appends `Accept-Encoding` to `Vary`, sets `Content-Encoding` only when non-identity is selected, sets `Content-Length` to the chosen representation's byte length, and sets `X-Content-Type-Options: nosniff`. Dynamic shell and error HTML documents are served uncompressed with `Cache-Control: no-store`. |
69
+
70
+ ## §xr-browser-security Browser security headers and Secure Context posture
71
+
72
+ Dynamic `/xr/` documents, redirects, and error responses emit:
73
+
74
+ - `Cache-Control: no-store`
75
+ - `Referrer-Policy: no-referrer`
76
+ - `X-Content-Type-Options: nosniff`
77
+ - `X-Frame-Options: DENY`
78
+ - `Permissions-Policy: xr-spatial-tracking=(self)`
79
+ - `Content-Security-Policy`: `default-src 'self'; script-src 'self'; style-src 'self'; connect-src 'self' [<acpHttpOrigin>] [<issuerOrigin>]; img-src 'self' data: blob:; media-src 'self' blob:; worker-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'`
80
+
81
+ When `PLURNK_AUTH_ISSUER` or the daemon credential authority face exposes an
82
+ external `http(s):` issuer origin (honoring loopback `X-Forwarded-Host` before
83
+ `Host`), `connect-src` includes that origin. No inline scripts or inline styles
84
+ are emitted.
85
+
86
+ In the browser, `xr/engine/posture.js` checks `isSecureContext` before reading
87
+ `navigator.xr`: on non-secure HTTP origins (such as unencrypted LAN IPs), the
88
+ airlock writes `the("xr-posture", "2d-insecure")`, keeps both XR entry buttons
89
+ disabled, and reveals the HTTPS / `localhost` guidance via `@layer state` CSS.
90
+
91
+ ## §xr-watch-plane Watch Plane SSE client, auth postures, and salience reducer
92
+
93
+ `/xr/` replicates workspace, session, child-lineage, and human-gate state over
94
+ `GET /notifications` (`DaemonNotificationEnvelope.json`) with zero `/acp` calls:
95
+
96
+ | Aspect | Contract |
97
+ | :--- | :--- |
98
+ | Transport & auth (`xr/watch-client.js`, `xr/auth.js`) | Streams all 21 Watch Plane event types via `on_the_money/live` `sse()` (`fetch`-SSE mode with `Last-Event-ID` replay). Loopback and BFF cookie deployments send `{}` extra headers (`same-origin` credentials); when `localStorage["plurnk_oidc_grant"]` holds a grant matching the notifications origin, attaches `Authorization: Bearer <accessToken>`, coordinates `refresh_token` exchanges across sibling tabs (`/`, `/xr/`) via Web Locks (`plurnk:oauth:refresh:<origin>`) and `BroadcastChannel("plurnk_oidc_grant")` + `storage` events, and offers PKCE S256 sign-in handoff (`/.well-known/oauth-protected-resource` -> `/auth/callback` with `returnTo: "/xr/"`, falling back to `/`) when `signed-out`. |
99
+ | Homomorphic level state (`xr/engine/watch-store.js`) | `notifications/snapshot` hydrates non-archived workspaces, `origin === "model"` sessions (`root`, `work`, `fork`), and open review gates (`ProposalProjection` with `disposition.decision === "review"`, `ClientInteractionProjection`) with canonical `<workspace>#<session>` addresses and concise single-line summaries (`subject.command` / `subject.title` / `request.message`). Active lifecycles (`running`, `queued`, `parked`) are always retained alongside `gates > 0`; `loop/started` materializes embedded `data.session` snapshots in place when a previously omitted session wakes, falling back to `resyncRequired` only when an unknown session delta arrives without `data.session` while `state.omitted > 0`. |
100
+ | Edge salience cues (`SalienceCue[]`) | `notifications/snapshot` emits `cues: []` so historical sessions never trigger arrival chimes or toasts on connect. Live deltas emit typed cues: `activity` (`loop/started`, `stream/concluded`), `gate-opened` (`loop/proposal` review, `loop/interaction`), `gate-settled` (`loop/gate-settled`), `replied` (`session/replied`), `terminated` (`loop/parked`, `loop/terminated`), and `notice` (`notice/event`). |
101
+
102
+ ## §xr-spatial-topology OKLCH palette, cylindrical constellation, and callout queue
103
+
104
+ `xr/engine/palette.js` and `xr/engine/topology.js` compute one input-agnostic
105
+ spatial frame shared 1:1 by Web Audio HRTF `PannerNode`s and the WebXR/WebGL2
106
+ renderer:
107
+
108
+ | Aspect | Contract |
109
+ | :--- | :--- |
110
+ | OKLCH workspace ring (`palette.js`) | Assigns each workspace a deterministic slot (`0`–`7`) on an equal-luminance OKLCH cool/mid ring (Teal, Azure, Emerald, Violet, Cyan, Magenta, Mint, Indigo; `L = 0.74, C = 0.155`) with precomputed linear-gamut-clamped sRGB `[r, g, b]` floats and matching harmonic timbre slot. Amber (`75°`) and Crimson (`25°`) are excluded from workspace identity and reserved for `SEMANTIC_PALETTE.gate` and `SEMANTIC_PALETTE.failed`. |
111
+ | Peripheral wings & parent-relative offsets (`topology.js`) | Default workspace hubs claim persistent alternating left/right peripheral wing slots outside the `±28°` front foveal corridor in right-handed `local-floor` meters ($x = r \sin\theta$, $y = \text{elevation}$, $z = -r \cos\theta$). Root sessions store $(\Delta\theta, \Delta y, \Delta r)$ relative to their workspace hub (omitting untouched empty draft root sessions); `work`/`fork` children store $(\Delta\theta, \Delta y, \Delta r)$ relative to their parent session. Moving a workspace hub (`setWorkspaceAnchor`) moves all tethered descendants rigidly; moving a session (`setSessionOffset`) moves that session and its children; `exportLayout` / `importLayout` persist overrides by canonical name. |
112
+ | Visibility modes (`on \| passive \| off`) | `on` renders active/gated nodes at `1.0` and resting nodes at `0.28` opacity; `passive` renders only active, gated, or recently pulsed nodes (plus their tether ancestors) at `1.0` and fades quiet nodes to `0`; `off` sets visual `targetOpacity = 0` while preserving 3D `(x, y, z)` coordinates for spatial audio. |
113
+ | Callout queue | Open gates produce **pinned** callouts (`pinned: true, expiresAtMs: null`) at their session's `(x, y, z)` that clear immediately upon gate settlement or termination. Live `replied`, `terminated` (`status !== 202`), and `notice` cues enqueue transient callouts (`expiresAtMs = nowMs + calloutMs`, bounded to at most `4` concurrent transient cards without evicting pinned gates). |
114
+
115
+ ## §xr-spatial-audio Salience-separated Web Audio HRTF spatializer
116
+
117
+ `xr/engine/audio.js` synthesizes spatialized Web Audio cues with zero external
118
+ audio assets or runtime dependencies:
119
+
120
+ | Aspect | Contract |
121
+ | :--- | :--- |
122
+ | 1:1 HRTF spatialization & listener pose | Positions each voice's `PannerNode` (`panningModel = "HRTF"`, `distanceModel = "inverse"`) at the exact `(x, y, z)` coordinates from `PeripheralWorldFrame.nodes`, updating live as workspace or session anchors move and tracking `setListenerPose({ position, forward, up })` (defaulting to ear level `(0, 1.35, 0)` facing `-Z`). |
123
+ | Workspace timbre registers (`TIMBRE_REGISTERS`) | Pairs `WORKSPACE_PALETTE` slots `0`–`7` 1:1 with consonant D-major add6/add9 frequencies (`146.83 Hz`–`440 Hz`, warm `sine`/`triangle` waveforms) so concurrent workspaces never clash; delegated `satellite` children (`work`/`fork`) sound an octave higher at reduced amplitude as light counterpoint. |
124
+ | Salience separation & anti-fatigue bounds | Idle state allocates zero oscillators (`0.0` output). Routine `activity` cues (`loop/started`, `stream/concluded`) pass through a `< 900 Hz` low-pass filter with per-session refractory cooldown (`1600 ms`) and a global active-transient cap (`6`). Open human gates (`gates > 0` level state) sustain a `0.25 Hz` breathing `sus4` dyad at the gated session's `(x, y, z)`—starting smoothly on `notifications/snapshot` or chiming softly on live `gate-opened`—and release immediately when `gates === 0`. `gate-settled` and `terminated` cues play consonant upward resolution (`accept` / `200`), soft park (`202`), muted release (`499` / `reject`), or a `< 220 Hz` fifth drop (`>= 400`). |
125
+ | User-gesture unlock & teardown | Lazily creates and resumes `AudioContext` on user gesture (`unlock()`), honors master `setGain(0..1)` and `setMuted(boolean)` / `toggleMuted()`, and stops all active nodes before `AudioContext.close()` on `dispose()`. |
126
+
127
+ ## §xr-constellation-renderer Direct WebXR and WebGL2 SDF constellation renderer
128
+
129
+ `xr/engine/constellation-math.js` and `xr/engine/xr-renderer.js` render stereo
130
+ `XRWebGLLayer` peripheral constellations directly over WebXR + WebGL2 with zero
131
+ third-party 3D libraries:
132
+
133
+ | Aspect | Contract |
134
+ | :--- | :--- |
135
+ | Temporal smoothing & orbital kinematics (`constellation-math.js`) | Exponentially smooths orb `(x, y, z)` coordinates, `opacity`, and `gateFactor` ($\tau = 0.18\text{ s}$), adds gentle tangent-plane orbital motion (`0.018 m`, `0.65 rad/s`) to `running` `satellite` children, decays `25°` Crimson failure flashes (`>= 400`) exponentially, and packs reusable `Float32Array` instance/vertex buffers (`ORB_INSTANCE_FLOATS = 11`, `LINE_VERTEX_FLOATS = 7`). |
136
+ | Instanced SDF orbs & gradient tethers (`xr-renderer.js`) | Compiles `#version 300 es` instanced camera-aligned SDF sphere billboards (`0.085 m` workspace hub, `0.052 m` root session, `0.032 m` child satellite; Fresnel rim, equal-luminance OKLCH core, synchronous activity ripple, `75°` Amber gate halo) and `gl.LINES` gradient tether filaments (`Workspace Hub ── Session ── Satellite` plus active controller ray) using premultiplied alpha. |
137
+ | Stereo `immersive-ar` & `immersive-vr` loop | Requests `local-floor` (falling back to `local`), clears `rgba(0, 0, 0, 0)` in `immersive-ar` for transparent passthrough behind 2D windows and `#050807` in `immersive-vr`, feeds `XRViewerPose` head orientation/position into `audio.setListenerPose(...)` every frame, and cleans up on `XRSession.onend` or `dispose()`. |
138
+
139
+ ## §xr-controller-input Physical tracked-pointer controller manipulation
140
+
141
+ `xr/engine/xr-input.js` lets operators arrange peripheral constellations and
142
+ toggle visibility/audio from physical W3C `xr-standard` controllers without
143
+ mutating daemon state:
144
+
145
+ | Aspect | Contract |
146
+ | :--- | :--- |
147
+ | Focus & modality gate | Processes input **only** when `xrSession.visibilityState === "visible"`, `source.targetRayMode === "tracked-pointer"`, and `!source.hand`. Backgrounded/blurred Seamless Multitasking focus and bare `XRHand` hand tracking are ignored. |
148
+ | Forgiving ray-sphere picking & Trigger drag (`buttons[0]`, `axes[3]`) | Intersects controller rays against visible orbs (`1.65x` radius forgiveness, `0.055 m` floor) with `satellite -> session -> workspace` priority and hover micro-haptics. Holding Trigger (`buttons[0]`) on a workspace hub updates `setWorkspaceAnchor` (moving tethered sessions + `PannerNode`s rigidly); holding Trigger on a session/satellite updates `setSessionOffset`, with thumbstick vertical axis `axes[3]` adjusting depth $r \in [0.9\text{ m}, 3.2\text{ m}]$ and persisting layout on release. |
149
+ | Face button quick toggles (`buttons[4]`, `buttons[5]`) | Rising edges on `buttons[4]` (`X` on left, `A` on right) cycle `topology.cycleVisibilityMode()` (`on -> passive -> off -> on`); rising edges on `buttons[5]` (`Y` on left, `B` on right) toggle `audio.toggleMuted()`. |
150
+
151
+ ## §xr-launch-shell Minimalist OTM 2D airlock and `xr/engine/` firewall
152
+
153
+ The `/xr/` document uses `on_the_money` (`the`, `on`, and the 5-S
154
+ `@layer schema, scheme, structure, style, state;` green stylesheet substrate) as
155
+ a minimalist 2D WebXR airlock while isolating WebXR/WebGL2/Web Audio plumbing
156
+ inside `xr/engine/`:
157
+
158
+ - `<html data-app-name data-notifications-url data-callout-ms data-xr-version>` and `<body data-xr-posture data-xr-session data-connection data-visibility data-audio-muted data-gain>`
159
+ - Centered `#xr-mascot` (`icons/plurnk-3d.svg` — Plurnk hamster wearing red/cyan 3D anaglyph glasses)
160
+ - Side-by-side `[data-action="enter-xr"]` buttons (`[data-xr-mode="immersive-vr"]` **Enter VR** and `[data-xr-mode="immersive-ar"]` **Enter AR**), enabled independently via `probeXrCapabilities` (`navigator.xr.isSessionSupported`) and unlocking `AudioContext` + requesting the matching `XRSession` in a single user gesture
161
+ - Quiet single-line `#xr-airlock-note` status line revealed only when `2d-insecure`, `2d`, `signed-out`, or `xr-session="active"`
162
+ - ESLint enforces the boundary mechanically: `xr/*.js` satisfies `on_the_money/eslint-config`, `otm-lint`, and `stylelint`, whereas `xr/engine/**/*.js` is forbidden from importing `on_the_money` or accessing `document`.
163
+
164
+ ## §xr-package Lean optional package contract
165
+
166
+ To remain small and dependency-clean enough for default inclusion in
167
+ `@plurnk/plurnk-service` `optionalDependencies`:
168
+
169
+ - Runtime `dependencies` contain `@plurnk/plurnk-meta` only (zero third-party runtime packages).
170
+ - `peerDependencies` declare `@plurnk/plurnk-contracts` and `@plurnk/plurnk-modules`.
171
+ - Authoring, bundling, and verification tools (`on_the_money`, `esbuild`, `linkedom`, `stylelint`, `typescript`, `eslint`, `@plurnk/plurnk-spec-check`) stay exclusively in `devDependencies`.
172
+ - `package.json#exports` exposes `./module` (`types` + `default`) and `./package.json`, and `package.json#files` ships `.env.defaults`, `types/module.d.ts`, `src/*.js`, `dist/`, `README.md`, `ARCHITECTURE.md`, `SPEC.md`, and `LICENSE`.