@wildshard/shard-format 0.79.1 → 0.79.3

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.79.1",
3
+ "version": "0.79.3",
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": {
@@ -457,18 +457,20 @@
457
457
  "./rigLooks": "./src/format/rig-looks.ts"
458
458
  },
459
459
  "engines": {
460
- "node": ">=24.18.0 <25"
460
+ "node": ">=24.18.0 <27"
461
461
  },
462
462
  "packageManager": "pnpm@10.34.9",
463
463
  "scripts": {
464
+ "dev": "node --test --watch 'src/!(format|ci)/**/*.test.ts'",
465
+ "build": "npm pack --dry-run --ignore-scripts",
464
466
  "pnpm:devPreinstall": "git rev-parse --is-inside-work-tree >/dev/null 2>&1 && git config core.hooksPath .githooks || true",
465
- "typecheck": "npr tsc -p kit/tsconfig.json && npr tsc -p src/format/tsconfig.json && npr tsc -p src/format/tsconfig.lib.json && npr tsc -p tsconfig.browser-tools.json",
466
- "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/engine-typecheck*' --ignore-pattern 'test/tooling/engine-typecheck.test.mjs' --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/**'",
467
- "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/engine-typecheck*' --ignore-pattern 'test/tooling/engine-typecheck.test.mjs' --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/**'",
467
+ "typecheck": "node src/scripts/.kit/typecheck.mjs && npr tsc -p src/format/tsconfig.json && npr tsc -p src/format/tsconfig.lib.json && npr tsc -p tsconfig.browser-tools.json",
468
+ "lint": "node src/scripts/.kit/bin-tools.mjs -c .oxlintrc.author.json --type-aware --deny-warnings --no-error-on-unmatched-pattern src packages",
469
+ "format:check": "npr oxfmt --check src '!src/format/**'",
470
+ "fix": "node src/scripts/.kit/bin-tools.mjs -c .oxlintrc.author.json --type-aware --no-error-on-unmatched-pattern src packages --fix && npr oxfmt --no-error-on-unmatched-pattern src '!src/format/**'",
471
+ "format": "npr oxfmt --no-error-on-unmatched-pattern src '!src/format/**'",
472
+ "test": "node --test 'src/!(format|ci)/**/*.test.ts' 'src/test/*.test.mjs' 'src/test/.kit/*.test.mjs' '.githooks/*.test.mjs' '.agents/hooks/test/*.test.mjs'",
468
473
  "lint:format": "node src/tools/format-ratchet.ts",
469
- "format": "npr oxfmt -c kit/.oxfmtrc.json kit src '!src/format/**' '!src/test/fixtures/**'",
470
- "format:check": "npr oxfmt -c kit/.oxfmtrc.json --check kit src '!src/format/**' '!src/test/fixtures/**'",
471
- "test": "node --test 'src/!(format|ci)/**/*.test.ts'",
472
474
  "test:ci": "node --test 'src/ci/**/*.test.ts'",
473
475
  "test:chain": "node --test 'src/tools/*.chain.ts'",
474
476
  "test:format": "vitest run src/format --testTimeout=30000 --maxWorkers=2",
@@ -477,19 +479,17 @@
477
479
  "check:format-gate": "node src/tools/format-gate.ts",
478
480
  "check:zone-snapshots": "node src/tools/zone-snapshot-guard.ts",
479
481
  "corpus:usage": "node src/cli/main.ts corpus --cache tmp/corpus --usage corpus/usage.json",
480
- "check:asks": "node kit/scripts/asks.mjs check",
482
+ "check:asks": "node src/scripts/.kit/asks.mjs check",
481
483
  "check:agents": "node .githooks/agents-md.mjs lint",
482
- "check:parity": "node scripts/agent-parity.mjs --strict",
483
- "check:agent-sync": "node scripts/agent-sync.mjs --check",
484
- "test:agent-hooks": "node --test '.agents/hooks/test/*.test.mjs'",
485
- "agents:sync": "node scripts/agent-sync.mjs",
486
- "md:wrap": "node kit/scripts/md-wrap.mjs",
487
- "test:hooks": "node --test '.githooks/*.test.mjs'",
488
- "check": "pnpm check:bin-pins && pnpm typecheck && pnpm lint && pnpm lint:format && pnpm format:check && pnpm test && pnpm check:lock && pnpm check:format-gate && pnpm check:zone-snapshots && node --test src/ci/exports-unique.test.ts && 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 test/tooling/engine-typecheck.test.mjs && pnpm check:wire && node scripts/engine-typecheck.mjs",
484
+ "check:parity": "node src/scripts/.kit/agent-parity.mjs --strict",
485
+ "check:agent-sync": "node src/scripts/.kit/agent-sync.mjs --check",
486
+ "agents:sync": "node src/scripts/.kit/agent-sync.mjs",
487
+ "md:wrap": "node src/scripts/.kit/md-wrap.mjs",
488
+ "check": "pnpm check:bin-pins && pnpm typecheck && pnpm lint && pnpm lint:format && pnpm format:check --no-error-on-unmatched-pattern && pnpm test && pnpm check:lock && pnpm check:format-gate && pnpm check:zone-snapshots && node --test src/ci/exports-unique.test.ts && pnpm test:format && pnpm check:asks && pnpm check:agents && pnpm check:agent-sync && pnpm check:parity && node --check src/scripts/.kit/chromium-keychain-check.mjs && pnpm check:wire && node src/scripts/engine-typecheck.mjs",
489
489
  "check:wire": "pnpm --dir packages/wire check && pnpm --dir packages/wire test && pnpm check:wire-proofs",
490
490
  "check:wire-proofs": "node --test src/scripts/wire/recordings-proof.mjs src/scripts/wire/graph-proof.mjs src/scripts/wire/prepared-frame-proof.mjs",
491
491
  "bench": "pnpm --dir packages/wire bench",
492
- "check:bin-pins": "node kit/scripts/bin-pins.mjs",
492
+ "check:bin-pins": "node src/scripts/.kit/bin-pins.mjs",
493
493
  "reupload": "node src/tools/reupload.ts"
494
494
  },
