<!-- GENERATED by scripts/gen-llm-spec.ts — do not edit by hand. Run `npm run gen:spec`. -->

# ArchLang in one prompt

ArchLang is a tiny declarative language that compiles a `.arch` source file into a professional
floor-plan drawing. It is built for AI agents: deterministic (same source →
identical output) and self-correcting (every error carries a machine code and
a `fix`).

## The 7 rules that matter

1. **Units are millimetres.** A 4-metre wall is `4000`, not `4`. Suffixes fold to mm: `3.5m`=3500, `40cm`=400, `20mm`=20, `12ft6in`=3810, `1in`=25 (25.4 rounded half away from 0).
2. **Origin is top-left; +x goes right, +y goes DOWN** (screen/SVG convention — *not* math y-up).
3. **Coordinates are `(x, y)` tuples; sizes are `WxH`** or `<expr> x <expr>` with spaces.
4. **Doors and windows must lie ON a wall segment** (on its centerline), or you get a
   `W_DOOR_OFF_WALL` / `W_WINDOW_OFF_WALL` warning. Host them by rooms (below) or `on <wall> at <pos>` — hosted by construction.
5. **String interpolation is `"{expr}"`** inside double quotes.
6. **`id=` comes FIRST — right after the element keyword, before any category word** (`wall exterior id=w1 …` and `furniture bed id=b1 …` are parse errors). Ids are unique; omit `id=` to auto-generate one, and name a thing only when you reference it.
7. **Everything is expand-time and pure** — `let`/`for`/`if`/functions all evaluate during compile.

## Start here: rooms first

Write the rooms (a corridor is a room), let `walls from rooms` derive every wall, and host each
opening by the rooms it joins. This plan compiles and lints clean:

```arch
plan "Room graph" {
  units mm
  grid 100
  room id=living at (0,0) size 4000x4000 uses living
  room id=hall right-of living size 1500x4000 uses hall
  room id=bedroom right-of hall size 3000x4000 uses bedroom
  walls from rooms exterior 200 partition 100 { open between living and hall }
  door on hall.bottom at center width 900 swing into hall
  door between hall and bedroom at 800 from start width 800 swing into bedroom
  window on living.left width 1500
  window on bedroom.right width 1200
  furniture bed in bedroom anchor bottom-right flush size 1500x2000
}
```

To type some walls and derive others, name one by its rooms: `wall … between <A> and <B>`.

An L is one `room polygon` with only horizontal and vertical edges, and `walls from rooms` keeps it one room. Wrapped round a room it shares several edges, so a door must pick one by an edge meeting that run at an end: `door between liv and bed at 1500 from bed.top`. `at center` there is `E_OPENING_HOST_AMBIGUOUS`; its hint quotes the position. Its sides are its outermost runs: `right-of liv`, `liv.left`, `anchor left` read that run, never the box; a corner anchor needs a ring vertex; two runs on a side, `.cx`, `centered` refuse.

## Structure

```arch
plan "Title" {
  units mm  # required-ish settings come first
  grid 50  # snap grid
  paper A3 landscape  # OPTIONAL sheet: A4|A3|A2|A1|A0, landscape|portrait (landscape default)
  scale 1:50  # drawing scale
  north up  # up|down|left|right; `north|scale … hidden`, `title hidden`: no arrow, bar, box; facts stay, a freed band may fit a finer auto scale
  dims auto all  # OPTIONAL: overall|rooms|walls|all
  accTitle "…"  # OPTIONAL a11y name → SVG <title> under `compile --accessible`
  accDescr "…"  # …and description → <desc>, replacing the derived caption. Both plan-level only (E_ACC_PLACEMENT)
  height 3000  # OPTIONAL storey floor-to-floor — the VERTICAL DATUM, and it DRAWS NOTHING. Overridden per storey then per wall; never grid-snapped, E_HEIGHT_RANGE outside 0–100000, and an opening's `head` above its wall is E_OPENING_ABOVE_WALL. Defaults: 3000 storey, 2100 door head, 900/2100 window sill/head. `height <mm> clear <mm>`: a single-storey clear height (levels: E_CLEAR_SCOPE). `describe --json` reports `heights` (storey_height/elevation/per-wall) + `head`/`sill` on the openings, but ONLY if the source wrote one of these clauses somewhere
  sheet text { decimal "," total "SUMME" }  # OPTIONAL drawn words (keys: reference); not describe/lint
  # … elements and scripting …
  title { project "…" drawn_by "…" date "…" number "…" revision "…" }
}
```

