Skip to main content

Intent contract tagging, validation and semantic mapping for codebases.

Project description

Intract

AI Cost Tracking

PyPI Version Python License AI Cost Human Time Model

  • 🤖 LLM usage: $2.6414 (15 commits)
  • 👤 Human dev: ~$849 (8.5h @ $100/h, 30min dedup)

Generated on 2026-06-01 using openrouter/qwen/qwen3-coder-next


Intract is an intent-contract layer for codebases and software delivery artifacts.

It lets you describe, validate and monitor intent across:

code
functions
classes
files
project manifests
API endpoints
Dockerfiles
CI/CD workflows
Kubernetes manifests
DevOps artifacts

Intract is not primarily a programming language. It is a contract system for short, portable intent declarations.

Quick example

# Comment form (all supported languages)
# @intract.v1 scope:function intent:validate:user_permission priority:1 domain:security input:user,resource output:allowed effect:none forbid:write,network validate:input_presence,return_value,no_forbidden_effect meaning:"check whether user can modify resource without changing state"
def can_update_resource(user, resource):
    return user.is_admin or resource.owner_id == user.id

Decorator form (same contract model, no comment prefix):

@intract.v1 id:safe-decoder scope:function intent:decode:header domain:security forbid:unsafe
pub fn decode_header(raw_data: &[u8]) -> Header {
    // ...
}

Rust attributes are also accepted: #[intract.v1 id:safe-decoder intent:decode:header forbid:unsafe].

Run:

python -m intract scan .
python -m intract validate .

Practical usage (small and large projects)

Poniżej gotowe wzorce użycia, które możesz pokazać zespołowi jako „jak to działa w praktyce”.

1) Mały projekt (1 repo, 1-3 usług)

Cel: szybko pilnować intencji funkcji i nie spowalniać developmentu.

Przykładowe technologie:

  • Python API (@intract.v1 nad funkcjami serwisowymi)
  • TypeScript frontend (kontrakty ui.*, validate.*)
  • Dockerfile (kontrakty deploy, np. forbid:root_user)

Workflow:

# lokalnie podczas developmentu
python -m intract validate .
python -m intract check --staged --hunks

# szybki podgląd pokrycia i duplikatów intencji
python -m intract coverage .
python -m intract duplicates . --threshold 0.8

2) Duży projekt (monorepo, wiele zespołów)

Cel: rozdzielić intencje na domeny i mieć osobne bramki jakości.

Przykładowe technologie w 1 monorepo:

  • Backend: Python + Java + Go
  • Frontend: TypeScript
  • Platforma: Dockerfile, Kubernetes, GitHub Actions/OpenAPI

Workflow:

# pełna walidacja release branch
python -m intract validate . --manifest intract.yaml

# raport do security/code scanning
python -m intract check . --format sarif --output intract.sarif

# graf zależności intencji i braków require
python -m intract graph . --format mermaid

Fokus na kategorie intencji (dev vs CI/CD)

Najpraktyczniej mieć osobne manifesty lub sekcje dla różnych etapów pracy:

  • intract.dev.yaml → fokus na poprawność funkcji (domain:app, domain:logic)
  • intract.ci.security.yaml → fokus na bezpieczeństwo (domain:security, forbid:network/write/unsafe)

Przykład uruchamiania:

# development: sprawdzamy głównie intencje funkcji
python -m intract validate . --manifest intract.dev.yaml

# CI/CD: sprawdzamy głównie bezpieczeństwo i artefakty dostarczeniowe
python -m intract validate . --manifest intract.ci.security.yaml
python -m intract scan . --all-artifacts --json

W praktyce daje to możliwość „przełączania radaru”:

  • dev: czy funkcja robi to, co obiecuje (intent, input/output, return)
  • CI/CD: czy release spełnia polityki bezpieczeństwa (network, secrets, root, workflow)

Automatyczne generowanie intencji

Intract wspiera generowanie kontraktów automatycznie (LLM i engine):

# 1) propozycje kontraktów z konkretnego pliku (LLM)
python -m intract propose llm --file src/auth.py --goal "RBAC without network side effects"

# 2) sugestie engine dla projektu
python -m intract engine suggest .

# 3) walidacja po zaakceptowaniu propozycji
python -m intract validate .

Wskazówka: zacznij od małej liczby kontraktów (kluczowe funkcje), potem rozszerzaj obszary.

Greenfield demo: NLP -> Intract -> Code

Poniższy scenariusz pokazuje start od zera dla nowej aplikacji.

Krok 1: Nowy projekt

mkdir my-app && cd my-app
python -m venv .venv
source .venv/bin/activate
pip install intract
python -m intract init .

Krok 2: Opis celu językiem naturalnym (NLP)

Przykład celu:

"Zbuduj API do zarządzania zadaniami. Endpoint create-task ma walidować input, nie może robić zewnętrznych wywołań sieciowych i ma zwracać jawny status."

