Skip to content

An agent skill for creating detailed, interactive isometric illustrations of real-world machines and complex systems. Generates polished SVGs with optional WebGL shaders and 3D effects.

publish.mjs: any theme, and --submit to send the pull request after asking (a fork is made only when needed)

R.5e9ce54fba55
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa19fb9..ffd6fc7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,7 @@ All notable changes to Anatomy are recorded here. The format follows [Keep a Cha
### Added
-- `scripts/publish.mjs` and `references/publish.md`: share a finished framework-free figure in the community gallery, `wheresryan22/anatomy-community`. The script copies the figure, points its kit imports at the gallery's `.skill/` link, records the kit fingerprint (`scripts/fingerprint.mjs`) so the gallery can rebuild it with the same kit version, and copies only the source, under `figures/<author>/<id>/`. The gallery builds the pages in a locked sandbox. It never pushes.
+- `scripts/publish.mjs` and `references/publish.md`: share a finished framework-free figure in the community gallery, `wheresryan22/anatomy-community`. The script copies the figure, points its kit imports at the gallery's `.skill/` link, records the kit fingerprint (`scripts/fingerprint.mjs`) so the gallery can rebuild it with the same kit version, and copies only the source, under `figures/<author>/<id>/`. The gallery builds the pages in a locked sandbox. `--submit` sends it as a pull request after asking, making a fork when needed.
- OpenCode and Codex support, alongside Claude Code. `SKILL.md` exposes `/anatomy` to OpenCode through `metadata`, `agents/openai.yaml` gives Codex its display name, and the README, CONTRIBUTING and the bug report form cover all three agents.
- `examples/arcade-cabinet/`, an upright arcade cabinet with its side panel off. A quarter rolls down the coin chute past the coin-switch wire into the cash box, the switch's pulse runs along its cable to the board, and the CRT warms up, self-tests and runs an attract mode drawn in the plane of the tilted monitor; the stick closes a microswitch under the panel. It draws in the light and dark themes and passes `--audit`.
- `examples/spot-plate/`, a second React figure from the same site as `test-rig`: six pairs of glass drops that run together into one piece of glass as a fan of feeler blades sets `merge`. It draws in the light and dark themes.
diff --git a/README.md b/README.md
index c8993ca..1526ccf 100644
--- a/README.md
+++ b/README.md
@@ -303,7 +303,7 @@ anatomy/
## Share a figure
-Made something good? Ask your agent to publish it to the community gallery, [anatomy-community](https://github.com/wheresryan22/anatomy-community), or run `scripts/publish.mjs` yourself. It prepares the figure in your clone of the gallery and prints the commands to open a pull request; it never pushes for you. The gallery's own [CONTRIBUTING.md](https://github.com/wheresryan22/anatomy-community/blob/main/CONTRIBUTING.md) has the steps.
+Made something good? Ask your agent to *"publish this figure to the Anatomy community gallery"*. It asks for a title and your GitHub name, shows what it will send, and after your yes opens a pull request on [anatomy-community](https://github.com/wheresryan22/anatomy-community) for you: no git, no forking by hand. Or run `scripts/publish.mjs --submit` yourself. Without a terminal, use the gallery's **Submit a figure** form with a GitHub Gist.
## Contributing
diff --git a/references/publish.md b/references/publish.md
index 2ce79aa..594ce8a 100644
--- a/references/publish.md
+++ b/references/publish.md
@@ -1,31 +1,34 @@
# Publishing a figure to the community gallery
-The community gallery is the repository `wheresryan22/anatomy-community`. People share plain HTML figures there: a build script that writes standalone pages next to itself, as the skill's examples do. React and Next.js figures can't be submitted. The gallery shows every figure in the light theme, so a published figure needs its light page (`build.mjs --light`); a dark page is optional.
+The community gallery is the repository `wheresryan22/anatomy-community`. People share plain HTML figures there: a build script that writes standalone pages next to itself, as the skill's examples do, in any theme. React and Next.js figures can't be submitted.
-Publish only when the user asks to share or publish a figure. Never push, fork or open a pull request yourself: prepare everything locally, show it, and give the user the commands to run.
+Publish only when the user asks to share or publish a figure. Never send anything without their explicit yes.
## Steps
-1. **Check the figure is finished.** Its pages are built and up to date, the line check passes, and `--audit` passes if it has pipes, cables or round parts. A figure that fails these will fail the gallery's checks too.
+1. **Check the figure is finished.** Its pages are built and up to date, the line check passes, `--audit` passes if it has pipes, cables or round parts, and with reduced motion on it holds one still pose. The gallery checks all of this too.
2. **Ask the user for what only they can give:**
- - their GitHub username (the author);
- - a title (at most 80 characters);
+ - their GitHub username (the author); `gh api user --jq .login` shows who the GitHub CLI is signed in as;
+ - a title (at most 80 characters) and a short kebab-case id;
- the license: MIT (the default) or CC-BY-4.0;
- confirmation that it is their own work and they are happy to share it.
The prompt is the request that made the figure; reuse it, trimmed to 600 characters.
-3. **Get a local clone of the gallery.** If the user has none, give them the commands to fork and clone it (`gh repo fork wheresryan22/anatomy-community --clone`), and wait.
-4. **Publish into the clone:**
+3. **Get a local clone of the gallery,** if they have none: `gh repo clone wheresryan22/anatomy-community`. Cloning the main repository is fine: the submit step makes a fork for them if they need one.
+4. **Show the plan,** without doing anything:
```sh
node <skill>/scripts/publish.mjs <figure folder> --into <clone> --id <kebab-id> \
--title "..." --author <github user> --prompt "..." \
[--agent "Claude Code"|OpenCode|Codex|Other] [--model "..."] [--license MIT|CC-BY-4.0] \
- [--tags a,b] [--audit] [--pages dark.html,light.html]
+ [--tags a,b] [--audit] [--pages a.html,b.html] --submit --dry-run
```
- Pass `--agent` for the agent you are running in. It copies only the figure's source into `figures/<author>/<id>/src/`, points its kit imports at the clone's `.skill/` link, records the kit fingerprint, checks the build works and removes what it built: the gallery keeps source only, and its CI builds the pages and the poster.
+ Pass `--agent` for the agent you are running in. Read the plan back to the user: it names the fork (if any), the branch, the folder it adds and where the pull request goes.
+5. **Only after the user says yes,** run the same command with `--yes` instead of `--dry-run`. It copies only the figure's source into `figures/<author>/<id>/src/`, points its kit imports at the clone's `.skill/` link, records the kit fingerprint, checks the build, saves a preview to `shots/<author>-<id>/preview.png`, then commits that folder alone, pushes, and opens the pull request. Give the user the link it prints.
- If it says a file reaches outside the figure folder and the skill, copy what that file needs into the figure folder, rebuild, and publish again.
- If it can't tell which pages are the figure, pass `--pages`.
-5. **Validate inside the clone:** `node scripts/validate.mjs figures/<author>/<id>` must end `passed`. Fix what it names. With Docker running (`docker build --platform linux/amd64 -t anatomy-sandbox:local sandbox` once), it runs the build in the same locked, network-less container as the gallery's CI; without Docker it still checks everything except the network isolation.
-6. **Show the user** the poster and screenshots in `shots/<author>-<id>/`, then give them the git and `gh` commands the publish script printed. They run them.
+ - To send an updated version later, run it again with `--force`; it updates the same pull request.
+6. **Without `--submit`** the script stops after preparing the folder and prints the git and `gh` commands instead; use that if the user prefers to send it themselves.
+
+People without a terminal can also submit through the gallery's **Submit a figure** issue form, with a link to a GitHub Gist holding the figure's source.
## What the gallery rejects
@@ -37,4 +40,5 @@ Publish only when the user asks to share or publish a figure. Never push, fork o
- files other than source text under `src/`, or committed built pages;
- builds that write anything but their pages, or that differ between two runs;
- figures that keep moving with reduced motion on.
+
Write figures that way from the start if the user plans to share them.
diff --git a/scripts/publish.mjs b/scripts/publish.mjs
index c21390d..c1f6692 100644
--- a/scripts/publish.mjs
+++ b/scripts/publish.mjs
@@ -20,16 +20,20 @@ function usage(message) {
node scripts/publish.mjs <figure folder> --into <anatomy-community clone> --id <kebab-id> --title "..." --prompt "..." --author <github user>
[--agent "Claude Code"|OpenCode|Codex|Other] [--model "..."] [--license MIT|CC-BY-4.0] [--tags a,b]
- [--build build.mjs] [--pages dark.html,light.html] [--kind "SVG + WebGL"] [--audit] [--no-preview] [--force]
+ [--build build.mjs] [--pages a.html,b.html] [--kind "SVG + WebGL"] [--audit] [--no-preview] [--force]
+ [--submit [--yes] [--dry-run] [--upstream owner/repo]]
-The figure must be plain HTML: a build script that writes standalone pages next to itself, with a light page.
+The figure must be plain HTML: a build script that writes standalone pages next to itself, in any theme.
Only the source is copied, to figures/<author>/<id>/: the gallery's CI builds the pages and the poster.
-Nothing is pushed: the command prints the git and gh commands to run when you are ready.`);
+Without --submit nothing is pushed: the command prints the git and gh commands to run when you are ready.
+With --submit it also sends the figure as a pull request, using the GitHub CLI (gh): it shows the plan and asks
+first (--yes skips the question, --dry-run only shows the plan). People who can push to the gallery get a branch
+there; everyone else gets a fork, made for them.`);
process.exit(message ? 1 : 0);
}
function parse(argv) {
- const options = { agent: "Claude Code", license: "MIT", build: "build.mjs", tags: [] };
+ const options = { agent: "Claude Code", license: "MIT", build: "build.mjs", tags: [], upstream: "wheresryan22/anatomy-community" };
const take = (index) => {
const value = argv[index + 1];
if (value === undefined || value.startsWith("--")) usage(`${argv[index]} needs a value`);
@@ -44,6 +48,10 @@ function parse(argv) {
else if (arg === "--audit") options.audit = true;
else if (arg === "--force") options.force = true;
else if (arg === "--no-preview") options.noPreview = true;
+ else if (arg === "--submit") options.submit = true;
+ else if (arg === "--yes") options.yes = true;
+ else if (arg === "--dry-run") options.dryRun = true;
+ else if (arg === "--upstream") options.upstream = take(index++);
else if (arg.startsWith("--")) usage(`unknown option ${arg}`);
else if (!options.source) options.source = arg;
else usage(`unexpected argument ${arg}`);
@@ -68,18 +76,22 @@ function listFiles(root, dir = root, out = []) {
}
function detectPages(source, files, given) {
+ const html = files.filter((file) => !file.includes("/") && file.endsWith(".html"));
if (given) {
- const [dark, light] = given;
- return { dark: dark || undefined, light: light || undefined };
+ const named = given.filter(Boolean);
+ const pages = {};
+ for (const page of named) pages[themeOf(source, page) === "light" ? "light" : themeOf(source, page) === "dark" ? "dark" : page.replace(/\.html$/, "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 24)] = page;
+ return pages;
}
- const html = files.filter((file) => !file.includes("/") && file.endsWith(".html"));
const pairs = html.filter((file) => !file.endsWith("-light.html") && html.includes(file.replace(/\.html$/, "-light.html")));
- if (pairs.length === 1) return { dark: pairs[0], light: pairs[0].replace(/\.html$/, "-light.html") };
- const singles = html.filter((file) => !/-(light|verify)\.html$/.test(file));
- if (!pairs.length && singles.length === 1) return { dark: singles[0] };
- throw new Error(`can't tell which pages are the figure (found: ${html.join(", ") || "none"}); pass --pages dark.html,light.html`);
+ if (pairs.length === 1) return { light: pairs[0].replace(/\.html$/, "-light.html"), dark: pairs[0] };
+ const singles = html.filter((file) => !/-verify(?:-light)?\.html$/.test(file) && !/^turning-stress/.test(file));
+ if (!pairs.length && singles.length === 1) return { [themeOf(source, singles[0]) === "light" ? "light" : "page"]: singles[0] };
+ throw new Error(`can't tell which pages are the figure (found: ${html.join(", ") || "none"}); pass --pages a.html,b.html`);
}
+const themeOf = (source, page) => (readFileSync(join(source, page), "utf8").match(/<body[^>]*\bdata-theme="([a-z-]+)"/) ?? [])[1] ?? "";
+
function detectKind(text) {
const webgl = /getContext\(\s*["']webgl2?["']|\bGLSL_ISO\b|\bglLayer\b/.test(text);
const turning = /\bTURN\.mount\b|\bturnScript\b|\bTURN_CSS\b|class="[^"]*iso-turn/.test(text);
@@ -127,11 +139,8 @@ export function publish(options) {
const all = listFiles(source);
const typed = all.filter((file) => SOURCE_TYPES.includes(extname(file).toLowerCase()));
const pages = detectPages(source, typed, options.pages);
+ const lightPage = pages.light ?? null;
for (const page of Object.values(pages)) if (page && !typed.includes(page)) throw new Error(`page ${page} not found in ${source}; build the figure first`);
- const themeOf = (page) => (readFileSync(join(source, page), "utf8").match(/<body[^>]*\bdata-theme="(light|dark)"/) ?? [])[1] ?? "dark";
- if (pages.dark && !pages.light && themeOf(pages.dark) === "light") [pages.light, pages.dark] = [pages.dark, undefined];
- if (!pages.light) throw new Error("the gallery shows figures in the light theme: build the light page too (node build.mjs --light), then publish again");
- for (const [key, page] of Object.entries(pages)) if (page && themeOf(page) !== key) throw new Error(`${page} is a ${themeOf(page)} page, not ${key}; pass --pages dark.html,light.html in that order`);
const outputs = new Set(Object.values(pages).filter(Boolean));
const files = typed.filter((file) => !outputs.has(file) && !/-verify(?:-light)?\.html$/.test(file));
const skipped = all.filter((file) => !files.includes(file) && !outputs.has(file));
@@ -163,19 +172,20 @@ export function publish(options) {
throw new Error(`${repo}/.skill (${where}) is a different kit version than this skill; remove it and run again`);
}
- const build = [[`src/${options.build}`, "--light"]];
- if (pages.dark) build.push([`src/${options.build}`]);
+ const build = [];
+ if (pages.light) build.push([`src/${options.build}`, "--light"]);
+ if (Object.keys(pages).some((name) => name !== "light")) build.push([`src/${options.build}`]);
for (const command of build) {
- log(`building the ${command.includes("--light") ? "light" : "dark"} page (heavy figures take a minute or two)…`);
+ log(`building ${command.includes("--light") ? "the light page" : "the page"} (heavy figures take a minute or two)…`);
run(command, dest);
}
let preview = null;
if (!options.noPreview) {
- log("taking a preview of the light page…");
+ log("taking a preview…");
const shots = join(repo, "shots", `${author.toLowerCase()}-${options.id}`);
mkdirSync(shots, { recursive: true });
preview = join(shots, "preview.png");
- run([join(SKILL, "scripts", "capture.mjs"), join(dest, "src", pages.light), "--reduced", "--width", "1200", "--out", preview], dest);
+ run([join(SKILL, "scripts", "capture.mjs"), join(dest, "src", lightPage ?? Object.values(pages)[0]), "--reduced", "--width", "1200", "--out", preview], dest);
}
const pageText = Object.values(pages).filter(Boolean).map((page) => readFileSync(join(dest, "src", page), "utf8")).join("\n");
for (const page of outputs) rmSync(join(dest, "src", page), { force: true });
@@ -190,6 +200,7 @@ export function publish(options) {
skill: { kit },
build,
pages: Object.fromEntries(Object.entries(pages).filter(([, page]) => page).map(([key, page]) => [key, `src/${page}`])),
+ preview: lightPage ? "light" : Object.keys(pages)[0],
...(options.audit ? { audit: true } : {}),
license: options.license,
...(options.tags.length ? { tags: options.tags } : {}),
@@ -200,9 +211,76 @@ export function publish(options) {
return { dest, figure, skipped, linked, preview };
}
+export function submitPlan({ login, canPush, upstream, author, id, title }) {
+ const name = upstream.split("/")[1];
+ const target = canPush ? upstream : `${login}/${name}`;
+ const folder = `figures/${author.toLowerCase()}/${id}`;
+ const branch = `figure/${id}`;
+ const steps = [
+ ...(canPush ? [] : [{ say: `make (or reuse) your fork, ${target}`, gh: ["repo", "fork", upstream, "--clone=false", "--remote=false"] }]),
+ { say: "let git use your GitHub CLI login", gh: ["auth", "setup-git"] },
+ { say: `start ${branch} from the gallery's latest main`, git: ["fetch", "--quiet", `https://github.com/${upstream}.git`, "main"] },
+ { git: ["switch", "--quiet", "-C", branch, "FETCH_HEAD"] },
+ { say: `add ${folder} and nothing else`, publish: true },
+ { git: ["add", "--", folder] },
+ { git: ["commit", "--quiet", "-m", `Add ${title}`, "--", folder] },
+ { say: `push it to ${target}`, git: ["push", "--quiet", "--force", `https://github.com/${target}.git`, `HEAD:refs/heads/${branch}`] },
+ { say: `open the pull request on ${upstream}`, pr: { repo: upstream, head: canPush ? branch : `${login}:${branch}`, title: `Add ${title}` } },
+ ];
+ return { target, branch, folder, steps };
+}
+
+async function confirm(question) {
+ if (!process.stdin.isTTY) return false;
+ const { createInterface } = await import("node:readline/promises");
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
+ const answer = await rl.question(question);
+ rl.close();
+ return /^y(es)?$/i.test(answer.trim());
+}
+
+async function submit(options) {
+ const gh = (args) => spawnSync("gh", args, { encoding: "utf8" });
+ const repo = resolve(options.into);
+ const who = gh(["api", "user", "--jq", ".login"]);
+ if (who.error || who.status !== 0) throw new Error("--submit needs the GitHub CLI, signed in: install it from https://cli.github.com and run gh auth login");
+ const login = who.stdout.trim();
+ const author = options.author.replace(/^@/, "");
+ if (login.toLowerCase() !== author.toLowerCase()) throw new Error(`you're signed in to GitHub as ${login}, but --author is ${author}; they must match`);
+ const perm = gh(["api", `repos/${options.upstream}`, "--jq", ".permissions.push"]);
+ if (perm.status !== 0) throw new Error(`can't see ${options.upstream} with your GitHub login`);
+ const plan = submitPlan({ login, canPush: perm.stdout.trim() === "true", upstream: options.upstream, author, id: options.id, title: options.title.trim() });
+ console.log(`\nSubmitting as @${login}:`);
+ for (const step of plan.steps) if (step.say) console.log(` · ${step.say}`);
+ console.log(` (in ${repo})`);
+ if (options.dryRun) return console.log("\ndry run: nothing was done");
+ if (!options.yes && !(await confirm("\nGo ahead? [y/N] "))) throw new Error("not submitted (answer y, or pass --yes after asking)");
+ const run = (tool, args) => {
+ const result = spawnSync(tool, args, { cwd: repo, encoding: "utf8" });
+ if (result.status !== 0) throw new Error(`${tool} ${args.slice(0, 2).join(" ")} failed:\n${`${result.stdout}${result.stderr}`.trim()}`);
+ return result.stdout.trim();
+ };
+ let published;
+ for (const step of plan.steps) {
+ if (step.gh) run("gh", step.gh);
+ if (step.git) run("git", step.git);
+ if (step.publish) published = publish({ ...options, log: (line) => console.log(` ${line}`) });
+ if (step.pr) {
+ const open = gh(["pr", "list", "--repo", step.pr.repo, "--head", plan.branch, "--state", "open", "--json", "url", "--jq", ".[0].url"]).stdout.trim();
+ const url = open || run("gh", ["pr", "create", "--repo", step.pr.repo, "--base", "main", "--head", step.pr.head, "--title", step.pr.title, "--body", `${published.figure.prompt}\n\nPublished with Anatomy's publish.mjs.`]);
+ console.log(`\nSubmitted: ${url}\nThe checks run there, and a preview of your figure appears on it when they finish.`);
+ }
+ }
+}
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
const options = parse(process.argv.slice(2));
- try {
+ if (options.submit) {
+ submit(options).catch((error) => {
+ console.error(`publish: ${error.message}`);
+ process.exit(1);
+ });
+ } else try {
console.log(`publishing ${options.id}…`);
const { dest, figure, skipped, linked, preview } = publish({ ...options, log: (line) => console.log(` ${line}`) });
const repo = resolve(options.into);
diff --git a/scripts/publish.test.mjs b/scripts/publish.test.mjs
index a4c070e..e2c1536 100644
--- a/scripts/publish.test.mjs
+++ b/scripts/publish.test.mjs
@@ -64,3 +64,17 @@ test("publishing refuses a folder that is not a gallery clone", () => {
rmSync(empty, { recursive: true, force: true });
}
});
+
+import { submitPlan } from "./publish.mjs";
+
+test("--submit: people who can push get a branch; everyone else a fork made for them", () => {
+ const owner = submitPlan({ login: "wheresryan22", canPush: true, upstream: "wheresryan22/anatomy-community", author: "wheresryan22", id: "token-bucket", title: "Token bucket" });
+ assert.equal(owner.target, "wheresryan22/anatomy-community");
+ assert.ok(!owner.steps.some((s) => s.gh?.[1] === "fork"));
+ assert.deepEqual(owner.steps.at(-1).pr, { repo: "wheresryan22/anatomy-community", head: "figure/token-bucket", title: "Add Token bucket" });
+ const guest = submitPlan({ login: "Octo-Cat", canPush: false, upstream: "wheresryan22/anatomy-community", author: "Octo-Cat", id: "token-bucket", title: "Token bucket" });
+ assert.equal(guest.target, "Octo-Cat/anatomy-community");
+ assert.deepEqual(guest.steps[0].gh, ["repo", "fork", "wheresryan22/anatomy-community", "--clone=false", "--remote=false"]);
+ assert.equal(guest.steps.at(-1).pr.head, "Octo-Cat:figure/token-bucket");
+ assert.ok(guest.steps.some((s) => s.git?.[0] === "add" && s.git.at(-1) === "figures/octo-cat/token-bucket"), "only the figure's folder is added");
+});