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.
@@ -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.map(source => path.dirname(source.path)))];
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
- ...(globals.config["source_exclusions"] || []),
88
- ...(this.additionalExclusions)])
89
- ]; // merge exclusions, duplicates removed
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
- for (let i = 0; i < this.sources.length; i += this.batchSize) {
94
- const batch = this.sources.slice(i, i + this.batchSize);
97
+ const total = this.sources.length;
98
+ let completed = 0;
95
99
 
96
- const results = await Promise.all(
97
- batch.map(async (source) => {
98
- let prompt = PromptsUtil.read("graph.build_nodes");
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
- prompt = prompt.replaceAll("***CONTENT***", JSON.stringify(source.content));
101
- prompt = prompt.replaceAll("ID-PREFIX", IdUtil.generate());
102
- Logger.detailed(prompt);
108
+ progressBar.start(total, 0);
103
109
 
104
- const graph = await this.llm.generate({ prompt: prompt, json: true });
105
- Logger.detailed(JSON.stringify(graph));
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
- const graphPath = `./graph/${IdUtil.generate()}.json`;
114
+ const results = await Promise.all(
115
+ batch.map(async (source) => {
116
+ try {
117
+ let prompt = PromptsUtil.read("graph.build_nodes");
108
118
 
109
- source.purpose = graph.purpose;
110
- const sourceJson = { file: path.basename(source.path), path: source.path, purpose: graph.purpose };
111
- this.fileUtil.saveJSON(graphPath, { file: sourceJson, graph: { nodes: graph.nodes, edges: graph.edges } });
119
+ prompt = prompt.replaceAll(
120
+ "***CONTENT***",
121
+ JSON.stringify(source.content)
122
+ );
112
123
 
113
- return { graphPath, file: source, graph: { nodes: graph.nodes, edges: graph.edges } };
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
- this.graphs.push(...results);
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 EnvironmentService {
8
+ class RunnerIdentificationService {
9
9
  static baseDir = path.join(process.cwd(), ".deeplyzer");
10
- static environmentsFile = path.join(EnvironmentService.baseDir, "environments.json");
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 define() {
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.environment");
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("Define Environments Prompt: " + prompt);
27
+ Logger.detailed("Identify Runners Prompt: " + prompt);
28
28
 
29
29
  const response = await this.llm.generate({ prompt: prompt, json: true });
30
- Logger.detailed("Define Environments: " + JSON.stringify(response));
30
+ Logger.detailed("Identify Runners: " + JSON.stringify(response));
31
31
 
32
- this._savEnvironments(response.environments);
32
+ this._saveRunners(response.runners);
33
33
 
34
- return response.environments;
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
- loadEnvironments() {
45
- if (!fs.existsSync(EnvironmentService.environmentsFile)) {
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(EnvironmentService.environmentsFile, "utf8")
51
+ fs.readFileSync(RunnerIdentificationService.runnersFile, "utf8")
52
52
  );
53
53
  } catch (error) {
54
- throw new Error(`Failed to load environments: ${error.message}`);
54
+ throw new Error(`Failed to load runners: ${error.message}`);
55
55
  }
56
56
  }
57
57
 
58
- _savEnvironments(environments) {
59
- fs.mkdirSync(EnvironmentService.baseDir, { recursive: true });
58
+ _saveRunners(runners) {
59
+ fs.mkdirSync(RunnerIdentificationService.baseDir, { recursive: true });
60
60
 
61
61
  fs.writeFileSync(
62
- EnvironmentService.environmentsFile,
63
- JSON.stringify(environments, null, 4),
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 = EnvironmentService;
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: "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 { success: true, stdout, stderr };
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
- require("url").pathToFileURL(modulePath).href
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(`Unsupported operating system: ${this.platform}`);
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
- let negate = pattern.startsWith("!");
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 isLast = i === segments.length - 1;
205
- const candidateIsDirectory = !isLast || isDirectory;
192
+ const candidateIsDirectory = i < segments.length - 1 || isDirectory;
206
193
 
207
194
  if (directoryOnly && !candidateIsDirectory) continue;
208
195
 
209
- if (hasSlash) {
210
- if (regex.test(candidate)) {
211
- matched = true;
212
- break;
213
- }
214
- } else {
215
- if (regex.test(segments[i])) {
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 envLevel = globals.log_level;
22
+ const logLevel = globals.log_level;
23
23
 
24
- this.currentLevel = Logger.LEVELS[envLevel] ?? Logger.LEVELS.DETAILED;
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 logLine =
45
- `[${new Date().toISOString()}] ` +
46
- `[${level}] ${message}`;
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;