2026-06-26
当日 #1 TypeScript +1.4k ★ today ★ 18.8k
📌 定义视觉身份格式规范,让 AI 代理理解设计系统
一种用于向编码代理描述视觉身份的格式规范。DESIGN.md 赋予代理对设计系统持久、结构化的理解能力。
# DESIGN.md
A format specification for describing a visual identity to coding agents. DESIGN.md gives agents a persistent, structured understanding of a design system.
## The Format
A DESIGN.md file combines machine-readable design tokens (YAML front matter) with human-readable design rationale (markdown prose). Tokens give agents exact values. Prose tells them *why* those values exist and how to apply them.
---
name: Heritage
colors:
primary: "#1A1C1E"
secondary: "#6C7278"
tertiary: "#B8422E"
neutral: "#F7F5F2"
typography:
h1:
fontFamily: Public Sans
fontSize: 3rem
body-md:
fontFamily: Public Sans
fontSize: 1rem
label-caps:
fontFamily: Space Grotesk
fontSize: 0.75rem
rounded:
sm: 4px
md: 8px
spacing:
sm: 8px
md: 16px
---
## Overview
Architectural Minimalism meets Journalistic Gravitas. The UI evokes a
premium matte finish — a high-end broadsheet or contemporary gallery.
## Colors
The palette is rooted in high-contrast neutrals and a single accent color.
- **Primary (#1A1C1E):** Deep ink for headlines and core text.
- **Secondary (#6C7278):** Sophisticated slate for borders, captions, metadata.
- **Tertiary (#B8422E):** "Boston Clay" — the sole driver for interaction.
- **Neutral (#F7F5F2):** Warm limestone foundation, softer than pure white.
An agent that reads this file will produce a UI with deep ink headlines in Public Sans, a warm limestone background, and Boston Clay call-to-action buttons.
## Getting Started
Validate a DESIGN.md against the spec, catch broken token references, check WCAG contrast ratios, and surface structural findings — all as structured JSON that agents can act on.
npx @google/design.md lint DESIGN.md
{
"findings": [
{
"severity": "warning",
"path": "components.button-primary",
"message": "textColor (#ffffff) on backgroundColor (#1A1C1E) has contrast ratio 15.42:1 — passes WCAG AA."
}
],
"summary": { "errors": 0, "warnings": 1, "info": 1 }
}
Compare two versions of a design system to detect token-level and prose regressions:
npx @google/design.md diff DESIGN.md DESIGN-v2.md
{
"tokens": {
"colors": { "added": ["accent"], "removed": [], "modified": ["tertiary"] },
"typography": { "added": [], "removed": [], "modified": [] }
},
"regression": false
}
## The Specification
The full DESIGN.md spec lives at `docs/spec.md`. What follows is a condensed reference.
### File Structure
A DESIGN.md file has two layers:
1. **YAML front matter** — Machine-readable design tokens, delimited by `---` fences at the top of the file.
2. **Markdown body** — Human-readable design rationale organized into `##` sections.
The tokens are the normative values. The prose provides context for how to apply them.
### Token Schema
version: # optional, current: "alpha"
name:
description: # optional
colors:
:
typography:
:
rounded:
:
spacing:
:
components:
:
:
### Token Types
| Type | Format | Example |
|:-----|:-------|:--------|
| Color | Any CSS color (hex, `rgb()`, `oklch()`, named, etc.) | `"#1A1C1E"`, `"oklch(62% 0.18 250)"` |
| Dimension | number + unit (`px`, `em`, `rem`) | `48px`, `-0.02em` |
| Token Reference | `{path.to.token}` | `{colors.primary}` |
| Typography | object with `fontFamily`, `fontSize`, `fontWeight`, `lineHeight`, `letterSpacing`, `fontFeature`, `fontVariation` | See example above |
### Section Order
Sections use `##` headings. They can be omitted, but those present must appear in this order:
| # | Section | Aliases |
|:--|:--------|:--------|
| 1 | Overview | Brand & Style |
| 2 | Colors | |
| 3 | Typography | |
| 4 | Layout | Layout & Spacing |
| 5 | Elevation & Depth | Elevation |
| 6 | Shapes | |
| 7 | Components | |
| 8 | Do's and Don'ts | |
### Component Tokens
Components map a name to a group of sub-token properties:
components:
button-primary:
backgroundColor: "{colors.tertiary}"
textColor: "{colors.on-tertiary}"
rounded: "{rounded.sm}"
padding: 12px
button-primary-hover:
backgroundColor: "{colors.tertiary-container}"
Valid component properties: `backgroundColor`, `textColor`, `typography`, `rounded`, `padding`, `size`, `height`, `width`.
Variants (hover, active, pressed) are expressed as separate component entries with a related key name.
### Consumer Behavior for Unknown Content
| Scenario | Behavior |
|:---------|:---------|
| Unknown section heading | Preserve; do not error |
| Unknown color token name | Accept if value is valid |
| Unknown typography token name | Accept as valid typography |
| Unknown component property | Accept with warning |
| Duplicate section heading | Error; reject the file |
## CLI Reference
### Installation
npm install @google/design.md
On **Windows**, quote the package name if your shell treats `@` specially (PowerShell, some terminals):
npm install "@google/design.md"
Or run directly (always resolves from the public npm registry):
npx @google/design.md lint DESIGN.md
On **Windows/PowerShell**, this direct form can produce no output (or open
`DESIGN.md` in your Markdown editor) because the `.md` suffix in the `design.md`
bin name collides with the Windows Markdown file association during command
resolution. Run the dot-free `designmd` alias instead — point `npx` at the
package with `-p`, then invoke `designmd`:
npx -p @google/design.md designmd lint DESIGN.md
The `designmd` shim resolves to the same entrypoint and works identically across
all platforms.
#### `npm error ENOVERSIONS` (“No versions available for @google/design.md”)
The CLI is published as `@google/design.md` on npm. `ENOVERSIONS` almost always means npm is not querying the public registry (custom `registry=` in `.npmrc`, a corporate mirror that has not synced this package, or a misconfigured `@google:registry` for the `@google` scope).
Check your effective registry:
npm config get registry
For a normal install from the internet it should be `https://registr
📌 定义视觉身份格式规范,让 AI 代理理解设计系统
一种用于向编码代理描述视觉身份的格式规范。DESIGN.md 赋予代理对设计系统持久、结构化的理解能力。