@wildshard/engine 0.1.15 → 0.1.18

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 (262) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/index.html +157 -11
  3. package/lint/engine-sides.json +23 -0
  4. package/lint/host-callback-syntax.mjs +2 -1
  5. package/lint/host-callbacks.mjs +3 -3
  6. package/lint/host-files.mjs +5 -4
  7. package/lint/host-register.json +496 -0
  8. package/lint/no-base64.mjs +3 -1
  9. package/lint/ratchet.json +2 -2
  10. package/lint/shard-imports.d.mts +1 -0
  11. package/lint/shard-imports.mjs +60 -13
  12. package/lint/shard-source.d.mts +9 -0
  13. package/lint/shard-source.mjs +91 -0
  14. package/lint/shardfile-boundaries.mjs +10 -8
  15. package/lint/sim-closure.mjs +6 -3
  16. package/lint/wildshard-plugin.d.ts +4 -0
  17. package/lint/wildshard-plugin.js +44 -27
  18. package/package.json +24 -6
  19. package/scripts/app-build/buildIdentity.d.mts +3 -1
  20. package/scripts/app-build/buildIdentity.mjs +25 -5
  21. package/scripts/app-build/builtAt.d.mts +4 -0
  22. package/scripts/app-build/builtAt.mjs +21 -0
  23. package/scripts/app-build/outputProducts.d.mts +3 -0
  24. package/scripts/app-build/outputProducts.mjs +31 -0
  25. package/scripts/app-build/serviceWorker.ts +16 -2
  26. package/scripts/app-build/versionFiles.ts +2 -1
  27. package/scripts/app-build-pipeline.mjs +7 -1
  28. package/scripts/audio-download-proof.mjs +843 -0
  29. package/scripts/build-app.mjs +4 -0
  30. package/scripts/build-mirror.d.mts +2 -0
  31. package/scripts/build-mirror.mjs +5 -4
  32. package/scripts/built-product.mjs +3 -3
  33. package/scripts/cell-mem/metrics-preload.mjs +65 -0
  34. package/scripts/cell-mem-bench.mjs +130 -0
  35. package/scripts/check-chunks.mjs +2 -1
  36. package/scripts/check-devserver.mjs +1 -1
  37. package/scripts/chromium-keychain-check.mjs +4 -2
  38. package/scripts/chromium-keychain.mjs +3 -1
  39. package/scripts/cook.mjs +7 -3
  40. package/scripts/devices.d.mts +4 -0
  41. package/scripts/devices.mjs +39 -0
  42. package/scripts/devserver-client.d.mts +7 -0
  43. package/scripts/devserver-client.mjs +85 -0
  44. package/scripts/doctor-proof.mjs +1 -1
  45. package/scripts/e2e-faults.mjs +159 -0
  46. package/scripts/engine-ci-budget.ts +7 -1
  47. package/scripts/format-lock.mjs +20 -11
  48. package/scripts/generate-title-launch.mjs +3 -2
  49. package/scripts/grid-crossing-walk-proof.mjs +30 -11
  50. package/scripts/heavy-lane.py +25 -1
  51. package/scripts/host-ruler/register-migrate.mjs +242 -0
  52. package/scripts/host-ruler/register.d.mts +36 -0
  53. package/scripts/host-ruler/register.mjs +116 -0
  54. package/scripts/host-ruler/roots.d.mts +29 -0
  55. package/scripts/host-ruler/roots.mjs +333 -0
  56. package/scripts/host-ruler/server-roots.d.mts +23 -0
  57. package/scripts/host-ruler/server-roots.mjs +272 -0
  58. package/scripts/main-watch.d.mts +1 -1
  59. package/scripts/main-watch.mjs +10 -6
  60. package/scripts/map-hash.mjs +3 -6
  61. package/scripts/memory-proof.mjs +158 -0
  62. package/scripts/mmo-bots.mjs +2 -2
  63. package/scripts/offline-proof-rules.d.mts +5 -2
  64. package/scripts/offline-proof-rules.mjs +43 -6
  65. package/scripts/offline-proof.mjs +15 -6
  66. package/scripts/online-rig.mjs +4 -4
  67. package/scripts/page-release/flow.d.mts +1 -0
  68. package/scripts/page-release/flow.mjs +6 -2
  69. package/scripts/page-release.mjs +5 -1
  70. package/scripts/physics-route.json +0 -71
  71. package/scripts/pins-catalogue.ts +103 -0
  72. package/scripts/pins-reuse.mjs +3 -1
  73. package/scripts/pins.ts +22 -14
  74. package/scripts/preview-grid.ts +203 -0
  75. package/scripts/road-preload-proof.mjs +167 -0
  76. package/scripts/server-release/publish.mjs +2 -2
  77. package/scripts/server-release/served-slug.d.mts +2 -0
  78. package/scripts/server-release/served-slug.mjs +10 -0
  79. package/scripts/server-release/sign.d.mts +1 -0
  80. package/scripts/server-release/sign.mjs +3 -7
  81. package/scripts/shard-components.mjs +0 -2
  82. package/scripts/shard-outputs.d.mts +8 -0
  83. package/scripts/shard-outputs.mjs +45 -11
  84. package/scripts/side-parity.d.mts +2 -1
  85. package/scripts/side-parity.mjs +25 -4
  86. package/scripts/test-amber.d.mts +1 -0
  87. package/scripts/test-amber.mjs +10 -0
  88. package/scripts/test-products.json +3 -3
  89. package/scripts/tier-textures-proof.mjs +101 -0
  90. package/scripts/tier-textures.mjs +60 -0
  91. package/scripts/tracked-public.d.mts +1 -0
  92. package/scripts/tracked-public.mjs +17 -0
  93. package/scripts/tsconfig.json +1 -0
  94. package/scripts/vps/wildshard-config +79 -23
  95. package/scripts/worker-client-play.mjs +1 -0
  96. package/scripts/worker-client-proof.mjs +1 -1
  97. package/scripts/worker-client-slug.mjs +44 -0
  98. package/src/cli/engine.mjs +8 -0
  99. package/src/client/app/bootRoute.ts +4 -1
  100. package/src/client/app/dropModal.ts +15 -2
  101. package/src/client/app/entry.ts +96 -13
  102. package/src/client/app/slugPath.ts +5 -0
  103. package/src/client/engine/audio/Audio.ts +20 -2
  104. package/src/client/engine/boot/bakedTextures.ts +3 -2
  105. package/src/client/engine/boot/bootTrace.ts +6 -1
  106. package/src/client/engine/boot/bytes.ts +4 -3
  107. package/src/client/engine/boot/clearDownloads.ts +1 -1
  108. package/src/client/engine/boot/contentRead.ts +4 -0
  109. package/src/client/engine/boot/dropNotice.ts +20 -6
  110. package/src/client/engine/boot/gpuFiles.ts +25 -2
  111. package/src/client/engine/boot/lastEnd.ts +8 -2
  112. package/src/client/engine/boot/parsedPages.ts +127 -58
  113. package/src/client/engine/boot/shardPrefetch.ts +7 -1
  114. package/src/client/engine/boot/sw.ts +19 -0
  115. package/src/client/engine/build.d.ts +2 -0
  116. package/src/client/engine/core/Game.ts +29 -3
  117. package/src/client/engine/core/GpuRecovery.ts +7 -0
  118. package/src/client/engine/core/Volumetrics.ts +5 -0
  119. package/src/client/engine/core/assets.ts +27 -20
  120. package/src/client/engine/core/bootstrap.ts +5 -3
  121. package/src/client/engine/core/ktx2.ts +84 -11
  122. package/src/client/engine/debug/probe.ts +18 -1
  123. package/src/client/engine/explore/Compare.ts +2 -2
  124. package/src/client/engine/explore/TouchFly.ts +3 -5
  125. package/src/client/engine/fx/LightPool.ts +41 -1
  126. package/src/client/engine/input/dom.ts +12 -0
  127. package/src/client/engine/net/predictor.ts +6 -2
  128. package/src/client/engine/player/Player.ts +10 -2
  129. package/src/client/engine/player/TouchControls.ts +12 -4
  130. package/src/client/engine/pwa/sw.js +59 -11
  131. package/src/client/engine/render/drawCheck.ts +96 -0
  132. package/src/client/engine/render/precompile.ts +20 -14
  133. package/src/client/engine/saves/staleBuildNote.ts +46 -0
  134. package/src/client/engine/telemetry/browserErrors.ts +161 -21
  135. package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
  136. package/src/client/engine/telemetry/screenOutbox.ts +61 -0
  137. package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
  138. package/src/client/engine/ui/DeathFade.ts +99 -11
  139. package/src/client/engine/ui/ErrorModal.ts +13 -6
  140. package/src/client/engine/ui/Feedback.ts +2 -1
  141. package/src/client/engine/ui/Loading.ts +10 -6
  142. package/src/client/engine/ui/Map.ts +2 -1
  143. package/src/client/engine/ui/WeaponStrip.ts +2 -1
  144. package/src/client/engine/ui/backGuard.ts +104 -0
  145. package/src/client/engine/ui/hudAdapters.ts +30 -4
  146. package/src/client/engine/ui/loading.css +17 -0
  147. package/src/client/engine/ui/namePrompt.ts +6 -5
  148. package/src/client/engine/ui/styles/combat.css +12 -0
  149. package/src/client/engine/ui/styles/namePrompt.css +4 -2
  150. package/src/client/game/boot/audio.generated.ts +0 -396
  151. package/src/client/game/boot/bytes.generated.ts +42 -71
  152. package/src/client/game/boot/versions.generated.ts +0 -13
  153. package/src/client/game/compendium/keepsakes.ts +16 -6
  154. package/src/client/game/grapple/tool.ts +10 -7
  155. package/src/client/game/grid/area.ts +38 -0
  156. package/src/client/game/grid/cellLoading.ts +23 -12
  157. package/src/client/game/grid/cellScreens.ts +39 -74
  158. package/src/client/game/grid/live.ts +28 -2
  159. package/src/client/game/grid/liveSession.ts +54 -10
  160. package/src/client/game/grid/menu.ts +4 -0
  161. package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
  162. package/src/client/game/grid/nearPlaceholderView.ts +9 -3
  163. package/src/client/game/grid/neighbourPanels.ts +10 -1
  164. package/src/client/game/grid/oneWayIn.ts +92 -27
  165. package/src/client/game/grid/pageEntry.ts +19 -0
  166. package/src/client/game/grid/pageShell.ts +1 -1
  167. package/src/client/game/grid/placedCards.ts +55 -0
  168. package/src/client/game/grid/placedCells.ts +131 -0
  169. package/src/client/game/grid/plotAudio.ts +114 -0
  170. package/src/client/game/grid/products.ts +55 -5
  171. package/src/client/game/grid/regionalRuntime.ts +6 -0
  172. package/src/client/game/grid/regionalWorld.ts +15 -2
  173. package/src/client/game/grid/roadCull.ts +44 -14
  174. package/src/client/game/grid/roadLookPlatform.ts +2 -2
  175. package/src/client/game/grid/roadTileBacking.ts +13 -3
  176. package/src/client/game/grid/session.ts +47 -22
  177. package/src/client/game/grid/shardfileFar.ts +9 -3
  178. package/src/client/game/grid/spawnGround.ts +68 -0
  179. package/src/client/game/grid/voidLook.ts +29 -23
  180. package/src/client/game/loot/runtime.ts +3 -1
  181. package/src/client/game/mainMenu.ts +14 -6
  182. package/src/client/game/riding/hud.ts +6 -4
  183. package/src/client/game/session/finish.ts +22 -4
  184. package/src/client/game/session/play.ts +8 -2
  185. package/src/client/game/session/session.ts +4 -1
  186. package/src/client/game/shard/titleList.ts +6 -2
  187. package/src/client/game/shardfile/clientWorker.ts +43 -13
  188. package/src/client/game/shardfile/serverRoute.ts +10 -22
  189. package/src/client/game/slugPage.css +11 -0
  190. package/src/client/game/slugPage.ts +84 -0
  191. package/src/client/game/systems/viewmodel/heldView.ts +6 -3
  192. package/src/client/game/titleDeck.ts +56 -32
  193. package/src/client/host/online/doctor.ts +7 -6
  194. package/src/client/host/online/linkScreens.ts +16 -0
  195. package/src/client/host/online/release.ts +51 -5
  196. package/src/client/host/online/shell.ts +62 -27
  197. package/src/client/host/standalone/shell.ts +7 -3
  198. package/src/cook/game/audioReport.ts +57 -0
  199. package/src/cook/game/entryTotals.ts +26 -6
  200. package/src/cook/game/installedRuntimeReads.ts +3 -0
  201. package/src/cook/game/shardCook.ts +38 -8
  202. package/src/cook/game/tierTextures.ts +276 -0
  203. package/src/e2e/smoke/game.ts +19 -14
  204. package/src/e2e/smoke/page-globals.d.ts +9 -8
  205. package/src/e2e/smoke/template2.spec.ts +8 -7
  206. package/src/server/engine/sim/respawn.ts +6 -1
  207. package/src/server/engine/sim.ts +3 -0
  208. package/src/server/game/grid/simulation.ts +35 -0
  209. package/src/server/game/loot/harvest.ts +2 -0
  210. package/src/server/game/loot/keepsakeProgression.ts +40 -0
  211. package/src/server/game/loot/playerOwned.ts +5 -1
  212. package/src/server/game/plugin/simulation.ts +4 -0
  213. package/src/server/game/population/nativeBake.ts +2 -1
  214. package/src/server/game/quest/chapterRecords.ts +2 -0
  215. package/src/server/game/quest/serverChapters.ts +4 -0
  216. package/src/server/game/quest/serverDoors.ts +11 -5
  217. package/src/server/game/roomRespawn.ts +4 -0
  218. package/src/server/game/shardfile/installedSides.ts +18 -0
  219. package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
  220. package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
  221. package/src/server/host/bake/headlessWorker.ts +5 -1
  222. package/src/server/host/dedicated/cellHost.ts +98 -29
  223. package/src/server/host/dedicated/cellProtocol.ts +11 -1
  224. package/src/server/host/dedicated/cellWorker.ts +9 -3
  225. package/src/server/host/dedicated/crossing.ts +6 -2
  226. package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
  227. package/src/server/host/dedicated/gridCells.ts +52 -9
  228. package/src/server/host/dedicated/main.ts +31 -12
  229. package/src/server/host/dedicated/placementFile.ts +56 -0
  230. package/src/server/host/dedicated/releaseFile.ts +17 -10
  231. package/src/server/host/dedicated/roadRoom.ts +21 -5
  232. package/src/server/host/dedicated/socketTransport.ts +2 -1
  233. package/src/server/host/dedicated/workerTable.ts +13 -1
  234. package/src/server/host/dedicated/world.ts +111 -10
  235. package/src/server/host/headlessRuntime.ts +10 -5
  236. package/src/server/host/installers.ts +62 -0
  237. package/src/server/host/openWorld.ts +59 -0
  238. package/src/server/host/ropeDecks.ts +2 -0
  239. package/src/server/host/standalone/cellWorld.ts +25 -19
  240. package/src/server/host/standalone/fallFloor.ts +2 -2
  241. package/src/server/host/standalone/gridServer.ts +7 -4
  242. package/src/server/host/standalone/roadWorld.ts +41 -4
  243. package/src/shared/engine/audio/bootAudio.ts +33 -0
  244. package/src/shared/engine/level/spec.ts +3 -3
  245. package/src/shared/engine/net/acts.ts +3 -0
  246. package/src/shared/engine/net/deviceWord.ts +138 -0
  247. package/src/shared/engine/net/socketFrames.ts +7 -4
  248. package/src/shared/engine/physics/query.ts +27 -0
  249. package/src/shared/engine/physics/terrain.ts +19 -28
  250. package/src/shared/engine/saves/saves.lock.json +15 -0
  251. package/src/shared/engine/sim/actRoutes.ts +2 -0
  252. package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
  253. package/src/shared/game/grid/catalogue.ts +12 -5
  254. package/src/shared/game/grid/catalogueSlot.ts +18 -0
  255. package/src/shared/game/grid/farProxy.ts +6 -5
  256. package/src/shared/game/grid/pageMode.ts +1 -1
  257. package/src/shared/game/grid/placementRows.ts +33 -0
  258. package/src/shared/game/grid/roadLayout.ts +26 -3
  259. package/src/shared/game/grid/singleplayer.json +0 -13
  260. package/src/shared/game/grid/voidFloor.ts +122 -0
  261. package/src/shared/game/strings.ts +15 -0
  262. package/src/shared/host/standalone/netInput.ts +2 -1
