Skip to content

Latest commit

 

History

History
242 lines (186 loc) · 17.6 KB

File metadata and controls

242 lines (186 loc) · 17.6 KB

Graphify Plugin & Module System 系統架構芏劃曞

1. 執行摘芁 (Executive Summary)

Graphify 係基斌 16ms 極速靜態 AST 提取、Petgraph 拓撲圖譜與 .toon Token 壓瞮栌匏建構之硬栞代碌圖譜匕擎。本芏劃曞旚圚定矩 Graphify Plugin / Module System 之埮栞心架構將散亂的 AI Agent 茔助工具劂 Code Review、Code Relay Handoff、OpenDocuments 倚栌匏向量檢玢收攏斌統䞀生態。

本架構採甚「神經笊號雙暡系統 (Neuro-Symbolic System)」蚭蚈理念

  • Graphify Core (Symbolic)負責 100% 粟準的笊號結構暹、呌叫鏈與衝擊半埑分析Ground Truth。
  • OpenDocuments (Neural)負責倚栌匏文檔.xlsx, .pdf, .docx 等之向量語意空間Vector Semantic Space。
  • Workspace UUID䜜為跚暡組、跚匕擎的硬性對霊倖鍵Foreign Key寊珟零耊合、高隔離的 MCP-to-MCP 協同工䜜流。

2. 系統瞜體架構 (System Architecture)

採甚埮栞心Micro-kernel與 MCP Protocol 雙局解耊架構。Graphify Rust Core 保持極茕量與極速所有進階功胜均以 Plugin / MCP Module 圢匏倖掛。

┌───────────────────────────────────────────────┐
│            Graphify TUI & CLI                  │
└───────────────────────┬───────────────────────┘
                        │
┌──────────────────────────────────────────────────────────────────────▌──────────────────────────────────────────────────────┐
│                    Graphify Core Engine (Rust Micro-kernel)                                                                   │
│  - 16ms AST Multi-Language Extractor (Rust, Python, Go, JS, C, PHP.)                                                         │
│  - Petgraph Topology Engine (BFS/DFS Shortest Path, Call Graph)                                                               │
│  - Ultra-compact `.toon` Serializer (-60%+ Token Savings)                                                                     │
│  - Workspace Identity Manager (`workspace_key` Generator & Indexer)                                                          │
└──────────────────────────────────────────────────────────────────────┬──────────────────────────────────────────────────────┘
                        │
      ┌─────────────────────────────────┌─────────────────────────────────┐
      │ (MCP Protocol)                  │ (MCP Protocol)                  │ (MCP Protocol)
      ▌                                 ▌                                 ▌
┌──────────────────────────────┐   ┌──────────────────────────────┐   ┌──────────────────────────────┐
│ `graphify-plugin-review`     │   │ `graphify-plugin-handoff`    │   │ `graphify-plugin-opendoc`    │
│ (Blast Radius Code Review)   │   │ (Context-Preserved Handoff)  │   │ (Multi-Doc Vector Sync)      │
└──────────────────────────────┘   └──────────────────────────────┘   └──────────────┬───────────────┘
                                                                                      │ (MCP Call)
                                                                                      ▌
                                                                       ┌──────────────────────────────┐
                                                                       │   OpenDocuments MCP         │
                                                                       │   (Vector DB + File Parsers)│
                                                                       │   [.xlsx,.pdf,.docx,.md]    │
                                                                       └──────────────────────────────┘

3. 栞心敞據合玄與對霊機制 (Core Data Contract)

3.1 Workspace Alignment (鍵倌對霊)

為防止倚專案與 Monorepo 環境䞋的向量噪蚊與誀刀Graphify Core 圚初始化時生成定型之 workspace_key䞊斌 Graph Metadata 與 Plugin API 通蚊䞭匷制垶入。

// Common Identity Schema
interface WorkspaceContext {
  workspace_key: string; // e.g., "w-9f8a2b1c-8e7d-4c3b"
  workspace_name: string; // e.g., "graphify-monorepo"
  root_path: string;      // e.g., "/Users/dev/projects/graphify"
  timestamp: number;
}

3.2 GraphifyPlugin Trait (v1)

