# AGENTS.md This repository defines the Aji programming language. ## Mission Aji is a small, typed, verifiable systems language intended primarily for AI-generated software. Any design or implementation change should improve at least one of: - semantic explicitness; - verifier strength; - deterministic behavior; - machine repairability; - memory/concurrency safety; - implementation simplicity; - auditability. Human ergonomics matter, but they are secondary to verifier clarity and agent reliability. Overarching objective (spec 14): **Model Capability Compression** — Aji SHOULD reduce the minimum model capability required to produce correct systems software, by moving reasoning about ownership, lifetime, aliasing, resources, authority, effects and concurrency from the model into the language, verifier and deterministic runtime. "Agent proposes, verifier decides." Every semantic feature is judged by the reasoning burden it adds for agents; the hypothesis is tested empirically by `docs/evaluation/protocol.md`. Anti-overfitting (spec 14 §12): never add or shape a language feature to improve a specific benchmark task, and never seek out or use the private held-out benchmark corpus. ## Non-negotiable principles Do not introduce: - implicit heap allocation; - implicit reference counting; - exceptions or stack unwinding; - hidden destructors; - unrestricted detached tasks; - raw-pointer operations in safe code; - default atomic memory orderings; - compiler flags that change language semantics; - arbitrary build scripts with host authority; - effects or capabilities that are inferred away from the public contract. Safe Aji must not permit use-after-free, double-free, out-of-bounds reads/writes, uninitialized reads, invalid mutable aliasing, dangling borrows or unsynchronized data races. ## Central abstractions Memory: ```text Own individually owned allocation Region bulk lifetime and bulk deallocation Island uniquely owned closed mutable object graph Frozen deeply immutable graph Arc explicit shared ownership for Share values ref immutable borrow mut exclusive mutable borrow ``` Concurrency preference: ```text ownership transfer → shared immutable data → synchronized shared state → atomics → unsafe raw concurrency ``` ## Source of truth The specification is the single normative source. When documents disagree, use this precedence order: 1. files in `docs/spec/`; 2. files in `docs/reference/`; 3. examples; 4. README prose. RFCs are architectural decision records with rationale, not a normative layer. Accepting an RFC means its rule changes are integrated into `docs/spec/` (and `docs/reference/`) in the same change; from then on the spec, not the RFC, is authoritative. If an accepted RFC and the spec disagree, the spec wins and the RFC is out of date. AIR format 0 is a frozen semantic baseline (spec 07 §8.7): do not change the meaning of existing format-0 constructs; extend only as §8.7 allows, otherwise introduce a new format version through an RFC. Every extension belongs to a registered feature (`docs/reference/air-features.md`); modules declare features and their full dependency closure in the `features [...]` header. Keep three concepts apart: features (what the implementation must understand), effects (what code does), capabilities (what code may do). ## Normative language Use RFC-style terminology: - MUST / MUST NOT: mandatory for conformance; - SHOULD / SHOULD NOT: strong recommendation with documented exceptions; - MAY: optional behavior. ## Implementation constraints Reference implementation target: Zig. Keep the trusted computing base small: - verifier; - AIR interpreter semantics; - backend; - unsafe runtime modules; - ABI/platform descriptions. Prefer verifier-visible primitives over opaque library magic. ## Changes to memory or concurrency Any change involving ownership, aliasing, atomics, tasks, cancellation, resource lifetime, FFI or unsafe code MUST include: 1. invariant being preserved; 2. verifier rule; 3. runtime rule if any; 4. at least one valid example; 5. at least one rejected example; 6. diagnostic/error code impact; 7. deterministic interpreter behavior; 8. backward-compatibility impact. ## RFCs Every RFC introducing a semantic feature includes `## Agent complexity impact` (spec 14 §6): new concepts, new verifier state, new syntax or instructions, interactions, effect on repairability, whether existing primitives suffice, and the bundle growth (`zig build agent-reference`, `docs/agent/README.md`). Normative text an agent needs to write AIR enters the AIR bundle through `docs/agent/bundle.txt`. **Features are vertical (owner decision after P6A-9).** Agents write `.aji`; AIR is the machine-facing layer. A new semantic feature lands in one RFC and one phase through every layer: spec → AIR → verifier → interpreter → `.aji` syntax and lowering (spec 15) → Quick Reference → conformance tests in AIR and in `.aji`. A feature with no source syntax is not done. Its `Agent complexity impact` reports the source-side budget: Quick Reference growth, Source Reference Bundle growth (`tools/agent_bundle_tokens.py --source`), new concepts, new diagnostics and new syntax forms. The budget is not a hard limit; growth is justified, not silent. **M and C are a regression corpus.** The former smoke tasks M and C (now dev material) may show that nothing broke: no new diagnostics, no growth of the source/AIR ratio. They never decide a semantic question. Never tune the language to them. ## Changes to AIR AIR instructions must have explicit: - operand types; - result types; - ownership effects; - memory effects; - concurrency effects; - capability/effect requirements; - trap behavior; - verifier transfer function. Do not add an AIR instruction solely as syntax sugar. ## Commands ```sh zig build # build ./zig-out/bin/aji zig build test # unit tests; fails if src/diag.zig drifts from docs/reference/error-codes.md zig build test-extended # long-running tests (interpreter memory at millions of steps); CI runs it in a separate job zig build conformance # tests/conformance; add `-- --json` for machine-readable results zig fmt --check build.zig build.zig.zon src tools tests/extended ``` Toolchain: Zig 0.17.0. Workflow, layout and definition of done: `CONTRIBUTING.md`. Implementation plan and current phase: `docs/plan/README.md`. Documentation layout and where new documents go: `docs/README.md`. Unresolved spec gaps: `docs/design/open-questions.md` — log new ones there instead of guessing. `aji` CLI output contract: diagnostics are JSON Lines on stdout, human notes on stderr; exit codes 0 accepted/returned, 1 rejected, 2 usage/I/O error, 3 not yet implemented, 4 trapped, 5 execution limit exceeded, 6 not instantiated, 7 blocked. `aji run [--fuel N] [--grant P=KIND[:SCOPE]]… [--stdin T] [--vfs PATH=T]… [--seed N]` runs in the deterministic profile and prints one JSON run record (with captured stdout/stderr and written files); capabilities reach a program only as named `@main` parameters. `--profile hosted` runs against the real OS; its run record goes only to `--result-file PATH` (the program owns stdout/stderr). Hosted smoke tests: `python3 tests/hosted/smoke.py`. Scheduler flags: `--quantum N`, `--task-limit N`, `--schedule-seed N` (independent of `--seed`); conformance tests use `schedules: N` to run N schedule seeds. `aji run --manifest aji.toml` runs a package with the grants its manifest requests (`--grant` replaces one per parameter; spec 12 §1). `aji report FILE` prints the audit report (spec 10 §6.1: effect graph with used/unused effects, entry capabilities, runtime and proven checks, unsafe sites); `aji check --report unsafe` lists trusted boundaries and unsafe operations; unsafe code lives only in functions declaring `effects [unsafe]` or behind a `trusted ""` boundary. `aji features` reports the supported AIR format, language version and features; query it before generating AIR. `aji explore [--max-runs N] FILE` runs `@main` under every schedule and weak-memory choice and prints the distinct outcomes (spec 04 §20.5); the litmus corpus runs through it (`python3 tools/litmus/run_interp.py`). Never use wall-clock timeouts to end runs or tests; use fuel (spec 11 §7). ## Testing policy Every verifier rule should have: - positive conformance test; - negative conformance test; - stable diagnostic code; - interpreter test if observable at runtime. Concurrency features additionally need deterministic scheduler tests and randomized schedule stress tests.