@aiready/context-analyzer 0.22.5 → 0.22.7
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-test.log +51 -49
- package/CONTRIBUTING.md +1 -1
- package/dist/chunk-6FQYIG6I.mjs +1298 -0
- package/dist/chunk-M2EGQ36M.mjs +1304 -0
- package/dist/chunk-P74BO725.mjs +1296 -0
- package/dist/cli-action-3CWN7PBE.mjs +95 -0
- package/dist/cli-action-MLFCIW2O.mjs +95 -0
- package/dist/cli-action-VCXBZGZP.mjs +95 -0
- package/dist/cli.js +12 -7
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +3 -11
- package/dist/index.d.ts +3 -11
- package/dist/index.js +27 -17
- package/dist/index.mjs +12 -11
- package/dist/orchestrator-3ERQS3NW.mjs +10 -0
- package/dist/orchestrator-5AL3XBPZ.mjs +10 -0
- package/dist/orchestrator-KMAKMHTD.mjs +10 -0
- package/package.json +2 -2
- package/src/ast-utils.ts +2 -2
- package/src/cli-action.ts +3 -3
- package/src/cluster-detector.ts +3 -1
- package/src/graph-builder.ts +6 -2
- package/src/metrics.ts +2 -2
- package/src/orchestrator.ts +4 -2
- package/src/provider.ts +7 -3
- package/src/remediation.ts +5 -1
- package/src/scoring.ts +9 -9
- package/src/semantic/domain-inference.ts +17 -6
- package/src/types.ts +2 -11
package/src/metrics.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { calculateImportSimilarity, isTestFile } from '@aiready/core';
|
|
2
|
-
import type { ExportInfo } from '
|
|
2
|
+
import type { ExportInfo } 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) => e.inferredDomain || 'unknown');
|
|
32
|
+
const domains = exports.map((e: any) => 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);
|
package/src/orchestrator.ts
CHANGED
|
@@ -56,7 +56,7 @@ function mapNodeToResult(
|
|
|
56
56
|
const rawCohesionScore = calculateEnhancedCohesion(
|
|
57
57
|
node.exports,
|
|
58
58
|
file,
|
|
59
|
-
options as
|
|
59
|
+
options as unknown as Record<string, unknown>
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
// Initial classification
|
|
@@ -108,7 +108,9 @@ function mapNodeToResult(
|
|
|
108
108
|
cohesionScore,
|
|
109
109
|
domains: Array.from(
|
|
110
110
|
new Set(
|
|
111
|
-
node.exports.flatMap(
|
|
111
|
+
node.exports.flatMap(
|
|
112
|
+
(e: any) => e.domains?.map((d: any) => d.domain) || []
|
|
113
|
+
)
|
|
112
114
|
)
|
|
113
115
|
),
|
|
114
116
|
exportCount: node.exports.length,
|
package/src/provider.ts
CHANGED
|
@@ -10,7 +10,11 @@ import {
|
|
|
10
10
|
SpokeOutputSchema,
|
|
11
11
|
} from '@aiready/core';
|
|
12
12
|
import { calculateContextScore } from './scoring';
|
|
13
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
ContextAnalyzerOptions,
|
|
15
|
+
ContextAnalysisResult,
|
|
16
|
+
ContextSummary,
|
|
17
|
+
} from './types';
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* Context Analyzer Tool Provider
|
|
@@ -58,8 +62,8 @@ export const ContextAnalyzerProvider: ToolProvider = {
|
|
|
58
62
|
},
|
|
59
63
|
|
|
60
64
|
score(output: SpokeOutput, options: ScanOptions): ToolScoringOutput {
|
|
61
|
-
const summary = output.summary as
|
|
62
|
-
return calculateContextScore(summary,
|
|
65
|
+
const summary = output.summary as unknown as ContextSummary;
|
|
66
|
+
return calculateContextScore(summary, options.costConfig);
|
|
63
67
|
},
|
|
64
68
|
|
|
65
69
|
defaultWeight: 19,
|
package/src/remediation.ts
CHANGED
|
@@ -155,5 +155,9 @@ export function getGeneralRecommendations(
|
|
|
155
155
|
if (severity === 'info') severity = 'minor';
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
-
return {
|
|
158
|
+
return {
|
|
159
|
+
recommendations,
|
|
160
|
+
issues,
|
|
161
|
+
severity: severity as 'critical' | 'major' | 'minor' | 'info',
|
|
162
|
+
};
|
|
159
163
|
}
|
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 =
|
|
@@ -2,8 +2,8 @@ import type {
|
|
|
2
2
|
DependencyGraph,
|
|
3
3
|
DomainAssignment,
|
|
4
4
|
DomainSignals,
|
|
5
|
-
ExportInfo,
|
|
6
5
|
} from '../types';
|
|
6
|
+
import type { ExportInfo } from '@aiready/core';
|
|
7
7
|
import { singularize } from '../utils/string-utils';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -59,8 +59,12 @@ export function inferDomainFromSemantics(
|
|
|
59
59
|
const coNode = graph.nodes.get(coFile);
|
|
60
60
|
if (coNode) {
|
|
61
61
|
for (const exp of coNode.exports) {
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const expAny = exp as {
|
|
63
|
+
inferredDomain?: string;
|
|
64
|
+
domains?: Array<{ domain: string }>;
|
|
65
|
+
};
|
|
66
|
+
if (expAny.inferredDomain && expAny.inferredDomain !== 'unknown') {
|
|
67
|
+
const domain = expAny.inferredDomain;
|
|
64
68
|
if (!domainSignals.has(domain)) {
|
|
65
69
|
domainSignals.set(domain, {
|
|
66
70
|
coUsage: false,
|
|
@@ -85,8 +89,15 @@ export function inferDomainFromSemantics(
|
|
|
85
89
|
const typeNode = graph.nodes.get(typeFile);
|
|
86
90
|
if (typeNode) {
|
|
87
91
|
for (const exp of typeNode.exports) {
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
const expAny = exp as {
|
|
93
|
+
inferredDomain?: string;
|
|
94
|
+
domains?: Array<{ domain: string }>;
|
|
95
|
+
};
|
|
96
|
+
if (
|
|
97
|
+
expAny.inferredDomain &&
|
|
98
|
+
expAny.inferredDomain !== 'unknown'
|
|
99
|
+
) {
|
|
100
|
+
const domain = expAny.inferredDomain;
|
|
90
101
|
if (!domainSignals.has(domain)) {
|
|
91
102
|
domainSignals.set(domain, {
|
|
92
103
|
coUsage: false,
|
|
@@ -160,7 +171,7 @@ export function extractExports(
|
|
|
160
171
|
domainOptions,
|
|
161
172
|
fileImports
|
|
162
173
|
);
|
|
163
|
-
exports.push({ name, type, inferredDomain });
|
|
174
|
+
exports.push({ name, type, inferredDomain } as any);
|
|
164
175
|
}
|
|
165
176
|
});
|
|
166
177
|
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ScanOptions, Severity } from '@aiready/core';
|
|
1
|
+
import type { ScanOptions, Severity, ExportInfo } from '@aiready/core';
|
|
2
|
+
export type { ExportInfo };
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Options for the Context Analyzer tool.
|
|
@@ -159,16 +160,6 @@ export interface DependencyNode {
|
|
|
159
160
|
sharedTypes?: string[]; // Types shared with other files
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
export interface ExportInfo {
|
|
163
|
-
name: string;
|
|
164
|
-
type: 'function' | 'class' | 'const' | 'type' | 'interface' | 'default';
|
|
165
|
-
inferredDomain?: string; // Inferred from name/usage (legacy single domain)
|
|
166
|
-
domains?: DomainAssignment[]; // Multi-domain support with confidence scores
|
|
167
|
-
imports?: string[]; // Imports used by this export (for import-based cohesion)
|
|
168
|
-
dependencies?: string[]; // Other exports from same file this depends on
|
|
169
|
-
typeReferences?: string[]; // TypeScript types referenced by this export
|
|
170
|
-
}
|
|
171
|
-
|
|
172
163
|
export interface DomainAssignment {
|
|
173
164
|
domain: string;
|
|
174
165
|
confidence: number; // 0-1, how confident are we in this assignment
|