@vgai/engine 0.5.10 → 0.5.12

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.
Files changed (157) hide show
  1. package/README.md +6 -5
  2. package/dist/adapter/authoring.d.ts +51 -28
  3. package/dist/adapter/authoring.d.ts.map +1 -1
  4. package/dist/adapter/body-marks.d.ts +59 -0
  5. package/dist/adapter/body-marks.d.ts.map +1 -0
  6. package/dist/adapter/body-marks.js +62 -0
  7. package/dist/adapter/constraint.d.ts +41 -0
  8. package/dist/adapter/constraint.d.ts.map +1 -0
  9. package/dist/adapter/constraint.js +27 -0
  10. package/dist/adapter/hierarchy-marks.d.ts +138 -0
  11. package/dist/adapter/hierarchy-marks.d.ts.map +1 -0
  12. package/dist/adapter/hierarchy-marks.js +148 -0
  13. package/dist/adapter/index.d.ts +1 -1
  14. package/dist/adapter/index.d.ts.map +1 -1
  15. package/dist/adapter/ingest/contract-system-adapters.d.ts +64 -0
  16. package/dist/adapter/ingest/contract-system-adapters.d.ts.map +1 -0
  17. package/dist/adapter/ingest/contract-system-adapters.js +134 -0
  18. package/dist/adapter/ingest/game-contract.d.ts +89 -5
  19. package/dist/adapter/ingest/game-contract.d.ts.map +1 -1
  20. package/dist/adapter/ingest/game-contract.js +11 -3
  21. package/dist/adapter/ingest/scene-capture.d.ts +31 -4
  22. package/dist/adapter/ingest/scene-capture.d.ts.map +1 -1
  23. package/dist/adapter/ingest/scene-capture.js +29 -7
  24. package/dist/adapter/ingest/structural-ids.d.ts +1 -1
  25. package/dist/adapter/ingest/structural-ids.js +2 -2
  26. package/dist/adapter/reflection-probe.d.ts +53 -0
  27. package/dist/adapter/reflection-probe.d.ts.map +1 -0
  28. package/dist/adapter/reflection-probe.js +18 -0
  29. package/dist/asset-formats/index.d.ts +4 -10
  30. package/dist/asset-formats/index.d.ts.map +1 -1
  31. package/dist/asset-formats/index.js +3 -8
  32. package/dist/asset-formats/material.d.ts +0 -66
  33. package/dist/asset-formats/material.d.ts.map +1 -1
  34. package/dist/asset-formats/material.js +0 -8
  35. package/dist/asset-formats/mesh.d.ts +1 -2
  36. package/dist/asset-formats/mesh.d.ts.map +1 -1
  37. package/dist/asset-formats/mesh.js +3 -13
  38. package/dist/asset-formats/render-env.d.ts +2 -2
  39. package/dist/asset-parse-error.d.ts +4 -5
  40. package/dist/asset-parse-error.d.ts.map +1 -1
  41. package/dist/asset-parse-error.js +4 -5
  42. package/dist/config.d.ts +7 -0
  43. package/dist/config.d.ts.map +1 -1
  44. package/dist/config.js +7 -0
  45. package/dist/data/curve.d.ts +116 -0
  46. package/dist/data/curve.d.ts.map +1 -0
  47. package/dist/data/curve.js +230 -0
  48. package/dist/data/vite-plugin-data.d.ts +2 -2
  49. package/dist/data/vite-plugin-data.d.ts.map +1 -1
  50. package/dist/data/vite-plugin-data.js +24 -15
  51. package/dist/dev/performance-profiler.d.ts +1 -0
  52. package/dist/dev/performance-profiler.d.ts.map +1 -1
  53. package/dist/dev/performance-profiler.js +25 -2
  54. package/dist/dev/register-render-vitals.d.ts +18 -7
  55. package/dist/dev/register-render-vitals.d.ts.map +1 -1
  56. package/dist/dev/register-render-vitals.js +35 -8
  57. package/dist/ecs/user-data.d.ts +49 -1
  58. package/dist/ecs/user-data.d.ts.map +1 -1
  59. package/dist/ecs/user-data.js +34 -0
  60. package/dist/index.d.ts +2 -3
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +2 -3
  63. package/dist/manifest/index.d.ts +3 -3
  64. package/dist/manifest/index.d.ts.map +1 -1
  65. package/dist/manifest/index.js +2 -2
  66. package/dist/manifest/load.d.ts +20 -63
  67. package/dist/manifest/load.d.ts.map +1 -1
  68. package/dist/manifest/load.js +12 -103
  69. package/dist/manifest/schema.d.ts +21 -103
  70. package/dist/manifest/schema.d.ts.map +1 -1
  71. package/dist/manifest/schema.js +66 -142
  72. package/dist/pixi/index.d.ts +2 -3
  73. package/dist/pixi/index.d.ts.map +1 -1
  74. package/dist/pixi/index.js +2 -3
  75. package/dist/pixi/ingest.d.ts +7 -75
  76. package/dist/pixi/ingest.d.ts.map +1 -1
  77. package/dist/pixi/ingest.js +6 -14
  78. package/dist/pixi/scene-capture.d.ts +2 -2
  79. package/dist/pixi/scene-capture.js +2 -2
  80. package/dist/react/use-data.d.ts +10 -5
  81. package/dist/react/use-data.d.ts.map +1 -1
  82. package/dist/react/use-data.js +15 -15
  83. package/dist/render/viewport-shading.d.ts +1 -1
  84. package/dist/render/viewport-shading.d.ts.map +1 -1
  85. package/dist/render/viewport-shading.js +14 -0
  86. package/dist/runtime/create-runtime.d.ts +12 -0
  87. package/dist/runtime/create-runtime.d.ts.map +1 -1
  88. package/dist/runtime/create-runtime.js +7 -2
  89. package/dist/runtime/mount-game.d.ts +1 -1
  90. package/dist/runtime/mount-game.d.ts.map +1 -1
  91. package/dist/runtime/mount-manifest.d.ts.map +1 -1
  92. package/dist/runtime/mount-manifest.js +5 -1
  93. package/dist/world3d-react/r3f-adapter.d.ts.map +1 -1
  94. package/dist/world3d-react/r3f-adapter.js +129 -6
  95. package/dist/world3d-react/renderer-config.d.ts +15 -0
  96. package/dist/world3d-react/renderer-config.d.ts.map +1 -1
  97. package/dist/world3d-react/renderer-config.js +15 -0
  98. package/dist/world3d-react/world-context.d.ts +11 -1
  99. package/dist/world3d-react/world-context.d.ts.map +1 -1
  100. package/dist/world3d-react/world-context.js +1 -0
  101. package/dist-config/config.js +140 -20
  102. package/dist-config/config.js.map +4 -4
  103. package/package.json +1 -1
  104. package/schemas/engine-capabilities.json +10 -10
  105. package/schemas/vgai-project.schema.json +22 -73
  106. package/src/adapter/authoring.ts +54 -31
  107. package/src/adapter/body-marks.ts +69 -0
  108. package/src/adapter/constraint.ts +71 -0
  109. package/src/adapter/hierarchy-marks.ts +155 -0
  110. package/src/adapter/index.ts +2 -3
  111. package/src/adapter/ingest/contract-system-adapters.ts +174 -0
  112. package/src/adapter/ingest/game-contract.ts +104 -6
  113. package/src/adapter/ingest/scene-capture.ts +61 -11
  114. package/src/adapter/ingest/structural-ids.ts +2 -2
  115. package/src/adapter/reflection-probe.ts +75 -0
  116. package/src/asset-formats/index.ts +4 -10
  117. package/src/asset-formats/material.ts +0 -11
  118. package/src/asset-formats/mesh.ts +3 -16
  119. package/src/asset-parse-error.ts +4 -5
  120. package/src/config.ts +13 -0
  121. package/src/data/curve.ts +263 -0
  122. package/src/data/vite-plugin-data.ts +48 -14
  123. package/src/dev/performance-profiler.ts +21 -2
  124. package/src/dev/register-render-vitals.ts +38 -8
  125. package/src/ecs/user-data.ts +50 -0
  126. package/src/index.ts +2 -3
  127. package/src/manifest/index.ts +3 -15
  128. package/src/manifest/load.ts +33 -139
  129. package/src/manifest/schema.ts +72 -181
  130. package/src/pixi/index.ts +2 -15
  131. package/src/pixi/ingest.ts +13 -87
  132. package/src/pixi/scene-capture.ts +2 -2
  133. package/src/react/use-data.ts +15 -20
  134. package/src/render/viewport-shading.ts +16 -1
  135. package/src/runtime/create-runtime.ts +30 -5
  136. package/src/runtime/mount-game.ts +1 -1
  137. package/src/runtime/mount-manifest.ts +5 -1
  138. package/src/world3d-react/r3f-adapter.tsx +142 -6
  139. package/src/world3d-react/renderer-config.ts +31 -0
  140. package/src/world3d-react/world-context.ts +11 -1
  141. package/dist/asset-formats/instances.d.ts +0 -17
  142. package/dist/asset-formats/instances.d.ts.map +0 -1
  143. package/dist/asset-formats/instances.js +0 -31
  144. package/dist/asset-formats/parse.d.ts +0 -20
  145. package/dist/asset-formats/parse.d.ts.map +0 -1
  146. package/dist/asset-formats/parse.js +0 -34
  147. package/dist/pixi/ingest-iframe.d.ts +0 -82
  148. package/dist/pixi/ingest-iframe.d.ts.map +0 -1
  149. package/dist/pixi/ingest-iframe.js +0 -166
  150. package/dist/render/instance-mesh.d.ts +0 -5
  151. package/dist/render/instance-mesh.d.ts.map +0 -1
  152. package/dist/render/instance-mesh.js +0 -19
  153. package/schemas/mat.schema.json +0 -255
  154. package/src/asset-formats/instances.ts +0 -38
  155. package/src/asset-formats/parse.ts +0 -39
  156. package/src/pixi/ingest-iframe.ts +0 -255
  157. package/src/render/instance-mesh.ts +0 -25
