@wildshard/shard-format 0.74.1 → 0.76.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.74.1",
3
+ "version": "0.76.0",
4
4
  "description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -124,6 +124,7 @@
124
124
  "./fur-strands": "./src/format/fur-strands.ts",
125
125
  "./scene-render": "./src/format/scene-render.ts",
126
126
  "./look-level": "./src/format/look-level.ts",
127
+ "./engine-floor": "./src/format/engine-floor.ts",
127
128
  "./level-start": "./src/format/level-start.ts",
128
129
  "./level-start-rows": "./src/format/level-start-rows.ts",
129
130
  "./look-sky": "./src/format/look-sky.ts",
@@ -4,8 +4,6 @@ import { MarkedBossPresentationSchema } from './bossProfiles.ts';
4
4
 
5
5
  const finite = v.pipe(v.number(), v.finite());
6
6
  const id = v.pipe(v.string(), v.minLength(1), v.maxLength(128));
7
- const count = v.pipe(finite, v.integer(), v.minValue(0), v.maxValue(4096));
8
- const ids = v.pipe(v.array(id), v.maxLength(1024), v.check(rows => new Set(rows).size === rows.length, 'Unique owner ids'));
9
7
  const home = v.strictObject({ x: finite, y: finite, z: finite, r: v.pipe(finite, v.minValue(Number.MIN_VALUE)) });
10
8
  const capture = v.union([
11
9
  v.strictObject({ flag: id }), v.strictObject({ action: id }),
@@ -41,17 +39,6 @@ export const ClientQuestPageSchema: v.StrictObjectSchema<{ readonly kind: v.Gene
41
39
  endpoints: v.optional(v.pipe(v.array(v.strictObject({ mover: id, stage: id, toast: v.exactOptional(v.pipe(v.string(), v.maxLength(4096))) })), v.maxLength(64)), []),
42
40
  capture: v.optional(v.pipe(v.record(id, v.pipe(v.array(capture), v.maxLength(64))), v.maxEntries(64)), {}),
43
41
  });
44
- /** Native body allocation/refill policy; placement rows retain their original
45
- * identities in sim/runtime-plan rather than introducing a second roster. */
46
- export const ClientPopulationSchema: v.StrictObjectSchema<{ readonly kind: v.GenericSchema<ClientPopulationRowsInput['kind'], ClientPopulationRows['kind']>; readonly system: v.GenericSchema<ClientPopulationRowsInput['system'], ClientPopulationRows['system']>; readonly held: v.ExactOptionalSchema<v.GenericSchema<Exclude<ClientPopulationRowsInput['held'], undefined>, Exclude<ClientPopulationRows['held'], undefined>>, undefined>; readonly bodyHomes: v.OptionalSchema<v.GenericSchema<Exclude<ClientPopulationRowsInput['bodyHomes'], undefined>, Exclude<ClientPopulationRows['bodyHomes'], undefined>>, readonly []>; readonly holds: v.ExactOptionalSchema<v.GenericSchema<Exclude<ClientPopulationRowsInput['holds'], undefined>, Exclude<ClientPopulationRows['holds'], undefined>>, undefined>; readonly groups: v.OptionalSchema<v.GenericSchema<Exclude<ClientPopulationRowsInput['groups'], undefined>, Exclude<ClientPopulationRows['groups'], undefined>>, Record<never, never>>; readonly witness: v.GenericSchema<ClientPopulationRowsInput['witness'], ClientPopulationRows['witness']>; }, undefined> = v.strictObject({ kind: v.literal('population.homes'), system: id,
47
- held: v.exactOptional(v.strictObject({ order: ids, settle: id,
48
- placements: v.optional(v.pipe(v.array(v.strictObject({ id, fromY: finite, y: finite })), v.maxLength(1024)), []),
49
- })),
50
- bodyHomes: v.optional(v.pipe(v.array(v.strictObject({ id, home })), v.maxLength(1024)), []),
51
- holds: v.exactOptional(v.strictObject({ system: id, rows: v.pipe(v.array(v.strictObject({ home: count, field: id, until: id })), v.maxLength(1024)) })),
52
- groups: v.optional(v.pipe(v.record(id, ids), v.maxEntries(64)), {}),
53
- witness: v.union([v.strictObject({ groups: ids }), v.strictObject({ kinds: ids })]),
54
- });
55
42
  /** Browser presentation borrows the actual encounter definition, profile,
56
43
  * director and victory policy already admitted by sim/runtime-plan. */
57
44
  const bossFight = { actor: id,
@@ -200,80 +187,6 @@ interface ClientQuestPageRowsFields {
200
187
  }))[]>;
