@wildshard/shard-format 0.32.0 → 0.33.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.32.0",
3
+ "version": "0.33.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": {
@@ -1,9 +1,11 @@
1
1
  import { controlFileHashes } from './admissionControl.ts'
2
2
  import { textureMipBytes } from './contentBounds.ts'
3
+ import { contentBytes, gpuBytes, phoneInactiveFiles } from './phone-files.ts'
3
4
  import { spawnViewSceneFiles } from './spawnView.ts'
4
5
  import { parseImageAsset } from './stillImage.ts'
5
6
  import { parseWorldScenes, worldScenesForTier } from './worldScenes.ts'
6
7
 
8
+ import type { TierIndex } from './phone-files.ts'
7
9
  import type { Shardfile } from './shardSchema.ts'
8
10
  import type { WorldScenesSection } from './worldScenes.ts'
9
11
 
@@ -22,10 +24,10 @@ interface BootMemoryCosts {
22
24
  readonly phoneFloor?: number
23
25
  }
24
26
 
25
- /** MG6 epoch 4: what the offline estimate reads of a product, in bytes. */
27
+ /** MG6 epoch 4: what the offline estimate reads of a product, in bytes; from epoch 5 only the files a phone fetches. */
26
28
  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
+ /** Every phone-tier client file's wire bytes plus its CPU-decoded bytes (audio aside), the commons the same way, and,
30
+ * for a data shard, the decoded engine images the cook mounts: what a boot downloads and decodes. */
29
31
  readonly content: number
30
32
  /** GPU texture bytes: image and KTX2 files, commons GPU and mounted images; zero for a runtime home, whose `gl` stands
31
33
  * in (its files carry every tier's variants: Pine ships 704 MB of texture bytes and holds 65 MB on a phone at Low). */
@@ -50,25 +52,25 @@ const BASE_LEVEL = 1
50
52
  // Chromium capture (04d76bcf). The calibrated increment rounds to 168 MB.
51
53
  const SHADER_COMPILE_BYTES = 168_000_000
52
54
  const MB = 1_000_000
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. */
55
+ const ENGINE_PLAYING_BYTES = 696_764_000
56
+ const ENGINE_LOADING_BYTES = 982_344_000
57
+ /** MG6 epoch 5 (mini-em11b, 2026-11-18): the estimate is ENGINE-MEMORY EM11's phone chain (engine
58
+ * `scripts/memory/phone-model.json`, refit on readings without the Web Inspector's Network retention: native WebKit [K]
59
+ * of the WebContent and GPU processes through alpha or scale to an iPhone 17 Pro's WebContent, at the 2048 MiB
60
+ * ActiveHard line). Each weight is phone bytes per product byte, fitted so that every pinned product's estimate is at or
61
+ * over the upper bound of EM11's error bar on its cold runs (engine `037d9f15`, Mac mini, phone Low;
62
+ * `memory-calibration.golden.json` holds the pairs), with each verdict kept at the 1.0 GB playing envelope and the 1.5 GB
63
+ * loading line except Pine's loading (memory-calibration.test.ts says why). The fit is minimax, then least
64
+ * total overshoot; the content weight is held at 0.5 settled and 0.8 loading at least, so bytes a boot downloads and
65
+ * decodes always count. The terms count only the files a phone fetches (`phoneInactiveFiles`). The engine term is
66
+ * Template's bound raised to cover Sunscar Dunes, whose held bitmaps outweigh its terms; refit it when the engine's own
67
+ * boot gets cheaper. Epoch 4 (`6b432a2a` readings) read Pine at 1.46x its clean bound and Dunes under it. */
66
68
  const PHONE = {
67
69
  engine: { playing: ENGINE_PLAYING_BYTES, loading: ENGINE_LOADING_BYTES },
68
70
  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 },
71
+ textures: { playing: 1.46099, loading: 1.786 },
72
+ gl: { playing: 1.771, loading: 1.349 },
73
+ geometry: { playing: 0, loading: 1.977 },
72
74
  /** A runtime home never reads under its own Simulator reading settled, nor under it times EM11's lowest peak over
73
75
  * settled (1.257) while loading. No pinned home binds here today; it stops a heavy runtime with light files. */
74
76
  runtime: { playing: 1, loading: 1.26 },
@@ -153,48 +155,13 @@ function paintArrayBytes(
153
155
  return { paintArrayGpu, paintArrayStaging }
154
156
  }
155
157
 
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(
161
- // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
162
- shard: Shardfile,
163
- mountedImages: number,
164
- ): number {
165
- let bytes = mountedImages
166
- for (const file of shard.files) {
167
- bytes += file.compressed + (file.kind === 'audio' ? NO_BYTES : file.decoded)
168
- }
169
- for (const wire of Object.values(shard.requires.commonsWire)) {
170
- bytes += wire
171
- }
172
- for (const row of Object.values(shard.requires.commonsCosts)) {
173
- bytes += row.decoded
174
- }
175
- return bytes
176
- }
177
-
178
- /** The GPU bytes of the product's files of these kinds. */
179
- function gpuBytes(
180
- // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
181
- shard: Shardfile,
182
- kinds: ReadonlySet<string>,
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. */
158
+ /** MG6 epoch 5: a product's terms without the `inactive` files. A runtime home's mounted images are left to its reading:
159
+ * a phone Low boot of Pine fetched none of its 99.6 MB of them (meta MEMORY-GATES, mini-pinemem2 `95a75759`). */
194
160
  function phoneTerms(
195
161
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
196
162
  shard: Shardfile,
197
163
  mountedImages: number = NO_BYTES,
164
+ inactive: ReadonlySet<string> = new Set(),
198
165
  ): PhoneTerms {
199
166
  const cost = shard.runtime?.cost
200
167
  const commonsGpu = Object.values(shard.requires.commonsCosts).reduce(
@@ -202,13 +169,17 @@ function phoneTerms(
202
169
  NO_BYTES,
203
170
  )
204
171
  return {
205
- content: contentBytes(shard, mountedImages),
172
+ content: contentBytes(
173
+ shard,
174
+ cost === undefined ? mountedImages : NO_BYTES,
175
+ inactive,
176
+ ),
206
177
  textures:
207
178
  cost === undefined
208
- ? gpuBytes(shard, TEXTURE_KINDS) + commonsGpu + mountedImages
179
+ ? gpuBytes(shard, TEXTURE_KINDS, inactive) + commonsGpu + mountedImages
209
180
  : NO_BYTES,
210
181
  gl: cost === undefined ? NO_BYTES : Math.ceil(cost.glMB * MB),
211
- geometry: gpuBytes(shard, GEOMETRY_KINDS),
182
+ geometry: gpuBytes(shard, GEOMETRY_KINDS, inactive),
212
183
  sims: Math.max(shard.budgets.sim.resident, shard.serverBudget.memory),
213
184
  runtimeReading:
214
185
  cost === undefined
@@ -250,20 +221,27 @@ function bootPhoneBytes(
250
221
  return { playing, loading: Math.max(playing, phase('loading')) }
251
222
  }
252
223
 
253
- /** Boot memory that sits outside the steady-state file and tile budgets. `mountedImages` is the decoded size of the
254
- * engine images the cook mounts (`mountedImageBytes`), when the caller has the product's mounts. */
224
+ /** Boot memory outside the steady-state file and tile budgets. `product` carries what the caller has: the decoded size
225
+ * of the images the cook mounts (`mountedImageBytes`) and the output index, so the terms count only phone files. */
255
226
  function bootMemoryCosts(
256
227
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
257
228
  shard: Shardfile,
258
229
  sections: ReadonlyMap<string, unknown>,
259
- mountedImages: number = NO_BYTES,
230
+ product: Readonly<{
231
+ mountedImages?: number
232
+ index?: TierIndex | undefined
233
+ }> = {},
260
234
  ): BootMemoryCosts {
261
235
  const rawScene = sections.get('world/scenes')
262
236
  const scene =
263
237
  rawScene === undefined
264
238
  ? undefined
265
239
  : worldScenesForTier(parseWorldScenes(rawScene), 'phone')
266
- const terms = phoneTerms(shard, mountedImages)
240
+ const terms = phoneTerms(
241
+ shard,
242
+ product.mountedImages ?? NO_BYTES,
243
+ phoneInactiveFiles(shard, product.index, sections),
244
+ )
267
245
  const phone = bootPhoneBytes(terms)
268
246
  return {
269
247
  ...spawnMemoryCosts(shard, sections),
@@ -2,9 +2,11 @@
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 = 4
5
+ const MEMORY_EPOCH = 5
6
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. */
7
+ * epoch 3's paired Simulator WebContent + GL protocol stands, so a reading from epoch 3 on is current. Epoch 5
8
+ * (mini-em11b) refits that conversion to EM11 read without the Web Inspector's Network retention and counts only the
9
+ * files a phone fetches; readings are still taken as in epoch 3. */
8
10
  const OLDEST_CURRENT_EPOCH = 3
9
11
  const LEGACY_EPOCH = 1
10
12
 
@@ -4,6 +4,7 @@ import { bootMemoryCosts } from './boot-memory-cost.ts'
4
4
  import { worstContentCost } from './budget.ts'
5
5
  import { runtimeAccountedBytes, RuntimeCostSchema } from './runtimeCost.ts'
6
6
 
7
+ import type { TierIndex } from './phone-files.ts'
7
8
  import type { Shardfile } from './shardSchema.ts'
8
9
 
9
10
  /** J408 (Jake, 2026-11-17, after Nine crashed his iPhone 17 Pro at boot): the hard line. An estimate over it
@@ -57,20 +58,28 @@ function runtimeOfflineBytes(input: unknown): number {
57
58
  })
58
59
  }
59
60
 
60
- /** What the offline estimate knows of the product beyond its sections: the decoded engine images its cook mounts. */
61
+ /** What the offline estimate knows of the product beyond its sections: the decoded engine images its cook mounts and,
62
+ * from MG6 epoch 5, the output index, so its terms count only the files a phone fetches. */
61
63
  type MemoryContext =
62
64
  | ReadonlyMap<string, unknown>
63
- | Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages: number }>
65
+ | Readonly<{
66
+ sections: ReadonlyMap<string, unknown>
67
+ mountedImages: number
68
+ index?: TierIndex
69
+ }>
64
70
 
65
- function memoryContext(
66
- context: MemoryContext,
67
- ): Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages: number }> {
71
+ function memoryContext(context: MemoryContext): Readonly<{
72
+ sections: ReadonlyMap<string, unknown>
73
+ mountedImages: number
74
+ index?: TierIndex
75
+ }> {
68
76
  return context instanceof Map
69
77
  ? { sections: context, mountedImages: EMPTY_BYTES }
70
78
  : // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the union's other arm
71
79
  (context as Readonly<{
72
80
  sections: ReadonlyMap<string, unknown>
73
81
  mountedImages: number
82
+ index?: TierIndex
74
83
  }>)
75
84
  }
76
85
 
@@ -80,7 +89,7 @@ function offlineMemoryIssues(
80
89
  source: Shardfile,
81
90
  context: MemoryContext,
82
91
  ): ReturnType<typeof hardLineIssue>[] {
83
- const { sections, mountedImages } = memoryContext(context)
92
+ const { sections, mountedImages, index } = memoryContext(context)
84
93
  const native = source.runtime?.cost
85
94
  const runtime =
86
95
  native === undefined ? EMPTY_BYTES : runtimeOfflineBytes(native)
@@ -90,7 +99,7 @@ function offlineMemoryIssues(
90
99
  )
91
100
  const cost = worstContentCost(source, {
92
101
  commons: runtime + commons,
93
- boot: bootMemoryCosts(source, sections, mountedImages),
102
+ boot: bootMemoryCosts(source, sections, { mountedImages, index }),
94
103
  })
95
104
  return (['playing', 'loading'] as const)
96
105
  .filter((kind): boolean => cost[kind] > MEMORY_HARD_BYTES)
@@ -0,0 +1,83 @@
1
+ // MEMORY-GATES MG6 epoch 5 (mini-em11b): the files a phone never fetches, for the offline estimate's terms.
2
+ import { tierLibrarySteps } from './tierSelection.ts'
3
+
4
+ import type { Shardfile } from './shardSchema.ts'
5
+ import type { TierSelectionSource } from './tierSelection.ts'
6
+
7
+ const NO_BYTES = 0
8
+
9
+ /** The output index rows tier selection reads: the assembled Shardfile drops each file's `tier` and `variantOf`. */
10
+ interface TierIndex {
11
+ readonly files: readonly Readonly<{
12
+ hash: string
13
+ path: string
14
+ name?: string
15
+ tier?: 'phone' | 'desktop'
16
+ variantOf?: string
17
+ compressed?: number
18
+ }>[]
19
+ }
20
+
21
+ /** The files a phone never fetches, by tier selection's own verdict (the selection boot compilation runs): the desktop
22
+ * tier's named files, the texture-mode alternatives a phone skips, the other tier's horizons and scene models. Empty
23
+ * when the caller has no output index, so the estimate then counts every file. */
24
+ function phoneInactiveFiles(
25
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- tier selection's source, only read
26
+ source: TierSelectionSource,
27
+ index: TierIndex | undefined,
28
+ sections: ReadonlyMap<string, unknown>,
29
+ ): ReadonlySet<string> {
30
+ if (index === undefined) {
31
+ return new Set()
32
+ }
33
+ const steps = tierLibrarySteps(source, 'phone', { index, sections })
34
+ let step = steps.next()
35
+ while (step.done !== true) {
36
+ step = steps.next()
37
+ }
38
+ return step.value
39
+ }
40
+
41
+ /** MG6 epoch 3: what a boot downloads and decodes. Each client file's downloaded bytes, its CPU-decoded form (decoded
42
+ * audio is left out: a boot decodes only its sample set, and Nine and Open Plots decode none), the commons the same way,
43
+ * and the engine images the cook mounts (Far Reach's sky and terrain textures: 107 MB of decoded bitmaps measured
44
+ * against 105 MB charged). */
45
+ function contentBytes(
46
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
47
+ shard: Shardfile,
48
+ mountedImages: number,
49
+ inactive: ReadonlySet<string>,
50
+ ): number {
51
+ let bytes = mountedImages
52
+ for (const file of shard.files) {
53
+ if (!inactive.has(file.hash)) {
54
+ bytes +=
55
+ file.compressed + (file.kind === 'audio' ? NO_BYTES : file.decoded)
56
+ }
57
+ }
58
+ for (const wire of Object.values(shard.requires.commonsWire)) {
59
+ bytes += wire
60
+ }
61
+ for (const row of Object.values(shard.requires.commonsCosts)) {
62
+ bytes += row.decoded
63
+ }
64
+ return bytes
65
+ }
66
+
67
+ /** The GPU bytes of the product's files of these kinds. */
68
+ function gpuBytes(
69
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
70
+ shard: Shardfile,
71
+ kinds: ReadonlySet<string>,
72
+ inactive: ReadonlySet<string>,
73
+ ): number {
74
+ let bytes = NO_BYTES
75
+ for (const file of shard.files) {
76
+ if (kinds.has(file.kind) && !inactive.has(file.hash)) {
77
+ bytes += file.gpu
78
+ }
79
+ }
80
+ return bytes
81
+ }
82
+
83
+ export { contentBytes, gpuBytes, phoneInactiveFiles, type TierIndex }
@@ -15,7 +15,8 @@ import { worstContentCost, memoryTargetWarnings, nearbyContentCost } from "./bud
15
15
  import { CONTENT_CAPS as C, MEMORY_GATES } from './contentBounds.ts';
16
16
  import { staleRuntimeIssues } from './memory-epoch.ts';
17
17
  import { MEMORY_HARD_BYTES, hardLineIssue, runtimeOfflineBytes } from './memory-line.ts';
18
- import { bootMemoryCosts, NO_BYTES } from './boot-memory-cost.ts';
18
+ import { bootMemoryCosts } from './boot-memory-cost.ts';
19
+ import type { TierIndex } from './phone-files.ts';
19
20
  import { VIEW_DRAWS, viewDraws } from './view-draws.ts';
20
21
  import { DEFAULT_GRAPH_BUDGET } from "./materialGraph.ts";
21
22
  import { SCRIPT_LIMITS } from './scriptLimits.ts';
@@ -25,12 +26,12 @@ import type { IssueCodeOf } from './issue-codes.ts';
25
26
  import { isNavigationData, navigationCost } from './navigationBytes.ts';
26
27
 
27
28
  type PerformancePolicy = 'refuse' | 'warn';
28
- interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown>; readonly mountedImages?: number }
29
+ interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown>; readonly mountedImages?: number; readonly index?: TierIndex }
29
30
 
30
31
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
31
- function reportMemory(source: Shardfile, nativeBytes: number, options: Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages?: number }>): PerformanceReport['memory'] {
32
+ function reportMemory(source: Shardfile, nativeBytes: number, options: Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages?: number; index?: TierIndex }>): PerformanceReport['memory'] {
32
33
  const commons = nativeBytes + Object.values(source.requires.commonsCosts).reduce((sum, row) => sum + row.decoded + row.gpu, 0);
33
- const budget = { commons, boot: bootMemoryCosts(source, options.sections, options.mountedImages ?? NO_BYTES) };
34
+ const budget = { commons, boot: bootMemoryCosts(source, options.sections, options) };
34
35
  return { near: nearbyContentCost(source, source.spawn.x, source.spawn.z, budget), worst: worstContentCost(source, budget), playingLimit: C.playing, loadingLimit: C.loading };
35
36
  }
36
37
  /** A performance issue's code and its metric words. */
@@ -37,7 +37,12 @@ function admitHead(
37
37
  preflightDeclaredCosts(shard, offlineMemoryAdmission('warn'))
38
38
  })
39
39
  withIssueCode('performance-targets', (): void => {
40
- assertShardfileTargets(shard, 'warn', payloads)
40
+ // MG6 epoch 5: the index lets the estimate count only the files a phone fetches (no mount bytes in the stream).
41
+ assertShardfileTargets(shard, 'warn', {
42
+ sections: payloads,
43
+ mountedImages: 0,
44
+ index,
45
+ })
41
46
  })
42
47
  return shard
43
48
  }
@@ -237,7 +237,7 @@ export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileV
237
237
  coded('runtime-files', (): void => { ports.runtimeImports?.(entry.path, decoder().decode(read(entry))); });
238
238
  }
239
239
  for (const path of files.paths()) if (!listed.has(path)) throw issueError('unlisted-file', `Unlisted output file: ${path}`);
240
- const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, { sections: payloads, mountedImages });
240
+ const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, { sections: payloads, mountedImages, index });
241
241
  checkWorldTargets(shard, payloads.get('world/targets'));
242
242
  if (ports.hash(validationSourceBytes(shard)) !== index.build.sourceHash) throw issueError('source-hash', 'Output sections differ from the declared source hash');
243
243
  return { index, shard, assets, sections: payloads, scripts, warnings, audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };