Custom rules for cross-cutting policy
automate-03 · TypeScript
When neither plane covers a policy, a named docRule sees the whole typed document — so a frontmatter field can gate a body section.
Builds on: Embed the corpus runner
The artifact
Section titled “The artifact”A TypeScript program against the library API; inline comments show the resulting values and behavior.
import { contract, sections, section, docRule } from "markdown-contract";import { z } from "zod";
// Policy: once a decision is accepted, it must record its outcome.const acceptedNeedsOutcome = docRule("policy/accepted-needs-outcome", (doc, ctx) => { if (doc.frontmatter.status === "accepted" && !doc.body.section("Outcome")) { return [ ctx.finding({ id: "policy/accepted-needs-outcome", message: "an accepted decision must record an Outcome section", }), ]; } return [];});
const decision = contract({ frontmatter: z.object({ status: z.enum(["proposed", "accepted"]) }), body: sections({ order: "none", allowUnknown: true }, [section("Summary")]), rules: [acceptedNeedsOutcome],});What it exercises
Section titled “What it exercises”docRule (cross-plane rules)ctx.finding() mintingfrontmatter gating body structure
Continue
Section titled “Continue”- Previous: A CI gate in GitHub Actions
- Next: This repo validates its own planning docs
- Group: Automate and embed · All examples
- Reference: Library API reference