@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
@@ -7,6 +7,7 @@ import { NetClient } from '@wildshard/engine/net/client';
7
7
  import type { NetIdentity } from '@wildshard/engine/net/identity';
8
8
  import { Redial, type LinkCause, type LinkProgress, type LinkState } from '@wildshard/engine/net/redial';
9
9
  import { decodeCountdown, type Countdown } from '@wildshard/engine/net/socketFrames';
10
+ import { encodeDeviceWord, worldReadsDevice } from '@wildshard/engine/net/deviceWord';
10
11
  import { WebSocketTransport } from '@wildshard/engine/net/webSocketTransport';
11
12
  import {NetRecords} from '@wildshard/engine/net/netRecord';
12
13
  import {onlineTelemetry} from '@wildshard/engine/telemetry/runtime';
@@ -16,8 +17,7 @@ import { dropTabArrival, setTitleArrival } from '@wildshard/engine/boot/titleArr
16
17
  import { chatLines } from './chatLines';
17
18
  import { VoiceChat, type VoiceHeard, type VoiceLink } from './voice';
18
19
  import { voiceUi } from './voiceUi';
19
- import { jsonSlot, type Json } from '@wildshard/engine/saves/slots';
20
- import { fetchSignedRelease } from './release';
20
+ import { fetchSignedRelease, releaseToDial, type ReleaseKeep } from './release';
21
21
  import { newBuildPanel } from './reconnectStrip';
22
22
  import { linkScreens } from './linkScreens';
23
23
 
