@wildshard/shard-format 0.70.0 → 0.72.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 (67) hide show
  1. package/package.json +15 -3
  2. package/src/cli/corpus-candidate.ts +228 -0
  3. package/src/cli/corpus-command.ts +32 -3
  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 +24 -3
  8. package/src/cli/corpus.ts +50 -68
  9. package/src/cli/format-diff-range.ts +112 -0
  10. package/src/cli/main.ts +39 -9
  11. package/src/cli/pack.ts +20 -3
  12. package/src/cli/validate.ts +1 -1
  13. package/src/format/clientOwnership.ts +1 -1
  14. package/src/format/clientTrails.ts +121 -46
  15. package/src/format/cook-data.ts +19 -1
  16. package/src/format/cook-deprecations.ts +53 -0
  17. package/src/format/cook-preparation.ts +2 -1
  18. package/src/format/creature-rest-rig.ts +248 -0
  19. package/src/format/creature-skin-bounds.ts +146 -0
  20. package/src/format/deprecations.ts +18 -21
  21. package/src/format/edge-observations.ts +67 -0
  22. package/src/format/empty-shardfile.ts +5 -3
  23. package/src/format/entry-read-set.ts +147 -0
  24. package/src/format/format-migrate-rebuild.ts +4 -1
  25. package/src/format/format-migrate.ts +7 -1
  26. package/src/format/format-migration-envelope.ts +19 -0
  27. package/src/format/format-migration-prune.ts +42 -1
  28. package/src/format/format-migrations.ts +8 -1
  29. package/src/format/format-window.ts +71 -0
  30. package/src/format/immutable.ts +4 -1
  31. package/src/format/json-schema.ts +1474 -0
  32. package/src/format/lootEconomy.ts +4 -1
  33. package/src/format/mat4.ts +225 -0
  34. package/src/format/memory-armed.json +1 -9
  35. package/src/format/memory-armed.ts +46 -17
  36. package/src/format/memory-epoch.ts +10 -3
  37. package/src/format/memory-line.ts +17 -6
  38. package/src/format/outputFields.ts +3 -2
  39. package/src/format/outputIndex.ts +25 -8
  40. package/src/format/platformDataSections.ts +5 -0
  41. package/src/format/platformFileFamilies.ts +3 -3
  42. package/src/format/play-area.ts +95 -0
  43. package/src/format/policy-verdict.ts +12 -2
  44. package/src/format/preparation-checks.ts +12 -1
  45. package/src/format/preparation-spec.ts +24 -0
  46. package/src/format/registeredJson.ts +2 -2
  47. package/src/format/runtime-tier.ts +14 -7
  48. package/src/format/save-revision.ts +105 -0
  49. package/src/format/schema-source.ts +70 -0
  50. package/src/format/sections.ts +4 -1
  51. package/src/format/server-plan.ts +42 -0
  52. package/src/format/server-reads.ts +23 -0
  53. package/src/format/shardSchema.ts +9 -4
  54. package/src/format/shardSections.ts +17 -7
  55. package/src/format/shardfile-assets.ts +5 -5
  56. package/src/format/shardfile-stream-admit.ts +19 -10
  57. package/src/format/shardfile-stream-assets.ts +11 -2
  58. package/src/format/shardfile-stream-facts.ts +2 -1
  59. package/src/format/shardfile-stream.ts +2 -3
  60. package/src/format/shardfileValidation.ts +16 -9
  61. package/src/format/species-deprecations.ts +79 -0
  62. package/src/format/stateLineage.ts +12 -6
  63. package/src/format/tread-boxes.ts +65 -0
  64. package/src/format/vehicle-hulls.ts +124 -0
  65. package/src/format/version.ts +74 -17
  66. package/src/format/whole-inputs.ts +51 -0
  67. package/src/tools/runtime-hosts.json +4 -0
@@ -6,7 +6,8 @@ import * as v from 'valibot';
6
6
  import { WIRE_CELL, WIRE_TILE_SIZES } from './wireLimits.ts';
7
7
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
8
8
  import { SHARDFILE_VERSIONS } from './version.ts';
9
- import type { ShardfileVersion } from './version.ts';
9
+ import { oneSaveRevisionSpelling, saveRevisionOf } from './save-revision.ts';
10
+ import type { FormatVersion } from './version.ts';
10
11
  import { RuntimeCostSchema } from './runtimeCost.ts';
11
12
  import { CommonsCostsSchema } from './commonsCosts.ts';
12
13
  import { ScriptBindingsSchema } from './scripts.ts';
