Sakura Lang

Overview

How an AI coding agent works with Sakura Lang - the skill to install, the tools it calls, and the loop from signature to tested code.

This section is for anyone who has a coding agent (Claude Code, Codex, Cursor and others) write Sakura Lang, and for people building tools around the compiler. It covers what to give the agent, which compiler tools it calls, and the loop it follows.

Stable

v1.0.0 is the current release, and it is stable: what the Stability page lists keeps working across 1.x, and a breaking change waits for 2.0. A security fix that has to break something comes with a migration in the changelog. Native, packages and workers are experimental and may change. These docs follow the main branch, which can be ahead of the latest release. See Stability for what you can rely on and Changes for what each release changed.

The idea in one paragraph

Agents write the code; humans review the signatures. A signature is everything a function promises from the outside: its parameter and result types, any refinements on them (limits such as where it > 0), its effect row (the side effects it may perform, such as Console or Http, written after !), the errors it can fail with, and its contracts (requires for what callers must guarantee, ensures for what the function guarantees back). An agent fills in bodies to match; a reviewer reads the signatures and how they changed.

The working loop

Use this loop with the sakura command line (CLI) or the compiler's MCP server. A check that passes can still contain unfinished parts, so always finish with tests and a build.

The agent loop: check, read structured records, fix by impact, and check again until clean.{ ?body }: signatures first; bodies as holes. sakura check --json: one JSON Lines record per hole or problem. Then sakura test --json or sakura fix. sakura fix: fill holes; apply fixes by impact class. Then sakura check --json. sakura test --json: once check is clean. sakura build: rejects any hole still left.{ ?body }signaturesfirst; bodies asholessakura check--jsonone JSON Linesrecord per holeor problemsakura fixfill holes;apply fixes byimpact classsakura test--jsononce check iscleansakura buildrejects any holestill left

Report every signature, effect, error or permission change to the reviewer.

The agent loop: check, read structured records, fix by impact, and check again until clean.

Load the language

Read docs/llms.txt once per session, or run sakura prompt, which prints the same file. It is the whole core language in one file. Look up library functions with the MCP symbol_query tool instead of guessing; sakura doc --search does the same offline.

Write signatures first, bodies as holes

A typed hole is a placeholder, ?name, for code not written yet:

fn clamp(x: Int, lo: Int, hi: Int) -> Int
  requires ordered: lo <= hi
  ensures bounded: lo <= result && result <= hi
{
  ?body
}

sakura check accepts holes. The signatures are what a human reviews, so get them right first.

Check

Run sakura check --json, or call the MCP check tool. Each typed hole comes back as a hole record: the type it must have, the effects allowed there, the local variables in scope, and ranked suggestions.

Fill holes and fix diagnostics

Each problem comes back as a diagnostic record with a stable code (such as V3001), the exact place in the source, what was expected and what was found, and suggested fixes. See Diagnostics. sakura explain V3001 explains a code.

Apply fixes by impact

Every fix says what it changes, its impact. local fixes marked machine_applicable are safe to apply. Fixes with impact interface_change, contract_change or authority_change are never machine_applicable, and sakura fix never applies the last two. Then run sakura test --json and sakura fmt.

Report signature changes

If the task really needs a new effect, error, permission or a changed contract, make the change and list it for the reviewer. To stop an agent from editing the spec to make a check pass, run --frozen-specs all --since <baseline> against the agreed Git revision; MCP callers pass frozen_specs: "all" on both patch calls. Run sakura build after the tests: it refuses any hole that is left.

What an agent should never do

  • Add an effect, error tag or [permissions] entry without flagging it.
  • Weaken or delete a requires, ensures or where clause, or edit a test body, to make a check pass. A contract violation (D020, D021) means the caller or the function is wrong, not the spec.
  • Use .trust(@trust("...")), Secret.expose, .expect or Email.from outside trusted boundaries, or without a true reason.
  • Leave a ?hole in code meant to build. sakura build and sakura run reject it with V2050.
  • Borrow syntax from other languages: call-site type arguments (f<T>(x), V0011) and named arguments (f(name: v), V0014) do not exist. Annotate the binding (let rows: List<User> = Sql.query(q)) and pass a record for options. Import every name outside the prelude explicitly (import std/http.{Http} and import std/request.{Request}).

Install the Sakura skill

A skill is a folder of instructions an agent loads on demand. The sakura skill teaches the compiler workflow, with examples and common repairs. Read the raw SKILL.md, or download the complete skill ZIP with its SHA-256 checksum and content manifest.

  1. Verify the ZIP: shasum -a 256 -c sakura-skill.sha256.
  2. Extract its sakura/ folder into one project-local skill directory: .claude/skills/sakura/, .agents/skills/sakura/ or .cursor/skills/sakura/.
  3. Keep its references/ and any assets/ next to SKILL.md.

The files are a byte-identical copy of skills/sakura/ in the repository. The manifest records the compiler version, every file's SHA-256 and the ZIP's SHA-256, but no Git commit, so the same source always produces the same files. The website follows the current source; your installed compiler carries its own matching copy, filled in from its version and the SAKURA_GIT_COMMIT it was built with. Prefer the compiler's copy when versions differ. For a URL that never changes, pin a commit: https://raw.githubusercontent.com/icantcodefyi/sakuralang/<commit>/skills/sakura/SKILL.md.

What to read

ResourceWhat it is
docs/llms.txtThe language reference for agents: the whole core language in one file.
/llms.txtAn index of every page on this site, with titles, descriptions and URLs.
/llms-full.txtEvery page on this site in one Markdown file.
/docs/<page>.mdAny page on this site as Markdown: add .md to its URL. The docs root is /docs.md.
Copy as MarkdownA button at the top of every page, next to a menu with the .md link and the GitHub source.

The two llms.txt files are different things; see llms.txt.

The tools

ToolWhat it does
sakura check --jsonReports diagnostics, holes and a summary as JSON Lines (one JSON object per line).
?name typed holesPlaceholders the checker describes: expected type, effects, locals and suggestions.
sakura promptPrints the embedded language guide; --budget drops whole sections to fit a size. Look up signatures with sakura doc.
sakura fix, --frozen-specsApplies compiler fixes by impact, and refuses patches that touch frozen specs.
sakura auditLists every place the code asks to be trusted.
sakura docSearches signatures offline.
sakura build --manifestRecords what a build trusts and which contract checks it keeps.
sakura verifyProves contracts and arithmetic safe, or finds a counterexample.
sakura test --recordRecords HTTP and model exchanges once; ordinary tests replay them offline.
sakura mcp serveRuns the compiler as Model Context Protocol tools.

The roadmap says what is finished, experimental and planned.

Pages in this section

For contributors

The design document explains the reasoning behind these tools (section 12 covers the agent interface). It is provisional and includes decisions not built yet; the compiler and its matching guide say what is available.

Edit on GitHub

Last updated

On this page