Skip to content

Diagram export to draw.io, Visio and Lucidchart (DECISIONS 311–348) - #133

Draft
bmjcoding wants to merge 18 commits into
mainfrom
claude/diagram-interop
Draft

bmjcoding wants to merge 18 commits into
mainfrom
claude/diagram-interop

Conversation

@bmjcoding

@bmjcoding bmjcoding commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Export Basalt diagrams to draw.io, Visio and Lucidchart, deterministically, so an agent writes Basalt's diagram JSON and runs one command instead of hand-tuning a tool's file (DECISIONS 311, 314, 324, 327, 348). The owner: "it needs to be deterministic so models don't spend tens of thousands of tokens getting it 'just right' for lucid." He imported Neon's first .vsdx proof into Lucid himself: "loks like except that single line thats off the import worked". That jog is fixed here.

What it adds

  • @srasyndicate/basalt/diagram-interop, a subpath outside the index: diagramToDrawio, diagramToVsdx, diagramToLucid (and diagramToLucidJson), exportMeasuredDiagram for a live figure, and placeAutoDiagram.
  • What each export carries: one connector per edge, glued to its ports, with Basalt's route as waypoints, snapped to the port in each tool's own units, so no tool inserts a joining segment; groups as containers, nested two deep; lanes; schema tables with their key rows; crow's-foot cardinality and far keys through their corridors; sequence lifelines, messages, opt / loop / alt frames with word-sized labels and dividers, and activation bars; labels on their connectors; line kinds and heads; the focal style; light, dark and adaptive.
  • Service marks only with --marks embed and only where the manifest's terms allow (87 of 104). Kubernetes carries its credit in the file's metadata (DECISIONS 333).
  • The basalt-diagram-export CLI: <input.json|page.html> --to drawio,vsdx,lucid [--theme] [--marks] [--out] [--width].
    • Exact geometry by default: it measures the real figure in headless Chromium through an optional Playwright peer (owner-approved, DECISIONS 348), after Geist and Geist Mono have loaded.
    • Records which Chromium, platform and Basalt version measured it.
    • Without Playwright, it falls back to an approximate headless layout and says so on stderr. --headless asks for that path; --browser refuses to fall back.
  • The HTML skill's rule: never hand-write .drawio, .vsdx or .lucid; author the diagram JSON and run the CLI.
  • No new runtime dependency. The ZIP writer has no dependencies, and Playwright is an optional peer, never installed for an app. elkjs's one copy stays as batch B shipped it.

Council

  • Proposal and build: Neon proposed and built it.
  • Phase 1 fixes: Neon ran out of usage limits mid-round, and Opus finished the round with Neon credited.
  • Code reviews: Opus reviewed both phases (the owner took the GPT seat off diagrams, DECISIONS 284).
Seat Phase 1 (394707ee) Phase 2 (7be7d09a)
Opus (code) 6/10, 3 blocking, fixed in 2b55ca12, 7cb998c5, 6ea8ac58 7/10, 2 blocking (fonts measured before load; frame labels as full-width boxes), fixed with all nine polish items in 131cd220, 19d3fbc3, 69fbb71c, 253788c3

The last fixes were not re-reviewed by a seat.

For the owner: import the .vsdx samples into Lucid the way you checked the first proof. .lucid is Lucid's Standard Import for its REST API only: Lucid's Import documents rejects it, which the owner found (b905abc3 now says so in the CLI's help and output, the skill's usage and the JSDoc). They're in .review/diagram-interop/{light,dark}/: the five CIMIP figures plus nested groups, crow's foot, frames, automatic layout and marks, as .drawio, .vsdx and .lucid.

Checks

  • Determinism: output is byte-identical on repeat (SHA-256), under UTC/C and Asia/Kolkata/de_DE. In the sample checks, every Visio connector end is exact to 1.8e-15 in, and no draw.io edge has a diagonal segment.
  • What passes: lint (all five steps), both typechecks, npm run build, npm run sizes, diagram-interop.test.mjs 33/33, bundle.test.mjs 118/118 and node scripts/verify-packages.mjs.
  • What verify-packages covers: the packed install's .bin CLI writing files, the fallback warning without Playwright, --browser's strict error, and automatic layout without elkjs.

