@luosuqwq/dsh-diagram 0.0.0-stage → 0.1.2

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/AGENTS.md ADDED
@@ -0,0 +1,83 @@
1
+ # AGENTS.md — dsh-diagram
2
+
3
+ English | [中文](#中文)
4
+
5
+ Machine-actionable notes for coding agents. Human documentation: [README.md](README.md) / [README.zh-CN.md](README.zh-CN.md).
6
+
7
+ ## What this package is
8
+
9
+ A DSH bundle that adds four model-facing tools for turning HTML, a web page or an existing image into PNG and inlining it in the answer. It runs inside the DSH server process and drives the system Chrome/Edge over CDP; it has **zero npm dependencies** and **no dependency on any image plugin** such as `imgr`.
10
+
11
+ ## Install
12
+
13
+ ```sh
14
+ dsh plugin --profile <profile> add @luosuqwq/dsh-diagram
15
+
16
+ git clone https://github.com/LuosuQWQ/dsh-diagram.git
17
+ dsh plugin --profile <profile> add link:<absolute path>/dsh-diagram
18
+ # restart DSH; settings shows nothing extra, the tools are simply mounted
19
+ ```
20
+
21
+ Requirements: DSH 0.2.x, Node 21+, Chrome/Edge/Chromium installed (set `DSH_DIAGRAM_BROWSER` when detection fails).
22
+
23
+ ## Tools
24
+
25
+ - `diagram_render` — HTML fragment or full document → PNG; theme, width, scale, selector, output path.
26
+ - `page_screenshot` — `http(s)` URL, local HTML file or inline HTML; full page or one CSS selector.
27
+ - `image_annotate` — box / ellipse / arrow / line / text / highlight / blur, optional crop, percent coordinates.
28
+ - `diagram_guide` — theme variables, CSS classes and ready-made layouts for the HTML shell.
29
+
30
+ Every tool returns a `markdown` field: paste it as-is; the asset route serves the file. Files are also written to disk (default `.dsh/diagram/` under the session working directory).
31
+
32
+ ## Post-install handoff (agents)
33
+
34
+ Tell the owner, in one short message: restart DSH, then the tools `diagram_render`, `page_screenshot`, `image_annotate` and `diagram_guide` are available; no settings page. Mention that images are rendered with the system Chrome/Edge and written to `.dsh/diagram/` by default.
35
+
36
+ ## Constraints
37
+
38
+ - No npm dependencies; only Node built-ins and the browser's CDP pipe.
39
+ - Do not hardcode a browser path; use `DSH_DIAGRAM_BROWSER` or the probe list.
40
+ - Keep output portable: relative paths resolve against the session cwd.
41
+ - `npm test` is not provided; `node --check index.js lib/*.js` is the minimum gate.
42
+
43
+ ---
44
+
45
+ <a id="中文"></a>
46
+
47
+ # AGENTS.md — dsh-diagram(中文)
48
+
49
+ 给编码 agent 的机器可读说明。人类文档:[README.md](README.md) / [README.zh-CN.md](README.zh-CN.md)。
50
+
51
+ ## 这个包是什么
52
+
53
+ 一个 DSH bundle,挂载 4 个面向模型的工具:把 HTML、网页或已有图片渲染成 PNG,并内联进回答。它跑在 DSH 服务进程里,通过 CDP 驱动系统已装的 Chrome/Edge;**零 npm 依赖**,也**不依赖 imgr 之类的图片插件**。
54
+
55
+ ## 安装
56
+
57
+ ```sh
58
+ git clone https://github.com/LuosuQWQ/dsh-diagram.git
59
+ dsh plugin --profile <profile> add link:<本地绝对路径>/dsh-diagram
60
+ # 重启 DSH,工具即挂载
61
+ ```
62
+
63
+ 要求:DSH 0.2.x、Node 21+、机器上有 Chrome/Edge/Chromium(探测失败时设 `DSH_DIAGRAM_BROWSER`)。
64
+
65
+ ## 工具
66
+
67
+ - `diagram_render`:HTML 片段/整页 → PNG,支持主题、宽度、倍数、选择器、输出路径;
68
+ - `page_screenshot`:URL / 本地 HTML / 内联 HTML,整页或单个 CSS 选择器;
69
+ - `image_annotate`:框、圈、箭头、线、文字、高亮、模糊打码,可先裁剪,坐标支持百分比;
70
+ - `diagram_guide`:主题变量、CSS 类与现成版式。
71
+
72
+ 每个工具都返回 `markdown` 字段,原样贴进回复即可;文件同时落盘(默认会话工作目录下 `.dsh/diagram/`)。
73
+
74
+ ## 安装后交接(给 agent)
75
+
76
+ 用一句话告诉主人:重启 DSH 后即可使用 `diagram_render`、`page_screenshot`、`image_annotate`、`diagram_guide`,没有设置页;图片由系统 Chrome/Edge 渲染,默认写到 `.dsh/diagram/`。
77
+
78
+ ## 约束
79
+
80
+ - 不引入 npm 依赖,只用 Node 内置模块和浏览器 CDP;
81
+ - 不写死浏览器路径,用 `DSH_DIAGRAM_BROWSER` 或探测列表;
82
+ - 输出保持可移植:相对路径按会话 cwd 解析;
83
+ - 没有 `npm test`;最低门槛是 `node --check index.js lib/*.js`。
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LuoSu
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/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Temporary Holding Version
1
+ English | [简体中文](README.zh-CN.md)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ # dsh-diagram
4
+
5
+ > Render diagrams, page screenshots and annotated images to PNG inside DSH answers.
6
+
7
+ A DeepSeek Harness answer is text, but some explanations are really about a flow, a structure, a comparison or "where exactly in this screenshot". This bundle gives the agent four tools that turn HTML, a web page or an existing image into a PNG file and inline it in the conversation. Rendering uses the Chrome or Edge already installed on the machine: no bundled browser, no npm packages, no external service.
8
+
9
+ ![dsh-diagram](docs/preview/hero.jpg)
10
+
11
+ ## Features
12
+
13
+ - **Diagrams from HTML.** `diagram_render` wraps a fragment in a shell with a CJK font stack, a dark or light theme and `.card` `.grid` `.arrow` `.pill` `table` utility classes, then crops to the content height and renders at 2× by default.
14
+ - **Page screenshots.** `page_screenshot` captures an `http(s)` URL, a local HTML file or inline HTML — the whole page or just the element matched by a CSS selector.
15
+ - **Annotations.** `image_annotate` draws boxes, ellipses, arrows, lines, text labels, highlights and blur redaction on an existing image, optionally after cropping it.
16
+ - **Built-in style guide.** `diagram_guide` returns the theme variables, available classes and three ready-made layouts, so the agent does not have to guess the shell.
17
+ - **Inline in chat.** Every tool returns a `markdown` line served from the bundle's own asset route; paste it as-is and the picture appears in the answer.
18
+ - **Real files on disk.** Each render is also saved as a file, by default under `.dsh/diagram/` in the session working directory.
19
+
20
+ ## Example
21
+
22
+ ![An annotated composition study](docs/preview/annotation.jpg)
23
+
24
+ One call to `image_annotate` produced all five marks on this picture: **1** the face as the focal point, **2** the gaze / visual lead-in toward the mint, **3** the body diagonal, **4** deliberate negative space, **5** the warm-red vs cool-green accent. Coordinates are original pixels; shapes, arrows and labels are drawn on the fly.
25
+
26
+ > After installing, tell the owner: restart DSH; the four tools are mounted with no settings page. If no Chrome/Edge is found, set `DSH_DIAGRAM_BROWSER`.
27
+
28
+ ## Requirements
29
+
30
+ - DeepSeek Harness 0.2.x (developed against 0.2.2-rc.5).
31
+ - Node.js 21 or newer, as declared in `engines`; the Node runtime that ships with DSH satisfies it.
32
+ - Chrome, Edge or Chromium installed on the same machine. The engine probes the usual Windows, macOS and Linux locations; set `DSH_DIAGRAM_BROWSER` when it cannot find one.
33
+ - A CJK font for Chinese labels — Microsoft YaHei on Windows, PingFang on macOS, Noto Sans CJK or Source Han Sans on Linux. The font stack falls back to `system-ui`.
34
+ - Nothing else: apart from the DSH tool API, the renderer imports only Node built-ins, and it runs inside the DSH server process.
35
+
36
+ ## Install
37
+
38
+ This directory is a DSH bundle: `package.json` points `dsh.bundle.patch` at `cordis.patch.yml`, which inserts one composition row.
39
+
40
+ Install it from the checkout with the plugin manager:
41
+
42
+ ```text
43
+ plugin_manager: { action: "install_bundle", target: "<path-to-checkout>" }
44
+ ```
45
+
46
+ dsh plugin --profile <profile> add @luosuqwq/dsh-diagram
47
+
48
+ Or add it to a profile by hand — in the profile's `package.json`:
49
+
50
+ ```json
51
+ {
52
+ "dependencies": {
53
+ "@luosuqwq/dsh-diagram": "link:<path-to-checkout>"
54
+ },
55
+ "dsh": {
56
+ "profile": {
57
+ "bundles": ["@luosuqwq/dsh-diagram"]
58
+ }
59
+ }
60
+ }
61
+ ```
62
+
63
+ then run `pnpm install` in the profile directory.
64
+
65
+ Restart DSH after installing: the tools are registered by the server-side half of the bundle when the process starts. Removing the bundle is `plugin_manager: { action: "remove_bundle", target: "dsh-diagram" }`, plus dropping the row from the profile.
66
+
67
+ ## Configuration
68
+
69
+ | Variable | Type | Default | Purpose |
70
+ | --- | --- | --- | --- |
71
+ | `DSH_DIAGRAM_BROWSER` | path | unset (auto-detect) | Full path to the Chrome/Edge/Chromium executable used for rendering. |
72
+
73
+ There are no profile config keys and no settings page: every option is a per-call tool argument, listed under Usage.
74
+
75
+ ## Usage
76
+
77
+ | Tool | What it does | Key arguments |
78
+ | --- | --- | --- |
79
+ | `diagram_render` | HTML fragment or document → explanatory PNG | `html`, `title`, `subtitle`, `theme` (`dark`/`light`), `width`, `height`, `scale`, `css`, `out` |
80
+ | `page_screenshot` | URL, local file or inline HTML → PNG | `url` / `file` / `html`, `width`, `height`, `fullPage`, `selector`, `waitMs`, `scale`, `out` |
81
+ | `image_annotate` | Existing image + `ops` → annotated PNG | `image`, `ops`, `crop`, `unit` (`px`/`percent`), `scale`, `out` |
82
+ | `diagram_guide` | Style guide as text | — |
83
+
84
+ The bundle also adds a short system-prompt section, so the agent prefers a rendered figure over ASCII art and avoids posting the same image twice.
85
+
86
+ A minimal `diagram_render` call:
87
+
88
+ ```json
89
+ {
90
+ "title": "Request path",
91
+ "subtitle": "client → cache → origin",
92
+ "theme": "dark",
93
+ "html": "<div class=\"grid\"><div class=\"card\"><h3>Client</h3><p>sends a request</p></div><div class=\"arrow\">→</div><div class=\"card\"><h3>Cache</h3><p>answers on a hit</p></div><div class=\"arrow\">→</div><div class=\"card\"><h3>Origin</h3><p>handles a miss</p></div></div>"
94
+ }
95
+ ```
96
+
97
+ The result carries `path`, `url`, `width`, `height`, `bytes` and `markdown`; the Markdown link points at `/plugins/dsh-diagram/asset?file=...` on the DSH web server, so it renders inline as long as the value is copied unchanged.
98
+
99
+ Defaults worth knowing: `diagram_render` uses width 1200, theme `dark` and scale 2 (output is twice the canvas size); `page_screenshot` uses a 1440×900 viewport, scale 2 and a 400 ms wait after load; `image_annotate` uses scale 2.
100
+
101
+ Annotation operations use these fields (defaults in parentheses):
102
+
103
+ | `type` | Shape |
104
+ | --- | --- |
105
+ | `box` | `x`, `y`, `width`, `height`, `color` (`#ff4d4f`), `strokeWidth` (4), `radius` (8), `label` |
106
+ | `highlight` | `x`, `y`, `width`, `height`, `color`, `opacity` (0.22) |
107
+ | `blur` | `x`, `y`, `width`, `height` — redacts by re-drawing the source behind a CSS blur |
108
+ | `ellipse` | `x`, `y`, `width`, `height`, `color`, `strokeWidth`, `label` |
109
+ | `arrow` / `line` | `x`, `y`, `x2`, `y2`, `color`, `strokeWidth`, `label` |
110
+ | `text` | `x`, `y` (baseline), `text`, `fontSize` (20), `color` |
111
+
112
+ `unit: "percent"` reads `x` and `width` as fractions of the image width and `y`/`height` as fractions of its height; `crop` is always in pixels.
113
+
114
+ ## How it works
115
+
116
+ - Every render starts a temporary headless Chromium with its own `--user-data-dir` under the OS temp directory; the process tree is killed and the directory removed when the capture finishes.
117
+ - The browser is driven over the DevTools protocol on `--remote-debugging-pipe` (fd 3 and fd 4, NUL-separated JSON) instead of a TCP port, so proxy environment variables that intercept localhost connections cannot break it.
118
+ - Content height is measured from the body subtree rather than `scrollHeight`, because both `scrollHeight` and `Page.getLayoutMetrics` refuse to report less than the viewport height.
119
+ - `image_annotate` renders the source image in a page and draws an SVG overlay on top; `blur` regions re-draw the image inside a CSS-filtered box.
120
+ - PNGs are written by the DSH server process and served by the bundle's own route (`GET`/`HEAD`, known image MIME types only, `cache-control: no-store`).
121
+
122
+ ## Limitations
123
+
124
+ - A cold browser start costs roughly 1–2 seconds per render; this is not a tool for large batches.
125
+ - Only addresses this machine can reach: `file://` paths and `http(s)` URLs. Every render uses an empty browser profile, so pages that need a login are captured logged out.
126
+ - Height caps: `page_screenshot` stops at 12000 px, content-height `diagram_render` at 8000 px. Longer pages are cut off rather than scaled.
127
+ - Output is PNG only.
128
+ - `page_screenshot` on an image file lays that image out as a web page, so the result gets padded to the viewport; use `image_annotate` for images.
129
+ - Annotation coordinates come from the caller. When the pixel size is unknown, use `unit: "percent"` or crop first.
130
+
131
+ ## Development
132
+
133
+ Both suites run without the DSH runtime, need a working Chrome/Edge, and write PNGs into `test/out/`:
134
+
135
+ ```bash
136
+ node test/smoke.mjs
137
+ node test/tool-path.mjs
138
+ ```
139
+
140
+ `smoke.mjs` exercises the rendering engine (diagram, full-page screenshot, annotate, crop + annotate) and prints the pixel size of each image. `tool-path.mjs` registers the plugin against a stub `ctx`, calls all four tools, then fetches the returned Markdown URL through the bundle's own route and checks the PNG bytes. Both exit non-zero on failure.
141
+
142
+ ## License
143
+
144
+ MIT. See [LICENSE](LICENSE).
@@ -0,0 +1,142 @@
1
+ [English](README.md) | 简体中文
2
+
3
+ # dsh-diagram
4
+
5
+ > 在 DSH 的回答里直接生成图示、网页截图与标注图片,输出 PNG。
6
+
7
+ DeepSeek Harness 的回答本身是文字,但有些解释说的是流程、结构、对比,或者「这一点在截图里的哪里」。这个 bundle 给模型四个工具,把 HTML、网页或已有图片变成 PNG,并内联到对话里。渲染直接用机器上已装的 Chrome 或 Edge:不带浏览器、不装 npm 包、不连外部服务。
8
+
9
+ ![dsh-diagram](docs/preview/hero.jpg)
10
+
11
+ ## 功能
12
+
13
+ - **用 HTML 画图。** `diagram_render` 把片段套进统一外壳:中文字体栈、深/浅主题,以及 `.card` `.grid` `.arrow` `.pill` `table` 等样式类;高度默认按内容裁剪,输出默认 2 倍图。
14
+ - **网页截图。** `page_screenshot` 截 `http(s)` 地址、本地 HTML 文件或内联 HTML,可以整页,也可以只截某个 CSS 选择器命中的元素。
15
+ - **图片标注。** `image_annotate` 在已有图片上画框、圈、箭头、直线、文字、高亮与模糊打码,也可以先裁剪再标注。
16
+ - **内置样式指南。** `diagram_guide` 返回主题变量、可用类与三个现成版式,模型不必猜外壳支持什么。
17
+ - **直接内联。** 每个工具都返回一行 `markdown`,指向本 bundle 自己的取图路由;原样放进回答,图就出现在对话里。
18
+ - **文件真实落盘。** 每次出图同时写一个文件,默认在会话工作目录的 `.dsh/diagram/` 下。
19
+
20
+ ## 示例
21
+
22
+ ![构图要点标注](docs/preview/annotation.jpg)
23
+
24
+ 一次 `image_annotate` 调用画出五处标记:**1** 脸部作为视觉焦点,**2** 视线/引导线指向薄荷叶,**3** 身体对角线,**4** 刻意留出的负空间,**5** 暖红与冷绿的对比。坐标按原图像素,框、箭头、文字都是即时绘制。
25
+
26
+ > 装好后请告诉主人:重启 DSH,四个工具即挂载,没有设置页。找不到 Chrome/Edge 时设 `DSH_DIAGRAM_BROWSER`。
27
+
28
+ ## 运行要求
29
+
30
+ - DeepSeek Harness 0.2.x(基于 0.2.2-rc.5 开发验证)。
31
+ - Node.js 21 或更高(`engines` 里的声明);DSH 自带的 Node 运行时满足这一条。
32
+ - 同机安装 Chrome、Edge 或 Chromium。渲染会探测 Windows/macOS/Linux 的常见安装位置;找不到时用环境变量 `DSH_DIAGRAM_BROWSER` 指定。
33
+ - 要画中文就还需要中文字体:Windows 的微软雅黑、macOS 的苹方,或 Linux 的 Noto Sans CJK/思源黑体;字体栈最终回退到 `system-ui`。
34
+ - 其他依赖没有:除了 DSH 的工具 API,渲染只 import Node 内置模块,跑在 DSH 服务进程里。
35
+
36
+ ## 安装
37
+
38
+ 这个目录是一个 DSH bundle:`package.json` 的 `dsh.bundle.patch` 指向 `cordis.patch.yml`,里面插入一行组合项。
39
+
40
+ 用插件管理器从检出目录安装:
41
+
42
+ ```text
43
+ plugin_manager: { action: "install_bundle", target: "<path-to-checkout>" }
44
+ ```
45
+
46
+ 也可以手工写进 profile 的 `package.json`:
47
+
48
+ ```json
49
+ {
50
+ "dependencies": {
51
+ "dsh-diagram": "link:<path-to-checkout>"
52
+ },
53
+ "dsh": {
54
+ "profile": {
55
+ "bundles": ["dsh-diagram"]
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ 然后在 profile 目录执行 `pnpm install`。
62
+
63
+ 安装后需要重启 DSH:四个工具由 bundle 的服务端半在进程启动时注册。卸载用 `plugin_manager: { action: "remove_bundle", target: "dsh-diagram" }`,同时把 profile 里那一行去掉。
64
+
65
+ ## 配置
66
+
67
+ | 环境变量 | 类型 | 默认值 | 说明 |
68
+ | --- | --- | --- | --- |
69
+ | `DSH_DIAGRAM_BROWSER` | 路径 | 未设置(自动探测) | 指定渲染用的 Chrome/Edge/Chromium 可执行文件。 |
70
+
71
+ 没有 profile 配置项,也没有设置页:所有选项都是单次调用时传的参数,见下节。
72
+
73
+ ## 使用
74
+
75
+ | 工具 | 作用 | 主要参数 |
76
+ | --- | --- | --- |
77
+ | `diagram_render` | HTML 片段或整页文档 → 说明图 PNG | `html`、`title`、`subtitle`、`theme`(`dark`/`light`)、`width`、`height`、`scale`、`css`、`out` |
78
+ | `page_screenshot` | 地址、本地文件或内联 HTML → PNG | `url` / `file` / `html`、`width`、`height`、`fullPage`、`selector`、`waitMs`、`scale`、`out` |
79
+ | `image_annotate` | 已有图片 + `ops` → 标注 PNG | `image`、`ops`、`crop`、`unit`(`px`/`percent`)、`scale`、`out` |
80
+ | `diagram_guide` | 返回样式指南文本 | — |
81
+
82
+ 这个 bundle 还会注册一小段系统提示,让模型优先出图而不是画 ASCII 示意图,并且不会把同一张图贴两遍。
83
+
84
+ 一个最小的 `diagram_render` 调用:
85
+
86
+ ```json
87
+ {
88
+ "title": "请求链路",
89
+ "subtitle": "客户端 → 缓存 → 源站",
90
+ "theme": "dark",
91
+ "html": "<div class=\"grid\"><div class=\"card\"><h3>客户端</h3><p>发出请求</p></div><div class=\"arrow\">→</div><div class=\"card\"><h3>缓存</h3><p>命中即返回</p></div><div class=\"arrow\">→</div><div class=\"card\"><h3>源站</h3><p>未命中时处理</p></div></div>"
92
+ }
93
+ ```
94
+
95
+ 返回结果里有 `path`、`url`、`width`、`height`、`bytes` 和 `markdown`;`markdown` 指向 DSH 服务的 `/plugins/dsh-diagram/asset?file=...`,只要原样复制就能内联显示。
96
+
97
+ 几个值得记住的默认值:`diagram_render` 宽度 1200、主题 `dark`、倍率 2(输出是画布的 2 倍像素);`page_screenshot` 视口 1440×900、倍率 2、页面载入后额外等 400 ms;`image_annotate` 倍率 2。
98
+
99
+ 标注操作(`ops`)的字段与默认值:
100
+
101
+ | `type` | 形状 |
102
+ | --- | --- |
103
+ | `box` | `x`、`y`、`width`、`height`、`color`(`#ff4d4f`)、`strokeWidth`(4)、`radius`(8)、`label` |
104
+ | `highlight` | `x`、`y`、`width`、`height`、`color`、`opacity`(0.22) |
105
+ | `blur` | `x`、`y`、`width`、`height` —— 用 CSS 模糊重绘原图实现打码 |
106
+ | `ellipse` | `x`、`y`、`width`、`height`、`color`、`strokeWidth`、`label` |
107
+ | `arrow` / `line` | `x`、`y`、`x2`、`y2`、`color`、`strokeWidth`、`label` |
108
+ | `text` | `x`、`y`(基线)、`text`、`fontSize`(20)、`color` |
109
+
110
+ `unit: "percent"` 时,`x` 与 `width` 是图片宽度的 0–1 比例,`y` 与 `height` 是高度的比例;`crop` 始终按像素。
111
+
112
+ ## 实现机制
113
+
114
+ - 每次渲染起一个临时的无头 Chromium,`--user-data-dir` 指向系统临时目录下的独立目录;截图完成后连同进程树一起收掉,临时目录随后删除。
115
+ - 浏览器走 DevTools 协议的 `--remote-debugging-pipe`(fd 3 写、fd 4 读,NUL 分隔的 JSON),不开 TCP 端口,所以拦截 localhost 的代理环境变量影响不到它。
116
+ - 内容高度不是读 `scrollHeight`:`scrollHeight` 和 `Page.getLayoutMetrics` 都不会小于视口高度,所以改为量 body 子树里最靠下的底边。
117
+ - `image_annotate` 先把原图放进一个页面,再在上面叠一层 SVG;`blur` 区域则是在被裁剪的盒子里用 CSS 滤镜重绘原图。
118
+ - PNG 由 DSH 服务进程写盘,并由本 bundle 自己的路由提供(只接受 `GET`/`HEAD`、只发已知图片类型、`cache-control: no-store`)。
119
+
120
+ ## 已知限制
121
+
122
+ - 每次渲染都冷启动一个浏览器,大约 1–2 秒开销;不适合大批量出图。
123
+ - 只能访问本机够得到的地址:`file://` 路径和 `http(s)` 链接。每次都用全新的空浏览器配置,所以需要登录的页面截到的是未登录状态。
124
+ - 高度上限:`page_screenshot` 12000 px,按内容裁剪的 `diagram_render` 8000 px;更长的页面会被截断,不会整体缩放。
125
+ - 输出只有 PNG。
126
+ - 对图片文件调用 `page_screenshot` 会按网页排版,结果高度被视口撑开;要标注图片请直接用 `image_annotate`。
127
+ - 标注坐标由调用方给出;不知道像素尺寸时用 `unit: "percent"`,或者先 `crop` 再标。
128
+
129
+ ## 开发
130
+
131
+ 两个测试都不需要 DSH 运行时,但需要可用的 Chrome/Edge,图片写到 `test/out/`:
132
+
133
+ ```bash
134
+ node test/smoke.mjs
135
+ node test/tool-path.mjs
136
+ ```
137
+
138
+ `smoke.mjs` 测渲染引擎(示意图、整页截图、标注、裁剪后再标注),逐张打印像素尺寸。`tool-path.mjs` 用桩 `ctx` 注册插件、调用四个工具,再通过本 bundle 自己的路由把返回的 Markdown 链接取回来校验 PNG 字节。任一失败都以非零退出码结束。
139
+
140
+ ## 许可证
141
+
142
+ MIT,见 [LICENSE](LICENSE)。
@@ -0,0 +1,5 @@
1
+ # This bundle owns its composition row; the Plugins page switch toggles the
2
+ # whole bundle, and the per-row switch writes `{ id, disabled }` here.
3
+ - insert:
4
+ - id: dsh-diagram
5
+ name: @luosuqwq/dsh-diagram
@@ -0,0 +1,100 @@
1
+ # 图示渲染指南
2
+
3
+ ## 先选工具
4
+
5
+ | 想做的事 | 工具 |
6
+ | --- | --- |
7
+ | 用自己的文字/框框/连线讲清流程、结构、对比、层级 | `diagram_render` |
8
+ | 把某个网页、或磁盘上已有的 HTML 报告截成图 | `page_screenshot` |
9
+ | 在已有截图/照片上圈重点、加箭头文字、打码 | `image_annotate` |
10
+
11
+ 三步做完再回答:出图 → 把返回的 Markdown 原样放进回答 → 用一两句话说明图里该看什么。不要把同一张图重复贴两次。
12
+
13
+ ## 画布与倍率
14
+
15
+ - `width` 默认 1200。信息密度高时用 1500;纵向长图也行,`height` 省略会按内容自动裁剪(推荐)。
16
+ - `scale` 默认 2,输出是画布尺寸的 2 倍像素,在聊天里更清晰。
17
+ - 画布宽度有限,别写 5 列以上并排卡片;超过 3 列就换行。
18
+
19
+ ## 主题变量(片段里可直接用)
20
+
21
+ `--bg` 背景、`--panel` 卡片底、`--fg` 正文、`--muted` 次要文字、`--line` 描边、`--accent` 强调色、`--accent-soft` 强调底色、`--warn` / `--good` / `--bad` 状态色。
22
+
23
+ 需要固定颜色时写 `var(--accent)`,不要硬编码 `#5b8cff`,否则 `theme: light` 下会看不清。
24
+
25
+ ## 直接可用的类
26
+
27
+ `.doc` 页面内边距容器 · `h1` 大标题 · `.lead` 副标题 · `.grid` 横向弹性容器 · `.card` 卡片 · `.card h3` 卡片标题 · `.card p` 卡片正文 · `.card ul` 卡片列表 · `.arrow` 居中箭头 · `.pill` 胶囊标签 · `.accent` 强调文字 · `.dim` 次要文字 · `.mono` 等宽字体 · `table/th/td` 表格 · `code` 行内代码 · `.note` 脚注。
28
+
29
+ ## 片段 1:三步流程
30
+
31
+ ```html
32
+ <div class="grid">
33
+ <div class="card"><h3>① 收集</h3><p>把散落的记录先归到一处。</p></div>
34
+ <div class="arrow">→</div>
35
+ <div class="card"><h3>② 归纳</h3><p>按主题合并,去掉重复项。</p></div>
36
+ <div class="arrow">→</div>
37
+ <div class="card"><h3>③ 输出</h3><p>一段结论加三条待办。</p></div>
38
+ </div>
39
+ ```
40
+
41
+ ## 片段 2:对比与清单
42
+
43
+ ```html
44
+ <table>
45
+ <tr><th>维度</th><th>方案 A</th><th>方案 B</th></tr>
46
+ <tr><td>启动成本</td><td>低</td><td class="accent">中</td></tr>
47
+ <tr><td>长期维护</td><td class="accent">简单</td><td>需要专人</td></tr>
48
+ </table>
49
+ <div class="grid" style="margin-top:18px">
50
+ <div class="card"><h3>适合 A</h3><ul><li>先验证想法</li><li>两周内要上线</li></ul></div>
51
+ <div class="card"><h3>适合 B</h3><ul><li>长期高频使用</li><li>有维护人手</li></ul></div>
52
+ </div>
53
+ ```
54
+
55
+ ## 片段 3:结构图(SVG 连线)
56
+
57
+ 画布宽度可预测时,用固定坐标的 SVG 最省事:盒子和连线都在同一张 SVG 里,坐标以 1200 宽画布为准。
58
+
59
+ ```html
60
+ <svg width="1120" height="260" style="display:block">
61
+ <defs>
62
+ <marker id="a" markerWidth="10" markerHeight="8" refX="9" refY="4" orient="auto">
63
+ <path d="M0,0 L10,4 L0,8 Z" fill="var(--accent)"></path>
64
+ </marker>
65
+ </defs>
66
+ <rect x="0" y="40" width="220" height="90" rx="12" fill="var(--panel)" stroke="var(--line)"></rect>
67
+ <text x="20" y="80" fill="var(--fg)" font-size="19">请求</text>
68
+ <text x="20" y="108" fill="var(--muted)" font-size="14">用户输入</text>
69
+ <line x1="228" y1="85" x2="318" y2="85" stroke="var(--accent)" stroke-width="3" marker-end="url(#a)"></line>
70
+ <rect x="330" y="40" width="220" height="90" rx="12" fill="var(--panel)" stroke="var(--line)"></rect>
71
+ <text x="350" y="80" fill="var(--fg)" font-size="19">处理</text>
72
+ <text x="350" y="108" fill="var(--muted)" font-size="14">规则 + 模型</text>
73
+ </svg>
74
+ ```
75
+
76
+ SVG 的 `font-family` 继承 body,中文字体不用另设。
77
+
78
+ ## 标注(image_annotate)
79
+
80
+ ```json
81
+ { "type": "box", "x": 120, "y": 80, "width": 300, "height": 120, "label": "这里" }
82
+ ```
83
+
84
+ 坐标默认是原图像素。拿不准原图尺寸时用 `"unit": "percent"`,此时 x / width 是图片宽度的 0–1 比例,y / height 是高度的比例:`{ "type": "box", "x": 0.08, "y": 0.12, "width": 0.3, "height": 0.2 }` 就是左上角那一片。`crop` 始终按像素。
85
+
86
+ 常用组合:
87
+
88
+ - 圈住一个小东西:`{ "type": "ellipse", "x": 0.42, "y": 0.36, "width": 0.08, "height": 0.06 }`
89
+ - 加箭头说明:`{ "type": "arrow", "x": 0.55, "y": 0.2, "x2": 0.72, "y2": 0.34, "label": "原因" }`
90
+ - 一段说明文字:`{ "type": "text", "x": 0.04, "y": 0.25, "text": "这一列是缓存命中率", "fontSize": 24 }`
91
+ - 打码:`{ "type": "blur", "x": 0.3, "y": 0.4, "width": 0.24, "height": 0.06 }`
92
+
93
+ 同一张图上标注超过 5 处会糊,先裁剪(`crop`)再标。
94
+
95
+ ## 常见坑
96
+
97
+ - 片段里别写 `<body>`、`<html>`、全局 `background`,那是外壳的事;只有给完整文档时(`<!doctype html>` 开头)才自己负责全部样式。
98
+ - 用 `flex` 布局时给卡片 `flex: 1 1 0`,否则宽度会塌。
99
+ - 文字别超过约 22 个字一行,38px 大标题 + 15.5px 正文是外壳默认的层级。
100
+ - 出图后先自己看一眼:把图片路径传给 `read_image`,确认没有文字溢出、没有重叠。
package/icon.svg ADDED
@@ -0,0 +1,12 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" color="#5b6673">
2
+ <g fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round" stroke-linejoin="round">
3
+ <rect x="7" y="13" width="14" height="14" rx="4"/>
4
+ <circle cx="14" cy="45" r="6"/>
5
+ <path d="M14 27v12"/>
6
+ <path d="M23 32h6"/>
7
+ <path d="M29 27.5 33.5 32 29 36.5" stroke="#3b78b5"/>
8
+ <rect x="38" y="11" width="20" height="42" rx="5"/>
9
+ <circle cx="46" cy="21" r="2.4" fill="currentColor" stroke="none"/>
10
+ <path d="M42 45 46 38 49.5 43.5 51.5 41 53.8 45.2"/>
11
+ </g>
12
+ </svg>