**`paper` is what makes `scale` real.** Without it `scale` is just a title-block row and every
drawn size grows with the building. With `paper`, every annotation is a fixed number of
millimetres ON THE SHEET × the scale denominator. Write `paper` and omit `scale` to auto-fit the
finest of 1:50 / 1:100 / 1:200 / 1:500 that fits; declare both and a plan too big for the sheet
warns `W_SCALE_OVERFLOW` (your scale is never silently overridden). `arch describe --json`
reports the result as `sheet`. Big plan? `paper A1` + `dims auto all` is the professional default.

## Elements

```text
wall [id=…] <category> thickness <mm> [material poche|concrete|brick|insulation|tile|none [scale <n>] [angle <deg>]] [height <mm>] [status existing|demolish|new] { (x,y) (x,y) … [arc (x,y) radius <mm> [cw|ccw] [major]] … [close] } | between <A> and <B> | around [<A> …]  # category e.g. exterior/partition. An unlisted material is W_UNKNOWN_MATERIAL; `scale`/`angle`: either order, each once. `close` makes a loop. An `arc` clause makes THAT edge a circular arc from the PREVIOUS vertex (default: the minor arc turning `ccw` AS DRAWN, bulging left of travel; `cw`/`major` pick the other circle / the long way round; R < chord/2 = E_ARC_RADIUS). A closed curve is two arcs. Openings work: `on <wall> at <pos>` walks RUN length (an arc contributes R·θ, not its chord); `furniture … against wall` on an arc = E_FURN_AGAINST (use at+rotate). `between`/`around`: points from rooms (their shared edge; their outline, one ring cw from top-left vertex, no hole). `status demolish`: drawn; encloses, hosts (E_OPENING_ON_DEMOLISHED_WALL), measures nothing
room [id=…] at (x,y) size <W>x<H> [label "…" [at (x,y)]] [uses living|kitchen|dining|bedroom|bath|wc|hall|circulation|storage|utility|office|entry|garage …] [floor tile|paving|deck|concrete]  # `floor`: a hatch, drawn only. OR relational: room [id=…] (right-of|left-of|below|above) <roomId> [align <edge>] [gap <mm>] size <W>x<H> — align: top|middle|bottom after right-of|left-of, left|center|right after below|above (middle=center, both OK); wrong axis = E_ROOM_ALIGN_AXIS +fix, non-edge = E_ROOM_ALIGN. OR POLYGONAL: room [id=…] polygon (x,y)… — an implicitly-closed SIMPLE polygon (>=3 vertices): exact shoelace area, label at the centroid (pole of inaccessibility if outside). A crossing or all-collinear ring errors (E_ROOM_POLY_SELF_INTERSECT/E_ROOM_POLY_DEGENERATE); a slanted one REFUSES relational placement and `anchor` (E_PLACE_POLY): `at (x,y)` [+ rotate]. OR CIRCULAR: room [id=…] circle at (cx,cy) radius <mm> — area is EXACT πR², reported as `floor_circle`. DATUMS: a rectangular room r has r.top|bottom|left|right|cx|cy: numbers for walls, openings, furniture, dims; not in a `let` or a room's own at/size (E_DATUM_BEFORE_ROOMS). north|south|west|east only at a `north up` root (E_DATUM_COMPASS); circle, slanted polygon: E_ROOM_NOT_RECTANGLE
door [id=…] [hinged|sliding|barn|bifold|pocket|garage|double|glazed_sliding] (at (x,y) | on <wall|room.edge> at <pos> | between <A> and <B> at <pos>) width <mm> [wall <id|category>] [hinge left|right|near start|near end] [swing in|out|inward|outward|into <roomId>] [slide left|right] [open <0..1>] [head <mm>]  # <pos>: mm along the wall (an EXPRESSION; a `%` suffix ENDS it — parenthesise a modulo), `center`, `<mm> from start`/`end`/`<room>.<edge>` (to the CENTRE; start = smaller x/y, on a wall its first point), `axis <label>`; by rooms only the last three, required for a door. `between`: the wall on the rooms' shared edge; `on <room>.<edge>`: its exterior wall. There a jamb < max(100, t/2) from a meeting wall's face REFUSES (E_OPENING_NIB). `wall …` pairs with `at (x,y)` only (else PARSE ERROR). No kind = `hinged`; `double` = two leaves of width/2, one per jamb. Clauses BY KIND, any other of hinge/swing/slide/open REFUSES (E_DOOR_KIND_CLAUSE): hinged: hinge swing; sliding/pocket/glazed_sliding: slide open; barn/bifold: swing slide open; garage: none; double: swing; on an `arc` wall only hinged/double (E_DOOR_KIND_CURVED). `swing`: hinged/double = the side the leaf sweeps (`in` = RIGHT of the wall's drawn direction; `out` = LEFT: a south wall drawn `{ (0,4000) (6000,4000) }` with `swing out` opens INTO the building; so prefer `inward|outward` = towards/away from the one face with floor, E_SWING_SIDE if both or neither, or `into <room>`); barn/bifold = the FACE the panel hangs on / folds toward. `glazed_sliding`: half `width` passes; `width` = wall opening. `slide` reads along the wall like `hinge`; `open` is DRAWING-only (E_DOOR_OPEN_RANGE). A `pocket` needs its own width + clearance of wall past the slide-side jamb, or W_POCKET_RUN. A jamb nearer a wall CORNER than the wall's thickness: W_DOOR_NEAR_CORNER. No `sill`
window [id=…] [fixed|casement|tilt|tilt_turn|sliding] <placement as door, no between> width <mm> [wall <id|category>] [hinge left|right] [sill <mm>] [head <mm>]  # `hinge`: casement/tilt_turn only; omit if unknown. `on <room>.<edge>` may omit `at` (centre). No pier: `on r.top at corner r.right` + `on r.right at corner r.top`; `width` to the outer face. `sill`/`head` bound the glazing; `sill 0` is legal (floor-length), sill >= head is E_SILL_ABOVE_HEAD
opening [id=…] <placement as door> width <mm> [wall <id|category>] [head <mm>]  # a leaf-less cased opening that still connects the two spaces in the access graph. `head` defaults to the HOST WALL's height; no `sill`
furniture [id=…] <category> (at (x,y) | against wall <id|category> [segment <n>] [offset <mm>] [side left|right] | against <room>.<edge> [offset <mm>] | in <roomId> (centered | anchor <a> [flush] [inset <mm>])) [size <W>x<H>] [label "…"] [rotate 0|90|180|270 | facing <id>] [mirror] [clear front|sides <mm>] [in <roomId>]  # `at` size is plan W×H, a fixture's depth running AWAY from its wall (a WC is 400x700 on a N/S wall, 700x400 on E/W); `against` size is along×depth, `offset` = mm along the wall to the piece's CENTRE (default: midpoint); it derives position+rotation (`side` inferred from `in <roomId>`); `rotate` is `at`/`in`-only (E_FURN_AGAINST; multi-segment wall ⇒ `segment <n>`, or `segment north|…` (closed ring, outward face; north-up root only) or `segment containing r.left`; not exactly one match = E_SEGMENT_SELECT). `against` may omit `size` for these + aliases (catalogued footprint): wc/basin/shower/bathtub/kitchen_sink/counter/stove/fridge/bed/double_bed/nightstand/wardrobe/tv_unit/bookshelf/dishwasher/upper_cabinet/washer/dryer/sofa_l/hedge/bbq/bin/mailbox/ev_charger/shed/bidet/urinal/laundry_sink/water_heater/mirror/range_hood/microwave/bar_counter/bunk_bed/crib/dresser/vanity/fireplace/radiator/sideboard/loveseat/chaise/tv/coat_rack/shoe_cabinet/meeting_table/reception_desk/filing_cabinet/locker/pool_table/treadmill/floor_lamp/side_table/console_table/ottoman/pantry/towel_rail/flower_bed/picnic_table/slide/bollard/bike_rack/raised_bed/whiteboard/printer/server_rack/hospital_bed. `anchor <a>` is top-left|top|top-right|left|center|right|bottom-left|bottom|bottom-right; `inset` (default 0) pulls it in from that edge, measured from the room rectangle (a wall CENTERLINE); `flush` measures from the backing wall's inner FACE instead (needs an anchored edge: E_FURN_FLUSH on `centered`/`anchor center`). `facing <id>` (a piece, rect room or opening) derives the turn whose front (rotate 0 = back north) points at it; no hit = E_FACING_MISS. A chair at a table facing away: W_SEAT_FACING_AWAY. `clear` = depth to keep free, lint-checked. `mirror`: left↔right, back stays
dim [faces|clear] (x,y)->(x,y) [offset <mm>] [text "…"]  # `offset` defaults to 300 (0 on the curve forms). Endpoint ORDER + the offset sign choose which side it lands on (the offset runs along the LEFT normal of from→to), so a reversed pair draws it INSIDE the building — `W_DIM_INSIDE`. `faces` pushes each endpoint out onto the wall it runs into (outside-to-outside); `clear` pulls both in to the inner faces. `dims auto all` instead draws dimension chains outside the building. CURVES: `dim radius <wallId> [segment <n>]` (an R leader) and `dim diameter <roomId>` (a φ call-out) DERIVE both geometry and text from the named element and also take `[offset <mm>] [text "…"]`; `dims auto` adds one R per distinct arc + one φ per circular room; chains skip curved/angled facades, so an opening there is W_OPENING_NOT_DIMENSIONED until you `dim` it
column [id=…] at (x,y) size <W>x<H>
stair [id=…] at (x,y) size <W>x<H> dir up|down [width <mm>]  # a flight. `at` = footprint TOP-LEFT; the flight runs along the LONG axis; `dir up` is entered at that axis's larger-coordinate end (arrow points N/W), `dir down` at the opposite end (arrow S/E). A stair has that ONE entry; to swap ends, draw it at (0,0) in a `component` and `place` it `mirror y` if portrait (`dir up` entered from the north; `at` = its bottom-left), `mirror x` if landscape (from the west; `at` = its top-right). `dir` is declared per storey. MULTI-STOREY (`elevator`, `escalator` too): the SAME id on two `level` blocks is ONE SHAFT — a `describe().vertical` connection: from a room you can reach, it reaches the other storey with no front door (an id on one storey only = `W_STAIR_UNMATCHED`). OR TURNING: stair [id=…] dir up|down width <mm> { flight at (x,y) size <W>x<H> landing at (x,y) size <W>x<H> flight … } — pieces in climbing order on every storey, each touching the next; a landing replaces one going (E_STAIR_PIECES). A quarter-turn landing exactly `width` × `width` may end `winders <2–8>`: that many tapered steps fanning from its inner corner, each one going (never a helix)
elevator [id=…] at (x,y) size <W>x<H>  # a lift shaft
escalator [id=…] at (x,y) size <W>x<H> dir up|down  # a moving stair; both narrow ends are entries
roof (overhang <mm> [wall <id>] | polygon (x,y)…)  # the eaves line: ONE outline of what oversails. DRAWING-ONLY, though it grows the page. `overhang` offsets a CLOSED wall ring outward by thickness/2 + <mm>, mitred: the named `wall`, else the plan's one closed `exterior` wall (none/several = E_ROOF_AMBIGUOUS, unknown/unclosed = E_ROOF_WALL, <= 0 = E_ROOF_OVERHANG). REFUSES rather than approximating — an `arc` edge is E_ROOF_CURVED, an offset that crosses itself E_ROOF_SELF_INTERSECT — so write `polygon` instead: the ring verbatim, implicitly closed, >= 3 effective vertices (E_ROOF_POLY_DEGENERATE). Not inside a `component` (E_ROOF_PLACEMENT)
void [id=…] (at (x,y) size <W>x<H> | polygon (x,y)…) [rail …]  # a hole in THIS storey's floor (stair well, atrium, double-height room), `at` = TOP-LEFT. It OBSTRUCTS circulation (not walkable; its edge is) and does NOT reduce the containing room's area; `describe --json`'s `voids[]` gives the extent (`area_m2` on a polygon) to subtract. polygon: only horizontal/vertical edges (E_VOID_POLY). rail: a balustrade on the named edges, sides (rectangle) or 0-based numbers, n = point n→n+1 (polygon), all|none; omit the stair's arrival edge (E_VOID_RAIL). E_VOID_SIZE
outdoor [id=…] lawn|planting|paving|deck|gravel|water|driveway|patio|balcony (at (x,y) size <W>x<H> | polygon (x,y) (x,y) (x,y) …) [label "…"] [rail top|bottom|left|right|all|none …]  # GROUND outside the building. NOT a room — absent from `rooms[]`, `totals.floor_area_m2`, `schedule rooms`, the access graph and Plan JSON — and it obstructs NOTHING (water included). Its facts are `describe --json`'s `outdoor[]` + `totals.outdoor_area_m2`, area by exact shoelace on the ring form. `label` draws the name AND the m²; unlabelled ground draws neither. `rail` is `balcony`-only (E_OUTDOOR_RAIL) and rectangle-only (E_OUTDOOR_POLY_DEGENERATE); omitted, it is DERIVED — every edge with no wall one thickness behind it. W_OUTDOOR_OVERLAPS_ROOM covers a surface over a room's floor, W_BALCONY_NO_DOOR a balcony with no opening within a wall thickness. It grows the page, so a site plan wants `paper` (E_OUTDOOR_SIZE, E_OUTDOOR_POLY_SELF_INTERSECT)
fence [id=…] [picket|panel|post] { (x,y) (x,y) … [close] }  # a posted boundary line; the style word defaults to the first. NOT a thin wall: no thickness, no poché, hosts NO opening, absent from `describe().walls` and the access graph (a gate is deferred by name). It measures (`fences[]`: `length_mm` + `closed`) and grows the page. An `arc` edge is E_FENCE_CURVED — write short straight runs
walls from rooms exterior <mm> partition <mm> [status <s>] [{ except <room>… | open [id=] between <A> and <B> [width <mm>] | between … thickness <mm> }]  # a ring + a partition per shared edge (`open`: an opening across it, centred; else `opening between`); rooms: rectangles or rectilinear polygons tiling one floor. Openings: never `on <wall>`
section <name|int> (x,y)->(x,y) look north|south|east|west  # plan level only, drawn on the lowest storey: a horizontal or vertical cut, looking across it. `describe` adds `sections[]` (`toward`: the page direction)
strip <right|left|down|up> at (x,y) gap <mm> [height|width <mm>] { room [id=…] size <main>[x<cross>] [label "…"] [uses …] … }  # a row/column of rooms laid end to end: each room's offset is the running sum of the previous extents + gap, and the shared cross dimension is the strip's height (right/left) or width (down/up). Pure sugar — expands to absolute rooms. Plan-level block only
level <int> ["Name"] [height <mm>] [slab <mm>] [clear <mm>] { … }  # ONE STOREY = one whole drawing. `height` in the body: E_LEVEL_MIX; `heights.elevation` ACCUMULATES the storeys below, so it is NOT level × height. `slab`: floor build-up UNDER this storey; `clear`: its clear height. Neither draws; `heights` adds `slab`, `clear_height` (the `clear`, else height − slab above) or `clear_height_omitted`; W_CLEAR_HEIGHT_MISMATCH. A plan is single-storey or ALL levels (a drawable statement beside them = E_LEVEL_MIX); settings/`component`/`import`/plan-global `let`/`set` stay OUTSIDE, applying to every level. Integers, unique, 0/negative legal, ASCENDING — lowest = page 1. Ids unique WITHIN a level (see `stair`). `arch compile` writes plan.L1.svg, plan.L2.svg … (`--level <n>` = one); `describe --json` adds `levels[]`. Plan-level only
zone <id> ["Label"] { … }  # a WING/DEPARTMENT grouping, pure metadata: every statement inside resolves as if the wrapper were deleted. Membership is DECLARED, never inferred from position. Nests (`zone west { zone galleries { … } }` → path `west.galleries`, innermost wins) and is legal wherever a statement is, incl. inside `level`. `describe --json` adds `zones[]` (path/rooms/floor_area_m2; nested rooms roll UP, so summing zones double-counts) + `describe --zone <path>` to read one wing
place <component>(<args>) as <name> at (x,y) [rotate 0|90|180|270] [mirror x|y]  # instantiate a component as an ADDRESSABLE instance, authored in LOCAL coords from (0,0). Ids inside become `<name>.<id>` (auto-ids restart per instance) and the plan addresses them dotted — `door on west.perimeter at 50%`, `describe --room west.main`. `mirror x` flips left↔right, `y` top↔bottom: a real reflection, so door swings mirror. `import "wing.arch" as wing` makes a WHOLE FILE a zero-arg component. Bare `<component>(<args>)` stays the old INLINE macro — caller's coords and id space, no namespace
axes { x at <mm>, <mm>, … y at <mm>, <mm>, … }  # GB/T 50001 positioning axes (定位轴线): datum lines. `x` are vertical (numbered 1,2,3… left-to-right), `y` horizontal (lettered A,B,C… BOTTOM-to-top, skipping I/O/Z). Positions are expressions. Plan-level; statements read `axis.3`, `axis.B` as coordinates (no arithmetic in an opening's `at`), not in a `let`/`place`/component
schedule rooms|openings  # DERIVED tables, either or both. `rooms [net]`: each room's NAME (label, else id), AREA, NET AREA + TOTALs = `describe --json`'s `schedule[]`, grouped by `zone` with SUBTOTALs; `net` also stamps each room. `openings`: D01…/W01… tags + a DOOR & WINDOW SCHEDULE
legend  # draw the LEGEND table, derived from what the plan uses
site { street north|south|east|west [hemisphere north|south] [boundary (x,y) (x,y) (x,y) …] }  # `street`/`hemisphere` draw NOTHING; `boundary` is the LOT LINE, which grows the page, adding `site.lot_area_m2` (exact shoelace) + `site.lot_bbox` (E_SITE_BOUNDARY_DEGENERATE, E_SITE_BOUNDARY_SELF_INTERSECT). `street` is a TRUE compass direction (read WITH `north`, not instead of it) and names five on `describe --json`'s `site`: `street`, `back` (opposite), `equator_side` (S north of the equator, N south of it), `sunrise_side` (E), `sunset_side` (W). An intent's `windows.facing` may assert those NAMES instead of a letter (no `site` = E_INTENT_NO_SITE). They are a DRAFTING HEURISTIC for an aspect: there is no sun model. `street` required (E_SITE_NO_STREET), one block (E_SITE_DUP), plan-level only
notes "…" ["…" …]  # a numbered NOTES table; repeats append. Drawing-only, like `legend` and title `number`/`revision`
keep (align <d>… | equal width|depth <id>… | offset <d|id> from <d> <mm> | min clear <room> <mm> | on axis <label> <wall|column> | stacked <room|stair|elevator|void> on levels <n>… | fixed <d> at <mm>) [hard|soft|advisory]  # CHECKED, never solved: draws/moves nothing. <d>: r.left…, axis <label>, straight wall; authored ids; stacked: plan root; others in their level. Broken: hard (default) W_KEEP_VIOLATED ±mm, fails --strict; soft in next; advisory in describe/validate/impact
```