@@ -32,6 +32,8 @@ export interface SeatPlace { readonly x: number; readonly y: number; readonly z:
32
32
  export interface OnlineConfig {
33
33
  /** The address the release file names. */
34
34
  readonly socket: string;
35
+ /** OF4: the address each later dial takes, when a fresh release file can name another after the first dial. */
36
+ readonly address?: () => string;
35
37
  /** This page's build: the door refuses another one (J54). */
36
38
  readonly build: string;
37
39
  /** The cell this page has loaded. */
@@ -89,6 +91,17 @@ export interface OnlineShell {
89
91
  dispose: () => void;
90
92
  }
91
93
 
94
+ /** DT3: how long a socket's device word waits for the renderer to name its GPU before it goes without it. */
95
+ const DEVICE_GPU_WAIT_MS = 10_000;
96
+ /** DT3: this page's device snapshot on `transport` (a closed one drops it). Telemetry: never throws, never holds the link. */
97
+ function sendDevice(transport: WebSocketTransport, build: string): void {
98
+ const send = async (): Promise<void> => {
99
+ const { deviceSnapshot } = await import('@wildshard/engine/telemetry/deviceSnapshot');
100
+ transport.control('device', encodeDeviceWord({ ...await deviceSnapshot(DEVICE_GPU_WAIT_MS), build }));
101
+ };
102
+ void send().catch(() => undefined);
103
+ }
104
+
92
105
  /** The link alone, with no page around it. `startOnline` is this with the strips. */
93
106
  export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShell {
94
107
  let playtest=false;
@@ -102,6 +115,8 @@ export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShe
102
115
  transport.onClose(() => { if (link === transport) down = true; });
103
116
  transport.onControl((control, bytes) => {
104
117
  if(control==='playtest'){playtest=true;return;}
118
+ // DEVICE-TELEMETRY DT3: a door whose first word says it reads the device word hears this page's snapshot, once per socket
119
+ if (control === 'world') { if (worldReadsDevice(bytes)) sendDevice(transport, config.build); return; }
105
120
  if (control === 'voice') {
106
121
  let word: VoiceHeard;
107
122
  try { word = JSON.parse(decoder.decode(bytes)) as VoiceHeard; } catch { return; }
@@ -125,7 +140,8 @@ export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShe
125
140
  const first = hear(new WebSocketTransport(config.socket)), client = new NetClient(first);
126
141
  const records=config.record===undefined?undefined:new NetRecords(client,{...config.record,build:config.build,level:config.loaded,
127
142
  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); } });
143
+ const address = config.address ?? ((): string => config.socket);
144
+ 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
145
  // A held seat comes straight back with no `resume`: a tab reloaded inside J114's 30 s.
130
146
  // 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
147
  const offFirst = client.onFrame(() => {
@@ -148,7 +164,7 @@ export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShe
148
164
  const say = (again: boolean): Promise<void> => {
149
165
  let quitting = link;
150
166
  // 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); }
167
+ if (quitting === null || down || !again) { quitting = new WebSocketTransport(address()); link = quitting; down = false; client.rejoin(quitting); }
152
168
  const gone = new Promise<void>(resolve => { quitting.onClose(reason => { if (again && reason === 'stalled') void say(false).then(resolve); else resolve(); }); });
153
169
  quitting.control('ready', new Uint8Array([LEAVE_FLAG]).buffer);
154
170
  return gone;
@@ -188,6 +204,9 @@ export interface StartOnline {
188
204
  readonly goto?: boolean };
189
205
  /** The signed release file, and the key that signed it. */
190
206
  readonly release: string; readonly key: string;
207
+ /** 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
208
+ * a second store writing the page's device save would drop the keys it doesn't define. */
209
+ readonly keep?: ReleaseKeep;
191
210
  readonly recordTag?:string;
192
211
  }
193
212
  /** E7.5 prep: ask the page to leave for the Connection doctor, saying which screen asked. The page's own bundle answers
@@ -207,21 +226,30 @@ export function gotoSocket(socket: string, cell: string | undefined): string {
207
226
  const asking = new Map<string, { word: Promise<unknown>; done: number | null }>();
208
227
  /** How long a page answers from a read that heard nothing before it dials again. */
209
228
  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
229
+ /** opus-wordkeep: the word a page heard, which release and when. */
230
+ export interface KeptWord { readonly of: string; readonly at: number; readonly word: unknown }
231
+ /** 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
232
+ * page lends its own (`oneWayIn.ts`, its `gridGate` session save). */
233
+ export interface WordKeep { readonly read: () => KeptWord | null; readonly write: (kept: KeptWord) => void }
234
+ /** A caller that lends no keep keeps the word for this module realm only. */
235
+ let realmWord: KeptWord | null = null;
236
+ const REALM_WORD: WordKeep = { read: () => realmWord, write: kept => { realmWord = kept; } };
237
+ /** GO4 gate: whether the world this build names hosts the grid, by `hosts` on the door's word (`worldWord`). Any failure answers false.
238
+ * 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
239
  * 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);
240
+ export async function worldHostsGrid(config: { readonly release: string; readonly key: string }, hosts: (world: unknown) => boolean, waitMs = 3000, keep: WordKeep = REALM_WORD): Promise<boolean> {
241
+ const word = await worldWord(config, waitMs, keep);
215
242
  try { return word !== null && hosts(word); } catch { return false; }
216
243
  }
217
244
  /** 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
245
  * 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
246
  * 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> {
247
+ export async function worldWord(config: { readonly release: string; readonly key: string }, waitMs = 3000, keep: WordKeep = REALM_WORD): Promise<unknown> {
221
248
  // 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);
249
+ // 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
250
+ // 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
251
+ // answers the next, so a page waits once.
252
+ const kept = keptWord(keep, config.release);
225
253
  if (kept !== null) return kept;
226
254
  const asked = asking.get(config.release);
227
255
  if (asked !== undefined && (asked.done === null || Math.abs(Date.now() - asked.done) < SILENT_KEEP_MS)) return asked.word;
@@ -229,24 +257,18 @@ export async function worldWord(config: { readonly release: string; readonly key
229
257
  asking.set(config.release, read);
230
258
  const word = await read.word;
231
259
  read.done = Date.now();
232
- if (word !== null) keepWord(config.release, word);
260
+ if (word !== null) { try { keep.write({ of: config.release, at: Date.now(), word }); } catch { /* a page that can keep nothing asks again */ } }
233
261
  return word;
234
262
  }
235
263
  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 {
264
+ /** A page that lends no keep reads the release file every time. */
265
+ const NO_KEEP: ReleaseKeep = { read: () => null, write: () => undefined };
266
+ function keptWord(keep: WordKeep, release: string): unknown {
240
267
  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;
268
+ const kept = keep.read();
269
+ return kept !== null && kept.of === release && Math.abs(Date.now() - kept.at) < GATE_KEEP_MS ? kept.word ?? null : null;
244
270
  } catch { return null; }
245
271
  }
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
272
  async function askWorld(config: { readonly release: string; readonly key: string }, waitMs: number): Promise<unknown> {
251
273
  // One deadline over the release file and the socket: a stall in either must not hold the page.
252
274
  const scope = new Scope('online.grid-gate'), late = new Promise<null>(resolve => { scope.timeout(waitMs, () => { resolve(null); }); });
@@ -269,13 +291,17 @@ async function askWorld(config: { readonly release: string; readonly key: string
269
291
 
270
292
  /** Enter the one world this build names. A stale tab reloads into the server's build once, and only then gives up. */
271
293
  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;
294
+ // OF4: a verified kept release file dials at once (offline too), and the fresh read follows; with none, the page waits for the read
295
+ const { release: at, key, keep, identity, recordTag, grid, ...link } = config, { file: release, fresh } = await releaseToDial(at, key, { keep: keep ?? NO_KEEP }), { socket } = release;
273
296
  // 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
297
  const entering = (slug: string): void => { setTitleArrival({ slug, mode: 'enter' }, { tab: true }); };
275
298
  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();
299
+ // 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
300
+ if (fresh === null && release.engineBuild !== link.build) await stale();
277
301
  if (socket === undefined) throw new Error('The release file names no address');
278
302
  const scope = new Scope('online.page');
303
+ const goto = grid?.goto === true ? grid.cell : undefined;
304
+ let dialing = socket;
279
305
  // 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
306
  const named = identity();
281
307
  let shellNow: OnlineShell | null = null, waitingForSeat = false;
@@ -290,7 +316,7 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
290
316
  // `reload` is the one ending a screen doesn't answer: the page reloads into the world's build, once (J174)
291
317
  const ended = async (): Promise<void> => { if (!await stale()) newBuildPanel(scope, stale, () => { entering(link.loaded); void reloadByHand(); }); };
292
318
  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})} }, {
319
+ 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
320
  link: (state, reason) => { waitingForSeat = state === 'full'; screens.link(state, reason); if (state === 'ended' && reason === 'reload') void ended(); },
295
321
  // The cut (5.5): an old server refused a v1 hello. Reload only into another build; on this one, the server is updating.
296
322
  cut: () => { void reloadStale(); },
@@ -301,6 +327,15 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
301
327
  elsewhere: seat => { entering(seat); const url = new URL(location.href); url.searchParams.set('chunk', seat); markUnload(`online seat elsewhere (${seat})`); location.replace(url); },
302
328
  });
303
329
  shellNow = shell;
330
+ // the fresh read behind a kept copy: another build reloads into it, as a fresh read before the dial would (two reloads share one
331
+ // durable claim, chunkRecovery.ts); another address takes the next dial: now if the link is down and waiting, else after the dial
332
+ // under way, or the player's Retry once the link has given up
333
+ void fresh?.then(read => {
334
+ if (read === null || scope.disposed) return undefined;
335
+ if (read.engineBuild !== link.build) return stale();
336
+ if (read.socket !== undefined && read.socket !== dialing) { dialing = read.socket; shell.dialNow(); }
337
+ return undefined;
338
+ });
304
339
  // a tap the world must hear waits for the link: the hold card says so, and the tap is never sent late
305
340
  shell.client.gateActions(what => screens.allow(what));
306
341
  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). */
