Skip to content
CAI
Software that uses CAICheck a score

terrastruct/d2

57.0

Adequate · 6 August 2026

44.4k

lines of production code

Go

primary language

4

measurements over time

CAI band scale
CAI trend line
CAI lens gauges

What this system is

D2 is a diagramming tool that converts a domain-specific language into visual diagrams. It compiles text-based descriptions into various output formats, including SVG, PNG, PDF, PPTX, GIF, and ASCII art. The system supports multiple layout engines (Dagre, ELK, Grid, Sequence) and rendering styles (sketch, dark/light themes). It also provides a JavaScript/Node.js API and a WebAssembly build for browser-based usage, alongside a CLI for headless and interactive diagram generation.

How it got here

2022 — Architecture modernization and layout engine expansion

55 changes.

This period focused on a comprehensive architectural overhaul, introducing an intermediate representation for the compiler and refactoring the codebase to support complex features like sequence diagrams and nested boards. The team also expanded the rendering capabilities by integrating the ELK layout engine, adding LaTeX and sketch modes, and significantly improving the installation and release pipelines.

2023–2025 — WebAssembly and multi-format export expansion

32 changes.

This period focused on extending D2's reach to web environments via a new JavaScript/Go WASM bridge, enabling browser-based diagramming and editor integration. Simultaneously, the project significantly broadened its output capabilities by introducing native support for PDF, PPTX, and ASCII art rendering, alongside a new grid-based layout engine and intermediate representation for improved compilation.

Features

Add AWS infrastructure provisioning and SSH execution scripts

The CI/CD pipeline now includes new shell scripts to provision and manage AWS EC2 instances for Linux (amd64/arm64), macOS (amd64), and Windows (amd64) builders. The \ensure.sh\ script handles the creation of security groups and EC2 instances, while \ssh.sh\ provides a unified way to execute commands across all configured remote builder hosts.

ci/release/aws · high confidence

Add D2 man page documentation

Added the D2 manual page (man/d2.1) which documents the command-line interface, including all available flags (such as --theme, --scale, --font-regular, --animate-interval, --target, and --ascii-mode) and subcommands (layout, fmt, play, validate). This provides users with a comprehensive reference for using D2 from the terminal.

ci/release/template/man · high confidence

Add FuzzyBubbles-Bold font and update Source Code Pro to WOFF format

The system now supports the 'FuzzyBubbles-Bold' font, which is added as a new encoded asset. Additionally, the 'Source Code Pro' font family is updated to use the '.woff' format for bold and italic styles, replacing the previous '.ttf' format. These changes affect the available fonts for rendering in the d2renderers/d2fonts/encoded module.

d2renderers/d2fonts/encoded · high confidence

Add JavaScript execution engine for Go and WebAssembly targets

The lib/jsrunner package now provides a unified interface for executing JavaScript code in two distinct environments: a Go-based runtime using the goja library for standard Go builds, and a native WebAssembly-based runtime for JS/WASM builds. This introduces the ability to run arbitrary JavaScript strings and manage global state across both platforms, enabling consistent JS integration in Go applications and WebAssembly modules.

lib/jsrunner · high confidence

Add LSP support for autocomplete, reference ranges, and board navigation

The d2lsp module now provides three new capabilities for IDE integration: autocomplete suggestions for D2 syntax (including styles, shapes, and labels), the ability to find all references to a field or edge (including those from imported files), and the ability to determine which board (layer/scenario/steps) a cursor position belongs to. These features enable richer editor experiences such as code completion, find-all-references, and smart navigation within nested diagrams.

d2lsp · high confidence

Add animated SVG wrapper for diagram transitions

The d2animate package now provides a new Wrap function that generates an animated SVG by applying CSS keyframe animations to a sequence of SVG frames. This enables smooth visual transitions between different states of a diagram, with each frame fading in and out based on a configurable interval. The implementation handles dimension scaling, theme styling, and font embedding, ensuring that the animated output is self-contained and visually consistent with the static renderer.

d2renderers/d2animate · high confidence

Add generic thread-safe map wrapper

A new generic \SyncMap\ type is introduced in \lib/syncmap\, wrapping Go's \sync.Map\ to provide a type-safe, concurrent map implementation. It exposes methods for storing and retrieving key-value pairs (\Set\, \Lookup\, \Get\), deleting entries, and iterating over the map (\Range\), offering a convenient, generic interface for concurrent access.

lib/syncmap · high confidence

Add in-memory filesystem implementation

A new in-memory filesystem implementation (lib/memfs) has been added, providing an fs.FS interface for environments where native file system calls are unavailable, such as JavaScript environments.

lib/memfs · high confidence

Add interactive D2.js example pages

The d2js/js/examples directory now includes basic.html and customizable.html, which provide interactive web interfaces for compiling and rendering D2 diagrams. The customizable example allows users to adjust layout algorithms (Dagre or ELK), enable sketch or ASCII modes, and toggle centering, offering a practical way to explore D2.js capabilities directly in the browser.

d2js/js/examples · high confidence

