From 53bdb0c8b5550cf048c9bb3f8259458291311141 Mon Sep 17 00:00:00 2001
From: Malav Shah
Date: Tue, 6 Oct 2026 10:58:35 -0700
Subject: [PATCH 1/5] shortened explanation pages and sized the quiz to the
change
Part of #4.
---
README.md | 8 +-
skills/explain-diff-html/SKILL.md | 175 ++++++++++---
skills/explain-diff-html/html-template.html | 67 ++++-
.../explain-diff-html/references/diagrams.md | 3 +
.../references/quiz-design.md | 28 ++-
.../references/validation.md | 49 +++-
.../scripts/validate-output.sh | 230 +++++++++++++++++-
7 files changed, 502 insertions(+), 58 deletions(-)
diff --git a/README.md b/README.md
index b0e5250..3ae0c07 100644
--- a/README.md
+++ b/README.md
@@ -115,9 +115,11 @@ the code around it, and writes a single page with four sections:
- Intuition, on the core idea, with toy data and diagrams rather than full
detail.
- Code walkthrough, ordered by the path a request or an action takes through the
- system, not by filename.
-- Quiz, five interactive multiple-choice questions that test whether the reader
- understood why the change is shaped the way it is.
+ system, not by filename. The edits that carry the change get a step each.
+ Every other changed file gets one line in an "Also changed" table at the end.
+- Quiz, three or five interactive multiple-choice questions that test whether
+ the reader understood why the change is shaped the way it is. A small change
+ gets three, or fewer when it carries fewer testable decisions.
The output is one HTML file with the CSS and JavaScript inline. It opens with a
double click, reads on a phone, and follows the reader's light or dark system
diff --git a/skills/explain-diff-html/SKILL.md b/skills/explain-diff-html/SKILL.md
index fbd1a1a..04b5fc8 100644
--- a/skills/explain-diff-html/SKILL.md
+++ b/skills/explain-diff-html/SKILL.md
@@ -115,6 +115,11 @@ therefore no Node. The hand-built families cover it.
- One long page with section headers and a table of contents. Do not use tabs
for the top-level structure.
- Responsive enough to read on a phone.
+- A lead under the title, in the `p.lead` paragraph: the change's purpose in one
+ sentence, derived from what the diff does. The pull request body may shape
+ that sentence, but the diff, not the body, decides which files the page treats
+ as core. When no record supports the purpose, mark the sentence as your
+ inference.
- A provenance line under the lead, in the `.provenance` paragraph that
`html-template.html`, the scaffold every page starts from, already carries: the source, the exact ref, and the date the page was written, as in
`owner/repo PR 1234 at abc1234, explained 2026-09-01`. Use the short form of
@@ -233,7 +238,15 @@ blank page, not an error. Evidence: uPortal PR 2983 gives 0 files that way and
because it was squashed.
`gh pr diff ` returns the same diff and needs no fetch, so use it when `gh`
-is available and keep the git form for when it is not.
+is available and keep the git form for when it is not. Create `` first
+either way, and save the diff to the same file, so every target leaves a
+`/diff.txt` for the later steps:
+
+```bash
+work="$(mktemp -d)"
+echo "$work" # write this path out in later steps
+gh pr diff > "$work/diff.txt"
+```
Fetching a bare sha is not always allowed. The server decides whether to serve
an object that no ref advertises. GitHub.com serves one that is reachable, and a
@@ -346,10 +359,25 @@ is still running.
Write in the order below. Aim for concrete, engaging, classic prose, with
smooth transitions so the page reads as one piece rather than four.
-Three rules bind all four sections. They are authoring rules, not review
+Before you write any section, do three things in this order:
+
+1. Write the `p.lead` sentence, as the output contract describes.
+2. Sort every path in the diff into core, brief, or table, as the Code section
+ below defines them. Save the list to `/triage.txt`, one path and its
+ group per line. The walkthrough and the "Also changed" table follow that
+ list.
+3. List the names the Code and Quiz sections will use. The naming rule below
+ checks them.
+
+Four rules bind all four sections. They are authoring rules, not review
notes: the humanize pass in step 6 catches violations, but by then the
prose is already built around them.
+Match the length to what the change needs. A one-file fix gets a short page. Add
+no filler, no summary that restates a section, and no boilerplate. Cut
+repetition, never explanation: a passage that is long because the mechanism is
+hard stays long.
+
Mark every inference as yours. Explaining why code is shaped a certain way is
most of the value of a page like this, and the record almost never states the
reason. So when you have worked out a reason the record does not give, write it
@@ -376,23 +404,89 @@ one argument makes a warning point at the caller, without saying the argument is
them the number and they verify it themselves; withhold it and they take the
whole section on faith.
+When you shorten any passage, keep every name, number, condition, and edge case
+exactly as it is. Shorten a caveat when you must, but never delete it.
+
Background: explain the existing system relevant to this change. Include a deep
-background for a beginner, marked so a familiar reader can skip it, then a
-narrow background covering exactly the code the change touches.
+background for a beginner, marked so a familiar reader can skip it. Then give a
+narrow background on the code the change touches. Scope both to what the core
+paths in the triage list need. The narrow background gives the change's reason,
+its names and data shapes, and the entry point the Code flow map starts from.
+It describes the code before the change at that level. What each changed line
+does belongs to the Code section. The narrow background walks an unchanged
+helper only when a core edit changes how the code calls it. Any other name the
+walkthrough uses gets a one-line definition in Background or Intuition. The deep
+background covers only the concepts the narrow background, Intuition, and the
+walkthrough use. Background, counting the collapsed part, runs no longer than
+the Code walkthrough. The `words:` line of the step 7 script counts both. When
+Background must run longer, the step 8 report says by how much and why. Report
+the excess, and never cut explanation to meet the limit.
Intuition: explain the core idea of the change. Focus on the essence, not the
-full detail. Use concrete examples with toy data. Use figures and diagrams
-liberally.
-
-Code: a high-level walkthrough of the changes, ordered by logical flow, never
-by filename, directory, or the order hunks appear in the diff. Open with a
-one-line flow map that names the path end to end, so the reader sees the whole
-path before the steps. Then follow that path: start where the change is entered
-(a request, a user action, an event, a command, a scheduled job, a schema
-migration that runs first), move through each layer it flows into, and end
-where the effect lands. Group the edits under that flow so each step builds on
-the one before it. When a single logical change touches several files, present
-them together as one step rather than scattering them alphabetically.
+full detail. Use concrete examples with toy data.
+
+Code: a walkthrough of the changes, ordered by logical flow, never by filename,
+directory, or the order hunks appear in the diff. Open with a one-line flow map
+that names the path end to end, so the reader sees the whole path before the
+steps. Then follow that path: start where the change is entered (a request, a
+user action, an event, a command, a scheduled job, a schema migration that runs
+first), move through each layer it flows into, and end where the effect lands.
+
+The triage list from the start of this step decides how much each path gets:
+
+- Core: the edits that carry the change's purpose. Walk each one in depth, in
+ flow order, under its own `h3.core-step` heading. When one logical change
+ touches several files, present them together as one step rather than
+ scattering them alphabetically.
+- Brief: an edit the reader needs that carries none of the purpose. Give it a
+ sentence or two inside the core step it belongs to.
+- Table: every other path. The "Also changed" table lists it.
+
+An edit that changes behavior never goes to the table. It may be walked briefly,
+but the reader has to meet it in the walkthrough.
+
+Say each thing once. When Intuition has already shown a mechanism, the
+walkthrough points back to it rather than explaining it again.
+
+End the walkthrough with the "Also changed" table, a `table.vals` with the extra
+class `also-changed`. Caption it `Every other changed file (N of M)`. N counts
+the files the table covers. M counts the files in the diff, from the
+`diff --git` headers in `/diff.txt`. The step 7 script checks both
+numbers.
+
+- Give each file a row with its path and a one-sentence reason it changed.
+- Leave the table out when no path is left for it.
+- One row may cover a directory of generated or binary asset files, such as
+ converted images. The row gives the file count.
+- Name a deleted file by its path, with no link, because it does not exist at
+ the target ref.
+
+A large change is walked by theme. Count the changed lines, additions plus
+deletions:
+
+```bash
+git apply --numstat < "/diff.txt" | {
+ total=0
+ while read -r added removed path; do
+ [ "$added" = - ] || total=$((total + added + removed))
+ done
+ echo "$total"
+}
+```
+
+The command counts every file, and counts a binary file's row as 0. When the
+diff carries a generated directory, subtract that directory's rows, which
+`git apply --numstat` lists by path.
+
+The loop uses named variables on purpose. When Claude Code loads this file, it
+replaces a dollar sign followed by a digit with a word from the user's request.
+So this file never writes one.
+
+Above 2,000, walk themes instead of single edits. Each theme is an
+`h3.core-step` that lists the paths it covers. The core edits inside a theme
+are `h4` headings, and each one still gets the in-depth walk. Say in the flow
+map, or in the first theme heading, that the walkthrough is summarized at theme
+level. A separate sentence that says so reads as signposting.
Name each file with a `path/to/file.ext:line` reference so a reader can find
it, but let the flow, not the path, set the order.
@@ -496,8 +590,8 @@ opens an unknown element that HTML5 never auto-closes, so it swallows the rest
of the document and breaks the sections and table-of-contents anchors below it.
Escaping also closes a self-XSS path when a diff carries `#$m#g" -e "s#
+
What does the function return?
+
When does the cache refill?
+
Which call reads it?
+
The cache returns a default value when it is empty.