glassbrain 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +236 -2
  3. package/dist/adapters/common.d.ts +51 -0
  4. package/dist/adapters/graphify.d.ts +51 -0
  5. package/dist/adapters/index.d.ts +24 -0
  6. package/dist/adapters/memory.d.ts +7 -0
  7. package/dist/adapters/obsidian.d.ts +18 -0
  8. package/dist/adapters/understand.d.ts +70 -0
  9. package/dist/adapters.js +492 -0
  10. package/dist/animate.d.ts +312 -0
  11. package/dist/chunks/chunk-37BAJC3L.js +234 -0
  12. package/dist/chunks/chunk-3CNKH3HB.js +5226 -0
  13. package/dist/chunks/chunk-EJURBBFC.js +92 -0
  14. package/dist/chunks/chunk-LEYJCT6O.js +0 -0
  15. package/dist/chunks/chunk-SA6RSWZP.js +0 -0
  16. package/dist/chunks/chunk-UJCALP4P.js +2283 -0
  17. package/dist/chunks/chunk-YGRPNAXE.js +95 -0
  18. package/dist/chunks/chunk-ZA47FP7C.js +7 -0
  19. package/dist/cli/glassbrain.js +1491 -0
  20. package/dist/cli/viewer.js +851 -0
  21. package/dist/core.d.ts +10 -0
  22. package/dist/core.js +148 -0
  23. package/dist/diff.d.ts +156 -0
  24. package/dist/edit.d.ts +58 -0
  25. package/dist/elements.d.ts +57 -0
  26. package/dist/index.d.ts +10 -0
  27. package/dist/index.js +175 -0
  28. package/dist/internal.d.ts +7 -0
  29. package/dist/internal.js +287 -0
  30. package/dist/layout/diff-layout.d.ts +92 -0
  31. package/dist/layout/divide.d.ts +61 -0
  32. package/dist/layout/engine.d.ts +63 -0
  33. package/dist/layout/inline-pool.d.ts +2 -0
  34. package/dist/layout/inline-pool.js +7 -0
  35. package/dist/layout/planes.d.ts +39 -0
  36. package/dist/layout/presets.d.ts +5 -0
  37. package/dist/layout/readability.d.ts +65 -0
  38. package/dist/layout/relax.d.ts +19 -0
  39. package/dist/layout/run-job.d.ts +30 -0
  40. package/dist/layout/worker-pool.d.ts +2 -0
  41. package/dist/layout/worker-pool.js +17 -0
  42. package/dist/layout/worker.d.ts +1 -0
  43. package/dist/layout/worker.js +87 -0
  44. package/dist/model.d.ts +92 -0
  45. package/dist/paint.d.ts +94 -0
  46. package/dist/profile.d.ts +133 -0
  47. package/dist/react/DetailPanel.d.ts +29 -0
  48. package/dist/react/DetailPanel.js +10 -0
  49. package/dist/react/DiffOverlay.d.ts +59 -0
  50. package/dist/react/EditPanel.d.ts +30 -0
  51. package/dist/react/GraphCanvas.d.ts +208 -0
  52. package/dist/react/GraphCanvas.js +13 -0
  53. package/dist/react/Legend.d.ts +47 -0
  54. package/dist/react/Toolbar.d.ts +48 -0
  55. package/dist/react/camera.d.ts +29 -0
  56. package/dist/react/i18n.d.ts +3 -0
  57. package/dist/react/icons.d.ts +20 -0
  58. package/dist/react/markdown.d.ts +11 -0
  59. package/dist/strings.d.ts +84 -0
  60. package/dist/style.d.ts +138 -0
  61. package/dist/view.d.ts +69 -0
  62. package/package.json +110 -4
  63. package/schema/graph.schema.json +54 -0
  64. package/schema/profile.schema.json +59 -0