The d2svg renderer now includes embedded SVG assets for paper textures, line patterns, dot patterns, and link icons. These resources are embedded into the binary via Go's embed directive, with the paper texture additionally decompressed from Brotli for WebAssembly builds. This enables the renderer to apply visual styles like paper backgrounds and connection icons directly from the compiled binary.

d2renderers/d2svg · high confidence

Add release installation and uninstallation scripts

The release pipeline now includes new shell scripts to handle the installation and uninstallation of the 'd2' binary and its manpage. The install script detects the operating system to install the correct executable (d2.exe on Windows, d2 on other platforms) and places it in the user's PATH. The uninstall script removes these files. A shared library (lib.sh) provides helper functions for logging, temporary files, and colorized output.

ci/release/template/scripts · high confidence

Add release template for Unix and Windows installation

The ci/release/template directory now includes a new LICENSE.txt symlink, a Makefile that delegates to install/uninstall scripts, and a README.md.sh script that generates release documentation. The generated README provides installation instructions for Unix systems and specific guidance for Windows users, including a recommendation to use the .msi installer for easier PATH management.

ci/release/template · high confidence

Add support for CSS gradients and theme color darkening

The color library now supports parsing and rendering CSS linear and radial gradients, converting them into SVG elements for visual output. It also introduces a new capability to darken theme colors (such as N1-N7, B1-B6, and alternative colors) by reducing their luminance, which allows for dynamic color adjustments based on background or theme requirements.

lib/color · high confidence

Add version management module

A new \lib/version\ package has been introduced to centralize version information. It defines a \Version\ variable, defaulting to \v0.7.1-HEAD\ for source builds, and provides an \OnlyNumbers\ function to extract the numeric portion of the version string.

lib/version · high confidence

Added Go WASM execution bridge

The \wasm\_exec.js\ file was added to the \d2js/js/wasm\ directory. This script provides the necessary JavaScript bridge to run Go-compiled WebAssembly code in the browser, including polyfills for the Node.js \fs\ and \process\ modules, as well as required global objects like \crypto\ and \performance\.

d2js/js/wasm · high confidence

Added font conversion and subsetting capabilities

The lib/font package now includes new Go implementations for converting SFNT fonts (.ttf, .otf) to WOFF format and for subsetting fonts. This adds the ability to transform and optimize font files directly within the library.

lib/font · high confidence

Appendix generation for static SVG exports

Added an appendix feature that appends a list of diagram links and tooltips to the bottom of static SVG exports (e.g., for PNG or PDF). The new \d2renderers/d2svg/appendix\ package handles the layout, separator lines, and font-face styling for the appendix content, ensuring that interactive elements like tooltips and links are preserved in non-interactive static formats.

d2renderers/d2svg/appendix · high confidence

Exposes D2 WebAssembly API to JavaScript

The d2js package now provides a WebAssembly-based interface for JavaScript environments. It registers a set of functions—including compile, render, getCompletions, and version retrieval—on the global JavaScript object, enabling JavaScript applications to interact with D2's core logic via the d2wasm module.

d2js · high confidence

Implement ASCII art rendering for all supported shapes

The \d2renderers/d2ascii/asciishapes\ package has been introduced to handle the rendering of all supported diagram shapes in ASCII art format. This includes specific renderers for callouts, classes, cylinders, diamonds, documents, hexagons, packages, pages, parallelograms, persons, queues, rectangles, SQL tables, steps, and stored data. The implementation provides a unified \Context\ for calibration and character sets, along with helper functions for drawing borders, headers, and labels, ensuring that every shape type is correctly rendered in the ASCII output.

d2renderers/d2ascii/asciishapes · high confidence

Introduce ASCII canvas for rendering diagrams as text

Added a new \asciicanvas\ package that provides a grid-based canvas for rendering D2 diagrams as ASCII art. The implementation includes methods to set and retrieve characters, draw labels, and convert the internal grid to a byte slice. The conversion logic automatically trims empty rows and columns to crop the output, and it attempts to preserve route characters (vertical/horizontal lines) while filtering out redundant route-only rows to produce cleaner ASCII output.

d2renderers/d2ascii/asciicanvas · high confidence

Introduce ASCII diagram renderer

Adds a new ASCII-based renderer for D2 diagrams, enabling text-based visualizations of shapes, connections, and labels. This feature allows users to generate ASCII art representations of their diagrams, with support for customizing character sets and scaling.

d2renderers/d2ascii · high confidence

Introduce CompileOptions for headless diagram compilation

The d2lib package now exposes a headless compilation entry point via the new d2.go file, which defines a CompileOptions struct and associated Parse/Compile functions. This allows programmatic control over diagram rendering by accepting a custom font family, layout engine, and edge router, while also ensuring that appearance-affecting properties (theme, sketch mode) are captured in the diagram's configuration for consistent hashing.

d2lib · high confidence

Introduce D2 LaTeX renderer with MathJax integration

Added a new LaTeX rendering capability to D2 using MathJax. The change introduces a Go-based renderer that processes LaTeX strings into SVG output, supporting both standard and WebAssembly builds. For WASM targets, the MathJax library is stored as a Brotli-compressed asset and decompressed at runtime to reduce bundle size. The implementation includes a test suite to validate SVG generation for various LaTeX expressions.

d2renderers/d2latex · high confidence