495
495
  "dependencies": {
@@ -502,11 +502,11 @@
502
502
  "@typescript/typescript6": "6.0.2",
503
503
  "binaryen": "132.0.0",
504
504
  "fflate": "0.8.3",
505
+ "npm-bin-deps": "2.2.0",
505
506
  "oxlint": "1.89.0",
506
507
  "playwright": "1.64.1",
507
508
  "vite": "8.3.0",
508
- "vitest": "5.0.1",
509
- "npm-bin-deps": "2.1.0"
509
+ "vitest": "5.0.1"
510
510
  },
511
511
  "pnpm": {
512
512
  "ignoredOptionalDependencies": [
@@ -597,5 +597,6 @@
597
597
  "oxfmt": "0.74.0",
598
598
  "oxlint-tsgolint": "7.0.2004"
599
599
  },
600
- "binDependenciesInstaller": "npm"
600
+ "binDependenciesInstaller": "pnpm",
601
+ "binDependenciesProjectSettings": false
601
602
  }
@@ -17,6 +17,7 @@ import {
17
17
  union,
18
18
  } from 'valibot'
19
19
 
20
+ import { sentSdkOf } from './incoming-sent.ts'
20
21
  import {
21
22
  failureOf,
22
23
  fenceValid,
@@ -246,11 +247,16 @@ function requireCookPreparation(
246
247
  return
247
248
  }
248
249
  // SHARD-COMPAT PR5 (J487): every failing prepared part is named, not the first.
250
+ // FP60: a published client hashed the index as sent, `requires.sdk` included (`incoming-sent.ts`).
251
+ const sdk = sentSdkOf(index)
252
+ const sent = { ...index, requires: { ...index.requires, sdk } }
253
+ const fresh = (sdk === undefined ? [index] : [index, sent]).some(
254
+ (row: Frozen<OutputIndex>): boolean =>
255
+ cook.inputHash ===
256
+ digest(cookPreparationBytes(row, cook.mounts, cook.renderer)),
257
+ )
249
258
  const failures = [
250
- cook.inputHash ===
251
- digest(cookPreparationBytes(index, cook.mounts, cook.renderer))
252
- ? undefined
253
- : `stale cook preparation: run ${fix}`,
259
+ fresh ? undefined : `stale cook preparation: run ${fix}`,
254
260
  failureOf((): void => {
255
261
  fenceValid(index, { fence: cook.fence ?? [], mounts: cook.mounts }, fix)
256
262
  }),
@@ -0,0 +1,36 @@
1
+ /** FORMAT-PRUNE FP60: what an incoming original's index carried before `incoming.ts` mended it. A published client
2
+ * declared its hashes (the source hash, the cook preparation's input hash) over the index as it sent it, `requires.sdk`
3
+ * included, so each check also accepts the index as sent. A leaf: `outputIndex.ts` reaches the preparation check, and
4
+ * this imports nothing. */
5
+
6
+ /** Each parsed incoming index whose `requires.sdk` was mended away, with the value the client sent. */
7
+ const SENT_SDK = new WeakMap<object, unknown>()
8
+
9
+ /** Remember the `requires.sdk` the client sent with `index`. */
10
+ function rememberSentSdk(index: object, sdk: unknown): void {
11
+ SENT_SDK.set(index, sdk)
12
+ }
13
+
14
+ /** The `requires.sdk` the client sent with `index`, when it was mended away. */
15
+ function sentSdkOf(index: object): unknown {
16
+ return SENT_SDK.get(index)
17
+ }
18
+
19
+ /** `value` with the `requires.sdk` its client sent. */
20
+ function withSentSdk(
21
+ value: Readonly<{ requires?: object }>,
22
+ sdk: unknown,
23
+ ): object {
24
+ return { ...value, requires: { ...value.requires, sdk } }
25
+ }
26
+
27
+ /** `value` as checked, then, when its client sent a `requires.sdk` that was mended away, as the client hashed it. */
28
+ function sentForms(
29
+ value: Readonly<{ requires?: object }>,
30
+ index: object,
31
+ ): readonly object[] {
32
+ const sdk = SENT_SDK.get(index)
33
+ return sdk === undefined ? [value] : [value, withSentSdk(value, sdk)]
34
+ }
35
+
36
+ export { rememberSentSdk, sentForms, sentSdkOf }
@@ -0,0 +1,55 @@
1
+ /** FORMAT-PRUNE FP60: an incoming original, mended of each deleted field before its strict parse. A published client
2
+ * still sends what its own format required: `@wildshard/upload` 0.4.22 (the oldest supported) checks with format 0.63.0
3
+ * and 0.4.25 with 0.66.0, both needing `requires.sdk`, and format 0.79.1's strict index refused every such upload
4
+ * ("Invalid key: Expected never but received sdk"). The stored bytes keep the field; the chain mends each copy it
5
+ * writes (`format-migration-deleted.ts`). Both validators read an original's index and sections through here, and check
6
+ * its declared source hash here: the client hashed `requires` as it sent it, `sdk` included. */
7
+ import { mendDeletedFields } from './format-migration-deleted.ts'
8
+ import { rememberSentSdk, sentForms } from './incoming-sent.ts'
9
+ import { parseOutputIndex, validateOutputSection } from './outputIndex.ts'
10
+ import { writtenSourceBytes } from './save-revision.ts'
11
+
12
+ import type { OutputIndex } from './outputIndex.ts'
13
+
14
+ function isRecord(value: unknown): value is Record<string, unknown> {
15
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
16
+ }
17
+
18
+ /** `shard.json` as uploaded: its deleted fields mended in place (`requires.sdk`), then parsed strictly. */
19
+ function parseIncomingIndex(index: unknown): OutputIndex {
20
+ const requires = isRecord(index) ? index['requires'] : undefined
21
+ const sdk = isRecord(requires) ? requires['sdk'] : undefined
22
+ if (isRecord(index)) {
23
+ mendDeletedFields({ index, sections: new Map(), mounts: new Map() })
24
+ }
25
+ const parsed = parseOutputIndex(index)
26
+ if (sdk !== undefined) {
27
+ rememberSentSdk(parsed, sdk)
28
+ }
29
+ return parsed
30
+ }
31
+
32
+ /** A section as uploaded: its deleted fields mended in place (the old grid pointer becomes `shardfile`), then
33
+ * validated strictly. */
34
+ function validateIncomingSection(name: string, value: unknown): void {
35
+ const sections = new Map([[name, value]])
36
+ mendDeletedFields({ index: {}, sections, mounts: new Map() })
37
+ validateOutputSection(name, value)
38
+ }
39
+
40
+ /** Whether `index`'s declared source hash covers `shard` as admitted, or as its client hashed it: with the
41
+ * `requires.sdk` it sent (`parseIncomingIndex`). */
42
+ function declaredSourceMatches(
43
+ shard: Readonly<{ requires?: object }>,
44
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
45
+ index: OutputIndex,
46
+ hash: (bytes: Readonly<Uint8Array>) => string,
47
+ ): boolean {
48
+ return sentForms(shard, index).some(
49
+ (source: object): boolean =>
50
+ hash(writtenSourceBytes(source, index.formatVersion)) ===
51
+ index.build.sourceHash,
52
+ )
53
+ }
54
+
55
+ export { declaredSourceMatches, parseIncomingIndex, validateIncomingSection }
@@ -8,10 +8,10 @@ import {
8
8
  assetAdmission,
9
9
  preflightDeclaredCosts,
10
10
  } from './assetAdmission.ts'
11
+ import { declaredSourceMatches } from './incoming.ts'
11
12
  import { issueError, withIssueCode } from './issue-codes.ts'
12
13
  import { assembleOutputShardfile } from './outputIndex.ts'
13
14
  import { admittedVerdict, recordVerdict } from './policy-verdict.ts'
14
- import { writtenSourceBytes } from './save-revision.ts'
15
15
  import { offlineMemoryAdmission } from './shardfile-assets.ts'
16
16
  import {
17
17
  assertShardfileTargets,
@@ -142,10 +142,7 @@ function admitTail(
142
142
  }>,
143
143
  ): void {
144
144
  checkWorldTargets(shard, product.payloads.get('world/targets'))
145
- if (
146
- product.hash(writtenSourceBytes(shard, product.index.formatVersion)) !==
147
- product.index.build.sourceHash
148
- ) {
145
+ if (!declaredSourceMatches(shard, product.index, product.hash)) {
149
146
  throw issueError(
150
147
  'source-hash',
151
148
  'Output sections differ from the declared source hash',
@@ -15,9 +15,9 @@
15
15
 
16
16
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts'
17
17
  import { assertSectionSides } from './feature-sides.ts'
18
+ import { parseIncomingIndex, validateIncomingSection } from './incoming.ts'
18
19
  import { issueError, withIssueCode } from './issue-codes.ts'
19
20
  import { unheldMount } from './manifest-deprecations.ts'
20
- import { parseOutputIndex, validateOutputSection } from './outputIndex.ts'
21
21
  import { admittedVerdict } from './policy-verdict.ts'
22
22
  import { assertScriptSides } from './script-sides.ts'
23
23
  import { scriptAdmissionRows } from './scriptContract.ts'
@@ -212,7 +212,7 @@ function readIndex(replay: Readonly<Replay>): OutputIndex {
212
212
  hash: shardJson.sha,
213
213
  bytes: shardJson.size,
214
214
  }
215
- return parseOutputIndex(readCanonicalJson(listedBytes(replay, listed)))
215
+ return parseIncomingIndex(readCanonicalJson(listedBytes(replay, listed)))
216
216
  }
217
217
 
218
218
  /** Each section: listed, hashed, canonical and valid; with the script side warnings (`assertScriptSides`). */
@@ -226,7 +226,7 @@ function readSections(
226
226
  withIssueCode('section-invalid', (): void => {
227
227
  const value = readCanonicalJson(listedBytes(replay, entry))
228
228
  assertSectionSides(entry.name, value)
229
- validateOutputSection(entry.name, value)
229
+ validateIncomingSection(entry.name, value)
230
230
  payloads.set(entry.name, value)
231
231
  })
232
232
  }
@@ -1,8 +1,8 @@
1
1
  import { cookMountPath, readCookData } from './cook-data.ts';
2
2
  import { checkDiscoveryMount } from './manifest-deprecations.ts';
3
3
  import { requireCookPreparation } from './cook-preparation.ts';
4
- import { parseOutputIndex, validateOutputSection, assembleOutputShardfile, type OutputFile, type OutputIndex } from './outputIndex.ts';
5
- import { asWrittenIdentity } from './save-revision.ts';
4
+ import { declaredSourceMatches, parseIncomingIndex, validateIncomingSection } from './incoming.ts';
5
+ import { assembleOutputShardfile, type OutputFile, type OutputIndex } from './outputIndex.ts';
6
6
  import { decisionModuleContracts, scriptAdmissionRows, type ScriptAdmissionRows, type ScriptContract } from './scriptContract.ts';
7
7
  import { registeredJsonContract, validateRegisteredJson } from './registeredJson.ts';
8
8
  import { validatePlatformFile } from './platformFileFamilies.ts';
@@ -183,7 +183,7 @@ type ReadListed = (entry: Readonly<{ path: string; hash: string; bytes: number }
183
183
  function readSections(index: OutputIndex, read: ReadListed): Map<string, unknown> {
184
184
  const payloads = new Map<string, unknown>();
185
185
  for (const entry of index.sections) {
186
- coded('section-invalid', (): void => { const value = readCanonicalJson(read(entry)); assertSectionSides(entry.name, value); validateOutputSection(entry.name, value); payloads.set(entry.name, value); });
186
+ coded('section-invalid', (): void => { const value = readCanonicalJson(read(entry)); assertSectionSides(entry.name, value); validateIncomingSection(entry.name, value); payloads.set(entry.name, value); });
187
187
  }
188
188
  return payloads;
189
189
  }
@@ -234,7 +234,7 @@ function readCook(index: OutputIndex, read: ReadListed, ports: Pick<ShardfileVal
234
234
  * check that refused (SA41, `issue-codes.ts`). */
235
235
  export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileValidationPorts): ValidatedShardfile {
236
236
  const verify = ports.verify ?? ((bytes: Uint8Array, expected: string): boolean => ports.hash(bytes) === expected);
237
- const index = coded('index-invalid', (): OutputIndex => parseOutputIndex(readCanonicalJson(files.read('shard.json', limits.sourceBytes))));
237
+ const index = coded('index-invalid', (): OutputIndex => parseIncomingIndex(readCanonicalJson(files.read('shard.json', limits.sourceBytes))));
238
238
  const listed = new Set(['shard.json', 'validation.json']), { assets, keep } = assetStore(files.read, ports.readThrough === true);
239
239
  const read: ReadListed = (entry): Uint8Array => coded('file-mismatch', (): Uint8Array => {
240
240
  listed.add(entry.path);
@@ -260,6 +260,6 @@ export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileV
260
260
  for (const path of files.paths()) if (!listed.has(path)) throw issueError('unlisted-file', `Unlisted output file: ${path}`);
261
261
  const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, { sections: payloads, mountedImages, index, judged: ports.judged ?? 'upload', armed: ports.armed });
262
262
  checkWorldTargets(shard, payloads.get('world/targets'));
263
- if (ports.hash(validationSourceBytes(asWrittenIdentity(shard, index.formatVersion))) !== index.build.sourceHash) throw issueError('source-hash', 'Output sections differ from the declared source hash');
263
+ if (!declaredSourceMatches(shard, index, ports.hash)) throw issueError('source-hash', 'Output sections differ from the declared source hash');
264
264
  return { index, shard, assets, sections: payloads, scripts, ...deprecationReport({ index, sections: payloads, cook }, warnings), policy: admittedVerdict(shard), audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };
265
265
  }