Communitygithub.com

machine-view

Explain or review how a UI component, hook system, or stateful feature works as an animated "machine" diagram with a fixed visual language. It has two views, Flow (what happens, in four bands) and Anatomy (how it's built: components, hooks in call order, ref handles, prop drilling), plus two layers: React internals (event/render/commit/layout/paint/passive phases, queued updates, a fiber walk of which components render, bail out, mount or unmount) and accessibility (ARIA state, DOM and virtual focus, approximate screen reader output). Review notes mark smells. Use when the user asks to visualize, map, break down, review, or "show me how it works" for components, state, refs, effects, event handling or accessibility, or wants a mental model of code an AI wrote. Not for static architecture boxes-and-arrows or for data charts.

¿Qué es machine-view?

machine-view is a Claude Code agent skill that explain or review how a UI component, hook system, or stateful feature works as an animated "machine" diagram with a fixed visual language. It has two views, Flow (what happens, in four bands) and Anatomy (how it's built: components, hooks in call order, ref handles, prop drilling), plus two layers: React internals (event/render/commit/layout/paint/passive phases, queued updates, a fiber walk of which components render, bail out, mount or unmount) and accessibility (ARIA state, DOM and virtual focus, approximate screen reader output). Review notes mark smells. Use when the user asks to visualize, map, break down, review, or "show me how it works" for components, state, refs, effects, event handling or accessibility, or wants a mental model of code an AI wrote. Not for static architecture boxes-and-arrows or for data charts.

Compatible con~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/kmcaloon/skills/tree/HEAD/skills/machine-view

Preguntar en tu IA favorita

Abre un nuevo chat con esta habilidad de agente ya precargada.

Documentación


name: machine-view description: Explain or review how a UI component, hook system, or stateful feature works as an animated "machine" diagram with a fixed visual language. It has two views, Flow (what happens, in four bands) and Anatomy (how it's built: components, hooks in call order, ref handles, prop drilling), plus two layers: React internals (event/render/commit/layout/paint/passive phases, queued updates, a fiber walk of which components render, bail out, mount or unmount) and accessibility (ARIA state, DOM and virtual focus, approximate screen reader output). Review notes mark smells. Use when the user asks to visualize, map, break down, review, or "show me how it works" for components, state, refs, effects, event handling or accessibility, or wants a mental model of code an AI wrote. Not for static architecture boxes-and-arrows or for data charts.

¿Qué hace machine-view?

The user reads code less and less, so they lose the feel of how a system moves and how it's wired. This skill gives that back as a small animated machine. A spec you write is rendered by a fixed renderer. The vocabulary never changes between diagrams, so the user's intuition builds up across every machine they see. Do not draw freehand, invent shapes or colours, or restyle the template.

One spec gives the user three ways to look at the same system:

  • Flow: what happens. Four bands. A scenario's tokens move through them.
  • Anatomy: how it's built. Each component is a card. Rows are its hooks in call order, then the DOM it renders. Ref handles and prop drilling are drawn explicitly. The same scenarios replay here.
  • React internals layer (a toggle in both views): a phase rail, EVENT › RENDER › COMMIT › LAYOUT › PAINT › PASSIVE › LATER, that lights up as each moment happens. State set outside render shows as old ⇢ new (faded, queued) until the next render applies it. A fiber walk lists, in order, which components render, bail out, mount or unmount, and why; in anatomy view a light travels card to card.
  • Accessibility layer (a toggle in both views): ARIA attributes on UI parts, DOM focus versus virtual focus rings, and a transcript of approximately what a screen reader says.

Plus review notes: numbered markers on the diagram, listed below it. Some come from you; the build adds others automatically.

The language (memorize; it is the whole point)

Flow view bands, always in this order, top to bottom. "Appearance rises, intent sinks."

bandholdskinds
SURFACEwhat the user sees and touchesui
BEHAVIORlogic that runs during render or on eventshook, handler, derived
STATEwhat is true; survives re-rendersstate, context, ref
WORLDoutside Reacteffect, external

Parts (node kinds):

  • ui: a DOM element or rendered child.
  • hook: a custom or library hook.
  • handler: an author-written callback.
  • derived: computed during render (useMemo, selectors, consts in the render body). Dashed.
  • state: a source of truth. List its fields.
  • context: a provider value.
  • ref: a mutable box that does not re-render. Dotted. Give it a current field when what it points at matters.
  • effect: reaches outside React (useEffect, useLayoutEffect, loaders, subscriptions). Put the timing in detail.
  • external: network, storage, router, timers, browser APIs.

Wires (edge kinds):

  • read: props, return values, state reads. Continuous drifting dots, because the data is always present.
  • event: an event or callback call. Dashed pink.
  • write: a setter or dispatch. Gold.
  • effect: triggers outside work. Violet.
  • response: an async result. Dotted green.
  • subscribe: a long-lived listener. Grey dots.
  • ref: a ref handle being passed or attached. Drawn ○ → ●: ○ is where the ref was created, ● is where it's attached (to a ui) or used (by a hook or effect). Use read from a ref only when code reads .current.

Motion (scenario actions): each has exactly one meaning.

  • send: one labelled token travels a wire (a single moment).
  • set: a field changes, shown as old → new in gold.
  • render: parts re-render (gold ring).
  • fire: an effect runs (violet ring). With cleanup: true, its cleanup or abort runs (contracting ring).
  • pulse: draws attention without changing anything.
  • focus: DOM focus moves (solid ring). null means focus fell to <body> or nowhere.
  • vfocus: virtual focus, e.g. aria-activedescendant (dashed cyan ring), with a label. null clears it.
  • aria: an ARIA attribute changes (cyan old → new).
  • announce: what a screen reader says, plus via (focus / live region / activedescendant / why it's silent).
  • wait: pause for N seconds.
  • fiber: the render walk, in order: [{ "c": "<component id>", "op": "render|bailout|mount|unmount", "why": "open prop changed" }].

Phases (React internals): put "phase" on a step (or on a single action to override it). The values are event (handlers; setState only queues), render (components called; pure; may run twice in StrictMode), commit (DOM mutation, refs detached then attached), layout (useLayoutEffect, before paint), paint, passive (useEffect: cleanups, then effects) and async (network or timers that lead to a new event). Model them faithfully. The point is to show when things really happen. Common truths worth showing:

  • a set in event doesn't change the value until render;
  • a ref is null during the first render and only attached in commit;
  • useEffect runs after paint, so state it sets causes a second render;
  • a parent's re-render re-renders every non-memoized child, so list those children in the fiber walk with why: "parent re-rendered"; use bailout only when memo or identical elements actually skip them.

Workflow

  1. Read the real code first. Trace element → event → handler/hook → setter → state → effects → render. For anatomy, also note which component calls each hook, in what order, every place a ref is created, passed, attached and read, and every prop that is only forwarded.

  2. Inventory. Every part gets a code ref (path/file.tsx:42). If you didn't confirm something in code, set "inferred": true; it renders visibly.

  3. Pick the zoom. In flow view, keep it to ≤ 10 parts, ≤ 4 per band, ≤ 16 wires. Parts that only matter to the "how" (individual refs, inner library hooks, wrapper elements) get "views": ["anatomy"] so flow stays readable. Keep anatomy to ≤ 7 components. For bigger systems, make one machine per feature.

  4. Write 2–4 scenarios, each a real user story:

    • the happy path (first);
    • the tricky case: a race, cancellation, stale closure, ref timing, error, or optimistic rollback;
    • a surprising consequence if one exists. These are where the skill earns its keep.

    Each step's say is one plain cause→effect sentence (≤ 140 chars) about why. Put the identifier in the token label and the line in code.

  5. Accessibility (do this for any interactive UI): give each ui part the aria it actually renders (role, accessible name, aria-expanded, aria-controls, aria-activedescendant, aria-live…). Write "(missing)" or "(none)" when it's absent. That is how gaps become visible. Add focus/vfocus/aria actions where they change, and an announce wherever a screen reader would speak, or would stay silent when it shouldn't ("(silence)", with the reason in via). Announcements are approximate: model them on the ARIA that is present, avoid claiming exact wording for one specific reader, and cite library behaviour only when you've seen it in code.

  6. Review notes. Add smells for real problems you found, with level bug, warn or note, a short title, and text that says what goes wrong and what to do instead. Don't repeat what the build detects automatically:

    • props or refs drilled through ≥ 2 components (wires with via), grouped per chain;
    • a ref read during render (read from a ref into ui or derived);
    • one ref attached to several elements;
    • a ref used by several other components;
    • an effect that writes state it depends on.

    With phases and fiber walks present, the build also flags state set during render, state set in layout or passive effects, and pass-through components (which own nothing) that re-render. Model the code faithfully (use via, owner, views, phase, fiber) so these fire.

  7. Build and validate: python3 <skill-dir>/build.py spec.json out.html. Fix every error:, and take warning:s seriously. Phases: for anything involving refs, effects, focus, measuring or re-render cost, give every step a phase and add a fiber walk to each render step. Set "internals": true at the top level to turn the layer on by default.

  8. Show it. If an inline HTML render tool exists (e.g. html_render), pass it the built file's full contents. Height is roughly 750 for flow-only and 1,000–1,400 with notes and anatomy; measure if you can. Otherwise give the absolute path to open in a browser. Offer to save the spec next to the code (e.g. docs/machines/<feature>.json) so it can be rebuilt after changes. Set "defaultView": "anatomy" when the question is about structure or code review.

  9. Keep prose short: at most three sentences on what to watch for. The machine does the explaining.

Spec format

{
  "title": "Feature — one-line name",
  "subtitle": "What this is and where it lives.",
  "defaultView": "flow",
  "internals": true,
  "components": [
    { "id": "app", "label": "App", "code": "App.tsx" },
    { "id": "pal", "label": "Palette", "parent": "app", "code": "Palette.tsx" }
  ],
  "nodes": [
    { "id": "q", "kind": "state", "owner": "app", "order": 1, "label": "useState(query)", "code": "App.tsx:9", "fields": { "query": "''" } },
    { "id": "inputRef", "kind": "ref", "owner": "app", "order": 2, "label": "useRef(inputRef)", "code": "App.tsx:10", "fields": { "current": "null" }, "views": ["anatomy"] },
    { "id": "input", "kind": "ui", "owner": "pal", "label": "<input>", "code": "Palette.tsx:20",
      "aria": { "role": "combobox", "accessible name": "Search", "aria-expanded": "false" } }
  ],
  "edges": [
    { "id": "type", "from": "input", "to": "q", "kind": "write", "label": "onChange → setQuery" },
    { "id": "attach", "from": "inputRef", "to": "input", "kind": "ref", "label": "ref={inputRef}", "views": ["anatomy"] },
    { "id": "drill", "from": "inputRef", "to": "fx", "kind": "ref", "label": "inputRef", "via": ["header", "toolbar"] }
  ],
  "smells": [
    { "at": "input", "level": "bug", "title": "no accessible name", "text": "What goes wrong, and the fix." }
  ],
  "scenarios": [
    { "name": "Type a letter", "summary": "Shown when the scenario ends.", "initialFocus": "input",
      "initial": { "q": { "query": "'a'" }, "input": { "aria-expanded": "true" } },
      "steps": [
        { "say": "Why this happens, in one sentence.", "code": "Palette.tsx:44", "phase": "event",
          "do": [ { "send": "type", "label": "'b'" }, { "set": "q", "field": "query", "value": "'ab'" },
                  { "aria": "input", "attr": "aria-expanded", "value": "true" },
                  { "announce": "3 results available", "via": "live region" } ] }
      ] }
  ]
}
  • owner puts a part in a component card. order is hook call order (UI parts list after the hooks). Parts with no owner go in an "Outside React" card.
  • via lists the components a wire passes through untouched, in travel order. Each one gets a "⇢" row in its card.
  • views (["flow"] or ["anatomy"]) hides a part or wire from the other view. Actions on hidden parts are skipped in that view.
  • fields and aria values are display strings. Only declared ones can be set or changed with aria, and initial may override either.
  • Actions in a step play in order, so their order is the causal order.

Mapping beyond React

The bands are generic. A server is SURFACE = endpoints, BEHAVIOR = middleware/handlers, STATE = DB/cache, WORLD = queues/third parties, and components become modules. Keep the kinds; only the labels change.

Examples: examples/rac-combobox.json (React Aria's real ComboBox, read from adobe/react-spectrum source with file:line refs; anatomy, internals, a11y, review notes on an every-render effect and a doubly attached ref) and examples/sloppy-palette.json (an illustrative hand-rolled palette with drilled refs, a ref read during render, cross-subtree focus and a11y gaps).

Skills relacionados