@aiready/context-analyzer 0.22.6 → 0.22.8
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 +32 -31
- package/.turbo/turbo-format-check.log +7 -0
- package/.turbo/turbo-lint.log +5 -4
- package/.turbo/turbo-test.log +51 -49
- package/.turbo/turbo-type-check.log +5 -0
- package/CONTRIBUTING.md +1 -1
- package/dist/chunk-BTDF2ZA4.mjs +91 -0
- package/dist/chunk-JSM7Q5CY.mjs +143 -0
- package/dist/chunk-ZA7HRDAH.mjs +1304 -0
- package/dist/cli-action-HREY7TK5.mjs +95 -0
- package/dist/cli.js +8 -2
- package/dist/cli.mjs +1 -1
- package/dist/index.js +18 -11
- package/dist/index.mjs +15 -14
- package/dist/orchestrator-62YVSQFV.mjs +10 -0
- package/dist/summary-RSPRRY6S.mjs +7 -0
- package/package.json +5 -3
- package/src/metrics.ts +10 -4
- package/src/scoring.ts +9 -9
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
displayConsoleReport,
|
|
3
|
+
generateHTMLReport,
|
|
4
|
+
runInteractiveSetup
|
|
5
|
+
} from "./chunk-J3SZQZNU.mjs";
|
|
6
|
+
import {
|
|
7
|
+
analyzeContext
|
|
8
|
+
} from "./chunk-ZA7HRDAH.mjs";
|
|
9
|
+
import "./chunk-64U3PNO3.mjs";
|
|
10
|
+
import {
|
|
11
|
+
generateSummary
|
|
12
|
+
} from "./chunk-BTDF2ZA4.mjs";
|
|
13
|
+
import "./chunk-JSM7Q5CY.mjs";
|
|
14
|
+
|
|
15
|
+
// src/cli-action.ts
|
|
16
|
+
import {
|
|
17
|
+
loadMergedConfig,
|
|
18
|
+
handleJSONOutput,
|
|
19
|
+
handleCLIError,
|
|
20
|
+
getElapsedTime,
|
|
21
|
+
resolveOutputPath
|
|
22
|
+
} from "@aiready/core";
|
|
23
|
+
import chalk from "chalk";
|
|
24
|
+
import { writeFileSync } from "fs";
|
|
25
|
+
async function contextActionHandler(directory, options) {
|
|
26
|
+
console.log(chalk.blue("\u{1F50D} Analyzing context window costs...\n"));
|
|
27
|
+
const startTime = Date.now();
|
|
28
|
+
try {
|
|
29
|
+
const defaults = {
|
|
30
|
+
maxDepth: 5,
|
|
31
|
+
maxContextBudget: 1e4,
|
|
32
|
+
minCohesion: 0.6,
|
|
33
|
+
maxFragmentation: 0.5,
|
|
34
|
+
focus: "all",
|
|
35
|
+
includeNodeModules: false,
|
|
36
|
+
include: void 0,
|
|
37
|
+
exclude: void 0,
|
|
38
|
+
maxResults: 10
|
|
39
|
+
};
|
|
40
|
+
let finalOptions = await loadMergedConfig(directory, defaults, {
|
|
41
|
+
maxDepth: options.maxDepth ? parseInt(options.maxDepth) : void 0,
|
|
42
|
+
maxContextBudget: options.maxContext ? parseInt(options.maxContext) : void 0,
|
|
43
|
+
minCohesion: options.minCohesion ? parseFloat(options.minCohesion) : void 0,
|
|
44
|
+
maxFragmentation: options.maxFragmentation ? parseFloat(options.maxFragmentation) : void 0,
|
|
45
|
+
focus: options.focus || void 0,
|
|
46
|
+
includeNodeModules: options.includeNodeModules,
|
|
47
|
+
include: options.include?.split(","),
|
|
48
|
+
exclude: options.exclude?.split(","),
|
|
49
|
+
maxResults: options.maxResults ? parseInt(options.maxResults) : void 0
|
|
50
|
+
});
|
|
51
|
+
if (options.interactive) {
|
|
52
|
+
finalOptions = await runInteractiveSetup(directory, finalOptions);
|
|
53
|
+
}
|
|
54
|
+
const results = await analyzeContext(finalOptions);
|
|
55
|
+
const summary = generateSummary(results, finalOptions);
|
|
56
|
+
const duration = getElapsedTime(startTime);
|
|
57
|
+
if (options.output === "json") {
|
|
58
|
+
handleJSONOutput(
|
|
59
|
+
{
|
|
60
|
+
summary: {
|
|
61
|
+
...summary,
|
|
62
|
+
executionTime: duration,
|
|
63
|
+
config: {
|
|
64
|
+
scan: { tools: ["context"] },
|
|
65
|
+
tools: { context: finalOptions }
|
|
66
|
+
},
|
|
67
|
+
toolConfigs: { context: finalOptions }
|
|
68
|
+
},
|
|
69
|
+
context: { results }
|
|
70
|
+
},
|
|
71
|
+
options.outputFile
|
|
72
|
+
);
|
|
73
|
+
} else if (options.output === "html") {
|
|
74
|
+
const html = generateHTMLReport(summary, results);
|
|
75
|
+
const outputPath = resolveOutputPath(
|
|
76
|
+
directory,
|
|
77
|
+
options.outputFile,
|
|
78
|
+
"context-report.html"
|
|
79
|
+
);
|
|
80
|
+
writeFileSync(outputPath, html, "utf-8");
|
|
81
|
+
console.log(chalk.green(`
|
|
82
|
+
\u2705 HTML report saved to: ${outputPath}`));
|
|
83
|
+
} else {
|
|
84
|
+
displayConsoleReport(summary, results, finalOptions.maxResults);
|
|
85
|
+
console.log(chalk.dim(`
|
|
86
|
+
\u2728 Analysis completed in ${duration}ms
|
|
87
|
+
`));
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
handleCLIError(error, "context-analyzer");
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export {
|
|
94
|
+
contextActionHandler
|
|
95
|
+
};
|
package/dist/cli.js
CHANGED
|
@@ -60,8 +60,14 @@ function calculateEnhancedCohesion(exports2, filePath, options) {
|
|
|
60
60
|
if (exp1Imports || exp2Imports) {
|
|
61
61
|
anyImportData = true;
|
|
62
62
|
const sim = (0, import_core.calculateImportSimilarity)(
|
|
63
|
-
{
|
|
64
|
-
|
|
63
|
+
{
|
|
64
|
+
...exports2[i],
|
|
65
|
+
imports: exp1Imports || []
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
...exports2[j],
|
|
69
|
+
imports: exp2Imports || []
|
|
70
|
+
}
|
|
65
71
|
);
|
|
66
72
|
importScoreTotal += sim;
|
|
67
73
|
pairsWithData++;
|
package/dist/cli.mjs
CHANGED
|
@@ -37,7 +37,7 @@ function defineContextCommand(program2) {
|
|
|
37
37
|
"--interactive",
|
|
38
38
|
"Run interactive setup to suggest excludes and focus areas"
|
|
39
39
|
).action(async (directory, options) => {
|
|
40
|
-
const { contextActionHandler } = await import("./cli-action-
|
|
40
|
+
const { contextActionHandler } = await import("./cli-action-HREY7TK5.mjs");
|
|
41
41
|
await contextActionHandler(directory, options);
|
|
42
42
|
});
|
|
43
43
|
}
|
package/dist/index.js
CHANGED
|
@@ -60,8 +60,14 @@ function calculateEnhancedCohesion(exports2, filePath, options) {
|
|
|
60
60
|
if (exp1Imports || exp2Imports) {
|
|
61
61
|
anyImportData = true;
|
|
62
62
|
const sim = (0, import_core2.calculateImportSimilarity)(
|
|
63
|
-
{
|
|
64
|
-
|
|
63
|
+
{
|
|
64
|
+
...exports2[i],
|
|
65
|
+
imports: exp1Imports || []
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
...exports2[j],
|
|
69
|
+
imports: exp2Imports || []
|
|
70
|
+
}
|
|
65
71
|
);
|
|
66
72
|
importScoreTotal += sim;
|
|
67
73
|
pairsWithData++;
|
|
@@ -1949,15 +1955,16 @@ var WEIGHT_DEPTH = 0.25;
|
|
|
1949
1955
|
var WEIGHT_FRAGMENTATION = 0.25;
|
|
1950
1956
|
function calculateContextScore(summary, costConfig) {
|
|
1951
1957
|
const {
|
|
1952
|
-
avgContextBudget,
|
|
1953
|
-
maxContextBudget,
|
|
1954
|
-
avgImportDepth,
|
|
1955
|
-
maxImportDepth,
|
|
1956
|
-
avgFragmentation,
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1958
|
+
avgContextBudget = 0,
|
|
1959
|
+
maxContextBudget = 0,
|
|
1960
|
+
avgImportDepth = 0,
|
|
1961
|
+
maxImportDepth = 0,
|
|
1962
|
+
avgFragmentation = 0.5,
|
|
1963
|
+
// neutral
|
|
1964
|
+
criticalIssues = 0,
|
|
1965
|
+
majorIssues = 0,
|
|
1966
|
+
totalFiles = 0
|
|
1967
|
+
} = summary || {};
|
|
1961
1968
|
const budgetScore = avgContextBudget < BUDGET_EXCELLENT_THRESHOLD ? 100 : Math.max(
|
|
1962
1969
|
0,
|
|
1963
1970
|
100 - (avgContextBudget - BUDGET_EXCELLENT_THRESHOLD) / BUDGET_PENALTY_RATE
|
package/dist/index.mjs
CHANGED
|
@@ -48,18 +48,18 @@ import {
|
|
|
48
48
|
isSessionFile,
|
|
49
49
|
isTypeDefinition,
|
|
50
50
|
isUtilityModule
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-ZA7HRDAH.mjs";
|
|
52
52
|
import "./chunk-64U3PNO3.mjs";
|
|
53
53
|
import {
|
|
54
54
|
generateSummary
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-BTDF2ZA4.mjs";
|
|
56
56
|
import {
|
|
57
57
|
calculateDirectoryDistance,
|
|
58
58
|
calculateEnhancedCohesion,
|
|
59
59
|
calculateFragmentation,
|
|
60
60
|
calculatePathEntropy,
|
|
61
61
|
calculateStructuralCohesionFromCoUsage
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-JSM7Q5CY.mjs";
|
|
63
63
|
|
|
64
64
|
// src/index.ts
|
|
65
65
|
import { ToolRegistry } from "@aiready/core";
|
|
@@ -100,15 +100,16 @@ var WEIGHT_DEPTH = 0.25;
|
|
|
100
100
|
var WEIGHT_FRAGMENTATION = 0.25;
|
|
101
101
|
function calculateContextScore(summary, costConfig) {
|
|
102
102
|
const {
|
|
103
|
-
avgContextBudget,
|
|
104
|
-
maxContextBudget,
|
|
105
|
-
avgImportDepth,
|
|
106
|
-
maxImportDepth,
|
|
107
|
-
avgFragmentation,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
103
|
+
avgContextBudget = 0,
|
|
104
|
+
maxContextBudget = 0,
|
|
105
|
+
avgImportDepth = 0,
|
|
106
|
+
maxImportDepth = 0,
|
|
107
|
+
avgFragmentation = 0.5,
|
|
108
|
+
// neutral
|
|
109
|
+
criticalIssues = 0,
|
|
110
|
+
majorIssues = 0,
|
|
111
|
+
totalFiles = 0
|
|
112
|
+
} = summary || {};
|
|
112
113
|
const budgetScore = avgContextBudget < BUDGET_EXCELLENT_THRESHOLD ? 100 : Math.max(
|
|
113
114
|
0,
|
|
114
115
|
100 - (avgContextBudget - BUDGET_EXCELLENT_THRESHOLD) / BUDGET_PENALTY_RATE
|
|
@@ -265,8 +266,8 @@ var ContextAnalyzerProvider = {
|
|
|
265
266
|
id: ToolName2.ContextAnalyzer,
|
|
266
267
|
alias: ["context", "fragmentation", "budget"],
|
|
267
268
|
async analyze(options) {
|
|
268
|
-
const { analyzeContext: analyzeContext2 } = await import("./orchestrator-
|
|
269
|
-
const { generateSummary: generateSummary2 } = await import("./summary-
|
|
269
|
+
const { analyzeContext: analyzeContext2 } = await import("./orchestrator-62YVSQFV.mjs");
|
|
270
|
+
const { generateSummary: generateSummary2 } = await import("./summary-RSPRRY6S.mjs");
|
|
270
271
|
const results = await analyzeContext2(options);
|
|
271
272
|
const summary = generateSummary2(results, options);
|
|
272
273
|
const normalizedResults = results.map(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/context-analyzer",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.8",
|
|
4
4
|
"description": "AI context window cost analysis - detect fragmented code, deep import chains, and expensive context budgets",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"commander": "^14.0.0",
|
|
50
50
|
"chalk": "^5.3.0",
|
|
51
51
|
"prompts": "^2.4.2",
|
|
52
|
-
"@aiready/core": "0.24.
|
|
52
|
+
"@aiready/core": "0.24.8"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^24.0.0",
|
|
@@ -68,6 +68,8 @@
|
|
|
68
68
|
"test": "vitest run --exclude \"**/dist/**\"",
|
|
69
69
|
"lint": "eslint src",
|
|
70
70
|
"clean": "rm -rf dist",
|
|
71
|
-
"release": "pnpm build && pnpm publish --no-git-checks"
|
|
71
|
+
"release": "pnpm build && pnpm publish --no-git-checks",
|
|
72
|
+
"type-check": "tsc --noEmit",
|
|
73
|
+
"format-check": "prettier --check . --ignore-path ../../.prettierignore"
|
|
72
74
|
}
|
|
73
75
|
}
|
package/src/metrics.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { calculateImportSimilarity, isTestFile } from '@aiready/core';
|
|
2
|
-
import type { ExportInfo } from '@aiready/core';
|
|
2
|
+
import type { ExportInfo, ExportWithImports } from '@aiready/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Calculates a cohesion score (0-1) for a module based on its exports,
|
|
@@ -29,7 +29,7 @@ export function calculateEnhancedCohesion(
|
|
|
29
29
|
if (filePath && isTestFile(filePath)) return 1;
|
|
30
30
|
|
|
31
31
|
// 1. Domain-based cohesion using entropy
|
|
32
|
-
const domains = exports.map((e:
|
|
32
|
+
const domains = exports.map((e: ExportInfo) => e.inferredDomain || 'unknown');
|
|
33
33
|
const domainCounts = new Map<string, number>();
|
|
34
34
|
for (const domain of domains)
|
|
35
35
|
domainCounts.set(domain, (domainCounts.get(domain) || 0) + 1);
|
|
@@ -63,8 +63,14 @@ export function calculateEnhancedCohesion(
|
|
|
63
63
|
if (exp1Imports || exp2Imports) {
|
|
64
64
|
anyImportData = true;
|
|
65
65
|
const sim = calculateImportSimilarity(
|
|
66
|
-
{
|
|
67
|
-
|
|
66
|
+
{
|
|
67
|
+
...exports[i],
|
|
68
|
+
imports: exp1Imports || [],
|
|
69
|
+
} as unknown as ExportWithImports,
|
|
70
|
+
{
|
|
71
|
+
...exports[j],
|
|
72
|
+
imports: exp2Imports || [],
|
|
73
|
+
} as unknown as ExportWithImports
|
|
68
74
|
);
|
|
69
75
|
importScoreTotal += sim;
|
|
70
76
|
pairsWithData++;
|
package/src/scoring.ts
CHANGED
|
@@ -49,15 +49,15 @@ export function calculateContextScore(
|
|
|
49
49
|
costConfig?: Partial<CostConfig>
|
|
50
50
|
): ToolScoringOutput {
|
|
51
51
|
const {
|
|
52
|
-
avgContextBudget,
|
|
53
|
-
maxContextBudget,
|
|
54
|
-
avgImportDepth,
|
|
55
|
-
maxImportDepth,
|
|
56
|
-
avgFragmentation,
|
|
57
|
-
criticalIssues,
|
|
58
|
-
majorIssues,
|
|
59
|
-
totalFiles,
|
|
60
|
-
} = summary;
|
|
52
|
+
avgContextBudget = 0,
|
|
53
|
+
maxContextBudget = 0,
|
|
54
|
+
avgImportDepth = 0,
|
|
55
|
+
maxImportDepth = 0,
|
|
56
|
+
avgFragmentation = 0.5, // neutral
|
|
57
|
+
criticalIssues = 0,
|
|
58
|
+
majorIssues = 0,
|
|
59
|
+
totalFiles = 0,
|
|
60
|
+
} = summary || {};
|
|
61
61
|
|
|
62
62
|
// More reasonable thresholds for modern codebases
|
|
63
63
|
const budgetScore =
|