@wildshard/shard-format 0.82.12 → 0.83.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.82.12",
3
+ "version": "0.83.0",
4
4
  "description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -114,6 +114,7 @@
114
114
  "./dayCycle": "./src/format/dayCycle.ts",
115
115
  "./dayLook": "./src/format/dayLook.ts",
116
116
  "./decisionBindings": "./src/format/decisionBindings.ts",
117
+ "./decisionFrameV2": "./src/format/decision-frame-v2.ts",
117
118
  "./decisionPublication": "./src/format/decisionPublication.ts",
118
119
  "./decisionScripts": "./src/format/decisionScripts.ts",
119
120
  "./declaredQuestPage": "./src/format/declaredQuestPage.ts",
@@ -40,7 +40,7 @@ const ENGINE_PINS =
40
40
  /** ZS3 (J507): the next releases, production's and staging's, as engine pins them. */
41
41
  const LIVE_PINS = `${ENGINE_PINS}/shardfiles.json,${ENGINE_PINS}/staging.json`
42
42
  /** The signed release and placement files api-server's prune reads, public: R2 layout RL10 moved them from
43
- * `packs.wildshard.io/releases/` to the root of `wildshard-releases` and removed the old keys. */
43
+ * the retired packs bucket's `releases/` to the root of `wildshard-releases` and removed the old keys. */
44
44
  const RELEASES = 'https://releases.wildshard.io'
45
45
 
