understand

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/understand

/understand

Analyze the current codebase and produce a
knowledge-graph.json
file in
.understand-anything/
. This file powers the interactive dashboard for exploring the project's architecture.
分析当前代码库并在
.understand-anything/
目录下生成
knowledge-graph.json
文件,该文件为探索项目架构的交互式仪表盘提供数据支持。

Options

选项

  • $ARGUMENTS
    may contain:
    • --full
      — Force a full rebuild, ignoring any existing graph
    • 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.
  1. Set
    PROJECT_ROOT
    to the current working directory.
  2. Get the current git commit hash:
    bash
    git rev-parse HEAD
  3. Create the intermediate output directory:
    bash
    mkdir -p $PROJECT_ROOT/.understand-anything/intermediate
  4. Check if
    $PROJECT_ROOT/.understand-anything/knowledge-graph.json
    exists. If it does, read it.
  5. Check if
    $PROJECT_ROOT/.understand-anything/meta.json
    exists. If it does, read it to get
    gitCommitHash
    .
  6. Decision logic:
    ConditionAction
    --full
    flag in
    $ARGUMENTS
    Full analysis (all phases)
    No existing graph or metaFull analysis (all phases)
    Existing graph + unchanged commit hashReport "Graph is up to date" and STOP
    Existing graph + changed filesIncremental update (re-analyze changed files only)
    For incremental updates, get the changed file list:
    bash
    git diff <lastCommitHash>..HEAD --name-only
    If this returns no files, report "Graph is up to date" and STOP.

确定执行完整分析还是增量更新。
  1. PROJECT_ROOT
    设置为当前工作目录。
  2. 获取当前git提交哈希值:
    bash
    git rev-parse HEAD
  3. 创建中间输出目录:
    bash
    mkdir -p $PROJECT_ROOT/.understand-anything/intermediate
  4. 检查
    $PROJECT_ROOT/.understand-anything/knowledge-graph.json
    是否存在,若存在则读取该文件。
  5. 检查
    $PROJECT_ROOT/.understand-anything/meta.json
    是否存在,若存在则读取其中的
    gitCommitHash
    字段。
  6. 决策逻辑:
    条件操作
    $ARGUMENTS
    中包含
    --full
    参数
    执行完整分析(所有阶段)
    无现有图谱或元数据执行完整分析(所有阶段)
    存在现有图谱且提交哈希未变更提示“图谱已为最新版本”并终止流程
    存在现有图谱且文件已变更执行增量更新(仅重新分析已变更文件)
    对于增量更新,获取变更文件列表:
    bash
    git 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:
$PROJECT_ROOT
Write output to:
$PROJECT_ROOT/.understand-anything/intermediate/scan-result.json
After the agent completes, read
$PROJECT_ROOT/.understand-anything/intermediate/scan-result.json
to get:
  • 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_ROOT
Project:
<projectName>
Languages:
<languages>
Batch index:
<batchIndex>
Write output to:
$PROJECT_ROOT/.understand-anything/intermediate/batch-<batchIndex>.json
All project files (for import resolution):
<full file path list from scan>
Files to analyze in this batch:
  1. <path>
    (<sizeLines> lines)
  2. <path>
    (<sizeLines> lines) ...
After ALL batches complete, read each
batch-<N>.json
file and merge:
  • Combine all
    nodes
    arrays. If duplicate node IDs exist, keep the later occurrence.
  • Combine all
    edges
    arrays. Deduplicate by the composite key
    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
所有项目文件(用于解析导入关系):
<扫描得到的完整文件路径列表>
本组需分析的文件:
  1. <路径>
    <sizeLines> 行)
  2. <路径>
    <sizeLines> 行) ...
所有批次处理完成后,读取每个
batch-<N>.json
文件并合并结果:
  • 合并所有
    nodes
    数组。若存在重复节点ID,保留最后出现的节点。
  • 合并所有
    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:
  1. Remove old nodes whose
    filePath
    matches any changed file
  2. Remove old edges whose
    source
    or
    target
    references a removed node
  3. Add new nodes and edges from the fresh analysis

使用阶段0得到的变更文件列表。按照上述相同流程,仅针对变更文件进行分组并调度file-analyzer agent。
批次处理完成后,将新结果与现有图谱合并:
  1. 删除所有
    filePath
    与变更文件匹配的旧节点
  2. 删除所有
    source
    target
    指向已删除节点的旧边
  3. 添加新分析得到的节点和边

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
    source
    or
    target
    references a node ID that does not exist in the merged node set
  • Remove duplicate node IDs (keep the last occurrence)
  • Log any removed edges or nodes for the final summary

将所有file-analyzer的结果合并为一组节点和边,然后执行基础的完整性清理:
  • 删除所有
    source
    target
    指向合并后节点集中不存在的节点ID的边
  • 移除重复的节点ID(保留最后出现的节点)
  • 记录所有被移除的边或节点,用于最终汇总报告

Phase 4 — ARCHITECTURE

阶段4 — 架构分析

Dispatch the architecture-analyzer agent with this prompt:
Analyze this codebase's structure to identify architectural layers. Project root:
$PROJECT_ROOT
Write output to:
$PROJECT_ROOT/.understand-anything/intermediate/layers.json
Project:
<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
$PROJECT_ROOT/.understand-anything/intermediate/layers.json
to get the layer assignments.
For 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:
$PROJECT_ROOT
Write output to:
$PROJECT_ROOT/.understand-anything/intermediate/tour.json
Project:
<projectName>
<projectDescription>
Languages:
<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
$PROJECT_ROOT/.understand-anything/intermediate/tour.json
to get the tour steps.

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.json
文件获取导览步骤。