@@ -17,10 +17,8 @@ import {
17
17
  type AdapterRoot,
18
18
  type GameManifest,
19
19
  GameManifestSchema,
20
- type IngestStrategy,
21
20
  type LearnMetadata,
22
21
  type RootAdapter,
23
- type Tier,
24
22
  } from './schema';
25
23
 
26
24
  // ---------------------------------------------------------------------------
@@ -42,31 +40,28 @@ export type ResolvedAdapter =
42
40
  }
43
41
  | {
44
42
  readonly type: 'ingest';
45
- // 'ingest-react' (Track N, N1) is assigned here purely structurally (kind
46
- // === 'dom'), same as 'ingest-three'/'ingest-pixi': this loader stays
47
- // strategy-agnostic at resolve time, exactly like the other two ingest
48
- // identities (`ceilingFor`/`resolveCapabilities` below already derive tiers
49
- // per `strategy` regardless of `kind`). The v1 "deduped rung only" rule
50
- // (D-N3) is enforced editor-side, at the resolver
51
- // (`packages/editor/src/adapter-resolver.ts`'s `resolveIngestReactAdapter`)
52
- // — not here — mirroring how THIS file never rejects
53
- // `ingest-three`/`ingest-pixi`'s `iframe-reachable`/`opaque-embed`
54
- // strategies either; `resolveIngestDescriptor`/`resolveIngest2DDescriptor`
55
- // are where "not yet buildable" strategies throw.
43
+ // 'ingest-react' (Track N, N1) is assigned here purely structurally
44
+ // (surface === 'dom'), same as 'ingest-three'/'ingest-pixi'.
56
45
  readonly identity: 'ingest-three' | 'ingest-pixi' | 'ingest-react';
57
46
  readonly surface: 'three' | 'canvas' | 'dom';
58
- readonly strategy: IngestStrategy;
59
- readonly entryHtml: string | undefined;
47
+ /**
48
+ * Project-relative ES module declaring `window.vgaiGame` beside a
49
+ * pristine copy. OPTIONAL rather than required-and-possibly-undefined
50
+ * (the shape its siblings above use) because most ingested games have
51
+ * nothing to say about it, and requiring the key would only make every
52
+ * construction site say `undefined`.
53
+ */
54
+ readonly contractShim?: string | undefined;
55
+ /**
56
+ * Project-relative ES module that writes this game'''s own DATA file back
57
+ * (see the field'''s schema description). Same OPTIONAL shape and same
58
+ * reason as {@link contractShim}: a game whose truth is entirely source
59
+ * declares nothing here.
60
+ */
61
+ readonly dataWriter?: string | undefined;
60
62
  readonly assets: Record<string, string> | undefined;
61
63
  readonly domStubs: string[] | undefined;
62
64
  readonly captureTimeoutMs: number | undefined;
63
- /** Iframe-reachable-multi mount fields. */
64
- readonly bundleUrl: string | undefined;
65
- readonly baseHref: string | undefined;
66
- readonly assetBaseUrl: string | undefined;
67
- readonly extraDeps: string[] | undefined;
68
- readonly pixiModuleUrl: string | undefined;
69
- readonly bodyHtml: string | undefined;
70
65
  };