@@ -38,9 +39,13 @@ const file: v.StrictObjectSchema<{ readonly hash: v.GenericSchema<ShardFileRowsI
38
39
  const tileCount = (2 * CHUNK_HALF / WIRE_TILE_SIZES.l0) ** 2 + (2 * CHUNK_HALF / WIRE_TILE_SIZES.l1) ** 2;
39
40
 
40
41
  /** Stable authored shard identity and deterministic seed. */
41
- export const IdentitySchema: v.GenericSchema<ShardIdentityInput, ShardIdentity> = v.strictObject({ slug: name, name: v.pipe(v.string(), v.minLength(1), v.maxLength(limits.idCharacters)), author: v.pipe(v.string(), v.minLength(1), v.maxLength(limits.idCharacters)), revision: positive, seed: ShardNaturalSchema });
42
+ /** FORMAT-PRUNE FP26 (J493): the save lineage is `saveRevision`. Format 0.1.0.3 and older spell it `revision`; either
43
+ * spelling reads (the index checks which one its format version writes) and both come out as `saveRevision`. */
44
+ const IdentityRowSchema = v.strictObject({ slug: name, name: v.pipe(v.string(), v.minLength(1), v.maxLength(limits.idCharacters)), author: v.pipe(v.string(), v.minLength(1), v.maxLength(limits.idCharacters)), saveRevision: v.exactOptional(positive), revision: v.exactOptional(positive), seed: ShardNaturalSchema });
45
+ function identityWithSaveRevision(row: Readonly<v.InferOutput<typeof IdentityRowSchema>>): ShardIdentity { const { revision: _old, saveRevision: _new, ...rest } = row; return { ...rest, saveRevision: saveRevisionOf(row) }; }
46
+ export const IdentitySchema: v.GenericSchema<ShardIdentityInput, ShardIdentity> = v.pipe(IdentityRowSchema, v.check(oneSaveRevisionSpelling, 'Shard identity needs exactly one of saveRevision or revision'), v.transform(identityWithSaveRevision));
42
47
  /** Wire revision, capabilities and exact commons declarations. */
43
- export const RequiresSchema: v.GenericSchema<ShardRequiresInput, ShardRequires> = v.strictObject({ sdk: v.picklist(SHARDFILE_VERSIONS), capabilities: ShardNamesSchema, commons: v.pipe(v.array(ShardHashSchema), v.maxLength(limits.commons)), commonsWire: v.optional(v.record(ShardHashSchema, ShardNaturalSchema), {}), commonsCosts: v.optional(CommonsCostsSchema, {}) });
48
+ export const RequiresSchema: v.GenericSchema<ShardRequiresInput, ShardRequires> = v.strictObject({ sdk: v.exactOptional(v.picklist(SHARDFILE_VERSIONS)), capabilities: ShardNamesSchema, commons: v.pipe(v.array(ShardHashSchema), v.maxLength(limits.commons)), commonsWire: v.optional(v.record(ShardHashSchema, ShardNaturalSchema), {}), commonsCosts: v.optional(CommonsCostsSchema, {}) });
44
49
  /** Authored compressed and resident ceilings. */
45
50
  export const BudgetsSchema: v.GenericSchema<ShardBudgetsInput, ShardBudgets> = v.strictObject({
46
51
  /** Reviewed whole-client floor retained when an opaque runtime becomes declared data. */
@@ -210,7 +215,10 @@ interface ShardIdentityInputFields {
210
215
  slug: string;
211
216
  name: string;
212
217
  author: string;
213
- revision: ShardNaturalInput;
218
+ /** FP26: the save lineage. */
219
+ saveRevision?: ShardNaturalInput;
220
+ /** FP26: the save lineage's spelling up to format 0.1.0.3; give exactly one of the two. */
221
+ revision?: ShardNaturalInput;
214
222
  seed: ShardNaturalInput;
215
223
  }
216
224
  export type ShardIdentityInput = { [Key in keyof ShardIdentityInputFields]: ShardIdentityInputFields[Key] };
@@ -218,12 +226,14 @@ interface ShardIdentityFields {
218
226
  slug: string;
219
227
  name: string;
220
228
  author: string;
221
- revision: ShardNatural;
229
+ /** FP26: the save lineage. It keys saves and never goes backwards; it is not the API's shard revision. */
230
+ saveRevision: ShardNatural;
222
231
  seed: ShardNatural;
223
232
  }
224
233
  export type ShardIdentity = { [Key in keyof ShardIdentityFields]: ShardIdentityFields[Key] };
225
234
  interface ShardRequiresInputFields {
226
- sdk: ShardfileVersion;
235
+ /** SHARD-COMPAT CP8: deprecated (a copy of the format version, never read); writers stop sourcing it. */
236
+ sdk?: FormatVersion;
227
237
  capabilities: ShardNamesInput;
228
238
  commons: (ShardHashInput)[];
229
239
  commonsWire?: Record<string, ShardNaturalInput> | undefined;
@@ -231,7 +241,7 @@ interface ShardRequiresInputFields {
231
241
  }
232
242
  export type ShardRequiresInput = { [Key in keyof ShardRequiresInputFields]: ShardRequiresInputFields[Key] };
233
243
  interface ShardRequiresFields {
234
- sdk: ShardfileVersion;
244
+ sdk?: FormatVersion;
235
245
  capabilities: ShardNames;
236
246
  commons: (ShardHash)[];
237
247
  commonsWire: Record<string, ShardNatural>;
@@ -13,7 +13,7 @@ import type { Shardfile } from "./shardSchema.ts";
13
13
  import type { ShardTerrain } from "./terrain.ts";
14
14
  import { worstContentCost, memoryTargetWarnings, nearbyContentCost } from "./budget.ts";
15
15
  import { CONTENT_CAPS as C } from './contentBounds.ts';
16
- import { ARMED_LINES, ratchetLimit } from './memory-armed.ts';
16
+ import { ARMED_LINES, armedZone, ratchetLimit } from './memory-armed.ts';
17
17
  import { asJudged } from './policy-verdict.ts';
18
18
  import type { Judged } from './policy-verdict.ts';
19
19
  import { staleRuntimeIssues } from './memory-epoch.ts';
@@ -29,7 +29,7 @@ import type { IssueCodeOf } from './issue-codes.ts';
29
29
  import { isNavigationData, navigationCost } from './navigationBytes.ts';
30
30
 
31
31
  type PerformancePolicy = 'refuse' | 'warn';
32
- interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown>; readonly mountedImages?: number; readonly index?: TierIndex; readonly judged?: Judged }
32
+ interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown>; readonly mountedImages?: number; readonly index?: TierIndex; readonly judged?: Judged; readonly armed?: boolean | ReadonlySet<string> | undefined }
33
33
 
34
34
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
35
35
  function reportMemory(source: Shardfile, nativeBytes: number, options: Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages?: number; index?: TierIndex }>): PerformanceReport['memory'] {
@@ -321,7 +321,7 @@ export function performanceReport(source: Shardfile, observations: PerformanceOb
321
321
  };
322
322
  if (native.unmeasuredViewAndDownload) check(['perf-native-view-unmeasured', 'native view/download measurement required'], 1, 0);
323
323
  if (source.runtime !== null && source.runtime.cost === undefined) check(['perf-native-resident-unmeasured', 'native resident measurement required'], 1, 0);
324
- issues.push(...staleRuntimeIssues(source.runtime, undefined, source.identity), ...memoryLineIssues(worst, source.identity.slug));
324
+ issues.push(...staleRuntimeIssues(source.runtime, undefined, { ...source.identity, armed: resolved.armed }), ...memoryLineIssues(worst, armedZone(source.identity.slug, resolved.armed)));
325
325
  const library = reportCardClosure(source, source.library), critical = reportCardClosure(source, source.critical);
326
326
  const tileRoots = source.tiles.flatMap(tile => tile.files), farRoots = source.far?.files ?? [], nearRoots = nearPlaceholderRoots(source.near);
327
327
  const playable = reportCardClosure(source, [...source.critical, ...source.library, ...farRoots, ...source.tiles.filter(tile => tile.lod === 1 || near(tile, spawn.x, spawn.z)).flatMap(tile => tile.files)]);
@@ -370,9 +370,9 @@ export function performanceReportLines(report: PerformanceReport): string[] {
370
370
 
371
371
  /** Offline soft-cap policy and the hard loading ceiling (J445). A stored shard file was judged at its upload (CP10):
372
372
  * no memory line refuses it again. */
373
- export function offlineMemoryAdmission(_policy: 'warn' | 'refuse', judged: 'upload' | 'stored' = 'upload'): MemoryAdmission {
373
+ export function offlineMemoryAdmission(_policy: 'warn' | 'refuse', judged: 'upload' | 'stored' = 'upload', armed?: boolean | ReadonlySet<string>): MemoryAdmission {
374
374
  // The hard loading ceiling applies to the armed list.
375
375
  return new MemoryAdmission((): boolean => true, judged === 'stored'
376
376
  ? (): number => Number.POSITIVE_INFINITY
377
- : (owner, kind): number => ratchetLimit(owner, kind, MEMORY_HARD_BYTES));
377
+ : (owner, kind): number => ratchetLimit(armedZone(owner, armed), kind, MEMORY_HARD_BYTES));
378
378
  }
@@ -11,17 +11,17 @@ import {
11
11
  import { issueError, withIssueCode } from './issue-codes.ts'
12
12
  import { assembleOutputShardfile } from './outputIndex.ts'
13
13
  import { admittedVerdict, recordVerdict } from './policy-verdict.ts'
14
+ import { writtenSourceBytes } from './save-revision.ts'
14
15
  import { offlineMemoryAdmission } from './shardfile-assets.ts'
15
16
  import {
16
17
  assertShardfileTargets,
17
18
  checkWorldTargets,
18
19
  } from './shardfileValidation.ts'
19
20
  import { parseShardfile } from './shardSchema.ts'
20
- import { validationSourceBytes } from './validationReceipt.ts'
21
21
 
22
22
  import type { AssetAdmission } from './assetAdmission.ts'
23
23
  import type { OutputIndex } from './outputIndex.ts'
24
- import type { Judged, PolicyVerdict } from './policy-verdict.ts'
24
+ import type { Judged, JudgedPorts, PolicyVerdict } from './policy-verdict.ts'
25
25
  import type { ScriptAdmissionRows } from './scriptContract.ts'
26
26
  import type { AssetPasses } from './shardfile-stream-assets.ts'
27
27
  import type { Shardfile } from './shardSchema.ts'
@@ -31,13 +31,14 @@ function admitHead(
31
31
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
32
32
  index: OutputIndex,
33
33
  payloads: ReadonlyMap<string, unknown>,
34
- judged: Judged = 'upload',
34
+ policy: Readonly<JudgedPorts>,
35
35
  ): Shardfile {
36
+ const { judged = 'upload', armed } = policy
36
37
  const shard = withIssueCode('shard-schema', (): Shardfile =>
37
38
  parseShardfile(assembleOutputShardfile(index, payloads), payloads),
38
39
  )
39
40
  withIssueCode('declared-costs', (): void => {
40
- preflightDeclaredCosts(shard, offlineMemoryAdmission('warn', judged))
41
+ preflightDeclaredCosts(shard, offlineMemoryAdmission('warn', judged, armed))
41
42
  })
42
43
  const verdict = withIssueCode('performance-targets', (): PolicyVerdict =>
43
44
  // MG6 epoch 5: the index lets the estimate count only the files a phone fetches (no mount bytes in the stream).
@@ -46,6 +47,7 @@ function admitHead(
46
47
  mountedImages: 0,
47
48
  index,
48
49
  judged,
50
+ armed,
49
51
  }),
50
52
  )
51
53
  return recordVerdict(shard, verdict)
@@ -58,21 +60,26 @@ function admitBeforeAssets(
58
60
  index: OutputIndex,
59
61
  payloads: ReadonlyMap<string, unknown>,
60
62
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's row type, only read
61
- rows: Readonly<{ scripts: ScriptAdmissionRows; judged?: Judged | undefined }>,
63
+ rows: Readonly<{
64
+ scripts: ScriptAdmissionRows
65
+ judged?: Judged | undefined
66
+ armed?: boolean | ReadonlySet<string> | undefined
67
+ }>,
62
68
  ): Readonly<{
63
69
  admission: AssetAdmission | undefined
64
70
  refusal: unknown
65
71
  head?: Shardfile | undefined
66
72
  judged?: Judged | undefined
73
+ armed?: boolean | ReadonlySet<string> | undefined
67
74
  }> {
68
- const { scripts, judged } = rows
75
+ const { scripts, judged, armed } = rows
69
76
  try {
70
- const head = admitHead(index, payloads, judged)
77
+ const head = admitHead(index, payloads, { judged, armed })
71
78
  return {
72
79
  admission: withIssueCode('asset-admission', (): AssetAdmission =>
73
80
  assetAdmission(
74
81
  head,
75
- offlineMemoryAdmission('warn', judged),
82
+ offlineMemoryAdmission('warn', judged, armed),
76
83
  scripts,
77
84
  payloads,
78
85
  ),
@@ -80,6 +87,7 @@ function admitBeforeAssets(
80
87
  refusal: undefined,
81
88
  head,
82
89
  judged,
90
+ armed,
83
91
  }
84
92
  } catch (error) {
85
93
  return { admission: undefined, refusal: error }
@@ -94,6 +102,7 @@ function admitAssets(
94
102
  refusal: unknown
95
103
  head?: Shardfile | undefined
96
104
  judged?: Judged | undefined
105
+ armed?: boolean | ReadonlySet<string> | undefined
97
106
  }>,
98
107
  later: Readonly<AssetPasses>,
99
108
  hash: (bytes: Readonly<Uint8Array>) => string,
@@ -114,7 +123,7 @@ function admitAssets(
114
123
  admitAfterFiles(
115
124
  admission,
116
125
  later.assets,
117
- offlineMemoryAdmission('warn', before.judged),
126
+ offlineMemoryAdmission('warn', before.judged, before.armed),
118
127
  ),
119
128
  admittedVerdict(head),
120
129
  )
@@ -134,7 +143,7 @@ function admitTail(
134
143
  ): void {
135
144
  checkWorldTargets(shard, product.payloads.get('world/targets'))
136
145
  if (
137
- product.hash(validationSourceBytes(shard)) !==
146
+ product.hash(writtenSourceBytes(shard, product.index.formatVersion)) !==
138
147
  product.index.build.sourceHash
139
148
  ) {
140
149
  throw issueError(
@@ -135,6 +135,12 @@ function namedKeys(
135
135
  )
136
136
  }
137
137
 
138
+ /** A JSON's listed dependencies are held for the checks after the files (a skin file's GLB, its variant and phone
139
+ * tables), but not its textures (`ktx2`, OF27b): no later check reads a texture's bytes (`validateSkinAssets` reads the
140
+ * JSON and the GLB, and each texture's own costs were checked as it streamed, by `admitFileBytes`). Holding them put
141
+ * Nalati r7's declared skin looks (OF30: 18 textures, 15.7 MB) over `PLACED_HOLD_CAP`. */
142
+ const UNHELD_DEPENDENCY_KIND = 'ktx2'
143
+
138
144
  /** The placed keys, and the listed dependencies of the JSON among them (a skin file names its GLB; Codex review). */
139
145
  function placedKeys(
140
146
  shard: Readonly<AssetAdmission['shard']>,
@@ -155,7 +161,10 @@ function placedKeys(
155
161
  const row = rows.get(key)
156
162
  if (row?.kind === 'json') {
157
163
  for (const dependency of row.dependencies) {
158
- for (const found of hashKeys(dependency, paths)) {
164
+ for (const found of hashKeys(dependency, paths).filter(
165
+ (held: string): boolean =>
166
+ rows.get(held)?.kind !== UNHELD_DEPENDENCY_KIND,
167
+ )) {
159
168
  keys.add(found)
160
169
  }
161
170
  }
@@ -508,4 +517,4 @@ async function assetPasses(base: AssetPassInput): Promise<AssetPasses> {
508
517
  }
509
518
 
510
519
  export type { AssetPassInput, AssetPasses, StoredSource }
511
- export { assetPasses }
520
+ export { assetPasses, placedPaths }
@@ -12,6 +12,7 @@ import {
12
12
  registeredJsonContract,
13
13
  validateRegisteredJson,
14
14
  } from './registeredJson.ts'
15
+ import { currentSchemaSource } from './schema-source.ts'
15
16
  import { assetCost } from './shardfile-assets.ts'
16
17
  import { outputBlobExtension, outputBlobKind } from './shardfileValidation.ts'
17
18
  import { validationSourceBytes } from './validationReceipt.ts'
@@ -140,7 +141,7 @@ function inspectRegistered(file: OutputFile, member: FactsMember): void {
140
141
  'Unregistered named JSON with a schema needs a JSON Schema checker',
141
142
  )
142
143
  }
143
- if (file.jsonSchema['$comment'] !== contract.source) {
144
+ if (currentSchemaSource(file.jsonSchema['$comment']) !== contract.source) {
144
145
  throw new Error(
145
146
  'Registered JSON requires its exact defining format contract',
146
147
  )
@@ -39,7 +39,7 @@ import { readCanonicalJson } from './shardfileValidation.ts'
39
39
 
40
40
  import type { DeprecationReport } from './deprecations.ts'
41
41
  import type { OutputIndex } from './outputIndex.ts'
42
- import type { Judged, PolicyVerdict } from './policy-verdict.ts'
42
+ import type { JudgedPorts, PolicyVerdict } from './policy-verdict.ts'
43
43
  import type { ScriptAdmissionRows } from './scriptContract.ts'
44
44
  import type { StoredSource } from './shardfile-stream-assets.ts'
45
45
  import type { KeptMember, Replay } from './shardfile-stream-rows.ts'
@@ -51,7 +51,7 @@ import type {
51
51
  import type { Shardfile } from './shardSchema.ts'
52
52
 
53
53
  /** The host services a streaming validation needs. */
54
- interface StreamValidationPorts {
54
+ interface StreamValidationPorts extends JudgedPorts {
55
55
  /** Lowercase hex SHA-256 of exact bytes. */
56
56
  readonly hash: (bytes: Readonly<Uint8Array>) => string
57
57
  /** A fresh incremental SHA-256. */
@@ -60,7 +60,6 @@ interface StreamValidationPorts {
60
60
  readonly decode?: (
61
61
  stored: AsyncIterable<Uint8Array>,
62
62
  ) => AsyncIterable<Uint8Array>
63
- readonly judged?: Judged
64
63
  }
65
64
 
66
65
  /** What one streaming validation found. */
@@ -1,6 +1,7 @@
1
1
  import { cookMountPath, readCookData } from './cook-data.ts';
2
2
  import { requireCookPreparation } from './cook-preparation.ts';
3
3
  import { parseOutputIndex, validateOutputSection, assembleOutputShardfile, type OutputFile, type OutputIndex } from './outputIndex.ts';
4
+ import { asWrittenIdentity } from './save-revision.ts';
4
5
  import { decisionModuleContracts, scriptAdmissionRows, type ScriptAdmissionRows, type ScriptContract } from './scriptContract.ts';
5
6
  import { registeredJsonContract, validateRegisteredJson } from './registeredJson.ts';
6
7
  import { validatePlatformFile } from './platformFileFamilies.ts';
@@ -22,12 +23,14 @@ import type { RecordingMeasure } from './audio-measure.ts';
22
23
  import { issueError, withIssueCode as coded } from './issue-codes.ts';
23
24
  import { staleRuntimeIssues } from './memory-epoch.ts';
24
25
  import { memoryContext, offlineMemoryIssues } from './memory-line.ts';
26
+ import { armedZone } from './memory-armed.ts';
25
27
  import { runtimeTierIssues } from './runtime-tier.ts';
26
28
  import type { MemoryContext } from './memory-line.ts';
27
29
  import { mountedImageBytes, NO_BYTES } from './boot-memory-cost.ts';
28
30
  import { admittedVerdict, policyVerdict, recordVerdict } from './policy-verdict.ts';
29
31
  import type { Judged, PolicyVerdict } from './policy-verdict.ts';
30
32
  import { deprecationReport } from './deprecations.ts';
33
+ import { currentSchemaSource } from './schema-source.ts';
31
34
  import type { DeprecationReport } from './deprecations.ts';
32
35
 
33
36
  /**
@@ -61,6 +64,9 @@ export interface ShardfileValidationPorts {
61
64
  /** SHARD-COMPAT CP10: `'stored'` for a shard file already admitted (a stored original, an engine pin, a cook): memory
62
65
  * and budget policy only reports, since it was judged at upload. Default `'upload'`: the policy refuses. */
63
66
  readonly judged?: Judged;
67
+ /** FORMAT-PRUNE FP27b: whether the API catalogue arms this shard (`/api/catalogue` `armed`). Admission passes it; absent,
68
+ * the format's own armed list decides until FP27c removes it. */
69
+ readonly armed?: boolean | ReadonlySet<string> | undefined;
64
70
  /** D31: hold no file's bytes between checks. `assets`, here and in the result, reads each file again from `files`, so a
65
71
  * host's peak is its largest file rather than the shard, at the cost of those repeat reads. */
66
72
  readonly readThrough?: boolean;
@@ -124,20 +130,21 @@ export function outputBlobExtension(kind: OutputFile['kind'], bytes: Uint8Array)
124
130
  * A stored shard file (CP10, the context's `judged`) is never refused here: it was judged at its upload. */
125
131
  export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refuse', context: MemoryContext = new Map()): PolicyVerdict {
126
132
  // J412: the memory gates are ratchets; an issue in a zone not armed reports (`memory-armed.ts`) and is not thrown here.
127
- const found = [...staleRuntimeIssues(source.runtime, undefined, source.identity), ...offlineMemoryIssues(source, context), ...runtimeTierIssues(source), ...performanceTargetIssues(source, policy)];
133
+ const { armed } = memoryContext(context);
134
+ const found = [...staleRuntimeIssues(source.runtime, undefined, { ...source.identity, armed }), ...offlineMemoryIssues(source, context), ...runtimeTierIssues(source, armed), ...performanceTargetIssues(source, policy)];
128
135
  const issues = found.filter(issue => issue.severity === 'refusal'), judged = memoryContext(context).judged ?? 'upload';
129
136
  if (issues.length > 0 && judged === 'upload') throw issueError('performance-targets', issues.map(issue => `REFUSAL: ${issue.metric}: ${issue.actual} > ${issue.limit}`).join('\n'));
130
- return policyVerdict(source.identity.slug, judged, found);
137
+ return policyVerdict(armedZone(source.identity.slug, armed), judged, found);
131
138
  }
132
139
 
133
140
  /** Admit a whole shardfile's declared costs and its actual immutable bytes through the defining contracts. */
134
141
  export function admitShardfileFolder(input: unknown, assets: ReadonlyMap<string, Uint8Array>, hash: (bytes: Uint8Array) => string,
135
142
  policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = [], context?: MemoryContext): Shardfile {
136
- const { sections, judged } = context === undefined ? { sections: undefined, judged: undefined } : memoryContext(context);
143
+ const { sections, judged, armed } = context === undefined ? { sections: undefined, judged: undefined, armed: undefined } : memoryContext(context);
137
144
  const source = coded('shard-schema', (): Shardfile => parseShardfile(input, sections));
138
- coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy, judged)); });
145
+ coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy, judged, armed)); });
139
146
  const verdict = coded('performance-targets', (): PolicyVerdict => assertShardfileTargets(source, policy, context));
140
- return recordVerdict(coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy, judged), undefined, scripts, sections)), verdict);
147
+ return recordVerdict(coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy, judged, armed), undefined, scripts, sections)), verdict);
141
148
  }
142
149
 
143
150
  /** Refuse world target rows that name items or quests the shardfile does not declare. */
@@ -154,7 +161,7 @@ function inspectBlob(file: OutputFile, bytes: Uint8Array, ports: ShardfileValida
154
161
  if (ports.definedJson !== undefined) ports.definedJson(validationSourceBytes(file.jsonSchema), bytes, file.name);
155
162
  else if (contract === undefined || file.name === undefined) throw new Error('Unregistered named JSON with a schema needs a JSON Schema checker');
156
163
  else {
157
- if (file.jsonSchema['$comment'] !== contract.source) throw new Error('Registered JSON requires its exact defining format contract');
164
+ if (currentSchemaSource(file.jsonSchema['$comment']) !== contract.source) throw new Error('Registered JSON requires its exact defining format contract');
158
165
  validateRegisteredJson(file.name, parseNamedJson(bytes));
159
166
  }
160
167
  }
@@ -250,8 +257,8 @@ export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileV
250
257
  coded('runtime-files', (): void => { ports.runtimeImports?.(entry.path, decoder().decode(read(entry))); });
251
258
  }
252
259
  for (const path of files.paths()) if (!listed.has(path)) throw issueError('unlisted-file', `Unlisted output file: ${path}`);
253
- const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, { sections: payloads, mountedImages, index, judged: ports.judged ?? 'upload' });
260
+ 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 });
254
261
  checkWorldTargets(shard, payloads.get('world/targets'));
255
- if (ports.hash(validationSourceBytes(shard)) !== index.build.sourceHash) throw issueError('source-hash', 'Output sections differ from the declared source hash');
256
- return { index, shard, assets, sections: payloads, scripts, ...deprecationReport({ index, sections: payloads }, warnings), policy: admittedVerdict(shard), audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };
262
+ if (ports.hash(validationSourceBytes(asWrittenIdentity(shard, index.formatVersion))) !== index.build.sourceHash) throw issueError('source-hash', 'Output sections differ from the declared source hash');
263
+ return { index, shard, assets, sections: payloads, scripts, ...deprecationReport({ index, sections: payloads, cook }, warnings), policy: admittedVerdict(shard), audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };
257
264
  }
