# The JSON interface

**Who this page is for:** developers who script the Workbench, write tests against it, or want
to know exactly what the page, the guide and the tools read. Everyone else can skip it.

The Workbench's page talks to its server over a JSON interface on the same site. The guide and
coding agents reach the same data through the [MCP tools](guide-and-agents.md#the-tools), which
are built on the same readers. This page lists every address, grouped by the part of the
Workbench that answers it, and the values they answer. The contract for each part is the
docstring of its package in `gvn_workbench`: `reading`, `run_actions`, `editing`, `evals`,
`guide`, `mcp` and `security`.

- **Read first:** [Files and safety](files-and-safety.md), for the rules every request passes.

## How the site is laid out

```mermaid
flowchart LR
    page["/<br/>the page"]
    evals["/evals/<br/>the Evals section"]
    subgraph api ["/api/"]
        direction TB
        reading["project · harnesses ·<br/>runs (reading)"]
        actions["journals · waiting ·<br/>runs/…/forks, answers, … (run actions)"]
        editing["harnesses/…/source · edits ·<br/>proposals · layouts (editing)"]
        guide["guide/conversations"]
        apievals["evals/…"]
    end
    mcp["/mcp<br/>MCP server"]
    page --> reading
    page --> actions
    page --> editing
    page --> guide
    evals --> apievals
```

## Conventions

- Every answer is JSON. A refusal is `{"error": "<one sentence for a person>"}`, sometimes with
  more members, with status 400 (the request is wrong), 404 (no such thing) or 409 (it cannot be
  done now, or it changed meanwhile).
- A changing request (POST, PUT, DELETE, PATCH) carries the header `X-Gvn-Token` with the page's
  token, which the server writes into the page it serves (`<meta name="gvn-token" ...>`).
  Without it the answer is 403. `/mcp` takes the MCP token instead.
- Every address under `/api/runs` takes `?journal=<key>`: `project` (the default, when absent),
  `fork:<id>` or `opened:<id>`. A key that names no journal is 404.
- A **template path** names an actor as written in a harness: stage names from the entry actor
  down, joined by `/`, a `Parallel` branch's index after its stage (`collecting_evidence/1`);
  the entry actor's is empty. A **run-time name** names an actor in one run:
  `<run actor>/<stage>.<visit>[.<index>[.<attempt>]]`, nested once per level.
- Everything read from a journal is returned only inside `content` members, as data.

## Reading

All GET. The reader never runs a harness, never calls a child's `make` or `start`, and never
writes.

| Address | Answers |
|---|---|
| `/api/project` | `{"root", "harnesses": [HarnessCard], "journal": bool, "docs", "generation", "versions": [{"name", "harness"}]}`. `docs` is where documentation links start. `generation` changes each time the project is loaded again (after a save), so a page that sees a new one reads everything again. |
| `/api/harnesses/<harness>` | `{"name", "summary", "brief": <JSON Schema>, "actor": ActorCard, "tools": [Tool], "policy": {"class", "outcomes"}, "model_roles", "external", "source": Source}` |
| `/api/harnesses/<harness>/actors/<template>` | one Drawing; `/api/harnesses/<harness>/actors/` is the entry actor's |
| `/api/versions/<version>` | `{"name", "harness", "same_as_harness", "actor": ActorCard}`: an eval version. `same_as_harness` is the harness whose entry actor is the version's very class (a baseline), else null; `harness` is that harness, else the one whose machine has the version's machine's name when exactly one has, else null. `actor` is the version's entry actor. |
| `/api/versions/<version>/actors/<template>` | one Drawing, built from the version's own actor class and plan; `/api/versions/<version>/actors/` is the version's own drawing |
| `/api/runs?harness=&after=&limit=&journal=` | `{"runs": [RunCard], "next"}`, in run id order; `after` is the last id of the page before; `limit` at most 200 (default 50) |
| `/api/runs/<run>` | `{"id", "journal", "harness", "version", "finished", "outcome", "actors": [RunActor], "moments": [MomentCard], "waiting": [Waiting]}` |
| `/api/runs/<run>/moments/<sequence>` | `{"sequence", "at", "event": EventDetail, "movements": [Movement], "deadlines": [Deadline], "standings": [Standing], "began", "ended", "pending": [RequestCard], "rejected": bool, "error"}` |
| `/api/runs/<run>/actors/<name>` | one Drawing: the actor of the run called `<name>` on the machine it ran on, with its template's stages and trail when the plans say which it is |

## Run actions

| Address | Body | Answers |
|---|---|---|
| `GET /api/journals` | | `{"journals": [JournalCard]}`: the project's, then the forks, then the opened ones |
| `POST /api/journals` | `{"path"}` | Opens a SQLite journal file (absolute, or relative to the project's root) to be read; its JournalCard. 400 unless the file exists and is a journal `SqliteJournal` wrote. |
| `DELETE /api/journals/<journal>` | | A fork: deletes its file and note, `{"deleted"}`. An opened journal: forgets it, its file left, `{"forgotten"}`. `project`: 400. |
| `GET /api/waiting` | | `{"waiting": [Waiting + {"run", "journal"}]}`, for the project's journal and every fork |
| `POST /api/runs/<run>/forks?journal=` | `{"at"}` | Copies the run as it stood after moment `at` into a new fork: `{"journal": "fork:<id>", "run": <its address>, "card": JournalCard}`. 400 for a moment the run lacks, 409 when it cannot be copied. |
| `POST /api/runs/<run>/answers?journal=` | `{"key", "answer", "journal"?, "by"?}` | Answers the request `key` through a gvn `Launcher` over the run's journal, then drives the run on: Continued. `answer` is `{"choice", "text"}` for a question, `{"approve", "reason"}` for an approval. `by` defaults to "a person at the Workbench", recorded as a principal issued by "gvn workbench". 409 for an opened journal, a key the run does not wait on, or a run no harness can drive; 400 for an answer the question does not accept, and for the project's journal unless the body also says `"journal": "project"`. |
| `POST /api/runs/<run>/resume?journal=` | `{"journal"?}` | Recovers the run and drives it on: Continued. The same journal rules as answers. |
| `GET /api/runs/<run>/case?journal=&name=` | | `{"content": Case}`, not written. 409 while the run has not ended. |
| `POST /api/runs/<run>/cases?journal=` | `{"file", "name"?}` | Appends the case to the cases file `file` through `POST /api/evals/cases/<file>`, with its checks and refusals (404 for a file that is not one of the project's cases files, 409 for a case id already there): `{"file", "content": Case}` |
| `GET /api/runs/<run>/divergence?journal=&against=<version>` | | The run's events replayed against the version `against` (`Inspector.against`): Divergence. 404 for a version the project does not offer. |

## Editing

| Address | Body | Answers |
|---|---|---|
| `GET /api/harnesses/<harness>/source?template=` | | `{"harness", "template", "targets": [Located], "files": {<file>: <sha256>}}` |
| `GET /api/versions/<version>/source?template=` | | `{"version", "same_as_harness", "template", "targets": [Located], "files"}`; `same_as_harness` names the harness a version is when it runs that harness's own class, else null |
| `POST /api/edits/preview` | `{"edits": [Edit]}` | Preview: `{"edits": [<sentence>], "edit_targets": [{"kind", "harness", "version", "template", "target"}], "patch": Patch, "bases", "acknowledge": [<what>], "acknowledge_shares": [Share], "verification": Verification, "suggestions": [Suggestion], "by_hand": [ByHand]}`. `edit_targets` and `acknowledge_shares` say for programs, in the same order, what `edits` and `acknowledge` say for a person. Writes nothing. |
| `POST /api/edits/save` | `{"edits", "acknowledged", "bases"?}` | `{"saved": true, "files": [{"path", "added", "removed"}], "restart": "restarting" or "needed", "sentence"}`. Refused with 409 and a `reason`: `changed_on_disk`, `refused`, `not_acknowledged` (with `acknowledge`, `acknowledge_shares`, `changes`), `verification_failed` (with `verification`, `suggestions`, `by_hand`) or `write_failed`; nothing written. |
| `GET /api/proposals` | | `{"proposals": [{"id", "created", "note", "edits", "files", "verified", "acknowledge", "stale", "changed"}]}`, oldest first |
| `GET /api/proposals/<id>` | | the proposal in full: its Preview, `id`, `created`, `note`, `plain_edits`, `stale`, `changed`, `stale_sentence` |
| `POST /api/proposals/<id>/save` | `{"acknowledged"}` | as a save, against the files it was proposed on; a saved proposal is deleted |
| `DELETE /api/proposals/<id>` | | `{"deleted"}` |
| `GET /api/layouts/<harness>?template=` | | `{"harness", "template", "positions": {<state>: {"x", "y"}}}` |
| `PUT /api/layouts/<harness>?template=` | `{"positions"}` | keeps them (each a state of the drawing; at most 2000 a drawing; the file at most 1 MB) |
| `POST /api/workbench/restart` | | while the changed code does not start, every address answers 503 `{"error", "running": false}`; this tries again |

### Edits

Every edit has `kind`, its owner (`harness`, a harness's name, or `version`, an eval
version's name: one of the two), `template` (`""` for the entry actor), and the members of its
kind. `"rewrite": true` accepts the rewrite a refusal offered (`rewrite_offered`); only
`set_value`, `remove_inputs` and `remove_outputs` are offered one.

| `kind` | Members |
|---|---|
| `set_value` | `target` (a `stage:`, `join:` or `child:` setting, written or listed in `unwritten_settings`), `value` |
| `add_route`, `change_route` | `state`, `final`, `symbol` |
| `remove_route` | `state`, `final` |
| `add_transition` | `source`, `input`, `target`, `output` (a Mealy machine only) |
| `remove_transition` | `source`, `input` (a branch's route goes with its outcome in `Alphabet.of(...)`) |
| `retarget_transition` | `source`, `input`, `target` |
| `add_state`, `remove_state` | `name` |
| `rename_state` | `old`, `new` |
| `reorder_states` | `order` (every state, once) |
| `swap_join` | `state`, `join` (`AllOf`, `AnyOf`, `Quorum`), `count` (a `Quorum` only) |
| `remove_inputs`, `remove_outputs` | `names` (at least one) |

### Targets

| Target | What it is |
|---|---|
| `plan` | the `Plan(...)` call of a workflow |
| `chain` | the blueprint chain of a workflow or custom actor |
| `state:<name>` | a `.state(...)` call |
| `transition:<source>:<input>` | an `.on(...)` call or a route of a `.branch(...)` |
| `stage:<state>` and `stage:<state>:<setting>` | the stage constructor, and `routes`, `retain`, `expired`, `empty`, `window`, `limit`, `attempts`; `make`, `start`, `judge`, `deadline`, `count` and `items` are always code |
| `join:<state>` and `join:<state>:<setting>` | the join constructor, and `success`, `reached`, `missed`, `count`, `wait`, `veto`, `order`, `early` |
| `child:<state>[:<branch>]` and `…:<setting>` | the one constructor call that builds the stage's child inside `make`, and its settings |

## The guide

| Address | Body | Answers |
|---|---|---|
| `GET /api/guide/conversations` | | `{"conversations": [{"id", "started", "first", "messages"}], "more"}`, newest first, at most 50 |
| `POST /api/guide/conversations` | | 201, `{"id"}` |
| `POST /api/guide/conversations/<id>/messages` | `{"text", "place"}` | when the turn ends: `{"reply", "ended", "shown": [Place], "used": [{"tool", "arguments"}], "proposed": [{"id", "address"}], "waiting", "at", "seconds", "tokens"}`. `ended` is `answered`, `failed`, `out_of_steps` or `out_of_time`; a turn that cannot finish still answers 200. |
| `GET /api/guide/conversations/<id>` | | `{"id", "entries", "waiting"}`: the person's and the guide's entries in order |

A **place** is a harness (`harness`), a drawing (`harness`, `template`), a selection in it
(`state`, or `source` and `target`), a run (`run`, `journal`, `at`, `actor`) or a replay (`run`,
`against`).

## The Evals section

The eval page is at `/evals/`, and its interface under `/api/evals/`: runs and reports
(`/api/evals/runs`, `/api/evals/runs/<run_name>`), a trial
(`/api/evals/runs/<run_name>/trials/<case_id>/<trial>`), a comparison
(`/api/evals/compare?candidate=&baseline=`), the eval files (`/api/evals/evals`), the cases
files and their cases (`/api/evals/cases`, `/api/evals/cases/<file>`, with POST, PUT and
DELETE), and the reviews (`/api/evals/reviews`, GET and POST). A cases file's path is sent as
one path segment with its slashes percent-encoded (`evals%2Frelease_review.cases.jsonl`).
[The web page](../evals/web-page.md) describes what each view shows.

## The MCP server

`/mcp` is an MCP server over Streamable HTTP. Every request carries `X-Gvn-Token` with the MCP
token from `.gvn/workbench/mcp-token`. Its tools are listed in
[The guide and coding agents](guide-and-agents.md#the-tools).

## Values

| Value | Members |
|---|---|
| HarnessCard | `{"name", "summary", "actor": ActorCard}` |
| ActorCard | `{"template", "class", "module", "kind", "style": "moore" or "mealy", "source": Source}`. `kind` is `workflow`, `agent`, `conversation`, `errand`, `inquiry`, `approval`, `choice` or `timer` for gvn's actors and their subclasses, `actor` for the project's own. |
| Source | `{"file", "line"}` relative to the project's root; null for a class outside the project |
| Drawing | `{"actor": ActorCard, "machine": Machine, "stages": {<state>: Stage}, "trail": [ActorCard]}`; `trail` runs from the entry actor down to this one's parent |
| Machine | `{"name", "style", "fingerprint", "initial", "states": [{"name", "final", "output"}], "inputs", "outputs", "transitions": [{"source", "input", "target", "output"}], "otherwise": {"output"}}`. A state's `output` is a Moore machine's; a transition's a Mealy machine's. Only declared transitions are listed; `otherwise` says what any other input emits. |
| Stage | `{"recipe": "host", "fan_out", "for_each" or "parallel", "children": [ActorCard], "leads": {<symbol>: <state>}, "settings", "join": Join}`; `leads` is every symbol the stage can end with and the state it leads to |
| Join | `{"class", "outcomes", "settings"}`: `success`, `reached`, `missed` (and `count`, `wait` for `Quorum`); `order`, `early` for `Worst` |
| Tool | `{"identity", "name", "namespace", "description", "arguments": <JSON Schema>, "untrusted", "independent"}` |
| RunCard | `{"id", "journal", "harness", "version", "finished", "outcome", "state", "records", "began", "latest", "waiting"}`. `harness` is the offered harness whose actor class revives the run; otherwise `version` names the first of the project's versions that does. |
| RunActor | `{"name", "template", "class", "fingerprint", "first", "last", "final", "recipe", "index", "visit", "attempt"}`: an actor that stood at some moment, with the sequences it started and ended at |
| MomentCard | `{"sequence", "at", "event": {"kind", "symbol", "to"}, "moved": [{"actor", "before", "after", "ended", "steps": [[source, input, target]]}], "deadlines": [Deadline], "began": int, "ended": int, "rejected", "error": bool}` |
| Deadline | `{"stage", "address", "steps"}`: the steps a stage's deadline took at one moment; `address` is `<workflow>/<stage>#<visit>` when the event was addressed to it |
| Movement | `{"actor", "template", "fingerprint", "before", "after", "ended", "started", "left", "steps": [{"source", "input", "target", "output", "declared"}]}`; an actor that started and ended within one event has `before` and `after` null and `started` and `left` true |
| Standing | `{"actor", "template", "fingerprint", "state", "finished"}` |
| EventDetail | `{"kind", "symbol", "to", "content"}` |
| RequestCard | `{"key", "kind", "from", "content"}` |
| Waiting | `{"key", "from", "template", "audience", "question", "choices", "since", "title", "kind": "question" or "approval"}`; `title` is the question's first line, at most 120 characters |
| JournalCard | `{"key", "kind": "project", "fork" or "opened", "label", "answerable", "from": {"journal", "run", "at"}, "path"}` |
| Continued | `{"journal", "run": RunCard, "status", "written": {"from", "records"}, "said"}` |
| Case | `{"case_id", "tags", "brief", "expect": {"outcome"}}` |
| Divergence | `{"run", "journal", "against", "recorded": Side + {"harness", "version"}, "changed": Side, "differs": bool or null, "at": {"position", "state", "event"}, "problem": {"sentence", "content"}}` |
| Side | `{"moments": [MomentCard], "finished", "outcome", "state"}`, from the first difference on |
| Located | `{"harness", "version", "template", "target", "what", "tier": "own", "shared" or "code", "file", "lines", "value", "kind", "shares": [Share], "reason", "edits": [<kind>], "unwritten_settings": [{"setting", "target", "default", "plain_default", "edits"}]}`. One of `harness` and `version` names the owner. `what` is the target in words ("the turns of the reviewing_components child"). `edits` are the kinds of edit the target takes; `unwritten_settings`, for a stage, join or child constructor, the settings it takes that are not written, with the constructor's default when `plain_default`. |
| Share | `{"what", "harness", "version", "template", "target", "file", "line"}`: something else an edit changes. `what` says it for a person: "the same setting of the version candidate", "the turns of the reviewing child of the harness other", "the plan at src/x.py:40, built on the same machine", "COMPONENT_REVIEW_TURNS is also read at src/release_review/candidate.py:92". The other members name the other owner, its template and its raw target (all null for a plan or a read of a constant). |
| Patch | `{"refusal": {"edit", "sentence", "rewrite_offered"}, "files": [{"path", "base", "added", "removed"}], "diff", "changes": [{"edit", "kind", "harness", "version", "template", "target", "also_changes": [Share]}], "notes": [{"kind", "file", "line", "note"}]}`. A change's `edit` is the edit's sentence; the other members are its raw kind, owner, template and target. A note's kind is `left_behind`, `orphaned_comment`, `moved_comment`, `long_line`, `no_stage` or `covered` (an edit another edit of the group makes, with `file` and `line` null). |
| Verification | `{"ok", "loaded", "seconds", "sentence", "checked": [{"what", "plans", "definitions"}], "problems": [{"what", "harness", "version", "template", "sentence", "findings": [{"code", "subject", "message"}], "file", "line"}], "effects": [{"edit", "ok", "sentence"}]}` |
| Suggestion | `{"why", "edit": Edit, "sentence"}`: a further edit the group needs, offered with every other one of the same answer: `remove_inputs` for the inputs no transition uses, `remove_outputs` for the outputs nothing emits, `remove_state` for each state nothing reaches, `remove_transition` for a transition still reaching a removed state or reading a removed input, `change_route` for a stage's route still ending it with a removed input |
| ByHand | `{"sentence", "file", "line"}`: what the group needs that no edit makes (a judge's class that still answers an outcome, a branch whose outcomes are a constant, code outside the editable shape), with the file and line to change by hand |
