Skip to content

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

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],
});
  • docRule (cross-plane rules)
  • ctx.finding() minting
  • frontmatter gating body structure