deeplyzer 0.8.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/README.md +9 -1
- package/analysis/deep/generate/ganerateAgent.js +11 -9
- package/analysis/deep/orchestratorAgent.js +37 -33
- package/analysis/deep/runner/runnerAgent.js +215 -0
- package/engine.js +8 -8
- package/globals.js +1 -1
- package/package.json +2 -1
- package/prompts/deep.generate +445 -0
- package/prompts/deep.runner.assess.command +43 -0
- package/prompts/deep.runner.command +361 -0
- package/prompts/deep.runner.identify.runtime +365 -0
- package/prompts/deep.runner.runtime +160 -0
- package/prompts/graph.identify.runner +82 -0
- package/prompts/graph.source_exclusions +2 -0
- package/services/graphService.js +76 -22
- package/services/{environmentService.js → runnerIdentificationService.js} +17 -17
- package/session/sessionManager.js +1 -1
- package/utils/execUtil.js +115 -13
- package/utils/fileUtil.js +13 -24
- package/utils/logger.js +5 -5
- package/analysis/deep/env/environmentAgent.js +0 -125
- package/analysis/deep/plan/planAgent.js +0 -26
- package/prompts/deep.env.runtime +0 -45
- package/prompts/deep.generate.output +0 -31
- package/prompts/deep.plans +0 -153
- package/prompts/graph.environment +0 -154
- /package/prompts/{deep.env.assess → deep.runner.assess.runtime} +0 -0
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
|
|
|
@@ -5,15 +5,15 @@ const globals = require("../globals");
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
|
|
8
|
-
class
|
|
8
|
+
class RunnerIdentificationService {
|
|
9
9
|
static baseDir = path.join(process.cwd(), ".deeplyzer");
|
|
10
|
-
static
|
|
10
|
+
static runnersFile = path.join(RunnerIdentificationService.baseDir, "runners.json");
|
|
11
11
|
|
|
12
12
|
constructor() {
|
|
13
13
|
this.llm = new LLM(globals.config.llm);
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
async
|
|
16
|
+
async identify() {
|
|
17
17
|
const files = globals.graphs.map(graph => graph.file).filter(Boolean);
|
|
18
18
|
let openPackageDefinitions = this._readOpenPackageDefinitions();
|
|
19
19
|
openPackageDefinitions = JSON.parse(openPackageDefinitions);
|
|
@@ -21,17 +21,17 @@ class EnvironmentService {
|
|
|
21
21
|
|
|
22
22
|
const definitions = openPackageDefinitions.map(item => ({ name: item.name, description: item.description }));
|
|
23
23
|
|
|
24
|
-
let prompt = PromptsUtil.read("graph.
|
|
24
|
+
let prompt = PromptsUtil.read("graph.identify.runner");
|
|
25
25
|
prompt = prompt.replaceAll("***FILES***", JSON.stringify(files));
|
|
26
26
|
prompt = prompt.replaceAll("***WORKFLOW_RUNNERS***", JSON.stringify(definitions));
|
|
27
|
-
Logger.detailed("
|
|
27
|
+
Logger.detailed("Identify Runners Prompt: " + prompt);
|
|
28
28
|
|
|
29
29
|
const response = await this.llm.generate({ prompt: prompt, json: true });
|
|
30
|
-
Logger.detailed("
|
|
30
|
+
Logger.detailed("Identify Runners: " + JSON.stringify(response));
|
|
31
31
|
|
|
32
|
-
this.
|
|
32
|
+
this._saveRunners(response.runners);
|
|
33
33
|
|
|
34
|
-
return response.
|
|
34
|
+
return response.runners;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
_readOpenPackageDefinitions() {
|
|
@@ -41,30 +41,30 @@ class EnvironmentService {
|
|
|
41
41
|
return content;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
if (!fs.existsSync(
|
|
44
|
+
loadRunners() {
|
|
45
|
+
if (!fs.existsSync(RunnerIdentificationService.runnersFile)) {
|
|
46
46
|
return [];
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
try {
|
|
50
50
|
return JSON.parse(
|
|
51
|
-
fs.readFileSync(
|
|
51
|
+
fs.readFileSync(RunnerIdentificationService.runnersFile, "utf8")
|
|
52
52
|
);
|
|
53
53
|
} catch (error) {
|
|
54
|
-
throw new Error(`Failed to load
|
|
54
|
+
throw new Error(`Failed to load runners: ${error.message}`);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
fs.mkdirSync(
|
|
58
|
+
_saveRunners(runners) {
|
|
59
|
+
fs.mkdirSync(RunnerIdentificationService.baseDir, { recursive: true });
|
|
60
60
|
|
|
61
61
|
fs.writeFileSync(
|
|
62
|
-
|
|
63
|
-
JSON.stringify(
|
|
62
|
+
RunnerIdentificationService.runnersFile,
|
|
63
|
+
JSON.stringify(runners, null, 4),
|
|
64
64
|
"utf8"
|
|
65
65
|
);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
module.exports =
|
|
70
|
+
module.exports = RunnerIdentificationService;
|
|
@@ -16,7 +16,7 @@ class SessionManager {
|
|
|
16
16
|
BUILD_NODES: "build_nodes",
|
|
17
17
|
CONNECT_EDGES: "connect_edges",
|
|
18
18
|
BUILD_WORKFLOWS: "build_workflows",
|
|
19
|
-
DEFINE_ENVIRONMENTS: "
|
|
19
|
+
DEFINE_ENVIRONMENTS: "identify_runners",
|
|
20
20
|
STATIC_ANALYSIS: "static_analysis",
|
|
21
21
|
DEEP_ANALYSIS: "deep_analysis",
|
|
22
22
|
};
|
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
|
@@ -18,10 +18,6 @@ class FileUtil {
|
|
|
18
18
|
|
|
19
19
|
fs.mkdirSync(root, { recursive: true });
|
|
20
20
|
|
|
21
|
-
if (!Array.isArray(files)) {
|
|
22
|
-
files = [files];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
21
|
const savedFiles = [];
|
|
26
22
|
|
|
27
23
|
for (const file of files) {
|
|
@@ -31,10 +27,6 @@ class FileUtil {
|
|
|
31
27
|
|
|
32
28
|
const filename = path.basename(file.filename);
|
|
33
29
|
|
|
34
|
-
if (filename !== file.filename || !filename.endsWith(".py")) {
|
|
35
|
-
throw new Error(`Invalid filename: ${file.filename}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
30
|
let destination = path.resolve(root, filename);
|
|
39
31
|
|
|
40
32
|
try {
|
|
@@ -169,17 +161,15 @@ class FileUtil {
|
|
|
169
161
|
}
|
|
170
162
|
|
|
171
163
|
_matchesExclusion(relativePath, isDirectory, exclusions = []) {
|
|
172
|
-
const normalizedPath = relativePath
|
|
173
|
-
.split(path.sep)
|
|
174
|
-
.join("/");
|
|
175
|
-
|
|
164
|
+
const normalizedPath = relativePath.replace(/\\/g, "/");
|
|
176
165
|
const segments = normalizedPath.split("/");
|
|
166
|
+
|
|
177
167
|
let excluded = false;
|
|
178
168
|
|
|
179
169
|
for (let pattern of exclusions) {
|
|
180
170
|
if (!pattern || pattern.startsWith("#")) continue;
|
|
181
171
|
|
|
182
|
-
|
|
172
|
+
const negate = pattern.startsWith("!");
|
|
183
173
|
|
|
184
174
|
if (negate) {
|
|
185
175
|
pattern = pattern.substring(1);
|
|
@@ -194,29 +184,28 @@ class FileUtil {
|
|
|
194
184
|
|
|
195
185
|
if (!pattern) continue;
|
|
196
186
|
|
|
197
|
-
const hasSlash = pattern.includes("/");
|
|
198
187
|
const regex = this._globToRegex(pattern);
|
|
199
|
-
|
|
200
188
|
let matched = false;
|
|
201
189
|
|
|
202
190
|
for (let i = 0; i < segments.length; i++) {
|
|
203
191
|
const candidate = segments.slice(0, i + 1).join("/");
|
|
204
|
-
const
|
|
205
|
-
const candidateIsDirectory = !isLast || isDirectory;
|
|
192
|
+
const candidateIsDirectory = i < segments.length - 1 || isDirectory;
|
|
206
193
|
|
|
207
194
|
if (directoryOnly && !candidateIsDirectory) continue;
|
|
208
195
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
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)) {
|
|
216
203
|
matched = true;
|
|
217
204
|
break;
|
|
218
205
|
}
|
|
219
206
|
}
|
|
207
|
+
|
|
208
|
+
if (matched) break;
|
|
220
209
|
}
|
|
221
210
|
|
|
222
211
|
if (matched) {
|
package/utils/logger.js
CHANGED
|
@@ -19,9 +19,9 @@ class Logger {
|
|
|
19
19
|
|
|
20
20
|
if (!this.logPath) return;
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const logLevel = globals.log_level;
|
|
23
23
|
|
|
24
|
-
this.currentLevel = Logger.LEVELS[
|
|
24
|
+
this.currentLevel = Logger.LEVELS[logLevel] ?? Logger.LEVELS.DETAILED;
|
|
25
25
|
|
|
26
26
|
fs.mkdirSync(this.logPath, { recursive: true });
|
|
27
27
|
}
|
|
@@ -41,9 +41,9 @@ class Logger {
|
|
|
41
41
|
static _write(level, message) {
|
|
42
42
|
if (Logger.LEVELS[level] > this.currentLevel) return;
|
|
43
43
|
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
const formattedMessage = typeof message === 'string' ? message : JSON.stringify(message);
|
|
45
|
+
|
|
46
|
+
const logLine = `[${new Date().toISOString()}] [${level}] ${formattedMessage}`;
|
|
47
47
|
|
|
48
48
|
// Console logging (DETAILED is suppressed)
|
|
49
49
|
switch (level) {
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
const LLM = require('../../../llm/llm');
|
|
2
|
-
const PromptsUtil = require('../../../utils/promptsUtil');
|
|
3
|
-
const Logger = require('../../../utils/logger');
|
|
4
|
-
const globals = require('../../../globals');
|
|
5
|
-
const execUtil = require('../../../utils/execUtil');
|
|
6
|
-
|
|
7
|
-
class EnvironmentAgent {
|
|
8
|
-
constructor() {
|
|
9
|
-
this.existingEnvironments = [];
|
|
10
|
-
|
|
11
|
-
this.llm = new LLM(globals.config.llm);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
async setup(workflow) {
|
|
15
|
-
const environment = this._findEnvironment(workflow);
|
|
16
|
-
|
|
17
|
-
if (!this.existingEnvironments.includes(environment.name)) {
|
|
18
|
-
let results = [];
|
|
19
|
-
|
|
20
|
-
// install runtime
|
|
21
|
-
for (let attempts = 0; attempts < 3; attempts++) {
|
|
22
|
-
results = await this._setupRuntime(environment.runtime, results);
|
|
23
|
-
const assessment = await this._assessResults(environment.runtime, results);
|
|
24
|
-
|
|
25
|
-
if (assessment) {
|
|
26
|
-
this.existingEnvironments.push(environment.name);
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// install open package if required for the environment
|
|
32
|
-
const workflowRunnerPackage = globals.openPackages.find(item => item.name === environment.workflowRunner);
|
|
33
|
-
if (workflowRunnerPackage) {
|
|
34
|
-
results = await this._setupOpenPackage(workflowRunnerPackage.name, workflowRunnerPackage.installations);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const complete = this.existingEnvironments.includes(environment.name);
|
|
39
|
-
|
|
40
|
-
return {
|
|
41
|
-
complete: complete,
|
|
42
|
-
environment: environment
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async _setupOpenPackage(packageName, installations) {
|
|
47
|
-
const results = [];
|
|
48
|
-
|
|
49
|
-
const installResult = await execUtil.installPackage(packageName);
|
|
50
|
-
results.push(installResult);
|
|
51
|
-
|
|
52
|
-
if (installResult.success) {
|
|
53
|
-
const loadResult = await execUtil.loadPackage(packageName);
|
|
54
|
-
results.push(loadResult);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if(installations && installations.length > 0) {
|
|
58
|
-
for(const installation of installations) {
|
|
59
|
-
await execUtil.exec(installation);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return results;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async _setupRuntime(runtimeDetails, existingResults) {
|
|
67
|
-
let prompt = PromptsUtil.read("deep.env.runtime");
|
|
68
|
-
prompt = prompt.replaceAll("***RUNTIME_DETAILS***", runtimeDetails);
|
|
69
|
-
prompt = prompt.replaceAll("***OS***", process.platform);
|
|
70
|
-
prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(existingResults ?? "NONE"));
|
|
71
|
-
Logger.detailed("Setup runtime details: " + prompt);
|
|
72
|
-
|
|
73
|
-
const response = await this.llm.generate({ prompt: prompt, json: true });
|
|
74
|
-
Logger.detailed("Commands Generated: " + JSON.stringify(response));
|
|
75
|
-
|
|
76
|
-
const results = [];
|
|
77
|
-
for(const command of response.commands) {
|
|
78
|
-
const result = await execUtil.exec(command);
|
|
79
|
-
|
|
80
|
-
results.push(result);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return results;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async _assessResults(runtimeDetails, results) {
|
|
87
|
-
let prompt = PromptsUtil.read("deep.env.assess");
|
|
88
|
-
prompt = prompt.replaceAll("***RUNTIME_DETAILS***", runtimeDetails);
|
|
89
|
-
prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(results ?? "NONE"));
|
|
90
|
-
Logger.detailed("Setup runtime details: " + prompt);
|
|
91
|
-
|
|
92
|
-
const response = await this.llm.generate({ prompt: prompt, text: true });
|
|
93
|
-
Logger.detailed("Setup Exit: " + response);
|
|
94
|
-
|
|
95
|
-
return String(response || "").trim().toUpperCase() === "TRUE";
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
_findEnvironment(workflow) {
|
|
99
|
-
// 1. Collect node IDs
|
|
100
|
-
const nodeIds = new Set([
|
|
101
|
-
workflow.node,
|
|
102
|
-
...(workflow.childNodes || [])
|
|
103
|
-
]);
|
|
104
|
-
|
|
105
|
-
// 2. Map node IDs to source files
|
|
106
|
-
const sourceFiles = new Set();
|
|
107
|
-
|
|
108
|
-
for (const graph of globals.graphs || []) {
|
|
109
|
-
const nodes = graph.graph?.nodes || [];
|
|
110
|
-
|
|
111
|
-
if (nodes.some(node => nodeIds.has(node.id))) {
|
|
112
|
-
if (graph.file?.file) {
|
|
113
|
-
sourceFiles.add(graph.file.file);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 3. Find matching environments
|
|
119
|
-
return (globals.environments || []).find(environment =>
|
|
120
|
-
(environment.files || []).some(file => sourceFiles.has(file))
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
module.exports = EnvironmentAgent;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const LLM = require('../../../llm/llm');
|
|
2
|
-
const PromptsUtil = require('../../../utils/promptsUtil');
|
|
3
|
-
const Logger = require('../../../utils/logger');
|
|
4
|
-
const globals = require("../../../globals");
|
|
5
|
-
|
|
6
|
-
class PlanAgent {
|
|
7
|
-
constructor() {
|
|
8
|
-
this.llm = new LLM(globals.config.llm);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
async plan(src, runtime) {
|
|
12
|
-
// prompt for prompt, sequence, formatted output
|
|
13
|
-
let prompt = PromptsUtil.read("deep.plans");
|
|
14
|
-
prompt = prompt.replaceAll("***SOURCE***", src);
|
|
15
|
-
prompt = prompt.replaceAll("***OS***", process.platform);
|
|
16
|
-
prompt = prompt.replaceAll("***RUNTIME***", runtime);
|
|
17
|
-
Logger.detailed("Generated Plans Prompt: " + prompt);
|
|
18
|
-
|
|
19
|
-
const response = await this.llm.generate({ prompt: prompt, json: true });
|
|
20
|
-
Logger.detailed("Generated Plans: " + JSON.stringify(response));
|
|
21
|
-
|
|
22
|
-
return response.plans;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = PlanAgent;
|