|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * DX-coverage guard: every public exported FUNCTION in the dev-facing |
| 4 | + * `@threadplane/*` libraries must carry a non-empty JSDoc summary so app |
| 5 | + * developers get hover guidance on the surface they actually call. |
| 6 | + * |
| 7 | + * Symbols tagged `@internal` are exempt (spec-only / implementation exports). |
| 8 | + * Run: `node scripts/check-dx-coverage.mjs` — exits non-zero on violations. |
| 9 | + */ |
| 10 | +import { Application, TSConfigReader, ReflectionKind } from 'typedoc'; |
| 11 | +import fs from 'fs'; |
| 12 | +import path from 'path'; |
| 13 | + |
| 14 | +const LIBRARIES = [ |
| 15 | + { slug: 'chat', entryPoints: ['libs/chat/src/public-api.ts'] }, |
| 16 | + { slug: 'ag-ui', entryPoints: ['libs/ag-ui/src/public-api.ts'] }, |
| 17 | + { slug: 'langgraph', entryPoints: ['libs/langgraph/src/public-api.ts'] }, |
| 18 | + { slug: 'render', entryPoints: ['libs/render/src/public-api.ts'] }, |
| 19 | +]; |
| 20 | + |
| 21 | +function summaryText(comment) { |
| 22 | + if (!comment?.summary) return ''; |
| 23 | + return comment.summary.map((p) => p.text ?? '').join('').trim(); |
| 24 | +} |
| 25 | + |
| 26 | +function isInternal(reflection, signature) { |
| 27 | + const tagged = (c) => !!c?.blockTags?.some((t) => t.tag === '@internal') || !!c?.modifierTags?.has?.('@internal'); |
| 28 | + return tagged(reflection.comment) || tagged(signature?.comment); |
| 29 | +} |
| 30 | + |
| 31 | +/** A function is documented if either the reflection or its call signature has a summary. */ |
| 32 | +function functionHasSummary(reflection) { |
| 33 | + const sig = reflection.signatures?.[0]; |
| 34 | + return summaryText(reflection.comment).length > 0 || summaryText(sig?.comment).length > 0; |
| 35 | +} |
| 36 | + |
| 37 | +function* walk(reflections) { |
| 38 | + for (const ref of reflections ?? []) { |
| 39 | + yield ref; |
| 40 | + if (ref.children) yield* walk(ref.children); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +async function main() { |
| 45 | + const violations = []; |
| 46 | + let checked = 0; |
| 47 | + |
| 48 | + for (const lib of LIBRARIES) { |
| 49 | + const missing = lib.entryPoints.filter((p) => !fs.existsSync(p)); |
| 50 | + if (missing.length) { |
| 51 | + console.error(`✗ ${lib.slug}: entry point(s) not found: ${missing.join(', ')}`); |
| 52 | + process.exitCode = 1; |
| 53 | + continue; |
| 54 | + } |
| 55 | + const libDir = path.dirname(path.dirname(lib.entryPoints[0])); |
| 56 | + const libTsconfig = fs.existsSync(path.join(libDir, 'tsconfig.lib.json')) |
| 57 | + ? path.join(libDir, 'tsconfig.lib.json') |
| 58 | + : undefined; |
| 59 | + |
| 60 | + const app = await Application.bootstrapWithPlugins({ |
| 61 | + entryPoints: lib.entryPoints, |
| 62 | + skipErrorChecking: true, |
| 63 | + excludeInternal: true, |
| 64 | + ...(libTsconfig ? { tsconfig: libTsconfig } : {}), |
| 65 | + }); |
| 66 | + app.options.addReader(new TSConfigReader()); |
| 67 | + const project = await app.convert(); |
| 68 | + if (!project) throw new Error(`TypeDoc failed to convert ${lib.slug}`); |
| 69 | + |
| 70 | + for (const ref of walk(project.children)) { |
| 71 | + if (ref.kind !== ReflectionKind.Function) continue; |
| 72 | + if (isInternal(ref, ref.signatures?.[0])) continue; |
| 73 | + checked++; |
| 74 | + if (!functionHasSummary(ref)) { |
| 75 | + violations.push(`@threadplane/${lib.slug} :: ${ref.name}()`); |
| 76 | + } |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + if (violations.length) { |
| 81 | + console.error(`\n✗ DX-coverage: ${violations.length} public function(s) missing a JSDoc summary:\n`); |
| 82 | + for (const v of violations.sort()) console.error(` - ${v}`); |
| 83 | + console.error(`\nAdd a one-line summary (and ideally an @example), or mark the symbol @internal if it is not public API.`); |
| 84 | + process.exit(1); |
| 85 | + } |
| 86 | + |
| 87 | + console.log(`✓ DX-coverage: all ${checked} public functions across chat/ag-ui/langgraph/render have a JSDoc summary.`); |
| 88 | +} |
| 89 | + |
| 90 | +main().catch((e) => { console.error(e); process.exit(1); }); |
0 commit comments