Repository navigation
Export collision-free colour tokens and verify every variable mapping - #134
Merged
owjs3901 merged 1 commit intoNov 28, 2026
Merged
Conversation
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
marked this pull request as ready for review
November 28, 2026 17:38
owjs3901
deleted the
devfive/3099154426bffbeef8b62999b80bb038/color-token-export
branch
November 28, 2026 17:38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A user exporting with devup-mcp 0.22.0 had to post-process the output, and the post-processing introduced the wrong colours:
gold/200,line/200andred/200all became$_200(andink/700,green/700became$_700). One token pointed at several colours, anddevup.jsoncould hold only one value for it.line/200also got ared/200entry, because$_200matched the first id with that token.flexShrink, so a longer label squeezed them.Changes
1. Collision-free theme tokens
New
theme::variable_token_namesgives every variable one$token, computed over the whole variable catalog (theme/devup_json/token_names.rs):gold/200becomesgold200. Addingred/200later does not rename it.text/primarybecomesprimary). When two variables share a leaf, each takes its full path, then its collection, then a numbered suffix.primarystill share$primary.devup.json(every scope), codegenvariable_tokensand length tokens, andgenerate_used_devup_jsonall 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/:$tokenbecomes avariable-tokenentry only when the node binds that variable for the property:boundVariables[property], orpaint.boundVariables.colorwith the top visible paint first. Mixed-colour text also countstextRangeFillsand segment fills. Non-paint properties accept any binding on the node.nodeId. The box's own attribute mapping carries no variable.fidelity.unverifiedVariableEntries, plus up to 40 examples infidelity.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 getsflexShrink="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-mismatchNew
ui_validate::token_bindings. WhensourceMapis supplied withtsx, a$tokenthat 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
sourceMapfield 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 haveflexShrink="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 inmanifest.json, and the change is documented in the fixture README.theme.rs,theme_modes.rsanddownstream_integration.rsasserted the old "one name, one winner" conflict behaviour. They now assert unique names with no conflicts.r16delivery mode. The real wquw-118 payload inr16now usesdelivery=autoinstead ofinline. The added verified provenance (about 1 KB per new attribute) pushes this screen past the 1 MiB inline limit, andautois what that limit's error tells callers to use.Tests
tests/color_token_collisions.rsuses 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:devup.jsontoken in both file and node scope;$_…and no unused$red200in the tsx;flexShrink="0"and the label does not;$line200for$gold200, or$green700for$ink700, gives onetoken-binding-mismatcherror each.cargo fmt --all -- --checkandcargo clippy --workspace --all-targets -- -D warningsare clean.cargo test --workspace: CI is the authoritative full run. Locally, every target that failed before the fixes was rerun and passes, exceptcolor_token_collisions(assertion fixed after the run) andcompat_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