Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
.PHONY: test lint typecheck doctor package-check ci clean
.PHONY: test test-statechart lint typecheck doctor package-check ci clean

test:
uv run pytest -v --timeout=60 tests/
cd skills/poteto-mode/scripts && bun test

test-statechart:
node --test skills/statechart/scripts/test/pipeline.test.ts skills/statechart/scripts/test/messages.test.ts skills/statechart/scripts/test/chart.test.ts skills/statechart/scripts/test/cli.test.ts

lint:
uv run ruff check .
bash -n scripts/package-plugin.sh skills/poteto-mode/scripts/worktree-audit.sh skills/show-me-your-work/scripts/log.sh
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ Or trigger `/cloud-swarm` right in chat:
| [`/ketchup`](./skills/ketchup/SKILL.md) | you want a status brief under 100 words on an autonomous run or background task, with artifact links and selectable picks. |
| [`/create-verification-skill`](./skills/create-verification-skill/SKILL.md) | your project has no scripted way to prove app behavior. generates a project-local verify skill with a feature map, for any language or platform. |
| [`/create-formal-verification-skill`](./skills/create-formal-verification-skill/SKILL.md) | you need formal model checking (TLA+, Alloy, Dafny) for high-consequence concurrency, consensus, complex state machines, or critical parsers. |
| [`/maintain-formal-verification-skill`](./skills/maintain-formal-verification-skill/SKILL.md) | your project's formal verification model or harness has drifted from the code. diffs covered commits, updates from code, and proves with a scratch break. |
| [`/maintain-verification-skill`](./skills/maintain-verification-skill/SKILL.md) | your verify skill's feature map has drifted from the app. source wave + one live pass, at most one PR of proven corrections. |
| [`/benchmark-checklist`](./skills/benchmark-checklist/SKILL.md) | you are reporting performance numbers or speedups and want to check them against the Seven Performance Verification Questions first. |
| [`/unslop`](./skills/unslop/SKILL.md) | you're cleaning up writing. removes AI tells. |
Expand Down
25 changes: 17 additions & 8 deletions scripts/package-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ build_archive() {
-x "*.venv*" \
-x "*node_modules*" \
-x "*.test.ts" \
-x "*.test-helper.ts"
-x "*.test-helper.ts" \
-x "*/scripts/test/*" \
-x "*/scripts/test/"
printf '%s\n' "${archive}"
}

Expand All @@ -124,17 +126,24 @@ required = [
"agystack-models.md",
"agystack-runtime.json.example",
"hooks.json.example",
"skills/statechart/scripts/statechart",
"skills/statechart/scripts/statechart.ts",
"skills/statechart/scripts/pipeline.ts",
]
missing = [r for r in required if r not in names]
if missing:
raise SystemExit(f"Error: archive missing required files: {missing}")
forbidden = [
n for n in names
if n.endswith(".test.ts")
or n.endswith(".test-helper.ts")
or "__pycache__" in n.split("/")
or "node_modules" in n.split("/")
]
def is_forbidden(name: str) -> bool:
parts = name.split("/")
return (
name.endswith(".test.ts")
or name.endswith(".test-helper.ts")
or "__pycache__" in parts
or "node_modules" in parts
or any(parts[i : i + 2] == ["scripts", "test"] for i in range(len(parts) - 1))
)

forbidden = [n for n in names if is_forbidden(n)]
if forbidden:
raise SystemExit(f"Error: archive contains forbidden entries: {forbidden[:10]}")
' "${archive}"
Expand Down
78 changes: 53 additions & 25 deletions skills/create-formal-verification-skill/SKILL.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,69 @@
---
name: create-formal-verification-skill
description: "Generate and apply formal specification models (TLA+, Alloy, Dafny, or state-machine model checkers) strictly for high-consequence concurrency, distributed consensus, complex state machines, and parsers."
description: "Generate a project-local skill that formally verifies the code where a bug costs the most and tests reach the least, in any language, with whichever verification tool fits. Use for /create-formal-verification-skill, \"model-check this race\", \"prove this invariant\", or when concurrency, retries, state machines, parsers, or unsafe code need more than tests."
disable-model-invocation: true
---

