# 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. ## 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 When documents disagree, use this precedence order: 1. accepted RFCs; 2. files in `docs/spec/`; 3. files in `docs/reference/`; 4. examples; 5. README prose. Until an RFC is explicitly marked Accepted, the spec remains authoritative. ## 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. ## 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 conformance # tests/conformance; add `-- --json` for machine-readable results zig fmt --check build.zig build.zig.zon src tools ``` 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, 1 rejected, 2 usage/I/O error, 3 not yet implemented. ## 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.