64 lines
2.1 KiB
Python
64 lines
2.1 KiB
Python
"""Layer 7 — Toolpath Determinism Engine: toolpath -> geometry -> intent -> requirement."""
|
|
|
|
from typing import Any
|
|
|
|
from pydantic import BaseModel, Field
|
|
|
|
|
|
class ToolpathLineage(BaseModel):
|
|
"""Lineage: toolpath traces to geometry, geometry to intent, intent to requirement."""
|
|
|
|
toolpath_ref: str = Field(...)
|
|
geometry_ref: str = Field(...)
|
|
intent_ref: str = Field(...)
|
|
requirement_ref: str | None = Field(default=None)
|
|
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
|
|
|
|
class ToolpathArtifact(BaseModel):
|
|
"""Toolpath artifact + lineage (G-code or AM slice)."""
|
|
|
|
artifact_id: str = Field(...)
|
|
artifact_type: str = Field(..., description="cnc_gcode or am_slice")
|
|
content_ref: str | None = Field(default=None)
|
|
lineage: ToolpathLineage = Field(...)
|
|
metadata: dict[str, Any] = Field(default_factory=dict)
|
|
|
|
|
|
class ToolpathEngine:
|
|
"""Every toolpath traces to geometry -> intent -> requirement. Generates only after full closure."""
|
|
|
|
def __init__(self) -> None:
|
|
self._artifacts: dict[str, ToolpathArtifact] = {}
|
|
|
|
def generate(
|
|
self,
|
|
artifact_id: str,
|
|
artifact_type: str,
|
|
geometry_ref: str,
|
|
intent_ref: str,
|
|
requirement_ref: str | None = None,
|
|
content_ref: str | None = None,
|
|
metadata: dict[str, Any] | None = None,
|
|
) -> ToolpathArtifact:
|
|
"""Generate toolpath artifact with lineage; only after full closure (caller ensures)."""
|
|
lineage = ToolpathLineage(
|
|
toolpath_ref=artifact_id,
|
|
geometry_ref=geometry_ref,
|
|
intent_ref=intent_ref,
|
|
requirement_ref=requirement_ref,
|
|
)
|
|
artifact = ToolpathArtifact(
|
|
artifact_id=artifact_id,
|
|
artifact_type=artifact_type,
|
|
content_ref=content_ref,
|
|
lineage=lineage,
|
|
metadata=metadata or {},
|
|
)
|
|
self._artifacts[artifact_id] = artifact
|
|
return artifact
|
|
|
|
def get(self, artifact_id: str) -> ToolpathArtifact | None:
|
|
"""Return artifact by id or None."""
|
|
return self._artifacts.get(artifact_id)
|