@wildshard/dev 0.0.0 → 0.4.0
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/bin/wildshard.mjs +75 -0
- package/lint/host-callbacks.d.mts +6 -0
- package/lint/host-callbacks.mjs +123 -0
- package/lint/ratchet.json +3 -0
- package/package.json +95 -4
- package/scripts/audit-assets.d.mts +10 -0
- package/scripts/audit-assets.mjs +151 -0
- package/scripts/bake/coatFiles.d.mts +6 -0
- package/scripts/bake/coatFiles.mjs +37 -0
- package/scripts/bake/navmeshGround.ts +22 -0
- package/scripts/bake/near-placeholder.mjs +331 -0
- package/scripts/bake/viewmodelBytes.ts +26 -0
- package/scripts/bake/viewmodelPage.ts +11 -0
- package/scripts/bake-catalogue.mjs +44 -0
- package/scripts/bake-check.mjs +54 -0
- package/scripts/bake-chunk.mjs +124 -0
- package/scripts/bake-cloud-field.mjs +24 -0
- package/scripts/bake-coats.mjs +110 -0
- package/scripts/bake-data-maps.d.mts +24 -0
- package/scripts/bake-data-maps.mjs +78 -0
- package/scripts/bake-entry-programs.mjs +126 -0
- package/scripts/bake-geometry.mjs +106 -0
- package/scripts/bake-ktx2.mjs +477 -0
- package/scripts/bake-map-glb.mjs +127 -0
- package/scripts/bake-map-rest.d.mts +7 -0
- package/scripts/bake-map-rest.mjs +50 -0
- package/scripts/bake-maps.mjs +200 -0
- package/scripts/bake-navmesh.mjs +259 -0
- package/scripts/bake-packs.mjs +129 -0
- package/scripts/bake-pickups.mjs +102 -0
- package/scripts/bake-query-terrain.mjs +64 -0
- package/scripts/bake-textures.mjs +80 -0
- package/scripts/bake-viewmodel-sets.mjs +137 -0
- package/scripts/bake-voxel-ao.mjs +119 -0
- package/scripts/bake-water-ripples.mjs +25 -0
- package/scripts/browser-imports.d.mts +2 -0
- package/scripts/browser-imports.mjs +40 -0
- package/scripts/browser-machine-loader-proof.mjs +39 -0
- package/scripts/browser-machine-loader.d.mts +8 -0
- package/scripts/browser-machine-loader.mjs +87 -0
- package/scripts/browser-playwright.d.mts +10 -0
- package/scripts/browser-playwright.mjs +5 -0
- package/scripts/browser-test.d.mts +4 -0
- package/scripts/browser-test.mjs +18 -0
- package/scripts/build-sdk.mjs +95 -0
- package/scripts/build-shardfiles.d.mts +7 -0
- package/scripts/build-shardfiles.mjs +230 -0
- package/scripts/capture-hero.mjs +211 -0
- package/scripts/chromium-keychain.d.mts +1 -0
- package/scripts/chromium-keychain.mjs +7 -0
- package/scripts/entry-reads/crawl.ts +152 -0
- package/scripts/gen-host-catalogue.d.mts +14 -0
- package/scripts/gen-host-catalogue.mjs +108 -0
- package/scripts/gen-shards.d.mts +17 -0
- package/scripts/gen-shards.mjs +311 -0
- package/scripts/goldens/plot-inputs.d.mts +12 -0
- package/scripts/goldens/plot-inputs.mjs +46 -0
- package/scripts/gpu-texmem.mjs +98 -0
- package/scripts/ktx2-ab.mjs +111 -0
- package/scripts/map-bake-frames.d.mts +4 -0
- package/scripts/map-bake-frames.mjs +23 -0
- package/scripts/map-world.mjs +162 -0
- package/scripts/memory-product.mjs +62 -0
- package/scripts/music/export-midi.mjs +69 -0
- package/scripts/named-blob-output.d.mts +8 -0
- package/scripts/named-blob-output.mjs +48 -0
- package/scripts/practice/verify_unimate_skin.mjs +356 -0
- package/scripts/preparation-browser.mjs +25 -0
- package/scripts/preparation-seed.mjs +15 -0
- package/scripts/prepare-product.d.mts +14 -0
- package/scripts/prepare-product.mjs +133 -0
- package/scripts/prove-walk.mjs +83 -0
- package/scripts/push-tables.d.mts +1 -0
- package/scripts/push-tables.mjs +28 -0
- package/scripts/record-shard-mounts.mjs +133 -0
- package/scripts/section-inventory.ts +209 -0
- package/scripts/shard-build-pool.d.mts +4 -0
- package/scripts/shard-build-pool.mjs +53 -0
- package/scripts/shard-milestones.d.mts +15 -0
- package/scripts/shard-milestones.mjs +105 -0
- package/scripts/shard-progress.mjs +212 -0
- package/scripts/shardfile-cold-boot.mjs +79 -0
- package/scripts/shardfile-rolldown.d.mts +2 -0
- package/scripts/shardfile-rolldown.mjs +32 -0
- package/scripts/shardfile-vite.d.mts +4 -0
- package/scripts/shardfile-vite.mjs +20 -0
- package/scripts/site-facts.mjs +88 -0
- package/scripts/test-template-gate.mjs +44 -0
- package/scripts/tex-tiers.mjs +240 -0
- package/scripts/unused-assets.mjs +173 -0
- package/scripts/wildshard.d.mts +4 -0
- package/scripts/wildshard.mjs +146 -0
- package/scripts/witness-generation.d.mts +10 -0
- package/scripts/witness-generation.mjs +45 -0
- package/src/.oxlintrc.json +12 -0
- package/src/cli/bin.mjs +8 -0
- package/src/cli/content-command.ts +44 -0
- package/src/cli/content.ts +287 -0
- package/src/cli/grid/command.ts +48 -0
- package/src/cli/grid/grid.ts +155 -0
- package/src/cli/help.ts +262 -0
- package/src/cli/hero/adopt.ts +109 -0
- package/src/cli/install-home.ts +40 -0
- package/src/cli/main.ts +142 -0
- package/src/cli/version.ts +63 -0
- package/src/server/app.ts +19 -0
- package/src/server/serve.ts +49 -0
- package/src/sharddev/bake/json.mjs +84 -0
- package/src/sharddev/bake/mapRest.ts +57 -0
- package/src/sharddev/bake/nativeRaster.ts +106 -0
- package/src/sharddev/bake/source-loader.mjs +55 -0
- package/src/sharddev/bake/splatLayers.ts +29 -0
- package/src/sharddev/bootInventory.ts +132 -0
- package/src/sharddev/check.ts +125 -0
- package/src/sharddev/checkProject.ts +134 -0
- package/src/sharddev/cli.ts +207 -0
- package/src/sharddev/dev.ts +150 -0
- package/src/sharddev/devClient.ts +120 -0
- package/src/sharddev/devRoot.ts +6 -0
- package/src/sharddev/engineMusic.ts +23 -0
- package/src/sharddev/projectEntryProof.ts +32 -0
- package/src/sharddev/test/diskScriptScenario.ts +88 -0
- package/src/sharddev/test/scriptScenario.ts +254 -0
- package/src/sharddev/tsconfig.json +3 -0
- package/src/sharddev/watch/page.ts +288 -0
- package/src/sharddev/watch/pageEntry.ts +44 -0
- package/src/sharddev/watch/parity-baseline.json +22 -0
- package/src/sharddev/watch/parity.mjs +194 -0
- package/src/sharddev/watch/proof.mjs +199 -0
- package/src/sharddev/watch/socket.ts +57 -0
- package/src/sharddev/watch/watch.ts +382 -0
- package/src/shared/health.ts +10 -0
- package/src/tools/build-web.ts +59 -0
- package/src/web/app.tsx +53 -0
- package/src/web/index.html +12 -0
- package/src/web/main.tsx +10 -0
- package/tsconfig.author.json +25 -0
- package/tsconfig.json +47 -0
- package/README.md +0 -3
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// G454: build output, not a hand-maintained list of supposedly shared hosts.
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, resolve } from 'node:path';
|
|
4
|
+
import { pathToFileURL } from 'node:url';
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
|
+
import ts from '@typescript/typescript6';
|
|
7
|
+
import { hostAnalysis } from '../lint/host-callbacks.mjs';
|
|
8
|
+
import { referenceData } from '@wildshard/sdk/scripts/docs/gen-shardfile-reference.mjs';
|
|
9
|
+
import { formatSource } from '@wildshard/engine/scripts/format-package.mjs';
|
|
10
|
+
|
|
11
|
+
const ROOT = resolve(import.meta.dirname, '..');
|
|
12
|
+
const AUDIT = 'progress/shard-platform/host-audit-2026-10-16/README.md';
|
|
13
|
+
const keyOf = row => `${row.module}#${row.export}`;
|
|
14
|
+
const hash = text => createHash('sha256').update(text).digest('hex');
|
|
15
|
+
const order = (a, b) => a.localeCompare(b);
|
|
16
|
+
const verdict = (status, evidence) => ({ status, evidence });
|
|
17
|
+
const review = reason => verdict('needs-review', reason);
|
|
18
|
+
|
|
19
|
+
/** Machine findings are evidence, never a substitute for the semantic host grill. */
|
|
20
|
+
export function hostVerdicts(users, callbacks, audited, sourceHash) {
|
|
21
|
+
const results = {
|
|
22
|
+
twoRealUsers: review(`${users.length} resolved calling shards; verify entry reach and live adoption before granting shared credit`),
|
|
23
|
+
noShardNouns: review(`Semantic review required; see ${AUDIT}`),
|
|
24
|
+
dataOnly: callbacks.length > 0 ? verdict('fail', `${callbacks.length} shard TS callback values cross this host`)
|
|
25
|
+
: review('No explicit shard callbacks found; host parameter semantics still require review'),
|
|
26
|
+
serverSafe: review('Import/DOM and server execution review required; client presentation is labelled separately'),
|
|
27
|
+
deletionTest: review('A reviewer must judge whether this survives deletion of its first shard'),
|
|
28
|
+
};
|
|
29
|
+
if (typeof sourceHash === 'string' && audited?.sourceHash === sourceHash && audited.evidence) for (const test of ['twoRealUsers', 'noShardNouns', 'dataOnly', 'serverSafe', 'deletionTest']) {
|
|
30
|
+
if (test === 'dataOnly' && callbacks.length > 0) continue;
|
|
31
|
+
const status = audited.verdicts?.[test];
|
|
32
|
+
if (status === 'pass' || status === 'fail') results[test] = verdict(status, audited.evidence);
|
|
33
|
+
}
|
|
34
|
+
return results;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Inventory resolved call targets plus pending hosts. Planned W3 users are never real-user evidence. */
|
|
38
|
+
export function hostCatalogue(root = ROOT, reference = referenceData(root)) {
|
|
39
|
+
const analysis = hostAnalysis(root), { program, checker } = analysis, hosts = new Map();
|
|
40
|
+
const get = identity => {
|
|
41
|
+
const key = keyOf(identity);
|
|
42
|
+
if (!hosts.has(key)) hosts.set(key, { module: identity.module, export: identity.export, calls: [], callbacks: [], pendingUsers: [] });
|
|
43
|
+
return hosts.get(key);
|
|
44
|
+
};
|
|
45
|
+
for (const file of analysis.files.toSorted(order)) {
|
|
46
|
+
const scan = analysis.scan(file);
|
|
47
|
+
for (const call of scan.calls) get(call).calls.push(call);
|
|
48
|
+
for (const callback of scan.callbacks) get(callback).callbacks.push(callback);
|
|
49
|
+
}
|
|
50
|
+
const pendingPath = resolve(root, 'lint/platform-pending-users.json');
|
|
51
|
+
const pending = existsSync(pendingPath) ? JSON.parse(readFileSync(pendingPath, 'utf8')).entries : [];
|
|
52
|
+
for (const row of pending) {
|
|
53
|
+
const host = get({ module: row.module, export: row.export ?? '*' });
|
|
54
|
+
host.pendingUsers.push(row);
|
|
55
|
+
if (row.export === undefined && host.calls.length === 0) for (const called of hosts.values()) {
|
|
56
|
+
if (called !== host && called.module === row.module) { host.calls.push(...called.calls); host.callbacks.push(...called.callbacks); }
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const reviewsPath = resolve(root, 'lint/host-reviews.json');
|
|
60
|
+
const reviews = existsSync(reviewsPath) ? JSON.parse(readFileSync(reviewsPath, 'utf8')).entries : {};
|
|
61
|
+
const sectionFile = program.getSourceFile(formatSource(root, 'sections.ts'));
|
|
62
|
+
const registry = sectionFile?.statements.find(node => ts.isInterfaceDeclaration(node) && node.name.text === 'PlatformSections');
|
|
63
|
+
if (!registry) throw new Error('Host catalogue requires the public PlatformSections registry');
|
|
64
|
+
const sections = registry.members.filter(ts.isPropertySignature).map(member => {
|
|
65
|
+
const type = checker.getTypeAtLocation(member);
|
|
66
|
+
const readers = [...hosts.values()].filter(host => host.export !== '*').flatMap(host => host.calls.filter(call => call.strings.includes(member.name.text)));
|
|
67
|
+
return { name: member.name.text, type: member.type?.getText(sectionFile) ?? '', readers,
|
|
68
|
+
hosts: [...new Set(readers.map(keyOf))].sort(order), users: [...new Set(readers.map(call => call.file.split('/')[2]))].sort(order),
|
|
69
|
+
fields: checker.getPropertiesOfType(type).map(field => ({ name: field.name,
|
|
70
|
+
type: checker.typeToString(checker.getTypeOfSymbolAtLocation(field, member)) })).sort((a, b) => a.name.localeCompare(b.name)) };
|
|
71
|
+
}).sort((a, b) => a.name.localeCompare(b.name));
|
|
72
|
+
const rows = [...hosts.values()].map(row => {
|
|
73
|
+
const users = [...new Set(row.calls.map(call => call.file.split('/')[2]))].sort(order);
|
|
74
|
+
const source = program.getSourceFile(resolve(root, row.module));
|
|
75
|
+
const sourceHash = source ? hash(source.text) : null;
|
|
76
|
+
return { module: row.module, export: row.export, calls: row.calls, callbacks: row.callbacks,
|
|
77
|
+
pendingUsers: row.pendingUsers, users, sourceHash,
|
|
78
|
+
verdicts: hostVerdicts(users, row.callbacks, reviews[keyOf(row)] ?? reviews[`${row.module}#*`], sourceHash), review: { source: AUDIT, revision: '9160141e3',
|
|
79
|
+
status: 'Historical review; not silently promoted to a current five-test pass' } };
|
|
80
|
+
}).sort((a, b) => keyOf(a).localeCompare(keyOf(b)));
|
|
81
|
+
return { schema: 'wildshard.host-catalogue/1',
|
|
82
|
+
coverage: 'Resolved calls/new expressions in non-frozen play TS; aliases, inherited methods and named callbacks. Indirect/dynamic calls and semantic host tests require review. No imports or planned W3 users count as actual users.',
|
|
83
|
+
sections, fields: reference.fields, wasm: { contract: reference.contract, signatures: reference.abi }, hosts: rows };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function renderHostCatalogue(catalogue) {
|
|
87
|
+
const cell = value => String(value).replaceAll('|', String.raw`\|`).replaceAll('\n', ' ');
|
|
88
|
+
const lines = ['# Host catalogue (generated)', '', catalogue.coverage, '',
|
|
89
|
+
'Five verdicts: two real users / no shard nouns / data-only / server-safe / deletion test. `needs-review` grants no pass.', '',
|
|
90
|
+
'## Sections', '', 'Readers below are statically resolved literal section reads; dynamic/host-internal access still needs review.', '',
|
|
91
|
+
'| Section | Fields | Reading hosts | Calling shards |', '|---|---|---|---|',
|
|
92
|
+
...catalogue.sections.map(row => `| ${cell(row.name)} | ${row.fields.map(field => cell(field.name)).join(', ')} | ${row.hosts.map(cell).join(', ')} | ${row.users.map(cell).join(', ')} |`), '',
|
|
93
|
+
'Full schema field inventory and exact Wasm ABI: [SHARDFILE.md](SHARDFILE.md). Machine-readable detail: `lint/host-catalogue.generated.json`.', '',
|
|
94
|
+
'## Hosts', '', '| Host | Resolved calling shards | Planned W3 users | Five verdicts |', '|---|---|---|---|',
|
|
95
|
+
...catalogue.hosts.map(row => `| ${cell(keyOf(row))} | ${row.users.length === 0 ? 'none proven' : row.users.map(cell).join(', ')} | ${[...new Set(row.pendingUsers.map(pending => pending.shard ?? `approved: ${pending.approvedFeature?.name ?? 'unknown'}`))].map(cell).join(', ')} | ${Object.values(row.verdicts).map(result => result.status).join(' / ')} |`)];
|
|
96
|
+
return `${lines.join('\n')}\n`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** pnpm docs publishes both the JSON retained in deploy trees and the human-readable generated page. */
|
|
100
|
+
export function writeHostCatalogue(root = ROOT) {
|
|
101
|
+
const catalogue = hostCatalogue(root);
|
|
102
|
+
const outputs = { 'lint/host-catalogue.generated.json': `${JSON.stringify(catalogue, null, 2)}\n`, 'docs/api/HOSTS.md': renderHostCatalogue(catalogue) };
|
|
103
|
+
for (const [file, text] of Object.entries(outputs)) { mkdirSync(dirname(resolve(root, file)), { recursive: true }); writeFileSync(resolve(root, file), text); }
|
|
104
|
+
console.info(`host-catalogue: ${catalogue.hosts.length} hosts, ${catalogue.sections.length} sections`);
|
|
105
|
+
return catalogue;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(resolve(process.argv[1])).href) writeHostCatalogue();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ShardFolder } from '@wildshard/build/scripts/shard-outputs.mjs';
|
|
2
|
+
|
|
3
|
+
export function shardFolders(root: string): string[];
|
|
4
|
+
/** Every product slug (SF88g: a folder's declared outputs, else the folder itself). */
|
|
5
|
+
export function shardSlugs(root: string): string[];
|
|
6
|
+
export function shardSource(root: string): string;
|
|
7
|
+
/** Type-only facade over generated identity data, including registered frozen copies. */
|
|
8
|
+
export function manifestClosure(root: string): Record<string, string[]>;
|
|
9
|
+
/** Core manifest/slug inputs for boot generation; full genShards publishes title tables afterward. */
|
|
10
|
+
export function genShardInputs(root?: string, check?: boolean, initializeMissing?: boolean, shard?: string): void;
|
|
11
|
+
export function genShards(root?: string, check?: boolean, initializeMissing?: boolean, shard?: string): void;
|
|
12
|
+
export function manifestContract(root: string, closure: Record<string, string[]>, fields?: boolean): string[];
|
|
13
|
+
|
|
14
|
+
/** Refresh identities before any consumer imports cached discovery modules. */
|
|
15
|
+
export function refreshDiscovery(root?: string): void;
|
|
16
|
+
/** Preserve every physical static/lazy module target when a discovery output leaves src. */
|
|
17
|
+
export function relocateDiscoverySource(root: string, product: Pick<ShardFolder, 'slug' | 'folder' | 'output'>, text: string): string;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// E357 F9: folder discovery is the sole authored shard list.
|
|
2
|
+
import { randomUUID } from 'node:crypto';
|
|
3
|
+
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { dirname, resolve, relative } from 'node:path';
|
|
5
|
+
import { pathToFileURL } from 'node:url';
|
|
6
|
+
import ts from '@typescript/typescript6';
|
|
7
|
+
import { folderManifestPath, authoredManifestSource } from '@wildshard/engine/scripts/authored-manifest.mjs';
|
|
8
|
+
import { outputManifest, builtShardFolders } from '@wildshard/build/scripts/shard-outputs.mjs';
|
|
9
|
+
import { genShardWords } from '@wildshard/engine/scripts/gen-shard-words.mjs';
|
|
10
|
+
import { readProgramDiscovery, usesProgramDiscovery } from '@wildshard/engine/scripts/program-discovery.mjs';
|
|
11
|
+
import { authoredManifestImports } from '@wildshard/engine/scripts/manifest-static-imports.mjs';
|
|
12
|
+
|
|
13
|
+
/** Static runtime imports only: lazy plugin/look thunks and erased types stay out of the startup closure. */
|
|
14
|
+
export function manifestClosure(root) {
|
|
15
|
+
const configPath = ts.findConfigFile(root, (file) => ts.sys.fileExists(file));
|
|
16
|
+
const config = configPath ? ts.readConfigFile(configPath, (file) => ts.sys.readFile(file)).config : {};
|
|
17
|
+
const { options } = ts.parseJsonConfigFileContent(config, ts.sys, root);
|
|
18
|
+
// All products in this synchronous walk resolve against the same options.
|
|
19
|
+
// Reuse resolution work and immutable syntax, never the closure or file bytes.
|
|
20
|
+
const resolutions = ts.createModuleResolutionCache(root, name => ts.sys.useCaseSensitiveFileNames ? name : name.toLowerCase(), options);
|
|
21
|
+
/** @type {Map<string,{text:string,source:import('@typescript/typescript6').SourceFile}>} */
|
|
22
|
+
const syntax = new Map();
|
|
23
|
+
const result = {};
|
|
24
|
+
for (const product of builtShardFolders(root, shardFolders(root))) {
|
|
25
|
+
const slug = product.slug, seen = new Set();
|
|
26
|
+
const entry = resolve(root, folderManifestPath(root, product));
|
|
27
|
+
const authored = resolve(root, `src/shards/${product.folder}/manifest.json`);
|
|
28
|
+
const visit = (file) => {
|
|
29
|
+
const id = relative(root, file).replaceAll('\\', '/');
|
|
30
|
+
if (seen.has(id)) return;
|
|
31
|
+
seen.add(id);
|
|
32
|
+
if (!/\.[cm]?[jt]sx?$/.test(file)) return;
|
|
33
|
+
const text = file === entry && existsSync(authored)
|
|
34
|
+
? relocateDiscoverySource(root, product, authoredManifestImports(root, product.folder, product.output === null ? JSON.parse(readFileSync(authored, 'utf8')) : outputManifest(root, product.folder, product.output), product.output !== null)
|
|
35
|
+
.map(specifier => `import ${JSON.stringify(specifier)};`).join('\n'))
|
|
36
|
+
: readFileSync(file, 'utf8');
|
|
37
|
+
let parsed = syntax.get(file);
|
|
38
|
+
if (parsed?.text !== text) {
|
|
39
|
+
parsed = { text, source: ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true) };
|
|
40
|
+
syntax.set(file, parsed);
|
|
41
|
+
}
|
|
42
|
+
const source = parsed.source;
|
|
43
|
+
for (const node of source.statements) {
|
|
44
|
+
if (!ts.isImportDeclaration(node) && !ts.isExportDeclaration(node)) continue;
|
|
45
|
+
if (!node.moduleSpecifier || !ts.isStringLiteral(node.moduleSpecifier)) continue;
|
|
46
|
+
if (ts.isImportDeclaration(node)) {
|
|
47
|
+
if (node.importClause?.phaseModifier === ts.SyntaxKind.TypeKeyword) continue;
|
|
48
|
+
const bindings = node.importClause?.namedBindings;
|
|
49
|
+
if (!node.importClause?.name && bindings && ts.isNamedImports(bindings) && bindings.elements.length > 0 && bindings.elements.every((e) => e.isTypeOnly)) continue;
|
|
50
|
+
} else if (node.isTypeOnly || (node.exportClause && ts.isNamedExports(node.exportClause) && node.exportClause.elements.length > 0 && node.exportClause.elements.every((e) => e.isTypeOnly))) continue;
|
|
51
|
+
const specifier = node.moduleSpecifier.text;
|
|
52
|
+
const target = ts.resolveModuleName(specifier, file, options, ts.sys, resolutions).resolvedModule?.resolvedFileName;
|
|
53
|
+
if (target && !target.includes('/node_modules/') && !target.endsWith('.d.ts')) visit(target);
|
|
54
|
+
// TypeScript intentionally does not resolve raster imports; include their bundler module ids too.
|
|
55
|
+
else if (specifier.startsWith('.') && existsSync(resolve(dirname(file), specifier))) visit(resolve(dirname(file), specifier));
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
visit(entry);
|
|
59
|
+
result[slug] = [...seen].sort((a, b) => a.localeCompare(b));
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Every product slug (SF88g: a folder's declared outputs, else the folder itself). */
|
|
65
|
+
export function shardSlugs(root) { return builtShardFolders(root, shardFolders(root)).map((row) => row.slug); }
|
|
66
|
+
export function shardFolders(root) {
|
|
67
|
+
return readdirSync(resolve(root, 'src/shards'), { withFileTypes: true })
|
|
68
|
+
.filter((entry) => entry.isDirectory() && ['manifest.ts', 'manifest.json'].some(file => existsSync(resolve(root, 'src/shards', entry.name, file))))
|
|
69
|
+
.map((entry) => entry.name).sort();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The shard list (E362 AG4): every manifest, imported by the composition root (src/shards.generated.ts, installed by
|
|
75
|
+
* src/shardList.ts) so the game layer imports no shard, and its TypeScript project builds without them.
|
|
76
|
+
*/
|
|
77
|
+
export function shardSource(root) {
|
|
78
|
+
const products = builtShardFolders(root, shardFolders(root)), slugs = products.map((row) => row.slug);
|
|
79
|
+
if (slugs.length === 0) throw new Error('gen-shards: no shard manifests');
|
|
80
|
+
const catalogue = resolve(root, 'src/shared/game/grid/singleplayer.json');
|
|
81
|
+
const placements = existsSync(catalogue) ? JSON.parse(readFileSync(catalogue, 'utf8')).placements : null;
|
|
82
|
+
if (placements !== null) {
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
for (const p of placements) {
|
|
85
|
+
if (!slugs.includes(p.slug) || seen.has(p.slug) || !Array.isArray(p.cell) || p.cell.length !== 2 || !p.cell.every(Number.isSafeInteger) || !Array.isArray(p.size) || p.size.length !== 3 || !p.size.every((n) => n === 500) || typeof p.instance !== 'string') throw new Error('gen-shards: invalid grid placement');
|
|
86
|
+
seen.add(p.slug);
|
|
87
|
+
}
|
|
88
|
+
if (seen.size !== slugs.length) throw new Error('gen-shards: missing grid placement');
|
|
89
|
+
}
|
|
90
|
+
const placed = slugs.flatMap((slug, i) => {
|
|
91
|
+
if (placements === null) return [`m${i}`];
|
|
92
|
+
const p = placements.find((entry) => entry.slug === slug);
|
|
93
|
+
return [`{ ...m${i}, placement: { grid: ${JSON.stringify(p.cell)}, size: ${JSON.stringify(p.size)}, instance: ${JSON.stringify(p.instance)} } }`];
|
|
94
|
+
});
|
|
95
|
+
const metadata = placements === null ? '' : ' & { placement: { grid: [number, number]; size: [number, number, number]; instance: string } }';
|
|
96
|
+
return `// Generated by gen:source (scripts/gen-shards.mjs) from authored manifests, outputs and grid placements; do not edit.
|
|
97
|
+
import type { ShardManifest } from './game/client/shard/manifest';
|
|
98
|
+
${products.map((product, i) => `import m${i} from '${moduleRelative(resolve(root, 'src'), resolve(root, folderManifestPath(root, product))).slice(0, -'.ts'.length)}';`).join('\n')}
|
|
99
|
+
const placed: (ShardManifest${metadata})[] = [${placed.join(', ')}];
|
|
100
|
+
export const SHARDS: typeof placed = placed.sort((a, b) => a.order - b.order);
|
|
101
|
+
`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const LOAD = /\bload:\s*\(\)\s*=>\s*import\(\s*['"]\.\.?\/plugin(?:\.ts)?['"]\s*\)/u;
|
|
105
|
+
const BUDGET_FILE = 'lint/manifest-closure-budget.json';
|
|
106
|
+
/** Only the exported manifest object can opt into the data-descriptor contract. */
|
|
107
|
+
export function shardfileDescriptor(text) {
|
|
108
|
+
const source = ts.createSourceFile('manifest.ts', text, ts.ScriptTarget.Latest, true);
|
|
109
|
+
const variables = new Map(); let expression;
|
|
110
|
+
for (const statement of source.statements) {
|
|
111
|
+
if (ts.isVariableStatement(statement)) for (const declaration of statement.declarationList.declarations) {
|
|
112
|
+
if (ts.isIdentifier(declaration.name)) variables.set(declaration.name.text, declaration.initializer);
|
|
113
|
+
}
|
|
114
|
+
if (ts.isExportAssignment(statement) && !statement.isExportEquals) expression = statement.expression;
|
|
115
|
+
}
|
|
116
|
+
if (expression && ts.isIdentifier(expression)) expression = variables.get(expression.text);
|
|
117
|
+
while (expression && (ts.isSatisfiesExpression(expression) || ts.isAsExpression(expression) || ts.isParenthesizedExpression(expression))) expression = expression.expression;
|
|
118
|
+
if (!expression || !ts.isObjectLiteralExpression(expression)) return null;
|
|
119
|
+
const named = (property, name) => property.name && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name)) && property.name.text === name;
|
|
120
|
+
const property = expression.properties.find((row) => named(row, 'shardfile'));
|
|
121
|
+
if (property === undefined) return null;
|
|
122
|
+
return { path: ts.isPropertyAssignment(property) && ts.isStringLiteral(property.initializer) ? property.initializer.text : null,
|
|
123
|
+
load: expression.properties.some((row) => named(row, 'load')) };
|
|
124
|
+
}
|
|
125
|
+
function descriptorContract(root, slug, text) {
|
|
126
|
+
const descriptor = shardfileDescriptor(text);
|
|
127
|
+
if (descriptor === null) return null;
|
|
128
|
+
const failures = [];
|
|
129
|
+
if (descriptor.path !== `/shardfiles/${slug}/shard.json`) failures.push('shardfile must be the literal canonical /shardfiles/<slug>/shard.json path');
|
|
130
|
+
if (!existsSync(resolve(root, `src/shards/${slug}/shard.config.ts`))) failures.push('shardfile descriptor requires its buildable shard.config.ts project');
|
|
131
|
+
if (descriptor.load) failures.push('shardfile descriptor cannot also load a runtime plugin');
|
|
132
|
+
return failures;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* E362 AG10: a legacy `load` is `() => import('./plugin')`; a data descriptor has a canonical shardfile path and no load.
|
|
136
|
+
* manifest's static closure stays inside its file budget (`lint/manifest-closure-budget.json`: one `default` limit for
|
|
137
|
+
* every shard, not a ratchet); every `ShardManifest` field is read by the engine, the game or the tooling (`fields`).
|
|
138
|
+
* Slug = folder is check-shards' (AG9).
|
|
139
|
+
*/
|
|
140
|
+
export function manifestContract(root, closure, fields = false) {
|
|
141
|
+
const failures = [];
|
|
142
|
+
const budgetPath = resolve(root, BUDGET_FILE);
|
|
143
|
+
const budgets = existsSync(budgetPath) ? JSON.parse(readFileSync(budgetPath, 'utf8')).budgets : {};
|
|
144
|
+
for (const product of builtShardFolders(root, shardFolders(root))) {
|
|
145
|
+
const slug = product.slug, folder = product.folder;
|
|
146
|
+
const json = existsSync(resolve(root, `src/shards/${folder}/manifest.json`));
|
|
147
|
+
const source = readFileSync(resolve(root, json ? `src/shards/${folder}/manifest.json` : `src/shards/${folder}/manifest.ts`), 'utf8');
|
|
148
|
+
const descriptor = json ? null : descriptorContract(root, slug, source);
|
|
149
|
+
const authored = !json ? null : product.output === null ? JSON.parse(source) : outputManifest(root, folder, product.output);
|
|
150
|
+
const dataOnly = json && authored.shardfile === `/shardfiles/${slug}/shard.json` && authored.bindings?.load === undefined && authored.bindings?.entry === undefined && existsSync(resolve(root, `src/shards/${folder}/shard.config.ts`));
|
|
151
|
+
if (descriptor !== null) failures.push(...descriptor.map((message) => `src/shards/${slug}/manifest.ts: ${message}`));
|
|
152
|
+
else if (!dataOnly && (json ? authored.bindings?.entry === undefined && authored.bindings?.load?.module !== './plugin' : !LOAD.test(source))) failures.push(`src/shards/${slug}/manifest.ts: load must be \`() => import('./plugin')\` (a lazy plugin, never a static import)`);
|
|
153
|
+
if (/^import\s[^;]*['"]\.\.?\/plugin(?:\.ts)?['"]/mu.test(source)) failures.push(`src/shards/${slug}/manifest.ts imports ./plugin statically: it would ride in cold boot`);
|
|
154
|
+
const budget = budgets[slug] ?? budgets.default, size = closure[slug]?.length ?? 0;
|
|
155
|
+
if (typeof budget === 'number' && size > budget) failures.push(`src/shards/${slug}/manifest.ts: its static closure is ${size} files, over its budget ${budget} (${BUDGET_FILE}); move the new imports behind load / a lazy thunk`);
|
|
156
|
+
}
|
|
157
|
+
if (fields) {
|
|
158
|
+
const file = resolve(root, 'src/client/game/shard/manifest.ts');
|
|
159
|
+
const decl = ts.createSourceFile(file, readFileSync(file, 'utf8'), ts.ScriptTarget.Latest, true);
|
|
160
|
+
let names = [];
|
|
161
|
+
decl.forEachChild((n) => { if (ts.isInterfaceDeclaration(n) && n.name.text === 'ShardManifest') names = n.members.filter(ts.isPropertySignature).map((m) => m.name.getText(decl)); });
|
|
162
|
+
const texts = [];
|
|
163
|
+
const scan = (dir) => {
|
|
164
|
+
if (!existsSync(resolve(root, dir))) return;
|
|
165
|
+
for (const entry of readdirSync(resolve(root, dir), { withFileTypes: true })) {
|
|
166
|
+
const path = `${dir}/${entry.name}`;
|
|
167
|
+
if (entry.isDirectory()) scan(path);
|
|
168
|
+
else if (/\.[cm]?[jt]s$/u.test(entry.name) && !entry.name.endsWith('.generated.ts')) texts.push(readFileSync(resolve(root, path), 'utf8'));
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
for (const dir of ['src/engine', 'src/game', 'lint', 'scripts']) scan(dir);
|
|
172
|
+
const all = texts.join('\n');
|
|
173
|
+
for (const name of names) if (!new RegExp(`\\.${name}\\b|['"]${name}['"]`, 'u').test(all)) failures.push(`ShardManifest.${name}: nothing in the engine, the game or the tooling reads it; drop the field`);
|
|
174
|
+
}
|
|
175
|
+
return failures;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** A product's discovery module source (its manifest.json bindings, its composed output when it declares one). */
|
|
179
|
+
function discoverySource(root, product) {
|
|
180
|
+
const composed = product.output === null ? null : outputManifest(root, product.folder, product.output);
|
|
181
|
+
const metadata = composed ?? JSON.parse(readFileSync(resolve(root, `src/shards/${product.folder}/manifest.json`), 'utf8'));
|
|
182
|
+
const program = usesProgramDiscovery(metadata);
|
|
183
|
+
return relocateDiscoverySource(root, product, authoredManifestSource(root, product.slug, { folder: product.folder, composed,
|
|
184
|
+
...(program ? { discovery: readProgramDiscovery(root, product.slug) } : {}) }));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function moduleRelative(from, to) {
|
|
188
|
+
const path = relative(from, to).replaceAll('\\', '/');
|
|
189
|
+
return path.startsWith('.') ? path : `./${path}`;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Rebase only actual module specifiers, never identically spelled authored data strings. */
|
|
193
|
+
export function relocateDiscoverySource(root, product, text) {
|
|
194
|
+
const original = resolve(root, 'src/shards', product.folder), destination = dirname(resolve(root, folderManifestPath(root, product)));
|
|
195
|
+
if (original === destination) return text;
|
|
196
|
+
const source = ts.createSourceFile('discovery.ts', text, ts.ScriptTarget.Latest, true), edits = [];
|
|
197
|
+
const visit = node => {
|
|
198
|
+
const specifier = (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) ? node.moduleSpecifier
|
|
199
|
+
: ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword ? node.arguments[0] : undefined;
|
|
200
|
+
if (specifier !== undefined && ts.isStringLiteral(specifier) && specifier.text.startsWith('.'))
|
|
201
|
+
edits.push({ start: specifier.getStart(source), end: specifier.getEnd(), value: JSON.stringify(moduleRelative(destination, resolve(original, specifier.text))) });
|
|
202
|
+
ts.forEachChild(node, visit);
|
|
203
|
+
};
|
|
204
|
+
visit(source);
|
|
205
|
+
let output = text;
|
|
206
|
+
for (const edit of edits.sort((left, right) => right.start - left.start)) output = output.slice(0, edit.start) + edit.value + output.slice(edit.end);
|
|
207
|
+
return output;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Publish a complete replacement without truncating the module concurrent readers hold.
|
|
211
|
+
* @param {string} path @param {string} source */
|
|
212
|
+
function writeDiscovery(path, source) {
|
|
213
|
+
if (existsSync(path) && readFileSync(path, 'utf8') === source) return;
|
|
214
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
215
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
216
|
+
try { writeFileSync(temporary, source, { flag: 'wx' }); renameSync(temporary, path); }
|
|
217
|
+
finally { rmSync(temporary, { force: true }); }
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Refresh every provider whose receipt/bindings are available. A missing or stale
|
|
221
|
+
* product never deletes its last published module: a later generation failure must
|
|
222
|
+
* not break concurrent source readers. genShards still requires current products and
|
|
223
|
+
* strictly replaces these modules after program construction; no placeholder is emitted. */
|
|
224
|
+
export function refreshDiscovery(root = resolve(import.meta.dirname, '..')) {
|
|
225
|
+
for (const product of builtShardFolders(root, shardFolders(root))) {
|
|
226
|
+
if (!existsSync(resolve(root, `src/shards/${product.folder}/manifest.json`))) continue;
|
|
227
|
+
const path = resolve(root, folderManifestPath(root, product));
|
|
228
|
+
let source;
|
|
229
|
+
try { source = discoverySource(root, product); } catch { continue; }
|
|
230
|
+
writeDiscovery(path, source);
|
|
231
|
+
// Retire the old source wrapper only after its complete replacement exists.
|
|
232
|
+
const prior = resolve(root, 'src/shards', product.folder, product.output === null ? 'discovery.generated.ts' : `discovery.${product.slug}.generated.ts`);
|
|
233
|
+
if (prior !== path && existsSync(prior)) rmSync(prior);
|
|
234
|
+
}
|
|
235
|
+
retireDiscoveryBank(root);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** This generator owns only its marked discovery modules, never other .app products. */
|
|
239
|
+
function retireDiscoveryBank(root) {
|
|
240
|
+
const bank = resolve(root, 'out/.app');
|
|
241
|
+
if (!existsSync(bank)) return;
|
|
242
|
+
const owned = new Set(builtShardFolders(root, shardFolders(root)).map(product => resolve(root, folderManifestPath(root, product))));
|
|
243
|
+
for (const file of readdirSync(bank)) {
|
|
244
|
+
if (!/^discovery\.[a-z0-9_.-]+\.generated\.ts$/u.test(file)) continue;
|
|
245
|
+
const path = resolve(bank, file);
|
|
246
|
+
if (!owned.has(path) && readFileSync(path, 'utf8').startsWith('// Generated by scripts/gen-shards.mjs — do not edit or commit.\n')) rmSync(path);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** The build-written shard tables (the shard list, the manifest closure), which import and walk every product's
|
|
251
|
+
* discovery module, by output path. genShards writes them; gen:source registers both. */
|
|
252
|
+
export function shardTables(root) {
|
|
253
|
+
const closure = manifestClosure(root);
|
|
254
|
+
return { 'src/shards.generated.ts': shardSource(root), 'src/server/game/shard/manifest-closure.generated.json': `${JSON.stringify(closure, null, 2)}\n` };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** Emit the manifest inputs the boot writer actually consumes. Title data
|
|
258
|
+
* is emitted by the final genShards pass after boot tables are complete. */
|
|
259
|
+
export function genShardInputs(root = resolve(import.meta.dirname, '..'), check = false, initializeMissing = false, shard = '') {
|
|
260
|
+
genShardWords(root, check, shard);
|
|
261
|
+
for (const product of builtShardFolders(root, shardFolders(root))) {
|
|
262
|
+
if (!existsSync(resolve(root, `src/shards/${product.folder}/manifest.json`))) continue;
|
|
263
|
+
const path = resolve(root, folderManifestPath(root, product)), source = discoverySource(root, product);
|
|
264
|
+
if (check && existsSync(path) && readFileSync(path, 'utf8') !== source) throw new Error(`gen-shards: stale ${path}`);
|
|
265
|
+
if (!check || !existsSync(path)) writeDiscovery(path, source);
|
|
266
|
+
}
|
|
267
|
+
// SF88g: a discovery module no product owns any more (a folder that now declares outputs, a dropped output) is removed,
|
|
268
|
+
// so no tree, mirror or loader keeps importing a retired product's manifest
|
|
269
|
+
const owned = new Set(builtShardFolders(root, shardFolders(root)).map((product) => resolve(root, folderManifestPath(root, product))));
|
|
270
|
+
for (const folder of shardFolders(root)) for (const file of readdirSync(resolve(root, 'src/shards', folder))) {
|
|
271
|
+
const path = resolve(root, 'src/shards', folder, file);
|
|
272
|
+
if (!/^discovery(?:\.[a-z0-9-]+)?\.generated\.ts$/u.test(file) || owned.has(path)) continue;
|
|
273
|
+
if (check) throw new Error(`gen-shards: stale ${relative(root, path)} (run pnpm gen)`);
|
|
274
|
+
rmSync(path);
|
|
275
|
+
}
|
|
276
|
+
if (!check) retireDiscoveryBank(root);
|
|
277
|
+
writeTables(root, shardTables(root), check, initializeMissing);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function writeTables(root, outputs, check, initializeMissing) {
|
|
281
|
+
for (const [name, source] of Object.entries(outputs)) {
|
|
282
|
+
const out = resolve(root, name);
|
|
283
|
+
const exists = existsSync(out), same = exists && readFileSync(out, 'utf8') === source;
|
|
284
|
+
// A staged-tree export lacks these untracked tables. Only that caller initializes missing outputs;
|
|
285
|
+
// committed vocabulary above and any existing runtime table still have strict --check semantics.
|
|
286
|
+
const initialize = initializeMissing && !exists;
|
|
287
|
+
if (check && !same && !initialize) throw new Error(`gen-shards: stale ${name} (run pnpm gen)`);
|
|
288
|
+
if ((!check || initialize) && !same) { mkdirSync(dirname(out), { recursive: true }); writeFileSync(out, source); }
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** Full standalone generation and strict checking. */
|
|
293
|
+
export function genShards(root = resolve(import.meta.dirname, '..'), check = false, initializeMissing = false, shard = '') {
|
|
294
|
+
genShardInputs(root, check, initializeMissing, shard);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// C3: the client builds from a catalogue and its packs, so a tree with no shard source has nothing to generate.
|
|
298
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href && existsSync(resolve(import.meta.dirname, '../src/shards'))) {
|
|
299
|
+
try {
|
|
300
|
+
const shard = process.argv.find((arg) => arg.startsWith('--shard='))?.slice(8);
|
|
301
|
+
genShards(undefined, process.argv.includes('--check'), false, shard);
|
|
302
|
+
// Vite runs discovery before boot byte tables exist. Budget generation belongs to pnpm gen after those tables.
|
|
303
|
+
if (process.argv.includes('--check')) {
|
|
304
|
+
const root = resolve(import.meta.dirname, '..'), failures = manifestContract(root, manifestClosure(root), true);
|
|
305
|
+
if (failures.length > 0) throw new Error(`gen-shards: the manifest contract (AG10):\n ${failures.join('\n ')}`);
|
|
306
|
+
const { genBudgetDerivations } = await import('@wildshard/engine/scripts/gen-budget-derivations.mjs');
|
|
307
|
+
await genBudgetDerivations(undefined, true, shard);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
catch (error) { console.error(error instanceof Error ? error.message : String(error)); process.exitCode = 1; }
|
|
311
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type {FloorGridState} from '@wildshard/engine/scripts/frame-floor-grid.mjs';
|
|
2
|
+
|
|
3
|
+
export interface PlotGoldenView {
|
|
4
|
+
n:number;name:string;label:string;player:[number,number];eye:[number,number,number];look:[number,number,number];
|
|
5
|
+
hfov:62;aspect:'2:3';world:{eye:[number,number,number];look:[number,number,number];fov:number};inside:string|null;note?:string;
|
|
6
|
+
}
|
|
7
|
+
export interface PlotGoldens {schema:'golden-cameras/1';slug:string;instance:string;origin:{x:number;z:number};pitch:number;convention:string;views:PlotGoldenView[]}
|
|
8
|
+
export function parsePlotGoldens(input:unknown):PlotGoldens;
|
|
9
|
+
export function plotGoldenCamera(row:Pick<PlotGoldenView,'eye'|'look'|'hfov'>,origin:{x:number;z:number}):{eye:number[];look:number[];fov:number};
|
|
10
|
+
export function plotGoldenPlacement(plan:PlotGoldens,grid:Pick<FloorGridState,'pitch'|'cells'>):{
|
|
11
|
+
instance:string;origin:{x:number;z:number};pitch:number;sourceInstance:string;sourceOrigin:{x:number;z:number};
|
|
12
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
const finite = v.pipe(v.number(), v.finite());
|
|
4
|
+
const name = v.pipe(v.string(), v.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/u));
|
|
5
|
+
const point = v.tuple([finite, finite, finite]);
|
|
6
|
+
const world = v.strictObject({eye:point,look:point,fov:finite});
|
|
7
|
+
const view = v.strictObject({n:finite,name,label:v.string(),player:v.tuple([finite,finite]),eye:point,look:point,
|
|
8
|
+
hfov:v.literal(62),aspect:v.literal('2:3'),world,inside:v.nullable(name),note:v.optional(v.string())});
|
|
9
|
+
const schema = v.strictObject({schema:v.literal('golden-cameras/1'),slug:name,instance:name,
|
|
10
|
+
origin:v.strictObject({x:finite,z:finite}),pitch:finite,convention:v.string(),views:v.pipe(v.array(view),v.length(8))});
|
|
11
|
+
|
|
12
|
+
/** Keep the historical world coordinates as provenance and reject corrupt local/world pairs.
|
|
13
|
+
* @param {unknown} input */
|
|
14
|
+
export function parsePlotGoldens(input) {
|
|
15
|
+
const plan = v.parse(schema,input);
|
|
16
|
+
if (plan.pitch <= 500 || !plan.slug.startsWith('open-plot-') || new Set(plan.views.map(row=>row.name)).size !== 8)
|
|
17
|
+
throw new Error('Invalid golden plot identity');
|
|
18
|
+
for (const [index,row] of plan.views.entries()) {
|
|
19
|
+
const camera = plotGoldenCamera(row,plan.origin);
|
|
20
|
+
if (row.n !== index+1 || row.player.some(word=>Math.abs(word)>250) || !row.eye.some((word,i)=>word !== row.look[i])
|
|
21
|
+
|| Math.abs(camera.fov-row.world.fov)>1e-6
|
|
22
|
+
|| camera.eye.some((word,i)=>Math.abs(word-row.world.eye[i])>1e-6)
|
|
23
|
+
|| camera.look.some((word,i)=>Math.abs(word-row.world.look[i])>1e-6)) throw new Error('Golden camera provenance differs');
|
|
24
|
+
}
|
|
25
|
+
return plan;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @param {{eye:readonly number[],look:readonly number[],hfov:number}} row
|
|
29
|
+
* @param {{x:number,z:number}} origin */
|
|
30
|
+
export function plotGoldenCamera(row,origin) {
|
|
31
|
+
return {eye:[row.eye[0]+origin.x,row.eye[1],row.eye[2]+origin.z],
|
|
32
|
+
look:[row.look[0]+origin.x,row.look[1],row.look[2]+origin.z],
|
|
33
|
+
fov:2*Math.atan(Math.tan(row.hfov*Math.PI/360)/(2/3))*180/Math.PI};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Resolve by product identity, never the pre-G986 instance or world origin.
|
|
37
|
+
* @param {ReturnType<typeof parsePlotGoldens>} plan
|
|
38
|
+
* @param {Pick<import('@wildshard/engine/scripts/frame-floor-grid.mjs').FloorGridState,'pitch'|'cells'>} grid */
|
|
39
|
+
export function plotGoldenPlacement(plan,grid) {
|
|
40
|
+
const cells=grid.cells.filter(row=>row.slug===plan.slug), pitch=grid.pitch;
|
|
41
|
+
if (cells.length!==1 || pitch===undefined || !Number.isFinite(pitch) || pitch<=500) throw new Error('Golden plot needs one served cell and explicit pitch');
|
|
42
|
+
const cell=cells[0];
|
|
43
|
+
if (cell===undefined) throw new Error('Missing golden plot');
|
|
44
|
+
return {instance:cell.instance,origin:{x:cell.cell[0]*pitch,z:cell.cell[1]*pitch},pitch,
|
|
45
|
+
sourceInstance:plan.instance,sourceOrigin:plan.origin};
|
|
46
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { KEYCHAIN_ARGS } from './chromium-keychain.mjs';
|
|
3
|
+
import { debugSettings, harnessPins } from '@wildshard/engine/scripts/debug-settings.mjs';
|
|
4
|
+
// gpu-texmem.mjs — how much GPU memory each shard's textures take (E157, KTX2 / Basis GPU compression).
|
|
5
|
+
//
|
|
6
|
+
// Counts at the WebGL call, not from three's bookkeeping: an init script wraps texStorage2D/3D, texImage2D/3D,
|
|
7
|
+
// compressedTexImage2D/3D, generateMipmap, renderbufferStorage(Multisample) and deleteTexture / deleteRenderbuffer, and
|
|
8
|
+
// keeps, per live WebGLTexture, the bytes its levels hold (internal format × width × height × depth; RGB8 counted as 4
|
|
9
|
+
// bytes a texel, which is what the GPU stores; a compressed level is its byte length). A texture that a framebuffer
|
|
10
|
+
// ever attached is a render target and is summed apart (bloom, shadow maps, the composer: not what KTX2 changes).
|
|
11
|
+
// After the settle the page's scene is walked: every texture a material or ShaderMaterial uniform holds is matched to
|
|
12
|
+
// its WebGLTexture (renderer.properties) and labelled with the mesh that draws it, so the table says whose bytes they are.
|
|
13
|
+
//
|
|
14
|
+
// node scripts/gpu-texmem.mjs --url=http://localhost:4391 --chunk=pine-hollow --tier=phone [--tex=ktx2|img] [--tag=x]
|
|
15
|
+
// … --record record individual files through the unavailable-pack fallback and merge the
|
|
16
|
+
// files this boot loaded into scripts/bake-ktx2.list.json (bake-ktx2's list)
|
|
17
|
+
//
|
|
18
|
+
// Phone: 390×844 @3, iPhone UA, `touch=1&tier=phone`. Desktop: 1600×900 @1, `tier=desktop`. One headless Chromium on
|
|
19
|
+
// Metal, muted (`--mute-audio`, `mute=1`), closed at the end. Writes progress/texmem/<tag>-<chunk>-<tier>.json.
|
|
20
|
+
import { writeFileSync, mkdirSync, readFileSync } from 'node:fs';
|
|
21
|
+
import { resolve as resolvePath } from 'node:path';
|
|
22
|
+
import { ledger, report } from '@wildshard/sdk/scripts/texmem-probe.mjs';
|
|
23
|
+
|
|
24
|
+
const { chromium, devices } = await import("./browser-playwright.mjs");
|
|
25
|
+
const ROOT = resolvePath(new URL('..', import.meta.url).pathname);
|
|
26
|
+
const argv = process.argv.slice(2);
|
|
27
|
+
const flag = (name, d) => { const a = argv.find((x) => x.startsWith(`--${name}=`)); return a ? a.slice(name.length + 3) : d; };
|
|
28
|
+
const URL_BASE = flag('url', 'http://localhost:4391');
|
|
29
|
+
const CHUNK = flag('chunk', 'pine-hollow');
|
|
30
|
+
const TIER = flag('tier', 'phone');
|
|
31
|
+
const EXTRA = flag('query', '');
|
|
32
|
+
/** --tex=ktx2|img: the textures (E157) — a harness pin (`__wildshardHarness.textures`, G386), never a setting or URL switch;
|
|
33
|
+
* the background prefetch of the other shards (E158) is off either way, so it adds nothing to the ledger */
|
|
34
|
+
const TEX = flag('tex', '');
|
|
35
|
+
const TAG = flag('tag', 'latest');
|
|
36
|
+
const SETTLE = Number(flag('settle', '10')) * 1000;
|
|
37
|
+
const TOP = Number(flag('top', '25'));
|
|
38
|
+
/** --record: merge the texture / model URLs this boot fetched into scripts/bake-ktx2.list.json (what bake-ktx2 bakes) */
|
|
39
|
+
const RECORD = argv.includes('--record');
|
|
40
|
+
|
|
41
|
+
const sleep = (ms) => new Promise((resolve) => { setTimeout(resolve, ms); });
|
|
42
|
+
const browser = await chromium.launch({ args: [...KEYCHAIN_ARGS, '--mute-audio', '--use-angle=metal', '--ignore-gpu-blocklist', '--enable-precise-memory-info', '--js-flags=--expose-gc'] });
|
|
43
|
+
try {
|
|
44
|
+
const phone = TIER === 'phone';
|
|
45
|
+
const iphone = devices['iPhone 16 Pro'];
|
|
46
|
+
const ctx = await browser.newContext(phone
|
|
47
|
+
? { userAgent: iphone.userAgent, isMobile: true, hasTouch: true, deviceScaleFactor: 3, viewport: { width: 390, height: 844 } }
|
|
48
|
+
: { viewport: { width: 1600, height: 900 }, deviceScaleFactor: 1 });
|
|
49
|
+
await ctx.addInitScript(ledger);
|
|
50
|
+
await debugSettings(ctx, { prefetch: 'off' });
|
|
51
|
+
if (TEX !== '') await harnessPins(ctx, { textures: TEX });
|
|
52
|
+
// G221: CLI-only fetch adapter; no in-game option, saved state or network error.
|
|
53
|
+
// The engine's normal unavailable-part fallback fetches each original URL for the ledger.
|
|
54
|
+
if (RECORD) await ctx.addInitScript(() => {
|
|
55
|
+
const fetchNow = window.fetch.bind(window);
|
|
56
|
+
window.fetch = (input, init) => {
|
|
57
|
+
const url = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
58
|
+
return new URL(url, location.href).pathname.startsWith('/assets/packs/')
|
|
59
|
+
? Promise.resolve(new Response(null, { status: 503 })) : fetchNow(input, init);
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
const page = await ctx.newPage();
|
|
63
|
+
const errors = [];
|
|
64
|
+
page.on('pageerror', (e) => errors.push(e.message.slice(0, 200)));
|
|
65
|
+
page.on('console', (m) => { if (m.type() === 'error' || /ktx2|KTX2|basis/i.test(m.text())) errors.push(`[${m.type()}] ${m.text().slice(0, 200)}`); });
|
|
66
|
+
const q = [`chunk=${CHUNK}`, 'mute=1', 'skipintro=1', 'nolock=1', 'sw=0', `tier=${TIER}`, phone ? 'touch=1' : '', EXTRA].filter(Boolean).join('&');
|
|
67
|
+
const t0 = Date.now();
|
|
68
|
+
await page.goto(`${URL_BASE}/?${q}`, { waitUntil: 'domcontentloaded' });
|
|
69
|
+
await page.waitForFunction(() => Boolean(window.__wildshard?.world?.game), undefined, { timeout: 300000, polling: 500 });
|
|
70
|
+
const readyS = (Date.now() - t0) / 1000;
|
|
71
|
+
await sleep(SETTLE);
|
|
72
|
+
// the JS heap after a full collection: what the page holds, not the garbage the boot left
|
|
73
|
+
await page.evaluate(async () => { for (let i = 0; i < 3; i++) { window.gc?.(); await new Promise((resolve) => { setTimeout(resolve, 200); }); } });
|
|
74
|
+
const r = await page.evaluate(report, TOP);
|
|
75
|
+
const out = { tag: TAG, chunk: CHUNK, tier: TIER, tex: TEX, query: q, readyS, when: new Date().toISOString(), errors: errors.slice(0, 20), ...r };
|
|
76
|
+
mkdirSync(resolvePath(ROOT, 'progress/texmem'), { recursive: true });
|
|
77
|
+
const file = resolvePath(ROOT, `progress/texmem/${TAG}-${CHUNK}-${TIER}.json`);
|
|
78
|
+
writeFileSync(file, `${JSON.stringify(out, null, 1)}\n`);
|
|
79
|
+
console.log(`[texmem] ${CHUNK} ${TIER} tex=${TEX === '' ? '(default)' : TEX} ${EXTRA} · ready ${readyS.toFixed(0)} s`);
|
|
80
|
+
console.log(` textures ${r.textureMB} MB in ${r.textures} (compressed ${r.compressedMB} MB in ${r.compressedTextures}) · in scene ${r.inSceneMB} MB · render targets ${r.renderTargetMB} MB · renderbuffers ${r.renderbufferMB} MB · JS heap ${r.jsHeapMB} MB`);
|
|
81
|
+
console.log(` by format ${JSON.stringify(r.byFormat)}`);
|
|
82
|
+
for (const [k, v] of Object.entries(r.byClass).sort((a, b) => b[1].mb - a[1].mb).slice(0, 30)) console.log(` ${String(v.mb.toFixed(1)).padStart(7)} MB ${String(v.n).padStart(4)} ${k}`);
|
|
83
|
+
console.log(` compressed ext: ${r.compressedExtensions.join(' ')}`);
|
|
84
|
+
for (const x of r.top) console.log(` ${String(x.mb).padStart(6)} MB ${`${x.w}x${x.h}${x.d > 1 ? `x${x.d}` : ''}`.padEnd(14)} ${x.fmt.padEnd(12)} ${x.mips.padEnd(7)} ${String(x.src).slice(-40).padEnd(40)} ${x.where.slice(0, 90)}`);
|
|
85
|
+
if (errors.length > 0) console.log(` errors: ${errors.slice(0, 5).join(' / ')}`);
|
|
86
|
+
console.log(` → ${file}`);
|
|
87
|
+
if (RECORD) {
|
|
88
|
+
const listFile = resolvePath(ROOT, 'scripts/bake-ktx2.list.json');
|
|
89
|
+
const list = JSON.parse(readFileSync(listFile, 'utf8'));
|
|
90
|
+
const keep = (u) => /\.(glb|gltf|png|jpe?g|webp)$/.test(u) && !/^\/(?:assets|b\/[\w.-]+)\/[^/]+-[\w-]{8}\.\w+$/.test(u) && !u.includes('/hdri/') && !u.startsWith('/assets/gpu/');
|
|
91
|
+
const before = list[TIER].length;
|
|
92
|
+
list[TIER] = [...new Set([...list[TIER], ...r.fetched.filter(keep)])].sort((a, b) => a.localeCompare(b));
|
|
93
|
+
writeFileSync(listFile, `${JSON.stringify(list, null, 1)}\n`);
|
|
94
|
+
console.log(` recorded: ${list[TIER].length - before} new ${TIER} URLs → ${listFile}`);
|
|
95
|
+
}
|
|
96
|
+
} finally {
|
|
97
|
+
await browser.close();
|
|
98
|
+
}
|