# Building on Bevia — instructions for a coding agent

You are building a program that talks to a running Bevia Local engine:
a sensor that sends evidence in, a surface that reads the governed World
out, an automation that reacts to events, an AI client on the MCP door,
or a check against Verify's published evidence. The engine is an HTTP
daemon the owner runs; your program connects to it and never the other
way round. This file is identical for every coding agent (`CLAUDE.md`
beside it includes it).

If you are changing the SDK itself rather than building on it, the
boundary rules below still bind, and the contribution rules of the
repository you are in govern the rest.

## Read first

- `README.md` beside this file: every operation, with examples.
- `PROTOCOL.md`: the contract the SDK wraps. On the web it is
  `https://www.bevia.co/build/PROTOCOL.md`; the public SDK repository
  carries it as `docs/reference/protocol.md`; the desktop app writes a
  copy into every developer workspace. If this README and the protocol
  disagree, the protocol wins.
- `skills/bevia-app-builder/SKILL.md`: the build loop, step by step.

## The architecture in five lines

1. **Evidence in.** `intake.submit` carries what happened, verbatim, with
   the time it happened. The engine decides what it means.
2. **The World out.** `world.current()` is the governed current World:
   Matter, standing, condition history, relations, receipts by exact
   identity. Every read answers from a publication, never from live state. It is the whole World, so the engine answers it only to the World's owner (the Bevia app, or a program the owner granted `control`); a program with `read` alone gets 403 `whole_world_owner_only` and reads one understanding at a time with `world.inspect(id)`, or asks.
3. **Events.** `events.subscribe` says what happened, as ids. Read the
   substance through the read doors.
4. **Propose, get authorized, report.** A proposal establishes nothing;
   the owner decides in the app. An accepted action is yours to carry out,
   and the receipt you report becomes evidence.
5. **MCP.** `POST /mcp` serves the same tools Bevia's own AI clients get.
   In Verify mode it serves four read-only tools: `reality_check` (the
   main one), `nuance_briefing`, `verify_holds` and `verify_brief`.

## Rules that are not negotiable

- **Talk only to the HTTP doors.** Never read or write the engine's data
  directory, vault folders or config files. The protocol is the only
  supported seam; it is what keeps your program working across engine
  upgrades.
- **Send what was, not what you concluded.** No ranking, filtering,
  summarizing or interpreting on the way in. Deciding what matters is the
  engine's job. Send the full text with the real speakers.
- **Event time is the source's time.** `emitted_at` is when the thing
  happened, not when you sent it. Old material keeps its original dates.
- **Stable identities.** Pick a `thread_id` scheme and a `source_kind` and
  keep them. Re-sending upserts, so honest ids make your sensor idempotent.
  `upstream_id` is the source record's own identity; `thread_id` is not.
- **Never declare authority.** A caller may not set `evidence_shape`,
  `source_object`, `source_state`, `source_attestation`, `standing`,
  `scoring_basis`, `establishment_basis`, `role_basis`, `authority` or
  `trusted` at any level of a capture, a turn, a turn's metadata or the
  envelope. The SDK refuses them before they leave; the engine refuses
  them again. A `record` field is faithful source content, never a claim
  about what it means.
- **A 401 names a capability.** `whoami()` says what the token may do; the
  owner grants more from the app. Never ask the owner for the host token,
  never work around a refusal, never read `bevia-workspace.json` from
  anywhere but the developer workspace.
- **Proposals establish nothing.** Never claim a proposal was accepted;
  read the ledger or the event. Never act without an accepted `action`.
- **Verify observes, it never judges.** A `reality_check` result says what
  was decided, claimed, committed, pushed, merged, checked and still
  current, each observed, unsupported or unobservable. None of its rungs
  means "correct". Print its `answer` as given; do not compose your own.
  Ask about holds with `verifyHolds()` and branch on `held`, never on the
  text. No hold recorded is not a go-ahead; when in doubt, ask the person.
- **Nothing phones home.** Your program talks to an engine on the owner's
  machine or one the owner made reachable. Never send the owner's
  evidence, tokens or World anywhere else.

## Where things live

| Need | Go to |
|---|---|
| Connect, evidence in, World out, ask, events, propose | `README.md` |
| Every door, its capability, its refusals | `PROTOCOL.md` |
| The build loop for a new program | `skills/bevia-app-builder/SKILL.md` |
| Working scripts | `examples/` (`quickstart.mjs`, `sensor.mjs`, `calendar-ics.mjs` (a connector: a calendar file in as evidence), `thesis-guard.mjs`, `timeline.mjs`, `handoff-brief.mjs`, a stdlib-only Python client in `examples/python/`) |
| What an adapter may declare about a custom source | `README.md` under "Registering a custom source" and "Qualifying an adapter" |

## Validate what you built

- `npm run build` compiles the SDK. `npm run check:examples` then
  type-checks every example against the built SDK's declarations.
- Where the SDK is developed, `npm test` also runs the mutation guard,
  the qualification samples and the contract-drift proof against a real
  published World, and `npm run audit:surface` proves the package ships
  only the public doors. Both run before every publish and fail closed.
- For your own program: `intake.validate(capture)` is the dry run that
  writes nothing and says exactly what is wrong. Fix until it is valid,
  then `intake.submit`.
- Report exactly which checks you ran. A check you did not run is not
  coverage.

## What you may not add to the SDK

No engine code, no database driver, no owner-only route, no credential,
no dependency, no transport but `fetch`, no door the protocol does not
publish. The publish audit reads every shipped byte and refuses each of
these by name.
