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): validate design node/edge types, figmaMeta, promote instance_of
gruming6750d471a920
diff --git a/understand-anything-plugin/packages/core/src/__tests__/schema.test.ts b/understand-anything-plugin/packages/core/src/__tests__/schema.test.tsindex d81759bd..4cab6344 100644--- a/understand-anything-plugin/packages/core/src/__tests__/schema.test.ts+++ b/understand-anything-plugin/packages/core/src/__tests__/schema.test.ts@@ -727,3 +727,45 @@ describe("Extended node/edge types", () => {expect(result.success).toBe(true);});});++function designGraph() {+ return {+ version: "1.0.0",+ kind: "design",+ project: { name: "F", languages: ["figma"], frameworks: [], description: "d", analyzedAt: "t", gitCommitHash: "" },+ nodes: [+ { id: "screen:1:2", type: "screen", name: "Login", summary: "s", tags: ["auth"], complexity: "simple" },+ { id: "component:3:4", type: "component", name: "Button/Primary", summary: "s", tags: ["ds"], complexity: "simple" },+ { id: "instance:5:6", type: "instance", name: "SignInBtn", summary: "s", tags: ["use"], complexity: "simple" },+ { id: "token:color:brand", type: "token", name: "color/brand", summary: "s", tags: ["token"], complexity: "simple" },+ ],+ edges: [+ { source: "instance:5:6", target: "component:3:4", type: "instance_of", direction: "forward", weight: 0.8 },+ { source: "component:3:4", target: "token:color:brand", type: "uses_token", direction: "forward", weight: 0.5 },+ ],+ layers: [],+ tour: [],+ };+}++describe("design graph schema", () => {+ it("accepts design node and edge types", () => {+ const res = validateGraph(designGraph());+ expect(res.success).toBe(true);+ expect(res.data!.nodes).toHaveLength(4);+ expect(res.data!.edges).toHaveLength(2);+ });++ it("keeps instance_of as a first-class edge (NOT rewritten to exemplifies)", () => {+ const res = validateGraph(designGraph());+ const e = res.data!.edges.find((x) => x.source === "instance:5:6");+ expect(e!.type).toBe("instance_of");+ });++ it("normalizes figma node-type aliases (frame → screen)", () => {+ const g = designGraph();+ g.nodes[0].type = "frame";+ const res = validateGraph(g);+ expect(res.data!.nodes.find((n) => n.id === "screen:1:2")!.type).toBe("screen");+ });+});diff --git a/understand-anything-plugin/packages/core/src/schema.ts b/understand-anything-plugin/packages/core/src/schema.tsindex 71b9cd8a..a9f9fc63 100644--- a/understand-anything-plugin/packages/core/src/schema.ts+++ b/understand-anything-plugin/packages/core/src/schema.ts@@ -11,6 +11,7 @@ export const EdgeTypeSchema = z.enum(["migrates", "documents", "routes", "defines_schema", // Schema/Data"contains_flow", "flow_step", "cross_domain", // Domain"cites", "contradicts", "builds_on", "exemplifies", "categorized_under", "authored_by", // Knowledge+ "instance_of", "variant_of", "uses_token", // Design]);// Aliases that LLMs commonly generate instead of canonical node types@@ -58,7 +59,6 @@ export const NODE_TYPE_ALIASES: Record<string, string> = {business_step: "step",// Knowledge aliasesnote: "article",- page: "article",wiki_page: "article",person: "entity",actor: "entity",@@ -72,6 +72,17 @@ export const NODE_TYPE_ALIASES: Record<string, string> = {reference: "source",raw: "source",paper: "source",+ // Design aliases (Figma node types). NOTE: the former `page: "article"`+ // entry was removed — `page` is now a first-class design node type, so it+ // must not be rewritten (and `canvas: "page"` would otherwise chain).+ frame: "screen",+ artboard: "screen",+ canvas: "page",+ main_component: "component",+ component_set: "componentSet",+ variant_set: "componentSet",+ design_token: "token",+ style: "token",};// Aliases that LLMs commonly generate instead of canonical edge types@@ -113,12 +124,18 @@ export const EDGE_TYPE_ALIASES: Record<string, string> = {refines: "builds_on",elaborates: "builds_on",illustrates: "exemplifies",- instance_of: "exemplifies",example_of: "exemplifies",belongs_to: "categorized_under",tagged_with: "categorized_under",written_by: "authored_by",created_by: "authored_by",+ // Design aliases+ instantiates: "instance_of",+ variant: "variant_of",+ styled_by: "uses_token",+ applies_token: "uses_token",+ // NOTE: the former `instance_of: "exemplifies"` entry is removed —+ // instance_of is now a first-class design edge.// Note: "implemented_by" is intentionally NOT aliased to "implements" —// it inverts edge direction (see commit fd0df15). The LLM should use// "implements" with correct source/target instead.@@ -365,6 +382,18 @@ const KnowledgeMetaSchema = z.object({content: z.string().optional(),}).passthrough();+const FigmaMetaSchema = z.object({+ fileKey: z.string().optional(),+ nodeId: z.string().optional(),+ figmaType: z.string().optional(),+ thumbnailUrl: z.string().optional(),+ dimensions: z.object({ width: z.number(), height: z.number() }).optional(),+ tokenKind: z.enum(["color", "type", "spacing", "effect", "grid"]).optional(),+ tokenValue: z.string().optional(),+ prototypeTargets: z.array(z.string()).optional(),+ componentKey: z.string().optional(),+}).passthrough();+export const GraphNodeSchema = z.object({id: z.string(),type: z.enum([@@ -373,6 +402,7 @@ export const GraphNodeSchema = z.object({"pipeline", "schema", "resource","domain", "flow", "step","article", "entity", "topic", "claim", "source",+ "page", "screen", "component", "componentSet", "instance", "token",]),name: z.string(),filePath: z.string().optional(),@@ -383,6 +413,7 @@ export const GraphNodeSchema = z.object({languageNotes: z.string().optional(),domainMeta: DomainMetaSchema.optional(),knowledgeMeta: KnowledgeMetaSchema.optional(),+ figmaMeta: FigmaMetaSchema.optional(),}).passthrough();export const GraphEdgeSchema = z.object({@@ -420,7 +451,7 @@ export const ProjectMetaSchema = z.object({export const KnowledgeGraphSchema = z.object({version: z.string(),- kind: z.enum(["codebase", "knowledge"]).optional(),+ kind: z.enum(["codebase", "knowledge", "design"]).optional(),project: ProjectMetaSchema,nodes: z.array(GraphNodeSchema),edges: z.array(GraphEdgeSchema),