Browser tests did not run. The owner paused them (DECISIONS 330). diagram-interop-browser.test.mjs is written and not run: the live comparison to 0.5px (every figure alone, labels included), repeat hashes and Chromium metadata. npm run ci:local has not run on this head.

Sizes

The subpath is 133,770 bytes minified (38,790 gzipped), now in the size table. Still diagrams and all 425 root exports did not move.

🤖 Generated with Claude Code

bmjcoding and others added 18 commits November 23, 2026 18:24
- Add the @srasyndicate/basalt/diagram-interop subpath outside the root
  index (diagramToDrawio, diagramToVsdx, diagramToLucid, diagramToLucidJson,
  exportMeasuredDiagram, readMeasuredExtras, isBundledMarkEmbeddable) with
  zero new runtime dependencies and 0 bytes added to still diagrams.
- Cover all five Basalt diagram types (architecture, flowchart, data-flow,
  sequence, schema) with deterministic store-mode ZIP output, real
  containers/swimlanes/tables, single glued orthogonal connectors, attached
  labels, light/dark/adaptive themes, and manifest-gated mark embedding
  (default omit).
- Snap connector endpoints and first/last waypoints directly to each shape's
  exact port coordinates in the target's own units (Visio inches, draw.io px,
  Lucid px), eliminating the RunTask joining jog seen in Lucidchart import.
- Add the basalt-diagram-export CLI reading Basalt diagram JSON or HTML
  <script type="application/json" data-diagram> blocks (headless by default,
  optional --browser measurement).

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…-writing XML

- Record the rule in SKILL.md and diagram.md usage notes to author Basalt
  diagram JSON and run basalt-diagram-export rather than hand-writing
  .drawio, .vsdx or .lucid files.
- Keep both SKILL.md (12,557 / 12,650 B) and diagram.md (4,011 / 4,300 B)
  within their byte caps and rebuild the packaged usage part.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…ckage checks

- Add packages/react/test/diagram-interop.test.mjs covering all five CIMIP
  fixtures across .drawio, .vsdx and .lucid: byte-identical SHA-256
  determinism, mxfile-1.0.xsd validation, Visio OPC parts / Connects glue /
  ConFixedCode=2, Lucid Standard Import JSON contract, exact port
  axis-alignment (including the RunTask L-bend invariant), live Chromium
  exportMeasuredDiagram, manifest mark terms, CLI inputs, and subpath
  isolation.
- Extend scripts/verify-packages.mjs to verify dist/diagram-interop.{js,d.ts},
  bin/basalt-diagram-export.mjs, TypeScript types and runtime smoke checks
  in an external packed consumer.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…measured lanes, marks from the manifest

From Opus's code review of the converter (DECISIONS 327).

- B3: a dark .vsdx starts with a locked, full-page surface-page shape
  (PageBackground, ID 1), so lines and lane words no longer sit on Visio's
  white page. .lucid keeps pages[].settings.fillColor: Lucid's Standard
  Import reference (Pages, Page Settings) documents fillColor as the
  canvas background colour, so it needs no shape.
- Polish 2: measured lanes carry their DOM index, and sceneFromMeasured
  falls back to it when the model's lane id isn't there, so a measured
  lane rect reaches the scene instead of an estimate from its cards.
- Polish 3: a .vsdx group is a Visio container (User.msvStructureType
  "Container", Relationships DEPENDSON(1, members) on the group and
  DEPENDSON(4, group) on each member), so moving it moves its services.
- Polish 4: a .lucid table's userSpecifiedRows are taken from the scene's
  row positions and sum to the table's height, so FK ends sit on their
  rows' centres.
- Polish 5: the embeddable marks and their attributions are read from
  marks/manifest.json's terms at build time (the same 87 of 104 as the
  hard-coded list); the Kubernetes attribution goes into the .vsdx
  document description and the .lucid image's customData.
  Adaptive .drawio carries both mark forms behind prefers-color-scheme.
