Design tokens

From event4u-app/agent-config · View interactive version

Design tokens is an AI agent skill from the GitHub repository event4u-app/agent-config. Author a 3-layer DTCG token system (primitive → semantic → component) with light/dark theming; generate CSS vars + Tailwind colors and lint hardcoded values. Use on design tokens / CSS variables.

How to use this skill

Skill file

design-tokens

Token authoring skill: the 3-layer DTCG model

(primitive → semantic → component) with light/dark theming, a

TypeScript toolchain (scripts/tokens.ts — generate / validate /

embed, run via node), and a starter template. Selection of

which token values fit the product comes grounded from

CODE0 (WCAG-adjusted

color sets, typography pairings); this skill turns the selection into a

maintained token system.

Toolchain provenance: port of the upstream .cjs trio

(generate-tokens, validate-tokens, embed-tokens) from

nextlevelbuilder/ui-ux-pro-max-skill design-system sub-skill

@ b7e3af80f6e331f6fb456667b82b12cade7c9d35 (MIT, last checked

2026-06-07); the HTML surface of upstream's html-token-validator.py is

folded into validate so there is exactly one token-discipline

linter. Obligations: CODE0.

When to use

dark-mode introduction).

validate linter into review/polish.

maintainable CSS variables / Tailwind theme entries.

The 3-layer model

| Layer | Names | References | Example |

|---|---|---|---|

| Primitive | raw scales | literal values only | primitive.color.blue.600 = #2563EB |

| Semantic | meaning | primitives via {primitive.…} | semantic.color.primary = {primitive.color.blue.600} |

| Component | per-widget | semantics via {semantic.…} | component.button.bg = {semantic.color.primary} |

Rules: components never reference primitives directly; dark mode lives

under dark.semantic.* overriding the same semantic names (emitted as a

.dark { … } block); every value is a {"$value": …, "$type": …} pair

(DTCG; 2025.10 colour/dimension/duration objects, shadow objects and

arrays, cubicBezier and fontFamily arrays read — a border,

transition, gradient, strokeStyle or typography composite, any other

array, an unresolvable {…} reference, $extends and a $ref without

$value fail generate by design, naming the token; $root takes its

group's name). A file with no primitive/semantic/component/dark

layer is flattened as semantic; top-level groups beside the layers are named

on stderr, and a file whose tokens yield no variable exits 1. Every

fontSize step has a letterSpacing sibling, per typography-system's

tracking ladder, written in rem as the step's font size × its em value,

since DTCG dimension objects allow only px and rem. Start from

the bundled starter template.

Toolchain (`scripts/tokens.ts` — skill-relative, any cwd)

# tokens.json → CSS variables (primitives + semantic + components + .dark)
node <skills-root>/design-tokens/scripts/tokens.mjs generate \
  --config tokens.json -o assets/design-tokens.css

# tokens.json → Tailwind theme.extend.colors snippet
node …/tokens.mjs generate --config tokens.json --format tailwind

# lint hex/rgb/px/rem; --tokens: palette tags
node …/tokens.mjs validate --dir src/ [--json [--tokens tokens.json]]

# embeddable inline CSS for standalone HTML artifacts
node …/tokens.mjs embed --tokens assets/design-tokens.css --minimal --style

validate --json emits "kind": "token_violation" findings — the kind

the UI directive set's polish step auto-converts

against state.ui_audit.design_tokens. Wire it into review/polish:

scan the changed files, append the findings to

state.ui_review.findings, and let the polish round fix them

(var(--token) over hardcoded hex — a rules/linters job in the

council's four-operation split, not the corpus).

**Set artifact_covered: true on a finding whose value traces to a provided

design artifact.** Without it the polish round edits AWAY from the artifact:

polish.ts::partition_artifact_covered drops flagged findings and treats every

unmarked one as actionable, and this path appended token_violation findings

without the flag — so a loop nobody asked converted a handover hex to a project

token. The flag is per finding: a hardcoded hex the artifact

never mentioned stays actionable and is fixed. Marking is not suppression — the

finding stays in the report as informational, so a reader sees that the spec

carries a value the token system does not.

(AI council 2026-09-09 on blocker: findings-actionability-default, option (b):

one call site, no package-wide default changed. Reopens if a second

artifact-derived finding path reaches the loop without provenance — then

provenance belongs in the finding TYPE, not at a third call site.)

Procedure

  1. Inspect the existing styling surface — detect the stack (Tailwind

config, global CSS, component conventions) and survey current

hard-coded values, so the token set covers what the codebase

actually uses.

  1. Ground the values — design-intelligence query gives the

WCAG-checked semantic color set + typography pairing for the product.

No brand and no corpus match (a genuinely from-scratch palette) →

derive the accent set in oklch() with shared lightness and chroma,

varied hue (oklch(50% 0.15 250) / … 200 / … 280) — equal L/C

keeps the hues perceptually balanced where random hex codes drift in

saturation; cross-check the result against C1/C5 avoidance before

locking it in.

  1. Author tokens.json from the starter: fill primitives, point

semantics at them, add dark.semantic overrides.

  1. Generate CSS vars (and the Tailwind snippet when the stack is

Tailwind — see CODE0).

  1. Validate the codebase; convert violations to var(--token).
  2. Re-run validate until clean — exit code 0 is the evidence.

Output format

  1. tokens.json (DTCG, 3 layers + dark.semantic).
  2. Generated design-tokens.css (+ Tailwind theme.extend.colors

snippet when the stack is Tailwind).

  1. validate report — exit 0 evidence, or the violations list handed to

the polish round as token_violation findings.

Security constraints

scripts/tokens.ts is the only shipped script.

directory it is asked to validate, and the --output path it is asked

to write. Nothing outside the paths named on the command line.

write to a path the caller did not name. It never edits the generated CSS

it produced earlier; regeneration replaces, it does not patch.

--output PATH is passed; --output is the flag that makes it mutating,

and it creates only that file's parent directory. validate never writes.

Do NOT

in between, always.

runtime-computed values are legitimate; review each.

(deferred per council).

Gotchas

spans (not their line), comments, token-definition files, and

known external asset hosts — review its output, don't blindly allowlist.

deferred per council 2026-06-07 (fork D2) — watch note:

agents/settings/contexts/domain-watch/brand-token-pipeline.md.

See also

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.