@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
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// HOST-RULER HR5 (meta docs/plans/HOST-RULER-PLAN.md): build lint/host-register.json from the old lists, once.
|
|
3
|
+
// Sources: engine lint/platform-pending-users.json, scripts/platform-chargebacks.mjs, lint/host-reviews.json,
|
|
4
|
+
// lint/listed-view-code.json, and singleplayer docs/HOST-BAR.md's G571 and G599–G677 lines at a pinned SHA. HR9
|
|
5
|
+
// deletes the engine lists (and this script) with the old ruler; the register is then the only list.
|
|
6
|
+
// Usage: node scripts/host-ruler/register-migrate.mjs [--write|--check] [--singleplayer <dir>] [--meta <dir>]
|
|
7
|
+
// --check (default) rebuilds the register and refuses if the committed one differs; --write rewrites it.
|
|
8
|
+
import { execFileSync } from 'node:child_process';
|
|
9
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
10
|
+
import { join, resolve } from 'node:path';
|
|
11
|
+
import { platformChargeback } from '../platform-chargebacks.mjs';
|
|
12
|
+
import { ENGINE_ROOT } from './roots.mjs';
|
|
13
|
+
import { RECHECK, REGISTER, TESTS, formatRegister, moduleFile, namesBinding, readHostRegister } from './register.mjs';
|
|
14
|
+
|
|
15
|
+
const SINGLEPLAYER_SHA = '48d24fdbbd';
|
|
16
|
+
const META_PLAN = 'docs/plans/multi-repo/MULTI-REPO-PLAN.md';
|
|
17
|
+
const args = process.argv.slice(2);
|
|
18
|
+
/** @param {string} name @param {string} fallback */
|
|
19
|
+
const option = (name, fallback) => { const at = args.indexOf(name); return at === -1 ? fallback : args[at + 1] ?? fallback; };
|
|
20
|
+
const singleplayer = resolve(option('--singleplayer', join(ENGINE_ROOT, '../../wildshard-singleplayer')));
|
|
21
|
+
const meta = resolve(option('--meta', join(ENGINE_ROOT, '../../project-wildshard-meta')));
|
|
22
|
+
/** @param {string} dir @param {string} rev @param {string} path */
|
|
23
|
+
const show = (dir, rev, path) => execFileSync('git', ['-C', dir, 'show', `${rev}:${path}`], { encoding: 'utf8', maxBuffer: 1 << 26 });
|
|
24
|
+
const META_SHA = '4112be3';
|
|
25
|
+
const ENGINE_SOURCES = ['lint/platform-pending-users.json', 'scripts/platform-chargebacks.mjs', 'lint/host-reviews.json', 'lint/listed-view-code.json'];
|
|
26
|
+
if (execFileSync('git', ['-C', ENGINE_ROOT, 'status', '--porcelain', '--', ...ENGINE_SOURCES], { encoding: 'utf8' }).trim() !== '') throw new Error('register-migrate: an old list has uncommitted edits; its SHA would not describe it');
|
|
27
|
+
const engineSha = execFileSync('git', ['-C', ENGINE_ROOT, 'log', '-1', '--format=%h', '--', 'lint/platform-pending-users.json', 'scripts/platform-chargebacks.mjs', 'lint/host-reviews.json', 'lint/listed-view-code.json'], { encoding: 'utf8' }).trim();
|
|
28
|
+
|
|
29
|
+
// The written path rule (as g571-hosts.mjs's hostFile): HOST-BAR's `format/x` is the pinned format package's
|
|
30
|
+
// `@wildshard/format/src/format/x.ts`; `engine|game/<side>/x` is side-first `src/<side>/<layer>/x.ts` (J122), tried on
|
|
31
|
+
// the named side first and then the others, since a retag moves the file, not the approval; an unsided `engine|game/x`
|
|
32
|
+
// takes the first side that has it. The old `src/<layer>/<side>/x.ts` and `src/format/x.ts` paths map the same way.
|
|
33
|
+
const SIDES = ['client', 'shared', 'server', 'cook'];
|
|
34
|
+
/** @param {string} selector @returns {{module:string, binding?:string}|null} */
|
|
35
|
+
export function sideFirst(selector) {
|
|
36
|
+
const [path = '', binding] = selector.split('#');
|
|
37
|
+
const bare = path.replace(/^src\//u, '').replace(/\.ts$/u, '');
|
|
38
|
+
/** @param {string} module */
|
|
39
|
+
const found = module => moduleFile(module) === null ? null : module;
|
|
40
|
+
let module = null;
|
|
41
|
+
if (bare.startsWith('format/')) module = found(`@wildshard/format/src/${bare}.ts`);
|
|
42
|
+
else {
|
|
43
|
+
const match = /^(engine|game)\/(?:(client|shared|server|cook)\/)?(.+)$/u.exec(bare);
|
|
44
|
+
if (match !== null) {
|
|
45
|
+
const [, layer, side, rest] = match;
|
|
46
|
+
for (const candidate of side === undefined ? SIDES : [side, ...SIDES.filter(other => other !== side)]) module ??= found(`src/${candidate}/${layer}/${rest}.ts`);
|
|
47
|
+
} else if (SIDES.includes(bare.split('/')[0] ?? '')) module = found(`src/${bare}.ts`);
|
|
48
|
+
}
|
|
49
|
+
return module === null ? null : binding === undefined ? { module } : { module, binding };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** @typedef {{source:string, line:number, selector:string}} From */
|
|
53
|
+
/** @typedef {{key:string, verdict:string, decision:string, users:string[], recheck?:string, score?:Record<string,0|1>, note?:string, from:From[], rank:number}} Draft */
|
|
54
|
+
/** @type {Draft[]} */
|
|
55
|
+
const drafts = [];
|
|
56
|
+
/** @type {{key:string, from:From, reason:string}[]} */
|
|
57
|
+
const dropped = [];
|
|
58
|
+
/** @type {Record<string, number>} */
|
|
59
|
+
const counts = {};
|
|
60
|
+
/** @param {string} module */
|
|
61
|
+
const layerVerdict = module => /^src\/\w+\/engine\//u.test(module) ? 'engine' : 'game';
|
|
62
|
+
/** Precedence on a shared key, as the old ruler applied it: a Jake-approved HOST-BAR host beats a chargeback; a
|
|
63
|
+
* chargeback beats an approved pending-user feature; listed and reviewed rows sit between. */
|
|
64
|
+
const RANK = { hostBarApproved: 6, chargebacks: 5, listedView: 4, hostReviews: 3, pendingApproved: 2, hostBarPending: 1, pendingW3: 0 };
|
|
65
|
+
/** @param {string} source @param {number} line @param {string} selector @param {Omit<Draft,'key'|'from'|'rank'>} row @param {number} rank */
|
|
66
|
+
function add(source, line, selector, row, rank) {
|
|
67
|
+
counts[source] = (counts[source] ?? 0) + 1;
|
|
68
|
+
const from = { source, line, selector }, mapped = sideFirst(selector);
|
|
69
|
+
if (selector.endsWith('.test.ts')) { dropped.push({ key: selector, from, reason: 'a test file the line cites, not a host' }); return; }
|
|
70
|
+
if (mapped === null) { dropped.push({ key: selector, from, reason: 'no such module in engine or the pinned format package' }); return; }
|
|
71
|
+
const file = moduleFile(mapped.module);
|
|
72
|
+
if (mapped.binding !== undefined && file !== null && !namesBinding(readFileSync(file, 'utf8'), mapped.binding)) {
|
|
73
|
+
dropped.push({ key: `${mapped.module}#${mapped.binding}`, from, reason: 'the module no longer names this binding' }); return;
|
|
74
|
+
}
|
|
75
|
+
drafts.push({ key: mapped.binding === undefined ? mapped.module : `${mapped.module}#${mapped.binding}`, from: [from], rank, ...row });
|
|
76
|
+
}
|
|
77
|
+
/** @param {string} text @param {string} needle @param {string} [after] the needle's first match after this anchor */
|
|
78
|
+
const lineOf = (text, needle, after = '') => {
|
|
79
|
+
const index = text.indexOf(needle, after === '' ? 0 : text.indexOf(after));
|
|
80
|
+
if (index === -1) throw new Error(`register-migrate: not found: ${needle}`);
|
|
81
|
+
return text.slice(0, index).split('\n').length;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// 1. Pending users (G419): an approved feature (G473–G484) is platform on its decision, also when it names a W3 shard
|
|
85
|
+
// (the old reader credited approvedFeature before the shard); a W3 entry without one is pending.
|
|
86
|
+
const pendingText = readFileSync(join(ENGINE_ROOT, 'lint/platform-pending-users.json'), 'utf8');
|
|
87
|
+
{
|
|
88
|
+
/** @type {{module:string, export?:string, shard?:string, plan?:{row:string}, approvedFeature?:{name:string, decision:{row:string}}}[]} */
|
|
89
|
+
const entries = JSON.parse(pendingText).entries;
|
|
90
|
+
let at = 0;
|
|
91
|
+
for (const entry of entries) {
|
|
92
|
+
at = pendingText.indexOf(`"module": "${entry.module}"`, at + 1);
|
|
93
|
+
if (at === -1) throw new Error(`register-migrate: entry out of order: ${entry.module}`);
|
|
94
|
+
const line = pendingText.slice(0, at).split('\n').length, selector = entry.export === undefined ? entry.module : `${entry.module}#${entry.export}`;
|
|
95
|
+
const users = entry.shard === undefined ? [] : [entry.shard];
|
|
96
|
+
if (entry.approvedFeature !== undefined) {
|
|
97
|
+
add('pending-users', line, selector, { verdict: layerVerdict(sideFirst(selector)?.module ?? ''), decision: entry.approvedFeature.decision.row, users,
|
|
98
|
+
note: `approved feature: ${entry.approvedFeature.name}${entry.plan === undefined ? '' : `; W3 row: ${entry.plan.row}`}` }, RANK.pendingApproved);
|
|
99
|
+
} else {
|
|
100
|
+
const decision = /G\d+/u.exec(entry.plan?.row ?? '')?.[0] ?? 'G419';
|
|
101
|
+
add('pending-users', line, selector, { verdict: 'pending', decision, users, recheck: RECHECK, note: `W3 row: ${entry.plan?.row ?? ''}` }, RANK.pendingW3);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// 2. HOST-BAR at the pinned SHA. `- G571` lines and the four G599–G677 lines that are not "Jake-approved host:" are
|
|
107
|
+
// pending (G595: every one-user host needs Jake's own approval); the 31 "Jake-approved host:" lines are platform on
|
|
108
|
+
// their G number. Every backticked selector is a row; a line without one names its host in plain text (HAND).
|
|
109
|
+
const hostBar = show(singleplayer, SINGLEPLAYER_SHA, 'docs/HOST-BAR.md');
|
|
110
|
+
/** Lines whose host is not a backticked selector, by line number: the selector their prose names. */
|
|
111
|
+
const HAND = new Map([
|
|
112
|
+
[76, ['format/postGraphLook#PaintedWorldSchema', 'game/looks/postGraphLook#paintedWorld', 'game/looks/postGraphLook#paintedWorldOf']],
|
|
113
|
+
[141, ['game/quest/continuation#installQuestContinuationFile']],
|
|
114
|
+
]);
|
|
115
|
+
for (const [index, text] of hostBar.split('\n').entries()) {
|
|
116
|
+
const line = index + 1, legacy = /^- G571\b/u.test(text), later = /^- G(?:599|6[0-6]\d|67[0-7])\b/u.test(text);
|
|
117
|
+
if (!legacy && !later) continue;
|
|
118
|
+
const approved = later && /^- G\d+(?: [A-Z]\d+[a-z]?)? Jake-approved host:/u.test(text);
|
|
119
|
+
const decision = /G\d+/u.exec(text)?.[0] ?? 'G571';
|
|
120
|
+
const tag = /^- (G\d+(?: [A-Z]\d+[a-z]?)?(?: \/ G\d+ [A-Z]\d+)?)/u.exec(text)?.[1] ?? decision;
|
|
121
|
+
const selectors = [...text.matchAll(/`((?:src\/)?(?:engine|game|format|sdk|sharddev)\/[A-Za-z0-9_./-]+(?:#[A-Za-z_$][\w$]*)?)`/gu)].map(match => match[1] ?? '');
|
|
122
|
+
const hosts = HAND.get(line) ?? [...new Set(selectors)];
|
|
123
|
+
if (!hosts.some(selector => !selector.endsWith('.test.ts'))) throw new Error(`register-migrate: HOST-BAR line ${line} names no host selector; add it to HAND`);
|
|
124
|
+
for (const selector of hosts) {
|
|
125
|
+
if (approved) add('host-bar', line, selector, { verdict: layerVerdict(sideFirst(selector)?.module ?? ''), decision, users: [], note: `${tag} Jake-approved host` }, RANK.hostBarApproved);
|
|
126
|
+
else add('host-bar', line, selector, { verdict: 'pending', decision, users: [], recheck: RECHECK, note: legacy ? `${tag} day-one host (test 1 waived), not yet approved one by one (G595)` : `${tag}: not a "Jake-approved host:" line` }, RANK.hostBarPending);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 3. Chargebacks (G520 / G496 cut list): every reviewed single-shard charge is a silly row on its owner.
|
|
131
|
+
const chargeText = readFileSync(join(ENGINE_ROOT, 'scripts/platform-chargebacks.mjs'), 'utf8');
|
|
132
|
+
/** [selector, owner, decision, needle in platform-chargebacks.mjs, checked through platformChargeback(), anchor]
|
|
133
|
+
* @type {[string, string, string, string, boolean, string?][]} */
|
|
134
|
+
const CHARGES = ([
|
|
135
|
+
['src/game/boss/arenaScript.ts', 'nalati-grasslands', 'G520', "'game/boss/arenaScript'", true],
|
|
136
|
+
['src/game/boss/arenaField.ts', 'nalati-grasslands', 'G520', "'game/boss/arenaField'", true],
|
|
137
|
+
['src/client/game/models/mountedSpecimen.ts', 'nalati-grasslands', 'G530', "['src/client/game/models/mountedSpecimen.ts'", true],
|
|
138
|
+
['src/client/game/shardfile/worldAssembly.ts#installAssemblyArenaScript', 'nalati-grasslands', 'G665', "['installAssemblyArenaScript'", true],
|
|
139
|
+
['src/client/game/looks/speciesBook.ts#SpeciesLookBook', 'nalati-grasslands', 'G520', "'SpeciesLookBook'", true],
|
|
140
|
+
['src/client/game/looks/speciesBook.ts#packedRows', 'nalati-grasslands', 'G520', "'packedRows'", true],
|
|
141
|
+
['src/client/game/practice/course.ts#MountedCourseEntry', 'nalati-grasslands', 'G520', "'MountedCourseEntry'", true],
|
|
142
|
+
['src/client/game/practice/course.ts#GrappleCourseEntry', 'nine-dragon-stack', 'G520', "'GrappleCourseEntry'", true],
|
|
143
|
+
['src/client/game/practice/course.ts#MountEntryRows', 'nalati-grasslands', 'G520', "'MountEntryRows'", true],
|
|
144
|
+
['src/client/game/practice/course.ts#GrappleEntryRows', 'nine-dragon-stack', 'G520', "'GrappleEntryRows'", true],
|
|
145
|
+
['src/client/game/boss/encounterView.ts#SlotEncounterView', 'nalati-grasslands', 'G520', "'SlotEncounterView'", true],
|
|
146
|
+
['src/client/game/boss/encounterView.ts#PatrolEncounterView', 'nalati-grasslands', 'G520', "'PatrolEncounterView'", true],
|
|
147
|
+
['src/shared/game/boss/slotLaw.ts#SlotEncounterLaw', 'nalati-grasslands', 'G520', "'SlotEncounterLaw'", true],
|
|
148
|
+
['src/client/game/shardfile/worldScenes.ts#WorldScenePoolPublications', 'nine-dragon-stack', 'G520', "['src/client/game/shardfile/worldScenes.ts', new Map([['WorldScenePoolPublications'", true],
|
|
149
|
+
['src/client/game/shardfile/scenePools.ts#WorldSceneTierPools', 'nine-dragon-stack', 'G520', "['src/client/game/shardfile/scenePools.ts', new Map([['WorldSceneTierPools'", true],
|
|
150
|
+
['src/format/worldScenes.ts#WorldSceneTierPools', 'nine-dragon-stack', 'G520', "['src/format/worldScenes.ts', new Map([['WorldSceneTierPools'", true],
|
|
151
|
+
['src/format/worldScenes.ts#WorldScenePoolPublications', 'nine-dragon-stack', 'G520', "['WorldScenePoolPublications', 'C1']])]", true, "['src/format/worldScenes.ts', new Map([['WorldSceneTierPools'"],
|
|
152
|
+
['src/client/game/quest/carriedProp.ts', 'nalati-grasslands', 'G520', '["src/client/game/quest/carriedProp.ts", null]', false],
|
|
153
|
+
['src/shared/engine/combat/effects/types.ts#SourceMulDef', 'nalati-grasslands', 'G520', '"SourceMulDef"', false],
|
|
154
|
+
['src/shared/engine/combat/effects/types.ts#anyTag', 'nalati-grasslands', 'G520', '"anyTag"', false],
|
|
155
|
+
['src/shared/engine/combat/effects/types.ts#sourceMultiplier', 'nalati-grasslands', 'G520', '"sourceMultiplier"', false],
|
|
156
|
+
['src/client/game/shardfile/scenePools.ts#WorldSceneTierPools', 'nine-dragon-stack', 'G520', "['src/client/game/shardfile/scenePools.ts', new Map([['WorldSceneTierPools', [", false],
|
|
157
|
+
['src/client/game/shardfile/worldScenes.ts#WorldScenePoolPublications', 'nine-dragon-stack', 'G520', "['WorldScenePoolPublications', [", false],
|
|
158
|
+
['src/format/worldScenes.ts#WorldScenePoolPublications', 'nine-dragon-stack', 'G520', "['WorldScenePoolPublications', [[", false],
|
|
159
|
+
['src/format/worldScenes.ts#WorldSceneTierPools', 'nine-dragon-stack', 'G520', "['WorldSceneTierPools', [\n", false, "['src/format/worldScenes.ts', new Map([\n"],
|
|
160
|
+
]);
|
|
161
|
+
for (const [selector, owner, decision, needle, table, after] of CHARGES) {
|
|
162
|
+
const [path = '', name] = selector.split('#');
|
|
163
|
+
if (table && platformChargeback(path, name) === null && platformChargeback(path) === null) throw new Error(`register-migrate: not a chargeback: ${selector}`);
|
|
164
|
+
const kind = table ? 'chargeback' : needle.startsWith('["') || needle.startsWith('"') ? 'chapter-facet owner' : 'inline span';
|
|
165
|
+
add('chargebacks', lineOf(chargeText, needle, after), selector, { verdict: 'silly', decision, users: [owner], note: `${kind}, charged to ${owner}` }, RANK.chargebacks);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 4. Host reviews (G456) and 5. listed view code (G570) carry over.
|
|
169
|
+
const reviewText = readFileSync(join(ENGINE_ROOT, 'lint/host-reviews.json'), 'utf8');
|
|
170
|
+
/** @type {Record<string,{evidence:string, verdicts:Record<string,string>}>} */
|
|
171
|
+
const reviews = JSON.parse(reviewText).entries;
|
|
172
|
+
for (const [selector, review] of Object.entries(reviews)) {
|
|
173
|
+
/** @type {Record<string,0|1>} */
|
|
174
|
+
const score = {};
|
|
175
|
+
for (const [test, verdict] of Object.entries(review.verdicts)) { if (!TESTS.includes(/** @type {typeof TESTS[number]} */ (test))) throw new Error(`register-migrate: unknown test ${test}`); score[test] = verdict === 'pass' ? 1 : 0; }
|
|
176
|
+
add('host-reviews', lineOf(reviewText, `"${selector}"`), selector.replace(/#\*$/u, ''), { verdict: 'borderline', decision: /G\d+/u.exec(review.evidence)?.[0] ?? 'G456', users: ['nalati-grasslands'], recheck: RECHECK, score, note: review.evidence }, RANK.hostReviews);
|
|
177
|
+
}
|
|
178
|
+
const viewText = readFileSync(join(ENGINE_ROOT, 'lint/listed-view-code.json'), 'utf8');
|
|
179
|
+
/** @type {Record<string,{path:string, name?:string, reason:string, decision:string}[]>} */
|
|
180
|
+
const views = JSON.parse(viewText).shards;
|
|
181
|
+
for (const [shard, rows] of Object.entries(views)) for (const row of rows) {
|
|
182
|
+
add('listed-view', lineOf(viewText, `"${row.path}"`), row.name === undefined ? row.path : `${row.path}#${row.name}`, { verdict: 'silly', decision: row.decision, users: [shard], note: `listed view code: ${row.reason}` }, RANK.listedView);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Merge rows that share a key: the higher-ranked row wins and keeps every source line.
|
|
186
|
+
/** @type {Map<string, Draft>} */
|
|
187
|
+
const byKey = new Map();
|
|
188
|
+
/** @type {{key:string, kept:string, merged:string[]}[]} */
|
|
189
|
+
const merged = [];
|
|
190
|
+
for (const draft of drafts) {
|
|
191
|
+
const seen = byKey.get(draft.key);
|
|
192
|
+
if (seen === undefined) { byKey.set(draft.key, draft); continue; }
|
|
193
|
+
const [win, lose] = draft.rank > seen.rank ? [draft, seen] : [seen, draft];
|
|
194
|
+
byKey.set(draft.key, { ...win, from: [...seen.from, ...draft.from] });
|
|
195
|
+
const note = merged.find(row => row.key === draft.key) ?? (merged.push({ key: draft.key, kept: '', merged: [] }), merged[merged.length - 1]);
|
|
196
|
+
if (note === undefined) throw new Error('unreachable');
|
|
197
|
+
note.kept = `${win.verdict} ${win.decision}`;
|
|
198
|
+
note.merged.push(`${lose.verdict} ${lose.decision} (${lose.from.map(from => `${from.source}:${from.line}`).join(', ')})`);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// The decision ids a row may cite: every G row of singleplayer's decisions.md at the pin, every J row of meta's §2.
|
|
202
|
+
const decisionsText = show(singleplayer, SINGLEPLAYER_SHA, 'docs/plans/decisions.md');
|
|
203
|
+
const gIds = [...new Set([...decisionsText.matchAll(/^\| *(G\d+) *\|/gmu)].map(match => match[1] ?? ''))];
|
|
204
|
+
const metaText = show(meta, META_SHA, META_PLAN), section = metaText.slice(metaText.indexOf('\n## 2. '), metaText.indexOf('\n## 3. '));
|
|
205
|
+
const jIds = [...new Set([...section.matchAll(/^\| *(J\d+) *\|/gmu)].map(match => match[1] ?? ''))];
|
|
206
|
+
|
|
207
|
+
/** A row in the register's field order, without its merge rank. @param {Draft} row */
|
|
208
|
+
function written(row) {
|
|
209
|
+
/** @type {Record<string, unknown>} */
|
|
210
|
+
const out = { key: row.key, verdict: row.verdict, decision: row.decision, users: row.users };
|
|
211
|
+
if (row.recheck !== undefined) out.recheck = row.recheck;
|
|
212
|
+
if (row.score !== undefined) out.score = row.score;
|
|
213
|
+
out.from = row.from;
|
|
214
|
+
if (row.note !== undefined) out.note = row.note;
|
|
215
|
+
return out;
|
|
216
|
+
}
|
|
217
|
+
const register = {
|
|
218
|
+
schema: 'wildshard.host-register/1',
|
|
219
|
+
about: 'HOST-RULER HR5: one row per host module or module#binding. Verdicts engine and game are platform; pending and borderline charge back after recheck; silly is charged to its users. Bar: docs/HOST-BAR.md. Reader: scripts/host-ruler/register.mjs.',
|
|
220
|
+
decisions: {
|
|
221
|
+
G: { source: `wildshard-singleplayer@${SINGLEPLAYER_SHA} docs/plans/decisions.md`, ids: gIds },
|
|
222
|
+
J: { source: `project-wildshard-meta@${META_SHA} ${META_PLAN} section 2`, ids: jIds },
|
|
223
|
+
},
|
|
224
|
+
sources: {
|
|
225
|
+
'pending-users': { file: `engine@${engineSha} lint/platform-pending-users.json`, rows: counts['pending-users'] ?? 0 },
|
|
226
|
+
'host-bar': { file: `wildshard-singleplayer@${SINGLEPLAYER_SHA} docs/HOST-BAR.md`, rows: counts['host-bar'] ?? 0 },
|
|
227
|
+
chargebacks: { file: `engine@${engineSha} scripts/platform-chargebacks.mjs`, rows: counts.chargebacks ?? 0 },
|
|
228
|
+
'host-reviews': { file: `engine@${engineSha} lint/host-reviews.json`, rows: counts['host-reviews'] ?? 0 },
|
|
229
|
+
'listed-view': { file: `engine@${engineSha} lint/listed-view-code.json`, rows: counts['listed-view'] ?? 0 },
|
|
230
|
+
},
|
|
231
|
+
merged: merged.sort((a, b) => a.key.localeCompare(b.key)),
|
|
232
|
+
dropped,
|
|
233
|
+
rows: [...byKey.values()].sort((a, b) => a.key.localeCompare(b.key)).map(written),
|
|
234
|
+
};
|
|
235
|
+
const text = formatRegister(register), file = join(ENGINE_ROOT, REGISTER);
|
|
236
|
+
if (args.includes('--write')) writeFileSync(file, text);
|
|
237
|
+
else if (readFileSync(file, 'utf8') !== text) { console.error(`register-migrate: ${REGISTER} differs from the old lists; rerun with --write`); process.exit(1); }
|
|
238
|
+
const read = readHostRegister(ENGINE_ROOT);
|
|
239
|
+
/** @type {Record<string, number>} */
|
|
240
|
+
const verdicts = {};
|
|
241
|
+
for (const row of read.rows) verdicts[row.verdict] = (verdicts[row.verdict] ?? 0) + 1;
|
|
242
|
+
console.log(JSON.stringify({ rows: read.rows.length, verdicts, sources: counts, merged: merged.length, dropped: dropped.length }));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export declare const REGISTER: 'lint/host-register.json';
|
|
2
|
+
export declare const RECHECK: string;
|
|
3
|
+
export declare const VERDICTS: readonly ['engine', 'game', 'pending', 'borderline', 'silly'];
|
|
4
|
+
export declare const TESTS: readonly ['twoRealUsers', 'noShardNouns', 'dataDriven', 'serverSafe', 'deletionTest', 'dataOnlyApi'];
|
|
5
|
+
export type Verdict = (typeof VERDICTS)[number];
|
|
6
|
+
export type HostTest = (typeof TESTS)[number];
|
|
7
|
+
export interface RegisterFrom { readonly source: string; readonly line: number; readonly selector: string }
|
|
8
|
+
export interface RegisterRow {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
readonly verdict: Verdict;
|
|
11
|
+
readonly decision: string;
|
|
12
|
+
readonly users: readonly string[];
|
|
13
|
+
readonly recheck?: string;
|
|
14
|
+
readonly score?: Readonly<Partial<Record<HostTest, 0 | 1>>>;
|
|
15
|
+
readonly from: readonly RegisterFrom[];
|
|
16
|
+
readonly note?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface HostRegister {
|
|
19
|
+
readonly schema: 'wildshard.host-register/1';
|
|
20
|
+
readonly about: string;
|
|
21
|
+
readonly decisions: { readonly G: { readonly source: string; readonly ids: readonly string[] }; readonly J: { readonly source: string; readonly ids: readonly string[] } };
|
|
22
|
+
readonly sources: Readonly<Record<string, { readonly file: string; readonly rows: number }>>;
|
|
23
|
+
readonly merged: readonly { readonly key: string; readonly kept: string; readonly merged: readonly string[] }[];
|
|
24
|
+
readonly dropped: readonly { readonly key: string; readonly from: RegisterFrom; readonly reason: string }[];
|
|
25
|
+
readonly rows: readonly RegisterRow[];
|
|
26
|
+
}
|
|
27
|
+
export function moduleFile(module: string, root?: string): string | null;
|
|
28
|
+
export function namesBinding(text: string, binding: string): boolean;
|
|
29
|
+
export function hostRegisterProblems(json: unknown, root?: string): string[];
|
|
30
|
+
export function readHostRegister(root?: string): HostRegister;
|
|
31
|
+
/** Loose on purpose: the migration formats a register before the reader has validated it. */
|
|
32
|
+
export function formatRegister(register: {
|
|
33
|
+
readonly schema: string; readonly about: string; readonly rows: readonly unknown[]; readonly merged: readonly unknown[]; readonly dropped: readonly unknown[];
|
|
34
|
+
readonly sources: Readonly<Record<string, unknown>>;
|
|
35
|
+
readonly decisions: Readonly<Record<string, { readonly source: string; readonly ids: readonly string[] }>>;
|
|
36
|
+
}): string;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// HOST-RULER HR5 (meta docs/plans/HOST-RULER-PLAN.md): the one host register, lint/host-register.json, and its reader.
|
|
2
|
+
// One row per host module or `module#binding`: a verdict (`engine`/`game` are platform, `pending`/`borderline` charge
|
|
3
|
+
// back after `recheck`, `silly` is charged to its users), HOST-BAR's six-test score (unscored allowed), the G or J
|
|
4
|
+
// decision behind it, the users known when it was written, and the old-list line(s) it came from. The bar is
|
|
5
|
+
// docs/HOST-BAR.md. Nothing reads the register yet: HR6's ruler will.
|
|
6
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
import * as v from 'valibot';
|
|
9
|
+
import { ENGINE_ROOT, modulePath } from './roots.mjs';
|
|
10
|
+
|
|
11
|
+
export const REGISTER = 'lint/host-register.json';
|
|
12
|
+
/** Kitchen Sink Q4 (b): every stale pending row gets one new recheck date. */
|
|
13
|
+
export const RECHECK = '2026-12-11';
|
|
14
|
+
export const VERDICTS = /** @type {const} */ (['engine', 'game', 'pending', 'borderline', 'silly']);
|
|
15
|
+
export const TESTS = /** @type {const} */ (['twoRealUsers', 'noShardNouns', 'dataDriven', 'serverSafe', 'deletionTest', 'dataOnlyApi']);
|
|
16
|
+
|
|
17
|
+
const MODULE = /^(?:src\/(?:client|shared|server|cook)\/(?:engine|game|host|app)\/|@wildshard\/format\/src\/format\/)(?:[\w.-]+\/)*[\w.-]+\.ts$/u;
|
|
18
|
+
const KEY = v.pipe(v.string(), v.check(key => {
|
|
19
|
+
const [module = '', binding, extra] = key.split('#');
|
|
20
|
+
return extra === undefined && MODULE.test(module) && !module.endsWith('.test.ts') && !module.split('/').includes('..') && (binding === undefined || /^[A-Za-z_$][\w$]*$/u.test(binding));
|
|
21
|
+
}, 'a key is a side-first engine module or @wildshard/format/src/format/x.ts, optionally #binding'));
|
|
22
|
+
const DATE = v.pipe(v.string(), v.regex(/^\d{4}-\d{2}-\d{2}$/u));
|
|
23
|
+
const From = v.strictObject({ source: v.string(), line: v.pipe(v.number(), v.integer(), v.minValue(1)), selector: v.pipe(v.string(), v.minLength(1)) });
|
|
24
|
+
const Row = v.strictObject({
|
|
25
|
+
key: KEY,
|
|
26
|
+
verdict: v.picklist(VERDICTS),
|
|
27
|
+
decision: v.pipe(v.string(), v.regex(/^[GJ]\d+$/u)),
|
|
28
|
+
users: v.array(v.pipe(v.string(), v.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u))),
|
|
29
|
+
recheck: v.exactOptional(DATE),
|
|
30
|
+
score: v.exactOptional(v.record(v.picklist(TESTS), v.picklist([0, 1]))),
|
|
31
|
+
from: v.pipe(v.array(From), v.minLength(1)),
|
|
32
|
+
note: v.exactOptional(v.string()),
|
|
33
|
+
});
|
|
34
|
+
const Ids = (/** @type {RegExp} */ shape) => v.strictObject({ source: v.string(), ids: v.array(v.pipe(v.string(), v.regex(shape))) });
|
|
35
|
+
const Register = v.strictObject({
|
|
36
|
+
schema: v.literal('wildshard.host-register/1'),
|
|
37
|
+
about: v.string(),
|
|
38
|
+
decisions: v.strictObject({ G: Ids(/^G\d+$/u), J: Ids(/^J\d+$/u) }),
|
|
39
|
+
sources: v.record(v.string(), v.strictObject({ file: v.string(), rows: v.pipe(v.number(), v.integer(), v.minValue(0)) })),
|
|
40
|
+
merged: v.array(v.strictObject({ key: KEY, kept: v.string(), merged: v.pipe(v.array(v.string()), v.minLength(1)) })),
|
|
41
|
+
dropped: v.array(v.strictObject({ key: v.string(), from: From, reason: v.pipe(v.string(), v.minLength(1)) })),
|
|
42
|
+
rows: v.array(Row),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/** The file behind a register module, or null when engine and the pinned format package lack it.
|
|
46
|
+
* @param {string} module @param {string} [root] */
|
|
47
|
+
export function moduleFile(module, root = ENGINE_ROOT) {
|
|
48
|
+
const path = modulePath(module, root);
|
|
49
|
+
return path !== null && existsSync(path) ? path : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Whether a module's source names a binding at all (declared, exported or re-exported); a cheap guard, not a parse.
|
|
53
|
+
* @param {string} text @param {string} binding */
|
|
54
|
+
export const namesBinding = (text, binding) => new RegExp(`(?<![\\w$])${binding.replaceAll('$', String.raw`\$`)}(?![\\w$])`, 'u').test(text);
|
|
55
|
+
|
|
56
|
+
/** Every reason a parsed register is not valid against the tree at `root`, empty when it is.
|
|
57
|
+
* @param {unknown} json @param {string} [root] @returns {string[]} */
|
|
58
|
+
export function hostRegisterProblems(json, root = ENGINE_ROOT) {
|
|
59
|
+
const parsed = v.safeParse(Register, json);
|
|
60
|
+
if (!parsed.success) return parsed.issues.map(issue => `shape: ${v.getDotPath(issue) ?? ''} ${issue.message}`);
|
|
61
|
+
const register = parsed.output, problems = [], seen = new Set(), ids = new Set([...register.decisions.G.ids, ...register.decisions.J.ids]);
|
|
62
|
+
/** @type {Map<string,string>} */
|
|
63
|
+
const texts = new Map();
|
|
64
|
+
for (const row of register.rows) {
|
|
65
|
+
const [module = '', binding] = row.key.split('#');
|
|
66
|
+
if (seen.has(row.key)) problems.push(`${row.key}: duplicate row`);
|
|
67
|
+
seen.add(row.key);
|
|
68
|
+
if (!ids.has(row.decision)) problems.push(`${row.key}: decision ${row.decision} is in neither ${register.decisions.G.source} nor ${register.decisions.J.source}`);
|
|
69
|
+
const recheck = row.verdict === 'pending' || row.verdict === 'borderline';
|
|
70
|
+
if (recheck !== (row.recheck !== undefined)) problems.push(`${row.key}: ${row.verdict} ${recheck ? 'needs' : 'takes no'} recheck date`);
|
|
71
|
+
if (new Set(row.users).size !== row.users.length) problems.push(`${row.key}: duplicate user`);
|
|
72
|
+
if (row.verdict === 'silly' && row.users.length === 0) problems.push(`${row.key}: silly is charged to its users, and names none`);
|
|
73
|
+
for (const from of row.from) if (register.sources[from.source] === undefined) problems.push(`${row.key}: unknown source ${from.source}`);
|
|
74
|
+
const file = moduleFile(module, root);
|
|
75
|
+
if (file === null) { problems.push(`${row.key}: no such module`); continue; }
|
|
76
|
+
if (binding !== undefined) {
|
|
77
|
+
const text = texts.get(file) ?? readFileSync(file, 'utf8');
|
|
78
|
+
texts.set(file, text);
|
|
79
|
+
if (!namesBinding(text, binding)) problems.push(`${row.key}: ${module} never names ${binding}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const row of register.dropped) if (register.sources[row.from.source] === undefined) problems.push(`dropped ${row.key}: unknown source ${row.from.source}`);
|
|
83
|
+
// Row count equals the sources minus the listed dedupe: every source row is one `from`, or one dropped row.
|
|
84
|
+
const sourceRows = Object.values(register.sources).reduce((sum, source) => sum + source.rows, 0);
|
|
85
|
+
const fromRows = register.rows.reduce((sum, row) => sum + row.from.length, 0);
|
|
86
|
+
if (sourceRows !== fromRows + register.dropped.length) problems.push(`count: sources list ${sourceRows} rows, the register holds ${fromRows} source lines and ${register.dropped.length} dropped`);
|
|
87
|
+
for (const [name, source] of Object.entries(register.sources)) {
|
|
88
|
+
const used = register.rows.reduce((sum, row) => sum + row.from.filter(from => from.source === name).length, 0) + register.dropped.filter(row => row.from.source === name).length;
|
|
89
|
+
if (used !== source.rows) problems.push(`count: source ${name} lists ${source.rows} rows, the register holds ${used}`);
|
|
90
|
+
}
|
|
91
|
+
const multi = register.rows.filter(row => row.from.length > 1);
|
|
92
|
+
const listed = new Map(register.merged.map(row => [row.key, row.merged.length]));
|
|
93
|
+
if (listed.size !== register.merged.length) problems.push('merged: a key is listed twice');
|
|
94
|
+
for (const row of multi) if (listed.get(row.key) !== row.from.length - 1) problems.push(`${row.key}: ${row.from.length - 1} merged source rows, the dedupe list says ${listed.get(row.key) ?? 0}`);
|
|
95
|
+
for (const key of listed.keys()) if (!multi.some(row => row.key === key)) problems.push(`merged ${key}: no row holds it`);
|
|
96
|
+
return problems;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Read and validate the register at `root`; refuse with every problem at once.
|
|
100
|
+
* @param {string} [root] */
|
|
101
|
+
export function readHostRegister(root = ENGINE_ROOT) {
|
|
102
|
+
const json = JSON.parse(readFileSync(join(root, REGISTER), 'utf8'));
|
|
103
|
+
const problems = hostRegisterProblems(json, root);
|
|
104
|
+
if (problems.length > 0) throw new Error(`host register: ${problems.length} problem(s)\n${problems.join('\n')}`);
|
|
105
|
+
return v.parse(Register, json);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The register's committed layout: one source, dedupe, drop or row per line, so a diff shows each change.
|
|
109
|
+
* @param {{rows:unknown[], merged:unknown[], dropped:unknown[], sources:Record<string,unknown>, decisions:Record<string,{source:string, ids:string[]}>, [key:string]:unknown}} register */
|
|
110
|
+
export function formatRegister(register) {
|
|
111
|
+
const { rows, merged, dropped, sources, decisions, ...head } = register;
|
|
112
|
+
const lines = (/** @type {unknown[]} */ list) => list.length === 0 ? '[]' : `[\n${list.map(row => ` ${JSON.stringify(row)}`).join(',\n')}\n ]`;
|
|
113
|
+
const object = (/** @type {Record<string,unknown>} */ record) => `{\n${Object.entries(record).map(([key, value]) => ` ${JSON.stringify(key)}: ${JSON.stringify(value)}`).join(',\n')}\n }`;
|
|
114
|
+
const top = Object.entries(head).map(([key, value]) => ` ${JSON.stringify(key)}: ${JSON.stringify(value)}`);
|
|
115
|
+
return `{\n${[...top, ` "decisions": ${object(decisions)}`, ` "sources": ${object(sources)}`, ` "merged": ${lines(merged)}`, ` "dropped": ${lines(dropped)}`, ` "rows": ${lines(rows)}`].join(',\n')}\n}\n`;
|
|
116
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare const ENGINE_ROOT: string;
|
|
2
|
+
export declare const CLIENT_PLAN: string;
|
|
3
|
+
export declare const CLIENT_PLAN_ROOT: '@client-plan';
|
|
4
|
+
/** Section name -> host selectors (`src/...ts#binding`, `@wildshard/format/x#binding` or `@client-plan`). */
|
|
5
|
+
export declare const SECTION_HOSTS: Readonly<Record<string, readonly string[]>>;
|
|
6
|
+
export interface ModuleRoot { readonly module: string; readonly bindings: readonly string[] }
|
|
7
|
+
export interface ProductRoot extends ModuleRoot { readonly from: string }
|
|
8
|
+
export type ImportShape = 'member' | 'destructure' | 'all';
|
|
9
|
+
export interface ClientPlanRoots {
|
|
10
|
+
readonly shared: readonly (ModuleRoot & { readonly specifier: string; readonly typeOnly: boolean })[];
|
|
11
|
+
readonly kinds: ReadonlyMap<string, readonly ModuleRoot[]>;
|
|
12
|
+
readonly kindShapes: ReadonlyMap<string, readonly ImportShape[]>;
|
|
13
|
+
readonly shapes: Readonly<Record<ImportShape, number>>;
|
|
14
|
+
readonly dynamicImports: number;
|
|
15
|
+
}
|
|
16
|
+
export interface ProductRoots {
|
|
17
|
+
readonly slug: string;
|
|
18
|
+
readonly sections: readonly string[];
|
|
19
|
+
readonly kinds: readonly string[];
|
|
20
|
+
readonly roots: readonly ProductRoot[];
|
|
21
|
+
readonly modules: readonly ModuleRoot[];
|
|
22
|
+
}
|
|
23
|
+
export function resolveModule(specifier: string, from: string, root?: string): string;
|
|
24
|
+
export function clientPlanRoots(root?: string): ClientPlanRoots;
|
|
25
|
+
export function modulePath(module: string, root?: string): string | null;
|
|
26
|
+
export function unresolvedRoots(rows: readonly ModuleRoot[], root?: string): string[];
|
|
27
|
+
export function sectionHostRows(): ModuleRoot[];
|
|
28
|
+
export function productRootsFrom(product: { readonly slug: string; readonly sections: readonly string[]; readonly kinds: readonly string[] }, plan?: ClientPlanRoots): ProductRoots;
|
|
29
|
+
export function productRoots(dir: string, plan?: ClientPlanRoots): ProductRoots;
|