@diatechai/cad
v0.2.4
Published
Render Diatech CAD (DiaScript) designs on your own machine instead of on the server.
Readme
@diatechai/cad — the headless viewport
An AI agent connects to Diatech CAD by pasting one URL into its custom-connector settings, and without this package every step of every render happens on our server: the compile, the booleans and the picture. Only the first of those is ours to do. The editor has run the rest in the browser for a long time — that code is not the CAD kernel, and this package is that same code on the command line.
DIATECH_URL=https://cad.diatech.ai DIATECH_TOKEN=… \
npx -y @diatechai/cad@latest render design.ds --view hero --out render.pngCall the diascript_setup MCP tool for the URL and a token; it is the only
place they come from, and it prints this exact line.
What runs where
The server parses, resolves and evaluates the design — the kernel, the stone
packing, the report — over the editor's own compile socket (/api/compile,
your token in the Authorization header). It answers with what it answers the
editor's viewport with: meshes, and recipes naming geometry to build locally
— a mesh Boolean arrives as its ordered steps over lossless operand meshes. An
expensive Boolean it needs mid-compile it asks this machine for, and checks
what comes back. This package then does what the browser does.
| | server | here | |---|---|---| | parse → resolve → kernel | ● | | | B-Rep → triangles | ● | | | metal weight, stone table | ● | | | mesh Booleans (drills, cutters, unions) | | ● | | instancing, grouping | | ● | | shading and the PNG | | ● |
The Booleans are manifold-3d — the same WASM build and release the editor and
the server load, run by the editor's own module rather than a re-implementation.
One that fails fails the render; it is never drawn as its overlapping operands.
Nothing here can build CAD geometry from a design; it draws triangles the server
sent.
Commands
cad render <file.ds> [--view hero] [--out render.png] [--size 512] [--server]
cad report <file.ds> [--server]--view takes hero, front, right, top or iso, and repeats: several
angles cost one compile, one download and one composition between them, so ask
for them together.
report prints the metal weight, the stone table and the overall size — the
numbers a picture cannot carry, in the summary diascript_render returns
(bounds_mm.size, metal, stones, and warnings apart from errors). A
render is auto-framed, so a 17 mm ring and a 170 mm one make the same image and
only the bounding box catches it. It is a
separate compile on purpose: the render build defers exactly the cuts this
package performs, so a weight taken from it would be the weight of the uncut
body. The Booleans a report needs are the ones a render just computed and
kept, so it reads "authority": "client_mesh".
--server has the server compute every Boolean itself — an authoritative
report, or a render of what the server carves. It is also the answer when a
Boolean fails on this machine, whether the server asked for it or the render
composes it: the command prints the failure and says to rerun with --server,
and never does so on its own.
The cache
Every node the server sends carries a content hash, and each render lists the
hashes this machine already holds. The server then sends only what changed —
after an edit that is usually one node. Each Boolean's result is kept too, so
an unchanged one is not recomputed and a report can name it instead of
resending its operands. The files live in $DIATECH_CACHE_DIR, or
~/.cache/diatech-cad, and the directory is bounded; deleting it costs one
slower render. Only keys in the shapes the server mints ever become filenames;
a write lands whole or not at all, and a file that does not decode is deleted
and fetched or computed again.
Refusals and retries
A refused compile prints {"ok": false, "error", "message", …} and exits 1,
whether the server refused the connection (401 sign-in, 403 subscription, 409
seat) or ended it. When every compile slot of the account is busy (429) the
command waits out Retry-After and reconnects for up to a minute first. It
retries nothing else. A server that never answers the upgrade (30 s), or goes
silent mid-compile (300 s without a frame or a ping), is a network error.
Limits
A local render is a preview: auto-framed, flat-shaded, screen tessellation.
Metal reflects the viewer's light tent; stones stay on a separate, faceted light.
Manufacturing files are server exports. If the server does not speak this
package's compile protocol (dscad.compile.v1), the socket does not open, and
if it answers with a payload protocol this package does not know, it refuses
rather than drawing geometry it may read wrongly — upgrade with
npx -y @diatechai/cad@latest, or fall back to the diascript_render MCP tool.
