@aiready/context-analyzer 0.9.14 → 0.9.17
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.
- package/.turbo/turbo-build.log +7 -7
- package/.turbo/turbo-test.log +17 -17
- package/package.json +2 -2
- package/SEMANTIC-VALIDATION.md +0 -235
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/context-analyzer@0.9.
|
|
3
|
+
> @aiready/context-analyzer@0.9.17 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
|
[34mCLI[39m Building entry: src/cli.ts, src/index.ts
|
|
@@ -11,15 +11,15 @@
|
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[32mCJS[39m [1mdist/index.js [22m[32m50.93 KB[39m
|
|
13
13
|
[32mCJS[39m [1mdist/cli.js [22m[32m62.68 KB[39m
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
15
|
-
[32mESM[39m [1mdist/cli.mjs [22m[32m18.53 KB[39m
|
|
16
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m585.00 B[39m
|
|
17
|
-
[32mESM[39m [1mdist/chunk-Y6FXYEAI.mjs [22m[32m390.00 B[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 63ms
|
|
18
15
|
[32mESM[39m [1mdist/chunk-VTALAPQZ.mjs [22m[32m42.65 KB[39m
|
|
16
|
+
[32mESM[39m [1mdist/chunk-Y6FXYEAI.mjs [22m[32m390.00 B[39m
|
|
17
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m585.00 B[39m
|
|
18
|
+
[32mESM[39m [1mdist/cli.mjs [22m[32m18.53 KB[39m
|
|
19
19
|
[32mESM[39m [1mdist/python-context-UOPTQH44.mjs [22m[32m5.64 KB[39m
|
|
20
|
-
[32mESM[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m ⚡️ Build success in 63ms
|
|
21
21
|
DTS Build start
|
|
22
|
-
DTS ⚡️ Build success in
|
|
22
|
+
DTS ⚡️ Build success in 1499ms
|
|
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
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/context-analyzer@0.9.
|
|
3
|
+
> @aiready/context-analyzer@0.9.17 test /Users/pengcao/projects/aiready/packages/context-analyzer
|
|
4
4
|
> vitest run
|
|
5
5
|
|
|
6
6
|
[?25l
|
|
7
7
|
[1m[46m RUN [49m[22m [36mv4.0.18 [39m[90m/Users/pengcao/projects/aiready/packages/context-analyzer[39m
|
|
8
8
|
|
|
9
9
|
[32m✓[39m src/__tests__/scoring.test.ts [2m([22m[2m7 tests[22m[2m)[22m[32m 5[2mms[22m[39m
|
|
10
|
-
[32m✓[39m dist/__tests__/scoring.test.js [2m([22m[2m7 tests[22m[2m)[22m[32m
|
|
11
|
-
[32m✓[39m
|
|
12
|
-
[32m✓[39m dist/__tests__/enhanced-cohesion.test.js [2m([22m[2m6 tests[22m[2m)[22m[32m
|
|
13
|
-
[32m✓[39m
|
|
14
|
-
[32m✓[39m src/__tests__/fragmentation-coupling.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m
|
|
15
|
-
[32m✓[39m dist/__tests__/
|
|
16
|
-
[32m✓[39m
|
|
17
|
-
[32m✓[39m dist/__tests__/fragmentation-log.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
18
|
-
[32m✓[39m dist/__tests__/auto-detection.test.js [2m([22m[2m8 tests[22m[2m)[22m[32m 26[2mms[22m[39m
|
|
19
|
-
[32m✓[39m dist/__tests__/analyzer.test.js [2m([22m[2m14 tests[22m[2m)[22m[32m 144[2mms[22m[39m
|
|
20
|
-
[32m✓[39m src/__tests__/enhanced-cohesion.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 7[2mms[22m[39m
|
|
21
|
-
[32m✓[39m src/__tests__/fragmentation-advanced.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 4[2mms[22m[39m
|
|
22
|
-
[32m✓[39m src/__tests__/structural-cohesion.test.ts [2m([22m[2m4 tests[22m[2m)[22m[32m 1[2mms[22m[39m
|
|
23
|
-
[32m✓[39m dist/__tests__/structural-cohesion.test.js [2m([22m[2m4 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
10
|
+
[32m✓[39m dist/__tests__/scoring.test.js [2m([22m[2m7 tests[22m[2m)[22m[32m 3[2mms[22m[39m
|
|
11
|
+
[32m✓[39m dist/__tests__/auto-detection.test.js [2m([22m[2m8 tests[22m[2m)[22m[32m 15[2mms[22m[39m
|
|
12
|
+
[32m✓[39m dist/__tests__/enhanced-cohesion.test.js [2m([22m[2m6 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
13
|
+
[32m✓[39m dist/__tests__/analyzer.test.js [2m([22m[2m14 tests[22m[2m)[22m[32m 16[2mms[22m[39m
|
|
14
|
+
[32m✓[39m src/__tests__/fragmentation-coupling.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m 13[2mms[22m[39m
|
|
15
|
+
[32m✓[39m dist/__tests__/structural-cohesion.test.js [2m([22m[2m4 tests[22m[2m)[22m[32m 3[2mms[22m[39m
|
|
16
|
+
[32m✓[39m src/__tests__/analyzer.test.ts [2m([22m[2m14 tests[22m[2m)[22m[32m 15[2mms[22m[39m
|
|
24
17
|
[32m✓[39m src/__tests__/fragmentation-log.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 1[2mms[22m[39m
|
|
18
|
+
[32m✓[39m dist/__tests__/fragmentation-coupling.test.js [2m([22m[2m2 tests[22m[2m)[22m[32m 15[2mms[22m[39m
|
|
19
|
+
[32m✓[39m src/__tests__/auto-detection.test.ts [2m([22m[2m8 tests[22m[2m)[22m[32m 41[2mms[22m[39m
|
|
20
|
+
[32m✓[39m src/__tests__/structural-cohesion.test.ts [2m([22m[2m4 tests[22m[2m)[22m[32m 8[2mms[22m[39m
|
|
21
|
+
[32m✓[39m dist/__tests__/fragmentation-advanced.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 1[2mms[22m[39m
|
|
22
|
+
[32m✓[39m src/__tests__/fragmentation-advanced.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 1[2mms[22m[39m
|
|
23
|
+
[32m✓[39m src/__tests__/enhanced-cohesion.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
24
|
+
[32m✓[39m dist/__tests__/fragmentation-log.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 1[2mms[22m[39m
|
|
25
25
|
|
|
26
26
|
[2m Test Files [22m [1m[32m16 passed[39m[22m[90m (16)[39m
|
|
27
27
|
[2m Tests [22m [1m[32m94 passed[39m[22m[90m (94)[39m
|
|
28
|
-
[2m Start at [22m
|
|
29
|
-
[2m Duration [22m
|
|
28
|
+
[2m Start at [22m 13:51:03
|
|
29
|
+
[2m Duration [22m 1.42s[2m (transform 2.51s, setup 0ms, import 10.99s, tests 144ms, environment 1ms)[22m
|
|
30
30
|
|
|
31
31
|
[?25h
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/context-analyzer",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.17",
|
|
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.
|
|
52
|
+
"@aiready/core": "0.9.17"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^24.0.0",
|
package/SEMANTIC-VALIDATION.md
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
# Semantic Analysis Validation Results
|
|
2
|
-
|
|
3
|
-
**Date:** 14 January 2026
|
|
4
|
-
**Test Project:** receiptclaimer (real-world Next.js application)
|
|
5
|
-
**Analysis Version:** v0.7.0 (semantic analysis)
|
|
6
|
-
|
|
7
|
-
## Executive Summary
|
|
8
|
-
|
|
9
|
-
✅ Semantic analysis successfully deployed and validated on production codebase
|
|
10
|
-
✅ 181 files analyzed in 0.99s (~5.5ms per file)
|
|
11
|
-
✅ Identified 10 semantic domains with high accuracy
|
|
12
|
-
✅ Average cohesion: 75% (up from folder-based approach)
|
|
13
|
-
✅ Zero false positives or analysis failures
|
|
14
|
-
|
|
15
|
-
## Key Findings
|
|
16
|
-
|
|
17
|
-
### 1. Domain Identification Accuracy
|
|
18
|
-
|
|
19
|
-
**Top Semantic Domains Detected:**
|
|
20
|
-
- `partner`: 7 files, 97% fragmentation, 74% cohesion
|
|
21
|
-
- `gift`: 6 files, 96% fragmentation, 78% cohesion
|
|
22
|
-
- `google`: 4 files, 95% fragmentation, 90% cohesion
|
|
23
|
-
- `shared`: 3 files, 100% fragmentation, 100% cohesion
|
|
24
|
-
- `categorization`: 3 files, 100% fragmentation, 78% cohesion
|
|
25
|
-
|
|
26
|
-
**Improvements Over Folder-Based:**
|
|
27
|
-
- ✅ No more "unknown" domains for generic file names
|
|
28
|
-
- ✅ Detected cross-cutting concerns (`shared`, `hook`)
|
|
29
|
-
- ✅ Identified infrastructure domains (`google`, `export`)
|
|
30
|
-
- ✅ Found business logic clusters (`partner`, `gift`, `mileage`)
|
|
31
|
-
|
|
32
|
-
### 2. Cohesion Analysis
|
|
33
|
-
|
|
34
|
-
**Distribution:**
|
|
35
|
-
- High cohesion (≥80%): Majority of files
|
|
36
|
-
- Medium cohesion (40-80%): Some integration points
|
|
37
|
-
- Low cohesion (<40%): Cross-cutting concerns (expected)
|
|
38
|
-
|
|
39
|
-
**Average Cohesion: 75%**
|
|
40
|
-
This is a strong indicator that semantic analysis correctly identifies when exports belong together vs. when files serve as integration points.
|
|
41
|
-
|
|
42
|
-
### 3. Fragmentation Detection
|
|
43
|
-
|
|
44
|
-
**10 Fragmented Module Clusters Identified:**
|
|
45
|
-
|
|
46
|
-
All clusters show high fragmentation (95-100%), indicating these domains are correctly scattered across the codebase for legitimate architectural reasons:
|
|
47
|
-
|
|
48
|
-
- Partner management spread across API, UI, blog content
|
|
49
|
-
- Gift functionality across admin, partner APIs, email templates
|
|
50
|
-
- Google integrations across analytics, document AI, layout
|
|
51
|
-
|
|
52
|
-
**This is correct behavior** - not all fragmentation is bad. Integration layers SHOULD reference multiple domains.
|
|
53
|
-
|
|
54
|
-
### 4. Performance
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
Total files: 181
|
|
58
|
-
Analysis time: 0.99s
|
|
59
|
-
Per-file average: ~5.5ms
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
**Semantic analysis overhead:** Minimal
|
|
63
|
-
- Co-usage matrix building: Fast
|
|
64
|
-
- Type graph construction: Fast
|
|
65
|
-
- Confidence scoring: Negligible
|
|
66
|
-
|
|
67
|
-
The 3-pass analysis (basic → semantic → enhancement) adds ~10-15% overhead compared to folder-based approach, but provides dramatically better accuracy.
|
|
68
|
-
|
|
69
|
-
## Semantic Analysis In Action
|
|
70
|
-
|
|
71
|
-
### Example: Partner Domain
|
|
72
|
-
|
|
73
|
-
**Files Detected:**
|
|
74
|
-
1. `shared/src/types/partners.ts` - Type definitions
|
|
75
|
-
2. `web/lib/partners.ts` - Business logic
|
|
76
|
-
3. `web/app/partners/_lib/hooks.ts` - React hooks
|
|
77
|
-
4. `web/app/blog/property-managers-referral-program/content.tsx` - Content
|
|
78
|
-
5. `web/app/blog/accountant-referral-programs-australia/content.tsx` - Content
|
|
79
|
-
6. `web/app/api/partners/gifts/__tests__/test-helpers.ts` - Tests
|
|
80
|
-
7. `web/app/api/partners/gifts/__tests__/fixtures.ts` - Test fixtures
|
|
81
|
-
|
|
82
|
-
**Why This Is Correct:**
|
|
83
|
-
- All files relate to partner functionality
|
|
84
|
-
- Spread across types, logic, UI, content, tests (appropriate separation)
|
|
85
|
-
- Semantic analysis correctly identified them as belonging to same domain despite different folders
|
|
86
|
-
- Fragmentation score 97% is accurate - these SHOULD be in different folders
|
|
87
|
-
|
|
88
|
-
**Confidence Signals:**
|
|
89
|
-
- ✅ **Type references** - All reference `Partner` types
|
|
90
|
-
- ✅ **Co-usage** - Often imported together in partner features
|
|
91
|
-
- ✅ **Import paths** - Import from `partners/` folders
|
|
92
|
-
- ✅ **Folder structure** - Most in `partners/` related folders
|
|
93
|
-
|
|
94
|
-
### Example: Google Domain
|
|
95
|
-
|
|
96
|
-
**Files Detected:**
|
|
97
|
-
1. `web/app/layout.tsx` - Google Analytics integration
|
|
98
|
-
2. `web/pages/api/internal/top-pages.ts` - Analytics API
|
|
99
|
-
3. `infra/lib/lambda/utils/google-document-ai-client.ts` - Document AI client
|
|
100
|
-
4. `infra/lib/lambda/documentai-adapter.ts` - Document AI adapter
|
|
101
|
-
|
|
102
|
-
**Why This Is Correct:**
|
|
103
|
-
- All files integrate with Google services
|
|
104
|
-
- Layout → Analytics, Lambda → Document AI (different concerns)
|
|
105
|
-
- 90% cohesion indicates strong semantic relationship despite different purposes
|
|
106
|
-
- Correctly identified as infrastructure domain, not business logic
|
|
107
|
-
|
|
108
|
-
**Confidence Signals:**
|
|
109
|
-
- ✅ **Co-usage** - Google libraries imported together
|
|
110
|
-
- ✅ **Type references** - Share Google API types
|
|
111
|
-
- ✅ **Import paths** - Reference `google` in imports
|
|
112
|
-
|
|
113
|
-
## Comparison: Folder-Based vs. Semantic
|
|
114
|
-
|
|
115
|
-
### Before (Folder-Based Heuristics)
|
|
116
|
-
|
|
117
|
-
**Problems:**
|
|
118
|
-
- Generic file names → "unknown" domain
|
|
119
|
-
- Folder structure assumed = semantic relationship
|
|
120
|
-
- No confidence scores
|
|
121
|
-
- Single domain per file
|
|
122
|
-
- Missed cross-cutting concerns
|
|
123
|
-
|
|
124
|
-
**Example Issue:**
|
|
125
|
-
```
|
|
126
|
-
lib/session.ts → "unknown" (generic name)
|
|
127
|
-
lib/dynamodb.ts → "unknown" (generic name)
|
|
128
|
-
components/nav/nav-links.ts → "unknown" (generic name)
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
### After (Semantic Analysis)
|
|
132
|
-
|
|
133
|
-
**Improvements:**
|
|
134
|
-
- Real usage patterns → accurate domains
|
|
135
|
-
- Co-usage + types > folder convention
|
|
136
|
-
- Confidence scores show signal strength
|
|
137
|
-
- Multi-domain support for integration points
|
|
138
|
-
- Correctly identifies cross-cutting concerns
|
|
139
|
-
|
|
140
|
-
**Example Fix:**
|
|
141
|
-
```
|
|
142
|
-
lib/session.ts → "gift" domain (35% co-usage, 30% types)
|
|
143
|
-
lib/dynamodb.ts → "customer" domain (imports from customers/)
|
|
144
|
-
components/nav/nav-links.ts → "order" domain (imports from orders/)
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
## Validation Criteria
|
|
148
|
-
|
|
149
|
-
| Criterion | Status | Evidence |
|
|
150
|
-
|-----------|--------|----------|
|
|
151
|
-
| **Accuracy** | ✅ Pass | All detected domains align with actual codebase structure |
|
|
152
|
-
| **Performance** | ✅ Pass | <1s for 181 files, negligible overhead |
|
|
153
|
-
| **Backward Compat** | ✅ Pass | `inferredDomain` still works, existing code unaffected |
|
|
154
|
-
| **Zero Crashes** | ✅ Pass | No analysis failures or errors |
|
|
155
|
-
| **Scalability** | ✅ Pass | O(n²) co-usage acceptable for typical codebases |
|
|
156
|
-
| **Usefulness** | ✅ Pass | Consolidation recommendations are actionable |
|
|
157
|
-
|
|
158
|
-
## Consolidation Recommendations
|
|
159
|
-
|
|
160
|
-
Based on semantic analysis, the tool correctly identified:
|
|
161
|
-
|
|
162
|
-
1. **Partner files (7 files)** - Consolidate into 3 files
|
|
163
|
-
- Reason: High co-usage, shared types
|
|
164
|
-
- Estimated savings: 4,022 tokens (30%)
|
|
165
|
-
|
|
166
|
-
2. **Gift files (6 files)** - Consolidate into 2 files
|
|
167
|
-
- Reason: Very high co-usage
|
|
168
|
-
- Estimated savings: 3,296 tokens (30%)
|
|
169
|
-
|
|
170
|
-
3. **Google files (4 files)** - Consolidate into 2 files
|
|
171
|
-
- Reason: Infrastructure cluster
|
|
172
|
-
- Estimated savings: 769 tokens (30%)
|
|
173
|
-
|
|
174
|
-
**These are evidence-based recommendations**, not guesses based on folder names.
|
|
175
|
-
|
|
176
|
-
## Confidence Scoring Validation
|
|
177
|
-
|
|
178
|
-
Spot-checked 10 random files:
|
|
179
|
-
|
|
180
|
-
| File | Primary Domain | Confidence | Signals | Correct? |
|
|
181
|
-
|------|---------------|------------|---------|----------|
|
|
182
|
-
| partners.ts | partner | High | 4/5 signals | ✅ |
|
|
183
|
-
| gift-notification.ts | gift | High | 4/5 signals | ✅ |
|
|
184
|
-
| documentai-adapter.ts | google | Medium | 3/5 signals | ✅ |
|
|
185
|
-
| session.ts | gift | Medium | 2/5 signals | ✅ |
|
|
186
|
-
| categorization.ts | categorization | High | 4/5 signals | ✅ |
|
|
187
|
-
| mileage-test-helpers.ts | mileage | High | 4/5 signals | ✅ |
|
|
188
|
-
| layout.tsx | google | Low | 2/5 signals | ✅ |
|
|
189
|
-
| rate-limit.ts | export | Low | 1/5 signals | ✅ |
|
|
190
|
-
| nav-links.ts | order | Medium | 2/5 signals | ✅ |
|
|
191
|
-
| PartnerDashboardClient.tsx | partner | High | 4/5 signals | ✅ |
|
|
192
|
-
|
|
193
|
-
**10/10 correct** - 100% accuracy on spot check
|
|
194
|
-
|
|
195
|
-
## Edge Cases Handled Correctly
|
|
196
|
-
|
|
197
|
-
1. **Cross-cutting concerns** - `shared` domain correctly identified
|
|
198
|
-
2. **Integration layers** - Multi-domain files work as expected
|
|
199
|
-
3. **Test files** - Correctly grouped with tested domain
|
|
200
|
-
4. **Infrastructure** - `google`, `export` domains separate from business logic
|
|
201
|
-
5. **Generic names** - No longer result in "unknown"
|
|
202
|
-
|
|
203
|
-
## Known Limitations
|
|
204
|
-
|
|
205
|
-
1. **New codebases with few files** - Co-usage matrix sparse, confidence low (expected)
|
|
206
|
-
2. **Very isolated files** - May fall back to folder heuristics (acceptable)
|
|
207
|
-
3. **No imports** - Can't infer from co-usage (expected, rare)
|
|
208
|
-
|
|
209
|
-
## Conclusion
|
|
210
|
-
|
|
211
|
-
✅ **Semantic analysis is production-ready**
|
|
212
|
-
|
|
213
|
-
The pivot from folder-based heuristics to semantic analysis (co-usage + types) dramatically improves domain identification accuracy while maintaining performance.
|
|
214
|
-
|
|
215
|
-
**Key Achievement:** We now answer the right question:
|
|
216
|
-
~~"What folder is this file in?"~~
|
|
217
|
-
✅ **"Which files need to be loaded together to understand this code?"**
|
|
218
|
-
|
|
219
|
-
This is the correct foundation for AI context optimization.
|
|
220
|
-
|
|
221
|
-
## Recommendations
|
|
222
|
-
|
|
223
|
-
1. ✅ **Deploy to production** - Validated and ready
|
|
224
|
-
2. ✅ **Release as v0.7.0** - Major improvement
|
|
225
|
-
3. ✅ **Config-free approach** - Domain detection fully automatic, no user configuration needed
|
|
226
|
-
4. 🔬 **Add call graph analysis** - Next enhancement (v0.8.0)
|
|
227
|
-
5. 🔬 **Add embedding-based clustering** - Future enhancement (v1.0.0)
|
|
228
|
-
|
|
229
|
-
## Next Steps
|
|
230
|
-
|
|
231
|
-
- [x] Implement semantic analysis
|
|
232
|
-
- [x] Validate on real codebase
|
|
233
|
-
- [ ] Add comprehensive tests for semantic features
|
|
234
|
-
- [ ] Document confidence scoring for users
|
|
235
|
-
- [ ] Release v0.7.0
|