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,199 @@
1
+ # Reference — DomainForge
2
+
3
+ Purpose: Canonical descriptions of APIs, data models, grammar, CLI commands, configuration and error codes.
4
+
5
+ MECE checklist:
6
+
7
+ - Stable API surface docs and usage examples
8
+ - Grammar and AST specification
9
+ - Error codes with examples and recommended handling
10
+ - CLI reference command list with flags and examples
11
+ - Configuration schema and environment variables
12
+
13
+ ## How to use this section
14
+
15
+ - Start with `grammar-spec.md` to understand supported syntax.
16
+ - Consult `primitives-api.md` to see the in-memory structures created by parsing.
17
+ - Use `cli-commands.md` when working from the terminal or CI.
18
+ - Binding-specific references (`python-api.md`, `typescript-api.md`, `wasm-api.md`) describe constructors, methods, and platform notes.
19
+ - `error-codes.md` provides remediation steps for validation output.
20
+ - `calm-mapping.md` documents integration with FINOS CALM.
21
+ - `protobuf-api.md` documents the Protobuf projection engine API.
22
+ - `configuration.md` centralizes environment variables and registry options.
23
+ - `registry.md` documents workspace namespace mappings (`.sea-registry.toml`).
24
+
25
+ ## File map and highlights
26
+
27
+ ### grammar-spec.md
28
+
29
+ - Pest grammar rules mirrored verbatim from `sea.pest`.
30
+ - Examples for every declaration type (namespace, dimension, unit, entity, resource, flow, instance, role, relation, policy).
31
+ - Edge cases (escaping, numeric formats, regex validation) documented for parser debugging.
32
+
33
+ ### primitives-api.md
34
+
35
+ - Fields and constructors for Entity, Resource, Flow, ResourceInstance, Role, Relation, Policy.
36
+ - Cross-language method parity tables.
37
+ - JSON serialization examples and CALM mapping notes.
38
+
39
+ ### cli-commands.md
40
+
41
+ - Subcommand-by-subcommand reference with flags and exit codes.
42
+ - Scenario-driven examples (batch validation, registry usage, JSON output piping).
43
+ - Pointers to CLI source files for maintainers.
44
+
45
+ ### python-api.md
46
+
47
+ - Installation instructions (pip, maturin, platform wheels).
48
+ - Usage examples for Graph parsing, export/import, policy evaluation.
49
+ - Exception types and how validation errors surface in Python.
50
+
51
+ ### typescript-api.md
52
+
53
+ - npm installation guidance (Node 18+, napi prebuilds).
54
+ - Graph API coverage with examples using Vitest.
55
+ - Notes on CommonJS vs ESM and bundler integration.
56
+
57
+ ### wasm-api.md
58
+
59
+ - Browser and bundler setup (wasm-pack, npm scripts, MIME types).
60
+ - API surface for parsing/exporting in WASM contexts.
61
+ - Performance and memory considerations for large graphs.
62
+
63
+ ### error-codes.md
64
+
65
+ - Exhaustive catalog of validation and parsing errors grouped by category.
66
+ - Examples demonstrating each code and suggested fixes.
67
+ - Binding notes on how errors are propagated.
68
+
69
+ ### calm-mapping.md
70
+
71
+ - Bidirectional mapping tables between SEA primitives and CALM JSON fields.
72
+ - Implementation pointers to export/import modules and round-trip tests.
73
+ - Known limitations and schema alignment notes.
74
+
75
+ ### configuration.md
76
+
77
+ - CLI/environment defaults, registry schema, binding configuration flags.
78
+ - Platform-specific guidance and migration notes across versions.
79
+
80
+ ## Navigational checklist by task
81
+
82
+ - **Model authoring**: read `grammar-spec.md` and `primitives-api.md` first.
83
+ - **Running tools**: rely on `cli-commands.md` and `configuration.md`.
84
+ - **Debugging**: use `error-codes.md` plus `cli-commands.md` (`explain`), optionally cross-check `calm-mapping.md` for projection issues.
85
+ - **Integrations**: choose the binding reference that matches your runtime (Python/TS/WASM) and pair with `calm-mapping.md` or RDF guides in how-tos.
86
+
87
+ ## Maintenance guidance
88
+
89
+ - When updating parser rules, edit `grammar-spec.md` and add examples mirroring new syntax.
90
+ - Any new primitive fields must be reflected in `primitives-api.md` and binding references.
91
+ - New CLI flags require updates to `cli-commands.md` and `configuration.md`.
92
+ - Adding or changing validation errors demands edits to `error-codes.md` and backfill of examples.
93
+ - Projection changes (CALM/RDF/SBVR) should be mirrored in `calm-mapping.md` with notes on compatibility.
94
+
95
+ ## Cross-references
96
+
97
+ - Tutorials and how-tos in `docs/new_docs/tutorials/` and `docs/new_docs/how-tos/` provide guided flows; use this reference section to double-check APIs used there.
98
+ - Explanations in `docs/new_docs/explanations/` describe the rationale behind design choices documented here.
99
+
100
+ ## Glossary
101
+
102
+ - **Namespace**: logical partition for IDs; default is `"default"`.
103
+ - **Dimension/Unit**: measurement system for quantities; see `create-custom-units` how-to for authoring guidance.
104
+ - **Policy**: logical statement evaluated over graph elements; see `policy-evaluation-logic.md` explanation.
105
+ - **CALM**: FINOS Architecture-as-Code JSON format for interoperability.
106
+
107
+ ## Sample workflow tying references together
108
+
109
+ 1. Review `grammar-spec.md` to model a payments domain with roles and relations.
110
+ 2. Use `cli-commands.md` to parse and validate the DSL: `domainforge validate payments.sea --format human`.
111
+ 3. If errors appear, look up codes in `error-codes.md` and adjust accordingly.
112
+ 4. Export to CALM using `cli-commands.md` guidance, then cross-check fields using `calm-mapping.md`.
113
+ 5. Embed the graph into your runtime using `python-api.md` or `typescript-api.md` examples.
114
+ 6. Configure CI with settings from `configuration.md` to keep validation automated.
115
+
116
+ ## Example table of common references
117
+
118
+ | Topic | Primary file | Secondary references |
119
+ | ------------------- | ----------------- | ------------------------------------------------------ |
120
+ | Syntax | grammar-spec.md | explanations/architecture-overview.md |
121
+ | API structs | primitives-api.md | python-api.md, typescript-api.md |
122
+ | CLI usage | cli-commands.md | how-tos/install-cli.md |
123
+ | Errors | error-codes.md | how-tos/debugging-parser-failures.md |
124
+ | CALM integration | calm-mapping.md | how-tos/export-to-calm.md, how-tos/import-from-calm.md |
125
+ | Protobuf projection | protobuf-api.md | how-tos/export-to-protobuf.md |
126
+ | Configuration | configuration.md | how-tos/run-cross-language-tests.md |
127
+
128
+ ## See also
129
+
130
+ - `docs/new_docs/how-tos/` for task-based guidance.
131
+ - `docs/new_docs/tutorials/` for guided, end-to-end walkthroughs.
132
+ - `docs/new_docs/playbooks/` for operational procedures (releases, migrations).
133
+
134
+ ## Quality bar for reference updates
135
+
136
+ - **Accuracy**: validate examples against current code. Run `cargo test -p domainforge-core --features "cli,python,typescript"` when modifying APIs.
137
+ - **Completeness**: ensure new primitives or flags are reflected across all relevant reference files.
138
+ - **Clarity**: prefer short code snippets with expected outputs; avoid pseudocode.
139
+ - **Traceability**: link to source files and tests that define behavior.
140
+
141
+ ## Review checklist
142
+
143
+ 1. Are grammar changes mirrored in `grammar-spec.md` with examples?
144
+ 2. Are new fields or methods documented in `primitives-api.md` and binding references?
145
+ 3. Do CLI flag additions include exit code expectations?
146
+ 4. Are new error codes documented with example inputs and fixes?
147
+ 5. Do CALM/RDF projection changes mention compatibility considerations?
148
+ 6. Are configuration defaults and environment variables updated?
149
+ 7. Are cross-references updated so tutorials/how-tos remain accurate?
150
+
151
+ ## Updating this directory
152
+
153
+ When adding or editing reference files:
154
+
155
+ - Follow the heading hierarchy (H1 title, H2 sections, H3 subsections).
156
+ - Keep line-wrapped bullet lists for readability.
157
+ - Include “See also” links at the bottom of each file to guide readers to related content.
158
+ - Use Markdown tables where comparisons help (e.g., CLI flags, binding parity).
159
+
160
+ ## Frequently asked questions
161
+
162
+ - **Where do the binding APIs come from?**
163
+ - Python: `domainforge-core/src/python/` via PyO3 classes.
164
+ - TypeScript: `domainforge-core/src/typescript/` via napi-rs.
165
+ - WASM: `domainforge-core/src/wasm/` via wasm-bindgen.
166
+ - **How stable is the CLI?**
167
+ - Semantic versioning applies; minor releases add flags, major releases break.
168
+ - **Can I generate docs automatically?**
169
+ - Use `domainforge --help` and bindings’ docstrings as sources; this reference is hand-curated to stay concise.
170
+
171
+ ## Example contribution workflow
172
+
173
+ ```bash
174
+ # Update grammar-spec after adding a new declaration
175
+ vim docs/new_docs/reference/grammar-spec.md
176
+ just fmt
177
+ just all-tests
178
+ ```
179
+
180
+ - Submit PR with links to relevant tests verifying the change.
181
+ - Keep commit messages descriptive (e.g., "Document new module import syntax").
182
+
183
+ ## Contact and ownership
184
+
185
+ - Primary maintainers: see `CODEOWNERS` and `docs/plans/` for domain leads.
186
+ - File issues with documentation bugs referencing the file path and version.
187
+
188
+ ## Release alignment
189
+
190
+ - Align documentation updates with version bumps recorded in `CHANGELOG.md`.
191
+ - When cutting releases, verify reference links against tagged source to avoid drift.
192
+ - Archive previous versions in branch tags if API changes are significant.
193
+
194
+ ## Metrics for completeness
195
+
196
+ - Each reference file should include: summary, API or schema details, examples with expected outputs, troubleshooting notes, and cross-references.
197
+ - Run link checkers (e.g., `markdown-link-check`) before merging large doc updates.
198
+
199
+ (End of reference overview)
@@ -0,0 +1,427 @@
1
+ # AST & JSON Output Reference
2
+
3
+ This reference documents the Abstract Syntax Tree (AST) structure and JSON output capabilities in DomainForge. It covers the AST schema, how to generate JSON output from SEA DSL source code, and the relationship between the `Ast` and `Graph` structures.
4
+
5
+ ## Overview
6
+
7
+ DomainForge provides multiple ways to work with parsed SEA DSL content as structured data:
8
+
9
+ 1. **AST (Abstract Syntax Tree)**: The direct representation of parsed SEA source code, preserving declaration order and source location information.
10
+ 2. **Graph**: The semantic domain model built from the AST, with entities, resources, flows, and policies organized for validation and querying.
11
+ 3. **JSON Output**: Serialized representations of both structures for interoperability with other tools.
12
+
13
+ ## AST Schema
14
+
15
+ The JSON schema for AST output is defined in `schemas/ast-v3.schema.json`. This schema is **programmatically generated** from the Rust type definitions to ensure accuracy.
16
+
17
+ > [!IMPORTANT]
18
+ > The schema is auto-generated from Rust types using [`schemars`](https://docs.rs/schemars). Do not edit `ast-v3.schema.json` manually—regenerate it instead.
19
+
20
+ ### Schema Location
21
+
22
+ | File | Description |
23
+ | ---------------------------- | -------------------------------------------------------------- |
24
+ | `schemas/ast-v3.schema.json` | Current programmatically-generated schema (recommended) |
25
+ | `schemas/ast-v2.schema.json` | Previous version (deprecated, lacks Resource/Flow annotations) |
26
+ | `schemas/ast-v1.schema.json` | Legacy hand-written schema (deprecated) |
27
+
28
+ ### Top-Level Structure
29
+
30
+ ```json
31
+ {
32
+ "$schema": "http://json-schema.org/draft-07/schema#",
33
+ "title": "Ast",
34
+ "description": "Abstract Syntax Tree for SEA DSL",
35
+ "type": "object",
36
+ "required": ["declarations", "metadata"],
37
+ "properties": {
38
+ "declarations": {
39
+ "type": "array",
40
+ "items": { "$ref": "#/definitions/SpannedAstNode" }
41
+ },
42
+ "metadata": { "$ref": "#/definitions/FileMetadata" }
43
+ }
44
+ }
45
+ ```
46
+
47
+ ### Regenerating the Schema
48
+
49
+ To regenerate the AST JSON schema from the Rust type definitions:
50
+
51
+ ```bash
52
+ cd domainforge-core
53
+ cargo test --lib generate_ast_schema -- --ignored --nocapture
54
+ ```
55
+
56
+ This runs the schema generation test which:
57
+
58
+ 1. Uses `schemars` to derive a JSON Schema from the Rust `Ast` type
59
+ 2. Writes the output to `schemas/ast-v3.schema.json`
60
+
61
+ > [!TIP]
62
+ > Run this command after modifying any AST-related types in `domainforge-core/src/parser/ast.rs` or `domainforge-core/src/policy/expression.rs`.
63
+
64
+ ### Schema Generation Implementation
65
+
66
+ The schema is generated from types defined in `domainforge-core/src/parser/ast_schema.rs`. This module mirrors the AST types with `JsonSchema` derives:
67
+
68
+ ```rust
69
+ use schemars::{schema_for, JsonSchema};
70
+ use serde::{Deserialize, Serialize};
71
+
72
+ #[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
73
+ pub struct Ast {
74
+ pub metadata: FileMetadata,
75
+ pub declarations: Vec<SpannedAstNode>,
76
+ }
77
+
78
+ // Test that generates the schema file
79
+ #[test]
80
+ #[ignore]
81
+ fn generate_ast_schema() {
82
+ let schema = schema_for!(Ast);
83
+ let json = serde_json::to_string_pretty(&schema).unwrap();
84
+ std::fs::write("../schemas/ast-v3.schema.json", &json).unwrap();
85
+ }
86
+ ```
87
+
88
+ ## AST Node Types
89
+
90
+ The schema includes all 15 AST node types:
91
+
92
+ | Node Type | Description | Fields |
93
+ | ----------------- | -------------------------------------- | --------------------------------------------------------------------------- |
94
+ | `Export` | Export wrapper for public declarations | `declaration` |
95
+ | `Entity` | Entity declaration | `name`, `annotations` (optional) |
96
+ | `Resource` | Resource declaration | `name`, `annotations` (optional) |
97
+ | `Flow` | Resource transfer between entities | `resource_name`, `from_entity`, `to_entity`, `annotations` (optional) |
98
+ | `Pattern` | Named regex for string validation | `name`, `regex` |
99
+ | `Role` | Participant category | `name` |
100
+ | `Relation` | Predicate connecting roles | `name`, `subject_role`, `predicate`, `object_role` |
101
+ | `Dimension` | Dimension declaration for units | `name` |
102
+ | `UnitDeclaration` | Custom unit definition | `symbol`, `dimension`, `factor`, `base_unit` |
103
+ | `Policy` | Validation rule or constraint | `name`, `metadata`, `expression` |
104
+ | `Instance` | Entity instance with field values | `name`, `entity_type` |
105
+ | `ConceptChange` | Version migration | `name`, `from_version`, `to_version`, `migration_policy`, `breaking_change` |
106
+ | `Metric` | Observable metric | `name`, `expression`, `metadata` |
107
+ | `MappingDecl` | Format mapping rules | `name`, `target`, `rules` |
108
+ | `ProjectionDecl` | Projection configuration | `name`, `target`, `overrides` |
109
+
110
+ ### Expression Types
111
+
112
+ Policy and metric expressions use a rich expression language:
113
+
114
+ | Expression Type | Description |
115
+ | -------------------------- | --------------------------------------------------- |
116
+ | `Literal` | JSON literal value |
117
+ | `QuantityLiteral` | Decimal value with unit |
118
+ | `TimeLiteral` | ISO 8601 timestamp |
119
+ | `IntervalLiteral` | Time interval (start, end) |
120
+ | `Variable` | Named variable reference |
121
+ | `Binary` | Binary operation (AND, OR, comparisons, arithmetic) |
122
+ | `Unary` | Unary operation (NOT, negate) |
123
+ | `Cast` | Type cast |
124
+ | `Quantifier` | ForAll, Exists, ExistsUnique |
125
+ | `MemberAccess` | Object member access |
126
+ | `Aggregation` | COUNT, SUM, MIN, MAX, AVG |
127
+ | `AggregationComprehension` | Aggregation with comprehension syntax |
128
+ | `GroupBy` | Grouping operation |
129
+
130
+ ## Generating JSON Output
131
+
132
+ ### Via Rust Library
133
+
134
+ The `Graph` struct implements `Serialize` from serde, enabling direct JSON serialization:
135
+
136
+ ```rust
137
+ use domainforge_core::parser::parse_to_graph;
138
+
139
+ fn main() -> Result<(), Box<dyn std::error::Error>> {
140
+ let source = r#"
141
+ Entity "Customer"
142
+ Entity "Vendor"
143
+ Resource "Payment" USD
144
+ Flow "Payment" from "Customer" to "Vendor"
145
+ "#;
146
+
147
+ let graph = parse_to_graph(source)?;
148
+
149
+ // Serialize the full graph to JSON
150
+ let json = serde_json::to_string_pretty(&graph)?;
151
+ println!("{}", json);
152
+
153
+ // OR: Serialize the AST directly (preserves source structure)
154
+ // using the new stable schema types
155
+ let ast_json = domainforge_core::parser::parse_to_ast_json(source)?;
156
+ println!("{}", ast_json);
157
+
158
+ Ok(())
159
+ }
160
+ ```
161
+
162
+ To convert a `Graph` back to an `Ast` structure:
163
+
164
+ ```rust
165
+ use domainforge_core::Graph;
166
+
167
+ let ast = graph.to_ast();
168
+ // The Ast can then be used for code generation or formatting
169
+ ```
170
+
171
+ ### Via WASM (JavaScript/TypeScript)
172
+
173
+ The WASM bindings expose a `toJSON()` method on the `Graph` class:
174
+
175
+ ```typescript
176
+ import init, { Graph } from "domainforge_core";
177
+
178
+ async function parseAndSerialize() {
179
+ await init();
180
+
181
+ const source = `
182
+ Entity "Customer"
183
+ Entity "Vendor"
184
+ Resource "Payment" USD
185
+ Flow "Payment" from "Customer" to "Vendor"
186
+ `;
187
+
188
+ const graph = Graph.parse(source);
189
+ const json = graph.toJSON();
190
+
191
+ console.log(JSON.stringify(json, null, 2));
192
+ }
193
+ ```
194
+
195
+ ### Via CLI
196
+
197
+ The SEA CLI provides multiple commands for JSON output:
198
+
199
+ #### Validate with JSON Output
200
+
201
+ ```bash
202
+ # Validate and output results as JSON
203
+ domainforge validate --format json input.sea
204
+ ```
205
+
206
+ Output structure:
207
+
208
+ ```json
209
+ {
210
+ "error_count": 0,
211
+ "violations": []
212
+ }
213
+ ```
214
+
215
+ #### Project to CALM Format
216
+
217
+ ```bash
218
+ # Export graph to CALM JSON format
219
+ domainforge project --format calm input.sea output.json
220
+ ```
221
+
222
+ #### Export AST as JSON
223
+
224
+ To export the raw Abstract Syntax Tree (useful for tools that need source preservation):
225
+
226
+ ```bash
227
+ domainforge parse --ast --format json input.sea > output.ast.json
228
+ ```
229
+
230
+ This output conforms to `ast-v3.schema.json` and preserves all declarations, comments, and line/column numbers.
231
+
232
+ #### Project to Knowledge Graph
233
+
234
+ ```bash
235
+ # Export to RDF/Turtle or XML
236
+ domainforge project --format kg input.sea output.ttl
237
+ domainforge project --format kg input.sea output.xml
238
+ ```
239
+
240
+ ## Graph JSON Structure
241
+
242
+ When serializing a `Graph` to JSON, the structure includes all domain primitives:
243
+
244
+ ```json
245
+ {
246
+ "entities": {
247
+ "<uuid>": {
248
+ "id": "<uuid>",
249
+ "name": "Customer",
250
+ "namespace": "default",
251
+ "version": null,
252
+ "attributes": {}
253
+ }
254
+ },
255
+ "resources": {
256
+ "<uuid>": {
257
+ "id": "<uuid>",
258
+ "name": "Payment",
259
+ "namespace": "default",
260
+ "unit": "USD",
261
+ "has_units": true,
262
+ "attributes": {}
263
+ }
264
+ },
265
+ "flows": {
266
+ "<uuid>": {
267
+ "id": "<uuid>",
268
+ "resource_id": "<uuid>",
269
+ "from": "<uuid>",
270
+ "to": "<uuid>",
271
+ "quantity": null,
272
+ "namespace": "default",
273
+ "attributes": {}
274
+ }
275
+ },
276
+ "roles": {},
277
+ "relations": {},
278
+ "instances": {},
279
+ "entity_instances": {},
280
+ "policies": {},
281
+ "patterns": {},
282
+ "concept_changes": {},
283
+ "metrics": {},
284
+ "mappings": {},
285
+ "projections": {},
286
+ "entity_roles": {},
287
+ "config": {
288
+ "use_three_valued_logic": true
289
+ }
290
+ }
291
+ ```
292
+
293
+ ### Field Descriptions
294
+
295
+ | Field | Type | Description |
296
+ | ------------------ | ------------------------------- | ------------------------------------ |
297
+ | `entities` | `Map<UUID, Entity>` | All declared entities in the graph |
298
+ | `resources` | `Map<UUID, Resource>` | All declared resources |
299
+ | `flows` | `Map<UUID, Flow>` | Resource transfers between entities |
300
+ | `roles` | `Map<UUID, Role>` | Participant categories |
301
+ | `relations` | `Map<UUID, RelationType>` | Predicates connecting roles |
302
+ | `instances` | `Map<UUID, ResourceInstance>` | Concrete resource instances |
303
+ | `entity_instances` | `Map<UUID, Instance>` | Entity instances with field values |
304
+ | `policies` | `Map<UUID, Policy>` | Validation rules and constraints |
305
+ | `patterns` | `Map<UUID, Pattern>` | Regex patterns for string validation |
306
+ | `concept_changes` | `Map<UUID, ConceptChange>` | Version migration declarations |
307
+ | `metrics` | `Map<UUID, Metric>` | Observable metrics |
308
+ | `mappings` | `Map<UUID, MappingContract>` | Format mapping declarations |
309
+ | `projections` | `Map<UUID, ProjectionContract>` | Projection declarations |
310
+ | `entity_roles` | `Map<UUID, Vec<UUID>>` | Role assignments to entities |
311
+ | `config` | `GraphConfig` | Evaluation configuration |
312
+
313
+ ## Spanned AST Structure
314
+
315
+ The internal `Ast` structure contains `SpannedAstNode` elements, where each node includes source location:
316
+
317
+ ```json
318
+ {
319
+ "node": { "type": "Entity", "name": "Customer", ... },
320
+ "line": 1,
321
+ "column": 1
322
+ }
323
+ ```
324
+
325
+ This enables precise error messages and IDE integration with accurate source positions.
326
+
327
+ ## Converting Between AST and Graph
328
+
329
+ ### AST → Graph (Parsing)
330
+
331
+ The standard parsing pipeline converts source code to a `Graph`:
332
+
333
+ ```rust
334
+ use domainforge_core::parser::{parse_to_graph, parse_to_graph_with_options, ParseOptions};
335
+
336
+ // Simple parsing
337
+ let graph = parse_to_graph(source)?;
338
+
339
+ // With options (namespace, registry, etc.)
340
+ let options = ParseOptions {
341
+ default_namespace: Some("my_namespace".to_string()),
342
+ ..Default::default()
343
+ };
344
+ let graph = parse_to_graph_with_options(source, &options)?;
345
+ ```
346
+
347
+ ### Graph → AST (Reconstruction)
348
+
349
+ Convert a `Graph` back to an `Ast` for code generation or formatting:
350
+
351
+ ```rust
352
+ let ast = graph.to_ast();
353
+ // Note: Currently reconstructs Entity and Resource nodes only
354
+ ```
355
+
356
+ > [!NOTE]
357
+ > The `to_ast()` method is a partial implementation that currently reconstructs only Entity and Resource nodes. Full round-trip support is planned for future releases.
358
+
359
+ ## Projection Formats
360
+
361
+ SEA supports projecting graphs to various external formats:
362
+
363
+ | Format | Command | Output |
364
+ | --------------- | ------------------- | ----------------------- |
365
+ | CALM | `--format calm` | FINOS CALM JSON |
366
+ | Knowledge Graph | `--format kg` | RDF Turtle or XML |
367
+ | Protobuf | `--format protobuf` | Protocol Buffers schema |
368
+
369
+ ### CALM Export Example
370
+
371
+ ```bash
372
+ domainforge project --format calm domains/finance.sea output/finance.calm.json
373
+ ```
374
+
375
+ Produces FINOS CALM-compatible JSON following the schema in `schemas/calm-v1.schema.json`.
376
+
377
+ ## Validation and Error Handling
378
+
379
+ JSON output from validation includes structured error information:
380
+
381
+ ```json
382
+ {
383
+ "error_count": 2,
384
+ "violations": [
385
+ {
386
+ "severity": "error",
387
+ "policy_name": "reference_integrity",
388
+ "message": "Entity 'Unknown' not found",
389
+ "context": { "line": 5, "column": 12 }
390
+ },
391
+ {
392
+ "severity": "warning",
393
+ "policy_name": "naming_convention",
394
+ "message": "Entity name should be PascalCase",
395
+ "context": { "line": 3, "column": 8 }
396
+ }
397
+ ]
398
+ }
399
+ ```
400
+
401
+ ### Severity Levels
402
+
403
+ | Severity | Description |
404
+ | --------- | --------------------------------------------- |
405
+ | `error` | Validation failure that blocks processing |
406
+ | `warning` | Potential issue that doesn't block processing |
407
+ | `info` | Informational message |
408
+
409
+ ## Version Compatibility
410
+
411
+ | Schema | Version | Status |
412
+ | -------------------- | ------- | ------------------------------------------------------- |
413
+ | `ast-v3.schema.json` | 3.0.0 | **Current** (auto-generated, Resource/Flow annotations) |
414
+ | `ast-v2.schema.json` | 2.0.0 | Deprecated (lacks Resource/Flow annotations) |
415
+ | `ast-v1.schema.json` | 1.0.0 | Deprecated (hand-written) |
416
+
417
+ - Minimum domainforge-core version: `0.6.0`
418
+ - JSON output is stable across minor versions
419
+
420
+ ## See Also
421
+
422
+ - [primitives-api.md](primitives-api.md) — Core data structure reference
423
+ - [cli-commands.md](cli-commands.md) — CLI operations
424
+ - [calm-mapping.md](calm-mapping.md) — CALM format mapping details
425
+ - [wasm-api.md](wasm-api.md) — WASM bindings reference
426
+ - [typescript-api.md](typescript-api.md) — TypeScript API reference
427
+ - [python-api.md](python-api.md) — Python API reference