@aiready/context-analyzer 0.3.3 → 0.3.4

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.3.3 build /Users/pengcao/projects/aiready/packages/context-analyzer
3
+ > @aiready/context-analyzer@0.3.4 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/cli.mjs 14.00 KB
13
- ESM dist/chunk-T6ZCOPPI.mjs 17.25 KB
12
+ ESM dist/cli.mjs 13.36 KB
14
13
  ESM dist/index.mjs 124.00 B
15
- ESM ⚡️ Build success in 54ms
16
- CJS dist/cli.js 33.27 KB
14
+ ESM dist/chunk-T6ZCOPPI.mjs 17.25 KB
15
+ ESM ⚡️ Build success in 60ms
17
16
  CJS dist/index.js 18.33 KB
18
- CJS ⚡️ Build success in 54ms
17
+ CJS dist/cli.js 32.57 KB
18
+ CJS ⚡️ Build success in 61ms
19
19
  DTS Build start
20
- DTS ⚡️ Build success in 596ms
20
+ DTS ⚡️ Build success in 654ms
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
@@ -583,7 +583,6 @@ program.name("aiready-context").description("Analyze AI context window cost and
583
583
  console.log(import_chalk.default.blue("\u{1F50D} Analyzing context window costs...\n"));
584
584
  const startTime = Date.now();
585
585
  try {
586
- const config = (0, import_core3.loadConfig)(directory);
587
586
  const defaults = {
588
587
  maxDepth: 5,
589
588
  maxContextBudget: 1e4,
@@ -595,21 +594,19 @@ program.name("aiready-context").description("Analyze AI context window cost and
595
594
  exclude: void 0,
596
595
  maxResults: 10
597
596
  };
598
- const mergedConfig = (0, import_core3.mergeConfigWithDefaults)(config, defaults);
599
- const finalOptions = {
600
- rootDir: directory,
601
- maxDepth: options.maxDepth ? parseInt(options.maxDepth) : mergedConfig.maxDepth,
602
- maxContextBudget: options.maxContext ? parseInt(options.maxContext) : mergedConfig.maxContextBudget,
603
- minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : mergedConfig.minCohesion,
604
- maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : mergedConfig.maxFragmentation,
605
- focus: options.focus || mergedConfig.focus,
606
- includeNodeModules: options.includeNodeModules !== void 0 ? options.includeNodeModules : mergedConfig.includeNodeModules,
607
- include: options.include?.split(",") || mergedConfig.include,
608
- exclude: options.exclude?.split(",") || mergedConfig.exclude,
609
- maxResults: options.maxResults ? parseInt(options.maxResults) : mergedConfig.maxResults
610
- };
597
+ const finalOptions = (0, import_core3.loadMergedConfig)(directory, defaults, {
598
+ maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
599
+ maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
600
+ minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
601
+ maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : void 0,
602
+ focus: options.focus || void 0,
603
+ includeNodeModules: options.includeNodeModules,
604
+ include: options.include?.split(","),
605
+ exclude: options.exclude?.split(","),
606
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0
607
+ });
611
608
  const results = await analyzeContext(finalOptions);
612
- const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(2);
609
+ const elapsedTime = (0, import_core3.getElapsedTime)(startTime);
613
610
  const summary = generateSummary(results);
614
611
  if (options.output === "json") {
615
612
  const jsonOutput = {
@@ -618,18 +615,8 @@ program.name("aiready-context").description("Analyze AI context window cost and
618
615
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
619
616
  analysisTime: elapsedTime
620
617
  };
621
- if (options.outputFile) {
622
- (0, import_fs.writeFileSync)(
623
- options.outputFile,
624
- JSON.stringify(jsonOutput, null, 2)
625
- );
626
- console.log(
627
- import_chalk.default.green(`
628
- \u2713 JSON report saved to ${options.outputFile}`)
629
- );
630
- } else {
631
- console.log(JSON.stringify(jsonOutput, null, 2));
632
- }
618
+ (0, import_core3.handleJSONOutput)(jsonOutput, options.outputFile, `
619
+ \u2713 JSON report saved to ${options.outputFile}`);
633
620
  return;
634
621
  }
635
622
  if (options.output === "html") {
@@ -642,9 +629,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
642
629
  }
643
630
  displayConsoleReport(summary, results, elapsedTime, finalOptions.maxResults);
644
631
  } catch (error) {
645
- console.error(import_chalk.default.red("\n\u274C Analysis failed:"));
646
- console.error(import_chalk.default.red(error instanceof Error ? error.message : String(error)));
647
- process.exit(1);
632
+ (0, import_core3.handleCLIError)(error, "Analysis");
648
633
  }
649
634
  });
650
635
  program.parse();
package/dist/cli.mjs CHANGED
@@ -9,7 +9,7 @@ import { Command } from "commander";
9
9
  import chalk from "chalk";
10
10
  import { writeFileSync } from "fs";
11
11
  import { join } from "path";
12
- import { loadConfig, mergeConfigWithDefaults } from "@aiready/core";
12
+ import { loadMergedConfig, handleJSONOutput, handleCLIError, getElapsedTime } from "@aiready/core";
13
13
  var program = new Command();
14
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>",
@@ -28,7 +28,6 @@ program.name("aiready-context").description("Analyze AI context window cost and
28
28
  console.log(chalk.blue("\u{1F50D} Analyzing context window costs...\n"));
29
29
  const startTime = Date.now();
30
30
  try {
31
- const config = loadConfig(directory);
32
31
  const defaults = {
33
32
  maxDepth: 5,
34
33
  maxContextBudget: 1e4,
@@ -40,21 +39,19 @@ program.name("aiready-context").description("Analyze AI context window cost and
40
39
  exclude: void 0,
41
40
  maxResults: 10
42
41
  };
43
- const mergedConfig = mergeConfigWithDefaults(config, defaults);
44
- const finalOptions = {
45
- rootDir: directory,
46
- maxDepth: options.maxDepth ? parseInt(options.maxDepth) : mergedConfig.maxDepth,
47
- maxContextBudget: options.maxContext ? parseInt(options.maxContext) : mergedConfig.maxContextBudget,
48
- minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : mergedConfig.minCohesion,
49
- maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : mergedConfig.maxFragmentation,
50
- focus: options.focus || mergedConfig.focus,
51
- includeNodeModules: options.includeNodeModules !== void 0 ? options.includeNodeModules : mergedConfig.includeNodeModules,
52
- include: options.include?.split(",") || mergedConfig.include,
53
- exclude: options.exclude?.split(",") || mergedConfig.exclude,
54
- maxResults: options.maxResults ? parseInt(options.maxResults) : mergedConfig.maxResults
55
- };
42
+ const finalOptions = loadMergedConfig(directory, defaults, {
43
+ maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
44
+ maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
45
+ minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
46
+ maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : void 0,
47
+ focus: options.focus || void 0,
48
+ includeNodeModules: options.includeNodeModules,
49
+ include: options.include?.split(","),
50
+ exclude: options.exclude?.split(","),
51
+ maxResults: options.maxResults ? parseInt(options.maxResults) : void 0
52
+ });
56
53
  const results = await analyzeContext(finalOptions);
57
- const elapsedTime = ((Date.now() - startTime) / 1e3).toFixed(2);
54
+ const elapsedTime = getElapsedTime(startTime);
58
55
  const summary = generateSummary(results);
59
56
  if (options.output === "json") {
60
57
  const jsonOutput = {
@@ -63,18 +60,8 @@ program.name("aiready-context").description("Analyze AI context window cost and
63
60
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
64
61
  analysisTime: elapsedTime
65
62
  };
66
- if (options.outputFile) {
67
- writeFileSync(
68
- options.outputFile,
69
- JSON.stringify(jsonOutput, null, 2)
70
- );
71
- console.log(
72
- chalk.green(`
73
- \u2713 JSON report saved to ${options.outputFile}`)
74
- );
75
- } else {
76
- console.log(JSON.stringify(jsonOutput, null, 2));
77
- }
63
+ handleJSONOutput(jsonOutput, options.outputFile, `
64
+ \u2713 JSON report saved to ${options.outputFile}`);
78
65
  return;
79
66
  }
80
67
  if (options.output === "html") {
@@ -87,9 +74,7 @@ program.name("aiready-context").description("Analyze AI context window cost and
87
74
  }
88
75
  displayConsoleReport(summary, results, elapsedTime, finalOptions.maxResults);
89
76
  } catch (error) {
90
- console.error(chalk.red("\n\u274C Analysis failed:"));
91
- console.error(chalk.red(error instanceof Error ? error.message : String(error)));
92
- process.exit(1);
77
+ handleCLIError(error, "Analysis");
93
78
  }
94
79
  });
95
80
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/context-analyzer",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
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.3.1"
52
+ "@aiready/core": "0.3.2"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^22.10.2",
package/src/cli.ts CHANGED
@@ -5,7 +5,7 @@ import { analyzeContext, generateSummary } from './index';
5
5
  import chalk from 'chalk';
6
6
  import { writeFileSync } from 'fs';
7
7
  import { join } from 'path';
8
- import { loadConfig, mergeConfigWithDefaults } from '@aiready/core';
8
+ import { loadMergedConfig, handleJSONOutput, handleCLIError, getElapsedTime } from '@aiready/core';
9
9
 
10
10
  const program = new Command();
11
11
 
@@ -45,9 +45,6 @@ program
45
45
  const startTime = Date.now();
46
46
 
47
47
  try {
48
- // Load config file if it exists
49
- const config = loadConfig(directory);
50
-
51
48
  // Define defaults
52
49
  const defaults = {
53
50
  maxDepth: 5,
@@ -61,26 +58,22 @@ program
61
58
  maxResults: 10,
62
59
  };
63
60
 
64
- // Merge config with defaults
65
- const mergedConfig = mergeConfigWithDefaults(config, defaults);
66
-
67
- // Override with CLI options (CLI takes precedence)
68
- const finalOptions = {
69
- rootDir: directory,
70
- maxDepth: options.maxDepth ? parseInt(options.maxDepth) : mergedConfig.maxDepth,
71
- maxContextBudget: options.maxContext ? parseInt(options.maxContext) : mergedConfig.maxContextBudget,
72
- minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : mergedConfig.minCohesion,
73
- maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : mergedConfig.maxFragmentation,
74
- focus: (options.focus || mergedConfig.focus) as any,
75
- includeNodeModules: options.includeNodeModules !== undefined ? options.includeNodeModules : mergedConfig.includeNodeModules,
76
- include: options.include?.split(',') || mergedConfig.include,
77
- exclude: options.exclude?.split(',') || mergedConfig.exclude,
78
- maxResults: options.maxResults ? parseInt(options.maxResults) : mergedConfig.maxResults,
79
- };
61
+ // Load and merge config with CLI options
62
+ const finalOptions = loadMergedConfig(directory, defaults, {
63
+ maxDepth: options.maxDepth ? parseInt(options.maxDepth) : undefined,
64
+ maxContextBudget: options.maxContext ? parseInt(options.maxContext) : undefined,
65
+ minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : undefined,
66
+ maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : undefined,
67
+ focus: (options.focus as 'fragmentation' | 'cohesion' | 'depth' | 'all') || undefined,
68
+ includeNodeModules: options.includeNodeModules,
69
+ include: options.include?.split(','),
70
+ exclude: options.exclude?.split(','),
71
+ maxResults: options.maxResults ? parseInt(options.maxResults) : undefined,
72
+ }) as any;
80
73
 
81
74
  const results = await analyzeContext(finalOptions);
82
75
 
83
- const elapsedTime = ((Date.now() - startTime) / 1000).toFixed(2);
76
+ const elapsedTime = getElapsedTime(startTime);
84
77
  const summary = generateSummary(results);
85
78
 
86
79
  if (options.output === 'json') {
@@ -91,17 +84,7 @@ program
91
84
  analysisTime: elapsedTime,
92
85
  };
93
86
 
94
- if (options.outputFile) {
95
- writeFileSync(
96
- options.outputFile,
97
- JSON.stringify(jsonOutput, null, 2)
98
- );
99
- console.log(
100
- chalk.green(`\n✓ JSON report saved to ${options.outputFile}`)
101
- );
102
- } else {
103
- console.log(JSON.stringify(jsonOutput, null, 2));
104
- }
87
+ handleJSONOutput(jsonOutput, options.outputFile, `\n✓ JSON report saved to ${options.outputFile}`);
105
88
  return;
106
89
  }
107
90
 
@@ -117,9 +100,7 @@ program
117
100
  // Console output
118
101
  displayConsoleReport(summary, results, elapsedTime, finalOptions.maxResults);
119
102
  } catch (error) {
120
- console.error(chalk.red('\n❌ Analysis failed:'));
121
- console.error(chalk.red(error instanceof Error ? error.message : String(error)));
122
- process.exit(1);
103
+ handleCLIError(error, 'Analysis');
123
104
  }
124
105
  });
125
106