feat(ipuaro): add impact score to initial context

Add High Impact Files section to initial context showing which files
are most critical based on percentage of codebase that depends on them.

Changes:
- Add impactScore field to FileMeta (0-100)
- Add calculateImpactScore() helper function
- Update MetaAnalyzer to compute impact scores
- Add formatHighImpactFiles() to prompts.ts
- Add includeHighImpactFiles config option (default: true)
- 28 new tests (1826 total)
This commit is contained in:
imfozilbek
2025-12-05 15:43:24 +05:00
parent d6d15dd271
commit e9aaa708fe
9 changed files with 606 additions and 12 deletions

View File

@@ -1,5 +1,9 @@
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("createFileMeta", () => {
@@ -15,6 +19,7 @@ describe("FileMeta", () => {
expect(meta.isHub).toBe(false)
expect(meta.isEntryPoint).toBe(false)
expect(meta.fileType).toBe("unknown")
expect(meta.impactScore).toBe(0)
})
it("should merge partial values", () => {
@@ -42,4 +47,51 @@ describe("FileMeta", () => {
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)
})
})
})