@aiready/context-analyzer 0.2.0 → 0.3.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.
@@ -1,6 +1,6 @@
1
1
 
2
2
  
3
- > @aiready/context-analyzer@0.2.0 build /Users/pengcao/projects/aiready/packages/context-analyzer
3
+ > @aiready/context-analyzer@0.3.0 build /Users/pengcao/projects/aiready/packages/context-analyzer
4
4
  > tsup src/index.ts src/cli.ts --format cjs,esm --dts
5
5
 
6
6
  CLI Building entry: src/cli.ts, src/index.ts
@@ -9,15 +9,15 @@
9
9
  CLI Target: es2020
10
10
  CJS Build start
11
11
  ESM Build start
12
- ESM dist/chunk-T6ZCOPPI.mjs 17.25 KB
12
+ ESM dist/cli.mjs 13.82 KB
13
13
  ESM dist/index.mjs 124.00 B
14
- ESM dist/cli.mjs 13.59 KB
15
- ESM ⚡️ Build success in 74ms
16
- CJS dist/cli.js 32.86 KB
14
+ ESM dist/chunk-T6ZCOPPI.mjs 17.25 KB
15
+ ESM ⚡️ Build success in 15ms
17
16
  CJS dist/index.js 18.33 KB
18
- CJS ⚡️ Build success in 74ms
17
+ CJS dist/cli.js 33.09 KB
18
+ CJS ⚡️ Build success in 16ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 630ms
20
+ DTS ⚡️ Build success in 622ms
21
21
  DTS dist/cli.d.ts 20.00 B
22
22
  DTS dist/index.d.ts 2.14 KB
23
23
  DTS dist/cli.d.mts 20.00 B
package/dist/cli.js CHANGED
@@ -566,19 +566,16 @@ var import_fs = require("fs");
566
566
  var import_path = require("path");
567
567
  var import_core3 = require("@aiready/core");
568
568
  var program = new import_commander.Command();