Krok 3: Wygeneruj kontrakty z NLP na kod

Tworzysz szkic pliku (src/tasks.py) i prosisz Intract/LLM o propozycje:

python -m intract propose llm --file src/tasks.py --goal "task API: validate input, no network, explicit status"

Wynik to linie @intract.v1 ..., które możesz wkleić nad funkcje lub przenieść do manifestu Toon/YAML.

Krok 4: Implementuj kod pod kontrakty

Implementujesz funkcje zgodnie z intencją, np.:

  • intent:create:task
  • forbid:network
  • validate:input_presence,return_value

Krok 5: Pętla deweloperska i CI

# lokalnie
python -m intract check --staged --hunks

# w CI
python -m intract validate .
python -m intract check . --format sarif --output intract.sarif

Efekt: flow przechodzi od wymagań NLP, przez kontrakty intencji, do kodu i automatycznej walidacji jakości.

External Target Addressing (Toon Manifests)

In addition to inline annotations, Intract supports two ways of defining quality gates and intent contracts:

  1. Inline Comments: Using @intract.v1 in source files (with #, //, --, or HTML comment prefixes).
  2. Inline Decorators: Bare @intract.v1 ... lines or Rust #[intract.v1 ...] attributes on the line above the governed block.
  3. External manifests (Toon Manifests): Decoupled files (.toon or intract.toon.yaml) that specify precise coordinates (targets) for files, functions, lines, and XPaths.

1. Płaski format URI linia po linii (.toon)

Pliki .toon używają struktury URI do prostego i przejrzystego przypisywania kontraktów na poziomie konkretnych linii, funkcji lub selektorów:

# Flat target-based URI rules
intract://src/calc.py?func=add#id=pure-addition&intent=pure-add&forbid=write
intract://src/calc.py?func=write_to_log&line=13#id=log-write&intent=write-log&require=write

2. Manifest YAML z targetowaniem (intract.toon.yaml)

Możesz również zdefiniować zasady w formacie YAML, podając sekcję target:

version: intract.v1
contracts:
  - id: addition-check
    intent: pure:addition
    forbid: [write]
    target:
      file: src/calc.py
      function: add

Więcej informacji i pełne przykłady znajdziesz w katalogu examples/toon/.

Documentation

Start here:

Important project locations

Core:

Operational modules:

Analysis engine:

Plugins and integrations:

Schemas and templates:

Examples:

SDKs:

CI / packaging:

Installation

pip install -e .[dev]

Main commands

python -m intract scan .
python -m intract validate .
python -m intract check .
python -m intract check --staged
python -m intract check --changed --base main
python -m intract check . --format sarif --output intract.sarif
python -m intract check-manifest intract.yaml
python -m intract coverage .
python -m intract duplicates .
python -m intract graph . --format mermaid
python -m intract watch .
python -m intract tickets .
python -m intract artifact Dockerfile
python -m intract artifact openapi.yaml
python -m intract engine suggest .
python -m intract engine drift .
python -m intract engine run .

Run examples

python examples/integration_tests/run_examples.py

Expected:

example_01: pass
example_02: violation + planfile-compatible ticket
example_03: watch/engine/drift works

Project manifest

Generate:

python -m intract init .

Validate:

python -m intract check-manifest intract.yaml
python -m intract validate . --manifest intract.yaml

Pre-commit

Example .pre-commit-config.yaml:

repos:
  - repo: local
    hooks:
      - id: intract
        name: intract intent contracts
        entry: intract check --staged
        language: system
        pass_filenames: false

SARIF / GitHub Code Scanning

python -m intract check . --format sarif --output intract.sarif

GitHub workflow:

License

Licensed under Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

intract-0.5.10.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

intract-0.5.10-py3-none-any.whl (92.2 kB view details)

Uploaded Python 3

File details

Details for the file intract-0.5.10.tar.gz.

File metadata

  • Download URL: intract-0.5.10.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for intract-0.5.10.tar.gz
Algorithm Hash digest
SHA256 2b61316e3a256ba659ed379ca3613be849b63fa17e97b49527f9b04519957d2e
MD5 05f7429628544f91ac0c2b0094758fc2
BLAKE2b-256 f0de7aef8a5ea3ccd99107c277f166384cc57cd8d5335b70bbea8c73accdd6d7

See more details on using hashes here.

File details

Details for the file intract-0.5.10-py3-none-any.whl.

File metadata

  • Download URL: intract-0.5.10-py3-none-any.whl
  • Upload date:
  • Size: 92.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for intract-0.5.10-py3-none-any.whl
Algorithm Hash digest
SHA256 9dae60320d07a200183f281d33e5d133779b9db0bafb0084f0c65110680f2ec1
MD5 fe4eca085d2fa8721681325f548dae2f
BLAKE2b-256 b867e22da839dd2d46a779ddcf21e09fb72a32f3bf54458627cf66f53301bb1b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page