speccore 6.89.0 → 6.90.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.
- package/dist/cli.js +15 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/code-index.d.ts +1 -0
- package/dist/commands/code-index.d.ts.map +1 -1
- package/dist/commands/code-index.js +10 -0
- package/dist/commands/code-index.js.map +1 -1
- package/dist/commands/knowledge.d.ts +12 -0
- package/dist/commands/knowledge.d.ts.map +1 -1
- package/dist/commands/knowledge.js +80 -0
- package/dist/commands/knowledge.js.map +1 -1
- package/dist/core/code-graph/builder.d.ts +6 -0
- package/dist/core/code-graph/builder.d.ts.map +1 -0
- package/dist/core/code-graph/builder.js +155 -0
- package/dist/core/code-graph/builder.js.map +1 -0
- package/dist/core/code-graph/index.d.ts +25 -0
- package/dist/core/code-graph/index.d.ts.map +1 -0
- package/dist/core/code-graph/index.js +125 -0
- package/dist/core/code-graph/index.js.map +1 -0
- package/dist/core/code-graph/parser.d.ts +10 -0
- package/dist/core/code-graph/parser.d.ts.map +1 -0
- package/dist/core/code-graph/parser.js +314 -0
- package/dist/core/code-graph/parser.js.map +1 -0
- package/dist/core/code-graph/query.d.ts +14 -0
- package/dist/core/code-graph/query.d.ts.map +1 -0
- package/dist/core/code-graph/query.js +112 -0
- package/dist/core/code-graph/query.js.map +1 -0
- package/dist/core/code-graph/reporter.d.ts +7 -0
- package/dist/core/code-graph/reporter.d.ts.map +1 -0
- package/dist/core/code-graph/reporter.js +97 -0
- package/dist/core/code-graph/reporter.js.map +1 -0
- package/dist/core/code-graph/types.d.ts +60 -0
- package/dist/core/code-graph/types.d.ts.map +1 -0
- package/dist/core/code-graph/types.js +7 -0
- package/dist/core/code-graph/types.js.map +1 -0
- package/dist/core/code-graph/visualizer.d.ts +9 -0
- package/dist/core/code-graph/visualizer.d.ts.map +1 -0
- package/dist/core/code-graph/visualizer.js +97 -0
- package/dist/core/code-graph/visualizer.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateGraphReport = generateGraphReport;
|
|
4
|
+
function generateGraphReport(graph) {
|
|
5
|
+
const m = graph.metadata;
|
|
6
|
+
const lines = [];
|
|
7
|
+
lines.push(`# ${m.projectName} — Code Knowledge Graph Report`);
|
|
8
|
+
lines.push('');
|
|
9
|
+
lines.push(`> Generated at: ${m.generatedAt}`);
|
|
10
|
+
lines.push(`> Scanned: ${m.scannedFiles} files | ${m.totalNodes} nodes | ${m.totalEdges} edges`);
|
|
11
|
+
lines.push(`> Confidence: ${m.extractedEdges} EXTRACTED | ${m.inferredEdges} INFERRED`);
|
|
12
|
+
lines.push('');
|
|
13
|
+
// 1. God Nodes
|
|
14
|
+
lines.push('## 🔥 God Nodes (Most Connected)');
|
|
15
|
+
lines.push('');
|
|
16
|
+
const godNodeDetails = graph.godNodes
|
|
17
|
+
.map(id => graph.nodes.find(n => n.id === id))
|
|
18
|
+
.filter(Boolean);
|
|
19
|
+
for (const n of godNodeDetails.slice(0, 15)) {
|
|
20
|
+
lines.push(`- **${n.name}** (${n.type}) — degree: ${n.degree}, file: \`${n.filePath}\``);
|
|
21
|
+
}
|
|
22
|
+
lines.push('');
|
|
23
|
+
// 2. Communities
|
|
24
|
+
lines.push('## 🏘️ Communities (Auto-detected Subsystems)');
|
|
25
|
+
lines.push('');
|
|
26
|
+
for (const comm of graph.communities.slice(0, 10)) {
|
|
27
|
+
lines.push(`### Community ${comm.id}: ${comm.label}`);
|
|
28
|
+
lines.push(`- Nodes: ${comm.nodes.length} | Density: ${(comm.density * 100).toFixed(1)}%`);
|
|
29
|
+
const sampleNodes = comm.nodes
|
|
30
|
+
.map(id => graph.nodes.find(n => n.id === id))
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.slice(0, 8);
|
|
33
|
+
lines.push(`- Key members: ${sampleNodes.map(n => n.name).join(', ')}${comm.nodes.length > 8 ? '...' : ''}`);
|
|
34
|
+
lines.push('');
|
|
35
|
+
}
|
|
36
|
+
// 3. Cross-community Bridges
|
|
37
|
+
lines.push('## 🔗 Cross-Community Bridges');
|
|
38
|
+
lines.push('');
|
|
39
|
+
const bridgeEdges = graph.edges.filter(e => {
|
|
40
|
+
const s = graph.nodes.find(n => n.id === e.source);
|
|
41
|
+
const t = graph.nodes.find(n => n.id === e.target);
|
|
42
|
+
return s && t && s.community !== undefined && t.community !== undefined && s.community !== t.community;
|
|
43
|
+
}).slice(0, 15);
|
|
44
|
+
if (bridgeEdges.length === 0) {
|
|
45
|
+
lines.push('No significant cross-community bridges detected.');
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
for (const e of bridgeEdges) {
|
|
49
|
+
const s = graph.nodes.find(n => n.id === e.source);
|
|
50
|
+
const t = graph.nodes.find(n => n.id === e.target);
|
|
51
|
+
lines.push(`- \`${s?.name}\` [${e.type}] → \`${t?.name}\` (${e.confidence})`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
lines.push('');
|
|
55
|
+
// 4. Suggested Questions
|
|
56
|
+
lines.push('## ❓ Suggested Questions');
|
|
57
|
+
lines.push('');
|
|
58
|
+
const topComm = graph.communities[0];
|
|
59
|
+
if (topComm) {
|
|
60
|
+
lines.push(`- "How does \`${topComm.label}\` subsystem interact with other modules?"`);
|
|
61
|
+
}
|
|
62
|
+
if (graph.godNodes[0]) {
|
|
63
|
+
const topGod = graph.nodes.find(n => n.id === graph.godNodes[0]);
|
|
64
|
+
lines.push(`- "What depends on \`${topGod?.name}\` and why is it a god node?"`);
|
|
65
|
+
}
|
|
66
|
+
const deepestDir = findDeepestDir(graph.nodes);
|
|
67
|
+
if (deepestDir) {
|
|
68
|
+
lines.push(`- "Explain the architecture of \`${deepestDir}\`"`);
|
|
69
|
+
}
|
|
70
|
+
lines.push(`- "Find the shortest path from entry point to database layer"`);
|
|
71
|
+
lines.push('');
|
|
72
|
+
// 5. Query Examples
|
|
73
|
+
lines.push('## 🛠️ Query Examples');
|
|
74
|
+
lines.push('');
|
|
75
|
+
lines.push('```bash');
|
|
76
|
+
lines.push('# Explain a concept');
|
|
77
|
+
lines.push(`speccore knowledge explain "${godNodeDetails[0]?.name || 'main'}"`);
|
|
78
|
+
lines.push('');
|
|
79
|
+
lines.push('# Trace path between two concepts');
|
|
80
|
+
lines.push(`speccore knowledge path "${godNodeDetails[0]?.name || 'A'}" "${godNodeDetails[1]?.name || 'B'}"`);
|
|
81
|
+
lines.push('');
|
|
82
|
+
lines.push('# Natural language query');
|
|
83
|
+
lines.push('speccore knowledge query "How is authentication handled?"');
|
|
84
|
+
lines.push('```');
|
|
85
|
+
lines.push('');
|
|
86
|
+
return lines.join('\n');
|
|
87
|
+
}
|
|
88
|
+
function findDeepestDir(nodes) {
|
|
89
|
+
const dirs = new Set(nodes.map(n => n.filePath.split('/').slice(0, -1).join('/')));
|
|
90
|
+
let deepest = '';
|
|
91
|
+
for (const d of dirs) {
|
|
92
|
+
if (d.split('/').length > deepest.split('/').length)
|
|
93
|
+
deepest = d;
|
|
94
|
+
}
|
|
95
|
+
return deepest || null;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=reporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter.js","sourceRoot":"","sources":["../../../src/core/code-graph/reporter.ts"],"names":[],"mappings":";;AAMA,kDA0FC;AA1FD,SAAgB,mBAAmB,CAAC,KAAgB;IAClD,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC;IACzB,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,WAAW,gCAAgC,CAAC,CAAC;IAC/D,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/C,KAAK,CAAC,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AAK,CAAC,CAAC;IAClB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,cAAc,CAAC,KAA6B;IACnD,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACnF,IAAI,OAAO,GAAG,EAAE,CAAC;IACjB,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM;YAAE,OAAO,GAAG,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,OAAO,IAAI,IAAI,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Knowledge Graph — 类型定义
|
|
3
|
+
* v6.90.0: 本地 AST 解析构建代码知识图谱
|
|
4
|
+
*/
|
|
5
|
+
export type NodeType = 'function' | 'class' | 'interface' | 'type' | 'variable' | 'module' | 'method' | 'property' | 'enum';
|
|
6
|
+
export type EdgeType = 'calls' | 'imports' | 'exports' | 'extends' | 'implements' | 'references' | 'contains' | 'typed_by';
|
|
7
|
+
export type Confidence = 'EXTRACTED' | 'INFERRED';
|
|
8
|
+
export interface CodeNode {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string;
|
|
11
|
+
type: NodeType;
|
|
12
|
+
filePath: string;
|
|
13
|
+
line: number;
|
|
14
|
+
column: number;
|
|
15
|
+
community?: number;
|
|
16
|
+
degree?: number;
|
|
17
|
+
/** 代码片段(前200字符) */
|
|
18
|
+
snippet?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface CodeEdge {
|
|
21
|
+
source: string;
|
|
22
|
+
target: string;
|
|
23
|
+
type: EdgeType;
|
|
24
|
+
confidence: Confidence;
|
|
25
|
+
/** 关系发生的文件 */
|
|
26
|
+
filePath?: string;
|
|
27
|
+
/** 行号 */
|
|
28
|
+
line?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface CodeCommunity {
|
|
31
|
+
id: number;
|
|
32
|
+
/** 社区标签(通常是目录名或高频概念) */
|
|
33
|
+
label: string;
|
|
34
|
+
nodes: string[];
|
|
35
|
+
/** 内部边数 / 总边数 */
|
|
36
|
+
density: number;
|
|
37
|
+
}
|
|
38
|
+
export interface CodeGraph {
|
|
39
|
+
nodes: CodeNode[];
|
|
40
|
+
edges: CodeEdge[];
|
|
41
|
+
communities: CodeCommunity[];
|
|
42
|
+
/** 高度数节点(连接数前10%) */
|
|
43
|
+
godNodes: string[];
|
|
44
|
+
metadata: {
|
|
45
|
+
projectName: string;
|
|
46
|
+
projectRoot: string;
|
|
47
|
+
scannedFiles: number;
|
|
48
|
+
totalNodes: number;
|
|
49
|
+
totalEdges: number;
|
|
50
|
+
extractedEdges: number;
|
|
51
|
+
inferredEdges: number;
|
|
52
|
+
generatedAt: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export interface GraphQueryResult {
|
|
56
|
+
nodes: CodeNode[];
|
|
57
|
+
edges: CodeEdge[];
|
|
58
|
+
path?: string[];
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/code-graph/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,OAAO,GACP,WAAW,GACX,MAAM,GACN,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,MAAM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;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC;QACnB,cAAc,EAAE,MAAM,CAAC;QACvB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/code-graph/types.ts"],"names":[],"mappings":";AAAA;;;GAGG"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Code Knowledge Graph — graph.html 可视化生成器
|
|
3
|
+
* v6.90.0
|
|
4
|
+
*
|
|
5
|
+
* 使用 vis-network CDN,与现有 knowledge-visualizer 风格一致
|
|
6
|
+
*/
|
|
7
|
+
import type { CodeGraph } from './types';
|
|
8
|
+
export declare function buildCodeGraphHtml(graph: CodeGraph): string;
|
|
9
|
+
//# sourceMappingURL=visualizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visualizer.d.ts","sourceRoot":"","sources":["../../../src/core/code-graph/visualizer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM,CAiG3D"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildCodeGraphHtml = buildCodeGraphHtml;
|
|
4
|
+
function buildCodeGraphHtml(graph) {
|
|
5
|
+
const palette = [
|
|
6
|
+
'#0ea5e9', '#14b8a6', '#f97316', '#8b5cf6',
|
|
7
|
+
'#ec4899', '#22c55e', '#eab308', '#6366f1',
|
|
8
|
+
'#06b6d4', '#f43f5e',
|
|
9
|
+
];
|
|
10
|
+
const nodes = graph.nodes.map(n => ({
|
|
11
|
+
id: n.id,
|
|
12
|
+
label: n.name,
|
|
13
|
+
group: n.community ?? -1,
|
|
14
|
+
title: `<b>${n.name}</b><br>type: ${n.type}<br>file: ${n.filePath}<br>line: ${n.line}<br>degree: ${n.degree}`,
|
|
15
|
+
value: n.degree || 1,
|
|
16
|
+
color: n.community !== undefined ? palette[n.community % palette.length] : '#94a3b8',
|
|
17
|
+
}));
|
|
18
|
+
const edges = graph.edges.map((e, i) => ({
|
|
19
|
+
from: e.source,
|
|
20
|
+
to: e.target,
|
|
21
|
+
label: e.type,
|
|
22
|
+
title: `${e.type} (${e.confidence})`,
|
|
23
|
+
dashes: e.confidence === 'INFERRED',
|
|
24
|
+
color: e.confidence === 'EXTRACTED' ? { color: '#0ea5e9', opacity: 0.6 } : { color: '#94a3b8', opacity: 0.4 },
|
|
25
|
+
arrows: { to: { enabled: true, scaleFactor: 0.5 } },
|
|
26
|
+
}));
|
|
27
|
+
const godNodeSet = new Set(graph.godNodes);
|
|
28
|
+
for (const n of nodes) {
|
|
29
|
+
if (godNodeSet.has(n.id)) {
|
|
30
|
+
n.value = (n.value || 1) * 2;
|
|
31
|
+
n.font = { size: 16, bold: true };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const meta = graph.metadata;
|
|
35
|
+
return `<!DOCTYPE html>
|
|
36
|
+
<html lang="zh-CN">
|
|
37
|
+
<head>
|
|
38
|
+
<meta charset="UTF-8">
|
|
39
|
+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
40
|
+
<title>${meta.projectName} — Code Graph</title>
|
|
41
|
+
<script src="https://unpkg.com/vis-network/standalone/umd/vis-network.min.js"></script>
|
|
42
|
+
<style>
|
|
43
|
+
body{margin:0;font-family:'Segoe UI',system-ui,sans-serif;background:#0b1929;color:#bae6fd;overflow:hidden}
|
|
44
|
+
#graph{position:fixed;inset:0}
|
|
45
|
+
.panel{position:fixed;top:12px;left:12px;background:rgba(13,31,56,.95);border:1px solid rgba(14,165,233,.2);border-radius:10px;padding:14px;max-width:280px;z-index:10;font-size:12px}
|
|
46
|
+
.panel h2{margin:0 0 8px;font-size:14px;color:#0ea5e9}
|
|
47
|
+
.panel .stat{display:flex;justify-content:space-between;padding:3px 0;border-bottom:1px solid rgba(255,255,255,.05)}
|
|
48
|
+
.panel .stat span{color:#5b7fa5}
|
|
49
|
+
.panel .legend{margin-top:10px}
|
|
50
|
+
.panel .legend-item{display:flex;align-items:center;gap:6px;margin:4px 0}
|
|
51
|
+
.panel .dot{width:10px;height:10px;border-radius:50%}
|
|
52
|
+
.panel .line{width:20px;height:2px}
|
|
53
|
+
.search{position:fixed;top:12px;right:12px;z-index:10;display:flex;gap:6px}
|
|
54
|
+
.search input{background:rgba(13,31,56,.95);border:1px solid rgba(14,165,233,.2);border-radius:6px;padding:6px 10px;color:#bae6fd;font-size:12px;outline:none;width:180px}
|
|
55
|
+
.search input::placeholder{color:#5b7fa5}
|
|
56
|
+
.search button{background:#0ea5e9;border:none;border-radius:6px;padding:6px 12px;color:#fff;font-size:12px;cursor:pointer}
|
|
57
|
+
</style>
|
|
58
|
+
</head>
|
|
59
|
+
<body>
|
|
60
|
+
<div id="graph"></div>
|
|
61
|
+
<div class="panel">
|
|
62
|
+
<h2>${meta.projectName}</h2>
|
|
63
|
+
<div class="stat">Files <span>${meta.scannedFiles}</span></div>
|
|
64
|
+
<div class="stat">Nodes <span>${meta.totalNodes}</span></div>
|
|
65
|
+
<div class="stat">Edges <span>${meta.totalEdges}</span></div>
|
|
66
|
+
<div class="stat">Communities <span>${graph.communities.length}</span></div>
|
|
67
|
+
<div class="stat">EXTRACTED <span>${meta.extractedEdges}</span></div>
|
|
68
|
+
<div class="stat">INFERRED <span>${meta.inferredEdges}</span></div>
|
|
69
|
+
<div class="legend">
|
|
70
|
+
<div class="legend-item"><span class="dot" style="background:#0ea5e9"></span> EXTRACTED edge</div>
|
|
71
|
+
<div class="legend-item"><span class="line" style="background:#94a3b8;border-top:2px dashed #94a3b8"></span> INFERRED edge</div>
|
|
72
|
+
<div class="legend-item"><span class="dot" style="background:#f97316"></span> God node</div>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
<div class="search">
|
|
76
|
+
<input type="text" id="searchInput" placeholder="Search node...">
|
|
77
|
+
<button onclick="searchNode()">Find</button>
|
|
78
|
+
</div>
|
|
79
|
+
<script>
|
|
80
|
+
const nodes=new vis.DataSet(${JSON.stringify(nodes)});
|
|
81
|
+
const edges=new vis.DataSet(${JSON.stringify(edges)});
|
|
82
|
+
const container=document.getElementById('graph');
|
|
83
|
+
const data={nodes,edges};
|
|
84
|
+
const options={
|
|
85
|
+
nodes:{shape:'dot',font:{color:'#bae6fd',size:12},borderWidth:1,borderWidthSelected:2},
|
|
86
|
+
edges:{width:1,smooth:{type:'continuous'}},
|
|
87
|
+
physics:{stabilization:false,barnesHut:{gravitationalConstant:-3000,springConstant:0.04,springLength:95}},
|
|
88
|
+
interaction:{hover:true,tooltipDelay:200,hideEdgesOnDrag:true}
|
|
89
|
+
};
|
|
90
|
+
const network=new vis.Network(container,data,options);
|
|
91
|
+
function searchNode(){const v=document.getElementById('searchInput').value.toLowerCase();const found=nodes.get({filter:n=>n.label.toLowerCase().includes(v)})[0];if(found){network.focus(found.id,{scale:1.2,animation:true});network.selectNodes([found.id]);}}
|
|
92
|
+
document.getElementById('searchInput').addEventListener('keydown',e=>{if(e.key==='Enter')searchNode();});
|
|
93
|
+
</script>
|
|
94
|
+
</body>
|
|
95
|
+
</html>`;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=visualizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visualizer.js","sourceRoot":"","sources":["../../../src/core/code-graph/visualizer.ts"],"names":[],"mappings":";;AAQA,gDAiGC;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