Skip to content

Export collision-free colour tokens and verify every variable mapping - #134

Merged
owjs3901 merged 1 commit into
mainfrom
devfive/3099154426bffbeef8b62999b80bb038/color-token-export
Nov 28, 2026
Merged

owjs3901 merged 1 commit into
mainfrom
devfive/3099154426bffbeef8b62999b80bb038/color-token-export

Conversation

@devfive-relay-c70423

@devfive-relay-c70423 devfive-relay-c70423 Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A user exporting with devup-mcp 0.22.0 had to post-process the output, and the post-processing introduced the wrong colours:

  • Token collisions. Variable tokens were named by the last path segment, so gold/200, line/200 and red/200 all became $_200 (and ink/700, green/700 became $_700). One token pointed at several colours, and devup.json could hold only one value for it.
  • Inaccurate source map. Entries named variables the node never bound. For example, a card stroke bound to line/200 also got a red/200 entry, because $_200 matched the first id with that token.
  • Squeezed icons. Fixed-size icons or images in a row had no flexShrink, so a longer label squeezed them.

Changes

1. Collision-free theme tokens

New theme::variable_token_names gives every variable one $token, computed over the whole variable catalog (theme/devup_json/token_names.rs):

  • A WEB code syntax names the variable.
  • A leaf that is only a scale step keeps its group: gold/200 becomes gold200. Adding red/200 later does not rename it.
  • Any other leaf stays short while it is unique (text/primary becomes primary). When two variables share a leaf, each takes its full path, then its collection, then a numbered suffix.
  • Two variables only clash if they are the same kind and can land in the same theme mode. Separate Light and Dark collections that each define primary still share $primary.
  • A file's own variable keeps its name when a linked library has one with the same name; the library variable is the one qualified.

devup.json (every scope), codegen variable_tokens and length tokens, and generate_used_devup_json all use this one map. The code and the theme always agree, and no name maps to two variableIds within a theme.

2. Source-map variables proven by the node's own bindings

In provenance/:

  • A $token becomes a variable-token entry only when the node binds that variable for the property: boundVariables[property], or paint.boundVariables.color with the top visible paint first. Mixed-colour text also counts textRangeFills and segment fills. Non-paint properties accept any binding on the node.
  • When a mask box draws its child vector's colour, the variable is entered under that descendant's nodeId. The box's own attribute mapping carries no variable.
  • A descendant that is emitted as its own element (for example, the label inside an inlined button) is never evidence for its parent.
  • Tokens that fail verification are left out of the source map and reported in fidelity.unverifiedVariableEntries, plus up to 40 examples in fidelity.unverifiedVariables.

3. Fixed icons and images keep their size

codegen/layout/layout_properties.rs: a FIXED icon or image on its parent's auto-layout axis gets flexShrink="0". Other FIXED children keep the existing rule (only when the line overflows). Figma has no shrink factor of its own, so FIXED is the signal.

4. devup_ui_validate: token-binding-mismatch

New ui_validate::token_bindings. When sourceMap is supplied with tsx, a $token that differs from the one exported for the variable the Figma node binds is an error. The error names the written and expected tokens and the Figma binding (nodeId, property, variableId). This catches tokens swapped later by scripts or by hand.

The input schema is unchanged; only the sourceMap field description was extended, so the change is backward compatible with MCP clients (see commit 731bed7).

Fixture and golden changes (reviewed)

  • flexShrink="0" goldens. 24 upstream-plugin codegen snapshots and the wquw-151 insta snapshots now have flexShrink="0" on fixed icons and images. That attribute is the only change, apart from formatter line wrapping and its "Source derivation verified" diagnostics. Only the affected corpus checksums were synced in manifest.json, and the change is documented in the fixture README.
  • Mask-box variables in wquw-151. In the wquw-151 source-map snapshot, three mask boxes no longer claim their child vector's variable as their own binding. The vector that binds it is the recorded entry.
  • Updated conflict tests. theme.rs, theme_modes.rs and downstream_integration.rs asserted the old "one name, one winner" conflict behaviour. They now assert unique names with no conflicts.
  • r16 delivery mode. The real wquw-118 payload in r16 now uses delivery=auto instead of inline. The added verified provenance (about 1 KB per new attribute) pushes this screen past the 1 MiB inline limit, and auto is what that limit's error tells callers to use.

Tests

  • New tests/color_token_collisions.rs uses the reported case: gold, line and red 200 and ink and green 700 colour groups, plus a green/700 button instance whose label binds ink/700. It checks:
    • unique names, and one variableId per devup.json token in both file and node scope;
    • no $_… and no unused $red200 in the tsx;
    • every source-map variable is bound by its node, the button keeps green/700, and the label keeps ink/700;
    • no unverified variable entries;
    • the fixed icon gets flexShrink="0" and the label does not;
    • swapping $line200 for $gold200, or $green700 for $ink700, gives one token-binding-mismatch error each.
  • Unit tests for the naming rules and for the validator.
  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets -- -D warnings are clean.
  • cargo test --workspace: CI is the authoritative full run. Locally, every target that failed before the fixes was rerun and passes, except color_token_collisions (assertion fixed after the run) and compat_manifest (checksums synced afterward). The final local full run was stopped by the host for low memory, not by a test failure.

🤖 Generated with Claude Code


Submitted via Devfive hub. Employee: ; device: 3099154426bffbeef8b62999b80bb038

Figma colour groups that share a numeric step (gold/200, line/200,
red/200; ink/700, green/700) all collapsed to `_200`/`_700`, so the
generated code pointed one token at several colours, devup.json could hold
only one of them, and the source map named variables the node never bound.

- Theme: `variable_token_names` gives each variable one unique `$token`
  over the whole catalog. A scale-step leaf keeps its group (`gold200`);
  a shared leaf takes its path, then its collection, then a suffix. A
  file's own variable keeps its name against a library one. devup.json,
  codegen and the used-tokens theme all use the same map.
- Source map: a `$token` is recorded as a variable mapping only when the
  node binds it for that property (`boundVariables[property]` or
  `paint.boundVariables.color`, top visible paint first; text range
  fills for mixed text). A mask box's colour is entered under the
  descendant vector that binds it, never as the box's own binding.
  Refused tokens are counted in `fidelity.unverifiedVariableEntries`.
- Layout: a FIXED icon or image in an auto-layout line gets
  `flexShrink="0"`, so a longer label cannot squeeze it.
- devup_ui_validate: new `token-binding-mismatch` error when a `$token`
  differs from the one exported for the variable the Figma node binds,
  joined to the supplied sourceMap on elementIndex + attribute.

Regression fixture covers the gold/line/red 200 + ink/green 700 groups
and a button instance whose label binds a different variable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 marked this pull request as ready for review November 28, 2026 17:38
@owjs3901
owjs3901 merged commit 7b06a4f into main Nov 28, 2026
9 checks passed
@owjs3901
owjs3901 deleted the devfive/3099154426bffbeef8b62999b80bb038/color-token-export branch November 28, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant