@aiready/context-analyzer 0.9.11 → 0.9.12

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.9.11 build /Users/pengcao/projects/aiready/packages/context-analyzer
3
+ > @aiready/context-analyzer@0.9.12 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
@@ -11,15 +11,15 @@
11
11
  ESM Build start
12
12
  ESM dist/cli.mjs 18.53 KB
13
13
  ESM dist/index.mjs 585.00 B
14
- ESM dist/chunk-BD4NWUVG.mjs 42.75 KB
15
14
  ESM dist/chunk-Y6FXYEAI.mjs 390.00 B
15
+ ESM dist/chunk-BD4NWUVG.mjs 42.75 KB
16
16
  ESM dist/python-context-UOPTQH44.mjs 5.64 KB
17
- ESM ⚡️ Build success in 84ms
18
- CJS dist/cli.js 62.78 KB
17
+ ESM ⚡️ Build success in 195ms
19
18
  CJS dist/index.js 51.03 KB
20
- CJS ⚡️ Build success in 85ms
19
+ CJS dist/cli.js 62.78 KB
20
+ CJS ⚡️ Build success in 226ms
21
21
  DTS Build start
22
- DTS ⚡️ Build success in 4202ms
22
+ DTS ⚡️ Build success in 4457ms
23
23
  DTS dist/cli.d.ts 20.00 B
24
24
  DTS dist/index.d.ts 6.03 KB
25
25
  DTS dist/cli.d.mts 20.00 B
@@ -1,31 +1,32 @@
1
1
 
2
2
  
3
- > @aiready/context-analyzer@0.9.11 test /Users/pengcao/projects/aiready/packages/context-analyzer
3
+ > @aiready/context-analyzer@0.9.12 test /Users/pengcao/projects/aiready/packages/context-analyzer
4
4
  > vitest run
5
5
 
