DiaMotion Skill v3.6
Tool Home: The root of your local
diamotionclone (denoted<diamotion>below; run CLI commands from<diamotion>or set$DIAMOTION_HOME). Read<diamotion>/README.md(orREADME.zh-CN.md) for setup (npm install, Node ≥ 24, Edge/Chrome, optional Python + Pillow/PyMuPDF) and the--dg-*theme contract. Schema:<diamotion>/schema/diagram.schema.json. Reference examples (all passingtools/check.mjswith0 errors / 0 warnings):
examples/ualink-fig-1-2/— Topology / Hierarchical Block Diagramexamples/ualink-fig-1-3-stack/— Layered Protocol Stackexamples/ualink-dl-fsm/— State Machine (FSM)examples/ualink-dl-fsm-route3/— Two-stage decoupledstatic.json+story-trace.json(trace+regions+badges+trail: "auto")examples/ualink-flit-flow/— Flowchart / Decision Logicexamples/ualink-chiplet-credits/— Nested Pipeline & Credit Loops
Two goals (nothing else matters)
- The reader understands the figure fast. One idea per step. Show cause and effect with motion. Keep text short and anchored on the diagram.
- The output is original-faithful and theme-agnostic. Author semantic data only: no HTML, CSS, JS, colors, or fonts. When an original figure exists, mirror its spatial layout and clean wiring via
"layout": "faithful"; themes style--dg-*CSS variables.
Hard rules
- Never hand-write a per-diagram HTML/SVG/JS page. Author
diagram.json(orstatic.json+story.json) and build/verify it withtools/check.mjs. - Original-faithful layout when a reference figure exists (
faithful). Set"layout": "faithful"(or{ "engine": "faithful", "pad": 24, "groupPad": 24 }) and omit"canvas". Place nodes on a clean grid mirroringoriginal.png's exact rows, columns, symmetry, aspect ratio, vertical pipeline strips (vertical: true), orthogonal rails, smooth curved FSM/cable arcs (curve: true), and dashed interface dividers (style: "guide"). Letlayout.mjsauto-size omittedw/h, recursively wrap nestedgroup.contains, auto-place omitted link/attached labels, and normalize tight bounds (negative rail coordinates are allowed during authoring). - ELK auto-layout for text-only diagrams (
elk). When creating a diagram from text alone without a source figure, set"layout": { "engine": "elk", ... }and omit node/groupx/y/w/hand linkpoints. - Preserve all original elements; add helpful ones freely. Always populate
"sourceItems": [...]with every visible label/element fromoriginal.pngsolintverifies nothing is silently dropped. You may freely add auxiliary explanatory nodes/groups/links styled normally withkinds. - Zero colors or fonts in data. Express meaning only via
kinds({ "ualink": { "slot": 1, "name": "UALink" } }using slots1..6or"neutral").lintalways rejects raw style keys (color,fill,stroke,bg,background,backgroundColor,font,fontFamily,css,theme, andstyleon non-links). - Do not edit
player/orthemes/for one diagram. If a capability is genuinely missing, extend the toolkit generically, runnpm run build:player && npm run verify, and document it inschema/diagram.schema.jsonand the READMEs. - Strict grounding & accuracy. When
sourceTextis present:- Every
quoteis verified verbatim bylint(hyphenation-aware; supports…/[...]ellipses). - Every non-overview step must have either a verified
quoteOR an explicit non-verbatimtagmatching推断|非原文|示意|假设|通用知识(e.g."tag": "推断 · 非原文"). - At least 50% (
ceil((steps - 1) * 0.5)) of main-scene non-overview steps must carry verified verbatimquotes. - Keep modal verbs exact (
shall≠may). Never invent fields, numbers, or behavior. Name unlabeled connections honestly (e.g."原文未命名").
- Every
Workflow
-
Prepare inputs in a working folder (e.g.,
diagrams/<slug>/, or a user-specified path):- From a PDF:
Writespython tools/crop_figure.py <spec.pdf> --page N --figure "x-y" --out <dir> [--pages-text a-b] [--clip x0,y0,x1,y1]original.pngandsource.txt. For vector PDFs, optionally also extract exact normalized geometry anchors:Always visually inspectpython tools/pdf_geom.py <spec.pdf> --page N --figure "x-y" -o <dir>/raw_geometry.json [--canvas-w 1100] [--clip x0,y0,x1,y1]original.png; if anything is clipped or stray prose leaked in, re-run with--clip. Include adjacent pages via--pages-textwhen the explanation spans pages. - From a screenshot: save it as
<dir>/original.pngand any accompanying text as<dir>/source.txt. - Two-stage decoupled workflow (Route 3, recommended when reusing one figure across multiple stories):
- Author
<dir>/static.json(elements,kinds,layout,sourceItems,glossary,original,sourceText— noscenes) and lock geometry +compare.pngvia:node tools/check.mjs <dir>/static.json --static - Author one or more
<dir>/story-*.jsonfiles referencing"base": "./static.json"(plus optional"overlayElements": [...]and"scenes": [...]) and verify each with:node tools/check.mjs <dir>/story-*.jsonSingle-filediagram.jsonremains 100% supported.
- Author
- From a PDF:
-
Understand before authoring. Answer for yourself:
- What single question does the figure answer? That becomes
summary(≤ 40 visual chars;vlen: CJK = 1, ASCII = 0.5). - What is the complete inventory of visible elements/labels in
original.png? Put every one intosourceItems. - What is the exact spatial structure of
original.png? Identify rows/columns, symmetry axes, vertical strips, nested containers, orthogonal channel rails, curved FSM/cable arcs, timing waveforms, and dashed interface dividers. - What are the 3–10 steps? Order: overview → one idea per step → takeaway.
- What single question does the figure answer? That becomes
-
Author theme-agnostic
diagram.json(orstatic.json+story.json).- Root metadata:
"$schema","version": 1,"id","title","source","summary","original": "original.png","sourceText": "source.txt","sourceItems": [...],"glossary": { ... }. - Root layout:
- With
original.png(primary):"layout": "faithful"or{ "engine": "faithful", "pad": 24, "groupPad": 24 }and omit"canvas"(auto-computed and normalized so top-left starts atpad; negative rail coordinates likex: -40are fine). Optional"fontSize": 15(default16). - Text-only (no
original.png):"layout": { "engine": "elk", "direction": "DOWN"|"RIGHT"|"UP"|"LEFT", "routing": "ORTHOGONAL"|"POLYLINE", "nodeGap": 40, "layerGap": 64, "groupPad": 24, "edgeGap": 22, "pad": 24, "wrapping": "OFF"|"SINGLE_EDGE"|"MULTI_EDGE", "aspectRatio": 1.6 }, omittingx/y/w/hand linkpoints.
- With
- Rich inline text: use
_{...}for subscript and^{...}for superscript (e.g.T_{HS-PREPARE},2^{16},D_{0}) in any node/group/link/label/wave text or step caption; bare_/^and\_{/\^{remain literal. - Elements:
node(defaulttype):id,x, y(required infaithful; omit inelk), optionalw, h(auto-sized when omitted; set explicitly for aligned uniform rows/columns/strips),label(\nfor multi-line), optionalsub,kind,shape:box | round | pill | circle | diamond | chip | tag | mux | cylinder | hexagon | xor | dot | brace,orient(right|left|down|upformux/hexagon/cylinder/brace),sharp: true,dashed: true,double: true,stack: true,vertical: true+verticalDir: "up"|"down",inset,minW/minH.group:type: "group",label, optionalkind,border("dashed"|"solid"|"none"),fill("none"|"tint"),labelPos(top-left|bottom-left|top|bottom|top-right|bottom-right|top-outside|bottom-outside),contains: [childIds...],pad, optionalx, y, w, h,minW/minH.wave:type: "wave", declarative protocol timing track at(x, y), optionalh,kind, optional left-raillabel&size, andsegments: [{ type, w, label?, from?, to?, cycles?, highlight? }]wheretypeishigh | low | mid | data | clk | x | gap | ramp.link:type: "link",from,to("id","id.side", or"id.side:frac", shape-aware onpill,circle,xor,dot,diamond,hexagon,mux), optionalpointsor explicitroute,curve: true,style: "line"|"bus"|"guide"|"block",z: "auto"|"top",dashed,arrow(none|end|start|both),label,labelPos,labelAt+labelOffset,labelRotate: true,labelBg: true.label:type: "label",text,anchor(start|middle|end),strong,size, optionalattach: "<id>"(inherits focus/dim/hidden across multi-hopattachchains).
glossary: map every acronym/key term to a concise plain explanation (also matchese.kindand newline-normalized labels).
- Root metadata:
-
Design steps for ADHD readers (strict budgets enforced as errors by
lint):- Step count:
3–10steps per scene. - Main scene step 1: overview with no
focus— frame what the figure shows and what to watch for. - Middle steps: one idea per step,
focus≤ 6 ids. Link endpoints and group members stay undimmed automatically;contextexpands group members recursively. Opt into 3-tier visual memory via"trail": "auto"on a scene or per-step"visited": [ids]. Every scene needs ≥ 1 focused step. - Motion for causality:
tokens: [{ via: [linkIds…], from?, text?, tone?: "accent"|"ok"|"danger"|"kind", after?: idx, once?: true, repeat?: N, dur?, delay?, reverse? }]— smooth travelling badges with semantic tones, synchronized relay chains (after), and finite settling (once/repeat).flow: ["lnk1", { "id": "lnk2", "reverse": true }]— continuous forward or reverse dashed flow.trace: ["lnk1", { "id": "lnk2", "reverse": true }]— single-pass stroke draw-in along a link (sweeps once and settles visibly without disturbing dashed wires; respectsmark: "danger" | "ok").set: { id: "new label" }— dynamic value/state update with persistent.is-changedaccent tint + bold label.mark: { id: "danger" | "ok" | "off" }— semantic error, success, or disabled state.show/hide— appearing or disappearing elements.
- Story-layer overlays (
regions&badges— ideal for decoupledstory.json):regions: [{ of: [elementIds…], tone?: "accent"|"ok"|"danger"|"kind", kind?, pad?: 8, dashed?: false }](max 3 per step): draws a soft translucent box belowL-groupsaround the union bounding box of any static elements (e.g. timing windows between vertical guide lines or a slice of register cells).badges: [{ at: "id", text?: "1", corner?: "tl"|"tr"|"bl"|"br", tone?: "accent"|"ok"|"danger"|"kind" }](max 6 per step,text≤ 2 visual chars, auto-numbers1..N): circular reading-order stamps with 4-corner collision avoidance.
- Notes: at most 2 notes per step, each
text≤ 12 visual chars; auto-placed collision-free across all 4 sides. - Captions:
title≤ 18 visual chars (state a takeaway, not a bare noun);say≤ 70 visual chars (1–2 crisp spoken sentences, at most 2**bold**pairs). - Second
scene: add only when a contrast or alternate branch genuinely clarifies why; tag non-verbatim scenarios.
- Step count:
-
Verify and iterate with one command (run from
<diamotion>):node tools/check.mjs <dir>/diagram.json [--themes paper,midnight] [--out <dir>] [--loose] [--static] [--no-shots] [--no-compare]check.mjsruns 4 stages in sequence and writes<dir>/check-report.json:lint— structure, forbidden style keys,sourceItems, strict ADHD budgets, static shape geometry, and verbatim quotes.layout + build—faithful/elk/manualresolution →<dir>/index.html.audit + shots— single headless Edge/Chrome via CDP audits live Shadow DOM across everytheme × scene × step(.err, JS/console errors, shape text overflow, group label overflow, note/badge clipping & overlaps, leader crossings, text–text overlaps, viewBox clipping,.wrapoverflow) and captures<dir>/shots/*.png.compare— builds side-by-side<dir>/compare.png(Original | Redraw).
Loop until
RESULT: PASS(exit 0, 0 errors/0 warnings), AND visually inspect<dir>/compare.pngplus rendered shots in BOTHpaperandmidnight! -
Deliver.
- Link
<dir>/index.html(offline, with theme switcher & zoom/pan UI),<dir>/diagram.json(orstatic.json+story.json), and<dir>/compare.png. - Keep the summary short: what the steps cover, any non-verbatim inferred steps, and confirmation that
check.mjspassed.
- Link
Embedding for other layers
Use <dg-player src="resolved.json"> (dumped via node tools/layout.mjs or build.mjs --resolved) or inline <script type="application/json">. Set --dg-* CSS custom properties on any ancestor to re-theme. Use chrome="none" for a bare diagram, zoomIn() / setZoom() / resetZoom() for viewport inspection, and listen to the dg-step event to sync narration or video.