569
- program.name("aiready-context").description("Analyze AI context window cost and code structure").version("0.1.0").addHelpText("after", "\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings").argument("<directory>", "Directory to analyze").option("--max-depth <number>", "Maximum acceptable import depth", "5").option(
569
+ program.name("aiready-context").description("Analyze AI context window cost and code structure").version("0.1.0").addHelpText("after", "\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings").argument("<directory>", "Directory to analyze").option("--max-depth <number>", "Maximum acceptable import depth").option(
570
570
  "--max-context <number>",
571
- "Maximum acceptable context budget (tokens)",
572
- "10000"
573
- ).option("--min-cohesion <number>", "Minimum acceptable cohesion score (0-1)", "0.6").option(
571
+ "Maximum acceptable context budget (tokens)"
572
+ ).option("--min-cohesion <number>", "Minimum acceptable cohesion score (0-1)").option(
574
573
  "--max-fragmentation <number>",
575
- "Maximum acceptable fragmentation (0-1)",
576
- "0.5"
574
+ "Maximum acceptable fragmentation (0-1)"
577
575
  ).option(
578
576
  "--focus <type>",
579
- "Analysis focus: fragmentation, cohesion, depth, all",
580
- "all"
581
- ).option("--include-node-modules", "Include node_modules in analysis", false).option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option(
577
+ "Analysis focus: fragmentation, cohesion, depth, all"
578
+ ).option("--include-node-modules", "Include node_modules in analysis").option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option("--max-results <number>", "Maximum number of results to show in console output").option(
582
579
  "-o, --output <format>",
583
580
  "Output format: console, json, html",
584
581
  "console"
@@ -595,7 +592,8 @@ program.name("aiready-context").description("Analyze AI context window cost and
595
592
  focus: "all",
596
593
  includeNodeModules: false,
597
594
  include: void 0,
598
- exclude: void 0
595
+ exclude: void 0,
596
+ maxResults: 10
599
597
  };
600
598
  const mergedConfig = (0, import_core3.mergeConfigWithDefaults)(config, defaults);
601
599
  const finalOptions = {
@@ -607,7 +605,8 @@ program.name("aiready-context").description("Analyze AI context window cost and
607
605
  focus: options.focus || mergedConfig.focus,
608
606
  includeNodeModules: options.includeNodeModules !== void 0 ? options.includeNodeModules : mergedConfig.includeNodeModules,
609
607
  include: options.include?.split(",") || mergedConfig.include,
610
- exclude: options.exclude?.split(",") || mergedConfig.exclude
608
+ exclude: options.exclude?.split(",") || mergedConfig.exclude,
609
+ maxResults: options.maxResults ? parseInt(options.maxResults) : mergedConfig.maxResults
611
610
  };
612
611
  const results = await analyzeContext(finalOptions);
613
612
  const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(2);
@@ -641,7 +640,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
641
640
  \u2713 HTML report saved to ${outputPath}`));
642
641
  return;
643
642
  }
644
- displayConsoleReport(summary, results, elapsedTime);
643
+ displayConsoleReport(summary, results, elapsedTime, finalOptions.maxResults);
645
644
  } catch (error) {
646
645
  console.error(import_chalk.default.red("\n\u274C Analysis failed:"));
647
646
  console.error(import_chalk.default.red(error instanceof Error ? error.message : String(error)));
@@ -649,7 +648,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
649
648
  }
650
649
  });
651
650
  program.parse();
652
- function displayConsoleReport(summary, results, elapsedTime) {
651
+ function displayConsoleReport(summary, results, elapsedTime, maxResults = 10) {
653
652
  const terminalWidth = process.stdout.columns || 80;
654
653
  const dividerWidth = Math.min(60, terminalWidth - 2);
655
654
  const divider = "\u2501".repeat(dividerWidth);
@@ -702,7 +701,7 @@ function displayConsoleReport(summary, results, elapsedTime) {
702
701
  );
703
702
  console.log(import_chalk.default.gray(` Maximum depth: ${summary.maxImportDepth}
704
703
  `));
705
- summary.deepFiles.slice(0, 5).forEach((item) => {
704
+ summary.deepFiles.slice(0, maxResults).forEach((item) => {
706
705
  const fileName = item.file.split("/").slice(-2).join("/");
707
706
  console.log(
708
707
  ` ${import_chalk.default.cyan("\u2192")} ${import_chalk.default.white(fileName)} ${import_chalk.default.dim(`(depth: ${item.depth})`)}`
@@ -718,7 +717,7 @@ function displayConsoleReport(summary, results, elapsedTime) {
718
717
  `
719
718
  )
720
719
  );
721
- summary.fragmentedModules.slice(0, 5).forEach((module2) => {
720
+ summary.fragmentedModules.slice(0, maxResults).forEach((module2) => {
722
721
  console.log(
723
722
  ` ${import_chalk.default.yellow("\u25CF")} ${import_chalk.default.white(module2.domain)} - ${import_chalk.default.dim(`${module2.files.length} files, ${(module2.fragmentationScore * 100).toFixed(0)}% scattered`)}`
724
723
  );
@@ -738,7 +737,7 @@ function displayConsoleReport(summary, results, elapsedTime) {
738
737
  `
739
738
  )
740
739
  );
741
- summary.lowCohesionFiles.slice(0, 5).forEach((item) => {
740
+ summary.lowCohesionFiles.slice(0, maxResults).forEach((item) => {
742
741
  const fileName = item.file.split("/").slice(-2).join("/");
743
742
  const scorePercent = (item.score * 100).toFixed(0);
744
743
  const color = item.score < 0.4 ? import_chalk.default.red : import_chalk.default.yellow;
@@ -750,7 +749,7 @@ function displayConsoleReport(summary, results, elapsedTime) {
750
749
  }
751
750
  if (summary.topExpensiveFiles.length > 0) {
752
751
  console.log(import_chalk.default.bold("\u{1F4B8} Most Expensive Files (Context Budget):\n"));
753
- summary.topExpensiveFiles.slice(0, 5).forEach((item) => {
752
+ summary.topExpensiveFiles.slice(0, maxResults).forEach((item) => {
754
753
  const fileName = item.file.split("/").slice(-2).join("/");
755
754
  const severityColor = item.severity === "critical" ? import_chalk.default.red : item.severity === "major" ? import_chalk.default.yellow : import_chalk.default.blue;
756
755
  console.log(
package/dist/cli.mjs CHANGED
@@ -11,19 +11,16 @@ import { writeFileSync } from "fs";
11
11
  import { join } from "path";
12
12
  import { loadConfig, mergeConfigWithDefaults } from "@aiready/core";
13
13
  var program = new Command();
14
- program.name("aiready-context").description("Analyze AI context window cost and code structure").version("0.1.0").addHelpText("after", "\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings").argument("<directory>", "Directory to analyze").option("--max-depth <number>", "Maximum acceptable import depth", "5").option(
14
+ program.name("aiready-context").description("Analyze AI context window cost and code structure").version("0.1.0").addHelpText("after", "\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings").argument("<directory>", "Directory to analyze").option("--max-depth <number>", "Maximum acceptable import depth").option(
15
15
  "--max-context <number>",
16
- "Maximum acceptable context budget (tokens)",
17
- "10000"
18
- ).option("--min-cohesion <number>", "Minimum acceptable cohesion score (0-1)", "0.6").option(
16
+ "Maximum acceptable context budget (tokens)"
17
+ ).option("--min-cohesion <number>", "Minimum acceptable cohesion score (0-1)").option(
19
18
  "--max-fragmentation <number>",
20
- "Maximum acceptable fragmentation (0-1)",
21
- "0.5"
19
+ "Maximum acceptable fragmentation (0-1)"
22
20
  ).option(
23
21
  "--focus <type>",
24
- "Analysis focus: fragmentation, cohesion, depth, all",
25
- "all"
26
- ).option("--include-node-modules", "Include node_modules in analysis", false).option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option(
22
+ "Analysis focus: fragmentation, cohesion, depth, all"
23
+ ).option("--include-node-modules", "Include node_modules in analysis").option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option("--max-results <number>", "Maximum number of results to show in console output").option(
27
24
  "-o, --output <format>",
28
25
  "Output format: console, json, html",
29
26
  "console"
@@ -40,7 +37,8 @@ program.name("aiready-context").description("Analyze AI context window cost and
40
37
  focus: "all",
41
38
  includeNodeModules: false,
42
39
  include: void 0,
43
- exclude: void 0
40
+ exclude: void 0,
41
+ maxResults: 10
44
42
  };
45
43
  const mergedConfig = mergeConfigWithDefaults(config, defaults);
46
44
  const finalOptions = {
@@ -52,7 +50,8 @@ program.name("aiready-context").description("Analyze AI context window cost and
52
50
  focus: options.focus || mergedConfig.focus,
53
51
  includeNodeModules: options.includeNodeModules !== void 0 ? options.includeNodeModules : mergedConfig.includeNodeModules,
54
52
  include: options.include?.split(",") || mergedConfig.include,
55
- exclude: options.exclude?.split(",") || mergedConfig.exclude
53
+ exclude: options.exclude?.split(",") || mergedConfig.exclude,
54
+ maxResults: options.maxResults ? parseInt(options.maxResults) : mergedConfig.maxResults
56
55
  };
57
56
  const results = await analyzeContext(finalOptions);
58
57
  const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(2);
@@ -86,7 +85,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
86
85
  \u2713 HTML report saved to ${outputPath}`));
87
86
  return;
88
87
  }
89
- displayConsoleReport(summary, results, elapsedTime);
88
+ displayConsoleReport(summary, results, elapsedTime, finalOptions.maxResults);
90
89
  } catch (error) {
91
90
  console.error(chalk.red("\n\u274C Analysis failed:"));
92
91
  console.error(chalk.red(error instanceof Error ? error.message : String(error)));
@@ -94,7 +93,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
94
93
  }
95
94
  });
