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
merge: resolve conflict with main and fix token auth in dashboard
Lum11043fad7207fbfb
diff --cc understand-anything-plugin/packages/core/src/persistence/index.tsindex 5eb71058,56db5190..cf1cab64--- a/understand-anything-plugin/packages/core/src/persistence/index.ts+++ b/understand-anything-plugin/packages/core/src/persistence/index.ts@@@ -1,6 -1,7 +1,7 @@@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 type { KnowledgeGraph, AnalysisMeta, ProjectConfig } from "../types.js";+ import type { FingerprintStore } from "../fingerprint.js";import { validateGraph } from "../schema.js";const UA_DIR = ".understand-anything";diff --cc understand-anything-plugin/packages/dashboard/src/App.tsxindex 50df4608,78ded8fa..d4867a8d--- a/understand-anything-plugin/packages/dashboard/src/App.tsx+++ b/understand-anything-plugin/packages/dashboard/src/App.tsx@@@ -10,7 -11,14 +11,21 @@@ import DiffToggle from "./components/Diimport LearnPanel from "./components/LearnPanel";import PersonaSelector from "./components/PersonaSelector";import ProjectOverview from "./components/ProjectOverview";+ import KeyboardShortcutsHelp from "./components/KeyboardShortcutsHelp";+ import WarningBanner from "./components/WarningBanner";+ import { useKeyboardShortcuts } from "./hooks/useKeyboardShortcuts";+ import type { KeyboardShortcut } from "./hooks/useKeyboardShortcuts";+ import { ThemeProvider } from "./themes/index.ts";+ import { ThemePicker } from "./components/ThemePicker.tsx";+ import type { ThemeConfig } from "./themes/index.ts";+++// Extract the access token from the URL so protected endpoints can be fetched.++const ACCESS_TOKEN = new URLSearchParams(window.location.search).get("token");++++function tokenUrl(path: string): string {++ return ACCESS_TOKEN ? `${path}?token=${ACCESS_TOKEN}` : path;++}+function App() {const graph = useDashboardStore((s) => s.graph);const setGraph = useDashboardStore((s) => s.setGraph);@@@ -21,9 -29,111 +36,111 @@@const closeCodeViewer = useDashboardStore((s) => s.closeCodeViewer);const setDiffOverlay = useDashboardStore((s) => s.setDiffOverlay);const [loadError, setLoadError] = useState<string | null>(null);+ const [graphIssues, setGraphIssues] = useState<GraphIssue[]>([]);+ const [showKeyboardHelp, setShowKeyboardHelp] = useState(false);+ const [metaTheme, setMetaTheme] = useState<ThemeConfig | null>(null);++ useEffect(() => {- fetch("/meta.json")++ fetch(tokenUrl("/meta.json"))+ .then((r) => (r.ok ? r.json() : null))+ .then((meta) => {+ if (meta?.theme) setMetaTheme(meta.theme);+ })+ .catch(() => {});+ }, []);++ // Define keyboard shortcuts+ const shortcuts = useMemo<KeyboardShortcut[]>(+ () => [+ // Help+ {+ key: "?",+ shiftKey: true,+ description: "Show keyboard shortcuts",+ action: () => setShowKeyboardHelp((prev) => !prev),+ category: "General",+ },+ // Navigation+ {+ key: "Escape",+ description: "Close panels and modals",+ action: () => {+ // Read from store at invocation time to avoid stale closures+ const state = useDashboardStore.getState();+ if (state.codeViewerOpen) {+ state.closeCodeViewer();+ } else if (state.selectedNodeId) {+ state.selectNode(null);+ } else if (state.tourActive) {+ state.stopTour();+ } else {+ setShowKeyboardHelp(false);+ }+ },+ category: "Navigation",+ },+ {+ key: "/",+ description: "Focus search bar",+ action: () => {+ const searchInput = document.querySelector<HTMLInputElement>(+ 'input[placeholder*="Search"]'+ );+ searchInput?.focus();+ },+ category: "Navigation",+ },+ // Tour controls+ {+ key: "ArrowRight",+ description: "Next tour step",+ action: () => {+ const state = useDashboardStore.getState();+ if (state.tourActive) {+ state.nextTourStep();+ }+ },+ category: "Tour",+ },+ {+ key: "ArrowLeft",+ description: "Previous tour step",+ action: () => {+ const state = useDashboardStore.getState();+ if (state.tourActive) {+ state.prevTourStep();+ }+ },+ category: "Tour",+ },+ // View toggles+ {+ key: "l",+ description: "Toggle layer visualization",+ action: () => {+ const state = useDashboardStore.getState();+ state.toggleLayers();+ },+ category: "View",+ },+ {+ key: "d",+ description: "Toggle diff mode",+ action: () => {+ const state = useDashboardStore.getState();+ state.toggleDiffMode();+ },+ category: "View",+ },+ ],+ []+ );++ // Register keyboard shortcuts+ useKeyboardShortcuts(shortcuts);useEffect(() => {-- fetch("/knowledge-graph.json")++ fetch(tokenUrl("/knowledge-graph.json")).then((res) => res.json()).then((data: unknown) => {const result = validateGraph(data);@@@ -42,7 -162,7 +169,7 @@@}, [setGraph]);useEffect(() => {-- fetch("/diff-overlay.json")++ fetch(tokenUrl("/diff-overlay.json")).then((res) => {if (!res.ok) return null;return res.json();diff --cc understand-anything-plugin/packages/dashboard/vite.config.tsindex 2b5ebc58,aa60f93c..cd43a830--- a/understand-anything-plugin/packages/dashboard/vite.config.ts+++ b/understand-anything-plugin/packages/dashboard/vite.config.ts@@@ -32,110 -18,47 +32,112 @@@ export default defineConfig({name: "serve-knowledge-graph",configureServer(server) {+ // Print the access URL once so the developer can open it.+ server.httpServer?.once("listening", () => {+ console.log(+ `\n 🔑 Dashboard URL: http://127.0.0.1:5173?token=${ACCESS_TOKEN}\n`+ );+ });+server.middlewares.use((req, res, next) => {- if (req.url === "/knowledge-graph.json") {- // GRAPH_DIR env var points to the project being analyzed- // Falls back to monorepo root, then public/ (demo)- const graphDir = process.env.GRAPH_DIR;- const candidates = [- ...(graphDir- ? [path.resolve(graphDir, ".understand-anything/knowledge-graph.json")]- : []),- path.resolve(process.cwd(), ".understand-anything/knowledge-graph.json"),- path.resolve(process.cwd(), "../../../.understand-anything/knowledge-graph.json"),- ];- for (const candidate of candidates) {- if (fs.existsSync(candidate)) {- res.setHeader("Content-Type", "application/json");- fs.createReadStream(candidate).pipe(res);- return;- }- }+ const url = new URL(req.url ?? "/", "http://127.0.0.1:5173");+ const pathname = url.pathname;+ const isProtectedEndpoint =+ pathname === "/knowledge-graph.json" ||- pathname === "/diff-overlay.json";++ pathname === "/diff-overlay.json" ||++ pathname === "/meta.json";++ if (!isProtectedEndpoint) {+ next();+ return;+ }++ // FIX 3 — require the one-time token on all data endpoints.+ // Requests without a matching ?token= get a 403.+ if (url.searchParams.get("token") !== ACCESS_TOKEN) {+ res.statusCode = 403;+ res.setHeader("Content-Type", "application/json");+ res.end(JSON.stringify({ error: "Forbidden: missing or invalid token" }));+ return;}- if (req.url === "/diff-overlay.json") {- const graphDir = process.env.GRAPH_DIR;- const candidates = [- ...(graphDir- ? [path.resolve(graphDir, ".understand-anything/diff-overlay.json")]- : []),- path.resolve(process.cwd(), ".understand-anything/diff-overlay.json"),- path.resolve(process.cwd(), "../../../.understand-anything/diff-overlay.json"),- ];- for (const candidate of candidates) {- if (fs.existsSync(candidate)) {- res.setHeader("Content-Type", "application/json");- fs.createReadStream(candidate).pipe(res);- return;++ const fileName =+ pathname === "/diff-overlay.json"+ ? "diff-overlay.json"++ : pathname === "/meta.json"++ ? "meta.json"+ : "knowledge-graph.json";++ const graphDir = process.env.GRAPH_DIR;+ const candidates = [+ ...(graphDir+ ? [path.resolve(graphDir, `.understand-anything/${fileName}`)]+ : []),+ path.resolve(process.cwd(), `.understand-anything/${fileName}`),+ path.resolve(+ process.cwd(),+ `../../../.understand-anything/${fileName}`+ ),+ ];++ for (const candidate of candidates) {+ if (!fs.existsSync(candidate)) continue;++ // FIX 2 — sanitise absolute file paths before sending the JSON.+ // Nodes can contain filePath values like /Users/alice/company/src/auth.ts.+ // We convert those to relative paths (src/auth.ts) so the developer's+ // home directory and company directory layout are not leaked.+ try {+ const raw = JSON.parse(fs.readFileSync(candidate, "utf-8")) as {+ nodes?: Array<Record<string, unknown>>;+ [key: string]: unknown;+ };++ // Derive the project root from the candidate path so we can+ // make file paths relative to it.+ const projectRoot = path.dirname(+ candidate.replace(+ `${path.sep}.understand-anything${path.sep}${fileName}`,+ ""+ )+ );++ if (Array.isArray(raw.nodes)) {+ raw.nodes = raw.nodes.map((node) => {+ if (typeof node.filePath !== "string") return node;+ const abs = node.filePath;+ // Only relativise paths that actually sit inside projectRoot.+ // Leave external or already-relative paths untouched.+ const rel = abs.startsWith(projectRoot)+ ? abs.slice(projectRoot.length).replace(/^[\\/]/, "")+ : path.isAbsolute(abs)+ ? path.basename(abs) // absolute but outside root — use filename only+ : abs; // already relative — keep as-is+ return { ...node, filePath: rel };+ });}++ res.setHeader("Content-Type", "application/json");+ res.end(JSON.stringify(raw));+ } catch (err) {+ // If we cannot parse or sanitise the file, refuse to serve it+ // rather than accidentally leaking raw content.+ console.error("[understand-anything] Failed to sanitise graph file:", err);+ res.statusCode = 500;+ res.setHeader("Content-Type", "application/json");+ res.end(JSON.stringify({ error: "Failed to read graph file" }));}- res.statusCode = 404;- res.end();return;}- next();++ // No matching file found on disk.- if (pathname === "/diff-overlay.json") {- res.statusCode = 404;- res.end();- } else {- res.statusCode = 404;++ res.statusCode = 404;++ if (pathname === "/knowledge-graph.json") {+ res.setHeader("Content-Type", "application/json");+ res.end(JSON.stringify({ error: "No knowledge graph found. Run /understand first." }));++ } else {++ res.end();+ }});},},