# Cairn > Cairn is a description language for Minecraft builds: a `.crn` file declares intent (walls, roofs, windows, themes, redstone) and the `cairn` compiler resolves it into structure files for the Minecraft edition and version it is asked to build for. # Introduction Cairn is a description language for Minecraft builds. You declare intent (walls, roofs, windows, symmetry, themes, redstone logic) and the compiler resolves the voxels: blockstates, orientations, coordinate maths, signal routing, and the right block IDs for the edition and version you are building for. A *cairn* is a deliberately stacked pile of stones that marks a place. A Minecraft build is exactly that. The name is the thesis. ## What it solves Minecraft's NBT/SNBT is inefficient for an AI to read and write. It is binary, with one record per block. It also works at the wrong granularity: people and AI reason about walls, roofs, and symmetry. Cairn sits between an AI's general architectural knowledge and Minecraft's voxel world. The portable artifact is always the Cairn source. Emitted NBT and schematics are per-target build outputs, the equivalent of a compiled binary. Targeting a new Minecraft version means **recompiling the source** rather than transcoding the NBT. ## What it deliberately does not do **Full round-trip fidelity with NBT.** Generation-first is lossy by design. Imported schematics are kept as a faithful low-level transliteration that an LLM can lift into idiomatic Cairn, with a voxel-diff loop driving convergence. **General sequential synthesis of arbitrary state machines or CPUs in redstone.** v1 ships combinational gates plus a curated macro library; everything else drops to physical placement or a `raw` escape hatch. **Pre-1.13 numeric-ID `.schematic` import.** v1 does not support flattening. See [Purpose and Scope](/spec/overview/) for the normative wording. ## Where to read next | | | |---|---| | [Tutorial](/tutorial/) | A walk from one cottage to a village, through the worked [examples](/examples/). | | [Specification](/spec/) | Fifteen chapters, plus the compatibility tiers and a cross-cutting glossary. | | [Developer Guide](/development/) | The Rust workspace, how the crates split, and how to land changes. | | [Playground](/playground/) | A placeholder for the browser-hosted compiler. Tracks `cairn-lang-wasm`. | Every page of this site except the home page and the playground also ships inside `cairn`, as it stood in the release you installed. `cairn docs` lists the pages, and `cairn docs spec/syntax` prints one as Markdown, with no network needed. For language models, [`/llms.txt`](/llms.txt) indexes the site. The same pages are also served as Markdown at their URL followed by `index.md`, and [`/llms-full.txt`](/llms-full.txt) holds every English page in one file. ## Status Cairn is at the design stage, draft `2026.06`. The language is being designed in the open, and the reference compiler already builds Java and Bedrock structure files from one source. The most useful contributions right now are design critique, concrete proposals, and worked examples. See [`CONTRIBUTING.md`](https://github.com/kage1020/Cairn/blob/main/CONTRIBUTING.md). # Tutorial This page walks through the [examples](/examples/), one idea at a time. Read it top to bottom, since each section builds on the one before it. > The `cairn compile` commands on this page run with the current compiler. Redstone does not reach > compiled output yet, so the gatehouse in section 3 builds without its circuit. ## 1. A cottage [`cottage.crn`](https://github.com/kage1020/Cairn/blob/main/examples/cottage.crn) is a complete Cairn build. ``` @cairn 2026.06 @requires version>=1.20 theme medieval: slot floor -> @oak_planks slot wall -> @cobblestone slot roof -> @spruce_stairs slot glass -> @glass_pane struct cottage size=9x7 floor mat_slot=floor walls class=outer mat_slot=wall height=4 door side=front at=center window class=small side=front offset=2 y=2 size=2x2 sym=true mat_slot=glass roof kind=gable mat_slot=roof overhang=1 ``` Compile it for either edition: ```sh cairn compile examples/cottage.crn --edition java --target 1.21.4 cairn compile examples/cottage.crn --edition bedrock --target 1.21.40 ``` **The source never picks the Minecraft version.** It lives in `--target`, and `--edition` is required alongside it. What the source *may* declare is `@requires`, a floor on what the target has to support; `@intended_targets`, a hint naming the versions the author has in mind; and `@cairn`, the language version the file was written against. **The struct says where; the theme says what.** `mat_slot=wall` is an injection point, not a block name. The theme binds it. Swap `theme medieval` for another and the geometry never changes. This is the CSS idea, applied to blocks. **Positions are semantic.** `side=front`, `offset=2`, `y=2`, `at=center` are positions along a wall. No absolute coordinates appear anywhere you write. **Order does not matter.** Move the `window` line above `walls` and it is still cut as an opening in the wall. The compiler sorts commands into fixed phases before evaluating them, so you can write lines in whatever order reads best. **Blockstate is derived.** Nobody writes `facing`, `half`, or `shape` for the roof's stairs. The compiler works them out from where each stair sits on the roof. The door's facing and the pane's connections are to be derived the same way; for now the `door` only cuts its opening. ## 2. Abstract materials and levels [`themed-tower.crn`](https://github.com/kage1020/Cairn/blob/main/examples/themed-tower.crn) adds three ideas to the same shape. ``` theme keep_dark: slot floor -> @floor.wood.broadleaf # abstract token slot wall -> @wall.stone.cobble slot trim -> @wood.dark slot roof -> @roof.dark_wood struct keep size=11x9 floor id=base mat_slot=floor walls id=shell mat_slot=wall height=5 roof id=roof kind=gable mat_slot=roof overhang=1 level id=floor1 y=0 ... level id=floor2 y=5 walls id=upper class=outer mat_slot=wall height=4 window class=arrow_slit side=front repeat=3 step=2 y=2 size=1x2 stair id=eave kind=stairs mat_slot=roof side=front half=top facing=out shape=outer_left ``` **Two kinds of token.** `@oak_planks` is a *canonical block token*, a specific meaning that can never be silently downgraded. `@floor.wood.broadleaf` is an *abstract material token*, an aesthetic choice a theme may resolve to oak or birch depending on the target. **`level y=5` gives the upper floor its own `y=0`.** The second-floor window stays at `y=2` from its own floor rather than from the ground. **Writing a blockstate promotes it to intent.** The `stair id=eave` line writes `half=top facing=out shape=outer_left` explicitly, so those values are now yours, not the compiler's. The rule is "derive by default; any blockstate that *can* be intent is overridable". Read on: [Materials and Themes](/spec/materials-themes/), [Blockstate Model](/spec/blockstate/). ## 3. Redstone as a signal graph Instead of placing dust and repeaters, you declare what depends on what. [`redstone-door.crn`](https://github.com/kage1020/Cairn/blob/main/examples/redstone-door.crn): ``` struct gatehouse size=7x5 floor mat_slot=wall walls class=outer mat_slot=wall height=3 roof kind=flat mat_slot=wall overhang=1 door id=front side=front at=center pressure_plate id=plate at=front.outside offset=3 y=0 -> sig.step pressure_plate id=inner at=inside.front offset=3 y=1 -> sig.exit logic sig.open = sig.step or sig.exit door[id=front] opened_by=sig.open circuit region=floor void=2 assert truth(sig.step, sig.exit -> sig.open) { 00->0; 01->1; 10->1; 11->1 } assert always(sig.step -> eventually sig.open within 2) ``` **A plate outside a wall stands under the roof's overhang.** `at=front.outside` takes the cell in front of the wall at `offset=3`, right outside the door, in the ring the roof's `overhang=1` adds. Without an overhang the struct ends at its walls, so the plate has nowhere to go and is refused with `E_INVALID_MEMBER`. `at=inside.front` takes the cell just inside, at `y=1`, on top of the floor: inside the walls row `y=0` is the floor itself, while outside it is the ground. **Sensors emit, actuators consume.** `-> sig.step` is a sensor's output; `opened_by=sig.open` is an actuator's input. `logic` writes the dependency between them. **There is no tick arithmetic.** The logic expression carries no time at all. The `within 2` in the assertion is the only number that means ticks, because delay is not known until the circuit has been placed and routed. **`circuit region=…` reserves space** for place-and-route. If routing does not fit you get `E_ROUTE_CONGESTION` with a suggested fix, never a silent overflow. For now only the experimental `cairn synth --experimental-logic-synth` runs the router, so `cairn compile` does not report it. **Assertions come in three kinds:** `truth(…)` for combinational logic, `latency(in -> out) <= N` for bounded delay, and `always(in -> eventually out within N)` for bounded temporal. There is no full LTL by design, only what a per-tick simulator can decide cheaply. That simulator does not exist yet, and the parser does not accept `latency` yet either. **The edition difference is in the cell library, not the language.** The same logic becomes a `ComparatorAND` cell on Java and a `TorchAND` on Bedrock. Circuits that depend on quasi-connectivity or block-update order are meant to be a compile error rather than a silent footgun, though nothing checks a circuit for that dependence yet. Read on: [Redstone](/spec/redstone/). ## 4. Several buildings Once one cottage works, reuse it. [`village.crn`](https://github.com/kage1020/Cairn/blob/main/examples/village.crn): ``` def cottage size=9x7: floor id=floor mat_slot=floor walls id=walls class=outer mat_slot=wall height=4 door id=entry class=entry side=front at=center window id=front side=front y=2 offset=2 size=2x2 mat_slot=glass roof id=roof kind=gable mat_slot=roof overhang=1 site hamlet: place id=home1 use=cottage theme=medieval at=origin place id=home2 use=cottage theme=medieval east_of=home1 gap=4 place id=home3 use=cottage theme=medieval north_of=home1 gap=5 connect home1.entry to home2.entry path=@gravel connect home1.entry to home3.entry path=@gravel ``` **`def` is a reusable component** built on the same slot mechanism as `theme` and `site`, so references work the same way across editing, theming, and multi-building. **Placement is relational.** `east_of=home1 gap=4` is a constraint; turning it into coordinates is the compiler's job. That removes the single worst class of LLM arithmetic error. **Structs expose ports.** `home1.entry` is the door member declared in the `def`, and `connect` joins two ports with a walkway. **The 48³ structure-block limit dissolves.** A village too large for one structure block is several `def`s composed on a `site`. Read on: [Components, Editing, and Multi-building](/spec/components-editing-sites/). ## Where to go next | If you want to… | Read | |---|---| | Change part of a build without rewriting it (planned) | [Editing model §9.2](/spec/components-editing-sites#92-editing-model), as in `edit window[class=vent] set shape=arch` | | Know which Minecraft versions a file works on | [Versioning and Editions §10.5](/spec/versioning-editions#105-which-version-is-it-for-has-three-answers), the `cairn info` report | | Bring an existing schematic into Cairn (planned) | [Ecosystem Interop](/spec/ecosystem-interop/): transliterate, lift, voxel-diff | | Try the other roof kinds | The `roof-shed`, `roof-hip`, and `roof-flat` [examples](/examples/) | | Look up a term | [Glossary](/spec/glossary/) | # Examples Every file lives in [`examples/`](https://github.com/kage1020/Cairn/tree/main/examples) and is intentionally minimal. The [Tutorial](/tutorial/) walks through the four in the first group. > Every file here compiles with the current compiler. Redstone does not reach compiled output yet, > so `redstone-door.crn` builds without its circuit. ## Start here | File | Shows | |---|---| | [`cottage.crn`](https://github.com/kage1020/Cairn/blob/main/examples/cottage.crn) | The minimum useful build: `struct`, `theme`, slots. | | [`themed-tower.crn`](https://github.com/kage1020/Cairn/blob/main/examples/themed-tower.crn) | Abstract material tokens, per-floor `level`, override-promotion. | | [`redstone-door.crn`](https://github.com/kage1020/Cairn/blob/main/examples/redstone-door.crn) | Logical redstone: signal binding, `circuit` region, assertions. | | [`village.crn`](https://github.com/kage1020/Cairn/blob/main/examples/village.crn) | Multi-building with `site` and topological `connect`. | ## Roof kinds | File | Shows | |---|---| | [`roof-shed.crn`](https://github.com/kage1020/Cairn/blob/main/examples/roof-shed.crn) | `kind=shed slope_to=front`: a single slope rising toward the front wall. | | [`roof-hip.crn`](https://github.com/kage1020/Cairn/blob/main/examples/roof-hip.crn) | `kind=hip` on a square footprint: four slopes onto one apex cap. | | [`roof-flat.crn`](https://github.com/kage1020/Cairn/blob/main/examples/roof-flat.crn) | `kind=flat`: a single deck layer, with the overhang extending it past the walls. | ## Walkways and ports | File | Shows | |---|---| | [`l-walkway.crn`](https://github.com/kage1020/Cairn/blob/main/examples/l-walkway.crn) | A Manhattan L between two ports that differ on both axes. | | [`at-side-walkway.crn`](https://github.com/kage1020/Cairn/blob/main/examples/at-side-walkway.crn) | `at=left` / `at=right` door anchors pulling ports toward the facing corners. | | [`window-walkway.crn`](https://github.com/kage1020/Cairn/blob/main/examples/window-walkway.crn) | A window port, anchored at the rectangle's centre and pinned to the ground row. | ## Edge cases | File | Shows | |---|---| | [`edition-fallback.crn`](https://github.com/kage1020/Cairn/blob/main/examples/edition-fallback.crn) | Per-edition theme variants for a slot with no cross-edition primitive. | | [`crossbar.crn`](https://github.com/kage1020/Cairn/blob/main/examples/crossbar.crn) | Four nets in a tight region: the router lays each one around the others and lifts one onto a bridge layer inside `void=2`; at `void=1` it refuses with `E_ROUTE_CONGESTION`. | # Roadmap Cairn ships **monthly minor releases** under [date-based versioning](/spec/versioning-editions/#101-the-target-is-a-compile-time-parameter) `YYYY.M[.PATCH]`. Each month delivers what is ready; nothing is held back for an arbitrary "1.0". Six named milestones sit across the monthly schedule, so contributors and consumers can plan against something more durable than a calendar date. > The schedule is a plan, not a promise. The compiler is implemented in the open, and slips happen. > The [CHANGELOG](https://github.com/kage1020/Cairn/blob/main/CHANGELOG.md) is the source of truth > for what shipped. ## Where things stand The compiler ran well ahead of the first plan. What M1, M2, M4 and M5 ask the compiler to do had all landed by 2026.8.0, three of them months before their dates, and the releases since have hardened it against the spec. M2 also makes the lockfile format Stable, and the lockfile kept changing after M2's build landed: 2026.9.0 added `lock_schema_version` and reframed the registry pack hash, and 2026.10.0 canonicalised the palette, which moved every `resolved_ir_hash`. So M2 counts as reached with 2026.11.0, the release its Stable contract starts from. Two milestones remain. - **M3** is where the language leaves draft. Every example already compiles clean for Java and builds for Bedrock. What M3 still needs is listed under [Leaving draft](#leaving-draft). - **M6** is where redstone reaches the structure file. Synthesis and place-and-route run behind `cairn synth --experimental-logic-synth`, but no routed circuit is written into an artifact, and nothing simulates one. ## Release cadence - **Monthly minor** (`YYYY.M.0`) on the first of the month. A cron job opens the PR that promotes `canary` to `main`; its merge opens the release PR on `main`, which is merged after human review. - **Patches** (`YYYY.M.N`, `N ≥ 1`) are cut on demand: a maintainer starts the same promote by hand, or merges a hotfix into `main`, and either opens a release PR on `main`. Typical triggers: registry/constraint pack updates, regressions, and security fixes. No upper bound on patches per month. - **Channel:** there is only one, `stable`. Cairn does not run a separate nightly or beta train. Behaviour that is not yet stable is gated by [compatibility tier](/spec/compatibility/), not by release channel. - **Backports:** none. The latest release is the supported release. Older `YYYY.M.*` lines do not receive further patches. ## Milestones Each milestone is a "the project can credibly do X" gate, hit when the release that does X ships. A milestone that turns a surface Stable is reached when that surface's Stable contract starts. Naming the gates separately from version numbers gives the roadmap a stable vocabulary even when the monthly schedule shifts. | Milestone | Status | The thing it earns | |---|---|---| | **M1, source parses** | Reached in 2026.7.1 | `cairn parse` produces an AST for every example in `examples/` | | **M2, minimal build** | Reached in 2026.11.0; the build landed in 2026.7.1 | `cairn compile` writes a Java `.nbt` for a single-room structure with floor and walls, plus a lockfile, and the lockfile format turns Stable | | **M3, examples work** | Planned for 2027.1.0 | Every example in `examples/` compiles clean with `--edition java` and loads in Minecraft; the specification leaves draft, and the surfaces the [compatibility tiers](/spec/compatibility/#c2-tier-of-each-surface-by-milestone) list for M3 turn Stable | | **M4, Java/Bedrock parity** | Reached in 2026.8.0 | Same DSL source emits valid output for both editions; parity table populated; per-edition theme fallbacks work | | **M5, developer experience** | Reached in 2026.8.0 | `cairn-lsp` provides diagnostics and completion in at least one editor (VS Code) | | **M6, redstone simulates** | Planned for 2027.4.0 | `cairn compile` lays a `logic` graph into the structure file, and a tick simulator verifies `redstone-door`'s assertions against the circuit it built | ## Shipped so far Each minor release by its headline. The patches and the full lists are in the CHANGELOG, which files the first release under `2026.7.0`; its tag and GitHub release are `v2026.7.1`. | Release | What it brought | |---|---| | **2026.7.1** | The first release. `cairn parse`, `check`, `info`, `lower` and `compile`; the Intent IR, the semantic layer and the block-array pivot; Java `.nbt` output with a lockfile; registry pack ingest and nearest-valid suggestions; `gable`, `shed`, `hip` and `flat` roofs; `site` placements joined by walkways. **M1**. | | **2026.8.0** | Bedrock `.mcstructure` output, with the parity table and per-edition theme fallbacks. `themed-tower`, `village` and `redstone-door` compile clean, through `level` grouping and eave stairs, walkways routed around structures, and pressure plates, circuit region markers and door actuator patches. `cairn-lsp` with diagnostics and completion, and a VS Code extension; the tree-sitter grammar, on npm as `tree-sitter-cairn`; redstone synthesis, placement, routing, delay insertion and crossing legalization behind `cairn synth --experimental-logic-synth`. **M4**, **M5**. | | **2026.9.0** | Hardening. A source that does not parse gets a diagnostic like any other; the lockfile is read back, so a rebuild for another target says so; the floor `@requires` declares is enforced; nesting and extents are bounded, so hostile input is refused instead of exhausting the compiler. | | **2026.10.0** | Version floors in full: `@cairn` is read, `@requires` floors order by DataVersion and may name an edition, a `def` or a `theme` declares its own floor, and `@intended_targets` is weighed against them. A renamed block id is answered from the pack's alias table, and an `assert truth` row may use `-` as a don't-care. | | **2026.11.0** | `cairn docs` prints the documentation built into the binary, offline, and the site serves each page as Markdown with an `/llms.txt` index. `cairn check` with no target reports the lowering findings that need none, a truth table may be written one row per line, and an even-span hip roof's apex faces away from its ridge. A member its own line cannot place, a pressure plate among them, is the error `E_INVALID_MEMBER`, `redstone-door`'s plates sit where a player can step on them, a name Windows reserves is refused on every host (`E_INVALID_PLACE_ID`, `E_INVALID_STRUCT_NAME`), and `and` / `or` / `not` come from a built-in logic library, which changes the expression shape `cairn parse --format json` prints. The coordinate system is settled on a corner origin and `front = +z`, and the language-evolution policy on announcing changes per release, with no year-based opt-in. Syntax the specification describes but the compiler does not build yet is flagged subject to change, so it stays Evolving when `.crn` syntax turns Stable. The specification lists the tier-1 tokens, the abstract tokens the built-in catalogs declare. The compatibility chapter fixes what `W_DEPRECATED` and `E_BREAKING` mean, which codes are reserved, and which findings are placeholders, raised only until what they stand in for is built. The lockfile format turns Stable. **M2**. | ## Monthly scope The table below is the working plan, month by month, for the releases still ahead. It is denser than the milestone table because a monthly minor can ship without crossing a milestone gate. | Release | Scope added | |---|---| | **2026.12.0** | What M3 waits on ([Leaving draft](#leaving-draft)): the diagnostic codes settled. Each release attaches the VS Code extension as a `.vsix`, and the extension is on the Marketplace. | | **2027.1.0** | Every example compiles clean on Java and loads in Minecraft. The specification leaves draft as `2027.1`, and `.crn` syntax, the `compile` / `check` / `info` interface, the diagnostic codes and the tier-1 vocabulary turn Stable. **M3.** | | **2027.2.0** | Blockstate derived beyond stairs: a `door` places its door block, panes, fences and walls connect, chests pair, and `fill`, with the coordinate triples it takes (`from=1,1,1`), sets `waterlogged`. The built-in packs are extracted from each edition's `--reports` / registry dumps, for the targets they carry today and each edition's current releases, so `E_STATE_DOMAIN` checks a state literal against the target and an error names the version an id first appears in. | | **2027.3.0** | Redstone reaches the structure file: edition legalization and lowering from the Placement IR to the block array, so `cairn compile` runs the `logic_*` phases. The rest of the combinational primitives (`xor`, `nand`, `nor`, `mux`), the remaining sensors and actuators (`lever`, `button`, `daylight`, `observer`, `lamp`, `piston`, `dispenser`), Tier 0 parts such as `repeater` placed by hand, the `raw` escape hatch, and `@edition` alternatives with `E_PARITY_UNSUPPORTED`. | | **2027.4.0** | A tick simulator checks `assert truth` and `assert always` against the built circuit; `assert latency`; the sequential macros (`latch`, `pulse`, `delay`, `edge_rising`, `edge_falling`, `counter`); `E_NO_PORTABLE_IMPL` for logic that depends on update order, whose fix, Tier 0 under an `@edition` guard, exists by then. `redstone-door` verifies, and the redstone DSL turns Stable. **M6.** | | **2027.5.0** | Entities and block entities (`spawn`, `painting`, `sign`, `bed`, …) with their anchors, and the decimal (`scale=1.5`) and `nbt={...}` values they take; theme selector bindings, specified and lowered; the first constraint catalog (attachment, support, fluids, entity AABB), so `cairn info` reports semantic-sensitive members and a lock records the catalog's hash. | | **2027.6.0** | `edit` patches, and the stable addresses the compiler gives members written without an `id=`; `.litematic` and `.schem` writers; `cairn-lang-wasm` and the browser playground (live compile in the docs site). | Beyond `2027.6.0` the schedule is not drawn yet. The spec describes more than this plan reaches: the reverse direction (`cairn import`, `cairn diff-blocks`), the harness the [evaluation framework](/spec/evaluation/) calls for, and the open questions that wait on its data, columns and arches as primitives and interiors. The roadmap will be redrawn around those, and around feedback from real use, as 2027.6.0 approaches. ## Leaving draft The specification is titled `2026.06 (draft)`. The label comes off at M3, when the surfaces the [compatibility tiers](/spec/compatibility/#c2-tier-of-each-surface-by-milestone) list for M3 turn Stable: `.crn` syntax (chapters 5 to 9 and §10.7), the flags, JSON schemas and exit codes of `cairn compile`, `check` and `info`, the diagnostic codes, and the tier-1 material vocabulary. From then on the specification carries the version of the release that ships it, starting with `2027.1`, and a break to any of those surfaces waits out a `W_DEPRECATED` window. What stands between today and that point: - **The diagnostic codes settle.** After M3, adding a code breaks nothing and changing what an existing code means does, so changes of the second kind land before 2027.1.0. [Compatibility "How a break is communicated"](/spec/compatibility/#c3-how-a-break-is-communicated) says which kind a change is, including a placeholder replaced by the behaviour the spec already defines. ## How the schedule is enforced The release strategy itself is automated: 1. **Monthly promote PR** from `canary` to `main` is opened by a GitHub Actions cron at `04:17 UTC` on the first of each month. The time is deliberately off the hour, because GitHub Actions crons are most likely to be delayed or skipped on the hour. A patch runs the same job by hand, or lands a hotfix on `main`. Only `main` is published, so nothing on `canary` reaches users before it is promoted. 2. **Version is computed** when the promote or the hotfix lands on `main`, from existing tags: no `vYYYY.M.*` tag yet → next is `YYYY.M.0`, otherwise the next in-month patch. The job writes it into the workspace `Cargo.toml`, unless a maintainer running it by hand gives the version. 3. **release-plz** writes the changelog section from the commits and opens the release PR against `main`. The job then brings the tree-sitter and VS Code manifests to the same version, regenerates the parser, and folds the `changelog.d/` fragments into `CHANGELOG.md`. 4. **Human review** merges the release PR into `main`, for a patch as for a minor. 5. **Publish** runs on that merge: `cargo publish` every crate except `xtask` to crates.io and tag `vYYYY.M.N`; build binaries for Linux, macOS, and Windows on `x86_64` and `aarch64`, each target on a runner of its own, and attach every archive with its SHA-256 checksum to a GitHub Release, beside a sigstore bundle for each archive except the Windows `aarch64` one, and a signed CycloneDX SBOM; publish the tree-sitter grammar to npm; and open a PR that merges `main` back into `canary`. Compatibility expectations across this schedule are defined separately by [compatibility tier](/spec/compatibility/): the lockfile format is **Stable** from 2026.11.0, where M2 is reached, and the LSP wire protocol from M5; `.crn` syntax follows at M3 and the redstone DSL at M6; the Rust API stays **Internal** throughout, and most other surfaces sit at **Evolving** for now. # Specification 2026.06 (draft) This is the normative specification of **Cairn**, an intermediate language for AI to read and write Minecraft builds. It avoids the inefficiency of NBT/SNBT, which is binary and one record per block, and aligns architectural knowledge (walls, roofs, symmetry) with the voxel world. The approach is **generation-first**, and therefore lossy on purpose. ## Reading order | # | Chapter | Contents | |---|---|---| | 1 | [Purpose and Scope](/spec/overview/) | Purpose, scope, non-goals | | 2 | [Design Principles](/spec/principles/) | P1–P5 | | 3 | [Architecture](/spec/architecture/) | Three-layer IR, block-array pivot | | 4 | [Compilation Model](/spec/compilation/) | Phase evaluation, target axes, roof lowering | | 5 | [Syntax](/spec/syntax/) | Lexical rules, `key=value`, selectors, headers | | 6 | [Blockstate Model](/spec/blockstate/) | Derivation and override, intent vs resolved, waterlogged | | 7 | [Materials and Themes](/spec/materials-themes/) | Slots, canonical vocabulary, themes | | 8 | [Entities](/spec/entities/) | Two-tier entity model, anchor conventions | | 9 | [Components, Editing, and Multi-building](/spec/components-editing-sites/) | `def`, editing, `site` | | 10 | [Versioning and Editions](/spec/versioning-editions/) | Target strategy, lock, portability | | 11 | [Lint](/spec/lint/) | Diagnostic codes and constraint validation | | 12 | [Ecosystem Interop](/spec/ecosystem-interop/) | Import, reverse conversion | | 13 | [Evaluation Framework](/spec/evaluation/) | How the spec is iterated | | 14 | [Redstone](/spec/redstone/) | Logic circuits | | 15 | [Open Issues](/spec/open-issues/) | What is still undecided | | — | [Compatibility Tiers](/spec/compatibility/) | Stable / Evolving / Internal, per public surface | | — | [Glossary](/spec/glossary/) | Defined terms, cross-chapter | ## Conventions - Requirement words **MUST / SHOULD / MUST NOT / OPTIONAL** are used in the RFC 2119 sense. - The language is **Cairn**, the CLI is `cairn`, and source files use `.crn`. - Design principles are referenced as `P1`–`P5` (see [Design Principles](/spec/principles/)). - Outside this specification, a chapter is cited by its file name and a section by its title without the number, as `spec/lint` "Error vs warning". `cairn docs` takes such a citation as written and prints that section from the specification the installed compiler implements: `cairn docs spec/lint "Error vs warning"`. ## Two version axes Cairn's own releases use date-based versioning (CalVer) `YYYY.M.PATCH`: `2026.7.0` for a monthly release, `2026.7.1` for an in-month patch. A version written without its patch, as `@cairn` allows, has patch `0`, so `2026.7` and `2026.7.0` name the same version. Versions compare component by component, as numbers: `2026.10.0` is later than `2026.8.2`, though it sorts before it as a string. A release bundles the language spec, the reference compiler, the standard library, and the `(edition, version)` registry and constraint catalogs. **Minecraft also moved to date-based versions**, so the two cannot be told apart by format. They are distinguished by field, flag, or keyword, never by shape: | | Cairn's own version | The Minecraft target | |---|---|---| | Lock | `cairn_version` | `mc_version` | | Headers | `@cairn` | `@requires`, `@intended_targets` | | CLI | `cairn --version` | `--target` | In prose, disambiguate with a prefix: `cairn:2026.06` and `mc:1.21.4`. This document is **2026.6 (draft)**, superseding the former `v0.2` label. A `.crn` file MAY declare `@cairn 2026.06`, the language version it was written against. It records provenance only, so that a future compiler can parse the file and warn correctly. No pass branches on it, but the value is still checked to be a `CalVer`. See [Syntax §5.3](/spec/syntax/#53-headers). The draft label comes off with the `2027.1.0` release. From then on the specification carries the version of the monthly minor that ships it, `2027.1` first, so a minor's specification and compiler share one version, and a patch release such as `2027.1.1` ships its minor's specification. A file written against `2027.1` MAY declare `@cairn 2027.1`, and a file written against a later release MAY declare that release. A value before `2027.1`, such as `@cairn 2026.06`, names the `2026.6` draft or a release that shipped it. It stays valid provenance, and a later compiler reads the file as it reads any other. # 1. Purpose and Scope ## 1.1 Purpose Minecraft's NBT/SNBT is inefficient for an AI to handle directly. It is binary, and it is a flat list of one record per block. It is also pitched at the wrong granularity: people and AI reason about walls, roofs, and symmetry, not about individual voxels. Cairn is an intermediate language that aligns an AI's general architectural knowledge with Minecraft's voxel world: the eyes and hands an AI uses to see and build. ## 1.2 Approach: generation-first Full round-trip fidelity with NBT is given up. The top priority is letting an AI generate and edit builds accurately, which makes the language lossy by design. The reverse direction, NBT or schematic back into Cairn, is best-effort ([Ecosystem Interop](/spec/ecosystem-interop/)). The portable artifact is always the **Cairn source**. Emitted NBT and schematics are per-target build outputs, the equivalent of a compiled binary ([Versioning and Editions](/spec/versioning-editions/)). ## 1.3 Scope and non-goals Redstone can be described at the logic level: declare signals, gates, and connections, and the compiler synthesizes, places, and routes them ([Redstone](/spec/redstone/)). v1 covers combinational logic plus a curated set of sequential macros. General sequential synthesis of arbitrary state machines or CPUs is out of scope, and those drop to Tier 0 physical placement or `raw`. Also out of scope for v1: - Full NBT recovery of chest contents, command blocks, and the like. - Importing legacy numeric-ID `.schematic` files from before the 1.13 flattening. # 2. Design Principles ## P1. Separate intent from blockstate The author declares meaning; the compiler derives blockstate. Two layers, meaning and blockstate, do not scale to `def`, themes, and multi-building, so the model is a three-layer IR with named members. See [Architecture](/spec/architecture/). ## P2. A phase-ordered canvas Whole-program last-wins, the "paint model", produces order-dependent accidents, so it is dropped. Commands are sorted into implicit phases and evaluated in a fixed order, and last-wins is restricted to local overrides within one phase. See [Compilation Model](/spec/compilation/). ## P3. A small closed vocabulary, with an escape hatch Keep the set of semantic primitives small. The smaller the vocabulary, the more stable LLM generation is and the simpler the validator. Missing expressiveness escapes through `raw` directives. ## P4. Relative, semantic positioning Position by wall selectors rather than by absolute coordinates. Blocks, block entities, and entities share one selector grammar. See [Syntax](/spec/syntax/). ## P5. The lint loop is part of the spec The compiler is both a translator and an architectural linter. The form and granularity of error reporting are designed as first-class concerns, because precision is earned through a loop rather than through one-shot generation. See [Lint](/spec/lint/). # 3. Architecture ``` Intent DSL ↓ parse Semantic / Component-Theme IR named members: id / class / role / mat_slot / intent_state ↓ resolve phase evaluation, geometry expansion, theme injection, derived blockstate block-array IR voxel grid + palette + block entities + entities ← universal pivot ↓ serialize per edition, version, format backend .nbt (Java) / .litematic / .schem / .mcstructure (Bedrock) ``` ## 3.1 The block-array IR is the universal pivot Every format's frontend and backend meets at this layer, and diff, IoU, and serialization all happen here. It holds a voxel grid, a palette, block entities, and entities, and is neutral to format, edition, and version. It is the output target of the forward direction and the input destination of the reverse one ([Ecosystem Interop](/spec/ecosystem-interop/)). ## 3.2 The Intent IR is rich and carries invariants A named member carries `id`, `class`, `role`, `mat_slot`, `intent_state`, and `resolved_state` ([Blockstate Model](/spec/blockstate/)). A raw import does not produce a valid Intent IR. It reaches one only after a semantic lift, and an artifact's progress along that path is `semantic_level: raw | grouped | lifted`. ## 3.3 Redstone sub-layers When redstone is described logically ([Redstone](/spec/redstone/)), four IR layers with distinct roles sit between the Intent IR and the block-array IR, the same separation HDL uses: ``` Logic IR logical expressions, dependency DAG. Edition-neutral, zero delay Netlist IR cells and nets. Logical cell selection. Still no delay Edition Netlist IR the same cells and nets. Edition cell selection. Still no wire Placement IR cell coordinates, then actual wire length. Delay and ticks determined here ``` The logic is edition-neutral; the edition cells and the place-and-route result (tiles, timing) are edition-specific. **Delay is not carried in the Logic or Netlist IR.** The Placement IR determines it: an edition cell fixes the ticks from each of its ports, but there is no wire before routing. Nothing lowers the Placement IR to the block-array IR yet ([Redstone §14.8](/spec/redstone/#148-connection-to-the-ir-and-phases)). ## 3.4 What the split buys The block-array IR at the bottom is shared across forward and reverse directions and across every format. The member/Intent IR above it is an independent type with invariants: every member has an `intent_state`, every slot is resolved, and so on. That separation lets serialization, diff, lint, and IoU evaluation be shared at the bottom layer while the semantic layer stays type-safe. # 4. Compilation Model ## 4.1 Phase evaluation Write commands flat and in any order. The compiler assigns each one to a phase and evaluates the phases in this fixed order: ``` massing floor / walls / volume envelope roof / stair openings door / window fixtures sign / painting / frame / bed / sensors / actuators logic_synth redstone: Logic IR → Netlist IR (and Edition Cell selection) logic_place cell placement → Placement IR logic_route routing, delay insertion and crossing legalization over the Placement IR, delay determined raw escape hatch ``` Not every row runs today. `volume`, `sign`, `painting`, `frame`, `bed` and `raw` are not keywords yet and are each refused as `E_UNKNOWN_KEYWORD`, so the phases that paint are `massing`, `envelope`, `openings` and `fixtures`, whose one member is `pressure_plate`. `cairn compile` does not run the three `logic_*` phases, so a `logic` line lays no redstone in the artifact; they are reached only through `cairn synth --experimental-logic-synth`. A `window` written after `roof` is still cut as an opening in the wall. Source order never decides what a member means. Nor does it decide what the artifact is ([§4.8](#48-within-phase-conflicts-and-the-palette)): permuting two members that share no voxel leaves the whole `BlockArray` equal, palette numbering included, not only the voxels. `circuit` marks a routing region and writes no voxel, so it belongs to no phase. The three `logic_*` phases follow `fixtures` because port coordinates are not fixed until sensors and actuators are placed in 3D. See [Redstone](/spec/redstone/). Last-wins applies only to **local overrides within the same phase**, and `raw` always runs last. Two different members contesting a voxel inside a phase resolve the same way and are reported. See [§4.8](#48-within-phase-conflicts-and-the-palette). ``` theme stone: slot floor -> @oak_planks slot wall -> @cobblestone slot roof -> @spruce_stairs slot glass -> @glass_pane struct keep size=11x9 floor id=base mat_slot=floor walls id=shell mat_slot=wall height=5 roof id=roof kind=gable mat_slot=roof overhang=1 window id=front_windows side=front y=2 offset=2 size=2x2 mat_slot=glass # still cut as an opening door id=entry side=front at=center ``` ## 4.2 Target axes The target is the pair `(edition, version)`. Neither is written in the source; only the backend knows them. See [Versioning and Editions](/spec/versioning-editions/). ```sh cairn compile build.crn --edition java --target 1.21.4 cairn compile build.crn --edition bedrock --target 1.21.40 ``` `--edition` is required and `--target` alone is refused. "1.21" means different things on Java and Bedrock, and Java's DataVersion has nothing to do with Bedrock's block_version. ## 4.3 Gable roof voxel rules `roof kind=gable [overhang=N] mat_slot=...` lowers to two opposite stair slopes meeting at a ridge. The four roof kinds (`gable`, `shed`, `hip`, `flat`) share the overhang and wall-top conventions below. Their layouts are this section and the three that follow. `overhang=` is read whatever the kind; `slope_to=` belongs to `shed` alone, and written on any other kind it is read by nothing and reported as `W_IGNORED_ARGUMENT` ([Lint §11.3](/spec/lint/#113-error-vs-warning)). **Material.** A sloped roof takes its material from `mat_slot=`, and it MUST be in the stair family (an id whose path ends in `_stairs`). The geometry attaches `facing`, `half`, and `shape` to whatever it paints, and a whole block cannot carry them. A binding outside the family is `E_INCOMPATIBLE_MATERIAL` and stops the build. With no `mat_slot=` at all the roof falls back to `minecraft:spruce_stairs`. The registry pack's four roof species (`roof.dark_wood`, `roof.light_wood`, `roof.warm_wood`, `roof.cool_wood`) all resolve inside the family. A binding inside the family that carries blockstates of its own keeps its id and loses those states to the geometry, with `W_DEFERRED_MEMBER`. An eave `stair kind=stairs` follows the same material rule, but takes its states from its own arguments. Those arguments are `facing=out | in`, `half=top | bottom` and `shape=straight | outer_left | outer_right`, each a bare identifier, defaulting to `out`, `top` and `straight`. An identifier outside the list is `E_INVALID_MEMBER`, and the stair is not built. A value of another shape (`half="bottom"`, `facing=1`) is an unreadable value: the stair is built with that key's default, and the value is reported as `W_IGNORED_ARGUMENT`. The value is reported even when the stair is refused for another reason, with a note saying the stair is not built either way ([Lint §11.3](/spec/lint/#113-error-vs-warning)). **Ridge axis.** The ridge runs along the long horizontal axis of the footprint. A square footprint (`size=WxW`) ties to `x`, giving an east-west ridge. **Ridge height.** A gable rises `ceil(short_span / 2)` voxels above the wall top, where `short_span` is `min(dims.x, dims.z)` after the overhang inflation. **Layers.** Layer `0` seats on the wall top and is a pair of slope rows, or one row when `short_span` is 1 and the two converge. Each layer above steps inward by one on each side. The topmost layer is the apex: - odd span: one `half=top` stair on the centre row. - even span: two `half=top` stairs on the adjacent meeting rows, so the ridge leaves no open V. A `short_span` of 1 or 2 rises exactly one layer, which is layer `0`, and has no apex course. **Overhang.** `overhang=N` inflates the voxel grid by `N` on both horizontal axes (`Dims.x = size.w + 2N`, `Dims.z = size.h + 2N`). Floors, walls, doors, and windows keep their authored coordinates and shift inward by `+N`. The roof spans the full inflated box, so eaves and gable ends extend past the wall ring. **Stair orientation.** Slope rows are `half=bottom, shape=straight` with `facing` pointed at the ridge: `south` on the `-z` slope and `north` on the `+z` slope for an x-axis ridge, `east` / `west` mirrored for a z-axis ridge. An even span's two apex stairs each face *away* from the ridge (`north` on the `-z` row, `south` on the `+z` row for an x-axis ridge). Facing inward would leave a 0.5 × 0.5 undercut along both outer faces for the roof's whole length; facing outward moves that void under the ridge. An odd span's single apex stair is `half=top` with the low-slope facing. One cell has two outer faces and a stair serves one, so the void is unavoidable and the rule fixes the choice. ## 4.4 Shed roof voxel rules `roof kind=shed slope_to=front|back|left|right [overhang=N] mat_slot=...` lowers to a single stair slope rising toward the wall named in `slope_to=`. Rows are shaped like a gable's low slope (`half=bottom, shape=straight`), but only one slope is emitted, so the opposite wall keeps its authored height. - **Slope axis.** `slope_to=front|back` rises along `z`; `slope_to=left|right` rises along `x`. The high edge sits on the named wall, the low edge on the opposite one. - **Height.** A shed rises `slope_span` voxels above the wall top: `dims.z` for `front|back` and `dims.x` for `left|right`, both after overhang inflation. Each layer steps inward by 1 from the low edge as `y` rises. - **Stair orientation.** Every slope stair points at the high edge: `front` → `facing=south`, `back` → `north`, `left` → `west`, `right` → `east`. The top layer is capped with one row at `half=top` and the same facing. - **`slope_to=` is required.** It has no default. A missing or unknown value is `E_INVALID_MEMBER` rather than a guessed direction. ## 4.5 Hip roof voxel rules `roof kind=hip [overhang=N] mat_slot=...` lowers to a four-sided stair pyramid: all four walls slope inward toward a centre ridge. - **Ridge axis and height.** As `gable`: long axis, square ties to `x`, `ceil(short_span / 2)` above the wall top. - **Layer layout.** Layer `L ∈ 0..extra_height` is the inset rectangle frame `[L, dims.x − 1 − L] × [L, dims.z − 1 − L]`. Layer `0` seats on the wall top and is always this frame, even when it is also the last layer: | Edge | States | |---|---| | north row (`z = L`) | `facing=south, shape=straight` | | south row (`z = dims.z − 1 − L`) | `facing=north, shape=straight` | | west column (`x = L`) | `facing=east, shape=straight` | | east column (`x = dims.x − 1 − L`) | `facing=west, shape=straight` | | NW / NE corners | `facing=south` with `outer_left` / `outer_right` | | SW / SE corners | `facing=north` with `outer_right` / `outer_left` | - **Apex.** The apex closes what the frames below it raised, so it applies only when `extra_height > 1`. It fills the top layer's whole inset rectangle with `half=top` stairs. A square footprint caps with a single stair (odd short span) or a `2x2` block of them (even short span). A rectangular footprint caps with a band along the long axis, one row deep on an odd short span and two on an even one, since the inset rectangle is two rows deep there and one row would leave the other open. Apex facings follow the gable rule. On an odd short span the apex takes the low slope's facing, `south` for an x-ridge and `east` for a z-ridge. On an even one each of its two rows faces away from the ridge: `north` on the `-z` row and `south` on the `+z` row for an x-ridge, `west` on the `-x` row and `east` on the `+x` row for a z-ridge. A square ties to `x`, so its `2x2` cap is the x-ridge pair (`north` / `south`). - **Overhang.** As `gable`. ## 4.6 Flat roof voxel rules `roof kind=flat [overhang=N] mat_slot=...` lowers to one layer of solid blocks at `y = wall_top + 1`, spanning the whole inflated bounding box. - **Material.** Every deck cell is the `mat_slot=` binding's id with no blockstate, falling back to `minecraft:spruce_planks`. A deck is whole blocks, so any id is valid where a sloped roof would refuse: a stair among them is a stair in its default state. - **Height.** A flat roof adds `1` to `Dims.y` whatever the footprint, so `size=WxH` with `walls height=K` gives `Dims.y = 1 + K + 1`. - **No slope arguments.** `slope_to=`, kind-specific facings, and ridge axes do not apply. ## 4.7 Level grouping and volume derivation `level y=N` groups members and places each of them `N` voxels above the struct's base plane. The `level` line itself lowers to no blocks; every member under it lowers as if written in the body with `N` added to its vertical coordinate. A `level` does not group a `circuit` line, whose reservation spans the whole scope: one under a `level` is `E_MISPLACED_MEMBER` ([Redstone §14.5](/spec/redstone/#145-place-and-route)). The volume a struct lowers into is derived, never written: ``` Dims.x = size.W + 2 × overhang Dims.z = size.H + 2 × overhang Dims.y = 1 + wall_top + roof_extra ``` Each term counts only the members that will paint: - `overhang`: the largest `overhang=` on any roof that will draw (a `kind=` the compiler knows, plus a `slope_to=` if that kind is `shed`). - `wall_top`: the largest `N + height` over the walls whose `mat_slot=` resolves, `N` being the enclosing level's offset and `0` in the body. - `roof_extra`: the tallest per-kind contribution from [§4.3](#43-gable-roof-voxel-rules)–[§4.6](#46-flat-roof-voxel-rules). - `1`: the base plane, which every struct has. Members inside a `level` count in all three, at their offset: `walls height=3` written directly gives `Dims.y = 4`, and the same walls under `level y=5` give `Dims.y = 9` (`1 + 5 + 3`). **Not every role lowers at a non-zero offset.** `walls`, `door`, `window`, `stair`, and `pressure_plate` read `N` as the base their geometry is measured from. A `floor` and a `roof` are planes a struct has one of, and what one under a raised `level` builds is reserved for a later extension: under `level y=N` with `N > 0` each fires `W_DEFERRED_MEMBER` and lowers to nothing. **A member that does not paint does not size the volume.** The `overhang=` of a roof under `level y=N` with `N > 0` does not widen the footprint, and its height does not raise `Dims.y`; under `level y=0` the roof draws, and widens and raises the volume as one in the body does. The same holds for every way a member drops out: a `roof` with no `kind=` or a `shed` with no `slope_to=` does not widen the footprint, and `walls` whose material does not resolve do not raise `Dims.y`. The material half applies to `walls` and not to `roof`, because a roof whose `mat_slot=` does not resolve falls back to a material of its own and still draws. A themeless struct shows the asymmetry: its walls are not built and take up no rows, while a `roof kind=gable` over them still draws, seated where it would sit with no walls at all. "Does the material resolve" is asked against the pinned target, so a block only some versions declare can change `Dims.y` between two `--target` values. An id the pinned target does not declare is `E_UNKNOWN_ID`, so no artifact ships from that shape. ## 4.8 Within-phase conflicts and the palette Across phases, the phase order decides: a `door` cut through `walls` is massing followed by openings, and the hole is the point. Inside one phase, only source order separates two members, which is what [§4.1](#41-phase-evaluation) grants to "local overrides within the same phase". That grant is for an author restating a member. Two footprints that intersect by accident are a different thing, so the compiler keeps the last write and emits `W_PHASE_CONFLICT` naming both members and how many voxels changed hands. The build is unchanged; the author is told that a line they could move is deciding the result. Two cases are not conflicts: - A cell whose value does not change, as when two `walls` of one material meet over shared rows. - A member writing over itself, as when a `window`'s `repeat=` / `step=` stamps overlap. **The palette** of an evaluated body (a `struct`, a `def`, and each `place` that instantiates one) is a *set with a canonical rendering*, not a log of the writes that filled it. It lists the blocks that body contains, and it lists them in one fixed order: air at slot `0`, then every other entry ascending by `(id, properties)`. The id decides first. When two entries share an id, each one's properties are sorted by name and the two lists are then compared pair by pair, so the **value** decides once the names agree (`facing=north` before `facing=south`), and a shorter bag sorts before a longer one that begins with it (`oak_stairs[facing=north]` before `oak_stairs[facing=north,half=top]`). Sorting the names is what makes the order independent of how a state literal happens to spell its properties: `@oak_stairs[half=top,facing=north]` and `@oak_stairs[facing=north,half=top]` name one block, and which of them a theme wrote first must not move a slot. "The blocks that body contains" has two exceptions. Slot `0` is one: air holds it whatever happens, so a fully paved volume still carries the entry. A slot that was never painted at all is the other, and it is kept on purpose. Dropping it would delete the only evidence a released build carries that a generator interned a material for geometry it does not emit. Two rules follow, and both exist because the numbering reaches the `.nbt`, `cairn info`'s per-entry rows, and `resolved_ir_hash`: - A material whose last voxel a later phase covered is **dropped**, and the remaining slots renumber onto the gap. Otherwise two sources differing only in which member lost would produce different artifacts for the same build. - Two members that share no voxel do not order each other. Nothing about the finished grid depends on which of their lines came first, so nothing about the artifact may either. That is the promise §4.1 opens with, and it is a claim about the bytes, not only about the voxels. Sorting is what makes it true: the palette is derived from the finished grid alone, so any permutation of the source that leaves the grid alone leaves the whole `BlockArray` alone. The sort is over the resolved state, so it is stable across editions and versions in the sense that matters: it does not consult source spans, member ids, phases, or paint order. It is not a claim that two targets agree on the palette, because two targets need not agree on the ids in it. The `.mcstructure` palette is written from this one and stays a set. Translating to Bedrock can map several entries to one Bedrock block (stairs that differ only in `shape`, once `shape` is dropped). Those entries share the first one's slot, so air stays at `0` and no Bedrock block is listed twice. A walkway's array is laid by the `connect` pass rather than by the phases, and is not covered here. # 5. Syntax ## 5.1 Lexical One line is one command, and `#` begins a line comment. The line starts with a command keyword; **every remaining argument MUST be `key=value`.** A truth table's braces are the one place a command may run onto the lines below it ([Literals and separators](#511-literals-and-separators)). ``` window side=front mat_slot=glass offset=2 y=2 size=2x2 sym=true # OK window front G 2 2 2x2 # forbidden (positional args) ``` Positional arguments would mean remembering argument order, which an LLM hallucinates and omits. Keys like `mat_slot=` and `side=` act as attention anchors and stabilize generation, which is worth more than the tokens they cost. A bare value on a line that reads none is `E_UNEXPECTED_POSITIONAL`. `connect FROM.PORT to TO.PORT` is the one form with a reader for positionals, and its shape is checked by `E_CONNECT_ARITY` instead. The parser puts anything that is not `key=`, `-> binding`, or `[selector]` into the positional list, so a dropped `=` lands there too. `walls mat_slot=wall height 3` is not a `walls` with a shortened height. It is not built at all. Only a member line (a line of a `struct`, `def` or `site` body) keeps a positional list so far. The header line of a `struct`, `def`, `site` or `theme`, a `theme` rule, and a `logic` or `assert` line do not yet, so the same slip there is `E_PARSE`, which ends the parse: `struct s size 3x3` is refused with "expected `=`". ### 5.1.1 Literals and separators **Subject to change.** Decimals (`scale=1.5`), coordinate triples (`at=4,3,2`) and `nbt={...}` values, which other chapters write, do not parse yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). No `key=` value starts with `-`, so a negative number does not parse: `offset=-1` is `E_PARSE`. The parser reads a number only as a run of decimal digits so far, up to 2^63 − 1, or 2^32 − 1 for the `within` bound of an `assert`. A decimal such as `scale=1.5` ([Entities](/spec/entities/)) is therefore `E_PARSE` too until the parser reads one. A size literal is exactly two non-zero extents, `WxH`. A run that continues past the second, such as `2x2x9` or `2x2y`, is refused at the literal rather than read as a size followed by something else. Commas are **optional separators**, not structure. `@intended_targets ["1.20.4", "1.21.4"]` and `@intended_targets ["1.20.4" "1.21.4"]` name the same two versions, as do `[side=front, y=2]` and `[side=front y=2]`. The two list kinds differ in how much punctuation they tolerate: - A `[selector]`'s attribute list skips a comma wherever it finds one, so `[side=front, , y=2]` parses. - A value list reads at most one comma between items and refuses `[a, , b]`. A canonical token may carry a **block-state literal**, as in `@oak_log[axis=x]` or `@oak_stairs[half=top, facing=north]`. The `[` must touch the token. After a space it is whatever comes next, so in a value list `[@a [b]]` is still a token and a nested list, while `[@a[b]]` is refused because `b` is not a property. Each pair inside is `property=value`, where the value is a word, a run of digits, or `true` / `false`. This is Minecraft's own block-state syntax rather than a Cairn list, so exactly one comma separates two pairs. An empty literal, a trailing or doubled comma, and a property named twice are refused. A dotted token such as `@floor.wood` is abstract and takes no literal, because the theme that binds it chooses the block, so a `[` touching it is whatever comes next, as one after a space is. Reading a touching `[` as the literal refuses no source that could build otherwise. Read as whatever comes next, `mat_slot=@a[1]` would leave a bare value on a member line that reads none, which is `E_UNEXPECTED_POSITIONAL`, and `mat_slot=[@a[b]]` would put a list where a label belongs, which is `E_TYPE_MISMATCH_LABEL`. The literal's properties and values are not yet checked against the target: `E_STATE_DOMAIN` ([Versioning and Editions](/spec/versioning-editions/)) is not implemented, so a Java build writes `@oak_log[axis=q]` as written. Each literal the build reads earns a `W_STATE_LITERAL_UNCHECKED` ([Lint](/spec/lint/)) on the token, so that is said rather than silent. Besides that literal, the one place a comma carries meaning is the input list of `assert truth(...)`, where it separates the signals whose count the row width is checked against. A row writes one character per input signal (`0`, `1`, or `-`), so `truth(a, b -> out)` takes rows two characters wide and refuses `{ 2->0 }` or `{ 0->0 }`. `-` is a **don't-care**: the row means every value of that input, so `0- -> 1` says what `00->1` and `01->1` say together. It is a shorthand for those rows and not a construct of its own, which is why two rows may not both stand for one combination (see the table below). `-` and `->` share a character, and the lexer takes the arrow whenever it can. A row whose last input is a don't-care is therefore written `11--> 0` or `11- -> 0`; both are the same three-wide row. Whitespace ends a pattern, so `0- 1 -> 1` is a two-wide pattern and a stray `1`, not a three-wide row. A row's **output** is `0`, `1`, or `-` as well, and there it means something else: the row's combinations are deliberately unconstrained. `--0 -> -` says the table has nothing to say about any combination with a low third input, which is what answers `W_TRUTH_TABLE_PARTIAL` without asserting four outputs the author does not mean. The arrow is already read by then, so `-> -` and `->-` are the same row. A table every row of which has a `-` output constrains nothing and is `E_TRUTH_TABLE_EMPTY`, the same as a table with no rows. The table around those rows is read the same way: | Case | Code | |---|---| | One signal listed as two or more inputs | `E_TRUTH_TABLE_DUPLICATE_INPUT` (and nothing else for the table until each signal is listed once) | | No rows at all, or no row with a `0` or `1` output | `E_TRUTH_TABLE_EMPTY` | | Two rows assign one input combination different outputs | `E_TRUTH_TABLE_CONFLICT` (on the later row) | | Two rows cover one input combination without contradicting each other | `W_TRUTH_TABLE_DUPLICATE_ROW` (on the later row) | | Some input combinations are unassigned | `W_TRUTH_TABLE_PARTIAL` | The last two are warnings because the rows that *are* present still assert what they say. A four-input table is sixteen rows, and an author part way through is not blocked. Between the braces a line break may come before or after any row, after a row's `;`, and before the `}`, so a table can sit on its `assert` line or give each row a line of its own: ``` assert truth(sig.a, sig.b, sig.enable -> sig.out) { 001 -> 0 011 -> 1 101 -> 1 111 -> 1 } ``` Inside the braces a line carries no indentation: the rows and the closing `}` may sit at any depth, and blank and comment lines between them are skipped. A tab in front of a row or the `}` is still refused, as it is in front of a command. A row is still one line, so a break between its pattern, its `->` and its output is refused. The `{` stays on the `assert` line, and a `;` ends the row in front of it on that row's line, so no line may open with one. A table whose `}` is missing is refused at whatever follows its last row, such as the next command, or at the end of that row's line when nothing does. Indentation is two spaces per level and opens one level at a time. A width that is not a multiple of two and a jump of more than one level are different mistakes and are reported as such. Neither can be made inside a truth table's braces, whose lines carry no indentation. Spaces before a line break are not part of the line, so a row may end in them, and a line holding nothing but spaces is a blank line. A blank line's leading spaces are counted like any other line's and then discarded with the line, so their width is neither an indent nor a mistake. A UTF-8 byte-order mark at the very start of a file is ignored; one anywhere else is an ordinary stray character. A line ends at `\n`, at `\r\n`, or at a lone `\r`, and all three are the same line break. VS Code and Monaco use the same rule, so a diagnostic's line number and the line under the cursor name the same row. A position always points at the text that is wrong, so an error at the end of a line is reported there and never at the first column of the next one. The tree-sitter grammar is a known exception in two ways. Its runtime advances the row on `\n` alone, so a file terminated only by lone `\r` highlights as one long line even though it parses correctly. It also accepts six forms the parser refuses, because tree-sitter cannot express their rules: a size with a zero extent (`0x3`), a third extent (`2x2x9`) or a trailing word (`2x2y`), an integer past 2^63 − 1, a truth row whose width differs from the input count, and a block-state literal naming one property twice. ## 5.2 Nesting Keep nesting shallow: `struct` / `def` / `level` / `theme` / `site`. Deep nesting increases LLM generation errors. (`room` is not on this list; it is still open, so writing one today is `E_UNKNOWN_KEYWORD`. See [Open Issues](/spec/open-issues/).) Inside a body, `level y=N` is the only member that groups other members, and only in a `struct` or a `def`. A `site` body is a flat list of `place` and `connect` rows with no grouping construct at all. An indented body anywhere else is `E_UNSUPPORTED_NESTING` rather than a silent drop. It lowers to nothing, places nothing, and lays no walkway. That rule is about members, and reaches only bodies that hold them. A `theme` body holds rules, which bind materials and open nothing, so a line indented under one is a syntax error and not a nesting diagnostic. So is a line indented after a directive: a directive is one line, and the line under it belongs to no construct. [Compilation Model §4.7](/spec/compilation/#47-level-grouping-and-volume-derivation) defines what `y=N` means to each grouped member. **Which keywords a body accepts** follows the same split. A `struct` / `def` body describes one building's geometry: `floor`, `walls`, `door`, `window`, `roof`, `stair`, `level`, `pressure_plate`, `circuit`. A `site` body describes a layout: `place`, `connect`. The keyword table is global, so writing one in the other body parses and classifies and then reaches nothing. That is `E_MISPLACED_MEMBER`, reported once at the offending row, taking anything indented under it along. A `level` groups the other members of a `struct` / `def` body, but not a `circuit` line, whose reservation spans the whole scope: a `circuit` line under a `level` reaches nothing either, and is `E_MISPLACED_MEMBER` on that line ([Redstone §14.5](/spec/redstone/#145-place-and-route)). `logic` and `assert` lines are not members, so the rule does not reach them. A `logic` line is read by redstone synthesis from either body. An `assert` is checked for its own shape and its names: `cairn check` checks a truth table ([Literals and separators](#511-literals-and-separators)), and redstone synthesis resolves the signals it names (`E_LOGIC_UNBOUND_SIGNAL`). Nothing verifies it against a built circuit yet. **Top-level names are scoped per kind.** `theme` / `def` / `struct` / `site` are four namespaces, so one name may appear once in each. Declaring it twice within one kind is `E_DUPLICATE_ITEM`. For `theme` / `def` / `struct` the name is what binds, so the first declaration resolves and the repeat would otherwise vanish without a signal. Two `site` blocks of one name merge instead, sharing one `site::NAME::` namespace, but `east_of=` cannot reach across the blocks. The merge is half a merge, and still an error. ## 5.3 Headers Metadata MAY go in headers rather than in the semantic body: ``` @cairn 2026.06 # the Cairn language version this file was written against @requires version>=1.20 # capability floor on the Minecraft target @intended_targets ["1.20.4","1.21.4"] # a hint, not a verification record ``` **`@cairn`** is the version of the Cairn language itself, a separate axis from the two Minecraft headers. It is optional and exists as provenance, so a future compiler can parse and warn correctly. No pass branches on the value, but it is read: `YYYY.M` or `YYYY.M.PATCH`, with a four-digit year and a month `1 … 12`. A leading zero on the month is accepted, so `2026.06` and `2026.6` are one version. Anything else is `W_INVALID_CAIRN_VERSION`, and a version later than the compiler reading it is `W_FUTURE_CAIRN_VERSION`: provenance that a later compiler cannot read is not doing the job the header exists for. **`@requires`** is a capability floor. Its expression is an optional edition, the subject `version`, the operator `>=`, and a version label. Whitespace is optional around the operator, so `version>=1.21` and `version >= 1.21` are one requirement, and required after an edition: `javaversion>=1.21` is `E_INVALID_REQUIRES`. `>=` is the only operator, since a floor is the only constraint that composes by folding to the strictest. Every other expression is `E_INVALID_REQUIRES` rather than a line that quietly declares nothing: a floor that evaporates is worse than an absent one, because a reader will still believe it. ``` @requires version>=1.21 # a floor on whichever edition is built @requires java version>=1.21.4 # a floor in Java's numbering, inert on a Bedrock build @requires bedrock version>=1.21.40 ``` The edition is there because Java releases run `1.20.4 / 1.21 / 1.21.4` and Bedrock `1.21.0 / 1.21.40 / 1.21.60`: `1.21.4` is Java's newest release and names no Bedrock release at all. A label is dot-separated components that each begin with a digit and carry only letters and digits, with an optional `-` and a pre-release tag of dot-separated letters and digits. `1.21.4`, `1.21.4-rc1`, and `24w14a` are all labels. Which of them the *target edition* can order is not a syntax question and is not answered here. See [Versioning and Editions](/spec/versioning-editions/). **`@intended_targets`** says which Minecraft versions the file was designed for. It is not a claim of being verified. That record lives only in the lock. A hint is still weighed against the floor beside it. Take the versions a file's `@intended_targets` names that the target edition can build. If its `@requires` refuses every one of them, the file states an intention the compiler will refuse the moment anyone acts on it, and that is `E_INTENDED_TARGET_CAP`. A list only partly below the floor is `W_INTENDED_TARGET_CAP`, and a version the target edition cannot build at all is `W_INTENDED_TARGET_UNSUPPORTED`. See [Versioning and Editions §10.4](/spec/versioning-editions/#the-hint-is-weighed-against-the-floor). `@cairn` and `@intended_targets` appear at most once per module, and a repeat is `E_DUPLICATE_HEADER`. `@requires` is the exception: its floors compose, so repeating it adds a constraint rather than displacing one. A `def` or a `theme` may carry the same expression as a body line, spelled `requires` without the `@`. It is a floor on that part rather than on the file, inherited by every build that instantiates it. The sigil is what marks a file directive, and a part's floor is not one. See [Versioning and Editions](/spec/versioning-editions/). ## 5.4 Selectors Wall selectors are `front` (+z), `back`, `left`, and `right`. `offset` runs along the wall, and `y` is measured from the floor (`y = 0`). Inside faces are prefixed: `inside.front`. Blocks, block entities, and entities all use one selector grammar. **`offset` origin.** `offset=0` sits at the wall's left end viewed from outside that wall. The `front` and `back` walls anchor at low `x`, `front` from the +z viewpoint and `back` mirrored along x so a `sym=true` opening looks symmetric from either side. The `left` and `right` walls anchor at low `z` and mirror the same way. `sym=true` mirrors the opening across the wall's midpoint (`mirror_offset = wall_length - offset - size_w`). A mirror overlapping the primary rectangle is rejected with `W_DEFERRED_MEMBER`, and only the primary is painted. That includes the mirror of a window centred on the wall's midpoint (`2 * offset + size_w = wall_length`), which coincides with the primary. A mirror that only touches the primary, beginning in the column after the primary's last (`2 * (offset + size_w) = wall_length`) or ending in the column before its first (`2 * offset = wall_length`), shares no cell with it, so it is neither rejected nor reported: both are painted, and read as one opening twice the window's width. `sym=` takes a bare `true` or `false`, and a window without it is not mirrored. Any other value (`sym=yes`, `sym="true"`, `sym=1`) is an unreadable value: the window is drawn without its mirror, and the value is reported as `W_IGNORED_ARGUMENT` ([Lint §11.3](/spec/lint/#113-error-vs-warning)). A window whose `repeat=` is greater than 1 is the exception. Mirroring a series is reserved for a later extension, so a `sym=true` series is not cut yet and is reported as `W_DEFERRED_MEMBER`, and an unreadable `sym=` is not read as `false` there: that window is not cut either, and is reported as `W_DEFERRED_MEMBER` beside the `W_IGNORED_ARGUMENT`. **`at=` door anchors.** A door's wall-local column comes from one of three named anchors: | Anchor | Column | |---|---| | `at=center` | `u = floor(wall_length / 2)`. Odd walls have a unique centre; even walls pick the column right of the midpoint. | | `at=left` | The wall-local axis origin, `u = 0`. | | `at=right` | The far corner, `u = wall_length - 1`. | The same column resolves both the openings cut and any `connect` walkway anchored to this door ([§9.3.5](/spec/components-editing-sites/#935-ports-and-connect)). Numeric offsets (`at=N`) are reserved for a future extension. A door with no `at=`, or one that names no anchor, is `E_INVALID_MEMBER` and cuts nothing. **Which rows a door opens.** A door under `level y=N` opens at row `N + 1`, the row above that level's base plane. It takes the two rows a doorway wants, or, if fewer remain, as much of that row's wall course as is left counting the row it opens at. A door under a one-row course therefore opens that one row rather than cutting into the roof. The row it opens at MUST be inside a course of the masonry. A door whose row no `walls` member is written to hold is `E_INVALID_MEMBER` and cuts nothing, the same finding the `window` on that body earns. A door in a course whose `walls` paint nothing, or beside `walls` under a `level` that is not placed, is `W_DEFERRED_MEMBER` instead, since the repair is on those walls or that level ([§9.3.5](/spec/components-editing-sites/#935-ports-and-connect) states the courses a `walls` paints). ## 5.5 IDs, classes, addresses **Subject to change.** The address the compiler gives a member without `id=`, and the `edit` patch DSL that would use it, are not built yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). Today such a member has no address, and a top-level `edit` is `E_PARSE`. Important members MAY declare `id=`, and `class=` groups members. Members without an `id=` get a stable, meaning-based address assigned by the compiler, derived from parent / role / side / level / offset. See [Components, Editing, and Multi-building §9.2](/spec/components-editing-sites/#92-editing-model). A `place` row is the exception: its `id=` is required, and omitting it is `E_INCOMPLETE_PLACE`. An auto-address names nothing outside the body it sits in. A `place`'s `id=` is what `east_of=` and `connect` refer to, and what its `.nbt` is written under, so an invented one would be a name the author never wrote and cannot point at. # 6. Blockstate Model ## 6.1 Derive by default, promote on override **Subject to change.** Of the overrides below, only a stair's `facing`, `half` and `shape` are built. The others, the `beam`, `chest` and `note_block` keywords, and coordinate triples are not ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). By default the compiler derives blockstate from position and neighbours: stair facing, door orientation, glass-pane and fence and wall connections, chest left/right, and so on. Of these, only stair geometry is derived today. A `roof` gets its stairs' `facing`, `half` and `shape` from where they sit. An eave `stair` gets only its cardinal `facing`, from the side it sits on, and its `half` and `shape` are what its line writes, or `top` and `straight`. A `door` cuts its opening and places no door block. Pane, fence and wall connections, chest pairing and the torch and sign substitution below are not derived yet, so `cairn lower examples/cottage.crn` writes a bare `minecraft:glass_pane`. Any blockstate that can be architectural intent is overridable, and **the moment you write it, it is promoted to intent**. Cairn does not adopt the strong reading, "if it can be derived, don't let the author write it". The rule is "derive by default; any blockstate that can be intent is overridable". Cases that MUST stay overridable, because each can be intent: | Group | States | |---|---| | Stairs | `facing` (a stair as a chair or decoration), `half=top` (upside-down eaves), `shape` | | Furniture | `chest size=single` (auto-merging from adjacency is forbidden), `bed facing`, `door hinge` / `open` | | Orientation | `log` / `pillar axis` (a horizontal beam), `trapdoor open` / `half`, `glazed_terracotta` rotation | | Counts | `snow layers`, `candle count` | | Redstone | `redstone_dust connect`, `repeater delay`, `observer` / `piston` / `dispenser facing`, `note` / `instrument` | Two easy-to-miss cases belong to derivation, not intent: `torch` ↔ `wall_torch` and `sign` ↔ `wall_sign` are substituted automatically by attachment face. The example below uses syntax the parser does not accept yet. Only its `stair` line is accepted: `beam`, `chest` and `note_block` are `E_UNKNOWN_KEYWORD`, and a coordinate triple such as `at=2,1,2` is `E_PARSE`. ``` stair id=eave kind=stairs mat_slot=roof side=front half=top facing=out shape=outer_left # eaves beam id=lintel kind=pillar mat_slot=frame at=front.top axis=x # horizontal beam chest id=store at=inside.back size=single note_block at=2,1,2 instrument=bit note=12 ``` ## 6.2 `intent_state` and `resolved_state` ```yaml member: id: eave type: block | block_entity | entity # typed in the IR; the distinction is the compiler's job primitive: stairs intent_state: { half: top, facing: out, shape: outer_left } # author intent. Edit diffs look only here resolved_state: { facing: south, waterlogged: false } # derived, including paint-derived state ``` The two are named apart from Minecraft's own term "blockstate" on purpose. Keeping resolved state (derived or paint-origin) out of intent state (authored) is what makes edits stable. The IR does not hold this shape yet. `resolved_state` is never populated: the blockstate that lowering derives goes straight into the block array's palette. `intent_state` carries every `key=value` the line writes, blockstate or not, except `id`, `class` and `mat_slot`, which become fields of their own. In place of `type`, a member carries the `role` its keyword classifies to. `bed` is treated as a block member rather than an entity, to keep the IR types clean. ## 6.3 `waterlogged` **Subject to change.** Nothing in this section is built yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). No pass sets or reads `waterlogged`: on a `stair`, `waterlogged=false` is an unreached key, reported as `W_IGNORED_ARGUMENT` ([Lint §11.3](/spec/lint/#113-error-vs-warning)), and the stair is built as if the key were not written. In the example below, `fill`, `trapdoor` and `water` are `E_UNKNOWN_KEYWORD`, and a coordinate triple such as `from=1,1,1` is `E_PARSE`. The default is paint-derived: when `fill fluid=water` overlaps a waterloggable block, the compiler sets `waterlogged`. A three-valued `waterlogged=auto|true|false` is allowed, for leaving an air pocket inside a tank (explicit `false`), distinguishing source from flowing, and version differences in the waterloggable table. Flowing water is made explicit with `flow=` and `level=`. Like the overrides in [§6.1](#61-derive-by-default-promote-on-override), `waterlogged=` is written on a member that places one block and names that block's state, and of the keywords the compiler knows only `stair` does. A `roof` or a `window` derives the state of every block it lays and takes no override, so `waterlogged=` on either is `E_UNKNOWN_ARGUMENT`. ``` fill fluid=water kind=source from=1,1,1 to=5,3,5 # overlapping fences/stairs/signs auto-waterlogged trapdoor id=shutter at=.. waterlogged=false # an air window in a tank water id=stream from=.. flow=east level=4 ``` # 7. Materials and Themes ## 7.1 Slots as dependency injection **Subject to change.** Selector bindings, the `key=value` pairs right of a selector row's arrow, are reserved and not built ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). The structure never writes a concrete block name. It carries `mat_slot` injection points, and a `theme` binds values to slots and selectors, the way CSS or dependency injection does. That separates structure (where the walls are) from style (which blocks, what detailing). ``` def cottage class=house size=9x7: floor id=floor mat_slot=floor walls id=walls class=outer mat_slot=wall height=4 roof id=roof kind=gable mat_slot=roof window id=front_windows class=small side=front y=2 offset=1 size=2x2 repeat=2 step=5 mat_slot=glass theme medieval: slot floor -> @spruce_planks slot wall -> @cobblestone slot roof -> @spruce_stairs slot glass -> @glass_pane walls[class=outer] -> trim=@spruce_log # part detailing, via a selector (reserved) window[class=small] -> frame=@spruce_wood ``` **The cascade.** A member collects the bindings of every selector row it matches, in source order, so when two rows bind the same key the member keeps the later value. CSS applies the same rule to two rules of equal weight. Bindings are reserved (below), so today the cascade decides what a member collects and nothing that is built. Rows whose attributes partly overlap rely on that: `window[class=small,side=front]` refines `window[class=small]` for the members it selects, and the members only the wider row selects keep the wider row's binding. Two rows that select the *same* members are different. Same keyword and same attributes means they match member for member, so no member keeps the earlier row's value of a key they both bind: that value is dead text whatever a binding comes to mean. That is `E_DUPLICATE_SELECTOR` ([Lint §11.1](/spec/lint/#111-diagnostic-codes)), an error even while bindings are reserved, for the reason `E_DUPLICATE_ARG` refuses one key written twice inside one row ([Lint §11.3](/spec/lint/#113-error-vs-warning)). Sameness is by meaning: attribute order does not count, and `class=` / `id=` / `mat_slot=` values compare as label text, so `window[class=small]` and `window[class="small"]` are one selector. Rows that coincide but bind different keys are not reported. They compose, and splitting a long binding list over two lines is allowed. **Selector bindings are reserved.** Which keys a row may bind on each keyword, and what each one paints, is not specified yet, and no lowering reads a binding. The two selector rows above build the same cottage as a theme without them, and no member's block depends on them. Until that is specified, the compiler reports each binding as an unreached key, `W_IGNORED_ARGUMENT` ([Lint](/spec/lint/)). It does so whatever the key or value, on every row whose keyword it knows, whether the row matched and whether its theme was applied. A row whose keyword it does not know gets `E_UNKNOWN_KEYWORD` instead. A binding's value is not resolved as a block either, because what the key would paint is not specified: `frame=@no_such_block` is reported exactly as `frame=@spruce_wood` or `frame=42` is, with or without `--target`, and no binding makes `check`, `compile` or `info` refuse a build. Binding one key twice for the same members does refuse a build, since the earlier value is dead text whatever a binding comes to mean. Within one row that is `E_DUPLICATE_ARG`; across two rows that select the same members it is `E_DUPLICATE_SELECTOR`. The rest of a row is still checked: `E_THEME_SELECTOR_UNMATCHED` applies to it exactly as its own entry says. `def`, `theme`, and `site` are unified by the same slot-bearing Component mechanism ([Components, Editing, and Multi-building](/spec/components-editing-sites/)). ## 7.2 Canonical vocabulary A theme binds **canonical tokens**, not raw block IDs. The backend resolves the ID, state names, state values, and serialization per `(edition, version)` ([Versioning and Editions](/spec/versioning-editions/)). An LLM never needs to know `pillar_axis`, little-endian NBT, or Bedrock's `weirdo_direction`. The backend resolves less than that today. A canonical token is written as `minecraft:` and checked against the pinned target ([§7.3](#73-mappings-across-version-and-edition)), so `@water_cauldron` is `E_UNKNOWN_ID` on every Bedrock version, and the Bedrock writer maps the states of the stair family alone: `@oak_log[axis=x]` compiles for Java and is refused for Bedrock. Tokens come in two kinds: | Kind | Example | What it means | |---|---|---| | **Canonical block token** | `@oak_planks`, `@water_cauldron`, `@oak_log[axis=x]` | A specific meaning in Minecraft. Silent meaning-breaking downgrades are **forbidden**, so `@water_cauldron` may never become `cauldron`. | | **Abstract material token** | `@floor.wood.broadleaf`, `@roof.dark_wood` | An aesthetic choice. Theme policy MAY downgrade these (oak ↔ birch). | ``` theme cottage: slot floor -> @floor.wood.broadleaf # abstract: resolved by target and policy theme exact_oak: slot floor -> @oak_planks # canonical: pinned 1:1 ``` An abstract token resolves through the registry pack's `materials` catalog, which maps it to a block, and an entry's `overrides` name the versions that spell that block differently ([Versioning and Editions §10.4](/spec/versioning-editions/#104-fail-loud-and-minimum-version-inference)). A token the catalog does not declare is `E_UNKNOWN_ABSTRACT_TOKEN` ([Lint](/spec/lint/)) wherever a pack is offered: at a pinned target, and in `cairn lower` and `cairn info`. ### Tier-1 tokens The abstract tokens the built-in `materials` catalogs declare are the **tier-1** vocabulary, which [Compatibility Tiers](/spec/compatibility/#c1-tier-definitions) holds Stable. Both editions' catalogs declare the same tokens, so a theme that binds only these resolves on either: | Tokens | For | |---|---| | `@floor.wood.broadleaf`, `@floor.wood.conifer`, `@floor.stone.cobble`, `@floor.stone.smooth` | Floors | | `@wall.wood.broadleaf`, `@wall.wood.conifer`, `@wall.stone.cobble`, `@wall.stone.smooth` | Walls | | `@wood.dark`, `@wood.light`, `@wood.warm`, `@wood.cool` | Planks, by tone | | `@roof.dark_wood`, `@roof.light_wood`, `@roof.warm_wood`, `@roof.cool_wood` | Roof stairs, by tone | | `@sign.oak`, `@sign.oak_wall` | A standing sign and a wall sign | | `@pressure_plate.default` | The block a `pressure_plate` places when no `mat_slot=` binds one | The block a tier-1 token resolves to is **tier-2**, which is Evolving: it is the catalog's answer for the target, and a release may change it. Adding a token to the catalogs breaks nothing. Renaming or retiring one is a break to a Stable surface, so the old token keeps resolving, with `W_DEPRECATED`, for the deprecation window. A canonical block token is neither tier-1 nor tier-2. It names a block through the mappings of [§7.3](#73-mappings-across-version-and-edition), and the names a target accepts follow its registry pack. [Compatibility Tiers](/spec/compatibility/#evolving) holds them Evolving. ## 7.3 Mappings across version and edition A canonical token absorbs five patterns. The resolution table's structure is in [Versioning and Editions](/spec/versioning-editions/). | Pattern | Example | Policy | |---|---|---| | Rename 1:1 | `@dirt_path` (was `grass_path`) | Auto-resolve. | | Split 1:N | `@cauldron[fluid=water]` → `water_cauldron` | Separate by meaning token. | | Merge N:1 | `@oak_slab` (was `wooden_slab{variant}`) | Resolve per target. | | New | `@cherry_planks` | Needs a `requires >=` floor. | | Deleted | Absent in the target version | Hard error plus alternatives. | Today only the last row holds as written. A canonical token is written as `minecraft:` and checked against the pinned target ([Versioning and Editions §10.4](/spec/versioning-editions/#104-fail-loud-and-minimum-version-inference)). A rename is `E_UNKNOWN_ID`, with a note naming the target's spelling from the registry pack's `aliases` (`@dirt_path` on Bedrock is answered with `minecraft:grass_path`); only an abstract token resolves across a rename, through its catalog entry's `overrides` ([§7.2](#72-canonical-vocabulary)). A split is not separated: `@cauldron[fluid=water]` is written as `minecraft:cauldron[fluid=water]` with `W_STATE_LITERAL_UNCHECKED`. A merged id is checked per target like any other. No floor is inferred for a new block: `@pale_oak_planks` with no `@requires` checks clean on Java 1.21.4 and is `E_UNKNOWN_ID` on a target that lacks it. A deleted id is `E_UNKNOWN_ID`, naming the nearest block the target has when one is near enough. **Only ID, state, and serialization differences may be absorbed.** Concept absence and game-behaviour differences are not. # 8. Entities ## 8.1 Two tiers **Subject to change.** Nothing in this section is built yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). Opening up `nbt={}` for everything would destroy theming, editing, linting, and version tolerance. So important entities are **structured**, which lets them ride the named-member editing model. The promotion criterion: an entity with attributes you want to edit, or attributes that absorb version differences, is structured. Only one-off special NBT escapes through `nbt={}`. - **Structured, first-class**: `sign`, `painting`, `item_frame`, `armor_stand`, `villager` (plus `trade`), `display` (text / block / item), and `bed` (treated as a block). - **Generic fallback**: `spawn id=.. type= at= [nbt={...}]` for other mobs. None of these is a keyword yet, `spawn` included: each is `E_UNKNOWN_KEYWORD`, so no build places an entity or a block entity. The example below also uses syntax the parser does not accept yet: a coordinate triple (`at=4,3,2`), a decimal (`scale=1.5`) and an `nbt={...}` value are `E_PARSE` ([Syntax §5.1.1](/spec/syntax/#511-literals-and-separators)). ``` villager id=trader at=stall[0] profession=librarian level=master trade villager=trader buy=emerald count=24 sell=enchanted_book enchant=mending text_display id=holo at=4,3,2 text="Inn" billboard=fixed scale=1.5 block_display id=model at=front.above block=@lantern scale=0.5 item_display id=trophy at=counter item=diamond_sword rotation=y90 spawn id=cat type=cat at=inside.floor nbt={variant:"black"} ``` A villager trading hall is a staple build and display entities are core to modern decoration. Sending them to `nbt={}` would cost generation quality and edit stability, so they are structured. Block entities (signs) and true entities (paintings) are different things in NBT but share one selector grammar in the DSL. Telling them apart is the compiler's job. ## 8.2 Anchor conventions **Subject to change.** `painting` and the anchor keys below (`anchor=`, `shape=`, `footprint=`, `bounds=`) are not built yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). Paintings, item frames, arch windows, stairwells, and overhanging roofs have a declared size that differs from the AABB they occupy. Left ambiguous, edit stability, theme swapping, and cross-implementation compatibility all break. This is the top open issue in this chapter. Every primitive therefore carries four things in the IR: an `anchor` (reference point), a declared bbox, an actual bbox, and a host face. The IR carries none of the four yet. In the example below, `painting` is `E_UNKNOWN_KEYWORD`, and the window's `anchor=` and `shape=` and the roof's `footprint=` and `bounds=` are accepted but read by no pass, so each is `W_IGNORED_ARGUMENT` ([Lint](/spec/lint/)). Overlapping AABBs resolve by a rule the spec fixes, either priority merge or a lint error ([Lint](/spec/lint/)). Neighbour-dependent blockstate (stairs, fences) breaks when overwritten without interference detection: an inner-corner stair left as an outer corner, hanging in mid-air. Re-resolving boundary blockstate is the IR layer's responsibility. ``` painting id=hall_art side=inside.front anchor=center y=2 variant=kebab window id=arch1 side=front anchor=bottom_center offset=4 y=2 size=3x3 shape=arch roof id=roof kind=gable footprint=struct overhang=1 bounds=expand ``` ## 8.3 Where the line is drawn Signs, paintings, item frames, and beds contribute to a build's architectural feel, so they are adopted. Chest contents, villager inventory, and other information that does not contribute to architectural precision is not structured. It goes to the generic `spawn` `nbt={}` or the escape hatch. # 9. Components, Editing, and Multi-building ## 9.1 `def`, the component construct **Subject to change.** A header's `class=` is accepted, but no pass reads it yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). `def` defines a slot-bearing Component, unified with `theme` and `site` by the same mechanism, so the reference system does not fracture across editing, theming, and multi-building. Parameterization (variable size and so on) is allowed; recursion is forbidden. A `def` may declare `requires version>=X`, and the minimum version of a composite is the max of its parts ([Versioning and Editions](/spec/versioning-editions/)). Until a parameter mechanism is specified, the header vocabulary is closed. A `def` header takes `size=`, which lowering reads, and `class=`, which no pass reads yet, and a `struct` header takes the same two. Any other key on either is refused as `E_UNKNOWN_ARGUMENT`, and a header `class=` is reported as `W_IGNORED_ARGUMENT` ([Lint §11.3](/spec/lint/#113-error-vs-warning)), so the sample below carries that warning. ``` def cottage class=house size=9x7: floor id=floor mat_slot=floor walls id=walls class=outer mat_slot=wall height=4 door id=door class=entry side=front at=center roof id=roof kind=gable mat_slot=roof ``` ## 9.2 Editing model **Subject to change.** The address the compiler gives a member without `id=`, and the `edit` patch DSL that would use it, are not built yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). Important members carry `id=`. Members without one get a **meaning-based stable address** derived from parent / role / side / level / offset rather than from generation order, so addresses stay stable when you append to a struct. No pass derives that address yet: today a member without `id=` has no address. Edits are a patch DSL against a selector or address: ``` edit window[class=vent][level=floor2] set shape=arch edit window@front[0] set mat_slot=accent_glass edit door[id=entry] set side=front at=center ``` `edit` is not accepted yet. A top-level `edit` line is `E_PARSE`, since the only top-level items are `theme`, `def`, `site` and `struct`, so no edit is applied today and the edit-diff rule below has nothing to compare. Editing at the level of a concept, such as "make only the second-floor windows arched", must be possible without breaking the whole. Edit diffs look only at `intent_state` ([Blockstate Model](/spec/blockstate/)), so a change in derived results does not harm edit stability. ## 9.3 Multi-building with `site` Never make the AI do absolute-coordinate arithmetic. Placements are topological constraints; resolving them to coordinates is the compiler's job. ``` site village: place id=home1 use=cottage theme=medieval at=origin place id=home2 use=cottage theme=medieval east_of=home1 gap=4 connect home1.door to home2.door path=@gravel ``` Each struct exposes ports (position, normal, width) and `connect` joins them. Villages and castles past the structure block's 48³ limit are expressed as a composition of several structs. ### 9.3.1 Coordinate convention `east` advances along `+x` and `north` retreats along `-z`. This matches "front is `+z`" from [§5.4](/spec/syntax/#54-selectors): a building whose `front` faces south sits with its facade on `+z`, and `north_of=X` puts the next placement behind it. The four wall selectors face outward along `front` `+z`, `back` `-z`, `left` `-x` and `right` `+x`. The Y axis is unaffected by topological selectors; every placement currently lands at `y = 0`. ### 9.3.2 Origin selectors Each `place` carries **exactly one** of `at`, `east_of`, `north_of`. In the formulas below, `prior` is the placement `ID` names and `new` is the one being placed. An origin is a placement's low-`x`, low-`z` corner, and `dims` is its full extent: the `size=WxH` footprint plus the roof's `overhang=` columns on each side, the same inflated extent the lockfile records. | Selector | Effect | Notes | |---|---|---| | `at=origin` | Anchors at world `(0, 0, 0)`. | The only legal `at=` value. The first `place` in a site must use it, since there is no implicit default. | | `east_of=ID gap=N` | New origin = `(prior.x + prior.dims.x + N, prior.y, prior.z)`. | `ID` must name a place declared earlier in the same `site`. `gap` is in blocks between the two facing bounding-box faces (each the wall plus its `overhang=` columns; `0` → the boxes touch), defaulting to `0`. | | `north_of=ID gap=N` | New origin = `(prior.x, prior.y, prior.z − new.dims.z − N)`. | Same `ID` and `gap` rules as `east_of`. Because an origin is the low-`z` corner, the step back is the new placement's own depth: that is what puts its `+z` face `N` blocks from the prior's `−z` face whichever of the two is deeper. | A `place` with no origin selector or more than one, an `at=` other than `origin`, or an `east_of=` / `north_of=` whose value is not a label is `E_INVALID_PLACE_ORIGIN`. `gap=` belongs to the two relative selectors. An `at=origin` row is anchored absolutely and reads no distance, so a `gap=` written beside it is read by nothing and reported as `W_IGNORED_ARGUMENT` ([Lint §11.3](/spec/lint/#113-error-vs-warning)). The argument is real, and which of the two the author meant is theirs to say. On a relative row, `gap=` takes a non-negative integer, the number of cells left between the two bodies, so neither reaches into the other. A negative value does not parse: `gap=-3` is `E_PARSE`, since no `key=` value starts with `-`. Any other value (`gap=wide`, `gap="4"`) is an unreadable value: the row is placed as `gap=0` places it, and the value is reported as `W_IGNORED_ARGUMENT`. An origin is recorded as a 32-bit signed coordinate. A row whose origin, or the far edge of whose body, works out past that range is not placed at all and is reported as `W_DEFERRED_MEMBER`, as is every row placed relative to it. It is refused rather than clamped to the edge: a clamped origin is not the one the source asks for, two rows clamped to one edge land on one coordinate, and a cell past the range has no coordinate at all. Every row refused for its origin or its far edge still reports what its `def` body raises, and so does one refused because the row it is placed relative to was. An `E_INCOMPATIBLE_MATERIAL` or `W_NO_THEME_BOUND` is a defect in the `def` or the theme wherever the row lands. An unreadable `gap=` on any row that is not placed is reported with a note saying so. ### 9.3.3 Cross-scope references Every `place` row declares `id=`, `use=`, and `theme=`. A row short of any of them cannot become a placement: there is no name for its structure file, no `def` to instantiate, or no theme to resolve its `mat_slot=` members against. That is `E_INCOMPLETE_PLACE`. The message names every missing key, and the row is dropped. A key that is present but not a label (`use=3`) is `E_TYPE_MISMATCH_LABEL` instead. `id=` is required rather than auto-assigned, unlike the geometry members of [§9.2](#92-editing-model), because it is the name `east_of=` and `connect` refer to and the name its structure file is written under ([§9.3.4](#934-output-naming)). | Code | Cause | |---|---| | `E_UNRESOLVED_PLACE_REF` | `use=NAME` does not name a top-level `def`. Carries a nearest-match suggestion. | | `E_UNRESOLVED_THEME_REF` | `theme=NAME` does not name a `theme` in the same file. Carries a nearest-match suggestion. | | `E_DUPLICATE_PLACE_ID` | Two `place` rows in one site share an `id=`. The diagnostic points back to the first declaration. | | `W_UNUSED_DEF` | A `def` no `place use=NAME` references. Advisory, so a typo on the `use=` side does not silently produce an empty build. | ### 9.3.4 Output naming The compiler writes one structure file (`.nbt` on Java, `.mcstructure` on Bedrock) per `place`, named after the `id=` (`home1.nbt`, `home2.nbt`), directly into the output directory. These ids are each `E_INVALID_PLACE_ID` ([Lint](/spec/lint/)): - one carrying `/` or `\`, which would name a path rather than a file; - one carrying a character a Windows file name cannot hold, which could not be written there; - one spelling a device name Windows reserves, such as `CON` or `NUL`, which may be opened there as the device. The site is not part of the name. The same directory holds every `struct`, written under its own name (`E_INVALID_STRUCT_NAME` when that name spells such a device), and every walkway ([§9.3.5](#935-ports-and-connect)). Two artifacts that would share a file name, compared ignoring case, are `E_OUTPUT_NAME_COLLISION`: a `place` named after a `struct`, or one `id=` placed in two sites, is refused rather than written over the other. The world-space origin and the `(site, def, theme)` provenance of every placement is recorded in the lockfile, by default `.lock` beside the source (`village.crn.lock` for `village.crn`), under `placements`, so a downstream consumer can rebuild the layout without re-running the coordinate solver. ### 9.3.5 Ports and `connect` `connect FROM.PORT to TO.PORT path=@MATERIAL` lays a 1-block-wide walkway between two named ports on placements within the same `site`. **What a port is.** A port is the `(place, member_id)` pair that `PLACE.PORT` resolves to. Ports are exposed on `door` and `window` members declared directly in the body of the referenced `def`; stair and roof ports, and ports on level-scoped members, are reserved for a future extension. **Where a port sits.** One block outside the member's `side=` wall, at the placement's ground row (`place_origin.1`). `front` / `back` / `left` / `right` map to `+z` / `-z` / `-x` / `+x` ([§9.3.1](#931-coordinate-convention)). The wall-local offset comes from: - a `door`'s `at=` value of `center`, `left`, or `right` ([§5.4](/spec/syntax/#54-selectors)). Numeric offsets are reserved. - a `window`'s geometric centre, `offset + size.w / 2`, with an absent `offset=` read as `0` the way the cut reads it. The placement's overhang shifts the port out into the overhang ring beyond the outer face. A `window`'s authored `y=` does **not** lift the port off the ground row: the walkway is a 1-voxel flat strip whose Y must agree with the other endpoint. A `sym=true` window contributes a single port at the primary `offset` side. Its mirrored cut, when there is one, appears in the wall too, but the `id=` resolves to one coordinate. A mirror that overlaps or coincides with the window is skipped ([§5.4](/spec/syntax/#54-selectors)), and the window keeps its primary cut and its port. **A port is somewhere a wall was opened.** Both port roles are openings cut through masonry, so a placement whose walls do not reach the rows the opening needs anchors neither: a `door` needs the row it opens at inside one course, and a `window` needs its whole rectangle inside one. ``` row 1 in one course # door (a port's door is a def-body member, # so the row it opens at is always 1) offset + size.w ≤ wall_length # window, horizontal every row of y … y + size.h - 1 in one course # window, vertical ``` Those are the rules a port reads for itself. It also anchors only on an opening the openings pass actually cut. A `window` left uncut by an argument only the cut reads (`repeat=` or `step=`, including a `repeat=` above 1 written beside `sym=true` or an unreadable `sym=`), or whose own `mat_slot=` resolves to no block, leaves its wall standing, and its port is refused with it. A `sym=true` window whose mirror is skipped is reported with `W_DEFERRED_MEMBER` for the mirror, but its own rectangle is cut, so its port anchors. A `walls height=H` member under `level y=N` paints world rows `N + 1 … N + H`, starting one above the level's base row. The base row is where that level's floor slab would go, though a level-scoped `floor` is deferred today and the struct's own slab owns row `0`. Courses that touch merge, so `walls height=5` plus a `level y=5 walls height=4` is one wall from row 1 to row 9, and a window spanning the seam is inside it. Courses with air between them do not merge, and a window hung in the gap is outside every one of them. A `door` member of the `def` body opens at row `1`, so a placement whose only masonry is a `level y=6 walls` is a wall the doorway never reaches. The same body's `window` is refused for the same reason. The rows a port is judged against are the rows the placement **painted**. That is the same value the openings pass cut against, not a second reading of the `def`. A `walls` whose `mat_slot=` does not resolve paints nothing, so the cut is deferred and the port is refused with it. A `walls` declared inside a `level` paints its rows, so the cut happens and the port stands on it. A port that cannot be placed drops its row with a `W_DEFERRED_MEMBER` carrying one note per refused endpoint, naming the one rule that endpoint broke: a role that cannot anchor a port, the `side=` or `at=` it was written with, the window argument it lacks or wrote in the wrong shape, how far its rectangle runs past the wall, which rows the masonry does and does not cover, or that the openings pass did not cut it. The note points at the member's line. When the fault is `side=`, an argument or the masonry, that line carries the member's own finding too, worded from the same reading of the argument, so the two never disagree about what was written. A port pushed past the coordinate range by its `place` has no member line to point at and says so on the row alone. **How the path runs.** A Manhattan L, x-axis leg then z-axis leg, at the two ports' shared Y. 3D path search over staircases and multi-level walkways is out of scope by design. When that L would cross an existing structure floor, the compiler searches the ground plane for a detour: the shortest route around the obstacle, and among equal-length routes the one with the fewest turns, with deterministic tie-breaking so the same source always lays the same strip. The row falls back to the straight L, with the colliding cells skipped, only when no unobstructed route exists at all: - a port is buried under another placement's floor, or under a block its own placement lays on the port cell; - the target is fully enclosed; - the search goes past the router's area cap. The router searches the box spanning both ports and every placement floor on the walk plane, so the cap can be reached by a distant pair of ports or by a widely spread floor plan. That earns one `W_WALKWAY_BLOCKED` naming the concrete cause and its remedy: move the buried door or window (or the block on its port cell), widen the gap, bring the two structures closer, or bring the placements that stretch the box closer. `--format json` carries `data: { kind: "walkway_blocked", skipped: N }` when cells were skipped. When the straight L itself is past the cap, the walkway is not laid at all and the finding carries no `data`. **Material.** `path=@TOKEN` lifts through the same `mat_slot=` pipeline as member materials. Concrete tokens like `@gravel` work without a registry pack; abstract tokens like `@path.gravel` need the pack's materials catalog and surface `W_ABSTRACT_TOKEN_DEFERRED` or `E_UNKNOWN_ABSTRACT_TOKEN` on a miss. **Output.** Each `connect` row that lays its walkway writes one structure file named after its site and ports (`hamlet_walkway_home1_entry__home2_entry.nbt`) and records a `walkways:` entry in the lockfile with the world origin, dims, and resolved path material. A row that lays no block has lost a walkway the source asked for. That happens for: - an endpoint whose `place` resolved but did not lower (`W_DEFERRED_MEMBER`), as when its `def` has no `size=` or its origin falls past the coordinate range; - a port that cannot be placed; - an id the walkway's name cannot carry; - a path material that does not resolve; - a straight L that is itself past the router's search-area cap; - a straight L whose every cell overlaps a placement, which leaves the strip all air. `cairn compile` then refuses the build with `E_PARTIAL_BUILD`, as it does for a lost scope, and `cairn check --edition E --target V` refuses with it too ([Lint](/spec/lint/)). A `cairn check` without `--target` reports the findings behind the loss that need no target, but not the loss itself ([Lint §11.3](/spec/lint/#113-error-vs-warning)). The loss is named `site::SITE::FROM ↔ TO`, with the ports as the row wrote them. An endpoint whose `place` row did not resolve at all (such as `E_INCOMPLETE_PLACE`, `E_INVALID_PLACE_ID`, `E_INVALID_PLACE_ORIGIN` or `W_DEFERRED_PLACE`) is not one of these losses. The `connect` row is dropped with `W_DEFERRED_CONNECT` ([Lint](/spec/lint/)), and the error that refused the `place` is what refuses the build. A `W_DUPLICATE_WALKWAY` row loses nothing, since the earlier row laid its pair, and two rows naming one pair that neither laid are one loss. One mistake can cost more than one loss: a `place` whose def has no `size=` is a lost scope, and every walkway with an endpoint on it is lost too, so each adds a note to `E_PARTIAL_BUILD` and one to the count of scopes that did not lower. **Diagnostics.** | Code | Cause | |---|---| | `E_CONNECT_ARITY` | The row's shape is not `FROM.PORT to TO.PORT`. Enforced before resolution, since an unreadable endpoint costs the row its walkway. | | `E_UNRESOLVED_PORT` | The right-of-dot port id does not name a member of the referenced def's body. Carries a nearest-match note when one fits the spell cap, or, when the id belongs to a member nested under a `level`, says so instead, with a note at that member: a level-scoped member cannot be a port yet. | | `E_AMBIGUOUS_PORT` | The def exposes the same `id=` on more than one member. Rename the collision. | | `E_MISSING_PATH_MATERIAL` | The row omits `path=`, or gives it a value that is not a `@TOKEN` (`path=gravel`), so walkway lowering has nothing to lay. | | `E_UNRESOLVED_PLACE_REF` | The head place id does not name a prior place in this site (shared with [§9.3.3](#933-cross-scope-references)). | | `W_WALKWAY_BLOCKED` | No unobstructed route exists; the row falls back to the straight L and the rest of the strip still lays. When every cell of the straight L overlaps a placement, or the straight L alone is past the router's search-area cap, nothing is laid and the walkway is lost. | | `W_DUPLICATE_WALKWAY` | The same two ports, in either order, already have a walkway laid in this site; the duplicate row is dropped. | | `W_INVALID_WALKWAY_IDENT` | A site, place or port id cannot be carried in the walkway's name ([Lint](/spec/lint/)); the row is dropped. | # 10. Versioning and Edition Strategy ## 10.1 The target is a compile-time parameter The target is the pair `(edition, version)`, and neither is written in the source. Only the backend knows them ([Compilation Model](/spec/compilation/)). **Version strings are opaque labels.** A Minecraft version may be the legacy semver-ish `1.21.4` or, from the latest release onward, date-based. Cairn does not compare version strings; it orders by **DataVersion**, the monotonically increasing integer Mojang assigns. That keeps `since`/`until`, Vmin/Vmax, `@requires`, and `semantic_sensitivity` boundaries working across the semver → date-based transition. The backend holds a "version string ↔ DataVersion" table, so `--target` accepts either spelling of the same version. Bedrock resolves its version strings to an internal monotonic key the same way. Two labels are the same version when they differ only in ways that carry no information: a missing trailing component is zero, and a leading zero in a numeric component is padding rather than a digit. So `1.21`, `1.21.0` and `1.021` are one version (`1.21.0` is Java's `1.21`, and `1.21` is Bedrock's `1.21.0`). `@requires` and `@intended_targets` read a label by the same rule. The build and its lockfile name the version as the table spells it. ## 10.2 Language contract: recompile, don't transcode > The spec does **not** guarantee NBT portability across version or edition. The only guarantee is > "the result of compiling the same source to a given target". The source is the blueprint; the `.nbt` is a target-pinned build output, the equivalent of a binary. To use a build on a new version or another edition, recompile the source. DataFixerUpper is forward-only, lossy, and incomplete, and loss is common in items, signs, paintings, and block entities. It is a rescue tool, kept out of the language semantics. Some residue is unsolvable and is stated rather than hidden: - Meaning changes across versions (the cauldron split, item `tag` → `components`). - Game behaviour not in data tables (fluids, gravity, attachment, redstone). - Visual consistency (colour-temperature drift). - Physics rule changes (1.21 wind charges breaking old traps). Geometrically correct NBT is emitted; the gameplay experience is not guaranteed. ## 10.3 Backend = data tables Two sources feed the backend, and they are kept apart. **Machine-extracted** from the game's `--reports` / registry dumps. This is the truth about syntax and domains: block and entity IDs, blockstate properties and their domains, item and component schemas, DataVersion, tags. Taking the game itself as the source of truth, rather than anyone's memory, closes the knowledge gap about new versions at its root. The built-in packs extract nothing from `--reports` yet: of that list they carry each version's block IDs and the version table, their block tables come from PrismarineJS/minecraft-data, and each pack file names its source. **Hand-written, version-tagged constraint catalog** for what the data does not carry: attachment (a frame cannot go on glass), gravity and support (gravel, hanging lanterns), fluid behaviour, entity AABB, redstone. Defined once per new version, and every user benefits. No constraint catalog ships yet, so a lock records its `constraint_catalog_hash` as zeros and no member is reported semantic-sensitive ([§10.5](#105-which-version-is-it-for-has-three-answers)). ```yaml constraints: minecraft:item_frame: type: entity_attachment since: "1.13" targets: { solid_full_face: true, glass_pane: false } error: "item_frame requires a solid attachable face" minecraft:lantern: type: support states: hanging=true: { requires_above: solid_or_chain } hanging=false: { requires_below: solid_top } ``` ### Folding the `(edition, version)` matrix The canonical token is the primary key, and each token carries a per-edition mapping (id + state_map). Versions fold with `inherits + diffs`: Java is the base, Bedrock the overriding diffs. The hand-written semantic catalog records only the points that differ. The built-in packs fold only within an edition so far. Each edition has a registry pack of its own, whose `pack.json` names its `edition`, and neither inherits from the other yet. Inside one pack the `blocks` component holds one version's block IDs, and each later version names the version it inherits and the IDs it adds and removes (Java `1.20.4` → `1.21` → `1.21.4`, Bedrock `1.21.0` → `1.21.40` → `1.21.60`). A `materials` entry maps a token to one block ID, and its `overrides` name the versions that spell it differently, as Bedrock's does for 1.21.0: ```json { "token": "floor.stone.smooth", "block": "stone_bricks", "overrides": [{ "mc_version": "1.21.0", "block": "stonebrick" }] } ``` No pack carries a `state_map` or a `sensitivity` yet: the one state translation that exists, the stair family's, is written in the Bedrock backend ([§10.7](#107-java--bedrock-portability)). ```yaml "@oak_stairs": base: { states: { half: [bottom,top], shape: [straight,inner_left,inner_right,outer_left,outer_right] } } mappings: java: { id: minecraft:oak_stairs, base: "1.13" } bedrock: { id: minecraft:oak_stairs, state_map: { half=top: {upside_down_bit: true} }, dropped_states: [shape] } sensitivity: - { edition: bedrock, kind: missing_state, state: shape, reason: "no inner/outer stair shape" } ``` ## 10.4 Fail-loud and minimum-version inference Unknown IDs, out-of-domain states, and parity gaps are hard errors. Silent substitution and implicit dropping are forbidden. An error returns the closed set of candidates valid in the target, the minimum version, and a suggested fix. That sends the model back to registry-derived candidates rather than to its memory. Out-of-domain states are not yet enforced: `E_STATE_DOMAIN` below is not implemented, because the compiler holds no table of each block's states. Until it does, a state literal ([Syntax](/spec/syntax/)) is written as given, and every one earns `W_STATE_LITERAL_UNCHECKED` ([Lint](/spec/lint/)) instead. `E_PARITY_UNSUPPORTED` below is not implemented either ([§10.7](#writing-an-alternative)). Nor does an error name a minimum version yet: the tables record which IDs a version has, not when one first appeared ([below](#which-registry-an-unknown-id-is-unknown-to)). ```text E_UNKNOWN_ID line 4: "minecraft:pale_oak_planks" not in java 1.21 registry. Nearest: minecraft:dark_oak_planks E_VERSION_CAP line 2: this file requires version>=1.21.4 (target 1.21). Valid java targets: 1.21.4. Fix: --target 1.21.4, or lower the @requires floor E_STATE_DOMAIN line 18: wall north=true invalid for 1.21.4. Valid: none, low, tall (changed from boolean in 1.16). Suggested DSL: wall_segment id=yard_wall connect_north=low E_PARITY_UNSUPPORTED line 8: text_display is Java-only (since 1.19.4); Bedrock has no display entity. Suggested: sign side=front text="Inn", or slot+theme fallback, or @edition java guard ``` ### Which registry an unknown ID is unknown to An ID is checked against the block table for the one `(edition, version)` the compile pinned, not against the edition as a whole. Bedrock 1.21.0 spells stone bricks `stonebrick` and 1.21.40 spells it `stone_bricks`, so an edition-wide answer would accept both everywhere and catch neither mistake. The tables ship in the registry pack's `blocks` component, folded with the `inherits + diffs` rule of [§10.3](#103-backend--data-tables). The check therefore runs where a version is pinned and nowhere else: on `cairn compile --target`, on `cairn check --edition E --target V`, which pins the same pair to run the same pass without writing anything, and in the `buildable targets` row of `cairn info`, which pins each supported version in turn. A `compile` whose target the file's floors refuse pins none: it checks no id and is refused on the floor instead ([§10.4](#the-declared-floor-is-enforced)), while `check --target` is not held to the floors and pins the target regardless. The `buildable targets` row reports each version's `E_UNKNOWN_ID` under that version and leaves the exit code alone ([§10.5](#the-buildable-targets-row)). The other rows of `info` report across the whole range by design, and `cairn lower` lowers with no target, so neither pins a version: they skip the comparison rather than pick one on the author's behalf. A `cairn check` with no `--target` lowers with no target at all, which pins no version and leaves each abstract token to the pack of the target that builds it, so neither this check, `E_UNKNOWN_ABSTRACT_TOKEN` nor `W_ABSTRACT_TOKEN_DEFERRED` reaches it ([Lint §11.3](/spec/lint/#113-error-vs-warning)). Checking against *every* version the edition ships and refusing only the ids valid in none of them would need no flag, and would answer a different question: `stone_bricks` is valid somewhere on Bedrock, so a build pinned to 1.21.0 would still be told nothing. The pin is what makes the answer true of the build being made. The suggested fix has two halves, because a wrong ID arrives two ways. A **typo** is answered by a distance search over the same table: `oak_plank` is answered with `oak_planks`. A **rename** is not a typo. Bedrock spells Java's `light` as `light_block_0` … `light_block_15`, eight edits away, and no threshold that keeps the typo finder honest will ever connect the two. Renames are answered from the registry pack's `aliases` component instead, and only where the pack has a row; where it does not, the message says it has no candidate rather than offering the nearest unrelated block. An `aliases` row is a **group of spellings**: the names one block has worn, across editions and across one edition's own range, including the several IDs one old spelling split into. ```json { "spellings": ["light", "light_block", "light_block_0", "light_block_1"] } ``` Nothing in the row says which spelling belongs to which `(edition, version)`. The `blocks` component already knows that, per version, so a lookup is "take the group, keep the members the pinned target declares". That is what lets one set of rows answer Java → Bedrock (`oak_sign` → `standing_sign`) and Bedrock 1.21.0 → 1.21.40 (`stonebrick` → `stone_bricks`) alike. An answer is the closed set §10.4 asks for, never a pick from it: `@light` on Bedrock 1.21.60 is answered with all sixteen light levels, because choosing one would be the silent substitution this section forbids. What the key cannot express is a spelling both editions declare meaning different blocks: Bedrock's `snow` is Java's `snow_block` while Java's `snow` is Bedrock's `snow_layer`. Such a pair gets no row, and the typo search still runs behind it. The same per-version scoping applies to a pack's own material mappings. An entry may carry `overrides` naming the versions that spell it differently, which is what lets one `@floor.stone.smooth` resolve across a range containing a rename. The `since` half is still deferred: the tables record which IDs a version *has*, not which version first introduced one, so the `E_VERSION_CAP` example above is an `@requires` floor rather than registry-inferred. ### A part may declare its own floor `def` and `theme` may declare `requires version>=X` on a line of their own, and the minimum version of a composite is the max of its parts: ``` def cottage size=9x7: requires version>=1.21.4 walls mat_slot=wall height=4 ``` The expression is the one `@requires` takes, edition scope and all. The two spellings differ in what they constrain, not in what they say. A module-level `@requires` is a floor on the *file*; this one is a floor on the *part*, so a `place use=cottage` inherits it and a library of templates carries its own requirements instead of every consumer restating them. **Which parts a build inherits from.** A `def` a `place use=` names, and a `theme` a scope binds. A part nothing instantiates contributes nothing: a `def` no `place` names builds no voxels (and is already `W_UNUSED_DEF`), so refusing a target over it would be refusing over a template the author left in the file. **A theme's floor applies when the theme is bound**, whether or not a member reads a slot from it. Binding a theme is the act of taking on what it declares. Charging the floor only once one of its rules fires would make the floor depend on which selectors matched and which variant the pin picked, so one source could require `1.21` on Java and nothing on Bedrock for a reason that is not about editions. It would also err in the unsafe direction. An over-applied floor is reported against the line that set it and is one edit away, while an under-applied one certifies a build the file itself rules out. Two things bind a theme, and both of them are a scope a build lowers. One is a `place ... theme=NAME` reference, which also instantiates the `def` it places, since `theme=` is required on a `place`. The other is the module-level auto-pick, read for a `struct`, the one scope a build lowers without a placement. The auto-pick also binds the sole theme to every `def` scope, and a floor does *not* follow it there: a `def` no `place` names builds nothing, so charging a theme's floor because such a `def` exists would read one `def` as instantiated enough to take on a theme's floor and not instantiated enough to be charged its own. A `def` that is placed reaches the theme through its placement's own `theme=` instead. `struct` and `site` take no such line. Neither is instantiated by anything, since each *is* the build, so a floor written inside one constrains exactly the file it is in, which is what `@requires` already says. The same goes for a member's own indented children: the floor belongs to the part, and a `walls` line is not a part. That is three refusals with three messages for two repairs: one points at `@requires`, the other at a dedent. A member's children inside a `def` get the dedent; inside a `struct` or a `site` a dedent lands the line in a body that refuses it too, so they get `@requires`, as the `struct` or `site` itself does. A floor is recognised by its expression before anything after the line is read, so one with an indented line under it is refused as a floor rather than read as a member. None of the three refuses on the word alone: `requires` is an ordinary keyword in a body that reads no floors, so a member line spelled that way parses in a `struct`, a `site`, or under a member like any other member line. A `def` or `theme` body is the other half of that, and takes the word whatever follows it: the line is a floor, and an expression that reads as none is `E_INVALID_REQUIRES` rather than a member. That costs nothing: `requires` is not a member keyword, so the same line would otherwise be `E_UNKNOWN_KEYWORD`. `E_VERSION_CAP` names the part that imposed the floor, not only the number. A target refused by a floor written inside a template is not actionable as a bare version, because the repair is at the other end of the `place use=` that inherited it. ### The declared floor is enforced A module's floors compose by intersection. `cairn compile --target` is held to every `@requires` line that applies to the build, and a target below any of them is `E_VERSION_CAP`. The refusal comes before any artifact is prepared, so a refused build leaves no structure file and no lock. That ordering matters: a lock records what was verified, and it must never say `verified: true` for a target the source itself rules out. A target below a floor usually also lacks a block the file uses, since a block introduced after the target is the common reason to declare one. So `cairn compile` pins no version for a target the floors refuse: one below a floor, and every target when a floor names a version this edition's table cannot place ([§10.4](#ordering-is-by-dataversion-per-edition)). Any id the source names goes unchecked, including one no version declares, until the target clears every floor. The build is refused on the floor instead, with `E_VERSION_CAP` or `E_REQUIRES_UNORDERABLE`, and no `E_UNKNOWN_ID` tells the author to replace the block the floor was declared for. What needs no version is still reported ahead of that refusal: the check pass's findings, such as `E_INVALID_REQUIRES`, and lowering's, such as `E_UNKNOWN_ABSTRACT_TOKEN`. An error among them stops the build before the refusal is reached. `cairn check --edition E --target V` is not held to the floors, so at a target they refuse it reports the ids that target lacks, where `compile` reports the floor ([Lint](/spec/lint/#materials-and-targets)). ### The hint is weighed against the floor `@intended_targets` ([§5.3](/spec/syntax/#53-headers)) is a wish rather than a verification record, and the floor above it is a constraint. A file may state both in a way that cannot hold, such as `@requires version>=1.21` beside `@intended_targets ["1.20.4"]`. If only the floor were checked, one of them would decide a build and the other would not. That is the worst arrangement, because the header that reads like an instruction would be the ignored one. So each version the header names is placed in the target edition's table and answered in one of three ways: | The version | The finding | |---|---| | No `--target` of the edition names it: a release the pack ships no block data for (`1.19` on Java), or a label the table cannot place at all (`1.21.40` on Java) | `W_INTENDED_TARGET_UNSUPPORTED` | | A version the edition builds, below a floor the file declares | `E_INTENDED_TARGET_CAP` when *every buildable* one is, `W_INTENDED_TARGET_CAP` when only some are | | A version the edition builds, at or above every floor | Nothing | The order is deliberate. A version the compiler cannot build is reported as that whatever the floors say, because `--target 1.19` not existing is what the author acts on. A cap beside it would ask them to edit a floor that is not what stops the build. The split between the two cap codes is reach rather than kind. "Nothing the file says it is for can be built" is the strongest reading a contradiction between two declarations gets, and no author meant it. A list that reaches past the floor at one end is a wish stated too widely, and what it names above the floor still builds. **"Every" counts the versions the edition can build.** A name no `--target` of it carries answers for none of the list, so `@intended_targets ["1.20.4", "1.19"]` under `version>=1.21` is the first case and not the second: Java builds exactly one of the two, and the floor refuses it. Counting `1.19` would let a version that was never buildable report a file nothing can build as half a problem. It is reported separately as the unsupported case, which is where its own repair is. Which floors count is the composite fold [§10.4](#a-part-may-declare-its-own-floor) already defines: the file's `@requires` lines plus every part the build instantiates. So a `def` in a library can refuse the intent of the file that places it, and the finding names the part. A floor scoped to the other edition is inert here as everywhere, and a floor this edition's table cannot place refuses nothing: that is `E_REQUIRES_UNORDERABLE`, whose repair is on the `requires` line rather than on the intent. Every command that gates on `cairn check` (`check`, `info`, `lower`, `compile`, `synth`) reports the two cap codes, and each weighs the header in the tables of the editions it is about: the one `--edition` names, the ones `cairn info --editions` lists, or both where the command names none. A finding either edition reaches is reported, since the contradiction is between two lines of the file however it is later built. One span carries one cap finding: two editions disagreeing about how far it reaches report the error, because one of them finding part of the list still buildable does not make the other's "none of it is" less true. `W_INTENDED_TARGET_UNSUPPORTED` waits until exactly one edition is in scope, because a version Java cannot build is routinely the Bedrock target the author means. `cairn info --editions bedrock` is one edition in scope, and is weighed in Bedrock's table alone. A report scoped to one edition is not refused by the other's answer. `E_REQUIRES_CONFLICT` is **reserved**. It is defined as a declared floor contradicting the registry-*inferred* range, and no inferred range is derived yet, because the pack carries no `since` / `until`. It is not a conflict between two `@requires` lines: floors compose by taking the strictest, so their intersection is never empty. A constraint needing an upper bound, such as `version<1.20`, is not a shape the language accepts; that is `E_INVALID_REQUIRES`. ### Ordering is by DataVersion, per edition [§10.1](#101-the-target-is-a-compile-time-parameter) makes `DataVersion` the canonical ordering key, and `@requires` uses it. A floor is placed in the **target edition's** version table (`registry-data/{java,bedrock}/data_versions.json`) and weighed against the target's own `DataVersion`. That table names the **release lines** of its edition that it carries, which is a different set from the versions the pack can *build* for: three per edition, the ones it ships block and material data for. A row says which it is (`targetable`). Java's rows are its releases from `1.14` on. Bedrock's are its release lines, numbered in tens (`1.21.0`, `1.21.20`, `1.21.40`), without the hotfixes between them. Keeping the two sets apart is what lets "inside the table's span, naming no row" mean "no release this table can order": a floor of `1.21.1` is a Java release the pack cannot build for and can order perfectly well, while `1.21.4` names no Bedrock row, and neither does the hotfix `1.21.42`. A floor may still name something no table carries, so placing one is not a bare lookup. Four answers, and only the first is exact: | The floor | Placed as | Because | |---|---|---| | Names a row (a missing trailing component is zero, and a leading zero in a numeric component is padding: `1.21` is Bedrock's `1.21.0`, `1.020` is Java's `1.20`) | That row's `DataVersion` | Exact. | | Names a pre-release of a row (`1.21.4-rc1`) | That row's `DataVersion` | Nothing ships between a release candidate and its release, so no supported target lies between them either. | | Sits below every row, or above every one | Met by every target, or by none | Reached by comparing the floor's label against the first and last rows' *labels*, while which rows those are is decided by their *keys*, so it holds exactly when the table's labels sort the same way by text as by key. The registry pack loader checks that at load time. The floor's own label must be a dotted decimal to be compared at all. | | Anything else: inside the table's span, naming no row | Not placed at all | It has no `DataVersion`, and there is none to give it. `E_REQUIRES_UNORDERABLE`. | The last row is a refusal, not a guess. `@requires version>=1.21.4` against Bedrock is exactly it: Java's release names no Bedrock release and sits between `1.21.0` and `1.21.20`. Comparing the labels would read it as satisfied on `40 > 4` and certify a Bedrock build against a version below the floor: the same defect enforcing the floor exists to remove, one edition to the left. The refusal can say more than "no". A label this edition cannot place but the *other* edition names (a row of its table, or the pre-release of one) is a floor written in the other's numbering, and `E_REQUIRES_UNORDERABLE` names it and offers the scope. A label the other edition does not name gets no scope offered, because recommending one would be recommending a guess: scoped to an edition that does not name it either, the floor goes inert there and the constraint disappears. That covers a label neither edition can place, such as a snapshot, and also one the other edition places only below or above every row. Those two placements are comparisons rather than releases: they say nothing about which numbering the author meant, and scoped there the floor is met by every target of that edition or by none. ### A floor may name its edition Java releases run `1.20.4 / 1.21 / 1.21.4` and Bedrock `1.21.0 / 1.21.40 / 1.21.60`. The two are different scales, and a floor written in one of them means nothing in the other. So a floor may say which it is written in: ``` @requires java version>=1.21.4 @requires bedrock version>=1.21.40 ``` A **scoped** floor constrains its own edition's build and is inert in the other's. Inert is not violated, so the pair above builds on both. An **unscoped** floor is a floor on whatever is being built, and is resolved in that edition's table like any other. That makes `@requires version>=1.21` a floor both editions can honour (Java's `1.21`, Bedrock's `1.21.0`), and makes a floor that names one edition's release and not the other's the error above rather than a silent pass. The `registry compatibility` row of `cairn info` ([§10.5](#the-registry-compatibility-row)) reads only the unscoped floors. It is one row for a file that may be reported against both editions at once, and a floor in Java's numbering says nothing about the file's Bedrock range; the per-edition answer is the `buildable targets` row. A floor a `theme` declares is held to the same test, and for the *part* it is inherited through rather than for the words on the line. Per-edition theme variants ([§10.7](#107-java--bedrock-portability)) mean the two editions can bind different themes for one `theme=` reference, so a theme feeds this row only when both bind the same one; otherwise the floor is a per-edition fact wearing no edition scope. A `def` needs no such test: a `place use=NAME` names one def and not a family of variants. Whatever the row leaves out is named on stderr with the reason, so a `0.0` beside a `buildable targets` row that refuses versions is never left to be inferred. ### Which labels a floor may use Every label shape [§10.1](#101-the-target-is-a-compile-time-parameter) says will exist is accepted by the directive: the semver-ish `1.21.4`, the pre-release `1.21.4-rc1`, a snapshot `24w14a`, and whatever a date-based scheme spells. The shape rule is dot-separated components that each begin with a digit and carry only letters and digits, with an optional `-` and a pre-release tag of the same. `1.a` and `x` name no version in any scheme and are `E_INVALID_REQUIRES`. Accepting a label is not claiming it can be ordered. Whether a given label has a `DataVersion` is the table's answer, and it is asked per edition: `cairn compile --target` refuses the build, and `cairn info --editions` reports the edition as having no buildable target and says why. `cairn check` does not ask: it never weighs a floor against its target, even with `--edition` and `--target` pinned ([§10.4](#the-declared-floor-is-enforced)). ## 10.5 "Which version is it for?" has three answers There is no single "for-version". `cairn info` reports three axes: 1. **Declared registry range `[Vmin, Vmax]`**: the floors the file declares without naming an edition, composed, against an open upper edge. A reading of what the source and the parts it instantiates declare, not a fact derived from the blocks they use. See [the `registry compatibility` row](#the-registry-compatibility-row). 2. **Semantic-sensitive members**: cases where the ID stays valid but meaning, behaviour, or appearance changes. This matters more than the range: behaviour changes far more often than IDs disappear, so deciding Vmax from the registry alone is dangerous. The constraint catalog carries a `semantic_sensitivity` (boundary version + reason) separate from `since`/`until`, and a compile crossing one warns. Examples: the cauldron split at 1.17, wall connections going bool → `none/low/tall` at 1.16, the item format at 1.20.5. No constraint catalog ships yet ([§10.3](#103-backend--data-tables)), so the `semantic-sensitive` row is always `(none)` and no compile warns. 3. **The verified lock target** ([§10.6](#106-provenance-and-lock)). `cairn info` does not report it yet, because it reads no lockfile. `cairn compile` does compare a lock's target with the one it builds, and reports a change as `W_PREVIOUSLY_VERIFIED_TARGET`. ```text $ cairn info build.crn --editions java,bedrock registry compatibility: 1.21.40 .. latest edition portability: Java: portable: 42 degraded: 0 unsupported: 0 Bedrock: portable: 38 degraded: 3 unsupported: 1 buildable targets: Java: none (1.20.4, 1.21, 1.21.4 all refuse) Bedrock: 1.21.40, 1.21.60 (1.21.0 refuses) intended targets: 1.21.40, 1.21.60 semantic-sensitive: yard_water(cauldron split @1.17), fence(wall conn @1.16) ``` Every version named is one the built-in packs declare. The file behind this output carries `@requires version>=1.21.40`, which is what puts every Java target below the floor, and Bedrock 1.21.0 with them. The `semantic-sensitive` row shows what a constraint catalog would add; today it reads `(none)`. `intended targets` is the file's own `@intended_targets` line, verbatim, and the one row that is a declaration rather than an answer. It sits beside `buildable targets` because that is the row it can contradict. [§10.4](#the-hint-is-weighed-against-the-floor) automates the comparison for the half that is decidable, and the reader makes it for the rest. A file declaring none gets `(none declared)` rather than a missing row. The five lines go to stdout; what each figure is made of goes to stderr as `note:` lines. A pipeline reading the rows sees the same five lines every time `cairn info` runs to completion. A run that does not complete is a different case: a finding refuses the command before any row is computed, so stdout is empty rather than short a line. ### The `registry compatibility` row The row reads declarations back; it never looks at the blocks the source uses. `Vmin` is the strictest floor the file is bound by with no edition named, or `0.0` when there is none. The candidates are the `@requires version>=X` headers, plus the `requires version>=X` line of every `def` and `theme` the build instantiates that feeds this row ([§10.4](#a-part-may-declare-its-own-floor)); a theme feeds it only when both editions bind the same one. Working out *which* parts a build instantiates is real work over the source; reading which blocks they paint is not part of it. "Strictest" is a comparison of the labels, so it is exact only while they are all dotted decimals. A label the comparison cannot read as a number sorts above every one it can, which is fixed rather than meaningful: a file declaring both `version>=1.21.4` and `version>=24w14a` reports the snapshot. That order decides no build: every gate that does weighs each floor against the target edition's table separately ([§10.4](#ordering-is-by-dataversion-per-edition)). The row is edition-agnostic, which is why it reads only the unscoped floors, for the reasons and with the stderr notes [§10.4](#a-floor-may-name-its-edition) gives. So `0.0` has two causes, a file that declares no floor and one whose every floor names an edition, and the row cannot tell them apart. The note on stderr can. `Vmax` is the literal `latest`. An upper edge is the half of a *derived* range and this row carries the declaration, so a pack that grows `since` / `until` would give its answer to `buildable targets` rather than fill this in. **The row is a declaration, not an answer about which versions build.** Those are easy to read as one thing, and a source can make them look identical. This one declares a floor every supported version clears, and uses a block Java gained in 1.21.4: ```text $ cat hut.crn @cairn 2026.06 @requires version>=1.20.4 theme pale: slot floor -> @pale_moss_block slot wall -> @cobblestone struct hut size=5x5 floor mat_slot=floor walls mat_slot=wall height=3 $ cairn info hut.crn --editions java registry compatibility: 1.20.4 .. latest edition portability: Java: portable: 2 degraded: 0 unsupported: 0 buildable targets: Java: 1.21.4 (1.20.4, 1.21 refuse) intended targets: (none declared) semantic-sensitive: (none) ``` `1.20.4 .. latest` reads as an answer, and the row two below disproves it, with `1.20.4` itself in the refusal list. The declared floor is not wrong; it is answering a different question. `minecraft:pale_moss_block` arriving in 1.21.4 is a fact about the pack, and this row reads only what the file declares. **The derivation is the `buildable targets` row**, two rows down. It weighs the source against every supported version and reports which ones a build would accept, per edition. That is the answer an intersection of `since` / `until` was meant to approximate, reached by asking rather than by inferring. It is also the shape the intersection could not take: the answer is per edition, and it need not be contiguous, so a `[Vmin, Vmax]` pair would have to claim a gap it cannot see. The declared floor stays a row of its own because it is a different kind of fact: an **input** the author wrote, which bounds what `cairn compile --target` accepts and what the file promises a reader, where `buildable targets` is an **output** about the packs that happen to ship. `E_REQUIRES_CONFLICT` ([§10.4](#104-fail-loud-and-minimum-version-inference)) is reserved for the day the two can be compared, when a declared floor could contradict a registry-*inferred* range. It stays unreachable until a pack carries `since` / `until`. ### The `edition portability` row The row counts palette entries. An entry is `unsupported` for one of two reasons: | Reason | The repair | |---|---| | The edition has no such block at all. | Change the material, or the pack's mapping for it. | | It has the block, but Cairn has no mapping for the states the intent carries ([§10.7](#107-java--bedrock-portability)). | None yet. The mapping is Cairn's to add. | The first is a question about IDs and the second about states. Only the second can produce `degraded`: a block that does not exist has nothing to lose detail from. Because two different repairs hide behind one figure, each counted entry is named on stderr with its reason. The ID case is answered the way `E_UNKNOWN_ID` answers one, and by the same two halves: the `aliases` component where it has a row, so an entry this edition has under another name is reported as that name rather than as a dead end (`standing_sign` on Java is `oak_sign`), and a `did you mean` where it has none. They are alternatives, not a sequence: a row is the pack's word about which block this is, and printing a distance guess beside it would ask the reader to choose between them. The alias question is asked of the edition here too: a spelling *some* supported version declares is an answer, where a pinned build would keep only its own version's. `--format json` carries them as `edition_portability[].unsupported_entries`, one element per unit of the count, in palette order. Both questions are asked of the *edition* rather than of a version, because this row reports across a whole compatible range. An ID valid for only part of that range is therefore not `unsupported`, as when Bedrock renamed `stonebrick` to `stone_bricks` at 1.21.40. Whether the version being built has it is what a pinned target answers, as `E_UNKNOWN_ID`, from `cairn compile --target` or `cairn check --edition E --target V` for the same answer without a build ([§10.4](#104-fail-loud-and-minimum-version-inference)). #### Which entries degraded, and what they lost `degraded` is the other figure over entries the command can name, and it is named the same way. The case is weaker than `unsupported`'s: there is one reason an entry degrades and one repair for it, so a reader is not choosing between repairs. What is identical is "which of the N": `roof-hip` reports `degraded: 4`, and the only other place that is answered is the build, as `W_INTENT_DEGRADED`, which is the run this command exists to be read *before*. Each counted entry is named on stderr and carried in `--format json` as `edition_portability[].degraded_entries`, one element per unit of the count, in palette order. An entry is `{id, states, dropped}`: | Field | Carries | |---|---| | `id` | The palette entry's block ID, verbatim as the lowering interned it. | | `states` | The entry's `key=value` pairs, comma-joined, the same spelling the `states_unmapped` reason uses. | | `dropped` | One `{key, value}` per intent the edition has no form for. `key` is a closed set (`shape`); a new kind of loss is a new `key` rather than a change to an existing one. | Two lists rather than one under a category tag, and `states` rather than the ID alone. Degradation is a fact about the *state combination*, not about the block: one ID reaches this list once per combination that loses something, and `roof-hip`'s four entries are four spellings of `minecraft:spruce_stairs`. A list keyed by the ID alone would print the same line four times. The build's `W_INTENT_DEGRADED` names each entry the same way, once per line, as `id[states]` after the structure's scope, so each warning is distinct and matches the note about the same entry. `dropped` carries the property and the value rather than the sentence about them, for the reason the `unsupported` reasons do: a consumer that reads this should not have to parse English to learn which state was lost. A value the edition *can* express is not a loss and does not appear: Bedrock's stairs are `straight`, so `shape=straight` drops without an entry. The prose both the note and `W_INTENT_DEGRADED` print is written in one place, and per `key` rather than over the pair, because the sentence for a dropped `shape` talks about stairs: a second block family that drops an intent brings its own `key` and its own sentence rather than inheriting this one. #### A blockstate the pack should have refused is not a figure Two further failures can reach the state translator: a state value outside the Java domain (`facing=up` on a stair), and a state key the translator does not read. Neither is an answer about the edition. No validated registry pack produces either, so each comes from a state literal in the source, which nothing checks against the target yet (`W_STATE_LITERAL_UNCHECKED`, [§10.4](#104-fail-loud-and-minimum-version-inference)), or from a defect in the pack or in Cairn. So they are not a third and fourth reason for `unsupported`. `cairn info` reports **no** portability figures for an edition whose palette carries one. The counts would still be computable, and they would read as ordinary portability. A `facing=up` counted as `unsupported: 1` is indistinguishable from a stair whose corner shape Bedrock simply has no state for, which is the one conclusion the reader must not draw. The command names every such entry on stderr with the translator's own message, whose fix is to the source blockstate, notes that each is either a state literal in the source or a leak in the pack or Cairn, and exits non-zero without a row, the way any other finding that refuses the command does. The state translator is the only place this can be observed, so the rule is stated for the states question alone. It is not a licence to answer `unsupported` for a validation gap elsewhere: a figure computed over a palette a validated pack could not have produced is not a portability answer, whatever produced it. ### The `buildable targets` row Counters cannot say everything: two entries can be declared by *disjoint* sets of versions and each answer "the edition has it", leaving the row clean while no single version declares both. `buildable targets` is the per-version answer. Per requested edition, it lists the supported versions whose pinned lowering raises no error, with the refusing ones named beside them. It is a set rather than a `[Vmin, Vmax]` range, because two IDs whose version sets interleave leave a gap a range would claim. It is derived by lowering once per supported version, the same check `cairn compile --target` runs. An entry the `edition portability` row counts `unsupported` for its states is one the edition's writer cannot carry, so it refuses every version of that edition here as it refuses the compile. It is **not** derived by intersecting the range-wide palette's ID sets, which is unsound: with no target pinned every material takes its *default* mapping, so a token the target respells is compared as the wrong ID. Like the counters, this row reports and does not refuse. `cairn info` exits 0 even for a source no supported version can build, because the build is the command that refuses it. Each refusing version's own findings are printed under that version, so an `E_UNKNOWN_ID` never stands without the target that raised it. #### Why the list is empty An empty `buildable` has five causes, and they are not all repaired by the same edit: the `@requires` line answers two of them, the member that produced no voxels a third, the material the writer cannot carry a fourth, and whatever the pinned lowering named the fifth. The list alone cannot tell them apart, so under `--format json` a `reason` accompanies it. The key is **absent** whenever a version builds, so an ordinary report is unchanged. `reason` is an object, and every cause that holds is reported. Three of the five are facts about the **edition**, identical under every release and settled before any release is weighed, so they are its own fields. The other two differ between releases and sit in a per-version list beside them. Each field is omitted when it carries nothing. | Field | Carries | What the author edits | |---|---|---| | `unplaceable_floors` | Floors | The `@requires` line. The floor names no release of this edition, so no version can be weighed against it and none is certified. | | `dropped_scopes` | Scope keys, and `site::SITE::FROM ↔ TO` for a walkway | The member or `connect` row that produced no voxels. It refuses every version before its ID table is consulted, since a partial build is not certified. | | `states_unmapped` | Palette entries, as `id[states]` | The theme slot bound to that material. The edition's writer cannot carry those states, so it refuses the build at every version. | | `versions` | Refused targets | One entry per version that refused for a reason of its own. | Beside rather than instead: a file can declare a floor this edition cannot place *and* use an ID one of its releases has never had. A shape that reported the first alone would send the author back for the second after the repair, one cause per run, which is the loop this row exists to close. `versions` is a **subsequence** of `considered`, not a parallel array. A release with nothing against it but an edition-wide answer above contributes no entry, so a consumer joins on `version` rather than by position. Each entry carries its `version` and a `refusal` tag: | `refusal` | Carries | What the author edits | |---|---|---| | `below_floor` | `floors` | The `@requires` line. Only the floors that refuse *this* version: a file declaring several is a file where the repair is one line rather than all of them. | | `lowering_refused` | `findings` | Whatever the findings name, usually a material or an ID, and it differs per version. | The two are exclusive, because a version below a floor is never lowered: a floor is a relation between the source and the target and no ID table changes it. A floor is `{declared, line, col, declared_by?}`: the floor as the author wrote it, scope and all, and where it is written. `declared_by` is `{keyword, name}` with `keyword` one of `def` or `theme`, for a floor a build inherited from a part; it is absent for a floor on the file itself, because the position already points at the line and the line is the file's. `findings` are rendered the way [Lint §11.2](/spec/lint/#112-machine-readable-payload) renders a finding, and are the same findings the run prints under that version on stderr. That section is unchanged by this row: these ride inside the report rather than in the `{"diagnostics": [ ... ]}` document, and a report is not a refusal. The text rows say none of this. `buildable targets: Bedrock: none (1.21.0, 1.21.40, 1.21.60 all refuse)` is true for every one of the five causes. Each cause is reported on stderr as well, though not in the same shape: the two floor causes print a `note:` carrying the position of the line, a dropped scope prints a `note:` naming the scope and no position, an entry the writer cannot carry prints a `note:` naming the entry, and a refused lowering prints the findings themselves under the version, each with its own position. Only the JSON lacks them, and `reason` fills that gap. A fifth line, `recommended test targets`, belongs to this axis and answers a different question again: which versions are worth testing against. No code path emits it yet. ## 10.6 Provenance and lock The `.crn` carries the language version it is written against (`@cairn`) and, about targets, only `@intended_targets`, a hint. `verified: true`, the DataVersion, and the hashes exist only in the lock, written by the compiler on a successful build. They are never hand-written. ```yaml # build.crn.lock (compiler-generated) lock_schema_version: 1 # revision of this document's own schema source_hash: sha256:... cairn_version: 2026.10.0 # the Cairn release that wrote it, as `cairn --version` prints it target: { edition: java, mc_version: 1.20.4, data_version: 3700 } inputs: { registry_pack_hash: sha256:..., constraint_catalog_hash: sha256:... } resolved_ir_hash: sha256:... verified: true member_version_sensitivity: [ { id: yard_water, reason: "cauldron split at 1.17" } ] ``` A compile writes the lock next to its source as `.lock` unless `--lock` names another path. No constraint catalog ships yet ([§10.3](#103-backend--data-tables)), so today `constraint_catalog_hash` is all zeros and `member_version_sensitivity` is `[]`. `resolved_ir_hash` is the core of reproducibility: it fixes the IR after macro expansion, default filling, and auto-address assignment. Auto-address assignment is not implemented yet: a member has an address only where it carries `id=` ([§9.2](/spec/components-editing-sites/#92-editing-model)). `lock_schema_version` leads the document so a reader can decide whether it understands the rest before parsing it. Version `1` is the shape above plus two keys written only when they are non-empty: `placements`, each `place` row's resolved origin and extent, and `walkways`, each `connect` row's resolved strip and path material. A document omitting `lock_schema_version` is version `1`. A document declaring a higher version is refused rather than read as if the field names still meant the same thing. Keys the schema does not declare are refused wherever they appear. Recompiling for a different target shows the difference from the verified one loudly: ```text $ cairn compile build.crn --edition java --target 1.21.4 --lock build.crn.lock W_PREVIOUSLY_VERIFIED_TARGET: verified for 1.20.4/DataVersion 3700, now 1.21.4/4189. W_SEMANTIC_SENSITIVITY: 2 members may resolve differently: yard_water, fence ``` The second warning reads the members the previous lock lists, so no lock a compile writes today produces it. ## 10.7 Java / Bedrock portability Derivation rules are edition-specific: **`intent_state` is neutral, `resolved_state` is per-edition**. The contract is "from the same intent, resolve the nearest legal representation per edition", not "guarantee the same result". ```yaml intent_state: { primitive: stairs, corner: inner_left, facing: east } # edition-neutral resolved_state: java: { facing: east, half: bottom, shape: inner_left } bedrock: { weirdo_direction: 0, upside_down_bit: false } # no shape → corners don't join ``` When a resolved difference becomes a visual or functional one, the build says so. `themed-tower`'s eave stair is `shape=outer_left`: ```text $ cairn compile examples/themed-tower.crn --edition bedrock warning[W_INTENT_DEGRADED]: struct::keep: minecraft:dark_oak_stairs[facing=south,half=top,shape=outer_left]: Bedrock has no `shape` state; its stairs render straight, so corners show visual gaps ``` The canonical vocabulary absorbs only ID, state, and serialization differences. **Concept absence and game-behaviour differences are not absorbed.** The cases that cannot be: - display entities (absent on Bedrock) - stairs `shape` (no such state on Bedrock) - armor_stand pose - redstone propagation - item components ↔ Bedrock item NBT - light block internal behaviour ### Writing an alternative **Subject to change.** `@edition` guards, `hologram`, `raw_block`, `slot` rules that take arguments, and coordinate triples are not built yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). `@edition` conditionals in the semantic layer are forbidden. When an alternative is needed, work down this hierarchy: 1. Use a closed semantic primitive (neutral). If it is not representable, fail loud with `E_PARITY_UNSUPPORTED`. 2. Fall back via **slot + per-edition theme**, resolving a `floating_text` slot to `text_display` on Java and a glowing sign on Bedrock. 3. Only at the escape-hatch layer, guard with `@edition`. Raw IDs and NBT are edition-specific by nature. ``` @requires bedrock version>=1.21.40 # the Bedrock branch below is spelled for the flattened ids hologram id=shop_sign text="Weapon" mat_slot=floating_text # the semantic layer is always neutral theme shop_java: slot floating_text -> text_display scale=2.0 theme shop_bedrock: slot floating_text -> sign glowing=true # Bedrock fallback @edition java { raw_block mat=minecraft:light[level=15] at=4,3,2 } @edition bedrock { raw_block mat=minecraft:light_block_15 at=4,3,2 } ``` The parser accepts only the snippet's `@requires` line today. `hologram` stands at top level, where only `theme`, `def`, `site` and `struct` open an item, so it is `E_PARSE`, and the parse ends there. Each later line would fail on its own as well. A `theme` takes its rules on indented lines under its header, so the one-line form is `E_PARSE` at `slot`, and even indented, a `slot` rule binds one token and takes nothing after it, so `scale=2.0` and `glowing=true` are `E_PARSE`. `@edition` is an unknown directive (`E_PARSE`), and inside a body `hologram` and `raw_block` are `E_UNKNOWN_KEYWORD`. `E_PARITY_UNSUPPORTED` is not implemented. ### `@edition` pins an edition, not a version **Subject to change.** No `@edition` guard parses yet ([Compatibility Tiers](/spec/compatibility/#subject-to-change)). The rest of what this section leans on is current behaviour: the per-version id check, the `aliases` answer, `E_VERSION_CAP` and `E_INTENDED_TARGET_CAP`. The guard settles which branch is built and nothing else. The id inside it is still checked against the one `(edition, version)` the compile pinned ([§10.4](#104-fail-loud-and-minimum-version-inference)), so where an edition respells a block inside its own supported range, `@edition bedrock` names the branch and the file's floor names the spelling. Bedrock's light block is that case, and it is why the snippet above carries a floor. 1.21.0 spells the block `light_block` and carries the level beside it as a `block_light_level` state; 1.21.40 promoted the level into the id, so 1.21.40 and 1.21.60 spell the same block `light_block_0` … `light_block_15` and have no id named `light_block` at all. The `aliases` row holding all of those spellings together ([§10.4](#104-fail-loud-and-minimum-version-inference)) answers the diagnostic and not the source. Its answer is the closed set the pinned target declares: `light` against Bedrock 1.21.60 comes back as all sixteen levels. A set of sixteen is not a spelling. Picking one of them is the silent substitution that section forbids, so it stays the author's to do. Writing the branch for one of the two shapes is doing it, and the floor is what says which shape that is. Being scoped, it is inert on the Java build ([§10.4](#a-floor-may-name-its-edition)), which the other branch serves. Leaving the floor off is loud rather than wrong: `light_block_15` against Bedrock 1.21.0 is `E_UNKNOWN_ID`, since the check is per version. The floor adds two things. One is a different refusal: with it, the same command is `E_VERSION_CAP`, which points at `--target` and the floor rather than at the block, since a compile checks no id at a target its floors refuse ([§10.4](#the-declared-floor-is-enforced)). The other is a declaration: the version half of what the branch is for, written where the rest of the file's constraints are, and the half the other headers can be read against. A file floored at 1.21.40 whose `@intended_targets` names 1.21.0 is `E_INTENDED_TARGET_CAP` at `cairn check` ([§10.4](#the-hint-is-weighed-against-the-floor)), before any target is picked; the same file without the floor says nothing until one is. A build that must serve both spellings is two builds: there is no version conditional to pair with `@edition`. ### The build picks the variant, not the source `theme NAME_java` and `theme NAME_bedrock` declare two variants of the logical theme `NAME`. A `--edition` pin binds that edition's variant, falls back to an unsuffixed `NAME`, and stops there. Binding the *other* edition's variant would route its slot values into this edition's output, which is the silent substitution [§10.4](#104-fail-loud-and-minimum-version-inference) forbids. When neither exists the compile stops with `E_THEME_VARIANT_MISSING` rather than building the requested extent out of air. `place ... theme=NAME` names the **logical** theme and follows exactly that rule, so one site places the same def under whichever variant the build needs. Naming a variant there (`theme=shop_bedrock`) still resolves: the pin binds the variant it selects, and `W_THEME_VARIANT_REBOUND` says which was bound instead. The neutral spelling is still what the semantic layer is meant to carry. With no `--edition` pin, nothing re-picks a variant the author named. A declared name binds verbatim. A name written *without* a suffix resolves through the same unpinned order the module-level pick uses. A name written *with* a suffix the module does not declare is `E_UNRESOLVED_THEME_REF`. ### Cross-version application Asymmetric by design: - **Downgrade** (new-version NBT → old-version world) is a hard error. Unknown components cause crashes and corruption. - **Upgrade** (old-version NBT → new-version world) is a loud warning plus a DataVersion stamp, and depends on DFU. It requires an explicit `--allow-cross-version`. No command applies a structure file to a world yet, so neither rule is enforced and no command takes `--allow-cross-version`. Not every build needs to be edition-portable. The compiler's job is to state what breaks portability. ## 10.8 Compatibility tier of Cairn's own surfaces The `(edition, version)` axis above covers what Cairn *emits*. The orthogonal axis is what Cairn promises about its own evolution: `.crn` syntax, the lockfile, the CLI flags, the Rust API. CalVer has no "major" axis to read those promises off, so they are spelled out in [Compatibility Tiers](/spec/compatibility/). A `Stable` surface gives one release of `W_DEPRECATED` lead time, a code reserved until the first deprecation adds it; an `Evolving` surface can change in any monthly minor; `Internal` makes no promise. # 11. Lint and Constraint Validation The compiler reports warnings and errors with line numbers. Every message MUST carry the self-correction triple: **what is wrong / valid candidates in the target / a suggested fix**. That shape is what feeds the loop in [Evaluation Framework](/spec/evaluation/). ## 11.1 Diagnostic codes This section is the catalog: every code a stable command can raise has a row here, and a code a stable command raises with no row is a bug in this section rather than a code outside it. A code another chapter names that no command raises yet, such as `E_STATE_DOMAIN`, is a reserved code ([Compatibility Tiers §C.3](/spec/compatibility/#c3-how-a-break-is-communicated)). Where a code's rule belongs to another chapter, the row states what the code means and links there for the rule. The row is what a reader with a code in hand needs to find, and the chapter is where the behaviour is defined. Every code of the redstone pipeline is outside that promise: the `E_LOGIC_*` / `W_LOGIC_*` codes, and `E_NO_CIRCUIT_REGION`, `E_ROUTE_CONGESTION`, `E_ATTENUATION_LIMIT` and `W_ROUTE_CROSS_LAYER_CLEARANCE`. They are reachable only through `cairn synth --experimental-logic-synth`, which is Internal tier ([Compatibility](/spec/compatibility/)). Nothing about those strings is guaranteed, so a row here would state a contract that does not exist. [Redstone and Logic](/spec/redstone/) names the ones its own rules turn on. ### Duplicates | Code | Meaning | |---|---| | `E_DUPLICATE_SIZE` | A header declares more than one `size=`. | | `E_DUPLICATE_SLOT` | A `theme` body declares the same slot twice. | | `E_DUPLICATE_ARG` | A `key=` is repeated in one argument list. | | `E_DUPLICATE_ID` | Two members share an `id=` in the same body scope. | | `E_DUPLICATE_SELECTOR` | Two selector rows in one `theme` select the same members and bind the same key. | | `E_DUPLICATE_ITEM` | Two top-level items of the same kind share a name. | | `E_DUPLICATE_HEADER` | A single-valued `@directive` is declared more than once. | | `E_DUPLICATE_CIRCUIT` | A `struct` or `def` body has more than one `circuit` line. | `E_DUPLICATE_ID` leaves two `place` rows of one `site` body to `E_DUPLICATE_PLACE_ID` ([Sites and placements](#sites-and-placements)), which names the site. That holds for an id refused as `E_INVALID_PLACE_ID` too: the second row sharing it gets `E_DUPLICATE_PLACE_ID` beside its own `E_INVALID_PLACE_ID`, so renaming both rows to one usable id raises nothing new. A `place` row sharing its `id=` with any other row of that body, such as a `connect`, is still `E_DUPLICATE_ID`. So are two `place` rows indented under one row, which are not in that body. `E_DUPLICATE_SELECTOR` compares selectors by meaning, not by text: attribute order does not count, and `class=` / `id=` / `mat_slot=` compare as label text, so `small` and `"small"` are one value. Rows that bind *different* keys compose and are not reported. Neither are rows whose attributes partly overlap (see [Materials and Themes §7.1](/spec/materials-themes/#71-slots-as-dependency-injection)). `E_DUPLICATE_SELECTOR` is an error even while selector bindings are reserved ([§11.3](#113-error-vs-warning)). `E_DUPLICATE_ITEM` treats `theme` / `def` / `struct` / `site` as four separate namespaces, so one name may appear once in each. For the first three the first declaration resolves and the rest bind nothing. Two `site` blocks of one name instead merge into a shared `site::NAME::PLACE_ID` namespace: every place with a distinct `id=` still builds, only a repeated `id=` collides, and `east_of=` does not reach across the blocks. `E_DUPLICATE_HEADER` covers `@cairn` and `@intended_targets`. `@requires` is excluded: its floors compose to the strictest across every line, so a second one adds a constraint ([§5.3](/spec/syntax/#53-headers)). ### Syntax and structure | Code | Meaning | |---|---| | `E_PARSE` | The source did not parse. | | `E_UNKNOWN_KEYWORD` | The statement keyword is not in the known-keyword table. | | `E_UNKNOWN_ARGUMENT` | A `key=` outside the vocabulary of the member's keyword, written as an argument or inside the member's own `[key=value]`, or outside the `size=` / `class=` a `struct` / `def` header takes. | | `W_IGNORED_ARGUMENT` | A `key=` inside that vocabulary, or inside a `struct` / `def` header's, that no pass read on the line it was written on, or any `key=` bound by a `theme` selector row, which no pass reads yet. | | `E_MISPLACED_BINDING` | A `-> value` tail on a member whose keyword cannot emit a signal ([§14.2](/spec/redstone/#142-signal-binding)). | | `E_MISPLACED_MEMBER` | The keyword is known, but the enclosing body has no reader for it, or it is a `circuit` line under a `level`. | | `E_UNEXPECTED_POSITIONAL` | A bare value on a line that reads none ([§5.1](/spec/syntax/#51-lexical)). | | `E_UNSUPPORTED_NESTING` | A member carries an indented body that nothing reads. | | `E_TYPE_MISMATCH_LABEL` | A label-typed key's value is not an identifier or string. | | `E_TYPE_MISMATCH_SIZE` | A `size=` value is not a `WxH` literal. | | `E_CONNECT_ARITY` | A `connect` row's shape is not `FROM.PORT to TO.PORT`. | | `E_INVALID_REQUIRES` | A `requires` expression that is not a version floor, written as the `@requires` header or as a `def` / `theme` body line ([§5.3](/spec/syntax/#53-headers)). | | `W_INVALID_CAIRN_VERSION` | An `@cairn` value that is not a `YYYY.M[.PATCH]` language version ([§5.3](/spec/syntax/#53-headers)). | | `W_FUTURE_CAIRN_VERSION` | An `@cairn` value naming a language version later than the compiler reading it. | `E_MISPLACED_MEMBER` fires on a `place` / `connect` inside a `struct` or `def`, or a geometry keyword among a `site`'s rows. It is reported once at the offending row, and anything indented under it goes with it. It also fires on a `circuit` line under a `level`, directly or through `level`s nested in it. A reservation spans the whole scope, so place-and-route reads a `circuit` line only among the `struct`'s or `def`'s own members ([§14.5](/spec/redstone/#145-place-and-route)), and one under a `level` reserves nothing. `E_DUPLICATE_CIRCUIT` counts only the body's own members, so it does not report that line as well. A `level` that groups nothing, such as one inside another, is `E_UNSUPPORTED_NESTING` as well: that finding is about the blocks its members lose, and a `circuit` line writes none. `E_UNSUPPORTED_NESTING`: only `level y=N` inside a `struct` or `def` groups members, and a `site` body is a flat list. Reported once per dropped subtree, at its root. `E_TYPE_MISMATCH_LABEL`: the label-typed keys are `id=`, `class=`, `mat_slot=`, `use=`, and `theme=`. For `use=` and `theme=` a mistyped value looks the same as an absent key to the resolver. This code says the key is on the line but unusable; `E_INCOMPLETE_PLACE` says it is missing. `E_CONNECT_ARITY`: `connect FROM.PORT to TO.PORT` is the one form that reads positionals. The code covers a missing half, a missing or replaced `to` keyword, extra trailing positionals, and an endpoint that is not a one-dot `PLACE.PORT` reference. The two endpoints are reported separately, since they are independent fix sites. `E_INVALID_REQUIRES`: the accepted shape is an optional edition, `version`, `>=`, and a version label, with whitespace optional. The code covers a word before `version` that is not an edition, any other operator, a missing version, a component that does not begin with a digit or does not fit in a `u32`, a `-` with no readable pre-release tag after it, and text after the version. It does *not* cover a well-formed label the target edition has no `DataVersion` for; that is `E_REQUIRES_UNORDERABLE`, and it is not a syntax fact. Both spellings of the floor are checked, and by the same rule: the `@requires` header, and the member-level `requires` line a `def` or a `theme` may carry ([§10.4](/spec/versioning-editions/#a-part-may-declare-its-own-floor)). A part no build instantiates is checked too, because the mistake is in the line, not in whether anything reads it. `W_INVALID_CAIRN_VERSION`: the accepted shape is `YYYY.M` or `YYYY.M.PATCH`: a four-digit year, a month `1 … 12`, and an optional patch, every component decimal digits. A leading zero on the month is accepted and does not change it: `2026.06` and `2026.6` are one version, the first being calver.org's `YYYY.0M` and the second the `YYYY.M` a Cargo `version` field can carry. The code covers a value that is not two or three components, a component that is empty or not digits, a year that is not four digits, a month outside the calendar, a patch past `u32`, and a second word after the version. The header value is a whole line, so `@cairn 2026.6 draft` names a version and then something else. This is deliberately stricter than `@requires`, which reads a Minecraft label out of Mojang's namespace and only has to order it, so a component there need only *begin* with a digit and a pre-release tag is a label too. `@cairn` names Cairn's own version, so every component is digits, `2026.13` is a month that does not exist and `1.2` is a semver rather than a year. `W_FUTURE_CAIRN_VERSION` is the one thing a compiler can usefully say about a file written against a language newer than itself: a keyword or argument added after this build is reported as `E_UNKNOWN_KEYWORD` or `E_UNKNOWN_ARGUMENT`, and only the header knows those findings may be about the version gap rather than about the lines they name. That reaches what a later language adds *within* the shapes this one has. A whole new syntactic form, such as a directive or a top-level item, is `E_PARSE`, and parsing precedes every check pass ([§11.3](#113-error-vs-warning)), so this finding cannot appear in the case the version gap explains best. There the header is read out of the text as one line, matched by a leading `@cairn` and read to end of line, and `E_PARSE` carries a note saying the file declares a later language than the build reading it. A note rather than a second finding, because a source that does not parse reports `E_PARSE` alone and that stays true. Only a value that reads as a version earns it: a malformed one is `W_INVALID_CAIRN_VERSION`'s business, and repeating that on an unrelated parse failure would be noise. The two codes never both fire on one directive: a value that is not read as a version has no version to compare. ### Materials and targets | Code | Meaning | |---|---| | `E_UNKNOWN_ID` | A resolved block ID the pinned target does not declare. | | `E_VERSION_CAP` | `--target` is below an `@requires` floor the source declares ([versioning-editions §10.4](/spec/versioning-editions/)). | | `E_REQUIRES_UNORDERABLE` | An `@requires` floor names a version the target edition's `DataVersion` table cannot place ([versioning-editions §10.4](/spec/versioning-editions/)). | | `E_INTENDED_TARGET_CAP` | Every version `@intended_targets` names is below a floor the same file declares. | | `W_INTENDED_TARGET_CAP` | Some, not all, of them are. | | `W_INTENDED_TARGET_UNSUPPORTED` | `@intended_targets` names a version no `--target` of the edition can build. | | `E_INCOMPATIBLE_MATERIAL` | A member whose geometry attaches blockstates is bound to a material that cannot carry them. | | `E_MISSING_MATERIAL` | A member whose only route to a block is `mat_slot=` was written without one. | | `E_UNRESOLVED_SLOT` | A member whose role reads a `mat_slot=` names a slot the bound theme does not declare. | | `E_UNKNOWN_SLOT_TARGET` | A `slot NAME -> VALUE` whose value is neither a canonical nor an abstract material token ([Materials and Themes](/spec/materials-themes/)). | | `E_THEME_SELECTOR_UNMATCHED` | A `theme` selector row that matches no member of the scopes the theme is bound to. A theme no scope binds is not checked. | | `E_THEME_VARIANT_MISSING` | The pinned edition can bind none of a theme's per-edition variants. | | `E_INCOMPLETE_PLACE` | A `place` row omits `id=`, `use=`, or `theme=` ([§9.3](/spec/components-editing-sites/#93-multi-building-with-site)). | | `E_UNKNOWN_ABSTRACT_TOKEN` | A `mat_slot=` resolves to an abstract material token the offered pack's catalog does not declare ([Materials and Themes](/spec/materials-themes/)). | | `W_ABSTRACT_TOKEN_DEFERRED` | The same token with no catalog offered at all, so there is nothing to lift it against. | | `W_STATE_LITERAL_UNCHECKED` | A canonical token's state literal (`@oak_log[axis=x]`) was taken as written, since nothing checks its properties and values against the target until `E_STATE_DOMAIN` is implemented ([Versioning and Editions](/spec/versioning-editions/)). | | `W_NO_THEME_BOUND` | A scope that reads a `mat_slot=` has no theme bound to it, so no `mat_slot=` it reads resolves to a block. | | `W_THEME_VARIANT_REBOUND` | A `place theme=` names one edition's variant and the pinned edition bound a different one ([Versioning and Editions](/spec/versioning-editions/)). | | `W_INTENT_DEGRADED` | A palette entry lost an intent the pinned edition has no form for, such as a stair's `shape` on Bedrock; one line per entry ([Versioning and Editions §10.7](/spec/versioning-editions/#107-java--bedrock-portability)). | | `W_PREVIOUSLY_VERIFIED_TARGET` | The lock being replaced verified a different `(edition, version)`; the line names both ([Versioning and Editions §10.6](/spec/versioning-editions/#106-provenance-and-lock)). | | `W_SEMANTIC_SENSITIVITY` | After `W_PREVIOUSLY_VERIFIED_TARGET`, the members the previous lock's `member_version_sensitivity` lists, as ones that may resolve differently at the new target ([§10.6](/spec/versioning-editions/#106-provenance-and-lock)). No lock the compiler writes lists any yet, since no constraint catalog ships, so a build over one does not raise it today. | The last three are `cairn compile`'s alone: they are about the artifact and the lock it writes, so they carry no span and no other command raises them. `E_UNKNOWN_ID` and `E_INCOMPATIBLE_MATERIAL` are raised during block-array lowering, which `cairn compile`, `cairn lower`, `cairn info` and `cairn check` all run, as does the language server. `E_UNKNOWN_ID` further needs a pinned target, so three commands raise it: `cairn compile --target`, `cairn check --edition E --target V`, and `cairn info`, which lowers once per supported version for its `buildable targets` row and prints each refusing version's findings under `note: refuses this source`, exiting 0 all the same ([Versioning and Editions](/spec/versioning-editions/#the-buildable-targets-row)). `lower` lowers against no version, as does the rest of `info`'s report, and so does a `compile` whose target the file's floors refuse ([Versioning and Editions](/spec/versioning-editions/#the-declared-floor-is-enforced)). A `cairn check` with no `--target`, and the language server, lower with no target at all, so they raise `E_INCOMPATIBLE_MATERIAL` only on a canonical token some shipped version declares, and never `E_UNKNOWN_ID` ([§11.3](#113-error-vs-warning)). `W_STATE_LITERAL_UNCHECKED` is raised by the same lowering, on every state literal it reads from a theme slot or a `connect … path=`, so `cairn compile`, `cairn lower`, `cairn info`, `cairn check` with or without `--target`, and the language server report it under either edition. It stands in for `E_STATE_DOMAIN`: until the compiler holds a table of each block's states, a property the block lacks or a value outside its domain is written into the structure file unchanged, and the warning is what keeps that from being silent. `cairn check --target` exists so a CI job can gate on the check command and still see the lowering-stage findings a compile would refuse on. Without it, an id the target does not declare passes `check` at exit 0 and stops `cairn compile` at exit 1, because the information that decides it, the one `(edition, version)` pair, is not on `check`'s command line. It requires `--edition` for the reason [Compilation Model §4.2](/spec/compilation/#42-target-axes) refuses `--target` alone, and runs the same lowering pass against the same table `compile` does at any target the file's floors let through, so a lost scope earns the same `E_PARTIAL_BUILD`. What it does not do is anything `compile` writes: no artifact, no lockfile, and no `@requires` floor enforcement. A lock certifies a build, and only the command that produces one holds `--target` to the floors (`E_VERSION_CAP`). So at a target the floors refuse, the two commands name different causes: `check` pins the target and reports the ids it lacks, with `E_PARTIAL_BUILD` for a scope the missing ids leave empty, while `compile` checks no id and reports the floor ([Versioning and Editions](/spec/versioning-editions/#the-declared-floor-is-enforced)). Leaving the flag off still lowers, with no target, and reports only the findings every target that reads their line raises ([§11.3](#113-error-vs-warning)). See [Versioning and Editions §10.4](/spec/versioning-editions/#104-fail-loud-and-minimum-version-inference). `E_INCOMPATIBLE_MATERIAL` today means a sloped roof or an eave `stair` bound outside the stair family ([Compilation Model §4.3](/spec/compilation/#43-gable-roof-voxel-rules)). `E_THEME_VARIANT_MISSING` fires only under `--edition`, and is reported **once per logical theme** however many scopes read it, since they all want the same edit in the same `theme` block. Every placement naming it is still refused, whatever its `def` reads: a `place`'s `theme=` binds the theme, the lockfile records the bound theme for the placement, and the theme's floor applies once it is bound ([Versioning and Editions](/spec/versioning-editions/#a-part-may-declare-its-own-floor)). A module that names such a theme in no `place`, and whose `struct` and `def` members read no `mat_slot=` from it, is not reported: the build is byte-identical with or without the pin. A `mat_slot=` on a keyword that reads none, such as a `door`'s, is not such a read ([§11.3](#113-error-vs-warning)). `E_THEME_SELECTOR_UNMATCHED` is a warning despite its prefix. A rule that matches nothing overrides nothing, so every member keeps the material it would have had with the rule deleted; the finding is about the author's intent rather than about what was built. The prefix is part of the code string, which is Stable ([Compatibility Tiers](/spec/compatibility/)), so it stays as written. Read severity from the `severity` field rather than from the first letter. `E_UNKNOWN_SLOT_TARGET` is an error on the opposite test: no `mat_slot=` pointing at a slot bound to something other than a material token resolves. A `floor` that names it is left air; a `walls` that names it is not built and takes up no rows, so a `door` or `window` cut into it is deferred; a `window` that names it is not cut, so its wall stays; and a `roof`, eave `stair` or `pressure_plate` that names it is built from its default block. Were it a warning, a theme whose slots are all mistyped would still build at exit 0 every scope that keeps something to draw, such as a `roof`: shorter than asked, with no floor and no walls, and only default blocks, less any eave `stair` or `pressure_plate` set higher than the shorter structure reaches. `E_MISSING_MATERIAL` and `E_UNRESOLVED_SLOT` are the two halves of one split, and no member earns both: the key is absent for the first and present-but-unusable for the second. They have different repairs, which is why they are different codes: the same division `E_INCOMPLETE_PLACE` and `E_TYPE_MISMATCH_LABEL` draw on a `place` row. The split is drawn on the keywords that read a `mat_slot=`. On one that reads none, neither half applies: nothing would read the key, so its absence is not reported, and its name is not looked up, so a label written there is `W_IGNORED_ARGUMENT` whatever slot it names ([§11.3](#113-error-vs-warning)). `E_MISSING_MATERIAL` applies to the roles that put nothing anywhere without one. `floor` and `walls` reach the palette through the applied theme's slot map and have no default block, so a bare one contributes no voxel. A `window` without a `mat_slot=` is an **opening**, carved to air, and is not reported; that is how a narrow slit is punched through a wall without choosing a species for it. A `door` carves its opening and reads no material, since its own block is not placed yet. A `roof`, `stair` or `pressure_plate` paints a default block and is not reported either. `cairn check` raises it, before any lowering, and it needs no theme: a module that declares none is still told which of its members name no material. `E_UNRESOLVED_SLOT` is reported **at most once per member per bound theme**. A `def` body is resolved once as its own scope and once again for every `place` that instantiates it, and each of those resolutions binds a theme; a repeat against a theme already reported for that member is dropped. Two placements naming two themes are two findings: each names the theme it is about and each is a separate edit. Which resolution a surviving finding came from is not specified, because two of them can bind the same theme and still judge the slot differently. The difference is edition-variant softening. Without an `--edition` pin, a slot that any sibling variant of the picked theme declares counts as known and is not reported: the concrete binding is edition-specific and comes into scope only once a pin narrows the theme to one variant ([Versioning and Editions §10.7](/spec/versioning-editions/#107-java--bedrock-portability)). A `place ... theme=NAME` is softened the same way only when `NAME` names the logical theme, because naming a variant asks about that variant's slots alone. Two placements can therefore bind one theme and disagree about one slot. A `def` nothing places is still resolved, against the theme the module picks, so a file of defs and no `site` is checked as long as the module has a single logical theme to pick. Where it declares more than one, or none at all, no theme binds to the def's own scope and its `mat_slot=` names are not judged until a `place` chooses one. `E_INCOMPLETE_PLACE` names every key the row is short of, and the row is dropped from the build. `E_UNKNOWN_ABSTRACT_TOKEN` and `W_ABSTRACT_TOKEN_DEFERRED` differ on whether anything could have answered. A pack was offered and does not declare the token, so the build stops with a suggestion towards the closest one it does declare; no pack was offered, so nothing was asked and the member degrades with a warning. The second is the path only a library caller reaches, by lowering with no pack at all, and it is a warning for that reason: refusing there would refuse every source read without a pack. A front end with no target (the language server, or a `cairn check` with no `--target`) raises neither, and leaves the token to the pack of the target that builds it ([§11.3](#113-error-vs-warning)). The warning says how the member degrades. A `floor` leaves its cells air, and a `roof`, eave `stair` or `pressure_plate` is built from its default block. A `walls` is not built and takes up no rows, so a `door` or `window` cut into it is deferred. A `window` is not cut, so its wall stays, and a port on it is refused with it ([§9.3.5](/spec/components-editing-sites/#935-ports-and-connect)). `W_NO_THEME_BOUND` is the same shape one level up: a `mat_slot=` that resolves against no theme at all has no slot map to read, so the member degrades the same way. With no theme no `walls` is built or takes up rows, so no `door` or `window` is cut and the structure is shorter than asked. A `floor` leaves its cells air, and a `roof` is still built from its default block, as is an eave `stair` or `pressure_plate` that still fits the shorter structure; one set higher than it reaches is deferred. It is judged per scope: a scope with no theme bound that reads no `mat_slot=` is not reported, whatever the rest of the module reads. A `mat_slot=` on a keyword that reads none, such as a `door`'s, is not a read. Nor, for this warning, is one on a member a `level` drops ([Compilation Model §4.7](/spec/compilation/#47-level-grouping-and-volume-derivation)), which paints nothing whatever the theme: a `floor` or `roof` above `y=0`, or any member of a `level` whose body is `E_UNSUPPORTED_NESTING`. The three `@intended_targets` codes weigh the file's stated intent against its own floor ([versioning-editions §10.4](/spec/versioning-editions/#the-hint-is-weighed-against-the-floor)). A version the edition cannot build is `W_INTENDED_TARGET_UNSUPPORTED` and is not also weighed against a floor: "this target does not exist here" is what the author acts on, and a cap beside it would send them to edit a line that is not what stops the build. The rest, the versions the edition *can* build, are counted among themselves. *Every* one of them below a floor is `E_INTENDED_TARGET_CAP`, since the file can then be built for nothing it says it is for and the first `cairn compile --target` naming any of them is `E_VERSION_CAP`. *Some* of them is `W_INTENDED_TARGET_CAP`, because the header is a hint ([§5.3](/spec/syntax/#53-headers)) and the versions above the floor still build. A version that was never buildable is not in that count either way: it answers for none of the list, and letting it would report a file nothing can build as half a problem. One header can earn a cap code and the unsupported code at once; the versions it names are not all wrong in the same way. All three are per-edition answers, since a floor and a target label are ordered in one edition's `DataVersion` table. Every command that gates on `cairn check` (`check`, `info`, `lower`, `compile`, `synth`) reports the two cap codes, each weighing the header in the tables of the editions it is about: the one `--edition` names, the ones `cairn info --editions` lists, or both where the command names none. A finding either edition reaches is reported, because the contradiction is between two lines of the file however it is later built; one span carries one cap finding, and two editions disagreeing about how far it reaches report the error. `W_INTENDED_TARGET_UNSUPPORTED` waits until exactly one edition is in scope: a version Java cannot build is routinely the Bedrock target the author means, so with both in scope the question has not been asked. ### Sites and placements | Code | Meaning | |---|---| | `E_INVALID_PLACE_ID` | A `place id=` is empty, carries `.`, `:`, `/`, `\`, `*`, `\|`, `?`, `<`, `>`, `"`, whitespace or a control character, or is a device name Windows reserves (`CON`, `NUL`, `COM1`, …) in any letter case. | | `E_INVALID_STRUCT_NAME` | A `struct` is named after a device Windows reserves (`CON`, `NUL`, `COM1`, …) in any letter case. | | `E_DUPLICATE_PLACE_ID` | Two `place` rows in one site share an `id=`. | | `E_OUTPUT_NAME_COLLISION` | Two artifacts a build would write share a file name, ignoring case: a `struct` and a `place` of one name, one `id=` placed in two sites, or two walkways whose names flatten alike. | | `E_INVALID_PLACE_ORIGIN` | A `place` carries no origin selector or more than one, an `at=` other than `origin`, or an `east_of=` / `north_of=` that is not a label ([§9.3](/spec/components-editing-sites/#93-multi-building-with-site)). | | `E_UNRESOLVED_PLACE_REF` | A `place use=`, an `east_of=` / `north_of=`, or a `connect` endpoint names a place or def that does not exist. | | `E_UNRESOLVED_THEME_REF` | A `place theme=` names a theme the module does not declare. | | `W_DEFERRED_PLACE` | An `east_of=` / `north_of=` names a `place` refused for its id, so the row naming it is not placed either. | | `W_UNUSED_DEF` | A `def` no `place use=` references. | `E_INVALID_PLACE_ID` is about round-tripping rather than taste. The scope key `site::SITE::PLACE`, and every walkway key parsed back out of one, is built with `.` and `:` as separators, so an id carrying one cannot be read back. The id is also the name of the file the placement is written to in the output directory, and a `/` or `\` would make that name a path: a relative id with one lands in a subdirectory, and an absolute id replaces the output directory altogether. `*`, `|`, `?`, `<`, `>`, `"` and the control characters U+0000 to U+001F cannot appear in a Windows file name, so an id carrying one would build on Linux and fail to be written on Windows. Microsoft's naming rules also reserve a set of device names, whatever extension follows: `CON`, `PRN`, `AUX`, `NUL`, `COM0` to `COM9`, `LPT0` to `LPT9`, and `COM¹`, `COM²`, `COM³`, `LPT¹`, `LPT²` and `LPT³`, whose superscripts count as digits, each in any letter case. A Windows release that applies those rules opens `CON.nbt` as the console rather than as a file. Both are refused on every platform, so whether an id is accepted does not depend on the host that checks it. The other control characters, U+007F to U+009F, are legal in a Windows file name and are refused on their own ground: they print as nothing or move the terminal cursor, so a finding that quotes the id could not show it. `id=` accepts a string literal, which is what let the value through. A `struct` is written under its own name ([§9.3.4](/spec/components-editing-sites/#934-output-naming)), so one named after a device is `E_INVALID_STRUCT_NAME`, for the same reason and in any letter case. A struct name is a bare identifier, so none of the characters above can reach it. Neither a site name nor a port id is refused for spelling a device name: each is only ever one part of a walkway's file name, such as `hamlet_walkway_home1_entry__home2_entry`, and Windows reads a file as a device only when the part of its name before the extension is the device's whole name. A later `east_of=` / `north_of=` naming the id of a row refused with `E_INVALID_PLACE_ID` still means that row, so it is not `E_UNRESOLVED_PLACE_REF`, which would send the author looking for a typo. It is `W_DEFERRED_PLACE`: the row naming the refused one is not placed either, since what it is placed against has no position, and the note points at the refused row, where the repair is. Renaming that row's id means renaming the reference with it. It is a warning for the reason `W_DEFERRED_CONNECT` is: the build already fails on the refused row, and a second error would send the author to a line that names the row it means. A `connect` endpoint naming the refused row is `W_DEFERRED_CONNECT`, whose note likewise points at the refused row. A reference above the refused row names no prior place, as it would for any other id, and is `E_UNRESOLVED_PLACE_REF`. `E_DUPLICATE_PLACE_ID` names both spans. The first row wins for everything that references the id and the duplicate is dropped, so a reference resolving to "the other one" is not a second finding. `W_UNUSED_DEF` counts every `place` row in a `site` body whose `use=` names the def, including a row refused for its id or its origin. That row does reference the def, and the finding with the repair is the one on the row: removing the def, as the warning would advise, only brings it back as `E_UNRESOLVED_PLACE_REF` once the row is fixed. A `use=` that is not an identifier or string (`use=3`) names no def, so it is not counted. `E_OUTPUT_NAME_COLLISION` follows from how artifacts are named ([§9.3.4](/spec/components-editing-sites/#934-output-naming)): a `struct` by its name, a `place` by its `id=` alone, and a walkway by its site and ports. Every one of them lands in the same output directory, so two can name one file, and if both are built, a build can keep only one of them. The check runs before lowering. It leaves out a sizeless `struct` and a `place` of a sizeless `def`, which lowering drops, and counts two `connect` rows for one pair of ports, in either order, as one walkway, which is what lowering lays. It still counts a struct or placement that `W_STRUCTURE_TOO_LARGE` drops, and a walkway whose search area is past the router's cap, which `W_WALKWAY_BLOCKED` reports and does not lay, so the finding says the two files *would* be one. Names are compared ignoring case, because `Hut` and `hut` are one file on the case-insensitive file systems macOS and Windows use by default, and whether a source builds should not depend on the host that builds it. The finding is raised with the other site findings, before lowering, so `cairn check` reports it without a `--target`. A name declared twice is not this code: a second `struct hut` is `E_DUPLICATE_ITEM`, and a second `id=` in one site is `E_DUPLICATE_PLACE_ID`. `E_UNRESOLVED_PLACE_REF` and `E_UNRESOLVED_THEME_REF` each carry a nearest-match suggestion when one fits the spell cap ([did you mean](#did-you-mean)). Both are errors because substituting something for the name would build a site the source did not describe. ### Connections and walkways | Code | Meaning | |---|---| | `E_UNRESOLVED_PORT` | A `connect A.PORT to B.PORT` names a port id that no member declared directly in the referenced def's body carries. A member under a `level` cannot be a port yet, and the finding says so when the id is on one. | | `E_AMBIGUOUS_PORT` | The port id matches more than one member of the referenced def. | | `E_MISSING_PATH_MATERIAL` | A `connect` row carries no `path=`, or a `path=` that is not a material token (`path=gravel` for `path=@gravel`), so the walkway has no material to lay. | | `W_DUPLICATE_WALKWAY` | A `connect` joins the same two ports, in either order, as an earlier row in the same site that already laid them. | | `W_INVALID_WALKWAY_IDENT` | A site, place or port identifier in a `connect` contains `__`, or a place or port identifier starts or ends with `_`. | | `W_DEFERRED_CONNECT` | A `connect` targets a `place` that was itself refused, so there is nothing to connect. | | `W_WALKWAY_BLOCKED` | Cells of the fallback path overlapped an existing structure and were dropped, or the straight L alone is past the router's 4,000,000-cell search-area cap and the walkway was not laid. | `E_UNRESOLVED_PORT` is the port half of the `place.port` shape alone; the place half is `E_UNRESOLVED_PLACE_REF`. `E_AMBIGUOUS_PORT` takes the first match for lowering and reports the collision, since the repair is to rename one of the colliding members rather than to pick for the author. `E_MISSING_PATH_MATERIAL` is an error, as `E_MISSING_MATERIAL` is, where `W_NO_THEME_BOUND` and `W_ABSTRACT_TOKEN_DEFERRED`, a material named with nothing to resolve it against, are warnings: a walkway that degrades to air leaves two buildings looking connected in the source and unconnected in the world, with nothing in the report to say so. `W_INVALID_WALKWAY_IDENT` is the same round-trip rule as the `.` / `:` half of `E_INVALID_PLACE_ID`, on a different separator. `__` joins the `from` and `to` halves of a walkway's scope key, so `b__c` in one half and `c__home2` in the other encode to one string. A `_` next to that separator merges into it the same way: `a.p_ to b.p` and `a.p to _b.p` both encode to `a.p___b.p`, and a port named `_` leaves a key that splits back into an empty port. Only the end of the `from` port and the start of the `to` place touch the separator. A `connect` can be written in either direction, so the start of every place and the end of every port can end up there. The other four edges, the end of a place and the start of a port, sit next to a `.` whichever way the row is written and cannot merge; they are refused too, so the rule stays one sentence: no place or port id starts or ends with `_`. The site is exempt from the edge rule, since `::` separates it from both neighbours. The row is dropped and the finding names the segment to rename. The walkway it asked for is lost, so `cairn compile` refuses the build with `E_PARTIAL_BUILD`, as it does for every row that lays nothing. `W_DEFERRED_CONNECT` follows whatever refused the `place`: an incomplete row, a mistyped key, an id refused with `E_INVALID_PLACE_ID` (the note then points at that row), a failed origin selector, an origin naming a row refused for its id (`W_DEFERRED_PLACE`, whose note leads on to that row), an unresolved `use=` or `theme=`. It is a warning because the finding that has the repair is the one on the `place`, or the one its note points at, and reporting the `connect` as a second error would send the author to a line that is correct. ### Lowering | Code | Meaning | |---|---| | `W_DEFERRED_MEMBER` | A member, or part of one, the block-array pass leaves out because another member did not build or because the pass does not lower what its line writes yet. | | `E_INVALID_MEMBER` | A member its own line keeps the block-array pass from building, whatever the rest of its struct builds. | | `W_STRUCT_NO_SIZE` | A `struct` declares no `size=WxH`, so lowering can derive no extent and skips it. | | `W_DEF_NO_SIZE` | The same on a `def`, so every `place use=` of it is skipped. | | `W_STRUCTURE_TOO_LARGE` | A scope's derived extent exceeds the volume the block-array pass will allocate for. | | `W_PALETTE_TOO_LARGE` | A scope paints more than 65,535 distinct block states besides air, past what one palette can index. | | `W_PHASE_CONFLICT` | Two members in one phase wrote one voxel to different blocks ([§4.8](/spec/compilation/#48-within-phase-conflicts-and-the-palette)). | | `E_PARTIAL_BUILD` | At least one requested scope, or a walkway a `connect` row asked for, did not lower, so the run produced less than was asked for. | `W_STRUCT_NO_SIZE` and `W_DEF_NO_SIZE` are one rule split by what carries it, so a filter matching on `code` can tell a struct that will not build from a template that will not instantiate. `W_STRUCTURE_TOO_LARGE` fires on a *combination*: `size=`, `walls height=`, `roof overhang=` and `level y=` are each range-checked on their own, and this is the product of them being out of reach. It is a warning rather than an error, matching the two above: the scope is skipped and the rest of the build is unaffected. `W_PALETTE_TOO_LARGE` is the same kind of limit on what a scope paints rather than where. Every state a member writes counts, including one a later member covers, so the limit is on the states written rather than the states the finished scope keeps. A vanilla registry has far fewer states, so a source reaches it only through block ids or state-literal properties no pinned target checks. Block ids go unchecked wherever lowering runs with no version pinned: in `cairn lower`, the range-wide lowering behind `cairn info`'s report, the language server and a `cairn check` with no `--target`, in a `cairn compile` or `cairn check --edition E --target V` naming a version the edition does not ship, and in a `cairn compile` whose target the file's floors refuse ([Versioning and Editions](/spec/versioning-editions/#the-declared-floor-is-enforced)). A state literal's properties go unchecked under every target, as `W_STATE_LITERAL_UNCHECKED` says ([Materials and targets](#materials-and-targets)), so every command that lowers can reach the limit, `cairn compile` with a target that resolves among them. A warning, for the reason above. `W_DEFERRED_MEMBER` keeps a partial build inspectable rather than failing the module: the rest of the scope lowers, and the finding names what is missing from it. In a struct body it covers three things, and in none of them does the member's own line keep it from being built. A member another member keeps out: a `door` or `window` in a course whose `walls` paint nothing or beside `walls` under a `level` that is not placed, or an eave `stair` beside a `roof` that draws nothing. A member whose line writes what the pass does not lower yet: a `floor` or `roof` under a raised `level`, a `window` with `repeat=` above 1 and a `sym=` that is `true` or unreadable, or a `pressure_plate` whose slot binds a state literal. And part of a member that is built: the mirror of a `sym=true` window that would overlap it, or the states a `mat_slot=` binding carries onto a roof that takes its own. The `place` and `connect` rows of a site it covers are in [Components, Editing, and Multi-building](/spec/components-editing-sites/). `E_INVALID_MEMBER` is an error for the reason `E_MISSING_MATERIAL` is ([§11.3](#113-error-vs-warning)): the member is dropped with nothing in its place, and the incomplete side is its own line rather than the compiler. A line does that with an argument the member cannot be built without left out or unreadable (a `window` with no `y=`, a `level` whose `y=` is not a non-negative integer, `walls` with no positive `height=`), a value outside the ones its key takes (a `roof kind=` that names no kind, `side=middle`, an eave `stair` whose `half=` is an identifier other than `top` or `bottom`), or arguments that put it outside its struct as written: a `window` past the end of its wall, a `door` or `window` whose rows no course of the walls holds, an eave `stair` above the struct or on one where no `roof` has an `overhang=` of at least 1. The struct as written is every member at the size its line asks for, whether or not it builds: a `roof` that draws nothing still rises and overhangs as its line says, and an unreadable value counts as the default its `W_IGNORED_ARGUMENT` puts in its place. A `roof` whose `kind=` or `slope_to=` does not read may rise as far as any roof on its footprint, and `walls` under a `level` that is not placed may hold any row, so a member only they could hold is deferred to them. A `circuit` line that reserves no region and an actuator patch that binds no door are refused the same way. [Redstone §14.2](/spec/redstone/#142-signal-binding) lists the lines that put a `pressure_plate` nowhere, and for a plate the drop reaches past the block array as well: its `->` binding is still read, so its signal stays in the netlist with no plate to drive it, and the finding says so in a note. A member the struct would have held had another member built is `W_DEFERRED_MEMBER` instead, with a note saying which member has the repair: a `walls` that paints nothing, a `roof` that draws nothing, or a `level` that is not placed. That member's finding, or the scope's `W_NO_THEME_BOUND`, says why it did not build. A member whose line is wrong too is `E_INVALID_MEMBER` all the same, and so is one whose line also writes what the pass does not lower yet, so neither hides a line's own fault. The members under a `level` that is not placed are the exception: `E_UNSUPPORTED_NESTING` says that level produces no blocks, and their own lines are read once it is placed. `E_PARTIAL_BUILD` is the run-level counterpart: a finding above says a scope builds without something, and this says a scope the command was asked for did not build at all. A scope that lowers to air alone did not build either, whatever left it empty: every member deferred or refused, no theme gave its `mat_slot=` members a block, or it declares no member. It is reported once for the run, naming how many of the requested scopes were lost, by `cairn compile` and by a `cairn check --edition E --target V` that runs the same lowering pass. `W_PHASE_CONFLICT` is last-wins reported rather than refused. [Compilation Model](/spec/compilation/) grants last-wins to local overrides within one phase, which is what an author restating a member is; two footprints that happen to intersect is not, and the grid cannot tell the two apart. The resolution the spec mandates still happens, and the finding says which voxel it happened at. ### Truth tables | Code | Meaning | |---|---| | `E_TRUTH_TABLE_EMPTY` | An `assert truth(...)` with no rows, or none whose output is `0` or `1`. | | `E_TRUTH_TABLE_DUPLICATE_INPUT` | An `assert truth(...)` lists one signal as two or more of its inputs. | | `E_TRUTH_TABLE_CONFLICT` | Two rows assign the same input combination different outputs. | | `W_TRUTH_TABLE_DUPLICATE_ROW` | Two rows cover the same input combination without contradicting each other. | | `W_TRUTH_TABLE_PARTIAL` | The rows leave input combinations unassigned. | `E_TRUTH_TABLE_DUPLICATE_INPUT` is reported on the whole `assert`, once per repeated signal, and no other truth-table code is raised for that table: every other one reads the rows against an input list that is wrong, so the rest of the table is left until the list names each signal once. `E_TRUTH_TABLE_CONFLICT` and `W_TRUTH_TABLE_DUPLICATE_ROW` are reported on the later row. A row is compared with every earlier row that shares a combination with it, so whether a table is refused does not depend on the order its rows are written in: `0- -> 1` after `00 -> 1; 01 -> 0` is `E_TRUTH_TABLE_CONFLICT`, though it agrees with the first of the two. A conflict takes precedence over a duplicate on the same row, and its note is at the first row assigning the combination it names the other output. Any other finding's note is at the first row assigning the combination it names, so every finding about one combination points at the same row. The spec does not say which of two conflicting rows an evaluator would read, because the repair is to decide which row is wrong. A `-` makes the same combination reachable from rows that do not look alike, so both codes are about the combination rather than about the pattern: `0-` and `-1` both assign `01`. The fix differs with the shape. A row inside an earlier one, such as `01` under `0-`, is deleted. Two rows that merely cross are narrowed, because deleting either would lose the combinations only it assigns. When the earlier row is itself reported for overlapping a row before it, the fix is to settle that row first instead: in `0- -> 1; -0 -> 1; 10 -> 1`, `-0` is told to narrow away from `0-`, and deleting `10` because `-0` stands for it would, together with that, leave `10` unassigned. A `-` **output** is the one shape that is neither a conflict nor a repeat: the row declines to constrain its combinations, so there is nothing for a concrete output to contradict, and nothing for it to agree with either. The pair is `W_TRUTH_TABLE_DUPLICATE_ROW`, and its fix names the asymmetry: whichever of the two rows is deleted, the table reads differently afterwards. A table with rows but no `0` or `1` output among them constrains nothing, which is why `E_TRUTH_TABLE_EMPTY` covers it too; the sentence differs from the no-rows one, because the repair is to change a row rather than to add one. The two warnings are warnings because every row present is still a real constraint. One table can earn both `W_TRUTH_TABLE_DUPLICATE_ROW` and `W_TRUTH_TABLE_PARTIAL`: a repeated row, or one inside an earlier one, fills no combination the table did not already have. Two rows that cross are the exception: the coverage finding is withheld there, because a count taken without the later row would name a combination the table does assign. ### Semantic categories Beyond the codes above, lint covers: | Category | Checks | |---|---| | **Geometry** | AABB expansion: a window outside the wall, a door hanging in mid-air. | | **attachment** | A frame, painting, sign, button, lever, or torch on a valid attachment face. | | **entity_aabb** | Entities not clipping walls or paths, not blocking a door's swing, not cramming. | | **support** | Hanging lanterns, torches, campfires, and gravity blocks such as gravel. | | **fluid** | Consistency of water source, flow, and `waterlogged`. | | **version_caps / parity** | Whether a state or entity schema is usable in the target ([Versioning and Editions](/spec/versioning-editions/)). | | **edit_stability** | Whether an `intent_state` change ripples into an unrelated member's `resolved_state`. | | **redstone** | Per-tick simulation against the declared truth table and temporal assertions; timing conflicts, QC dependence, routing congestion ([Redstone](/spec/redstone/)). | | **AABB interference** | On overlap, priority-merge or reject. Boundary blockstate re-resolution is the IR layer's job. | Of these, attachment, entity_aabb, support, fluid, edit_stability and AABB interference are planned, and no command checks them yet: two `place` rows whose bodies overlap are not reported. Geometry holds only in part: a door, window, eave stair or pressure plate its own line puts outside its struct is not drawn and is reported as `E_INVALID_MEMBER`, and one that only a member left unbuilt keeps out as `W_DEFERRED_MEMBER`. version_caps / parity runs only in part, through codes of its own: `E_VERSION_CAP` holds `--target` to the `@requires` floors, `E_UNKNOWN_ID` refuses a block id the pinned target does not declare, and `W_INTENT_DEGRADED` names what an edition cannot carry, while a state literal goes unchecked (`W_STATE_LITERAL_UNCHECKED`) and no entity schema is checked. The redstone row runs only in part as well: the truth-table codes check a table against itself, nothing simulates the circuit, and routing congestion is `E_ROUTE_CONGESTION`, which only the Internal-tier `cairn synth --experimental-logic-synth` reaches. ### "did you mean" A diagnostic that rejects a name against a closed vocabulary attaches the nearest candidate when one sits within a length-scaled Damerau-Levenshtein cap of ≤ 1 edit for 1–3 characters, ≤ 2 for 4–6, and ≤ 3 beyond. The names are a keyword, an argument key, a `mat_slot=` name, a place, def, theme or port reference, an abstract token, a `pressure_plate` side, a block id, and a `--target` version. The note reads ``did you mean `X`?``, with `X` written as the line would be (`home1.entry` for a port, `at=front.outside` for a plate); `E_UNKNOWN_ID` instead names the target's nearest block and carries it as `data.suggestion` ([§11.2](#112-machine-readable-payload)). An unknown keyword, argument key or `mat_slot=` name also prints the closed set (`expected one of: ...`), and an unknown `--target` the versions it could have named (`supported targets: ...`). A reference, a token and a block id print no such list. ## 11.2 Machine-readable payload Every command that takes `--format json` (`check`, `info`, `parse` and `lower`) writes exactly one JSON document to stdout under it, for every source it can read. `check`'s document is an array of findings, so a source that does not parse is that array with one `E_PARSE` element. `info`'s is the report; where there is no report, after a parse failure or any error-severity finding, it writes `{"diagnostics": [ ... ]}` instead, told apart from a report by its keys and by the exit code. Which pass raised the finding does not change that: the strict per-edition dry-run sees what the edition-neutral gate unions away, and a refusal it raises writes the same document, after every requested edition has been walked. Which pass raised the finding does decide what the document carries, and this is the contract rather than an accident. Where the edition-neutral pass refuses, its warnings are elements of the document beside the errors. Where the per-edition pass refuses, the document carries the errors alone: the neutral warnings have already been reported as text, and a per-edition warning belongs to a row the run is about to discard, so it reads on stderr under the note naming its edition. Warnings on a run that still has a report are reported as text on stderr in both formats. A run-level refusal is not an element of `check`'s array: an unshipped `--target` and a lowering that lost a scope (`E_PARTIAL_BUILD`) are facts about the command line and about the build rather than findings at a span, so both are reported on stderr and by the exit code in either format, the shape `compile` gives them. The array still carries every finding the run did reach, so it is a report of what was checked rather than an empty document. This is settled rather than pending: `check --format json` has no machine-readable form for a run-level refusal, and a consumer reads the verdict from the exit code. Stderr is prose for a person in either format. It is not part of this contract, and a consumer should treat it as unstructured text rather than parse it. What the consumer can tell without it is *that* the run was refused at the run level rather than by a finding: an exit of `1` over an array that holds no element with `"severity": "error"` means exactly that, down to a `[]` over a source with nothing to report. A refusal can also arrive on a run that has error-severity findings of its own, and then the array reads like any other error failure; that the run was *also* refused at the run level is said only on stderr. No other failure reads that way: a source that does not parse is an array carrying `E_PARSE`, and a file that cannot be read writes no document at all. Which of the two refusals it was, and what the build lost, is said only on stderr. One `info` refusal is a run-level refusal of the same kind: a palette carrying a blockstate a registry pack was expected to refuse costs that edition its portability row, and names no span in the source. Such a blockstate is either a leak in the pack or the compiler, which the author cannot repair, or a state literal on a stair in the source (a `facing` or `half` value outside the Java domain such as `@oak_stairs[facing=up]`, or a key other than `facing` / `half` / `shape`), which nothing checks against the target until `E_STATE_DOMAIN` is implemented. The refusal names both. A literal on any other block is counted `unsupported` instead. It reads as prose on stderr in both formats. The document is still written, since the promise is one document per input, not one element per refusal, so a run refused by nothing else writes `{"diagnostics": []}` and says the rest with its exit code. `parse`'s product is the AST and `lower`'s is the block-array IR. A dump is not a report, so a failure is not the dump with a hole in it: each writes the same `{"diagnostics": [ ... ]}` document `info` does, told apart from the dump by its keys and by the exit code. `lower` writes it for a source that does not parse and for one that fails a later pass, since neither leaves an IR worth dumping. Under every other `--format` the findings read as prose on stderr. `--format json` renders one object per finding: | Field | Type | Notes | |---|---|---| | `code` | string | Stable `E_*` / `W_*` identifier; same string as the gcc-style format. | | `severity` | string | `"error"` or `"warning"`. | | `line` | integer | 1-based line of the primary span's first byte. | | `col` | integer | 1-based column of the same byte, in Unicode scalar values. | | `end_line` | integer | 1-based line of the span's exclusive end boundary. | | `end_col` | integer | 1-based column of the same boundary. | | `primary` | string | The human-readable message. | | `notes` | array | `[{line?, col?, message}]`. Omitted when empty. | | `data` | object | Code-specific payload. Omitted when absent. | `data` is an open object tagged with `kind`. Match on `(code, data.kind)` rather than parsing `primary`. Additions are strictly additive, so ignore unknown `kind` values rather than failing on them. A value added to a field the table below gives as one of a list is an addition too, so treat a value you do not know as you would an unknown `kind`. Removing or retyping a field, renaming a `kind`, or leaving out a field that was always present changes what the code means and is a break ([Compatibility Tiers §C.3](/spec/compatibility/#c3-how-a-break-is-communicated)). Codes not listed below omit `data` entirely, so the JSON key is absent rather than `null`. | Code | `data` payload | |---|---| | `W_WALKWAY_BLOCKED` | `{ "kind": "walkway_blocked", "skipped": }`. Cells along the fallback L-shaped path that overlapped an existing structure and were dropped. Present when cells were dropped; absent when the walkway was past the router's cap and not laid. | | `E_DUPLICATE_SELECTOR` | `{ "kind": "duplicate_selector", "rebound": ["frame"] }`. The binding keys this row takes over from an earlier one, without the trailing `=`. Never empty. | | `E_UNKNOWN_ID` | `{ "kind": "unknown_id", "id", "registry", "origin", "token"?, "suggestion"?, "aliases"? }`. See below. | | `E_INCOMPATIBLE_MATERIAL` | `{ "kind": "incompatible_material", "id", "required", "slot"?, "token"? }`. The bound material, the family the geometry needs, and where the binding came from. | | `E_INCOMPLETE_PLACE` | `{ "kind": "incomplete_place", "missing": ["id", "use", "theme"] }`. The keys the row does not declare. Never empty. | | `E_INVALID_REQUIRES` | `{ "kind": "invalid_requires", "reason", "found" }`. `reason` is one of `not_a_version_requirement`, `unknown_edition_scope`, `unsupported_operator`, `empty_version`, `component_not_a_number`, `component_too_large`, `prerelease_not_a_tag`, `trailing_tokens`. `found` is empty when the failure names no fragment. | | `W_INVALID_CAIRN_VERSION` | `{ "kind": "invalid_cairn_version", "reason", "found" }`. `reason` is one of `component_count`, `component_not_a_number`, `year_not_four_digits`, `month_out_of_range`, `patch_too_large`, `trailing_tokens`. `found` is the component the reason is about, and is empty when the failure names no fragment: `component_count`, and `component_not_a_number` on a value whose component is itself empty (`2026.`). | | `W_FUTURE_CAIRN_VERSION` | `{ "kind": "future_cairn_version", "declared", "compiler" }`. Both verbatim: `declared` is the string in the file, `compiler` is the build that reported it. | | `W_TRUTH_TABLE_PARTIAL` | `{ "kind": "truth_table_partial", "inputs": 2, "covered": 1, "missing": ["01","10","11"] }`. See below. | | The three `@intended_targets` codes | `{ "kind": "intended_targets", "edition", "targets": ["1.20.4"], "floor"? }`. The versions this finding is about, in source order, and the edition that weighed them. `floor` is the first one that refuses them, as written; absent for `W_INTENDED_TARGET_UNSUPPORTED`, which is not about a floor. | **`E_UNKNOWN_ID.origin`** says who chose the ID, because the repair differs: | `origin` | Meaning | Where the fix goes | |---|---|---| | `authored` | The source names the ID. | The author's line. | | `catalog` | The registry pack maps a token onto it. | The pack's mapping. | | `builtin` | The pack declares no row for a member default, so the compiler's own ID was used. | The pack, which has to grow the row. | `token` accompanies `catalog` and `builtin` and is absent for `authored`. `suggestion` is absent when no declared ID is within the typo threshold. A rename is normally past it, but the two fields are filled by independent rules and a renamed ID near its replacement carries both. `aliases` is the other half, and the two are different claims about the same ID. A suggestion is a guess from a string distance; an alias is the registry pack's `aliases` component stating that two names are one block, so a quick-fix may apply an alias unasked and should not apply a suggestion. It holds every ID the target declares for that block, the closed set, never a pick from it, in the pack's own order, and is absent when the pack names none. The rendered note prints the first few and counts the rest; the payload is where the whole set lives. See [Versioning and Editions §10.4](/spec/versioning-editions/#104-fail-loud-and-minimum-version-inference). `E_INCOMPATIBLE_MATERIAL` follows the same idea: `slot` is the `mat_slot=` name the member read and is absent when it carries no binding, and a dotted `token` (`roof.dark_wood`) means the pack's mapping is what to correct rather than the source line. `required` is named rather than implied so that adding a second family later is a new value here, not a new code. `W_TRUTH_TABLE_PARTIAL.missing` is a **sample** rather than the set: twenty inputs have a million combinations. Take the count from `2^inputs - covered`, never from `missing.len()`. `inputs` is carried instead of that total because the grammar puts no ceiling on the input list and no integer holds `2^130`. ## 11.3 Error vs warning - **Errors** are things that, left alone, produce unintended results: concept absence, unknown IDs, out-of-domain states. Silent substitution and implicit dropping are forbidden. - **Warnings** are semantic drift across versions and editions, the non-guarantee of redstone behaviour, and the partial-build degradations the block-array pass reports. In those the compiler rather than the source is the incomplete side. The `E_` / `W_` prefix is not the severity, in either direction. Most `W_` codes mark a partial-build degradation, but some are warnings without being one, among them `W_UNUSED_DEF`, the two truth-table warnings, the two `@cairn` codes, `W_INTENDED_TARGET_CAP`, `W_INTENDED_TARGET_UNSUPPORTED`, `W_THEME_VARIANT_REBOUND`, `W_DUPLICATE_WALKWAY`, and `W_STATE_LITERAL_UNCHECKED`, whose literal is written unchanged; and two `E_`-prefixed codes are decided by the rule above rather than by their name: - `E_UNKNOWN_SLOT_TARGET` is an **error**, because the fault is in the source: the slot is written with a value that is not a material token. Its members degrade as they would with no theme bound, so what is built does not set it apart from `W_NO_THEME_BOUND`. - `E_THEME_SELECTOR_UNMATCHED` is a **warning**, because a rule that matches nothing overrides nothing. `E_PARSE` is one code for every shape a parse fails in (a stray character, an odd indent, an integer past `i64`, a keyword where an item was expected), with the message saying which. A code per shape would make every future one a line of this table, for a distinction nothing branches on; what that costs is that a consumer reads the message to tell them apart. It is also the only code no check pass raises: parsing precedes them all, and a source that does not parse reaches none of them, so it is the one finding a build reports alone. A finding of block-array lowering is reported wherever a source is checked, whether a target is pinned or not. With no `--target`, in a plain `cairn check` and in the language server, which pins nothing, lowering runs with no target and reports the findings every target that reads their line raises, with the code, span and text a pinned check gives them. It weighs the source as if every block id some shipped version of the edition declares were declared. An abstract token, and an id no shipped version declares, are not deferred: each stands in for the block a target's pack names for it, and no verdict on that block is given. So there is no `E_INCOMPATIBLE_MATERIAL` on it, no `W_PHASE_CONFLICT` between it and another block, and no `W_PALETTE_TOO_LARGE` that only it could cause, since the palette is counted without it. A stand-in overwritten by air, or air by a stand-in, is still a `W_PHASE_CONFLICT`, since no pack names air. A `pressure_plate` built from its default block takes the pack's plate, so it is such a block too, and a `W_WALKWAY_BLOCKED` note says "a block" where a pinned check would name it. `E_UNKNOWN_ID` and `E_UNKNOWN_ABSTRACT_TOKEN` are the pack's verdicts and are not raised. Neither is `E_PARTIAL_BUILD`, which counts what a build at a target loses. `--edition` alone picks that edition's theme variants. With neither flag, each edition's variants are lowered: a finding on a line only one edition's variant reads is that edition's verdict and is reported, and any other finding is reported when every edition raises it with the same code at the same span, once for each wording the editions give it. A check with `--target` lowers once, against the target, so no finding is reported twice. `E_MISSING_MATERIAL` is an **error** by the first rule above rather than the second: the member is dropped from the build and nothing is put in its place, which is implicit dropping and not a partial-build degradation. The incomplete side is the source, which named no material, and not the compiler. The drop does not stop at the member either: a dropped `walls` lowers the wall height the volume is derived from, so the structure shrinks and every `door` and `window` that was to be cut into it is deferred as well. `E_DUPLICATE_SELECTOR` is an **error** on the same test, though selector bindings are reserved and neither of the two values it is about is built. Whatever a binding comes to mean, the later row makes the earlier value dead text, and that is a fault in the source: it is there today and stays there once bindings are lowered. Every member the earlier row selects is selected by the later row too, so no edit to the members brings the earlier value back, where adding a member revives a row `E_THEME_SELECTOR_UNMATCHED` reports. The compiler's gap is the reservation itself, which each binding's `W_IGNORED_ARGUMENT` already reports. The code also gives two rows the verdict `E_DUPLICATE_ARG` gives one. The same key written twice inside one row is refused, and rows that select the same members are one binding list split over two lines ([Materials and Themes §7.1](/spec/materials-themes/#71-slots-as-dependency-injection)), so where the line breaks does not decide whether the build is refused. The two `@cairn` codes are **warnings** by the same rule read the other way. The header is provenance: no pass branches on it, no palette entry comes from it, and the lockfile's `cairn_version` records the compiler rather than the file. `@cairn banana` builds byte-for-byte what `@cairn 2026.06` builds, so nothing about the result is unintended. What is lost is the header's own job, being readable by a later compiler, which is worth a word and not worth refusing the file over. `@requires` is an error on the same test because its floor *is* an input: it sets `cairn info`'s compatible range and the bound `cairn compile --target` is held to, so a floor that evaporates accepts a target it should not. `E_UNKNOWN_ARGUMENT` is an **error** for the same reason `E_UNKNOWN_KEYWORD` is, one level down. A key outside the keyword's vocabulary names nothing, so no pass will read the value however the compiler grows, and the member is built without whatever was being asked for. A misspelled argument that has a default is the worst of them: the build succeeds, at the default, and says nothing. Each keyword's vocabulary is closed, and a `theme` selector widens the one it names: writing `window[tags=...]` in a theme makes `tags=` a key something reads on a window, and on nothing else. The reverse direction is `E_THEME_SELECTOR_UNMATCHED`. A selector coins words; one edit away from a word the keyword already has is a typo written twice rather than a coinage, and is refused with the suggestion. Widening admits the word and nothing more: the match hands the member the row's bindings, which are reserved ([Materials and Themes](/spec/materials-themes/)), so a key the keyword defines and no pass reads is still an unreached key when a selector matches on it. A member's own `[key=value]` answers to that same vocabulary. `window[clas=outer]` is the same defect as `window clas=outer`: a word the author expects something to read that nothing does, with the `class` lost either way. It earns the same code and the same suggestion. What the selector *means* is a separate question and is not settled here: a member's selector is carried through verbatim and later passes decide whether one binds a fresh id or references an existing member. This check does not need that answer, because the word is one something reads or it is not, whichever the answer turns out to be. Note that a key in a member's own bracket does not make the member *carry* the attribute, so a `theme` row selecting on it matches nothing. A `struct` / `def` header line answers to a closed vocabulary of its own, the one [Components, Editing, and Multi-building](/spec/components-editing-sites/) states: `size=`, which lowering reads, and `class=`, which no pass reads yet. No `theme` selector widens it, since a selector names a member keyword. A key outside the two is the same defect one line up from a member's, and is refused with the suggestion: `struct s siz=7x7` is offered `size`. The missing-size warning the same typo causes cannot name it, since it says only that the struct has no size. The error is printed before the warning. `W_IGNORED_ARGUMENT` is a **warning**, and covers three things. An **unreadable value**: a `key=` in the vocabulary whose value the pass cannot read is dropped and a default put in its place, or, where the key itself decides whether the member is built at all, the member is left out instead under `W_DEFERRED_MEMBER` (`sym=` on a `window` whose `repeat=` is greater than 1 is that key today, [§5.4](/spec/syntax/#54-selectors)). An **unread key**: a `key=` the keyword accepts and nothing reads where it is written, carried into the IR and never consulted. It comes in two kinds. An *unreached* key is one this specification defines that no pass reads yet. `window shape=` / `anchor=`, `roof footprint=` / `bounds=`, a header's `class=`, a `door`'s `mat_slot=`, which waits on the door block itself, and a `stair`'s `waterlogged=` are those keys today. Every `key=value` on the right of a `theme` selector row whose keyword the compiler knows is one too, reported on the binding whatever its key or value, since no pass lowers a selector's bindings yet ([Materials and Themes](/spec/materials-themes/)). An *inapplicable* key is one every member accepts, on a keyword that puts down nothing it would be read for; `mat_slot=` on a `level`, `circuit`, `place` or `connect` is that key today. A `mat_slot=` of either kind is not looked up in the theme, so a slot name the theme does not declare is this warning rather than `E_UNRESOLVED_SLOT`, and a misspelt one is not caught. And a key **routed past**: one the keyword reads only under some ways of writing a sibling argument, on a member that writes it another way. The boundary is the keyword: a spec-defined key on a keyword the compiler knows is reported this way, while a spec-defined *keyword* it does not know is `E_UNKNOWN_KEYWORD` and its arguments are not judged at all. All three make the build differ from the source. The rule forbids *silent* substitution, and all three are announced. For an unreached key the gap is the compiler's rather than the source's, which is why it is not a refusal. An inapplicable key is no gap at all: the key is one every member accepts and its value changes nothing in the build, so the warning asks for its removal, where a refusal would make a key every member accepts one that some refuse. Whether autofix is offered is up to the implementation. An unreadable value is reported whether or not its member is then built. The value is wrong wherever the member ends up, so it is a repair of its own, and holding the finding back until a refusal on the same line is repaired only costs the author another compile. The note says which of three things happened: what the default did to a member that is built; that the member is not built either way, and the refusal beside it is why; or that the member is left out instead of taking the default, and the deferral beside it is the one the value caused. A member dropped before its arguments are read is the exception today: a `roof` under a raised `level` has only its `kind=` and `slope_to=` read, for its refusal, so its other values are not reported beside the drop. Most values are read only during block-array lowering, and an unreadable one needs no target, so a `cairn check` with no `--target` and the language server report it as a pinned check does. The routed-past shape is the vocabulary's second axis: closed per keyword *and* per the way the argument that selects the lowering rule is written. `roof slope_to=` is read by the `kind=shed` rule and by none of the others, so ``` roof kind=gable slope_to=front ``` builds a roof that ignores the direction it was pointed in: the same silent drop a key outside the vocabulary makes, one argument down. It stays a warning rather than becoming the refusal `E_UNKNOWN_ARGUMENT` is, because the repair is not decided: the key names something real on a keyword that reads it, and either the `kind=` is the argument that was meant or the `slope_to=` is left over. The message names both sites and picks neither. An arm of that axis can also be the selector's *absence*, where that is itself a rule rather than a mistake. `place gap=` is the case: a row with no `at=` is placed relative to another and reads the distance, and `at=origin` is anchored absolutely and does not, so `at=origin gap=5` is the same silent drop ([§9.3.2](/spec/components-editing-sites/#932-origin-selectors)). Where the **selector** names no rule at all (a value the dispatch does not know, or nothing written on an axis with no absent arm), no finding is raised here: that member lowers to nothing and its refusal is the whole repair, so a second finding about the argument that rule would not have read bills one repair twice. That refusal is `E_INVALID_MEMBER`, or `E_INVALID_PLACE_ORIGIN` for a `place`'s `at=`, and needs no target either, so a `cairn check` with no `--target` reports it as a pinned check does. A key another key makes inert *without* selecting a rule is a different shape again and is not reported today: `window step=` at `repeat=1` is a condition on a count rather than on a rule. `E_MISPLACED_BINDING` is the fourth field of a member line asked the same question the other three are: is this word read by anything. A `-> value` tail is read by exactly one thing, the sensor set of [§14.2](/spec/redstone/#142-signal-binding), so a tail on a member that is not a sensor is carried into the IR and dropped, and the signal it names is emitted by nothing. It is an **error** on the same test `E_UNKNOWN_ARGUMENT` meets: the build differs from the source, and no edit to the value repairs it. Only the host is asked here, because only the host can be asked without the Logic IR. Whether the tail's value names a signal, and whether that signal is driven twice or by nobody, are questions the redstone pipeline answers ([§14.2](/spec/redstone/#142-signal-binding)). The host is asked first, so a tail on a member that cannot emit earns this code and not also the value's. A member whose keyword is not in the known-keyword table is left to `E_UNKNOWN_KEYWORD`, which is why `lever -> sig.a`, a sensor this specification lists and the surface has not reached, is not told its host is wrong. ## 11.4 Constraint catalog In-game constraints are cataloged and managed per version: gravity blocks, attachment conditions, fluid flow, and disallowed attachment combinations ([Versioning and Editions](/spec/versioning-editions/)). "A frame cannot hang on glass" lives there. # 12. Ecosystem Interop and Reverse Conversion ## 12.1 Forward direction Serializing the block-array IR emits `.nbt`, `.litematic`, `.schem`, and `.mcstructure` ([Architecture](/spec/architecture/)). Each format is a serializer, and an existing format is one more backend around the pivot. Only the `.nbt` and `.mcstructure` serializers exist today: `cairn compile` writes `.nbt` for Java and `.mcstructure` for Bedrock. ## 12.2 Reverse direction: the compiler transliterates, an LLM lifts The compiler does not look at voxels and decide "this is a wall": that kind of computer vision becomes unmaintainable. What it implements is robust, faithful transliteration, verification, and a voxel diff. Lifting the result to meaning is an LLM's job, done as a refactor of the raw-centric DSL. That dogfoods the language and matches P5's self-correction loop. ```text cairn import house.litematic --mode raw → house.raw.crn # fill/raw_block centric (an LLM refactors house.raw.crn into a semantic DSL) → house.lifted.crn cairn compile house.lifted.crn --edition java --target 1.21.4 cairn diff-blocks house.litematic house.lifted.crn # voxel XOR → into self-correction ``` The reverse direction is not implemented yet. Neither `cairn import` nor `cairn diff-blocks` exists, so nothing in this section or the two after it runs today. The compile → diff → patch loop reports like this: ```text E_DECOMPILE_DIFF: block IoU = 0.962 < threshold 0.985 missing bbox=(12,4,3)..(18,6,3) mat=glass_pane → likely window repeat too small Suggested patch: edit window[id=front_windows] set repeat=4 ``` `E_DECOMPILE_DIFF` is not implemented, and the `edit` statement its patch suggests does not parse yet ([§9.2](/spec/components-editing-sites/#92-editing-model)). Convergence thresholds are block IoU ≥ 0.985, `state_accuracy` ≥ 0.995, and residual raw ≤ 5%. An exact match is not required, and the residue stays explicit as `raw_fill id=residual_* origin=imported`. ## 12.3 Three tiers of transliteration Naming is the boundary between transliteration and lift. | Tier | What it is | Ceiling | |---|---|---| | **L0, raw cells** | One voxel per line. Too large for LLM context, so it is an intermediate only. | — | | **L1, spatially compressed** | Fill aggregation, AABB palette compression, `resolved_state` → `intent_state` inversion (`stair facing=east half=top`), symmetry and period folded into `raw_repeat`. **No naming.** | The compiler's ceiling. | | **L2, semantically lifted** | fill → `wall`, repeat → `def` / `use`, concrete block → `mat_slot` + `theme`. | The LLM's ceiling. | ``` # L1: no naming, deterministic raw_repeat id=r03 count=5 step=3,0,0: raw_fill mat=@glass_pane from=0,2,0 to=1,3,0 # L2: the LLM names it and gives it meaning window id=front_windows side=front mat_slot=glass repeat=5 ... ``` ## 12.4 Import stamping and pitfalls On import, the `(edition, version)` pair and provenance are stamped onto the block-array IR (`.litematic` → java, `.mcstructure` → bedrock, `.schem` → java). This is what makes an import reproducible ([Versioning and Editions](/spec/versioning-editions/)). **Never present import as "recovering author intent."** That is the biggest pitfall. Only voxels and some regularity can be recovered, and the CLI says so with `W_SEMANTIC_LOSS`. With no import yet, nothing is stamped and `W_SEMANTIC_LOSS` is not implemented. Other rules: - Import-origin `raw_fill` is isolated with `origin=imported` / `residual` and is not treated as first-class design DSL. - Litematica's multiple regions and sub-region offsets are preserved as provenance rather than flattened, and regions map to a `site` or several structs. - For entity-bearing schematics, do not mark success on block IoU alone. Keep a separate entity metric and extract only first-class entities ([Entities](/spec/entities/)). Chest contents and command blocks are dropped. - Huge schematics (over 48³, or whole villages) do not fit in an LLM's context if lifted at once. They need chunk split → per-chunk L1 → per-part lift → join with `site`, run over a streaming parse. - Legacy numeric-ID `.schematic` files from before 1.13 flattening are not supported in v1 ([Purpose and Scope](/spec/overview/)). # 13. Evaluation Framework The spec improves by measurement, not taste, using a headless geometry simulator that does not depend on Minecraft itself. Vocabulary and syntax debates drift into preference, so the evaluation bench comes first. ```text test prompt set (~50) → zero-shot generation → headless lint (syntax + AABB geometry: "window outside wall", "door hanging", …) → return line-numbered errors and self-correct for up to 3 turns ``` This chapter is the methodology the project is to follow, and none of it is automated in the repository yet: there is no prompt set, harness, metric or geometry simulator. Of the loop above, only the lint step exists, as `cairn check`. ## 13.1 Primary metrics | Metric | What it measures | |---|---| | **Zero-shot compile rate** | The fraction that compiles error-free on the first try. Measures how intuitive the spec is. | | **Fix convergence rate** | The fraction that converges to error-free within 3 turns. Measures how expressive the error messages are. | | **Token efficiency** | Expanded block count ÷ DSL token count. | | **Edit stability** | How small the AST and NBT diffs are after a follow-up edit such as "make only the second-floor windows arched". | ## 13.2 Reverse-conversion auxiliary metrics Reverse-conversion quality ([Ecosystem Interop](/spec/ecosystem-interop/)) is kept out of the primary evaluation and treated as auxiliary, consistent with the lossy approach. What it measures is not "did it reproduce the shape" but **"did it become editable DSL"**. - `block_iou`, `state_accuracy` (facing / shape / waterlogged match), `entity_accuracy` (frame, sign, villager, display retention). - `residual_ratio`: raw volume left after the lift. `compression_ratio`: voxel count ÷ token count. - `editability_score`: named-member count, slot-ization rate, stable-address rate. - `theme_extraction_score`: whether concrete blocks were separated into slot and theme rather than inlined. - `symmetry_score`: the fraction folded into `repeat` / `mirror` / `def`. `version_portability`: canonical-token rate. ## 13.3 Operating rule A vocabulary addition or syntax change is adopted only if it improves these metrics, especially fix convergence rate and edit stability. One experiment settles most syntax and vocabulary questions on real data: give the model only the spec, have it generate, and see where the errors are. The reverse-conversion harness doubles as an engine that grows the `def` and `theme` standard library from a community schematic corpus: ```text corpus → import → normalize(edition/version) → L1 compact → cluster(shape/material) → LLM lift candidates → compile/diff → human review → def/theme library ``` ## 13.4 Redstone verification The headless geometry simulator extends to a per-tick redstone logic simulator. It simulates the synthesized circuit per target edition and checks it against the declared truth-table, latency and temporal assertions, in a synth → sim → diff → patch loop. Neither simulator exists yet, and of the three assertion kinds only truth tables and temporal assertions are parsed today. See [Redstone](/spec/redstone/#147-verification). # 14. Redstone (logic circuits) Cairn describes redstone at the **logic level**. You declare a signal graph; the compiler synthesizes, places, and routes the actual dust, repeaters, torches, and comparators into voxels. This is where P1 pays off most. Signal attenuation, crosstalk, and delay calculation are physics an AI handles even worse than voxel building, and all three are derived deterministically from the logic description. The first-class object of the logic layer is the **signal dependency graph**, not behaviour. Time is not carried in the language core ([§14.4](#144-time-model)). ## 14.1 Two tiers, and the v1 boundary - **Tier 0, physical placement.** You write `repeater facing=north delay=2` and the like, placing parts yourself while the compiler derives the blockstate. Behaviour is not modeled ([Blockstate Model](/spec/blockstate/)). None of these parts is a keyword yet, so such a line is `E_UNKNOWN_KEYWORD` today. - **Tier 1, logic.** This chapter. You declare a signal graph and the compiler turns it into voxels through synthesis → placement → routing. The only new keywords are `logic`, `circuit`, and `assert`. Logic primitives are not keywords: they ship as a built-in library, which keeps the vocabulary small and closed (P3). In Verilog terms, v1 allows the `assign` equivalent and no clocked assignment: | | Scope | |---|---| | **Combinational** | `and` / `or` / `not` / `xor` / `nand` / `nor` / `mux` | | **Curated sequential macros** | `latch` / `pulse` / `delay` / `edge_rising` / `edge_falling` / `counter` | | **Out of scope** (→ Tier 0 or `raw`) | `always` / `process` / `state` / `case` / FSMs / clocked assignment / CPUs | **The built-in logic library.** Each entry is a primitive's name and its notation. A prefix primitive stands before its one operand. An infix primitive stands between its two, and its rank says how tightly it binds: a higher rank groups first, and one rank groups left to right. The parser takes an expression's shape from the library, so a prefix or infix primitive the library gains needs no new syntax. The library holds three primitives today: | Primitive | Notation | |---|---| | `or` | infix, rank 0 | | `and` | infix, rank 1 | | `not` | prefix | A prefix primitive binds tighter than any infix one, so `sig.a or sig.b and not sig.c` reads as `sig.a or (sig.b and (not sig.c))`. Parentheses group as written. The other primitives and macros above are not in the library yet. Written before an operand or between two, or called, each is `E_PARSE`, and the message names the primitives that could stand there: `sig.a xor sig.b` stops at `xor`, and a macro call such as `pulse(sig.ring, 4)` at its `(`. ## 14.2 Signal binding Sensors emit signals and actuators consume them. Both are physical members ([Components, Editing, and Multi-building](/spec/components-editing-sites/)) placed in earlier phases. ``` # sensor → signal lever id=sw side=front offset=2 y=1 -> sig.power button id=bt side=front -> sig.ring daylight id=dl at=.. -> sig.day observer id=ob at=.. facing=down -> sig.tick pressure_plate id=pp at=front.outside offset=0 y=0 -> sig.step # actuator ← signal lamp id=l1 at=.. lit_by=sig.lamps piston id=p1 at=.. powered_by=sig.mem facing=up sticky=true door id=d1 .. opened_by=sig.power dispenser id=ds at=.. fired_by=sig.pulse facing=south ``` That pairing is normative. A `-> sig.X` tail belongs to a sensor, and each actuator key belongs to the one component that reads it. A binding written anywhere else describes no circuit, and accepting it would put a port in the netlist with no component behind it. Which code says so is decided by what the finding needs in order to be made. A `->` tail on a member that is not a sensor is `E_MISPLACED_BINDING`: whether a keyword may emit is a fact about the member line, so `check` answers it and every command reports it. An actuator key on a component that does not read it is a fact about the member line too, since the key is outside that member's vocabulary: `walls opened_by=sig.power` is `E_UNKNOWN_ARGUMENT` ([Lint](/spec/lint/#syntax-and-structure)), which `check` reports and every command stops on, with a note naming the component the key belongs to. The synth pipeline's `E_LOGIC_MISPLACED_BINDING`, which names that component too, is reached only where a `theme` selector has made the key one that member reads ([Lint](/spec/lint/#113-error-vs-warning)). Of the components above, only `door` and `pressure_plate` are accepted today. `lit_by=`, `powered_by=`, and `fired_by=` have no host yet and are refused wherever they are written. **Where an `at=.outside` plate may sit.** The plate takes the wall cell at `offset=` and sits one voxel outward from it, in the ring a roof's `overhang=` adds around the walls ([Compilation Model §4.3](/spec/compilation/#43-gable-roof-voxel-rules)). That ring is the only exterior a struct has, so where no roof draws an overhang the plate has no cell at any row, the floor row `y = 0` included. It is not placed on the wall's own column instead, where the wall above would bury it and its signal could never fire. **Where an `at=inside.` plate may sit.** The plate takes the wall cell at `offset=` and sits one voxel inward from it, and that voxel must be strictly inside the wall ring: the footprint's outermost row and column, where `walls` paint their courses. So `offset` runs from 1 to the wall's length minus 2 (the length is `size.w` for `front` and `back`, `size.h` for `left` and `right`), and a struct needs a `size` of at least 3 on both axes to have an interior at all. The ring is decided from the footprint whether or not a `walls` member paints it, and the rule holds at every `y`, including the floor row `y = 0`. A plate outside it is not placed. **A plate that cannot be placed.** A plate whose own line puts it on no voxel is `E_INVALID_MEMBER`, and the build stops. Its line does that with no `at=` or one other than `.outside` or `inside.`, an `offset=` or `y=` that is not a non-negative integer, an `offset=` at or past its wall's length, a row above every row the struct as written reaches ([Compilation Model §4.7](/spec/compilation/#47-level-grouping-and-volume-derivation)), an `at=.outside` on a struct where no roof has an `overhang=` of at least 1, or an `at=inside.` outside the interior. A plate the struct would have held had another member built is `W_DEFERRED_MEMBER` instead, because the repair is on that member: a row that `walls` painting nothing, a `roof` drawing nothing or `walls` under a `level` that is not placed would have reached, or an `at=.outside` beside a `roof` with an `overhang=` that draws nothing ([Lint](/spec/lint/#lowering)). The plate's own line is judged first, so a line that puts it nowhere is the error even when such a member is missing too. Either way the plate's `->` binding is still read, since synthesis reads the member line and not the voxels, so the signal stays in the netlist with no plate to drive it, and the finding says so. **Signal names.** Sensors emit into the `sig.` namespace and actuators read from it, so a name outside it can never be read, whether on the left of a `logic` line, in a sensor's `->` tail, or as an actuator key's value. That is `E_LOGIC_INVALID_SIGNAL`. A name is `sig.` and exactly one segment after it: `opened_by=a` is not a wire to a signal called `a`, and `opened_by=sig.a.b` names nothing either. The host is checked before the value, so `walls -> a` is one fault and it belongs to the host: the `E_MISPLACED_BINDING` above, and not also the `E_LOGIC_INVALID_SIGNAL` the value would earn on a sensor. No way of writing the value makes `walls` a sensor. **Bindings go after the `[selector]`, never inside it.** `door[id=front] opened_by=sig.power` binds; `door[id=front,opened_by=sig.power]` does not. The brackets pick the member the line acts on, so nothing written among them is read as a binding. A bracketed pair earns the finding its key would earn once moved out: `E_UNKNOWN_ARGUMENT` for a key outside the member's vocabulary, and `E_LOGIC_UNKNOWN_BINDING_KEY`, below, for a `sig.` value under a key the member reads that is not an actuator key. A component's own actuator key inside its brackets is `E_LOGIC_MISPLACED_BINDING`, which names the brackets, whatever the value. **A selector line binds the member its brackets pick.** `door[id=front] opened_by=sig.power` binds the door declared as `door id=front ...` in the same scope, at the top level or directly under a `level`. The `id=` has to name exactly one such door, written without brackets. The patch is a line of its own, before or after the door it binds, at the top level or directly under a `level`, wherever that door is. A patch whose selector has no `id=`, or whose id no door carries or two doors carry, is `E_LOGIC_UNRESOLVED_PATCH`: it acts on no door, so a port for it would have no component behind it. The door patch is the only binding a selector line carries, so a `->` tail on `pressure_plate[id=p]` is `E_MISPLACED_BINDING`, as it is on a member that is not a sensor. **An actuator takes one binding per key.** A door carries one `opened_by=`, whether it is written on the door's own line, through a patch, or on both. A second is `E_LOGIC_DUPLICATE_BINDING`: two bindings would be two wires into one door, a wired OR the logic layer never states. Signals are combined there instead: write `logic sig.open = sig.a or sig.x` and bind the door to `sig.open`. A `sig.` value under a key the member reads that is not one of the four actuator keys is `E_LOGIC_UNKNOWN_BINDING_KEY`, raised by the synth pipeline, as in `walls height=sig.power`. The value says a signal was meant to be wired and the key is not one any component reads a signal from. A misspelt actuator key such as `oepend_by=sig.power` is outside the member's vocabulary, so it is the `E_UNKNOWN_ARGUMENT` that `check` reports first. ## 14.3 The logic layer is a dependency DAG You write dependencies among signals: boolean combination plus macro application. It is a pure, time-free dataflow that becomes a Logic IR inside the compiler. ``` logic sig.lamps = sig.power and not sig.day logic sig.mem = latch(set=sig.a, reset=sig.b) # RS latch (macro) logic sig.pulse = pulse(sig.ring, 4) # monostable: 4 stages logic sig.fire = edge_rising(sig.tick) logic sig.sel = mux(sel=sig.s, a=sig.x, b=sig.y) ``` The expression contains no time arithmetic. The `4` in `pulse(sig.ring, 4)` is a **stage count**, not a tick value. Of these lines only the first parses today; the macro calls are `E_PARSE` ([§14.1](#141-two-tiers-and-the-v1-boundary)). ## 14.4 Time model In v1 only the macros carry time: `delay`, `pulse`, `edge_rising`, `edge_falling`, `latch`, and `counter`. `delay(3)` is a cell macro that lowers to three repeaters internally; no macro is parsed yet ([§14.1](#141-two-tiers-and-the-v1-boundary)). There is no tick operator to write. **Delay is carried in neither the Logic IR nor the Netlist IR. It is determined for the first time in the Placement IR** ([§14.8](#148-connection-to-the-ir-and-phases)). `and` is logically zero-delay, but the tick count is known only after cell selection (`and → ComparatorAND` on Java) and the actual post-placement wire length. A cell takes each operand on an input port of its own: `a` and `b` on a two-input cell, `a` on `not`, and on `mux` the `sel`, `a` and `b` its arguments name. A cell's delay is counted per input port, as the ticks from that port to the cell's output, since one input can pass through more of a cell than another. A signal's delay through a cell is the delay of the port it enters by. A number appears as ticks only in verification assertions ([§14.7](#147-verification)). You never do tick arithmetic inside a logic expression. ## 14.5 Place-and-route The DSL shows you a 2D mental model. A purely 2D floorplan gets stuck, so the internal implementation is pseudo-2.5D, holding `plane` / `via` / `bridge` concepts that the DSL never exposes. Circuit classes a pure 2D model cannot handle: fanout, bus, crossing, comparator feedback, observer chain. ``` circuit region=basement void=3 # reserve a 3-high service layer; route the circuit here ``` A `struct` or `def` has one such line: a second one in the same body is `E_DUPLICATE_CIRCUIT` ([Lint §11.1](/spec/lint/#111-diagnostic-codes)). Logic that needs more than one reservation goes in more than one scope. The line stands among the body's own members: a reservation spans the scope's `size=WxH` and takes no `level`'s `y=`, so place-and-route reads no `circuit` line under a `level`. Such a line is `E_MISPLACED_MEMBER` on that line, not `E_DUPLICATE_CIRCUIT`. The internal algorithm runs five stages: 1. **Placement.** Topological order, left to right, one clear column between each pair of cells. The row starts in the column after the input pads and ends at the latest in the column before the actuator pads, so a row of `n` cells needs `2n + 1` columns. That last column is the actuator pads' own: at `2n` the last cell would stand in it, face to face with the pads at `z = 0` and `z = 2`. Neither pad column carries a pad on the cell row, so an end cell that stands beside a pad column keeps the coordinate beside it there as a free neighbour. A cell body is a block, so a net reaches it through a neighbouring coordinate; a two-input gate has three distinct nets touching it (its two drivers and its own output) and therefore needs three free neighbours. Packed against each other the cells in the middle of a row have two, at any region size, so a row spaced like this is what makes a short-free wiring possible at all. The row also stands one row in from the near edge of the region. In a scope with cells the I/O pads step along `z` from `0`, skipping the cell row; a scope with no cells has no cell row, and its pads take every row from `0`. A pad on the cell row would stand face to face with the end cell whenever the row reaches its column, so the terminal of a net that cell may have nothing to do with would take one of its faces. With the pads off that row and the row ending before the actuator-pad column, no pad touches a cell at any width the row check accepts. Dust reads the dust in the coordinate beside it, so a lane of free coordinates carries one net however long it is; a cell against the edge has one lane, and the three nets touching a two-input gate cannot share it. One row in gives every cell a lane on each side. That costs one row for the whole netlist rather than one per cell, so unlike the column spacing it does not grow with the cell count. Neither spacing is a guarantee of a wiring: a net passing through can still take the last free face, and that scope is refused rather than shorted. Three kinds of region are refused here rather than left to fail as an unreachable sink at stage 2: one that cannot hold the row (`2n + 1` columns for `n` cells, and three rows); one that cannot hold the rows its pads stand in (a row per sensor or actuator on the busier edge, and, in a scope with cells, one more for the cell row once that edge carries two); and, in a scope with both sensors and actuators, one without two columns for its two pad columns, which at one column are the same column. 2. **Steiner routing.** Manhattan, around what is already standing and around the dust of the nets already laid. Cell bodies and I/O pads are reserved: dust cannot be drawn on one, and a signal cannot pass *through* one, since a component either emits or consumes. Every sink is therefore a leaf of its net's tree, and a fanout is a trunk beside the row with a tap into each sink rather than a chain through them. Where nothing is in the way the wire is a straight rectilinear run; otherwise it goes around, or climbs to a `bridge` layer inside the `void=` budget. Two nets on one coordinate would be one strand of dust carrying two signals, and so would two nets one coordinate apart in the same plane, because dust joins the dust next to it. So the nets are laid one at a time, and each goes round the dust already laid *and* the coordinates beside it. That is the crossing escape, and it happens here rather than at stage 4 so the climb is measured: `wire_length` and the delay pass's tick count are both read off the routed tree. The order is fanout descending, then the net's own key. That is a total order, so one layout has one answer however many passes ask for it. Beside is per-plane. Whether two strands a layer apart read each other depends on what is standing between them, which this model does not carry: the internal model is pseudo-2.5D and the voxel realisation belongs to the physical tile layer. Separating two strands within one step of each other across layers is that layer's obligation rather than the router's. That covers both the stacked pair and the diagonal one, which is a staircase and is the more numerous of the two, because a coordinate has one coordinate directly under it and four diagonally under it, and a run that climbed to clear a lane then travels alongside that lane, one step across from it, for as long as the two run parallel. The tile tier carries the obligation as a requirement on what a `bridge` coordinate may render as ([§14.6](#146-edition-differences)). Named, not inferred. A scope whose escape leaves two *strands* within one step of each other across layers earns `W_ROUTE_CROSS_LAYER_CLEARANCE`, which lists the coordinates and the nets, so those pairs are readable from the layout rather than derived from it. It is advisory and elides nothing: the layout is not at fault, and a rule the router invented here would refuse layouts for a reason nothing in its model can check. Nor is there a remedy to offer. Enlarging the region does not remove the pairs: where a net has to climb at its own doorstep, because the lanes either side of its cell are taken, more room only lengthens the run it then makes on the upper layer. ```text W_ROUTE_CROSS_LAYER_CLEARANCE line 45 circuit=floor: routed netlist for struct `crossbar` leaves 12 pairs of dust within one step of each other across layers (2 stacked, 10 staircase) — … note: (4,1,1) on cell #0 stands directly over (4,0,1) on cell #1 note: (5,1,1) on cell #0 stands directly over (5,0,1) on cell #1 note: (1,1,1) on cell #0 stands a layer over, and one step across from, (1,0,0) on sig.a note: (1,1,1) on cell #0 stands a layer over, and one step across from, (1,0,2) on sig.b note: and 8 more of the same two shapes … Fix: nothing in the source is wrong — the pairs are what the escape costs, and enlarging the region is not a remedy: … ``` The segment cap is tested here too, before any wire is laid. The Manhattan distance between a driver and its sink is a lower bound on every route between them, so a sink already past the cap in a straight line is past it however the router goes, and that scope earns `E_ATTENUATION_LIMIT` at this stage rather than at stage 3. A floor and not the measure: it refuses strictly less than stage 3 does and replaces nothing. A region 256 wide puts its pad 255 blocks from the driver and may route 257 to get there, which is over the cap and not over this. The fix line differs from stage 3's for the same reason: nothing shortens a straight line, so enlarging the region is not the remedy here. The router's search is bounded by the same cap. A path from a net's wire to a sink is part of that sink's segment, so the search does not look past the cap. Each sink it cannot reach is then judged on its own. It earns `E_ROUTE_CONGESTION`, below, when the router can prove it walled in: none of its faces can be arrived through, or the search ran out of coordinates before the cap cut any off, or the free coordinates the sink opens onto all lie within the cap of it and the net's wire is not among them. Otherwise it earns `E_ATTENUATION_LIMIT` here, which says only that no route within the cap exists. A sink walled off in a free region wider than the cap is one of these. When a scope has sinks of both kinds, the message is about a walled-in one. The bound is what keeps giving up on a sink proportional to the cap rather than to the reservation: without it, the search visited every free coordinate the net could reach before it refused. 3. **Delay insertion.** A repeater goes in as a buffer only where a segment carries more dust than the attenuation limit of 15 blocks: a source at strength 15 carries 15 blocks of dust, the last at strength 1, which still drives the sink after it. The segment is measured along the **routed** path from driver to sink, and the buffer stands on that path, so the straight line between the two is not always wire. A segment past the v1 cap of 256 steps is refused rather than buffered, under the same `E_ATTENUATION_LIMIT` stage 2 raises; what differs is that this pass measures the wire that was actually laid. The figure the pass records per cell is a local cost, the delay of its slowest driven port plus the buffer repeaters on the nets feeding it, not a signal's latency. A repeater reads the block behind it and drives the one in front of it, at its own height, so it stands only where the wire runs straight through a coordinate at one height and nothing branches off there, nor where any block of its net other than the two it joins (dust the route reaches some other way, or one of the net's cells or pads) is on any of its six faces, which a repeater there would cut off. On a straight run from a fresh source it stands in place of every 16th block, with 15 blocks of dust behind it. Where that coordinate turns, climbs or forks, the repeater stands on the last coordinate before it that runs straight, which can leave a route one repeater more than its length alone implies. When the coordinate it steps back from is a fork, the one it lands on is on the trunk, so one block serves every branch past it; a fork further back than that gets a repeater on each branch. Repeaters are placed on each net's routed tree rather than per sink, and a sink is charged for the ones on its route. A stretch of dust past the limit with no coordinate a repeater can stand on is refused with `E_ATTENUATION_LIMIT`. The limit is counted from the last component that restores strength (a sensor pad, a repeater, a torch), not from the start of each segment. Two of the cells pass on the strength they receive instead: the Bedrock OR is a dust merge, and the Java comparator AND, a comparator with one operand inverted onto its side ([§14.6](#146-edition-differences)), outputs the strength its rear input carries while it is on. The wire into either cell on an input it passes on (both of the merge's, and the comparator's rear) and the wire out of it count as one run of dust, though the cell stands between them, measured from whichever of those inputs has spent the most. While the cell is on, its output is never weaker than that input: the merge passes on its strongest lit input and the comparator its rear. The wire into the comparator's side, port `b`, ends at the inverter, which restores strength, so it is held to the limit as the wire into any sink that restores strength is, and the dust spent on it does not count on the wire out. A net on both ports feeds the rear as well, so it stays in the run. The repeater the run needs goes where the running total would pass 15, or, on a wire of the run into such a cell, what the cell can spare of it, since the wire out needs the rest. Where that is a block of dust, the repeater stands in its place and reads the dust before it, as on a straight run. Where it is a sink, as such a cell is, the repeater cannot stand in its place and stands on the wire before it. It lands on the wire out of the cell, or on the wire into it when the wire out has no coordinate near enough to the cell to take one. 4. **Crossing legalization.** Assigns the coordinate of every buffer repeater stage 3 counted. The wire needs no legalizing by this point: a repeater stands on its own net's routed path, that path belongs to that net alone, and no other net runs within a step of it, so there is no short to lift and no coordinate to contest. It applies the straight-line cap as well, since it lays nets of its own and a scope can reach it from a netlist an earlier stage handed over, and for the same reason it refuses a stretch of dust with nowhere for a repeater as stage 3 does. 5. **Edition legalization.** See [§14.6](#146-edition-differences). This stage is not implemented yet. Routing is confined to the `circuit` region. If it does not fit, the compiler fails loud. A sink whose every way out is walled in, by a component, by an earlier net's dust or the coordinates beside it, or by the edge of the reservation, earns the same refusal for a different reason, and the message says which two coordinates it could not join and which nets took the faces. ```text E_ROUTE_CONGESTION line 21 circuit=basement: synthesized netlist needs ~3.2x the reserved area (void=3, region 9x7). Fix: increase `void`, enlarge region, or split the logic across several scopes, each with its own `circuit` line. ``` `E_ATTENUATION_LIMIT` is the other refusal these passes raise, for four shapes. Stages 2, 3 and 4 all lay nets through one shared step, which tests the straight line between a driver and its sink against the cap before any route is laid, and refuses a sink no route within the cap reaches once the router has searched for one. Stage 3 also measures each routed segment against the cap. Stages 3 and 4 both refuse a stretch of dust past the limit of 15 on which no coordinate can hold a repeater: each works out where the repeaters stand from the same routed tree, by the same rule, so the two agree on which stretch that is and the message names the node that goes dark. Which stage refuses a scope depends only on which one reached it first. The primary names the netlist that pass read (`placed` at stage 2, `routed` at stage 3, `delayed` at stage 4), so the message says where in the pipeline the shape was measured. ```text E_ATTENUATION_LIMIT line 13 circuit=floor: placed netlist for struct `wide_pack` puts output pad #0 299 steps from its driver in a straight line — exceeds the v1 attenuation limit of 256 steps, and no route between two coords is shorter than the straight line between them. Fix: split the logic across several scopes, each with its own `circuit` line, or reserve a `region=` whose pad column sits within the cap of the cells it serves — a larger reservation cannot help, because the straight line between these two is already over the cap. ``` ## 14.6 Edition differences A three-tier cell library confines the edition difference to the library alone: ``` Logical Cell → Edition Cell → Physical Tile AND → Java: ComparatorAND → block array → Bedrock: TorchAND → block array ``` The Java `ComparatorAND` is a comparator in subtract mode with one operand inverted onto its side at full strength. While that operand is on, the side reads 0 and the comparator outputs the strength its rear input carries; while it is off, the side reads 15 and the output is 0 whatever the rear carries. Both operands reach the cell as the netlist carries them, so the inversion is the cell's own, and subtract mode is the one that then computes AND: while the side reads 15, compare mode would still pass a rear input at 15 through. The `ComparatorAND` takes port `a` at its rear and inverts `b` onto its side. Counted per port ([§14.4](#144-time-model)), a signal entering by `a` passes the comparator alone, 1 tick, and one entering by `b` passes the inverter and then the comparator, 2 ticks. Which operand of `and` or `or` the netlist puts on `a` is not specified; `assert latency` ([§14.7](#147-verification)), not the order written, pins a path's ticks through a `ComparatorAND`. `assert latency` is not parsed yet, so nothing pins them today. The tile tier carries one place-and-route obligation of its own: a `bridge` coordinate renders as a tile that conducts to neither **another net's** coordinate below it nor another net's coordinates diagonally below it. Its own net's coordinate below it is the climb that put it there, since there is no separate via, and has to conduct. Stage 2 ([§14.5](#145-place-and-route)) keeps each net's dust off another net's dust and off the coordinates beside it in their own plane, and climbs to clear what it cannot go round, so every strand a layer above another net is the escape's doing and separating the two is the tile's. It is a requirement on the catalogue rather than on the author, and it is wider than the finding that reports it: `W_ROUTE_CROSS_LAYER_CLEARANCE` names the strand-to-strand pairs, which are the ones two signals could come to share, while the obligation above holds over any coordinate of another net below a `bridge` tile, a cell body or an I/O pad as much as dust. Climbing over a component is the ordinary way past it, so a finding that named those too would report the layout rather than what is unresolved in it. - **Absorbed**: repeater, observer, comparator, and orientation, all cell-implementation differences. - **Not absorbed**: QC (quasi-connectivity), BUD, update order. These depend on the implicit semantics of block-update order, for which no portable implementation exists. Logic that requires update-order semantics is a compile error rather than a silent footgun, consistent with "recompile, don't transcode". No pass checks for it yet, so `E_NO_PORTABLE_IMPL` below is not raised today. ```text E_NO_PORTABLE_IMPL line 15: this circuit requires update-order (quasi-connectivity / BUD) semantics. No portable redstone implementation exists for the target edition. Fix: redesign the logic to be order-independent, or drop to Tier 0 with an @edition guard. ``` Hand-placed redstone breaks across editions. With a logic description the compiler emits an edition-correct circuit instead. That is the biggest reason to describe logic rather than parts. ## 14.7 Verification Declare the intent, then simulate the synthesized circuit per tick, headless, and check it. There are three assertion kinds: ``` # combinational: truth table assert truth(sig.a, sig.b -> sig.out) { 00->0; 01->1; 10->1; 11->0 } # latency — matters because place-and-route changes delay assert latency(sig.in -> sig.out) <= 4 # temporal — bounded eventually only, not full LTL assert always(sig.button -> eventually sig.door_open within 8) ``` Of the three, only `truth` and `always` are parsed today, and nothing simulates the circuit yet. `assert latency(...)` is `E_PARSE` at `latency`. A truth table's rows are checked ([Lint](/spec/lint/#truth-tables)), and the synth pipeline refuses either kind naming a signal nothing in its scope drives (`E_LOGIC_UNBOUND_SIGNAL`), but neither is checked against the circuit: a truth table its logic contradicts still synthesizes. The loop below and `E_SIM_ASSERTION_FAILED` do not exist yet. The self-correction loop (P5) is **synth → sim → diff → patch**, and verification runs per target edition. The patch targets place-and-route hints, repeaters, and buffers only. **The Logic IR is never rewritten**, because self-correction that auto-modifies logic is dangerous. ```text E_SIM_ASSERTION_FAILED edition=bedrock: assert latency(sig.in -> sig.out) <= 4, but measured 6 (2 buffer repeaters on the routed path). Patch target: placement hint / route. (logic is never auto-modified) Suggested: relax to <=6, enlarge circuit void to shorten routes, or pin cell placement. ``` ## 14.8 Connection to the IR and phases Four IR layers sit between the Intent IR and the block-array IR, separated the way HDL separates them: ``` Intent IR logic declarations / circuit region / signal binding ↓ logic_synth Logic IR logical expressions, dependency DAG. Edition-neutral, zero delay ↓ Netlist IR cells and nets. Logical Cell selection. Still no delay ↓ Edition Netlist IR the same cells and nets. Edition Cell selection. Still no wire ↓ logic_place Placement IR cell coordinates ↓ logic_route Placement IR + actual wire length + delay + buffer repeater coordinates. Delay determined ↓ block-array IR the voxel reality of dust, repeater, torch, comparator ``` The Placement IR is filled pass by pass ([§14.5](#145-place-and-route)): placement gives every cell its coordinates, then routing adds the wire length, delay insertion the delay, and crossing legalization the buffer repeaters' coordinates. An Edition Cell fixes the ticks from each of its ports ([§14.6](#146-edition-differences)), but there is no wire to count before routing, so the delay is determined in the Placement IR and no earlier. Nothing lowers the Placement IR to the block-array IR yet: edition legalization is not implemented, `cairn compile` runs none of these passes, and a circuit goes no further than the IRs `cairn synth --experimental-logic-synth` prints. The phase model ([Compilation Model](/spec/compilation/)) splits the step right after `fixtures` into `logic_synth → logic_place → logic_route`, because the I/O port coordinates are not fixed until sensors and actuators are placed in 3D. ## 14.9 Reverse conversion Hand-built redstone imported from a schematic ([Ecosystem Interop](/spec/ecosystem-interop/)) is kept as Tier 0 raw in v1. Reverse-synthesizing logic from a mass of dust is out of scope, consistent with the generation-first, lossy approach. # 15. Open Issues ## 15.1 Choices to settle at implementation time **Where provenance lives:** the `.crn` header or the lock. Decided: the `.crn` carries only `@intended_targets` as a hint and `@cairn` as the language version it was written against, and the compiler writes records such as `verified` into the lock ([Versioning and Editions §10.6](/spec/versioning-editions/#106-provenance-and-lock)). **Coordinate system:** keep the corner origin and `front = +z`, or move to a centre origin or an entrance-relative orientation. Decided: a placement's origin is the low-`x`, low-`z` corner of its full extent, overhang columns included, which its structure file writes as `(0, 0, 0)` ([Components, Editing, and Multi-building §9.3.2](/spec/components-editing-sites/#932-origin-selectors)). Coordinates on the member lines of a `struct` or `def` body are measured from the low corner of the `size=` footprint instead, and shift with `overhang=` as every member does ([Compilation Model §4.3](/spec/compilation/#43-gable-roof-voxel-rules)). Coordinate triples (`from=1,1,1`, `at=4,3,2`) on those lines are read the same way once the spec defines them. `y` rises from the floor, and `front` / `back` / `left` / `right` face `+z` / `-z` / `-x` / `+x` ([Syntax §5.4](/spec/syntax/#54-selectors), [§9.3.1](/spec/components-editing-sites/#931-coordinate-convention)). A centre origin would sit off the true centre on every even side, behind a tie-break the author has to remember, as `at=center` takes the column right of an even wall's midpoint. An entrance-relative frame would add nothing: the author chooses which wall is `front`, and a door's `side=` already names the entrance wall. Which way a build faces in the world is chosen when a player places its structure file in the game, since `place` has no rotation, so a fixed frame does not fix the facing. A per-floor local `y=0` comes from `level y=N` ([Compilation Model §4.7](/spec/compilation/#47-level-grouping-and-volume-derivation)). **The type of the reverse-direction IR:** one IR that can degenerate, or separate Intent IR and Raw Geometry IR types. The tentative policy is to share the block-array layer and split types at the member layer above it ([Architecture](/spec/architecture/)). **Legacy `.schematic`** from before 1.13 is unsupported in v1. A numeric-ID mapping could be considered later as an option. **Language-evolution policy:** a Rust-style, year-based opt-in, or changes announced per release. Decided: per release, as [Compatibility Tiers §C.3](/spec/compatibility/#c3-how-a-break-is-communicated) records. The tiers already bound what a release may break, and a Stable surface's `W_DEPRECATED` window already gives a file at least one release to move, so an opt-in would add a second bound and keep every past revision's rules alive in the compiler. "Edition" already names Java or Bedrock, and `@cairn` stays provenance. ## 15.2 Untouched topics **Primitive promotion.** Whether columns and arches should become semantic primitives. The decision rests on experimental data from the [Evaluation Framework](/spec/evaluation/). **Interiors.** Whether the `inside.front` prefix suffices or a higher-level `room` concept is needed, and whether furniture can be served by a `def` library. # Compatibility Tiers Cairn ships a single release train under [date-based versioning](/spec/#two-version-axes) (`YYYY.M.PATCH`). Because CalVer has no semver-style "major" axis, the **scope of what is and is not safe to break in a release** is set by this document rather than by version numbers. Every public surface of the project sits in exactly one of three tiers: **Stable**, **Evolving**, or **Internal**. The tier sets the rules; the version number only records when something happened. ## C.1 Tier definitions ### Stable The contract is: **breaking changes are announced one release in advance with a `W_DEPRECATED` warning, and removed in the following monthly minor at the earliest.** `W_DEPRECATED` is a reserved code ([§C.3](#c3-how-a-break-is-communicated)): it is added with the first deprecation, and nothing emits it yet. A surface that no source or command line spells, such as a JSON output field or an exit code, has nothing to carry the warning, and is announced in the CHANGELOG's `Deprecations` section alone. - A breaking change reaching `Stable` MUST be referenced from the next month's CHANGELOG. - Renames MUST keep the old name working for the deprecation window. - Default values MAY change with a warning; semantic meaning MUST NOT. - Downstream consumers can pin a minor version (`cairn ~= 2026.7`) and expect at least the next monthly minor to compile their inputs unchanged. Stable surfaces: - `.crn` syntax that is normative in the spec (keywords, headers, block kinds, blockstate primitives, theme/material primitives, edition guards), except what a section flags [subject to change](#subject-to-change). - The lockfile format (`.lock`: fields, hash inputs, the `verified` semantics defined in [§10.6](/spec/versioning-editions/#106-provenance-and-lock)). - `cairn compile`, `cairn check`, and `cairn info`: their flag names, argument shapes, JSON output schemas, and process exit codes. - The tier-1 material vocabulary: the abstract tokens the built-in `materials` catalogs declare, listed in [§7.2](/spec/materials-themes/#tier-1-tokens). Adding one is not a break. - The error and warning codes (`E_*`, `W_*`) [Lint §11.1](/spec/lint/#111-diagnostic-codes) lists, and the meaning the spec states for a reserved code ([§C.3](#c3-how-a-break-is-communicated)). ### Evolving The contract is: **breaking changes ship in any monthly minor and are listed in the CHANGELOG.** No deprecation window is promised. - Consumers SHOULD read the CHANGELOG before bumping the minor. - Patches MUST NOT introduce Evolving-tier breaks; only monthly minors may. - A surface MAY graduate from Evolving to Stable by being moved in this document plus CHANGELOG. Demotion (Stable → Evolving) is forbidden short of a spec amendment. Evolving surfaces: - Spec chapters or sections explicitly marked as draft (the [Open Issues](/spec/open-issues/) list), and the syntax a section flags [subject to change](#subject-to-change). - New `cairn` subcommands during their first three monthly minors after introduction. - The registry pack and constraint catalog file layout (their *hashes* feed Stable lock semantics, but the *internal structure* is Evolving). No constraint catalog ships yet, and a lock records its hash as zeros. - The tier-2 material vocabulary: the block each tier-1 token resolves to at a target ([§7.2](/spec/materials-themes/#tier-1-tokens)). - Canonical block tokens: the names a target accepts, which follow its registry pack, and the block each names there ([§7.3](/spec/materials-themes/#73-mappings-across-version-and-edition)). - The CLI's human-readable diagnostic format and prose (the *codes* are Stable; the *prose* is not). - The `--features` set on `cairn-lang-cli` (cargo features) and `[features]` on workspace crates. #### Subject to change The flag is for the syntax the `.crn` syntax row of [§C.2](#c2-tier-of-each-surface-by-milestone) covers: chapters 5 to 9, and [§10.7](/spec/versioning-editions/#107-java--bedrock-portability), which writes the edition guards. A section there that specifies syntax the compiler does not build yet opens with a **Subject to change.** paragraph naming that syntax. What the flag names stays Evolving whatever tier the row gives, and the flag says nothing about the rest of its section. The change that builds the syntax takes the flag off. The syntax then takes the row's tier, and when that tier is Stable, the CHANGELOG entry says it graduates. No flag is added to syntax that is already Stable, since that would be a demotion. Chapter 14 carries no flag: the redstone DSL has a row of its own, Evolving until M6. ### Internal The contract is: **no promise. Any release may change anything. Consumers depending on Internal surfaces are responsible for their own pinning.** Internal surfaces: - The Rust API of every workspace crate (`cairn-lang-core`, `cairn-lang-nbt`, `cairn-lang-formats`, `cairn-lang-redstone`, `cairn-lang-lsp`, `cairn-lang-wasm`, `cairn-lang-tree-sitter`, `cairn-lang-docs`). These crates are published to crates.io from the first monthly minor that contains them, but every item that is not the CLI's transitive public dependency is marked `#[doc(hidden)]`. No item is marked yet. - `cairn synth`, which runs only behind `--experimental-logic-synth`, and the JSON it prints. - The compiler's intermediate representation (Intent IR, Semantic IR, block-array pivot layouts). - The on-disk shape of incremental build caches (`target/`-equivalents inside the project workspace). - The internal protocol of the language server (its on-wire LSP protocol with VS Code etc. is Stable; the way `cairn-lang-lsp` decomposes work internally is not). ## C.2 Tier of each surface, by milestone The tier of a given surface is not fixed for all time. A surface earns its way to Stable as the project matures along the [roadmap](/roadmap/). The table is the canonical record. | Surface | Through M1 | At M2 (minimal build) | At M3 (examples work) | At M5 (DX) | At M6 (redstone) | |---|---|---|---|---|---| | `.crn` syntax (chapters 5-9, §10.7) | Evolving | Evolving | **Stable** | Stable | Stable | | Lockfile format | Evolving | **Stable** | Stable | Stable | Stable | | `cairn compile/check/info` flags | Evolving | Evolving | **Stable** | Stable | Stable | | Diagnostic codes (`E_*`, `W_*`) | Evolving | Evolving | **Stable** | Stable | Stable | | Tier-1 material vocabulary | Evolving | Evolving | **Stable** | Stable | Stable | | LSP wire protocol (LSP std) | — | — | — | **Stable** | Stable | | Redstone DSL (chapter 14) | Evolving | Evolving | Evolving | Evolving | **Stable** | | Tier-2 material vocabulary, canonical block tokens, registry pack layout | Evolving | Evolving | Evolving | Evolving | Evolving | | Rust API (every crate) | Internal | Internal | Internal | Internal | Internal | Reading the table: **the column where a row first turns Stable is the soft commitment.** Until that milestone lands, the project reserves the right to change the surface without a deprecation window. The Rust API row never graduates within the planned roadmap. Cairn is consumed through the `cairn` CLI binary and the language server, not as a Rust library. If a downstream consumer wants a stable embedding API, the project will treat that as a new, separately tracked surface. ## C.3 How a break is communicated Regardless of tier, every breaking change MUST appear in the CHANGELOG in a section named `Breaking changes`. For Stable surfaces this is the second appearance, the first being the preceding release's `Deprecations` section. ```text ## 2026.11.0 — 2026-11-01 ### Breaking changes - `cairn compile --java-target` removed (deprecated in 2026.10.0). Use `--target` with `--edition java`. ### Deprecations - `slot` keyword without an arrow form is now deprecated; emits `W_DEPRECATED`. Will be removed no earlier than 2026.12.0. ``` A break reaches every file at once. Cairn has no per-file opt-in to a revision of the language, such as Rust's editions: `@cairn` records the language version a file was written against and selects no rules ([§5.3](/spec/syntax/#53-headers)), and "edition" names Java or Bedrock ([Glossary](/spec/glossary/#editions-and-versions)). What a release may break is bounded by the tier of the surface instead, and a Stable surface's `W_DEPRECATED` window gives a file at least one release to move. `W_DEPRECATED` and `E_BREAKING` are reserved codes: neither exists yet, and each is added with the first deprecation or break that needs it, with the meaning this chapter fixes for it before either is added. Adding a new code is not a breaking change; changing the meaning of an existing code is. `W_DEPRECATED` warns on a source or command line that uses a Stable form inside its deprecation window, and names the replacement and the earliest release that removes the form. Every deprecation raises the one code, and its message says which form it is about. `E_BREAKING` refuses a source or command line that uses a form a release has removed from a Stable surface, in place of the error the form would otherwise earn, and names that release and the replacement. It stays on that form in every later release, so a removed form never falls back to that other error. A form removed from an Evolving surface has no deprecation window and gets no `E_BREAKING`: it earns the error any source spelling it earns, and the CHANGELOG entry names the replacement. **Reserved codes.** The codes a stable command raises are the ones [Lint §11.1](/spec/lint/#111-diagnostic-codes) lists. The redstone pipeline's codes, which only the Internal `cairn synth` raises, are outside that catalog on purpose. Any other code the spec names, such as `E_STATE_DOMAIN` or `E_REQUIRES_CONFLICT`, is a reserved code: no command raises it yet. A reserved code lands with the meaning the spec states for it, where it states one, and its row landing is adding a code. **What a code means.** A code's severity, and the payload [Lint §11.2](/spec/lint/#112-machine-readable-payload) gives it, are part of what it means. Adding a field to a payload, a payload to a code that had none, or a value to a field the payload gives as one of a list is still adding. Removing or retyping a field, renaming a `kind`, or leaving out a field that was always present changes what the code means. **Placeholders.** A placeholder is a finding that stands in for what the compiler does not build yet, and stops being raised there once it is built. That is a bug fix that aligns behaviour with the spec, which [§C.4](#c4-what-is-not-covered-by-tier) never counts as a break, and the placeholder's code still means what it meant. A placeholder stands in only for what a [subject to change](#subject-to-change) flag names, what another chapter says the compiler does not build yet, or what the spec reserves for a later extension. Source the spec itself refuses keeps its code. The placeholders today include: - `E_PARSE`, on syntax the spec specifies that does not parse yet, such as coordinate triples, decimals, `nbt={...}` values, `edit`, `@edition` and `assert latency`; - `E_UNKNOWN_KEYWORD`, on a keyword the spec specifies that the compiler does not know yet, such as `spawn`, `chest`, `lever` and `raw_block`; - `W_IGNORED_ARGUMENT`, on an unreached key, which [Lint §11.3](/spec/lint/#113-error-vs-warning) lists, a theme selector's bindings among them; - `E_UNRESOLVED_PORT`, on a port of a member under a `level`, which [§9.3.5](/spec/components-editing-sites/#935-ports-and-connect) reserves for a later extension; - `W_STATE_LITERAL_UNCHECKED`, until `E_STATE_DOMAIN` checks a state literal against the target; - `W_DEFERRED_MEMBER`, on a member whose line writes what the block-array pass does not lower yet ([Lint](/spec/lint/#lowering)), such as a member whose keyword lowering does not handle yet, a `floor` or `roof` under a raised `level`, and a `window` with `repeat=` above 1 and `sym=true`. A placeholder that nothing raises any more keeps its row in [Lint §11.1](/spec/lint/#111-diagnostic-codes), which says from which release nothing raises it, and its name is never given another meaning. ## C.4 What is not covered by tier Two classes of change sit outside this matrix: - **Bug fixes** that align behaviour with the spec are never breaking, even if a consumer was depending on the buggy behaviour. The spec, not the implementation, defines the contract. - **Output bit-equality** of emitted `.nbt` / `.litematic` / `.schem` / `.mcstructure` is not promised at any tier. Only the `.nbt` and `.mcstructure` writers exist today ([§12.1](/spec/ecosystem-interop/#121-forward-direction)). Two releases may produce structurally-different files for the same source; what matters is that the result is valid for the target `(edition, version)` and matches the lockfile's `resolved_ir_hash`. See [§10.6](/spec/versioning-editions/#106-provenance-and-lock). # Glossary Defined terms used throughout the specification. Where a term is defined in detail in a chapter, that chapter is linked. This page is **not normative on its own**, since the linked chapter is the source of truth, but implementations and authors SHOULD use these exact spellings. The vocabulary is closed by design ([principles P3](/spec/principles/)); inventing parallel terminology defeats the lint loop. ## Architecture and IR - **Block-array IR.** The universal pivot at the bottom of the three-layer IR: a voxel grid + palette + block entities + entities, neutral to format, edition, and version. Every format's frontend/backend, plus diff/IoU/serialization, meet here. See [architecture §3.1](/spec/architecture/#31-the-block-array-ir-is-the-universal-pivot). - **Intent IR.** The top layer: named members carrying `id` / `class` / `role` / `mat_slot` / `intent_state` / `resolved_state`. Independent type with invariants; not produced directly by schematic ingestion. See [architecture §3.2](/spec/architecture/#32-the-intent-ir-is-rich-and-carries-invariants). - **Semantic / Component-Theme IR.** The middle layer that resolves themes, components (`def`), and multi-building (`site`) into the Intent IR. See [components-editing-sites](/spec/components-editing-sites/), [materials-themes](/spec/materials-themes/). - **Logic IR / Netlist IR / Edition Netlist IR / Placement IR.** The four redstone sub-layers between Intent IR and block-array IR. Delay is **not** carried in Logic/Netlist, and the Edition Netlist IR has only each cell's own ticks; the Placement IR determines the delay. See [redstone §14.8](/spec/redstone/#148-connection-to-the-ir-and-phases), [architecture §3.3](/spec/architecture/#33-redstone-sub-layers). - **`semantic_level`.** An imported artifact's progress label: `raw` (one voxel per line) → `grouped` (L1 spatial compression) → `lifted` (L2 semantic naming). The compiler reaches L1; L2 is the LLM's job. See [ecosystem-interop §12.3](/spec/ecosystem-interop/#123-three-tiers-of-transliteration). ## Members and blockstate - **Member.** A named element of the Intent IR. Types: `block`, `block_entity`, `entity`. The IR carries the type, but the author writes one selector grammar across all of them ([principles P4](/spec/principles/)). Today a member carries the `role` its keyword classifies to and no type, and no keyword places a block entity or an entity yet. - **`id` / `class` / `role`.** Identity, group, and architectural function tags on a member. Used for selectors and stable addresses. - **`mat_slot`.** A material injection point on a member; bound by a `theme`. Structure carries slots, themes carry block bindings. See [materials-themes §7.1](/spec/materials-themes/#71-slots-as-dependency-injection). - **`intent_state`.** The author's blockstate intent. Edit diffs look **only** here. Today it holds every `key=value` a member line writes except `id`, `class` and `mat_slot`. See [blockstate §6.2](/spec/blockstate/#62-intent_state-and-resolved_state). - **`resolved_state`.** Compiler-derived blockstate (orientation, connections, waterlogged). Never hand-written. Not populated yet: what lowering derives goes straight into the block array. - **Override-promotion.** Writing a blockstate that *could* be intent promotes it from `resolved_state` to `intent_state`. The spec rule is "derive by default; any blockstate that can be intent is overridable." See [blockstate §6.1](/spec/blockstate/#61-derive-by-default-promote-on-override). - **Anchor / bbox.** Every primitive carries an `anchor` (reference point), a declared bbox, an actual bbox, and a host face in the IR. Primitives like paintings, item frames, and arch windows have a declared size that differs from the occupied AABB, and these four resolve it. The IR carries none of them yet. See [entities §8.2](/spec/entities/#82-anchor-conventions). ## Materials and themes - **Canonical token.** The value bound to a slot or theme selector: a *meaning* token, not a raw block ID. The backend resolves the per-`(edition, version)` ID and state names. See [materials-themes §7.2](/spec/materials-themes/#72-canonical-vocabulary). - **Canonical block token.** A specific block meaning: `@oak_planks`, `@water_cauldron`, `@oak_log[axis=x]`. Silent meaning-breaking downgrades (`@water_cauldron` → `cauldron`) are forbidden. - **Abstract material token.** An aesthetic choice: `@floor.wood.broadleaf`, `@roof.dark_wood`. Theme policy MAY downgrade these (e.g. oak↔birch). - **Tier-1 token.** An abstract material token the built-in `materials` catalogs declare, Stable once the specification leaves draft. The block it resolves to is tier-2, and Evolving. See [materials-themes §7.2](/spec/materials-themes/#tier-1-tokens). - **`theme`.** A CSS-like binding of slot/selector values to canonical tokens. Separates *structure* (where the walls are) from *style* (which blocks). - **`def`.** A slot-bearing Component definition (a reusable struct). Recursion forbidden; parameterization allowed, though until a mechanism for it is specified the header takes only `size=` and `class=`. The minimum version of a composite is the max of its parts. See [components-editing-sites §9.1](/spec/components-editing-sites/#91-def-the-component-construct). - **`site`.** A multi-building container that places `def`-derived structures by topological relations (`east_of`, `gap=`, `connect`), not absolute coordinates. See [components-editing-sites §9.3](/spec/components-editing-sites/#93-multi-building-with-site). ## Compilation - **Phase.** A fixed evaluation slot the compiler sorts each command into: `massing → envelope → openings → fixtures → logic_synth → logic_place → logic_route → raw`. Source order is irrelevant; phases enforce semantics ([compilation §4.1](/spec/compilation/#41-phase-evaluation)). - **Last-wins (local).** Within the same phase, a later command overrides an earlier one. The old whole-program last-wins ("paint model") is dropped. See [principles P2](/spec/principles/). - **Target axes.** `(edition, version)`: the only layer that knows them is the backend. The DSL source never names them. `--edition` is required, `--target` alone is forbidden. See [compilation §4.2](/spec/compilation/#42-target-axes), [versioning-editions](/spec/versioning-editions/). - **Lowering.** The pass that turns a scope's members into the block-array IR: walls, openings, roofs, walkways, and materials become a palette and an index array. `cairn compile`, `cairn lower`, `cairn info`, and `cairn check` all run it. See [architecture §3.1](/spec/architecture/#31-the-block-array-ir-is-the-universal-pivot). - **DataVersion.** Mojang's monotonically increasing integer key for a Java version. Cairn uses it as the canonical ordering key so the semver→date-based version transition does not break `since/until` or `@requires`. See [versioning-editions §10.1](/spec/versioning-editions/#101-the-target-is-a-compile-time-parameter). ## Headers and provenance - **`@cairn`.** Header declaring the **Cairn language version** the file was written against (CalVer `YYYY.M[.PATCH]`). Provenance only; optional. - **`@requires`.** A capability floor on the Minecraft target (e.g. `version>=1.20`). Hard error on conflict with the inferred value. That error, `E_REQUIRES_CONFLICT`, is reserved: no inferred range is derived yet. A `cairn compile --target` below the floor is `E_VERSION_CAP`. See [versioning-editions §10.4](/spec/versioning-editions/#104-fail-loud-and-minimum-version-inference). - **`@intended_targets`.** A hint about which Minecraft versions the file was designed for. Not a verification record, since the record lives in the lock. Still weighed against the file's own floor: an intent the floor refuses is reported rather than left to be discovered at compile time. - **Lock (`*.crn.lock`).** Compiler-generated reproducibility record, written next to the source as `.lock` (`cottage.crn.lock`) unless `--lock` names another path. Carries `lock_schema_version`, `source_hash`, `cairn_version`, `target` (`edition`, `mc_version`, `data_version`), `inputs` (`registry_pack_hash`, `constraint_catalog_hash`), `resolved_ir_hash`, `verified: true` and `member_version_sensitivity`, plus `placements` and `walkways` for a source with a `site`. See [versioning-editions §10.6](/spec/versioning-editions/#106-provenance-and-lock). - **Provenance stamp.** `(edition, version)` recorded onto the block-array IR on import, mapped from the format itself (`.litematic` → java, `.mcstructure` → bedrock, `.schem` → java). See [ecosystem-interop §12.4](/spec/ecosystem-interop/#124-import-stamping-and-pitfalls). ## Redstone - **Logical cell / edition cell / physical tile.** The three-tier cell library. The Logic IR selects logical cells; the per-edition cell library lowers them to physical tiles. Confines the Java/Bedrock difference to the library. See [redstone §14.6](/spec/redstone/#146-edition-differences). - **Combinational vs sequential.** v1 ships closed-set combinational gates and curated sequential macros (`latch` / `pulse` / `delay` / `edge_rising` / `edge_falling` / `counter`). Arbitrary FSMs / CPUs are out of scope for v1. Today a `logic` line accepts only `and`, `or` and `not`; no sequential macro is parsed yet. - **Truth / latency / temporal assertion.** The three verification kinds. See [redstone §14.7](/spec/redstone/#147-verification). Temporal is bounded `eventually within N` only, not full LTL. `assert latency` is not parsed yet (`E_PARSE`), and no simulator checks the other two against a built circuit. - **QC / BUD.** Quasi-connectivity / block-update-detector behaviors. **Not absorbed** by the cell library; a circuit that depends on update-order semantics is an `E_NO_PORTABLE_IMPL` compile error. That code is not implemented yet: nothing checks a circuit for update-order dependence. ## Lint and evaluation - **Self-correction loop.** The compile → diagnostics → patch → recompile cycle that lifts precision out of one-shot generation ([principles P5](/spec/principles/)). Diagnostic messages MUST be in "what is wrong / valid candidates in the target / suggested fix" form ([lint](/spec/lint/)). - **Fail-loud.** Silent substitution and implicit dropping of unknown IDs / out-of-domain states are forbidden. Errors return the closed set of valid candidates plus a suggested DSL fix. See [versioning-editions §10.4](/spec/versioning-editions/#104-fail-loud-and-minimum-version-inference). - **`semantic_sensitivity`.** A constraint-catalog field distinguishing "the ID stays valid but meaning/behavior/appearance changed at this version" from `since/until`. Cauldron split @1.17, wall connection bool→none/low/tall @1.16, item format @1.20.5 are examples. See [versioning-editions §10.5](/spec/versioning-editions/#105-which-version-is-it-for-has-three-answers). - **Block IoU.** Voxel intersection-over-union used for the import self-correction loop. Convergence threshold ≥ 0.985. See [ecosystem-interop §12.2](/spec/ecosystem-interop/#122-reverse-direction-the-compiler-transliterates-an-llm-lifts), [evaluation §13.2](/spec/evaluation/#132-reverse-conversion-auxiliary-metrics). - **Zero-shot Compile Rate / Fix Convergence Rate / Token Efficiency / Edit Stability.** The four primary spec-iteration metrics. See [evaluation §13.1](/spec/evaluation/#131-primary-metrics). ## Editions and versions - **Edition.** `java` or `bedrock`. Compile-time only; never present in the DSL semantic layer. See [versioning-editions §10.7](/spec/versioning-editions/#107-java--bedrock-portability). - **Cairn version vs MC target.** Two **separate axes** distinguished by field/flag/keyword, never by format. `cairn:2026.06` vs `mc:1.21.4` in disambiguating prose. See [Specification overview](/spec/), [versioning-editions](/spec/versioning-editions/). - **Recompile, don't transcode.** The language spec does **not** guarantee NBT portability across version or edition. To target a new version, recompile the DSL; do not convert the NBT. See [versioning-editions §10.2](/spec/versioning-editions/#102-language-contract-recompile-dont-transcode). ## Ecosystem interop - **Raw / L1 / L2.** The three tiers of faithful transliteration on import. The compiler reaches L1 (spatial compression, no naming); L2 is the LLM's job (naming → `wall`, `mat_slot`, `theme`). See [ecosystem-interop §12.3](/spec/ecosystem-interop/#123-three-tiers-of-transliteration). - **`raw_fill` / `raw_block` / `raw_repeat`.** Escape-hatch primitives used by faithful transliteration. Import-origin instances carry `origin=imported` so they are not treated as first-class design DSL. # Developer Guide This guide covers the Rust workspace and the day-to-day contributor flow. If you are working on the language spec rather than the compiler, start at the [Specification](/spec/) and [CONTRIBUTING.md](https://github.com/kage1020/Cairn/blob/main/CONTRIBUTING.md). > The spec is the source of truth, and the Rust workspace implements it chapter by chapter: what it > does not cover yet, the spec marks as not implemented. `cairn-lang-wasm` is still a placeholder. ## Workspace layout | Path | Contents | |---|---| | `Cargo.toml` | Workspace root: shared lints, release profile, MSRV. | | `rust-toolchain.toml` | The exact Rust version CI runs, with `rustfmt` and `clippy`. | | `rustfmt.toml` | Edition 2024, `max_width = 100`. | | `crates/` | The Rust workspace (below). | | `editors/vscode/` | VS Code extension. | | `examples/` | Worked `.crn` examples. | | `website/` | This site: Astro + Starlight, including the specification, and the `cairn-lang-docs` crate that embeds its pages. | Each crate maps back to the spec chapter it implements: | Crate | Role | Kind | |---|---|---| | [`cairn-lang-core`](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-core/README.md) | Parser, IR, resolver, lint | lib | | [`cairn-lang-cli`](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-cli/README.md) | The `cairn` binary | bin | | [`cairn-lang-nbt`](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-nbt/README.md) | Java / Bedrock NBT codec | lib | | [`cairn-lang-formats`](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-formats/README.md) | `.nbt` / `.mcstructure` writers, registry packs, portability | lib | | [`cairn-lang-redstone`](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-redstone/README.md) | Logic synthesis and place-and-route; tick simulation is planned | lib | | [`cairn-lang-lsp`](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-lsp/README.md) | Language Server Protocol | lib + bin | | [`cairn-lang-wasm`](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-wasm/README.md) | WebAssembly bindings | cdylib + rlib | | [`cairn-lang-tree-sitter`](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-tree-sitter/README.md) | Grammar for editor highlighting, also published to npm | lib | | [`cairn-lang-docs`](https://github.com/kage1020/Cairn/blob/main/website/rust/README.md) | This site's Markdown pages, embedded for `cairn docs` | lib | ## Dependency rules `cairn-lang-core` sits at the root. `cairn-lang-cli`, `cairn-lang-lsp`, and `cairn-lang-wasm` are leaf integrations that nothing depends on. `cairn-lang-formats` is the only crate that pulls in `cairn-lang-nbt`. `cairn-lang-docs` depends on nothing. Its manifest is `website/Cargo.toml`, so the pages it embeds are the site's own sources, with no copy to drift. - **`cairn-lang-core` knows nothing about NBT, file formats, redstone simulation, or editor protocols.** The block-array IR is the universal pivot ([Architecture](/spec/architecture/)); everything beyond it lives in a sibling crate. - **`cairn-lang-nbt` is the byte codec and nothing more.** Litematica regions, schematic palettes, and Bedrock's `.mcstructure` quirks belong in `cairn-lang-formats`. - **`cairn-lang-redstone` reads sensors, actuators, and `circuit` reservations from core's Intent IR**, then lays its own pads and owns its own IR layers ([Redstone §14.8](/spec/redstone#148-connection-to-the-ir-and-phases)). ## Toolchain | Tool | Pinned by | Notes | |---|---|---| | Rust | `rust-toolchain.toml` | An exact version, not a channel. With `rustfmt` and `clippy`. | | Edition 2024, MSRV | `Cargo.toml` | Workspace package metadata, inherited by every crate. | | Formatting | `rustfmt.toml` | `max_width = 100`, Unix line endings. | | Lints | `[workspace.lints]` in `Cargo.toml` | `unsafe_code = forbid`, `missing_docs = warn`, `clippy::all` + `clippy::pedantic`. | The Rust version is exact because CI treats every clippy finding as fatal. On a channel, a Rust release would turn every open branch red by itself, with findings in files the branch never touched. The pin decides when new lints arrive, not whether they do: bumping it is a pull request of its own, carrying whatever the new release found. The pin is not the MSRV. `rust-version` is the floor a consumer needs, and raising the pin does not raise it. That number lives only in `Cargo.toml`. CI's `MSRV` job reads it back out with `cargo metadata` and checks the workspace with that compiler, so a change that reaches for a newly stabilised API goes red in CI rather than for a consumer. Every crate except the tree-sitter one inherits these with `[lints] workspace = true` and writes no `[lints.*]` table of its own; the next paragraph explains why the tree-sitter crate carries a copy. Inheritance is opt-in per crate and all-or-nothing. A crate without that line receives none of the workspace lints, so a lint added to the workspace later would silently skip it. `unsafe_code` is forbidden everywhere except one module: `ffi` in the tree-sitter crate's Rust binding, which is the only way to reach the generated C parser. `forbid` cannot be lifted, so that crate alone carries a copy of the workspace lints with `unsafe_code` at `deny`, and `ffi` lifts it with `#![expect(unsafe_code)]`. `cargo xtask lint` keeps the exception that narrow: - its `manifest` rule fails if the workspace level is anything but `forbid`, if a crate does not inherit the workspace lints, or if the tree-sitter copy differs from them in anything else; - its `unsafe-code` rule fails if an `allow`, `expect`, `warn` or `cfg_attr` attribute names `unsafe_code` outside that module. If another use case ever needs `unsafe`, it lifts the lint on a single module with documented invariants and adds that file and module to the rule's `ALLOWED` list. It never uses `#[allow]` at a call site. ## Build, test, lint CI runs these on Linux, macOS, and Windows, checks the workspace once more at the declared MSRV, and builds the API docs on Linux (below). Run them before opening a PR. ```sh cargo fmt --all -- --check cargo clippy --workspace --all-targets -- -D warnings cargo build --workspace --locked cargo test --workspace --locked cargo test -p cairn-lang-core --bench lowering cargo test -p cairn-lang-redstone --bench place_and_route ``` `--workspace` does not select bench targets, so the last two run each bench once, as an untimed test. CI's `Lint` job also runs `cargo xtask lint`, which compares files with each other rather than testing behaviour: README inventories, spec citations, the diagnostic catalog, the copies of the version, and the lint configuration. `cargo xtask lint --list` names the rules, and each rule's module in `xtask/src/rules/` explains why it exists. CI sets `RUSTFLAGS=-D warnings`, so any new warning fails the build. To match it locally: ```sh RUSTFLAGS="-D warnings" cargo build --workspace --locked ``` CI also builds the API docs twice on Linux, with rustdoc's warnings fatal, because clippy does not see a doc link to a private item or to a path that no longer resolves. The first run covers the public surface, and it is the only one that flags a public doc linking to a private item. The second also covers the docs only a contributor reads: ```sh RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked --all-features RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked --all-features --document-private-items ``` Two benches time the passes a build spends most of its time in: `lowering` in `cairn-lang-core` and `place_and_route` in `cairn-lang-redstone`. They call the passes in-process, since timing the CLI over an example would mostly time process startup. They generate their sources, since an example-sized source goes through a pass faster than the timer can tell a change apart. They take their settings from the release profile, except `panic`: Cargo builds benches with unwinding, as it does tests. CI runs the benches once as tests, as above, but never times them. They exist to measure a change to `[profile.release]`, above all to `opt-level`, before it is made. [CONTRIBUTING.md](https://github.com/kage1020/Cairn/blob/main/CONTRIBUTING.md) walks through comparing two profiles with them. To run both: ```sh cargo bench -p cairn-lang-core -p cairn-lang-redstone --bench lowering --bench place_and_route ``` `cairn-lang-wasm` has nothing to build for the browser yet: it has no `wasm-bindgen` binding layer, so `wasm-pack` refuses it. Its [README](https://github.com/kage1020/Cairn/blob/main/crates/cairn-lang-wasm/README.md) says what is missing and gives the command for when the binding layer lands. ### The examples in Minecraft `cargo test` holds what Cairn writes to Cairn's own reading of each format. Whether the game reads a file the same way is the job of the `Minecraft` workflow, whose check is `Examples load in Minecraft Java`. It runs weekly, and on a pull request or a push to `canary` that touches the examples, `cairn-lang-core`, `cairn-lang-nbt`, `cairn-lang-formats` and its registry packs, `cairn-lang-cli` or `Cargo.lock`. For each targetable row of the built-in Java pack, the job compiles every example and has that version's server jar load each `.nbt` through its data generator. `--dev` turns the files into SNBT, and `--server` turns them back into structures through the DataFixer and the template loader. Unlike a running world, that loader does not filter blocks by enabled features, so a block behind an experiment passes here and still loads as air in a world without the experiment. Block-entity NBT is kept as written until a structure is placed, so the job does not check it. The job fails when: - An example does not compile clean, meaning exit 0 with nothing on stderr, at every shipped target. An example with `@requires version>=1.21` fails at 1.20.4 with `E_VERSION_CAP`, and so does one that raises any warning. - A written file uses a key the game does not read, gives `pos` or `size` as anything but three `Int`s, or puts two blocks at one position. - The game reads a block, a property, the `DataVersion`, the `size`, the block count or the entity count differently from what was written, or writes no copy of a file. A block's line names the file and the cell. - The data generator logs an exception. It still exits 0 then, so the job reads its log. To run it locally, with Java 21 and network access to Mojang: ```sh cargo build -p cairn-lang-cli python3 .github/scripts/minecraft_load.py --cairn ./target/debug/cairn --target 1.21.4 ``` Leave out `--target` to check every shipped version. 1.21 and later need Java 21, so when the `java` on the `PATH` is older, pass a newer one with `--java `. The script downloads each server jar from Mojang, checks it against the SHA-1 Mojang publishes, and keeps it under `~/.cache/cairn-minecraft`. The jars are used under the Minecraft EULA and are never committed. The data generator writes no world, so it needs no `eula.txt`. ## Conventions for Rust code - **The spec is the source of truth.** When spec and implementation disagree, fix the implementation. If the spec is wrong, send a spec PR first. - **No linter-ignore directives.** `#[allow(clippy::…)]`, `#[allow(dead_code)]`, and friends are not allowed. If a lint fires, the design is the bug. Where a lint is wrong for one item, put `#[expect(lint, reason = "…")]` on that item alone. - **Lift the spec's terms verbatim.** `IntentState`, `ResolvedState`, `MatSlot`, `CanonicalToken`, `BlockArrayIr`. Do not invent parallel vocabulary. - **`missing_docs` is a warning everywhere.** Every public item gets a `///` line, and every crate a `//!` block. - **No Minecraft target constants.** The `(edition, version)` pair is a CLI parameter and must never appear in the language semantics ([Compilation Model §4.2](/spec/compilation#42-target-axes)). - **Errors carry the self-correction triple:** what is wrong / valid candidates / suggested fix ([Lint](/spec/lint/)). ## TDD discipline 1. **Design.** Read the relevant spec chapter and restate the slice you are implementing in plain prose. 2. **Acceptance criteria.** Write them as bullets, before any code. 3. **Tests.** Translate the ACs into `#[test]` functions. 4. **Implementation.** Make them pass. 5. **Iterate.** Keep tests and implementation in lockstep until green. The spec is compact enough that an acceptance-criteria list almost always fits in a few lines, so there is nothing to gain by skipping ahead. ## Adding a format backend Format support lives in `cairn-lang-formats`. A new file type needs a writer from the block-array IR to bytes. Importing it, the reverse direction, needs two more things, and no format has them yet: 1. A reader from bytes to the block-array IR. 2. An `(edition, version)` provenance stamp on import ([Ecosystem Interop §12.4](/spec/ecosystem-interop#124-import-stamping-and-pitfalls)). If you find yourself reaching into `cairn-lang-core` to add format-specific fields, format concerns are leaking into the block-array IR. Discuss it before merging. ## Adding redstone primitives The v1 vocabulary is closed ([Redstone §14.1](/spec/redstone#141-two-tiers-and-the-v1-boundary)): combinational gates plus `latch`, `pulse`, `delay`, `edge_rising`, `edge_falling`, and `counter`. Adding to it is a **spec change**. Open a spec PR with: - the new primitive's signal-graph semantics, - whether it is combinational or sequential, - the per-edition cell library entry it lowers to, - the truth-table, latency, and temporal assertions it must satisfy in the headless simulator ([Evaluation Framework §13.4](/spec/evaluation#134-redstone-verification)). ## Where to ask Open an issue against the relevant spec chapter. A question about implementation alone can point at the crate README instead. Design questions about vocabulary, IR shape, or error message wording belong against the spec.