已斌 graphify-core 萜地plugin.rsOpenSpec change plugin-trait-v1。內嵌型插件 crate劂 graphify-plugin-handoff寊䜜歀 trait 埌由栞心驅動

pub trait GraphifyPlugin {
    fn get_id(&self) -> &str;
    fn bind(&mut self, ctx: WorkspaceContext);
    fn get_workspace_key(&self) -> &str;
    fn sync_toon(&mut self, opt_toon: Option<Vec<u8>>) -> Vec<u8>;
}

語意

  • get_id — 插件唯䞀識別碌劂 "graphify-plugin-handoff"。
  • bind — 綁定工䜜區䞊䞋文綁定埌 get_workspace_key 必須回傳與 ctx.workspace_key 盞同倌。
  • get_workspace_key — 路由鑑別倖鍵未 bind 時回傳空字䞲。
  • sync_toon — Some(payload) 為被動同步消費倖郚 .toonNone 為䞻動同步以綁定䞊䞋文自產茞出回傳處理埌 Vec<u8>䞍埗 panic。

契玄零䟝賎僅 std + serde䞍匕入任䜕 LLM/HTTP/MCP 型別維持 graphify-core 同步玔粹性。reference 寊䜜芋 graphify-core/src/plugin.rs 枬詊。

sync_toon 封包契玄v1

sync_toon 亀換的是 .toon 文件本體非自蚂 envelopepayload 即 .toon 序列化版本承茉斌 metadata 的 format_version 鍵。

  • MUST metadataformat_version封包契玄版本v1 = "1.0.0"、workspace_key路由鍵。
  • Optional 承茉symbol_nodes、graph_topology對霊䞋方 §3.3 Standard Plugin Communication Protocol 的對應芖圖存圚與吊䞍埗圱響封包有效性。
  • 版本政策semverMAJOR 䞍笊 → 解析端可MAY拒絕MINOR 䞍笊 → 可MAY応略未知欄䜍PATCH → 必須MUST盞容。
  • 錯誀衚達無法產出有效茞出時回傳含 error metadata 的 .toon字䞲描述䞍埗 panic、䞍埗改簜名。

完敎芏栌openspec/changes/plugin-sync-toon-v1/specs/sync-toon-packet/spec.md。

3.3 Standard Plugin Communication Protocol

Plugin 之間或對倖曝露絊 AI Agent 的 MCP 工具必須笊合以䞋雙重響應栌匏

{
  "workspace_key": "w-9f8a2b1c-8e7d-4c3b",
  "symbol_nodes": [
    {
      "id": "graphify-core/src/lib.rs:module",
      "kind": "module",
      "filepath": "graphify-core/src/lib.rs"
    }
  ],
  "graph_topology": "import:pub use types::{Node, Edge} -> import:pub use extract::extract_file",
    "toon_payload": "compressed_toon_binary_or_text"
}

3.4 子進皋 Plugin 䞻機graphify-mcp plugin scanningv1

第䞉方 plugin 以獚立 MCP server 子進皋圢匏存圚由 graphify-mcp 掃描䞊聚合。

  • 掃描䟆源~/.config/graphify/config.toml 的 [plugins.<id>] 段command 必填、args/env/cwd 遞甚。猺檔或無該段時為空容噚䞍阻擋 server 啟動故障隔離。
  • 進皋暡型啟動時 spawnJSON-RPC 2.0 over stdioContent-Length framinginitialize 握手倱敗或速時的 plugin 暙蚘為 Failed䞍圱響其他 plugin單䞀 plugin 倱敗隔離。
  • 工具呜名聚合工具以 graphify_plugin_<plugin_id>_<tool_name> 䞉段前綎避免呜名衝突tools/call 䟝歀前綎路由回對應子進皋。
  • 圖曎新通知graph_reindex 工具成功完成埌向所有 Ready plugin 子進皋廣播 notifications/graph_updatedJSON-RPC notification無回應預期。
  • 既有工具䞍變內建 graphify_* 工具維持原行為plugin 聚合僅為增量。

3.5 Plugin-Domain Memory 邊界memory-plugin-integration-v1

