deeplyzer 0.8.0 → 0.9.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);
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);
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
 
@@ -0,0 +1,170 @@
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 RunnerAgent {
8
+ constructor() {
9
+ this.llm = new LLM(globals.config.llm);
10
+ }
11
+
12
+ findRunner(workflow) {
13
+ // 1. Collect node IDs
14
+ const nodeIds = new Set([
15
+ workflow.node,
16
+ ...(workflow.childNodes || [])
17
+ ]);
18
+
19
+ // 2. Map node IDs to source files
20
+ const sourceFiles = new Set();
21
+
22
+ for (const graph of globals.graphs || []) {
23
+ const nodes = graph.graph?.nodes || [];
24
+
25
+ if (nodes.some(node => nodeIds.has(node.id))) {
26
+ if (graph.file?.file) {
27
+ sourceFiles.add(graph.file.file);
28
+ }
29
+ }
30
+ }
31
+
32
+ // 3. Find matching runners
33
+ return (globals.runners || []).find(runner =>
34
+ (runner.files || []).some(file => sourceFiles.has(file))
35
+ );
36
+ }
37
+
38
+ async setupRuntime(generateResult) {
39
+ // install runtime
40
+ let results = [], complete = false;
41
+
42
+ for (let attempts = 0; attempts < 3; attempts++) {
43
+ results = await this._setupRuntime(generateResult.runtimeCommands, results);
44
+ const assessment = await this._assessSetupRuntimeResults(generateResult.runtimeCommands, results);
45
+
46
+ if (assessment) { complete = true; break; }
47
+ }
48
+
49
+ /*// install open package if required for the runner
50
+ const workflowRunnerPackage = globals.openPackages.find(item => item.name === runner.workflowRunner);
51
+ if (workflowRunnerPackage) {
52
+ results = await this._setupOpenPackage(workflowRunnerPackage.name, workflowRunnerPackage.installations);
53
+ }*/
54
+
55
+ return { complete: complete }
56
+ }
57
+
58
+ async execCommand(command, id) {
59
+ let result = null, results = [], complete = false;
60
+ let cmd = command;
61
+
62
+ Logger.detailed("Initiating command execution: " + command);
63
+
64
+ for (let attempts = 0; attempts < 5; attempts++) {
65
+ if (results.length > 0) {
66
+ let prompt = PromptsUtil.read("deep.runner.command");
67
+
68
+ const executionHistory = results.map((item, index) => {
69
+ return `COMMAND ${index + 1}: ${item.command}
70
+ RESULT ${index + 1}:
71
+ ${JSON.stringify(item.result)}`;
72
+ }).join("\n\n");
73
+
74
+ prompt = prompt.replaceAll("***COMMAND***", JSON.stringify(cmd));
75
+ prompt = prompt.replaceAll("***OS***", process.platform);
76
+ prompt = prompt.replaceAll("***RESULT***", executionHistory);
77
+ Logger.detailed("Exec command details: " + prompt);
78
+
79
+ const response = await this.llm.generate({ prompt: prompt, json: true });
80
+ Logger.detailed("Command Generated: " + JSON.stringify(response));
81
+
82
+ cmd = response.command;
83
+ }
84
+
85
+ result = await execUtil.exec(cmd, id);
86
+ results.push({
87
+ command: cmd,
88
+ result: result
89
+ });
90
+
91
+ const assessment = await this._assessExecCommandResults(cmd, result);
92
+
93
+ if (assessment) { complete = true; break; }
94
+ }
95
+
96
+ return { complete: complete }
97
+ }
98
+
99
+ async _setupOpenPackage(packageName, installations) {
100
+ const results = [];
101
+
102
+ const installResult = await execUtil.installPackage(packageName);
103
+ results.push(installResult);
104
+
105
+ if (installResult.success) {
106
+ const loadResult = await execUtil.loadPackage(packageName);
107
+ results.push(loadResult);
108
+ }
109
+
110
+ if(installations && installations.length > 0) {
111
+ for(const installation of installations) {
112
+ await execUtil.exec(installation);
113
+ }
114
+ }
115
+
116
+ return results;
117
+ }
118
+
119
+ async _setupRuntime(runtimeCommands, existingResults) {
120
+ let commands = runtimeCommands;
121
+
122
+ if (existingResults.length > 0) {
123
+ let prompt = PromptsUtil.read("deep.runner.runtime");
124
+ prompt = prompt.replaceAll("***RUNTIME_DETAILS***", JSON.stringify(runtimeCommands));
125
+ prompt = prompt.replaceAll("***OS***", process.platform);
126
+ prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(existingResults ?? "NONE"));
127
+ Logger.detailed("Setup runtime details: " + prompt);
128
+
129
+ const response = await this.llm.generate({ prompt: prompt, json: true });
130
+ Logger.detailed("Commands Generated: " + JSON.stringify(response));
131
+
132
+ commands = response.commands;
133
+ }
134
+
135
+ const results = [];
136
+ for(const command of commands) {
137
+ const result = await execUtil.exec(command);
138
+
139
+ results.push(result);
140
+ }
141
+
142
+ return results;
143
+ }
144
+
145
+ async _assessSetupRuntimeResults(runtimeDetails, results) {
146
+ let prompt = PromptsUtil.read("deep.runner.assess.runtime");
147
+ prompt = prompt.replaceAll("***RUNTIME_DETAILS***", runtimeDetails);
148
+ prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(results ?? "NONE"));
149
+ Logger.detailed("Assess runtime setup details: " + prompt);
150
+
151
+ const response = await this.llm.generate({ prompt: prompt, text: true });
152
+ Logger.detailed("Setup Exit: " + response);
153
+
154
+ return String(response || "").trim().toUpperCase() === "TRUE";
155
+ }
156
+
157
+ async _assessExecCommandResults(command, results) {
158
+ let prompt = PromptsUtil.read("deep.runner.assess.command");
159
+ prompt = prompt.replaceAll("***COMMAND***", command);
160
+ prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(results ?? "NONE"));
161
+ Logger.detailed("Assess run command details: " + prompt);
162
+
163
+ const response = await this.llm.generate({ prompt: prompt, text: true });
164
+ Logger.detailed("Exec Exit: " + response);
165
+
166
+ return String(response || "").trim().toUpperCase() === "TRUE";
167
+ }
168
+ }
169
+
170
+ 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.9.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",