@@ -0,0 +1,79 @@
1
+ /** FORMAT-PRUNE FP15: the species-program family's page features. OF30's cut B leaves the `species.program` client row
2
+ * and the `population.product-creatures` and `population.hull-book` plan features reading only what the family's
3
+ * sections held; each creature is a declared row now (ONE-FORMAT OF5b2b). The sections themselves are FE7 rows in
4
+ * `deprecations.ts`. No data migration exists: a shard drops the feature when it re-uploads (Track F), and FP20 deletes
5
+ * it at zero users. `legacyKinds` sits inside `actors/species-programs`, so that section's row counts it. */
6
+
7
+ /** The registry's row shape (`deprecations.ts`). */
8
+ interface SpeciesFeatureDeprecation {
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<{ sections: ReadonlyMap<string, unknown> }>,
16
+ ) => boolean
17
+ }
18
+
19
+ /** The sections a page feature row can sit in. */
20
+ const FEATURE_SECTIONS: readonly string[] = ['client/plan', 'sim/runtime-plan']
21
+ const NONE = 0
22
+
23
+ /** Whether any object under `value` is a row of `kind`. */
24
+ function hasKind(value: unknown, kind: string): boolean {
25
+ const pending: unknown[] = [value]
26
+ while (pending.length > NONE) {
27
+ const next = pending.pop()
28
+ if (typeof next === 'object' && next !== null) {
29
+ if (!Array.isArray(next) && Reflect.get(next, 'kind') === kind) {
30
+ return true
31
+ }
32
+ const children: readonly unknown[] = Object.values(next)
33
+ pending.push(...children)
34
+ }
35
+ }
36
+ return false
37
+ }
38
+
39
+ function featureRow(kind: string): SpeciesFeatureDeprecation {
40
+ return {
41
+ id: `feature.${kind}`,
42
+ path: `client/plan or sim/runtime-plan rows of kind ${kind} (the species-program family, FORMAT-PRUNE FP15)`,
43
+ since: '0.1.0.4',
44
+ replacement:
45
+ 'declared creature rows (actors/creatures and their looks); the engine draws each from its row',
46
+ migration: undefined,
47
+ uses: (
48
+ shard: Readonly<{ sections: ReadonlyMap<string, unknown> }>,
49
+ ): boolean =>
50
+ FEATURE_SECTIONS.some((name: string): boolean =>
51
+ hasKind(shard.sections.get(name), kind),
52
+ ),
53
+ }
54
+ }
55
+
56
+ /** OF30 cut B leaves these sections as plain JSON nothing reads. Deprecated at 0.1.0.1 (format `cda6f63`). */
57
+ const SPECIES_SECTION_DEPRECATIONS: readonly SpeciesFeatureDeprecation[] = [
58
+ 'actors/species-programs',
59
+ 'look/hull-book',
60
+ 'look/rigged-hulls',
61
+ ].map((name: string): SpeciesFeatureDeprecation => ({
62
+ id: `section.${name}`,
63
+ path: `sections/${name} (the species-program family, FORMAT-PRUNE FP15)`,
64
+ since: '0.1.0.1',
65
+ replacement:
66
+ 'species rows and authored looks (actors/species); nothing reads it once OF30 lands',
67
+ migration: undefined,
68
+ uses: (
69
+ shard: Readonly<{ sections: ReadonlyMap<string, unknown> }>,
70
+ ): boolean => shard.sections.has(name),
71
+ }))
72
+
73
+ const SPECIES_FEATURE_DEPRECATIONS: readonly SpeciesFeatureDeprecation[] = [
74
+ featureRow('species.program'),
75
+ featureRow('population.product-creatures'),
76
+ featureRow('population.hull-book'),
77
+ ]
78
+
79
+ export { SPECIES_FEATURE_DEPRECATIONS, SPECIES_SECTION_DEPRECATIONS }
@@ -1,13 +1,18 @@
1
1
  import * as v from 'valibot';
