@aiready/context-analyzer 0.21.22 → 0.21.24

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.
Files changed (78) hide show
  1. package/.turbo/turbo-build.log +26 -25
  2. package/.turbo/turbo-lint.log +5 -5
  3. package/.turbo/turbo-test.log +91 -41
  4. package/coverage/clover.xml +2615 -1242
  5. package/coverage/coverage-final.json +30 -13
  6. package/coverage/dist/chunk-64U3PNO3.mjs.html +367 -0
  7. package/coverage/dist/chunk-J3MUOWHC.mjs.html +5326 -0
  8. package/coverage/dist/index.html +146 -0
  9. package/coverage/{classifier.ts.html → dist/index.mjs.html} +537 -912
  10. package/coverage/index.html +84 -189
  11. package/coverage/src/analyzer.ts.html +88 -0
  12. package/coverage/src/analyzers/index.html +116 -0
  13. package/coverage/src/analyzers/python-context.ts.html +910 -0
  14. package/coverage/{ast-utils.ts.html → src/ast-utils.ts.html} +84 -54
  15. package/coverage/src/classifier.ts.html +892 -0
  16. package/coverage/src/classify/classification-patterns.ts.html +307 -0
  17. package/coverage/src/classify/file-classifiers.ts.html +973 -0
  18. package/coverage/src/classify/index.html +131 -0
  19. package/coverage/{cluster-detector.ts.html → src/cluster-detector.ts.html} +154 -91
  20. package/coverage/{defaults.ts.html → src/defaults.ts.html} +74 -65
  21. package/coverage/{graph-builder.ts.html → src/graph-builder.ts.html} +268 -229
  22. package/coverage/src/index.html +341 -0
  23. package/coverage/{index.ts.html → src/index.ts.html} +70 -13
  24. package/coverage/{scoring.ts.html → src/issue-analyzer.ts.html} +201 -261
  25. package/coverage/src/mapper.ts.html +439 -0
  26. package/coverage/{metrics.ts.html → src/metrics.ts.html} +201 -132
  27. package/coverage/src/orchestrator.ts.html +493 -0
  28. package/coverage/{provider.ts.html → src/provider.ts.html} +21 -21
  29. package/coverage/{remediation.ts.html → src/remediation.ts.html} +112 -52
  30. package/coverage/src/report/console-report.ts.html +415 -0
  31. package/coverage/src/report/html-report.ts.html +361 -0
  32. package/coverage/src/report/index.html +146 -0
  33. package/coverage/src/report/interactive-setup.ts.html +373 -0
  34. package/coverage/src/scoring.ts.html +895 -0
  35. package/coverage/src/semantic/co-usage.ts.html +340 -0
  36. package/coverage/src/semantic/consolidation.ts.html +223 -0
  37. package/coverage/src/semantic/domain-inference.ts.html +859 -0
  38. package/coverage/src/semantic/index.html +161 -0
  39. package/coverage/src/semantic/type-graph.ts.html +163 -0
  40. package/coverage/{summary.ts.html → src/summary.ts.html} +155 -275
  41. package/coverage/{types.ts.html → src/types.ts.html} +133 -31
  42. package/coverage/src/utils/dependency-graph-utils.ts.html +463 -0
  43. package/coverage/src/utils/index.html +131 -0
  44. package/coverage/src/utils/string-utils.ts.html +148 -0
  45. package/dist/chunk-AMPK6SWS.mjs +1754 -0
  46. package/dist/chunk-BHCRDEE4.mjs +1745 -0
  47. package/dist/chunk-IKRP7ECY.mjs +1754 -0
  48. package/dist/chunk-J3MUOWHC.mjs +1747 -0
  49. package/dist/chunk-TWWPY7FD.mjs +1754 -0
  50. package/dist/chunk-Z5WY6A4P.mjs +1754 -0
  51. package/dist/cli.js +77 -185
  52. package/dist/cli.mjs +1 -1
  53. package/dist/index.d.mts +1 -1
  54. package/dist/index.d.ts +1 -1
  55. package/dist/index.js +73 -181
  56. package/dist/index.mjs +1 -1
  57. package/dist/python-context-BWDC4E5Z.mjs +162 -0
  58. package/package.json +3 -3
  59. package/src/__tests__/analyzer.test.ts +14 -14
  60. package/src/__tests__/auto-detection.test.ts +16 -16
  61. package/src/__tests__/consolidation.test.ts +247 -0
  62. package/src/__tests__/defaults.test.ts +121 -0
  63. package/src/__tests__/domain-inference.test.ts +420 -0
  64. package/src/__tests__/fragmentation-coupling.test.ts +4 -4
  65. package/src/__tests__/issue-analyzer.test.ts +155 -0
  66. package/src/__tests__/orchestrator.test.ts +143 -0
  67. package/src/__tests__/python-context.test.ts +100 -0
  68. package/src/__tests__/report/console-report.test.ts +292 -0
  69. package/src/__tests__/report/html-report.test.ts +243 -0
  70. package/src/__tests__/scoring.test.ts +17 -11
  71. package/src/analyzers/python-context.ts +2 -2
  72. package/src/ast-utils.ts +3 -3
  73. package/src/graph-builder.ts +4 -4
  74. package/src/mapper.ts +6 -0
  75. package/src/orchestrator.ts +1 -1
  76. package/src/report/html-report.ts +73 -181
  77. package/coverage/analyzer.ts.html +0 -1369
  78. package/coverage/semantic-analysis.ts.html +0 -1201