201
188
  }
202
189
  export type ClientQuestPageRows = { [Key in keyof ClientQuestPageRowsFields]: ClientQuestPageRowsFields[Key] };
203
- interface ClientPopulationRowsInputFields {
204
- kind: 'population.homes';
205
- system: string;
206
- held?: {
207
- order: (string)[];
208
- settle: string;
209
- placements?: ({
210
- id: string;
211
- fromY: number;
212
- y: number;
213
- })[] | undefined;
214
- };
215
- bodyHomes?: ({
216
- id: string;
217
- home: {
218
- x: number;
219
- y: number;
220
- z: number;
221
- r: number;
222
- };
223
- })[] | undefined;
224
- holds?: {
225
- system: string;
226
- rows: ({
227
- home: number;
228
- field: string;
229
- until: string;
230
- })[];
231
- };
232
- groups?: Record<string, (string)[]> | undefined;
233
- witness: ({
234
- groups: (string)[];
235
- }) | ({
236
- kinds: (string)[];
237
- });
238
- }
239
- export type ClientPopulationRowsInput = { [Key in keyof ClientPopulationRowsInputFields]: ClientPopulationRowsInputFields[Key] };
240
- interface ClientPopulationRowsFields {
241
- kind: 'population.homes';
242
- system: string;
243
- held?: {
244
- order: (string)[];
245
- settle: string;
246
- placements: ({
247
- id: string;
248
- fromY: number;
249
- y: number;
250
- })[];
251
- };
252
- bodyHomes: ({
253
- id: string;
254
- home: {
255
- x: number;
256
- y: number;
257
- z: number;
258
- r: number;
259
- };
260
- })[];
261
- holds?: {
262
- system: string;
263
- rows: ({
264
- home: number;
265
- field: string;
266
- until: string;
267
- })[];
268
- };
269
- groups: Record<string, (string)[]>;
270
- witness: ({
271
- groups: (string)[];
272
- }) | ({
273
- kinds: (string)[];
274
- });
275
- }
276
- export type ClientPopulationRows = { [Key in keyof ClientPopulationRowsFields]: ClientPopulationRowsFields[Key] };
277
190
  interface ClientBossTelegraphRowsInputFields {
278
191
  kind: 'boss.telegraph';
279
192
  actor: string;
@@ -9,11 +9,11 @@ import { pageDrawsDeclaredLooks, rigLookRules } from './rig-looks.ts';
9
9
  export function clientOwnershipRules(source: Shardfile, sections: ReadonlyMap<string, unknown>): readonly string[] {
10
10
  const raw = sections.get('client/plan'), rigs = rigLookRules(source.rows.looks, sections);
11
11
  const features = raw === undefined ? [] : parseClientPlan(raw).features;
12
- const page = hasDeclaredClientPage(source), native = features.some(row => row.kind === 'population.homes');
13
- if (!page && !native) return rigs;
12
+ const page = hasDeclaredClientPage(source);
13
+ if (!page) return rigs;
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
- if (!page || source.runtime !== null) errors.push('Native client features require their typed data page owner');
16
+ if (source.runtime !== null) errors.push('Native client features require their typed data page owner');
17
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');
@@ -17,7 +17,7 @@ import { isJsonData } from './json.ts';
17
17
  import { LightEmittersSchema } from './lightEmitters.ts';
18
18
  import { EasedFieldsSchema } from './easedFields.ts';
19
19
  import { SceneMotionSchema } from './sceneMotion.ts';
20
- import { ClientHeldMeleeSchema, ClientSpeciesProgramSchema, ClientQuestPageSchema, ClientPopulationSchema, ClientHeldBossSchema, ClientSpawnedBossSchema, ClientPlayerEnterSchema, ClientBossTelegraphSchema } from './clientNative.ts';
20
+ import { ClientHeldMeleeSchema, ClientSpeciesProgramSchema, ClientQuestPageSchema, ClientHeldBossSchema, ClientSpawnedBossSchema, ClientPlayerEnterSchema, ClientBossTelegraphSchema } from './clientNative.ts';
21
21
 
22
22
  const finite=v.pipe(v.number(),v.finite()),rgb=v.tuple([finite,finite,finite]);
23
23
  const label=v.pipe(v.string(),v.minLength(1),v.maxLength(512));
@@ -135,7 +135,7 @@ export const ClientFeatureSchema: v.GenericSchema<ClientFeatureInput, ClientFeat
135
135
  v.strictObject({ kind: v.literal('world.scenes') }),
136
136
  v.strictObject({ kind: v.literal('world.baked'), rows: v.pipe(v.array(BakedTilesSchema), v.minLength(1), v.maxLength(4), v.check(rows => new Set(rows.map(row => row.id)).size === rows.length, 'unique baked tile ids')) }),
137
137
  v.strictObject({ kind: v.literal('motion.channels'), rows: SceneMotionSchema }),
138
- ClientHeldMeleeSchema, ClientSpeciesProgramSchema, ClientQuestPageSchema, ClientPopulationSchema, ClientTrailsSchema, ClientCuesSchema,
138
+ ClientHeldMeleeSchema, ClientSpeciesProgramSchema, ClientQuestPageSchema, ClientTrailsSchema, ClientCuesSchema,
139
139
  ClientHeldBossSchema, ClientSpawnedBossSchema, ClientPlayerEnterSchema, ClientBossTelegraphSchema,
140
140
  v.strictObject({ kind: v.literal('light.emitters'), rows: LightEmittersSchema }),
141
141
  v.strictObject({ kind: v.literal('weather.fields'), rows: EasedFieldsSchema, quest: id }),
@@ -207,7 +207,7 @@ export type ClientFeatureInput = { kind: 'strings.register'; } | { kind: 'conten
207
207
  | { kind: 'world.scenes'; } | { kind: 'world.baked'; rows: (v.InferInput<typeof BakedTilesSchema>)[]; } | {
208
208
  kind: 'motion.channels'; rows: v.InferInput<typeof SceneMotionSchema>; } | v.InferInput<typeof
209
209
  ClientHeldMeleeSchema> | v.InferInput<typeof ClientSpeciesProgramSchema> | v.InferInput<typeof
210
- ClientQuestPageSchema> | v.InferInput<typeof ClientPopulationSchema> | v.InferInput<typeof ClientTrailsSchema>
210
+ ClientQuestPageSchema> | v.InferInput<typeof ClientTrailsSchema>
211
211
  | v.InferInput<typeof ClientCuesSchema> | v.InferInput<typeof ClientHeldBossSchema> | v.InferInput<typeof
212
212
  ClientSpawnedBossSchema> | v.InferInput<typeof ClientPlayerEnterSchema> | v.InferInput<typeof
213
213
  ClientBossTelegraphSchema> | { kind: 'light.emitters'; rows: v.InferInput<typeof LightEmittersSchema>; } | {
@@ -271,7 +271,7 @@ export type ClientFeatureRow = { kind: 'strings.register'; } | { kind: 'content.
271
271
  boolean; }; })[]; } | { kind: 'world.scenes'; } | { kind: 'world.baked'; rows: (v.InferOutput<typeof
272
272
  BakedTilesSchema>)[]; } | { kind: 'motion.channels'; rows: v.InferOutput<typeof SceneMotionSchema>; } |
273
273
  v.InferOutput<typeof ClientHeldMeleeSchema> | v.InferOutput<typeof ClientSpeciesProgramSchema> |
274
- v.InferOutput<typeof ClientQuestPageSchema> | v.InferOutput<typeof ClientPopulationSchema> |
274
+ v.InferOutput<typeof ClientQuestPageSchema> |
275
275
  v.InferOutput<typeof ClientTrailsSchema> | v.InferOutput<typeof ClientCuesSchema> | v.InferOutput<typeof
276
276
  ClientHeldBossSchema> | v.InferOutput<typeof ClientSpawnedBossSchema> | v.InferOutput<typeof
277
277
  ClientPlayerEnterSchema> | v.InferOutput<typeof ClientBossTelegraphSchema> | { kind: 'light.emitters'; rows:
@@ -6,9 +6,10 @@ const id = v.pipe(v.string(), v.minLength(1), v.maxLength(128))
6
6
  const real = v.pipe(v.number(), v.minValue(0), v.maxValue(10000))
7
7
  const FEWEST_MEMBERS = 1
8
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)),
9
+ const members = v.pipe(
10
+ v.array(id),
11
+ v.minLength(FEWEST_MEMBERS),
12
+ v.maxLength(MOST_MEMBERS),
12
13
  )
