@wildshard/shard-format 0.12.0 → 0.13.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.12.0",
3
+ "version": "0.13.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": {
@@ -407,12 +407,12 @@
407
407
  "packageManager": "pnpm@10.34.9",
408
408
  "scripts": {
409
409
  "pnpm:devPreinstall": "git rev-parse --is-inside-work-tree >/dev/null 2>&1 && git config core.hooksPath .githooks || true",
410
- "typecheck": "tsc -p kit/tsconfig.json && tsc -p src/format/tsconfig.json && tsc -p src/format/tsconfig.lib.json",
411
- "lint": "node kit/scripts/lint.mjs --type-aware --deny-warnings --no-error-on-unmatched-pattern --ignore-pattern '.githooks/**' --ignore-pattern '.agents/**' --ignore-pattern 'scripts/agent-parity.mjs' --ignore-pattern 'scripts/agent-sync.mjs' --ignore-pattern 'scripts/scratch-dir*' --ignore-pattern 'scripts/scratch-sweep*' --ignore-pattern 'scripts/lane-live*' --ignore-pattern 'scripts/leftovers-report*' --ignore-pattern 'scripts/keep-copy*' --ignore-pattern 'scripts/disk-audit*' --ignore-pattern 'test/tooling/disk-land.test.mjs' --ignore-pattern 'test/tooling/land-fixture.mjs' --ignore-pattern 'test/tooling/owned-scratch.mjs' --ignore-pattern 'test/tooling/lane-live.test.mjs' --ignore-pattern 'test/tooling/keep-copy.test.mjs' --ignore-pattern 'test/tooling/leftovers-report.test.mjs' --ignore-pattern 'test/tooling/reap-report.test.mjs' --ignore-pattern 'tmp/**' --ignore-pattern 'src/format/**' --ignore-pattern 'scripts/chromium-keychain*' --ignore-pattern 'scripts/worktree-ignore*' --ignore-pattern 'scripts/land*' --ignore-pattern 'scripts/worktree.mjs' --ignore-pattern 'scripts/worktree-reap.mjs' --ignore-pattern 'scripts/pid-lock*' --ignore-pattern 'scripts/apfs-clone.mjs' --ignore-pattern 'scripts/assert-store-layout.mjs' --ignore-pattern 'test/tooling/worktree-guard.test.mjs' --ignore-pattern 'scripts/vite-tmp*' --ignore-pattern 'vitest.config.ts' --ignore-pattern 'test/tooling/chrome-keychain.test.mjs' --ignore-pattern 'packages/wire/frozen/**' --ignore-pattern 'packages/wire/lib/**'",
410
+ "typecheck": "npr tsc -p kit/tsconfig.json && npr tsc -p src/format/tsconfig.json && npr tsc -p src/format/tsconfig.lib.json",
411
+ "lint": "node kit/scripts/lint.mjs --type-aware --deny-warnings --no-error-on-unmatched-pattern --ignore-pattern '.githooks/**' --ignore-pattern '.agents/**' --ignore-pattern 'scripts/agent-parity.mjs' --ignore-pattern 'scripts/agent-sync.mjs' --ignore-pattern 'scripts/scratch-dir*' --ignore-pattern 'scripts/scratch-sweep*' --ignore-pattern 'scripts/lane-live*' --ignore-pattern 'scripts/leftovers-report*' --ignore-pattern 'scripts/keep-copy*' --ignore-pattern 'scripts/disk-audit*' --ignore-pattern 'test/tooling/disk-land.test.mjs' --ignore-pattern 'test/tooling/land-fixture.mjs' --ignore-pattern 'test/tooling/owned-scratch.mjs' --ignore-pattern 'test/tooling/lane-live.test.mjs' --ignore-pattern 'test/tooling/keep-copy.test.mjs' --ignore-pattern 'test/tooling/leftovers-report.test.mjs' --ignore-pattern 'test/tooling/reap-report.test.mjs' --ignore-pattern 'tmp/**' --ignore-pattern 'src/format/**' --ignore-pattern 'scripts/chromium-keychain*' --ignore-pattern 'scripts/worktree-ignore*' --ignore-pattern 'scripts/land*' --ignore-pattern 'scripts/main-push*' --ignore-pattern 'scripts/worktree.mjs' --ignore-pattern 'scripts/worktree-reap.mjs' --ignore-pattern 'scripts/pid-lock*' --ignore-pattern 'scripts/apfs-clone.mjs' --ignore-pattern 'scripts/assert-store-layout.mjs' --ignore-pattern 'test/tooling/worktree-guard.test.mjs' --ignore-pattern 'scripts/vite-tmp*' --ignore-pattern 'vitest.config.ts' --ignore-pattern 'test/tooling/chrome-keychain.test.mjs' --ignore-pattern 'packages/wire/frozen/**' --ignore-pattern 'packages/wire/lib/**'",
412
412
  "lint:fix": "node kit/scripts/lint.mjs --type-aware --fix --ignore-pattern '.githooks/**' --ignore-pattern '.agents/**' --ignore-pattern 'scripts/agent-parity.mjs' --ignore-pattern 'scripts/agent-sync.mjs' --ignore-pattern 'scripts/scratch-dir*' --ignore-pattern 'scripts/scratch-sweep*' --ignore-pattern 'scripts/lane-live*' --ignore-pattern 'scripts/leftovers-report*' --ignore-pattern 'scripts/keep-copy*' --ignore-pattern 'scripts/disk-audit*' --ignore-pattern 'test/tooling/disk-land.test.mjs' --ignore-pattern 'test/tooling/land-fixture.mjs' --ignore-pattern 'test/tooling/owned-scratch.mjs' --ignore-pattern 'test/tooling/lane-live.test.mjs' --ignore-pattern 'test/tooling/keep-copy.test.mjs' --ignore-pattern 'test/tooling/leftovers-report.test.mjs' --ignore-pattern 'test/tooling/reap-report.test.mjs' --ignore-pattern 'tmp/**' --ignore-pattern 'src/format/**'",
413
413
  "lint:format": "node src/tools/format-ratchet.ts",
414
- "format": "oxfmt -c kit/.oxfmtrc.json kit src '!src/format/**' '!src/test/fixtures/**'",
415
- "format:check": "oxfmt -c kit/.oxfmtrc.json --check kit src '!src/format/**' '!src/test/fixtures/**'",
414
+ "format": "npr oxfmt -c kit/.oxfmtrc.json kit src '!src/format/**' '!src/test/fixtures/**'",
415
+ "format:check": "npr oxfmt -c kit/.oxfmtrc.json --check kit src '!src/format/**' '!src/test/fixtures/**'",
416
416
  "test": "node --test 'src/!(format|ci)/**/*.test.ts'",
417
417
  "test:ci": "node --test 'src/ci/**/*.test.ts'",
418
418
  "test:format": "vitest run src/format --testTimeout=30000 --maxWorkers=2",
@@ -424,10 +424,11 @@
424
424
  "agents:sync": "node scripts/agent-sync.mjs",
425
425
  "md:wrap": "node kit/scripts/md-wrap.mjs",
426
426
  "test:hooks": "node --test '.githooks/*.test.mjs'",
427
- "check": "pnpm typecheck && pnpm lint && pnpm lint:format && pnpm format:check && pnpm test && pnpm test:format && pnpm check:asks && pnpm check:agents && pnpm check:agent-sync && pnpm test:agent-hooks && pnpm check:parity && node --check scripts/chromium-keychain-check.mjs && node --test test/tooling/chrome-keychain.test.mjs test/tooling/disk-land.test.mjs test/tooling/lane-live.test.mjs test/tooling/keep-copy.test.mjs test/tooling/leftovers-report.test.mjs test/tooling/reap-report.test.mjs && pnpm check:wire",
427
+ "check": "pnpm check:bin-pins && pnpm typecheck && pnpm lint && pnpm lint:format && pnpm format:check && pnpm test && pnpm test:format && pnpm check:asks && pnpm check:agents && pnpm check:agent-sync && pnpm test:agent-hooks && pnpm check:parity && node --check scripts/chromium-keychain-check.mjs && node --test test/tooling/chrome-keychain.test.mjs test/tooling/disk-land.test.mjs test/tooling/lane-live.test.mjs test/tooling/keep-copy.test.mjs test/tooling/leftovers-report.test.mjs test/tooling/reap-report.test.mjs && pnpm check:wire",
428
428
  "check:wire": "pnpm --dir packages/wire check && pnpm --dir packages/wire test && pnpm check:wire-proofs",
429
429
  "check:wire-proofs": "node --test src/scripts/wire/recordings-proof.mjs src/scripts/wire/graph-proof.mjs src/scripts/wire/prepared-frame-proof.mjs",
430
- "bench": "pnpm --dir packages/wire bench"
430
+ "bench": "pnpm --dir packages/wire bench",
431
+ "check:bin-pins": "node kit/scripts/bin-pins.mjs"
431
432
  },
432
433
  "dependencies": {
433
434
  "meshoptimizer": "1.2.0",
@@ -438,13 +439,11 @@
438
439
  "@typescript/typescript6": "6.0.2",
439
440
  "binaryen": "132.0.0",
440
441
  "fflate": "0.8.3",
441
- "oxfmt": "0.74.0",
442
442
  "oxlint": "1.89.0",
443
- "oxlint-tsgolint": "7.0.2004",
444
443
  "playwright": "1.64.1",
445
- "typescript": "7.0.2",
446
444
  "vite": "8.3.0",
447
- "vitest": "5.0.1"
445
+ "vitest": "5.0.1",
446
+ "npm-bin-deps": "2.1.0"
448
447
  },
449
448
  "pnpm": {
450
449
  "ignoredOptionalDependencies": [
@@ -529,5 +528,11 @@
529
528
  "@typescript/typescript-win32-arm64",
530
529
  "@typescript/typescript-win32-x64"
531
530
  ]
532
- }
531
+ },
532
+ "binDependencies": {
533
+ "typescript": "7.0.2",
534
+ "oxfmt": "0.74.0",
535
+ "oxlint-tsgolint": "7.0.2004"
536
+ },
537
+ "binDependenciesInstaller": "npm"
533
538
  }
