code-graph-builder 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- code_graph_builder/__init__.py +82 -0
- code_graph_builder/builder.py +366 -0
- code_graph_builder/cgb_cli.py +32 -0
- code_graph_builder/cli.py +564 -0
- code_graph_builder/commands_cli.py +1288 -0
- code_graph_builder/config.py +340 -0
- code_graph_builder/constants.py +708 -0
- code_graph_builder/embeddings/__init__.py +40 -0
- code_graph_builder/embeddings/qwen3_embedder.py +573 -0
- code_graph_builder/embeddings/vector_store.py +584 -0
- code_graph_builder/examples/__init__.py +0 -0
- code_graph_builder/examples/example_configuration.py +276 -0
- code_graph_builder/examples/example_kuzu_usage.py +109 -0
- code_graph_builder/examples/example_semantic_search_full.py +347 -0
- code_graph_builder/examples/generate_wiki.py +915 -0
- code_graph_builder/examples/graph_export_example.py +100 -0
- code_graph_builder/examples/rag_example.py +206 -0
- code_graph_builder/examples/test_cli_demo.py +129 -0
- code_graph_builder/examples/test_embedding_api.py +153 -0
- code_graph_builder/examples/test_kuzu_local.py +190 -0
- code_graph_builder/examples/test_rag_redis.py +390 -0
- code_graph_builder/graph_updater.py +605 -0
- code_graph_builder/guidance/__init__.py +1 -0
- code_graph_builder/guidance/agent.py +123 -0
- code_graph_builder/guidance/prompts.py +74 -0
- code_graph_builder/guidance/toolset.py +264 -0
- code_graph_builder/language_spec.py +536 -0
- code_graph_builder/mcp/__init__.py +21 -0
- code_graph_builder/mcp/api_doc_generator.py +764 -0
- code_graph_builder/mcp/file_editor.py +207 -0
- code_graph_builder/mcp/pipeline.py +777 -0
- code_graph_builder/mcp/server.py +161 -0
- code_graph_builder/mcp/tools.py +1800 -0
- code_graph_builder/models.py +115 -0
- code_graph_builder/parser_loader.py +344 -0
- code_graph_builder/parsers/__init__.py +7 -0
- code_graph_builder/parsers/call_processor.py +306 -0
- code_graph_builder/parsers/call_resolver.py +139 -0
- code_graph_builder/parsers/definition_processor.py +796 -0
- code_graph_builder/parsers/factory.py +119 -0
- code_graph_builder/parsers/import_processor.py +293 -0
- code_graph_builder/parsers/structure_processor.py +145 -0
- code_graph_builder/parsers/type_inference.py +143 -0
- code_graph_builder/parsers/utils.py +134 -0
- code_graph_builder/rag/__init__.py +68 -0
- code_graph_builder/rag/camel_agent.py +429 -0
- code_graph_builder/rag/client.py +298 -0
- code_graph_builder/rag/config.py +239 -0
- code_graph_builder/rag/cypher_generator.py +67 -0
- code_graph_builder/rag/llm_backend.py +210 -0
- code_graph_builder/rag/markdown_generator.py +352 -0
- code_graph_builder/rag/prompt_templates.py +440 -0
- code_graph_builder/rag/rag_engine.py +640 -0
- code_graph_builder/rag/review_report.md +172 -0
- code_graph_builder/rag/tests/__init__.py +3 -0
- code_graph_builder/rag/tests/test_camel_agent.py +313 -0
- code_graph_builder/rag/tests/test_client.py +221 -0
- code_graph_builder/rag/tests/test_config.py +177 -0
- code_graph_builder/rag/tests/test_markdown_generator.py +240 -0
- code_graph_builder/rag/tests/test_prompt_templates.py +160 -0
- code_graph_builder/services/__init__.py +39 -0
- code_graph_builder/services/graph_service.py +465 -0
- code_graph_builder/services/kuzu_service.py +665 -0
- code_graph_builder/services/memory_service.py +171 -0
- code_graph_builder/settings.py +75 -0
- code_graph_builder/tests/ACCEPTANCE_CRITERIA_PHASE2.md +401 -0
- code_graph_builder/tests/__init__.py +1 -0
- code_graph_builder/tests/run_acceptance_check.py +378 -0
- code_graph_builder/tests/test_api_find.py +231 -0
- code_graph_builder/tests/test_api_find_integration.py +226 -0
- code_graph_builder/tests/test_basic.py +78 -0
- code_graph_builder/tests/test_c_api_extraction.py +388 -0
- code_graph_builder/tests/test_call_resolution_scenarios.py +504 -0
- code_graph_builder/tests/test_embedder.py +411 -0
- code_graph_builder/tests/test_integration_semantic.py +434 -0
- code_graph_builder/tests/test_mcp_protocol.py +298 -0
- code_graph_builder/tests/test_mcp_user_flow.py +190 -0
- code_graph_builder/tests/test_rag.py +404 -0
- code_graph_builder/tests/test_settings.py +135 -0
- code_graph_builder/tests/test_step1_graph_build.py +264 -0
- code_graph_builder/tests/test_step2_api_docs.py +323 -0
- code_graph_builder/tests/test_step3_embedding.py +278 -0
- code_graph_builder/tests/test_vector_store.py +552 -0
- code_graph_builder/tools/__init__.py +40 -0
- code_graph_builder/tools/graph_query.py +495 -0
- code_graph_builder/tools/semantic_search.py +387 -0
- code_graph_builder/types.py +333 -0
- code_graph_builder/utils/__init__.py +0 -0
- code_graph_builder/utils/path_utils.py +30 -0
- code_graph_builder-0.2.0.dist-info/METADATA +321 -0
- code_graph_builder-0.2.0.dist-info/RECORD +93 -0
- code_graph_builder-0.2.0.dist-info/WHEEL +4 -0
- code_graph_builder-0.2.0.dist-info/entry_points.txt +3 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Path utilities for code graph builder."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from .. import constants as cs
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def should_skip_path(
|
|
9
|
+
path: Path,
|
|
10
|
+
repo_path: Path,
|
|
11
|
+
exclude_paths: frozenset[str] | None = None,
|
|
12
|
+
unignore_paths: frozenset[str] | None = None,
|
|
13
|
+
) -> bool:
|
|
14
|
+
"""Check if a path should be skipped during analysis."""
|
|
15
|
+
if path.is_file() and path.suffix in cs.IGNORE_SUFFIXES:
|
|
16
|
+
return True
|
|
17
|
+
rel_path = path.relative_to(repo_path)
|
|
18
|
+
rel_path_str = rel_path.as_posix()
|
|
19
|
+
dir_parts = rel_path.parent.parts if path.is_file() else rel_path.parts
|
|
20
|
+
if exclude_paths and (
|
|
21
|
+
not exclude_paths.isdisjoint(dir_parts)
|
|
22
|
+
or rel_path_str in exclude_paths
|
|
23
|
+
or any(rel_path_str.startswith(f"{p}/") for p in exclude_paths)
|
|
24
|
+
):
|
|
25
|
+
return True
|
|
26
|
+
if unignore_paths and any(
|
|
27
|
+
rel_path_str == p or rel_path_str.startswith(f"{p}/") for p in unignore_paths
|
|
28
|
+
):
|
|
29
|
+
return False
|
|
30
|
+
return not cs.IGNORE_PATTERNS.isdisjoint(dir_parts)
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: code-graph-builder
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Code knowledge graph builder with MCP server for AI-assisted code navigation
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Requires-Dist: diff-match-patch>=20230430
|
|
8
|
+
Requires-Dist: kuzu>=0.4
|
|
9
|
+
Requires-Dist: loguru>=0.7
|
|
10
|
+
Requires-Dist: mcp>=1.0
|
|
11
|
+
Requires-Dist: python-dotenv>=1.0
|
|
12
|
+
Requires-Dist: tree-sitter>=0.22
|
|
13
|
+
Provides-Extra: rag
|
|
14
|
+
Requires-Dist: httpx>=0.25; extra == 'rag'
|
|
15
|
+
Provides-Extra: semantic
|
|
16
|
+
Requires-Dist: httpx>=0.25; extra == 'semantic'
|
|
17
|
+
Provides-Extra: treesitter-c
|
|
18
|
+
Requires-Dist: tree-sitter-c; extra == 'treesitter-c'
|
|
19
|
+
Requires-Dist: tree-sitter-cpp; extra == 'treesitter-c'
|
|
20
|
+
Provides-Extra: treesitter-full
|
|
21
|
+
Requires-Dist: tree-sitter-c; extra == 'treesitter-full'
|
|
22
|
+
Requires-Dist: tree-sitter-cpp; extra == 'treesitter-full'
|
|
23
|
+
Requires-Dist: tree-sitter-go; extra == 'treesitter-full'
|
|
24
|
+
Requires-Dist: tree-sitter-java; extra == 'treesitter-full'
|
|
25
|
+
Requires-Dist: tree-sitter-javascript; extra == 'treesitter-full'
|
|
26
|
+
Requires-Dist: tree-sitter-lua; extra == 'treesitter-full'
|
|
27
|
+
Requires-Dist: tree-sitter-python; extra == 'treesitter-full'
|
|
28
|
+
Requires-Dist: tree-sitter-rust; extra == 'treesitter-full'
|
|
29
|
+
Requires-Dist: tree-sitter-scala; extra == 'treesitter-full'
|
|
30
|
+
Requires-Dist: tree-sitter-typescript; extra == 'treesitter-full'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# code_graph_builder
|
|
34
|
+
|
|
35
|
+
多语言代码知识图谱构建库,支持从源码仓库提取函数、类、调用关系等,存储到图数据库,并提供 RAG(检索增强生成)能力用于代码分析。
|
|
36
|
+
|
|
37
|
+
## 特性
|
|
38
|
+
|
|
39
|
+
- **多语言解析**:Python、JavaScript/TypeScript、C/C++、Rust、Go、Java、Scala、C#、PHP、Lua
|
|
40
|
+
- **多后端支持**:Kùzu(嵌入式,无需 Docker)、Memgraph(完整图数据库)、Memory(内存,测试用)
|
|
41
|
+
- **语义搜索**:基于 Qwen3 Embedding(阿里云 DashScope API)的向量化代码检索
|
|
42
|
+
- **RAG 引擎**:结合图数据和向量搜索,用 Kimi k2.5 生成代码分析报告
|
|
43
|
+
|
|
44
|
+
## 目录结构
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
code_graph_builder/
|
|
48
|
+
├── builder.py # 主 API:CodeGraphBuilder
|
|
49
|
+
├── cli.py # 命令行接口
|
|
50
|
+
├── config.py # 配置类(KuzuConfig、ScanConfig 等)
|
|
51
|
+
├── constants.py # 常量和 StrEnum
|
|
52
|
+
├── graph_updater.py # 图更新和批量写入
|
|
53
|
+
├── language_spec.py # 语言规范和 Tree-sitter 映射
|
|
54
|
+
├── models.py # 数据类
|
|
55
|
+
├── parser_loader.py # Tree-sitter 解析器加载
|
|
56
|
+
├── types.py # 类型定义(BuildResult、GraphData 等)
|
|
57
|
+
│
|
|
58
|
+
├── parsers/ # 各类解析器
|
|
59
|
+
│ ├── factory.py # 解析器工厂
|
|
60
|
+
│ ├── structure_processor.py
|
|
61
|
+
│ ├── definition_processor.py
|
|
62
|
+
│ ├── call_processor.py
|
|
63
|
+
│ ├── call_resolver.py
|
|
64
|
+
│ ├── import_processor.py
|
|
65
|
+
│ └── type_inference.py
|
|
66
|
+
│
|
|
67
|
+
├── services/ # 后端适配层
|
|
68
|
+
│ ├── graph_service.py # Memgraph 后端
|
|
69
|
+
│ ├── kuzu_service.py # Kùzu 后端
|
|
70
|
+
│ └── memory_service.py # 内存后端
|
|
71
|
+
│
|
|
72
|
+
├── embeddings/ # 向量化
|
|
73
|
+
│ ├── qwen3_embedder.py # Qwen3 嵌入器(阿里云 API)
|
|
74
|
+
│ └── vector_store.py # 向量存储抽象
|
|
75
|
+
│
|
|
76
|
+
├── tools/ # 查询工具
|
|
77
|
+
│ ├── graph_query.py # 图查询
|
|
78
|
+
│ └── semantic_search.py # 语义搜索
|
|
79
|
+
│
|
|
80
|
+
├── rag/ # RAG 模块
|
|
81
|
+
│ ├── rag_engine.py # RAG 引擎
|
|
82
|
+
│ ├── kimi_client.py # Kimi API 客户端
|
|
83
|
+
│ ├── camel_agent.py # CAMEL Agent
|
|
84
|
+
│ ├── markdown_generator.py
|
|
85
|
+
│ ├── prompt_templates.py # 提示词模板(移植自 deepwiki)
|
|
86
|
+
│ └── config.py
|
|
87
|
+
│
|
|
88
|
+
├── utils/
|
|
89
|
+
│ └── path_utils.py
|
|
90
|
+
│
|
|
91
|
+
├── tests/ # 单元测试
|
|
92
|
+
└── examples/ # 示例和演示脚本
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## 快速开始
|
|
96
|
+
|
|
97
|
+
### 安装
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# 克隆项目
|
|
101
|
+
git clone <repo-url>
|
|
102
|
+
cd CodeGraphWiki
|
|
103
|
+
|
|
104
|
+
# 基础安装(含 Kùzu 后端)
|
|
105
|
+
pip install .
|
|
106
|
+
|
|
107
|
+
# 含 C/C++ Tree-sitter 语法
|
|
108
|
+
pip install ".[treesitter-c]"
|
|
109
|
+
|
|
110
|
+
# 含所有 Tree-sitter 语言语法
|
|
111
|
+
pip install ".[treesitter-full]"
|
|
112
|
+
|
|
113
|
+
# 含语义搜索(Qwen3 嵌入)
|
|
114
|
+
pip install ".[semantic]"
|
|
115
|
+
|
|
116
|
+
# 安装全部可选依赖
|
|
117
|
+
pip install ".[treesitter-full,semantic,rag]"
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
> 如需在虚拟环境中安装:
|
|
121
|
+
> ```bash
|
|
122
|
+
> python3 -m venv .venv && source .venv/bin/activate
|
|
123
|
+
> pip install ".[treesitter-full]"
|
|
124
|
+
> ```
|
|
125
|
+
|
|
126
|
+
### 基本用法
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from code_graph_builder import CodeGraphBuilder
|
|
130
|
+
|
|
131
|
+
# 构建代码图(Kùzu 后端,无需 Docker)
|
|
132
|
+
builder = CodeGraphBuilder(
|
|
133
|
+
repo_path="/path/to/your/repo",
|
|
134
|
+
backend="kuzu",
|
|
135
|
+
backend_config={"db_path": "./code_graph.db"},
|
|
136
|
+
)
|
|
137
|
+
result = builder.build_graph()
|
|
138
|
+
|
|
139
|
+
print(f"解析文件: {result.files_processed}")
|
|
140
|
+
print(f"函数数量: {result.functions_found}")
|
|
141
|
+
print(f"调用关系: {result.relationships_created}")
|
|
142
|
+
|
|
143
|
+
# 导出图数据
|
|
144
|
+
graph_data = builder.export_graph()
|
|
145
|
+
|
|
146
|
+
# 执行 Cypher 查询
|
|
147
|
+
rows = builder.query("MATCH (f:Function) RETURN f.name LIMIT 10")
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### 内存模式(无持久化,适合测试)
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
builder = CodeGraphBuilder(
|
|
154
|
+
repo_path="/path/to/repo",
|
|
155
|
+
backend="memory",
|
|
156
|
+
)
|
|
157
|
+
result = builder.build_graph()
|
|
158
|
+
data = builder.export_graph() # 返回完整图数据
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 语义搜索
|
|
162
|
+
|
|
163
|
+
需要配置阿里云 DashScope API Key:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
export DASHSCOPE_API_KEY=sk-xxxxxx
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from code_graph_builder import CodeGraphBuilder, create_embedder, create_vector_store
|
|
171
|
+
from code_graph_builder.tools.semantic_search import SemanticSearchService
|
|
172
|
+
|
|
173
|
+
builder = CodeGraphBuilder("/path/to/repo", backend="kuzu")
|
|
174
|
+
builder.build_graph()
|
|
175
|
+
|
|
176
|
+
embedder = create_embedder(provider="qwen3")
|
|
177
|
+
vector_store = create_vector_store(backend="memory", dimension=1536)
|
|
178
|
+
|
|
179
|
+
# 构建向量索引(首次需要调用 API)
|
|
180
|
+
service = SemanticSearchService(
|
|
181
|
+
embedder=embedder,
|
|
182
|
+
vector_store=vector_store,
|
|
183
|
+
)
|
|
184
|
+
results = service.search("recursive fibonacci implementation", top_k=5)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### MCP 服务器
|
|
188
|
+
|
|
189
|
+
项目内置 MCP(Model Context Protocol)服务器,可与 Claude Code 等 AI 工具集成:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# 启动 MCP 服务器(stdio 模式)
|
|
193
|
+
python3 -m code_graph_builder.mcp.server
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
在 Claude Code 配置文件(`~/.claude/settings.json` 或项目 `.mcp.json`)中添加:
|
|
197
|
+
|
|
198
|
+
```json
|
|
199
|
+
{
|
|
200
|
+
"mcpServers": {
|
|
201
|
+
"code-graph-builder": {
|
|
202
|
+
"command": "python3",
|
|
203
|
+
"args": ["-m", "code_graph_builder.mcp.server"],
|
|
204
|
+
"cwd": "/path/to/CodeGraphWiki",
|
|
205
|
+
"env": {
|
|
206
|
+
"CGB_WORKSPACE": "~/.code-graph-builder",
|
|
207
|
+
"LLM_API_KEY": "sk-你的LLM-Key",
|
|
208
|
+
"LLM_BASE_URL": "https://api.openai.com/v1",
|
|
209
|
+
"LLM_MODEL": "gpt-4o",
|
|
210
|
+
"DASHSCOPE_API_KEY": "sk-你的Embedding-Key"
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
MCP 服务器提供 11 个工具:`initialize_repository`、`get_repository_info`、`query_code_graph`、`get_code_snippet`、`semantic_search`、`locate_function`、`list_api_interfaces`、`list_api_docs`、`get_api_doc`、`list_wiki_pages`、`get_wiki_page`。
|
|
218
|
+
|
|
219
|
+
> **首次配置?** 请参阅 [CLAUDE_CODE_GUIDE.md](./CLAUDE_CODE_GUIDE.md) 第 0 节的交互式配置流程,由 AI Agent 自动完成 LLM / Embedding 连接测试和 MCP 配置。
|
|
220
|
+
|
|
221
|
+
### RAG Wiki 生成
|
|
222
|
+
|
|
223
|
+
需要配置 Moonshot API Key(Kimi k2.5):
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
export MOONSHOT_API_KEY=sk-xxxxxx
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# 参考 examples/test_rag_tinycc.py
|
|
231
|
+
# 按模块批量生成代码 wiki,真实源码作为上下文
|
|
232
|
+
python3 code_graph_builder/examples/test_rag_tinycc.py \
|
|
233
|
+
--repo-path /path/to/tinycc \
|
|
234
|
+
--max-pages 10 \
|
|
235
|
+
--output-dir ./rag_output
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
## 环境变量
|
|
239
|
+
|
|
240
|
+
### LLM(优先级从高到低,首个匹配生效)
|
|
241
|
+
|
|
242
|
+
| 变量名 | 用途 | 默认值 |
|
|
243
|
+
|--------|------|--------|
|
|
244
|
+
| `LLM_API_KEY` / `LLM_BASE_URL` / `LLM_MODEL` | 通用 LLM(最高优先级) | 无 / `https://api.openai.com/v1` / `gpt-4o` |
|
|
245
|
+
| `OPENAI_API_KEY` / `OPENAI_BASE_URL` / `OPENAI_MODEL` | OpenAI 或兼容平台 | 无 / `https://api.openai.com/v1` / `gpt-4o` |
|
|
246
|
+
| `MOONSHOT_API_KEY` / `MOONSHOT_MODEL` | Moonshot / Kimi(旧版兼容) | 无 / `kimi-k2.5` |
|
|
247
|
+
|
|
248
|
+
### Embedding & 其他
|
|
249
|
+
|
|
250
|
+
| 变量名 | 用途 | 默认值 |
|
|
251
|
+
|--------|------|--------|
|
|
252
|
+
| `DASHSCOPE_API_KEY` | 阿里云 DashScope(Qwen3 Embedding) | 无 |
|
|
253
|
+
| `DASHSCOPE_BASE_URL` | DashScope API 地址 | `https://dashscope.aliyuncs.com/api/v1` |
|
|
254
|
+
| `CGB_WORKSPACE` | MCP 服务器工作目录 | `~/.code-graph-builder` |
|
|
255
|
+
| `MEMGRAPH_HOST` | Memgraph 主机(仅 Memgraph 后端) | `localhost` |
|
|
256
|
+
| `MEMGRAPH_PORT` | Memgraph 端口 | `7687` |
|
|
257
|
+
|
|
258
|
+
## 支持的编程语言
|
|
259
|
+
|
|
260
|
+
| 语言 | 提取内容 |
|
|
261
|
+
|------|----------|
|
|
262
|
+
| Python | 函数、类、方法、导入、调用关系 |
|
|
263
|
+
| JavaScript / TypeScript | 函数、类、模块、调用关系 |
|
|
264
|
+
| C / C++ | 函数、结构体/联合体/枚举(含成员)、typedef、宏、调用关系 |
|
|
265
|
+
| Rust | 函数、impl 块、trait、调用关系 |
|
|
266
|
+
| Go | 函数、接口、调用关系 |
|
|
267
|
+
| Java | 类、方法、继承、调用关系 |
|
|
268
|
+
| Scala | 类、对象、方法 |
|
|
269
|
+
| C# | 类、方法、命名空间 |
|
|
270
|
+
| PHP | 函数、类、方法 |
|
|
271
|
+
| Lua | 函数、调用关系 |
|
|
272
|
+
|
|
273
|
+
## 图模式(Graph Schema)
|
|
274
|
+
|
|
275
|
+
**节点类型**:`Project`、`Package`、`Module`、`File`、`Class`、`Function`、`Method`、`Type`、`Folder`
|
|
276
|
+
|
|
277
|
+
**关系类型**:`CONTAINS`、`DEFINES`、`CALLS`、`INHERITS`、`IMPORTS`
|
|
278
|
+
|
|
279
|
+
**节点属性**:`qualified_name`(主键)、`name`、`path`、`start_line`、`end_line`、`signature`、`return_type`、`visibility`、`parameters`、`kind`、`docstring`
|
|
280
|
+
|
|
281
|
+
## 示例脚本
|
|
282
|
+
|
|
283
|
+
位于 `examples/` 目录:
|
|
284
|
+
|
|
285
|
+
| 脚本 | 用途 |
|
|
286
|
+
|------|------|
|
|
287
|
+
| `example_kuzu_usage.py` | Kùzu 后端完整示例 |
|
|
288
|
+
| `example_configuration.py` | 各种配置方式演示 |
|
|
289
|
+
| `test_tinycc.py` | 用 tinycc 仓库测试图构建 |
|
|
290
|
+
| `test_kuzu_local.py` | Kùzu 后端功能测试 |
|
|
291
|
+
| `test_tinycc_memory.py` | 内存模式解析测试 |
|
|
292
|
+
| `test_rag_tinycc.py` | RAG wiki 生成(含真实源码上下文) |
|
|
293
|
+
| `rag_example.py` | RAG 模块使用示例 |
|
|
294
|
+
| `example_semantic_search_full.py` | 完整语义搜索流程 |
|
|
295
|
+
| `test_embedding_api.py` | Qwen3 嵌入 API 测试 |
|
|
296
|
+
|
|
297
|
+
## RAG 提示词模板
|
|
298
|
+
|
|
299
|
+
`rag/prompt_templates.py` 移植自 [deepwiki-open](https://github.com/AsyncFuncAI/deepwiki-open),包含:
|
|
300
|
+
|
|
301
|
+
- `RAG_SYSTEM_PROMPT` / `RAG_TEMPLATE` — 标准 RAG 提示词
|
|
302
|
+
- `DEEP_RESEARCH_*_ITERATION_PROMPT` — 多轮深度研究提示词
|
|
303
|
+
- `SIMPLE_CHAT_SYSTEM_PROMPT` — 直接问答提示词
|
|
304
|
+
|
|
305
|
+
源码上下文注入方案:通过 `qualified_name` 推导源文件路径,用 `start_line`/`end_line` 精确提取函数体,按 `## File Path: xxx.c` 格式组装进 prompt。
|
|
306
|
+
|
|
307
|
+
## 运行测试
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
# 安装测试依赖
|
|
311
|
+
pip install pytest
|
|
312
|
+
|
|
313
|
+
# 单元测试(无需外部依赖)
|
|
314
|
+
python3 -m pytest code_graph_builder/tests/ -v
|
|
315
|
+
|
|
316
|
+
# RAG 模块测试
|
|
317
|
+
python3 -m pytest code_graph_builder/rag/tests/ -v
|
|
318
|
+
|
|
319
|
+
# C API 提取测试(需要 tree-sitter-c)
|
|
320
|
+
python3 -m pytest code_graph_builder/tests/test_c_api_extraction.py -v
|
|
321
|
+
```
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
code_graph_builder/__init__.py,sha256=BTPziE9mvhRQEtunmEN8q48Wwzu8ijzrjUjhlDr50QQ,2065
|
|
2
|
+
code_graph_builder/builder.py,sha256=Xp2nqWPP24W9zNdZBY1riBKtKWtZbqPwWhbGCjriXCw,14333
|
|
3
|
+
code_graph_builder/cgb_cli.py,sha256=w4Z2P4rGKxPCUH9YarOguQJCqUUmwRxpRbJQLZXOM5g,872
|
|
4
|
+
code_graph_builder/cli.py,sha256=7_W82IHVb-3-qcGUke9RL-yYC8Uzb2gRI0GMEa74TtU,16648
|
|
5
|
+
code_graph_builder/commands_cli.py,sha256=XkSE1BfDr4dDDG19ZpPM3mqTf-fwpDwBHvL5PaqRd2o,45771
|
|
6
|
+
code_graph_builder/config.py,sha256=ni9-0XdWoh8eqDZpiOZKDQ9NbYWlx1uHgr3mXGNTgpk,11728
|
|
7
|
+
code_graph_builder/constants.py,sha256=PhOIkoYi1fsaapODJqScNrdTOJZQ7lJF7Nw1_tOPeuU,20380
|
|
8
|
+
code_graph_builder/graph_updater.py,sha256=kSkURYbeSN_67gVSJFki-wMChWBoquyK0CCzCtVUyTk,21827
|
|
9
|
+
code_graph_builder/language_spec.py,sha256=rbW8lq8hO7GFsObKfE5viBMRrovPxJGeh280KQd5OI8,18519
|
|
10
|
+
code_graph_builder/models.py,sha256=_IwUoXsNCu7HZ67M3f4Ir9USbnLaiLExwjMir2HKzaw,2640
|
|
11
|
+
code_graph_builder/parser_loader.py,sha256=j3UFwwwB-HNrvDLZcEWCrVNY217codHGXFdx6yFWINk,12002
|
|
12
|
+
code_graph_builder/settings.py,sha256=o6DOd-C6qu9d2zcIzKj2yx8JVKtdbYCPYeTTErByjBU,2400
|
|
13
|
+
code_graph_builder/types.py,sha256=vhv_RL8Y4oClrPIn6sVtnusBfy1yt4DsuVwHvIUXLTU,8424
|
|
14
|
+
code_graph_builder/embeddings/__init__.py,sha256=r1e38SJ0YbpX8MplAXwnTFr_bq4p25u-soU4LwcwkeM,790
|
|
15
|
+
code_graph_builder/embeddings/qwen3_embedder.py,sha256=RBKWP8ftJpvakAVwEt0tf6ro8eaQ-sN_jq4vArxWTr8,19518
|
|
16
|
+
code_graph_builder/embeddings/vector_store.py,sha256=UfcGHCXc0AMTM6x2dLnWlB2Twm7ktEthk3cngDRWX50,16853
|
|
17
|
+
code_graph_builder/examples/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
code_graph_builder/examples/example_configuration.py,sha256=1SnwtSKioVq_DeCuOKmG-hwebGMOYz3zRBvexIuUrJw,8752
|
|
19
|
+
code_graph_builder/examples/example_kuzu_usage.py,sha256=p7q6UKGNMI9DLng95UDdq1Saike38cwMGCOu64Ql0LQ,3645
|
|
20
|
+
code_graph_builder/examples/example_semantic_search_full.py,sha256=_zRCtEcVabwICCt0-gx_EwsgBi8KxjRbnp80fo7bd2M,10092
|
|
21
|
+
code_graph_builder/examples/generate_wiki.py,sha256=D470ODUcb1gAlvCLAHrY8lS3hKKpWbSUsUhUCmKCd6s,35999
|
|
22
|
+
code_graph_builder/examples/graph_export_example.py,sha256=RtyCysM-QvSU1861cRQcQHpnpL7xbc26QNNhb6Uvofg,3061
|
|
23
|
+
code_graph_builder/examples/rag_example.py,sha256=56MAq0qb3FwrrcqSDBQeje7BVOpM9BrVtR29BvKPX6M,5807
|
|
24
|
+
code_graph_builder/examples/test_cli_demo.py,sha256=4p_om163NjufwjGUe5Hx6FVElkZGtM64mmSkHbzQsvI,3446
|
|
25
|
+
code_graph_builder/examples/test_embedding_api.py,sha256=HSx8nKRlXoohqpB3WAp_V0pNAotIJwwM208_KDzlk2A,4719
|
|
26
|
+
code_graph_builder/examples/test_kuzu_local.py,sha256=c5NhTneYpAlPgO45e7BdkMnePOdbgFp7sSixPQPMRfc,5669
|
|
27
|
+
code_graph_builder/examples/test_rag_redis.py,sha256=f1Xwoe8Yt8ynGSuj2HvqhenpX5aLfXgn_3Y3Qkr3BYM,13830
|
|
28
|
+
code_graph_builder/guidance/__init__.py,sha256=Xm1v1GC6podKn8SN56VPZaVrL0A-Rubl2MIOvu6zV6c,79
|
|
29
|
+
code_graph_builder/guidance/agent.py,sha256=fYxWi4ZUaqLAtMRsPfLwtkFQSJZhVK74U0EfTv6knuk,4167
|
|
30
|
+
code_graph_builder/guidance/prompts.py,sha256=utLHSCNrBnKNYSEeaMmoM_vXHcaEKKkSQcT-jZwl3Aw,2641
|
|
31
|
+
code_graph_builder/guidance/toolset.py,sha256=YhEn2UseI-hhn50P_3rjiARY2CD-tnopo5Dfl8RVocA,9017
|
|
32
|
+
code_graph_builder/mcp/__init__.py,sha256=YxD-hR4djCu_RRAEiZs_pvAahT2ZohwBhkQU6RJ6wfI,412
|
|
33
|
+
code_graph_builder/mcp/api_doc_generator.py,sha256=TTPEgoxTDXpgYL6J0djZw1sfu-JaKih4oNdSinZBiLE,27407
|
|
34
|
+
code_graph_builder/mcp/file_editor.py,sha256=KesZldC-1D9jfb3MV-R7EGWLJ48RgJMQ9OgqjuI5J7Y,7339
|
|
35
|
+
code_graph_builder/mcp/pipeline.py,sha256=Pvtu6oqud8yfXSzpQh9ulcMjPAvDLZ-5iUtrLmW1ZJ0,27889
|
|
36
|
+
code_graph_builder/mcp/server.py,sha256=sNcGodmlMRZWCounpRac5TRhrb6J7cHgz7POX-6E82g,5569
|
|
37
|
+
code_graph_builder/mcp/tools.py,sha256=he6bXVwgvzTeniONHbpWZ-KyK0ylGPlDKG96prAcVU8,71780
|
|
38
|
+
code_graph_builder/parsers/__init__.py,sha256=EAbmuNjwzBFGpYon8yAK8ohQNQ718rM8JcFhudcOzz0,258
|
|
39
|
+
code_graph_builder/parsers/call_processor.py,sha256=oFmlNu3kTzG2rlKxLbuqTrxjGcFySAJDU9GiM4Y7PRU,11173
|
|
40
|
+
code_graph_builder/parsers/call_resolver.py,sha256=1WuRHTxDxuaKHzIqJVCux0yhebM4VfSvU1d9bVqDdlA,4788
|
|
41
|
+
code_graph_builder/parsers/definition_processor.py,sha256=83FlXjCEWy8JZcCpIPIzX0gSXH4rOH_2GNKEqBNp4fE,30396
|
|
42
|
+
code_graph_builder/parsers/factory.py,sha256=04XN-p4zC0tW3R-MP6_k-ULy5TGopPbMDKvaDzWD5IA,4593
|
|
43
|
+
code_graph_builder/parsers/import_processor.py,sha256=8ooMT7qjBQpzxjeH0-iX_7Nn1z1soVJa2ZjLdlcnX1U,11193
|
|
44
|
+
code_graph_builder/parsers/structure_processor.py,sha256=cfAke8FV5-_vHAwjHkSF1XeQ1CDcZ5TZp8CXeymsQCw,5681
|
|
45
|
+
code_graph_builder/parsers/type_inference.py,sha256=ifyVEvJSfrFps44SPlnatm5wlYXS3Aoakfv4CwL81RE,4885
|
|
46
|
+
code_graph_builder/parsers/utils.py,sha256=wdupULGnCfLGTJYnRZU8XUVt3d7wopvtGItjNYFJSg4,4515
|
|
47
|
+
code_graph_builder/rag/__init__.py,sha256=xyUNTOU4r8h4yYt3q458DVBuzNVdexnasG2WW1USvBU,1475
|
|
48
|
+
code_graph_builder/rag/camel_agent.py,sha256=N_uOqvlGgAD-m0rBK5lnv42QYGzunajWXNAF08o4jkw,13442
|
|
49
|
+
code_graph_builder/rag/client.py,sha256=jJorVwlI6Ck8I2JuE1fDfzbHtqdFfqHDTtNrVKQ1RFM,9719
|
|
50
|
+
code_graph_builder/rag/config.py,sha256=ihi6fBh3ne8PPQHVTxQNWDzlBcwSWA3JOZwghgMXPjM,7488
|
|
51
|
+
code_graph_builder/rag/cypher_generator.py,sha256=dzHtSlPpTl2Tpj0hqv0dzRuFp6tj9zF6CfPkycdJF3w,2261
|
|
52
|
+
code_graph_builder/rag/llm_backend.py,sha256=N3Xmv_6aR6PnXkNIMlS7-yzNrxZvQy6q5EhMuhRUy3k,7231
|
|
53
|
+
code_graph_builder/rag/markdown_generator.py,sha256=X34NpO-QAGuyPQ9j_AnXAq9IO0fU0vQIwMFhdwSdv9A,10019
|
|
54
|
+
code_graph_builder/rag/prompt_templates.py,sha256=Au4Yu2HuHYKSkEjAa3pgfrs-KA0gl9d8GxUPmCUlIFQ,16427
|
|
55
|
+
code_graph_builder/rag/rag_engine.py,sha256=-JxpmcoOpSwZDiO9TNcotz4uMi580Xtiwc4gJZ-Vup0,19924
|
|
56
|
+
code_graph_builder/rag/review_report.md,sha256=tUveeR3pltR55pOdkOfNiQRKCTPpm9X2qvfJAqWMZ6E,3857
|
|
57
|
+
code_graph_builder/rag/tests/__init__.py,sha256=AE6cNRSucuuGxMq3QYoSoCqhuMoUexiwQFnmdPWO5kA,64
|
|
58
|
+
code_graph_builder/rag/tests/test_camel_agent.py,sha256=46SWISyOZzhvuM4hQ_7DDPwgtpPrhhlnzUKgBTacVDY,10809
|
|
59
|
+
code_graph_builder/rag/tests/test_client.py,sha256=74gGoug-1VE5Oqja19mM2UGE8O1eKs-LfsiO3UiQCMU,7384
|
|
60
|
+
code_graph_builder/rag/tests/test_config.py,sha256=071mrkMMSGeVmrfgw-nz1qQfR3YYOlEu-MqsEwdiHmQ,6113
|
|
61
|
+
code_graph_builder/rag/tests/test_markdown_generator.py,sha256=zHlziXyR69X2h_InULN465R5zPO9auigwZNaGdcP0hY,7894
|
|
62
|
+
code_graph_builder/rag/tests/test_prompt_templates.py,sha256=eh0Ep2pojnuFfpkYtS7jYQ1VK-noUMfMmaVT7Q0kXaQ,5483
|
|
63
|
+
code_graph_builder/services/__init__.py,sha256=uhxX6SU0HtvUYLF3L27EuM_188_lIn0NaeSfllO0QLY,1046
|
|
64
|
+
code_graph_builder/services/graph_service.py,sha256=O36SjpRgQ8NpguJwojOTmNshrfG6zL3LPZx_tbYtnSA,15410
|
|
65
|
+
code_graph_builder/services/kuzu_service.py,sha256=tR6Knfil2iFeB__5rTkLfXX8okMY5LxJ4kwT_zE0eTE,25749
|
|
66
|
+
code_graph_builder/services/memory_service.py,sha256=Y4NjB9UHdqGgGXvGYk2JUtYZcBMBwAJi7EmZ8X9r5d4,5942
|
|
67
|
+
code_graph_builder/tests/ACCEPTANCE_CRITERIA_PHASE2.md,sha256=kq-E7NilmW7REB9L-1I2u3NbSMs3Wh33K9MtI4Stg8Q,11798
|
|
68
|
+
code_graph_builder/tests/__init__.py,sha256=cyj-puJzjMiBJ3Gq5uIK8SUNnP2bwnN1y9j5JQ9G-Us,36
|
|
69
|
+
code_graph_builder/tests/run_acceptance_check.py,sha256=uXvhB3mCDPIFx4nX6C6mjJ9gEBucY-3rlNCypItLeGs,12329
|
|
70
|
+
code_graph_builder/tests/test_api_find.py,sha256=Ei4V1yiVeUrxvE5WLrMWr3P_IpQN5rFVuEyVtRmb9Oo,7971
|
|
71
|
+
code_graph_builder/tests/test_api_find_integration.py,sha256=YKX_EX2Y9WfAZt-6k4yjti2VCcAinbVKjhh-LawoytE,8535
|
|
72
|
+
code_graph_builder/tests/test_basic.py,sha256=jNCoGK0pmHKITiyfz2XoTeX6TFEHr4Y69yDlqOmn5Vo,2342
|
|
73
|
+
code_graph_builder/tests/test_c_api_extraction.py,sha256=cM0t1FA8yEHZt0oEbtpSG_sO2n2NYI4PxYBfXIsfupU,11464
|
|
74
|
+
code_graph_builder/tests/test_call_resolution_scenarios.py,sha256=jJOAHfUmhSgI1T2fZ331qkW1F8vuufFjHZoHGU2VXv0,13404
|
|
75
|
+
code_graph_builder/tests/test_embedder.py,sha256=d3VWeYAnu1QsdbnhWXizO0PDqF6b1Xrx6SiSzwFVe1o,15047
|
|
76
|
+
code_graph_builder/tests/test_integration_semantic.py,sha256=lPCID5_YdrGMSdZo9jlawqEXIok4GxWX08ZqatZs0c8,14366
|
|
77
|
+
code_graph_builder/tests/test_mcp_protocol.py,sha256=pKdL3gDrPxg__sWtHhZOmfttw29o359c8LT2Ie4cBo8,11174
|
|
78
|
+
code_graph_builder/tests/test_mcp_user_flow.py,sha256=E8nKCMiMuOxr5eUC139igN2BjB663xDNzmzlaWzXyas,7410
|
|
79
|
+
code_graph_builder/tests/test_rag.py,sha256=0Fy3uci36-aNz-RVbsjWKBNUIrKGOJBZVwxybyXaGus,13958
|
|
80
|
+
code_graph_builder/tests/test_settings.py,sha256=-qoM8xyJP4-SGdnew3EvFbwY9GuYVKmBef0EdksCbfw,4724
|
|
81
|
+
code_graph_builder/tests/test_step1_graph_build.py,sha256=78kOFeLayrBWYeF293huEeaIhxVtEdUQL5dkI-j3LVQ,10645
|
|
82
|
+
code_graph_builder/tests/test_step2_api_docs.py,sha256=LMtQOWB8lrVCeIF6hm2VHK125klbArunPyO3eU6MTzE,13324
|
|
83
|
+
code_graph_builder/tests/test_step3_embedding.py,sha256=JBtOKNiE0KacOI5p5vCFQbrCP8kWDPuAL572AyU-bpk,10138
|
|
84
|
+
code_graph_builder/tests/test_vector_store.py,sha256=ik920-cOLflDwt9EHYNR2mhnIxKG0avSIyCPkV1r8FQ,19278
|
|
85
|
+
code_graph_builder/tools/__init__.py,sha256=TapjQ9GkOQfGn3D6NuRXsYnSLPO0pXB1Fp4fOys3i54,937
|
|
86
|
+
code_graph_builder/tools/graph_query.py,sha256=VF6ffNJobXtvCLo0pkXqq2UvUMWVJplIj17QxfsrfwY,16299
|
|
87
|
+
code_graph_builder/tools/semantic_search.py,sha256=pqj8KjbUVXHwCl5aG7FGvS_DleEm0HU0FkXj5U4gGO4,12503
|
|
88
|
+
code_graph_builder/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
89
|
+
code_graph_builder/utils/path_utils.py,sha256=BMAoAGTLQSOremaLK6eNxkgiNr4HBOShXohSn0i42es,990
|
|
90
|
+
code_graph_builder-0.2.0.dist-info/METADATA,sha256=NW_rj2m10fN4M6mhGaQ4Y9gM8jRlabMQBG7ZL6f4dSo,11014
|
|
91
|
+
code_graph_builder-0.2.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
92
|
+
code_graph_builder-0.2.0.dist-info/entry_points.txt,sha256=55t33wgFx_gjJXFmy8P-CaLs4FlWzlxXbf4fcphBGZQ,105
|
|
93
|
+
code_graph_builder-0.2.0.dist-info/RECORD,,
|