# OsBrain

> One verdict for every agent move across databases, cloud API calls and MCP tool calls: your own rules, one list of held moves, a sealed decision ledger.

Source: https://osevel.com/docs/products/osbrain/

OsBrain joins the decisions of the other Os products. It gives each move an agent makes
(a database write, a cloud API call, an MCP tool call) one verdict with a reason in plain words,
lists every move that waits for you in one place, and keeps one record of every decision.
It decides with fixed rules. No AI model takes part in a decision.

- [What it protects against](#what-it-protects-against)
- [Set up](#set-up)
- [How it works](#how-it-works)
- [What waits for you](#what-waits-for-you)
- [Your rules](#your-rules)
- [The decision ledger](#the-decision-ledger)
- [The coverage map](#the-coverage-map)
- [The OsBrain page](#the-osbrain-page)
- [With the other Os products](#with-the-other-os-products)
- [Limits](#limits)

## What it protects against

- **Rules that live in three places.** Database rules, API rules and tool rules do not know about
  each other. One OsBrain rule such as "in production, hold every dangerous move" applies to all
  three.
- **Held moves you do not see.** A database change and a cloud API call that both wait for you
  are in one list, not in two tools.
- **A record nobody can check.** Every decision is a line in a hash chain whose latest line is
  sealed in Osevel's cloud. A removed or rewritten line shows.
- **Blind spots.** The coverage map lists what agents on this computer can reach without Osevel
  seeing it.

## Set up

OsBrain has no install step of its own. It is part of the CLI and runs as soon as you use
[OsBase](https://osevel.com/docs/products/osbase/), [OsApi](https://osevel.com/docs/products/osapi/) or [OsBox](https://osevel.com/docs/products/osbox/).

```bash
npm i -g @osevel/cli
```

```bash
osevel brain status
```

`status` shows how many rules you have, whether the ledger's chain holds, and how many moves
were held or refused in the files kept.

With the Osevel service installed (daemon mode, see [security](https://osevel.com/docs/security/model/#two-modes-unisolated-and-daemon)),
the rules and the ledger live in the service's own folder, out of an agent's reach. Read and
change them through the root-owned launcher:

```bash
sudo /opt/osevel/bin/osevel brain status
```

Without `sudo`, the commands read the rules and the ledger of runs in your own user's process.
The service exists on macOS and Linux, not on Windows.

## How it works

1. An agent makes a move through an Os product.
2. The product judges it as it always did. OsBase classifies the SQL and applies your policy.
   OsApi reads the call against its catalogue. OsBox checks the tool against its pin.
3. OsBrain turns that into one shape: the move (product, target, operation, class, environment)
   and a verdict: `through`, `held` or `refused`.
4. OsBrain applies your own rules. A rule can only ask for more: `through` can become `held`
   or `refused`, `held` can become `refused`. Nothing a product held or refused is let through.
5. The product answers the agent. The decision is written to the ledger in the background.

Every move has a class: `read`, `change`, `danger` or `unknown`. The decision is made on your
computer. The cloud is not on the path.

If your rules cannot be read, every change waits for a person until the file is fixed. If
OsBrain cannot judge a database write at all, that write waits for a person too.

## What waits for you

```bash
osevel brain holds
```

lists every move waiting for a person on this computer, soonest to expire first: calls held by
OsApi and the approval requests of every database in your store. Each line gives the command
that decides it. Deciding stays with the product, because its own command shows the whole move
and asks for a typed code:

- a database change: `osevel approve <id>` or `osevel deny <id>` (see [usage](https://osevel.com/docs/getting-started/usage/));
- a cloud API call: `osevel api approve <id>` or `osevel api deny <id>` (see [OsApi](https://osevel.com/docs/products/osapi/)).

In the dashboard, the Inbox shows both kinds together and you decide with your passkey.

Your answer is written to the ledger: who answered, where (terminal or dashboard), and for a
dashboard answer the proof (the digest of the signed statement and the passkey assertion).

## Your rules

List them:

```bash
osevel brain rules
```

Add one. Name at least one condition; a rule that matches every move is refused:

```bash
osevel brain rules add --product osapi --class danger --then refuse --note "no deletes through APIs"
```

| Option          | Meaning                                             |
| --------------- | --------------------------------------------------- |
| `--product`     | `osbase`, `osapi`, `osbox` or `osvault`             |
| `--agent`       | An agent's name                                     |
| `--environment` | An environment, for example `production`            |
| `--class`       | `read`, `change`, `danger` or `unknown`             |
| `--operation`   | A product's operation name, for example `railway.*` |
| `--then`        | `hold` (the default) or `refuse`                    |
| `--note`        | A note for yourself                                 |

Two presets:

```bash
osevel brain rules preset production-asks
```

holds every `danger` and `unknown` move in production (name another environment with
`--environment`). For databases, the labels `prod`, `prd` and `live` count as `production`.

```bash
osevel brain rules preset read-only-agent --agent nightly-bot
```

refuses every move by that agent that is not a read.

Remove a rule by its id (`r1`, `r2`, …):

```bash
osevel brain rules remove r1
```

Adding a rule asks for more, so it needs no code. Removing one asks for less: it needs an
interactive terminal and a typed code. Every change is a line in the ledger. A rule applies to
the next move.

With the Osevel service installed, run these with `sudo /opt/osevel/bin/osevel brain rules …`.
Without `sudo` the command says that it changed only your own user's runs. Rules are never read
from `osevel.yaml`, because that file sits in the repository where an agent can edit it.

## The decision ledger

The ledger is a file of lines, each carrying the hash of the line before it. It holds operation
names, classes, verdicts, reason codes and proofs. It never holds SQL text, request bodies, keys
or values.

- Held moves always get their own line.
- Reads that went through are counted in a summary line. In a flood, changes that went through
  and refusals are counted too.
- Ten closed files are kept.

When the Osevel service runs the dashboard bridge, the latest line (its number and hash) is
sealed in Osevel's cloud every five minutes. The cloud refuses a seal that goes backwards. The
ledger is compared with its seal at start and every hour.

Check the chain yourself:

```bash
osevel brain verify
```

It exits with code 4 when the chain is broken. What it proves: nothing was changed by someone
who could not also rewrite every line after it. With the seal, lines before the last seal were
not changed or removed afterwards.

## The coverage map

```bash
osevel brain coverage
```

lists what agents on this computer can reach without Osevel seeing it. For each: where it was
found and the one step that covers it. It looks at:

- provider keys outside a vault (`.env` files, shell profiles, the environment, the CLIs' own
  sign-in files, git and npm credentials);
- other secrets OsVault recognises (Stripe, OpenAI, …) in plain `.env` files;
- services that were reached without a locked key;
- databases without the foreign connection watch.

It never prints a value: a few characters and the length only. It says what it does not look
at: the system keychain, and agents that run in someone else's cloud. `--dir <path>` reads
another folder; `--json` prints JSON.

## The OsBrain page

The dashboard's home shows an OsBrain card. Its page shows the API calls waiting for you, the
ledger's state (chain, lines, sealed up to), the latest decisions with the rule that asked for
more, your answers, and your rules. The rules are read-only there; the page gives the command to
change them. The page reads from your personal bridge; a team bridge shows none of it.

## With the other Os products

| Product               | What OsBrain judges                                                                |
| --------------------- | ---------------------------------------------------------------------------------- |
| [OsBase](https://osevel.com/docs/products/osbase/)   | Each agent write, before it runs, and each schema change. Reads are not judged.    |
| [OsApi](https://osevel.com/docs/products/osapi/)     | Every operation in a call. With several in one call, the strictest verdict stands. |
| [OsBox](https://osevel.com/docs/products/osbox/)     | Each tool call the gateway would forward.                                          |
| [OsVault](https://osevel.com/docs/products/osvault/) | Nothing. OsVault makes no per-use decision; its own refusals stay its own.         |

## Limits

- **Only what passes through Osevel.** An agent that uses its own keys elsewhere is not seen.
  The coverage map shows where that can happen on this computer.
- **A held tool call does not run.** OsBox tool calls cannot be approved one by one yet. The
  agent is told to ask you.
- **Rules for one named agent apply to database moves.** OsApi and OsBox moves are recorded
  under the name `agent`, because the run proxy and the box gateway do not know which agent runs
  them.
- **Some held moves are refused instead.** A rule that would hold an unlisted GraphQL read or an
  MCP `tools/list` refuses it, because there is nothing to bind an approval to.
- **No one command decides everything.** `osevel brain holds` lists; each product's own command
  decides.
- **Without the Osevel service**, the rules and the ledger are in your own folder, which an
  agent running as you can write. The cloud seal then only shows that something changed after
  the last seal.
- **Nothing is approved for you.** A held move waits for a person, then expires.
- **Not built:** approvals on a phone, and approval routing to a team for OsApi and OsBox moves.
  Database approvals keep the team rules they already have.

Related: [OsBase](https://osevel.com/docs/products/osbase/), [OsApi](https://osevel.com/docs/products/osapi/), [OsBox](https://osevel.com/docs/products/osbox/), [OsVault](https://osevel.com/docs/products/osvault/),
[security model](https://osevel.com/docs/security/model/).