6
6
  [?25l
7
7
   RUN  v4.0.18 /Users/pengcao/projects/aiready/packages/context-analyzer
8
8
 
9
- ✓ src/__tests__/scoring.test.ts (7 tests) 3ms
10
- ✓ dist/__tests__/scoring.test.js (7 tests) 5ms
11
- ✓ dist/__tests__/auto-detection.test.js (8 tests) 117ms
12
- ✓ src/__tests__/fragmentation-advanced.test.ts (3 tests) 3ms
13
- ✓ src/__tests__/fragmentation-log.test.ts (3 tests) 18ms
14
- ✓ src/__tests__/fragmentation-coupling.test.ts (2 tests) 52ms
15
- ✓ dist/__tests__/fragmentation-advanced.test.js (3 tests) 3ms
16
- ✓ dist/__tests__/analyzer.test.js (14 tests) 128ms
17
- ✓ dist/__tests__/fragmentation-coupling.test.js (2 tests) 113ms
18
- ✓ src/__tests__/auto-detection.test.ts (8 tests) 220ms
19
- ✓ src/__tests__/analyzer.test.ts (14 tests) 252ms
9
+ ✓ dist/__tests__/scoring.test.js (7 tests) 4ms
10
+ ✓ dist/__tests__/structural-cohesion.test.js (4 tests) 9ms
11
+ ✓ src/__tests__/auto-detection.test.ts (8 tests) 419ms
12
+ ✓ should auto-detect domain keywords from folder paths  329ms
13
+ ✓ src/__tests__/structural-cohesion.test.ts (4 tests) 3ms
14
+ ✓ src/__tests__/fragmentation-coupling.test.ts (2 tests) 28ms
15
+ ✓ dist/__tests__/fragmentation-coupling.test.js (2 tests) 19ms
16
+ ✓ dist/__tests__/fragmentation-advanced.test.js (3 tests) 7ms
17
+ ✓ dist/__tests__/analyzer.test.js (14 tests) 315ms
18
+ ✓ src/__tests__/fragmentation-log.test.ts (3 tests) 8ms
19
+ ✓ dist/__tests__/auto-detection.test.js (8 tests) 334ms
20
+ ✓ src/__tests__/analyzer.test.ts (14 tests) 299ms
21
+ ✓ src/__tests__/scoring.test.ts (7 tests) 9ms
22
+ ✓ dist/__tests__/enhanced-cohesion.test.js (6 tests) 2ms
23
+ ✓ dist/__tests__/fragmentation-log.test.js (3 tests) 4ms
24
+ ✓ src/__tests__/fragmentation-advanced.test.ts (3 tests) 2ms
20
25
  ✓ src/__tests__/enhanced-cohesion.test.ts (6 tests) 2ms
21
- ✓ dist/__tests__/fragmentation-log.test.js (3 tests) 3ms
22
- ✓ dist/__tests__/structural-cohesion.test.js (4 tests) 34ms
23
- ✓ src/__tests__/structural-cohesion.test.ts (4 tests) 6ms
24
- ✓ dist/__tests__/enhanced-cohesion.test.js (6 tests) 3ms
25
26
 
26
27
   Test Files  16 passed (16)
27
28
   Tests  94 passed (94)
28
-  Start at  19:26:06
29
-  Duration  6.62s (transform 12.96s, setup 0ms, import 38.59s, tests 962ms, environment 34ms)
29
+  Start at  22:06:57
30
+  Duration  6.34s (transform 5.67s, setup 0ms, import 32.10s, tests 1.46s, environment 22ms)
30
31
 
31
32
  [?25h
package/CONTRIBUTING.md CHANGED
@@ -1,10 +1,19 @@
1
- # Contributing to @aiready/pattern-detect
1
+ # Contributing to @aiready/context-analyzer
2
2
 
3
- Thank you for your interest in contributing to AIReady Pattern Detection! We welcome bug reports, feature requests, and code contributions.
3
+ Thank you for your interest in contributing to AIReady Context Analyzer! We welcome bug reports, feature requests, and code contributions.
4
+
5
+ ## 🎯 What is Context Analyzer?
6
+
7
+ The Context Analyzer measures and optimizes **context window usage** - how much of your codebase an AI model must understand to work with any given file. It helps identify:
8
+
9
+ - **High context cost files**: Files that require loading many dependencies
10
+ - **Deep import chains**: Complex dependency graphs that waste tokens
11
+ - **Low cohesion modules**: Files that import too many unrelated concerns
12
+ - **Context fragmentation**: Places where important code is scattered
4
13
 
5
14
  ## 🐛 Reporting Issues
6
15
 
7
- Found a bug or have a feature request? [Open an issue](https://github.com/caopengau/aiready-pattern-detect/issues) with:
16
+ Found a bug or have a feature request? [Open an issue](https://github.com/caopengau/aiready-context-analyzer/issues) with:
8
17
  - Clear description of the problem or feature
9
18
  - Sample code that demonstrates the issue
10
19
  - Expected vs actual behavior
@@ -14,8 +23,8 @@ Found a bug or have a feature request? [Open an issue](https://github.com/caopen
14
23
 
15
24
  ```bash
16
25
  # Clone your fork
17
- git clone https://github.com/YOUR_USERNAME/aiready-pattern-detect
18
- cd aiready-pattern-detect
26
+ git clone https://github.com/YOUR_USERNAME/aiready-context-analyzer
27
+ cd aiready-context-analyzer
19
28
 
20
29
  # Install dependencies
21
30
  pnpm install
@@ -34,16 +43,16 @@ pnpm test
34
43
 
35
44
  1. **Fork the repository** and create a new branch:
36
45
  ```bash
37
- git checkout -b fix/similarity-calculation
46
+ git checkout -b fix/import-depth-calculation
38
47
  # or
39
- git checkout -b feat/new-pattern-type
48
+ git checkout -b feat/new-metric
40
49
  ```
41
50
 
42
51
  2. **Make your changes** following our code style:
43
52
  - Use TypeScript strict mode
44
- - Add tests for new pattern types
53
+ - Add tests for new metrics
45
54
  - Update README with new features
46
- - Keep detection logic modular
55
+ - Keep analysis logic modular and focused
47
56
 
48
57
  3. **Test your changes**:
49
58
  ```bash
@@ -56,21 +65,21 @@ pnpm test
56
65
 
57
66
  4. **Commit using conventional commits**:
58
67
  ```bash
59
- git commit -m "fix: improve similarity threshold accuracy"
60
- git commit -m "feat: add React component pattern detection"
68
+ git commit -m "fix: accurate import depth calculation"
69
+ git commit -m "feat: add cohesion metric"
61
70
  ```
62
71
 
63
72
  5. **Push and open a PR**:
64
73
  ```bash
65
- git push origin feat/new-pattern-type
74
+ git push origin feat/new-metric
66
75
  ```
67
76
 
68
77
  ## 📋 Commit Convention
69
78
 
70
79
  We use [Conventional Commits](https://www.conventionalcommits.org/):
71
80
 
72
- - `feat:` - New feature (new pattern type, output format)
73
- - `fix:` - Bug fix (detection accuracy, false positives)
81
+ - `feat:` - New feature (new metric, output format)
82
+ - `fix:` - Bug fix (calculation accuracy, false positives)
74
83
  - `docs:` - Documentation updates
75
84
  - `perf:` - Performance improvements
76
85
  - `refactor:` - Code restructuring
@@ -78,28 +87,67 @@ We use [Conventional Commits](https://www.conventionalcommits.org/):
78
87
 
79
88
  ## 🧪 Testing Guidelines
80
89
 
81
- - Add test cases in `src/__tests__/detector.test.ts`
82
- - Include real-world pattern examples
83
- - Test edge cases (empty files, single-line functions)
84
- - Verify output formats (console, JSON, HTML)
90
+ - Add test cases in `src/__tests__/`
91
+ - Include real-world code examples
92
+ - Test edge cases (empty files, circular imports)
93
+ - Verify output formats (console, JSON)
85
94
 
86
95
  Example test:
87
96
  ```typescript
88
- test('detects API handler patterns', () => {
89
- const results = detectDuplicatePatterns([...]);
90
- expect(results).toHaveLength(2);
91
- expect(results[0].patternType).toBe('api-handler');
97
+ test('calculates import depth correctly', () => {
98
+ const result = analyzeFile('src/utils/helper.ts', [...files]);
99
+ expect(result.contextCost).toBe(1500);
100
+ expect(result.importDepth).toBe(3);
92
101
  });
93
102
  ```
94
103
 
104
+ ## 🏗️ Architecture
105
+
106
+ ### Directory Structure
107
+
108
+ ```
109
+ src/
110
+ ├── analyzer.ts # Main orchestrator
111
+ ├── metrics/
112
+ │ ├── contextCost.ts # Token cost estimation
113
+ │ ├── importDepth.ts # Dependency depth analysis
114
+ │ ├── cohesion.ts # Module cohesion scoring
115
+ │ └── fragmentation.ts # Context fragmentation detection
116
+ ├── types.ts # Type definitions
117
+ ├── cli.ts # CLI interface
118
+ └── index.ts # Public API exports
119
+ ```
120
+
121
+ ### Adding a New Metric
122
+
123
+ 1. Create `src/metrics/your-metric.ts`:
124
+ ```typescript
125
+ import type { FileAnalysis } from '../types';
126
+
127
+ export function calculateYourMetric(file: FileAnalysis): number {
128
+ // Your calculation logic
129
+ return metricValue;
130
+ }
131
+ ```
132
+
133
+ 2. Update `src/types.ts` with new result types
134
+
135
+ 3. Integrate in `src/analyzer.ts`
136
+
137
+ 4. Add CLI options in `src/cli.ts`
138
+
139
+ 5. Export from `src/index.ts`
140
+
141
+ 6. Add tests in `src/__tests__/`
142
+
95
143
  ## 🎯 Areas for Contribution
96
144
 
97
145
  Great places to start:
98
- - **New pattern types**: Add detection for new code patterns
99
- - **Better categorization**: Improve pattern type classification
100
- - **Detection accuracy**: Reduce false positives/negatives
146
+ - **New metrics**: Add new context quality measurements
147
+ - **Better calculations**: Improve token estimation accuracy
148
+ - **Language support**: Add analysis for more file types
101
149
  - **Performance**: Optimize for large codebases
102
- - **Output formats**: Add new export options
150
+ - **Visualization**: Add output formats or reports
103
151
  - **Documentation**: Usage examples, best practices
104
152
 
105
153
  ## 🔍 Code Review
@@ -112,18 +160,18 @@ Great places to start:
112
160
  ## 📚 Documentation
113
161
 
114
162
  - Update README.md for new features
115
- - Add examples for new pattern types
163
+ - Add examples for new metrics
116
164
  - Document CLI options
117
165
  - Include real-world use cases
118
166
 
119
167
  ## 💡 Feature Ideas
120
168
 
121
169
  Looking for inspiration? Consider:
122
- - Language-specific pattern types (Go, Rust, etc.)
123
- - Integration with popular linters
124
- - VS Code extension
125
- - CI/CD report generation
126
- - Pattern suggestion improvements
170
+ - Language-specific context costs (TypeScript vs Python)
171
+ - Framework-aware analysis (React hooks, Vue composables)
172
+ - Bundle size estimation
173
+ - Hot path analysis
174
+ - IDE integration
127
175
 
128
176
  ## ❓ Questions?
129
177
 
@@ -131,4 +179,4 @@ Open an issue or reach out to the maintainers. We're here to help!
131
179
 
132
180
  ---
133
181
 
134
- **Thank you for helping make AI-generated code better!** 💙
182
+ **Thank you for helping optimize AI context usage!** 💙
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/context-analyzer",
3
- "version": "0.9.11",
3
+ "version": "0.9.12",
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.9.11"
52
+ "@aiready/core": "0.9.12"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^24.0.0",