@aiready/context-analyzer 0.22.7 → 0.22.8

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.
@@ -0,0 +1,95 @@
1
+ import {
2
+ displayConsoleReport,
3
+ generateHTMLReport,
4
+ runInteractiveSetup
5
+ } from "./chunk-J3SZQZNU.mjs";
6
+ import {
7
+ analyzeContext
8
+ } from "./chunk-ZA7HRDAH.mjs";
9
+ import "./chunk-64U3PNO3.mjs";
10
+ import {
11
+ generateSummary
12
+ } from "./chunk-BTDF2ZA4.mjs";
13
+ import "./chunk-JSM7Q5CY.mjs";
14
+
15
+ // src/cli-action.ts
16
+ import {
17
+ loadMergedConfig,
18
+ handleJSONOutput,
19
+ handleCLIError,
20
+ getElapsedTime,
21
+ resolveOutputPath
22
+ } from "@aiready/core";
23
+ import chalk from "chalk";
24
+ import { writeFileSync } from "fs";
25
+ async function contextActionHandler(directory, options) {
26
+ console.log(chalk.blue("\u{1F50D} Analyzing context window costs...\n"));
27
+ const startTime = Date.now();
28
+ try {
29
+ const defaults = {
30
+ maxDepth: 5,
31
+ maxContextBudget: 1e4,
32
+ minCohesion: 0.6,
33
+ maxFragmentation: 0.5,
34
+ focus: "all",
35
+ includeNodeModules: false,
36
+ include: void 0,
37
+ exclude: void 0,
38
+ maxResults: 10
39
+ };
40
+ let finalOptions = await loadMergedConfig(directory, defaults, {
41
+ maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
42
+ maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
43
+ minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
44
+ maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : void 0,
45
+ focus: options.focus || void 0,
46
+ includeNodeModules: options.includeNodeModules,
47
+ include: options.include?.split(","),
48
+ exclude: options.exclude?.split(","),
49
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0
50
+ });
51
+ if (options.interactive) {
52
+ finalOptions = await runInteractiveSetup(directory, finalOptions);
53
+ }
54
+ const results = await analyzeContext(finalOptions);
55
+ const summary = generateSummary(results, finalOptions);
56
+ const duration = getElapsedTime(startTime);
57
+ if (options.output === "json") {
58
+ handleJSONOutput(
59
+ {
60
+ summary: {
61
+ ...summary,
62
+ executionTime: duration,
63
+ config: {
64
+ scan: { tools: ["context"] },
65
+ tools: { context: finalOptions }
66
+ },
67
+ toolConfigs: { context: finalOptions }
68
+ },
69
+ context: { results }
70
+ },
71
+ options.outputFile
72
+ );
73
+ } else if (options.output === "html") {
74
+ const html = generateHTMLReport(summary, results);
75
+ const outputPath = resolveOutputPath(
76
+ directory,
77
+ options.outputFile,
78
+ "context-report.html"
79
+ );
80
+ writeFileSync(outputPath, html, "utf-8");
81
+ console.log(chalk.green(`
82
+ \u2705 HTML report saved to: ${outputPath}`));
83
+ } else {
84
+ displayConsoleReport(summary, results, finalOptions.maxResults);
85
+ console.log(chalk.dim(`
86
+ \u2728 Analysis completed in ${duration}ms
87
+ `));
88
+ }
89
+ } catch (error) {
90
+ handleCLIError(error, "context-analyzer");
91
+ }
92
+ }
93
+ export {
94
+ contextActionHandler
95
+ };
package/dist/cli.js CHANGED
@@ -60,8 +60,14 @@ function calculateEnhancedCohesion(exports2, filePath, options) {
60
60
  if (exp1Imports || exp2Imports) {
61
61
  anyImportData = true;
62
62
  const sim = (0, import_core.calculateImportSimilarity)(
63
- { ...exports2[i], imports: exp1Imports || [] },
64
- { ...exports2[j], imports: exp2Imports || [] }
63
+ {
64
+ ...exports2[i],
65
+ imports: exp1Imports || []
66
+ },
67
+ {
68
+ ...exports2[j],
69
+ imports: exp2Imports || []
70
+ }
65
71
  );
66
72
  importScoreTotal += sim;
67
73
  pairsWithData++;
package/dist/cli.mjs CHANGED
@@ -37,7 +37,7 @@ function defineContextCommand(program2) {
37
37
  "--interactive",
38
38
  "Run interactive setup to suggest excludes and focus areas"
39
39
  ).action(async (directory, options) => {
40
- const { contextActionHandler } = await import("./cli-action-VCXBZGZP.mjs");
40
+ const { contextActionHandler } = await import("./cli-action-HREY7TK5.mjs");
41
41
  await contextActionHandler(directory, options);
42
42
  });
43
43
  }
package/dist/index.js CHANGED
@@ -60,8 +60,14 @@ function calculateEnhancedCohesion(exports2, filePath, options) {
60
60
  if (exp1Imports || exp2Imports) {
61
61
  anyImportData = true;
62
62
  const sim = (0, import_core2.calculateImportSimilarity)(
63
- { ...exports2[i], imports: exp1Imports || [] },
64
- { ...exports2[j], imports: exp2Imports || [] }
63
+ {
64
+ ...exports2[i],
65
+ imports: exp1Imports || []
66
+ },
67
+ {
68
+ ...exports2[j],
69
+ imports: exp2Imports || []
70
+ }
65
71
  );
66
72
  importScoreTotal += sim;
67
73
  pairsWithData++;
package/dist/index.mjs CHANGED
@@ -48,18 +48,18 @@ import {
48
48
  isSessionFile,
49
49
  isTypeDefinition,
50
50
  isUtilityModule
51
- } from "./chunk-M2EGQ36M.mjs";
51
+ } from "./chunk-ZA7HRDAH.mjs";
52
52
  import "./chunk-64U3PNO3.mjs";
53
53
  import {
54
54
  generateSummary
55
- } from "./chunk-BQCISA2F.mjs";
55
+ } from "./chunk-BTDF2ZA4.mjs";
56
56
  import {
57
57
  calculateDirectoryDistance,
58
58
  calculateEnhancedCohesion,
59
59
  calculateFragmentation,
60
60
  calculatePathEntropy,
61
61
  calculateStructuralCohesionFromCoUsage
62
- } from "./chunk-EMYD7NS6.mjs";
62
+ } from "./chunk-JSM7Q5CY.mjs";
63
63
 
