Skip to content

REAL-WORLD-SCHEMAS-12: First cross-document check: dangling depends_on

A docRule that flags a task whose depends_on names an id no task defines.

Builds on: REAL-WORLD-SCHEMAS-10: Corpus config: route two types, first match wins

A TypeScript program against the library API; inline comments show the resulting values and behavior.

import { contract, sections, section, docRule, runCorpus } from "markdown-contract";
const task = contract({
frontmatter: z.object({ id: z.string(), depends_on: z.array(z.string()).default([]) }).strict(),
body: sections({ allowUnknown: true }, [section("Goal")]),
rules: [ docRule("task/depends-resolve", (doc, ctx) =>
doc.frontmatter.depends_on.filter(d => !KNOWN_IDS.has(d)).map(d =>
ctx.finding({ id: "task/depends-resolve", level: "error", message: `unknown dependency ${d}` }))) ],
});
await runCorpus({ rules: [{ include: ["docs/planning/tasks/**/*.md"], contract: task }] }, { cwd: "." });
  • contract({ rules }); docRule(id, (doc, ctx)) reading typed doc.frontmatter
  • runCorpus aggregating findings + exitCode (aggregation not yet fully tested — T-DRAG)