@aiready/context-analyzer 0.1.0 → 0.1.2

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.
@@ -38,8 +38,8 @@ describe('calculateImportDepth', () => {
38
38
  it('should calculate import depth correctly', () => {
39
39
  const files = [
40
40
  { file: 'a.ts', content: 'export const a = 1;' },
41
- { file: 'b.ts', content: 'import { a } from "./a";\nexport const b = a;' },
42
- { file: 'c.ts', content: 'import { b } from "./b";\nexport const c = b;' },
41
+ { file: 'b.ts', content: 'import { a } from "a.ts";\nexport const b = a;' },
42
+ { file: 'c.ts', content: 'import { b } from "b.ts";\nexport const c = b;' },
43
43
  ];
44
44
 
45
45
  const graph = buildDependencyGraph(files);
@@ -67,15 +67,15 @@ describe('getTransitiveDependencies', () => {
67
67
  it('should get all transitive dependencies', () => {
68
68
  const files = [
69
69
  { file: 'a.ts', content: 'export const a = 1;' },
70
- { file: 'b.ts', content: 'import { a } from "./a";\nexport const b = a;' },
71
- { file: 'c.ts', content: 'import { b } from "./b";\nexport const c = b;' },
70
+ { file: 'b.ts', content: 'import { a } from "a.ts";\nexport const b = a;' },
71
+ { file: 'c.ts', content: 'import { b } from "b.ts";\nexport const c = b;' },
72
72
  ];
73
73
 
74
74
  const graph = buildDependencyGraph(files);
75
75
  const deps = getTransitiveDependencies('c.ts', graph);
76
76
 
77
- expect(deps).toContain('./b');
78
- expect(deps).toContain('./a');
77
+ expect(deps).toContain('b.ts');
78
+ expect(deps).toContain('a.ts');
79
79
  expect(deps.length).toBe(2);
80
80
  });
81
81
  });
@@ -98,8 +98,8 @@ describe('calculateContextBudget', () => {
98
98
  describe('detectCircularDependencies', () => {
99
99
  it('should detect circular dependencies', () => {
100
100
  const files = [
101
- { file: 'a.ts', content: 'import { b } from "./b";\nexport const a = 1;' },
102
- { file: 'b.ts', content: 'import { a } from "./a";\nexport const b = 2;' },
101
+ { file: 'a.ts', content: 'import { b } from "b.ts";\nexport const a = 1;' },
102
+ { file: 'b.ts', content: 'import { a } from "a.ts";\nexport const b = 2;' },
103
103
  ];
104
104
 
105
105
  const graph = buildDependencyGraph(files);
@@ -111,7 +111,7 @@ describe('detectCircularDependencies', () => {
111
111
  it('should return empty for no circular dependencies', () => {
112
112
  const files = [
113
113
  { file: 'a.ts', content: 'export const a = 1;' },
114
- { file: 'b.ts', content: 'import { a } from "./a";\nexport const b = a;' },
114
+ { file: 'b.ts', content: 'import { a } from "a.ts";\nexport const b = a;' },
115
115
  ];
116
116
 
117
117
  const graph = buildDependencyGraph(files);
package/src/cli.ts CHANGED
@@ -5,6 +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
9
 
9
10
  const program = new Command();
10
11
 
@@ -45,17 +46,38 @@ program
45
46
  const startTime = Date.now();
46
47
 
47
48
  try {
48
- const results = await analyzeContext({
49
+ // Load config file if it exists
50
+ const config = loadConfig(directory);
51
+
52
+ // Define defaults
53
+ const defaults = {
54
+ maxDepth: 5,
55
+ maxContextBudget: 10000,
56
+ minCohesion: 0.6,
57
+ maxFragmentation: 0.5,
58
+ focus: 'all',
59
+ includeNodeModules: false,
60
+ include: undefined,
61
+ exclude: undefined,
62
+ };
63
+
64
+ // Merge config with defaults
65
+ const mergedConfig = mergeConfigWithDefaults(config, defaults);
66
+
67
+ // Override with CLI options (CLI takes precedence)
68
+ const finalOptions = {
49
69
  rootDir: directory,
50
- maxDepth: parseInt(options.maxDepth),
51
- maxContextBudget: parseInt(options.maxContext),
52
- minCohesion: parseFloat(options.minCohesion),
53
- maxFragmentation: parseFloat(options.maxFragmentation),
54
- focus: options.focus as any,
55
- includeNodeModules: options.includeNodeModules,
56
- include: options.include?.split(','),
57
- exclude: options.exclude?.split(','),
58
- });
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
+ };
79
+
80
+ const results = await analyzeContext(finalOptions);
59
81
 
60
82
  const elapsedTime = ((Date.now() - startTime) / 1000).toFixed(2);
61
83
  const summary = generateSummary(results);