From AI-generated to AI-engineered code. Guides AI agents to write verifiable code through contracts and structured workflows.
<p align="center">
<img src="docs/logo.svg" alt="Invar Logo" width="128" height="128">
</p>
<h1 align="center">Invar</h1>
<p align="center">
<strong>From AI-generated to AI-engineered code.</strong>
</p>
<p align="center">
Invar brings decades of software engineering best practices to AI-assisted development.<br>
Through automated verification, structured workflows, and proven design patterns,<br>
agents write code that's correct by constructionβnot by accident.
</p>
<p align="center">
<a href="https://badge.fury.io/py/invar-tools"><img src="https://badge.fury.io/py/invar-tools.svg" alt="PyPI version"></a>
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.11+-blue.svg" alt="Python 3.11+"></a>
<a href="#license"><img src="https://img.shields.io/badge/License-Apache%202.0%20%2B%20GPL--3.0-blue.svg" alt="License"></a>
</p>
<p align="center">
<a href="#why-invar"><img src="https://img.shields.io/badge/π€_Dogfooding-Invar's_code_is_100%25_AI--generated_and_AI--verified_using_itself-8A2BE2?style=for-the-badge" alt="Dogfooding"></a>
</p>
### What It Looks Like
An AI agent, guided by Invar, writes code with formal contracts and built-in tests:
```python
from invar_runtime import pre, post
@pre(lambda items: len(items) > 0)
@post(lambda result: result >= 0)
def average(items: list[float]) -> float:
"""
Calculate the average of a non-empty list.
>>> average([1.0, 2.0, 3.0])
2.0
>>> average([10.0])
10.0
"""
return sum(items) / len(items)
```
Invar's Guard automatically verifies the codeβthe agent sees results and fixes issues without human intervention:
```
$ invar guard
Invar Guard Report
========================================
No violations found.
----------------------------------------
Files checked: 1 | Errors: 0 | Warnings: 0
Contract coverage: 100% (1/1 functions)
Code Health: 100% ββββββββββββββββββββ (Excellent)
β Doctests passed
β CrossHair: no counterexamples found
β Agent that generates comprehensive documentation, API references, architecture diagrams, and developer onboarding guides from existing code.
Agent configuration for systematic bug investigation that traces issues from error logs through the codebase to root cause with suggested fixes.
Agent for integrating third-party APIs including SDK setup, type generation, error handling, retry logic, and rate limit management.
Cursor's built-in autonomous coding agent that can make multi-file edits, run terminal commands, search the codebase, and iteratively build features with minimal human intervention.
Cloud-based autonomous coding agent that runs in the background on remote sandboxed environments, handling complex multi-step tasks while you continue working.
Cursor's multi-file editing agent within Composer mode that can create, edit, and delete files across your entire project in a single conversation.