openforma 0.4.0__py3-none-any.whl

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 (288) hide show
  1. forma_cli/__init__.py +5 -0
  2. forma_cli/app.py +1139 -0
  3. forma_cli/config.py +112 -0
  4. forma_cli/credentials.py +141 -0
  5. forma_cli/local.py +562 -0
  6. forma_cli/metadata_api.py +138 -0
  7. forma_cli/project_artifacts.py +182 -0
  8. forma_cli/sdk.py +571 -0
  9. forma_core/__init__.py +9 -0
  10. forma_core/__main__.py +4 -0
  11. forma_core/_version.py +3 -0
  12. forma_core/agents/__init__.py +50 -0
  13. forma_core/agents/clarification.py +194 -0
  14. forma_core/agents/component_reconciliation.py +99 -0
  15. forma_core/agents/context_gathering.py +115 -0
  16. forma_core/agents/continuous.py +537 -0
  17. forma_core/agents/contracts.py +247 -0
  18. forma_core/agents/firecrawl_mcp.py +484 -0
  19. forma_core/agents/lattice.py +239 -0
  20. forma_core/agents/orchestrator.py +3724 -0
  21. forma_core/agents/pipeline.py +843 -0
  22. forma_core/agents/project_correction.py +83 -0
  23. forma_core/agents/prompt_compaction.py +428 -0
  24. forma_core/agents/system_architecture.py +345 -0
  25. forma_core/agents/video_correction.py +119 -0
  26. forma_core/agents/web_research_workflow.py +1256 -0
  27. forma_core/agents/workflows.py +176 -0
  28. forma_core/assets/__init__.py +1 -0
  29. forma_core/assets/models.py +156 -0
  30. forma_core/assets/project.py +17 -0
  31. forma_core/assets/repository.py +48 -0
  32. forma_core/assets/service.py +142 -0
  33. forma_core/assets/validation.py +35 -0
  34. forma_core/benchmarks/__init__.py +5 -0
  35. forma_core/benchmarks/ir_triad_v1.py +477 -0
  36. forma_core/biology/__init__.py +28 -0
  37. forma_core/biology/benchmark.py +80 -0
  38. forma_core/biology/ewart_liverchip.py +279 -0
  39. forma_core/biology/ir.py +25 -0
  40. forma_core/biology/liverbench.py +416 -0
  41. forma_core/biology/liverbench_assay.py +251 -0
  42. forma_core/biology/liverbench_baselines.py +133 -0
  43. forma_core/biology/liverbench_independent.py +229 -0
  44. forma_core/biology/liverchip_demo.py +154 -0
  45. forma_core/biology/liverchip_evidence.py +149 -0
  46. forma_core/biology/models.py +247 -0
  47. forma_core/biology/validation.py +72 -0
  48. forma_core/cad_migrations/__init__.py +6 -0
  49. forma_core/cad_migrations/cli.py +101 -0
  50. forma_core/cad_migrations/emitters.py +227 -0
  51. forma_core/cad_migrations/models.py +121 -0
  52. forma_core/cad_migrations/planner.py +68 -0
  53. forma_core/chemistry/__init__.py +5 -0
  54. forma_core/chemistry/models.py +215 -0
  55. forma_core/chemistry/stoichiometry.py +272 -0
  56. forma_core/chemistry/validation.py +179 -0
  57. forma_core/cli/__init__.py +1 -0
  58. forma_core/cli/__main__.py +4 -0
  59. forma_core/cli/main.py +370 -0
  60. forma_core/config/__init__.py +28 -0
  61. forma_core/config/compatibility.py +282 -0
  62. forma_core/config/contract.py +184 -0
  63. forma_core/config/environment.py +129 -0
  64. forma_core/config/parti.py +34 -0
  65. forma_core/config/runtime.py +303 -0
  66. forma_core/control/__init__.py +10 -0
  67. forma_core/control/actions.py +136 -0
  68. forma_core/control/adapters.py +36 -0
  69. forma_core/control/cli.py +49 -0
  70. forma_core/control/client.py +124 -0
  71. forma_core/control/models.py +168 -0
  72. forma_core/control/opencode_worker.py +80 -0
  73. forma_core/control/package.py +318 -0
  74. forma_core/control/rover_scene/__init__.py +1 -0
  75. forma_core/control/rover_scene/__main__.py +34 -0
  76. forma_core/control/rover_scene/assets.py +65 -0
  77. forma_core/control/rover_scene/fleet.py +214 -0
  78. forma_core/control/rover_scene/host.py +258 -0
  79. forma_core/control/rover_scene/kinematics.py +35 -0
  80. forma_core/control/rover_scene/machine.py +347 -0
  81. forma_core/control/rover_scene/robot.py +166 -0
  82. forma_core/control/rover_scene/scene.py +206 -0
  83. forma_core/control/rover_scene/view.py +80 -0
  84. forma_core/control/rover_scene/web/index.html +25 -0
  85. forma_core/control/rover_scene/web/viewer.js +148 -0
  86. forma_core/control/runtime.py +356 -0
  87. forma_core/control/so101.py +235 -0
  88. forma_core/control/tasks.py +287 -0
  89. forma_core/database.py +2362 -0
  90. forma_core/debug.py +314 -0
  91. forma_core/domains/__init__.py +7 -0
  92. forma_core/domains/agents.py +85 -0
  93. forma_core/domains/base.py +69 -0
  94. forma_core/domains/benchmark.py +87 -0
  95. forma_core/domains/cli.py +48 -0
  96. forma_core/domains/compatibility.py +234 -0
  97. forma_core/domains/composition.py +372 -0
  98. forma_core/domains/diagnostics.py +15 -0
  99. forma_core/domains/generation.py +479 -0
  100. forma_core/domains/interaction.py +301 -0
  101. forma_core/domains/planning.py +140 -0
  102. forma_core/domains/providers.py +214 -0
  103. forma_core/domains/registry.py +267 -0
  104. forma_core/domains/selection.py +75 -0
  105. forma_core/domains/storage.py +60 -0
  106. forma_core/domains/tools.py +180 -0
  107. forma_core/electronics/__init__.py +1 -0
  108. forma_core/electronics/models.py +84 -0
  109. forma_core/electronics/primitives.py +43 -0
  110. forma_core/electronics/rules.py +340 -0
  111. forma_core/external_sources.py +497 -0
  112. forma_core/fabricator/__init__.py +33 -0
  113. forma_core/fabricator/__main__.py +7 -0
  114. forma_core/fabricator/main.py +578 -0
  115. forma_core/firmware/__init__.py +60 -0
  116. forma_core/firmware/drivers.py +140 -0
  117. forma_core/firmware/examples.py +503 -0
  118. forma_core/firmware/generate.py +520 -0
  119. forma_core/firmware/models.py +34 -0
  120. forma_core/firmware/sil/__init__.py +5 -0
  121. forma_core/firmware/sil/adapter.py +71 -0
  122. forma_core/firmware/sil/build.py +49 -0
  123. forma_core/firmware/sil/native/CMakeLists.txt +9 -0
  124. forma_core/firmware/sil/native/bridge.cpp +112 -0
  125. forma_core/firmware/sil/native/controller.cpp +123 -0
  126. forma_core/firmware/sil/native/controller.h +49 -0
  127. forma_core/firmware/sil/simulator.py +139 -0
  128. forma_core/firmware/targets.py +111 -0
  129. forma_core/firmware/validation.py +130 -0
  130. forma_core/fluidics/__init__.py +6 -0
  131. forma_core/fluidics/benchmark.py +217 -0
  132. forma_core/fluidics/calculations.py +79 -0
  133. forma_core/fluidics/examples.py +54 -0
  134. forma_core/fluidics/ir.py +25 -0
  135. forma_core/fluidics/models.py +132 -0
  136. forma_core/fluidics/topology.py +47 -0
  137. forma_core/fluidics/validation.py +134 -0
  138. forma_core/generation.py +32 -0
  139. forma_core/geometry_bindings/__init__.py +20 -0
  140. forma_core/geometry_bindings/cad_adapter.py +80 -0
  141. forma_core/geometry_bindings/models.py +163 -0
  142. forma_core/geometry_bindings/resolution.py +340 -0
  143. forma_core/geometry_bindings/tools.py +125 -0
  144. forma_core/image_providers.py +3049 -0
  145. forma_core/images.py +3 -0
  146. forma_core/integrations/__init__.py +1 -0
  147. forma_core/integrations/huggingface/__init__.py +29 -0
  148. forma_core/integrations/huggingface/huggingface_artifacts.py +272 -0
  149. forma_core/jobs/__init__.py +1 -0
  150. forma_core/jobs/context.py +277 -0
  151. forma_core/jobs/continuous.py +719 -0
  152. forma_core/jobs/metrics.py +124 -0
  153. forma_core/jobs/migrations.py +161 -0
  154. forma_core/jobs/persistence.py +28 -0
  155. forma_core/jobs/repositories.py +422 -0
  156. forma_core/jobs/schema.py +28 -0
  157. forma_core/jobs/source_usage.py +230 -0
  158. forma_core/jobs/store.py +476 -0
  159. forma_core/llm.py +3 -0
  160. forma_core/llm_providers.py +2682 -0
  161. forma_core/logs.py +107 -0
  162. forma_core/mechanics/__init__.py +1 -0
  163. forma_core/mechanics/gear_benchmark.py +85 -0
  164. forma_core/mechanics/mechanism_benchmarks.py +345 -0
  165. forma_core/mechanics/models.py +72 -0
  166. forma_core/mechanics/primitives.py +109 -0
  167. forma_core/mechanics/solid_cad.py +83 -0
  168. forma_core/observability.py +237 -0
  169. forma_core/openai_streams.py +780 -0
  170. forma_core/opencode/__init__.py +25 -0
  171. forma_core/opencode/architecture.py +82 -0
  172. forma_core/opencode/capabilities.py +130 -0
  173. forma_core/opencode/models.py +419 -0
  174. forma_core/opencode/persistence.py +62 -0
  175. forma_core/opencode/public_events.py +91 -0
  176. forma_core/opencode/schema.py +28 -0
  177. forma_core/opencode/store.py +874 -0
  178. forma_core/persistence/__init__.py +16 -0
  179. forma_core/persistence/base.py +38 -0
  180. forma_core/persistence/images.py +598 -0
  181. forma_core/persistence/migrations.py +200 -0
  182. forma_core/persistence/models.py +439 -0
  183. forma_core/persistence/project_artifacts.py +341 -0
  184. forma_core/persistence/project_reconciliation.py +1094 -0
  185. forma_core/persistence/providers/__init__.py +4 -0
  186. forma_core/persistence/providers/sqlite.py +114 -0
  187. forma_core/persistence/providers/supabase.py +31 -0
  188. forma_core/persistence/repositories/__init__.py +9 -0
  189. forma_core/persistence/repositories/base.py +335 -0
  190. forma_core/persistence/repositories/sqlite.py +1571 -0
  191. forma_core/persistence/repositories/supabase.py +1576 -0
  192. forma_core/persistence/schema.py +176 -0
  193. forma_core/processes/__init__.py +5 -0
  194. forma_core/processes/models.py +338 -0
  195. forma_core/processes/validation.py +141 -0
  196. forma_core/project_list_cache.py +316 -0
  197. forma_core/prompt_continuity.py +387 -0
  198. forma_core/providers/__init__.py +39 -0
  199. forma_core/providers/base.py +28 -0
  200. forma_core/providers/models.py +138 -0
  201. forma_core/providers/openai.py +92 -0
  202. forma_core/providers/openai_compatible.py +190 -0
  203. forma_core/providers/registry.py +68 -0
  204. forma_core/providers/registry_utils.py +46 -0
  205. forma_core/py.typed +1 -0
  206. forma_core/runtime.py +3 -0
  207. forma_core/selectors.py +36 -0
  208. forma_core/signups/__init__.py +5 -0
  209. forma_core/signups/models.py +49 -0
  210. forma_core/terminal/__init__.py +1 -0
  211. forma_core/terminal/dashboard.py +475 -0
  212. forma_core/terminal/images.py +156 -0
  213. forma_core/thermal/__init__.py +5 -0
  214. forma_core/thermal/models.py +361 -0
  215. forma_core/thermal/validation.py +175 -0
  216. forma_core/user_integrations.py +2069 -0
  217. forma_core/utils.py +291 -0
  218. forma_core/validation.py +83 -0
  219. forma_core/vertex_auth.py +92 -0
  220. forma_core/video_prompts.py +193 -0
  221. forma_core/video_review.py +1006 -0
  222. forma_core/wiring.py +356 -0
  223. forma_core/workers/__init__.py +120 -0
  224. forma_core/workers/contracts.py +183 -0
  225. forma_core/workers/generation.py +753 -0
  226. forma_core/workers/orchestration.py +805 -0
  227. forma_core/workers/registry.py +222 -0
  228. forma_core/workers/reverse_engineering.py +272 -0
  229. forma_core/workers/validation.py +291 -0
  230. forma_core/workspaces/__init__.py +5 -0
  231. forma_core/workspaces/chats/__init__.py +11 -0
  232. forma_core/workspaces/chats/models.py +48 -0
  233. forma_core/workspaces/context/__init__.py +15 -0
  234. forma_core/workspaces/context/agent.py +260 -0
  235. forma_core/workspaces/context/models.py +117 -0
  236. forma_core/workspaces/context/pdf.py +418 -0
  237. forma_core/workspaces/design_briefs/__init__.py +25 -0
  238. forma_core/workspaces/design_briefs/models.py +85 -0
  239. forma_core/workspaces/design_briefs/references.py +56 -0
  240. forma_core/workspaces/models.py +41 -0
  241. forma_core/workspaces/projects/__init__.py +88 -0
  242. forma_core/workspaces/projects/cad_generation.py +1016 -0
  243. forma_core/workspaces/projects/context_governance.py +365 -0
  244. forma_core/workspaces/projects/design_lifecycle.py +668 -0
  245. forma_core/workspaces/projects/fabrication/__init__.py +54 -0
  246. forma_core/workspaces/projects/fabrication/demo_printers.py +236 -0
  247. forma_core/workspaces/projects/fabrication/models.py +120 -0
  248. forma_core/workspaces/projects/fabrication/printer_config.py +205 -0
  249. forma_core/workspaces/projects/fabrication/slicers/__init__.py +7 -0
  250. forma_core/workspaces/projects/fabrication/slicers/base.py +25 -0
  251. forma_core/workspaces/projects/fabrication/slicers/cura.py +125 -0
  252. forma_core/workspaces/projects/fabrication/slicers/orca.py +208 -0
  253. forma_core/workspaces/projects/fabrication/slicing.py +202 -0
  254. forma_core/workspaces/projects/fabrication/validation.py +103 -0
  255. forma_core/workspaces/projects/gear_benchmark.py +6 -0
  256. forma_core/workspaces/projects/generation_mode.py +70 -0
  257. forma_core/workspaces/projects/identity.py +28 -0
  258. forma_core/workspaces/projects/iteration.py +680 -0
  259. forma_core/workspaces/projects/manifest.py +362 -0
  260. forma_core/workspaces/projects/mechanism_benchmarks.py +12 -0
  261. forma_core/workspaces/projects/models.py +913 -0
  262. forma_core/workspaces/projects/objects.py +731 -0
  263. forma_core/workspaces/projects/outcomes.py +47 -0
  264. forma_core/workspaces/projects/output.py +735 -0
  265. forma_core/workspaces/projects/resolver.py +397 -0
  266. forma_core/workspaces/projects/solid_cad.py +8 -0
  267. forma_core/workspaces/projects/state.py +622 -0
  268. forma_core/workspaces/readiness/__init__.py +28 -0
  269. forma_core/workspaces/readiness/evaluator.py +103 -0
  270. forma_core/workspaces/readiness/models.py +97 -0
  271. forma_core/workspaces/readiness/service.py +225 -0
  272. forma_core/workspaces/reverse_engineering/__init__.py +37 -0
  273. forma_core/workspaces/reverse_engineering/analyzer.py +246 -0
  274. forma_core/workspaces/reverse_engineering/models.py +128 -0
  275. forma_core/workspaces/validation/__init__.py +37 -0
  276. forma_core/workspaces/validation/evaluator.py +327 -0
  277. forma_core/workspaces/validation/models.py +146 -0
  278. forma_core/workspaces/validation/service.py +212 -0
  279. forma_core/workspaces/workflow/__init__.py +29 -0
  280. forma_core/workspaces/workflow/guard.py +33 -0
  281. forma_core/workspaces/workflow/models.py +77 -0
  282. forma_core/workspaces/workflow/service.py +287 -0
  283. openforma-0.4.0.dist-info/METADATA +247 -0
  284. openforma-0.4.0.dist-info/RECORD +288 -0
  285. openforma-0.4.0.dist-info/WHEEL +5 -0
  286. openforma-0.4.0.dist-info/entry_points.txt +4 -0
  287. openforma-0.4.0.dist-info/licenses/LICENSE +373 -0
  288. openforma-0.4.0.dist-info/top_level.txt +2 -0
