Phase 0 through Phase 7: From pre-flight checks to the finished Knowledge Graph with 16 node types and 29 edge types.
Before analysis begins, Phase 0 verifies prerequisites. The incremental checkChecks whether a knowledge-graph.json already exists and whether files have changed since the last run (via Git diff). In incremental mode, only changed files are re-analyzed. is particularly important: Does a Knowledge Graph already exist? If so, which files have changed since the last run?
# Phase 0: Pre-flight checks
pre_flight:
steps:
- check_git_status # Uncommitted changes?
- load_config # .claude-learning/config.json
- check_existing_graph # knowledge-graph.json present?
- compute_diff # git diff --name-only since last run
- decide_mode # full vs. incrementalWhat happens? Phase 0 checks if a prior graph exists. If so, only changed files (via Git diff) are re-analyzed, saving significant time on large projects.
Phase 1 (SCAN) dispatches the project-scanner agent to inventory all code files. Phase 2 (ANALYZE) splits files into batches of 20-30 and dispatches up to five file-analyzer instances in parallel.
Phase 3 merges all batch sub-graphs into a single graph. The assemble-reviewerTakes all batch results (batch-1.json through batch-N.json) and merges them into assembled-graph.json. Deduplicates nodes and resolves cross-batch edges. solves three problems: node deduplication, cross-batch edge resolution, and consistency checks.
# merge-batch-graphs.py — core logic
def merge_graphs(batch_files):
merged = {"nodes": [], "edges": []}
seen_ids = set()
for batch in batch_files:
for node in batch["nodes"]:
if node["id"] not in seen_ids:
merged["nodes"].append(node)
seen_ids.add(node["id"])
return mergedPhase 4 dispatches the architecture-analyzer to identify 3-10 logical layers. Phase 5 dispatches the tour-builder to create an ordered learning path starting from the main entry point.
// After Phase 5: Graph structure
{
"nodes": [/* 16 types, 50-500 nodes */],
"edges": [/* 29 types, 100-2000 edges */],
"layers": [{ "name": "Core" }, { "name": "API" }],
"guided_tour": { "steps": [{ "order": 1, "node_id": "src/index.ts" }] }
}Phase 6 runs final quality validation. The graph-reviewer checks schema conformity, referential integrity, and completeness.
The final phase saves the validated graph as knowledge-graph.json in .claude-learning/. Intermediate files (batch JSONs, assembled-graph.json) are cleaned up. An optional HTML dashboard is auto-generated and launched.
# Phase 7: Save + Cleanup
save:
steps:
- write_knowledge_graph # .claude-learning/knowledge-graph.json
- generate_dashboard # .claude-learning/dashboard.html
- cleanup_intermediate # batch-*.json removed
- auto_launch_dashboard # open in browser