Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
070501f
Diagram motion tokens (DECISIONS 292, 1.2): the durations, the speed …
bmjcoding Nov 23, 2026
b1d2ac6
Service marks (DECISIONS 292, 2.2 to 2.6): the first set of 37, from …
bmjcoding Nov 23, 2026
193a1be
Diagram motion and the card's mark in the engine (DECISIONS 292, 1 an…
bmjcoding Nov 23, 2026
a258255
React: motion on the five diagrams and marks on architecture cards (D…
bmjcoding Nov 23, 2026
8d902bf
HTML skill: the diagram-motion module, marks in a page, and the diagr…
bmjcoding Nov 23, 2026
79a1842
Diagram motion: the run button's class is basalt-diagram-play, and a …
bmjcoding Nov 23, 2026
028d80f
Docs for diagram motion and service marks (DECISIONS 292, section 5)
bmjcoding Nov 23, 2026
c998195
Tests for diagram motion and service marks (DECISIONS 292, section 7)…
bmjcoding Nov 23, 2026
d4e6082
Sizes for diagram motion and marks (DECISIONS 292): a still diagram +…
bmjcoding Nov 23, 2026
7f2d3e9
Review round 65: diagram motion and service marks (DECISIONS 292)
bmjcoding Nov 23, 2026
4143896
Diagram motion, fix round 1 (React): a lazy build of its own, ink tha…
bmjcoding Nov 23, 2026
2a6ced4
Diagram motion, fix round 1 (HTML skill): the pause button's toggle, …
bmjcoding Nov 23, 2026
defa89a
Round 65 walkthrough plays, and the docs say what was fixed
bmjcoding Nov 23, 2026
9bc7584
Four unofficial marks: Jenkins, ServiceNow, BlazeMeter and Bedrock (D…
bmjcoding Nov 23, 2026
7594c02
Every focal node prints its fill with Background graphics off (DECISI…
bmjcoding Nov 23, 2026
6fdc5ab
Diagram tests fixed and run (DECISIONS 298); the entrance keeps its o…
bmjcoding Nov 23, 2026
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
1 change: 1 addition & 0 deletions .agent/skills/basalt-html/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Markup built only at run time (a `.row` your script writes) won't be seen: add `
- **terminal** `.terminal`: with `.code`; lines are `span[data-kind]`; the script draws the gutter.
- **chart** `.chart`: JSON in `script[data-chart]`; `null` is a day not observed, never zero; needs a `summary`.
- **diagram** `.diagram`: JSON in `script[data-diagram]`; sides only to change the default; needs a `summary`.
- **diagram-motion** `"motion": "animated"`: added for you, with `loops`; a flow line needs a label; one mover a figure.
- **sparkline** `.sparkline`: JSON in `script[data-sparkline]`; one line, no axes or series (that is a `chart`).
- **palette** `data-open-palette`, `Basalt.init({ palette })`: `keys` is an array, `['⌘', 'S']`: ⌘, ⌃ or ⌥ plus one key.
- **command-list** `.command-list`: the script builds it; items are the palette's; ⌘K goes to the palette when the page has one.
Expand Down
91 changes: 85 additions & 6 deletions .agent/skills/basalt-html/compose.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
// compose.mjs wraps it in the doctype, meta and theme bootstrap, adds Geist (inlined, unless --no-fonts), the core CSS and
// script and only the modules the body uses, the icons it names, and `Basalt.init()` unless the body already calls it.
// A comment, script, style, svg or template that is never closed is refused. A style, title, meta or link inside an svg or a template is left where it is.
// The output is the same for the same input. It reads only the files beside it (parts/ and SKILL.md) and writes only --out.
// The output is the same for the same input. It reads only the files beside it (parts/ and SKILL.md), and a diagram's own service-mark files where a
// card names one by path (read from beside the body, so the page stays one file), and writes only --out.
// --all adds every module and every icon (for a page that builds markup at run time, and for measuring). No dependencies.
// After the page, it prints the one-line warning of each module it added (the module's line in SKILL.md's index), to stdout; a module
// the body never uses itself, which is in only because another module's script builds it, says so instead.
Expand Down Expand Up @@ -513,7 +514,7 @@ export function brandSvg(text) {
* The page for a body fragment. Options: fonts (default true), lang ("en"), all (every module), parts (the folder of parts).
* Returns { html, modules, icons, glyphs, built, external, bytes } (external: what the body references that leaves the file; built: { module: the module whose script builds it } for a module the body never triggers). Throws an Error with a plain message for input it can't use.
*/
export function compose(body, { fonts = true, lang = "en", all = false, parts = path.join(here, "parts") } = {}) {
export function compose(body, { fonts = true, lang = "en", all = false, parts = path.join(here, "parts"), baseDir = process.cwd() } = {}) {
if (!/^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/.test(lang)) throw new Error(`"${lang}" is not a language code`);
const manifest = JSON.parse(read(parts, "manifest.json"));
const iconFile = JSON.parse(read(parts, "icons.json"));
Expand All @@ -524,6 +525,9 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts =
let markup = held.text;
if (held.whole) throw new Error("the input is a whole page; give compose.mjs the body fragment only (the HTML that goes inside <body>)");
const use = [];
// A diagram's service marks (DECISIONS 292, 2.6): the bundled ids a page names (in its cards, or in a <!-- basalt:marks … --> comment for a figure drawn
// from script) and its own marks, read into the page. One rule a mark, however many cards use it.
const marks = { named: [], used: new Map(), baseDir, file: null, parts };
const styles = [];
const headTags = [];
let title = null;
Expand All @@ -533,6 +537,8 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts =
if (kind === "title" && title === null) { title = inner.trim(); return ""; }
if (kind === "head") { headTags.push(headTag(text.trim(), held.saved[Number(i)].attrs)); return ""; }
if (kind === "svg" && readTag(text, 0).attrs.some((a) => a[0] === "data-brand")) return brandSvg(text) + ws;
const named = kind === "comment" && text.match(/^<!--\s*basalt:marks\s+([\s\S]*?)-->$/);
if (named) { marks.named.push(...named[1].split(/[\s,]+/).filter(Boolean)); return ws; }
const directive = kind === "comment" && text.match(/^<!--\s*basalt:use\s+([\s\S]*?)-->$/);
if (!directive) return all$;
use.push(...directive[1].split(/[\s,]+/).filter(Boolean));
Expand All @@ -541,7 +547,7 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts =
for (const name of use) if (!(name in manifest.modules)) throw new Error(`basalt:use names "${name}", which is not a module (modules: ${Object.keys(manifest.modules).join(", ")})`);

const diagramNotes = [];
const content = held.restore(writeDiagrams(markup, held, parts, diagramNotes)).replace(/^\s+/, "");
const content = held.restore(writeDiagrams(markup, held, parts, diagramNotes, marks)).replace(/^\s+/, "");
title ||= held.h1 || "Untitled page"; // an empty <title> names nothing: the heading does

// Detection reads markup and code, never comments: a word written about in a comment (an HTML one, or one inside a script or a style) brings nothing in.
Expand All @@ -552,7 +558,9 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts =
const direct = detect(code, bare, [], { all, use }).modules;
const built = Object.fromEntries(chosen.modules.filter((n) => !direct.includes(n)).flatMap((n) => chosen.modules.filter((m) => (manifest.modules[m].builds ?? []).includes(n)).slice(0, 1).map((m) => [n, m])));

const css = [read(parts, "core.css"), ...chosen.modules.filter((n) => exists(parts, `${n}.css`)).map((n) => read(parts, `${n}.css`))].join("");
for (const id of marks.named) useMark(marks, id, null);
const markCss = chosen.modules.includes("diagram") ? markRules(marks) : "";
const css = [read(parts, "core.css"), ...chosen.modules.filter((n) => exists(parts, `${n}.css`)).map((n) => read(parts, `${n}.css`)), markCss].join("");
const icons = Object.fromEntries(chosen.icons.map((n) => [n, iconFile.icons[n]]));
const script = [
read(parts, "core.js"),
Expand Down Expand Up @@ -601,7 +609,7 @@ export function compose(body, { fonts = true, lang = "en", all = false, parts =
* example inside one is text and is never expanded. A figure is found by the composer's own tag reader (quoted, single-quoted or unquoted attributes alike),
* and is expanded only when its class list holds `diagram` and its content is one `script` with `data-diagram` and nothing else but white space.
*/
function writeDiagrams(markup, held, parts, notes) {
function writeDiagrams(markup, held, parts, notes, marks) {
if (!exists(parts, "diagram.js")) return markup;
const mark = held.mark;
const json = new RegExp(`^(\\s*)${mark}(\\d+)${mark}(\\s*)</figure(?=[\\t\\n\\f\\r />])[^>]*>`, "i");
Expand All @@ -621,6 +629,22 @@ function writeDiagrams(markup, held, parts, notes) {
if (!item || item.kind !== "script" || !item.attrs.some(([k]) => k === "data-diagram")) continue;
let spec;
try { spec = JSON.parse(item.inner); } catch (e) { notes.push(`a diagram's JSON does not parse (${e.message}); the page's script will say so`); continue; }
// Each card's mark: a bundled id is checked and its rule written once; the page's own mark is read into the page and named by an id, so the JSON
// the script reads carries the id and never a path.
if (spec && spec.type === "architecture" && Array.isArray(spec.nodes)) {
let rewrote = false;
for (const n of spec.nodes) {
if (!n || n.mark === undefined || n.mark === null) continue;
if (typeof n.mark === "string") useMark(marks, n.mark, n, notes);
else { n.mark = ownMark(marks, n.mark); rewrote = true; }
}
if (rewrote) {
// Every < as \u003c, which JSON reads as the same character: a title holding </script> or <!-- cannot end or bend the script it is in.
const inner = `\n${JSON.stringify(spec).replace(/</g, "\\u003c")}\n`;
item.text = item.text.replace(item.inner, () => inner);
item.inner = inner;
}
}
if (!engine) {
const context = { window: { Basalt: { _: { step() {}, esc: (x) => x } } }, console: { warn() {}, error() {}, log() {} } };
vm.runInNewContext(read(parts, "diagram.js"), context);
Expand All @@ -644,6 +668,61 @@ function writeDiagrams(markup, held, parts, notes) {
return out + markup.slice(at);
}

/** The bundled marks file (parts/marks.json), read once a page names a mark. */
const marksFile = (marks) => (marks.file ??= JSON.parse(read(marks.parts, "marks.json")));
/** A URL as a CSS string inside a <style>: a backslash and a quote escaped, a newline as \a and every < as \3c (CSS reads both as the character), so a data URI
* holding </style> cannot end the style sheet. */
const cssUrl = (u) => `url("${u.replace(/[\\"]/g, (c) => `\\${c}`).replace(/\n/g, "\\a ").replace(/</g, "\\3c ")}")`;

/** A bundled mark a page uses: known, its rule written once, and (for a card) its words checked: a mark never carries a fact alone. */
function useMark(marks, id, node, notes) {
const file = marksFile(marks);
if (marks.used.has(id)) { if (node) checkSays(file, id, node, notes); return; }
const mark = Object.hasOwn(file.marks, id) ? file.marks[id] : undefined;
if (!mark) throw new Error(`"${id}" is not a bundled service mark (the marks: ${Object.keys(file.marks).join(", ")}); a page's own mark is { "onLight": "path", "onDark": "path" }`);
marks.used.set(id, mark);
if (node) checkSays(file, id, node, notes);
}
function checkSays(file, id, node, notes) {
const says = (Object.hasOwn(file.says, id) ? file.says[id] : undefined) ?? [];
const words = [node.name, node.kind, node.detail].filter(Boolean).join(" ").toLowerCase();
if (says.length && !says.some((w) => words.includes(w.toLowerCase()))) notes.push(`${node.id}'s mark (${id}) stands for ${says.join(" or ")}, and none of its words say so: a mark never carries a fact alone`);
}

/** A page's own mark, { onLight, onDark }: each file read from beside the body into a data URI (a page is one file with no network), and an id for its rule. */
function ownMark(marks, mark) {
const uri = (ref) => {
const at = String(ref ?? "");
if (!at) throw new Error("a card's own mark needs onLight: a path to the file beside the body");
if (/^data:/i.test(at)) return at;
if (/^[a-z][\w+.-]*:/i.test(at)) throw new Error(`a card's mark is ${at}, which leaves the file: give a path beside the body, which compose.mjs reads into the page`);
const file = path.resolve(marks.baseDir, at);
const ext = path.extname(file).toLowerCase();
const type = { ".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp", ".gif": "image/gif" }[ext];
if (ext !== ".svg" && !type) throw new Error(`a card's mark is ${at}: an SVG, PNG, JPEG, WebP or GIF file`);
// Beside the body means inside its folder: a path that climbs out of it, or a link that points out of it, is not read.
const inside = (dir, f) => { const rel = path.relative(dir, f); return rel !== "" && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel); };
if (!inside(marks.baseDir, file)) throw new Error(`a card's mark is ${at}, which is outside the body's folder: put the file beside the body`);
if (!fs.existsSync(file)) throw new Error(`a card's mark is ${at}, and there is no such file beside the body`);
if (!inside(fs.realpathSync(marks.baseDir), fs.realpathSync(file))) throw new Error(`a card's mark is ${at}, which links outside the body's folder: put the file itself beside the body`);
const bytes = fs.readFileSync(file);
if (ext === ".svg") return `data:image/svg+xml,${bytes.toString("utf8").replace(/"/g, "'").replace(/%/g, "%25").replace(/#/g, "%23").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/\s+/g, " ").trim()}`;
return `data:${type};base64,${bytes.toString("base64")}`;
};
const onLight = uri(mark.onLight);
const onDark = mark.onDark ? uri(mark.onDark) : onLight;
for (const [id, m] of marks.used) if (m.onLight === onLight && (m.onDark ?? m.onLight) === onDark) return id;
const id = `page-${marks.used.size + 1}`;
marks.used.set(id, { onLight, onDark });
return id;
}

/** One rule a mark the page uses, in the diagram's layer: the two forms, which the stylesheet picks between by the ground. */
function markRules(marks) {
if (!marks.used.size) return "";
return `@layer basalt{${[...marks.used].map(([id, m]) => `.diagram-node[data-mark="${id}"]>.diagram-mark{--_ml:${cssUrl(m.onLight)}${m.onDark ? `;--_md:${cssUrl(m.onDark)}` : ""}}`).join("")}}`;
}

/** The module lines of SKILL.md's "## Modules" index: [{ name, trigger, warning }]. A line is `- **name** \`trigger\`: warning`. */
export function indexLines(skillText) {
const section = skillText.match(/^## Modules\n([\s\S]*?)(?=^## |(?![\s\S]))/m)?.[1] ?? "";
Expand Down Expand Up @@ -751,7 +830,7 @@ if (isMain) {
if (path.resolve(out) === path.resolve(input)) throw new Error(`${input} would be overwritten; name the page with --out`);
}
if (path.resolve(out) === path.resolve(input)) throw new Error("--out is the input file; name another file");
const result = compose(fs.readFileSync(input, "utf8"), options);
const result = compose(fs.readFileSync(input, "utf8"), { ...options, baseDir: path.dirname(path.resolve(input)) });
fs.writeFileSync(out, result.html);
console.log(`${out}: ${(result.bytes / 1024).toFixed(1)} KB, core + ${result.modules.join(", ") || "no modules"}; icons: ${result.icons.join(", ") || "none"}`);
// One line of warning for each module added: the mistake an agent makes with it. The full text is `--usage NAME`.
Expand Down
1 change: 1 addition & 0 deletions .agent/skills/basalt-html/parts/diagram-motion.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .agent/skills/basalt-html/parts/diagram-motion.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .agent/skills/basalt-html/parts/diagram.css

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion .agent/skills/basalt-html/parts/diagram.js

Large diffs are not rendered by default.

36 changes: 32 additions & 4 deletions .agent/skills/basalt-html/parts/manifest.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .agent/skills/basalt-html/parts/marks.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .agent/skills/basalt-html/parts/usage/diagram-motion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# diagram-motion

Added for you when a diagram's JSON says `"motion": "animated"` (with `loops`); a page that draws one from script writes `<!-- basalt:use diagram-motion -->`.

- **Entrance:** in view (two fifths of it), each line draws once in the author's order, inside five seconds; a sequence's arrows go in message order and each label lifts from secondary to primary. Every word is at rest from the first frame. It never plays under reduced motion, in forced colours, under the hold or in print, and settles at once on a hover, a focus, a key or a control.
- **Loops:** a flow line's cuts, a pulse's bead, a repeating packet. They run only in view, never while a node is traced, and stop under the page's hold. The figure's foot then has "Pause animations" (the hold's own button, built for you) after "View as list". Don't add a second one for the diagram.
- **One mover a figure:** a pulse or a packet, never both. Flow is a state of a line and never runs on a line the mover travels.
- **Run:** "Play the run" sends one dot through a sequence's messages; it reads "Stop the run" while it runs. It works under the hold and under reduced motion (by colour alone).
- `Basalt.diagram(figure, spec)` with a new `packet.send` value sends one message.
Loading
Loading