@@ -0,0 +1,57 @@
1
+ // AUDIO AU6 (J303, J295): the cook's audio report. One row per shard and tier from its cooked client manifest: the
2
+ // recordings DOWNLOAD fetches (the shard's own and the engine's shared files alike, AU1's list), their MB on the wire and
3
+ // their share of DOWNLOAD, judged against Jake's lines: green to 6 MB, amber over 6, red over 10 (J303). The report never
4
+ // fails a build or main: an overrun is an AMBER line that CI's budget reporter annotates and main-watch receipts (J295).
5
+
6
+ /** A recording a spawn manifest lists (AU1): engine music and sound effects and a shard's own audio mounts. */
7
+ const AUDIO_URL = /^\/assets\/(?:music|sfx)\/[^?]+\.(?:m4a|mp3|ogg|opus|wav|webm|flac)(?:\?|$)/u;
8
+ export const isAudioUrl = (url: string): boolean => AUDIO_URL.test(url);
9
+
10
+ /** J303 (Jake, 2026-11-12): "each shard can have 10 megabytes of audio. Red over 10. Green up to 6. Amber between 6 and 10". */
11
+ export const AUDIO_LINES: Readonly<{greenBytes: number; redBytes: number}> = Object.freeze({ greenBytes: 6_000_000, redBytes: 10_000_000 });
12
+
13
+ export type AudioLevel = 'green' | 'amber' | 'red';
14
+ export interface AudioReportRow {
15
+ readonly shard: string; readonly tier: 'phone' | 'desktop';
16
+ /** Recordings in the manifest, and their bytes on the wire. */
17
+ readonly files: number; readonly audioBytes: number;
18
+ /** The manifest's whole DOWNLOAD on the wire. */
19
+ readonly downloadBytes: number;
20
+ readonly level: AudioLevel;
21
+ }
22
+ /** What the report reads of a cooked client manifest. */
23
+ export interface AudioReportManifest {
24
+ readonly shard: string; readonly tier: 'phone' | 'desktop';
25
+ readonly files: readonly {readonly url: string; readonly bytes: number; readonly wireBytes?: number}[];
26
+ readonly wireBytes?: number;
27
+ }
28
+
29
+ export const audioLevel = (bytes: number, lines: Readonly<{greenBytes: number; redBytes: number}> = AUDIO_LINES): AudioLevel =>
30
+ bytes > lines.redBytes ? 'red' : bytes > lines.greenBytes ? 'amber' : 'green';
31
+
32
+ /** One row per manifest, sorted by shard then tier (phone first). Pure. */
33
+ export function audioReport(manifests: readonly AudioReportManifest[]): AudioReportRow[] {
34
+ const wire = (row: {readonly bytes: number; readonly wireBytes?: number}): number => row.wireBytes ?? row.bytes;
35
+ return manifests.map(manifest => {
36
+ const audio = manifest.files.filter(row => isAudioUrl(row.url)), audioBytes = audio.reduce((sum, row) => sum + wire(row), 0);
37
+ const downloadBytes = manifest.wireBytes ?? manifest.files.reduce((sum, row) => sum + wire(row), 0);
38
+ return {shard: manifest.shard, tier: manifest.tier, files: audio.length, audioBytes, downloadBytes, level: audioLevel(audioBytes)};
39
+ }).sort((a, b) => (a.shard < b.shard ? -1 : a.shard > b.shard ? 1 : 0) || (a.tier === b.tier ? 0 : a.tier === 'phone' ? -1 : 1));
40
+ }
41
+
42
+ const mb = (bytes: number): string => (bytes / 1e6).toFixed(2);
43
+
44
+ /** The cook's table, one line per row, with the lines it is judged by. */
45
+ export function audioReportTable(rows: readonly AudioReportRow[]): string {
46
+ const head = `cook audio (AU6, J303: green to ${mb(AUDIO_LINES.greenBytes)} MB, amber over it, red over ${mb(AUDIO_LINES.redBytes)} MB; an overrun is AMBER, never a red build or main)`;
47
+ const width = Math.max(5, ...rows.map(row => row.shard.length));
48
+ const line = (cells: readonly string[]): string => [cells[0]?.padEnd(width), cells[1]?.padEnd(7), ...cells.slice(2, 6).map(cell => cell.padStart(11)), ` ${cells[6] ?? ''}`].join(' ');
49
+ return [head, line(['shard', 'tier', 'files', 'audio MB', 'DOWNLOAD MB', 'share', 'line']),
50
+ ...rows.map(row => line([row.shard, row.tier, String(row.files), mb(row.audioBytes), mb(row.downloadBytes),
51
+ `${row.downloadBytes === 0 ? '0' : (100 * row.audioBytes / row.downloadBytes).toFixed(0)}%`, row.level === 'green' ? 'green' : row.level.toUpperCase()]))].join('\n');
52
+ }
53
+
54
+ /** The machine line for a row over the green line, which CI annotates and main-watch reads (`parseAudioAmber` in
55
+ * scripts/test-amber.mjs). A row over the red line is still AMBER here (J295): `level=red` only says how far. */
56
+ export const audioAmberLine = (row: AudioReportRow): string =>
57
+ `AMBER audio shard=${row.shard} tier=${row.tier} bytes=${row.audioBytes} budget=${AUDIO_LINES.greenBytes} red=${AUDIO_LINES.redBytes} level=${row.level}`;
@@ -18,9 +18,10 @@ import {contentNamed} from './contentNamed';
18
18
  import {homedir} from 'node:os';