# Create Formal Verification Skill
# Create a formal verification skill

Generate project-local formal verification specifications and model checkers for high-consequence algorithms. Formal methods verify invariants mathematically across entire state spaces. They carry high authoring and maintenance costs, so strict gating is mandatory.
A test checks the cases someone thought to write. Formal verification checks every case in a stated scope: every interleaving in a model, every input up to a bound, or every input. This skill finds the target in the repo where a bug costs the most, verifies its key invariant, and leaves a project-local skill that lets the next agent recheck changes cold, mid-task.

## Applicability Gating Criteria
## Choose the target from the code

Before authoring a formal specification or model checking harness, evaluate the target system against the gating criteria.
Answer from the codebase first, and ask the user only what you cannot observe. If the user named an area or bug, start there.

### Strictly Reserved Targets
Use this four-domain quick selector to gate formal methods against their maintenance cost:

Formal verification is strictly reserved for these high-consequence domains:
1. **Concurrency protocols:** Multi-threaded synchronization primitives, lockless data structures, and non-blocking algorithms where interleavings defy testing.
2. **Distributed consensus:** Raft, Paxos, leader election, quorum replication, and split-brain recovery protocols under network partitions.
3. **Complex state machines:** Multi-actor lifecycle transitions with concurrent events, timeout hazards, and asynchronous state resets.
4. **Critical parsers and serializers:** Untrusted input decoders, binary serialization boundaries, and cryptographic envelope validators where ambiguity introduces security vulnerabilities.
- **Concurrency protocols.** Synchronization primitives, lockless structures, and interleavings that tests miss.
- **Distributed consensus.** Leader election, quorum replication, split-brain recovery, and partition tolerance.
- **Complex state machines.** Multi-actor lifecycles with concurrent events, retries, timeouts, and asynchronous resets.
- **Critical parsers and serializers.** Untrusted input decoders, binary framing, and cryptographic envelope checks.

### Reject Non-Applicable Targets
If the target is routine CRUD endpoints, standard UI layouts and render loops, linear request handlers, or simple option parsers, reject formal verification and point to standard tests or [`/create-verification-skill`](../create-verification-skill/SKILL.md). For applicable work, pick the strongest promise whose violation harms users and defies unit tests, not the easiest module to model.

Immediately reject requests to formally verify non-applicable targets:
- Ordinary CRUD APIs and database mutation endpoints.
- Standard UI components, view layouts, styling systems, and render loops.
- Simple linear business logic and sequential request-response handlers.
- Routine configuration parsers, environment loaders, and CLI option parsing.
## Let the question choose the tool

When a target is non-applicable, reject formal verification immediately. Redirect to standard automated unit tests, integration harnesses, property-based testing, or verification skills (`/create-verification-skill`).
Pick the lowest-cost tool that answers the question:

## Authoring Process for Applicable Targets
- **Event ordering and concurrency.** Use a model checker over a faithful small model; TLA+ is the default in any language.
- **Input-level safety or data-structure invariants.** Use an SMT-backed verifier or prover that checks the real code (such as memory safety or overflow). If none exists for the language, test the real code with generated inputs instead of modeling a pure function by hand.
- **Unbounded size properties.** Use a proof assistant when no finite bound suffices.

When a target satisfies the gating criteria, proceed with model authoring:
Prefer a tool the repo's developers can install and run locally, and record why you chose it.

1. **Define state and actions.** Name state variables and state boundaries. Formulate explicit next-state relations.
2. **Specify safety invariants.** State properties that must never be violated (such as mutual exclusion or absence of deadlocks).
3. **Specify liveness properties.** State conditions that must eventually occur (such as request fulfillment or eventual consensus).
4. **Run model checker.** Model check finite state configurations to exhaustively search for counterexamples.
5. **Map counterexamples to code.** Translate any model checker counterexample directly into a reproducible unit test in the target codebase.
## What makes it good