- Polish 7: the subpath is built with NODE_ENV defined, so it runs as
  native browser ESM without `process`. (It still bundles its own
  diagram-core: see the round's report.)
- Polish 8: Math.hypot replaced by exact sums on axis-aligned segments
  and Math.sqrt (correctly rounded in every engine) elsewhere. The light
  .drawio samples are byte-identical to before.

diagram-core.ts is unchanged.

Co-Authored-By: Gemini Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ser; custom mark files; --out checks

From Opus's code review of the converter (DECISIONS 327).

- B1: the main-module check compares real paths, so the CLI runs when
  npm links it as node_modules/.bin/basalt-diagram-export (a symlink).
  package-lock.json records the package's bin. verify-packages.mjs puts
  the bin in the packed consumer's lock entry (so `npm ci` links it, as
  a real install does), runs the CLI through the link, and checks it
  wrote .drawio, .vsdx and .lucid, a dark draw.io background and the dark
  .vsdx page shape. It also prints an assertion's message now, which the
  catch used to swallow.
- --browser from a packed install (and polish 6): the harness serves
  only the package's own dist (styles.css, the Geist files,
  diagram-core.js, diagram-interop.js) to headless Chromium, so it no
  longer needs the repo's HTML skill. Playwright is not a dependency:
  without it the CLI exits with "npm install -D playwright && npx
  playwright install chromium", which verify-packages checks.
- Polish 9: a custom mark's file path is read relative to the input
  file; a missing file, a non-SVG file or a remote URL is a warning on
  stderr, not a silent omission.
- Polish 10: --out with a file extension needs one diagram and one
  format, and the extension must match the format.
- The skill and diagram.md give the in-repo form of the command
  (node packages/react/bin/basalt-diagram-export.mjs after npm run
  build). SKILL.md is 12,642 of its 12,650 B.
- Polish 11: f92f416 also reworded steps 1 to 3 of SKILL.md to make
  room for the export rule; that commit didn't say so. They were
  shortened: step 1's "the classes, attributes and tags that bring it
  in" became "its triggers", step 3's "the modules your classes,
  attributes and tags use" became "the modules you use", and "only for a
  file a tool reads, never a file a person opens" became "tools only,
  never for readers".

Co-Authored-By: Gemini Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…age, containers, rows, CLI link and environments

From Opus's code review of the converter (DECISIONS 327).

- Polish 1: the RunTask test works out Begin and End against the
  Connection rows they are glued to (value and formula) and requires
  2e-6 in. The proof .vsdx that jogged in Lucid is a fixture
  (test/fixtures/runtask-jog-proof.vsdx, read with a general ZIP
  reader): the test requires its RunTask Begin to be 0.5 px off and
  assertValidVsdx to reject it.
- assertValidVsdx also checks every Connection row's F formula against
  its V, and that each architecture group is a Visio container listing
  its members and listed by them (checked after the glue, so the proof
  fails on its glue first).
- B3: a dark .vsdx's first shape is the locked surface-page
  PageBackground; a light one has none. .lucid's page fillColor is
  #000000 dark and #fafafa light.
- Polish 4: a .lucid table's rows sum to its height and every FK end is
  within 0.5 px of a row's centre.
- B1: the CLI run through a symlink writes its file.
- Polish 8: the two CLI runs use different TZ and LC_ALL
  (UTC/C and Asia/Kolkata/de_DE.UTF-8) and must agree byte for byte.
- Polish 9 and 10: a custom mark file is embedded, a missing one warns;
  an --out extension that doesn't match the format fails.
- Polish 5: aws-database (distinct light and dark forms) is embedded and
  adaptive draw.io carries both forms; the Kubernetes attribution lands
  in the .vsdx and the .lucid.

Written, not run (browser tests are paused, DECISIONS 330): in the live
DOM test, the headless-vs-live comparison (it records every box's and
route point's difference, printed with PRINT_INTEROP_COMPARISON=1, and
asserts nothing yet: B2 lands after batch B), polish 2's measured lane
reaching the scene, and polish 7's native-browser import with no
`process`; and the packaged --browser CLI test.

Co-Authored-By: Gemini Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…diagram-interop

Resolve conflicts in build.mjs, package.json, verify-packages.mjs and SKILL.md (rewording steps 1-3 to keep SKILL.md within its 13050 B budget while keeping the export rule and all main rules; raising diagram usage cap 4600 -> 4850 in modules.json for the merged export line). Fix oxlint no-new-array and narrow MStep on sequence frames in scene.ts so the merge commit builds cleanly.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…ps, and auto-layout placement

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…n draw.io, Visio, and Lucid

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
… with approximate headless fallback

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…etry, tighten port precision

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…tion, and tag every Lucid node

