Standard library
Complete API reference for all 15 stdlib packages.
std/io
Console output.
fn print(s: string) fn println(s: string)
std/strings
19 string manipulation functions. No effects required.
Splitting & joining
fn split(s: string, sep: string) -> []string fn join(parts: []string, sep: string) -> string
Searching
fn contains(s: string, substr: string) -> bool fn starts_with(s: string, prefix: string) -> bool fn ends_with(s: string, suffix: string) -> bool fn index_of(s: string, substr: string) -> int // -1 if not found
Transforming
fn to_upper(s: string) -> string fn to_lower(s: string) -> string fn trim(s: string) -> string // strips leading/trailing whitespace fn trim_prefix(s: string, prefix: string) -> string fn trim_suffix(s: string, suffix: string) -> string fn replace(s: string, old: string, new: string) -> string // replaces all fn replace_first(s: string, old: string, new: string) -> string // replaces first
Inspection
fn length(s: string) -> int fn is_empty(s: string) -> bool fn char_at(s: string, index: int) -> string // "" for out-of-bounds fn substring(s: string, start: int, end: int) -> string // clips to valid range
Formatting
fn repeat(s: string, count: int) -> string fn pad_left(s: string, width: int, pad: string) -> string fn pad_right(s: string, width: int, pad: string) -> string
std/json
JSON serialization. No effects required.
fn encode(value: any) -> string fn decode(text: string) -> Result[any, string] fn pretty(value: any) -> string fn valid(text: string) -> bool
Type-specialized decode
When json.decode is used with a type annotation, the compiler specializes the call:
let config: MyConfig = json.decode(text)? // Deserializes directly into MyConfig at compile time
std/math
Numeric utilities. No effects required.
Integer operations
fn abs(x: int) -> int fn min(a: int, b: int) -> int fn max(a: int, b: int) -> int fn clamp(x: int, lo: int, hi: int) -> int fn is_even(x: int) -> bool fn is_odd(x: int) -> bool
Float operations
fn floor(x: float) -> int fn ceil(x: float) -> int fn round(x: float) -> int fn sqrt(x: float) -> float fn pow(base: float, exp: float) -> float
std/http
HTTP client. All request functions require needs { net }.
Types
type Header = struct { name: string, value: string } type Request = struct { method: string, url: string, body: string, headers: []Header } type Response = struct { status: int, body: string, headers: []Header }
Functions
fn get(url: string) -> Result[Response, string] needs { net } fn post(url: string, body: string) -> Result[Response, string] needs { net } fn send(req: Request) -> Result[Response, string] needs { net }
post defaults Content-Type to application/json. send gives full control over method, headers, and body. All requests have a 30-second timeout.
Correlation IDs: outbound requests automatically include the X-Request-ID header when a correlation ID is set on Effects.
std/fs
File system operations. All functions require needs { fs }.
Types
type FileInfo = struct { name: string, size: int, is_dir: bool }
Functions
fn read(path: string) -> Result[string, string] needs { fs } fn read_lines(path: string) -> Result[[]string, string] needs { fs } fn write(path: string, content: string) -> Result[bool, string] needs { fs } fn append_file(path: string, content: string) -> Result[bool, string] needs { fs } fn list(path: string) -> Result[[]FileInfo, string] needs { fs } fn exists(path: string) -> bool needs { fs } fn mkdir(path: string) -> Result[bool, string] needs { fs }
std/env
Environment variable access. Requires needs { io }.
Types
type EnvVar = struct { name: string, value: string }
Functions
fn get(name: string) -> Result[string, string] needs { io } fn get_or(name: string, default: string) -> string needs { io } fn set(name: string, value: string) -> Result[bool, string] needs { io } fn all() -> []EnvVar needs { io }
std/log
Leveled logging to stderr. Requires needs { log }.
fn debug(message: string) needs { log } fn info(message: string) needs { log } fn warn(message: string) needs { log } fn error(message: string) needs { log }
Output format: [LEVEL] message or [LEVEL] [correlation-id] message when a correlation ID is set.
std/os
Process-level operations. args() is pure; all others require needs { io }.
fn args() -> []string // no effects (pure) fn exit(code: int) needs { io } fn getwd() -> Result[string, string] needs { io } fn hostname() -> Result[string, string] needs { io }
args() returns command-line arguments excluding the binary name.
std/crypto
SHA-256 hashing and hex encoding. No effects required.
fn sha256(data: string) -> sha256 fn hex_encode(hash: sha256) -> string
std/time
Wall-clock access. No effects declared on functions.
fn now() -> time fn fixed(value: string) -> time // parse RFC3339: "2025-01-15T10:30:00Z"
fixed is for deterministic tests — use with using time = time.fixed("...") to freeze the clock.
std/llm
LLM primitives. generate and tokens require needs { llm }.
fn prompt(model: string, input: string) -> Result[string, string] fn generate(model: string, prompt: string) -> Result[any, string] needs { llm } stream tokens(prompt: string) -> string needs { llm } buffer: 16
Structured output
When llm.generate is used with a type annotation, the compiler extracts a JSON Schema:
type Analysis = struct { summary: string, score: int, } let result: Analysis = llm.generate("claude-sonnet-4-20250514", "Analyze this")?
The LLM is constrained to produce output matching the schema.
std/server
HTTP server types and response helpers. See Servers.
Types
type Header = struct { name: string, value: string } type Param = struct { name: string, value: string } type Request = struct { method: string, path: string, body: string, headers: []Header, query: string, request_id: string, params: []Param, } type Response = struct { status: int, body: string, headers: []Header }
Response constructors
fn text(status: int, body: string) -> Response fn json_response(status: int, body: string) -> Response fn error_response(status: int, message: string) -> Response fn redirect(status: int, location: string) -> Response
Helpers
fn get_param(params: []Param, name: string) -> string
std/supervisor
Supervised agent execution. Run functions require needs { llm }. Trace/summary require needs { io }.
fn run(agent_name: string, prompt: string) -> Result[string, string] needs { llm } fn run_with_retry(agent_name: string, prompt: string, max_retries: int) -> Result[string, string] needs { llm } fn run_with_timeout(agent_name: string, prompt: string, timeout_secs: int) -> Result[string, string] needs { llm } fn run_with_options(agent_name: string, prompt: string, options: string) -> Result[string, string] needs { llm } fn trace() -> Result[string, string] needs { io } fn summary() -> Result[string, string] needs { io }
agent_name is a string matching a declared agent name. The supervisor adds:
- Retry: automatic re-execution on failure
- Timeout: time limit for the entire agent run
- Tracing: JSON trace of every LLM call and tool dispatch
- Summary: human-readable stats (
turns: 5, tool_calls: 3, duration: 2340ms, status: ok)
std/memory
Persistent key-value store with namespaces. All functions require needs { fs }.
Default namespace
fn set(key: string, value: string) -> Result[string, string] needs { fs } fn get(key: string) -> Result[string, string] needs { fs } fn keys() -> Result[string, string] needs { fs } // returns JSON array fn delete(key: string) -> Result[string, string] needs { fs } fn clear() -> Result[string, string] needs { fs }
Namespaced operations
fn set_ns(namespace: string, key: string, value: string) -> Result[string, string] needs { fs } fn get_ns(namespace: string, key: string) -> Result[string, string] needs { fs } fn keys_ns(namespace: string) -> Result[string, string] needs { fs }
Context for prompts
fn context() -> Result[string, string] needs { fs } fn context_ns(namespace: string) -> Result[string, string] needs { fs }
context() returns all key-value pairs as "key: value\n" lines — designed for injection into agent system prompts.
Persistence: data is stored in .cleat-memory.json in the current directory (configurable via CLEAT_MEMORY_PATH environment variable).