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(scan): reject incomplete incremental inventories
Lum110473477db4a132
diff --git a/tests/skill/understand/test_prepare_incremental.test.mjs b/tests/skill/understand/test_prepare_incremental.test.mjsindex fb036e00..9cbbcb30 100644--- a/tests/skill/understand/test_prepare_incremental.test.mjs+++ b/tests/skill/understand/test_prepare_incremental.test.mjs@@ -1,5 +1,6 @@import { afterEach, describe, expect, it } from 'vitest';import {+ chmodSync,mkdirSync,mkdtempSync,readFileSync,@@ -665,6 +666,35 @@ describe('prepare-incremental.mjs', { timeout: 30_000 }, () => {const { plan } = prepare(root, baseCommit);expect(plan.filesToReanalyze).toEqual(['src/a.ts']);});++ it('aborts rather than treating a transient scan read failure as deletion', () => {+ if (process.platform === 'win32' || (process.getuid && process.getuid() === 0)) return;+ 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',+ });+ const graphPath = join(root, '.ua', 'knowledge-graph.json');+ const metaPath = join(root, '.ua', 'meta.json');+ const graphBefore = readFileSync(graphPath, 'utf-8');+ const metaBefore = readFileSync(metaPath, 'utf-8');+ writeProjectFile(root, 'src/a.ts', 'export const renamed = 1;\n');+ commit(root, 'committed structural change');+ chmodSync(join(root, 'src/b.ts'), 0o000);++ const result = spawnSync(process.execPath, [prepareScript, root, baseCommit], {+ cwd: root,+ encoding: 'utf-8',+ });+ chmodSync(join(root, 'src/b.ts'), 0o644);+ expect(result.status).not.toBe(0);+ expect(result.stderr).toMatch(+ /(?:Project scan reported failures|Working tree has relevant uncommitted changes): src\/b\.ts/,+ );+ expect(readFileSync(graphPath, 'utf-8')).toBe(graphBefore);+ expect(readFileSync(metaPath, 'utf-8')).toBe(metaBefore);+ });});describe('finalize-incremental.mjs', { timeout: 30_000 }, () => {diff --git a/tests/skill/understand/test_scan_project.test.mjs b/tests/skill/understand/test_scan_project.test.mjsindex 7618ae7e..9c0817f2 100644--- a/tests/skill/understand/test_scan_project.test.mjs+++ b/tests/skill/understand/test_scan_project.test.mjs@@ -719,6 +719,7 @@ describe('scan-project.mjs — empty repo', () => {const r = runScript(projectRoot);expect(r.status).toBe(0);expect(r.output.scriptCompleted).toBe(true);+ expect(r.output.failures).toEqual([]);expect(r.output.totalFiles).toBe(0);expect(r.output.files).toEqual([]);expect(r.output.filteredByIgnore).toBe(0);@@ -762,6 +763,9 @@ describe('scan-project.mjs — per-file failure resilience', () => {const r = runScript(projectRoot);expect(r.status).toBe(0);expect(r.output.scriptCompleted).toBe(true);+ expect(r.output.failures).toEqual([+ expect.objectContaining({ path: 'src/unreadable.ts', stage: 'file-read' }),+ ]);// The good file is in the output.expect(byPath(r.output, 'src/good.ts')).toBeDefined();// The unreadable file is dropped.@@ -907,6 +911,7 @@ describe('scan-project.mjs — output schema invariants', () => {out.estimatedComplexity,);expect(out.stats).toBeDefined();+ expect(out.failures).toEqual([]);expect(out.stats.filesScanned).toBe(out.files.length);expect(typeof out.stats.byCategory).toBe('object');expect(typeof out.stats.byLanguage).toBe('object');diff --git a/understand-anything-plugin/skills/understand/prepare-incremental.mjs b/understand-anything-plugin/skills/understand/prepare-incremental.mjsindex c5b16322..3674248b 100644--- a/understand-anything-plugin/skills/understand/prepare-incremental.mjs+++ b/understand-anything-plugin/skills/understand/prepare-incremental.mjs@@ -24,6 +24,7 @@ import { dirname, basename, isAbsolute, join, resolve } from 'node:path';import { fileURLToPath, pathToFileURL } from 'node:url';import {existsSync,+ lstatSync,mkdirSync,readdirSync,readFileSync,@@ -219,6 +220,14 @@ function relevantWorktreeChanges(projectRoot, excludePatterns) {});}+function isTrackedSymlink(projectRoot, filePath) {+ try {+ return lstatSync(join(projectRoot, filePath)).isSymbolicLink();+ } catch {+ return false;+ }+}+function normalizeFingerprintStore(raw, baseCommit) {if (raw && raw.files && typeof raw.files === 'object' && !Array.isArray(raw.files)) {return raw;@@ -509,6 +518,15 @@ async function main() {const currentScanPath = join(intermediateDir, 'current-scan.json');const currentScan = runScan(projectRoot, currentScanPath, args.excludePatterns);+ const scanFailures = Array.isArray(currentScan?.failures) ? currentScan.failures : [];+ if (scanFailures.length > 0) {+ const preview = scanFailures+ .slice(0, 5)+ .map(failure => `${failure.path ?? '<global>'} (${failure.stage})`)+ .join(', ');+ const suffix = scanFailures.length > 5 ? ` (+${scanFailures.length - 5} more)` : '';+ throw new Error(`Project scan reported failures: ${preview}${suffix}`);+ }const currentInventory = sorted(currentScan.files.map(file => file.path));const currentInventorySet = new Set(currentInventory);// If a previous attempt saved the graph but failed before fingerprints/meta,@@ -521,6 +539,24 @@ async function main() {const inventoryGraph = graphMatchesUncommittedHead ? {} : graph;const oldInventory = inventoryFrom(baselineScan, inventoryGraph, oldFingerprints);const oldInventorySet = new Set(oldInventory);+ const trackedPaths = new Set(parseNulPaths(run(+ 'git',+ ['ls-files', '--cached', '-z', '--', '.'],+ { cwd: projectRoot },+ )));+ const currentIgnoreFilter = createIgnoreFilter(projectRoot, args.excludePatterns);+ const unexplainedMissingFiles = oldInventory.filter(path =>+ !currentInventorySet.has(path)+ && trackedPaths.has(path)+ && !currentIgnoreFilter.isIgnored(path)+ && !isTrackedSymlink(projectRoot, path),+ );+ if (unexplainedMissingFiles.length > 0) {+ throw new Error(+ `Project scan omitted tracked, non-ignored files: ` ++ `${unexplainedMissingFiles.slice(0, 10).join(', ')}. Baseline not advanced.`,+ );+ }const generatedArtifactFiles = sorted(diffPaths.filter(isGeneratedArtifact));const nonGeneratedDiffPaths = diffPaths.filter(path => !isGeneratedArtifact(path));diff --git a/understand-anything-plugin/skills/understand/scan-project.mjs b/understand-anything-plugin/skills/understand/scan-project.mjsindex c6e3d677..9c6d5cb2 100644--- a/understand-anything-plugin/skills/understand/scan-project.mjs+++ b/understand-anything-plugin/skills/understand/scan-project.mjs@@ -649,7 +649,7 @@ function hasUserIgnoreFile(projectRoot) {* Per-file failure: emits a Warning: and returns null. Caller decides* whether to drop the file or keep it with sizeLines=0.*/-function readAndCountLines(absPath, posixPath) {+function readAndCountLines(absPath, posixPath, failures) {try {const buf = readFileSync(absPath);// Manual newline count beats split('\n').length on large files — no@@ -660,6 +660,7 @@ function readAndCountLines(absPath, posixPath) {}return { bytes: buf, sizeLines: count };} catch (err) {+ failures.push({ path: posixPath, stage: 'file-read', message: err.message });process.stderr.write(`Warning: scan-project: ${posixPath} — line count failed ` +`(${err.message}) — file skipped from output\n`,@@ -757,6 +758,8 @@ async function main() {process.exit(1);}+ const failures = [];+// 1. Enumerate. Either git ls-files or recursive walk.const candidates = enumerateFiles(projectRoot).filter(rel =>@@ -814,13 +817,14 @@ async function main() {continue;}} catch (err) {+ failures.push({ path: rel, stage: 'file-lstat', message: err.message });process.stderr.write(`Warning: scan-project: ${rel} — lstat failed (${err.message}) ` +`— file skipped from output\n`,);continue;}- const scanned = readAndCountLines(absPath, rel);+ const scanned = readAndCountLines(absPath, rel, failures);if (scanned === null) {// readAndCountLines already emitted the Warning: line.continue;@@ -855,6 +859,7 @@ async function main() {totalFiles: fileEntries.length,filteredByIgnore,estimatedComplexity,+ failures,stats: {filesScanned: fileEntries.length,byCategory,