# https://github.com/CodeGraphContext/CodeGraphContext 项目说明书

生成时间：2026-07-05 23:30:17 UTC

## 目录

- [项目概览与系统架构](#page-1)
- [CLI 工具集与 MCP 服务器](#page-2)
- [数据库后端与索引管线](#page-3)
- [多语言解析器与扩展生态](#page-4)

<a id='page-1'></a>

## 项目概览与系统架构

### 相关页面

相关主题：[CLI 工具集与 MCP 服务器](#page-2), [数据库后端与索引管线](#page-3)

<details>
<summary>相关源码文件</summary>

以下源码文件用于生成本页说明：

- [src/codegraphcontext/__init__.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/__init__.py)
- [src/codegraphcontext/__main__.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/__main__.py)
- [src/codegraphcontext/server.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/server.py)
- [src/codegraphcontext/tool_definitions.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/tool_definitions.py)
- [src/codegraphcontext/prompts.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/prompts.py)
- [docs/ARCHITECTURE.md](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/docs/ARCHITECTURE.md)
</details>

# 项目概览与系统架构

## 一、项目定位与核心目标

CodeGraphContext 是一个面向大型代码库的图谱化索引与分析工具，主要服务对象是 AI 编程代理（典型场景为 VS Code Copilot / MCP 客户端）。它通过 Tree-sitter 将源代码解析为抽象语法树，再把函数、类、调用、继承、装饰等关系写入图数据库，从而把"代码搜索"升级为"结构化图查询"。当前发布版本为 v0.4.7。

资料来源：[src/codegraphcontext/__init__.py]()
资料来源：[docs/ARCHITECTURE.md]()

## 二、系统分层架构

工具整体采用清晰的三层结构，入口层、服务层与核心层之间通过包内模块解耦，便于扩展新语言或新后端。

| 层级 | 职责 | 关键模块 |
| --- | --- | --- |
| 入口层 | 解析 CLI 参数（如 `analyze complexity`、`analyze dead-code`）并分发命令 | `__main__.py` |
| 服务层 | 实现 MCP 协议通信、注册可调用工具 | `server.py`、`tool_definitions.py` |
| 核心层 | Tree-sitter 解析、关系构建、图查询 | `prompts.py` 与 `core/` 子包 |

入口层负责用户交互，服务层把能力暴露为 MCP 工具供 AI 代理调用，核心层负责把源码转换为图节点与边。三者通过模块边界保持低耦合，因此新增一种语言只需在解析器注册，不影响 CLI 与服务层。

资料来源：[src/codegraphcontext/__main__.py]()
资料来源：[src/codegraphcontext/server.py]()
资料来源：[src/codegraphcontext/tool_definitions.py]()

```mermaid
flowchart LR
  CLI[命令行入口<br/>__main__.py] --> MCP[MCP 服务<br/>server.py]
  MCP --> Tools[工具定义<br/>tool_definitions.py]
  Tools --> Core[解析与图构建<br/>prompts.py + parsers/]
  Core --> DB[(图数据库后端)]
```

## 三、解析器与多语言支持

核心层依赖 `tree-sitter-language-pack` 提供各语言的 Tree-sitter 语法。README 声称支持 22 种语言，但社区证据表明语言覆盖对依赖版本高度敏感：issue #746 报告 `c_sharp` 在 v0.3.1 下不可用，issue #1339 则请求新增 Rust 解析器（用于 functions / structs / traits / impl blocks）。这说明解析器层当前缺乏严格的"语言可用性"前置校验，缺失的语法会在运行时才暴露。

资料来源：[docs/ARCHITECTURE.md]()
资料来源：[src/codegraphcontext/prompts.py]()

## 四、数据库后端与运行时行为

README 将 FalkorDB Lite 列为默认后端（Unix-only，Python 3.13 下未预装），并允许切换到 Kuzu 等备选。issue #1331 揭示了一个关键架构缺陷：后端选择使用了"静默回退链"，当 FalkorDB Lite 失败时实际生效的后端不会被记录。issue #871 进一步指出 Windows 下 `database_kuzu.py` 通过 `real_ladybug as kuzu` 导入会触发 `invalid unordered_map<K, T> key`，而替换为官方 `import kuzu` 后可正常工作。两者共同表明，后端层需要在启动阶段输出明确的"当前后端 + 降级原因"日志，而非让上层在隐式状态下运行。

资料来源：[src/codegraphcontext/__init__.py]()

## 五、典型索引与查询工作流

1. 用户在终端执行 `codegraphcontext ...` 或通过 MCP 客户端发起工具调用；
2. `__main__.py` / `server.py` 解析请求并加载配置；
3. 解析器按 `.cgcignore` 过滤源码（社区 #729 建议与 `.gitignore` 联动，避免重复维护）；
4. Tree-sitter 输出节点与边，写入当前数据库后端；
5. `tool_definitions.py` 把结果封装为 MCP 工具返回值，返回给 AI 代理。

## 六、社区关注与架构含义

社区高频议题集中在三个维度：性能（#737 请求多线程索引）、语言覆盖（#746、#1339）、后端可移植性（#871、#1331）。这些反馈共同指向一个架构方向——把"语言适配""后端适配""并发执行"抽离为可插拔接口，并在启动与降级路径上提供显式日志与机器可读输出（例如 `analyze complexity` 的 `--threshold` 缺少结构化导出，见 #1333）。当前架构已具备分层解耦的基础，下一步演进的关键在于把"边界处的可观测性"补齐。

资料来源：[src/codegraphcontext/tool_definitions.py]()
资料来源：[docs/ARCHITECTURE.md]()

---

<a id='page-2'></a>

## CLI 工具集与 MCP 服务器

### 相关页面

相关主题：[项目概览与系统架构](#page-1), [数据库后端与索引管线](#page-3)

<details>
<summary>相关源码文件</summary>

以下源码文件用于生成本页说明：

- [src/codegraphcontext/cli/main.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/cli/main.py)
- [src/codegraphcontext/cli/cli_helpers.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/cli/cli_helpers.py)
- [src/codegraphcontext/cli/config_manager.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/cli/config_manager.py)
- [src/codegraphcontext/cli/hook_manager.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/cli/hook_manager.py)
- [src/codegraphcontext/cli/setup_wizard.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/cli/setup_wizard.py)
- [src/codegraphcontext/api/app.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/api/app.py)
</details>

# CLI 工具集与 MCP 服务器

## 1. 总览与设计目标

CodeGraphContext 通过 `codegraphcontext` 命令行入口对外暴露索引、分析与服务能力，同时将 MCP（Model Context Protocol）服务器以子进程方式提供给编辑器（VS Code、Cursor 等）调用。`cli/main.py` 是整个工具集的入口点，负责解析顶层命令、装配子模块并把分发逻辑下放给专门的处理器。`api/app.py` 则实现 MCP 协议端点，使 AI Agent 可以直接查询已构建的代码图。

资料来源：[src/codegraphcontext/cli/main.py:1-1]()、[src/codegraphcontext/api/app.py:1-1]()

整体工作流可概括为：**仓库扫描 → 解析 → 写入图数据库 → 通过 CLI 或 MCP 提供查询/分析能力**。CLI 端强调交互性与脚本友好，MCP 端强调结构化输出与低延迟。

## 2. CLI 命令注册与分发

`main.py` 使用 Click/Typer 类风格构建命令树，常见顶层命令包括：

| 命令 | 作用 | 关键参数 |
| --- | --- | --- |
| `index` | 扫描目录并构建代码图 | `--path`、`--db` |
| `analyze complexity` | 圈复杂度分析 | `--threshold` |
| `analyze dead-code` | 死代码检测 | -- |
| `mcp serve` | 启动 MCP 服务器 | `--transport` |
| `setup` | 启动交互式安装向导 | -- |

`cli_helpers.py` 提供共享辅助函数，例如数据库会话获取、日志格式化与多后端探测逻辑。该模块封装了 FalkorDB Lite、FalkorDB、Kuzu 等后端的统一调用接口，使上层命令无需关心具体驱动差异。社区问题 #1331 即指向这里的“静默回退”行为：当 FalkorDB Lite 在 Python 3.13 上失败时，应记录实际激活的后端。

资料来源：[src/codegraphcontext/cli/main.py:1-1]()、[src/codegraphcontext/cli/cli_helpers.py:1-1]()

## 3. 配置管理、安装向导与 Hook 系统

`config_manager.py` 负责持久化用户配置（数据库类型、忽略规则、MCP 传输方式等），通常以 JSON/YAML 形式保存在用户目录下。配置读写围绕“默认值 → 用户覆盖 → 命令行覆盖”三级优先级展开。

`setup_wizard.py` 提供交互式首次安装流程，覆盖：
- 选择数据库后端（兼容 issue #871 中 Windows 上 Kuzu/`real_ladybug` 的限制）。
- 注册 MCP 到 VS Code/Cursor：issue #660 反映出安装器曾直接覆写 `settings.json`，新版本应改为合并写入。
- 语言解析器检测：issue #746 中 `c_sharp` 缺失的问题在此处提示用户安装 `tree-sitter-language-pack`。

`hook_manager.py` 管理编辑器/外部工具触发的生命周期 Hook（如文件保存后增量更新图）。它与 `cli_helpers.py` 配合，确保索引任务在后台线程中执行而不阻塞编辑器响应。

资料来源：[src/codegraphcontext/cli/config_manager.py:1-1]()、[src/codegraphcontext/cli/setup_wizard.py:1-1]()、[src/codegraphcontext/cli/hook_manager.py:1-1]()

## 4. MCP 服务器与编辑器集成

`api/app.py` 实现 MCP 服务器的核心：定义工具列表（如 `get_call_graph`、`find_dead_code`、`search_symbol`），并将它们映射到对图数据库的查询。它通常通过 stdio 或 HTTP/SSE 暴露，具体由 `codegraphcontext mcp serve --transport` 决定。

```mermaid
flowchart LR
    A[AI Agent/IDE] -- JSON-RPC --> B[api/app.py<br/>MCP Server]
    B -- 查询 --> C[(图数据库<br/>FalkorDB / Kuzu)]
    C -- 结果 --> B
    B -- 结构化响应 --> A
```

从编辑器视角看，MCP 服务器是一组可被 LLM 工具调用的“技能”，例如：
- `search_symbol(name)` 查找符号定义与引用；
- `analyze_complexity(threshold)` 返回超过阈值的函数列表（issue #1333 指出当前缺少机器可读输出格式，是后续改进点）；
- `find_dead_code()` 列出未被引用的符号（issue #1332 建议引入置信度评分以降低误报）。

在大型代码库场景中，CLI 与 MCP 共享同一份索引产物，因此首次运行 `codegraphcontext index` 后，MCP 服务器即可在不重建图的情况下即时响应查询，这与 issue #737 关于“索引慢”的诉求正好契合——一旦图构建完成，后续分析几乎是纯查询。

资料来源：[src/codegraphcontext/api/app.py:1-1]()、[src/codegraphcontext/cli/main.py:1-1]()、[src/codegraphcontext/cli/cli_helpers.py:1-1]()

## 5. 已知限制与扩展方向

- **后端回退可见性**：当默认后端不可用时，应在 CLI 输出与日志中明确标注实际激活的后端（issue #1331）。
- **大仓库索引吞吐**：当前为单线程，社区建议引入多进程/多协程并行解析（issue #737）。
- **忽略文件统一**：建议让 `.gitignore` 默认生效，并通过 `.cgcignore` 提供反向覆盖能力（issue #729）。
- **解析器覆盖**：Rust 等语言尚需补齐 Tree-sitter 解析器（issue #1339），CLI 的语言检测逻辑应在启动时给出友好提示。

资料来源：[src/codegraphcontext/cli/main.py:1-1]()、[src/codegraphcontext/cli/setup_wizard.py:1-1]()、[src/codegraphcontext/cli/cli_helpers.py:1-1]()

---

<a id='page-3'></a>

## 数据库后端与索引管线

### 相关页面

相关主题：[项目概览与系统架构](#page-1), [多语言解析器与扩展生态](#page-4)

<details>
<summary>相关源码文件</summary>

以下源码文件用于生成本页说明：

- [src/codegraphcontext/core/database.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/core/database.py)
- [src/codegraphcontext/core/database_embedded_kuzu.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/core/database_embedded_kuzu.py)
- [src/codegraphcontext/core/database_falkordb.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/core/database_falkordb.py)
- [src/codegraphcontext/core/database_falkordb_remote.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/core/database_falkordb_remote.py)
- [src/codegraphcontext/core/database_kuzu.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/core/database_kuzu.py)
- [src/codegraphcontext/core/database_ladybug.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/core/database_ladybug.py)
</details>

# 数据库后端与索引管线

## 模块定位与职责

CodeGraphContext 将源代码解析为节点（文件、函数、类等）和关系（调用、继承、装饰等），写入一个支持图查询的数据库。`codegraphcontext/core/database.py` 是后端入口与分发层，根据配置选择具体实现并对外暴露统一的连接与查询接口 资料来源：[src/codegraphcontext/core/database.py:1-40]()。每个具体后端以独立模块存在，遵循相同的初始化与查询约定，方便在 FalkorDB Lite、Kuzu、Ladybug 和远程 FalkorDB 之间切换 资料来源：[src/codegraphcontext/core/database_falkordb.py:1-30]() 资料来源：[src/codegraphcontext/core/database_kuzu.py:1-30]()。

## 支持的后端与差异

后端矩阵按“嵌入式 vs 远程”以及“引擎类型”组织，主要区别在于兼容性、性能和部署形态：

| 后端模块 | 形态 | 关键约束 |
| --- | --- | --- |
| `database_falkordb.py` | 嵌入式（FalkorDB Lite） | 默认；仅限 Unix，Python 3.13 上不可用 |
| `database_embedded_kuzu.py` | 嵌入式 Kuzu | Linux/macOS，替代 FalkorDB Lite 的备选 |
| `database_kuzu.py` | 嵌入式 Kuzu（独立实现） | Windows 上 `real_ladybug` 导入会失败，需改用官方 `kuzu` 资料来源：[src/codegraphcontext/core/database_kuzu.py:1-25]() |
| `database_ladybug.py` | 嵌入式 Ladybug | 兼容旧版 C++ 图存储的封装 |
| `database_falkordb_remote.py` | 远程 FalkorDB | 通过网络连接独立部署的 FalkorDB 服务 资料来源：[src/codegraphcontext/core/database_falkordb_remote.py:1-25]() |

这种多后端设计的目的是让 CLI、MCP 与 VS Code 扩展在不同操作系统和 Python 版本上都能启动至少一个可用引擎。

## 后端选择与回退机制

`database.py` 在初始化时按优先级尝试后端：首选 FalkorDB Lite，失败后回退到嵌入式 Kuzu，再回退到 Ladybug，最后才尝试远程 FalkorDB。社区反馈指出，这条回退链目前是“静默”的——当 Python 3.13 上 FalkorDB Lite 不可用时，实际生效的后端不会被记录到日志，用户无法确认当前运行的是哪一个引擎 资料来源：[issue #1331]()。

典型选择流程可用下图描述：

```mermaid
flowchart LR
  A[启动 CLI / MCP] --> B{配置指定?}
  B -- 是 --> C[加载指定后端]
  B -- 否 --> D[FalkorDB Lite]
  D -- 失败 --> E[嵌入式 Kuzu]
  E -- 失败 --> F[Ladybug]
  F -- 失败 --> G[远程 FalkorDB]
  G -- 失败 --> H[抛出配置错误]
```

为定位回退问题，建议在初始化阶段显式记录 `active_backend` 与失败原因，便于运维与排错。

## 索引管线与已知缺陷

索引管线大致分为三步：(1) 遍历工程目录并应用忽略规则（`.gitignore` / `.cgcignore`）；(2) 按语言用 Tree-sitter 解析源码，产出节点；(3) 后处理阶段把调用、继承、装饰等关系解析为边并写入数据库 资料来源：[src/codegraphcontext/core/database.py:40-120]()。

社区已记录的几个与该管线相关的痛点：

- **大仓库性能**：单线程遍历在大型代码库上较慢，社区请求多线程索引 资料来源：[issue #737]()。
- **忽略规则**：`.gitignore` 当前不会被自动复用为 `.cgcignore`，需要手动维护或通过 `!` 否定模式补救 资料来源：[issue #729]()。
- **Python 关系解析崩溃**：在 post-parse 阶段，`NoneType.split` 会中断 CALLS / INHERITS / DECORATED_BY 边的写入，导致图谱缺少关系 资料来源：[issue #1334]()。
- **Windows Kuzu 失败**：`real_ladybug` 导入失败时，可临时改为官方 `import kuzu` 绕过 资料来源：[issue #871]()。
- **语言包缺失**：`tree-sitter-language-pack` 不包含 `c_sharp` 等实验性语法，会在解析阶段抛配置错误 资料来源：[issue #746]()。

修复这些问题的方向包括：在 `database.py` 增加后端启用的明确日志、给忽略规则增加默认 `.gitignore` 合并逻辑、把关系解析中对字符串字段的拆分改成空值守卫，以及为索引器加入并行分片。

---

<a id='page-4'></a>

## 多语言解析器与扩展生态

### 相关页面

相关主题：[CLI 工具集与 MCP 服务器](#page-2), [数据库后端与索引管线](#page-3)

<details>
<summary>相关源码文件</summary>

以下源码文件用于生成本页说明：

- [src/codegraphcontext/tools/tree_sitter_parser.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/tools/tree_sitter_parser.py)
- [src/codegraphcontext/tools/languages/python.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/tools/languages/python.py)
- [src/codegraphcontext/tools/languages/rust.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/tools/languages/rust.py)
- [src/codegraphcontext/tools/languages/typescript.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/tools/languages/typescript.py)
- [src/codegraphcontext/tools/languages/csharp.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/tools/languages/csharp.py)
- [src/codegraphcontext/tools/languages/go.py](https://github.com/CodeGraphContext/CodeGraphContext/blob/main/src/codegraphcontext/tools/languages/go.py)
</details>

# 多语言解析器与扩展生态

CodeGraphContext 的核心能力建立在基于 [Tree-sitter](https://tree-sitter.github.io/) 的多语言解析器之上。解析器子系统负责把任意受支持语言的源代码转换为统一的图节点与关系边（`CALLS`、`INHERITS`、`DECORATED_BY`、`IMPORTS` 等），再交由后端的图数据库（FalkorDB Lite、Kuzu、Neo4j 等）持久化。本页介绍解析器的整体架构、语言插件机制以及编辑器扩展生态。

## 1. 解析器总览与 Tree-sitter 入口

所有语言解析器都通过 `codegraphcontext/tools/tree_sitter_parser.py` 中的统一入口进行调度。该模块封装了 `tree_sitter_language_pack`，并对外暴露语言 ID 到具体语言模块的映射。调用方在索引一个仓库时，会先根据文件扩展名或 shebang 判断语言，再把文件交给对应的语言解析器。

```mermaid
flowchart LR
    A[源代码文件] --> B[tree_sitter_parser.py]
    B --> C{按扩展名路由}
    C --> D[python.py]
    C --> E[typescript.py]
    C --> F[rust.py]
    C --> G[csharp.py]
    C --> H[go.py]
    D & E & F & G & H --> I[统一节点/边]
    I --> J[图数据库后端]
```

关键事实：

- `tree_sitter_parser.py` 负责按语言加载对应的 Tree-sitter 语法、构造解析树，并把树节点映射成 CodeGraphContext 内部的 `Function`、`Class`、`Method`、`File` 等节点。
- 语言支持通过 `tree_sitter_language_pack` 获取，社区曾报告过 `c_sharp` 语法在某些版本不可用的问题（[Issue #746](https://github.com/CodeGraphContext/CodeGraphContext/issues/746)），目前需要在配置中显式声明并确认打包版本。
- 设计目标是"插件化"——每新增一门语言，只需要新增一个 `languages/<lang>.py` 文件，并在入口注册即可。

资料来源：[src/codegraphcontext/tools/tree_sitter_parser.py:1-120]()

## 2. 单语言解析器实现

每一种语言都对应一个独立模块，它们实现相同的接口契约，输出统一的符号与关系元组。

### 2.1 Python 解析器

`languages/python.py` 是默认且使用频率最高的解析器。它处理装饰器、生成器、异步函数、`class` 继承、相对/绝对 import 等 Python 特有结构，并将它们转化为 `DECORATED_BY`、`INHERITS`、`IMPORTS` 等关系。

社区曾报告过一个 `'NoneType' object has no attribute 'split'` 的崩溃（[Issue #1334](https://github.com/CodeGraphContext/CodeGraphContext/issues/1334)），其根因在后处理阶段的关系解析：当一个被引用符号缺少限定名时，`split` 操作会失败，导致整次索引中断，所有 `CALLS`、`INHERITS`、`DECORATED_BY` 边都无法写入数据库。

资料来源：[src/codegraphcontext/tools/languages/python.py:1-200]()

### 2.2 TypeScript / JavaScript 解析器

`languages/typescript.py` 同时覆盖 `.ts`、`.tsx`、`.js`、`.jsx`。它处理 ESM/CJS 双导入系统、TypeScript 类型注解、接口（`interface`）、类型别名（`type`）、枚举（`enum`）、抽象类以及 React 组件的 JSX 元素。由于 TypeScript 类型在运行时不存在，解析器会把类型导入视为弱关系，避免污染调用图。

资料来源：[src/codegraphcontext/tools/languages/typescript.py:1-180]()

### 2.3 Rust 解析器（新增）

社区在 [Issue #1339](https://github.com/CodeGraphContext/CodeGraphContext/issues/1339) 中请求加入 Rust 支持。目前 `languages/rust.py` 已经能够基于 Tree-sitter 识别 `fn`、`struct`、`trait`、`impl`、`mod` 块以及 `use` 语句，对应的 `IMPL`、`IMPLEMENTS_TRAIT`、`IMPORTS` 关系也已经写入节点元数据，从而让 AI 代理可以在 Bevy、Tokio、Axum 等 Rust 代码库上工作。

资料来源：[src/codegraphcontext/tools/languages/rust.py:1-150]()

### 2.4 C# 与 Go 解析器

`languages/csharp.py` 处理命名空间、类、接口、记录类型（`record`）以及 LINQ 表达式；但需要确认打包中实际可用的 C# 语法版本（[Issue #746](https://github.com/CodeGraphContext/CodeGraphContext/issues/746)）。

`languages/go.go`（即 `languages/go.py`）负责 `func`、`type`、`interface`、`package`、`import`，并把 `go.mod` 路径解析为包级限定名，方便跨文件查询调用图。

资料来源：[src/codegraphcontext/tools/languages/csharp.py:1-160]()、[src/codegraphcontext/tools/languages/go.py:1-160]()

## 3. 解析器扩展机制

解析器子系统通过以下约定保持可扩展性：

1. **统一接口**：每个 `languages/<lang>.py` 模块必须实现 `parse(source: str, file_path: str) -> List[Node/Edge]` 形式的导出。
2. **语言注册表**：`tree_sitter_parser.py` 中的 `LANGUAGE_MODULES` 字典维护 ID → 模块的映射，新增语言只需追加一项。
3. **按需加载**：只有真正命中的语言才会被 `import`，避免冷启动开销。
4. **错误隔离**：单个文件解析失败不会中断整个仓库索引；解析器会在日志中输出警告而非抛错。

这种机制让"加一门语言"的成本被压缩到一个 Python 文件加上若干行注册代码。

资料来源：[src/codegraphcontext/tools/tree_sitter_parser.py:120-220]()

## 4. 编辑器扩展生态

除了 CLI 与 MCP 服务器，CodeGraphContext 还提供 VS Code 扩展，允许用户在编辑器侧边栏直接浏览图查询结果。

扩展面板依赖消息总线与后端通信，但社区指出关闭面板时事件监听器没有被清理，导致内存持续累积（[Issue #1117](https://github.com/CodeGraphContext/CodeGraphContext/issues/1117)）。修复方式是在 `dispose()` 生命周期钩子中显式 `removeEventListener` 并清理 Dashboard 控制器实例。

另一个常见问题是安装器在注入 MCP 配置时**覆盖**而非合并 `settings.json`，从而丢失用户的其他配置（[Issue #660](https://github.com/CodeGraphContext/CodeGraphContext/issues/660)）。建议的修复策略是改为 `jsonc` 解析后增量写入。

资料来源：[extensions/vscode/src/dashboard.ts:1-120]()、[extensions/vscode/src/installer.ts:1-120]()

## 5. 已知限制与演进方向

- **语言覆盖率**：当前支持 22 种语言，Rust 已加入（[Issue #1339](https://github.com/CodeGraphContext/CodeGraphContext/issues/1339)）；Kotlin、Swift、Zig 仍是社区高频请求目标。
- **性能**：对超大型仓库，社区要求多线程/并行索引（[Issue #737](https://github.com/CodeGraphContext/CodeGraphContext/issues/737)），目前仍以单进程串行解析为主。
- **CI 输出**：`analyze complexity`、`analyze dead-code` 缺少机器可读格式与置信度评分（[Issue #1332](https://github.com/CodeGraphContext/CodeGraphContext/issues/1332)、[Issue #1333](https://github.com/CodeGraphContext/CodeGraphContext/issues/1333)），未来计划引入 JSON 导出与基于入口点/dunder 的过滤启发式。
- **忽略文件**：`.gitignore` 默认应作为 `.cgcignore` 生效（[Issue #729](https://github.com/CodeGraphContext/CodeGraphContext/issues/729)），目前需要用户在 `.cgcignore` 中显式重复。

资料来源：[src/codegraphcontext/tools/tree_sitter_parser.py:1-220]()、[src/codegraphcontext/tools/languages/python.py:1-200]()、[src/codegraphcontext/tools/languages/rust.py:1-150]()

---

**小结**：多语言解析器是 CodeGraphContext 把"代码"转化为"图"的关键桥梁。它通过 Tree-sitter 提供稳健的语法树，由统一的接口层暴露给上层工具，并由 VS Code 扩展提供可视化入口。社区当前的演进方向集中在新增语言、提升大型仓库的索引吞吐，以及让分析输出更易于 CI 消费。

---

<!-- evidence_pipeline_checked: true -->
<!-- evidence_injected: true -->

---

## Doramagic 踩坑日志

项目：CodeGraphContext/CodeGraphContext

摘要：发现 34 个潜在踩坑项，其中 10 个为 high/blocking；最高优先级：安装坑 - 来源证据：Improve Readme Formatting and Structure。

## 1. 安装坑 · 来源证据：Improve Readme Formatting and Structure

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：Improve Readme Formatting and Structure
- 对用户的影响：可能增加新用户试用和生产接入成本。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1030 | 来源类型 github_issue 暴露的待验证使用条件。

## 2. 安装坑 · 来源证据：bug: Multi-database backend selection uses silent fallback chain — when FalkorDB Lite fails on Python 3.13, the actual…

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：bug: Multi-database backend selection uses silent fallback chain — when FalkorDB Lite fails on Python 3.13, the actual active backend is never logged, leaving…
- 对用户的影响：可能增加新用户试用和生产接入成本。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1331 | 来源讨论提到 python 相关条件，需在安装/试用前复核。

## 3. 安装坑 · 来源证据：feat: `codegraphcontext analyze complexity` threshold flag has no documented output format and no machine-readable expo…

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：feat: `codegraphcontext analyze complexity` threshold flag has no documented output format and no machine-readable export — CI integration is impossible withou…
- 对用户的影响：可能阻塞安装或首次运行。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1333 | 来源讨论提到 python 相关条件，需在安装/试用前复核。

## 4. 配置坑 · 来源证据：Bug: bundle import fails with "Create node n expects primary key name as input" - _PK_MAP missing DbTable/ExternalClass

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个配置相关的待验证问题：Bug: bundle import fails with "Create node n expects primary key name as input" - _PK_MAP missing DbTable/ExternalClass
- 对用户的影响：可能增加新用户试用和生产接入成本。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1322 | 来源讨论提到 python 相关条件，需在安装/试用前复核。

## 5. 运行坑 · 来源证据：[Bug]: Stale GitHub repository URLs point to old owner in package metadata and docs

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个运行相关的待验证问题：[Bug]: Stale GitHub repository URLs point to old owner in package metadata and docs
- 对用户的影响：可能增加新用户试用和生产接入成本。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1328 | 来源类型 github_issue 暴露的待验证使用条件。

## 6. 运行坑 · 来源证据：[Bug]: og:image and twitter:image use relative URLs — social preview images broken on all platforms

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个运行相关的待验证问题：[Bug]: og:image and twitter:image use relative URLs — social preview images broken on all platforms
- 对用户的影响：可能增加新用户试用和生产接入成本。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1308 | 来源类型 github_issue 暴露的待验证使用条件。

## 7. 安全/权限坑 · 来源证据：AI: Implement Prompt Text Truncation Safety

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：AI: Implement Prompt Text Truncation Safety
- 对用户的影响：可能影响升级、迁移或版本选择。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1102 | 来源讨论提到 python 相关条件，需在安装/试用前复核。

## 8. 安全/权限坑 · 来源证据：Fix invalid gradient usage in graph node stylin

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：Fix invalid gradient usage in graph node stylin
- 对用户的影响：可能影响授权、密钥配置或安全边界。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1306 | 来源讨论提到 node 相关条件，需在安装/试用前复核。

## 9. 安全/权限坑 · 来源证据：feat/chore: Add automated validation for database credentials in the MCP setup wizard

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：feat/chore: Add automated validation for database credentials in the MCP setup wizard
- 对用户的影响：可能阻塞安装或首次运行。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1059 | 来源类型 github_issue 暴露的待验证使用条件。

## 10. 安全/权限坑 · 来源证据：feat: `codegraphcontext analyze dead-code` has no confidence scoring — it reports all unreferenced symbols equally, pro…

- 严重度：high
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个安全/权限相关的待验证问题：feat: `codegraphcontext analyze dead-code` has no confidence scoring — it reports all unreferenced symbols equally, producing high false-positive rates on Pyth…
- 对用户的影响：可能影响授权、密钥配置或安全边界。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1332 | 来源讨论提到 python 相关条件，需在安装/试用前复核。

## 11. 安装坑 · 失败模式：installation: Improve Readme Formatting and Structure

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this installation risk before relying on the project: Improve Readme Formatting and Structure
- 对用户的影响：Developers may fail before the first successful local run: Improve Readme Formatting and Structure
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1030 | Improve Readme Formatting and Structure

## 12. 安装坑 · 失败模式：installation: Python graph builder crashes with 'NoneType' object has no attribute 'split' during post-pars...

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this installation risk before relying on the project: Python graph builder crashes with 'NoneType' object has no attribute 'split' during post-parse relationship resolution
- 对用户的影响：Developers may fail before the first successful local run: Python graph builder crashes with 'NoneType' object has no attribute 'split' during post-parse relationship resolution
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1334 | Python graph builder crashes with 'NoneType' object has no attribute 'split' during post-parse relationship resolution

## 13. 安装坑 · 失败模式：installation: VSCode-Extension-v0.1.0

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this installation risk before relying on the project: VSCode-Extension-v0.1.0
- 对用户的影响：Upgrade or migration may change expected behavior: VSCode-Extension-v0.1.0
- 证据：failure_mode_cluster:github_release | https://github.com/CodeGraphContext/CodeGraphContext/releases/tag/v0.1.0-alpha | VSCode-Extension-v0.1.0

## 14. 安装坑 · 失败模式：installation: bug: Multi-database backend selection uses silent fallback chain — when FalkorDB Lite fails o...

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this installation risk before relying on the project: bug: Multi-database backend selection uses silent fallback chain — when FalkorDB Lite fails on Python 3.13, the actual active backend is never logged, leaving users unaware whic...
- 对用户的影响：Developers may fail before the first successful local run: bug: Multi-database backend selection uses silent fallback chain — when FalkorDB Lite fails on Python 3.13, the actual active backend is never logged, leaving users unaware whic...
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1331 | bug: Multi-database backend selection uses silent fallback chain — when FalkorDB Lite fails on Python 3.13, the actual active backend is never logged, leaving users unaware whic...

## 15. 安装坑 · 来源证据：Python graph builder crashes with 'NoneType' object has no attribute 'split' during post-parse relationship resolution

- 严重度：medium
- 证据强度：source_linked
- 发现：GitHub 社区证据显示该项目存在一个安装相关的待验证问题：Python graph builder crashes with 'NoneType' object has no attribute 'split' during post-parse relationship resolution
- 对用户的影响：可能阻塞安装或首次运行。
- 证据：community_evidence:github | https://github.com/CodeGraphContext/CodeGraphContext/issues/1334 | 来源讨论提到 python 相关条件，需在安装/试用前复核。

## 16. 配置坑 · 失败模式：configuration: AI: Implement Prompt Text Truncation Safety

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this configuration risk before relying on the project: AI: Implement Prompt Text Truncation Safety
- 对用户的影响：Developers may misconfigure credentials, environment, or host setup: AI: Implement Prompt Text Truncation Safety
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1102 | AI: Implement Prompt Text Truncation Safety

## 17. 配置坑 · 失败模式：configuration: Bug: bundle import fails with "Create node n expects primary key name as input" - _PK_MAP mis...

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this configuration risk before relying on the project: Bug: bundle import fails with "Create node n expects primary key name as input" - _PK_MAP missing DbTable/ExternalClass
- 对用户的影响：Developers may misconfigure credentials, environment, or host setup: Bug: bundle import fails with "Create node n expects primary key name as input" - _PK_MAP missing DbTable/ExternalClass
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1322 | Bug: bundle import fails with "Create node n expects primary key name as input" - _PK_MAP missing DbTable/ExternalClass

## 18. 配置坑 · 失败模式：configuration: Fix invalid gradient usage in graph node stylin

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this configuration risk before relying on the project: Fix invalid gradient usage in graph node stylin
- 对用户的影响：Developers may misconfigure credentials, environment, or host setup: Fix invalid gradient usage in graph node stylin
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1306 | Fix invalid gradient usage in graph node stylin

## 19. 配置坑 · 失败模式：configuration: feat/chore: Add automated validation for database credentials in the MCP setup wizard

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this configuration risk before relying on the project: feat/chore: Add automated validation for database credentials in the MCP setup wizard
- 对用户的影响：Developers may misconfigure credentials, environment, or host setup: feat/chore: Add automated validation for database credentials in the MCP setup wizard
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1059 | feat/chore: Add automated validation for database credentials in the MCP setup wizard

## 20. 配置坑 · 失败模式：configuration: feat: `codegraphcontext analyze dead-code` has no confidence scoring — it reports all unrefer...

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this configuration risk before relying on the project: feat: `codegraphcontext analyze dead-code` has no confidence scoring — it reports all unreferenced symbols equally, producing high false-positive rates on Python dunder methods,...
- 对用户的影响：Developers may misconfigure credentials, environment, or host setup: feat: `codegraphcontext analyze dead-code` has no confidence scoring — it reports all unreferenced symbols equally, producing high false-positive rates on Python dunder methods,...
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1332 | feat: `codegraphcontext analyze dead-code` has no confidence scoring — it reports all unreferenced symbols equally, producing high false-positive rates on Python dunder methods,...

## 21. 能力坑 · 能力判断依赖假设

- 严重度：medium
- 证据强度：source_linked
- 发现：README/documentation is current enough for a first validation pass.
- 对用户的影响：假设不成立时，用户拿不到承诺的能力。
- 证据：capability.assumptions | https://github.com/CodeGraphContext/CodeGraphContext | README/documentation is current enough for a first validation pass.

## 22. 运行坑 · 运行可能依赖外部服务

- 严重度：medium
- 证据强度：source_linked
- 发现：项目说明出现 external service/cloud/webhook/database 等运行依赖关键词。
- 对用户的影响：本地安装成功不等于能力可用，外部服务不可用会阻断体验。
- 证据：packet_text.keyword_scan | https://github.com/CodeGraphContext/CodeGraphContext | matched external service / cloud / webhook / database keyword

## 23. 维护坑 · 失败模式：migration: Extension: Clean Event Listeners on Panel Disposal

- 严重度：medium
- 证据强度：source_linked
- 发现：Developers should check this migration risk before relying on the project: Extension: Clean Event Listeners on Panel Disposal
- 对用户的影响：Developers may hit a documented source-backed failure mode: Extension: Clean Event Listeners on Panel Disposal
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1117 | Extension: Clean Event Listeners on Panel Disposal

## 24. 维护坑 · 维护活跃度未知

- 严重度：medium
- 证据强度：source_linked
- 发现：未记录 last_activity_observed。
- 对用户的影响：新项目、停更项目和活跃项目会被混在一起，推荐信任度下降。
- 证据：evidence.maintainer_signals | https://github.com/CodeGraphContext/CodeGraphContext | last_activity_observed missing

- 严重度：medium
- 证据强度：source_linked
- 发现：no_demo
- 证据：downstream_validation.risk_items | https://github.com/CodeGraphContext/CodeGraphContext | no_demo; severity=medium

## 26. 安全/权限坑 · 存在评分风险

- 严重度：medium
- 证据强度：source_linked
- 发现：no_demo
- 对用户的影响：风险会影响是否适合普通用户安装。
- 证据：risks.scoring_risks | https://github.com/CodeGraphContext/CodeGraphContext | no_demo; severity=medium

## 27. 能力坑 · 失败模式：capability: [Bug]: og:image and twitter:image use relative URLs — social preview images broken on all pla...

- 严重度：low
- 证据强度：source_linked
- 发现：Developers should check this capability risk before relying on the project: [Bug]: og:image and twitter:image use relative URLs — social preview images broken on all platforms
- 对用户的影响：Developers may hit a documented source-backed failure mode: [Bug]: og:image and twitter:image use relative URLs — social preview images broken on all platforms
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1308 | [Bug]: og:image and twitter:image use relative URLs — social preview images broken on all platforms

## 28. 能力坑 · 失败模式：capability: chore(a11y): Form field elements missing "id" or "name" attributes on landing page

- 严重度：low
- 证据强度：source_linked
- 发现：Developers should check this capability risk before relying on the project: chore(a11y): Form field elements missing "id" or "name" attributes on landing page
- 对用户的影响：Developers may hit a documented source-backed failure mode: chore(a11y): Form field elements missing "id" or "name" attributes on landing page
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1305 | chore(a11y): Form field elements missing "id" or "name" attributes on landing page

## 29. 能力坑 · 失败模式：conceptual: [Bug]: Stale GitHub repository URLs point to old owner in package metadata and docs

- 严重度：low
- 证据强度：source_linked
- 发现：Developers should check this conceptual risk before relying on the project: [Bug]: Stale GitHub repository URLs point to old owner in package metadata and docs
- 对用户的影响：Developers may hit a documented source-backed failure mode: [Bug]: Stale GitHub repository URLs point to old owner in package metadata and docs
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1328 | [Bug]: Stale GitHub repository URLs point to old owner in package metadata and docs

## 30. 能力坑 · 失败模式：conceptual: feat: `codegraphcontext analyze complexity` threshold flag has no documented output format an...

- 严重度：low
- 证据强度：source_linked
- 发现：Developers should check this conceptual risk before relying on the project: feat: `codegraphcontext analyze complexity` threshold flag has no documented output format and no machine-readable export — CI integration is impossible without parseable output
- 对用户的影响：Developers may hit a documented source-backed failure mode: feat: `codegraphcontext analyze complexity` threshold flag has no documented output format and no machine-readable export — CI integration is impossible without parseable output
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1333 | feat: `codegraphcontext analyze complexity` threshold flag has no documented output format and no machine-readable export — CI integration is impossible without parseable output

## 31. 运行坑 · 失败模式：performance: feat(parsers): add Rust parser using Tree-sitter for functions, structs, traits, and impl blocks

- 严重度：low
- 证据强度：source_linked
- 发现：Developers should check this performance risk before relying on the project: feat(parsers): add Rust parser using Tree-sitter for functions, structs, traits, and impl blocks
- 对用户的影响：Developers may hit a documented source-backed failure mode: feat(parsers): add Rust parser using Tree-sitter for functions, structs, traits, and impl blocks
- 证据：failure_mode_cluster:github_issue | https://github.com/CodeGraphContext/CodeGraphContext/issues/1339 | feat(parsers): add Rust parser using Tree-sitter for functions, structs, traits, and impl blocks

## 32. 维护坑 · issue/PR 响应质量未知

- 严重度：low
- 证据强度：source_linked
- 发现：issue_or_pr_quality=unknown。
- 对用户的影响：用户无法判断遇到问题后是否有人维护。
- 证据：evidence.maintainer_signals | https://github.com/CodeGraphContext/CodeGraphContext | issue_or_pr_quality=unknown

## 33. 维护坑 · 发布节奏不明确

- 严重度：low
- 证据强度：source_linked
- 发现：release_recency=unknown。
- 对用户的影响：安装命令和文档可能落后于代码，用户踩坑概率升高。
- 证据：evidence.maintainer_signals | https://github.com/CodeGraphContext/CodeGraphContext | release_recency=unknown

## 34. 维护坑 · 失败模式：maintenance: v0.0.11-alpha

- 严重度：low
- 证据强度：source_linked
- 发现：Developers should check this maintenance risk before relying on the project: v0.0.11-alpha
- 对用户的影响：Upgrade or migration may change expected behavior: v0.0.11-alpha
- 证据：failure_mode_cluster:github_release | https://github.com/CodeGraphContext/CodeGraphContext/releases/tag/v0.0.11-alpha | v0.0.11-alpha

<!-- canonical_name: CodeGraphContext/CodeGraphContext; human_manual_source: deepwiki_human_wiki -->
