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.
@@ -51,7 +51,7 @@ The purpose must be a string, not an object or array.
51
51
 
52
52
  Return valid JSON only.
53
53
 
54
- The output must have exactly two top-level properties:
54
+ The output must have exactly three top-level properties:
55
55
 
56
56
  {
57
57
  "purpose": "A concise description of the primary purpose of the supplied input",
@@ -83,7 +83,7 @@ Rules:
83
83
  4. Ensure every node ID is unique across the complete input.
84
84
  5. Use the exact same prefixed IDs when referencing nodes in edges.
85
85
  6. Never generate an unprefixed node ID.
86
- 7. Do not add the prefix to external_dependants regex patterns.
86
+ 7. Do not add the prefix to external_dependants search terms.
87
87
  8. Do not modify the prefix or generate a different prefix.
88
88
 
89
89
  Examples:
@@ -259,7 +259,7 @@ Code nodes must follow one of these two structures:
259
259
  "endLine": 47,
260
260
  "is_function": true,
261
261
  "external_dependants": [
262
- "\\buseOrders\\s*\\("
262
+ "OrderRepository"
263
263
  ]
264
264
  }
265
265
 
@@ -270,52 +270,34 @@ Rules:
270
270
  - 'endLine': Last line of the code entity.
271
271
  - 'is_function': Include this property only on function nodes, with the boolean value true. Do not include it on non-function code nodes.
272
272
  - Treat function declarations, function expressions, arrow functions, methods, constructors, and hooks as function nodes.
273
- - 'external_dependants': Array of regex strings that can locate potential references to the code entity elsewhere in the source code.
274
- - Use an empty array when no useful search pattern exists.
273
+ - 'external_dependants': Array of strings representing dependencies that are unresolved in the complete source code supplied for analysis.
274
+ - Use an empty array when the current entity has no unresolved dependencies.
275
275
  - Do not include 'type', 'name', 'parameters', 'returnType', 'description', source snippets, or any other properties.
276
276
  - Do not invent line numbers. Use null when source positions are unavailable.
277
277
  - Every function node must include all five properties, including 'is_function': true.
278
278
  - Non-function code nodes must not include 'is_function' and must contain exactly the four properties: 'id', 'startLine', 'endLine', and 'external_dependants'.
279
279
 
280
- ### External dependant patterns
280
+ ### External Dependants
281
281
 
282
- Generate simple, language-appropriate regex patterns to find potential references to the code entity.
283
-
284
- Examples:
285
-
286
- For a function:
287
-
288
- [
289
- "\\bcalculateTotal\\s*\\("
290
- ]
291
-
292
- For a method:
293
-
294
- [
295
- "\\.calculateTotal\\s*\\(",
296
- "\\bcalculateTotal\\s*\\("
297
- ]
298
-
299
- For a custom hook:
300
-
301
- [
302
- "\\buseOrders\\s*\\("
303
- ]
304
-
305
- For a class:
306
-
307
- [
308
- "\\bnew\\s+OrderService\\b",
309
- "\\bOrderService\\b"
310
- ]
282
+ An external dependant is a dependency used by the current code entity whose definition or implementation cannot be found anywhere in the complete source code supplied for analysis.
311
283
 
312
284
  Rules:
313
285
 
314
- 1. Patterns must be strings, not nested objects.
315
- 2. Multiple patterns are allowed.
316
- 3. Avoid matching the entity's own declaration wherever practical.
317
- 4. Patterns represent potential references, not confirmed dependencies.
318
- 5. Do not put graph node IDs in this array.
286
+ 1. Include only dependencies that the current code entity actually uses or references to perform its functionality.
287
+ 2. Determine whether each dependency is defined or implemented anywhere in the complete supplied source code, including other supplied files.
288
+ 3. If the dependency is defined or implemented anywhere in the supplied source code, it is resolved and must not be included.
289
+ 4. If the dependency is used by the current entity but its definition or implementation is not available anywhere in the supplied source code, include its name in 'external_dependants'.
290
+ 5. Never include the current entity itself.
291
+ 6. Never include entities that are locally declared or defined in the supplied source code.
292
+ 7. Do not include local variables, parameters, or properties merely because they are referenced.
293
+ 8. Do not include built-in language functionality, standard library functionality, or functionality provided by the framework or runtime.
294
+ 9. Do not infer dependencies from names alone. There must be evidence that the current entity actually uses or references the dependency.
295
+ 10. Do not include dependencies that are only hypothetical or might be needed in a different implementation.
296
+ 11. Use the dependency's plain identifier or name as the array string. Do not use regular expressions, search patterns, wildcards, escaping, or matching operators.
297
+ 12. Do not include the current entity's own name, declaration, or definition as an external dependency.
298
+ 13. If no unresolved dependencies exist, return an empty array.
299
+
300
+ The purpose of 'external_dependants' is to identify dependencies whose source definitions may need to be found outside the currently supplied source code. It is not a list of identifiers to search for usages of the current entity.
319
301
 
