@wildshard/shard-format 0.29.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.29.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": {
@@ -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
 
@@ -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
+ }