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
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ immutable.

## [Unreleased]

## [0.6.0] — 2026-11-25

### Added

- **`hmd-lsp` 0.1.0**, the HyperMarkDown language server
(`ewiger/hypermarkdown` `lsp-v0.1.0`), in all five archives as `bin/hmd-lsp`,
or `bin/hmd-lsp.exe` on Windows, with its licence at
`licenses/hmd-lsp/LICENSE`. It is one native program that speaks the Language
Server Protocol over standard input and output. `d2` 0.9.0 and `hql` 0.8.0
are unchanged.
- The build reads an upstream asset published as a zip, which is how `hmd-lsp`
publishes its Windows program. `d2` and `hql` publish a tarball for every
platform.
- The release check starts `hmd-lsp` on each platform and runs one session: it
opens a card in a vault, asks for its semantic tokens, and stops the server.

## [0.5.3] — 2026-11-25

### Changed
Expand Down
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

Pinned native binaries for [HyperMarkDown](https://github.com/ewiger/hypermarkdown).

HyperMarkDown needs two native binaries:
HyperMarkDown needs three native binaries:

- [`d2`](https://github.com/d2lang/d2) to render diagrams — in CI, in the
documentation build, and inside the VS Code extension;
- [`hql`](https://github.com/ewiger/hql) to run HQL cells — inside the VS Code
extension.
extension;
- [`hmd-lsp`](https://github.com/ewiger/hypermarkdown/tree/main/tools/hmd-lsp),
the HyperMarkDown language server, to colour links by whether they resolve
and to answer hover and Go to Definition — inside the VS Code extension.

Before this repository existed `d2` was acquired separately in each place from a
moving `:latest` Docker tag, so two runs could render the same diagram
Expand All @@ -17,8 +20,10 @@ reproducible archive per platform, one checksum file.

It packages only native executables released elsewhere. HQL is its own project
with its own releases, so to HyperMarkDown it is a pinned binary like `d2`. The
`hmd` CLI, the HMD LSP and the VS Code extension are HyperMarkDown components and
live in the main repository.
language server is built and released by the main repository, on its own
`lsp-v` tags, and is pinned here from that release like the other two. The
`hmd` CLI and the VS Code extension are HyperMarkDown components that live in
the main repository and are not packaged here.

## What a release contains

Expand All @@ -37,14 +42,16 @@ all of them:

```text
bin/d2 # bin/d2.exe on Windows
bin/hmd-lsp # bin/hmd-lsp.exe on Windows
bin/hql # where HQL publishes this platform
licenses/d2/LICENSE # d2 is MPL-2.0; each binary travels with its licence
licenses/hql/LICENSE # hql is MIT
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
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` is in all five. HQL 0.8.0 publishes Linux x86_64, both macOS
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.

Expand All @@ -58,10 +65,10 @@ 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` and `bin/hql`. Nothing here is meant to be consumed as source: HyperMarkDown
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.

The version lines are independent. Bumping d2 or hql happens here;
The version lines are independent. Bumping d2, hql or hmd-lsp happens here;
HyperMarkDown bumps only the toolchain version it pins, and a published
toolchain release is immutable.

Expand All @@ -80,21 +87,24 @@ 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, a `.sha256` beside each asset for hql. The first catches a moved tag; the second catches a pin that was
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.

`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`,
and `hql render --emit after --envelope json -` runs a cell.
`hql render --emit after --envelope json -` runs a cell, and `hmd-lsp --stdio`
answers one session of the Language Server Protocol.

## 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.
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.
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 @@ -103,4 +113,6 @@ and `hql render --emit after --envelope json -` runs a cell.

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`.
`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`.
28 changes: 21 additions & 7 deletions scripts/build-release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
// node scripts/build-release.mjs [--platform <id>]... [--out dist]
//
// Downloads the pinned upstream assets of every tool — d2 and hql — verifies
// 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
// byte-reproducible: given the same toolchain.json, two runs produce identical
Expand All @@ -26,7 +26,7 @@ import {
} from "./lib/common.mjs";
import { readTarGz, writeTarGz } from "./lib/tar.mjs";
import { binaryPath, licensePath, toolsFor } from "./lib/tools.mjs";
import { writeZip } from "./lib/zip.mjs";
import { readZip, writeZip } from "./lib/zip.mjs";

const ARCHIVE_MODE = 0o755;
const LICENSE_MODE = 0o644;
Expand All @@ -45,8 +45,21 @@ function parseArgs(argv) {
}

/**
* Find a tool's single executable in an extracted upstream tarball. d2 nests it
* at `d2-v<version>/bin/d2` and hql at `hql-v<version>-<target>/hql`; searching
* 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.
*/
function readUpstream(name, body) {
if (!name.endsWith(".zip")) return readTarGz(body);
return readZip(body).map((entry) => ({ ...entry, type: entry.name.endsWith("/") ? "5" : "0" }));
}

/**
* Find a tool's single executable in an extracted upstream archive. d2 nests it
* at `d2-v<version>/bin/d2`, hql at `hql-v<version>-<target>/hql`, and hmd-lsp
* at `hmd-lsp-v<version>-<target>/hmd-lsp`; searching
* by name means a layout change surfaces as a clear failure here rather than as
* an archive that is missing its binary.
*/
Expand All @@ -67,8 +80,9 @@ function findExecutable(entries, tool) {
}

function findLicense(entries) {
// d2 is MPL-2.0 and hql is MIT, not this repo's licence, so redistributing a
// binary means shipping upstream's licence text alongside it.
// 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.
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 @@ -88,7 +102,7 @@ async function toolFiles(manifest, tool, platform) {
fail(`${asset.name}: pinned sha256 ${asset.sha256}, downloaded ${actual}`);
}

const entries = readTarGz(upstreamArchive);
const entries = readUpstream(asset.name, upstreamArchive);
const path = binaryPath(tool, platform);
return {
files: [
Expand Down
5 changes: 3 additions & 2 deletions scripts/lib/tools.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +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 publishes 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 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.

/** The tools pinned for a platform, in a stable order. */
export function toolsFor(manifest, platform) {
Expand Down
9 changes: 6 additions & 3 deletions scripts/lib/zip.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ export function writeZip(files) {
}

/**
* Read a zip written by writeZip. Enough of the format to let the verifier
* inspect the Windows artifact the same way it inspects the tarballs — it
* walks the central directory rather than scanning for local headers.
* Read a zip. Enough of the format to let the verifier inspect the Windows
* artifact the same way it inspects the tarballs, and to let the build read an
* upstream asset published as a zip. It walks the central directory rather
* than scanning for local headers, so sizes are right even for an archiver
* that writes them after the data. Stored and deflated entries only, and no
* zip64: every archive read here is a few megabytes.
*
* @param {Buffer} buf
* @returns {{name: string, mode: number, body: Buffer}[]}
Expand Down
73 changes: 71 additions & 2 deletions scripts/verify-release.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
// Checks every archive in the output directory: its digest matches SHA256SUMS,
// 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, and hql runs a
// cell. Both workflows call this, so
// 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.

import { execFileSync } from "node:child_process";
import { chmodSync, mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
import { readFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { pathToFileURL } from "node:url";

import { ROOT, fail, parseSums, readManifest, sha256 } from "./lib/common.mjs";
import { readTarGz } from "./lib/tar.mjs";
Expand Down Expand Up @@ -95,6 +96,74 @@ const EXERCISE = {
},
};

/** One Language Server Protocol message, framed as the protocol frames it. */
function frame(message) {
const body = JSON.stringify({ jsonrpc: "2.0", ...message });
return `Content-Length: ${Buffer.byteLength(body)}\r\n\r\n${body}`;
}

/** The messages in a server's output, in the order it wrote them. */
function unframe(output) {
const messages = [];
let rest = Buffer.from(output, "utf8");
for (;;) {
const head = rest.indexOf("\r\n\r\n");
if (head === -1) return messages;
const length = /Content-Length: (\d+)/i.exec(rest.subarray(0, head).toString("utf8"));
if (length === null) return messages;
const start = head + 4;
const end = start + Number(length[1]);
messages.push(JSON.parse(rest.subarray(start, end).toString("utf8")));
rest = rest.subarray(end);
}
}

EXERCISE["hmd-lsp"] = (binary, expectedVersion, dir) => {
const version = execFileSync(binary, ["--version"], { encoding: "utf8" }).trim();
check(
version === `hmd-lsp ${expectedVersion}`,
`hmd-lsp --version reported ${JSON.stringify(version)}, expected "hmd-lsp ${expectedVersion}"`,
);
// One whole session over stdin and stdout, as the extension starts it:
// `--stdio`, diagnostics off, a card opened, its tokens asked for, and a
// clean stop. The card links to a card that exists and to one that does
// not, so the answer shows the server resolved against the vault on disk.
const vault = join(dir, "lsp-vault");
mkdirSync(join(vault, ".hmd"), { recursive: true });
writeFileSync(join(vault, "tokens.hmd"), "# Tokens\n");
const uri = pathToFileURL(join(vault, "login.hmd")).href;
const session = [
{ id: 1, method: "initialize", params: { capabilities: {}, initializationOptions: { diagnostics: false } } },
{ method: "initialized", params: {} },
{
method: "textDocument/didOpen",
params: { textDocument: { uri, languageId: "hmd", version: 1, text: "[[tokens]] [[nowhere]]\n" } },
},
{ id: 2, method: "textDocument/semanticTokens/full", params: { textDocument: { uri } } },
{ id: 3, method: "shutdown", params: null },
{ method: "exit", params: null },
];
const answers = unframe(
execFileSync(binary, ["--stdio"], { input: session.map(frame).join(""), encoding: "utf8", timeout: 30_000 }),
);
const answer = (id) => answers.find((message) => message.id === id)?.result;
check(
answer(1)?.serverInfo?.name === "hmd-lsp" && answer(1)?.serverInfo?.version === expectedVersion,
`hmd-lsp introduced itself as ${JSON.stringify(answer(1)?.serverInfo)}`,
);
// Two tokens: `tokens` resolves, and `nowhere` carries the first modifier,
// which the server's legend names `unresolved`.
check(
JSON.stringify(answer(2)?.data) === JSON.stringify([0, 2, 6, 0, 0, 0, 11, 7, 0, 1]),
`hmd-lsp answered semantic tokens ${JSON.stringify(answer(2)?.data)}`,
);
check(
answer(1)?.capabilities?.semanticTokensProvider?.legend?.tokenModifiers?.[0] === "unresolved",
"hmd-lsp's first token modifier is not `unresolved`",
);
return version;
};

async function main() {
const outIndex = process.argv.indexOf("--out");
const out = join(ROOT, outIndex === -1 ? "dist" : process.argv[outIndex + 1]);
Expand Down
33 changes: 32 additions & 1 deletion toolchain.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"toolchain": "0.5.3",
"toolchain": "0.6.0",
"platforms": [
"linux-x86_64",
"linux-arm64",
Expand Down Expand Up @@ -65,6 +65,37 @@
"sha256": "5064a257e475fe92481e19a785146253362c92d239d3a5021288b446244d4d8f"
}
}
},
"hmd-lsp": {
"version": "0.1.0",
"upstream": {
"repo": "ewiger/hypermarkdown",
"tag": "lsp-v0.1.0"
},
"checksums": "SHA256SUMS",
"license": "MIT",
"assets": {
"linux-x86_64": {
"name": "hmd-lsp-v0.1.0-x86_64-unknown-linux-musl.tar.gz",
"sha256": "99791d0774cbd0d52da2243011313b3fcd29cd577dcfcf6b0db16230236802ee"
},
"linux-arm64": {
"name": "hmd-lsp-v0.1.0-aarch64-unknown-linux-musl.tar.gz",
"sha256": "a789727661fcb23c353c60f8b0ad96831b94779262b6dbacc39cf8f9cccd899a"
},
"macos-x86_64": {
"name": "hmd-lsp-v0.1.0-x86_64-apple-darwin.tar.gz",
"sha256": "9d7b2fb7c1f5bcd8a5b74be71b51e7d825f92b378241a96cd4eed58b58e700c0"
},
"macos-arm64": {
"name": "hmd-lsp-v0.1.0-aarch64-apple-darwin.tar.gz",
"sha256": "f06b73071d5543d85f1f65301d00c0345b4c76579c3d25b25eb2158b882c9f57"
},
"windows-x86_64": {
"name": "hmd-lsp-v0.1.0-x86_64-pc-windows-msvc.zip",
"sha256": "162b800f390b8d49bde4c994d1df13df8622c0df036ac8e0aeeab4f79be9795c"
}
}
}
}
}
Loading