understand
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/understand
/understand
Analyze the current codebase and produce a file in . This file powers the interactive dashboard for exploring the project's architecture.
knowledge-graph.json.understand-anything/分析当前代码库并在目录下生成文件,该文件为探索项目架构的交互式仪表盘提供数据支持。
.understand-anything/knowledge-graph.jsonOptions
选项
- may contain:
$ARGUMENTS- — Force a full rebuild, ignoring any existing graph
--full - A directory path — Scope analysis to a specific subdirectory
- 可包含以下内容:
$ARGUMENTS- — 强制完全重建,忽略已有的图谱
--full - 目录路径 — 将分析范围限定在指定子目录内
Phase 0 — Pre-flight
阶段0 — 预检查
Determine whether to run a full analysis or incremental update.
-
Setto the current working directory.
PROJECT_ROOT -
Get the current git commit hash:bash
git rev-parse HEAD -
Create the intermediate output directory:bash
mkdir -p $PROJECT_ROOT/.understand-anything/intermediate -
Check ifexists. If it does, read it.
$PROJECT_ROOT/.understand-anything/knowledge-graph.json -
Check ifexists. If it does, read it to get
$PROJECT_ROOT/.understand-anything/meta.json.gitCommitHash -
Decision logic:
Condition Action flag in--full$ARGUMENTSFull analysis (all phases) No existing graph or meta Full analysis (all phases) Existing graph + unchanged commit hash Report "Graph is up to date" and STOP Existing graph + changed files Incremental update (re-analyze changed files only) For incremental updates, get the changed file list:bashgit diff <lastCommitHash>..HEAD --name-onlyIf this returns no files, report "Graph is up to date" and STOP.
确定执行完整分析还是增量更新。
-
将设置为当前工作目录。
PROJECT_ROOT -
获取当前git提交哈希值:bash
git rev-parse HEAD -
创建中间输出目录:bash
mkdir -p $PROJECT_ROOT/.understand-anything/intermediate -
检查是否存在,若存在则读取该文件。
$PROJECT_ROOT/.understand-anything/knowledge-graph.json -
检查是否存在,若存在则读取其中的
$PROJECT_ROOT/.understand-anything/meta.json字段。gitCommitHash -
决策逻辑:
条件 操作 中包含$ARGUMENTS参数--full执行完整分析(所有阶段) 无现有图谱或元数据 执行完整分析(所有阶段) 存在现有图谱且提交哈希未变更 提示“图谱已为最新版本”并终止流程 存在现有图谱且文件已变更 执行增量更新(仅重新分析已变更文件) 对于增量更新,获取变更文件列表:bashgit diff <lastCommitHash>..HEAD --name-only若该命令未返回任何文件,提示“图谱已为最新版本”并终止流程。
Phase 1 — SCAN (Full analysis only)
阶段1 — 扫描(仅完整分析)
Dispatch the project-scanner agent with this prompt:
Scan this project directory to discover all source files, detect languages and frameworks. Project root:Write output to:$PROJECT_ROOT$PROJECT_ROOT/.understand-anything/intermediate/scan-result.json
After the agent completes, read to get:
$PROJECT_ROOT/.understand-anything/intermediate/scan-result.json- Project name, description
- Languages, frameworks
- File list with line counts
- Complexity estimate
Gate check: If >200 files, inform the user and suggest scoping with a subdirectory argument. Proceed only if user confirms or add guidance that this may take a while.
向project-scanner agent发送如下指令:
扫描此项目目录,发现所有源文件,检测使用的语言和框架。 项目根目录:输出写入路径:$PROJECT_ROOT$PROJECT_ROOT/.understand-anything/intermediate/scan-result.json
Agent完成任务后,读取文件,获取以下信息:
$PROJECT_ROOT/.understand-anything/intermediate/scan-result.json- 项目名称、描述
- 使用的语言、框架
- 带行数统计的文件列表
- 复杂度评估
检查点: 若文件数量超过200个,告知用户并建议通过子目录参数限定分析范围。仅在用户确认或提示用户分析可能耗时较久后,方可继续执行。
Phase 2 — ANALYZE
阶段2 — 分析
Full analysis path
完整分析流程
Batch the file list from Phase 1 into groups of 5-10 files each (aim for balanced batch sizes).
For each batch, dispatch a file-analyzer agent. Run up to 3 agents concurrently using parallel dispatch. Each agent gets this prompt:
Analyze these source files and produce GraphNode and GraphEdge objects. Project root:Project:$PROJECT_ROOTLanguages:<projectName>Batch index:<languages>Write output to:<batchIndex>$PROJECT_ROOT/.understand-anything/intermediate/batch-<batchIndex>.jsonAll project files (for import resolution):<full file path list from scan>Files to analyze in this batch:
(<sizeLines> lines)<path> (<sizeLines> lines) ...<path>
After ALL batches complete, read each file and merge:
batch-<N>.json- Combine all arrays. If duplicate node IDs exist, keep the later occurrence.
nodes - Combine all arrays. Deduplicate by the composite key
edges.source + target + type
将阶段1得到的文件列表分成每组5-10个文件(尽量保证每组文件数量均衡)。
针对每个文件组,调度file-analyzer agent执行任务。最多同时调度3个agent并行处理。每个agent将收到如下指令:
分析这些源文件并生成GraphNode和GraphEdge对象。 项目根目录:项目:$PROJECT_ROOT使用语言:<projectName>批次索引:<languages>输出写入路径:<batchIndex>$PROJECT_ROOT/.understand-anything/intermediate/batch-<batchIndex>.json所有项目文件(用于解析导入关系):<扫描得到的完整文件路径列表>本组需分析的文件:
(<sizeLines> 行)<路径> (<sizeLines> 行) ...<路径>
所有批次处理完成后,读取每个文件并合并结果:
batch-<N>.json- 合并所有数组。若存在重复节点ID,保留最后出现的节点。
nodes - 合并所有数组。根据复合键
edges进行去重。source + target + type
Incremental update path
增量更新流程
Use the changed files list from Phase 0. Batch and dispatch file-analyzer agents using the same process as above, but only for changed files.
After batches complete, merge with the existing graph:
- Remove old nodes whose matches any changed file
filePath - Remove old edges whose or
sourcereferences a removed nodetarget - Add new nodes and edges from the fresh analysis
使用阶段0得到的变更文件列表。按照上述相同流程,仅针对变更文件进行分组并调度file-analyzer agent。
批次处理完成后,将新结果与现有图谱合并:
- 删除所有与变更文件匹配的旧节点
filePath - 删除所有或
source指向已删除节点的旧边target - 添加新分析得到的节点和边
Phase 3 — ASSEMBLE
阶段3 — 组装
Merge all file-analyzer results into a single set of nodes and edges. Then perform basic integrity cleanup:
- Remove any edge whose or
sourcereferences a node ID that does not exist in the merged node settarget - Remove duplicate node IDs (keep the last occurrence)
- Log any removed edges or nodes for the final summary
将所有file-analyzer的结果合并为一组节点和边,然后执行基础的完整性清理:
- 删除所有或
source指向合并后节点集中不存在的节点ID的边target - 移除重复的节点ID(保留最后出现的节点)
- 记录所有被移除的边或节点,用于最终汇总报告
Phase 4 — ARCHITECTURE
阶段4 — 架构分析
Dispatch the architecture-analyzer agent with this prompt:
Analyze this codebase's structure to identify architectural layers. Project root:Write output to:$PROJECT_ROOTProject:$PROJECT_ROOT/.understand-anything/intermediate/layers.json—<projectName><projectDescription>File nodes:json[list of {id, name, filePath, summary, tags} for all file-type nodes]Import edges:json[list of edges with type "imports"]
After the agent completes, read to get the layer assignments.
$PROJECT_ROOT/.understand-anything/intermediate/layers.jsonFor incremental updates: Always re-run architecture analysis on the full merged node set, since layer assignments may shift when files change.
向architecture-analyzer agent发送如下指令:
分析此代码库的结构,识别架构分层。 项目根目录:输出写入路径:$PROJECT_ROOT项目:$PROJECT_ROOT/.understand-anything/intermediate/layers.json—<projectName><projectDescription>文件节点:json[所有文件类型节点的{id, name, filePath, summary, tags}列表]导入边:json[所有类型为"imports"的边列表]
Agent完成任务后,读取文件获取分层分配结果。
$PROJECT_ROOT/.understand-anything/intermediate/layers.json增量更新注意事项: 始终基于合并后的完整节点集重新执行架构分析,因为文件变更可能导致分层分配发生变化。
Phase 5 — TOUR
阶段5 — 导览生成
Dispatch the tour-builder agent with this prompt:
Create a guided learning tour for this codebase. Project root:Write output to:$PROJECT_ROOTProject:$PROJECT_ROOT/.understand-anything/intermediate/tour.json—<projectName>Languages:<projectDescription><languages>Nodes (summarized):json[list of {id, name, filePath, summary, type} for key nodes]Layers:json[layers from Phase 4]Key edges:json[imports and calls edges]
After the agent completes, read to get the tour steps.
$PROJECT_ROOT/.understand-anything/intermediate/tour.json向tour-builder agent发送如下指令:
为此代码库创建一个引导式学习导览。 项目根目录:输出写入路径:$PROJECT_ROOT项目:$PROJECT_ROOT/.understand-anything/intermediate/tour.json—<projectName>使用语言:<projectDescription><languages>节点(摘要版):json[关键节点的{id, name, filePath, summary, type}列表]分层:json[阶段4得到的分层结果]关键边:json[导入和调用类型的边列表]
Agent完成任务后,读取文件获取导览步骤。
$PROJECT_ROOT/.understand-anything/intermediate/tour.jsonPhase 6 — REVIEW
阶段6 — 审核
Assemble the full KnowledgeGraph JSON object:
json
{
"version": "1.0.0",
"project": {
"name": "<projectName>",
"languages": ["<languages>"],
"frameworks": ["<frameworks>"],
"description": "<projectDescription>",
"analyzedAt": "<ISO 8601 timestamp>",
"gitCommitHash": "<commit hash from Phase 0>"
},
"nodes": [<all merged nodes from Phase 3>],
"edges": [<all merged edges from Phase 3>],
"layers": [<layers from Phase 4>],
"tour": [<steps from Phase 5>]
}-
Write the assembled graph to.
$PROJECT_ROOT/.understand-anything/intermediate/assembled-graph.json -
Dispatch the graph-reviewer agent with this prompt:Validate the knowledge graph at. Project root:
$PROJECT_ROOT/.understand-anything/intermediate/assembled-graph.jsonRead the file and validate it for completeness and correctness. Write output to:$PROJECT_ROOT$PROJECT_ROOT/.understand-anything/intermediate/review.json -
After the agent completes, read.
$PROJECT_ROOT/.understand-anything/intermediate/review.json -
If:
approved: false- Review the list
issues - Apply automated fixes where possible:
- Remove edges with dangling references
- Fill missing required fields with sensible defaults (e.g., empty ->
tags, empty["untagged"]->summary)"No summary available" - Remove nodes with invalid types
- If critical issues remain after one fix attempt, save the graph anyway but include the warnings in the final report
- Review the
-
If: Proceed to Phase 7.
approved: true
组装完整的KnowledgeGraph JSON对象:
json
{
"version": "1.0.0",
"project": {
"name": "<projectName>",
"languages": ["<languages>"],
"frameworks": ["<frameworks>"],
"description": "<projectDescription>",
"analyzedAt": "<ISO 8601 timestamp>",
"gitCommitHash": "<阶段0获取的提交哈希>"
},
"nodes": [<阶段3合并后的所有节点>],
"edges": [<阶段3合并后的所有边>],
"layers": [<阶段4得到的分层>],
"tour": [<阶段5得到的导览步骤>]
}-
将组装好的图谱写入。
$PROJECT_ROOT/.understand-anything/intermediate/assembled-graph.json -
向graph-reviewer agent发送如下指令:验证位于的知识图谱。 项目根目录:
$PROJECT_ROOT/.understand-anything/intermediate/assembled-graph.json读取该文件并验证其完整性和正确性。 输出写入路径:$PROJECT_ROOT$PROJECT_ROOT/.understand-anything/intermediate/review.json -
Agent完成任务后,读取文件。
$PROJECT_ROOT/.understand-anything/intermediate/review.json -
若:
approved: false- 查看列表
issues - 尽可能应用自动修复:
- 删除指向不存在节点的边
- 为缺失的必填字段填充合理默认值(例如,空设为
tags,空["untagged"]设为summary)"无可用摘要" - 删除类型无效的节点
- 若经过一次修复尝试后仍存在严重问题,仍保存图谱,但在最终报告中包含警告信息
- 查看
-
若: 进入阶段7。
approved: true
Phase 7 — SAVE
阶段7 — 保存
-
Write the final knowledge graph to.
$PROJECT_ROOT/.understand-anything/knowledge-graph.json -
Write metadata to:
$PROJECT_ROOT/.understand-anything/meta.jsonjson{ "lastAnalyzedAt": "<ISO 8601 timestamp>", "gitCommitHash": "<commit hash>", "version": "1.0.0", "analyzedFiles": <number of files analyzed> } -
Clean up intermediate files:bash
rm -rf $PROJECT_ROOT/.understand-anything/intermediate -
Report a summary to the user containing:
- Project name and description
- Files analyzed / total files
- Nodes created (broken down by type: file, function, class)
- Edges created (broken down by type)
- Layers identified (with names)
- Tour steps generated (count)
- Any warnings from the reviewer
- Path to the output file:
$PROJECT_ROOT/.understand-anything/knowledge-graph.json
-
Automatically launch the dashboard by invoking theskill.
/understand-dashboard
-
将最终知识图谱写入。
$PROJECT_ROOT/.understand-anything/knowledge-graph.json -
将元数据写入:
$PROJECT_ROOT/.understand-anything/meta.jsonjson{ "lastAnalyzedAt": "<ISO 8601 timestamp>", "gitCommitHash": "<提交哈希>", "version": "1.0.0", "analyzedFiles": <分析的文件数量> } -
清理中间文件:bash
rm -rf $PROJECT_ROOT/.understand-anything/intermediate -
向用户发送包含以下内容的汇总报告:
- 项目名称和描述
- 已分析文件数 / 总文件数
- 已创建的节点数(按类型细分:文件、函数、类)
- 已创建的边数(按类型细分)
- 识别出的分层(含名称)
- 生成的导览步骤数
- 审核器给出的所有警告
- 输出文件路径:
$PROJECT_ROOT/.understand-anything/knowledge-graph.json
-
调用skill自动启动仪表盘。
/understand-dashboard
Error Handling
错误处理
- If any agent dispatch fails, retry once with the same prompt plus additional context about the failure.
- If it fails a second time, skip that phase and continue with partial results.
- ALWAYS save partial results — a partial graph is better than no graph.
- Report any skipped phases or errors in the final summary so the user knows what happened.
- NEVER silently drop errors. Every failure must be visible in the final report.
- 若任何agent调度失败,重试一次,使用相同指令并添加失败相关的额外上下文。
- 若第二次仍失败,跳过该阶段并继续处理部分结果。
- 始终保存部分结果 — 不完整的图谱总比没有图谱好。
- 在最终汇总报告中说明所有跳过的阶段或错误,让用户了解情况。
- 绝不静默忽略错误。所有失败必须在最终报告中可见。
Reference: KnowledgeGraph Schema
参考:KnowledgeGraph Schema
Node Types
节点类型
| Type | Description | ID Convention |
|---|---|---|
| Source file | |
| Function or method | |
| Class, interface, or type | |
| Logical module or package | |
| Abstract concept or pattern | |
| 类型 | 描述 | ID 命名规则 |
|---|---|---|
| 源文件 | |
| 函数或方法 | |
| 类、接口或类型 | |
| 逻辑模块或包 | |
| 抽象概念或模式 | |
Edge Types (18 total)
边类型(共18种)
| Category | Types |
|---|---|
| Structural | |
| Behavioral | |
| Data flow | |
| Dependencies | |
| Semantic | |
| 分类 | 类型 |
|---|---|
| 结构型 | |
| 行为型 | |
| 数据流型 | |
| 依赖型 | |
| 语义型 | |
Edge Weight Conventions
边权重规则
| Edge Type | Weight |
|---|---|
| 1.0 |
| 0.9 |
| 0.8 |
| 0.7 |
| 0.6 |
| 0.5 |
| All others | 0.5 (default) |
| 边类型 | 权重 |
|---|---|
| 1.0 |
| 0.9 |
| 0.8 |
| 0.7 |
| 0.6 |
| 0.5 |
| 其他所有类型 | 0.5(默认) |