From 75fc9df5aa0847cd4331ebd55d17346a4d108c7d Mon Sep 17 00:00:00 2001 From: Yauhen Yakimovich Date: Wed, 25 Nov 2026 21:49:15 +0100 Subject: [PATCH] Toolchain 0.7.0: carry merman-cli 0.11.0 merman-cli is a native Mermaid renderer that needs no browser. HyperMarkDown draws a mermaid#show diagram cell with it, the way it draws a d2#show cell with d2. It is in all five archives, with its MIT licence text and the notices of the libraries it links. Its Linux and macOS programs are published as .tar.xz, which the build reads through the system's xz after the digest check. A pin may now name its licence file and a notices file. The release check draws a flowchart with the arguments HyperMarkDown uses, checks that the labels are SVG text, and draws it again to the same bytes. --- CHANGELOG.md | 29 ++++++++++++++++++++ README.md | 52 ++++++++++++++++++++++++----------- scripts/build-release.mjs | 55 +++++++++++++++++++++++++++----------- scripts/lib/tar.mjs | 37 ++++++++++++++++++++++++- scripts/lib/tools.mjs | 16 ++++++++--- scripts/verify-release.mjs | 41 ++++++++++++++++++++++++++-- toolchain.json | 35 +++++++++++++++++++++++- 7 files changed, 228 insertions(+), 37 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ca61797..7a03c82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,35 @@ immutable. ## [Unreleased] +## [0.7.0] — 2026-11-25 + +### Added + +- **`merman-cli` 0.11.0**, a native Mermaid renderer that needs no browser + (`latias94/merman` `v0.11.0`), in all five archives as `bin/merman-cli`, or + `bin/merman-cli.exe` on Windows. HyperMarkDown draws a `mermaid#show` diagram + cell with it, the way it draws a `d2#show` cell with `d2`. It is offered + under MIT or Apache-2.0: the MIT text is at `licenses/merman-cli/LICENSE`, + and the notices of the libraries it links are at + `licenses/merman-cli/THIRD_PARTY_NOTICES.md`. `d2` 0.9.0, `hql` 0.8.0 and + `hmd-lsp` 0.1.0 are unchanged. +- The build reads an upstream asset published as `.tar.xz`, which is how + `merman-cli` publishes its Linux and macOS programs. It runs the system's + `xz` for that, after the asset's digest is checked. +- A pin may name its licence file with `licenseFile`, for a tool whose archive + has one file for each licence it is offered under, and a `notices` file that + travels with the binary. +- The release check starts `merman-cli` on each platform with the arguments + HyperMarkDown uses. It draws a flowchart, checks that the labels are SVG + text and that no `foreignObject` or `script` element is written, and draws + it again to the same bytes. + +### Changed + +- An archive is between 43 MiB and 55 MiB, where a 0.6.0 archive was between + 17 MiB and 28 MiB. `merman-cli` is the difference. +- The Linux builds of `merman-cli` need glibc 2.35 or later. + ## [0.6.0] — 2026-11-25 ### Added diff --git a/README.md b/README.md index be7c17a..4c2a59a 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,13 @@ Pinned native binaries for [HyperMarkDown](https://github.com/ewiger/hypermarkdown). -HyperMarkDown needs three native binaries: +HyperMarkDown needs four native binaries: - [`d2`](https://github.com/d2lang/d2) to render diagrams — in CI, in the documentation build, and inside the VS Code extension; +- [`merman-cli`](https://github.com/latias94/merman) to render Mermaid + diagrams, in the same three places. It is a native Mermaid renderer that + needs no browser; - [`hql`](https://github.com/ewiger/hql) to run HQL cells — inside the VS Code extension; - [`hmd-lsp`](https://github.com/ewiger/hypermarkdown/tree/main/tools/hmd-lsp), @@ -44,16 +47,23 @@ all of them: bin/d2 # bin/d2.exe on Windows bin/hmd-lsp # bin/hmd-lsp.exe on Windows bin/hql # where HQL publishes this platform +bin/merman-cli # bin/merman-cli.exe on Windows licenses/d2/LICENSE # d2 is MPL-2.0; each binary travels with its licence licenses/hmd-lsp/LICENSE # hmd-lsp is MIT licenses/hql/LICENSE # hql is MIT +licenses/merman-cli/LICENSE # merman-cli is MIT or Apache-2.0; this is the MIT text +licenses/merman-cli/THIRD_PARTY_NOTICES.md # the licences of what merman-cli links manifest.json # toolchain version, platform, and each tool's version and upstream pin ``` A tool is in an archive exactly when `toolchain.json` pins an asset for that -platform. `d2` and `hmd-lsp` are in all five. HQL 0.8.0 publishes Linux x86_64, both macOS -targets and Windows x86_64, so only the Linux ARM64 archive carries `d2` alone; -`manifest.json` lists what an archive holds. +platform. `d2`, `hmd-lsp` and `merman-cli` are in all five. HQL 0.8.0 publishes +Linux x86_64, both macOS targets and Windows x86_64, so the Linux ARM64 archive +carries no `hql`; `manifest.json` lists what an archive holds. + +The Linux builds of `merman-cli` are linked against glibc, and version 0.11.0 +needs glibc 2.35 or later, which Ubuntu 22.04 and Debian 12 have. `d2` and +`hmd-lsp` are static and have no such requirement. `manifest.json` describes the inputs rather than the build — no timestamp, no builder identity — which is what makes the archives byte-reproducible. Building @@ -65,18 +75,22 @@ happens to have. CI rebuilds and compares on every push. ## Consuming a release Download the archive for your platform, verify it against `SHA256SUMS`, unpack -it, and use `bin/d2`, `bin/hql` and `bin/hmd-lsp`. Nothing here is meant to be consumed as source: HyperMarkDown -pins a toolchain *version* and fetches the published artifact over HTTPS. +it, and use `bin/d2`, `bin/hql`, `bin/hmd-lsp` and `bin/merman-cli`. Nothing +here is meant to be consumed as source: HyperMarkDown pins a toolchain +*version* and fetches the published artifact over HTTPS. -The version lines are independent. Bumping d2, hql or hmd-lsp happens here; +The version lines are independent. Bumping d2, hql, hmd-lsp or merman-cli happens here; HyperMarkDown bumps only the toolchain version it pins, and a published toolchain release is immutable. ## Working on this repository -Node 22+, no dependencies — the tar and zip readers and writers are in +Node 22+, no package dependencies — the tar and zip readers and writers are in [scripts/lib/](scripts/lib/) precisely so that a release cannot depend on a -package that might change under it. +package that might change under it. The build also needs the `xz` program: +`merman-cli` publishes its Linux and macOS builds as `.tar.xz`, and Node has no +xz decoder. `xz` only reads those upstream archives, after their digests are +checked, and writes nothing that is released. ```bash node scripts/build-release.mjs # build every platform into dist/ @@ -87,16 +101,18 @@ node scripts/bump-d2.mjs v0.10.0 # repin d2 to a new upstream release `build-release.mjs` verifies the upstream assets twice: once against the digests pinned in `toolchain.json`, and once against the digests upstream publishes for -that tag — a `SHA256SUMS` for d2 and for hmd-lsp, a `.sha256` beside each asset for hql. The first catches a moved tag; the second catches a pin that was -written wrong to begin with. +that tag — a `SHA256SUMS` for d2 and for hmd-lsp, a `.sha256` beside each asset +for hql and for merman-cli. The first catches a moved tag; the second catches a +pin that was written wrong to begin with. `verify-release.mjs` is the single definition of a good release — both workflows call it rather than each describing the checks themselves. It confirms every digest, the exact file list, the executable bit, and that the embedded manifest agrees with `toolchain.json`; and for the archive matching the host it extracts each binary and runs it the way its consumer does — `d2 - -` renders `a -> b`, -`hql render --emit after --envelope json -` runs a cell, and `hmd-lsp --stdio` -answers one session of the Language Server Protocol. +`hql render --emit after --envelope json -` runs a cell, `hmd-lsp --stdio` +answers one session of the Language Server Protocol, and `merman-cli render -` +draws a flowchart with its labels as SVG text, twice, to the same bytes. ## Releasing @@ -104,7 +120,10 @@ answers one session of the Language Server Protocol. `version`, `tag` and the three asset digests in `toolchain.json`; the build checks them against HQL's published `.sha256` files. To move hmd-lsp, edit its `version`, `tag`, and the five asset names and digests, from the - `SHA256SUMS` of its release; the build checks them against that file. + `SHA256SUMS` of its release; the build checks them against that file. To + move merman-cli, edit its `version`, `tag`, and the five asset digests, from + the `sha256.sum` of its release; the build checks them against the + `.sha256` file beside each asset. 2. Bump `toolchain` in `toolchain.json` and add a `CHANGELOG.md` entry. 3. Tag `v`. The release workflow rejects a tag that disagrees with `toolchain.json`, builds, verifies on all five platforms, and publishes. @@ -115,4 +134,7 @@ This repository is MIT ([LICENSE](LICENSE)). The `d2` binary it redistributes is MPL-2.0 and ships with upstream's licence text at `licenses/d2/LICENSE`; the `hql` binary is MIT and ships with its licence at `licenses/hql/LICENSE`; the `hmd-lsp` binary is MIT and ships with its licence at -`licenses/hmd-lsp/LICENSE`. +`licenses/hmd-lsp/LICENSE`; the `merman-cli` binary is offered under MIT or +Apache-2.0, and ships with the MIT text at `licenses/merman-cli/LICENSE` and +with the notices of the libraries it links, one of them under EPL-2.0, at +`licenses/merman-cli/THIRD_PARTY_NOTICES.md`. diff --git a/scripts/build-release.mjs b/scripts/build-release.mjs index 32f351a..1a4bfbf 100644 --- a/scripts/build-release.mjs +++ b/scripts/build-release.mjs @@ -3,9 +3,9 @@ // // node scripts/build-release.mjs [--platform ]... [--out dist] // -// Downloads the pinned upstream assets of every tool — d2, hql and hmd-lsp — verifies -// them twice over, and repacks them into one archive per platform with a -// stable internal layout. Output is +// Downloads the pinned upstream assets of every tool — d2, hql, hmd-lsp and +// merman-cli — verifies them twice over, and repacks them into one archive per +// platform with a stable internal layout. Output is // byte-reproducible: given the same toolchain.json, two runs produce identical // archives and an identical SHA256SUMS. @@ -24,8 +24,8 @@ import { releaseAssetUrl, sha256, } from "./lib/common.mjs"; -import { readTarGz, writeTarGz } from "./lib/tar.mjs"; -import { binaryPath, licensePath, toolsFor } from "./lib/tools.mjs"; +import { readTarGz, readTarXz, writeTarGz } from "./lib/tar.mjs"; +import { binaryPath, licensePath, noticesPath, toolsFor } from "./lib/tools.mjs"; import { readZip, writeZip } from "./lib/zip.mjs"; const ARCHIVE_MODE = 0o755; @@ -46,12 +46,14 @@ function parseArgs(argv) { /** * The entries of an upstream archive, whichever format upstream chose. d2 and - * hql publish a tarball for every platform; hmd-lsp publishes a zip for - * Windows. A zip entry carries no type, so one is given here: a name ending in - * `/` is a directory and everything else is a file, which is all the search - * below needs to know. + * hql publish a gzipped tarball for every platform; hmd-lsp and merman-cli + * publish a zip for Windows; merman-cli publishes an xz tarball for the rest. + * A zip entry carries no type, so one is given here: a name ending in `/` is a + * directory and everything else is a file, which is all the search below needs + * to know. */ function readUpstream(name, body) { + if (name.endsWith(".tar.xz")) return readTarXz(body); if (!name.endsWith(".zip")) return readTarGz(body); return readZip(body).map((entry) => ({ ...entry, type: entry.name.endsWith("/") ? "5" : "0" })); } @@ -79,10 +81,25 @@ function findExecutable(entries, tool) { return matches[0]; } -function findLicense(entries) { +/** + * One file of an upstream archive by its name, wherever the archive nests it. + * The shallowest match wins: merman-cli's archive holds a `LICENSE` for each + * dependency below `THIRD_PARTY_LICENSES/`, and the tool's own is at the top. + */ +function findNamed(entries, fileName, what) { + const matches = entries + .filter((entry) => entry.type === "0" && entry.name.split("/").pop() === fileName) + .sort((a, b) => a.name.split("/").length - b.name.split("/").length); + if (matches.length === 0) fail(`no ${what} \`${fileName}\` found in the upstream archive`); + return matches[0]; +} + +function findLicense(entries, spec) { // d2 is MPL-2.0, and hql and hmd-lsp are MIT under their own copyright // lines, so redistributing a binary means shipping upstream's licence text - // alongside it. + // alongside it. merman-cli is offered under MIT or Apache-2.0 and names each + // text in its own file, so its pin says which one travels: `licenseFile`. + if (spec.licenseFile !== undefined) return findNamed(entries, spec.licenseFile, "licence file"); const match = entries.find((entry) => /(^|\/)LICENSE(\.[A-Za-z]+)?$/.test(entry.name) && entry.type === "0"); if (!match) fail("no LICENSE file found in the upstream archive"); return match; @@ -104,11 +121,19 @@ async function toolFiles(manifest, tool, platform) { const entries = readUpstream(asset.name, upstreamArchive); const path = binaryPath(tool, platform); + const files = [ + { name: path, mode: ARCHIVE_MODE, body: findExecutable(entries, tool).body }, + { name: licensePath(tool), mode: LICENSE_MODE, body: findLicense(entries, spec).body }, + ]; + if (spec.notices !== undefined) { + files.push({ + name: noticesPath(tool), + mode: LICENSE_MODE, + body: findNamed(entries, spec.notices, "notices file").body, + }); + } return { - files: [ - { name: path, mode: ARCHIVE_MODE, body: findExecutable(entries, tool).body }, - { name: licensePath(tool), mode: LICENSE_MODE, body: findLicense(entries).body }, - ], + files, entry: { version: spec.version, path, diff --git a/scripts/lib/tar.mjs b/scripts/lib/tar.mjs index 41b2abd..94f0316 100644 --- a/scripts/lib/tar.mjs +++ b/scripts/lib/tar.mjs @@ -6,6 +6,7 @@ // everywhere, and it lets the writer state plainly that every field except the // name, size and mode is a constant. +import { spawnSync } from "node:child_process"; import { gzipSync, gunzipSync } from "node:zlib"; const BLOCK = 512; @@ -41,7 +42,41 @@ function readOctal(block, offset, length) { * @returns {{name: string, mode: number, type: string, body: Buffer}[]} */ export function readTarGz(gzipped) { - const buf = gunzipSync(gzipped); + return readTar(gunzipSync(gzipped)); +} + +/** + * Parse an xz-compressed tar into entries. + * + * Node has no xz decoder, so this one step runs the system's `xz`. It is the + * only program the build starts, and it runs after the compressed bytes were + * checked against their pinned digest, so what it is given is known. It only + * reads upstream: every archive this repository writes is still written here, + * which is what keeps a release byte-reproducible. + * + * @param {Buffer} compressed + */ +export function readTarXz(compressed) { + const done = spawnSync("xz", ["--decompress", "--stdout"], { + input: compressed, + maxBuffer: 1024 * 1024 * 1024, + }); + if (done.error) { + throw new Error(`cannot run \`xz\` to read an upstream .tar.xz: ${done.error.message}`); + } + if (done.status !== 0) { + throw new Error(`\`xz\` failed on an upstream .tar.xz: ${done.stderr.toString("utf8").trim()}`); + } + return readTar(done.stdout); +} + +/** + * Parse an uncompressed tar into entries. + * + * @param {Buffer} buf + * @returns {{name: string, mode: number, type: string, body: Buffer}[]} + */ +export function readTar(buf) { const entries = []; let offset = 0; let pendingName = null; diff --git a/scripts/lib/tools.mjs b/scripts/lib/tools.mjs index ee812b7..86a199e 100644 --- a/scripts/lib/tools.mjs +++ b/scripts/lib/tools.mjs @@ -2,9 +2,9 @@ // verifier so the two cannot disagree about a layout. // // A tool appears in a platform's archive exactly when toolchain.json pins an -// asset for that platform. d2 and hmd-lsp publish all five; hql publishes four, -// and the Linux ARM64 archive simply carries no hql — a consumer falls back to -// PATH there. +// asset for that platform. d2, hmd-lsp and merman-cli publish all five; hql +// publishes four, and the Linux ARM64 archive simply carries no hql — a +// consumer falls back to PATH there. /** The tools pinned for a platform, in a stable order. */ export function toolsFor(manifest, platform) { @@ -21,11 +21,21 @@ export function licensePath(tool) { return `licenses/${tool}/LICENSE`; } +/** + * Where a tool's third-party notices go, for a tool that pins a `notices` + * file. merman-cli links layout engines under other licences than its own, and + * its archive names them in one file that has to travel with the binary. + */ +export function noticesPath(tool) { + return `licenses/${tool}/THIRD_PARTY_NOTICES.md`; +} + /** Every file a platform's archive holds, sorted. */ export function expectedFiles(manifest, platform) { const files = ["manifest.json"]; for (const tool of toolsFor(manifest, platform)) { files.push(binaryPath(tool, platform), licensePath(tool)); + if (manifest.tools[tool].notices !== undefined) files.push(noticesPath(tool)); } return files.sort(); } diff --git a/scripts/verify-release.mjs b/scripts/verify-release.mjs index a930318..04d73cc 100644 --- a/scripts/verify-release.mjs +++ b/scripts/verify-release.mjs @@ -7,8 +7,9 @@ // it contains exactly the files the layout promises for its platform, its // embedded manifest agrees with toolchain.json, and — for the archive matching // the host — every extracted binary actually runs: d2 renders, hql runs a -// cell, and hmd-lsp answers a client. Both workflows call this, so -// there is one definition of "a good release" rather than a copy in each. +// cell, hmd-lsp answers a client, and merman-cli draws a Mermaid diagram. Both +// workflows call this, so there is one definition of "a good release" rather +// than a copy in each. import { execFileSync } from "node:child_process"; import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs"; @@ -164,6 +165,42 @@ EXERCISE["hmd-lsp"] = (binary, expectedVersion, dir) => { return version; }; +EXERCISE["merman-cli"] = (binary, expectedVersion) => { + const version = execFileSync(binary, ["--version"], { encoding: "utf8" }).trim(); + check( + version === `merman-cli ${expectedVersion}`, + `merman-cli --version reported ${JSON.stringify(version)}, expected "merman-cli ${expectedVersion}"`, + ); + // The arguments HyperMarkDown draws a Mermaid diagram with: the source on + // stdin, SVG on stdout, labels as SVG text, the resource policy for input + // nobody vetted, and the renderer's own deadline. + const args = [ + "render", + "-", + "--format", + "svg", + "--svg-pipeline", + "resvg-safe", + "--resource-profile", + "constrained", + "--operation-timeout-ms", + "2000", + "--quiet", + ]; + const draw = (source) => execFileSync(binary, args, { input: source, encoding: "utf8", timeout: 30_000 }); + const source = "flowchart LR\n A[Card on disk] -->|parse| B{Has cells?}\n"; + const svg = draw(source); + check(svg.startsWith("]*>Card on disk<\/text>/.test(svg), "merman-cli did not draw the node label as SVG text"); + check(!svg.includes("