@wildshard/engine 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/index.html +157 -11
  3. package/lint/engine-sides.json +16 -0
  4. package/lint/host-register.json +496 -0
  5. package/lint/ratchet.json +2 -2
  6. package/lint/shard-imports.d.mts +1 -0
  7. package/lint/shard-imports.mjs +56 -8
  8. package/lint/wildshard-plugin.js +22 -4
  9. package/package.json +16 -5
  10. package/scripts/app-build/buildIdentity.d.mts +3 -1
  11. package/scripts/app-build/buildIdentity.mjs +25 -5
  12. package/scripts/app-build/builtAt.d.mts +4 -0
  13. package/scripts/app-build/builtAt.mjs +21 -0
  14. package/scripts/app-build/serviceWorker.ts +16 -2
  15. package/scripts/app-build/versionFiles.ts +2 -1
  16. package/scripts/app-build-pipeline.mjs +4 -1
  17. package/scripts/audio-download-proof.mjs +843 -0
  18. package/scripts/build-app.mjs +4 -0
  19. package/scripts/build-mirror.d.mts +2 -0
  20. package/scripts/build-mirror.mjs +5 -4
  21. package/scripts/built-product.mjs +3 -3
  22. package/scripts/cell-mem/metrics-preload.mjs +65 -0
  23. package/scripts/cell-mem-bench.mjs +130 -0
  24. package/scripts/check-chunks.mjs +2 -1
  25. package/scripts/devserver-client.d.mts +5 -0
  26. package/scripts/devserver-client.mjs +68 -0
  27. package/scripts/engine-ci-budget.ts +7 -1
  28. package/scripts/format-lock.mjs +20 -11
  29. package/scripts/generate-title-launch.mjs +3 -2
  30. package/scripts/grid-crossing-walk-proof.mjs +16 -8
  31. package/scripts/heavy-lane.py +25 -1
  32. package/scripts/host-ruler/register-migrate.mjs +242 -0
  33. package/scripts/host-ruler/register.d.mts +36 -0
  34. package/scripts/host-ruler/register.mjs +116 -0
  35. package/scripts/host-ruler/roots.d.mts +29 -0
  36. package/scripts/host-ruler/roots.mjs +333 -0
  37. package/scripts/host-ruler/server-roots.d.mts +23 -0
  38. package/scripts/host-ruler/server-roots.mjs +272 -0
  39. package/scripts/main-watch.d.mts +1 -1
  40. package/scripts/main-watch.mjs +10 -6
  41. package/scripts/map-hash.mjs +3 -6
  42. package/scripts/mmo-bots.mjs +2 -2
  43. package/scripts/offline-proof-rules.d.mts +1 -0
  44. package/scripts/offline-proof-rules.mjs +22 -1
  45. package/scripts/online-rig.mjs +4 -4
  46. package/scripts/page-release/flow.d.mts +1 -0
  47. package/scripts/page-release/flow.mjs +6 -2
  48. package/scripts/page-release.mjs +5 -1
  49. package/scripts/physics-route.json +0 -71
  50. package/scripts/pins-catalogue.ts +103 -0
  51. package/scripts/pins-reuse.mjs +3 -1
  52. package/scripts/pins.ts +22 -14
  53. package/scripts/preview-grid.ts +203 -0
  54. package/scripts/road-preload-proof.mjs +167 -0
  55. package/scripts/server-release/publish.mjs +2 -2
  56. package/scripts/server-release/served-slug.d.mts +2 -0
  57. package/scripts/server-release/served-slug.mjs +10 -0
  58. package/scripts/server-release/sign.d.mts +1 -0
  59. package/scripts/server-release/sign.mjs +3 -7
  60. package/scripts/shard-components.mjs +0 -2
  61. package/scripts/shard-outputs.d.mts +8 -0
  62. package/scripts/shard-outputs.mjs +45 -11
  63. package/scripts/side-parity.d.mts +2 -1
  64. package/scripts/side-parity.mjs +25 -4
  65. package/scripts/test-amber.d.mts +1 -0
  66. package/scripts/test-amber.mjs +10 -0
  67. package/scripts/test-products.json +3 -3
  68. package/scripts/tracked-public.d.mts +1 -0
  69. package/scripts/tracked-public.mjs +17 -0
  70. package/src/cli/engine.mjs +8 -0
  71. package/src/client/app/bootRoute.ts +4 -1
  72. package/src/client/app/dropModal.ts +15 -2
  73. package/src/client/app/entry.ts +67 -11
  74. package/src/client/app/slugPath.ts +5 -0
  75. package/src/client/engine/audio/Audio.ts +20 -2
  76. package/src/client/engine/boot/bakedTextures.ts +3 -2
  77. package/src/client/engine/boot/bootTrace.ts +6 -1
  78. package/src/client/engine/boot/bytes.ts +4 -3
  79. package/src/client/engine/boot/clearDownloads.ts +1 -1
  80. package/src/client/engine/boot/contentRead.ts +4 -0
  81. package/src/client/engine/boot/dropNotice.ts +20 -6
  82. package/src/client/engine/boot/gpuFiles.ts +25 -2
  83. package/src/client/engine/boot/lastEnd.ts +8 -2
  84. package/src/client/engine/boot/shardPrefetch.ts +7 -1
  85. package/src/client/engine/boot/sw.ts +19 -0
  86. package/src/client/engine/core/Game.ts +11 -3
  87. package/src/client/engine/core/GpuRecovery.ts +7 -0
  88. package/src/client/engine/core/Volumetrics.ts +5 -0
  89. package/src/client/engine/core/assets.ts +27 -20
  90. package/src/client/engine/core/bootstrap.ts +1 -2
  91. package/src/client/engine/core/ktx2.ts +84 -11
  92. package/src/client/engine/explore/Compare.ts +2 -2
  93. package/src/client/engine/explore/TouchFly.ts +3 -5
  94. package/src/client/engine/input/dom.ts +12 -0
  95. package/src/client/engine/net/predictor.ts +6 -2
  96. package/src/client/engine/player/Player.ts +10 -2
  97. package/src/client/engine/player/TouchControls.ts +12 -4
  98. package/src/client/engine/pwa/sw.js +47 -8
  99. package/src/client/engine/render/drawCheck.ts +96 -0
  100. package/src/client/engine/saves/staleBuildNote.ts +46 -0
  101. package/src/client/engine/telemetry/browserErrors.ts +157 -20
  102. package/src/client/engine/telemetry/screenOutbox.ts +61 -0
  103. package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
  104. package/src/client/engine/ui/DeathFade.ts +99 -11
  105. package/src/client/engine/ui/ErrorModal.ts +13 -6
  106. package/src/client/engine/ui/Feedback.ts +2 -1
  107. package/src/client/engine/ui/Loading.ts +10 -6
  108. package/src/client/engine/ui/Map.ts +2 -1
  109. package/src/client/engine/ui/WeaponStrip.ts +2 -1
  110. package/src/client/engine/ui/backGuard.ts +104 -0
  111. package/src/client/engine/ui/hudAdapters.ts +30 -4
  112. package/src/client/engine/ui/loading.css +17 -0
  113. package/src/client/engine/ui/namePrompt.ts +6 -5
  114. package/src/client/engine/ui/styles/combat.css +12 -0
  115. package/src/client/engine/ui/styles/namePrompt.css +4 -2
  116. package/src/client/game/boot/audio.generated.ts +0 -294
  117. package/src/client/game/boot/bytes.generated.ts +0 -11
  118. package/src/client/game/boot/versions.generated.ts +0 -11
  119. package/src/client/game/compendium/keepsakes.ts +16 -6
  120. package/src/client/game/grapple/tool.ts +10 -7
  121. package/src/client/game/grid/cellLoading.ts +23 -12
  122. package/src/client/game/grid/cellScreens.ts +39 -74
  123. package/src/client/game/grid/liveSession.ts +40 -7
  124. package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
  125. package/src/client/game/grid/nearPlaceholderView.ts +9 -3
  126. package/src/client/game/grid/oneWayIn.ts +92 -27
  127. package/src/client/game/grid/pageEntry.ts +19 -0
  128. package/src/client/game/grid/pageShell.ts +1 -1
  129. package/src/client/game/grid/plotAudio.ts +114 -0
  130. package/src/client/game/grid/products.ts +55 -5
  131. package/src/client/game/grid/roadLookPlatform.ts +2 -2
  132. package/src/client/game/grid/session.ts +38 -22
  133. package/src/client/game/grid/spawnGround.ts +68 -0
  134. package/src/client/game/grid/voidLook.ts +29 -23
  135. package/src/client/game/loot/runtime.ts +3 -1
  136. package/src/client/game/mainMenu.ts +14 -6
  137. package/src/client/game/riding/hud.ts +6 -4
  138. package/src/client/game/session/finish.ts +17 -3
  139. package/src/client/game/session/play.ts +8 -2
  140. package/src/client/game/session/session.ts +4 -1
  141. package/src/client/game/shardfile/clientWorker.ts +41 -12
  142. package/src/client/game/shardfile/serverRoute.ts +10 -22
  143. package/src/client/game/slugPage.css +11 -0
  144. package/src/client/game/slugPage.ts +84 -0
  145. package/src/client/game/systems/viewmodel/heldView.ts +6 -3
  146. package/src/client/game/titleDeck.ts +55 -32
  147. package/src/client/host/online/doctor.ts +7 -6
  148. package/src/client/host/online/linkScreens.ts +16 -0
  149. package/src/client/host/online/release.ts +51 -5
  150. package/src/client/host/online/shell.ts +48 -27
  151. package/src/client/host/standalone/shell.ts +7 -3
  152. package/src/cook/game/audioReport.ts +57 -0
  153. package/src/cook/game/entryTotals.ts +26 -6
  154. package/src/cook/game/installedRuntimeReads.ts +3 -0
  155. package/src/server/engine/sim/respawn.ts +6 -1
  156. package/src/server/engine/sim.ts +3 -0
  157. package/src/server/game/grid/simulation.ts +35 -0
  158. package/src/server/game/loot/harvest.ts +2 -0
  159. package/src/server/game/loot/keepsakeProgression.ts +40 -0
  160. package/src/server/game/loot/playerOwned.ts +5 -1
  161. package/src/server/game/plugin/simulation.ts +4 -0
  162. package/src/server/game/population/nativeBake.ts +2 -1
  163. package/src/server/game/quest/chapterRecords.ts +2 -0
  164. package/src/server/game/quest/serverChapters.ts +4 -0
  165. package/src/server/game/quest/serverDoors.ts +11 -5
  166. package/src/server/game/roomRespawn.ts +4 -0
  167. package/src/server/game/shardfile/installedSides.ts +18 -0
  168. package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
  169. package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
  170. package/src/server/host/bake/headlessWorker.ts +5 -1
  171. package/src/server/host/dedicated/cellHost.ts +98 -29
  172. package/src/server/host/dedicated/cellProtocol.ts +11 -1
  173. package/src/server/host/dedicated/cellWorker.ts +9 -3
  174. package/src/server/host/dedicated/crossing.ts +6 -2
  175. package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
  176. package/src/server/host/dedicated/gridCells.ts +52 -9
  177. package/src/server/host/dedicated/main.ts +31 -12
  178. package/src/server/host/dedicated/placementFile.ts +72 -0
  179. package/src/server/host/dedicated/releaseFile.ts +17 -10
  180. package/src/server/host/dedicated/roadRoom.ts +21 -5
  181. package/src/server/host/dedicated/workerTable.ts +13 -1
  182. package/src/server/host/dedicated/world.ts +81 -9
  183. package/src/server/host/headlessRuntime.ts +10 -5
  184. package/src/server/host/installers.ts +62 -0
  185. package/src/server/host/openWorld.ts +59 -0
  186. package/src/server/host/ropeDecks.ts +2 -0
  187. package/src/server/host/standalone/cellWorld.ts +25 -19
  188. package/src/server/host/standalone/fallFloor.ts +2 -2
  189. package/src/server/host/standalone/gridServer.ts +7 -4
  190. package/src/server/host/standalone/roadWorld.ts +41 -4
  191. package/src/shared/engine/audio/bootAudio.ts +33 -0
  192. package/src/shared/engine/level/spec.ts +3 -3
  193. package/src/shared/engine/net/acts.ts +3 -0
  194. package/src/shared/engine/physics/query.ts +27 -0
  195. package/src/shared/engine/physics/terrain.ts +19 -28
  196. package/src/shared/engine/saves/saves.lock.json +15 -0
  197. package/src/shared/engine/sim/actRoutes.ts +2 -0
  198. package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
  199. package/src/shared/game/grid/catalogue.ts +12 -5
  200. package/src/shared/game/grid/catalogueSlot.ts +11 -0
  201. package/src/shared/game/grid/farProxy.ts +6 -5
  202. package/src/shared/game/grid/pageMode.ts +1 -1
  203. package/src/shared/game/grid/roadLayout.ts +26 -3
  204. package/src/shared/game/grid/singleplayer.json +0 -13
  205. package/src/shared/game/grid/voidFloor.ts +122 -0
  206. package/src/shared/game/strings.ts +15 -0
  207. package/src/shared/host/standalone/netInput.ts +2 -1
