@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.
- package/CHANGELOG.md +23 -0
- package/index.html +157 -11
- package/lint/engine-sides.json +23 -0
- package/lint/host-callback-syntax.mjs +2 -1
- package/lint/host-callbacks.mjs +3 -3
- package/lint/host-files.mjs +5 -4
- package/lint/host-register.json +496 -0
- package/lint/no-base64.mjs +3 -1
- package/lint/ratchet.json +2 -2
- package/lint/shard-imports.d.mts +1 -0
- package/lint/shard-imports.mjs +60 -13
- package/lint/shard-source.d.mts +9 -0
- package/lint/shard-source.mjs +91 -0
- package/lint/shardfile-boundaries.mjs +10 -8
- package/lint/sim-closure.mjs +6 -3
- package/lint/wildshard-plugin.d.ts +4 -0
- package/lint/wildshard-plugin.js +44 -27
- package/package.json +24 -6
- package/scripts/app-build/buildIdentity.d.mts +3 -1
- package/scripts/app-build/buildIdentity.mjs +25 -5
- package/scripts/app-build/builtAt.d.mts +4 -0
- package/scripts/app-build/builtAt.mjs +21 -0
- package/scripts/app-build/outputProducts.d.mts +3 -0
- package/scripts/app-build/outputProducts.mjs +31 -0
- package/scripts/app-build/serviceWorker.ts +16 -2
- package/scripts/app-build/versionFiles.ts +2 -1
- package/scripts/app-build-pipeline.mjs +7 -1
- package/scripts/audio-download-proof.mjs +843 -0
- package/scripts/build-app.mjs +4 -0
- package/scripts/build-mirror.d.mts +2 -0
- package/scripts/build-mirror.mjs +5 -4
- package/scripts/built-product.mjs +3 -3
- package/scripts/cell-mem/metrics-preload.mjs +65 -0
- package/scripts/cell-mem-bench.mjs +130 -0
- package/scripts/check-chunks.mjs +2 -1
- package/scripts/check-devserver.mjs +1 -1
- package/scripts/chromium-keychain-check.mjs +4 -2
- package/scripts/chromium-keychain.mjs +3 -1
- package/scripts/cook.mjs +7 -3
- package/scripts/devices.d.mts +4 -0
- package/scripts/devices.mjs +39 -0
- package/scripts/devserver-client.d.mts +7 -0
- package/scripts/devserver-client.mjs +85 -0
- package/scripts/doctor-proof.mjs +1 -1
- package/scripts/e2e-faults.mjs +159 -0
- package/scripts/engine-ci-budget.ts +7 -1
- package/scripts/format-lock.mjs +20 -11
- package/scripts/generate-title-launch.mjs +3 -2
- package/scripts/grid-crossing-walk-proof.mjs +30 -11
- package/scripts/heavy-lane.py +25 -1
- package/scripts/host-ruler/register-migrate.mjs +242 -0
- package/scripts/host-ruler/register.d.mts +36 -0
- package/scripts/host-ruler/register.mjs +116 -0
- package/scripts/host-ruler/roots.d.mts +29 -0
- package/scripts/host-ruler/roots.mjs +333 -0
- package/scripts/host-ruler/server-roots.d.mts +23 -0
- package/scripts/host-ruler/server-roots.mjs +272 -0
- package/scripts/main-watch.d.mts +1 -1
- package/scripts/main-watch.mjs +10 -6
- package/scripts/map-hash.mjs +3 -6
- package/scripts/memory-proof.mjs +158 -0
- package/scripts/mmo-bots.mjs +2 -2
- package/scripts/offline-proof-rules.d.mts +5 -2
- package/scripts/offline-proof-rules.mjs +43 -6
- package/scripts/offline-proof.mjs +15 -6
- package/scripts/online-rig.mjs +4 -4
- package/scripts/page-release/flow.d.mts +1 -0
- package/scripts/page-release/flow.mjs +6 -2
- package/scripts/page-release.mjs +5 -1
- package/scripts/physics-route.json +0 -71
- package/scripts/pins-catalogue.ts +103 -0
- package/scripts/pins-reuse.mjs +3 -1
- package/scripts/pins.ts +22 -14
- package/scripts/preview-grid.ts +203 -0
- package/scripts/road-preload-proof.mjs +167 -0
- package/scripts/server-release/publish.mjs +2 -2
- package/scripts/server-release/served-slug.d.mts +2 -0
- package/scripts/server-release/served-slug.mjs +10 -0
- package/scripts/server-release/sign.d.mts +1 -0
- package/scripts/server-release/sign.mjs +3 -7
- package/scripts/shard-components.mjs +0 -2
- package/scripts/shard-outputs.d.mts +8 -0
- package/scripts/shard-outputs.mjs +45 -11
- package/scripts/side-parity.d.mts +2 -1
- package/scripts/side-parity.mjs +25 -4
- package/scripts/test-amber.d.mts +1 -0
- package/scripts/test-amber.mjs +10 -0
- package/scripts/test-products.json +3 -3
- package/scripts/tier-textures-proof.mjs +101 -0
- package/scripts/tier-textures.mjs +60 -0
- package/scripts/tracked-public.d.mts +1 -0
- package/scripts/tracked-public.mjs +17 -0
- package/scripts/tsconfig.json +1 -0
- package/scripts/vps/wildshard-config +79 -23
- package/scripts/worker-client-play.mjs +1 -0
- package/scripts/worker-client-proof.mjs +1 -1
- package/scripts/worker-client-slug.mjs +44 -0
- package/src/cli/engine.mjs +8 -0
- package/src/client/app/bootRoute.ts +4 -1
- package/src/client/app/dropModal.ts +15 -2
- package/src/client/app/entry.ts +96 -13
- package/src/client/app/slugPath.ts +5 -0
- package/src/client/engine/audio/Audio.ts +20 -2
- package/src/client/engine/boot/bakedTextures.ts +3 -2
- package/src/client/engine/boot/bootTrace.ts +6 -1
- package/src/client/engine/boot/bytes.ts +4 -3
- package/src/client/engine/boot/clearDownloads.ts +1 -1
- package/src/client/engine/boot/contentRead.ts +4 -0
- package/src/client/engine/boot/dropNotice.ts +20 -6
- package/src/client/engine/boot/gpuFiles.ts +25 -2
- package/src/client/engine/boot/lastEnd.ts +8 -2
- package/src/client/engine/boot/parsedPages.ts +127 -58
- package/src/client/engine/boot/shardPrefetch.ts +7 -1
- package/src/client/engine/boot/sw.ts +19 -0
- package/src/client/engine/build.d.ts +2 -0
- package/src/client/engine/core/Game.ts +29 -3
- package/src/client/engine/core/GpuRecovery.ts +7 -0
- package/src/client/engine/core/Volumetrics.ts +5 -0
- package/src/client/engine/core/assets.ts +27 -20
- package/src/client/engine/core/bootstrap.ts +5 -3
- package/src/client/engine/core/ktx2.ts +84 -11
- package/src/client/engine/debug/probe.ts +18 -1
- package/src/client/engine/explore/Compare.ts +2 -2
- package/src/client/engine/explore/TouchFly.ts +3 -5
- package/src/client/engine/fx/LightPool.ts +41 -1
- package/src/client/engine/input/dom.ts +12 -0
- package/src/client/engine/net/predictor.ts +6 -2
- package/src/client/engine/player/Player.ts +10 -2
- package/src/client/engine/player/TouchControls.ts +12 -4
- package/src/client/engine/pwa/sw.js +59 -11
- package/src/client/engine/render/drawCheck.ts +96 -0
- package/src/client/engine/render/precompile.ts +20 -14
- package/src/client/engine/saves/staleBuildNote.ts +46 -0
- package/src/client/engine/telemetry/browserErrors.ts +161 -21
- package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
- package/src/client/engine/telemetry/screenOutbox.ts +61 -0
- package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
- package/src/client/engine/ui/DeathFade.ts +99 -11
- package/src/client/engine/ui/ErrorModal.ts +13 -6
- package/src/client/engine/ui/Feedback.ts +2 -1
- package/src/client/engine/ui/Loading.ts +10 -6
- package/src/client/engine/ui/Map.ts +2 -1
- package/src/client/engine/ui/WeaponStrip.ts +2 -1
- package/src/client/engine/ui/backGuard.ts +104 -0
- package/src/client/engine/ui/hudAdapters.ts +30 -4
- package/src/client/engine/ui/loading.css +17 -0
- package/src/client/engine/ui/namePrompt.ts +6 -5
- package/src/client/engine/ui/styles/combat.css +12 -0
- package/src/client/engine/ui/styles/namePrompt.css +4 -2
- package/src/client/game/boot/audio.generated.ts +0 -396
- package/src/client/game/boot/bytes.generated.ts +42 -71
- package/src/client/game/boot/versions.generated.ts +0 -13
- package/src/client/game/compendium/keepsakes.ts +16 -6
- package/src/client/game/grapple/tool.ts +10 -7
- package/src/client/game/grid/area.ts +38 -0
- package/src/client/game/grid/cellLoading.ts +23 -12
- package/src/client/game/grid/cellScreens.ts +39 -74
- package/src/client/game/grid/live.ts +28 -2
- package/src/client/game/grid/liveSession.ts +54 -10
- package/src/client/game/grid/menu.ts +4 -0
- package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
- package/src/client/game/grid/nearPlaceholderView.ts +9 -3
- package/src/client/game/grid/neighbourPanels.ts +10 -1
- package/src/client/game/grid/oneWayIn.ts +92 -27
- package/src/client/game/grid/pageEntry.ts +19 -0
- package/src/client/game/grid/pageShell.ts +1 -1
- package/src/client/game/grid/placedCards.ts +55 -0
- package/src/client/game/grid/placedCells.ts +131 -0
- package/src/client/game/grid/plotAudio.ts +114 -0
- package/src/client/game/grid/products.ts +55 -5
- package/src/client/game/grid/regionalRuntime.ts +6 -0
- package/src/client/game/grid/regionalWorld.ts +15 -2
- package/src/client/game/grid/roadCull.ts +44 -14
- package/src/client/game/grid/roadLookPlatform.ts +2 -2
- package/src/client/game/grid/roadTileBacking.ts +13 -3
- package/src/client/game/grid/session.ts +47 -22
- package/src/client/game/grid/shardfileFar.ts +9 -3
- package/src/client/game/grid/spawnGround.ts +68 -0
- package/src/client/game/grid/voidLook.ts +29 -23
- package/src/client/game/loot/runtime.ts +3 -1
- package/src/client/game/mainMenu.ts +14 -6
- package/src/client/game/riding/hud.ts +6 -4
- package/src/client/game/session/finish.ts +22 -4
- package/src/client/game/session/play.ts +8 -2
- package/src/client/game/session/session.ts +4 -1
- package/src/client/game/shard/titleList.ts +6 -2
- package/src/client/game/shardfile/clientWorker.ts +43 -13
- package/src/client/game/shardfile/serverRoute.ts +10 -22
- package/src/client/game/slugPage.css +11 -0
- package/src/client/game/slugPage.ts +84 -0
- package/src/client/game/systems/viewmodel/heldView.ts +6 -3
- package/src/client/game/titleDeck.ts +56 -32
- package/src/client/host/online/doctor.ts +7 -6
- package/src/client/host/online/linkScreens.ts +16 -0
- package/src/client/host/online/release.ts +51 -5
- package/src/client/host/online/shell.ts +62 -27
- package/src/client/host/standalone/shell.ts +7 -3
- package/src/cook/game/audioReport.ts +57 -0
- package/src/cook/game/entryTotals.ts +26 -6
- package/src/cook/game/installedRuntimeReads.ts +3 -0
- package/src/cook/game/shardCook.ts +38 -8
- package/src/cook/game/tierTextures.ts +276 -0
- package/src/e2e/smoke/game.ts +19 -14
- package/src/e2e/smoke/page-globals.d.ts +9 -8
- package/src/e2e/smoke/template2.spec.ts +8 -7
- package/src/server/engine/sim/respawn.ts +6 -1
- package/src/server/engine/sim.ts +3 -0
- package/src/server/game/grid/simulation.ts +35 -0
- package/src/server/game/loot/harvest.ts +2 -0
- package/src/server/game/loot/keepsakeProgression.ts +40 -0
- package/src/server/game/loot/playerOwned.ts +5 -1
- package/src/server/game/plugin/simulation.ts +4 -0
- package/src/server/game/population/nativeBake.ts +2 -1
- package/src/server/game/quest/chapterRecords.ts +2 -0
- package/src/server/game/quest/serverChapters.ts +4 -0
- package/src/server/game/quest/serverDoors.ts +11 -5
- package/src/server/game/roomRespawn.ts +4 -0
- package/src/server/game/shardfile/installedSides.ts +18 -0
- package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
- package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
- package/src/server/host/bake/headlessWorker.ts +5 -1
- package/src/server/host/dedicated/cellHost.ts +98 -29
- package/src/server/host/dedicated/cellProtocol.ts +11 -1
- package/src/server/host/dedicated/cellWorker.ts +9 -3
- package/src/server/host/dedicated/crossing.ts +6 -2
- package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
- package/src/server/host/dedicated/gridCells.ts +52 -9
- package/src/server/host/dedicated/main.ts +31 -12
- package/src/server/host/dedicated/placementFile.ts +56 -0
- package/src/server/host/dedicated/releaseFile.ts +17 -10
- package/src/server/host/dedicated/roadRoom.ts +21 -5
- package/src/server/host/dedicated/socketTransport.ts +2 -1
- package/src/server/host/dedicated/workerTable.ts +13 -1
- package/src/server/host/dedicated/world.ts +111 -10
- package/src/server/host/headlessRuntime.ts +10 -5
- package/src/server/host/installers.ts +62 -0
- package/src/server/host/openWorld.ts +59 -0
- package/src/server/host/ropeDecks.ts +2 -0
- package/src/server/host/standalone/cellWorld.ts +25 -19
- package/src/server/host/standalone/fallFloor.ts +2 -2
- package/src/server/host/standalone/gridServer.ts +7 -4
- package/src/server/host/standalone/roadWorld.ts +41 -4
- package/src/shared/engine/audio/bootAudio.ts +33 -0
- package/src/shared/engine/level/spec.ts +3 -3
- package/src/shared/engine/net/acts.ts +3 -0
- package/src/shared/engine/net/deviceWord.ts +138 -0
- package/src/shared/engine/net/socketFrames.ts +7 -4
- package/src/shared/engine/physics/query.ts +27 -0
- package/src/shared/engine/physics/terrain.ts +19 -28
- package/src/shared/engine/saves/saves.lock.json +15 -0
- package/src/shared/engine/sim/actRoutes.ts +2 -0
- package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
- package/src/shared/game/grid/catalogue.ts +12 -5
- package/src/shared/game/grid/catalogueSlot.ts +18 -0
- package/src/shared/game/grid/farProxy.ts +6 -5
- package/src/shared/game/grid/pageMode.ts +1 -1
- package/src/shared/game/grid/placementRows.ts +33 -0
- package/src/shared/game/grid/roadLayout.ts +26 -3
- package/src/shared/game/grid/singleplayer.json +0 -13
- package/src/shared/game/grid/voidFloor.ts +122 -0
- package/src/shared/game/strings.ts +15 -0
- package/src/shared/host/standalone/netInput.ts +2 -1
package/scripts/build-app.mjs
CHANGED
|
@@ -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(
|
package/scripts/build-mirror.mjs
CHANGED
|
@@ -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
|
-
|
|
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 (!
|
|
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 =
|
|
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`) });
|
package/scripts/check-chunks.mjs
CHANGED
|
@@ -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)
|
|
@@ -16,7 +16,7 @@ export function assertProductionBuild(directory) {
|
|
|
16
16
|
if (file.isDirectory()) walk(full);
|
|
17
17
|
else if (file.name.endsWith('.js')) {
|
|
18
18
|
const code = readFileSync(full, 'utf8');
|
|
19
|
-
if (code.includes('__DEVSERVER__')) throw new Error('Production bundle contains an unsubstituted DEVSERVER define');
|
|
19
|
+
if (code.includes('__DEVSERVER__') || code.includes('__PREPARATION_ONLY__')) throw new Error('Production bundle contains an unsubstituted DEVSERVER or PREPARATION_ONLY define');
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// Conservative source guard for Chromium launchers, without a parser dependency.
|
|
2
|
+
import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
|
|
3
|
+
|
|
2
4
|
const childMethods = ['spawn', 'spawnSync', 'execFile', 'execFileSync', 'exec', 'execSync'];
|
|
3
5
|
const browserBinary = /chrom(?:e|ium)|executablePath\s*\(/iu;
|
|
4
6
|
|
|
@@ -11,7 +13,7 @@ function shellProblems(/** @type {string} */ text) {
|
|
|
11
13
|
if (!command || command[1].startsWith('#') || command[1].includes('=')) return [];
|
|
12
14
|
const program = command[1].replaceAll(/\$\{?(\w+)\}?/gu, (_all, name) => variables.get(name) ?? name);
|
|
13
15
|
if (!browserBinary.test(program)) return [];
|
|
14
|
-
return
|
|
16
|
+
return KEYCHAIN_ARGS.every(flag => command[2].includes(flag)) ? [] : ['bare Chromium shell executable'];
|
|
15
17
|
});
|
|
16
18
|
}
|
|
17
19
|
|
|
@@ -96,7 +98,7 @@ export function keychainProblems(/** @type {string} */ text) {
|
|
|
96
98
|
return expanded;
|
|
97
99
|
};
|
|
98
100
|
const safe = (/** @type {string} */ value) => /\.\.\.\s*KEYCHAIN_ARGS\b/u.test(expand(value))
|
|
99
|
-
||
|
|
101
|
+
|| KEYCHAIN_ARGS.every(flag => expand(value).includes(flag));
|
|
100
102
|
const names = [...childMethods];
|
|
101
103
|
const namespaces = new Set([...text.matchAll(/import\s+\*\s+as\s+(\w+)\s+from\s+['"](?:node:)?child_process['"]/gu)].map(match => match[1]));
|
|
102
104
|
for (const match of text.matchAll(/import\s+(\w+)\s+from\s+['"](?:node:)?child_process['"]/gu)) namespaces.add(match[1]);
|
|
@@ -2,4 +2,6 @@
|
|
|
2
2
|
// keychain for "Chrome for Testing Safe Storage" and a dialog lands on the desktop at each launch. Playwright adds them
|
|
3
3
|
// by default, but a raw `spawn` of the executable skips its defaults, so every launch site spreads them explicitly and
|
|
4
4
|
// test/tooling/chrome-keychain.test.mjs refuses a launch file that does not.
|
|
5
|
-
|
|
5
|
+
// `--mute-audio` rides along (Jake, 2026-11-13: "headless chromium with volume off"), so a launch that forgets it
|
|
6
|
+
// still cannot play a game's sound out of Jake's speakers.
|
|
7
|
+
export const KEYCHAIN_ARGS = Object.freeze(['--use-mock-keychain', '--password-store=basic', '--mute-audio']);
|
package/scripts/cook.mjs
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// C1 (J28): `cook <shardfile.tar> <out>`, a shard's packs from its tarball alone: no bundle, no src/shards, no public/.
|
|
3
|
-
// node --import ./scripts/bake-loader.mjs scripts/cook.mjs <shardfile.tar> <out>
|
|
3
|
+
// node --import ./scripts/bake-loader.mjs scripts/cook.mjs <shardfile.tar> <out> [--phone-textures]
|
|
4
4
|
// `out` receives `assets/spawn/parts/<hash>.pack.br`, one manifest per tier and set, and what no part may hold at its URL.
|
|
5
|
+
// --phone-textures (S12b): the phone manifests list each KTX2 table row trimmed to its phone size (`phoneTier`).
|
|
5
6
|
import { readFileSync } from 'node:fs';
|
|
6
7
|
import { homedir } from 'node:os';
|
|
7
8
|
import { resolve } from 'node:path';
|
|
8
9
|
import { BrotliSizeCache } from '../src/cook/game/brotliSizeCache.mjs';
|
|
9
10
|
|
|
10
11
|
const { cookShard, servedAsIs } = await import('../src/cook/game/shardCook.ts');
|
|
11
|
-
const
|
|
12
|
-
if (
|
|
12
|
+
const flags = process.argv.slice(2).filter(arg => arg.startsWith('--')), unknown = flags.find(flag => flag !== '--phone-textures');
|
|
13
|
+
if (unknown !== undefined) throw new Error(`cook: unknown flag ${unknown}`);
|
|
14
|
+
const [tarball, out] = process.argv.slice(2).filter(arg => !arg.startsWith('--'));
|
|
15
|
+
if (tarball === undefined || out === undefined) throw new Error('usage: cook <shardfile.tar> <out> [--phone-textures]');
|
|
13
16
|
const served = new BrotliSizeCache(process.env.WILDSHARD_WIRE_SIZE_CACHE ?? resolve(homedir(), '.cache/wildshard/gen/served-bytes/1'));
|
|
14
17
|
const report = await cookShard(readFileSync(tarball), resolve(out), {
|
|
15
18
|
now: () => performance.now(),
|
|
16
19
|
wireBytes: (url, bytes) => servedAsIs(url, bytes) ? bytes.length : served.bytes(bytes),
|
|
17
20
|
warn: line => { console.warn(`warning: ${line}`); },
|
|
21
|
+
...(process.argv.includes('--phone-textures') ? { tiers: { phone: true } } : {}),
|
|
18
22
|
});
|
|
19
23
|
console.log(JSON.stringify(report));
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// DEVICE-TELEMETRY DT5 (meta docs/plans/DEVICE-TELEMETRY-PLAN.md): the last N connects' devices from a door's journal, as a table.
|
|
3
|
+
// The door writes one `client.device` JSON line per connect (src/server/host/dedicated/world.ts, src/shared/engine/net/deviceWord.ts).
|
|
4
|
+
// ssh wildshard-agent journalctl -u wildshard-server@staging --since today -o cat | node scripts/devices.mjs --last 20
|
|
5
|
+
// node scripts/devices.mjs --last 20 journal.txt (a saved journal)
|
|
6
|
+
// node scripts/devices.mjs --json < journal.txt (the lines themselves)
|
|
7
|
+
// Read-only: it reads text and prints. Lines carry device characteristics, the Name and the secret-keyed body id, never an address.
|
|
8
|
+
import { readFileSync } from 'node:fs';
|
|
9
|
+
|
|
10
|
+
const COLUMNS = [['name', 14], ['body', 12], ['model', 16], ['platform', 10], ['platformVersion', 8], ['browser', 24], ['gpu', 36], ['screen', 10], ['dpr', 5], ['memory', 4], ['cores', 4], ['clientBuild', 12]];
|
|
11
|
+
|
|
12
|
+
/** The `client.device` lines in a journal's text, oldest first; anything else on a line (a journal prefix) is skipped. */
|
|
13
|
+
export function deviceLines(text) {
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const raw of text.split('\n')) {
|
|
16
|
+
const at = raw.indexOf('{"at":"client.device"');
|
|
17
|
+
if (at === -1) continue;
|
|
18
|
+
try { out.push(JSON.parse(raw.slice(at))); } catch { /* a cut line */ }
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The lines as a fixed-width table. */
|
|
24
|
+
export function deviceTable(lines) {
|
|
25
|
+
const cell = (value, width) => { const said = value === undefined ? '-' : String(value); return (said.length > width ? `${said.slice(0, width - 1)}~` : said).padEnd(width); };
|
|
26
|
+
const head = COLUMNS.map(([name, width]) => cell(name, width)).join(' ');
|
|
27
|
+
return [head, ...lines.map(line => COLUMNS.map(([name, width]) => cell(line[name], width)).join(' '))].join('\n');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function main(argv) {
|
|
31
|
+
const lastAt = argv.indexOf('--last'), last = lastAt === -1 ? 20 : Number(argv[lastAt + 1] ?? 20);
|
|
32
|
+
const files = argv.filter((arg, index) => !arg.startsWith('--') && index !== lastAt + 1);
|
|
33
|
+
const text = files.length === 0 ? readFileSync(0, 'utf8') : files.map(file => readFileSync(file, 'utf8')).join('\n');
|
|
34
|
+
const lines = deviceLines(text).slice(-Math.max(1, last));
|
|
35
|
+
if (argv.includes('--json')) { for (const line of lines) console.log(JSON.stringify(line)); return; }
|
|
36
|
+
console.log(lines.length === 0 ? 'no client.device lines (a door from before DEVICE-TELEMETRY writes none)' : deviceTable(lines));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (import.meta.url === `file://${process.argv[1]}`) main(process.argv.slice(2));
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
/** SA43: the preparation client's asset; sharddev's `PREPARATION_CLIENT_ASSET` reads the same. */
|
|
5
|
+
export declare const PREPARATION_CLIENT_ASSET: string;
|
|
6
|
+
/** Prune a devserver build (or a preparation-only production build) in place to the client an author's page reads. */
|
|
7
|
+
export declare function pruneDevserverClient(client: string, kind?: 'devserver' | 'preparation'): void;
|
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
//
|
|
13
|
+
// SHARD-AUTHORING SA43: `--kind preparation` packs the client `wildshard prepare` records in, `preparation-client.tar.gz`:
|
|
14
|
+
// the production build (DEVSERVER off, the production renderer and its revision) made with `WILDSHARD_PREPARATION_ONLY=1`,
|
|
15
|
+
// so it owns the author's inline draft as `wildshard dev`'s page does, pruned the same way. check-devserver refuses to
|
|
16
|
+
// release it; it is only ever a release asset beside the devserver client.
|
|
17
|
+
import { execFileSync, spawnSync } from 'node:child_process';
|
|
18
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync } from 'node:fs';
|
|
19
|
+
import { join, relative, resolve } from 'node:path';
|
|
20
|
+
import { pathToFileURL } from 'node:url';
|
|
21
|
+
|
|
22
|
+
const ROOT = resolve(import.meta.dirname, '..');
|
|
23
|
+
/** The release asset's name; sharddev's `DEV_CLIENT_ASSET` reads the same. */
|
|
24
|
+
export const DEV_CLIENT_ASSET = 'devserver-client.tar.gz';
|
|
25
|
+
/** SA43: the preparation client's asset; sharddev's `PREPARATION_CLIENT_ASSET` reads the same. */
|
|
26
|
+
export const PREPARATION_CLIENT_ASSET = 'preparation-client.tar.gz';
|
|
27
|
+
/** @typedef {'devserver' | 'preparation'} ClientKind */
|
|
28
|
+
/** Top-level paths (and `assets/` folders) a devserver page never reads. */
|
|
29
|
+
const DROP_TOP = ['programs', 'drafts', 'trailer-15.mp4', 'trailer-30.mp4'];
|
|
30
|
+
const DROP_ASSETS = ['driftwood-isle', 'far-reach', 'nalati', 'nine-dragon', 'pine-hollow', 'sunscar-dunes', 'practice'];
|
|
31
|
+
/** `assets/gpu/` (KTX2 stand-ins): the shards' own folders go; the engine's `tex`, `models` and `horizon` stay. */
|
|
32
|
+
const DROP_GPU = ['baked', 'far-reach', 'nalati', 'nine-dragon', 'pine-hollow'];
|
|
33
|
+
|
|
34
|
+
/** Prune a devserver build (or, SA43, a preparation-only production build) in place to the client an author's page reads.
|
|
35
|
+
* @param {string} client @param {ClientKind} [kind] */
|
|
36
|
+
export function pruneDevserverClient(client, kind = 'devserver') {
|
|
37
|
+
const flags = JSON.parse(readFileSync(join(client, 'build-flags.json'), 'utf8'));
|
|
38
|
+
if (kind === 'devserver' && flags?.devserver !== true) throw new Error('devserver-client: the build is not in devserver mode');
|
|
39
|
+
if (kind === 'preparation') {
|
|
40
|
+
const versionFile = join(client, 'version.json');
|
|
41
|
+
const version = existsSync(versionFile) ? JSON.parse(readFileSync(versionFile, 'utf8')) : undefined;
|
|
42
|
+
if (flags?.devserver !== false || version?.preparationOnly !== true) throw new Error('devserver-client: the build is not a preparation-only production build');
|
|
43
|
+
}
|
|
44
|
+
for (const name of DROP_TOP) rmSync(join(client, name), { recursive: true, force: true });
|
|
45
|
+
for (const name of DROP_ASSETS) rmSync(join(client, 'assets', name), { recursive: true, force: true });
|
|
46
|
+
for (const name of DROP_GPU) rmSync(join(client, 'assets', 'gpu', name), { recursive: true, force: true });
|
|
47
|
+
// baked: only the engine's common bake; spawn: only the in-page server's book (`server-<build>.json`)
|
|
48
|
+
for (const [folder, keep] of /** @type {const} */ ([['assets/baked', name => name === 'common'], ['assets/spawn', name => /^server-.+\.json$/u.test(name)]])) {
|
|
49
|
+
const path = join(client, folder);
|
|
50
|
+
if (existsSync(path)) for (const name of readdirSync(path)) if (!keep(name)) rmSync(join(path, name), { recursive: true, force: true });
|
|
51
|
+
}
|
|
52
|
+
const shardfiles = join(client, 'shardfiles');
|
|
53
|
+
if (existsSync(shardfiles)) for (const slug of readdirSync(shardfiles)) {
|
|
54
|
+
for (const name of readdirSync(join(shardfiles, slug))) if (name !== 'discovery.json') rmSync(join(shardfiles, slug, name), { recursive: true, force: true });
|
|
55
|
+
}
|
|
56
|
+
for (const entry of readdirSync(client, { recursive: true, withFileTypes: true })) if (entry.isFile() && entry.name.endsWith('.map')) rmSync(join(entry.parentPath, entry.name));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** @param {string} folder @returns {number} */
|
|
60
|
+
const bytesOf = folder => readdirSync(folder, { recursive: true, withFileTypes: true }).reduce((sum, entry) => sum + (entry.isFile() ? statSync(join(entry.parentPath, entry.name)).size : 0), 0);
|
|
61
|
+
|
|
62
|
+
if (process.argv[1] !== undefined && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) {
|
|
63
|
+
const args = process.argv.slice(2), option = (/** @type {string} */ name) => { const at = args.indexOf(`--${name}`); return at === -1 ? undefined : args[at + 1]; };
|
|
64
|
+
const kind = /** @type {ClientKind} */ (option('kind') ?? 'devserver');
|
|
65
|
+
if (kind !== 'devserver' && kind !== 'preparation') throw new Error(`devserver-client: --kind is devserver or preparation, not ${String(kind)}`);
|
|
66
|
+
const out = resolve(option('out') ?? join('tmp', 'devserver-client', kind === 'devserver' ? DEV_CLIENT_ASSET : PREPARATION_CLIENT_ASSET));
|
|
67
|
+
const client = resolve(option('keep') ?? join(ROOT, 'tmp', 'devserver-client', 'client'));
|
|
68
|
+
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)');
|
|
69
|
+
rmSync(client, { recursive: true, force: true });
|
|
70
|
+
const built = spawnSync(process.execPath, ['scripts/build-app.mjs', '--mode', kind === 'devserver' ? 'devserver' : 'production', '--outDir', client], {
|
|
71
|
+
cwd: ROOT, stdio: 'inherit', env: { ...process.env, WILDSHARD_CATALOGUE: process.env.WILDSHARD_CATALOGUE ?? 'test/pins/catalogue.json',
|
|
72
|
+
...(kind === 'preparation' ? { WILDSHARD_PREPARATION_ONLY: '1' } : {}) } });
|
|
73
|
+
if (built.status !== 0) throw new Error(`devserver-client: build-app exited ${String(built.status)}`);
|
|
74
|
+
const before = bytesOf(client);
|
|
75
|
+
pruneDevserverClient(client, kind);
|
|
76
|
+
mkdirSync(resolve(out, '..'), { recursive: true });
|
|
77
|
+
// the same bytes for the same tree: sorted names, no owners or times (as the dedicated bundle is packed in server-release.yml)
|
|
78
|
+
const tar = spawnSync('tar', ['--version'], { encoding: 'utf8' }).stdout.includes('GNU') ? 'tar' : 'gtar';
|
|
79
|
+
const gnu = spawnSync(tar, ['--version'], { encoding: 'utf8' }).status === 0;
|
|
80
|
+
execFileSync('bash', ['-c', gnu
|
|
81
|
+
? `set -euo pipefail; ${tar} --sort=name --mtime='@0' --owner=0 --group=0 --numeric-owner -cf - -C "$1" . | gzip -n > "$2"`
|
|
82
|
+
: 'set -euo pipefail; tar -cf - -C "$1" . | gzip -n > "$2"', 'pack', client, out], { stdio: 'inherit' });
|
|
83
|
+
console.log(`devserver-client (${kind}): ${(before / 1e6).toFixed(0)} MB built, ${(bytesOf(client) / 1e6).toFixed(0)} MB kept, ${(statSync(out).size / 1e6).toFixed(1)} MB packed: ${out}`);
|
|
84
|
+
if (option('keep') === undefined) rmSync(client, { recursive: true, force: true });
|
|
85
|
+
}
|
package/scripts/doctor-proof.mjs
CHANGED
|
@@ -62,7 +62,7 @@ const pages = spawn(process.execPath, ['scripts/preview-server.mjs', '--outDir',
|
|
|
62
62
|
for (let tries = 0; tries < 100 && !(await fetch(`http://127.0.0.1:${String(PAGE_PORT)}/version.json`).then(found => found.ok).catch(() => false)); tries++) await sleep(100);
|
|
63
63
|
const base = `http://127.0.0.1:${String(PAGE_PORT)}`;
|
|
64
64
|
|
|
65
|
-
const browser = await (engine === 'webkit' ? webkit : chromium).launch(engine === 'webkit' ? {} : { args: ['--use-mock-keychain', '--password-store=basic'] });
|
|
65
|
+
const browser = await (engine === 'webkit' ? webkit : chromium).launch(engine === 'webkit' ? {} : { args: ['--use-mock-keychain', '--password-store=basic', '--mute-audio'] });
|
|
66
66
|
const device = engine === 'webkit' ? devices['iPhone 13'] : devices['Pixel 7'];
|
|
67
67
|
const failures = /** @type {string[]} */ ([]), results = /** @type {Record<string, unknown>} */ ({});
|
|
68
68
|
/** @param {boolean} ok @param {string} what */
|