deeplyzer 0.4.0 → 0.7.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/assess/assessAgent.js +24 -0
- package/analysis/deep/env/environmentAgent.js +125 -0
- package/analysis/deep/generate/ganerateAgent.js +30 -0
- package/analysis/deep/orchestratorAgent.js +94 -0
- package/analysis/deep/plan/planAgent.js +26 -0
- package/analysis/static/staticAnalyzer.js +86 -0
- package/engine.js +87 -0
- package/globals.js +9 -0
- package/img/logo.png +0 -0
- package/img/workflow.png +0 -0
- package/index.js +0 -0
- package/llm/llm.js +58 -0
- package/llm/providers/claude.js +65 -0
- package/llm/providers/gemini.js +66 -0
- package/llm/providers/openai.js +91 -0
- package/open-packages.json +11 -0
- package/package.json +11 -3
- package/prompts/deep.assess +85 -0
- package/prompts/deep.env.assess +11 -0
- package/prompts/deep.env.runtime +45 -0
- package/prompts/deep.generate.output +31 -0
- package/prompts/deep.plans +153 -0
- package/prompts/graph.build_nodes +577 -0
- package/prompts/graph.environment +154 -0
- package/prompts/graph.resolve_edges +44 -0
- package/prompts/graph.source_exclusions +47 -0
- package/prompts/static.analyse +58 -0
- package/services/environmentService.js +70 -0
- package/services/graphService.js +292 -0
- package/services/workflowService.js +168 -0
- package/session/sessionManager.js +130 -0
- package/utils/execUtil.js +153 -0
- package/utils/fileUtil.js +239 -0
- package/utils/idUtil.js +17 -0
- package/utils/logger.js +93 -0
- package/utils/promptsUtil.js +29 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const LLM = require('../../../llm/llm');
|
|
2
|
+
const PromptsUtil = require('../../../utils/promptsUtil');
|
|
3
|
+
const globals = require("../../../globals");
|
|
4
|
+
const Logger = require('../../../utils/logger');
|
|
5
|
+
|
|
6
|
+
class AssessAgent {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.llm = new LLM(globals.config.llm);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async assess(results) {
|
|
12
|
+
let prompt = PromptsUtil.read("deep.assess");
|
|
13
|
+
|
|
14
|
+
prompt = prompt.replaceAll("***RESULTS***", JSON.stringify(results));
|
|
15
|
+
//Logger.detailed(prompt);
|
|
16
|
+
|
|
17
|
+
const response = await this.llm.generate({ prompt: prompt, text: true });
|
|
18
|
+
Logger.detailed(response);
|
|
19
|
+
|
|
20
|
+
return response;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
module.exports = AssessAgent;
|
|
@@ -0,0 +1,125 @@
|
|
|
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;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const LLM = require('../../../llm/llm');
|
|
2
|
+
const globals = require('../../../globals');
|
|
3
|
+
const Logger = require('../../../utils/logger');
|
|
4
|
+
const FileUtil = require('../../../utils/fileUtil');
|
|
5
|
+
const PromptsUtil = require('../../../utils/promptsUtil');
|
|
6
|
+
|
|
7
|
+
class GenerateAgent {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.llm = new LLM(globals.config.llm);
|
|
10
|
+
this.fileUtil = new FileUtil();
|
|
11
|
+
}
|
|
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);
|
|
17
|
+
|
|
18
|
+
const prompt = generatePrompt + "\n\n" + outputPrompt;
|
|
19
|
+
Logger.detailed("Generate Agent Internal Prompt: " + prompt);
|
|
20
|
+
|
|
21
|
+
let files = await this.llm.generate({ prompt: prompt, json: true });
|
|
22
|
+
Logger.detailed("Generate Agent Internal Response: " + JSON.stringify(files));
|
|
23
|
+
|
|
24
|
+
files = Array.isArray(files) ? files : [files];
|
|
25
|
+
|
|
26
|
+
this.fileUtil.saveCodeFiles(files, id);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = GenerateAgent;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
const Logger = require('../../utils/logger');
|
|
2
|
+
const IdUtil = require('../../utils/idUtil');
|
|
3
|
+
const LLM = require('../../llm/llm');
|
|
4
|
+
const globals = require('../../globals');
|
|
5
|
+
const execUtil = require('../../utils/execUtil');
|
|
6
|
+
|
|
7
|
+
// agents
|
|
8
|
+
const EnvironmentAgent = require('./env/environmentAgent');
|
|
9
|
+
const PlanAgent = require('./plan/planAgent');
|
|
10
|
+
const GenerateAgent = require('./generate/ganerateAgent');
|
|
11
|
+
const AssessAgent = require('./assess/assessAgent');
|
|
12
|
+
|
|
13
|
+
class OrchestratorAgent {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.environmentAgent = new EnvironmentAgent();
|
|
16
|
+
this.planAgent = new PlanAgent();
|
|
17
|
+
this.generateAgent = new GenerateAgent();
|
|
18
|
+
this.assessAgent = new AssessAgent();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async start(workflows) {
|
|
22
|
+
Logger.essential("Starting deep analysis orchestrator agent");
|
|
23
|
+
|
|
24
|
+
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
|
+
}
|
|
30
|
+
|
|
31
|
+
if(setup.environment.workflowRunner == "dynamic") {
|
|
32
|
+
await this._runDynamicWorkflow(workflow, setup.environment);
|
|
33
|
+
} else {
|
|
34
|
+
await this._runOpenPackageWorkflow(workflow, setup.environment);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async _runDynamicWorkflow(workflow, environment) {
|
|
40
|
+
let results = [];
|
|
41
|
+
|
|
42
|
+
// PLAN
|
|
43
|
+
let plans = await this.planAgent.plan(workflow.src, environment.runtime);
|
|
44
|
+
|
|
45
|
+
for (const plan of plans) {
|
|
46
|
+
const id = IdUtil.generate();
|
|
47
|
+
|
|
48
|
+
// GENERATE
|
|
49
|
+
if (plan.prompt && plan.prompt != "") {
|
|
50
|
+
await this.generateAgent.generate(plan.prompt, workflow.src, id);
|
|
51
|
+
}
|
|
52
|
+
|
|
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
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ASSESS
|
|
63
|
+
const assessments = await this.assessAgent.assess(results);
|
|
64
|
+
|
|
65
|
+
return assessments;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async _runOpenPackageWorkflow(workflow, environment) {
|
|
69
|
+
// run commands
|
|
70
|
+
for(const command of environment.commands) {
|
|
71
|
+
await execUtil.exec(command);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// workflow runner
|
|
75
|
+
const workflowRunnerPackage = globals.openPackages.find(item => item.name === environment.workflowRunner);
|
|
76
|
+
if (workflowRunnerPackage) {
|
|
77
|
+
const result = await execUtil.createInstance(workflowRunnerPackage.name, workflowRunnerPackage.initClass);
|
|
78
|
+
const instance = result.instance;
|
|
79
|
+
|
|
80
|
+
instance.logger = Logger;
|
|
81
|
+
instance.llm = new LLM(globals.config.llm);
|
|
82
|
+
instance.src = workflow.src;
|
|
83
|
+
instance.url = "http://localhost:8080/"; // TODO
|
|
84
|
+
|
|
85
|
+
const conclusion = await instance.start();
|
|
86
|
+
|
|
87
|
+
return conclusion;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// TODO: STOP ALL PROCESSES
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
module.exports = OrchestratorAgent;
|
|
@@ -0,0 +1,26 @@
|
|
|
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;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
const FileUtil = require('../../utils/fileUtil');
|
|
2
|
+
const LLM = require("../../llm/llm");
|
|
3
|
+
const PromptsUtil = require('../../utils/promptsUtil');
|
|
4
|
+
const globals = require("../../globals");
|
|
5
|
+
const Logger = require('../../utils/logger');
|
|
6
|
+
|
|
7
|
+
class StaticAnalyzer {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.fileUtil = new FileUtil();
|
|
10
|
+
this.llm = new LLM(globals.config.llm);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async analyze(graphs, workflows) {
|
|
14
|
+
const results = [];
|
|
15
|
+
|
|
16
|
+
for (const workflow of workflows) {
|
|
17
|
+
const source = this._getWorkflowSource(graphs, workflow);
|
|
18
|
+
|
|
19
|
+
if (!source.trim()) continue;
|
|
20
|
+
|
|
21
|
+
let prompt = PromptsUtil.read("static.analyse");
|
|
22
|
+
prompt = prompt.replaceAll("***SOURCE_CODE***", source);
|
|
23
|
+
Logger.detailed(prompt);
|
|
24
|
+
|
|
25
|
+
const response = await this.llm.generate({ prompt: prompt });
|
|
26
|
+
|
|
27
|
+
results.push({
|
|
28
|
+
workflow: workflow.node,
|
|
29
|
+
analysis: response
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
_getWorkflowSource(graphs, workflow) {
|
|
37
|
+
const nodeIds = new Set([
|
|
38
|
+
workflow.node,
|
|
39
|
+
...(workflow.childNodes || [])
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
const sources = [];
|
|
43
|
+
|
|
44
|
+
for (const graph of graphs) {
|
|
45
|
+
const nodes = graph.graph?.nodes || [];
|
|
46
|
+
|
|
47
|
+
for (const node of nodes) {
|
|
48
|
+
if (!nodeIds.has(node.id)) continue;
|
|
49
|
+
|
|
50
|
+
const source = this._extractSource(graph, node);
|
|
51
|
+
|
|
52
|
+
if (!source) continue;
|
|
53
|
+
|
|
54
|
+
sources.push({
|
|
55
|
+
file: graph.file.path,
|
|
56
|
+
startLine: node.startLine,
|
|
57
|
+
endLine: node.endLine,
|
|
58
|
+
source
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return sources.map(item => {
|
|
64
|
+
return `
|
|
65
|
+
/**
|
|
66
|
+
* File: ${item.file}
|
|
67
|
+
* Lines: ${item.startLine}-${item.endLine}
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
${item.source}
|
|
71
|
+
`;
|
|
72
|
+
}).join("\n\n");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
_extractSource(graph, node) {
|
|
76
|
+
if (!node.startLine || !node.endLine || !graph.file?.content) {
|
|
77
|
+
return "";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const lines = graph.file.content.split(/\r?\n/);
|
|
81
|
+
|
|
82
|
+
return lines.slice(node.startLine - 1, node.endLine).join("\n");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = StaticAnalyzer;
|
package/engine.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
const GraphService = require('./services/graphService');
|
|
2
|
+
const WorkflowService = require('./services/workflowService');
|
|
3
|
+
const EnvironmentService = require('./services/environmentService');
|
|
4
|
+
const StaticAnalyzer = require('./analysis/static/staticAnalyzer');
|
|
5
|
+
const OrchestratorAgent = require('./analysis/deep/orchestratorAgent');
|
|
6
|
+
|
|
7
|
+
const Logger = require('./utils/logger');
|
|
8
|
+
const globals = require("./globals");
|
|
9
|
+
const SessionManager = require("./session/sessionManager");
|
|
10
|
+
|
|
11
|
+
class Engine {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.graphService = new GraphService();
|
|
14
|
+
this.workflowService = new WorkflowService();
|
|
15
|
+
this.environmentService = new EnvironmentService();
|
|
16
|
+
this.staticAnalyzer = new StaticAnalyzer();
|
|
17
|
+
|
|
18
|
+
this.orchestratorAgent = new OrchestratorAgent();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async run() {
|
|
22
|
+
try {
|
|
23
|
+
Logger.essential("[ENGINE] Starting Deeplyzer...");
|
|
24
|
+
SessionManager.updateState("in_progress");
|
|
25
|
+
|
|
26
|
+
// step 1: build graph
|
|
27
|
+
if (globals.config.build_graph ?? true) {
|
|
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
|
+
}
|
|
34
|
+
|
|
35
|
+
// step 2: build workflows
|
|
36
|
+
if(SessionManager.checkStage("build_workflows")) {
|
|
37
|
+
globals.workflows = this.workflowService.build();
|
|
38
|
+
|
|
39
|
+
SessionManager.updateStage("build_workflows");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if(!globals.workflows) {
|
|
43
|
+
globals.workflows = this.workflowService.loadWorkflows();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.workflowService.fillSources();
|
|
47
|
+
|
|
48
|
+
// step 3: define environments
|
|
49
|
+
if(SessionManager.checkStage("define_environments")) {
|
|
50
|
+
globals.environments = await this.environmentService.define();
|
|
51
|
+
|
|
52
|
+
SessionManager.updateStage("define_environments");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if(!globals.environments) {
|
|
56
|
+
globals.environments = this.environmentService.loadEnvironments();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// step 4: perform static code analysis
|
|
60
|
+
/*if (SessionManager.checkStage("static_analysis")) {
|
|
61
|
+
if (globals.config.static_analysis ?? true) {
|
|
62
|
+
await this.staticAnalyzer.analyze(graphs, workflows);
|
|
63
|
+
|
|
64
|
+
SessionManager.updateStage("static_analysis");
|
|
65
|
+
}
|
|
66
|
+
}*/
|
|
67
|
+
|
|
68
|
+
// step 4: perform deep code analysis
|
|
69
|
+
if (SessionManager.checkStage("deep_analysis")) {
|
|
70
|
+
if (globals.config.deep_analysis ?? true) {
|
|
71
|
+
Logger.essential("[ENGINE] Starting deep analysis...");
|
|
72
|
+
await this.orchestratorAgent.start(globals.workflows);
|
|
73
|
+
|
|
74
|
+
SessionManager.updateStage("deep_analysis");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
SessionManager.updateState("completed");
|
|
79
|
+
Logger.essential("[ENGINE] Execution completed.");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
Logger.error("[ENGINE ERROR]", error);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = Engine;
|
package/globals.js
ADDED
package/img/logo.png
ADDED
|
Binary file
|
package/img/workflow.png
ADDED
|
Binary file
|
package/index.js
CHANGED
|
File without changes
|
package/llm/llm.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
|
|
2
|
+
const OpenAIProvider = require("./providers/openai");
|
|
3
|
+
const ClaudeProvider = require("./providers/claude");
|
|
4
|
+
const GeminiProvider = require("./providers/gemini");
|
|
5
|
+
|
|
6
|
+
class LLM {
|
|
7
|
+
constructor(llmConfig = {}) {
|
|
8
|
+
const providers = {
|
|
9
|
+
openai: OpenAIProvider,
|
|
10
|
+
claude: ClaudeProvider,
|
|
11
|
+
gemini: GeminiProvider
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const Provider = providers[llmConfig.provider];
|
|
15
|
+
|
|
16
|
+
if (!Provider) {
|
|
17
|
+
throw new Error(`Unsupported LLM provider: ${llmConfig.provider}`);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!llmConfig.model || !llmConfig.apiKey) {
|
|
21
|
+
throw new Error("LLM model and API key are required.");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.llmConfig = llmConfig;
|
|
25
|
+
this.provider = new Provider(llmConfig);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async generate(options = {}) {
|
|
29
|
+
if (!options.prompt) {
|
|
30
|
+
throw new Error("Prompt is required.");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
const response = await this.provider.generate(options);
|
|
35
|
+
|
|
36
|
+
if(options.text) return response.text;
|
|
37
|
+
|
|
38
|
+
return this._parseJSON(response.text);
|
|
39
|
+
|
|
40
|
+
} catch (error) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
`[${this.llmConfig.provider}] ${error.message}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
_parseJSON(text) {
|
|
48
|
+
return JSON.parse(
|
|
49
|
+
text
|
|
50
|
+
.replace(/^```json\s*/i, "")
|
|
51
|
+
.replace(/^```\s*/i, "")
|
|
52
|
+
.replace(/\s*```$/, "")
|
|
53
|
+
.trim()
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
module.exports = LLM;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
|
|
2
|
+
const axios = require("axios");
|
|
3
|
+
|
|
4
|
+
class ClaudeProvider {
|
|
5
|
+
constructor(llmConfig) {
|
|
6
|
+
this.llmConfig = llmConfig;
|
|
7
|
+
|
|
8
|
+
this.client = axios.create({
|
|
9
|
+
baseURL: "https://api.anthropic.com/v1",
|
|
10
|
+
headers: {
|
|
11
|
+
"x-api-key": llmConfig.apiKey,
|
|
12
|
+
"anthropic-version": "2023-06-01",
|
|
13
|
+
"Content-Type": "application/json"
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async generate(options) {
|
|
19
|
+
const payload = {
|
|
20
|
+
model: this.llmConfig.model,
|
|
21
|
+
messages: [
|
|
22
|
+
{
|
|
23
|
+
role: "user",
|
|
24
|
+
content: options.prompt
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
if (options.system) {
|
|
30
|
+
payload.system = options.system;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (options.temperature !== undefined) {
|
|
34
|
+
payload.temperature = options.temperature;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (options.json) {
|
|
38
|
+
payload.system = [
|
|
39
|
+
payload.system || "",
|
|
40
|
+
"Return only valid JSON. No markdown code fences."
|
|
41
|
+
].join("\n");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const { data } = await this.client.post("/messages", payload);
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
text: data.content
|
|
48
|
+
.filter(item => item.type === "text")
|
|
49
|
+
.map(item => item.text)
|
|
50
|
+
.join("\n"),
|
|
51
|
+
model: data.model,
|
|
52
|
+
provider: "claude",
|
|
53
|
+
usage: {
|
|
54
|
+
inputTokens: data.usage?.input_tokens || 0,
|
|
55
|
+
outputTokens: data.usage?.output_tokens || 0,
|
|
56
|
+
totalTokens:
|
|
57
|
+
(data.usage?.input_tokens || 0) +
|
|
58
|
+
(data.usage?.output_tokens || 0)
|
|
59
|
+
},
|
|
60
|
+
raw: data
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = ClaudeProvider;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
const axios = require("axios");
|
|
3
|
+
|
|
4
|
+
class GeminiProvider {
|
|
5
|
+
constructor(llmConfig) {
|
|
6
|
+
this.llmConfig = llmConfig;
|
|
7
|
+
|
|
8
|
+
this.client = axios.create({
|
|
9
|
+
baseURL: "https://generativelanguage.googleapis.com/v1beta/openai",
|
|
10
|
+
headers: {
|
|
11
|
+
Authorization: `Bearer ${llmConfig.apiKey}`,
|
|
12
|
+
"Content-Type": "application/json"
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async generate(options) {
|
|
18
|
+
const messages = [];
|
|
19
|
+
|
|
20
|
+
if (options.system) {
|
|
21
|
+
messages.push({
|
|
22
|
+
role: "system",
|
|
23
|
+
content: options.system
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
messages.push({
|
|
28
|
+
role: "user",
|
|
29
|
+
content: options.prompt
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const payload = {
|
|
33
|
+
model: this.llmConfig.model,
|
|
34
|
+
messages
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (options.temperature !== undefined) {
|
|
38
|
+
payload.temperature = options.temperature;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (options.json) {
|
|
42
|
+
payload.response_format = {
|
|
43
|
+
type: "json_object"
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { data } = await this.client.post(
|
|
48
|
+
"/chat/completions",
|
|
49
|
+
payload
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
text: data.choices?.[0]?.message?.content || "",
|
|
54
|
+
model: data.model,
|
|
55
|
+
provider: "gemini",
|
|
56
|
+
usage: {
|
|
57
|
+
inputTokens: data.usage?.prompt_tokens || 0,
|
|
58
|
+
outputTokens: data.usage?.completion_tokens || 0,
|
|
59
|
+
totalTokens: data.usage?.total_tokens || 0
|
|
60
|
+
},
|
|
61
|
+
raw: data
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
module.exports = GeminiProvider;
|