@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
@@ -10,6 +10,8 @@ import { ExplorerCatalogueSchema, type ExplorerCatalogue } from './explorerCatal
10
10
  import { ToonLookSchema, type ToonLookRow } from './toonLook.ts';
11
11
  import { KEYED_SKY, type KeyedSkyStyle } from './keyedSky.ts';
12
12
  import { ClientPlanSchema, type ClientPlan } from './clientPlan.ts';
13
+ import { ServerPlanSchema } from './server-plan.ts';
14
+ import type { ServerPlan } from './server-plan.ts';
13
15
  import { SpawnScriptsSchema, type SpawnScriptRows } from './spawnScripts.ts';
14
16
  import { WorldScenesSchema, type WorldScenesSection } from './worldScenes.ts';
15
17
  import { HeldArmsSchema, type HeldArmsRows } from './heldArms.ts';
@@ -50,6 +52,8 @@ export interface PlatformDataSections {
50
52
  'look/colour-functions': ColourFunctionBook;
51
53
  'look/keyed-sky': KeyedSkyStyle;
52
54
  'client/plan': ClientPlan;
55
+ /** SHARD-COMPAT HS6b: the server's own copy of the feature rows, so `client/plan` stays the page's. */
56
+ 'server/plan': ServerPlan;
53
57
  'view/modules': ViewModuleRow[];
54
58
  'held/arms': HeldArmsRows;
55
59
  'held/gear': HeldGearRows;
@@ -89,6 +93,7 @@ export const PLATFORM_DATA_SECTIONS: Readonly<{ [Name in keyof PlatformDataSecti
89
93
  'look/colour-functions': { schema: ColourFunctionBookSchema },
90
94
  'look/keyed-sky': { schema: KEYED_SKY },
91
95
  'client/plan': { schema: ClientPlanSchema },
96
+ 'server/plan': { schema: ServerPlanSchema },
92
97
  'view/modules': { schema: ViewModulesSchema },
93
98
  'held/arms': { schema: HeldArmsSchema },
94
99
  'held/gear': { schema: HeldGearSchema },
@@ -8,6 +8,7 @@ import { HeldJianDocumentSchema } from './heldJianDocument.ts';
8
8
  import { BladeDocumentSchema, PolearmDocumentSchema, HeldSlotsDocumentSchema } from './heldWeaponDocuments.ts';
9
9
  import { HeldBowFileSchema, HeldFirearmPageSchema } from './weaponProfiles.ts';
10
10
  import { WaterWorldSchema } from './waterWorld.ts';
11
+ import { currentSchemaSource } from './schema-source.ts';
11
12
  import { ForestNativeInputsSchema } from './forestNativeInputs.ts';
12
13
  import { CaveFileSchema, CaveInteriorSchema } from './caveInterior.ts';
13
14
  import { ForestGroundLayoutSchema, ForestPageSchema, LivingPageSitesSchema } from './forestPage.ts';
@@ -224,9 +225,8 @@ export const PLATFORM_FILE_FAMILIES: readonly PlatformFileFamily[] = [
224
225
  source: '@wildshard/format/questInteractions#QuestPageInteractionsSchema', reader: 'src/game/quest/pageComposition.ts' },
225
226
  { pattern: /^quests\/services\.json$/u, schema: QuestServiceActionsSchema,
226
227
  source: '@wildshard/format/questSteps#QuestServiceActionsSchema', reader: 'src/game/quest/effects.ts' },
227
- // SA23: the source string is shard file data (each file's `jsonSchema.$comment`), so it keeps the old module name.
228
228
  { pattern: /^directors\/main\.json$/u, schema: DirectorDocumentSchema,
229
- source: '@wildshard/format/directorProduct#DirectorProductSchema', reader: 'src/game/plugin/director.ts' },
229
+ source: '@wildshard/format/directorDocument#DirectorDocumentSchema', reader: 'src/game/plugin/director.ts' },
230
230
  { pattern: /^quests\/panels\.json$/u, schema: QuestPanelCatalogueSchema,
231
231
  source: '@wildshard/format/panelTemplate#QuestPanelCatalogueSchema', reader: 'src/game/ui/dataPanels.ts' },
232
232
  { pattern: /^world\/forest-weather\.json$/u, schema: ForestWeatherSchema,
@@ -283,7 +283,7 @@ export const PLATFORM_FILE_FAMILIES: readonly PlatformFileFamily[] = [
283
283
  /** Match both logical name and defining schema identity. An unregistered or
284
284
  * differently typed named JSON remains custom, even under a shared prefix. */
285
285
  export function platformFileFamily(name: string, schemaSource: string | undefined): PlatformFileFamily | undefined {
286
- const matches = PLATFORM_FILE_FAMILIES.filter(family => family.source === schemaSource && family.pattern.test(name));
286
+ const matches = PLATFORM_FILE_FAMILIES.filter(family => family.source === currentSchemaSource(schemaSource) && family.pattern.test(name));
287
287
  if (matches.length > 1) throw new Error(`Ambiguous platform file family: ${name}`);
288
288
  return matches[0];
289
289
  }
@@ -0,0 +1,95 @@
1
+ /* oxlint-disable id-length, import/exports-last, import/group-exports, max-params, max-statements, no-magic-numbers -- x0/z1/x/z are the format's own bound field names and outerFloor keeps engine's (rows, floor, x, z) shape (SHARD-COMPAT PR6c) */
2
+ // SHARD-COMPAT PR6c (J487): a shard's play area (its x/z box and the fall floor at each spot) from the manifest's bounds
3
+ // under the `client/plan` rows that override them, so the page, the room and the MMO server read one rule without engine
4
+ // code. Moved from engine `src/shared/game/shardfile/playArea.ts` (SERVER-PARITY SS6): `player.enter` replaces the
5
+ // authored bounds (Sky Reach: floor -8, 250 m each way), `world.runtime-hooks` keeps the authored floor near the middle
6
+ // and drops it past a radius (Nine Dragon: -20 past 200 m), and the hooks win when a shard has both.
7
+
8
+ /** A rectangle and its fall floor, as a manifest or `player.enter` declares it. */
9
+ export interface PlayBounds {
10
+ readonly x0: number
11
+ readonly x1: number
12
+ readonly z0: number
13
+ readonly z1: number
14
+ readonly floor: number
15
+ }
16
+
17
+ /** A `world.runtime-hooks` play area: its x/z, and the floor past `maxAbsXZ` from the origin. */
18
+ export interface RuntimeBoundsRows {
19
+ readonly x: readonly [number, number]
20
+ readonly z: readonly [number, number]
21
+ readonly outer: { readonly maxAbsXZ: number; readonly floor: number }
22
+ }
23
+
24
+ /** One `client/plan` feature row, as far as the play area reads it. */
25
+ export interface PlayAreaFeature {
26
+ readonly kind: string
27
+ readonly bounds?: PlayBounds | RuntimeBoundsRows
28
+ }
29
+
30
+ /** Where a player may stand in a shard: an x/z box, and the fall floor at each spot in it. */
31
+ export interface PlayArea {
32
+ readonly x0: number
33
+ readonly x1: number
34
+ readonly z0: number
35
+ readonly z1: number
36
+ readonly floorAt: (x: number, z: number) => number
37
+ }
38
+
39
+ /** The floor at (x, z) under a runtime-hooks area: the authored floor inside `maxAbsXZ`, the outer floor past it. */
40
+ export function outerFloor(
41
+ rows: RuntimeBoundsRows,
42
+ authored: number,
43
+ x: number,
44
+ z: number,
45
+ ): number {
46
+ return Math.max(Math.abs(x), Math.abs(z)) > rows.outer.maxAbsXZ
47
+ ? rows.outer.floor
48
+ : authored
49
+ }
50
+
51
+ const isRuntime = (
52
+ bounds: PlayBounds | RuntimeBoundsRows,
53
+ ): bounds is RuntimeBoundsRows => 'outer' in bounds
54
+
55
+ /** The play area the page selects for `authored` (the manifest's bounds) under the shard's `client/plan` features, or
56
+ * none. The runtime hooks install after `player.enter`, so theirs wins when a shard has both. */
57
+ export function declaredPlayArea(
58
+ authored: PlayBounds | undefined,
59
+ features: readonly PlayAreaFeature[],
60
+ ): PlayArea | undefined {
61
+ let enter: PlayBounds | undefined = undefined
62
+ let hooks: RuntimeBoundsRows | undefined = undefined
63
+ for (const { kind, bounds } of features) {
64
+ if (bounds !== undefined && kind === 'player.enter' && !isRuntime(bounds)) {
65
+ enter = bounds
66
+ } else if (
67
+ bounds !== undefined &&
68
+ kind === 'world.runtime-hooks' &&
69
+ isRuntime(bounds)
70
+ ) {
71
+ hooks = bounds
72
+ }
73
+ }
74
+ if (hooks !== undefined) {
75
+ // The page's hook keeps no area for a level that authors none (`runtimeLevelBounds`).
76
+ if (authored === undefined) {
77
+ return undefined
78
+ }
79
+ const rows = hooks
80
+ const { floor } = authored
81
+ return {
82
+ x0: rows.x[0],
83
+ x1: rows.x[1],
84
+ z0: rows.z[0],
85
+ z1: rows.z[1],
86
+ floorAt: (x: number, z: number): number => outerFloor(rows, floor, x, z),
87
+ }
88
+ }
89
+ const bounds = enter ?? authored
90
+ if (bounds === undefined) {
91
+ return undefined
92
+ }
93
+ const { x0, x1, z0, z1, floor } = bounds
94
+ return { x0, x1, z0, z1, floorAt: (): number => floor }
95
+ }
@@ -1,6 +1,8 @@
1
1
  import { zoneArmed } from './memory-armed.ts'
2
2
  import { MEMORY_EPOCH } from './memory-epoch.ts'
3
3
 
4
+ import type { ZoneRef } from './memory-armed.ts'
5
+
4
6
  /**
5
7
  * SHARD-COMPAT CP10 (J486 D1.1, Jake 2026-11-21): memory lines, budgets and runtime targets judge a shard file once,
6
8
  * at upload. The API stores this verdict and its rule version (the memory epoch) beside the original; a stored
@@ -10,6 +12,13 @@ import { MEMORY_EPOCH } from './memory-epoch.ts'
10
12
  */
11
13
  type Judged = 'upload' | 'stored'
12
14
 
15
+ /** How admission judges a shard: CP10's `judged`, and FP27b's `armed`, the API catalogue's armed state for it (absent,
16
+ * the format's own list decides until FP27c removes it). */
17
+ interface JudgedPorts {
18
+ readonly judged?: Judged | undefined
19
+ readonly armed?: boolean | ReadonlySet<string> | undefined
20
+ }
21
+
13
22
  interface PolicyIssue {
14
23
  readonly code: string
15
24
  readonly metric: string
@@ -29,14 +38,14 @@ interface PolicyVerdict {
29
38
  }
30
39
 
31
40
  function policyVerdict(
32
- slug: string | undefined,
41
+ zone: ZoneRef,
33
42
  judged: Judged,
34
43
  issues: readonly PolicyIssue[],
35
44
  ): PolicyVerdict {
36
45
  return {
37
46
  judged,
38
47
  epoch: MEMORY_EPOCH,
39
- armed: zoneArmed(slug),
48
+ armed: zoneArmed(zone),
40
49
  issues: issues.map(
41
50
  ({ code, metric, actual, limit, severity }): PolicyIssue => ({
42
51
  code,
@@ -85,6 +94,7 @@ function admittedVerdict(shard: Readonly<object>): PolicyVerdict {
85
94
  }
86
95
 
87
96
  export {
97
+ type JudgedPorts,
88
98
  type Judged,
89
99
  type PolicyIssue,
90
100
  type PolicyVerdict,
@@ -0,0 +1,100 @@
1
+ /** The checks `requireCookPreparation` runs on a prepared file (SHARD-COMPAT PR4 and PR5, J487): the preparation
2
+ * marker against `cook.json`'s spec, the fence and the programs mount. */
3
+ import { isPreparationSpec, preparationSpecOf } from './preparation-spec.ts'
4
+ import { validationSourceBytes } from './validationReceipt.ts'
5
+
6
+ import type { AnyPrograms } from './cook-preparation.ts'
7
+ import type { OutputIndex } from './outputIndex.ts'
8
+
9
+ type Frozen<Value> = Value extends object
10
+ ? { readonly [Key in keyof Value]: Frozen<Value[Key]> }
11
+ : Value
12
+
13
+ /** Shared by admission and the cook. Legacy sdk 0.2 is an explicit migration boundary. */
14
+ function fenceValid(
15
+ index: Frozen<OutputIndex>,
16
+ lists: Readonly<{
17
+ fence: readonly string[]
18
+ mounts: readonly Readonly<{ hash: string }>[]
19
+ }>,
20
+ fix: string,
21
+ ): void {
22
+ const known = new Set<string>()
23
+ for (const file of index.files) {
24
+ known.add(file.hash)
25
+ }
26
+ for (const mount of lists.mounts) {
27
+ known.add(mount.hash)
28
+ }
29
+ for (const row of lists.fence) {
30
+ if (!known.has(row) && !index.requires.commons.includes(row)) {
31
+ throw new Error(`stale fence preparation: run ${fix}`)
32
+ }
33
+ }
34
+ }
35
+ function programMountValid(
36
+ index: Frozen<OutputIndex>,
37
+ cook: {
38
+ readonly programs?: AnyPrograms
39
+ readonly mounts: readonly Readonly<{ url: string; hash: string }>[]
40
+ },
41
+ digest: (bytes: Readonly<Uint8Array>) => string,
42
+ ): void {
43
+ const url = `/programs/${index.identity.slug}.json`
44
+ const mount = cook.mounts.find(
45
+ (row: Readonly<{ url: string; hash: string }>): boolean => row.url === url,
46
+ )
47
+ if (
48
+ cook.programs === undefined ||
49
+ mount?.hash !== digest(validationSourceBytes(cook.programs))
50
+ ) {
51
+ throw new Error(
52
+ `stale GLSL program mount: run wildshard prepare <folder> --base <exact-preview-url> (${index.identity.slug})`,
53
+ )
54
+ }
55
+ }
56
+ function failureOf(run: () => void): string | undefined {
57
+ try {
58
+ run()
59
+ return undefined
60
+ } catch (error: unknown) {
61
+ return error instanceof Error ? error.message : String(error)
62
+ }
63
+ }
64
+ const MISMATCH = 'mismatch'
65
+ /** Why the marker and `cook.json` disagree, or `undefined` when they agree. */
66
+ function markerRefusal(
67
+ spec: number | undefined,
68
+ prepared: boolean,
69
+ noMarker: boolean,
70
+ ): string | undefined {
71
+ if (spec === undefined) {
72
+ return prepared && noMarker
73
+ ? 'cook.json is prepared but shard.json names no preparation spec'
74
+ : undefined
75
+ }
76
+ return prepared ? MISMATCH : 'Missing cook preparation'
77
+ }
78
+ /** PR4: whether the file is prepared, holding `shard.json`'s spec and `cook.json`'s version to each other. */
79
+ function preparationMarked(
80
+ index: Readonly<{ sdk?: unknown; preparation?: unknown }>,
81
+ version: number | undefined,
82
+ fix: string,
83
+ ): boolean {
84
+ const spec = preparationSpecOf(index)
85
+ const prepared = isPreparationSpec(version)
86
+ const refusal =
87
+ spec !== undefined && version === spec
88
+ ? undefined
89
+ : markerRefusal(spec, prepared, index.sdk === undefined)
90
+ if (refusal !== undefined) {
91
+ throw new Error(
92
+ refusal === MISMATCH
93
+ ? `shard.json names preparation spec ${String(spec)}, cook.json is spec ${String(version)}: run ${fix}`
94
+ : `${refusal}: run ${fix}`,
95
+ )
96
+ }
97
+ return spec !== undefined || prepared
98
+ }
99
+
100
+ export { failureOf, fenceValid, preparationMarked, programMountValid }
@@ -0,0 +1,45 @@
1
+ /** The preparation spec version (SHARD-COMPAT PR4, J487): one number owned by this package, beside the format
2
+ * version. A prepared file records it in `shard.json` `preparation` (format 0.1.0.3 on) and as `cook.json`'s
3
+ * `version`; it names no engine release. Spec 3 still carries the engine renderer fingerprint and program build;
4
+ * spec 4 drops both. See `docs/preparation.md`. */
5
+
6
+ /** `cook.json` version 3: the legacy spec, bound to the engine renderer that recorded it. */
7
+ const LEGACY_PREPARATION_SPEC = 3
8
+ /** The spec a freshly prepared file is made to: no renderer fingerprint, programs with no engine build. */
9
+ const PREPARATION_SPEC = 4
10
+ /** Every preparation spec version a reader of this package accepts. */
11
+ const PREPARATION_SPECS: readonly [
12
+ typeof LEGACY_PREPARATION_SPEC,
13
+ typeof PREPARATION_SPEC,
14
+ ] = [LEGACY_PREPARATION_SPEC, PREPARATION_SPEC] as const
15
+ type PreparationSpec = (typeof PREPARATION_SPECS)[number]
16
+ /** The legacy `sdk` marker's prepared value, which always meant spec 3. */
17
+ const PREPARED_SDK = '0.3'
18
+
19
+ /** Whether `version` is a preparation spec this package reads (a prepared `cook.json`). */
20
+ function isPreparationSpec(version: unknown): version is PreparationSpec {
21
+ return PREPARATION_SPECS.some(
22
+ (spec: PreparationSpec): boolean => spec === version,
23
+ )
24
+ }
25
+
26
+ /** The preparation spec a `shard.json` records: `preparation` from format 0.1.0.3, the legacy `sdk: '0.3'` marker as
27
+ * spec 3 before it, `undefined` for an unprepared file. */
28
+ function preparationSpecOf(
29
+ index: Readonly<{ sdk?: unknown; preparation?: unknown }>,
30
+ ): PreparationSpec | undefined {
31
+ if (isPreparationSpec(index.preparation)) {
32
+ return index.preparation
33
+ }
34
+ return index.sdk === PREPARED_SDK ? LEGACY_PREPARATION_SPEC : undefined
35
+ }
36
+
37
+ export {
38
+ LEGACY_PREPARATION_SPEC,
39
+ PREPARATION_SPEC,
40
+ PREPARATION_SPECS,
41
+ PREPARED_SDK,
42
+ type PreparationSpec,
43
+ isPreparationSpec,
44
+ preparationSpecOf,
45
+ }
@@ -128,7 +128,7 @@ export interface RegisteredJsonContracts {
128
128
  readonly 'world/dressing-phone.json':{readonly schema:typeof SceneDressingSchema;readonly source:'@wildshard/format/sceneDressing#SceneDressingSchema'};
129
129
  readonly 'world/building-sites.json':{readonly schema:typeof LivingPageSitesSchema;readonly source:'@wildshard/format/forestPage#LivingPageSitesSchema'};
130
130
  readonly 'models/shape-book.json':{readonly schema:typeof FixedDrawRowsSchema;readonly source:'@wildshard/format/fixedDraws#FixedDrawRowsSchema'};
131
- readonly 'directors/main.json':{readonly schema:typeof DirectorDocumentSchema;readonly source:'@wildshard/format/directorProduct#DirectorProductSchema'};
131
+ readonly 'directors/main.json':{readonly schema:typeof DirectorDocumentSchema;readonly source:'@wildshard/format/directorDocument#DirectorDocumentSchema'};
132
132
  readonly 'scenes/cascade.json':{readonly schema:typeof WorldSceneSchema;readonly source:'@wildshard/format/clientChannels#WorldSceneSchema'};
133
133
  readonly 'scenes/cove.json':{readonly schema:typeof WorldSceneSchema;readonly source:'@wildshard/format/clientChannels#WorldSceneSchema'};
134
134
  readonly 'scenes/hibiscus.json':{readonly schema:typeof WorldSceneSchema;readonly source:'@wildshard/format/clientChannels#WorldSceneSchema'};
@@ -250,7 +250,7 @@ export const REGISTERED_JSON:RegisteredJsonContracts = {
250
250
  'world/dressing-phone.json':{schema:SceneDressingSchema,source:'@wildshard/format/sceneDressing#SceneDressingSchema'},
251
251
  'world/building-sites.json':{schema:LivingPageSitesSchema,source:'@wildshard/format/forestPage#LivingPageSitesSchema'},
252
252
  'models/shape-book.json':{schema:FixedDrawRowsSchema,source:'@wildshard/format/fixedDraws#FixedDrawRowsSchema'},
253
- 'directors/main.json':{schema:DirectorDocumentSchema,source:'@wildshard/format/directorProduct#DirectorProductSchema'},
253
+ 'directors/main.json':{schema:DirectorDocumentSchema,source:'@wildshard/format/directorDocument#DirectorDocumentSchema'},
254
254
  'scenes/cascade.json':{schema:WorldSceneSchema,source:'@wildshard/format/clientChannels#WorldSceneSchema'},
255
255
  'scenes/cove.json':{schema:WorldSceneSchema,source:'@wildshard/format/clientChannels#WorldSceneSchema'},
256
256
  'scenes/hibiscus.json':{schema:WorldSceneSchema,source:'@wildshard/format/clientChannels#WorldSceneSchema'},
@@ -1,5 +1,5 @@
1
1
  import { UNNAMED_TIER, budgetTierLimits } from './budget-tiers.ts'
2
- import { ratchetNote, ratchetSeverity } from './memory-armed.ts'
2
+ import { armedZone, ratchetNote, ratchetSeverity } from './memory-armed.ts'
3
3
  import { runtimeAccountedBytes } from './runtimeCost.ts'
4
4
 
5
5
  import type { BudgetTier } from './budget-tiers.ts'
@@ -24,7 +24,10 @@ interface RuntimeTierIssue {
24
24
  * ONE-FORMAT OF10c1a and J445: report a runtime's accounted bytes above its
25
25
  * named memory tier. A runtime with no named tier uses the large target.
26
26
  */
27
- function runtimeTierIssues(source: RuntimeTierSource): RuntimeTierIssue[] {
27
+ function runtimeTierIssues(
28
+ source: RuntimeTierSource,
29
+ armed?: boolean | ReadonlySet<string>,
30
+ ): RuntimeTierIssue[] {
28
31
  const cost = source.runtime?.cost ?? source.budgets.client
29
32
  if (source.runtime === null || cost === undefined) {
30
33
  return []
@@ -35,14 +38,18 @@ function runtimeTierIssues(source: RuntimeTierSource): RuntimeTierIssue[] {
35
38
  if (actual <= limit) {
36
39
  return []
37
40
  }
38
- const severity = ratchetSeverity(source.identity?.slug, 'runtime', {
39
- line: limit,
40
- actual,
41
- })
41
+ const severity = ratchetSeverity(
42
+ armedZone(source.identity?.slug, armed),
43
+ 'runtime',
44
+ {
45
+ line: limit,
46
+ actual,
47
+ },
48
+ )
42
49
  return [
43
50
  {
44
51
  code: 'runtime-tier-memory',
45
- metric: `runtime accounted bytes over the ${tier} tier's memory (OF10c1a: name a larger tier or shrink the runtime)${severity === 'warning' ? ratchetNote(source.identity?.slug) : ''}`,
52
+ metric: `runtime accounted bytes over the ${tier} tier's memory (OF10c1a: name a larger tier or shrink the runtime)${severity === 'warning' ? ratchetNote(armedZone(source.identity?.slug, armed)) : ''}`,
46
53
  actual,
47
54
  limit,
48
55
  severity,
@@ -0,0 +1,105 @@
1
+ import { validationSourceBytes } from './validationReceipt.ts'
2
+ import { writesSaveRevision } from './version.ts'
3
+
4
+ /** FORMAT-PRUNE FP26 (J493): from format 0.1.0.4 the save lineage `identity.revision` is spelled `identity.saveRevision`. */
5
+ const SAVE_REVISION = '0.1.0.4'
6
+
7
+ function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
8
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
9
+ }
10
+
11
+ /** A copy of `row` with its key `from` named `to`, every other key as it is. */
12
+ function renamedKey(
13
+ row: Readonly<Record<string, unknown>>,
14
+ from: string,
15
+ to: string,
16
+ ): Record<string, unknown> {
17
+ const entries = Object.entries(row)
18
+ const renamed = entries.map(
19
+ ([key, item]: readonly [string, unknown]): readonly [string, unknown] => [
20
+ key === from ? to : key,
21
+ item,
22
+ ],
23
+ )
24
+ return Object.fromEntries(renamed)
25
+ }
26
+
27
+ /** FP26: what a file's hashes cover keeps the identity as its format wrote it. Below 0.1.0.4 that is `revision`: the
28
+ * source hash and the cook preparation's inputs were taken over those bytes, so an older file still matches its own.
29
+ * `formatVersion` is the index's (`2` for the legacy envelope). */
30
+ function asWrittenIdentity(value: object, formatVersion: unknown): unknown {
31
+ if (typeof formatVersion === 'string' && writesSaveRevision(formatVersion)) {
32
+ return value
33
+ }
34
+ const identity: unknown = Reflect.get(value, 'identity')
35
+ if (!isRecord(identity) || !Object.hasOwn(identity, 'saveRevision')) {
36
+ return value
37
+ }
38
+ return {
39
+ ...value,
40
+ identity: renamedKey(identity, 'saveRevision', 'revision'),
41
+ }
42
+ }
43
+
44
+ interface SaveRevisionSpellings<Revision> {
45
+ readonly saveRevision?: Revision
46
+ readonly revision?: Revision
47
+ }
48
+
49
+ /** FP26: a row gives exactly one spelling of the save lineage. */
50
+ function oneSaveRevisionSpelling<Revision>(
51
+ row: Readonly<SaveRevisionSpellings<Revision>>,
52
+ ): boolean {
53
+ return (row.saveRevision === undefined) !== (row.revision === undefined)
54
+ }
55
+
56
+ /** FP26: the save lineage, under whichever spelling the row gave it. */
57
+ function saveRevisionOf<Revision>(
58
+ row: Readonly<SaveRevisionSpellings<Revision>>,
59
+ ): Revision {
60
+ const value = row.saveRevision ?? row.revision
61
+ if (value === undefined) {
62
+ throw new Error(
63
+ 'The identity needs exactly one of saveRevision or revision',
64
+ )
65
+ }
66
+ return value
67
+ }
68
+
69
+ /** The deprecation row for the old spelling (`deprecations.ts` lists it). */
70
+ interface SaveRevisionDeprecation {
71
+ readonly id: string
72
+ readonly path: string
73
+ readonly since: string
74
+ readonly replacement: string
75
+ readonly migration: string
76
+ readonly uses: (shard: Readonly<{ index: unknown }>) => boolean
77
+ }
78
+
79
+ /** FP26: the canonical bytes a source hash covers, the identity spelled as `formatVersion` wrote it. */
80
+ function writtenSourceBytes(value: object, formatVersion: unknown): Uint8Array {
81
+ return validationSourceBytes(asWrittenIdentity(value, formatVersion))
82
+ }
83
+
84
+ const SAVE_REVISION_DEPRECATION: SaveRevisionDeprecation = {
85
+ id: 'identity.revision',
86
+ path: 'shard.json identity.revision, the save lineage (FORMAT-PRUNE FP26, J493)',
87
+ since: SAVE_REVISION,
88
+ replacement:
89
+ 'identity.saveRevision: the same number under its own name, so it is never read as the API shard revision',
90
+ migration: 'fp26-save-revision',
91
+ uses: (shard: Readonly<{ index: unknown }>): boolean => {
92
+ const identity: unknown = isRecord(shard.index)
93
+ ? shard.index['identity']
94
+ : undefined
95
+ return isRecord(identity) && identity['revision'] !== undefined
96
+ },
97
+ }
98
+
99
+ export {
100
+ SAVE_REVISION_DEPRECATION,
101
+ asWrittenIdentity,
102
+ oneSaveRevisionSpelling,
103
+ saveRevisionOf,
104
+ writtenSourceBytes,
105
+ }
@@ -0,0 +1,70 @@
1
+ /** FORMAT-PRUNE FP10: each named JSON file's `jsonSchema.$comment` names the format module that defines it. A module
2
+ * renamed after files shipped leaves a stale id in shard data; the chain step `fp10-schema-source` rewrites it, and
3
+ * until every kept file is mended (FE7 counts `schema-source.retired`), readers take the old id as the new one. The
4
+ * map empties, and this file goes, at FP22. */
5
+
6
+ /** Retired id to current id. */
7
+ const RETIRED_SCHEMA_SOURCES: Readonly<Record<string, string>> = {
8
+ // SA23 kept the old id because it was shard data; the module is directorDocument.
9
+ '@wildshard/format/directorProduct#DirectorProductSchema':
10
+ '@wildshard/format/directorDocument#DirectorDocumentSchema',
11
+ }
12
+
13
+ /** The current id for `source`, retired or not. */
14
+ function currentSchemaSource(source: unknown): unknown {
15
+ if (
16
+ typeof source === 'string' &&
17
+ Object.hasOwn(RETIRED_SCHEMA_SOURCES, source)
18
+ ) {
19
+ return RETIRED_SCHEMA_SOURCES[source]
20
+ }
21
+ return source
22
+ }
23
+
24
+ /** Whether `source` is a retired id. */
25
+ function retiredSchemaSource(source: unknown): boolean {
26
+ return (
27
+ typeof source === 'string' && Object.hasOwn(RETIRED_SCHEMA_SOURCES, source)
28
+ )
29
+ }
30
+
31
+ /** FE7's row for FP10, in the registry's shape (`deprecations.ts`). */
32
+ interface SchemaSourceDeprecation {
33
+ readonly id: string
34
+ readonly path: string
35
+ readonly since: string
36
+ readonly replacement: string
37
+ readonly migration: string
38
+ readonly uses: (shard: Readonly<{ index: unknown }>) => boolean
39
+ }
40
+
41
+ function field(value: unknown, key: string): unknown {
42
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
43
+ ? Reflect.get(value, key)
44
+ : undefined
45
+ }
46
+
47
+ const SCHEMA_SOURCE_DEPRECATION: SchemaSourceDeprecation = {
48
+ id: 'schema-source.retired',
49
+ path: 'shard.json files[].jsonSchema.$comment naming a retired module (FORMAT-PRUNE FP10)',
50
+ since: '0.1.0.4',
51
+ replacement:
52
+ 'the current defining module, e.g. @wildshard/format/directorDocument#DirectorDocumentSchema',
53
+ migration: 'fp10-schema-source',
54
+ uses: (shard: Readonly<{ index: unknown }>): boolean => {
55
+ const files = field(shard.index, 'files')
56
+ return (
57
+ Array.isArray(files) &&
58
+ files.some((file: unknown): boolean =>
59
+ retiredSchemaSource(field(field(file, 'jsonSchema'), '$comment')),
60
+ )
61
+ )
62
+ },
63
+ }
64
+
65
+ export {
66
+ RETIRED_SCHEMA_SOURCES,
67
+ SCHEMA_SOURCE_DEPRECATION,
68
+ currentSchemaSource,
69
+ retiredSchemaSource,
70
+ }
@@ -10,6 +10,7 @@ import type { ToonLookRow } from './toonLook.ts';
10
10
  import type { KeyedSkyStyle } from './keyedSky.ts';
11
11
  import type { SpawnScriptRows } from './spawnScripts.ts';
12
12
  import type { ClientPlan } from './clientPlan.ts';
13
+ import type { ServerPlan } from './server-plan.ts';
13
14
  import type { NativeSweptPolicyRows } from './items.ts';
14
15
  import type { ReturnModuleRow, ViewModuleRow } from './scriptContract.ts';
15
16
  import type { WorldScenesSection } from './worldScenes.ts';
@@ -63,6 +64,8 @@ export interface PlatformSections {
63
64
  'look/keyed-sky': KeyedSkyStyle;
64
65
  /** Client-only compiled feature declarations; ignored by the authoritative simulation. */
65
66
  'client/plan': ClientPlan;
67
+ /** SHARD-COMPAT HS6b: the feature rows the server reads, written beside `client/plan` so the page's plan is the page's. */
68
+ 'server/plan': ServerPlan;
66
69
  'held/arms': HeldArmsRows;
67
70
  'held/gear': HeldGearRows;
68
71
  'held/finishes': HeldFinishesRows;
@@ -75,7 +78,7 @@ export interface PlatformSections {
75
78
  'sim/runtime-plan': NativeRuntimePlanData;
76
79
  'world/tiles': Pick<Shardfile, 'tiles' | 'far' | 'near' | 'ring'>;
77
80
  'world/terrain': Pick<Shardfile, 'terrain' | 'nativeGround'>;
78
- 'world/edge': Pick<Shardfile, 'edge' | 'entryways'>;
81
+ 'world/edge': Pick<Shardfile, 'edge' | 'entryways' | 'edgeObservations'>;
79
82
  'world/collision': Pick<Shardfile, 'meshCollision'>;
80
83
  'world/navigation': Pick<Shardfile, 'navigation'>;
81
84
  'world/props': Pick<Shardfile, 'props'>;
@@ -0,0 +1,42 @@
1
+ /** SHARD-COMPAT HS6b (meta): `server/plan`, the server's own copy of the feature rows, so `client/plan` stays the page's.
2
+ * The SDK writes it from the parsed `client/plan` (HS6d) and the engine's server parses each row with the client plan's
3
+ * own schema at its seam (HS6c); here it is held to the shape that projects to JSON Schema (FP9): a version and up to 64
4
+ * rows, each naming its kind. */
5
+ import {
6
+ array,
7
+ literal,
8
+ looseObject,
9
+ maxLength,
10
+ pipe,
11
+ strictObject,
12
+ string,
13
+ } from 'valibot'
14
+
15
+ import type { GenericSchema } from 'valibot'
16
+
17
+ /** The section's only version. */
18
+ const VERSION = 1
19
+ /** The most feature rows a plan holds, as `client/plan`'s schema caps them. */
20
+ const MAX_FEATURES = 64
21
+
22
+ /** One feature row as the section holds it: its kind and its settings. */
23
+ interface ServerPlanRow {
24
+ readonly kind: string
25
+ readonly [key: string]: unknown
26
+ }
27
+
28
+ /** The section's value. */
29
+ interface ServerPlan {
30
+ readonly version: typeof VERSION
31
+ readonly features: readonly ServerPlanRow[]
32
+ }
33
+
34
+ const RowSchema = looseObject({ kind: string() })
35
+ const RowsSchema = pipe(array(RowSchema), maxLength(MAX_FEATURES))
36
+
37
+ const ServerPlanSchema: GenericSchema<unknown, ServerPlan> = strictObject({
38
+ version: literal(VERSION),
39
+ features: RowsSchema,
40
+ })
41
+
42
+ export { type ServerPlan, type ServerPlanRow, ServerPlanSchema }