13
14
  /** Whether no two trail rows share a system id. */
14
15
  function uniqueIds(rows: readonly Readonly<{ id: string }>[]): boolean {
@@ -17,21 +18,10 @@ function uniqueIds(rows: readonly Readonly<{ id: string }>[]): boolean {
17
18
  .size === rows.length
18
19
  )
19
20
  }
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
- }
31
- /** Client-only trails follow actual native population groups in their local
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. */
21
+ /** Client-only trails follow actual native bodies in their local world frame.
22
+ * Looks and timing are data; there are no owner callbacks. A row names the
23
+ * declared spawns it follows as `members` (ONE-FORMAT OF29e7a); the page
24
+ * population group went with `population.homes` (FORMAT-PRUNE FP43). */
35
25
  export const ClientTrailsSchema: v.StrictObjectSchema<
36
26
  {
37
27
  readonly kind: v.GenericSchema<
@@ -50,7 +40,6 @@ export const ClientTrailsSchema: v.StrictObjectSchema<
50
40
  v.array(
51
41
  v.strictObject({
52
42
  id,
53
- group,
54
43
  members,
55
44
  library: id,
56
45
  look: id,
@@ -72,10 +61,6 @@ export const ClientTrailsSchema: v.StrictObjectSchema<
72
61
  uniqueIds,
73
62
  'Unique trail systems',
74
63
  ),
75
- v.check<ClientTrailsRows['rows'], string>(
76
- oneSource,
77
- 'A trail names its group or its members',
78
- ),
79
64
  ),
80
65
  })
