{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://usebode.com/bode.ops.json",
  "title": "bode verbs",
  "description": "A batch of verbs. Ops (`op`) edit the document and are applied atomically — nothing lands unless every one is legal. Commands (`command`) act on the session, run after the ops, in order, and are NOT atomic: a refused command stops the rest. Each command carries a cost.",
  "type": "array",
  "items": {
    "oneOf": [
      {
        "$ref": "#/$defs/add"
      },
      {
        "$ref": "#/$defs/remove"
      },
      {
        "$ref": "#/$defs/connect"
      },
      {
        "$ref": "#/$defs/disconnect"
      },
      {
        "$ref": "#/$defs/setParams"
      },
      {
        "$ref": "#/$defs/note"
      },
      {
        "$ref": "#/$defs/chip"
      },
      {
        "$ref": "#/$defs/move"
      },
      {
        "$ref": "#/$defs/resize"
      },
      {
        "$ref": "#/$defs/duplicate"
      },
      {
        "$ref": "#/$defs/layout"
      },
      {
        "$ref": "#/$defs/rename"
      },
      {
        "$ref": "#/$defs/open"
      },
      {
        "$ref": "#/$defs/clear"
      },
      {
        "$ref": "#/$defs/setVar"
      },
      {
        "$ref": "#/$defs/removeVar"
      },
      {
        "$ref": "#/$defs/select"
      },
      {
        "$ref": "#/$defs/focus"
      },
      {
        "$ref": "#/$defs/fitView"
      },
      {
        "$ref": "#/$defs/run"
      },
      {
        "$ref": "#/$defs/undo"
      },
      {
        "$ref": "#/$defs/redo"
      },
      {
        "$ref": "#/$defs/saveVersion"
      },
      {
        "$ref": "#/$defs/restoreVersion"
      },
      {
        "$ref": "#/$defs/deleteVersion"
      },
      {
        "$ref": "#/$defs/updateVersion"
      },
      {
        "$ref": "#/$defs/newBode"
      },
      {
        "$ref": "#/$defs/openBode"
      },
      {
        "$ref": "#/$defs/openDocument"
      },
      {
        "$ref": "#/$defs/renameBode"
      },
      {
        "$ref": "#/$defs/trashBode"
      },
      {
        "$ref": "#/$defs/restoreBode"
      },
      {
        "$ref": "#/$defs/deleteBode"
      },
      {
        "$ref": "#/$defs/emptyTrash"
      },
      {
        "$ref": "#/$defs/keepBode"
      },
      {
        "$ref": "#/$defs/setSetting"
      },
      {
        "$ref": "#/$defs/setFlag"
      },
      {
        "$ref": "#/$defs/resetFlags"
      },
      {
        "$ref": "#/$defs/wipeEverything"
      },
      {
        "$ref": "#/$defs/setCredential"
      },
      {
        "$ref": "#/$defs/removeCredential"
      },
      {
        "$ref": "#/$defs/bindVar"
      },
      {
        "$ref": "#/$defs/setLocalVar"
      }
    ]
  },
  "$defs": {
    "pos": {
      "type": "object",
      "required": [
        "x",
        "y"
      ],
      "additionalProperties": false,
      "properties": {
        "x": {
          "type": "number"
        },
        "y": {
          "type": "number"
        }
      }
    },
    "port": {
      "type": "object",
      "required": [
        "block",
        "port"
      ],
      "additionalProperties": false,
      "properties": {
        "block": {
          "type": "string"
        },
        "port": {
          "type": "string"
        }
      }
    },
    "size": {
      "type": "object",
      "required": [
        "w"
      ],
      "additionalProperties": false,
      "description": "An imposed size. Omit `h` to let the card grow to fit.",
      "properties": {
        "w": {
          "type": "number",
          "exclusiveMinimum": 0
        },
        "h": {
          "type": "number",
          "exclusiveMinimum": 0
        }
      }
    },
    "add": {
      "title": "add",
      "description": "Add a block. Placement is the interesting part, and it is three policies rather than one: `at` if you know where, else beside `connectFrom` (using that block's real width, not a constant), else to the right of everything. Whichever it is, the result is nudged clear of anything already there — a caller that cannot see the canvas must not be able to drop a block on top of another one. **Refuses** an unknown `blockId`, an `id` already in the graph, and a capability param (see `refusedParams`). `connectFrom` is best-effort about the WIRE and strict about the request. A port that does not exist is a mistake and is refused; nothing on the new block accepting that type is a fact about the two blocks, and the block is added unwired — which is what both shells already do and the honest outcome rather than a refusal. A caller that REQUIRES the wire says `add` then `connect`, which refuses loudly.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "blockId"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "add"
        },
        "blockId": {
          "type": "string",
          "description": "Which block, from the manifest — `text`, `jwt-decode`, `timer`."
        },
        "id": {
          "type": "string",
          "description": "The id to give it. Minted when absent; supply one when a later op in the same batch has to name this block before it exists."
        },
        "at": {
          "$ref": "#/$defs/pos",
          "description": "Where to put it, before collision avoidance."
        },
        "connectFrom": {
          "$ref": "#/$defs/port",
          "description": "Wire this output into the new block's first input it can legally reach, and place the block beside its source. The chain-building gesture: it is what ⌘K does from the selected block and what the phone's Add does from the end of the chain. Left unwired when nothing on the new block accepts the type."
        },
        "params": {
          "type": "object",
          "description": "Params to set at birth, merged over the block's defaults like any other."
        }
      }
    },
    "remove": {
      "title": "remove",
      "description": "Delete a block, and every wire touching it. **Refuses** an id that is not in the graph. Both ends go together because a dangling wire is not a state the evaluator has — and undo restores both, since the snapshot is of the whole document.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "remove"
        },
        "id": {
          "type": "string",
          "description": "The block to delete."
        }
      }
    },
    "connect": {
      "title": "connect",
      "description": "Wire one output to one input. **Refuses** a missing block or port, types that cannot connect at all (lossy connects and says so; impossible is refused), a loop, and — unless `replace` — an input that already has a wire.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "from",
        "to"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "connect"
        },
        "from": {
          "$ref": "#/$defs/port",
          "description": "The output end."
        },
        "to": {
          "$ref": "#/$defs/port",
          "description": "The input end."
        },
        "replace": {
          "type": "boolean",
          "description": "Take over an input that is already wired, dropping the old wire. Off by default, and the asymmetry is deliberate. Dragging onto an occupied port is an unambiguous instruction — you aimed at it — so the canvas passes this. A caller working from a description has no idea the port was taken, and silently discarding someone's wire on its behalf is the kind of edit you only notice later."
        }
      }
    },
    "disconnect": {
      "title": "disconnect",
      "description": "Remove a wire, by its id or by the input it feeds. Both, because both callers exist: the canvas has the edge in hand, and a caller reasoning about a bode knows \"whatever is feeding this input\" long before it knows an edge id. **Refuses** when neither is given, or when nothing matches.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "disconnect"
        },
        "id": {
          "type": "string",
          "description": "The wire's own id."
        },
        "to": {
          "$ref": "#/$defs/port",
          "description": "The input end instead — at most one wire can be there."
        }
      }
    },
    "setParams": {
      "title": "setParams",
      "description": "Change a block's settings. A patch, merged over what is there; it does not replace the whole param object. Setting a key to `undefined` removes it, which is the §29 rule — a param is absent, never empty, because an empty string reaches downstream as something to parse. **Refuses** an unknown block and any capability param (see `refusedParams`).",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "id",
        "params"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "setParams"
        },
        "id": {
          "type": "string",
          "description": "The block whose params to patch."
        },
        "params": {
          "type": "object",
          "description": "The keys to change. Everything else is left alone."
        }
      }
    },
    "note": {
      "title": "note",
      "description": "Write a note on a block, in Markdown. Its own op rather than a `setParams` key, for the reason the note lives outside `params` in the first place: `compute` must never see it, and putting it in there would put it in the evaluator's fingerprint and invalidate a cached result on every keystroke. It is still part of the DOCUMENT — it travels in a share link and belongs in a version. **Refuses** an unknown block. An empty string clears the note.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "id",
        "notes"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "note"
        },
        "id": {
          "type": "string",
          "description": "The block to annotate."
        },
        "notes": {
          "type": "string",
          "description": "The note, in Markdown. Empty clears it."
        }
      }
    },
    "chip": {
      "title": "chip",
      "description": "Show a block as a chip, or as a card again — item 13. A chip is the block's name and its output, with the form put away: what the Display block used to be, available on every block instead of requiring a special one. Its own op rather than a `setParams` key for the same reason as `note`: `compute` must never see it, and it is not an input — it is how the block is ARRANGED, which is the document's business and nobody else's. **Refuses** an unknown block. `on: false` takes the chip off rather than storing one that says no — absent, never empty (§29).",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "id",
        "on"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "chip"
        },
        "id": {
          "type": "string",
          "description": "The block to fold up."
        },
        "on": {
          "type": "boolean",
          "description": "`true` folds it to name and output; `false` opens the card again."
        }
      }
    },
    "move": {
      "title": "move",
      "description": "Put a block somewhere. Position is excluded from the evaluator's fingerprint, so this recomputes nothing — but it is part of the document, so it is saved and it is undoable. **Refuses** an unknown block.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "id",
        "to"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "move"
        },
        "id": {
          "type": "string",
          "description": "The block to move."
        },
        "to": {
          "$ref": "#/$defs/pos",
          "description": "Where to, exactly. No collision avoidance: a caller that said `move` meant that spot, and `layout` is the op that chooses spots."
        }
      }
    },
    "resize": {
      "title": "resize",
      "description": "Give a block a size. `h` is optional because a height only EXISTS once one has been imposed: a card that has merely been widened, as a template's note is, still grows to fit its content. Omitting it is how you hand a height back. This op exists because #111's boundary audit found it missing. `GBlock.size` is part of the document and `templates/index.ts` already sets `size: { w }` by hand, but React Flow's `dimensions` change was the only thing that could write it — so \"make that card wider\" was unsayable by anything that is not a mouse. **Refuses** an unknown block, and a width that is not a positive number.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "resize"
        },
        "id": {
          "type": "string",
          "description": "The block to resize."
        },
        "size": {
          "$ref": "#/$defs/size",
          "description": "The imposed size. Omit `h` to let the card grow to fit its content again, and omit `size` entirely to take the imposed size off altogether — which is the only way to undo a resize, and was unsayable until a UI wanted it."
        }
      }
    },
    "duplicate": {
      "title": "duplicate",
      "description": "Copy blocks, with the wiring that makes the copy useful. **Incoming wires are copied, outgoing wires are not.** Duplicating a block whose input was fed should give you a copy that is also fed — that is the whole point of duplicating mid-chain. Copying its OUTPUT wires would propose a second wire into inputs that already have one, which is refused anyway, so the rule is the only coherent one rather than a preference. The copies move as a group, keeping the arrangement you made, and land below the originals rather than beside them: beside reads as a longer chain, below reads as a second copy. **Refuses** an unknown id. An empty list is a no-op, not an error.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "ids"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "duplicate"
        },
        "ids": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The blocks to copy. Wires between any two of them come along."
        },
        "as": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The ids to give the copies, one per entry in `ids`. Minted when absent, exactly like `add`'s — and absent for the same reason it is usually absent there: you rarely care. Supply them when a later verb has to NAME a copy, which until this existed was impossible: you could duplicate a block and then had no way to refer to what you had made."
        }
      }
    },
    "layout": {
      "title": "layout",
      "description": "Straighten the canvas: columns by depth in the DAG, sources on the left. This is #112's Tidy, reachable as an op because generated blocks cannot be allowed to land in a pile. Never refuses — a graph is always layout-able, and an unknown id in `ids` is simply not there to move.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "layout"
        },
        "ids": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Lay out only these, leaving everything else where it is — Tidy on a selection. Absent means the whole bode."
        },
        "at": {
          "$ref": "#/$defs/pos",
          "description": "Where the top-left of the result goes. Absent means \"where this lot already is\", which is what Tidy wants: it straightens without moving your work across the canvas. A caller BUILDING a bode has no existing position to preserve and does want to say, which is how a template places its chain below its note — the one thing layout cannot derive, because how tall a paragraph renders needs a browser."
        }
      }
    },
    "rename": {
      "title": "rename",
      "description": "Name the bode, or give it an icon. An empty string CLEARS the field rather than storing one, because §29's \"absent, never empty\" applies to the document too: an empty name is not a name, and a reader would have to decide what to display for it. Never refuses.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "rename"
        },
        "name": {
          "type": "string",
          "description": "What to call it."
        },
        "icon": {
          "type": "string",
          "description": "One emoji."
        }
      }
    },
    "open": {
      "title": "open",
      "description": "Replace the content with a document. One op for four things that were four code paths: a template, `core/demo.ts`, a share link and an import are all \"open this bode\". It ignores the graph it is handed and returns the document's, which `(Graph, Op[]) => Graph` takes without a special case. Validated by **`readDocument`** — the same reader a file goes through — so the document's own rules apply inside the op: a thing that is not a bode is **refused**, but a single bad block or wire is dropped and reported as a WARNING rather than failing the batch. Those are the file's problems, not the caller's, and half a bode you can look at beats a dialog saying no. It does not touch the bode's identity — its id, its versions, its save state. That is `openBode`, which is a command.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "document"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "open"
        },
        "document": {
          "$ref": "https://usebode.com/bode.schema.json",
          "description": "A `BodeDocument`, or anything claiming to be one. Unparsed: the op runs the reader, so a caller cannot skip the validation by pre-parsing."
        }
      }
    },
    "clear": {
      "title": "clear",
      "description": "Empty the bode, keeping its name and icon. Expressible as one `remove` per block, and earns its own op only because the label and the notification belong to the gesture rather than to N deletions — \"Cleared 9 blocks\" is what a person needs to read in an undo notice. Never refuses. Clearing an empty bode is a no-op, not an error.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "clear"
        }
      }
    },
    "setVar": {
      "title": "setVar",
      "description": "Declare one of the bode's variables, or change what the FILE says about it — item 157. A variable is a name a block writes as `<< name >>`. What this op can set is the half that travels: a static value the bode carries, and a `hint` saying what somebody opening it should put there. **It cannot bind one to a credential**, and that is not an omission. A binding lives in the browser, per bode, and is the one thing a bode that arrived from somewhere else must never be able to make — the same reason §33 refuses a caller a file param: a caller cannot honestly consent on your behalf. There is simply nothing here to bind with. `value: \"\"` clears the static value and leaves the variable declared and unset, which is §29's \"absent, never empty\" applied to a table that travels.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "name"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "setVar"
        },
        "name": {
          "type": "string",
          "description": "Lowercase letters, digits, `-` and `_`."
        },
        "value": {
          "type": "string",
          "description": "What the file carries. Empty unsets it, leaving the question."
        },
        "hint": {
          "type": "string",
          "description": "What to tell whoever opens this bode: \"a token with repo:read\"."
        }
      }
    },
    "removeVar": {
      "title": "removeVar",
      "description": "Forget a variable entirely. A block still naming it stops with \"not set\", which is the honest state rather than a silent empty string.",
      "cost": "writes",
      "type": "object",
      "required": [
        "op",
        "name"
      ],
      "additionalProperties": false,
      "properties": {
        "op": {
          "const": "removeVar"
        },
        "name": {
          "type": "string",
          "description": ""
        }
      }
    },
    "select": {
      "title": "select",
      "description": "Select blocks. The verb that looked pointless and is not. *\"Select these three so the person can see what I mean\"* is the **preview** step of the pipeline — a builder needs it before it needs anything clever. It also matters mechanically: ⌘K wires from whatever is selected. **Refuses** an id that is not in the bode. An empty list clears the selection.",
      "cost": "safe",
      "type": "object",
      "required": [
        "command",
        "ids"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "select"
        },
        "ids": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The blocks to select. Empty selects nothing."
        }
      }
    },
    "focus": {
      "title": "focus",
      "description": "Put the camera on one block. The store cannot do this itself — the viewport belongs to React Flow, inside the canvas. So this records a REQUEST that the canvas answers, the same shape `fitView` and Save already use. A caller that is not on a canvas (the phone, a test, a prerender) simply has nobody listening, which is the correct outcome rather than an error. **Refuses** an id that is not in the bode.",
      "cost": "safe",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "focus"
        },
        "id": {
          "type": "string",
          "description": "The block to centre on."
        },
        "field": {
          "type": "boolean",
          "description": "Also put the text cursor in this block's first editable field — what arriving from a tool page does, so you can start typing."
        }
      }
    },
    "fitView": {
      "title": "fitView",
      "description": "Frame the whole bode. Never refuses; an empty bode has nothing to frame and that is not an error.",
      "cost": "safe",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "fitView"
        }
      }
    },
    "run": {
      "title": "run",
      "description": "Lift the run barrier and evaluate — #105. A block that `needs: ['network']` does not run just because something upstream changed; it holds its last value and reports `stale`. This is the only way past that, and it is one-shot: the permission is spent by the evaluation it triggers, so a later keystroke cannot ride through on it. With no `ids`, every stale block runs — the canvas's \"3 blocks are out of date · Run\". With `ids`, only those, which is Run on one card. **Never refuses.** Nothing stale is not an error, it is the ordinary state of a bode you have not edited, and a caller that ran it on a timer should not have to check first.",
      "cost": "external",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "run"
        },
        "ids": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Which blocks to run. Absent means every stale one."
        }
      }
    },
    "undo": {
      "title": "undo",
      "description": "Step back through history. **Refuses** when there is nothing to undo, and refused outright inside a batch that contains ops — the batch is itself one history entry, so undoing within it means undoing the thing being built.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "undo"
        }
      }
    },
    "redo": {
      "title": "redo",
      "description": "Step forward again. **Refuses** when there is nothing to redo, and in a batch containing ops, for the same reason as `undo`.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "redo"
        }
      }
    },
    "saveVersion": {
      "title": "saveVersion",
      "description": "Save a named version of this bode. Versions are explicit and separate from autosave: autosave answers \"what was I doing?\", a version answers \"take me back to this\".",
      "cost": "writes",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "saveVersion"
        },
        "label": {
          "type": "string",
          "description": "What to call it. A timestamp stands in when absent."
        },
        "note": {
          "type": "string",
          "description": "Why you saved it."
        }
      }
    },
    "restoreVersion": {
      "title": "restoreVersion",
      "description": "Put a saved version back. **Refuses** an id this bode has no version for.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "restoreVersion"
        },
        "id": {
          "type": "string",
          "description": "The version to restore."
        }
      }
    },
    "deleteVersion": {
      "title": "deleteVersion",
      "description": "Forget a version. **Refuses** an unknown id. Undoable only in the sense that the version list itself is restorable for a few seconds.",
      "cost": "destructive",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "deleteVersion"
        },
        "id": {
          "type": "string",
          "description": "The version to delete."
        }
      }
    },
    "updateVersion": {
      "title": "updateVersion",
      "description": "Rename a saved version, or change its note. The inverse of the hole `emptyTrash` was: reachable from the Versions dialog and not from the vocabulary, so a caller could save and delete a version but not correct the name it gave one. **Refuses** an id this bode has no version for. A blank label falls back to unnamed rather than storing whitespace (§29).",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "updateVersion"
        },
        "id": {
          "type": "string",
          "description": "The version to change."
        },
        "label": {
          "type": "string",
          "description": "What to call it."
        },
        "note": {
          "type": "string",
          "description": "Why you saved it."
        }
      }
    },
    "newBode": {
      "title": "newBode",
      "description": "Start an empty bode, with its own id, versions and save state. The current one is autosaved first, so nothing is lost. Never refuses.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "newBode"
        }
      }
    },
    "openBode": {
      "title": "openBode",
      "description": "Open a saved bode. **Refuses** an id that is not in storage.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "openBode"
        },
        "id": {
          "type": "string",
          "description": "Which saved bode, from `bodes()`."
        }
      }
    },
    "openDocument": {
      "title": "openDocument",
      "description": "Open a document as a NEW bode. The hole the §135 review found. The `open` OP replaces a bode's content and deliberately leaves its identity alone — same id, same versions, same save state. `loadGraph` resets all of that and validated nothing, which is how every caller that actually wanted \"open this file\" ended up bypassing the reader: a template, the example bode, a share link and an import all took the second door. So this is the first door, and it runs **`readDocument`** like the op does. A caller cannot skip §110's validation by pre-parsing, which is exactly what `JsonModal` was doing. **Refuses** anything that is not a bode. A single bad block or wire is dropped and reported as a warning, because that is the file's problem and the readable part still opens.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "document"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "openDocument"
        },
        "document": {
          "$ref": "https://usebode.com/bode.schema.json",
          "description": "A `BodeDocument`, or anything claiming to be one. Unparsed on purpose."
        },
        "draft": {
          "type": "boolean",
          "description": "Open it as a DRAFT — it works across a refresh without joining All bodes, which is what a template or a shared link should do until you keep it."
        },
        "from": {
          "type": "string",
          "description": "What it came from, shown on the draft banner: a template's name, a URL."
        }
      }
    },
    "renameBode": {
      "title": "renameBode",
      "description": "Rename a saved bode. **One verb with a documented branch, not two verbs** — which is what the §39 inventory asked for. Renaming the bode you have OPEN goes through the document and is undoable; renaming one you do not goes straight to storage and is not. The branch belongs here rather than in every caller, because a caller that has to know which case it is in will eventually get it wrong. **Refuses** an id that is neither open nor in storage.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "renameBode"
        },
        "id": {
          "type": "string",
          "description": "Which bode."
        },
        "name": {
          "type": "string",
          "description": "What to call it. Empty clears it back to untitled."
        },
        "icon": {
          "type": "string",
          "description": "One emoji."
        }
      }
    },
    "trashBode": {
      "title": "trashBode",
      "description": "Move a bode to the trash, where it stays recoverable. **Refuses** an id that is not in storage.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "trashBode"
        },
        "id": {
          "type": "string",
          "description": "Which bode."
        }
      }
    },
    "restoreBode": {
      "title": "restoreBode",
      "description": "Take one back out of the trash. **Refuses** an id that is not in it.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "restoreBode"
        },
        "id": {
          "type": "string",
          "description": "Which bode."
        }
      }
    },
    "deleteBode": {
      "title": "deleteBode",
      "description": "Delete a bode for good. **Refuses** nothing — an id that is already gone is the outcome you asked for.",
      "cost": "destructive",
      "type": "object",
      "required": [
        "command",
        "id"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "deleteBode"
        },
        "id": {
          "type": "string",
          "description": "Which bode."
        }
      }
    },
    "emptyTrash": {
      "title": "emptyTrash",
      "description": "Delete everything in the trash. The one the §39 sweep found with **no function at all** — an inline loop in `CanvasesModal`, which is how a destructive action ends up with no name, no test and no way to call it from anywhere else.",
      "cost": "destructive",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "emptyTrash"
        }
      }
    },
    "keepBode": {
      "title": "keepBode",
      "description": "Turn the draft into a real bode in All bodes. **Refuses** when what is open is not a draft.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "keepBode"
        },
        "name": {
          "type": "string",
          "description": "What to call it. Falls back to the draft's current name."
        }
      }
    },
    "setSetting": {
      "title": "setSetting",
      "description": "Change a setting. Settings are in the language because the first draft of §39 left them out as \"a developer's A/B harness\", and `proxyUrl` is the counterexample: a string that decides what network a bode can reach, sitting in the same object as `background: 'dots'`. Operational configuration was already mixed in with cosmetics, so the exclusion was drawn around the wrong thing. **Refuses** an unknown key, and a value the setting does not allow — `SETTING_SPEC` is what makes the second one checkable rather than a cast.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "key",
        "value"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "setSetting"
        },
        "key": {
          "type": "string",
          "description": "Which setting, from `SETTING_SPEC`."
        },
        "value": {
          "$ref": "https://usebode.com/bode.schema.json",
          "description": "The new value. Checked against that setting's kind and choices."
        }
      }
    },
    "setFlag": {
      "title": "setFlag",
      "description": "Switch a Labs flag. **Refuses** an unknown key, and a variant that flag does not offer.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "key",
        "variant"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "setFlag"
        },
        "key": {
          "type": "string",
          "description": "The flag, from `flags()`."
        },
        "variant": {
          "type": "string",
          "description": "Which variant."
        }
      }
    },
    "resetFlags": {
      "title": "resetFlags",
      "description": "Put every flag back to its default. `destructive`, because it discards choices with no history entry to undo.",
      "cost": "destructive",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "resetFlags"
        }
      }
    },
    "wipeEverything": {
      "title": "wipeEverything",
      "description": "Erase every bode, version, draft and setting this browser holds. In the language precisely BECAUSE it is the most dangerous thing here: an absent verb cannot be discovered, and a caller that needs to reset a browser would otherwise go looking for localStorage itself.",
      "cost": "destructive",
      "type": "object",
      "required": [
        "command"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "wipeEverything"
        }
      }
    },
    "setCredential": {
      "title": "setCredential",
      "description": "Add or replace a credential in this browser — items 103 and 157. In the language because the Builder has to be able to finish the job: a bode it writes that calls an API needs somewhere for the key to go, and a caller that cannot put one there would hand back a bode that cannot run and no way to fix it but a dialog it cannot open. **It is a command, not an op**, and that is the whole shape of it. Ops edit the document and travel with it; this touches the browser, is `destructive` because it silently replaces a key of the same name, and is in nothing that is ever saved, shared or exported. No query ever returns a value, so a caller can write one and never read one.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "name",
        "value"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "setCredential"
        },
        "name": {
          "type": "string",
          "description": "Lowercase letters, digits, `-` and `_`."
        },
        "value": {
          "type": "string",
          "description": "The key itself."
        }
      }
    },
    "removeCredential": {
      "title": "removeCredential",
      "description": "Forget a credential. Every bode bound to it stops, saying which key it wanted — which is the honest outcome of revoking something.",
      "cost": "destructive",
      "type": "object",
      "required": [
        "command",
        "name"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "removeCredential"
        },
        "name": {
          "type": "string",
          "description": ""
        }
      }
    },
    "bindVar": {
      "title": "bindVar",
      "description": "Point one of THIS bode's variables at one of this browser's credentials. The one gesture that is deliberately not an op: a binding is not in the document — a document that could carry one could name a stranger's keys — so it is a command, and it applies to the bode that is open.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "name"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "bindVar"
        },
        "name": {
          "type": "string",
          "description": "The variable. It does not have to exist yet; binding declares it."
        },
        "credential": {
          "type": "string",
          "description": "The credential to answer it with, or omitted to take the answer back."
        }
      }
    },
    "setLocalVar": {
      "title": "setLocalVar",
      "description": "Answer one of this bode's variables with a value kept in THIS BROWSER. The unshared half of a variable: `setVar` writes what the file carries, and this writes what it does not. A caller filling in a bode somebody else wrote wants this one, because the alternative publishes the answer.",
      "cost": "writes",
      "type": "object",
      "required": [
        "command",
        "name"
      ],
      "additionalProperties": false,
      "properties": {
        "command": {
          "const": "setLocalVar"
        },
        "name": {
          "type": "string",
          "description": ""
        },
        "value": {
          "type": "string",
          "description": "Omitted clears it, leaving whatever the file says."
        }
      }
    }
  }
}