Introduce ELK layout engine integration

Added the ELK (Eclipse Layout Kernel) graph layout engine to the D2 rendering pipeline. This includes the ELK JavaScript library (v0.8.2) and Go/WASM bindings to enable advanced graph visualization features such as automatic node spacing, self-loop handling, and edge routing. The integration supports both Goja (JavaScript) and WebAssembly execution environments, allowing users to benefit from improved layout algorithms for complex diagrams.

d2layouts/d2elklayout · high confidence

Introduce Playwright-based PNG generation with EXIF support

The PNG generation library has been refactored to use the Playwright headless browser (migrated to the maintained playwright-go driver) for rendering SVGs into PNG images. This change introduces a new background utility for periodic execution and updates the PNG library to handle browser lifecycle management, including automatic Chromium installation prompts and error reporting. Additionally, the implementation now supports embedding EXIF metadata into the generated PNG files.

lib/png · high confidence

Introduce d2.js, a JavaScript wrapper for D2

Users can now run D2 directly in browsers and Node environments using the new @terrastruct/d2 package. The library provides a universal API for compiling D2 markup and rendering diagrams to SVG, with support for custom fonts, relative imports, and various render options like sketch mode, theme selection, and animation intervals.

d2js/js · high confidence

Introduce d2ir intermediate representation for compiling D2 diagrams

The d2ir package now provides a new intermediate representation (IR) for the D2 compiler, introducing types like Map, Field, Edge, and Scalar to track resolved values and references. This change adds the core data structures and the \Compile\ function that transforms the parsed AST into this IR, supporting features such as glob patterns, filters, imports, and variable substitution. The implementation includes logic for handling nested scopes, cyclic import detection, and class overlaying, effectively bridging the gap between parsing and the final target representation.

d2ir · high confidence

Introduce dedicated layout engine for sequence diagrams

Users can now use the \shape: sequence\_diagram\ property to automatically layout diagrams as sequence diagrams. This adds a new \d2sequence\ package that handles the specific positioning of actors, messages, lifelines, spans, and notes, ensuring correct spacing, z-indexing, and alignment for sequence diagram elements.

d2layouts/d2sequence · high confidence

Introduce grid-based diagram layout

A new grid layout engine has been added to D2, allowing users to arrange objects in rows and columns. This feature supports configurable row and column counts, horizontal and vertical gaps, and automatic sizing adjustments for labels and icons. The implementation includes a new \d2grid\ package with constants, diagram structure, and layout logic, along with tests for the layout generation.

d2layouts/d2grid · high confidence

Introduce new AST node types and keyword definitions

The d2ast package now includes a new \Suspension\ node type and an \Import\ node type, expanding the abstract syntax tree to support suspension and import features. Additionally, a new \keywords.go\ file defines reserved keywords, style keywords, and position constants for labels and tooltips, while the \Position\ struct gains a \Debug\ method and \Before\ comparison logic. Test coverage is updated to use the \util-go\ assertion library instead of the old \diff\ package.

d2ast · medium confidence

Introduce new d2wasm API for WebAssembly-based diagramming

The d2js/d2wasm directory now contains a new Go package that exposes the D2 engine to JavaScript via WebAssembly. This new API provides structured JSON responses for core operations including compiling D2 DSL into a graph, retrieving reference ranges for code completion, and converting graphs for layout engines like ELK. It also supports rendering options such as custom fonts, theme overrides, and animation intervals, enabling web-based D2 tools to interact with the engine through a consistent, error-handling wrapper.

d2js/d2wasm · high confidence

Introduce sketch rendering mode for hand-drawn style diagrams

The D2 renderer now supports a 'sketch' mode that renders diagrams with a hand-drawn, sketchy aesthetic. This is implemented via a modified version of the 'rough.js' library, integrated into the \d2renderers/d2sketch\ package. The Go code in \sketch.go\ loads the JavaScript renderer and provides functions to generate SVG paths for shapes (like rectangles and double-bordered rectangles) using rough drawing techniques. The system also defines fill patterns with subtle streaky effects to enhance the hand-drawn look. Tests in \sketch\_test.go\ verify the rendering of various shapes, connections, and arrowheads in this new style.

d2renderers/d2sketch · high confidence

New ASCII art route rendering engine

The ASCII renderer now uses a dedicated \asciiroute\ package to draw connection lines, arrows, and labels. This new routing logic processes connection paths by merging collinear segments, forcing horizontal/vertical segments, and handling label placement, which changes how edges and their labels are rendered in ASCII diagrams.

d2renderers/d2ascii/asciiroute · high confidence

New CI scripts for coverage, end-to-end reporting, and development

The CI directory now includes several new helper scripts: \cov.sh\ for generating Go code coverage reports, \e2ereport.sh\ for generating and opening end-to-end test reports, \gen.sh\ for generating installation scripts and templates, and \peek-wasm-size.sh\ for measuring and optimizing WebAssembly build sizes. Additionally, \dev.sh\ was added to streamline local development builds, and \test.sh\ was updated to always run with \CI=1\ to ensure consistent test behavior in all environments.

ci · high confidence

New Dockerfile and build scripts for the D2 release image

