src/installer — 多 agent 安裝器

新增一個 agent target = 一個新檔案 + registry 一列
檔案:src/installer/ · targets/registry.ts · 手刻 TOML serializer

大方向

安裝器是 codegraph install(與裸 codegraph / npx @colbymchenry/codegraph)的入口。架構刻意做成可擴充:targets/registry.ts 列所有 agent;targets/types.ts 定義 AgentTarget interface——加第 5 個 agent = targets/ 一個新檔 + registry 一個 entry。每個 target 自己負責它的 config 檔位置與 MCP-server JSON/TOML/JSONC 寫法。


AgentTarget / registry.ts src/installer/agent 支援清單與介面。

目前的 targets:claude.tscursor.tscodex.tsopencode.ts,加上 Hermes / Gemini CLI / Antigravity / Kiro / Copilot 三 surface。每個 target 實現偵測(agent 是否安裝)、config 路徑、MCP server 設定寫入與移除。codegraph install 的「問哪些 agent」就是列 registry 自動偵測。

教學重點:安裝器只接 agent、不索引程式——CLI 安裝、agent 設定、專案索引是三個獨立階段(對應 install.sh / codegraph install / codegraph init)。
targets/toml.ts src/installer/手刻 TOML serializer,只作用於 [mcp_servers.codegraph]。

Codex 用 TOML。為了不破壞使用者原本的設定,這個 serializer 只處理 [mcp_servers.codegraph],sibling tables 與 [[array_of_tables]] 原樣保留。不引入新 dependency。

opencode target(jsonc) src/installer/targets/opencode.tsopencode 讀 opencode.jsonc,用 jsonc-parser 做 surgical 編輯。

opencode 預設讀 opencode.jsonc:偏好既有 .jsonc、fallback .json、greenfield 建 .jsonc。編輯用 jsonc-parser 精準改——使用者的註解與排版在 install / re-install / uninstall round-trip 後存活。這是「絕不亂開實驗性 flag、不啟用 plugin、不信任第三方指令」原則的體現。

instructions 段落(marker-fenced) src/installer/在 CLAUDE.md / AGENTS.md / GEMINI.md 寫 marker-fenced 段落。

主 agent 收到 MCP initialize 的指引,但 sub-agent 與非 MCP harness 收不到——所以安裝器在每個 agent 的 instructions 檔寫入短 marker-fenced 段落,指向 codegraph explore CLI 對等指令。`codegraph uninstall` 可乾淨移除。Copilot target 目前不寫 instructions(MCP 指引已足夠)。

本站實測對照

本站是 opencode 使用情境——安裝 codegraph 時,opencode target 就是寫入 opencode.jsoncmcp_servers.codegraph 區塊。你也可以用 codegraph install --print-config opencode 只印設定不寫檔。

看完這頁你應該能說出:新增 agent 的檔案對應、Codex 的 TOML 為何手刻、opencode 的 jsonc 編輯為何要 surgical、以及 instructions 段落為什麼存在(sub-agent 看不到 MCP 指引)。