design-by-contract
Automated contract verification, detection, and remediation across multiple languages using formal preconditions, postconditions, and invariants. This skill provides both reference documentation AND execution capabilities for the full PLAN -> CREATE -> VERIFY -> REMEDIATE workflow.
Install / Use
npx skills add Microck/ordinary-claude-skills --skill design-by-contractInstalls into whichever agent you are using.
SKILL.md
Installable skill definition
Quality Score
Category
AutomationSupported Platforms
Our assessment of design-by-contract
design-by-contract scores 83/100 on our quality scale, 2134th of 2,885 Automation skills we index.
Its SKILL.md is 31 KB long, well organised into 141 sections with 57 code examples: a thorough specification that gives an agent plenty to work with.
It has 399 GitHub stars, a meaningful sign that others use it.
Maintenance, license and trust
- The repository was last updated 30 days ago, so design-by-contract is actively maintained.
- No license is declared. By default that means all rights are reserved: you can read it, but reusing or redistributing it is not clearly permitted. Ask the author before building on it commercially.
- Its trust signals score 88/100, with 1 caution from licensing, adoption, age or documentation. These come from repository metadata, not a code audit — read the skill file before letting an agent act on it.
design-by-contract compared with similar skills
All 4 of these similar skills score higher than design-by-contract; compare them before choosing.
| Skill | Score | Stars | Updated | Format |
|---|---|---|---|---|
| design-by-contract (this skill)by Microck | 83 | 399 | 30d ago | SKILL.md |
| Agent-Reachby Panniantong | 100 | 92.4k | 21d ago | CLAUDE.md |
| Scraplingby D4Vinci | 100 | 86.0k | today | MCP Server |
| rufloby ruvnet | 100 | 74.0k | today | MCP Server |
| algorithmic-artby anthropics | 100 | 177.9k | 14d ago | SKILL.md |
Frequently asked questions
- How do I install design-by-contract?
- Run
npx skills add Microck/ordinary-claude-skills --skill design-by-contract. The install tabs above show the steps for each supported agent. - Which AI agents does design-by-contract work with?
- It is written for Universal, as a SKILL.md file. Other agents that read the same format can often use it too.
- Is design-by-contract safe to use?
- It declares no license and scores 88/100 on trust signals. Skills are instructions an agent will follow, so read the file before installing it and do not approve commands you do not understand.
- Is design-by-contract still maintained?
- The repository was last updated 30 days ago, so design-by-contract is actively maintained.
Skill content
View source on GitHubname: design-by-contract description: Automated contract verification, detection, and remediation across multiple languages using formal preconditions, postconditions, and invariants. This skill provides both reference documentation AND execution capabilities for the full PLAN -> CREATE -> VERIFY -> REMEDIATE workflow.
Design-by-Contract Development Skill
Capability
Design-by-Contract (DbC) is a programming methodology that uses formal specifications (contracts) to define component behavior. This skill enables:
- Contract Design: Plan preconditions, postconditions, and invariants before implementation
- Artifact Generation: Create contract annotations across 8+ languages
- Verification: Run contract validation with appropriate runtime flags
- Remediation: Fix contract violations with targeted debugging
Core Contract Types:
- Preconditions: What must be true before a function executes (caller's duty)
- Postconditions: What must be true after a function executes (callee's promise)
- Invariants: What must always be true about object state
When to Use
Design-by-Contract is ideal for:
- Public API boundaries: Validate inputs at module boundaries
- Critical business logic: Ensure computation correctness
- State management: Maintain object consistency
- Integration points: Verify data crossing system boundaries
- Team collaboration: Document expected behavior formally
Workflow Overview
[<start>Requirements] -> [Phase 1: PLAN]
[Phase 1: PLAN|
Identify contracts
Design predicates
Map obligations
] -> [Phase 2: CREATE]
[Phase 2: CREATE|
Generate annotations
Add to .outline/contracts/
Wire dependencies
] -> [Phase 3: VERIFY]
[Phase 3: VERIFY|
Enable runtime flags
Run test suite
Check violations
] -> [Phase 4: REMEDIATE]
[Phase 4: REMEDIATE|
Diagnose violation type
Fix caller/callee/state
Re-verify
] -> [<end>Success]
Verification Hierarchy
Principle: Use compile-time verification before runtime contracts. If a property can be verified statically, do NOT add a runtime contract for it.
Static Assertions (compile-time) > Test/Debug Contracts > Runtime Contracts
When to Use Each Level
| Property | Static | Test Contract | Debug Contract | Runtime Contract |
|----------|--------|---------------|----------------|------------------|
| Type size/alignment | static_assert (C++), assert_eq_size! (Rust) | - | - | - |
| Trait/interface bounds | assert_impl_all! (Rust), Concepts (C++) | - | - | - |
| Const value bounds | const_assert!, static_assert | - | - | - |
| Null/type safety | Type checker (tsc/pyright/kotlinc) | - | - | - |
| Exhaustiveness | Pattern matching + never/Never | - | - | - |
| Expensive O(n)+ checks | - | test_ensures | - | - |
| Reference impl equivalence | - | test_ensures | - | - |
| Internal state invariants | - | - | debug_invariant | - |
| Development preconditions | - | - | debug_requires | - |
| Public API input validation | - | - | - | requires |
| Safety-critical postconditions | - | - | - | ensures |
| External/untrusted data | - | - | - | Required (Zod/icontract) |
Legend: - = Do not use for this property
Decision Flow
Can type system encode it? ──yes──> Use types (typestate, newtype)
│no
v
Verifiable at compile-time? ──yes──> static_assertions / const_assert!
│no
v
Expensive O(n)+ check? ──yes──> test_* (test builds only)
│no
v
Internal development aid? ──yes──> debug_* (debug builds only)
│no
v
Must enforce in production? ──yes──> Runtime contracts
│no
v
Consider if check is needed at all
Phase 1: PLAN (Contract Design)
Process
-
Understand Requirements
- Parse user's task/requirement
- Identify preconditions, postconditions, invariants
- Use sequential-thinking to decompose contract obligations
- Map requirements to contract types
-
Artifact Detection (Conditional)
- Check for existing contract artifacts by language:
# Rust (contracts crate) rg '#\[pre\(|#\[post\(|#\[invariant\(' $ARGUMENTS # TypeScript (Zod) rg 'z\.object|z\.string|\.refine\(' $ARGUMENTS # Python (icontract) rg '@pre\(|@post\(|@invariant\(' $ARGUMENTS # Java/Kotlin rg 'checkArgument|checkState|require\s*\{' $ARGUMENTS - If artifacts exist: analyze coverage gaps, plan extensions
- If no artifacts: proceed to design contract architecture
- Check for existing contract artifacts by language:
-
Design Contract Architecture
- Design precondition predicates
- Plan postcondition guarantees
- Define class/module invariants
- Output: Contract design with annotation signatures
-
Prepare Run Phase
- Define target:
.outline/contracts/ - Specify verification: language-specific contract checking
- Create traceability: requirement -> contract -> enforcement
- Define target:
Thinking Tool Integration
Use sequential-thinking for:
- Contract decomposition
- Obligation ordering
- Inheritance chain planning
Use actor-critic-thinking for:
- Contract strength evaluation
- Precondition completeness
- Postcondition sufficiency
Use shannon-thinking for:
- Contract coverage gaps
- Runtime verification costs
- Weakest precondition analysis
Contract Design Templates
Rust (contracts crate)
// Target: .outline/contracts/{module}_contracts.rs
// From requirement: {requirement text}
#[pre(input > 0, "Input must be positive")]
#[post(ret.is_some() => ret.unwrap() > input)]
fn process(input: i32) -> Option<i32> {
// Implementation in run phase
}
// Class invariant
#[invariant(self.balance >= 0)]
impl Account {
// Methods maintain invariant
}
TypeScript (Zod)
// Target: .outline/contracts/{module}.contracts.ts
// From requirement: {requirement text}
const InputSchema = z.object({
value: z.number().positive("Value must be positive"),
}).refine(
(data) => /* precondition */,
{ message: "Precondition: {description}" }
);
// Postcondition validator
const OutputSchema = z.object({
result: z.number(),
}).refine(
(data) => /* postcondition */,
{ message: "Postcondition: {description}" }
);
Python (icontract)
# Target: .outline/contracts/{module}_contracts.py
# From requirement: {requirement text}
@icontract.require(lambda x: x > 0, "Input must be positive")
@icontract.ensure(lambda result: result is not None)
def process(x: int) -> Optional[int]:
# Implementation in run phase
pass
Plan Output
-
Requirements Analysis
- Preconditions identified
- Postconditions guaranteed
- Invariants to maintain
-
Contract Architecture
- Contract signatures per function/method
- Invariant definitions per class/module
- Inheritance contract chains
-
Target Artifacts
.outline/contracts/*file list- Contract library dependencies
- Runtime flag configuration
-
Verification Commands
- Build with contracts enabled
- Test suite exercising contracts
- Success criteria: no contract violations
Phase 2: CREATE (Generate Artifacts)
Setup
# Create .outline/contracts directory
mkdir -p .outline/contracts
Generate Contract Files by Language
Rust (contracts crate)
// .outline/contracts/{module}_contracts.rs
// Generated from plan design
use contracts::*;
// Source Requirement: {traceability from plan}
// Precondition: {from plan design}
// Postcondition: {from plan design}
#[pre(input > 0, "Input must be positive")]
#[post(ret.is_some() => ret.unwrap() > input, "Output must exceed input")]
pub fn process(input: i32) -> Option<i32> {
// Implementation
Some(input + 1)
}
// Class invariant: {from plan design}
#[invariant(self.balance >= 0, "Balance must be non-negative")]
impl Account {
#[post(self.balance == old(self.balance) + amount)]
pub fn deposit(&mut self, amount: u64) {
self.balance += amount;
}
}
TypeScript (Zod)
// .outline/contracts/{module}.contracts.ts
// Generated from plan design
import { z } from 'zod';
// Source Requirement: {traceability from plan}
// Precondition schema: {from plan design}
export const InputSchema = z.object({
value: z.number().positive("Value must be positive"),
name: z.string().min(1, "Name required"),
}).refine(
(data) => data.value < 1000,
{ message: "Precondition: value must be under 1000" }
);
// Postcondition schema: {from plan design}
export const OutputSchema = z.object({
result: z.number(),
success: z.boolean(),
}).refine(
(data) => data.success || data.result === 0,
{ message: "Postcondition: failed operations must return 0" }
);
// Validation wrapper
export function withContracts<I, O>(
inputSchema: z.ZodType<I>,
outputSchema: z.ZodType<O>,
fn: (input: I) => O
): (input: I) => O {
return (input: I) => {
const validInput = inputSchema.parse(input);
const output = fn(validInput);
return outputSchema.parse(output);
};
}
Python (icontract)
# .outline/contracts/{module}_contracts.py
# Generated from plan design
import icontract
# Source Requirement: {traceability from plan}
# Precondition: {from plan design}
# Postcondition: {from plan design}
@icontract.require(lambda x: x > 0, "Input must be positive")
@icontract.ensure(lambda result: result is not None, "Must return value")
@icontract.ensure(lambda x, result: result > x, "Output must exceed input")
def process(x: int) -> int:
return x + 1
# Class invariant: {from plan design}
@icontract.invariant(lambda self: self.balance >= 0)
class Account:
def __init__(self):
self.balance = 0
@icontract.require(lambda amount: amount > 0)
@icontract.ensure(lambda self, amount, OLD: self.balance == OLD.balance + amount)
def deposit(self, amount: int) -> None:
self.balance += amount
Phase 3: VERIFY (Contract Validation)
Rust
# Ensure contracts are enabled (not disabled)
unset CONTRACTS_DISABLE
# Verify contracts exist
rg '#\[pre\(|#\[post\(|#\[invariant\(' .outline/contracts/ || exit 12
# Run tests with contracts
cargo test || exit 13
TypeScript
# Verify Zod schemas exist
rg 'z\.object|\.refine\(' .outline/contracts/ || exit 12
# Run tests (Zod validates at runtime)
npx vitest run || exit 13
Python
# Enable thorough contract checking
export ICONTRACT_SLOW=true
# Verify decorators exist
rg '@icontract\.(require|ensure|invariant)' .outline/contracts/ || exit 12
# Run tests
pytest || exit 13
Java (Guava)
# Verify Guava preconditions exist
rg 'checkArgument|checkState|checkNotNull' .outline/contracts/ || exit 12
# Run tests
mvn test || exit 13
C++ (GSL/Boost)
# Ensure NDEBUG is NOT set for contract checking
unset NDEBUG
# Verify contracts exist
rg 'Expects\(|Ensures\(' .outline/contracts/ || exit 12
# Build and test
cmake --build build && ./build/tests || exit 13
Phase 4: REMEDIATE (Fix Violations)
Contract Violation Types
| Violation | Exit Code | Fix Strategy | |-----------|-----------|--------------| | Precondition | 1 | Fix caller to meet requirements | | Postcondition | 2 | Fix implementation to meet guarantee | | Invariant | 3 | Fix state management logic |
Debugging by Violation Type
Precondition Violation (Caller's fault)
# Error: icontract.ViolationError: Pre: x > 0
# The CALLER passed invalid input
# Debug: Check call site
# Before:
result = process(-5) # WRONG: violates x > 0
# After:
if x > 0:
result = process(x)
else:
handle_invalid_input(x)
Postcondition Violation (Callee's fault)
# Error: icontract.ViolationError: Post: result > x
# The IMPLEMENTATION doesn't meet its guarantee
# Debug: Fix the function
# Before:
@icontract.ensure(lambda x, result: result > x)
def
Truncated for display — read the full file on GitHub.
Related Skills
Agent-Reach
92.4kGive your AI agent eyes to see the entire internet. Read & search Twitter, Reddit, YouTube, GitHub, Bilibili, XiaoHongShu — one CLI, zero API fees.
Scrapling
86.0k🕷️ An adaptive Web Scraping framework that handles everything from a single request to a full-scale crawl! Don't be shy, join here: https://discord.gg/EMgGbDceNQ and follow here for daily tips and tricks: https://x.com/Scrapling_dev
ruflo
74.0k🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
algorithmic-art
177.9kCreating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems.
Languages
Trust signals
From repository metadata: license, adoption, age and documentation. Not a code audit — see the Safety scan above for what the skill file itself contains.
