tskb 0.0.1
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/LICENSE +21 -0
- package/README.md +1086 -0
- package/dist/cli/commands/build.d.ts +55 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +105 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/query.d.ts +10 -0
- package/dist/cli/commands/query.d.ts.map +1 -0
- package/dist/cli/commands/query.js +399 -0
- package/dist/cli/commands/query.js.map +1 -0
- package/dist/cli/commands/visualize.d.ts +10 -0
- package/dist/cli/commands/visualize.d.ts.map +1 -0
- package/dist/cli/commands/visualize.js +26 -0
- package/dist/cli/commands/visualize.js.map +1 -0
- package/dist/cli/index.d.ts +9 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +109 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/core/extraction/documentation.d.ts +28 -0
- package/dist/core/extraction/documentation.d.ts.map +1 -0
- package/dist/core/extraction/documentation.js +330 -0
- package/dist/core/extraction/documentation.js.map +1 -0
- package/dist/core/extraction/index.d.ts +11 -0
- package/dist/core/extraction/index.d.ts.map +1 -0
- package/dist/core/extraction/index.js +9 -0
- package/dist/core/extraction/index.js.map +1 -0
- package/dist/core/extraction/registry.d.ts +40 -0
- package/dist/core/extraction/registry.d.ts.map +1 -0
- package/dist/core/extraction/registry.js +604 -0
- package/dist/core/extraction/registry.js.map +1 -0
- package/dist/core/graph/builder.d.ts +37 -0
- package/dist/core/graph/builder.d.ts.map +1 -0
- package/dist/core/graph/builder.js +421 -0
- package/dist/core/graph/builder.js.map +1 -0
- package/dist/core/graph/index.d.ts +23 -0
- package/dist/core/graph/index.d.ts.map +1 -0
- package/dist/core/graph/index.js +25 -0
- package/dist/core/graph/index.js.map +1 -0
- package/dist/core/graph/types.d.ts +128 -0
- package/dist/core/graph/types.d.ts.map +1 -0
- package/dist/core/graph/types.js +9 -0
- package/dist/core/graph/types.js.map +1 -0
- package/dist/core/visualization/dot-generator.d.ts +13 -0
- package/dist/core/visualization/dot-generator.d.ts.map +1 -0
- package/dist/core/visualization/dot-generator.js +200 -0
- package/dist/core/visualization/dot-generator.js.map +1 -0
- package/dist/core/visualization/index.d.ts +20 -0
- package/dist/core/visualization/index.d.ts.map +1 -0
- package/dist/core/visualization/index.js +23 -0
- package/dist/core/visualization/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-runtime.d.ts +7 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +11 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/runtime/jsx.d.ts +84 -0
- package/dist/runtime/jsx.d.ts.map +1 -0
- package/dist/runtime/jsx.js +93 -0
- package/dist/runtime/jsx.js.map +1 -0
- package/dist/runtime/registry.d.ts +61 -0
- package/dist/runtime/registry.d.ts.map +1 -0
- package/dist/runtime/registry.js +2 -0
- package/dist/runtime/registry.js.map +1 -0
- package/dist/typescript/index.d.ts +7 -0
- package/dist/typescript/index.d.ts.map +1 -0
- package/dist/typescript/index.js +7 -0
- package/dist/typescript/index.js.map +1 -0
- package/dist/typescript/program.d.ts +33 -0
- package/dist/typescript/program.d.ts.map +1 -0
- package/dist/typescript/program.js +84 -0
- package/dist/typescript/program.js.map +1 -0
- package/package.json +73 -0
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
/**
|
|
3
|
+
* Builds a knowledge graph from extracted registry and documentation data.
|
|
4
|
+
*
|
|
5
|
+
* GRAPH STRUCTURE:
|
|
6
|
+
* A knowledge graph has two parts:
|
|
7
|
+
* 1. NODES: The "things" in your system (Folders, Modules, Terms, Docs)
|
|
8
|
+
* 2. EDGES: Relationships between nodes ("doc X references module Y")
|
|
9
|
+
*
|
|
10
|
+
* BUILDING PROCESS:
|
|
11
|
+
* 1. Create nodes from registry:
|
|
12
|
+
* - Each Folder becomes a FolderNode with { id, desc, path }
|
|
13
|
+
* - Each Module becomes a ModuleNode with { id, desc, typeSignature }
|
|
14
|
+
* - Each Term becomes a TermNode with { id, desc }
|
|
15
|
+
*
|
|
16
|
+
* 2. Create nodes from docs:
|
|
17
|
+
* - Each doc file becomes a DocNode with { id, filePath, content }
|
|
18
|
+
*
|
|
19
|
+
* 3. Create edges from references:
|
|
20
|
+
* - For each doc, look at its references.modules/terms/folders
|
|
21
|
+
* - Create an edge: { from: docId, to: moduleId, type: "references" }
|
|
22
|
+
*
|
|
23
|
+
* RESULT:
|
|
24
|
+
* A complete graph that can be queried: "What docs reference Module X?"
|
|
25
|
+
* "What terms are used in Folder Y?", etc.
|
|
26
|
+
*
|
|
27
|
+
* This is what feeds AI tools to understand your architecture.
|
|
28
|
+
*
|
|
29
|
+
* @param registry - Extracted vocabulary (Folders, Modules, Terms)
|
|
30
|
+
* @param docs - Extracted documentation files
|
|
31
|
+
* @param baseDir - Base directory (from tsconfig) to make paths relative to
|
|
32
|
+
* @returns Complete knowledge graph ready for JSON export
|
|
33
|
+
*/
|
|
34
|
+
export function buildGraph(registry, docs, baseDir) {
|
|
35
|
+
const graph = {
|
|
36
|
+
nodes: {
|
|
37
|
+
folders: {},
|
|
38
|
+
modules: {},
|
|
39
|
+
terms: {},
|
|
40
|
+
exports: {},
|
|
41
|
+
docs: {},
|
|
42
|
+
},
|
|
43
|
+
edges: [],
|
|
44
|
+
metadata: {
|
|
45
|
+
generatedAt: new Date().toISOString(),
|
|
46
|
+
version: "1.0.0",
|
|
47
|
+
stats: {
|
|
48
|
+
folderCount: 0,
|
|
49
|
+
moduleCount: 0,
|
|
50
|
+
termCount: 0,
|
|
51
|
+
exportCount: 0,
|
|
52
|
+
docCount: 0,
|
|
53
|
+
edgeCount: 0,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// Build nodes from registry
|
|
58
|
+
buildFolderNodes(registry, graph);
|
|
59
|
+
buildModuleNodes(registry, graph);
|
|
60
|
+
buildTermNodes(registry, graph);
|
|
61
|
+
buildExportNodes(registry, graph);
|
|
62
|
+
// Build nodes from docs
|
|
63
|
+
buildDocNodes(docs, graph, baseDir);
|
|
64
|
+
// Build edges (relationships)
|
|
65
|
+
buildEdges(docs, graph, baseDir);
|
|
66
|
+
// Build hierarchical edges
|
|
67
|
+
buildFolderHierarchy(graph);
|
|
68
|
+
buildModuleFolderMembership(graph);
|
|
69
|
+
buildExportMembership(graph);
|
|
70
|
+
// Update stats
|
|
71
|
+
updateStats(graph);
|
|
72
|
+
return graph;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create Folder nodes from registry
|
|
76
|
+
*/
|
|
77
|
+
function buildFolderNodes(registry, graph) {
|
|
78
|
+
for (const [name, data] of registry.folders.entries()) {
|
|
79
|
+
const node = {
|
|
80
|
+
id: name,
|
|
81
|
+
type: "folder",
|
|
82
|
+
desc: data.desc,
|
|
83
|
+
path: data.path,
|
|
84
|
+
resolvedPath: data.resolvedPath,
|
|
85
|
+
pathExists: data.pathExists,
|
|
86
|
+
};
|
|
87
|
+
graph.nodes.folders[name] = node;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create Module nodes from registry
|
|
92
|
+
*/
|
|
93
|
+
function buildModuleNodes(registry, graph) {
|
|
94
|
+
for (const [name, data] of registry.modules.entries()) {
|
|
95
|
+
const node = {
|
|
96
|
+
id: name,
|
|
97
|
+
type: "module",
|
|
98
|
+
desc: data.desc,
|
|
99
|
+
typeSignature: data.type,
|
|
100
|
+
importPath: data.importPath,
|
|
101
|
+
resolvedPath: data.resolvedPath,
|
|
102
|
+
pathExists: data.pathExists,
|
|
103
|
+
};
|
|
104
|
+
graph.nodes.modules[name] = node;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create Term nodes from registry
|
|
109
|
+
*/
|
|
110
|
+
function buildTermNodes(registry, graph) {
|
|
111
|
+
for (const [name, desc] of registry.terms.entries()) {
|
|
112
|
+
const node = {
|
|
113
|
+
id: name,
|
|
114
|
+
type: "term",
|
|
115
|
+
desc,
|
|
116
|
+
};
|
|
117
|
+
graph.nodes.terms[name] = node;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Create Export nodes from registry
|
|
122
|
+
*/
|
|
123
|
+
function buildExportNodes(registry, graph) {
|
|
124
|
+
for (const [name, data] of registry.exports.entries()) {
|
|
125
|
+
const node = {
|
|
126
|
+
id: name,
|
|
127
|
+
type: "export",
|
|
128
|
+
desc: data.desc,
|
|
129
|
+
typeSignature: data.type,
|
|
130
|
+
importPath: data.importPath,
|
|
131
|
+
resolvedPath: data.resolvedPath,
|
|
132
|
+
pathExists: data.pathExists,
|
|
133
|
+
};
|
|
134
|
+
graph.nodes.exports[name] = node;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Create Doc nodes from extracted documentation
|
|
139
|
+
*/
|
|
140
|
+
function buildDocNodes(docs, graph, baseDir) {
|
|
141
|
+
for (const doc of docs) {
|
|
142
|
+
// doc.filePath is already relative from extraction, use it directly as both id and filePath
|
|
143
|
+
const id = doc.filePath;
|
|
144
|
+
const node = {
|
|
145
|
+
id,
|
|
146
|
+
type: "doc",
|
|
147
|
+
filePath: doc.filePath, // Now relative, not absolute
|
|
148
|
+
content: doc.content,
|
|
149
|
+
format: doc.format,
|
|
150
|
+
};
|
|
151
|
+
graph.nodes.docs[id] = node;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Build edges (relationships) between nodes.
|
|
156
|
+
*
|
|
157
|
+
* CREATING GRAPH RELATIONSHIPS:
|
|
158
|
+
* We have all the nodes, now we connect them based on references.
|
|
159
|
+
*
|
|
160
|
+
* For each doc file:
|
|
161
|
+
* - Look at doc.references.modules = ["AuthService", "PaymentAPI"]
|
|
162
|
+
* - For each module name, create edge: doc -> module (type: "references")
|
|
163
|
+
* - Same for terms and contexts
|
|
164
|
+
*
|
|
165
|
+
* VALIDATION:
|
|
166
|
+
* We only create edges if the target node actually exists in the graph.
|
|
167
|
+
* If doc references "NonExistentModule", we skip it (could log a warning).
|
|
168
|
+
*
|
|
169
|
+
* FUTURE EDGE TYPES:
|
|
170
|
+
* Could add more relationship types:
|
|
171
|
+
* - "belongs-to": Module belongs to Context (if we annotate that)
|
|
172
|
+
* - "related-to": Doc is related to another Doc
|
|
173
|
+
* - "implements": Module implements an interface
|
|
174
|
+
*
|
|
175
|
+
* Right now we just do "references" which is the most important.
|
|
176
|
+
*/
|
|
177
|
+
function buildEdges(docs, graph, baseDir) {
|
|
178
|
+
for (const doc of docs) {
|
|
179
|
+
// doc.filePath is already relative from extraction
|
|
180
|
+
const docId = doc.filePath;
|
|
181
|
+
// Create "references" edges from doc to modules/terms/contexts
|
|
182
|
+
for (const moduleName of doc.references.modules) {
|
|
183
|
+
if (graph.nodes.modules[moduleName]) {
|
|
184
|
+
graph.edges.push({
|
|
185
|
+
from: docId,
|
|
186
|
+
to: moduleName,
|
|
187
|
+
type: "references",
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
for (const termName of doc.references.terms) {
|
|
192
|
+
if (graph.nodes.terms[termName]) {
|
|
193
|
+
graph.edges.push({
|
|
194
|
+
from: docId,
|
|
195
|
+
to: termName,
|
|
196
|
+
type: "references",
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
for (const folderName of doc.references.folders) {
|
|
201
|
+
if (graph.nodes.folders[folderName]) {
|
|
202
|
+
graph.edges.push({
|
|
203
|
+
from: docId,
|
|
204
|
+
to: folderName,
|
|
205
|
+
type: "references",
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const exportName of doc.references.exports) {
|
|
210
|
+
if (graph.nodes.exports[exportName]) {
|
|
211
|
+
graph.edges.push({
|
|
212
|
+
from: docId,
|
|
213
|
+
to: exportName,
|
|
214
|
+
type: "references",
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Build folder hierarchy based on path nesting.
|
|
222
|
+
*
|
|
223
|
+
* HIERARCHICAL STRUCTURE:
|
|
224
|
+
* Folders with nested paths create parent-child relationships.
|
|
225
|
+
* For example:
|
|
226
|
+
* - "/electron-layers" contains "/electron-layers/main"
|
|
227
|
+
* - "/electron-layers/main" contains "/electron-layers/main/features/auth"
|
|
228
|
+
*
|
|
229
|
+
* This creates a tree structure that can be traversed:
|
|
230
|
+
* "Show me all folders under ElectronLayers"
|
|
231
|
+
* "What's the full path from Root to BoardCommunication?"
|
|
232
|
+
*
|
|
233
|
+
* ALGORITHM:
|
|
234
|
+
* For each pair of folders, if childPath starts with parentPath + '/',
|
|
235
|
+
* create a "contains" edge from parent to child.
|
|
236
|
+
*/
|
|
237
|
+
function buildFolderHierarchy(graph) {
|
|
238
|
+
const folders = Object.values(graph.nodes.folders);
|
|
239
|
+
for (const child of folders) {
|
|
240
|
+
if (!child.path)
|
|
241
|
+
continue;
|
|
242
|
+
// Find the most specific parent (longest matching path)
|
|
243
|
+
let bestParent = null;
|
|
244
|
+
let bestParentPathLength = 0;
|
|
245
|
+
for (const parent of folders) {
|
|
246
|
+
if (!parent.path || parent.id === child.id)
|
|
247
|
+
continue;
|
|
248
|
+
// Use path.relative to check if child is within parent
|
|
249
|
+
const relativePath = path.posix.relative(parent.path, child.path);
|
|
250
|
+
// If relative path doesn't start with '..' and isn't empty, child is within parent
|
|
251
|
+
const isChildOfParent = relativePath && !relativePath.startsWith("..") && relativePath !== ".";
|
|
252
|
+
if (isChildOfParent) {
|
|
253
|
+
// Use the longest matching parent (most specific)
|
|
254
|
+
if (parent.path.length > bestParentPathLength) {
|
|
255
|
+
bestParent = parent;
|
|
256
|
+
bestParentPathLength = parent.path.length;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
// Create edge from parent to child
|
|
261
|
+
if (bestParent) {
|
|
262
|
+
graph.edges.push({
|
|
263
|
+
from: bestParent.id,
|
|
264
|
+
to: child.id,
|
|
265
|
+
type: "contains",
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Build module-to-folder membership based on resolved paths.
|
|
272
|
+
*
|
|
273
|
+
* MODULE OWNERSHIP:
|
|
274
|
+
* If a module's resolvedPath falls within a folder's resolvedPath,
|
|
275
|
+
* that module belongs to that folder.
|
|
276
|
+
*
|
|
277
|
+
* For example:
|
|
278
|
+
* - Module at "electron-layers/main/src/features/auth/AuthService.ts"
|
|
279
|
+
* - Folder at "electron-layers/main/features/auth"
|
|
280
|
+
* - Creates "belongs-to" edge: AuthService -> Auth folder
|
|
281
|
+
*
|
|
282
|
+
* This answers:
|
|
283
|
+
* "What modules are part of the Auth folder?"
|
|
284
|
+
* "Is this module in the right place?"
|
|
285
|
+
*
|
|
286
|
+
* ALGORITHM:
|
|
287
|
+
* For each module with a resolvedPath, find the most specific folder
|
|
288
|
+
* whose resolvedPath is a prefix of the module's path.
|
|
289
|
+
*/
|
|
290
|
+
function buildModuleFolderMembership(graph) {
|
|
291
|
+
const modules = Object.values(graph.nodes.modules);
|
|
292
|
+
const folders = Object.values(graph.nodes.folders);
|
|
293
|
+
for (const module of modules) {
|
|
294
|
+
if (!module.resolvedPath)
|
|
295
|
+
continue;
|
|
296
|
+
// Find the most specific folder (longest matching path)
|
|
297
|
+
let bestFolder = null;
|
|
298
|
+
let bestFolderPathLength = 0;
|
|
299
|
+
for (const folder of folders) {
|
|
300
|
+
if (!folder.resolvedPath)
|
|
301
|
+
continue;
|
|
302
|
+
// Both paths are already relative to baseDir, just check prefix
|
|
303
|
+
// Normalize to forward slashes for consistent comparison
|
|
304
|
+
const folderPath = folder.resolvedPath.replace(/\\/g, "/");
|
|
305
|
+
const modulePath = module.resolvedPath.replace(/\\/g, "/");
|
|
306
|
+
// Check if module path starts with folder path
|
|
307
|
+
const isModuleInFolder = modulePath.startsWith(folderPath + "/") || modulePath.startsWith(folderPath);
|
|
308
|
+
if (isModuleInFolder) {
|
|
309
|
+
// Use the longest matching folder (most specific)
|
|
310
|
+
if (folderPath.length > bestFolderPathLength) {
|
|
311
|
+
bestFolder = folder;
|
|
312
|
+
bestFolderPathLength = folderPath.length;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// Create edge from module to folder
|
|
317
|
+
if (bestFolder) {
|
|
318
|
+
graph.edges.push({
|
|
319
|
+
from: module.id,
|
|
320
|
+
to: bestFolder.id,
|
|
321
|
+
type: "belongs-to",
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Build export membership - connect exports to their parent module or folder.
|
|
328
|
+
*
|
|
329
|
+
* EXPORT OWNERSHIP:
|
|
330
|
+
* Exports can belong to:
|
|
331
|
+
* 1. A Module - if the export's resolvedPath matches a module's resolvedPath
|
|
332
|
+
* 2. A Folder - if the export's path falls within a folder's path (but no matching module)
|
|
333
|
+
*
|
|
334
|
+
* This creates a three-level hierarchy:
|
|
335
|
+
* Folder -> Module -> Export
|
|
336
|
+
* or
|
|
337
|
+
* Folder -> Export (if no module is defined for that file)
|
|
338
|
+
*
|
|
339
|
+
* ALGORITHM:
|
|
340
|
+
* For each export with a resolvedPath:
|
|
341
|
+
* 1. First try to find a matching module (same file)
|
|
342
|
+
* 2. If no module, find the most specific folder containing it
|
|
343
|
+
*/
|
|
344
|
+
function buildExportMembership(graph) {
|
|
345
|
+
const exports = Object.values(graph.nodes.exports);
|
|
346
|
+
const modules = Object.values(graph.nodes.modules);
|
|
347
|
+
const folders = Object.values(graph.nodes.folders);
|
|
348
|
+
for (const exp of exports) {
|
|
349
|
+
if (!exp.resolvedPath)
|
|
350
|
+
continue;
|
|
351
|
+
// Normalize path for comparison
|
|
352
|
+
const exportPath = exp.resolvedPath.replace(/\\/g, "/");
|
|
353
|
+
// First, try to find a matching module (same file)
|
|
354
|
+
let foundModule = false;
|
|
355
|
+
for (const module of modules) {
|
|
356
|
+
if (!module.resolvedPath)
|
|
357
|
+
continue;
|
|
358
|
+
const modulePath = module.resolvedPath.replace(/\\/g, "/");
|
|
359
|
+
// Check if they're from the same file (handle .ts/.tsx/.js variations)
|
|
360
|
+
const exportBase = exportPath.replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
361
|
+
const moduleBase = modulePath.replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
362
|
+
if (exportBase === moduleBase) {
|
|
363
|
+
graph.edges.push({
|
|
364
|
+
from: exp.id,
|
|
365
|
+
to: module.id,
|
|
366
|
+
type: "belongs-to",
|
|
367
|
+
});
|
|
368
|
+
foundModule = true;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// If no module found, try to find the most specific folder
|
|
373
|
+
if (!foundModule) {
|
|
374
|
+
let bestFolder = null;
|
|
375
|
+
let bestFolderPathLength = 0;
|
|
376
|
+
for (const folder of folders) {
|
|
377
|
+
if (!folder.resolvedPath)
|
|
378
|
+
continue;
|
|
379
|
+
const folderPath = folder.resolvedPath.replace(/\\/g, "/");
|
|
380
|
+
// Check if export path starts with folder path
|
|
381
|
+
const isExportInFolder = exportPath.startsWith(folderPath + "/") || exportPath.startsWith(folderPath);
|
|
382
|
+
if (isExportInFolder) {
|
|
383
|
+
// Use the longest matching folder (most specific)
|
|
384
|
+
if (folderPath.length > bestFolderPathLength) {
|
|
385
|
+
bestFolder = folder;
|
|
386
|
+
bestFolderPathLength = folderPath.length;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
// Create edge from export to folder
|
|
391
|
+
if (bestFolder) {
|
|
392
|
+
graph.edges.push({
|
|
393
|
+
from: exp.id,
|
|
394
|
+
to: bestFolder.id,
|
|
395
|
+
type: "belongs-to",
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Update graph statistics
|
|
403
|
+
*/
|
|
404
|
+
function updateStats(graph) {
|
|
405
|
+
graph.metadata.stats.folderCount = Object.keys(graph.nodes.folders).length;
|
|
406
|
+
graph.metadata.stats.moduleCount = Object.keys(graph.nodes.modules).length;
|
|
407
|
+
graph.metadata.stats.termCount = Object.keys(graph.nodes.terms).length;
|
|
408
|
+
graph.metadata.stats.exportCount = Object.keys(graph.nodes.exports).length;
|
|
409
|
+
graph.metadata.stats.docCount = Object.keys(graph.nodes.docs).length;
|
|
410
|
+
graph.metadata.stats.edgeCount = graph.edges.length;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Normalize file path to use as node ID
|
|
414
|
+
* Converts absolute paths to relative from the base directory
|
|
415
|
+
*/
|
|
416
|
+
function normalizeFilePath(filePath, baseDir) {
|
|
417
|
+
// Make path relative to base directory and use forward slashes
|
|
418
|
+
const relativePath = path.relative(baseDir, filePath);
|
|
419
|
+
return relativePath.replace(/\\/g, "/");
|
|
420
|
+
}
|
|
421
|
+
//# sourceMappingURL=builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../../../src/core/graph/builder.ts"],"names":[],"mappings":"AAWA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,UAAU,CACxB,QAA2B,EAC3B,IAAoB,EACpB,OAAe;IAEf,MAAM,KAAK,GAAmB;QAC5B,KAAK,EAAE;YACL,OAAO,EAAE,EAAE;YACX,OAAO,EAAE,EAAE;YACX,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,EAAE;YACX,IAAI,EAAE,EAAE;SAC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IACvE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;IAC3E,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IACrE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;AACtD,CAAC;AAED;;;GAGG;AACH,SAAS,iBAAiB,CAAC,QAAgB,EAAE,OAAe;IAC1D,+DAA+D;IAC/D,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACtD,OAAO,YAAY,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph Module - Builds knowledge graphs from extracted data
|
|
3
|
+
*
|
|
4
|
+
* Public API for creating queryable graph structures.
|
|
5
|
+
*/
|
|
6
|
+
export type { KnowledgeGraph, FolderNode, ModuleNode, TermNode, DocNode, GraphEdge, EdgeType, } from "./types.js";
|
|
7
|
+
export { buildGraph } from "./builder.js";
|
|
8
|
+
/**
|
|
9
|
+
* Build a knowledge graph from extraction results.
|
|
10
|
+
*
|
|
11
|
+
* This is the main entry point for graph building. It:
|
|
12
|
+
* - Creates nodes from folders, modules, terms, and docs
|
|
13
|
+
* - Builds reference edges between nodes
|
|
14
|
+
* - Infers hierarchical relationships from paths
|
|
15
|
+
* - Determines module-to-folder membership
|
|
16
|
+
*
|
|
17
|
+
* @param registry - Extracted vocabulary (folders, modules, terms)
|
|
18
|
+
* @param documentation - Extracted documentation files
|
|
19
|
+
* @param baseDir - Base directory for normalizing file paths
|
|
20
|
+
* @returns Complete knowledge graph with nodes and edges
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildKnowledgeGraph(registry: import("../extraction/index.js").ExtractedRegistry, documentation: import("../extraction/index.js").ExtractedDoc[], baseDir: string): import("./types.js").KnowledgeGraph;
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/graph/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,cAAc,EACd,UAAU,EACV,UAAU,EACV,QAAQ,EACR,OAAO,EACP,SAAS,EACT,QAAQ,GACT,MAAM,YAAY,CAAC;AAIpB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,OAAO,wBAAwB,EAAE,iBAAiB,EAC5D,aAAa,EAAE,OAAO,wBAAwB,EAAE,YAAY,EAAE,EAC9D,OAAO,EAAE,MAAM,GACd,OAAO,YAAY,EAAE,cAAc,CAErC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph Module - Builds knowledge graphs from extracted data
|
|
3
|
+
*
|
|
4
|
+
* Public API for creating queryable graph structures.
|
|
5
|
+
*/
|
|
6
|
+
import { buildGraph } from "./builder.js";
|
|
7
|
+
export { buildGraph } from "./builder.js";
|
|
8
|
+
/**
|
|
9
|
+
* Build a knowledge graph from extraction results.
|
|
10
|
+
*
|
|
11
|
+
* This is the main entry point for graph building. It:
|
|
12
|
+
* - Creates nodes from folders, modules, terms, and docs
|
|
13
|
+
* - Builds reference edges between nodes
|
|
14
|
+
* - Infers hierarchical relationships from paths
|
|
15
|
+
* - Determines module-to-folder membership
|
|
16
|
+
*
|
|
17
|
+
* @param registry - Extracted vocabulary (folders, modules, terms)
|
|
18
|
+
* @param documentation - Extracted documentation files
|
|
19
|
+
* @param baseDir - Base directory for normalizing file paths
|
|
20
|
+
* @returns Complete knowledge graph with nodes and edges
|
|
21
|
+
*/
|
|
22
|
+
export function buildKnowledgeGraph(registry, documentation, baseDir) {
|
|
23
|
+
return buildGraph(registry, documentation, baseDir);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/graph/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAA4D,EAC5D,aAA8D,EAC9D,OAAe;IAEf,OAAO,UAAU,CAAC,QAAQ,EAAE,aAAa,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph structure types for the knowledge base.
|
|
3
|
+
*
|
|
4
|
+
* The graph consists of:
|
|
5
|
+
* - Nodes: Folders, Modules, Terms, and Documentation files
|
|
6
|
+
* - Edges: Relationships between nodes (references, belongs-to, etc.)
|
|
7
|
+
*/
|
|
8
|
+
export interface GraphNode {
|
|
9
|
+
id: string;
|
|
10
|
+
type: "folder" | "module" | "term" | "export" | "doc";
|
|
11
|
+
}
|
|
12
|
+
export interface FolderNode extends GraphNode {
|
|
13
|
+
type: "folder";
|
|
14
|
+
desc: string;
|
|
15
|
+
path?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Resolved path relative to tsconfig directory (portable across machines)
|
|
18
|
+
*/
|
|
19
|
+
resolvedPath?: string;
|
|
20
|
+
/**
|
|
21
|
+
* Whether the resolved path actually exists on disk
|
|
22
|
+
*/
|
|
23
|
+
pathExists?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ModuleNode extends GraphNode {
|
|
26
|
+
type: "module";
|
|
27
|
+
desc: string;
|
|
28
|
+
/**
|
|
29
|
+
* The module's type signature (if available from typeof import)
|
|
30
|
+
*/
|
|
31
|
+
typeSignature?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Import path from typeof import("...")
|
|
34
|
+
*/
|
|
35
|
+
importPath?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Resolved path relative to tsconfig directory (portable across machines)
|
|
38
|
+
*/
|
|
39
|
+
resolvedPath?: string;
|
|
40
|
+
/**
|
|
41
|
+
* Whether the resolved path actually exists on disk
|
|
42
|
+
*/
|
|
43
|
+
pathExists?: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface TermNode extends GraphNode {
|
|
46
|
+
type: "term";
|
|
47
|
+
desc: string;
|
|
48
|
+
}
|
|
49
|
+
export interface ExportNode extends GraphNode {
|
|
50
|
+
type: "export";
|
|
51
|
+
desc: string;
|
|
52
|
+
/**
|
|
53
|
+
* The export's type signature (if available from typeof import)
|
|
54
|
+
*/
|
|
55
|
+
typeSignature?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Import path from typeof import("...")
|
|
58
|
+
*/
|
|
59
|
+
importPath?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Resolved path relative to tsconfig directory (portable across machines)
|
|
62
|
+
*/
|
|
63
|
+
resolvedPath?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Whether the resolved path actually exists on disk
|
|
66
|
+
*/
|
|
67
|
+
pathExists?: boolean;
|
|
68
|
+
}
|
|
69
|
+
export interface DocNode extends GraphNode {
|
|
70
|
+
type: "doc";
|
|
71
|
+
/**
|
|
72
|
+
* File path relative to project root
|
|
73
|
+
*/
|
|
74
|
+
filePath: string;
|
|
75
|
+
/**
|
|
76
|
+
* Full text content of the documentation
|
|
77
|
+
*/
|
|
78
|
+
content: string;
|
|
79
|
+
/**
|
|
80
|
+
* Format of the doc file
|
|
81
|
+
*/
|
|
82
|
+
format: "ts" | "tsx";
|
|
83
|
+
}
|
|
84
|
+
export type AnyNode = FolderNode | ModuleNode | TermNode | ExportNode | DocNode;
|
|
85
|
+
/**
|
|
86
|
+
* Edge types representing relationships in the knowledge graph
|
|
87
|
+
*/
|
|
88
|
+
export type EdgeType = "references" | "belongs-to" | "contains" | "related-to";
|
|
89
|
+
export interface GraphEdge {
|
|
90
|
+
from: string;
|
|
91
|
+
to: string;
|
|
92
|
+
type: EdgeType;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Complete knowledge graph structure
|
|
96
|
+
*/
|
|
97
|
+
export interface KnowledgeGraph {
|
|
98
|
+
/**
|
|
99
|
+
* All nodes in the graph, keyed by ID
|
|
100
|
+
*/
|
|
101
|
+
nodes: {
|
|
102
|
+
folders: Record<string, FolderNode>;
|
|
103
|
+
modules: Record<string, ModuleNode>;
|
|
104
|
+
terms: Record<string, TermNode>;
|
|
105
|
+
exports: Record<string, ExportNode>;
|
|
106
|
+
docs: Record<string, DocNode>;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* All edges (relationships) in the graph
|
|
110
|
+
*/
|
|
111
|
+
edges: GraphEdge[];
|
|
112
|
+
/**
|
|
113
|
+
* Metadata about the graph
|
|
114
|
+
*/
|
|
115
|
+
metadata: {
|
|
116
|
+
generatedAt: string;
|
|
117
|
+
version: string;
|
|
118
|
+
stats: {
|
|
119
|
+
folderCount: number;
|
|
120
|
+
moduleCount: number;
|
|
121
|
+
termCount: number;
|
|
122
|
+
exportCount: number;
|
|
123
|
+
docCount: number;
|
|
124
|
+
edgeCount: number;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/core/graph/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,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,GAAG,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;AAEhF;;GAEG;AACH,MAAM,MAAM,QAAQ,GAChB,YAAY,GACZ,YAAY,GACZ,UAAU,GACV,YAAY,CAAC;AAEjB,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,QAAQ,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,KAAK,EAAE;QACL,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACpC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACpC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;QACpC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KAC/B,CAAC;IACF;;OAEG;IACH,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB;;OAEG;IACH,QAAQ,EAAE;QACR,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE;YACL,WAAW,EAAE,MAAM,CAAC;YACpB,WAAW,EAAE,MAAM,CAAC;YACpB,SAAS,EAAE,MAAM,CAAC;YAClB,WAAW,EAAE,MAAM,CAAC;YACpB,QAAQ,EAAE,MAAM,CAAC;YACjB,SAAS,EAAE,MAAM,CAAC;SACnB,CAAC;KACH,CAAC;CACH"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph structure types for the knowledge base.
|
|
3
|
+
*
|
|
4
|
+
* The graph consists of:
|
|
5
|
+
* - Nodes: Folders, Modules, Terms, and Documentation files
|
|
6
|
+
* - Edges: Relationships between nodes (references, belongs-to, etc.)
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/graph/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { KnowledgeGraph } from "../graph/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generate a Graphviz DOT file from a knowledge graph.
|
|
4
|
+
*
|
|
5
|
+
* This creates a hierarchical visualization showing:
|
|
6
|
+
* - Folders as nested subgraphs (boxes)
|
|
7
|
+
* - Modules within their folders (ellipses)
|
|
8
|
+
* - Terms as separate cluster (diamonds)
|
|
9
|
+
* - Docs as separate cluster (notes)
|
|
10
|
+
* - Reference relationships as directed edges
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateDot(graph: KnowledgeGraph): string;
|
|
13
|
+
//# sourceMappingURL=dot-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dot-generator.d.ts","sourceRoot":"","sources":["../../../src/core/visualization/dot-generator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,mBAAmB,CAAC;AAEpE;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,MAAM,CAuIzD"}
|