@wildshard/shard-format 0.69.2 → 0.71.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.
Files changed (73) hide show
  1. package/package.json +21 -3
  2. package/src/cli/corpus-candidate.ts +228 -0
  3. package/src/cli/corpus-command.ts +67 -0
  4. package/src/cli/corpus-pins.ts +73 -0
  5. package/src/cli/corpus-report.ts +36 -0
  6. package/src/cli/corpus-tar.ts +28 -0
  7. package/src/cli/corpus-usage.ts +106 -0
  8. package/src/cli/corpus.ts +50 -68
  9. package/src/cli/format-diff-data.ts +89 -0
  10. package/src/cli/format-diff-lock.ts +122 -0
  11. package/src/cli/format-diff-normal.ts +300 -0
  12. package/src/cli/format-diff-paths.ts +103 -0
  13. package/src/cli/format-diff-range.ts +112 -0
  14. package/src/cli/format-diff-report.ts +30 -0
  15. package/src/cli/format-diff-rules.ts +232 -0
  16. package/src/cli/format-diff.ts +226 -0
  17. package/src/cli/main.ts +81 -32
  18. package/src/cli/pack.ts +20 -3
  19. package/src/cli/validate.ts +1 -1
  20. package/src/format/clientOwnership.ts +1 -1
  21. package/src/format/clientTrails.ts +121 -46
  22. package/src/format/cook-data.ts +22 -3
  23. package/src/format/cook-deprecations.ts +53 -0
  24. package/src/format/cook-preparation.ts +105 -70
  25. package/src/format/creature-rest-rig.ts +248 -0
  26. package/src/format/creature-skin-bounds.ts +146 -0
  27. package/src/format/deprecations.ts +30 -21
  28. package/src/format/edge-observations.ts +67 -0
  29. package/src/format/empty-shardfile.ts +4 -2
  30. package/src/format/entry-read-set.ts +147 -0
  31. package/src/format/format-migrate-rebuild.ts +4 -1
  32. package/src/format/format-migrate.ts +10 -5
  33. package/src/format/format-migration-envelope.ts +40 -0
  34. package/src/format/format-migration-prune.ts +42 -1
  35. package/src/format/format-migrations.ts +10 -1
  36. package/src/format/format-window.ts +71 -0
  37. package/src/format/immutable.ts +4 -1
  38. package/src/format/json-schema.ts +1468 -0
  39. package/src/format/lootEconomy.ts +4 -1
  40. package/src/format/mat4.ts +225 -0
  41. package/src/format/memory-armed.json +1 -9
  42. package/src/format/memory-armed.ts +46 -17
  43. package/src/format/memory-epoch.ts +10 -3
  44. package/src/format/memory-line.ts +17 -6
  45. package/src/format/outputFields.ts +3 -2
  46. package/src/format/outputIndex.ts +41 -6
  47. package/src/format/platformDataSections.ts +5 -0
  48. package/src/format/platformFileFamilies.ts +3 -3
  49. package/src/format/play-area.ts +95 -0
  50. package/src/format/policy-verdict.ts +12 -2
  51. package/src/format/preparation-checks.ts +100 -0
  52. package/src/format/preparation-spec.ts +45 -0
  53. package/src/format/registeredJson.ts +2 -2
  54. package/src/format/runtime-tier.ts +14 -7
  55. package/src/format/save-revision.ts +105 -0
  56. package/src/format/schema-source.ts +70 -0
  57. package/src/format/sections.ts +4 -1
  58. package/src/format/server-plan.ts +42 -0
  59. package/src/format/server-reads.ts +23 -0
  60. package/src/format/shardSchema.ts +9 -4
  61. package/src/format/shardSections.ts +17 -7
  62. package/src/format/shardfile-assets.ts +5 -5
  63. package/src/format/shardfile-stream-admit.ts +19 -10
  64. package/src/format/shardfile-stream-facts.ts +2 -1
  65. package/src/format/shardfile-stream.ts +2 -3
  66. package/src/format/shardfileValidation.ts +16 -9
  67. package/src/format/species-deprecations.ts +79 -0
  68. package/src/format/stateLineage.ts +15 -7
  69. package/src/format/tread-boxes.ts +65 -0
  70. package/src/format/vehicle-hulls.ts +124 -0
  71. package/src/format/version.ts +96 -10
  72. package/src/format/whole-inputs.ts +51 -0
  73. package/src/tools/runtime-hosts.json +4 -0
