build-guardrail

Converts a coding rule into a failing automated test with baselines and ratchets.

9|Updated Mar 4, 2026
One-click install
npx skills add https://github.com/timcsy/semorphe --skill build-guardrail-timcsy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: build-guardrail
Source: https://github.com/timcsy/semorphe/tree/main/knowledge/skills/build-guardrail
Command: npx skills add https://github.com/timcsy/semorphe --skill build-guardrail-timcsy

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Written coding rules decay because nothing enforces them mechanically. This Skill turns a rule into a test that turns red on violations, with a baseline and a ratchet that only allows the violation count to decrease, plus a self-falsification statement so the guardrail can say when it itself is broken. ## Core Features & Use Cases - Rule-to-check conversion: Picks one countable quantity per rule, measures from actually loaded runtime state rather than static config, and classifies conservatively (undecidable items never count as safe). - Anchor and injection discipline: Requires self-falsification statements written before measurement, synthetic-input anchors instead of real-world defect counts, and two-direction injection tests proving the check both reports bad input and stays quiet on good input. - Baseline and ratchet workflow: Generates baselines via vitest, enforces named-item reporting on regressions, distinguishes hard-zero rules from ratchet rules, and records reviewed decisions in a decisions JSON with collision-resistant keys. - Use Case: A team wants to enforce "no cross-layer direct calls" in a TypeScript codebase. The Skill guides writing an audit test that scans loaded modules, fails red on first run, names each violation, then locks a baseline so the count can only go down. ## Quick Start Ask the AI to build a guardrail for the rule you want enforced, naming the quantity to measure and the test file where the check should live.

Frequently Asked Questions about build-guardrail

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I turn a coding rule into an automated test?

Pick one countable quantity per rule, write a self-falsification statement before the measurement, then implement a vitest check that fails red on violations. Generate a baseline only after confirming the first run is red and each violation is named.

What is a ratchet in software testing?

A ratchet is a baseline number that may only decrease, used for rules with many existing violations that must be paid down gradually. Rules where a single violation breaks the invariant use a hard zero instead of a ratchet.

Why should a new guardrail test fail on its first run?

A new guardrail faces a world that was never governed by it, so violations must exist or the rule was unnecessary. A green first run means the criterion is wrong, data failed to load, or the baseline was generated before measuring.

When should I use vitest snapshots for regression checks?

Do not use vitest snapshots for guardrails, because the -u flag silently updates them and auto-accepts degradation. Use explicit baselines with named-item reporting so every regression identifies exactly which item is new.

Why does my guardrail report new violations after I fixed code?

The decision key likely uses file line numbers, which shift when code above them is removed. Key decisions by stable identifiers like file plus imported path or receiver method, keeping line numbers only for human-readable reports.