| name | understand-diff |
| description | Use when you need to analyze git diffs or pull requests to understand what changed, affected components, and risks |
/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. Run UA_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.json exists. If not, tell the user to run /understand first.
-
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
-
Read project metadata and check graph freshness — use Grep or Read with a line limit to extract the "project" section, including gitCommitHash as GRAPH_COMMIT_RAW, then: