Skip to content

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.

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 saw
stats.matchedByRule; // per-rule match counts, parallel to config.rules
countByLevel(findings); // { error, warn, report }
process.exit(exitCode); // 0 clean, 1 error-level findings — same verdict as the CLI
  • defineConfig / runCorpus
  • first-match glob routing
  • RunStats and countByLevel
  • library exit codes