@doccov/sdk 0.11.0 → 0.12.0

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/dist/index.d.ts CHANGED
@@ -177,6 +177,54 @@ declare function getDriftSummary(drifts: SpecDocDrift[]): DriftSummary;
177
177
  * ```
178
178
  */
179
179
  declare function formatDriftSummaryLine(summary: DriftSummary): string;
180
+ /**
181
+ * Calculate aggregate coverage score from a spec's exports.
182
+ *
183
+ * This is a lightweight function that calculates coverage without
184
+ * requiring full quality evaluation. It handles three cases:
185
+ * 1. Exports with `docs.coverageScore` - uses that value
186
+ * 2. Exports without score but with description - counts as 100%
187
+ * 3. Exports without score and no description - counts as 0%
188
+ *
189
+ * @param spec - The OpenPkg spec to calculate coverage for
190
+ * @returns The aggregate coverage score (0-100)
191
+ *
192
+ * @example
193
+ * ```ts
194
+ * import { calculateAggregateCoverage } from '@doccov/sdk';
195
+ *
196
+ * const coverage = calculateAggregateCoverage(spec);
197
+ * console.log(`Coverage: ${coverage}%`);
198
+ * ```
199
+ */
200
+ declare function calculateAggregateCoverage(spec: OpenPkgSpec): number;
201
+ /**
202
+ * Ensure a spec has a top-level docs.coverageScore.
203
+ *
204
+ * If the spec already has `docs.coverageScore`, returns the spec unchanged.
205
+ * Otherwise, calculates aggregate coverage from exports and returns a
206
+ * new spec with the coverage score added.
207
+ *
208
+ * This is useful for commands like `diff` that need coverage scores
209
+ * but may receive raw specs that haven't been enriched.
210
+ *
211
+ * @param spec - The OpenPkg spec to ensure coverage for
212
+ * @returns The spec with guaranteed top-level coverage score
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * import { ensureSpecCoverage } from '@doccov/sdk';
217
+ *
218
+ * // Works with raw or enriched specs
219
+ * const specWithCoverage = ensureSpecCoverage(rawSpec);
220
+ * console.log(specWithCoverage.docs?.coverageScore); // e.g., 85
221
+ * ```
222
+ */
223
+ declare function ensureSpecCoverage(spec: OpenPkgSpec): OpenPkgSpec & {
224
+ docs: {
225
+ coverageScore: number;
226
+ };
227
+ };
180
228
  import { OpenPkg as OpenPkg2, SpecDocDrift as SpecDocDrift2, SpecDocsMetadata, SpecExport as SpecExport3 } from "@openpkg-ts/spec";
181
229
  import { SpecExport as SpecExport2, SpecExportKind } from "@openpkg-ts/spec";
182
230
  import * as TS from "typescript";
@@ -476,6 +524,24 @@ declare const REPORT_EXTENSIONS: Record<string, string>;
476
524
  */
477
525
  declare function getReportPath(format: string, dir?: string): string;
478
526
  /**
527
+ * Get the report path for a diff comparison.
528
+ *
529
+ * Uses truncated hashes from both specs to create a unique, deterministic filename.
530
+ *
531
+ * @param baseHash - Hash of the base (before) spec
532
+ * @param headHash - Hash of the head (after) spec
533
+ * @param format - The report format (json, markdown, html, github)
534
+ * @param dir - The output directory (defaults to .doccov)
535
+ * @returns The full path to the diff report file
536
+ *
537
+ * @example
538
+ * ```ts
539
+ * getDiffReportPath('abc123def456', 'xyz789uvw012', 'markdown');
540
+ * // '.doccov/diff-abc123de-xyz789uv.md'
541
+ * ```
542
+ */
543
+ declare function getDiffReportPath(baseHash: string, headHash: string, format: string, dir?: string): string;
544
+ /**
479
545
  * Drift summary with category breakdown.
480
546
  */
