Scientific Schematics (raster figures through the Codex CLI)
Overview
This skill produces raster figures with an image model. Generation runs through
the Codex CLI installed on this machine: scripts/imagegen.py starts one
non-interactive codex exec turn per image, Codex calls its built-in
image_gen tool (gpt-image-2 on the ChatGPT subscription), copies the PNG to
--out, and the script writes a provenance sidecar (<stem>.imagegen.json:
the Codex thread id, the prompt Codex actually sent to the image model, actual
size, wall time). edit resumes the thread recorded in the sidecar, so the
model still sees the original image and changes only what the instruction
names. No gateway, no API key, no token.
Backend facts, measured 2026-09-09 with codex-cli 0.153.4 on a four-module
pipeline diagram:
- About 35 seconds per
generate and about 45 seconds per edit; two
parallel attempts finished together in 36 seconds. Run every call with
run_in_background: true.
- The image tool takes no size or quality parameter; the canvas follows the
prompt text. "Landscape 3:2" came back 1536x1024; a left-to-right pipeline
with no stated shape came back as a 3:1 strip. State the aspect ratio in
FRAMING.
- Billing is ChatGPT subscription quota, not per-image money.
- Label fidelity is high: labels spelled exactly on the first attempt. Keep
the SPELL EXACTLY line anyway; it costs nothing.
edit in the same thread (rename one label) changed only that label; every
other pixel stayed.
Requirements: codex on PATH and logged in. codex login is interactive, so
the user runs it in a terminal, never this skill. The image_generation
feature is on by default; codex features list | grep image_generation
confirms it.
Two roles: decide which one applies before invoking
Role 1, design exploration (on demand). When the design direction of a
figure is unclear, a novel figure type with no obvious layout, several plausible
ways to organize the information, or the user asks to "explore directions",
generate three direction drafts in parallel (different layouts or information
organization, not color variants), show all three, and let the user pick. The
user then also chooses the delivery form: use the PNG directly (manuscript, or
material for a slides rework), iterate it to final quality with edit, or hand
it to superpower-writing:tikz-figures as a replication reference (ref.png)
for a vector rendition. See Exploration mode below.
Role 2, final raster output. When the deliverable is a PNG:
- Illustrative concept art with lighting, texture, 3D rendering, or hand-drawn style.
- Photorealistic or semi-realistic scene compositions.
- Graphical abstracts with strong pictorial elements.
- Any figure where the user prefers a polished PNG over vector source.
Routing for everything else. Routine structural diagrams with a clear design
(architecture diagrams, flowcharts, pipelines, sequence diagrams) default to
superpower-writing:tikz-figures; its two-candidate preview covers the layout
choice, and vector source keeps formulas and fonts consistent with the body
text. That is a default, not a rule: a high-quality PNG is a legitimate
deliverable whenever the user prefers it. Data plots (CDFs, training curves,
ablation bars, speedups, Pareto fronts) go to
superpower-writing:scientific-visualization.
Run it
IMG="${CLAUDE_PLUGIN_ROOT}/skills/scientific-schematics/scripts/imagegen.py"
# one figure
python3 "$IMG" generate --prompt-file .writing/figures/prompts/<slug>.txt \
--out .writing/figures/<slug>.png
# three attempts of the same prompt in parallel, saved as <slug>-1.png .. <slug>-3.png
python3 "$IMG" generate --prompt-file .writing/figures/prompts/<slug>.txt \
--out .writing/figures/<slug>.png --count 3
# one targeted fix on a chosen PNG
python3 "$IMG" edit --image .writing/figures/<slug>-2.png \
--prompt 'Rename the label "Top-k Docs" to "Top-k Passages".' \
--out .writing/figures/<slug>.png
Mandatory: run_in_background: true on every call. A foreground call freezes
the session for a minute or more. Do not poll; the harness notifies on
completion. Then Read the PNG to inspect it; the Read tool renders images.
The script runs codex exec from the current directory with the
workspace-write sandbox plus write access to the output directory, retries
once when Codex exits non-zero or leaves no PNG behind, and prints one
OK <path> <WxH> <seconds> thread=<id> line per image. edit resumes the
thread named in the input image's sidecar; --thread overrides it, and an
image without a sidecar is attached to a fresh thread instead. The edit
instruction names only the change; the script adds the "keep everything else"
clause.
Workflow
- Decide whether the paper needs this figure and which kind. Read
tikz-figures/references/figure-rhetoric.md for Figure-1 and
solution-overview candidates; it is venue-agnostic across the figure skills.
- Write the brief: every component with its exact label, the flow direction,
the one hero module that carries the novelty, and the canvas shape.
- Write the prompt file
.writing/figures/prompts/<slug>.txt following
references/prompt-contract.md. For a modern-ML pastel look also read
references/style-pastel-ml.md.
- Generate three attempts (
--count 3) in the background. Read all three and
pick the best against the checklist below. Quality varies between runs;
never accept the first without seeing the others.
- Fix defects with
edit, one targeted change per call, at most three rounds.
- Move the final to
.writing/figures/<slug>.png, keep the prompt file and the
sidecar under version control, reference with \includegraphics, and write
the caption.
Exploration mode (Role 1)
- Write one shared figure brief (components, labels, flow), then derive three
prompts that differ in layout or information organization, for example
horizontal pipeline, layered stack, and central hero with panels. Style or
color variants do not count as directions.
- Save them as
.writing/figures/explore/<slug>-{a,b,c}.txt and dispatch three
background generate calls in one message, each with its own --out
under .writing/figures/explore/.
- When all return, Read the three PNGs, show them to the user, and ask which
direction to develop (AskUserQuestion, one option per draft with a one-line
layout summary).
- Ask how to develop the chosen draft: use the PNG directly, iterate it with
edit to final quality, or hand it to superpower-writing:tikz-figures as
the replication reference. The last satisfies tikz-figures' two-candidate
requirement through its 复刻 exemption; figure-diff.py SSIM verifies the
TikZ rendition against the chosen draft.
- Keep all drafts under
.writing/figures/explore/ until the figure ships;
runner-up directions often get revisited.
Graphical abstracts are optional. Systems papers usually omit them; generate one
only when the venue asks.
Failure and recovery
- Script exits non-zero. Read its message.
codex CLI not found or an
authentication error in Codex's stderr needs the user to run codex login
in a terminal; stop and say so. "codex finished but does not exist"
quotes Codex's last reply, which usually explains why nothing was saved (the
image tool refused the prompt, or Codex asked a question instead of acting);
fix the prompt and rerun. A timeout (600 s by default) that survived the
built-in retry means the turn hung; stop and report the error text. Never
invent a saved path or claim an image exists.
- Labels will not converge. Allow at most three
edit rounds on one image.
If a label is still wrong after the third, hand the draft to
superpower-writing:tikz-figures for a vector rendition, where text is exact,
or deliver the PNG with a caption note. Endless re-prompting is the failure
mode to avoid.
- All three exploration drafts rejected. Do not silently regenerate the same
three. Ask what was wrong (layout family, emphasis, missing component), derive
a new brief, and dispatch one fresh round. After two rejected rounds, talk
through the intended structure before spending more quota.
Prompt essentials
The full contract lives in references/prompt-contract.md. The rules that
decide most outcomes:
- Labels name modules; they never explain them. No sentences, no
paragraphs, no formulas inside the image. Explanation belongs in the caption.
- Name the core novelty. One hero module gets the one visual distinction (a
thicker border, the single accent color); everything else stays quiet.
- Spell every label in a list and add the literal line "SPELL ALL LABELS
EXACTLY AS WRITTEN, do not rephrase or abbreviate".
- State the canvas shape in FRAMING (wide 3:1 strip, 3:2 landscape,
square). The image tool has no size parameter; the prompt decides.
- Icons only where they aid recognition: a small monochrome icon inside a
module (document stack, database cylinder, shield, network graph), never
decoration.
- Flat vector on white: pastel fills with slightly darker borders, thin
dark-grey arrows, no shadows, no 3D, no photos, no figure number, caption, or
title baked into the image.
LaTeX integration
- Include with
\includegraphics{figures/<slug>.png}.
- Write a thorough caption defining every component and abbreviation; the
image carries names only.
- Reference the figure in the narrative with
Figure~\ref{fig:...} (use the
~ tie).
- Keep styling consistent across all figures in the paper: same prompt VISUAL
STYLE and COLOR PALETTE blocks for every figure.
- Version-control the prompt file and the sidecar next to the PNG so the figure
can be regenerated.
Quick reference checklist
Before accepting an attempt:
Before shipping:
Integration with other skills
- Figure rhetoric (design judgment). Whether the paper needs the figure and
which kind:
tikz-figures/references/figure-rhetoric.md.
superpower-writing:tikz-figures: vector diagrams compiled with LaTeX; the
default route for routine paper figures and the vector-rendition path after
exploration.
superpower-writing:scientific-visualization: data plots.
- Drafting / Methods: the architecture-overview figure is a first-class
drafting task; the evidence contract's
route field may name this skill.
1---2name: scientific-schematics3description: Generate raster figure PNGs (architecture diagrams, pipelines, concept art, graphical abstracts) through the local Codex CLI's built-in image tool (gpt-image-2), under a six-section prompt contract with three-attempt selection and a targeted edit loop. Use when the user wants an image-model figure, says 生图 / 用 AI 出一张架构图 / 先出几个方向看看, prefers a polished PNG, or wants layout drafts to pick from before a TikZ rendition. Data plots go to scientific-visualization; routine vector diagrams default to tikz-figures.4license: MIT license5---67# Scientific Schematics (raster figures through the Codex CLI)89## Overview1011This skill produces raster figures with an image model. Generation runs through12the Codex CLI installed on this machine: `scripts/imagegen.py` starts one13non-interactive `codex exec` turn per image, Codex calls its built-in14`image_gen` tool (gpt-image-2 on the ChatGPT subscription), copies the PNG to15`--out`, and the script writes a provenance sidecar (`<stem>.imagegen.json`:16the Codex thread id, the prompt Codex actually sent to the image model, actual17size, wall time). `edit` resumes the thread recorded in the sidecar, so the18model still sees the original image and changes only what the instruction19names. No gateway, no API key, no token.2021Backend facts, measured 2026-09-09 with codex-cli 0.153.4 on a four-module22pipeline diagram:2324- About 35 seconds per `generate` and about 45 seconds per `edit`; two25 parallel attempts finished together in 36 seconds. Run every call with26 `run_in_background: true`.27- The image tool takes no size or quality parameter; the canvas follows the28 prompt text. "Landscape 3:2" came back 1536x1024; a left-to-right pipeline29 with no stated shape came back as a 3:1 strip. State the aspect ratio in30 FRAMING.31- Billing is ChatGPT subscription quota, not per-image money.32- Label fidelity is high: labels spelled exactly on the first attempt. Keep33 the SPELL EXACTLY line anyway; it costs nothing.34- `edit` in the same thread (rename one label) changed only that label; every35 other pixel stayed.3637Requirements: `codex` on PATH and logged in. `codex login` is interactive, so38the user runs it in a terminal, never this skill. The `image_generation`39feature is on by default; `codex features list | grep image_generation`40confirms it.4142## Two roles: decide which one applies before invoking4344**Role 1, design exploration (on demand).** When the design direction of a45figure is unclear, a novel figure type with no obvious layout, several plausible46ways to organize the information, or the user asks to "explore directions",47generate three direction drafts in parallel (different layouts or information48organization, not color variants), show all three, and let the user pick. The49user then also chooses the delivery form: use the PNG directly (manuscript, or50material for a slides rework), iterate it to final quality with `edit`, or hand51it to `superpower-writing:tikz-figures` as a replication reference (`ref.png`)52for a vector rendition. See Exploration mode below.5354**Role 2, final raster output.** When the deliverable is a PNG:5556- Illustrative concept art with lighting, texture, 3D rendering, or hand-drawn style.57- Photorealistic or semi-realistic scene compositions.58- Graphical abstracts with strong pictorial elements.59- Any figure where the user prefers a polished PNG over vector source.6061**Routing for everything else.** Routine structural diagrams with a clear design62(architecture diagrams, flowcharts, pipelines, sequence diagrams) default to63`superpower-writing:tikz-figures`; its two-candidate preview covers the layout64choice, and vector source keeps formulas and fonts consistent with the body65text. That is a default, not a rule: a high-quality PNG is a legitimate66deliverable whenever the user prefers it. Data plots (CDFs, training curves,67ablation bars, speedups, Pareto fronts) go to68`superpower-writing:scientific-visualization`.6970## Run it7172```bash73IMG="${CLAUDE_PLUGIN_ROOT}/skills/scientific-schematics/scripts/imagegen.py"7475# one figure76python3 "$IMG" generate --prompt-file .writing/figures/prompts/<slug>.txt \77 --out .writing/figures/<slug>.png7879# three attempts of the same prompt in parallel, saved as <slug>-1.png .. <slug>-3.png80python3 "$IMG" generate --prompt-file .writing/figures/prompts/<slug>.txt \81 --out .writing/figures/<slug>.png --count 38283# one targeted fix on a chosen PNG84python3 "$IMG" edit --image .writing/figures/<slug>-2.png \85 --prompt 'Rename the label "Top-k Docs" to "Top-k Passages".' \86 --out .writing/figures/<slug>.png87```8889Mandatory: `run_in_background: true` on every call. A foreground call freezes90the session for a minute or more. Do not poll; the harness notifies on91completion. Then Read the PNG to inspect it; the Read tool renders images.9293The script runs `codex exec` from the current directory with the94`workspace-write` sandbox plus write access to the output directory, retries95once when Codex exits non-zero or leaves no PNG behind, and prints one96`OK <path> <WxH> <seconds> thread=<id>` line per image. `edit` resumes the97thread named in the input image's sidecar; `--thread` overrides it, and an98image without a sidecar is attached to a fresh thread instead. The edit99instruction names only the change; the script adds the "keep everything else"100clause.101102## Workflow1031041. Decide whether the paper needs this figure and which kind. Read105 `tikz-figures/references/figure-rhetoric.md` for Figure-1 and106 solution-overview candidates; it is venue-agnostic across the figure skills.1072. Write the brief: every component with its exact label, the flow direction,108 the one hero module that carries the novelty, and the canvas shape.1093. Write the prompt file `.writing/figures/prompts/<slug>.txt` following110 `references/prompt-contract.md`. For a modern-ML pastel look also read111 `references/style-pastel-ml.md`.1124. Generate three attempts (`--count 3`) in the background. Read all three and113 pick the best against the checklist below. Quality varies between runs;114 never accept the first without seeing the others.1155. Fix defects with `edit`, one targeted change per call, at most three rounds.1166. Move the final to `.writing/figures/<slug>.png`, keep the prompt file and the117 sidecar under version control, reference with `\includegraphics`, and write118 the caption.119120## Exploration mode (Role 1)1211221. Write one shared figure brief (components, labels, flow), then derive three123 prompts that differ in layout or information organization, for example124 horizontal pipeline, layered stack, and central hero with panels. Style or125 color variants do not count as directions.1262. Save them as `.writing/figures/explore/<slug>-{a,b,c}.txt` and dispatch three127 background `generate` calls in one message, each with its own `--out`128 under `.writing/figures/explore/`.1293. When all return, Read the three PNGs, show them to the user, and ask which130 direction to develop (AskUserQuestion, one option per draft with a one-line131 layout summary).1324. Ask how to develop the chosen draft: use the PNG directly, iterate it with133 `edit` to final quality, or hand it to `superpower-writing:tikz-figures` as134 the replication reference. The last satisfies tikz-figures' two-candidate135 requirement through its 复刻 exemption; `figure-diff.py` SSIM verifies the136 TikZ rendition against the chosen draft.1375. Keep all drafts under `.writing/figures/explore/` until the figure ships;138 runner-up directions often get revisited.139140Graphical abstracts are optional. Systems papers usually omit them; generate one141only when the venue asks.142143## Failure and recovery144145- **Script exits non-zero.** Read its message. `codex CLI not found` or an146 authentication error in Codex's stderr needs the user to run `codex login`147 in a terminal; stop and say so. "codex finished but <out> does not exist"148 quotes Codex's last reply, which usually explains why nothing was saved (the149 image tool refused the prompt, or Codex asked a question instead of acting);150 fix the prompt and rerun. A timeout (600 s by default) that survived the151 built-in retry means the turn hung; stop and report the error text. Never152 invent a saved path or claim an image exists.153- **Labels will not converge.** Allow at most three `edit` rounds on one image.154 If a label is still wrong after the third, hand the draft to155 `superpower-writing:tikz-figures` for a vector rendition, where text is exact,156 or deliver the PNG with a caption note. Endless re-prompting is the failure157 mode to avoid.158- **All three exploration drafts rejected.** Do not silently regenerate the same159 three. Ask what was wrong (layout family, emphasis, missing component), derive160 a new brief, and dispatch one fresh round. After two rejected rounds, talk161 through the intended structure before spending more quota.162163## Prompt essentials164165The full contract lives in `references/prompt-contract.md`. The rules that166decide most outcomes:167168- **Labels name modules; they never explain them.** No sentences, no169 paragraphs, no formulas inside the image. Explanation belongs in the caption.170- **Name the core novelty.** One hero module gets the one visual distinction (a171 thicker border, the single accent color); everything else stays quiet.172- **Spell every label** in a list and add the literal line "SPELL ALL LABELS173 EXACTLY AS WRITTEN, do not rephrase or abbreviate".174- **State the canvas shape** in FRAMING (wide 3:1 strip, 3:2 landscape,175 square). The image tool has no size parameter; the prompt decides.176- **Icons only where they aid recognition:** a small monochrome icon inside a177 module (document stack, database cylinder, shield, network graph), never178 decoration.179- **Flat vector on white:** pastel fills with slightly darker borders, thin180 dark-grey arrows, no shadows, no 3D, no photos, no figure number, caption, or181 title baked into the image.182183## LaTeX integration1841851. Include with `\includegraphics{figures/<slug>.png}`.1862. Write a thorough caption defining every component and abbreviation; the187 image carries names only.1883. Reference the figure in the narrative with `Figure~\ref{fig:...}` (use the189 `~` tie).1904. Keep styling consistent across all figures in the paper: same prompt VISUAL191 STYLE and COLOR PALETTE blocks for every figure.1925. Version-control the prompt file and the sidecar next to the PNG so the figure193 can be regenerated.194195## Quick reference checklist196197Before accepting an attempt:198199- [ ] Every label present and spelled exactly; no extra words the prompt did not list.200- [ ] Every arrow is one continuous stroke ending on its target; no stubs.201- [ ] No overlapping elements; spacing even; the hero module visibly distinct.202- [ ] White background, flat fills, no shadow or 3D artifacts, no photographic texture.203- [ ] At most three colors plus greys; readable in grayscale.204- [ ] No figure number, caption, or title inside the image.205- [ ] Canvas shape matches what the layout needs (a strip for a pipeline, a landscape for panels).206- [ ] Text legible at final column width (check by reading the PNG scaled down).207208Before shipping:209210- [ ] Prompt file and sidecar committed with the PNG.211- [ ] Caption defines every component; `\ref{}` resolves; figure sits near its first mention.212213## Integration with other skills214215- **Figure rhetoric (design judgment).** Whether the paper needs the figure and216 which kind: `tikz-figures/references/figure-rhetoric.md`.217- **`superpower-writing:tikz-figures`**: vector diagrams compiled with LaTeX; the218 default route for routine paper figures and the vector-rendition path after219 exploration.220- **`superpower-writing:scientific-visualization`**: data plots.221- **Drafting / Methods**: the architecture-overview figure is a first-class222 drafting task; the evidence contract's `route` field may name this skill.