All files / src provider.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 4/4
100% Lines 11/11

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 65 66 67                                  11x         1x 1x   1x 1x     1x 1x   1x                           1x                           1x 1x          
import {
  ToolProvider,
  ToolName,
  SpokeOutput,
  ScanOptions,
  ToolScoringOutput,
  AnalysisResult,
  Severity,
  IssueType,
  SpokeOutputSchema,
} from '@aiready/core';
import { calculateContextScore } from './scoring';
import type { ContextAnalyzerOptions, ContextAnalysisResult } from './types';
 
/**
 * Context Analyzer Tool Provider
 */
export const ContextAnalyzerProvider: ToolProvider = {
  id: ToolName.ContextAnalyzer,
  alias: ['context', 'fragmentation', 'budget'],
 
  async analyze(options: ScanOptions): Promise<SpokeOutput> {
    const { analyzeContext } = await import('./orchestrator');
    const { generateSummary } = await import('./summary');
 
    const results = await analyzeContext(options as ContextAnalyzerOptions);
    const summary = generateSummary(results, options);
 
    // Normalize to SpokeOutput format
    const normalizedResults: AnalysisResult[] = results.map(
      (r: ContextAnalysisResult) => ({
        fileName: r.file,
        issues: r.issues.map((msg) => ({
          type: IssueType.ContextFragmentation,
          severity: r.severity as Severity,
          message: msg,
          location: { file: r.file, line: 1 },
          suggestion: r.recommendations[0],
        })),
        metrics: {
          tokenCost: r.tokenCost,
          complexityScore: r.importDepth,
        },
      })
    );
 
    return SpokeOutputSchema.parse({
      results: normalizedResults,
      summary: {
        ...summary,
      },
      metadata: {
        toolName: ToolName.ContextAnalyzer,
        version: '0.17.5',
        timestamp: new Date().toISOString(),
      },
    });
  },
 
  score(output: SpokeOutput, options: ScanOptions): ToolScoringOutput {
    const summary = output.summary as any;
    return calculateContextScore(summary, (options as any).costConfig);
  },
 
  defaultWeight: 19,
};