@wildshard/shard-format 0.70.0 → 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 (63) 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-deprecations.ts +53 -0
  16. package/src/format/cook-preparation.ts +2 -1
  17. package/src/format/creature-rest-rig.ts +248 -0
  18. package/src/format/creature-skin-bounds.ts +146 -0
  19. package/src/format/deprecations.ts +18 -21
  20. package/src/format/edge-observations.ts +67 -0
  21. package/src/format/empty-shardfile.ts +4 -2
  22. package/src/format/entry-read-set.ts +147 -0
  23. package/src/format/format-migrate-rebuild.ts +4 -1
  24. package/src/format/format-migrate.ts +7 -1
  25. package/src/format/format-migration-envelope.ts +19 -0
  26. package/src/format/format-migration-prune.ts +42 -1
  27. package/src/format/format-migrations.ts +8 -1
  28. package/src/format/format-window.ts +71 -0
  29. package/src/format/immutable.ts +4 -1
  30. package/src/format/json-schema.ts +1468 -0
  31. package/src/format/lootEconomy.ts +4 -1
  32. package/src/format/mat4.ts +225 -0
  33. package/src/format/memory-armed.json +1 -9
  34. package/src/format/memory-armed.ts +46 -17
  35. package/src/format/memory-epoch.ts +10 -3
  36. package/src/format/memory-line.ts +17 -6
  37. package/src/format/outputFields.ts +3 -2
  38. package/src/format/outputIndex.ts +14 -1
  39. package/src/format/platformDataSections.ts +5 -0
  40. package/src/format/platformFileFamilies.ts +3 -3
  41. package/src/format/play-area.ts +95 -0
  42. package/src/format/policy-verdict.ts +12 -2
  43. package/src/format/registeredJson.ts +2 -2
  44. package/src/format/runtime-tier.ts +14 -7
  45. package/src/format/save-revision.ts +105 -0
  46. package/src/format/schema-source.ts +70 -0
  47. package/src/format/sections.ts +4 -1
  48. package/src/format/server-plan.ts +42 -0
  49. package/src/format/server-reads.ts +23 -0
  50. package/src/format/shardSchema.ts +9 -4
  51. package/src/format/shardSections.ts +17 -7
  52. package/src/format/shardfile-assets.ts +5 -5
  53. package/src/format/shardfile-stream-admit.ts +19 -10
  54. package/src/format/shardfile-stream-facts.ts +2 -1
  55. package/src/format/shardfile-stream.ts +2 -3
  56. package/src/format/shardfileValidation.ts +16 -9
  57. package/src/format/species-deprecations.ts +79 -0
  58. package/src/format/stateLineage.ts +12 -6
  59. package/src/format/tread-boxes.ts +65 -0
  60. package/src/format/vehicle-hulls.ts +124 -0
  61. package/src/format/version.ts +74 -17
  62. package/src/format/whole-inputs.ts +51 -0
  63. package/src/tools/runtime-hosts.json +4 -0
@@ -1,11 +1,11 @@
1
1
  import { LEGACY_PREPARATION_SPEC, PREPARED_SDK } from './preparation-spec.ts'
2
2
 
3
- /** Canonical format revision, separate from the npm package and script ABI (J319).
3
+ /** Canonical format version, separate from the npm package and script ABI (J319).
4
4
  * The fourth component adds fields; the third changes their meaning. */
5
5
  const ZERO = 0
6
6
  const ONE = 1
7
7
 
8
- const SHARDFILE_VERSION = '0.1.0.3'
8
+ const SHARDFILE_VERSION = '0.1.0.4'
9
9
  /** Formats whose `shard.json` names its version in `version`, beside the frozen layout marker `formatVersion: 2`.
10
10
  * Legacy 0.1 is the byte-preserving spelling of 0.1.0.0. */
