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
feat(core): rename data directory to .ua with legacy fallback
Lum1104534d2402da14
diff --git a/understand-anything-plugin/packages/core/src/__tests__/domain-persistence.test.ts b/understand-anything-plugin/packages/core/src/__tests__/domain-persistence.test.tsindex 4543a0cb..675bd50a 100644--- a/understand-anything-plugin/packages/core/src/__tests__/domain-persistence.test.ts+++ b/understand-anything-plugin/packages/core/src/__tests__/domain-persistence.test.ts@@ -56,8 +56,8 @@ describe("domain graph persistence", () => {it("saves to domain-graph.json, not knowledge-graph.json", () => {saveDomainGraph(testRoot, domainGraph);- const domainPath = join(testRoot, ".understand-anything", "domain-graph.json");- const structuralPath = join(testRoot, ".understand-anything", "knowledge-graph.json");+ const domainPath = join(testRoot, ".ua", "domain-graph.json");+ const structuralPath = join(testRoot, ".ua", "knowledge-graph.json");expect(existsSync(domainPath)).toBe(true);expect(existsSync(structuralPath)).toBe(false);});diff --git a/understand-anything-plugin/packages/core/src/ignore-filter.ts b/understand-anything-plugin/packages/core/src/ignore-filter.tsindex a56d2e3f..ec395a93 100644--- a/understand-anything-plugin/packages/core/src/ignore-filter.ts+++ b/understand-anything-plugin/packages/core/src/ignore-filter.ts@@ -1,6 +1,7 @@import ignore, { type Ignore } from "ignore";import { readFileSync, existsSync } from "node:fs";import { join } from "node:path";+import { resolveUaDir } from "./persistence/index.js";/*** Hardcoded default ignore patterns matching the project-scanner agent's@@ -80,7 +81,8 @@ export interface IgnoreFilter {** Pattern load order (later entries can override earlier ones via ! negation):* 1. Hardcoded defaults- * 2. .understand-anything/.understandignore (if exists)+ * 2. <ua-dir>/.understandignore (if exists — `.ua/`, or the legacy+ * `.understand-anything/` when that directory already exists)* 3. .understandignore at project root (if exists)*/export function createIgnoreFilter(projectRoot: string): IgnoreFilter {@@ -89,8 +91,8 @@ export function createIgnoreFilter(projectRoot: string): IgnoreFilter {// Layer 1: hardcoded defaultsig.add(DEFAULT_IGNORE_PATTERNS);- // Layer 2: .understand-anything/.understandignore- const projectIgnorePath = join(projectRoot, ".understand-anything", ".understandignore");+ // Layer 2: <ua-dir>/.understandignore+ const projectIgnorePath = join(resolveUaDir(projectRoot), ".understandignore");if (existsSync(projectIgnorePath)) {const content = readFileSync(projectIgnorePath, "utf-8");ig.add(content);diff --git a/understand-anything-plugin/packages/core/src/persistence/index.ts b/understand-anything-plugin/packages/core/src/persistence/index.tsindex d69857be..d3b86fd9 100644--- a/understand-anything-plugin/packages/core/src/persistence/index.ts+++ b/understand-anything-plugin/packages/core/src/persistence/index.ts@@ -4,14 +4,29 @@ import type { KnowledgeGraph, AnalysisMeta, ProjectConfig } from "../types.js";import type { FingerprintStore } from "../fingerprint.js";import { validateGraph } from "../schema.js";-const UA_DIR = ".understand-anything";+const UA_DIR = ".ua";+const LEGACY_UA_DIR = ".understand-anything";const GRAPH_FILE = "knowledge-graph.json";const META_FILE = "meta.json";const FINGERPRINT_FILE = "fingerprints.json";const CONFIG_FILE = "config.json";+/**+ * Resolve the data directory NAME for a project. Projects analyzed before+ * the `.ua` rename keep their existing `.understand-anything/` for both+ * reads and writes (no migration needed); fresh projects get `.ua/`.+ */+export function resolveUaDirName(projectRoot: string): string {+ return existsSync(join(projectRoot, LEGACY_UA_DIR)) ? LEGACY_UA_DIR : UA_DIR;+}++/** Absolute path of the project's data directory (see resolveUaDirName). */+export function resolveUaDir(projectRoot: string): string {+ return join(projectRoot, resolveUaDirName(projectRoot));+}+function ensureDir(projectRoot: string): string {- const dir = join(projectRoot, UA_DIR);+ const dir = resolveUaDir(projectRoot);if (!existsSync(dir)) {mkdirSync(dir, { recursive: true });}@@ -86,7 +101,7 @@ export function loadGraph(projectRoot: string,options?: { validate?: boolean },): KnowledgeGraph | null {- const filePath = join(projectRoot, UA_DIR, GRAPH_FILE);+ const filePath = join(resolveUaDir(projectRoot), GRAPH_FILE);if (!existsSync(filePath)) return null;const data = JSON.parse(readFileSync(filePath, "utf-8"));@@ -110,7 +125,7 @@ export function saveMeta(projectRoot: string, meta: AnalysisMeta): void {}export function loadMeta(projectRoot: string): AnalysisMeta | null {- const filePath = join(projectRoot, UA_DIR, META_FILE);+ const filePath = join(resolveUaDir(projectRoot), META_FILE);if (!existsSync(filePath)) return null;return JSON.parse(readFileSync(filePath, "utf-8")) as AnalysisMeta;}@@ -121,7 +136,7 @@ export function saveFingerprints(projectRoot: string, store: FingerprintStore):}export function loadFingerprints(projectRoot: string): FingerprintStore | null {- const filePath = join(projectRoot, UA_DIR, FINGERPRINT_FILE);+ const filePath = join(resolveUaDir(projectRoot), FINGERPRINT_FILE);if (!existsSync(filePath)) return null;try {return JSON.parse(readFileSync(filePath, "utf-8")) as FingerprintStore;@@ -138,7 +153,7 @@ export function saveConfig(projectRoot: string, config: ProjectConfig): void {}export function loadConfig(projectRoot: string): ProjectConfig {- const filePath = join(projectRoot, UA_DIR, CONFIG_FILE);+ const filePath = join(resolveUaDir(projectRoot), CONFIG_FILE);if (!existsSync(filePath)) return { ...DEFAULT_CONFIG };try {return JSON.parse(readFileSync(filePath, "utf-8")) as ProjectConfig;@@ -163,7 +178,7 @@ export function loadDomainGraph(projectRoot: string,options?: { validate?: boolean },): KnowledgeGraph | null {- const filePath = join(projectRoot, UA_DIR, DOMAIN_GRAPH_FILE);+ const filePath = join(resolveUaDir(projectRoot), DOMAIN_GRAPH_FILE);if (!existsSync(filePath)) return null;const data = JSON.parse(readFileSync(filePath, "utf-8"));diff --git a/understand-anything-plugin/packages/core/src/persistence/persistence.test.ts b/understand-anything-plugin/packages/core/src/persistence/persistence.test.tsindex 3a694fb2..ef6dc44a 100644--- a/understand-anything-plugin/packages/core/src/persistence/persistence.test.ts+++ b/understand-anything-plugin/packages/core/src/persistence/persistence.test.ts@@ -3,7 +3,8 @@ import { mkdtempSync, rmSync, existsSync } from "node:fs";import { join } from "node:path";import { tmpdir } from "node:os";import { writeFileSync } from "node:fs";-import { saveGraph, loadGraph, saveMeta, loadMeta, saveFingerprints, loadFingerprints, saveConfig, loadConfig } from "./index.js";+import { saveGraph, loadGraph, saveMeta, loadMeta, saveFingerprints, loadFingerprints, saveConfig, loadConfig, resolveUaDirName } from "./index.js";+import { mkdirSync } from "node:fs";import type { KnowledgeGraph, AnalysisMeta } from "../types.js";import type { FingerprintStore } from "../fingerprint.js";@@ -75,10 +76,10 @@ describe("persistence", () => {};describe("saveGraph / loadGraph", () => {- it("should write knowledge-graph.json to .understand-anything/", () => {+ it("should write knowledge-graph.json to .ua/", () => {saveGraph(tempDir, sampleGraph);- const filePath = join(tempDir, ".understand-anything", "knowledge-graph.json");+ const filePath = join(tempDir, ".ua", "knowledge-graph.json");expect(existsSync(filePath)).toBe(true);});@@ -115,10 +116,10 @@ describe("persistence", () => {});describe("saveMeta / loadMeta", () => {- it("should write meta.json to .understand-anything/", () => {+ it("should write meta.json to .ua/", () => {saveMeta(tempDir, sampleMeta);- const filePath = join(tempDir, ".understand-anything", "meta.json");+ const filePath = join(tempDir, ".ua", "meta.json");expect(existsSync(filePath)).toBe(true);});@@ -168,7 +169,7 @@ describe("persistence", () => {});it("should return null when fingerprints.json is corrupted", () => {- const dir = join(tempDir, ".understand-anything");+ const dir = join(tempDir, ".ua");// Ensure the directory exists by saving first, then overwrite with garbagesaveFingerprints(tempDir, sampleFingerprints);writeFileSync(join(dir, "fingerprints.json"), "{{not valid json!!", "utf-8");@@ -194,7 +195,7 @@ describe("persistence", () => {it("should return default config when config.json is corrupted", () => {saveConfig(tempDir, { autoUpdate: true });- const dir = join(tempDir, ".understand-anything");+ const dir = join(tempDir, ".ua");writeFileSync(join(dir, "config.json"), "not json!!", "utf-8");const loaded = loadConfig(tempDir);@@ -202,3 +203,44 @@ describe("persistence", () => {});});});++describe("legacy .understand-anything compatibility", () => {+ let tempDir: string;++ beforeEach(() => {+ tempDir = mkdtempSync(join(tmpdir(), "ua-legacy-test-"));+ });++ afterEach(() => {+ rmSync(tempDir, { recursive: true, force: true });+ });++ it("resolves to .ua for fresh projects", () => {+ expect(resolveUaDirName(tempDir)).toBe(".ua");+ });++ it("keeps using an existing .understand-anything/ for reads and writes", () => {+ mkdirSync(join(tempDir, ".understand-anything"));+ expect(resolveUaDirName(tempDir)).toBe(".understand-anything");++ saveMeta(tempDir, { analyzedAt: "t", gitCommitHash: "abc", fileCount: 1 } as never);+ expect(existsSync(join(tempDir, ".understand-anything", "meta.json"))).toBe(true);+ expect(existsSync(join(tempDir, ".ua"))).toBe(false);+ expect(loadMeta(tempDir)?.gitCommitHash).toBe("abc");+ });++ it("reads a graph saved under the legacy directory", () => {+ mkdirSync(join(tempDir, ".understand-anything"));+ const graph = {+ version: "1.0.0",+ project: { name: "p", languages: [], frameworks: [], description: "d", analyzedAt: "t", gitCommitHash: "" },+ nodes: [{ id: "file:a.ts", type: "file", name: "a.ts", summary: "s", tags: [], complexity: "simple" }],+ edges: [],+ layers: [],+ tour: [],+ } as never;+ saveGraph(tempDir, graph);+ expect(existsSync(join(tempDir, ".understand-anything", "knowledge-graph.json"))).toBe(true);+ expect(loadGraph(tempDir)?.nodes).toHaveLength(1);+ });+});