@@ -1,7 +1,7 @@
1
1
  import { titleAssetURL } from './titleAssets';
2
2
  import { pageScope } from '@wildshard/engine/app/resources';
3
3
  import { isDev } from '@wildshard/engine/core/devMode';
4
- import { followsTap, listenDom, listenTap } from '@wildshard/engine/input/dom';
4
+ import { capturePointer, followsTap, listenDom, listenTap } from '@wildshard/engine/input/dom';
5
5
  import { beginNavigationShell } from '@wildshard/engine/boot/shell';
6
6
  import { startEntryDownload } from './shardfile/entryTransport';
7
7
  import { saves } from '@wildshard/engine/saves/runtime';
@@ -36,7 +36,8 @@ import { readSummary, summaryView } from './summary';
36
36
  import { GAME_STRINGS } from '../../shared/game/strings';
37
37
  import { menuMode, selectEnters, selectExplores, type MenuMode } from './grid/menu';
38
38
  import { pageShardRefusals, refusalReason, type ShardRefusal } from './grid/refusal';
39
- import { playerHidden, titleStatus } from '../../shared/game/grid/catalogueSlot';
39
+ import { autoPlaced, playerHidden, titleStatus } from '../../shared/game/grid/catalogueSlot';
40
+ import { worldOpens } from './grid/oneWayIn';
40
41
  import './summary.css';
41
42
  import './upgrade.css';
42
43
 
@@ -61,6 +62,8 @@ export interface TitleCard {
61
62
  upgrade?: { readonly built: number };
62
63
  /** G167: this session refused the shard (memory, safety, format or load): the dimmed UNAVAILABLE card with its reason */
63
64
  unavailable?: ShardRefusal;
65
+ /** OFFLINE OF3: a world build whose world doesn't open this shard: the dimmed card reads "Not in this world yet", ENTER WORLD off */
66
+ closed?: true;
64
67
  }
65
68
 
66
69
  /** Which shards need an upgrade before this client can enter them (G86): the shardfile version each was built for. Every
@@ -71,30 +74,40 @@ const noUpgrades: UpgradeNeeded = () => null;
71
74
  /** Which shards this session refused (G167; `src/client/game/grid/refusal.ts`), default: the page's session record. */