Fixes phase 2 review B2 and polish 1, 2, and 5:
- Read measured .basalt-diagram-flabel and .basalt-diagram-fword rects (and measure word boxes headlessly) so frame header and else labels never cover uncovered lifelines in draw.io, Visio, or Lucid, and match Basalt's 600 tab / 500 label weights.
- Remove par from MeasuredFrame, SceneFrame, readMeasuredExtras, and writer comments so the public surface matches Basalt's opt/loop/alt frames.
- Match Chromium's direction rule in headless pickPlacement by choosing the first candidate whose minimum width fits target width.
- Write basalt_measured_by customData on every Lucid node shape.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…r, and include platform and Basalt version in metadata

Fixes phase 2 review B1 and polish 3, 4, and 5:
- Explicitly load all document.fonts faces before measurement and assert Geist and Geist Mono are active before every figure so single-figure runs never measure on fallback metrics.
- Fail non-zero under --browser if a figure cannot fit drawn in Chromium; log a stderr note when widening past --width.
- Strip the duplicate basalt-diagram-export: prefix in the approximate headless fallback warning and note automatic direction differences.
- Record process.platform and Basalt's package version beside the Chromium version in measuredBy metadata.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…-interop in the size table

Fixes phase 2 review polish 6 and 8:
- Cite DECISIONS 348 for the optional Playwright peer in dependencies.allowed.json, note optional peers in $comment, and bound the range to >=1.40.0 <2.
- Measure @srasyndicate/basalt/diagram-interop in export-sizes.mjs, record it in export-sizes.json (133,770 B minified / 38,790 B gzipped), and guard it in bundle.test.mjs.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…-figure fonts, B2 frame labels, and polish items

- Test B2 word-sized frame headers and else rows against lifeline coverage and weights across draw.io, Visio, and Lucid.
- Test Polish 2 headless auto-layout direction selection, Polish 4 single-prefix fallback warning, and Polish 5 metadata on every Lucid node.
- Extend diagram-interop-browser.test.mjs (written, not run per tests-paused.md) to run one figure per CLI call across CIMIP and Batch B fixtures and compare edge label positions, lifelines, frames, and dividers within 0.5px.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…'s UI

Make every place that offers .lucid (CLI --help, CLI stdout line for .lucid, diagramToLucid/diagramToLucidJson/exportMeasuredDiagram JSDoc, and the basalt-html diagram usage text) state plainly that .lucid is for Lucid's REST API (POST https://api.lucid.co/v1/documents with a token, type x-application/vnd.lucid.standardImport) and that importing through Lucid's own screen uses .vsdx.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…layer labels, and compact crow's feet

Addresses all four defects from the owner's Lucidchart .vsdx import:
1. Disable line jumps (LineJumpCode=0 on PageSheet, ConLineJumpCode=1 on connectors), allocate one dedicated Connection row per connector end with outward DirX/DirY normals, and bind aligned bend coordinates to Visio 0/Width*1/Height*1 formulas so Lucidchart keeps orthogonal legs straight without small port-shift steps.
2. Emit every edge label, sequence band label, frame tab, frame header label, and else row as a word-sized opaque page-colour shape (FillPattern=1, NoFill=0, NoLine=1) painted after lifelines, activation bars, and connectors so lines and bars never cut through words.
3. Shrink Visio crow's-foot arrow size to Very Small (0) so markers fit 28px table rows cleanly, and widen short (< 27px) 6-point schema corridor final stubs to ~35px when clear so Lucidchart keeps the corridor orthogonal instead of collapsing it into a diagonal.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
…d top-layer opaque labels

Updates assertValidVsdx to verify LineJumpCode=0, ConLineJumpCode=1, unique per-connector Connection ports, compact crow's-foot BeginArrowSize/EndArrowSize=0, and opaque FillPattern=1 EdgeLabel_*/FrameTab_*/FrameLabel_*/FrameElse_*/BandLabel_* shapes painted above connectors and activation bars.

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant