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(fingerprints): classify non-code edits conservatively
Lum110419075e0ab604
diff --git a/tests/skill/understand/test_prepare_incremental.test.mjs b/tests/skill/understand/test_prepare_incremental.test.mjsindex 67a929eb..023ed2e6 100644--- a/tests/skill/understand/test_prepare_incremental.test.mjs+++ b/tests/skill/understand/test_prepare_incremental.test.mjs@@ -417,6 +417,24 @@ describe('prepare-incremental.mjs', { timeout: 30_000 }, () => {expect(plan.reason).toContain('structural changes');});+ it('treats parsed non-code content changes as structural', () => {+ 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',+ 'docs/guide.md': '# Guide\n\nOld body.\n',+ });+ const fingerprints = JSON.parse(+ readFileSync(join(root, '.ua', 'fingerprints.json'), 'utf-8'),+ );+ expect(fingerprints.files['docs/guide.md'].hasStructuralAnalysis).toBe(false);+ writeProjectFile(root, 'docs/guide.md', '# Guide\n\nNew body.\n');+ commit(root, 'update parsed non-code content');++ const { plan } = prepare(root, baseCommit);+ expect(plan.filesToReanalyze).toEqual(['docs/guide.md']);+ });+it('classifies implementation-only edits as SKIP and advances fingerprints via finalize', () => {const { root, baseCommit } = setupRepository({'src/a.ts': 'export function value() { return 1; }\n',diff --git a/understand-anything-plugin/packages/core/src/__tests__/fingerprint.test.ts b/understand-anything-plugin/packages/core/src/__tests__/fingerprint.test.tsindex 6cd95338..c093d997 100644--- a/understand-anything-plugin/packages/core/src/__tests__/fingerprint.test.ts+++ b/understand-anything-plugin/packages/core/src/__tests__/fingerprint.test.ts@@ -5,6 +5,7 @@ import {extractFileFingerprint,compareFingerprints,analyzeChanges,+ buildFingerprintStore,type FileFingerprint,type FingerprintStore,} from "../fingerprint.js";@@ -24,6 +25,34 @@ beforeEach(() => {vi.clearAllMocks();});+describe("buildFingerprintStore", () => {+ it("uses content-only fingerprints when parser structure is not fully represented", () => {+ mockedExistsSync.mockReturnValue(true);+ mockedReadFileSync.mockReturnValue('{"enabled":true}');+ const registry = {+ analyzeFile: vi.fn().mockReturnValue({+ functions: [],+ classes: [],+ imports: [],+ exports: [],+ definitions: [{ name: "enabled", kind: "property" }],+ }),+ getLanguageForFile: vi.fn().mockReturnValue("json"),+ } as any;++ const store = buildFingerprintStore(+ "/project",+ ["config.json"],+ registry,+ "abc123",+ { structuralFingerprintLanguages: new Set(["typescript"]) },+ );++ expect(store.files["config.json"].hasStructuralAnalysis).toBe(false);+ expect(store.files["config.json"].contentHash).toBe(contentHash('{"enabled":true}'));+ });+});+describe("contentHash", () => {it("produces consistent SHA-256 hashes", () => {const hash1 = contentHash("hello world");diff --git a/understand-anything-plugin/packages/core/src/fingerprint.ts b/understand-anything-plugin/packages/core/src/fingerprint.tsindex cc66dd0f..a43242c4 100644--- a/understand-anything-plugin/packages/core/src/fingerprint.ts+++ b/understand-anything-plugin/packages/core/src/fingerprint.ts@@ -45,6 +45,15 @@ export interface FingerprintStore {files: Record<string, FileFingerprint>;}+export interface FingerprintBuildOptions {+ /**+ * Languages whose StructuralAnalysis fields are fully represented by+ * FileFingerprint. Other languages receive content-only fingerprints so a+ * content change is classified conservatively instead of as cosmetic.+ */+ structuralFingerprintLanguages?: ReadonlySet<string>;+}+export type ChangeLevel = "NONE" | "COSMETIC" | "STRUCTURAL";export interface FileChangeResult {@@ -255,6 +264,7 @@ export function buildFingerprintStore(filePaths: string[],registry: PluginRegistry,gitCommitHash: string,+ options: FingerprintBuildOptions = {},): FingerprintStore {const files: Record<string, FileFingerprint> = {};@@ -264,8 +274,14 @@ export function buildFingerprintStore(const content = readFileSync(absolutePath, "utf-8");const analysis = registry.analyzeFile(filePath, content);+ let fingerprintCoversAnalysis = true;+ if (options.structuralFingerprintLanguages !== undefined) {+ const language = registry.getLanguageForFile(filePath);+ fingerprintCoversAnalysis =+ language !== null && options.structuralFingerprintLanguages.has(language);+ }- if (analysis) {+ if (analysis && fingerprintCoversAnalysis) {files[filePath] = extractFileFingerprint(filePath, content, analysis);} else {// No tree-sitter support: content hash only (conservative)diff --git a/understand-anything-plugin/packages/core/src/index.ts b/understand-anything-plugin/packages/core/src/index.tsindex 9c3bc854..5f78123a 100644--- a/understand-anything-plugin/packages/core/src/index.ts+++ b/understand-anything-plugin/packages/core/src/index.ts@@ -98,6 +98,7 @@ export {type ImportFingerprint,type FileFingerprint,type FingerprintStore,+ type FingerprintBuildOptions,type ChangeLevel,type FileChangeResult,type ChangeAnalysis,diff --git a/understand-anything-plugin/skills/understand/build-fingerprints.mjs b/understand-anything-plugin/skills/understand/build-fingerprints.mjsindex 75fb4063..33d51888 100644--- a/understand-anything-plugin/skills/understand/build-fingerprints.mjs+++ b/understand-anything-plugin/skills/understand/build-fingerprints.mjs@@ -89,7 +89,10 @@ async function main() {registry.register(tsPlugin);registerAllParsers(registry);- const store = buildFingerprintStore(projectRoot, filePaths, registry, gitCommitHash);+ const structuralFingerprintLanguages = new Set(tsConfigs.map(config => config.id));+ const store = buildFingerprintStore(projectRoot, filePaths, registry, gitCommitHash, {+ structuralFingerprintLanguages,+ });saveFingerprints(projectRoot, store);const fileCount = Object.keys(store.files).length;diff --git a/understand-anything-plugin/skills/understand/prepare-incremental.mjs b/understand-anything-plugin/skills/understand/prepare-incremental.mjsindex 1692f292..a31f7be0 100644--- a/understand-anything-plugin/skills/understand/prepare-incremental.mjs+++ b/understand-anything-plugin/skills/understand/prepare-incremental.mjs@@ -276,7 +276,10 @@ async function buildCurrentFingerprints(projectRoot, paths, headCommit) {const registry = new PluginRegistry();registry.register(treeSitter);registerAllParsers(registry);- return buildFingerprintStore(projectRoot, paths, registry, headCommit);+ const structuralFingerprintLanguages = new Set(tsConfigs.map(config => config.id));+ return buildFingerprintStore(projectRoot, paths, registry, headCommit, {+ structuralFingerprintLanguages,+ });} catch (error) {process.stderr.write(`Warning: prepare-incremental: structural parser initialization failed ` +