dsh-3d-magic-house 0.0.0-stage → 0.1.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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/PUBLISHING.md +63 -0
- package/README.md +95 -2
- package/README.zh.md +96 -0
- package/client.js +1813 -0
- package/cordis.patch.yml +3 -0
- package/data/ideas.json +281 -0
- package/icon.svg +7 -0
- package/index.js +410 -0
- package/lib/mqtt-lite.js +378 -0
- package/lib/printer-link.js +297 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +63 -4
- package/test/link.test.mjs +146 -0
- package/test/mqtt.test.mjs +183 -0
- package/test/render.test.mjs +468 -0
- package/test/run.mjs +49 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First public version.
|
|
6
|
+
|
|
7
|
+
- Left-sidebar entry **3D magic house / 3D魔法屋** with a five-step workshop:
|
|
8
|
+
ideas → sizing → queue → print → stars.
|
|
9
|
+
- Idea spinner (subject × job × limit) and ten curated kid-sized project cards.
|
|
10
|
+
- Dependency-free 3D view of the 256 mm build volume with box/cylinder/sphere/cone/ring,
|
|
11
|
+
live volume, solid-PLA weight guess, oversize warning, and a progress sketch while printing.
|
|
12
|
+
- Project board with idea → design → printing → done, one star per finished print,
|
|
13
|
+
an in-progress project shared by every step, and a six-item pre-print checklist.
|
|
14
|
+
- Bambu Lab P2S over LAN: MQTT over TLS (8883, user `bblp`), read-only status, automatic reconnect.
|
|
15
|
+
The access code is stored in `data/printer.json` with `0600` permissions.
|
|
16
|
+
- `magic_house` agent tool: `read`, `ideas`, `printer`, `add`, `status`, `remove`.
|
|
17
|
+
- One-click handoff of an idea or an exact 3D size to a new conversation.
|
|
18
|
+
- Verified against a real P2S over LAN: status reads (progress, layers, temperatures, job name).
|
|
19
|
+
- `npm test`: four dependency-free suites (MQTT over a local TLS printer, the link, and the panel in a React shim).
|
|
20
|
+
- Published to npm as `dsh-3d-magic-house`, and submitted to the awesome-dsh-plugin catalog.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 挖宝的瓦力
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/PUBLISHING.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# 发布到 GitHub
|
|
2
|
+
|
|
3
|
+
这个目录已经是"仓库就绪"的状态:README(英文 + 中文)、LICENSE、.gitignore、package.json 元数据都在,运行时数据(`data/state.json`、`data/printer.json`)已被忽略。
|
|
4
|
+
|
|
5
|
+
## 1. 先看一眼要提交什么
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
cd /path/to/3d-magic-house
|
|
9
|
+
git status --short # 只应该有源码和文档,不应该出现 data/state.json、data/printer.json
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
如果 `data/printer.json` 出现在列表里,说明 `.gitignore` 没生效——**别提交**,那里面有访问码。
|
|
13
|
+
|
|
14
|
+
## 2. 初始化并提交
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
git init
|
|
18
|
+
git add .
|
|
19
|
+
git commit -m "feat: 3D magic house — five-step print workshop for kids"
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 3. 建远程仓库并推送
|
|
23
|
+
|
|
24
|
+
有 `gh`(GitHub CLI):
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
gh repo create 3d-magic-house --public --source=. --remote=origin --push
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
没有 `gh`:先去 GitHub 网页建一个空仓库(不要勾 README / .gitignore),然后:
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
git remote add origin git@github.com:<你的账号>/3d-magic-house.git
|
|
34
|
+
git branch -M main
|
|
35
|
+
git push -u origin main
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 4. 推上去之后建议补两处
|
|
39
|
+
|
|
40
|
+
- `package.json` 加 `"repository": "github:<你的账号>/3d-magic-house"`(如果打算发 npm 也一并加 `"homepage"`)。
|
|
41
|
+
- LICENSE 里的版权人现在是 `挖宝的瓦力`,想换成真名就改那一行。
|
|
42
|
+
|
|
43
|
+
## 5. 可选:截图
|
|
44
|
+
|
|
45
|
+
README 里目前没有截图。你可以在面板上截图(「3D 视图」和「打印机」两块最值得拍),放进 `docs/` 后在 README 里加:
|
|
46
|
+
|
|
47
|
+
```markdown
|
|
48
|
+

|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## 6. 发版
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
# 改 package.json 的 version,然后
|
|
55
|
+
git tag v0.1.0 && git push --tags
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
CHANGELOG.md 里记一句改了什么。
|
|
59
|
+
|
|
60
|
+
## 注意
|
|
61
|
+
|
|
62
|
+
- 这个目录现在在另一个 vault 里面。**如果之后把它搬走**,已经装好的插件会失效(它是指向绝对路径的软链)。搬完在应用里删掉旧插件、重新 Add plugin 指向新路径即可。
|
|
63
|
+
- 不要提交 `data/state.json`:那是孩子自己的清单。插件缺这个文件时会从空清单开始,这正是新用户想要的状态。
|
package/README.md
CHANGED
|
@@ -1,3 +1,96 @@
|
|
|
1
|
-
#
|
|
1
|
+
# 3D magic house · 3D魔法屋
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A five-step 3D-printing workshop for a child, as a [DeepSeek Harness](https://github.com/deepseek-ai/dsh) plugin. It lives in the left sidebar and walks a kid from *"what should I make"* to *"look, it's done, I got a star"* on a **Bambu Lab P2S**.
|
|
4
|
+
|
|
5
|
+
> ⚠️ The panel is a workshop, not a slicer. It never slices, never starts a print, and never talks to Bambu's cloud.
|
|
6
|
+
|
|
7
|
+
[中文说明 →](README.zh.md)
|
|
8
|
+
|
|
9
|
+
## The five steps
|
|
10
|
+
|
|
11
|
+
| | Step | What actually happens |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| 1 | **Ideas** | Spin a wheel of *subject × job × limit* (dinosaur / it must glow / smaller than a hand), or pick one of ten curated kid-sized projects. Every card carries difficulty, rough time, rough grams, and three steps. |
|
|
14
|
+
| 2 | **Sizing** | A hand-written 3D view of the 256 mm build volume. Drag to rotate, scroll to zoom, choose box / cylinder / sphere / cone / ring, set length × width × height. Volume, a solid-PLA weight guess, and an oversized warning update live. The size is saved onto the project. |
|
|
15
|
+
| 3 | **Queue** | The project board: idea → design → printing → done, one click per stage. Done earns a star. Plus a six-item pre-print checklist and four safety rules. |
|
|
16
|
+
| 4 | **Print** | LAN address + serial + access code, then live progress, remaining minutes, layer count, nozzle / bed / chamber temperatures and the current job name. **Read-only.** |
|
|
17
|
+
| 5 | **Stars** | The finished-print list with dates and the star total. |
|
|
18
|
+
|
|
19
|
+
Anything in step 1 or 2 can be handed to a conversation with one click: the prompt is built from the card or from the exact 3D dimensions, so the model starts from "256 × 256 × 256 mm, 0.4 mm nozzle, PLA" instead of guessing.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
The plugin is a plain directory — no build step, no dependencies.
|
|
24
|
+
|
|
25
|
+
**From the app:** Plugins → **Add plugin** → pick this directory. The entry appears in the left sidebar as **Magic house / 3D魔法屋**.
|
|
26
|
+
|
|
27
|
+
**From npm:** the same package is published as [`dsh-3d-magic-house`](https://www.npmjs.com/package/dsh-3d-magic-house) — add that package name the same way.
|
|
28
|
+
|
|
29
|
+
Nothing else is required: the bundle declares no dependencies and has no build step. A saved printer configuration reconnects on the next start.
|
|
30
|
+
|
|
31
|
+
## Connect the printer (LAN only)
|
|
32
|
+
|
|
33
|
+
On the printer screen: **Settings → Network → LAN Only mode**. Note the **IP** and **serial number** on that page, tap **Access Code** and copy the code. Enter all three in step 4.
|
|
34
|
+
|
|
35
|
+
- Transport: MQTT over TLS on port 8883, user `bblp`, topic `device/<serial>/report`.
|
|
36
|
+
- The only thing ever published is one `pushall` status request. There is no code path that starts, pauses, cancels or rewrites a print.
|
|
37
|
+
- Firmware newer than early 2025 may reject unsigned commands; status pushes usually still arrive. If nothing arrives, enable **Developer mode** too.
|
|
38
|
+
- The access code is stored in plain text in `data/printer.json` with `0600` permissions. It is never returned by a route and never printed by a tool. Delete the file to forget it.
|
|
39
|
+
|
|
40
|
+
## Privacy
|
|
41
|
+
|
|
42
|
+
- The panel talks only to the printer on your own network, and to the plugin's own host routes.
|
|
43
|
+
- No Bambu account, no cloud, no third-party request, no telemetry.
|
|
44
|
+
- The 3D view renders with a few hundred lines of JavaScript on a 2D canvas: no three.js, no CDN, no network.
|
|
45
|
+
|
|
46
|
+
## Data
|
|
47
|
+
|
|
48
|
+
| File | Contents |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `data/ideas.json` | Shipped idea cards and the spin word lists (edit freely). |
|
|
51
|
+
| `data/state.json` | The board: projects, stages, stars, checklist, the project in progress. Created at runtime, git-ignored. |
|
|
52
|
+
| `data/printer.json` | LAN address, serial, access code (`0600`). Created at runtime, git-ignored. |
|
|
53
|
+
|
|
54
|
+
Both are plain JSON. Back them up or edit them by hand.
|
|
55
|
+
|
|
56
|
+
## The agent side
|
|
57
|
+
|
|
58
|
+
The host half registers the `magic_house` tool:
|
|
59
|
+
|
|
60
|
+
`read` · `ideas` · `printer` · `add` · `status` · `remove`
|
|
61
|
+
|
|
62
|
+
So a child can ask "打到哪了" (how far along is it) or say "帮我把今天的乌龟存钱罐记下来" (remember today's turtle bank), and the panel reflects the same board. The printer address and access code are only ever entered in the panel — they are deliberately not parameters of the tool.
|
|
63
|
+
|
|
64
|
+
## Layout
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
index.js host: same-origin routes + the magic_house tool + JSON storage
|
|
68
|
+
lib/mqtt-lite.js dependency-free MQTT 3.1.1 client (TLS, subscribe, keepalive, reconnect)
|
|
69
|
+
lib/printer-link.js printer config, connection lifecycle, report merging
|
|
70
|
+
client.js sidebar entry + panel + the 3D renderer (plain JS, only `react`)
|
|
71
|
+
data/ideas.json idea cards and spin words
|
|
72
|
+
locale/{en,zh}.json Plugin Manager title and description
|
|
73
|
+
icon.svg plugin icon
|
|
74
|
+
test/ the checks below: `npm test`
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Tests
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
npm test
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Four suites, no dependencies: an MQTT client driven against a local TLS "printer" it starts itself (handshake, subscribe, chunked reports, a rejected access code, an unreachable socket), the printer link (config validation, delta merging, payload splitting, credentials at `0600`, reload), and the panel rendered under a small React shim in both a healthy and a route-down world. The 3D scene is asserted through a recording canvas: it must paint faces, recompute volume, and flag an oversized design.
|
|
84
|
+
|
|
85
|
+
The suite simulates the printer so it runs anywhere. Separately, the transport and the link have been run against a real P2S in LAN-only mode and read live progress, layer counts, nozzle/bed temperatures and the job name — so the protocol fields below are not guesses.
|
|
86
|
+
|
|
87
|
+
## Notes for contributors
|
|
88
|
+
|
|
89
|
+
- One `connection.fetch.register` per path. A second registration for the same path throws, and that throw also disposes the effect that owns the first — the panel then gets a plain-text `not found` and shows a JSON error.
|
|
90
|
+
- Use `requestBody: 'buffered'`. A streamed GET body is not a valid `Request`.
|
|
91
|
+
- `socket.setTimeout` is an inactivity timeout, not a handshake deadline: use a one-shot timer cleared on CONNACK, or an idle-but-healthy connection dies between reports.
|
|
92
|
+
- Printer reports can arrive as several JSON documents back to back (sometimes NUL-separated, because one MQTT message caps at 16 KB). Split by brace balance, ignoring braces inside strings.
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT. See [LICENSE](LICENSE).
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# 3D魔法屋
|
|
2
|
+
|
|
3
|
+
给孩子的 3D 打印小工坊,一个 [DeepSeek Harness](https://github.com/deepseek-ai/dsh) 插件。入口在左侧菜单,把孩子从「做点什么好」一路带到「打完了,我又得一颗星」,用的是家里的**拓竹 P2S**。
|
|
4
|
+
|
|
5
|
+
> ⚠️ 这是工坊,不是切片器。它不切片、不下达打印任务、不碰拓竹云。
|
|
6
|
+
|
|
7
|
+
[English →](README.md)
|
|
8
|
+
|
|
9
|
+
## 五步流程
|
|
10
|
+
|
|
11
|
+
| | 步骤 | 实际发生什么 |
|
|
12
|
+
| --- | --- | --- |
|
|
13
|
+
| 1 | **找灵感** | 转「主题 × 功能 × 限制」的转盘(恐龙 / 必须能发光 / 比手掌小),或者从 10 张准备好的灵感卡里挑一张。每张卡都有难度、预估时间、预估克数和三步做法。 |
|
|
14
|
+
| 2 | **量尺寸** | 自己写的 3D 视图,灰框就是 256 毫米打印范围。拖动旋转、滚轮缩放,选方块/圆柱/球/圆锥/圆环,改长宽高;体积、按实心 PLA 估的克数、「装不装得下」实时变。尺寸会记在这件作品上。 |
|
|
15
|
+
| 3 | **排好队** | 作品清单:想法 → 建模 → 打印 → 完成,点一下就往前推,推到完成得一颗星。旁边是六项打印前检查和四条安全须知。 |
|
|
16
|
+
| 4 | **开打** | 填局域网地址、序列号、访问码,然后看实时进度、剩余时间、层数、喷嘴/热床/腔温和当前作品名。**只读。** |
|
|
17
|
+
| 5 | **收星星** | 完成的作品列表(带日期)和星星总数。 |
|
|
18
|
+
|
|
19
|
+
第一步和第二步都能一键交给对话:提示词里带着卡片内容或你刚设的精确尺寸,模型不用猜「多大、什么喷嘴、什么料」。
|
|
20
|
+
|
|
21
|
+
## 安装
|
|
22
|
+
|
|
23
|
+
插件就是一个目录,没有依赖、没有构建步骤。
|
|
24
|
+
|
|
25
|
+
**在应用里**:插件(Plugins)→ **添加插件** → 选这个目录。左侧菜单会出现「**3D魔法屋**」。
|
|
26
|
+
|
|
27
|
+
**从 npm 装**:同一个包也发布在 [`dsh-3d-magic-house`](https://www.npmjs.com/package/dsh-3d-magic-house),在同一个入口填包名即可。
|
|
28
|
+
|
|
29
|
+
不用做别的。已经保存过打印机信息的,下次启动会自动重连。
|
|
30
|
+
|
|
31
|
+
## 连打印机(只用局域网)
|
|
32
|
+
|
|
33
|
+
打印机屏幕上:**设置 → 网络 → 局域网模式(LAN Only)**。记下同一页的 **IP** 和 **序列号**,点「访问码」拿到那串码,填进第 4 步。
|
|
34
|
+
|
|
35
|
+
- 传输:MQTT over TLS,端口 8883,用户 `bblp`,订阅 `device/<序列号>/report`。
|
|
36
|
+
- 全程只发过一条 `pushall` 状态请求。代码里没有任何开始、暂停、取消或修改打印的通路。
|
|
37
|
+
- 2025 年之后的固件可能拒收未签名指令,状态推送一般照常到;一直收不到就把**开发者模式**也打开。
|
|
38
|
+
- 访问码以明文存在 `data/printer.json`,权限 `0600`。它不会被任何路由返回,也不会被工具打印出来。删掉这个文件就等于忘掉它。
|
|
39
|
+
|
|
40
|
+
## 隐私
|
|
41
|
+
|
|
42
|
+
- 面板只和你家局域网里的打印机通信,以及插件自己的同源路由。
|
|
43
|
+
- 不登录拓竹账号、不走云端、没有第三方请求、没有遥测。
|
|
44
|
+
- 3D 视图是几百行 JS 在 2D canvas 上自己算的:没有 three.js、没有 CDN、不联网。
|
|
45
|
+
|
|
46
|
+
## 数据
|
|
47
|
+
|
|
48
|
+
| 文件 | 内容 |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| `data/ideas.json` | 内置灵感卡和转盘词库(随便改)。 |
|
|
51
|
+
| `data/state.json` | 清单:作品、阶段、星星、检查项、正在做的那件。运行时生成,已 gitignore。 |
|
|
52
|
+
| `data/printer.json` | 局域网地址、序列号、访问码(`0600`)。运行时生成,已 gitignore。 |
|
|
53
|
+
|
|
54
|
+
都是纯 JSON,可以直接备份或手改。
|
|
55
|
+
|
|
56
|
+
## 给 AI 的那一半
|
|
57
|
+
|
|
58
|
+
Host 半注册了 `magic_house` 工具:
|
|
59
|
+
|
|
60
|
+
`read` · `ideas` · `printer` · `add` · `status` · `remove`
|
|
61
|
+
|
|
62
|
+
所以孩子可以问「打到哪了」,也可以说「帮我把今天的乌龟存钱罐记下来」——AI 读写的和面板是同一份。打印机地址和访问码**故意**不是工具参数,只能在面板里填。
|
|
63
|
+
|
|
64
|
+
## 目录
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
index.js Host:同源路由 + magic_house 工具 + JSON 存储
|
|
68
|
+
lib/mqtt-lite.js 零依赖 MQTT 3.1.1 客户端(TLS、订阅、心跳、重连)
|
|
69
|
+
lib/printer-link.js 打印机配置、连接生命周期、报告合并
|
|
70
|
+
client.js 侧栏入口 + 面板 + 3D 渲染器(纯 JS,只用 react)
|
|
71
|
+
data/ideas.json 灵感卡与转盘词库
|
|
72
|
+
locale/{en,zh}.json Plugin Manager 里的标题和说明
|
|
73
|
+
icon.svg 插件图标
|
|
74
|
+
test/ 下面的检查:`npm test`
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 测试
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
npm test
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
四个套件,零依赖:MQTT 客户端对着自带的本地 TLS 假打印机跑(握手、订阅、分片报告、访问码被拒、端口不通);打印机链路(配置校验、增量合并、载荷切分、凭据 0600、重启复用);面板在一个小 React 垫片里分别跑「正常」和「路由全 404」两种世界;3D 场景用记录型 canvas 断言:真的画面片、真的重算体积、超大尺寸会被标出来。
|
|
84
|
+
|
|
85
|
+
套件里的打印机是模拟的,所以到处都能跑。分开说一件事:这套传输和链路已经对着一台真的 P2S(局域网模式)跑过——实时进度、层数、喷嘴/热床温度、作品名都读到了,下面的协议字段不是猜的。
|
|
86
|
+
|
|
87
|
+
## 给改代码的人(四个坑)
|
|
88
|
+
|
|
89
|
+
- **一个路径只能注册一次。** `connection.fetch.register` 对同一个 path 的第二次注册会抛错,而这个异常会连带销毁第一次注册的那个 effect——面板拿到纯文本 `not found`,前端却报 JSON 解析错误。
|
|
90
|
+
- **`requestBody` 用 `buffered`。** GET 走 `streaming` 会构造一个带 body 的 GET,不是合法 `Request`。
|
|
91
|
+
- **`socket.setTimeout` 是空闲超时,不是握手超时。** 用它做连接超时会在两次状态推送之间误杀健康连接;握手要用一次性定时器,收到 CONNACK 就清掉。
|
|
92
|
+
- **打印机报告可能是多个 JSON 首尾相接**(有时用 NUL 分隔,因为单条 MQTT 消息上限 16 KB)。按大括号配平切分,并跳过字符串里的括号。
|
|
93
|
+
|
|
94
|
+
## 许可
|
|
95
|
+
|
|
96
|
+
MIT,见 [LICENSE](LICENSE)。
|