Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.
TypeScript antigravity-skillsbusiness-knowledgeclaude-codeclaude-skillscodebase-analysiscodexcodex-skillsdeveloper-tools-ai-agentgemini-cli-skillskarpathy-llm-wikiknowledge-baseknowledge-graphmemoryopencode-skillspi-agentunderstandcodevibe-coding
fix(graph): refresh incremental project metadata
Lum110464eb3e142fa0
diff --git a/tests/skill/understand/test_prepare_incremental.test.mjs b/tests/skill/understand/test_prepare_incremental.test.mjsindex c77dff9a..f8684996 100644--- a/tests/skill/understand/test_prepare_incremental.test.mjs+++ b/tests/skill/understand/test_prepare_incremental.test.mjs@@ -433,9 +433,14 @@ describe('prepare-incremental.mjs', { timeout: 30_000 }, () => {const fingerprints = JSON.parse(readFileSync(join(root, '.ua', 'fingerprints.json'), 'utf-8'),);+ const graph = JSON.parse(+ readFileSync(join(root, '.ua', 'knowledge-graph.json'), 'utf-8'),+ );expect(meta.gitCommitHash).toBe(headCommit);expect(fingerprints.gitCommitHash).toBe(headCommit);expect(Object.keys(fingerprints.files)).toHaveLength(4);+ expect(graph.project.gitCommitHash).toBe(headCommit);+ expect(graph.project.analyzedAt).not.toBe('2026-01-01T00:00:00.000Z');});it('removes files newly covered by .understandignore without analyzing them', () => {@@ -658,6 +663,61 @@ describe('finalize-incremental.mjs', { timeout: 30_000 }, () => {expect(readFileSync(metaPath, 'utf-8')).toBe(metaBefore);});+ it('adds a newly introduced language to graph project metadata', () => {+ const { root, baseCommit } = setupRepository({+ 'src/a.ts': 'export const a = 1;\n',+ 'src/b.ts': 'export const b = 2;\n',+ 'src/c.ts': 'export const c = 3;\n',+ 'src/d.ts': 'export const d = 4;\n',+ });+ writeProjectFile(root, 'src/script.py', 'value = 1\n');+ commit(root, 'add first python file');+ prepare(root, baseCommit);++ const intermediate = join(root, '.ua', 'intermediate');+ const retained = JSON.parse(readFileSync(join(intermediate, 'batch-existing.json'), 'utf-8'));+ writeFileSync(+ join(intermediate, 'assembled-graph.json'),+ JSON.stringify({+ nodes: [+ ...retained.nodes,+ {+ id: 'file:src/script.py',+ type: 'file',+ name: 'script.py',+ filePath: 'src/script.py',+ summary: 'Python script',+ tags: ['python'],+ complexity: 'simple',+ },+ ],+ edges: retained.edges,+ }),+ 'utf-8',+ );+ run(process.execPath, [finalizeScript, root], root);++ const graph = JSON.parse(readFileSync(join(root, '.ua', 'knowledge-graph.json'), 'utf-8'));+ expect(graph.project.languages).toEqual(['python', 'typescript']);+ });++ it('removes a language from graph metadata when its last file is deleted', () => {+ const { root, baseCommit } = setupRepository({+ 'src/a.ts': 'export const a = 1;\n',+ 'src/b.ts': 'export const b = 2;\n',+ 'src/c.ts': 'export const c = 3;\n',+ 'src/script.py': 'value = 1\n',+ });+ unlinkSync(join(root, 'src/script.py'));+ commit(root, 'remove last python file');+ prepare(root, baseCommit);+ run(python, [mergeScript, root], root);+ run(process.execPath, [finalizeScript, root], root);++ const graph = JSON.parse(readFileSync(join(root, '.ua', 'knowledge-graph.json'), 'utf-8'));+ expect(graph.project.languages).toEqual(['typescript']);+ });+it('does not advance the baseline when analyzer output omits a changed file node', () => {const { root, baseCommit } = setupRepository({'src/a.ts': 'export const a = 1;\n',diff --git a/understand-anything-plugin/skills/understand/finalize-incremental.mjs b/understand-anything-plugin/skills/understand/finalize-incremental.mjsindex 8208e9c3..38f1724b 100644--- a/understand-anything-plugin/skills/understand/finalize-incremental.mjs+++ b/understand-anything-plugin/skills/understand/finalize-incremental.mjs@@ -315,6 +315,20 @@ function advanceMeta(uaDir, plan, analyzedFiles) {});}+function projectMetadata(previousProject, plan, scan) {+ const languages = [...new Set(+ (scan.files ?? [])+ .map(file => file?.language)+ .filter(language => typeof language === 'string' && language.length > 0),+ )].sort();+ return {+ ...(previousProject ?? {}),+ languages,+ analyzedAt: new Date().toISOString(),+ gitCommitHash: plan.headCommit,+ };+}+function main() {const args = process.argv.slice(2);if (args.length !== 1 || args[0].startsWith('--')) {@@ -339,8 +353,21 @@ function main() {return;}+ const graphPath = join(uaDir, 'knowledge-graph.json');++ if (plan.action === 'SKIP') {+ const previousGraph = readJson(graphPath);+ if (!previousGraph || !Array.isArray(previousGraph.nodes) || !Array.isArray(previousGraph.edges)) {+ throw new Error('knowledge-graph.json is missing or invalid; baseline not advanced');+ }+ atomicWriteJson(graphPath, {+ ...previousGraph,+ project: projectMetadata(previousGraph.project, plan, scan),+ });+ }+if (plan.action !== 'SKIP') {- const previousGraph = readJson(join(uaDir, 'knowledge-graph.json'), {});+ const previousGraph = readJson(graphPath, {});const assembledRaw = readJson(join(intermediateDir, 'assembled-graph.json'));if (!assembledRaw || !Array.isArray(assembledRaw.nodes) || !Array.isArray(assembledRaw.edges)) {throw new Error('assembled-graph.json is missing or invalid; baseline not advanced');@@ -372,9 +399,8 @@ function main() {...previousGraph,version: previousGraph.version ?? '1.0.0',project: {- ...(previousGraph.project ?? {}),+ ...projectMetadata(previousGraph.project, plan, scan),analyzedAt: now,- gitCommitHash: plan.headCommit,},nodes: assembled.nodes,edges: assembled.edges,@@ -384,7 +410,7 @@ function main() {// Ordering is intentional: a failed graph save must never advance the// structural baseline and hide the failed update from the next run.- atomicWriteJson(join(uaDir, 'knowledge-graph.json'), graph);+ atomicWriteJson(graphPath, graph);}patchFingerprints(uaDir, plan, patch);