Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | 3x 3x 3x 3x 4x 3x 3x | import { calculateAiSignalClarity, ToolName } from '@aiready/core';
import type { ToolScoringOutput } from '@aiready/core';
import type { AiSignalClarityReport } from './types';
/**
* Convert AI signal clarity report into a ToolScoringOutput
* suitable for inclusion in the unified AIReady score.
*
* Note: The risk score from core is 0-100 where higher = more risk.
* We invert it so the spoke score is 0-100 where higher = better.
*/
export function calculateAiSignalClarityScore(
report: AiSignalClarityReport
): ToolScoringOutput {
const { aggregateSignals } = report;
const riskResult = calculateAiSignalClarity({
overloadedSymbols: aggregateSignals.overloadedSymbols,
magicLiterals: aggregateSignals.magicLiterals,
booleanTraps: aggregateSignals.booleanTraps,
implicitSideEffects: aggregateSignals.implicitSideEffects,
deepCallbacks: aggregateSignals.deepCallbacks,
ambiguousNames: aggregateSignals.ambiguousNames,
undocumentedExports: aggregateSignals.undocumentedExports,
totalSymbols: Math.max(1, aggregateSignals.totalSymbols),
totalExports: Math.max(1, aggregateSignals.totalExports),
});
// Invert: high risk = low score
const score = Math.max(0, 100 - riskResult.score);
const factors: ToolScoringOutput['factors'] = riskResult.signals.map(
(sig) => ({
name: sig.name,
impact: -sig.riskContribution,
description: sig.description,
})
);
const recommendations: ToolScoringOutput['recommendations'] =
riskResult.recommendations.map((rec) => ({
action: rec,
estimatedImpact: 8,
priority: riskResult.score > 50 ? 'high' : 'medium',
}));
return {
toolName: ToolName.AiSignalClarity,
score,
rawMetrics: {
riskScore: riskResult.score,
rating: riskResult.rating,
topRisk: riskResult.topRisk,
...aggregateSignals,
},
factors,
recommendations,
};
}
|