[
 {
  "name": "concat",
  "category": "string",
  "signature": "concat(a, b) -> String | concat(a: List, b: List) -> List",
  "brief": "Concatenate strings, or join two lists (numeric list `+` is elementwise, so this is THE list concat).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "pad_left",
  "category": "string",
  "signature": "pad_left(s, width: Int, fill?: String) -> String",
  "brief": "Left-pad to `width` characters: pad_left(\"7\", 4, \"0\") = \"0007\". Default fill is a space.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "pad_right",
  "category": "string",
  "signature": "pad_right(s, width: Int, fill?: String) -> String",
  "brief": "Right-pad to `width` characters.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "split",
  "category": "string",
  "signature": "split(s: String, delim: String) -> List<String>",
  "brief": "Split a string on a delimiter into a list of substrings.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "replace",
  "category": "string",
  "signature": "replace(s: String, old: String, new: String) -> String",
  "brief": "Replace every occurrence of `old` with `new`.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "contains",
  "category": "string",
  "signature": "contains(haystack: String, needle: String) -> Bool | contains(list: List, x) -> Bool | contains(m: Map, key) -> Bool",
  "brief": "Substring test; list membership (structural equality); map key membership.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "starts_with",
  "category": "string",
  "signature": "starts_with(s: String, prefix: String) -> Bool",
  "brief": "True if `s` begins with `prefix`.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "ends_with",
  "category": "string",
  "signature": "ends_with(s: String, suffix: String) -> Bool",
  "brief": "True if `s` ends with `suffix`.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "lowercase",
  "category": "string",
  "signature": "lowercase(s: String) -> String",
  "brief": "Lowercase the string (non-strings are stringified first).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "uppercase",
  "category": "string",
  "signature": "uppercase(s: String) -> String",
  "brief": "Uppercase the string (non-strings are stringified first).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "trim",
  "category": "string",
  "signature": "trim(s: String) -> String | trim(s: String, chars: String) -> String",
  "brief": "Strip leading and trailing whitespace — or any of the characters in `chars` (Go's strings.Trim(s, cutset)).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sha256",
  "category": "string",
  "signature": "sha256(s: String) -> String",
  "brief": "SHA-256 of the text, as 64 hex characters (store `sha256(salt + password)` or better an hmac_sha256 with a server secret, never the password).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "hmac_sha256",
  "category": "string",
  "signature": "hmac_sha256(key: String, message: String) -> String",
  "brief": "HMAC-SHA-256 as hex: sign a session cookie or a webhook payload with a server secret.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "random_token",
  "category": "string",
  "signature": "random_token(bytes?: Int) -> String",
  "brief": "Cryptographically secure random bytes from the OS, as hex (default 32 bytes = 64 characters): session tokens, API keys, salts. random() is NOT for secrets.",
  "deterministic": false,
  "replay": "nondeterministic: replay reports it as a divergence source"
 },
 {
  "name": "secure_eq",
  "category": "string",
  "signature": "secure_eq(a: String, b: String) -> Bool",
  "brief": "Constant-time equality for secrets (tokens, signatures): `==` returns early and leaks a prefix by timing.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "format",
  "category": "string",
  "signature": "format(fmt: String, args...) -> String",
  "brief": "printf subset: %d %s %f %.2f %8.2f %e %.3e %3d %-8s %05d %% — %e is C-style scientific (6.022000e+23); widths, precision (rounded half away from zero on the decimal text), left-align with '-', zero-pad with '0'.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "to_fixed",
  "category": "math",
  "signature": "to_fixed(x: Float, digits: Int) -> String",
  "brief": "x with exactly `digits` decimals (\"%.2f\"), rounded half away from zero on the decimal text: to_fixed(1.005, 2) = \"1.01\".",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "div_round",
  "category": "math",
  "signature": "div_round(n: Int, d: Int) -> Int",
  "brief": "Exact integer division rounded to the nearest, half away from zero (BigDecimal HALF_UP): div_round(10125 * 600, 120000) == 51, div_round(-7, 2) == -4. Money in cents stays exact.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "floor_div",
  "category": "math",
  "signature": "floor_div(a: Int, b: Int) -> Int",
  "brief": "Division rounded toward -∞ (Ruby/Python `//`): floor_div(-150, 100) = -2. `idiv` truncates toward zero; `/` is exact.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "mod",
  "category": "math",
  "signature": "mod(a: Int, b: Int) -> Int",
  "brief": "Modulo with the DIVISOR's sign (Ruby/Python `%`): mod(-150, 100) = 50. The `%` operator keeps the dividend's sign (C/Rust): -150 % 100 = -50.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "divmod",
  "category": "math",
  "signature": "divmod(a: Int, b: Int) -> [q, r]",
  "brief": "[floor_div(a, b), mod(a, b)] — q * b + r == a with 0 <= r < |b|.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "parse_date",
  "category": "time",
  "signature": "parse_date(s: \"YYYY-MM-DD\") -> {year, month, day, weekday, epoch_day}",
  "brief": "Strict ISO date to its parts (weekday 1 = Monday); raises kind \"date\" otherwise.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "add_days",
  "category": "time",
  "signature": "add_days(date: String, n: Int) -> String",
  "brief": "The ISO date n days later (negative n goes back), across month and year ends.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "add_months",
  "category": "time",
  "signature": "add_months(date: String, n: Int) -> String",
  "brief": "Same day n months later, clamped to the month's length (Ruby's Date >> n): add_months(\"2026-01-31\", 1) = \"2026-02-28\".",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "days_between",
  "category": "time",
  "signature": "days_between(a: String, b: String) -> Int",
  "brief": "Days from a to b (negative when b is earlier).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "months_between",
  "category": "time",
  "signature": "months_between(a: String, b: String) -> Int",
  "brief": "Whole months from a to b (\"YYYY-MM-DD\"), day-of-month aware like java.time MONTHS.between: 2026-01-15 → 2026-04-14 is 2, → 2026-04-20 is 3.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "days_in_month",
  "category": "time",
  "signature": "days_in_month(year: Int, month: Int) -> Int",
  "brief": "28–31, leap years included.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "fields",
  "category": "string",
  "signature": "fields(s: String) -> List<String>",
  "brief": "Split on any run of whitespace, no empty pieces (Go's strings.Fields; split(s, \" \") keeps empties).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "index_of",
  "category": "string",
  "signature": "index_of(s: String, sub: String) -> Int  |  index_of(xs: List, x) -> Int",
  "brief": "Character index of the first occurrence of `sub` in a String, or the position of the first element equal to `x` in a List; -1 if absent.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "substring",
  "category": "string",
  "signature": "substring(s: String, start: Int, end: Int) -> String",
  "brief": "Character-based slice [start, end) — both indexes are clamped to 0..len(s), end exclusive. A negative end gives an empty string; use slice() for indexes relative to the end.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "escape_html",
  "category": "string",
  "signature": "escape_html(s: String) -> String",
  "brief": "Escape &, <, >, double and single quotes for safe HTML embedding.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "str_len",
  "category": "string",
  "signature": "str_len(s: String) -> Int",
  "brief": "Byte length of a string (cf. len(), which counts characters).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "str_at",
  "category": "string",
  "signature": "str_at(s: String, i: Int) -> Int",
  "brief": "Byte value at index `i`; errors if out of range.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "str_eq",
  "category": "string",
  "signature": "str_eq(a: String, b: String) -> Bool",
  "brief": "Exact string equality (fast path for [native] code).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "len",
  "category": "types",
  "signature": "len(x: String|List|Map) -> Int",
  "brief": "Characters of a string, elements of a list, or entries of a map.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "to_string",
  "category": "types",
  "signature": "to_string(x) -> String",
  "brief": "Render any value with its display formatting.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "to_int",
  "category": "types",
  "signature": "to_int(x) -> Int",
  "brief": "Convert to Int (floats truncate, strings parse, BigInt-exact); returns () on failure.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "to_float",
  "category": "types",
  "signature": "to_float(x) -> Float",
  "brief": "Convert to Float; returns () if a string fails to parse.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "to_json",
  "category": "types",
  "signature": "to_json(x) -> String",
  "brief": "Serialize a value as JSON (strings escaped, NaN/inf become null).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "from_json",
  "category": "types",
  "signature": "from_json(s: String) -> Any",
  "brief": "Parse a JSON string into a Map/List/scalar; maps and lists pass through. Invalid JSON RAISES (kind \"json\") — wrap LLM output in try { from_json(s) }.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "type_of",
  "category": "types",
  "signature": "type_of(x) -> String",
  "brief": "Type name: \"Int\" (any size), \"Float\", \"String\", \"Bool\", \"List\", \"Map\", \"Function\", \"Variant\", or \"Unit\".",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "is_type",
  "category": "types",
  "signature": "is_type(value: Map, type_name: String) -> Bool",
  "brief": "True if a record's `_type` field equals `type_name`.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "is_a",
  "category": "types",
  "signature": "is_a(value: Map, type_name: String) -> Bool",
  "brief": "Alias of is_type.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "abs",
  "category": "math",
  "signature": "abs(x: Int|Float) -> Int|Float",
  "brief": "Absolute value, arbitrary precision (abs(-9223372036854775808) is 9223372036854775808).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "round",
  "category": "math",
  "signature": "round(x: Float) -> Int | round(x: Float, digits: Int) -> Float",
  "brief": "Round half away from zero to the nearest integer, or keep `digits` decimals: round(2.345, 2) = 2.35.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "floor",
  "category": "math",
  "signature": "floor(x: Float) -> Int",
  "brief": "Largest integer <= x.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "ceil",
  "category": "math",
  "signature": "ceil(x: Float) -> Int",
  "brief": "Smallest integer >= x.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sqrt",
  "category": "math",
  "signature": "sqrt(x: Int|Float) -> Float",
  "brief": "Square root.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sin",
  "category": "math",
  "signature": "sin(x: Int|Float) -> Float",
  "brief": "Sine (radians). Also cos, tan, atan, atan2(y, x).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "cos",
  "category": "math",
  "signature": "cos(x: Int|Float) -> Float",
  "brief": "Cosine (radians).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "tan",
  "category": "math",
  "signature": "tan(x: Int|Float) -> Float",
  "brief": "Tangent (radians).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "atan",
  "category": "math",
  "signature": "atan(x: Int|Float) -> Float",
  "brief": "Arc tangent.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "atan2",
  "category": "math",
  "signature": "atan2(y: Float, x: Float) -> Float",
  "brief": "Arc tangent of y/x, quadrant-aware.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "asin",
  "category": "math",
  "signature": "asin(x: Float) -> Float",
  "brief": "Arc sine (x in [-1, 1], else kind range).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "acos",
  "category": "math",
  "signature": "acos(x: Float) -> Float",
  "brief": "Arc cosine (x in [-1, 1], else kind range).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "pi",
  "category": "math",
  "signature": "pi() -> Float",
  "brief": "The constant π.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "log",
  "category": "math",
  "signature": "log(x: Int|Float) -> Float",
  "brief": "Natural logarithm.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "ln",
  "category": "math",
  "signature": "ln(x: Int|Float) -> Float",
  "brief": "Alias of log (natural logarithm).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "exp",
  "category": "math",
  "signature": "exp(x: Int|Float) -> Float",
  "brief": "e raised to the power x.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "log10",
  "category": "math",
  "signature": "log10(x: Int|Float) -> Float",
  "brief": "Base-10 logarithm.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "pow",
  "category": "math",
  "signature": "pow(base: Int|Float, exp: Int|Float) -> Float",
  "brief": "base raised to exp (always a Float; `ipow` for an exact Int power).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "ipow",
  "category": "math",
  "signature": "ipow(base: Int, exp: Int) -> Int",
  "brief": "Exact Int power (exp ≥ 0; kind range past the Int size limit). `to_int(pow(3, 40))` is off by 33, `ipow(3, 40)` is exact.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "min",
  "category": "math",
  "signature": "min(a, b) -> Int|Float | min(list: List) -> Int|Float",
  "brief": "Smaller of two numbers, or the minimum of a list (Float if any element is). An empty list gives () (no minimum exists).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "max",
  "category": "math",
  "signature": "max(a, b) -> Int|Float | max(list: List) -> Int|Float",
  "brief": "Larger of two numbers, or the maximum of a list (Float if any element is). An empty list gives () (no maximum exists).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sum",
  "category": "math",
  "signature": "sum(list: List) -> Int|Float",
  "brief": "Sum of a list of numbers (Int-exact unless any element is a Float); 0 when empty. Floats are added left to right without compensation (NumPy's pairwise / Python's fsum can differ in the last bits).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "product",
  "category": "math",
  "signature": "product(list: List) -> Int|Float",
  "brief": "Product of a list of numbers; 1 when empty.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "avg",
  "category": "math",
  "signature": "avg(list: List) -> Int|Float",
  "brief": "Mean of a list of numbers: finite operands are averaged exactly before Float rounding, avoiding intermediate overflow and cancellation. An exact mean of Ints stays an Int; () when empty.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "parse_int",
  "category": "math",
  "signature": "parse_int(s: String, base: Int?) -> Int | ()",
  "brief": "Strict integer parse: () unless the WHOLE string is an integer (\"1.5\", \"12abc\", \"\" → ()). parse_int(\"ff\", 16) = 255 (base 2..36, no 0x prefix). to_int() is lenient and truncates.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "parse_float",
  "category": "math",
  "signature": "parse_float(s: String) -> Float | ()",
  "brief": "Strict float parse: () unless the whole string is a finite number.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "idiv",
  "category": "math",
  "signature": "idiv(a: Int, b: Int) -> Int",
  "brief": "Integer division truncating toward zero; errors on division by zero.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "clamp",
  "category": "math",
  "signature": "clamp(v, lo, hi) -> Int|Float",
  "brief": "Constrain numeric v to [lo, hi] using exact Int/Float comparisons; return the selected operand with its type. Reject nonnumeric operands, reversed bounds and NaN bounds; a NaN value stays NaN.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "random",
  "category": "math",
  "signature": "random() -> Float | random(max: Int) -> Int | random(min: Int, max: Int) -> Int",
  "brief": "Time-seeded PRNG: float in [0,1), or int in [0,max) / [min,max). There is no seed: for reproducible runs write your own generator (an LCG over Ints), and for secrets use random_token().",
  "deterministic": false,
  "replay": "nondeterministic: replay reports it as a divergence source"
 },
 {
  "name": "gcd",
  "category": "math",
  "signature": "gcd(a: Int, b: Int) -> Int",
  "brief": "Greatest common divisor (Euclid, absolute values).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sqrt_int",
  "category": "math",
  "signature": "sqrt_int(n: Int) -> Int",
  "brief": "Integer square root; errors on negative input.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "pow_mod",
  "category": "math",
  "signature": "pow_mod(base: Int, exp: Int, m: Int) -> Int",
  "brief": "Modular exponentiation base^exp mod m; errors if m is zero.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "band",
  "category": "math",
  "signature": "band(a: Int, b: Int) -> Int",
  "brief": "Bitwise AND.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bor",
  "category": "math",
  "signature": "bor(a: Int, b: Int) -> Int",
  "brief": "Bitwise OR.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bxor",
  "category": "math",
  "signature": "bxor(a: Int, b: Int) -> Int",
  "brief": "Bitwise XOR.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bnot",
  "category": "math",
  "signature": "bnot(a: Int) -> Int",
  "brief": "Bitwise NOT.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "shl",
  "category": "math",
  "signature": "shl(a: Int, n: Int) -> Int",
  "brief": "Exact left shift (a * 2^n), arbitrary precision like every Int op. For a 64-bit wrapping shift (xorshift), mask: band(shl(x, 13), M) with M = shl(1, 64) - 1 bound once (a literal beyond 64 bits is not allowed in [native]); values past 2^63 run [native] code in BigInt mode — prefer 32-bit xorshift masks for speed.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "shr",
  "category": "math",
  "signature": "shr(a: Int, n: Int) -> Int",
  "brief": "Arithmetic shift right by a nonnegative Int count; arbitrarily large counts give 0 (nonnegative a) or -1 (negative a).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bit_test",
  "category": "math",
  "signature": "bit_test(a: Int, i: Int) -> Int",
  "brief": "1 if bit i of a is set, else 0.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bit_set",
  "category": "math",
  "signature": "bit_set(a: Int, i: Int) -> Int",
  "brief": "a with bit i set.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bit_clr",
  "category": "math",
  "signature": "bit_clr(a: Int, i: Int) -> Int",
  "brief": "a with bit i cleared.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bit_next",
  "category": "math",
  "signature": "bit_next(a: Int, i: Int) -> Int",
  "brief": "Index of the lowest set bit at or above i, or -1 if none.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bit_len",
  "category": "math",
  "signature": "bit_len(a: Int) -> Int",
  "brief": "Exact number of significant bits in the magnitude, including BigInt.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "list",
  "category": "collection",
  "signature": "list(items...) -> List",
  "brief": "Build a list of the arguments; list(list(1, 2), 3) is [[1, 2], 3]. Use push(xs, x) to append.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "map",
  "category": "collection",
  "signature": "map(key, value, ...) -> Map | list |> map(x => expr) -> List",
  "brief": "Build a map from key-value pairs (even arg count), or — with a lambda — transform each list element.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "push",
  "category": "collection",
  "signature": "push(list: List, items...) -> List",
  "brief": "Return a new list with the items appended (the original is unchanged).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "nth",
  "category": "collection",
  "signature": "nth(list: List, i: Int) -> Any",
  "brief": "Element at index i, or () when out of bounds.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "reverse",
  "category": "collection",
  "signature": "reverse(list: List) -> List",
  "brief": "Return the list in reverse order.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "range",
  "category": "collection",
  "signature": "range(start: Int, end: Int, step?: Int) -> List<Int>",
  "brief": "Integers from start toward end (exclusive); bounds and step are 64-bit Ints. A negative step counts down; zero raises kind range. Direct for-loops do not materialize the list, including stepped ranges.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sort",
  "category": "collection",
  "signature": "sort(list: List, order?: \"desc\") -> List",
  "brief": "Sort scalars ascending (or \"desc\"); errors on incomparable element types.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "flatten",
  "category": "collection",
  "signature": "flatten(list: List) -> List",
  "brief": "Flatten one level of nested lists.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "zip",
  "category": "collection",
  "signature": "zip(a: List, b: List) -> List<{left, right}>",
  "brief": "Pair elements positionally; stops at the shorter list.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "enumerate",
  "category": "collection",
  "signature": "enumerate(list: List) -> List<{index, value}>",
  "brief": "Attach a 0-based index to each element.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "with",
  "category": "collection",
  "signature": "with(m: Map, key, value, ...) -> Map | with(list: List, i: Int, value) -> List",
  "brief": "Copy of the map with every key-value pair inserted, or copy of the list with element i replaced. An incomplete pair raises kind type; large Int map keys are stringified, while list indices must fit signed 64 bits.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "without",
  "category": "collection",
  "signature": "without(m: Map, keys...) -> Map",
  "brief": "Return a copy of the map with the given keys removed.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "merge",
  "category": "collection",
  "signature": "merge(a: Map, b: Map) -> Map",
  "brief": "Copy of `a` with all entries of `b` inserted (b wins on conflict).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "join",
  "category": "collection",
  "signature": "join(list: List, sep: String) -> String | join(left: List, right: List, key) -> List",
  "brief": "Join list elements into a string — or, with two lists, an inner data join on `key`.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "filter_by",
  "category": "pipeline",
  "signature": "filter_by(rows: List<Map>, field, op: \">\"|\">=\"|\"<\"|\"<=\"|\"==\"|\"!=\", value) -> List<Map>",
  "brief": "Keep rows whose `field` compares true against `value` (op defaults to == with 3 args).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "fail",
  "category": "types",
  "signature": "fail(kind: String, detail?) -> never | fail(r: TryResult) -> never",
  "brief": "Raise a domain error. `try { f() }` yields {value, error, kind, detail}: branch on r.kind (\"not_found\", \"invalid_transition\", \"guard_failed\", \"invariant\", a `require … else Tag` tag, …); fail(r) re-raises a caught error unchanged.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "slice",
  "category": "collection",
  "signature": "slice(xs: List|String, start: Int, end?: Int) -> List|String",
  "brief": "Sub-list / substring, end exclusive; negative indexes count from the end (slice(xs, -2) = last two). Clamped, never raises.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "keys",
  "category": "collection",
  "signature": "keys(m: Map) -> List<String>",
  "brief": "Keys of a map VALUE, in insertion order. (Memory slots: slot.keys().)",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "values",
  "category": "collection",
  "signature": "values(m: Map) -> List",
  "brief": "Values of a map VALUE, in insertion order. (Memory slots: slot.values().)",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "entries",
  "category": "collection",
  "signature": "entries(m: Map) -> List<{key, value}>",
  "brief": "Key/value records of a map VALUE: for e in entries(m) { e.key  e.value }.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sort_by",
  "category": "pipeline",
  "signature": "sort_by(rows: List<Map>, field, order?: \"desc\") -> List<Map> | sort_by(list, x => key, order?: \"desc\") -> List",
  "brief": "Stable sort by a field (numbers by value, strings lexicographically) or by a key function; a list key sorts on several keys: sort_by(rows, r => [0 - r.total, r.name]).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "top",
  "category": "pipeline",
  "signature": "top(rows: List, n: Int) -> List",
  "brief": "First n elements, capped at the list length. n must be a nonnegative Int; negative raises kind range, wrong types raise kind type.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "bottom",
  "category": "pipeline",
  "signature": "bottom(rows: List, n: Int) -> List",
  "brief": "Last n elements, capped at the list length. n must be a nonnegative Int; negative raises kind range, wrong types raise kind type.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sum_by",
  "category": "pipeline",
  "signature": "sum_by(rows: List<Map>, field) -> Int | Float",
  "brief": "Sum of a field across rows: exact Int when every value is an Int, else a Float; a numeric String (\"5\") counts as its number.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "avg_by",
  "category": "pipeline",
  "signature": "avg_by(rows: List<Map>, field) -> Int|Float",
  "brief": "Mean of a field; Int when whole, () on an empty list.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "min_by",
  "category": "pipeline",
  "signature": "min_by(rows: List<Map>, field) -> Map",
  "brief": "Row with the smallest integer value of `field`, or ().",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "max_by",
  "category": "pipeline",
  "signature": "max_by(rows: List<Map>, field) -> Map",
  "brief": "Row with the largest integer value of `field`, or ().",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "pluck",
  "category": "pipeline",
  "signature": "pluck(rows: List<Map>, field) -> List",
  "brief": "Extract one field from every row (missing fields become ()).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "group_by",
  "category": "pipeline",
  "signature": "group_by(rows: List<Map>, field) -> Map<String, List>",
  "brief": "Group rows into a map keyed by the field's stringified value: 1 and \"1\" (true and \"true\") share a group, a row without the field goes to \"unknown\" and a () value to \"null\" — normalise the field first when those differ in your data.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "distinct",
  "category": "pipeline",
  "signature": "distinct(rows: List, field?) -> List",
  "brief": "Unique elements — or, with `field`, the unique VALUES of that field (distinct_by keeps the rows).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "distinct_by",
  "category": "pipeline",
  "signature": "distinct_by(rows: List<Map>, field: String) -> List<Map>",
  "brief": "The first row per distinct value of `field` (lodash uniqBy / dedup by id). Alias: unique_by.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "count_by",
  "category": "pipeline",
  "signature": "count_by(rows: List<Map>, field, value) -> Int",
  "brief": "Number of rows whose `field` stringifies equal to `value`.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "select",
  "category": "pipeline",
  "signature": "select(rows: List<Map>, fields...) -> List<Map>",
  "brief": "Project each row down to the named fields.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "agg",
  "category": "pipeline",
  "signature": "agg(rows: List<Map>, group_field, \"col:func\"...) -> List<Map>",
  "brief": "Group + aggregate: func is sum|avg|min|max|count; every group also gets a `count`. Groups are keyed like group_by (the field's text).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "inner_join",
  "category": "pipeline",
  "signature": "inner_join(left: List<Map>, right: List<Map>, key) -> List<Map>",
  "brief": "Merge rows whose `key` matches in both lists (left fields win).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "left_join",
  "category": "pipeline",
  "signature": "left_join(left: List<Map>, right: List<Map>, key) -> List<Map>",
  "brief": "Keep every left row, merging matching right-row fields when found.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "filter",
  "category": "lambda",
  "signature": "filter(list: List, x => Bool) -> List",
  "brief": "Keep elements where the lambda returns true (it answers a Bool; () counts as false).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "find",
  "category": "lambda",
  "signature": "find(list: List, x => Bool) -> Any",
  "brief": "First element where the lambda returns true, or ().",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "any",
  "category": "lambda",
  "signature": "any(list: List, x => Bool) -> Bool",
  "brief": "True if the lambda returns true for at least one element.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "all",
  "category": "lambda",
  "signature": "all(list: List, x => Bool) -> Bool",
  "brief": "True if the lambda returns true for every element (true on empty).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "count",
  "category": "lambda",
  "signature": "count(list: List, x => Bool) -> Int",
  "brief": "Number of elements where the lambda returns true.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "reduce",
  "category": "lambda",
  "signature": "reduce(list: List, initial, p => expr) -> Any",
  "brief": "Fold the list; the lambda receives {acc, val} and returns the next acc.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "print",
  "category": "io",
  "signature": "print(args...) -> ()",
  "brief": "Print arguments space-separated, then a newline.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "read_file",
  "category": "io",
  "signature": "read_file(path: String) -> String | {error}",
  "brief": "Read a file as a string; returns {error: ...} on failure.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "write_file",
  "category": "io",
  "signature": "write_file(path: String, content) -> Bool | {error}",
  "brief": "Write content (stringified) to a file; true on success.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "read_csv",
  "category": "io",
  "signature": "read_csv(path: String, opts: Map?) -> List<Map> | {error}",
  "brief": "Parse an RFC 4180 CSV (quoted fields, \"\" escapes, multi-line quoted cells, CRLF) with a header row into maps. Unquoted cells are auto-typed Int/Float/String; a quoted cell and a leading-zero id (007) stay Strings; a short row is padded with \"\", extra fields are dropped. map(\"raw\", true) keeps every cell as text (exact money: \"1.00\"); map(\"delimiter\", \";\") reads a `;`-separated file; any other option is refused.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "to_csv",
  "category": "io",
  "signature": "to_csv(rows: List<Map>) -> String",
  "brief": "The CSV text write_csv would write (header from the first row; quoting that from_csv reads back exactly) — for a download without a temp file.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "from_csv",
  "category": "io",
  "signature": "from_csv(text: String, opts: Map?) -> List<Map>",
  "brief": "read_csv on CSV text already in memory (an uploaded body): same header, typing, raw and delimiter rules.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "write_csv",
  "category": "io",
  "signature": "write_csv(path: String, rows: List<Map>) -> Bool | {error}",
  "brief": "Write rows as CSV using the first row's keys as the header. A cell read_csv would split, trim or re-type is quoted (separators, quotes, newlines, edge spaces, and a String that reads as a number: \"12\" comes back \"12\"); a List/Map is its JSON text, () an empty cell; true comes back as the String \"true\".",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "read_files",
  "category": "io",
  "signature": "read_files(dir: String, count: Int) -> List<{path, content}>",
  "brief": "Read the first `count` files of a directory, in file-name order, with their content (a file that is not UTF-8 text is skipped). There is no listing, move or delete: remember the names you processed in a slot.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "par_read_files",
  "category": "io",
  "signature": "par_read_files(dir: String, count: Int) -> List<{path, content}>",
  "brief": "Thread-parallel variant of read_files.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "word_count",
  "category": "io",
  "signature": "word_count(text: String | docs: List) -> Map<String, Int>",
  "brief": "Lowercased word frequency of a string or of {content} docs (Rust-speed).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "par_word_count",
  "category": "io",
  "signature": "par_word_count(docs: List) -> Map<String, Int>",
  "brief": "Thread-parallel variant of word_count over a list.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "load_template",
  "category": "template",
  "signature": "load_template(path: String, key, value, ...) -> String",
  "brief": "Read a file and substitute each {key} placeholder with its value.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "load",
  "category": "template",
  "signature": "load(path: String, key, value, ...) -> String",
  "brief": "Alias of load_template.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "include",
  "category": "template",
  "signature": "include(path: String, key, value, ...) -> String",
  "brief": "Alias of load_template.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "render",
  "category": "template",
  "signature": "render(template: String, key, value, ...) -> String",
  "brief": "Substitute {key} placeholders in an in-memory template string.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "render_each",
  "category": "template",
  "signature": "render_each(rows: List<Map>, template: String) -> String",
  "brief": "Render the template once per row, substituting {field} from each map.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "html",
  "category": "web",
  "signature": "html(body) -> Response | html(status: Int, body, header_key, header_value, ...) -> Response",
  "brief": "text/html response; auto-injects HTMX on full pages that use hx- attributes.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "response",
  "category": "web",
  "signature": "response(status: Int, body, header_key, header_value, ...) -> Response",
  "brief": "Response with explicit status, body, and optional headers.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "redirect",
  "category": "web",
  "signature": "redirect(url: String) -> Response",
  "brief": "302 redirect to `url`.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sse",
  "category": "web",
  "signature": "sse(streams...) -> Response",
  "brief": "Open a Server-Sent-Events connection that receives only the named streams (no name: every stream).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "publish",
  "category": "web",
  "signature": "publish(stream: String, data) -> ()",
  "brief": "Push data to a runtime-chosen SSE stream name on the event bus.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "http_get",
  "category": "http",
  "signature": "http_get(url: String, opts?: {timeout, max_bytes, headers}) -> Map|List|String",
  "brief": "GET a URL. 2xx: the body (JSON parsed). Never raises on the network or a status: otherwise {error, kind, status, body}; an invalid or unknown option raises kind type — kind http_status (status + the upstream body), timeout, refused or network. timeout defaults to 30000 ms.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "http_post",
  "category": "http",
  "signature": "http_post(url: String, body, opts?: {timeout, max_bytes, headers}) -> Map|List|String",
  "brief": "POST body (a Map/List is sent as JSON, a String as is). Same result shape and default timeout as http_get. Also http_put, http_patch, http_delete(url, opts?).",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "http_put",
  "category": "http",
  "signature": "http_put(url: String, body, opts?) -> Map|List|String",
  "brief": "PUT; same shape as http_post.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "http_patch",
  "category": "http",
  "signature": "http_patch(url: String, body, opts?) -> Map|List|String",
  "brief": "PATCH; same shape as http_post.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "http_delete",
  "category": "http",
  "signature": "http_delete(url: String, opts?) -> Map|List|String",
  "brief": "DELETE; same shape as http_get.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "ws_connect",
  "category": "http",
  "signature": "ws_connect(url: String) -> Map",
  "brief": "Open a WebSocket connection; incoming messages dispatch as signals.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "ws_send",
  "category": "http",
  "signature": "ws_send(msg) -> ()",
  "brief": "Send a message on the current WebSocket connection; errors if not connected.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "link",
  "category": "http",
  "signature": "link(addr: \"host:port\") -> ()",
  "brief": "Open a TCP signal-bus link to a peer node.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "subscribe",
  "category": "http",
  "signature": "subscribe(url: String) -> ()",
  "brief": "Subscribe to a remote event stream; an {\"event\", \"data\"} message runs on event(data) only for an event this program emits or soma.toml [bus] accept lists (else refused); other text runs on ws(msg).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "now",
  "category": "time",
  "signature": "now() -> Int",
  "brief": "Current Unix timestamp in seconds.",
  "deterministic": false,
  "replay": "nondeterministic: replay reports it as a divergence source"
 },
 {
  "name": "now_ms",
  "category": "time",
  "signature": "now_ms() -> Int",
  "brief": "Current Unix timestamp in milliseconds.",
  "deterministic": false,
  "replay": "nondeterministic: replay reports it as a divergence source"
 },
 {
  "name": "today",
  "category": "time",
  "signature": "today() -> String",
  "brief": "Today's date as \"YYYY-MM-DD\" (UTC).",
  "deterministic": false,
  "replay": "nondeterministic: replay reports it as a divergence source"
 },
 {
  "name": "format_date",
  "category": "time",
  "signature": "format_date(ts: Int) -> String",
  "brief": "Format a Unix-seconds timestamp as \"YYYY-MM-DD\" (UTC).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sleep",
  "category": "time",
  "signature": "sleep(ms: Int) -> ()",
  "brief": "Block the current handler for `ms` milliseconds. Requires one Int (other types raise kind type); values outside 0 to 86400000 raise kind range. Under serve it holds the handler lock the whole time.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "next_id",
  "category": "state",
  "signature": "next_id() -> Int",
  "brief": "Monotonic per-cell counter, in its own table (persistent under run/serve; per test cell in tests); journaled — a refused request burns no id; the ids drawn inside a `try` that fails are kept (they may have escaped into a local), so ids are unique, not always dense. Exhaustion at 2^63 - 1 raises range; a malformed or negative stored counter raises storage. Legacy migration is confined to the current cell.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "transition",
  "category": "state",
  "signature": "transition(id, target_state: String) -> {id, from, to}",
  "brief": "Move instance `id` to `target_state` (read the new state with get_status(id)); raises kind \"invalid_transition\" with the valid targets, or \"guard_failed\". Rolled back if the handler later fails.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "get_status",
  "category": "state",
  "signature": "get_status(id) -> String",
  "brief": "Current state of instance `id` — the INITIAL state when `id` was never transitioned (an unknown id looks like a fresh instance; use has_state(id) to tell them apart).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "has_state",
  "category": "state",
  "signature": "has_state(id) -> Bool",
  "brief": "True when instance `id` was transitioned at least once (a recorded state exists). get_status(id) alone cannot distinguish an unknown id from a fresh one.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "valid_transitions",
  "category": "state",
  "signature": "valid_transitions(id) -> List<String>",
  "brief": "States reachable from instance `id`'s current state.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "remember",
  "category": "memory",
  "signature": "remember(key, value) -> ()",
  "brief": "Persist typed data in this cell's agent memory; rejects functions and storage encodings deeper than 100 levels.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "recall",
  "category": "memory",
  "signature": "recall(key: String) -> Any",
  "brief": "The value this cell remember()ed under the key, or (); preserves JSON-shaped Strings and never reads another cell's memory.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "append",
  "category": "memory",
  "signature": "slot.append(value) -> ()",
  "brief": "Memory-slot method: append a value to a list-backed slot (alias: slot.push).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "think",
  "category": "agent",
  "signature": "think(prompt: String, system?: String, opts?: {max_tokens, timeout, max_rounds, tools_allowed, requires}) -> String",
  "brief": "Call the configured LLM with tool-calling, multi-turn context, and budget enforcement. A think() offers the model every tool of the cell's face, or only those named in map(\"tools_allowed\", [\"lookup\"]) (a call to another is refused and told to the model); `requires` lists model capabilities checked by `soma check`. A timeout is not retried (429/5xx are, up to 3 times).",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "think_json",
  "category": "agent",
  "signature": "think_json(prompt: String, system?: String, opts?: {max_tokens, timeout, max_rounds, tools_allowed, requires}) -> Map",
  "brief": "Like think(), but parses the response as JSON into a Map (tools are offered too: pass max_rounds 1 to keep the cost bound at one round). There is no schema option — check the fields yourself.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "refusal",
  "category": "http",
  "signature": "refusal(kind: String, detail?: String) -> Map",
  "brief": "An HTTP response — status from the kind (`conflict` → 409, `not_found` → 404, `unauthorized` → 401, your own tag → 400) and body {error, kind, detail}, exactly what RAISING that error would answer. Return it when the handler must refuse AND keep what it wrote (an audit row): raising rolls the writes back, returning does not. It is a response envelope like response(): read the fields through `_body` (`r._body.kind`), and return it as the handler's value.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "horde",
  "category": "agent",
  "signature": "horde(handler, inputs: List, opts?: {concurrency, max_attempts, budget_tokens, seed, snapshot, instance, on_result, apply, on_done, on_error}) -> String",
  "brief": "Run `handler` (mark it [task]) once per input with a bounded pool of workers; returns the horde id (`Cell:h1`) at once. The queue is persisted with the program's data and resumes after a restart; each result is recorded — and on_result(result) / on_result(input, result) called — with the handler's last step, so once. budget_tokens: a hard ceiling (every think() reserves its bound first; state `exhausted`). on_error(input, error: {error, kind, detail}) after max_attempts (default 1); on_done(id) once at the end. Rounds: snapshot (handler takes (input, snapshot)), apply (in input order at the end), seed (reproducible random()), instance (per-agent memory). concurrency default 8, at most 1000. Without workers (soma test) it runs right after the caller commits.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "vote",
  "category": "agent",
  "signature": "vote(handler, input, k: Int) -> Map",
  "brief": "k agents (1..25) answer the same input; {winner, count, k, unanimous, errors, votes}. The most common answer wins, ties to the earliest voter. In a [task] step under serve / run the k calls run at once outside the lock, else in turn; each voter starts a fresh model context; a voter that raises counts in `errors` (all raising: the first error). Voters' writes are theirs — keep them read-only.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "horde_status",
  "category": "agent",
  "signature": "horde_status(id: String) -> Map",
  "brief": "{state: running | cancelling | exhausting | done | cancelled | exhausted, total, queued, running, done, failed, cancelled, tokens, budget_tokens?} of a horde (its id names its cell).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "horde_results",
  "category": "agent",
  "signature": "horde_results(id: String) -> List",
  "brief": "The results of a horde in input order; () for a task not done (failed, cancelled or still queued).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "horde_cancel",
  "category": "agent",
  "signature": "horde_cancel(id: String) -> Bool",
  "brief": "Stop a horde: no new task starts, running ones finish, on_done is called. false when it was not running.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "delegate",
  "category": "agent",
  "signature": "delegate(cell: String, signal: String, args...) -> Any",
  "brief": "Invoke another cell's handler and return its result.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "set_budget",
  "category": "agent",
  "signature": "set_budget(max_tokens: Int) -> ()",
  "brief": "Hard cap on LLM tokens; think() fails once exhausted.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "tokens_used",
  "category": "agent",
  "signature": "tokens_used() -> Int",
  "brief": "LLM tokens consumed since the budget was set.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "tokens_remaining",
  "category": "agent",
  "signature": "tokens_remaining() -> Int",
  "brief": "Tokens left in the budget, or -1 if unlimited.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "trace",
  "category": "agent",
  "signature": "trace() -> List",
  "brief": "Structured execution log: every think(), tool call, and approval.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "clear_trace",
  "category": "agent",
  "signature": "clear_trace() -> ()",
  "brief": "Empty the agent trace log.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "clear_context",
  "category": "agent",
  "signature": "clear_context() -> ()",
  "brief": "Reset the multi-turn LLM conversation history.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "approve",
  "category": "agent",
  "signature": "approve(action: String) -> Bool",
  "brief": "Human-in-the-loop gate. Answered by `mock approve true|false` in tests, by SOMA_APPROVE=always|never, or by a person at the terminal under `soma run`; otherwise (e.g. under soma serve) it RAISES kind \"approval_required\" — it never approves on its own.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "matrix",
  "category": "linalg",
  "signature": "matrix(\"1 2; 3 4\") -> List<List<Float>>",
  "brief": "MATLAB-style matrix literal: ';' separates rows, whitespace/',' separates entries.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "mat",
  "category": "linalg",
  "signature": "mat(rows: Int, cols: Int, values: List<Float>) -> List<List<Float>>",
  "brief": "Reshape a flat list into an r×c matrix; errors if the count mismatches.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "reshape",
  "category": "linalg",
  "signature": "reshape(values, rows: Int, cols: Int) -> Matrix",
  "brief": "Lay a flat list or matrix out row-major as rows×cols; also m.reshape(r,c).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "transpose",
  "category": "linalg",
  "signature": "transpose(m: Matrix) -> Matrix",
  "brief": "Transpose; also m.transpose().",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "shape",
  "category": "linalg",
  "signature": "shape(m) -> List<Int>",
  "brief": "[rows, cols] for a matrix, [n] for a vector; also m.shape().",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "matmul",
  "category": "linalg",
  "signature": "matmul(a: Matrix, b: Matrix) -> Matrix",
  "brief": "Matrix product (also the `*` operator on two matrices); inner dims must agree.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "det",
  "category": "linalg",
  "signature": "det(m: Matrix) -> Float",
  "brief": "Determinant of a square matrix (LU with partial pivoting).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "diag_sum",
  "category": "linalg",
  "signature": "diag_sum(m: Matrix) -> Float",
  "brief": "Matrix trace: sum of the diagonal.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "identity",
  "category": "linalg",
  "signature": "identity(n: Int) -> Matrix",
  "brief": "n×n identity matrix (alias of eye).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "scale",
  "category": "linalg",
  "signature": "scale(m: Matrix, k) -> Matrix",
  "brief": "Scalar-multiply every entry (also `k * m`).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "flatten_mat",
  "category": "linalg",
  "signature": "flatten_mat(m: Matrix) -> List<Float>",
  "brief": "Flatten a matrix to a row-major vector.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "rows",
  "category": "linalg",
  "signature": "rows(r1: List<Float>, r2: List<Float>, ...) -> List<List<Float>>",
  "brief": "Build a matrix from row vectors.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "cols",
  "category": "linalg",
  "signature": "cols(c1: List<Float>, c2: List<Float>, ...) -> List<List<Float>>",
  "brief": "Build a matrix from column vectors (transposes).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "eye",
  "category": "linalg",
  "signature": "eye(n: Int) -> List<List<Float>>",
  "brief": "n×n identity matrix.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "zeros",
  "category": "linalg",
  "signature": "zeros(r: Int, c: Int) -> List<List<Float>>",
  "brief": "r×c matrix of zeros.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "ones",
  "category": "linalg",
  "signature": "ones(r: Int, c: Int) -> List<List<Float>>",
  "brief": "r×c matrix of ones.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "diag",
  "category": "linalg",
  "signature": "diag(values: List<Float>) -> List<List<Float>>",
  "brief": "Square diagonal matrix from a list.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "to_sampled",
  "category": "linalg",
  "signature": "to_sampled(A: List<List<Float>>, opts?: {max_rows, max_cols}) -> Map",
  "brief": "Build a BST-backed length-squared sampling handle (Tang); O(log n) per sample after.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sample_row",
  "category": "linalg",
  "signature": "sample_row(A) -> Map",
  "brief": "Draw one row index by ℓ²-norm importance sampling (time-seeded PRNG).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "drop_sampled",
  "category": "linalg",
  "signature": "drop_sampled(handle: Map) -> Bool",
  "brief": "Free a to_sampled() registry entry; true if it existed.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "importance_sample_rows",
  "category": "linalg",
  "signature": "importance_sample_rows(A, opts: {samples}) -> Map",
  "brief": "Sample rows by squared-norm importance (time-seeded PRNG).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "svd_lowrank",
  "category": "linalg",
  "signature": "svd_lowrank(A, opts: {row_samples, col_samples, rank, max_dim}) -> Map",
  "brief": "Sublinear randomized low-rank SVD with declared sampling bounds.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "regress_sgd",
  "category": "linalg",
  "signature": "regress_sgd(A, b: List<Float>, opts: {eps, lambda, max_iter, max_dim}) -> Map",
  "brief": "Ridge regression via stochastic gradient descent with declared bounds.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "clean_covariance",
  "category": "linalg",
  "signature": "clean_covariance(returns: List<List<Float>>, opts: {method: \"rie\"|\"clip\"|\"raw\", eta, center, max_assets, max_obs}) -> Map",
  "brief": "RMT (Bouchaud-Potters) covariance cleaning: rows are observations (T), columns assets (N); the sample covariance divides by T (population — numpy cov uses T-1); center (default true) subtracts each column mean; clip replaces the eigenvalues inside the Marchenko-Pastur bulk by their mean; .matrix is the cleaned N×N, .eigenvalues the cleaned spectrum (no eigenvectors). max_obs / max_assets past the data raise kind range.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "impact_sqrt",
  "category": "linalg",
  "signature": "impact_sqrt(qty: Float, daily_volume: Float, sigma: Float, opts?: {Y}) -> Map",
  "brief": "Bouchaud square-root market-impact law; .bps is expected slippage.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "quantile",
  "category": "linalg",
  "signature": "quantile(values: List<Float>, q: Float) -> Float",
  "brief": "q-th quantile with linear interpolation between the two nearest sorted values (numpy's default): quantile(xs, 0.5) == median(xs).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "median",
  "category": "math",
  "signature": "median(xs: List) -> Int | Float",
  "brief": "Order Int/Float values exactly and preserve the middle value (mean of the two middles for even n). An Int middle stays exact; any NaN input makes the result NaN.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "pstdev",
  "category": "math",
  "signature": "pstdev(xs: List) -> Float",
  "brief": "Population standard deviation (divide by n). Preserve finite and subnormal deviations even when their variance is outside Float range.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "stddev",
  "category": "math",
  "signature": "stddev(xs: List) -> Float",
  "brief": "Same as pstdev (population).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "stdev",
  "category": "math",
  "signature": "stdev(xs: List) -> Float",
  "brief": "SAMPLE standard deviation (divide by n - 1); needs two values. Preserve finite and subnormal deviations even when their variance is outside Float range.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "variance",
  "category": "math",
  "signature": "variance(xs: List) -> Float",
  "brief": "SAMPLE variance (divide by n - 1) — statistics.variance; pvariance is the population form.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "pvariance",
  "category": "math",
  "signature": "pvariance(xs: List) -> Float",
  "brief": "Population variance (divide by n) — statistics.pvariance.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "chr",
  "category": "string",
  "signature": "chr(n: Int) -> String",
  "brief": "The character with code point n: chr(65) == \"A\". Raises kind range outside 0..0x10FFFF or for surrogate code points.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "ord",
  "category": "string",
  "signature": "ord(s: String) -> Int",
  "brief": "Code point of the first character: ord(\"A\") == 65.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "var_historical",
  "category": "linalg",
  "signature": "var_historical(returns: List<Float>, opts?: {alpha, max_obs}) -> Float",
  "brief": "Historical Value-at-Risk as a POSITIVE loss: -quantile(returns, 1 - alpha) (returns positive for gains); alpha in (0, 1), else kind range; more observations than max_obs raise kind range.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "expected_shortfall_historical",
  "category": "linalg",
  "signature": "expected_shortfall_historical(returns: List<Float>, opts?: {alpha, max_obs}) -> Float",
  "brief": "Historical expected shortfall (CVaR) as a positive loss: minus the mean of the returns at or below the (1 - alpha) quantile; alpha in (0, 1); max_obs as for var_historical.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "var_gaussian",
  "category": "linalg",
  "signature": "var_gaussian(returns: List<Float>, opts?: {alpha, mu, sigma}) -> Float",
  "brief": "Gaussian VaR assuming N(mu, sigma^2); moments inferred unless overridden.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "_coalesce",
  "category": "internal",
  "signature": "_coalesce(a, b) -> Any",
  "brief": "Desugared form of `a ?? b`: returns b only when a is ().",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "regex_count",
  "category": "string",
  "signature": "regex_count(text: String, pattern: String) -> Int",
  "brief": "Number of non-overlapping matches (Rust regex syntax). Same in [native] (pattern must be a literal there).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "regex_match",
  "category": "string",
  "signature": "regex_match(text: String, pattern: String) -> Int",
  "brief": "1 when the pattern matches anywhere in text, else 0.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "regex_replace",
  "category": "string",
  "signature": "regex_replace(text: String, pattern: String, replacement: String) -> String",
  "brief": "Replace every match; $1 refers to the first capture group.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "read_stdin",
  "category": "io",
  "signature": "read_stdin() -> String",
  "brief": "The whole standard input (for `soma run` filters).",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "write_str",
  "category": "io",
  "signature": "write_str(s: String) -> Int",
  "brief": "Write s to stdout without a newline; returns the byte count.",
  "deterministic": true,
  "replay": "an effect: not in the log — replay calls it again"
 },
 {
  "name": "buffer",
  "category": "native",
  "signature": "buffer(n: Int) -> Buf   [native] only",
  "brief": "Array of n Ints, zeroed. Random access with buf_get / buf_set. Not available in interpreted handlers.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "buf_get",
  "category": "native",
  "signature": "buf_get(b: Buf, i: Int) -> Int   [native] only",
  "brief": "Read b[i].",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "buf_set",
  "category": "native",
  "signature": "buf_set(b: Buf, i: Int, v: Int) -> ()   [native] only",
  "brief": "Write b[i] = v.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "buffer_f",
  "category": "native",
  "signature": "buffer_f(n: Int) -> BufF   [native] only",
  "brief": "Array of n Floats, zeroed (buf_get_f / buf_set_f).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "buf_get_f",
  "category": "native",
  "signature": "buf_get_f(b: BufF, i: Int) -> Float   [native] only",
  "brief": "Read b[i].",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "buf_set_f",
  "category": "native",
  "signature": "buf_set_f(b: BufF, i: Int, v: Float) -> ()   [native] only",
  "brief": "Write b[i] = v.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "hashmap",
  "category": "native",
  "signature": "hashmap() -> HMap   [native] only",
  "brief": "Int → Int hash map (hm_get / hm_set / hm_inc / hm_len / hm_has).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "hm_get",
  "category": "native",
  "signature": "hm_get(m: HMap, k: Int) -> Int   [native] only",
  "brief": "Value at k, 0 when absent.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "hm_set",
  "category": "native",
  "signature": "hm_set(m: HMap, k: Int, v: Int) -> ()   [native] only",
  "brief": "m[k] = v.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "hm_inc",
  "category": "native",
  "signature": "hm_inc(m: HMap, k: Int) -> ()   [native] only",
  "brief": "m[k] += 1 (inserting 1).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "hm_len",
  "category": "native",
  "signature": "hm_len(m: HMap) -> Int   [native] only",
  "brief": "Number of keys.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "hm_has",
  "category": "native",
  "signature": "hm_has(m: HMap, k: Int) -> Bool   [native] only",
  "brief": "Whether k is present.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "strbuf",
  "category": "native",
  "signature": "strbuf(capacity?: Int) -> SBuf   [native] only",
  "brief": "Growable string builder (sb_push / sb_push_int / sb_push_char / sb_len / sb_finish).",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sb_push",
  "category": "native",
  "signature": "sb_push(b: SBuf, s: String) -> ()   [native] only",
  "brief": "Append a string.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sb_push_int",
  "category": "native",
  "signature": "sb_push_int(b: SBuf, n: Int) -> ()   [native] only",
  "brief": "Append an Int's decimal digits.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sb_push_char",
  "category": "native",
  "signature": "sb_push_char(b: SBuf, c: Int) -> ()   [native] only",
  "brief": "Append one character by code point.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sb_len",
  "category": "native",
  "signature": "sb_len(b: SBuf) -> Int   [native] only",
  "brief": "Bytes so far.",
  "deterministic": true,
  "replay": "pure"
 },
 {
  "name": "sb_finish",
  "category": "native",
  "signature": "sb_finish(b: SBuf) -> String   [native] only",
  "brief": "The built String.",
  "deterministic": true,
  "replay": "pure"
 }
]