dsh-cad 0.9.1 → 0.11.0

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