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
Accept a generated material source for maps from a local program (#311) (#320)
Matthew Kissinger4404e35c5a0e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8c79276a..f02bbb5c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -25,6 +25,15 @@ does not publish a package.export and import. It is optional, and the key is omitted when absent, so existing records keeptheir revision ids. A record that carries it is refused by an engine older than this one, whosemanifest schema is strict.++- Materials accept a `generated` source for maps from a local deterministic program (#311). It+ needs no `assetUrl`, which is what forced an invented URL before, and requires a `generator`+ record: the program's name, version and sha256, its toolkit hashes, the seed when it takes one,+ and runtime versions. Kiln verifies the shape and the stored bytes, and does not run the+ generator or prove the bytes came from it. `external` still requires an HTTP(S) URL and existing+ records keep their revision ids. A record with this source is refused by an engine older than+ this one.+||||||| 8e08b9c||||||| cde4dfe## 1.6.0 (2026-10-27)diff --git a/dist/agent-run.mjs b/dist/agent-run.mjsindex bc014081..98a25a96 100644--- a/dist/agent-run.mjs+++ b/dist/agent-run.mjs@@ -5085,9 +5085,11 @@ function validateMaterialManifest(value) {throw new Error("Height derivation requires a normal map slot");if (canonicalMaterialJson(map.procedural.spec) !== canonicalMaterialJson(canonicalizeProceduralTextureSpecV2(map.procedural.spec)))throw new Error("Stored procedural material recipe must be canonical");+ if (source.kind === "generated")+ throw new Error("A recipe map cannot use a generated source; use a procedural source");if (source.kind !== "procedural" || map.originalFile || map.procedural.spec.usage !== map.usage || map.procedural.spec.size !== map.width || map.width !== map.height)throw new Error("Procedural material source or map convention mismatch");- } else if (source.kind !== "external" || !source.originalFiles.some((file) => file.name === map.originalFile)) {+ } else if (source.kind === "procedural" || !source.originalFiles.some((file) => file.name === map.originalFile)) {throw new Error("Material map must reference an original source file");}bytes += map.bytes;@@ -5189,6 +5191,8 @@ function validateMaterialManifestAny(value) {throw Error("Material map source/usage/convention mismatch");const recipe = map.recipe;if (recipe) {+ if (source.kind === "generated")+ throw Error("A recipe map cannot use a generated source; use a procedural source");if (source.kind !== "procedural" || map.originalFile)throw Error("Procedural/atlas map source convention mismatch");if (recipe.kind === "procedural") {@@ -5210,8 +5214,8 @@ function validateMaterialManifestAny(value) {pins.set(`${pin.resourceId}/${pin.revisionId}`, pin);}}- } else if (source.kind !== "external" || !source.originalFiles.some((f) => f.name === map.originalFile))- throw Error("External material source original file missing");+ } else if (source.kind === "procedural" || !source.originalFiles.some((f) => f.name === map.originalFile))+ throw Error(`${source.kind === "generated" ? "Generated" : "External"} material source original file missing`);bytes += map.bytes;pixels += map.width * map.height;}@@ -5241,7 +5245,7 @@ function validateMaterialRecordShapeAny(record) {}return manifest;}-var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text4, url, materialSourceSchema, materialTransformSchema, color2, count2, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, afterShape, reason = (error) => error instanceof Error ? error.message : String(error), samplerSchema, v3SpecSchema, atlasSpecSchema, atlasManifestSchema, materialMapPinSchema, materialRecipeV2Schema, materialManifestV2Schema, materialManifestAnySchema, materialLibraryPayloadV2Schema, materialLibraryPayloadAnySchema, proceduralMaterialDraftV2Schema, proceduralMaterialDraftAnySchema;+var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text4, url, materialGeneratorSchema, materialSourceSchema, materialTransformSchema, color2, count2, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, afterShape, reason = (error) => error instanceof Error ? error.message : String(error), samplerSchema, v3SpecSchema, atlasSpecSchema, atlasManifestSchema, materialMapPinSchema, materialRecipeV2Schema, materialManifestV2Schema, materialManifestAnySchema, materialLibraryPayloadV2Schema, materialLibraryPayloadAnySchema, proceduralMaterialDraftV2Schema, proceduralMaterialDraftAnySchema;var init_material_library = __esm(() => {init_procedural_material_v2();init_procedural_texture_v3_contract();@@ -5283,15 +5287,22 @@ var init_material_library = __esm(() => {materialLibraryHashSchema = z5.string().regex(/^sha256:[a-f0-9]{64}$/);text4 = z5.string().min(1).max(1000);url = z5.string().max(2000).url().refine((value) => /^https?:\/\//.test(value), "Provenance URL must be HTTP(S)");+ materialGeneratorSchema = z5.object({+ program: z5.object({ name: text4, version: text4, sha256: materialLibraryHashSchema }).strict(),+ toolkit: z5.array(z5.object({ name: text4, sha256: materialLibraryHashSchema }).strict()).max(32),+ seed: z5.number().int().optional(),+ runtimes: z5.array(z5.object({ name: text4, version: text4 }).strict()).min(1).max(32)+ }).strict();materialSourceSchema = z5.object({id: materialLibraryIdSchema,- kind: z5.enum(["external", "procedural"]),+ kind: z5.enum(["external", "procedural", "generated"]),provider: text4,creator: text4,assetId: text4.optional(),assetUrl: url.optional(),accessedAt: z5.string().datetime().optional(),license: z5.object({ spdx: text4, url, attribution: z5.string().max(4000) }).strict(),+ generator: materialGeneratorSchema.optional(),originalFiles: z5.array(z5.object({name: z5.string().min(1).max(200),sha256: materialLibraryHashSchema,@@ -5303,6 +5314,16 @@ var init_material_library = __esm(() => {code: "custom",message: "External materials require a source URL and original file hashes"});+ if (source.kind === "generated" && (!source.generator || !source.originalFiles.length))+ context.addIssue({+ code: "custom",+ message: "Generated materials require a generator record and original file hashes"+ });+ if (source.kind !== "generated" && source.generator)+ context.addIssue({+ code: "custom",+ message: "Only a generated material source carries a generator record"+ });if (new Set(source.originalFiles.map((file) => file.name)).size !== source.originalFiles.length)context.addIssue({ code: "custom", message: "Duplicate original filename" });});diff --git a/dist/build.json b/dist/build.jsonindex 571c18f0..72566cd9 100644--- a/dist/build.json+++ b/dist/build.json@@ -2,10 +2,10 @@"schemaVersion": 1,"entries": {"worker": {- "identity": "sha256:882ffe5778be825607fabf93b4a3737dbeab95994b459d7f2a34f007266eb21d",+ "identity": "sha256:34f79b576bec07a5eb9944495cd4926260346b7d57df7a8eee52ef30ea752447","engineVersion": "1.6.0","toolchain": "[email protected]",- "sourceHash": "241ce0a2373f40a575d9adc1f859760a2a1b5ecdbe939ef260cb2c2c5d4d9089",+ "sourceHash": "f34719998cf3aceed4e9d29a9e29e3093338af2c26835af59f38ad2ae7ac0048","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -37,13 +37,13 @@},"target": "node","file": "evaluator-worker.mjs",- "bundleHash": "sha256:967e226a32b2f5d0ae2ac29ca0c5643c95557f8549d5aef4dc4f637354e2dc2f"+ "bundleHash": "sha256:99c009df78ef1da11fa1232eedf6b97da6792b9dfe4852196fcb0dcabdea23eb"},"agent-run": {- "identity": "sha256:882ffe5778be825607fabf93b4a3737dbeab95994b459d7f2a34f007266eb21d",+ "identity": "sha256:34f79b576bec07a5eb9944495cd4926260346b7d57df7a8eee52ef30ea752447","engineVersion": "1.6.0","toolchain": "[email protected]",- "sourceHash": "241ce0a2373f40a575d9adc1f859760a2a1b5ecdbe939ef260cb2c2c5d4d9089",+ "sourceHash": "f34719998cf3aceed4e9d29a9e29e3093338af2c26835af59f38ad2ae7ac0048","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -75,13 +75,13 @@},"target": "node","file": "agent-run.mjs",- "bundleHash": "sha256:8068bed2f4ff84cc3b45d6fbc1b1216414d26c138f3ce412422dd310d0f20aac"+ "bundleHash": "sha256:258794a0ac9f55380be4f268eac6d3693545155f254e868fa57723f93b62996c"},"agent-providers": {- "identity": "sha256:882ffe5778be825607fabf93b4a3737dbeab95994b459d7f2a34f007266eb21d",+ "identity": "sha256:34f79b576bec07a5eb9944495cd4926260346b7d57df7a8eee52ef30ea752447","engineVersion": "1.6.0","toolchain": "[email protected]",- "sourceHash": "241ce0a2373f40a575d9adc1f859760a2a1b5ecdbe939ef260cb2c2c5d4d9089",+ "sourceHash": "f34719998cf3aceed4e9d29a9e29e3093338af2c26835af59f38ad2ae7ac0048","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -116,10 +116,10 @@"bundleHash": "sha256:9d6faf03d307321bc2e3bd5ce5bdee0bbbf61e0ebed8bfebfa1fb072287b83fa"},"mcp": {- "identity": "sha256:882ffe5778be825607fabf93b4a3737dbeab95994b459d7f2a34f007266eb21d",+ "identity": "sha256:34f79b576bec07a5eb9944495cd4926260346b7d57df7a8eee52ef30ea752447","engineVersion": "1.6.0","toolchain": "[email protected]",- "sourceHash": "241ce0a2373f40a575d9adc1f859760a2a1b5ecdbe939ef260cb2c2c5d4d9089",+ "sourceHash": "f34719998cf3aceed4e9d29a9e29e3093338af2c26835af59f38ad2ae7ac0048","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -154,10 +154,10 @@"bundleHash": "sha256:4c8f00a36bcc57be3ff7afb3df03646ffebdc355e7bb42478112aa2ac4c1319f"},"cli": {- "identity": "sha256:882ffe5778be825607fabf93b4a3737dbeab95994b459d7f2a34f007266eb21d",+ "identity": "sha256:34f79b576bec07a5eb9944495cd4926260346b7d57df7a8eee52ef30ea752447","engineVersion": "1.6.0","toolchain": "[email protected]",- "sourceHash": "241ce0a2373f40a575d9adc1f859760a2a1b5ecdbe939ef260cb2c2c5d4d9089",+ "sourceHash": "f34719998cf3aceed4e9d29a9e29e3093338af2c26835af59f38ad2ae7ac0048","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -189,13 +189,13 @@},"target": "node","file": "cli.mjs",- "bundleHash": "sha256:13b8c3cf6cc9fafeec5507fd2c25c2bcbcd313bae3dabd765657d9e6de2e1c0d"+ "bundleHash": "sha256:49f500e23d45bf835b538c33c0f21f8474c02d71f914b599365ec5c0b2a8cdec"},"engine": {- "identity": "sha256:882ffe5778be825607fabf93b4a3737dbeab95994b459d7f2a34f007266eb21d",+ "identity": "sha256:34f79b576bec07a5eb9944495cd4926260346b7d57df7a8eee52ef30ea752447","engineVersion": "1.6.0","toolchain": "[email protected]",- "sourceHash": "241ce0a2373f40a575d9adc1f859760a2a1b5ecdbe939ef260cb2c2c5d4d9089",+ "sourceHash": "f34719998cf3aceed4e9d29a9e29e3093338af2c26835af59f38ad2ae7ac0048","rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a","dependencyHash": "af916d063d319fe3c11d1acc13211950eea82bb5ebb87ae4eb60008d72fa7f10","dependencies": {@@ -227,7 +227,7 @@},"target": "node","file": "mcp-engine.mjs",- "bundleHash": "sha256:2800fce549841e9f2105a78e5fdf1ca992ed815c1d747c1301b99361c9b7a9fb"+ "bundleHash": "sha256:5dbd9e34a3f9e980874c850128dc192f9115c4345839165f364620889419f82e"}}}diff --git a/dist/cli.mjs b/dist/cli.mjsindex a12dedaf..cedd34c1 100644--- a/dist/cli.mjs+++ b/dist/cli.mjs@@ -4326,9 +4326,11 @@ function validateMaterialManifest(value) {throw new Error("Height derivation requires a normal map slot");if (canonicalMaterialJson(map.procedural.spec) !== canonicalMaterialJson(canonicalizeProceduralTextureSpecV2(map.procedural.spec)))throw new Error("Stored procedural material recipe must be canonical");+ if (source.kind === "generated")+ throw new Error("A recipe map cannot use a generated source; use a procedural source");if (source.kind !== "procedural" || map.originalFile || map.procedural.spec.usage !== map.usage || map.procedural.spec.size !== map.width || map.width !== map.height)throw new Error("Procedural material source or map convention mismatch");- } else if (source.kind !== "external" || !source.originalFiles.some((file) => file.name === map.originalFile)) {+ } else if (source.kind === "procedural" || !source.originalFiles.some((file) => file.name === map.originalFile)) {throw new Error("Material map must reference an original source file");}bytes += map.bytes;@@ -4430,6 +4432,8 @@ function validateMaterialManifestAny(value) {throw Error("Material map source/usage/convention mismatch");const recipe = map.recipe;if (recipe) {+ if (source.kind === "generated")+ throw Error("A recipe map cannot use a generated source; use a procedural source");if (source.kind !== "procedural" || map.originalFile)throw Error("Procedural/atlas map source convention mismatch");if (recipe.kind === "procedural") {@@ -4451,8 +4455,8 @@ function validateMaterialManifestAny(value) {pins.set(`${pin.resourceId}/${pin.revisionId}`, pin);}}- } else if (source.kind !== "external" || !source.originalFiles.some((f) => f.name === map.originalFile))- throw Error("External material source original file missing");+ } else if (source.kind === "procedural" || !source.originalFiles.some((f) => f.name === map.originalFile))+ throw Error(`${source.kind === "generated" ? "Generated" : "External"} material source original file missing`);bytes += map.bytes;pixels += map.width * map.height;}@@ -4482,7 +4486,7 @@ function validateMaterialRecordShapeAny(record) {}return manifest;}-var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text3, url, materialSourceSchema, materialTransformSchema, color2, count2, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, afterShape, reason = (error) => error instanceof Error ? error.message : String(error), samplerSchema, v3SpecSchema, atlasSpecSchema, atlasManifestSchema, materialMapPinSchema, materialRecipeV2Schema, materialManifestV2Schema, materialManifestAnySchema, materialLibraryPayloadV2Schema, materialLibraryPayloadAnySchema, proceduralMaterialDraftV2Schema, proceduralMaterialDraftAnySchema;+var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text3, url, materialGeneratorSchema, materialSourceSchema, materialTransformSchema, color2, count2, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, afterShape, reason = (error) => error instanceof Error ? error.message : String(error), samplerSchema, v3SpecSchema, atlasSpecSchema, atlasManifestSchema, materialMapPinSchema, materialRecipeV2Schema, materialManifestV2Schema, materialManifestAnySchema, materialLibraryPayloadV2Schema, materialLibraryPayloadAnySchema, proceduralMaterialDraftV2Schema, proceduralMaterialDraftAnySchema;var init_material_library = __esm(() => {init_procedural_material_v2();init_procedural_texture_v3_contract();@@ -4524,15 +4528,22 @@ var init_material_library = __esm(() => {materialLibraryHashSchema = z5.string().regex(/^sha256:[a-f0-9]{64}$/);text3 = z5.string().min(1).max(1000);url = z5.string().max(2000).url().refine((value) => /^https?:\/\//.test(value), "Provenance URL must be HTTP(S)");+ materialGeneratorSchema = z5.object({+ program: z5.object({ name: text3, version: text3, sha256: materialLibraryHashSchema }).strict(),+ toolkit: z5.array(z5.object({ name: text3, sha256: materialLibraryHashSchema }).strict()).max(32),+ seed: z5.number().int().optional(),+ runtimes: z5.array(z5.object({ name: text3, version: text3 }).strict()).min(1).max(32)+ }).strict();materialSourceSchema = z5.object({id: materialLibraryIdSchema,- kind: z5.enum(["external", "procedural"]),+ kind: z5.enum(["external", "procedural", "generated"]),provider: text3,creator: text3,assetId: text3.optional(),assetUrl: url.optional(),accessedAt: z5.string().datetime().optional(),license: z5.object({ spdx: text3, url, attribution: z5.string().max(4000) }).strict(),+ generator: materialGeneratorSchema.optional(),originalFiles: z5.array(z5.object({name: z5.string().min(1).max(200),sha256: materialLibraryHashSchema,@@ -4544,6 +4555,16 @@ var init_material_library = __esm(() => {code: "custom",message: "External materials require a source URL and original file hashes"});+ if (source.kind === "generated" && (!source.generator || !source.originalFiles.length))+ context.addIssue({+ code: "custom",+ message: "Generated materials require a generator record and original file hashes"+ });+ if (source.kind !== "generated" && source.generator)+ context.addIssue({+ code: "custom",+ message: "Only a generated material source carries a generator record"+ });if (new Set(source.originalFiles.map((file) => file.name)).size !== source.originalFiles.length)context.addIssue({ code: "custom", message: "Duplicate original filename" });});diff --git a/dist/evaluator-worker.mjs b/dist/evaluator-worker.mjsindex e5f71392..5f66fb5b 100644--- a/dist/evaluator-worker.mjs+++ b/dist/evaluator-worker.mjs@@ -32832,9 +32832,11 @@ function validateMaterialManifest(value) {throw new Error("Height derivation requires a normal map slot");if (canonicalMaterialJson(map.procedural.spec) !== canonicalMaterialJson(canonicalizeProceduralTextureSpecV2(map.procedural.spec)))throw new Error("Stored procedural material recipe must be canonical");+ if (source.kind === "generated")+ throw new Error("A recipe map cannot use a generated source; use a procedural source");if (source.kind !== "procedural" || map.originalFile || map.procedural.spec.usage !== map.usage || map.procedural.spec.size !== map.width || map.width !== map.height)throw new Error("Procedural material source or map convention mismatch");- } else if (source.kind !== "external" || !source.originalFiles.some((file) => file.name === map.originalFile)) {+ } else if (source.kind === "procedural" || !source.originalFiles.some((file) => file.name === map.originalFile)) {throw new Error("Material map must reference an original source file");}bytes += map.bytes;@@ -32906,6 +32908,8 @@ function validateMaterialManifestAny(value) {throw Error("Material map source/usage/convention mismatch");const recipe = map.recipe;if (recipe) {+ if (source.kind === "generated")+ throw Error("A recipe map cannot use a generated source; use a procedural source");if (source.kind !== "procedural" || map.originalFile)throw Error("Procedural/atlas map source convention mismatch");if (recipe.kind === "procedural") {@@ -32927,8 +32931,8 @@ function validateMaterialManifestAny(value) {pins.set(`${pin.resourceId}/${pin.revisionId}`, pin);}}- } else if (source.kind !== "external" || !source.originalFiles.some((f) => f.name === map.originalFile))- throw Error("External material source original file missing");+ } else if (source.kind === "procedural" || !source.originalFiles.some((f) => f.name === map.originalFile))+ throw Error(`${source.kind === "generated" ? "Generated" : "External"} material source original file missing`);bytes += map.bytes;pixels += map.width * map.height;}@@ -32958,7 +32962,7 @@ function validateMaterialRecordShapeAny(record) {}return manifest;}-var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text4, url, materialSourceSchema, materialTransformSchema, color2, count4, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, afterShape, reason = (error) => error instanceof Error ? error.message : String(error), samplerSchema, v3SpecSchema, atlasSpecSchema, atlasManifestSchema, materialMapPinSchema, materialRecipeV2Schema, materialManifestV2Schema, materialManifestAnySchema, materialLibraryPayloadV2Schema, materialLibraryPayloadAnySchema, proceduralMaterialDraftV2Schema, proceduralMaterialDraftAnySchema;+var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text4, url, materialGeneratorSchema, materialSourceSchema, materialTransformSchema, color2, count4, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, afterShape, reason = (error) => error instanceof Error ? error.message : String(error), samplerSchema, v3SpecSchema, atlasSpecSchema, atlasManifestSchema, materialMapPinSchema, materialRecipeV2Schema, materialManifestV2Schema, materialManifestAnySchema, materialLibraryPayloadV2Schema, materialLibraryPayloadAnySchema, proceduralMaterialDraftV2Schema, proceduralMaterialDraftAnySchema;var init_material_library = __esm(() => {init_procedural_material_v2();init_procedural_texture_v3_contract();@@ -33000,15 +33004,22 @@ var init_material_library = __esm(() => {materialLibraryHashSchema = z6.string().regex(/^sha256:[a-f0-9]{64}$/);text4 = z6.string().min(1).max(1000);url = z6.string().max(2000).url().refine((value) => /^https?:\/\//.test(value), "Provenance URL must be HTTP(S)");+ materialGeneratorSchema = z6.object({+ program: z6.object({ name: text4, version: text4, sha256: materialLibraryHashSchema }).strict(),+ toolkit: z6.array(z6.object({ name: text4, sha256: materialLibraryHashSchema }).strict()).max(32),+ seed: z6.number().int().optional(),+ runtimes: z6.array(z6.object({ name: text4, version: text4 }).strict()).min(1).max(32)+ }).strict();materialSourceSchema = z6.object({id: materialLibraryIdSchema,- kind: z6.enum(["external", "procedural"]),+ kind: z6.enum(["external", "procedural", "generated"]),provider: text4,creator: text4,assetId: text4.optional(),assetUrl: url.optional(),accessedAt: z6.string().datetime().optional(),license: z6.object({ spdx: text4, url, attribution: z6.string().max(4000) }).strict(),+ generator: materialGeneratorSchema.optional(),originalFiles: z6.array(z6.object({name: z6.string().min(1).max(200),sha256: materialLibraryHashSchema,@@ -33020,6 +33031,16 @@ var init_material_library = __esm(() => {code: "custom",message: "External materials require a source URL and original file hashes"});+ if (source.kind === "generated" && (!source.generator || !source.originalFiles.length))+ context.addIssue({+ code: "custom",+ message: "Generated materials require a generator record and original file hashes"+ });+ if (source.kind !== "generated" && source.generator)+ context.addIssue({+ code: "custom",+ message: "Only a generated material source carries a generator record"+ });if (new Set(source.originalFiles.map((file) => file.name)).size !== source.originalFiles.length)context.addIssue({ code: "custom", message: "Duplicate original filename" });});diff --git a/dist/mcp-engine.mjs b/dist/mcp-engine.mjsindex bb50dcc3..1cea2a0f 100644--- a/dist/mcp-engine.mjs+++ b/dist/mcp-engine.mjs@@ -1793,9 +1793,11 @@ function validateMaterialManifest(value) {throw new Error("Height derivation requires a normal map slot");if (canonicalMaterialJson(map.procedural.spec) !== canonicalMaterialJson(canonicalizeProceduralTextureSpecV2(map.procedural.spec)))throw new Error("Stored procedural material recipe must be canonical");+ if (source.kind === "generated")+ throw new Error("A recipe map cannot use a generated source; use a procedural source");if (source.kind !== "procedural" || map.originalFile || map.procedural.spec.usage !== map.usage || map.procedural.spec.size !== map.width || map.width !== map.height)throw new Error("Procedural material source or map convention mismatch");- } else if (source.kind !== "external" || !source.originalFiles.some((file) => file.name === map.originalFile)) {+ } else if (source.kind === "procedural" || !source.originalFiles.some((file) => file.name === map.originalFile)) {throw new Error("Material map must reference an original source file");}bytes += map.bytes;@@ -1897,6 +1899,8 @@ function validateMaterialManifestAny(value) {throw Error("Material map source/usage/convention mismatch");const recipe = map.recipe;if (recipe) {+ if (source.kind === "generated")+ throw Error("A recipe map cannot use a generated source; use a procedural source");if (source.kind !== "procedural" || map.originalFile)throw Error("Procedural/atlas map source convention mismatch");if (recipe.kind === "procedural") {@@ -1918,8 +1922,8 @@ function validateMaterialManifestAny(value) {pins.set(`${pin.resourceId}/${pin.revisionId}`, pin);}}- } else if (source.kind !== "external" || !source.originalFiles.some((f) => f.name === map.originalFile))- throw Error("External material source original file missing");+ } else if (source.kind === "procedural" || !source.originalFiles.some((f) => f.name === map.originalFile))+ throw Error(`${source.kind === "generated" ? "Generated" : "External"} material source original file missing`);bytes += map.bytes;pixels += map.width * map.height;}@@ -1949,7 +1953,7 @@ function validateMaterialRecordShapeAny(record) {}return manifest;}-var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text, url, materialSourceSchema, materialTransformSchema, color2, count, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, afterShape, reason = (error) => error instanceof Error ? error.message : String(error), samplerSchema, v3SpecSchema, atlasSpecSchema, atlasManifestSchema, materialMapPinSchema, materialRecipeV2Schema, materialManifestV2Schema, materialManifestAnySchema, materialLibraryPayloadV2Schema, materialLibraryPayloadAnySchema, proceduralMaterialDraftV2Schema, proceduralMaterialDraftAnySchema;+var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text, url, materialGeneratorSchema, materialSourceSchema, materialTransformSchema, color2, count, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, afterShape, reason = (error) => error instanceof Error ? error.message : String(error), samplerSchema, v3SpecSchema, atlasSpecSchema, atlasManifestSchema, materialMapPinSchema, materialRecipeV2Schema, materialManifestV2Schema, materialManifestAnySchema, materialLibraryPayloadV2Schema, materialLibraryPayloadAnySchema, proceduralMaterialDraftV2Schema, proceduralMaterialDraftAnySchema;var init_material_library = __esm(() => {init_procedural_material_v2();init_procedural_texture_v3_contract();@@ -1991,15 +1995,22 @@ var init_material_library = __esm(() => {materialLibraryHashSchema = z2.string().regex(/^sha256:[a-f0-9]{64}$/);text = z2.string().min(1).max(1000);url = z2.string().max(2000).url().refine((value) => /^https?:\/\//.test(value), "Provenance URL must be HTTP(S)");+ materialGeneratorSchema = z2.object({+ program: z2.object({ name: text, version: text, sha256: materialLibraryHashSchema }).strict(),+ toolkit: z2.array(z2.object({ name: text, sha256: materialLibraryHashSchema }).strict()).max(32),+ seed: z2.number().int().optional(),+ runtimes: z2.array(z2.object({ name: text, version: text }).strict()).min(1).max(32)+ }).strict();materialSourceSchema = z2.object({id: materialLibraryIdSchema,- kind: z2.enum(["external", "procedural"]),+ kind: z2.enum(["external", "procedural", "generated"]),provider: text,creator: text,assetId: text.optional(),assetUrl: url.optional(),accessedAt: z2.string().datetime().optional(),license: z2.object({ spdx: text, url, attribution: z2.string().max(4000) }).strict(),+ generator: materialGeneratorSchema.optional(),originalFiles: z2.array(z2.object({name: z2.string().min(1).max(200),sha256: materialLibraryHashSchema,@@ -2011,6 +2022,16 @@ var init_material_library = __esm(() => {code: "custom",message: "External materials require a source URL and original file hashes"});+ if (source.kind === "generated" && (!source.generator || !source.originalFiles.length))+ context.addIssue({+ code: "custom",+ message: "Generated materials require a generator record and original file hashes"+ });+ if (source.kind !== "generated" && source.generator)+ context.addIssue({+ code: "custom",+ message: "Only a generated material source carries a generator record"+ });if (new Set(source.originalFiles.map((file) => file.name)).size !== source.originalFiles.length)context.addIssue({ code: "custom", message: "Duplicate original filename" });});diff --git a/docs/material-library.md b/docs/material-library.mdindex 55ac9957..ec1f8a3b 100644--- a/docs/material-library.md+++ b/docs/material-library.md@@ -222,7 +222,15 @@ green and blue; occlusion must be separately bound if wanted. Metalness/roughnestheir texture channels, so use factors of one when the maps should control the full range.Every external map names an original source file with its hash and size. The source includes-provider, creator, URL and license. Derivations record the actual normalization steps and tool+provider, creator, URL and license. A map produced by a local deterministic program with no public+URL uses a `generated` source instead: the same fields, no URL required, and a required `generator`+record with the program's name, version and sha256, its toolkit files' hashes, the seed when it takes+one, and runtime name/version pairs. Kiln checks that record's shape, that each map names a file the+source lists, and the stored bytes against their hashes, as it does for external maps. It does not+run the generator or prove the bytes came from it; the record states a claim someone can reproduce.+Recipe maps use a `procedural` source, so a recipe on a `generated` source is refused, and+`material export --maps` copies the generator record into its sidecar with the other source fields.+Derivations record the actual normalization steps and toolversions. Procedural maps retain canonical recipes, seeds, recipe hashes, decoded pixel hashesand encoder version. The revision hash covers this metadata and the normalized map hashes.Changing bytes, seed, derivation, scale, or provenance creates a different revision.diff --git a/docs/procedural-surfaces-v3.md b/docs/procedural-surfaces-v3.mdindex 018d595c..9b37ac3e 100644--- a/docs/procedural-surfaces-v3.md+++ b/docs/procedural-surfaces-v3.md@@ -215,7 +215,7 @@ not establish acceptable motion, distant cutouts, or atlas gutter behavior.Read `shape:material-draft` and `shape:material-import` with Discovery for thecomplete runtime-validated fields. Sources keep explicit creator and licenserecords. The JSON authoring surface accepts no file paths, URLs to fetch, or-raw image bytes. Existing external image records enter through verified import.+raw image bytes. Existing external or generated image records enter through verified import.A normal-slot map with a V3 recipe of `usage: 'normal'` may add`derive: {"kind":"normal-from-height","strength":4}`. The compiled pixels arediff --git a/src/material-generated-source.test.ts b/src/material-generated-source.test.tsnew file mode 100644index 00000000..64a8010c--- /dev/null+++ b/src/material-generated-source.test.ts@@ -0,0 +1,209 @@+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';+import { createHash } from 'node:crypto';+import { mkdtemp, readFile, rm } from 'node:fs/promises';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import sharp from 'sharp';+import { materialSourceSchema } from './material-library';+import {+ createMaterialLibraryPayload,+ createMaterialRecordV1,+ createMaterialRecordV2,+ decodeMaterialLibraryPayload,+ FileMaterialLibrary,+} from './material-library-node';+import { exportMaterialMaps } from './material-map-export-node';++const digest = (bytes: Uint8Array | string) =>+ `sha256:${createHash('sha256').update(bytes).digest('hex')}` as const;++const generator = {+ program: { name: 'stone-maps.py', version: '3.1.0', sha256: digest('program') },+ toolkit: [{ name: 'cellular.py', sha256: digest('toolkit') }],+ seed: 41,+ runtimes: [+ { name: 'Python', version: '3.12.4' },+ { name: 'NumPy', version: '2.1.0' },+ ],+};+const license = {+ spdx: 'CC0-1.0',+ url: 'https://creativecommons.org/publicdomain/zero/1.0/',+ attribution: '',+};++let png: Uint8Array;+let root: string;+beforeAll(async () => {+ png = new Uint8Array(+ await sharp({+ create: { width: 4, height: 4, channels: 4, background: { r: 90, g: 80, b: 70, alpha: 1 } },+ })+ .png()+ .toBuffer(),+ );+ root = await mkdtemp(join(tmpdir(), 'kiln-material-generated-'));+});+afterAll(() => rm(root, { recursive: true, force: true }));++const source = (overrides: Record<string, unknown> = {}) => ({+ id: 'script',+ kind: 'generated' as const,+ provider: 'Castle project',+ creator: 'Test author',+ license,+ generator,+ originalFiles: [{ name: 'rock.base.png', sha256: digest(png), bytes: png.length }],+ ...overrides,+});+const draftV1 = (src: unknown = source(), originalFile = 'rock.base.png') =>+ ({+ materialId: 'rock',+ name: 'Rock',+ tileable: true,+ sources: [src],+ maps: [+ {+ slot: 'baseColor',+ sourceId: 'script',+ transforms: [],+ bytes: png,+ originalFile,+ },+ ],+ }) as never;+const draftV2 = (src: unknown = source(), originalFile = 'rock.base.png') => ({+ schemaVersion: 2,+ materialId: 'rock',+ name: 'Rock',+ tileable: true,+ sources: [src],+ maps: [+ {+ slot: 'baseColor',+ sourceId: 'script',+ transforms: [],+ sampler: { minFilter: 'linear', magFilter: 'linear', wrapS: 'repeat', wrapT: 'repeat' },+ bytes: png,+ originalFile,+ },+ ],+});+const recipeMap = {+ slot: 'baseColor',+ sourceId: 'script',+ transforms: [],+ procedural: {+ schemaVersion: 2,+ size: 4,+ usage: 'albedo',+ layers: [{ op: 'solid', color: 0x808080 }],+ },+};++describe.each([+ ['V1', (src?: unknown, file?: string) => createMaterialRecordV1(draftV1(src, file))],+ ['V2', (src?: unknown, file?: string) => createMaterialRecordV2(draftV2(src, file))],+])('%s generated material source (#311)', (name, create) => {+ test('supplied maps create a record that verifies, imports and round-trips', async () => {+ const record = await create();+ const library = new FileMaterialLibrary(join(root, `first-${name}`));+ const [saved] = await library.import([record]);+ expect(saved!.sources[0]).toMatchObject({ kind: 'generated', generator });++ const payload = await createMaterialLibraryPayload([+ await library.read('rock', saved!.revisionId),+ ]);+ const receiving = new FileMaterialLibrary(join(root, `second-${name}`));+ const [imported] = await receiving.import(+ await decodeMaterialLibraryPayload(JSON.parse(JSON.stringify(payload))),+ );+ expect(imported!.revisionId).toBe(saved!.revisionId);+ });++ test('the map export sidecar carries the generator record', async () => {+ const outDir = join(root, `maps-${name}`);+ await exportMaterialMaps(await create(), { outDir, size: 4, repeatMeters: 1 });+ const sidecar = JSON.parse(await readFile(join(outDir, 'rock.maps.json'), 'utf8'));+ expect(sidecar.material.sources[0].generator).toEqual(generator);+ });++ test('a map naming a file the source does not list is refused by name', async () => {+ await expect(create(source(), 'missing.png')).rejects.toThrow(/original.*file/i);+ });++ test('the generator is covered by the revision hash', async () => {+ const other = await create(source({ generator: { ...generator, seed: 42 } }));+ expect(other.manifest.revisionId).not.toBe((await create()).manifest.revisionId);+ });+});++describe('generated source rules (#311)', () => {+ const issues = (value: unknown) => {+ const parsed = materialSourceSchema.safeParse(value);+ return parsed.success ? [] : parsed.error.issues.map((issue) => issue.message);+ };++ test('a generated source needs no URL, and may still state one', () => {+ expect(issues(source())).toEqual([]);+ expect(issues(source({ assetUrl: 'https://example.com/rock' }))).toEqual([]);+ });++ test('a generated source without a generator is refused by name', () => {+ expect(issues(source({ generator: undefined })).join()).toMatch(/generator/i);+ });++ test('a generated source without original files is refused by name', () => {+ expect(issues(source({ originalFiles: [] })).join()).toMatch(/original file/i);+ });++ test('a generator on any other kind is refused by name', () => {+ expect(+ issues(+ source({+ kind: 'external',+ assetUrl: 'https://example.com/rock',+ }),+ ).join(),+ ).toMatch(/generator/i);+ expect(issues(source({ kind: 'procedural', originalFiles: [] })).join()).toMatch(/generator/i);+ });++ test.each([+ ['a program without a hash', { ...generator, program: { name: 'x', version: '1' } }],+ ['an unknown generator field', { ...generator, command: 'python x.py' }],+ ['a fractional seed', { ...generator, seed: 1.5 }],+ ['no runtimes', { ...generator, runtimes: [] }],+ ])('refuses %s', (_name, value) => {+ expect(issues(source({ generator: value })).length).toBeGreaterThan(0);+ });++ test('external still requires an HTTP(S) URL', () => {+ const external = {+ id: 'scan',+ kind: 'external',+ provider: 'P',+ creator: 'C',+ license,+ originalFiles: [{ name: 'a.png', sha256: digest('a'), bytes: 1 }],+ };+ expect(issues(external).join()).toMatch(/source URL/);+ expect(issues({ ...external, assetUrl: 'file:///tmp/a.png' }).join()).toMatch(/HTTP\(S\)/);+ expect(issues({ ...external, assetUrl: 'https://example.com/a' })).toEqual([]);+ });++ test('a recipe map on a generated source is refused by name', async () => {+ const draft = { ...(draftV1() as object), maps: [recipeMap] };+ await expect(createMaterialRecordV1(draft as never)).rejects.toThrow(/recipe.*generated/i);+ const v2 = {+ ...draftV2(),+ maps: [+ {+ ...recipeMap,+ sampler: { minFilter: 'linear', magFilter: 'linear', wrapS: 'repeat', wrapT: 'repeat' },+ },+ ],+ };+ await expect(createMaterialRecordV2(v2)).rejects.toThrow(/recipe.*generated/i);+ });+});diff --git a/src/material-library.ts b/src/material-library.tsindex c1dae328..396b4efc 100644--- a/src/material-library.ts+++ b/src/material-library.ts@@ -60,16 +60,29 @@ const url = z.max(2000).url().refine((value) => /^https?:\/\//.test(value), 'Provenance URL must be HTTP(S)');+/** What produced a `generated` source's files. Kiln records this; it never runs the program. */+export const materialGeneratorSchema = z+ .object({+ program: z.object({ name: text, version: text, sha256: materialLibraryHashSchema }).strict(),+ toolkit: z.array(z.object({ name: text, sha256: materialLibraryHashSchema }).strict()).max(32),+ seed: z.number().int().optional(),+ runtimes: z+ .array(z.object({ name: text, version: text }).strict())+ .min(1)+ .max(32),+ })+ .strict();export const materialSourceSchema = z.object({id: materialLibraryIdSchema,- kind: z.enum(['external', 'procedural']),+ kind: z.enum(['external', 'procedural', 'generated']),provider: text,creator: text,assetId: text.optional(),assetUrl: url.optional(),accessedAt: z.string().datetime().optional(),license: z.object({ spdx: text, url, attribution: z.string().max(4000) }).strict(),+ generator: materialGeneratorSchema.optional(),originalFiles: z.array(z@@ -93,6 +106,16 @@ export const materialSourceSchema = zcode: 'custom',message: 'External materials require a source URL and original file hashes',});+ if (source.kind === 'generated' && (!source.generator || !source.originalFiles.length))+ context.addIssue({+ code: 'custom',+ message: 'Generated materials require a generator record and original file hashes',+ });+ if (source.kind !== 'generated' && source.generator)+ context.addIssue({+ code: 'custom',+ message: 'Only a generated material source carries a generator record',+ });if (new Set(source.originalFiles.map((file) => file.name)).size !== source.originalFiles.length)context.addIssue({ code: 'custom', message: 'Duplicate original filename' });});@@ -427,6 +450,8 @@ export function validateMaterialManifest(value: unknown): MaterialManifestV1 {canonicalMaterialJson(canonicalizeProceduralTextureSpecV2(map.procedural.spec)))throw new Error('Stored procedural material recipe must be canonical');+ if (source.kind === 'generated')+ throw new Error('A recipe map cannot use a generated source; use a procedural source');if (source.kind !== 'procedural' ||map.originalFile ||@@ -436,7 +461,7 @@ export function validateMaterialManifest(value: unknown): MaterialManifestV1 {)throw new Error('Procedural material source or map convention mismatch');} else if (- source.kind !== 'external' ||+ source.kind === 'procedural' ||!source.originalFiles.some((file) => file.name === map.originalFile)) {throw new Error('Material map must reference an original source file');@@ -742,6 +767,8 @@ export function validateMaterialManifestAny(value: unknown): MaterialManifest {throw Error('Material map source/usage/convention mismatch');const recipe = map.recipe;if (recipe) {+ if (source.kind === 'generated')+ throw Error('A recipe map cannot use a generated source; use a procedural source');if (source.kind !== 'procedural' || map.originalFile)throw Error('Procedural/atlas map source convention mismatch');if (recipe.kind === 'procedural') {@@ -784,10 +811,12 @@ export function validateMaterialManifestAny(value: unknown): MaterialManifest {}}} else if (- source.kind !== 'external' ||+ source.kind === 'procedural' ||!source.originalFiles.some((f) => f.name === map.originalFile))- throw Error('External material source original file missing');+ throw Error(+ `${source.kind === 'generated' ? 'Generated' : 'External'} material source original file missing`,+ );bytes += map.bytes;pixels += map.width * map.height;}