# Overview

URL: /docs/agents
Markdown: /docs/agents.md

> 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](/docs/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](/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](/docs/stability) for what you can rely on and [Changes](/docs/changes) for what
> each release changed.

## The idea in one paragraph [#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 [#the-working-loop]

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

> **Diagram:** The agent loop: check, read structured records, fix by impact, and check again until clean.
>
> 1. `{ ?body }`: signatures first; bodies as holes.
> 2. `sakura check --json`: one JSON Lines record per hole or problem. Then `sakura test --json` or `sakura fix`.
> 3. `sakura fix`: fill holes; apply fixes by impact class. Then `sakura check --json`.
> 4. `sakura test --json`: once check is clean.
> 5. `sakura build`: rejects any hole still left.
>
> Report every signature, effect, error or permission change to the reviewer.

### Load the language [#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`](/docs/agents/doc) does the same offline.
### Write signatures first, bodies as holes [#write-signatures-first-bodies-as-holes]

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

```sakura holes
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 [#check]

Run `sakura check --json`, or call the MCP `check` tool. Each [typed hole](/docs/agents/typed-holes)
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 [#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](/docs/agents/diagnostics). `sakura explain V3001` explains a code.
### Apply fixes by impact [#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 [#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 [#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 [#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`](/skills/sakura/SKILL.md), or download the [complete skill ZIP](/skills/sakura-skill.zip)
with its [SHA-256 checksum](/skills/sakura-skill.sha256) and
[content manifest](/skills/manifest.json).

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/`](https://github.com/icantcodefyi/sakuralang/tree/main/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 [#what-to-read]

| Resource | What it is |
| --- | --- |
| [`docs/llms.txt`](https://github.com/icantcodefyi/sakuralang/blob/main/docs/llms.txt) | The language reference for agents: the whole core language in one file. |
| [`/llms.txt`](/llms.txt) | An index of every page on this site, with titles, descriptions and URLs. |
| [`/llms-full.txt`](/llms-full.txt) | Every page on this site in one Markdown file. |
| `/docs/<page>.md` | Any page on this site as Markdown: add `.md` to its URL. The docs root is `/docs.md`. |
| Copy as Markdown | A 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](/docs/agents/llms-txt).

## The tools [#the-tools]

| Tool | What it does |
| --- | --- |
| `sakura check --json` | Reports diagnostics, holes and a summary as JSON Lines (one JSON object per line). |
| `?name` typed holes | Placeholders the checker describes: expected type, effects, locals and suggestions. |
| `sakura prompt` | Prints the embedded language guide; `--budget` drops whole sections to fit a size. Look up signatures with `sakura doc`. |
| `sakura fix`, `--frozen-specs` | Applies compiler fixes by impact, and refuses patches that touch frozen specs. |
| [`sakura audit`](/docs/agents/audit) | Lists every place the code asks to be trusted. |
| [`sakura doc`](/docs/agents/doc) | Searches signatures offline. |
| [`sakura build --manifest`](/docs/agents/build-manifest) | Records what a build trusts and which contract checks it keeps. |
| [`sakura verify`](/docs/agents/verify) | Proves contracts and arithmetic safe, or finds a counterexample. |
| [`sakura test --record`](/docs/agents/cassettes) | Records HTTP and model exchanges once; ordinary tests replay them offline. |
| [`sakura mcp serve`](/docs/agents/mcp) | Runs the compiler as Model Context Protocol tools. |

The [roadmap](/docs/roadmap) says what is finished, experimental and planned.

## Pages in this section [#pages-in-this-section]

- [llms.txt](/docs/agents/llms-txt): The site's Markdown exports and the language's `docs/llms.txt`.
- [MCP server](/docs/agents/mcp): The compiler as tools an agent calls directly.
- [Diagnostics](/docs/agents/diagnostics): The JSON Lines format, error codes and fix impact.
- [Typed holes](/docs/agents/typed-holes): Writing programs a step at a time with `?name`.
- [Trust audit](/docs/agents/audit): Find every place the code asks to be trusted.
- [Offline API search](/docs/agents/doc): Look up signatures, effects and contracts with sakura doc.
- [Build manifest](/docs/agents/build-manifest): See what a build trusts and which checks it keeps.
- [Verify contracts](/docs/agents/verify): Prove contracts with a solver and read counterexamples.
- [Cassettes and recording](/docs/agents/cassettes): Replay HTTP and model exchanges offline; record them when you choose.

## For contributors [#for-contributors]

The [design document](https://github.com/icantcodefyi/sakuralang/blob/main/docs/design.md)
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.