- **Code-to-model traceability and indivisible step fidelity.** Every state, action, and rule in the model points to code a reviewer can open. What the verification treats as one indivisible step must be one indivisible step in the code. Use the repo's real symbol and module names.
- **Able to fail.** A check that has never failed proves nothing. Prove every property catches a broken variant (such as a removed guard or reordered step).
- **Findings stay findings.** When current code breaks a property, report the counterexample in the code's terms. Never weaken the property or model to force a pass, and never edit product code unless the user asks.
- **Honest about scope.** State the verified bounds, assumptions, and exclusions explicitly.
- **Readable without the tool.** State each property and its harm in one plain sentence, and narrate counterexamples as short steps in the code's words.
- **Cheap to rerun.** One command, pinned or reproducible tool versions, and fast execution so agents rerun it on relevant edits.
- **Kept in step with the code.** Record the coverage map (files and functions covered) and the sync-commit SHA where verification last matched the code.

## Generate the verify skill

Write a project-local skill (such as `.agents/skills/verify-<area>/SKILL.md`) with YAML frontmatter containing `name` and `description` so the skill registers.

From that skill alone, the next agent must be able to see whether an edit touches covered code, run the check, distinguish a code bug from a modeling error, and update the verification when behavior intentionally changes. Include:

- The **coverage map** (exact files, functions, bounds, and assumptions).
- The **sync-commit SHA** (`git rev-parse HEAD` once verified), with instructions to advance it only after confirming the verification still describes the code at the new commit.
- Real repo commands, paths, and identifiers with zero placeholders.

If the check uses a TLA+ model, direct the next agent to read every run with [`/statechart`](../statechart/SKILL.md) by name. It extracts shortest counterexample paths on failures and draws the state graph on passes. Never hardcode `/statechart`'s internal script flags or paths into the generated skill, because releases evolve independently.

## Prove it before you hand off

Run the generated skill's instructions end to end as the next agent would against a temporary scratch change in the real code that breaks the property. Confirm the check catches the break, then revert the scratch change and confirm the check returns to baseline (passing, or failing only on the findings you are reporting). If the skill misses the break or fails to run, fix the skill or verification, not the scratch change.

## Report and hand off

Write the full verification report to the Antigravity Brain Artifact `<appDataDir>/brain/<conversation-id>/formal_verification_report.md` (`ArtifactMetadata` with `UserFacing: true` and `RequestFeedback: false`). Record:

- Verified properties and harms in plain sentences.
- Tool choice rationale, bounds, assumptions, and exclusions.
- Findings and counterexamples in the code's terms.
- Coverage map, sync-commit SHA, rerun command, and the scratch-break mutation receipt.

In chat, summarize the result, name any close second target if you spotted one, link `[formal_verification_report.md](file://<appDataDir>/brain/<conversation-id>/formal_verification_report.md)`, and point the user to [`/maintain-formal-verification-skill`](../maintain-formal-verification-skill/SKILL.md) for catching future code drift.
60 changes: 60 additions & 0 deletions skills/maintain-formal-verification-skill/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: maintain-formal-verification-skill
description: "Bring a project's formal verification back in line with the code after the code changes: find the commits that touched verified code, update the model, harness, or properties to describe the code as it is now, rerun, and say whether each failure is drift in the verification or a bug in the code. Use for /maintain-formal-verification-skill, \"is the model still true to the code\", or after merges and refactors that touched verified code without rechecking it."
disable-model-invocation: true
---

# Maintain a formal verification skill

A formal check proves a property of what it describes. When the code changes and the verification does not, the check can keep passing while describing code that no longer exists. That pass is dangerous because it looks like a proof.

This skill is the upkeep loop for a project-local verify skill generated by [`/create-formal-verification-skill`](../create-formal-verification-skill/SKILL.md), or for any project-local skill that runs a model checker, prover, or code-level verifier against named code. The project-local skill handles a change made while using that skill. This skill handles changes that skipped it: merges, direct edits, and drift across many commits.

## Outcomes

Assign each check one outcome, and state it directly:

- **in sync.** No change since the last sync alters what the check describes, and the check passes.
- **updated.** The code changed, the verification now describes the new code, and the check passes.
- **bug.** The verification describes the current code, and the code breaks the property. This is a code finding, not drift.
- **blocked.** The check could not be brought back in line or could not run. State why.

