@wildshard/engine 0.1.15 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/index.html +157 -11
  3. package/lint/engine-sides.json +16 -0
  4. package/lint/host-register.json +496 -0
  5. package/lint/ratchet.json +2 -2
  6. package/lint/shard-imports.d.mts +1 -0
  7. package/lint/shard-imports.mjs +56 -8
  8. package/lint/wildshard-plugin.js +22 -4
  9. package/package.json +16 -5
  10. package/scripts/app-build/buildIdentity.d.mts +3 -1
  11. package/scripts/app-build/buildIdentity.mjs +25 -5
  12. package/scripts/app-build/builtAt.d.mts +4 -0
  13. package/scripts/app-build/builtAt.mjs +21 -0
  14. package/scripts/app-build/serviceWorker.ts +16 -2
  15. package/scripts/app-build/versionFiles.ts +2 -1
  16. package/scripts/app-build-pipeline.mjs +4 -1
  17. package/scripts/audio-download-proof.mjs +843 -0
  18. package/scripts/build-app.mjs +4 -0
  19. package/scripts/build-mirror.d.mts +2 -0
  20. package/scripts/build-mirror.mjs +5 -4
  21. package/scripts/built-product.mjs +3 -3
  22. package/scripts/cell-mem/metrics-preload.mjs +65 -0
  23. package/scripts/cell-mem-bench.mjs +130 -0
  24. package/scripts/check-chunks.mjs +2 -1
  25. package/scripts/devserver-client.d.mts +5 -0
  26. package/scripts/devserver-client.mjs +68 -0
  27. package/scripts/engine-ci-budget.ts +7 -1
  28. package/scripts/format-lock.mjs +20 -11
  29. package/scripts/generate-title-launch.mjs +3 -2
  30. package/scripts/grid-crossing-walk-proof.mjs +16 -8
  31. package/scripts/heavy-lane.py +25 -1
  32. package/scripts/host-ruler/register-migrate.mjs +242 -0
  33. package/scripts/host-ruler/register.d.mts +36 -0
  34. package/scripts/host-ruler/register.mjs +116 -0
  35. package/scripts/host-ruler/roots.d.mts +29 -0
  36. package/scripts/host-ruler/roots.mjs +333 -0
  37. package/scripts/host-ruler/server-roots.d.mts +23 -0
  38. package/scripts/host-ruler/server-roots.mjs +272 -0
  39. package/scripts/main-watch.d.mts +1 -1
  40. package/scripts/main-watch.mjs +10 -6
  41. package/scripts/map-hash.mjs +3 -6
  42. package/scripts/mmo-bots.mjs +2 -2
  43. package/scripts/offline-proof-rules.d.mts +1 -0
  44. package/scripts/offline-proof-rules.mjs +22 -1
  45. package/scripts/online-rig.mjs +4 -4
  46. package/scripts/page-release/flow.d.mts +1 -0
  47. package/scripts/page-release/flow.mjs +6 -2
  48. package/scripts/page-release.mjs +5 -1
  49. package/scripts/physics-route.json +0 -71
  50. package/scripts/pins-catalogue.ts +103 -0
  51. package/scripts/pins-reuse.mjs +3 -1
  52. package/scripts/pins.ts +22 -14
  53. package/scripts/preview-grid.ts +203 -0
  54. package/scripts/road-preload-proof.mjs +167 -0
  55. package/scripts/server-release/publish.mjs +2 -2
  56. package/scripts/server-release/served-slug.d.mts +2 -0
  57. package/scripts/server-release/served-slug.mjs +10 -0
  58. package/scripts/server-release/sign.d.mts +1 -0
  59. package/scripts/server-release/sign.mjs +3 -7
  60. package/scripts/shard-components.mjs +0 -2
  61. package/scripts/shard-outputs.d.mts +8 -0
  62. package/scripts/shard-outputs.mjs +45 -11
  63. package/scripts/side-parity.d.mts +2 -1
  64. package/scripts/side-parity.mjs +25 -4
  65. package/scripts/test-amber.d.mts +1 -0
  66. package/scripts/test-amber.mjs +10 -0
  67. package/scripts/test-products.json +3 -3
  68. package/scripts/tracked-public.d.mts +1 -0
  69. package/scripts/tracked-public.mjs +17 -0
  70. package/src/cli/engine.mjs +8 -0
  71. package/src/client/app/bootRoute.ts +4 -1
  72. package/src/client/app/dropModal.ts +15 -2
  73. package/src/client/app/entry.ts +67 -11
  74. package/src/client/app/slugPath.ts +5 -0
  75. package/src/client/engine/audio/Audio.ts +20 -2
  76. package/src/client/engine/boot/bakedTextures.ts +3 -2
  77. package/src/client/engine/boot/bootTrace.ts +6 -1
  78. package/src/client/engine/boot/bytes.ts +4 -3
  79. package/src/client/engine/boot/clearDownloads.ts +1 -1
  80. package/src/client/engine/boot/contentRead.ts +4 -0
  81. package/src/client/engine/boot/dropNotice.ts +20 -6
  82. package/src/client/engine/boot/gpuFiles.ts +25 -2
  83. package/src/client/engine/boot/lastEnd.ts +8 -2
  84. package/src/client/engine/boot/shardPrefetch.ts +7 -1
  85. package/src/client/engine/boot/sw.ts +19 -0
  86. package/src/client/engine/core/Game.ts +11 -3
  87. package/src/client/engine/core/GpuRecovery.ts +7 -0
  88. package/src/client/engine/core/Volumetrics.ts +5 -0
  89. package/src/client/engine/core/assets.ts +27 -20
  90. package/src/client/engine/core/bootstrap.ts +1 -2
  91. package/src/client/engine/core/ktx2.ts +84 -11
  92. package/src/client/engine/explore/Compare.ts +2 -2
  93. package/src/client/engine/explore/TouchFly.ts +3 -5
  94. package/src/client/engine/input/dom.ts +12 -0
  95. package/src/client/engine/net/predictor.ts +6 -2
  96. package/src/client/engine/player/Player.ts +10 -2
  97. package/src/client/engine/player/TouchControls.ts +12 -4
  98. package/src/client/engine/pwa/sw.js +47 -8
  99. package/src/client/engine/render/drawCheck.ts +96 -0
  100. package/src/client/engine/saves/staleBuildNote.ts +46 -0
  101. package/src/client/engine/telemetry/browserErrors.ts +157 -20
  102. package/src/client/engine/telemetry/screenOutbox.ts +61 -0
  103. package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
  104. package/src/client/engine/ui/DeathFade.ts +99 -11
  105. package/src/client/engine/ui/ErrorModal.ts +13 -6
  106. package/src/client/engine/ui/Feedback.ts +2 -1
  107. package/src/client/engine/ui/Loading.ts +10 -6
  108. package/src/client/engine/ui/Map.ts +2 -1
  109. package/src/client/engine/ui/WeaponStrip.ts +2 -1
  110. package/src/client/engine/ui/backGuard.ts +104 -0
  111. package/src/client/engine/ui/hudAdapters.ts +30 -4
  112. package/src/client/engine/ui/loading.css +17 -0
  113. package/src/client/engine/ui/namePrompt.ts +6 -5
  114. package/src/client/engine/ui/styles/combat.css +12 -0
  115. package/src/client/engine/ui/styles/namePrompt.css +4 -2
  116. package/src/client/game/boot/audio.generated.ts +0 -294
  117. package/src/client/game/boot/bytes.generated.ts +0 -11
  118. package/src/client/game/boot/versions.generated.ts +0 -11
  119. package/src/client/game/compendium/keepsakes.ts +16 -6
  120. package/src/client/game/grapple/tool.ts +10 -7
  121. package/src/client/game/grid/cellLoading.ts +23 -12
  122. package/src/client/game/grid/cellScreens.ts +39 -74
  123. package/src/client/game/grid/liveSession.ts +40 -7
  124. package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
  125. package/src/client/game/grid/nearPlaceholderView.ts +9 -3
  126. package/src/client/game/grid/oneWayIn.ts +92 -27
  127. package/src/client/game/grid/pageEntry.ts +19 -0
  128. package/src/client/game/grid/pageShell.ts +1 -1
  129. package/src/client/game/grid/plotAudio.ts +114 -0
  130. package/src/client/game/grid/products.ts +55 -5
  131. package/src/client/game/grid/roadLookPlatform.ts +2 -2
  132. package/src/client/game/grid/session.ts +38 -22
  133. package/src/client/game/grid/spawnGround.ts +68 -0
  134. package/src/client/game/grid/voidLook.ts +29 -23
  135. package/src/client/game/loot/runtime.ts +3 -1
  136. package/src/client/game/mainMenu.ts +14 -6
  137. package/src/client/game/riding/hud.ts +6 -4
  138. package/src/client/game/session/finish.ts +17 -3
  139. package/src/client/game/session/play.ts +8 -2
  140. package/src/client/game/session/session.ts +4 -1
  141. package/src/client/game/shardfile/clientWorker.ts +41 -12
  142. package/src/client/game/shardfile/serverRoute.ts +10 -22
  143. package/src/client/game/slugPage.css +11 -0
  144. package/src/client/game/slugPage.ts +84 -0
  145. package/src/client/game/systems/viewmodel/heldView.ts +6 -3
  146. package/src/client/game/titleDeck.ts +55 -32
  147. package/src/client/host/online/doctor.ts +7 -6
  148. package/src/client/host/online/linkScreens.ts +16 -0
  149. package/src/client/host/online/release.ts +51 -5
  150. package/src/client/host/online/shell.ts +48 -27
  151. package/src/client/host/standalone/shell.ts +7 -3
  152. package/src/cook/game/audioReport.ts +57 -0
  153. package/src/cook/game/entryTotals.ts +26 -6
  154. package/src/cook/game/installedRuntimeReads.ts +3 -0
  155. package/src/server/engine/sim/respawn.ts +6 -1
  156. package/src/server/engine/sim.ts +3 -0
  157. package/src/server/game/grid/simulation.ts +35 -0
  158. package/src/server/game/loot/harvest.ts +2 -0
  159. package/src/server/game/loot/keepsakeProgression.ts +40 -0
  160. package/src/server/game/loot/playerOwned.ts +5 -1
  161. package/src/server/game/plugin/simulation.ts +4 -0
  162. package/src/server/game/population/nativeBake.ts +2 -1
  163. package/src/server/game/quest/chapterRecords.ts +2 -0
  164. package/src/server/game/quest/serverChapters.ts +4 -0
  165. package/src/server/game/quest/serverDoors.ts +11 -5
  166. package/src/server/game/roomRespawn.ts +4 -0
  167. package/src/server/game/shardfile/installedSides.ts +18 -0
  168. package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
  169. package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
  170. package/src/server/host/bake/headlessWorker.ts +5 -1
  171. package/src/server/host/dedicated/cellHost.ts +98 -29
  172. package/src/server/host/dedicated/cellProtocol.ts +11 -1
  173. package/src/server/host/dedicated/cellWorker.ts +9 -3
  174. package/src/server/host/dedicated/crossing.ts +6 -2
  175. package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
  176. package/src/server/host/dedicated/gridCells.ts +52 -9
  177. package/src/server/host/dedicated/main.ts +31 -12
  178. package/src/server/host/dedicated/placementFile.ts +72 -0
  179. package/src/server/host/dedicated/releaseFile.ts +17 -10
  180. package/src/server/host/dedicated/roadRoom.ts +21 -5
  181. package/src/server/host/dedicated/workerTable.ts +13 -1
  182. package/src/server/host/dedicated/world.ts +81 -9
  183. package/src/server/host/headlessRuntime.ts +10 -5
  184. package/src/server/host/installers.ts +62 -0
  185. package/src/server/host/openWorld.ts +59 -0
  186. package/src/server/host/ropeDecks.ts +2 -0
  187. package/src/server/host/standalone/cellWorld.ts +25 -19
  188. package/src/server/host/standalone/fallFloor.ts +2 -2
  189. package/src/server/host/standalone/gridServer.ts +7 -4
  190. package/src/server/host/standalone/roadWorld.ts +41 -4
  191. package/src/shared/engine/audio/bootAudio.ts +33 -0
  192. package/src/shared/engine/level/spec.ts +3 -3
  193. package/src/shared/engine/net/acts.ts +3 -0
  194. package/src/shared/engine/physics/query.ts +27 -0
  195. package/src/shared/engine/physics/terrain.ts +19 -28
  196. package/src/shared/engine/saves/saves.lock.json +15 -0
  197. package/src/shared/engine/sim/actRoutes.ts +2 -0
  198. package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
  199. package/src/shared/game/grid/catalogue.ts +12 -5
  200. package/src/shared/game/grid/catalogueSlot.ts +11 -0
  201. package/src/shared/game/grid/farProxy.ts +6 -5
  202. package/src/shared/game/grid/pageMode.ts +1 -1
  203. package/src/shared/game/grid/roadLayout.ts +26 -3
  204. package/src/shared/game/grid/singleplayer.json +0 -13
  205. package/src/shared/game/grid/voidFloor.ts +122 -0
  206. package/src/shared/game/strings.ts +15 -0
  207. package/src/shared/host/standalone/netInput.ts +2 -1