72
75
  export type RefusedShard = (slug: string) => ShardRefusal | null;
73
76
  const sessionRefusals: RefusedShard = (slug) => pageShardRefusals().read(slug);
77
+ /** Which shards this build's world opens (OF3), default: the build's world stamp and the device's kept world word. */
78
+ export type OpensShard = (slug: string) => boolean;
79
+ const buildWorld = (): OpensShard => worldOpens((globalThis as { __WS_WORLD__?: unknown }).__WS_WORLD__);
74
80
 
75
81
  /** Developer mode reveals hidden levels after every player-facing card. */
76
- export function titleCards(showHidden: boolean = isDev(), upgradeNeeded: UpgradeNeeded = noUpgrades, refused: RefusedShard = sessionRefusals): readonly TitleCard[] {
82
+ export function titleCards(showHidden: boolean = isDev(), upgradeNeeded: UpgradeNeeded = noUpgrades, refused: RefusedShard = sessionRefusals, opens: OpensShard = buildWorld()): readonly TitleCard[] {
77
83
  // a `_` prototype stays Developer only unless its catalogue placement opens it (J313: Mossgate)
78
84
  const hidden = (m: TitleManifest): boolean => playerHidden(m);
79
- const ordinary = titleManifests().filter(m => m.shardSelect !== false);
85
+ // SA34 (Q12): an auto-placed shard has no card, even for Developer: you cross in from a neighbour
86
+ const ordinary = titleManifests().filter(m => m.shardSelect !== false && !autoPlaced(m));
80
87
  const visible = ordinary.filter((m) => !hidden(m));
81
88
  const manifests = showHidden ? [...visible, ...ordinary.filter(hidden)] : visible;
82
- return manifests.map((m): TitleCard => {
83
- const card: TitleCard = {
89
+ return manifests.map((m): TitleCard => titleCard(m, upgradeNeeded, refused, opens));
90
+ }
91
+
92
+ /** One shard's card, as Shard Select draws it; also the `/slug/<slug>` page's one card (SA36), which a shard with no Shard
93
+ * Select card (an open plot, an auto-placed shard) still gets. */
94
+ export function titleCard(m: TitleManifest, upgradeNeeded: UpgradeNeeded = noUpgrades, refused: RefusedShard = sessionRefusals, opens: OpensShard = buildWorld()): TitleCard {
95
+ const card: TitleCard = {
84
96
  slug: m.slug, name: m.name, label: m.biome,
85
97
  thumbnail: m.card.thumb, heroPortrait: m.card.portrait, heroLandscape: m.card.landscape,
86
- };
87
- const status = titleStatus(m);
88
- if (status === 'earlyAccess') card.badge = 'Early access';
89
- if (status === 'experimental') card.badge = 'Experimental';
90
- if (status === 'partial') card.badge = 'Partial';
91
- if (hidden(m)) card.badge = 'Developer only';
92
- const built = upgradeNeeded(m.slug);
93
- if (built !== null) card.upgrade = { built };
94
- const refusal = built === null ? refused(m.slug) : null; // G86's card already says NEEDS UPGRADE
95
- if (refusal !== null) card.unavailable = refusal;
96
- return card;
97
- });
98
+ };
99
+ const status = titleStatus(m);
100
+ if (status === 'earlyAccess') card.badge = 'Early access';
101
+ if (status === 'experimental') card.badge = 'Experimental';
102
+ if (status === 'partial') card.badge = 'Partial';
103
+ if (playerHidden(m)) card.badge = 'Developer only';
104
+ const built = upgradeNeeded(m.slug);
105
+ if (built !== null) card.upgrade = { built };
106
+ // OF3: a shard this world doesn't open never loads here, so no refusal of it is news
107
+ if (built === null && !opens(m.slug)) card.closed = true;
108
+ const refusal = built === null && card.closed === undefined ? refused(m.slug) : null; // G86's card already says NEEDS UPGRADE
109
+ if (refusal !== null) card.unavailable = refusal;
110
+ return card;
98
111
  }
99
112
 
100
113
  /** A deck entry: a shard's card, or a draft's COMING SOON card (WORLDCLAW-TOOLS W9, J19, J38): no world to enter, its
@@ -106,6 +119,7 @@ interface DeckEntry {
106
119
  readonly badge?: TitleBadge | undefined;
107
120
  readonly upgrade?: { readonly built: number } | undefined;
108
121
  readonly unavailable?: ShardRefusal | undefined;
122
+ readonly closed?: true | undefined;
109
123
  readonly thumbnail: string;
110
124
  readonly heroPortrait: string;
111
125
  readonly heroLandscape: string;
@@ -130,6 +144,11 @@ export interface TitleDeckOptions {
130
144
  readonly notice?: string;
131
145
  /** what the menu may show and enter (default: Settings ▸ Developer and the DEVSERVER build, read live) */
132
146
  readonly mode?: () => MenuMode;
147
+ /** SA36: the `/slug/<slug>` page's one card. ENTER WORLD reads `play` over `hint`; `closed` (a slug with no grid cell)
148
+ * disables it and says why in the hint's place (Jake, grill Q16: the card and hero, Play disabled) */
149
+ readonly single?: { readonly play: string; readonly hint: string; readonly closed?: string };
150
+ /** runs on ENTER WORLD's tap before the entry (the slug page's first-play name ask); `go` enters */
151
+ readonly gate?: (go: () => void) => void;
133
152
  }
134
153
 
