# The vault contract

What a vault command answers, so kebbie can run it as `vault.command`, whatever the package is called.

kebbie runs the command with its own arguments after the words you set, such as `uvx mindin about --json`. Every answer is JSON on stdout; a refusal exits non-zero with its reason on the last line of stderr.

A value kebbie cannot vouch for goes in the same word as its option, as `--line=<text>`, `--branch=<name>` and `--note=<path>`, so a log line that starts with `-` stays the line. The vault's parser takes `--option=value` as well as `--option value`.

## `about --json`

kebbie asks this first, at each `kebbie doctor` run and whenever its kept answer is older than 10 minutes.

```json
{
  "name": "mindin",
  "version": "0.14.0",
  "contract": 1,
  "capabilities": ["tasks", "claims", "log", "snapshot", "read"],
  "former_names": ["notes-vault-mcp"]
}
```

| Field | Type | What kebbie does with it |
| --- | --- | --- |
| `name` | string | The package's name, in `kebbie doctor` and in `kebbie update --check`. |
| `version` | string | The package's version, beside its name. |
| `contract` | number | `1` is this page. A higher number keeps the vault off until kebbie is updated, and `kebbie doctor` says so. |
| `capabilities` | list of strings | The calls kebbie makes. A call whose capability is not listed is never run. |
| `former_names` | list of strings, optional | Names the package had before. A `vault.command` word that is one of them makes `kebbie doctor` suggest the line with the new name. |

## Capabilities

| Capability | Calls kebbie makes | Without it |
| --- | --- | --- |
| `tasks` | `task open`, `task close`, `task backlog` | The vault is off for tasks: no notes. |
| `claims` | `task claim`, `task release` | Notes are kept, but claimed by no machine. |
| `log` | `log append`, `log path` | Pushes write no log lines. |
| `snapshot` | `snapshot --json [--since <etag>]` | The board reads the vault's local index instead. |
| `watch` | `watch --json --body [--since <cursor>]`, one long-lived process the keeper runs | The keeper asks for `snapshot` every 20 seconds and reads each changed backlog note with `read`. |
| `read` | `read <note> --body` | A plan in a vault note shows only from the local index. |
| `templates` | `template --json --kind task` | Local and vault items are drafted in kebbie's own sections. |
| `styles` | `style write --kind backlog --file - --version <n>`, the style on stdin | The vault holds no backlog style, and kebbie's bundled default applies. |
| `write` | `read --json -- <note>`, answering `{"text", "etag"}`, then `write --etag <etag> -- <note>` with the note on stdin, answering `{"path", "etag"}` | An edit from the phone to a vault backlog item is refused, and no task's card is written to `Kebbie/`. |

With `templates`, kebbie asks for the task template at most every six hours and keeps it in `item-template.json` in its state directory. An answer with no sections means the vault has no task template, and is kept as long; an ask that fails is tried again after ten minutes. kebbie drafts a short vault item in its sections, and the phone shows an item's sections in its order. An item is read in whatever shape it was written: its questions are the bullets under its questions heading, `Open questions` or `Öppna frågor`, and it is to write only while it is a draft.

## The card note

A task with a vault note gets its sign-off card in the vault while it stands under Ready to push on the board, one note per task at `Kebbie/<task note>-card.md` (`-card-<repo>.md` for a half whose repo does not start the task note's name):

```markdown
---
title: "Export the invoices"
tags: [kebbie, card]
status: active
up: "[[web-export]]"
kebbie-card: "export@web"
push: ready
---

## Built
…
```

- The keeper writes it every 30 seconds while the card changed, or an open board does without the keeper; an unchanged card is not written again.
- A task that leaves Ready to push only has its `push` line changed, `pushed` while its CI runs and `waiting` otherwise; the rest of the note, frontmatter you added included, stays as it is.
- kebbie rewrites only a note whose `kebbie-card` names the task and whose body is still the card kebbie last wrote there. A note you wrote in, a note kebbie has no record of writing, or any other note at that path is left as it is, and kebbie says so once in `vault.log`.
- `kebbie done`, a drop and a reset close the card note with `task close`, which moves it to the archive beside the task note. When that fails, or the vault is off, the keeper's card routine closes it later, and only while its body is still the card kebbie wrote; a later task at the same address starts with no card of its own.
- A failed write is one line in `vault.log`, and in the keeper's `keeper.log`; the task's push waits for nothing.

## The backlog style

kebbie owns how a backlog item reads, and keeps its rules in the vault, where the vault hands them to any agent that files an item there, kebbie's or not. The default ships in kebbie as `styles/backlog.md`, its first line stamping its version as `<!-- style-version: N -->`.

- `kebbie setup`, the end of `kebbie update` and the keeper's start write it to `.vault/styles/backlog.md` with `style write`. A vault already at that version, or holding a newer one, keeps its own, and kebbie says nothing; any other refusal is one line, in the keeper's in `keeper.log`, said once until it changes or a write goes through.
- kebbie writes nothing else under `.vault/`: never the schema, never a note, never `.vault/styles/backlog.override.md`.
- Your own rules go in `.vault/styles/backlog.override.md`, edited as a file. It applies in place of the default, and no kebbie writes it.
- `kebbie backlog template` asks `template --json --kind backlog` for the style that applies, and prints kebbie's bundled default when the vault answers none.

A `write` whose etag no longer matches exits 1 with the line `mindin: the etag <etag> no longer matches <note>; it changed since it was read` on stderr; kebbie tells the phone the note changed and to read it again. Any other failure is reported as it stands.

## `watch --json --body`

With `snapshot` and `watch`, the keeper runs one `watch` for as long as it runs, instead of asking for a snapshot every 20 seconds. Each line on stdout is one JSON object:

```json
{"cursor": "a1b2c3d4.42", "reset": false, "more": false, "changes": [
  {"key": "Projects/export.md", "action": "write", "version": "…", "note": {"frontmatter": {"status": "backlog"}, "body": "…"}}
]}
```

| Field | What kebbie does with it |
| --- | --- |
| `cursor` | Kept in `vault-watch.json` after the line is applied, and passed as `--since` when the keeper starts `watch` again. |
| `reset` | `true` makes kebbie take a full `snapshot`, then follow from this cursor. |
| `changes` | Each note's latest state: `write` with its `frontmatter` and `body`, `delete` with `note: null`, or `schema`. kebbie writes a change to a note the snapshot holds straight into its copy, and a backlog note's body into its copy of the backlog. A note it does not hold yet, a changed kind, a frontmatter that does not parse or a `schema` makes it take a full `snapshot`. |

When `watch` exits, the keeper starts it again after 1 second, then twice as long each time up to 5 minutes. The keeper stops it when it stops.

## `status`

kebbie runs `status` with every `about --json`, and `status --probe` from `kebbie doctor`, which may try a write.

| Field | Type | What kebbie does with it |
| --- | --- | --- |
| `configured` | bool | `false` keeps the vault off: no vault is set up for the command. |
| `writable` | bool or null | `false` keeps the vault off; `null` is unknown and keeps it on. |
| `backend` | string | Shown in `kebbie doctor`, such as `local`, `s3` or `server`. |
| `version` | string | Used when `about --json` gives none. |

## A vault without `about`

A vault that refuses `about --json`, as notes-vault-mcp up to 0.13 does, is read from `status`, `task --help` and `--help`: the name from the usage line, `tasks` and `log` when `task --help` answers, `claims` when it lists `claim`, and `snapshot` and `read` when `--help` lists them. `kebbie doctor` names it as read without `about --json`.
