@wildshard/shard-format 0.25.0 → 0.26.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.25.0",
3
+ "version": "0.26.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": {
@@ -77,6 +77,7 @@
77
77
  "./bowVariantRows": "./src/format/bowVariantRows.ts",
78
78
  "./brains": "./src/format/brains.ts",
79
79
  "./budget": "./src/format/budget.ts",
80
+ "./budget-tiers": "./src/format/budget-tiers.ts",
80
81
  "./buildings": "./src/format/buildings.ts",
81
82
  "./builtIndexes": "./src/format/builtIndexes.ts",
82
83
  "./catalogueEconomy": "./src/format/catalogueEconomy.ts",
@@ -1,6 +1,7 @@
1
1
  import { controlFileHashes } from './admissionControl.ts'
2
2
  import { textureMipBytes } from './contentBounds.ts'
3
3
  import { spawnViewSceneFiles } from './spawnView.ts'
4
+ import { parseImageAsset } from './stillImage.ts'
4
5
  import { parseWorldScenes, worldScenesForTier } from './worldScenes.ts'
5
6
 
6
7
  import type { Shardfile } from './shardSchema.ts'
@@ -13,6 +14,12 @@ interface BootMemoryCosts {
13
14
  readonly farSlabIndices: number
14
15
  readonly paintArrayGpu: number
15
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. */
22
+ readonly phoneFloor?: number
16
23
  }
17
24
 
18
25
  const NO_BYTES = 0
@@ -24,6 +31,18 @@ const BASE_LEVEL = 1
24
31
  // MG6: Nine's cold phone-tier shader step rose by 193 MB in the mini's
25
32
  // Chromium capture (04d76bcf). The calibrated increment rounds to 168 MB.
26
33
  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
+ 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
45
+ const IMAGE_MOUNT = /\.(?:webp|png|jpe?g)$/u
27
46
 
28
47
  function spawnMemoryCosts(
29
48
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
@@ -101,23 +120,95 @@ function paintArrayBytes(
101
120
  return { paintArrayGpu, paintArrayStaging }
102
121
  }
103
122
 
104
- /** Boot memory that sits outside the steady-state file and tile budgets. */
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(
128
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
129
+ shard: Shardfile,
130
+ mountedImages: number,
131
+ ): number {
132
+ let bytes = RENDERER_FLOOR_BYTES + mountedImages
133
+ for (const file of shard.files) {
134
+ bytes += file.compressed + (file.kind === 'audio' ? NO_BYTES : file.decoded)
135
+ }
136
+ for (const wire of Object.values(shard.requires.commonsWire)) {
137
+ bytes += wire
138
+ }
139
+ for (const row of Object.values(shard.requires.commonsCosts)) {
140
+ bytes += row.decoded
141
+ }
142
+ return bytes
143
+ }
144
+
145
+ /** MG6 epoch 3: a runtime home's paired reading, whole. */
146
+ function runtimeReadingBytes(
147
+ // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
148
+ shard: Shardfile,
149
+ ): number {
150
+ const cost = shard.runtime?.cost
151
+ return cost === undefined
152
+ ? NO_BYTES
153
+ : Math.ceil((cost.webContentMB + cost.glMB) * MB)
154
+ }
155
+
156
+ /** The decoded bytes of one mounted engine image the cook serves beside the product; zero for any other mount. A
157
+ * mount that does not parse as a still image is charged at its own size. */
158
+ function mountedImageBytes(path: string, bytes: Readonly<Uint8Array>): number {
159
+ if (!IMAGE_MOUNT.test(path)) {
160
+ return NO_BYTES
161
+ }
162
+ try {
163
+ return parseImageAsset(bytes).decoded
164
+ } catch {
165
+ return bytes.length
166
+ }
167
+ }
168
+
169
+ /** MG6 epoch 3: the boot's phone floor, from the renderer side and from a runtime home's own reading. */
170
+ 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
+ )
179
+ }
180
+
181
+ /** Boot memory that sits outside the steady-state file and tile budgets. `mountedImages` is the decoded size of the
182
+ * engine images the cook mounts (`mountedImageBytes`), when the caller has the product's mounts. */
105
183
  function bootMemoryCosts(
106
184
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
107
185
  shard: Shardfile,
108
186
  sections: ReadonlyMap<string, unknown>,
187
+ mountedImages: number = NO_BYTES,
109
188
  ): BootMemoryCosts {
110
189
  const rawScene = sections.get('world/scenes')
111
190
  const scene =
112
191
  rawScene === undefined
113
192
  ? undefined
114
193
  : worldScenesForTier(parseWorldScenes(rawScene), 'phone')
194
+ const renderer = rendererBytes(shard, mountedImages)
195
+ const runtimeReading = runtimeReadingBytes(shard)
115
196
  return {
116
197
  ...spawnMemoryCosts(shard, sections),
117
198
  shaderCompile: SHADER_COMPILE_BYTES,
118
199
  farSlabIndices: farSlabBytes(shard.files, scene),
119
200
  ...paintArrayBytes(scene),
201
+ renderer,
202
+ runtimeReading,
203
+ phoneFloor: bootPhoneBytes({ renderer, runtimeReading }),
120
204
  }
121
205
  }