71
66
 
72
67
  export interface ResolvedAdapterRoot {
@@ -81,8 +76,6 @@ export interface ResolvedAdapterRoot {
81
76
  * `manifest/schema.ts`'s `dev` field for the four readers. */
82
77
  readonly dev: boolean;
83
78
  readonly loop: 'gated' | 'self-driven';
84
- /** Every optional resolved: both contexts always present (§4/§5). */
85
- readonly capabilities: { readonly local: Tier; readonly hosted: Tier };
86
79
  }
87
80
 
88
81
  export interface ResolvedGameManifest {
@@ -95,6 +88,8 @@ export interface ResolvedGameManifest {
95
88
  readonly roots: readonly ResolvedAdapterRoot[];
96
89
  readonly server: { readonly room: string; readonly module: string } | undefined;
97
90
  readonly resolution: { readonly width: number; readonly height: number } | undefined;
91
+ /** Construction-time renderer properties no world can declare for itself — see the schema. */
92
+ readonly rendering: { readonly antialias: boolean } | undefined;
98
93
  readonly authoring:
99
94
  | {
100
95
  readonly hierarchy?:
@@ -140,55 +135,6 @@ export interface ResolvedGameManifest {
140
135
  readonly learn: LearnMetadata | undefined;
141
136
  }
142
137
 
143
- // ---------------------------------------------------------------------------
144
- // §4 — the per-context ceiling table (named + exported so the tier-table test
145
- // can pin its rows against this).
146
- // ---------------------------------------------------------------------------
147
-
148
- /**
149
- * Ceiling (maximum legal declared `Tier`) per adapter type and delivery
150
- * context. `default` roots are always first-party in both contexts (D6/§2 —
151
- * a first-party root is fully vgai-native everywhere). `ingest` roots are
152
- * ceilinged by their own capture `strategy`: locally the local CLI's Vite
153
- * pipeline gives bundler dedupe, so every strategy reaches its own natural
154
- * rung; hosted has no bundler (esbuild-wasm + externals only), and a
155
- * `deduped` root is DEFINED by being source built through our pipeline — no
156
- * prebuilt bundle exists to fall back to an iframe rung, and nothing
157
- * implements a hosted build for it, so hosted is `unsupported` (honesty over
158
- * optimism; if the hosted esbuild-wasm path ever proves capable, raising
159
- * this ceiling is a non-breaking widening). `shared`/`iframe-reachable`/
160
- * `opaque-embed` don't depend on a bundler either way, so they carry through
161
- * unchanged. `module` adapters have no derivable ceiling ("a custom
162
- * adapter's reach is not derivable", §4) — modeled here as `first-party`
163
- * (the top rank), i.e. no ceiling actually constrains a module adapter's
164
- * declared tier; the loader instead requires the tier to be declared
165
- * explicitly for module roots (see `resolveCapabilities`), since there is no
166
- * default to derive.
167
- */
168
- export const CAPABILITY_CEILINGS = {
169
- builtin: { local: 'first-party', hosted: 'first-party' },
170
- ingest: {
171
- shared: { local: 'shared', hosted: 'shared' },
172
- deduped: { local: 'deduped', hosted: 'unsupported' },
173
- 'iframe-reachable': { local: 'iframe-reachable', hosted: 'iframe-reachable' },
174
- 'opaque-embed': { local: 'opaque-embed', hosted: 'opaque-embed' },
175
- },
176
- module: { local: 'first-party', hosted: 'first-party' },
177
- } as const satisfies Record<
178
- string,
179
- { local: Tier; hosted: Tier } | Record<IngestStrategy, { local: Tier; hosted: Tier }>
180
- >;
181
-
182
- /** Total order over `Tier` (§4: `first-party > shared ≈ deduped > iframe-reachable > opaque-embed > unsupported`). */
183
- const TIER_RANK: Record<Tier, number> = {
184
- 'first-party': 5,
185
- shared: 4,
186
- deduped: 4,
187
- 'iframe-reachable': 3,
188
- 'opaque-embed': 2,
189
- unsupported: 1,
190
- };
191
-
192
138
  /** Default relative path for `server.module` when omitted (§3) — the scaffolded Colyseus bootstrap. */
193
139
  export const DEFAULT_SERVER_MODULE = 'server/colyseus-setup.ts';
194
140
 
@@ -226,18 +172,14 @@ function checkAdapterEntryRules(root: AdapterRoot): void {
226
172
  '`entry` — a built-in adapter root is authored as an entry module.',
227
173
  );
228
174
  }
175
+ if (typeof adapter === 'object' && 'ingest' in adapter && !root.entry) {
176
+ throw new Error(
177
+ `Game manifest: root "${root.id}" is an { ingest } root but declares no \`entry\` — the ` +
178
+ "game's own entry module is what the host imports.",
179
+ );
180
+ }
229
181
  }
230
182
 
231
- // Historical note (Track N, N1): this file used to reject EVERY `kind:
232
- // 'react'` + `{ ingest }` root outright here (`checkReactAdapterRestriction`,
233
- // citing "no react ingest program is un-parked"). Track N un-parks exactly
234
- // that program — react+ingest is now a structurally legal combination,
235
- // resolved to the `'ingest-react'` identity by `resolveAdapter` below like
236
- // any other ingest root. There is nothing left to reject at THIS layer: the
237
- // v1 "deduped strategy only" restriction is an editor-resolver concern (D-N3),
238
- // not a manifest-shape concern — see the `ResolvedAdapter` type's comment
239
- // above.
240
-
241
183
  // ---------------------------------------------------------------------------
242
184
  // Resolution (§5)
243
185
  // ---------------------------------------------------------------------------
@@ -259,8 +201,7 @@ function resolveAdapter(root: AdapterRoot): ResolvedAdapter {
259
201
  }
260
202
 
261
203
  // isIngestAdapter (Track N, N1: 'ingest-react' joins 'ingest-three'/
262
- // 'ingest-pixi' — see the `ResolvedAdapter` type's comment above for why
263
- // this stays strategy-agnostic here).
204
+ // 'ingest-pixi').
264
205
  const identity =
265
206
  adapter.surface === 'three'
266
207
  ? 'ingest-three'
@@ -272,61 +213,14 @@ function resolveAdapter(root: AdapterRoot): ResolvedAdapter {
272
213
  type: 'ingest',
273
214
  identity,
274
215
  surface: adapter.surface,
275
- strategy: ingest.strategy,
276
- entryHtml: ingest.entryHtml,
216
+ contractShim: ingest.contractShim,
217
+ dataWriter: ingest.dataWriter,
277
218
  assets: ingest.assets,
278
219
  domStubs: ingest.domStubs,
279
220
  captureTimeoutMs: ingest.captureTimeoutMs,
280
- bundleUrl: ingest.bundleUrl,
281
- baseHref: ingest.baseHref,
282
- assetBaseUrl: ingest.assetBaseUrl,
283
- extraDeps: ingest.extraDeps,
284
- pixiModuleUrl: ingest.pixiModuleUrl,
285
- bodyHtml: ingest.bodyHtml,
286
221
  };
287
222
  }
288
223
 
289
- function ceilingFor(adapter: RootAdapter, context: 'local' | 'hosted'): Tier {
290
- if (typeof adapter === 'string') return CAPABILITY_CEILINGS.builtin[context];
291
- if (isModuleAdapter(adapter)) return CAPABILITY_CEILINGS.module[context];
292
- return CAPABILITY_CEILINGS.ingest[adapter.ingest.strategy][context];
293
- }
294
-
295
- function resolveCapabilities(root: AdapterRoot): { local: Tier; hosted: Tier } {
296
- const contexts = ['local', 'hosted'] as const;
297
- const result = {} as { local: Tier; hosted: Tier };
298
-
299
- for (const context of contexts) {
300
- const declared = root.capabilities?.[context];
301
- if (declared !== undefined) {
302
- const ceiling = ceilingFor(root.adapter, context);
303
- if (TIER_RANK[declared] > TIER_RANK[ceiling]) {
304
- throw new Error(
305
- `Game manifest: root "${root.id}": declared capabilities.${context} tier "${declared}" ` +
306
- `exceeds the "${ceiling}" ceiling for this adapter in the ${context} context (§4). ` +
307
- 'Under-claiming (including `unsupported`) is legal; over-claiming is not.',
308
- );
309
- }
310
- result[context] = declared;
311
- continue;
312
- }
313
-
314
- // Omitted -> derive.
315
- if (typeof root.adapter === 'string') {
316
- result[context] = 'first-party';
317
- } else if (isModuleAdapter(root.adapter)) {
318
- throw new Error(
319
- `Game manifest: root "${root.id}": { module } adapter requires an explicit ` +
320
- `capabilities.${context} declaration — a custom adapter's reach is not derivable (§4).`,
321
- );
322
- } else {
323
- result[context] = CAPABILITY_CEILINGS.ingest[root.adapter.ingest.strategy][context];
324
- }
325
- }
326
-
327
- return result;
328
- }
329
-
330
224
  function checkEngineVersionPin(version: string): void {
331
225
  if (!SEMVER_RE.test(version)) {
332
226
  throw new Error(
@@ -338,17 +232,17 @@ function checkEngineVersionPin(version: string): void {
338
232
 
339
233
  /**
340
234
  * Resolve one already-Zod-validated root entry into its `ResolvedAdapterRoot`
341
- * (adapter identity, capabilities, and a pass-through of every other field).
235
+ * (adapter identity, and a pass-through of every other field).
342
236
  * Every `AdapterRoot` field participates here or in a check above:
343
237
  * `id` drives uniqueness; `adapter` (incl. its surface and
344
- * `module`/`ingest.*` sub-fields) drives identity + capability-ceiling
238
+ * `module`/`ingest.*` sub-fields) drives adapter identity
345
239
  * resolution; `entry` drives the entry cross-field rule and is
346
240
  * carried through; `zOrder` drives the final sort; `pausable`/`loop` are
347
241
  * carried through as-is (their consumers are the runtime/CLI, T3.2/T3.3);
348
242
  * `dev` is carried through for the four dev-layer readers (`mountManifestRoots`'s
349
243
  * ship gate, the host's topmost stacking pass, the play compositor's capture
350
244
  * exclusion, and the editor's chrome-not-content seam);
351
- * `capabilities.{local,hosted}` drive tier resolution; `description` (T3.3
245
+ * `description` (T3.3
352
246
  * slice 3) is carried through as-is — its consumer today is
353
247
  * `resolveIngestDescriptor` (packages/editor/src/adapter-resolver.ts), which
354
248
  * threads an ingest-three root's description into `IngestGame.description`.
@@ -367,7 +261,6 @@ function resolveRoot(root: AdapterRoot): ResolvedAdapterRoot {
367
261
  pausable: root.pausable,
368
262
  dev: root.dev,
369
263
  loop: root.loop,
370
- capabilities: resolveCapabilities(root),
371
264
  };
372
265
  }
373
266
 
@@ -394,7 +287,7 @@ export function loadGameManifest(raw: unknown): ResolvedGameManifest {
394
287
  // raw multi-issue dump, because each one already reads as a finished
395
288
  // sentence naming the offending ids. Every other schema violation keeps
396
289
  // propagating as the raw `ZodError` it always has (unchanged behavior,
397
- // e.g. the iframe-reachable field-exclusivity / manifestVersion checks).
290
+ // e.g. an unrecognized key or a bad `manifestVersion`).
398
291
  const compositionIssue = parsed.error.issues.find(
399
292
  (issue) =>
400
293
  issue.message.startsWith('Game manifest: duplicate root id') ||
@@ -431,6 +324,7 @@ export function loadGameManifest(raw: unknown): ResolvedGameManifest {
431
324
  roots,
432
325
  server,
433
326
  resolution: manifest.resolution,
327
+ rendering: manifest.rendering,
434
328
  authoring: manifest.authoring,
435
329
  debug: manifest.debug,
436
330
  determinism: manifest.determinism,
@@ -9,8 +9,8 @@
9
9
  //
10
10
  // Naming: this file follows the repo's `XxxSchema` (Zod schema) / `Xxx`
11
11
  // (inferred type) convention used throughout `scene/schema/` — the design
12
- // doc's §3 sketch names the bare consts (`Tier`, `IngestStrategy`,
13
- // `AdapterRoot`) without the `Schema` suffix; that sketch is explicitly a
12
+ // doc's §3 sketch names the bare consts (`AdapterRoot`) without the
13
+ // `Schema` suffix; that sketch is explicitly a
14
14
  // "Zod sketch" the doc tells implementers to adapt to real code style
15
15
  // ("mirror the style in scene/schema/scene-file.ts" per CLAUDE.md), so the
16
16
  // schema consts here are suffixed and the bare names are reserved for the
@@ -28,32 +28,6 @@ import { z } from 'zod';
28
28
  */
29
29
  export const GAME_MANIFEST_VERSION = 2 as const;
30
30
 
31
- // ---------------------------------------------------------------------------
32
- // Ingest capture strategy (the general vocabulary D6/§4 names)
33
- // ---------------------------------------------------------------------------
34
-
35
- export const IngestStrategySchema = z.enum([
36
- 'shared', // game imports host-served ESM three — full in-realm capture
37
- 'deduped', // game source built by OUR pipeline, bundler dedupe — full capture
38
- 'iframe-reachable', // prebuilt bundle in iframe, three reachable — cross-realm capture
39
- 'opaque-embed', // prebuilt bundle, nothing reachable — host lifecycle only
40
- ]);
41
- export type IngestStrategy = z.infer<typeof IngestStrategySchema>;
42
-
43
- // ---------------------------------------------------------------------------
44
- // Capability tier — one ordered enum, declared per delivery context (§4)
45
- // ---------------------------------------------------------------------------
46
-
47
- export const TierSchema = z.enum([
48
- 'first-party', // vgai-native root: full editor, full loop control
49
- 'shared', // = IngestStrategy 'shared' rung
50
- 'deduped', // = IngestStrategy 'deduped' rung
51
- 'iframe-reachable', // = IngestStrategy 'iframe-reachable' rung
52
- 'opaque-embed', // = IngestStrategy 'opaque-embed' rung
53
- 'unsupported', // this root does not function in this delivery context
54
- ]);
55
- export type Tier = z.infer<typeof TierSchema>;
56
-
57
31
  // ---------------------------------------------------------------------------
58
32
  // Root adapter identity. The adapter is the sole discriminator: a root never
59
33
  // repeats its rendering substrate in a sibling `kind` field. Module and ingest
@@ -160,19 +134,51 @@ export const RootAdapterSchema = z
160
134
  .describe('Native surface captured from the unmodified game'),
161
135
  ingest: z
162
136
  .object({
163
- strategy: IngestStrategySchema.describe(
164
- 'Capture mechanics rung this ingested root uses (§4) — also the root`s natural local capability tier',
165
- ),
166
- entryHtml: z
137
+ contractShim: z
138
+ .string()
139
+ .optional()
140
+ .describe(
141
+ "Project-relative path to a HOST-ADDED ES module that declares this game's " +
142
+ '`window.vgaiGame` contract (adapter/ingest/game-contract.ts) WITHOUT editing a ' +
143
+ 'vendored byte — the pristine-copy door. The host imports it immediately BEFORE ' +
144
+ "the game's own entry module, in the editor's realm. " +
145
+ 'TIMING CONTRACT, which a shim author must obey: because it runs before the ' +
146
+ 'game`s entry, it MUST assign `window.vgaiGame` SYNCHRONOUSLY at top level. ' +
147
+ 'Anything that needs the game`s own modules must be LAZY: a dynamic `import()` ' +
148
+ 'INSIDE each verb/provider closure, resolved at call time. Importing a game module ' +
149
+ 'eagerly from the shim would evaluate it ahead of the game`s own entry and reorder ' +
150
+ 'its module side effects. ' +
151
+ 'Every such `import()` MUST take a STRING LITERAL, never a variable/table lookup. ' +
152
+ 'A variable specifier is not statically analyzable, so the dev server leaves it ' +
153
+ 'alone and it resolves at runtime against the shim`s own `/@fs/` url — while the ' +
154
+ 'game`s entry has had ITS relative imports rewritten to whatever url the server ' +
155
+ 'considers canonical for those files. Module identity is per-url, so the shim ' +
156
+ 'silently binds a SECOND, freshly-evaluated copy of the whole game and every ' +
157
+ 'provider reports a game that never started. Measured on three-descent: 285 ' +
158
+ 'segments through the game`s graph, 0 through the shim`s, and no error anywhere.',
159
+ ),
160
+ dataWriter: z
167
161
  .string()
168
162
  .optional()
169
163
  .describe(
170
- 'Entry HTML path, project-relative. WIRED for opaque-embed (D-W2): ' +
171
- 'the file`s bytes are read verbatim through ' +
172
- 'the project-static route and hosted in a sandboxed iframe (embed-only, no scene ' +
173
- 'introspection), for both canvas and three roots. Legal but NOT wired to a ' +
174
- 'mount for iframe-reachable (a named error at resolve names this use `bundleUrl` ' +
175
- 'instead, the wired reachable route).',
164
+ "Project-relative path to a HOST-ADDED ES module that writes this game's own " +
165
+ 'DATA file back the sibling of a source write for a game whose authorable ' +
166
+ 'truth is not source. Descent places its robots, powerups and hostages in ' +
167
+ 'binary records inside `descent.hog`, reaching no source literal, so an ' +
168
+ 'authored move of one is an edit to that file and nothing else can write it. ' +
169
+ 'The module declares two exports and the host knows nothing else about it: ' +
170
+ '`dataFile` (a project-relative string — the ONE file this writer edits) and ' +
171
+ '`planDataEdit(bytes, {record, property, baseline, next})`, which returns ' +
172
+ '`{changed: true, bytes}` or `{changed: false, reason}` and may be async. ' +
173
+ 'It is loaded in the editor realm beside the game, so it may `import()` the ' +
174
+ "game's own modules to resolve what only a running game knows (Descent's " +
175
+ 'writer asks the game`s own `find_point_seg` which segment a moved object ' +
176
+ 'landed in, and refuses "outside the mine" rather than writing data the game ' +
177
+ 'would read back wrong). It NEVER fabricates: a record it cannot address, or ' +
178
+ 'a property it does not model, is a named refusal. ' +
179
+ 'An object is anchored to a record by carrying `userData.vgaiRecordIndex` — ' +
180
+ 'the game declares that identity itself (a recorded patch or a shim); the ' +
181
+ 'host never infers one.',
176
182
  ),
177
183
  assets: z
178
184
  .record(z.string(), z.string())
@@ -190,139 +196,16 @@ export const RootAdapterSchema = z
190
196
  .number()
191
197
  .optional()
192
198
  .describe(
193
- 'How long to wait for capture before REPORTING the degrade loudly not how ' +
194
- 'long to keep listening. On the self-hosted-three route the devtools ' +
195
- 'subscription is permanent, so a renderer appearing later still upgrades a ' +
196
- 'reported-embed-only mount in place; the host clamps this value so a long ' +
197
- 'one cannot block the editor on a question the upgrade path answers anyway.',
198
- ),
199
- // The six iframe-reachable-multi mount fields
200
- // (`ingest-iframe-2d.ts`'s `IframeReachableMultiOpts`), legal
201
- // ONLY when `strategy` is 'iframe-reachable' (enforced by the
202
- // `.superRefine` below).
203
- bundleUrl: z
204
- .string()
205
- .optional()
206
- .describe(
207
- 'Absolute URL of the externalized built game bundle — the WIRED iframe-reachable ' +
208
- 'mount route (iframe-reachable only), for BOTH canvas (Track P, ' +
209
- "ingest-iframe-2d.ts's mountIngestGame2DIframeReachableMulti) and three (D-W1, " +
210
- "ingest-iframe-reachable-adapter.ts's mountIngestGameIframeReachableBundle). " +
211
- 'PRECONDITION: the bundle must externalize its root`s own runtime as a bare, ' +
212
- 'un-rewritten import (`pixi.js` for canvas, `three` for three — `vgai bundle` ' +
213
- 'does this for you) so it resolves through the iframe importmap to the HOST ' +
214
- 'instance the capture trap is installed on; a bundle with an inlined runtime is ' +
215
- 'unreachable and degrades to the embed-only floor. Exactly one of bundleUrl/' +
216
- 'entryHtml is required when strategy is iframe-reachable.',
217
- ),
218
- baseHref: z
219
- .string()
220
- .optional()
221
- .describe(
222
- "Iframe <base href> so the game's relative asset URLs resolve (iframe-reachable only).",
223
- ),
224
- assetBaseUrl: z
225
- .string()
226
- .optional()
227
- .describe(
228
- "Host-side basePath forced onto the trapped runtime's own asset resolution — " +
229
- "pixi's `Assets.init` for a canvas root, three's " +
230
- '`DefaultLoadingManager.setURLModifier` for a three root (D-W1) — absolute, or ' +
231
- "root-relative (resolved against the editor page's own origin at mount time, " +
232
- 'ingest-mode.ts, so a static manifest never has to know the dev-server port) ' +
233
- '(iframe-reachable only — a document.write iframe keeps the parent window.location).',
234
- ),
235
- extraDeps: z
236
- .array(z.string())
237
- .optional()
238
- .describe(
239
- "Bare specifiers of this root's externalized deps beyond its own runtime " +
240
- "(pixi.js/three — e.g. '@pixi/sound', 'gsap'). Resolved by the editor's " +
241
- 'host-namespace registry into module namespaces when known (D-P1 — the manifest ' +
242
- 'carries data, not code); an unregistered specifier falls back to the open ' +
243
- "project's own node_modules (D-Z3), served " +
244
- 'as a verbatim iframe importmap URL. Throws a named error if neither resolves it ' +
245
- '(iframe-reachable only).',
246
- ),
247
- pixiModuleUrl: z
248
- .string()
249
- .optional()
250
- .describe(
251
- 'PIXI-ONLY: standalone matching-major pixi ESM URL to trap instead of the host ' +
252
- "pixi, for version-skewed games (e.g. a v6 game on a v8 host); this field's " +
253
- 'PRESENCE is how the skew is expressed (D-P2 — no separate strategy/tier for ' +
254
- 'version skew) (iframe-reachable only). Declaring this on a `kind: "three"` ' +
255
- 'root is schema-legal (this field is kind-agnostic here) but throws a NAMED ' +
256
- 'not-supported error at resolve — three has no version-skew mount this wave ' +
257
- '(D-W7: a hypothetical `threeModuleUrl` is explicitly parked, no consumer ' +
258
- 'exists).',
259
- ),
260
- bodyHtml: z
261
- .string()
262
- .optional()
263
- .describe(
264
- 'HTML injected into the iframe body before the game script boots (e.g. a ' +
265
- '`<div id="game-root">` the game expects to find) (iframe-reachable only).',
199
+ "How long the host waits for this game's first captured frame before the mount " +
200
+ 'FAILS by name. A game that needs a long boot (streamed world assets, a menu ' +
201
+ 'the player must clear) raises it; the default is 10s.',
266
202
  ),
267
203
  })
204
+ .strict()
268
205
  .describe(
269
206
  'Ingest adapter configuration for an unmodified game (a repo-vendored game or your ' +
270
207
  'own external folder)',
271
- )
272
- .superRefine((ingest, ctx) => {
273
- // The six iframe-reachable-multi fields only make sense for the
274
- // iframe-reachable-multi mount — reject them under any other
275
- // strategy (mirrors ui.ts's dead-field-under-wrong-variant pattern).
276
- const iframeOnlyFields: ReadonlyArray<
277
- readonly [
278
- key:
279
- | 'bundleUrl'
280
- | 'baseHref'
281
- | 'assetBaseUrl'
282
- | 'extraDeps'
283
- | 'pixiModuleUrl'
284
- | 'bodyHtml',
285
- present: boolean,
286
- ]
287
- > = [
288
- ['bundleUrl', ingest.bundleUrl !== undefined],
289
- ['baseHref', ingest.baseHref !== undefined],
290
- ['assetBaseUrl', ingest.assetBaseUrl !== undefined],
291
- ['extraDeps', ingest.extraDeps !== undefined],
292
- ['pixiModuleUrl', ingest.pixiModuleUrl !== undefined],
293
- ['bodyHtml', ingest.bodyHtml !== undefined],
294
- ];
295
- if (ingest.strategy !== 'iframe-reachable') {
296
- for (const [key, present] of iframeOnlyFields) {
297
- if (present) {
298
- ctx.addIssue({
299
- code: z.ZodIssueCode.custom,
300
- message:
301
- `\`${key}\` is only legal when strategy is 'iframe-reachable' (got ` +
302
- `"${ingest.strategy}") — bundleUrl/baseHref/assetBaseUrl/extraDeps/` +
303
- "pixiModuleUrl/bodyHtml are the iframe-reachable-multi mount's options " +
304
- '(canvas: ingest-iframe-2d.ts IframeReachableMultiOpts; three, D-W1: ' +
305
- 'ingest-iframe-reachable-adapter.ts IframeReachableBundleOpts) and have no ' +
306
- 'meaning under any other strategy.',
307
- path: [key],
308
- });
309
- }
310
- }
311
- return;
312
- }
313
- const hasBundleUrl = ingest.bundleUrl !== undefined;
314
- const hasEntryHtml = ingest.entryHtml !== undefined;
315
- if (hasBundleUrl === hasEntryHtml) {
316
- ctx.addIssue({
317
- code: z.ZodIssueCode.custom,
318
- message:
319
- "strategy 'iframe-reachable' requires EXACTLY ONE of `bundleUrl` (externalized " +
320
- 'multi-file bundle, the iframe-reachable-multi mount) or `entryHtml` (single-' +
321
- `file/legacy iframe entry) — ${hasBundleUrl ? 'both are present' : 'neither is present'}.`,
322
- path: hasBundleUrl ? ['bundleUrl'] : ['entryHtml'],
323
- });
324
- }
325
- }),
208
+ ),
326
209
  })
327
210
  .strict(),
328
211
  ]),
