/design-system:story-auto-compile-migratefrom design-system
Batch-migrates design system components to Story Auto-Compile Phase 1+2 structure by adding tsx componentMeta exports and spec.md YAML frontmatter. Automatically parses cva variants, sizes, and tokens.
Ships in design-system. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
目的:把全部元件從 hand-written stories 遷到 auto-compile-able 結構(tsx componentMeta export + spec YAML frontmatter)。分「mechanical auto」+「evidence-bound judgment」兩層。元件總數由 Phase 0 inventory 動態計,禁止 hardcode。
不含:不改元件實作(cva / tsx logic 不動);不寫入 stories files。compile-stories.mjs 只在 stdout 編譯 canonical rows並驗 drift;本 skill 只加 metadata。
/design-system-audit --deep Dim 23 發現未 migrated 元件後自動 chain/new-component 時 Phase X 自動跑(未來延伸)node scripts/compile-stories.mjs --all 2>&1 | grep "Skipped"
得清單(default 模式 Skipped(N): 行):每元件 {Name}(reason: no componentMeta export | no frontmatter)。(--check 模式只印 drift / skipped 總數,不含 per-component reason。)
Output:待 migration 元件清單 + 每元件缺哪層(tsx only / spec only / 兩層都缺)。
對每元件:
componentMeta export從 tsx cva 讀:
variants keys → componentMeta.variants = { [key]: {} }(purpose 空)size variants keys → componentMeta.sizes = { [key]: {} }(fieldHeight/icon/typography 空,待 Phase 2 填)defaultVariants → defaultVariant / defaultSizestates 預設 ['default', 'hover', 'active', 'focus-visible', 'disabled'](元件無互動則改)tokens — grep tsx 的 --* token usage 自動列,或留 { bg: [], fg: [], ring: [] } 待 Phase 2 填family — 讀 spec 第一段 Layout Family 宣告插入位置:tsx 檔案 export { Component, ... } 之前。
插到 spec.md 頂部(H1 之前):
---
component: {Name}
family: {N from spec Layout Family declaration}
variants:
{key}:
when: "TODO: Phase 2 填"
world-class: [] # TODO: Phase 2 填 ≥ 3 家對照
# ... (mirror tsx.componentMeta.variants keys)
sizes:
{key}: { when: "TODO: Phase 2 填" }
禁止事項: # 從 spec 「禁止事項」section 自動 extract,若有
- rule: "..."
reason: "..."
反例: "..."
related:
近親: [] # TODO: Phase 2 填
SSOT-anchor: "{name}.spec.md"
---
compile-stories {Name} --checkPhase 1 output:N 元件成功 mechanical migrated / M 元件遇特殊 cva 邏輯需 Phase 2 手動 mapping。
記錄並回報:
Phase 1 完成:
- ✅ {N} 元件 mechanical migrated(componentMeta + frontmatter placeholders in,compile --check passed)
- ⚠️ {M} 元件 needs manual cva mapping(列出 + 原因)
- TODO: {N+M} 元件 frontmatter 的 variants[].when / world-class[] / sizes[].when / related[] 是 judgment 欄位,Phase 2 填
Authority:ENGINEERING-AUTO;直接進 Phase 2。只有填值會創造新的產品/UI/UX SSOT 語意且仍有真取捨才列 human-only decision。
對每個 migrated 元件:
variants[].when — 從 spec 現有「variants」section 或近親元件同名 variant 抄variants[].world-class — 讀 benchmarks/ 外部 snapshot,或 inline grep 既有 spec 對照sizes[].when — 從 spec size table 抄related.近親 — grep SSOT reciprocal pointers每元件過 owning-spec、benchmark、cross-field consistency 與 compile check;工程 mapping 自主收斂。若現有 SSOT 無法回答且選擇會改產品/UI/UX語意,集中成一次 human-only decision,不逐元件詢問。
node scripts/compile-stories.mjs --all --check
必 0 drift。跑 npm run build:lib 確認 tsx export 無 break(設計系統本庫的 tsc -b 不檢查 DS 原始碼)。
Commit 每批 5-10 元件一個(不一次全推,好 review)。
## Self-improvement capture
- 新發現 cva patterns: {特殊邏輯整理到 planning/story-auto-compile.md 供未來參考}
- Mechanical migration 失敗 case: {列出 + 手動 workaround 紀錄}
- Migration 覆蓋率:{N migrated / total}(total = Phase 0 動態計 `ls -d packages/design-system/src/components/*/ | wc -l`)
確認 keys、source citations、input digest 與 rollback;receipt 不停止 execution。
禁止無證據套預設。每批後 agent review 5-10 element 產出;全部元件仍須 complete-bytes/protocol coverage,不取樣判全域完成。
Agent 依 public contract、owning spec、consumer evidence與 rollback 自行選出唯一工程方案;若方案會改 public component 的產品/UI/UX語意且存在真取捨才 STOP,否則不可把(a)修 cva/(b)metadata 特例/(c)skip 的工程選擇丟給 user。
| Flow | 誰做 |
|---|---|
| 偵測未 migrated | /design-system-audit --deep Dim 23 |
| 批次 mechanical migrate | 本 skill Phase 1 |
| Judgment fill | 本 skill Phase 2(CP 2) |
| Drift detection(已 migrated) | hook post_edit_dispatcher.sh → lib/_story_compile_drift.sh(原 check_story_compile_drift.sh folded)+ Dim 23 |
Chain:user 說「ds 完整 audit」→ /design-system-audit --deep Phase 1 跑 Dim 23 → 發現 N 未 migrated → 自動 chain 本 skill → mechanical migrate + evidence-bound judgment → 全 migrated + 0 drift;中途 report 只是 receipt。
governance/planning/story-auto-compile.md — historical 4-phase plan + current non-executable statusscripts/compile-stories.mjs — compile + verifypackages/design-system/ds-canonical/skills/story-writing/references/anatomy-standard.md — 6-story canonicalpackages/design-system/ds-canonical/skills/new-component/SKILL.md — 新建元件流程(本 skill 為已建元件 migration)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub ajenchen/design-system --plugin design-system27 skills in this plugin
/bug-fix-rhythmBatch-end-verify rhythm + parallel tool batch + user-listed N-rule MUST-ALL + claim runtime verify. Invoke when entering multi-fix session 或 user 列 numbered rules. Replaces M32(c)(d)(h1)(h2) sub-invariants(2026-05-12 split per Knowledge-Prune Checkpoint 2)。/canonical-reviewerReview governance changes in an isolated read-only context with explicit author identity, complete canonical evidence, and mutation detection./code-quality-auditClean code 量化稽核 — `any` 使用 / dead export / file size / long function / circular dep / magic number。補 `/design-system-audit` 只管「design canonical」的缺口。Invoke via /code-quality-audit scope=all(release / 季度)OR scope=changed(daily)OR scope=component:X(focused)。Auto-chain by `/design-system-audit --deep` Dim 27 + `/component-quality-gate` Ship phase + `/new-component` Phase 4.5。