@@ -0,0 +1,134 @@
1
+ """Deterministic topology and supplied operating-constraint checks."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from math import isclose
6
+
7
+ from pydantic import BaseModel, ValidationError
8
+
9
+ from .calculations import FlowCalculationError, pressure_drop_kpa
10
+ from .models import FluidicSystem
11
+ from .topology import build_topology, reachable
12
+
13
+
14
+ class FluidicIssue(BaseModel):
15
+ """Blocking finding with a stable code, component ID or schema location."""
16
+
17
+ code: str
18
+ entity_id: str
19
+ message: str
20
+
21
+
22
+ def validate_fluidic_system(system: FluidicSystem) -> list[FluidicIssue]:
23
+ """Return blocking findings. An empty result means supplied checks passed.
24
+
25
+ This checks nominal open-valve topology, not valve sequencing, pressure
26
+ balancing, transport across membranes, biology, or fabrication readiness.
27
+ """
28
+ issues: list[FluidicIssue] = []
29
+
30
+ def add(code: str, entity_id: str, message: str) -> None:
31
+ issues.append(FluidicIssue(code=code, entity_id=entity_id, message=message))
32
+
33
+ # Lists/models are mutable: recheck dimensions and IDs after in-process edits.
34
+ try:
35
+ system = FluidicSystem.model_validate(system.model_dump())
36
+ except ValidationError as exc:
37
+ return [FluidicIssue(
38
+ code="schema", entity_id=".".join(map(str, error["loc"])) or "system", message=error["msg"],
39
+ ) for error in exc.errors()]
40
+
41
+ graph = build_topology(system)
42
+ channels = {item.id: item for item in system.channels}
43
+ pumps = {item.id: item for item in system.pumps}
44
+ valves = {item.id: item for item in system.valves}
45
+ fluids = {item.id: item for item in system.fluids}
46
+ if not graph.sources:
47
+ add("missing_source", "system", "Declare at least one inlet or supply reservoir.")
48
+ if not graph.sinks:
49
+ add("missing_outlet", "system", "Declare at least one outlet or waste reservoir.")
50
+ if not channels:
51
+ add("missing_channel", "system", "Declare at least one flow channel.")
52
+ for channel in system.channels:
53
+ source, target = graph.nodes.get(channel.source_id), graph.nodes.get(channel.target_id)
54
+ for endpoint in (channel.source_id, channel.target_id):
55
+ if endpoint not in graph.nodes:
56
+ add("unknown_node", channel.id, f"Unknown channel endpoint '{endpoint}'.")
57
+ if channel.source_id == channel.target_id or channel.target_id in graph.sources or channel.source_id in graph.sinks:
58
+ add("invalid_direction", channel.id, "Channels cannot self-connect, enter a source or leave a sink.")
59
+ if source and target and source.circuit_id != target.circuit_id:
60
+ add("circuit_mixing", channel.id, "Bulk flow cannot cross isolated circuit IDs; use a membrane interface.")
61
+ for reference, catalog, kind in [(channel.pump_id, pumps, "pump"), (channel.valve_id, valves, "valve")]:
62
+ if reference is not None:
63
+ if reference not in catalog:
64
+ add(f"unknown_{kind}", channel.id, f"Unknown {kind} '{reference}'.")
65
+ elif reference not in (channel.source_id, channel.target_id):
66
+ add(f"non_inline_{kind}", channel.id, f"Referenced {kind} '{reference}' must be a channel endpoint.")
67
+ lower, upper, flow = channel.min_flow_rate_ul_min, channel.max_flow_rate_ul_min, channel.target_flow_rate_ul_min
68
+ if lower is not None and upper is not None and lower > upper:
69
+ add("flow_bounds", channel.id, "Minimum flow exceeds maximum flow.")
70
+ if (lower is not None or upper is not None) and flow is None:
71
+ add("flow_unknown", channel.id, "A flow target is required to check the supplied bounds.")
72
+ if flow is not None and ((lower is not None and flow < lower) or (upper is not None and flow > upper)):
73
+ add("flow_bounds", channel.id, "Target flow is outside the declared bounds.")
74
+ if channel.max_pressure_kpa is not None:
75
+ try:
76
+ if channel.fluid not in fluids:
77
+ raise FlowCalculationError(f"Missing properties for fluid '{channel.fluid}'.")
78
+ drop = pressure_drop_kpa(channel, fluids[channel.fluid])
79
+ if drop > channel.max_pressure_kpa:
80
+ add("pressure_limit", channel.id, f"Estimated pressure drop {drop:.6g} kPa exceeds the declared limit.")
81
+ except FlowCalculationError as exc:
82
+ add("pressure_unknown", channel.id, str(exc))
83
+
84
+ from_source = reachable(graph.forward, graph.sources)
85
+ to_sink = reachable(graph.reverse, graph.sinks)
86
+ for node_id in sorted(graph.nodes):
87
+ if node_id not in from_source:
88
+ add("unreachable_node", node_id, "Node has no incoming path from a source.")
89
+ if node_id not in to_sink:
90
+ add("no_outlet_path", node_id, "Node cannot reach a valid outlet or waste reservoir.")
91
+
92
+ incoming = {node: [c for c in system.channels if c.target_id == node] for node in graph.nodes}
93
+ outgoing = {node: [c for c in system.channels if c.source_id == node] for node in graph.nodes}
94
+ for chamber in system.chambers:
95
+ for declared, actual, label in [
96
+ (chamber.inlet_ids, incoming[chamber.id], "inlet_ids"),
97
+ (chamber.outlet_ids, outgoing[chamber.id], "outlet_ids"),
98
+ ]:
99
+ if len(declared) != len(set(declared)) or set(declared) != {c.id for c in actual}:
100
+ add("chamber_ports", chamber.id, f"{label} must list exactly the connected {label.split('_')[0]} channel IDs.")
101
+
102
+ for node_id in sorted(graph.nodes.keys() - graph.sources - graph.sinks):
103
+ ins, outs = incoming[node_id], outgoing[node_id]
104
+ flows = [c.target_flow_rate_ul_min for c in ins + outs]
105
+ if ins and outs and all(q is not None for q in flows):
106
+ inflow = sum(c.target_flow_rate_ul_min for c in ins)
107
+ outflow = sum(c.target_flow_rate_ul_min for c in outs)
108
+ if not isclose(inflow, outflow, rel_tol=1e-6, abs_tol=1e-9):
109
+ add("flow_balance", node_id, "Supplied flows do not conserve volume at this steady-state internal node.")
110
+ pump = pumps.get(node_id)
111
+ if pump is not None:
112
+ target, maximum = pump.target_flow_rate_ul_min, pump.max_flow_rate_ul_min
113
+ if target is not None and maximum is not None and target > maximum:
114
+ add("pump_flow_limit", node_id, "Pump target exceeds pump capacity.")
115
+ for adjacent in (ins, outs):
116
+ if not adjacent or any(c.target_flow_rate_ul_min is None for c in adjacent):
117
+ if target is not None or maximum is not None:
118
+ add("pump_flow_unknown", node_id, "Supply adjacent channel flows to verify the pump target/capacity.")
119
+ continue
120
+ total = sum(c.target_flow_rate_ul_min for c in adjacent)
121
+ if target is not None and not isclose(total, target, rel_tol=1e-6, abs_tol=1e-9):
122
+ add("pump_flow_target", node_id, "Adjacent channel flow does not match the pump target.")
123
+ if maximum is not None and total > maximum:
124
+ add("pump_flow_limit", node_id, "Adjacent channel flow exceeds pump capacity.")
125
+
126
+ interface_circuits = {c.id: graph.nodes[c.source_id].circuit_id for c in system.channels if c.source_id in graph.nodes}
127
+ interface_circuits.update({c.id: c.circuit_id for c in system.chambers})
128
+ for membrane in system.membranes:
129
+ sides = [interface_circuits.get(membrane.side_a_id), interface_circuits.get(membrane.side_b_id)]
130
+ if None in sides:
131
+ add("membrane_reference", membrane.id, "Each membrane side must reference an existing channel or chamber.")
132
+ elif sides[0] == sides[1]:
133
+ add("membrane_isolation", membrane.id, "Membrane sides must belong to distinct bulk-fluid circuits.")
134
+ return sorted(issues, key=lambda issue: (issue.code, issue.entity_id, issue.message))
@@ -0,0 +1,32 @@
1
+ """High-level generation API for package consumers."""
2
+
3
+ from forma_core.domains.generation import EngineeringRequest, EngineeringResult, generate_engineering
4
+ from forma_core.domains.interaction import advance_generation
5
+ from forma_core.agents.orchestrator import HardwarePipelineOrchestrator
6
+ from forma_core.agents.workflows import (
7
+ generate_project_with_workflow,
8
+ get_workflow_debug_config,
9
+ list_workflows,
10
+ normalize_workflow_id,
11
+ )
12
+ from forma_core.agents.project_correction import ProjectSelfCorrectionAgent
13
+ from forma_core.workspaces.projects.iteration import ProjectIterator, iterate_project
14
+ from forma_core.workspaces.projects.objects import FormaProjectObject, build_project_object, list_project_namespaces
15
+ from forma_core.video_prompts import VIDEO_PROMPT_NAMESPACES, generate_image_to_video_prompt_from_namespaces
16
+
17
+ __all__ = [
18
+ "EngineeringRequest", "EngineeringResult", "generate_engineering", "advance_generation",
19
+ "HardwarePipelineOrchestrator",
20
+ "FormaProjectObject",
21
+ "ProjectIterator",
22
+ "ProjectSelfCorrectionAgent",
23
+ "VIDEO_PROMPT_NAMESPACES",
24
+ "build_project_object",
25
+ "generate_image_to_video_prompt_from_namespaces",
26
+ "generate_project_with_workflow",
27
+ "get_workflow_debug_config",
28
+ "iterate_project",
29
+ "list_project_namespaces",
30
+ "list_workflows",
31
+ "normalize_workflow_id",
32
+ ]
@@ -0,0 +1,20 @@
1
+ """Independent geometry binding contract shared across engineering domain IRs.
2
+
3
+ The owning domain artifacts remain versioned separately. The manifest is a
4
+ cross-domain sidecar, not a new engineering IR or a CAD kernel.
5
+ """
6
+
7
+ from .models import Binding, BindingManifest, GeometryArtifact, GeometryEntity, GeometryRequirement, Pose, SemanticRef
8
+ from .resolution import (
9
+ BindingReport, apply_pose, axis_bounds, composed_pose, forward_lookup,
10
+ invalidate_geometry, reverse_lookup, rotate_xyz, validate_manifest,
11
+ validate_manifest_against_product,
12
+ )
13
+
14
+ __all__ = [
15
+ "Binding", "BindingManifest", "BindingReport", "GeometryArtifact",
16
+ "GeometryEntity", "GeometryRequirement", "Pose", "SemanticRef",
17
+ "apply_pose", "axis_bounds", "composed_pose", "forward_lookup",
18
+ "invalidate_geometry", "reverse_lookup", "rotate_xyz", "validate_manifest",
19
+ "validate_manifest_against_product",
20
+ ]
@@ -0,0 +1,80 @@
1
+ """Opt-in, locally trusted STEP body inspection using the installed CAD kernel.
2
+
3
+ This adapter reads an explicitly supplied local STEP file. It is intentionally
4
+ SDK-only; the authenticated hosted MCP surface never accepts arbitrary paths.
5
+ No numeric face index or free-form file name is considered persistent geometry.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import hashlib
11
+ from pathlib import Path
12
+ from typing import Literal
13
+
14
+ from .models import Binding, BindingManifest, GeometryArtifact, GeometryEntity, Pose, SemanticRef
15
+
16
+
17
+ class GeometryInspectionError(ValueError):
18
+ """A STEP artifact cannot be verified at the requested identity/fidelity."""
19
+
20
+
21
+ def inspect_single_step_body(
22
+ path: str | Path,
23
+ *,
24
+ geometry: GeometryArtifact,
25
+ product_id: str,
26
+ semantic: SemanticRef,
27
+ role: Literal["physical_body", "envelope"] = "physical_body",
28
+ ) -> BindingManifest:
29
+ """Build a pinned, verified coarse BODY binding from a real single-solid STEP.
30
+
31
+ Use only if the caller knows the source semantic occurrence produced this
32
+ isolated part artifact. This function checks the STEP bytes and actual
33
+ geometry, but cannot infer part semantics or identify exact mating faces.
34
+ The tool has **no** silent fallback for multi-solid or empty exports.
35
+ """
36
+ source = Path(path)
37
+ if geometry.format != "step" or geometry.units != "mm":
38
+ raise GeometryInspectionError("The bounded STEP body adapter expects a millimetre STEP artifact.")
39
+ digest = hashlib.sha256(source.read_bytes()).hexdigest()
40
+ if digest != geometry.sha256:
41
+ raise GeometryInspectionError("STEP bytes disagree with the pinned geometry artifact digest.")
42
+ try:
43
+ import cadquery as cq
44
+ except ImportError as exc:
45
+ raise GeometryInspectionError("CadQuery/OCCT is required to inspect STEP geometry.") from exc
46
+ try:
47
+ workplane = cq.importers.importStep(str(source))
48
+ solids = workplane.solids().vals()
49
+ except Exception as exc:
50
+ raise GeometryInspectionError(f"Could not import pinned STEP geometry: {type(exc).__name__}") from exc
51
+ if len(solids) != 1:
52
+ raise GeometryInspectionError(
53
+ f"STEP body selection is unresolved: expected one isolated solid, found {len(solids)}."
54
+ )
55
+ solid = solids[0]
56
+ bounds = solid.BoundingBox()
57
+ dimensions = (float(bounds.xlen), float(bounds.ylen), float(bounds.zlen))
58
+ if min(dimensions) <= 0:
59
+ raise GeometryInspectionError("Imported STEP solid has a degenerate bounding envelope.")
60
+ selector = f"step-sha256/{digest}/solid-singleton"
61
+ return BindingManifest(
62
+ product_id=product_id, geometry=geometry,
63
+ entities=[GeometryEntity(
64
+ entity_id="body-0", selector=selector, kind="body",
65
+ anchor=(float((bounds.xmin + bounds.xmax) / 2.0),
66
+ float((bounds.ymin + bounds.ymax) / 2.0),
67
+ float((bounds.zmin + bounds.zmax) / 2.0)),
68
+ bounds_mm=dimensions, fidelity="detailed",
69
+ source="supplied_cad", verified_from_artifact=True,
70
+ )],
71
+ bindings=[Binding(
72
+ binding_id=f"step-body/{semantic.entity_id}/{'/'.join(semantic.occurrence_path)}",
73
+ semantic=semantic, selector=selector, role=role,
74
+ method="artifact_local", resolution="resolved",
75
+ fidelity="detailed", source="supplied_cad",
76
+ occurrence_pose=Pose(),
77
+ )],
78
+ evidence={"verified_geometry": "sha256 and one native CADQuery/OCCT imported STEP solid",
79
+ "selection_limit": "Body-level only; face/port selectors and semantic authorship unverified"},
80
+ )
@@ -0,0 +1,163 @@
1
+ """Versioned, revision-pinned semantic-to-geometric identity contracts.
2
+
3
+ A binding describes a relationship, not an assertion that arbitrary geometry
4
+ has exact feature semantics. Source documents remain owned by their domain IRs.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import math
10
+ from typing import Literal
11
+
12
+ from pydantic import Field, model_validator
13
+
14
+ from forma_core.domains.base import DomainModel, Text, unique
15
+
16
+ Digest = str
17
+ Vector3 = tuple[float, float, float]
18
+ Origin = Literal["supplied_cad", "measured", "specification", "authored", "agent_estimate", "heuristic"]
19
+ Fidelity = Literal["envelope", "simplified", "detailed", "unknown"]
20
+ Resolution = Literal["resolved", "unresolved", "ambiguous", "stale", "unsupported", "not_applicable"]
21
+ TargetKind = Literal["assembly", "body", "face", "edge", "vertex", "datum", "port", "region", "mesh_group"]
22
+ Role = Literal["physical_body", "envelope", "mounting_face", "mating_interface",
23
+ "pin", "fluid_boundary", "clearance", "biological_host", "feature"]
24
+ Method = Literal["named_feature", "artifact_local", "approximate"]
25
+
26
+
27
+ class Pose(DomainModel):
28
+ """Active right-handed XYZ Euler pose, applying Rx then Ry then Rz, in mm."""
29
+
30
+ translation_mm: Vector3 = (0.0, 0.0, 0.0)
31
+ euler_xyz_deg: Vector3 = (0.0, 0.0, 0.0)
32
+ convention: Literal["RH_active_XYZ"] = "RH_active_XYZ"
33
+
34
+ @model_validator(mode="after")
35
+ def finite_pose(self) -> "Pose":
36
+ """A translation/rotation with NaN cannot be a reproducible transform."""
37
+ if any(not math.isfinite(v) for v in (*self.translation_mm, *self.euler_xyz_deg)):
38
+ raise ValueError("Pose values must be finite.")
39
+ return self
40
+
41
+
42
+ class SemanticRef(DomainModel):
43
+ """Stable domain entity and actual occurrence; display labels are not keys."""
44
+
45
+ domain: Text
46
+ artifact_id: Text
47
+ revision: int = Field(ge=1)
48
+ sha256: str = Field(pattern=r"^[a-f0-9]{64}$")
49
+ entity_id: Text
50
+ occurrence_path: tuple[Text, ...] = Field(min_length=1)
51
+ feature_id: Text | None = None
52
+ part_definition_id: Text | None = None
53
+ label: str | None = None
54
+
55
+
56
+ class GeometryArtifact(DomainModel):
57
+ """A pinned CAD/mesh revision with one declared metric coordinate frame."""
58
+
59
+ artifact_id: Text
60
+ revision: int = Field(ge=1)
61
+ sha256: str = Field(pattern=r"^[a-f0-9]{64}$")
62
+ format: Literal["step", "stl", "obj", "3mf", "opencad", "glb", "scene", "synthetic"]
63
+ producer: Text
64
+ producer_version: Text
65
+ frame: Text
66
+ units: Literal["mm", "m"] = "mm"
67
+ handedness: Literal["right"] = "right"
68
+
69
+
70
+ class GeometryEntity(DomainModel):
71
+ """A geometric item exposed by an adapter, with revision-local identity.
72
+
73
+ A named selector is valid only within this exact geometry artifact revision.
74
+ A mesh envelope has no implied exact face, contact or pin features.
75
+ """
76
+
77
+ entity_id: Text
78
+ selector: Text
79
+ kind: TargetKind
80
+ anchor: Vector3 = (0.0, 0.0, 0.0)
81
+ normal: Vector3 | None = None
82
+ bounds_mm: Vector3 | None = None
83
+ fidelity: Fidelity = "unknown"
84
+ source: Origin
85
+ verified_from_artifact: bool = False
86
+
87
+ @model_validator(mode="after")
88
+ def valid_geometry(self) -> "GeometryEntity":
89
+ """Reject non-finite anchors, invalid dimensions and a zero normal."""
90
+ vectors = [self.anchor] + ([self.normal] if self.normal else []) + ([self.bounds_mm] if self.bounds_mm else [])
91
+ if any(not math.isfinite(n) for vec in vectors for n in vec):
92
+ raise ValueError("Geometric vectors must be finite.")
93
+ if self.bounds_mm is not None and any(v <= 0 for v in self.bounds_mm):
94
+ raise ValueError("Geometric bounds must be positive.")
95
+ if self.normal is not None and math.isclose(sum(v*v for v in self.normal), 0.0, abs_tol=1e-15):
96
+ raise ValueError("Geometric face normal cannot be zero.")
97
+ return self
98
+
99
+
100
+ class Binding(DomainModel):
101
+ """One independently versioned semantic-to-geometric association."""
102
+
103
+ binding_id: Text
104
+ semantic: SemanticRef
105
+ selector: Text | None = None
106
+ role: Role
107
+ method: Method = "artifact_local"
108
+ required: bool = True
109
+ resolution: Resolution = "unresolved"
110
+ fidelity: Fidelity = "unknown"
111
+ source: Origin
112
+ occurrence_pose: Pose = Field(default_factory=Pose)
113
+ assumptions: list[Text] = Field(default_factory=list)
114
+
115
+ @model_validator(mode="after")
116
+ def declared_status(self) -> "Binding":
117
+ """No resolved binding without a selector or inapplicable target."""
118
+ if self.resolution == "resolved" and not self.selector:
119
+ raise ValueError("Resolved binding requires a geometry selector.")
120
+ if self.resolution == "not_applicable" and self.selector is not None:
121
+ raise ValueError("Nonspatial bindings cannot select geometric targets.")
122
+ return self
123
+
124
+
125
+ class GeometryRequirement(DomainModel):
126
+ """A bounded requirement, distinct from a measured geometric result."""
127
+
128
+ requirement_id: Text
129
+ kind: Literal["coincident", "aligned", "axis_offset", "envelope_clearance"]
130
+ source_binding_id: Text
131
+ target_binding_id: Text
132
+ tolerance_mm: float = Field(0.1, ge=0, allow_inf_nan=False)
133
+ tolerance_deg: float = Field(1.0, ge=0, allow_inf_nan=False)
134
+ offset_mm: float | None = Field(None, allow_inf_nan=False)
135
+ axis: Literal["x", "y", "z"] | None = None
136
+ required: bool = True
137
+
138
+ @model_validator(mode="after")
139
+ def required_parameter(self) -> "GeometryRequirement":
140
+ """Axis offsets must specify the axis and target signed displacement."""
141
+ if self.kind == "axis_offset" and (self.axis is None or self.offset_mm is None):
142
+ raise ValueError("Axis offset needs an axis and a signed offset_mm.")
143
+ return self
144
+
145
+
146
+ class BindingManifest(DomainModel):
147
+ """Portable sidecar, separate from CAD/source IR and scene/runtime state."""
148
+
149
+ schema_version: Literal["1.0"] = "1.0"
150
+ product_id: Text
151
+ geometry: GeometryArtifact
152
+ entities: list[GeometryEntity] = Field(default_factory=list)
153
+ bindings: list[Binding] = Field(default_factory=list)
154
+ requirements: list[GeometryRequirement] = Field(default_factory=list)
155
+ evidence: dict[str, str] = Field(default_factory=dict)
156
+
157
+ @model_validator(mode="after")
158
+ def local_identity(self) -> "BindingManifest":
159
+ """Keep manifest-local IDs stable while permitting ambiguous selectors."""
160
+ unique([entity.entity_id for entity in self.entities], "geometric entity IDs")
161
+ unique([binding.binding_id for binding in self.bindings], "binding IDs")
162
+ unique([requirement.requirement_id for requirement in self.requirements], "requirement IDs")
163
+ return self