deeplyzer 0.9.0 → 0.11.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.
@@ -9,6 +9,27 @@ class WorkflowService {
9
9
  static workflowFile = path.join(WorkflowService.baseDir, "workflows.json");
10
10
 
11
11
  build() {
12
+ const functionNodeIds = this._getFunctionNodeIds();
13
+ const workflowMap = new Map();
14
+
15
+ if (functionNodeIds.size === 0) {
16
+ this._buildFallbackWorkflow(workflowMap);
17
+ } else {
18
+ this._initializeWorkflows(workflowMap, functionNodeIds);
19
+
20
+ const adjacencyMap = this._buildAdjacencyMap();
21
+
22
+ this._traverseWorkflows(workflowMap, functionNodeIds, adjacencyMap);
23
+ }
24
+
25
+ const workflows = [...workflowMap.values()];
26
+
27
+ this._saveWorkflows(workflows);
28
+
29
+ return workflows;
30
+ }
31
+
32
+ _getFunctionNodeIds() {
12
33
  const functionNodeIds = new Set();
13
34
 
14
35
  for (const graph of globals.graphs) {
@@ -21,55 +42,99 @@ class WorkflowService {
21
42
  }
22
43
  }
23
44
 
24
- const workflowMap = new Map();
45
+ return functionNodeIds;
46
+ }
25
47
 
26
- // Fallback: entire graph becomes a single workflow
27
- if (functionNodeIds.size === 0) {
28
- const allNodes = globals.graphs.flatMap(
29
- graph => graph.graph?.nodes || []
30
- );
48
+ _buildFallbackWorkflow(workflowMap) {
49
+ const allNodes = globals.graphs.flatMap(
50
+ graph => graph.graph?.nodes || []
51
+ );
31
52
 
32
- if (allNodes.length > 0) {
33
- const rootNode = allNodes[0];
53
+ if (allNodes.length > 0) {
54
+ const rootNode = allNodes[0];
34
55
 
35
- workflowMap.set(rootNode.id, {
36
- id: IdUtil.generate(),
37
- node: rootNode.id,
38
- childNodes: allNodes
39
- .slice(1)
40
- .map(node => node.id)
41
- });
42
- }
43
- } else {
44
- for (const nodeId of functionNodeIds) {
45
- workflowMap.set(nodeId, {
46
- id: IdUtil.generate(),
47
- node: nodeId,
48
- childNodes: []
49
- });
50
- }
56
+ workflowMap.set(rootNode.id, {
57
+ id: IdUtil.generate(),
58
+ node: rootNode.id,
59
+ childNodes: allNodes.slice(1).map(node => node.id)
60
+ });
61
+ }
62
+ }
63
+
64
+ _initializeWorkflows(workflowMap, functionNodeIds) {
65
+ for (const nodeId of functionNodeIds) {
66
+ workflowMap.set(nodeId, {
67
+ id: IdUtil.generate(),
68
+ node: nodeId,
69
+ childNodes: []
70
+ });
71
+ }
72
+ }
51
73
 
52
- for (const graph of graphs) {
53
- const edges = graph.graph?.edges || [];
74
+ _buildAdjacencyMap() {
75
+ const adjacencyMap = new Map();
54
76
 
55
- for (const edge of edges) {
56
- const { node1, node2 } = edge;
77
+ for (const graph of globals.graphs) {
78
+ const edges = graph.graph?.edges || [];
57
79
 
58
- if (!workflowMap.has(node1) || !workflowMap.has(node2)) {
59
- continue;
60
- }
80
+ for (const edge of edges) {
81
+ const { node1, node2 } = edge;
61
82
 
62
- this._addConnection(workflowMap, node1, node2);
63
- this._addConnection(workflowMap, node2, node1);
83
+ if (!adjacencyMap.has(node1)) {
84
+ adjacencyMap.set(node1, new Set());
64
85
  }
86
+
87
+ if (!adjacencyMap.has(node2)) {
88
+ adjacencyMap.set(node2, new Set());
89
+ }
90
+
91
+ adjacencyMap.get(node1).add(node2);
92
+ adjacencyMap.get(node2).add(node1);
65
93
  }
66
94
  }
67
95
 
68
- const workflows = [...workflowMap.values()];
96
+ return adjacencyMap;
97
+ }
69
98
 
70
- this._saveWorkflows(workflows);
99
+ _traverseWorkflows(workflowMap, functionNodeIds, adjacencyMap) {
100
+ for (const [functionNodeId, workflow] of workflowMap) {
101
+ this._traverseFromFunction(
102
+ functionNodeId,
103
+ workflow,
104
+ functionNodeIds,
105
+ adjacencyMap
106
+ );
107
+ }
108
+ }
71
109
 
72
- return workflows;
110
+ _traverseFromFunction(functionNodeId, workflow, functionNodeIds, adjacencyMap) {
111
+ const visited = new Set([functionNodeId]);
112
+ const queue = [functionNodeId];
113
+
114
+ while (queue.length > 0) {
115
+ const currentNodeId = queue.shift();
116
+
117
+ const connectedNodes = adjacencyMap.get(currentNodeId) || [];
118
+
119
+ for (const connectedNodeId of connectedNodes) {
120
+ if (visited.has(connectedNodeId)) {
121
+ continue;
122
+ }
123
+
124
+ visited.add(connectedNodeId);
125
+
126
+ // Add connected node, including another function node
127
+ workflow.childNodes.push(connectedNodeId);
128
+
129
+ // Stop traversal when another function node is reached
130
+ if (functionNodeIds.has(connectedNodeId)) {
131
+ continue;
132
+ }
133
+
134
+ // Continue traversal through non-function nodes
135
+ queue.push(connectedNodeId);
136
+ }
137
+ }
73
138
  }
74
139
 
75
140
  loadWorkflows() {
@@ -97,6 +162,8 @@ class WorkflowService {
97
162
  }
98
163
 
99
164
  _addConnection(workflowMap, source, target) {
165
+ if(!workflowMap.has(source)) return;
166
+
100
167
  const childNodes = workflowMap.get(source).childNodes;
101
168
 
102
169
  if (!childNodes.includes(target)) {
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
@@ -122,7 +122,7 @@ class FileUtil {
122
122
  return results;
123
123
  }
124
124
 
125
- removeAllFiles(dir) {
125
+ removeFiles(dir) {
126
126
  const dirPath = path.join(this.baseDir, dir);
127
127
 
128
128
  if (!fs.existsSync(dirPath)) return;
@@ -161,17 +161,15 @@ class FileUtil {
161
161
  }
162
162
 
163
163
  _matchesExclusion(relativePath, isDirectory, exclusions = []) {
164
- const normalizedPath = relativePath
165
- .split(path.sep)
166
- .join("/");
167
-
164
+ const normalizedPath = relativePath.replace(/\\/g, "/");
168
165
  const segments = normalizedPath.split("/");
166
+
169
167
  let excluded = false;
170
168
 
171
169
  for (let pattern of exclusions) {
172
170
  if (!pattern || pattern.startsWith("#")) continue;
173
171
 
174
- let negate = pattern.startsWith("!");
172
+ const negate = pattern.startsWith("!");
175
173
 
176
174
  if (negate) {
177
175
  pattern = pattern.substring(1);
@@ -186,29 +184,28 @@ class FileUtil {
186
184
 
187
185
  if (!pattern) continue;
188
186
 
189
- const hasSlash = pattern.includes("/");
190
187
  const regex = this._globToRegex(pattern);
191
-
192
188
  let matched = false;
193
189
 
194
190
  for (let i = 0; i < segments.length; i++) {
195
191
  const candidate = segments.slice(0, i + 1).join("/");
196
- const isLast = i === segments.length - 1;
197
- const candidateIsDirectory = !isLast || isDirectory;
192
+ const candidateIsDirectory = i < segments.length - 1 || isDirectory;
198
193
 
199
194
  if (directoryOnly && !candidateIsDirectory) continue;
200
195
 
201
- if (hasSlash) {
202
- if (regex.test(candidate)) {
203
- matched = true;
204
- break;
205
- }
206
- } else {
207
- 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)) {
208
203
  matched = true;
209
204
  break;
210
205
  }
211
206
  }
207
+
208
+ if (matched) break;
212
209
  }
213
210
 
214
211
  if (matched) {
@@ -0,0 +1,34 @@
1
+
2
+ const crypto = require("crypto");
3
+ const fs = require("fs");
4
+
5
+ class HashUtil {
6
+
7
+ static hash(content) {
8
+ return crypto
9
+ .createHash("sha256")
10
+ .update(content, "utf8")
11
+ .digest("hex");
12
+ }
13
+
14
+ static hashFile(filePath) {
15
+ const content = fs.readFileSync(filePath);
16
+ return crypto
17
+ .createHash("sha256")
18
+ .update(content)
19
+ .digest("hex");
20
+ }
21
+
22
+ static async hashFileAsync(filePath) {
23
+ const hash = crypto.createHash("sha256");
24
+ const stream = fs.createReadStream(filePath);
25
+
26
+ for await (const chunk of stream) {
27
+ hash.update(chunk);
28
+ }
29
+
30
+ return hash.digest("hex");
31
+ }
32
+ }
33
+
34
+ module.exports = HashUtil;
@@ -1,130 +0,0 @@
1
-
2
- const fs = require("fs");
3
- const path = require("path");
4
-
5
- class SessionManager {
6
-
7
- static STATE = {
8
- NONE: "none",
9
- IN_PROGRESS: "in_progress",
10
- COMPLETED: "completed",
11
- ABORTED: "aborted"
12
- };
13
-
14
- static STAGES = {
15
- NONE: "none",
16
- BUILD_NODES: "build_nodes",
17
- CONNECT_EDGES: "connect_edges",
18
- BUILD_WORKFLOWS: "build_workflows",
19
- DEFINE_ENVIRONMENTS: "identify_runners",
20
- STATIC_ANALYSIS: "static_analysis",
21
- DEEP_ANALYSIS: "deep_analysis",
22
- };
23
-
24
- static session = null;
25
-
26
- static baseDir = path.join(process.cwd(), ".deeplyzer");
27
- static sessionFile = path.join(SessionManager.baseDir, "session.json");
28
-
29
- static _ensureDirectory() {
30
- fs.mkdirSync(this.baseDir, { recursive: true });
31
- }
32
-
33
- static loadSession() {
34
- this._ensureDirectory();
35
-
36
- if (!fs.existsSync(this.sessionFile)) {
37
- this.session = {
38
- state: this.STATE.IN_PROGRESS,
39
- currentStage: this.STAGES.NONE
40
- };
41
- this._writeSession();
42
- return this.session;
43
- }
44
-
45
- try {
46
- this.session = JSON.parse(
47
- fs.readFileSync(this.sessionFile, "utf8")
48
- );
49
- } catch (error) {
50
- throw new Error(`Failed to load session: ${error.message}`);
51
- }
52
- }
53
-
54
- static updateState(state) {
55
- if (!this.session) {
56
- this.loadSession();
57
- }
58
-
59
- this.session.state = state;
60
-
61
- this._writeSession();
62
-
63
- return this.session;
64
- }
65
-
66
-
67
- static updateStage(stage) {
68
- if (!this.session) {
69
- this.loadSession();
70
- }
71
-
72
- this.session.currentStage = stage;
73
-
74
- this._writeSession();
75
-
76
- return this.session;
77
- }
78
-
79
- static clearSession() {
80
- this.session = {
81
- state: this.STATE.NONE,
82
- currentStage: this.STAGES.NONE
83
- };
84
- this._writeSession();
85
- return this.session;
86
- }
87
-
88
- static resetAnalysisSession() {
89
- this.session = {
90
- state: this.STATE.IN_PROGRESS,
91
- currentStage: this.STAGES.DEFINE_ENVIRONMENTS
92
- };
93
- this._writeSession();
94
- return this.session;
95
- }
96
-
97
- static checkStage(stage) {
98
- if (!this.session) {
99
- this.loadSession();
100
- }
101
-
102
- const stages = Object.values(this.STAGES);
103
-
104
- const stageIndex = stages.indexOf(stage);
105
-
106
- if (stageIndex === -1) {
107
- throw new Error(`Invalid stage: ${stage}`);
108
- }
109
-
110
- const lastCompletedIndex = stages.indexOf(this.session.currentStage);
111
-
112
- return stageIndex > lastCompletedIndex;
113
- }
114
-
115
- static _writeSession() {
116
- this._ensureDirectory();
117
-
118
- fs.writeFileSync(
119
- this.sessionFile,
120
- JSON.stringify(this.session, null, 4),
121
- "utf8"
122
- );
123
- }
124
-
125
- static getStageList() {
126
- return Object.values(this.STAGES);
127
- }
128
- }
129
-
130
- module.exports = SessionManager;