96
95
  program.parse();
97
- function displayConsoleReport(summary, results, elapsedTime) {
96
+ function displayConsoleReport(summary, results, elapsedTime, maxResults = 10) {
98
97
  const terminalWidth = process.stdout.columns || 80;
99
98
  const dividerWidth = Math.min(60, terminalWidth - 2);
100
99
  const divider = "\u2501".repeat(dividerWidth);
@@ -147,7 +146,7 @@ function displayConsoleReport(summary, results, elapsedTime) {
147
146
  );
148
147
  console.log(chalk.gray(` Maximum depth: ${summary.maxImportDepth}
149
148
  `));
150
- summary.deepFiles.slice(0, 5).forEach((item) => {
149
+ summary.deepFiles.slice(0, maxResults).forEach((item) => {
151
150
  const fileName = item.file.split("/").slice(-2).join("/");
152
151
  console.log(
153
152
  ` ${chalk.cyan("\u2192")} ${chalk.white(fileName)} ${chalk.dim(`(depth: ${item.depth})`)}`
@@ -163,7 +162,7 @@ function displayConsoleReport(summary, results, elapsedTime) {
163
162
  `
164
163
  )
165
164
  );
166
- summary.fragmentedModules.slice(0, 5).forEach((module) => {
165
+ summary.fragmentedModules.slice(0, maxResults).forEach((module) => {
167
166
  console.log(
168
167
  ` ${chalk.yellow("\u25CF")} ${chalk.white(module.domain)} - ${chalk.dim(`${module.files.length} files, ${(module.fragmentationScore * 100).toFixed(0)}% scattered`)}`
169
168
  );
@@ -183,7 +182,7 @@ function displayConsoleReport(summary, results, elapsedTime) {
183
182
  `
184
183
  )
185
184
  );
186
- summary.lowCohesionFiles.slice(0, 5).forEach((item) => {
185
+ summary.lowCohesionFiles.slice(0, maxResults).forEach((item) => {
187
186
  const fileName = item.file.split("/").slice(-2).join("/");
188
187
  const scorePercent = (item.score * 100).toFixed(0);
189
188
  const color = item.score < 0.4 ? chalk.red : chalk.yellow;
@@ -195,7 +194,7 @@ function displayConsoleReport(summary, results, elapsedTime) {
195
194
  }
196
195
  if (summary.topExpensiveFiles.length > 0) {
197
196
  console.log(chalk.bold("\u{1F4B8} Most Expensive Files (Context Budget):\n"));
198
- summary.topExpensiveFiles.slice(0, 5).forEach((item) => {
197
+ summary.topExpensiveFiles.slice(0, maxResults).forEach((item) => {
199
198
  const fileName = item.file.split("/").slice(-2).join("/");
200
199
  const severityColor = item.severity === "critical" ? chalk.red : item.severity === "major" ? chalk.yellow : chalk.blue;
201
200
  console.log(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/context-analyzer",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
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
  "dependencies": {
50
50
  "commander": "^12.1.0",
51
51
  "chalk": "^5.3.0",
52
- "@aiready/core": "0.2.4"
52
+ "@aiready/core": "0.3.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^22.10.2",
package/src/cli.ts CHANGED
@@ -15,26 +15,24 @@ program
15
15
  .version('0.1.0')
16
16
  .addHelpText('after', '\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings')
17
17
  .argument('<directory>', 'Directory to analyze')
18
- .option('--max-depth <number>', 'Maximum acceptable import depth', '5')
18
+ .option('--max-depth <number>', 'Maximum acceptable import depth')
19
19
  .option(
20
20
  '--max-context <number>',
21
- 'Maximum acceptable context budget (tokens)',
22
- '10000'
21
+ 'Maximum acceptable context budget (tokens)'
23
22
  )
24
- .option('--min-cohesion <number>', 'Minimum acceptable cohesion score (0-1)', '0.6')
23
+ .option('--min-cohesion <number>', 'Minimum acceptable cohesion score (0-1)')
25
24
  .option(
26
25
  '--max-fragmentation <number>',
27
- 'Maximum acceptable fragmentation (0-1)',
28
- '0.5'
26
+ 'Maximum acceptable fragmentation (0-1)'
29
27
  )
30
28
  .option(
31
29
  '--focus <type>',
32
- 'Analysis focus: fragmentation, cohesion, depth, all',
33
- 'all'
30
+ 'Analysis focus: fragmentation, cohesion, depth, all'
34
31
  )
35
- .option('--include-node-modules', 'Include node_modules in analysis', false)
32
+ .option('--include-node-modules', 'Include node_modules in analysis')
36
33
  .option('--include <patterns>', 'File patterns to include (comma-separated)')
37
34
  .option('--exclude <patterns>', 'File patterns to exclude (comma-separated)')
35
+ .option('--max-results <number>', 'Maximum number of results to show in console output')
38
36
  .option(
39
37
  '-o, --output <format>',
40
38
  'Output format: console, json, html',
@@ -60,6 +58,7 @@ program
60
58
  includeNodeModules: false,
61
59
  include: undefined,
62
60
  exclude: undefined,
61
+ maxResults: 10,
63
62
  };
64
63
 
65
64
  // Merge config with defaults
@@ -76,6 +75,7 @@ program
76
75
  includeNodeModules: options.includeNodeModules !== undefined ? options.includeNodeModules : mergedConfig.includeNodeModules,
77
76
  include: options.include?.split(',') || mergedConfig.include,
78
77
  exclude: options.exclude?.split(',') || mergedConfig.exclude,
78
+ maxResults: options.maxResults ? parseInt(options.maxResults) : mergedConfig.maxResults,
79
79
  };
80
80
 
81
81
  const results = await analyzeContext(finalOptions);
@@ -115,7 +115,7 @@ program
115
115
  }
116
116
 
117
117
  // Console output
118
- displayConsoleReport(summary, results, elapsedTime);
118
+ displayConsoleReport(summary, results, elapsedTime, finalOptions.maxResults);
119
119
  } catch (error) {
120
120
  console.error(chalk.red('\n❌ Analysis failed:'));
121
121
  console.error(chalk.red(error instanceof Error ? error.message : String(error)));
@@ -131,7 +131,8 @@ program.parse();
131
131
  function displayConsoleReport(
132
132
  summary: ReturnType<typeof generateSummary>,
133
133
  results: Awaited<ReturnType<typeof analyzeContext>>,
134
- elapsedTime: string
134
+ elapsedTime: string,
135
+ maxResults: number = 10
135
136
  ) {
136
137
  const terminalWidth = process.stdout.columns || 80;
137
138
  const dividerWidth = Math.min(60, terminalWidth - 2);
@@ -190,7 +191,7 @@ function displayConsoleReport(
190
191
  );
191
192
  console.log(chalk.gray(` Maximum depth: ${summary.maxImportDepth}\n`));
192
193
 
193
- summary.deepFiles.slice(0, 5).forEach((item) => {
194
+ summary.deepFiles.slice(0, maxResults).forEach((item) => {
194
195
  const fileName = item.file.split('/').slice(-2).join('/');
195
196
  console.log(
196
197
  ` ${chalk.cyan('→')} ${chalk.white(fileName)} ${chalk.dim(`(depth: ${item.depth})`)}`
@@ -208,7 +209,7 @@ function displayConsoleReport(
208
209
  )
209
210
  );
210
211
 
211
- summary.fragmentedModules.slice(0, 5).forEach((module) => {
212
+ summary.fragmentedModules.slice(0, maxResults).forEach((module) => {
212
213
  console.log(
213
214
  ` ${chalk.yellow('●')} ${chalk.white(module.domain)} - ${chalk.dim(`${module.files.length} files, ${(module.fragmentationScore * 100).toFixed(0)}% scattered`)}`
214
215
  );
@@ -230,7 +231,7 @@ function displayConsoleReport(
230
231
  )
231
232
  );
232
233
 
233
- summary.lowCohesionFiles.slice(0, 5).forEach((item) => {
234
+ summary.lowCohesionFiles.slice(0, maxResults).forEach((item) => {
234
235
  const fileName = item.file.split('/').slice(-2).join('/');
235
236
  const scorePercent = (item.score * 100).toFixed(0);
236
237
  const color = item.score < 0.4 ? chalk.red : chalk.yellow;
@@ -245,7 +246,7 @@ function displayConsoleReport(
245
246
  if (summary.topExpensiveFiles.length > 0) {
246
247
  console.log(chalk.bold('💸 Most Expensive Files (Context Budget):\n'));
247
248
 
248
- summary.topExpensiveFiles.slice(0, 5).forEach((item) => {
249
+ summary.topExpensiveFiles.slice(0, maxResults).forEach((item) => {
249
250
  const fileName = item.file.split('/').slice(-2).join('/');
250
251
  const severityColor =
251
252
  item.severity === 'critical'