Added a new Dockerfile and associated build scripts (build.sh, entrypoint.sh, prepare-continuity-dockerfile.sh) to containerize the D2 release. The image is based on Ubuntu, installs Node.js and Playwright dependencies, and runs the D2 binary via an entrypoint script. The build script supports a --version flag and explicitly disables --push/--latest flags, deferring publishing to the GitHub workflow. A helper script patches the Dockerfile for version v0.7.1 to use a specific Playwright driver version (1.47.2) to work around a retired CDN endpoint.

ci/release/docker · high confidence

New PPTX export capability

The \lib/pptx\ package now provides a complete implementation for generating Microsoft PowerPoint (.pptx) presentation files. This includes the core Go logic in \pptx.go\ and a set of embedded XML templates (e.g., \app.xml\, \content\_types.xml\, \presentation.xml\) that define the structure of the generated files. The implementation handles slide creation, image scaling, and hyperlink relationships, with a corresponding validation suite in \validate.go\ to ensure the output conforms to the OOXML standard.

lib/pptx · high confidence

New URL encoding and decoding functions for D2 scripts

The lib/urlenc package now provides Encode and Decode functions that compress and base64-encode D2 scripts for URL embedding. Encode uses flate compression with no dictionary, and Decode reverses the process. A new test file and expected output data file have been added to verify the encoding and decoding behavior.

lib/urlenc · high confidence

New imgbundler library for inlining images

Added the \lib/imgbundler\ package, which provides functionality to bundle local and remote images into SVG documents. The library supports caching, parallel fetching with a concurrency limit, and improved MIME type detection (including handling octet streams with SVG signatures). A new \simplelog.Logger\ interface is introduced to abstract logging, and test files are added to verify the bundling behavior.

lib/imgbundler · high confidence

New layout feature flags for object positioning and container sizing

A new file, d2layouts/d2layoutfeatures/d2layoutfeatures.go, introduces three boolean constants that act as feature flags for layout capabilities. These flags control whether objects can be positioned relative to other objects (NEAR\_OBJECT), whether containers can have explicit dimensions (CONTAINER\_HIERARChY), and whether objects can specify absolute top/left coordinates (TOP\_LEFT).

d2layouts/d2layoutfeatures · high confidence

New themes and theme catalog reorganization

The theme catalog is now split into LightCatalog and DarkCatalog, each containing a set of available themes. New themes added include Buttered Toast, C4, Dark Flagship Terrastruct, Dark Mauve, Everglade Green, Origami, Terminal, and Terminal Grayscale. Several existing themes have had their display names corrected to title case (e.g., 'Colorblind Clear', 'Cool Classics', 'Earth Tones', 'Grape Soda', 'Mixed Berry Blue', 'Orange Creamsicle', 'Shirley Temple', 'Vanilla Nitro Cola'). The CLI output for listing themes now separates them into Light and Dark sections.

d2themes/d2themescatalog · high confidence

New xgif library for generating GIF animations from PNG frames

A new \xgif\ package has been added to \lib/xgif\, providing utilities to convert animated SVGs into PNG frame sequences and subsequently into animated GIFs. The implementation uses the \playwright-go\ driver to render SVGs into PNGs and applies median-cut quantization to ensure each frame stays within the 256-color GIF limit. The library supports concurrent processing of frames and centers images on a white background. A corresponding test suite (\xgif\_test.go\) validates the PNG-to-GIF conversion logic.

lib/xgif · high confidence

PDF export implementation

Added a new PDF export capability for D2 diagrams. The \lib/pdf\ package now provides a \GoFPDF\ struct that handles PDF generation using the \gofpdf\ library. This includes rendering board titles, headers, and images onto PDF pages, with support for theme-based colors and internal/external links within the generated PDFs.

lib/pdf · high confidence

Support for constant near keywords in layout

The d2near layout module now handles the placement of shapes assigned constant near keywords (e.g., top-center, bottom-left). The new \Layout\ function processes these objects, calculating their positions relative to the diagram's bounding box and adjusting for label dimensions. This ensures that shapes with constant near attributes are correctly positioned outside the main layout area, preventing collisions and respecting label positions.

d2layouts/d2near · high confidence

Support for nested diagram layouts and cross-graph edge routing

The layout engine now supports nested diagrams, allowing complex hierarchical structures to be laid out recursively. This change introduces a new \LayoutNested\ function that extracts, layouts, and re-injects nested graphs, while also handling the re-association of edge references after layout. Additionally, the system now supports cross-graph edge routing via a \RoutingPlugin\ interface, enabling edges to be routed across different diagram types (e.g., from a grid cell to a sequence diagram). The \d2layouts\ package has been updated to manage object ordering and handle various edge cases in nested graph extraction and injection.

d2layouts · high confidence

Windows installer package added

A new Windows installer package has been introduced, allowing users to install the D2 executable via a standard Windows installer. The package is configured to place d2.exe in the Program Files directory and automatically add the installation directory to the system PATH environment variable, enabling command-line access from any location.

ci/release/windows · high confidence

Removals

Removal of Go2 utility package

The Go2 package, which provided general utility helpers such as Pointer, Min, Max, StringToIntHash, Contains, Filter, IntMax, and IntMin, has been removed from the codebase. Users relying on these functions will need to implement equivalent logic or use standard library alternatives.