@@ -3,6 +3,7 @@
3
3
  import { spawnSync } from "node:child_process";
4
4
  import { resolve } from "node:path";
5
5
  import { newBuildId } from "./app-build/buildIdentity.mjs";
6
+ import { builtAtOf } from "./app-build/builtAt.mjs";
6
7
  import { deferredPublicCopy } from "./app-build/outputProducts.mjs";
7
8
  import { prepareAppBuild, finishAppBuild, AppBuildFailureError } from "./app-build-pipeline.mjs";
8
9
 
@@ -23,6 +24,9 @@ try {
23
24
 
24
25
  const vite = resolve(import.meta.dirname, "../node_modules/vite/bin/vite.js");
25
26
  const buildId = newBuildId();
27
+ // STALE-BUILD SB1 (J321): one build time for every step's stamp (version.json, the documents, the entry, sw.js);
28
+ // a caller may pass its own, as with WS_BUILD_ID
29
+ process.env.WS_BUILT_AT = builtAtOf(process.env.WS_BUILT_AT);
26
30
  const deferPublic = deferredPublicCopy(process.cwd(), outDir, args);
27
31
  // vite.config.ts bundles to one module whose static imports reach @wildshard/format, so the hook comes first (J82).
28
32
  const build = spawnSync(
@@ -2,6 +2,8 @@ export interface Mirror {
2
2
  dir: string;
3
3
  sha: string;
4
4
  release: () => void;
5
+ /** The slot's git index, at the synced commit (the slot has no .git; tracked-public.mjs reads it). */
6
+ index: string;
5
7
  }
6
8
 
7
9
  export interface MirrorOptions {
@@ -196,7 +196,7 @@ function sourceOverlay(git, generated) {
196
196
  .some(file => file && !generated.has(file) && !file.split('/').includes('node_modules'));
197
197
  }
198
198
 
199
- /** Lock the slot, bring its tree to `rev`, return { dir, sha, release }. The lock also releases at process exit. */
199
+ /** Lock the slot, bring its tree to `rev`, return { dir, sha, release, index } (index: the slot's git index, at `rev`). The lock also releases at process exit. */
200
200
  /** Any check name requests the shared five-slot pool. No reserved slots. */
201
201
  export function defaultSlot(env = process.env) {
202
202
  return env.WILDSHARD_MIRROR_SLOT ?? 'check';
@@ -343,7 +343,8 @@ function prepareMirror(rev, candidateTree, { repo = REPO, slot = 'check', full =
343
343
  // Children of this process inherit it; git run from the checkout itself is unaffected.
344
344
  const ceilings = (env.GIT_CEILING_DIRECTORIES ?? '').split(':').filter(Boolean);
345
345
  if (!ceilings.includes(root)) process.env.GIT_CEILING_DIRECTORIES = [...ceilings, root].join(':');
346
- return { dir, sha, release };
346
+ // pins.ts reads the tracked public files from this index (tracked-public.mjs): the slot has no .git of its own
347
+ return { dir, sha, release, index: join(root, 'index') };
347
348
  } catch (error) {
348
349
  release();
349
350
  throw error;
@@ -376,8 +377,8 @@ if (isMain) {
376
377
  throw new Error('G612: build-mirror run is reserved for serve-build re-execution; use types, lint and focused tests in the working tree');
377
378
  }
378
379
  mainMirrorRevision(rev);
379
- const { dir, sha, release } = openMirror(rev, { slot, full });
380
- const result = spawnSync(command[0], command.slice(1), { cwd: dir, stdio: 'inherit', env: { ...process.env, WS_BUILD_ID: sourceBuildId(sha) } });
380
+ const { dir, sha, release, index } = openMirror(rev, { slot, full });
381
+ const result = spawnSync(command[0], command.slice(1), { cwd: dir, stdio: 'inherit', env: { ...process.env, WS_BUILD_ID: sourceBuildId(sha), WS_MIRROR_REPO: REPO, WS_MIRROR_INDEX: index } });
381
382
  release();
382
383
  process.exit(result.status ?? 1);
383
384
  } else {
@@ -8,7 +8,7 @@ import { mapStampPath, mapSettingsPath, mapTilesHash } from './map-hash.mjs';
8
8
  import { borrowShardfileEntry, readBuildKey, shardfileCacheRoot } from './shardfile-cache.mjs';
9
9
  import { InputHashMemo } from './bake-input-hashes.mjs';
10
10
  import { productInputKey, productToolchainKey, matchingProductInputKey } from './shardfile-inputs.mjs';
11
- import { productFolder } from './shard-outputs.mjs';
11
+ import { hasShardSource, productFolder, shardSourceDir } from './shard-outputs.mjs';
12
12
  import { shardfileValidationRevision } from './shardfile-validation-revision.mjs';
13
13
 
14
14
  // VITEST-BENCH VB14: the boundary lint pulls in Vite, Rolldown, sharp and semver. Only a source shard's runtime
@@ -98,13 +98,13 @@ export function readBuiltShardfile(sourceRoot, name, { cacheRoot = shardfileCach
98
98
  if (built !== undefined && /^[a-f0-9]{40}$/u.test(built) && built === env.GITHUB_SHA
99
99
  && existsSync(resolve(destination, 'shard.json'))) return destination;
100
100
  // P3: no shard source to rebuild from, so a product is a pinned shardfile (J65) or it is missing.
101
- if (!existsSync(resolve(root, 'src/shards'))) {
101
+ if (!hasShardSource(root)) {
102
102
  if (existsSync(resolve(destination, 'shard.json'))) return destination;
103
103
  const slice = resolve(root, 'out/.slices', name);
104
104
  if (existsSync(resolve(slice, 'shard.json'))) return slice;
105
105
  throw new Error(`No shard source and no pinned product: ${name}`);
106
106
  }
107
- const folder = productFolder(root, name), project = resolve(root, 'src/shards', folder);
107
+ const folder = productFolder(root, name), project = shardSourceDir(root, folder);
108
108
  const output = name === folder ? undefined : name;
109
109
  const map = productMapInput(project, output);
110
110
  const flags = productFlags(root, output, map, runtimeCopyIssues(root, project).length === 0);
@@ -0,0 +1,65 @@
1
+ // SERVER-CELLS (draft, opus-cellmem): Prometheus text for a dedicated server under a bench, with no change to the server. Loaded with
2
+ // `node --import ./scripts/cell-mem/metrics-preload.mjs main.mjs` and `METRICS_PORT` set; without that env it does nothing.
3
+ // The main thread serves `/metrics` on 127.0.0.1 only. Every worker thread (the same preload runs there) sends its own event-loop
4
+ // delay and heap over a BroadcastChannel. The door's own `{"at":"worker"}` log rows (cells resident and awake, players, tick time)
5
+ // are read off `console.info` as they are written, and still written. Nothing leaves loopback; nothing here alters a reply or a tick.
6
+ import { createServer } from 'node:http';
7
+ import { monitorEventLoopDelay } from 'node:perf_hooks';
8
+ import { BroadcastChannel, isMainThread, threadId } from 'node:worker_threads';
9
+
10
+ const port = Number(process.env.METRICS_PORT ?? 0);
11
+ if (Number.isInteger(port) && port > 0) {
12
+ const channel = new BroadcastChannel('wildshard-cell-metrics'), delay = monitorEventLoopDelay({ resolution: 10 });
13
+ delay.enable();
14
+ // The histogram's samples include its own 10 ms timer: what is past that is lag.
15
+ const ms = (/** @type {number} */ ns) => Math.max(0, ns / 1e6 - 10);
16
+ const own = () => { const memory = process.memoryUsage(); return { thread: threadId, p50: ms(delay.percentile(50)), p99: ms(delay.percentile(99)), max: ms(delay.max), heap: memory.heapUsed, heapTotal: memory.heapTotal, external: memory.external, arrayBuffers: memory.arrayBuffers }; };
17
+ if (!isMainThread) {
18
+ // oxlint-disable-next-line unicorn/require-post-message-target-origin -- A BroadcastChannel has no origin to name.
19
+ const timer = setInterval(() => { channel.postMessage(own()); delay.reset(); }, 5_000);
20
+ timer.unref(); channel.unref();
21
+ } else {
22
+ /** @type {Map<number, ReturnType<typeof own>>} */
23
+ const threads = new Map();
24
+ /** @type {Map<number, Record<string, number>>} */
25
+ const workers = new Map();
26
+ channel.onmessage = event => { const row = /** @type {ReturnType<typeof own>} */ (/** @type {{ data: unknown }} */ (event).data); threads.set(row.thread, row); };
27
+ channel.unref();
28
+ const info = console.info.bind(console);
29
+ console.info = (...args) => {
30
+ const [line] = args;
31
+ if (typeof line === 'string' && line.startsWith('{"at":"worker"')) try { const row = JSON.parse(line); workers.set(row.index, row); } catch { /* still logged */ }
32
+ info(...args);
33
+ };
34
+ let main = own();
35
+ setInterval(() => { main = own(); delay.reset(); }, 5_000).unref();
36
+ /** @param {string} labels */
37
+ const pair = (labels, /** @type {number} */ value) => /** @type {[string, number]} */ ([labels, value]);
38
+ const text = () => {
39
+ const memory = process.memoryUsage(), cpu = process.cpuUsage(), rows = /** @type {string[]} */ ([]);
40
+ const metric = (/** @type {string} */ name, /** @type {string} */ type, /** @type {[string, number][]} */ values) => { rows.push(`# TYPE ${name} ${type}`); for (const [labels, value] of values) rows.push(`${name}${labels} ${String(value)}`); };
41
+ const perThread = (/** @type {'heap' | 'external' | 'arrayBuffers'} */ field, /** @type {number} */ mainValue) => [pair('{thread="main"}', mainValue), ...[...threads.values()].map(row => pair(`{thread="${String(row.thread)}"}`, row[field]))];
42
+ metric('process_resident_memory_bytes', 'gauge', [pair('', memory.rss)]);
43
+ metric('process_cpu_seconds_total', 'counter', [pair('', (cpu.user + cpu.system) / 1e6)]);
44
+ metric('nodejs_heap_used_bytes', 'gauge', perThread('heap', memory.heapUsed));
45
+ metric('nodejs_external_bytes', 'gauge', perThread('external', memory.external));
46
+ metric('nodejs_array_buffers_bytes', 'gauge', perThread('arrayBuffers', memory.arrayBuffers));
47
+ metric('nodejs_eventloop_lag_seconds', 'summary', [main, ...threads.values()].flatMap(row => {
48
+ const name = row === main ? 'main' : String(row.thread);
49
+ return [pair(`{thread="${name}",quantile="0.5"}`, row.p50 / 1000), pair(`{thread="${name}",quantile="0.99"}`, row.p99 / 1000), pair(`{thread="${name}",quantile="1"}`, row.max / 1000)];
50
+ }));
51
+ const each = (/** @type {string} */ field) => [...workers.entries()].map(([index, row]) => pair(`{worker="${String(index)}"}`, row[field] ?? 0));
52
+ metric('wildshard_cells_resident', 'gauge', each('cells'));
53
+ metric('wildshard_cells_awake', 'gauge', each('awake'));
54
+ metric('wildshard_players', 'gauge', each('players'));
55
+ metric('wildshard_tick_seconds', 'summary', [...workers.entries()].flatMap(([index, row]) => [['0.5', 'p50'], ['0.95', 'p95'], ['0.99', 'p99'], ['1', 'max']].map(([q, field]) => pair(`{worker="${String(index)}",quantile="${q}"}`, (row[field] ?? 0) / 1000))));
56
+ metric('wildshard_ticks_per_second', 'gauge', each('ticksPerSecond'));
57
+ metric('wildshard_tick_drops', 'gauge', each('drops'));
58
+ return `${rows.join('\n')}\n`;
59
+ };
60
+ createServer((request, response) => {
61
+ if (request.url !== '/metrics') { response.writeHead(404).end(); return; }
62
+ response.writeHead(200, { 'content-type': 'text/plain; version=0.0.4' }).end(text());
63
+ }).on('error', error => { console.error(JSON.stringify({ at: 'metrics.refused', port, error: String(error) })); }).listen(port, '127.0.0.1').unref();
64
+ }
65
+ }
@@ -0,0 +1,130 @@
1
+ #!/usr/bin/env node
2
+ // SERVER-CELLS (draft, opus-cellmem): what one dedicated server costs per resident cell, dormant (nobody in it) and with one bot in
3
+ // each. It runs a kept `mmo-bots.mjs replica --keep` folder's release bundle on loopback with production's shape (4 workers), once per
4
+ // cell count, and reads it through scripts/cell-mem/metrics-preload.mjs (Prometheus text on a loopback port): RSS, CPU, heap and
5
+ // external per thread, event-loop lag per thread, and the workers' own tick readings. Nothing leaves this Mac but the book GET.
6
+ // node scripts/mmo-bots.mjs replica --bots 1 --seconds 15 --cells grid --keep (once: bundle, bots tree, pack cache)
7
+ // (cd tmp/mmo-bots/<stamp>/src && node scripts/build-server.mjs --build <build> --out ../cmbuild --entry cellMemBots=test/fixtures/dedicated/cellMemBotsEntry.ts)
8
+ // node scripts/cell-mem-bench.mjs --from tmp/mmo-bots/<stamp> [--counts 1,2,8,16,25] [--dormant 30] [--active 40] [--workers 4]
9
+ // The report goes to <from>/cell-mem-w<workers>.json.
10
+ import { execFileSync, spawn } from 'node:child_process';
11
+ import { generateKeyPairSync, randomBytes, sign } from 'node:crypto';
12
+ import { readFileSync, rmSync, writeFileSync } from 'node:fs';
13
+ import { join, resolve as absolute } from 'node:path';
14
+ import { pathToFileURL } from 'node:url';
15
+ import { parseArgs } from 'node:util';
16
+
17
+ const ROOT = absolute(import.meta.dirname, '..');
18
+ const { values } = parseArgs({ options: { from: { type: 'string' }, counts: { type: 'string', default: '1,2,8,16,25' }, dormant: { type: 'string', default: '30' }, active: { type: 'string', default: '40' },
19
+ workers: { type: 'string', default: '4' }, port: { type: 'string', default: '18896' }, origin: { type: 'string', default: 'https://packs.wildshard.io' } } });
20
+ if (values.from === undefined) throw new Error('--from <kept mmo-bots folder>');
21
+ const from = absolute(values.from), server = join(from, 'server'), bots = join(from, 'cmbuild', 'cellMemBots.mjs'), port = Number(values.port), metricsPort = port + 1;
22
+ const signed = JSON.parse(readFileSync(join(from, 'release.json'), 'utf8')), release = JSON.parse(signed.body);
23
+ const sleep = (/** @type {number} */ ms) => new Promise(resolve => { setTimeout(resolve, ms); });
24
+ const note = (/** @type {Record<string, unknown>} */ row) => { console.info(JSON.stringify({ at: 'cell-mem', ...row })); };
25
+
26
+ /** The grid's cells in the order `WORLD_CELLS=grid` opens them, read off the kept run's own log. */
27
+ const order = /** @type {string[]} */ (readFileSync(join(from, 'server.jsonl'), 'utf8').split('\n').map(line => { try { return JSON.parse(line); } catch { return null; } }).find(row => row?.at === 'server.listening')?.cells ?? []);
28
+ if (order.length === 0) throw new Error('The kept run never listened');
29
+
30
+ /** @returns {Promise<Record<string, number>>} The scrape, flattened to `name{labels}` → value. */
31
+ async function scrape() {
32
+ const text = await (await fetch(`http://127.0.0.1:${String(metricsPort)}/metrics`)).text(), rows = /** @type {Record<string, number>} */ ({});
33
+ for (const line of text.split('\n')) { if (line === '' || line.startsWith('#')) continue; const at = line.lastIndexOf(' '); rows[line.slice(0, at)] = Number(line.slice(at + 1)); }
34
+ return rows;
35
+ }
36
+ const sum = (/** @type {Record<string, number>} */ rows, /** @type {string} */ prefix) => Object.entries(rows).filter(([name]) => name.startsWith(prefix)).reduce((total, [, value]) => total + value, 0);
37
+ const most = (/** @type {Record<string, number>} */ rows, /** @type {RegExp} */ match) => Math.max(0, ...Object.entries(rows).filter(([name]) => match.test(name)).map(([, value]) => value));
38
+ const median = (/** @type {number[]} */ list) => { const sorted = list.slice().sort((a, b) => a - b); return sorted[Math.floor(sorted.length / 2)] ?? 0; };
39
+
40
+ /** macOS RSS drops as the kernel compresses a quiet process's pages; `footprint` counts those too, as Activity Monitor's Memory does. Elsewhere, RSS. */
41
+ const footprint = (/** @type {number | undefined} */ pid) => {
42
+ if (process.platform !== 'darwin' || pid === undefined) return null;
43
+ try { const mb = /Footprint: ([\d.]+) (KB|MB|GB)/u.exec(execFileSync('footprint', ['-p', String(pid)], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })); return mb === null ? null : Number(mb[1]) * ({ KB: 1 / 1024, MB: 1, GB: 1024 }[mb[2] ?? 'MB'] ?? 1); } catch { return null; }
44
+ };
45
+
46
+ /** One phase: scrapes every 5 s for `seconds`, and the CPU used across it. */
47
+ async function phase(/** @type {number} */ seconds, /** @type {string[]} */ workerLines, /** @type {number | undefined} */ pid) {
48
+ const first = await scrape(), started = performance.now(), samples = [], footprints = /** @type {number[]} */ ([]);
49
+ const linesBefore = workerLines.length;
50
+ while (performance.now() - started < seconds * 1000) { await sleep(5_000); samples.push(await scrape()); const mb = footprint(pid); if (mb !== null) footprints.push(mb); }
51
+ const last = samples.at(-1) ?? first, wall = (performance.now() - started) / 1000;
52
+ const ticks = workerLines.slice(linesBefore).map(line => JSON.parse(line));
53
+ const mb = (/** @type {number} */ bytes) => Math.round(bytes / 1048576);
54
+ return {
55
+ footprintMB: footprints.length === 0 ? null : Math.round(median(footprints)), footprintMaxMB: footprints.length === 0 ? null : Math.round(Math.max(...footprints)),
56
+ rssMB: mb(median(samples.map(row => row.process_resident_memory_bytes ?? 0))), rssMaxMB: mb(Math.max(...samples.map(row => row.process_resident_memory_bytes ?? 0))),
57
+ heapMB: mb(median(samples.map(row => sum(row, 'nodejs_heap_used_bytes')))), externalMB: mb(median(samples.map(row => sum(row, 'nodejs_external_bytes')))), arrayBuffersMB: mb(median(samples.map(row => sum(row, 'nodejs_array_buffers_bytes')))),
58
+ cpuCores: Number((((last.process_cpu_seconds_total ?? 0) - (first.process_cpu_seconds_total ?? 0)) / wall).toFixed(3)),
59
+ mainLagP50: Number(median(samples.map(row => row['nodejs_eventloop_lag_seconds{thread="main",quantile="0.5"}'] ?? 0)).toFixed(5)) * 1000,
60
+ mainLagP99: Number(Math.max(...samples.map(row => row['nodejs_eventloop_lag_seconds{thread="main",quantile="0.99"}'] ?? 0)).toFixed(5)) * 1000,
61
+ workerLagP99: Number(Math.max(...samples.map(row => most(row, /^nodejs_eventloop_lag_seconds\{thread="\d+",quantile="0.99"\}/u))).toFixed(5)) * 1000,
62
+ tickP50: Math.max(0, ...ticks.map(row => row.p50)), tickP95: Math.max(0, ...ticks.map(row => row.p95)), tickP99: Math.max(0, ...ticks.map(row => row.p99)), tickMax: Math.max(0, ...ticks.map(row => row.max)),
63
+ drops: ticks.reduce((total, row) => total + row.drops, 0), minTicksPerSecond: Math.min(60, ...ticks.map(row => row.ticksPerSecond)),
64
+ awake: Math.max(0, ...samples.map(row => sum(row, 'wildshard_cells_awake'))), players: Math.max(0, ...samples.map(row => sum(row, 'wildshard_players'))),
65
+ perThreadHeapMB: Object.fromEntries(Object.entries(last).filter(([name]) => name.startsWith('nodejs_heap_used_bytes')).map(([name, value]) => [name.slice(name.indexOf('{')), mb(value)])),
66
+ };
67
+ }
68
+
69
+ /** One count: a fresh replica with the first `count` cells, dormant, then a bot in every cell. */
70
+ async function run(/** @type {number} */ count) {
71
+ const cells = order.slice(0, count), { publicKey, privateKey } = generateKeyPairSync('ed25519');
72
+ const body = JSON.stringify({ ...release, serial: 1 }), file = join(from, `cell-mem-release.json`);
73
+ writeFileSync(file, JSON.stringify({ body, signature: sign(null, Buffer.from(body), privateKey).toString('hex') }));
74
+ const env = { PATH: process.env.PATH ?? '', HOME: process.env.HOME ?? '', PACK_ORIGIN: values.origin, PACK_CACHE: join(from, 'packs'), DATABASE_URL: 'memory:', SEAT_SECRET: randomBytes(32).toString('hex'),
75
+ HOST: '127.0.0.1', PORT: String(port), RELEASE_CHANNEL: 'production', RELEASE_URL: pathToFileURL(file).href, RELEASE_PUBLIC_KEY: publicKey.export({ type: 'spki', format: 'der' }).toString('hex'),
76
+ WORLD_CELLS: cells.join(','), WORLD_WORKERS: values.workers, WORLD_SEATS: '64', TELEMETRY_URL: '', ERRORS_URL: '', SENTRY_DSN: '', RECORD_TAG: '', METRICS_PORT: String(metricsPort) };
77
+ const began = performance.now(), workerLines = /** @type {string[]} */ ([]), booted = /** @type {Record<string, number>} */ ({});
78
+ const child = spawn(process.execPath, ['--import', pathToFileURL(join(ROOT, 'scripts/cell-mem/metrics-preload.mjs')).href, join(server, 'main.mjs')], { cwd: server, env, stdio: ['ignore', 'pipe', 'pipe'] });
79
+ /** Set by the log reader as lines arrive. */
80
+ const seen = { listening: 0 };
81
+ let buffer = '';
82
+ child.stdout.on('data', (/** @type {Buffer} */ chunk) => {
83
+ buffer += chunk.toString();
84
+ for (let end = buffer.indexOf('\n'); end >= 0; end = buffer.indexOf('\n')) {
85
+ const line = buffer.slice(0, end); buffer = buffer.slice(end + 1);
86
+ if (line.startsWith('{"at":"worker"')) workerLines.push(line);
87
+ else if (line.startsWith('{"at":"server.listening"')) seen.listening = performance.now() - began;
88
+ else if (line.startsWith('{"at":"cell.booted"')) { const row = JSON.parse(line); booted[row.slug] = Math.round(row.ms); }
89
+ }
90
+ });
91
+ child.stderr.on('data', () => { /* the replica's warnings stay out of the report */ });
92
+ /** @type {import('node:child_process').ChildProcess | null} */
93
+ let bot = null;
94
+ try {
95
+ while (seen.listening === 0 && child.exitCode === null && performance.now() - began < 240_000) await sleep(250);
96
+ if (seen.listening === 0) throw new Error(`${String(count)} cells never listened`);
97
+ // The first worker readings come 10 s after boot: let the boot's own garbage settle before the dormant read.
98
+ while (workerLines.length === 0 && performance.now() - began < 300_000) await sleep(500);
99
+ const dormant = await phase(Number(values.dormant), workerLines, child.pid);
100
+ note({ count, phase: 'dormant', ...dormant });
101
+ const result = join(from, `cell-mem-bots-${String(count)}.json`);
102
+ rmSync(result, { force: true });
103
+ const players = spawn(process.execPath, [bots, `ws://127.0.0.1:${String(port)}/`, release.engineBuild, cells.join(','), String(Number(values.active) + 10), 'cm', result], { stdio: ['ignore', 'pipe', 'inherit'] });
104
+ bot = players;
105
+ const arrival = { at: 0 };
106
+ players.stdout.on('data', (/** @type {Buffer} */ chunk) => { if (chunk.toString().includes('cellmem.arrived')) arrival.at = performance.now(); });
107
+ while (arrival.at === 0 && players.exitCode === null) await sleep(250);
108
+ if (arrival.at === 0) throw new Error(`${String(count)} cells: the bots ended before they were seated`);
109
+ const active = await phase(Number(values.active), workerLines, child.pid);
110
+ await new Promise(resolve => { if (players.exitCode !== null) resolve(null); else players.once('exit', resolve); });
111
+ const report = JSON.parse(readFileSync(result, 'utf8')), rtts = report.rows.map((/** @type {{ rttP50: number | null }} */ row) => row.rttP50).filter((/** @type {number | null} */ value) => value !== null);
112
+ const row = { count, cells, bootMs: Math.round(seen.listening), cellBootMs: booted, dormant, active: { ...active, seated: report.seated, inTheirCell: report.inTheirCell, rttP50: median(rtts), rttMax: Math.max(0, ...report.rows.map((/** @type {{ rttMax: number | null }} */ seat) => seat.rttMax ?? 0)), joinMsMax: Math.max(0, ...report.rows.map((/** @type {{ joinedMs: number | null }} */ seat) => seat.joinedMs ?? 0)) } };
113
+ note({ count, phase: 'active', ...row.active });
114
+ return row;
115
+ } finally {
116
+ if (bot !== null && bot.exitCode === null) bot.kill('SIGTERM');
117
+ child.kill('SIGTERM');
118
+ const gone = new Promise(resolve => { if (child.exitCode !== null) resolve(null); else child.once('exit', resolve); });
119
+ await Promise.race([gone, sleep(15_000)]);
120
+ if (child.exitCode === null) child.kill('SIGKILL');
121
+ }
122
+ }
123
+
124
+ const rows = [];
125
+ for (const count of values.counts.split(',').map(Number)) {
126
+ if (!Number.isInteger(count) || count < 1 || count > order.length) { note({ count, skipped: `the grid opens ${String(order.length)} cells` }); continue; }
127
+ rows.push(await run(count));
128
+ writeFileSync(join(from, `cell-mem-w${values.workers}.json`), `${JSON.stringify({ build: release.engineBuild, workers: Number(values.workers), node: process.version, rows }, null, 2)}\n`);
129
+ }
130
+ note({ done: join(from, `cell-mem-w${values.workers}.json`) });
@@ -59,7 +59,8 @@ function closureBudgetErrors(modules, budgets, label, roots, forbidden) {
59
59
  return errors;
60
60
  }
61
61
  /** Static dependencies of the original public title's explicit dynamic roots.
62
- * Count shared chunks once; optional settings and gameplay stay outside. */
62
+ * Count shared chunks once; optional settings and gameplay stay outside.
63
+ * Ceilings 160 KB gzip / 500 KB raw (J324, Jake 2026-11-13: "A 1 megabyte title page is fine"; was 110 KB / 350 KB). */
63
64
  export function titleClosureBudgetErrors(modules, budgets) {
64
65
  // C3: the title's rows are data in its document, so the cold title loads no generated module
65
66
  return closureBudgetErrors(modules, budgets, 'title', titleRoots, id => /node_modules\/(?:three|@dimforge\/rapier[^/]*)(?:\/|$)/u.test(id)
@@ -0,0 +1,5 @@
1
+ // HOW-WE-BUILD ENG-16: types for scripts/devserver-client.mjs.
2
+ /** The release asset's name; sharddev's `DEV_CLIENT_ASSET` reads the same. */
3
+ export declare const DEV_CLIENT_ASSET: string;
4
+ /** Prune a devserver build in place to the client an author's page reads. */
5
+ export declare function pruneDevserverClient(client: string): void;
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ // HOW-WE-BUILD ENG-16 (meta SHARD-AUTHORING SA15, J314): engine's devserver client, the page an installed `wildshard dev`
3
+ // serves around an author's shard. sharddev can't build it (it is this repo's whole app build), so server-release.yml puts
4
+ // it on the GitHub release of every tag it publishes (`server-staging-<sha>` for green main, `vX.Y.Z`), and sharddev's
5
+ // `src/sharddev/devClient.ts` fetches it once per engine pin.
6
+ //
7
+ // The archive is `build-app.mjs --mode devserver`, minus what only a first-party page reads: the pinned shards' folders
8
+ // (their `discovery.json` stays, the title deck reads it), their asset folders and KTX2 and baked textures, spawn sets,
9
+ // programs, drafts, trailers and source maps. The author's own shard comes from `wildshard dev`'s build.
10
+ //
11
+ // python3 scripts/heavy-lane.py build -- node scripts/devserver-client.mjs --out <devserver-client.tar.gz> [--keep <folder>]
12
+ import { execFileSync, spawnSync } from 'node:child_process';
13
+ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
14
+ import { join, relative, resolve } from 'node:path';
15
+ import { pathToFileURL } from 'node:url';
16
+
17
+ const ROOT = resolve(import.meta.dirname, '..');
18
+ /** The release asset's name; sharddev's `DEV_CLIENT_ASSET` reads the same. */
19
+ export const DEV_CLIENT_ASSET = 'devserver-client.tar.gz';
20
+ /** Top-level paths (and `assets/` folders) a devserver page never reads. */
21
+ const DROP_TOP = ['programs', 'drafts', 'trailer-15.mp4', 'trailer-30.mp4'];
22
+ const DROP_ASSETS = ['driftwood-isle', 'far-reach', 'nalati', 'nine-dragon', 'pine-hollow', 'sunscar-dunes', 'practice'];
23
+ /** `assets/gpu/` (KTX2 stand-ins): the shards' own folders go; the engine's `tex`, `models` and `horizon` stay. */
24
+ const DROP_GPU = ['baked', 'far-reach', 'nalati', 'nine-dragon', 'pine-hollow'];
25
+
26
+ /** Prune a devserver build in place to the client an author's page reads. @param {string} client */
27
+ export function pruneDevserverClient(client) {
28
+ const flags = JSON.parse(readFileSync(join(client, 'build-flags.json'), 'utf8'));
29
+ if (flags?.devserver !== true) throw new Error('devserver-client: the build is not in devserver mode');
30
+ for (const name of DROP_TOP) rmSync(join(client, name), { recursive: true, force: true });
31
+ for (const name of DROP_ASSETS) rmSync(join(client, 'assets', name), { recursive: true, force: true });
32
+ for (const name of DROP_GPU) rmSync(join(client, 'assets', 'gpu', name), { recursive: true, force: true });
33
+ // baked: only the engine's common bake; spawn: only the in-page server's book (`server-<build>.json`)
34
+ for (const [folder, keep] of /** @type {const} */ ([['assets/baked', name => name === 'common'], ['assets/spawn', name => /^server-.+\.json$/u.test(name)]])) {
35
+ const path = join(client, folder);
36
+ if (existsSync(path)) for (const name of readdirSync(path)) if (!keep(name)) rmSync(join(path, name), { recursive: true, force: true });
37
+ }
38
+ const shardfiles = join(client, 'shardfiles');
39
+ if (existsSync(shardfiles)) for (const slug of readdirSync(shardfiles)) {
40
+ for (const name of readdirSync(join(shardfiles, slug))) if (name !== 'discovery.json') rmSync(join(shardfiles, slug, name), { recursive: true, force: true });
41
+ }
42
+ for (const entry of readdirSync(client, { recursive: true, withFileTypes: true })) if (entry.isFile() && entry.name.endsWith('.map')) rmSync(join(entry.parentPath, entry.name));
43
+ }
44
+
45
+ /** @param {string} folder @returns {number} */
46
+ const bytesOf = folder => readdirSync(folder, { recursive: true, withFileTypes: true }).reduce((sum, entry) => sum + (entry.isFile() ? statSync(join(entry.parentPath, entry.name)).size : 0), 0);
47
+
48
+ if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
49
+ const args = process.argv.slice(2), option = (/** @type {string} */ name) => { const at = args.indexOf(`--${name}`); return at === -1 ? undefined : args[at + 1]; };
50
+ const out = resolve(option('out') ?? join('tmp', 'devserver-client', DEV_CLIENT_ASSET));
51
+ const client = resolve(option('keep') ?? join(ROOT, 'tmp', 'devserver-client', 'client'));
52
+ if (relative(ROOT, client).startsWith('..')) throw new Error('devserver-client: the build folder must be inside this checkout (build-app defers its public copy there)');
53
+ rmSync(client, { recursive: true, force: true });
54
+ const built = spawnSync(process.execPath, ['scripts/build-app.mjs', '--mode', 'devserver', '--outDir', client], {
55
+ cwd: ROOT, stdio: 'inherit', env: { ...process.env, WILDSHARD_CATALOGUE: process.env.WILDSHARD_CATALOGUE ?? 'test/pins/catalogue.json' } });
56
+ if (built.status !== 0) throw new Error(`devserver-client: build-app exited ${String(built.status)}`);
57
+ const before = bytesOf(client);
58
+ pruneDevserverClient(client);
59
+ mkdirSync(resolve(out, '..'), { recursive: true });
60
+ // the same bytes for the same tree: sorted names, no owners or times (as the dedicated bundle is packed in server-release.yml)
61
+ const tar = spawnSync('tar', ['--version'], { encoding: 'utf8' }).stdout.includes('GNU') ? 'tar' : 'gtar';
62
+ const gnu = spawnSync(tar, ['--version'], { encoding: 'utf8' }).status === 0;
63
+ execFileSync('bash', ['-c', gnu
64
+ ? `set -euo pipefail; ${tar} --sort=name --mtime='@0' --owner=0 --group=0 --numeric-owner -cf - -C "$1" . | gzip -n > "$2"`
65
+ : 'set -euo pipefail; tar -cf - -C "$1" . | gzip -n > "$2"', 'pack', client, out], { stdio: 'inherit' });
66
+ console.log(`devserver-client: ${(before / 1e6).toFixed(0)} MB built, ${(bytesOf(client) / 1e6).toFixed(0)} MB kept, ${(statSync(out).size / 1e6).toFixed(1)} MB packed: ${out}`);
67
+ if (option('keep') === undefined) rmSync(client, { recursive: true, force: true });
68
+ }
@@ -29,11 +29,17 @@ export default class EngineBudget implements Reporter{
29
29
  const ledger=readTimings()?.amber??{},now=Date.now();
30
30
  const verdicts=files.map(file=>judgeFile(file.file,file.durationMs,this.limit,ledger[file.file],now)).filter(verdict=>verdict.level!=='ok');
31
31
  const amber=verdicts.filter(verdict=>verdict.level==='amber'),red=verdicts.filter(verdict=>verdict.level==='red');
32
+ // AUDIO AU6 (J303, J295): the cook report's test annotates each shard whose audio is over its line. The lines join
33
+ // the report's amber list, so the timings job repeats them for a main run that reused its plan-branch run, and
34
+ // main-watch reads them as `main AMBER … audio` receipts. Never an error: they change no exit code.
35
+ const audio=modules.flatMap(module=>[...module.children.allTests()].flatMap(test=>test.annotations().map(note=>note.message).filter(message=>message.startsWith('AMBER audio '))));
32
36
  const out=resolve(timings??`tmp/engine-ci/timings-${process.pid}.json`);mkdirSync(dirname(out),{recursive:true});
33
37
  writeFileSync(out,`${JSON.stringify({schema:'engine-ci-budget/2',sha:sha??null,run:run??null,attempt:attempt??null,reason,errorCount:errors.length,startedAt:this.began,endedAt:now,
34
- budget:{limitMs:this.limit,amber:amber.map(row=>amberLine(row,run)),red:red.map(row=>amberLine(row,run))},files},null,2)}\n`);
38
+ budget:{limitMs:this.limit,amber:[...amber.map(row=>amberLine(row,run)),...audio],red:red.map(row=>amberLine(row,run))},files},null,2)}\n`);
35
39
  for(const row of amber)console.error(`::warning file=${row.file},title=AMBER test file over budget (J295)::${amberLine(row,run)}`);
36
40
  for(const row of red)console.error(`::error file=${row.file}::CI test file ${row.ms} ms exceeds ${row.budget} ms, red: ${row.why}. ${amberLine(row,run)}`);
41
+ // One annotation for them all: GitHub keeps only 10 warnings a step.
42
+ if(audio.length>0)console.error(`::warning title=AMBER shard audio over 6 MB (J303)::${audio.join('%0A')}`);
37
43
  if(red.length>0)process.exitCode=1;
38
44
  }
39
45
  }
@@ -12,6 +12,8 @@ const LOCK = 'pnpm-lock.yaml';
12
12
  const FORMAT = '@wildshard/format';
13
13
  const PACKAGE = '@wildshard/shard-format';
14
14
  const PIN = /^github:project-wildshard\/shard-format#(v\d+\.\d+\.\d+)$/u;
15
+ // NPM-PUBLISH NP6: the registry release, by the same alias (`npm:@wildshard/shard-format@^0.4.9`); its lock row is an integrity, no commit
16
+ const NPM_PIN = /^npm:@wildshard\/shard-format@\^?\d+\.\d+\.\d+$/u;
15
17
  const SECTIONS = ['dependencies', 'devDependencies', 'optionalDependencies'];
16
18
  const FETCH_MS = 8000;
17
19
 
@@ -26,16 +28,21 @@ function parseLock(text) {
26
28
  const block = start === -1 || end === -1 ? '' : text.slice(start, end), keys = [...block.matchAll(/^ {2}(\S+):$/gmu)];
27
29
  keys.forEach((key, index) => {
28
30
  const body = block.slice(key.index, keys[index + 1]?.index);
29
- // pnpm locks a github pin as git (`git+ssh://…#<commit>`) or as a codeload tarball (`…/tar.gz/<commit>`)
30
- const row = /^ {6}'@wildshard\/format':\n {8}specifier: (\S+)\n {8}version: \S*?(?:#|\/tar\.gz\/)([0-9a-f]{40})/mu.exec(body);
31
- if (row !== null) importers.set(key[1], { specifier: row[1], commit: row[2] });
31
+ // pnpm locks a github pin as git (`git+ssh://…#<commit>`) or as a codeload tarball (`…/tar.gz/<commit>`), an npm one by version
32
+ const row = /^ {6}'@wildshard\/format':\n {8}specifier: (\S+)\n {8}version: (\S+)/mu.exec(body);
33
+ const version = row?.[2] ?? '';
34
+ if (row !== null) importers.set(key[1], { specifier: row[1], commit: /(?:#|\/tar\.gz\/)([0-9a-f]{40})/u.exec(version)?.[1],
35
+ registry: /^'?@wildshard\/shard-format@(\d+\.\d+\.\d+[^('\s]*)/u.exec(version)?.[1] });
32
36
  });
33
- const rows = [...text.matchAll(/^ {2}'@wildshard\/shard-format@[^']*':\n {4}resolution: \{([^}\n]*)\}\n(?: {4}version: (\S+)\n)?/gmu)]
37
+ const rows = [...text.matchAll(/^ {2}'@wildshard\/shard-format@([^']*)':\n {4}resolution: \{([^}\n]*)\}\n(?: {4}version: (\S+)\n)?/gmu)]
38
+ .map(([, key, resolution, version]) => [resolution, version, key])
34
39
  .map(row => {
35
- const git = /^commit: ([0-9a-f]{40}), repo: ([^,]+), type: git$/u.exec(row[1] ?? '');
36
- if (git !== null) return { commit: git[1], repo: git[2], version: row[2] };
37
- const tarball = /tarball: https:\/\/codeload\.github\.com\/([\w.-]+\/[\w.-]+)\/tar\.gz\/([0-9a-f]{40})$/u.exec(row[1] ?? '');
38
- return { commit: tarball?.[2], repo: tarball === null ? undefined : `https://github.com/${tarball[1]}.git`, version: row[2] };
40
+ // NP6: a registry row is keyed by its version and resolved by integrity alone
41
+ if (/^integrity: sha512-[^,]+$/u.test(row[0] ?? '') && /^\d+\.\d+\.\d+/u.test(row[2] ?? '')) return { commit: undefined, repo: undefined, version: row[2], registry: true };
42
+ const git = /^commit: ([0-9a-f]{40}), repo: ([^,]+), type: git$/u.exec(row[0] ?? '');
43
+ if (git !== null) return { commit: git[1], repo: git[2], version: row[1], registry: false };
44
+ const tarball = /tarball: https:\/\/codeload\.github\.com\/([\w.-]+\/[\w.-]+)\/tar\.gz\/([0-9a-f]{40})$/u.exec(row[0] ?? '');
45
+ return { commit: tarball?.[2], repo: tarball === null ? undefined : `https://github.com/${tarball[1]}.git`, version: row[1], registry: false };
39
46
  });
40
47
  return { importers, keys: keys.map(key => key[1]), rows };
41
48
  }
@@ -48,7 +55,7 @@ export function formatLockFailures(read, workflows = []) {
48
55
  const { importers, keys, rows } = parseLock(text);
49
56
  const row = rows[0];
50
57
  if (rows.length !== 1 || row === undefined) return [`${LOCK}: expected one ${PACKAGE} package row, found ${rows.length}`];
51
- if (row.commit === undefined) return [`${LOCK}: ${PACKAGE} row's resolution is neither a git commit nor a codeload tarball`];
58
+ if (row.commit === undefined && !row.registry) return [`${LOCK}: ${PACKAGE} row's resolution is neither a git commit, a codeload tarball nor a registry integrity`];
52
59
  const pins = new Set();
53
60
  for (const key of keys) {
54
61
  const file = key === '.' ? 'package.json' : `${key}/package.json`, manifest = read(file);
@@ -59,10 +66,12 @@ export function formatLockFailures(read, workflows = []) {
59
66
  if (locked !== undefined) failures.push(`${LOCK}: importer ${key} locks ${FORMAT} but ${file} doesn't name it`);
60
67
  continue;
61
68
  }
62
- if (!PIN.test(pin)) failures.push(`${file}: ${FORMAT} pin ${pin} isn't a shard-format release tag`);
69
+ const npm = NPM_PIN.test(pin);
70
+ if (!npm && !PIN.test(pin)) failures.push(`${file}: ${FORMAT} pin ${pin} isn't a shard-format release tag or npm release`);
63
71
  pins.add(pin);
64
72
  if (locked?.specifier !== pin) failures.push(`${file}: ${FORMAT} pin ${pin} but ${LOCK} has ${locked?.specifier ?? 'no row'}`);
65
- else if (locked.commit !== row.commit) failures.push(`${LOCK}: importer ${key} locks ${locked.commit}, its package row ${row.commit}`);
73
+ else if (npm !== row.registry) failures.push(`${LOCK}: importer ${key} pins ${npm ? 'the npm release' : 'a git tag'}, its package row is ${row.registry ? 'a registry' : 'a git'} row`);
74
+ else if (npm ? locked.registry !== row.version : locked.commit !== row.commit) failures.push(`${LOCK}: importer ${key} locks ${npm ? locked.registry : locked.commit}, its package row ${npm ? row.version : row.commit}`);
66
75
  }
67
76
  if (pins.size > 1) failures.push(`package.json: ${FORMAT} pins disagree: ${[...pins].join(', ')}`);
68
77
  const tag = pins.size === 1 ? PIN.exec([...pins][0] ?? '')?.[1] : undefined;
@@ -14,7 +14,8 @@ const source = readFileSync(resolve(root, 'index.html'), 'utf8');
14
14
  const style = /<style>([\s\S]*?)<\/style>/u.exec(source)?.[1];
15
15
  const shell = /<div class="ws-launch" data-title-shell>[\s\S]*?<\/div><!-- \/title-shell -->/u.exec(source)?.[0];
16
16
  if (style === undefined || shell === undefined) throw new Error('Missing first-document title shell');
17
- // Standalone content starts below the 62 px phone status area (index.html E58).
17
+ // Standalone content starts below the 62 px phone status area (index.html E58). The pill and bar (QA 11-13) are live
18
+ // elements a script fills; iOS's still image before the document keeps the approved hero and wordmark only.
18
19
  const nativeInset = 62;
19
20
  const previous = /rel="apple-touch-startup-image" href="([^"]+)"/u.exec(source)?.[1];
20
21
  if (previous === undefined) throw new Error('Missing native launch image link');
@@ -27,7 +28,7 @@ try {
27
28
  await context.route('http://launch.test/**', async route => {
28
29
  const path = new URL(route.request().url()).pathname;
29
30
  if (path === '/') {
30
- await route.fulfill({ contentType: 'text/html', body: `<!doctype html><html class="title-first"><head><meta name="viewport" content="width=device-width, initial-scale=1"><style>${style} html.title-first .ws-launch { top: ${nativeInset}px; }</style></head><body>${shell}</body></html>` });
31
+ await route.fulfill({ contentType: 'text/html', body: `<!doctype html><html class="title-first"><head><meta name="viewport" content="width=device-width, initial-scale=1"><style>${style} html.title-first .ws-launch { top: ${nativeInset}px; } .ws-launch-pill, .ws-launch-load { visibility: hidden; }</style></head><body>${shell}</body></html>` });
31
32
  } else if (path.startsWith('/assets/title/') || path.startsWith('/fonts/')) {
32
33
  const asset = resolve(root, 'public', `.${titleSources.get(path) ?? path}`);
33
34
  if (!asset.startsWith(`${resolve(root, 'public')}/`)) throw new Error('Invalid launch asset');
@@ -4,7 +4,7 @@
4
4
  // from the deck's card, then walks into a same-worker neighbour (Sunscar, or Pine Hollow), boosts back into Driftwood and boosts out again, by
5
5
  // real input. Each leg passes with no stop (no 1.5 s under 0.15 m a sample while the key is held), no page reload, and control in the
6
6
  // target cell (the page inside it, gameplay ready, the player moving). It writes time-to-control per leg beside GC1's baseline.
7
- // scripts/browser-lane.sh node scripts/grid-crossing-walk-proof.mjs <app dist stamped with http://127.0.0.1:18799/release.json> <work dir> <key.json> [--engine=chromium|webkit] [--to=sunscar|pine] [--out=<dir>]
7
+ // scripts/browser-lane.sh node scripts/grid-crossing-walk-proof.mjs <app dist stamped with http://127.0.0.1:18799/release.json> <work dir> <key.json> [--engine=chromium|webkit] [--to=sunscar|pine|farreach|nalati] [--workers=2] [--base=<staging url>] [--out=<dir>]
8
8
  import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
9
9
  import { join, resolve as absolute } from 'node:path';
10
10
  import { chromium, webkit } from 'playwright';
@@ -13,7 +13,7 @@ import { saveFixture } from './debug-settings.mjs';
13
13
  import { openRig, WORLD_PORT } from './online-rig.mjs';
14
14
 
15
15
  const [dist = '', relativeWork = '', keyFile = ''] = process.argv.slice(2).filter(arg => !arg.startsWith('--')), work = relativeWork === '' ? '' : absolute(relativeWork);
16
- if (dist === '' || work === '' || keyFile === '') throw new Error('usage: grid-crossing-walk-proof.mjs <dist> <work> <key.json> [--engine=chromium|webkit] [--to=sunscar|pine] [--out=<dir>]');
16
+ if (dist === '' || work === '' || keyFile === '') throw new Error('usage: grid-crossing-walk-proof.mjs <dist> <work> <key.json> [--engine=chromium|webkit] [--to=sunscar|pine|farreach|nalati] [--out=<dir>]');
17
17
  const engineName = process.argv.find(arg => arg.startsWith('--engine='))?.slice(9) ?? 'chromium', out = absolute(process.argv.find(arg => arg.startsWith('--out='))?.slice(6) ?? join(work, 'shots'));
18
18
  if (engineName !== 'chromium' && engineName !== 'webkit') throw new Error(`No engine ${engineName}`);
19
19
  mkdirSync(out, { recursive: true });
@@ -23,7 +23,9 @@ mkdirSync(out, { recursive: true });
23
23
  // (`sections/world/edge.json`), so a crossing goes through it: `approach` are waypoints in Driftwood's frame, boosted and not scored,
24
24
  // that end in front of it; the legs then walk straight through it.
25
25
  const NEIGHBOURS = /** @type {Record<string, { slug: string, axis: 'x' | 'z', sign: number, approach: [number, number][] }>} */ ({
26
- pine: { slug: 'pine-hollow', axis: 'z', sign: 1, approach: [[-235, -194], [-235, 235], [0, 235]] }, sunscar: { slug: 'sunscar-dunes', axis: 'x', sign: -1, approach: [[-235, -194], [-235, 0]] } });
26
+ pine: { slug: 'pine-hollow', axis: 'z', sign: 1, approach: [[-235, -194], [-235, 235], [0, 235]] }, sunscar: { slug: 'sunscar-dunes', axis: 'x', sign: -1, approach: [[-235, -194], [-235, 0]] },
27
+ // GC29 (Jake 11-13): his walk off the south dock toward Far Reach, and east into Nalati (staging: another worker).
28
+ farreach: { slug: 'far-reach', axis: 'z', sign: -1, approach: [[0, -235]] }, nalati: { slug: 'nalati-grasslands', axis: 'x', sign: 1, approach: [[235, -194], [235, 0]] } });
27
29
  const toName = process.argv.find(arg => arg.startsWith('--to='))?.slice(5) ?? 'sunscar', to = NEIGHBOURS[toName];
28
30
  if (to === undefined) throw new Error(`No neighbour ${toName}: ${Object.keys(NEIGHBOURS).join(', ')}`);
29
31
  const HOME = 'driftwood-isle', NEXT = to.slug, STUCK_MS = 1500, LEG_MS = 100_000;
@@ -35,14 +37,20 @@ const note = (step, ok, detail) => { steps.push({ step, ok, ...detail === undefi
35
37
  /** @param {number} ms */
36
38
  const sleep = ms => new Promise(resolve => { setTimeout(resolve, ms); });
37
39
 
38
- const rig = await openRig({ dist, work, keyFile, pgBin: 'memory:', pgData: '', shard: HOME, more: ['pine-hollow', 'far-reach', 'sunscar-dunes', 'nalati-grasslands'], cells: 'grid', crossing: true, workers: 2 });
40
+ // `--base=<url>`: a served site instead of the rig (staging only, J205: a read-only join; never production). dist and key.json are unused.
41
+ const served = process.argv.find(arg => arg.startsWith('--base='))?.slice(7) ?? '';
42
+ if (served !== '' && !/^https:\/\/(staging|preview)\.wildshard\.io\/?$|^http:\/\/127\.0\.0\.1:\d+\/?$/.test(served)) throw new Error('--base takes staging, preview or a loopback page only: never production (J205)');
43
+ const workers = Number(process.argv.find(arg => arg.startsWith('--workers='))?.slice(10) ?? 2);
44
+ if (!Number.isInteger(workers) || workers < 1) throw new Error('--workers takes a whole number from 1');
45
+ const rig = served !== '' ? { base: served.replace(/\/$/, ''), close: () => Promise.resolve() }
46
+ : await openRig({ dist, work, keyFile, pgBin: 'memory:', pgData: '', shard: HOME, more: ['pine-hollow', 'far-reach', 'sunscar-dunes', 'nalati-grasslands'], cells: 'grid', crossing: true, workers });
39
47
  let code = 1, browser = /** @type {import('playwright').Browser | null} */ (null);
40
48
  /** @type {Record<string, unknown>} */
41
- const result = { lane: 'opus-gc15c', engine: engineName, layout: 'desktop 1440x900', site: 'local rig, WORLD_CELLS=grid, WORLD_CROSSING=worker, WORLD_WORKERS=2 (staging: Nalati alone, Driftwood with Pine Hollow, Sunscar and Far Reach)' };
49
+ const result = { lane: 'opus-gc15c', engine: engineName, layout: 'desktop 1440x900', site: served !== '' ? served : 'local rig, WORLD_CELLS=grid, WORLD_CROSSING=worker, WORLD_WORKERS=2 (staging: Nalati alone, Driftwood with Pine Hollow, Sunscar and Far Reach)' };
42
50
  try {
43
- let open = null;
51
+ let open = served !== '' ? { cells: 25 } : null;
44
52
  for (let tries = 0; tries < 300 && open === null; tries++) { open = await fetch(`http://127.0.0.1:${String(WORLD_PORT)}/health`).then(found => found.ok ? found.json() : null).catch(() => null); if (open === null) await sleep(200); }
45
- note('the world runs the grid', open !== null && open.cells > 1, { cells: open?.cells });
53
+ note('the world runs the grid', open !== null && open.cells > 1, served !== '' ? { skipped: 'a served site: not read' } : { cells: open?.cells });
46
54
  if (open === null) throw new Error(`The world did not start: see ${join(work, 'server.log')}`);
47
55
  browser = await (engineName === 'webkit' ? webkit : chromium).launch({ headless: true, args: engineName === 'chromium' ? [...KEYCHAIN_ARGS, '--mute-audio', '--use-angle=metal', '--ignore-gpu-blocklist'] : [] });
48
56
  const context = await browser.newContext({ viewport: { width: 1440, height: 900 } }), page = await context.newPage(), errors = /** @type {string[]} */ ([]);
@@ -162,7 +170,7 @@ try {
162
170
  code = steps.every(step => step.ok) ? 0 : 1;
163
171
  } catch (error) { note('the run', false, String(error).slice(0, 400)); }
164
172
  finally {
165
- const log = readFileSync(join(work, 'server.log'), 'utf8').split('\n');
173
+ const log = served !== '' ? [] : readFileSync(join(work, 'server.log'), 'utf8').split('\n');
166
174
  result.server = { road: log.filter(line => line.includes('road.pack')).slice(0, 2), booted: log.filter(line => line.includes('cell.booted')).length };
167
175
  result.steps = steps; result.code = code;
168
176
  writeFileSync(join(out, `${engineName}-gc15c-walk.json`), `${JSON.stringify(result, null, 2)}\n`);
@@ -162,11 +162,35 @@ def wait_label(seconds):
162
162
  return '5 min' if seconds == 5 * 60 else '%gs' % seconds
163
163
 
164
164
 
165
+ def reap_dead(root, slot):
166
+ """True (and the lease file removed) when a slot's lease names a runner and child that both exited and its lock is free.
167
+
168
+ A SIGKILLed owner never runs its cleanup, so its `.active.json` outlives it; its flock went with it, so the slot is free.
169
+ A lock still held with both pids dead is an orphaned grandchild that inherited the fd: a real holder, kept and named.
170
+ The check and the unlink run under the slot's own lock, so a new owner's lease is never removed."""
171
+ path = root / (slot + '.active.json')
172
+ try:
173
+ with (root / (slot + '.lock')).open('a+') as lock:
174
+ try:
175
+ fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
176
+ except BlockingIOError:
177
+ return False
178
+ entry = read_entry(path)
179
+ pids = [entry.get(key) for key in ('runnerPid', 'childPid') if entry.get(key) is not None]
180
+ if not pids or not all(isinstance(pid, int) and 0 < pid < 2**31 for pid in pids) or any(alive(pid) for pid in pids):
181
+ return False
182
+ path.unlink(missing_ok=True)
183
+ return True
184
+ except OSError:
185
+ return False
186
+
187
+
165
188
  def queue_timeout(root, entry):
166
189
  slots = set(slot for resource in entry['resources'] for slot in (BUILD_SLOTS if resource == 'build' else (resource,)))
167
190
  if 'full-test' in slots:
168
191
  slots.update(path.name[:-len('.active.json')] for path in root.glob('full-test-*.active.json'))
169
- holders = [holder(slot, read_entry(root / (slot + '.active.json'))) for slot in sorted(slots)]
192
+ # 2026-11-13: a killed push gate's lease was named as the holder for 2.8 h and hid the real one
193
+ holders = [holder(slot, read_entry(root / (slot + '.active.json'))) for slot in sorted(slots) if not reap_dead(root, slot)]
170
194
  queued = read_entry(root / 'queue.json').get('queue', [])
171
195
  holders.extend('queue head ' + holder('/'.join(row['resources']), row) for row in queued
172
196
  if row['token'] != entry['token'] and row['ticket'] < entry['ticket']