replicator-workshop 0.1.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 (118) hide show
  1. replicator/__init__.py +6 -0
  2. replicator/app.py +204 -0
  3. replicator/config.py +48 -0
  4. replicator/core/__init__.py +0 -0
  5. replicator/core/assembly.py +117 -0
  6. replicator/core/blender_link.py +161 -0
  7. replicator/core/critique.py +594 -0
  8. replicator/core/drawing.py +389 -0
  9. replicator/core/dxf.py +120 -0
  10. replicator/core/evaluate.py +439 -0
  11. replicator/core/explain.py +139 -0
  12. replicator/core/export.py +96 -0
  13. replicator/core/fit.py +170 -0
  14. replicator/core/importers.py +185 -0
  15. replicator/core/materials.py +104 -0
  16. replicator/core/ops_advanced.py +496 -0
  17. replicator/core/ops_engineering.py +223 -0
  18. replicator/core/physics.py +147 -0
  19. replicator/core/printers.py +100 -0
  20. replicator/core/program.py +298 -0
  21. replicator/core/render.py +145 -0
  22. replicator/core/reverse.py +350 -0
  23. replicator/core/robot.py +153 -0
  24. replicator/core/step.py +245 -0
  25. replicator/fixtures/gaming_pc_liquid.json +2259 -0
  26. replicator/fixtures/gas_generator_rocket.json +876 -0
  27. replicator/fixtures/gas_generator_rocket_aero.json +861 -0
  28. replicator/fixtures/house_two_bed.json +979 -0
  29. replicator/fixtures/quadcopter_drone.json +687 -0
  30. replicator/fixtures/raspberry_pi_5.json +884 -0
  31. replicator/fixtures/rocket_engine.json +652 -0
  32. replicator/fixtures/turbofan.json +931 -0
  33. replicator/fixtures/vector_engine.json +314 -0
  34. replicator/gpu.py +81 -0
  35. replicator/image3d/__init__.py +0 -0
  36. replicator/image3d/comfy.py +181 -0
  37. replicator/image3d/pipeline.py +208 -0
  38. replicator/image3d/sheet.py +154 -0
  39. replicator/knowledge/__init__.py +61 -0
  40. replicator/knowledge/car_wheel_corner.md +21 -0
  41. replicator/knowledge/desk_lamp.md +21 -0
  42. replicator/knowledge/desktop_pc.md +20 -0
  43. replicator/knowledge/electronics_board.md +21 -0
  44. replicator/knowledge/exoskeleton.md +21 -0
  45. replicator/knowledge/house.md +22 -0
  46. replicator/knowledge/light_aircraft.md +22 -0
  47. replicator/knowledge/multirotor_drone.md +25 -0
  48. replicator/knowledge/print_replica.md +13 -0
  49. replicator/knowledge/rocket_engine.md +27 -0
  50. replicator/knowledge/turbofan.md +23 -0
  51. replicator/llm/__init__.py +0 -0
  52. replicator/llm/client.py +424 -0
  53. replicator/llm/prompts/blueprint.md +28 -0
  54. replicator/llm/prompts/edit.md +15 -0
  55. replicator/llm/prompts/explain.md +37 -0
  56. replicator/llm/prompts/name_parts.md +13 -0
  57. replicator/llm/prompts/program.md +72 -0
  58. replicator/llm/prompts/research_queries.md +8 -0
  59. replicator/mcp_server.py +307 -0
  60. replicator/qml/Main.qml +874 -0
  61. replicator/qml/Replicator/UI/Chip.qml +17 -0
  62. replicator/qml/Replicator/UI/DockHeader.qml +27 -0
  63. replicator/qml/Replicator/UI/Icon.qml +118 -0
  64. replicator/qml/Replicator/UI/IconButton.qml +31 -0
  65. replicator/qml/Replicator/UI/Kbd.qml +18 -0
  66. replicator/qml/Replicator/UI/NumField.qml +69 -0
  67. replicator/qml/Replicator/UI/Pill.qml +28 -0
  68. replicator/qml/Replicator/UI/RCombo.qml +51 -0
  69. replicator/qml/Replicator/UI/RMenu.qml +42 -0
  70. replicator/qml/Replicator/UI/RSlider.qml +23 -0
  71. replicator/qml/Replicator/UI/Segmented.qml +63 -0
  72. replicator/qml/Replicator/UI/Swatch.qml +47 -0
  73. replicator/qml/Replicator/UI/Theme.qml +149 -0
  74. replicator/qml/Replicator/UI/qmldir +14 -0
  75. replicator/qml/panels/AgentPrompt.qml +53 -0
  76. replicator/qml/panels/AttributeManager.qml +171 -0
  77. replicator/qml/panels/Commander.qml +136 -0
  78. replicator/qml/panels/HolodeckPanel.qml +117 -0
  79. replicator/qml/panels/IssuesCard.qml +78 -0
  80. replicator/qml/panels/LedgerPanel.qml +110 -0
  81. replicator/qml/panels/MaterialShelf.qml +97 -0
  82. replicator/qml/panels/ObjectManager.qml +107 -0
  83. replicator/qml/panels/Preferences.qml +211 -0
  84. replicator/qml/panels/Presenter.qml +316 -0
  85. replicator/qml/panels/StatusBar.qml +77 -0
  86. replicator/qml/panels/Timeline.qml +149 -0
  87. replicator/qml/panels/Welcome.qml +126 -0
  88. replicator/qml/viewport/Callouts.qml +87 -0
  89. replicator/qml/viewport/EdgeMaterial.qml +16 -0
  90. replicator/qml/viewport/GridMaterial.qml +16 -0
  91. replicator/qml/viewport/HoloMaterial.qml +23 -0
  92. replicator/qml/viewport/NavGizmo.qml +72 -0
  93. replicator/qml/viewport/ReferenceMaterial.qml +17 -0
  94. replicator/qml/viewport/Viewport.qml +583 -0
  95. replicator/qt/__init__.py +0 -0
  96. replicator/qt/bridge.py +1427 -0
  97. replicator/qt/drawing_sheet.py +33 -0
  98. replicator/qt/envmap.py +40 -0
  99. replicator/qt/library.py +68 -0
  100. replicator/qt/mesh_geometry.py +167 -0
  101. replicator/qt/svg.py +41 -0
  102. replicator/research/__init__.py +0 -0
  103. replicator/research/lane.py +281 -0
  104. replicator/shaders/edge.frag +9 -0
  105. replicator/shaders/edge.vert +7 -0
  106. replicator/shaders/grid.frag +52 -0
  107. replicator/shaders/grid.vert +6 -0
  108. replicator/shaders/holo.frag +41 -0
  109. replicator/shaders/reference.frag +15 -0
  110. replicator/shaders/reference.vert +6 -0
  111. replicator/voice.py +120 -0
  112. replicator_workshop-0.1.0.dist-info/METADATA +410 -0
  113. replicator_workshop-0.1.0.dist-info/RECORD +118 -0
  114. replicator_workshop-0.1.0.dist-info/WHEEL +5 -0
  115. replicator_workshop-0.1.0.dist-info/entry_points.txt +3 -0
  116. replicator_workshop-0.1.0.dist-info/licenses/LICENSE +21 -0
  117. replicator_workshop-0.1.0.dist-info/licenses/vendor/mcp-for-blender/LICENSE +21 -0
  118. replicator_workshop-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,8 @@
