Build and revise procedural 3D assets with your coding agent. Local MCP server, CLI and TypeScript engine with rendered review, editable source and GLB export.
JavaScript 3d3d-assets3d-modelingagent-skillsagent-toolsai-agentsasset-pipelinecligame-assetsglbgltfmcpmcp-servermodel-context-protocolprocedural-generationprocedural-modelingtext-to-3dthreejstypescript
feat: add exact-byte integration manifests (#5)
Matthew Kissinger3e0b1c6c6d90
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 83b47c91..8406622b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -5,6 +5,19 @@ for the consuming app's lockfile + tarball provenance, not public npm releases.## [Unreleased]+### Added+- **Browser-safe GLB integration manifest.** Every `renderGLB` / `renderSceneToGLB`+ result now carries `kiln.integration-manifest.v1`: artifact SHA-256, metre/+Y-up+ coordinate semantics, world bounds, ground offset, role, render metrics, and+ structural-validator counts. `inspectGlbIntegration(bytes)` derives the same+ contract from finished bytes without executing model-authored source.++### Fixed+- **Explicit default scenes on exported GLBs.** Generated and composed artifacts now+ set the glTF default scene, and optimize/palette rewrites repair legacy files whose+ first scene existed without being selected. Consumers no longer have to guess which+ scene to mount.+## [0.6.0] — 2026-07-12### Addeddiff --git a/README.md b/README.mdindex 60b02edb..186e368e 100644--- a/README.md+++ b/README.md@@ -60,8 +60,17 @@ The engine ships TypeScript source (Bun/tsx transpile on the fly); consume by su| `@kiln/engine/primitives` | the 70+ primitive/helper registry || `@kiln/engine/prompt`, `/prompt-api`, `/list-primitives` | system-prompt generation + catalog || `@kiln/engine/metrics`, `/inspect` | instanceability grade + scene-structure analysis |+| `@kiln/engine/contracts` | browser-safe asset and integration contracts, including `IntegrationManifestV1` || `@kiln/engine/composer`, `/composer/agent` | THREE-free scene-composition core (placement model, layout, overlap, DSL) + its Strands agent loop (`runKilnComposer`) |+Finished renders include `integrationManifest`, a versioned sidecar with the artifact+hash, metres/+Y-up axes, bounds, grounding offset, selected default scene, role, render+metrics, and structural QA. Consumers that only have GLB bytes can derive the same+sidecar with `inspectGlbIntegration(bytes)` from `@kiln/engine/render`; the inspection+path parses the artifact and never executes model-authored source code. Visual quality+remains explicitly `not_assessed` until a browser QA loop evaluates the asset in its+actual scene.+## DependenciesRuntime: `three`, `@gltf-transform/*`, `manifold-3d` (CSG, WASM), `three-subdivide`,diff --git a/src/__tests__/architecture-expansion-gate.test.ts b/src/__tests__/architecture-expansion-gate.test.tsindex 5680c68e..ae3cda19 100644--- a/src/__tests__/architecture-expansion-gate.test.ts+++ b/src/__tests__/architecture-expansion-gate.test.ts@@ -1228,41 +1228,41 @@ describe('W8 G-ROOF-EXPAND provider-free gate', () => {]),} as const;expect(report.artifactSemanticSha256).toEqual([- 'a210322f7a1a0073fddb7f7c48b0288442d5ec6b98c33032db72f66d9b740e34',- '12e028d767f2d1e19ab64113f952deb6a56367271286911fee7be26ff03c5852',- '029687b67413db72ece48fba6c8f85114814afa8c8deebd235ddb25db1b0e6ef',- '670872b2b0bd62a0fb355fb61ef268e12a29d15bcf8ca09bcb7f9f1037e20cb9',- '600e7c4c1f34d8b728f694eae03ece435c7966729e3b9674593869b7b10473a5',- 'a4e76914d66511dbad26fd36f46f25691d44c6a1574c0fa0d8faaecb83d19f66',- '2577c71fb6f46f27610d3acd686bad4f7611ad02e2a107b90e05e795b4e5958b',- '3519cec73addc4dcdc0e6b79950fc9f0b507a4b8f0a33ea781d11be629d6a26b',- '6247086fccc059579dbdfc96cb2ccefceed306c8b50ab245c66ba4034b82aa8c',- '7fc30d3390625c99294ca0a244938cc68485964bb7c63eb26e49f281fc15dcae',- 'cc646b14c11a4a4b26de45245d8fa922787dd2c26879992a757b31f523b34bbe',- 'b87f86e1004c6b6ef7ac266ee94c2e2e996bc1294bade8f3bb3a4ea6aa7d9900',- 'bba5d72fbe0f52be853dd3c2ad7b3aceb9cbeec3de4aa9a8087a488bac7d59d3',- 'ecbeb7f9d9244e9b8445b82b1e210975f7575743235be7ce7a7e627e39706b55',- '16f536684cdf91f1194cb308495dfc3a25c5254b43c8099f48101043014eaa16',- '12b51a2e37c7f81465f8124e8f9079bb61398bb23d1190d24c1559d8e8938a51',+ '8ef5dde9dd55cae9c191520ce796b02883fec5372fddfd5330595203d7df816e',+ 'cf6ebcb813e489a6f85598a3595b185e88049c2a577a2487a90512ab86d84ffc',+ '811f166ee84858210b5c814548e9123eb5f096c6237bf9ebce59d4fb6e78deaa',+ '7e75eff22ba18aaca067997c64aa5ee95ccb994be235bc80a057b0a6c5714f5f',+ '5d5eea27ea6d18170b02a90d93a6ffd187bbaebb59d61e8259c713f7a5ab45e1',+ '91be9f341bb32719b0d0ac633b4afd8bff04fef9f9f51d6278080246f4771571',+ '26ff3a12225c2e1e8006953148ee35165f1e9c1600a00cd48614f7a0ba8c02f3',+ 'b7b8d0b93180bdd9dd6c121a206ad16173d665af1469dc9596404243191d1f8e',+ '7da52ab2f2bbd34d48874ad820282eed4debdce992ce01512a0f0b619c45553b',+ '9a9ae3f4aa2a26014ca82a4e2befc2d6ff2d7823f91f03fbc2b696d6569f2968',+ 'daaef40184ee572c665a88379f86ee68fcd004adb08cb0dc782cd5d420988c27',+ 'ee2dfc1f5687ef9c93643c71a2802f3a66db76569372a4586ad215f28ac15eb0',+ 'a6dd13db58ce6623c85d12d9240d78aeae93e4240598786fb554fdd6bd898c39',+ '881fe2bc7bebe25cc9e23f08f4a3824920bd0133d347d85dec27b931e400eb1c',+ '98edae5f31ab323530e80f11ee321c608924b56804c0430d1569bcf3f957d868',+ 'ef0c35aa4b374129c28ef63a6bbda1018786f8f22146bf7ed8056954664587a4',]);expect(report.uvArtifactSemanticSha256).toEqual([- 'dab3f0f17bda49ed1801b88529a1b221e179b71700d8859b95b19cdcfe2c392b',- 'd415e2749d00e6ae04711ab3c2306ef4cd67e5b3aacfbda1a689a9955f880829',- '76069a8313069ad54c3a5cf45f6879792971dcf0083f06d5f914e0619ac2a873',- '140a97a58f0e90d906e2cdf641e3f737b688c63ee936782ee773135620e7792c',- '7a3d6847eed2298432b55858b708bd2918bd1e710308d11f45dd784a145ec183',- 'e691c37018c29c04dae64b0e1e9149cbcb4f8daacba97caab72e5f8bfc617809',- '65f2a3b650cad6d3a2547b4f76c39b5f713313f90ade1244783e5e0db97041c8',- '7e7c17826e5ccb64eaea56e4192748ecffaac71153ecc0af00db1005cfe35962',+ '4e945b321eb8e1ef058454ec2be04fe12dcce0a0f82bd5adce67809be07d9e8c',+ '1b237305e0a2d4fcb605edfddf2d1ba6798946227b2c4f6adf42eed4170f454a',+ 'a8a01f015dbbfb830306311cf056def7a2b648ebf21e090f02ede0022a0938c8',+ '0ed7afed454ade27e7e852fd047c77a5eca2b16ff01bdbd13cb228d963139a31',+ '95c65fe529f271be203da5db6f7bfa552939fc63ea58b4530636163e08a77c23',+ 'a3b06dbc560224a3d05b59655d47bb4f370f553154dccc6288ae1f656d1c781c',+ 'fe0c383ca2027ea6642e4a3773e47923b13914ec55a421d51f291cd16e4f2028',+ '6f4f4ba10f1028ba8cde301f153200da34bebc58ba7d8a971f0b2b8338aaa177',]);expect(sha256(canonicalJson(report.artifactSemanticSha256))).toBe(- '820b282c4bf970f2a13e2c83291456e645ef9c0f93d7d11083d07cd3c86112f3',+ '35397ac0dbc9f395d31f1c83275553c227f6ef9bb9725301c264878cbcaf0ddd',);expect(sha256(canonicalJson(report.uvArtifactSemanticSha256))).toBe(- '89f915d17dd4d763cd2681018c01dab6312b77509e6a14c7d36fb67595cae393',+ '5b1e21ecdf2fa71a83757daf144c4334cb154dedf057aeb07f0c9c4c33fe2204',);expect(sha256(canonicalJson(report))).toBe(- '6c8faff90464ab635f31b9bac1984d189c98dabc9b6c51ee30370af1c290483f',+ '6047b4aac6fd9d21392ca490185f2987adbda3135fba8966cc4f82d57c98a96f',);});});diff --git a/src/__tests__/integration-manifest.test.ts b/src/__tests__/integration-manifest.test.tsnew file mode 100644index 00000000..cad8facb--- /dev/null+++ b/src/__tests__/integration-manifest.test.ts@@ -0,0 +1,73 @@+import { describe, expect, test } from 'bun:test';+import { WebIO } from '@gltf-transform/core';++import { createRoot, boxGeo, createPart, gameMaterial } from '../primitives';+import { composeSceneGLB, inspectGlbIntegration, renderSceneToGLB } from '../render';++describe('GLB integration contract', () => {+ test('writes an explicit default scene and returns a deterministic integration manifest', async () => {+ const root = createRoot('IntegrationProbe');+ createPart('OffsetBody', boxGeo(2, 4, 6), gameMaterial(0x445566), {+ position: [1, 2, -3],+ parent: root,+ });++ const rendered = await renderSceneToGLB(root, {+ sceneName: 'Integration Scene',+ role: 'prop',+ });+ const document = await new WebIO().readBinary(rendered.bytes);++ expect(document.getRoot().getDefaultScene()?.getName()).toBe('Integration Scene');+ expect(rendered.integrationManifest).toEqual(+ expect.objectContaining({+ schemaVersion: 'kiln.integration-manifest.v1',+ artifactSha256: expect.stringMatching(/^[a-f0-9]{64}$/),+ units: 'm',+ axes: { forward: '+X', up: '+Y', right: '+Z' },+ defaultScene: { index: 0, name: 'Integration Scene' },+ requestedRole: 'prop',+ visualQa: 'not_assessed',+ }),+ );+ expect(rendered.integrationManifest.bounds.min).toEqual([0, 0, -6]);+ expect(rendered.integrationManifest.bounds.max).toEqual([2, 4, 0]);+ expect(rendered.integrationManifest.bounds.size).toEqual([2, 4, 6]);+ expect(rendered.integrationManifest.ground.offsetToGround).toBeCloseTo(0, 8);+ expect(rendered.integrationManifest.ground.grounded).toBe(true);+ expect(rendered.integrationManifest.structuralQa.hasDefaultScene).toBe(true);+ expect(rendered.integrationManifest.structuralQa.finiteBounds).toBe(true);++ expect(await inspectGlbIntegration(rendered.bytes, { requestedRole: 'prop' })).toEqual(+ rendered.integrationManifest,+ );+ });++ test('reports the offset needed to ground a floating artifact', async () => {+ const root = createRoot('FloatingProbe');+ createPart('FloatingBody', boxGeo(1, 2, 1), gameMaterial(0x778899), {+ position: [0, 4, 0],+ parent: root,+ });++ const rendered = await renderSceneToGLB(root, { role: 'poi' });+ expect(rendered.integrationManifest.bounds.min[1]).toBeCloseTo(3, 8);+ expect(rendered.integrationManifest.ground.offsetToGround).toBeCloseTo(-3, 8);+ expect(rendered.integrationManifest.ground.grounded).toBe(false);+ });++ test('composed artifacts also declare their default scene', async () => {+ const root = createRoot('ComposeProbe');+ createPart('Body', boxGeo(1, 1, 1), gameMaterial(0x223344), { parent: root });+ const part = await renderSceneToGLB(root);+ const composed = await composeSceneGLB([+ {+ bytes: part.bytes,+ transform: { pos: [0, 0, 0], rotDeg: [0, 0, 0], scale: [1, 1, 1] },+ },+ ]);++ const document = await new WebIO().readBinary(composed.bytes);+ expect(document.getRoot().getDefaultScene()?.getName()).toBe('Scene');+ });+});diff --git a/src/agent/generate.ts b/src/agent/generate.tsindex 84e66e1d..3e139dc2 100644--- a/src/agent/generate.ts+++ b/src/agent/generate.ts@@ -107,6 +107,7 @@ export interface GenerateKilnAssetResult {materialRecipeApplications?: NonNullable<RenderResult['materialRecipeApplications']>;materialResourceProvenance?: NonNullable<RenderResult['materialResourceProvenance']>;materialMetrics?: NonNullable<RenderResult['materialMetrics']>;+ integrationManifest: RenderResult['integrationManifest'];}/**@@ -261,5 +262,6 @@ export async function generateKilnAsset(? { materialResourceProvenance: render.materialResourceProvenance }: {}),...(render.materialMetrics ? { materialMetrics: render.materialMetrics } : {}),+ integrationManifest: render.integrationManifest,};}diff --git a/src/contracts/index.ts b/src/contracts/index.tsindex beb2e2ec..6c905ad4 100644--- a/src/contracts/index.ts+++ b/src/contracts/index.ts@@ -1,4 +1,5 @@export * from './asset';export * from './breadth';export * from './environment';+export * from './integration';export * from './semantic';diff --git a/src/contracts/integration.ts b/src/contracts/integration.tsnew file mode 100644index 00000000..4c9530a5--- /dev/null+++ b/src/contracts/integration.ts@@ -0,0 +1,57 @@+/** Browser-safe sidecar contract for placing and validating a finished Kiln GLB. */++export const INTEGRATION_ASSET_ROLES = [+ 'ground',+ 'building',+ 'wonder',+ 'poi',+ 'prop',+ 'fill',+ 'vehicle',+] as const;++export type IntegrationAssetRole = (typeof INTEGRATION_ASSET_ROLES)[number];++export interface IntegrationBoundsV1 {+ min: [number, number, number];+ max: [number, number, number];+ size: [number, number, number];+ center: [number, number, number];+}++export interface IntegrationManifestV1 {+ schemaVersion: 'kiln.integration-manifest.v1';+ analyzerVersion: 1;+ artifactSha256: string;+ units: 'm';+ axes: { forward: '+X'; up: '+Y'; right: '+Z' };+ bounds: IntegrationBoundsV1;+ pivot: { convention: 'author-origin'; position: [0, 0, 0] };+ ground: {+ groundY: 0;+ contactTolerance: 0.02;+ minY: number;+ offsetToGround: number;+ grounded: boolean;+ };+ defaultScene: { index: number; name: string };+ requestedRole?: IntegrationAssetRole;+ assessedRole?: IntegrationAssetRole;+ renderMetrics: {+ triangles: number;+ drawCalls: number;+ uniqueGeometries: number;+ uniqueMaterials: number;+ textureCount: number;+ transparentMaterials: number;+ skinned: boolean;+ };+ structuralQa: {+ hasDefaultScene: boolean;+ finiteBounds: boolean;+ validatorErrors: number;+ validatorWarnings: number;+ };+ /** Visual composition/usability is deliberately assessed by browser QA, not inferred here. */+ visualQa: 'not_assessed';+}diff --git a/src/render.ts b/src/render.tsindex 0b81fdca..8e09bac1 100644--- a/src/render.ts+++ b/src/render.ts@@ -49,6 +49,8 @@ import {validateSemanticMetadataV1,type AssetCategory,type AssetIntentV1,+ type IntegrationAssetRole,+ type IntegrationManifestV1,} from './contracts';import {assertFinalGlbValid,@@ -156,9 +158,94 @@ const TYPE_VEC4: AccessorTypeStr = 'VEC4';* snap to roads) and Kiln City density budgeting. Semantic — cannot be recomputed* from GLB bytes, so it travels in provenance. See plan/05-product-depth.md §3.4.*/-export type AssetRole = 'ground' | 'building' | 'wonder' | 'poi' | 'prop' | 'fill' | 'vehicle';+export type AssetRole = IntegrationAssetRole;export type { SnapPaletteSlot } from './palette-snap';+const GROUND_CONTACT_TOLERANCE = 0.02;++function ensureDefaultScene(doc: Document): GtScene | undefined {+ const root = doc.getRoot();+ const scene = root.getDefaultScene() ?? root.listScenes()[0];+ if (scene && !root.getDefaultScene()) root.setDefaultScene(scene);+ return scene;+}++async function sha256Hex(bytes: Uint8Array): Promise<string> {+ const digest = await globalThis.crypto.subtle.digest('SHA-256', new Uint8Array(bytes).buffer);+ return [...new Uint8Array(digest)].map((value) => value.toString(16).padStart(2, '0')).join('');+}++/** Inspect finished bytes without executing model-authored source code. */+export async function inspectGlbIntegration(+ bytes: Uint8Array,+ opts: {+ requestedRole?: IntegrationAssetRole;+ assessedRole?: IntegrationAssetRole;+ validation?: KhronosGltfValidationReport;+ } = {},+): Promise<IntegrationManifestV1 | undefined> {+ const doc = await engineIO().readBinary(bytes);+ const root = doc.getRoot();+ const explicitDefault = root.getDefaultScene();+ const scene = explicitDefault ?? root.listScenes()[0];+ if (!scene) return undefined;++ const { min, max } = getBounds(scene);+ const finiteBounds = min.every(Number.isFinite) && max.every(Number.isFinite);+ if (!finiteBounds) return undefined;+ const metrics = collectGlbMetrics(doc);+ const validation = opts.validation ?? (await validateFinalGlbBytes(bytes));+ const scenes = root.listScenes();+ const minTuple: [number, number, number] = [min[0]!, min[1]!, min[2]!];+ const maxTuple: [number, number, number] = [max[0]!, max[1]!, max[2]!];+ const minY = minTuple[1];++ return {+ schemaVersion: 'kiln.integration-manifest.v1',+ analyzerVersion: 1,+ artifactSha256: await sha256Hex(bytes),+ units: 'm',+ axes: { forward: '+X', up: '+Y', right: '+Z' },+ bounds: {+ min: minTuple,+ max: maxTuple,+ size: [maxTuple[0] - minTuple[0], maxTuple[1] - minTuple[1], maxTuple[2] - minTuple[2]],+ center: [+ (minTuple[0] + maxTuple[0]) / 2,+ (minTuple[1] + maxTuple[1]) / 2,+ (minTuple[2] + maxTuple[2]) / 2,+ ],+ },+ pivot: { convention: 'author-origin', position: [0, 0, 0] },+ ground: {+ groundY: 0,+ contactTolerance: GROUND_CONTACT_TOLERANCE,+ minY,+ offsetToGround: -minY,+ grounded: Math.abs(minY) <= GROUND_CONTACT_TOLERANCE,+ },+ defaultScene: { index: scenes.indexOf(scene), name: scene.getName() },+ ...(opts.requestedRole ? { requestedRole: opts.requestedRole } : {}),+ ...(opts.assessedRole ? { assessedRole: opts.assessedRole } : {}),+ renderMetrics: {+ triangles: metrics.triangles,+ drawCalls: metrics.drawCalls,+ uniqueGeometries: metrics.uniqueGeometries,+ uniqueMaterials: metrics.uniqueMaterials,+ textureCount: metrics.textureCount,+ transparentMaterials: metrics.transparentMaterials,+ skinned: metrics.skinned,+ },+ structuralQa: {+ hasDefaultScene: explicitDefault !== null,+ finiteBounds,+ validatorErrors: validation.issues.numErrors,+ validatorWarnings: validation.issues.numWarnings,+ },+ visualQa: 'not_assessed',+ };+}+export interface KilnCodeMeta {name?: string;category?: string;@@ -704,6 +791,7 @@ export interface RenderResult {materialMetrics?: MaterialMetricsV1;materialRecipeApplications?: MaterialRecipeApplicationProvenanceV1[];materialResourceProvenance?: MaterialResourceProvenanceV1[];+ integrationManifest: IntegrationManifestV1;}/**@@ -780,6 +868,7 @@ export interface RenderSceneResult {materialMetrics?: MaterialMetricsV1;materialRecipeApplications?: MaterialRecipeApplicationProvenanceV1[];materialResourceProvenance?: MaterialResourceProvenanceV1[];+ integrationManifest: IntegrationManifestV1;}export interface RenderSceneOptions {@@ -1013,7 +1102,8 @@ export async function renderSceneToGLB(const nodeMap = new Map<string, GtNode>();const rootNode = bridgeNode(doc, buf, root, matCache, nodeMap, meshCache, texCache);- doc.createScene(opts.sceneName ?? 'Scene').addChild(rootNode);+ const gltfScene = doc.createScene(opts.sceneName ?? 'Scene').addChild(rootNode);+ doc.getRoot().setDefaultScene(gltfScene);if (clips.length > 0) {bridgeAnimations(doc, buf, clips, nodeMap, warnings);@@ -1103,6 +1193,7 @@ export async function renderSceneToGLB(}const io = engineIO();+ ensureDefaultScene(doc);const bytes = await io.writeBinary(doc);const gltfValidation = await validateFinalGlbBytes(bytes);const finalGltfReport = appendFinalGltfQa(intent, sceneQaReport, gltfValidation);@@ -1128,6 +1219,12 @@ export async function renderSceneToGLB();}+ const integrationManifest = await inspectGlbIntegration(bytes, {+ ...(opts.role ? { requestedRole: opts.role } : {}),+ validation: gltfValidation,+ });+ if (!integrationManifest) throw new Error('renderSceneToGLB: final GLB has no measurable scene');+let diagnosticViews: CapturedDiagnosticV1[] | undefined;if (intent.category === 'character' && intent.character) {try {@@ -1169,6 +1266,7 @@ export async function renderSceneToGLB(...(materialMetrics ? { materialMetrics } : {}),...(materialRecipeApplications.length ? { materialRecipeApplications } : {}),...(materialResourceProvenance.length ? { materialResourceProvenance } : {}),+ integrationManifest,};}@@ -1230,6 +1328,7 @@ export async function renderGLB(...(scene.materialResourceProvenance? { materialResourceProvenance: scene.materialResourceProvenance }: {}),+ integrationManifest: scene.integrationManifest,};}@@ -1310,6 +1409,7 @@ export async function optimizeGlbBytes(}if (mode) summary = await consolidateMaterials(doc, mode);if (!summary && !instancing) return undefined;+ ensureDefaultScene(doc);const outBytes = await io.writeBinary(doc);const gltfValidation = await assertFinalGlbValid(outBytes);let report: InstanceabilityReport | undefined;@@ -1422,6 +1522,7 @@ export async function snapGlbToPalette(drawsBefore: before.drawCalls,drawsAfter: after.drawCalls,};+ ensureDefaultScene(doc);const outBytes = await io.writeBinary(doc);const gltfValidation = await assertFinalGlbValid(outBytes);let report: InstanceabilityReport | undefined;@@ -1523,6 +1624,7 @@ export async function composeSceneGLB(const io = engineIO();const master = new Document();const masterScene = master.createScene(opts.sceneName ?? 'Scene');+ master.getRoot().setDefaultScene(masterScene);let composed = 0;for (let i = 0; i < parts.length; i++) {@@ -1589,6 +1691,7 @@ export async function composeSceneGLB(}const metrics = collectGlbMetrics(master);+ ensureDefaultScene(master);const bytes = await io.writeBinary(master);const gltfValidation = await assertFinalGlbValid(bytes, 'scene.glb');for (const issue of gltfValidation.issues.messages) {