## Scripting

- `let NAME = expr` — bind a constant. `NAME = expr` — reassign an existing binding
  (**deprecated**: `W_REASSIGN_DEPRECATED`; bind a new name instead).
- `let f(a, b) = expr` — a pure value-function; only yours and the built-ins are callable: `min max abs sqrt floor ceil round len str`.
- `for i in lo..hi { … }` — loop over a half-open integer range.
- `if cond { … } else { … }` · `while cond { … }` (**deprecated**: `W_WHILE_DEPRECATED`;
  use `for` instead).
- `set <element>(attr: value)` — scoped default for following elements.
- Arrays: `[a, b, c]`, indexed `arr[i]`. Operators: `+ - * / %`, `== != < > <= >=`, `&& ||`. Comments: `# …`.
- `import "lib/x.arch": name` and `component name(args) { … }` for reuse.
- `theme blueprint|mono|dark|presentation|rendered` — a named palette base. `theme [<name>] { key: value }` overrides single keys, `theme from "#rrggbb"` derives the whole palette from one colour, and `style <kind> { key: value }` does the same per element kind (any but `opening`, `walls`). An unknown key WARNS and is dropped (`W_UNKNOWN_THEME_KEY`/`W_UNKNOWN_STYLE_KEY`).

## Keyword reference

