For AI agents: a documentation index is available at /llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Skip to content

Scoring API

The scoring module is available as a pure function for programmatic consumers. It takes a ReportResult from runChecks and returns a standalone ScoreResult with the overall score, per-category breakdowns, interaction diagnostics, and fix suggestions.

Compute a score

ts
import { runChecks, computeScore } from 'afdocs';

const report = await runChecks('https://docs.example.com');
const score = computeScore(report);

console.log(score.overall); // 72
console.log(score.grade); // 'C'
console.log(score.categoryScores); // { 'content-discoverability': { score: 80, grade: 'B' }, ... }
console.log(score.diagnostics); // [{ id: 'markdown-undiscoverable', severity: 'warning', ... }]
console.log(score.resolutions); // { 'llms-txt-directive': 'Add a blockquote near the top...' }

computeScore is a pure function. It does not modify the report or make any network requests. Composition is the consumer's responsibility: the CLI formatters compose runChecks and computeScore; external consumers call them separately.

Import from the subpath

You can also import from the dedicated scoring subpath:

ts
import { computeScore } from 'afdocs/scoring';

This is the same function; the subpath is provided for consumers who want a narrower import.

ScoreResult

computeScore returns a ScoreResult with these fields:

FieldTypeDescription
overallnumberThe overall score (0-100)
gradeGradeLetter grade (A+, A, B, C, D, F)
categoryScoresRecord<string, CategoryScore>Per-category score and grade
checkScoresRecord<string, CheckScore>Per-check scoring details (weight, coefficient, proportion, earned score)
diagnosticsDiagnostic[]Interaction diagnostics that fired
capsScoreCap[]Score caps that were applied
resolutionsRecord<string, string>Fix suggestions keyed by check ID

Grade conversion

If you need to convert a numeric score to a letter grade independently:

ts
import { toGrade } from 'afdocs';

toGrade(92); // 'A'
toGrade(100); // 'A+'
toGrade(55); // 'F'

Types

ts
import type {
  ScoreResult,
  CheckScore,
  CategoryScore,
  ScoreCap,
  Diagnostic,
  DiagnosticSeverity, // 'info' | 'warning' | 'critical'
  Grade, // 'A+' | 'A' | 'B' | 'C' | 'D' | 'F'
} from 'afdocs';

For how the score is calculated (weights, coefficients, caps, proportional scoring), see Score Calculation.