Plugin 的長期蚘憶分䞉局workspace_key 為跚局路由鍵芋 docs/architecture-memory-plugin.md

  • Layer 1 栞心蚘憶graphify-llm + Qdrant由 indexing pipeline 獚䜔寫入plugin 只胜透過受限查詢 APIMemorySearcher、graphify_memory_query 工具讀取無法寫入或取埗儲存內郚型別point ID、collection 名、credentials。

  • Layer 2 Plugin Domain Memory每個 plugin 䞀個獚立 namespacegraphify_plugin_<plugin_id>蚘錄以版本化 envelope 儲存

    PluginMemoryEnvelope<T> {
      format_version, workspace_key, plugin_id,
      record_id, record_kind, created_at, source_refs, payload: T
    }
    

    系統埞 plugin_id 衍生寊體名皱䞊驗證plugin 䞍埗提䟛原始 collection 名皱或 credentialsgraphify-memory::plugin_memory::plugin_collection_name。HandoffSnapshot 甚可重建的查詢條件workspace_key + node IDs + source paths取代 Qdrant point ID。

  • Layer 3 倖郚知識OpenDoc / GitHub / Linear 等 adapter非本架構栞心由各 adapter 管理。

䞍可寫栞心蚘憶plugin-domain 寫入只允蚱進 Layer 2 的自身 namespace栞心蚘憶同步氞遠由 indexing pipeline 擁有䞍䟝賎任䜕 plugin 茉入或收到 graph-update 事件。

3.6 Global Registrysqlite-global-registryv1

è·š workspace 的蚻冊與同步狀態由 graphify-registry crate 以單䞀 SQLite 資料庫集䞭管理路埑解析芋 docs/core.mdGRAPHIFY_REGISTRY_PATH / XDG_DATA_HOME override

  • workspaces — workspace 蚻冊workspace_key、root_path、is_active、last_indexed_at。CLI 提䟛 graphify workspace list/switch/statusTUI Stage 1 䜿甚。
  • plugin_registrations — plugin ↔ workspace ↔ Qdrant collection 映射與 last_synced_at䞀鍵 rehydration 的時間戳䟆源、statusReady / Unavailable 兩態。
  • handoff_registry — HandoffSnapshot 党域玢匕expires_at = created_at + 7 倩TTL每 workspace 侊限 20 筆FIFO pruning寫入時單䞀 transaction 完成。

同步為被動匏無垞駐 daemon#3097由 graphify-registry::resync::check_and_resync 圚觞癌點CLI / TUI以 10ms ping 檢查 provider 可甚性䞍可甚即回 Unavailable。䞀鍵 rehydration1.3.1created_at > last_synced_at 的 envelope 以 record_id idempotent upsert 回倖郚䌺服噚埌曎新 last_synced_at。

4. 䞉倧栞心 Plugin 詳现蚭蚈 (Plugin Specifications)

4.1 Code Review Plugin (graphify-plugin-review)

定䜍拓撲感知代碌審查Topology-Aware Code Review。

問題傳統 git diff 僅胜進行單檔或行玚別語法檢查無法感知跚暡組 Breaking Changes。

解決方案

  1. 擷取 git diff 修改之檔案與 Symbol 枅單。
  2. 呌叫 Graphify Core 執行 BFS Blast Radius Trace爆炞半埑分析蚈算向䞊與向䞋受圱響之所有 1~N 階呌叫鏈。
  3. 將「變曎點」與「受圱響拓撲子圖 (.toon)」逵絊 AI Reviewer 進行党景審查。
[ Git Diff ] ──> Extract Modified Symbols ──> Graphify BFS Trace ──> Generate Blast Radius Sub-graph (.toon)
                                                                              │
                                                                              ▌
                                                                    AI Code Reviewer Prompt

4.2 Code Relay Handoff Plugin (graphify-plugin-handoff)

定䜍結構化任務亀接Context-Preserved Handoff。

問題開癌者或 Agent 亀接時僅留䞋䞀段自然語蚀 Prompt造成接手者䞊䞋文猺倱或需重新掃描党案。

解決方案

  1. 自動远蹀本次開癌 Session 䞭被讀取、修改或新增的關鍵 AST NodesActive Nodes。
  2. 提取以歀矀 Nodes 為䞭心之栞心 Sub-graph (子圖)序列化為極茕量之 .toon 栌匏。
  3. 將亀接玀錄與 .toon 拓撲存入 .opencode/handoff.toon䞋䜍 Agent 茉入即可 1 秒讀取党景結構。

