@aiready/context-analyzer 0.9.20 → 0.9.22

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.20 build /Users/pengcao/projects/aiready/packages/context-analyzer
3
+ > @aiready/context-analyzer@0.9.22 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
  CJS dist/cli.js 62.68 KB
13
13
  CJS dist/index.js 50.93 KB
14
- CJS ⚡️ Build success in 83ms
15
- ESM dist/cli.mjs 18.53 KB
16
- ESM dist/chunk-VTALAPQZ.mjs 42.65 KB
17
- ESM dist/chunk-Y6FXYEAI.mjs 390.00 B
14
+ CJS ⚡️ Build success in 36ms
18
15
  ESM dist/python-context-UOPTQH44.mjs 5.64 KB
16
+ ESM dist/chunk-VTALAPQZ.mjs 42.65 KB
19
17
  ESM dist/index.mjs 585.00 B
20
- ESM ⚡️ Build success in 84ms
18
+ ESM dist/chunk-Y6FXYEAI.mjs 390.00 B
19
+ ESM dist/cli.mjs 18.53 KB
20
+ ESM ⚡️ Build success in 37ms
21
21
  DTS Build start
22
- DTS ⚡️ Build success in 8122ms
22
+ DTS ⚡️ Build success in 1637ms
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,31 @@
1
1
 
2
2
  
3
- > @aiready/context-analyzer@0.9.20 test /Users/pengcao/projects/aiready/packages/context-analyzer
3
+ > @aiready/context-analyzer@0.9.22 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) 5ms
10
- ✓ dist/__tests__/scoring.test.js (7 tests) 10ms
11
- ✓ src/__tests__/structural-cohesion.test.ts (4 tests) 6ms
12
- ✓ src/__tests__/fragmentation-coupling.test.ts (2 tests) 161ms
13
- ✓ src/__tests__/analyzer.test.ts (14 tests) 134ms
14
- ✓ dist/__tests__/enhanced-cohesion.test.js (6 tests) 66ms
15
- ✓ dist/__tests__/structural-cohesion.test.js (4 tests) 1ms
16
- ✓ dist/__tests__/fragmentation-coupling.test.js (2 tests) 202ms
17
- ✓ dist/__tests__/fragmentation-log.test.js (3 tests) 4ms
18
- ✓ src/__tests__/auto-detection.test.ts (8 tests) 205ms
19
- ✓ dist/__tests__/analyzer.test.js (14 tests) 610ms
20
- ✓ dist/__tests__/auto-detection.test.js (8 tests) 317ms
21
- ✓ src/__tests__/fragmentation-advanced.test.ts (3 tests) 2ms
22
- ✓ dist/__tests__/fragmentation-advanced.test.js (3 tests) 8ms
9
+ ✓ src/__tests__/scoring.test.ts (7 tests) 4ms
10
+ ✓ dist/__tests__/scoring.test.js (7 tests) 2ms
11
+ ✓ src/__tests__/analyzer.test.ts (14 tests) 17ms
12
+ ✓ dist/__tests__/enhanced-cohesion.test.js (6 tests) 2ms
13
+ ✓ dist/__tests__/fragmentation-advanced.test.js (3 tests) 14ms
14
+ ✓ dist/__tests__/fragmentation-coupling.test.js (2 tests) 130ms
15
+ ✓ dist/__tests__/auto-detection.test.js (8 tests) 230ms
16
+ ✓ src/__tests__/fragmentation-coupling.test.ts (2 tests) 69ms
17
+ ✓ src/__tests__/fragmentation-advanced.test.ts (3 tests) 4ms
18
+ ✓ dist/__tests__/analyzer.test.js (14 tests) 191ms
19
+ ✓ src/__tests__/structural-cohesion.test.ts (4 tests) 2ms
20
+ ✓ src/__tests__/auto-detection.test.ts (8 tests) 30ms
23
21
  ✓ src/__tests__/enhanced-cohesion.test.ts (6 tests) 4ms