19
19
  import {productTarball} from './productTarball';
20
20
  import {BrotliSizeCache} from './brotliSizeCache.mjs';
21
- import {defaultBootAudio} from '@wildshard/engine/audio/bootAudio';
21
+ import {defaultBootAudio, ENGINE_MUSIC_STYLE, missingEngineMusic, musicDir} from '@wildshard/engine/audio/bootAudio';
22
22
  import {withAssetTables, type AssetTables} from '@wildshard/engine/boot/tables';
23
23
  import type {AudioData} from '@wildshard/format/audio';
24
+ import {audioReport, audioReportTable, isAudioUrl} from './audioReport';
24
25
 
25
26
  const size = v.pipe(v.number(), v.safeInteger(), v.minValue(0));
26
27
  const files = v.array(v.tuple([v.string(), size]));
@@ -30,7 +31,6 @@ const schema = v.object({common: files, client: files, grid: files,
30
31
  extras: v.record(v.string(), v.tuple([v.string(), size, size, v.string()])),
31
32
  });
32
33
  interface Address {readonly url: string; readonly bytes: number}
33
- const AUDIO_URL = /^\/assets\/(?:music|sfx)\/[^?]+\.(?:m4a|mp3|ogg|opus|wav|webm|flac)(?:\?|$)/u;
34
34
  /** AUDIO AU1 (J299): the recordings a shard's LOAD reads, so DOWNLOAD fetches, counts and caches them: a new player's
35
35
  * boot set (the default music style and sound-effect set, through the client's own selection) and the audio its
36
36
  * recorded fence names. `tables` is the build's common boot table, the one the page installs. */
