contracts

contracts is a command for coding agents from punt-labs/z-spec. It costs 17 tokens per session (7,218 once invoked), scanned A, a copy of contracts-dev, MIT.

A command that generates runtime checks from a Z specification, including preconditions, postconditions, and state invariants. These checks verify that running code follows the rules described by the specification.

In plain words
What is it for?
Use it with Swift, TypeScript, Python, or Kotlin specifications. It can generate invariant-only checks, before-and-after wrappers, or no-operation stubs for production builds.
Why use it?
It turns formal rules into assertions that can catch invalid states or operations while the program runs, instead of allowing errors to go unnoticed.

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/contracts
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 contracts

README.md
[![agentmods](https://agentmods.dev/badge/commands/punt-labs/z-spec/contracts.svg)](https://agentmods.dev/commands/punt-labs/z-spec/contracts)
Your own site
<a href="https://agentmods.dev/commands/punt-labs/z-spec/contracts"><img src="https://agentmods.dev/badge/commands/punt-labs/z-spec/contracts.svg" alt="Measured on agentmods" height="20"></a>
Per session 17 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 7,218 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin 98% copy Near-identical to another mod 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.00017 $0.07218
Opus 5 $0.00009 $0.03609
Sonnet 5 $0.00003 $0.01444
Haiku 4.5 $0.00002 $0.00722

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

Security

Grade A, and why

contracts 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 4d 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.

Origin

This is a copy

98% identical to contracts-dev — 34 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

plugin/commands/contracts.md · 938 lines

How it starts

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

/z-spec:contracts - Generate Runtime Contracts

Generate runtime precondition, postcondition, and invariant assertion functions in the target language from Z schemas. Unlike /z-spec:model2code which generates implementation code, this command generates checks -- assertion functions that verify spec conformance at runtime.

Contracts are the executable bridge between specification and implementation. They encode Z predicates as runtime assertions so that violations are caught immediately rather than silently corrupting state.

Input

Arguments: $ARGUMENTS

Parse arguments:

  • First positional argument: Z specification file (default: search docs/*.tex)
  • Second positional argument or auto-detect: target language (swift, typescript, python, kotlin)
  • --invariants-only: generate only state invariant checks (no operation contracts)
  • --wrap: also generate wrapper functions with before/after assertion sandwiches
  • --strip: emit no-op stubs (empty function bodies) for production builds

Process

0. Prerequisites

The specification should exist and be type-checked. If the spec has not been checked, suggest running /z-spec:check first but do not block -- contracts can still be generated from a syntactically valid spec.

Verify fuzz is available for type-checking:

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

If fuzz is found, run a type-check to confirm the spec is valid:

fuzz -t <spec.tex>

If fuzz reports errors, warn the user but continue. Contract generation does not require a passing type-check, but the generated assertions may reference invalid types.

No other external tools are needed.

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.

2. Detect Target Language

If a language is explicitly provided as the second argument, use it.

Read the full file on GitHub · 938 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. 4d ago First seen · 938 lines · 17 tokens per session scan A 58d8a4a9300d

Subscribe to this mod's changes

contracts is a command published in the GitHub repository punt-labs/z-spec (5 stars, last pushed yesterday), licensed MIT. It adds 17 tokens to every session and 7,218 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. It is 98% identical to contracts-dev, differing in 34 lines, and is treated as a copy.