122
206
 
123
- export { type BootMemoryCosts, bootMemoryCosts }
207
+ export {
208
+ type BootMemoryCosts,
209
+ bootMemoryCosts,
210
+ bootPhoneBytes,
211
+ mountedImageBytes,
212
+ NO_BYTES,
213
+ RENDERER_FLOOR_BYTES,
214
+ }
@@ -0,0 +1,62 @@
1
+ import { picklist } from 'valibot'
2
+
3
+ import type { PicklistSchema } from 'valibot'
4
+
5
+ /**
6
+ * ONE-FORMAT OF10c0 (Q-T21: "tiers a shard picks"): a shard names its budget tier in `budgets.tier`, and each tier is a
7
+ * CPU, memory and bandwidth limit. Checked at build and at upload; OF10c1 to OF10c4 meter the engine's four dangerous
8
+ * gates against these limits and then delete the gates. A shard that names no tier is `small`.
9
+ *
10
+ * - `cpuMicrosPerFrame`: the shard's own runtime and page features, per 60 Hz frame on the reference phone.
11
+ * - `memoryBytes`: resident memory its runtime and owned stages may hold beyond the admitted content.
12
+ * - `bandwidthBytes`: compressed bytes a player downloads for the shard (J338: 50 MB is fine, 100 MB is the hard cap).
13
+ */
14
+ interface BudgetTierLimits {
15
+ readonly cpuMicrosPerFrame: number
16
+ readonly memoryBytes: number
17
+ readonly bandwidthBytes: number
18
+ }
19
+ type BudgetTier = 'small' | 'medium' | 'large'
20
+
21
+ const MEBIBYTE = 1_048_576
22
+ const SMALL_CPU = 1000
23
+ const MEDIUM_CPU = 2000
24
+ const LARGE_CPU = 4000
25
+ const SMALL_MEMORY = 128
26
+ const MEDIUM_MEMORY = 256
27
+ const LARGE_MEMORY = 512
28
+ const SMALL_BANDWIDTH = 25_000_000
29
+ const MEDIUM_BANDWIDTH = 50_000_000
30
+ const LARGE_BANDWIDTH = 100_000_000
31
+
32
+ const BUDGET_TIERS: Readonly<Record<BudgetTier, BudgetTierLimits>> = {
33
+ small: {
34
+ cpuMicrosPerFrame: SMALL_CPU,
35
+ memoryBytes: SMALL_MEMORY * MEBIBYTE,
36
+ bandwidthBytes: SMALL_BANDWIDTH,
37
+ },
38
+ medium: {
39
+ cpuMicrosPerFrame: MEDIUM_CPU,
40
+ memoryBytes: MEDIUM_MEMORY * MEBIBYTE,
41
+ bandwidthBytes: MEDIUM_BANDWIDTH,
42
+ },
43
+ large: {
44
+ cpuMicrosPerFrame: LARGE_CPU,
45
+ memoryBytes: LARGE_MEMORY * MEBIBYTE,
46
+ bandwidthBytes: LARGE_BANDWIDTH,
47
+ },
48
+ }
49
+ /** The tier a shard picks; an unknown tier refuses. */
50
+ const BudgetTierSchema: PicklistSchema<
51
+ ['small', 'medium', 'large'],
52
+ undefined
53
+ > = picklist(['small', 'medium', 'large'])
54
+ /** The limits a shard's budgets name (`small` when it names none). */
55
+ function budgetTierLimits(budgets: {
56
+ readonly tier?: BudgetTier
57
+ }): BudgetTierLimits {
58
+ return BUDGET_TIERS[budgets.tier ?? 'small']
59
+ }
60
+
61
+ export { BUDGET_TIERS, BudgetTierSchema, budgetTierLimits }
62
+ export type { BudgetTier, BudgetTierLimits }
@@ -36,7 +36,8 @@ export function contentCost(input: ContentCostInput): { playing: number; loading
36
36
  const base = (input.engineBase ?? C.engineBase) + page + Math.ceil(resident * C.residentFactor);
37
37
  const playing = base + input.overlap;
38
38
  // The boot phases and playing churn share the same allocation headroom.
39
- const loading = input.boot === undefined ? playing + input.overlap : base + bootOverlap(input.overlap, input.boot);
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);
40
41
  return { playing, loading, accounted };
