技能檔結構拆解

SKILL.md 是 /graphify 的大腦——它怎麼指揮 AI 助手,references/ 又裝了什麼
來源:graphify/skill.md · graphify/skill-opencode.md · graphify/skills/opencode/references/(8 篇)

先講清楚:skill 檔是「給 AI 助手看的指令」

Graphify 作為一個 Claude Code / OpenCode / Cursor 的 skill,它的「本體」其實是一份 SKILL.md——一份寫給 AI 代理看的操作手冊。當你在助手裡輸入 /graphify .,助手讀這份檔案,照著裡面的 ## What You Must Do When InvokedStep 0–9 一步步執行。

這份檔案的設計重點:

Frontmatter:兩個欄位決定一切

---
name: graphify
description: "Use for any question about a codebase, its architecture, file relationships, or project content — especially when graphify-out/ exists, where the question should be treated as a graphify query first. …"
---

這兩個欄位就是 skill 的「名片」——name 決定安裝資料夾名稱,description 決定助手何時認為該用這個 skill。Graphify 的 description 刻意很寬:任何程式碼庫問題都可能觸發。skillgen 的 platforms.toml 規定 description「PRESERVED VERBATIM per platform」——各平台保留同樣的 description。

SKILL.md 的主體:Step 0–9

核心流程是「What You Must Do When Invoked」之後的九個步驟(每個平台版本大同小異):

