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>
This commit is contained in:
1 parent
e887996105
commit
abde27c130
2 files changed
+67
-70
No files matched your search
+65
-68
@@ -1,41 +1,48 @@
|
||||
---
|
||||
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, or "a diagram like the cookie-rotation one"; 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: who holds a reference to what, and so who can do what — use when asked for a wiring diagram, a capability diagram, or a picture of who holds what; when reviewing a design for POLA and wanting to see the reference graph; when stepping through how that graph changes across create, checkpoint, crash and revive (an "algorithm animation"). In the style of MarkM's ERTP slides. Sequence diagrams of messages between parties are a separate skill (sequence-diagram-actor-sim).
|
||||
---
|
||||
|
||||
# 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).
|
||||
POLA says each party should hold only the authority its job needs. A wiring diagram lets you check that at a glance: one picture of **who holds a reference to what, and therefore who can do what**. The arrows that are absent are the security argument. To show what happens over time, step the diagram through frames, one message each (an algorithm animation, below), draw a sequence diagram (see sequence-diagram-actor-sim), or both.
|
||||
|
||||
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.
|
||||
- `capsite-cookie-rotation/docs/cookie-rotation-wiring.html` (+ `.png`) in this workspace: the original.
|
||||
- `~/qtrx/packages/umb-download/docs/wiring.html` (+ `.png`): three makers, two outside parties, and an adversary holding a webkey.
|
||||
- `capsite-toybox-kernel/docs/sugarmint-sturdyrefs.html` in this workspace: a step-through of E's sugarMint making sturdyrefs, crashing, and reviving, with nested panes, facets on shared state, weak tables, and 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.
|
||||
Start from [`template.html`](template.html), next to this file: it has the drawing helpers and a small scene to replace. For a step-through, start from the sugarMint page. The deliverable is a local HTML file in the repo's `docs/`, 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.
|
||||
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. An id is a reference when its holder can redeem it: a DO id string reaches the object through code that holds the namespace binding, or through a route that redeems ids for anyone (cookie-rotation's `/at/<id>`, which makes the id a bearer capability). Draw the arrow from the id's holder, and say what redeems it. 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 say what it is. E's SturdyRef looks like plain data (vatID, swiss number) but also holds a LocatorUnum presence, which is its authority to look the number up. 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.
|
||||
|
||||
Watch for references dropped on purpose, such as 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 leave the arrow out.
|
||||
|
||||
When a caption claims something a reader may doubt, cite the line that shows 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.
|
||||
|
||||
## One pane per maker call
|
||||
|
||||
In MarkM's [makeMint slide](https://docs.agoric.com/guides/js-programming/hardened-js.html#from-ocaps-to-electronic-rights-mint-and-purse), each stacked pane is one call to `makeMint`. Inside a pane 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. `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 after 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, each facet a box, with arrows to the shared state table: an ERTP mint, issuer and brand; an account and its revoker. Drawing facets apart is how the picture shows attenuation.
|
||||
- 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.
|
||||
|
||||
## 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. Her caption says what she *can't* reach. Mallory makes the absent arrows visible.
|
||||
|
||||
## Vocabulary
|
||||
|
||||
@@ -43,71 +50,61 @@ leave the arrow out.
|
||||
|---|---|---|
|
||||
| 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 |
|
||||
| pale region | `maker(x, y, w, h, "makeFoo")` | a maker (factory, DO class) and the instances it made; stacked panes say "there are many" |
|
||||
| rounded square | `obj(x, y, w, h, label, stacked)` | an object or facet; `stacked` when its scope makes many |
|
||||
| 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)`.
|
||||
- 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 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)`. Where one bend can't clear everything, give explicit control points (the sugarMint page's `via` and `via2`).
|
||||
|
||||
## Step-through (algorithm animation)
|
||||
|
||||
When the story is a sequence of state changes (create, checkpoint, crash, revive), keep one layout and step through frames, like slides:
|
||||
|
||||
- Each frame is one message. The bubble shows it, with its tail at the sender; a step inside some object gets a dashed bubble with no tail.
|
||||
- Orange marks what that message changed: a halo on new objects and tables, a fill on new rows, orange for new references.
|
||||
- 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.
|
||||
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. A step-through sets `<desc>` per frame.
|
||||
|
||||
## 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:
|
||||
Render with headless Chromium. The viewport comes out shorter than `--window-size`, so render taller and crop to the SVG size; `--force-prefers-reduced-motion` keeps highlights from being caught mid-fade:
|
||||
|
||||
```sh
|
||||
chromium --headless=new --disable-gpu --no-sandbox --hide-scrollbars \
|
||||
chromium --headless=new --disable-gpu --no-sandbox --hide-scrollbars --force-prefers-reduced-motion \
|
||||
--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.
|
||||
**Look at each screenshot** (Read it) and fix overlaps: captions on arrows, arrows through tables, text clipped at the bottom. Expect two or three rounds. 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`.
|
||||
|
||||
QA screenshots in a scratch directory are fine at any point. Don't commit a PNG until the user confirms the diagram is right; a step-through gets none unless asked. Commit the HTML and the PNG separately, so the source diff stays readable.
|
||||
|
||||
## 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?
|
||||
- Does every arrow cite something in the code? Is any real reference missing?
|
||||
- Does each actor hold only what its job needs? If the picture shows an actor holding more, that's a finding about the design, not a drawing problem.
|
||||
- For each stacked box: is a new one really made per instance? For each unstacked box: is there really only one?
|
||||
- Are facets drawn apart where they differ in authority, and pointed at shared state where they share it?
|
||||
- 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.
|
||||
- Is any secret value drawn? Elide values (`session=…`, `{…}`): the picture shows *that* a row exists, not its contents.
|
||||
|
||||
## TODO
|
||||
|
||||
Migrate or copy sequence-diagram-actor-sim here. It lives at `~/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.
|
||||
@@ -28,7 +28,7 @@ adversary can and cannot reach.</desc>
|
||||
<stop offset="0%" stop-color="#6cbcf4"/>
|
||||
<stop offset="100%" stop-color="#4aa8ec"/>
|
||||
</linearGradient>
|
||||
<marker id="head" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="9" markerHeight="9" orient="auto-start-reverse">
|
||||
<marker id="arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="9" markerHeight="9" orient="auto-start-reverse">
|
||||
<path d="M0,0 L10,5 L0,10 z" fill="#1d4f7a"/>
|
||||
</marker>
|
||||
</defs>
|
||||
@@ -54,7 +54,7 @@ const dot = (x, y) => el("circle", { cx: x, cy: y, r: 4.5, fill: INK });
|
||||
const ref = (x1, y1, x2, y2, bend = 0, extra = {}) => {
|
||||
dot(x1, y1);
|
||||
const mx = (x1 + x2) / 2 - (y2 - y1) * bend, my = (y1 + y2) / 2 + (x2 - x1) * bend;
|
||||
el("path", { d: `M${x1},${y1} Q${mx},${my} ${x2},${y2}`, fill: "none", stroke: INK, "stroke-width": 2, "marker-end": "url(#head)", ...extra });
|
||||
el("path", { d: `M${x1},${y1} Q${mx},${my} ${x2},${y2}`, fill: "none", stroke: INK, "stroke-width": 2, "marker-end": "url(#arrow)", ...extra });
|
||||
};
|
||||
|
||||
// maker box: a pale rounded region, with stacked instances inside
|
||||
|
||||
Reference in new issue
Block a user