Introduction¶
When using DeepSeek Harness (DSH) to ask agents to draw flowcharts, data flow diagrams, or UML schematics, the common bottleneck is not “whether a PNG can be output,” but rather not knowing if the layout is correct before adjusting coordinates: whether boxes are wide enough, if labels overlap lines, or if arrows pierce through boxes. Usually, this requires rendering, visual inspection, and another round of revisions. DiagramKit (npm package dsh-tool-diagram) addresses this scenario: it draws diagrams using declarative specs, while measuring actual text widths and performing layout self-checks, attaching executable fixes to each issue in the report. It is not an automatic layout engine—if you provide at, it draws using absolute positioning; the tool is only responsible for accurate measurement and validation.
What is this¶
DiagramKit is a DSH workflow plugin released by the maintainer erzhe-lume (GitHub repository erzhe-lume/dsh-tool-diagram, current package version 0.1.0, MIT License). The official introduction summarizes it as: a layout measuring ruler and self-checker for structured schematics—measuring actual text width, checking for overflow/overlap/piercing, and returning “diagram + executable fixes” for every call.
The README states that a single diagram contains about 13 types of primitives, with measurement taking approximately 80 ms at 300 dpi; it covers schematic types with discrete elements + connections such as flowcharts, N-S charts and PAD charts, layered DFDs, E-R diagrams, UML use case diagrams and class diagrams, decision trees, fault trees, and organizational charts.
Core Features¶
Three DSH Tools¶
| Tool | Function |
|---|---|
diagram_create |
Draws diagram according to spec, returns inline image, self-check report, and canvas size |
diagram_patch |
Incremental modification: move / moveby / resize / set / add / remove / canvas, no need to resend the entire spec |
diagram_measure |
Measurement and self-check only, no rendering; suitable for first determining “if this line of text fits” |
Layout Measuring Ruler¶
The plugin parses TTF/OTF head / hhea / hmtx / cmap itself to obtain advance widths, without relying on external font metrics libraries. The README specifically emphasizes Chinese scenarios: symbols like curly quotes and ()《》,。 are often counted as full-width 1 em in common fonts; estimating them as half-width will result in significantly undersized box widths.
Additionally, it supports Chinese line wrapping and typographic rules (avoiding ,。、)】 at the beginning of a line), automatic box calculation based on text and padding when size is not provided, and reports glyph_missing for missing characters instead of silently drawing squares.
Self-Check Report¶
The documentation lists 10 categories of check items, each with fix suggestions, such as text overflow, height insufficiency after wrapping, node overlap, edges piercing through a third box, exceeding canvas boundaries, label collisions, and arrow endpoints overlapping text within a box. Levels are divided into error (must fix), warn (visible but suboptimal), and info (e.g., number of edge crossings, for reference).
Primitives, Connections, and Output¶
13 types of shape (including rect, round_rect, store, ellipse, class_box, actor, fault tree AND/OR gates, as well as box_span, line_h, line_v, chevron for N-S/PAD). Edge routing precision ranges from automatic intersection to fromSide/toSide, fromPoint/toPoint, and waypoints; label position can be controlled using labelAt.
Coordinates and dimensions are in centimeters for easy comparison with Word illustrations; default PNG is 300 dpi (configurable up to 600), and SVG export is supported. containers are supported for drawing system boundaries or swimlane outer frames.
Installation and Activation¶
The plugin runs within the DSH process with current user permissions; it is recommended to read the repository source code and MIT license before installation. The official README installation steps are as follows:
- Enter the desktop profile directory and add the dependency:
cd $env:USERPROFILE\.dsh\profiles\desktop
pnpm add github:erzhe-lume/dsh-tool-diagram
- In the
package.jsonin the same directory, adddsh-tool-diagramto thedsh.profile.bundlesarray, then restart dsh:
"dsh": { "profile": { "bundles": [
"@deepseek-ai/dsh-base",
"@deepseek-ai/dsh-web-app",
"dshmarket",
"dsh-tool-diagram"
] } }
During the first installation, [ERR_PNPM_IGNORED_BUILDS] Ignored build scripts: sharp@0.34.0 may appear; the README states this can be ignored; you can execute pnpm approve-builds if needed. The package includes dsh.bundle.patch; generally, there is no need to modify the profile’s cordis.patch.yml; if you want to override default parameters, you can configure dpi, maxDpi, maxDiagrams, etc., according to the README examples.
Runtime environment requires Node.js >=20 (see package.json engines).
Typical Usage¶
Minimal Spec Example¶
The following snippet comes from the README, drawing two DFD-style processes and a data store, connected by two edges:
{
"canvas": { "w_cm": 12.0, "h_cm": 5.0 },
"nodes": [
{ "id": "p1", "shape": "round_rect", "num": "1", "text": "Read card and verify password",
"at": [3.0, 1.4], "size": [3.4, 1.1] },
{ "id": "p2", "shape": "round_rect", "num": "2", "text": "Withdrawal processing",
"at": [8.6, 1.4], "size": [3.0, 1.1] },
{ "id": "db", "shape": "store", "num": "D1", "text": "Central database",
"at": [6.0, 3.9], "size": [4.0, 0.85] }
],
"edges": [
{ "id": "e1", "from": "p1", "to": "p2", "arrow": "open", "label": "Verification passed" },
{ "id": "e2", "from": "p1", "to": "db", "arrow": "both", "label": "Read / Write" }
]
}
After calling diagram_create, besides the PNG, you also get sizeCm, diagramId (for subsequent diagram_patch / diagram_measure), and structured self-check results.
Patching based on Report¶
If the self-check suggests moving a box or changing label position, you can send an array of operations via diagram_patch, for example:
[
{ "op": "move", "node": "db", "to": [6.0, 4.2] },
{ "op": "resize", "node": "p2", "size": [3.4, 1.1] },
{ "op": "set", "edge": "e2", "label": "Read / Write", "labelAt": "left" }
]
CLI without DSH¶
The repository provides lib/cli.js, which can be used locally to render directly or just measure:
node lib/cli.js examples\usecase.json --out usecase.png --dpi 300
node lib/cli.js examples\broken.json --measure
node lib/cli.js examples\lib-dfd-l1.json --patch examples\patch-labels.json --out out.png
node lib/cli.js examples\usecase.json --out a.png --svg
Styles can use presets like se-textbook, uml, dfd via style.preset; the font defaults to the Windows SimHei path, but can be replaced with any TTF/OTF/TTC file path.
Use Cases and Notes¶
The criteria given in the README: discrete elements + relationship connections, containing containers or hierarchies, where correctness mainly depends on “connections are correct, elements are spread out”—suitable for program flowcharts, DFDs, E-R diagrams, UML schematics, fault trees, swimlane diagrams, etc. Not suitable for data visualizations like line/column charts, or drawings based on physical object shapes like circuits and mechanical drafting.
Discipline-specific layouts like N-S charts and PAD charts are still manually divided by the author using at and specialized primitives (such as line_v, chevron); "structural": true can be used to mark layout skeleton elements to avoid false positives from overlap detection. Line wrapping and rules are optimized for Chinese; pure English breaks words by spaces, with no hyphenated word breaking.
Community directory page: https://www.skillhub.cn/plugins/erzhe-lume/dsh-tool-diagram (Independent site, with no official affiliation with DeepSeek / High-Flyer). For source code and full design, see GitHub: https://github.com/erzhe-lume/dsh-tool-diagram, with docs/DESIGN.md and docs/DEVELOPMENT.md available for in-depth reading.
Conclusion¶
If your workflow requires agents to repeatedly draw textbook-style schematics, and you want to know about box widths, piercing, and label issues before changing coordinates, DiagramKit consolidates “rendering + self-check + fixes” into a single call (or incremental patch). Compared to “just outputting an image and relying on human eyes for correctness,” the iteration cost is more controllable. For installation and bundle configuration, please refer to the README; for details, please refer to the current documentation in the repository.