Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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/
Expand All @@ -87,24 +101,29 @@ 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

1. `node scripts/bump-d2.mjs <tag>` if d2 is moving. To move hql, edit its
`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<version>`. The release workflow rejects a tag that disagrees with
`toolchain.json`, builds, verifies on all five platforms, and publishes.
Expand All @@ -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`.
55 changes: 40 additions & 15 deletions scripts/build-release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//
// node scripts/build-release.mjs [--platform <id>]... [--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.

Expand All @@ -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;
Expand All @@ -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" }));
}
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
37 changes: 36 additions & 1 deletion scripts/lib/tar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions scripts/lib/tools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
}
41 changes: 39 additions & 2 deletions scripts/verify-release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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("<svg"), "drawing a flowchart through `merman-cli render -` produced no SVG");
// The drawing is shown as an image, which does not show HTML inside
// `foreignObject`: a label drawn that way arrives as an empty box.
check(!svg.includes("<foreignObject"), "merman-cli drew a label as HTML in a foreignObject");
check(/<text[^>]*>Card on disk<\/text>/.test(svg), "merman-cli did not draw the node label as SVG text");
check(!svg.includes("<script"), "merman-cli wrote a script element into the SVG");
// A site build and an editor must agree on a drawing, byte for byte.
check(draw(source) === svg, "merman-cli drew the same source differently the second time");
return version;
};

async function main() {
const outIndex = process.argv.indexOf("--out");
const out = join(ROOT, outIndex === -1 ? "dist" : process.argv[outIndex + 1]);
Expand Down
Loading
Loading