Step做什麼備註
Step 0GitHub URL / 多路徑 merge只在給了 URL 或多個路徑時執行
Step 1確保 graphify 已安裝檢查 graphify --version,缺就裝
Step 2偵測檔案graphify-out/.graphify_detect.json
Step 2.5影音轉錄只有偵測到 video 才跑
Step 3抽取實體與關係Part A AST(本機)+ Part B 語意(LLM,讀 extraction-spec.md
Step 4建圖、分群、分析、產出build + cluster + analyze + graph.html + GRAPH_REPORT
Step 4.5圖健康檢查唯讀完整性 gate
Step 5社群命名用設定好的後端自動取名
Step 6Obsidian vault + HTMLvault 是 opt-in
Steps 6b–8Wiki / Neo4j / FalkorDB / SVG / GraphML / MCP / benchmark只在對應 flag 出現時跑
Step 9存 manifest、更新成本、清理、報告收尾

檔案後段還有幾個「分流入口」:## For --update and --cluster-only## For /graphify query## For /graphify add and --watch## For the commit hook …——依照使用者的指令類型跳到對應章節。最後是 ## Honesty Rules

展開英文原文:What You Must Do When Invoked(Fast path)
**Fast path — existing graph:** Before doing anything else, check whether
`graphify-out/graph.json` exists. The expected location is
`graphify-out/graph.json` relative to the **current working directory**. If it
exists AND the user's request is a natural-language question about the
codebase (e.g. "How does X work?", "What calls Y?") AND NOT an explicit rebuild
command (`--update`, `--cluster-only`, or a bare path/URL): **skip Steps 1–5
entirely and jump straight to `## For /graphify query`.** Run
`graphify query ""` immediately. Do not run detect. Do not check
corpus size. Do not ask the user to narrow. The graph is already built — use it.

references/ 側車:8 篇參考檔(以 opencode 為例)

每個平台都有 graphify/skills/<platform>/references/,同一組 8 篇(部分平台內容因 hook 機制略異)。SKILL.md 裡 Load this when… 就是載入入口:

檔案什麼時候載入內容重點
query.md使用者對既有圖提問、跑 /graphify pathexplainBFS/DFS 兩種走訪模式選擇、graphify query CLI 或內建 NetworkX 走訪
extraction-spec.mdStep 3 Part B——語料有 doc/paper/image給語意子代理的完整 JSON schema prompt(verbatim 嵌入)
hooks.md要裝 post-commit hook 或接 CLAUDE.mdgraphify hook install 與 CLAUDE.md 整合
add-watch.md跑了 /graphify add--watchingest URL、watch 資料夾
update.md跑了 --update--cluster-onlydetect_incremental、只重抽變更檔案
exports.md傳了 export flag(--wiki/--neo4j/--svg…)各 export 步驟 + token benchmark
transcribe.mddetect 回報有 video 檔faster-whisper 轉錄 + god-node 領域提示
github-and-merge.md給了 GitHub URL 或要 merge 多個子資料夾graphify clone、跨 repo 合併

有趣的事實:query.md(13KB)是最大的一篇,extraction-spec.md(8KB)其次——這兩篇裝載了「怎麼查圖」與「怎麼抽取」的核心邏輯。

平台差異:以 OpenCode 為例

各平台的 skill 檔幾乎相同,差異在「always-on 機制」與「安裝位置」:

平台安裝位置always-on 機制
OpenCode~/.config/opencode/skills/graphify/SKILL.md(專案:.opencode/skills/…AGENTS.md + tool.execute.before plugin
Claude Code~/.claude/skills/graphify/SKILL.mdCLAUDE.md + PreToolUse hook
Codex~/.codex/skills/…AGENTS.md(hook 是刻意 no-op)
Cursor~/.cursor/skills/….cursor/rules/graphify.mdc(alwaysApply)

install.pyPLATFORMS 表可看到對應關係(如 opencode: skill_file: skill-opencode.md, skill_dst: .config/opencode/skills/graphify/SKILL.md)。

這些檔是「生出來的」

SKILL.md 與 references/ 都是 generated artifacts——真正的 source of truth 是 tools/skillgen/fragments/。人在 fragments 編輯,python -m tools.skillgen 重新渲染成各平台成品,--check 檢查有沒有 drift、--bless 更新 baseline。

所以「中文化技能檔」不應該直接改 SKILL.md:那會被 skillgen 的 byte-diff 檢查打回。本站的做法是「中文講解」,而不是翻譯可安裝的 skill——翻譯會破壞產出管線的 round-trip 一致性。想深入產出機制,見 程式碼對照 · skillgen

教學解說

SKILL.md 是 Graphify 的「大腦」——一份寫給 AI 代理看的操作手冊。它的設計重點是「輕量核心 + 按需載入的 references」:SKILL.md 本身只講流程,細節放在 references/ 側車。

Fast path 是一個重要的優化:如果 graph.json 已存在且使用者問的是自然語言問題,直接跳過建圖、立刻跑 query。這讓「已建圖」的查詢變得非常快速。

所有 skill 檔都是 generated artifacts——真正的 source of truth 是 tools/skillgen/fragments/。這意味著不應該直接改 SKILL.md,而應該改 fragments 然後重新產生。

Worked Example:追蹤 skill 檔的產生流程

  1. 查看 fragments:瀏覽 tools/skillgen/fragments/ 目錄,查看原始片段。
  2. 執行 skillgen:執行 python -m tools.skillgen,觀察產生的各平台 SKILL.md。
  3. 比較差異:用 --check 檢查有沒有 drift(python -m tools.skillgen --check)。
  4. 更新 baseline:如果修改了 fragments,執行 --bless 更新 baseline。
關鍵觀察:各平台的 skill 檔幾乎相同,差異在「always-on 機制」與「安裝位置」。

常見錯誤與診斷

錯誤訊息原因解決方式
skillgen: drift detectedSKILL.md 與 fragments 不同步執行 python -m tools.skillgen 重新產生
skill: not foundskill 未安裝到正確位置執行 graphify install --platform opencode
references: load failedreferences/ 目錄缺失重新安裝 skill 或手動複製 references/
description: too longdescription 超過平台限制縮短 description 或使用更精確的關鍵字

練習與驗收清單

① 進階真實情境 Worked Example:fork 一份 graphify 並客製化自家 skill 的完整循環

前面的 Worked Example 是「追蹤產出流程」;這次是真的動手客製:你的公司要把 graphify 調成「只支援特定語言 + 中文 report + 自家 MCP 後端」,正確的改法是從 fragments 下手。

  1. fork 與環境:clone 上游、裝依賴、確認 python -m tools.skillgen --check 在乾淨狀態 exit 0(baseline 一致)。
  2. 改 fragments:編輯 tools/skillgen/fragments/ 下的對應片段(例如在 core 的 Step 3 加「只抽取下列語言的清單」、把 report 範本改中文)——不要碰已產生的 SKILL.md
  3. 重新產生python -m tools.skillgen 重渲染所有平台;再用 --audit-coverage 驗證你改的 host 每個 heading 仍「單一居住」在它的渲染裡。
  4. 更新 baselinepython -m tools.skillgen --bless 寫進 expected/,再 commit fragments + 產物 + baseline 三者。
  5. 安裝驗證graphify install --platform opencode 裝到 ~/.config/opencode/skills/graphify/,實測 /graphify 觸發後行為符合預期。
為什麼選這條路徑:skill 檔是 generated artifact,直接改 SKILL.md 會讓 byte-diff 檢查抓狂、且下次 python -m tools.skillgen 就把你的修改洗掉。從 fragments 改,你的客製才有「來源(fragments)→ 產物(SKILL.md)→ 驗證(check/audit)→ 安裝」的完整閉環,也能跟著上游 upgrade 而不衝突。

② 深入原理擴充:description 是「觸發器」,always-on 機制才是「保命符」

技能檔最容易被人低估的是「什麼時候會被載入」:

大家以為建圖正確、但其實有誤的案例:以為「裝好 skill 就等於接好 hook」。安裝(把檔案放對位置)與「啟用 always-on」是兩回事:例如 OpenCode 的 tool.execute.before plugin 要另行配置、Cursor 的 .mdc 要在 rules 設定 alwaysApply——缺了其中一環,skill 檔案都在,但 agent 不會在該觸發時載入,只在你手動輸入 /graphify 時才跑。檢查「skill 有沒有真的常駐」的最快方法:直接問 agent 一個 codebase 問題,看它是否自動先讀圖。

③ 診斷式疑難排解表

症狀可能原因解決方案
助手對 codebase 問題不自動用 graphifyalways-on 機制沒啟用(hook 未裝、plugin 沒設)照 platform 對照表補上 hook/AGENTS.md/.mdc;用「問問題看是否自動讀圖」驗證
skillgen --check 一直 exit 1有人直接改了 SKILL.md 或 fragment 改了沒重產執行 python -m tools.skillgen 重產;確認之後 --check
換機後 skill 不見裝在 user scope(~/.config/opencode)且未備份 / 專案 scope 沒進 repo決定 scope(user vs project)並把 project scope 的 skill 檔 commit;user scope 用安裝 script 重裝
skill 版本比套件新、安裝被拒絕skill 已更新而 pip 套件停在舊版(issue #1568)升級套件而非降級 skill——pip install -U graphify
references 側車載入失敗references/ 目錄遺失或部分檔案缺失重新 graphify install 或從 repo 複製;確認 query.md(13KB)等大檔完整

④ 進階挑戰題

  1. description 要「寬到觸發、窄到不誤觸」。給你一個專案:只處理「Java + SQL 的 legacy codebase」的 graphify,你會怎麼改 description 讓它在該觸發時觸發、在不相干問題上不誤觸?
  2. Codex 平台的 hook 是「刻意 no-op」。請推測這個決策的理由,並設計一個不靠 hook、純靠 AGENTS.md 達成「先讀圖再回答」的方案。
  3. 「Fast path」規定「不要 check corpus size、不要問使用者縮小範圍」。這條規則在什麼情況下會害你?如果要加一個例外條件,你會加在哪個判斷節點?

① 專案級端到端 Worked Example:從 fragments 到四平台安裝——skill 檔的完整生命週期

前面的 Worked Example 是客製化自家 skill。這次是完整的 skill 開發生命週期:你要為一個新的 AI agent 平台(假設叫「AgentX」)新增 graphify skill 支援,從 fragments 改動到安裝驗證。

  1. 分析 AgentX 的 hook 機制:AgentX 支援 AGENTS.md + PreToolUse hook(類似 Claude Code)。在 tools/skillgen/platforms.toml 新增 AgentX 的條目:skill 檔名、安裝路徑、hook 類型。
  2. 改 fragments:如果 AgentX 有特殊的 hook 語法,改 fragments/hooks.md 加 AgentX 的 hook 片段。不要碰已產生的 SKILL.md。
  3. 產生與驗證python -m tools.skillgen——確認 skills/agentx/SKILL.md 被正確產生。用 --audit-coverage 確認每個 heading 仍「單一居住」。
  4. 安裝測試graphify install --platform agentx——確認 skill 檔被放到 AgentX 的安裝目錄。手動測試 /graphify 觸發後的行為。
  5. 更新 baselinepython -m tools.skillgen --bless——把 AgentX 的產物寫進 expected/,確保下次 --check 不會误報 drift。
  6. 文件更新:在 README 的「支援平台」表格加 AgentX,附安裝路徑與 hook 機制說明。
關鍵觀察:各平台的 SKILL.md 幾乎相同(>95%),差異只在 hook 片段和安裝路徑。這就是「輕量核心 + 按需載入 references」的設計價值——改一次 fragments,四個平台同時更新。

② 效能/品質/安全深度

面向考量實務建議
效能SKILL.md 本身 ~8KB,references/ 總計 ~50KB;agent 每次觸發都要載入Fast path 是關鍵優化:graph.json 存在 + 自然語言問題 → 跳過建圖直接 query,省下全部 references 載入時間
品質skillgen 的 byte-diff 檢查確保 fragments 與 SKILL.md 同步;直接改 SKILL.md 會被打回python -m tools.skillgen --check 做 pre-commit hook;用 --audit-coverage 確認沒有 heading 重複
安全SKILL.md 的 description 決定「何時被觸發」——太寬會誤觸、太窄會漏觸description 保持「寬到觸發、窄到不誤觸」;platforms.toml 規定它「PRESERVED VERBATIM per platform」

③ 文件間比較對照表

面向本文(技能檔結構)相關文差異說明
Skill 流程Step 0-9 + Fast path + references/ 側車架構總覽架構頁講 pipeline 的七階段;技能檔頁講 agent 如何指揮 pipeline
平台差異四平台的安裝位置與 always-on 機制對照表程式碼對照 · skillgen程式碼對照頁講 tools/skillgen 的渲染管線與 --check 機制
references/8 篇參考檔的用途與載入時機運作原理運作原理頁講三遍處理,不涉及 skill 檔的 references 載入邏輯
Generated artifactsfragments → skillgen → SKILL.md 的產生管線增量更新增量頁講圖的增量更新;技能檔頁講 SKILL.md 的增量產生(drift check)

④ 互動式檢核清單