41
42
  }
42
43
 
@@ -2,7 +2,7 @@
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 = 2
5
+ const MEMORY_EPOCH = 3
6
6
  const LEGACY_EPOCH = 1
7
7
 
8
8
  interface EpochRow {
@@ -1,6 +1,8 @@
1
+ import { parse } from 'valibot'
2
+
1
3
  import { bootMemoryCosts } from './boot-memory-cost.ts'
2
4
  import { worstContentCost } from './budget.ts'
3
- import { runtimeAccountedBytes } from './runtimeCost.ts'
5
+ import { runtimeAccountedBytes, RuntimeCostSchema } from './runtimeCost.ts'
4
6
 
5
7
  import type { Shardfile } from './shardSchema.ts'
6
8
 
@@ -40,22 +42,55 @@ function hardLineIssue(
40
42
  }
41
43
  }
42
44
 
45
+ /**
46
+ * MG6 epoch 3 (mini-estcal, 2026-11-17): the offline gates charge a runtime home from the engine base, never less a
47
+ * matched pre-entry resident set. The phone-tier probe found that set live at the boot peak: the renderer's
48
+ * ArrayBuffers stay at their peak after ready (Nalati 509 of 531 MB, Pine 484, Driftwood 284), so subtracting
49
+ * `residentBaseMB` (Nalati 685, Pine 671 MB against a 299 MB engine) dropped 386 and 372 MB from the estimate.
50
+ */
51
+ function runtimeOfflineBytes(input: unknown): number {
52
+ const row = parse(RuntimeCostSchema, input)
53
+ return runtimeAccountedBytes({
54
+ ...row,
55
+ residentBaseMB: row.engineBaseMB,
56
+ imagesFirst: undefined,
57
+ })
58
+ }
59
+
60
+ /** What the offline estimate knows of the product beyond its sections: the decoded engine images its cook mounts. */
61
+ type MemoryContext =
62
+ | ReadonlyMap<string, unknown>
63
+ | Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages: number }>
64
+
65
+ function memoryContext(
66
+ context: MemoryContext,
67
+ ): Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages: number }> {
68
+ return context instanceof Map
69
+ ? { sections: context, mountedImages: EMPTY_BYTES }
70
+ : // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- the union's other arm
71
+ (context as Readonly<{
72
+ sections: ReadonlyMap<string, unknown>
73
+ mountedImages: number
74
+ }>)
75
+ }
76
+
43
77
  /** Count cold-boot costs and any opaque runtime residency in offline admission. */