- **Enums / values not shown above:** `true`

## CLI loop

Every command takes `--json` (structured result on **stdout**, human messages on **stderr**) and
reads source from a file or stdin (`-`). Exit codes: `0` ok · `1` internal / IO error · `2` user-source error (deterministic — fix it, don't blindly retry) · `3` bad usage · `4` stale source: the file is not the revision --expected-hash names (re-read it, redo the edit).
In a shell, every `arch` in this spec means `archlang` (or `npx -y @chanmeng666/archlang`): coreutils owns `arch` on Linux, macOS and Git Bash.

```text
arch compile  # render a plan to SVG/DXF/TXT/PDF/PNG, or to Plan JSON
arch batch  # render many .arch files in one call, concurrently
arch md  # render every ```arch block in a Markdown file and rewrite to image links
arch preview  # render a PNG you can look at (zero-install where the optional binary is present)
arch link  # print a playground URL that opens the plan, rendered, with nothing to install
arch watch  # recompile on save (interactive)
arch validate  # parse + resolve + lint, no render (is it valid & sound?)
arch describe  # semantic facts: rooms, areas, adjacency, what doors connect
arch takeoff  # quantities as csv or md
arch score  # continuous intent satisfaction (satisfied/total) as data — the refine-loop reward — or, with --taste, the plan's taste score
arch lint  # architectural soundness warnings
arch ast  # parse only (no resolve/render) and print the span-bearing AST as JSON
arch complete  # completion items in scope at a source byte offset (the LSP completion() core)
arch fmt  # canonical formatting
arch repair  # explicit source-to-source corrector (furniture out of walls) + change log
arch fix  # apply the machine-applicable fix suggestions on a plan's diagnostics (bounded fixpoint)
arch finish  # furnish the rooms that hold no furniture, then add the sheet statements a plan lacks (paper, scale, dims auto, title, schedule rooms, legend); deletes nothing
arch reroll  # offer a proven-equivalent `for` loop for a repeated statement run
arch impact  # change one number: what moved and why, what held, what broke
arch suggest  # advisory door/window statements for unreachable or windowless rooms
arch manifest  # this document: the whole CLI API as structured data
arch spec  # print the one-prompt language spec (spec.llm.md)
arch context  # print the full bundled agent context (spec + workflow + CLI + errors)
arch new  # scaffold a starter .arch
arch import  # convert an OpenPlan3D plan (JSON) to .arch source, reporting what it left out
arch explain  # look up an error code (cause / fix / example)
```

The flags that matter:

```bash
arch compile plan.arch -o out.svg --json  # JSON: { ok, diagnostics, summary }. -f txt = zero-dep ASCII plan, dxf = blocks
arch validate plan.arch --strict --json  # ship-gate: --strict fails on warnings too
arch fix plan.arch --dry-run --json  # preview
arch validate plan.arch --intent brief.json --feedback --json  # gate on a brief's intent contract (miss → exit 2)
arch score plan.arch --brief brief.json --json  # or --taste generic (0–1); measures, never gates
arch impact new.arch --against old.arch --lock a,b
```

**Self-correction loop:** compile → `validate --json` (fix its `next` first) → lint → repair; author in stages: `validate --stage rooms|walls|openings|fixtures` in turn, advancing when `at_stage.clean`. If
`ok` is false, read each `diagnostics[].fix` (and `line`/`col`/`span`), edit the source, recompile.
Then `describe --json` to confirm intent without rendering an image (floor area: `net_area_m2`; `area_m2` runs to wall centrelines).

**Fix topology from facts, not guesses.** `arch repair` never adds a door or
window. When lint reports `W_ROOM_UNREACHABLE`, `W_NO_ENTRANCE`,
`W_BEDROOM_NO_WINDOW`, or `W_BATH_VIA_BEDROOM`, run `arch suggest --json` — ready to paste,
each with a rationale. If nothing fits, read
`describe --json` (`access.rooms[].reachable`, room `bbox`/`adjacent`, building extent =
min/max of room boxes) and attach the opening yourself — an exterior entrance into a cut-off living
space beats routing a bath through a bedroom — then re-`repair`. Full recipe:
`archlang context --section workflow`.

## Common mistakes

| Mistake | Fix |
| --- | --- |
| Furniture floated at a guessed `at`, or an `inset` hand-computed from a wall thickness | Place it `in <room> anchor <9-point> [flush] [inset]` or `against wall <id>` — closed-form, never names a thickness. |

## Worked examples

### `examples/parametric.arch`

```arch
# Parametric plan (v0.8 scripting): a row of studio units generated with a
# `for` loop over a range, a value-function, an array indexed per unit, a scoped
# `set` rule, an `if`, and string-interpolated labels. Everything is derived
# from the constants — change COUNT and the whole row regenerates.
plan "Parametric — Studio Row" {
  units mm
  grid 50
  scale 1:100
  north up

  # Plan-level constants (visible everywhere below — plan scope is global).
  let WALL  = 200
  let W     = 4000          # unit width
  let H     = 5000          # unit depth
  let DOOR  = 900
  let WIN   = 1600
  let COUNT = 3             # number of units

  # A value-function (pure closure) — area in square metres.
  let aream2(w, h) = w * h / 1000000

  # Per-unit names, indexed by the loop variable.
  let names = ["Studio A", "Studio B", "Studio C"]

  # Entrance doors swing outward throughout this plan (scoped default).
  set door(swing: out)

  for i in 0..COUNT {
    let x = i * W
    wall exterior thickness WALL { (x, 0) (x + W, 0) (x + W, H) (x, H) close }
    room at (x, 0) size W x H label "{names[i]}"
    furniture bed   at (x + 300, 300)      size 1500x2000 label "Bed"
    furniture kitch at (x + W - 1900, 300) size 1600x600  label "Kitchen"
    door   at (x + W / 2, H) width DOOR wall exterior hinge left
    window at (x + W - 1100, 0) width WIN  wall exterior

    # The end unit carries a per-unit area dimension (computed by the function).
    # Referenced to the outer face (y = H + WALL/2) so the extension lines start at
    # the wall and read downward, away from the building.
    if i == COUNT - 1 {
      dim (x, H + WALL / 2)->(x + W, H + WALL / 2) offset 600 text "{aream2(W, H)} m² each"
    }
  }

  # Overall run, dimensioned above the building: right-to-left so the offset lands
  # ABOVE the row (outside), and referenced to the outer top face (y = -WALL/2).
  dim (W * COUNT, 0 - WALL / 2)->(0, 0 - WALL / 2) offset 1300 text "{COUNT} units"
}
```
