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 CHANGED
@@ -69,10 +69,18 @@ Deeplyzer goes further. It understands how the application works, investigates t
69
69
 
70
70
  ## Installation
71
71
 
72
- Install Deeplyzer using npm:
72
+ Install deeplyzer locally and run it:
73
73
 
74
74
  ```bash
75
75
  npm install deeplyzer
76
+ npx deeplyzer <configfile>
77
+ ```
78
+
79
+ Install deeplyzer globally and run it:
80
+
81
+ ```bash
82
+ npm install -g deeplyzer
83
+ deeplyzer <configfile>
76
84
  ```
77
85
 
78
86
  ## Command Line Usage
@@ -10,20 +10,22 @@ class GenerateAgent {
10
10
  this.fileUtil = new FileUtil();
11
11
  }
12
12
 
13
- async generate(generatePrompt, src, id) {
14
- let outputPrompt = PromptsUtil.read("deep.generate.output");
15
- outputPrompt = outputPrompt.replaceAll("***SOURCE***", src);
16
- outputPrompt = outputPrompt.replaceAll("***OS***", process.platform);
13
+ async generate(src, id) {
14
+ let prompt = PromptsUtil.read("deep.generate");
15
+ prompt = prompt.replaceAll("***SOURCE***", src);
16
+ prompt = prompt.replaceAll("***OS***", process.platform);
17
17
 
18
- const prompt = generatePrompt + "\n\n" + outputPrompt;
19
18
  Logger.detailed("Generate Agent Internal Prompt: " + prompt);
20
19
 
21
- let files = await this.llm.generate({ prompt: prompt, json: true });
22
- Logger.detailed("Generate Agent Internal Response: " + JSON.stringify(files));
20
+ let response = await this.llm.generate({ prompt: prompt, json: true });
21
+ Logger.detailed("Generate Agent Internal Response: " + JSON.stringify(response));
23
22
 
24
- files = Array.isArray(files) ? files : [files];
23
+ this.fileUtil.saveCodeFiles(response.files, id);
25
24
 
26
- this.fileUtil.saveCodeFiles(files, id);
25
+ return {
26
+ runtimeCommands: response.runtimeCommands,
27
+ execCommands: response.execCommands,
28
+ };
27
29
  }
28
30
  }
29
31
 
@@ -5,15 +5,13 @@ const globals = require('../../globals');
5
5
  const execUtil = require('../../utils/execUtil');
6
6
 
7
7
  // agents
8
- const EnvironmentAgent = require('./env/environmentAgent');
9
- const PlanAgent = require('./plan/planAgent');
8
+ const RunnerAgent = require('./runner/runnerAgent');
10
9
  const GenerateAgent = require('./generate/ganerateAgent');
11
10
  const AssessAgent = require('./assess/assessAgent');
12
11
 
