invariant-first-coding

Rewrite code branches to encode real invariants and remove non-invariant safeguards.

16|3|Updated May 5, 2026
One-click install
npx skills add https://github.com/Kevin-Liu-01/Agent-Machines --skill invariant-first-coding
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: invariant-first-coding
Source: https://github.com/Kevin-Liu-01/Agent-Machines/tree/main/knowledge/skills/invariant-first-coding
Command: npx skills add https://github.com/Kevin-Liu-01/Agent-Machines --skill invariant-first-coding

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Reason from proven invariants before coding. Eliminate defensive theater, minimize unreachable code, and ensure runtime behavior aligns with guarantees.

Core Features & Use Cases

  • Invariant-first decision making: encode the system invariant directly in code paths.
  • Clear classification: distinguish real runtime cases, invariant violations, and type-system artifacts.
  • Safer review templates: provide concrete guardrails to prune unnecessary fallbacks and assertions.

Quick Start

Ask the AI to identify the real invariant in a function and rewrite branches to reflect that invariant.

Frequently Asked Questions about invariant-first-coding

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

FAQPage Schema
How do I remove defensive coding and unnecessary fallbacks in my code review?

Defensive coding can be minimized by deriving real system invariants and removing non-invariant safeguards. This approach distinguishes reachable runtime cases from invariant violations, ensuring code paths reflect proven guarantees rather than speculative fallbacks.

What is an invariant-first approach to software engineering?

An invariant-first approach encodes proven system invariants directly into code paths before writing logic. It eliminates defensive theater by distinguishing actual runtime cases from impossible states, ensuring behavior aligns with strict guarantees.

When should I use assertions to prevent runtime errors?

Assertions should prevent runtime errors when an invariant is violated. Use them explicitly to guard type boundaries and conversions, ensuring impossible states trigger preventive errors rather than slipping through as defensive fallback code.

How do I identify real invariants in a function to rewrite branches?

Identify real invariants by reasoning from proven system behavior, then rewrite branches to enshrine those guarantees. This removes unreachable code and aligns type boundaries and conversions with actual reachable runtime cases instead of speculative guards.

Does invariant-first coding require explicit error handling for type boundaries?

Yes, invariant-first coding requires explicit error handling and strong guardrails for type boundaries. It classifies type-system artifacts separately from real runtime cases, relying on preventive assertions when invariant violations occur.

What is the best way to distinguish real runtime cases from invariant violations?

The best way is encoding real invariants directly into code paths to classify behavior. This approach separates actual reachable runtime cases from invariant violations and type-system artifacts, removing non-invariant safeguards.