/design-system:governance-healthfrom design-system
Monthly governance health scan that reads Git-owned telemetry to detect dead hooks, hot files, Meta-Pattern candidates, stale memories, and pending corrections. Proposes rule upgrades or retirements without mutating policy. Complements /knowledge-prune.
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.
This canonical workflow contains a committed inventory of legacy assumptions. Resolve them exactly as follows; an unavailable resolution or inventory drift is ADAPTER-BLOCKED:
provider-identity: Treat historical provider names as provenance labels, never as the current runtime identity.provider-surface-path: Resolve legacy repository paths through generated views while treating ds-canonical as the semantic owner.目的:從 aspirational「會有大腦」升級到 operational 自我優化。/knowledge-prune 是季度深度重構;本 skill 是月度 metric scan + 自動提議 rule 升級 / retire 候選。
hook-fires.jsonl > 5MB → trigger/knowledge-prune)for NAME in hook-fires.jsonl hook-fires-per-hook.jsonl skill-invokes.jsonl user-corrections.jsonl metric-snapshots.jsonl; do
SAFE_FILE="$(node scripts/lib/governance-runtime-evidence.mjs --repo-root . --telemetry --path "$NAME")" || exit 2
[ ! -e "$SAFE_FILE" ] || ls -la "$SAFE_FILE"
done
GOVERNANCE_TELEMETRY_DIR="$(dirname "$(node scripts/lib/governance-runtime-evidence.mjs --repo-root . --telemetry --path hook-fires.jsonl)")"
resolver 只允許真實 Git directory 下的 governance-runtime/,並逐檔拒絕 escape/symlink/hardlink;禁止自行改讀 .claude、.codex 或 workspace runtime(唯一例外是 infra/governance/runtime/benchmarks/:Phase 1「Benchmark freshness」只讀其中的 last-fetch.txt,那是 governance/benchmarks/fetch.sh 寫的外部訊號快取、不是遙測;它的保留規則在 packages/design-system/ds-canonical/references/runtime-evidence-retention.md「Workspace runtime」)。若任一 log > 1MB → 提議由 canonical telemetry writer 實作受測 rotation,不能自行搬檔。無 log → Phase 0 回報「instrumentation 未 opt-in 或尚未積累 1-2 個月 baseline」,退出。
| Metric | Source | 判斷 |
|---|---|---|
| Hook fire count(per hook,6 月窗) | hook-fires-per-hook.jsonl(+ .jsonl.YYYYMM rotation 檔)或 npm run audit:hook-quality(產 hook-quality-report.json 含 fire_count_6mo/dead 分類);hook-fires.jsonl 記的是 governance-file 編輯軌跡(hot files 分析用),無 hook 名欄 | 0 fire = retire 候選;>50 fire = hot rule |
| Skill invoke count(per skill,3 月窗) | skill-invokes.jsonl(若存在) | 0 = dead;< 3 = under-used |
| User correction signals(per session) | user-corrections.jsonl count + sample | 總累積 > 20 = 需 codify |
| File size trend(weekly snapshot) | $GOVERNANCE_TELEMETRY_DIR/metric-snapshots.jsonl(若存在)裡 tag:"auto-daily" 列的 instruction_lines | repository instruction 增速 > 5 line/week = sprawl alert |
| Benchmark freshness(external) | infra/governance/runtime/benchmarks/last-fetch.txt | > 30 天 = 過期 |
| Infra-ref integrity(2026-05-30 加,根因防線) | node scripts/check-dangling-infra-ref.mjs + node scripts/check-skill-deadref.mjs(fail-open report) | bucket-B > 0(死 hook ref)OR removed-section/line-number ref > 0 OR product spec cite generated provider instruction adapter = infra-self drift → 提議 repoint。錨例:2026-05-30 抓 40 處死 hook ref + env-smoke set-e bug;2026-08-02 抓 33 specs / 41 refs authority drift |
| 判準化佔比 trend(2026-07-07 加,治理進化方向 1 KPI) | node scripts/audit-coverage-matrix.mjs(PURE-JUDGMENT / HOOK / DETERMINISTIC 三級計數) | PURE-JUDGMENT 佔比應逐月持平或降;連 2 月上升 = deep-audit C.0b 判準化 harvest 沒在跑 → flag。SSOT → governance/planning/2026-07-07-governance-evolution-roadmap.md |
四類 auto-propose:
規則 fire > 50 次 / 6 月 = 該 rule 反覆觸發 = 問題普遍 = 值得上升 Meta-Pattern layer 收斂(對齊 mindset #6「大原則吸收瑣碎」)。
Output: 「check_item_list_gap.sh 6 月 fired 78 次 → 提議擴充到 packages/design-system/ds-canonical/rules/meta-patterns.md M18?」
Hook 0 fire / 6 月 OR skill 0 invoke / 3 月 = 無 consumer = retire 候選。前提:audit:hook-quality 報告的 summary.observation.blind 必須是 false,且 skill log 涵蓋 3 個月;遙測預設關,全盲時零筆不是證據,不得提名(判法同 /knowledge-prune D2)。
Output: 「check_sideoffset_canonical.sh(retired;已移入 hooks/retired/,此為 dead-rule 偵測示例)6 月 0 fire → retire 候選(先 grep 全 repo 確認無 reference 才執行)」
user-corrections.jsonl 未 codify 數超過門檻 = user 反覆糾正類似錯誤,該升級到 canonical。
門檻不在本檔硬寫(同檔 Phase 2 表格曾寫 20、此處曾寫 10,兩個都會漂):唯一 SSOT 是
session_start_governance_check.sh Check 3 的 -gt 判斷(現行只有 hard 40 一條)。
Output: 「過去 4 週 user 糾正 15 條,sample: ..., 提議:升級 M19「XX pattern」或擴充 # Meta-Pattern 預警」
/knowledge-prune 掃描策略候選/knowledge-prune Phase 5 每次跑完在同一份 metric-snapshots.jsonl 寫一列 tag:"knowledge-prune"(含 retire_rate,行數欄位用 v3 的 instruction_lines)。每個日曆季取最後一列,看最近三季:
SNAP="$(node scripts/lib/governance-runtime-evidence.mjs --repo-root . --telemetry --path metric-snapshots.jsonl)" || exit 2
[ ! -f "$SNAP" ] || jq -Rsc --arg today "$(date -u +%Y-%m-%d)" '
def qi: (.[0:4] | tonumber) * 4 + (((.[5:7] | tonumber) - 1) / 3 | floor);
def qname: "\(. / 4 | floor)Q\(. % 4 + 1)";
(split("\n") | map(select(test("\\S")) | ((fromjson? // null) | if type == "object" then . else {bad: true} end))) as $all
| ($all | map(select(.tag == "knowledge-prune" and (.retire_rate | type) == "number"
and ((.ts | type) == "string") and (.ts | test("^[0-9]{4}-[0-9]{2}")))
| . + {qi: (.ts | qi)}) | group_by(.qi) | map(max_by(.ts)) | .[-3:]) as $r
| {
quarters: ($r | map({quarter: (.qi | qname), ts, retire_rate, instruction_lines})),
untagged_retire_rows: ($all | map(select(.tag != "knowledge-prune" and (.retire_rate | type) == "number")) | length),
unreadable_lines: ($all | map(select(.bad)) | length),
verdict: (
if ($r | length) < 3 then "資料不足:knowledge-prune 列不到三季"
elif $r[2].qi < ($today | qi) - 1 then "資料不足:最近一筆 knowledge-prune 列早於上一季"
elif $r[2].qi - $r[0].qi != 2 then "資料不足:三季不相連"
elif ($r | any((.instruction_lines | type) != "number")) then "資料不足:有列沒有 instruction_lines(舊欄位名口徑不同,不比)"
elif ($r | all(.retire_rate < 0.05)) and $r[2].instruction_lines > $r[0].instruction_lines then "提議換 /knowledge-prune 掃描策略"
else "不提議" end)
}' "$SNAP"
照 verdict 寫報告:
提議換 /knowledge-prune 掃描策略:三季相連、每季 retire_rate < 0.05、第三季的 instruction_lines 大於第一季 = 可能有隱性冗贅沒抓到 → 列進報告「掃描策略候選」,附三季數字。不提議:三季資料齊全,條件不成立。資料不足:…:照實寫「量不到」和缺什麼,不得寫成「沒問題」,也不得當成觸發(沒觀察到 ≠ 沒發生,M37)。untagged_retire_rows > 0 代表有帶 retire_rate、卻不是 tag:"knowledge-prune" 的列(舊格式)被排除;unreadable_lines > 0 代表有壞列。兩者都要寫進報告。# Governance Health Report — {YYYY-MM-DD}
## Metrics
| | 本月 | 前月 | Trend |
|--|------|------|-------|
| repository instruction 行數 | N | M | ↑/↓/→ |
| Hook fire total | N | M | ↑/↓/→ |
| Skill invoke total | N | M | ↑/↓/→ |
| Pending corrections | N | — | — |
| Benchmark freshness | X days | — | — |
## Retire 候選(auto-propose → engineering remediation queue)
- {hook/skill name} — 0 fire / N mo — rationale
- ...
## Meta-Pattern upgrade 候選(auto-propose)
- {rule name} — {fire count}/6mo — propose: 升級 M{N} 「...」
- ...
## Codify 候選(pending corrections)
- {topic} — {count} user corrections — propose: 擴充 AGENTS.md / `packages/design-system/ds-canonical/rules/meta-patterns.md` {section}
- ...
## 掃描策略候選(§2d)
- 近三季:{quarter} retire_rate {r} / instruction_lines {n} ×3 → {verdict}
- 排除的舊格式列 {untagged_retire_rows} / 壞列 {unreadable_lines}
## 外部 benchmark
- Last fetch: {date} ({days} days ago)
- 若過期 → 提議 run `bash governance/benchmarks/fetch.sh`
report 是 receipt,不是 approval milestone;完成後直接 routing:
/knowledge-prune報告尾加:
## Self-improvement capture
- 新發現 governance pattern: {...} OR "無"
- 新確立 monitoring rule: {...} OR "無"
- 修完的矛盾 / user 糾正: {list}
本 skill 保持 read-only,不直接 append telemetry。$GOVERNANCE_TELEMETRY_DIR/metric-snapshots.jsonl 有三個寫入者(另外兩個 skill 寫的 $GOVERNANCE_STATE_DIR/metric-snapshots.jsonl 是同一份檔:scripts/lib/governance-runtime-evidence.mjs 的 resolveProviderTelemetryStateRoot 與 hook 的 governance_runtime_state_dir 都解析到 GOVERNANCE_STATE_DIR,沒設就是 <real-git-dir>/governance-runtime/),各寫各的 tag、欄位不一樣。本 skill 讀欄位的兩處(Phase 1、§2d)一律先用 tag 篩選;不分 tag 的讀取只有一處,是下面 R3 的 24 小時去重:
stop_passive_logging.sh R3:trusted adapter 已明示 GOVERNANCE_TELEMETRY_OPT_IN=1 時寫 tag:"auto-daily" 列,欄位是 schema v3(距檔案最後一列不到 24 小時就不寫;它只讀最後一列的 ts,不看那列是哪個寫入者寫的):{"ts":"<UTC ISO 8601>","schema_version":"v3","tag":"auto-daily","instruction_lines":N,"memory_entries":N,"hooks_total":N,"skills_total":N,"untested_hooks":N,"last_prune_days_ago":N,"corrections_pending":N}
/knowledge-prune Phase 5:寫 tag:"knowledge-prune" 列(含 retire_rate,行數欄位用 v3 的 instruction_lines),由 §2d 讀。/codify-corrections Phase 4:寫 tag:"codify-corrections-run" 列(processed/p0/p1/p2,沒有行數欄位),Phase 1 與 §2d 都不讀。下次 Phase 1 對比 trend。
/knowledge-prune 分工| Skill | Cadence | Focus | Scope |
|---|---|---|---|
/governance-health | 月度 / auto-triggered | Metric-driven 自動提議(retire / upgrade / codify) | canonical governance files + Git-owned opt-in telemetry |
/knowledge-prune | 季度 / release cut | 深度結構重構(duplicate / dead / contradiction / over-concrete abstraction) | 同上 |
Chain 關係:/knowledge-prune --deep 可 auto-chain /governance-health 產 metric baseline,但 health 不自動 chain prune。
<real-git-dir>/governance-runtime/ — metric source;只能透過 canonical resolver 解析governance/benchmarks/ — provider-neutral fetch policy;infra/governance/runtime/benchmarks/ — disposable external signal cache# 治理 canonical — provider-neutral governance rules (本 skill 執行)What SKILL.md sets; muted values are Claude Code's defaults
27 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。Other plugins' skills for the same job
npx claudepluginhub ajenchen/design-system --plugin design-system