understand-diff
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese/understand-diff
/understand-diff
Analyze the current code changes against the knowledge graph at .
.understand-anything/knowledge-graph.json针对中的知识图谱,分析当前代码变更。
.understand-anything/knowledge-graph.jsonGraph Structure Reference
图谱结构参考
The knowledge graph JSON has this structure:
- — {name, description, languages, frameworks, analyzedAt, gitCommitHash}
project - — each has {id, type, name, filePath, summary, tags[], complexity, languageNotes?}
nodes[]- Node types: file, function, class, module, concept
- IDs: ,
file:path,function:path:nameclass:path:name
- — each has {source, target, type, direction, weight}
edges[]- Key types: imports, contains, calls, depends_on
- — each has {id, name, description, nodeIds[]}
layers[] - — each has {order, title, description, nodeIds[]}
tour[]
知识图谱JSON的结构如下:
- — {name, description, languages, frameworks, analyzedAt, gitCommitHash}
project - — 每个节点包含{id, type, name, filePath, summary, tags[], complexity, languageNotes?}
nodes[]- 节点类型:file、function、class、module、concept
- ID格式:、
file:path、function:path:nameclass:path:name
- — 每条边包含{source, target, type, direction, weight}
edges[]- 主要类型:imports、contains、calls、depends_on
- — 每个层级包含{id, name, description, nodeIds[]}
layers[] - — 每个导览项包含{order, title, description, nodeIds[]}
tour[]
How to Read Efficiently
高效阅读方法
- Use Grep to search within the JSON for relevant entries BEFORE reading the full file
- Only read sections you need — don't dump the entire graph into context
- Node names and summaries are the most useful fields for understanding
- Edges tell you how components connect — follow imports and calls for dependency chains
- 在阅读完整文件前,使用Grep在JSON中搜索相关条目
- 只阅读你需要的部分——不要将整个图谱都加载到上下文里
- 节点名称和摘要对于理解内容是最有用的字段
- 边信息展示了组件之间的关联——通过imports和calls跟踪依赖链
Instructions
操作步骤
-
Check thatexists. If not, tell the user to run
.understand-anything/knowledge-graph.jsonfirst./understand -
Get the changed files list (do NOT read the graph yet):
- If on a branch with uncommitted changes:
git diff --name-only - If on a feature branch: (or the base branch)
git diff main...HEAD --name-only - If the user specifies a PR number: get the diff from that PR
- If on a branch with uncommitted changes:
-
Read project metadata only — use Grep or Read with a line limit to extract just thesection for context.
"project" -
Find nodes for changed files — for each changed file path, use Grep to search the knowledge graph for:
- Nodes with matching values (e.g.,
"filePath")grep "changed/file/path" - This finds file nodes AND function/class nodes defined in those files
- Note the values of all matched nodes
id
- Nodes with matching
-
Find connected edges (1-hop) — for each matched node ID, Grep for that ID in the edges to find:
- What imports or depends on the changed nodes (upstream callers)
- What the changed nodes import or call (downstream dependencies)
- These are the "affected components" — things that might break or need updating
-
Identify affected layers — Grep for the matched node IDs in thesection to determine which architectural layers are touched.
"layers" -
Provide structured analysis:
- Changed Components: What was directly modified (with summaries from matched nodes)
- Affected Components: What might be impacted (from 1-hop edges)
- Affected Layers: Which architectural layers are touched and cross-layer concerns
- Risk Assessment: Based on node values, number of cross-layer edges, and blast radius (number of affected components)
complexity - Suggest what to review carefully and any potential issues
-
Write diff overlay for dashboard — after producing the analysis, write the diff data toso the dashboard can visualize changed and affected components. The file contains:
.understand-anything/diff-overlay.jsonjson{ "version": "1.0.0", "baseBranch": "<the base branch used>", "generatedAt": "<ISO timestamp>", "changedFiles": ["<list of changed file paths>"], "changedNodeIds": ["<node IDs from step 4>"], "affectedNodeIds": ["<node IDs from step 5, excluding changedNodeIds>"] }After writing, tell the user they can runto see the diff overlay visually./understand-anything:understand-dashboard
-
检查是否存在。如果不存在,告知用户先运行
.understand-anything/knowledge-graph.json。/understand -
获取变更文件列表(此时不要读取图谱):
- 如果分支有未提交的变更:
git diff --name-only - 如果在功能分支上:(或对应的基础分支)
git diff main...HEAD --name-only - 如果用户指定了PR编号:获取该PR的diff
- 如果分支有未提交的变更:
-
仅读取项目元数据——使用Grep或限制行数的方式,仅提取部分作为上下文。
"project" -
查找变更文件对应的节点——对于每个变更文件路径,使用Grep在知识图谱中搜索:
- 匹配值的节点(例如:
"filePath")grep "changed/file/path" - 这会找到文件节点以及这些文件中定义的函数/类节点
- 记录所有匹配节点的值
id
- 匹配
-
查找关联的边(1跳)——对于每个匹配的节点ID,在edges中Grep该ID,以找到:
- 哪些组件导入或依赖变更的节点(上游调用者)
- 变更的节点导入或调用了哪些组件(下游依赖)
- 这些就是“受影响组件”——可能会出现故障或需要更新的部分
-
识别受影响的层级——在部分Grep匹配的节点ID,确定涉及哪些架构层级。
"layers" -
提供结构化分析:
- 变更组件:直接修改的内容(来自匹配节点的摘要)
- 受影响组件:可能受到影响的内容(来自1跳边的结果)
- 受影响层级:涉及的架构层级以及跨层级关注点
- 风险评估:基于节点的值、跨层级边的数量,以及影响范围(受影响组件的数量)
complexity - 建议需要重点评审的内容和潜在问题
-
为仪表板编写diff覆盖层——完成分析后,将diff数据写入,以便仪表板可以可视化变更和受影响的组件。该文件的格式如下:
.understand-anything/diff-overlay.jsonjson{ "version": "1.0.0", "baseBranch": "<the base branch used>", "generatedAt": "<ISO timestamp>", "changedFiles": ["<list of changed file paths>"], "changedNodeIds": ["<node IDs from step 4>"], "affectedNodeIds": ["<node IDs from step 5, excluding changedNodeIds>"] }写入完成后,告知用户可以运行来可视化查看diff覆盖层。",/understand-anything:understand-dashboard