Skip to content

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.

fix(core): classify updates from before and after inventories

Lum110434bab674bfc3
diff --git a/understand-anything-plugin/packages/core/src/__tests__/change-classifier.test.ts b/understand-anything-plugin/packages/core/src/__tests__/change-classifier.test.ts
index dd25373e..5e0eab5c 100644
--- a/understand-anything-plugin/packages/core/src/__tests__/change-classifier.test.ts
+++ b/understand-anything-plugin/packages/core/src/__tests__/change-classifier.test.ts
@@ -95,6 +95,54 @@ describe("classifyUpdate", () => {
expect(decision.rerunArchitecture).toBe(true);
});
+ it("compares explicit before and after inventories for removed directories", () => {
+ const analysis = makeAnalysis({
+ deletedFiles: ["legacy/removed.ts"],
+ });
+
+ const decision = classifyUpdate(
+ analysis,
+ 20,
+ ["src/index.ts", "legacy/removed.ts"],
+ ["src/index.ts"],
+ );
+
+ expect(decision.action).toBe("ARCHITECTURE_UPDATE");
+ expect(decision.filesToReanalyze).toEqual([]);
+ });
+
+ it("keeps deletion-only changes partial when the top-level directory remains", () => {
+ const analysis = makeAnalysis({
+ deletedFiles: ["src/removed.ts"],
+ });
+
+ const decision = classifyUpdate(
+ analysis,
+ 20,
+ ["src/index.ts", "src/removed.ts"],
+ ["src/index.ts"],
+ );
+
+ expect(decision.action).toBe("PARTIAL_UPDATE");
+ expect(decision.filesToReanalyze).toEqual([]);
+ expect(decision.rerunArchitecture).toBe(false);
+ });
+
+ it("normalizes Windows separators when comparing top-level directories", () => {
+ const analysis = makeAnalysis({
+ newFiles: ["src\\new.ts"],
+ });
+
+ const decision = classifyUpdate(
+ analysis,
+ 20,
+ ["src\\existing.ts"],
+ ["src\\existing.ts", "src\\new.ts"],
+ );
+
+ expect(decision.action).toBe("PARTIAL_UPDATE");
+ });
+
it("does NOT trigger ARCHITECTURE_UPDATE for new file in existing directory", () => {
const analysis = makeAnalysis({
newFiles: ["src/newfile.ts"],
diff --git a/understand-anything-plugin/packages/core/src/change-classifier.ts b/understand-anything-plugin/packages/core/src/change-classifier.ts
index e2b9b9eb..eb2773cb 100644
--- a/understand-anything-plugin/packages/core/src/change-classifier.ts
+++ b/understand-anything-plugin/packages/core/src/change-classifier.ts
@@ -21,7 +21,8 @@ export interface UpdateDecision {
export function classifyUpdate(
analysis: ChangeAnalysis,
totalFilesInGraph: number,
- allKnownFiles: string[] = [],
+ previousFiles: string[] = [],
+ currentFiles?: string[],
): UpdateDecision {
const { newFiles, deletedFiles, structurallyChangedFiles, cosmeticOnlyFiles } = analysis;
const structuralCount = structurallyChangedFiles.length + newFiles.length + deletedFiles.length;
@@ -62,7 +63,12 @@ export function classifyUpdate(
}
// Check if directory structure changed (new/deleted top-level directories)
- const hasDirectoryChanges = detectDirectoryChanges(newFiles, deletedFiles, allKnownFiles);
+ const hasDirectoryChanges = detectDirectoryChanges(
+ newFiles,
+ deletedFiles,
+ previousFiles,
+ currentFiles,
+ );
if (hasDirectoryChanges || structuralCount > 10) {
return {
@@ -94,25 +100,40 @@ export function classifyUpdate(
function detectDirectoryChanges(
newFiles: string[],
deletedFiles: string[],
- allKnownFiles: string[],
+ previousFiles: string[],
+ currentFiles?: string[],
): boolean {
- const existingDirs = new Set(
- allKnownFiles.map((f) => topDirectory(f)).filter(Boolean),
- );
-
- for (const f of newFiles) {
- const dir = topDirectory(f);
- if (dir && !existingDirs.has(dir)) return true;
+ // Older callers only provided one inventory. Reconstruct both sides from
+ // the change analysis so that the optional fourth argument remains fully
+ // backwards compatible while still fixing deletion-only directory changes.
+ const before = new Set(previousFiles);
+ for (const file of deletedFiles) before.add(file);
+
+ const after = currentFiles === undefined
+ ? new Set(previousFiles.filter(file => !deletedFiles.includes(file)))
+ : new Set(currentFiles);
+ if (currentFiles === undefined) {
+ for (const file of newFiles) after.add(file);
}
- for (const f of deletedFiles) {
- const dir = topDirectory(f);
- if (dir && !existingDirs.has(dir)) return true;
+ const beforeDirs = topDirectories(before);
+ const afterDirs = topDirectories(after);
+ if (beforeDirs.size !== afterDirs.size) return true;
+ for (const dir of beforeDirs) {
+ if (!afterDirs.has(dir)) return true;
}
-
return false;
}
+function topDirectories(files: Iterable<string>): Set<string> {
+ const dirs = new Set<string>();
+ for (const file of files) {
+ const dir = topDirectory(file.replaceAll("\\", "/"));
+ if (dir) dirs.add(dir);
+ }
+ return dirs;
+}
+
/**
* Get the top-level directory of a file path (first path segment).
*/