# Studio action vocabulary

The actions `soundbox.studio_apply` takes, which are also what the studio's own **Chat** panel produces. The
vocabulary is kept beside the code that checks it, in `STUDIO_ACTIONS_HELP` in `server/src/studio-link.ts`, and the
tool's description carries the same text.

## Actions

Each action is an object with a `type`:

| `type` | Fields | Effect | Undoable |
|---|---|---|---|
| `set_track` | `track_index`, `muted`, `soloed`, `gain_db` | Mute, solo or set a lane's gain | Yes |
| `rename_track` | `track_index`, `name` | Name a lane | Yes |
| `move_clip` | `clip_id`, `start_s`, `track_index` | Move a clip in time, to another lane, or both | Yes |
| `set_clip` | `clip_id`, `muted`, `text`, `speaker`, `voice_id`, `gain_db`, `fade_in_s`, `fade_out_s`, `duration_s`, `trim_start_s` | Mute a clip, rewrite or recast its line, set gain, fades and trim | Yes |
| `delete_clip` | `clip_id` | Remove a clip. Held unless `allow_delete` is true | Yes |
| `add_clip` | `track_index`, `start_s`, `text` | Write a new line onto a lane at a time | Yes |
| `add_lines` | `lines`: `{ text, speaker, voice_id }` or `{ kind: "pause", duration_s }` | Write script lines and pauses, in order | Yes |
| `speak_lines` | `clip_ids` | Read written lines aloud | Yes |
| `add_device`, `remove_device` | `track_index`, `kind` | Put a device on a lane's rack, or take it off | No |
| `set_device` | `track_index`, `kind`, `params` | Turn a device's knobs | No |
| `generate_clip` | `track_index`, `start_s`, `prompt` | Generate audio from a prompt and place it | Yes |
| `show_panel` | `panel` (`script`, `insert`, `library`, `history`, `sample`, `devices`), `open` | Open or close a panel | Not an edit |
| `start_recording` | None | Start a take | Not an edit |

Device-rack changes and adding a lane are not undoable, whoever makes them. Every other edit goes through the same
handler a click uses and lands on the user's undo stack.

## Selectors

A clip action takes `select` in place of `clip_id` to act on many clips. Keys in one `select` combine with AND.

| `select` | Matches |
|---|---|
| `{"scope": "all"}` | Every clip |
| `{"scope": "selected"}` | The user's selection |
| `{"from_track": 2}` | Every clip on lane 2 |
| `{"matching": "vocal"}` | Clips whose label contains the text |

Example `studio_apply` arguments that turn lane 2 down, name lane 1 and fade in every clip on lane 3:

```json title="soundbox.studio_apply arguments"
{
  "summary": "Quieter drums, named lanes",
  "actions": [
    { "type": "set_track", "track_index": 2, "gain_db": -6 },
    { "type": "rename_track", "track_index": 1, "name": "Narration" },
    {
      "type": "set_clip",
      "select": { "from_track": 3 },
      "fade_in_s": 0.5
    }
  ]
}
```

## Validation

| Rule | Detail |
|---|---|
| Ids | Lane numbers, clip ids and voice ids must come from `soundbox.studio_context`. An action that names something not in the studio, or is malformed, is dropped and counted in `dropped` |
| New lanes | `add_clip` may name the next free lane. `generate_clip` with an unknown lane goes on the next free one |
| Devices | `kind` must be one of the eight the rack builds: `compressor`, `eq`, `reverb`, `delay`, `distortion`, `gate`, `limiter`, `autotune` |
| Deletes | `delete_clip` is held and counted in `held_deletes` unless `allow_delete` is true |
| Background work | `generate_clip` and `speak_lines` return at once; the clips fill in as the work finishes |

## In the Chat panel

The studio's **Chat** panel turns a typed instruction into the same actions. It applies small edits (mute, solo,
rename, move, level, fades, devices, panels) at once and lists them in its reply. A plan that deletes a clip, writes
lines, generates audio or reads lines aloud is shown first and waits for the user to click the apply button, labelled
with the count (for example **Apply 3 edits**), or **Discard**. Actions that refer to something not on the timeline
are dropped before the plan is shown, and the reply gives the count.

While an MCP tool works on a story, an open studio for that story shows a notice and pauses editing; the agent's
changes stream into the page as they land.
