@plasius/gpu-shader 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@ type Sha256Hex = string & {
19
19
  declare const SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES: readonly [Readonly<{
20
20
  matrixId: "stable-webgpu";
21
21
  matrixVersion: "2026-07-13";
22
- matrixSha256: "9b47ff8162b055d49e38c4fe90b9074992ab8c9e1125926e936f8122e6119fd8";
22
+ matrixSha256: "4620eca44fd03004ee7650cfe9fcf42934493611a5097da5525f71578980b016";
23
23
  }>];
24
24
  /**
25
25
  * Exact additive policies accepted by this release. Empty means supplemental
@@ -19,7 +19,7 @@ type Sha256Hex = string & {
19
19
  declare const SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES: readonly [Readonly<{
20
20
  matrixId: "stable-webgpu";
21
21
  matrixVersion: "2026-07-13";
22
- matrixSha256: "9b47ff8162b055d49e38c4fe90b9074992ab8c9e1125926e936f8122e6119fd8";
22
+ matrixSha256: "4620eca44fd03004ee7650cfe9fcf42934493611a5097da5525f71578980b016";
23
23
  }>];
24
24
  /**
25
25
  * Exact additive policies accepted by this release. Empty means supplemental
package/dist/index.cjs CHANGED
@@ -34,6 +34,7 @@ __export(src_exports, {
34
34
  SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES: () => SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES,
35
35
  activateStyleProfile: () => activateStyleProfile,
36
36
  asSha256Hex: () => asSha256Hex,
37
+ assertImmutableAssetVersion: () => assertImmutableAssetVersion,
37
38
  canonicalizeGpuContract: () => canonicalizeGpuContract,
38
39
  computeGpuAbiHash: () => computeGpuAbiHash,
39
40
  computeSha256: () => computeSha256,
@@ -68,12 +69,35 @@ var SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES = [
68
69
  Object.freeze({
69
70
  matrixId: "stable-webgpu",
70
71
  matrixVersion: "2026-07-13",
71
- matrixSha256: "9b47ff8162b055d49e38c4fe90b9074992ab8c9e1125926e936f8122e6119fd8"
72
+ matrixSha256: "4620eca44fd03004ee7650cfe9fcf42934493611a5097da5525f71578980b016"
72
73
  })
73
74
  ];
74
75
  Object.freeze(SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES);
75
76
  var SUPPORTED_ADDITIVE_WEBGPU_MATRIX_POLICIES = Object.freeze([]);
76
77
 
78
+ // src/asset-version.ts
79
+ var ASSET_VERSION_PATTERN = /^[0-9A-Za-z][0-9A-Za-z._-]{0,127}$/u;
80
+ var MUTABLE_VERSION_ALIASES = /* @__PURE__ */ new Set([
81
+ "latest",
82
+ "current",
83
+ "stable",
84
+ "preview",
85
+ "default",
86
+ "production",
87
+ "canary",
88
+ "next",
89
+ "head",
90
+ "main"
91
+ ]);
92
+ var X_WILDCARD_SEGMENT_PATTERN = /^(?:[vV])?[xX](?:\.|-|$)|\.[xX](?:\.|-|$)/u;
93
+ var IMMUTABLE_VERSION_ERROR_MESSAGE = "Immutable asset version must be an exact token up to 128 characters; mutable aliases, ranges, wildcards, and URLs are not allowed.";
94
+ function assertImmutableAssetVersion(value) {
95
+ if (typeof value !== "string" || !ASSET_VERSION_PATTERN.test(value) || MUTABLE_VERSION_ALIASES.has(value.toLowerCase()) || X_WILDCARD_SEGMENT_PATTERN.test(value)) {
96
+ throw new TypeError(IMMUTABLE_VERSION_ERROR_MESSAGE);
97
+ }
98
+ return value;
99
+ }
100
+
77
101
  // src/canonical-json.ts
78
102
  function isPlainObject(value) {
79
103
  const prototype = Object.getPrototypeOf(value);
@@ -882,96 +906,18 @@ function validateShaderDerivedRequirements(input) {
882
906
  for (const feature of inferWgslRequiredFeatures([...input.moduleSources.values()])) if (!features.has(feature)) throw new TypeError(`Shader requirements omit WGSL-derived feature ${feature}.`);
883
907
  }
884
908
 
885
- // src/compatibility.ts
886
- function error(code, message, path) {
887
- return { code, severity: "error", message, ...path ? { path } : {} };
888
- }
889
- function interfaceMatches(item, model) {
890
- return item.interfaceId === model.gpuInterface.interfaceId && item.interfaceVersion === model.gpuInterface.interfaceVersion && item.manifestSha256 === model.gpuInterface.manifestSha256 && item.interfaceAbiHash === model.gpuInterface.interfaceAbiHash && item.modelAbiHash === model.modelAbiHash;
891
- }
892
- function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
893
- const semantics = new Set(model.providedSemantics);
894
- const requiredSemantics = /* @__PURE__ */ new Set([
895
- ...shader.requirements.semantics,
896
- ...gpuInterface.modelAbi.semantics.map((projection) => projection.semantic)
897
- ]);
898
- for (const semantic2 of requiredSemantics) {
899
- if (!semantics.has(semantic2)) {
900
- diagnostics.push(error("missing-semantic", `Model does not provide required semantic ${semantic2}.`, "requirements.semantics"));
901
- }
902
- }
903
- if (!capabilities) return;
904
- const features = new Set(capabilities.features);
905
- for (const feature of shader.requirements.features) {
906
- if (!features.has(feature)) {
907
- diagnostics.push(error("missing-feature", `GPU does not provide required feature ${feature}.`, "requirements.features"));
908
- }
909
- }
910
- const formats = new Set(capabilities.formats);
911
- for (const format of shader.requirements.formats) {
912
- if (!formats.has(format)) {
913
- diagnostics.push(error("unsupported-format", `GPU runtime does not expose required format ${format}.`, "requirements.formats"));
914
- }
915
- }
916
- for (const requirement of shader.requirements.limits) {
917
- const available = capabilities.limits[requirement.name];
918
- const satisfied = available !== void 0 && (requirement.comparator === "at-least" ? available >= requirement.value : available <= requirement.value);
919
- if (!satisfied) {
920
- diagnostics.push(error(
921
- "limit-not-met",
922
- `GPU limit ${requirement.name} does not meet the ${requirement.comparator} requirement.`,
923
- "requirements.limits"
924
- ));
925
- }
926
- }
927
- }
928
- function validateModelShaderCompatibility(input) {
929
- const diagnostics = [];
930
- const { model, shader, gpuInterface, profile, capabilities } = input;
909
+ // src/manifest-validation.ts
910
+ var stages = ["vertex", "fragment", "compute"];
911
+ var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
912
+ function detachedJson(value, path) {
931
913
  try {
932
- validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
914
+ return JSON.parse(canonicalizeGpuContract(value));
933
915
  } catch (cause) {
934
- diagnostics.push(error(
935
- "invalid-contract",
936
- cause instanceof Error ? cause.message : "Shader requirements differ from the reflected GPU interface.",
937
- "requirements"
938
- ));
939
- }
940
- if (model.gpuInterface.modelAbiHash !== model.modelAbiHash) {
941
- diagnostics.push(error("model-abi-mismatch", "Model manifest and GPU interface reference disagree on modelAbiHash.", "modelAbiHash"));
942
- }
943
- if (shader.gpuInterface.modelAbiHash !== model.modelAbiHash) {
944
- diagnostics.push(error("model-abi-mismatch", "Shader GPU interface does not match the model ABI.", "gpuInterface.modelAbiHash"));
945
- }
946
- if (!shader.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
947
- diagnostics.push(error("incompatible-model-interface", "Shader does not declare this exact model interface as compatible."));
948
- }
949
- if (profile) {
950
- if (!profile.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
951
- diagnostics.push(error("incompatible-model-interface", "Style profile does not declare this exact model interface as compatible."));
952
- }
953
- const provided = new Set(model.providedSemantics);
954
- for (const semantic2 of profile.requiredSemantics) {
955
- if (!provided.has(semantic2)) {
956
- diagnostics.push(error("missing-semantic", `Model does not provide profile semantic ${semantic2}.`, "requiredSemantics"));
957
- }
958
- }
916
+ const detail = cause instanceof Error ? cause.message : "Contract snapshot failed.";
917
+ const boundedDetail = [...detail].slice(0, 512).join("");
918
+ throw new TypeError(`${path} must contain detached JSON contract data: ${boundedDetail}`, { cause });
959
919
  }
960
- validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
961
- if (diagnostics.length > 0) return { ok: false, diagnostics };
962
- return {
963
- ok: true,
964
- value: {
965
- modelAbiHash: model.modelAbiHash,
966
- shaderAbiHash: shader.shaderAbiHash,
967
- matchedInterfaceId: model.gpuInterface.interfaceId
968
- }
969
- };
970
920
  }
971
-
972
- // src/manifest-validation.ts
973
- var stages = ["vertex", "fragment", "compute"];
974
- var roles = ["material", "lighting", "outline", "shadow", "post-processing"];
975
921
  function object(value, path) {
976
922
  if (typeof value !== "object" || value === null || Array.isArray(value)) throw new TypeError(`${path} must be an object.`);
977
923
  return value;
@@ -992,6 +938,16 @@ function token(value, path) {
992
938
  if (!/^[A-Za-z0-9][A-Za-z0-9._:/-]*$/u.test(result) || result.includes("..")) throw new TypeError(`${path} must be a safe token.`);
993
939
  return result;
994
940
  }
941
+ function immutableVersion(value, path) {
942
+ try {
943
+ return assertImmutableAssetVersion(value);
944
+ } catch (cause) {
945
+ throw new TypeError(
946
+ `${path} must be an immutable asset version: exact token required; mutable aliases, ranges, wildcards, and URLs are not allowed.`,
947
+ { cause }
948
+ );
949
+ }
950
+ }
995
951
  function enumeration(value, values, path) {
996
952
  if (!values.includes(value)) throw new TypeError(`${path} is invalid.`);
997
953
  return value;
@@ -1265,7 +1221,7 @@ function interfaceRef(value, path) {
1265
1221
  const input = object(value, path);
1266
1222
  exact(input, ["interfaceId", "interfaceVersion", "manifestUri", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path);
1267
1223
  token(input.interfaceId, `${path}.interfaceId`);
1268
- token(input.interfaceVersion, `${path}.interfaceVersion`);
1224
+ immutableVersion(input.interfaceVersion, `${path}.interfaceVersion`);
1269
1225
  uri(input.manifestUri, `${path}.manifestUri`);
1270
1226
  digest(input.manifestSha256, `${path}.manifestSha256`);
1271
1227
  digest(input.interfaceAbiHash, `${path}.interfaceAbiHash`);
@@ -1406,7 +1362,7 @@ function compatibleModel(value, path) {
1406
1362
  const input = object(value, path);
1407
1363
  exact(input, ["interfaceId", "interfaceVersion", "manifestSha256", "interfaceAbiHash", "modelAbiHash"], path);
1408
1364
  token(input.interfaceId, `${path}.interfaceId`);
1409
- token(input.interfaceVersion, `${path}.interfaceVersion`);
1365
+ immutableVersion(input.interfaceVersion, `${path}.interfaceVersion`);
1410
1366
  digest(input.manifestSha256, `${path}.manifestSha256`);
1411
1367
  digest(input.interfaceAbiHash, `${path}.interfaceAbiHash`);
1412
1368
  digest(input.modelAbiHash, `${path}.modelAbiHash`);
@@ -1419,7 +1375,7 @@ function validationEvidenceRef(value, path) {
1419
1375
  uri(evidence.uri, `${path}.uri`);
1420
1376
  digest(evidence.sha256, `${path}.sha256`);
1421
1377
  token(evidence.matrixId, `${path}.matrixId`);
1422
- token(evidence.matrixVersion, `${path}.matrixVersion`);
1378
+ immutableVersion(evidence.matrixVersion, `${path}.matrixVersion`);
1423
1379
  digest(evidence.matrixSha256, `${path}.matrixSha256`);
1424
1380
  const attestation = object(evidence.attestationRef, `${path}.attestationRef`);
1425
1381
  exact(attestation, ["uri", "sha256"], `${path}.attestationRef`);
@@ -1446,11 +1402,11 @@ function reflectedRecordBindingSize(record) {
1446
1402
  return Math.ceil(unrounded / record.alignment) * record.alignment;
1447
1403
  }
1448
1404
  function parseGpuInterfaceManifest(value) {
1449
- const input = object(value, "GpuInterfaceManifest");
1405
+ const input = object(detachedJson(value, "GpuInterfaceManifest"), "GpuInterfaceManifest");
1450
1406
  exact(input, ["contractVersion", "interfaceId", "interfaceVersion", "modules", "records", "bindings", "entryPoints", "vertexInputs", "overrides", "modelAbi", "modelAbiHash", "interfaceAbiHash", "generatedBy"], "GpuInterfaceManifest");
1451
1407
  if (input.contractVersion !== GPU_INTERFACE_MANIFEST_VERSION) throw new TypeError("Unsupported GPU interface contract version.");
1452
1408
  token(input.interfaceId, "GpuInterfaceManifest.interfaceId");
1453
- token(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
1409
+ immutableVersion(input.interfaceVersion, "GpuInterfaceManifest.interfaceVersion");
1454
1410
  const moduleValues = array(input.modules, "GpuInterfaceManifest.modules");
1455
1411
  if (moduleValues.length === 0) throw new TypeError("GpuInterfaceManifest.modules must not be empty.");
1456
1412
  const moduleIds = moduleValues.map((value2, index) => {
@@ -1632,11 +1588,11 @@ function parseGpuInterfaceManifest(value) {
1632
1588
  return freeze(input);
1633
1589
  }
1634
1590
  function parseShaderVersionManifest(value) {
1635
- const input = object(value, "ShaderVersionManifest");
1591
+ const input = object(detachedJson(value, "ShaderVersionManifest"), "ShaderVersionManifest");
1636
1592
  exact(input, ["contractVersion", "shaderId", "version", "modules", "gpuInterface", "pipelines", "renderRoles", "compatibleModelInterfaces", "requirements", "shaderAbiHash", "validationEvidence", "additionalValidationEvidence"], "ShaderVersionManifest");
1637
1593
  if (input.contractVersion !== SHADER_VERSION_MANIFEST_VERSION) throw new TypeError("Unsupported shader manifest contract version.");
1638
1594
  token(input.shaderId, "ShaderVersionManifest.shaderId");
1639
- token(input.version, "ShaderVersionManifest.version");
1595
+ immutableVersion(input.version, "ShaderVersionManifest.version");
1640
1596
  const moduleValues = array(input.modules, "ShaderVersionManifest.modules");
1641
1597
  if (moduleValues.length === 0) throw new TypeError("ShaderVersionManifest.modules must not be empty.");
1642
1598
  const moduleIds = moduleValues.map((item, index) => {
@@ -1749,7 +1705,7 @@ function parseShaderVersionManifest(value) {
1749
1705
  return freeze(input);
1750
1706
  }
1751
1707
  function parseShaderVersionManifestCore(value) {
1752
- const input = object(value, "ShaderVersionManifestCore");
1708
+ const input = object(detachedJson(value, "ShaderVersionManifestCore"), "ShaderVersionManifestCore");
1753
1709
  if ("validationEvidence" in input || "additionalValidationEvidence" in input) {
1754
1710
  throw new TypeError("ShaderVersionManifestCore must not contain validationEvidence or additionalValidationEvidence.");
1755
1711
  }
@@ -1775,11 +1731,11 @@ function parseShaderVersionManifestCore(value) {
1775
1731
  return freeze(core);
1776
1732
  }
1777
1733
  function parseShaderStyleProfileManifest(value) {
1778
- const input = object(value, "ShaderStyleProfileManifest");
1734
+ const input = object(detachedJson(value, "ShaderStyleProfileManifest"), "ShaderStyleProfileManifest");
1779
1735
  exact(input, ["contractVersion", "profileId", "version", "style", "roles", "compatibleModelInterfaces", "requiredSemantics", "requiredValidationScopes"], "ShaderStyleProfileManifest");
1780
1736
  if (input.contractVersion !== SHADER_STYLE_PROFILE_MANIFEST_VERSION) throw new TypeError("Unsupported style-profile contract version.");
1781
1737
  token(input.profileId, "ShaderStyleProfileManifest.profileId");
1782
- token(input.version, "ShaderStyleProfileManifest.version");
1738
+ immutableVersion(input.version, "ShaderStyleProfileManifest.version");
1783
1739
  token(input.style, "ShaderStyleProfileManifest.style");
1784
1740
  const roleValues = array(input.roles, "ShaderStyleProfileManifest.roles", 5);
1785
1741
  if (roleValues.length === 0) throw new TypeError("ShaderStyleProfileManifest.roles must not be empty.");
@@ -1792,7 +1748,7 @@ function parseShaderStyleProfileManifest(value) {
1792
1748
  const shader = object(role.shader, `${path}.shader`);
1793
1749
  exact(shader, ["shaderId", "version", "manifestUri", "manifestSha256"], `${path}.shader`);
1794
1750
  token(shader.shaderId, `${path}.shader.shaderId`);
1795
- token(shader.version, `${path}.shader.version`);
1751
+ immutableVersion(shader.version, `${path}.shader.version`);
1796
1752
  uri(shader.manifestUri, `${path}.shader.manifestUri`);
1797
1753
  digest(shader.manifestSha256, `${path}.shader.manifestSha256`);
1798
1754
  });
@@ -1808,7 +1764,7 @@ function parseShaderStyleProfileManifest(value) {
1808
1764
  const scope = token(requirement.scope, `${path}.scope`);
1809
1765
  if (scope === "universal") throw new TypeError(`${path}.scope must not use the reserved universal scope.`);
1810
1766
  token(requirement.matrixId, `${path}.matrixId`);
1811
- token(requirement.matrixVersion, `${path}.matrixVersion`);
1767
+ immutableVersion(requirement.matrixVersion, `${path}.matrixVersion`);
1812
1768
  const matrixSha256 = digest(requirement.matrixSha256, `${path}.matrixSha256`);
1813
1769
  if (SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES.some((policy) => policy.matrixSha256 === matrixSha256)) {
1814
1770
  throw new TypeError(`${path} must require an additive matrix policy, not the universal matrix policy.`);
@@ -1823,10 +1779,10 @@ function parseShaderStyleProfileManifest(value) {
1823
1779
  return freeze(input);
1824
1780
  }
1825
1781
  function parseModelGpuCompatibilityDescriptor(value) {
1826
- const input = object(value, "ModelGpuCompatibilityDescriptor");
1782
+ const input = object(detachedJson(value, "ModelGpuCompatibilityDescriptor"), "ModelGpuCompatibilityDescriptor");
1827
1783
  exact(input, ["modelId", "version", "gpuInterface", "modelAbiHash", "providedSemantics", "defaultStyleProfile"], "ModelGpuCompatibilityDescriptor");
1828
1784
  token(input.modelId, "ModelGpuCompatibilityDescriptor.modelId");
1829
- token(input.version, "ModelGpuCompatibilityDescriptor.version");
1785
+ immutableVersion(input.version, "ModelGpuCompatibilityDescriptor.version");
1830
1786
  const gpuInterface = interfaceRef(input.gpuInterface, "ModelGpuCompatibilityDescriptor.gpuInterface");
1831
1787
  const modelAbiHash = digest(input.modelAbiHash, "ModelGpuCompatibilityDescriptor.modelAbiHash");
1832
1788
  if (gpuInterface.modelAbiHash !== modelAbiHash) throw new TypeError("ModelGpuCompatibilityDescriptor.gpuInterface.modelAbiHash differs from modelAbiHash.");
@@ -1835,7 +1791,7 @@ function parseModelGpuCompatibilityDescriptor(value) {
1835
1791
  const profile = object(input.defaultStyleProfile, "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
1836
1792
  exact(profile, ["profileId", "version", "manifestUri", "manifestSha256"], "ModelGpuCompatibilityDescriptor.defaultStyleProfile");
1837
1793
  token(profile.profileId, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.profileId");
1838
- token(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
1794
+ immutableVersion(profile.version, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.version");
1839
1795
  uri(profile.manifestUri, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestUri");
1840
1796
  digest(profile.manifestSha256, "ModelGpuCompatibilityDescriptor.defaultStyleProfile.manifestSha256");
1841
1797
  }
@@ -1849,6 +1805,135 @@ function parseJsonBytes(bytes, label) {
1849
1805
  }
1850
1806
  }
1851
1807
 
1808
+ // src/compatibility.ts
1809
+ function error(code, message, path) {
1810
+ const bounded = [...message].map((character) => {
1811
+ const codePoint = character.codePointAt(0);
1812
+ return codePoint <= 31 || codePoint === 127 ? " " : character;
1813
+ }).slice(0, 512).join("");
1814
+ return { code, severity: "error", message: bounded, ...path ? { path } : {} };
1815
+ }
1816
+ function interfaceMatches(item, model) {
1817
+ return item.interfaceId === model.gpuInterface.interfaceId && item.interfaceVersion === model.gpuInterface.interfaceVersion && item.manifestSha256 === model.gpuInterface.manifestSha256 && item.interfaceAbiHash === model.gpuInterface.interfaceAbiHash && item.modelAbiHash === model.modelAbiHash;
1818
+ }
1819
+ function detachedContract(value) {
1820
+ return JSON.parse(canonicalizeGpuContract(value));
1821
+ }
1822
+ function hasValidationEvidence(value) {
1823
+ return typeof value === "object" && value !== null && !Array.isArray(value) && (Object.hasOwn(value, "validationEvidence") || Object.hasOwn(value, "additionalValidationEvidence"));
1824
+ }
1825
+ function validateRequirements(shader, gpuInterface, model, capabilities, diagnostics) {
1826
+ const semantics = new Set(model.providedSemantics);
1827
+ const requiredSemantics = /* @__PURE__ */ new Set([
1828
+ ...shader.requirements.semantics,
1829
+ ...gpuInterface.modelAbi.semantics.map((projection) => projection.semantic)
1830
+ ]);
1831
+ for (const semantic2 of requiredSemantics) {
1832
+ if (!semantics.has(semantic2)) {
1833
+ diagnostics.push(error("missing-semantic", `Model does not provide required semantic ${semantic2}.`, "requirements.semantics"));
1834
+ }
1835
+ }
1836
+ if (!capabilities) return;
1837
+ const features = new Set(capabilities.features);
1838
+ for (const feature of shader.requirements.features) {
1839
+ if (!features.has(feature)) {
1840
+ diagnostics.push(error("missing-feature", `GPU does not provide required feature ${feature}.`, "requirements.features"));
1841
+ }
1842
+ }
1843
+ const formats = new Set(capabilities.formats);
1844
+ for (const format of shader.requirements.formats) {
1845
+ if (!formats.has(format)) {
1846
+ diagnostics.push(error("unsupported-format", `GPU runtime does not expose required format ${format}.`, "requirements.formats"));
1847
+ }
1848
+ }
1849
+ for (const requirement of shader.requirements.limits) {
1850
+ const available = capabilities.limits[requirement.name];
1851
+ const satisfied = available !== void 0 && (requirement.comparator === "at-least" ? available >= requirement.value : available <= requirement.value);
1852
+ if (!satisfied) {
1853
+ diagnostics.push(error(
1854
+ "limit-not-met",
1855
+ `GPU limit ${requirement.name} does not meet the ${requirement.comparator} requirement.`,
1856
+ "requirements.limits"
1857
+ ));
1858
+ }
1859
+ }
1860
+ }
1861
+ function validateModelShaderCompatibility(input) {
1862
+ const diagnostics = [];
1863
+ let model;
1864
+ let shader;
1865
+ let gpuInterface;
1866
+ let profile;
1867
+ let capabilities;
1868
+ try {
1869
+ const modelSnapshot = detachedContract(input.model);
1870
+ const shaderSnapshot = detachedContract(input.shader);
1871
+ const gpuInterfaceSnapshot = detachedContract(input.gpuInterface);
1872
+ const profileValue = input.profile;
1873
+ const profileSnapshot = profileValue === void 0 ? void 0 : detachedContract(profileValue);
1874
+ model = parseModelGpuCompatibilityDescriptor(modelSnapshot);
1875
+ shader = hasValidationEvidence(shaderSnapshot) ? parseShaderVersionManifest(shaderSnapshot) : parseShaderVersionManifestCore(shaderSnapshot);
1876
+ gpuInterface = parseGpuInterfaceManifest(gpuInterfaceSnapshot);
1877
+ profile = profileSnapshot === void 0 ? void 0 : parseShaderStyleProfileManifest(profileSnapshot);
1878
+ capabilities = input.capabilities;
1879
+ } catch (cause) {
1880
+ return {
1881
+ ok: false,
1882
+ diagnostics: [error(
1883
+ "invalid-contract",
1884
+ cause instanceof Error ? cause.message : "GPU compatibility contract snapshot failed."
1885
+ )]
1886
+ };
1887
+ }
1888
+ try {
1889
+ validateShaderInterfaceRequirements({ manifest: shader, gpuInterface });
1890
+ } catch (cause) {
1891
+ diagnostics.push(error(
1892
+ "invalid-contract",
1893
+ cause instanceof Error ? cause.message : "Shader requirements differ from the reflected GPU interface.",
1894
+ "requirements"
1895
+ ));
1896
+ }
1897
+ if (model.gpuInterface.modelAbiHash !== model.modelAbiHash) {
1898
+ diagnostics.push(error("model-abi-mismatch", "Model manifest and GPU interface reference disagree on modelAbiHash.", "modelAbiHash"));
1899
+ }
1900
+ if (shader.gpuInterface.modelAbiHash !== model.modelAbiHash) {
1901
+ diagnostics.push(error("model-abi-mismatch", "Shader GPU interface does not match the model ABI.", "gpuInterface.modelAbiHash"));
1902
+ }
1903
+ if (!shader.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
1904
+ diagnostics.push(error("incompatible-model-interface", "Shader does not declare this exact model interface as compatible."));
1905
+ }
1906
+ if (profile) {
1907
+ if (!profile.compatibleModelInterfaces.some((item) => interfaceMatches(item, model))) {
1908
+ diagnostics.push(error("incompatible-model-interface", "Style profile does not declare this exact model interface as compatible."));
1909
+ }
1910
+ const provided = new Set(model.providedSemantics);
1911
+ for (const semantic2 of profile.requiredSemantics) {
1912
+ if (!provided.has(semantic2)) {
1913
+ diagnostics.push(error("missing-semantic", `Model does not provide profile semantic ${semantic2}.`, "requiredSemantics"));
1914
+ }
1915
+ }
1916
+ }
1917
+ try {
1918
+ validateRequirements(shader, gpuInterface, model, capabilities, diagnostics);
1919
+ } catch (cause) {
1920
+ diagnostics.push(error(
1921
+ "invalid-contract",
1922
+ cause instanceof Error ? cause.message : "GPU capability snapshot validation failed.",
1923
+ "capabilities"
1924
+ ));
1925
+ }
1926
+ if (diagnostics.length > 0) return { ok: false, diagnostics };
1927
+ return {
1928
+ ok: true,
1929
+ value: {
1930
+ modelAbiHash: model.modelAbiHash,
1931
+ shaderAbiHash: shader.shaderAbiHash,
1932
+ matchedInterfaceId: model.gpuInterface.interfaceId
1933
+ }
1934
+ };
1935
+ }
1936
+
1852
1937
  // src/runtime/trusted-values.ts
1853
1938
  var ReadonlyMapView = class {
1854
1939
  #source;
@@ -1975,6 +2060,36 @@ async function verifyBytes(bytes, expected, label) {
1975
2060
  function copyBytes(bytes) {
1976
2061
  return new Uint8Array(bytes);
1977
2062
  }
2063
+ function snapshotProfileRef(ref) {
2064
+ const profileId = ref.profileId;
2065
+ const version = ref.version;
2066
+ const manifestUri = ref.manifestUri;
2067
+ const manifestSha256 = ref.manifestSha256;
2068
+ return Object.freeze({ profileId, version, manifestUri, manifestSha256 });
2069
+ }
2070
+ function snapshotShaderRef(ref) {
2071
+ const shaderId = ref.shaderId;
2072
+ const version = ref.version;
2073
+ const manifestUri = ref.manifestUri;
2074
+ const manifestSha256 = ref.manifestSha256;
2075
+ return Object.freeze({ shaderId, version, manifestUri, manifestSha256 });
2076
+ }
2077
+ function snapshotInterfaceRef(ref) {
2078
+ const interfaceId = ref.interfaceId;
2079
+ const interfaceVersion = ref.interfaceVersion;
2080
+ const manifestUri = ref.manifestUri;
2081
+ const manifestSha256 = ref.manifestSha256;
2082
+ const interfaceAbiHash = ref.interfaceAbiHash;
2083
+ const modelAbiHash = ref.modelAbiHash;
2084
+ return Object.freeze({
2085
+ interfaceId,
2086
+ interfaceVersion,
2087
+ manifestUri,
2088
+ manifestSha256,
2089
+ interfaceAbiHash,
2090
+ modelAbiHash
2091
+ });
2092
+ }
1978
2093
  function throwIfAborted(signal) {
1979
2094
  if (signal?.aborted) throw signal.reason instanceof Error ? signal.reason : new DOMException("Aborted", "AbortError");
1980
2095
  }
@@ -2038,6 +2153,7 @@ async function mapLimit(values, limit, operation, signal) {
2038
2153
  }
2039
2154
  async function loadInterface(catalog, ref, signal) {
2040
2155
  throwIfAborted(signal);
2156
+ assertImmutableAssetVersion(ref.interfaceVersion);
2041
2157
  if (!catalog.isCatalogAssetUri(ref.manifestUri)) throw new TypeError("GPU interface URI is outside the promoted catalog root.");
2042
2158
  const loaded = await catalog.loadInterface(ref, signal);
2043
2159
  const bytes = copyBytes(loaded.bytes);
@@ -2058,6 +2174,7 @@ async function loadInterface(catalog, ref, signal) {
2058
2174
  }
2059
2175
  async function loadShader(catalog, ref, signal) {
2060
2176
  throwIfAborted(signal);
2177
+ assertImmutableAssetVersion(ref.version);
2061
2178
  if (!catalog.isCatalogAssetUri(ref.manifestUri)) throw new TypeError("Shader manifest URI is outside the promoted catalog root.");
2062
2179
  const loaded = await catalog.loadShader(ref, signal);
2063
2180
  const bytes = copyBytes(loaded.bytes);
@@ -2076,7 +2193,8 @@ async function loadShader(catalog, ref, signal) {
2076
2193
  if (!catalog.isCatalogAssetUri(evidence.uri)) throw new TypeError("Shader validation evidence URI is outside the promoted catalog root.");
2077
2194
  if (!catalog.isCatalogAssetUri(evidence.attestationRef.uri)) throw new TypeError("Shader validation evidence attestation URI is outside the promoted catalog root.");
2078
2195
  }
2079
- const gpuInterface = await loadInterface(catalog, manifest.gpuInterface, signal);
2196
+ const interfaceRef2 = snapshotInterfaceRef(manifest.gpuInterface);
2197
+ const gpuInterface = await loadInterface(catalog, interfaceRef2, signal);
2080
2198
  const normalizeModules = (values) => [...values].sort((left, right) => left.moduleId < right.moduleId ? -1 : left.moduleId > right.moduleId ? 1 : 0).map(({ moduleId, sha256 }) => ({ moduleId, sha256 }));
2081
2199
  if (canonicalizeGpuContract(normalizeModules(gpuInterface.modules)) !== canonicalizeGpuContract(normalizeModules(manifest.modules))) {
2082
2200
  throw new TypeError("Shader modules differ from the exact reflected GPU interface module set.");
@@ -2107,28 +2225,32 @@ async function loadShader(catalog, ref, signal) {
2107
2225
  return { ref, manifest, gpuInterface, modules: new Map(modulePairs) };
2108
2226
  }
2109
2227
  async function loadShaderStyleProfile(input) {
2228
+ const signal = input.signal;
2110
2229
  try {
2111
- throwIfAborted(input.signal);
2112
- if (!input.catalog.isCatalogAssetUri(input.ref.manifestUri)) throw new TypeError("Style profile URI is outside the promoted catalog root.");
2113
- const loaded = await input.catalog.loadProfile(input.ref, input.signal);
2230
+ throwIfAborted(signal);
2231
+ const ref = snapshotProfileRef(input.ref);
2232
+ assertImmutableAssetVersion(ref.version);
2233
+ if (!input.catalog.isCatalogAssetUri(ref.manifestUri)) throw new TypeError("Style profile URI is outside the promoted catalog root.");
2234
+ const loaded = await input.catalog.loadProfile(ref, signal);
2114
2235
  const profileBytes = copyBytes(loaded.bytes);
2115
2236
  const promoted = loaded.promoted;
2116
- throwIfAborted(input.signal);
2237
+ throwIfAborted(signal);
2117
2238
  if (!promoted) {
2118
2239
  return { ok: false, diagnostics: [diagnostic("unpromoted-asset", "Style profile is not promoted.")] };
2119
2240
  }
2120
- await verifyBytes(profileBytes, input.ref.manifestSha256, "Style profile manifest");
2241
+ await verifyBytes(profileBytes, ref.manifestSha256, "Style profile manifest");
2121
2242
  const manifest = parseShaderStyleProfileManifest(parseJsonBytes(profileBytes, "Style profile manifest"));
2122
- if (manifest.profileId !== input.ref.profileId || manifest.version !== input.ref.version) {
2243
+ if (manifest.profileId !== ref.profileId || manifest.version !== ref.version) {
2123
2244
  return { ok: false, diagnostics: [diagnostic("invalid-contract", "Style profile identity does not match its exact reference.")] };
2124
2245
  }
2125
2246
  const cache = /* @__PURE__ */ new Map();
2126
2247
  const pairs = await mapLimit(manifest.roles, 4, async (binding2) => {
2127
- throwIfAborted(input.signal);
2128
- const cacheKey = exactShaderRefKey(binding2.shader);
2248
+ throwIfAborted(signal);
2249
+ const shaderRef = snapshotShaderRef(binding2.shader);
2250
+ const cacheKey = exactShaderRefKey(shaderRef);
2129
2251
  let shader = cache.get(cacheKey);
2130
2252
  if (!shader) {
2131
- shader = loadShader(input.catalog, binding2.shader, input.signal);
2253
+ shader = loadShader(input.catalog, shaderRef, signal);
2132
2254
  cache.set(cacheKey, shader);
2133
2255
  }
2134
2256
  const resolved = await shader;
@@ -2150,18 +2272,18 @@ async function loadShaderStyleProfile(input) {
2150
2272
  }
2151
2273
  }
2152
2274
  return [binding2.role, resolved];
2153
- }, input.signal);
2275
+ }, signal);
2154
2276
  assertDistinctEvidenceOwnership(pairs.map(([, shader]) => shader));
2155
2277
  return {
2156
2278
  ok: true,
2157
2279
  value: trustLoadedShaderStyleProfile({
2158
- ref: input.ref,
2280
+ ref,
2159
2281
  manifest,
2160
2282
  shaders: new Map(pairs)
2161
2283
  })
2162
2284
  };
2163
2285
  } catch (cause) {
2164
- if (input.signal?.aborted) throw cause;
2286
+ if (signal?.aborted) throw cause;
2165
2287
  const code = cause instanceof TypeError && /digest/u.test(cause.message) ? "digest-mismatch" : "invalid-contract";
2166
2288
  return {
2167
2289
  ok: false,
@@ -2492,6 +2614,7 @@ async function activateStyleProfile(input) {
2492
2614
  SUPPORTED_STABLE_WEBGPU_MATRIX_POLICIES,
2493
2615
  activateStyleProfile,
2494
2616
  asSha256Hex,
2617
+ assertImmutableAssetVersion,
2495
2618
  canonicalizeGpuContract,
2496
2619
  computeGpuAbiHash,
2497
2620
  computeSha256,