@@ -38,16 +38,29 @@ export function shardBootAudio(sections: ReadonlyMap<string, unknown>, tables: A
38
38
  const row = sections.get('audio/audio'), data = typeof row === 'object' && row !== null && 'audio' in row ? row.audio as AudioData : undefined;
39
39
  // A level with no music or sample rows boots with no recordings (NO_AUDIO); anything else must select, as on the page.
40
40
  let boot: readonly string[] = [];
41
+ // AU18 (J304): the rows name the engine music they play; a name this build's style lacks fails the cook, never drops.
42
+ const music = data?.music, missing = music === undefined ? [] : withAssetTables(tables, () => missingEngineMusic(music));
43
+ if (missing.length > 0) throw new Error(`${shard}: its audio rows name engine music the ${ENGINE_MUSIC_STYLE} style lacks: ${missing.join(', ')}`);
41
44
  if (data !== undefined && data.music !== undefined && data.samples !== undefined) {
42
45
  try { boot = withAssetTables(tables, () => defaultBootAudio(data)); }
43
46
  catch (error) { throw new Error(`${shard}: its boot audio does not select (${error instanceof Error ? error.message : String(error)})`, {cause: error}); }
44
47
  }
45
48
  const shipped = (url: string): boolean => Object.hasOwn(tables.bytes, url.split('?')[0] ?? url);
46
- return [...new Set([...boot, ...fenceMounts.filter(url => AUDIO_URL.test(url)).map(url => url.split('?')[0] ?? url)])].filter(shipped);
49
+ return [...new Set([...boot, ...fenceMounts.filter(url => isAudioUrl(url)).map(url => url.split('?')[0] ?? url)])].filter(shipped);
50
+ }
51
+ /** AU18: the build log's line for a shard's derived engine music (its boot set's files under the engine style). */
52
+ export function engineMusicLine(shard: string, bootAudio: readonly string[], tables: AssetTables): string {
53
+ const dir = musicDir(ENGINE_MUSIC_STYLE), music = bootAudio.filter(url => url.startsWith(dir));
54
+ const bytes = music.reduce((sum, url) => sum + (tables.bytes[url] ?? 0), 0);
55
+ return `${shard}: engine music: ${music.length} files, ${(bytes / 1e6).toFixed(2)} MB${music.length === 0 ? '' : ` (${music.map(url => url.slice(dir.length)).join(', ')})`}`;
47
56
  }
48
57
  /** What a build's half of the manifests needs from the app: the page's own tables and names, which no cook owns. */
