@wildshard/shard-format 0.28.0 → 0.31.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.28.0",
3
+ "version": "0.31.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": {
@@ -269,6 +269,7 @@
269
269
  "./practiceCourseRows": "./src/format/practiceCourseRows.ts",
270
270
  "./preflight": "./src/format/preflight.ts",
271
271
  "./presentation": "./src/format/presentation.ts",
272
+ "./primitives": "./src/format/primitives.ts",
272
273
  "./shardfileAssets": "./src/format/shardfile-assets.ts",
273
274
  "./shardfileValidation": "./src/format/shardfileValidation.ts",
274
275
  "./shardfileStream": "./src/format/shardfile-stream.ts",
@@ -323,6 +324,7 @@
323
324
  "./scriptActionsV2": "./src/format/scriptActionsV2.ts",
324
325
  "./scriptAdmission": "./src/format/scriptAdmission.ts",
325
326
  "./scriptAdmissionV2": "./src/format/scriptAdmissionV2.ts",
327
+ "./sectionVersions": "./src/format/section-versions.ts",
326
328
  "./scriptContract": "./src/format/scriptContract.ts",
327
329
  "./scriptFuelV2": "./src/format/scriptFuelV2.ts",
328
330
  "./scriptGroupBankV2": "./src/format/scriptGroupBankV2.ts",
@@ -14,14 +14,32 @@ interface BootMemoryCosts {
14
14
  readonly farSlabIndices: number
15
15
  readonly paintArrayGpu: number
16
16
  readonly paintArrayStaging: number
17
- /** MG6 epoch 3: the boot's CPU side as the phone-tier probe's renderer holds it (boot-phone.ts). */
18
- readonly renderer?: number
19
- /** MG6 epoch 3: a runtime home's paired Simulator WebContent + GL reading, whole (not less its pre-entry set). */
20
- readonly runtimeReading?: number
21
- /** MG6 epoch 3: `bootPhoneBytes` of the two above, the floor the loading estimate never goes under. */
17
+ /** MG6 epoch 4: the product's terms in EM11's phone chain (`phoneTerms`). */
18
+ readonly terms?: PhoneTerms
19
+ /** MG6 epoch 4: the phone playing (settled) estimate of `terms`. */
20
+ readonly phonePlaying?: number
21
+ /** MG6 epoch 4: the phone loading-peak estimate of `terms`. */
22
22
  readonly phoneFloor?: number
23
23
  }
24
24
 
25
+ /** MG6 epoch 4: what the offline estimate reads of a product, in bytes. */
26
+ interface PhoneTerms {
27
+ /** Every client file's wire bytes plus its CPU-decoded bytes (audio aside), the commons the same way, and the decoded
28
+ * engine images the cook mounts: what a boot downloads and decodes. */
29
+ readonly content: number
30
+ /** GPU texture bytes: image and KTX2 files, commons GPU and mounted images; zero for a runtime home, whose `gl` stands
31
+ * in (its files carry every tier's variants: Pine ships 704 MB of texture bytes and holds 65 MB on a phone at Low). */
32
+ readonly textures: number
33
+ /** A runtime home's paired GL reading [L]; zero for a data shard. */
34
+ readonly gl: number
35
+ /** GPU geometry bytes: GLB and binary files. */
36
+ readonly geometry: number
37
+ /** The shard's own declared sim residency at its growth limit (`budgets.sim`, `serverBudget.memory`). */
38
+ readonly sims: number
39
+ /** A runtime home's paired Simulator WebContent + GL reading, whole; zero for a data shard. */
40
+ readonly runtimeReading: number
41
+ }
42
+
25
43
  const NO_BYTES = 0
26
44
  const TRIANGLE_CORNERS = 3
27
45
  const INDEX_COPIES = 2
@@ -31,18 +49,33 @@ const BASE_LEVEL = 1
31
49
  // MG6: Nine's cold phone-tier shader step rose by 193 MB in the mini's
32
50
  // Chromium capture (04d76bcf). The calibrated increment rounds to 168 MB.
33
51
  const SHADER_COMPILE_BYTES = 168_000_000
34
- /** MG6 epoch 3 (mini-estcal, 2026-11-17): the phone-tier probe's loading renderer on an empty product (Ink Cel, Pastel,
35
- * Template, Open Plots read 368-424 MB on the v0.1.36 client, engine probe `3cd2dd87`), rounded up to cover Brasscap
36
- * and Sunscar. Lower it when the engine's own boot gets cheaper (mini-ninemem2). */
37
- const RENDERER_FLOOR_BYTES = 420_000_000
38
52
  const MB = 1_000_000
39
- /** MG6 epoch 3: the phone is the probe's loading renderer x2.0 (engine `3cd2dd87`, the floor from Jake's v0.1.36
40
- * iPhone crash). */
41
- const PHONE_PER_RENDERER = 2
42
- /** MG6 epoch 3: the probe's phone over a runtime home's paired Simulator WebContent + GL reading. Nalati 2,239 / 904 MB
43
- * = 2.48, Pine 2,076 / 850 MB = 2.44 (Driftwood 2.12; Nine's reading is stale). */
44
- const PHONE_PER_RUNTIME_READING = 2.5
53
+ const ENGINE_PLAYING_BYTES = 710_000_000
54
+ const ENGINE_LOADING_BYTES = 910_000_000
55
+ /** MG6 epoch 4 (mini-estcal2, 2026-11-17): the estimate is ENGINE-MEMORY EM11's phone chain (engine
56
+ * `scripts/memory/phone-model.json`, refit at the 2048 MiB ActiveHard line in `72e30a23`: native WebKit [K] of the
57
+ * WebContent and GPU processes through alpha or scale to an iPhone 17 Pro's WebContent). It replaces epoch 3's
58
+ * Chromium renderer x2.0 and 2.5 x the Simulator reading, which put Pine at 2,276 MB against EM11's 1.5-1.7 GB. Each
59
+ * weight is phone bytes per product byte, fitted so that every pinned product's estimate is at or over the upper bound
60
+ * of EM11's error bar on its cold runs (engine `6b432a2a`, Mac mini, phone Low; `memory-calibration.golden.json` holds
61
+ * the pairs), with each verdict kept: a product EM11 puts under the 1.0 GB playing envelope or the 1.5 GB loading line
62
+ * stays under it here (Far Reach binds both). The fit is minimax, then least total overshoot; the content weight is held
63
+ * at 0.5 settled and 0.8 loading at least, so bytes a boot downloads and decodes always count (epoch 3: the renderer's
64
+ * ArrayBuffers stay at their peak after ready). The engine term is Template's bound raised to cover Sunscar Dunes,
65
+ * whose held bitmaps outweigh its terms; refit it when the engine's own boot gets cheaper. */
66
+ const PHONE = {
67
+ engine: { playing: ENGINE_PLAYING_BYTES, loading: ENGINE_LOADING_BYTES },
68
+ content: { playing: 0.5, loading: 0.8 },
69
+ textures: { playing: 1.3, loading: 2.4 },
70
+ gl: { playing: 1.5, loading: 1.4 },
71
+ geometry: { playing: 0.2, loading: 2.6 },
72
+ /** A runtime home never reads under its own Simulator reading settled, nor under it times EM11's lowest peak over
73
+ * settled (1.257) while loading. No pinned home binds here today; it stops a heavy runtime with light files. */
74
+ runtime: { playing: 1, loading: 1.26 },
75
+ } as const
45
76
  const IMAGE_MOUNT = /\.(?:webp|png|jpe?g)$/u
77
+ const TEXTURE_KINDS: ReadonlySet<string> = new Set(['image', 'ktx2'])
78
+ const GEOMETRY_KINDS: ReadonlySet<string> = new Set(['glb', 'binary'])
46
79
 
47
80
  function spawnMemoryCosts(
48
81
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
@@ -120,16 +153,16 @@ function paintArrayBytes(
120
153
  return { paintArrayGpu, paintArrayStaging }
121
154
  }
122
155
 
123
- /** MG6 epoch 3: what the probe's renderer holds at the boot peak beyond its empty-product floor. Each client file's
124
- * downloaded bytes, its CPU-decoded form (decoded audio is left out: a boot decodes only its sample set, and Nine and
125
- * Open Plots decode none), the commons the same way, and the engine images the cook mounts (Far Reach's sky and
126
- * terrain textures: 107 MB of decoded bitmaps measured against 105 MB charged). */
127
- function rendererBytes(
156
+ /** MG6 epoch 3: what a boot downloads and decodes. Each client file's downloaded bytes, its CPU-decoded form (decoded
157
+ * audio is left out: a boot decodes only its sample set, and Nine and Open Plots decode none), the commons the same way,
158
+ * and the engine images the cook mounts (Far Reach's sky and terrain textures: 107 MB of decoded bitmaps measured
159
+ * against 105 MB charged). */
160
+ function contentBytes(
128
161
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
129
162
  shard: Shardfile,
130
163
  mountedImages: number,
131
164
  ): number {
132
- let bytes = RENDERER_FLOOR_BYTES + mountedImages
165
+ let bytes = mountedImages
133
166
  for (const file of shard.files) {
134
167
  bytes += file.compressed + (file.kind === 'audio' ? NO_BYTES : file.decoded)
135
168
  }
@@ -142,15 +175,46 @@ function rendererBytes(
142
175
  return bytes
143
176
  }
144
177
 
145
- /** MG6 epoch 3: a runtime home's paired reading, whole. */
146
- function runtimeReadingBytes(
178
+ /** The GPU bytes of the product's files of these kinds. */
179
+ function gpuBytes(
147
180
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
148
181
  shard: Shardfile,
182
+ kinds: ReadonlySet<string>,
149
183
  ): number {
184
+ let bytes = NO_BYTES
185
+ for (const file of shard.files) {
186
+ if (kinds.has(file.kind)) {
187
+ bytes += file.gpu
188
+ }
189
+ }
190
+ return bytes
191
+ }
192
+
193
+ /** MG6 epoch 4: a product's terms. */
194
+ function phoneTerms(
195
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
196
+ shard: Shardfile,
197
+ mountedImages: number = NO_BYTES,
198
+ ): PhoneTerms {
150
199
  const cost = shard.runtime?.cost
151
- return cost === undefined
152
- ? NO_BYTES
153
- : Math.ceil((cost.webContentMB + cost.glMB) * MB)
200
+ const commonsGpu = Object.values(shard.requires.commonsCosts).reduce(
201
+ (sum, row): number => sum + row.gpu,
202
+ NO_BYTES,
203
+ )
204
+ return {
205
+ content: contentBytes(shard, mountedImages),
206
+ textures:
207
+ cost === undefined
208
+ ? gpuBytes(shard, TEXTURE_KINDS) + commonsGpu + mountedImages
209
+ : NO_BYTES,
210
+ gl: cost === undefined ? NO_BYTES : Math.ceil(cost.glMB * MB),
211
+ geometry: gpuBytes(shard, GEOMETRY_KINDS),
212
+ sims: Math.max(shard.budgets.sim.resident, shard.serverBudget.memory),
213
+ runtimeReading:
214
+ cost === undefined
215
+ ? NO_BYTES
216
+ : Math.ceil((cost.webContentMB + cost.glMB) * MB),
217
+ }
154
218
  }
155
219
 
156
220
  /** The decoded bytes of one mounted engine image the cook serves beside the product; zero for any other mount. A
@@ -166,16 +230,24 @@ function mountedImageBytes(path: string, bytes: Readonly<Uint8Array>): number {
166
230
  }
167
231
  }
168
232
 
169
- /** MG6 epoch 3: the boot's phone floor, from the renderer side and from a runtime home's own reading. */
233
+ /** MG6 epoch 4: the phone's playing (settled) and loading-peak estimates of a product's terms. */
170
234
  function bootPhoneBytes(
171
- boot: Readonly<Pick<BootMemoryCosts, 'renderer' | 'runtimeReading'>>,
172
- ): number {
173
- return Math.ceil(
174
- Math.max(
175
- PHONE_PER_RENDERER * (boot.renderer ?? NO_BYTES),
176
- PHONE_PER_RUNTIME_READING * (boot.runtimeReading ?? NO_BYTES),
177
- ),
178
- )
235
+ terms: Readonly<PhoneTerms>,
236
+ ): Readonly<{ playing: number; loading: number }> {
237
+ const phase = (kind: 'playing' | 'loading'): number =>
238
+ Math.ceil(
239
+ Math.max(
240
+ PHONE.engine[kind] +
241
+ PHONE.content[kind] * terms.content +
242
+ PHONE.textures[kind] * terms.textures +
243
+ PHONE.gl[kind] * terms.gl +
244
+ PHONE.geometry[kind] * terms.geometry +
245
+ terms.sims,
246
+ PHONE.runtime[kind] * terms.runtimeReading,
247
+ ),
248
+ )
249
+ const playing = phase('playing')
250
+ return { playing, loading: Math.max(playing, phase('loading')) }
179
251
  }
180
252
 
181
253
  /** Boot memory that sits outside the steady-state file and tile budgets. `mountedImages` is the decoded size of the
@@ -191,16 +263,16 @@ function bootMemoryCosts(
191
263
  rawScene === undefined
192
264
  ? undefined
193
265
  : worldScenesForTier(parseWorldScenes(rawScene), 'phone')
194
- const renderer = rendererBytes(shard, mountedImages)
195
- const runtimeReading = runtimeReadingBytes(shard)
266
+ const terms = phoneTerms(shard, mountedImages)
267
+ const phone = bootPhoneBytes(terms)
196
268
  return {
197
269
  ...spawnMemoryCosts(shard, sections),
198
270
  shaderCompile: SHADER_COMPILE_BYTES,
199
271
  farSlabIndices: farSlabBytes(shard.files, scene),
200
272
  ...paintArrayBytes(scene),
201
- renderer,
202
- runtimeReading,
203
- phoneFloor: bootPhoneBytes({ renderer, runtimeReading }),
273
+ terms,
274
+ phonePlaying: phone.playing,
275
+ phoneFloor: phone.loading,
204
276
  }
205
277
  }
206
278
 
@@ -210,5 +282,6 @@ export {
210
282
  bootPhoneBytes,
211
283
  mountedImageBytes,
212
284
  NO_BYTES,
213
- RENDERER_FLOOR_BYTES,
285
+ type PhoneTerms,
286
+ phoneTerms,
214
287
  }
@@ -34,10 +34,14 @@ export function contentCost(input: ContentCostInput): { playing: number; loading
34
34
  const resident = input.l0 + input.l1 + input.far + input.libraries + input.sims + input.commons + (input.products ?? 0) + (input.near ?? 0) + bootResident(input.boot);
35
35
  const page = input.page ?? 0, accounted = resident + page;
36
36
  const base = (input.engineBase ?? C.engineBase) + page + Math.ceil(resident * C.residentFactor);
37
+ // MG6 epoch 4: a cold boot with its phone terms is EM11's phone chain, fitted to the measured product (boot-memory-cost.ts);
38
+ // the grid caps above stay with runtime admission, which passes no boot.
39
+ const phone = input.boot?.phonePlaying === undefined || input.boot.phoneFloor === undefined ? undefined
40
+ : { playing: input.boot.phonePlaying, loading: Math.max(input.boot.phonePlaying, input.boot.phoneFloor) };
41
+ if (phone !== undefined) { return { ...phone, accounted }; }
37
42
  const playing = base + input.overlap;
38
43
  // The boot phases and playing churn share the same allocation headroom.
39
- // MG6 epoch 3: the boot peak is also bounded below by what the phone-tier probe measures; the larger reading wins.
40
- const loading = input.boot === undefined ? playing + input.overlap : Math.max(base + bootOverlap(input.overlap, input.boot), input.boot.phoneFloor ?? NO_BYTES);
44
+ const loading = input.boot === undefined ? playing + input.overlap : base + bootOverlap(input.overlap, input.boot);
41
45
  return { playing, loading, accounted };
42
46
  }
43
47
 
@@ -27,6 +27,7 @@ import { StrikeTellKindSchema } from './spawnCombat.ts'
27
27
  import { HuntTuningSchema } from './speciesPrograms.ts'
28
28
 
29
29
  import type { CreatureBody } from './creature-body.ts'
30
+ import type { CreatureMount } from './creature-mount.ts'
30
31
  import type { CreatureProjectile } from './creature-projectile.ts'
31
32
  import type { CreatureSkinClipName } from './skinData.ts'
32
33
  import type { StrikeTellKind } from './spawnCombat.ts'
@@ -112,6 +113,8 @@ interface CreatureLayers {
112
113
  senses?: CreatureSenses
113
114
  abilities?: CreatureAbility[]
114
115
  presentation?: CreaturePresentation
116
+ /** CC40a: rideable by the riding primitive. */
117
+ mount?: CreatureMount
115
118
  }
116
119
 
117
120
  const ZERO = 0
@@ -285,4 +288,5 @@ export type {
285
288
  }
286
289
 
287
290
  export { CreatureBodySchema } from './creature-body.ts'
291
+ export { CreatureMountSchema, creatureMountRules } from './creature-mount.ts'
288
292
  export type { CreatureBody } from './creature-body.ts'
@@ -0,0 +1,120 @@
1
+ import {
2
+ boolean,
3
+ check,
4
+ exactOptional,
5
+ finite,
6
+ maxValue,
7
+ minValue,
8
+ number,
9
+ pipe,
10
+ strictObject,
11
+ } from 'valibot'
12
+
13
+ import { CREATURE_SKELETONS } from './creature-skeletons.ts'
14
+ import { CreatureSocketNameSchema } from './creature-volumes.ts'
15
+
16
+ import type { CreatureSkeleton } from './creature-layers.ts'
17
+ import type { GenericSchema } from 'valibot'
18
+
19
+ /** The seat socket both kit skeletons name. */
20
+ const DEFAULT_SEAT = 'seat'
21
+ /** Metres per second: past a galloping horse with room for a fast flyer. */
22
+ const MAX_GAIT = 40
23
+ const ZERO = 0
24
+ const PREVIOUS = 1
25
+
26
+ /** Ground speeds in metres per second, slowest first; trot and canter are optional steps between. */
27
+ interface MountGaits {
28
+ walk: number
29
+ trot?: number
30
+ canter?: number
31
+ gallop: number
32
+ }
33
+ /**
34
+ * ONE-FORMAT CC40a (Q27, Q-S3, Q-C7, Q-CC42): a `mount` row makes any creature rideable by the one riding primitive.
35
+ * `seat` names the socket the rider sits at (default `seat`), `fly` lets it take off on its species `flight` row.
36
+ */
37
+ interface CreatureMount {
38
+ seat?: string
39
+ gaits: MountGaits
40
+ fly?: boolean
41
+ }
42
+
43
+ const gait = pipe(number(), finite(), minValue(ZERO), maxValue(MAX_GAIT))
44
+ const gaitsObject = strictObject(
45
+ {
46
+ walk: gait,
47
+ trot: exactOptional(gait),
48
+ canter: exactOptional(gait),
49
+ gallop: gait,
50
+ },
51
+ 'Unknown mount gait',
52
+ )
53
+ function rising(gaits: Readonly<MountGaits>): boolean {
54
+ const steps = [gaits.walk, gaits.trot, gaits.canter, gaits.gallop].filter(
55
+ (step): step is number => step !== undefined,
56
+ )
57
+ return steps.every(
58
+ (step: number, at: number): boolean =>
59
+ at === ZERO || step > (steps[at - PREVIOUS] ?? step),
60
+ )
61
+ }
62
+ const CreatureMountSchema: GenericSchema<CreatureMount> = strictObject(
63
+ {
64
+ seat: exactOptional(CreatureSocketNameSchema),
65
+ gaits: pipe(
66
+ gaitsObject,
67
+ check(rising, 'Mount gaits rise from walk to gallop'),
68
+ ),
69
+ fly: exactOptional(boolean()),
70
+ },
71
+ 'Unknown mount field',
72
+ )
73
+
74
+ /** The parts of a species row the mount rules read. */
75
+ interface MountedSpecies {
76
+ readonly id: string
77
+ readonly mount?: { readonly seat?: string; readonly fly?: boolean }
78
+ readonly flight?: unknown
79
+ readonly body?: {
80
+ readonly skeleton?: CreatureSkeleton
81
+ readonly volumes?: readonly { readonly part: string }[]
82
+ }
83
+ }
84
+
85
+ function seatKnown(seat: string, body: MountedSpecies['body']): boolean {
86
+ const parts = (body?.volumes ?? []).map(
87
+ (volume: { readonly part: string }): string => volume.part,
88
+ )
89
+ if (parts.includes(seat)) {
90
+ return true
91
+ }
92
+ // A GLB with its own rig names its sockets in its skin; admission checks the seat there.
93
+ return (
94
+ body?.skeleton === undefined ||
95
+ Object.hasOwn(CREATURE_SKELETONS[body.skeleton].sockets, seat)
96
+ )
97
+ }
98
+
99
+ /** Each mount's references, as named refusals: a body to sit on, a seat it has, and a flight row to fly with. */
100
+ function creatureMountRules(species: readonly MountedSpecies[]): string[] {
101
+ return species.flatMap((row: MountedSpecies): string[] => {
102
+ const { mount, body, id } = row
103
+ if (mount === undefined) {
104
+ return []
105
+ }
106
+ const seat = mount.seat ?? DEFAULT_SEAT
107
+ return [
108
+ ...(body === undefined ? [`Mount ${id} needs a body`] : []),
109
+ ...(body !== undefined && !seatKnown(seat, body)
110
+ ? [`Unknown mount seat ${seat} on ${id}`]
111
+ : []),
112
+ ...(mount.fly === true && row.flight === undefined
113
+ ? [`Flying mount ${id} needs a flight row`]
114
+ : []),
115
+ ]
116
+ })
117
+ }
118
+
119
+ export type { CreatureMount, MountGaits }
120
+ export { CreatureMountSchema, DEFAULT_SEAT, creatureMountRules }
@@ -2,7 +2,10 @@
2
2
  * `runtimeCost` reading must have been taken against. It rises when the model changes what it charges (MG6 adds shader
3
3
  * compile, load transients, far slabs and paint arrays); from then a reading from an older epoch is refused until the
4
4
  * shard re-measures. A reading with no `epoch` is epoch 1, the model before MG6. */
5
- const MEMORY_EPOCH = 3
5
+ const MEMORY_EPOCH = 4
6
+ /** MG6 epoch 4 (mini-estcal2) changed how the estimate converts a reading (EM11's chain), not how a reading is taken:
7
+ * epoch 3's paired Simulator WebContent + GL protocol stands, so a reading from epoch 3 on is current. */
8
+ const OLDEST_CURRENT_EPOCH = 3
6
9
  const LEGACY_EPOCH = 1
7
10
 
8
11
  interface EpochRow {
@@ -17,10 +20,10 @@ interface StaleRuntimeIssue {
17
20
  readonly severity: 'refusal'
18
21
  }
19
22
 
20
- /** Why a runtime reading is stale against `current`, or empty when it is current. */
23
+ /** Why a runtime reading is stale, older than `current` (the oldest current epoch), or empty when it is current. */
21
24
  function staleRuntimeCost(
22
25
  row: EpochRow,
23
- current: number = MEMORY_EPOCH,
26
+ current: number = OLDEST_CURRENT_EPOCH,
24
27
  ): string {
25
28
  const epoch = row.epoch ?? LEGACY_EPOCH
26
29
  if (epoch >= current) {
@@ -33,7 +36,7 @@ function staleRuntimeCost(
33
36
  * `current`. Takes the shard's `runtime` (null for a data-only shard). */
34
37
  function staleRuntimeIssues(
35
38
  runtime: Readonly<{ cost?: EpochRow | undefined }> | null,
36
- current: number = MEMORY_EPOCH,
39
+ current: number = OLDEST_CURRENT_EPOCH,
37
40
  ): StaleRuntimeIssue[] {
38
41
  const rows: EpochRow[] = []
39
42
  const cost = runtime === null ? undefined : runtime.cost
@@ -54,4 +57,9 @@ function staleRuntimeIssues(
54
57
  }))
55
58
  }
56
59
 
57
- export { MEMORY_EPOCH, staleRuntimeCost, staleRuntimeIssues }
60
+ export {
61
+ MEMORY_EPOCH,
62
+ OLDEST_CURRENT_EPOCH,
63
+ staleRuntimeCost,
64
+ staleRuntimeIssues,
65
+ }
@@ -20,6 +20,7 @@ import type { ShardfileVersion } from './version.ts';
20
20
  import { isJsonData, isJsonDataWithFileSchemas } from './json.ts';
21
21
  import { clientOwnershipRules } from './clientOwnership.ts';
22
22
  import { PLATFORM_DATA_SECTIONS } from './platformDataSections.ts';
23
+ import { sectionSchemaIssue } from './section-versions.ts';
23
24
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
24
25
 
25
26
  const path = v.pipe(v.string(), v.maxLength(240), v.regex(/^(?:[a-zA-Z0-9_-][a-zA-Z0-9_.-]*\/)*[a-zA-Z0-9_-][a-zA-Z0-9_.-]*$/u));
@@ -81,7 +82,8 @@ function parseOutputIndexRows(input: unknown): OutputIndex {
81
82
  for (const entry of index.sections) {
82
83
  if (names.has(entry.name) || entry.path !== `sections/${entry.name}.json`) throw new Error('Duplicate or mismatched section path');
83
84
  names.add(entry.name);
84
- if ((!OUTPUT_SECTIONS.some(row => row.name === entry.name) && !isPlatformDataSection(entry.name)) || entry.schema !== `wildshard:${entry.name}@1`) throw new Error('Unknown platform section schema');
85
+ const issue = sectionSchemaIssue(entry.name, entry.schema);
86
+ if (issue !== undefined) throw new Error(`Unknown platform section schema: ${issue}`);
85
87
  }
86
88
  const refs = new Set<string>(), logical = new Set<string>();
87
89
  for (const entry of index.files) {
@@ -0,0 +1,274 @@
1
+ import { ACCEPTED_SECTION_VERSIONS, FIRST_VERSION } from './section-versions.ts'
2
+
3
+ /**
4
+ * ONE-FORMAT OF17a (J365 (6), J367 (5), Q-T22 option (b), Q-T27 (a)): no host list ships. A section switches a primitive
5
+ * on, and the server works out the list from the product's sections. The families and their hosts are the verdict
6
+ * table, meta `docs/plans/one-format/HOSTS.md` (OF16a), pending Jake's corrections (OF16b).
7
+ *
8
+ * `on` says what turns a family on: `always` (every product has it), a section path whose value is a non-empty array or
9
+ * object, or `later` while its row (`row`) has not given it a section yet. A family's version is its section's `@N`
10
+ * (`ACCEPTED_SECTION_VERSIONS`): changes are additive, and a removal follows SHARD-COMPAT's rollout.
11
+ */
12
+ /** An empty array or object switches nothing on. */
13
+ const NONE = 0
14
+
15
+ interface PrimitiveSwitch {
16
+ readonly section: string
17
+ readonly path: readonly string[]
18
+ /** When set, the family is on only if some row of the list at `path` has this key. */
19
+ readonly having?: string
20
+ }
21
+ interface Primitive {
22
+ readonly name: string
23
+ /** The ONE-FORMAT row that builds it. */
24
+ readonly row: string
25
+ /** The server hosts and page features it replaces (HOSTS.md). A host split across two families sits in the first. */
26
+ readonly hosts: readonly string[]
27
+ readonly on: PrimitiveSwitch | 'always' | 'later'
28
+ }
29
+ /** One family the server switched on, at the version of the section that switched it; no `section` for `always`. */
30
+ interface DerivedPrimitive {
31
+ readonly name: string
32
+ readonly section?: string
33
+ readonly version: number
34
+ }
35
+
36
+ const TABLE: readonly Primitive[] = [
37
+ {
38
+ name: 'collision',
39
+ row: 'OF41',
40
+ on: 'always',
41
+ hosts: ['collision', 'collision.pieces'],
42
+ },
43
+ {
44
+ name: 'plumbing',
45
+ row: 'OF18',
46
+ on: 'always',
47
+ hosts: [
48
+ 'commands',
49
+ 'decisions',
50
+ 'engine.creatures.update',
51
+ 'strings.register',
52
+ 'content.catalogue',
53
+ 'debug.expose',
54
+ 'audio.cues',
55
+ 'audio.scene',
56
+ 'player.enter',
57
+ 'bag.finds',
58
+ 'state.adventure',
59
+ ],
60
+ },
61
+ {
62
+ name: 'population',
63
+ row: 'OF29',
64
+ on: 'later',
65
+ hosts: [
66
+ 'population.roster',
67
+ 'population.spawn-script',
68
+ 'population.shelter',
69
+ 'population.environment',
70
+ 'population.mixed',
71
+ 'population.poses',
72
+ 'population.reactions',
73
+ 'population.settle',
74
+ 'population.homes',
75
+ 'population.wildlife',
76
+ ],
77
+ },
78
+ {
79
+ name: 'elites',
80
+ row: 'OF33',
81
+ on: 'later',
82
+ hosts: [
83
+ 'population.elites',
84
+ 'population.elites-ready',
85
+ 'riding.elites',
86
+ 'riding.elites-ready',
87
+ 'elite.entry',
88
+ 'elite.construct',
89
+ ],
90
+ },
91
+ {
92
+ name: 'boss',
93
+ row: 'OF34',
94
+ on: 'later',
95
+ hosts: ['boss.ground', 'boss.spawned', 'boss.held'],
96
+ },
97
+ {
98
+ name: 'boss.arena',
99
+ row: 'OF34',
100
+ on: 'later',
101
+ hosts: ['boss.arena', 'boss.open-arena'],
102
+ },
103
+ {
104
+ name: 'riding',
105
+ row: 'CC40',
106
+ on: {
107
+ section: 'actors/species',
108
+ path: ['rows', 'species'],
109
+ having: 'mount',
110
+ },
111
+ hosts: [
112
+ 'riding.mounted',
113
+ 'riding.roster',
114
+ 'riding.groups',
115
+ 'riding.hunt',
116
+ 'riding.trample',
117
+ 'riding.environment',
118
+ 'riding.taming',
119
+ 'riding.session',
120
+ 'taming.entry',
121
+ ],
122
+ },
123
+ {
124
+ name: 'patrol',
125
+ row: 'OF37',
126
+ on: 'later',
127
+ hosts: ['encounter.patrol', 'timed.encounters'],
128
+ },
129
+ {
130
+ name: 'held.melee',
131
+ row: 'OF38',
132
+ on: 'later',
133
+ hosts: [
134
+ 'item.swept',
135
+ 'held.melee',
136
+ 'held.arms',
137
+ 'held.claims',
138
+ 'held.cosmetics',
139
+ ],
140
+ },
141
+ {
142
+ name: 'held.ranged',
143
+ row: 'OF38',
144
+ on: 'later',
145
+ hosts: [
146
+ 'item.ranged',
147
+ 'combat.motion',
148
+ 'ammunition',
149
+ 'loadout',
150
+ 'held.ranged-feel',
151
+ 'held.ranged-page',
152
+ 'combat.targets',
153
+ ],
154
+ },
155
+ {
156
+ name: 'sky',
157
+ row: 'OF41',
158
+ on: { section: 'world/days', path: ['rows', 'days'] },
159
+ hosts: ['day.toon', 'day.keyed-sky', 'day.declared'],
160
+ },
161
+ {
162
+ name: 'weather',
163
+ row: 'OF41',
164
+ on: { section: 'world/weather', path: ['rows', 'weather'] },
165
+ hosts: [
166
+ 'weather.program',
167
+ 'weather.native',
168
+ 'weather.forest',
169
+ 'weather.fields',
170
+ ],
171
+ },
172
+ {
173
+ name: 'water.sea',
174
+ row: 'OF40',
175
+ on: 'later',
176
+ hosts: ['water.sea', 'world.water'],
177
+ },
178
+ { name: 'water.field', row: 'OF40', on: 'later', hosts: ['water.field'] },
179
+ { name: 'grapple', row: 'OF41', on: 'later', hosts: ['grapple'] },
180
+ { name: 'portal', row: 'OF41', on: 'later', hosts: ['portal.ride'] },
181
+ ]
182
+ const PRIMITIVES: readonly Primitive[] = Object.freeze(
183
+ TABLE.map((row): Primitive => Object.freeze(row)),
184
+ )
185
+
186
+ /** Hosts HOSTS.md leaves out of the primitives: quest (Q-S5), opened as it is; Nalati's stealth entry (Q-S4). */
187
+ const OUT_OF_SCOPE_HOSTS: readonly string[] = Object.freeze([
188
+ 'quest.body-scripts',
189
+ 'quest.composition',
190
+ 'quest.chapter',
191
+ 'quest.kill-steps',
192
+ 'stealth.entry',
193
+ ])
194
+
195
+ const HOST_FAMILY: ReadonlyMap<string, string> = new Map(
196
+ PRIMITIVES.flatMap((row): (readonly [string, string])[] =>
197
+ row.hosts.map((host): readonly [string, string] => [host, row.name]),
198
+ ),
199
+ )
200
+
201
+ /** The family a host joins, or `undefined` for a host outside the table. */
202
+ function primitiveOfHost(host: string): string | undefined {
203
+ return HOST_FAMILY.get(host)
204
+ }
205
+
206
+ function at(value: unknown, path: readonly string[]): unknown {
207
+ let here = value
208
+ for (const key of path) {
209
+ if (typeof here !== 'object' || here === null || Array.isArray(here)) {
210
+ return undefined
211
+ }
212
+ const next: unknown = Object.getOwnPropertyDescriptor(here, key)?.value
213
+ here = next
214
+ }
215
+ return here
216
+ }
217
+ function filled(value: unknown): boolean {
218
+ if (Array.isArray(value)) {
219
+ return value.length > NONE
220
+ }
221
+ return (
222
+ typeof value === 'object' &&
223
+ value !== null &&
224
+ Object.keys(value).length > NONE
225
+ )
226
+ }
227
+ function switchedOn(value: unknown, having: string | undefined): boolean {
228
+ if (having === undefined) {
229
+ return filled(value)
230
+ }
231
+ return (
232
+ Array.isArray(value) &&
233
+ value.some(
234
+ (row: unknown): boolean =>
235
+ typeof row === 'object' && row !== null && Object.hasOwn(row, having),
236
+ )
237
+ )
238
+ }
239
+ function newest(section: string): number {
240
+ return Math.max(...(ACCEPTED_SECTION_VERSIONS[section] ?? [FIRST_VERSION]))
241
+ }
242
+
243
+ /**
244
+ * The primitives a product's sections switch on, in table order: `sections` maps each section name to its admitted
245
+ * value. A family is on when its switch path holds a non-empty array or object. `versions` are the `@N` the index named
246
+ * (default: the newest this format reads).
247
+ */
248
+ function derivePrimitives(
249
+ sections: ReadonlyMap<string, unknown>,
250
+ versions: ReadonlyMap<string, number> = new Map(),
251
+ ): DerivedPrimitive[] {
252
+ return PRIMITIVES.flatMap((row): DerivedPrimitive[] => {
253
+ if (row.on === 'always') {
254
+ return [{ name: row.name, version: FIRST_VERSION }]
255
+ }
256
+ if (
257
+ row.on === 'later' ||
258
+ !switchedOn(at(sections.get(row.on.section), row.on.path), row.on.having)
259
+ ) {
260
+ return []
261
+ }
262
+ const { section } = row.on
263
+ return [
264
+ {
265
+ name: row.name,
266
+ section,
267
+ version: versions.get(section) ?? newest(section),
268
+ },
269
+ ]
270
+ })
271
+ }
272
+
273
+ export type { DerivedPrimitive, Primitive, PrimitiveSwitch }
274
+ export { OUT_OF_SCOPE_HOSTS, PRIMITIVES, derivePrimitives, primitiveOfHost }
@@ -7,7 +7,7 @@ import * as v from 'valibot';
7
7
  import { isJsonData } from './json.ts';
8
8
  import { sketchReference } from './sketch.ts';
9
9
  import { JournalRowSchema, journalRowRules } from './compendiumRows.ts';
10
- import { CreatureTypeSchema, CreatureBodySchema, CreatureTemperamentSchema, CreatureSensesSchema, CreatureAbilitySchema, CreaturePresentationSchema } from './creature-layers.ts';
10
+ import { CreatureMountSchema, creatureMountRules, CreatureTypeSchema, CreatureBodySchema, CreatureTemperamentSchema, CreatureSensesSchema, CreatureAbilitySchema, CreaturePresentationSchema } from './creature-layers.ts';
11
11
  import type { CreatureAbilityInput, CreatureLayers } from './creature-layers.ts';
12
12
  import { creatureSizeRules } from './creature-sizes.ts';
13
13
  import { SKIN_CLIPS_RECIPE, SkinClipMapSchema } from './skins.ts';
@@ -52,7 +52,7 @@ const species = v.strictObject({ id, kind: id, label: text, capExempt: v.exactOp
52
52
  variants: v.pipe(v.array(variant), v.minLength(1), v.maxLength(64)),
53
53
  type: v.exactOptional(CreatureTypeSchema), body: v.exactOptional(CreatureBodySchema),
54
54
  temperament: v.exactOptional(CreatureTemperamentSchema), senses: v.exactOptional(CreatureSensesSchema),
55
- abilities: v.exactOptional(abilities), presentation: v.exactOptional(CreaturePresentationSchema) });
55
+ abilities: v.exactOptional(abilities), presentation: v.exactOptional(CreaturePresentationSchema), mount: v.exactOptional(CreatureMountSchema) });
56
56
  const parameter = v.union([finite, v.boolean(), text, v.pipe(v.array(finite), v.maxLength(16))]);
57
57
  const animationParameters = v.record(id, parameter);
58
58
  const lookAnimation = v.strictObject({
@@ -82,7 +82,7 @@ function rowRules(rows: ShardRows): string[] {
82
82
  }
83
83
  for (const d of rows.days) if (d.schedule[0]?.from !== 0 || d.schedule.at(-1)?.to !== 24 || d.schedule.some((s, i) => s.from >= s.to || (i > 0 && d.schedule[i - 1]?.to !== s.from))) errors.push('complete ordered day schedule');
84
84
  const speciesIds = new Set(rows.species.map((s) => s.id));
85
- errors.push(...strikeDebrisCatalogueRules(rows), ...creatureSizeRules(rows.species));
85
+ errors.push(...strikeDebrisCatalogueRules(rows), ...creatureSizeRules(rows.species), ...creatureMountRules(rows.species));
86
86
  for (const s of rows.species) if (new Set(s.variants.map((r) => r.id)).size !== s.variants.length || s.variants.some((r) => r.scale[1] > 10)) errors.push('species variants');
87
87
  const strikeIds = new Set<string>();
88
88
  for (const strikeRow of rows.strikes) { strikeIds.add(strikeRow.id); }
@@ -0,0 +1,63 @@
1
+ import { OUTPUT_SECTIONS } from './outputFields.ts'
2
+ import { PLATFORM_DATA_SECTIONS } from './platformDataSections.ts'
3
+
4
+ /** The one version every section is at today. */
5
+ const FIRST_VERSION = 1
6
+ /** How much of a bad schema string a refusal quotes. */
7
+ const QUOTED_SCHEMA_CHARS = 120
8
+ const FIRST_CHAR = 0
9
+
10
+ /**
11
+ * ONE-FORMAT OF17a, SHARD-COMPAT §3.3: the section versions this format reads. A section's version is the `@N` its index
12
+ * row already names (`schema: "wildshard:<name>@<N>"`), never a field in its body. Every section is at version 1 today;
13
+ * an additive change keeps `[1]`, a removal adds `@2` beside `@1` and drops `@1` only at SHARD-COMPAT's B release.
14
+ */
15
+ const ACCEPTED_SECTION_VERSIONS: Readonly<Record<string, readonly number[]>> =
16
+ Object.freeze(
17
+ Object.fromEntries(
18
+ [
19
+ ...OUTPUT_SECTIONS.map((row): string => row.name),
20
+ ...Object.keys(PLATFORM_DATA_SECTIONS),
21
+ ].map((name): [string, readonly number[]] => [
22
+ name,
23
+ Object.freeze([FIRST_VERSION]),
24
+ ]),
25
+ ),
26
+ )
27
+
28
+ const SCHEMA = /^wildshard:(?<name>[^@]+)@(?<version>0|[1-9]\d{0,5})$/u
29
+
30
+ /** The version an index row's schema names, when it names its own section; `undefined` otherwise. */
31
+ function sectionSchemaVersion(
32
+ name: string,
33
+ schema: string,
34
+ ): number | undefined {
35
+ const match = SCHEMA.exec(schema)
36
+ return match?.groups?.['name'] === name
37
+ ? Number(match.groups['version'])
38
+ : undefined
39
+ }
40
+
41
+ /** Why an index row's section and schema are not ones this format reads, as one named line; `undefined` when they are. */
42
+ function sectionSchemaIssue(name: string, schema: string): string | undefined {
43
+ const accepted = Object.hasOwn(ACCEPTED_SECTION_VERSIONS, name)
44
+ ? ACCEPTED_SECTION_VERSIONS[name]
45
+ : undefined
46
+ if (accepted === undefined) {
47
+ return `unknown platform section ${name}`
48
+ }
49
+ const version = sectionSchemaVersion(name, schema)
50
+ if (version === undefined) {
51
+ return `section ${name} names the schema ${schema.slice(FIRST_CHAR, QUOTED_SCHEMA_CHARS)}; expected wildshard:${name}@<version>`
52
+ }
53
+ return accepted.includes(version)
54
+ ? undefined
55
+ : `section ${name} is at version ${String(version)}; this format reads ${accepted.join(', ')}`
56
+ }
57
+
58
+ export {
59
+ ACCEPTED_SECTION_VERSIONS,
60
+ FIRST_VERSION,
61
+ sectionSchemaIssue,
62
+ sectionSchemaVersion,
63
+ }