@@ -0,0 +1,11 @@
1
+ /* ─── SA36: the `/slug/<slug>` page (src/client/game/slugPage.ts) ─── prefix ws-slug ───
2
+ Shard Select's restyled deck (mainMenu.css `.ws-menu-carousel`) with exactly one card: no thumbnail strip to pick from, and a
3
+ disabled PLAY (a slug with no grid cell, Jake's grill Q16) is dimmed with its "Not on the grid yet" line kept readable. */
4
+ .ws-menu.ws-slug .ws-menu-dots { display: none; }
5
+ .ws-menu.ws-slug .ws-menu-play:disabled { cursor: default; opacity: 1; border-color: rgba(143, 227, 255, 0.25); background: rgba(9, 22, 36, 0.78); box-shadow: none; }
6
+ .ws-menu.ws-slug .ws-menu-play:disabled b, .ws-menu.ws-slug .ws-menu-play:disabled .ws-menu-mode-glyph { opacity: 0.4; }
7
+ .ws-menu.ws-slug .ws-menu-play:disabled small { color: var(--ws-amber); opacity: 1; }
8
+ /* a phone keeps MAIN MENU and the build pill on the top row; the WILDSHARD word ran under the pill at 402 px */
9
+ @media (max-width: 480px) {
10
+ .ws-menu.ws-slug .ws-menu-title { display: none; }
11
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * SA36 (meta SHARD-AUTHORING-PLAN; Jake, grill 2026-11-12 Q14 to Q18): the `/slug/<slug>` page, the link a sharddev author shares
3
+ * with friends. "it's kind of like SHARD SELECT. But instead of being shard select it has exactly one shard, the slugName, and it
4
+ * has the hero image of it, and it will dynamically load that hero / slug / shard etc, and spawn you into the infinite grid there."
5
+ *
6
+ * const view = buildSlugPage({ manifest, placed, onEnter, onExplore, onSettings }) // a TitleDeckView for showStartTitle
7
+ *
8
+ * It is Shard Select's own deck (src/client/game/titleDeck.ts) holding that one card, dressed the same (mainMenu.css
9
+ * `.ws-menu-carousel`): the card, its hero behind, PLAY, SETTINGS. PLAY is ENTER WORLD: the same shardfile download, loading
10
+ * shell and `onEnter`, which src/client/app/entry.ts points at `travel`, so the next page enters the grid at the shard's cell
11
+ * exactly as a Shard select tap does (grid/oneWayIn.ts). A slug with no grid cell (not placed yet, `--no-place`, an off-grid
12
+ * shard such as Thin Ice) keeps its card and hero with PLAY disabled: "Not on the grid yet" (Q16). MAIN MENU leaves for `/`.
13
+ */
14
+ import { pageScope } from '@wildshard/engine/app/resources';
15
+ import { mobileDevice } from '@wildshard/engine/boot/titleArrival';
16
+ import { dropFirstPlay, firstPlayDone, startFirstPlay } from '@wildshard/engine/boot/firstPlayMark';
17
+ import { askNameOnce, nameAskDue } from '@wildshard/engine/ui/namePrompt';
18
+ import type { TitleDeckView } from '@wildshard/engine/ui/HUD';
19
+ import { buildTitleDeck, titleCard, type TitleCard, type TitleDeckOptions } from './titleDeck';
20
+ import type { TitleManifest } from './shard/titleList';
21
+ import { GAME_STRINGS } from '../../shared/game/strings';
22
+ import './mainMenu.css';
23
+ import './slugPage.css';
24
+
25
+ export interface SlugPageOptions extends Pick<TitleDeckOptions, 'onExplore' | 'onSettings' | 'notice' | 'mode'> {
26
+ /** the shard the link names (its title row) */
27
+ readonly manifest: TitleManifest;
28
+ /** the grid places this shard: PLAY enters it at its cell. False: PLAY is disabled, "Not on the grid yet" */
29
+ readonly placed: boolean;
30
+ /** PLAY, once the name is asked and the loading shell is up (the deck's ENTER WORLD) */
31
+ readonly onEnter: (card: TitleCard) => void;
32
+ }
33
+
34
+ /** One shard's page over Shard Select's deck. */
35
+ export function buildSlugPage(opts: SlugPageOptions): TitleDeckView {
36
+ const owner = pageScope.child('slug-page');
37
+ const s = GAME_STRINGS.slugPage;
38
+ const card = titleCard(opts.manifest);
39
+ // MG5 (as the main menu arms it): a phone's first play arms its first-play card for this shard; any other entry drops one
40
+ const phone = mobileDevice(navigator.userAgent, navigator.platform, navigator.maxTouchPoints);
41
+ // MMO-PLAN MP2.4 (as the main menu asks it): a device's first PLAY asks for the Name once, then enters
42
+ let naming = false;
43
+ const gate = (go: () => void): void => {
44
+ if (naming || !opts.placed) return; // a slug with no cell enters nothing, so it asks nothing
45
+ if (!nameAskDue()) { go(); return; }
46
+ naming = true;
47
+ void askNameOnce(owner, { parent: document.body }).then(answered => { naming = false; if (answered && !owner.disposed) go(); return undefined; },
48
+ () => { naming = false; });
49
+ };
50
+ const deck = buildTitleDeck({
51
+ cards: [card], active: null, onSettings: opts.onSettings, gate,
52
+ ...(opts.notice === undefined ? {} : { notice: opts.notice }), ...(opts.mode === undefined ? {} : { mode: opts.mode }),
53
+ single: { play: s.play, hint: s.placed, ...(opts.placed ? {} : { closed: s.unplaced }) },
54
+ onEnter: (entered) => { if (!(phone && !firstPlayDone() && startFirstPlay(entered.slug))) dropFirstPlay(); opts.onEnter(entered); },
55
+ onExplore: (entered) => { dropFirstPlay(); opts.onExplore(entered); },
56
+ });
57
+ deck.root.classList.add('ws-menu-carousel', 'ws-slug');
58
+ deck.root.dataset['slug'] = card.slug;
59
+ deck.root.dataset['placed'] = String(opts.placed);
60
+ const bar = document.createElement('div');
61
+ bar.className = 'ws-menu-bar';
62
+ const back = document.createElement('button');
63
+ back.type = 'button';
64
+ back.className = 'ws-menu-back';
65
+ back.textContent = s.menu;
66
+ const title = document.createElement('div');
67
+ title.className = 'ws-menu-title';
68
+ title.textContent = GAME_STRINGS.mainMenu.logo;
69
+ bar.append(back, title);
70
+ deck.root.querySelector('.ws-menu-head')?.prepend(bar);
71
+ deck.onTap(back, () => { location.assign('/'); });
72
+ const root = document.createElement('div');
73
+ root.className = 'ws-title-stack';
74
+ root.dataset['screen'] = 'slug';
75
+ root.append(deck.root);
76
+ return {
77
+ root, cards: deck.cards,
78
+ get index() { return deck.index; },
79
+ select: (i, smooth) => { deck.select(i, smooth); },
80
+ activate: () => { gate(() => { deck.activate(); }); },
81
+ start: () => { deck.start(); },
82
+ dispose: () => { owner.dispose(); deck.dispose(); },
83
+ };
84
+ }
@@ -5,7 +5,7 @@
5
5
  * its own look and the frame rows that write time, buffer size, pixel ratio and projection into the looks. Rows are