2
2
  import { assertMigrationCompatibility } from './migrations.ts';
3
3
  import { StateSchema } from './state.ts';
4
+ import { oneSaveRevisionSpelling, saveRevisionOf } from './save-revision.ts';
4
5
  import type { Shardfile } from './shardSchema.ts';
5
6
  import { isJsonDataWithFileSchemas } from './json.ts';
6
7
  import { IndexFormatVersionSchema, LegacyIndexVersionSchema } from './index-format-version.ts';
7
8
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
8
9
 
9
- const identity = v.object({ slug: v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u)),
10
- revision: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(Number.MAX_SAFE_INTEGER)) });
10
+ const lineageRevision = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(Number.MAX_SAFE_INTEGER));
11
+ // FORMAT-PRUNE FP26: a cached product of format 0.1.0.3 or older spells the save lineage `revision`; both read as `saveRevision`.
12
+ const identityRow = v.object({ slug: v.pipe(v.string(), v.regex(/^[a-z][a-z0-9.-]*$/u)),
13
+ saveRevision: v.exactOptional(lineageRevision), revision: v.exactOptional(lineageRevision) });
14
+ function lineageIdentity(row: Readonly<v.InferOutput<typeof identityRow>>): StateLineage['identity'] { return { slug: row.slug, saveRevision: saveRevisionOf(row) }; }
15
+ const identity = v.pipe(identityRow, v.check(oneSaveRevisionSpelling, 'State lineage needs exactly one of saveRevision or revision'), v.transform(lineageIdentity));
11
16
  const lineage: v.GenericSchema<StateLineageInput, StateLineage> = v.object({ identity, state: StateSchema });
