deeplyzer 0.10.0 → 0.11.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 +1 -19
- package/engine.js +15 -37
- package/index.js +27 -36
- package/package.json +1 -1
- package/prompts/graph.build_nodes +32 -48
- package/services/graphService.js +91 -100
- package/services/workflowService.js +103 -36
- package/utils/fileUtil.js +1 -1
- package/utils/hashUtil.js +34 -0
- package/session/sessionManager.js +0 -130
package/README.md
CHANGED
|
@@ -93,20 +93,6 @@ deeplyzer <configfile>
|
|
|
93
93
|
|
|
94
94
|
This creates graphs and workflows, then runs static and deep analysis.
|
|
95
95
|
|
|
96
|
-
- **Clear the session**
|
|
97
|
-
|
|
98
|
-
```bash
|
|
99
|
-
deeplyzer clear-session
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
- **Reset the analysis session**
|
|
103
|
-
|
|
104
|
-
```bash
|
|
105
|
-
deeplyzer reset-analysis-session
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
This resets the session and performs only static and deep analysis.
|
|
109
|
-
|
|
110
96
|
## Configuration
|
|
111
97
|
|
|
112
98
|
Create a configuration file (e.g. `deeplyzer.json`) in your project root.
|
|
@@ -121,9 +107,7 @@ Create a configuration file (e.g. `deeplyzer.json`) in your project root.
|
|
|
121
107
|
"apiKey": "<API key goes here>"
|
|
122
108
|
},
|
|
123
109
|
"log_path": "C:\\<local path>\\.logs",
|
|
124
|
-
"build_graph": false,
|
|
125
110
|
"deep_analysis": true,
|
|
126
|
-
"static_analysis": false,
|
|
127
111
|
"batch_size": 10
|
|
128
112
|
}
|
|
129
113
|
```
|
|
@@ -150,13 +134,11 @@ Create a configuration file (e.g. `deeplyzer.json`) in your project root.
|
|
|
150
134
|
| `llm.provider` | Yes | - | LLM provider (`openai`, `claude`, `gemini`). |
|
|
151
135
|
| `llm.model` | Yes | - | Model to use for analysis. |
|
|
152
136
|
| `llm.apiKey` | Yes | - | API key for the selected LLM provider. |
|
|
153
|
-
| `build_graph` | No | `true` | Build semantic code graphs. |
|
|
154
137
|
| `deep_analysis` | No | true | Enable deep LLM-based analysis. |
|
|
155
|
-
| `static_analysis` | No | `true` | Enable static code analysis. |
|
|
156
138
|
| `batch_size` | No | `10` | Number of sources processed in each batch. |
|
|
157
139
|
| `log_path` | No | - | Windows or platform-specific directory where logs are written (example: `C:\\deeplyzer\\.logs`). |
|
|
158
140
|
|
|
159
|
-
**Note:** `
|
|
141
|
+
**Note:** `batch_size` is optional. If omitted, its default value is used.
|
|
160
142
|
|
|
161
143
|
## Links
|
|
162
144
|
|
package/engine.js
CHANGED
|
@@ -6,7 +6,6 @@ const OrchestratorAgent = require('./analysis/deep/orchestratorAgent');
|
|
|
6
6
|
|
|
7
7
|
const Logger = require('./utils/logger');
|
|
8
8
|
const globals = require("./globals");
|
|
9
|
-
const SessionManager = require("./session/sessionManager");
|
|
10
9
|
|
|
11
10
|
class Engine {
|
|
12
11
|
constructor() {
|
|
@@ -21,61 +20,40 @@ class Engine {
|
|
|
21
20
|
async run() {
|
|
22
21
|
try {
|
|
23
22
|
Logger.essential("[ENGINE] Starting Deeplyzer...");
|
|
24
|
-
SessionManager.updateState("in_progress");
|
|
25
23
|
|
|
26
24
|
// step 1: build graph
|
|
27
|
-
|
|
28
|
-
globals.graphs = await this.graphService.buildGraphs();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if(!globals.graphs || globals.graphs.length == 0) {
|
|
32
|
-
globals.graphs = await this.graphService.loadGraphs();
|
|
33
|
-
}
|
|
25
|
+
await this.graphService.buildGraphs();
|
|
34
26
|
|
|
35
|
-
// step 2: build workflows
|
|
36
|
-
if(
|
|
27
|
+
// step 2: build / load workflows
|
|
28
|
+
if(this.graphService.hasUpdates()) {
|
|
37
29
|
globals.workflows = this.workflowService.build();
|
|
38
|
-
|
|
39
|
-
SessionManager.updateStage("build_workflows");
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if(!globals.workflows) {
|
|
30
|
+
} else {
|
|
43
31
|
globals.workflows = this.workflowService.loadWorkflows();
|
|
44
32
|
}
|
|
45
33
|
|
|
46
34
|
this.workflowService.fillSources();
|
|
47
35
|
|
|
48
36
|
// step 3: identify runners
|
|
49
|
-
if(
|
|
37
|
+
if(this.graphService.hasUpdates()) {
|
|
50
38
|
globals.runners = await this.runnerIdentificationService.identify();
|
|
51
|
-
|
|
52
|
-
SessionManager.updateStage("identify_runners");
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
if(!globals.runners) {
|
|
39
|
+
} else {
|
|
56
40
|
globals.runners = this.runnerIdentificationService.loadRunners();
|
|
57
41
|
}
|
|
58
42
|
|
|
43
|
+
const staticAnalysisEnabled = globals.config.static_analysis ?? true;
|
|
44
|
+
const deepAnalysisEnabled = globals.config.deep_analysis ?? true;
|
|
45
|
+
|
|
59
46
|
// step 4: perform static code analysis
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
SessionManager.updateStage("static_analysis");
|
|
65
|
-
}
|
|
66
|
-
}*/
|
|
47
|
+
if (staticAnalysisEnabled || deepAnalysisEnabled) {
|
|
48
|
+
// await this.staticAnalyzer.analyze(graphs, workflows);
|
|
49
|
+
}
|
|
67
50
|
|
|
68
51
|
// step 4: perform deep code analysis
|
|
69
|
-
if (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
await this.orchestratorAgent.start(globals.workflows);
|
|
73
|
-
|
|
74
|
-
SessionManager.updateStage("deep_analysis");
|
|
75
|
-
}
|
|
52
|
+
if (deepAnalysisEnabled) {
|
|
53
|
+
Logger.essential("[ENGINE] Starting deep analysis...");
|
|
54
|
+
await this.orchestratorAgent.start(globals.workflows);
|
|
76
55
|
}
|
|
77
56
|
|
|
78
|
-
SessionManager.updateState("completed");
|
|
79
57
|
Logger.essential("[ENGINE] Execution completed.");
|
|
80
58
|
} catch (error) {
|
|
81
59
|
Logger.error("[ENGINE ERROR]", error);
|
package/index.js
CHANGED
|
@@ -1,55 +1,46 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
const Engine = require("./engine");
|
|
4
|
-
const SessionManager = require("./session/sessionManager");
|
|
5
4
|
const Logger = require('./utils/logger');
|
|
5
|
+
const FileUtil = require('./utils/fileUtil');
|
|
6
6
|
const globals = require("./globals");
|
|
7
7
|
const fs = require("fs");
|
|
8
8
|
const path = require("path");
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
console.log("[INFO] Session cleared successfully.");
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (argument === "reset-analysis-session") {
|
|
22
|
-
SessionManager.resetAnalysisSession();
|
|
23
|
-
console.log("[INFO] Session reset successfully.");
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// Normal execution
|
|
28
|
-
SessionManager.loadSession();
|
|
10
|
+
async function run(configPath) {
|
|
11
|
+
// Handle commands
|
|
12
|
+
if (configPath === "clear-graphs") {
|
|
13
|
+
const fileUtil = new FileUtil();
|
|
14
|
+
fileUtil.removeFiles("graph");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
29
17
|
|
|
30
|
-
|
|
18
|
+
globals.config = _loadConfig(configPath);
|
|
31
19
|
|
|
32
|
-
|
|
20
|
+
Logger.init();
|
|
33
21
|
|
|
34
|
-
|
|
22
|
+
const engine = new Engine();
|
|
23
|
+
await engine.run();
|
|
24
|
+
}
|
|
35
25
|
|
|
36
|
-
|
|
26
|
+
// Export for require()
|
|
27
|
+
module.exports = run;
|
|
37
28
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
// Console execution
|
|
30
|
+
if (require.main === module) {
|
|
31
|
+
(async () => {
|
|
32
|
+
try {
|
|
33
|
+
await run(process.argv[2]);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error(`[ERROR] ${error.message}`);
|
|
36
|
+
process.exitCode = 1;
|
|
37
|
+
}
|
|
38
|
+
})();
|
|
39
|
+
}
|
|
43
40
|
|
|
44
41
|
function _loadConfig(configPath) {
|
|
45
|
-
|
|
46
42
|
if (!configPath) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
"Configuration file path or command is required.\n" +
|
|
49
|
-
"Usage:\n" +
|
|
50
|
-
" node index.js <config.json>\n" +
|
|
51
|
-
" node index.js clear-session"
|
|
52
|
-
);
|
|
43
|
+
throw new Error("Configuration file path or command is required.");
|
|
53
44
|
}
|
|
54
45
|
|
|
55
46
|
const resolvedPath = path.resolve(configPath);
|
package/package.json
CHANGED
|
@@ -51,7 +51,7 @@ The purpose must be a string, not an object or array.
|
|
|
51
51
|
|
|
52
52
|
Return valid JSON only.
|
|
53
53
|
|
|
54
|
-
The output must have exactly
|
|
54
|
+
The output must have exactly three top-level properties:
|
|
55
55
|
|
|
56
56
|
{
|
|
57
57
|
"purpose": "A concise description of the primary purpose of the supplied input",
|
|
@@ -83,7 +83,7 @@ Rules:
|
|
|
83
83
|
4. Ensure every node ID is unique across the complete input.
|
|
84
84
|
5. Use the exact same prefixed IDs when referencing nodes in edges.
|
|
85
85
|
6. Never generate an unprefixed node ID.
|
|
86
|
-
7. Do not add the prefix to external_dependants
|
|
86
|
+
7. Do not add the prefix to external_dependants search terms.
|
|
87
87
|
8. Do not modify the prefix or generate a different prefix.
|
|
88
88
|
|
|
89
89
|
Examples:
|
|
@@ -259,7 +259,7 @@ Code nodes must follow one of these two structures:
|
|
|
259
259
|
"endLine": 47,
|
|
260
260
|
"is_function": true,
|
|
261
261
|
"external_dependants": [
|
|
262
|
-
"
|
|
262
|
+
"OrderRepository"
|
|
263
263
|
]
|
|
264
264
|
}
|
|
265
265
|
|
|
@@ -270,52 +270,34 @@ Rules:
|
|
|
270
270
|
- 'endLine': Last line of the code entity.
|
|
271
271
|
- 'is_function': Include this property only on function nodes, with the boolean value true. Do not include it on non-function code nodes.
|
|
272
272
|
- Treat function declarations, function expressions, arrow functions, methods, constructors, and hooks as function nodes.
|
|
273
|
-
- 'external_dependants': Array of
|
|
274
|
-
- Use an empty array when
|
|
273
|
+
- 'external_dependants': Array of strings representing dependencies that are unresolved in the complete source code supplied for analysis.
|
|
274
|
+
- Use an empty array when the current entity has no unresolved dependencies.
|
|
275
275
|
- Do not include 'type', 'name', 'parameters', 'returnType', 'description', source snippets, or any other properties.
|
|
276
276
|
- Do not invent line numbers. Use null when source positions are unavailable.
|
|
277
277
|
- Every function node must include all five properties, including 'is_function': true.
|
|
278
278
|
- Non-function code nodes must not include 'is_function' and must contain exactly the four properties: 'id', 'startLine', 'endLine', and 'external_dependants'.
|
|
279
279
|
|
|
280
|
-
### External
|
|
280
|
+
### External Dependants
|
|
281
281
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
Examples:
|
|
285
|
-
|
|
286
|
-
For a function:
|
|
287
|
-
|
|
288
|
-
[
|
|
289
|
-
"\\bcalculateTotal\\s*\\("
|
|
290
|
-
]
|
|
291
|
-
|
|
292
|
-
For a method:
|
|
293
|
-
|
|
294
|
-
[
|
|
295
|
-
"\\.calculateTotal\\s*\\(",
|
|
296
|
-
"\\bcalculateTotal\\s*\\("
|
|
297
|
-
]
|
|
298
|
-
|
|
299
|
-
For a custom hook:
|
|
300
|
-
|
|
301
|
-
[
|
|
302
|
-
"\\buseOrders\\s*\\("
|
|
303
|
-
]
|
|
304
|
-
|
|
305
|
-
For a class:
|
|
306
|
-
|
|
307
|
-
[
|
|
308
|
-
"\\bnew\\s+OrderService\\b",
|
|
309
|
-
"\\bOrderService\\b"
|
|
310
|
-
]
|
|
282
|
+
An external dependant is a dependency used by the current code entity whose definition or implementation cannot be found anywhere in the complete source code supplied for analysis.
|
|
311
283
|
|
|
312
284
|
Rules:
|
|
313
285
|
|
|
314
|
-
1.
|
|
315
|
-
2.
|
|
316
|
-
3.
|
|
317
|
-
4.
|
|
318
|
-
5.
|
|
286
|
+
1. Include only dependencies that the current code entity actually uses or references to perform its functionality.
|
|
287
|
+
2. Determine whether each dependency is defined or implemented anywhere in the complete supplied source code, including other supplied files.
|
|
288
|
+
3. If the dependency is defined or implemented anywhere in the supplied source code, it is resolved and must not be included.
|
|
289
|
+
4. If the dependency is used by the current entity but its definition or implementation is not available anywhere in the supplied source code, include its name in 'external_dependants'.
|
|
290
|
+
5. Never include the current entity itself.
|
|
291
|
+
6. Never include entities that are locally declared or defined in the supplied source code.
|
|
292
|
+
7. Do not include local variables, parameters, or properties merely because they are referenced.
|
|
293
|
+
8. Do not include built-in language functionality, standard library functionality, or functionality provided by the framework or runtime.
|
|
294
|
+
9. Do not infer dependencies from names alone. There must be evidence that the current entity actually uses or references the dependency.
|
|
295
|
+
10. Do not include dependencies that are only hypothetical or might be needed in a different implementation.
|
|
296
|
+
11. Use the dependency's plain identifier or name as the array string. Do not use regular expressions, search patterns, wildcards, escaping, or matching operators.
|
|
297
|
+
12. Do not include the current entity's own name, declaration, or definition as an external dependency.
|
|
298
|
+
13. If no unresolved dependencies exist, return an empty array.
|
|
299
|
+
|
|
300
|
+
The purpose of 'external_dependants' is to identify dependencies whose source definitions may need to be found outside the currently supplied source code. It is not a list of identifiers to search for usages of the current entity.
|
|
319
301
|
|
|
320
302
|
# 5. DATABASE SCHEMAS
|
|
321
303
|
|
|
@@ -372,7 +354,7 @@ UI code entities must follow the same code-node structures defined in Section 4:
|
|
|
372
354
|
"endLine": 47,
|
|
373
355
|
"is_function": true,
|
|
374
356
|
"external_dependants": [
|
|
375
|
-
"
|
|
357
|
+
"OrderRepository"
|
|
376
358
|
]
|
|
377
359
|
}
|
|
378
360
|
|
|
@@ -502,7 +484,7 @@ Follow these rules:
|
|
|
502
484
|
9. Capture meaningful structural, semantic, and dependency relationships.
|
|
503
485
|
10. Do not invent information.
|
|
504
486
|
11. Ensure every edge references existing nodes.
|
|
505
|
-
12.
|
|
487
|
+
12. Include only genuine unresolved dependencies in 'external_dependants', according to Section 4.
|
|
506
488
|
13. Do not add unnecessary properties to nodes.
|
|
507
489
|
14. Follow the strict node structures defined in this prompt.
|
|
508
490
|
|
|
@@ -525,7 +507,7 @@ Before returning the output, verify:
|
|
|
525
507
|
- Line numbers accurately identify the original input range represented by each node.
|
|
526
508
|
- Text and configuration node line ranges correspond exactly to their preserved 'content'.
|
|
527
509
|
- Unavailable line positions are represented as null, not omitted or fabricated.
|
|
528
|
-
-
|
|
510
|
+
- Every 'external_dependants' entry names a genuine dependency that is unresolved in the complete supplied source code.
|
|
529
511
|
|
|
530
512
|
### Edges
|
|
531
513
|
|
|
@@ -556,13 +538,15 @@ If a declaration or definition is present in the input, create its node and use
|
|
|
556
538
|
If an entity is declared in another supplied source file, it may be represented as a node using that declaration's source location.
|
|
557
539
|
|
|
558
540
|
External Dependants:
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
Do not
|
|
562
|
-
Do not
|
|
541
|
+
1. Populate 'external_dependants' only on code nodes that are declared or defined in the supplied source code.
|
|
542
|
+
2. Each entry must identify another code entity that the current node actually depends on and whose definition or implementation is absent from the complete supplied source code.
|
|
543
|
+
3. Do not include imported-only symbols as standalone code nodes. However, an imported symbol may appear in the 'external_dependants' array of a code node when that node actually uses it and its definition is not present in the supplied source.
|
|
544
|
+
4. Do not include dependencies that are defined in another supplied source file.
|
|
545
|
+
5. Do not include the current node's own name, locally defined entities, local variables, parameters, properties, built-in functionality, standard library functionality, or framework/runtime functionality.
|
|
546
|
+
6. If there are no such unresolved dependencies, use an empty array.
|
|
563
547
|
|
|
564
548
|
Validation:
|
|
565
|
-
Before
|
|
549
|
+
Before returning the graph, verify each 'external_dependants' entry against the complete supplied source code. Remove the entry if its definition or implementation is present in any supplied source file, if the current entity does not actually use it, or if it is the current entity itself.
|
|
566
550
|
|
|
567
551
|
# 12. FINAL OUTPUT
|
|
568
552
|
|
package/services/graphService.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const SessionManager = require('../session/sessionManager');
|
|
2
1
|
const FileUtil = require('../utils/fileUtil');
|
|
3
2
|
const IdUtil = require('../utils/idUtil');
|
|
4
3
|
const LLM = require("../llm/llm");
|
|
5
4
|
const PromptsUtil = require('../utils/promptsUtil');
|
|
5
|
+
const HashUtil = require('../utils/hashUtil');
|
|
6
6
|
const Logger = require('../utils/logger');
|
|
7
7
|
const globals = require("../globals");
|
|
8
8
|
const path = require("path");
|
|
@@ -12,30 +12,28 @@ class GraphService {
|
|
|
12
12
|
constructor() {
|
|
13
13
|
this.fileUtil = new FileUtil();
|
|
14
14
|
this.llm = new LLM(globals.config.llm);
|
|
15
|
-
|
|
15
|
+
globals.graphs = [];
|
|
16
|
+
this.updatedPaths = [];
|
|
16
17
|
|
|
17
18
|
this.batchSize = globals.config.batch_size ?? 10;
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
hasUpdates() {
|
|
22
|
+
return this.updatedPaths.length > 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
async buildGraphs() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
this.fileUtil.removeAllFiles("graph");
|
|
26
|
+
Logger.essential("Finding source exclusions");
|
|
27
|
+
await this._identifyExclusions();
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Logger.essential("Building nodes is in-progress");
|
|
29
|
-
await this._buildNodes();
|
|
29
|
+
Logger.essential("Building nodes is in-progress");
|
|
30
|
+
await this._loadGraphs();
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
}
|
|
32
|
+
await this._buildNodes();
|
|
33
33
|
|
|
34
|
-
if(
|
|
35
|
-
Logger.essential("Connecting edges");
|
|
34
|
+
if(this.hasUpdates()) {
|
|
35
|
+
Logger.essential("Connecting external edges");
|
|
36
36
|
await this._buildExternalEdges();
|
|
37
|
-
|
|
38
|
-
SessionManager.updateStage("connect_edges");
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
|
|
@@ -53,35 +51,6 @@ class GraphService {
|
|
|
53
51
|
this.additionalExclusions = response.exclusions;
|
|
54
52
|
}
|
|
55
53
|
|
|
56
|
-
async loadGraphs() {
|
|
57
|
-
this.graphs = [];
|
|
58
|
-
this.sources = [];
|
|
59
|
-
|
|
60
|
-
const graphFiles = this.fileUtil.readPaths([
|
|
61
|
-
path.join(this.fileUtil.baseDir, "graph")
|
|
62
|
-
]);
|
|
63
|
-
|
|
64
|
-
for (const file of graphFiles) {
|
|
65
|
-
if (!file.filename.endsWith(".json")) continue;
|
|
66
|
-
|
|
67
|
-
const data = this.fileUtil.loadJSON(
|
|
68
|
-
path.join("graph", file.filename)
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
if (!data?.file || !data?.graph) continue;
|
|
72
|
-
|
|
73
|
-
this.graphs.push({
|
|
74
|
-
graphPath: path.join("graph", file.filename),
|
|
75
|
-
file: data.file,
|
|
76
|
-
graph: data.graph
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
this.sources.push(data.file);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return this.graphs;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
54
|
async _buildNodes() {
|
|
86
55
|
const sourceFiles = globals.config.sources;
|
|
87
56
|
|
|
@@ -94,6 +63,8 @@ class GraphService {
|
|
|
94
63
|
|
|
95
64
|
this.sources = this.fileUtil.readPaths(sourceFiles, exclusions);
|
|
96
65
|
|
|
66
|
+
this.updatedPaths = [];
|
|
67
|
+
|
|
97
68
|
const total = this.sources.length;
|
|
98
69
|
let completed = 0;
|
|
99
70
|
|
|
@@ -114,21 +85,29 @@ class GraphService {
|
|
|
114
85
|
const results = await Promise.all(
|
|
115
86
|
batch.map(async (source) => {
|
|
116
87
|
try {
|
|
117
|
-
|
|
88
|
+
const hash = HashUtil.hashFile(source.path);
|
|
118
89
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
JSON.stringify(source.content)
|
|
90
|
+
const existingGraph = globals.graphs.find(
|
|
91
|
+
item => item.file.path === source.path
|
|
122
92
|
);
|
|
123
93
|
|
|
94
|
+
// Skip unchanged files
|
|
95
|
+
if (existingGraph && existingGraph.file.hash === hash) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Track new and modified files
|
|
100
|
+
this.updatedPaths.push(source.path);
|
|
101
|
+
|
|
102
|
+
let prompt = PromptsUtil.read("graph.build_nodes");
|
|
103
|
+
|
|
104
|
+
prompt = prompt.replaceAll("***CONTENT***", JSON.stringify(source.content));
|
|
105
|
+
|
|
124
106
|
prompt = prompt.replaceAll("ID-PREFIX", IdUtil.generate());
|
|
125
107
|
|
|
126
108
|
Logger.detailed(prompt);
|
|
127
109
|
|
|
128
|
-
const graph = await this.llm.generate({
|
|
129
|
-
prompt,
|
|
130
|
-
json: true
|
|
131
|
-
});
|
|
110
|
+
const graph = await this.llm.generate({ prompt, json: true });
|
|
132
111
|
|
|
133
112
|
Logger.detailed(JSON.stringify(graph));
|
|
134
113
|
|
|
@@ -139,24 +118,19 @@ class GraphService {
|
|
|
139
118
|
const sourceJson = {
|
|
140
119
|
file: path.basename(source.path),
|
|
141
120
|
path: source.path,
|
|
142
|
-
purpose: graph.purpose
|
|
121
|
+
purpose: graph.purpose,
|
|
122
|
+
hash
|
|
143
123
|
};
|
|
144
124
|
|
|
145
125
|
this.fileUtil.saveJSON(graphPath, {
|
|
146
126
|
file: sourceJson,
|
|
147
|
-
graph: {
|
|
148
|
-
nodes: graph.nodes,
|
|
149
|
-
edges: graph.edges
|
|
150
|
-
}
|
|
127
|
+
graph: { nodes: graph.nodes, edges: graph.edges }
|
|
151
128
|
});
|
|
152
129
|
|
|
153
130
|
return {
|
|
154
131
|
graphPath,
|
|
155
|
-
file: source,
|
|
156
|
-
graph: {
|
|
157
|
-
nodes: graph.nodes,
|
|
158
|
-
edges: graph.edges
|
|
159
|
-
}
|
|
132
|
+
file: { ...source, hash },
|
|
133
|
+
graph: { nodes: graph.nodes, edges: graph.edges }
|
|
160
134
|
};
|
|
161
135
|
} finally {
|
|
162
136
|
completed++;
|
|
@@ -165,7 +139,7 @@ class GraphService {
|
|
|
165
139
|
})
|
|
166
140
|
);
|
|
167
141
|
|
|
168
|
-
|
|
142
|
+
globals.graphs.push(...results.filter(Boolean));
|
|
169
143
|
}
|
|
170
144
|
} finally {
|
|
171
145
|
progressBar.stop();
|
|
@@ -173,8 +147,8 @@ class GraphService {
|
|
|
173
147
|
}
|
|
174
148
|
|
|
175
149
|
async _buildExternalEdges() {
|
|
176
|
-
for (let i = 0; i <
|
|
177
|
-
const batch =
|
|
150
|
+
for (let i = 0; i < globals.graphs.length; i += this.batchSize) {
|
|
151
|
+
const batch = globals.graphs.slice(i, i + this.batchSize);
|
|
178
152
|
|
|
179
153
|
await Promise.all(
|
|
180
154
|
batch.map(async (sourceGraph) => {
|
|
@@ -214,40 +188,32 @@ class GraphService {
|
|
|
214
188
|
JSON.stringify(candidateData, null, 2)
|
|
215
189
|
);
|
|
216
190
|
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
let result;
|
|
220
|
-
|
|
221
|
-
try {
|
|
222
|
-
result = JSON.parse(response.text);
|
|
223
|
-
} catch {
|
|
224
|
-
continue;
|
|
225
|
-
}
|
|
191
|
+
const result = await this.llm.generate({ prompt: prompt, json: true });
|
|
226
192
|
|
|
227
193
|
if (!result?.selectedNodeId) continue;
|
|
228
194
|
|
|
229
|
-
const selected = candidates.find(
|
|
230
|
-
candidate => candidate.id === result.selectedNodeId
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
if (!selected) continue;
|
|
234
|
-
|
|
235
195
|
const exists = sourceGraph.graph.edges.some(
|
|
236
196
|
edge =>
|
|
237
197
|
edge.node1 === node.id &&
|
|
238
|
-
edge.node2 ===
|
|
198
|
+
edge.node2 === result.selectedNodeId
|
|
239
199
|
);
|
|
240
200
|
|
|
241
201
|
if (exists) continue;
|
|
242
202
|
|
|
243
203
|
sourceGraph.graph.edges.push({
|
|
244
204
|
node1: node.id,
|
|
245
|
-
node2:
|
|
205
|
+
node2: result.selectedNodeId
|
|
246
206
|
});
|
|
247
207
|
}
|
|
248
208
|
}
|
|
249
209
|
|
|
250
|
-
const sourceJson = {
|
|
210
|
+
const sourceJson = {
|
|
211
|
+
file: path.basename(sourceGraph.file.path),
|
|
212
|
+
path: sourceGraph.file.path,
|
|
213
|
+
purpose: sourceGraph.file.purpose,
|
|
214
|
+
hash: sourceGraph.file.hash
|
|
215
|
+
};
|
|
216
|
+
|
|
251
217
|
this.fileUtil.saveJSON(sourceGraph.graphPath, {
|
|
252
218
|
file: sourceJson,
|
|
253
219
|
graph: sourceGraph.graph
|
|
@@ -270,7 +236,7 @@ class GraphService {
|
|
|
270
236
|
.join("\n");
|
|
271
237
|
}
|
|
272
238
|
|
|
273
|
-
_searchSources(
|
|
239
|
+
_searchSources(searchTerms, sourceFile) {
|
|
274
240
|
const matches = [];
|
|
275
241
|
|
|
276
242
|
for (const source of this.sources) {
|
|
@@ -281,24 +247,22 @@ class GraphService {
|
|
|
281
247
|
const lines = source.content.split(/\r?\n/);
|
|
282
248
|
|
|
283
249
|
for (let i = 0; i < lines.length; i++) {
|
|
284
|
-
for (const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (!match[0].length) regex.lastIndex++;
|
|
297
|
-
}
|
|
250
|
+
for (const term of searchTerms) {
|
|
251
|
+
|
|
252
|
+
// Search for literal text (case-sensitive)
|
|
253
|
+
if (!term || !lines[i].includes(term)) continue;
|
|
254
|
+
|
|
255
|
+
matches.push({
|
|
256
|
+
file: source.path,
|
|
257
|
+
line: i + 1,
|
|
258
|
+
matchedText: term,
|
|
259
|
+
sourceLine: lines[i].trim()
|
|
260
|
+
});
|
|
298
261
|
}
|
|
299
262
|
}
|
|
300
263
|
}
|
|
301
264
|
|
|
265
|
+
// Remove duplicate matches
|
|
302
266
|
return [
|
|
303
267
|
...new Map(
|
|
304
268
|
matches.map(match => [
|
|
@@ -320,7 +284,7 @@ class GraphService {
|
|
|
320
284
|
|
|
321
285
|
const lines = source.content.split(/\r?\n/);
|
|
322
286
|
|
|
323
|
-
for (const sourceGraph of
|
|
287
|
+
for (const sourceGraph of globals.graphs) {
|
|
324
288
|
if (sourceGraph.file.path !== match.file) continue;
|
|
325
289
|
for (const node of sourceGraph.graph.nodes) {
|
|
326
290
|
if (
|
|
@@ -341,6 +305,33 @@ class GraphService {
|
|
|
341
305
|
|
|
342
306
|
return candidates;
|
|
343
307
|
}
|
|
308
|
+
|
|
309
|
+
async _loadGraphs() {
|
|
310
|
+
globals.graphs = [];
|
|
311
|
+
this.sources = [];
|
|
312
|
+
|
|
313
|
+
const graphFiles = this.fileUtil.readPaths([
|
|
314
|
+
path.join(this.fileUtil.baseDir, "graph")
|
|
315
|
+
]);
|
|
316
|
+
|
|
317
|
+
for (const file of graphFiles) {
|
|
318
|
+
if (!file.filename.endsWith(".json")) continue;
|
|
319
|
+
|
|
320
|
+
const data = this.fileUtil.loadJSON(
|
|
321
|
+
path.join("graph", file.filename)
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
if (!data?.file || !data?.graph) continue;
|
|
325
|
+
|
|
326
|
+
globals.graphs.push({
|
|
327
|
+
graphPath: path.join("graph", file.filename),
|
|
328
|
+
file: data.file,
|
|
329
|
+
graph: data.graph
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
this.sources.push(data.file);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
344
335
|
}
|
|
345
336
|
|
|
346
337
|
module.exports = GraphService;
|
|
@@ -9,6 +9,27 @@ class WorkflowService {
|
|
|
9
9
|
static workflowFile = path.join(WorkflowService.baseDir, "workflows.json");
|
|
10
10
|
|
|
11
11
|
build() {
|
|
12
|
+
const functionNodeIds = this._getFunctionNodeIds();
|
|
13
|
+
const workflowMap = new Map();
|
|
14
|
+
|
|
15
|
+
if (functionNodeIds.size === 0) {
|
|
16
|
+
this._buildFallbackWorkflow(workflowMap);
|
|
17
|
+
} else {
|
|
18
|
+
this._initializeWorkflows(workflowMap, functionNodeIds);
|
|
19
|
+
|
|
20
|
+
const adjacencyMap = this._buildAdjacencyMap();
|
|
21
|
+
|
|
22
|
+
this._traverseWorkflows(workflowMap, functionNodeIds, adjacencyMap);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const workflows = [...workflowMap.values()];
|
|
26
|
+
|
|
27
|
+
this._saveWorkflows(workflows);
|
|
28
|
+
|
|
29
|
+
return workflows;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_getFunctionNodeIds() {
|
|
12
33
|
const functionNodeIds = new Set();
|
|
13
34
|
|
|
14
35
|
for (const graph of globals.graphs) {
|
|
@@ -21,55 +42,99 @@ class WorkflowService {
|
|
|
21
42
|
}
|
|
22
43
|
}
|
|
23
44
|
|
|
24
|
-
|
|
45
|
+
return functionNodeIds;
|
|
46
|
+
}
|
|
25
47
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
);
|
|
48
|
+
_buildFallbackWorkflow(workflowMap) {
|
|
49
|
+
const allNodes = globals.graphs.flatMap(
|
|
50
|
+
graph => graph.graph?.nodes || []
|
|
51
|
+
);
|
|
31
52
|
|
|
32
|
-
|
|
33
|
-
|
|
53
|
+
if (allNodes.length > 0) {
|
|
54
|
+
const rootNode = allNodes[0];
|
|
34
55
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
workflowMap.set(rootNode.id, {
|
|
57
|
+
id: IdUtil.generate(),
|
|
58
|
+
node: rootNode.id,
|
|
59
|
+
childNodes: allNodes.slice(1).map(node => node.id)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
_initializeWorkflows(workflowMap, functionNodeIds) {
|
|
65
|
+
for (const nodeId of functionNodeIds) {
|
|
66
|
+
workflowMap.set(nodeId, {
|
|
67
|
+
id: IdUtil.generate(),
|
|
68
|
+
node: nodeId,
|
|
69
|
+
childNodes: []
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
51
73
|
|
|
52
|
-
|
|
53
|
-
|
|
74
|
+
_buildAdjacencyMap() {
|
|
75
|
+
const adjacencyMap = new Map();
|
|
54
76
|
|
|
55
|
-
|
|
56
|
-
|
|
77
|
+
for (const graph of globals.graphs) {
|
|
78
|
+
const edges = graph.graph?.edges || [];
|
|
57
79
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
80
|
+
for (const edge of edges) {
|
|
81
|
+
const { node1, node2 } = edge;
|
|
61
82
|
|
|
62
|
-
|
|
63
|
-
|
|
83
|
+
if (!adjacencyMap.has(node1)) {
|
|
84
|
+
adjacencyMap.set(node1, new Set());
|
|
64
85
|
}
|
|
86
|
+
|
|
87
|
+
if (!adjacencyMap.has(node2)) {
|
|
88
|
+
adjacencyMap.set(node2, new Set());
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
adjacencyMap.get(node1).add(node2);
|
|
92
|
+
adjacencyMap.get(node2).add(node1);
|
|
65
93
|
}
|
|
66
94
|
}
|
|
67
95
|
|
|
68
|
-
|
|
96
|
+
return adjacencyMap;
|
|
97
|
+
}
|
|
69
98
|
|
|
70
|
-
|
|
99
|
+
_traverseWorkflows(workflowMap, functionNodeIds, adjacencyMap) {
|
|
100
|
+
for (const [functionNodeId, workflow] of workflowMap) {
|
|
101
|
+
this._traverseFromFunction(
|
|
102
|
+
functionNodeId,
|
|
103
|
+
workflow,
|
|
104
|
+
functionNodeIds,
|
|
105
|
+
adjacencyMap
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
71
109
|
|
|
72
|
-
|
|
110
|
+
_traverseFromFunction(functionNodeId, workflow, functionNodeIds, adjacencyMap) {
|
|
111
|
+
const visited = new Set([functionNodeId]);
|
|
112
|
+
const queue = [functionNodeId];
|
|
113
|
+
|
|
114
|
+
while (queue.length > 0) {
|
|
115
|
+
const currentNodeId = queue.shift();
|
|
116
|
+
|
|
117
|
+
const connectedNodes = adjacencyMap.get(currentNodeId) || [];
|
|
118
|
+
|
|
119
|
+
for (const connectedNodeId of connectedNodes) {
|
|
120
|
+
if (visited.has(connectedNodeId)) {
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
visited.add(connectedNodeId);
|
|
125
|
+
|
|
126
|
+
// Add connected node, including another function node
|
|
127
|
+
workflow.childNodes.push(connectedNodeId);
|
|
128
|
+
|
|
129
|
+
// Stop traversal when another function node is reached
|
|
130
|
+
if (functionNodeIds.has(connectedNodeId)) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Continue traversal through non-function nodes
|
|
135
|
+
queue.push(connectedNodeId);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
73
138
|
}
|
|
74
139
|
|
|
75
140
|
loadWorkflows() {
|
|
@@ -97,6 +162,8 @@ class WorkflowService {
|
|
|
97
162
|
}
|
|
98
163
|
|
|
99
164
|
_addConnection(workflowMap, source, target) {
|
|
165
|
+
if(!workflowMap.has(source)) return;
|
|
166
|
+
|
|
100
167
|
const childNodes = workflowMap.get(source).childNodes;
|
|
101
168
|
|
|
102
169
|
if (!childNodes.includes(target)) {
|
package/utils/fileUtil.js
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
const crypto = require("crypto");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
|
|
5
|
+
class HashUtil {
|
|
6
|
+
|
|
7
|
+
static hash(content) {
|
|
8
|
+
return crypto
|
|
9
|
+
.createHash("sha256")
|
|
10
|
+
.update(content, "utf8")
|
|
11
|
+
.digest("hex");
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static hashFile(filePath) {
|
|
15
|
+
const content = fs.readFileSync(filePath);
|
|
16
|
+
return crypto
|
|
17
|
+
.createHash("sha256")
|
|
18
|
+
.update(content)
|
|
19
|
+
.digest("hex");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static async hashFileAsync(filePath) {
|
|
23
|
+
const hash = crypto.createHash("sha256");
|
|
24
|
+
const stream = fs.createReadStream(filePath);
|
|
25
|
+
|
|
26
|
+
for await (const chunk of stream) {
|
|
27
|
+
hash.update(chunk);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return hash.digest("hex");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = HashUtil;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
const path = require("path");
|
|
4
|
-
|
|
5
|
-
class SessionManager {
|
|
6
|
-
|
|
7
|
-
static STATE = {
|
|
8
|
-
NONE: "none",
|
|
9
|
-
IN_PROGRESS: "in_progress",
|
|
10
|
-
COMPLETED: "completed",
|
|
11
|
-
ABORTED: "aborted"
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
static STAGES = {
|
|
15
|
-
NONE: "none",
|
|
16
|
-
BUILD_NODES: "build_nodes",
|
|
17
|
-
CONNECT_EDGES: "connect_edges",
|
|
18
|
-
BUILD_WORKFLOWS: "build_workflows",
|
|
19
|
-
DEFINE_ENVIRONMENTS: "identify_runners",
|
|
20
|
-
STATIC_ANALYSIS: "static_analysis",
|
|
21
|
-
DEEP_ANALYSIS: "deep_analysis",
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
static session = null;
|
|
25
|
-
|
|
26
|
-
static baseDir = path.join(process.cwd(), ".deeplyzer");
|
|
27
|
-
static sessionFile = path.join(SessionManager.baseDir, "session.json");
|
|
28
|
-
|
|
29
|
-
static _ensureDirectory() {
|
|
30
|
-
fs.mkdirSync(this.baseDir, { recursive: true });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
static loadSession() {
|
|
34
|
-
this._ensureDirectory();
|
|
35
|
-
|
|
36
|
-
if (!fs.existsSync(this.sessionFile)) {
|
|
37
|
-
this.session = {
|
|
38
|
-
state: this.STATE.IN_PROGRESS,
|
|
39
|
-
currentStage: this.STAGES.NONE
|
|
40
|
-
};
|
|
41
|
-
this._writeSession();
|
|
42
|
-
return this.session;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
this.session = JSON.parse(
|
|
47
|
-
fs.readFileSync(this.sessionFile, "utf8")
|
|
48
|
-
);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
throw new Error(`Failed to load session: ${error.message}`);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static updateState(state) {
|
|
55
|
-
if (!this.session) {
|
|
56
|
-
this.loadSession();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
this.session.state = state;
|
|
60
|
-
|
|
61
|
-
this._writeSession();
|
|
62
|
-
|
|
63
|
-
return this.session;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
static updateStage(stage) {
|
|
68
|
-
if (!this.session) {
|
|
69
|
-
this.loadSession();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.session.currentStage = stage;
|
|
73
|
-
|
|
74
|
-
this._writeSession();
|
|
75
|
-
|
|
76
|
-
return this.session;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
static clearSession() {
|
|
80
|
-
this.session = {
|
|
81
|
-
state: this.STATE.NONE,
|
|
82
|
-
currentStage: this.STAGES.NONE
|
|
83
|
-
};
|
|
84
|
-
this._writeSession();
|
|
85
|
-
return this.session;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static resetAnalysisSession() {
|
|
89
|
-
this.session = {
|
|
90
|
-
state: this.STATE.IN_PROGRESS,
|
|
91
|
-
currentStage: this.STAGES.DEFINE_ENVIRONMENTS
|
|
92
|
-
};
|
|
93
|
-
this._writeSession();
|
|
94
|
-
return this.session;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
static checkStage(stage) {
|
|
98
|
-
if (!this.session) {
|
|
99
|
-
this.loadSession();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const stages = Object.values(this.STAGES);
|
|
103
|
-
|
|
104
|
-
const stageIndex = stages.indexOf(stage);
|
|
105
|
-
|
|
106
|
-
if (stageIndex === -1) {
|
|
107
|
-
throw new Error(`Invalid stage: ${stage}`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const lastCompletedIndex = stages.indexOf(this.session.currentStage);
|
|
111
|
-
|
|
112
|
-
return stageIndex > lastCompletedIndex;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
static _writeSession() {
|
|
116
|
-
this._ensureDirectory();
|
|
117
|
-
|
|
118
|
-
fs.writeFileSync(
|
|
119
|
-
this.sessionFile,
|
|
120
|
-
JSON.stringify(this.session, null, 4),
|
|
121
|
-
"utf8"
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
static getStageList() {
|
|
126
|
-
return Object.values(this.STAGES);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
module.exports = SessionManager;
|