understand-diff
它能做什么
分析你的代码改动,帮你了解改了什么、影响了项目的哪些部分,以及可能存在哪些风险。
适用场景
- ✓当你在审查别人的代码时。
- ✓在把你的改动合并到主项目之前。
- ✓当你想了解某个改动的影响范围时。
技能链接
https://github.com/Egonex-AI/Understand-Anything/blob/main/understand-anything-plugin/skills/understand-diff/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“分析这段代码的改动,告诉我可能会受到影响的部分。”
每周 5 个新技能,1 分钟读完。
工作原理
它会把你的代码改动与项目的一张“地图”(即“知识图谱”)进行比对。这张地图展示了不同代码部分之间的关联。随后,它会找出直接被改动的部分,以及可能受这些改动波及的部分。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
/understand-diff
Analyze the current code changes against the knowledge graph in the project's data directory (.ua/knowledge-graph.json, or the legacy .understand-anything/knowledge-graph.json when that directory is present).
Graph Structure Reference
The knowledge graph JSON has this structure:
project— {name, description, languages, frameworks, analyzedAt, gitCommitHash}nodes[]— each has {id, type, name, filePath?, summary, tags[], complexity, languageNotes?}- Code node types: file, function, class, module, concept
- Non-code node types: config, document, service, table, endpoint, pipeline, schema, resource
- Domain/knowledge node types: domain, flow, step, article, entity, topic, claim, source
- IDs use the node type as prefix, e.g.
file:path,function:path:name,config:path,article:path
edges[]— each has {source, target, type, direction, weight}- Key types: imports, contains, calls, depends_on, configures, documents, deploys, triggers, contains_flow, flow_step, related, cites
layers[]— each has {id, name, description, nodeIds[]}tour[]— each has {order, title, description, nodeIds[]}
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
Instructions
Resolve the data directory
$UA_DIR. RunUA_DIR=$([ -d .understand-anything ] && echo .understand-anything || echo .ua)— this is the legacy.understand-anything/when it already exists, otherwise the new.ua/. Check that$UA_DIR/knowledge-graph.jsonexists. If not, tell the user to run/understandfirst.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:
git diff main...HEAD --name-only(or the base branch) - If the user specifies a PR number: get the diff from that PR
- If on a branch with uncommitted changes:
Read project metadata and check graph freshness — use Grep or Read with a line limit to extract the
"project"section, includinggitCommitHashasGRAPH_COMMIT_RAW, then:- Resolve it as a commit before using it in any Git diff. From the project root, compare the resolved commit with
git rev-parse HEADand inspect project-scoped committed and working-tree changes:GRAPH_COMMIT=$(git rev-parse --verify --end-of-options "${GRAPH_COMMIT_RAW}^{commit}" 2>/dev/null) git rev-parse HEAD git diff --name-only "$GRAPH_COMMIT" HEAD -- . git diff --cached --name-only -- . git diff --name-only -- . git ls-files --others --exclude-standard -- . - The
-- .pathspec is required: commits that only touch a sibling monorepo project must not make this graph stale. A hash mismatch alone is not stale when the project diff is empty. - Ignore the selected data directory (
.ua/or legacy.understand-anything/) in every command's output because it contains generated graph artifacts, not project source drift. - If the committed diff or any working-tree command reports project files, warn before impact analysis that the graph may omit those changes. Suggest: Run
/understandto refresh the graph. - Run the commit diff only when
GRAPH_COMMIT_RAWresolves successfully. If the graph commit or Git metadata is missing, invalid, or unavailable, give a brief best-effort warning and continue instead of blocking.
- Resolve it as a commit before using it in any Git diff. From the project root, compare the resolved commit with
Find nodes for changed files — for each changed file path, use Grep to search the knowledge graph for:
- Nodes with matching
"filePath"values (e.g.,grep "changed/file/path") - This finds file-level nodes (including non-code types) AND function/class nodes defined in those files
- Note the
idvalues of all matched nodes
- 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 the
"layers"section to determine which architectural layers are touched.Provide structured analysis:
…
常见问题
什么是“知识图谱”?
它就像一张详细的项目地图,展示了不同代码片段、文件和其他组件之间的关联。
“风险”是什么意思?
风险指的是某个改动可能导致项目其他部分出现问题的可能性。这个工具会尝试找出这些关联,以便提前提醒你潜在的问题。
我需要事先准备好“知识图谱”吗?
需要,这个工具必须依靠这张项目地图才能工作。如果它还不存在,你需要先运行之前的命令来生成它。
详情
作者的原始描述
Use when you need to analyze git diffs or pull requests to understand what changed, affected components, and risks
热度
- GitHub 星标
- 87k
- 排名
- #1366
- 许可证
- MIT
- 更新时间
- 2026/10/12
评论
- …