deeplyzer 0.9.0 → 0.10.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/analysis/deep/orchestratorAgent.js +19 -8
- package/analysis/deep/runner/runnerAgent.js +72 -27
- package/package.json +2 -1
- package/prompts/deep.runner.command +230 -37
- package/prompts/deep.runner.identify.runtime +365 -0
- package/prompts/deep.runner.runtime +137 -44
- package/prompts/graph.source_exclusions +2 -0
- package/services/graphService.js +76 -22
- package/utils/execUtil.js +115 -13
- package/utils/fileUtil.js +13 -16
package/services/graphService.js
CHANGED
|
@@ -6,6 +6,7 @@ const PromptsUtil = require('../utils/promptsUtil');
|
|
|
6
6
|
const Logger = require('../utils/logger');
|
|
7
7
|
const globals = require("../globals");
|
|
8
8
|
const path = require("path");
|
|
9
|
+
const cliProgress = require("cli-progress");
|
|
9
10
|
|
|
10
11
|
class GraphService {
|
|
11
12
|
constructor() {
|
|
@@ -40,7 +41,7 @@ class GraphService {
|
|
|
40
41
|
|
|
41
42
|
async _identifyExclusions() {
|
|
42
43
|
const sources = this.fileUtil.readPaths(globals.config.sources, globals.config["source_exclusions"]);
|
|
43
|
-
const folders = [...new Set(sources.
|
|
44
|
+
const folders = [...new Set(sources.flatMap(source => [source.path, path.dirname(source.path)]))];
|
|
44
45
|
|
|
45
46
|
let prompt = PromptsUtil.read("graph.source_exclusions");
|
|
46
47
|
prompt = prompt.replaceAll("***PATHS***", JSON.stringify(folders));
|
|
@@ -83,38 +84,91 @@ class GraphService {
|
|
|
83
84
|
|
|
84
85
|
async _buildNodes() {
|
|
85
86
|
const sourceFiles = globals.config.sources;
|
|
87
|
+
|
|
86
88
|
const exclusions = [...new Set([
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
"**/*.png", "**/*.jpg", "**/*.jpeg", "**/*.gif", "**/*.bmp",
|
|
90
|
+
"**/*.webp", "**/*.svg", "**/*.ico", "**/*.tif", "**/*.tiff",
|
|
91
|
+
...(globals.config.source_exclusions || []),
|
|
92
|
+
...(this.additionalExclusions || [])
|
|
93
|
+
])];
|
|
90
94
|
|
|
91
95
|
this.sources = this.fileUtil.readPaths(sourceFiles, exclusions);
|
|
92
96
|
|
|
93
|
-
|
|
94
|
-
|
|
97
|
+
const total = this.sources.length;
|
|
98
|
+
let completed = 0;
|
|
95
99
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
100
|
+
const progressBar = new cliProgress.SingleBar({
|
|
101
|
+
format: 'Building Nodes |{bar}| {percentage}% | {value}/{total}',
|
|
102
|
+
barCompleteChar: '\u2588',
|
|
103
|
+
barIncompleteChar: '\u2591',
|
|
104
|
+
barsize: 25,
|
|
105
|
+
hideCursor: true
|
|
106
|
+
}, cliProgress.Presets.shades_classic);
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
prompt = prompt.replaceAll("ID-PREFIX", IdUtil.generate());
|
|
102
|
-
Logger.detailed(prompt);
|
|
108
|
+
progressBar.start(total, 0);
|
|
103
109
|
|
|
104
|
-
|
|
105
|
-
|
|
110
|
+
try {
|
|
111
|
+
for (let i = 0; i < total; i += this.batchSize) {
|
|
112
|
+
const batch = this.sources.slice(i, i + this.batchSize);
|
|
106
113
|
|
|
107
|
-
|
|
114
|
+
const results = await Promise.all(
|
|
115
|
+
batch.map(async (source) => {
|
|
116
|
+
try {
|
|
117
|
+
let prompt = PromptsUtil.read("graph.build_nodes");
|
|
108
118
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
119
|
+
prompt = prompt.replaceAll(
|
|
120
|
+
"***CONTENT***",
|
|
121
|
+
JSON.stringify(source.content)
|
|
122
|
+
);
|
|
112
123
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
prompt = prompt.replaceAll("ID-PREFIX", IdUtil.generate());
|
|
125
|
+
|
|
126
|
+
Logger.detailed(prompt);
|
|
127
|
+
|
|
128
|
+
const graph = await this.llm.generate({
|
|
129
|
+
prompt,
|
|
130
|
+
json: true
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
Logger.detailed(JSON.stringify(graph));
|
|
134
|
+
|
|
135
|
+
const graphPath = `./graph/${IdUtil.generate()}.json`;
|
|
116
136
|
|
|
117
|
-
|
|
137
|
+
source.purpose = graph.purpose;
|
|
138
|
+
|
|
139
|
+
const sourceJson = {
|
|
140
|
+
file: path.basename(source.path),
|
|
141
|
+
path: source.path,
|
|
142
|
+
purpose: graph.purpose
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
this.fileUtil.saveJSON(graphPath, {
|
|
146
|
+
file: sourceJson,
|
|
147
|
+
graph: {
|
|
148
|
+
nodes: graph.nodes,
|
|
149
|
+
edges: graph.edges
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return {
|
|
154
|
+
graphPath,
|
|
155
|
+
file: source,
|
|
156
|
+
graph: {
|
|
157
|
+
nodes: graph.nodes,
|
|
158
|
+
edges: graph.edges
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
} finally {
|
|
162
|
+
completed++;
|
|
163
|
+
progressBar.update(completed);
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
this.graphs.push(...results);
|
|
169
|
+
}
|
|
170
|
+
} finally {
|
|
171
|
+
progressBar.stop();
|
|
118
172
|
}
|
|
119
173
|
}
|
|
120
174
|
|
package/utils/execUtil.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
|
|
1
2
|
const path = require("path");
|
|
2
|
-
const { exec } = require("child_process");
|
|
3
|
+
const { exec, spawn } = require("child_process");
|
|
3
4
|
const util = require("util");
|
|
4
5
|
const fs = require("fs");
|
|
5
6
|
const { createRequire } = require("module");
|
|
@@ -16,16 +17,30 @@ class ExecUtil {
|
|
|
16
17
|
|
|
17
18
|
this.platform = process.platform;
|
|
18
19
|
this.shell = this._getShell();
|
|
20
|
+
|
|
21
|
+
// Background command -> accumulated output
|
|
22
|
+
this.backgroundCommandOutput = new Map();
|
|
23
|
+
|
|
24
|
+
// Background command -> child process
|
|
25
|
+
this.processes = new Map();
|
|
19
26
|
}
|
|
20
27
|
|
|
21
|
-
async exec(command, id) {
|
|
22
|
-
let cwd = this.baseDir
|
|
23
|
-
if(id) {
|
|
24
|
-
cwd = path.join(this.baseDir, "src", id);
|
|
28
|
+
async exec(command, id = "", detached = false) {
|
|
29
|
+
let cwd = this.baseDir;
|
|
25
30
|
|
|
31
|
+
if (id) {
|
|
32
|
+
cwd = path.join(this.baseDir, "src", id);
|
|
26
33
|
fs.mkdirSync(cwd, { recursive: true });
|
|
27
34
|
}
|
|
28
35
|
|
|
36
|
+
if (detached) {
|
|
37
|
+
return this._spawn(command, cwd);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return this._exec(command, cwd);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async _exec(command, cwd) {
|
|
29
44
|
try {
|
|
30
45
|
const { stdout, stderr } = await this.execAsync(command, {
|
|
31
46
|
cwd,
|
|
@@ -37,7 +52,12 @@ class ExecUtil {
|
|
|
37
52
|
if (stdout) process.stdout.write(stdout);
|
|
38
53
|
if (stderr) process.stderr.write(stderr);
|
|
39
54
|
|
|
40
|
-
return {
|
|
55
|
+
return {
|
|
56
|
+
success: true,
|
|
57
|
+
stdout,
|
|
58
|
+
stderr
|
|
59
|
+
};
|
|
60
|
+
|
|
41
61
|
} catch (error) {
|
|
42
62
|
console.error(`[COMMAND ERROR] ${error.message}`);
|
|
43
63
|
|
|
@@ -50,6 +70,87 @@ class ExecUtil {
|
|
|
50
70
|
}
|
|
51
71
|
}
|
|
52
72
|
|
|
73
|
+
_spawn(command, cwd) {
|
|
74
|
+
return new Promise((resolve) => {
|
|
75
|
+
try {
|
|
76
|
+
this.backgroundCommandOutput.set(command, "");
|
|
77
|
+
|
|
78
|
+
const child = spawn(command, {
|
|
79
|
+
cwd,
|
|
80
|
+
shell: this.shell,
|
|
81
|
+
windowsHide: true,
|
|
82
|
+
detached: true,
|
|
83
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
this.processes.set(command, child);
|
|
87
|
+
|
|
88
|
+
const appendOutput = (data) => {
|
|
89
|
+
const current =
|
|
90
|
+
this.backgroundCommandOutput.get(command) || "";
|
|
91
|
+
|
|
92
|
+
const output = data.toString();
|
|
93
|
+
|
|
94
|
+
this.backgroundCommandOutput.set(
|
|
95
|
+
command,
|
|
96
|
+
current + output
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
process.stdout.write(output);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
child.stdout.on("data", appendOutput);
|
|
103
|
+
child.stderr.on("data", appendOutput);
|
|
104
|
+
|
|
105
|
+
child.on("error", (error) => {
|
|
106
|
+
const current =
|
|
107
|
+
this.backgroundCommandOutput.get(command) || "";
|
|
108
|
+
|
|
109
|
+
this.backgroundCommandOutput.set(
|
|
110
|
+
command,
|
|
111
|
+
current + `\n[PROCESS ERROR] ${error.message}`
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
this.processes.delete(command);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
child.on("close", (code, signal) => {
|
|
118
|
+
this.processes.delete(command);
|
|
119
|
+
|
|
120
|
+
const current =
|
|
121
|
+
this.backgroundCommandOutput.get(command) || "";
|
|
122
|
+
|
|
123
|
+
this.backgroundCommandOutput.set(
|
|
124
|
+
command,
|
|
125
|
+
current + `\n[PROCESS EXIT] code=${code}, signal=${signal}`
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
child.on("spawn", () => {
|
|
130
|
+
resolve({
|
|
131
|
+
success: true,
|
|
132
|
+
detached: true,
|
|
133
|
+
pid: child.pid
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
} catch (error) {
|
|
138
|
+
resolve({
|
|
139
|
+
success: false,
|
|
140
|
+
error: error.message
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
getCommandOutput(command) {
|
|
147
|
+
return this.backgroundCommandOutput.get(command) || "";
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
getRunningProcesses() {
|
|
151
|
+
return [...this.processes.keys()];
|
|
152
|
+
}
|
|
153
|
+
|
|
53
154
|
async installPackage(packageName) {
|
|
54
155
|
try {
|
|
55
156
|
fs.mkdirSync(this.baseDir, { recursive: true });
|
|
@@ -68,20 +169,19 @@ class ExecUtil {
|
|
|
68
169
|
if (stderr) process.stderr.write(stderr);
|
|
69
170
|
|
|
70
171
|
return { success: true };
|
|
172
|
+
|
|
71
173
|
} catch (error) {
|
|
72
174
|
return {
|
|
73
175
|
success: false,
|
|
74
|
-
error: "Package installation failed:" + error.message
|
|
75
|
-
}
|
|
176
|
+
error: "Package installation failed: " + error.message
|
|
177
|
+
};
|
|
76
178
|
}
|
|
77
179
|
}
|
|
78
180
|
|
|
79
181
|
async loadPackage(packageName) {
|
|
80
182
|
try {
|
|
81
|
-
// Resolve from .deeplyzer/node_modules
|
|
82
183
|
const modulePath = this.packageRequire.resolve(packageName);
|
|
83
184
|
|
|
84
|
-
// Dynamically load CommonJS or ES modules
|
|
85
185
|
const module = await import(
|
|
86
186
|
pathToFileURL(modulePath).href
|
|
87
187
|
);
|
|
@@ -104,7 +204,7 @@ class ExecUtil {
|
|
|
104
204
|
const modulePath = this.packageRequire.resolve(packageName);
|
|
105
205
|
|
|
106
206
|
const importedModule = await import(
|
|
107
|
-
|
|
207
|
+
pathToFileURL(modulePath).href
|
|
108
208
|
);
|
|
109
209
|
|
|
110
210
|
// Support named exports and default exports
|
|
@@ -145,9 +245,11 @@ class ExecUtil {
|
|
|
145
245
|
return "/bin/bash";
|
|
146
246
|
|
|
147
247
|
default:
|
|
148
|
-
throw new Error(
|
|
248
|
+
throw new Error(
|
|
249
|
+
`Unsupported operating system: ${this.platform}`
|
|
250
|
+
);
|
|
149
251
|
}
|
|
150
252
|
}
|
|
151
253
|
}
|
|
152
254
|
|
|
153
|
-
module.exports = new ExecUtil();
|
|
255
|
+
module.exports = new ExecUtil();
|
package/utils/fileUtil.js
CHANGED
|
@@ -161,17 +161,15 @@ class FileUtil {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
_matchesExclusion(relativePath, isDirectory, exclusions = []) {
|
|
164
|
-
const normalizedPath = relativePath
|
|
165
|
-
.split(path.sep)
|
|
166
|
-
.join("/");
|
|
167
|
-
|
|
164
|
+
const normalizedPath = relativePath.replace(/\\/g, "/");
|
|
168
165
|
const segments = normalizedPath.split("/");
|
|
166
|
+
|
|
169
167
|
let excluded = false;
|
|
170
168
|
|
|
171
169
|
for (let pattern of exclusions) {
|
|
172
170
|
if (!pattern || pattern.startsWith("#")) continue;
|
|
173
171
|
|
|
174
|
-
|
|
172
|
+
const negate = pattern.startsWith("!");
|
|
175
173
|
|
|
176
174
|
if (negate) {
|
|
177
175
|
pattern = pattern.substring(1);
|
|
@@ -186,29 +184,28 @@ class FileUtil {
|
|
|
186
184
|
|
|
187
185
|
if (!pattern) continue;
|
|
188
186
|
|
|
189
|
-
const hasSlash = pattern.includes("/");
|
|
190
187
|
const regex = this._globToRegex(pattern);
|
|
191
|
-
|
|
192
188
|
let matched = false;
|
|
193
189
|
|
|
194
190
|
for (let i = 0; i < segments.length; i++) {
|
|
195
191
|
const candidate = segments.slice(0, i + 1).join("/");
|
|
196
|
-
const
|
|
197
|
-
const candidateIsDirectory = !isLast || isDirectory;
|
|
192
|
+
const candidateIsDirectory = i < segments.length - 1 || isDirectory;
|
|
198
193
|
|
|
199
194
|
if (directoryOnly && !candidateIsDirectory) continue;
|
|
200
195
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (regex.test(
|
|
196
|
+
// Match from any directory boundary.
|
|
197
|
+
const candidates = candidate.split("/");
|
|
198
|
+
|
|
199
|
+
for (let j = 0; j < candidates.length; j++) {
|
|
200
|
+
const subPath = candidates.slice(j).join("/");
|
|
201
|
+
|
|
202
|
+
if (regex.test(subPath)) {
|
|
208
203
|
matched = true;
|
|
209
204
|
break;
|
|
210
205
|
}
|
|
211
206
|
}
|
|
207
|
+
|
|
208
|
+
if (matched) break;
|
|
212
209
|
}
|
|
213
210
|
|
|
214
211
|
if (matched) {
|