81
66
 
@@ -102,8 +87,7 @@ interface ClientTrailsRowsFields {
102
87
  kind: 'fx.trail'
103
88
  rows: {
104
89
  id: string
105
- group?: string
106
- members?: string[]
90
+ members: string[]
107
91
  library: string
108
92
  look: string
109
93
  name: string
@@ -29,7 +29,10 @@ import type { GenericSchema } from 'valibot'
29
29
  // `mounts` are the shard's own files that its sections and boot tables
30
30
  // name by a public URL: the bytes travel in the product under `mounts/`
31
31
  // and the cook publishes each one at its URL. `packs` and `fence` are
32
- // optional only on legacy version 1. Version 2 requires J198 preparation.
32
+ // optional only on legacy version 1, which only an unprepared draft writes
33
+ // (`wildshard build` before `wildshard prepare`). Version 2 is gone
34
+ // (FORMAT-PRUNE FP23: no kept original or engine pin used it); version 3
35
+ // on requires J198 preparation.
33
36
 
34
37
  interface CookMount {
35
38
  readonly url: string
@@ -115,36 +118,15 @@ const SpecCookDataSchema = strictObject({
115
118
  ...CookSpecPreparationSchema.entries,
116
119
  mounts: mountRows,
117
120
  })
118
- const PREVIOUS_COOK_VERSION = 2
119
- const PreviousCookDataSchema = strictObject({
120
- version: literal(PREVIOUS_COOK_VERSION),
121
- inputHash: CookPreparationSchema.entries.inputHash,
122
- packs: CookPreparationSchema.entries.packs,
123
- fence: CookPreparationSchema.entries.fence,
124
- programs: CookPreparationSchema.entries.programs,
125
- mounts: mountRows,
126
- })
127
- interface PreviousCookData extends Omit<
128
- CookPreparation,
129
- 'version' | 'renderer'
130
- > {
131
- readonly version: typeof PREVIOUS_COOK_VERSION
132
- readonly mounts: readonly CookMount[]
133
- }
134
121
  interface PreparedCookData extends CookPreparation {
135
122
  readonly mounts: readonly CookMount[]
136
123
  }
137
124
  interface SpecCookData extends CookSpecPreparation {
138
125
  readonly mounts: readonly CookMount[]
139
126
  }
140
- type CookData =
141
- | LegacyCookData
142
- | PreviousCookData
143
- | PreparedCookData
144
- | SpecCookData
127
+ type CookData = LegacyCookData | PreparedCookData | SpecCookData
145
128
  const CookDataSchema: GenericSchema<unknown, CookData> = variant('version', [
146
129
  LegacyCookDataSchema,
147
- PreviousCookDataSchema,
148
130
  PreparedCookDataSchema,
149
131
  SpecCookDataSchema,
150
132
  ])
@@ -3,7 +3,11 @@
3
3
  * both validators warn on it and the corpus counts its kept users (`shard-format corpus`). A path with a migration is
4
4
  * mended by the chain; one without is deleted once no kept file uses it. */
5
5
  import { COOK_DEPRECATIONS } from './cook-deprecations.ts'
6
- import { MANIFEST_MOVED_DEPRECATIONS } from './manifest-deprecations.ts'
6
+ import {
7
+ LEVEL_DEPRECATIONS,
8
+ MANIFEST_MOVED_DEPRECATIONS,
9
+ MAP_IMAGE_DEPRECATION,
10
+ } from './manifest-deprecations.ts'
7
11
  import { SAVE_REVISION_DEPRECATION } from './save-revision.ts'
8
12
  import { SCHEMA_SOURCE_DEPRECATION } from './schema-source.ts'
9
13
  import {
@@ -129,8 +133,8 @@ const RULES: readonly DeprecationRule[] = [
129
133
  path: 'shard.json requires.sdk (SHARD-COMPAT CP8): a copy of the format version',
130
134
  since: ENVELOPE,
131
135
  replacement:
132
- 'nothing: formatVersion names the format; writers stop sourcing it, then it goes at zero users',
133
- migration: undefined,
136
+ 'nothing: formatVersion names the format; format 0.1.0.5 refuses it and the chain drops it (FORMAT-PRUNE FP33)',
137
+ migration: 'fp33-drop-requires-sdk',
134
138
  uses: (shard: Readonly<DeprecationInput>): boolean =>
135
139
  field(field(shard.index, 'requires'), 'sdk') !== undefined,
136
140
  },
@@ -157,6 +161,8 @@ const RULES: readonly DeprecationRule[] = [
157
161
  ) !== undefined,
158
162
  },
159
163
  ...MANIFEST_MOVED_DEPRECATIONS,
164
+ ...LEVEL_DEPRECATIONS,
165
+ MAP_IMAGE_DEPRECATION,
160
166
  {
161
167
  id: 'runtime.trust',
162
168
  path: 'shard.json runtime.trust',
@@ -0,0 +1,68 @@
1
+ import { maxLength, pipe, regex, string } from 'valibot'
2
+
3
+ import type { GenericSchema } from 'valibot'
4
+
5
+ // FORMAT-PRUNE FP47b (coordinator, 2026-11-24, J505): a product names the lowest engine release that can draw it
6
+ // (`requires.engine`, from format 0.1.0.6). The SDK stamps the engine release it builds against; the cook, a pin and a
7
+ // grid's admission refuse a product whose floor is above the engine they run, so a product built for a newer engine
8
+ // never lands on an older grid. An older engine's format has no such word and refuses the product outright.
9
+
10
+ const RELEASE = /^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/u
11
+ /** A running engine's version: a release, or a release's prerelease or build (`0.1.83-next.839c8ba0`). */
12
+ const RUNNING =
13
+ /^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:[-+][0-9A-Za-z.-]+)?$/u
14
+ const MAX_RELEASE = 32
15
+ const SAME = 0
16
+
17
+ /** An engine release, `X.Y.Z`. */
18
+ const EngineReleaseSchema: GenericSchema<string, string> = pipe(
19
+ string(),
20
+ maxLength(MAX_RELEASE),
21
+ regex(RELEASE),
22
+ )
23
+
24
+ /** A version's release numbers; a prerelease of `X.Y.Z` (an engine `next` build) counts as `X.Y.Z`. */
25
+ function releaseParts(version: string): readonly number[] | undefined {
26
+ const groups = RUNNING.exec(version)?.groups
27
+ return groups === undefined
28
+ ? undefined
29
+ : [groups['major'], groups['minor'], groups['patch']].map(Number)
30
+ }
31
+
32
+ /** Positive when `left` is the newer release. */
33
+ function compareReleases(
34
+ left: readonly number[],
35
+ right: readonly number[],
36
+ ): number {
37
+ const differs = left.findIndex(
38
+ (part: number, index: number): boolean => part !== right[index],
39
+ )
40
+ return differs < SAME
41
+ ? SAME
42
+ : (left[differs] ?? SAME) - (right[differs] ?? SAME)
43
+ }
44
+
45
+ /**
46
+ * Why an engine running `running` refuses a product whose floor is `required`, or undefined when it may draw it (no
47
+ * floor, or a floor at or below it). An unreadable running version refuses any floor.
48
+ */
49
+ function engineFloorRefusal(
50
+ required: string | undefined,
51
+ running: string,
52
+ ): string | undefined {
53
+ if (required === undefined) {
54
+ return undefined
55
+ }
56
+ const need = releaseParts(required)
57
+ const have = releaseParts(running)
58
+ if (
59
+ need !== undefined &&
60
+ have !== undefined &&
61
+ compareReleases(have, need) >= SAME
62
+ ) {
63
+ return undefined
64
+ }
65
+ return `This shard needs engine ${required} or newer; this engine is ${running} (requires.engine)`
66
+ }
67
+
68
+ export { EngineReleaseSchema, engineFloorRefusal }
@@ -57,7 +57,6 @@ const CLIENT_FEATURE_SIDES: Readonly<Record<ClientFeatureKind, SideEntry>> =
57
57
  'motion.channels': VIEW,
58
58
  'page.life': VIEW,
59
59
  'player.enter': both('fallFloor'),
60
- 'population.homes': VIEW,
61
60
  'population.hull-book': VIEW,
62
61
  'population.product-creatures': VIEW,
63
62
  'population.wildlife': VIEW,
@@ -13,6 +13,7 @@ type JsonRecord = Record<string, unknown>
13
13
  const ENVELOPE = '0.1.0.2'
14
14
  const PREPARATION_MARKER = '0.1.0.3'
15
15
  const SAVE_REVISION = '0.1.0.4'
16
+ const NO_REQUIRES_SDK = '0.1.0.5'
16
17
 
17
18
  function isRecord(value: unknown): value is JsonRecord {
18
19
  return typeof value === 'object' && value !== null && !Array.isArray(value)
@@ -74,6 +75,21 @@ const dropRequiresCapabilities: FormatMigration = {
74
75
  repairs: carriesCapabilities,
75
76
  }
76
77
 
78
+ /** FORMAT-PRUNE FP33 (SHARD-COMPAT CP8's last clause): `requires.sdk`, a copy of the format version nothing reads. Data
79
+ * only; the copy's declared source hash is re-sealed over the new index, as for `requires.capabilities`. */
80
+ const dropRequiresSdk: FormatMigration = {
81
+ id: 'fp33-drop-requires-sdk',
82
+ to: NO_REQUIRES_SDK,
83
+ touches: 'data',
84
+ affects: [],
85
+ apply: (shard: MigratingShard): void => {
86
+ const requires = requiresOf(shard)
87
+ if (requires !== undefined) {
88
+ Reflect.deleteProperty(requires, 'sdk')
89
+ }
90
+ },
91
+ }
92
+
77
93
  /** SHARD-COMPAT PR4 (J487, FORMAT-PRUNE FP5 folded in): the `sdk` marker becomes `preparation`, the spec version the
78
94
  * file was prepared to. `'0.3'` (prepared) is spec 3, the only spec that marker ever meant; `'0.2'` (built, not
79
95
  * prepared) leaves no field. Data only: the copy's `cook.json` stays spec 3 and its input hash is re-sealed over the
@@ -133,6 +149,7 @@ export {
133
149
  declaredShardfileFormat,
134
150
  dropEmptyIndexFields,
135
151
  dropRequiresCapabilities,
152
+ dropRequiresSdk,
136
153
  formatVersionField,
137
154
  preparationMarker,
138
155
  saveRevisionName,
@@ -0,0 +1,103 @@
1
+ // oxlint-disable typescript/prefer-readonly-parameter-types -- a step edits the shard it is handed, in place
2
+ /** FORMAT-PRUNE FP43's chain step (J486, CP16): `population.homes` left the client plan (engine `8848e8930` refuses it at
3
+ * runtime), but kept originals still carry it (Far Reach r1 and r3 to r6, Sunscar Dunes r1, r2 and r5), so the format
4
+ * refused them as stored with no step to mend them. The copy drops the row, and a trail row that followed one of its
5
+ * groups names that group's members instead, the spawn ids the homes row listed, as FP38 did by hand in Sky Reach. */
6
+ import type { FormatMigration, MigratingShard } from './format-migrations.ts'
7
+
8
+ type JsonRecord = Record<string, unknown>
9
+
10
+ const HOMES = 'population.homes'
11
+ const TRAIL = 'fx.trail'
12
+ const PLANS = ['client/plan', 'server/plan'] as const
13
+ /** The format that first refuses the row (FP43 rides format 0.1.0.5 with FP33). */
14
+ const HOMES_GONE = '0.1.0.5'
15
+
16
+ function isRecord(value: unknown): value is JsonRecord {
17
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
18
+ }
19
+
20
+ /** A plan's feature rows, or none. */
21
+ function featuresOf(plan: unknown): unknown[] {
22
+ if (!isRecord(plan)) {
23
+ return []
24
+ }
25
+ const { features } = plan
26
+ return Array.isArray(features) ? features : []
27
+ }
28
+
29
+ function kindIs(row: unknown, kind: string): row is JsonRecord {
30
+ return isRecord(row) && row['kind'] === kind
31
+ }
32
+
33
+ /** Every group the plan's homes rows declare, by name: the spawn ids in it. */
34
+ function homeGroups(features: readonly unknown[]): Map<string, unknown> {
35
+ const groups = new Map<string, unknown>()
36
+ for (const row of features) {
37
+ if (kindIs(row, HOMES) && isRecord(row['groups'])) {
38
+ for (const [name, members] of Object.entries(row['groups'])) {
39
+ groups.set(name, members)
40
+ }
41
+ }
42
+ }
43
+ return groups
44
+ }
45
+
46
+ /** A trail row that names `group` names that group's `members` in the same place; one naming no known group stays as it is
47
+ * and the copy's validator names it. */
48
+ function trailMembers(
49
+ row: JsonRecord,
50
+ groups: ReadonlyMap<string, unknown>,
51
+ ): void {
52
+ const { group } = row
53
+ if (typeof group !== 'string' || !groups.has(group)) {
54
+ return
55
+ }
56
+ const entries = Object.entries(row)
57
+ for (const [key] of entries) {
58
+ Reflect.deleteProperty(row, key)
59
+ }
60
+ for (const [key, value] of entries) {
61
+ if (key === 'group') {
62
+ row['members'] = groups.get(group)
63
+ } else {
64
+ row[key] = value
65
+ }
66
+ }
67
+ }
68
+
69
+ /** One plan: trails first take their members from the homes rows, then the homes rows go. */
70
+ function migratePlan(plan: unknown): void {
71
+ if (!isRecord(plan) || !Array.isArray(plan['features'])) {
72
+ return
73
+ }
74
+ const features = featuresOf(plan)
75
+ const groups = homeGroups(features)
76
+ for (const feature of features) {
77
+ if (kindIs(feature, TRAIL) && Array.isArray(feature['rows'])) {
78
+ for (const row of feature['rows']) {
79
+ if (isRecord(row)) {
80
+ trailMembers(row, groups)
81
+ }
82
+ }
83
+ }
84
+ }
85
+ plan['features'] = features.filter(
86
+ (row: unknown): boolean => !kindIs(row, HOMES),
87
+ )
88
+ }
89
+
90
+ /** FORMAT-PRUNE FP43: the copy carries no `population.homes` row, and its trails name their members. */
91
+ const homesToMembers: FormatMigration = {
92
+ id: 'fp43-homes-to-members',
93
+ to: HOMES_GONE,
94
+ touches: 'data',
95
+ affects: [],
96
+ apply: (shard: MigratingShard): void => {
97
+ for (const name of PLANS) {
98
+ migratePlan(shard.sections.get(name))
99
+ }
100
+ },
101
+ }
102
+
103
+ export { homesToMembers }