481
547
  interface DriftReportSummary {
@@ -2283,4 +2349,4 @@ declare function typecheckExample(example: string, packagePath: string, options?
2283
2349
  * Type-check multiple examples
2284
2350
  */
2285
2351
  declare function typecheckExamples(examples: string[], packagePath: string, options?: TypecheckOptions): TypecheckResult;
2286
- export { validateSpecCache, validateExamples, typecheckExamples, typecheckExample, shouldValidate, serializeJSDoc, saveSpecCache, saveReport, safeParseJson, runExamplesWithPackage, runExamples, runExample, resolveTarget, readPackageJson, parseMarkdownFiles, parseMarkdownFile, parseListFlag, parseJSDocToPatch, parseGitHubUrl, parseExamplesFlag, parseAssertions, mergeFixes, mergeFilters, mergeConfig, loadSpecCache, loadCachedReport, isFixableDrift, isExecutableLang, isCachedReportValid, installDependencies, hashString, hashFiles, hashFile, hasNonAssertionComments, hasDocsImpact, hasDocsForExport, groupDriftsByCategory, getUndocumentedExports, getSpecCachePath, getRunCommand, getRulesForKind, getRule, getReportPath, getPrimaryBuildScript, getInstallCommand, getDriftSummary, getDocumentedExports, getDocsImpactSummary, getDefaultConfig, getCoverageRules, generateReportFromEnriched, generateReport, generateFixesForExport, generateFix, formatPackageList, formatDriftSummaryLine, findRemovedReferences, findPackageByName, findJSDocLocation, findExportReferences, findDeprecatedReferences, fetchSpecFromGitHub, fetchSpec, extractSpecSummary, extractPackageSpec, extractImports, extractFunctionCalls, evaluateQuality, evaluateExportQuality, enrichSpec, diffSpecWithDocs, diffHashes, detectPackageManager, detectMonorepo, detectExampleRuntimeErrors, detectExampleAssertionFailures, detectEntryPoint, detectBuildInfo, defineConfig, createSourceFile, createNodeCommandRunner, computeExportDrift, computeDrift, clearSpecCache, categorizeDrifts, categorizeDrift, buildRawUrl, buildExportRegistry, buildDisplayUrl, buildCloneUrl, blockReferencesExport, applyPatchToJSDoc, applyEdits, analyzeProject2 as analyzeProject, analyzeFile, analyzeDocsImpact, analyze, WorkspacePackage, VALIDATION_INFO, TypecheckValidationResult, TypecheckResult, TypecheckOptions, SpecSummary, SpecDiffWithDocs, SpecCacheConfig, SpecCache, ScanResult, ScanOrchestratorOptions, ScanOrchestrator, ScanOptions, ScanContext, SandboxFileSystem, STYLE_RULES, SPEC_CACHE_FILE, RuntimeDrift, RunValidationResult, RunExamplesWithPackageResult, RunExamplesWithPackageOptions, RunExampleOptions, RuleContext, ResolvedTarget, ResolvedFilters, ResolveTargetOptions, REPORT_VERSION, REPORT_EXTENSIONS, QualityViolation, QualitySeverity2 as QualitySeverity, QualityRulesConfig, QualityRule, QualityResult, QualityConfig, ProjectInfo, ProgressStage, ProgressEvent, ProgressCallback, PresenceResult, ParsedGitHubUrl, PackageManagerInfo, PackageManager, PackageJson, PackageExports, OpenPkgSpec, OpenPkgOptions, OpenPkg8 as OpenPkg, NodeFileSystem, MonorepoType, MonorepoRequiresPackageError, MonorepoInfo, MemberChange, MarkdownDocFile, MarkdownCodeBlock, LLMAssertion, JSDocTag, JSDocReturn, JSDocPatch, JSDocParam, JSDocEdit, InstallResult, InstallOptions, FixType, FixSuggestion, FilterSource, FilterOptions, FileSystem, ExportReference, ExportDriftResult, ExportCoverageData, ExampleValidationTypeError, ExampleValidationResult, ExampleValidationOptions, ExampleValidationMode, ExampleValidation, ExampleTypeError, ExampleRunResult, EntryPointSource, EntryPointInfo, EnrichedOpenPkg, EnrichedExport, EnrichedDocsMetadata, EnrichOptions, DriftSummary, DriftResult, DriftReportSummary, DriftReport, DriftIssue, DocsImpactResult, DocsImpactReference, DocsImpact, DocsConfig, DocsChangeType, DocCovReport, DocCovOptions, DocCovConfig, DocCov, DiffWithDocsOptions, Diagnostic, DEFAULT_REPORT_PATH, DEFAULT_REPORT_DIR, CoverageSummary, CommandRunner, CommandResult, CheckConfig, CategorizedDrift, CacheValidationResult, CacheContext, CORE_RULES, CACHE_VERSION, BuildInfo, BUILTIN_RULES, ApplyEditsResult, AnalyzeProjectOptions, AnalyzeOptions, AnalysisResult, AggregateQualityResult, ALL_VALIDATIONS };
2352
+ export { validateSpecCache, validateExamples, typecheckExamples, typecheckExample, shouldValidate, serializeJSDoc, saveSpecCache, saveReport, safeParseJson, runExamplesWithPackage, runExamples, runExample, resolveTarget, readPackageJson, parseMarkdownFiles, parseMarkdownFile, parseListFlag, parseJSDocToPatch, parseGitHubUrl, parseExamplesFlag, parseAssertions, mergeFixes, mergeFilters, mergeConfig, loadSpecCache, loadCachedReport, isFixableDrift, isExecutableLang, isCachedReportValid, installDependencies, hashString, hashFiles, hashFile, hasNonAssertionComments, hasDocsImpact, hasDocsForExport, groupDriftsByCategory, getUndocumentedExports, getSpecCachePath, getRunCommand, getRulesForKind, getRule, getReportPath, getPrimaryBuildScript, getInstallCommand, getDriftSummary, getDocumentedExports, getDocsImpactSummary, getDiffReportPath, getDefaultConfig, getCoverageRules, generateReportFromEnriched, generateReport, generateFixesForExport, generateFix, formatPackageList, formatDriftSummaryLine, findRemovedReferences, findPackageByName, findJSDocLocation, findExportReferences, findDeprecatedReferences, fetchSpecFromGitHub, fetchSpec, extractSpecSummary, extractPackageSpec, extractImports, extractFunctionCalls, evaluateQuality, evaluateExportQuality, ensureSpecCoverage, enrichSpec, diffSpecWithDocs, diffHashes, detectPackageManager, detectMonorepo, detectExampleRuntimeErrors, detectExampleAssertionFailures, detectEntryPoint, detectBuildInfo, defineConfig, createSourceFile, createNodeCommandRunner, computeExportDrift, computeDrift, clearSpecCache, categorizeDrifts, categorizeDrift, calculateAggregateCoverage, buildRawUrl, buildExportRegistry, buildDisplayUrl, buildCloneUrl, blockReferencesExport, applyPatchToJSDoc, applyEdits, analyzeProject2 as analyzeProject, analyzeFile, analyzeDocsImpact, analyze, WorkspacePackage, VALIDATION_INFO, TypecheckValidationResult, TypecheckResult, TypecheckOptions, SpecSummary, SpecDiffWithDocs, SpecCacheConfig, SpecCache, ScanResult, ScanOrchestratorOptions, ScanOrchestrator, ScanOptions, ScanContext, SandboxFileSystem, STYLE_RULES, SPEC_CACHE_FILE, RuntimeDrift, RunValidationResult, RunExamplesWithPackageResult, RunExamplesWithPackageOptions, RunExampleOptions, RuleContext, ResolvedTarget, ResolvedFilters, ResolveTargetOptions, REPORT_VERSION, REPORT_EXTENSIONS, QualityViolation, QualitySeverity2 as QualitySeverity, QualityRulesConfig, QualityRule, QualityResult, QualityConfig, ProjectInfo, ProgressStage, ProgressEvent, ProgressCallback, PresenceResult, ParsedGitHubUrl, PackageManagerInfo, PackageManager, PackageJson, PackageExports, OpenPkgSpec, OpenPkgOptions, OpenPkg8 as OpenPkg, NodeFileSystem, MonorepoType, MonorepoRequiresPackageError, MonorepoInfo, MemberChange, MarkdownDocFile, MarkdownCodeBlock, LLMAssertion, JSDocTag, JSDocReturn, JSDocPatch, JSDocParam, JSDocEdit, InstallResult, InstallOptions, FixType, FixSuggestion, FilterSource, FilterOptions, FileSystem, ExportReference, ExportDriftResult, ExportCoverageData, ExampleValidationTypeError, ExampleValidationResult, ExampleValidationOptions, ExampleValidationMode, ExampleValidation, ExampleTypeError, ExampleRunResult, EntryPointSource, EntryPointInfo, EnrichedOpenPkg, EnrichedExport, EnrichedDocsMetadata, EnrichOptions, DriftSummary, DriftResult, DriftReportSummary, DriftReport, DriftIssue, DocsImpactResult, DocsImpactReference, DocsImpact, DocsConfig, DocsChangeType, DocCovReport, DocCovOptions, DocCovConfig, DocCov, DiffWithDocsOptions, Diagnostic, DEFAULT_REPORT_PATH, DEFAULT_REPORT_DIR, CoverageSummary, CommandRunner, CommandResult, CheckConfig, CategorizedDrift, CacheValidationResult, CacheContext, CORE_RULES, CACHE_VERSION, BuildInfo, BUILTIN_RULES, ApplyEditsResult, AnalyzeProjectOptions, AnalyzeOptions, AnalysisResult, AggregateQualityResult, ALL_VALIDATIONS };
package/dist/index.js CHANGED
@@ -1201,6 +1201,35 @@ function formatDriftSummaryLine(summary) {
1201
1201
  const fixableNote = summary.fixable > 0 ? ` (${summary.fixable} auto-fixable)` : "";
1202
1202
  return `${summary.total} issues (${parts.join(", ")})${fixableNote}`;
1203
1203
  }
1204
+ function calculateAggregateCoverage(spec) {
1205
+ const exports = spec.exports ?? [];
1206
+ if (exports.length === 0)
1207
+ return 100;
1208
+ let totalScore = 0;
1209
+ for (const exp of exports) {
1210
+ const score = exp.docs?.coverageScore;
1211
+ if (score !== undefined) {
1212
+ totalScore += score;
1213
+ } else {
1214
+ totalScore += exp.description ? 100 : 0;
1215
+ }
1216
+ }
1217
+ return Math.round(totalScore / exports.length);
1218
+ }
1219
+ function ensureSpecCoverage(spec) {
1220
+ const specWithDocs = spec;
1221
+ if (specWithDocs.docs?.coverageScore !== undefined) {
1222
+ return spec;
1223
+ }
1224
+ const coverage = calculateAggregateCoverage(spec);
1225
+ return {
1226
+ ...spec,
1227
+ docs: {
1228
+ ...specWithDocs.docs ?? {},
1229
+ coverageScore: coverage
1230
+ }
1231
+ };
1232
+ }
1204
1233
  // src/fix/jsdoc-writer.ts
1205
1234
  import * as fs from "node:fs";
1206
1235
  import * as path from "node:path";
@@ -1938,6 +1967,11 @@ function getReportPath(format, dir = DEFAULT_REPORT_DIR) {
1938
1967
  const ext = REPORT_EXTENSIONS[format] ?? format;
1939
1968
  return `${dir}/report.${ext}`;
1940
1969
  }
1970
+ function getDiffReportPath(baseHash, headHash, format, dir = DEFAULT_REPORT_DIR) {
1971
+ const ext = REPORT_EXTENSIONS[format] ?? format;
1972
+ const hash = `${baseHash.slice(0, 8)}-${headHash.slice(0, 8)}`;
1973
+ return `${dir}/diff-${hash}.${ext}`;
1974
+ }
1941
1975
 
1942
1976
  // src/analysis/report.ts
1943
1977
  function generateReport(spec) {
@@ -8626,6 +8660,7 @@ export {
8626
8660
  getDriftSummary,
8627
8661
  getDocumentedExports,
8628
8662
  getDocsImpactSummary,
8663
+ getDiffReportPath,
8629
8664
  getDefaultConfig,
8630
8665
  getCoverageRules,
8631
8666
  generateReportFromEnriched,
@@ -8647,6 +8682,7 @@ export {
8647
8682
  extractFunctionCalls,
8648
8683
  evaluateQuality,
8649
8684
  evaluateExportQuality,
8685
+ ensureSpecCoverage,
8650
8686
  enrichSpec,
8651
8687
  diffSpecWithDocs,
8652
8688
  diffHashes,
@@ -8664,6 +8700,7 @@ export {
8664
8700
  clearSpecCache,
8665
8701
  categorizeDrifts,
8666
8702
  categorizeDrift,
8703
+ calculateAggregateCoverage,
8667
8704
  buildRawUrl,
8668
8705
  buildExportRegistry,
8669
8706
  buildDisplayUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doccov/sdk",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "DocCov SDK - Documentation coverage and drift detection for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",