@aiready/context-analyzer 0.17.5 → 0.19.0
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 +10 -10
- package/.turbo/turbo-lint.log +22 -2
- package/.turbo/turbo-test.log +21 -18
- package/dist/chunk-474DEGWW.mjs +1792 -0
- package/dist/chunk-IPIE5TXJ.mjs +1741 -0
- package/dist/chunk-Q2GDZ2FZ.mjs +1794 -0
- package/dist/chunk-S6OPP4L5.mjs +1791 -0
- package/dist/cli.js +190 -35
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +64 -30
- package/dist/index.mjs +3 -1
- package/package.json +2 -2
- package/src/index.ts +6 -1
- package/src/metrics.ts +13 -23
- package/src/provider.ts +65 -0
- package/src/scoring.ts +2 -1
package/src/metrics.ts
CHANGED
|
@@ -69,16 +69,12 @@ export function calculateEnhancedCohesion(
|
|
|
69
69
|
pairsWithData > 0 ? importScoreTotal / pairsWithData : 0;
|
|
70
70
|
|
|
71
71
|
// Weighted average
|
|
72
|
-
let score =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (score === 0 && domainScore === 0) score = 0.1;
|
|
79
|
-
} else {
|
|
80
|
-
// Fallback to domain-based
|
|
81
|
-
score = domainScore;
|
|
72
|
+
let score = anyImportData
|
|
73
|
+
? domainScore * 0.4 + avgImportScore * 0.6
|
|
74
|
+
: domainScore;
|
|
75
|
+
|
|
76
|
+
if (anyImportData && score === 0 && domainScore === 0) {
|
|
77
|
+
score = 0.1;
|
|
82
78
|
}
|
|
83
79
|
|
|
84
80
|
// Structural boost
|
|
@@ -150,19 +146,13 @@ export function calculateFragmentation(
|
|
|
150
146
|
);
|
|
151
147
|
const uniqueDirs = directories.size;
|
|
152
148
|
|
|
153
|
-
let score =
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const den = Math.log(total) / Math.log(base);
|
|
161
|
-
score = den > 0 ? num / den : 0;
|
|
162
|
-
}
|
|
163
|
-
} else {
|
|
164
|
-
score = (uniqueDirs - 1) / (files.length - 1);
|
|
165
|
-
}
|
|
149
|
+
let score = options?.useLogScale
|
|
150
|
+
? uniqueDirs <= 1
|
|
151
|
+
? 0
|
|
152
|
+
: Math.log(uniqueDirs) /
|
|
153
|
+
Math.log(options.logBase || Math.E) /
|
|
154
|
+
(Math.log(files.length) / Math.log(options.logBase || Math.E))
|
|
155
|
+
: (uniqueDirs - 1) / (files.length - 1);
|
|
166
156
|
|
|
167
157
|
// Coupling Discount
|
|
168
158
|
if (options?.sharedImportRatio && options.sharedImportRatio > 0.5) {
|
package/src/provider.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ToolProvider,
|
|
3
|
+
ToolName,
|
|
4
|
+
SpokeOutput,
|
|
5
|
+
ScanOptions,
|
|
6
|
+
ToolScoringOutput,
|
|
7
|
+
AnalysisResult,
|
|
8
|
+
Severity,
|
|
9
|
+
IssueType,
|
|
10
|
+
SpokeOutputSchema,
|
|
11
|
+
} from '@aiready/core';
|
|
12
|
+
import { analyzeContext, generateSummary } from './index';
|
|
13
|
+
import { calculateContextScore } from './scoring';
|
|
14
|
+
import { ContextAnalyzerOptions, ContextAnalysisResult } from './types';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Context Analyzer Tool Provider
|
|
18
|
+
*/
|
|
19
|
+
export const ContextAnalyzerProvider: ToolProvider = {
|
|
20
|
+
id: ToolName.ContextAnalyzer,
|
|
21
|
+
alias: ['context', 'fragmentation', 'budget'],
|
|
22
|
+
|
|
23
|
+
async analyze(options: ScanOptions): Promise<SpokeOutput> {
|
|
24
|
+
const results = await analyzeContext(options as ContextAnalyzerOptions);
|
|
25
|
+
const summary = generateSummary(results);
|
|
26
|
+
|
|
27
|
+
// Normalize to SpokeOutput format
|
|
28
|
+
const normalizedResults: AnalysisResult[] = results.map(
|
|
29
|
+
(r: ContextAnalysisResult) => ({
|
|
30
|
+
fileName: r.file,
|
|
31
|
+
issues: r.issues.map((msg) => ({
|
|
32
|
+
type: IssueType.ContextFragmentation,
|
|
33
|
+
severity: r.severity as Severity,
|
|
34
|
+
message: msg,
|
|
35
|
+
location: { file: r.file, line: 1 },
|
|
36
|
+
suggestion: r.recommendations[0],
|
|
37
|
+
})),
|
|
38
|
+
metrics: {
|
|
39
|
+
tokenCost: r.tokenCost,
|
|
40
|
+
complexityScore: r.importDepth,
|
|
41
|
+
// Map other context-specific metrics if needed
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return SpokeOutputSchema.parse({
|
|
47
|
+
results: normalizedResults,
|
|
48
|
+
summary: {
|
|
49
|
+
...summary,
|
|
50
|
+
},
|
|
51
|
+
metadata: {
|
|
52
|
+
toolName: ToolName.ContextAnalyzer,
|
|
53
|
+
version: '0.17.5',
|
|
54
|
+
timestamp: new Date().toISOString(),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
score(output: SpokeOutput, options: ScanOptions): ToolScoringOutput {
|
|
60
|
+
const summary = output.summary as any;
|
|
61
|
+
return calculateContextScore(summary, (options as any).costConfig);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
defaultWeight: 19,
|
|
65
|
+
};
|
package/src/scoring.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
calculateProductivityImpact,
|
|
4
4
|
DEFAULT_COST_CONFIG,
|
|
5
5
|
type CostConfig,
|
|
6
|
+
ToolName,
|
|
6
7
|
} from '@aiready/core';
|
|
7
8
|
import type { ToolScoringOutput } from '@aiready/core';
|
|
8
9
|
import type { ContextSummary } from './types';
|
|
@@ -150,7 +151,7 @@ export function calculateContextScore(
|
|
|
150
151
|
const productivityImpact = calculateProductivityImpact(issues);
|
|
151
152
|
|
|
152
153
|
return {
|
|
153
|
-
toolName:
|
|
154
|
+
toolName: ToolName.ContextAnalyzer,
|
|
154
155
|
score,
|
|
155
156
|
rawMetrics: {
|
|
156
157
|
avgContextBudget: Math.round(avgContextBudget),
|