Steps 6.4-6.7B — Local surfaces, reference-exhibit validation, SciFi Observation surface

One commit for the work accumulated in the working tree since Step 6.3,
which had never been split into per-step commits:

- src/local-surfaces.js + src/surface-url.js (new); src/ui.js,
  src/validation.js, src/connection.js and public/index.html updated for
  local-surface hosting and generic surface rendering
- tests: local-surfaces (20), scifi-surfaces (24) and postmessage-interop (7)
  new; connection/museum-gallery/surface-validation suites updated
- reference exhibits: shared/contract-core.js defaults to Contract 5.3
  (major 5, minor 3, xzbt 5.3); museum-gallery advertises its surface
  catalog; aquarium/haunted-house/planetarium adapters updated
- SciFi-XZBT (Step 6.7A/6.7B): surface-mode.js + surface-bus.js,
  Observation-surface boot branch, local-change hooks, view.pillars /
  view.warp-flight targets; fixture byte-identical to G:/.vibe/SciFi-XZBT
- SciFi-XZBT contract adapter handshake fix: the inbound bridge filter no
  longer gates on an exact advisory xzbt value (Contract 5.3 §6.5), only on
  its presence/type, matching the host's own envelope validation; the
  adapter now advertises contract minor 3 / version 5.3.0, which it already
  implemented via the 5.3 surfaces field. Root cause of the five failing
  postmessage-interop tests (host hello was silently dropped).
- docs: architecture 6.4 and 6.7A, reference 6.6 and 6.7; evidence logs;
  test-fixtures/PROVENANCE.md resync record

Test results: NGN 154/154 (was 149/154); postmessage-interop 7/7 (was 2/7);
SciFi contract harness 21/21, real-adapter suite 32/32. git diff --check
clean for changed files; two pre-existing trailing-whitespace lines remain
in test-fixtures/reference-exhibits/scifi/index.html, copied verbatim from
the authoritative SciFi source.

