mirror of
https://github.com/samiyev/puaros.git
synced 2025-12-28 15:26:53 +05:00
Compare commits
8 Commits
ipuaro-v0.
...
ipuaro-v0.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92ba3fd9ba | ||
|
|
e9aaa708fe | ||
|
|
d6d15dd271 | ||
|
|
d63d85d850 | ||
|
|
41cfc21f20 | ||
|
|
eeaa223436 | ||
|
|
36768c06d1 | ||
|
|
5a22cd5c9b |
@@ -5,6 +5,214 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.29.0] - 2025-12-05 - Impact Score
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **High Impact Files in Initial Context (v0.29.0)**
|
||||||
|
- New `## High Impact Files` section in initial context
|
||||||
|
- Shows files with highest impact scores (percentage of codebase depending on them)
|
||||||
|
- Table format with File, Impact %, and Dependents count
|
||||||
|
- Files sorted by impact score descending
|
||||||
|
- Default: shows top 10 files with impact score >= 5%
|
||||||
|
|
||||||
|
- **Impact Score Computation**
|
||||||
|
- New `impactScore: number` field in `FileMeta` (0-100)
|
||||||
|
- Formula: `(dependents.length / (totalFiles - 1)) * 100`
|
||||||
|
- Computed in `MetaAnalyzer.analyzeAll()` after all files analyzed
|
||||||
|
- New `calculateImpactScore()` helper function in FileMeta.ts
|
||||||
|
|
||||||
|
- **Configuration Option**
|
||||||
|
- `includeHighImpactFiles: boolean` in ContextConfigSchema (default: `true`)
|
||||||
|
- `includeHighImpactFiles` option in `BuildContextOptions`
|
||||||
|
- Users can disable to save tokens: `context.includeHighImpactFiles: false`
|
||||||
|
|
||||||
|
- **New Helper Function in prompts.ts**
|
||||||
|
- `formatHighImpactFiles()` - formats high impact files table for display
|
||||||
|
|
||||||
|
### New Context Format
|
||||||
|
|
||||||
|
```
|
||||||
|
## High Impact Files
|
||||||
|
|
||||||
|
| File | Impact | Dependents |
|
||||||
|
|------|--------|------------|
|
||||||
|
| utils/validation | 67% | 12 files |
|
||||||
|
| types/user | 45% | 8 files |
|
||||||
|
| services/user | 34% | 6 files |
|
||||||
|
```
|
||||||
|
|
||||||
|
### Technical Details
|
||||||
|
|
||||||
|
- Total tests: 1826 passed (was 1798, +28 new tests)
|
||||||
|
- 9 new tests for calculateImpactScore()
|
||||||
|
- 14 new tests for formatHighImpactFiles() and buildInitialContext
|
||||||
|
- 5 new tests for includeHighImpactFiles config option
|
||||||
|
- Coverage: 97.52% lines, 91.3% branches, 98.63% functions
|
||||||
|
- 0 ESLint errors, 3 warnings (pre-existing complexity)
|
||||||
|
- Build successful
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
|
||||||
|
This completes v0.29.0 of the Graph Metrics milestone:
|
||||||
|
- ✅ 0.27.0 - Inline Dependency Graph
|
||||||
|
- ✅ 0.28.0 - Circular Dependencies in Context
|
||||||
|
- ✅ 0.29.0 - Impact Score
|
||||||
|
|
||||||
|
Next milestone: v0.30.0 - Transitive Dependencies Count
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## [0.28.0] - 2025-12-05 - Circular Dependencies in Context
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Circular Dependencies in Initial Context (v0.28.0)**
|
||||||
|
- New `## ⚠️ Circular Dependencies` section in initial context
|
||||||
|
- Shows cycle chains immediately without requiring tool calls
|
||||||
|
- Format: `- services/user → services/auth → services/user`
|
||||||
|
- Uses same path shortening as dependency graph (removes `src/`, extensions, `/index`)
|
||||||
|
|
||||||
|
- **Configuration Option**
|
||||||
|
- `includeCircularDeps: boolean` in ContextConfigSchema (default: `true`)
|
||||||
|
- `includeCircularDeps` option in `BuildContextOptions`
|
||||||
|
- `circularDeps: string[][]` parameter to pass pre-computed cycles
|
||||||
|
- Users can disable to save tokens: `context.includeCircularDeps: false`
|
||||||
|
|
||||||
|
- **New Helper Function in prompts.ts**
|
||||||
|
- `formatCircularDeps()` - formats circular dependency cycles for display
|
||||||
|
|
||||||
|
### New Context Format
|
||||||
|
|
||||||
|
```
|
||||||
|
## ⚠️ Circular Dependencies
|
||||||
|
|
||||||
|
- services/user → services/auth → services/user
|
||||||
|
- utils/a → utils/b → utils/c → utils/a
|
||||||
|
```
|
||||||
|
|
||||||
|
### Technical Details
|
||||||
|
|
||||||
|
- Total tests: 1798 passed (was 1775, +23 new tests)
|
||||||
|
- 12 new tests for formatCircularDeps()
|
||||||
|
- 6 new tests for buildInitialContext with includeCircularDeps
|
||||||
|
- 5 new tests for includeCircularDeps config option
|
||||||
|
- Coverage: 97.48% lines, 91.13% branches, 98.63% functions
|
||||||
|
- 0 ESLint errors, 3 warnings (pre-existing complexity in ASTParser and prompts)
|
||||||
|
- Build successful
|
||||||
|
|
||||||
|
## [0.27.0] - 2025-12-05 - Inline Dependency Graph
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Dependency Graph in Initial Context (v0.27.0)**
|
||||||
|
- New `## Dependency Graph` section in initial context
|
||||||
|
- Shows file relationships without requiring tool calls
|
||||||
|
- Format: `services/user: → types/user, utils/validation ← controllers/user`
|
||||||
|
- `→` indicates files this file imports (dependencies)
|
||||||
|
- `←` indicates files that import this file (dependents)
|
||||||
|
- Hub files (>5 dependents) shown first
|
||||||
|
- Files sorted by total connections (descending)
|
||||||
|
|
||||||
|
- **Configuration Option**
|
||||||
|
- `includeDepsGraph: boolean` in ContextConfigSchema (default: `true`)
|
||||||
|
- `includeDepsGraph` option in `BuildContextOptions`
|
||||||
|
- Users can disable to save tokens: `context.includeDepsGraph: false`
|
||||||
|
|
||||||
|
- **New Helper Functions in prompts.ts**
|
||||||
|
- `formatDependencyGraph()` - formats entire dependency graph from metas
|
||||||
|
- `formatDepsEntry()` - formats single file's dependencies/dependents
|
||||||
|
- `shortenPath()` - shortens paths (removes `src/`, extensions, `/index`)
|
||||||
|
|
||||||
|
### New Context Format
|
||||||
|
|
||||||
|
```
|
||||||
|
## Dependency Graph
|
||||||
|
|
||||||
|
utils/validation: ← services/user, services/auth, controllers/api
|
||||||
|
services/user: → types/user, utils/validation ← controllers/user, api/routes
|
||||||
|
services/auth: → services/user, utils/jwt ← controllers/auth
|
||||||
|
types/user: ← services/user, services/auth
|
||||||
|
```
|
||||||
|
|
||||||
|
### Technical Details
|
||||||
|
|
||||||
|
- Total tests: 1775 passed (was 1754, +21 new tests)
|
||||||
|
- 16 new tests for formatDependencyGraph()
|
||||||
|
- 5 new tests for includeDepsGraph config option
|
||||||
|
- Coverage: 97.48% lines, 91.07% branches, 98.62% functions
|
||||||
|
- 0 ESLint errors, 2 warnings (pre-existing complexity in ASTParser and prompts)
|
||||||
|
- Build successful
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
|
||||||
|
This completes v0.27.0 of the Graph Metrics milestone:
|
||||||
|
- ✅ 0.27.0 - Inline Dependency Graph
|
||||||
|
|
||||||
|
Next milestone: v0.28.0 - Circular Dependencies in Context
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## [0.26.0] - 2025-12-05 - Rich Initial Context: Decorator Extraction
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **Decorator Extraction (0.24.4)**
|
||||||
|
- Functions now show their decorators in initial context
|
||||||
|
- Classes now show their decorators in initial context
|
||||||
|
- Methods show decorators per-method
|
||||||
|
- New format: `@Controller('users') class UserController`
|
||||||
|
- Function format: `@Get(':id') async getUser(id: string): Promise<User>`
|
||||||
|
- Supports NestJS decorators: `@Controller`, `@Get`, `@Post`, `@Injectable`, `@UseGuards`, etc.
|
||||||
|
- Supports Angular decorators: `@Component`, `@Injectable`, `@Input`, `@Output`, etc.
|
||||||
|
|
||||||
|
- **FileAST.ts Enhancements**
|
||||||
|
- `decorators?: string[]` field on `FunctionInfo`
|
||||||
|
- `decorators?: string[]` field on `MethodInfo`
|
||||||
|
- `decorators?: string[]` field on `ClassInfo`
|
||||||
|
|
||||||
|
- **ASTParser.ts Enhancements**
|
||||||
|
- `formatDecorator()` - formats decorator node to string (e.g., `@Get(':id')`)
|
||||||
|
- `extractNodeDecorators()` - extracts decorators that are direct children of a node
|
||||||
|
- `extractDecoratorsFromSiblings()` - extracts decorators before the declaration in export statements
|
||||||
|
- Decorators are extracted for classes, methods, and exported functions
|
||||||
|
|
||||||
|
- **prompts.ts Enhancements**
|
||||||
|
- `formatDecoratorsPrefix()` - formats decorators as a prefix string for display
|
||||||
|
- Used in `formatFunctionSignature()` for function decorators
|
||||||
|
- Used in `formatFileSummary()` for class decorators
|
||||||
|
|
||||||
|
### New Context Format
|
||||||
|
|
||||||
|
```
|
||||||
|
### src/controllers/user.controller.ts
|
||||||
|
- @Controller('users') class UserController extends BaseController
|
||||||
|
- @Get(':id') @Auth() async getUser(id: string): Promise<User>
|
||||||
|
- @Post() @ValidateBody() async createUser(data: UserDTO): Promise<User>
|
||||||
|
```
|
||||||
|
|
||||||
|
### Technical Details
|
||||||
|
|
||||||
|
- Total tests: 1754 passed (was 1720, +34 new tests)
|
||||||
|
- 14 new tests for ASTParser decorator extraction
|
||||||
|
- 6 new tests for prompts decorator formatting
|
||||||
|
- +14 other tests from internal improvements
|
||||||
|
- Coverage: 97.49% lines, 91.14% branches, 98.61% functions
|
||||||
|
- 0 ESLint errors, 2 warnings (pre-existing complexity in ASTParser and prompts)
|
||||||
|
- Build successful
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
|
||||||
|
This completes the v0.24.0 Rich Initial Context milestone:
|
||||||
|
- ✅ 0.24.1 - Function Signatures with Types
|
||||||
|
- ✅ 0.24.2 - Interface/Type Field Definitions
|
||||||
|
- ✅ 0.24.3 - Enum Value Definitions
|
||||||
|
- ✅ 0.24.4 - Decorator Extraction
|
||||||
|
|
||||||
|
Next milestone: v0.25.0 - Graph Metrics in Context
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## [0.25.0] - 2025-12-04 - Rich Initial Context: Interface Fields & Type Definitions
|
## [0.25.0] - 2025-12-04 - Rich Initial Context: Interface Fields & Type Definitions
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -1779,10 +1779,10 @@ export interface ScanResult {
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Version 0.24.0 - Rich Initial Context 📋
|
## Version 0.24.0 - Rich Initial Context 📋 ✅
|
||||||
|
|
||||||
**Priority:** HIGH
|
**Priority:** HIGH
|
||||||
**Status:** In Progress (2/4 complete)
|
**Status:** Complete (v0.24.0 released)
|
||||||
|
|
||||||
Enhance initial context for LLM: add function signatures, interface field types, and enum values. This allows LLM to answer questions about types and parameters without tool calls.
|
Enhance initial context for LLM: add function signatures, interface field types, and enum values. This allows LLM to answer questions about types and parameters without tool calls.
|
||||||
|
|
||||||
@@ -1836,7 +1836,7 @@ Enhance initial context for LLM: add function signatures, interface field types,
|
|||||||
|
|
||||||
**Why:** LLM knows data structure, won't invent fields.
|
**Why:** LLM knows data structure, won't invent fields.
|
||||||
|
|
||||||
### 0.24.3 - Enum Value Definitions
|
### 0.24.3 - Enum Value Definitions ⭐ ✅
|
||||||
|
|
||||||
**Problem:** LLM only sees `type: Status`
|
**Problem:** LLM only sees `type: Status`
|
||||||
**Solution:** Show values: `Status { Active=1, Inactive=0, Pending=2 }`
|
**Solution:** Show values: `Status { Active=1, Inactive=0, Pending=2 }`
|
||||||
@@ -1852,13 +1852,13 @@ Enhance initial context for LLM: add function signatures, interface field types,
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Changes:**
|
**Changes:**
|
||||||
- [ ] Add `EnumInfo` to FileAST with members and values
|
- [x] Add `EnumInfo` to FileAST with members and values
|
||||||
- [ ] Update `ASTParser.ts` to extract enum members
|
- [x] Update `ASTParser.ts` to extract enum members
|
||||||
- [ ] Update `formatFileSummary()` to output enum values
|
- [x] Update `formatFileSummary()` to output enum values
|
||||||
|
|
||||||
**Why:** LLM knows valid enum values.
|
**Why:** LLM knows valid enum values.
|
||||||
|
|
||||||
### 0.24.4 - Decorator Extraction
|
### 0.24.4 - Decorator Extraction ⭐ ✅
|
||||||
|
|
||||||
**Problem:** LLM doesn't see decorators (important for NestJS, Angular)
|
**Problem:** LLM doesn't see decorators (important for NestJS, Angular)
|
||||||
**Solution:** Show decorators in context
|
**Solution:** Show decorators in context
|
||||||
@@ -1872,27 +1872,24 @@ Enhance initial context for LLM: add function signatures, interface field types,
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Changes:**
|
**Changes:**
|
||||||
- [ ] Add `decorators: string[]` to FunctionInfo and ClassInfo
|
- [x] Add `decorators: string[]` to FunctionInfo, MethodInfo, and ClassInfo
|
||||||
- [ ] Update `ASTParser.ts` to extract decorators
|
- [x] Update `ASTParser.ts` to extract decorators via `extractNodeDecorators()` and `extractDecoratorsFromSiblings()`
|
||||||
- [ ] Update context to display decorators
|
- [x] Update `prompts.ts` to display decorators via `formatDecoratorsPrefix()`
|
||||||
|
|
||||||
**Why:** LLM understands routing, DI, guards in NestJS/Angular.
|
**Why:** LLM understands routing, DI, guards in NestJS/Angular.
|
||||||
|
|
||||||
**Tests:**
|
**Tests:**
|
||||||
- [ ] Unit tests for enhanced ASTParser
|
- [x] Unit tests for ASTParser decorator extraction (14 tests)
|
||||||
- [ ] Unit tests for new context format
|
- [x] Unit tests for prompts decorator formatting (6 tests)
|
||||||
- [ ] Integration tests for full flow
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Version 0.25.0 - Graph Metrics in Context 📊
|
## Version 0.27.0 - Inline Dependency Graph 📊 ✅
|
||||||
|
|
||||||
**Priority:** MEDIUM
|
**Priority:** MEDIUM
|
||||||
**Status:** Planned
|
**Status:** Complete (v0.27.0 released)
|
||||||
|
|
||||||
Add graph metrics to initial context: dependency graph, circular dependencies, impact score.
|
### Description
|
||||||
|
|
||||||
### 0.25.1 - Inline Dependency Graph
|
|
||||||
|
|
||||||
**Problem:** LLM doesn't see file relationships without tool calls
|
**Problem:** LLM doesn't see file relationships without tool calls
|
||||||
**Solution:** Show dependency graph in context
|
**Solution:** Show dependency graph in context
|
||||||
@@ -1907,14 +1904,25 @@ Add graph metrics to initial context: dependency graph, circular dependencies, i
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Changes:**
|
**Changes:**
|
||||||
- [ ] Add `formatDependencyGraph()` to prompts.ts
|
- [x] Add `formatDependencyGraph()` to prompts.ts
|
||||||
- [ ] Use data from `FileMeta.dependencies` and `FileMeta.dependents`
|
- [x] Use data from `FileMeta.dependencies` and `FileMeta.dependents`
|
||||||
- [ ] Group by hub files (many connections)
|
- [x] Group by hub files (many connections)
|
||||||
- [ ] Add `includeDepsGraph: boolean` option to config
|
- [x] Add `includeDepsGraph: boolean` option to config
|
||||||
|
|
||||||
|
**Tests:**
|
||||||
|
- [x] Unit tests for formatDependencyGraph() (16 tests)
|
||||||
|
- [x] Unit tests for includeDepsGraph config option (5 tests)
|
||||||
|
|
||||||
**Why:** LLM sees architecture without tool call.
|
**Why:** LLM sees architecture without tool call.
|
||||||
|
|
||||||
### 0.25.2 - Circular Dependencies in Context
|
---
|
||||||
|
|
||||||
|
## Version 0.28.0 - Circular Dependencies in Context 🔄 ✅
|
||||||
|
|
||||||
|
**Priority:** MEDIUM
|
||||||
|
**Status:** Complete (v0.28.0 released)
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
**Problem:** Circular deps are computed but not shown in context
|
**Problem:** Circular deps are computed but not shown in context
|
||||||
**Solution:** Show cycles immediately
|
**Solution:** Show cycles immediately
|
||||||
@@ -1928,13 +1936,26 @@ Add graph metrics to initial context: dependency graph, circular dependencies, i
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Changes:**
|
**Changes:**
|
||||||
- [ ] Add `formatCircularDeps()` to prompts.ts
|
- [x] Add `formatCircularDeps()` to prompts.ts
|
||||||
- [ ] Get circular deps from IndexBuilder
|
- [x] Add `includeCircularDeps: boolean` config option (default: true)
|
||||||
- [ ] Store in Redis as separate key or in meta
|
- [x] Add `circularDeps: string[][]` parameter to `BuildContextOptions`
|
||||||
|
- [x] Integrate into `buildInitialContext()`
|
||||||
|
|
||||||
|
**Tests:**
|
||||||
|
- [x] Unit tests for formatCircularDeps() (12 tests)
|
||||||
|
- [x] Unit tests for buildInitialContext with includeCircularDeps (6 tests)
|
||||||
|
- [x] Unit tests for includeCircularDeps config option (5 tests)
|
||||||
|
|
||||||
**Why:** LLM immediately sees architecture problems.
|
**Why:** LLM immediately sees architecture problems.
|
||||||
|
|
||||||
### 0.25.3 - Impact Score
|
---
|
||||||
|
|
||||||
|
## Version 0.29.0 - Impact Score 📈 ✅
|
||||||
|
|
||||||
|
**Priority:** MEDIUM
|
||||||
|
**Status:** Complete (v0.29.0 released)
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
**Problem:** LLM doesn't know which files are critical
|
**Problem:** LLM doesn't know which files are critical
|
||||||
**Solution:** Show impact score (% of codebase that depends on file)
|
**Solution:** Show impact score (% of codebase that depends on file)
|
||||||
@@ -1951,14 +1972,27 @@ Add graph metrics to initial context: dependency graph, circular dependencies, i
|
|||||||
```
|
```
|
||||||
|
|
||||||
**Changes:**
|
**Changes:**
|
||||||
- [ ] Add `impactScore: number` to FileMeta (0-100)
|
- [x] Add `impactScore: number` to FileMeta (0-100)
|
||||||
- [ ] Compute in MetaAnalyzer: (transitiveDepByCount / totalFiles) * 100
|
- [x] Compute in MetaAnalyzer: (dependents.length / (totalFiles - 1)) * 100
|
||||||
- [ ] Add `formatHighImpactFiles()` to prompts.ts
|
- [x] Add `formatHighImpactFiles()` to prompts.ts
|
||||||
- [ ] Show top-10 high impact files
|
- [x] Show top-10 high impact files
|
||||||
|
- [x] Add `includeHighImpactFiles` config option (default: true)
|
||||||
|
|
||||||
|
**Tests:**
|
||||||
|
- [x] Unit tests for calculateImpactScore (9 tests)
|
||||||
|
- [x] Unit tests for formatHighImpactFiles (14 tests)
|
||||||
|
- [x] Unit tests for includeHighImpactFiles config (5 tests)
|
||||||
|
|
||||||
**Why:** LLM understands which files are critical for changes.
|
**Why:** LLM understands which files are critical for changes.
|
||||||
|
|
||||||
### 0.25.4 - Transitive Dependencies Count
|
---
|
||||||
|
|
||||||
|
## Version 0.30.0 - Transitive Dependencies Count 🔢
|
||||||
|
|
||||||
|
**Priority:** MEDIUM
|
||||||
|
**Status:** Planned
|
||||||
|
|
||||||
|
### Description
|
||||||
|
|
||||||
**Problem:** Currently only counting direct dependencies
|
**Problem:** Currently only counting direct dependencies
|
||||||
**Solution:** Add transitive dependencies to meta
|
**Solution:** Add transitive dependencies to meta
|
||||||
@@ -1978,8 +2012,7 @@ interface FileMeta {
|
|||||||
- [ ] Store in FileMeta
|
- [ ] Store in FileMeta
|
||||||
|
|
||||||
**Tests:**
|
**Tests:**
|
||||||
- [ ] Unit tests for graph metrics computation
|
- [ ] Unit tests for transitive dependencies computation
|
||||||
- [ ] Unit tests for new context sections
|
|
||||||
- [ ] Performance tests for large codebases
|
- [ ] Performance tests for large codebases
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -1995,12 +2028,12 @@ interface FileMeta {
|
|||||||
- [x] Error handling complete ✅ (v0.16.0)
|
- [x] Error handling complete ✅ (v0.16.0)
|
||||||
- [ ] Performance optimized
|
- [ ] Performance optimized
|
||||||
- [x] Documentation complete ✅ (v0.17.0)
|
- [x] Documentation complete ✅ (v0.17.0)
|
||||||
- [x] Test coverage ≥91% branches, ≥95% lines/functions/statements ✅ (91.21% branches, 97.5% lines, 98.58% functions, 97.5% statements - 1687 tests)
|
- [x] Test coverage ≥91% branches, ≥95% lines/functions/statements ✅ (91.3% branches, 97.52% lines, 98.63% functions, 97.52% statements - 1826 tests)
|
||||||
- [x] 0 ESLint errors ✅
|
- [x] 0 ESLint errors ✅
|
||||||
- [x] Examples working ✅ (v0.18.0)
|
- [x] Examples working ✅ (v0.18.0)
|
||||||
- [x] CHANGELOG.md up to date ✅
|
- [x] CHANGELOG.md up to date ✅
|
||||||
- [ ] Rich initial context (v0.24.0) — function signatures, interface fields, enum values
|
- [x] Rich initial context (v0.24.0-v0.26.0) — function signatures, interface fields, enum values, decorators ✅
|
||||||
- [ ] Graph metrics in context (v0.25.0) — dependency graph, circular deps, impact score
|
- [ ] Graph metrics in context (v0.27.0-v0.30.0) — dependency graph ✅, circular deps ✅, impact score ✅, transitive deps
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -2077,9 +2110,9 @@ sessions:list # List<session_id>
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Last Updated:** 2025-12-04
|
**Last Updated:** 2025-12-05
|
||||||
**Target Version:** 1.0.0
|
**Target Version:** 1.0.0
|
||||||
**Current Version:** 0.25.0
|
**Current Version:** 0.29.0
|
||||||
**Next Milestones:** v0.24.0 (Rich Context - 2/4 complete), v0.25.0 (Graph Metrics)
|
**Next Milestones:** v0.30.0 (Transitive Deps), v1.0.0 (Production Ready)
|
||||||
|
|
||||||
> **Note:** v0.24.0 and v0.25.0 are required for 1.0.0 release. They enable LLM to answer questions about types, signatures, and architecture without tool calls.
|
> **Note:** Rich Initial Context complete ✅ (v0.24.0-v0.26.0). Graph Metrics in progress (v0.27.0 ✅, v0.28.0 ✅, v0.29.0 ✅, v0.30.0 pending) for 1.0.0 release.
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@samiyev/ipuaro",
|
"name": "@samiyev/ipuaro",
|
||||||
"version": "0.25.0",
|
"version": "0.29.0",
|
||||||
"description": "Local AI agent for codebase operations with infinite context feeling",
|
"description": "Local AI agent for codebase operations with infinite context feeling",
|
||||||
"author": "Fozilbek Samiyev <fozilbek.samiyev@gmail.com>",
|
"author": "Fozilbek Samiyev <fozilbek.samiyev@gmail.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ export interface FunctionInfo {
|
|||||||
isExported: boolean
|
isExported: boolean
|
||||||
/** Return type (if available) */
|
/** Return type (if available) */
|
||||||
returnType?: string
|
returnType?: string
|
||||||
|
/** Decorators applied to the function (e.g., ["@Get(':id')", "@Auth()"]) */
|
||||||
|
decorators?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface MethodInfo {
|
export interface MethodInfo {
|
||||||
@@ -69,6 +71,8 @@ export interface MethodInfo {
|
|||||||
visibility: "public" | "private" | "protected"
|
visibility: "public" | "private" | "protected"
|
||||||
/** Whether it's static */
|
/** Whether it's static */
|
||||||
isStatic: boolean
|
isStatic: boolean
|
||||||
|
/** Decorators applied to the method (e.g., ["@Get(':id')", "@UseGuards(AuthGuard)"]) */
|
||||||
|
decorators?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PropertyInfo {
|
export interface PropertyInfo {
|
||||||
@@ -105,6 +109,8 @@ export interface ClassInfo {
|
|||||||
isExported: boolean
|
isExported: boolean
|
||||||
/** Whether class is abstract */
|
/** Whether class is abstract */
|
||||||
isAbstract: boolean
|
isAbstract: boolean
|
||||||
|
/** Decorators applied to the class (e.g., ["@Controller('users')", "@Injectable()"]) */
|
||||||
|
decorators?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InterfaceInfo {
|
export interface InterfaceInfo {
|
||||||
@@ -133,6 +139,28 @@ export interface TypeAliasInfo {
|
|||||||
definition?: string
|
definition?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EnumMemberInfo {
|
||||||
|
/** Member name */
|
||||||
|
name: string
|
||||||
|
/** Member value (string or number, if specified) */
|
||||||
|
value?: string | number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EnumInfo {
|
||||||
|
/** Enum name */
|
||||||
|
name: string
|
||||||
|
/** Start line number */
|
||||||
|
lineStart: number
|
||||||
|
/** End line number */
|
||||||
|
lineEnd: number
|
||||||
|
/** Enum members with values */
|
||||||
|
members: EnumMemberInfo[]
|
||||||
|
/** Whether it's exported */
|
||||||
|
isExported: boolean
|
||||||
|
/** Whether it's a const enum */
|
||||||
|
isConst: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export interface FileAST {
|
export interface FileAST {
|
||||||
/** Import statements */
|
/** Import statements */
|
||||||
imports: ImportInfo[]
|
imports: ImportInfo[]
|
||||||
@@ -146,6 +174,8 @@ export interface FileAST {
|
|||||||
interfaces: InterfaceInfo[]
|
interfaces: InterfaceInfo[]
|
||||||
/** Type alias declarations */
|
/** Type alias declarations */
|
||||||
typeAliases: TypeAliasInfo[]
|
typeAliases: TypeAliasInfo[]
|
||||||
|
/** Enum declarations */
|
||||||
|
enums: EnumInfo[]
|
||||||
/** Whether parsing encountered errors */
|
/** Whether parsing encountered errors */
|
||||||
parseError: boolean
|
parseError: boolean
|
||||||
/** Parse error message if any */
|
/** Parse error message if any */
|
||||||
@@ -160,6 +190,7 @@ export function createEmptyFileAST(): FileAST {
|
|||||||
classes: [],
|
classes: [],
|
||||||
interfaces: [],
|
interfaces: [],
|
||||||
typeAliases: [],
|
typeAliases: [],
|
||||||
|
enums: [],
|
||||||
parseError: false,
|
parseError: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ export interface FileMeta {
|
|||||||
isEntryPoint: boolean
|
isEntryPoint: boolean
|
||||||
/** File type classification */
|
/** File type classification */
|
||||||
fileType: "source" | "test" | "config" | "types" | "unknown"
|
fileType: "source" | "test" | "config" | "types" | "unknown"
|
||||||
|
/** Impact score (0-100): percentage of codebase that depends on this file */
|
||||||
|
impactScore: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createFileMeta(partial: Partial<FileMeta> = {}): FileMeta {
|
export function createFileMeta(partial: Partial<FileMeta> = {}): FileMeta {
|
||||||
@@ -41,6 +43,7 @@ export function createFileMeta(partial: Partial<FileMeta> = {}): FileMeta {
|
|||||||
isHub: false,
|
isHub: false,
|
||||||
isEntryPoint: false,
|
isEntryPoint: false,
|
||||||
fileType: "unknown",
|
fileType: "unknown",
|
||||||
|
impactScore: 0,
|
||||||
...partial,
|
...partial,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -48,3 +51,20 @@ export function createFileMeta(partial: Partial<FileMeta> = {}): FileMeta {
|
|||||||
export function isHubFile(dependentCount: number): boolean {
|
export function isHubFile(dependentCount: number): boolean {
|
||||||
return dependentCount > 5
|
return dependentCount > 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate impact score based on number of dependents and total files.
|
||||||
|
* Impact score represents what percentage of the codebase depends on this file.
|
||||||
|
* @param dependentCount - Number of files that depend on this file
|
||||||
|
* @param totalFiles - Total number of files in the project
|
||||||
|
* @returns Impact score from 0 to 100
|
||||||
|
*/
|
||||||
|
export function calculateImpactScore(dependentCount: number, totalFiles: number): number {
|
||||||
|
if (totalFiles <= 1) {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
// Exclude the file itself from the total
|
||||||
|
const maxPossibleDependents = totalFiles - 1
|
||||||
|
const score = (dependentCount / maxPossibleDependents) * 100
|
||||||
|
return Math.round(Math.min(100, score))
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import JSON from "tree-sitter-json"
|
|||||||
import * as yamlParser from "yaml"
|
import * as yamlParser from "yaml"
|
||||||
import {
|
import {
|
||||||
createEmptyFileAST,
|
createEmptyFileAST,
|
||||||
|
type EnumMemberInfo,
|
||||||
type ExportInfo,
|
type ExportInfo,
|
||||||
type FileAST,
|
type FileAST,
|
||||||
type ImportInfo,
|
type ImportInfo,
|
||||||
@@ -192,6 +193,11 @@ export class ASTParser {
|
|||||||
this.extractTypeAlias(node, ast, false)
|
this.extractTypeAlias(node, ast, false)
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
|
case NodeType.ENUM_DECLARATION:
|
||||||
|
if (isTypeScript) {
|
||||||
|
this.extractEnum(node, ast, false)
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,13 +264,15 @@ export class ASTParser {
|
|||||||
const declaration = node.childForFieldName(FieldName.DECLARATION)
|
const declaration = node.childForFieldName(FieldName.DECLARATION)
|
||||||
|
|
||||||
if (declaration) {
|
if (declaration) {
|
||||||
|
const decorators = this.extractDecoratorsFromSiblings(declaration)
|
||||||
|
|
||||||
switch (declaration.type) {
|
switch (declaration.type) {
|
||||||
case NodeType.FUNCTION_DECLARATION:
|
case NodeType.FUNCTION_DECLARATION:
|
||||||
this.extractFunction(declaration, ast, true)
|
this.extractFunction(declaration, ast, true, decorators)
|
||||||
this.addExportInfo(ast, declaration, "function", isDefault)
|
this.addExportInfo(ast, declaration, "function", isDefault)
|
||||||
break
|
break
|
||||||
case NodeType.CLASS_DECLARATION:
|
case NodeType.CLASS_DECLARATION:
|
||||||
this.extractClass(declaration, ast, true)
|
this.extractClass(declaration, ast, true, decorators)
|
||||||
this.addExportInfo(ast, declaration, "class", isDefault)
|
this.addExportInfo(ast, declaration, "class", isDefault)
|
||||||
break
|
break
|
||||||
case NodeType.INTERFACE_DECLARATION:
|
case NodeType.INTERFACE_DECLARATION:
|
||||||
@@ -275,6 +283,10 @@ export class ASTParser {
|
|||||||
this.extractTypeAlias(declaration, ast, true)
|
this.extractTypeAlias(declaration, ast, true)
|
||||||
this.addExportInfo(ast, declaration, "type", isDefault)
|
this.addExportInfo(ast, declaration, "type", isDefault)
|
||||||
break
|
break
|
||||||
|
case NodeType.ENUM_DECLARATION:
|
||||||
|
this.extractEnum(declaration, ast, true)
|
||||||
|
this.addExportInfo(ast, declaration, "type", isDefault)
|
||||||
|
break
|
||||||
case NodeType.LEXICAL_DECLARATION:
|
case NodeType.LEXICAL_DECLARATION:
|
||||||
this.extractLexicalDeclaration(declaration, ast, true)
|
this.extractLexicalDeclaration(declaration, ast, true)
|
||||||
break
|
break
|
||||||
@@ -299,7 +311,12 @@ export class ASTParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extractFunction(node: SyntaxNode, ast: FileAST, isExported: boolean): void {
|
private extractFunction(
|
||||||
|
node: SyntaxNode,
|
||||||
|
ast: FileAST,
|
||||||
|
isExported: boolean,
|
||||||
|
externalDecorators: string[] = [],
|
||||||
|
): void {
|
||||||
const nameNode = node.childForFieldName(FieldName.NAME)
|
const nameNode = node.childForFieldName(FieldName.NAME)
|
||||||
if (!nameNode) {
|
if (!nameNode) {
|
||||||
return
|
return
|
||||||
@@ -309,6 +326,9 @@ export class ASTParser {
|
|||||||
const isAsync = node.children.some((c) => c.type === NodeType.ASYNC)
|
const isAsync = node.children.some((c) => c.type === NodeType.ASYNC)
|
||||||
const returnTypeNode = node.childForFieldName(FieldName.RETURN_TYPE)
|
const returnTypeNode = node.childForFieldName(FieldName.RETURN_TYPE)
|
||||||
|
|
||||||
|
const nodeDecorators = this.extractNodeDecorators(node)
|
||||||
|
const decorators = [...externalDecorators, ...nodeDecorators]
|
||||||
|
|
||||||
ast.functions.push({
|
ast.functions.push({
|
||||||
name: nameNode.text,
|
name: nameNode.text,
|
||||||
lineStart: node.startPosition.row + 1,
|
lineStart: node.startPosition.row + 1,
|
||||||
@@ -317,6 +337,7 @@ export class ASTParser {
|
|||||||
isAsync,
|
isAsync,
|
||||||
isExported,
|
isExported,
|
||||||
returnType: returnTypeNode?.text?.replace(/^:\s*/, ""),
|
returnType: returnTypeNode?.text?.replace(/^:\s*/, ""),
|
||||||
|
decorators,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,6 +363,7 @@ export class ASTParser {
|
|||||||
isAsync,
|
isAsync,
|
||||||
isExported,
|
isExported,
|
||||||
returnType: returnTypeNode?.text?.replace(/^:\s*/, ""),
|
returnType: returnTypeNode?.text?.replace(/^:\s*/, ""),
|
||||||
|
decorators: [],
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isExported) {
|
if (isExported) {
|
||||||
@@ -364,7 +386,12 @@ export class ASTParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extractClass(node: SyntaxNode, ast: FileAST, isExported: boolean): void {
|
private extractClass(
|
||||||
|
node: SyntaxNode,
|
||||||
|
ast: FileAST,
|
||||||
|
isExported: boolean,
|
||||||
|
externalDecorators: string[] = [],
|
||||||
|
): void {
|
||||||
const nameNode = node.childForFieldName(FieldName.NAME)
|
const nameNode = node.childForFieldName(FieldName.NAME)
|
||||||
if (!nameNode) {
|
if (!nameNode) {
|
||||||
return
|
return
|
||||||
@@ -375,14 +402,19 @@ export class ASTParser {
|
|||||||
const properties: PropertyInfo[] = []
|
const properties: PropertyInfo[] = []
|
||||||
|
|
||||||
if (body) {
|
if (body) {
|
||||||
|
let pendingDecorators: string[] = []
|
||||||
for (const member of body.children) {
|
for (const member of body.children) {
|
||||||
if (member.type === NodeType.METHOD_DEFINITION) {
|
if (member.type === NodeType.DECORATOR) {
|
||||||
methods.push(this.extractMethod(member))
|
pendingDecorators.push(this.formatDecorator(member))
|
||||||
|
} else if (member.type === NodeType.METHOD_DEFINITION) {
|
||||||
|
methods.push(this.extractMethod(member, pendingDecorators))
|
||||||
|
pendingDecorators = []
|
||||||
} else if (
|
} else if (
|
||||||
member.type === NodeType.PUBLIC_FIELD_DEFINITION ||
|
member.type === NodeType.PUBLIC_FIELD_DEFINITION ||
|
||||||
member.type === NodeType.FIELD_DEFINITION
|
member.type === NodeType.FIELD_DEFINITION
|
||||||
) {
|
) {
|
||||||
properties.push(this.extractProperty(member))
|
properties.push(this.extractProperty(member))
|
||||||
|
pendingDecorators = []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -390,6 +422,9 @@ export class ASTParser {
|
|||||||
const { extendsName, implementsList } = this.extractClassHeritage(node)
|
const { extendsName, implementsList } = this.extractClassHeritage(node)
|
||||||
const isAbstract = node.children.some((c) => c.type === NodeType.ABSTRACT)
|
const isAbstract = node.children.some((c) => c.type === NodeType.ABSTRACT)
|
||||||
|
|
||||||
|
const nodeDecorators = this.extractNodeDecorators(node)
|
||||||
|
const decorators = [...externalDecorators, ...nodeDecorators]
|
||||||
|
|
||||||
ast.classes.push({
|
ast.classes.push({
|
||||||
name: nameNode.text,
|
name: nameNode.text,
|
||||||
lineStart: node.startPosition.row + 1,
|
lineStart: node.startPosition.row + 1,
|
||||||
@@ -400,6 +435,7 @@ export class ASTParser {
|
|||||||
implements: implementsList,
|
implements: implementsList,
|
||||||
isExported,
|
isExported,
|
||||||
isAbstract,
|
isAbstract,
|
||||||
|
decorators,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +489,7 @@ export class ASTParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private extractMethod(node: SyntaxNode): MethodInfo {
|
private extractMethod(node: SyntaxNode, decorators: string[] = []): MethodInfo {
|
||||||
const nameNode = node.childForFieldName(FieldName.NAME)
|
const nameNode = node.childForFieldName(FieldName.NAME)
|
||||||
const params = this.extractParameters(node)
|
const params = this.extractParameters(node)
|
||||||
const isAsync = node.children.some((c) => c.type === NodeType.ASYNC)
|
const isAsync = node.children.some((c) => c.type === NodeType.ASYNC)
|
||||||
@@ -475,6 +511,7 @@ export class ASTParser {
|
|||||||
isAsync,
|
isAsync,
|
||||||
visibility,
|
visibility,
|
||||||
isStatic,
|
isStatic,
|
||||||
|
decorators,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -565,6 +602,75 @@ export class ASTParser {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extractEnum(node: SyntaxNode, ast: FileAST, isExported: boolean): void {
|
||||||
|
const nameNode = node.childForFieldName(FieldName.NAME)
|
||||||
|
if (!nameNode) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = node.childForFieldName(FieldName.BODY)
|
||||||
|
const members: EnumMemberInfo[] = []
|
||||||
|
|
||||||
|
if (body) {
|
||||||
|
for (const child of body.children) {
|
||||||
|
if (child.type === NodeType.ENUM_ASSIGNMENT) {
|
||||||
|
const memberName = child.childForFieldName(FieldName.NAME)
|
||||||
|
const memberValue = child.childForFieldName(FieldName.VALUE)
|
||||||
|
if (memberName) {
|
||||||
|
members.push({
|
||||||
|
name: memberName.text,
|
||||||
|
value: this.parseEnumValue(memberValue),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
child.type === NodeType.IDENTIFIER ||
|
||||||
|
child.type === NodeType.PROPERTY_IDENTIFIER
|
||||||
|
) {
|
||||||
|
members.push({
|
||||||
|
name: child.text,
|
||||||
|
value: undefined,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const isConst = node.children.some((c) => c.text === "const")
|
||||||
|
|
||||||
|
ast.enums.push({
|
||||||
|
name: nameNode.text,
|
||||||
|
lineStart: node.startPosition.row + 1,
|
||||||
|
lineEnd: node.endPosition.row + 1,
|
||||||
|
members,
|
||||||
|
isExported,
|
||||||
|
isConst,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
private parseEnumValue(valueNode: SyntaxNode | null): string | number | undefined {
|
||||||
|
if (!valueNode) {
|
||||||
|
return undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = valueNode.text
|
||||||
|
|
||||||
|
if (valueNode.type === "number") {
|
||||||
|
return Number(text)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valueNode.type === "string") {
|
||||||
|
return this.getStringValue(valueNode)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (valueNode.type === "unary_expression" && text.startsWith("-")) {
|
||||||
|
const num = Number(text)
|
||||||
|
if (!isNaN(num)) {
|
||||||
|
return num
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return text
|
||||||
|
}
|
||||||
|
|
||||||
private extractParameters(node: SyntaxNode): ParameterInfo[] {
|
private extractParameters(node: SyntaxNode): ParameterInfo[] {
|
||||||
const params: ParameterInfo[] = []
|
const params: ParameterInfo[] = []
|
||||||
const paramsNode = node.childForFieldName(FieldName.PARAMETERS)
|
const paramsNode = node.childForFieldName(FieldName.PARAMETERS)
|
||||||
@@ -613,6 +719,49 @@ export class ASTParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a decorator node to a string like "@Get(':id')" or "@Injectable()".
|
||||||
|
*/
|
||||||
|
private formatDecorator(node: SyntaxNode): string {
|
||||||
|
return node.text.replace(/\s+/g, " ").trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract decorators that are direct children of a node.
|
||||||
|
* In tree-sitter, decorators are children of the class/function declaration.
|
||||||
|
*/
|
||||||
|
private extractNodeDecorators(node: SyntaxNode): string[] {
|
||||||
|
const decorators: string[] = []
|
||||||
|
for (const child of node.children) {
|
||||||
|
if (child.type === NodeType.DECORATOR) {
|
||||||
|
decorators.push(this.formatDecorator(child))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return decorators
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract decorators from sibling nodes before the current node.
|
||||||
|
* Decorators appear as children before the declaration in export statements.
|
||||||
|
*/
|
||||||
|
private extractDecoratorsFromSiblings(node: SyntaxNode): string[] {
|
||||||
|
const decorators: string[] = []
|
||||||
|
const parent = node.parent
|
||||||
|
if (!parent) {
|
||||||
|
return decorators
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const sibling of parent.children) {
|
||||||
|
if (sibling.type === NodeType.DECORATOR) {
|
||||||
|
decorators.push(this.formatDecorator(sibling))
|
||||||
|
} else if (sibling === node) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return decorators
|
||||||
|
}
|
||||||
|
|
||||||
private classifyImport(from: string): ImportInfo["type"] {
|
private classifyImport(from: string): ImportInfo["type"] {
|
||||||
if (from.startsWith(".") || from.startsWith("/")) {
|
if (from.startsWith(".") || from.startsWith("/")) {
|
||||||
return "internal"
|
return "internal"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import * as path from "node:path"
|
import * as path from "node:path"
|
||||||
import {
|
import {
|
||||||
|
calculateImpactScore,
|
||||||
type ComplexityMetrics,
|
type ComplexityMetrics,
|
||||||
createFileMeta,
|
createFileMeta,
|
||||||
type FileMeta,
|
type FileMeta,
|
||||||
@@ -430,6 +431,7 @@ export class MetaAnalyzer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Batch analyze multiple files.
|
* Batch analyze multiple files.
|
||||||
|
* Computes impact scores after all files are analyzed.
|
||||||
*/
|
*/
|
||||||
analyzeAll(files: Map<string, { ast: FileAST; content: string }>): Map<string, FileMeta> {
|
analyzeAll(files: Map<string, { ast: FileAST; content: string }>): Map<string, FileMeta> {
|
||||||
const allASTs = new Map<string, FileAST>()
|
const allASTs = new Map<string, FileAST>()
|
||||||
@@ -443,6 +445,12 @@ export class MetaAnalyzer {
|
|||||||
results.set(filePath, meta)
|
results.set(filePath, meta)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compute impact scores now that we know total file count
|
||||||
|
const totalFiles = results.size
|
||||||
|
for (const [, meta] of results) {
|
||||||
|
meta.impactScore = calculateImpactScore(meta.dependents.length, totalFiles)
|
||||||
|
}
|
||||||
|
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export const NodeType = {
|
|||||||
CLASS_DECLARATION: "class_declaration",
|
CLASS_DECLARATION: "class_declaration",
|
||||||
INTERFACE_DECLARATION: "interface_declaration",
|
INTERFACE_DECLARATION: "interface_declaration",
|
||||||
TYPE_ALIAS_DECLARATION: "type_alias_declaration",
|
TYPE_ALIAS_DECLARATION: "type_alias_declaration",
|
||||||
|
ENUM_DECLARATION: "enum_declaration",
|
||||||
|
|
||||||
// Clauses
|
// Clauses
|
||||||
IMPORT_CLAUSE: "import_clause",
|
IMPORT_CLAUSE: "import_clause",
|
||||||
@@ -37,6 +38,11 @@ export const NodeType = {
|
|||||||
FIELD_DEFINITION: "field_definition",
|
FIELD_DEFINITION: "field_definition",
|
||||||
PROPERTY_SIGNATURE: "property_signature",
|
PROPERTY_SIGNATURE: "property_signature",
|
||||||
|
|
||||||
|
// Enum members
|
||||||
|
ENUM_BODY: "enum_body",
|
||||||
|
ENUM_ASSIGNMENT: "enum_assignment",
|
||||||
|
PROPERTY_IDENTIFIER: "property_identifier",
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
REQUIRED_PARAMETER: "required_parameter",
|
REQUIRED_PARAMETER: "required_parameter",
|
||||||
OPTIONAL_PARAMETER: "optional_parameter",
|
OPTIONAL_PARAMETER: "optional_parameter",
|
||||||
@@ -57,6 +63,9 @@ export const NodeType = {
|
|||||||
DEFAULT: "default",
|
DEFAULT: "default",
|
||||||
ACCESSIBILITY_MODIFIER: "accessibility_modifier",
|
ACCESSIBILITY_MODIFIER: "accessibility_modifier",
|
||||||
READONLY: "readonly",
|
READONLY: "readonly",
|
||||||
|
|
||||||
|
// Decorators
|
||||||
|
DECORATOR: "decorator",
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export type NodeTypeValue = (typeof NodeType)[keyof typeof NodeType]
|
export type NodeTypeValue = (typeof NodeType)[keyof typeof NodeType]
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ export interface ProjectStructure {
|
|||||||
*/
|
*/
|
||||||
export interface BuildContextOptions {
|
export interface BuildContextOptions {
|
||||||
includeSignatures?: boolean
|
includeSignatures?: boolean
|
||||||
|
includeDepsGraph?: boolean
|
||||||
|
includeCircularDeps?: boolean
|
||||||
|
includeHighImpactFiles?: boolean
|
||||||
|
circularDeps?: string[][]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,11 +131,35 @@ export function buildInitialContext(
|
|||||||
): string {
|
): string {
|
||||||
const sections: string[] = []
|
const sections: string[] = []
|
||||||
const includeSignatures = options?.includeSignatures ?? true
|
const includeSignatures = options?.includeSignatures ?? true
|
||||||
|
const includeDepsGraph = options?.includeDepsGraph ?? true
|
||||||
|
const includeCircularDeps = options?.includeCircularDeps ?? true
|
||||||
|
const includeHighImpactFiles = options?.includeHighImpactFiles ?? true
|
||||||
|
|
||||||
sections.push(formatProjectHeader(structure))
|
sections.push(formatProjectHeader(structure))
|
||||||
sections.push(formatDirectoryTree(structure))
|
sections.push(formatDirectoryTree(structure))
|
||||||
sections.push(formatFileOverview(asts, metas, includeSignatures))
|
sections.push(formatFileOverview(asts, metas, includeSignatures))
|
||||||
|
|
||||||
|
if (includeDepsGraph && metas && metas.size > 0) {
|
||||||
|
const depsGraph = formatDependencyGraph(metas)
|
||||||
|
if (depsGraph) {
|
||||||
|
sections.push(depsGraph)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeHighImpactFiles && metas && metas.size > 0) {
|
||||||
|
const highImpactSection = formatHighImpactFiles(metas)
|
||||||
|
if (highImpactSection) {
|
||||||
|
sections.push(highImpactSection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeCircularDeps && options?.circularDeps && options.circularDeps.length > 0) {
|
||||||
|
const circularDepsSection = formatCircularDeps(options.circularDeps)
|
||||||
|
if (circularDepsSection) {
|
||||||
|
sections.push(circularDepsSection)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sections.join("\n\n")
|
return sections.join("\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,10 +215,22 @@ function formatFileOverview(
|
|||||||
return lines.join("\n")
|
return lines.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format decorators as a prefix string.
|
||||||
|
* Example: "@Get(':id') @Auth() "
|
||||||
|
*/
|
||||||
|
function formatDecoratorsPrefix(decorators: string[] | undefined): string {
|
||||||
|
if (!decorators || decorators.length === 0) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return `${decorators.join(" ")} `
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a function signature.
|
* Format a function signature.
|
||||||
*/
|
*/
|
||||||
function formatFunctionSignature(fn: FileAST["functions"][0]): string {
|
function formatFunctionSignature(fn: FileAST["functions"][0]): string {
|
||||||
|
const decoratorsPrefix = formatDecoratorsPrefix(fn.decorators)
|
||||||
const asyncPrefix = fn.isAsync ? "async " : ""
|
const asyncPrefix = fn.isAsync ? "async " : ""
|
||||||
const params = fn.params
|
const params = fn.params
|
||||||
.map((p) => {
|
.map((p) => {
|
||||||
@@ -200,7 +240,7 @@ function formatFunctionSignature(fn: FileAST["functions"][0]): string {
|
|||||||
})
|
})
|
||||||
.join(", ")
|
.join(", ")
|
||||||
const returnType = fn.returnType ? `: ${fn.returnType}` : ""
|
const returnType = fn.returnType ? `: ${fn.returnType}` : ""
|
||||||
return `${asyncPrefix}${fn.name}(${params})${returnType}`
|
return `${decoratorsPrefix}${asyncPrefix}${fn.name}(${params})${returnType}`
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -240,6 +280,37 @@ function formatTypeAliasSignature(type: FileAST["typeAliases"][0]): string {
|
|||||||
return `type ${type.name} = ${definition}`
|
return `type ${type.name} = ${definition}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format an enum signature with members and values.
|
||||||
|
* Example: "enum Status { Active=1, Inactive=0, Pending=2 }"
|
||||||
|
* Example: "const enum Role { Admin="admin", User="user" }"
|
||||||
|
*/
|
||||||
|
function formatEnumSignature(enumInfo: FileAST["enums"][0]): string {
|
||||||
|
const constPrefix = enumInfo.isConst ? "const " : ""
|
||||||
|
|
||||||
|
if (enumInfo.members.length === 0) {
|
||||||
|
return `${constPrefix}enum ${enumInfo.name}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const membersStr = enumInfo.members
|
||||||
|
.map((m) => {
|
||||||
|
if (m.value === undefined) {
|
||||||
|
return m.name
|
||||||
|
}
|
||||||
|
const valueStr = typeof m.value === "string" ? `"${m.value}"` : String(m.value)
|
||||||
|
return `${m.name}=${valueStr}`
|
||||||
|
})
|
||||||
|
.join(", ")
|
||||||
|
|
||||||
|
const result = `${constPrefix}enum ${enumInfo.name} { ${membersStr} }`
|
||||||
|
|
||||||
|
if (result.length > 100) {
|
||||||
|
return truncateDefinition(result, 100)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Truncate long type definitions for display.
|
* Truncate long type definitions for display.
|
||||||
*/
|
*/
|
||||||
@@ -279,9 +350,10 @@ function formatFileSummary(
|
|||||||
|
|
||||||
if (ast.classes.length > 0) {
|
if (ast.classes.length > 0) {
|
||||||
for (const cls of ast.classes) {
|
for (const cls of ast.classes) {
|
||||||
|
const decoratorsPrefix = formatDecoratorsPrefix(cls.decorators)
|
||||||
const ext = cls.extends ? ` extends ${cls.extends}` : ""
|
const ext = cls.extends ? ` extends ${cls.extends}` : ""
|
||||||
const impl = cls.implements.length > 0 ? ` implements ${cls.implements.join(", ")}` : ""
|
const impl = cls.implements.length > 0 ? ` implements ${cls.implements.join(", ")}` : ""
|
||||||
lines.push(`- class ${cls.name}${ext}${impl}`)
|
lines.push(`- ${decoratorsPrefix}class ${cls.name}${ext}${impl}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -297,6 +369,12 @@ function formatFileSummary(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ast.enums && ast.enums.length > 0) {
|
||||||
|
for (const enumInfo of ast.enums) {
|
||||||
|
lines.push(`- ${formatEnumSignature(enumInfo)}`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (lines.length === 1) {
|
if (lines.length === 1) {
|
||||||
return `- ${path}${flags}`
|
return `- ${path}${flags}`
|
||||||
}
|
}
|
||||||
@@ -330,6 +408,11 @@ function formatFileSummaryCompact(path: string, ast: FileAST, flags: string): st
|
|||||||
parts.push(`type: ${names}`)
|
parts.push(`type: ${names}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ast.enums && ast.enums.length > 0) {
|
||||||
|
const names = ast.enums.map((e) => e.name).join(", ")
|
||||||
|
parts.push(`enum: ${names}`)
|
||||||
|
}
|
||||||
|
|
||||||
const summary = parts.length > 0 ? ` [${parts.join(" | ")}]` : ""
|
const summary = parts.length > 0 ? ` [${parts.join(" | ")}]` : ""
|
||||||
return `- ${path}${summary}${flags}`
|
return `- ${path}${summary}${flags}`
|
||||||
}
|
}
|
||||||
@@ -359,6 +442,209 @@ function formatFileFlags(meta?: FileMeta): string {
|
|||||||
return flags.length > 0 ? ` (${flags.join(", ")})` : ""
|
return flags.length > 0 ? ` (${flags.join(", ")})` : ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shorten a file path for display in dependency graph.
|
||||||
|
* Removes common prefixes like "src/" and file extensions.
|
||||||
|
*/
|
||||||
|
function shortenPath(path: string): string {
|
||||||
|
let short = path
|
||||||
|
if (short.startsWith("src/")) {
|
||||||
|
short = short.slice(4)
|
||||||
|
}
|
||||||
|
// Remove common extensions
|
||||||
|
short = short.replace(/\.(ts|tsx|js|jsx)$/, "")
|
||||||
|
// Remove /index suffix
|
||||||
|
short = short.replace(/\/index$/, "")
|
||||||
|
return short
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a single dependency graph entry.
|
||||||
|
* Format: "path: → dep1, dep2 ← dependent1, dependent2"
|
||||||
|
*/
|
||||||
|
function formatDepsEntry(path: string, dependencies: string[], dependents: string[]): string {
|
||||||
|
const parts: string[] = []
|
||||||
|
const shortPath = shortenPath(path)
|
||||||
|
|
||||||
|
if (dependencies.length > 0) {
|
||||||
|
const deps = dependencies.map(shortenPath).join(", ")
|
||||||
|
parts.push(`→ ${deps}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dependents.length > 0) {
|
||||||
|
const deps = dependents.map(shortenPath).join(", ")
|
||||||
|
parts.push(`← ${deps}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts.length === 0) {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return `${shortPath}: ${parts.join(" ")}`
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format dependency graph for all files.
|
||||||
|
* Shows hub files first, then files with dependencies/dependents.
|
||||||
|
*
|
||||||
|
* Format:
|
||||||
|
* ## Dependency Graph
|
||||||
|
* services/user: → types/user, utils/validation ← controllers/user
|
||||||
|
* services/auth: → services/user, utils/jwt ← controllers/auth
|
||||||
|
*/
|
||||||
|
export function formatDependencyGraph(metas: Map<string, FileMeta>): string | null {
|
||||||
|
if (metas.size === 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const entries: { path: string; deps: string[]; dependents: string[]; isHub: boolean }[] = []
|
||||||
|
|
||||||
|
for (const [path, meta] of metas) {
|
||||||
|
// Only include files that have connections
|
||||||
|
if (meta.dependencies.length > 0 || meta.dependents.length > 0) {
|
||||||
|
entries.push({
|
||||||
|
path,
|
||||||
|
deps: meta.dependencies,
|
||||||
|
dependents: meta.dependents,
|
||||||
|
isHub: meta.isHub,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entries.length === 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort: hubs first, then by total connections (desc), then by path
|
||||||
|
entries.sort((a, b) => {
|
||||||
|
if (a.isHub !== b.isHub) {
|
||||||
|
return a.isHub ? -1 : 1
|
||||||
|
}
|
||||||
|
const aTotal = a.deps.length + a.dependents.length
|
||||||
|
const bTotal = b.deps.length + b.dependents.length
|
||||||
|
if (aTotal !== bTotal) {
|
||||||
|
return bTotal - aTotal
|
||||||
|
}
|
||||||
|
return a.path.localeCompare(b.path)
|
||||||
|
})
|
||||||
|
|
||||||
|
const lines: string[] = ["## Dependency Graph", ""]
|
||||||
|
|
||||||
|
for (const entry of entries) {
|
||||||
|
const line = formatDepsEntry(entry.path, entry.deps, entry.dependents)
|
||||||
|
if (line) {
|
||||||
|
lines.push(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return null if only header (no actual entries)
|
||||||
|
if (lines.length <= 2) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format circular dependencies for display in context.
|
||||||
|
* Shows warning section with cycle chains.
|
||||||
|
*
|
||||||
|
* Format:
|
||||||
|
* ## ⚠️ Circular Dependencies
|
||||||
|
* - services/user → services/auth → services/user
|
||||||
|
* - utils/a → utils/b → utils/c → utils/a
|
||||||
|
*/
|
||||||
|
export function formatCircularDeps(cycles: string[][]): string | null {
|
||||||
|
if (!cycles || cycles.length === 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
const lines: string[] = ["## ⚠️ Circular Dependencies", ""]
|
||||||
|
|
||||||
|
for (const cycle of cycles) {
|
||||||
|
if (cycle.length === 0) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const formattedCycle = cycle.map(shortenPath).join(" → ")
|
||||||
|
lines.push(`- ${formattedCycle}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return null if only header (no actual cycles)
|
||||||
|
if (lines.length <= 2) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format high impact files table for display in context.
|
||||||
|
* Shows files with highest impact scores (most dependents).
|
||||||
|
*
|
||||||
|
* Format:
|
||||||
|
* ## High Impact Files
|
||||||
|
* | File | Impact | Dependents |
|
||||||
|
* |------|--------|------------|
|
||||||
|
* | src/utils/validation.ts | 67% | 12 files |
|
||||||
|
*
|
||||||
|
* @param metas - Map of file paths to their metadata
|
||||||
|
* @param limit - Maximum number of files to show (default: 10)
|
||||||
|
* @param minImpact - Minimum impact score to include (default: 5)
|
||||||
|
*/
|
||||||
|
export function formatHighImpactFiles(
|
||||||
|
metas: Map<string, FileMeta>,
|
||||||
|
limit = 10,
|
||||||
|
minImpact = 5,
|
||||||
|
): string | null {
|
||||||
|
if (metas.size === 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect files with impact score >= minImpact
|
||||||
|
const impactFiles: { path: string; impact: number; dependents: number }[] = []
|
||||||
|
|
||||||
|
for (const [path, meta] of metas) {
|
||||||
|
if (meta.impactScore >= minImpact) {
|
||||||
|
impactFiles.push({
|
||||||
|
path,
|
||||||
|
impact: meta.impactScore,
|
||||||
|
dependents: meta.dependents.length,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (impactFiles.length === 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort by impact score descending, then by path
|
||||||
|
impactFiles.sort((a, b) => {
|
||||||
|
if (a.impact !== b.impact) {
|
||||||
|
return b.impact - a.impact
|
||||||
|
}
|
||||||
|
return a.path.localeCompare(b.path)
|
||||||
|
})
|
||||||
|
|
||||||
|
// Take top N files
|
||||||
|
const topFiles = impactFiles.slice(0, limit)
|
||||||
|
|
||||||
|
const lines: string[] = [
|
||||||
|
"## High Impact Files",
|
||||||
|
"",
|
||||||
|
"| File | Impact | Dependents |",
|
||||||
|
"|------|--------|------------|",
|
||||||
|
]
|
||||||
|
|
||||||
|
for (const file of topFiles) {
|
||||||
|
const shortPath = shortenPath(file.path)
|
||||||
|
const impact = `${String(file.impact)}%`
|
||||||
|
const dependents = file.dependents === 1 ? "1 file" : `${String(file.dependents)} files`
|
||||||
|
lines.push(`| ${shortPath} | ${impact} | ${dependents} |`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return lines.join("\n")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format line range for display.
|
* Format line range for display.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ export const ContextConfigSchema = z.object({
|
|||||||
autoCompressAt: z.number().min(0).max(1).default(0.8),
|
autoCompressAt: z.number().min(0).max(1).default(0.8),
|
||||||
compressionMethod: z.enum(["llm-summary", "truncate"]).default("llm-summary"),
|
compressionMethod: z.enum(["llm-summary", "truncate"]).default("llm-summary"),
|
||||||
includeSignatures: z.boolean().default(true),
|
includeSignatures: z.boolean().default(true),
|
||||||
|
includeDepsGraph: z.boolean().default(true),
|
||||||
|
includeCircularDeps: z.boolean().default(true),
|
||||||
|
includeHighImpactFiles: z.boolean().default(true),
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { describe, it, expect } from "vitest"
|
import { describe, it, expect } from "vitest"
|
||||||
import { createFileMeta, isHubFile } from "../../../../src/domain/value-objects/FileMeta.js"
|
import {
|
||||||
|
calculateImpactScore,
|
||||||
|
createFileMeta,
|
||||||
|
isHubFile,
|
||||||
|
} from "../../../../src/domain/value-objects/FileMeta.js"
|
||||||
|
|
||||||
describe("FileMeta", () => {
|
describe("FileMeta", () => {
|
||||||
describe("createFileMeta", () => {
|
describe("createFileMeta", () => {
|
||||||
@@ -15,6 +19,7 @@ describe("FileMeta", () => {
|
|||||||
expect(meta.isHub).toBe(false)
|
expect(meta.isHub).toBe(false)
|
||||||
expect(meta.isEntryPoint).toBe(false)
|
expect(meta.isEntryPoint).toBe(false)
|
||||||
expect(meta.fileType).toBe("unknown")
|
expect(meta.fileType).toBe("unknown")
|
||||||
|
expect(meta.impactScore).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should merge partial values", () => {
|
it("should merge partial values", () => {
|
||||||
@@ -42,4 +47,51 @@ describe("FileMeta", () => {
|
|||||||
expect(isHubFile(0)).toBe(false)
|
expect(isHubFile(0)).toBe(false)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("calculateImpactScore", () => {
|
||||||
|
it("should return 0 for file with 0 dependents", () => {
|
||||||
|
expect(calculateImpactScore(0, 10)).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return 0 when totalFiles is 0", () => {
|
||||||
|
expect(calculateImpactScore(5, 0)).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return 0 when totalFiles is 1", () => {
|
||||||
|
expect(calculateImpactScore(0, 1)).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should calculate correct percentage", () => {
|
||||||
|
// 5 dependents out of 10 files (excluding itself = 9 possible)
|
||||||
|
// 5/9 * 100 = 55.56 → rounded to 56
|
||||||
|
expect(calculateImpactScore(5, 10)).toBe(56)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return 100 when all other files depend on it", () => {
|
||||||
|
// 9 dependents out of 10 files (9 possible dependents)
|
||||||
|
expect(calculateImpactScore(9, 10)).toBe(100)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should cap at 100", () => {
|
||||||
|
// Edge case: more dependents than possible (shouldn't happen normally)
|
||||||
|
expect(calculateImpactScore(20, 10)).toBe(100)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should round the percentage", () => {
|
||||||
|
// 1 dependent out of 3 files (2 possible)
|
||||||
|
// 1/2 * 100 = 50
|
||||||
|
expect(calculateImpactScore(1, 3)).toBe(50)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should calculate impact for small projects", () => {
|
||||||
|
// 1 dependent out of 2 files (1 possible)
|
||||||
|
expect(calculateImpactScore(1, 2)).toBe(100)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should calculate impact for larger projects", () => {
|
||||||
|
// 50 dependents out of 100 files (99 possible)
|
||||||
|
// 50/99 * 100 = 50.51 → rounded to 51
|
||||||
|
expect(calculateImpactScore(50, 100)).toBe(51)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -562,4 +562,274 @@ third: value3`
|
|||||||
expect(ast.exports[2].line).toBe(3)
|
expect(ast.exports[2].line).toBe(3)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("enums (0.24.3)", () => {
|
||||||
|
it("should extract enum with numeric values", () => {
|
||||||
|
const code = `enum Status {
|
||||||
|
Active = 1,
|
||||||
|
Inactive = 0,
|
||||||
|
Pending = 2
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(1)
|
||||||
|
expect(ast.enums[0]).toMatchObject({
|
||||||
|
name: "Status",
|
||||||
|
isExported: false,
|
||||||
|
isConst: false,
|
||||||
|
})
|
||||||
|
expect(ast.enums[0].members).toHaveLength(3)
|
||||||
|
expect(ast.enums[0].members[0]).toMatchObject({ name: "Active", value: 1 })
|
||||||
|
expect(ast.enums[0].members[1]).toMatchObject({ name: "Inactive", value: 0 })
|
||||||
|
expect(ast.enums[0].members[2]).toMatchObject({ name: "Pending", value: 2 })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract enum with string values", () => {
|
||||||
|
const code = `enum Role {
|
||||||
|
Admin = "admin",
|
||||||
|
User = "user",
|
||||||
|
Guest = "guest"
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(1)
|
||||||
|
expect(ast.enums[0].members).toHaveLength(3)
|
||||||
|
expect(ast.enums[0].members[0]).toMatchObject({ name: "Admin", value: "admin" })
|
||||||
|
expect(ast.enums[0].members[1]).toMatchObject({ name: "User", value: "user" })
|
||||||
|
expect(ast.enums[0].members[2]).toMatchObject({ name: "Guest", value: "guest" })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract enum without explicit values", () => {
|
||||||
|
const code = `enum Direction {
|
||||||
|
Up,
|
||||||
|
Down,
|
||||||
|
Left,
|
||||||
|
Right
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(1)
|
||||||
|
expect(ast.enums[0].members).toHaveLength(4)
|
||||||
|
expect(ast.enums[0].members[0]).toMatchObject({ name: "Up", value: undefined })
|
||||||
|
expect(ast.enums[0].members[1]).toMatchObject({ name: "Down", value: undefined })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract exported enum", () => {
|
||||||
|
const code = `export enum Color {
|
||||||
|
Red = "#FF0000",
|
||||||
|
Green = "#00FF00",
|
||||||
|
Blue = "#0000FF"
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(1)
|
||||||
|
expect(ast.enums[0].isExported).toBe(true)
|
||||||
|
expect(ast.exports).toHaveLength(1)
|
||||||
|
expect(ast.exports[0].kind).toBe("type")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract const enum", () => {
|
||||||
|
const code = `const enum HttpStatus {
|
||||||
|
OK = 200,
|
||||||
|
NotFound = 404,
|
||||||
|
InternalError = 500
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(1)
|
||||||
|
expect(ast.enums[0].isConst).toBe(true)
|
||||||
|
expect(ast.enums[0].members[0]).toMatchObject({ name: "OK", value: 200 })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract exported const enum", () => {
|
||||||
|
const code = `export const enum LogLevel {
|
||||||
|
Debug = 0,
|
||||||
|
Info = 1,
|
||||||
|
Warn = 2,
|
||||||
|
Error = 3
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(1)
|
||||||
|
expect(ast.enums[0].isExported).toBe(true)
|
||||||
|
expect(ast.enums[0].isConst).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract line range for enum", () => {
|
||||||
|
const code = `enum Test {
|
||||||
|
A = 1,
|
||||||
|
B = 2
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums[0].lineStart).toBe(1)
|
||||||
|
expect(ast.enums[0].lineEnd).toBe(4)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle enum with negative values", () => {
|
||||||
|
const code = `enum Temperature {
|
||||||
|
Cold = -10,
|
||||||
|
Freezing = -20,
|
||||||
|
Hot = 40
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(1)
|
||||||
|
expect(ast.enums[0].members[0]).toMatchObject({ name: "Cold", value: -10 })
|
||||||
|
expect(ast.enums[0].members[1]).toMatchObject({ name: "Freezing", value: -20 })
|
||||||
|
expect(ast.enums[0].members[2]).toMatchObject({ name: "Hot", value: 40 })
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle empty enum", () => {
|
||||||
|
const code = `enum Empty {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(1)
|
||||||
|
expect(ast.enums[0].name).toBe("Empty")
|
||||||
|
expect(ast.enums[0].members).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not extract enum from JavaScript", () => {
|
||||||
|
const code = `enum Status { Active = 1 }`
|
||||||
|
const ast = parser.parse(code, "js")
|
||||||
|
|
||||||
|
expect(ast.enums).toHaveLength(0)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("decorators (0.24.4)", () => {
|
||||||
|
it("should extract class decorator", () => {
|
||||||
|
const code = `@Controller('users')
|
||||||
|
class UserController {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators[0]).toBe("@Controller('users')")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract multiple class decorators", () => {
|
||||||
|
const code = `@Controller('api')
|
||||||
|
@Injectable()
|
||||||
|
@UseGuards(AuthGuard)
|
||||||
|
class ApiController {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators).toHaveLength(3)
|
||||||
|
expect(ast.classes[0].decorators[0]).toBe("@Controller('api')")
|
||||||
|
expect(ast.classes[0].decorators[1]).toBe("@Injectable()")
|
||||||
|
expect(ast.classes[0].decorators[2]).toBe("@UseGuards(AuthGuard)")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract method decorators", () => {
|
||||||
|
const code = `class UserController {
|
||||||
|
@Get(':id')
|
||||||
|
@Auth()
|
||||||
|
async getUser() {}
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].methods).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].methods[0].decorators).toHaveLength(2)
|
||||||
|
expect(ast.classes[0].methods[0].decorators[0]).toBe("@Get(':id')")
|
||||||
|
expect(ast.classes[0].methods[0].decorators[1]).toBe("@Auth()")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract exported decorated class", () => {
|
||||||
|
const code = `@Injectable()
|
||||||
|
export class UserService {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].isExported).toBe(true)
|
||||||
|
expect(ast.classes[0].decorators).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators[0]).toBe("@Injectable()")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract decorator with complex arguments", () => {
|
||||||
|
const code = `@Module({
|
||||||
|
imports: [UserModule],
|
||||||
|
controllers: [AppController],
|
||||||
|
providers: [AppService]
|
||||||
|
})
|
||||||
|
class AppModule {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators[0]).toContain("@Module")
|
||||||
|
expect(ast.classes[0].decorators[0]).toContain("imports")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract decorated class with extends", () => {
|
||||||
|
const code = `@Entity()
|
||||||
|
class User extends BaseEntity {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].extends).toBe("BaseEntity")
|
||||||
|
expect(ast.classes[0].decorators).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators![0]).toBe("@Entity()")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle class without decorators", () => {
|
||||||
|
const code = `class SimpleClass {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle method without decorators", () => {
|
||||||
|
const code = `class SimpleClass {
|
||||||
|
simpleMethod() {}
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].methods).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].methods[0].decorators).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle function without decorators", () => {
|
||||||
|
const code = `function simpleFunc() {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.functions).toHaveLength(1)
|
||||||
|
expect(ast.functions[0].decorators).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle arrow function without decorators", () => {
|
||||||
|
const code = `const arrowFn = () => {}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.functions).toHaveLength(1)
|
||||||
|
expect(ast.functions[0].decorators).toHaveLength(0)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should extract NestJS controller pattern", () => {
|
||||||
|
const code = `@Controller('users')
|
||||||
|
export class UserController {
|
||||||
|
@Get()
|
||||||
|
findAll() {}
|
||||||
|
|
||||||
|
@Get(':id')
|
||||||
|
findOne() {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
@Body()
|
||||||
|
create() {}
|
||||||
|
}`
|
||||||
|
const ast = parser.parse(code, "ts")
|
||||||
|
|
||||||
|
expect(ast.classes).toHaveLength(1)
|
||||||
|
expect(ast.classes[0].decorators).toContain("@Controller('users')")
|
||||||
|
expect(ast.classes[0].methods).toHaveLength(3)
|
||||||
|
expect(ast.classes[0].methods[0].decorators).toContain("@Get()")
|
||||||
|
expect(ast.classes[0].methods[1].decorators).toContain("@Get(':id')")
|
||||||
|
expect(ast.classes[0].methods[2].decorators).toContain("@Post()")
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -16,6 +16,9 @@ describe("ContextConfigSchema", () => {
|
|||||||
autoCompressAt: 0.8,
|
autoCompressAt: 0.8,
|
||||||
compressionMethod: "llm-summary",
|
compressionMethod: "llm-summary",
|
||||||
includeSignatures: true,
|
includeSignatures: true,
|
||||||
|
includeDepsGraph: true,
|
||||||
|
includeCircularDeps: true,
|
||||||
|
includeHighImpactFiles: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -28,6 +31,9 @@ describe("ContextConfigSchema", () => {
|
|||||||
autoCompressAt: 0.8,
|
autoCompressAt: 0.8,
|
||||||
compressionMethod: "llm-summary",
|
compressionMethod: "llm-summary",
|
||||||
includeSignatures: true,
|
includeSignatures: true,
|
||||||
|
includeDepsGraph: true,
|
||||||
|
includeCircularDeps: true,
|
||||||
|
includeHighImpactFiles: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -165,6 +171,9 @@ describe("ContextConfigSchema", () => {
|
|||||||
autoCompressAt: 0.8,
|
autoCompressAt: 0.8,
|
||||||
compressionMethod: "llm-summary",
|
compressionMethod: "llm-summary",
|
||||||
includeSignatures: true,
|
includeSignatures: true,
|
||||||
|
includeDepsGraph: true,
|
||||||
|
includeCircularDeps: true,
|
||||||
|
includeHighImpactFiles: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -179,6 +188,9 @@ describe("ContextConfigSchema", () => {
|
|||||||
autoCompressAt: 0.9,
|
autoCompressAt: 0.9,
|
||||||
compressionMethod: "llm-summary",
|
compressionMethod: "llm-summary",
|
||||||
includeSignatures: true,
|
includeSignatures: true,
|
||||||
|
includeDepsGraph: true,
|
||||||
|
includeCircularDeps: true,
|
||||||
|
includeHighImpactFiles: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -194,6 +206,9 @@ describe("ContextConfigSchema", () => {
|
|||||||
autoCompressAt: 0.8,
|
autoCompressAt: 0.8,
|
||||||
compressionMethod: "truncate",
|
compressionMethod: "truncate",
|
||||||
includeSignatures: true,
|
includeSignatures: true,
|
||||||
|
includeDepsGraph: true,
|
||||||
|
includeCircularDeps: true,
|
||||||
|
includeHighImpactFiles: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -206,6 +221,9 @@ describe("ContextConfigSchema", () => {
|
|||||||
autoCompressAt: 0.85,
|
autoCompressAt: 0.85,
|
||||||
compressionMethod: "truncate" as const,
|
compressionMethod: "truncate" as const,
|
||||||
includeSignatures: false,
|
includeSignatures: false,
|
||||||
|
includeDepsGraph: false,
|
||||||
|
includeCircularDeps: false,
|
||||||
|
includeHighImpactFiles: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = ContextConfigSchema.parse(config)
|
const result = ContextConfigSchema.parse(config)
|
||||||
@@ -219,6 +237,9 @@ describe("ContextConfigSchema", () => {
|
|||||||
autoCompressAt: 0.8,
|
autoCompressAt: 0.8,
|
||||||
compressionMethod: "llm-summary" as const,
|
compressionMethod: "llm-summary" as const,
|
||||||
includeSignatures: true,
|
includeSignatures: true,
|
||||||
|
includeDepsGraph: true,
|
||||||
|
includeCircularDeps: true,
|
||||||
|
includeHighImpactFiles: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = ContextConfigSchema.parse(config)
|
const result = ContextConfigSchema.parse(config)
|
||||||
@@ -250,4 +271,79 @@ describe("ContextConfigSchema", () => {
|
|||||||
expect(() => ContextConfigSchema.parse({ includeSignatures: 1 })).toThrow()
|
expect(() => ContextConfigSchema.parse({ includeSignatures: 1 })).toThrow()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("includeDepsGraph", () => {
|
||||||
|
it("should accept true", () => {
|
||||||
|
const result = ContextConfigSchema.parse({ includeDepsGraph: true })
|
||||||
|
expect(result.includeDepsGraph).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should accept false", () => {
|
||||||
|
const result = ContextConfigSchema.parse({ includeDepsGraph: false })
|
||||||
|
expect(result.includeDepsGraph).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should default to true", () => {
|
||||||
|
const result = ContextConfigSchema.parse({})
|
||||||
|
expect(result.includeDepsGraph).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should reject non-boolean", () => {
|
||||||
|
expect(() => ContextConfigSchema.parse({ includeDepsGraph: "true" })).toThrow()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should reject number", () => {
|
||||||
|
expect(() => ContextConfigSchema.parse({ includeDepsGraph: 1 })).toThrow()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("includeCircularDeps", () => {
|
||||||
|
it("should accept true", () => {
|
||||||
|
const result = ContextConfigSchema.parse({ includeCircularDeps: true })
|
||||||
|
expect(result.includeCircularDeps).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should accept false", () => {
|
||||||
|
const result = ContextConfigSchema.parse({ includeCircularDeps: false })
|
||||||
|
expect(result.includeCircularDeps).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should default to true", () => {
|
||||||
|
const result = ContextConfigSchema.parse({})
|
||||||
|
expect(result.includeCircularDeps).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should reject non-boolean", () => {
|
||||||
|
expect(() => ContextConfigSchema.parse({ includeCircularDeps: "true" })).toThrow()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should reject number", () => {
|
||||||
|
expect(() => ContextConfigSchema.parse({ includeCircularDeps: 1 })).toThrow()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("includeHighImpactFiles", () => {
|
||||||
|
it("should accept true", () => {
|
||||||
|
const result = ContextConfigSchema.parse({ includeHighImpactFiles: true })
|
||||||
|
expect(result.includeHighImpactFiles).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should accept false", () => {
|
||||||
|
const result = ContextConfigSchema.parse({ includeHighImpactFiles: false })
|
||||||
|
expect(result.includeHighImpactFiles).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should default to true", () => {
|
||||||
|
const result = ContextConfigSchema.parse({})
|
||||||
|
expect(result.includeHighImpactFiles).toBe(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should reject non-boolean", () => {
|
||||||
|
expect(() => ContextConfigSchema.parse({ includeHighImpactFiles: "true" })).toThrow()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should reject number", () => {
|
||||||
|
expect(() => ContextConfigSchema.parse({ includeHighImpactFiles: 1 })).toThrow()
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user