這篇教學的每一條指令都來自本站在 RTX A6000 48 GB 工作站 上實際錄下的終端機過程(2026-11-05 的版本,commit 663e6d943b66),照順序做即可。
開始前
我們在一台配備 NVIDIA RTX A6000 (48 GB) 的 Linux 工作站上進行測試,作業系統為 Ubuntu 24.04 (Kernel 7.0.0-38-generic)。環境需準備 Python 3.12.3、Node.js v22.23.4 以及 uv 0.11.2。由於 GitNexus 是 TypeScript 專案且全程在地執行,不需要雲端 API 金鑰。根據我們的測試,GitNexus 原始碼目錄大小約 379M,建議預留足夠的磁碟空間以容納工具本身及索引產生的資料。
安裝與執行
步驟 1:取得 GitNexus 原始碼
從 GitHub 複製指定 commit 的 GitNexus 原始碼到本地工作目錄,以便後續安裝或參考。
git clone https://github.com/abhigyanpatwari/GitNexus GitNexus cd GitNexus
成功時會看到:終端機顯示 commit 編號 '663e6d9'、日期 '2026-11-05' 及提交訊息,並列出專案目錄結構。(這一步我們花了 2.4 秒,結束碼 0)
DoD.md RUNBOOK.md eslint.config.mjs SECURITY.md eslint-rules skills.mdm eval TESTING.md gitnexus type-resolution-roadmap.md gitnexus-claude-plugin type-resolution-system.md
步驟 2:全域安裝 GitNexus CLI
透過 npm 全域安裝 gitnexus 套件,使其成為系統可用的命令列工具。
npm install -g --prefix "~/lab/npm" --prefix "~/lab/npm" gitnexus && gitnexus --version
成功時會看到:安裝過程顯示 'added 23 packages',最後執行 gitnexus --version 顯示版本號 '1.6.12'。(這一步我們花了 94.4 秒,結束碼 0)
$ npm install -g --prefix "$LAB/npm" --prefix "$LAB/npm" gitnexus && gitnexus --version added 23 packages, and changed 234 packages in 2m ⠇ ⠇69 packages are looking for funding ⠇ run `npm fund` for details ⠇1.6.12
步驟 3:準備測試專案
下載一個中型 Python 專案 (pallets/click) 作為索引對象,驗證工具對非自身專案的分析能力。
git clone https://github.com/abhigyanpatwari/GitNexus GitNexus cd GitNexus
成功時會看到:終端機顯示 'Python 檔案數 91' 及目錄大小 '2.9M'。(這一步我們花了 1.4 秒,結束碼 0)
Python 檔案數 91 2.9M .
步驟 4:建立程式碼知識圖譜
執行 analyze 指令僅建立索引,將程式碼符號、調用關係轉換為圖譜資料,供後續查詢使用。
cd "~/lab/target" && gitnexus analyze --index-only 2>&1 | tail -40
成功時會看到:輸出顯示 'Repository indexed successfully',並列出統計數據如 '3,296 nodes | 6,253 edges'。(這一步我們花了 19.4 秒,結束碼 0)
…(前略) ":"callable-value-flow: candidate set exceeded the cap; no partial CALLS emitted"} Repository indexed successfully (13.0s) 3,296 nodes | 6,253 edges | 116 clusters | 245 flows /home/user/lab/notes/abhigyanpatwari-gitnexus/target
步驟 5:檢查索引狀態
確認索引是否成功寫入且與當前程式碼版本同步,確保資料新鮮度。
cd "~/lab/target" && gitnexus status
成功時會看到:狀態顯示 'Status: ✅ up-to-date',並列出索引時間、Commit 編號及覆蓋檔案數。(這一步我們花了 0.8 秒,結束碼 0)
Branch: main Indexed: 2026/11/5 下午10:57:28 Indexed commit: 2247b35 Current commit: 2247b35 Index content: matches all 154 covered file(s) Status: ✅ up-to-date
步驟 6:自然語言查詢流程
使用自然語言描述功能,測試 GitNexus 能否從圖譜中檢索出相關的執行流程與符號。
cd "~/lab/target" && gitnexus query "parse command line arguments" 2>&1 | head -60
成功時會看到:輸出 JSON 格式的 'processes' 列表,包含 'summary' 如 'Get_completions → _split_opt' 及相關符號資訊。(這一步我們花了 0.8 秒,結束碼 0)
"step_index": 3
},
{
"id": "Method:src/click/parser.py:_OptionParser.parse_args#1",
"name": "parse_args",
"filePath": "src/click/parser.py",步驟 7:查詢特定符號
針對特定類別或函式名稱進行查詢,驗證圖譜對單一符號的關聯性分析。
cd "~/lab/target" && gitnexus query "Context" 2>&1 | head -40
成功時會看到:輸出包含 'Context' 相關的 processes,如 'Prompt → Get_current_context' 及其步驟數。(這一步我們花了 1.4 秒,結束碼 0)
"step_count": 5
},
{
"id": "proc_182_update",
"summary": "Update → Get_current_context",
"priority": 0.108,步驟 8:生成 AGENTS.md 指引
執行完整分析並強制更新,生成供 AI 代理使用的 AGENTS.md 檔案,定義如何與圖譜互動。
cd "~/lab/target" && gitnexus analyze --force 2>&1 | tail -12 && echo "---- 索引目錄 ----" && du -sh .gitnexus && echo "---- AGENTS.md ----" && head -60 AGENTS.md
成功時會看到:輸出顯示索引統計,並列出新生成的 AGENTS.md 內容開頭,包含 'Always Do' 與 'Never Do' 規範。(這一步我們花了 10.7 秒,結束碼 0)
| Blast radius / "What breaks if I change X?" | `.claude/skills/gitnexus-impact-analysis/SKILL.md` | | Trace bugs / "Why is X failing?" | `.claude/skills/gitnexus-debugging/SKILL.md` | | Rename / extract / split / refactor | `.claude/skills/gitnexus-refactoring/SKILL.md` | | Tools, resources, schema reference | `.claude/skills/gitnexus-guide/SKILL.md` | | Index, status, clean, wiki CLI commands | `.claude/skills/gitnexus-cli/SKILL.md` | <!-- gitnexus:end -->
步驟 9:列出已索引倉庫
確認系統中所有已建立索引的專案清單,驗證索引記錄是否正確保存。
gitnexus list
成功時會看到:顯示 'Indexed Repositories (1)',列出專案名稱 'click'、路徑、Commit 及統計數據。(這一步我們花了 0.1 秒,結束碼 0)
Indexed: 2026/11/5 下午10:57:41
Commit: 2247b35
Branch: main
Stats: 154 files, 3296 symbols, 6253 edges
Clusters: 116
Processes: 245確認裝好了
執行 gitnexus list 後,若看到專案名稱 'click' 及其對應的索引路徑、Commit 編號 (2247b35) 和統計數據(如 3296 symbols, 6253 edges),且 gitnexus status 顯示 'Status: ✅ up-to-date',即代表安裝與索引流程成功完成。
可能遇到的問題
1. 若索引過程中出現 'candidate set exceeded the cap' 警告,表示某些函式的調用候選過多,部分 CALLS 關係未完全發射,但不影響整體索引成功。
2. 若出現 'whole flows are MISSING' 警告,表示部分執行流程因深度或分支預算限制未被完整追蹤,這不代表程式碼路徑不存在。
接下來
安裝完成後,您可以將生成的 AGENTS.md 檔案整合到 AI 代理的上下文中,讓代理能透過 MCP 或 CLI 指令進行影響分析 (impact)、變更檢測 (detect-changes) 及符號重命名等操作,從而提升程式碼維護的準確性。

