jml-design
Skill1 starsChanged 7 months agoMITView on GitHub
Write JML specifications (invariants, requires, ensures) for a class in the project. Use this skill during step 2 of the workflow (stub + contracts) or when adding JML annotations to an existing class. The goal is to produce a complete, consistent, and verifiable formal contract before implementation.
In this repository12 other files it gives its agents.
- api-consistency-checkSkill
- architecture-drift-checkSkill
- design-reviewSkill
- jml-completeness-checkSkill
- jml-conformance-checkSkill
- jml-test-generationSkill
- new-classSkill
- refactor-classSkill
- static-analysisSkill
- test-coverage-reviewSkill
- update-backlogSkill
- update-readmeSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
When adding JML annotations to an existing class
- Distinctive: line 16
When the user says "add JML", "write contracts", or "specify invariants"
- Distinctive: line 35
Place the invariant block inside the class body, before the first field or constructor.
- Very specific: line 119
All invariants in INVARIANTS.md must have a corresponding JML annotation in the code
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
JML Design
When to run
- During step 2 of the workflow (stub class + JML specifications)
- When adding JML annotations to an existing class
- When the user says "add JML", "write contracts", or "specify invariants"
Inputs
Before starting, read:
- The class stub or source file
- The relevant section of
INVARIANTS.md(if it exists) - The class Javadoc (the informal contract)
- The corresponding interface (if the class implements one)
Specification checklist
1. Class-level invariants (/*@ ... @*/)
Place the invariant block inside the class body, before the first field or constructor.
- Size consistency —
size() >= 0, and relationship to internal storage - Null handling — whether null elements/keys/values are allowed or forbidden
- Ordering — if the structure maintains order, express the sort invariant
- Uniqueness — if duplicates are forbidden, express it
- Bijectivity — for bijective structures, express the forward/reverse mapping consistency
- Configuration — non-null constraints on configurable fields (strategies, comparators, etc.)
2. Constructor contracts (//@ ensures)
Each constructor must specify:
- Post-conditions on
size()(typically== 0for empty constructors) - Post-conditions on configuration (initial capacity, strategies, etc.)
- Pre-conditions (
//@ requires) for parameters with constraints - For copy constructors:
size() == other.size()and element equality
3. Query method contracts
size()—ensures \result >= 0isEmpty()—ensures \result <==> size() == 0contains()/containsKey()/containsValue()— relationship to other methods where expressibleget()— pre-conditions on index bounds, post-conditions on resultindexOf()/lastIndexOf()— result range and relationship tocontains()
4. Mutation method contracts
These are the most important contracts. For each mutation method:
- Pre-conditions (
//@ requires) — parameter constraints, index bounds, null rejection - Post-conditions (
//@ ensures) — size change, element presence/ absence, return value - Frame conditions — what is not changed (e.g.
size() == \old(size())forset())
Pay special attention to:
add/put— size increment, element now presentremove— size decrement, element now absent, return value equals removed elementclear—size() == 0set/replace— size unchanged, element at position updated
5. View methods
keySet(),values(),entrySet()— result not null, size equals map sizeinverse()— result not null, size preserved, mapping inverted
JML syntax reference
// Class-level invariant block (inside class body, before first field)
/*@
@ public invariant size() >= 0;
@ public invariant (\forall int i; 0 <= i && i < size(); get(i) != null);
@*/
// Method-level annotations (before method declaration, after Javadoc)
//@ requires index >= 0 && index < size();
//@ ensures \result != null;
//@ ensures size() == \old(size());
// Quantifiers
//@ ensures (\forall int i; 0 <= i && i < size(); get(i) != null);
//@ ensures (\exists int i; 0 <= i && i < size(); get(i).equals(o));Consistency rules
- All invariants in
INVARIANTS.mdmust have a corresponding JML annotation in the code - JML annotations must not reference private fields — use public methods only
- Pre-conditions must match the exceptions documented in Javadoc
- Post-conditions must be verifiable through the public API
- Synchronized variants must have the same contracts as their unsynchronized counterparts
Output format
Report the annotations added, grouped by category:
- Invariants — list each class-level invariant
- Constructors — list contracts per constructor
- Methods — list contracts per method
Flag any inconsistency found between INVARIANTS.md and the code.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