135
154
  export interface TitleDeck {
@@ -163,20 +182,21 @@ const restricted = (card: DeckEntry): boolean => card.badge === 'Developer only'
163
182
 
164
183
  /** ENTER WORLD for a card: Select a shard enters what §3.3's table allows in this mode (SF21a: shipped, Developer, DEVSERVER) */
165
184
  function canEnter(card: DeckEntry, mode: MenuMode = menuMode()): boolean {
166
- if (card.draft || card.upgrade !== undefined || card.unavailable !== undefined) return false;
185
+ if (card.draft || card.upgrade !== undefined || card.unavailable !== undefined || card.closed === true) return false;
167
186
  return selectEnters(card.slug, restricted(card), mode);
168
187
  }
169
188
 
170
189
  /** EXPLORE WORLD is a developer tool: only in developer mode (or a DEVSERVER build), and only for a world that can be
171
190
  * entered (Jake, E386) */
172
191
  function canExplore(card: DeckEntry, mode: MenuMode = menuMode()): boolean {
173
- return !card.draft && selectExplores(card.slug, restricted(card), mode);
192
+ // OF3: exploring joins the world too (OF2), which would seat a closed shard's page in another cell
193
+ return !card.draft && card.closed !== true && selectExplores(card.slug, restricted(card), mode);
174
194
  }
175
195
 
176
196
  /** the tape over a card's image: a world that can't be entered reads COMING SOON, not EXPERIMENTAL (Jake, E386) */
177
197
  function ribbonFor(card: DeckEntry, mode: MenuMode = menuMode()): string {
178
198
  if (card.draft) return mode.developer || mode.devserver ? GAME_STRINGS.drafts.ribbon(card.draft.stage) : GAME_STRINGS.drafts.comingSoon;
179
- if (card.upgrade !== undefined || card.unavailable !== undefined) return ''; // G86 / G167: the amber badge says it, not a tape
199
+ if (card.upgrade !== undefined || card.unavailable !== undefined || card.closed === true) return ''; // G86 / G167 / OF3: the amber line says it, not a tape
180
200
  if (!canEnter(card, mode)) return 'Coming soon';
181
201
  return card.badge === 'Developer only' ? GAME_STRINGS.developer.ribbon : card.badge ?? '';
182
202
  }
@@ -202,7 +222,8 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
202
222
  const onTap = (el: HTMLElement, fn: () => void): void => { listenTap(scope, el, fn); };
203
223
  const { cards } = opts;
204
224
  // J313: a draft's card (Thin Ice, off the grid by J305) never loads, so only Developer sees it
205
- const drafts = mode().developer || mode().devserver ? DRAFT_TITLES : [];
225
+ // SA36: the slug page holds exactly its one card, Developer or not
226
+ const drafts = opts.single === undefined && (mode().developer || mode().devserver) ? DRAFT_TITLES : [];
206
227
  const entries: readonly DeckEntry[] = [...cards.map(fromShard), ...drafts.map(fromDraft)];
207
228
  const activeIndex = entries.map((card): string => card.slug).indexOf(opts.active ?? '');
208
229
  const root = document.createElement('div');
@@ -221,17 +242,18 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
221
242
  const cardTrack = required(root, '.ws-menu-deck-track'), dotTrack = required(root, '.ws-menu-dots');
222
243
  entries.forEach((card, index) => {
223
244
  const active = index === activeIndex, button = document.createElement('button'); button.type = 'button'; button.dataset['i'] = String(index);
224
- button.className = `ws-menu-card${active ? ' active' : ''}${card.upgrade !== undefined || card.unavailable !== undefined ? ' ws-menu-card-upgrade' : ''}${card.unavailable !== undefined ? ' ws-menu-card-unavailable' : ''}`;
245
+ const dimmed = card.upgrade !== undefined || card.unavailable !== undefined || card.closed === true, amber = card.unavailable !== undefined || card.closed === true;
246
+ button.className = `ws-menu-card${active ? ' active' : ''}${dimmed ? ' ws-menu-card-upgrade' : ''}${amber ? ' ws-menu-card-unavailable' : ''}`;
225
247
  const image = document.createElement('span'); image.className = 'ws-menu-card-img'; image.style.backgroundImage = `url('${titleAssetURL(card.thumbnail)}')`;
226
248
  if (card.upgrade !== undefined) image.append(words('i', 'ws-menu-card-tag ws-menu-card-needs', GAME_STRINGS.upgrade.badge));
227
249
  else if (card.unavailable !== undefined) image.append(words('i', 'ws-menu-card-tag ws-menu-card-needs', GAME_STRINGS.unavailable.badge));
228
- if (canEnter(card, mode())) image.append(words('i', `ws-menu-card-tag${active ? ' ok' : ''}`, active ? 'Loaded' : 'Load'));
250
+ if (canEnter(card, mode()) && opts.single?.closed === undefined) image.append(words('i', `ws-menu-card-tag${active ? ' ok' : ''}`, active ? 'Loaded' : 'Load'));
229
251
  // G238: the port badge, Developer on only (the public card is unchanged)
230
252
  const ribbon = ribbonFor(card, mode());
231
253
  const tone = !canEnter(card, mode()) ? '' : card.badge === 'Early access' ? ' ws-menu-card-ea' : card.badge === 'Partial' ? ' ws-menu-card-partial' : '';
232
254
  if (ribbon !== '') image.append(words('i', `ws-menu-card-exp${tone}`, ribbon));
233
- const sub = card.upgrade !== undefined ? GAME_STRINGS.upgrade.built(card.upgrade.built) : card.unavailable !== undefined ? refusalReason(card.unavailable) : card.label;
234
- button.append(image, words('b', '', card.name), words('small', card.unavailable !== undefined ? 'ws-menu-card-reason' : '', sub)); cardTrack.append(button);
255
+ const sub = card.upgrade !== undefined ? GAME_STRINGS.upgrade.built(card.upgrade.built) : card.closed === true ? GAME_STRINGS.notInWorld.badge : card.unavailable !== undefined ? refusalReason(card.unavailable) : card.label;
256
+ button.append(image, words('b', '', card.name), words('small', amber ? 'ws-menu-card-reason' : '', sub)); cardTrack.append(button);
235
257
  const dot = document.createElement('i'); dot.dataset['i'] = String(index); dot.dataset['tag'] = dotTag(card, mode()); dot.style.setProperty('--thumb', `url('${titleAssetURL(card.thumbnail)}')`); dotTrack.append(dot);
236
258
  });
237
259
  if (opts.notice) {
@@ -286,11 +308,12 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
286
308
  // (a phone network, a busy page), the backdrop is the card's picture, never black (Jake's Pine Hollow, ab93dccfe)
287
309
  hero.style.backgroundImage = `url('${heroUrl(c)}'), url('${titleAssetURL(c.thumbnail)}')`;
288
310
  hero.classList.add('show');
289
- hint.textContent = hintFor(c, index === activeIndex, mode());
290
- play.disabled = !canEnter(c, mode()) && c.draft === null;
311
+ const open = canEnter(c, mode()), single = opts.single;
312
+ hint.textContent = single?.closed ?? (single === undefined || !open ? hintFor(c, index === activeIndex, mode()) : single.hint);
313
+ play.disabled = (!open && c.draft === null) || single?.closed !== undefined;
291
314
  explore.disabled = !canExplore(c, mode());
292
315
  explore.classList.toggle('off', !canExplore(c, mode())); // menu.css hides .off
293
- required(play, 'b').textContent = c.draft ? (isDev() ? GAME_STRINGS.drafts.draftMode : GAME_STRINGS.drafts.followBuild) : c.upgrade !== undefined ? GAME_STRINGS.upgrade.badge : c.unavailable !== undefined ? GAME_STRINGS.unavailable.badge : canEnter(c, mode()) ? 'Enter world' : 'Coming soon';
316
+ required(play, 'b').textContent = c.draft ? (isDev() ? GAME_STRINGS.drafts.draftMode : GAME_STRINGS.drafts.followBuild) : c.upgrade !== undefined ? GAME_STRINGS.upgrade.badge : c.unavailable !== undefined ? GAME_STRINGS.unavailable.badge : c.closed === true ? GAME_STRINGS.notInWorld.badge : open ? single?.play ?? 'Enter world' : 'Coming soon';
294
317
  paintSummary(c);
295
318
  };
296
319
  const select = (raw: number, smooth = true): void => {
@@ -302,7 +325,7 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
302
325
  let entering = false;
303
326
  const enter = (c: DeckEntry): boolean => {
304
327
  if (entering) return false;
305
- if (c.shard === null || !canEnter(c, mode())) return false;
328
+ if (c.shard === null || !canEnter(c, mode()) || opts.single?.closed !== undefined) return false;
306
329
  const shard = c.shard;
307
330
  entering = true;
308
331
  startEntryDownload(c.slug); titlePrefetchChoice(saves).remember(c.slug);
@@ -323,7 +346,7 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
323
346
  listenDom(scope, list, 'pointerdown', (e) => {
324
347
  if (drag) return;
325
348
  drag = { id: e.pointerId, x0: e.clientX, t0: performance.now(), dx: 0 };
326
- list.setPointerCapture(e.pointerId);
349
+ capturePointer(list, e.pointerId);
327
350
  });
328
351
  listenDom(scope, list, 'pointermove', (e) => {
329
352
  if (!drag || e.pointerId !== drag.id) return;
@@ -343,7 +366,7 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
343
366
  // a click that only follows the title's SHARD SELECT tap lands where that tap was, not on a card or dot (QC2)
344
367
  cardEls.forEach((e, i) => { listenDom(scope, e, 'click', (ev) => { ev.stopPropagation(); if (!followsTap(ev) && i !== index && performance.now() - swipedAt > 400) select(i); }); });
345
368
  dots.forEach((d, i) => { listenDom(scope, d, 'click', (ev) => { ev.stopPropagation(); if (!followsTap(ev)) select(i); }); });
346
- onTap(required(root, '.ws-menu-play'), () => { activate(); });
369
+ onTap(required(root, '.ws-menu-play'), () => { if (opts.gate === undefined) activate(); else opts.gate(() => { activate(); }); });
347
370
  onTap(required(root, '.ws-menu-explore'), () => { const c = entries[index]; if (c?.shard && canExplore(c, mode())) opts.onExplore(c.shard); });
348
371
  onTap(required(root, '.ws-menu-settings'), opts.onSettings);
349
372
  // QA row 25's Developer pixel card is gone: Settings ▸ Graphics ▸ Pixel density is the one pixel control (MG8, Jake ~23:45)
@@ -265,12 +265,13 @@ async function checkBrowser(config: DoctorConfig, scope: Scope, ms: number): Pro
265
265
  } catch { ed25519 = false; }
266
266
  parts.push(ed25519 ? 'Ed25519' : 'no Ed25519');
267
267
  if (!ed25519) { failed = true; problems.push(`Update ${chrome === undefined ? 'this browser' : `Chrome (${chrome})`} to Chrome 137+ or Safari 17+.`); }
268
- let gpu = '';
269
- const webgpu = (navigator as { gpu?: { requestAdapter: () => Promise<unknown> } }).gpu;
270
- if (webgpu !== undefined) { try { if (await limited(scope, Math.min(ms, 3000), () => webgpu.requestAdapter()) !== null) gpu = 'WebGPU'; } catch { gpu = ''; } }
271
- if (gpu === '') { const canvas = document.createElement('canvas'); gpu = canvas.getContext('webgl2') !== null ? 'WebGL2' : canvas.getContext('webgl') !== null ? 'WebGL' : ''; }
272
- parts.push(gpu === '' ? 'no 3D' : gpu);
273
- if (gpu === '') { failed = true; problems.push('This browser has no WebGPU or WebGL: turn on hardware acceleration, or use Chrome or Safari.'); }
268
+ // J326 (Jake, 2026-11-13): the game draws with WebGL2 only (core/webglStartup.ts), so the doctor asks for exactly that;
269
+ // a WebGPU adapter or a WebGL1 context is no pass, since neither draws the game
270
+ const probe = document.createElement('canvas').getContext('webgl2');
271
+ const gpu = probe === null ? '' : 'WebGL2';
272
+ probe?.getExtension('WEBGL_lose_context')?.loseContext();
273
+ parts.push(gpu === '' ? 'no WebGL2' : gpu);
274
+ if (gpu === '') { failed = true; problems.push('This browser has no WebGL2: turn on hardware acceleration, or use Chrome or Safari.'); }
274
275
  try {
275
276
  const estimate = await limited(scope, Math.min(ms, 3000), () => navigator.storage.estimate());
276
277
  const free = (estimate.quota ?? 0) - (estimate.usage ?? 0);
@@ -8,6 +8,17 @@ import type { Scope } from '@wildshard/engine/app/scope';
8
8
  import type { LinkCause, LinkProgress, LinkState } from '@wildshard/engine/net/redial';
9
9
  import type { Countdown } from '@wildshard/engine/net/socketFrames';
10
10
  import { diagnosticNow } from '@wildshard/engine/core/clock';
11
+ import { captureBrowserError } from '@wildshard/engine/telemetry/browserErrors';
12
+
13
+ declare const __BUILD_ID__: string;
14
+ /** SENTRY-TRIAGE S13: a stop card that means the link failed (`link-lost`, `link-refused`) sends one event as it opens */
15
+ function reportStop(screen: 'link-lost' | 'link-refused', detail: string, report: typeof captureBrowserError): void {
16
+ try {
17
+ let build = ''; try { build = __BUILD_ID__; } catch { /* under Node */ }
18
+ report(new Error(screen === 'link-lost' ? `Couldn't reconnect: ${detail}` : `The world turned this connection away: ${detail}`),
19
+ { system: 'link', build, shard: '', bootStage: 'running', fatal: false, screen, diagnostic: { detail } });
20
+ } catch { /* telemetry never stops the card */ }
21
+ }
11
22
 
12
23
  /** Redial gives up after this long (`redial.ts` GIVE_UP_MS). */
13
24
  const GIVE_UP_S = 120;
@@ -77,6 +88,8 @@ export interface LinkScreenHooks {
77
88
  readonly doctor?: (from: string) => void;
78
89
  /** Reload this page into the world, taking the seat back (another tab, a turned-away link). */
79
90
  readonly reload: () => void;
91
+ /** S13: where a failed link's stop card reports (the browser error tracker; a test observes its own) */
92
+ readonly report?: typeof captureBrowserError;
80
93
  }
81
94
  /** What the shell tells the screens, and asks of them. */
82
95
  export interface LinkScreens {
@@ -144,6 +157,7 @@ function buttons(scope: Scope, actions: readonly { readonly label: string; reado
144
157
  * if (!screens.allow('Talk')) return; // a tap the world must hear
145
158
  */
146
159
  export function linkScreens(scope: Scope, hooks: LinkScreenHooks, parent: HTMLElement = document.body): LinkScreens {
160
+ const report = hooks.report ?? captureBrowserError;
147
161
  // the stylesheet lives as long as the document: a second shell (a reload in place) shares it
148
162
  if (document.getElementById('ws-link-style') === null) { const style = make('style'); style.id = 'ws-link-style'; style.textContent = CSS; document.head.append(style); }
149
163
  // the banner keeps the old strip's id, so the online proofs still find it
@@ -255,6 +269,7 @@ export function linkScreens(scope: Scope, hooks: LinkScreenHooks, parent: HTMLEl
255
269
  }
256
270
  if (state === 'ended') for (const kept of held.splice(0)) kept.drop();
257
271
  if (state === 'lost') {
272
+ reportStop('link-lost', `${String(hooks.progress().dials)} dials · last close: ${hooks.why()}`, report);
258
273
  stop('lost', 'bad', 'Connection lost', 'Couldn\'t reconnect', 'We tried for 2 minutes and the world didn\'t answer. Anything the world hadn\'t saved yet may need doing again.',
259
274
  [{ label: 'Try again', primary: true, busy: 'Reconnecting…', act: () => { hooks.retry(); } }, ...doctor('lost')], `${String(hooks.progress().dials)} dials · last close: ${hooks.why()}`);
260
275
  } else if (state === 'full') {
@@ -264,6 +279,7 @@ export function linkScreens(scope: Scope, hooks: LinkScreenHooks, parent: HTMLEl
264
279
  stop('replaced', 'info', 'Another tab', 'Playing somewhere else', 'This world is open in another tab or on another device. Only one can play at a time.',
265
280
  [{ label: 'Play here', primary: true, busy: 'Joining…', act: () => { hooks.reload(); } }], 'close "replaced" (4003)');
266
281
  } else if (state === 'ended' && reason !== 'reload') {
282
+ reportStop('link-refused', `close "${String(reason)}"`, report);
267
283
  stop('refused', 'bad', 'Turned away', 'The world turned this connection away', 'The server ended this link and won\'t take it back by itself.',
268
284
  [{ label: 'Play again', primary: true, busy: 'Joining…', act: () => { hooks.reload(); } }, ...doctor('lost')], `close "${String(reason)}"`);
269
285
  }
@@ -1,6 +1,7 @@
1
1
  // E7.2d: a page's read of the signed release file (J171): the build the world runs and the address to dial. WebCrypto's Ed25519, so no
2
2
  // signature code ships in the client. A page believes nothing in the file before its signature holds.
3
3
  import * as v from 'valibot';
4
+ import { Scope } from '@wildshard/engine/app/scope';
4
5
  import { ReleaseSchema, SignedSchema, type ReleaseFile } from '../../../shared/host/releaseRows';
5
6
 
6
7
  const hexBytes = (hex: string): Uint8Array<ArrayBuffer> => Uint8Array.from(hex.match(/../gu) ?? [], pair => Number.parseInt(pair, 16));
@@ -20,9 +21,54 @@ export async function readSignedRelease(text: string, publicKey: string): Promis
20
21
  if (!await crypto.subtle.verify({ name: 'Ed25519' }, key, hexBytes(signed.signature), new TextEncoder().encode(signed.body))) throw new Error('A release file has a bad signature');
21
22
  return v.parse(ReleaseSchema, JSON.parse(signed.body));
22
23
  }
23
- /** The release file at `url`, never from a cache: a stale one would dial an old address. */
24
- export async function fetchSignedRelease(url: string, publicKey: string): Promise<ReleaseFile> {
25
- const response = await fetch(url, { cache: 'no-store' });
26
- if (!response.ok) throw new Error(`No release file at ${url}: ${String(response.status)}`);
27
- return readSignedRelease(await response.text(), publicKey);
24
+ /** FM5 (catalogue mode 11): a release read that has not answered, body and all, in 8 s has failed. */
25
+ export const RELEASE_DEADLINE_MS = 8000;
26
+ /** OFFLINE OF4: how long a verified release file is kept for a page that can't read a fresh one (the recommended limit; reversible). */
27
+ export const KEPT_RELEASE_MS: number = 7 * 24 * 60 * 60 * 1000;
28
+
29
+ /** The release file at `url`, never from a cache: a stale one would dial an old address. It throws past `deadlineMs`. */
30
+ export async function fetchSignedRelease(url: string, publicKey: string, deadlineMs: number = RELEASE_DEADLINE_MS, read: typeof fetch = fetch): Promise<ReleaseFile> {
31
+ return readSignedRelease(await fetchReleaseText(url, deadlineMs, read), publicKey);
32
+ }
33
+ async function fetchReleaseText(url: string, deadlineMs: number, read: typeof fetch): Promise<string> {
34
+ const abort = new AbortController(), scope = new Scope('online.release-read');
35
+ scope.timeout(deadlineMs, () => { abort.abort(); });
36
+ try {
37
+ const response = await read(url, { cache: 'no-store', signal: abort.signal });
38
+ if (!response.ok) throw new Error(`No release file at ${url}: ${String(response.status)}`);
39
+ return await response.text();
40
+ } catch (error) {
41
+ if (abort.signal.aborted) throw new Error(`No release file at ${url} in ${String(deadlineMs)} ms`, { cause: error });
42
+ throw error;
43
+ } finally { scope.dispose(); }
44
+ }
45
+
46
+ /** OF4: the last release file a page read and believed: which release, when, and its text as signed. */
47
+ export interface KeptRelease { readonly of: string; readonly at: number; readonly text: string }
48
+ export interface ReleaseKeep { readonly read: () => KeptRelease | null; readonly write: (kept: KeptRelease) => void }
49
+
50
+ /** The kept copy, only if it is this release's, no older than 7 days and its signature holds again now. Anything else is no copy. */
51
+ export async function keptRelease(url: string, publicKey: string, keep: ReleaseKeep, now: number = Date.now()): Promise<ReleaseFile | null> {
52
+ try {
53
+ const kept = keep.read(), age = kept === null ? -1 : now - kept.at;
54
+ if (kept?.of !== url || age < 0 || age > KEPT_RELEASE_MS) return null;
55
+ return await readSignedRelease(kept.text, publicKey);
56
+ } catch { return null; }
57
+ }
58
+
59
+ /** What a page dials from: the file, and when that was the kept copy, the fresh read still under way (null if it fails). */
60
+ export interface ReleaseToDial { readonly file: ReleaseFile; readonly fresh: Promise<ReleaseFile | null> | null }
61
+ /** OF4: the release file a page dials from. A verified kept copy answers at once, so a load never waits on the read; the fresh read
62
+ * replaces it once its own signature holds. With no copy the page waits for the read (8 s at most), and a failed read throws. */
63
+ export async function releaseToDial(url: string, publicKey: string, ports: { readonly keep: ReleaseKeep; readonly fetch?: typeof fetch; readonly now?: () => number; readonly deadlineMs?: number }): Promise<ReleaseToDial> {
64
+ const now = ports.now ?? Date.now, kept = await keptRelease(url, publicKey, ports.keep, now());
65
+ const reading = (async (): Promise<ReleaseFile> => {
66
+ const text = await fetchReleaseText(url, ports.deadlineMs ?? RELEASE_DEADLINE_MS, ports.fetch ?? fetch), file = await readSignedRelease(text, publicKey);
67
+ // a release only moves forward (J179, the server's own rule in releaseFile.ts): an older signed file never replaces the kept one
68
+ if (kept !== null && file.serial < kept.serial) throw new Error(`A release file older than the kept one (${String(file.serial)} < ${String(kept.serial)})`);
69
+ try { ports.keep.write({ of: url, at: now(), text }); } catch { /* a page that can keep nothing reads again next time */ }
70
+ return file;
71
+ })();
72
+ if (kept === null) return { file: await reading, fresh: null };
73
+ return { file: kept, fresh: reading.catch(() => null) };
28
74
  }
@@ -16,8 +16,7 @@ import { dropTabArrival, setTitleArrival } from '@wildshard/engine/boot/titleArr
16
16
  import { chatLines } from './chatLines';
17
17
  import { VoiceChat, type VoiceHeard, type VoiceLink } from './voice';
18
18
  import { voiceUi } from './voiceUi';
19
- import { jsonSlot, type Json } from '@wildshard/engine/saves/slots';
20
- import { fetchSignedRelease } from './release';
19
+ import { fetchSignedRelease, releaseToDial, type ReleaseKeep } from './release';
21
20
  import { newBuildPanel } from './reconnectStrip';
22
21
  import { linkScreens } from './linkScreens';
23
22
 
@@ -32,6 +31,8 @@ export interface SeatPlace { readonly x: number; readonly y: number; readonly z:
32
31
  export interface OnlineConfig {
33
32
  /** The address the release file names. */
34
33
  readonly socket: string;
34
+ /** OF4: the address each later dial takes, when a fresh release file can name another after the first dial. */
35
+ readonly address?: () => string;
35
36
  /** This page's build: the door refuses another one (J54). */
36
37
  readonly build: string;
37
38
  /** The cell this page has loaded. */
@@ -125,7 +126,8 @@ export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShe
125
126
  const first = hear(new WebSocketTransport(config.socket)), client = new NetClient(first);
126
127
  const records=config.record===undefined?undefined:new NetRecords(client,{...config.record,build:config.build,level:config.loaded,
127
128
  correction:(row:NetCorrection)=>{if(playtest)link?.control('playtest',new TextEncoder().encode(JSON.stringify(row)).buffer);}});
128
- const redial = new Redial({ client, transport: first, dial: () => {playtest=false;return hear(new WebSocketTransport(config.socket));}, onState: (state,reason)=>{records?.link(state);view.link(state,reason);}, onCause: cause => { view.link(redial.told, cause); }, onCut: reason => { view.cut?.(reason); } });
129
+ const address = config.address ?? ((): string => config.socket);
130
+ const redial = new Redial({ client, transport: first, dial: () => {playtest=false;return hear(new WebSocketTransport(address()));}, onState: (state,reason)=>{records?.link(state);view.link(state,reason);}, onCause: cause => { view.link(redial.told, cause); }, onCut: reason => { view.cut?.(reason); } });
129
131
  // A held seat comes straight back with no `resume`: a tab reloaded inside J114's 30 s.
130
132
  // GO4: on a grid page, a held seat in another cell than the page booted re-enters the grid there, as a `resume` would say.
131
133
  const offFirst = client.onFrame(() => {
@@ -148,7 +150,7 @@ export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShe
148
150
  const say = (again: boolean): Promise<void> => {
149
151
  let quitting = link;
150
152
  // A retry always dials: the link it follows is closed, whether or not `hear` was watching it.
151
- if (quitting === null || down || !again) { quitting = new WebSocketTransport(config.socket); link = quitting; down = false; client.rejoin(quitting); }
153
+ if (quitting === null || down || !again) { quitting = new WebSocketTransport(address()); link = quitting; down = false; client.rejoin(quitting); }
152
154
  const gone = new Promise<void>(resolve => { quitting.onClose(reason => { if (again && reason === 'stalled') void say(false).then(resolve); else resolve(); }); });
153
155
  quitting.control('ready', new Uint8Array([LEAVE_FLAG]).buffer);
154
156
  return gone;
@@ -188,6 +190,9 @@ export interface StartOnline {
188
190
  readonly goto?: boolean };
189
191
  /** The signed release file, and the key that signed it. */
190
192
  readonly release: string; readonly key: string;
193
+ /** OF4: where the page keeps the last verified release file. The page's own saves hold it: this bundle's saves have no storage, and
194
+ * a second store writing the page's device save would drop the keys it doesn't define. */
195
+ readonly keep?: ReleaseKeep;
191
196
  readonly recordTag?:string;
192
197
  }
193
198
  /** E7.5 prep: ask the page to leave for the Connection doctor, saying which screen asked. The page's own bundle answers
@@ -207,21 +212,30 @@ export function gotoSocket(socket: string, cell: string | undefined): string {
207
212
  const asking = new Map<string, { word: Promise<unknown>; done: number | null }>();
208
213
  /** How long a page answers from a read that heard nothing before it dials again. */
209
214
  const SILENT_KEEP_MS = 10_000;
210
- /** GO4 gate: whether the world this build names hosts the grid, by `hosts` on the door's word (`worldWord`). Any failure answers false,
211
- * and the grid page keeps today's solo grid. A word is kept a minute, a no as well as a yes, so a `WORLD_CELLS` change reaches a tab
215
+ /** opus-wordkeep: the word a page heard, which release and when. */
216
+ export interface KeptWord { readonly of: string; readonly at: number; readonly word: unknown }
217
+ /** Where a page keeps the word it heard. This bundle's save store has no storage (OF4), so a keep here would die with the page: the
218
+ * page lends its own (`oneWayIn.ts`, its `gridGate` session save). */
219
+ export interface WordKeep { readonly read: () => KeptWord | null; readonly write: (kept: KeptWord) => void }
220
+ /** A caller that lends no keep keeps the word for this module realm only. */
221
+ let realmWord: KeptWord | null = null;
222
+ const REALM_WORD: WordKeep = { read: () => realmWord, write: kept => { realmWord = kept; } };
223
+ /** GO4 gate: whether the world this build names hosts the grid, by `hosts` on the door's word (`worldWord`). Any failure answers false.
224
+ * No page picks its server by it any more (OFFLINE OF2: a world build's pages all go online). A word is kept a minute, a no as well as a yes, so a `WORLD_CELLS` change reaches a tab
212
225
  * within that minute. */
213
- export async function worldHostsGrid(config: { readonly release: string; readonly key: string }, hosts: (world: unknown) => boolean, waitMs = 3000): Promise<boolean> {
214
- const word = await worldWord(config, waitMs);
226
+ export async function worldHostsGrid(config: { readonly release: string; readonly key: string }, hosts: (world: unknown) => boolean, waitMs = 3000, keep: WordKeep = REALM_WORD): Promise<boolean> {
227
+ const word = await worldWord(config, waitMs, keep);
215
228
  try { return word !== null && hosts(word); } catch { return false; }
216
229
  }
217
230
  /** GO4, opus-route2: the door's first word (`world`: its cell count and the shard each cell runs), or null when none came in `waitMs`.
218
231
  * The release names the address; a socket there hears the word and closes before any hello, so no seat is taken. Not `/health`: D7
219
232
  * keeps that off the rooms address (a 404 with no CORS), and only loopback answers it. */
220
- export async function worldWord(config: { readonly release: string; readonly key: string }, waitMs = 3000): Promise<unknown> {
233
+ export async function worldWord(config: { readonly release: string; readonly key: string }, waitMs = 3000, keep: WordKeep = REALM_WORD): Promise<unknown> {
221
234
  // The title, a `?chunk=` page, the grid page and a one-shard page each ask within seconds, and every socket counts against the door's
222
- // 10 a minute per address: a tab keeps the word it heard for a minute. No word is asked again on the next page, since a stall or a
223
- // blip says nothing; within one page, a read under way or one that just heard nothing answers the next, so a page waits once.
224
- const kept = keptWord(config.release);
235
+ // 10 a minute per address: a tab keeps the word it heard for a minute, in the page's keep (`keep`, opus-wordkeep). No word is asked
236
+ // again on the next page, since a stall or a blip says nothing; within one page, a read under way or one that just heard nothing
237
+ // answers the next, so a page waits once.
238
+ const kept = keptWord(keep, config.release);
225
239
  if (kept !== null) return kept;
226
240
  const asked = asking.get(config.release);
227
241
  if (asked !== undefined && (asked.done === null || Math.abs(Date.now() - asked.done) < SILENT_KEEP_MS)) return asked.word;
@@ -229,24 +243,18 @@ export async function worldWord(config: { readonly release: string; readonly key
229
243
  asking.set(config.release, read);
230
244
  const word = await read.word;
231
245
  read.done = Date.now();
232
- if (word !== null) keepWord(config.release, word);
246
+ if (word !== null) { try { keep.write({ of: config.release, at: Date.now(), word }); } catch { /* a page that can keep nothing asks again */ } }
233
247
  return word;
234
248
  }
235
249
  const GATE_KEEP_MS = 60_000;
236
- /** The tab's kept word (a session save), made on first use so a page that never asks defines nothing. The release is under `of`, not
237
- * `release`: an older build in the same tab kept only a yes there and reads any fresh `release` entry as one. */
238
- const gateSlot = (): ReturnType<typeof jsonSlot> => jsonSlot('gridGate', 'session');
239
- function keptWord(release: string): unknown {
250
+ /** A page that lends no keep reads the release file every time. */
251
+ const NO_KEEP: ReleaseKeep = { read: () => null, write: () => undefined };
252
+ function keptWord(keep: WordKeep, release: string): unknown {
240
253
  try {
241
- const kept = gateSlot().read();
242
- const fresh = typeof kept === 'object' && kept !== null && !Array.isArray(kept) && kept['of'] === release && typeof kept['at'] === 'number' && Math.abs(Date.now() - kept['at']) < GATE_KEEP_MS;
243
- return fresh ? kept['word'] ?? null : null;
254
+ const kept = keep.read();
255
+ return kept !== null && kept.of === release && Math.abs(Date.now() - kept.at) < GATE_KEEP_MS ? kept.word ?? null : null;
244
256
  } catch { return null; }
245
257
  }
246
- /** A word is parsed JSON, so it keeps as it came. */
247
- function keepWord(release: string, word: unknown): void {
248
- try { gateSlot().write({ of: release, at: Date.now(), word: word as Json }); } catch { /* a page that can keep nothing asks again */ }
249
- }
250
258
  async function askWorld(config: { readonly release: string; readonly key: string }, waitMs: number): Promise<unknown> {
251
259
  // One deadline over the release file and the socket: a stall in either must not hold the page.
252
260
  const scope = new Scope('online.grid-gate'), late = new Promise<null>(resolve => { scope.timeout(waitMs, () => { resolve(null); }); });
@@ -269,13 +277,17 @@ async function askWorld(config: { readonly release: string; readonly key: string
269
277
 
270
278
  /** Enter the one world this build names. A stale tab reloads into the server's build once, and only then gives up. */
271
279
  export async function startOnline(config: StartOnline): Promise<OnlineShell> {
272
- const { release: at, key, identity, recordTag, grid, ...link } = config, release = await fetchSignedRelease(at, key), { socket } = release;
280
+ // OF4: a verified kept release file dials at once (offline too), and the fresh read follows; with none, the page waits for the read
281
+ const { release: at, key, keep, identity, recordTag, grid, ...link } = config, { file: release, fresh } = await releaseToDial(at, key, { keep: keep ?? NO_KEEP }), { socket } = release;
273
282
  // QA row 16: a level page enters only from a tap. A reload this page makes itself carries the tap that brought it here.
274
283
  const entering = (slug: string): void => { setTitleArrival({ slug, mode: 'enter' }, { tab: true }); };
275
284
  const stale = async (): Promise<boolean> => { entering(link.loaded); const going = await reloadStale(); if (!going) dropTabArrival(); return going; };
276
- if (release.engineBuild !== link.build) await stale();
285
+ // only a fresh read says the world moved on: a kept copy's build is the past, and an offline page can't reload anyway
286
+ if (fresh === null && release.engineBuild !== link.build) await stale();
277
287
  if (socket === undefined) throw new Error('The release file names no address');
278
288
  const scope = new Scope('online.page');
289
+ const goto = grid?.goto === true ? grid.cell : undefined;
290
+ let dialing = socket;
279
291
  // MP2.4: the page asked for the Name before it got here (namePrompt.ts, once per device); Skip keeps the device's own (Guest)
280
292
  const named = identity();
281
293
  let shellNow: OnlineShell | null = null, waitingForSeat = false;
@@ -290,7 +302,7 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
290
302
  // `reload` is the one ending a screen doesn't answer: the page reloads into the world's build, once (J174)
291
303
  const ended = async (): Promise<void> => { if (!await stale()) newBuildPanel(scope, stale, () => { entering(link.loaded); void reloadByHand(); }); };
292
304
  const telemetry=onlineTelemetry(),tag=recordTag??release.channel;
293
- const shell = connectOnline({ ...link, ...(grid === undefined ? {} : { gridCell: grid.cell, gridCells: grid.cells }), socket: gotoSocket(socket, grid?.goto === true ? grid.cell : undefined), identity: named,record:{install:telemetry.install,session:crypto.randomUUID(),send:telemetry.send,...(tag===undefined?{}:{tag})} }, {
305
+ const shell = connectOnline({ ...link, ...(grid === undefined ? {} : { gridCell: grid.cell, gridCells: grid.cells }), socket: gotoSocket(socket, goto), address: () => gotoSocket(dialing, goto), identity: named,record:{install:telemetry.install,session:crypto.randomUUID(),send:telemetry.send,...(tag===undefined?{}:{tag})} }, {
294
306
  link: (state, reason) => { waitingForSeat = state === 'full'; screens.link(state, reason); if (state === 'ended' && reason === 'reload') void ended(); },
295
307
  // The cut (5.5): an old server refused a v1 hello. Reload only into another build; on this one, the server is updating.
296
308
  cut: () => { void reloadStale(); },
@@ -301,6 +313,15 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
301
313
  elsewhere: seat => { entering(seat); const url = new URL(location.href); url.searchParams.set('chunk', seat); markUnload(`online seat elsewhere (${seat})`); location.replace(url); },
302
314
  });
303
315
  shellNow = shell;
316
+ // the fresh read behind a kept copy: another build reloads into it, as a fresh read before the dial would (two reloads share one
317
+ // durable claim, chunkRecovery.ts); another address takes the next dial: now if the link is down and waiting, else after the dial
318
+ // under way, or the player's Retry once the link has given up
319
+ void fresh?.then(read => {
320
+ if (read === null || scope.disposed) return undefined;
321
+ if (read.engineBuild !== link.build) return stale();
322
+ if (read.socket !== undefined && read.socket !== dialing) { dialing = read.socket; shell.dialNow(); }
323
+ return undefined;
324
+ });
304
325
  // a tap the world must hear waits for the link: the hold card says so, and the tap is never sent late
305
326
  shell.client.gateActions(what => screens.allow(what));
306
327
  void settled(shell.booted);
@@ -34,7 +34,7 @@ export interface StandaloneConfig {
34
34
  readonly identity?: NetIdentity;
35
35
  /** MP2.4: the Name the page keeps (the Name prompt), sent with this device's own id. Solo shows it only on this page. */
36
36
  readonly name?: string;
37
- /** A one-shard page: the server runs this cell alone, inside its own walls and with no road. */
37
+ /** A one-shard page: the server runs this cell alone, with no road and no walls (GC36). */
38
38
  readonly lone?: true;
39
39
  /** J311: a grid page's Shard select pick (a cell instance): the server starts the session in that cell. */
40
40
  readonly goto?: string;
@@ -99,7 +99,7 @@ export function connectStandalone(config: StandaloneConfig, control: MessagePort
99
99
  transport.onClose(reason => { if (reason === 'reload') config.refused?.(); });
100
100
  const post = (message: ShellMessage): void => { control.postMessage(v.parse(ShellMessageSchema, message), []); };
101
101
  const waits = new Map<number, (message: ServerMessage) => void>();
102
- let held = false, requests = 0, booted: (value: { tick: number; restored: boolean }) => void = () => undefined, failed: (reason: Error) => void = () => undefined;
102
+ let held = false, disposed = false, requests = 0, booted: (value: { tick: number; restored: boolean }) => void = () => undefined, failed: (reason: Error) => void = () => undefined;
103
103
  const bootPromise = new Promise<{ tick: number; restored: boolean }>((resolve, reject) => { booted = resolve; failed = reject; });
104
104
  const request = <T>(send: (id: number) => ShellMessage, read: (message: ServerMessage) => T | null): Promise<T> => new Promise(resolve => {
105
105
  const id = ++requests;
@@ -111,7 +111,11 @@ export function connectStandalone(config: StandaloneConfig, control: MessagePort
111
111
  if (value === null) workerDocuments.delete(key); else workerDocuments.set(key, value);
112
112
  post({ kind: 'written', seq, ok: await (config.write?.(key, merged) ?? applyWrite(config.storage, key, merged)) });
113
113
  };
114
+ // EV5: a port can still hand over what the worker posted before `dispose`, such as a progress save's write. That session
115
+ // is over: its write would land in storage the next session already read, beside saves that session can't see, and its
116
+ // world's tick could outrank the next session's save. The page drops it, as a reload drops a terminated worker's.
114
117
  control.onmessage = (event: MessageEvent<unknown>): void => {
118
+ if (disposed) return;
115
119
  const message = v.parse(ServerMessageSchema, event.data);
116
120
  if (message.kind === 'booted') { bootMark('server:booted-receive'); booted({ tick: message.tick, restored: message.restored }); bootMark('server:hello-send'); client.hello(config.build, config.identity ?? deviceIdentity(config.storage, config.savePrefix, config.name)); }
117
121
  else if (message.kind === 'write') void write(message.seq, message.key, message.value);
@@ -138,7 +142,7 @@ export function connectStandalone(config: StandaloneConfig, control: MessagePort
138
142
  second.hello(config.build, { player: id, name: id });
139
143
  return { client: second, move: (mx, my, mz) => { harness?.postMessage({ move: id, x: mx, y: my, z: mz, yaw: 0 } satisfies HarnessMove, []); } };
140
144
  },
141
- dispose: () => { scope.dispose(); client.dispose(); transport.close('disposed'); control.close(); end(); } };
145
+ dispose: () => { disposed = true; scope.dispose(); client.dispose(); transport.close('disposed'); control.close(); end(); } };
142
146
  }
143
147
 
144
148
  /** Start the standalone target: the server always in a module worker, with no main-thread fallback (J49). */