dsh-diagram-studio 0.0.0-stage → 1.0.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 ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ First public release.
6
+
7
+ - Diagram Studio panel in the DSH Web UI, available from the left sidebar and the right sidebar guide tab.
8
+ - Preview rendered PNG and open a full-screen lightbox with download.
9
+ - Edit node labels, positions, shapes, and font sizes.
10
+ - Edit edge arrows, line style, labels, and direction names.
11
+ - Overall controls: canvas ratio, auto/grid layout, columns, rows, gaps, margins, font size, line width, edge width, and style profile.
12
+ - Spec card: `blueprint.spec` with intent, required nodes, required edges, groups, and constraints.
13
+ - Deterministic doctor: missing nodes/edges, bad endpoints, duplicate edges, orphan nodes, group references, node limits, missing edge labels, out-of-bounds, overlap, and estimated crossings.
14
+ - Natural-language repair requests: the agent writes a reviewable `repair-plan.json`; selected operations are applied atomically.
15
+ - Reference image drop: saves `diagram.*` into a new `diagrams/ref-*` folder and triggers an agent turn for observation card → blueprint → render.
16
+ - Undo history for local patches; invalid patches never overwrite the blueprint.
17
+ - Rendered changelog with headings, lists, inline code, and bold text.
18
+ - Light/dark theme support through DSH theme tokens.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Diagram Studio contributors
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,226 @@
1
- # Temporary Holding Version
1
+ # Diagram Studio
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
+ **Spec-driven diagram review, deterministic doctor, and natural-language repair for DSH + `diagram-draw`.**
4
+
5
+ Diagram Studio is a DSH Web UI plugin for diagrams that are rendered from a `blueprint.json` by the local `diagram-draw` skill.
6
+
7
+ It does not generate images with an image API. It reads the blueprint, renders locally, and gives you a reviewable loop:
8
+
9
+ ```text
10
+ spec → blueprint → SVG/PNG/HTML → doctor → repair plan → atomic patch → re-render
11
+ ```
12
+
13
+ ![Diagram Studio](docs/cover.png)
14
+
15
+ _A real diagram rendered locally by `diagram-draw`._
16
+
17
+ | Flow | Timing |
18
+ |---|---|
19
+ | ![Flow](docs/login-flow.png) | ![Timing](docs/timing.png) |
20
+
21
+ ## Why this exists
22
+
23
+ AI-generated diagrams often fail for structural reasons: a missing module, a wrong edge, an ambiguous hierarchy, or a layout that cannot be fixed by changing font size. Repeatedly asking the model to “redraw it” makes those problems drift.
24
+
25
+ Diagram Studio adds the missing layer:
26
+
27
+ - **Spec** — make the required nodes, edges, groups, and acceptance constraints explicit.
28
+ - **Doctor** — turn “it looks wrong” into a concrete, clickable issue list.
29
+ - **Repair plan** — natural language becomes a reviewable diff, not a full redraw.
30
+
31
+ ## Features
32
+
33
+ ### Preview and inspect
34
+
35
+ - Preview the rendered PNG
36
+ - Full-screen lightbox with download
37
+ - Click a block in the preview to select the node
38
+ - Theme-token styling for light and dark UI
39
+
40
+ ### Local editing
41
+
42
+ - Node label, column/row, shape, and font size
43
+ - Edge arrow, solid/dashed style, and edge name/label
44
+ - Undo history
45
+ - Preview-only for timing and circuit diagrams; use the blueprint/patch CLI for their structure
46
+
47
+ ### Overall controls
48
+
49
+ - Canvas ratio: 16:9, 4:3, 3:4
50
+ - Grid / auto layout
51
+ - Column widths and row heights
52
+ - Horizontal/vertical gaps
53
+ - Margins
54
+ - Global font size
55
+ - Stroke width and edge width
56
+ - Style profile
57
+
58
+ ### Spec card
59
+
60
+ `blueprint.spec` is an acceptance contract, not a second copy of the diagram:
61
+
62
+ ```json
63
+ {
64
+ "intent": "Explain the CPU / cache / main-memory hierarchy",
65
+ "diagramType": "block",
66
+ "mustNodes": ["cpu", "cache", "memory"],
67
+ "mustEdges": [
68
+ { "from": "cpu", "to": "cache" },
69
+ { "from": "cache", "to": "memory" }
70
+ ],
71
+ "groups": [],
72
+ "constraints": {
73
+ "direction": "left-right",
74
+ "maxNodes": 12,
75
+ "maxEdgeCrossings": 0,
76
+ "requireEdgeLabels": true
77
+ }
78
+ }
79
+ ```
80
+
81
+ The UI can extract a spec from an existing diagram and edit it in a form.
82
+
83
+ ### Doctor
84
+
85
+ The doctor is deterministic and read-only. It checks:
86
+
87
+ - missing required nodes/edges
88
+ - broken edge endpoints
89
+ - duplicate edges
90
+ - orphan nodes
91
+ - group references to missing nodes
92
+ - node count over the spec limit
93
+ - missing edge labels when required
94
+ - out-of-bounds nodes
95
+ - overlapping nodes
96
+ - estimated edge crossings
97
+
98
+ Each issue has a severity, a target node/edge, and a hint. Clicking an issue selects the target.
99
+
100
+ ### Natural-language repair
101
+
102
+ Describe the problem in the panel. The current agent writes a `repair-plan.json`; the UI shows a diff with checkboxes. Only selected operations are applied.
103
+
104
+ ```json
105
+ {
106
+ "summary": "Move the memory matrix up and separate address/data paths",
107
+ "scope": "structure",
108
+ "operations": [
109
+ { "op": "move_node", "id": "matrix", "row": 1 },
110
+ { "op": "add_group", "group": { "id": "addr-path", "label": "Address path", "nodes": ["mar", "decoder"] } }
111
+ ],
112
+ "risks": ["3 nodes will move"],
113
+ "questions": []
114
+ }
115
+ ```
116
+
117
+ Supported operations: `set_label`, `move_node`, `set_edge`, `set_style`, `set_global`, `set_spec`, `add_group`, `remove_group`.
118
+
119
+ The plan is applied by the same Python patch core used by the CLI, with temporary-render validation before commit.
120
+
121
+ ### Reference image drop
122
+
123
+ Drop a PNG/JPEG/WebP/GIF into the panel. The image is saved as:
124
+
125
+ ```text
126
+ diagrams/ref-<timestamp>-<id>/reference.<ext>
127
+ ```
128
+
129
+ The plugin then queues an agent prompt to run:
130
+
131
+ ```text
132
+ observation card → blueprint → render → self-check → comparison table
133
+ ```
134
+
135
+ This requires the current model to support image input.
136
+
137
+ ## Install
138
+
139
+ ### 1. Prerequisite: `diagram-draw` skill
140
+
141
+ The UI is a studio for the local `diagram-draw` skill. Install the skill at:
142
+
143
+ ```text
144
+ ~/.dsh/skills/diagram-draw/
145
+ ```
146
+
147
+ or point the Host at another directory with:
148
+
149
+ ```bash
150
+ DIAGRAM_DRAW_SKILL_DIR=/absolute/path/to/diagram-draw
151
+ ```
152
+
153
+ The release also ships `diagram-draw-skill.zip` and `install-skill.ps1`. From the release folder:
154
+
155
+ ```powershell
156
+ .\install-skill.ps1
157
+ ```
158
+
159
+ The extracted folder must contain `SKILL.md`, `scripts/`, and `references/`.
160
+
161
+ ### 2. Install the plugin bundle
162
+
163
+ Install `dsh-diagram-studio` as a DSH bundle, for example from the DSH Plugin Manager, or with the `plugin_manager` tool:
164
+
165
+ ```text
166
+ action: install_bundle
167
+ target: dsh-diagram-studio
168
+ ```
169
+
170
+ For a local checkout, point `target` at this directory. After installation, disable/enable the `diagram-studio` row or restart DSH, then refresh the page.
171
+
172
+ The panel appears in the left sidebar as **画图** and in the right-side guide tab.
173
+
174
+ ### 3. Runtime requirements
175
+
176
+ - DSH Desktop / Web with Client plugin support
177
+ - Node.js 20+
178
+ - Python 3.10+
179
+ - Pillow
180
+ - Microsoft YaHei / Noto Sans SC (or another CJK font)
181
+ - Edge/Chrome for PNG export; SVG/HTML work without it
182
+
183
+ ## Usage
184
+
185
+ 1. Open a workspace that contains `diagrams/<slug>/blueprint.json`.
186
+ 2. Open **画图** in the left sidebar.
187
+ 3. Check the **规格** card; generate or edit the spec.
188
+ 4. Read the **体检** card and fix structural issues first.
189
+ 5. Use **描述问题** for layout/semantic changes; review the plan and apply selected operations.
190
+ 6. Use **撤销** if a change makes things worse.
191
+
192
+ ## Security and privacy
193
+
194
+ - Everything runs locally; no image generation API and no outbound diagram-rendering service.
195
+ - The Host API is same-origin and only reads/writes `<workspace>/diagrams/<slug>/`.
196
+ - Path traversal is rejected for slugs and file names.
197
+ - Reference uploads are size-limited and restricted to image MIME types.
198
+ - Reference images are treated as untrusted content; the agent prompt instructs the model to read them only as diagram content, not as instructions.
199
+ - Repair plans are validated by the Python patch core and rendered to a temporary directory before the blueprint is replaced.
200
+
201
+ ## Limits
202
+
203
+ - The panel edits block diagrams; timing/circuit diagrams are preview-only in this release.
204
+ - The doctor is deterministic. It cannot know a missing business concept unless it is in the spec.
205
+ - Natural-language repair requires an active agent session and writes `repair-plan.json` into the diagram folder.
206
+ - Visual critique (a vision model reviewing the rendered PNG) is not part of 1.0.
207
+
208
+ ## Development
209
+
210
+ ```bash
211
+ # Python tests
212
+ python -m unittest discover -s tests
213
+
214
+ # syntax checks
215
+ node --check client.js
216
+ node --check index.js
217
+
218
+ # npm package
219
+ npm pack
220
+ ```
221
+
222
+ The Client is plain JavaScript + `React.createElement`; there is no build step.
223
+
224
+ ## License
225
+
226
+ MIT