lib/go2 · high confidence

Removal of lib/diff package

The lib/diff package, which previously provided a TestdataGeneric helper for generating and comparing test data diffs, has been removed from the codebase.

lib/diff, lib/xexec · high confidence

Removal of text measurement components

The \markdown.go\ and \textmeasure.go\ files in the \d2renderers/textmeasure\ package have been deleted. This removes the legacy text measurement logic, including the \Ruler\ struct and markdown rendering helpers, from the codebase.

d2renderers/textmeasure · high confidence

Removal of the xmain library

The xmain library, which previously provided a standard stub for command-line applications by handling logging, flags, signals, and shutdown logic, has been removed from the codebase. This eliminates the shared infrastructure for managing application entry points, signal handling, and error reporting for all consumers of this library.

lib/xmain · high confidence

Removal of xbrowser utility

The xbrowser package, which previously provided a utility for opening URLs in the user's default browser, has been removed from the codebase. This change eliminates the local implementation that previously handled browser launching via environment variables or fallback to a third-party library.

lib/xbrowser · high confidence

Removed CI subdirectory and all associated shell scripts

The entire \ci/sub\ directory has been removed, including all shell scripts (e.g., \assert\_linear.sh\, \echop\, \prefix\, \xargsd\), the \lib.sh\ utility library, and the \fmt/\ subdirectory containing formatting logic for Go, Prettier, and other tools. This eliminates the previous CI helper scripts and formatting automation from the repository.

ci/sub · high confidence

Removed deprecated CLI entry points and version check

The \cmd/d2\ package, including \help.go\, \main.go\, and \cmd/version/version.go\, has been removed. This eliminates the legacy command-line interface that handled help text, layout engine listing, and automatic version checking against GitHub releases. Users will no longer see the \d2 layout\ subcommand or the automatic update check in the CLI.

cmd/d2 · high confidence

Removed xhttp HTTP helper package

The xhttp package, which provided HTTP server utilities including error handling, logging, and server creation, has been removed from the codebase. This eliminates the custom HTTP handler adapters, JSON error response helpers, and server configuration logic previously maintained in lib/xhttp.

lib/xhttp · high confidence

Behavioural changes

Add configurable D2\_TIMEOUT environment variable

Users can now set the D2\_TIMEOUT environment variable to configure a timeout value for D2 operations. The system reads this variable and parses it as an integer; if provided, the timeout is applied, otherwise the default behavior remains unchanged.

lib/env · high confidence

Automated npm publishing and WASM build pipeline for d2.js

The CI build script for d2.js has been updated to support automated npm publishing and WASM optimization. The script now handles both official releases and nightly builds, using the NPM\_VERSION environment variable to determine the target version and npm tag (latest or nightly). It also integrates wasm-opt for WASM optimization and manages package.json versioning and publishing via npm stage or direct publish modes.

d2js/js/ci · medium confidence

CLI refactoring and new subcommands

The d2cli package has been reorganized, moving the main entry point and related files (watch, help, fmt, validate, play) into the d2cli package. This includes adding new CLI subcommands: 'fmt' for formatting D2 files, 'validate' for syntax checking, and 'play' for opening the online playground. The 'fmt' command now supports a '--check' flag to verify file formatting without modifying files. The watch mode has been updated to ignore backup files and handle file changes more robustly. Additionally, the CLI now supports outputting to stdout with the '--stdout-format' flag for formats like PNG, SVG, ASCII, TXT, PDF, PPTX, and GIF.

d2cli · medium confidence

Compiler refactored to use an intermediate representation (IR) and returns a config object

The d2compiler now compiles the parsed AST into an intermediate representation (IR) before generating the graph, which allows for better validation and error handling. The Compile function now returns a Config object alongside the graph, enabling the compiler to pass configuration data (such as file system references) to downstream components. Additionally, the compiler now validates reserved fields, checks for negative positions, and enforces dimension constraints on shapes like circles and hexagons.

d2compiler · high confidence

D2 project reorganization and improved installation experience

The project has been reorganized with a new entry point in main.go and the removal of legacy d2.go and c.go files. The installation process is significantly improved with a new install.sh script that handles Go, Homebrew, and manual builds, alongside updated documentation in README.md and Makefile. The repository has also been moved from the terrastruct organization to d2lang.

(repo-wide) · high confidence

Dagre plugin build tag and import path updated

The Dagre plugin's build constraints were simplified by removing the 'cgo' requirement, now relying solely on the 'nodagre' tag. Additionally, the import path for the xmain package was updated from 'oss.terrastruct.com/d2/lib/xmain' to 'oss.terrastruct.com/util-go/xmain', and the plugin is now passed as a pointer to the Serve function.

cmd/d2plugin-dagre · high confidence

E2E report tool gains profiling, configurable test names, and improved layout

The e2etests/report tool now supports CPU and memory profiling via new --cpuprofile and --memprofile flags, and allows overriding the default test name with --test-name. The generated HTML report includes a table of contents with anchor links to each test case, and the layout has been updated to display expected and got images side-by-side using a flexbox wrapper, improving visual comparison of test results.

