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,214 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ use super::schema::{PackRef, PackSetRef, SourceRef, Suggestion};
4
+
5
+ // ---------------------------------------------------------------------------
6
+ // 4.5 SemanticTruth and DiagnosticSeverity
7
+ // ---------------------------------------------------------------------------
8
+ #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
9
+ #[serde(rename_all = "snake_case")]
10
+ pub enum SemanticTruth {
11
+ Valid,
12
+ Invalid,
13
+ Unknown,
14
+ }
15
+
16
+ #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
17
+ #[serde(rename_all = "snake_case")]
18
+ pub enum DiagnosticSeverity {
19
+ Error,
20
+ Warning,
21
+ Info,
22
+ Hint,
23
+ }
24
+
25
+ // ---------------------------------------------------------------------------
26
+ // 4.6 SemanticDiagnosticCode
27
+ // ---------------------------------------------------------------------------
28
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
29
+ #[serde(rename_all = "snake_case")]
30
+ pub enum SemanticDiagnosticCode {
31
+ UnknownConcept,
32
+ DeprecatedConcept,
33
+ AmbiguousConcept,
34
+ AmbiguousAlias,
35
+ AliasConflict,
36
+ RejectedConcept,
37
+ ProposedConcept,
38
+ InvalidRelation,
39
+ InvalidPredicate,
40
+ UnknownMetric,
41
+ UnknownDimension,
42
+ UnknownUnit,
43
+ UnitMismatch,
44
+ DimensionMismatch,
45
+ MissingDefinition,
46
+ MissingOwner,
47
+ DuplicateCanonicalName,
48
+ DuplicateConceptId,
49
+ UnreviewedConcept,
50
+ PackUnavailable,
51
+ PackSchemaMismatch,
52
+ PackVersionMismatch,
53
+ PackHashMismatch,
54
+ PackUnsigned,
55
+ PackSignatureInvalid,
56
+ PackSetConflict,
57
+ MappingRequired,
58
+ MeaningVersionNotBumped,
59
+ MeaningVersionBaselineMissing,
60
+ AmbiguousAliasGroup,
61
+ }
62
+
63
+ impl SemanticDiagnosticCode {
64
+ pub fn as_str(&self) -> &str {
65
+ match self {
66
+ Self::UnknownConcept => "unknown_concept",
67
+ Self::DeprecatedConcept => "deprecated_concept",
68
+ Self::AmbiguousConcept => "ambiguous_concept",
69
+ Self::AmbiguousAlias => "ambiguous_alias",
70
+ Self::AliasConflict => "alias_conflict",
71
+ Self::RejectedConcept => "rejected_concept",
72
+ Self::ProposedConcept => "proposed_concept",
73
+ Self::InvalidRelation => "invalid_relation",
74
+ Self::InvalidPredicate => "invalid_predicate",
75
+ Self::UnknownMetric => "unknown_metric",
76
+ Self::UnknownDimension => "unknown_dimension",
77
+ Self::UnknownUnit => "unknown_unit",
78
+ Self::UnitMismatch => "unit_mismatch",
79
+ Self::DimensionMismatch => "dimension_mismatch",
80
+ Self::MissingDefinition => "missing_definition",
81
+ Self::MissingOwner => "missing_owner",
82
+ Self::DuplicateCanonicalName => "duplicate_canonical_name",
83
+ Self::DuplicateConceptId => "duplicate_concept_id",
84
+ Self::UnreviewedConcept => "unreviewed_concept",
85
+ Self::PackUnavailable => "pack_unavailable",
86
+ Self::PackSchemaMismatch => "pack_schema_mismatch",
87
+ Self::PackVersionMismatch => "pack_version_mismatch",
88
+ Self::PackHashMismatch => "pack_hash_mismatch",
89
+ Self::PackUnsigned => "pack_unsigned",
90
+ Self::PackSignatureInvalid => "pack_signature_invalid",
91
+ Self::PackSetConflict => "pack_set_conflict",
92
+ Self::MappingRequired => "mapping_required",
93
+ Self::MeaningVersionNotBumped => "meaning_version_not_bumped",
94
+ Self::MeaningVersionBaselineMissing => "meaning_version_baseline_missing",
95
+ Self::AmbiguousAliasGroup => "ambiguous_alias_group",
96
+ }
97
+ }
98
+ }
99
+
100
+ // ---------------------------------------------------------------------------
101
+ // 4.6 SemanticDiagnostic
102
+ // ---------------------------------------------------------------------------
103
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
104
+ pub struct SemanticDiagnostic {
105
+ pub code: SemanticDiagnosticCode,
106
+ pub severity: DiagnosticSeverity,
107
+ pub semantic_truth: SemanticTruth,
108
+ pub message: String,
109
+ pub source_ref: SourceRef,
110
+ pub pack_ref: PackRef,
111
+ #[serde(default)]
112
+ pub suggestions: Vec<Suggestion>,
113
+ pub recoverability_hint: String,
114
+ }
115
+
116
+ // ---------------------------------------------------------------------------
117
+ // 4.7 SemanticValidationResult
118
+ // ---------------------------------------------------------------------------
119
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
120
+ pub struct SemanticValidationResult {
121
+ pub status: SemanticValidationStatus,
122
+ pub diagnostics: Vec<SemanticDiagnostic>,
123
+ pub pack_set_ref: PackSetRef,
124
+ pub input_hash: String,
125
+ pub validation_mode: ValidationMode,
126
+ pub expected_hashes: Vec<ExpectedHashCheck>,
127
+ pub unsigned_fixture_bypass_used: bool,
128
+ pub first_approved_version_bypass_used: bool,
129
+ #[serde(skip_serializing_if = "Option::is_none")]
130
+ pub evidence_ref: Option<String>,
131
+ }
132
+
133
+ #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
134
+ #[serde(rename_all = "snake_case")]
135
+ pub enum SemanticValidationStatus {
136
+ Passed,
137
+ Failed,
138
+ Unknown,
139
+ Blocked,
140
+ }
141
+
142
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
143
+ pub struct ExpectedHashCheck {
144
+ pub path: String,
145
+ pub expected_hash: String,
146
+ #[serde(skip_serializing_if = "Option::is_none")]
147
+ pub actual_hash: Option<String>,
148
+ pub matched: bool,
149
+ }
150
+
151
+ // ---------------------------------------------------------------------------
152
+ // ValidationMode / policies (11.2)
153
+ // ---------------------------------------------------------------------------
154
+ #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
155
+ #[serde(rename_all = "snake_case")]
156
+ pub enum ValidationMode {
157
+ Off,
158
+ Warn,
159
+ Strict,
160
+ }
161
+
162
+ #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
163
+ #[serde(rename_all = "snake_case")]
164
+ pub enum UnknownConceptPolicy {
165
+ Ignore,
166
+ Warning,
167
+ Error,
168
+ }
169
+
170
+ #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
171
+ #[serde(rename_all = "snake_case")]
172
+ pub enum DeprecatedPolicy {
173
+ Allow,
174
+ Warn,
175
+ ErrorInStrict,
176
+ ErrorAlways,
177
+ }
178
+
179
+ // ---------------------------------------------------------------------------
180
+ // ValidationOptions (11.2)
181
+ // ---------------------------------------------------------------------------
182
+ #[derive(Debug, Clone, Serialize, Deserialize)]
183
+ #[serde(default)]
184
+ pub struct ValidationOptions {
185
+ pub mode: ValidationMode,
186
+ pub unknown_concept_policy: UnknownConceptPolicy,
187
+ pub deprecated_policy: DeprecatedPolicy,
188
+ pub require_signed_pack: bool,
189
+ pub allow_unsigned_test_fixtures: bool,
190
+ }
191
+
192
+ impl Default for ValidationOptions {
193
+ fn default() -> Self {
194
+ Self {
195
+ mode: ValidationMode::Warn,
196
+ unknown_concept_policy: UnknownConceptPolicy::Warning,
197
+ deprecated_policy: DeprecatedPolicy::Warn,
198
+ require_signed_pack: false,
199
+ allow_unsigned_test_fixtures: false,
200
+ }
201
+ }
202
+ }
203
+
204
+ impl ValidationOptions {
205
+ pub fn strict() -> Self {
206
+ Self {
207
+ mode: ValidationMode::Strict,
208
+ unknown_concept_policy: UnknownConceptPolicy::Error,
209
+ deprecated_policy: DeprecatedPolicy::ErrorInStrict,
210
+ require_signed_pack: true,
211
+ allow_unsigned_test_fixtures: false,
212
+ }
213
+ }
214
+ }
@@ -0,0 +1,216 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ use super::schema::{ConceptDef, SemanticPack};
4
+
5
+ /// Diff classification (12.4)
6
+ #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
7
+ #[serde(rename_all = "snake_case")]
8
+ pub enum DiffClassification {
9
+ Additive,
10
+ DefinitionalChange,
11
+ Deprecating,
12
+ Breaking,
13
+ GovernanceCritical,
14
+ SignatureOnly,
15
+ }
16
+
17
+ #[derive(Debug, Clone, Serialize, Deserialize)]
18
+ pub struct DiffEntry {
19
+ pub classification: DiffClassification,
20
+ pub subject_type: String,
21
+ pub subject_id: String,
22
+ pub detail: String,
23
+ }
24
+
25
+ #[derive(Debug, Clone, Serialize, Deserialize)]
26
+ pub struct PackDiff {
27
+ pub old_pack_id: String,
28
+ pub new_pack_id: String,
29
+ pub entries: Vec<DiffEntry>,
30
+ pub summary: DiffSummary,
31
+ }
32
+
33
+ #[derive(Debug, Clone, Serialize, Deserialize)]
34
+ pub struct DiffSummary {
35
+ pub additive_count: usize,
36
+ pub definitional_change_count: usize,
37
+ pub deprecating_count: usize,
38
+ pub breaking_count: usize,
39
+ pub governance_critical_count: usize,
40
+ pub signature_only_count: usize,
41
+ }
42
+
43
+ /// Compute the diff between two semantic packs.
44
+ pub fn diff_packs(old: &SemanticPack, new: &SemanticPack) -> PackDiff {
45
+ let mut entries = Vec::new();
46
+
47
+ let old_concepts: std::collections::HashMap<&str, &ConceptDef> =
48
+ old.concepts.iter().map(|c| (c.id.as_str(), c)).collect();
49
+ let new_concepts: std::collections::HashMap<&str, &ConceptDef> =
50
+ new.concepts.iter().map(|c| (c.id.as_str(), c)).collect();
51
+
52
+ // Added concepts
53
+ for (id, concept) in &new_concepts {
54
+ if !old_concepts.contains_key(id) {
55
+ entries.push(DiffEntry {
56
+ classification: DiffClassification::Additive,
57
+ subject_type: "concept".to_string(),
58
+ subject_id: id.to_string(),
59
+ detail: format!(
60
+ "Added concept '{}' ({})",
61
+ concept.canonical_name,
62
+ concept.status.as_str()
63
+ ),
64
+ });
65
+ }
66
+ }
67
+
68
+ // Removed concepts (breaking if active)
69
+ for (id, concept) in &old_concepts {
70
+ if !new_concepts.contains_key(id) {
71
+ let is_breaking = matches!(concept.status, super::schema::ConceptStatus::Active);
72
+ entries.push(DiffEntry {
73
+ classification: if is_breaking {
74
+ DiffClassification::Breaking
75
+ } else {
76
+ DiffClassification::Deprecating
77
+ },
78
+ subject_type: "concept".to_string(),
79
+ subject_id: id.to_string(),
80
+ detail: format!(
81
+ "Removed concept '{}' (was {})",
82
+ concept.canonical_name,
83
+ concept.status.as_str()
84
+ ),
85
+ });
86
+ }
87
+ }
88
+
89
+ // Changed concepts
90
+ for (id, new_concept) in &new_concepts {
91
+ if let Some(old_concept) = old_concepts.get(id) {
92
+ // Definition hash change
93
+ if old_concept.definition.definition_hash != new_concept.definition.definition_hash {
94
+ let is_breaking = old.meaning_fingerprint != new.meaning_fingerprint
95
+ && !version_increased(&old.meaning_version, &new.meaning_version);
96
+ entries.push(DiffEntry {
97
+ classification: if is_breaking {
98
+ DiffClassification::Breaking
99
+ } else {
100
+ DiffClassification::DefinitionalChange
101
+ },
102
+ subject_type: "concept".to_string(),
103
+ subject_id: id.to_string(),
104
+ detail: format!(
105
+ "Definition changed for '{}' (hash {} -> {})",
106
+ id,
107
+ old_concept.definition.definition_hash,
108
+ new_concept.definition.definition_hash
109
+ ),
110
+ });
111
+ }
112
+
113
+ // Status transition
114
+ if old_concept.status != new_concept.status {
115
+ let classification = match new_concept.status {
116
+ super::schema::ConceptStatus::Deprecated => DiffClassification::Deprecating,
117
+ super::schema::ConceptStatus::Rejected => DiffClassification::Breaking,
118
+ _ => DiffClassification::GovernanceCritical,
119
+ };
120
+ entries.push(DiffEntry {
121
+ classification,
122
+ subject_type: "concept".to_string(),
123
+ subject_id: id.to_string(),
124
+ detail: format!(
125
+ "Status changed: {} -> {}",
126
+ old_concept.status.as_str(),
127
+ new_concept.status.as_str()
128
+ ),
129
+ });
130
+ }
131
+ }
132
+ }
133
+
134
+ // Meaning fingerprint change without version bump
135
+ if old.meaning_fingerprint != new.meaning_fingerprint
136
+ && !version_increased(&old.meaning_version, &new.meaning_version)
137
+ {
138
+ entries.push(DiffEntry {
139
+ classification: DiffClassification::Breaking,
140
+ subject_type: "pack".to_string(),
141
+ subject_id: "meaning_fingerprint".to_string(),
142
+ detail: format!(
143
+ "meaning_fingerprint changed without meaning_version increase ({} vs {})",
144
+ old.meaning_version, new.meaning_version
145
+ ),
146
+ });
147
+ }
148
+
149
+ // Sort entries by classification priority then subject_id
150
+ entries.sort_by(|a, b| {
151
+ classification_order(a.classification)
152
+ .cmp(&classification_order(b.classification))
153
+ .then(a.subject_id.cmp(&b.subject_id))
154
+ });
155
+
156
+ let summary = DiffSummary {
157
+ additive_count: entries
158
+ .iter()
159
+ .filter(|e| e.classification == DiffClassification::Additive)
160
+ .count(),
161
+ definitional_change_count: entries
162
+ .iter()
163
+ .filter(|e| e.classification == DiffClassification::DefinitionalChange)
164
+ .count(),
165
+ deprecating_count: entries
166
+ .iter()
167
+ .filter(|e| e.classification == DiffClassification::Deprecating)
168
+ .count(),
169
+ breaking_count: entries
170
+ .iter()
171
+ .filter(|e| e.classification == DiffClassification::Breaking)
172
+ .count(),
173
+ governance_critical_count: entries
174
+ .iter()
175
+ .filter(|e| e.classification == DiffClassification::GovernanceCritical)
176
+ .count(),
177
+ signature_only_count: entries
178
+ .iter()
179
+ .filter(|e| e.classification == DiffClassification::SignatureOnly)
180
+ .count(),
181
+ };
182
+
183
+ PackDiff {
184
+ old_pack_id: old.pack_id.clone(),
185
+ new_pack_id: new.pack_id.clone(),
186
+ entries,
187
+ summary,
188
+ }
189
+ }
190
+
191
+ fn classification_order(c: DiffClassification) -> u8 {
192
+ match c {
193
+ DiffClassification::Breaking => 0,
194
+ DiffClassification::GovernanceCritical => 1,
195
+ DiffClassification::DefinitionalChange => 2,
196
+ DiffClassification::Deprecating => 3,
197
+ DiffClassification::Additive => 4,
198
+ DiffClassification::SignatureOnly => 5,
199
+ }
200
+ }
201
+
202
+ fn version_increased(old: &str, new: &str) -> bool {
203
+ super::builder::version_increased(old, new).unwrap_or(false)
204
+ }
205
+
206
+ impl super::schema::ConceptStatus {
207
+ fn as_str(&self) -> &'static str {
208
+ match self {
209
+ super::schema::ConceptStatus::Active => "active",
210
+ super::schema::ConceptStatus::Proposed => "proposed",
211
+ super::schema::ConceptStatus::Deprecated => "deprecated",
212
+ super::schema::ConceptStatus::Rejected => "rejected",
213
+ super::schema::ConceptStatus::ExternalOnly => "external_only",
214
+ }
215
+ }
216
+ }
@@ -0,0 +1,31 @@
1
+ pub mod builder;
2
+ pub mod canonical_json;
3
+ pub mod diagnostics;
4
+ pub mod diff;
5
+ pub mod pack_set;
6
+ pub mod resolver;
7
+ pub mod review;
8
+ pub mod schema;
9
+ #[cfg(feature = "signing")]
10
+ pub mod signing;
11
+ pub mod validator;
12
+
13
+ // Re-export main public types (§11.1)
14
+ pub use builder::{build_semantic_pack, PackBuildInput, PackBuildOutput};
15
+ pub use canonical_json::{canonical_json, compute_pack_content_hash, compute_sha256};
16
+ pub use diagnostics::{
17
+ DeprecatedPolicy, DiagnosticSeverity, SemanticDiagnostic, SemanticDiagnosticCode,
18
+ SemanticTruth, SemanticValidationResult, SemanticValidationStatus, UnknownConceptPolicy,
19
+ ValidationMode, ValidationOptions,
20
+ };
21
+ pub use diff::{diff_packs, PackDiff};
22
+ pub use pack_set::{merge_packs, ConflictType, PackSet};
23
+ pub use resolver::{normalize_lookup_key, resolve_concept, ResolveRequest, ResolveResult};
24
+ pub use schema::{
25
+ AliasDef, AliasStatus, ApprovalState, CompatibilityInfo, ConceptDef, ConceptDefinition,
26
+ ConceptKind, ConceptStatus, GeneratorInfo, PackRef, PackSetRef, PackTrust, ReviewDecision,
27
+ ReviewRecord, SemanticPack, SignatureState, SourceRef,
28
+ };
29
+ #[cfg(feature = "signing")]
30
+ pub use signing::{derive_signer_id, sign_pack, verify_pack_signature, SignOutput};
31
+ pub use validator::{validate_graph_with_pack, validate_semantic_pack, validate_term};
@@ -0,0 +1,240 @@
1
+ use serde::{Deserialize, Serialize};
2
+
3
+ use super::schema::{PackRef, SemanticPack};
4
+
5
+ // ---------------------------------------------------------------------------
6
+ // PackSet (10.1)
7
+ // ---------------------------------------------------------------------------
8
+ #[derive(Debug, Clone, Serialize, Deserialize)]
9
+ pub struct PackSet {
10
+ pub packs: Vec<PackRef>,
11
+ pub precedence: Vec<String>,
12
+ pub merged_pack_hash: String,
13
+ pub conflicts: Vec<PackConflict>,
14
+ }
15
+
16
+ // ---------------------------------------------------------------------------
17
+ // PackConflict (10.4)
18
+ // ---------------------------------------------------------------------------
19
+ #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
20
+ pub struct PackConflict {
21
+ pub conflict_type: ConflictType,
22
+ pub key: String,
23
+ pub pack_a_id: String,
24
+ pub pack_b_id: String,
25
+ pub detail: String,
26
+ }
27
+
28
+ #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
29
+ #[serde(rename_all = "snake_case")]
30
+ pub enum ConflictType {
31
+ SameConceptIdDifferentHash,
32
+ SameCanonicalNameDifferentId,
33
+ SameAliasKeyDifferentTarget,
34
+ IncompatibleRelationCardinality,
35
+ SameUnitSymbolDifferentDimension,
36
+ InvalidPriorityOrder,
37
+ }
38
+
39
+ // ---------------------------------------------------------------------------
40
+ // Merge packs into a PackSet
41
+ // ---------------------------------------------------------------------------
42
+ pub fn merge_packs(
43
+ packs: &[SemanticPack],
44
+ priority_order: &[i32],
45
+ ) -> Result<PackSet, Vec<PackConflict>> {
46
+ if !packs.is_empty() && priority_order.len() != packs.len() {
47
+ return Err(vec![PackConflict {
48
+ conflict_type: ConflictType::InvalidPriorityOrder,
49
+ key: String::new(),
50
+ pack_a_id: String::new(),
51
+ pack_b_id: String::new(),
52
+ detail: format!(
53
+ "priority_order length ({}) must match packs length ({})",
54
+ priority_order.len(),
55
+ packs.len()
56
+ ),
57
+ }]);
58
+ }
59
+ if packs.is_empty() {
60
+ return Ok(PackSet {
61
+ packs: vec![],
62
+ precedence: vec![],
63
+ merged_pack_hash: super::canonical_json::compute_sha256(b"empty_pack_set"),
64
+ conflicts: vec![],
65
+ });
66
+ }
67
+
68
+ // Build PackRefs sorted by canonical merge order (§10.2)
69
+ let mut refs: Vec<(PackRef, usize)> = Vec::new();
70
+ for (i, pack) in packs.iter().enumerate() {
71
+ let content_hash = super::canonical_json::compute_pack_content_hash(pack);
72
+ let priority = priority_order.get(i).copied().unwrap_or(0);
73
+ refs.push((
74
+ PackRef {
75
+ pack_id: pack.pack_id.clone(),
76
+ pack_content_hash: content_hash,
77
+ path_or_uri: format!("pack://{}", pack.pack_id),
78
+ priority,
79
+ },
80
+ i,
81
+ ));
82
+ }
83
+
84
+ // Sort: explicit priority ascending, pack_id ascending, hash ascending
85
+ refs.sort_by(|a, b| {
86
+ a.0.priority
87
+ .cmp(&b.0.priority)
88
+ .then(a.0.pack_id.cmp(&b.0.pack_id))
89
+ .then(a.0.pack_content_hash.cmp(&b.0.pack_content_hash))
90
+ });
91
+
92
+ // Detect conflicts (§10.4)
93
+ let conflicts = detect_conflicts(packs, &refs);
94
+
95
+ if !conflicts.is_empty() {
96
+ return Err(conflicts);
97
+ }
98
+
99
+ let pack_refs: Vec<PackRef> = refs.into_iter().map(|(r, _)| r).collect();
100
+ let merged_hash = compute_merged_hash(&pack_refs).map_err(|e| {
101
+ vec![PackConflict {
102
+ conflict_type: ConflictType::InvalidPriorityOrder,
103
+ key: format!("hash computation failed: {}", e),
104
+ pack_a_id: String::new(),
105
+ pack_b_id: String::new(),
106
+ detail: e,
107
+ }]
108
+ })?;
109
+ let precedence: Vec<String> = pack_refs.iter().map(|r| r.pack_id.clone()).collect();
110
+
111
+ Ok(PackSet {
112
+ packs: pack_refs.clone(),
113
+ precedence,
114
+ merged_pack_hash: merged_hash,
115
+ conflicts: vec![],
116
+ })
117
+ }
118
+
119
+ fn detect_conflicts(packs: &[SemanticPack], refs: &[(PackRef, usize)]) -> Vec<PackConflict> {
120
+ let mut conflicts = Vec::new();
121
+
122
+ // Same concept ID, different definition hash
123
+ for i in 0..refs.len() {
124
+ for j in (i + 1)..refs.len() {
125
+ let pack_a = &packs[refs[i].1];
126
+ let pack_b = &packs[refs[j].1];
127
+
128
+ // Concept conflicts
129
+ for ca in &pack_a.concepts {
130
+ for cb in &pack_b.concepts {
131
+ if ca.id == cb.id
132
+ && ca.definition.definition_hash != cb.definition.definition_hash
133
+ {
134
+ conflicts.push(PackConflict {
135
+ conflict_type: ConflictType::SameConceptIdDifferentHash,
136
+ key: ca.id.clone(),
137
+ pack_a_id: pack_a.pack_id.clone(),
138
+ pack_b_id: pack_b.pack_id.clone(),
139
+ detail: format!(
140
+ "Concept '{}' has different definition hashes: {} vs {}",
141
+ ca.id, ca.definition.definition_hash, cb.definition.definition_hash
142
+ ),
143
+ });
144
+ }
145
+ }
146
+ }
147
+
148
+ // Canonical name conflicts
149
+ use super::resolver::normalize_lookup_key;
150
+ let mut names_a: std::collections::HashMap<String, &str> =
151
+ std::collections::HashMap::new();
152
+ for c in &pack_a.concepts {
153
+ let norm = normalize_lookup_key(&c.canonical_name);
154
+ names_a.insert(norm, &c.id);
155
+ }
156
+ for c in &pack_b.concepts {
157
+ let norm = normalize_lookup_key(&c.canonical_name);
158
+ if let Some(existing_id) = names_a.get(&norm) {
159
+ if *existing_id != c.id {
160
+ conflicts.push(PackConflict {
161
+ conflict_type: ConflictType::SameCanonicalNameDifferentId,
162
+ key: norm.clone(),
163
+ pack_a_id: pack_a.pack_id.clone(),
164
+ pack_b_id: pack_b.pack_id.clone(),
165
+ detail: format!(
166
+ "Canonical name '{}' maps to '{}' and '{}'",
167
+ norm, existing_id, c.id
168
+ ),
169
+ });
170
+ }
171
+ }
172
+ }
173
+
174
+ // Alias conflicts
175
+ let mut aliases_a: std::collections::HashMap<String, &str> =
176
+ std::collections::HashMap::new();
177
+ for a in &pack_a.aliases {
178
+ aliases_a.insert(a.normalized_alias.clone(), &a.target_concept_id);
179
+ }
180
+ for a in &pack_b.aliases {
181
+ if let Some(existing_target) = aliases_a.get(&a.normalized_alias) {
182
+ if *existing_target != a.target_concept_id {
183
+ conflicts.push(PackConflict {
184
+ conflict_type: ConflictType::SameAliasKeyDifferentTarget,
185
+ key: a.normalized_alias.clone(),
186
+ pack_a_id: pack_a.pack_id.clone(),
187
+ pack_b_id: pack_b.pack_id.clone(),
188
+ detail: format!(
189
+ "Alias '{}' targets '{}' and '{}'",
190
+ a.normalized_alias, existing_target, a.target_concept_id
191
+ ),
192
+ });
193
+ }
194
+ }
195
+ }
196
+
197
+ // Unit symbol conflicts
198
+ let mut units_a: std::collections::HashMap<String, &str> =
199
+ std::collections::HashMap::new();
200
+ for u in &pack_a.units {
201
+ units_a.insert(u.symbol.clone(), &u.dimension_id);
202
+ }
203
+ for u in &pack_b.units {
204
+ if let Some(existing_dim) = units_a.get(&u.symbol) {
205
+ if *existing_dim != u.dimension_id {
206
+ conflicts.push(PackConflict {
207
+ conflict_type: ConflictType::SameUnitSymbolDifferentDimension,
208
+ key: u.symbol.clone(),
209
+ pack_a_id: pack_a.pack_id.clone(),
210
+ pack_b_id: pack_b.pack_id.clone(),
211
+ detail: format!(
212
+ "Unit '{}' has different dimensions: {} vs {}",
213
+ u.symbol, existing_dim, u.dimension_id
214
+ ),
215
+ });
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+
222
+ conflicts
223
+ }
224
+
225
+ fn compute_merged_hash(refs: &[PackRef]) -> Result<String, String> {
226
+ let mut sorted_refs: Vec<serde_json::Value> = refs
227
+ .iter()
228
+ .map(|r| serde_json::to_value(r).map_err(|e| format!("failed to serialize PackRef: {}", e)))
229
+ .collect::<Result<_, _>>()?;
230
+ sorted_refs.sort_by(|a, b| {
231
+ let a_id = a.get("pack_id").and_then(|v| v.as_str()).unwrap_or("");
232
+ let b_id = b.get("pack_id").and_then(|v| v.as_str()).unwrap_or("");
233
+ a_id.cmp(b_id)
234
+ });
235
+ let input = serde_json::json!({
236
+ "pack_refs": sorted_refs,
237
+ "conflict_policy": "error_on_conflict"
238
+ });
239
+ Ok(super::canonical_json::hash_canonical_json(&input))
240
+ }