ln-021-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: |
| 输入项 | 是否必填 | 来源 | 描述 |
|---|---|---|---|
| 是 | 参数或当前工作目录 | 要索引的项目根目录 |
| 否 | 参数 | 具体操作: |
When to Use
使用场景
- Starting work on an unfamiliar codebase → +
indexarchitecture - Before refactoring a function/class → +
find_symbols+inspect_symboltrace_paths - Understanding call flow →
trace_paths - Finding a symbol quickly →
search
- 接手陌生代码库时 → +
indexarchitecture - 对函数/类进行重构前 → +
find_symbols+inspect_symboltrace_paths - 理解调用流程时 →
trace_paths - 快速查找符号时 →
search
MCP Availability
MCP 可用性
Tool policy: follow host AGENTS.md MCP preferences; load and only when host policy is absent or MCP behavior is unclear.
references/mcp_tool_preferences.mdreferences/mcp_integration_patterns.mdUse first when the task depends on symbol identity, references, implementations, architecture, dataflow, or edit impact. Use first for targeted local code reads when available. If MCP is unavailable, unsupported, or not indexed, continue with built-in , answer with manual evidence, and explicitly note the degraded confidence instead of blocking the skill.
hex-graphhex-lineGlob/Grep/Read/Bash工具策略:遵循宿主AGENTS.md中的MCP偏好;仅当宿主策略缺失或MCP行为不明确时,才加载和。
references/mcp_tool_preferences.mdreferences/mcp_integration_patterns.md当任务依赖符号标识、引用、实现、架构、数据流或编辑影响时,优先使用;如果有可用的针对性本地代码读取工具,优先使用。若MCP不可用、不支持或未完成索引,则继续使用内置的,手动提供证据并明确标注置信度降低,而非阻塞技能执行。
hex-graphhex-lineGlob/Grep/Read/BashWorkflow
工作流程
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.
If is unavailable: build a manual project map with and targeted , then continue to the closest matching query workflow without indexing.
hex-graphGlobGrep/Read检查项目根目录下是否存在图谱文件()。
.hex-skills/codegraph/index.db若不存在:
Call: index_project({ path: "{project_path}" })若存在(按需重新索引):
Call: index_project({ path: "{project_path}" })幂等操作 — 自动跳过未修改的文件。
若不可用: 使用和针对性的构建手动项目映射,然后继续执行最匹配的查询工作流,无需索引。
hex-graphGlobGrep/ReadPhase 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" | | |
"Find | | `{ path: "{project_path}", pattern: "app\.get\( |
| "Find duplicate code / hotspots / unused exports" | | |
| "Circular dependencies / module coupling" | | |
| "Implementations / overrides" | | |
| "Dataflow / propagation" | | |
| "Review a diff / worktree" | | |
| "Check what editing this range affects" | | |
Canonical selector rule: Semantic tools accept exactly one selector:
symbol_idworkspace_qualified_namequalified_name- +
namefile
Preferred flow: use only after narrowing as much as practical, then feed the returned into , , , or for exact follow-up queries.
find_symbolspathworkspace_qualified_nameinspect_symboltrace_pathsfind_referencesfind_implementationsQuery boundary rule: is name-based discovery only. For code fragments like or unresolved member-call patterns like , use instead of treating them as symbols.
find_symbolsexport functionapp.get(...)grep_searchAmbiguity rule: if returns or shows more total results than returned rows, refine with , then or instead of widening the graph query.
find_symbolspartial ... truncated=1pathname + fileworkspace_qualified_namePath rule: may be the indexed project root or any file/subdirectory inside that indexed project.
pathDataflow anchors: requires and optional . Use:
trace_dataflowsource.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.
inspect_symboltrace_pathsfind_referencesmin_confidencelowinferredexactprecise根据用户意图路由:
| 用户需求 | 工具 | 参数 |
|---|---|---|
| "显示依赖关系" / "哪些地方用到了X?" | | |
| "谁调用了X?" / "X调用了哪些内容?" | | |
| "告诉我关于X的信息" / "X的上下文" | | |
| "项目结构" / "架构" | | |
| "查找符号X" | | |
"查找 | | `{ path: "{project_path}", pattern: "app\.get\( |
| "查找重复代码 / 热点代码 / 未使用的导出" | | |
| "循环依赖 / 模块耦合" | | |
| "实现 / 重写" | | |
| "数据流 / 传播路径" | | |
| "审查差异 / 工作区" | | |
| "检查编辑此范围会影响哪些内容" | | |
标准选择器规则: 语义工具仅接受以下选择器之一:
symbol_idworkspace_qualified_namequalified_name- +
namefile
推荐流程: 仅在尽可能缩小范围后使用,然后将返回的传入、、或进行精确的后续查询。
pathfind_symbolsworkspace_qualified_nameinspect_symboltrace_pathsfind_referencesfind_implementations查询边界规则: 仅基于名称进行发现。对于等代码片段或这类未解析的成员调用模式,请使用而非将其视为符号。
find_symbolsexport functionapp.get(...)grep_search歧义处理规则: 如果返回或显示的总结果数多于返回行数,请通过缩小范围,然后使用或进行查询,而非扩大图谱查询范围。
find_symbolspartial ... truncated=1pathname + fileworkspace_qualified_name路径规则: 可以是已索引的项目根目录,也可以是该索引项目内的任意文件/子目录。
path数据流锚点: 需要,可选。可使用:
trace_dataflowsource.anchorsink.anchor- 表示函数参数
param - 表示局部变量
local - 表示函数返回值
return - 搭配
property表示有界属性流access_path
精度控制: 当调用者希望屏蔽较弱的仅解析器生成的结果时,、和支持参数(可选值:, , , )。
inspect_symboltrace_pathsfind_referencesmin_confidencelowinferredexactprecisePhase 3: Present Results
阶段3:结果呈现
- Show MCP tool output directly when available; otherwise present manual findings and mark them as fallback reasoning
- For code snippets referenced in results, use with line ranges when available; otherwise use built-in
hex-line read_fileRead - Suggest follow-up queries based on results:
- After with a clean top match → suggest
find_symbolswithinspect_symbolworkspace_qualified_name - After with
find_symbols→ suggest narrowingpartial ... truncated=1or switching topathbefore any deeper graph toolname + file - After → suggest
inspect_symbolif refactoringtrace_paths - After → suggest
trace_pathsorfind_referencesdepending on symbol kindfind_implementations - After empty from a broad or module-level selector → suggest
trace_pathsorinspect_symbolinstead of assuming there are no dependenciesanalyze_architecture
- 若有可用的MCP工具输出,直接展示;否则呈现手动查找结果并标记为 fallback 推理
- 对于结果中引用的代码片段,若有可用的工具,使用行范围读取;否则使用内置的
hex-line read_file工具Read - 根据结果提供后续查询建议:
- 若返回清晰的顶级匹配结果 → 建议使用
find_symbols调用workspace_qualified_nameinspect_symbol - 若返回
find_symbols→ 建议先缩小partial ... truncated=1范围或切换为path,再进行更深层的图谱工具查询name + file - 若完成查询 → 若涉及重构,建议调用
inspect_symboltrace_paths - 若完成查询 → 根据符号类型,建议调用
trace_paths或find_referencesfind_implementations - 若从宽泛或模块级选择器执行返回空结果 → 建议调用
trace_paths或inspect_symbol,而非假设不存在依赖关系analyze_architecture
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 | 支持工作区感知的定义、调用、导入、未使用导出;若安装了提供者,可启用可选的精确覆盖 |
| C# | .cs | 支持工作区感知的定义、调用、项目/命名空间归属、类型关系;若安装了提供者,可启用可选的精确覆盖 |
| PHP | .php | 支持工作区感知的定义、调用、PSR-4命名空间导入、未使用导出;若安装了提供者,可启用可选的精确覆盖 |
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 or manual fallback map built
- Query results shown to user
- Follow-up suggestions provided
- Fallback path stated when MCP was unavailable
Version: 0.1.0
Last Updated: 2026-03-20
- 已完成项目索引或构建手动 fallback 映射
- 已向用户展示查询结果
- 已提供后续查询建议
- 当MCP不可用时,已说明 fallback 路径
版本: 0.1.0
最后更新: 2026-03-20