dsh-d2-diagrams: Real-Time D2 Diagram Preview in DeepSeek Harness

Introduction

When writing architecture and flow diagrams in DeepSeek Harness (DSH), a common practice is to maintain .d2 source code, then export images via local CLI or external tools and paste them back into documents. There is often an extra step of manual synchronization between the source file and the visualization; changing a line of layout requires re-running commands. The community plugin dsh-d2-diagrams (maintainer KorionCN) targets the Web client, providing a chart block similar to Documentation products in the right sidebar for .d2 files: supports toggling Chart Only / Code Only / Split view, auto-renders with debounce after editing, and allows Agents to inline the same interaction via d2_render within the conversation flow. Below is an introduction to its positioning, capabilities, and installation/usage.

What is it

dsh-d2-diagrams is a client-side plugin for DeepSeek Harness, classified as a client (platform: web). In short: opening any .d2 file provides a real-time compiled preview of D2 (d2lang) in the sidebar. It does not have a built-in rendering engine but instead invokes the local D2 CLI to compile the source code into SVG. The current plugin version is 0.1.0 in the repository’s package.json, licensed under MIT. Directory page: SkillHub Plugin Page; Source code: GitHub KorionCN/dsh-d2-diagrams.

Core Features

The following lists capabilities explicitly mentioned in the README, all usable in the sidebar or chat cards.

Three Display Modes

  • Chart Only: Fit to width, zoom, copy D2 source code, download SVG.
  • Code Only: Focus on .d2 text.
  • Code and Chart: Dual-column split screen, edit source code on the left, chart on the right auto-redraws after 450ms debounce.

Editing and Rendering Behavior

Editing sidebar content is for real-time preview only and will not write back to disk; for persistence, please save the original file in the main editor, and the preview will refresh automatically with file changes. Syntax errors display prompts with line and column numbers in the chart area; while rendering, the previous successful result is retained to avoid flickering blank screens.

Zoom and Theme

Bottom-right of the chart area provides - / Percentage / + controls (click percentage to return to fit to width), or use Ctrl/⌘ + Scroll to zoom within the 20%–500% range. Light / Dark themes automatically follow the application (D2 theme 0 / Dark Mauve 200).

In-Chat Cards

When an Agent calls the tool d2_render, the same interaction block as the sidebar is inlined into the chat flow, facilitating direct viewing and adjustment of chart context within the conversation.

How it Works (Host / Client)

Component File Responsibility
Host lib/index.js Registers the /d2/render route on the deployed webServer, calls local d2 CLI to compile SVG; includes timeout, output limits, and error protection
Client lib/client.js Registers a document renderer for .d2 via ctx.documentPreviews.register, hooks into the right sidebar.right.tab.document

The host environment must have D2 installed (e.g., brew install d2). The layout engine defaults to elk; it can be adjusted in the config of the bundle patch (see cordis.patch.yml comments in the repository).

Installation and Enablement

The official installation command from GitHub is as follows (must use --profile web, consistent with the plugin’s client positioning):

dsh plugin --profile web add github:KorionCN/dsh-d2-diagrams

If debugging from a local bundle, you can install via the plugin manager by path:

plugin_manager install_bundle  →  /absolute_path/dsh-d2-diagrams

Before installing, please review the repository source code and the MIT license yourself; the plugin runs with current DSH process permissions and will invoke the local d2 executable, so you need to confirm the environment is trusted and the CLI is available. Node engine requirements are in package.json: ^22.19.0 || >=24.0.0.

Typical Usage

  1. Complete the above plugin installation in DSH Web configuration and ensure the local machine has D2 CLI installed.
  2. Open or create a .d2 file in the project; the preview block appears in the right sidebar automatically. Switch between the three views to compare source code and charts.
  3. You can copy the example from the repository assets/example.d2 for your first experience; D2 syntax and advanced capabilities are available at d2lang.com and d2lang/d2.
  4. If an Agent generates or updates the chart, pay attention to the inlined cards triggered by d2_render in the conversation, which behave consistently with the sidebar.

Suitable Scenarios and Notes

Suitable for: DSH users already using or planning to use D2 to describe architecture diagrams, flowcharts, sequence diagrams, ER diagrams, etc.; those who want to edit and preview .d2 files alongside the Harness workspace and reduce the steps of repeatedly exporting images.

Notes:

  • Preview editing does not save to disk; saving must be done via the main editor.
  • Without the local d2, the Host side cannot complete /d2/render, so the CLI must be installed first.
  • The DSH ecosystem operates on the philosophy of “everything is a plugin”; SkillHub etc. are community directories with no official affiliation with DeepSeek / Huanfang. The installation sources in this article follow the GitHub README.

Conclusion

dsh-d2-diagrams links D2 declarative source code with the Harness sidebar and Agent tools: split-screen real-time rendering, themes and zooming, SVG export, relying on the local D2 CLI rather than reimplementing the engine. For further explanation and screenshots, see GitHub README, and the plugin entry at SkillHub Directory Page.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye