⏳ This skill is pending AI review.
Scores will appear once the review pipeline completes.
d2-slides
>-
Choose how to use this skill
You do not need every option. Choose the path your AI client supports. The stable page stays the same; versioned files are immutable.
1. Native installer
This listing has no registered native installer command. Use the complete package or source fallback below, depending on what your client supports.
Do not guess an installer command or replace an existing version without reviewing the diff.
2. Complete package recommended
Download the ZIP when available. It includes SKILL.md plus the references, security notes and version metadata.
No complete ProSkills package is published for this listing yet.3. Prompt-only
Copy the prompt above when the agent can read the stable page or when you want to adopt the workflow without installing a skill.
Need only the instruction file?
Download SKILL.md only if your client requires a single file. The complete ZIP is safer for a full installation because it preserves the references and release context.
No path installs or executes anything by itself. Your agent still needs access to the project files. Before updating, compare the installed version and review the diff.
// RATINGS
Not yet listed on ClawHub or SkillsMP
// README
explainer
English | 日本語
Skills and tools for explaining concepts from an AI to a human.
Coding agents now write faster than people can understand what they wrote (Geoffrey Litt, Understanding is the new bottleneck). This repository is for writing, for one reader, only what that reader does not already know, with claims and figures checked by tools.
Install
As a Claude Code plugin (this repository is itself a plugin marketplace; one plugin, explainer, contains five skills):
/plugin marketplace add mizchi/explainer
/plugin install explainer@explainer
From a shell: claude plugin marketplace add mizchi/explainer and claude plugin install explainer@explainer.
To update an installed copy: claude plugin marketplace update explainer and then claude plugin update explainer@explainer. Changes are listed in CHANGELOG.md.
The skills can also be installed with npx skills or APM (checked with skills 1.7.0 and apm-cli 0.32.0; both put the skills in .claude/skills/, byte-identical to this repository).
npx skills add mizchi/explainer --skill '*' -a claude-code # --list to see the skills first
apm install mizchi/explainer --target claude
Install explainer, explainer-book and first-reader together: explainer-book runs explainer's verify-doc.mjs from the sibling directory (../../explainer/scripts/).
| Skill | When to use it |
|---|---|
explainer | A crash course for one reader. Claims and figures are checked with tools |
explainer-book | A chaptered course. Checks learning objectives, concept order, reading time and exercises |
first-reader | Has simulated readers read a draft one paragraph at a time before publishing. Reports where they drop off and what stays with them the next day. Does not rewrite |
d2-diagram | A D2 diagram laid out by TALA, read in the terminal, and held to a fact sheet by d2-facts.mjs (what the picture draws, not what the text says) |
d2-slides | A slide deck from one Markdown file with a D2 fence per figure, built to HTML and checked with vlmkit's gates |
The last two came from mizchi/vlmkit. Figures are Mermaid or D2 text checked by figure-check.mjs; the animation package @mizchi/vlmkit-anim and its two skills were removed in 0.5 (see CHANGELOG).
Install the scripts' dependencies in the repository that holds the documents (npm i -D @mizchi/vlmkit marked playwright mermaid, Node 24+). Add the d2 CLI if you use D2 figures, and @iconify-json/lucide @iconify-json/logos to use icons.
first-reader needs only the Python 3 standard library.
For documents in Japanese, also install yomiyasu (MIT): verify-doc.mjs then runs its linter over the prose and lists patterns common in AI-written Japanese (too much bold or bulleting, metaphorical verbs) as things to look at. It is not bundled (npx skills add nanaism/yomiyasu).
first-reader is bundled from Shubhamsaboo/awesome-llm-apps (Apache-2.0; see skills/first-reader/LICENSE and NOTICE).
feed.py counts words differently so that Japanese drafts can also be read one paragraph at a time.
What it does
persona ─→ question ─→ real artifacts (runnable examples, models) ─→ text + figures ─→ verify ─→ HTML
│ │ │ │
questions + public info paste outputs, never retype Mermaid / D2 verify-doc.mjs
+ fact sheets (checks / figures / quotes / vlmkit)
- Persona (
personas/): what the reader already knows, and where their understanding is shaky. It decides what to leave out. - Skills (
skills/explainer/): the procedure, writing style, how to choose a figure, how to verify. - Verification: every quoted output is re-run from
checks.jsonand compared with the text. Figures (Mermaid / D2 / SVG / HTML) are checked against fact sheets and for overlap, clipping and arrow readability byfigure-check.mjs, and pages go throughvlmkit check integrity/check a11y contrast.
ELI5 treats the reader as a type (age, job). This skill treats one real person as the reader, and checks what it writes with tools.
Instructions, and the figures they produced
These are instructions actually given in the conversation that built this repository (excerpts, translated from Japanese; the originals are in README.ja.md), and the figures that came out.
Every figure was either checked against a tool's output or passed figure-check.mjs, and was looked at and fixed by eye.
The images are rebuilt with npm run readme:images. The figures themselves are in Japanese, the language of the documents.
1. A crash course on formal methods
As a test, build a persona of mizchi from public information, and write an explanation of formal methods that I can understand. I tried to write material on Z3 and TLA+, but lost confidence as I wrote it.
Actually run the induction check with Apalache as well, and verify it.

- A: all reachable states of Counter, generated from TLC's state graph as Mermaid by
tlc-to-mermaid.mjs. The thick-bordered states are the ones the correct order and TLC's counterexample walk;D D | 1is the final state where one update was lost. - B: for CounterAtomic, reachable states ⊂ NoLostUpdate ⊂ all states. The contents of the "reachable" box are checked against the states TLC enumerated. Red is the counterexample to induction (CTI) that Z3 found: an unreachable state that satisfies NoLostUpdate and leaves it in one step.
- C: which states each check looked at (hand-written SVG).
- Document:
docs/formal-methods/README.md
2. A chaptered course
I want to add a skill for making a substantial course that doesn't end as a short text. Like foo-book/01-quickstart.md.

- A: chapter dependency map, generated from
book.json; the same data drives the check that no concept is used before it is introduced. - B: triaging a counterexample to induction (CTI), in D2 + ELK.
- Book:
docs/inductive-invariant-book/
3. Which figure tool to use
Using TALA and D2, make a cheat sheet from samples that sorts out which drawing tool to use when.

- The same
arch.d2drawn by A: TALA, B: ELK, C: dagre. - Without a
direction, A put the entry points (browser, app) at the bottom. In B and C, lines cross the container titles (エッジ, サービス, データ). - Cheat sheet:
docs/figure-cheatsheet/README.md
Write down when to use Mermaid. Use Mermaid when it is enough; for other structured patterns consider D2; for free-form drawings D2 can't express, consider SVG or HTML.

- A: a figure Mermaid is enough for (a procedure with a back edge). No ✗ from the checks.
- B: in Mermaid, once a node inside a subgraph links to a node outside it, the subgraph's
direction TBis ignored and everything goes into one row. - C: the same links in D2 + TALA keep the inside vertical.
4. Render, look, and fix the layout
With D2 and Mermaid, when you actually render from the semantics, the result is sometimes clearly unnatural, or the arrows are hard to read. I want a flow that checks these visually and fixes them.

// HOW IT'S BUILT
// FILES
4 files shipped with this skill. Inline text is the catalog copy. The upstream link is the source repository.
skills/d2-slides/SKILL.md16 KB2cb9835fb61fupstream ↗
--- name: d2-slides description: >- Build a slide deck whose source is text and whose figures are laid out by TALA — one Markdown file with a ```d2 fence per figure, compiled to a self-contained HTML deck (keyboard nav, overview grid, print-to-PDF), each figure as its own SVG, and a copy manifest. The deck is a page, so vlmkit's own gates read it: `check integrity` for a slide that breaks or clips, `check copy --manifest` for text the frame cut off, `check a11y contrast` for a projector. Loop: write `deck.md` → build → gates → fix. Use when asked for slides, a deck, a talk, a presentation, a review walkthrough, or a figure-heavy explainer that has to be presented rather than read. Not for one diagram (`d2-diagram`) or a moving figure (`explanatory-animation`). --- # d2-slides Paths below: `<skill>` is this skill's directory and `<skills>` the directory the skills are installed in (`skills/` in mizchi/explainer, `.claude/skills/` in a project that installed them). A deck is text: the prose is Markdown, every figure is a ```d2 fence, and the build is a pure function of the file. Nothing is dragged, so a slide can be reviewed in a diff, regenerated after a rename, and — because the output is an HTML page — **checked**. That last part is the point: a slide deck normally has no failing state, so nobody notices the bullet the frame cut in half. ```bash node <skill>/assets/build-deck.mjs deck.md --out built # ✓ built/index.html: 8 slides, 5 figure(s) laid out by tala, 26 copy lines → built/copy.txt # the deck: built/index.html → vlmkit check integrity # all slides: built/print.html → vlmkit check copy --manifest, check a11y contrast, print to PDF ``` Requires `d2` with TALA (`d2 layout` must list `tala (bundled)` — see `d2-diagram` for installing it) and nothing else: the builder has no dependencies and the deck loads no network resource. ## The deck format ````markdown --- title: Nothing tells you the picture is wrong subtitle: two rounds, measured date: 2026-09-14 --- # Nothing tells you the picture is wrong ← a lone `#` heading is the title slide --- ## A D2 diagram is a drawing ← `##` is a slide heading - `d2 validate` reads **syntax** ← bullets; `code`, **bold**, *italic* work - there is no `--expect` ```d2 ← the figure, laid out by TALA direction: right write -> check -> facts ``` <!-- notes: what to say out loud --> ← speaker notes: printed, never on screen ```` - Slides are separated by a line of exactly `---`; a `---` inside a fence is not a separator. - **Bullets plus a figure** lays them side by side; **a figure alone** gets the whole stage; a heading alone is a title slide. `> line` is a pull quote, and a fence in any other language stays a code block. - Each slide is a fixed **1280×720 frame**, scaled to whatever screen it is shown on. Nothing reflows between a laptop and a projector, which is also why a screenshot of slide 4 is the same picture everywhere. ## The loop ``` 1. write deck.md prose in Markdown, every figure a ```d2 fence 2. node …/build-deck.mjs deck.md --out built fails on the first figure that does not compile, naming the slide; warns when a slide's prose overflows its frame's character budget 3. vlmkit check integrity built/index.html a slide that breaks, clips, collides or paints nothing 4. vlmkit check integrity built/print.html --viewports 1280 every slide at once — this is what catches the bullet the frame cut off 5. vlmkit check copy built/print.html --manifest built/copy.txt --allow-invisible unknown every line of the deck's own text still on a slide (add --forbid stale.txt when you are editing a deck: the claim you removed must really be gone) 6. vlmkit check a11y contrast built/print.html readable from the back of the room 7. node …/d2-facts.mjs --from-svg built/slide-NN.svg --expect slide-NN.facts.json what each figure DRAWS, for every figure that has facts it must not get wrong — steps 3-6 are blind to it 8. node …/deck-review.mjs built --out review shoot each slide, hand the PNGs to a reader node …/deck-review.mjs built --answers a.json score what it read back: fidelity, order, SPLITs 9. read built/index.html in a browser, or the PNG of a slide; fix the Markdown; go to 2 ``` **Step 7 is not optional decoration, and the four page gates do not cover it.** They read the page: a figure that compiles and draws the wrong thing passes all four. The checker takes the slide SVGs the build already writes and needs no `d2` (it reads the render), so this costs one command per figure: ```bash node <skills>/d2-diagram/assets/d2-facts.mjs --from-svg built/slide-04.svg \ --expect slide-04.facts.json # exits 1 and names the box or edge that is wrong ``` The same trick pins **two figures to each other**, which nothing else does: when slides 2 and 3 both claim `ledger` is the writer, hold *both* SVGs to one sheet (`{"boxes": ["checkout","ledger"], "deps": ["checkout->ledger"], "forbidden": ["checkout->orders"]}`). Update one figure and forget the other and that sheet fails on the one you missed. The fact-sheet schema is `d2-diagram`'s; `exhaustive: true` is what makes an extra box an error rather than a shrug. ## Step 8: somebody has to read it Steps 3-7 are the page and the figures' geometry. None of them reads the slide the way a viewer does, and that gap is not theoretical: in the v1/v2 rounds two defects reached a **delivered** deck — a sentence rendered as two blocks, and a fragment sitting above its own bullet — with all four gates green, because every fragment was visible text and nothing overflowed. ```bash node <skill>/assets/deck-review.mjs built --out review # → review/slide-NN.png, one per slide, plus review-brief.md # hand that directory to a vision model or an agent; it answers JSON node <skill>/assets/deck-review.mjs built --answers review/answers.json # read 19/21, invented 6, fidelity 0.70, order 1.00 # ⚠ SPLIT: "…it calls ledger, which is now the only writer to orders." # every word is on the slide, the sentence is not — read back as 2 blocks ``` The scoring is deterministic, against the `slides.json` the build writes: each slide's text **in reading order** (which `copy.txt` is not — the manifest is a set, and it lists bullets before paragraphs while the page renders paragraphs first) plus the words its figures draw. Two numbers and one line to read: - **fidelity** — sheet lines read / (sheet lines + invented). 1.00 is "the slide, nothing more". Measured in v3: 1.00 on a clean deck from both readers, 0.70 on the same deck built by a builder that split its bullets. - **order** — pairs of read lines whose order disagrees with the sheet. It is for a genuinely reordered slide; be aware it did **not** catch v3's split, because the fragments still appeared in the sheet's relative order. Fidelity and the SPLIT line caught that. - **⚠ SPLIT** — a sheet line no single read line covers, whose words are all present across two or more. That is one sentence rendered as two blocks, and the tool names it whether or not the reader had the word for it: one v3 reader called the same defect "clipped at the right edge" — right slides, wrong mechanism — and the diagnosis came out anyway. `--sheet <other-build>/slides.json` scores one render against another build's sheet, which is how a before/after pair is compared against one ground truth. Honest limits. A reader that transcribes none of the figures' labels is not evidence they are illegible, only that it read prose — the `figures: k of n` line is a hint, not a verdict. A reading is a measurement and exits 0; what to do about a 0.7 is the author's call. And a reader will occasionally report a mechanism that is not the real one, so read the slide it names before believing the reason it gives. ## Done condition - The build exits 0 with no overflow warning. - `check integrity` reports **no failures** on `index.html` (all three viewports) and on `print.html` at 1280. A `warn` is not a failure and the command still exits 0 — see the figure-internals note below before you spend a round chasing one. - `check copy --manifest` reports nothing missing (and nothing forbidden, if you are editing an existing deck). - `check a11y contrast` reports no failure, over a count that means **every** slide was read. The count is content-dependent — a terse deck runs about 7 elements a slide, a dense one about 17 — so the number is not the test. Run it against `index.html` too: that shows one slide at a time, so it comes back in single digits. Print view ≫ deck view is the check. - Every figure with facts it must not get wrong passed `d2-facts --expect`. - **Somebody read it back.** You pressed through the deck yourself, or a reader scored it with `deck-review` — fidelity near 1.00 and no `SPLIT`. This is the only step that sees a sentence broken into two blocks. ## The same loop, in CI This repo runs its own worked example through that loop on every change to the skill, the example or the three gates it uses, so the claim above is measured rather than asserted. Two halves, because they need different machines: - **`tests/d2/d2-slides.test.mjs`** (in the ordinary suite, no `d2`, no browser) — the builder's decisions before a figure is drawn: where a slide ends (`---` inside a fence is not a separator), which layout a slide gets, the manifest as the *rendered* text, the overflow warning naming the slide, a figure that does not compile failing the build, and `examples/d2-slides/built/` still matching its `deck.md`. `D2` points at a stub that echoes a fixed SVG — the builder already reads that variable. - **`.github/workflows/d2-slides.yml`** (real `d2` pinned at `v0.9.0`, real Chromium) — the four gate runs above on a fresh build, plus a byte comparison against the committed build, plus two negative controls: a manifest line the deck does not say must be reported `copy-missing`, and a frame shortened to 260px must be reported `clipped-content`. A suite that only ever sees passes cannot tell a working gate from a gate that always passes. Regenerate the committed example with `npm run deck:example` after editing its `deck.md` — the byte comparison is what keeps a committed build from drifting into a lie. ## What the gates found in this skill's own deck Everything below was a real defect in the template or the example, caught by a gate, fixed, and re-measured. It is why the loop above is in that order. - **A phone showed nothing.** `check integrity` at 375px: *"the DOM holds 4 text blocks but almost nothing painted (ink ratio 0.05%)"*. Centring a 1280px stage as an over-sized grid item leaves the middle off-screen; the stage is centred by transform now. - **Every slide clipped 114px.** A percentage height inside a padded fixed box is not the box: the frame is a flex column and the body the flexible child. The gate reported it as `clipped-content` on slides whose text was well inside the frame. - **Long bullets were cut top and bottom.** With `align-items: center` on the split layout, prose taller than the frame overflows both ways and the copy gate reads those lines as copy a user cannot see. Overflow goes downward now, where it is measurable, and the builder warns above ~430 characters of prose beside a figure. - **The manifest did not match the render.** It is generated from the rendered markup, not from the Markdown with its markers stripped: a line containing ```` ```d2 ```` strips to something the page never says. ## What the copy manifest covers `copy.txt` is generated from the **Markdown prose only** — each slide's heading, bullets, pull quotes and paragraphs, as the page renders them (markers gone, entities decoded). Three things are therefore *not* in it: - **A figure's labels.** Text inside a ```d2 fence is drawn as SVG, and the manifest never contains it. So a string the deck must be seen to say belongs in prose; if it only appears in a figure, the copy gate cannot vouch for it — hold the figure to a fact sheet instead (step 7). - **Speaker notes.** `<!-- notes: … -->` is printed and never on screen, and it is not in the manifest either. - **The chrome.** The footer's deck title and page number are not manifest lines. For a reader, the build also writes **`slides.json`**: per slide, its heading, its text in reading order, its figures and the words those figures draw. That is the sheet `deck-review` scores against, and the reason it is a separate file from `copy.txt` is that a manifest cannot express order. A bullet, quote or paragraph wrapped over several lines is **rejoined** into one line, as Markdown does, so wrapping at 80 columns is safe and one sentence is one manifest line. A blank line ends the block: an indented line after one is a paragraph of its own. ## Failure modes - **`✗ slide 6-1: the d2 figure does not compile`** with `reserved keywords are prohibited in edges` → an id collided with a D2 keyword. `width`, `height`, `label`, `style`, `shape`, `icon`, `near`, `top`, `left`, `direction`, `class`, `link`, `constraint`, `layers`, `steps` and `scenarios` are the ones that bite; rename the box (`cols`, `verdict`) and keep the words in its label. - **`copy-invisible (reason: unknown)` on a line that is plainly on the slide** → a vlmkit gate limitation, not your deck: a manifest line whose rendered text is assembled from several inline children can read as invisible. Reproduced minimally in `examples/d2-slides/README.md`; three bullets carrying `<code>` and `<strong>` fail, the same three lines without markup pass. Run with `--allow-invisible unknown` (every accepted line is listed, so the suppression stays auditable) and check the `missing` count, which is the part that matters. - **`check a11y contrast` inspected only four elements** → you pointed it at `index.html`. One slide is on screen at a time; `print.html` is the stacked view. Do not read the absolute count as a threshold: it tracks how many text nodes the deck has, so a terse deck legitimately sits near 7 a slide. The comparison between the two views is the signal. - **`near-misalignment` (a warn) on a base64-looking selector like `g.KGdhdGV3YXkgLSZndDsgY2hlY2tvdXQpWzBd`** → that is *inside* a figure's SVG: the gate has found two of TALA's own edge-label groups sitting 5.5px apart, which is the layout engine's business and not the deck's. It is a `warn`, so the verdict reads `NO DEFECTS, n WARN` and the command exits 0 — that is done, leave it. There is no stable way to exempt it either: `--allow` matches the finding's own selector by substring, and d2 derives that class from the edge's text, so the string changes with the label. If a run has to be silent, `--rule near-misalignment=off` is the only lever, and it gives up the rule for the slide chrome too. Whether it fires at all depends on the layout, not on having labelled edges: the same deck's figures can be CLEAN after an edit. - **`page-overflow-x` on `print.html` at 768 or 375** → expected: the print view is a column of 1280px frames. Check it at `--viewports 1280`. - **A figure is enormous or unreadable** → it is a D2 diagram like any other: take it to `d2-diagram`, where the width levers, the fact check and the terminal render live. A slide figure has about 700×560 to live in. - **CJK labels** render correctly in SVG, so a Japanese deck is fine; the terminal-render caveats in `d2-diagram` do not apply here. ## Deliver - The deck: `built/index.html`, opened in a browser. Arrows and space move, `o` is the overview grid, `p` prints, `f` is fullscreen, and the URL carries `#/4`, so one slide can be linked. - A PDF: open `print.html` and print it, or `index.html` and press `p`. Speaker notes appear in print and never on screen. - In a repo: commit `deck.md` and the figures' `.svg`; the HTML is a build output. `examples/d2-slides/` is the worked example — its deck, its build, and the gate runs above. - One slide as an image: the figure is already `built/slide-NN.svg`.skills/d2-slides/assets/build-deck.mjs24 KBfffeb73e61c7upstream ↗
#!/usr/bin/env node /** * build-deck — a slide deck from one Markdown file, its figures laid out by TALA. * * node build-deck.mjs deck.md --out dist * node build-deck.mjs deck.md --out dist --theme 3 --pad 16 --layout tala * * The deck is text: prose in Markdown, every figure a ```d2 fence rendered by * `d2 --layout=tala`. The output is ONE self-contained HTML file (inline SVG, * inline CSS and script, no network) plus each figure as its own `.svg` and a * `copy.txt` manifest of every word on the slides — which is what makes the * deck checkable: it is a page, so vlmkit's own gates read it. * * Deck format * ----------- * --- * title: What TALA changed * subtitle: three rounds, measured * author: … (optional) * date: 2026-09-14 (optional) * --- * * # What TALA changed ← a slide whose only content is a heading is a title slide * * --- * * ## The loop ← every other `#`/`##` is that slide's heading * * - write the `.d2` ← bullets * - read it in the terminal * * ```d2 ← a figure, rendered with --layout=tala * direction: right * write -> check -> facts * ``` * * <!-- notes: what to say out loud --> ← speaker notes; printed, never on screen * * A slide with both bullets and a figure is laid out side by side; a slide with * only a figure gives it the whole stage. `> quote` becomes a pull quote and a * fenced block in any other language stays code. * * Keys in the deck: → ← space for next / previous, Home / End, `o` for the * overview grid, `p` for the print view (one slide per page), `f` fullscreen. * The URL carries `#/4`, so a slide can be linked. */ import { execFileSync } from "node:child_process"; import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { basename, dirname, join, resolve } from "node:path"; const argv = process.argv.slice(2); const flag = (name, fallback) => { const i = argv.indexOf(`--${name}`); if (i !== -1 && argv[i + 1] && !argv[i + 1].startsWith("--")) return argv[i + 1]; const eq = argv.find((a) => a.startsWith(`--${name}=`)); return eq ? eq.slice(name.length + 3) : fallback; }; const positional = []; for (let i = 0; i < argv.length; i += 1) { const a = argv[i]; if (a.startsWith("--")) { if (!a.includes("=") && argv[i + 1] && !argv[i + 1].startsWith("--")) i += 1; continue; } positional.push(a); } const source = positional[0]; if (!source) { console.error("usage: build-deck.mjs deck.md --out dist [--theme 0] [--pad 20] [--layout tala]"); process.exit(2); } const outDir = resolve(flag("out", "dist")); const layout = flag("layout", "tala"); const theme = flag("theme", "0"); const pad = flag("pad", "20"); const d2 = process.env.D2 || "d2"; /* ---------- read the deck ---------- */ const text = readFileSync(source, "utf8").replace(/\r\n/g, "\n"); let meta = {}; let body = text; const front = text.match(/^---\n([\s\S]*?)\n---\n/); if (front) { for (const line of front[1].split("\n")) { const m = line.match(/^([a-z][a-z0-9-]*):\s*(.*)$/i); if (m) meta[m[1].toLowerCase()] = m[2].trim(); } body = text.slice(front[0].length); } // Slides split on a line that is exactly `---`. A `---` inside a fence is not a separator. const slides = []; let current = []; let inFence = false; for (const line of body.split("\n")) { if (/^```/.test(line)) inFence = !inFence; if (!inFence && /^---\s*$/.test(line)) { slides.push(current); current = []; continue; } current.push(line); } slides.push(current); /* ---------- parse one slide ---------- */ const escape = (s) => s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """); // `code`, **bold**, *italic* — the only inline markup a slide needs. const inline = (s) => escape(s) .replace(/`([^`]+)`/g, "<code>$1</code>") .replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>") .replace(/(^|\s)\*([^*]+)\*/g, "$1<em>$2</em>"); function parseSlide(lines) { const slide = { heading: null, level: 2, bullets: [], numbers: [], figures: [], code: [], quotes: [], notes: [], paras: [] }; /** * Which block a bare line continues, Markdown's lazy continuation. * * A wrapped bullet used to end up as a PARAGRAPH, and paragraphs render * before the list, so `- …D2 creates a new\n shape, so the picture…` put * "shape, so the picture…" above its own bullet and split the sentence * across two manifest lines. Every gate passed — each fragment is visible * somewhere on the slide — and a writer found it by grepping copy.txt for a * string the brief required (writer e, v1). Wrapping a bullet at 80 columns * is ordinary Markdown, so the builder rejoins instead of warning. */ let open = null; for (let i = 0; i < lines.length; i += 1) { const line = lines[i]; if (!line.trim()) { open = null; continue; } const fence = line.match(/^```(\S*)\s*$/); if (fence) { open = null; const lang = fence[1]; const block = []; i += 1; while (i < lines.length && !/^```\s*$/.test(lines[i])) block.push(lines[i++]); if (lang === "d2") slide.figures.push(block.join("\n")); else slide.code.push({ lang, text: block.join("\n") }); continue; } const note = line.match(/^<!--\s*notes?:\s*([\s\S]*?)\s*-->\s*$/); if (note) { slide.notes.push(note[1]); open = null; continue; } const head = line.match(/^(#{1,3})\s+(.*)$/); if (head && !slide.heading) { slide.level = head[1].length; slide.heading = head[2].trim(); open = null; continue; } const bullet = line.match(/^\s*[-*]\s+(.*)$/); if (bullet) { slide.bullets.push(bullet[1].trim()); open = slide.bullets; continue; } // `1. step` is a list, not prose. Before continuation lines were rejoined // each numbered line became its own paragraph, which happened to LOOK like // a list because the text carried the number; once bare lines joined the // block above them, a writer's four-step loop ran together into one // sentence (writer e's deck, v1). So the marker starts a block of its own. const numbered = line.match(/^\s*\d+[.)]\s+(.*)$/); if (numbered) { slide.numbers.push(numbered[1].trim()); open = slide.numbers; continue; } const quote = line.match(/^>\s?(.*)$/); if (quote) { // Consecutive `>` lines are ONE pull quote, as in Markdown: two of them // would be two blockquotes and two manifest lines for one sentence. if (open === slide.quotes) slide.quotes[slide.quotes.length - 1] += ` ${quote[1].trim()}`; else slide.quotes.push(quote[1].trim()); open = slide.quotes; continue; } // A bare line continues the block above it — the wrapped half of a bullet, // a quote or a paragraph — and starts a paragraph only when nothing is open. if (open) { open[open.length - 1] = `${open[open.length - 1]} ${line.trim()}`; continue; } slide.paras.push(line.trim()); open = slide.paras; } return slide; } /* ---------- render the figures ---------- */ function renderFigure(d2Source, salt) { let svg; try { svg = execFileSync( d2, [`--layout=${layout}`, `--theme=${theme}`, `--pad=${pad}`, `--salt=s${salt}`, "-", "-", "--stdout-format", "svg"], { input: d2Source, encoding: "utf8", stdio: ["pipe", "pipe", "pipe"] }, ); } catch (error) { const detail = String(error.stderr || error.message).trim(); console.error(`✗ slide ${salt}: the d2 figure does not compile\n${detail}`); process.exit(1); } return ( svg .replace(/<\?xml[^>]*\?>/, "") // The stage sizes the figure; a fixed width/height would fight it. The viewBox stays, // so the aspect ratio is the layout's. .replace(/(<svg[^>]*?)\swidth="[^"]*"/, "$1") .replace(/(<svg[^>]*?)\sheight="[^"]*"/, "$1") .replace(/<svg /, '<svg class="figure" ') .trim() ); } /* ---------- build ---------- */ mkdirSync(outDir, { recursive: true }); const copy = []; const built = []; slides.forEach((lines, index) => { const slide = parseSlide(lines); if (!slide.heading && !slide.bullets.length && !slide.numbers.length && !slide.figures.length && !slide.paras.length && !slide.quotes.length && !slide.code.length) return; const svgs = slide.figures.map((fig, n) => { const svg = renderFigure(fig, `${index + 1}-${n + 1}`); const name = `slide-${String(built.length + 1).padStart(2, "0")}${slide.figures.length > 1 ? `-${n + 1}` : ""}.svg`; writeFileSync(join(outDir, name), `<?xml version="1.0" encoding="utf-8"?>\n${svg.replace(' class="figure"', "")}\n`); return { svg, name, source: fig }; }); built.push({ ...slide, svgs, index: built.length }); }); // A frame does not grow, so too much prose is cut. There is no browser here to measure with, so // this is a character budget: roughly 38 characters a line in the split layout's column and 13 // lines of room under a heading. The gates measure it properly; this says it before they run. const budget = (s) => (s.svgs.length ? 430 : 900); for (const s of built) { const chars = [...s.bullets, ...s.numbers, ...s.paras, ...s.quotes].join(" ").length; if (chars > budget(s)) console.warn( `⚠ slide ${s.index + 1} (${(s.heading || "untitled").slice(0, 40)}): ${chars} characters of prose` + `${s.svgs.length ? " beside a figure" : ""} — the frame holds about ${budget(s)}; the rest is cut, and` + " the copy gate reports the cut lines as copy a user cannot see", ); } if (!built.length) { console.error("✗ no slides found: a deck is Markdown with slides separated by a line of `---`"); process.exit(1); } const titleOf = (s) => s.heading || meta.title || ""; // The manifest has to be what the DOM will hold, so it is taken from the rendered markup rather // than from the Markdown with its markers stripped: `a ```d2 fence` renders as one thing and // strips to another, and the copy gate reported the difference as a missing line. const rendered = (s) => inline(s) .replace(/<[^>]+>/g, "") .replace(/&/g, "&") .replace(/</g, "<") .replace(/>/g, ">") .replace(/"/g, '"') .replace(/\s+/g, " ") .trim(); for (const s of built) { if (s.heading) copy.push(rendered(s.heading)); for (const b of s.bullets) copy.push(rendered(b)); for (const n of s.numbers) copy.push(rendered(n)); for (const q of s.quotes) copy.push(rendered(q)); for (const p of s.paras) copy.push(rendered(p)); } /** * The words a figure draws, read back out of the SVG the build just made. * * A reader transcribing a slide reads the figure's box labels too — of course * it does, they are words on the slide — and without this the sheet counts * every one as text the reader invented. One v3 reader read all 21 prose lines * and scored 0.55 fidelity for also reading the figures. It is also the only * record of whether a label was legible at slide size. */ const figureTextOf = (svg) => [...svg.matchAll(/<text[^>]*>([^<]+)<\/text>/g)] .map((m) => m[1].replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/\s+/g, " ").trim()) .filter((s) => s.length > 0); const kindOf = (s) => s.figures.length && !s.bullets.length && !s.numbers.length && !s.paras.length && !s.quotes.length ? "figure-only" : s.figures.length ? "split" : s.level === 1 ? "title" : "text"; /** * A slide's text in the order a READER meets it, top to bottom. * * Not the same list as `copy.txt`: the manifest is a set the copy gate looks * each line up in, and it lists bullets before paragraphs while the page * renders paragraphs first. Order is the whole point here — the two defects * that reached a delivered deck in the v1/v2 rounds were a sentence split * across two blocks and a fragment rendered ABOVE its own bullet, both of * which a set cannot express and every page gate passed. */ const readingOrder = (s) => { const lines = []; if (s.heading) lines.push(rendered(s.heading)); if (s.level === 1 && meta.subtitle && s.index === 0) lines.push(rendered(meta.subtitle)); for (const p of s.paras) lines.push(rendered(p)); for (const b of s.bullets) lines.push(rendered(b)); for (const n of s.numbers) lines.push(rendered(n)); for (const q of s.quotes) lines.push(rendered(q)); return lines; }; const slideHtml = (s) => { const kind = kindOf(s); const parts = []; if (s.heading) parts.push(`<h${s.level === 1 ? 1 : 2}>${inline(s.heading)}</h${s.level === 1 ? 1 : 2}>`); if (s.level === 1 && meta.subtitle && s.index === 0) parts.push(`<p class="subtitle">${inline(meta.subtitle)}</p>`); const prose = []; for (const p of s.paras) prose.push(`<p>${inline(p)}</p>`); if (s.bullets.length) prose.push(`<ul>${s.bullets.map((b) => `<li>${inline(b)}</li>`).join("")}</ul>`); if (s.numbers.length) prose.push(`<ol>${s.numbers.map((n) => `<li>${inline(n)}</li>`).join("")}</ol>`); for (const q of s.quotes) prose.push(`<blockquote>${inline(q)}</blockquote>`); for (const c of s.code) prose.push(`<pre><code>${escape(c.text)}</code></pre>`); const figures = s.svgs.map((f) => `<div class="fig">${f.svg}</div>`).join(""); if (kind === "split") parts.push(`<div class="cols"><div class="prose">${prose.join("")}</div><div class="figs">${figures}</div></div>`); else if (kind === "figure-only") parts.push(`<div class="figs full">${figures}</div>`); else parts.push(`<div class="prose">${prose.join("")}</div>`); const notes = s.notes.length ? `<aside class="notes">${s.notes.map((n) => `<p>${inline(n)}</p>`).join("")}</aside>` : ""; return `<section class="slide ${kind}" data-index="${s.index}" aria-label="${escape(titleOf(s))}"> <div class="body">${parts.join("\n ")}</div> <footer><span class="deck-title">${escape(meta.title || "")}</span><span class="page">${s.index + 1} / ${built.length}</span></footer> ${notes} </section>`; }; const html = `<!doctype html> <html lang="${meta.lang || "en"}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>${escape(meta.title || basename(source))}</title> <style> :root { --ink: #14181f; --muted: #5b6472; --line: #d6dbe4; --bg: #ffffff; --stage: #ffffff; --accent: #0d32b2; --code: #f4f6fa; --stage-w: 1280px; --stage-h: 720px; } * { box-sizing: border-box; } html, body { margin: 0; height: 100%; background: #0d1117; color: var(--ink); } body { font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif; overflow: hidden; } #deck { position: fixed; inset: 0; } .slide { width: var(--stage-w); height: var(--stage-h); background: var(--stage); color: var(--ink); display: none; padding: 64px 72px 56px; /* Centred by transform, not by the layout box: a 1280px stage is wider than a phone, and centring an over-sized grid item leaves the middle off-screen. The integrity gate caught that at 375px as "the DOM holds 4 text blocks but almost nothing painted". */ position: absolute; left: 50%; top: 50%; transform-origin: center center; /* A slide is a fixed frame, so content that does not fit is CUT rather than spilling over the next slide — which is what makes overflow detectable: the integrity gate reads it as clipped text, and the copy gate reads the cut line as copy it cannot see. */ overflow: hidden; } .slide.active { display: flex; flex-direction: column; } /* The frame is a flex column and the body is the flexible child: a percentage height inside a padded, fixed box was 114px out on every slide, which the integrity gate reported as clipped content on slides whose text was well inside the frame. */ .slide .body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 20px; } h1 { font-size: 58px; line-height: 1.1; margin: 0; letter-spacing: -0.02em; } h2 { font-size: 38px; line-height: 1.15; margin: 0; letter-spacing: -0.01em; } h2::after { content: ""; display: block; width: 56px; height: 4px; background: var(--accent); margin-top: 16px; } .subtitle { font-size: 26px; color: var(--muted); margin: 0; } .slide.title .body { justify-content: center; } ul, ol { margin: 0; padding-left: 26px; } ol { display: flex; flex-direction: column; } li { font-size: 25px; margin: 0 0 14px; } li code, p code { background: var(--code); padding: 1px 6px; border-radius: 4px; font-size: 0.9em; } p { font-size: 25px; margin: 0 0 10px; } blockquote { margin: 0; padding-left: 20px; border-left: 4px solid var(--accent); font-size: 24px; color: var(--muted); } pre { background: var(--code); padding: 14px 18px; border-radius: 8px; overflow: auto; margin: 0; } pre code { font: 18px/1.45 ui-monospace, "SF Mono", Menlo, monospace; } /* align-items is start, not center: prose taller than the frame then overflows DOWNWARD, where the clip is measurable, instead of being cut off at both ends. Centred, a long bullet list is silently trimmed top and bottom — the copy gate reads those lines as copy a user cannot see. */ .cols { flex: 1; display: grid; grid-template-columns: 1fr 1.1fr; gap: 40px; align-items: start; min-height: 0; height: 100%; } .prose { min-height: 0; } .figs { display: flex; flex-direction: column; gap: 16px; justify-content: center; align-items: center; min-height: 0; height: 100%; } .figs.full { flex: 1; } .fig { display: flex; min-height: 0; width: 100%; height: 100%; justify-content: center; align-items: center; } svg.figure { max-width: 100%; max-height: 100%; height: auto; width: auto; } footer { position: absolute; left: 72px; right: 72px; bottom: 22px; display: flex; justify-content: space-between; font-size: 15px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; } .notes { display: none; } #progress { position: fixed; left: 0; top: 0; height: 3px; background: var(--accent); transition: width .15s; z-index: 5; } #overview { position: fixed; inset: 0; background: #0d1117; overflow: auto; padding: 28px; display: none; z-index: 10; } #overview.on { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; align-content: start; } #overview .thumb { background: #fff; border-radius: 6px; overflow: hidden; cursor: pointer; position: relative; aspect-ratio: 16 / 9; } #overview .thumb .slide { display: block; transform: scale(0.234); transform-origin: top left; position: absolute; } #overview .thumb span { position: absolute; right: 6px; bottom: 4px; font-size: 12px; color: var(--muted); z-index: 2; } /* Every slide at once: what printing gives, and what a page gate has to read. One slide is on screen at a time in the deck, so the copy gate over index.html only ever sees the first one. print.html is the same content stacked, and that is the file the copy and contrast gates take. */ body.print { overflow: visible; background: #eef1f6; } body.print #deck { position: static; } body.print #progress, body.print #overview { display: none !important; } body.print .slide { display: flex !important; flex-direction: column; position: relative; left: auto; top: auto; transform: none !important; margin: 0 auto 24px; box-shadow: 0 1px 4px rgba(20, 24, 31, .18); page-break-after: always; break-after: page; } body.print .notes { display: block; margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 10px; font-size: 15px; color: var(--muted); } @media print { html, body { background: #fff; overflow: visible; } #deck { position: static; display: block; } #progress, #overview { display: none !important; } .slide { display: flex !important; flex-direction: column; position: static; left: auto; top: auto; margin: 0; box-shadow: none; page-break-after: always; break-after: page; transform: none !important; } .notes { display: block; margin-top: 18px; border-top: 1px dashed var(--line); padding-top: 10px; font-size: 14px; color: var(--muted); } } </style> </head> <body> <div id="progress"></div> <div id="deck"> ${built.map(slideHtml).join("\n")} </div> <div id="overview" aria-hidden="true"></div> <script> (() => { const slides = [...document.querySelectorAll("#deck .slide")]; const deck = document.getElementById("deck"); const progress = document.getElementById("progress"); const overview = document.getElementById("overview"); let at = 0; const fit = () => { // One fixed 1280x720 stage scaled to the viewport: nothing reflows between screens, so a // screenshot of slide N is the same picture on any display. const s = Math.min(innerWidth / 1280, innerHeight / 720) * 0.96; for (const el of slides) el.style.transform = "translate(-50%, -50%) scale(" + s + ")"; }; const show = (n) => { at = Math.max(0, Math.min(slides.length - 1, n)); slides.forEach((el, i) => el.classList.toggle("active", i === at)); progress.style.width = ((at + 1) / slides.length) * 100 + "%"; if (location.hash !== "#/" + (at + 1)) history.replaceState(null, "", "#/" + (at + 1)); }; const buildOverview = () => { if (overview.childElementCount) return; slides.forEach((el, i) => { const thumb = document.createElement("div"); thumb.className = "thumb"; const clone = el.cloneNode(true); clone.classList.add("active"); clone.style.transform = "scale(0.234)"; thumb.append(clone, Object.assign(document.createElement("span"), { textContent: i + 1 })); thumb.addEventListener("click", () => { overview.classList.remove("on"); show(i); }); overview.append(thumb); }); }; addEventListener("keydown", (e) => { if (e.key === "ArrowRight" || e.key === " " || e.key === "PageDown") { show(at + 1); e.preventDefault(); } else if (e.key === "ArrowLeft" || e.key === "PageUp") show(at - 1); else if (e.key === "Home") show(0); else if (e.key === "End") show(slides.length - 1); else if (e.key === "o") { buildOverview(); overview.classList.toggle("on"); } else if (e.key === "p") print(); else if (e.key === "f") document.documentElement.requestFullscreen?.(); else if (e.key === "Escape") overview.classList.remove("on"); }); deck.addEventListener("click", (e) => show(at + (e.clientX < innerWidth / 3 ? -1 : 1))); addEventListener("resize", fit); addEventListener("hashchange", () => show((parseInt(location.hash.slice(2), 10) || 1) - 1)); fit(); show((parseInt(location.hash.slice(2), 10) || 1) - 1); })(); </script> </body> </html> `; writeFileSync(join(outDir, "index.html"), html); // The same deck with every slide stacked and the speaker notes visible: the print view, and the // only form in which a page gate can read all of the copy. writeFileSync(join(outDir, "print.html"), html.replace("<body>", '<body class="print">')); writeFileSync(join(outDir, "copy.txt"), `${copy.join("\n")}\n`); // The sheet a reader is scored against: what each slide says, in reading order, // and which figures it carries. `deck-review.mjs` needs exactly this and the // manifest cannot supply it (see `readingOrder`). writeFileSync( join(outDir, "slides.json"), `${JSON.stringify( { title: meta.title || "", slides: built.map((s) => ({ index: s.index, kind: kindOf(s), ...(s.heading ? { heading: rendered(s.heading) } : {}), lines: readingOrder(s), figures: s.svgs.map((f) => f.name), figureText: s.svgs.flatMap((f) => figureTextOf(f.svg)), })), }, null, 2, )}\n`, ); const figures = built.reduce((n, s) => n + s.svgs.length, 0); console.log( `✓ ${join(outDir, "index.html")}: ${built.length} slides, ${figures} figure(s) laid out by ${layout}, ` + `${copy.length} copy lines → ${join(outDir, "copy.txt")}`, ); console.log(` the deck: ${join(outDir, "index.html")} → vlmkit check integrity`); console.log(` all slides: ${join(outDir, "print.html")} → vlmkit check copy --manifest, check a11y contrast, print to PDF`);skills/d2-slides/assets/deck-review.mjs14 KB1374aad0d927upstream ↗
#!/usr/bin/env node /** * deck-review — hand a slide to a reader, then score what they read back. * * node deck-review.mjs built --out review # shoot the slides + write the brief * node deck-review.mjs built --answers answers.json # score a reading * node deck-review.mjs old-build --answers a.json --sheet new-build/slides.json * * Why this exists. Every other check in the `d2-slides` loop reads the page or * the figure's geometry: `check integrity` measures boxes, `check copy` looks * each manifest line up as a SET, `d2-facts` reads the SVG's ids. Two defects * still reached a delivered deck in the v1/v2 validation rounds — a sentence * split across two blocks, and a fragment rendered above its own bullet — and * both were *visible on the slide* while every gate passed, because every gate * was blind to reading order. A reader is the measurement that is not. * * The reader can be a vision model or an agent looking at the PNGs; either way * its answer is JSON and the scoring is deterministic, against the * `slides.json` the build already writes: * * { "slides": [ { "index": 0, "lines": ["read this", "then this"], * "issues": [ { "kind": "split", "what": "…" } ] } ] } * * Issue kinds: `split` (one sentence broken across two blocks), `out-of-order` * (text above what it belongs to), `clipped`, `overlap`, `illegible`, `other`. * * Scoring (the vocabulary of the old `vlmkit-anim review` for a still figure): * read a sheet line the reader read (matched loosely — see `near`) * missed a sheet line no read line covers * invented a read line no sheet line covers * fidelity read / (sheet lines + invented) — 1.0 is "the slide, nothing more" * order Kendall-ish: pairs of read lines whose order disagrees with the sheet * * Playwright is required for the shooting half (`--out`); the scoring half is * dependency-free, so a reading can be re-scored anywhere. */ import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { basename, join, resolve } from "node:path"; const argv = process.argv.slice(2); const flag = (name, fallback) => { const i = argv.indexOf(`--${name}`); if (i !== -1 && argv[i + 1] && !argv[i + 1].startsWith("--")) return argv[i + 1]; const eq = argv.find((a) => a.startsWith(`--${name}=`)); return eq ? eq.slice(name.length + 3) : fallback; }; const positional = []; for (let i = 0; i < argv.length; i += 1) { const a = argv[i]; if (a.startsWith("--")) { if (!a.includes("=") && argv[i + 1] && !argv[i + 1].startsWith("--")) i += 1; continue; } positional.push(a); } const builtDir = positional[0]; if (!builtDir) { console.error( "usage: deck-review.mjs <built-dir> --out <dir> # shoot the slides and write the brief\n" + " deck-review.mjs <built-dir> --answers <json> # score a reading", ); process.exit(2); } const outDir = flag("out"); const answersPath = flag("answers"); const width = Number(flag("width", "1280")); if (!outDir && !answersPath) { console.error("deck-review: pass --out to shoot the slides, or --answers to score a reading"); process.exit(2); } // `--sheet` scores one render against ANOTHER build's sheet. That is the A/B // primitive: the sheet says what the deck should say, so two renders of the // same `deck.md` — before and after a builder change — are comparable against // one ground truth, and a render from a builder too old to write a sheet is // still scorable. const sheetPath = flag("sheet", join(builtDir, "slides.json")); let sheet; try { sheet = JSON.parse(readFileSync(sheetPath, "utf8")); } catch (error) { console.error(`✗ ${sheetPath} is not readable: ${error.message}`); console.error(" It is written by build-deck.mjs — rebuild the deck with a current builder."); process.exit(1); } /* ---------- normalise, and decide when two lines are the same line ---------- */ const norm = (s) => s .toLowerCase() .replace(/[‘’“”]/g, "'") .replace(/[—–]/g, "-") .replace(/[^\p{L}\p{N}\s'-]/gu, " ") .replace(/\s+/g, " ") .trim(); /** * A reader retypes a slide; it does not transcribe it. So a line counts as read * when most of its words are there, in one of the reader's lines — deliberately * generous, because the round is about ORDER and COMPLETENESS, not about * whether a reader kept a comma. The one thing generosity must not hide is a * SPLIT: half a sentence matching at 0.5 has to stay unread, or the defect this * tool exists to find would score as a pass. */ const COVER = 0.7; const coverage = (want, got) => { const w = norm(want).split(" ").filter((x) => x.length > 2); if (!w.length) return norm(want) && norm(got).includes(norm(want)) ? 1 : 0; const g = norm(got); return w.filter((word) => g.includes(word)).length / w.length; }; /* ---------- shoot ---------- */ async function shoot() { const { chromium } = await import("playwright"); mkdirSync(outDir, { recursive: true }); const browser = await chromium.launch(); const page = await browser.newPage({ viewport: { width, height: Math.round((width * 9) / 16) } }); const files = []; const url = `file://${resolve(join(builtDir, "index.html"))}`; for (const s of sheet.slides) { // The deck's own navigation, not a hand-rolled one: `#/N` is what a viewer // links, so a shot taken through it is the slide a viewer sees. await page.goto(`${url}#/${s.index + 1}`, { waitUntil: "load" }); await page.waitForFunction( (i) => document.querySelector(`.slide[data-index="${i}"]`)?.classList.contains("active"), s.index, ); const name = `slide-${String(s.index + 1).padStart(2, "0")}.png`; await page.locator(`.slide[data-index="${s.index}"]`).screenshot({ path: join(outDir, name) }); files.push(name); } await browser.close(); const brief = [ `# Read these slides back`, ``, `${files.length} PNG(s) in this directory, one per slide, in order. Look at each one and`, `write down what it says — you are a reader, not a spell-checker.`, ``, `Answer as JSON, and nothing else:`, ``, "```json", `{ "slides": [ { "index": 0, "lines": ["the first line you read", "the next one"], "issues": [] } ] }`, "```", ``, `- \`index\` is the slide's number minus one, matching the file name.`, `- \`lines\`: every piece of text you can read on the slide, **in the order you`, ` meet it reading top to bottom, left to right**. Order is the point of this`, ` exercise — do not tidy it. Transcribe what is there, including a line that`, ` looks like it is in the wrong place. Skip the footer (deck title, page number).`, `- \`issues\`: anything wrong with the slide AS A SLIDE, each as`, ` \`{ "kind": …, "what": … }\`. Kinds: \`split\` (one sentence broken across two`, ` separate blocks of text), \`out-of-order\` (text sitting above or before what it`, ` belongs to), \`clipped\` (cut off by an edge), \`overlap\` (text on top of text),`, ` \`illegible\` (too small or too crowded to read), \`other\`. Say what and where.`, ` An empty list is a fine answer for a slide that reads cleanly.`, ``, `Do not read the deck's source, its \`copy.txt\`, its \`slides.json\` or any other`, `file in the build: the whole measurement is what the PICTURE says.`, ``, `## Files`, ``, ...files.map((f) => `- ${f}`), ``, ].join("\n"); writeFileSync(join(outDir, "review-brief.md"), brief); console.log(`✓ ${files.length} slide(s) → ${outDir}`); console.log(` brief: ${join(outDir, "review-brief.md")}`); console.log(` score a reading: node deck-review.mjs ${builtDir} --answers <answers.json>`); } /* ---------- score ---------- */ function score() { const answers = JSON.parse(readFileSync(answersPath, "utf8")); if (!Array.isArray(answers.slides)) { console.error('✗ answers need {"slides": [{"index": 0, "lines": [...]}]}'); process.exit(2); } const byIndex = new Map(answers.slides.map((s) => [s.index, s])); const rows = []; let totals = { want: 0, read: 0, invented: 0, swapped: 0, pairs: 0 }; for (const want of sheet.slides) { const got = byIndex.get(want.index); const readLines = (got?.lines ?? []).map((l) => String(l)); const issues = got?.issues ?? []; const hit = new Map(); // sheet line index → first reader line index that covers it const usedBy = new Map(); // reader line index → sheet line index want.lines.forEach((line, wi) => { for (let ri = 0; ri < readLines.length; ri += 1) { if (usedBy.has(ri)) continue; if (coverage(line, readLines[ri]) >= COVER) { hit.set(wi, ri); usedBy.set(ri, wi); return; } } }); const missed = want.lines.filter((_, wi) => !hit.has(wi)); // A reader line that matched no prose line may still be on the slide: the // figure's own box labels are words too, and a reader reads them. They are // counted separately — as the only record of whether a label was legible at // slide size — so that reading the figure cannot look like inventing text. const figureWords = want.figureText ?? []; const leftover = readLines.filter((_, ri) => !usedBy.has(ri)); const figureRead = []; const invented = []; for (const line of leftover) { if (figureWords.some((w) => coverage(w, line) >= COVER || coverage(line, w) >= COVER)) figureRead.push(line); else invented.push(line); } // Order: every pair of sheet lines both read, counted as agreeing or not. const order = [...hit.entries()].sort((a, b) => a[0] - b[0]).map(([, ri]) => ri); let swapped = 0; let pairs = 0; for (let i = 0; i < order.length; i += 1) { for (let j = i + 1; j < order.length; j += 1) { pairs += 1; if (order[i] > order[j]) swapped += 1; } } /** * The diagnosis the reader does not have to make. * * A missed sheet line whose words are all present ACROSS two or more * invented lines is not missing copy — it is one sentence rendered as two * blocks. Both v3 readers of the broken arm saw it; only the larger one * named it, the other called it "clipped at the right edge" (right slide, * wrong mechanism). So the scorer says it: the reader supplies the reading, * this supplies the word for what the reading shows. */ const splits = []; for (const line of missed) { const parts = invented.filter((i) => coverage(i, line) >= 0.5 || coverage(line, i) > 0); if (parts.length < 2) continue; if (coverage(line, parts.join(" ")) >= COVER) splits.push({ line, parts }); } rows.push({ index: want.index, heading: want.heading ?? `slide ${want.index + 1}`, splits, want: want.lines.length, read: hit.size, missed, invented, figureRead: figureRead.length, figureWords: figureWords.length, swapped, pairs, issues, answered: got !== undefined, }); totals = { want: totals.want + want.lines.length, read: totals.read + hit.size, invented: totals.invented + invented.length, figureRead: (totals.figureRead ?? 0) + figureRead.length, figureWords: (totals.figureWords ?? 0) + figureWords.length, swapped: totals.swapped + swapped, pairs: totals.pairs + pairs, }; } const fidelity = totals.want + totals.invented === 0 ? 1 : totals.read / (totals.want + totals.invented); const orderScore = totals.pairs === 0 ? 1 : 1 - totals.swapped / totals.pairs; const unanswered = rows.filter((r) => !r.answered).map((r) => r.index + 1); console.log(`deck: ${sheet.title || basename(builtDir)} — ${sheet.slides.length} slide(s), reading by ${basename(answersPath)}`); console.log(""); for (const r of rows) { const flags = []; if (r.missed.length) flags.push(`${r.missed.length} missed`); if (r.splits.length) flags.push(`${r.splits.length} SPLIT`); if (r.invented.length) flags.push(`${r.invented.length} invented`); if (r.figureRead) flags.push(`${r.figureRead} figure label(s) read`); if (r.swapped) flags.push(`${r.swapped}/${r.pairs} pairs out of order`); if (r.issues.length) flags.push(`${r.issues.length} issue(s) reported`); console.log( `slide ${String(r.index + 1).padStart(2)} ${r.read}/${r.want} read` + (flags.length ? ` — ${flags.join(", ")}` : " — clean") + (r.answered ? "" : " (NOT ANSWERED)"), ); for (const m of r.missed) { const split = r.splits.find((s) => s.line === m); if (split) { console.log(` ⚠ SPLIT: "${m}"`); console.log(` every word is on the slide, the sentence is not — read back as ${split.parts.length} blocks:`); for (const part of split.parts) console.log(` · "${part}"`); } else { console.log(` ✗ missed: "${m}"`); } } for (const i of r.invented) console.log(` ? invented: "${i}"`); for (const i of r.issues) console.log(` ! ${i.kind}: ${i.what}`); } console.log(""); console.log( `read ${totals.read}/${totals.want}, invented ${totals.invented}, ` + `fidelity ${fidelity.toFixed(2)}, order ${orderScore.toFixed(2)} (${totals.swapped}/${totals.pairs} pairs swapped)`, ); if (totals.figureWords) { console.log( `figures: ${totals.figureRead} label(s) read of ${totals.figureWords} drawn` + " — a reader that transcribes none of them is not evidence they are illegible, only that it read prose", ); } if (unanswered.length) console.log(`slides the reader did not answer: ${unanswered.join(", ")}`); const splitCount = rows.reduce((n, r) => n + r.splits.length, 0); if (splitCount) { console.log( `${splitCount} sentence(s) rendered as two or more blocks — the defect no page gate sees,` + " because every fragment is visible text and nothing overflows", ); } const reported = rows.reduce((n, r) => n + r.issues.length, 0); if (reported) console.log(`reader reported ${reported} issue(s) — read them above; none of them is in any gate`); // A reading is a measurement, not a gate: it exits 0 and the numbers are the // output. What to do about a 0.6 fidelity is the deck author's call. process.exit(0); } if (outDir) await shoot(); if (answersPath) score();README.mdupstream ↗
Contents are not inlined in the catalog. Open the upstream file.
Plain-text copy, no login: /skill-bundles/mizchi-explainer-skills-d2-slides.md