---
name: bevia-app-builder
description: Build or review a program that talks to a running Bevia Local engine through @bevia/sdk or the HTTP protocol — a sensor that sends evidence in, a surface that reads the governed World out, an automation on events, an AI client on the MCP door, or a check against Verify's published evidence. Use for app-side TypeScript, JavaScript, Python or any language that speaks HTTP. Not for changing the engine or the SDK's internals.
---

# Bevia app builder

Build against the public doors of a running Bevia Local engine. The SDK
(`@bevia/sdk`) is a convenience over the protocol; if the target language
has no SDK, the protocol document is the SDK.

Links below are relative to this skill inside the SDK's source. If the
skill was copied elsewhere, the same files are `README.md`, `AGENTS.md`
and `examples/` in the `@bevia/sdk` source, and the protocol is at
`https://www.bevia.co/build/PROTOCOL.md`.

## 1. Start from the program's requirements

Establish, from what the person said and from the code you can see:

- **Direction.** Evidence in (a sensor), the World out (a surface),
  reacting to events (an automation), an AI reading through MCP, or a
  reality check against Verify. Most programs are one of these.
- **Source.** For a sensor: what the source is, what one record looks
  like, the source's own ids and timestamps, and whether records carry
  typed fields worth sending as `record`.
- **Engine.** Where it is reachable and how the token arrives:
  `~/Bevia/Developer/bevia-workspace.json` (written by the desktop app),
  `BEVIA_ENGINE_URL` + `BEVIA_TOKEN`, or a pairing code from the app.
- **Mode.** One engine, two product modes, both with MCP. A Bevia engine
  serves the full door set and `POST /mcp` with its whole tool family. A
  Verify engine serves pairing, `POST /intake/capture`, `GET /health` and
  `POST /mcp` with four tools, `reality_check` (the main one),
  `nuance_briefing`, `verify_holds` and `verify_brief`; every other door, `whoami`
  and `intake.validate` included, answers `wrong_mode`. `health()` names
  the mode. Ask the person which they run if it is not visible.

Ask only for choices that change the implementation. Read
[`AGENTS.md`](../../AGENTS.md) before writing anything.

## 2. Connect and learn what the token may do

```ts
import { connectLocal, BeviaClient, BeviaError } from "@bevia/sdk";
const bevia = await connectLocal();          // workspace file, or BEVIA_ENGINE_URL + BEVIA_TOKEN
const me = await bevia.whoami();             // { name, kind, capabilities, pending }
```

On a Verify engine `whoami()` answers `wrong_mode`; `health()` says
`mode: "verify"` and the token's `read` capability is what `POST /mcp`
needs. Every door is gated by a capability (`capture`, `read`, `ask`,
`subscribe`, `propose`, `source_contract`, `substrate_export`). A
`BeviaError` with `status: 401` carries the capability the door needs.
Say so to the person; never work around it. Capabilities are listed in
[`README.md`](../../README.md) under "Capabilities".

## 3. Evidence in: the sensor loop

1. Build a capture: stable `thread_id`, `source_platform`, `source_kind`,
   `conversation[]` of turns with the real `speaker`, the full `text` and
   the source's `emitted_at`. Put the source's own id in `upstream_id` and
   its typed fields in `record` (JSON only, 32 KiB, never authority).
2. `await bevia.intake.validate(capture)` until it is valid. It writes
   nothing and names what is wrong.
3. `await bevia.intake.submit(capture, envelope?)`. Re-sending the same
   `thread_id` upserts, so retries are safe. Up to 500 turns per request;
   split longer streams across requests with the same `thread_id`.
4. Never set `evidence_shape` or any authority field; the SDK throws
   `caller_may_not_declare` before sending.

For a custom source with declared structure, register a source contract
(`contracts.propose`, which needs the `source_contract` capability) and
qualify the adapter (`qualify`). A well-formed contract is active the
moment it arrives; there is no approval step. The owner may revoke it from
the app. See the README's "Registering a custom source" and "Qualifying an
adapter".

## 4. The World out: the surface loop

- `bevia.world.current()` returns the governed current World, typed. It
  is `null` until the engine has published. Never count durable rows as
  the World; the current projection is the World. 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.
- `bevia.world.inspect(id)` says why a Matter or relation exists.
- `bevia.attention()` is what the publisher selected as worth noticing.
- `bevia.world.history()` and `world.at(manifest)` read past
  publications exactly as they were.
- `bevia.ask(question)` spends the owner's fuel and may answer with
  `posture: "clarify"`; send the choice back and the Ask continues.

A surface renders what the engine published. It never computes its own
map, never merges reads into a judgment, and cites the refs it was given.

## 5. Events: the automation loop

```ts
for await (const ev of bevia.events.subscribe({ kinds: ["world.published"] })) { /* … */ }
```

Events carry ids, not evidence text. Read the substance through the read
doors. Every event id is a cursor; resume with `after`.

## 6. Propose, get authorized, report

`bevia.propose(...)` says what the program thinks or wants to do. The
owner decides in the app. `proposals.awaitResolution(id)` waits for that
decision. If an `action` is accepted, the program carries it out itself
and reports with `proposals.report(id, { outcome, summary })`. The report
becomes evidence. Never claim acceptance you did not read.

## 7. An AI surface: the MCP door

`bevia.mcp.tools()` lists the current tool family; `bevia.mcp.call(name,
args)` calls one. Discover, never hardcode. Start from `bevia_brief`,
`bevia_ground`, `bevia_challenge`, `bevia_what_changed_since` and
`bevia_what_am_i_missing`. Each returns a governed packet the AI reasons
from and cites. `bevia_capture` is the one write tool on this door.

## 8. A reality check: the Verify door

```ts
const r = await bevia.realityCheck({ question: "did the last agent finish this?", project: "my-repo" });
if ("code" in r && r.code === "not_published") { /* say exactly that; ask again after the next publication */ }
else console.log(r.answer.word, r.answer.line, r.answer.safe_to_assume);
```

The result names the publication it read. Each rung (DECIDED, CLAIMED,
LOCAL, COMMITTED, PUSHED, MERGED, CHECKED AT REVISION, CURRENT) is
observed, unsupported or unobservable. Print `answer` as given. Never
reconstruct the answer from git yourself and present it as Verify's.

The same door serves three more read-only tools, each typed:
`nuanceBriefing()` (what stands now on one job, and what was set aside),
`verifyHolds()` (whether the person recorded a hold on some paths or an
area) and `verifyBrief()` (one whiteboard in plain words). For holds,
branch on `held`, never on the text; none recorded is not a go-ahead.
Read `mcp.tools()` first: an engine without a World lists
`reality_check` alone.

## 9. Validate the changed behaviour

- Run the program against a real engine with a test token, or against a
  fake `fetch` that answers the doors it uses. `BeviaClient` accepts a
  `fetch` for exactly this.
- Exercise the refusal paths: a 401 names its capability; a Verify engine
  answers `wrong_mode` on doors it does not serve; `not_published` is an
  honest answer, not an error to retry.
- State exactly which checks ran. Do not claim a door works because the
  code compiles.

## Never

- Read or write the engine's data directory, vault or config.
- Summarize, rank or filter evidence on the way in.
- Set event time to "now" for things that happened earlier.
- Declare authority on a capture, a turn, metadata or the envelope.
- Send the owner's evidence, tokens or World to any other host.
- Present a reconstruction as a Verify result.
