/design-system:codify-principlefrom design-system
Transforms a new design principle into 5-layer artifacts: SSOT canonical text, hook scaffold, audit dimension, scaffold update, and memory entry. Invoked when user states a new principle or uses trigger phrases like 'ensure X always'.
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.
User mandate「我說一條原則 → 自動轉化產生正確 artifacts 放正確位置」(2026-04-26)。本 skill 是 M19 ensure-canonical pipeline 的 generator 上層,接受 principle text 為 input,output 5-layer 完整落地。
/ensure-canonical 當 trigger 是「新原則」非「既有原則 enforce」User 提供 principle text。Skill 提取:
design-system-audit/references/rule-placement.md Level 1–9 taxonomy):
packages/design-system/ds-canonical/rules/ 或 references/ 哪個 canonical owner?*.spec.md 哪個元件?對 cross-component 原則(scope ≠ governance-only),強制 M8 ≥ 3 家世界級 DS 對照:
每 layer 產 draft + evidence,工程 mapping 不逐層等 user:
| Layer | Action |
|---|---|
| 1. SSOT canonical | 寫 markdown text 到對應 canonical home(packages/design-system/ds-canonical/rules/ / references/、spec.md 段);包含 rule + Why + How to apply + 世界級 anchor |
| 2. Spec frontmatter | 若 trait-like → 加入 traits: array OR 新增 frontmatter field |
| 3. Hook | 若 Absolute → scaffold packages/design-system/ds-canonical/hooks/check_{topic}.sh 含 P0/P1 detection logic + 7-Q self-check 模板,並更新 canonical registrations.json |
| 4. Audit dim | 加 dim N 到 packages/design-system/ds-canonical/skills/design-system-audit/SKILL.md + references/audit-prompts.md(periodic verify) |
| 5. Memory | 寫 governance/memory/project_{topic}_{date}.md + 更新 governance/memory/MEMORY.md index;provider cache 只由 npm run sync-memory 投影 |
每 layer 都記錄 review receipt:
Phase 3 Layer N draft ready:
{draft content}
Authority: ENGINEERING-AUTO | PRODUCT-UIUX-DECISION
Evidence / tests / rollback: {...}
若原則是「新元件 / 新 story 該滿足」 → 更新 /new-component Phase 5 scaffold + /story-writing Phase 0。
若 Layer 3 hook 建立 → scaffold packages/design-system/ds-canonical/hooks/tests/test_{topic}.sh 含 ≥ 5 smoke tests(silent skip / canonical compliance / drift block / rationale escape / per-trait verify)。Provider hook config/view 由 adapter materialize,禁止手改。
Per layer 一個 commit:
每 commit 後跑:
npm run build:lib(型別證明;tsc -b 在設計系統本庫不算)node scripts/audit-content-quality.mjs --check(防 content drift)## Self-improvement capture
- 新原則 SSOT home: {path}
- 新 hook: {filename} / fires on: {pattern}
- 新 audit dim: N
- 5-layer 落地完整度: {% layers actually shipped}
- 跳過的 layer + rationale: {if any}
更新 $GOVERNANCE_STATE_DIR/codified-principles.jsonl runtime log(lazy-create on first run;只在 trusted telemetry opt-in 且 state root 位於 Git-owned <git-dir>/governance-runtime/ 時建立;provider home 不得作 fallback):
{"date":"2026-04-26", "principle":"...", "scope":"...", "layers":["ssot","hook","audit","scaffold","memory"], "commits":[...]}
Scope / type / affected homes 是工程 mapping,由 agent 依 canonical 自行決定。只有原則文字本身對產品/UI/UX語意有多種合理解讀且會改 SSOT,才請 user 釐清。
< 3 家世界級對照 → 繼續 primary-source research,證據仍不足就不 codify 並明列 benchmark gap;只有 task/deliverable 明確要求 independent review 且 peer 證據不可得時才標 REVIEW-BLOCKED。只有 OG-only 是否成為產品/UI/UX原則的選擇交給 user,工程治理原則由 evidence + security/hard gates 決定。
每 layer 都過 tests/rollback check;task/deliverable 明確要求時才把 independent review 列為 required。工程 canonical substantive 直接執行,只有產品/UI/UX SSOT 真取捨停下。
任何 layer commit 後 tsc / hook test fail → 回該 phase 修,不繞過。
| Skill | Scope |
|---|---|
/ensure-canonical | 既有原則 enforcement(hook / audit 補強) |
/codify-principle(本) | 新原則 從 0 生成 5-layer artifacts |
/knowledge-prune | 反向:既有原則太多時 retire |
/design-system-audit | periodic verify 既有 artifacts compliance |
/codify-principle 是新原則 entry point;落地後其他 skill 接管 enforcement / verify / retire。
governance/memory/MEMORY.md — repository-owned index of codified principles(SSOT)$GOVERNANCE_STATE_DIR/codified-principles.jsonl — non-authoritative execution log(lazy-create on first run,見 Phase 7)packages/design-system/ds-canonical/skills/design-system-audit/references/rule-placement.md — home 識別 rulespackages/design-system/ds-canonical/rules/meta-patterns.md M14 / M19 — 上游 pipeline rulesUser 說:「我要加一條原則:所有 form-like 元件必須支援 controlled + uncontrolled dual-mode」
Skill 自動:
packages/design-system/ds-canonical/rules/ui-development.md「元件 Props 命名」 + form specpackages/design-system/ds-canonical/hooks/check_form_dual_mode.sh(未實作;此為 5-layer 產物範例 — audit-only via dim,無 write-time hook)偵測 missing pair/new-component Phase 4 加 dual-mode templateproject_form_dual_mode_2026_04_26.mdWhat SKILL.md sets; muted values are Claude Code's defaults
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。