This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.
Node
import std/nodeKoru Standard Library: node — a named, custody-owning index of cells.
node.kz · 12 tors
Koru Standard Library: node — a named, custody-owning index of cells. · 37 more lines
Phantom lifecycles
Derived from the phantom labels in the declarations below — state! issues an
obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.
Node carries the label <node> with no obligation attached — a dimension, not a lifecycle.
Cell carries the label <cell> with no obligation attached — a dimension, not a lifecycle.
// NODE-SELF — `std/node(node)`: borrow the node itself.
~pub tor node-self { node: string }
| node *Node<node>
| ?not-found// MEMBER / MEMBER-NAMED — `std/node(node.ID)`: borrow the member cell.
// `member` is the borrow-typed verb (inside a `| node f |` arm);
// `member-named` is the name-addressed surface `default` emits.
~pub tor member { f: *Node<node>, id: string }
| cell std/cell:*Cell<cell>
| held-by string
| not-found~pub tor member-named { node: string, id: string }
| cell std/cell:*Cell<cell>
| held-by string
| not-found// CELL-SPAWN — activate a cell under node custody. The user-facing verb is
// `spawn(f, id:, cell: <proto>)`, whose [pre] transform resolves the proto and
// rewrites here with `shape`/`shape_def` baked. `| spawned` yields the borrow
// so the caller can dispatch into it immediately.
~pub tor cell-spawn { f: *Node<node>, id: string, shape: string, shape_def: string }
| spawned std/cell:*Cell<cell>
| resident
| held-by string
| refused// EVICT — hibernate a cell: remove + `std/cell`'s destroy. The destroy
// discharges the cell obligation and releases whatever the cell still held —
// that is the point of routing teardown through here.
~pub tor evict { f: *Node<node>, id: string }
| evicted
| absent// COUNT — resident cells.
~pub tor count { f: *Node<node> } -> u32// DRAIN — shutdown: close every resident cell, retire the node's registry
// entry, and release everything the index allocated. A daemon runs nodes
// forever; a program that created one must drain it before exit — the leak
// check counts every byte the registry still holds.
~pub tor drain { f: *Node<node> } -> u32// NODE.SPAWN — `std/node:spawn(f, id: "room-42", cell: room_state)`: bind the
// shape at spawn. The `cell:` name resolves against the program's `std/proto`
// decls at transform time ([pre], like cell:open — decl sites still legible),
// its field block bakes into the `shape_def` manifest, and the call rewrites
// to `cell-spawn`. A spawn without `cell:` refuses — a node member IS a cell.
~[keyword|comptime|transform|pre] pub tor spawn {
expr: Expression,
cell: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
}
| spawned *
| resident
| refused// NODE.DEFAULT — `std/node(<target>)`: the borrow join. [pre] so the rewrite
// lands before `new` transforms away — the scan reads raw declaration sites.
//
// node → node-self(node) needs `| node f |`
// node.ID → member-named(node, "ID") needs `| cell c |` (+ `| not-found`)
// node[expr] → member-named(node, expr) needs `| cell c |` (+ `| not-found`)
~[keyword|comptime|transform|pre] pub tor default {
expr: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~part fleetretain koru_std/node.fleetretain.kz
Koru Standard Library: the `fleetretain` part of node — the fleet-event retention splice `node:new` needs. Joined via `~part fleetretain` in node.kz; merged into the node module at load. The fleet tors are called from HOST code — nothing in the program spells `std/fleet:claim`, so dead-strip retires the tors and `koru_fleet` would never emit. This splice is duplicated in `cell.retain.kz` ON PURPOSE: the transform's emitted handler runs inside the backend compiler, so its body must not reference `koru_fleet` — the module exists in that emit only because the retain already ran. Sharing this helper creates a bootstrap cycle.
~part new koru_std/node.new.kz
Koru Standard Library: the `new` part of node — the declaration machinery. `std/node:new` is comptime-only: it validates the name and options, retains the host-called surfaces, and rewrites to a `node-init` turn so the registry is populated at the point the declaration sat in source. Joined via `~part new` in node.kz. NODE-INIT — what `std/node:new` rewrites to. Void: the declaration is a statement, not a turn.
node-init
koru_std/node.new.kz:12// Koru Standard Library: the `new` part of node — the declaration
// machinery. `std/node:new` is comptime-only: it validates the name and
// options, retains the host-called surfaces, and rewrites to a
// `node-init` turn so the registry is populated at the point the
// declaration sat in source. Joined via `~part new` in node.kz.
//
// NODE-INIT — what `std/node:new` rewrites to. Void: the declaration is a
// statement, not a turn.
~pub tor node-init {
name: string,
scope: string,
world: string,
capacity: usize,
lease-ms: u64
}// NODE.NEW — `std/node:new(name, scope: "cell", world: "cells", capacity:
// N, lease-ms: T)` mints the name at comptime and rewrites to a
// `node-init` call. `lease-ms` is the TTL every claim this node makes
// carries (default 0 — un-leased): renewal is piggybacked on activity, so
// a dead node's cells become reclaimable when their deadlines pass.
~[keyword|comptime|transform] pub tor new {
expr: Expression,
invocation: *const Invocation,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
reporter: std/compiler:*ErrorReporter,
allocator: std.mem.Allocator
} -> SiteResult~part world koru_std/node.world.kz
Koru Standard Library: the `world` part of node — the shared-floor ownership boundary. Activation claims on the durable floor, retire is fenced by the record, and the `new` transform retains fleet's surface against dead-strip. Joined via `~part world` in node.kz; merged into the node module at load.
// RETIRE — the durable counterpart of `evict`: evict releases residency and
// the state file survives; retire deletes `<world_root>/<id>` outright —
// the cell stops existing anywhere. `| absent` only when nothing was there.
~pub tor retire { f: *Node<node>, id: string }
| retired
| held-by string
| absent