D2 CLI
$ d2 Official Low RiskD2 (d2) compiles human- and agent-readable .d2 diagram scripts into crisp themed SVGs, PNGs, or PDFs with zero browser dependencies. It supports deterministic d2 fmt formatting, d2 validate syntax checking, and selectable layout engines (dagre, elk).
brew install d2 d2 compiles .d2 files directly on the local machine in Go with d2 validate and d2 fmt, requiring no MCP wrapper.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Native Go CLI with d2 validate, d2 fmt, --layout, and clean compiler error messages; lacks a JSON AST output flag.
d2 validateprovides zero-write syntax checking- Clear line/column diagnostics on parse failures
Pure offline local compiler with no credentials needed for OSS layouts.
- Zero network calls during standard SVG rendering
Single Go binary via Homebrew, go install, and GitHub releases; SVG requires no browser (PNG/PDF uses Playwright if enabled).
brew install d2and cross-platform releases
Produces polished modern architecture diagrams with readable .d2 syntax that LLMs write accurately.
- Supports themes, sketch mode, containers, SQL tables, and ELK/Dagre layouts
Official Terrastruct repository (terrastruct/d2) actively maintained under MPL-2.0.
- Official Terrastruct GitHub organization
Clean official tour and manpage docs at d2lang.com.
- Official docs at d2lang.com/tour/man/
Security, Auth & Guardrails
Open-source d2 (dagre/elk) needs zero auth; optional commercial TALA layout plugin reads TSTRUCT_TOKEN or ~/.config/tstruct/auth.json.
CLI and dagre/elk engines are free (MPL-2.0); optional commercial TALA layout engine requires a Terrastruct license.
# D2 CLI Agent Rules - Run `d2 validate <file>.d2` and `d2 fmt` after editing diagram sources. - Prefer SVG output (`output.svg`) over PNG when no headless browser/Playwright rasterizer is installed. - Do not pass `--watch` in synchronous agent commands.
Agent-Ready Command Recipes
Safe Read-Only Queries
d2 validate architecture.d2
Parses and validates .d2 syntax without writing any rendered output file.
d2 --version
Prints the installed d2 compiler version.
Controlled Writes & Previews
d2 --layout=elk architecture.d2 dist/architecture.svg
Renders architecture.d2 using the ELK layout engine into dist/architecture.svg.
Strengths for Agents
- + Browser-free SVG rendering and
d2 validate/d2 fmtin a single Go binary. - + Concise
.d2language is easy for coding agents to generate and diff cleanly. - + Supports
--layout=elkand built-in themes out of the box.
Caveats & Pitfalls
- ! Raster PNG/PDF export still relies on Playwright/browser unless sticking to SVG.
- ! The TALA layout engine is proprietary and requires a Terrastruct license token.