domainforge 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (481) hide show
  1. package/.cargo/config.toml +6 -0
  2. package/.claude/settings.local.json +18 -0
  3. package/.coderabbit.yml +43 -0
  4. package/.codex/skills/release-management/SKILL.md +151 -0
  5. package/.codex/skills/release-management/agents/openai.yaml +4 -0
  6. package/.github/actions/decrypt-secrets/action.yml +121 -0
  7. package/.github/agents/Coder.agent.md +97 -0
  8. package/.github/agents/DeepResearch.agent.md +61 -0
  9. package/.github/chatmodes/tdd.vibepro.chatmode.md +1183 -0
  10. package/.github/copilot-instructions.md +13 -0
  11. package/.github/dependabot.yml +68 -0
  12. package/.github/workflows/README.md +165 -0
  13. package/.github/workflows/ci.yml +335 -0
  14. package/.github/workflows/dependabot-automerge.yml +114 -0
  15. package/.github/workflows/dependency-review.yml +27 -0
  16. package/.github/workflows/deploy.yml +87 -0
  17. package/.github/workflows/prepare-release.yml +168 -0
  18. package/.github/workflows/release-crates.yml +42 -0
  19. package/.github/workflows/release-npm.yml +137 -0
  20. package/.github/workflows/release-please.yml +29 -0
  21. package/.github/workflows/release-pypi.yml +96 -0
  22. package/.gitkeep +1 -0
  23. package/.release-please-manifest.json +5 -0
  24. package/.sea-registry.toml +10 -0
  25. package/.serena/project.yml +133 -0
  26. package/.sops.yaml +10 -0
  27. package/AGENTS.md +216 -0
  28. package/CHANGELOG.md +400 -0
  29. package/CLAUDE.md +62 -0
  30. package/CONTRIBUTING.md +323 -0
  31. package/Cargo.lock +3612 -0
  32. package/Cargo.toml +12 -0
  33. package/LICENSE +201 -0
  34. package/README.md +660 -0
  35. package/README_PYTHON.md +256 -0
  36. package/README_TYPESCRIPT.md +305 -0
  37. package/README_WASM.md +329 -0
  38. package/RELEASE_NOTES.md +41 -0
  39. package/bun.lock +378 -0
  40. package/bunfig.toml +11 -0
  41. package/check_output.txt +83 -0
  42. package/clippy_output.txt +80 -0
  43. package/commitlint.config.cjs +8 -0
  44. package/deny.toml +42 -0
  45. package/devbox.json +14 -0
  46. package/devbox.lock +76 -0
  47. package/docs/RELEASE_PROCESS.md +360 -0
  48. package/docs/diagnostics.md +161 -0
  49. package/docs/doc_guidelines.md +53 -0
  50. package/docs/explanations/README.md +21 -0
  51. package/docs/explanations/architecture-overview.md +109 -0
  52. package/docs/explanations/cross-language-binding-strategy.md +68 -0
  53. package/docs/explanations/graph-store-design.md +47 -0
  54. package/docs/explanations/performance-benchmarks.md +63 -0
  55. package/docs/explanations/policy-evaluation-logic.md +106 -0
  56. package/docs/explanations/semantic-modeling-concepts.md +109 -0
  57. package/docs/explanations/three-valued-logic.md +66 -0
  58. package/docs/explanations/versioning-strategy.md +45 -0
  59. package/docs/governance.md +168 -0
  60. package/docs/how-tos/README.md +46 -0
  61. package/docs/how-tos/ci-cd-validation.md +93 -0
  62. package/docs/how-tos/create-custom-units.md +125 -0
  63. package/docs/how-tos/define-policies.md +119 -0
  64. package/docs/how-tos/export-to-calm.md +110 -0
  65. package/docs/how-tos/export-to-protobuf.md +312 -0
  66. package/docs/how-tos/extend-grammar.md +133 -0
  67. package/docs/how-tos/generate-rdf-turtle.md +106 -0
  68. package/docs/how-tos/import-from-calm.md +114 -0
  69. package/docs/how-tos/import-from-sbvr.md +249 -0
  70. package/docs/how-tos/install-cli.md +126 -0
  71. package/docs/how-tos/parse-sea-files.md +132 -0
  72. package/docs/how-tos/policy-evaluation-modes.md +30 -0
  73. package/docs/how-tos/run-cross-language-tests.md +115 -0
  74. package/docs/how-tos/troubleshoot-napi-builds.md +55 -0
  75. package/docs/how-tos/use-modules-imports.md +285 -0
  76. package/docs/index.md +13 -0
  77. package/docs/plans/canonical-normalizer.md +121 -0
  78. package/docs/plans/cd_improvement.md +112 -0
  79. package/docs/plans/cli-ast.md +29 -0
  80. package/docs/plans/expression-bindings-and-normalizer-integration.md +174 -0
  81. package/docs/plans/protobuf_advanced_features_plan.md +597 -0
  82. package/docs/plans/protobuf_plan.yml +525 -0
  83. package/docs/plans/refactor_dsl_architecture.md +131 -0
  84. package/docs/plans/release-plan.md +163 -0
  85. package/docs/plans/sea_fmt_implementation_plan.md +516 -0
  86. package/docs/playbooks/README.md +18 -0
  87. package/docs/playbooks/adding-new-primitive.md +68 -0
  88. package/docs/playbooks/debugging-parser-failures.md +42 -0
  89. package/docs/playbooks/local-release-preparation.md +139 -0
  90. package/docs/playbooks/migrating-schema-versions.md +43 -0
  91. package/docs/playbooks/onboarding-contributors.md +64 -0
  92. package/docs/playbooks/releasing-beta.md +86 -0
  93. package/docs/playbooks/secret-management.md +64 -0
  94. package/docs/reference/README.md +199 -0
  95. package/docs/reference/ast-json-api.md +427 -0
  96. package/docs/reference/calm-mapping.md +519 -0
  97. package/docs/reference/cli-commands.md +588 -0
  98. package/docs/reference/configuration.md +202 -0
  99. package/docs/reference/error-codes.md +664 -0
  100. package/docs/reference/generated-artifacts-policy.md +53 -0
  101. package/docs/reference/grammar-spec.md +255 -0
  102. package/docs/reference/primitives-api.md +317 -0
  103. package/docs/reference/protobuf-api.md +426 -0
  104. package/docs/reference/python-api.md +485 -0
  105. package/docs/reference/registry.md +50 -0
  106. package/docs/reference/sea-dsl-ai-cheatsheet.yaml +913 -0
  107. package/docs/reference/security-model.md +74 -0
  108. package/docs/reference/typescript-api.md +508 -0
  109. package/docs/reference/wasm-api.md +420 -0
  110. package/docs/semantic-pack-review.md +144 -0
  111. package/docs/semantic-pack-signing.md +234 -0
  112. package/docs/semantic-packs.md +284 -0
  113. package/docs/specs/ADR-001-sea-dsl-semantic-source-of-truth.md +33 -0
  114. package/docs/specs/ADR-002-projection-first-class-construct.md +50 -0
  115. package/docs/specs/ADR-003-protobuf-projection-target.md +51 -0
  116. package/docs/specs/ADR-004-projection-compatibility-semantics.md +57 -0
  117. package/docs/specs/ADR-005-multi-language-support-strategy.md +112 -0
  118. package/docs/specs/ADR-006-error-handling-strategy.md +115 -0
  119. package/docs/specs/ADR-007-policy-evaluation-engine.md +95 -0
  120. package/docs/specs/ADR-008-knowledge-graph-integration.md +90 -0
  121. package/docs/specs/ADR-009-module-resolution-strategy.md +115 -0
  122. package/docs/specs/ADR-010-unit-system.md +106 -0
  123. package/docs/specs/PRD-001-sea-projection-framework.md +155 -0
  124. package/docs/specs/PRD-002-sea-cli-tooling.md +169 -0
  125. package/docs/specs/PRD-003-dsl-core-capabilities.md +275 -0
  126. package/docs/specs/README.md +62 -0
  127. package/docs/specs/SDS-001-protobuf-projection-engine.md +451 -0
  128. package/docs/specs/SDS-002-sea-core-architecture.md +268 -0
  129. package/docs/specs/SDS-003-parser-semantic-graph.md +377 -0
  130. package/docs/specs/SDS-004-policy-engine-design.md +362 -0
  131. package/docs/specs/SDS-005-knowledge-graph-module.md +364 -0
  132. package/docs/specs/SDS-006-calm-integration.md +367 -0
  133. package/docs/specs/SDS-007-sbvr-import.md +347 -0
  134. package/docs/templates/template_explanation.md +14 -0
  135. package/docs/templates/template_howto.md +21 -0
  136. package/docs/templates/template_playbook.md +21 -0
  137. package/docs/templates/template_reference.md +17 -0
  138. package/docs/templates/template_tutorial.md +24 -0
  139. package/docs/tutorials/README.md +12 -0
  140. package/docs/tutorials/first-sea-model.md +85 -0
  141. package/docs/tutorials/getting-started.md +98 -0
  142. package/docs/tutorials/python-binding-quickstart.md +107 -0
  143. package/docs/tutorials/typescript-binding-quickstart.md +91 -0
  144. package/docs/tutorials/wasm-in-browser.md +75 -0
  145. package/domainforge-core/CHANGELOG.md +138 -0
  146. package/domainforge-core/Cargo.toml +101 -0
  147. package/domainforge-core/MIGRATING.md +32 -0
  148. package/domainforge-core/README.md +197 -0
  149. package/domainforge-core/benchmark_results.txt +51 -0
  150. package/domainforge-core/build.rs +6 -0
  151. package/domainforge-core/deny.toml +31 -0
  152. package/domainforge-core/docs/specs/projections/sbvr_kg_mapping.md +43 -0
  153. package/domainforge-core/examples/basic.sea +7 -0
  154. package/domainforge-core/examples/cli/import_export_workflow.sh +38 -0
  155. package/domainforge-core/examples/cli/validate_example.sh +30 -0
  156. package/domainforge-core/examples/evolution_semantics.sea +31 -0
  157. package/domainforge-core/examples/parser_demo.rs +203 -0
  158. package/domainforge-core/grammar/sea.pest +408 -0
  159. package/domainforge-core/schemas/calm-v1.schema.json +170 -0
  160. package/domainforge-core/schemas/shacl/sea_shapes.ttl +19 -0
  161. package/domainforge-core/src/authority/compiler.rs +309 -0
  162. package/domainforge-core/src/authority/environment.rs +203 -0
  163. package/domainforge-core/src/authority/error.rs +164 -0
  164. package/domainforge-core/src/authority/fact_resolver.rs +224 -0
  165. package/domainforge-core/src/authority/mod.rs +25 -0
  166. package/domainforge-core/src/authority/pack.rs +133 -0
  167. package/domainforge-core/src/authority/policy.rs +224 -0
  168. package/domainforge-core/src/authority/resolver.rs +446 -0
  169. package/domainforge-core/src/authority/trace.rs +217 -0
  170. package/domainforge-core/src/authority/transform.rs +168 -0
  171. package/domainforge-core/src/authority/types.rs +617 -0
  172. package/domainforge-core/src/bin/domainforge.rs +25 -0
  173. package/domainforge-core/src/calm/export.rs +538 -0
  174. package/domainforge-core/src/calm/import.rs +1220 -0
  175. package/domainforge-core/src/calm/mod.rs +9 -0
  176. package/domainforge-core/src/calm/models.rs +108 -0
  177. package/domainforge-core/src/calm/sbvr_import.rs +9 -0
  178. package/domainforge-core/src/cli/authority.rs +149 -0
  179. package/domainforge-core/src/cli/format.rs +85 -0
  180. package/domainforge-core/src/cli/import.rs +133 -0
  181. package/domainforge-core/src/cli/mod.rs +64 -0
  182. package/domainforge-core/src/cli/normalize.rs +180 -0
  183. package/domainforge-core/src/cli/pack.rs +904 -0
  184. package/domainforge-core/src/cli/parse.rs +112 -0
  185. package/domainforge-core/src/cli/project.rs +294 -0
  186. package/domainforge-core/src/cli/registry.rs +41 -0
  187. package/domainforge-core/src/cli/test.rs +12 -0
  188. package/domainforge-core/src/cli/validate.rs +195 -0
  189. package/domainforge-core/src/cli/validate_kg.rs +80 -0
  190. package/domainforge-core/src/concept_id.rs +89 -0
  191. package/domainforge-core/src/error/diagnostics.rs +426 -0
  192. package/domainforge-core/src/error/fuzzy.rs +253 -0
  193. package/domainforge-core/src/error/mod.rs +13 -0
  194. package/domainforge-core/src/formatter/comments.rs +223 -0
  195. package/domainforge-core/src/formatter/config.rs +114 -0
  196. package/domainforge-core/src/formatter/mod.rs +22 -0
  197. package/domainforge-core/src/formatter/printer.rs +906 -0
  198. package/domainforge-core/src/graph/mod.rs +858 -0
  199. package/domainforge-core/src/graph/to_ast.rs +66 -0
  200. package/domainforge-core/src/kg.rs +1476 -0
  201. package/domainforge-core/src/kg_import.rs +251 -0
  202. package/domainforge-core/src/lib.rs +203 -0
  203. package/domainforge-core/src/module/mod.rs +1 -0
  204. package/domainforge-core/src/module/resolver.rs +260 -0
  205. package/domainforge-core/src/parser/ast.rs +2919 -0
  206. package/domainforge-core/src/parser/ast_convert.rs +494 -0
  207. package/domainforge-core/src/parser/ast_schema.rs +491 -0
  208. package/domainforge-core/src/parser/error.rs +291 -0
  209. package/domainforge-core/src/parser/lint.rs +39 -0
  210. package/domainforge-core/src/parser/mod.rs +193 -0
  211. package/domainforge-core/src/parser/printer.rs +702 -0
  212. package/domainforge-core/src/parser/profiles.rs +71 -0
  213. package/domainforge-core/src/parser/string_utils.rs +138 -0
  214. package/domainforge-core/src/patterns.rs +68 -0
  215. package/domainforge-core/src/policy/core.rs +1148 -0
  216. package/domainforge-core/src/policy/expression.rs +399 -0
  217. package/domainforge-core/src/policy/mod.rs +18 -0
  218. package/domainforge-core/src/policy/normalize.rs +1028 -0
  219. package/domainforge-core/src/policy/quantifier.rs +940 -0
  220. package/domainforge-core/src/policy/three_valued.rs +140 -0
  221. package/domainforge-core/src/policy/three_valued_microbench.rs +104 -0
  222. package/domainforge-core/src/policy/type_inference.rs +67 -0
  223. package/domainforge-core/src/policy/violation.rs +36 -0
  224. package/domainforge-core/src/primitives/concept_change.rs +61 -0
  225. package/domainforge-core/src/primitives/entity.rs +224 -0
  226. package/domainforge-core/src/primitives/flow.rs +111 -0
  227. package/domainforge-core/src/primitives/instance.rs +93 -0
  228. package/domainforge-core/src/primitives/mapping_contract.rs +50 -0
  229. package/domainforge-core/src/primitives/metric.rs +79 -0
  230. package/domainforge-core/src/primitives/mod.rs +25 -0
  231. package/domainforge-core/src/primitives/projection_contract.rs +50 -0
  232. package/domainforge-core/src/primitives/quantity.rs +56 -0
  233. package/domainforge-core/src/primitives/relation.rs +68 -0
  234. package/domainforge-core/src/primitives/resource.rs +237 -0
  235. package/domainforge-core/src/primitives/resource_instance.rs +88 -0
  236. package/domainforge-core/src/primitives/role.rs +49 -0
  237. package/domainforge-core/src/projection/buf.rs +404 -0
  238. package/domainforge-core/src/projection/contracts.rs +22 -0
  239. package/domainforge-core/src/projection/engine.rs +19 -0
  240. package/domainforge-core/src/projection/mod.rs +16 -0
  241. package/domainforge-core/src/projection/protobuf.rs +3331 -0
  242. package/domainforge-core/src/projection/registry.rs +43 -0
  243. package/domainforge-core/src/python/authority.rs +253 -0
  244. package/domainforge-core/src/python/error.rs +227 -0
  245. package/domainforge-core/src/python/formatter.rs +86 -0
  246. package/domainforge-core/src/python/graph.rs +366 -0
  247. package/domainforge-core/src/python/mod.rs +9 -0
  248. package/domainforge-core/src/python/policy.rs +651 -0
  249. package/domainforge-core/src/python/primitives.rs +796 -0
  250. package/domainforge-core/src/python/registry.rs +98 -0
  251. package/domainforge-core/src/python/semantic_pack.rs +619 -0
  252. package/domainforge-core/src/python/units.rs +96 -0
  253. package/domainforge-core/src/registry/mod.rs +432 -0
  254. package/domainforge-core/src/registry/tests.rs +210 -0
  255. package/domainforge-core/src/sbvr.rs +744 -0
  256. package/domainforge-core/src/semantic_pack/builder.rs +470 -0
  257. package/domainforge-core/src/semantic_pack/canonical_json.rs +184 -0
  258. package/domainforge-core/src/semantic_pack/diagnostics.rs +214 -0
  259. package/domainforge-core/src/semantic_pack/diff.rs +216 -0
  260. package/domainforge-core/src/semantic_pack/mod.rs +31 -0
  261. package/domainforge-core/src/semantic_pack/pack_set.rs +240 -0
  262. package/domainforge-core/src/semantic_pack/resolver.rs +437 -0
  263. package/domainforge-core/src/semantic_pack/review.rs +125 -0
  264. package/domainforge-core/src/semantic_pack/schema.rs +342 -0
  265. package/domainforge-core/src/semantic_pack/signing.rs +105 -0
  266. package/domainforge-core/src/semantic_pack/validator.rs +368 -0
  267. package/domainforge-core/src/semantic_version.rs +140 -0
  268. package/domainforge-core/src/test_utils.rs +12 -0
  269. package/domainforge-core/src/typescript/authority.rs +184 -0
  270. package/domainforge-core/src/typescript/error.rs +146 -0
  271. package/domainforge-core/src/typescript/formatter.rs +76 -0
  272. package/domainforge-core/src/typescript/graph.rs +391 -0
  273. package/domainforge-core/src/typescript/mod.rs +9 -0
  274. package/domainforge-core/src/typescript/policy.rs +564 -0
  275. package/domainforge-core/src/typescript/primitives.rs +784 -0
  276. package/domainforge-core/src/typescript/registry.rs +88 -0
  277. package/domainforge-core/src/typescript/semantic_pack.rs +470 -0
  278. package/domainforge-core/src/typescript/units.rs +76 -0
  279. package/domainforge-core/src/units/mod.rs +462 -0
  280. package/domainforge-core/src/uuid_module.rs +42 -0
  281. package/domainforge-core/src/validation_error.rs +818 -0
  282. package/domainforge-core/src/validation_result.rs +30 -0
  283. package/domainforge-core/src/wasm/authority.rs +192 -0
  284. package/domainforge-core/src/wasm/error.rs +145 -0
  285. package/domainforge-core/src/wasm/formatter.rs +69 -0
  286. package/domainforge-core/src/wasm/graph.rs +471 -0
  287. package/domainforge-core/src/wasm/mod.rs +16 -0
  288. package/domainforge-core/src/wasm/policy.rs +607 -0
  289. package/domainforge-core/src/wasm/primitives.rs +295 -0
  290. package/domainforge-core/src/wasm/semantic_pack.rs +471 -0
  291. package/domainforge-core/src/wasm/units.rs +62 -0
  292. package/domainforge-core/std/aws.sea +6 -0
  293. package/domainforge-core/std/core.sea +6 -0
  294. package/domainforge-core/std/http.sea +27 -0
  295. package/domainforge-core/tests/aggregation_enhanced_tests.rs +162 -0
  296. package/domainforge-core/tests/aggregation_eval_tests.rs +248 -0
  297. package/domainforge-core/tests/aggregation_integration_tests.rs +379 -0
  298. package/domainforge-core/tests/aggregation_parser_tests.rs +92 -0
  299. package/domainforge-core/tests/aggregation_tests.rs +102 -0
  300. package/domainforge-core/tests/authority_conformance_tests.rs +1173 -0
  301. package/domainforge-core/tests/calm_round_trip_tests.rs +283 -0
  302. package/domainforge-core/tests/calm_schema_validation_tests.rs +137 -0
  303. package/domainforge-core/tests/cast_operator_tests.rs +85 -0
  304. package/domainforge-core/tests/cli_binary_check.rs +37 -0
  305. package/domainforge-core/tests/cli_import_tests.rs +291 -0
  306. package/domainforge-core/tests/cli_path_traversal_tests.rs +124 -0
  307. package/domainforge-core/tests/cli_tests.rs +63 -0
  308. package/domainforge-core/tests/diagnostics_tests.rs +203 -0
  309. package/domainforge-core/tests/dimension_unit_tests.rs +80 -0
  310. package/domainforge-core/tests/entity_tests.rs +69 -0
  311. package/domainforge-core/tests/evolution_semantics_tests.rs +157 -0
  312. package/domainforge-core/tests/flow_tests.rs +78 -0
  313. package/domainforge-core/tests/flow_unit_validation_tests.rs +31 -0
  314. package/domainforge-core/tests/graph_integration_tests.rs +218 -0
  315. package/domainforge-core/tests/graph_tests.rs +626 -0
  316. package/domainforge-core/tests/import_parsing_tests.rs +23 -0
  317. package/domainforge-core/tests/instance_integration_tests.rs +98 -0
  318. package/domainforge-core/tests/instance_parsing_tests.rs +58 -0
  319. package/domainforge-core/tests/instance_tests.rs +61 -0
  320. package/domainforge-core/tests/kg_uri_encoding_tests.rs +53 -0
  321. package/domainforge-core/tests/lint_tests.rs +19 -0
  322. package/domainforge-core/tests/metric_tests.rs +143 -0
  323. package/domainforge-core/tests/module_resolution_tests.rs +100 -0
  324. package/domainforge-core/tests/namespace_registry_tests.rs +247 -0
  325. package/domainforge-core/tests/null_handling_tests.rs +26 -0
  326. package/domainforge-core/tests/parser_ast_v3.rs +53 -0
  327. package/domainforge-core/tests/parser_dimension_registry_tests.rs +20 -0
  328. package/domainforge-core/tests/parser_integration_tests.rs +294 -0
  329. package/domainforge-core/tests/parser_metadata_tests.rs +97 -0
  330. package/domainforge-core/tests/parser_resource_domain_only_graph_test.rs +21 -0
  331. package/domainforge-core/tests/parser_resource_limits_tests.rs +122 -0
  332. package/domainforge-core/tests/parser_tests.rs +512 -0
  333. package/domainforge-core/tests/pattern_semantics_tests.rs +87 -0
  334. package/domainforge-core/tests/phase_14_determinism_tests.rs +166 -0
  335. package/domainforge-core/tests/phase_15_validation_error_tests.rs +136 -0
  336. package/domainforge-core/tests/phase_16_unicode_tests.rs +248 -0
  337. package/domainforge-core/tests/phase_17_export_tests.rs +285 -0
  338. package/domainforge-core/tests/phase_17_round_trip_tests.rs +264 -0
  339. package/domainforge-core/tests/policy_tests.rs +635 -0
  340. package/domainforge-core/tests/primitives_integration_tests.rs +151 -0
  341. package/domainforge-core/tests/print_rdf_xml.rs +14 -0
  342. package/domainforge-core/tests/printer_tests.rs +204 -0
  343. package/domainforge-core/tests/profile_tests.rs +35 -0
  344. package/domainforge-core/tests/projection_contracts_tests.rs +154 -0
  345. package/domainforge-core/tests/protobuf_projection_tests.rs +199 -0
  346. package/domainforge-core/tests/quantity_tests.rs +41 -0
  347. package/domainforge-core/tests/rdf_xml_typed_literal_tests.rs +105 -0
  348. package/domainforge-core/tests/registry_schema_tests.rs +33 -0
  349. package/domainforge-core/tests/resource_tests.rs +50 -0
  350. package/domainforge-core/tests/resource_unit_tests.rs +24 -0
  351. package/domainforge-core/tests/roles_relations_tests.rs +61 -0
  352. package/domainforge-core/tests/round_trip_tests.rs +34 -0
  353. package/domainforge-core/tests/runtime_toggle_tests.rs +70 -0
  354. package/domainforge-core/tests/sbvr_fact_schema_tests.rs +60 -0
  355. package/domainforge-core/tests/sbvr_flow_facts_tests.rs +55 -0
  356. package/domainforge-core/tests/sbvr_parsing_tests.rs +53 -0
  357. package/domainforge-core/tests/semantic_pack_alias_resolution.rs +197 -0
  358. package/domainforge-core/tests/semantic_pack_build.rs +302 -0
  359. package/domainforge-core/tests/semantic_pack_consumer_smoke.rs +150 -0
  360. package/domainforge-core/tests/semantic_pack_pack_set.rs +160 -0
  361. package/domainforge-core/tests/semantic_pack_signing.rs +157 -0
  362. package/domainforge-core/tests/semantic_pack_three_valued.rs +250 -0
  363. package/domainforge-core/tests/semantic_pack_validate.rs +196 -0
  364. package/domainforge-core/tests/std_lib_tests.rs +37 -0
  365. package/domainforge-core/tests/temporal_evaluation_tests.rs +159 -0
  366. package/domainforge-core/tests/temporal_semantics_tests.rs +214 -0
  367. package/domainforge-core/tests/three_valued_quantifiers_tests.rs +164 -0
  368. package/domainforge-core/tests/turtle_entity_export_tests.rs +38 -0
  369. package/domainforge-core/tests/turtle_escaping_tests.rs +53 -0
  370. package/domainforge-core/tests/turtle_resource_export_tests.rs +34 -0
  371. package/domainforge-core/tests/type_inference_tests.rs +40 -0
  372. package/domainforge-core/tests/unicode_validation_tests.rs +169 -0
  373. package/domainforge-core/tests/unit_tests.rs +81 -0
  374. package/domainforge-core/tests/validate_tests.rs +38 -0
  375. package/domainforge-core/tests/validation_unit_mismatch_tests.rs +83 -0
  376. package/domainforge-core/tests/wasm_tests.rs +229 -0
  377. package/domainforge-python/CHANGELOG-python.md +12 -0
  378. package/domainforge-python/MIGRATING.md +24 -0
  379. package/domainforge-python/README.md +256 -0
  380. package/domainforge-python/domainforge/__init__.py +95 -0
  381. package/domainforge-python/domainforge/domainforge.pyi +519 -0
  382. package/domainforge-python/pyproject.toml +36 -0
  383. package/domainforge-typescript/CHANGELOG-typescript.md +12 -0
  384. package/domainforge-typescript/LICENSE +201 -0
  385. package/domainforge-typescript/MIGRATING.md +24 -0
  386. package/domainforge-typescript/README.md +305 -0
  387. package/domainforge-typescript/index.d.ts +452 -0
  388. package/domainforge-typescript/index.js +361 -0
  389. package/domainforge-typescript/package.json +60 -0
  390. package/example.js +61 -0
  391. package/examples/browser.html +366 -0
  392. package/examples/namespaces/finance/cashflow.sea +5 -0
  393. package/examples/namespaces/logistics/core.sea +7 -0
  394. package/examples/observability_metrics.sea +38 -0
  395. package/fixtures/semantic_packs/acme_procurement/domain/entities.sea +39 -0
  396. package/fixtures/semantic_packs/acme_procurement/domain/metrics.sea +11 -0
  397. package/fixtures/semantic_packs/acme_procurement/domain/relations.sea +7 -0
  398. package/fixtures/semantic_packs/acme_procurement/domain/resources.sea +9 -0
  399. package/fixtures/semantic_packs/acme_procurement/review/acme.procurement.semantic-review.jsonl +7 -0
  400. package/fixtures/semantic_packs/acme_procurement/tests/ambiguous_vendor_alias.sea +8 -0
  401. package/fixtures/semantic_packs/acme_procurement/tests/deprecated_vendor_alias.sea +8 -0
  402. package/fixtures/semantic_packs/acme_procurement/tests/invalid_relation.sea +3 -0
  403. package/fixtures/semantic_packs/acme_procurement/tests/proposed_concept.sea +8 -0
  404. package/fixtures/semantic_packs/acme_procurement/tests/rejected_concept.sea +8 -0
  405. package/fixtures/semantic_packs/acme_procurement/tests/unit_mismatch.sea +7 -0
  406. package/fixtures/semantic_packs/acme_procurement/tests/unknown_vendor_policy.sea +8 -0
  407. package/fixtures/semantic_packs/acme_procurement/tests/valid_purchase_policy.sea +8 -0
  408. package/index.d.ts +2 -0
  409. package/index.js +8 -0
  410. package/justfile +200 -0
  411. package/lefthook.yml +13 -0
  412. package/lib/validate_native_exports.d.ts +4 -0
  413. package/lib/validate_native_exports.js +12 -0
  414. package/package.json +22 -0
  415. package/pytest.ini +5 -0
  416. package/python/tests/test_registry.py +75 -0
  417. package/python/tests/test_units.py +18 -0
  418. package/release-please-config.json +49 -0
  419. package/requirements-dev.txt +3 -0
  420. package/requirements.txt +3 -0
  421. package/rust-toolchain.toml +3 -0
  422. package/schemas/ast-v1.schema.json +72 -0
  423. package/schemas/ast-v2.schema.json +1200 -0
  424. package/schemas/ast-v3.schema.json +1200 -0
  425. package/schemas/sea-registry.schema.json +45 -0
  426. package/scripts/build-python.sh +37 -0
  427. package/scripts/build-release.sh +279 -0
  428. package/scripts/build-typescript.sh +13 -0
  429. package/scripts/build-wasm.sh +113 -0
  430. package/scripts/bump-version.sh +245 -0
  431. package/scripts/check_unused_test_imports.py +85 -0
  432. package/scripts/ci_tasks.py +379 -0
  433. package/scripts/clear_debug_test.sh +10 -0
  434. package/scripts/create-github-release.sh +262 -0
  435. package/scripts/create-tag.sh +203 -0
  436. package/scripts/find_and_link_test_binary.sh +70 -0
  437. package/scripts/generate-changelog.sh +271 -0
  438. package/scripts/generate-release-notes.sh +205 -0
  439. package/scripts/lint_release_security.py +96 -0
  440. package/scripts/lint_release_workflows.py +82 -0
  441. package/scripts/lint_workflow_gates.py +113 -0
  442. package/scripts/optimized-wasm-build.sh +61 -0
  443. package/scripts/patch_napi_types.py +62 -0
  444. package/scripts/pre-release-check.sh +289 -0
  445. package/scripts/prepare_rust_debug.sh +52 -0
  446. package/scripts/release.sh +373 -0
  447. package/scripts/resolve_rust_binary.py +230 -0
  448. package/scripts/run_commitlint.sh +29 -0
  449. package/scripts/test-all.sh +77 -0
  450. package/scripts/update_launch_program.py +93 -0
  451. package/secrets/README.md +27 -0
  452. package/secrets/secrets.yaml +21 -0
  453. package/test_integration.py +67 -0
  454. package/tests/test_authority.py +328 -0
  455. package/tests/test_ci_tasks.py +143 -0
  456. package/tests/test_expression.py +256 -0
  457. package/tests/test_golden_payment_flow.py +42 -0
  458. package/tests/test_graph.py +127 -0
  459. package/tests/test_instance.py +136 -0
  460. package/tests/test_parser.py +82 -0
  461. package/tests/test_primitives.py +68 -0
  462. package/tests/test_role_relation_parity.py +56 -0
  463. package/tests/test_runtime_toggle.py +156 -0
  464. package/tests/test_semantic_pack.py +639 -0
  465. package/tests/test_three_valued_eval.py +159 -0
  466. package/tsconfig.json +30 -0
  467. package/typescript-tests/advanced.test.ts +165 -0
  468. package/typescript-tests/authority.test.ts +216 -0
  469. package/typescript-tests/expression.test.ts +228 -0
  470. package/typescript-tests/golden-payment-flow.test.ts +51 -0
  471. package/typescript-tests/graph.test.ts +142 -0
  472. package/typescript-tests/native-binding.test.ts +20 -0
  473. package/typescript-tests/primitives.test.ts +88 -0
  474. package/typescript-tests/registry.test.ts +122 -0
  475. package/typescript-tests/role_relation.test.ts +63 -0
  476. package/typescript-tests/runtime_toggle.test.ts +141 -0
  477. package/typescript-tests/semantic-pack.test.ts +556 -0
  478. package/typescript-tests/three_valued_eval.test.ts +135 -0
  479. package/typescript-tests/units.test.ts +36 -0
  480. package/vitest.config.ts +13 -0
  481. package/wasm_demo.html +225 -0