package/dist/cli.js CHANGED
@@ -130,7 +130,7 @@ __export(python_context_exports, {
130
130
  });
131
131
  async function analyzePythonContext(files, rootDir) {
132
132
  const results = [];
133
- const parser = (0, import_core5.getParser)("dummy.py");
133
+ const parser = await (0, import_core5.getParser)("dummy.py");
134
134
  if (!parser) {
135
135
  console.warn("Python parser not available");
136
136
  return results;
@@ -194,7 +194,7 @@ async function analyzePythonContext(files, rootDir) {
194
194
  }
195
195
  async function buildPythonDependencyGraph(files, rootDir) {
196
196
  const graph = /* @__PURE__ */ new Map();
197
- const parser = (0, import_core5.getParser)("dummy.py");
197
+ const parser = await (0, import_core5.getParser)("dummy.py");
198
198
  if (!parser) return graph;
199
199
  for (const file of files) {
200
200
  try {
@@ -293,7 +293,7 @@ var init_python_context = __esm({
293
293
  var import_commander = require("commander");
294
294
 
295
295
  // src/cli-action.ts
296
- var import_core8 = require("@aiready/core");
296
+ var import_core9 = require("@aiready/core");
297
297
 
298
298
  // src/orchestrator.ts
299
299
  var import_core6 = require("@aiready/core");
@@ -490,9 +490,9 @@ function inferDomain(name, filePath, domainOptions, fileImports) {
490
490
  }
491
491
 
492
492
  // src/ast-utils.ts
493
- function extractExportsWithAST(content, filePath, domainOptions, fileImports) {
493
+ async function extractExportsWithAST(content, filePath, domainOptions, fileImports) {
494
494
  try {
495
- const { exports: astExports } = (0, import_core.parseFileExports)(content, filePath);
495
+ const { exports: astExports } = await (0, import_core.parseFileExports)(content, filePath);
496
496
  if (astExports.length === 0 && !isTestFile(filePath)) {
497
497
  return extractExports(content, filePath, domainOptions, fileImports);
498
498
  }
@@ -824,16 +824,16 @@ function extractDomainKeywordsFromPaths(files) {
824
824
  }
825
825
  return Array.from(folderNames);
826
826
  }
827
- function buildDependencyGraph(files, options) {
827
+ async function buildDependencyGraph(files, options) {
828
828
  const nodes = /* @__PURE__ */ new Map();
829
829
  const edges = /* @__PURE__ */ new Map();
830
830
  const autoDetectedKeywords = options?.domainKeywords ?? extractDomainKeywordsFromPaths(files);
831
831
  const allFilePaths = new Set(files.map((f) => f.file));
832
832
  for (const { file, content } of files) {
833
- const { imports: astImports } = (0, import_core4.parseFileExports)(content, file);
833
+ const { imports: astImports } = await (0, import_core4.parseFileExports)(content, file);
834
834
  const resolvedImports = astImports.map((i) => resolveImport(i.source, file, allFilePaths)).filter((path) => path !== null);
835
835
  const importSources = astImports.map((i) => i.source);
836
- const exports2 = extractExportsWithAST(
836
+ const exports2 = await extractExportsWithAST(
837
837
  content,
838
838
  file,
839
839
  { domainKeywords: autoDetectedKeywords },
@@ -1511,7 +1511,7 @@ async function analyzeContext(options) {
1511
1511
  content: await (0, import_core6.readFileContent)(file)
1512
1512
  }))
1513
1513
  );
1514
- const graph = buildDependencyGraph(
1514
+ const graph = await buildDependencyGraph(
1515
1515
  fileContents.filter((f) => !f.file.toLowerCase().endsWith(".py"))
1516
1516
  );
1517
1517
  let pythonResults = [];
@@ -1726,182 +1726,74 @@ function displayConsoleReport(summary, results, maxResults = 10) {
1726
1726
  }
1727
1727
 
1728
1728
  // src/report/html-report.ts
1729
+ var import_core8 = require("@aiready/core");
1729
1730
  function generateHTMLReport(summary, results) {
1730
1731
  const totalIssues = summary.criticalIssues + summary.majorIssues + summary.minorIssues;
1731
1732
  void results;
1732
- return `<!DOCTYPE html>
1733
- <html lang="en">
1734
- <head>
1735
- <meta charset="UTF-8">
1736
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
1737
- <title>aiready Context Analysis Report</title>
1738
- <style>
1739
- body {
1740
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
1741
- line-height: 1.6;
1742
- color: #333;
1743
- max-width: 1200px;
1744
- margin: 0 auto;
1745
- padding: 20px;
1746
- background-color: #f5f5f5;
1747
- }
1748
- h1, h2, h3 { color: #2c3e50; }
1749
- .header {
1750
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
1751
- color: white;
1752
- padding: 30px;
1753
- border-radius: 8px;
1754
- margin-bottom: 30px;
1755
- }
1756
- .summary {
1757
- display: grid;
1758
- grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
1759
- gap: 20px;
1760
- margin-bottom: 30px;
1761
- }
1762
- .card {
1763
- background: white;
1764
- padding: 20px;
1765
- border-radius: 8px;
1766
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
1767
- }
1768
- .metric {
1769
- font-size: 2em;
1770
- font-weight: bold;
1771
- color: #667eea;
1772
- }
1773
- .label {
1774
- color: #666;
1775
- font-size: 0.9em;
1776
- margin-top: 5px;
1777
- }
1778
- .issue-critical { color: #e74c3c; }
1779
- .issue-major { color: #f39c12; }
1780
- .issue-minor { color: #3498db; }
1781
- table {
1782
- width: 100%;
1783
- border-collapse: collapse;
1784
- background: white;
1785
- border-radius: 8px;
1786
- overflow: hidden;
1787
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
1788
- }
1789
- th, td {
1790
- padding: 12px;
1791
- text-align: left;
1792
- border-bottom: 1px solid #eee;
1793
- }
1794
- th {
1795
- background-color: #667eea;
1796
- color: white;
1797
- font-weight: 600;
1798
- }
1799
- tr:hover { background-color: #f8f9fa; }
1800
- .footer {
1801
- text-align: center;
1802
- margin-top: 40px;
1803
- padding: 20px;
1804
- color: #666;
1805
- font-size: 0.9em;
1733
+ const head = (0, import_core8.generateReportHead)("AIReady Context Analysis Report");
1734
+ const stats = (0, import_core8.generateStatCards)([
1735
+ { value: summary.totalFiles, label: "Files Analyzed" },
1736
+ { value: summary.totalTokens.toLocaleString(), label: "Total Tokens" },
1737
+ { value: summary.avgContextBudget.toFixed(0), label: "Avg Context Budget" },
1738
+ {
1739
+ value: totalIssues,
1740
+ label: "Total Issues",
1741
+ color: totalIssues > 0 ? "#f39c12" : void 0
1806
1742
  }
1807
- </style>
1808
- </head>
1743
+ ]);
1744
+ const hero = (0, import_core8.generateReportHero)(
1745
+ "\u{1F50D} AIReady Context Analysis Report",
1746
+ `Generated on ${(/* @__PURE__ */ new Date()).toLocaleString()}`
1747
+ );
1748
+ let body = `${hero}
1749
+ ${stats}`;
1750
+ if (totalIssues > 0) {
1751
+ body += (0, import_core8.generateIssueSummary)(
1752
+ summary.criticalIssues,
1753
+ summary.majorIssues,
1754
+ summary.minorIssues,
1755
+ summary.totalPotentialSavings
1756
+ );
1757
+ }
1758
+ if (summary.fragmentedModules.length > 0) {
1759
+ const fragmentedRows = summary.fragmentedModules.map((m) => [
1760
+ m.domain,
1761
+ String(m.files.length),
1762
+ `${(m.fragmentationScore * 100).toFixed(0)}%`,
1763
+ m.totalTokens.toLocaleString()
1764
+ ]);
1765
+ body += (0, import_core8.wrapInCard)(
1766
+ (0, import_core8.generateTable)({
1767
+ headers: ["Domain", "Files", "Fragmentation", "Token Cost"],
1768
+ rows: fragmentedRows
1769
+ }),
1770
+ "\u{1F9E9} Fragmented Modules"
1771
+ );
1772
+ }
1773
+ if (summary.topExpensiveFiles.length > 0) {
1774
+ const expensiveRows = summary.topExpensiveFiles.map((f) => [
1775
+ f.file,
1776
+ `${f.contextBudget.toLocaleString()} tokens`,
1777
+ `<span class="issue-${f.severity}">${f.severity.toUpperCase()}</span>`
1778
+ ]);
1779
+ body += (0, import_core8.wrapInCard)(
1780
+ (0, import_core8.generateTable)({
1781
+ headers: ["File", "Context Budget", "Severity"],
1782
+ rows: expensiveRows
1783
+ }),
1784
+ "\u{1F4B8} Most Expensive Files"
1785
+ );
1786
+ }
1787
+ const footer = (0, import_core8.generateReportFooter)({
1788
+ title: "Context Analysis Report",
1789
+ packageName: "context-analyzer",
1790
+ packageUrl: "https://github.com/caopengau/aiready-context-analyzer",
1791
+ bugUrl: "https://github.com/caopengau/aiready-context-analyzer/issues"
1792
+ });
1793
+ return `${head}
1809
1794
  <body>
1810
- <div class="header">
1811
- <h1>\u{1F50D} AIReady Context Analysis Report</h1>
1812
- <p>Generated on ${(/* @__PURE__ */ new Date()).toLocaleString()}</p>
1813
- </div>
1814
-
1815
- <div class="summary">
1816
- <div class="card">
1817
- <div class="metric">${summary.totalFiles}</div>
1818
- <div class="label">Files Analyzed</div>
1819
- </div>
1820
- <div class="card">
1821
- <div class="metric">${summary.totalTokens.toLocaleString()}</div>
1822
- <div class="label">Total Tokens</div>
1823
- </div>
1824
- <div class="card">
1825
- <div class="metric">${summary.avgContextBudget.toFixed(0)}</div>
1826
- <div class="label">Avg Context Budget</div>
1827
- </div>
1828
- <div class="card">
1829
- <div class="metric ${totalIssues > 0 ? "issue-major" : ""}">${totalIssues}</div>
1830
- <div class="label">Total Issues</div>
1831
- </div>
1832
- </div>
1833
-
1834
- ${totalIssues > 0 ? `
1835
- <div class="card" style="margin-bottom: 30px;">
1836
- <h2>\u26A0\uFE0F Issues Summary</h2>
1837
- <p>
1838
- <span class="issue-critical">\u{1F534} Critical: ${summary.criticalIssues}</span> &nbsp;
1839
- <span class="issue-major">\u{1F7E1} Major: ${summary.majorIssues}</span> &nbsp;
1840
- <span class="issue-minor">\u{1F535} Minor: ${summary.minorIssues}</span>
1841
- </p>
1842
- <p><strong>Potential Savings:</strong> ${summary.totalPotentialSavings.toLocaleString()} tokens</p>
1843
- </div>
1844
- ` : ""}
1845
-
1846
- ${summary.fragmentedModules.length > 0 ? `
1847
- <div class="card" style="margin-bottom: 30px;">
1848
- <h2>\u{1F9E9} Fragmented Modules</h2>
1849
- <table>
1850
- <thead>
1851
- <tr>
1852
- <th>Domain</th>
1853
- <th>Files</th>
1854
- <th>Fragmentation</th>
1855
- <th>Token Cost</th>
1856
- </tr>
1857
- </thead>
1858
- <tbody>
1859
- ${summary.fragmentedModules.map(
1860
- (m) => `
1861
- <tr>
1862
- <td>${m.domain}</td>
1863
- <td>${m.files.length}</td>
1864
- <td>${(m.fragmentationScore * 100).toFixed(0)}%</td>
1865
- <td>${m.totalTokens.toLocaleString()}</td>
1866
- </tr>
1867
- `
1868
- ).join("")}
1869
- </tbody>
1870
- </table>
1871
- </div>
1872
- ` : ""}
1873
-
1874
- ${summary.topExpensiveFiles.length > 0 ? `
1875
- <div class="card" style="margin-bottom: 30px;">
1876
- <h2>\u{1F4B8} Most Expensive Files</h2>
1877
- <table>
1878
- <thead>
1879
- <tr>
1880
- <th>File</th>
1881
- <th>Context Budget</th>
1882
- <th>Severity</th>
1883
- </tr>
1884
- </thead>
1885
- <tbody>
1886
- ${summary.topExpensiveFiles.map(
1887
- (f) => `
1888
- <tr>
1889
- <td>${f.file}</td>
1890
- <td>${f.contextBudget.toLocaleString()} tokens</td>
1891
- <td class="issue-${f.severity}">${f.severity.toUpperCase()}</td>
1892
- </tr>
1893
- `
1894
- ).join("")}
1895
- </tbody>
1896
- </table>
1897
- </div>
1898
- ` : ""}
1899
-
1900
- <div class="footer">
1901
- <p>Generated by <strong>@aiready/context-analyzer</strong></p>
1902
- <p>Like AIReady? <a href="https://github.com/caopengau/aiready-context-analyzer">Star us on GitHub</a></p>
1903
- <p>Found a bug? <a href="https://github.com/caopengau/aiready-context-analyzer/issues">Report it here</a></p>
1904
- </div>
1795
+ ${body}
1796
+ ${footer}
1905
1797
  </body>
1906
1798
  </html>`;
1907
1799
  }
@@ -1997,7 +1889,7 @@ async function contextActionHandler(directory, options) {
1997
1889
  exclude: void 0,
1998
1890
  maxResults: 10
1999
1891
  };
2000
- let finalOptions = await (0, import_core8.loadMergedConfig)(directory, defaults, {
1892
+ let finalOptions = await (0, import_core9.loadMergedConfig)(directory, defaults, {
2001
1893
  maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
2002
1894
  maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
2003
1895
  minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
@@ -2013,9 +1905,9 @@ async function contextActionHandler(directory, options) {
2013
1905
  }
2014
1906
  const results = await analyzeContext(finalOptions);
2015
1907
  const summary = generateSummary(results, finalOptions);
2016
- const duration = (0, import_core8.getElapsedTime)(startTime);
1908
+ const duration = (0, import_core9.getElapsedTime)(startTime);
2017
1909
  if (options.output === "json") {
2018
- (0, import_core8.handleJSONOutput)(
1910
+ (0, import_core9.handleJSONOutput)(
2019
1911
  {
2020
1912
  summary: {
2021
1913
  ...summary,
@@ -2032,7 +1924,7 @@ async function contextActionHandler(directory, options) {
2032
1924
  );
2033
1925
  } else if (options.output === "html") {
2034
1926
  const html = generateHTMLReport(summary, results);
2035
- const outputPath = (0, import_core8.resolveOutputPath)(
1927
+ const outputPath = (0, import_core9.resolveOutputPath)(
2036
1928
  directory,
2037
1929
  options.outputFile,
2038
1930
  "context-report.html"
@@ -2047,7 +1939,7 @@ async function contextActionHandler(directory, options) {
2047
1939
  `));
2048
1940
  }
2049
1941
  } catch (error) {
2050
- (0, import_core8.handleCLIError)(error, "context-analyzer");
1942
+ (0, import_core9.handleCLIError)(error, "context-analyzer");
2051
1943
  }
2052
1944
  }
2053
1945
 
package/dist/cli.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  generateHTMLReport,
6
6
  generateSummary,
7
7
  runInteractiveSetup
8
- } from "./chunk-CBWM3EK5.mjs";
8
+ } from "./chunk-Z5WY6A4P.mjs";
9
9
  import "./chunk-64U3PNO3.mjs";
10
10
 
11
11
  // src/cli.ts
package/dist/index.d.mts CHANGED
@@ -196,7 +196,7 @@ declare function extractDomainKeywordsFromPaths(files: FileContent[]): string[];
196
196
  */
197
197
  declare function buildDependencyGraph(files: FileContent[], options?: {
198
198
  domainKeywords?: string[];
199
- }): DependencyGraph;
199
+ }): Promise<DependencyGraph>;
200
200
  /**
201
201
  * Calculate the maximum depth of the import tree for a specific file.
202
202
  *
package/dist/index.d.ts CHANGED
@@ -196,7 +196,7 @@ declare function extractDomainKeywordsFromPaths(files: FileContent[]): string[];
196
196
  */
197
197
  declare function buildDependencyGraph(files: FileContent[], options?: {
198
198
  domainKeywords?: string[];
199
- }): DependencyGraph;
199
+ }): Promise<DependencyGraph>;
200
200
  /**
201
201
  * Calculate the maximum depth of the import tree for a specific file.
202
202
  *