Tw invariant ace

From SDiamante13/dotfiles · View interactive version

Tw invariant ace is an AI agent skill from the GitHub repository SDiamante13/dotfiles. Turn 'should never happen' into 'cannot happen' by defining owned inductive invariants and enforcing them at parse/construct/API/DB/lock/txn boundaries with a verification signal. Use when prompts mention invariants, impossible states, validation sprawl, cache/index drift, idempotency/versioning, re

How to use this skill

Skill file

Invariant Ace

Mission

Turn "should never happen" into "cannot happen" with minimal, high-leverage changes: pick owned, inductive invariants; enforce them at the strongest cheap boundary; prove via a concrete counterexample trace and a verification signal.

Use When (Signals)

Routing Priority

Core Model (Fast Definitions)

Immediate Scan

Protection Ladder

Choose the cheapest strong layer that makes the violation hard or impossible.

Protocol (Counterexample-Driven)

  1. Declare scope + owner.
  1. List transitions and try to break P.
  1. Make P inductive (or downgrade it).
  1. Run a coordination check (concurrency/distributed).
  1. Encode enforcement at the strongest cheap boundary.
  1. Add observability if full enforcement must be staged.
  1. Verify with the right harness.

Compact Mode (Fast Path)

Use this when the task is small or time-boxed.

  1. Counterexample: one concrete failing trace (<=5 transitions).
  2. Invariants: 1-2 predicates with explicit owner + scope.
  3. Enforcement Boundary: one chosen choke point (parse/construct/API/DB/lock/txn).
  4. Verification: one signal tied to one predicate.

Escalate to full protocol if any of the above is ambiguous or non-inductive.

Invariant Record (Use This Format)

Patterns by Pain

Data Modeling & Input Validity

Concurrency & Protocol Correctness

Algorithms & Loop-Heavy Code

Before/After Sketches (Language-Agnostic)

Boundary Refinement (Data)

Before: functions accept RawInput and validate ad hoc
After:  parseRaw(...) -> ValidatedValue | Error
        core functions accept ValidatedValue only

Idempotency + Versioning (Concurrency/Protocol)

Before: handle(event) mutates state directly (retries duplicate side effects)
After:  if seen(event.id) return
        if event.version <= state.version return (or reject)
        apply(event) at a single atomic boundary (lock/txn/CAS)

Loop Invariant (Algorithm)

Before: comment says "array left side is partitioned"
After:  assert(invariant(state)) inside loop
        test: random arrays, shrink failing cases, compare to reference

Verification

Pick at least one signal and tie it to a specific invariant predicate.

Research Anchors (Mental Models, Not Requirements)

Output Contract (Required Headings)

Use these exact headings in the final response for this skill:

  1. Counterexample
  2. Invariants
  3. Owner and Scope
  4. Enforcement Boundary
  5. Seam (Before -> After)
  6. Verification
  7. Observability (optional)

Deliverable Checklist

  1. Counterexample: minimal breaking trace (include schedule/retry if relevant).
  2. Invariants: 1-5 predicates with owner + scope ("holds when").
  3. Enforcement Boundary: boundary/type/API/DB/lock/txn/protocol choice + why.
  4. Seam (Before -> After): minimal structural change that makes violations hard.
  5. Verification: property/stateful/stress/model/differential tied to at least one predicate.
  6. Observability (optional): tripwires/quarantine/metrics if rollout must be staged.

Cross-Coordination

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.