Andreas Heige

· 9 min · harness engineering, information engineering

Old knowledge into new work, part 2: the library draws itself

A prototype, a design system and a React app described one product and drifted apart. Each now owns one thing, the Figma library is rendered from the code, and part 1's three concerns come up again.

Contents · 7 sections

Abstract

Part 2 of two. In the autumn a second project met the June problem in a bigger shape: a Figma Make prototype, a design system the team does not own, and a production React app. Each source now owns one thing, a test compares the code's tokens with a design-system snapshot, the Figma library is generated from the rendered components, and design changes come back to code through the MCP server and a reviewed agent. The two projects illustrate similar concerns: bindings, verification and stored state.

Part 1 ended with a loop that ran one way. A scheduled job noticed when the design changed and described it, and a person brought the code along. A reader had pointed out what it could not see: the binding between a design node and its code component, which regeneration drops. Their question was whether the check could be a gate, and whether the loop could close both ways.

In the autumn the same problem came back with more parts. (The June work was first written up on LinkedIn.)

It was a different client and a different team.

Three descriptions of one product

Designers prototyped in Figma Make. The client had its own design system in Figma, which the team reads and never writes. And the team built a React app that people would use every day. Three descriptions of one product, all moving at once, and a Figma library drawn and maintained separately can drift from the application.

At first the prototype was “the single source of truth”. Porting it showed why that could not hold: copying the prototype’s pixels meant copying values the design system does not have. So the sources were split by what each one owns:

prototype      the what:   structure, flows, copy, states, intent
design system  the how:    colour, type, spacing, radius, elevation
code           as built:   components and screens; the Figma library mirrors it

With ownership settled, every seam between two sources could get a script or a test. The team’s write-up from October walks the loop stop by stop, and this part follows it.

The loop, stop by stop

Make to disk. The write-up records what the team found when it looked in August: Make had no public API, its own export was one-way and could not target an existing repository, and “Download code” depended on your seat. So a small tool saves the source the Make editor has already loaded in your own browser session, unpacks it, checks that every import resolves, and commits each pull to its own branch. The next pull’s diff shows what the designers changed.

The tool is public: figma-make-export.

Prototype to app. The port reads the prototype’s code, not its screenshots. The write-up gives the reason: once, the exported code held a newer version of a module than the published prototype showed, and a screenshot would have sent the port the wrong way. The port itself ran as agents working in separate worktrees. Two documents keep it honest. A design-intent log says why the prototype behaves as it does, so nobody “corrects” something deliberate. A flagged list records each place the sources disagree, with the default chosen and a question for design. Some answers became standing rules, and the write-up names three: accessibility beats the prototype, a value off the design system’s scale snaps to the nearest step, and the prototype’s test controls never ship.

Design system to tokens. An agent reads the design system read-only into a snapshot. After each refresh of that snapshot, a test compares it with the code’s tokens and reports the differences. For example, a refreshed snapshot can expose a breakpoint mismatch between the design system and code.

The test does two things. It fails on any token that drifts, and it pins how many tokens in each collection are linked to the design system, so a change in what the design system publishes is noticed instead of absorbed. An excerpt, with setup and calculation bodies omitted, the design system’s name taken out and the comment shortened:

it("has no drifting variable, text style or effect style", () => {
  // …every variable, text style and effect style, with its link status
  expect(drifts).toEqual([]);
});

// Pin today's classification so a DS publishing change (…) is noticed instead of silently
// drifting the app further from the DS. When this fails because the DS legitimately changed,
// don't just update the numbers here blind: re-run the snapshot migration (…), confirm the new
// counts are expected, then update this pin together with any code that should now follow the DS.
it("pins each variable collection's status counts", () => {
  // …count statuses per collection
  expect(counts).toEqual({
    "Color Primitives": { linked: 79 },
    "Color Theme": { linked: 3 },
    "Color Semantic": { linked: 84 },
    App: { local: 42 },
    Radius: { linked: 6 },
    Spacing: { mirror: 19 },
    Typography: { linked: 20 },
  });
});

linked means the token matches a published design-system variable and can bind to it. local means no counterpart was found in the snapshot. mirror means the value matches a variable in a collection hidden from publishing.

That is June’s sync loop as a unit test. It no longer files a ticket for someone to read later; the comparison fails until the code follows.

Code to Storybook. According to the write-up, every component has stories, many with interaction tests that run before every push, and CI publishes Storybook from the main branch so designers can try the real components without installing anything. The stories are also the input to the next stop.

The library draws itself

Instead of drawing the Figma library, the team renders every component and converts what the browser shows into Figma. Each combination of a component’s props becomes a variant in a component set. Hover, pressed, focus and disabled get a set of their own, because folding them in would have given the component set too many variants to manage comfortably. The write-up says every colour, spacing value, radius and text style is bound to the design system’s own variables wherever it publishes them, so designers pick the real tokens, not look-alikes. Patterns and full screens, desktop and mobile, are built from instances of those components: change Button in code, push, and the screens that use it follow. Each page opens with a generated card that says what the component is, its properties, and the source file it came from.

  1. Make prototype the what
  2. React app as built tokens from the design system
  3. Storybook stories as inputs
  4. Figma library rendered from code
  1. Make prototype the what leads to React app as built tokens from the design system: pull to disk, port the what
  2. Storybook stories as inputs leads to Figma library rendered from code: render, then push
  3. Figma library rendered from code leads to React app as built tokens from the design system: MCP + agent, reviewed (a design change coming back to code)
  • React app as built tokens from the design system leads to Storybook stories as inputs
  • Design
    • Make prototype the what
  • Code
    • React app as built tokens from the design system
    • Storybook stories as inputs
  • Mirror
    • Figma library rendered from code