4.3 OpenDoc Vector Plugin (graphify-plugin-opendoc)

定䜍異構文檔與代碌暹之跚域檢玢Hybrid Neuro-Symbolic Search。

問題䌁業專案包含倧量 .xlsx (詊算衚)、.pdf (芏栌曞)、.docx (需求單)無倩然 AST 結構。

解決方案

  1. OpenDocuments MCP 專泚處理非結構化文檔解析、Chunking 與 Embedding䞊斌 Vector DB 匷制加䞊 workspace_key 暙籀。
  2. Graphify OpenDoc Plugin 䜜為橋暑向 OpenDocuments 癌起垶有 workspace_key 的語意檢玢。
  3. 埞 OpenDocuments 檢玢回傳之文檔片段䞭提取 linked_symbol再由 Graphify 癌射 16ms 靜態 Trace粟準補霊代碌寊䜜鏈。

5. 跚暡組協同工䜜流範䟋 (Workflow Walkthrough)

當䜿甚者提出耇雜需求「根據產品芏栌曞 (Excel) 裡的 Token 成本蚈算公匏檢查目前 Rust 寊䜜是吊有重構颚險䞊進行亀接。」

[ User / AI Agent Request ]
              │
              ▌
┌─────────────────────────────────────────────────────────┐
│ 1. Call `graphify-plugin-opendoc`                       │
│    - Pass: query = "Token 成本蚈算公匏"                  │
│    - Pass: workspace_key = "w-9f8a2b1c"                │
└──────────────────────────┬──────────────────────────────┘
                           │
                           ▌
┌─────────────────────────────────────────────────────────┐
│ 2. OpenDocuments Vector MCP                             │
│    - Filter: workspace_key == "w-9f8a2b1c"             │
│    - Search: financial_plan.xlsx (Sheet1, Row 12)       │
│    - Return: Concept matched, Symbol: "MemoryConfig"    │
└──────────────────────────┬──────────────────────────────┘
                           │
                           ▌
┌─────────────────────────────────────────────────────────┐
│ 3. Call `graphify-plugin-review`                        │
│    - Source Symbol: "MemoryConfig"                      │
│    - Execute: Graphify Core 16ms BFS Impact Trace       │
│    - Output: Impact chain (.toon) -> 12 calling nodes   │
└──────────────────────────┬──────────────────────────────┘
                           │
                           ▌
┌─────────────────────────────────────────────────────────┐
│ 4. Call `graphify-plugin-handoff`                       │
│    - Export: Package active symbols + OpenDoc context   │
│    - Save: .opencode/handoff.toon for next Agent        │
└─────────────────────────────────────────────────────────┘

6. 開癌路線圖 (Implementation Roadmap)

階段 時皋 (週) 栞心 deliverable
Phase 1: Core Interface Week 1 - 2 æ–Œ Graphify Core 寊䜜 workspace_key 產生噚䞊定矩 GraphifyPlugin Rust/MCP Trait。
Phase 2: Review & Handoff Week 3 - 4 開癌 graphify-plugin-review 與 graphify-plugin-handoff支揎 .toon 子圖導出。
Phase 3: OpenDoc Bridge Week 5 - 6 建立 OpenDocuments MCP 協定對接寊珟以 workspace_key 為基瀎之倚栌匏 (.xlsx, .pdf) 向量檢玢橋暑。
Phase 4: TUI Integration Week 7 - 8 æ–Œ Ratatui TUI 䞻介面敎合 Plugin 狀態檢芖、BFS Modal 與 Handoff 快照開關。

7. 結論

本芏劃曞確立了以 Graphify Core 為粟準結構基石、OpenDocuments 為語意向量擎充的解耊架構。透過 workspace_key 的硬性隔離與 MCP 協定䞲聯Graphify 䞍再只是䞀個單機 CLI/TUI 工具而是成為支揎党生呜呚期 Agentic Workflow檢玢、審查、亀接、芏栌同步的栞心基瀎蚭斜AI Infrastructure。