11
11
  const LEGACY_INDEX_VERSIONS: readonly ['0.1', '0.1.0.0', '0.1.0.1'] = [
@@ -15,15 +15,19 @@ const LEGACY_INDEX_VERSIONS: readonly ['0.1', '0.1.0.0', '0.1.0.1'] = [
15
15
  ] as const
16
16
  /** Formats whose `shard.json` names its version in `formatVersion` (SHARD-COMPAT CP14, FORMAT-PRUNE FP25): the
17
17
  * layout marker and `version` are gone, so a reader tells the two envelopes apart by the field's type. */
18
- const INDEX_FORMAT_VERSIONS: readonly ['0.1.0.2', typeof SHARDFILE_VERSION] = [
18
+ const INDEX_FORMAT_VERSIONS: readonly [
19
19
  '0.1.0.2',
20
- SHARDFILE_VERSION,
21
- ] as const
20
+ '0.1.0.3',
21
+ typeof SHARDFILE_VERSION,
22
+ ] = ['0.1.0.2', '0.1.0.3', SHARDFILE_VERSION] as const
22
23
  const SHARDFILE_VERSIONS: readonly [
23
24
  ...typeof LEGACY_INDEX_VERSIONS,
24
25
  ...typeof INDEX_FORMAT_VERSIONS,
25
26
  ] = [...LEGACY_INDEX_VERSIONS, ...INDEX_FORMAT_VERSIONS] as const
26
- type ShardfileVersion = (typeof SHARDFILE_VERSIONS)[number]
27
+ /** A format version (J319): the four-part number naming a shard file's shape (SHARD-COMPAT §2's word). */
28
+ type FormatVersion = (typeof SHARDFILE_VERSIONS)[number]
29
+ /** @deprecated SHARD-COMPAT SP10: the retired word; use `FormatVersion`. Kept until no consumer imports it (ST19). */
30
+ type ShardfileVersion = FormatVersion
27
31
  type LegacyIndexVersion = (typeof LEGACY_INDEX_VERSIONS)[number]
28
32
  type IndexFormatVersion = (typeof INDEX_FORMAT_VERSIONS)[number]
29
33
  /** The frozen layout marker the legacy envelope carries in `formatVersion`. */
@@ -33,10 +37,16 @@ const SHARDFILE_VERSION_INDEX_RENAME = '0.1.0.2'
33
37
  /** The first format whose `shard.json` records the preparation spec version in `preparation` instead of the `sdk`
34
38
  * marker (SHARD-COMPAT PR4, J487; FORMAT-PRUNE FP5 folded in). */
35
39
  const SHARDFILE_VERSION_PREPARATION = '0.1.0.3'
36
- type ShardfileVersionParts = readonly [number, number, number, number]
40
+ /** The first format whose `shard.json` names the save lineage `identity.saveRevision` instead of `identity.revision`
41
+ * (FORMAT-PRUNE FP26, J493): the number keys saves and only ever rises; it is not the API's shard revision. */
42
+ const SHARDFILE_VERSION_SAVE_REVISION = '0.1.0.4'
43
+ /** A format version's four parts. */
44
+ type FormatVersionParts = readonly [number, number, number, number]
45
+ /** @deprecated SHARD-COMPAT SP10: use `FormatVersionParts`. */
46
+ type ShardfileVersionParts = FormatVersionParts
37
47
 
38
48
  /** Read canonical bounded decimal components; the legacy two-part spelling has zero counters. */
39
- function parseShardfileVersion(input: unknown): ShardfileVersionParts {
49
+ function parseShardfileVersion(input: unknown): FormatVersionParts {
40
50
  if (
41
51
  typeof input !== 'string' ||
42
52
  !/^(?:0|[1-9][0-9]{0,3})(?:\.(?:0|[1-9][0-9]{0,3}))(?:\.(?:0|[1-9][0-9]{0,3})\.(?:0|[1-9][0-9]{0,3}))?$/u.test(
@@ -91,7 +101,7 @@ function compatibleShardfileVersion(
91
101
 
92
102
  /** The format version a `shard.json` declares: `formatVersion` when it is a version string (0.1.0.2 on), else the
93
103
  * legacy `version` beside the layout marker `formatVersion: 2`. Throws when neither names a format. */
94
- function shardfileFormatOf(index: unknown): ShardfileVersion {
104
+ function shardfileFormatOf(index: unknown): FormatVersion {
95
105
  const declared: unknown =
96
106
  typeof index === 'object' && index !== null
97
107
  ? Reflect.get(index, 'formatVersion')
@@ -124,6 +134,53 @@ function writesPreparationMarker(version: string): boolean {
124
134
  )
125
135
  }
126
136
 
137
+ /** Whether a format version names the save lineage `identity.saveRevision` (0.1.0.4 on, FP26). */
138
+ function writesSaveRevision(version: string): boolean {
139
+ return (
140
+ compareShardfileVersions(version, SHARDFILE_VERSION_SAVE_REVISION) >= ZERO
141
+ )
142
+ }
143
+
144
+ /** FP26: a copy of an identity row with `revision` spelled `saveRevision`; anything else as it is. */
145
+ function withSaveRevision(identity: unknown): unknown {
146
+ if (
147
+ typeof identity !== 'object' ||
148
+ identity === null ||
149
+ Array.isArray(identity) ||
150
+ !Object.hasOwn(identity, 'revision')
151
+ ) {
152
+ return identity
153
+ }
154
+ const renamed = Object.entries(identity).map(
155
+ ([key, item]: readonly [string, unknown]): readonly [string, unknown] => [
156
+ key === 'revision' ? 'saveRevision' : key,
157
+ item,
158
+ ],
159
+ )
160
+ return Object.fromEntries(renamed)
161
+ }
162
+
163
+ /** The rows a version from 0.1.0.3 on changes in place: PR4's preparation marker, then FP26's save lineage. */
164
+ function laterEnvelopeRows(
165
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- it changes the writer's envelope in place
166
+ envelope: Record<string, unknown>,
167
+ version: string,
168
+ ): void {
169
+ // SHARD-COMPAT PR4: from 0.1.0.3 the `sdk` marker goes; a prepared writer's `'0.3'` becomes the spec version it
170
+ // meant, unless the writer already names one in `preparation`.
171
+ if (writesPreparationMarker(version)) {
172
+ const { sdk } = envelope
173
+ Reflect.deleteProperty(envelope, 'sdk')
174
+ if (sdk === PREPARED_SDK && envelope['preparation'] === undefined) {
175
+ envelope['preparation'] = LEGACY_PREPARATION_SPEC
176
+ }
177
+ }
178
+ // FORMAT-PRUNE FP26: from 0.1.0.4 the save lineage is `identity.saveRevision`.
179
+ if (writesSaveRevision(version)) {
180
+ envelope['identity'] = withSaveRevision(envelope['identity'])
181
+ }
182
+ }
183
+
127
184
  /** A copy of a JSON object without `keys`; anything else as it is. */
128
185
  function withoutKeys(value: unknown, keys: readonly string[]): unknown {
129
186
  if (typeof value !== 'object' || value === null || Array.isArray(value)) {
@@ -167,14 +224,8 @@ function outputIndexEnvelope<Rows extends Readonly<Record<string, unknown>>>(
167
224
  formatVersion: version,
168
225
  runtime: withoutKeys(rest['runtime'], ['files', 'lines', 'trust']),
169
226
  }
170
- // SHARD-COMPAT PR4: from 0.1.0.3 the `sdk` marker goes; a prepared writer's `'0.3'` becomes the spec version it
171
- // meant, unless the writer already names one in `preparation`.
172
- if (typeof version === 'string' && writesPreparationMarker(version)) {
173
- const { sdk } = envelope
174
- Reflect.deleteProperty(envelope, 'sdk')
175
- if (sdk === PREPARED_SDK && envelope['preparation'] === undefined) {
176
- envelope['preparation'] = LEGACY_PREPARATION_SPEC
177
- }
227
+ if (typeof version === 'string') {
228
+ laterEnvelopeRows(envelope, version)
178
229
  }
179
230
  // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the writer's own rows; only envelope fields change
180
231
  return envelope as IndexEnvelope<Rows>
@@ -193,9 +244,15 @@ export {
193
244
  shardfileFormatOf,
194
245
  writesIndexFormatVersion,
195
246
  writesPreparationMarker,
247
+ writesSaveRevision,
196
248
  SHARDFILE_VERSION_PREPARATION,
249
+ SHARDFILE_VERSION_SAVE_REVISION,
197
250
  SHARDFILE_FLOOR,
251
+ type FormatVersion,
252
+ type FormatVersionParts,
253
+ // oxlint-disable-next-line typescript/no-deprecated -- SP10: the old name stays exported as an alias until no consumer imports it (ST19).
198
254
  type ShardfileVersion,
255
+ // oxlint-disable-next-line typescript/no-deprecated -- SP10: as above.
199
256
  type ShardfileVersionParts,
200
257
  parseShardfileVersion,
201
258
  compareShardfileVersions,
@@ -0,0 +1,51 @@
1
+ import { splatTerrainOf, splatTextureRefs } from './splatTerrain.ts'
2
+
3
+ /* oxlint-disable curly, import/group-exports, no-magic-numbers, typescript/explicit-function-return-type, typescript/prefer-readonly-parameter-types, unicorn/prefer-spread -- moved verbatim from engine (SHARD-COMPAT PR6e), so the cook's entry set stays the same set byte for byte */
4
+ // SHARD-COMPAT PR6e (J487): the whole-intake inputs and the other tier's splat files, a rule over the shard alone.
5
+ // Moved from engine `src/shared/game/shardfile/wholeInputs.ts`.
6
+ import type { Shardfile } from './shardSchema.ts'
7
+
8
+ /** Ordered native whole-intake inputs. A named assembly also reads its
9
+ * declared whole library; explicit-reference callers bypass this default. */
10
+ export function wholeGeometryInputs(
11
+ props: Shardfile['props'],
12
+ includeLibrary: boolean,
13
+ ): readonly string[] {
14
+ return [
15
+ ...(props?.tiles
16
+ .filter(row => row.lod === 0)
17
+ .flatMap(row => [row.file].concat(row.additionalFiles ?? [])) ?? []),
18
+ ...(includeLibrary ? (props?.wholeLibrary ?? []) : []),
19
+ ]
20
+ }
21
+
22
+ /** S4: a splat ground with a phone set draws one set per tier, and every L0 tile depends on both sets, so a dependency pins
23
+ * both through tier selection. The files only the other tier's set names are never read on this one. */
24
+ export function otherTierSplatFiles(
25
+ source: Pick<Shardfile, 'props'>,
26
+ tier: 'phone' | 'desktop' | (() => 'phone' | 'desktop'),
27
+ ): ReadonlySet<string> {
28
+ const splat = source.props === null ? undefined : splatTerrainOf(source.props)
29
+ if (splat?.phone === undefined) return new Set()
30
+ const drawn = new Set(
31
+ splatTextureRefs(splat, typeof tier === 'function' ? tier() : tier),
32
+ )
33
+ return new Set(splatTextureRefs(splat).filter(hash => !drawn.has(hash)))
34
+ }
35
+ /** S12f2b2: the phone layers a device drawing the phone set reads as the cook's own 6×6 file (`layer` names one), never as
36
+ * their blobs. None on a device drawing the desktop set, or without a cooked row (an older cook): the blob is read. */
37
+ export function cookedSplatLayers(
38
+ source: Pick<Shardfile, 'props'>,
39
+ tier: () => 'phone' | 'desktop',
40
+ layer: ((hash: string) => string | undefined) | undefined,
41
+ ): ReadonlySet<string> {
42
+ const splat =
43
+ source.props === null || layer === undefined
44
+ ? undefined
45
+ : splatTerrainOf(source.props)
46
+ if (splat?.phone === undefined || layer === undefined || tier() !== 'phone')
47
+ return new Set()
48
+ return new Set(
49
+ splatTextureRefs(splat, 'phone').filter(hash => layer(hash) !== undefined),
50
+ )
51
+ }
@@ -40,6 +40,10 @@
40
40
  "client/plan": {
41
41
  "hosts": ["page installClientPhase"]
42
42
  },
43
+ "server/plan": {
44
+ "hosts": ["server serverPlan"],
45
+ "note": "SHARD-COMPAT HS6b: the server's copy of the feature rows; engine's seam (`src/server/game/shardfile/serverPlan.ts`) reads it, falling back to `client/plan` for a file without one until the roll."
46
+ },
43
47
  "collections/displays": {
44
48
  "hosts": ["page CollectionCatalogue"]
45
49
  },