# Trust audit

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

> List every place a Sakura project asks to be trusted instead of checked, with sakura audit.

`sakura audit` lists every place in your project where the code asks to be trusted instead of
checked. Run it before you review an agent's work: these are the lines a human should read
first.

```sh
sakura audit src
sakura audit --json src
```

## What it lists [#what-it-lists]

| Site | What it is |
| --- | --- |
| `trust` | An `@trust("reason")` expression: the code vouches for a value the compiler cannot check. The record keeps the reason and the **sink**, the function that receives the trusted value. |
| `total` | A function marked `@total`: its author promises, without proof, that it finishes on every input, so contracts may call it. |
| `external` | An `@external` declaration: a function written in the host language (such as JavaScript), outside the compiler's checks. |
| `resource` | A type marked `@resource`, such as an open file that must not outlive its scope. |
| `from` | An explicit `T.from(...)` call that converts a value into a **refined type** (a type with a limit, such as `Int where it > 0`) and checks the limit at run time. |

Only your own package is listed; the standard library is not. The
[build manifest](/docs/agents/build-manifest) includes the standard library's trusted parts.
The human report groups the sites by file.

## An example [#an-example]

This program checks and runs. Its audit has one `total`, one `from` and one `trust` site:

```sakura
@total
fn identity(n: Int) -> Int { n }

type Positive = Int where it > 0

pub fn main() -> Unit ! {Console} {
  let n = Positive.from(identity(1))
  let raw = Untrusted.of(n)
  Console.print("{Untrusted.trust(raw, @trust("locally constructed positive value"))}")
}
```

## JSON output [#json-output]

`--json` writes JSON Lines, one record per line. Each site is a record with
`schema_version: "1.0"`, `kind: "audit"`, `site`, `symbol_id`, `span` and `reason` (which can be
null). `trust` and `from` records also name the resolved `sink`. Spans give the source URI,
content hash and byte range. The last record is an `audit_summary` with the snapshot hash
(`snapshot`), the number of sites (`sites`) and the count for each kind of site (`by_site`).

An audit is a list, not a type check or a security certificate. It exits 0 whatever sites it
finds, though loading and usage errors can still fail it. Run `sakura check` separately.

## Literal conversions [#literal-conversions]

A literal given a refined type, such as `let p: Positive = 5`, is checked while compiling when
the compiler can decide it; then it needs no run-time check and is not listed. A literal the compiler cannot decide keeps a check when
the program starts. It is listed as a `from` record with `reason: "literal"`, at the literal,
with the refined type's `from` as its `sink`. See
[contracts](/docs/tour/contracts#literal-refinements-at-compile-time).