12
17
 
13
18
  /** Read only strict portable state and identity from a previously visited product. Its legacy geometry and scripts remain unadmitted. */
@@ -26,7 +31,7 @@ const inventory = v.object({ format: v.literal('wildshard.shardfile'), formatVer
26
31
  schema: v.pipe(v.string(), v.maxLength(240)) })), v.maxLength(256)),
27
32
  schemas: lineageSchemas });
28
33
  export interface OutputLineageIndex {
29
- readonly identity: { readonly slug: string; readonly revision: number };
34
+ readonly identity: { readonly slug: string; readonly saveRevision: number };
30
35
  readonly sections: readonly { readonly path: string; readonly hash: string; readonly bytes: number; readonly name: string; readonly schema: string }[];
31
36
  readonly schemas: readonly { readonly path: string; readonly hash: string; readonly bytes: number }[];
32
37
  }
@@ -52,7 +57,7 @@ export function parseOutputLineageIndex(input: unknown): OutputLineageIndex {
52
57
  /** Preserve saved field identities across validated author revisions; declaration ordering is immaterial. */
53
58
  export function assertStateCompatibility(previous: StateLineage, next: Shardfile): void {
54
59
  v.parse(v.literal(previous.identity.slug, 'State revisions must name the same shard'), next.identity.slug);
55
- if (next.identity.revision < previous.identity.revision) throw new Error('State revisions cannot move backwards');
60
+ if (next.identity.saveRevision < previous.identity.saveRevision) throw new Error('State revisions cannot move backwards');
56
61
  assertMigrationCompatibility(previous.state, next.state, next.migrations);
57
62
  }
58
63
 
@@ -61,7 +66,8 @@ export function assertStateCompatibility(previous: StateLineage, next: Shardfile
61
66
  interface StateLineageInputFields {
62
67
  identity: {
63
68
  slug: string;
64
- revision: number;
69
+ saveRevision?: number;
70
+ revision?: number;
65
71
  };
66
72
  state: v.InferInput<typeof StateSchema>;
67
73
  }
@@ -69,7 +75,7 @@ export type StateLineageInput = { [Key in keyof StateLineageInputFields]: StateL
69
75
  interface StateLineageFields {
70
76
  identity: {
71
77
  slug: string;
72
- revision: number;
78
+ saveRevision: number;
73
79
  };
74
80
  state: v.InferOutput<typeof StateSchema>;
75
81
  }
@@ -0,0 +1,65 @@
1
+ /* oxlint-disable id-length, import/group-exports, max-statements, no-magic-numbers, no-plusplus -- a port of engine's treadBoxes kept term for term (SHARD-COMPAT PR6b), so the boxes match engine's byte for byte */
2
+ // SHARD-COMPAT PR6b (J487): a stair's `treads` collider as the solid boxes physics installs, one per tread from the
3
+ // stair's foot up to that tread's top, with format code only. Moved from engine
4
+ // `src/shared/engine/physics/pieces.ts` `treadBoxes`; the material (surface, friction, groups) rides on every box.
5
+
6
+ interface Point {
7
+ readonly x: number
8
+ readonly y: number
9
+ readonly z: number
10
+ }
11
+
12
+ /** A `treads` shape as props declare it, with whatever contact fields it carries. */
13
+ export interface TreadShape {
14
+ readonly from: Point
15
+ readonly to: Point
16
+ readonly width: number
17
+ readonly count: number
18
+ readonly surface?: string
19
+ readonly friction?: number
20
+ readonly groups?: number
21
+ }
22
+
23
+ /** One tread's solid block: centre, half extents and yaw, plus the stair's material. */
24
+ export interface TreadBox {
25
+ readonly kind: 'box'
26
+ readonly x: number
27
+ readonly y: number
28
+ readonly z: number
29
+ readonly hx: number
30
+ readonly hy: number
31
+ readonly hz: number
32
+ readonly yaw: number
33
+ readonly surface?: string
34
+ readonly friction?: number
35
+ readonly groups?: number
36
+ }
37
+
38
+ /** One tread of a stair: a solid block from the stair's foot up to this tread's top. */
39
+ export function treadBoxes(d: TreadShape): TreadBox[] {
40
+ const dx = d.to.x - d.from.x
41
+ const dz = d.to.z - d.from.z
42
+ const run = Math.hypot(dx, dz) / d.count
43
+ const rise = (d.to.y - d.from.y) / d.count
44
+ const yaw = Math.atan2(dx, dz)
45
+ const out: TreadBox[] = []
46
+ for (let i = 0; i < d.count; i++) {
47
+ const f = (i + 0.5) / d.count
48
+ const top = d.from.y + rise * (i + 1)
49
+ const hy = Math.max(0.01, (top - d.from.y) / 2)
50
+ out.push({
51
+ kind: 'box',
52
+ x: d.from.x + dx * f,
53
+ y: d.from.y + hy,
54
+ z: d.from.z + dz * f,
55
+ hx: d.width / 2,
56
+ hy,
57
+ hz: run / 2,
58
+ yaw,
59
+ ...(d.surface === undefined ? {} : { surface: d.surface }),
60
+ ...(d.friction === undefined ? {} : { friction: d.friction }),
61
+ ...(d.groups === undefined ? {} : { groups: d.groups }),
62
+ })
63
+ }
64
+ return out
65
+ }