1
+ Someone wants to understand or design this object: {{SUBJECT}}
2
+ Its parts: {{PARTS}}
3
+
4
+ It may be fictional. Name the real-world machines, mechanisms and physical principles it is closest to, as search
5
+ queries for an encyclopedia. Use the names an engineer would look up ("thrust reversal", "involute gear",
6
+ "regenerative cooling"), never the fictional name. 3 or 4 queries, 2 to 5 words each.
7
+
8
+ Reply with ONE ```json block: ["query one", "query two", "query three"]
@@ -0,0 +1,307 @@
1
+ """Replicator as an MCP server: any agent (Claude Code, Codex, Cursor, a lab's own harness) can read, edit, build, check,
2
+ draw and export a BuildProgram, and ask the local models to specify a new one.
3
+
4
+ .venv/bin/python -m replicator.mcp_server # stdio, for an agent's MCP config
5
+
6
+ The document is a program file on disk. Every write is validated and built before it replaces the file, so an agent
7
+ can never leave a broken program behind; the previous version is kept beside it as <name>.prev.json. A Replicator
8
+ window that has the same file open reloads it on change, so the timeline shows the agent's edits as they land.
9
+ Nothing here opens a GPU context: building, checks, drawings and STEP run on the CPU.
10
+ """
11
+ from __future__ import annotations
12
+
13
+ import json
14
+ import os
15
+ import time
16
+ from pathlib import Path
17
+
18
+ os.environ.setdefault("CUDA_VISIBLE_DEVICES", "") # a GPU is left to the model server
19
+
20
+ from mcp.server import MCPServer # noqa: E402
21
+
22
+ from . import config # noqa: E402
23
+ from .core import assembly, critique, fit, physics # noqa: E402
24
+ from .core import printers as printers_mod # noqa: E402 (the `printers` tool name takes the bare one)
25
+ from .core import export as exporter # noqa: E402
26
+ from .core.evaluate import EvalError, Evaluator, bounds # noqa: E402
27
+ from .core.program import ProgramError, apply_patch, check, scale_program # noqa: E402
28
+
29
+ mcp = MCPServer("replicator", instructions=(
30
+ "Replicator builds physical things from a BuildProgram: a JSON document of typed ops (primitives, modifiers, "
31
+ "combiners, placement, engineering ops such as nozzle, rotor, wing, gear) evaluated into exact solids. "
32
+ "It covers houses and floor plans, electronics, household objects, engines, aircraft and concepts. "
33
+ "Start with `op_reference`, read a program with `read_program`, change it with `patch_program` (RFC 6902 JSON "
34
+ "Patch; rejected patches leave the file untouched), and confirm with `build_report`, which returns size, mass, "
35
+ "parts and every accuracy issue. `specify` asks the local models for a new program from a description. "
36
+ "To print: `printers` lists the catalog and the active bed, `fit_check` measures a build against a bed and "
37
+ "suggests the scale and orientation that fit, and `scale_for_printer` writes a scaled copy of the program that "
38
+ "fits the bed. Nothing is ever clipped: an oversized print is refused with the overflow per axis."))
39
+
40
+
41
+ def _path(p: str) -> Path:
42
+ """Resolve a path an agent named. With REPLICATOR_MCP_ROOT set, a path outside that folder is refused."""
43
+ path = Path(p).expanduser().resolve()
44
+ root = os.environ.get("REPLICATOR_MCP_ROOT", "")
45
+ if root:
46
+ r = Path(root).expanduser().resolve()
47
+ if path != r and r not in path.parents:
48
+ raise PermissionError(f"{p} is outside REPLICATOR_MCP_ROOT ({r})")
49
+ return path
50
+
51
+
52
+ def _report(program: dict, root: Path, step: int = -1) -> dict:
53
+ t0 = time.perf_counter()
54
+ prog = dict(program, ops=program["ops"][: step + 1]) if step >= 0 else program
55
+ shapes = Evaluator(root).step(prog)
56
+ ms = (time.perf_counter() - t0) * 1000
57
+ comps = assembly.components(prog, shapes)
58
+ mass = physics.properties(prog, shapes)
59
+ issues = critique.critique(prog, shapes, comps)
60
+ lo, hi = bounds(shapes) if shapes else ([0, 0, 0], [0, 0, 0])
61
+ return {
62
+ "name": prog.get("name", ""), "units": prog.get("units", "mm"), "ops": len(prog["ops"]),
63
+ "total_ops": len(program["ops"]), "parts": len(shapes), "build_ms": round(ms),
64
+ "size": [round(float(hi[i] - lo[i]), 3) for i in range(3)],
65
+ "mass_kg": round(mass.kg, 4), "mass_assumed": mass.assumed,
66
+ "components": [{"id": c.id, "label": c.label, "parts": len(c.shapes)} for c in comps],
67
+ "issues": [i.as_dict() for i in issues],
68
+ "blocking": len(critique.blocking(issues)),
69
+ }
70
+
71
+
72
+ def _load(path: Path) -> dict:
73
+ return check(json.loads(path.read_text()))
74
+
75
+
76
+ def _commit(path: Path, program: dict) -> dict:
77
+ """Validate and build, then write atomically, keeping the old file as .prev.json."""
78
+ program = check(program)
79
+ report = _report(program, path.parent)
80
+ if path.exists():
81
+ path.with_suffix(".prev.json").write_text(path.read_text())
82
+ tmp = path.with_suffix(".tmp")
83
+ tmp.write_text(json.dumps(program, indent=1))
84
+ tmp.replace(path)
85
+ return report
86
+
87
+
88
+ def _err(e: Exception) -> dict:
89
+ return {"ok": False, "error": f"{type(e).__name__}: {e}"}
90
+
91
+
92
+ @mcp.tool()
93
+ def op_reference() -> str:
94
+ """The BuildProgram op vocabulary: every op, its kind, and its required and optional fields."""
95
+ from .llm.client import op_reference as ref
96
+ return ('Program: {"version": 1, "name": str, "units": "mm", "materials": {name: {"base_color": [r,g,b], '
97
+ '"metalness", "roughness", "opacity"}}, "ops": [op, ...]}. Y is up.\n'
98
+ 'Op: {"id": str, "op": kind, "label": str, "part": str, "component": str, "material": name, '
99
+ '"params": {...the fields below, plus "translate": [x,y,z], "rotate": [deg,deg,deg], "scale"}, '
100
+ '"input": id (modifiers) or "inputs": [ids] (combiners)}. A consumed input stops being visible.\n'
101
+ 'Example: {"id": "boss", "op": "cylinder", "material": "alu", "params": {"radius": 17, "height": 3, '
102
+ '"translate": [81, 24.5, 81]}}\n\n' + ref())
103
+
104
+
105
+ @mcp.tool()
106
+ def read_program(path: str) -> dict:
107
+ """Read a BuildProgram file (validated)."""
108
+ try:
109
+ return {"ok": True, "program": _load(_path(path))}
110
+ except (OSError, json.JSONDecodeError, ProgramError) as e:
111
+ return _err(e)
112
+
113
+
114
+ @mcp.tool()
115
+ def write_program(path: str, program: dict) -> dict:
116
+ """Create or replace a BuildProgram file. Rejected (file untouched) unless it validates and builds."""
117
+ try:
118
+ p = _path(path)
119
+ p.parent.mkdir(parents=True, exist_ok=True)
120
+ return {"ok": True, "report": _commit(p, program)}
121
+ except (OSError, ProgramError, EvalError, ValueError) as e:
122
+ return _err(e)
123
+
124
+
125
+ @mcp.tool()
126
+ def patch_program(path: str, patch: list[dict]) -> dict:
127
+ """Apply an RFC 6902 JSON Patch to a program, e.g. [{"op": "replace", "path": "/ops/3/radius", "value": 12}].
128
+ Rejected (file untouched) unless the result validates and builds; returns the new build report."""
129
+ try:
130
+ p = _path(path)
131
+ return {"ok": True, "report": _commit(p, apply_patch(_load(p), patch))}
132
+ except (OSError, json.JSONDecodeError, ProgramError, EvalError, ValueError) as e:
133
+ return _err(e)
134
+
135
+
136
+ @mcp.tool()
137
+ def build_report(path: str, step: int = -1) -> dict:
138
+ """Build a program (or only ops 0..step) and report size, mass, components and every accuracy issue.
139
+ `blocking` > 0 means a check found something that must be fixed."""
140
+ try:
141
+ p = _path(path)
142
+ return {"ok": True, "report": _report(_load(p), p.parent, step)}
143
+ except (OSError, json.JSONDecodeError, ProgramError, EvalError) as e:
144
+ return _err(e)
145
+
146
+
147
+ @mcp.tool()
148
+ def export(path: str, out: str) -> dict:
149
+ """Export a program's solids. Format from the extension: .step/.stp (faceted B-rep for CAD), .stl and .3mf
150
+ (printers, Z-up, watertight only), .glb, .obj, .dxf (the drawing's views at full size in model units, for CAD and laser), or a simulator model: .urdf, or .xml/.mjcf for MuJoCo (one link per
151
+ component, mass and inertia from the exact solid, meshes/ written beside it)."""
152
+ try:
153
+ p, o = _path(path), _path(out)
154
+ program = _load(p)
155
+ o.parent.mkdir(parents=True, exist_ok=True)
156
+ shapes = Evaluator(p.parent).step(program)
157
+ if o.suffix.lower() == ".dxf":
158
+ from .core import dxf
159
+ dxf.write(shapes, o, program.get("units", "mm"))
160
+ return {"ok": True, "file": str(o), "bytes": o.stat().st_size}
161
+ if o.suffix.lower() in (".urdf", ".xml", ".mjcf"):
162
+ from .core import robot
163
+ f = robot.write(program, shapes, o)
164
+ return {"ok": True, "file": str(f), "meshes": str(f.parent / "meshes"), "bytes": f.stat().st_size}
165
+ exporter.export(shapes, program.get("materials", {}), o, name=program.get("name", p.stem),
166
+ units=program.get("units", "mm"))
167
+ return {"ok": True, "file": str(o), "bytes": o.stat().st_size}
168
+ except (OSError, json.JSONDecodeError, ProgramError, EvalError, ValueError) as e:
169
+ return _err(e)
170
+
171
+
172
+ def _printer(printer_id: str, cfg: dict):
173
+ """Named printer (catalog, then saved profiles), else the active one. Raises when none is usable."""
174
+ if printer_id:
175
+ if printer_id in printers_mod.CATALOG:
176
+ return printers_mod.CATALOG[printer_id]
177
+ for p in printers_mod.configured(cfg):
178
+ if p.id == printer_id:
179
+ return p
180
+ raise ValueError(f"printer {printer_id!r} is not in the catalog or saved profiles (see `printers`)")
181
+ p = printers_mod.active(cfg)
182
+ if p is None:
183
+ raise ValueError("no printer: pass printer_id (see `printers`) or set active_printer in services.json")
184
+ return p
185
+
186
+
187
+ def _fit_fields(f) -> dict:
188
+ return {"fits": f.fits, "scale": f.scale, "orientation": f.orientation, "size": list(f.size),
189
+ "usable": list(f.usable), "clearance": list(f.clearance), "overflow": list(f.overflow)}
190
+
191
+
192
+ @mcp.tool()
193
+ def printers() -> dict:
194
+ """The printer catalog (Bambu Lab models, published build volumes to verify on the device), the
195
+ profiles saved in services.json, and the active printer with its usable build volume."""
196
+ try:
197
+ cfg = config.load()
198
+ active = printers_mod.active(cfg)
199
+ return {"ok": True,
200
+ "catalog": [p.as_dict() for p in printers_mod.CATALOG.values()],
201
+ "saved": [p.as_dict() for p in printers_mod.configured(cfg)],
202
+ "active": active.as_dict() if active else None}
203
+ except (OSError, ValueError) as e:
204
+ return _err(e)
205
+
206
+
207
+ @mcp.tool()
208
+ def fit_check(path: str, printer_id: str = "", scale: float = 1.0) -> dict:
209
+ """Does the build fit the printer's bed (active printer when printer_id is empty)? Size in the
210
+ print frame (Z up, mm), clearance or overflow per axis, plus the best orientation at scale 1 and
211
+ the largest scale that fits."""
212
+ try:
213
+ p = _path(path)
214
+ program = _load(p)
215
+ shapes = Evaluator(p.parent).step(program)
216
+ units = program.get("units", "mm")
217
+ printer = _printer(printer_id, config.load())
218
+ f = fit.check(shapes, units, printer, scale=scale)
219
+ return {"ok": True, "printer": printer.id, "name": printer.name, "scale": scale,
220
+ **_fit_fields(f),
221
+ "best_orientation": _fit_fields(fit.best_orientation(shapes, units, printer)),
222
+ "scale_to_fit": _fit_fields(fit.scale_to_fit(shapes, units, printer))}
223
+ except (OSError, json.JSONDecodeError, ProgramError, EvalError, ValueError) as e:
224
+ return _err(e)
225
+
226
+
227
+ @mcp.tool()
228
+ def scale_for_printer(path: str, out: str, printer_id: str = "", preset: str = "fit") -> dict:
229
+ """Write `out` as a scaled copy of the program sized for the printer (active when printer_id is
230
+ empty). preset: 1:1, 1:<n>, fit (largest factor the as-built build takes on the bed) or height:<mm>.
231
+ Rejected (nothing written) unless the scaled build passes the fit check; returns the factor and
232
+ the final print-frame size."""
233
+ try:
234
+ p, o = _path(path), _path(out)
235
+ program = _load(p)
236
+ shapes = Evaluator(p.parent).step(program)
237
+ units = program.get("units", "mm")
238
+ printer = _printer(printer_id, config.load())
239
+ factor = fit.replica_scale(preset, shapes, units, printer)
240
+ scaled = scale_program(program, factor)
241
+ f = fit.check(Evaluator(o.parent).step(scaled), units, printer)
242
+ if not f.fits:
243
+ over = ", ".join(f"{ax} by {v:.1f} mm" for ax, v in zip(fit.AXES, f.overflow) if v > 0)
244
+ raise ValueError(f"{printer.name} ({printer.id}): the {preset} build still overflows {over}; "
245
+ f"use a smaller preset or a bigger bed")
246
+ o.parent.mkdir(parents=True, exist_ok=True)
247
+ o.write_text(json.dumps(scaled, indent=1))
248
+ return {"ok": True, "file": str(o), "printer": printer.id, "factor": factor,
249
+ "size": list(f.size), "orientation": f.orientation}
250
+ except (OSError, json.JSONDecodeError, ProgramError, EvalError, ValueError) as e:
251
+ return _err(e)
252
+
253
+
254
+ @mcp.tool()
255
+ def drawing_sheet(path: str, out_dir: str, style: str = "blueprint") -> dict:
256
+ """Draw an A3 sheet: third-angle views, section or floor plan, measured dimensions, numbered parts list with
257
+ computed masses. Writes SVG and PNG. style: blueprint or paper."""
258
+ from .qt.drawing_sheet import make
259
+ try:
260
+ svg, png, seconds = make(_path(path), _path(out_dir), style)
261
+ return {"ok": True, "svg": str(svg), "png": str(png), "seconds": round(seconds, 2)}
262
+ except (OSError, json.JSONDecodeError, ProgramError, EvalError, ValueError) as e:
263
+ return _err(e)
264
+
265
+
266
+ @mcp.tool()
267
+ def specify(description: str, out: str, engine: str = "") -> dict:
268
+ """Ask the local models for a new BuildProgram from a description (blueprint, program, repair and critique
269
+ rounds; takes minutes). Writes it to `out` only if it validates and builds. engine: empty for the default
270
+ (`default_engine` in services.json, else "local"), or any name `engines` lists."""
271
+ from .llm import client
272
+ log: list[str] = []
273
+ try:
274
+ program = client.dream(description, engine, log=log.append)
275
+ return {"ok": True, "report": _commit(_path(out), program), "log": log[-20:]}
276
+ except Exception as e: # noqa: BLE001 - a model failure is reported to the agent, the server stays up
277
+ return dict(_err(e), log=log[-20:])
278
+
279
+
280
+ @mcp.tool()
281
+ def engines() -> dict:
282
+ """The model engines `specify` can use: name -> model and chat URL ("local" plus configured endpoints)."""
283
+ from .llm import client
284
+ return {k: {"model": m, "url": u, "needs_key": bool(env) and not env.startswith("?")} for k, (u, m, _, env) in client.engines().items()}
285
+
286
+
287
+ @mcp.tool()
288
+ def reverse(mesh: str, out: str) -> dict:
289
+ """Take an existing model (STL, OBJ, GLB, STEP, IGES and ~25 more) apart into a BuildProgram of its pieces, with
290
+ a ledger tagging every claim observed, inferred or unknown. Piece geometry goes to <out dir>/assets/."""
291
+ from .core import reverse as rev
292
+ try:
293
+ o = _path(out)
294
+ o.parent.mkdir(parents=True, exist_ok=True)
295
+ program, report = rev.analyze_mesh(_path(mesh), o.parent)
296
+ o.write_text(json.dumps(program, indent=1))
297
+ return {"ok": True, "program": str(o), "report": report}
298
+ except Exception as e: # noqa: BLE001
299
+ return _err(e)
300
+
301
+
302
+ def main() -> None:
303
+ mcp.run()
304
+
305
+
306
+ if __name__ == "__main__":
307
+ main()