Files
mad-skills/wiring-diagram/SKILL.md
T
dckcandClaude Opus 5.5 3b584df647 wiring-diagram: multiplicity, facets, proxies, step-throughs
From drawing E's sugarMint sturdyrefs and reviewing cookie-rotation-wiring:
one pane per maker call and stack only what a scope makes many of;
facets point at shared state; cross-vat references go through a proxy
in the holder's vat; read fields before calling something data; a
step-through format; no PNG deliverables until the diagram is
confirmed. The template's marker id is now "arrow": "head" collided
with an <h2 id="head"> and arrowheads vanished.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-31 13:04:09 -05:00

153 lines
9.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
name: wiring-diagram
description: >-
Capability wiring diagram, "who holds what" — use when asked for a wiring diagram, a picture of who holds what, a capability diagram, "a diagram like the cookie-rotation one", or an "algorithm animation" stepping a diagram through state changes (create, checkpoint, crash, revive); when reviewing a design for POLA and wanting to see the reference graph. MarkM ERTP-slide style: actors are balls, makers pale regions, objects rounded squares, state ledger tables, references dot-to-arrowhead; HTML/SVG plus a headless-Chromium PNG. Not for message order over time: that's a sequence diagram (sequence-diagram-actor-sim in agoric-sdk).
---
# Capability wiring diagram
One picture that answers, for a design: **who holds a reference to what,
and therefore who can do what.** It complements a sequence diagram,
which shows *when* messages flow. This one shows the standing graph of
authority that makes those messages possible. For sequences, see
`~/projects/ymax-workspace/agoric-sdk/.agents/skills/sequence-diagram-actor-sim/SKILL.md`
(on agoric-sdk branches `connolly/ago-1264-agentic-planning` and
`connolly/ago-1299-agentic-planning-tdd`, not yet on master).
Exemplars:
- `~/oros-bots/capsite-cookie-rotation/docs/cookie-rotation-wiring.html`
(+ `.png`): the original.
- `~/qtrx/packages/umb-download/docs/wiring.html` (+ `.png`): three
makers, two outside parties, and an adversary holding a webkey.
- `~/oros-bots/capsite-toybox-kernel/docs/sugarmint-sturdyrefs.html`: a step-through (see below) of E's sugarMint making sturdyrefs, crashing, and reviving. Nested panes, facets on shared state, weak tables, cross-vat proxies.
Start from [`template.html`](template.html), next to this file. It has
the drawing helpers and a small example scene to replace. For a step-through, start from the sugarMint page instead.
The deliverable is a local HTML file in the repo's `docs/`, like the exemplars, not a claude.ai artifact, unless asked.
## Read the graph from the code, not the story
Every arrow must correspond to something real: a constructor argument, a
stored id, a binding, a held token, or a file someone keeps. Before
drawing, list the references as `holder → target: where in the code`.
Read the factories (`make…`, `newX`, `configure`) and anything that
stores an id: a DO id held as a string *is* a reference. If you can't
cite where a reference comes from, it doesn't get an arrow.
Watch for references that are dropped on purpose (e.g. a setup route
that mints an instance, hands its id to one holder and forgets it).
That's often the point of the design. Say so in a caption, or just
leave the arrow out.
Read each object's fields before you characterize it. E's SturdyRef looks like plain data (vatID, swiss number) but also holds a LocatorUnum presence, which is its lookup authority. A table keyed by data can't be weak-keyed: say which side is weak (E's swissTable is a WeakValueMap) and draw the weak arrow dashed.
When a frame claims something surprising (balances don't survive a revival), cite the line that proves it, and keep what the code shows apart from what you infer. If the code is lost, say so and draw no arrows into it.
## Multiplicity: one pane per maker call
In MarkM's makeMint slide, each stacked pane is one call to `makeMint`, and inside it is what that one call made: one issuer, mint, brand and ledger, and a stack of purses because `makePurse` runs many times per mint. For each box, ask: *a new one per what call?*
- Stack a box only when its scope makes many of them. `store.readOnly()` returns the same object every time, so readOnly is 1:1 with its store and not stacked.
- Put state where the code keeps it. If one Durable Object holds many stores in one kv, the kv is one table in the DO's pane (like makeMint's ledger), not one per store.
- Name a pane by the real maker (the class or function in the code), not an invented `makeFoo`.
- Nested scopes nest panes: issuer ⊃ account ⊃ hold.
- Facets that close over shared state go in one pane for the record, each facet a box, with arrows to a shared state table (an ERTP mint/issuer/brand, an account and its revoker).
- A stack can be over time: one vat pane per incarnation.
## Between vats
A reference to an object in another vat is a proxy in the holder's vat that forwards over CapTP (or Cap'n Web). Draw the holder's vat as a small pane with the proxy in it, and the arrow from the proxy onward. That proxy is where a crash shows up as a broken reference.
## Vocabulary
| element | helper | means |
|---|---|---|
| blue ball | `actor(cx, cy, label)` | a person or a program with its own agency |
| grey ball | `actor(cx, cy, label, "url(#ext)")` | outside the system: a browser extension, a third-party service |
| pale region | `maker(x, y, w, h, "makeFoo")` | a maker (factory, DO class) and the instances it made; the stacked inner panes say "there are many" |
| rounded square | `obj(x, y, w, h, label, stacked)` | an object or facet; `stacked` when one is made per instance |
| ledger table | `table(x, y, title, rows, [colW0, colW1])` | an object's state; rows are key/value; `rowY(i)` and `colX` give arrow anchors |
| dot → arrowhead | `ref(x1, y1, x2, y2, bend)` | holder references target; `bend` (±0.05–0.3) curves around things |
| speech bubble | the `path` + `code` block | the one call the picture is about, in `E(target).method(args)` form |
| caption | `cap(x, y, text, attrs)` | what an actor holds, and what it can't reach |
Facets are separate objects (`store` vs `readOnly`): drawing them apart
is how the picture shows attenuation.
## Include an adversary
Add a Mallory who holds whatever is most likely to leak (an instance
id, a webkey, a URL), with an arrow to exactly what it reaches. The
caption says what she *can't* reach. Absent arrows are the security
argument, and Mallory makes them visible.
## Layout
- Actors in a row along the top (y≈200), makers below (y≈320 onward),
captions along the bottom (y≈ height − 14).
- Put each maker under the actors that mostly use it, so arrows run
short and downward.
- Speech bubble at the top, its tail pointing at the speaker. Move the
bubble's path (`M x,y`) and the tail segment (`h… l-38,48 l6,-48`)
together.
- Captions: two or three short lines, never on top of an arrow or a
ball. Use `"text-anchor": "start"` to set one beside a ball.
- Long arrows that cross a maker: increase `|bend|` until the curve
clears tables and objects. The control point is the midpoint offset
by `bend × (−dy, dx)`.
## Step-through (algorithm animation)
When the story is a sequence of state changes (create, checkpoint, crash, revive), keep one fixed layout and step through frames, like slides:
- Each frame is one message. The bubble shows it, with its tail at the sender; a step internal to some object gets a dashed bubble with no tail.
- Orange marks what that message changed: new objects and tables get a halo, new rows a fill, new references an orange arrow.
- Below the picture: a short heading, a sentence saying what the message did and why, and a cite line (`file:line`).
- Dead things fade (opacity 0.25); broken references are red, dashed, with a ✕.
- Controls: Prev/Next, arrow keys, a slider, and `#sN` deep links.
- In code, name frames (`F.save`, `F.revive`) and derive visibility from them (`on(F.sturdy, F.rebuild)`, `fresh(F.save)`), so inserting a frame doesn't shift every index.
## Accessibility
Keep `<title>` short. Write `<desc>` as prose that names every actor and
maker, every reference, the bubble's call, and what the adversary
can't reach. Someone who can't see the picture should get the same
argument from it.
## Render and check
The page is self-contained (no network). Render a PNG with headless
Chromium. The viewport comes out shorter than `--window-size`, so render
taller and crop to the SVG size:
```sh
chromium --headless=new --disable-gpu --no-sandbox --hide-scrollbars \
--window-size=W,$((H+100)) --screenshot=full.png "file://$PWD/NAME.html"
python3 -c "from PIL import Image; Image.open('full.png').crop((0,0,W,H)).save('NAME.png')" && rm full.png
```
Then **look at the PNG** (Read it) and fix overlaps: captions on arrows,
arrows through tables, text clipped at the bottom. Expect two or three
rounds. Commit the HTML (source) and the PNG separately, so the source
diff stays readable.
QA screenshots in a scratch directory are fine at any point; add `--force-prefers-reduced-motion` so highlights aren't caught mid-fade. Don't make PNG deliverables until the user confirms the diagram is right. A step-through gets no PNG unless asked.
If arrowheads vanish, look for an id collision: SVG marker ids share the page's id namespace, and an `<h2 id="head">` once hijacked `url(#head)`. The template's marker is `arrow`.
## Review checklist
- Does every arrow cite something in the code? Is any real reference
missing?
- Does each actor hold only what its job needs (POLA)? If the picture
shows an actor holding more, that's a finding about the design, not a
drawing problem.
- Are facets drawn apart where they differ in authority, and pointed at shared state where they share it?
- For each stacked box: is a new one really made per instance? For each unstacked box: is there really only one?
- Do references into another vat go through a proxy in the holder's vat?
- Does the adversary's caption match what the arrows show?
- Does `<desc>` tell the same story in prose?
- Is any secret value drawn? Elide values (`session=…`, `{…}`): the
picture shows *that* a row exists, not its contents.