ln-020-codegraph
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePaths: File paths are relative to skills repo root.
路径: 文件路径相对于技能仓库根目录。
Code Knowledge Graph
代码知识图谱
Type: Standalone Utility
Category: 0XX Dev Environment
Indexes codebase into a layered graph (tree-sitter AST → SQLite) and provides dependency analysis, path tracing, references, implementations, and architecture overview via MCP tools.
类型: 独立工具
分类: 0XX 开发环境
将代码库索引为分层图谱(tree-sitter AST → SQLite),并通过MCP工具提供依赖分析、路径追踪、引用查找、实现定位和架构概览功能。
Inputs
输入
| Input | Required | Source | Description |
|---|---|---|---|
| yes | args or CWD | Project root to index |
| no | args | Specific action: |
| 输入 | 是否必填 | 来源 | 描述 |
|---|---|---|---|
| 是 | 参数或当前工作目录(CWD) | 要索引的项目根目录 |
| 否 | 参数 | 具体操作: |
When to Use
适用场景
- Starting work on an unfamiliar codebase → +
indexarchitecture - Before refactoring a function/class → +
search+get_symboltrace_paths - Understanding call flow →
trace_paths - Finding a symbol quickly →
search
- 开始接触陌生代码库 → +
indexarchitecture - 重构函数/类之前 → +
search+get_symboltrace_paths - 梳理调用流程 →
trace_paths - 快速查找符号 →
search
Workflow
工作流程
Phase 1: Index
阶段1:索引
Check if graph exists ( in project root).
.hex-skills/codegraph/index.dbIf NOT exists:
Call: index_project({ path: "{project_path}" })If exists (re-index on demand):
Call: index_project({ path: "{project_path}" })Idempotent — skips unchanged files automatically.
检查图谱是否存在(项目根目录下的)。
.hex-skills/codegraph/index.db如果不存在:
Call: index_project({ path: "{project_path}" })如果存在(按需重新索引):
Call: index_project({ path: "{project_path}" })幂等操作 — 会自动跳过未修改的文件。
Phase 2: Query
阶段2:查询
Route based on user intent:
| User says | Tool | Parameters |
|---|---|---|
| "Show dependencies" / "What uses X?" | | |
| "Who calls X?" / "What does X call?" | | |
| "Tell me about X" / "Context of X" | | |
| "Project structure" / "Architecture" | | |
| "Find symbol X" | | |
| "Watch for changes" | | |
| "Find duplicate code" | | |
| "Risky hotspots" | | |
| "Unused exports" | | |
| "Circular dependencies" | | |
| "Module coupling" | | |
| "Implementations / overrides" | | |
| "Dataflow / propagation" | | |
Canonical selector rule: Semantic tools accept exactly one selector:
symbol_idworkspace_qualified_namequalified_name- +
namefile
Preferred flow: use first, then feed the returned into , , , or for exact follow-up queries.
search_symbolsworkspace_qualified_nameget_symboltrace_pathsfind_referencesfind_implementationsDataflow anchors: requires and optional . Use:
find_dataflowssource.anchorsink.anchor- for function parameters
param - for local variables
local - for function returns
return - with
propertyfor bounded property flowaccess_path
Precision controls: , , and support (, , , ) when the caller wants to suppress weaker parser-only facts.
get_symboltrace_pathsfind_referencesmin_confidencelowinferredexactprecise根据用户意图路由到对应工具:
| 用户诉求 | 工具 | 参数 |
|---|---|---|
| "展示依赖" / "哪些地方用到了X?" | | |
| "谁调用了X?" / "X调用了哪些内容?" | | |
| "介绍下X" / "X的上下文" | | |
| "项目结构" / "架构概览" | | |
| "查找符号X" | | |
| "监听变更" | | |
| "查找重复代码" | | |
| "风险热点" | | |
| "未使用导出" | | |
| "循环依赖" | | |
| "模块耦合度" | | |
| "实现/重写逻辑" | | |
| "数据流/传播路径" | | |
标准选择器规则: 语义工具仅接受以下选择器中的一个:
symbol_idworkspace_qualified_namequalified_name- +
namefile
推荐流程: 先使用,再将返回的传入、、或进行精准的后续查询。
search_symbolsworkspace_qualified_nameget_symboltrace_pathsfind_referencesfind_implementations数据流锚点: 需要传入,可选传入。可用值:
find_dataflowssource.anchorsink.anchor- 对应函数参数
param - 对应局部变量
local - 对应函数返回值
return - 搭配使用的
access_path对应有限属性流property
精度控制: 当调用方想要过滤掉仅靠解析器得到的可信度较低的结果时,、和支持设置(、、、)。
get_symboltrace_pathsfind_referencesmin_confidencelowinferredexactprecisePhase 3: Present Results
阶段3:结果展示
- Show MCP tool output directly (markdown tables)
- For code snippets referenced in results, use with line ranges
hex-line read_file - Suggest follow-up queries based on results:
- After → suggest
search_symbolswithget_symbolfor the top exact matchworkspace_qualified_name - After → suggest
get_symbolif refactoringtrace_paths - After → suggest
trace_pathsorfind_referencesdepending on symbol kindfind_implementations
- After
- 直接展示MCP工具的输出(markdown表格)
- 对于结果中引用的代码片段,使用带行范围的读取
hex-line read_file - 基于结果推荐后续查询:
- 执行后 → 推荐使用匹配度最高的
search_symbols调用workspace_qualified_nameget_symbol - 执行后 → 如果是重构场景,推荐使用
get_symboltrace_paths - 执行后 → 根据符号类型推荐
trace_paths或find_referencesfind_implementations
- 执行
Supported Languages
支持的语言
| Language | Extensions | Coverage |
|---|---|---|
| JavaScript | .js, .mjs, .cjs, .jsx | Strongest semantic coverage |
| TypeScript / TSX | .ts, .tsx | Strongest semantic coverage |
| Python | .py | Workspace-aware definitions, calls, imports, unused exports; optional precise overlay when provider is installed |
| C# | .cs | Workspace-aware definitions, calls, project/namespace ownership, type relations; optional precise overlay when provider is installed |
| PHP | .php | Workspace-aware definitions, calls, PSR-4 namespace imports, unused exports; optional precise overlay when provider is installed |
| 语言 | 扩展名 | 支持程度 |
|---|---|---|
| JavaScript | .js, .mjs, .cjs, .jsx | 最强语义覆盖 |
| TypeScript / TSX | .ts, .tsx | 最强语义覆盖 |
| Python | .py | 支持工作区级别的定义、调用、导入、未使用导出检测;安装对应provider后可开启可选的高精度覆盖 |
| C# | .cs | 支持工作区级别的定义、调用、项目/命名空间归属、类型关系;安装对应provider后可开启可选的高精度覆盖 |
| PHP | .php | 支持工作区级别的定义、调用、PSR-4命名空间导入、未使用导出检测;安装对应provider后可开启可选的高精度覆盖 |
MCP Server Setup
MCP 服务端配置
Add to :
.mcp.jsonjson
{
"mcpServers": {
"hex-graph": {
"command": "node",
"args": ["{skills_repo}/mcp/hex-graph-mcp/server.mjs"]
}
}
}添加到:
.mcp.jsonjson
{
"mcpServers": {
"hex-graph": {
"command": "node",
"args": ["{skills_repo}/mcp/hex-graph-mcp/server.mjs"]
}
}
}Definition of Done
完成标准
- Project indexed (index_project returns success)
- Query results shown to user
- Follow-up suggestions provided
Version: 0.1.0
Last Updated: 2026-03-20
- 项目索引完成(index_project返回成功)
- 已向用户展示查询结果
- 已提供后续查询建议
版本: 0.1.0
最后更新: 2026-03-20