agentleFS
TrarothTraroth/claude-dev-framework/skills/jml-design/SKILL.md

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.

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
  1. Distinctive:

    When adding JML annotations to an existing class

    line 15
  2. Distinctive:

    When the user says "add JML", "write contracts", or "specify invariants"

    line 16
  3. Distinctive:

    Place the invariant block inside the class body, before the first field or constructor.

    line 35
  4. Very specific:

    All invariants in INVARIANTS.md must have a corresponding JML annotation in the code

    line 119

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  1. The class stub or source file
  2. The relevant section of INVARIANTS.md (if it exists)
  3. The class Javadoc (the informal contract)
  4. 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 == 0 for 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 >= 0
  • isEmpty() — ensures \result <==> size() == 0
  • contains() / containsKey() / containsValue() — relationship to other methods where expressible
  • get() — pre-conditions on index bounds, post-conditions on result
  • indexOf() / lastIndexOf() — result range and relationship to contains()

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()) for set())

Pay special attention to:

  • add / put — size increment, element now present
  • remove — size decrement, element now absent, return value equals removed element
  • clear — size() == 0
  • set / replace — size unchanged, element at position updated

5. View methods

  • keySet(), values(), entrySet() — result not null, size equals map size
  • inverse() — 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.md must 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:

  1. Invariants — list each class-level invariant
  2. Constructors — list contracts per constructor
  3. Methods — list contracts per method

Flag any inconsistency found between INVARIANTS.md and the code.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.