24
- ✓ src/__tests__/fragmentation-log.test.ts (3 tests) 47ms
22
+ ✓ dist/__tests__/fragmentation-log.test.js (3 tests) 3ms
23
+ ✓ dist/__tests__/structural-cohesion.test.js (4 tests) 1ms
24
+ ✓ src/__tests__/fragmentation-log.test.ts (3 tests) 1ms
25
25
 
26
26
   Test Files  16 passed (16)
27
27
   Tests  94 passed (94)
28
-  Start at  15:34:38
29
-  Duration  10.60s (transform 21.01s, setup 0ms, import 58.32s, tests 1.78s, environment 37ms)
28
+  Start at  00:46:20
29
+  Duration  2.34s (transform 4.67s, setup 0ms, import 14.26s, tests 706ms, environment 2ms)
30
30
 
31
31
  [?25h
package/README.md CHANGED
@@ -7,31 +7,48 @@ When AI tools try to help with your code, they need to load files into their con
7
7
  ## 🏛️ Architecture
8
8
 
9
9
  ```
10
- 🎯 USER
11
-
12
-
13
- 🎛️ CLI (orchestrator)
14
-
15
-
16
- 🏢 HUB (core)
17
-
18
- ┌──────────────────────┼───────────┬───────────┐
19
- ▼ ▼ ▼ ▼
20
- 📊 PATTERN ┌─────────────┐ 🔧 CONSIST 📚 DOC
21
- DETECT 📦 CONTEXT ⬅ YOU ARE HERE
22
- ✅ Ready │ ANALYZER │ ENCY DRIFT
23
- │ ✅ Ready ✅ Ready 🔜 Soon
24
- └─────────────┘
10
+ 🎯 USER
11
+
12
+
13
+ 🎛️ CLI (orchestrator)
14
+
15
+ ┌─────────────────┴─────────────────┐
16
+ │ │
17
+ ▼ ▼
18
+ ┌────────┐ ┌────────┐
19
+ │🎨 VIS- │ │ ANALY- │
20
+ │UALIZER │ │ SIS │
21
+ │✅ Ready SPOKES
22
+ └────────┘ └───┬────┘
23
+
24
+ │ ┌─────────────────────┼─────────────────────┐
25
+ │ ▼ ▼ ▼
26
+ │ ┌────────┐ ┌────────┐ ┌────────┐
27
+ │ │📊 PAT- │ │📦 CON- │ │🔧 CON- │
28
+ │ │TERN │ │TEXT │ │SISTENCY│
29
+ │ │DETECT │ │ANALYZER│ │ │
30
+ │ │ │ │ │ │ │
31
+ │ │✅ Ready│ │✅ Ready│ │✅ Ready│
32
+ │ └────────┘ └────────┘ └────────┘
33
+ │ │ │
34
+ │ ← YOU ARE HERE │
35
+ │ │
36
+ └───────────────────────────────────────────────────────┘
37
+
38
+
39
+ 🏢 HUB (@aiready/core)
25
40
  ```
26
41
 
27
42
  ## 🌍 Language Support
28
43
 
29
44
  **Currently Supported (64% market coverage):**
45
+
30
46
  - ✅ **TypeScript** (`.ts`, `.tsx`) - Import chains, context budget, cohesion
31
47
  - ✅ **JavaScript** (`.js`, `.jsx`) - Import chains, context budget, cohesion
32
48
  - ✅ **Python** (`.py`) - Import chains, context budget, circular deps, cohesion
33
49
 
34
50
  **Roadmap:**
51
+
35
52
  - 🔜 **Java** (Q3 2026) - Package dependencies, Maven/Gradle analysis
36
53
  - 🔜 **Go** (Q4 2026) - Module dependencies, package cohesion
37
54
  - 🔜 **Rust** (Q4 2026) - Crate dependencies, module structure
@@ -65,11 +82,13 @@ aiready-context ./src
65
82
  ### 🎯 Input & Output
66
83
 
67
84
  **Input:** Path to your source code directory
85
+
68
86
  ```bash
69
87
  aiready-context ./src
70
88
  ```
71
89
 
72
90
  **Output:** Terminal report + optional JSON file (saved to `.aiready/` directory)
91
+
73
92
  ```
74
93
  📊 Context Analysis Results
75
94
  ━━━━━━━━━━━━━━━━━━━━━━━━━━━
@@ -130,11 +149,13 @@ Result: AI sees everything, gives complete answers ✅
130
149
  | Recommendations | Generic | Rule-based | AI context optimization |
131
150
 
132
151
  **Recommended Workflow:**
152
+
133
153
  - Use **dependency-cruiser** to enforce architecture rules (blocking)
134
154
  - Use **@aiready/context-analyzer** to optimize for AI tools (advisory)
135
155
  - Track improvements over time with SaaS tier
136
156
 
137
157
  **Related AIReady Tools:**
158
+
138
159
  - [**@aiready/cli**](https://www.npmjs.com/package/@aiready/cli) - Unified CLI with all analysis tools
139
160
  - [**@aiready/pattern-detect**](https://www.npmjs.com/package/@aiready/pattern-detect) - Semantic duplicate detection
140
161
  - [**@aiready/consistency**](https://www.npmjs.com/package/@aiready/consistency) - Consistency checking
@@ -148,11 +169,13 @@ This tool measures four key dimensions that affect how much context AI tools nee
148
169
  **What it measures:** Total AI tokens needed to understand a file (file content + all dependencies)
149
170
 
150
171
  **Why it matters:** AI tools have limited context windows (e.g., 128K tokens). Large context budgets mean:
172
+
151
173
  - AI needs to load more files to understand your code
152
174
  - Risk of hitting context limits → incomplete/wrong answers
153
175
  - Slower AI responses (more processing time)
154
176
 
155
177
  **Example:**
178
+
156
179
  ```typescript
157
180
  // High context budget (15,000 tokens)
158
181
  import { A, B, C } from './deeply/nested/utils' // +5,000 tokens
@@ -174,12 +197,15 @@ import { X, Y, Z } from './another/chain' // +8,000 tokens
174
197
  **What it measures:** How many layers deep your import chains go
175
198
 
176
199
  **Why it matters:** Deep import chains create cascading context loads:
200
+
177
201
  ```
178
202
  app.ts → service.ts → helper.ts → util.ts → core.ts → base.ts
179
203
  ```
204
+
180
205
  AI must load all 6 files just to understand app.ts!
181
206
 
182
207
  **Example:**
208
+
183
209
  ```typescript
184
210
  // Deep chain (depth 8) = AI loads 8+ files
185
211
  import { validate } from '../../../utils/validators/user/schema'
@@ -197,10 +223,12 @@ import { validate } from './validators'
197
223
  **What it measures:** How related the exports in a file are to each other
198
224
 
199
225
  **How it's calculated:** Uses Shannon entropy of inferred domains
226
+
200
227
  - 1.0 = Perfect cohesion (all exports are related)
201
228
  - 0.0 = Zero cohesion (completely unrelated exports)
202
229
 
203
230
  **Why it matters:** Low cohesion = "God object" pattern = AI confusion
231
+
204
232
  ```typescript
205
233
  // Low cohesion (0.3) - mixing unrelated concerns
206
234
  export function validateUser() { } // User domain
@@ -226,10 +254,12 @@ export interface User { }
226
254
  **What it measures:** How scattered a domain/concept is across different directories
227
255
 
228
256
  **How it's calculated:** `(unique directories - 1) / (total files - 1)`
257
+
229
258
  - 0.0 = No fragmentation (all files in same directory)
230
259
  - 1.0 = Maximum fragmentation (each file in different directory)
231
260
 
232
261
  **Why it matters:** Scattered domains force AI to load many unrelated paths
262
+
233
263
  ```typescript
234
264
  // High fragmentation (0.8) - User domain scattered
235
265
  src/api/user-routes.ts // 800 tokens
@@ -270,6 +300,7 @@ These signals are included in the JSON summary (`fragmentedModules` entries) so
270
300
  | **Consolidate scattered files** | ⚠️ May increase | ✅ Reduces | ⚠️ May decrease |
271
301
 
272
302
  **Best Practice:** Optimize for your use case:
303
+
273
304
  - **Large files with mixed concerns** → Split by domain (improves cohesion + reduces budget)
274
305
  - **Scattered single-domain files** → Consolidate (reduces fragmentation)
275
306
  - **Large files with high cohesion** → May be OK if under context budget threshold
@@ -350,6 +381,7 @@ aiready-context ./src --max-depth 3 --max-context 5000 --min-cohesion 0.7 --max-
350
381
  ```
351
382
 
352
383
  **What this means:**
384
+
353
385
  - `--max-depth 3`: Flag files with import depth ≥4 (stricter than default 5-7)
354
386
  - `--max-context 5000`: Flag files needing 5K+ tokens (catches smaller files)
355
387
  - `--min-cohesion 0.7`: Require 70%+ cohesion (stricter about mixed concerns)
@@ -365,6 +397,7 @@ aiready-context ./src --max-depth 10 --max-context 30000 --min-cohesion 0.4 --ma
365
397
  ```
366
398
 
367
399
  **What this means:**
400
+
368
401
  - `--max-depth 10`: Only flag import depth ≥11 (very deep chains)
369
402
  - `--max-context 30000`: Only flag files needing 30K+ tokens (only huge files)
370
403
  - `--min-cohesion 0.4`: Accept 40%+ cohesion (more lenient about mixed concerns)
@@ -384,6 +417,7 @@ aiready-context ./src --max-depth 10 --max-context 30000 --min-cohesion 0.4 --ma
384
417
  ### Common Tuning Scenarios
385
418
 
386
419
  **Small codebase getting too many warnings?**
420
+
387
421
  ```bash
388
422
  aiready-context ./src --max-depth 6 --min-cohesion 0.5
389
423
  # Explanation: Allow slightly deeper imports and more mixed concerns
@@ -391,6 +425,7 @@ aiready-context ./src --max-depth 6 --min-cohesion 0.5
391
425
  ```
392
426
 
393
427
  **Large codebase showing too few issues?**
428
+
394
429
  ```bash
395
430
  aiready-context ./src --max-depth 5 --max-context 15000
396
431
  # Explanation: Be stricter about depth and context to catch more problems
@@ -398,6 +433,7 @@ aiready-context ./src --max-depth 5 --max-context 15000
398
433
  ```
399
434
 
400
435
  **Focus on critical issues only:**
436
+
401
437
  ```bash
402
438
  aiready-context ./src --max-depth 8 --max-context 25000 --min-cohesion 0.3
403
439
  # Explanation: Very lenient - only show the worst offenders
@@ -405,6 +441,7 @@ aiready-context ./src --max-depth 8 --max-context 25000 --min-cohesion 0.3
405
441
  ```
406
442
 
407
443
  **Preparing for AI refactoring sprint:**
444
+
408
445
  ```bash
409
446
  aiready-context ./src --max-depth 4 --max-context 8000 --min-cohesion 0.6 --max-fragmentation 0.5
410
447
  # Explanation: Strict on all dimensions to get comprehensive issue list
@@ -412,6 +449,7 @@ aiready-context ./src --max-depth 4 --max-context 8000 --min-cohesion 0.6 --max-
412
449
  ```
413
450
 
414
451
  **Microservices architecture (naturally fragmented):**
452
+
415
453
  ```bash
416
454
  aiready-context ./src --max-fragmentation 0.9
417
455
  # Explanation: Very lenient on fragmentation (services are meant to be separate)
@@ -614,24 +652,28 @@ for (const result of results) {
614
652
  ## 📊 Metrics Explained
615
653
 
616
654
  ### Import Depth
655
+
617
656
  **What:** Maximum chain length of transitive dependencies
618
657
  **Impact:** Deeper chains = more files to load = higher context cost
619
658
  **Threshold:** >5 is concerning, >8 is critical
620
659
  **Fix:** Flatten dependency tree, use facade pattern, break circular deps
621
660
 
622
661
  ### Context Budget
662
+
623
663
  **What:** Total tokens AI needs to load to understand this file
624
664
  **Impact:** Higher budget = more expensive AI assistance
625
665
  **Threshold:** >10,000 tokens often hits context limits
626
666
  **Fix:** Split files, reduce dependencies, extract interfaces
627
667
 
628
668
  ### Fragmentation Score
669
+
629
670
  **What:** How scattered related code is across directories (0-100%)
630
671
  **Impact:** Higher = more files to load for domain understanding
631
672
  **Threshold:** >50% indicates poor organization
632
673
  **Fix:** Consolidate related code into cohesive modules
633
674
 
634
675
  ### Cohesion Score
676
+
635
677
  **What:** How related exports are within a file (0-100%)
636
678
  **Impact:** Lower = mixed concerns = wasted context
637
679
  **Threshold:** <60% indicates low cohesion
@@ -657,6 +699,7 @@ for (const result of results) {
657
699
  ### Default Exclusions
658
700
 
659
701
  By default, these patterns are excluded (unless `--include-node-modules` is used):
702
+
660
703
  ```bash
661
704
  # Dependencies (excluded by default, override with --include-node-modules)
662
705
  **/node_modules/**
@@ -699,29 +742,37 @@ interface ContextAnalyzerOptions {
699
742
  ## 🔬 How It Works
700
743
 
701
744
  ### 1. Dependency Graph Builder
745
+
702
746
  Parses imports and exports to build a complete dependency graph of your codebase.
703
747
 
704
748
  ### 2. Depth Calculator
749
+
705
750
  Calculates maximum import chain depth using graph traversal, identifying circular dependencies.
706
751
 
707
752
  ### 3. Semantic Domain Detection
753
+
708
754
  Uses **co-usage patterns** (files imported together) and **type dependencies** (shared types) to automatically identify semantic domains. No configuration needed - the tool discovers relationships from actual code usage.
709
755
 
710
756
  ### 4. Fragmentation Detector
757
+
711
758
  Groups files by semantic domain and calculates how scattered they are across directories.
712
759
 
713
760
  ### 5. Cohesion Analyzer
761
+
714
762
  Uses entropy to measure how related exports are within each file (low entropy = high cohesion).
715
763
 
716
764
  ### 6. Context Budget Calculator
765
+
717
766
  Sums tokens across entire dependency tree to estimate AI context cost for each file.
718
767
 
719
768
  ## 🎨 Output Formats
720
769
 
721
770
  ### Console (Default)
771
+
722
772
  Rich formatted output with colors, emojis, and actionable recommendations.
723
773
 
724
774
  ### JSON
775
+
725
776
  Machine-readable output for CI/CD integration:
726
777
 
727
778
  ```json
@@ -748,6 +799,7 @@ Machine-readable output for CI/CD integration:
748
799
  ```
749
800
 
750
801
  ### HTML
802
+
751
803
  Shareable report with tables and visualizations. Perfect for stakeholders:
752
804
 
753
805
  ```bash
@@ -764,6 +816,7 @@ aiready-context ./src --interactive
764
816
  ```
765
817
 
766
818
  Interactive mode:
819
+
767
820
  - Detects frameworks and recommends excludes (e.g., .next, cdk.out)
768
821
  - Lets you choose focus areas: frontend, backend, or both
769
822
  - Applies configuration without modifying your files
@@ -813,6 +866,7 @@ aiready-patterns src # Duplicate pattern detection
813
866
  ## 💰 SaaS Features (Coming Soon)
814
867
 
815
868
  ### Free Tier (CLI)
869
+
816
870
  ✅ One-time snapshot analysis
817
871
  ✅ All metrics and recommendations
818
872
  ✅ JSON/HTML export
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/context-analyzer",
3
- "version": "0.9.20",
3
+ "version": "0.9.22",
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.20"
52
+ "@aiready/core": "0.9.22"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/node": "^24.0.0",