@nahisaho/musubix-codegraph 2.3.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/README.md +187 -0
- package/dist/codegraph.d.ts +218 -0
- package/dist/codegraph.d.ts.map +1 -0
- package/dist/codegraph.js +429 -0
- package/dist/codegraph.js.map +1 -0
- package/dist/events/event-emitter.d.ts +93 -0
- package/dist/events/event-emitter.d.ts.map +1 -0
- package/dist/events/event-emitter.js +152 -0
- package/dist/events/event-emitter.js.map +1 -0
- package/dist/events/index.d.ts +8 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +8 -0
- package/dist/events/index.js.map +1 -0
- package/dist/graph/graph-engine.d.ts +97 -0
- package/dist/graph/graph-engine.d.ts.map +1 -0
- package/dist/graph/graph-engine.js +341 -0
- package/dist/graph/graph-engine.js.map +1 -0
- package/dist/graph/index.d.ts +8 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +8 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graphrag/graphrag-search.d.ts +67 -0
- package/dist/graphrag/graphrag-search.d.ts.map +1 -0
- package/dist/graphrag/graphrag-search.js +297 -0
- package/dist/graphrag/graphrag-search.js.map +1 -0
- package/dist/graphrag/index.d.ts +8 -0
- package/dist/graphrag/index.d.ts.map +1 -0
- package/dist/graphrag/index.js +8 -0
- package/dist/graphrag/index.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/index.d.ts +8 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +8 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/indexer/indexer.d.ts +58 -0
- package/dist/indexer/indexer.d.ts.map +1 -0
- package/dist/indexer/indexer.js +206 -0
- package/dist/indexer/indexer.js.map +1 -0
- package/dist/parser/ast-parser.d.ts +79 -0
- package/dist/parser/ast-parser.d.ts.map +1 -0
- package/dist/parser/ast-parser.js +489 -0
- package/dist/parser/ast-parser.js.map +1 -0
- package/dist/parser/index.d.ts +8 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +8 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/storage/index.d.ts +9 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +10 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/memory-storage.d.ts +102 -0
- package/dist/storage/memory-storage.d.ts.map +1 -0
- package/dist/storage/memory-storage.js +263 -0
- package/dist/storage/memory-storage.js.map +1 -0
- package/dist/storage/sqlite-storage.d.ts +90 -0
- package/dist/storage/sqlite-storage.d.ts.map +1 -0
- package/dist/storage/sqlite-storage.js +344 -0
- package/dist/storage/sqlite-storage.js.map +1 -0
- package/dist/types.d.ts +539 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +99 -0
- package/dist/types.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-emitter.js","sourceRoot":"","sources":["../../src/events/event-emitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC;;;;;;;;;;;;;GAaG;AACH,MAAM,OAAO,iBAAiB;IACpB,OAAO,CAAe;IAE9B;QACE,IAAI,CAAC,OAAO,GAAG,IAAI,YAAY,EAAE,CAAC;QAClC,kDAAkD;QAClD,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,EAAE,CAA0B,KAAQ,EAAE,QAAoC;QACxE,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,KAAe,EAAE,QAAwC,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,IAAI,CAA0B,KAAQ,EAAE,QAAoC;QAC1E,IAAI,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E,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACtD,CAAC;CACF;AAED,kCAAkC;AAClC,MAAM,UAAU,kBAAkB;IAChC,OAAO,IAAI,qBAAqB,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nahisaho/musubix-codegraph - Events Module
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module @nahisaho/musubix-codegraph/events
|
|
6
|
+
*/
|
|
7
|
+
export { TypedEventEmitter, CodeGraphEventEmitter, createEventEmitter, } from './event-emitter.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nahisaho/musubix-codegraph - Events Module
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module @nahisaho/musubix-codegraph/events
|
|
6
|
+
*/
|
|
7
|
+
export { TypedEventEmitter, CodeGraphEventEmitter, createEventEmitter, } from './event-emitter.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/events/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nahisaho/musubix-codegraph - Graph Engine
|
|
3
|
+
*
|
|
4
|
+
* Core graph engine for code entity relationship management
|
|
5
|
+
*
|
|
6
|
+
* @see REQ-CG-GRF-001 - Graph construction
|
|
7
|
+
* @see REQ-CG-GRF-002 - Relation inference
|
|
8
|
+
* @see REQ-CG-GRF-003 - Query operations
|
|
9
|
+
* @see DES-CG-003
|
|
10
|
+
* @see TSK-CG-020
|
|
11
|
+
*/
|
|
12
|
+
import type { Entity, Relation, StorageAdapter, GraphOptions, GraphQuery, QueryResult, CallPath, ModuleAnalysis } from '../types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Graph Engine for code entities
|
|
15
|
+
*
|
|
16
|
+
* Manages the code graph, performs queries, and provides
|
|
17
|
+
* traversal algorithms for dependency and call analysis.
|
|
18
|
+
*/
|
|
19
|
+
export declare class GraphEngine {
|
|
20
|
+
private storage;
|
|
21
|
+
private _options;
|
|
22
|
+
private enableInferRelations;
|
|
23
|
+
constructor(storage: StorageAdapter, options?: Partial<GraphOptions>);
|
|
24
|
+
/**
|
|
25
|
+
* Get max traversal depth
|
|
26
|
+
*/
|
|
27
|
+
getMaxDepth(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Add entity to graph
|
|
30
|
+
*/
|
|
31
|
+
addEntity(entity: Entity): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Add multiple entities
|
|
34
|
+
*/
|
|
35
|
+
addEntities(entities: Entity[]): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Get entity by ID
|
|
38
|
+
*/
|
|
39
|
+
getEntity(id: string): Promise<Entity | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Find entity by name
|
|
42
|
+
*/
|
|
43
|
+
findByName(name: string): Promise<Entity | null>;
|
|
44
|
+
/**
|
|
45
|
+
* Add relation to graph
|
|
46
|
+
*/
|
|
47
|
+
addRelation(relation: Relation): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Add multiple relations
|
|
50
|
+
*/
|
|
51
|
+
addRelations(relations: Relation[]): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Infer relations from entities
|
|
54
|
+
*/
|
|
55
|
+
inferRelations(entities: Entity[]): Promise<Relation[]>;
|
|
56
|
+
/**
|
|
57
|
+
* Extract function calls from source code
|
|
58
|
+
*/
|
|
59
|
+
private extractCallsFromSource;
|
|
60
|
+
/**
|
|
61
|
+
* Query the graph
|
|
62
|
+
*/
|
|
63
|
+
query(query: GraphQuery): Promise<QueryResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Find dependencies of an entity
|
|
66
|
+
*/
|
|
67
|
+
findDependencies(entityName: string, depth?: number): Promise<Entity[]>;
|
|
68
|
+
/**
|
|
69
|
+
* Traverse dependencies recursively
|
|
70
|
+
*/
|
|
71
|
+
private traverseDependencies;
|
|
72
|
+
/**
|
|
73
|
+
* Find callers of an entity
|
|
74
|
+
*/
|
|
75
|
+
findCallers(entityName: string): Promise<CallPath[]>;
|
|
76
|
+
/**
|
|
77
|
+
* Find callees of an entity
|
|
78
|
+
*/
|
|
79
|
+
findCallees(entityName: string): Promise<CallPath[]>;
|
|
80
|
+
/**
|
|
81
|
+
* Find implementations of an interface
|
|
82
|
+
*/
|
|
83
|
+
findImplementations(interfaceName: string): Promise<Entity[]>;
|
|
84
|
+
/**
|
|
85
|
+
* Analyze module structure
|
|
86
|
+
*/
|
|
87
|
+
analyzeModule(filePath: string): Promise<ModuleAnalysis>;
|
|
88
|
+
/**
|
|
89
|
+
* Add entities and relations from parse results
|
|
90
|
+
*/
|
|
91
|
+
addParseResults(entities: Entity[], relations: Relation[]): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Clear the graph
|
|
94
|
+
*/
|
|
95
|
+
clear(): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=graph-engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-engine.d.ts","sourceRoot":"","sources":["../../src/graph/graph-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,MAAM,EACN,QAAQ,EACR,cA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AAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IA0B1D;;OAEG;IACG,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IA0B1D;;OAEG;IACG,mBAAmB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAqBnE;;OAEG;IACG,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAgD9D;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAW/E;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B"}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nahisaho/musubix-codegraph - Graph Engine
|
|
3
|
+
*
|
|
4
|
+
* Core graph engine for code entity relationship management
|
|
5
|
+
*
|
|
6
|
+
* @see REQ-CG-GRF-001 - Graph construction
|
|
7
|
+
* @see REQ-CG-GRF-002 - Relation inference
|
|
8
|
+
* @see REQ-CG-GRF-003 - Query operations
|
|
9
|
+
* @see DES-CG-003
|
|
10
|
+
* @see TSK-CG-020
|
|
11
|
+
*/
|
|
12
|
+
import { generateRelationId } from '../types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Graph Engine for code entities
|
|
15
|
+
*
|
|
16
|
+
* Manages the code graph, performs queries, and provides
|
|
17
|
+
* traversal algorithms for dependency and call analysis.
|
|
18
|
+
*/
|
|
19
|
+
export class GraphEngine {
|
|
20
|
+
storage;
|
|
21
|
+
_options;
|
|
22
|
+
enableInferRelations;
|
|
23
|
+
constructor(storage, options = {}) {
|
|
24
|
+
this.storage = storage;
|
|
25
|
+
this._options = {
|
|
26
|
+
maxDepth: options.maxDepth ?? 10,
|
|
27
|
+
enableCaching: options.enableCaching ?? true,
|
|
28
|
+
};
|
|
29
|
+
this.enableInferRelations = true;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get max traversal depth
|
|
33
|
+
*/
|
|
34
|
+
getMaxDepth() {
|
|
35
|
+
return this._options.maxDepth;
|
|
36
|
+
}
|
|
37
|
+
// =========================================================================
|
|
38
|
+
// Entity Operations
|
|
39
|
+
// =========================================================================
|
|
40
|
+
/**
|
|
41
|
+
* Add entity to graph
|
|
42
|
+
*/
|
|
43
|
+
async addEntity(entity) {
|
|
44
|
+
await this.storage.saveEntity(entity);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Add multiple entities
|
|
48
|
+
*/
|
|
49
|
+
async addEntities(entities) {
|
|
50
|
+
for (const entity of entities) {
|
|
51
|
+
await this.storage.saveEntity(entity);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get entity by ID
|
|
56
|
+
*/
|
|
57
|
+
async getEntity(id) {
|
|
58
|
+
return this.storage.getEntity(id);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Find entity by name
|
|
62
|
+
*/
|
|
63
|
+
async findByName(name) {
|
|
64
|
+
const results = await this.storage.queryEntities({ textSearch: name, limit: 1 });
|
|
65
|
+
return results.find(e => e.name === name) ?? null;
|
|
66
|
+
}
|
|
67
|
+
// =========================================================================
|
|
68
|
+
// Relation Operations
|
|
69
|
+
// =========================================================================
|
|
70
|
+
/**
|
|
71
|
+
* Add relation to graph
|
|
72
|
+
*/
|
|
73
|
+
async addRelation(relation) {
|
|
74
|
+
await this.storage.saveRelation(relation);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Add multiple relations
|
|
78
|
+
*/
|
|
79
|
+
async addRelations(relations) {
|
|
80
|
+
for (const relation of relations) {
|
|
81
|
+
await this.storage.saveRelation(relation);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Infer relations from entities
|
|
86
|
+
*/
|
|
87
|
+
async inferRelations(entities) {
|
|
88
|
+
if (!this.enableInferRelations) {
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
const inferred = [];
|
|
92
|
+
const entityMap = new Map(entities.map(e => [e.name, e]));
|
|
93
|
+
for (const entity of entities) {
|
|
94
|
+
// Infer contains relations (file -> entities)
|
|
95
|
+
if (entity.filePath && entity.type !== 'file') {
|
|
96
|
+
const fileEntity = entities.find(e => e.type === 'file' && e.filePath === entity.filePath);
|
|
97
|
+
if (fileEntity) {
|
|
98
|
+
inferred.push({
|
|
99
|
+
id: generateRelationId(fileEntity.id, entity.id, 'contains'),
|
|
100
|
+
sourceId: fileEntity.id,
|
|
101
|
+
targetId: entity.id,
|
|
102
|
+
type: 'contains',
|
|
103
|
+
weight: 1.0,
|
|
104
|
+
metadata: {},
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
// Infer calls relations from source code analysis
|
|
109
|
+
if (entity.sourceCode && (entity.type === 'function' || entity.type === 'method')) {
|
|
110
|
+
const calls = this.extractCallsFromSource(entity.sourceCode, entityMap);
|
|
111
|
+
for (const callee of calls) {
|
|
112
|
+
inferred.push({
|
|
113
|
+
id: generateRelationId(entity.id, callee.id, 'calls'),
|
|
114
|
+
sourceId: entity.id,
|
|
115
|
+
targetId: callee.id,
|
|
116
|
+
type: 'calls',
|
|
117
|
+
weight: 1.0,
|
|
118
|
+
metadata: {},
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return inferred;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Extract function calls from source code
|
|
127
|
+
*/
|
|
128
|
+
extractCallsFromSource(sourceCode, entityMap) {
|
|
129
|
+
const calls = [];
|
|
130
|
+
// Simple regex to find function calls
|
|
131
|
+
const callRegex = /\b(\w+)\s*\(/g;
|
|
132
|
+
let match;
|
|
133
|
+
while ((match = callRegex.exec(sourceCode)) !== null) {
|
|
134
|
+
const name = match[1];
|
|
135
|
+
// Skip common keywords
|
|
136
|
+
if (['if', 'while', 'for', 'switch', 'catch', 'function', 'class'].includes(name)) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
const entity = entityMap.get(name);
|
|
140
|
+
if (entity && (entity.type === 'function' || entity.type === 'method')) {
|
|
141
|
+
if (!calls.includes(entity)) {
|
|
142
|
+
calls.push(entity);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return calls;
|
|
147
|
+
}
|
|
148
|
+
// =========================================================================
|
|
149
|
+
// Query Operations
|
|
150
|
+
// =========================================================================
|
|
151
|
+
/**
|
|
152
|
+
* Query the graph
|
|
153
|
+
*/
|
|
154
|
+
async query(query) {
|
|
155
|
+
const startTime = Date.now();
|
|
156
|
+
const entities = await this.storage.queryEntities(query);
|
|
157
|
+
// Get related relations
|
|
158
|
+
const relationSet = new Set();
|
|
159
|
+
const relations = [];
|
|
160
|
+
for (const entity of entities) {
|
|
161
|
+
const entityRelations = await this.storage.getRelations(entity.id);
|
|
162
|
+
for (const rel of entityRelations) {
|
|
163
|
+
if (!relationSet.has(rel.id)) {
|
|
164
|
+
relationSet.add(rel.id);
|
|
165
|
+
relations.push(rel);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return {
|
|
170
|
+
entities,
|
|
171
|
+
relations,
|
|
172
|
+
totalCount: entities.length,
|
|
173
|
+
hasMore: false,
|
|
174
|
+
queryTimeMs: Date.now() - startTime,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Find dependencies of an entity
|
|
179
|
+
*/
|
|
180
|
+
async findDependencies(entityName, depth = 3) {
|
|
181
|
+
const entity = await this.findByName(entityName);
|
|
182
|
+
if (!entity)
|
|
183
|
+
return [];
|
|
184
|
+
const visited = new Set();
|
|
185
|
+
const dependencies = [];
|
|
186
|
+
await this.traverseDependencies(entity.id, depth, visited, dependencies);
|
|
187
|
+
return dependencies;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Traverse dependencies recursively
|
|
191
|
+
*/
|
|
192
|
+
async traverseDependencies(entityId, depth, visited, results) {
|
|
193
|
+
if (depth <= 0 || visited.has(entityId))
|
|
194
|
+
return;
|
|
195
|
+
visited.add(entityId);
|
|
196
|
+
// Get outgoing relations (things this entity depends on)
|
|
197
|
+
const relations = await this.storage.getRelations(entityId, 'out');
|
|
198
|
+
for (const relation of relations) {
|
|
199
|
+
// Only follow dependency-like relations
|
|
200
|
+
if (['imports', 'uses', 'calls', 'extends', 'implements'].includes(relation.type)) {
|
|
201
|
+
const target = await this.storage.getEntity(relation.targetId);
|
|
202
|
+
if (target && !visited.has(target.id)) {
|
|
203
|
+
results.push(target);
|
|
204
|
+
await this.traverseDependencies(target.id, depth - 1, visited, results);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Find callers of an entity
|
|
211
|
+
*/
|
|
212
|
+
async findCallers(entityName) {
|
|
213
|
+
const entity = await this.findByName(entityName);
|
|
214
|
+
if (!entity)
|
|
215
|
+
return [];
|
|
216
|
+
const callers = [];
|
|
217
|
+
// Get incoming 'calls' relations
|
|
218
|
+
const relations = await this.storage.getRelations(entity.id, 'in');
|
|
219
|
+
for (const relation of relations) {
|
|
220
|
+
if (relation.type === 'calls') {
|
|
221
|
+
const caller = await this.storage.getEntity(relation.sourceId);
|
|
222
|
+
if (caller) {
|
|
223
|
+
callers.push({
|
|
224
|
+
from: caller,
|
|
225
|
+
to: entity,
|
|
226
|
+
path: [caller, entity],
|
|
227
|
+
callSites: relation.metadata?.callSites ?? [],
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return callers;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Find callees of an entity
|
|
236
|
+
*/
|
|
237
|
+
async findCallees(entityName) {
|
|
238
|
+
const entity = await this.findByName(entityName);
|
|
239
|
+
if (!entity)
|
|
240
|
+
return [];
|
|
241
|
+
const callees = [];
|
|
242
|
+
// Get outgoing 'calls' relations
|
|
243
|
+
const relations = await this.storage.getRelations(entity.id, 'out');
|
|
244
|
+
for (const relation of relations) {
|
|
245
|
+
if (relation.type === 'calls') {
|
|
246
|
+
const callee = await this.storage.getEntity(relation.targetId);
|
|
247
|
+
if (callee) {
|
|
248
|
+
callees.push({
|
|
249
|
+
from: entity,
|
|
250
|
+
to: callee,
|
|
251
|
+
path: [entity, callee],
|
|
252
|
+
callSites: relation.metadata?.callSites ?? [],
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return callees;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Find implementations of an interface
|
|
261
|
+
*/
|
|
262
|
+
async findImplementations(interfaceName) {
|
|
263
|
+
const entity = await this.findByName(interfaceName);
|
|
264
|
+
if (!entity)
|
|
265
|
+
return [];
|
|
266
|
+
const implementations = [];
|
|
267
|
+
// Get incoming 'implements' relations
|
|
268
|
+
const relations = await this.storage.getRelations(entity.id, 'in');
|
|
269
|
+
for (const relation of relations) {
|
|
270
|
+
if (relation.type === 'implements') {
|
|
271
|
+
const impl = await this.storage.getEntity(relation.sourceId);
|
|
272
|
+
if (impl) {
|
|
273
|
+
implementations.push(impl);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return implementations;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Analyze module structure
|
|
281
|
+
*/
|
|
282
|
+
async analyzeModule(filePath) {
|
|
283
|
+
const entities = await this.storage.queryEntities({ filePath });
|
|
284
|
+
const fileEntity = entities.find(e => e.type === 'file');
|
|
285
|
+
const imports = entities.filter(e => e.type === 'import');
|
|
286
|
+
const exports = entities.filter(e => e.type === 'export');
|
|
287
|
+
// Get dependencies and dependents from relations
|
|
288
|
+
const dependencies = new Set();
|
|
289
|
+
const dependents = new Set();
|
|
290
|
+
for (const entity of entities) {
|
|
291
|
+
const outRels = await this.storage.getRelations(entity.id, 'out');
|
|
292
|
+
for (const rel of outRels) {
|
|
293
|
+
if (['imports', 'uses'].includes(rel.type)) {
|
|
294
|
+
const target = await this.storage.getEntity(rel.targetId);
|
|
295
|
+
if (target?.filePath && target.filePath !== filePath) {
|
|
296
|
+
dependencies.add(target.filePath);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const inRels = await this.storage.getRelations(entity.id, 'in');
|
|
301
|
+
for (const rel of inRels) {
|
|
302
|
+
if (['imports', 'uses'].includes(rel.type)) {
|
|
303
|
+
const source = await this.storage.getEntity(rel.sourceId);
|
|
304
|
+
if (source?.filePath && source.filePath !== filePath) {
|
|
305
|
+
dependents.add(source.filePath);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return {
|
|
311
|
+
filePath,
|
|
312
|
+
moduleName: fileEntity?.name ?? filePath.split('/').pop() ?? 'unknown',
|
|
313
|
+
entities,
|
|
314
|
+
imports,
|
|
315
|
+
exports,
|
|
316
|
+
dependencies: Array.from(dependencies),
|
|
317
|
+
dependents: Array.from(dependents),
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
// =========================================================================
|
|
321
|
+
// Bulk Operations
|
|
322
|
+
// =========================================================================
|
|
323
|
+
/**
|
|
324
|
+
* Add entities and relations from parse results
|
|
325
|
+
*/
|
|
326
|
+
async addParseResults(entities, relations) {
|
|
327
|
+
// Add entities first
|
|
328
|
+
await this.addEntities(entities);
|
|
329
|
+
// Infer additional relations
|
|
330
|
+
const inferred = await this.inferRelations(entities);
|
|
331
|
+
// Add all relations
|
|
332
|
+
await this.addRelations([...relations, ...inferred]);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Clear the graph
|
|
336
|
+
*/
|
|
337
|
+
async clear() {
|
|
338
|
+
await this.storage.clear();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
//# sourceMappingURL=graph-engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-engine.js","sourceRoot":"","sources":["../../src/graph/graph-engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAaH,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACd,OAAO,CAAiB;IACxB,QAAQ,CAAyB;IACjC,oBAAoB,CAAU;IAEtC,YAAY,OAAuB,EAAE,UAAiC,EAAE;QACtE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG;YACd,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE;YAChC,aAAa,EAAE,OAAO,CAAC,aAAa,IAAI,IAAI;SAC7C,CAAC;QACF,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED,4EAA4E;IAC5E,oBAAoB;IACpB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,MAAc;QAC5B,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,QAAkB;QAClC,KAAK,MAAM,MAAM,IAAI,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS,CAAC,EAAU;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,UAAU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C,CAAC;IACJ,CAAC;IAED,4EAA4E;IAC5E,kBAAkB;IAClB,4EAA4E;IAE5E;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,QAAkB,EAAE,SAAqB;QAC7D,qBAAqB;QACrB,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAEjC,6BAA6B;QAC7B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAErD,oBAAoB;QACpB,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC,GAAG,SAAS,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/graph/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/graph/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @nahisaho/musubix-codegraph - GraphRAG Search
|
|
3
|
+
*
|
|
4
|
+
* Graph-based retrieval augmented generation search
|
|
5
|
+
*
|
|
6
|
+
* @see REQ-CG-RAG-001 - Community detection
|
|
7
|
+
* @see REQ-CG-RAG-002 - Global search
|
|
8
|
+
* @see REQ-CG-RAG-003 - Local search
|
|
9
|
+
* @see DES-CG-005
|
|
10
|
+
* @see TSK-CG-040
|
|
11
|
+
*/
|
|
12
|
+
import type { SearchResult, Community, GraphRAGOptions, GlobalSearchOptions, LocalSearchOptions } from '../types.js';
|
|
13
|
+
import type { GraphEngine } from '../graph/index.js';
|
|
14
|
+
/**
|
|
15
|
+
* GraphRAG Search Engine
|
|
16
|
+
*
|
|
17
|
+
* Implements Microsoft's GraphRAG approach for code understanding:
|
|
18
|
+
* - Community detection via Leiden algorithm
|
|
19
|
+
* - Hierarchical summaries for global queries
|
|
20
|
+
* - Local context retrieval for specific queries
|
|
21
|
+
*/
|
|
22
|
+
export declare class GraphRAGSearch {
|
|
23
|
+
private graph;
|
|
24
|
+
private _options;
|
|
25
|
+
private communities;
|
|
26
|
+
private entityCommunityMap;
|
|
27
|
+
constructor(graph: GraphEngine, options?: Partial<GraphRAGOptions>);
|
|
28
|
+
/**
|
|
29
|
+
* Get current options
|
|
30
|
+
*/
|
|
31
|
+
getOptions(): Required<GraphRAGOptions>;
|
|
32
|
+
/**
|
|
33
|
+
* Detect communities in the code graph
|
|
34
|
+
*
|
|
35
|
+
* Uses a simplified Leiden-inspired algorithm for code communities
|
|
36
|
+
*/
|
|
37
|
+
detectCommunities(): Promise<Community[]>;
|
|
38
|
+
/**
|
|
39
|
+
* Generate community summary
|
|
40
|
+
*/
|
|
41
|
+
generateCommunitySummary(communityId: string): Promise<string>;
|
|
42
|
+
/**
|
|
43
|
+
* Global search across all communities
|
|
44
|
+
*
|
|
45
|
+
* Searches community summaries for high-level understanding
|
|
46
|
+
*/
|
|
47
|
+
globalSearch(query: string, options?: GlobalSearchOptions): Promise<SearchResult[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Local search in entity neighborhood
|
|
50
|
+
*
|
|
51
|
+
* Searches within a specific entity's local context
|
|
52
|
+
*/
|
|
53
|
+
localSearch(entityName: string, options?: LocalSearchOptions): Promise<SearchResult[]>;
|
|
54
|
+
/**
|
|
55
|
+
* Collect neighbors within radius
|
|
56
|
+
*/
|
|
57
|
+
private collectNeighbors;
|
|
58
|
+
/**
|
|
59
|
+
* Get all communities
|
|
60
|
+
*/
|
|
61
|
+
getCommunities(): Community[];
|
|
62
|
+
/**
|
|
63
|
+
* Get community for entity
|
|
64
|
+
*/
|
|
65
|
+
getCommunityForEntity(entityId: string): Community | undefined;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=graphrag-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphrag-search.d.ts","sourceRoot":"","sources":["../../src/graphrag/graphrag-search.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAEV,YAAY,EACZ,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;GAOG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,QAAQ,CAA4B;IAC5C,OAAO,CAAC,WAAW,CAAmB;IACtC,OAAO,CAAC,kBAAkB,CAA6B;gBAE3C,KAAK,EAAE,WAAW,EAAE,OAAO,GAAE,OAAO,CAAC,eAAe,CAAM;IAQtE;;OAEG;IACH,UAAU,IAAI,QAAQ,CAAC,eAAe,CAAC;IAQvC;;;;OAIG;IACG,iBAAiB,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAiF/C;;OAEG;IACG,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAgCpE;;;;OAIG;IACG,YAAY,CAChB,KAAK,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,YAAY,EAAE,CAAC;IAuD1B;;;;OAIG;IACG,WAAW,CACf,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE,kBAAkB,GAC3B,OAAO,CAAC,YAAY,EAAE,CAAC;IAyE1B;;OAEG;YACW,gBAAgB;IAyB9B;;OAEG;IACH,cAAc,IAAI,SAAS,EAAE;IAI7B;;OAEG;IACH,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;CAK/D"}
|