Native functions
Builtins dispatched by the Rust server and native execution context.
append¶
[result =] append <array-path> <value>Append a resolved value to an array in the execution context.
Runtime: Native / server
Aliases: memory.append
Returns / effects
Mutates the context array; an assignment target receives the updated value. Nested object paths are supported by this builtin.
Errors / edge cases
Missing/non-array targets and invalid nested paths can fail.
append users bodyImplementation: src/builtins/builtin/commands.rs
csv.append¶
csv.append <filename> <record>Append a record to a CSV file. Relative file resolution uses the app/script path and filesystem candidates.
Runtime: Native / server
Parameters
filename- Filesystem path.
record- Context data or assignment target, as shown in the signature.
Returns / effects
Appends the context object to the target CSV file.
Errors / edge cases
Requires filename and record; invalid data or file writes can fail.
csv.append "users.csv" bodyImplementation: src/builtins/builtin/csv.rs
csv.read¶
rows = csv.read <filename>Read CSV records. Relative file resolution uses the app/script path and filesystem candidates.
Runtime: Native / server
Parameters
filename- Filesystem path.
result- Context data or assignment target, as shown in the signature.
Returns / effects
Array of objects whose CSV field values are strings. Writes the assigned variable and ___last_exec_result___.
Errors / edge cases
Missing filename is an error. An unreadable file logs a warning and assigns an empty array.
users = csv.read "users.csv"Implementation: src/builtins/builtin/csv.rs
csv.write¶
csv.write <filename> <rows>Replace a CSV file with records. Relative file resolution uses the app/script path and filesystem candidates.
Runtime: Native / server
Parameters
filename- Filesystem path.
rows- Context data or assignment target, as shown in the signature.
Returns / effects
Writes a header from the first object and rows from the supplied context array.
Errors / edge cases
Missing/non-array variable and write failures are errors. Values are written through their string representation path; do not assume JSON numeric values are preserved.
csv.write "users.csv" usersImplementation: src/builtins/builtin/csv.rs
datasource¶
[result =] datasource <action> <Schema> <operation arguments...>Dispatch a schema-based database operation through a configured native MySQL or PostgreSQL source.
Runtime: Native / server
Returns / effects
Operation-dependent result or side effect. Supported actions: create_table, fetch_all, fetch, insert, update, delete.
Errors / edge cases
Unknown source, missing connection/type, unsupported connection type, and database/query failures.
datasource create_table User in Users
datasource fetch_all User from Users into dataImplementation: src/builtins/builtin/data_source.rs
db¶
result = db <source> <packet>Execute one Rune DB operation packet against a named datasource.
Runtime: Native Rune / Rune-Web action I/O
Parameters
source- Named rune-db provider for db, or vect-event provider for events.
packet- Context variable containing the operation object. See knowledge/runtime/storage.md.
Returns / effects
Operation result or atomic commit receipt. Pure expressions remain synchronous; browser top-level actions resume after completion.
Errors / edge cases
Invalid packets, revision conflicts and persistence failures reject the operation. Batches roll back together.
packet = { op: "get", collection: "notes", key: "hello" }
record = db main packetImplementation: src/storage/mod.rs · src/storage/provider.rs · src/builtins.rs · runtime/rune-web/src/datasource.ts
delete¶
delete <path>Delete a top-level context variable or nested object property.
Runtime: Native / server
Returns / effects
Mutates the current context. Missing targets are ignored.
Errors / edge cases
Missing path is a builtin error.
delete state.players.[id]Implementation: src/builtins/builtin/context_ops.rs
events¶
result = events <source> <packet>Append or read durable events through a named vect-event provider.
Runtime: Native Rune / Rune-Web action I/O
Parameters
source- Named rune-db provider for db, or vect-event provider for events.
packet- Context variable containing the operation object. See knowledge/runtime/storage.md.
Returns / effects
Operation result or atomic commit receipt. Pure expressions remain synchronous; browser top-level actions resume after completion.
Errors / edge cases
Invalid packets, revision conflicts and persistence failures reject the operation. Batches roll back together.
packet = { op: "read", stream: "orders", after: "0", limit: 20 }
page = events activity packetImplementation: src/storage/mod.rs · src/storage/provider.rs · src/builtins.rs · runtime/rune-web/src/datasource.ts
fetch¶
result = fetch <url|name> [options <binding>] [catch <handler>]Perform an outbound HTTP GET and return {status, body}.
Runtime: Native / server
Parameters
url- http(s) URL literal, or a name (e.g. an @Values entry) holding one.
options- Optional binding holding headers, timeout_ms, max_body_bytes, or redirect. Custom header requests reject redirects.
catch- Optional: func/action called with the error ($1 / payload {status, message}).
Returns / effects
Writes the response (fetch: {status, body}; fetch-json: parsed JSON) to the assignment target and ___last_exec_result___.
Errors / edge cases
GET only; http/https only; Default 10s timeout and 1 MiB cap, configurable per request. Native REST: 502 for upstream non-2xx/bad JSON/network errors, 504 on timeout, unless a catch handler is given. Rune-Web: failures call the catch action; browser CORS rules apply.
response = fetch weather_urlImplementation: src/builtins/builtin/http_fetch.rs · runtime/rune-web/src/builtins/fetch.ts
fetch-json¶
result = fetch-json <url|name> [options <binding>] [catch <handler>]Perform an outbound HTTP GET and parse the body as JSON.
Runtime: Native / server
Parameters
url- http(s) URL literal, or a name (e.g. an @Values entry) holding one.
options- Optional binding holding headers, timeout_ms, max_body_bytes, or redirect. Custom header requests reject redirects.
catch- Optional: func/action called with the error ($1 / payload {status, message}).
Returns / effects
Writes the response (fetch: {status, body}; fetch-json: parsed JSON) to the assignment target and ___last_exec_result___.
Errors / edge cases
GET only; http/https only; Default 10s timeout and 1 MiB cap, configurable per request. Native REST: 502 for upstream non-2xx/bad JSON/network errors, 504 on timeout, unless a catch handler is given. Background jobs fail on errors and accept only assigned calls with dotted URL and optional options paths, without callbacks. Rune-Web: failures call the catch action; browser CORS rules apply.
weather = fetch-json weather_urlImplementation: src/builtins/builtin/http_fetch.rs · runtime/rune-web/src/builtins/fetch.ts
func¶
func <name> <step>; <step>; ...Register a sequence of semicolon-separated native steps in the current context.
Runtime: Native / server
Returns / effects
Stores steps under func:<name>. Invocations expose positional arguments as $1, $2, ... and copy non-positional context values back to the caller.
Errors / edge cases
Missing function name is a builtin error; directly surfaced builtin failures inside a function propagate to its caller, including failures from arithmetic command operands.
func greet log "hello"; respond 200 "OK"Implementation: src/builtins/builtin/function.rs
is-set¶
result = is-set <path>Check whether a variable or resolved path exists in the execution context.
Runtime: Native / server
Returns / effects
True when the variable or path exists, including when its value is negative, zero, or null. False when it cannot be resolved.
Errors / edge cases
Omitting the path argument is a builtin error.
body = { response: -1, feedback: null }
present = is-set body.response
feedback_present = is-set body.feedback
missing = is-set body.extraImplementation: src/builtins/builtin/context_ops.rs
json.read¶
result = json.read <filename>Read a JSON file and parse its contents.
Runtime: Native / server
Returns / effects
Parsed JSON is written to the assignment target and ___last_exec_result___.
Errors / edge cases
Requires a filename and assignment target. File-read and JSON-parse failures return builtin errors.
settings = json.read "settings.json"Implementation: src/builtins/builtin/json.rs
list.slice¶
result = list.slice <array> <start> [end]Return a subarray slice from start index to optional end index.
Runtime: Native / server
Returns / effects
New sliced array.
top = list.slice ranked 0 10Implementation: src/builtins/builtin/str_list.rs
list.sort-by¶
result = list.sort-by <array> <field> [asc|desc]Return a new array sorted by a numeric or string object field.
Runtime: Native / server
Returns / effects
New sorted array; ascending by default, or descending when "desc" is passed.
ranked = list.sort-by hits "score" "desc"Implementation: src/builtins/builtin/str_list.rs
load-rune¶
result = load-rune <path> [as xml]Load a Rune file or directory, resolving its top-level imports before parsing.
Runtime: Native / server
Returns / effects
Document data in JSON form by default, or an XML string when as xml is supplied.
Errors / edge cases
Requires a path; loading/parsing failure is an error. The explicit conversion form supports xml.
document = load-rune "shared.rune"Implementation: src/builtins.rs
log¶
log <message...>Expand {expression} placeholders using the current execution context and write the message to the logger.
Runtime: Native / server
Parameters
message- One or more message tokens; quoted text may contain spaces.
Returns / effects
Stores the expanded message in ___last_exec_result___. Unknown placeholders remain unchanged.
log "Fetching user {id}"Implementation: src/builtins/builtin/logger.rs
memory.cas¶
[swapped =] memory.cas <key> <expected> <new> [--key-from-context] [--ttl <seconds>]Atomically replace a memory entry only if its current value equals expected.
Runtime: Native / server
Returns / effects
Assigns true to the target and ___last_exec_result___ when the swap succeeds, or false when the current value does not match expected.
Errors / edge cases
Missing arguments, unknown/extra arguments, invalid --ttl, or an invalid context key is a builtin error.
swapped = memory.cas sid expected next --key-from-context
created = memory.cas sid null initial --key-from-context --ttl 300Implementation: src/builtins/builtin/memory.rs
memory.clear¶
memory.clearRemove all keys from the process memory backend.
Runtime: Native / server
Aliases: clear-memory
Returns / effects
Clears the shared backend, not only the current request context.
Errors / edge cases
Unexpected arguments return a builtin error.
memory.clearImplementation: src/builtins/builtin/memory.rs
memory.del¶
memory.del <key>
memory.del <path> --key-from-contextDelete a key from the process memory backend.
Runtime: Native / server
Aliases: del-memory
Returns / effects
Removes the key; no assigned result.
Errors / edge cases
Missing key, unknown/extra arguments, or a context key that does not resolve to a nonempty string is a builtin error.
memory.del "user"
memory.del path.params.id --key-from-contextImplementation: src/builtins/builtin/memory.rs
memory.get¶
result = memory.get <key>
result = memory.get <path> --key-from-contextRead a value from the process memory backend.
Runtime: Native / server
Aliases: get-memory
Returns / effects
Assigns the stored JSON value and ___last_exec_result___ when found. A missing or expired key logs a warning and leaves the context unchanged; it does not assign null.
Errors / edge cases
Missing key, unknown/extra arguments, or a context key that does not resolve to a nonempty string is a builtin error.
user = memory.get "user"
stored = memory.get path.params.id --key-from-contextImplementation: src/builtins/builtin/memory.rs
memory.push¶
[result =] memory.push <key> <value> [--key-from-context] [--ttl <seconds>]Atomically append a value to a list in the process memory backend.
Runtime: Native / server
Returns / effects
Creates a one-element list if the key is missing or expired, otherwise appends under the backend write lock and assigns the updated list to the target and ___last_exec_result___.
Errors / edge cases
Missing arguments, unknown/extra arguments, invalid --ttl, an invalid context key, or an existing non-list value at the key is a builtin error.
items = memory.push sid item --key-from-context
items = memory.push "events" payload --ttl 600Implementation: src/builtins/builtin/memory.rs
memory.set¶
memory.set <key> [value] [--ttl <seconds>]
memory.set <path> <value> --key-from-context [--ttl <seconds>]Store a value in the process memory backend.
Runtime: Native / server
Aliases: set-memory
Returns / effects
Uses an exact context-variable lookup for value; otherwise stores literal text. If omitted, value uses the key token.
Errors / edge cases
Missing key, an invalid --ttl duration, unknown/extra arguments, or a context key that does not resolve to a nonempty string is a builtin error.
memory.set "user" body
memory.set path.params.id record --key-from-context --ttl 300Implementation: src/builtins/builtin/memory.rs
now¶
result = now [format]Read the current UTC time.
Runtime: Native / server
Returns / effects
Default: RFC 3339 string. millis: Unix milliseconds. unix or seconds: Unix seconds.
timestamp = now millisImplementation: src/builtins/builtin/coercion.rs
parse-json¶
[result =] parse-json [source]Parse a JSON string stored in the request context.
Runtime: Native / server
Parameters
source- Context variable containing a JSON string; defaults to body.
Returns / effects
Writes parsed JSON to the assignment target, or body when unassigned, and ___last_exec_result___.
Errors / edge cases
Malformed JSON raises a builtin error (HTTP 500 in a native REST request). A missing or non-string source leaves the context unchanged in legacy Rune execution, but fails a background job.
payload = parse-json bodyImplementation: src/builtins/builtin/parse_json.rs
respond¶
respond [status] [value...]Finish the current request with an HTTP status and response body.
Runtime: Native / server
Parameters
status- HTTP status integer; defaults to 200 if absent or not parseable.
value- A context variable name, an unquoted object expression after an explicit status, or literal text. Defaults to OK.
Returns / effects
HTTP response. Context objects and unquoted object expressions are serialized as JSON text. The native REST handler uses a text/plain response body; generated OpenAPI documents detected status codes with a string response schema.
respond 200 "Echoed: {pretty data}"Implementation: src/builtins/builtin/respond.rs
str.contains¶
result = str.contains <haystack> <needle>Check whether a string contains a substring.
Runtime: Native / server
Returns / effects
Boolean true when needle appears in haystack; otherwise false.
matched = str.contains summary "rest"Implementation: src/builtins/builtin/str_list.rs
str.join¶
result = str.join <array> [separator]Join array elements into a single string with an optional separator.
Runtime: Native / server
Returns / effects
Joined string; non-array inputs return an empty string.
slug = str.join words "-"Implementation: src/builtins/builtin/str_list.rs
str.lower¶
result = str.lower <value>Convert a string value to lowercase.
Runtime: Native / server
Returns / effects
Lowercased UTF-8 string.
normalized = str.lower queryImplementation: src/builtins/builtin/str_list.rs
str.split¶
result = str.split <text> [separator]Split a string into an array on whitespace or an explicit separator.
Runtime: Native / server
Returns / effects
Array of string parts.
terms = str.split queryImplementation: src/builtins/builtin/str_list.rs
str.trim¶
result = str.trim <value>Strip leading and trailing whitespace from a string.
Runtime: Native / server
Returns / effects
Trimmed string.
clean = str.trim raw_inputImplementation: src/builtins/builtin/str_list.rs
summarize¶
result = summarize <records> by <group-path> [<metric> <value-path>]Group records into an ordered, non-mutating report.
Runtime: Native / server
Parameters
metric- sum, avg, min, max, median, distinct, first, or last. Omit for counts.
Returns / effects
Array of groups in first-occurrence order, with counts and the requested metric. Missing group fields join the null group.
Errors / edge cases
Invalid syntax, non-array input, unsupported metrics, invalid paths, and non-numeric metric values can fail.
report = summarize sales by region sum amountImplementation: src/builtins/builtin/summarize.rs
to-bool¶
result = to-bool [value]Convert a context value to a boolean.
Runtime: Native / server
Returns / effects
Strings are true only for case-insensitive true or exactly 1. Numbers are true when nonzero; null is false; objects and arrays are true. No argument is false.
enabled = to-bool inputImplementation: src/builtins/builtin/coercion.rs
to-json¶
result = to-json <value>Serialize a context value, object, or array to a compact JSON string.
Runtime: Native / server
Returns / effects
Compact JSON string representation of the resolved value.
encoded = to-json payloadImplementation: src/builtins/builtin/str_list.rs
to-number¶
result = to-number <value>Convert a resolved number, numeric string, or boolean to a number.
Runtime: Native / server
Returns / effects
A JSON number, or null for an unsupported/unparseable value. Booleans map to 1 and 0.
value = to-number idImplementation: src/builtins/builtin/coercion.rs
to-string¶
result = to-string [value]Convert a context value or literal token to a string.
Runtime: Native / server
Returns / effects
Existing strings are preserved; other JSON values are serialized. No argument produces an empty string.
Errors / edge cases
In background jobs, exactly one existing dotted source path is required; a missing path fails the job.
text = to-string bodyImplementation: src/builtins/builtin/coercion.rs
uuid.v4¶
result = uuid.v4Generate a random version 4 UUID.
Runtime: Native / server
Aliases: uuid
Returns / effects
Hyphenated UUID string.
id = uuid.v4Implementation: src/builtins/builtin/coercion.rs
validate¶
validate <value> #<Schema>
validate <left> <operator> <right> "message"Validate required scalar fields against a named schema, or check a comparison.
Runtime: Native / server
Parameters
value- Context variable to validate.
Schema- An @Schema name; supported scalar field types are string, number, bool.
Returns / effects
Schema form stores the validated value in ___last_exec_result___. Validation failures finish the request with HTTP 400.
Errors / edge cases
Missing field, type mismatch, or unknown schema/value. Additional properties are accepted; nested/optional schema validation is not implemented by this path.
parse-json
validate body #GreetingImplementation: src/builtins/builtin/validate.rs
verify¶
verify <source> as <Schema> into <target>Parse JSON and validate required fields against a named schema.
Runtime: Native / server
Parameters
source- Dotted context path containing a JSON string.
Schema- Named @Schema with scalar, nested schema or array fields.
target- Writable simple identifier.
Returns / effects
Writes the parsed object to the target on success; preserves the source and ___last_exec_result___ unless either is the target.
Errors / edge cases
Invalid JSON or data responds 400. Invalid command or schema, missing or non-string source, and read-only targets fail execution. No target is written on failure.
verify body as Order into orderImplementation: src/builtins/builtin/verify.rs · tests/verify_builtin.rs
ws.broadcast¶
ws.broadcast <path> <message...>Broadcast a message to connections registered on a WebSocket path.
Runtime: Native / server
Aliases: broadcast-websocket
Returns / effects
Queues the message for connections on the supplied path.
Errors / edge cases
Requires a path and message.
ws.broadcast /chat bodyImplementation: src/builtins/builtin/ws.rs
ws.id¶
id = ws.idRead the identifier of the current WebSocket connection.
Runtime: Native / server
Returns / effects
Connection ID string, or null outside a connection context.
id = ws.idImplementation: src/builtins/builtin/ws.rs
ws.send¶
ws.send <path> <connection-id> <message...>Send a message to one WebSocket connection.
Runtime: Native / server
Returns / effects
Queues a message in the process-local connection registry.
Errors / edge cases
Requires a path, connection ID, and message.
ws.send /chat id bodyImplementation: src/builtins/builtin/ws.rs