Adapter contracts and compiler integration
This document describes how adapter semantic contracts work, where they live, and how contributors should extend them when adding or modifying adapter verbs.
Adapter contracts and compiler integration
This document describes how adapter semantic contracts work, where they live, and how contributors should extend them when adding or modifying adapter verbs.
Architecture
ADAPTER_CONTRACTS (tooling/ainl_get_started.py)
↓
contract_semantics.py (tooling/)
↓
ainl validate --strict-contracts
↓
Structured diagnostics (kind, severity, suggested_fix)
Where contracts live
| Source | Role |
|--------|------|
| tooling/ainl_get_started.py → ADAPTER_CONTRACTS | Canonical dict of adapter verbs, arg specs, pitfalls |
| tooling/adapter_manifest.json | Machine-readable adapter catalog (name, effect, flags) |
| tooling/contract_semantics.py | Validation engine: IR → diagnostics |
| runtime/adapters/base.py | ADAPTER_EFFECT side-effect classification |
Contributor checklist (adding or changing a verb)
-
Add/update the verb entry in
ADAPTER_CONTRACTS(tooling/ainl_get_started.py).- Include
argslist with type annotations (required:name: type, optional:name?: type). - Include
exampleshowing compact syntax usage. - Include
returnslisting expected result fields.
- Include
-
Update the adapter manifest if adding a new adapter:
- Add an entry to
tooling/adapter_manifest.json. - Verify
ADAPTER_EFFECTinruntime/adapters/base.pyis consistent.
- Add an entry to
-
Add a strict-valid example if none exists for the adapter family:
- Create under
examples/adapter/. - Register in
tooling/artifact_profiles.jsonunderstrict-valid.
- Create under
-
Test contract validation:
- Run
ainl validateexample--strict --strict-contractsand verify zero diagnostics. - Add negative test cases to
tests/test_strict_adapter_contracts.pyif the verb has arity constraints.
- Run
-
Update MCP resource (
ainl://adapter-contracts) by running the MCP server — it readsADAPTER_CONTRACTSat startup.
Sync rules
ADAPTER_CONTRACTSkeys must be a superset of adapters referenced inartifact_profiles.jsonstrict-valid examples.adapter_manifest.jsonadapter names should have a correspondingADAPTER_CONTRACTSentry (gaps are tracked as "uncontracted" inainl_capabilities).ADAPTER_EFFECTinbase.pyclassifies side effects; contracts add verb-level semantic detail on top.
Validation modes
| Flag | Behavior |
|------|----------|
| --strict | Syntax strictness (existing) |
| --strict-contracts | Semantic contract validation: unknown verbs and arity mismatches become errors |
| Neither | Permissive: compiles even with unknown verbs |
See also
docs/issues/04-strict-adapter-contract-expansion-policy.md— expansion policydocs/operations/OPERATOR_MARKETING_GUARDRAILS.md— marketing rulesdocs/EMIT_TARGETS.md— shipped emit targets