# Commands, batches and revisions

> How an edit is a batch of named operations, how revisions protect against stale plans, and how to retry safely.

Source: https://stuarty.com/docs/concepts/commands-and-revisions/

## The idea

An edit is a **batch**: a list of **operations**, each one a named command such as `track.add` or `item.move`, with its arguments. The whole batch applies or none of it does, and it becomes one revision and one undo step.

Every batch names the `base_revision` it was planned against. If the project moved on, the batch is replayed on the newer revision unless it touches objects another actor changed; then it answers `E_REVISION_CONFLICT` with a text diff of what changed, so you can read it and plan again.

## Quick start

1. Read the revision: `project_get`, or the `revision` of your last edit result.
2. Send the batch with that `base_revision`. Give a new track or item your own `id` when a later operation in the same batch refers to it.
3. Use `dry_run: true` to check a batch without saving it.
4. Use an `idempotency_key` when you may retry: the same key with the same batch returns the first result, with `replayed: true`. The same key with a different batch is `E_IDEMPOTENCY_MISMATCH`.

The operations are in the [operations of the edit tool](/docs/mcp/tools/edit).

## Going back: revert, checkpoints and the diff

The history is never rewritten, so going back is one more revision.

- **Checkpoints** name a revision ("before the intro"): in the History sidebar, with `stuarty checkpoint:create`, or with `history` `action=checkpoint`. Removing a checkpoint never removes a revision. Before an agent's first edit of the day the service makes one by itself, so there is always a point to come back to.
- **The diff** says in words what changed between two revisions, most significant first: `stuarty diff --project <id> --from 12`, or `history` `action=diff`. It is computed from the two documents, so it is right after undo and redo too.
- **Revert** takes the project back to the document at a revision or a checkpoint, as a new revision of whoever asked: `stuarty revert --project <id> --checkpoint "before the intro" --dry-run` shows what it would change and writes nothing. Without `--dry-run` it is a step like any other, and `undo` takes it back. A revert goes over what other actors did since, on purpose; with an older `--base` it answers `E_REVISION_CONFLICT` instead when they changed an object it would change.
- **Images** have the same three, with the same rules: in the history panel of the image editor (name a version, read the changes since a revision, "revert to here" with the dry run as the confirmation), with `stuarty image:checkpoint:create`, `stuarty image:diff` and `stuarty image:revert` and the id of the image as the first argument, or with `history` `domain=image` and its `image_id`.

## Common mistakes

- Sending a `base_revision` ahead of the project: `E_VALIDATION`.
- Retrying a conflict unchanged. Read the diff first.

## Next steps

- [Tracks, clips and items](/docs/concepts/tracks-clips-items)
- [Batches, revisions and idempotency for agents](/docs/agents/batches)
