Embed the corpus runner
automate-01 · TypeScript
Everything the CLI does is one library call: runCorpus routes a tree of files to contracts and returns findings, stats, and an exit code.
Builds on: nothing — start here in Automate and embed.
The artifact
Section titled “The artifact”A TypeScript program against the library API; inline comments show the resulting values and behavior.
import { defineConfig, runCorpus, countByLevel } from "markdown-contract";
const config = defineConfig({ rules: [ { include: ["decisions/**/*.md"], contract: decision, name: "decision" }, { include: ["**/*.md"], contract: notes, name: "notes" }, // catch-all last: first match wins ],});
const { findings, exitCode, stats } = runCorpus(config, { cwd: repoRoot });
stats.filesScanned; // every file the walk sawstats.matchedByRule; // per-rule match counts, parallel to config.rulescountByLevel(findings); // { error, warn, report }process.exit(exitCode); // 0 clean, 1 error-level findings — same verdict as the CLIWhat it exercises
Section titled “What it exercises”defineConfig / runCorpusfirst-match glob routingRunStats and countByLevellibrary exit codes
Continue
Section titled “Continue”- Previous: this is the first example of the group
- Next: A CI gate in GitHub Actions
- Group: Automate and embed · All examples
- Reference: Library API reference