@aiready/context-analyzer 0.19.11 → 0.19.14

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/dist/cli.js CHANGED
@@ -661,7 +661,7 @@ function buildDependencyGraph(files, options) {
661
661
  const edges = /* @__PURE__ */ new Map();
662
662
  const autoDetectedKeywords = options?.domainKeywords ?? extractDomainKeywordsFromPaths(files);
663
663
  for (const { file, content } of files) {
664
- const imports = extractImportsFromContent(content);
664
+ const imports = extractImportsFromContent(content, file);
665
665
  const exports2 = extractExportsWithAST(
666
666
  content,
667
667
  file,
@@ -696,19 +696,37 @@ function buildDependencyGraph(files, options) {
696
696
  }
697
697
  return graph;
698
698
  }
699
- function extractImportsFromContent(content) {
699
+ function extractImportsFromContent(content, filePath) {
700
700
  const imports = [];
701
- const patterns = [
702
- /import\s+.*?\s+from\s+['"](.+?)['"]/g,
703
- /import\s+['"](.+?)['"]/g,
704
- /require\(['"](.+?)['"]\)/g
705
- ];
706
- for (const pattern of patterns) {
707
- let match;
708
- while ((match = pattern.exec(content)) !== null) {
709
- const importPath = match[1];
710
- if (importPath && !importPath.startsWith("node:")) {
711
- imports.push(importPath);
701
+ const isPython = filePath?.toLowerCase().endsWith(".py");
702
+ if (isPython) {
703
+ const pythonPatterns = [
704
+ /^\s*import\s+([a-zA-Z0-9_., ]+)/gm,
705
+ /^\s*from\s+([a-zA-Z0-9_.]+)\s+import/gm
706
+ ];
707
+ for (const pattern of pythonPatterns) {
708
+ let match;
709
+ while ((match = pattern.exec(content)) !== null) {
710
+ const importPath = match[1];
711
+ if (importPath) {
712
+ const parts = importPath.split(",").map((p) => p.trim().split(/\s+as\s+/)[0]);
713
+ imports.push(...parts);
714
+ }
715
+ }
716
+ }
717
+ } else {
718
+ const patterns = [
719
+ /import\s+.*?\s+from\s+['"](.+?)['"]/g,
720
+ /import\s+['"](.+?)['"]/g,
721
+ /require\(['"](.+?)['"]\)/g
722
+ ];
723
+ for (const pattern of patterns) {
724
+ let match;
725
+ while ((match = pattern.exec(content)) !== null) {
726
+ const importPath = match[1];
727
+ if (importPath && !importPath.startsWith("node:")) {
728
+ imports.push(importPath);
729
+ }
712
730
  }
713
731
  }
714
732
  }
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  analyzeContext,
4
4
  generateSummary
5
- } from "./chunk-P5YV5WIX.mjs";
5
+ } from "./chunk-K2WFOBAZ.mjs";
6
6
 
7
7
  // src/cli.ts
8
8
  import { Command } from "commander";
package/dist/index.d.mts CHANGED
@@ -143,9 +143,9 @@ declare function buildDependencyGraph(files: FileContent[], options?: {
143
143
  domainKeywords?: string[];
144
144
  }): DependencyGraph;
145
145
  /**
146
- * Extract imports from file content using regex
146
+ * Extract imports from file content
147
147
  */
148
- declare function extractImportsFromContent(content: string): string[];
148
+ declare function extractImportsFromContent(content: string, filePath?: string): string[];
149
149
  /**
150
150
  * Calculate the maximum depth of import tree for a file
151
151
  */
package/dist/index.d.ts CHANGED
@@ -143,9 +143,9 @@ declare function buildDependencyGraph(files: FileContent[], options?: {
143
143
  domainKeywords?: string[];
144
144
  }): DependencyGraph;
145
145
  /**
146
- * Extract imports from file content using regex
146
+ * Extract imports from file content
147
147
  */
148
- declare function extractImportsFromContent(content: string): string[];
148
+ declare function extractImportsFromContent(content: string, filePath?: string): string[];
149
149
  /**
150
150
  * Calculate the maximum depth of import tree for a file
151
151
  */
package/dist/index.js CHANGED
@@ -777,7 +777,7 @@ function buildDependencyGraph(files, options) {
777
777
  const edges = /* @__PURE__ */ new Map();
778
778
  const autoDetectedKeywords = options?.domainKeywords ?? extractDomainKeywordsFromPaths(files);
779
779
  for (const { file, content } of files) {
780
- const imports = extractImportsFromContent(content);
780
+ const imports = extractImportsFromContent(content, file);
781
781
  const exports2 = extractExportsWithAST(
782
782
  content,
783
783
  file,
@@ -812,19 +812,37 @@ function buildDependencyGraph(files, options) {
812
812
  }
813
813
  return graph;
814
814
  }
815
- function extractImportsFromContent(content) {
815
+ function extractImportsFromContent(content, filePath) {
816
816
  const imports = [];
817
- const patterns = [
818
- /import\s+.*?\s+from\s+['"](.+?)['"]/g,
819
- /import\s+['"](.+?)['"]/g,
820
- /require\(['"](.+?)['"]\)/g
821
- ];
822
- for (const pattern of patterns) {
823
- let match;
824
- while ((match = pattern.exec(content)) !== null) {
825
- const importPath = match[1];
826
- if (importPath && !importPath.startsWith("node:")) {
827
- imports.push(importPath);
817
+ const isPython = filePath?.toLowerCase().endsWith(".py");
818
+ if (isPython) {
819
+ const pythonPatterns = [
820
+ /^\s*import\s+([a-zA-Z0-9_., ]+)/gm,
821
+ /^\s*from\s+([a-zA-Z0-9_.]+)\s+import/gm
822
+ ];
823
+ for (const pattern of pythonPatterns) {
824
+ let match;
825
+ while ((match = pattern.exec(content)) !== null) {
826
+ const importPath = match[1];
827
+ if (importPath) {
828
+ const parts = importPath.split(",").map((p) => p.trim().split(/\s+as\s+/)[0]);
829
+ imports.push(...parts);
830
+ }
831
+ }
832
+ }
833
+ } else {
834
+ const patterns = [
835
+ /import\s+.*?\s+from\s+['"](.+?)['"]/g,
836
+ /import\s+['"](.+?)['"]/g,
837
+ /require\(['"](.+?)['"]\)/g
838
+ ];
839
+ for (const pattern of patterns) {
840
+ let match;
841
+ while ((match = pattern.exec(content)) !== null) {
842
+ const importPath = match[1];
843
+ if (importPath && !importPath.startsWith("node:")) {
844
+ imports.push(importPath);
845
+ }
828
846
  }
829
847
  }
830
848
  }
package/dist/index.mjs CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  isTypeDefinition,
45
45
  isUtilityModule,
46
46
  mapScoreToRating
47
- } from "./chunk-P5YV5WIX.mjs";
47
+ } from "./chunk-K2WFOBAZ.mjs";
48
48
  export {
49
49
  ContextAnalyzerProvider,
50
50
  adjustCohesionForClassification,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/context-analyzer",
3
- "version": "0.19.11",
3
+ "version": "0.19.14",
4
4
  "description": "AI context window cost analysis - detect fragmented code, deep import chains, and expensive context budgets",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -49,7 +49,7 @@
49
49
  "commander": "^14.0.0",
50
50
  "chalk": "^5.3.0",
51
51
  "prompts": "^2.4.2",
52
- "@aiready/core": "0.21.11"
52
+ "@aiready/core": "0.21.14"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^24.0.0",
@@ -89,7 +89,7 @@ export function buildDependencyGraph(
89
89
  options?.domainKeywords ?? extractDomainKeywordsFromPaths(files);
90
90
 
91
91
  for (const { file, content } of files) {
92
- const imports = extractImportsFromContent(content);
92
+ const imports = extractImportsFromContent(content, file);
93
93
  const exports = extractExportsWithAST(
94
94
  content,
95
95
  file,
@@ -132,22 +132,48 @@ export function buildDependencyGraph(
132
132
  }
133
133
 
134
134
  /**
135
- * Extract imports from file content using regex
135
+ * Extract imports from file content
136
136
  */
137
- export function extractImportsFromContent(content: string): string[] {
137
+ export function extractImportsFromContent(
138
+ content: string,
139
+ filePath?: string
140
+ ): string[] {
138
141
  const imports: string[] = [];
139
- const patterns = [
140
- /import\s+.*?\s+from\s+['"](.+?)['"]/g,
141
- /import\s+['"](.+?)['"]/g,
142
- /require\(['"](.+?)['"]\)/g,
143
- ];
144
-
145
- for (const pattern of patterns) {
146
- let match;
147
- while ((match = pattern.exec(content)) !== null) {
148
- const importPath = match[1];
149
- if (importPath && !importPath.startsWith('node:')) {
150
- imports.push(importPath);
142
+ const isPython = filePath?.toLowerCase().endsWith('.py');
143
+
144
+ if (isPython) {
145
+ const pythonPatterns = [
146
+ /^\s*import\s+([a-zA-Z0-9_., ]+)/gm,
147
+ /^\s*from\s+([a-zA-Z0-9_.]+)\s+import/gm,
148
+ ];
149
+
150
+ for (const pattern of pythonPatterns) {
151
+ let match;
152
+ while ((match = pattern.exec(content)) !== null) {
153
+ const importPath = match[1];
154
+ if (importPath) {
155
+ // Handle multiple imports in one line: import os, sys
156
+ const parts = importPath
157
+ .split(',')
158
+ .map((p) => p.trim().split(/\s+as\s+/)[0]);
159
+ imports.push(...parts);
160
+ }
161
+ }
162
+ }
163
+ } else {
164
+ const patterns = [
165
+ /import\s+.*?\s+from\s+['"](.+?)['"]/g,
166
+ /import\s+['"](.+?)['"]/g,
167
+ /require\(['"](.+?)['"]\)/g,
168
+ ];
169
+
170
+ for (const pattern of patterns) {
171
+ let match;
172
+ while ((match = pattern.exec(content)) !== null) {
173
+ const importPath = match[1];
174
+ if (importPath && !importPath.startsWith('node:')) {
175
+ imports.push(importPath);
176
+ }
151
177
  }
152
178
  }
153
179
  }