@@ -390,21 +273,7 @@ export const AdapterRootSchema = z
390
273
  .default('gated')
391
274
  .describe(
392
275
  'gated: host-driven loop (default). self-driven: this root drives its own loop ' +
393
- '(the "composited, unsynchronized" tier) — an axis independent of capability tier',
394
- ),
395
- capabilities: z
396
- .object({
397
- local: TierSchema.optional().describe(
398
- 'Declared capability tier when served via the local CLI (Vite pipeline); omitted -> derived (§4)',
399
- ),
400
- hosted: TierSchema.optional().describe(
401
- 'Declared capability tier when served hosted (no bundler: esbuild-wasm + externals only); omitted -> derived (§4)',
402
- ),
403
- })
404
- .optional()
405
- .describe(
406
- "Per-delivery-context capability tier declarations (§4). Declaring above the adapter's " +
407
- 'ceiling for that context is an error; declaring at or below it (including `unsupported`) is legal.',
276
+ '(composited, unsynchronized)',
408
277
  ),
409
278
  })
410
279
  .strict();
@@ -652,6 +521,28 @@ export const GameManifestSchema = z
652
521
  })
653
522
  .optional()
654
523
  .describe('Canvas resolution'),
524
+ rendering: z
525
+ .object({
526
+ antialias: z
527
+ .boolean()
528
+ .describe(
529
+ 'Whether every three root is built with a multisampled drawing buffer. This is the ' +
530
+ 'ONE render property a world cannot declare for itself (world3d-react/' +
531
+ 'renderer-config.ts): a WebGL context fixes its sample count at CREATION from this ' +
532
+ 'boolean, long before a world mounts, so it belongs to the PROJECT. The runtime ' +
533
+ 'reader is mount-manifest.ts, which threads it into createHostRenderer for each ' +
534
+ 'three root. WebGL exposes no sample COUNT — the implementation picks one (4x on ' +
535
+ 'every desktop browser measured), so a source engine that authored 8x/16x gets ' +
536
+ 'multisampling but not its exact count.',
537
+ ),
538
+ })
539
+ .strict()
540
+ .optional()
541
+ .describe(
542
+ 'Construction-time renderer properties, which no world can declare after the fact. ' +
543
+ 'Everything a world CAN declare (tone mapping, output colour space, clear colour, ' +
544
+ "shadow filter) lives on the world's own renderer config instead.",
545
+ ),
655
546
  debug: z
