/graphify 的大腦——它怎麼指揮 AI 助手,references/ 又裝了什麼graphify/skill.md · graphify/skill-opencode.md · graphify/skills/opencode/references/(8 篇)Graphify 作為一個 Claude Code / OpenCode / Cursor 的 skill,它的「本體」其實是一份 SKILL.md——一份寫給 AI 代理看的操作手冊。當你在助手裡輸入 /graphify .,助手讀這份檔案,照著裡面的 ## What You Must Do When Invoked 和 Step 0–9 一步步執行。
這份檔案的設計重點:
references/ 側車,需要時才載入。graphify-out/graph.json 已存在且使用者問的是自然語言問題,直接跳過建圖、立刻跑 graphify query。$(cat graphify-out/.graphify_python) 指定 Python 直譯器,避免用錯環境。---
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。
核心流程是「What You Must Do When Invoked」之後的九個步驟(每個平台版本大同小異):
| Step | 做什麼 | 備註 |
|---|---|---|
Step 0 | GitHub 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 6 | Obsidian vault + HTML | vault 是 opt-in |
Steps 6b–8 | Wiki / 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。
**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.
每個平台都有 graphify/skills/<platform>/references/,同一組 8 篇(部分平台內容因 hook 機制略異)。SKILL.md 裡 Load this when… 就是載入入口:
| 檔案 | 什麼時候載入 | 內容重點 |
|---|---|---|
query.md | 使用者對既有圖提問、跑 /graphify path 或 explain | BFS/DFS 兩種走訪模式選擇、graphify query CLI 或內建 NetworkX 走訪 |
extraction-spec.md | Step 3 Part B——語料有 doc/paper/image | 給語意子代理的完整 JSON schema prompt(verbatim 嵌入) |
hooks.md | 要裝 post-commit hook 或接 CLAUDE.md | graphify hook install 與 CLAUDE.md 整合 |
add-watch.md | 跑了 /graphify add 或 --watch | ingest URL、watch 資料夾 |
update.md | 跑了 --update 或 --cluster-only | detect_incremental、只重抽變更檔案 |
exports.md | 傳了 export flag(--wiki/--neo4j/--svg…) | 各 export 步驟 + token benchmark |
transcribe.md | detect 回報有 video 檔 | faster-whisper 轉錄 + god-node 領域提示 |
github-and-merge.md | 給了 GitHub URL 或要 merge 多個子資料夾 | graphify clone、跨 repo 合併 |
有趣的事實:query.md(13KB)是最大的一篇,extraction-spec.md(8KB)其次——這兩篇裝載了「怎麼查圖」與「怎麼抽取」的核心邏輯。
各平台的 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.md | CLAUDE.md + PreToolUse hook |
| Codex | ~/.codex/skills/… | AGENTS.md(hook 是刻意 no-op) |
| Cursor | ~/.cursor/skills/… | .cursor/rules/graphify.mdc(alwaysApply) |
從 install.py 的 PLATFORMS 表可看到對應關係(如 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 是 Graphify 的「大腦」——一份寫給 AI 代理看的操作手冊。它的設計重點是「輕量核心 + 按需載入的 references」:SKILL.md 本身只講流程,細節放在 references/ 側車。
Fast path 是一個重要的優化:如果 graph.json 已存在且使用者問的是自然語言問題,直接跳過建圖、立刻跑 query。這讓「已建圖」的查詢變得非常快速。
所有 skill 檔都是 generated artifacts——真正的 source of truth 是 tools/skillgen/fragments/。這意味著不應該直接改 SKILL.md,而應該改 fragments 然後重新產生。
tools/skillgen/fragments/ 目錄,查看原始片段。python -m tools.skillgen,觀察產生的各平台 SKILL.md。--check 檢查有沒有 drift(python -m tools.skillgen --check)。--bless 更新 baseline。| 錯誤訊息 | 原因 | 解決方式 |
|---|---|---|
skillgen: drift detected | SKILL.md 與 fragments 不同步 | 執行 python -m tools.skillgen 重新產生 |
skill: not found | skill 未安裝到正確位置 | 執行 graphify install --platform opencode |
references: load failed | references/ 目錄缺失 | 重新安裝 skill 或手動複製 references/ |
description: too long | description 超過平台限制 | 縮短 description 或使用更精確的關鍵字 |
前面的 Worked Example 是「追蹤產出流程」;這次是真的動手客製:你的公司要把 graphify 調成「只支援特定語言 + 中文 report + 自家 MCP 後端」,正確的改法是從 fragments 下手。
python -m tools.skillgen --check 在乾淨狀態 exit 0(baseline 一致)。tools/skillgen/fragments/ 下的對應片段(例如在 core 的 Step 3 加「只抽取下列語言的清單」、把 report 範本改中文)——不要碰已產生的 SKILL.md。python -m tools.skillgen 重渲染所有平台;再用 --audit-coverage 驗證你改的 host 每個 heading 仍「單一居住」在它的渲染裡。python -m tools.skillgen --bless 寫進 expected/,再 commit fragments + 產物 + baseline 三者。graphify install --platform opencode 裝到 ~/.config/opencode/skills/graphify/,實測 /graphify 觸發後行為符合預期。python -m tools.skillgen 就把你的修改洗掉。從 fragments 改,你的客製才有「來源(fragments)→ 產物(SKILL.md)→ 驗證(check/audit)→ 安裝」的完整閉環,也能跟著上游 upgrade 而不衝突。技能檔最容易被人低估的是「什麼時候會被載入」:
platforms.toml 規定它「PRESERVED VERBATIM per platform」——改一個平台就全部同步,避免觸發率不一致。tool.execute.before plugin、Claude Code 用 CLAUDE.md + PreToolUse hook、Cursor 用 alwaysApply 的 .mdc。Codex 的 hook 是刻意 no-op,只靠 AGENTS.md。tool.execute.before plugin 要另行配置、Cursor 的 .mdc 要在 rules 設定 alwaysApply——缺了其中一環,skill 檔案都在,但 agent 不會在該觸發時載入,只在你手動輸入 /graphify 時才跑。檢查「skill 有沒有真的常駐」的最快方法:直接問 agent 一個 codebase 問題,看它是否自動先讀圖。| 症狀 | 可能原因 | 解決方案 |
|---|---|---|
| 助手對 codebase 問題不自動用 graphify | always-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)等大檔完整 |
前面的 Worked Example 是客製化自家 skill。這次是完整的 skill 開發生命週期:你要為一個新的 AI agent 平台(假設叫「AgentX」)新增 graphify skill 支援,從 fragments 改動到安裝驗證。
tools/skillgen/platforms.toml 新增 AgentX 的條目:skill 檔名、安裝路徑、hook 類型。fragments/hooks.md 加 AgentX 的 hook 片段。不要碰已產生的 SKILL.md。python -m tools.skillgen——確認 skills/agentx/SKILL.md 被正確產生。用 --audit-coverage 確認每個 heading 仍「單一居住」。graphify install --platform agentx——確認 skill 檔被放到 AgentX 的安裝目錄。手動測試 /graphify 觸發後的行為。python -m tools.skillgen --bless——把 AgentX 的產物寫進 expected/,確保下次 --check 不會误報 drift。| 面向 | 考量 | 實務建議 |
|---|---|---|
| 效能 | 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 artifacts | fragments → skillgen → SKILL.md 的產生管線 | 增量更新 | 增量頁講圖的增量更新;技能檔頁講 SKILL.md 的增量產生(drift check) |
name 和 description 各自決定什麼(安裝目錄名 vs 觸發時機)--check 確認無 drift--audit-coverage 確認每個 heading 仍「單一居住」在它的渲染裡