refine

refine is a command for coding agents from punt-labs/z-spec. It costs 14 tokens per session (10,560 once invoked), scanned A, original, MIT.

A refinement-checking command that compares implementation code with a Z specification using an abstraction function. An abstraction function maps concrete program data to the abstract state described by the specification.

In plain words
What is it for?
Use it to generate abstraction-function scaffolding, commutativity tests, and optionally Lean 4 proofs for an implementation.
Why use it?
It checks whether each implementation operation behaves like the corresponding specified operation, exposing mismatches between the model and the code.

Command

Part of the z-spec-dev plugin — 42 commands, 1 hook shipped together

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/punt-labs/z-spec/refine
Clone the repo
git clone --depth 1 https://github.com/punt-labs/z-spec

Or install z-spec-dev, the plugin that ships this one along with the rest of its 42 commands, 1 hook.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for refine

README.md
[![agentmods](https://agentmods.dev/badge/commands/punt-labs/z-spec/refine.svg)](https://agentmods.dev/commands/punt-labs/z-spec/refine)
Your own site
<a href="https://agentmods.dev/commands/punt-labs/z-spec/refine"><img src="https://agentmods.dev/badge/commands/punt-labs/z-spec/refine.svg" alt="Measured on agentmods" height="20"></a>
Per session 14 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 10,560 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00014 $0.10560
Opus 5 $0.00007 $0.05280
Sonnet 5 $0.00003 $0.02112
Haiku 4.5 $0.00001 $0.01056

Measured 5d ago against content hash b73dd912d8e7, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

refine scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugin/commands/refine.md · 1,533 lines

How it starts

The opening of the file, as written. The whole thing — 1,533 lines — stays where its author put it; the contents beside it link to each section on GitHub.

/z-spec:refine - Data Refinement Verification

Verify that implementation code correctly refines a Z specification by defining an abstraction function and generating commutativity tests (and optionally Lean 4 proofs) for every operation.

The key correctness property for each operation:

abstract(concreteOp(concreteState)) = abstractOp(abstract(concreteState))

If this holds for every operation, the code is a provably correct refinement of the specification.

Input

Arguments: $ARGUMENTS

Parse arguments:

  • First positional argument: Z specification file (default: search docs/*.tex)
  • Second positional argument: target language (default: auto-detect)
  • --lean - also generate Lean 4 commutativity proofs in proofs/
  • --generate-abstraction - auto-generate abstraction function scaffold (otherwise walk the user through defining it interactively)
  • --impl <file> - path to implementation file (default: auto-detect from project)

Process

0. Prerequisites

Verify the specification has been type-checked:

which fuzz >/dev/null 2>&1 || echo "FUZZ_NOT_FOUND"

If fuzz is not found: Warn but do not block. The refinement process can proceed without type-checking, but recommend running /z-spec:check first.

If --lean is specified, verify Lean 4 and Lake are installed:

which lean >/dev/null 2>&1 || echo "LEAN_NOT_FOUND"
which lake >/dev/null 2>&1 || echo "LAKE_NOT_FOUND"

If lean or lake not found: Stop and tell the user:

Lean 4 is not installed. Run /z-spec:setup lean to install the Lean 4 toolchain via elan. Or omit --lean to generate commutativity tests only.

The Z specification should already exist. Implementation code should also exist (from /z-spec:model2code or hand-written).

1. Locate the Specification

If a file path is provided, use it directly.

If no file specified:

  • Look in docs/ for .tex files containing Z specifications
  • If multiple found, ask user to specify

Read the specification file.

Read the full file on GitHub · 1,533 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 1,533 lines · 14 tokens per session scan A b73dd912d8e7

Subscribe to this mod's changes

refine is a command published in the GitHub repository punt-labs/z-spec (5 stars, last pushed yesterday), licensed MIT. It adds 14 tokens to every session and 10,560 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.