44
78
  function offlineMemoryIssues(
45
79
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard type, read only
46
80
  source: Shardfile,
47
- sections: ReadonlyMap<string, unknown>,
81
+ context: MemoryContext,
48
82
  ): ReturnType<typeof hardLineIssue>[] {
83
+ const { sections, mountedImages } = memoryContext(context)
49
84
  const native = source.runtime?.cost
50
85
  const runtime =
51
- native === undefined ? EMPTY_BYTES : runtimeAccountedBytes(native)
86
+ native === undefined ? EMPTY_BYTES : runtimeOfflineBytes(native)
52
87
  const commons = Object.values(source.requires.commonsCosts).reduce(
53
88
  (sum, row): number => sum + row.decoded + row.gpu,
54
89
  EMPTY_BYTES,
55
90
  )
56
91
  const cost = worstContentCost(source, {
57
92
  commons: runtime + commons,
58
- boot: bootMemoryCosts(source, sections),
93
+ boot: bootMemoryCosts(source, sections, mountedImages),
59
94
  })
60
95
  return (['playing', 'loading'] as const)
61
96
  .filter((kind): boolean => cost[kind] > MEMORY_HARD_BYTES)
@@ -64,4 +99,12 @@ function offlineMemoryIssues(
64
99
  )
65
100
  }
66
101
 
67
- export { MEMORY_HARD_BYTES, hardLineIssue, offlineMemoryIssues, overHardLine }
102
+ export {
103
+ MEMORY_HARD_BYTES,
104
+ type MemoryContext,
105
+ hardLineIssue,
106
+ memoryContext,
107
+ offlineMemoryIssues,
108
+ overHardLine,
109
+ runtimeOfflineBytes,
110
+ }
@@ -1,5 +1,7 @@
1
1
  /** Defining root wire sections shared by the authoring SDK and game admission.
2
2
  * Native reference/asset/entry/allocator checks stay in game; look and material contracts await DS1.4. */
3
+ import { BudgetTierSchema } from './budget-tiers.ts';
4
+ import type { BudgetTier } from './budget-tiers.ts';
3
5
  import * as v from 'valibot';
4
6
  import { WIRE_CELL, WIRE_TILE_SIZES } from './wireLimits.ts';
5
7
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
@@ -40,7 +42,9 @@ export const RequiresSchema: v.GenericSchema<ShardRequiresInput, ShardRequires>
40
42
  /** Authored compressed and resident ceilings. */
41
43
  export const BudgetsSchema: v.GenericSchema<ShardBudgetsInput, ShardBudgets> = v.strictObject({
42
44
  /** Reviewed whole-client floor retained when an opaque runtime becomes declared data. */
43
- client: v.exactOptional(RuntimeCostSchema), library: v.strictObject({ resident: ShardNaturalSchema, compressed: ShardNaturalSchema, downloadAllowance: v.exactOptional(ShardNaturalSchema) }), sim: v.strictObject({ resident: ShardNaturalSchema, compressed: ShardNaturalSchema }), overlap: ShardNaturalSchema });
45
+ client: v.exactOptional(RuntimeCostSchema),
46
+ /** ONE-FORMAT OF10c0: the budget tier this shard picks (`budgetTiers.ts`); none is `small`. */
47
+ tier: v.exactOptional(BudgetTierSchema), library: v.strictObject({ resident: ShardNaturalSchema, compressed: ShardNaturalSchema, downloadAllowance: v.exactOptional(ShardNaturalSchema) }), sim: v.strictObject({ resident: ShardNaturalSchema, compressed: ShardNaturalSchema }), overlap: ShardNaturalSchema });
44
48
  /** Fixed-step simulation and admitted script binding declarations. */
45
49
  export const SimSchema: v.GenericSchema<ShardSimInput, ShardSim> = v.strictObject({ fixedHz: v.literal(60), scriptTickDivisor: v.pipe(positive, v.check((n) => 60 % n === 0, 'script divisor divides 60')), commandVersion: v.literal(0), snapshotVersion: v.literal(0), scripts: ShardReferencesSchema, bindings: v.optional(ScriptBindingsSchema, []) });