@@ -85,10 +85,10 @@ interface AssetAdmission {
85
85
  }
86
86
 
87
87
  /** The checks before any byte is read: preflight, schema, decision modules, the graph and declared costs. */
88
- // oxlint-disable-next-line eslint/max-statements, typescript/prefer-readonly-parameter-types -- validateShardfileAssets' opening steps, moved whole (AC6a2)
89
- function assetAdmission(input: unknown, memory: MemoryAdmission | undefined, scripts: ScriptAdmissionRows): AssetAdmission {
88
+ // oxlint-disable-next-line eslint/max-params, eslint/max-statements, typescript/prefer-readonly-parameter-types -- the existing admission state also receives its checked section context
89
+ function assetAdmission(input: unknown, memory: MemoryAdmission | undefined, scripts: ScriptAdmissionRows, sections?: ReadonlyMap<string, unknown>): AssetAdmission {
90
90
  preflightShardfile(input);
91
- const s = parseShardfile(input), files = new Map(s.files.map((f) => [f.hash, f]));
91
+ const s = parseShardfile(input, sections), files = new Map(s.files.map((f) => [f.hash, f]));
92
92
  const contracts = decisionModuleContracts(scripts, s.files);
93
93
  const legacyModules = new Set([...s.sim.scripts, ...s.clientScripts.bindings.map(row => row.module), ...s.movers.filter(row => row.execution !== 'native').map(row => row.module)]);
94
94
  if ([...contracts.keys()].some(hash => legacyModules.has(hash))) throw new Error('Decision module cannot also use a legacy script host');
@@ -266,8 +266,8 @@ function admitAfterFiles(state: AssetAdmission, assets: ReadonlyMap<string, Uint
266
266
  }
267
267
 
268
268
  /** Admit exact bytes, graph closure, script growth and worst-location residency before a runtime is allocated. */
269
- function validateShardfileAssets(input: unknown, assets: ReadonlyMap<string, Uint8Array>, contentHash: (bytes: Uint8Array) => string, memory?: MemoryAdmission, textures?: TextureTranscodeSupport, scripts: ScriptAdmissionRows = []): Shardfile {
270
- const state = assetAdmission(input, memory, scripts);
269
+ function validateShardfileAssets(input: unknown, assets: ReadonlyMap<string, Uint8Array>, contentHash: (bytes: Uint8Array) => string, memory?: MemoryAdmission, textures?: TextureTranscodeSupport, scripts: ScriptAdmissionRows = [], sections?: ReadonlyMap<string, unknown>): Shardfile {
270
+ const state = assetAdmission(input, memory, scripts, sections);
271
271
  admitCommonsBytes(state, assets, contentHash);
272
272
  for (const file of state.shard.files) {
273
273
  admitFileBytes(state, file, assets.get(file.hash), assets, contentHash);
@@ -148,7 +148,7 @@ export function assembleOutputFields(index: OutputIndex, sections: ReadonlyMap<s
148
148
  }
149
149
  /** The default untrusted reader always checks sections and the full host schema. */
150
150
  export function assembleOutputShardfile(input: unknown, sections: ReadonlyMap<string, unknown>): Shardfile {
151
- const source = parseShardfile(assembleOutputFields(parseOutputIndex(input), sections));
151
+ const source = parseShardfile(assembleOutputFields(parseOutputIndex(input), sections), sections);
152
152
  const errors = clientOwnershipRules(source, sections); if (errors.length > 0) throw new Error(errors.join('; '));
153
153
  return source;
154
154
  }
@@ -1,3 +1,4 @@
1
+ import { readSpeciesPrograms } from './speciesPrograms.ts';
1
2
  import type { StrikeDebrisPolicy } from './strike-debris.ts';
2
3
  import { strikeDebrisCatalogueRules } from './strike-debris.ts';
3
4
  import { harvestSpeciesRules } from './harvest-rows.ts';
@@ -210,7 +211,7 @@ export interface Shardfile {
210
211
  function sceneOf(row: Readonly<{ scene: string }>): string { return row.scene; }
211
212
  /** A hook's name. */
212
213
  function idOf(row: Readonly<{ id: string }>): string { return row.id; }
213
- export function shardfileRules(s: Shardfile): string[] {
214
+ export function shardfileRules(s: Shardfile, sections?: ReadonlyMap<string, unknown>): string[] {
214
215
  const errors: string[] = [];
215
216
  const pageOwner = hasDeclaredClientPage(s);
216
217
  errors.push(...questNpcBindingRules(s.questNpcs ?? [], s.quests.flags, pageOwner || s.runtime?.binds?.includes('quests') === true));
@@ -309,7 +310,10 @@ export function shardfileRules(s: Shardfile): string[] {
309
310
  if (moves.passes !== undefined) { debrisStrikes.push(moves.passes.left, moves.passes.right); }
310
311
  }
311
312
  }
312
- errors.push(...strikeDebrisCatalogueRules({ strikes: debrisStrikes, species: s.rows.species }));
313
+ const metadata = sections?.get('actors/species-programs');
314
+ const roster = metadata === undefined ? undefined : readSpeciesPrograms(metadata);
315
+ const targets = [...s.rows.species, ...roster?.page ?? [], ...roster?.native ?? [], ...roster?.program?.species ?? []];
316
+ errors.push(...strikeDebrisCatalogueRules({ strikes: debrisStrikes, species: targets }));
313
317
  const harvestItems = new Set((s.items.catalogue ?? []).map((row: Readonly<{ id: string }>): string => row.id));
314
318
  errors.push(...harvestSpeciesRules(s.rows.species, harvestItems));
315
319
  if (s.migrations.some(step => step.equipmentSlots?.some(rename => !s.items.rows.some(row => row.kind === 'weapon' && row.slot === rename.to)))) errors.push('migration equipment slots resolve declared weapons');
@@ -382,7 +386,7 @@ export function shardfileRules(s: Shardfile): string[] {
382
386
  }
383
387
  /** Strict schema for the public SDK format; rejects unknown fields and invalid references.
384
388
  * Keep the unknown-input/named-output boundary independent of the nested validator implementation. */
385
- export const ShardfileSchema: v.GenericSchema<unknown, Shardfile> = v.pipe(v.unknown(), v.rawCheck(({ dataset, addIssue }) => {
389
+ function shardfileSchema(sections?: ReadonlyMap<string, unknown>): v.GenericSchema<unknown, Shardfile> { return v.pipe(v.unknown(), v.rawCheck(({ dataset, addIssue }) => {
386
390
  const input = dataset.value;
387
391
  try { preflightShardfile(input); } catch (error) {
388
392
  const nonData = error instanceof Error && /(?:JSON data|accessors)/u.test(error.message);
@@ -397,9 +401,14 @@ export const ShardfileSchema: v.GenericSchema<unknown, Shardfile> = v.pipe(v.unk
397
401
  }
398
402
  }), rawSchema,
399
403
  v.rawCheck(({ dataset, addIssue }) => { if (dataset.typed) { try { preflightAssetGraph(dataset.value); } catch (error) { addIssue({ message: error instanceof Error ? error.message : 'shardfile asset graph admission' }); } } }),
400
- v.check((s) => entrywayRules(s).length === 0, 'illegal shard: entryway openings must meet road height y=0'), v.check((s) => shardfileRules(s).length === 0, 'shardfile semantic rules'));
401
- /** Parse untrusted JSON as a validated shardfile, or throw a Valibot error. */
402
- function parseShardfile(input: unknown): Shardfile { return v.parse(ShardfileSchema, input); }
404
+ v.check((s) => entrywayRules(s).length === 0, 'illegal shard: entryway openings must meet road height y=0'), v.check((s) => shardfileRules(s, sections).length === 0, 'shardfile semantic rules')); }
405
+ export const ShardfileSchema: v.GenericSchema<unknown, Shardfile> = shardfileSchema();
406
+ /** Parse JSON through every shard rule. Optional section payloads extend item target
407
+ * references only through the defining species-program contract, never an id allowlist.
408
+ * Product readers must verify section inventories, hashes and sizes before calling. */
409
+ function parseShardfile(input: unknown, sections?: ReadonlyMap<string, unknown>): Shardfile {
410
+ return v.parse(sections === undefined ? ShardfileSchema : shardfileSchema(sections), input);
411
+ }
403
412
  /** Admit one owned or cached declaration field with its defining schema.
404
413
  * The assembled declaration still crosses parseShardfile's cross-field rules. */
405
414
  function parseShardfileField<Key extends keyof Shardfile>(field: Key, input: unknown): Shardfile[Key] {
@@ -31,7 +31,7 @@ function admitHead(
31
31
  payloads: ReadonlyMap<string, unknown>,
32
32
  ): Shardfile {
33
33
  const shard = withIssueCode('shard-schema', (): Shardfile =>
34
- parseShardfile(assembleOutputShardfile(index, payloads)),
34
+ parseShardfile(assembleOutputShardfile(index, payloads), payloads),
35
35
  )
36
36
  withIssueCode('declared-costs', (): void => {
37
37
  preflightDeclaredCosts(shard, offlineMemoryAdmission('warn'))
@@ -55,7 +55,7 @@ function admitBeforeAssets(
55
55
  const head = admitHead(index, payloads)
56
56
  return {
57
57
  admission: withIssueCode('asset-admission', (): AssetAdmission =>
58
- assetAdmission(head, offlineMemoryAdmission('warn'), scripts),
58
+ assetAdmission(head, offlineMemoryAdmission('warn'), scripts, payloads),
59
59
  ),
60
60
  refusal: undefined,
61
61
  }
@@ -114,11 +114,11 @@ export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refu
114
114
 
115
115
  /** Admit a whole shardfile's declared costs and its actual immutable bytes through the defining contracts. */
116
116
  export function admitShardfileFolder(input: unknown, assets: ReadonlyMap<string, Uint8Array>, hash: (bytes: Uint8Array) => string,
117
- policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = []): Shardfile {
118
- const source = coded('shard-schema', (): Shardfile => parseShardfile(input));
117
+ policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = [], sections?: ReadonlyMap<string, unknown>): Shardfile {
118
+ const source = coded('shard-schema', (): Shardfile => parseShardfile(input, sections));
119
119
  coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy)); });
120
120
  coded('performance-targets', (): void => { assertShardfileTargets(source, policy); });
121
- return coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy), undefined, scripts));
121
+ return coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy), undefined, scripts, sections));
122
122
  }
123
123
 
124
124
  /** Refuse world target rows that name items or quests the shardfile does not declare. */
@@ -229,7 +229,7 @@ export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileV
229
229
  coded('runtime-files', (): void => { ports.runtimeImports?.(entry.path, decoder().decode(read(entry))); });
230
230
  }
231
231
  for (const path of files.paths()) if (!listed.has(path)) throw issueError('unlisted-file', `Unlisted output file: ${path}`);
232
- const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts);
232
+ const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, payloads);
233
233
  checkWorldTargets(shard, payloads.get('world/targets'));
234
234
  if (ports.hash(validationSourceBytes(shard)) !== index.build.sourceHash) throw issueError('source-hash', 'Output sections differ from the declared source hash');
235
235
  return { index, shard, assets, sections: payloads, scripts, warnings, audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };