Skip to content

armgit / kiln

Public Imported from GitHub
0

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.

fix(materials): name the rule in validation errors (#198) (#214)

Matthew Kissinger5ddc3b71237f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95f0094a..9d0359fd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,13 @@ does not publish a package.
## Unreleased
+- Name the rule in material validation errors ([#198](https://github.com/instruktlabs/kiln/issues/198)).
+ Sampler, procedural V3 and atlas checks now report the canonicalizer's reason (for
+ example "stamps are supported only for color usages albedo and emissive") instead of a
+ bare "Invalid input", and run only after the field checks pass. Tool input errors drop
+ a bare parent "Invalid input" line when an issue inside that record already explains
+ the failure.
+
## 1.3.1 (2026-10-17)
- Document private security reporting, include the policy in distributed
diff --git a/dist/agent-run.mjs b/dist/agent-run.mjs
index 7d1f3006..db7e1d0c 100644
--- a/dist/agent-run.mjs
+++ b/dist/agent-run.mjs
@@ -5034,6 +5034,17 @@ function materialLibraryPortableSpec(manifest) {
]))
};
}
+function admittedBy(label, canonicalize, stored) {
+ return (value, context) => {
+ try {
+ const canonical = canonicalize(value);
+ if (stored && canonicalMaterialJson(value) !== canonicalMaterialJson(canonical))
+ context.addIssue({ code: "custom", message: `${label} must be stored in canonical form.` });
+ } catch (error) {
+ context.addIssue({ code: "custom", message: reason(error) });
+ }
+ };
+}
function materialRecordDependencyPins(manifest) {
return manifest.schemaVersion === 1 ? [] : manifest.dependencies.map((pin) => ({ ...pin }));
}
@@ -5108,7 +5119,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, 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, 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();
@@ -5330,27 +5341,10 @@ var init_material_library = __esm(() => {
}).strict()).max(MATERIAL_LIBRARY_LIMITS.maxPayloadRecords)
}).strict();
authoringSchemas = makeMaterialAuthoringSchemas(materialProceduralSpecSchema);
- samplerSchema = authoringSchemas.portableSamplerSchema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizePortableSamplerV1(value));
- } catch {
- return false;
- }
- });
- v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizeProceduralTextureSpecV3(value));
- } catch {
- return false;
- }
- });
- atlasSpecSchema = authoringSchemas.canonicalTextureAtlasSpecV1Schema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizeTextureAtlasSpecV1(value));
- } catch {
- return false;
- }
- });
+ afterShape = { when: (payload) => !payload.issues.length };
+ samplerSchema = authoringSchemas.portableSamplerSchema.superRefine(admittedBy("sampler", canonicalizePortableSamplerV1, true), afterShape);
+ v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.superRefine(admittedBy("procedural V3 spec", canonicalizeProceduralTextureSpecV3, true), afterShape);
+ atlasSpecSchema = authoringSchemas.canonicalTextureAtlasSpecV1Schema.superRefine(admittedBy("atlas spec", canonicalizeTextureAtlasSpecV1, true), afterShape);
atlasManifestSchema = authoringSchemas.textureAtlasManifestV1Schema;
materialMapPinSchema = z4.object({
resourceId: materialLibraryIdSchema,
@@ -5377,11 +5371,11 @@ var init_material_library = __esm(() => {
try {
validateTextureAtlasManifestV1(recipe.manifest, recipe.spec);
if (recipe.compilerId !== recipe.manifest.compilerId)
- throw new Error("compiler id");
- } catch {
- context.addIssue({ code: "custom", message: "Invalid stored atlas manifest" });
+ throw new Error(`recipe compilerId ${recipe.compilerId} does not match the manifest's ${recipe.manifest.compilerId}.`);
+ } catch (error) {
+ context.addIssue({ code: "custom", message: `stored atlas manifest: ${reason(error)}` });
}
- })
+ }, afterShape)
]);
materialManifestV2Schema = materialManifestSchema.omit({ schemaVersion: true, maps: true }).extend({
schemaVersion: z4.literal(2),
@@ -5410,23 +5404,9 @@ var init_material_library = __esm(() => {
sampler: samplerSchema,
procedural: z4.union([
materialProceduralSpecSchema,
- authoringSchemas.proceduralTextureSpecV3Schema.refine((value) => {
- try {
- canonicalizeProceduralTextureSpecV3(value);
- return true;
- } catch {
- return false;
- }
- })
+ authoringSchemas.proceduralTextureSpecV3Schema.superRefine(admittedBy("procedural V3 spec", canonicalizeProceduralTextureSpecV3, false), afterShape)
]).optional(),
- atlas: authoringSchemas.textureAtlasSpecV1Schema.refine((value) => {
- try {
- canonicalizeTextureAtlasSpecV1(value);
- return true;
- } catch {
- return false;
- }
- }).optional()
+ atlas: authoringSchemas.textureAtlasSpecV1Schema.superRefine(admittedBy("atlas spec", canonicalizeTextureAtlasSpecV1, false), afterShape).optional()
}).strict().refine((map) => map.procedural !== undefined !== (map.atlas !== undefined), "Supply exactly one procedural or atlas recipe")).min(1).max(5)
}).strict();
proceduralMaterialDraftAnySchema = z4.union([
@@ -44377,7 +44357,12 @@ function describeInputError(tool, error, options = {}) {
const where = nested.length ? nested.join("; ") : `nested shapes: kiln_discover({ ids: ['shape:...'] })`;
return `${tool}: invalid input. ${lines.join("; ")}${issues.length > 6 ? `; ${issues.length - 6} more` : ""}.${takes} Check the field names and values against the ${tool} schema; ${where}.`;
}
-function flattenIssues(issues, prefix = []) {
+var BARE_REFINE_MESSAGE = "Invalid input";
+function flattenIssues(issues) {
+ const flat = flattenIssuePaths(issues);
+ return flat.filter(({ code, path, message }) => !(code === "custom" && message === BARE_REFINE_MESSAGE && flat.some((other) => other.path.length > path.length && path.every((key, i) => other.path[i] === key)))).map(({ path, message }) => `${path.join(".") || "input"}: ${message}`);
+}
+function flattenIssuePaths(issues, prefix = []) {
const lines = [];
for (const raw of issues) {
const issue = raw;
@@ -44385,10 +44370,10 @@ function flattenIssues(issues, prefix = []) {
const branches = Array.isArray(issue.errors) ? issue.errors.filter((branch) => Array.isArray(branch) && branch.length) : [];
if (issue.code === "invalid_union" && branches.length) {
const closest = branches.reduce((best, branch) => branch.length < best.length ? branch : best);
- lines.push(...flattenIssues(closest, path));
+ lines.push(...flattenIssuePaths(closest, path));
continue;
}
- lines.push(`${path.join(".") || "input"}: ${issue.message ?? "invalid"}`);
+ lines.push({ code: issue.code, path, message: issue.message ?? "invalid" });
}
return lines;
}
diff --git a/dist/build.json b/dist/build.json
index c866e4c3..48bb9122 100644
--- a/dist/build.json
+++ b/dist/build.json
@@ -2,12 +2,12 @@
"schemaVersion": 1,
"entries": {
"worker": {
- "identity": "sha256:d191b9c64e679e2175cda0dc8dd86ca11870c2955991ce7510bf350d62b37db4",
+ "identity": "sha256:c55e4770c4f6b08d2ef248aad2a565d8cf5a84fbab28844185f3b6a2517b58d6",
"engineVersion": "1.3.1",
"toolchain": "[email protected]",
- "sourceHash": "947ee3b7e06e83a91fa377b06d065e5d994cba34eabac8715bb7575172184711",
+ "sourceHash": "839c118eca6d3c8267927a71715c5af5ffda22e14815e9c777985c23d9f50f1b",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
- "dependencyHash": "f17d705cc5de6856252c111542b8e179695cc81448eb1e2fc4d9a343ed42370a",
+ "dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3",
"dependencies": {
"@gltf-transform/core": "4.5.1",
"@gltf-transform/extensions": "4.5.1",
@@ -21,31 +21,31 @@
"gltf-validator": "2.0.0-dev.3.10",
"jsonc-parser": "3.3.1",
"manifold-3d": "^3.5.4",
- "meshoptimizer": "1.1.1",
+ "meshoptimizer": "1.3.0",
"minisearch": "7.2.0",
"pngjs": "7.0.0",
"sharp": "^0.35.5",
- "smol-toml": "1.9.0",
+ "smol-toml": "1.9.1",
"three": "0.186.1",
"three-subdivide": "1.1.5",
"xatlasjs": "^0.2.0",
"zod": "^4.6.5"
},
"optionalDependencies": {
- "@napi-rs/canvas": "1.0.10",
+ "@napi-rs/canvas": "1.0.11",
"webgpu": "0.6.2"
},
"target": "node",
"file": "evaluator-worker.mjs",
- "bundleHash": "sha256:07c1b534e55c1b7fa3fb8136028209b5187fbc9b16810970ad76140ea436696e"
+ "bundleHash": "sha256:fde0385cddab538fe68c221db77dbc6b8944679a2e86a42ba213e6524ed33cce"
},
"agent-run": {
- "identity": "sha256:d191b9c64e679e2175cda0dc8dd86ca11870c2955991ce7510bf350d62b37db4",
+ "identity": "sha256:c55e4770c4f6b08d2ef248aad2a565d8cf5a84fbab28844185f3b6a2517b58d6",
"engineVersion": "1.3.1",
"toolchain": "[email protected]",
- "sourceHash": "947ee3b7e06e83a91fa377b06d065e5d994cba34eabac8715bb7575172184711",
+ "sourceHash": "839c118eca6d3c8267927a71715c5af5ffda22e14815e9c777985c23d9f50f1b",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
- "dependencyHash": "f17d705cc5de6856252c111542b8e179695cc81448eb1e2fc4d9a343ed42370a",
+ "dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3",
"dependencies": {
"@gltf-transform/core": "4.5.1",
"@gltf-transform/extensions": "4.5.1",
@@ -59,31 +59,31 @@
"gltf-validator": "2.0.0-dev.3.10",
"jsonc-parser": "3.3.1",
"manifold-3d": "^3.5.4",
- "meshoptimizer": "1.1.1",
+ "meshoptimizer": "1.3.0",
"minisearch": "7.2.0",
"pngjs": "7.0.0",
"sharp": "^0.35.5",
- "smol-toml": "1.9.0",
+ "smol-toml": "1.9.1",
"three": "0.186.1",
"three-subdivide": "1.1.5",
"xatlasjs": "^0.2.0",
"zod": "^4.6.5"
},
"optionalDependencies": {
- "@napi-rs/canvas": "1.0.10",
+ "@napi-rs/canvas": "1.0.11",
"webgpu": "0.6.2"
},
"target": "node",
"file": "agent-run.mjs",
- "bundleHash": "sha256:45a9bf04ade13494e77465880b22402d9e248ad4fe316407c228db6b0c6b8a8c"
+ "bundleHash": "sha256:0c22ff4c9e973855110098f05b87a151389a8ae93332af8e6e96b3c14689ed46"
},
"agent-providers": {
- "identity": "sha256:d191b9c64e679e2175cda0dc8dd86ca11870c2955991ce7510bf350d62b37db4",
+ "identity": "sha256:c55e4770c4f6b08d2ef248aad2a565d8cf5a84fbab28844185f3b6a2517b58d6",
"engineVersion": "1.3.1",
"toolchain": "[email protected]",
- "sourceHash": "947ee3b7e06e83a91fa377b06d065e5d994cba34eabac8715bb7575172184711",
+ "sourceHash": "839c118eca6d3c8267927a71715c5af5ffda22e14815e9c777985c23d9f50f1b",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
- "dependencyHash": "f17d705cc5de6856252c111542b8e179695cc81448eb1e2fc4d9a343ed42370a",
+ "dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3",
"dependencies": {
"@gltf-transform/core": "4.5.1",
"@gltf-transform/extensions": "4.5.1",
@@ -97,18 +97,18 @@
"gltf-validator": "2.0.0-dev.3.10",
"jsonc-parser": "3.3.1",
"manifold-3d": "^3.5.4",
- "meshoptimizer": "1.1.1",
+ "meshoptimizer": "1.3.0",
"minisearch": "7.2.0",
"pngjs": "7.0.0",
"sharp": "^0.35.5",
- "smol-toml": "1.9.0",
+ "smol-toml": "1.9.1",
"three": "0.186.1",
"three-subdivide": "1.1.5",
"xatlasjs": "^0.2.0",
"zod": "^4.6.5"
},
"optionalDependencies": {
- "@napi-rs/canvas": "1.0.10",
+ "@napi-rs/canvas": "1.0.11",
"webgpu": "0.6.2"
},
"target": "node",
@@ -116,12 +116,12 @@
"bundleHash": "sha256:9d6faf03d307321bc2e3bd5ce5bdee0bbbf61e0ebed8bfebfa1fb072287b83fa"
},
"mcp": {
- "identity": "sha256:d191b9c64e679e2175cda0dc8dd86ca11870c2955991ce7510bf350d62b37db4",
+ "identity": "sha256:c55e4770c4f6b08d2ef248aad2a565d8cf5a84fbab28844185f3b6a2517b58d6",
"engineVersion": "1.3.1",
"toolchain": "[email protected]",
- "sourceHash": "947ee3b7e06e83a91fa377b06d065e5d994cba34eabac8715bb7575172184711",
+ "sourceHash": "839c118eca6d3c8267927a71715c5af5ffda22e14815e9c777985c23d9f50f1b",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
- "dependencyHash": "f17d705cc5de6856252c111542b8e179695cc81448eb1e2fc4d9a343ed42370a",
+ "dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3",
"dependencies": {
"@gltf-transform/core": "4.5.1",
"@gltf-transform/extensions": "4.5.1",
@@ -135,18 +135,18 @@
"gltf-validator": "2.0.0-dev.3.10",
"jsonc-parser": "3.3.1",
"manifold-3d": "^3.5.4",
- "meshoptimizer": "1.1.1",
+ "meshoptimizer": "1.3.0",
"minisearch": "7.2.0",
"pngjs": "7.0.0",
"sharp": "^0.35.5",
- "smol-toml": "1.9.0",
+ "smol-toml": "1.9.1",
"three": "0.186.1",
"three-subdivide": "1.1.5",
"xatlasjs": "^0.2.0",
"zod": "^4.6.5"
},
"optionalDependencies": {
- "@napi-rs/canvas": "1.0.10",
+ "@napi-rs/canvas": "1.0.11",
"webgpu": "0.6.2"
},
"target": "node",
@@ -154,12 +154,12 @@
"bundleHash": "sha256:814d8ca81116501226d58e6f67c6ab2fe408c5ad08ae4995d6136b22ad024285"
},
"cli": {
- "identity": "sha256:d191b9c64e679e2175cda0dc8dd86ca11870c2955991ce7510bf350d62b37db4",
+ "identity": "sha256:c55e4770c4f6b08d2ef248aad2a565d8cf5a84fbab28844185f3b6a2517b58d6",
"engineVersion": "1.3.1",
"toolchain": "[email protected]",
- "sourceHash": "947ee3b7e06e83a91fa377b06d065e5d994cba34eabac8715bb7575172184711",
+ "sourceHash": "839c118eca6d3c8267927a71715c5af5ffda22e14815e9c777985c23d9f50f1b",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
- "dependencyHash": "f17d705cc5de6856252c111542b8e179695cc81448eb1e2fc4d9a343ed42370a",
+ "dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3",
"dependencies": {
"@gltf-transform/core": "4.5.1",
"@gltf-transform/extensions": "4.5.1",
@@ -173,31 +173,31 @@
"gltf-validator": "2.0.0-dev.3.10",
"jsonc-parser": "3.3.1",
"manifold-3d": "^3.5.4",
- "meshoptimizer": "1.1.1",
+ "meshoptimizer": "1.3.0",
"minisearch": "7.2.0",
"pngjs": "7.0.0",
"sharp": "^0.35.5",
- "smol-toml": "1.9.0",
+ "smol-toml": "1.9.1",
"three": "0.186.1",
"three-subdivide": "1.1.5",
"xatlasjs": "^0.2.0",
"zod": "^4.6.5"
},
"optionalDependencies": {
- "@napi-rs/canvas": "1.0.10",
+ "@napi-rs/canvas": "1.0.11",
"webgpu": "0.6.2"
},
"target": "node",
"file": "cli.mjs",
- "bundleHash": "sha256:ae308a69bc0403d06afe903f12974bfecc22ecbbfacced32f724f3bc72610a63"
+ "bundleHash": "sha256:10e7e9128a08023cfc8a4fcc89181e2d5a6bf482ca7d9a51184b80e727e2ae41"
},
"engine": {
- "identity": "sha256:d191b9c64e679e2175cda0dc8dd86ca11870c2955991ce7510bf350d62b37db4",
+ "identity": "sha256:c55e4770c4f6b08d2ef248aad2a565d8cf5a84fbab28844185f3b6a2517b58d6",
"engineVersion": "1.3.1",
"toolchain": "[email protected]",
- "sourceHash": "947ee3b7e06e83a91fa377b06d065e5d994cba34eabac8715bb7575172184711",
+ "sourceHash": "839c118eca6d3c8267927a71715c5af5ffda22e14815e9c777985c23d9f50f1b",
"rendererSourceHash": "27927c48b377f7694251a76c0cecd05216fcbbb8a7d03e8bf2bd681dabb5573a",
- "dependencyHash": "f17d705cc5de6856252c111542b8e179695cc81448eb1e2fc4d9a343ed42370a",
+ "dependencyHash": "20b5b45a138ab83d340e78729d1a427bdc9b8aeadc47c5f7acf907eab43377f3",
"dependencies": {
"@gltf-transform/core": "4.5.1",
"@gltf-transform/extensions": "4.5.1",
@@ -211,23 +211,23 @@
"gltf-validator": "2.0.0-dev.3.10",
"jsonc-parser": "3.3.1",
"manifold-3d": "^3.5.4",
- "meshoptimizer": "1.1.1",
+ "meshoptimizer": "1.3.0",
"minisearch": "7.2.0",
"pngjs": "7.0.0",
"sharp": "^0.35.5",
- "smol-toml": "1.9.0",
+ "smol-toml": "1.9.1",
"three": "0.186.1",
"three-subdivide": "1.1.5",
"xatlasjs": "^0.2.0",
"zod": "^4.6.5"
},
"optionalDependencies": {
- "@napi-rs/canvas": "1.0.10",
+ "@napi-rs/canvas": "1.0.11",
"webgpu": "0.6.2"
},
"target": "node",
"file": "mcp-engine.mjs",
- "bundleHash": "sha256:f3dcdceed72bd0868f34160dd9037b9154cbe945655e04eaf87676c02f44e929"
+ "bundleHash": "sha256:f4b71dcdfc203877f72031a1afbc78a5b5ee4f6fdcb51ea09066aaab03eac222"
}
}
}
diff --git a/dist/cli.mjs b/dist/cli.mjs
index ffb39846..e1f3b22a 100644
--- a/dist/cli.mjs
+++ b/dist/cli.mjs
@@ -15062,6 +15062,17 @@ function materialLibraryPortableSpec(manifest) {
]))
};
}
+function admittedBy(label, canonicalize, stored) {
+ return (value, context) => {
+ try {
+ const canonical = canonicalize(value);
+ if (stored && canonicalMaterialJson(value) !== canonicalMaterialJson(canonical))
+ context.addIssue({ code: "custom", message: `${label} must be stored in canonical form.` });
+ } catch (error) {
+ context.addIssue({ code: "custom", message: reason(error) });
+ }
+ };
+}
function materialRecordDependencyPins(manifest) {
return manifest.schemaVersion === 1 ? [] : manifest.dependencies.map((pin) => ({ ...pin }));
}
@@ -15136,7 +15147,7 @@ function validateMaterialRecordShapeAny(record) {
}
return manifest;
}
-var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text3, url, materialSourceSchema, materialTransformSchema, color2, count3, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, 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, materialSourceSchema, materialTransformSchema, color2, count3, 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();
@@ -15358,27 +15369,10 @@ var init_material_library = __esm(() => {
}).strict()).max(MATERIAL_LIBRARY_LIMITS.maxPayloadRecords)
}).strict();
authoringSchemas = makeMaterialAuthoringSchemas(materialProceduralSpecSchema);
- samplerSchema = authoringSchemas.portableSamplerSchema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizePortableSamplerV1(value));
- } catch {
- return false;
- }
- });
- v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizeProceduralTextureSpecV3(value));
- } catch {
- return false;
- }
- });
- atlasSpecSchema = authoringSchemas.canonicalTextureAtlasSpecV1Schema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizeTextureAtlasSpecV1(value));
- } catch {
- return false;
- }
- });
+ afterShape = { when: (payload) => !payload.issues.length };
+ samplerSchema = authoringSchemas.portableSamplerSchema.superRefine(admittedBy("sampler", canonicalizePortableSamplerV1, true), afterShape);
+ v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.superRefine(admittedBy("procedural V3 spec", canonicalizeProceduralTextureSpecV3, true), afterShape);
+ atlasSpecSchema = authoringSchemas.canonicalTextureAtlasSpecV1Schema.superRefine(admittedBy("atlas spec", canonicalizeTextureAtlasSpecV1, true), afterShape);
atlasManifestSchema = authoringSchemas.textureAtlasManifestV1Schema;
materialMapPinSchema = z4.object({
resourceId: materialLibraryIdSchema,
@@ -15405,11 +15399,11 @@ var init_material_library = __esm(() => {
try {
validateTextureAtlasManifestV1(recipe.manifest, recipe.spec);
if (recipe.compilerId !== recipe.manifest.compilerId)
- throw new Error("compiler id");
- } catch {
- context.addIssue({ code: "custom", message: "Invalid stored atlas manifest" });
+ throw new Error(`recipe compilerId ${recipe.compilerId} does not match the manifest's ${recipe.manifest.compilerId}.`);
+ } catch (error) {
+ context.addIssue({ code: "custom", message: `stored atlas manifest: ${reason(error)}` });
}
- })
+ }, afterShape)
]);
materialManifestV2Schema = materialManifestSchema.omit({ schemaVersion: true, maps: true }).extend({
schemaVersion: z4.literal(2),
@@ -15438,23 +15432,9 @@ var init_material_library = __esm(() => {
sampler: samplerSchema,
procedural: z4.union([
materialProceduralSpecSchema,
- authoringSchemas.proceduralTextureSpecV3Schema.refine((value) => {
- try {
- canonicalizeProceduralTextureSpecV3(value);
- return true;
- } catch {
- return false;
- }
- })
+ authoringSchemas.proceduralTextureSpecV3Schema.superRefine(admittedBy("procedural V3 spec", canonicalizeProceduralTextureSpecV3, false), afterShape)
]).optional(),
- atlas: authoringSchemas.textureAtlasSpecV1Schema.refine((value) => {
- try {
- canonicalizeTextureAtlasSpecV1(value);
- return true;
- } catch {
- return false;
- }
- }).optional()
+ atlas: authoringSchemas.textureAtlasSpecV1Schema.superRefine(admittedBy("atlas spec", canonicalizeTextureAtlasSpecV1, false), afterShape).optional()
}).strict().refine((map) => map.procedural !== undefined !== (map.atlas !== undefined), "Supply exactly one procedural or atlas recipe")).min(1).max(5)
}).strict();
proceduralMaterialDraftAnySchema = z4.union([
@@ -47750,7 +47730,11 @@ function describeInputError(tool, error, options = {}) {
const where = nested.length ? nested.join("; ") : `nested shapes: kiln_discover({ ids: ['shape:...'] })`;
return `${tool}: invalid input. ${lines.join("; ")}${issues.length > 6 ? `; ${issues.length - 6} more` : ""}.${takes} Check the field names and values against the ${tool} schema; ${where}.`;
}
-function flattenIssues(issues, prefix = []) {
+function flattenIssues(issues) {
+ const flat = flattenIssuePaths(issues);
+ return flat.filter(({ code, path, message }) => !(code === "custom" && message === BARE_REFINE_MESSAGE && flat.some((other) => other.path.length > path.length && path.every((key, i) => other.path[i] === key)))).map(({ path, message }) => `${path.join(".") || "input"}: ${message}`);
+}
+function flattenIssuePaths(issues, prefix = []) {
const lines = [];
for (const raw of issues) {
const issue = raw;
@@ -47758,14 +47742,14 @@ function flattenIssues(issues, prefix = []) {
const branches = Array.isArray(issue.errors) ? issue.errors.filter((branch) => Array.isArray(branch) && branch.length) : [];
if (issue.code === "invalid_union" && branches.length) {
const closest = branches.reduce((best, branch) => branch.length < best.length ? branch : best);
- lines.push(...flattenIssues(closest, path));
+ lines.push(...flattenIssuePaths(closest, path));
continue;
}
- lines.push(`${path.join(".") || "input"}: ${issue.message ?? "invalid"}`);
+ lines.push({ code: issue.code, path, message: issue.message ?? "invalid" });
}
return lines;
}
-var list = (fields) => fields.length <= 1 ? fields.join("") : `${fields.slice(0, -1).join(", ")} and ${fields.at(-1)}`, nestedRecordDescription = (purpose, shape) => `${purpose} Shape: kiln_discover({ ids: ['${shape}'] }).`;
+var list = (fields) => fields.length <= 1 ? fields.join("") : `${fields.slice(0, -1).join(", ")} and ${fields.at(-1)}`, nestedRecordDescription = (purpose, shape) => `${purpose} Shape: kiln_discover({ ids: ['${shape}'] }).`, BARE_REFINE_MESSAGE = "Invalid input";
// src/tools/projects.ts
import { z as z17 } from "zod";
diff --git a/dist/evaluator-worker.mjs b/dist/evaluator-worker.mjs
index c48c83c4..977fefee 100644
--- a/dist/evaluator-worker.mjs
+++ b/dist/evaluator-worker.mjs
@@ -30690,6 +30690,17 @@ function materialLibraryResourceId(manifest, slot) {
throw new Error("Unknown material slot");
return `kiln.library.${manifest.revisionId.slice(7)}.${slotNames[slot]}`;
}
+function admittedBy(label, canonicalize, stored) {
+ return (value, context) => {
+ try {
+ const canonical = canonicalize(value);
+ if (stored && canonicalMaterialJson(value) !== canonicalMaterialJson(canonical))
+ context.addIssue({ code: "custom", message: `${label} must be stored in canonical form.` });
+ } catch (error) {
+ context.addIssue({ code: "custom", message: reason(error) });
+ }
+ };
+}
function materialRecordDependencyPins(manifest) {
return manifest.schemaVersion === 1 ? [] : manifest.dependencies.map((pin) => ({ ...pin }));
}
@@ -30764,7 +30775,7 @@ function validateMaterialRecordShapeAny(record) {
}
return manifest;
}
-var MATERIAL_LIBRARY_LIMITS, MATERIAL_LIBRARY_SLOTS, MATERIAL_LIBRARY_USAGE, slotNames, materialLibraryIdSchema, materialLibraryHashSchema, text3, url, materialSourceSchema, materialTransformSchema, color2, count4, layerCommon, materialProceduralSpecSchema, materialNormalDerivationSchema, proceduralSchema, parametersSchema, materialManifestSchema, proceduralMaterialDraftSchema, materialLibraryPayloadSchema, authoringSchemas, 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, 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();
@@ -30986,27 +30997,10 @@ var init_material_library = __esm(() => {
}).strict()).max(MATERIAL_LIBRARY_LIMITS.maxPayloadRecords)
}).strict();
authoringSchemas = makeMaterialAuthoringSchemas(materialProceduralSpecSchema);
- samplerSchema = authoringSchemas.portableSamplerSchema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizePortableSamplerV1(value));
- } catch {
- return false;
- }
- });
- v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizeProceduralTextureSpecV3(value));
- } catch {
- return false;
- }
- });
- atlasSpecSchema = authoringSchemas.canonicalTextureAtlasSpecV1Schema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizeTextureAtlasSpecV1(value));
- } catch {
- return false;
- }
- });
+ afterShape = { when: (payload) => !payload.issues.length };
+ samplerSchema = authoringSchemas.portableSamplerSchema.superRefine(admittedBy("sampler", canonicalizePortableSamplerV1, true), afterShape);
+ v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.superRefine(admittedBy("procedural V3 spec", canonicalizeProceduralTextureSpecV3, true), afterShape);
+ atlasSpecSchema = authoringSchemas.canonicalTextureAtlasSpecV1Schema.superRefine(admittedBy("atlas spec", canonicalizeTextureAtlasSpecV1, true), afterShape);
atlasManifestSchema = authoringSchemas.textureAtlasManifestV1Schema;
materialMapPinSchema = z5.object({
resourceId: materialLibraryIdSchema,
@@ -31033,11 +31027,11 @@ var init_material_library = __esm(() => {
try {
validateTextureAtlasManifestV1(recipe.manifest, recipe.spec);
if (recipe.compilerId !== recipe.manifest.compilerId)
- throw new Error("compiler id");
- } catch {
- context.addIssue({ code: "custom", message: "Invalid stored atlas manifest" });
+ throw new Error(`recipe compilerId ${recipe.compilerId} does not match the manifest's ${recipe.manifest.compilerId}.`);
+ } catch (error) {
+ context.addIssue({ code: "custom", message: `stored atlas manifest: ${reason(error)}` });
}
- })
+ }, afterShape)
]);
materialManifestV2Schema = materialManifestSchema.omit({ schemaVersion: true, maps: true }).extend({
schemaVersion: z5.literal(2),
@@ -31066,23 +31060,9 @@ var init_material_library = __esm(() => {
sampler: samplerSchema,
procedural: z5.union([
materialProceduralSpecSchema,
- authoringSchemas.proceduralTextureSpecV3Schema.refine((value) => {
- try {
- canonicalizeProceduralTextureSpecV3(value);
- return true;
- } catch {
- return false;
- }
- })
+ authoringSchemas.proceduralTextureSpecV3Schema.superRefine(admittedBy("procedural V3 spec", canonicalizeProceduralTextureSpecV3, false), afterShape)
]).optional(),
- atlas: authoringSchemas.textureAtlasSpecV1Schema.refine((value) => {
- try {
- canonicalizeTextureAtlasSpecV1(value);
- return true;
- } catch {
- return false;
- }
- }).optional()
+ atlas: authoringSchemas.textureAtlasSpecV1Schema.superRefine(admittedBy("atlas spec", canonicalizeTextureAtlasSpecV1, false), afterShape).optional()
}).strict().refine((map) => map.procedural !== undefined !== (map.atlas !== undefined), "Supply exactly one procedural or atlas recipe")).min(1).max(5)
}).strict();
proceduralMaterialDraftAnySchema = z5.union([
diff --git a/dist/mcp-engine.mjs b/dist/mcp-engine.mjs
index 945a96f9..02172d4f 100644
--- a/dist/mcp-engine.mjs
+++ b/dist/mcp-engine.mjs
@@ -1855,6 +1855,17 @@ function materialLibraryPortableSpec(manifest) {
]))
};
}
+function admittedBy(label, canonicalize, stored) {
+ return (value, context) => {
+ try {
+ const canonical = canonicalize(value);
+ if (stored && canonicalMaterialJson(value) !== canonicalMaterialJson(canonical))
+ context.addIssue({ code: "custom", message: `${label} must be stored in canonical form.` });
+ } catch (error) {
+ context.addIssue({ code: "custom", message: reason(error) });
+ }
+ };
+}
function materialRecordDependencyPins(manifest) {
return manifest.schemaVersion === 1 ? [] : manifest.dependencies.map((pin) => ({ ...pin }));
}
@@ -1929,7 +1940,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, 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, 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();
@@ -2151,27 +2162,10 @@ var init_material_library = __esm(() => {
}).strict()).max(MATERIAL_LIBRARY_LIMITS.maxPayloadRecords)
}).strict();
authoringSchemas = makeMaterialAuthoringSchemas(materialProceduralSpecSchema);
- samplerSchema = authoringSchemas.portableSamplerSchema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizePortableSamplerV1(value));
- } catch {
- return false;
- }
- });
- v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizeProceduralTextureSpecV3(value));
- } catch {
- return false;
- }
- });
- atlasSpecSchema = authoringSchemas.canonicalTextureAtlasSpecV1Schema.refine((value) => {
- try {
- return canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizeTextureAtlasSpecV1(value));
- } catch {
- return false;
- }
- });
+ afterShape = { when: (payload) => !payload.issues.length };
+ samplerSchema = authoringSchemas.portableSamplerSchema.superRefine(admittedBy("sampler", canonicalizePortableSamplerV1, true), afterShape);
+ v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.superRefine(admittedBy("procedural V3 spec", canonicalizeProceduralTextureSpecV3, true), afterShape);
+ atlasSpecSchema = authoringSchemas.canonicalTextureAtlasSpecV1Schema.superRefine(admittedBy("atlas spec", canonicalizeTextureAtlasSpecV1, true), afterShape);
atlasManifestSchema = authoringSchemas.textureAtlasManifestV1Schema;
materialMapPinSchema = z2.object({
resourceId: materialLibraryIdSchema,
@@ -2198,11 +2192,11 @@ var init_material_library = __esm(() => {
try {
validateTextureAtlasManifestV1(recipe.manifest, recipe.spec);
if (recipe.compilerId !== recipe.manifest.compilerId)
- throw new Error("compiler id");
- } catch {
- context.addIssue({ code: "custom", message: "Invalid stored atlas manifest" });
+ throw new Error(`recipe compilerId ${recipe.compilerId} does not match the manifest's ${recipe.manifest.compilerId}.`);
+ } catch (error) {
+ context.addIssue({ code: "custom", message: `stored atlas manifest: ${reason(error)}` });
}
- })
+ }, afterShape)
]);
materialManifestV2Schema = materialManifestSchema.omit({ schemaVersion: true, maps: true }).extend({
schemaVersion: z2.literal(2),
@@ -2231,23 +2225,9 @@ var init_material_library = __esm(() => {
sampler: samplerSchema,
procedural: z2.union([
materialProceduralSpecSchema,
- authoringSchemas.proceduralTextureSpecV3Schema.refine((value) => {
- try {
- canonicalizeProceduralTextureSpecV3(value);
- return true;
- } catch {
- return false;
- }
- })
+ authoringSchemas.proceduralTextureSpecV3Schema.superRefine(admittedBy("procedural V3 spec", canonicalizeProceduralTextureSpecV3, false), afterShape)
]).optional(),
- atlas: authoringSchemas.textureAtlasSpecV1Schema.refine((value) => {
- try {
- canonicalizeTextureAtlasSpecV1(value);
- return true;
- } catch {
- return false;
- }
- }).optional()
+ atlas: authoringSchemas.textureAtlasSpecV1Schema.superRefine(admittedBy("atlas spec", canonicalizeTextureAtlasSpecV1, false), afterShape).optional()
}).strict().refine((map) => map.procedural !== undefined !== (map.atlas !== undefined), "Supply exactly one procedural or atlas recipe")).min(1).max(5)
}).strict();
proceduralMaterialDraftAnySchema = z2.union([
@@ -48496,7 +48476,12 @@ function schemaFields(schema) {
const shape = schema?.shape;
return shape && typeof shape === "object" ? Object.keys(shape) : [];
}
-function flattenIssues(issues, prefix = []) {
+var BARE_REFINE_MESSAGE = "Invalid input";
+function flattenIssues(issues) {
+ const flat = flattenIssuePaths(issues);
+ return flat.filter(({ code, path, message }) => !(code === "custom" && message === BARE_REFINE_MESSAGE && flat.some((other) => other.path.length > path.length && path.every((key, i) => other.path[i] === key)))).map(({ path, message }) => `${path.join(".") || "input"}: ${message}`);
+}
+function flattenIssuePaths(issues, prefix = []) {
const lines = [];
for (const raw of issues) {
const issue = raw;
@@ -48504,10 +48489,10 @@ function flattenIssues(issues, prefix = []) {
const branches = Array.isArray(issue.errors) ? issue.errors.filter((branch) => Array.isArray(branch) && branch.length) : [];
if (issue.code === "invalid_union" && branches.length) {
const closest = branches.reduce((best, branch) => branch.length < best.length ? branch : best);
- lines.push(...flattenIssues(closest, path));
+ lines.push(...flattenIssuePaths(closest, path));
continue;
}
- lines.push(`${path.join(".") || "input"}: ${issue.message ?? "invalid"}`);
+ lines.push({ code: issue.code, path, message: issue.message ?? "invalid" });
}
return lines;
}
diff --git a/src/__tests__/open-shell.test.ts b/src/__tests__/open-shell.test.ts
index f11ad976..9f888f2d 100644
--- a/src/__tests__/open-shell.test.ts
+++ b/src/__tests__/open-shell.test.ts
@@ -93,6 +93,10 @@ describe('markOpenShell', () => {
() => markOpenShell(new THREE.Mesh(), 'x'.repeat(201)),
])
expect(openShellError(run).message).toContain('markOpenShell(part, reason)');
+ // #198: a capped field names its limit.
+ expect(
+ openShellError(() => markOpenShell(new THREE.Mesh(), 'x'.repeat(201))).message,
+ ).toContain('at most 200 characters');
expect(() => markOpenShell(new THREE.Mesh(), 'x'.repeat(200))).not.toThrow();
});
});
diff --git a/src/material-library-v2.test.ts b/src/material-library-v2.test.ts
index 0dc1ed0e..cce721ed 100644
--- a/src/material-library-v2.test.ts
+++ b/src/material-library-v2.test.ts
@@ -3,9 +3,12 @@ import { createHash } from 'node:crypto';
import { mkdtemp, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+import type { z } from 'zod';
import {
canonicalMaterialJson,
materialLibraryPortableSpec,
+ materialManifestV2Schema,
+ proceduralMaterialDraftV2Schema,
materialLibraryResourceId,
validateMaterialManifestAny,
type MaterialSourceV1,
@@ -24,6 +27,8 @@ import {
resolveMaterialRecordClosure,
} from './material-library-node';
import { compilePortableMaterialSpecV3 } from './portable-material-runtime';
+import { describeInputError } from './tools/actions';
+import { TEXTURE_ATLAS_COMPILER_ID_V1_2 } from './texture-atlas-contract';
const temporaryRoots: string[] = [];
afterEach(async () => {
for (const root of temporaryRoots.splice(0)) await rm(root, { recursive: true, force: true });
@@ -423,3 +428,121 @@ test('import deduplicates exact compound context identities and rejects conflict
/integrity|conflict|hash/i,
);
});
+
+// #198: a recipe only its canonicalizer rejects reached the agent as a bare
+// "maps.0.procedural: Invalid input". Each refine now reports the canonicalizer's
+// reason once, at the field it checked, in the text kiln_material returns.
+const toolError = (schema: z.ZodType, value: unknown): string => {
+ const parsed = schema.safeParse(value);
+ expect(parsed.success).toBe(false);
+ return describeInputError('kiln_material', parsed.error)!;
+};
+const stamps = {
+ op: 'stamps',
+ shape: { kind: 'rectangle', x: 0, y: 0, width: 1, height: 1 },
+ rgba: [1, 2, 3, 255],
+ opacity: 1,
+ count: 2,
+ seed: 1,
+ area: { x: 0, y: 0, width: 8, height: 4 },
+ periodic: false,
+};
+const withMap = (map: Record<string, unknown>) => {
+ const value = draft() as Record<string, unknown> & { maps: Record<string, unknown>[] };
+ value.maps = [{ ...value.maps[0]!, ...map }];
+ return value;
+};
+test('draft V3 recipe errors name the canonicalizer rule instead of Invalid input', () => {
+ const message = toolError(
+ proceduralMaterialDraftV2Schema,
+ withMap({ procedural: { ...recipe, usage: 'normal', operations: [stamps] } }),
+ );
+ expect(message).toContain(
+ 'maps.0.procedural: proceduralTexture V3: stamps are supported only for color usages albedo and emissive',
+ );
+ expect(message).not.toContain('Invalid input');
+});
+test('a draft field the schema already bounds is reported once, without a parent line', () => {
+ const message = toolError(
+ proceduralMaterialDraftV2Schema,
+ withMap({ procedural: { ...recipe, name: 'x'.repeat(100) } }),
+ );
+ expect(message).toContain(
+ 'maps.0.procedural.name: Too big: expected string to have <=80 characters',
+ );
+ expect(message).not.toContain('maps.0.procedural:');
+ expect(message).not.toContain('Invalid input');
+});
+test('draft atlas errors name the canonicalizer rule instead of Invalid input', () => {
+ const message = toolError(
+ proceduralMaterialDraftV2Schema,
+ withMap({
+ procedural: undefined,
+ atlas: {
+ schemaVersion: 1,
+ width: 8,
+ height: 8,
+ usage: 'albedo',
+ regions: [
+ {
+ name: 'a',
+ content: { x: 2, y: 2, width: 4, height: 4 },
+ source: { kind: 'procedural', spec: { ...recipe, width: 4, usage: 'roughness' } },
+ },
+ ],
+ },
+ }),
+ );
+ expect(message).toContain('maps.0.atlas: textureAtlas: source usage does not match atlas usage');
+ expect(message).not.toContain('Invalid input');
+});
+test('a sampler outside the portable set names the field and its options once', () => {
+ const message = toolError(
+ proceduralMaterialDraftV2Schema,
+ withMap({ sampler: { ...sampler, wrapS: 'clamp' } }),
+ );
+ expect(message).toContain('maps.0.sampler.wrapS');
+ expect(message).toContain('repeat');
+ expect(message).not.toContain('Invalid input');
+});
+test('stored V3 and atlas recipe errors carry the canonicalizer reason', async () => {
+ const v3 = (await createMaterialRecordV2(draft())).manifest;
+ const spec = structuredClone(v3);
+ const procedural = spec.maps[0]!.recipe as { spec: Record<string, unknown> };
+ procedural.spec = { ...procedural.spec, usage: 'normal', operations: [stamps] };
+ const v3Message = toolError(materialManifestV2Schema, spec);
+ expect(v3Message).toContain(
+ 'maps.0.recipe.spec: proceduralTexture V3: stamps are supported only for color usages albedo and emissive',
+ );
+ expect(v3Message).not.toContain('Invalid input');
+
+ const child = await createMaterialRecordV2(draft());
+ const atlas = (await createMaterialRecordV2(atlasDraft(child), { materials: [child] })).manifest;
+ const dilated = structuredClone(atlas);
+ const dilatedSpec = (dilated.maps[0]!.recipe as { spec: Record<string, unknown> }).spec as {
+ usage: string;
+ regions: Record<string, unknown>[];
+ };
+ dilatedSpec.usage = 'normal';
+ dilatedSpec.regions[0]!.edgeMode = 'mask-rgb-dilate';
+ const specMessage = toolError(materialManifestV2Schema, dilated);
+ expect(specMessage).toContain(
+ 'maps.0.recipe.spec: textureAtlas: mask RGB dilation requires color usage',
+ );
+ expect(specMessage).not.toContain('Invalid input');
+ expect(specMessage).not.toContain('Invalid stored atlas manifest');
+
+ const compiler = structuredClone(atlas);
+ (compiler.maps[0]!.recipe as { compilerId: string }).compilerId = TEXTURE_ATLAS_COMPILER_ID_V1_2;
+ const compilerMessage = toolError(materialManifestV2Schema, compiler);
+ expect(compilerMessage).toContain(
+ `maps.0.recipe: stored atlas manifest: recipe compilerId ${TEXTURE_ATLAS_COMPILER_ID_V1_2} does not match the manifest's`,
+ );
+
+ const layout = structuredClone(atlas);
+ (layout.maps[0]!.recipe as { manifest: { layoutHash: string } }).manifest.layoutHash =
+ `sha256:${'0'.repeat(64)}`;
+ const layoutMessage = toolError(materialManifestV2Schema, layout);
+ expect(layoutMessage).toContain('maps.0.recipe: stored atlas manifest: ');
+ expect(layoutMessage).not.toMatch(/stored atlas manifest\.?(;|$| Check)/);
+});
diff --git a/src/material-library.ts b/src/material-library.ts
index af500d7e..9a27724e 100644
--- a/src/material-library.ts
+++ b/src/material-library.ts
@@ -530,36 +530,39 @@ export function materialLibraryPortableSpec(
/** New versions are explicit; every exported V1 schema/type above stays V1. */
const authoringSchemas = makeMaterialAuthoringSchemas(materialProceduralSpecSchema);
-const samplerSchema = authoringSchemas.portableSamplerSchema.refine((value) => {
- try {
- return (
- canonicalMaterialJson(value) === canonicalMaterialJson(canonicalizePortableSamplerV1(value))
- );
- } catch {
- return false;
- }
-});
-const v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.refine((value) => {
- try {
- return (
- canonicalMaterialJson(value) ===
- canonicalMaterialJson(canonicalizeProceduralTextureSpecV3(value))
- );
- } catch {
- return false;
- }
-});
-const atlasSpecSchema: z.ZodType<CanonicalTextureAtlasSpecV1> =
- authoringSchemas.canonicalTextureAtlasSpecV1Schema.refine((value) => {
+/** Runs a canonicalizer check only on a value its structural schema accepted. */
+const afterShape = { when: (payload: { issues: readonly unknown[] }) => !payload.issues.length };
+const reason = (error: unknown) => (error instanceof Error ? error.message : String(error));
+/**
+ * Admits a value by its canonicalizer and reports the canonicalizer's own reason (#198). A
+ * bare refine reported zod's "Invalid input", which named no rule; one that ran beside a
+ * field issue repeated it as a second, vaguer line. `stored` also requires the value to
+ * be in canonical form already, as a saved record is.
+ */
+function admittedBy<T>(label: string, canonicalize: (value: T) => unknown, stored: boolean) {
+ return (value: T, context: z.RefinementCtx<T>) => {
try {
- return (
- canonicalMaterialJson(value) ===
- canonicalMaterialJson(canonicalizeTextureAtlasSpecV1(value))
- );
- } catch {
- return false;
+ const canonical = canonicalize(value);
+ if (stored && canonicalMaterialJson(value) !== canonicalMaterialJson(canonical))
+ context.addIssue({ code: 'custom', message: `${label} must be stored in canonical form.` });
+ } catch (error) {
+ context.addIssue({ code: 'custom', message: reason(error) });
}
- });
+ };
+}
+const samplerSchema = authoringSchemas.portableSamplerSchema.superRefine(
+ admittedBy('sampler', canonicalizePortableSamplerV1, true),
+ afterShape,
+);
+const v3SpecSchema = authoringSchemas.canonicalProceduralTextureSpecV3Schema.superRefine(
+ admittedBy('procedural V3 spec', canonicalizeProceduralTextureSpecV3, true),
+ afterShape,
+);
+const atlasSpecSchema: z.ZodType<CanonicalTextureAtlasSpecV1> =
+ authoringSchemas.canonicalTextureAtlasSpecV1Schema.superRefine(
+ admittedBy('atlas spec', canonicalizeTextureAtlasSpecV1, true),
+ afterShape,
+ );
const atlasManifestSchema: z.ZodType<TextureAtlasManifestV1> =
authoringSchemas.textureAtlasManifestV1Schema;
export const materialMapPinSchema = z
@@ -594,11 +597,14 @@ const materialRecipeV2Schema = z.discriminatedUnion('kind', [
.superRefine((recipe, context) => {
try {
validateTextureAtlasManifestV1(recipe.manifest, recipe.spec);
- if (recipe.compilerId !== recipe.manifest.compilerId) throw new Error('compiler id');
- } catch {
- context.addIssue({ code: 'custom', message: 'Invalid stored atlas manifest' });
+ if (recipe.compilerId !== recipe.manifest.compilerId)
+ throw new Error(
+ `recipe compilerId ${recipe.compilerId} does not match the manifest's ${recipe.manifest.compilerId}.`,
+ );
+ } catch (error) {
+ context.addIssue({ code: 'custom', message: `stored atlas manifest: ${reason(error)}` });
}
- }),
+ }, afterShape),
]);
export const materialManifestV2Schema = materialManifestSchema
.omit({ schemaVersion: true, maps: true })
@@ -669,25 +675,17 @@ export const proceduralMaterialDraftV2Schema = proceduralMaterialDraftSchema
procedural: z
.union([
materialProceduralSpecSchema,
- authoringSchemas.proceduralTextureSpecV3Schema.refine((value) => {
- try {
- canonicalizeProceduralTextureSpecV3(value);
- return true;
- } catch {
- return false;
- }
- }),
+ authoringSchemas.proceduralTextureSpecV3Schema.superRefine(
+ admittedBy('procedural V3 spec', canonicalizeProceduralTextureSpecV3, false),
+ afterShape,
+ ),
])
.optional(),
atlas: authoringSchemas.textureAtlasSpecV1Schema
- .refine((value) => {
- try {
- canonicalizeTextureAtlasSpecV1(value);
- return true;
- } catch {
- return false;
- }
- })
+ .superRefine(
+ admittedBy('atlas spec', canonicalizeTextureAtlasSpecV1, false),
+ afterShape,
+ )
.optional(),
})
.strict()
diff --git a/src/tools/actions.test.ts b/src/tools/actions.test.ts
index 96f21f9c..30edff2a 100644
--- a/src/tools/actions.test.ts
+++ b/src/tools/actions.test.ts
@@ -52,6 +52,20 @@ describe('describeInputError', () => {
expect(generic).toContain("nested shapes: kiln_discover({ ids: ['shape:...'] })");
});
+ it("drops zod's bare parent line when an issue inside that record already says what is wrong", () => {
+ // #198: a 100-character procedural name came back as the size limit and a second
+ // "maps.0.procedural: Invalid input" that named no rule.
+ const nested = z.strictObject({
+ recipe: z.strictObject({ name: z.string().max(80) }).refine(() => false),
+ draft: z.strictObject({ name: z.string().max(80) }).refine(() => false, 'Draft is closed'),
+ });
+ const parsed = nested.safeParse({ recipe: { name: 'x'.repeat(100) }, draft: { name: 'y' } });
+ const message = describeInputError('kiln_material', parsed.error)!;
+ expect(message).toContain('recipe.name: Too big: expected string to have <=80 characters');
+ expect(message).not.toContain('Invalid input');
+ expect(message).toContain('draft: Draft is closed');
+ });
+
it('reads the keys of an advertised object schema and nothing from any other schema', () => {
expect(schemaFields(input)).toEqual(['action', 'materialId', 'revisionId']);
expect(schemaFields(z.string())).toEqual([]);
diff --git a/src/tools/actions.ts b/src/tools/actions.ts
index 88b5d377..4c8d8df2 100644
--- a/src/tools/actions.ts
+++ b/src/tools/actions.ts
@@ -98,13 +98,39 @@ interface Issue {
errors?: unknown[][];
}
+/** zod's text for a refine that gave no message: it names no rule. */
+const BARE_REFINE_MESSAGE = 'Invalid input';
+
/**
* "field: what is wrong" per issue. A union reports only "Invalid input" at
* its root; the branch that came closest (the fewest issues) says which field
- * was wrong, so that branch's issues stand in for it.
+ * was wrong, so that branch's issues stand in for it. A message-less refine's
+ * "Invalid input" is dropped when an issue inside the same record already says
+ * what is wrong (#198: a long procedural name also came back as a bare
+ * "maps.0.procedural: Invalid input").
*/
-function flattenIssues(issues: readonly unknown[], prefix: (string | number)[] = []): string[] {
- const lines: string[] = [];
+function flattenIssues(issues: readonly unknown[]): string[] {
+ const flat = flattenIssuePaths(issues);
+ return flat
+ .filter(
+ ({ code, path, message }) =>
+ !(
+ code === 'custom' &&
+ message === BARE_REFINE_MESSAGE &&
+ flat.some(
+ (other) =>
+ other.path.length > path.length && path.every((key, i) => other.path[i] === key),
+ )
+ ),
+ )
+ .map(({ path, message }) => `${path.join('.') || 'input'}: ${message}`);
+}
+
+function flattenIssuePaths(
+ issues: readonly unknown[],
+ prefix: (string | number)[] = [],
+): { code?: string; path: (string | number)[]; message: string }[] {
+ const lines: { code?: string; path: (string | number)[]; message: string }[] = [];
for (const raw of issues) {
const issue = raw as Issue;
const path = [...prefix, ...(issue.path ?? [])];
@@ -115,10 +141,10 @@ function flattenIssues(issues: readonly unknown[], prefix: (string | number)[] =
const closest = branches.reduce((best, branch) =>
branch.length < best.length ? branch : best,
);
- lines.push(...flattenIssues(closest, path));
+ lines.push(...flattenIssuePaths(closest, path));
continue;
}
- lines.push(`${path.join('.') || 'input'}: ${issue.message ?? 'invalid'}`);
+ lines.push({ code: issue.code, path, message: issue.message ?? 'invalid' });
}
return lines;
}