46
50
  /** Bounded player count and authored movement speed. */
@@ -233,6 +237,7 @@ interface ShardRequiresFields {
233
237
  }
234
238
  export type ShardRequires = { [Key in keyof ShardRequiresFields]: ShardRequiresFields[Key] };
235
239
  interface ShardBudgetsInputFields {
240
+ tier?: BudgetTier;
236
241
  client?: v.InferInput<typeof RuntimeCostSchema>;
237
242
  library: {
238
243
  resident: ShardNaturalInput;
@@ -248,6 +253,7 @@ interface ShardBudgetsInputFields {
248
253
  export type ShardBudgetsInput = { [Key in keyof ShardBudgetsInputFields]: ShardBudgetsInputFields[Key] };
249
254
  interface ShardBudgetsFields {
250
255
  client?: v.InferOutput<typeof RuntimeCostSchema>;
256
+ tier?: BudgetTier;
251
257
  library: {
252
258
  resident: ShardNatural;
253
259
  compressed: ShardNatural;
@@ -14,24 +14,23 @@ import type { ShardTerrain } from "./terrain.ts";
14
14
  import { worstContentCost, memoryTargetWarnings, nearbyContentCost } from "./budget.ts";
15
15
  import { CONTENT_CAPS as C, MEMORY_GATES } from './contentBounds.ts';
16
16
  import { staleRuntimeIssues } from './memory-epoch.ts';
17
- import { MEMORY_HARD_BYTES, hardLineIssue } from './memory-line.ts';
18
- import { bootMemoryCosts } from './boot-memory-cost.ts';
17
+ import { MEMORY_HARD_BYTES, hardLineIssue, runtimeOfflineBytes } from './memory-line.ts';
18
+ import { bootMemoryCosts, NO_BYTES } from './boot-memory-cost.ts';
19
19
  import { VIEW_DRAWS, viewDraws } from './view-draws.ts';
20
20
  import { DEFAULT_GRAPH_BUDGET } from "./materialGraph.ts";
21
21
  import { SCRIPT_LIMITS } from './scriptLimits.ts';
22
- import { runtimeAccountedBytes } from "./runtimeCost.ts";
23
22
  import { MemoryAdmission } from './memoryAdmission.ts';
24
23
  import { nearPlaceholderRoots } from './nearPlaceholder.ts';
25
24
  import type { IssueCodeOf } from './issue-codes.ts';
26
25
  import { isNavigationData, navigationCost } from './navigationBytes.ts';
27
26
 
28
27
  type PerformancePolicy = 'refuse' | 'warn';
29
- interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown> }
28
+ interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown>; readonly mountedImages?: number }
30
29
 
31
30
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
32
- function reportMemory(source: Shardfile, nativeBytes: number, sections: ReadonlyMap<string, unknown>): PerformanceReport['memory'] {
31
+ function reportMemory(source: Shardfile, nativeBytes: number, options: Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages?: number }>): PerformanceReport['memory'] {
33
32
  const commons = nativeBytes + Object.values(source.requires.commonsCosts).reduce((sum, row) => sum + row.decoded + row.gpu, 0);
34
- const budget = { commons, boot: bootMemoryCosts(source, sections) };
33
+ const budget = { commons, boot: bootMemoryCosts(source, options.sections, options.mountedImages ?? NO_BYTES) };
35
34
  return { near: nearbyContentCost(source, source.spawn.x, source.spawn.z, budget), worst: worstContentCost(source, budget), playingLimit: C.playing, loadingLimit: C.loading };
36
35
  }
37
36
  /** A performance issue's code and its metric words. */
@@ -308,9 +307,9 @@ export function validatePropDrawBounds(source: Shardfile, assets: ReadonlyMap<st
308
307
 
309
308
  /** Report deterministic declared bounds and measured native execution; the caller supplies trusted provenance policy. */
310
309
  export function performanceReport(source: Shardfile, observations: PerformanceObservations, options: PerformancePolicy | PerformanceOptions = 'refuse'): PerformanceReport {
311
- const { policy, sections } = typeof options === 'string' ? { policy: options, sections: new Map<string, unknown>() } : options;
312
- const native = { resident: source.runtime?.cost === undefined ? 0 : runtimeAccountedBytes(source.runtime.cost), evidence: source.runtime?.cost?.evidence ?? null, unmeasuredViewAndDownload: source.runtime !== null };
313
- const memory = reportMemory(source, native.resident, sections), { worst } = memory, spawn = source.spawn;
310
+ const resolved: PerformanceOptions = typeof options === 'string' ? { policy: options, sections: new Map<string, unknown>() } : options, { policy } = resolved;
311
+ const native = { resident: source.runtime?.cost === undefined ? 0 : runtimeOfflineBytes(source.runtime.cost), evidence: source.runtime?.cost?.evidence ?? null, unmeasuredViewAndDownload: source.runtime !== null };
312
+ const memory = reportMemory(source, native.resident, resolved), { worst } = memory, spawn = source.spawn;
314
313
  const issues: PerformanceIssue[] = memoryTargetWarnings(source).map(row => ({ code: 'perf-memory-target', metric: `${row.category} resident target (tradeable)`, actual: row.bytes, limit: row.target, severity: 'warning' }));
315
314
  issues.push(...performanceTargetIssues(source, policy));
316
315
  const check = ([code, metric]: Named, actual: number, limit: number): void => {
@@ -21,7 +21,9 @@ import { shardfileRecordings } from './shardfile-audio.ts';
21
21
  import type { RecordingMeasure } from './audio-measure.ts';
22
22
  import { issueError, withIssueCode as coded } from './issue-codes.ts';
23
23
  import { staleRuntimeIssues } from './memory-epoch.ts';
24
- import { offlineMemoryIssues } from './memory-line.ts';
24
+ import { memoryContext, offlineMemoryIssues } from './memory-line.ts';
25
+ import type { MemoryContext } from './memory-line.ts';
26
+ import { mountedImageBytes, NO_BYTES } from './boot-memory-cost.ts';
25
27
 
26
28
  /**
27
29
  * P1-F3 format validation of a built shardfile product (format 2: `shard.json`, sections, blobs, packs): the schema,
@@ -108,18 +110,19 @@ export function outputBlobExtension(kind: OutputFile['kind'], bytes: Uint8Array)
108
110
  }
109
111
 
110
112
  /** Refuse the declared targets a policy treats as refusals, before any byte is read or executed. */
111
- export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refuse', sections: ReadonlyMap<string, unknown> = new Map()): void {
112
- const issues = [...staleRuntimeIssues(source.runtime), ...offlineMemoryIssues(source, sections), ...performanceTargetIssues(source, policy).filter(issue => issue.severity === 'refusal')];
113
+ export function assertShardfileTargets(source: Shardfile, policy: 'warn' | 'refuse', context: MemoryContext = new Map()): void {
114
+ const issues = [...staleRuntimeIssues(source.runtime), ...offlineMemoryIssues(source, context), ...performanceTargetIssues(source, policy).filter(issue => issue.severity === 'refusal')];
113
115
  if (issues.length === 0) return;
114
116
  throw issueError('performance-targets', issues.map(issue => `REFUSAL: ${issue.metric}: ${issue.actual} > ${issue.limit}`).join('\n'));
115
117
  }
116
118
 
117
119
  /** Admit a whole shardfile's declared costs and its actual immutable bytes through the defining contracts. */
118
120
  export function admitShardfileFolder(input: unknown, assets: ReadonlyMap<string, Uint8Array>, hash: (bytes: Uint8Array) => string,
119
- policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = [], sections?: ReadonlyMap<string, unknown>): Shardfile {
121
+ policy: 'warn' | 'refuse' = 'refuse', scripts: ScriptAdmissionRows = [], context?: MemoryContext): Shardfile {
122
+ const sections = context === undefined ? undefined : memoryContext(context).sections;
120
123
  const source = coded('shard-schema', (): Shardfile => parseShardfile(input, sections));
121
124
  coded('declared-costs', (): void => { preflightDeclaredCosts(source, offlineMemoryAdmission(policy)); });
122
- coded('performance-targets', (): void => { assertShardfileTargets(source, policy, sections); });
125
+ coded('performance-targets', (): void => { assertShardfileTargets(source, policy, context); });
123
126
  return coded('asset-admission', (): Shardfile => validateShardfileAssets(source, assets, hash, offlineMemoryAdmission(policy), undefined, scripts, sections));
124
127
  }
125
128
 
@@ -185,17 +188,19 @@ function checkServerAndKtx2(index: OutputIndex, read: ReadListed, assets: Readon
185
188
 
186
189
  /** C0 (J137): the cook file; a mount passes the same hash and size checks as any listed file (`cook-invalid`). */
187
190
  // oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
188
- function readCook(index: OutputIndex, read: ReadListed, hash: (bytes: Uint8Array) => string): ReturnType<typeof readCookData> | undefined {
189
- return coded('cook-invalid', (): ReturnType<typeof readCookData> | undefined => {
191
+ function readCook(index: OutputIndex, read: ReadListed, hash: (bytes: Uint8Array) => string): { cook: ReturnType<typeof readCookData> | undefined; mountedImages: number } {
192
+ return coded('cook-invalid', (): { cook: ReturnType<typeof readCookData> | undefined; mountedImages: number } => {
190
193
  const cook = index.cook === undefined ? undefined : readCookData(readCanonicalJson(read(index.cook)));
191
194
  requireCookPreparation(index, cook, hash);
195
+ let mountedImages = NO_BYTES;
192
196
  for (const mount of cook?.mounts ?? []) {
193
197
  if (!mountSharesBlob(mount, index.files)) {
194
198
  if (mount.path !== cookMountPath(mount.url)) { throw new Error(`Mount path differs from its URL: ${mount.url}`); }
195
- read(mount);
199
+ // MG6 epoch 3: the engine images a shard mounts decode at boot like its own (Far Reach's sky and textures).
200
+ mountedImages += mountedImageBytes(mount.path, read(mount));
196
201
  }
197
202
  }
198
- return cook;
203
+ return { cook, mountedImages };
199
204
  });
200
205
  }
201
206
 
@@ -225,13 +230,13 @@ export function validateShardfileFolder(files: ShardfileFiles, ports: ShardfileV
225
230
  }
226
231
  checkServerAndKtx2(index, read, assets);
227
232
  coded('pack-invalid', (): void => { checkPacks(index, new Set(files.paths()), { readFile: files.read, readListed: read, verify, hash: ports.hash }); });
228
- const cook = readCook(index, read, ports.hash);
233
+ const { cook, mountedImages } = readCook(index, read, ports.hash);
229
234
  for (const entry of index.runtime?.files ?? []) {
230
235
  if (ports.runtimeImports === undefined) throw issueError('runtime-files', 'Copied runtime files need a runtime import checker');
231
236
  coded('runtime-files', (): void => { ports.runtimeImports?.(entry.path, decoder().decode(read(entry))); });
232
237
  }
233
238
  for (const path of files.paths()) if (!listed.has(path)) throw issueError('unlisted-file', `Unlisted output file: ${path}`);
234
- const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, payloads);
239
+ const shard = admitShardfileFolder(coded('shard-schema', (): unknown => assembleOutputShardfile(index, payloads)), assets, ports.hash, 'warn', scripts, { sections: payloads, mountedImages });
235
240
  checkWorldTargets(shard, payloads.get('world/targets'));
236
241
  if (ports.hash(validationSourceBytes(shard)) !== index.build.sourceHash) throw issueError('source-hash', 'Output sections differ from the declared source hash');
237
242
  return { index, shard, assets, sections: payloads, scripts, warnings, audio: shardfileRecordings({ cook, read: files.read, shard, assets }) };