320
302
  # 5. DATABASE SCHEMAS
321
303
 
@@ -372,7 +354,7 @@ UI code entities must follow the same code-node structures defined in Section 4:
372
354
  "endLine": 47,
373
355
  "is_function": true,
374
356
  "external_dependants": [
375
- "\\buseOrders\\s*\\("
357
+ "OrderRepository"
376
358
  ]
377
359
  }
378
360
 
@@ -502,7 +484,7 @@ Follow these rules:
502
484
  9. Capture meaningful structural, semantic, and dependency relationships.
503
485
  10. Do not invent information.
504
486
  11. Ensure every edge references existing nodes.
505
- 12. Generate useful external dependant regex patterns for relevant code entities.
487
+ 12. Include only genuine unresolved dependencies in 'external_dependants', according to Section 4.
506
488
  13. Do not add unnecessary properties to nodes.
507
489
  14. Follow the strict node structures defined in this prompt.
508
490
 
@@ -525,7 +507,7 @@ Before returning the output, verify:
525
507
  - Line numbers accurately identify the original input range represented by each node.
526
508
  - Text and configuration node line ranges correspond exactly to their preserved 'content'.
527
509
  - Unavailable line positions are represented as null, not omitted or fabricated.
528
- - External dependant patterns are valid and useful.
510
+ - Every 'external_dependants' entry names a genuine dependency that is unresolved in the complete supplied source code.
529
511
 
530
512
  ### Edges
531
513
 
@@ -556,13 +538,15 @@ If a declaration or definition is present in the input, create its node and use
556
538
  If an entity is declared in another supplied source file, it may be represented as a node using that declaration's source location.
557
539
 
558
540
  External Dependants:
559
- Generate regex patterns only for actual declared or defined code entities.
560
- Patterns must identify potential usages of the declared entity elsewhere.
561
- Do not generate external_dependants for imported-only symbols.
562
- Do not use a pattern that simply matches every occurrence of an external identifier when no corresponding local declaration exists.
541
+ 1. Populate 'external_dependants' only on code nodes that are declared or defined in the supplied source code.
542
+ 2. Each entry must identify another code entity that the current node actually depends on and whose definition or implementation is absent from the complete supplied source code.
543
+ 3. Do not include imported-only symbols as standalone code nodes. However, an imported symbol may appear in the 'external_dependants' array of a code node when that node actually uses it and its definition is not present in the supplied source.
544
+ 4. Do not include dependencies that are defined in another supplied source file.
545
+ 5. Do not include the current node's own name, locally defined entities, local variables, parameters, properties, built-in functionality, standard library functionality, or framework/runtime functionality.
546
+ 6. If there are no such unresolved dependencies, use an empty array.
563
547
 
564
548
  Validation:
565
- Before creating a code node, verify that its declaration or definition exists in the supplied input. If it is only an external reference, do not create a node.
549
+ Before returning the graph, verify each 'external_dependants' entry against the complete supplied source code. Remove the entry if its definition or implementation is present in any supplied source file, if the current entity does not actually use it, or if it is the current entity itself.
566
550
 
567
551
  # 12. FINAL OUTPUT
568
552
 
@@ -19,6 +19,8 @@ Your task is to analyze the repository structure and identify files and folders
19
19
  - Avoid broad exclusions that could unintentionally remove meaningful source code.
20
20
  - Exclude only paths that can be confidently identified as unnecessary for subsequent deep source analysis.
21
21
  - Do not invent paths that are not present in the supplied file or folder list.
22
+ - Exclude dependency lockfiles and package-manager generated metadata files (e.g., package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lock, composer.lock, Cargo.lock, poetry.lock, and equivalent files).
23
+ - Exclude dependency manifests only when they are clearly non-essential to architectural analysis? No. Preserve manifests such as package.json, requirements.txt, pyproject.toml, Cargo.toml, and pom.xml because they provide meaningful architectural and dependency context.
22
24
 