@@ -0,0 +1,492 @@
1
+ // adapters/common.ts
2
+ var tryJson = (text) => {
3
+ try {
4
+ return JSON.parse(text);
5
+ } catch {
6
+ return void 0;
7
+ }
8
+ };
9
+ var isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
10
+ var HUES = ["#6366f1", "#0891b2", "#e63b7a", "#f59e0b", "#16a34a", "#be38f3", "#ff6a00", "#64748b", "#0ea5e9", "#a16207"];
11
+ var autoPalette = (kinds) => Object.fromEntries([...new Set(kinds)].map((k, i) => [k, HUES[i % HUES.length]]));
12
+ function folderOf(file, out) {
13
+ const parts = file.split("/").filter(Boolean);
14
+ parts.pop();
15
+ let parent;
16
+ for (let i = 0; i < parts.length; i++) {
17
+ const id = `dir:${parts.slice(0, i + 1).join("/")}`;
18
+ if (!out.has(id)) out.set(id, { id, label: parts[i], kind: "folder", ...parent ? { parent } : {} });
19
+ parent = id;
20
+ }
21
+ return parent;
22
+ }
23
+ function wouldCycle(parentOf, child, parent) {
24
+ for (let p = parent, n = 0; p && n < 1e4; p = parentOf.get(p), n++) if (p === child) return true;
25
+ return false;
26
+ }
27
+ var clean = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0 && v !== "" && v !== null));
28
+
29
+ // adapters/graphify.ts
30
+ var STRUCT = /* @__PURE__ */ new Set(["contains", "method"]);
31
+ var NOTE = "rationale_for";
32
+ var looksLike = (d) => isObj(d) && Array.isArray(d.nodes) && Array.isArray(d.links ?? d.edges) && (d.nodes.length === 0 || d.nodes.some((n) => isObj(n) && ("file_type" in n || "source_file" in n))) && !("layers" in d && "project" in d);
33
+ var base = (p) => p.split("/").pop() ?? p;
34
+ function convertGraphify(d, name) {
35
+ const raw = d.nodes.filter(isObj);
36
+ const links = (d.links ?? d.edges).filter(isObj);
37
+ const ids = new Set(raw.map((n) => String(n.id)));
38
+ const parentOf = /* @__PURE__ */ new Map();
39
+ const claim = (child, parent) => {
40
+ if (child === parent || parentOf.has(child) || !ids.has(child) || !ids.has(parent)) return false;
41
+ if (wouldCycle(parentOf, child, parent)) return false;
42
+ parentOf.set(child, parent);
43
+ return true;
44
+ };
45
+ const edges = [];
46
+ for (const rel of ["method", "contains", NOTE]) {
47
+ for (const l of links) {
48
+ if (l.relation !== rel) continue;
49
+ const s = String(l.source);
50
+ const t = String(l.target);
51
+ if (rel === NOTE ? claim(s, t) : claim(t, s)) continue;
52
+ edges.push(clean({ source: s, target: t, kind: rel, weight: score(l) }));
53
+ }
54
+ }
55
+ for (const l of links) {
56
+ if (STRUCT.has(l.relation) || l.relation === NOTE) continue;
57
+ edges.push(clean({
58
+ source: String(l.source),
59
+ target: String(l.target),
60
+ kind: String(l.relation ?? "related"),
61
+ weight: score(l),
62
+ confidence: l.confidence,
63
+ source_location: l.source_location
64
+ }));
65
+ }
66
+ const fileNode = /* @__PURE__ */ new Map();
67
+ for (const n of raw) {
68
+ const sf = typeof n.source_file === "string" ? n.source_file : "";
69
+ if (sf && n.label === base(sf) && !fileNode.has(sf)) fileNode.set(sf, String(n.id));
70
+ }
71
+ const extra = /* @__PURE__ */ new Map();
72
+ const nodes = raw.map((n) => {
73
+ const id = String(n.id);
74
+ const sf = typeof n.source_file === "string" ? n.source_file : "";
75
+ const isFile = !!sf && fileNode.get(sf) === id;
76
+ let parent = parentOf.get(id);
77
+ if (!parent) {
78
+ if (isFile) parent = folderOf(sf, extra);
79
+ else if (sf && fileNode.has(sf)) parent = fileNode.get(sf);
80
+ else if (sf) {
81
+ const f = `file:${sf}`;
82
+ if (!extra.has(f)) extra.set(f, clean({ id: f, label: base(sf), kind: "file", parent: folderOf(sf, extra), source_file: sf }));
83
+ parent = f;
84
+ } else {
85
+ const g = `group:${n.file_type ?? "other"}`;
86
+ if (!extra.has(g)) extra.set(g, { id: g, label: groupLabel(String(n.file_type ?? "other")), kind: "group" });
87
+ parent = g;
88
+ }
89
+ }
90
+ const kind = isFile ? n.file_type === "document" ? "document" : "file" : n.file_type === "code" ? "symbol" : String(n.file_type ?? "symbol");
91
+ return clean({
92
+ id,
93
+ label: String(n.label ?? id),
94
+ kind,
95
+ parent,
96
+ source_file: sf || void 0,
97
+ source_location: n.source_location,
98
+ community: n.community_name ?? n.community
99
+ });
100
+ });
101
+ return { name: name ?? "Graphify", nodes: [...extra.values(), ...nodes], edges };
102
+ }
103
+ var score = (l) => typeof l.confidence_score === "number" ? l.confidence_score : typeof l.weight === "number" ? Math.min(1, l.weight) : void 0;
104
+ var groupLabel = (t) => ({ concept: "Concepts", rationale: "Rationale", document: "Documents" })[t] ?? t;
105
+ var PROFILE = {
106
+ nodePalette: { symbol: "#6366f1", concept: "#e63b7a", rationale: "#f59e0b", document: "#0891b2", paper: "#0891b2", image: "#16a34a" },
107
+ edgePalette: {
108
+ calls: "#6366f1",
109
+ imports: "#94a3b8",
110
+ imports_from: "#94a3b8",
111
+ re_exports: "#94a3b8",
112
+ references: "#0891b2",
113
+ extends: "#be38f3",
114
+ inherits: "#be38f3",
115
+ implements: "#be38f3",
116
+ conceptually_related_to: "#e63b7a",
117
+ semantically_similar_to: "#e63b7a",
118
+ shares_data_with: "#f59e0b"
119
+ },
120
+ kindLabels: {
121
+ folder: "Folder",
122
+ file: "File",
123
+ symbol: "Symbol",
124
+ concept: "Concept",
125
+ rationale: "Rationale",
126
+ document: "Document",
127
+ group: "Group",
128
+ calls: "calls",
129
+ imports: "imports",
130
+ imports_from: "imports from",
131
+ references: "references"
132
+ },
133
+ detail: { line: [{ key: "source_file", label: "File" }, { key: "source_location", label: "Line" }, { key: "community", label: "Community" }, { key: "confidence", label: "Confidence" }] },
134
+ rootLabel: "Graphify",
135
+ // Fields that change on every rerun without the content changing: community renumbering, line numbers moving with the code.
136
+ diffIgnore: ["community", "source_location"]
137
+ };
138
+ var graphify = {
139
+ id: "graphify",
140
+ label: "Graphify graph.json",
141
+ detect: (files) => files.some((f) => f.path.endsWith(".json") && looksLike(tryJson(f.text))),
142
+ convert(files) {
143
+ const sources = files.flatMap((f) => {
144
+ const d = f.path.endsWith(".json") ? tryJson(f.text) : void 0;
145
+ return looksLike(d) ? [{ origin: f.path, graph: convertGraphify(d) }] : [];
146
+ });
147
+ return { sources, profile: PROFILE };
148
+ }
149
+ };
150
+
151
+ // adapters/memory.ts
152
+ function readRecords(text) {
153
+ const whole = tryJson(text);
154
+ if (isObj(whole) && (Array.isArray(whole.entities) || Array.isArray(whole.relations))) {
155
+ return [
156
+ ...(whole.entities ?? []).map((e) => ({ type: "entity", ...e })),
157
+ ...(whole.relations ?? []).map((r) => ({ type: "relation", ...r }))
158
+ ];
159
+ }
160
+ const lines = text.split("\n").map((l) => l.trim()).filter(Boolean);
161
+ if (!lines.length) return null;
162
+ const recs = lines.map(tryJson);
163
+ if (!recs.every((r) => isObj(r) && (r.type === "entity" || r.type === "relation"))) return null;
164
+ return recs;
165
+ }
166
+ function convertMemory(recs) {
167
+ const groups = /* @__PURE__ */ new Map();
168
+ const nodes = [];
169
+ const edges = [];
170
+ const seen = /* @__PURE__ */ new Set();
171
+ for (const r of recs) {
172
+ if (r.type !== "entity" || typeof r.name !== "string" || seen.has(r.name)) continue;
173
+ seen.add(r.name);
174
+ const t = String(r.entityType ?? "entity");
175
+ const g = `type:${t}`;
176
+ if (!groups.has(g)) groups.set(g, { id: g, label: t, kind: "type" });
177
+ const obs = Array.isArray(r.observations) ? r.observations.map(String) : [];
178
+ nodes.push(clean({
179
+ id: r.name,
180
+ label: r.name,
181
+ kind: t,
182
+ parent: g,
183
+ description: obs.length ? obs.map((o) => `- ${o}`).join("\n") : void 0,
184
+ observations: obs.length ? obs : void 0
185
+ }));
186
+ }
187
+ for (const r of recs) {
188
+ if (r.type !== "relation" || typeof r.from !== "string" || typeof r.to !== "string") continue;
189
+ edges.push({ source: r.from, target: r.to, kind: String(r.relationType ?? "related") });
190
+ }
191
+ return { name: "Memory", nodes: [...groups.values(), ...nodes], edges };
192
+ }
193
+ var memory = {
194
+ id: "memory",
195
+ label: "MCP memory (memory.jsonl)",
196
+ detect: (files) => files.some((f) => /\.jsonl?$/.test(f.path) && readRecords(f.text) !== null),
197
+ convert(files) {
198
+ const sources = files.flatMap((f) => {
199
+ const recs = /\.jsonl?$/.test(f.path) ? readRecords(f.text) : null;
200
+ return recs ? [{ origin: f.path, graph: convertMemory(recs) }] : [];
201
+ });
202
+ const kinds = sources.flatMap((s) => s.graph.nodes.filter((n) => n.kind !== "type").map((n) => n.kind));
203
+ const rels = sources.flatMap((s) => s.graph.edges.map((e) => e.kind));
204
+ return {
205
+ sources,
206
+ profile: {
207
+ nodePalette: autoPalette(kinds),
208
+ edgePalette: autoPalette(rels),
209
+ kindLabels: { type: "Entity type" },
210
+ detail: { skip: ["observations"] },
211
+ rootLabel: "Memory"
212
+ }
213
+ };
214
+ }
215
+ };
216
+
217
+ // adapters/obsidian.ts
218
+ var isNote = (p) => p.toLowerCase().endsWith(".md") && !p.split("/").some((s) => s.startsWith("."));
219
+ var stem = (p) => p.replace(/\.md$/i, "");
220
+ var baseName = (p) => stem(p).split("/").pop();
221
+ function frontmatter(text) {
222
+ const m = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/.exec(text);
223
+ if (!m) return { meta: {}, body: text };
224
+ const meta = {};
225
+ let listKey = "";
226
+ for (const line of m[1].split(/\r?\n/)) {
227
+ const item = /^\s+-\s+(.*)$/.exec(line);
228
+ if (item && listKey) {
229
+ meta[listKey].push(unquote(item[1]));
230
+ continue;
231
+ }
232
+ const kv = /^([\w-]+):\s*(.*)$/.exec(line);
233
+ if (!kv) continue;
234
+ listKey = "";
235
+ const v = kv[2].trim();
236
+ if (!v) {
237
+ meta[kv[1]] = [];
238
+ listKey = kv[1];
239
+ } else if (/^\[.*\]$/.test(v)) meta[kv[1]] = v.slice(1, -1).split(",").map((s) => unquote(s.trim())).filter(Boolean);
240
+ else meta[kv[1]] = unquote(v);
241
+ }
242
+ return { meta, body: text.slice(m[0].length) };
243
+ }
244
+ var unquote = (s) => s.replace(/^["']|["']$/g, "");
245
+ function convertObsidian(files) {
246
+ const notes = files.filter((f) => isNote(f.path));
247
+ const byPath = /* @__PURE__ */ new Map();
248
+ const byName = /* @__PURE__ */ new Map();
249
+ for (const f of [...notes].sort((a, b) => a.path.split("/").length - b.path.split("/").length || a.path.localeCompare(b.path))) {
250
+ const id = stem(f.path);
251
+ byPath.set(id.toLowerCase(), id);
252
+ const k = baseName(f.path).toLowerCase();
253
+ if (!byName.has(k)) byName.set(k, id);
254
+ }
255
+ const decodeSafe = (t) => {
256
+ try {
257
+ return decodeURIComponent(t);
258
+ } catch {
259
+ return t;
260
+ }
261
+ };
262
+ const resolve = (target, from) => {
263
+ const t = decodeSafe(target.split("#")[0].split("|")[0]).trim().replace(/\.md$/i, "");
264
+ if (!t) return void 0;
265
+ const dir = from.includes("/") ? from.slice(0, from.lastIndexOf("/") + 1) : "";
266
+ return byPath.get(t.toLowerCase()) ?? byPath.get(normalize(dir + t).toLowerCase()) ?? (t.includes("/") ? void 0 : byName.get(t.toLowerCase()));
267
+ };
268
+ const folders = /* @__PURE__ */ new Map();
269
+ return notes.map((f) => {
270
+ const id = stem(f.path);
271
+ const { meta, body } = frontmatter(f.text);
272
+ const edges = [];
273
+ const link = (target) => {
274
+ if (target && target !== id && !edges.some((e) => e.target === target)) edges.push({ source: id, target, kind: "link" });
275
+ return target;
276
+ };
277
+ const description = body.replace(/(!?)\[\[([^\]]+)\]\]/g, (all, bang, inner) => {
278
+ if (bang) return all;
279
+ const [target, alias] = String(inner).split("|");
280
+ const to = link(resolve(target, id));
281
+ const text = (alias ?? target.split("#")[0]).trim();
282
+ return to ? `[${text}](node:${to})` : text;
283
+ }).replace(/(?<!!)\[([^\]]*)\]\(([^)\s]+\.md)(#[^)\s]*)?\)/gi, (all, text, href) => {
284
+ if (/^[a-z]+:/i.test(href)) return all;
285
+ const to = link(resolve(href, id));
286
+ return to ? `[${text}](node:${to})` : all;
287
+ }).trim();
288
+ const parent = folderOf(f.path, folders);
289
+ const node = clean({
290
+ id,
291
+ label: typeof meta.title === "string" ? meta.title : baseName(f.path),
292
+ kind: typeof meta.type === "string" ? meta.type : "note",
293
+ parent,
294
+ description: description || void 0,
295
+ path: f.path,
296
+ tags: Array.isArray(meta.tags) && meta.tags.length ? meta.tags : typeof meta.tags === "string" ? [meta.tags] : void 0
297
+ });
298
+ const chain = [];
299
+ for (let p = parent; p; p = folders.get(p)?.parent) chain.unshift(folders.get(p));
300
+ return { origin: f.path, graph: { name: node.label, nodes: [...chain, node], edges } };
301
+ });
302
+ }
303
+ var normalize = (p) => {
304
+ const out = [];
305
+ for (const s of p.split("/")) {
306
+ if (s === "..") out.pop();
307
+ else if (s && s !== ".") out.push(s);
308
+ }
309
+ return out.join("/");
310
+ };
311
+ var obsidian = {
312
+ id: "obsidian",
313
+ label: "Markdown folder (Obsidian / LLM wiki)",
314
+ detect: (files) => files.some((f) => isNote(f.path)),
315
+ convert(files) {
316
+ const sources = convertObsidian(files);
317
+ const kinds = sources.map((s) => s.graph.nodes.at(-1).kind);
318
+ return {
319
+ sources,
320
+ profile: {
321
+ nodePalette: autoPalette(kinds),
322
+ edgePalette: { link: "#94a3b8" },
323
+ kindLabels: { folder: "Folder", note: "Note", link: "link" },
324
+ detail: { line: [{ key: "path", label: "File" }], list: [{ key: "tags", label: "Tags" }] },
325
+ rootLabel: "Notes"
326
+ }
327
+ };
328
+ }
329
+ };
330
+
331
+ // adapters/understand.ts
332
+ var DOWN = /* @__PURE__ */ new Set(["contains", "contains_flow", "flow_step"]);
333
+ var UP = /* @__PURE__ */ new Set(["categorized_under"]);
334
+ var looksLike2 = (d) => isObj(d) && Array.isArray(d.nodes) && Array.isArray(d.edges) && (Array.isArray(d.layers) || isObj(d.project)) && d.nodes.every((n) => isObj(n) && "type" in n && "name" in n);
335
+ function convertUnderstand(d) {
336
+ const raw = d.nodes.filter(isObj);
337
+ const ids = new Set(raw.map((n) => String(n.id)));
338
+ const parentOf = /* @__PURE__ */ new Map();
339
+ const claim = (child, parent) => {
340
+ if (child === parent || parentOf.has(child) || !ids.has(child) || !ids.has(parent)) return false;
341
+ if (wouldCycle(parentOf, child, parent)) return false;
342
+ parentOf.set(child, parent);
343
+ return true;
344
+ };
345
+ const edges = [];
346
+ for (const e of d.edges.filter(isObj)) {
347
+ let s = String(e.source);
348
+ let t = String(e.target);
349
+ if (e.direction === "backward") [s, t] = [t, s];
350
+ const type = String(e.type ?? "related");
351
+ if (DOWN.has(type) && claim(t, s)) continue;
352
+ if (UP.has(type) && claim(s, t)) continue;
353
+ edges.push(clean({
354
+ source: s,
355
+ target: t,
356
+ kind: type,
357
+ weight: typeof e.weight === "number" ? e.weight : void 0,
358
+ description: e.description,
359
+ ...e.direction === "bidirectional" ? { bidirectional: true } : {}
360
+ }));
361
+ }
362
+ const extra = /* @__PURE__ */ new Map();
363
+ const layerOf = /* @__PURE__ */ new Map();
364
+ for (const l of (d.layers ?? []).filter(isObj)) {
365
+ const id = `ua-layer:${l.id}`;
366
+ extra.set(id, clean({ id, label: String(l.name ?? l.id), kind: "layer", description: l.description }));
367
+ for (const n of l.nodeIds ?? []) if (!layerOf.has(String(n))) layerOf.set(String(n), id);
368
+ }
369
+ const nodes = raw.map((n) => {
370
+ const id = String(n.id);
371
+ const file = typeof n.filePath === "string" ? n.filePath : "";
372
+ const parent = parentOf.get(id) ?? layerOf.get(id) ?? (file ? folderOf(file, extra) : void 0);
373
+ const lines = Array.isArray(n.lineRange) ? `${n.lineRange[0]}\u2013${n.lineRange[1]}` : void 0;
374
+ return clean({
375
+ id,
376
+ label: String(n.name ?? id),
377
+ kind: String(n.type ?? "node"),
378
+ parent,
379
+ description: n.summary,
380
+ filePath: file || void 0,
381
+ lines,
382
+ complexity: n.complexity,
383
+ tags: Array.isArray(n.tags) && n.tags.length ? n.tags : void 0,
384
+ languageNotes: n.languageNotes
385
+ });
386
+ });
387
+ return { name: String(d.project?.name ?? "Understand-Anything"), nodes: [...extra.values(), ...nodes], edges };
388
+ }
389
+ var PROFILE2 = {
390
+ nodePalette: {
391
+ function: "#6366f1",
392
+ class: "#be38f3",
393
+ concept: "#e63b7a",
394
+ document: "#0891b2",
395
+ config: "#64748b",
396
+ service: "#ff6a00",
397
+ table: "#16a34a",
398
+ endpoint: "#f59e0b",
399
+ schema: "#16a34a",
400
+ pipeline: "#ff6a00",
401
+ resource: "#64748b",
402
+ domain: "#e63b7a",
403
+ flow: "#6366f1",
404
+ step: "#f59e0b",
405
+ article: "#0891b2",
406
+ entity: "#6366f1",
407
+ topic: "#e63b7a",
408
+ claim: "#f59e0b",
409
+ source: "#64748b",
410
+ screen: "#0891b2",
411
+ component: "#6366f1",
412
+ token: "#f59e0b"
413
+ },
414
+ edgePalette: {
415
+ imports: "#94a3b8",
416
+ exports: "#94a3b8",
417
+ calls: "#6366f1",
418
+ depends_on: "#f59e0b",
419
+ tested_by: "#16a34a",
420
+ inherits: "#be38f3",
421
+ implements: "#be38f3",
422
+ related: "#e63b7a",
423
+ similar_to: "#e63b7a",
424
+ documents: "#0891b2",
425
+ reads_from: "#0891b2",
426
+ writes_to: "#ff6a00",
427
+ cites: "#0891b2",
428
+ contradicts: "#ef4444",
429
+ builds_on: "#16a34a"
430
+ },
431
+ kindLabels: { layer: "Layer", folder: "Folder", file: "File", function: "Function", class: "Class", document: "Document", config: "Config" },
432
+ detail: {
433
+ line: [{ key: "filePath", label: "File" }, { key: "lines", label: "Lines" }, { key: "complexity", label: "Complexity" }],
434
+ list: [{ key: "tags", label: "Tags" }]
435
+ },
436
+ rootLabel: "Understand-Anything"
437
+ };
438
+ var understand = {
439
+ id: "understand-anything",
440
+ label: "Understand-Anything knowledge-graph.json",
441
+ detect: (files) => files.some((f) => f.path.endsWith(".json") && looksLike2(tryJson(f.text))),
442
+ convert(files) {
443
+ const sources = files.flatMap((f) => {
444
+ const d = f.path.endsWith(".json") ? tryJson(f.text) : void 0;
445
+ return looksLike2(d) ? [{ origin: f.path, graph: convertUnderstand(d) }] : [];
446
+ });
447
+ return { sources, profile: PROFILE2 };
448
+ }
449
+ };
450
+
451
+ // adapters/index.ts
452
+ var ADAPTERS = [understand, graphify, memory];
453
+ var MARKDOWN = obsidian;
454
+ function adapt(files, only) {
455
+ const pick = only === "native" ? null : only ? [...ADAPTERS, MARKDOWN].find((a) => a.id === only) ?? null : ADAPTERS.find((a) => a.detect(files)) ?? (MARKDOWN.detect(files) && !files.some(isNativeGraph) ? MARKDOWN : null);
456
+ if (only && only !== "native" && !pick) throw new Error(`Unknown format: ${only} (known: native, ${[...ADAPTERS, MARKDOWN].map((a) => a.id).join(", ")})`);
457
+ if (!pick) {
458
+ const json = files.filter((f) => /\.json$/i.test(f.path));
459
+ return {
460
+ sources: json.map((f) => ({ origin: f.path, text: f.text })),
461
+ profile: null,
462
+ adapter: null,
463
+ skipped: files.filter((f) => /\.jsonl$/i.test(f.path)).map((f) => f.path)
464
+ };
465
+ }
466
+ const out = pick.convert(files);
467
+ const skipped = pick === MARKDOWN ? [] : files.filter((f) => /\.jsonl?$/i.test(f.path) && !pick.detect([f])).map((f) => f.path);
468
+ return {
469
+ sources: out.sources.map((s) => ({ origin: s.origin, text: JSON.stringify(s.graph) })),
470
+ profile: out.profile,
471
+ adapter: pick,
472
+ skipped
473
+ };
474
+ }
475
+ var isNativeGraph = (f) => {
476
+ if (!/\.json$/i.test(f.path)) return false;
477
+ try {
478
+ const d = JSON.parse(f.text);
479
+ return !!d && typeof d === "object" && ("nodes" in d || "edges" in d);
480
+ } catch {
481
+ return false;
482
+ }
483
+ };
484
+ export {
485
+ ADAPTERS,
486
+ MARKDOWN,
487
+ adapt,
488
+ convertGraphify,
489
+ convertMemory,
490
+ convertObsidian,
491
+ convertUnderstand
492
+ };