A check can be both `updated` and `bug`: updating the verification makes it describe the current code again, and then the property fails on it.

## Edit scope

Edit only verification files: models, harnesses, property files, and the verify skill itself. Never edit product code during a run unless the user asks you to. When a property fails on the current code, do not weaken the property or the model to make it pass. Report the failure.

## Pass

1. **Find the checks.** A verify skill has no fixed name, so find each project-local skill (such as `.agents/skills/verify-*/SKILL.md`) that runs a model checker, prover, or verifier against named code. Read every check found, or the one the user named. Collect the property, the covered code, the bounds and assumptions, the run command, and the sync-commit SHA where the verification last matched the code. If no verify skill exists, stop and point to [`/create-formal-verification-skill`](../create-formal-verification-skill/SKILL.md). If the skill omits a sync commit, use the last commit that touched the verification files and record that fallback.

2. **Run it as it is.** Run each check once before editing anything and record the result. A pass here proves only that the old description holds, not that the code holds. A failure here can be drift or a bug. Defer classification until step 5.

3. **Read every change to covered code.** Diff the covered files from the sync commit to `HEAD`, and read every commit message. Inspect renamed, split, or relocated functions that came from covered code. Inspect new code that writes the same fields or enters the guarded state. Classify each change:
- **No effect.** Formatting, comments, or paths outside what the verification models. Verify this against the model or harness, not the commit message alone.
- **The verification no longer describes the code.** An indivisible step split into two, a branch changed, a guard moved, a new path reaches the guarded state, or a value's range changed. Update the model or harness.
- **The promise changed on purpose.** The change alters intended behavior, backed by doc comments, tests, changelog notes, or commit messages. Update the property and cite that evidence.
- **The promise may be broken.** Behavior changed without evidence of intent. Treat any resulting failure as a bug candidate.

4. **Update from the code, not from the result.** Update the model or harness so every changed part maps back to code a reviewer can open, preserving indivisible-step fidelity so one indivisible step in code stays one step in verification. Write the update from the code before rerunning, and never shape the model around what makes the check pass. Change a property only when the promise changed on purpose, recording the old wording, new wording, and evidence. Keep existing bounds unless the code change invalidates them; if you must shrink a bound, explain why in the report.

5. **Rerun and judge each result.** If the check is a TLA+ model, inspect every result with [`/statechart`](../statechart/SKILL.md).
- **Pass.** Prove the updated check can still fail. Introduce a temporary scratch break in the new code targeting what the property guards (such as removing a check or reordering a step), confirm the check catches it, and revert the scratch break.
- **Fail.** Replay the counterexample step by step against the real code. If a step is impossible in code, the verification has a modeling error; fix the verification and document what was wrong. If every step is reachable, report a bug: name the introducing commit, state the counterexample as steps in the code's terms, and state the harm in one sentence. Include a non-committed reproduction if one cheaply demonstrates the bug.

6. **Update the verify skill.** Update the coverage map (files and functions), commands, bounds, assumptions, and sync-commit SHA to the checked commit. Do not advance the sync commit for a `blocked` check, and note why. Run the verify skill once end to end as the next agent would to confirm its instructions still execute cleanly.

## Report

Write the full maintenance report to the Antigravity Brain Artifact `<appDataDir>/brain/<conversation-id>/formal_verification_report.md` (`ArtifactMetadata` with `UserFacing: true` and `RequestFeedback: false`). Include for each check:

- The outcome and the list of commits reviewed.
- Each change made to the verification and why (code shape changed, or promise changed on purpose with cited evidence).
- The rerun result and the scratch-break mutation receipt showing the updated check still catches failures.
- Each code bug in plain words: counterexample steps in the code's terms, harm in one sentence, and introducing commit SHA.
- Remaining coverage gaps, including new code that touches guarded state but stays unverified.

State explicitly which prior failures were verification drift and which were product bugs. If a check passed before your update and fails afterward, state that the earlier pass held only on a stale description.

Keep verification updates in their own commit, separate from any product fix. In chat, summarize the outcomes and link `[formal_verification_report.md](file://<appDataDir>/brain/<conversation-id>/formal_verification_report.md)` instead of pasting the full report.
Loading
Loading