Phase 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>]
}
  1. Write the assembled graph to
    $PROJECT_ROOT/.understand-anything/intermediate/assembled-graph.json
    .
  2. Dispatch the graph-reviewer agent with this prompt:
    Validate the knowledge graph at
    $PROJECT_ROOT/.understand-anything/intermediate/assembled-graph.json
    . Project root:
    $PROJECT_ROOT
    Read the file and validate it for completeness and correctness. Write output to:
    $PROJECT_ROOT/.understand-anything/intermediate/review.json
  3. After the agent completes, read
    $PROJECT_ROOT/.understand-anything/intermediate/review.json
    .
  4. If
    approved: false
    :
    • Review the
      issues
      list
    • Apply automated fixes where possible:
      • Remove edges with dangling references
      • Fill missing required fields with sensible defaults (e.g., empty
        tags
        ->
        ["untagged"]
        , empty
        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
  5. If
    approved: true
    :
    Proceed to Phase 7.

组装完整的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得到的导览步骤>]
}
  1. 将组装好的图谱写入
    $PROJECT_ROOT/.understand-anything/intermediate/assembled-graph.json
  2. graph-reviewer agent发送如下指令:
    验证位于
    $PROJECT_ROOT/.understand-anything/intermediate/assembled-graph.json
    的知识图谱。 项目根目录:
    $PROJECT_ROOT
    读取该文件并验证其完整性和正确性。 输出写入路径:
    $PROJECT_ROOT/.understand-anything/intermediate/review.json
  3. Agent完成任务后,读取
    $PROJECT_ROOT/.understand-anything/intermediate/review.json
    文件。
  4. approved: false
    • 查看
      issues
      列表
    • 尽可能应用自动修复:
      • 删除指向不存在节点的边
      • 为缺失的必填字段填充合理默认值(例如,空
        tags
        设为
        ["untagged"]
        ,空
        summary
        设为
        "无可用摘要"
      • 删除类型无效的节点
    • 若经过一次修复尝试后仍存在严重问题,仍保存图谱,但在最终报告中包含警告信息
  5. approved: true
    进入阶段7。

Phase 7 — SAVE

阶段7 — 保存

  1. Write the final knowledge graph to
    $PROJECT_ROOT/.understand-anything/knowledge-graph.json
    .
  2. Write metadata to
    $PROJECT_ROOT/.understand-anything/meta.json
    :
    json
    {
      "lastAnalyzedAt": "<ISO 8601 timestamp>",
      "gitCommitHash": "<commit hash>",
      "version": "1.0.0",
      "analyzedFiles": <number of files analyzed>
    }
  3. Clean up intermediate files:
    bash
    rm -rf $PROJECT_ROOT/.understand-anything/intermediate
  4. 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
  5. Automatically launch the dashboard by invoking the
    /understand-dashboard
    skill.

  1. 将最终知识图谱写入
    $PROJECT_ROOT/.understand-anything/knowledge-graph.json
  2. 将元数据写入
    $PROJECT_ROOT/.understand-anything/meta.json
    json
    {
      "lastAnalyzedAt": "<ISO 8601 timestamp>",
      "gitCommitHash": "<提交哈希>",
      "version": "1.0.0",
      "analyzedFiles": <分析的文件数量>
    }
  3. 清理中间文件:
    bash
    rm -rf $PROJECT_ROOT/.understand-anything/intermediate
  4. 向用户发送包含以下内容的汇总报告:
    • 项目名称和描述
    • 已分析文件数 / 总文件数
    • 已创建的节点数(按类型细分:文件、函数、类)
    • 已创建的边数(按类型细分)
    • 识别出的分层(含名称)
    • 生成的导览步骤数
    • 审核器给出的所有警告
    • 输出文件路径:
      $PROJECT_ROOT/.understand-anything/knowledge-graph.json
  5. 调用
    /understand-dashboard
    skill自动启动仪表盘。

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

节点类型

TypeDescriptionID Convention
file
Source file
file:<relative-path>
function
Function or method
func:<relative-path>:<name>
class
Class, interface, or type
class:<relative-path>:<name>
module
Logical module or package
module:<name>
concept
Abstract concept or pattern
concept:<name>
类型描述ID 命名规则
file
源文件
file:<相对路径>
function
函数或方法
func:<相对路径>:<名称>
class
类、接口或类型
class:<相对路径>:<名称>
module
逻辑模块或包
module:<名称>
concept
抽象概念或模式
concept:<名称>

Edge Types (18 total)

边类型(共18种)

CategoryTypes
Structural
imports
,
exports
,
contains
,
inherits
,
implements
Behavioral
calls
,
subscribes
,
publishes
,
middleware
Data flow
reads_from
,
writes_to
,
transforms
,
validates
Dependencies
depends_on
,
tested_by
,
configures
Semantic
related
,
similar_to
分类类型
结构型
imports
,
exports
,
contains
,
inherits
,
implements
行为型
calls
,
subscribes
,
publishes
,
middleware
数据流型
reads_from
,
writes_to
,
transforms
,
validates
依赖型
depends_on
,
tested_by
,
configures
语义型
related
,
similar_to

Edge Weight Conventions

边权重规则

Edge TypeWeight
contains
1.0
inherits
,
implements
0.9
calls
,
exports
0.8
imports
0.7
depends_on
0.6
tested_by
0.5
All others0.5 (default)
边类型权重
contains
1.0
inherits
,
implements
0.9
calls
,
exports
0.8
imports
0.7
depends_on
0.6
tested_by
0.5
其他所有类型0.5(默认)