@@ -14,7 +14,7 @@ export function clientOwnershipRules(source: Shardfile, sections: ReadonlyMap<st
14
14
  // OF19d1: a page drawing its declared bodies from their looks needs no species program
15
15
  const errors: string[] = [...rigs], program = !pageDrawsDeclaredLooks(source, sections.get('sim/runtime-plan'), features);
16
16
  if (!page || source.runtime !== null) errors.push('Native client features require their typed data page owner');
17
- for (const kind of ['world.scenes', 'motion.channels', ...program ? ['species.program'] as const : [], 'held.melee', 'quest.page', 'population.homes'] as const)
17
+ for (const kind of ['world.scenes', 'motion.channels', ...program ? ['species.program'] as const : [], 'held.melee', 'quest.page'] as const)
18
18
  if (!features.some(row => row.kind === kind)) errors.push(`Data page requires ${kind}`);
19
19
  const quest = features.find(row => row.kind === 'quest.page'), held = features.find(row => row.kind === 'held.melee');
20
20
  const declared = source.questHost?.page;
@@ -1,56 +1,131 @@
1
- import {isJsonData} from './json.ts';
2
- import * as v from 'valibot';
1
+ import * as v from 'valibot'
3
2
 
4
- const id = v.pipe(v.string(), v.minLength(1), v.maxLength(128));
5
- const real = v.pipe(v.number(), v.minValue(0), v.maxValue(10000));
3
+ import { isJsonData } from './json.ts'
4
+
5
+ const id = v.pipe(v.string(), v.minLength(1), v.maxLength(128))
6
+ const real = v.pipe(v.number(), v.minValue(0), v.maxValue(10000))
7
+ const FEWEST_MEMBERS = 1
8
+ const MOST_MEMBERS = 256
9
+ const group = v.exactOptional(id)
10
+ const members = v.exactOptional(
11
+ v.pipe(v.array(id), v.minLength(FEWEST_MEMBERS), v.maxLength(MOST_MEMBERS)),
12
+ )
13
+ /** Whether no two trail rows share a system id. */
14
+ function uniqueIds(rows: readonly Readonly<{ id: string }>[]): boolean {
15
+ return (
16
+ new Set(rows.map((row: Readonly<{ id: string }>): string => row.id))
17
+ .size === rows.length
18
+ )
19
+ }
20
+ /** Whether every trail row names exactly one of its group and its members. */
21
+ function oneSource(
22
+ rows: readonly Partial<Readonly<Record<'group' | 'members', unknown>>>[],
23
+ ): boolean {
24
+ for (const row of rows) {
25
+ if ((row.group === undefined) === (row.members === undefined)) {
26
+ return false
27
+ }
28
+ }
29
+ return true
30
+ }
6
31
  /** Client-only trails follow actual native population groups in their local
7
- * world frame. Looks and timing are data; there are no owner callbacks. */
8
- export const ClientTrailsSchema: v.StrictObjectSchema<{ readonly kind: v.GenericSchema<ClientTrailsRowsInput['kind'], ClientTrailsRows['kind']>; readonly rows: v.GenericSchema<ClientTrailsRowsInput['rows'], ClientTrailsRows['rows']>; }, undefined> = v.strictObject({ kind: v.literal('fx.trail'), rows: v.pipe(v.array(v.strictObject({
9
- id, group: id, library: id, look: id, name: id,
10
- points: v.pipe(v.number(), v.integer(), v.minValue(2), v.maxValue(2048)),
11
- every: v.pipe(real, v.minValue(0.001)), width: real, minimum: real, movementSq: real,
12
- })), v.maxLength(64), v.check(rows => new Set(rows.map(row => row.id)).size === rows.length, 'Unique trail systems')) });
32
+ * world frame. Looks and timing are data; there are no owner callbacks. A row
33
+ * names a page population's group, or (ONE-FORMAT OF29e7a) the declared spawns
34
+ * it follows as `members`; exactly one. */
35
+ export const ClientTrailsSchema: v.StrictObjectSchema<
36
+ {
37
+ readonly kind: v.GenericSchema<
38
+ ClientTrailsRowsInput['kind'],
39
+ ClientTrailsRows['kind']
40
+ >
41
+ readonly rows: v.GenericSchema<
42
+ ClientTrailsRowsInput['rows'],
43
+ ClientTrailsRows['rows']
44
+ >
45
+ },
46
+ undefined
47
+ > = v.strictObject({
48
+ kind: v.literal('fx.trail'),
49
+ rows: v.pipe(
50
+ v.array(
51
+ v.strictObject({
52
+ id,
53
+ group,
54
+ members,
55
+ library: id,
56
+ look: id,
57
+ name: id,
58
+ points: v.pipe(
59
+ v.number(),
60
+ v.integer(),
61
+ v.minValue(2),
62
+ v.maxValue(2048),
63
+ ),
64
+ every: v.pipe(real, v.minValue(0.001)),
65
+ width: real,
66
+ minimum: real,
67
+ movementSq: real,
68
+ }),
69
+ ),
70
+ v.maxLength(64),
71
+ v.check<ClientTrailsRows['rows'], string>(
72
+ uniqueIds,
73
+ 'Unique trail systems',
74
+ ),
75
+ v.check<ClientTrailsRows['rows'], string>(
76
+ oneSource,
77
+ 'A trail names its group or its members',
78
+ ),
79
+ ),
80
+ })
13
81
 
14
82
  /** A predicted line uses prepared widths and a finite fade envelope. */
15
- export const ProjectedTrailSchema: v.GenericSchema<ProjectedTrailRowsInput, ProjectedTrailRows>=v.pipe(v.unknown(),v.check(isJsonData),v.strictObject({
16
- points:v.pipe(v.number(),v.integer(),v.minValue(2),v.maxValue(256)),
17
- width:v.tuple([real,real]),lifetime:v.pipe(real,v.minValue(.001)),fade:real,
18
- color:v.tuple([real,real,real]),order:v.pipe(v.number(),v.integer(),v.minValue(-100),v.maxValue(100)),
19
- }));
20
-
83
+ export const ProjectedTrailSchema: v.GenericSchema<
84
+ ProjectedTrailRowsInput,
85
+ ProjectedTrailRows
86
+ > = v.pipe(
87
+ v.unknown(),
88
+ v.check(isJsonData),
89
+ v.strictObject({
90
+ points: v.pipe(v.number(), v.integer(), v.minValue(2), v.maxValue(256)),
91
+ width: v.tuple([real, real]),
92
+ lifetime: v.pipe(real, v.minValue(0.001)),
93
+ fade: real,
94
+ color: v.tuple([real, real, real]),
95
+ order: v.pipe(v.number(), v.integer(), v.minValue(-100), v.maxValue(100)),
96
+ }),
97
+ )
21
98
 
22
99
  /** Admitted data contracts, independent of validator implementation metadata. */
23
- export type ClientTrailsRowsInput = ClientTrailsRows;
100
+ export type ClientTrailsRowsInput = ClientTrailsRows
24
101
  interface ClientTrailsRowsFields {
25
- kind: 'fx.trail';
26
- rows: ({
27
- id: string;
28
- group: string;
29
- library: string;
30
- look: string;
31
- name: string;
32
- points: number;
33
- every: number;
34
- width: number;
35
- minimum: number;
36
- movementSq: number;
37
- })[];
102
+ kind: 'fx.trail'
103
+ rows: {
104
+ id: string
105
+ group?: string
106
+ members?: string[]
107
+ library: string
108
+ look: string
109
+ name: string
110
+ points: number
111
+ every: number
112
+ width: number
113
+ minimum: number
114
+ movementSq: number
115
+ }[]
116
+ }
117
+ export type ClientTrailsRows = {
118
+ [Key in keyof ClientTrailsRowsFields]: ClientTrailsRowsFields[Key]
38
119
  }
39
- export type ClientTrailsRows = { [Key in keyof ClientTrailsRowsFields]: ClientTrailsRowsFields[Key] };
40
- export type ProjectedTrailRowsInput = unknown;
120
+ export type ProjectedTrailRowsInput = unknown
41
121
  interface ProjectedTrailRowsFields {
42
- points: number;
43
- width: [
44
- number,
45
- number
46
- ];
47
- lifetime: number;
48
- fade: number;
49
- color: [
50
- number,
51
- number,
52
- number
53
- ];
54
- order: number;
122
+ points: number
123
+ width: [number, number]
124
+ lifetime: number
125
+ fade: number
126
+ color: [number, number, number]
127
+ order: number
128
+ }
129
+ export type ProjectedTrailRows = {
130
+ [Key in keyof ProjectedTrailRowsFields]: ProjectedTrailRowsFields[Key]
55
131
  }
56
- export type ProjectedTrailRows = { [Key in keyof ProjectedTrailRowsFields]: ProjectedTrailRowsFields[Key] };
@@ -13,9 +13,15 @@ import {
13
13
  string,
14
14
  } from 'valibot'
15
15
 
16
- import { CookPreparationSchema } from './cook-preparation.ts'
16
+ import {
17
+ CookPreparationSchema,
18
+ CookSpecPreparationSchema,
19
+ } from './cook-preparation.ts'
17
20
 
18
- import type { CookPreparation } from './cook-preparation.ts'
21
+ import type {
22
+ CookPreparation,
23
+ CookSpecPreparation,
24
+ } from './cook-preparation.ts'
19
25
  import type { GenericSchema } from 'valibot'
20
26
 
21
27
  // C0 (J137, D5): what makes a shardfile stand alone, in one file beside
@@ -104,6 +110,11 @@ const PreparedCookDataSchema = strictObject({
104
110
  ...CookPreparationSchema.entries,
105
111
  mounts: mountRows,
106
112
  })
113
+ /** SHARD-COMPAT PR4: preparation spec 4, which names no engine. */
114
+ const SpecCookDataSchema = strictObject({
115
+ ...CookSpecPreparationSchema.entries,
116
+ mounts: mountRows,
117
+ })
107
118
  const PREVIOUS_COOK_VERSION = 2
108
119
  const PreviousCookDataSchema = strictObject({
109
120
  version: literal(PREVIOUS_COOK_VERSION),
@@ -123,11 +134,19 @@ interface PreviousCookData extends Omit<
123
134
  interface PreparedCookData extends CookPreparation {
124
135
  readonly mounts: readonly CookMount[]
125
136
  }
126
- type CookData = LegacyCookData | PreviousCookData | PreparedCookData
137
+ interface SpecCookData extends CookSpecPreparation {
138
+ readonly mounts: readonly CookMount[]
139
+ }
140
+ type CookData =
141
+ | LegacyCookData
142
+ | PreviousCookData
143
+ | PreparedCookData
144
+ | SpecCookData
127
145
  const CookDataSchema: GenericSchema<unknown, CookData> = variant('version', [
128
146
  LegacyCookDataSchema,
129
147
  PreviousCookDataSchema,
130
148
  PreparedCookDataSchema,
149
+ SpecCookDataSchema,
131
150
  ])
132
151
 
133
152
  /** Where a mount's bytes sit in a product. */
@@ -0,0 +1,53 @@
1
+ /** FORMAT-PRUNE FP19: unprepared originals and old cook data are deprecated. Neither can be mended by data alone; the
2
+ * box's cook prepares them (SP1b), and they are deleted at FP23 once FE7 counts no kept upload using them. No engine
3
+ * pin uses either. A 0.1.0.3 file with no `preparation` is an author's file before `wildshard prepare` and is not
4
+ * warned; only the old `sdk: '0.2'` marker says a stored original was never prepared. */
5
+
6
+ /** The registry's row shape (`deprecations.ts`), with what it reads: the index and, from the folder validator, the
7
+ * parsed `cook.json` (the stream validator has none, so it never warns on cook data). */
8
+ interface CookDeprecation {
9
+ readonly id: string
10
+ readonly path: string
11
+ readonly since: string
12
+ readonly replacement: string
13
+ readonly migration: undefined
14
+ readonly uses: (
15
+ shard: Readonly<{ index: unknown; cook?: unknown }>,
16
+ ) => boolean
17
+ }
18
+
19
+ const BUILT_SDK = '0.2'
20
+ const CURRENT_COOK_DATA = 3
21
+ const SINCE = '0.1.0.4'
22
+
23
+ function field(value: unknown, key: string): unknown {
24
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
25
+ ? Reflect.get(value, key)
26
+ : undefined
27
+ }
28
+
29
+ const COOK_DEPRECATIONS: readonly CookDeprecation[] = [
30
+ {
31
+ id: 'shard.unprepared',
32
+ path: "shard.json sdk '0.2': a stored original built and never prepared (FORMAT-PRUNE FP19)",
33
+ since: SINCE,
34
+ replacement:
35
+ 'a prepared file: run wildshard prepare before upload; the box cook prepares old ones (SP1b)',
36
+ migration: undefined,
37
+ uses: (shard: Readonly<{ index: unknown }>): boolean =>
38
+ field(shard.index, 'sdk') === BUILT_SDK,
39
+ },
40
+ {
41
+ id: 'cook.legacy-data',
42
+ path: 'cook.json version 1 or 2 (FORMAT-PRUNE FP19)',
43
+ since: SINCE,
44
+ replacement: 'cook.json version 3 or later, written by wildshard prepare',
45
+ migration: undefined,
46
+ uses: (shard: Readonly<{ cook?: unknown }>): boolean => {
47
+ const version = field(shard.cook, 'version')
48
+ return typeof version === 'number' && version < CURRENT_COOK_DATA
49
+ },
50
+ },
51
+ ]
52
+
53
+ export { COOK_DEPRECATIONS }
@@ -14,8 +14,20 @@ import {
14
14
  strictObject,
15
15
  string,
16
16
  tuple,
17
+ union,
17
18
  } from 'valibot'
18
19
 
20
+ import {
21
+ failureOf,
22
+ fenceValid,
23
+ preparationMarked,
24
+ programMountValid,
25
+ } from './preparation-checks.ts'
26
+ import {
27
+ LEGACY_PREPARATION_SPEC,
28
+ PREPARATION_SPEC,
29
+ } from './preparation-spec.ts'
30
+ import { asWrittenIdentity } from './save-revision.ts'
19
31
  import { validationSourceBytes } from './validationReceipt.ts'
20
32
 
21
33
  import type { OutputIndex } from './outputIndex.ts'
@@ -30,8 +42,10 @@ const MAX_BUILD = 160
30
42
  const MAX_FENCE = 8192
31
43
  const ZERO = 0
32
44
  const ONE = 1
33
- const VERSION = 3
45
+ const VERSION: typeof LEGACY_PREPARATION_SPEC = LEGACY_PREPARATION_SPEC
34
46
  const PROGRAM_VERSION = 2
47
+ /** Programs at spec 4: the same GLSL rows with no engine `build`. */
48
+ const SPEC_PROGRAM_VERSION = 3
35
49
  const MAX_COOK_BYTES = 8_388_608
36
50
 
37
51
  /** Actual linked GLSL pairs, not decision programs. The recorder owns provenance. */
@@ -42,6 +56,14 @@ interface EntryPrograms {
42
56
  readonly shaders: readonly (readonly number[])[]
43
57
  readonly programs: readonly (readonly [number, number])[]
44
58
  }
59
+ /** Spec 4's programs: a warm-up hint any engine may use or ignore; no engine build is named. */
60
+ interface SpecPrograms {
61
+ readonly version: typeof SPEC_PROGRAM_VERSION
62
+ readonly lines: readonly string[]
63
+ readonly shaders: readonly (readonly number[])[]
64
+ readonly programs: readonly (readonly [number, number])[]
65
+ }
66
+ type AnyPrograms = EntryPrograms | SpecPrograms
45
67
  interface CookPreparation {
46
68
  readonly version: typeof VERSION
47
69
  readonly inputHash: string
@@ -50,6 +72,14 @@ interface CookPreparation {
50
72
  readonly fence: readonly string[]
51
73
  readonly programs: EntryPrograms
52
74
  }
75
+ /** Preparation spec 4 (PR4): spec 3 without the renderer fingerprint; programs without the engine build. */
76
+ interface CookSpecPreparation {
77
+ readonly version: typeof PREPARATION_SPEC
78
+ readonly inputHash: string
79
+ readonly packs: 'fence' | 'whole'
80
+ readonly fence: readonly string[]
81
+ readonly programs: SpecPrograms
82
+ }
53
83
  const natural = pipe(number(), safeInteger(), minValue(ZERO))
54
84
  const shader = pipe(array(natural), maxLength(MAX_LINES))
55
85
  const program = tuple([natural, natural])
@@ -59,14 +89,14 @@ const lines = pipe(array(line), maxLength(MAX_LINES))
59
89
  const shaders = pipe(array(shader), maxLength(MAX_SHADERS))
60
90
  const build = pipe(string(), minLength(ONE), maxLength(MAX_BUILD))
61
91
 
62
- function programSourceValid(row: EntryPrograms): boolean {
92
+ function programSourceValid(row: AnyPrograms): boolean {
63
93
  let size = ZERO
64
94
  for (const text of row.lines) {
65
95
  size += text.length
66
96
  }
67
97
  return size <= MAX_TEXT
68
98
  }
69
- function programLinesValid(row: EntryPrograms): boolean {
99
+ function programLinesValid(row: AnyPrograms): boolean {
70
100
  for (const source of row.shaders) {
71
101
  for (const index of source) {
72
102
  if (index >= row.lines.length) {
@@ -76,7 +106,7 @@ function programLinesValid(row: EntryPrograms): boolean {
76
106
  }
77
107
  return true
78
108
  }
79
- function programPairsValid(row: EntryPrograms): boolean {
109
+ function programPairsValid(row: AnyPrograms): boolean {
80
110
  const seen = new Set<string>()
81
111
  for (const pair of row.programs) {
82
112
  if (
@@ -97,12 +127,41 @@ const programRows: GenericSchema<unknown, EntryPrograms> = strictObject({
97
127
  shaders,
98
128
  programs,
99
129
  })
100
- const EntryProgramsSchema: GenericSchema<unknown, EntryPrograms> = pipe(
101
- programRows,
102
- check(programSourceValid, 'Program source exceeds cap'),
103
- check(programLinesValid, 'Program line index is out of range'),
104
- check(programPairsValid, 'Invalid or duplicate program pair'),
105
- )
130
+ const specProgramRows: GenericSchema<unknown, SpecPrograms> = strictObject({
131
+ version: literal(SPEC_PROGRAM_VERSION),
132
+ lines,
133
+ shaders,
134
+ programs,
135
+ })
136
+ function programChecks<Row extends AnyPrograms>(
137
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- a valibot schema, only piped
138
+ rows: GenericSchema<unknown, Row>,
139
+ ): GenericSchema<unknown, Row> {
140
+ return pipe(
141
+ rows,
142
+ check(
143
+ (row: Row): boolean => programSourceValid(row),
144
+ 'Program source exceeds cap',
145
+ ),
146
+ check(
147
+ (row: Row): boolean => programLinesValid(row),
148
+ 'Program line index is out of range',
149
+ ),
150
+ check(
151
+ (row: Row): boolean => programPairsValid(row),
152
+ 'Invalid or duplicate program pair',
153
+ ),
154
+ )
155
+ }
156
+ const EntryProgramsSchema: GenericSchema<unknown, EntryPrograms> =
157
+ programChecks(programRows)
158
+ const SpecProgramsSchema: GenericSchema<unknown, SpecPrograms> =
159
+ programChecks(specProgramRows)
160
+ /** The programs mount at either spec, by its `version`. */
161
+ const AnyProgramsSchema: GenericSchema<unknown, AnyPrograms> = union([
162
+ EntryProgramsSchema,
163
+ SpecProgramsSchema,
164
+ ])
106
165
  const hash = pipe(string(), regex(HASH))
107
166
  const fenceRows: GenericSchema<unknown, readonly string[]> = pipe(
108
167
  array(hash),
@@ -127,6 +186,20 @@ const CookPreparationSchema: GenericSchema<unknown, CookPreparation> & {
127
186
  fence,
128
187
  programs: EntryProgramsSchema,
129
188
  })
189
+ const CookSpecPreparationSchema: GenericSchema<unknown, CookSpecPreparation> & {
190
+ readonly entries: {
191
+ readonly [Key in keyof CookSpecPreparation]: GenericSchema<
192
+ unknown,
193
+ CookSpecPreparation[Key]
194
+ >
195
+ }
196
+ } = strictObject({
197
+ version: literal(PREPARATION_SPEC),
198
+ inputHash: hash,
199
+ packs: picklist(['fence', 'whole']),
200
+ fence,
201
+ programs: SpecProgramsSchema,
202
+ })
130
203
  /** Omit only the pointer to preparation itself; all other transport/host inputs remain bound. */
131
204
  type Frozen<Value> = Value extends object
132
205
  ? { readonly [Key in keyof Value]: Frozen<Value[Key]> }
@@ -143,62 +216,11 @@ function cookPreparationBytes(
143
216
  ): Uint8Array {
144
217
  const { cook: _cook, ...inputs } = index
145
218
  return validationSourceBytes({
146
- index: inputs,
219
+ index: asWrittenIdentity(inputs, index.formatVersion),
147
220
  mounts,
148
221
  ...(renderer === undefined ? {} : { renderer }),
149
222
  })
150
223
  }
151
- /** Shared by admission and the cook. Legacy sdk 0.2 is an explicit migration boundary. */
152
- function fenceValid(
153
- index: Frozen<OutputIndex>,
154
- lists: Readonly<{
155
- fence: readonly string[]
156
- mounts: readonly Readonly<{ hash: string }>[]
157
- }>,
158
- fix: string,
159
- ): void {
160
- const known = new Set<string>()
161
- for (const file of index.files) {
162
- known.add(file.hash)
163
- }
164
- for (const mount of lists.mounts) {
165
- known.add(mount.hash)
166
- }
167
- for (const row of lists.fence) {
168
- if (!known.has(row) && !index.requires.commons.includes(row)) {
169
- throw new Error(`stale fence preparation: run ${fix}`)
170
- }
171
- }
172
- }
173
- function programMountValid(
174
- index: Frozen<OutputIndex>,
175
- cook: {
176
- readonly programs?: EntryPrograms
177
- readonly mounts: readonly Readonly<{ url: string; hash: string }>[]
178
- },
179
- digest: (bytes: Readonly<Uint8Array>) => string,
180
- ): void {
181
- const url = `/programs/${index.identity.slug}.json`
182
- const mount = cook.mounts.find(
183
- (row: Readonly<{ url: string; hash: string }>): boolean => row.url === url,
184
- )
185
- if (
186
- cook.programs === undefined ||
187
- mount?.hash !== digest(validationSourceBytes(cook.programs))
188
- ) {
189
- throw new Error(
190
- `stale GLSL program mount: run wildshard prepare <folder> --base <exact-preview-url> (${index.identity.slug})`,
191
- )
192
- }
193
- }
194
- function failureOf(run: () => void): string | undefined {
195
- try {
196
- run()
197
- return undefined
198
- } catch (error: unknown) {
199
- return error instanceof Error ? error.message : String(error)
200
- }
201
- }
202
224
  function requireCookPreparation(
203
225
  index: Frozen<OutputIndex>,
204
226
  cook:
@@ -213,19 +235,16 @@ function requireCookPreparation(
213
235
  inputHash?: string
214
236
  renderer?: string
215
237
  fence?: readonly string[]
216
- programs?: EntryPrograms
238
+ programs?: AnyPrograms
217
239
  packs?: 'fence' | 'whole'
218
240
  }>
219
241
  | undefined,
220
242
  digest: (bytes: Readonly<Uint8Array>) => string,
221
243
  ): void {
222
244
  const fix = `wildshard prepare <folder> --base <exact-preview-url> (${index.identity.slug})`
223
- if (index.sdk === '0.2' && cook?.version !== VERSION) {
245
+ if (!preparationMarked(index, cook?.version, fix) || cook === undefined) {
224
246
  return
225
247
  }
226
- if (cook?.version !== VERSION) {
227
- throw new Error(`Missing cook preparation: run ${fix}`)
228
- }
229
248
  // SHARD-COMPAT PR5 (J487): every failing prepared part is named, not the first.
230
249
  const failures = [
231
250
  cook.inputHash ===
@@ -243,15 +262,31 @@ function requireCookPreparation(
243
262
  throw new Error(failures.join('; '))
244
263
  }
245
264
  }
246
- function readEntryPrograms(input: unknown): EntryPrograms {
247
- return parse(EntryProgramsSchema, input)
265
+ /** Whether a `cook.json` is prepared, at any spec this package reads (PR4). */
266
+ function isPreparedCook(
267
+ cook: Readonly<{ version: number }> | undefined,
268
+ ): boolean {
269
+ return preparationMarked({ sdk: '0.2' }, cook?.version, '')
270
+ }
271
+ function readEntryPrograms(input: unknown): AnyPrograms {
272
+ return parse(AnyProgramsSchema, input)
273
+ }
274
+ export type {
275
+ AnyPrograms,
276
+ EntryPrograms,
277
+ SpecPrograms,
278
+ CookPreparation,
279
+ CookSpecPreparation,
248
280
  }
249
- export type { EntryPrograms, CookPreparation }
250
281
  export {
251
282
  CookPreparationSchema,
283
+ CookSpecPreparationSchema,
252
284
  EntryProgramsSchema,
285
+ SpecProgramsSchema,
286
+ AnyProgramsSchema,
253
287
  cookPreparationBytes,
254
288
  requireCookPreparation,
255
289
  readEntryPrograms,
290
+ isPreparedCook,
256
291
  MAX_COOK_BYTES,
257
292
  }