6
6
  * admitted before any rig, look or texture is borrowed; Model Explorer cards settle the same rigs. Client-only.
7
7
  */
8
- import { BackSide, type BufferGeometry, ClampToEdgeWrapping, DataTexture, DoubleSide, LinearMipmapLinearFilter, type Material, Mesh, NoColorSpace,
8
+ import { BackSide, type BufferGeometry, ClampToEdgeWrapping, CompressedTexture, DataTexture, DoubleSide, LinearMipmapLinearFilter, type Material, Mesh, NoColorSpace,
9
9
  type Object3D, type PerspectiveCamera, Quaternion, RedFormat, RepeatWrapping, SkinnedMesh, Texture, UnsignedByteType, Vector2, Vector3 } from 'three';
10
10
  import type { RigBake, RigContract } from '@wildshard/engine/anim/rig';
11
11
  import { retainCachedResources } from '@wildshard/engine/app/cachedAssets';
@@ -14,7 +14,7 @@ import { resourceScope } from '@wildshard/engine/app/resources';
14
14
  import { app } from '@wildshard/engine/app/runtime';
15
15
  import type { Scope } from '@wildshard/engine/app/scope';
16
16
  import { fetchImage, phoneUrl } from '@wildshard/engine/boot/bytes';
17
- import { ktx2Texture } from '@wildshard/engine/core/ktx2';
17
+ import { ktx2Texture, readHeldForm } from '@wildshard/engine/core/ktx2';
18
18
  import { loadTextureRow } from '@wildshard/engine/core/assets';
19
19
  import { SlashTrail } from '@wildshard/engine/combat/view/slashTrail';
20
20
  import type { ModelContext } from '@wildshard/engine/models/model';
@@ -82,7 +82,10 @@ function loadMap(path: string, anisotropy: number): Promise<Texture> {
82
82
  let loading = images.get(path);
83
83
  if (loading === undefined) {
84
84
  loading = (async () => {
85
- const value = await ktx2Texture(phoneUrl(path)) ?? new Texture(await fetchImage(path, Infinity, false));
85
+ // OF17: a form that fails to read gives way to the other when the cache holds it
86
+ const served = phoneUrl(path);
87
+ const read = await readHeldForm(served, tex => ktx2Texture(served, Infinity, tex), instead => fetchImage(path, Infinity, false, false, instead));
88
+ const value = read instanceof CompressedTexture ? read : new Texture(read);
86
89
  value.colorSpace = NoColorSpace; value.flipY = false; value.minFilter = LinearMipmapLinearFilter; value.anisotropy = anisotropy; value.needsUpdate = true;
87
90
  resolved.set(path, value);
88
91
  return retainCachedResources(value);
@@ -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, placedByFile, 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,41 @@ 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. A cell the page learned from its
86
+ // channel's placement file (`placedCells.ts`) has one: with crossing off, its card and `?chunk=` are the only ways in
87
+ const ordinary = titleManifests().filter(m => (m.shardSelect !== false && !autoPlaced(m)) || placedByFile(m));
80
88
  const visible = ordinary.filter((m) => !hidden(m));
81
89
  const manifests = showHidden ? [...visible, ...ordinary.filter(hidden)] : visible;
82
- return manifests.map((m): TitleCard => {
83
- const card: TitleCard = {
90
+ return manifests.map((m): TitleCard => titleCard(m, upgradeNeeded, refused, opens));
91
+ }
92
+
93
+ /** One shard's card, as Shard Select draws it; also the `/slug/<slug>` page's one card (SA36), which a shard with no Shard
94
+ * Select card (an open plot, an auto-placed shard) still gets. */
95
+ export function titleCard(m: TitleManifest, upgradeNeeded: UpgradeNeeded = noUpgrades, refused: RefusedShard = sessionRefusals, opens: OpensShard = buildWorld()): TitleCard {
96
+ const card: TitleCard = {
84
97
  slug: m.slug, name: m.name, label: m.biome,
85
98
  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
- });
99
+ };
100
+ const status = titleStatus(m);
101
+ if (status === 'earlyAccess') card.badge = 'Early access';
102
+ if (status === 'experimental') card.badge = 'Experimental';
103
+ if (status === 'partial') card.badge = 'Partial';
104
+ if (playerHidden(m)) card.badge = 'Developer only';
105
+ const built = upgradeNeeded(m.slug);
106
+ if (built !== null) card.upgrade = { built };
107
+ // OF3: a shard this world doesn't open never loads here, so no refusal of it is news
108
+ if (built === null && !opens(m.slug)) card.closed = true;
109
+ const refusal = built === null && card.closed === undefined ? refused(m.slug) : null; // G86's card already says NEEDS UPGRADE
110
+ if (refusal !== null) card.unavailable = refusal;
111
+ return card;
98
112
  }
99
113
 
100
114
  /** 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 +120,7 @@ interface DeckEntry {
106
120
  readonly badge?: TitleBadge | undefined;
107
121
  readonly upgrade?: { readonly built: number } | undefined;
108
122
  readonly unavailable?: ShardRefusal | undefined;
123
+ readonly closed?: true | undefined;
109
124
  readonly thumbnail: string;
110
125
  readonly heroPortrait: string;
111
126
  readonly heroLandscape: string;
@@ -130,6 +145,11 @@ export interface TitleDeckOptions {
130
145
  readonly notice?: string;
131
146
  /** what the menu may show and enter (default: Settings ▸ Developer and the DEVSERVER build, read live) */
132
147
  readonly mode?: () => MenuMode;
148
+ /** SA36: the `/slug/<slug>` page's one card. ENTER WORLD reads `play` over `hint`; `closed` (a slug with no grid cell)
149
+ * disables it and says why in the hint's place (Jake, grill Q16: the card and hero, Play disabled) */
150
+ readonly single?: { readonly play: string; readonly hint: string; readonly closed?: string };
151
+ /** runs on ENTER WORLD's tap before the entry (the slug page's first-play name ask); `go` enters */
152
+ readonly gate?: (go: () => void) => void;
133
153
  }
134
154
 
135
155
  export interface TitleDeck {
@@ -163,20 +183,21 @@ const restricted = (card: DeckEntry): boolean => card.badge === 'Developer only'
163
183
 
164
184
  /** ENTER WORLD for a card: Select a shard enters what §3.3's table allows in this mode (SF21a: shipped, Developer, DEVSERVER) */
165
185
  function canEnter(card: DeckEntry, mode: MenuMode = menuMode()): boolean {
166
- if (card.draft || card.upgrade !== undefined || card.unavailable !== undefined) return false;
186
+ if (card.draft || card.upgrade !== undefined || card.unavailable !== undefined || card.closed === true) return false;
167
187
  return selectEnters(card.slug, restricted(card), mode);
168
188
  }
169
189
 
170
190
  /** EXPLORE WORLD is a developer tool: only in developer mode (or a DEVSERVER build), and only for a world that can be
171
191
  * entered (Jake, E386) */
172
192
  function canExplore(card: DeckEntry, mode: MenuMode = menuMode()): boolean {
173
- return !card.draft && selectExplores(card.slug, restricted(card), mode);
193
+ // OF3: exploring joins the world too (OF2), which would seat a closed shard's page in another cell
194
+ return !card.draft && card.closed !== true && selectExplores(card.slug, restricted(card), mode);
174
195
  }
175
196
 
176
197
  /** the tape over a card's image: a world that can't be entered reads COMING SOON, not EXPERIMENTAL (Jake, E386) */
177
198
  function ribbonFor(card: DeckEntry, mode: MenuMode = menuMode()): string {
178
199
  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
200
+ if (card.upgrade !== undefined || card.unavailable !== undefined || card.closed === true) return ''; // G86 / G167 / OF3: the amber line says it, not a tape
180
201
  if (!canEnter(card, mode)) return 'Coming soon';
181
202
  return card.badge === 'Developer only' ? GAME_STRINGS.developer.ribbon : card.badge ?? '';
182
203
  }
@@ -202,7 +223,8 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
202
223
  const onTap = (el: HTMLElement, fn: () => void): void => { listenTap(scope, el, fn); };
203
224
  const { cards } = opts;
204
225
  // 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 : [];
226
+ // SA36: the slug page holds exactly its one card, Developer or not
227
+ const drafts = opts.single === undefined && (mode().developer || mode().devserver) ? DRAFT_TITLES : [];
206
228
  const entries: readonly DeckEntry[] = [...cards.map(fromShard), ...drafts.map(fromDraft)];
207
229
  const activeIndex = entries.map((card): string => card.slug).indexOf(opts.active ?? '');
208
230
  const root = document.createElement('div');
@@ -221,17 +243,18 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
221
243
  const cardTrack = required(root, '.ws-menu-deck-track'), dotTrack = required(root, '.ws-menu-dots');
222
244
  entries.forEach((card, index) => {
223
245
  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' : ''}`;
246
+ const dimmed = card.upgrade !== undefined || card.unavailable !== undefined || card.closed === true, amber = card.unavailable !== undefined || card.closed === true;
247
+ button.className = `ws-menu-card${active ? ' active' : ''}${dimmed ? ' ws-menu-card-upgrade' : ''}${amber ? ' ws-menu-card-unavailable' : ''}`;
225
248
  const image = document.createElement('span'); image.className = 'ws-menu-card-img'; image.style.backgroundImage = `url('${titleAssetURL(card.thumbnail)}')`;
226
249
  if (card.upgrade !== undefined) image.append(words('i', 'ws-menu-card-tag ws-menu-card-needs', GAME_STRINGS.upgrade.badge));
227
250
  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'));
251
+ if (canEnter(card, mode()) && opts.single?.closed === undefined) image.append(words('i', `ws-menu-card-tag${active ? ' ok' : ''}`, active ? 'Loaded' : 'Load'));
229
252
  // G238: the port badge, Developer on only (the public card is unchanged)
230
253
  const ribbon = ribbonFor(card, mode());
231
254
  const tone = !canEnter(card, mode()) ? '' : card.badge === 'Early access' ? ' ws-menu-card-ea' : card.badge === 'Partial' ? ' ws-menu-card-partial' : '';
232
255
  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);
256
+ 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;
257
+ button.append(image, words('b', '', card.name), words('small', amber ? 'ws-menu-card-reason' : '', sub)); cardTrack.append(button);
235
258
  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
259
  });
237
260
  if (opts.notice) {
@@ -286,11 +309,12 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
286
309
  // (a phone network, a busy page), the backdrop is the card's picture, never black (Jake's Pine Hollow, ab93dccfe)
287
310
  hero.style.backgroundImage = `url('${heroUrl(c)}'), url('${titleAssetURL(c.thumbnail)}')`;
288
311
  hero.classList.add('show');
289
- hint.textContent = hintFor(c, index === activeIndex, mode());
290
- play.disabled = !canEnter(c, mode()) && c.draft === null;
312
+ const open = canEnter(c, mode()), single = opts.single;
313
+ hint.textContent = single?.closed ?? (single === undefined || !open ? hintFor(c, index === activeIndex, mode()) : single.hint);
314
+ play.disabled = (!open && c.draft === null) || single?.closed !== undefined;
291
315
  explore.disabled = !canExplore(c, mode());
292
316
  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';
317
+ 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
318
  paintSummary(c);
295
319
  };
296
320
  const select = (raw: number, smooth = true): void => {
@@ -302,7 +326,7 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
302
326
  let entering = false;
303
327
  const enter = (c: DeckEntry): boolean => {
304
328
  if (entering) return false;
305
- if (c.shard === null || !canEnter(c, mode())) return false;
329
+ if (c.shard === null || !canEnter(c, mode()) || opts.single?.closed !== undefined) return false;
306
330
  const shard = c.shard;
307
331
  entering = true;
308
332
  startEntryDownload(c.slug); titlePrefetchChoice(saves).remember(c.slug);
@@ -323,7 +347,7 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
323
347
  listenDom(scope, list, 'pointerdown', (e) => {
324
348
  if (drag) return;
325
349
  drag = { id: e.pointerId, x0: e.clientX, t0: performance.now(), dx: 0 };
326
- list.setPointerCapture(e.pointerId);
350
+ capturePointer(list, e.pointerId);
327
351
  });
328
352
  listenDom(scope, list, 'pointermove', (e) => {
329
353
  if (!drag || e.pointerId !== drag.id) return;
@@ -343,7 +367,7 @@ export function buildTitleDeck(opts: TitleDeckOptions): TitleDeck {
343
367
  // a click that only follows the title's SHARD SELECT tap lands where that tap was, not on a card or dot (QC2)
344
368
  cardEls.forEach((e, i) => { listenDom(scope, e, 'click', (ev) => { ev.stopPropagation(); if (!followsTap(ev) && i !== index && performance.now() - swipedAt > 400) select(i); }); });
345
369
  dots.forEach((d, i) => { listenDom(scope, d, 'click', (ev) => { ev.stopPropagation(); if (!followsTap(ev)) select(i); }); });
346
- onTap(required(root, '.ws-menu-play'), () => { activate(); });
370
+ onTap(required(root, '.ws-menu-play'), () => { if (opts.gate === undefined) activate(); else opts.gate(() => { activate(); }); });
347
371
  onTap(required(root, '.ws-menu-explore'), () => { const c = entries[index]; if (c?.shard && canExplore(c, mode())) opts.onExplore(c.shard); });
348
372
  onTap(required(root, '.ws-menu-settings'), opts.onSettings);
349
373
  // 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
  }