Fig. 1 — Each source owns one thing; scripts and tests carry changes between them, and the library is rendered from the code.

By the write-up’s account, the first library took days. Agents sent every generated script to Figma through the MCP server, one at a time. Halfway through, it says, the Claude session hit its usage limit, and a Codex agent with the same Figma access ran the remaining screen scripts straight from disk. Every checksum matched, because the state lived in files and not in either agent’s memory. Now a small local Figma plugin reads the generated jobs from disk and runs them in order: building blocks first, then patterns, then screens, so instance overrides survive. The write-up puts a full push at about ten minutes, and describes destructive steps as separate and reviewed, though the push code does remove children and obsolete variants.

There is a small loop inside this one. The designers change a drawing, an agent turns the change into code, and the code draws the drawing again. Nobody draws the library any more, but it keeps changing. What used to be a reference document has become something closer to a mirror that can also be edited.

Back to code

A generated library still needs a return path for design changes. The write-up describes three:

  • Design changes through the MCP server. When a designer changes a component or a screen, an agent reads the new design and applies it to the component’s source in design-system tokens. The next push regenerates the library from the updated code. A change that contradicts an earlier decision goes on the flagged list instead. It is driven by an agent and reviewed, not a sync button.

  • Code Connect. In Dev Mode, Code Connect shows a code example for the selected component and variant. A shortened adaptation of the Button’s mapping, with the Figma URL, seven variant entries, the shape and caps mappings and the export metadata omitted; the example template is simplified:

    // source=src/components/ui/Button/Button.tsx
    // component=Button
    import figma from "figma";
    const instance = figma.selectedInstance;
    
    const label = instance.getString("label");
    const variant = instance.getEnum("variant", {
      "primary-fill": "primary-fill",
      "secondary-stroke": "secondary-stroke",
      // …seven more
    });
    const size = instance.getEnum("size", { medium: "medium", small: "small" });
    
    export default {
      example: figma.code`<Button variant="${variant}" size="${size}">${label}</Button>`,
      imports: ['import { Button } from "@/components/ui/Button"'],
    };
    
  • Storybook and Figma, both ways. Each story embeds its Figma component in a Design panel, and Storybook Connect links each Figma component back to its live story.

The same three concerns

The two projects illustrate similar concerns: bindings, verification and stored state. Set side by side, each of June’s lessons has an October shape.

Bindings are identity. In June, identity lived next to the code and regeneration dropped it, until a manifest made it something a test reads. Here the library is generated from the code, which gives the two a shared input instead of two drawings to keep in step. Code Connect publishes the mapping in the other direction.

What keeps a component’s node, and so its id, is the push itself. It reuses component sets and variants whose names still match, preserving those nodes and their ids while rebuilding their contents. It creates missing variants, removes duplicates, and removes variants whose names no longer fit the grid’s prop axes or options. Nothing in the repository tests that the ids survive a push. The write-up’s mock-up says “same node id after every push”; that is how the push is written, not something a gate checks.

Gates, not eyeballing. The drift test fails instead of filing a ticket. Checksums accompany the generated scripts, and the write-up describes the library push as running in checksum-verified batches. The port’s pixel diffs showed what was left, and some differences were closed as design decisions instead of being fixed. A person still decides, but a machine finds what needs deciding.

The loop keeps its own memory. June moved the baseline out of the repo and stamped every snapshot with where it came from. Here plans, generated jobs and checksums are stored in files, and the write-up credits that for one agent finishing another’s run. Decisions live in the intent log and the flagged list, and in a notes vault the agents read (Autograph is how mine gets written).

What the autumn did not solve is just as clear. The return path from a changed design to code still runs through an agent and a reviewer, not the deterministic gate the reader asked for; it does not establish automatic equivalence between design and code.

What is not automated yet

The goal is to hand as much of the loop to agents and scripts as it will take. In October the write-up listed what still needed a person in that implementation:

  • Publishing the library was one click; neither the plugin API nor the MCP server could publish at the time.
  • Near-identical building blocks, such as a button with one extra class, sometimes stayed plain frames instead of instances.
  • Some CSS did not convert to auto layout: gradients, dividers, some fractional widths.
  • Images were placeholders, because real ones would push a script past its size limit.
  • Pulling from Make still needed one paste into the browser console.

Where this sits on the thread

The write-up’s rule was to use agents for judgement and scripts for repeatable work. It also says that whatever an agent did twice became a script, a skill or a workflow. One agent writes the code and another, with a fresh context, writes the tests and tries to break it (devsecops-workflow). Git hooks run the Storybook tests, a build and a bundle budget before every push, and a machine-level hook blocks dangerous commands (my setup).

That is why this post hangs on harness engineering: the scripts, gates and hooks around the agents are what make the loop dependable, more than any single agent run. It also hangs on information engineering, because what mattered in both projects was not code. It was knowing what to keep: the binding, the baseline, the decision and why it was made.

Part 1 ended on a question about what the loop preserves. In October the answer was a record, not a guarantee: the later implementation keeps source ownership, decisions and generated state in files.