Step 6.7 live verification (browser Observation, packaged standalone) is
still pending and is not claimed here.
This commit is contained in:
2026-09-14 19:45:27 -07:00
parent ed76cf6189
commit 745912e451
40 changed files with 5346 additions and 210 deletions
@@ -0,0 +1,165 @@
# Step 6.4 — Local Multi-Surface Rendering
Verified 2026-09-14. **Step 6.4 complete.** Contract 5.3 presentation surfaces
can be rendered locally through the normal NGN operator UI.
## Pre-change architecture
`ExhibitConnection` owned one iframe, remembered its normalized same-origin
URL in `connection.url`, and passed it to `ExhibitHost.connect()`.
`ExhibitHost` stored that URL as `exhibitBaseUrl`; discovery called
`validateSurfaceCatalog()` and stored the surviving descriptors in `host.surfaces`.
The UI displayed descriptive surface cards only. The primary iframe alone used
`postMessageTransport`, which checked both source window and origin.
There was no separate window/frame lifecycle helper for presentation views.
Museum Gallery's `control.html` is both its entry point and declared primary.
Only this page constructs its Contract Core. `artifact.html` and `info-wall.html`
attach through the fixture's existing BroadcastChannel bus and construct no
independent Core. NGN does not participate in that bus. SciFi is an external
reference implementation, not a source of NGN architecture.
The working tree already contained Step 6.3 contract/fixture/test/documentation
edits, including an untracked postMessage interoperability test. They were
preserved; this task did not commit, push or modify publishing records.
## Files changed for this step
| File | Change |
| --- | --- |
| `src/surface-url.js` | Canonical standards-based resolver |
| `src/validation.js` | Reuse resolver; validate optional metadata types |
| `src/local-surfaces.js` | Local frame ownership, resource checks and lifecycle |
| `src/connection.js` | Establish base from final same-origin control document after navigation |
| `src/ui.js` | Descriptor-driven lifecycle controls, state and pane rendering |
| `public/index.html` | Operator explanation of local surfaces |
| `tests/local-surfaces.test.js` | 17 URL, lifecycle, failure, trust and resource tests |
| `tests/connection.test.js` | Final-document URL/navigation regression test |
| `README.md` | Current functionality and deferred scope |
| This report | Architecture, behavior and verification |
| `test-fixtures/evidence/step6.4-*.txt` | Live Museum and SciFi DOM snapshots |
No framework, dependencies, exhibit-specific host branches or schema fields
were added. Existing CSS supplies pane sizing and button styles.
## Resolution and trust
`resolveSurfaceURL(value, exhibitBaseUrl)` uses `new URL()` and returns a
normalized absolute URL. Both discovery and opening use it. Sibling paths,
`./`, parent paths, query-only and fragment-only references resolve against the
supplying exhibit document, never NGN's administrative page. Absolute URLs
(including same-origin ones), protocol-relative URLs, invalid values, control
characters, surrounding whitespace and cross-origin results are rejected.
HTTP(S) and credential-free results are required. The existing static server
continues to enforce mount and filesystem containment for both control and
presentation resources.
Individual invalid entries produce discovery diagnostics without invalidating
targets/state. The exactly-one-primary rule is applied to the surviving set.
Malformed optional metadata cannot reach the UI's string/array operations.
Each open/reload first performs a same-origin HEAD resource check with
`redirect: 'error'`. Missing pages become surface errors; redirects are refused
before the iframe is created. Frame loads additionally check the resulting
origin. Descriptor text is inserted as text, never evaluated. No presentation
frame receives a host transport or session, and the existing postMessage
source/origin checks are unchanged. A test demonstrates that a same-origin
presentation window cannot impersonate the control peer through this transport.
## Rendering, primary handling and lifecycle
NGN uses inline iframe panes, one per opened descriptor ID. Nothing is
automatically opened beyond the existing control frame. A primary descriptor
whose complete normalized URL matches the control document is shown as already
open there, with separate surface actions disabled. Its lifecycle belongs to
the Connection panel. A separate primary URL is offered through the same Open
action as any other presentation view. Queries/fragments remain significant.
States are `closed`, `loading`, `open`, `error`, and `control` (already rendered
by the authoritative frame). Open during loading/open is a no-op. Reload
replaces only the selected presentation document. Close removes it and clears
its diagnostic; Open recreates it. UI cards show labels, primary/non-primary
status, capability availability, lifecycle state and failures.
Disconnect, session reconnect, exhibit replacement and host page departure
release owned frames and abort pending checks. Late load/check completions
cannot recreate abandoned panes. Removed/changed descriptors release their
resources on rediscovery; unchanged frames survive metadata updates. An observer
detects externally removed pane frames and updates their state to closed.
HTTP failures, frame errors, origin failures and a 15-second load timeout stay
local to the affected surface. Reload can retry them. The authoritative control
session and synchronized host state remain intact.
## Automated verification
Final focused command:
```text
node --test tests/local-surfaces.test.js tests/surface-validation.test.js tests/postmessage-interop.test.js tests/connection.test.js
80 passed, 0 failed
```
Coverage includes every requested relative URL form and rejection category;
real Museum descriptors loaded from its actual adapter; duplicate-open, reload,
close, reopen, disconnect/switch cleanup, pending-load cancellation, registry
refresh, distinct primary pages, malformed metadata, timeouts, external removal,
cross-origin loads, source impersonation and real HTTP success/404/redirect cases.
Lifecycle tests use the production manager and ExhibitHost with EventTarget
frames; the existing Step 6.3 suite retains the real production host and exhibit
postMessage bridges in browser-like window realms.
Full `npm test`: **118 passed, 0 failed**, including Museum Gallery and SciFi
connection/synchronization regressions and existing Step 6.3 tests.
Node test workers required execution outside the Windows sandbox after its
initial `spawn EPERM` denial. `python devlog_editor.py --validate` passed.
`git diff --check` passed.
## Live browser verification
Performed in the Codex in-app browser against `npm start` at
`http://127.0.0.1:4173/`, using the ordinary operator UI:
1. Loaded the requested full Museum `control.html` URL: connected,
synchronized, Contract 5.3, three surface descriptors.
2. Primary card reported the existing control frame and disabled duplicate Open.
3. Opened Artifact Display and Information Wall: both reported `open`, rendered
their respective page headings/content and displayed “Attached to Control Room.”
4. Reloaded Artifact Display; closed Information Wall (confirmed `closed`),
then reopened it (confirmed `open`).
5. Switched to SciFi: both Museum cards/panes disappeared; SciFi reported
connected, synchronized, Contract 5.3.
6. Reloaded Museum: both secondary cards began closed and opened cleanly.
7. Explicit Disconnect cleared all frames/catalog; Reconnect rediscovered the
closed surfaces and Artifact Display reopened successfully.
8. Loaded SciFi again after the final UI changes: connected and synchronized;
no Museum surface cards remained.
Saved observations:
- [Museum rendered panes](../../test-fixtures/evidence/step6.4-museum-local.txt)
- [SciFi regression](../../test-fixtures/evidence/step6.4-scifi-regression.txt)
An early batched browser Close action did not change the page; after inspecting
the unchanged state, individual Close/Reopen actions passed, including a repeat
on the final UI. Failure injection is automated coverage, not a claim of live
missing-page or timeout testing.
## Limitations and deferred work
- `open` means the document loaded, not that its application scripts are healthy
or that cross-surface state synchronization has been proven.
- HEAD support is required. HTTP redirects, including same-origin redirects,
are conservatively refused for presentation resources. The local static server
supports HEAD and does not issue redirects.
- These are trusted same-origin exhibit pages under the existing trust model,
not a sandbox for hostile exhibit code. A page's later script-driven navigation
can only be detected at load; resource checks do not certify application code.
- Museum's existing initial shared-state attachment was observed. Its Control
Room counter/footer text did not consistently reflect that attachment. No
fixture behavior was changed; mutation propagation proof remains **Step 6.5**.
- No remote/cast display assignment, device discovery, networking clients,
fullscreen orchestration, SciFi Observation adaptation or synchronization
architecture was introduced.
All Step 6.4 acceptance categories pass. Step 6.5 has not been implemented.
@@ -0,0 +1,945 @@
# Step 6.7A — SciFi Observation Surface Architecture
**Status:** design only. No implementation performed. No source files modified.
**Scope:** adapting SciFi-XZBT Observation to the already-proven Contract 5.3
local presentation-surface model (Steps 6.36.6).
**Audience:** the implementation model executing Step 6.7B.
### Repositories inspected
| Repo | Path | Role |
| --- | --- | --- |
| XZBT-NGN | `G:/.vibe/XZBT-NGN` | Host engine, contract spec, test fixtures |
| SciFi-XZBT | `G:/.vibe/SciFi-XZBT` | **The real exhibit source.** Step 6.7B edits here. |
`test-fixtures/reference-exhibits/scifi/` inside XZBT-NGN is a *copy* of
SciFi-XZBT, kept for NGN's own tests (`test-fixtures/PROVENANCE.md`). Step 6.7B
must change SciFi-XZBT and then resync the fixture. Both working trees carry
uncommitted work; nothing was modified by this task.
---
## 1. Recommendation
**Adopt Candidate A in its narrowest form: one document, one script set, two boot
modes.** SciFi advertises exactly two surfaces. The primary is the existing
`index.html` (unchanged, the full console). The Observation surface is
*the same document* re-served with a query string — `?surface=observation&xi=<instanceId>`
— which Contract 5.3 §31.4 explicitly provides for ("a bare query string and/or
fragment, resolving against the exhibit's own base document, for a single-page
exhibit whose surfaces are views within one already-served document"). A boot-mode
resolver read at the top of `app.js` decides which mode the instance runs in. In
Observation mode the instance constructs no audio graph, no generative engine, no
contract host bridge, and no ambient event scheduler; it renders the existing
`#observation-overlay` and mirrors state from the authoritative console instance
over an exhibit-internal, instance-scoped `BroadcastChannel`.
This is the only candidate that survives contact with the actual code. Roughly
3,230 of `app.js`'s 4,703 lines (lines ~12614494) are the Observation renderer,
and they live inside `app.js`'s single IIFE closure, reading `activeUniverseId`,
`activePresetId`, `isPlaying`, `observationActivity`, `UniverseRegistry`,
`observationEngine`, `alerts` and `audioManager` as free variables.
`observation-engine.js` additionally reads five *console-panel* element IDs
(`toggle-observation-viewport`, `val-observation-viewport`,
`toggle-observation-pillars`, `val-observation-pillars`, and the preset select)
that do not exist outside the console document. Keeping one document means **zero
renderer extraction and zero DOM decoupling**: every element the renderer reaches
for is still present, merely hidden by a body class. A dedicated lightweight page
(Candidate B) would require lifting that entire closure into a shared module —
the single largest and riskiest refactor available in this project — and would
still not fit the distribution, because `tools/package.ps1` inlines exactly one
input document and emits exactly one output file. A second HTML document simply
cannot exist in the standalone single-file build.
The second load-bearing decision: **surface existence is not `view.observation`.**
`view.observation` keeps its current meaning exactly — the console page's own
full-screen overlay — and opening or closing the NGN Observation pane never
touches it. Conflating them would black out the operator's console the moment
they opened the presentation pane, which is precisely the simultaneity failure
Candidate C is rejected for. The Observation surface renders the scene
unconditionally while it is open; that is its whole purpose and it needs no state
flag to say so.
---
## 2. Current SciFi state architecture
### 2.1 Where state actually lives
`app.js` is one `DOMContentLoaded` IIFE. There is no state object. Authority is
distributed across subsystem instances and three closure variables, and
`getContractStateSnapshot()` (app.js:4666) is the one function that composes them
into the contract-visible view.
| Contract state | Authoritative owner | Read path |
| --- | --- | --- |
| `universe.selected` | `let activeUniverseId` (app.js:29) | closure var |
| `preset.selected` | `let activePresetId` (app.js:30) | closure var |
| `transport.playing` | `let isPlaying` (app.js:28) | closure var |
| `transport.muted`, `mix.master` | `AudioManager` | `audioManager.isMuted` / `.getMasterVolume()` |
| `mix.hull.*` | `HullDroneSynth.params` | `hullDrone.params.*` |
| `mix.drive.*` | `WarpCoreSynth.params` | `warpCore.params.*` |
| `mix.environment.*` | `LifeSupportSynth.params` | `lifeSupport.params.*` |
| `mix.telemetry.*` | `TelemetrySynth.params` | `telemetry.params.*` |
| `fnc.enabled`, `fnc.level` | `FuturisticNoiceCancellation` | `fncSystem.enabled` / `.level` |
| `speech.robot-amount` | `XZBTGenerativeExperience` | `generativeExperience.roboticAmount()` |
| `alert.active` | `AlertSynth.activeAlert` | `alerts.activeAlert` |
| `view.observation` | `let observationActive` (app.js:1281) | closure var |
| `view.activity` | `let observationActivity` (app.js:1282) | closure var |
| `view.viewport-frame` | `ObservationEngine.showViewport` | `observationEngine.showViewport` |
| **`showPillars`** *(no target)* | `ObservationEngine.showPillars` | — |
| **warp flight** *(no target)* | `ObservationEngine` internal | — |
| **HUD hold** *(no target)* | console checkbox DOM only | — |
**Canonical vs reflected.** The subsystem/closure values above are canonical. All
DOM is *reflected*: every setter in the adapter's `bindings.setters` writes the
subsystem first and then assigns `slider.value` / `label.textContent`. There is
exactly one genuine exception — **HUD hold** is stored nowhere but
`#toggle-observation-hud.checked`, which is why it is treated as surface-local in
§7 rather than promoted to a target.
**Observation does not own its own mutation path.** `observationEngine.onMutation`
(app.js:259) routes every dock interaction straight into
`contractAdapter.applyMutation(...)` with source `'ui'` — except `togglePillars()`
and `toggleWarpFlight()`, which mutate engine-local fields directly because no
canonical target exists for them (see §11).
**The adapter reads the same authority.** `bindings.getState` is literally
`() => getContractStateSnapshot()`. There is no second state computation anywhere.
### 2.2 Flow diagram (actual)
```text
NGN (postMessage) console UI hotkeys Observation dock
| | | |
| | | | observationEngine.onMutation
v v v v
adapter.handleMessage +------------+---------------+
| |
v v
XZBTControlBus (intercepted) --> contractAdapter.applyMutation / invokeAction
| [ THE one chokepoint ]
v
bindings.setters[id] / invokers[id]
|
+-------------------+-----------+-----------+-------------------+
v v v v
audio subsystems closure vars ObservationEngine reflected DOM
(AudioManager, (activeUniverseId, (showViewport, canvas (sliders, labels,
synths, FNC, activePresetId, scene, bezels) dock button text)
alerts) isPlaying,
observationActive,
observationActivity)
| | |
+---------+---------+-----------------------+
v
_commitChanges() -> getContractStateSnapshot() diff
|
+--> stateRevision++ , state.changed / selection.changed
+--> _emitEvent(...) [ GATED on sessionActive ]
|
v
NGN host session
```
**The gate marked above is critical for 6.7B.** `_emitEvent` begins
`if (!this.sessionActive) return;` (contract-adapter.js:596). With no NGN attached,
**no events are emitted at all.** A mirror built on contract events would therefore
go dead in standalone multi-window use. §6.4 specifies the fix.
### 2.3 Observation entry/exit today
- `enterObservation()` (app.js:4443) — calls
`generativeExperience.prepareExperience()` **(the WebLLM/Kokoro loader)**, sets
`observationActive = true`, adds `.active` to `#observation-overlay`, calls
`refreshObservation()`, starts the HUD/return fade timers, and calls
`scheduleObservationAmbientActivity()`.
- `exitObservation()` (app.js:4460) — stops the engine, the ambient timer, live
instrumentation, spline morphs and the scene loop, then clears the stage markup.
- `refreshObservation()` (app.js:4422) — injects `getObservationSvg(activeUniverseId)`,
starts the scene and instrumentation, and calls `observationEngine.start(activeUniverseId)`.
- Every entry/exit path (button app.js:4502, background click 4508, return pill 4517,
Escape 4574) goes through `applyMutation('view.observation', …)`. Nothing toggles
`observationActive` directly. This is already clean.
### 2.4 Assets, packaging and existing surface concepts
- `index.html` loads one stylesheet and ten scripts in a **fixed order**, all
classic globals. `agents.md` forbids ES modules, dependencies and network access
outside the one bounded `generative-experience.js` exception.
- `tools/package.ps1` walks `index.html` line by line and inlines any
`<script src="…"></script>` or `<link rel="stylesheet" href="…">` that matches
its exact regex, emitting **one** file, `dist/SciFiAmbientDisplay_V<commit>.html`.
One input document, one output document. There is no other build step.
- **No existing surface concept.** `describe()` (contract-adapter.js:854) returns
`exhibit / contract / registryRevision / stateRevision / capabilities / targets`
and no `surfaces` field. SciFi is currently a conformant Contract 5.3 exhibit in
§31.3 form 1 ("absent").
- The nearest adjacent concept is the **TV PRESENTATION** card (16:9 aspect lock,
render density). It is console-local presentation tuning, not a surface, and
Step 6.7 should not disturb it.
- **No Step 6.7 planning notes exist** in either repo. The only forward references
are `STEP5-MVP-COMPLETION-REPORT.md:234` (the step list) and
`docs/architecture/XZBT-Multi-Surface-Model-Step6.1.md:393`, which names §7.2/§8
as "the reusable template Phase 6.7 adapts" — that template is the attachment
sequence this design follows.
---
## 3. Candidate comparison
| | **A — same document, surface mode** | B — dedicated lightweight page | C — reuse control page/overlay |
| --- | --- | --- | --- |
| Architectural cleanliness | Good. One app, one code path, mode is a boot input. | Cleanest *in theory*; unreachable in practice. | Poor. Conflates host UI with exhibit presentation. |
| Renderer refactoring | **None.** All ~3,230 renderer lines and all DOM stay put. | Extract the renderer from `app.js`'s closure; decouple 5 console-panel element reads in `observation-engine.js`. Very large. | None. |
| Standalone behavior | Untouched. `index.html` with no query is byte-for-byte today's app. | Untouched, but the new page has no place in the single-file build. | Untouched. |
| Duplicate initialization | Controlled: mode guard skips audio, AI, adapter bridge, visualizer, hotkeys, timers. | Structurally impossible to duplicate. | N/A. |
| State authority | Single. Presentation instance never calls `applyMutation` locally. | Single. | Single, but only one view can exist. |
| Sync complexity | One instance-scoped BroadcastChannel; Museum's proven shape. | Same. | None. |
| Contract purity | Exactly the §31.4 query-string form the spec provides for. | Fine. | Fine, but defeats §31.1's "independently viewable". |
| NGN genericity | No NGN change. | No NGN change. | Would tempt NGN into exhibit-specific pane handling. |
| Future cast suitability | Good — the surface is already a standalone URL with its own viewport. | Best (smallest payload), marginally. | Bad. |
| Packaging | `package.ps1` unchanged; two new inlined scripts. | **Breaks.** Second document cannot be packaged. | Unchanged. |
| Implementation risk | Moderate, concentrated in `app.js` mode branching. | High. | Low, but wrong. |
### Rejections
- **B — Dedicated lightweight Observation surface.** Rejected on two independent
grounds, either sufficient. (i) *Packaging:* `tools/package.ps1` produces a single
self-contained document; a second HTML page has nowhere to go in the offline
deliverable, so SciFi would fork into two maintained applications — explicitly
forbidden by the brief. (ii) *Cost and risk:* it requires lifting ~3,230 lines out
of a shared closure that `agents.md` marks "surgical, scoped edits — do not
rewrite", plus decoupling `observation-engine.js` from five console-panel element
IDs. The payoff is a lighter payload; but under Candidate A the presentation
instance already parses the same bytes the browser has cached and *runs* almost
none of the heavy subsystems, so the real saving is parse time, not runtime. Not
worth the refactor. Revisit only if remote casting later demands a minimal payload.
- **C — Reuse the existing page / overlay.** Rejected: it makes simultaneous
control and observation impossible, which is the entire point of the multi-surface
model (§31.1 "independently viewable"); NGN would end up manipulating exhibit DOM,
breaking the generic boundary Step 6.4 established; and it has no path to casting.
- **D — Better architecture found in the repository.** None found. The repository
does, however, supply two refinements adopted into A: the §31.4 query-string
surface form, and Museum Gallery's attach/snapshot/mutate/detach bus — improved
here with an instance-scoped channel name (§6.2).
---
## 4. Surface catalog
Two surfaces. No more are justified: the console is one coherent operator view,
and Observation is the one thing an audience is meant to look at. Adding
per-universe or per-panel surfaces now would be speculative.
```js
// js/surface-mode.js — instanceId is the live per-document id (see §6.2)
function SURFACES(instanceId) {
return [
{
id: 'surface.console',
label: 'Main Console',
kind: 'surface',
primary: true,
url: 'index.html',
role: 'control',
category: 'console',
description: 'The full SciFi-XZBT operator console.'
},
{
id: 'surface.observation',
label: 'Observation',
kind: 'surface',
primary: false,
url: '?surface=observation&xi=' + encodeURIComponent(instanceId),
role: 'ambient',
category: 'observation',
aspectRatio: '16:9',
requires: ['observation'],
description: 'Full-screen procedural viewscreen mirroring the console.'
}
];
}
```
Schema notes, all verified against §31.2 and `src/validation.js`:
- `id` uses the canonical target-ID grammar (§8.1) and matches Museum's
`surface.control` / `surface.info-wall` convention.
- `kind: 'surface'` is the required constant. Exactly one `primary: true`.
- Only documented optional fields are used: `description`, `role`, `aspectRatio`,
`category`, `requires`. **No invented fields.** No field names a transport,
endpoint or device class (§31.9).
- `requires: ['observation']` reuses the adapter's already-declared `observation`
capability (contract-adapter.js:52).
### Why `url: 'index.html'` for the primary
`src/local-surfaces.js:35` marks a descriptor as the already-open control pane
with **full URL equality** against `host.exhibitBaseUrl`, and
`src/connection.js` sets that base from `frame.contentWindow.location.href` after
load. Connecting NGN to `…/scifi/index.html` — the URL already used by
`README.md:54` and the Step 6.6 procedure — makes `index.html` resolve to exactly
the base, so the primary reuses the existing session frame and is never opened a
second time. See risk **R1** for the trailing-slash case.
### Why the Observation `url` is a bare query
§31.4 sanctions it for single-page exhibits, `resolveSurfaceURL` accepts it
(relative, same-origin, no scheme), and `server/serve.js` routes on `url.pathname`
only, so the `HEAD` resource check in `checkSurfaceResource` returns 200. No new
file is served and `package.ps1` never sees a second document.
---
## 5. Authority and synchronization
### 5.1 Ownership rule
> The instance whose resolved mode is `console` is the sole authority. It owns
> every subsystem, the one contract session, and the one mutation chokepoint. An
> instance whose mode is `observation` owns **nothing**: it holds a read-only
> mirror and may only *request* mutations.
The presentation instance never calls `contractAdapter.applyMutation`,
`invokeAction`, or any `bindings.setter`. It never constructs a contract session:
it does not install the window message bridge, so a stray `hello` cannot reach it,
and NGN never offers one — `LocalSurfaces` attaches no transport to surface frames
(`src/local-surfaces.js`, and `tests/local-surfaces.test.js:232` asserts a
presentation window cannot impersonate an authoritative peer).
### 5.2 Mechanism: instance-scoped BroadcastChannel
Chosen mechanism: `BroadcastChannel`, named
`xzbt-scifi-surface-v1:<instanceId>`, with the console document as owner —
Museum Gallery's proven shape (`surface-bus.js`), with one deliberate improvement.
Evaluated and rejected:
- **Explicit parent/child `postMessage`.** *Structurally impossible here.* Under
NGN the console document and the Observation iframe are **siblings** inside the
NGN page, not parent and child. Neither holds a window handle to the other.
This alone decides the mechanism.
- **`storage` events / same-origin storage.** No request/response, so late join
needs a polled or mirrored snapshot key; fires only in *other* documents;
serializes on every change. Strictly worse.
- **`SharedWorker`.** Extra lifecycle and an unsupported-context risk, for no
benefit over BroadcastChannel.
- **Extending `XZBTControlBus`.** It is an in-document registry with no transport;
extending it means writing one of the above anyway. Keep it as-is.
**The improvement over Museum: the channel name carries an instance id.** Museum
uses one fixed channel name, which means two independent Museum tabs on one origin
would cross-talk. For SciFi that matters more: two console tabs is a normal thing
to do. The console mints `instanceId` once per document load, publishes it inside
the Observation surface URL (which `describe()` produces at call time, so it is
always current), and the presentation instance reads it from its own query string.
A surface with an unknown or stale id finds no owner and lands in the waiting
state rather than attaching to the wrong console.
### 5.3 Message shapes (exhibit-internal; never seen by a host)
```
surface -> owner : { type:'attach', requestId, participantId }
owner -> surface : { type:'attach.snapshot', inReplyTo, values, stateRevision,
registryRevision, presentation:{ tickerText } }
owner -> all : { type:'state', target, value, stateRevision }
owner -> all : { type:'action', target, args }
owner -> all : { type:'presentation', kind:'ticker'|'obs-activity', … }
surface -> owner : { type:'mutate', kind:'set'|'invoke', target, value|args }
surface -> owner : { type:'detach', participantId }
```
This carries no XZBT envelope, no `xzbt` field, no `sessionId`, and is never
observed by NGN — §31.7's explicit allowance. Participant bookkeeping is a
`Set` of `participantId`s, not a counter, so duplicate attach or late detach
cannot ratchet the count (Museum's lesson; see its participant-lifecycle tests).
### 5.4 The event-gate correction (mandatory)
Because `_emitEvent` early-returns unless `sessionActive`, the mirror **must not**
be fed from contract events. Add one exhibit-internal hook to the adapter,
independent of session state:
```js
// contract-adapter.js, inside _commitChanges(), after the event loop:
if (this.onLocalChange) {
for (const target of changes) {
this.onLocalChange(target.id, after[target.id], this.stateRevision);
}
}
// and in _invokeAction(), after _commitChanges:
if (this.onLocalAction) this.onLocalAction(canonicalId, sanitizedArgs);
```
Contract event semantics are untouched — a host still only sees events inside a
session. The mirror gets a session-independent feed, so Observation works with or
without NGN attached.
### 5.5 Guarantees
- **One authority:** enforced structurally — the presentation branch never
constructs the mutation path's callers.
- **Late join:** `attach` → owner replies with the live
`contractAdapter.getContractState()` plus transient presentation extras.
- **Reload:** a reload is a fresh `attach` with a fresh `participantId`; identical
path to first join.
- **Prompt propagation:** `onLocalChange` fires inside `_commitChanges`, i.e. in
the same turn as the mutation.
- **Surface interactions:** routed as `mutate` and executed by the owner through
`contractAdapter.applyMutation(..., 'ui')` — the same chokepoint NGN's `set`
uses, satisfying §31.7's mutation/revision/source/event requirement.
- **No NGN-specific logic:** the bus is unaware NGN exists.
---
## 6. Audio / AI / procedural subsystem ownership
Audio is already safe by construction: `AudioManager`'s constructor
(`audio.js`) sets `this.ctx = null` and creates nothing; the `AudioContext` and
every node appear only in `init()`, reached only via `resume()`. So a presentation
instance that never engages transport never creates an audio graph. The dangerous
paths are the ones that *call* `resume()` or `prepareExperience()`.
| Subsystem | Authoritative console | Observation surface | Note |
| --- | --- | --- | --- |
| `AudioManager` / `AudioContext` | **Yes** | Constructed, **never `init()`/`resume()`** | Needed only to satisfy `ObservationEngine`'s constructor arity. |
| Hull / Warp / LifeSupport / Telemetry / Alert / Whataverse / Expanded / EngineTransition synths | **Yes** | Constructed, silent | Same reason; they create nodes only on play. |
| `FuturisticNoiceCancellation` | **Yes** | Constructed, inert | Do not call `setEnabled`/`setLevel` locally. |
| `XZBTGenerativeExperience` (WebLLM + Kokoro) | **Yes** | **Not constructed. Not bound. Never prepared.** | `enterObservation()` calls `prepareExperience()`**this call must be skipped in presentation mode**, or every opened pane downloads a 1.7B model. Highest-value guard in this design. |
| `XZBTContractAdapter` + window bridge | **Yes — the one session** | **Not constructed** | Guarantees no second contract session. |
| `XZBTControlBus` | **Yes** | Not constructed | |
| `StarshipVisualizer` (spectrum, warp core) | **Yes** | Not constructed | Its canvases are console-panel only. |
| `CoreAnimations` | **Yes** | Not constructed | |
| Sleep timer | **Yes** | Not constructed | |
| Hotkey handler (`window keydown`) | **Yes** | **Not installed** | A keystroke on the pane must not mutate state; see §7. |
| Ambient activity scheduler (`scheduleObservationAmbientActivity`) | **Yes — authority only** | **Disabled**; renders broadcast events | Prevents duplicate random event generation. |
| `triggerObservationActivity` | Decides + broadcasts | Renders on receipt | |
| AI announcement / ticker text | **Yes** (`onGenerated`) | Renders relayed text | Relayed as `presentation/ticker`; announcement text is not contract state. |
| `ObservationEngine` (canvas, bezels, waveform) | Yes (when overlay active) | **Yes — renderer only** | `am.analyser` guards already exist (`observation-engine.js:2262, 3097`). |
| Observation SVG scene, spline morphs, scene entity loop | Yes (when overlay active) | **Yes — renderer only** | Deterministic from universe + preset + activity. |
| Live instrumentation digit churn (`observationInstrumentTick`) | Yes | **Yes — local, deliberately** | See below. |
| `ObservationBezels` | Yes | Yes | Pure SVG generation. |
| Web3D / external visual deps | None exist | None | SciFi is canvas + SVG only. |
### Two judgment calls, stated explicitly
**1. Instrumentation digit churn stays local.** `observationInstrumentTick` mutates
cosmetic numerals in the HUD text. It is high-frequency, carries no narrative or
contract meaning, and mirroring it would need a continuous high-rate channel for
nothing. Two screens showing different filler digits is invisible. This is a
deliberate, bounded divergence — and it is the *only* one.
**2. Transient activity events are mirrored, not regenerated.** By contrast,
`triggerObservationActivity` spawns visible narrative beats (contacts, expanding
rings, text cards). Regenerating them independently would give two screens
different events and would violate the brief's "no duplicate random event
generation". The authority decides; the surface renders.
### The audience-scheduler correction (mandatory)
`triggerObservationActivity` begins `if (!observationActive …) return;` and
`scheduleObservationAmbientActivity` refuses to schedule unless `observationActive`.
So with the console in normal mode and only the NGN Observation pane open,
**nothing would ever be generated** — the surface would render a static scene.
6.7B must decouple the scheduler from local overlay visibility:
```js
const observationAudienceActive = () => observationActive || surfaceOwner.attachedCount() > 0;
```
Use that predicate for *scheduling and deciding* activity; keep `observationActive`
for *local rendering* only. The activity decision is then broadcast, and the
console renders it locally only when its own overlay is up.
### Audio-reactive fidelity (accepted limitation)
With no audio graph, `am.analyser` is null on the surface, so the waveform sill
and the audio-reactive modulation read zero. `ObservationEngine` already guards
this and degrades to a flat trace; the scene itself is procedural and unaffected.
Mirroring a scalar audio level is a reasonable future refinement and is **out of
scope for 6.7**.
---
## 7. Observation interaction policy
**Policy: minimally interactive — every retained control is a mutation request to
the authority; nothing is applied locally.**
Strict read-only would be a regression (the dock already exists and is genuinely
useful on a second screen). Fully interactive would mean installing hotkeys and
local setters on a non-authoritative document. The middle is both correct and
already half-built: four of the six dock controls *already* route through
`observationEngine.onMutation`.
| Control (`index.html`) | Decision | Mechanism |
| --- | --- | --- |
| `#obs-btn-warp` (WARP) | **Route** | Needs a new target — `view.warp-flight`. Today `toggleWarpFlight()` mutates engine-local state and would diverge. |
| `#obs-btn-frame` (VIEWPORT) | **Route** | Existing `view.viewport-frame`; already routed. |
| `#obs-btn-pillars` (PILLARS) | **Route** | Needs a new target — `view.pillars`. Today `togglePillars()` is engine-local and would diverge. |
| `#obs-btn-alert` (RED ALERT) | **Route** | Existing `alert.active`; already routed. |
| `#obs-select-preset` (PRESET) | **Route** | Existing `preset.selected`; already routed. |
| `#obs-btn-exit` (RETURN ✕) | **Remove** on the surface | Hidden by CSS. Closing a pane is NGN's job; posting `view.observation=false` from the pane would toggle the *console's* overlay — a confusing cross-surface side effect. |
| Background click-to-exit (app.js:4508) | **Remove** on the surface | Same reason; also makes the pane fragile to stray clicks. |
| `#observation-return-pill` | **Remove** on the surface | Same. |
| HUD HOLD (`#toggle-observation-hud`) | **Surface-local** | A per-screen fade preference, stored only in the checkbox. §31.7 explicitly leaves purely presentational surface-local interaction outside the contract. |
| ACTIVITY slider (console panel) | Console-only | Existing `view.activity`; the surface follows it. |
| Hotkeys | **Not installed** on the surface | Would be a local mutation path. |
Removal is by CSS on the body class, so `observation-engine.js` needs no change —
it may keep binding listeners to elements the user can never reach.
---
## 8. Observation lifecycle semantics
Four concepts, deliberately kept distinct:
| Concept | Owner | Meaning | Changed by |
| --- | --- | --- | --- |
| **Surface lifecycle** | NGN (`LocalSurfaces`) | Whether an Observation pane exists and is loaded | Operator clicking Open/Close/Reload in NGN |
| **`view.observation`** | SciFi console instance | Whether the **console page's own** full-screen overlay is up | WATCH EXPERIENCE, background click, Escape, contract `set` |
| **Fullscreen state** | Browser | Whether a document occupies the screen | User/OS; SciFi does not drive it |
| **Local overlay CSS state** | Each document | `.active` on `#observation-overlay` | Derived from the two above, per document |
### The explicit answer
> **Opening the secondary surface does NOT imply `view.observation = true`.**
> "A surface exists" and "Observation mode is active" are separate facts.
Rationale: `view.observation` is declared `restorable: false` and is scoped to the
console's own presentation. If opening the pane set it true, the operator's console
would black out into its overlay the instant they opened the pane — destroying
simultaneous control and observation, the whole point of §31.1. Conversely,
closing the pane must not set it false, or an operator using the console overlay
would lose it when tidying up NGN panes. Contract 5.3 is additive; no existing
target may be reinterpreted (`AGENTS.md`), and this keeps `view.observation`'s
meaning exactly as it is today.
Consequences, all of which 6.7B must honor:
- The Observation **surface renders the scene whenever it is open**, with no state
flag gating it. It is an Observation surface; that is what it is for.
- **WATCH EXPERIENCE is unchanged** — same button, same target, same local overlay.
- A host `set view.observation true` still raises the *console's* overlay and is
reflected on the surface only as a state readout. It never opens or closes a pane;
NGN owns pane lifecycle and Contract 5.3 gives an exhibit no way to ask for one.
- Closing the pane detaches cleanly: `window.__xzbtSurfaceDispose` (called
synchronously by `local-surfaces.js` before frame removal) plus a `beforeunload`
fallback, both idempotent. The owner removes the participant; **no state mutates.**
- When the last participant detaches and the console overlay is down,
`observationAudienceActive()` goes false and the ambient scheduler stops — the
symmetric counterpart of §6's correction.
---
## 9. Standalone behavior
Unconditionally preserved, and mostly by construction.
- **`index.html` opened with no query string is byte-for-byte today's application.**
The mode resolver returns `console` for the absence of `?surface=`, and the
console path is the existing code path. No behavior is gated on NGN.
- **Host attachment is not part of startup.** It is not today (the adapter only
installs a passive `message` listener) and must not become so. No `hello` is
ever initiated by SciFi.
- **In-page Observation is retained exactly.** WATCH EXPERIENCE, Escape,
background click, the dock, and the hotkeys all keep working with no NGN, no
surface, and no bus participant.
- **The renderer is shared, not duplicated.** Both modes run the same
`app.js`/`observation-engine.js` code; only the boot mode differs. There is no
second implementation to drift.
- **`?surface=observation` is directly usable without NGN** (§31.8's SHOULD): open
it in a second browser window over `http(s)` and it attaches to the console tab
on the same origin. With no console open it shows a waiting state and never
invents its own authority — Museum's proven behavior.
- **Single-file build:** opening `SciFiAmbientDisplay_V<commit>.html` normally is
unchanged. Under `file://`, `BroadcastChannel` is scoped to an opaque origin, so
the two-window pairing is **not** promised there; the single-file build's
Observation remains the in-page overlay. That is the correct guarantee, and it is
exactly what §31.8 requires (primary unconditional, non-primary best-effort).
---
## 10. Packaging approach
**No second application, no second document, no build change.**
| Concern | Impact |
| --- | --- |
| Source files | +2 small JS files (`js/surface-mode.js`, `js/surface-bus.js`); edits to `index.html`, `js/app.js`, `js/contract-adapter.js`, `css/style.css`. |
| Generated HTML | Still one file, `dist/SciFiAmbientDisplay_V<commit>.html`. |
| Optional secondary page | **None. Deliberately.** The Observation surface is a query-string view of the same document (§31.4). |
| Shared scripts | 100% shared — the surface *is* the same script set. Divergence is structurally impossible. |
| Build process | `tools/package.ps1` unchanged. The two new tags are inlined automatically **only if written in the exact form** `<script src="js/surface-mode.js"></script>` — the regex is whitespace- and quote-sensitive and fails silently otherwise (`agents.md`, "Adding a new JS file"). |
| Offline behavior | Unchanged. Nothing new touches the network. `BroadcastChannel` is a browser primitive with no dependency. |
| Future embedded offline package | Unaffected — still one artifact. |
| Resource duplication | The surface re-parses the same cached bytes and constructs the inert subsystem shells; it downloads nothing new and runs no second engine. |
Script order in `index.html` — insert **after `control-bus.js`, before
`generative-experience.js`**, so the adapter and `app.js` can see both globals:
```
audio.js → config.js → core-animations.js → visualizer.js →
observation-bezels.js → observation-engine.js → control-bus.js →
surface-mode.js → surface-bus.js →
generative-experience.js → contract-adapter.js → app.js
```
---
## 11. Contract adapter changes
All in `js/contract-adapter.js`. Additive only. No change to the handshake, the
envelope, message types, or generic semantics.
**1. Surface catalog.** Accept `options.surfaces` (an array) and
`options.instanceId`; store them. Emit `surfaces` from `describe()` **only when
non-empty**, so absence stays §31.3 form 1:
```js
describe() {
const description = { exhibit: {...}, contract: {...}, registryRevision, stateRevision,
capabilities: [...], targets: [...] };
if (this.surfaces && this.surfaces.length) description.surfaces = this.surfaces;
return description;
}
```
The array is a plain static declaration with exactly one `primary: true`.
Host-side §31.3 validation is NGN's job, not the exhibit's; do not reimplement it.
**2. Two missing absolute state targets.** Required for deterministic presentation
sync — without them, PILLARS and WARP diverge between console and surface, and a
host cannot read or restore them at all:
```js
reg({ id: 'view.pillars', legacyId: 'observation-pillars',
label: 'Window Pillars / Mullions', kind: 'state', valueType: 'boolean',
readable: true, writable: true, restorable: true,
category: 'observation', requires: ['observation'] });
reg({ id: 'view.warp-flight',
label: 'Warp Flight Mode', kind: 'state', valueType: 'boolean',
readable: true, writable: true, restorable: true,
category: 'observation', requires: ['observation'] });
```
Permitted by §28.7 (additive targets). Wire matching entries in
`bindings.setters` (→ `observationEngine.setPillars` / `setWarpFlight`) and in
`getContractStateSnapshot()` (→ `observationEngine.showPillars` and the engine's
warp-flight field — confirm its exact name when implementing). `registryRevision`
stays `1`; this is a new build, not a runtime registry change, so no
`registry.changed` is emitted.
**3. Session-independent local hooks.** Add `onLocalChange` / `onLocalAction` as
described in §5.4. This is the only structural addition and it changes no
contract-visible behavior.
**4. Identity.** `app.js:126` passes `version: '5.2.0'`; bump to `'5.3.0'` to
match the adapter's declared `contractMinor = 3` and this build's surface support.
Advisory metadata only.
**No second command protocol.** Surface-originated interactions reuse `set` /
`invoke` semantics through `applyMutation` / `invokeAction`. **No capability
change** — `observation` is already declared `ready`.
---
## 12. NGN changes
### None.
Verified against the current source rather than assumed:
- **Query-string surface URLs already work.** `src/surface-url.js` accepts a
relative reference with a query and rejects only schemes, protocol-relative and
cross-origin values. `tests/local-surfaces.test.js:153` is literally
*"a separate primary page and query/fragment views are rendered from generic
descriptors"* — the case SciFi needs is already covered.
- **The resource check passes.** `server/serve.js` routes on `url.pathname` and
ignores the query, so `HEAD index.html?surface=observation` returns 200 and
`checkSurfaceResource` is satisfied.
- **Primary reuse already works.** `src/local-surfaces.js:35` compares full URLs
and marks the matching primary as the control pane, so it is never re-opened.
`tests/local-surfaces.test.js:54` covers it with Museum's real descriptors.
- **Lifecycle already works.** `release()` calls `__xzbtSurfaceDispose` synchronously
before removing a frame (`src/local-surfaces.js:51`); SciFi implements the hook.
- **Catalog validation already works.** `host.js:154` runs `validateSurfaceCatalog`
against §31.3 ordering, exercised by `tests/museum-gallery.test.js:172253`.
If a genuine NGN gap emerges during 6.7B, it must be fixed **generically** and
justified against Museum Gallery; a SciFi-specific branch is not an acceptable
outcome (`AGENTS.md`: "Do not infer XZBT-NGN behavior from SciFi-XZBT source code").
---
## 13. File-by-file implementation plan
### A. SciFi-XZBT — `G:/.vibe/SciFi-XZBT` (the real exhibit)
| # | File | Why it changes | Responsibility added | Must not change |
| --- | --- | --- | --- | --- |
| A1 | `js/surface-mode.js` **(new, ~60 lines)** | A pure, testable seam for mode resolution and the catalog | `XZBTSurfaceMode.resolve(locationLike) → { mode, instanceId }`; `XZBTSurfaceMode.newInstanceId()`; `XZBTSurfaceMode.SURFACES(instanceId)`; `XZBTSurfaceMode.channelName(instanceId)` | No DOM, no globals beyond `window.XZBTSurfaceMode`, no imports. Unknown `?surface=` values resolve to `console`. |
| A2 | `js/surface-bus.js` **(new, ~180 lines)** | Exhibit-internal state mirror | `createOwner(adapter, { channelName, onParticipantsChanged })` and `attach({ channelName, timeoutMs, onSnapshot, onChange, onAction, onPresentation, onTimeout })`, plus idempotent `detach()` and `mutate(kind, target, valueOrArgs)` | Carries no XZBT envelope. `Set`-based participant bookkeeping (not a counter). Owner routes every `mutate` through `adapter.applyMutation/invokeAction` with source `'ui'` — never a second computation of state. |
| A3 | `index.html` | Load the two new files | Two `<script src>` tags in the exact `package.ps1` form, positioned per §10 | **No DOM changes.** The overlay markup, dock and all IDs stay exactly as they are — the design depends on them existing in both modes. |
| A4 | `js/contract-adapter.js` | Advertise surfaces; close the two target gaps; expose session-independent hooks | §11 items 14 | Handshake, envelope, `xzbt` advisory handling, inbound gating, error codes, `_emitEvent`'s session gate, existing target IDs and semantics. |
| A5 | `js/app.js` | Mode branch, owner/mirror wiring, audience scheduler | (a) resolve mode at the top; add `body.surface-observation` in presentation mode. (b) **Presentation branch skips:** `XZBTGenerativeExperience` construction/bind, `StarshipVisualizer`, `CoreAnimations`, `XZBTControlBus`, `XZBTContractAdapter`, the `keydown` handler, the sleep timer, and all console-panel listeners. (c) **`enterObservation()` must not call `prepareExperience()` in presentation mode.** (d) Presentation enters the scene on snapshot and re-runs `refreshObservation()` on universe/preset/activity change. (e) Replace `observationActive` with `observationAudienceActive()` for **scheduling/deciding** activity only. (f) Broadcast activity decisions and ticker text; presentation renders them and runs no scheduler. (g) Presentation dock routes through `bus.mutate`. (h) `window.__xzbtSurfaceDispose = () => link.detach()` + `beforeunload`. (i) Console mode constructs the bus owner and feeds it from `onLocalChange`/`onLocalAction`. | The console code path's behavior. `getContractStateSnapshot()`'s shape (extend with the two new keys only). The single mutation chokepoint. `agents.md`: surgical scoped edits, no reformatting. |
| A6 | `css/style.css` | Present the surface mode | `body.surface-observation`: hide `header/main/footer`, show the overlay full-bleed, hide `#obs-btn-exit` and `#observation-return-pill` | Existing theme, overlay and CRT rules. Additive block only. |
| A7 | `agents.md` | Keep the agent contract honest | Document the one-document/two-mode rule, the two new files, the bus, and the "never construct audio/AI in presentation mode" invariant | The hard constraints; they are all still satisfied. |
| A8 | `README.md` | User-facing | One short paragraph on the Observation surface | — |
**Deliberately unchanged:** `js/observation-engine.js`, `js/observation-bezels.js`,
`js/audio.js`, `js/config.js`, `js/visualizer.js`, `js/core-animations.js`,
`js/generative-experience.js`, `js/control-bus.js`, `tools/package.ps1`, `dist/**`
(regenerate, never edit).
### B. XZBT-NGN — `G:/.vibe/XZBT-NGN`
| # | File | Why it changes | Responsibility added | Must not change |
| --- | --- | --- | --- | --- |
| B1 | `test-fixtures/reference-exhibits/scifi/**` | Fixture must match the new exhibit | Mechanical resync of the changed files + the two new ones | Nothing hand-edited; keep it a faithful copy. |
| B2 | `test-fixtures/PROVENANCE.md` | Provenance discipline | Note the resync, its source commit, and that no fixture-local corrections were added | The existing correction record. |
| B3 | `tests/scifi-surfaces.test.js` **(new)** | Cover the new seams | §14 tests, in the existing `node:test` + `vm.createContext` + real `BroadcastChannel` style (`tests/museum-gallery.test.js`) | — |
| B4 | `tests/local-surfaces.test.js` | Prove the real SciFi descriptors render correctly | One case using SciFi's actual catalog, mirroring the Museum cases at :54 and :153 | Existing cases. |
| B5 | `docs/reference/XZBT-NGN-Step6.7-SciFi-Surface-Adaptation.md` **(new)** | Verification writeup | Evidence for 6.7B, matching the Step 6.6 document's shape | — |
| B6 | `README.md` | Operator accuracy | Note that NGN should be pointed at the explicit `…/scifi/index.html` URL (risk R1) | — |
**`src/**` — no changes.** If a diff appears there in 6.7B, it is a design
deviation and needs review before merge.
---
## 14. Automated test plan for Step 6.7B
`node --test`, matching the existing style: `vm.createContext` per simulated
document, Node's real `BroadcastChannel`, `plain()` for cross-realm comparison,
and every channel closed in teardown. `app.js` is far too DOM-bound for `vm`;
that is why A1/A2 are deliberately small, pure and separately loadable, and why
the app-level invariants below are asserted as **source-structure tests** — the
same technique as Museum's "Exactly one Exhibit State Core exists".
**Catalog and contract (`tests/scifi-surfaces.test.js`)**
1. `describe()` includes a `surfaces` array that passes `validateSurfaceCatalog`
against a representative base URL.
2. Exactly one entry has `primary: true`.
3. Every entry carries only §31.2 fields; no invented fields; `kind === 'surface'`.
4. Constructing the adapter with no `surfaces` option omits the field entirely
(§31.3 form 1 preserved — the Museum analogue at `museum-gallery.test.js:148`).
5. `resolveSurfaceURL('?surface=observation&xi=…', base)` resolves same-origin to
`base?…`; absolute/protocol-relative variants are rejected.
6. The primary's `url` resolves to exactly a base of `…/scifi/index.html`, so
`LocalSurfaces` marks it `control` and opens no second frame (extend
`tests/local-surfaces.test.js`).
7. `view.pillars` and `view.warp-flight` exist, are `state`/`boolean`, readable,
writable, and appear in the snapshot key set.
**Mode resolution (pure)**
8. No query → `console`. `?surface=observation``observation`.
`?surface=bogus``console`. Query order and extra params are tolerated.
9. `xi` round-trips through `SURFACES()``resolve()` and `channelName()` is
instance-scoped (two ids yield different names).
**Bus / synchronization**
10. **Late join:** mutate first, then attach — the snapshot carries current
universe, preset and view state, plus the current `stateRevision`.
11. **Propagation:** an authority mutation reaches an attached surface as one
`state`/`selection` message with the post-mutation value.
12. **Mutation routing:** `link.mutate('set','view.pillars',true)` results in
exactly one `adapter.applyMutation` call with source `'ui'`, and the value
converges on the authority and on a *second* attached surface.
13. **No second authority:** a surface-side `mutate` performs no local state write;
with no owner present it is a no-op and the surface enters the waiting state
(the analogue of `museum-gallery.test.js:469`).
14. **One event stream:** `stateRevision` advances monotonically regardless of
which surface originated the interaction; two attached surfaces never disagree.
15. **Reload:** re-attaching with a fresh `participantId` yields the current
snapshot; repeated reloads leave the participant count stable (no ratchet).
16. **Detach:** idempotent; never mutates state; count decrements exactly once;
duplicate/late `detach` cannot underflow.
17. **Session independence:** with `sessionActive === false`, `onLocalChange` still
fires on `_commitChanges` — the correction in §5.4 — while `_emitEvent` still
emits nothing.
**Duplicate-subsystem prevention (construction spies + source structure)**
18. *Spy test:* load `surface-bus.js` in a `vm` context with stub globals and
assert the surface side never touches `AudioContext`, `fetch` or `import`
a counting stub for `globalThis.AudioContext` must record zero constructions.
19. *Source-structure test:* assert `js/app.js` contains no call to
`prepareExperience()` that is not inside the console-mode branch — pin it by
asserting the presentation branch is entered before the
`new XZBTGenerativeExperience` / `new XZBTContractAdapter` /
`new StarshipVisualizer` construction sites, in the manner of Museum's
"structurally incapable" assertion. Prefer a resilient marker (e.g. a named
`bootConsole()` function containing those constructions) over brittle regex —
**A5 should be implemented so this test is easy to write.**
20. *Timer test:* with only a presentation instance simulated, no ambient-activity
timer is scheduled.
21. **One contract session:** the presentation branch never installs a `message`
listener; a simulated `hello` posted at it produces no `hello.result`.
**Regression**
22. `tests/museum-gallery.test.js`, `tests/local-surfaces.test.js`,
`tests/surface-validation.test.js`, `tests/host.test.js`,
`tests/connection.test.js`, `tests/postmessage-interop.test.js`,
`tests/haunted-house.test.js` all remain green (`npm test`).
23. `tests/postmessage-interop.test.js:118` still negotiates a SciFi session
against the resynced fixture.
---
## 15. Live acceptance procedure
Serve with `npm start` (`http://127.0.0.1:4173`).
1. Open NGN at `http://127.0.0.1:4173/` and connect to
**`http://127.0.0.1:4173/test-fixtures/reference-exhibits/scifi/index.html`**
(the explicit filename — see R1).
2. Confirm `connected`, Contract major 5 / minor 3, target catalog populated.
3. In the Surfaces panel: exactly two entries. `surface.console` is badged
**Primary** and offers **no Open button** (it is the control pane).
`surface.observation` is non-primary with `URL: ?surface=observation&xi=…`.
4. Open `surface.observation`. It loads in its own pane and renders the current
universe and preset within ~1s.
5. Confirm the pane shows **no RETURN ✕ and no return pill**, and that clicking
its background does nothing.
6. Confirm the console pane is **still the full console**`view.observation`
remains `false` and the console did not black out. *(This is the §8 invariant.)*
7. From NGN, `set universe.selected` to another universe. Both the console and the
Observation pane change scene. Repeat for `preset.selected`, `alert.active`,
`view.viewport-frame`, `view.activity`.
8. On the Observation pane, click **PILLARS** and **WARP**. The value changes on
the pane *and* on the console's own controls, and NGN's state readout advances
`stateRevision` — proving the mutation went through the authority, not locally.
9. Click **RED ALERT** and change **PRESET** on the pane; confirm the same
convergence across console, pane and NGN.
10. Reload the Observation pane from NGN. It returns to the *current* state, not a
default one.
11. Close the pane, then reopen it. Same result; the participant count in the
console does not ratchet.
12. On the console, press **WATCH EXPERIENCE**. The console overlay comes up,
`view.observation` becomes `true`, and the Observation pane is **unaffected**
(it was already rendering).
13. Exit the console overlay. `view.observation` returns to `false`; the pane is
still rendering. Repeat once.
14. **Duplication checks, with the pane open and the console engaged (audio on):**
- DevTools → the pane's frame → console shows no WebLLM/Kokoro network
activity, and `window.generativeExperience` is `undefined`.
- The pane's frame has no `AudioContext` (audio comes only from the console);
mute the console and the room goes fully silent.
- Transient activity events (contacts, rings, cards) appear on console overlay
and pane **at the same moment and as the same events**, not independently.
- An AI announcement appears once, on both tickers, with identical text.
15. Disconnect NGN. The pane is released and the console continues standalone.
Reconnect; surfaces rediscover and the pane reopens cleanly.
16. **Standalone, no NGN:** open
`…/test-fixtures/reference-exhibits/scifi/index.html` directly. Full console,
clean browser console, WATCH EXPERIENCE works, hotkeys work, audio engages.
17. **Standalone two-window:** with that tab open, open
`…/index.html?surface=observation&xi=<id from the console's describe()>` in a
second window. It attaches and mirrors with no NGN present.
18. Open `…/index.html?surface=observation&xi=nonexistent` alone. It shows a
waiting state and does **not** invent its own state or start audio.
19. Re-run `tools/package.ps1`; open the new `dist/` file **with the network
disabled**. Console, Observation overlay, audio and hotkeys all work; the
Generative Experience panel degrades quietly. *(The packaged build's
Observation is the in-page overlay; two-window pairing is not promised under
`file://` — §9.)*
---
## 16. Risks and mitigations
**R1 — A directory-style base URL causes the primary to open a second full
instance.** `LocalSurfaces` uses full-URL equality. If the operator connects to
`…/scifi/` rather than `…/scifi/index.html`, `exhibitBaseUrl` ends in `/`,
`index.html` no longer equals it, and NGN offers to open the primary as a pane —
which would load a second complete SciFi app.
*Impact:* bounded. That instance gets no transport from NGN and its window bridge
only answers parent/opener/self, so **no second contract session** is created, and
it creates no `AudioContext` until someone engages it. It is wasted, not wrong.
*Mitigation:* document the explicit-filename URL in `README.md` (B6) and in the
6.7B verification doc; it is already the documented URL. Do **not** "fix" this in
NGN — full-URL equality is deliberate (queries and fragments designate other
views), and Museum has the same property. Revisit generically in a later step if
it proves to bite operators.
**R2 — The `prepareExperience()` guard is missed.** `enterObservation()` calls it
unconditionally today; a presentation instance that reaches that line downloads a
1.7B model per pane.
*Mitigation:* the single most important guard in A5(c); covered by tests 1819 and
acceptance step 14. Structure A5 so the construction sites sit in a named
console-only function, making the assertion cheap and durable.
**R3 — The ambient scheduler silently never runs.** Both
`triggerObservationActivity` and `scheduleObservationAmbientActivity` early-return
on `!observationActive`; with the console in normal mode, an open pane would show
a static scene and the defect would look like "the surface is just quiet".
*Mitigation:* the `observationAudienceActive()` correction (§6), test 20, and
acceptance step 14's "same moment, same events" check, which fails loudly if
nothing is generated.
**R4 — Mode branching damages the console path.** `app.js` is 4,703 lines of
tightly coupled closure; a badly placed branch could disable console features.
*Mitigation:* branch by *skipping construction* in presentation mode rather than
by adding conditionals through the console path; `agents.md`'s surgical-edit rule;
acceptance steps 1619 exercise standalone fully; keep the diff reviewable.
**R5 — BroadcastChannel cross-talk between instances.** Two console tabs on one
origin would share a fixed channel name.
*Mitigation:* the instance-scoped channel name (§5.2), tests 9 and 18.
**R6 — Fixture drift between SciFi-XZBT and the NGN copy.** Two trees, one
mechanical copy, and both currently carry uncommitted work.
*Mitigation:* resync as one discrete step (B1), record it in `PROVENANCE.md` (B2),
and hash-verify as Step 5 did (`test-fixtures/evidence/step5-scifi-files.json`).
**R7 — `package.ps1`'s silent inlining failure.** A script tag with different
quoting, extra attributes or self-closing form is left as an external reference and
the standalone build breaks with no error.
*Mitigation:* A3 specifies the exact form; acceptance step 19 opens the packaged
build offline, which is the only test that catches it.
**R8 — Audio-reactive visuals are flat on the surface.** No analyser without an
audio graph.
*Mitigation:* accepted and documented (§6). `ObservationEngine` already guards it.
Mirroring a scalar level is deferred; do not solve it in 6.7B.
**Explicitly not risks:** a second contract session (structurally prevented twice
over); NGN genericity (no NGN change); loss of standalone behavior (the console
path is untouched); packaging fork (one document by construction).
---
## 17. Step 6.7B scope estimate
### Moderate.
Not *small*: the work spans two repositories, touches the largest and most
sensitive file in SciFi-XZBT (`app.js`), adds two contract targets and a catalog,
introduces two new source files and a new synchronization mechanism, and needs a
fixture resync plus two test files and a verification document. Three of the
corrections it depends on — the `_emitEvent` session gate, the
`prepareExperience()` call inside `enterObservation()`, and the
`observationActive` gate on the ambient scheduler — are non-obvious and would each
produce a plausible-looking but wrong implementation if missed.
Not *large*: the decisive cost driver was avoided. There is **no renderer
extraction, no DOM decoupling, no second document, no build change, and no NGN
change.** `observation-engine.js` (3,595 lines) and `audio.js` (6,889 lines) are
untouched. The synchronization mechanism is a direct adaptation of Museum
Gallery's already-validated `surface-bus.js`, and the NGN side was proven in Steps
6.36.6.
Expected diff: roughly 240 new lines across two new SciFi files, ~120 modified
lines in `app.js`, ~40 in `contract-adapter.js`, ~25 in `css/style.css`, 2 lines
in `index.html`, plus ~350 lines of new tests and the fixture resync.
The risk concentrates almost entirely in A5. Implement A1 and A2 first, test them
in isolation, and only then branch `app.js`.
@@ -1,6 +1,13 @@
# XZBT Exhibit Contract Specification
## Version 5.2
> **Historical:** Superseded, additively, by
> [Contract Specification 5.3](XZBT-Exhibit-Contract-Specification-v5.3.md),
> the current maintained contract. No normative requirement in this document
> was removed, weakened, or reinterpreted by 5.3; it is retained here for
> historical context, not as a second currently-maintained contract version.
> XZBT-NGN and its maintained reference exhibits target Contract 5.3.
**Status:** Proposed normative specification
**Document version:** 5.2
**Contract family:** XZBT Exhibit Contract
@@ -0,0 +1,256 @@
# XZBT-NGN Step 6.6 — Reference Exhibit End-to-End Validation
Status: PASS — no implementation changes were required.
Step 6.6 validates Museum Gallery end-to-end as a complete Contract 5.3 reference
exhibit operating through the normal NGN operator UI. It is a validation task: no
architecture was redesigned, no features were added, and no source file was modified.
## A. Environment
| Item | Value |
| --- | --- |
| NGN UI | `http://127.0.0.1:4173/` |
| Server | The already-running `npm start` server on port 4173 (started at 16:43, before this session). A second instance started for validation failed to bind with `EADDRINUSE` and exited, so the served state was unchanged and the running server was left untouched. |
| Exhibit under test | `http://127.0.0.1:4173/test-fixtures/reference-exhibits/museum-gallery/control.html` |
| Replacement exhibit | `http://127.0.0.1:4173/test-fixtures/reference-exhibits/scifi/index.html` |
| Working tree | Step 6.3/6.4/6.5 uncommitted work preserved as found; HEAD `ed76cf6` |
| Method | Real NGN UI in a browser, driven through the served page (no test doubles) |
## B. Initial connection
Observed through the served NGN page after `Load exhibit`:
- Status: `connected · synchronized`
- Session: `sess-1f54f`
- Negotiated contract: `{ major: 5, minor: 3 }`
- Exhibit metadata: `Museum Gallery · 0.1.0 · build reference-exhibit`
- `registryRevision` 1, `stateRevision` 0
- Capabilities: `render: ready`
- Target registry discovered (5):
| Target | Kind | Access |
| --- | --- | --- |
| `artifact.selected` | selection | readable · writable |
| `lighting.level` | range | readable · writable |
| `rotation.speed` | range | readable · writable |
| `labels.enabled` | state | readable · writable |
| `action.spotlight-flash` | impulse | not readable · not writable |
- State snapshot received: `artifact.selected="the-orrery"`, `lighting.level=0.6`,
`rotation.speed=0.4`, `labels.enabled=true`
- Protocol/error log: one `SESSION` entry, no errors
## C. Surface discovery and primary handling
`Presentation surfaces (3)` discovered, exactly the three the exhibit advertises:
| id | Label | Primary | Role | URL |
| --- | --- | --- | --- | --- |
| `surface.control` | Control Room | yes | control | `control.html` |
| `surface.artifact` | Artifact Display | no | ambient | `artifact.html` |
| `surface.info-wall` | Information Wall | no | information | `info-wall.html` |
Primary handling: the primary is not duplicated as a local pane. Its card carries the
`Primary` badge, shows `Open in the authoritative control frame. Use Connection controls
to reload or disconnect.`, and its Open/Reload/Close buttons are disabled. The two
non-primary surfaces open as local panes and each renders and reports
`Attached to Control Room.`
The Control Room's own `Attached non-primary surfaces` readout (the exhibit's participant
count) became `2` when both panes were open.
## D. Lifecycle validation
Measured participant count in the authoritative Control Room:
```text
open both: 2
reload: 2
reload again: 2
close one: 1
reopen: 2
```
Each reload produced a fresh secondary document (verified by a marker placed on the
frame's `contentWindow` disappearing after reload), which then re-attached and rendered
the current authoritative state. No ratcheting and no stale participant entries were
observed at any point.
## E. Shared-state validation
### Control -> secondaries
| Change made in Control Room | Observed propagation |
| --- | --- |
| Selected artifact -> Star Map | `selection.changed`, sequence 1, `stateRevision` 1, `source: "ui"`; both secondaries rendered `Star Map` |
| Lighting level -> 25% | `state.changed`, sequence 2, `stateRevision` 2, `source: "ui"`; Artifact Display rendered `Lighting: 25%` |
Control Room, Artifact Display, Information Wall and NGN's reported state all agreed
after each change.
### Secondary -> primary -> secondaries
A real mouse click on the Artifact Display's native `Cycle artifact` control while the
authoritative selection was `star-map`:
- Control Room's authoritative selection became `meteorite` (its combobox followed)
- `selection.changed`, sequence 3, `stateRevision` 3, `source: "ui"`
- Information Wall updated to `Meteorite Fragment`
- Artifact Display re-rendered from the authoritative result
The secondary remained a mirror: it holds no Core (see section H) and only routes
mutations back through the owner's canonical path.
### Late join
Information Wall closed (count 1) -> authoritative state mutated (rotation 1.7,
labels OFF, `stateRevision` 5) -> Information Wall reopened: it immediately rendered
`Meteorite Fragment` and `Labels: OFF`, and the count returned to 2.
### Reload recovery
Lighting mutated to 90% (`stateRevision` 6) -> Artifact Display reloaded: a fresh
document (marker gone) returned showing `Meteorite Fragment`, `Lighting: 90%`,
`Rotation: 1.7x` — current state, not exhibit defaults — with the count still 2.
### Sustained convergence
Four consecutive normal changes alternating between the primary and both secondaries
(control selection, Information Wall toggle, control rotation, Artifact Display cycle)
left Control Room, Artifact Display, Information Wall and NGN all in agreement at every
step, with revisions advancing 7 -> 8 -> 9 -> 10 and the count steady at 2.
## F. Host-command validation (NGN UI)
| Operation | NGN control used | Result |
| --- | --- | --- |
| Readable state query | `Refresh state` (`state.get`) | Succeeded; snapshot matched, `stateRevision` 10, status `connected · synchronized`, no error |
| `set` (range) | `lighting.level` -> `0.35` + `Set` | Succeeded; Control Room 35%, Artifact Display `Lighting: 35%`, `state.changed` revision 11, `source: "host"`, `correlationId: ngn-2-4` |
| `set` (selection) | `artifact.selected` -> Meteorite Fragment + `Set` | Succeeded; all surfaces `Meteorite Fragment`, `selection.changed` revision 12, `source: "host"`, `correlationId: ngn-2-6` |
| `invoke` (impulse) | `action.spotlight-flash` + `Invoke` | Succeeded; `action.executed` sequence 13, `source: "host"`, `correlationId: ngn-2-8`; exhibit `spotlightFlashCount` incremented; Control Room and both secondaries flashed `Spotlight flashed.` |
Each command left NGN's own state synchronized and produced no error entry. Instrumenting
the Artifact Display's announcement node with a DOM observer confirmed the host-initiated
`action.executed` event actually reached the secondary (it flashed, then returned to idle
after the announcer's 2.6 s window).
## G. Reconnect and replacement
### Disconnect / reconnect
- `Disconnect`: status `disconnected · not synchronized`; catalog reset to
`Connect an exhibit to discover its controls.`; surfaces reset to
`No presentation surfaces advertised.`; both local panes removed (0 surface iframes
remaining); control frame removed; reported state `{}`; no error entries.
- `Reconnect`: new session `sess-15cf1`, Contract 5.3, all three surfaces rediscovered
with correct primary handling, control frame re-established, participant count `0`
(fresh authoritative document), no stale panes or counts.
- Both secondaries reopened and attached to the new session (count 2), each rendering the
new session's current state.
### Exhibit replacement
- Museum -> SciFi (`scifi/index.html`): no Museum pane survived (0 iframes referencing
the Museum exhibit), the surface catalog became `No presentation surfaces advertised.`
(SciFi advertises none), and SciFi negotiated Contract 5.3 as
`SciFi-XZBT · 5.2.0 · build production`, session `sess-2akzu3a7`,
`connected · synchronized`, 61 targets, state snapshot received.
- SciFi -> Museum (`museum-gallery/control.html`): new session `sess-126c6`, Contract 5.3,
5 targets, 3 surfaces rediscovered with the correct primary, participant count `0`,
0 SciFi frames left, 0 stale Museum panes.
## H. Failure isolation
Live-tested through the served UI:
- **A non-primary surface holds no authority.** Inside the Artifact Display document:
`XZBTContractCore` undefined, `MuseumGalleryContract` undefined,
`MuseumGalleryExhibit` undefined, `XZBTHostTransport` undefined; only the surface bus is
present, and `__museumGalleryDebug` exposes a `link` but no core.
- **A secondary cannot act as a protocol peer.** A forged `hello` and a forged `set`
posted directly to the Artifact Display's window produced zero responses, and the
authoritative selection was unchanged.
- **One broken presentation surface does not harm the control session.** The Artifact
Display frame was navigated to a missing page (`does-not-exist.html`, served as
`Not found`): the authoritative session stayed `connected · synchronized` on
`sess-126c6`, the Control Room kept rendering, the registry/state were unaffected, and
the surface's participant slot was released (count 2 -> 0) with no stale entry.
- **Reload failure is surface-local and recoverable.** NGN's per-surface `Reload` brought
the pane back to `artifact.html`; it re-attached and the count returned to 1 while the
session remained synchronized. No error was raised against the session.
Automated-only (covered by the suites below, not re-injected live):
- malformed / individually-invalid surface descriptors and catalog-level rejection
(`surface-validation.test.js`, `museum-gallery.test.js` — 50 validation cases)
- isolated HTTP, frame and reload failures, external frame removal detection, and a
stalled surface resource (`local-surfaces.test.js`)
- resource-check refusal of redirects before frame navigation (`local-surfaces.test.js`)
- presentation window cannot impersonate the authoritative peer over the production
transport (`local-surfaces.test.js`)
- source/origin validation on the real postMessage transport
(`postmessage-interop.test.js`)
## I. Automated verification
Focused run (Museum Gallery, local surfaces, surface validation, postMessage interop,
connection lifecycle):
```text
node --test tests/museum-gallery.test.js tests/local-surfaces.test.js \
tests/surface-validation.test.js tests/postmessage-interop.test.js tests/connection.test.js
# tests 107
# pass 107
# fail 0
```
Full suite (run once):
```text
node --test
# tests 129
# pass 129
# fail 0
```
Other validation:
```text
git diff --check -> clean (exit 0)
python devlog_editor.py --validate -> devlog-editor: devlog is valid (exit 0)
```
## J. Files changed
None. Validation found no defect, so per the Step 6.6 fix policy no implementation file
was modified. The only additions are this report and its raw evidence record
(`test-fixtures/evidence/step6.6-museum-gallery-validation.txt`).
## K. Limitations
1. Failure isolation was live-tested only for the three cases in section H; malformed
descriptor catalogs, redirect refusal, stalled resources and peer impersonation remain
automated-only, and no risky manual failure injection was performed for them.
2. The `Spotlight flashed.` announcement on secondaries is transient (2.6 s idle timeout).
It was confirmed with a DOM mutation observer rather than by a raw text read after the
event, so the recorded evidence is the observer transition sequence.
3. All live checks were same-origin over `http://127.0.0.1:4173`. Cross-origin exhibits,
`file://` documents, and non-`http` schemes were not exercised live.
4. The exhibit instance is recreated by `Disconnect`/`Reconnect` and by exhibit switching,
so post-reconnect state is the exhibit's documented default state (`stateRevision` 0).
No cross-session state persistence exists in the reference exhibit; this is expected
standalone behavior, not a regression.
5. Local surfaces were exercised in one browser window; casting/remote displays remain
out of scope for Step 6.6 and were not tested.
## L. Verdict
PASS. Museum Gallery behaves as a complete Contract 5.3 reference exhibit through the
normal NGN operator UI: connection and synchronization succeed, Contract 5.3 is
negotiated, the surface catalog and primary handling are correct, both secondaries render
locally and report attachment, participant counts stay correct across reload/close/reopen,
Control -> secondary and secondary -> primary -> secondaries synchronization are both
proven, late join and reload recovery return current state, representative host commands
work, disconnect/reconnect and exhibit switching clean up completely, SciFi still connects
and synchronizes, and the focused and full automated suites pass.
@@ -0,0 +1,206 @@
# XZBT-NGN Step 6.7B — SciFi Observation Surface Implementation
Status: PARTIAL PASS. Implementation, focused tests, and full NGN test suite are
complete against a pre-existing, out-of-scope defect. Live browser verification
(report §15) and the standalone packaged-build check were not performed in this
session.
Step 6.7B implements the architecture selected by Step 6.7A (design-only, no
code changes) — Candidate A, narrow form: SciFi-XZBT remains one document, one
script set, with two boot modes, and advertises a Contract 5.3 Observation
presentation surface as a query-mode view of its own `index.html`.
## A. Chosen architecture (confirmed as implemented)
- One document, two boot modes, resolved by `js/surface-mode.js` from
`window.location` before heavy subsystem construction.
- Primary surface: `index.html` (unchanged console), `primary: true`.
- Observation surface: `index.html?surface=observation&xi=<instanceId>`, per
Contract 5.3 §31.4's query-string surface form.
- One authoritative SciFi state, one Contract 5.3 host session (console mode
only), no NGN changes (`src/**` untouched — verified by mtime check against
this session's own edits).
- Presentation synchronization is exhibit-owned via an instance-scoped
`BroadcastChannel` (`js/surface-bus.js`), never observed by NGN.
- Opening the Observation surface does not set `view.observation = true`; the
console's own full-screen overlay is unaffected by pane lifecycle.
## B. Files changed — SciFi-XZBT (`G:\.vibe\SciFi-XZBT`)
| File | Change |
| --- | --- |
| `js/surface-mode.js` | **New**, 108 lines. Pure mode resolver (`resolve`, `newInstanceId`, `SURFACES`, `channelName`). No DOM, no imports. |
| `js/surface-bus.js` | **New**, 254 lines. Instance-scoped `BroadcastChannel` owner/attach sides (`createOwner`, `attach`), adapted from Museum Gallery's proven attach/snapshot/mutate/detach shape with a Set-based participant count. |
| `js/contract-adapter.js` | 1006 → 1060 lines (+54). Additive: `surfaces`/`instanceId` constructor options; `describe()` emits `surfaces` only when non-empty; `view.pillars` / `view.warp-flight` targets registered (state/boolean/readable/writable/restorable, `category: observation`, `requires: [observation]`); `onLocalChange`/`onLocalAction` hooks fired from `_commitChanges`/`_invokeAction`, independent of `sessionActive`; version bumped `5.2.0``5.3.0`. Handshake, envelope, `xzbt` gating, and the `_emitEvent` session gate are unchanged. |
| `js/app.js` | 4703 → 4921 lines (+218). Boot-mode resolution; `isConsoleMode`-guarded construction of `StarshipVisualizer`, `XZBTGenerativeExperience`, `XZBTControlBus`, `XZBTContractAdapter`, the keydown hotkey listener, and the sleep timer; `enterObservation()`'s `prepareExperience()` call now runs only in console mode; surface-bus owner wiring (console) / attach wiring (presentation); `applyPresentationState()` renderer; `observationAudienceActive()` decoupling the ambient scheduler from local overlay visibility; `view.pillars`/`view.warp-flight` added to `bindings.setters` and `getContractStateSnapshot()`; `togglePillars()`/`toggleWarpFlight()` now route through `applyMutation`/bus `mutate` instead of local engine mutation; `window.__xzbtSurfaceDispose` + `beforeunload` detach. |
| `js/observation-engine.js` | 3595 → 3602 lines (+7). Only change: the WARP and PILLARS dock buttons now route through `onMutation`, matching the pre-existing VIEWPORT/RED ALERT/PRESET pattern, instead of mutating engine state directly. |
| `css/style.css` | 2430 → 2457 lines (+27, additive). `body.surface-observation` rules hide `header`/`main`, hide `#obs-btn-exit` / `#observation-return-pill`; overlay renders full-bleed. |
| `index.html` | +2 `<script src="...">` tags, exact `package.ps1`-compatible form, positioned after `control-bus.js`, before `generative-experience.js`. |
| `agents.md`, `README.md` | Documented the two-mode rule, the two new files, the surface-bus mechanism, and the no-duplicate-authority invariant. |
`js/audio.js`, `js/config.js`, `js/visualizer.js`, `js/core-animations.js`,
`js/generative-experience.js`, `js/control-bus.js`, `js/observation-bezels.js`,
and `tools/package.ps1` are unchanged, per the report's "deliberately
unchanged" list.
## C. Files changed — XZBT-NGN
| File | Change |
| --- | --- |
| `test-fixtures/reference-exhibits/scifi/{index.html, js/app.js, js/contract-adapter.js, js/observation-engine.js, css/style.css}` | Byte-for-byte resync from SciFi-XZBT source. |
| `test-fixtures/reference-exhibits/scifi/js/{surface-mode.js, surface-bus.js}` | **New**, copied verbatim from SciFi-XZBT source. |
| `test-fixtures/PROVENANCE.md` | Appended resync note (source path, files copied, no fixture-local corrections). |
| `tests/scifi-surfaces.test.js` | **New**, 533 lines, 24 tests: surface catalog / contract validation, mode resolution, bus late-join/propagation/mutation-routing/no-second-authority/reload/detach/session-independence, duplicate-subsystem construction spies, app.js source-structure guards, ambient-timer test, one-contract-session test. |
| `tests/local-surfaces.test.js` | +1 test using SciFi's real descriptors (19 → 20 tests), confirming the primary resolves to `control` and opens no second frame. |
| `src/**` | **Unchanged.** No NGN core changes were needed or made. |
## D. State synchronization
- Mechanism: `BroadcastChannel` named `xzbt-scifi-surface-v1:<instanceId>`, owned
by the console document; the presentation document reads `instanceId` from its
own `?xi=` query parameter.
- Message shapes match report §5.3 verbatim (`attach` / `attach.snapshot` /
`state` / `action` / `presentation` / `mutate` / `detach`), carry no XZBT
envelope, and are never observed by NGN.
- Late join / reload: `attach` always receives the live
`contractAdapter.getContractState()` snapshot plus `stateRevision` and
`registryRevision`; a reload is a fresh `attach` with a fresh `participantId`.
- Presentation mutations (`view.pillars`, `view.warp-flight`, `view.viewport-frame`,
`alert.active`, `preset.selected`) are sent as `mutate` requests and applied by
the owner exclusively through `contractAdapter.applyMutation(...)` with source
`'ui'` — the same chokepoint NGN's own `set` uses. The presentation side never
writes local state.
- Participant bookkeeping is a `Set`, so duplicate attach and late/duplicate
detach are harmless and cannot ratchet the count.
## E. Heavy-subsystem ownership (confirmed)
Presentation mode does **not** construct: `XZBTGenerativeExperience` (WebLLM +
Kokoro — `prepareExperience()` is now called only inside the console-mode
branch of `enterObservation()`), `XZBTContractAdapter` (no second Contract
session), `XZBTControlBus`, `StarshipVisualizer`, or `CoreAnimations` (its
render loop is only reachable from `StarshipVisualizer`, which is never
constructed). The keydown hotkey listener and the sleep timer are also
console-only. This is enforced by `isConsoleMode` guards at each construction
site and asserted by source-structure tests in `scifi-surfaces.test.js`, plus
construction-spy tests that fail if `AudioContext`/`fetch`/`import` are ever
touched from the surface side.
`AudioManager` and the synth subsystems are still constructed on the
presentation side (needed only to satisfy `ObservationEngine`'s constructor
arity, per the 6.7A report) but never `init()`/`resume()`d, so no
`AudioContext` or audio node is ever created there.
## F. New absolute state targets
- `view.pillars` — state/boolean, readable, writable, restorable,
`category: observation`, `requires: [observation]`. Wired into
`bindings.setters`, `getContractStateSnapshot()`, and dock routing on both
surfaces.
- `view.warp-flight` — same shape. Implemented as a compare-and-toggle against
the engine's existing flight-mode field in `app.js`'s setter rather than
adding a new `observationEngine.setWarpFlight()` method (the report's
suggested name doesn't exist in `observation-engine.js`), keeping that file's
change to the two dock-routing lines only.
Both targets are covered end-to-end (registration, snapshot inclusion, mutation
routing, cross-surface convergence) by tests in `scifi-surfaces.test.js`.
## G. Observation audience behavior
`observationAudienceActive()` = `observationActive || surfaceOwner.attachedCount() > 0`.
The ambient-activity scheduler and `triggerObservationActivity` now gate on this
predicate instead of `observationActive` alone, so a presentation-only audience
(console in normal mode, one or more Observation panes attached) keeps
procedural activity running. `observationActive` itself is unchanged and still
gates the console's own local overlay rendering. Activity *decisions* are made
once by the authority and broadcast; each surface renders its own visual
realization of "an event fired now" rather than a byte-identical copy (see
Deviations, below) — narrative timing is shared, exact pixel content is not.
## H. Standalone verification
Not run live in this session (see §K). By construction: `index.html` with no
query string resolves to console mode via `js/surface-mode.js`'s `resolve()`,
which is unchanged from today's single-mode behavior for that input, and no
code path in the console branch was removed — only guarded with `isConsoleMode`,
which is `true` for that input. This is asserted structurally by
`scifi-surfaces.test.js`'s mode-resolution tests, but not confirmed by opening
a real browser.
## I. Fixture synchronization
`test-fixtures/reference-exhibits/scifi/` was resynced by copying the seven
changed/new files verbatim from `G:\.vibe\SciFi-XZBT` after the source was
syntax-checked and its own focused tests passed. `test-fixtures/PROVENANCE.md`
records the resync. No fixture-local corrections were introduced — drift
prevention relies on this being a discrete, documented, one-directional copy
step (source → fixture), matching the procedure Step 5 used.
## J. Tests
| Suite | Result |
| --- | --- |
| `tests/scifi-surfaces.test.js` (new) | 24/24 pass |
| `tests/local-surfaces.test.js` | 20/20 pass |
| Full NGN suite (`npm test`) | 149/154 pass |
The 5 failures are all in `tests/postmessage-interop.test.js` (`hello timed
out` ×4, one regex check), and are **not** caused by this step's changes.
Root cause: `contract-adapter.js`'s `_setupWindowBridge` gates inbound
messages on exact string equality against `xzbt: '5.2'`, while NGN's
`src/host.js` — modified independently, before this session, and outside this
step's scope — now stamps outgoing envelopes `xzbt: '5.3'`. Fixing this
requires editing the handshake/envelope gating logic that the 6.7A report
explicitly marks "must not change" for Step 6.7B. This is flagged as a
pre-existing cross-repo integration gap for separate resolution, not silently
worked around.
## K. Live verification
**Not performed in this session.** The implementation was delegated to and
completed by an agent operating via local shell access on the SciFi-XZBT and
XZBT-NGN working trees; it did not drive a real browser against a running
`npm start` server. The following report §15 acceptance-procedure steps
remain to be run manually:
1. Connect NGN to `http://127.0.0.1:4173/test-fixtures/reference-exhibits/scifi/index.html`; confirm `connected · synchronized`, Contract 5/3, target catalog.
2. Confirm the Surfaces panel shows exactly two entries — `surface.console` (Primary, no Open button) and `surface.observation` (`?surface=observation&xi=…`).
3. Open the Observation pane; confirm it renders the current universe/preset within ~1s, shows no RETURN ✕ / return pill, and background click does nothing.
4. Confirm the console pane does **not** black out — `view.observation` stays `false`.
5. From NGN, `set` `universe.selected`, `preset.selected`, `alert.active`, `view.viewport-frame`, `view.activity`, `view.pillars`, `view.warp-flight` and confirm both console and pane converge, with `stateRevision` advancing.
6. Reload the pane; confirm it returns to current (not default) state. Close/reopen; confirm the participant count does not ratchet.
7. Press WATCH EXPERIENCE on the console; confirm the pane is unaffected and `view.observation` toggles only the console overlay.
8. DevTools checks on the pane's frame: no WebLLM/Kokoro network activity, `window.generativeExperience === undefined`, no `AudioContext`.
9. Confirm transient activity events and AI announcements appear on console and pane at the same moment.
10. Disconnect/reconnect NGN; confirm clean pane release and rediscovery.
11. Standalone: open `index.html` directly (no NGN) — full console, WATCH EXPERIENCE, hotkeys, audio.
12. Standalone two-window: open `index.html?surface=observation&xi=<real id>` in a second window with no NGN present; confirm it attaches and mirrors.
13. Open `?surface=observation&xi=nonexistent` alone; confirm a waiting state, no invented authority.
14. Run `tools/package.ps1` (requires PowerShell — unavailable in this session's Linux shell) and open the packaged `dist/` file offline; confirm the two new scripts were inlined (report risk R7 — inlining failure is silent) and standalone behavior is unchanged.
## L. Deviations from the 6.7A report
- **Warp-flight setter name.** The report's suggested `observationEngine.setWarpFlight(...)` does not exist; implemented as a compare-and-toggle in `app.js`'s setter instead, touching only the two dock-routing lines in `observation-engine.js`.
- **No single `bootConsole()` function.** The guarded constructions/listeners remain in their existing positions in `app.js` (each wrapped in an `isConsoleMode` check) rather than being physically lifted into one named function, to respect `agents.md`'s "surgical, scoped edits" rule on a ~4,900-line file. Source-structure tests instead assert `isConsoleMode` appears immediately before each construction site. Functionally equivalent to the report's suggestion; less textually tidy.
- **Activity-event visuals are decision-synchronized, not pixel-identical.** Byte-identical rendering across documents would require refactoring the ten universe generator functions to take explicit random parameters instead of calling `Math.random()` internally — judged out of proportion to this step. The *decision* to fire an event, and its narrative timing, is shared; each surface renders its own visual instance of it. Documented as an extension of the already-accepted instrumentation-digit divergence (report §6).
## M. Remaining limitations
- **Audio-reactive waveform is flat on the Observation surface**, as explicitly scoped out of 6.7B. No audio graph exists there; `observation-engine.js`'s pre-existing `am.analyser`-null guards degrade it gracefully. Deferred, not solved, per the governing report.
- **`postmessage-interop.test.js`'s 5 failures** (see §J) are a pre-existing `5.2`/`5.3` handshake-gating mismatch between this SciFi-XZBT change and an independent, prior `src/host.js` change, outside this step's edit scope. Needs separate resolution — likely a version-gating fix in `contract-adapter.js`'s `_setupWindowBridge`, but that edit was withheld here because the report marks it must-not-change for 6.7B.
- **Live browser verification and the packaged single-file build were not exercised** in this session (§K) — recommended before treating 6.7B as fully accepted.
## Step 6.7 verdict
Step 6.7B implementation is **substantively complete against the 6.7A
architecture**: correct surface catalog, single authority, session-independent
local synchronization, both new canonical targets, all heavy-subsystem guards,
audience-activity decoupling, and standalone-preserving structure, all
supported by 44 passing focused/regression tests. Step 6.7 as a whole should
**not yet be marked complete**: the pre-existing handshake mismatch surfaced by
the full suite run needs a decision (fix now vs. track separately), and the
live NGN/browser and standalone/packaged-build verification in report §15
has not been performed. Recommend resolving the handshake mismatch and running
live verification before closing Step 6.7B, and explicitly deferring Step 6.8
until then, per this task's instructions.