dsh-cad 0.12.2 → 0.13.1

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.
package/README.md CHANGED
@@ -1,270 +1,272 @@
1
- # dsh-cad — CAD Plugin for DeepSeek Harness
2
-
3
- ![dsh-cad banner](docs/img/banner.svg)
4
-
5
- [![homepage](https://img.shields.io/badge/homepage-dsh--cad-4D6BFE)](https://lau-mars.github.io/dsh-cad/)
6
- [![npm](https://img.shields.io/npm/v/dsh-cad)](https://www.npmjs.com/package/dsh-cad)
7
- [![dsh](https://img.shields.io/npm/v/@deepseek-ai%2Fdsh?label=dsh)](https://www.npmjs.com/package/@deepseek-ai/dsh)
8
- [![Node](https://img.shields.io/badge/node-%3E%3D%2022-4D6BFE)](https://nodejs.org/)
9
- [![occt.ts](https://img.shields.io/npm/v/occt.ts)](https://www.npmjs.com/package/occt.ts)
10
- [![ansatz](https://img.shields.io/npm/v/ansatz-wasm?label=ansatz)](https://www.npmjs.com/package/ansatz-wasm)
11
- [![License: MIT](https://img.shields.io/badge/license-MIT-4D6BFE)](./LICENSE)
12
-
13
- English | [简体中文](./README.zh-CN.md)
14
-
15
- A CAD plugin for [DeepSeek Harness (dsh)](https://github.com/deepseek-ai/deepseek-harness):
16
- an **embedded 3D/2D CAD viewer** plus a **native parametric modeling tool family**
17
- (OCCT kernel) in the Web UI, letting the agent build and inspect CAD geometry
18
- step by step — "model while you watch".
19
-
20
- ## Preview
21
-
22
- A full modeling session, end to end: the agent builds a parametric assembly
23
- from plain chat — a 120×80×8 base plate with R5 rounded corners, then four
24
- bolt instances placed at the corners — while the resident CAD panel tracks
25
- every step live (parts tree with per-instance colors, ViewCube, "装配体"
26
- assembly tab, 5 instances · 1,740 triangles). The finished assembly exports
27
- as a structured STEP document and the agent verifies it by reading the file
28
- back — 2 solids, 3 products, 2 assembly usages, 1,125.00 mm³:
29
-
30
- ![dsh-cad assembly session](docs/img/assembly-preview.png)
31
-
32
- ## Feature Overview
33
-
34
- | Capability | Description |
35
- | --- | --- |
36
- | ⚙️ Single-kernel architecture | **occt.ts as the primary modeling kernel** (true B-splines, native shell/draft, centroid); opencascade.js stays only as the fallback backend; the old "no editing after shell" seam is gone — fillet/chamfer/boolean keep working after shelling |
37
- | 🔍 CAD viewing | STL / OBJ / STEP / IGES / BREP / DCPRT (3D), DXF / SVG (2D); interactive in-chat card (orbit / zoom / wireframe / pan) |
38
- | 🧭 CAD editor interactions | Onshape-style ViewCube (26-zone click-to-orient), hover/click face & edge picking with live measurement (area mm² / length mm), Faces+Edges / Faces / Wireframe render modes, switchable BRep demo parts (bracket / flange / shaft) |
39
- | 🏗️ Parametric modeling | Primitives, profile extrusion, **loft**, **sweep**, **revolve**, booleans, all-edge fillet/chamfer, **shell**, **draft**, **patterns** (linear/circular), transforms; profiles take **curve segments** (arcs/circles exact BRep; B-splines sampled approximation) — exact OCCT BRep, not a mesh approximation |
40
- | ✏️ Named sketches | Standalone named profiles (Sketch1…) kept in the document (`cad_sketch_new` / `edit` / `list` / `delete`); extrude/revolve/sweep reference them **by name**, and `cad_sketch_edit` rewrites the definition in place + replays the log, rebuilding every dependent feature — the parametric loop. Sketches render as Onshape-style **blue curves + plane frame** in the viewport (refreshing live on edit), listed in a left-side **feature tree** (sketches + features, eye-toggle visibility, click-to-highlight bodies) over the Part tab |
41
- | 🗂️ Codex-style document tabs | The resident display panel gets a tab strip with a "+" menu: **Part** (Part Studio, the default) / **Assembly** (instance insert/move/remove) / **Drawing** (true hidden-line sheets); tabs are closable and keep their state |
42
- | 📁 Multi-document file space | Named documents per workspace (`.dsh-cad/docs/`), each session bound to its own active document — new sessions start empty instead of inheriting leftovers; a folder button in the panel lists every document (preview / delete), and `cad_doc_new` / `cad_doc_open` manage the modeling target from chat |
43
- | 📐 Engineering drawings | GB first-angle layout: front / top / left views + isometric, true OCCT hidden-line removal via the **occt.ts** kernel (an npm dependency, dashed); sheet frame, title block, overall dimensions, standard scale series; exports SVG / DXF |
44
- | 🔗 Constraint solving & motion | **Ansatz** geometric constraint solver (**one command: `npm install ansatz-wasm`** — a wasm dependency, no Rust toolchain, no native binary): entity/constraint modeling (assembly instances ↔ rigid3 poses mapped automatically), solve-with-writeback, full DOF/residual/redundancy/suggestion diagnostics (LLM-oriented), and parametric kinematic sweeps (`cad_constraint` / `cad_solve` / `cad_motion`) |
45
- | 📐 Geometry measurement | Exact volume (mm³), bounding box, triangle counts, DXF layers |
46
- | 📤 On-demand export | STEP (parametric) / STL (mesh); files are written only when the user asks |
47
- | 🖥️ Resident CAD panel | A permanent panel right of the conversation: Codex-style tabs (Part / Assembly / Drawing), tracking the latest model in real time while modeling |
48
- | ⚡ Zero-copy render pipeline | worker mesh → in-memory binary → three.js typed arrays; zero base64 / zero intermediate files / zero per-step disk writes |
49
- | 💾 Modeling document persistence | Operation log (JSON) + debounced disk mirror; automatically replayed to restore state after a process restart |
50
- | 🖼️ Image → profile | PNG sketch/screenshot → Otsu binarization → contour tracing → extrusion-ready polygon (`cad_image_profile`) |
51
- | 🔌 FreeCAD executor | Run the same op family on an external FreeCAD console (STEP in/out); requires a local FreeCAD install |
52
- | ☁️ Onshape executor | Run the same op family on **Onshape** over its signed REST API — zero local install; every op compiles to a **standard Onshape feature** pushed into the target Part Studio (no Feature Studio setup). Readback is three-tier: cheap per-part STL by default, `readback: "step"` for exact-BRep-derived named meshes via a server-side STEP translation, or `readback: "none"` — build only and return the document link (~3 calls, quota-friendliest). Exports `.stl` / `.step` / `.x_t` (Parasolid). Quota-aware errors distinguish credential problems from free-plan cooldowns; the Onshape document URL is always surfaced |
53
-
54
- ## Installation
55
-
56
- The plugin is published to npm — one line:
57
-
58
- ```sh
59
- dsh plugin --profile web add dsh-cad
60
- ```
61
-
62
- The installer applies the bundled `cordis.patch.yml` (declared in the `dsh.bundle` manifest) automatically, so there is nothing to configure by hand.
63
-
64
- ### Version requirements
65
-
66
- - **Node.js** and **dsh CLI** (`@deepseek-ai/dsh`): minimum versions live in
67
- the badge row above and the `engines` field of `package.json` — kept out of
68
- the prose so they never go stale
69
-
70
- ### Install from source (dev mode)
71
-
72
- ```sh
73
- git clone https://github.com/LAU-MARS/dsh-cad.git
74
- cd dsh-cad
75
- npm install && npm run build && npm test # deps include occt.ts (true-HLR drawing kernel, ~20MB wasm)
76
-
77
- npm install -g @deepseek-ai/dsh pnpm
78
- dsh web # let the first launch init the profile, then Ctrl-C
79
-
80
- dsh plugin --profile web add /path/to/dsh-cad
81
-
82
- dsh web
83
- ```
84
-
85
- The patch insert ships as `cordis.patch.yml` in the package root and is applied by the installer via the same `dsh.bundle` manifest.
86
-
87
- Set `DEEPSEEK_API_KEY` and you are ready — for example:
88
-
89
- - “open bracket.stl” → `cad_view`
90
- - “model a 100×60×5 plate, punch a ⌀20 hole in the middle, R2 fillets on the four
91
- corners, add a ⌀16 boss 20 tall, export plate.step”
92
- → `cad_create_prim` + `cad_boolean` + `cad_fillet` + `cad_export`, with the 3D tab
93
- updating live at every step
94
- - “build a snowman” → spheres + a cone nose + a cylinder hat (precise `at`/`axis` placement)
95
- - “add two more b1, one rotated 90 degrees” → `cad_assembly_insert` + `cad_assembly_move`, the Assembly tab updates live
96
- - “make an A3 drawing of b1 and export dxf” → `cad_drawing` (three views + iso + dashed hidden lines + dimensions) → `cad_export` `.dxf`
97
-
98
- ## Modeling Tool Family
99
-
100
- | Tool | Description |
101
- | --- | --- |
102
- | `cad_view` | Open a CAD file and render an interactive viewer card |
103
- | `cad_info` | Read-only geometry metadata (format / counts / bounding box / units / layers) |
104
- | `cad_create_prim` | Primitives (mm, Z-up); `at` for placement, `axis` for orientation (exact axis-angle rotation) |
105
- | `cad_sketch_new` | Create a named sketch (Sketch1…): {start, segments} / {circle} / flat points loop — referenced by name from the profile features |
106
- | `cad_sketch_edit` | Redefine a sketch (回改): the definition op is rewritten in place and the log replayed — every referencing feature rebuilds |
107
- | `cad_sketch_list` | List the document's sketches (name / form / size) |
108
- | `cad_sketch_delete` | Delete a sketch (refused while features still reference it) |
109
- | `cad_extrude_profile` | Extrude a closed XY-plane profile along +Z into a solid — inline points/segments/circle or a named sketch (`sketch`) |
110
- | `cad_loft` | Loft: skin a solid through successive closed sections (each a [x,y,z,…] loop in its own plane); sections may differ in shape and point count; `ruled` for straight sides |
111
- | `cad_revolve` | Solid of revolution: revolve a closed profile around an axis (profile coords = (radius, height); curve segments supported — rounded rims exact); optional `angle`; accepts a named sketch |
112
- | `cad_chamfer` | Chamfer: bevel every sharp edge with one equal distance (mm) |
113
- | `cad_pattern` | Pattern: linear (`delta` spacing) or circular (principal axis + `at` point + sweep angle); creates copy bodies, fuse afterwards for one body |
114
- | `cad_shell` | Shell: hollow to a wall thickness (inward, outer skin preserved); `open` lists outward normals of the faces to open (empty = sealed). Runs on the occt.ts kernel; the result is a HOSTED body |
115
- | `cad_draft` | Draft: tilt the walls `angle` degrees about a neutral plane (mold release); `direction` is the pull direction, walls auto-selected by default. Runs on the occt.ts kernel; the result is a HOSTED body |
116
- | `cad_sweep` | Sweep: pipe a closed 2D profile along a 3D [x,y,z,…] path; the profile is auto-placed on the start plane, so no manual orientation; accepts a named sketch |
117
- | `cad_boolean` | fuse / cut / common (classic hole punching: plate cut cylinder) |
118
- | `cad_fillet` | Constant-radius fillet on all sharp edges |
119
- | `cad_transform` | Translate / Euler rotate / mirror |
120
- | `cad_volume` | Exact BRep volume (mm³) |
121
- | `cad_drawing` | Engineering drawing: front/top/left + isometric views, dashed hidden lines, frame, title block, overall dimensions, standard scale, A4/A3 |
122
- | `cad_assembly_insert` | Insert a body into the assembly as a placed instance (`at` position, `rotate` orientation) |
123
- | `cad_assembly_move` | Set an instance's absolute placement |
124
- | `cad_assembly_remove` | Remove an instance from the assembly (the body stays) |
125
- | `cad_constraint` | Declare the constraint model: entities (assembly-instance bindings) + constraints (distance/angle/mate/coaxial…), persisted in the op log |
126
- | `cad_solve` | Solve with Ansatz and write poses back; returns DOF/residual/redundancy/suggestion diagnostics |
127
- | `cad_motion` | Kinematic sweep: drive one constraint value from `from` to `to`, solve frame by frame, apply the last pose, return the motion table |
128
- | `cad_export` | Export STEP / STL / DCPRT (the native replayable part document) to a workspace path; `target: "assembly"` writes the assembly STEP, `target: "drawing"` writes the sheet as SVG / DXF |
129
- | `cad_delete` | Delete a body |
130
- | `cad_docs` | List the workspace's modeling documents (id / name / bodies / updated, active marked) |
131
- | `cad_doc_new` | Create a named document and make it the session's modeling target (start multi-part projects here) |
132
- | `cad_doc_open` | Open an existing document (by id or name) as the session's modeling target — bodies replay exactly |
133
- | `cad_doc_rename` | Rename a document |
134
- | `cad_doc_delete` | Permanently delete a document (requires `confirm: true`) |
135
- | `cad_freecad` | Run an op program on an external FreeCAD executor (optional STEP input / export) |
136
- | `cad_fusion` | Run an op program on an external Fusion 360 executor (GUI bridge; optional export) |
137
- | `cad_onshape` | Run an op program on the Onshape cloud (signed REST API): creates or drives a document, returns its URL; `readback: "step"` for exact BRep meshes; exports `.stl` / `.step` / `.x_t` (Parasolid) |
138
- | `cad_image_profile` | PNG → contours → extrusion-ready polygon points |
139
-
140
- After every modeling step: **the same viewer card refreshes in place** (stable viewId +
141
- versioned URL), and the "3D" tab tracks the latest model in real time.
142
-
143
- ## Connectors (roadmap)
144
-
145
- Modeling primarily runs on the **occt.ts kernel** (opencascade.js as the fallback backend) (OCCT in the browser —
146
- zero install). The connectors below refer to **external CAD engines** acting as
147
- executors for the same tool family, planned for future support:
148
-
149
- | Connector | Suite | Platform | Status |
150
- | --- | --- | --- | --- |
151
- | **Built-in kernel** | CAD modeling kernel based on OCCT + WebGL, runs in the browser — zero install | All platforms (WebGL rendering) | ✅ Built-in |
152
- | FreeCAD | open-source parametric suite — natural local executor via its Python API (console + GUI window modes) | Windows / macOS / Linux | ✅ Available (needs local install) |
153
- | Fusion 360 | Autodesk CAD/CAM — resident add-in + spool bridge (no headless; the Fusion window doubles as a viewer) | Windows / macOS | 🧪 Experimental (`cad_fusion`) |
154
- | SolidWorks | Dassault Systèmes industry-standard 3D CAD, COM/.NET automation | Windows only | 🚧 Windows demo scaffold (`scripts/solidworks-bridge/`) |
155
- | Onshape | PTC cloud-native SaaS CAD, fully in the browser — signed REST API (cad.onshape.com or chamber hosts); every op compiles to a standard Onshape feature pushed into the Part Studio, results read back as per-part STL + mass properties, the cloud is the viewer | All platforms (browser) | ✅ Available (`cad_onshape`; set `DSH_ONSHAPE_ACCESS_KEY` / `DSH_ONSHAPE_SECRET_KEY`) |
156
- | ZW3D(中望3D) | ZWSOFT all-in-one CAD/CAM | Windows / Linux | 🚧 Planned |
157
- | GstarCAD 3D(浩辰3D) | Gstarsoft 3D CAD | Windows | 🚧 Planned |
158
-
159
- All external engines implement the same **GeometryExecutor contract** (`available()` /
160
- `run(opProgram) → meshes`), so the WebGL display layer never changes — swapping a
161
- backend changes only the quality of the produced geometry.
162
-
163
- ## Architecture
164
-
165
- ```
166
- cad_view(path) modeling tools (cad_create_prim, …)
167
- → import worker (occt-import-js) → modeling worker (opencascade.js WASM)
168
- → CadScene JSON (base64-f32) → exact BRep geometry + meshing
169
- → GET /dsh-cad/scene/<id> → in-memory binary scene (f32/u32 packed)
170
- → GET /dsh-cad/bin/<docId>
171
- ↓ session presentationMeta (viewId + versioned URL) ↓
172
- browser card + persistent "3D" tab (three.js / SVG, Z-up, XYZ axes)
173
- ```
174
-
175
- - **Two workers**: import (occt-import-js, read-only STEP/IGES/BREP) and modeling
176
- (opencascade.js, full OCCT) are separate, both lazily started; the `_N`
177
- suffix convention of embind overloaded constructors is wrapped in
178
- `src/modeling/occt-adapter.cjs` (all verified at runtime)
179
- - **Zero-copy pipeline**: modeling scenes use zero base64 / zero large JSON arrays /
180
- zero per-step disk writes (disk mirror debounced 1.5s, replayed only on service
181
- restart); `cad_export` is the only explicit file export
182
- - **Modeling document**: `<workspace>/.dsh-cad/model.json` operation log; all bodies
183
- are restored by replay after a restart
184
- - **Drawing HLR kernel**: hidden lines run on **occt.ts** (npm dependency,
185
- `npm i occt.ts`) — true OCCT removal, no fallback engine, a missing kernel is
186
- a hard error. New APIs over opencascade.js: `hiddenLines()` true hidden-line
187
- removal, byte-level STEP/BRep `readStep`/`readBrep`/`writeStep`/`writeBrep`
188
- without MEMFS, tessellation with built-in feature-edge extraction, and a
189
- `hasError()`/`lastError()` error contract. Geometry crosses kernels as STEP
190
- bytes and the projected segments are remapped into the sheet frame. Kernel
191
- dist resolution: `DSH_OCCTJS_DIST` env var → Node's own resolution of the
192
- `occt.ts` dependency (walks up every parent node_modules — npm/yarn flat and
193
- pnpm symlink layouts all hit) → `<repo>/../opencascade-ts/dist` (sibling
194
- checkout) → `vendor/` → `node_modules/opencascade-ts`
195
- - **Constraint solving (Ansatz)**: the solver is the npm dependency
196
- **`ansatz-wasm`** (a wasm-bindgen build, single package ~538KB, zero deps) —
197
- installing dsh-cad pulls it automatically, and `npm install ansatz-wasm` alone
198
- upgrades it. **No Rust toolchain, no native binary, platform independent.**
199
- Resolution: the npm package (node_modules) → a `DSH_ANSATZ_WASM` directory → a
200
- sibling Ansatz checkout's pkg-node. The solver speaks one JSON envelope
201
- contract, with tool-layer errors (e.g. `unsupported_constraint`) surfaced
202
- verbatim for the LLM. Assembly placements (translate + XYZ Euler
203
- degrees) map bidirectionally to the solver's rigid3 poses (translate +
204
- exponential-map rotation, radians). Solver capability is staged
205
- (point-distance-to-origin today) — the plumbing contract is finished and needs
206
- no changes as it grows
207
- - **Single-kernel architecture**: the primary modeling kernel is
208
- **occt.ts** — primitives, curve-segment profiles (TRUE B-spline
209
- interpolation), loft/sweep/revolve, booleans, fillet/chamfer, shell/draft,
210
- mirror (composed as scale(-1) + a π rotation) and centroid all live in one
211
- session; engineering-drawing HLR takes the shape directly (zero STEP hops);
212
- editing after shelling is seamless (the old hosted-body seam is deleted).
213
- opencascade.js remains as the FALLBACK backend (auto-selected when occt.ts
214
- cannot load). Assembly STEP export writes a **structured document** (occt.ts
215
- `writeStepDocument`): one root product plus one named, placed child
216
- per instance — instance separation survives the file (STL stays a single
217
- fused mesh; the fallback backend also fuses). Instance separation stays in
218
- the assembly scene/document for the fuse paths.
219
- Face selection matches `describe()` plane normals (outermost along ±normal)
220
- - **Client**: esbuild single-file CJS factory (three.js inlined ~560KB, react provided
221
- by the host module table), Z-up CAD convention, empty scene with XYZ axis labels
222
- and a ground grid always displayed
223
-
224
- ## Tests
225
-
226
- ```sh
227
- npm test # full suite: converters / modeling worker (exact volume assertions) / DCPRT round-trip / FreeCAD + Onshape executors / image profiles / binary pipeline / document persistence
228
- node test/m0-kernel-check.cjs # OCCT kernel API smoke test
229
- node test/route-check.mjs # JSON scene routing layer
230
- node test/visual/serve.mjs # browser card/tab visual verification page (http://127.0.0.1:3987)
231
- ```
232
-
233
- Representative assertions covered: the boolean-punched volume exactly equals the
234
- analytic value (28429.20 mm³), L-shaped profile extrusion 3000 mm³, volumes and
235
- bounding-box flips of sphere/cone/torus placed with `at`/`axis`, 8-byte alignment
236
- of the binary packing, an STL export round-trip (export → read back by the
237
- phase-1 parser), and a DCPRT document round-trip (serialize → replay on the
238
- OCCT worker → exact bounds).
239
-
240
- ## Known Limitations
241
-
242
- - DWG (closed-source) is unsupported; DXF bulge arcs are approximated by chords;
243
- glTF/3MF viewing is not implemented (the structure is reserved)
244
- - `cad_fillet` is all-edge constant-radius (per-edge selection is unstable under
245
- embind); chamfer is not implemented
246
- - Sketch extrusion supports polygon profiles only (arc profiles are constructed by
247
- boolean combinations of cylinders/tori)
248
- - dsh framework limitation: an already-mounted single slot (the right-side details
249
- panel itself) does not respond to components registered later, so the persistent
250
- view is provided as the "3D" view tab (a list slot, the official composition)
251
- - The host reads CAD files via node:fs (the platform fs service supports UTF-8 text
252
- only and cannot carry binary data)
253
-
254
- ## Community
255
-
256
- | QQ Group (🇨🇳 China) | Feishu (🇨🇳 China) | X / Twitter (🌍 International) | Discord (🌍 International) |
257
- | --- | --- | --- | --- |
258
- | `485038246` (join note: dsh-cad) | 🚧 Coming soon | 🚧 Coming soon | 🚧 Coming soon |
259
-
260
- <!-- TODO: fill in the X handle / Discord invite link before publishing -->
261
-
262
- ## Contributors
263
-
264
- Auto-generated from the commit history — thanks to everyone who has contributed!
265
-
266
- [![Contributors](https://contrib.rocks/image?repo=LAU-MARS/dsh-cad)](https://github.com/LAU-MARS/dsh-cad/graphs/contributors)
267
-
268
- ## License
269
-
270
- MIT
1
+ # dsh-cad — CAD Plugin for DeepSeek Harness
2
+
3
+ ![dsh-cad banner](docs/img/banner.svg)
4
+
5
+ [![homepage](https://img.shields.io/badge/homepage-dsh--cad-4D6BFE)](https://lau-mars.github.io/dsh-cad/)
6
+ [![npm](https://img.shields.io/npm/v/dsh-cad)](https://www.npmjs.com/package/dsh-cad)
7
+ [![downloads](https://img.shields.io/npm/dm/dsh-cad)](https://www.npmjs.com/package/dsh-cad)
8
+ [![dsh](https://img.shields.io/npm/v/@deepseek-ai%2Fdsh?label=dsh)](https://www.npmjs.com/package/@deepseek-ai/dsh)
9
+ [![Node](https://img.shields.io/badge/node-%3E%3D%2022-4D6BFE)](https://nodejs.org/)
10
+ [![occt.ts](https://img.shields.io/npm/v/occt.ts)](https://www.npmjs.com/package/occt.ts)
11
+ [![ansatz](https://img.shields.io/npm/v/ansatz-wasm?label=ansatz)](https://www.npmjs.com/package/ansatz-wasm)
12
+ [![License: MIT](https://img.shields.io/badge/license-MIT-4D6BFE)](./LICENSE)
13
+
14
+ English | [简体中文](./README.zh-CN.md)
15
+
16
+ A CAD plugin for [DeepSeek Harness (dsh)](https://github.com/deepseek-ai/deepseek-harness):
17
+ an **embedded 3D/2D CAD viewer** plus a **native parametric modeling tool family**
18
+ (OCCT kernel) in the Web UI, letting the agent build and inspect CAD geometry
19
+ step by step — "model while you watch".
20
+
21
+ ## Preview
22
+
23
+ A full modeling session, end to end: the agent builds a parametric assembly
24
+ from plain chat — a 120×80×8 base plate with R5 rounded corners, then four
25
+ bolt instances placed at the corners — while the resident CAD panel tracks
26
+ every step live (parts tree with per-instance colors, ViewCube, "装配体"
27
+ assembly tab, 5 instances · 1,740 triangles). The finished assembly exports
28
+ as a structured STEP document and the agent verifies it by reading the file
29
+ back — 2 solids, 3 products, 2 assembly usages, 1,125.00 mm³:
30
+
31
+ ![dsh-cad assembly session](docs/img/assembly-preview.png)
32
+
33
+ ## Feature Overview
34
+
35
+ | Capability | Description |
36
+ | --- | --- |
37
+ | ⚙️ Single-kernel architecture | **occt.ts as the primary modeling kernel** (true B-splines, native shell/draft, centroid); opencascade.js stays only as the fallback backend; the old "no editing after shell" seam is gone — fillet/chamfer/boolean keep working after shelling |
38
+ | 🔍 CAD viewing | STL / OBJ / STEP / IGES / BREP / DCPRT (3D), DXF / SVG (2D); interactive viewport in the resident right panel (orbit / zoom / wireframe / pan), with a one-line result row in the conversation |
39
+ | 🧭 CAD editor interactions | Onshape-style ViewCube (26-zone click-to-orient), hover/click face & edge picking with live measurement (area mm² / length mm), Faces+Edges / Faces / Wireframe render modes, switchable BRep demo parts (bracket / flange / shaft) |
40
+ | 🏗️ Parametric modeling | Primitives, profile extrusion, **loft**, **sweep**, **revolve**, booleans, all-edge fillet/chamfer, **shell**, **draft**, **patterns** (linear/circular), transforms; profiles take **curve segments** (arcs/circles exact BRep; B-splines sampled approximation) — exact OCCT BRep, not a mesh approximation |
41
+ | ✏️ Named sketches | Standalone named profiles (Sketch1…) kept in the document (`cad_sketch_new` / `edit` / `list` / `delete`); extrude/revolve/sweep reference them **by name**, and `cad_sketch_edit` rewrites the definition in place + replays the log, rebuilding every dependent feature — the parametric loop. Sketches render as Onshape-style **blue curves + plane frame** in the viewport (refreshing live on edit), listed in a left-side **feature tree** (sketches + features, eye-toggle visibility, click-to-highlight bodies) over the Part tab |
42
+ | 🗂️ Codex-style document tabs | The resident display panel gets a tab strip with a "+" menu: **Part** (Part Studio, the default) / **Assembly** (instance insert/move/remove) / **Drawing** (true hidden-line sheets); tabs are closable and keep their state |
43
+ | 📁 Multi-document file space | Named documents per workspace (`.dsh-cad/docs/`), each session bound to its own active document — new sessions start empty instead of inheriting leftovers; a folder button in the panel lists every document (preview / delete), and `cad_doc_new` / `cad_doc_open` manage the modeling target from chat |
44
+ | 📐 Engineering drawings | GB first-angle layout: front / top / left views + isometric, true OCCT hidden-line removal via the **occt.ts** kernel (an npm dependency, dashed); sheet frame, title block, overall dimensions, standard scale series; exports SVG / DXF |
45
+ | 🔗 Constraint solving & motion | **Ansatz** geometric constraint solver (**one command: `npm install ansatz-wasm`** — a wasm dependency, no Rust toolchain, no native binary): entity/constraint modeling (assembly instances ↔ rigid3 poses mapped automatically), solve-with-writeback, full DOF/residual/redundancy/suggestion diagnostics (LLM-oriented), and parametric kinematic sweeps (`cad_constraint` / `cad_solve` / `cad_motion`) |
46
+ | 📐 Geometry measurement | Exact volume (mm³), bounding box, triangle counts, DXF layers |
47
+ | 📤 On-demand export | STEP (parametric) / STL (mesh); files are written only when the user asks |
48
+ | 🖥️ Resident CAD panel | A permanent panel right of the conversation: Codex-style tabs (Part / Assembly / Drawing), tracking the latest model in real time while modeling |
49
+ | ⚡ Zero-copy render pipeline | worker mesh → in-memory binary → three.js typed arrays; zero base64 / zero intermediate files / zero per-step disk writes |
50
+ | 💾 Modeling document persistence | Operation log (JSON) + debounced disk mirror; automatically replayed to restore state after a process restart |
51
+ | 🖼️ Image → profile | PNG sketch/screenshot → Otsu binarization → contour tracing → extrusion-ready polygon (`cad_image_profile`) |
52
+ | 🔌 FreeCAD executor | Run the same op family on an external FreeCAD console (STEP in/out); requires a local FreeCAD install |
53
+ | ☁️ Onshape executor | Run the same op family on **Onshape** over its signed REST API — zero local install; every op compiles to a **standard Onshape feature** pushed into the target Part Studio (no Feature Studio setup). Readback is three-tier: cheap per-part STL by default, `readback: "step"` for exact-BRep-derived named meshes via a server-side STEP translation, or `readback: "none"` — build only and return the document link (~3 calls, quota-friendliest). Exports `.stl` / `.step` / `.x_t` (Parasolid). Quota-aware errors distinguish credential problems from free-plan cooldowns; the Onshape document URL is always surfaced |
54
+
55
+ ## Installation
56
+
57
+ The plugin is published to npm — one line:
58
+
59
+ ```sh
60
+ dsh plugin --profile web add dsh-cad
61
+ ```
62
+
63
+ The installer applies the bundled `cordis.patch.yml` (declared in the `dsh.bundle` manifest) automatically, so there is nothing to configure by hand.
64
+
65
+ ### Version requirements
66
+
67
+ - **Node.js** and **dsh CLI** (`@deepseek-ai/dsh`): minimum versions live in
68
+ the badge row above and the `engines` field of `package.json` — kept out of
69
+ the prose so they never go stale
70
+
71
+ ### Install from source (dev mode)
72
+
73
+ ```sh
74
+ git clone https://github.com/LAU-MARS/dsh-cad.git
75
+ cd dsh-cad
76
+ npm install && npm run build && npm test # deps include occt.ts (true-HLR drawing kernel, ~20MB wasm)
77
+
78
+ npm install -g @deepseek-ai/dsh pnpm
79
+ dsh web # let the first launch init the profile, then Ctrl-C
80
+
81
+ dsh plugin --profile web add /path/to/dsh-cad
82
+
83
+ dsh web
84
+ ```
85
+
86
+ The patch insert ships as `cordis.patch.yml` in the package root and is applied by the installer via the same `dsh.bundle` manifest.
87
+
88
+ Set `DEEPSEEK_API_KEY` and you are ready — for example:
89
+
90
+ - “open bracket.stl” → `cad_view`
91
+ - “model a 100×60×5 plate, punch a ⌀20 hole in the middle, R2 fillets on the four
92
+ corners, add a ⌀16 boss 20 tall, export plate.step”
93
+ → `cad_create_prim` + `cad_boolean` + `cad_fillet` + `cad_export`, with the 3D tab
94
+ updating live at every step
95
+ - “build a snowman” → spheres + a cone nose + a cylinder hat (precise `at`/`axis` placement)
96
+ - “add two more b1, one rotated 90 degrees” → `cad_assembly_insert` + `cad_assembly_move`, the Assembly tab updates live
97
+ - “make an A3 drawing of b1 and export dxf” → `cad_drawing` (three views + iso + dashed hidden lines + dimensions) → `cad_export` `.dxf`
98
+
99
+ ## Modeling Tool Family
100
+
101
+ | Tool | Description |
102
+ | --- | --- |
103
+ | `cad_view` | Open a CAD file and render it in the viewer (resident panel) |
104
+ | `cad_info` | Read-only geometry metadata (format / counts / bounding box / units / layers) |
105
+ | `cad_create_prim` | Primitives (mm, Z-up); `at` for placement, `axis` for orientation (exact axis-angle rotation) |
106
+ | `cad_sketch_new` | Create a named sketch (Sketch1…): {start, segments} / {circle} / flat points loop — referenced by name from the profile features |
107
+ | `cad_sketch_edit` | Redefine a sketch (回改): the definition op is rewritten in place and the log replayed — every referencing feature rebuilds |
108
+ | `cad_sketch_list` | List the document's sketches (name / form / size) |
109
+ | `cad_sketch_delete` | Delete a sketch (refused while features still reference it) |
110
+ | `cad_extrude_profile` | Extrude a closed XY-plane profile along +Z into a solid — inline points/segments/circle or a named sketch (`sketch`) |
111
+ | `cad_loft` | Loft: skin a solid through successive closed sections (each a [x,y,z,…] loop in its own plane); sections may differ in shape and point count; `ruled` for straight sides |
112
+ | `cad_revolve` | Solid of revolution: revolve a closed profile around an axis (profile coords = (radius, height); curve segments supported — rounded rims exact); optional `angle`; accepts a named sketch |
113
+ | `cad_chamfer` | Chamfer: bevel every sharp edge with one equal distance (mm) |
114
+ | `cad_pattern` | Pattern: linear (`delta` spacing) or circular (principal axis + `at` point + sweep angle); creates copy bodies, fuse afterwards for one body |
115
+ | `cad_shell` | Shell: hollow to a wall thickness (inward, outer skin preserved); `open` lists outward normals of the faces to open (empty = sealed). Runs on the occt.ts kernel; the result is a HOSTED body |
116
+ | `cad_draft` | Draft: tilt the walls `angle` degrees about a neutral plane (mold release); `direction` is the pull direction, walls auto-selected by default. Runs on the occt.ts kernel; the result is a HOSTED body |
117
+ | `cad_sweep` | Sweep: pipe a closed 2D profile along a 3D [x,y,z,…] path; the profile is auto-placed on the start plane, so no manual orientation; accepts a named sketch |
118
+ | `cad_boolean` | fuse / cut / common (classic hole punching: plate cut cylinder) |
119
+ | `cad_fillet` | Constant-radius fillet on all sharp edges |
120
+ | `cad_transform` | Translate / Euler rotate / mirror |
121
+ | `cad_volume` | Exact BRep volume (mm³) |
122
+ | `cad_drawing` | Engineering drawing: front/top/left + isometric views, dashed hidden lines, frame, title block, overall dimensions, standard scale, A4/A3 |
123
+ | `cad_assembly_insert` | Insert a body into the assembly as a placed instance (`at` position, `rotate` orientation) |
124
+ | `cad_assembly_move` | Set an instance's absolute placement |
125
+ | `cad_assembly_remove` | Remove an instance from the assembly (the body stays) |
126
+ | `cad_constraint` | Declare the constraint model: entities (assembly-instance bindings) + constraints (distance/angle/mate/coaxial…), persisted in the op log |
127
+ | `cad_solve` | Solve with Ansatz and write poses back; returns DOF/residual/redundancy/suggestion diagnostics |
128
+ | `cad_motion` | Kinematic sweep: drive one constraint value from `from` to `to`, solve frame by frame, apply the last pose, return the motion table |
129
+ | `cad_export` | Export STEP / STL / DCPRT (the native replayable part document) to a workspace path; `target: "assembly"` writes the assembly STEP, `target: "drawing"` writes the sheet as SVG / DXF |
130
+ | `cad_delete` | Delete a body |
131
+ | `cad_docs` | List the workspace's modeling documents (id / name / bodies / updated, active marked) |
132
+ | `cad_doc_new` | Create a named document and make it the session's modeling target (start multi-part projects here) |
133
+ | `cad_doc_open` | Open an existing document (by id or name) as the session's modeling target — bodies replay exactly |
134
+ | `cad_doc_rename` | Rename a document |
135
+ | `cad_doc_delete` | Permanently delete a document (requires `confirm: true`) |
136
+ | `cad_freecad` | Run an op program on an external FreeCAD executor (optional STEP input / export) |
137
+ | `cad_fusion` | Run an op program on an external Fusion 360 executor (GUI bridge; optional export) |
138
+ | `cad_onshape` | Run an op program on the Onshape cloud (signed REST API): creates or drives a document, returns its URL; `readback: "step"` for exact BRep meshes; exports `.stl` / `.step` / `.x_t` (Parasolid) |
139
+ | `cad_image_profile` | PNG → contours → extrusion-ready polygon points |
140
+ | `cad_script` | Deterministic script evaluation for geometry math (profile point arrays, arc coordinates): `js` runs in-process (Node vm — works even when the host shell is unavailable), `py` uses a system Python |
141
+
142
+ After every modeling step: **the chat result row updates in place** (stable viewId +
143
+ versioned URL), and the resident panel's "Part" tab tracks the latest model in real time.
144
+
145
+ ## Connectors (roadmap)
146
+
147
+ Modeling primarily runs on the **occt.ts kernel** (opencascade.js as the fallback backend) (OCCT in the browser —
148
+ zero install). The connectors below refer to **external CAD engines** acting as
149
+ executors for the same tool family, planned for future support:
150
+
151
+ | Connector | Suite | Platform | Status |
152
+ | --- | --- | --- | --- |
153
+ | **Built-in kernel** | CAD modeling kernel based on OCCT + WebGL, runs in the browser — zero install | All platforms (WebGL rendering) | ✅ Built-in |
154
+ | FreeCAD | open-source parametric suite — natural local executor via its Python API (console + GUI window modes) | Windows / macOS / Linux | ✅ Available (needs local install) |
155
+ | Fusion 360 | Autodesk CAD/CAM — resident add-in + spool bridge (no headless; the Fusion window doubles as a viewer) | Windows / macOS | 🧪 Experimental (`cad_fusion`) |
156
+ | SolidWorks | Dassault Systèmes industry-standard 3D CAD, COM/.NET automation | Windows only | 🚧 Windows demo scaffold (`scripts/solidworks-bridge/`) |
157
+ | Onshape | PTC cloud-native SaaS CAD, fully in the browser — signed REST API (cad.onshape.com or chamber hosts); every op compiles to a standard Onshape feature pushed into the Part Studio, results read back as per-part STL + mass properties, the cloud is the viewer | All platforms (browser) | ✅ Available (`cad_onshape`; set `DSH_ONSHAPE_ACCESS_KEY` / `DSH_ONSHAPE_SECRET_KEY`) |
158
+ | ZW3D(中望3D) | ZWSOFT all-in-one CAD/CAM | Windows / Linux | 🚧 Planned |
159
+ | GstarCAD 3D(浩辰3D) | Gstarsoft 3D CAD | Windows | 🚧 Planned |
160
+
161
+ All external engines implement the same **GeometryExecutor contract** (`available()` /
162
+ `run(opProgram) → meshes`), so the WebGL display layer never changes — swapping a
163
+ backend changes only the quality of the produced geometry.
164
+
165
+ ## Architecture
166
+
167
+ ```
168
+ cad_view(path) modeling tools (cad_create_prim, …)
169
+ → import worker (occt-import-js) → modeling worker (opencascade.js WASM)
170
+ → CadScene JSON (base64-f32) → exact BRep geometry + meshing
171
+ → GET /dsh-cad/scene/<id> → in-memory binary scene (f32/u32 packed)
172
+ → GET /dsh-cad/bin/<docId>
173
+ ↓ session presentationMeta (viewId + versioned URL) ↓
174
+ browser card + persistent "3D" tab (three.js / SVG, Z-up, XYZ axes)
175
+ ```
176
+
177
+ - **Two workers**: import (occt-import-js, read-only STEP/IGES/BREP) and modeling
178
+ (opencascade.js, full OCCT) are separate, both lazily started; the `_N`
179
+ suffix convention of embind overloaded constructors is wrapped in
180
+ `src/modeling/occt-adapter.cjs` (all verified at runtime)
181
+ - **Zero-copy pipeline**: modeling scenes use zero base64 / zero large JSON arrays /
182
+ zero per-step disk writes (disk mirror debounced 1.5s, replayed only on service
183
+ restart); `cad_export` is the only explicit file export
184
+ - **Modeling document**: `<workspace>/.dsh-cad/model.json` operation log; all bodies
185
+ are restored by replay after a restart
186
+ - **Drawing HLR kernel**: hidden lines run on **occt.ts** (npm dependency,
187
+ `npm i occt.ts`) — true OCCT removal, no fallback engine, a missing kernel is
188
+ a hard error. New APIs over opencascade.js: `hiddenLines()` true hidden-line
189
+ removal, byte-level STEP/BRep `readStep`/`readBrep`/`writeStep`/`writeBrep`
190
+ without MEMFS, tessellation with built-in feature-edge extraction, and a
191
+ `hasError()`/`lastError()` error contract. Geometry crosses kernels as STEP
192
+ bytes and the projected segments are remapped into the sheet frame. Kernel
193
+ dist resolution: `DSH_OCCTJS_DIST` env var → Node's own resolution of the
194
+ `occt.ts` dependency (walks up every parent node_modules — npm/yarn flat and
195
+ pnpm symlink layouts all hit) → `<repo>/../opencascade-ts/dist` (sibling
196
+ checkout) → `vendor/` → `node_modules/opencascade-ts`
197
+ - **Constraint solving (Ansatz)**: the solver is the npm dependency
198
+ **`ansatz-wasm`** (a wasm-bindgen build, single package ~538KB, zero deps) —
199
+ installing dsh-cad pulls it automatically, and `npm install ansatz-wasm` alone
200
+ upgrades it. **No Rust toolchain, no native binary, platform independent.**
201
+ Resolution: the npm package (node_modules) → a `DSH_ANSATZ_WASM` directory → a
202
+ sibling Ansatz checkout's pkg-node. The solver speaks one JSON envelope
203
+ contract, with tool-layer errors (e.g. `unsupported_constraint`) surfaced
204
+ verbatim for the LLM. Assembly placements (translate + XYZ Euler
205
+ degrees) map bidirectionally to the solver's rigid3 poses (translate +
206
+ exponential-map rotation, radians). Solver capability is staged
207
+ (point-distance-to-origin today) — the plumbing contract is finished and needs
208
+ no changes as it grows
209
+ - **Single-kernel architecture**: the primary modeling kernel is
210
+ **occt.ts** — primitives, curve-segment profiles (TRUE B-spline
211
+ interpolation), loft/sweep/revolve, booleans, fillet/chamfer, shell/draft,
212
+ mirror (composed as scale(-1) + a π rotation) and centroid all live in one
213
+ session; engineering-drawing HLR takes the shape directly (zero STEP hops);
214
+ editing after shelling is seamless (the old hosted-body seam is deleted).
215
+ opencascade.js remains as the FALLBACK backend (auto-selected when occt.ts
216
+ cannot load). Assembly STEP export writes a **structured document** (occt.ts
217
+ `writeStepDocument`): one root product plus one named, placed child
218
+ per instance — instance separation survives the file (STL stays a single
219
+ fused mesh; the fallback backend also fuses). Instance separation stays in
220
+ the assembly scene/document for the fuse paths.
221
+ Face selection matches `describe()` plane normals (outermost along ±normal)
222
+ - **Client**: esbuild single-file CJS factory (three.js inlined ~560KB, react provided
223
+ by the host module table), Z-up CAD convention, empty scene with XYZ axis labels
224
+ and a ground grid always displayed
225
+
226
+ ## Tests
227
+
228
+ ```sh
229
+ npm test # full suite: converters / modeling worker (exact volume assertions) / DCPRT round-trip / FreeCAD + Onshape executors / image profiles / binary pipeline / document persistence
230
+ node test/m0-kernel-check.cjs # OCCT kernel API smoke test
231
+ node test/route-check.mjs # JSON scene routing layer
232
+ node test/visual/serve.mjs # browser card/tab visual verification page (http://127.0.0.1:3987)
233
+ ```
234
+
235
+ Representative assertions covered: the boolean-punched volume exactly equals the
236
+ analytic value (28429.20 mm³), L-shaped profile extrusion 3000 mm³, volumes and
237
+ bounding-box flips of sphere/cone/torus placed with `at`/`axis`, 8-byte alignment
238
+ of the binary packing, an STL export round-trip (export → read back by the
239
+ phase-1 parser), and a DCPRT document round-trip (serialize → replay on the
240
+ OCCT worker → exact bounds).
241
+
242
+ ## Known Limitations
243
+
244
+ - DWG (closed-source) is unsupported; DXF bulge arcs are approximated by chords;
245
+ glTF/3MF viewing is not implemented (the structure is reserved)
246
+ - `cad_fillet` is all-edge constant-radius (per-edge selection is unstable under
247
+ embind); chamfer is not implemented
248
+ - Sketch extrusion supports polygon profiles only (arc profiles are constructed by
249
+ boolean combinations of cylinders/tori)
250
+ - dsh framework limitation: an already-mounted single slot (the right-side details
251
+ panel itself) does not respond to components registered later, so the persistent
252
+ view is provided as the "3D" view tab (a list slot, the official composition)
253
+ - The host reads CAD files via node:fs (the platform fs service supports UTF-8 text
254
+ only and cannot carry binary data)
255
+
256
+ ## Community
257
+
258
+ | QQ Group (🇨🇳 China) | Feishu (🇨🇳 China) | X / Twitter (🌍 International) | Discord (🌍 International) |
259
+ | --- | --- | --- | --- |
260
+ | `485038246` (join note: dsh-cad) | 🚧 Coming soon | 🚧 Coming soon | 🚧 Coming soon |
261
+
262
+ <!-- TODO: fill in the X handle / Discord invite link before publishing -->
263
+
264
+ ## Contributors
265
+
266
+ Auto-generated from the commit history — thanks to everyone who has contributed!
267
+
268
+ [![Contributors](https://contrib.rocks/image?repo=LAU-MARS/dsh-cad)](https://github.com/LAU-MARS/dsh-cad/graphs/contributors)
269
+
270
+ ## License
271
+
272
+ MIT