64
64
  // src/index.ts
65
65
  import { ToolRegistry } from "@aiready/core";
@@ -266,8 +266,8 @@ var ContextAnalyzerProvider = {
266
266
  id: ToolName2.ContextAnalyzer,
267
267
  alias: ["context", "fragmentation", "budget"],
268
268
  async analyze(options) {
269
- const { analyzeContext: analyzeContext2 } = await import("./orchestrator-KMAKMHTD.mjs");
270
- const { generateSummary: generateSummary2 } = await import("./summary-7PZVW72O.mjs");
269
+ const { analyzeContext: analyzeContext2 } = await import("./orchestrator-62YVSQFV.mjs");
270
+ const { generateSummary: generateSummary2 } = await import("./summary-RSPRRY6S.mjs");
271
271
  const results = await analyzeContext2(options);
272
272
  const summary = generateSummary2(results, options);
273
273
  const normalizedResults = results.map(
@@ -0,0 +1,10 @@
1
+ import {
2
+ analyzeContext,
3
+ calculateCohesion
4
+ } from "./chunk-ZA7HRDAH.mjs";
5
+ import "./chunk-64U3PNO3.mjs";
6
+ import "./chunk-JSM7Q5CY.mjs";
7
+ export {
8
+ analyzeContext,
9
+ calculateCohesion
10
+ };
@@ -0,0 +1,7 @@
1
+ import {
2
+ generateSummary
3
+ } from "./chunk-BTDF2ZA4.mjs";
4
+ import "./chunk-JSM7Q5CY.mjs";
5
+ export {
6
+ generateSummary
7
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/context-analyzer",
3
- "version": "0.22.7",
3
+ "version": "0.22.8",
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.24.7"
52
+ "@aiready/core": "0.24.8"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^24.0.0",
@@ -68,6 +68,8 @@
68
68
  "test": "vitest run --exclude \"**/dist/**\"",
69
69
  "lint": "eslint src",
70
70
  "clean": "rm -rf dist",
71
- "release": "pnpm build && pnpm publish --no-git-checks"
71
+ "release": "pnpm build && pnpm publish --no-git-checks",
72
+ "type-check": "tsc --noEmit",
73
+ "format-check": "prettier --check . --ignore-path ../../.prettierignore"
72
74
  }
73
75
  }
package/src/metrics.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { calculateImportSimilarity, isTestFile } from '@aiready/core';
2
- import type { ExportInfo } from '@aiready/core';
2
+ import type { ExportInfo, ExportWithImports } from '@aiready/core';
3
3
 
4
4
  /**
5
5
  * Calculates a cohesion score (0-1) for a module based on its exports,
@@ -29,7 +29,7 @@ export function calculateEnhancedCohesion(
29
29
  if (filePath && isTestFile(filePath)) return 1;
30
30
 
31
31
  // 1. Domain-based cohesion using entropy
32
- const domains = exports.map((e: any) => e.inferredDomain || 'unknown');
32
+ const domains = exports.map((e: ExportInfo) => e.inferredDomain || 'unknown');
33
33
  const domainCounts = new Map<string, number>();
34
34
  for (const domain of domains)
35
35
  domainCounts.set(domain, (domainCounts.get(domain) || 0) + 1);
@@ -63,8 +63,14 @@ export function calculateEnhancedCohesion(
63
63
  if (exp1Imports || exp2Imports) {
64
64
  anyImportData = true;
65
65
  const sim = calculateImportSimilarity(
66
- { ...exports[i], imports: exp1Imports || [] } as any,
67
- { ...exports[j], imports: exp2Imports || [] } as any
66
+ {
67
+ ...exports[i],
68
+ imports: exp1Imports || [],
69
+ } as unknown as ExportWithImports,
70
+ {
71
+ ...exports[j],
72
+ imports: exp2Imports || [],
73
+ } as unknown as ExportWithImports
68
74
  );
69
75
  importScoreTotal += sim;
70
76
  pairsWithData++;