46
46
  interface LiveSet {
@@ -189,7 +189,7 @@ function admitAfterFiles(state: AssetAdmission, assets: ReadonlyMap<string, Uint
189
189
  if (s.sim.scripts.some((id) => !id.startsWith('commons:') && files.get(id)?.kind !== 'wasm')) throw new Error('script reference is not an admitted Wasm file');
190
190
  for (const t of s.tiles) {
191
191
  const roots = closure(t.files);
192
- // Meta J551 (Jake, 2026-11-30): a texture shared by several tiles loads once, with the library, so a coarse tile may
192
+ // Meta ZONE-SIZE-LIMITS D3 (Jake, 2026-11-30): a texture shared by several tiles loads once, with the library, so a coarse tile may
193
193
  // name a library image; a library model stays fine-only
194
194
  if (t.lod === 1 && coarseLibraryModel(roots, library, (r) => files.get(r)?.kind)) throw new Error('coarse dependency on library');
195
195
  const cost = sum(t.files, library);
@@ -1,4 +1,4 @@
1
- /** The file kinds a coarse tile may share with the library (meta J551): images, not models. */
1
+ /** The file kinds a coarse tile may share with the library (meta ZONE-SIZE-LIMITS D3): images, not models. */
2
2
  const LIBRARY_IMAGE_KINDS: ReadonlySet<string> = new Set(['image', 'ktx2'])
3
3
 
4
4
  /** True when a coarse tile's closure names a library file that is not an image (a model, a script): refused. */
@@ -44,7 +44,7 @@ export const MEMORY_GATES: Readonly<{ reportOnly: boolean; explorerMB: number; l
44
44
  });
45
45
  /** Provisional phone content caps; shadow draws count in each draw cap. */
46
46
  export const CONTENT_CAPS: { readonly l0: { readonly size: 62.5; readonly resident: number; readonly compressed: number; readonly triangles: 40000; readonly draws: 8; }; readonly l1: { readonly size: 125; readonly resident: number; readonly compressed: number; readonly triangles: 10000; readonly draws: 2; }; readonly far: { readonly resident: number; readonly compressed: 1000000; readonly triangles: 8000; readonly draws: 1; }; readonly library: { readonly resident: number; readonly compressed: number; }; readonly sim: { readonly resident: number; readonly compressed: number; }; readonly engineBase: number; readonly playing: number; readonly loading: number; readonly l0Count: 40; readonly l1Count: 32; readonly farCount: 9; readonly simCount: 4; readonly libraryCount: 4; readonly overlap: number; readonly residentFactor: 1.11; readonly nearRadius: 150; readonly shadowRadius: 80; readonly pitch: 562.5; } = {
47
- // Meta J551 (Jake, 2026-11-30): the far target 2 MB and the library 28 MB; J557 (Jake, 2026-11-30): the fine-tile
47
+ // Meta ZONE-SIZE-LIMITS D3 (Jake, 2026-11-30): the far target 2 MB and the library 28 MB; meta ZONE-SIZE-LIMITS D5 (Jake, 2026-11-30): the fine-tile
48
48
  // download line is 720 kB and the coarse 240 kB (Mossgate's 649 kB and 211 kB tiles plus 10%, J439)
49
49
  l0: { size: 62.5, resident: 4 * CONTENT_MB, compressed: 0.72 * CONTENT_MB, triangles: 40_000, draws: 8 },
50
50
  l1: { size: 125, resident: 2 * CONTENT_MB, compressed: 0.24 * CONTENT_MB, triangles: 10_000, draws: 2 },
@@ -0,0 +1,59 @@
1
+ import { SCRIPT_V2_REVISIONS } from './scriptAdmissionV2.ts'
2
+ import { layoutV2 } from './scriptWireV2.ts'
3
+
4
+ import type { DecisionScriptRow } from './decisionScripts.ts'
5
+ import type { ScriptContract } from './scriptContract.ts'
6
+ import type { V2Layout } from './scriptWireV2.ts'
7
+
8
+ /** WASM-HOST H13: an event decision row's ABI v2 module (abi '2.0') runs one binding per entry over this fixed frame,
9
+ * bank kind to row capacity: bindings 1, state and candidate 16, params 32, events 16, commands 32, read misses 32,
10
+ * replies 128 with 512 list values, one RNG stream. Its I/O base is 0, so its I/O size follows from its pages alone. */
11
+ const CAPACITY: Readonly<Record<number, number>> = {
12
+ 1: 1,
13
+ 2: 16,
14
+ 3: 16,
15
+ 4: 32,
16
+ 9: 16,
17
+ 10: 32,
18
+ 11: 32,
19
+ 12: 128,
20
+ 13: 512,
21
+ 21: 1,
22
+ 22: 1,
23
+ }
24
+ const capacities = new Map<number, number>()
25
+ for (const [kind, capacity] of Object.entries(CAPACITY)) {
26
+ capacities.set(Number(kind), capacity)
27
+ }
28
+ const DECISION_V2_CAPACITIES: ReadonlyMap<number, number> = capacities
29
+ /** List replies are keyed `DECISION_V2_LIST_KEY + list op`, apart from read ops. */
30
+ const DECISION_V2_LIST_KEY = 1000
31
+ const DECISION_V2_IO = 0
32
+ /** The I/O frame a decision module of `pages` pages admits under. */
33
+ function decisionLayoutV2(pages: number): V2Layout {
34
+ return layoutV2(DECISION_V2_IO, pages, DECISION_V2_CAPACITIES)
35
+ }
36
+ /** A decision row's byte contract: ABI 1 by its pages, or (abi '2.0') the ABI 2 sim lane over its fixed decision frame. */
37
+ function decisionContract(
38
+ row: Readonly<Pick<DecisionScriptRow, 'abi' | 'pages'>>,
39
+ ): Extract<ScriptContract, { pages: number }> {
40
+ if (row.abi === '1.0') {
41
+ return { abi: 1, pages: row.pages }
42
+ }
43
+ return {
44
+ abi: 2,
45
+ lane: 'sim',
46
+ pages: row.pages,
47
+ ioBytes: decisionLayoutV2(row.pages).bytes,
48
+ compilerRevision: SCRIPT_V2_REVISIONS.compiler,
49
+ admissionRevision: SCRIPT_V2_REVISIONS.admission,
50
+ }
51
+ }
52
+
53
+ export {
54
+ DECISION_V2_CAPACITIES,
55
+ DECISION_V2_IO,
56
+ DECISION_V2_LIST_KEY,
57
+ decisionContract,
58
+ decisionLayoutV2,
59
+ }
@@ -1,4 +1,5 @@
1
1
  import * as v from 'valibot';
2
+ import { decisionContract } from './decision-frame-v2.ts';
2
3
  import { isJsonData } from './json.ts';
3
4
  import { SCRIPT_V1_COMMANDS, SCRIPT_V1_EVENTS, SCRIPT_V1_LISTS, SCRIPT_V1_READS } from './scriptAbiV1.ts';
4
5
  import { SCRIPT_LIMITS } from './scriptLimits.ts';
@@ -24,7 +25,8 @@ export type ScriptV1ReferenceKind = typeof SCRIPT_V1_REFERENCE_KINDS[number];
24
25
  const rowEntries = {
25
26
  // SERVER-PARITY SS7: `sim` is server-owned gameplay; `view` runs on the page only and writes no gameplay (row rules).
26
27
  // Per-frame view is still the v2 view lane's (view/modules, client view.program).
27
- id, abi: v.literal('1.0'), side: v.picklist(SCRIPT_V1_SIDES),
28
+ // WASM-HOST H13: '2.0' is the same row compiled as an ABI v2 sim module (scriptWireV2 decisionLayoutV2).
29
+ id, abi: v.picklist(['1.0', '2.0']), side: v.picklist(SCRIPT_V1_SIDES),
28
30
  module: v.pipe(v.string(), v.regex(/^blobs\/wasm\/[a-f0-9]{64}\.wasm$/u)),
29
31
  source: v.pipe(v.string(), v.maxLength(256), v.regex(/^behaviour\/(?:[A-Za-z0-9_-][A-Za-z0-9_.-]*\/)*[A-Za-z0-9_-][A-Za-z0-9_.-]*\.as$/u),
30
32
  v.check(value => !value.split('/').includes('generated'), 'authored script source, not generated glue')),
@@ -78,6 +80,7 @@ export function decisionScriptRowRules(script: DecisionScriptRow): string[] {
78
80
  if (script.tags !== undefined && !validNames(Object.keys(script.tags))) { errors.push('unique nonreserved generated binding names'); }
79
81
  if (script.on.some(name => SCRIPT_V1_EVENTS[name] >= 30) || script.commands.some(name => SCRIPT_V1_COMMANDS[name] >= 100)) errors.push('simulation script uses only simulation ops');
80
82
  if (script.side === 'view' && !script.commands.every(isViewCommand)) { errors.push(VIEW_WRITES_GAMEPLAY); }
83
+ if (script.abi === '2.0' && script.side !== 'sim') { errors.push('an ABI 2 decision row is a sim module'); }
81
84
  for (const names of [...SCRIPT_V1_REFERENCE_KINDS.map(kind => Object.keys(script[kind] ?? {})), script.timers, script.state.map(slot => slot.name), Object.keys(script.params)]) {
82
85
  if (!validNames(names)) errors.push('unique nonreserved generated binding names');
83
86
  }
@@ -173,7 +176,7 @@ export function decisionScriptRules(scripts: readonly DecisionScriptRow[], refer
173
176
  for (const script of scripts) {
174
177
  errors.push(...decisionScriptRowRules(script));
175
178
  const module = references.modules.get(script.module);
176
- if (module?.abi !== 1 || module.pages !== script.pages) errors.push('script module has matching admitted ABI and fixed pages');
179
+ if (module?.abi !== decisionContract(script).abi || module.pages !== script.pages) errors.push('script module has matching admitted ABI and fixed pages');
177
180
  for (const kind of SCRIPT_V1_REFERENCE_KINDS) for (const value of Object.values(script[kind] ?? {})) {
178
181
  if (references.ids[kind]?.has(value) !== true) errors.push(`script ${kind} reference resolves in its platform section`);
179
182
  }
@@ -204,7 +207,7 @@ export type BorrowedDecision = v.InferOutput<typeof BorrowedDecisionSchema>;
204
207
  /** Admitted data contracts, independent of validator implementation metadata. */
205
208
  interface DecisionScriptRowInputFields {
206
209
  id: string;
207
- abi: '1.0';
210
+ abi: '1.0' | '2.0';
208
211
  side: 'sim' | 'view';
209
212
  module: string;
210
213
  source: string;
@@ -262,7 +265,7 @@ interface DecisionScriptRowInputFields {
262
265
  export type DecisionScriptRowInput = { [Key in keyof DecisionScriptRowInputFields]: DecisionScriptRowInputFields[Key] };
263
266
  interface DecisionScriptRowFields {
264
267
  id: string;
265
- abi: '1.0';
268
+ abi: '1.0' | '2.0';
266
269
  side: 'sim' | 'view';
267
270
  module: string;
268
271
  source: string;
@@ -4,6 +4,7 @@ import * as v from 'valibot';
4
4
  import { admitScript, type ScriptAdmission } from './scriptAdmission.ts';
5
5
  import { admitScriptV2, SCRIPT_V2_REVISIONS, type ScriptAdmissionV2 } from './scriptAdmissionV2.ts';
6
6
  import { DecisionScriptsSchema, parseDecisionScripts, type DecisionScripts } from './decisionScripts.ts';
7
+ import { decisionContract } from './decision-frame-v2.ts';
7
8
 
8
9
  /** Fixed ABI2 byte admission metadata, independent of execution or source sniffing. */
9
10
  export const ScriptV2ContractSchema: v.StrictObjectSchema<{ readonly abi: v.GenericSchema<ScriptV2ContractRowsInput['abi'], ScriptV2ContractRows['abi']>; readonly lane: v.GenericSchema<ScriptV2ContractRowsInput['lane'], ScriptV2ContractRows['lane']>; readonly pages: v.GenericSchema<ScriptV2ContractRowsInput['pages'], ScriptV2ContractRows['pages']>; readonly ioBytes: v.GenericSchema<ScriptV2ContractRowsInput['ioBytes'], ScriptV2ContractRows['ioBytes']>; readonly compilerRevision: v.GenericSchema<ScriptV2ContractRowsInput['compilerRevision'], ScriptV2ContractRows['compilerRevision']>; readonly admissionRevision: v.GenericSchema<ScriptV2ContractRowsInput['admissionRevision'], ScriptV2ContractRows['admissionRevision']>; }, undefined> = v.strictObject({ abi: v.literal(2), lane: v.picklist(['sim', 'project', 'view']), pages: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(4)),
@@ -69,7 +70,7 @@ export function decisionModuleContracts(input: ScriptAdmissionRows, files: reado
69
70
  const file = files.find(value => value.kind === 'wasm' && `blobs/wasm/${value.hash}.wasm` === row.module && (value.path === undefined || value.path === row.module));
70
71
  if (file === undefined) throw new Error('Decision script module is not an exact declared Wasm path');
71
72
  const contract = row.abi === 2 ? v.parse(ScriptV2ContractSchema, { abi: row.abi, lane: row.lane, pages: row.pages, ioBytes: row.ioBytes,
72
- compilerRevision: row.compilerRevision, admissionRevision: row.admissionRevision }) : { abi: 1 as const, pages: row.pages };
73
+ compilerRevision: row.compilerRevision, admissionRevision: row.admissionRevision }) : decisionContract(row);
73
74
  const old = contracts.get(file.hash);
74
75
  if (old !== undefined && (JSON.stringify(old) !== JSON.stringify(contract) || sides.get(file.hash) !== row.side)) throw new Error('Conflicting decision module contracts');
75
76
  contracts.set(file.hash, contract); sides.set(file.hash, row.side);
@@ -95,7 +96,7 @@ export function decisionMemoryPreparationPages(sections?: ReadonlyMap<string, un
95
96
  const decisions = new Set(decisionScriptsFromSections(sections).map(row => row.id));
96
97
  const modules = new Map<string, number>();
97
98
  for (const row of inventory) {
98
- if (row.abi === 2 || !decisions.has(row.id)) continue;
99
+ if (row.abi === 2 || row.abi === '2.0' || !decisions.has(row.id)) continue;
99
100
  const previous = modules.get(row.module);
100
101
  if (previous !== undefined && previous !== row.pages) throw new Error('Conflicting decision memory pages');
101
102
  modules.set(row.module, row.pages);
@@ -33,7 +33,7 @@ const vec3 = v.tuple([ShardFiniteSchema, ShardFiniteSchema, ShardFiniteSchema]);
33
33
  export const CellBoundsSchema: v.GenericSchema<CellBoundsInput, CellBounds> = v.pipe(v.strictObject({ min: vec3, max: vec3 }), v.check((b) => b.min.every((n, i) => n <= (b.max[i] ?? -Infinity)), 'ordered bounds'), v.check((b) => b.min[0] >= -CHUNK_HALF && b.max[0] <= CHUNK_HALF && b.min[2] >= -CHUNK_HALF && b.max[2] <= CHUNK_HALF && b.min[1] >= -CELL_BELOW && b.max[1] <= CELL_ABOVE, 'cell bounds'));
34
34
  const drawBounds = CellBoundsSchema;
35
35
  const costs = { compressed: ShardNaturalSchema, decoded: ShardNaturalSchema, gpu: ShardNaturalSchema, triangles: ShardNaturalSchema, draws: ShardNaturalSchema };
36
- /** Meta ZONE-SIZE-LIMITS ZL29 (J551): a fine tile's draws the engine merges for the view, one per (key, 250 m block) across
36
+ /** Meta ZONE-SIZE-LIMITS ZL29 (D3): a fine tile's draws the engine merges for the view, one per (key, 250 m block) across
37
37
  * resident tiles: their keys, the tile draws they account for and the shadow draws the tile keeps for them. */
38
38
  const merged = v.strictObject({ keys: ShardNamesSchema, draws: ShardNaturalSchema, shadows: ShardNaturalSchema, vertices: v.exactOptional(v.array(ShardNaturalSchema)) });
39
39
  const tile: v.GenericSchema<ShardTileRowsInput, ShardTileRows> = v.strictObject({ lod: v.picklist([0, 1]), x: ShardNaturalSchema, z: ShardNaturalSchema, bounds: CellBoundsSchema, drawBounds: v.exactOptional(drawBounds), merged: v.exactOptional(merged), geometricError: v.pipe(ShardFiniteSchema, v.minValue(0)), files: ShardReferencesSchema, ...costs });
@@ -1,6 +1,6 @@
1
1
  import { CONTENT_CAPS } from './contentBounds.ts'
2
2
 
3
- // Meta J557 (Jake, 2026-11-30): Mossgate's worst view count (287) plus 10%
3
+ // Meta ZONE-SIZE-LIMITS D5 (Jake, 2026-11-30): Mossgate's worst view count (287) plus 10%
4
4
  const PHONE_VIEW = 320
5
5
  const DESKTOP_VIEW = 400
6
6
  const FINE = 0