49
58
  export interface BuildHalf {
50
59
  readonly preparationOnly?: boolean;
60
+ /** AUDIO AU19: write each manifest's file list alone: no part or server pack is cooked, and a row's wire size is its
61
+ * raw size. The lists are the build's own (the rows don't depend on packing); a test reads them without the
62
+ * minutes the parts' q11 encode takes over every product. Tests only: a build never sets it. */
63
+ readonly filesOnly?: boolean;
51
64
  readonly rendererRevision?: string;
52
65
  readonly cacheName: string;
53
66
  readonly gpuFiles: Parameters<typeof standInRefs>[0];
@@ -104,6 +117,7 @@ export async function writeSpawnManifests(outDir: string, input: unknown,
104
117
  const precompressed = new BrotliSizeCache(process.env['WILDSHARD_WIRE_SIZE_CACHE'] ?? resolve(homedir(), '.cache/wildshard/gen/served-bytes/1'), 'precompressed');
105
118
  const wireSizes = new Map<string, number>();
106
119
  const wireBytes = (url: string, bytes: Uint8Array, hash: string): number => {
120
+ if (build.filesOnly === true) return bytes.length;
107
121
  const key = `${hash}:${url}`, previous = wireSizes.get(key); if (previous !== undefined) return previous;
108
122
  // Match the deployed/preview representation; Rapier retains its precompressed native body.
109
123
  const length = servedAsIs(url, bytes) ? bytes.length
@@ -208,8 +222,10 @@ export async function writeSpawnManifests(outDir: string, input: unknown,
208
222
  if (half.shard.preparation === 'stale') console.warn(stalePreparationLine(directory));
209
223
  const shardRows = {phone: {entry: half.productRows('phone', 'entry'), whole: half.productRows('phone', 'whole')},
210
224
  desktop: {entry: half.productRows('desktop', 'entry'), whole: half.productRows('desktop', 'whole')}};
211
- for (const [url, member] of await cookParts(output, half, [{tier: 'phone', rows: shardRows.phone.whole}, {tier: 'desktop', rows: shardRows.desktop.whole}], encoder)) cooked.set(url, member);
212
- serverPacks[directory] = await cookShardServerPack(half.shard, output, encoder);
225
+ if (build.filesOnly !== true) {
226
+ for (const [url, member] of await cookParts(output, half, [{tier: 'phone', rows: shardRows.phone.whole}, {tier: 'desktop', rows: shardRows.desktop.whole}], encoder)) cooked.set(url, member);
227
+ serverPacks[directory] = await cookShardServerPack(half.shard, output, encoder);
228
+ }
213
229
  for (const table of [shardRows.phone, shardRows.desktop]) for (const row of [...table.entry, ...table.whole]) {
214
230
  const stable = half.stableKey(row.url); if (stable !== undefined) stableKeys.set(row.url, stable);
215
231
  }
@@ -242,6 +258,7 @@ export async function writeSpawnManifests(outDir: string, input: unknown,
242
258
  }
243
259
  // AUDIO AU1: the same recordings on every tier and flow: LOAD reads them before control on all of them.
244
260
  const bootAudio = assetTables === undefined ? [] : shardBootAudio(sections, assetTables, half.mountRows('phone', 'entry').map(row => row.url), directory);
261
+ if (assetTables !== undefined && sections.has('audio/audio')) console.info(engineMusicLine(directory, bootAudio, assetTables));
245
262
  const write = (tier: 'phone' | 'desktop', flow: 'client' | 'grid', addresses: readonly Address[] = [], mode = '000', whole = false): number => {
246
263
  const selected = new Map<string, SpawnFile>(), add = (row: SpawnFile): void => {selected.set(row.url, row);};
247
264
  for (const row of shardRows[tier][whole ? 'whole' : 'entry']) add(row);
@@ -296,10 +313,13 @@ export async function writeSpawnManifests(outDir: string, input: unknown,
296
313
  (packsGridAt[mode] ??= {})[directory] = {phone: write('phone', 'grid', homes[directory], mode, true), desktop: write('desktop', 'grid', homes[directory], mode, true)};
297
314
  }
298
315
  }
316
+ // AU6 (J303): each shard's recordings and their share of its client DOWNLOAD, per tier; an overrun says AMBER, never fails.
317
+ const entries = pending.filter(row => !row.packed && row.manifest.flow === 'client').map(row => row.manifest);
318
+ if (entries.some(manifest => manifest.files.some(row => isAudioUrl(row.url)))) console.info(audioReportTable(audioReport(entries)));
299
319
  if (Object.keys(preparations).length > 0) console.info(`cook preparation: ${(['current', 'stale', 'none'] as const).map(state => `${preparations[state]?.length ?? 0} ${state}`).join(', ')}`);
300
320
  // DL5: every manifest is known, so pack their files into shared parts, then write each manifest with its own table.
301
321
  const packed = pending.flatMap((row, index) => row.packed ? [index] : []);
302
- const packedTables = await writeSpawnParts(output, packed.map(index => ({rows: pending[index]?.manifest.files ?? [], public: pending[index]?.public === true, desktop: pending[index]?.manifest.tier === 'desktop'})), url => {
322
+ const packedTables = build.filesOnly === true ? [] : await writeSpawnParts(output, packed.map(index => ({rows: pending[index]?.manifest.files ?? [], public: pending[index]?.public === true, desktop: pending[index]?.manifest.tier === 'desktop'})), url => {
303
323
  const read = sources.get(url); if (read === undefined) throw new Error(`Spawn file has no source: ${url}`); return read();
304
324
  }, url => stableKeys.get(url), encoder, cooked);
305
325
  // DL15: each part's q11 body is written before the manifests, so every part row carries its exact wire size.
@@ -36,6 +36,9 @@ export function installedRuntimeReads(launcher:object,root:string):readonly stri
36
36
  const optional=new Set(Object.keys(manifest.optionalDependencies??{}));
37
37
  const names=new Set([...Object.keys(manifest.dependencies??{}),...optional,...Object.keys(manifest.peerDependencies??{})]);
38
38
  for(const name of names){
39
+ // NP6: a type package (engine's optional `@types/three` peer) is never loaded at run time, and its own
40
+ // dependencies may be overridden away (`@types/three>@dimforge/rapier3d-compat`): not part of the closure.
41
+ if(name.startsWith('@types/'))continue;
39
42
  const target=installed(name,directory);
40
43
  if(target!==undefined){
41
44
  pending.push(target.directory);
@@ -23,6 +23,7 @@ import {readTar} from '@wildshard/format/tar';
23
23
  import type {ServerPack, ServerPackPart} from '../../shared/game/shardfile/serverPack';
24
24
  import {serverReadsFile} from '../../shared/game/shardfile/outputDescriptor';
25
25
  import {entryReadSet} from './entryReadSet';
26
+ import {phoneTier} from './tierTextures';
26
27
  import {createPartEncoder, packable, writeSpawnParts, type CookedMember, type PartEncoder} from './spawnParts';
27
28
 
28
29
  export type CookTier = 'phone' | 'desktop';
@@ -160,11 +161,18 @@ export interface ShardHalf {
160
161
  readonly mountRows: (tier: CookTier, set: CookSet) => readonly SpawnFile[];
161
162
  readonly read: (url: string) => Uint8Array;
162
163
  readonly stableKey: (url: string) => string | undefined;
164
+ /** A mount's bytes as this cook serves it: the discovery document carries the phone tier's table (S12b). */
165
+ readonly mountBytes: (row: CookMount) => Uint8Array;
163
166
  }
164
167
 
168
+ /** S12b: what the cook does with a shard's textures per tier. `phone`: give each phone row of the KTX2 table its own
169
+ * trimmed file (`phoneTier`), listed in the phone manifests in place of the file it stands in for. Off by default until
170
+ * the cook's own 6×6 encode (S12c) can replace the hand-made sets. */
171
+ export interface CookTiers {readonly phone?: boolean}
172
+
165
173
  /** The shard half of every manifest: what the app build's `write` and the standalone cook share. `folder` is where the
166
174
  * product is served; a catalogue names it by slug, and today's `_template` folder is the one that differs (`template`). */
167
- export function shardHalf(shard: OpenShardfile, wireBytes: WireBytes, warn: (line: string) => void = () => undefined, folder: string = shard.slug): ShardHalf {
175
+ export function shardHalf(shard: OpenShardfile, wireBytes: WireBytes, warn: (line: string) => void = () => undefined, folder: string = shard.slug, tiers: CookTiers = {}): ShardHalf {
168
176
  const prefix = `/shardfiles/${folder}/`, {index, source, sections} = shard, named = namedPlaces(sections);
169
177
  // D5-4: a preparation-only preview lists the default set alone (no stored fence), so `wildshard prepare` sees the boot's
170
178
  // own reads beyond it. Listing the whole level there made every recorded fence the whole level (Pine, Nalati).
@@ -187,17 +195,31 @@ export function shardHalf(shard: OpenShardfile, wireBytes: WireBytes, warn: (lin
187
195
  sources.set(headerURL, () => shard.header);
188
196
  const header = {url: headerURL, bytes: shard.header.length, hash: headerHash, wireBytes: wireBytes(`${prefix}shard.json`, shard.header, headerHash)};
189
197
  // C3: a page reads this before it knows the product, and a cold offline entry reads it too.
190
- const document = shard.cook?.mounts.find(row => row.url === `${prefix}discovery.json`), discovery: readonly SpawnFile[] = document === undefined ? [] : [{
191
- url: `${document.url}?v=${document.hash.slice(0, 8)}`, bytes: document.bytes, hash: document.hash, wireBytes: wireBytes(document.url, shard.read(document.path), document.hash)}];
192
- for (const row of discovery) if (document !== undefined) sources.set(row.url, () => shard.read(document.path));
193
- const mounts = downloaded(shard), mountURLs = new Set(mounts.map(row => row.url)), onTier = mountTiers(mountURLs);
198
+ const document = shard.cook?.mounts.find(row => row.url === `${prefix}discovery.json`), mounts = downloaded(shard);
199
+ // S12b: the phone tier's files, made from the KTX2 table's own targets; the discovery document names them.
200
+ const onTier = mountTiers(new Set(mounts.map(row => row.url))), mountByURL = new Map(mounts.map(row => [row.url, row])), mountOf = (url: string): Uint8Array | undefined => { const row = mountByURL.get(url); return row === undefined ? undefined : shard.read(row.path); };
201
+ const phone = tiers.phone === true && document !== undefined ? phoneTier(shard.read(document.path), mountOf) : undefined;
202
+ const documentBytes = phone?.discovery ?? (document === undefined ? undefined : shard.read(document.path));
203
+ const discovery: readonly SpawnFile[] = document === undefined || documentBytes === undefined ? [] : [(() => {
204
+ const hash = phone === undefined ? document.hash : sha256(documentBytes);
205
+ return {url: `${document.url}?v=${hash.slice(0, 8)}`, bytes: documentBytes.length, hash, wireBytes: wireBytes(document.url, documentBytes, hash)};
206
+ })()];
207
+ for (const row of discovery) if (documentBytes !== undefined) sources.set(row.url, () => documentBytes);
194
208
  const mountRow = new Map(mounts.map(row => {
195
209
  const url = CONTENT_NAMED.test(row.url) || /-[a-f0-9]{8}\.[a-z0-9]+$/u.test(row.url) ? row.url : `${row.url}?v=${row.hash.slice(0, 8)}`;
196
210
  sources.set(url, () => shard.read(row.path));
197
211
  return [row.url, () => ({url, bytes: row.bytes, hash: row.hash, wireBytes: wireBytes(row.url, shard.read(row.path), row.hash)})] as const;
198
212
  }));
213
+ const tierRows = new Map([...phone?.files ?? []].map(([from, files]) => [from, files.map(file => {
214
+ const hash = sha256(file.bytes);
215
+ sources.set(file.url, () => file.bytes);
216
+ return {url: file.url, bytes: file.bytes.length, hash, wireBytes: wireBytes(file.url, file.bytes, hash)};
217
+ })]));
218
+ /** A phone list names each trimmed target's phone files in its place, and the target too while a kept row still reads it. */
219
+ const tiered = (tier: CookTier, url: string): readonly string[] => tier !== 'phone' || !tierRows.has(url) ? [url] : phone?.kept.has(url) === true ? [url, `tier:${url}`] : [`tier:${url}`];
199
220
  return {shard, header, read: url => { const read = sources.get(url); if (read === undefined) throw new Error(`Spawn file has no source: ${url}`); return read(); },
200
221
  stableKey: url => stableKeys.get(url),
222
+ mountBytes: row => (row.url === document?.url && documentBytes !== undefined ? documentBytes : shard.read(row.path)),
201
223
  productRows: (tier, set) => {
202
224
  const selected: SpawnFile[] = [header, ...discovery];
203
225
  for (const row of index.sections) selected.push(productFile(row.path, row.bytes, row.hash, `section:${row.name}`));
@@ -208,7 +230,13 @@ export function shardHalf(shard: OpenShardfile, wireBytes: WireBytes, warn: (lin
208
230
  },
209
231
  mountRows: (tier, set) => {
210
232
  const urls = wholeSet(tier, set) ? mounts.map(row => row.url).filter(url => onTier(url, tier)) : fence.mounts;
211
- return urls.flatMap(url => { const row = mountRow.get(url); return row === undefined ? [] : [row()]; });
233
+ // A phone file whose target no phone list names (a fence shard's file read past its fence) rides in the phone's whole
234
+ // set: no other tier's part holds it, and it costs less than the target a phone read from a desktop part before.
235
+ const listed = new Set(urls), unlisted = tier === 'phone' && set === 'whole' ? [...tierRows.keys()].filter(url => !listed.has(url)).map(url => `tier:${url}`) : [];
236
+ return [...urls.flatMap(url => tiered(tier, url)), ...unlisted].flatMap(url => {
237
+ if (url.startsWith('tier:')) return tierRows.get(url.slice(5)) ?? [];
238
+ const row = mountRow.get(url); return row === undefined ? [] : [row()];
239
+ });
212
240
  }};
213
241
  }
214
242
 
@@ -300,6 +328,8 @@ export interface CookShardOptions {
300
328
  readonly warn?: (line: string) => void;
301
329
  /** The renderer fingerprint to cook for; this engine's own unless a build names it. */
302
330
  readonly renderer?: string;
331
+ /** S12b: per-tier texture files; off unless a cook asks. */
332
+ readonly tiers?: CookTiers;
303
333
  }
304
334
 
305
335
  /** `cook <shardfile> → <packs>`: the shard's half of every manifest, its parts, and its loose mounts at their URLs. */
@@ -313,7 +343,7 @@ export async function cookShard(tarball: Uint8Array, out: string, options: CookS
313
343
  async function cookWith(tarball: Uint8Array, out: string, options: CookShardOptions, encoder: PartEncoder): Promise<CookReport> {
314
344
  const started = options.now(), shard = openShardfile(tarball, options.renderer === undefined ? {} : {renderer: options.renderer});
315
345
  if (shard.preparation === 'stale') options.warn?.(stalePreparationLine(shard.slug));
316
- const half = shardHalf(shard, options.wireBytes, options.warn);
346
+ const half = shardHalf(shard, options.wireBytes, options.warn, shard.slug, options.tiers);
317
347
  const before = encoder.stats();
318
348
  const table = COOK_TIERS.flatMap(tier => COOK_SETS.map(set => ({tier, set, rows: [...half.productRows(tier, set), ...half.mountRows(tier, set)]})));
319
349
  const whole = table.filter(row => row.set === 'whole');
@@ -337,7 +367,7 @@ async function cookWith(tarball: Uint8Array, out: string, options: CookShardOpti
337
367
  const loose = (half.shard.cook?.mounts ?? []).filter(row => !packable(row.url) || !row.url.startsWith('/assets/'));
338
368
  for (const row of loose) {
339
369
  const file = join(out, row.url.slice(1));
340
- mkdirSync(dirname(file), {recursive: true}); writeFileSync(file, half.shard.read(row.path));
370
+ mkdirSync(dirname(file), {recursive: true}); writeFileSync(file, half.mountBytes(row));
341
371
  }
342
372
  // C3: a title or menu `<img>` reads a shard's images by the URLs its level manifest names, before any fetch layer exists.
343
373
  const images = half.shard.index.files.flatMap(row => row.name?.startsWith('ui/images/') === true ? [row.path] : []);