@@ -0,0 +1,470 @@
1
+ use serde::Deserialize;
2
+
3
+ use super::canonical_json;
4
+ use super::diagnostics::{
5
+ DiagnosticSeverity, SemanticDiagnostic, SemanticDiagnosticCode, SemanticTruth,
6
+ };
7
+ use super::review::{self, DefinitionHashResult};
8
+ use super::schema::{
9
+ AliasDef, ApprovalState, CompatibilityInfo, ConceptDef, ConceptStatus, GeneratorInfo, PackRef,
10
+ PackTrust, ReviewRecord, SemanticPack, SignatureState, SourceRef,
11
+ };
12
+
13
+ /// Input for building a semantic pack.
14
+ #[derive(Debug, Clone, Deserialize)]
15
+ pub struct PackBuildInput {
16
+ pub org_id: String,
17
+ pub domain_id: String,
18
+ pub pack_version: String,
19
+ pub meaning_version: String,
20
+ pub approval: ApprovalState,
21
+ pub concepts: Vec<ConceptDef>,
22
+ pub relations: Vec<super::schema::RelationDef>,
23
+ pub metrics: Vec<super::schema::MetricDef>,
24
+ pub dimensions: Vec<super::schema::DimensionDef>,
25
+ pub units: Vec<super::schema::UnitDef>,
26
+ pub aliases: Vec<AliasDef>,
27
+ pub mapping_rules: Vec<super::schema::MappingRuleDef>,
28
+ pub review_records: Vec<ReviewRecord>,
29
+ pub previous_pack: Option<SemanticPack>,
30
+ pub allow_first_approved_version: bool,
31
+ pub source_graph_hash: String,
32
+ }
33
+
34
+ /// Output from building a semantic pack.
35
+ #[derive(Debug, Clone)]
36
+ pub struct PackBuildOutput {
37
+ pub pack: SemanticPack,
38
+ pub pack_content_hash: String,
39
+ pub meaning_fingerprint: String,
40
+ pub pre_pack_diagnostics: Vec<SemanticDiagnostic>,
41
+ pub build_warnings: Vec<SemanticDiagnostic>,
42
+ }
43
+
44
+ /// Build a semantic pack from input.
45
+ pub fn build_semantic_pack(
46
+ input: PackBuildInput,
47
+ ) -> Result<PackBuildOutput, Vec<SemanticDiagnostic>> {
48
+ let mut pre_pack_diagnostics = Vec::new();
49
+
50
+ // Run pre-pack checks (§5.1)
51
+ let mut build_warnings = Vec::new();
52
+ run_pre_pack_checks(&input, &mut pre_pack_diagnostics, &mut build_warnings);
53
+
54
+ // Check review coverage for approved builds
55
+ if matches!(input.approval, ApprovalState::Approved) {
56
+ check_review_coverage(&input, &mut pre_pack_diagnostics, &mut build_warnings);
57
+ }
58
+
59
+ // Build the pack
60
+ let pack_id = format!(
61
+ "{}/{}/{}",
62
+ input.org_id, input.domain_id, input.pack_version
63
+ );
64
+ let generator = GeneratorInfo {
65
+ name: "domainforge-core".to_string(),
66
+ version: "0.3".to_string(),
67
+ };
68
+
69
+ // Compute review manifest hash
70
+ let review_manifest_hash = review::compute_review_manifest_hash(&input.review_records);
71
+
72
+ // Compute definition hashes for concepts
73
+ let mut concepts = input.concepts;
74
+ for c in &mut concepts {
75
+ if c.definition.definition_hash.is_empty() {
76
+ c.definition.definition_hash = canonical_json::compute_definition_hash(
77
+ &c.definition.text,
78
+ &c.examples,
79
+ &c.counterexamples,
80
+ &serde_json::to_value(c.status)
81
+ .ok()
82
+ .and_then(|v| v.as_str().map(String::from))
83
+ .unwrap_or_default(),
84
+ );
85
+ }
86
+ }
87
+
88
+ // Normalize aliases
89
+ let mut aliases = input.aliases;
90
+ for a in &mut aliases {
91
+ a.normalized_alias = super::resolver::normalize_lookup_key(&a.alias);
92
+ }
93
+
94
+ let mut pack = SemanticPack {
95
+ schema_version: "0.3".to_string(),
96
+ pack_id: pack_id.clone(),
97
+ org_id: input.org_id,
98
+ domain_id: input.domain_id,
99
+ pack_version: input.pack_version,
100
+ meaning_version: input.meaning_version,
101
+ meaning_fingerprint: String::new(), // computed below
102
+ source_graph_hash: input.source_graph_hash,
103
+ build_config_hash: canonical_json::compute_sha256(b"{}"),
104
+ review_manifest_hash,
105
+ created_at: chrono::Utc::now().to_rfc3339(),
106
+ generator,
107
+ trust: PackTrust {
108
+ approval_state: input.approval,
109
+ signature_state: SignatureState::Unsigned,
110
+ signed_by: None,
111
+ signature_alg: None,
112
+ signature: None,
113
+ },
114
+ concepts,
115
+ relations: input.relations,
116
+ metrics: input.metrics,
117
+ dimensions: input.dimensions,
118
+ units: input.units,
119
+ aliases,
120
+ mapping_rules: input.mapping_rules,
121
+ compatibility: CompatibilityInfo::default(),
122
+ };
123
+
124
+ // Compute meaning fingerprint
125
+ pack.meaning_fingerprint = canonical_json::compute_meaning_fingerprint(&pack);
126
+
127
+ // Sort for canonicalization
128
+ canonical_json::sort_pack_for_canonicalization(&mut pack);
129
+
130
+ // Compute content hash
131
+ let pack_content_hash = canonical_json::compute_pack_content_hash(&pack);
132
+
133
+ // Check meaning version (§4.1)
134
+ if let Some(ref prev) = input.previous_pack {
135
+ if prev.meaning_fingerprint != pack.meaning_fingerprint {
136
+ // Meaning changed — version must increase
137
+ match version_increased(&prev.meaning_version, &pack.meaning_version) {
138
+ None => {
139
+ pre_pack_diagnostics.push(SemanticDiagnostic {
140
+ code: SemanticDiagnosticCode::MeaningVersionNotBumped,
141
+ severity: DiagnosticSeverity::Error,
142
+ semantic_truth: SemanticTruth::Invalid,
143
+ message: format!(
144
+ "Invalid version format: meaning_version '{}' or previous meaning_version '{}' contains non-numeric segments",
145
+ pack.meaning_version, prev.meaning_version
146
+ ),
147
+ source_ref: SourceRef::pack_uri(&pack_id),
148
+ pack_ref: PackRef {
149
+ pack_id: pack_id.clone(),
150
+ pack_content_hash: pack_content_hash.clone(),
151
+ path_or_uri: format!("pack://{}", pack_id),
152
+ priority: 0,
153
+ },
154
+ suggestions: vec![],
155
+ recoverability_hint: "Use numeric-only version format (e.g., MAJOR.MINOR.PATCH)".to_string(),
156
+ });
157
+ }
158
+ Some(false) => {
159
+ pre_pack_diagnostics.push(SemanticDiagnostic {
160
+ code: SemanticDiagnosticCode::MeaningVersionNotBumped,
161
+ severity: DiagnosticSeverity::Error,
162
+ semantic_truth: SemanticTruth::Invalid,
163
+ message: format!(
164
+ "meaning_fingerprint changed but meaning_version '{}' did not increase from '{}'",
165
+ pack.meaning_version, prev.meaning_version
166
+ ),
167
+ source_ref: SourceRef::pack_uri(&pack_id),
168
+ pack_ref: PackRef {
169
+ pack_id: pack_id.clone(),
170
+ pack_content_hash: pack_content_hash.clone(),
171
+ path_or_uri: format!("pack://{}", pack_id),
172
+ priority: 0,
173
+ },
174
+ suggestions: vec![],
175
+ recoverability_hint: "Bump meaning_version (MAJOR.MINOR.PATCH)".to_string(),
176
+ });
177
+ }
178
+ Some(true) => {
179
+ // Version properly increased, no error
180
+ }
181
+ }
182
+ }
183
+ } else if matches!(input.approval, ApprovalState::Approved)
184
+ && !input.allow_first_approved_version
185
+ {
186
+ pre_pack_diagnostics.push(SemanticDiagnostic {
187
+ code: SemanticDiagnosticCode::MeaningVersionBaselineMissing,
188
+ severity: DiagnosticSeverity::Error,
189
+ semantic_truth: SemanticTruth::Unknown,
190
+ message: "No previous pack provided for approved build; use --allow-first-approved-version for initial pack".to_string(),
191
+ source_ref: SourceRef::pack_uri(&pack_id),
192
+ pack_ref: PackRef {
193
+ pack_id: pack_id.clone(),
194
+ pack_content_hash: pack_content_hash.clone(),
195
+ path_or_uri: format!("pack://{}", pack_id),
196
+ priority: 0,
197
+ },
198
+ suggestions: vec![],
199
+ recoverability_hint: "Provide --previous-pack or --allow-first-approved-version".to_string(),
200
+ });
201
+ }
202
+
203
+ // Block approved builds on pre-pack errors
204
+ if matches!(input.approval, ApprovalState::Approved) {
205
+ let has_errors = pre_pack_diagnostics
206
+ .iter()
207
+ .any(|d| d.severity == DiagnosticSeverity::Error);
208
+ if has_errors {
209
+ return Err(pre_pack_diagnostics);
210
+ }
211
+ }
212
+
213
+ let meaning_fingerprint = pack.meaning_fingerprint.clone();
214
+
215
+ Ok(PackBuildOutput {
216
+ pack,
217
+ pack_content_hash,
218
+ meaning_fingerprint,
219
+ pre_pack_diagnostics,
220
+ build_warnings,
221
+ })
222
+ }
223
+
224
+ fn run_pre_pack_checks(
225
+ input: &PackBuildInput,
226
+ diagnostics: &mut Vec<SemanticDiagnostic>,
227
+ build_warnings: &mut Vec<SemanticDiagnostic>,
228
+ ) {
229
+ let dummy_ref = PackRef {
230
+ pack_id: format!(
231
+ "{}/{}/{}",
232
+ input.org_id, input.domain_id, input.pack_version
233
+ ),
234
+ pack_content_hash: String::new(),
235
+ path_or_uri: String::new(),
236
+ priority: 0,
237
+ };
238
+
239
+ // Duplicate concept IDs
240
+ let mut seen_ids: std::collections::HashSet<String> = std::collections::HashSet::new();
241
+ for c in &input.concepts {
242
+ if !seen_ids.insert(c.id.clone()) {
243
+ diagnostics.push(SemanticDiagnostic {
244
+ code: SemanticDiagnosticCode::DuplicateConceptId,
245
+ severity: DiagnosticSeverity::Error,
246
+ semantic_truth: SemanticTruth::Invalid,
247
+ message: format!("Duplicate concept ID: '{}'", c.id),
248
+ source_ref: SourceRef::pack_uri(&dummy_ref.pack_id),
249
+ pack_ref: dummy_ref.clone(),
250
+ suggestions: vec![],
251
+ recoverability_hint: "Rename duplicate concepts".to_string(),
252
+ });
253
+ }
254
+ }
255
+
256
+ // Duplicate canonical names
257
+ let mut seen_names: std::collections::HashMap<String, String> =
258
+ std::collections::HashMap::new();
259
+ for c in &input.concepts {
260
+ let norm = super::resolver::normalize_lookup_key(&c.canonical_name);
261
+ if let Some(existing) = seen_names.get(&norm) {
262
+ if existing != &c.id {
263
+ diagnostics.push(SemanticDiagnostic {
264
+ code: SemanticDiagnosticCode::DuplicateCanonicalName,
265
+ severity: DiagnosticSeverity::Error,
266
+ semantic_truth: SemanticTruth::Invalid,
267
+ message: format!(
268
+ "Duplicate canonical name '{}' for concepts '{}' and '{}'",
269
+ c.canonical_name, existing, c.id
270
+ ),
271
+ source_ref: SourceRef::pack_uri(&dummy_ref.pack_id),
272
+ pack_ref: dummy_ref.clone(),
273
+ suggestions: vec![],
274
+ recoverability_hint: "Ensure canonical names are unique".to_string(),
275
+ });
276
+ }
277
+ } else {
278
+ seen_names.insert(norm, c.id.clone());
279
+ }
280
+ }
281
+
282
+ // Active concept without definition
283
+ for c in &input.concepts {
284
+ if matches!(c.status, ConceptStatus::Active) && c.definition.text.is_empty() {
285
+ diagnostics.push(SemanticDiagnostic {
286
+ code: SemanticDiagnosticCode::MissingDefinition,
287
+ severity: DiagnosticSeverity::Warning,
288
+ semantic_truth: SemanticTruth::Unknown,
289
+ message: format!("Active concept '{}' missing definition", c.id),
290
+ source_ref: SourceRef::pack_uri(&dummy_ref.pack_id),
291
+ pack_ref: dummy_ref.clone(),
292
+ suggestions: vec![],
293
+ recoverability_hint: "Add definition text".to_string(),
294
+ });
295
+ }
296
+ }
297
+
298
+ // Active concept without owner
299
+ for c in &input.concepts {
300
+ if matches!(c.status, ConceptStatus::Active) && c.owner.is_empty() {
301
+ diagnostics.push(SemanticDiagnostic {
302
+ code: SemanticDiagnosticCode::MissingOwner,
303
+ severity: DiagnosticSeverity::Warning,
304
+ semantic_truth: SemanticTruth::Unknown,
305
+ message: format!("Active concept '{}' missing owner", c.id),
306
+ source_ref: SourceRef::pack_uri(&dummy_ref.pack_id),
307
+ pack_ref: dummy_ref.clone(),
308
+ suggestions: vec![],
309
+ recoverability_hint: "Assign an owner".to_string(),
310
+ });
311
+ }
312
+ }
313
+
314
+ // Alias target missing
315
+ let concept_ids: std::collections::HashSet<&str> =
316
+ input.concepts.iter().map(|c| c.id.as_str()).collect();
317
+ for a in &input.aliases {
318
+ if !concept_ids.contains(a.target_concept_id.as_str()) {
319
+ diagnostics.push(SemanticDiagnostic {
320
+ code: SemanticDiagnosticCode::UnknownConcept,
321
+ severity: DiagnosticSeverity::Error,
322
+ semantic_truth: SemanticTruth::Invalid,
323
+ message: format!(
324
+ "Alias '{}' targets missing concept '{}'",
325
+ a.alias, a.target_concept_id
326
+ ),
327
+ source_ref: SourceRef::pack_uri(&dummy_ref.pack_id),
328
+ pack_ref: dummy_ref.clone(),
329
+ suggestions: vec![],
330
+ recoverability_hint: "Add the target concept".to_string(),
331
+ });
332
+ }
333
+ }
334
+
335
+ // Alias conflict detection (§5.1)
336
+ let conflict_report = super::resolver::detect_alias_conflicts(&input.aliases);
337
+ for key in &conflict_report.conflicting_keys {
338
+ diagnostics.push(SemanticDiagnostic {
339
+ code: SemanticDiagnosticCode::AliasConflict,
340
+ severity: DiagnosticSeverity::Error,
341
+ semantic_truth: SemanticTruth::Invalid,
342
+ message: format!(
343
+ "Alias conflict for key '{}': multiple targets through approved/deprecated entries",
344
+ key
345
+ ),
346
+ source_ref: SourceRef::pack_uri(&dummy_ref.pack_id),
347
+ pack_ref: dummy_ref.clone(),
348
+ suggestions: vec![],
349
+ recoverability_hint: "Resolve conflicting aliases".to_string(),
350
+ });
351
+ }
352
+ for key in &conflict_report.ambiguous_only_keys {
353
+ build_warnings_push(build_warnings, key, &dummy_ref);
354
+ }
355
+ }
356
+
357
+ fn build_warnings_push(diagnostics: &mut Vec<SemanticDiagnostic>, key: &str, pack_ref: &PackRef) {
358
+ diagnostics.push(SemanticDiagnostic {
359
+ code: SemanticDiagnosticCode::AmbiguousAliasGroup,
360
+ severity: DiagnosticSeverity::Warning,
361
+ semantic_truth: SemanticTruth::Unknown,
362
+ message: format!("Ambiguous-only alias group for key '{}'", key),
363
+ source_ref: SourceRef::pack_uri(&pack_ref.pack_id),
364
+ pack_ref: pack_ref.clone(),
365
+ suggestions: vec![],
366
+ recoverability_hint: String::new(),
367
+ });
368
+ }
369
+
370
+ fn check_review_coverage(
371
+ input: &PackBuildInput,
372
+ diagnostics: &mut Vec<SemanticDiagnostic>,
373
+ _build_warnings: &mut Vec<SemanticDiagnostic>,
374
+ ) {
375
+ let active_ids: Vec<String> = input
376
+ .concepts
377
+ .iter()
378
+ .filter(|c| matches!(c.status, ConceptStatus::Active))
379
+ .map(|c| c.id.clone())
380
+ .collect();
381
+
382
+ let gaps = review::validate_review_coverage(&active_ids, &input.review_records);
383
+ for gap in gaps {
384
+ diagnostics.push(SemanticDiagnostic {
385
+ code: SemanticDiagnosticCode::UnreviewedConcept,
386
+ severity: DiagnosticSeverity::Error,
387
+ semantic_truth: SemanticTruth::Unknown,
388
+ message: format!("Concept '{}' lacks review approval", gap.subject_id),
389
+ source_ref: SourceRef::pack_uri(&format!(
390
+ "{}/{}/{}",
391
+ input.org_id, input.domain_id, input.pack_version
392
+ )),
393
+ pack_ref: PackRef {
394
+ pack_id: format!(
395
+ "{}/{}/{}",
396
+ input.org_id, input.domain_id, input.pack_version
397
+ ),
398
+ pack_content_hash: String::new(),
399
+ path_or_uri: String::new(),
400
+ priority: 0,
401
+ },
402
+ suggestions: vec![],
403
+ recoverability_hint: "Add review decision for this concept".to_string(),
404
+ });
405
+ }
406
+
407
+ // Validate definition hashes match
408
+ for c in &input.concepts {
409
+ if c.definition.definition_hash.is_empty() {
410
+ continue;
411
+ }
412
+ let hash_result = review::validate_definition_hashes(
413
+ &c.id,
414
+ &c.definition.definition_hash,
415
+ &input.review_records,
416
+ );
417
+ if let DefinitionHashResult::Mismatch {
418
+ reviewed_hash,
419
+ current_hash,
420
+ } = hash_result
421
+ {
422
+ diagnostics.push(SemanticDiagnostic {
423
+ code: SemanticDiagnosticCode::UnreviewedConcept,
424
+ severity: DiagnosticSeverity::Error,
425
+ semantic_truth: SemanticTruth::Unknown,
426
+ message: format!(
427
+ "Definition hash mismatch for '{}': reviewed='{}', current='{}'",
428
+ c.id, reviewed_hash, current_hash
429
+ ),
430
+ source_ref: SourceRef::pack_uri(&format!(
431
+ "{}/{}/{}",
432
+ input.org_id, input.domain_id, input.pack_version
433
+ )),
434
+ pack_ref: PackRef {
435
+ pack_id: format!(
436
+ "{}/{}/{}",
437
+ input.org_id, input.domain_id, input.pack_version
438
+ ),
439
+ pack_content_hash: String::new(),
440
+ path_or_uri: String::new(),
441
+ priority: 0,
442
+ },
443
+ suggestions: vec![],
444
+ recoverability_hint: "Re-review or record minor_amendment_no_semantic_change"
445
+ .to_string(),
446
+ });
447
+ }
448
+ }
449
+ }
450
+
451
+ pub(crate) fn version_increased(old: &str, new: &str) -> Option<bool> {
452
+ let parse = |s: &str| -> Option<Vec<u32>> {
453
+ s.split('.')
454
+ .map(|p| p.parse::<u32>().ok())
455
+ .collect::<Option<Vec<u32>>>()
456
+ };
457
+ let old_parts = parse(old)?;
458
+ let new_parts = parse(new)?;
459
+ for i in 0..std::cmp::max(old_parts.len(), new_parts.len()) {
460
+ let o = old_parts.get(i).copied().unwrap_or(0);
461
+ let n = new_parts.get(i).copied().unwrap_or(0);
462
+ if n > o {
463
+ return Some(true);
464
+ }
465
+ if n < o {
466
+ return Some(false);
467
+ }
468
+ }
469
+ Some(false)
470
+ }
@@ -0,0 +1,184 @@
1
+ use sha2::{Digest, Sha256};
2
+
3
+ use super::schema::{AliasStatus, SemanticPack, SourceRef};
4
+
5
+ /// Canonical JSON: UTF-8, sorted keys, no whitespace, RFC3339 UTC timestamps.
6
+ /// Arrays follow the explicit ordering table (§6.1.1).
7
+ pub fn canonical_json(value: &serde_json::Value) -> String {
8
+ canonicalize_value(value).to_string()
9
+ }
10
+
11
+ fn canonicalize_value(v: &serde_json::Value) -> serde_json::Value {
12
+ match v {
13
+ serde_json::Value::Object(map) => {
14
+ let mut keys: Vec<&String> = map.keys().collect();
15
+ keys.sort();
16
+ let ordered: serde_json::Map<String, serde_json::Value> = keys
17
+ .into_iter()
18
+ .map(|k| (k.clone(), canonicalize_value(&map[k])))
19
+ .collect();
20
+ serde_json::Value::Object(ordered)
21
+ }
22
+ serde_json::Value::Array(arr) => {
23
+ serde_json::Value::Array(arr.iter().map(canonicalize_value).collect())
24
+ }
25
+ other => other.clone(),
26
+ }
27
+ }
28
+
29
+ /// Compute sha256 of canonical JSON bytes.
30
+ pub fn compute_sha256(data: &[u8]) -> String {
31
+ let mut hasher = Sha256::new();
32
+ hasher.update(data);
33
+ let result = hasher.finalize();
34
+ format!("sha256:{:x}", result)
35
+ }
36
+
37
+ /// Compute sha256 of canonical JSON string.
38
+ pub fn hash_canonical_json(value: &serde_json::Value) -> String {
39
+ let canonical = canonical_json(value);
40
+ compute_sha256(canonical.as_bytes())
41
+ }
42
+
43
+ /// Sort a pack's vectors for deterministic serialization (§6.1.1).
44
+ pub fn sort_pack_for_canonicalization(pack: &mut SemanticPack) {
45
+ pack.concepts.sort_by(|a, b| a.id.cmp(&b.id));
46
+ pack.relations
47
+ .sort_by(|a, b| a.id.cmp(&b.id).then(a.predicate.cmp(&b.predicate)));
48
+ pack.metrics.sort_by(|a, b| a.id.cmp(&b.id));
49
+ pack.dimensions.sort_by(|a, b| a.id.cmp(&b.id));
50
+ pack.units
51
+ .sort_by(|a, b| a.id.cmp(&b.id).then(a.symbol.cmp(&b.symbol)));
52
+ pack.aliases.sort_by(|a, b| {
53
+ a.normalized_alias
54
+ .cmp(&b.normalized_alias)
55
+ .then(a.target_concept_id.cmp(&b.target_concept_id))
56
+ .then(alias_status_order(&a.status).cmp(&alias_status_order(&b.status)))
57
+ });
58
+ pack.mapping_rules.sort_by(|a, b| a.id.cmp(&b.id));
59
+
60
+ for concept in &mut pack.concepts {
61
+ sort_string_vec(&mut concept.examples);
62
+ sort_string_vec(&mut concept.counterexamples);
63
+ sort_string_vec(&mut concept.allowed_predicates);
64
+ sort_string_vec(&mut concept.valid_contexts);
65
+ sort_source_refs(&mut concept.source_refs);
66
+ }
67
+ for relation in &mut pack.relations {
68
+ sort_source_refs(&mut relation.source_refs);
69
+ }
70
+ for metric in &mut pack.metrics {
71
+ sort_source_refs(&mut metric.source_refs);
72
+ }
73
+ for dim in &mut pack.dimensions {
74
+ sort_source_refs(&mut dim.source_refs);
75
+ }
76
+ for unit in &mut pack.units {
77
+ sort_source_refs(&mut unit.source_refs);
78
+ }
79
+ }
80
+
81
+ /// Sort diagnostics for deterministic output.
82
+ pub fn sort_diagnostics(diags: &mut [super::diagnostics::SemanticDiagnostic]) {
83
+ diags.sort_by(|a, b| {
84
+ a.source_ref
85
+ .uri
86
+ .cmp(&b.source_ref.uri)
87
+ .then(a.source_ref.start_byte.cmp(&b.source_ref.start_byte))
88
+ .then(a.code.as_str().cmp(b.code.as_str()))
89
+ .then(a.message.cmp(&b.message))
90
+ });
91
+ for d in diags.iter_mut() {
92
+ d.suggestions
93
+ .sort_by(|a, b| b.rank.cmp(&a.rank).then(a.label.cmp(&b.label)));
94
+ }
95
+ }
96
+
97
+ /// Compute pack content hash excluding signature fields (§6.2).
98
+ pub fn compute_pack_content_hash(pack: &SemanticPack) -> String {
99
+ let mut pack_for_hash = pack.clone();
100
+
101
+ // Clear non-semantic / build-variant and signature metadata fields for hash computation
102
+ pack_for_hash.created_at = String::new();
103
+ pack_for_hash.review_manifest_hash = String::new();
104
+ pack_for_hash.trust.signed_by = None;
105
+ pack_for_hash.trust.signature_alg = None;
106
+ pack_for_hash.trust.signature = None;
107
+ pack_for_hash.trust.signature_state = super::schema::SignatureState::Unsigned;
108
+
109
+ sort_pack_for_canonicalization(&mut pack_for_hash);
110
+
111
+ let json = serde_json::to_value(&pack_for_hash)
112
+ .expect("failed to serialize pack for hash computation");
113
+ hash_canonical_json(&json)
114
+ }
115
+
116
+ /// Compute meaning fingerprint from definition records.
117
+ pub fn compute_meaning_fingerprint(pack: &SemanticPack) -> String {
118
+ let mut records: Vec<serde_json::Value> = Vec::new();
119
+
120
+ for c in &pack.concepts {
121
+ records.push(serde_json::json!({
122
+ "subject_type": "concept",
123
+ "subject_id": c.id,
124
+ "definition_hash": c.definition.definition_hash,
125
+ "status": serde_json::to_value(c.status).unwrap_or_default(),
126
+ "decision_ref": c.definition.decision_ref,
127
+ }));
128
+ }
129
+ records.sort_by(|a, b| {
130
+ let at = a.get("subject_type").and_then(|v| v.as_str()).unwrap_or("");
131
+ let bt = b.get("subject_type").and_then(|v| v.as_str()).unwrap_or("");
132
+ at.cmp(bt).then(
133
+ a.get("subject_id")
134
+ .and_then(|v| v.as_str())
135
+ .unwrap_or("")
136
+ .cmp(b.get("subject_id").and_then(|v| v.as_str()).unwrap_or("")),
137
+ )
138
+ });
139
+
140
+ hash_canonical_json(&serde_json::Value::Array(records))
141
+ }
142
+
143
+ /// Compute definition hash for a concept from its text, examples, counterexamples, and status.
144
+ pub fn compute_definition_hash(
145
+ text: &str,
146
+ examples: &[String],
147
+ counterexamples: &[String],
148
+ status: &str,
149
+ ) -> String {
150
+ let mut norm_examples: Vec<String> = examples.to_vec();
151
+ sort_string_vec(&mut norm_examples);
152
+ let mut norm_counter: Vec<String> = counterexamples.to_vec();
153
+ sort_string_vec(&mut norm_counter);
154
+
155
+ let input = serde_json::json!({
156
+ "text": text,
157
+ "examples": norm_examples,
158
+ "counterexamples": norm_counter,
159
+ "status": status,
160
+ });
161
+ hash_canonical_json(&input)
162
+ }
163
+
164
+ fn alias_status_order(s: &AliasStatus) -> u8 {
165
+ match s {
166
+ AliasStatus::Approved => 0,
167
+ AliasStatus::Deprecated => 1,
168
+ AliasStatus::Ambiguous => 2,
169
+ AliasStatus::Blocked => 3,
170
+ }
171
+ }
172
+
173
+ fn sort_string_vec(v: &mut [String]) {
174
+ v.sort();
175
+ }
176
+
177
+ fn sort_source_refs(v: &mut [SourceRef]) {
178
+ v.sort_by(|a, b| {
179
+ a.uri
180
+ .cmp(&b.uri)
181
+ .then(a.start_byte.cmp(&b.start_byte))
182
+ .then(a.end_byte.cmp(&b.end_byte))
183
+ });
184
+ }