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
Update index.ts
Sai Smruti Ranjan Dasf9e5f551b583
diff --git a/understand-anything-plugin/packages/core/src/persistence/index.ts b/understand-anything-plugin/packages/core/src/persistence/index.tsindex 36ba5cf0..5eb71058 100644--- a/understand-anything-plugin/packages/core/src/persistence/index.ts+++ b/understand-anything-plugin/packages/core/src/persistence/index.ts@@ -1,5 +1,5 @@import { readFileSync, writeFileSync, mkdirSync, existsSync } from "node:fs";-import { join } from "node:path";+import { join, isAbsolute, relative, basename } from "node:path";import type { KnowledgeGraph, AnalysisMeta } from "../types.js";import { validateGraph } from "../schema.js";@@ -15,9 +15,68 @@ function ensureDir(projectRoot: string): string {return dir;}+/**+ * Sanitise every node's filePath before writing to disk.+ *+ * The analysis agent produces absolute paths like:+ * /Users/alice/company/src/auth.ts+ *+ * We convert them to paths relative to projectRoot:+ * src/auth.ts+ *+ * Three cases are handled:+ * 1. Path is inside projectRoot → make it relative+ * 2. Path is absolute but outside → keep only the filename (last segment)+ * 3. Path is already relative → leave it untouched+ *+ * This means the developer's home directory, username, and company+ * directory layout are never written to knowledge-graph.json.+ */+function sanitiseFilePaths(+ graph: KnowledgeGraph,+ projectRoot: string,+): KnowledgeGraph {+ const normalRoot = projectRoot.endsWith("/")+ ? projectRoot+ : projectRoot + "/";++ const sanitisedNodes = graph.nodes.map((node) => {+ if (typeof node.filePath !== "string") return node;++ const fp = node.filePath;++ if (!isAbsolute(fp)) {+ // Already relative — nothing to do.+ return node;+ }++ if (fp.startsWith(normalRoot) || fp.startsWith(projectRoot)) {+ // Inside the project root — make it relative.+ return { ...node, filePath: relative(projectRoot, fp) };+ }++ // Absolute but outside the project root — use only the filename+ // so we leak as little as possible.+ return { ...node, filePath: basename(fp) };+ });++ return { ...graph, nodes: sanitisedNodes };+}+export function saveGraph(projectRoot: string, graph: KnowledgeGraph): void {const dir = ensureDir(projectRoot);- writeFileSync(join(dir, GRAPH_FILE), JSON.stringify(graph, null, 2), "utf-8");++ // FIX — sanitise absolute file paths before persisting.+ // Without this, absolute paths like /Users/alice/company/src/auth.ts+ // are written verbatim into knowledge-graph.json and later served+ // by the dashboard server, leaking the developer's directory layout.+ const sanitised = sanitiseFilePaths(graph, projectRoot);++ writeFileSync(+ join(dir, GRAPH_FILE),+ JSON.stringify(sanitised, null, 2),+ "utf-8",+ );}export function loadGraph(@@ -44,7 +103,11 @@ export function loadGraph(export function saveMeta(projectRoot: string, meta: AnalysisMeta): void {const dir = ensureDir(projectRoot);- writeFileSync(join(dir, META_FILE), JSON.stringify(meta, null, 2), "utf-8");+ writeFileSync(+ join(dir, META_FILE),+ JSON.stringify(meta, null, 2),+ "utf-8",+ );}export function loadMeta(projectRoot: string): AnalysisMeta | null {