1agent Reviewer {
2 model: "claude-sonnet-4-5"
3 tools: [read_file, list_files]
4 max_turns: 8
5 system: "Code reviewer."
6}
7
8let r: Review = Reviewer.run(diff)?
Agent
Code review agent
An LLM-powered code reviewer that reads files with tool calls and returns a typed Review struct. Ships with structured output and correlation tracing.
1guard no_secrets(s: string)
2 -> GuardResult
3{
4 if strings.contains(s, "sk-") {
5 return Deny("api key")
6 }
7 return Allow
8}
Guard
Content policy guard
Pre-flight policy check that blocks API key leaks and prompt injection attempts before a tool or agent runs. Composable with @attach.
1server API {
2 port: 8080
3 GET "/users/:id" -> get_user
4 POST "/users" -> create_user
5 middleware: [log, auth]
6}
7
8fn get_user(id: string) -> User
Server
Typed HTTP server
A complete REST API with typed handlers, logging, and auth middleware. Routes are compile-checked against handler signatures — no runtime surprises.
1import "std/io"
2
3fn main() -> int needs { io } {
4 io.println("hello from cleat")
5 return 0
6}
Basics
Hello, world
The smallest possible Cleat program. Demonstrates the needs clause on main.
1tool analyze(repo: string, pr: int)
2 -> Result[Analysis, string]
3 needs { net }
4 timeout: 30s
5 retry: 2
6{
7 let url = "https://api/${repo}/pr/${pr}"
8 let resp = http.get(url)?
Tool
PR analyzer
Fetches a pull request, parses the diff, returns a typed risk assessment. The canonical Cleat tool example.
1stream tokens(prompt: string) -> string
2 needs { llm }
3 buffer: 16
4{
5 let stream = llm.stream(prompt)
6 for chunk in stream {
7 yield chunk.text
8 }
9}
Stream
LLM token stream
Streams tokens from an LLM with backpressure-aware buffering. Wraps std/llm for safe consumption.
1state PRReview {
2 initial: Pending
3 Pending -> InReview { when: assigned }
4 InReview -> Approved {
5 when: approved && ci_green
6 }
7 Approved -> Merged { when: merged }
8 any -> Cancelled { when: closed }
State
PR review state machine
A complete pull request lifecycle modeled as a state machine with reachability checks at compile time.
1chain AuditTrail {
2 signing: ed25519
3 @retention(7y)
4 record Entry {
5 source: string,
6 action: string,
7 hash: sha256,
8 timestamp: time,
9 }
Chain
Cryptographic audit chain
Signed, append-only log of every action your AI takes. Ed25519 signatures, SHA-256 content addressing, 7-year retention.
1import "std/http"
2import "std/json"
3
4tool fetch_json(url: string)
5 -> Result[json.Value, string]
6 needs { net }
7 timeout: 10s
Tool
HTTP JSON fetcher
Generic HTTP GET with JSON parsing and typed error returns. Common building block for API integrations.
1tool process_files(dir: string)
2 -> Result[int, string]
3 needs { fs }
4{
5 let files = fs.list(dir)?
6 let count = files
7 |> filter(fn(f) f.endswith(".txt"))
Tool
Batch file processor
Walks a directory, filters by extension, processes each file. Demonstrates the pipe operator and std/fs.
1state OrderWorkflow {
2 initial: Cart
3 Cart -> CheckedOut {
4 when: payment_authorized
5 }
6 CheckedOut -> Shipped {
7 when: warehouse_picked
8 }
State
E-commerce order workflow
Cart → Checkout → Shipped → Delivered with refund branches. Shows guards, terminal states, and rollback patterns.
1stream pipeline(source: string)
2 -> Record
3 needs { net, fs }
4 buffer: 64
5{
6 for raw in read_chunks(source) {
7 let parsed = parse(raw)?
8 yield enrich(parsed)
Stream
ETL pipeline
Streaming extract → transform → load with bounded buffers. Backpressure ensures upstream slows when downstream lags.
1type RateLimiter = struct {
2 capacity: int,
3 tokens: float,
4 refill_rate: float,
5}
6
7tool try_acquire(l: RateLimiter)
8 -> bool needs { time }
Tool
Token bucket rate limiter
A leaky-bucket rate limiter with deterministic test clocks for repeatable tests. No flakiness.
1tool resilient_call(url: string)
2 -> Result[http.Response, string]
3 needs { net, time }
4 timeout: 5s
5 retry: 5
6 backoff: exponential
7{
8 return http.get(url)
Tool
Resilient HTTP with backoff
Demonstrates declarative retry policies with exponential backoff. Five lines of config, zero glue code.
1tool agent_step(state: AgentState)
2 -> Result[Action, string]
3 needs { llm, net }
4{
5 let reasoning = llm.complete(state.prompt)?
6 let action = parse_action(reasoning)?
7 AuditTrail.append(action)
Tool
Chain
Agent reasoning loop
A complete agent: LLM reasoning, action parsing, tool execution, audit trail. Combines three primitives.