All files scoring.ts

100% Statements 5/5
83.33% Branches 5/6
100% Functions 2/2
100% Lines 5/5

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 61 62 63 64                    3x   3x                                                               3x 2x             3x                      
import { type ToolScoringOutput, ToolName } from '@aiready/core';
import type { AgentGroundingReport } from './types';
 
/**
 * Convert agent grounding report into a ToolScoringOutput
 * for inclusion in the unified AIReady score.
 */
export function calculateGroundingScore(
  report: AgentGroundingReport
): ToolScoringOutput {
  const { summary, rawData, recommendations } = report;
 
  const factors: ToolScoringOutput['factors'] = [
    {
      name: 'Structure Clarity',
      impact: Math.round(summary.dimensions.structureClarityScore - 50),
      description: `${rawData.deepDirectories} of ${rawData.totalDirectories} dirs exceed recommended depth`,
    },
    {
      name: 'Self-Documentation',
      impact: Math.round(summary.dimensions.selfDocumentationScore - 50),
      description: `${rawData.vagueFileNames} of ${rawData.totalFiles} files have vague names`,
    },
    {
      name: 'Entry Points',
      impact: Math.round(summary.dimensions.entryPointScore - 50),
      description: rawData.hasRootReadme
        ? rawData.readmeIsFresh
          ? 'README present and fresh'
          : 'README present but stale'
        : 'No root README',
    },
    {
      name: 'API Clarity',
      impact: Math.round(summary.dimensions.apiClarityScore - 50),
      description: `${rawData.untypedExports} of ${rawData.totalExports} exports lack type annotations`,
    },
    {
      name: 'Domain Consistency',
      impact: Math.round(summary.dimensions.domainConsistencyScore - 50),
      description: `${rawData.inconsistentDomainTerms} inconsistent domain terms detected`,
    },
  ];
 
  const recs: ToolScoringOutput['recommendations'] = recommendations.map(
    (action) => ({
      action,
      estimatedImpact: 6,
      priority: summary.score < 50 ? 'high' : 'medium',
    })
  );
 
  return {
    toolName: ToolName.AgentGrounding,
    score: summary.score,
    rawMetrics: {
      ...rawData,
      rating: summary.rating,
    },
    factors,
    recommendations: recs,
  };
}