Desktop app for designing parametric 3D models in CadQuery together with the coding agent of your choice
TypeScript 3d-modeling3d-printing3d-printing-toolsagentagentic-aiai-cadcadcadqueryclaude-codecodexelectronfemllmmacdmakeropencodeparametric-designpythonsteptext-to-cad
soma: render findet die App über bridge.json, build weist auf fremde Shell hin
Kai-Jungsthoefel3fdc198ec948
diff --git a/python/soma/cli.py b/python/soma/cli.pyindex 650a76b..42ab08c 100644--- a/python/soma/cli.py+++ b/python/soma/cli.py@@ -41,10 +41,38 @@ def _print_build(res, as_json, seconds):print("Warning:", w, file=sys.stderr)+def _foreign_shell_note(project):+ """Hinweis, wenn `soma` in einem Arbeitsordner der App laeuft, aber nicht mit der Umgebung ihrer Terminals.++ Manche Agenten (Codex) fuehren Befehle ueber einen Hintergrunddienst mit der Umgebung eines anderen Programms aus:+ `soma` und `pip` fehlen dort im PATH oder sind fremde, `pip install` landete nicht in der Projektumgebung.+ """+ from .render import bridge_file+ root = Path(project).resolve()+ if bridge_file(root) is None:+ return None # kein Arbeitsordner der laufenden App+ mine = os.environ.get("SOMA_PROJECT")+ try:+ if mine and Path(mine).resolve() == root:+ return None+ except OSError:+ pass+ py = Path(".soma", "env", "Scripts", "python.exe") if os.name == "nt" else Path(".soma", "env", "bin", "python")+ if not (root / py).is_file():+ py = Path(sys.executable)+ note = (f"Note: this shell does not have the environment of the app's terminals. Run soma as `{py} -m soma ...` "+ f"and install packages only with `{py} -m pip install ...`.")+ skill = root / ".soma" / "skills" / "shell-environment.md"+ return note + (" Details: .soma/skills/shell-environment.md" if skill.is_file() else "")++def cmd_build(args):from . import buildres = build.run_build(args.project)_print_build(res, args.json, time.perf_counter() - _STARTED)+ note = None if args.json else _foreign_shell_note(args.project)+ if note:+ print(note)# Das Aufraeumen von OCP und vtk beim normalen Beenden kostet fast eine Sekunde und bringt nichts:# alle Dateien sind geschrieben und geschlossen, also Puffer leeren und sofort beendensys.stdout.flush()diff --git a/python/soma/render.py b/python/soma/render.pyindex d587270..2d6149f 100644--- a/python/soma/render.py+++ b/python/soma/render.py@@ -2,7 +2,8 @@Die App zeichnet mit demselben Viewer wie auf dem Bildschirm, in einem unsichtbaren Fenster. Dieser Befehl bereitet denAuftrag vor (Animation bauen, Ergebnis suchen) und schickt ihn ueber eine lokale Verbindung an die App. Die Adresse und-ein Schluessel stehen in den Umgebungsvariablen der Terminals der App (SOMA_APP, SOMA_APP_TOKEN).+ein Schluessel stehen in den Umgebungsvariablen der Terminals der App (SOMA_APP, SOMA_APP_TOKEN). Fehlen sie (Agenten+wie Codex fuehren Befehle teils mit fremder Umgebung aus), gilt `bridge.json` in den App-Daten, neben `workspaces/`."""import http.clientimport json@@ -136,12 +137,35 @@ def prepare(root, args):return job+def bridge_file(root):+ """`bridge.json` der App, wenn `root` ein Arbeitsordner der App ist (<App-Daten>/workspaces/<id>), sonst None."""+ root = Path(root).resolve()+ if root.parent.name.lower() != "workspaces":+ return None+ f = root.parent.parent / "bridge.json"+ return f if f.is_file() else None+++def _connection(project):+ """Adresse und Schluessel: aus der Umgebung, sonst aus `bridge.json` der App."""+ addr, token = os.environ.get("SOMA_APP"), os.environ.get("SOMA_APP_TOKEN")+ if addr and token:+ return addr, token+ f = bridge_file(project)+ if f:+ try:+ data = json.loads(f.read_text(encoding="utf-8"))+ if data.get("app") and data.get("token"):+ return str(data["app"]), str(data["token"])+ except (OSError, ValueError):+ pass+ raise RenderError("soma render needs the running app: open this model in SOMA and run the command in its folder "+ "(the app's terminals have the connection in SOMA_APP and SOMA_APP_TOKEN).")++def send(job, timeout=900):"""Schickt den Auftrag an die App und wartet auf das Ergebnis."""- addr, token = os.environ.get("SOMA_APP"), os.environ.get("SOMA_APP_TOKEN")- if not addr or not token:- raise RenderError("soma render needs the running app: run the command in a terminal of the app "- "(SOMA_APP and SOMA_APP_TOKEN are set there).")+ addr, token = _connection(job["project"])host, _, port = addr.rpartition(":")try:conn = http.client.HTTPConnection(host or "127.0.0.1", int(port), timeout=timeout)