656
547
  .object({
657
548
  allowInProduction: z
package/src/pixi/index.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * PixiJS is opt-in: the engine core never imports it, so a three-only bundle
5
5
  * never pays for it. What lives here is what the host needs to mount and
6
6
  * inspect a PixiJS game it did not write — the render-call capture trap, the
7
- * in-realm and iframe mounts, the live display-tree authoring adapter, and the
7
+ * in-realm mount, the live display-tree authoring adapter, and the
8
8
  * Rapier-2D handle registry the editor's transform coordination reads.
9
9
  */
10
10
 
@@ -16,20 +16,7 @@ export {
16
16
  type Property2D,
17
17
  type Transform2DValue,
18
18
  } from './authoring';
19
- export {
20
- type ExtraDepsResolution2D,
21
- type IngestGame2D,
22
- type IngestMount2D,
23
- mountIngestGame2D,
24
- } from './ingest';
25
- export {
26
- type EmbedMount2D,
27
- type IframeReachableMount2D,
28
- type IframeReachableMultiOpts,
29
- mountIngestGame2DEmbed,
30
- mountIngestGame2DIframeReachable,
31
- mountIngestGame2DIframeReachableMulti,
32
- } from './ingest-iframe';
19
+ export { type IngestGame2D, type IngestMount2D, mountIngestGame2D } from './ingest';
33
20
  export {
34
21
  createPhysics2DRegistry,
35
22
  type Physics2DRefs,