e2etests/report · high confidence

Enhanced styling and structure for class, SQL table, and diagram target models

The d2target package introduces structural and styling improvements for diagram elements. Class fields and methods now support an underline style and expose visibility tokens (e.g., +, -, \#) for rendering. SQL table columns are refactored to support multiple constraints (PK, FK, UNQ) and render each component (name, type, constraints) as separate text elements for better layout control. The Diagram struct gains support for layers, scenarios, and steps, along with a new Legend model and a Config object for theme overrides and layout engine selection.

d2target · medium confidence

Export function signature updated to support custom fonts and legend rendering

The Export function in the d2exporter package now accepts fontFamily and monoFontFamily parameters, allowing the exporter to use specific font families for standard and monospace text. Additionally, the exporter now processes and includes legend data (shapes and connections) in the exported diagram structure, and the test suite has been updated to reflect these changes, including new tests for legend rendering and font family handling.

d2exporter · high confidence

Improved SVG path precision and new path manipulation utilities

SVG text is now escaped using the standard library's XML escape function to ensure safe rendering. The precision of floating-point numbers in SVG paths is improved by converting to float32 before rounding, ensuring consistent results across different architectures and eliminating negative zero issues. Additionally, new functions have been added to the SVG path library: a Bezier curve segment calculator, a path length calculator, and a function to split SVG paths into two segments based on a percentage, enabling more complex path manipulations.

lib/svg · medium confidence

Improved SVG rendering and scaling in watch mode

Watch mode now parses incoming SVG messages as XML and replaces the content of the SVG container rather than overwriting the entire element, which prevents ID loss. The SVG is also scaled to fit the viewport or a provided scale factor, and the favicon is updated to reflect the current status.

d2cli/static · medium confidence

Improved formatting for null values, imports, and board nodes

The formatter now escapes the null value as 'null' (single-quoted string) instead of the previous backslash escape, and correctly formats import paths by cleaning relative prefixes like ./ and ../. It also preserves the order of board nodes (layers, scenarios, steps) by moving them to the bottom of their parent map, and adds support for formatting the new Suspension node type.

d2format · high confidence

Improved layout engine integration and configurability

The DAGRE layout engine is now integrated via a new object mapper that handles node and edge registration, with embedded JavaScript assets (including a compressed version for WASM builds) and updated Go code to support configurable spacing options (node/edge separation) and dynamic rank separation based on label dimensions. The layout logic now adapts to graph direction (top-bottom, left-right, etc.) and handles edge endpoints more accurately, resulting in better spacing and label placement for diagrams.

d2layouts/d2dagrelayout · medium confidence

Migrate logging from third-party slog to Go standard library slog

The logging subsystem has been migrated from the external cdr.dev/slog library to Go's standard library log/slog. This introduces new internal handler types (LevelHandler, PrettyHandler, and tbWriter) to manage log levels, formatted output, and test integration. The public API has shifted from passing slog.Logger instances to passing \*slog.Logger, and the Init function now sets the default logger using slog.SetDefault. Additionally, a new WithTimeout utility in lib/time allows overriding the default timeout via the D2\_TIMEOUT environment variable.

lib/log · high confidence

Move text measurement logic to a shared library

The text measurement and rendering logic has been moved from d2renderers/textmeasure to lib/textmeasure, making it available as a shared library. This includes the core text measurement, markdown rendering, and link sanitization. The move is accompanied by updates to the public API, specifically adding font size and font family parameters to the MeasureMarkdown function to support more accurate text dimension calculations.

lib/textmeasure · high confidence

Parser now auto-detects and handles UTF-16 encoded files

The parser now automatically detects UTF-16 encoded files by checking for the UTF-16 BOM (0xFFFE) and decoding the input stream accordingly. This allows the parser to correctly process diagrams saved in UTF-16 encoding, which is common on Windows systems. Additionally, the parser now supports the 'not ampersand' syntax (!&) for map keys, and import paths are normalized by stripping leading './' characters.

d2parser · high confidence

Plugin architecture refactored to support feature flags and cross-graph edge routing

The plugin system now enforces feature support checks (e.g., locked positions, container dimensions, descendant edges) via a new \PluginFeature\ system, ensuring layout engines only process diagrams they support. Additionally, a \RoutingPlugin\ interface has been introduced, allowing plugins to implement custom edge routing logic, with the \exec\ plugin updated to support this new protocol. The \dagre\ and \elk\ plugins have been updated to expose their specific configuration flags and declare their supported features.

d2plugin · high confidence

Redesign of the release and installation pipeline

The \ci/release\ directory has been restructured with new scripts to modernize the release process. \build.sh\ now supports \--install\ and \--uninstall\ flags for quick local builds, while \build\_in\_docker.sh\ handles cross-platform Docker builds. The \install.sh\ script has been significantly improved with support for Homebrew, TALA, and various installation methods (standalone, detect, homebrew). A new \release.sh\ wrapper and \release-js.sh\ for NPM publishing have been added. Additionally, \gen\_install.sh\ and \gen\_template\_lib.sh\ are introduced to generate bundled scripts, and a \README.md\ documents the new workflow.

ci/release · high confidence

Refactor d2graph with new layout and sequence diagram helpers

The d2graph package has been reorganized to improve layout calculations and sequence diagram handling. New helper methods were added to d2graph.Object for identifying and navigating grid diagrams (IsGridDiagram, ClosestGridDiagram, ClosestGridCell, TopGridDiagram) and sequence diagrams (IsSequenceDiagram, OuterSequenceDiagram, IsSequenceDiagramGroup, IsSequenceDiagramNote). Layout logic was extracted into a new layout.go file, providing functions for moving objects with descendants, removing children, and shifting edges during layout adjustments. Additionally, the color and font helper files were removed, and the serialization logic was updated to support new graph properties like RootLevel and Data, with improved casing handling for child lookups.

d2graph · high confidence

Refactor geometry library to remove external dependencies and add spatial query methods

The geometry library replaces the external 'gonum.org/v1/plot' dependencies with local implementations for Bezier curves, improving portability and reducing build overhead. This change introduces new spatial query capabilities, including methods to check if a segment intersects or overlaps with a box or another segment, and to determine if a point is contained within a box. Additionally, the library adds utility functions for point interpolation, vector angle calculation, and floating-point precision truncation to ensure consistent behavior across platforms.

lib/geo · high confidence

Refactor label positioning to use integer types and add border-based positions

The label positioning system in lib/label has been refactored to use an integer-based type (int8) instead of strings, improving memory efficiency and performance. Additionally, new border-based label positions (BorderTopLeft, BorderTopCenter, etc.) have been introduced, allowing users to place labels directly on the borders of nodes. The FromString and String methods have been updated to support the new integer-based enum values and the new border positions.

lib/label · medium confidence

Refactor shape sizing to support independent horizontal and vertical padding

The shape library now uses separate horizontal and vertical padding values (paddingX, paddingY) for all shapes, replacing the previous single 'padding' parameter. This change allows for more precise control over how content is spaced within shapes. As part of this refactor, the 'FullShape' pointer is now set on all shape instances, and default padding values are explicitly defined for each shape type. Additionally, a new 'C4Person' shape is introduced with specific inner box calculations and aspect ratio limiting, while existing shapes like 'Callout', 'Circle', 'Oval', and 'Page' have been updated to use the new padding model and adjust their internal dimensions accordingly.

lib/shape · high confidence

Refactored font management with semibold styles and WASM compression

The font rendering system has been refactored to support semibold font styles for Source Sans Pro, Source Code Pro, and the hand-drawn 'Fuzzy Bubbles' theme. The internal font registry has been migrated from standard maps to a thread-safe SyncMap, and font data for WebAssembly builds is now stored as Brotli-compressed assets that are decompressed at runtime to reduce package size. Additionally, the codebase was reorganized into separate files for common logic, embedded non-WASM assets, and WASM-specific compressed assets, with a corresponding test added for font cutting.

d2renderers/d2fonts · high confidence

Support for ASCII character set in ASCII renderer

The ASCII renderer now supports rendering with standard ASCII characters (e.g., +, -, \|) in addition to the default Unicode box-drawing characters. This allows users to generate diagrams using simple text characters, which may be more compatible with older terminals or systems that do not support Unicode box-drawing glyphs.

d2renderers/d2ascii/charset · high confidence

Support for complex IDs and sequence diagram safety in d2chaos

The d2chaos test generator now supports complex IDs, allowing for longer, more realistic node and edge identifiers (up to 256 characters) and mixed-case labels, while defaulting to shorter, simpler IDs. The generator also prevents invalid sequence diagram inputs by ensuring nodes are not connected to themselves and by filtering out sequence diagrams from random generation. Additionally, the test suite was updated to use the new d2compiler.Compile signature and the d2dagrelayout.DefaultLayout function, and a new test case was added to verify that creating an edge between boards is handled correctly.

d2chaos · high confidence

Support for decompressing embedded SVG images in compressed formats

The compression library now includes logic to detect and decompress embedded SVG images that are compressed using gzip, zlib/deflate, or Brotli. This ensures that when SVGs are loaded into headless Chromium for PNG screenshots, the system can properly identify and wait for these images to load, preventing issues where compressed images were previously not detected as proper images.

lib/compression · medium confidence

Theming system refactored with new helper classes and special rules

The d2themes package has been refactored to support more granular theme control and new visual styles. A new \ThemableElement\ helper class is introduced to manage XML/SVG element creation with automatic theme color resolution and class naming. The \Theme\ struct now includes a \SpecialRules\ configuration, enabling features like monospaced fonts, disabled corner radius, double borders for outer containers, and specific styles for C4 diagrams. Additionally, the neutral color palette has been expanded to include N6 and N7 shades, and new dark themes (Dark, Dark Mauve) have been added.

d2themes · medium confidence

d2oracle functions now support nested board paths

The d2oracle package's edit and get functions (Create, Set, GetParentID, GetObj, GetEdge, GetObjOrder) now accept a boardPath argument to target nested boards, layers, scenarios, and steps. This allows modifications and queries to be scoped to specific board contexts within the diagram. A new OutsideScopeError is introduced to handle cases where an operation would modify the AST outside the given scope. Additionally, helper functions GetBoardGraph, ReplaceBoardNode, GetChildrenIDs, IsImportedObj, and IsImportedEdge were added to support this scoping logic.

d2oracle · high confidence

Test coverage

Added integration and unit tests for D2.js; Added tests for the dark theme rendering; E2E CLI test suite expanded with new test cases and infrastructure; Expanded end-to-end test coverage for D2 rendering and layout; Expanded test coverage for grid, layout, and styling features.

Dependencies

Updated JavaScript and Go dependencies for the D2.js package and core library

The D2.js package (d2js/js) was introduced with version 0.1.33, establishing a new JavaScript/Node.js build for the D2 diagramming tool, including a package.json and lockfile that pin the 'bun' development dependency. In the main Go module, the Go version was updated to 1.25, and numerous dependencies were upgraded or replaced, including 'github.com/PuerkitoBio/goquery' to v1.10.0, 'github.com/alecthomas/chroma/v2' to v2.14.0, and 'github.com/fsnotify/fsnotify' to v1.7.1. Additionally, the 'cdr.dev/slog' dependency was removed in favor of the standard library 'log/slog', and 'github.com/andybalholm/brotli' was added.

(dependencies) · high confidence

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

How this codebase got here

This is the PUBLIC form of this artifact. Findings are listed in full, but the details of SECURITY findings — which rule fired, in which file, on which line, and how to fix it — are deliberately withheld, and any secret-scanner results are excluded entirely. Where detail is absent here it was REMOVED FOR PUBLICATION; it is not missing from the analysis. The complete artifact is available from the repository owner.

Score

  • CAI 55 → 57 (+2.2)
  • Rubric changed (rubric-2026.08.18 → rubric-2026.08.19) — scores are not directly comparable.

Lenses

  • Code Health 53 → 53 (+0.0)
  • Architecture 99 → 99 (+0.0)
  • Maturity 72 → 71 (-0.5)
  • Readiness 44 → 49 (+5.8)
  • Security 74 → 70 (-4.2)

Resolved (8)

  • High CVE: [GHSA redacted] (go.mod)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • LLM evaluation failed
  • Off-boarding risk: anonymized user #1

New (16)

  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • High: security finding (details withheld)
  • Hotspot: d2cli/main.go (d2cli/main.go)
  • Medium IaC: CKV_DOCKER_2 (ci/release/docker/Dockerfile)
  • Medium IaC: CKV_DOCKER_3 (ci/release/linux/Dockerfile)
  • Medium IaC: CKV_DOCKER_4 (ci/release/docker/Dockerfile)
  • Medium IaC: CKV_DOCKER_7 (ci/release/docker/Dockerfile)
  • No SBOM
  • Off-boarding risk: anonymized user #1
  • The library examples directory is referenced but only one example (1-d2lib) is shown with no links to the other two (d2oracle, lowlevel). (docs/examples/lib/README.md)
  • Unpinned build actions

Changes since last survey

  • 37 commits — 24 feature/other, 13 fixes

By area

  • (repo) — 17 commits
  • .github/workflows — 8 commits
  • ci/release — 6 commits
  • (root) — 3 commits
  • ci/sub — 1 commit
  • d2js/js — 1 commit
  • e2etests-cli/main_test.go — 1 commit

Notable commits

  • fix: Fix package installation links
  • fix: Merge pull request #2790 from d2lang/agent/fix-distribution-links
  • fix: Merge pull request #2793 from d2lang/agent/fix-cjs-asset-path
  • fix: Merge pull request #2794 from d2lang/agent/fix-npm-stage-policy
  • fix: Merge pull request #2795 from d2lang/agent/fix-npm-stage-notify
  • fix: Merge pull request #2796 from d2lang/agent/fix-wasm-opt-memory
  • fix: Merge pull request #2799 from d2lang/agent/fix-playwright-continuity
  • fix: Merge pull request #2800 from d2lang/agent/fix-playwright-cache-permissions
  • fix: fix continuity browser cache ownership
  • fix: fix d2js CJS asset paths
  • fix: fix docker continuity playwright bootstrap
  • fix: fix npm stage CI execution
  • fix: fix npm stage action policy
  • change: Merge pull request #2789 from d2lang/agent/d2lang-link-migration
  • change: Merge pull request #2791 from d2lang/agent/update-transferred-dependencies
  • change: Merge pull request #2792 from d2lang/agent/npm-trusted-publishing
  • change: Merge pull request #2797 from d2lang/agent/remove-legacy-npm-nightly
  • change: Merge pull request #2798 from d2lang/agent/docker-continuity-test
  • change: Merge pull request #2801 from d2lang/agent/migrate-playwright-go-061
  • change: Merge pull request #2802 from d2lang/agent/docker-production-workflow
  • …and 17 more

Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.

Survey your own repository

terrastruct/d2 was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.

About this page

  • The score is its most recent published measurement, taken on 6 August 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
  • Measured at commit c30239f3408f3a60036865385a0c2b3c5e345074 — the exact code this score is about.
  • Scored under rubric-2026.08.19 — the same rubric and the same method as every other entry in this index.
  • Measured by watchdog.canine.dev using codehealth-analyzer latest.