23
25
  ***PATHS***
24
26
 
@@ -1,46 +1,45 @@
1
- const SessionManager = require('../session/sessionManager');
2
1
  const FileUtil = require('../utils/fileUtil');
3
2
  const IdUtil = require('../utils/idUtil');
4
3
  const LLM = require("../llm/llm");
5
4
  const PromptsUtil = require('../utils/promptsUtil');
5
+ const HashUtil = require('../utils/hashUtil');
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() {
12
13
  this.fileUtil = new FileUtil();
13
14
  this.llm = new LLM(globals.config.llm);
14
- this.graphs = [];
15
+ globals.graphs = [];
16
+ this.updatedPaths = [];
15
17
 
16
18
  this.batchSize = globals.config.batch_size ?? 10;
17
19
  }
18
20
 
21
+ hasUpdates() {
22
+ return this.updatedPaths.length > 0;
23
+ }
24
+
19
25
  async buildGraphs() {
20
- if(SessionManager.checkStage("build_nodes")) {
21
- // clear all existing graph files
22
- this.fileUtil.removeAllFiles("graph");
26
+ Logger.essential("Finding source exclusions");
27
+ await this._identifyExclusions();
23
28
 
24
- Logger.essential("Finding source exclusions");
25
- await this._identifyExclusions();
26
-
27
- Logger.essential("Building nodes is in-progress");
28
- await this._buildNodes();
29
+ Logger.essential("Building nodes is in-progress");
30
+ await this._loadGraphs();
29
31
 
30
- SessionManager.updateStage("build_nodes");
31
- }
32
+ await this._buildNodes();
32
33
 
33
- if(SessionManager.checkStage("connect_edges")) {
34
- Logger.essential("Connecting edges");
34
+ if(this.hasUpdates()) {
35
+ Logger.essential("Connecting external edges");
35
36
  await this._buildExternalEdges();
36
-
37
- SessionManager.updateStage("connect_edges");
38
37
  }
39
38
  }
40
39
 
41
40
  async _identifyExclusions() {
42
41
  const sources = this.fileUtil.readPaths(globals.config.sources, globals.config["source_exclusions"]);
43
- const folders = [...new Set(sources.map(source => path.dirname(source.path)))];
42
+ const folders = [...new Set(sources.flatMap(source => [source.path, path.dirname(source.path)]))];
44
43
 
45
44
  let prompt = PromptsUtil.read("graph.source_exclusions");
46
45
  prompt = prompt.replaceAll("***PATHS***", JSON.stringify(folders));
@@ -52,75 +51,104 @@ class GraphService {
52
51
  this.additionalExclusions = response.exclusions;
53
52
  }
54
53
 
55
- async loadGraphs() {
56
- this.graphs = [];
57
- this.sources = [];
54
+ async _buildNodes() {
55
+ const sourceFiles = globals.config.sources;
58
56
 
59
- const graphFiles = this.fileUtil.readPaths([
60
- path.join(this.fileUtil.baseDir, "graph")
61
- ]);
57
+ const exclusions = [...new Set([
58
+ "**/*.png", "**/*.jpg", "**/*.jpeg", "**/*.gif", "**/*.bmp",
59
+ "**/*.webp", "**/*.svg", "**/*.ico", "**/*.tif", "**/*.tiff",
60
+ ...(globals.config.source_exclusions || []),
61
+ ...(this.additionalExclusions || [])
62
+ ])];
62
63
 
63
- for (const file of graphFiles) {
64
- if (!file.filename.endsWith(".json")) continue;
64
+ this.sources = this.fileUtil.readPaths(sourceFiles, exclusions);
65
65
 
66
- const data = this.fileUtil.loadJSON(
67
- path.join("graph", file.filename)
68
- );
66
+ this.updatedPaths = [];
69
67
 
70
- if (!data?.file || !data?.graph) continue;
68
+ const total = this.sources.length;
69
+ let completed = 0;
71
70
 
72
- this.graphs.push({
73
- graphPath: path.join("graph", file.filename),
74
- file: data.file,
75
- graph: data.graph
76
- });
71
+ const progressBar = new cliProgress.SingleBar({
72
+ format: 'Building Nodes |{bar}| {percentage}% | {value}/{total}',
73
+ barCompleteChar: '\u2588',
74
+ barIncompleteChar: '\u2591',
75
+ barsize: 25,
76
+ hideCursor: true
77
+ }, cliProgress.Presets.shades_classic);
77
78
 
78
- this.sources.push(data.file);
79
- }
79
+ progressBar.start(total, 0);
80
80
 
81
- return this.graphs;
82
- }
81
+ try {
82
+ for (let i = 0; i < total; i += this.batchSize) {
83
+ const batch = this.sources.slice(i, i + this.batchSize);
83
84
 
84
- async _buildNodes() {
85
- const sourceFiles = globals.config.sources;
86
- const exclusions = [...new Set([
87
- ...(globals.config["source_exclusions"] || []),
88
- ...(this.additionalExclusions)])
89
- ]; // merge exclusions, duplicates removed
85
+ const results = await Promise.all(
86
+ batch.map(async (source) => {
87
+ try {
88
+ const hash = HashUtil.hashFile(source.path);
90
89
 
91
- this.sources = this.fileUtil.readPaths(sourceFiles, exclusions);
90
+ const existingGraph = globals.graphs.find(
91
+ item => item.file.path === source.path
92
+ );
92
93
 
93
- for (let i = 0; i < this.sources.length; i += this.batchSize) {
94
- const batch = this.sources.slice(i, i + this.batchSize);
94
+ // Skip unchanged files
95
+ if (existingGraph && existingGraph.file.hash === hash) {
96
+ return null;
97
+ }
95
98
 
96
- const results = await Promise.all(
97
- batch.map(async (source) => {
98
- let prompt = PromptsUtil.read("graph.build_nodes");
99
+ // Track new and modified files
100
+ this.updatedPaths.push(source.path);
99
101
 
100
- prompt = prompt.replaceAll("***CONTENT***", JSON.stringify(source.content));
101
- prompt = prompt.replaceAll("ID-PREFIX", IdUtil.generate());
102
- Logger.detailed(prompt);
102
+ let prompt = PromptsUtil.read("graph.build_nodes");
103
103
 
104
- const graph = await this.llm.generate({ prompt: prompt, json: true });
105
- Logger.detailed(JSON.stringify(graph));
104
+ prompt = prompt.replaceAll("***CONTENT***", JSON.stringify(source.content));
106
105
 
107
- const graphPath = `./graph/${IdUtil.generate()}.json`;
106
+ prompt = prompt.replaceAll("ID-PREFIX", IdUtil.generate());
108
107
 
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 } });
108
+ Logger.detailed(prompt);
112
109
 
113
- return { graphPath, file: source, graph: { nodes: graph.nodes, edges: graph.edges } };
114
- })
115
- );
110
+ const graph = await this.llm.generate({ prompt, json: true });
111
+
112
+ Logger.detailed(JSON.stringify(graph));
113
+
114
+ const graphPath = `./graph/${IdUtil.generate()}.json`;
115
+
116
+ source.purpose = graph.purpose;
117
+
118
+ const sourceJson = {
119
+ file: path.basename(source.path),
120
+ path: source.path,
121
+ purpose: graph.purpose,
122
+ hash
123
+ };
124
+
125
+ this.fileUtil.saveJSON(graphPath, {
126
+ file: sourceJson,
127
+ graph: { nodes: graph.nodes, edges: graph.edges }
128
+ });
116
129
 
117
- this.graphs.push(...results);
130
+ return {
131
+ graphPath,
132
+ file: { ...source, hash },
133
+ graph: { nodes: graph.nodes, edges: graph.edges }
134
+ };
135
+ } finally {
136
+ completed++;
137
+ progressBar.update(completed);
138
+ }
139
+ })
140
+ );
141
+
142
+ globals.graphs.push(...results.filter(Boolean));
143
+ }
144
+ } finally {
145
+ progressBar.stop();
118
146
  }
119
147
  }
120
148
 
121
149
  async _buildExternalEdges() {
122
- for (let i = 0; i < this.graphs.length; i += this.batchSize) {
123
- const batch = this.graphs.slice(i, i + this.batchSize);
150
+ for (let i = 0; i < globals.graphs.length; i += this.batchSize) {
151
+ const batch = globals.graphs.slice(i, i + this.batchSize);
124
152
 
125
153
  await Promise.all(
126
154
  batch.map(async (sourceGraph) => {
@@ -160,40 +188,32 @@ class GraphService {
160
188
  JSON.stringify(candidateData, null, 2)
161
189
  );
162
190
 
163
- const response = await this.llm.generate({ prompt: prompt });
164
-
165
- let result;
166
-
167
- try {
168
- result = JSON.parse(response.text);
169
- } catch {
170
- continue;
171
- }
191
+ const result = await this.llm.generate({ prompt: prompt, json: true });
172
192
 
173
193
  if (!result?.selectedNodeId) continue;
174
194
 
175
- const selected = candidates.find(
176
- candidate => candidate.id === result.selectedNodeId
177
- );
178
-
179
- if (!selected) continue;
180
-
181
195
  const exists = sourceGraph.graph.edges.some(
182
196
  edge =>
183
197
  edge.node1 === node.id &&
184
- edge.node2 === selected.id
198
+ edge.node2 === result.selectedNodeId
185
199
  );
186
200
 
187
201
  if (exists) continue;
188
202
 
189
203
  sourceGraph.graph.edges.push({
190
204
  node1: node.id,
191
- node2: selected.id
205
+ node2: result.selectedNodeId
192
206
  });
193
207
  }
194
208
  }
195
209
 
196
- const sourceJson = { file: path.basename(sourceGraph.file.path), path: sourceGraph.file.path, purpose: sourceGraph.file.purpose };
210
+ const sourceJson = {
211
+ file: path.basename(sourceGraph.file.path),
212
+ path: sourceGraph.file.path,
213
+ purpose: sourceGraph.file.purpose,
214
+ hash: sourceGraph.file.hash
215
+ };
216
+
197
217
  this.fileUtil.saveJSON(sourceGraph.graphPath, {
198
218
  file: sourceJson,
199
219
  graph: sourceGraph.graph
@@ -216,7 +236,7 @@ class GraphService {
216
236
  .join("\n");
217
237
  }
218
238
 
219
- _searchSources(patterns, sourceFile) {
239
+ _searchSources(searchTerms, sourceFile) {
220
240
  const matches = [];
221
241
 
222
242
  for (const source of this.sources) {
@@ -227,24 +247,22 @@ class GraphService {
227
247
  const lines = source.content.split(/\r?\n/);
228
248
 
229
249
  for (let i = 0; i < lines.length; i++) {
230
- for (const pattern of patterns) {
231
- const regex = new RegExp(pattern, "g");
232
- let match;
233
-
234
- while ((match = regex.exec(lines[i])) !== null) {
235
- matches.push({
236
- file: source.path,
237
- line: i + 1,
238
- matchedText: match[0],
239
- sourceLine: lines[i].trim()
240
- });
241
-
242
- if (!match[0].length) regex.lastIndex++;
243
- }
250
+ for (const term of searchTerms) {
251
+
252
+ // Search for literal text (case-sensitive)
253
+ if (!term || !lines[i].includes(term)) continue;
254
+
255
+ matches.push({
256
+ file: source.path,
257
+ line: i + 1,
258
+ matchedText: term,
259
+ sourceLine: lines[i].trim()
260
+ });
244
261
  }
245
262
  }
246
263
  }
247
264
 
265
+ // Remove duplicate matches
248
266
  return [
249
267
  ...new Map(
250
268
  matches.map(match => [
@@ -266,7 +284,7 @@ class GraphService {
266
284
 
267
285
  const lines = source.content.split(/\r?\n/);
268
286
 
269
- for (const sourceGraph of this.graphs) {
287
+ for (const sourceGraph of globals.graphs) {
270
288
  if (sourceGraph.file.path !== match.file) continue;
271
289
  for (const node of sourceGraph.graph.nodes) {
272
290
  if (
@@ -287,6 +305,33 @@ class GraphService {
287
305
 
288
306
  return candidates;
289
307
  }
308
+
309
+ async _loadGraphs() {
310
+ globals.graphs = [];
311
+ this.sources = [];
312
+
313
+ const graphFiles = this.fileUtil.readPaths([
314
+ path.join(this.fileUtil.baseDir, "graph")
315
+ ]);
316
+
317
+ for (const file of graphFiles) {
318
+ if (!file.filename.endsWith(".json")) continue;
319
+
320
+ const data = this.fileUtil.loadJSON(
321
+ path.join("graph", file.filename)
322
+ );
323
+
324
+ if (!data?.file || !data?.graph) continue;
325
+
326
+ globals.graphs.push({
327
+ graphPath: path.join("graph", file.filename),
328
+ file: data.file,
329
+ graph: data.graph
330
+ });
331
+
332
+ this.sources.push(data.file);
333
+ }
334
+ }
290
335
  }
291
336
 
292
337
  module.exports = GraphService;