@aiready/context-analyzer 0.9.20 → 0.9.23
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 +11 -11
- package/.turbo/turbo-test.log +24 -20
- package/README.md +120 -15
- package/dist/chunk-MBE4AQP5.mjs +1362 -0
- package/dist/cli.js +124 -5
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +29 -1
- package/dist/index.d.ts +29 -1
- package/dist/index.js +128 -5
- package/dist/index.mjs +5 -1
- package/package.json +2 -2
- package/src/__tests__/file-classification.test.ts +216 -0
- package/src/analyzer.ts +187 -0
- package/src/index.ts +52 -5
- package/src/types.ts +14 -0
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.23 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
|
|
@@ -9,18 +9,18 @@
|
|
|
9
9
|
[34mCLI[39m Target: es2020
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
11
|
[34mESM[39m Build start
|
|
12
|
-
[32mCJS[39m [1mdist/
|
|
13
|
-
[32mCJS[39m [1mdist/
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
12
|
+
[32mCJS[39m [1mdist/index.js [22m[32m55.45 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/cli.js [22m[32m67.03 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 162ms
|
|
15
15
|
[32mESM[39m [1mdist/cli.mjs [22m[32m18.53 KB[39m
|
|
16
|
-
[32mESM[39m [1mdist/chunk-
|
|
17
|
-
[32mESM[39m [1mdist/chunk-Y6FXYEAI.mjs [22m[32m390.00 B[39m
|
|
16
|
+
[32mESM[39m [1mdist/chunk-MBE4AQP5.mjs [22m[32m47.02 KB[39m
|
|
18
17
|
[32mESM[39m [1mdist/python-context-UOPTQH44.mjs [22m[32m5.64 KB[39m
|
|
19
|
-
[32mESM[39m [1mdist/
|
|
20
|
-
[32mESM[39m
|
|
18
|
+
[32mESM[39m [1mdist/chunk-Y6FXYEAI.mjs [22m[32m390.00 B[39m
|
|
19
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m697.00 B[39m
|
|
20
|
+
[32mESM[39m ⚡️ Build success in 162ms
|
|
21
21
|
DTS Build start
|
|
22
|
-
DTS ⚡️ Build success in
|
|
22
|
+
DTS ⚡️ Build success in 7868ms
|
|
23
23
|
DTS dist/cli.d.ts 20.00 B
|
|
24
|
-
DTS dist/index.d.ts
|
|
24
|
+
DTS dist/index.d.ts 7.37 KB
|
|
25
25
|
DTS dist/cli.d.mts 20.00 B
|
|
26
|
-
DTS dist/index.d.mts
|
|
26
|
+
DTS dist/index.d.mts 7.37 KB
|
package/.turbo/turbo-test.log
CHANGED
|
@@ -1,31 +1,35 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
> @aiready/context-analyzer@0.9.
|
|
3
|
+
> @aiready/context-analyzer@0.9.23 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
|
-
[32m✓[39m
|
|
10
|
-
[32m✓[39m
|
|
11
|
-
[32m✓[39m src/__tests__/
|
|
12
|
-
|
|
13
|
-
[32m✓[39m src/__tests__/
|
|
14
|
-
[32m✓[39m
|
|
9
|
+
[32m✓[39m dist/__tests__/scoring.test.js [2m([22m[2m7 tests[22m[2m)[22m[32m 27[2mms[22m[39m
|
|
10
|
+
[32m✓[39m src/__tests__/scoring.test.ts [2m([22m[2m7 tests[22m[2m)[22m[32m 11[2mms[22m[39m
|
|
11
|
+
[32m✓[39m src/__tests__/auto-detection.test.ts [2m([22m[2m8 tests[22m[2m)[22m[33m 612[2mms[22m[39m
|
|
12
|
+
[33m[2m✓[22m[39m should auto-detect domain keywords from folder paths [33m 315[2mms[22m[39m
|
|
13
|
+
[32m✓[39m src/__tests__/file-classification.test.ts [2m([22m[2m17 tests[22m[2m)[22m[32m 242[2mms[22m[39m
|
|
14
|
+
[32m✓[39m src/__tests__/analyzer.test.ts [2m([22m[2m14 tests[22m[2m)[22m[33m 491[2mms[22m[39m
|
|
15
|
+
[33m[2m✓[22m[39m should build a basic dependency graph [33m 379[2mms[22m[39m
|
|
16
|
+
[32m✓[39m dist/__tests__/fragmentation-coupling.test.js [2m([22m[2m2 tests[22m[2m)[22m[32m 38[2mms[22m[39m
|
|
17
|
+
[32m✓[39m src/__tests__/fragmentation-coupling.test.ts [2m([22m[2m2 tests[22m[2m)[22m[32m 271[2mms[22m[39m
|
|
18
|
+
[32m✓[39m dist/__tests__/fragmentation-log.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 6[2mms[22m[39m
|
|
19
|
+
[32m✓[39m dist/__tests__/analyzer.test.js [2m([22m[2m14 tests[22m[2m)[22m[33m 542[2mms[22m[39m
|
|
20
|
+
[33m[2m✓[22m[39m should calculate import depth correctly [33m 314[2mms[22m[39m
|
|
21
|
+
[32m✓[39m dist/__tests__/auto-detection.test.js [2m([22m[2m8 tests[22m[2m)[22m[33m 536[2mms[22m[39m
|
|
22
|
+
[32m✓[39m src/__tests__/fragmentation-advanced.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 111[2mms[22m[39m
|
|
23
|
+
[32m✓[39m dist/__tests__/enhanced-cohesion.test.js [2m([22m[2m6 tests[22m[2m)[22m[32m 24[2mms[22m[39m
|
|
15
24
|
[32m✓[39m dist/__tests__/structural-cohesion.test.js [2m([22m[2m4 tests[22m[2m)[22m[32m 1[2mms[22m[39m
|
|
16
|
-
[32m✓[39m
|
|
17
|
-
[32m✓[39m
|
|
18
|
-
[32m✓[39m src/__tests__/
|
|
19
|
-
[32m✓[39m dist/__tests__/
|
|
20
|
-
[32m✓[39m dist/__tests__/auto-detection.test.js [2m([22m[2m8 tests[22m[2m)[22m[33m 317[2mms[22m[39m
|
|
21
|
-
[32m✓[39m src/__tests__/fragmentation-advanced.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 2[2mms[22m[39m
|
|
22
|
-
[32m✓[39m dist/__tests__/fragmentation-advanced.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 8[2mms[22m[39m
|
|
23
|
-
[32m✓[39m src/__tests__/enhanced-cohesion.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 4[2mms[22m[39m
|
|
24
|
-
[32m✓[39m src/__tests__/fragmentation-log.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 47[2mms[22m[39m
|
|
25
|
+
[32m✓[39m src/__tests__/enhanced-cohesion.test.ts [2m([22m[2m6 tests[22m[2m)[22m[32m 31[2mms[22m[39m
|
|
26
|
+
[32m✓[39m src/__tests__/fragmentation-log.test.ts [2m([22m[2m3 tests[22m[2m)[22m[32m 4[2mms[22m[39m
|
|
27
|
+
[32m✓[39m src/__tests__/structural-cohesion.test.ts [2m([22m[2m4 tests[22m[2m)[22m[32m 240[2mms[22m[39m
|
|
28
|
+
[32m✓[39m dist/__tests__/fragmentation-advanced.test.js [2m([22m[2m3 tests[22m[2m)[22m[32m 6[2mms[22m[39m
|
|
25
29
|
|
|
26
|
-
[2m Test Files [22m [1m[
|
|
27
|
-
[2m Tests [22m [1m[
|
|
28
|
-
[2m Start at [22m
|
|
29
|
-
[2m Duration [22m 10.
|
|
30
|
+
[2m Test Files [22m [1m[32m17 passed[39m[22m[90m (17)[39m
|
|
31
|
+
[2m Tests [22m [1m[32m111 passed[39m[22m[90m (111)[39m
|
|
32
|
+
[2m Start at [22m 11:30:31
|
|
33
|
+
[2m Duration [22m 10.28s[2m (transform 3.68s, setup 0ms, import 60.43s, tests 3.19s, environment 12ms)[22m
|
|
30
34
|
|
|
31
35
|
[?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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
@@ -260,6 +290,57 @@ These signals are included in the JSON summary (`fragmentedModules` entries) so
|
|
|
260
290
|
|
|
261
291
|
---
|
|
262
292
|
|
|
293
|
+
### 🏷️ File Classification (Reducing False Positives)
|
|
294
|
+
|
|
295
|
+
**What it measures:** The tool now classifies files into categories to distinguish real issues from acceptable patterns:
|
|
296
|
+
|
|
297
|
+
| Classification | Description | Fragmentation Treatment |
|
|
298
|
+
|---------------|-------------|------------------------|
|
|
299
|
+
| **barrel-export** | Re-exports from other modules (index.ts) | 0% (expected behavior) |
|
|
300
|
+
| **type-definition** | Primarily type/interface definitions | 0% (centralized types are good) |
|
|
301
|
+
| **cohesive-module** | Single domain, high cohesion (≥70%) | 30% of original (large but focused is OK) |
|
|
302
|
+
| **mixed-concerns** | Multiple domains, low cohesion | 100% (real issue) |
|
|
303
|
+
| **unknown** | Doesn't fit other categories | 70% of original (benefit of doubt) |
|
|
304
|
+
|
|
305
|
+
**Why it matters:** Previous versions could flag files that were actually well-designed:
|
|
306
|
+
|
|
307
|
+
```typescript
|
|
308
|
+
// ❌ Old behavior: Flagged as "high fragmentation (99%)"
|
|
309
|
+
// shared/src/index.ts - barrel export with 6 domains
|
|
310
|
+
export * from './user';
|
|
311
|
+
export * from './order';
|
|
312
|
+
export * from './product';
|
|
313
|
+
// ... more re-exports
|
|
314
|
+
|
|
315
|
+
// ✅ New behavior: Classified as "barrel-export"
|
|
316
|
+
// Fragmentation score: 0% (this is what barrel files DO)
|
|
317
|
+
// Recommendation: "Barrel export file detected - multiple domains are expected here"
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
// ❌ Old behavior: Flagged as "high fragmentation (98%)"
|
|
322
|
+
// gst-calculator/client.tsx - 346 lines, 7 dependencies, 1 domain
|
|
323
|
+
|
|
324
|
+
// ✅ New behavior: Classified as "cohesive-module"
|
|
325
|
+
// Fragmentation score: 29% (reduced from 98%)
|
|
326
|
+
// Recommendation: "Module has good cohesion despite its size"
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**🎯 Benefit:** Focus on real issues while accepting legitimate patterns.
|
|
330
|
+
|
|
331
|
+
**JSON Output includes classification:**
|
|
332
|
+
|
|
333
|
+
```json
|
|
334
|
+
{
|
|
335
|
+
"file": "src/index.ts",
|
|
336
|
+
"fileClassification": "barrel-export",
|
|
337
|
+
"fragmentationScore": 0,
|
|
338
|
+
"severity": "info"
|
|
339
|
+
}
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
263
344
|
### ⚖️ The Tradeoff: Splitting vs. Consolidating
|
|
264
345
|
|
|
265
346
|
**Important:** These metrics can pull in opposite directions!
|
|
@@ -270,6 +351,7 @@ These signals are included in the JSON summary (`fragmentedModules` entries) so
|
|
|
270
351
|
| **Consolidate scattered files** | ⚠️ May increase | ✅ Reduces | ⚠️ May decrease |
|
|
271
352
|
|
|
272
353
|
**Best Practice:** Optimize for your use case:
|
|
354
|
+
|
|
273
355
|
- **Large files with mixed concerns** → Split by domain (improves cohesion + reduces budget)
|
|
274
356
|
- **Scattered single-domain files** → Consolidate (reduces fragmentation)
|
|
275
357
|
- **Large files with high cohesion** → May be OK if under context budget threshold
|
|
@@ -350,6 +432,7 @@ aiready-context ./src --max-depth 3 --max-context 5000 --min-cohesion 0.7 --max-
|
|
|
350
432
|
```
|
|
351
433
|
|
|
352
434
|
**What this means:**
|
|
435
|
+
|
|
353
436
|
- `--max-depth 3`: Flag files with import depth ≥4 (stricter than default 5-7)
|
|
354
437
|
- `--max-context 5000`: Flag files needing 5K+ tokens (catches smaller files)
|
|
355
438
|
- `--min-cohesion 0.7`: Require 70%+ cohesion (stricter about mixed concerns)
|
|
@@ -365,6 +448,7 @@ aiready-context ./src --max-depth 10 --max-context 30000 --min-cohesion 0.4 --ma
|
|
|
365
448
|
```
|
|
366
449
|
|
|
367
450
|
**What this means:**
|
|
451
|
+
|
|
368
452
|
- `--max-depth 10`: Only flag import depth ≥11 (very deep chains)
|
|
369
453
|
- `--max-context 30000`: Only flag files needing 30K+ tokens (only huge files)
|
|
370
454
|
- `--min-cohesion 0.4`: Accept 40%+ cohesion (more lenient about mixed concerns)
|
|
@@ -384,6 +468,7 @@ aiready-context ./src --max-depth 10 --max-context 30000 --min-cohesion 0.4 --ma
|
|
|
384
468
|
### Common Tuning Scenarios
|
|
385
469
|
|
|
386
470
|
**Small codebase getting too many warnings?**
|
|
471
|
+
|
|
387
472
|
```bash
|
|
388
473
|
aiready-context ./src --max-depth 6 --min-cohesion 0.5
|
|
389
474
|
# Explanation: Allow slightly deeper imports and more mixed concerns
|
|
@@ -391,6 +476,7 @@ aiready-context ./src --max-depth 6 --min-cohesion 0.5
|
|
|
391
476
|
```
|
|
392
477
|
|
|
393
478
|
**Large codebase showing too few issues?**
|
|
479
|
+
|
|
394
480
|
```bash
|
|
395
481
|
aiready-context ./src --max-depth 5 --max-context 15000
|
|
396
482
|
# Explanation: Be stricter about depth and context to catch more problems
|
|
@@ -398,6 +484,7 @@ aiready-context ./src --max-depth 5 --max-context 15000
|
|
|
398
484
|
```
|
|
399
485
|
|
|
400
486
|
**Focus on critical issues only:**
|
|
487
|
+
|
|
401
488
|
```bash
|
|
402
489
|
aiready-context ./src --max-depth 8 --max-context 25000 --min-cohesion 0.3
|
|
403
490
|
# Explanation: Very lenient - only show the worst offenders
|
|
@@ -405,6 +492,7 @@ aiready-context ./src --max-depth 8 --max-context 25000 --min-cohesion 0.3
|
|
|
405
492
|
```
|
|
406
493
|
|
|
407
494
|
**Preparing for AI refactoring sprint:**
|
|
495
|
+
|
|
408
496
|
```bash
|
|
409
497
|
aiready-context ./src --max-depth 4 --max-context 8000 --min-cohesion 0.6 --max-fragmentation 0.5
|
|
410
498
|
# Explanation: Strict on all dimensions to get comprehensive issue list
|
|
@@ -412,6 +500,7 @@ aiready-context ./src --max-depth 4 --max-context 8000 --min-cohesion 0.6 --max-
|
|
|
412
500
|
```
|
|
413
501
|
|
|
414
502
|
**Microservices architecture (naturally fragmented):**
|
|
503
|
+
|
|
415
504
|
```bash
|
|
416
505
|
aiready-context ./src --max-fragmentation 0.9
|
|
417
506
|
# Explanation: Very lenient on fragmentation (services are meant to be separate)
|
|
@@ -614,24 +703,28 @@ for (const result of results) {
|
|
|
614
703
|
## 📊 Metrics Explained
|
|
615
704
|
|
|
616
705
|
### Import Depth
|
|
706
|
+
|
|
617
707
|
**What:** Maximum chain length of transitive dependencies
|
|
618
708
|
**Impact:** Deeper chains = more files to load = higher context cost
|
|
619
709
|
**Threshold:** >5 is concerning, >8 is critical
|
|
620
710
|
**Fix:** Flatten dependency tree, use facade pattern, break circular deps
|
|
621
711
|
|
|
622
712
|
### Context Budget
|
|
713
|
+
|
|
623
714
|
**What:** Total tokens AI needs to load to understand this file
|
|
624
715
|
**Impact:** Higher budget = more expensive AI assistance
|
|
625
716
|
**Threshold:** >10,000 tokens often hits context limits
|
|
626
717
|
**Fix:** Split files, reduce dependencies, extract interfaces
|
|
627
718
|
|
|
628
719
|
### Fragmentation Score
|
|
720
|
+
|
|
629
721
|
**What:** How scattered related code is across directories (0-100%)
|
|
630
722
|
**Impact:** Higher = more files to load for domain understanding
|
|
631
723
|
**Threshold:** >50% indicates poor organization
|
|
632
724
|
**Fix:** Consolidate related code into cohesive modules
|
|
633
725
|
|
|
634
726
|
### Cohesion Score
|
|
727
|
+
|
|
635
728
|
**What:** How related exports are within a file (0-100%)
|
|
636
729
|
**Impact:** Lower = mixed concerns = wasted context
|
|
637
730
|
**Threshold:** <60% indicates low cohesion
|
|
@@ -657,6 +750,7 @@ for (const result of results) {
|
|
|
657
750
|
### Default Exclusions
|
|
658
751
|
|
|
659
752
|
By default, these patterns are excluded (unless `--include-node-modules` is used):
|
|
753
|
+
|
|
660
754
|
```bash
|
|
661
755
|
# Dependencies (excluded by default, override with --include-node-modules)
|
|
662
756
|
**/node_modules/**
|
|
@@ -699,29 +793,37 @@ interface ContextAnalyzerOptions {
|
|
|
699
793
|
## 🔬 How It Works
|
|
700
794
|
|
|
701
795
|
### 1. Dependency Graph Builder
|
|
796
|
+
|
|
702
797
|
Parses imports and exports to build a complete dependency graph of your codebase.
|
|
703
798
|
|
|
704
799
|
### 2. Depth Calculator
|
|
800
|
+
|
|
705
801
|
Calculates maximum import chain depth using graph traversal, identifying circular dependencies.
|
|
706
802
|
|
|
707
803
|
### 3. Semantic Domain Detection
|
|
804
|
+
|
|
708
805
|
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
806
|
|
|
710
807
|
### 4. Fragmentation Detector
|
|
808
|
+
|
|
711
809
|
Groups files by semantic domain and calculates how scattered they are across directories.
|
|
712
810
|
|
|
713
811
|
### 5. Cohesion Analyzer
|
|
812
|
+
|
|
714
813
|
Uses entropy to measure how related exports are within each file (low entropy = high cohesion).
|
|
715
814
|
|
|
716
815
|
### 6. Context Budget Calculator
|
|
816
|
+
|
|
717
817
|
Sums tokens across entire dependency tree to estimate AI context cost for each file.
|
|
718
818
|
|
|
719
819
|
## 🎨 Output Formats
|
|
720
820
|
|
|
721
821
|
### Console (Default)
|
|
822
|
+
|
|
722
823
|
Rich formatted output with colors, emojis, and actionable recommendations.
|
|
723
824
|
|
|
724
825
|
### JSON
|
|
826
|
+
|
|
725
827
|
Machine-readable output for CI/CD integration:
|
|
726
828
|
|
|
727
829
|
```json
|
|
@@ -748,6 +850,7 @@ Machine-readable output for CI/CD integration:
|
|
|
748
850
|
```
|
|
749
851
|
|
|
750
852
|
### HTML
|
|
853
|
+
|
|
751
854
|
Shareable report with tables and visualizations. Perfect for stakeholders:
|
|
752
855
|
|
|
753
856
|
```bash
|
|
@@ -764,6 +867,7 @@ aiready-context ./src --interactive
|
|
|
764
867
|
```
|
|
765
868
|
|
|
766
869
|
Interactive mode:
|
|
870
|
+
|
|
767
871
|
- Detects frameworks and recommends excludes (e.g., .next, cdk.out)
|
|
768
872
|
- Lets you choose focus areas: frontend, backend, or both
|
|
769
873
|
- Applies configuration without modifying your files
|
|
@@ -813,6 +917,7 @@ aiready-patterns src # Duplicate pattern detection
|
|
|
813
917
|
## 💰 SaaS Features (Coming Soon)
|
|
814
918
|
|
|
815
919
|
### Free Tier (CLI)
|
|
920
|
+
|
|
816
921
|
✅ One-time snapshot analysis
|
|
817
922
|
✅ All metrics and recommendations
|
|
818
923
|
✅ JSON/HTML export
|