13
12
  class OrchestratorAgent {
14
13
  constructor() {
15
- this.environmentAgent = new EnvironmentAgent();
16
- this.planAgent = new PlanAgent();
14
+ this.runnerAgent = new RunnerAgent();
17
15
  this.generateAgent = new GenerateAgent();
18
16
  this.assessAgent = new AssessAgent();
19
17
  }
@@ -22,40 +20,35 @@ class OrchestratorAgent {
22
20
  Logger.essential("Starting deep analysis orchestrator agent");
23
21
 
24
22
  for(const workflow of workflows) {
25
- const setup = await this.environmentAgent.setup(workflow);
26
- if (!setup.complete) {
27
- Logger.error(`Setup of required environment for workflow: ${workflow.name} failed.`);
28
- continue;
29
- }
23
+ const runner = this.runnerAgent.findRunner(workflow);
30
24
 
31
- if(setup.environment.workflowRunner == "dynamic") {
32
- await this._runDynamicWorkflow(workflow, setup.environment);
25
+ if(runner.workflowRunner == "dynamic") {
26
+ await this._runDynamicWorkflow(workflow);
33
27
  } else {
34
- await this._runOpenPackageWorkflow(workflow, setup.environment);
28
+ await this._runOpenPackageWorkflow(workflow, runner);
35
29
  }
36
30
  }
37
31
  }
38
32
 
39
- async _runDynamicWorkflow(workflow, environment) {
33
+ async _runDynamicWorkflow(workflow) {
40
34
  let results = [];
41
35
 
42
- // PLAN
43
- let plans = await this.planAgent.plan(workflow.src, environment.runtime);
36
+ const id = IdUtil.generate();
44
37
 
45
- for (const plan of plans) {
46
- const id = IdUtil.generate();
38
+ // GENERATE
39
+ const generateResult = await this.generateAgent.generate(workflow.src, id);
47
40
 
48
- // GENERATE
49
- if (plan.prompt && plan.prompt != "") {
50
- await this.generateAgent.generate(plan.prompt, workflow.src, id);
51
- }
41
+ const setup = await this.runnerAgent.setupRuntime(generateResult.runtimeCommands);
42
+ if (!setup.complete) {
43
+ Logger.error(`Setup of runtime for workflow: ${workflow.id} failed.`);
44
+ return;
45
+ }
52
46
 
53
- // EXECUTE
54
- if (plan.commands && plan.commands.length > 0) {
55
- for (const command of plan.commands) {
56
- const result = await execUtil.exec(command, id);
57
- results.push(result);
58
- }
47
+ // EXECUTE
48
+ if (generateResult.execCommands && generateResult.execCommands.length > 0) {
49
+ for (const command of generateResult.execCommands) {
50
+ const result = await this.runnerAgent.execCommand(command, id);
51
+ results.push(result);
59
52
  }
60
53
  }
61
54
 
@@ -65,15 +58,26 @@ class OrchestratorAgent {
65
58
  return assessments;
66
59
  }
67
60
 
68
- async _runOpenPackageWorkflow(workflow, environment) {
69
- // run commands
70
- for(const command of environment.commands) {
71
- await execUtil.exec(command);
61
+ async _runOpenPackageWorkflow(workflow, runner) {
62
+ // Step 1: setup runtime, run servers
63
+ const commands = await this.runnerAgent.identifyRuntime(runner);
64
+ const setup = await this.runnerAgent.setupRuntime(commands.runtimeCommands);
65
+ if (!setup.complete) {
66
+ Logger.error(`Setup of runtime for workflow: ${workflow.id} failed.`);
67
+ return;
72
68
  }
73
69
 
74
- // workflow runner
75
- const workflowRunnerPackage = globals.openPackages.find(item => item.name === environment.workflowRunner);
70
+ if (commands.execCommands.length > 0) {
71
+ for (const command of commands.execCommands) {
72
+ const result = await this.runnerAgent.execCommand(command, "", commands.execCommands);
73
+ }
74
+ }
75
+
76
+ // Step 2: open package installation, execution
77
+ const workflowRunnerPackage = globals.openPackages.find(item => item.name === runner.workflowRunner);
76
78
  if (workflowRunnerPackage) {
79
+ await this.setupOpenPackage(workflowRunnerPackage.name, workflowRunnerPackage.installations);
80
+
77
81
  const result = await execUtil.createInstance(workflowRunnerPackage.name, workflowRunnerPackage.initClass);
78
82
  const instance = result.instance;
79
83
 
@@ -0,0 +1,215 @@
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
+ const os = require("os");
7
+
8
+ class RunnerAgent {
9
+ constructor() {
10
+ this.llm = new LLM(globals.config.llm);
11
+ }
12
+
13
+ findRunner(workflow) {
14
+ // 1. Collect node IDs
15
+ const nodeIds = new Set([
16
+ workflow.node,
17
+ ...(workflow.childNodes || [])
18
+ ]);
19
+
20
+ // 2. Map node IDs to source files
21
+ const sourceFiles = new Set();
22
+
23
+ for (const graph of globals.graphs || []) {
24
+ const nodes = graph.graph?.nodes || [];
25
+
26
+ if (nodes.some(node => nodeIds.has(node.id))) {
27
+ if (graph.file?.file) {
28
+ sourceFiles.add(graph.file.file);
29
+ }
30
+ }
31
+ }
32
+
33
+ // 3. Find matching runners
34
+ return (globals.runners || []).find(runner =>
35
+ (runner.files || []).some(file => sourceFiles.has(file))
36
+ );
37
+ }
38
+
39
+ async identifyRuntime(runner) {
40
+ const files = this._getWorkflowFilePaths(runner.files);
41
+
42
+ let prompt = PromptsUtil.read("deep.runner.identify.runtime");
43
+ prompt = prompt.replaceAll("***FILES***", JSON.stringify(files));
44
+ prompt = prompt.replaceAll("***SHELL***", this._detectShell());
45
+ Logger.detailed("Identify runtime details: " + prompt);
46
+
47
+ const response = await this.llm.generate({ prompt: prompt, json: true });
48
+ Logger.detailed("Commands Generated: " + JSON.stringify(response));
49
+
50
+ return response.commands;
51
+ }
52
+
53
+ async setupRuntime(runtimeCommands) {
54
+ // install runtime
55
+ let results = [], complete = false;
56
+
57
+ for (let attempts = 0; attempts < 3; attempts++) {
58
+ results = await this._setupRuntime(runtimeCommands, results);
59
+ const assessment = await this._assessSetupRuntimeResults(runtimeCommands, results);
60
+
61
+ if (assessment) { complete = true; break; }
62
+ }
63
+
64
+ return { complete: complete }
65
+ }
66
+
67
+ async execCommand(command, id, allCommands) {
68
+ let result = null, results = [], complete = false;
69
+ let cmd = typeof command === "string" ? { detached: false, cmd: command } : command;
70
+ let cmds = [cmd];
71
+
72
+ Logger.detailed("Initiating command execution: " + command);
73
+
74
+ for (let attempts = 0; attempts < 5; attempts++) {
75
+ if (results.length > 0) {
76
+ let prompt = PromptsUtil.read("deep.runner.command");
77
+
78
+ let executionHistory = results.map((item, index) => {
79
+ return `COMMAND ${index + 1}: ${
80
+ typeof item.command === "object" && item.command !== null
81
+ ? JSON.stringify(item.command) : item.command ?? "NOT_AVAILABLE"
82
+ }
83
+ RESULT ${index + 1}: ${JSON.stringify(item.result)}`;}).join("\n\n");
84
+
85
+ prompt = prompt.replaceAll("***INITIAL_COMMANDS***", allCommands == null ? "NOT_AVAILABLE" : JSON.stringify(allCommands));
86
+ prompt = prompt.replaceAll("***COMMAND***", JSON.stringify(cmds));
87
+ prompt = prompt.replaceAll("***OS***", process.platform);
88
+ prompt = prompt.replaceAll("***SHELL***", this._detectShell());
89
+ prompt = prompt.replaceAll("***RESULT***", executionHistory);
90
+ Logger.detailed("Exec command details: " + prompt);
91
+
92
+ const response = await this.llm.generate({ prompt: prompt, json: true });
93
+ Logger.detailed("Command Generated: " + JSON.stringify(response));
94
+
95
+ cmds = response.commands;
96
+ }
97
+
98
+ for(const cmd of cmds) {
99
+ result = await execUtil.exec(cmd.cmd, id, cmd.detached);
100
+ results.push({ command: cmd, result: result });
101
+ }
102
+
103
+ const assessment = await this._assessExecCommandResults(cmds, result);
104
+
105
+ if (assessment) { complete = true; break; }
106
+ }
107
+
108
+ return { complete: complete }
109
+ }
110
+
111
+ async setupOpenPackage(packageName, installations) {
112
+ const results = [];
113
+
114
+ const installResult = await execUtil.installPackage(packageName);
115
+ results.push(installResult);
116
+
117
+ if (installResult.success) {
118
+ const loadResult = await execUtil.loadPackage(packageName);
119
+ results.push(loadResult);
120
+ }
121
+
122
+ if(installations && installations.length > 0) {
123
+ for(const installation of installations) {
124
+ await execUtil.exec(installation);
125
+ }
126
+ }
127
+
128
+ return results;
129
+ }
130
+
131
+ async _setupRuntime(runtimeCommands, existingResults) {
132
+ let commands = runtimeCommands;
133
+
134
+ if (existingResults.length > 0) {
135
+ let prompt = PromptsUtil.read("deep.runner.runtime");
136
+ prompt = prompt.replaceAll("***RUNTIME_DETAILS***", JSON.stringify(runtimeCommands));
137
+ prompt = prompt.replaceAll("***OS***", process.platform);
138
+ prompt = prompt.replaceAll("***SHELL***", this._detectShell());
139
+ prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(existingResults ?? "NONE"));
140
+ Logger.detailed("Setup runtime details: " + prompt);
141
+
142
+ const response = await this.llm.generate({ prompt: prompt, json: true });
143
+ Logger.detailed("Commands Generated: " + JSON.stringify(response));
144
+
145
+ commands = response.commands;
146
+ }
147
+
148
+ const results = [];
149
+ for(const command of commands) {
150
+ const result = await execUtil.exec(command);
151
+
152
+ results.push(result);
153
+ }
154
+
155
+ return results;
156
+ }
157
+
158
+ async _assessSetupRuntimeResults(runtimeDetails, results) {
159
+ let prompt = PromptsUtil.read("deep.runner.assess.runtime");
160
+ prompt = prompt.replaceAll("***RUNTIME_DETAILS***", runtimeDetails);
161
+ prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(results ?? "NONE"));
162
+ Logger.detailed("Assess runtime setup details: " + prompt);
163
+
164
+ const response = await this.llm.generate({ prompt: prompt, text: true });
165
+ Logger.detailed("Setup Exit: " + response);
166
+
167
+ return String(response || "").trim().toUpperCase() === "TRUE";
168
+ }
169
+
170
+ async _assessExecCommandResults(commands, results) {
171
+ let prompt = PromptsUtil.read("deep.runner.assess.command");
172
+ prompt = prompt.replaceAll("***COMMAND***", JSON.stringify(commands));
173
+ prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(results ?? "NONE"));
174
+ Logger.detailed("Assess run command details: " + prompt);
175
+
176
+ const response = await this.llm.generate({ prompt: prompt, text: true });
177
+ Logger.detailed("Exec Exit: " + response);
178
+
179
+ return String(response || "").trim().toUpperCase() === "TRUE";
180
+ }
181
+
182
+ _getWorkflowFilePaths(files) {
183
+ const fileNames = new Set(files);
184
+
185
+ const sourcePaths = new Set();
186
+
187
+ for (const graph of globals.graphs || []) {
188
+ if (fileNames.has(graph.file?.file) && graph.file?.path) {
189
+ sourcePaths.add(graph.file.path);
190
+ }
191
+ }
192
+
193
+ return [...sourcePaths];
194
+ }
195
+
196
+ _detectShell() {
197
+ if (process.platform !== "win32") {
198
+ return process.env.SHELL || "bash";
199
+ }
200
+
201
+ // PowerShell sets this environment variable
202
+ if (process.env.PSModulePath) {
203
+ return "powershell";
204
+ }
205
+
206
+ // CMD normally exposes ComSpec pointing to cmd.exe
207
+ if (process.env.ComSpec?.toLowerCase().endsWith("\\cmd.exe")) {
208
+ return "cmd";
209
+ }
210
+
211
+ return "unknown";
212
+ }
213
+ }
214
+
215
+ module.exports = RunnerAgent;
package/engine.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const GraphService = require('./services/graphService');
2
2
  const WorkflowService = require('./services/workflowService');
3
- const EnvironmentService = require('./services/environmentService');
3
+ const RunnerIdentificationService = require('./services/runnerIdentificationService');
4
4
  const StaticAnalyzer = require('./analysis/static/staticAnalyzer');
5
5
  const OrchestratorAgent = require('./analysis/deep/orchestratorAgent');
6
6
 
@@ -12,7 +12,7 @@ class Engine {
12
12
  constructor() {
13
13
  this.graphService = new GraphService();
14
14
  this.workflowService = new WorkflowService();
15
- this.environmentService = new EnvironmentService();
15
+ this.runnerIdentificationService = new RunnerIdentificationService();
16
16
  this.staticAnalyzer = new StaticAnalyzer();
17
17
 
18
18
  this.orchestratorAgent = new OrchestratorAgent();
@@ -45,15 +45,15 @@ class Engine {
45
45
 
46
46
  this.workflowService.fillSources();
47
47
 
48
- // step 3: define environments
49
- if(SessionManager.checkStage("define_environments")) {
50
- globals.environments = await this.environmentService.define();
48
+ // step 3: identify runners
49
+ if(SessionManager.checkStage("identify_runners")) {
50
+ globals.runners = await this.runnerIdentificationService.identify();
51
51
 
52
- SessionManager.updateStage("define_environments");
52
+ SessionManager.updateStage("identify_runners");
53
53
  }
54
54
 
55
- if(!globals.environments) {
56
- globals.environments = this.environmentService.loadEnvironments();
55
+ if(!globals.runners) {
56
+ globals.runners = this.runnerIdentificationService.loadRunners();
57
57
  }
58
58
 
59
59
  // step 4: perform static code analysis
package/globals.js CHANGED
@@ -2,7 +2,7 @@ const globals = {
2
2
  config: {},
3
3
  graphs: [],
4
4
  workflows: null,
5
- environments: null,
5
+ runners: null,
6
6
  openPackages: []
7
7
  };
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deeplyzer",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Go beyond static code analysis. End-to-end intelligence across code, execution flows, databases, and cloud infrastructure.",
5
5
  "main": "index.js",
6
6
  "type": "commonjs",
@@ -27,6 +27,7 @@
27
27
  "license": "MIT",
28
28
  "dependencies": {
29
29
  "axios": "^1.21.1",
30
+ "cli-progress": "^3.12.0",
30
31
  "playwright": "^1.65.1"
31
32
  }
32
33
  }