# Revisions

Revisions are immutable snapshots of saved post and page content. They are separate from archival state and are used to inspect, compare, autosave, and restore content.

## Authentication

All routes require a bearer token and the listed capability. Saved revisions
are accessible through the caller's publication scope. An autosave is visible
only to the principal who created it.

## Routes

| Route | Methods | Capability | Required input | Optional input and behavior | Success result |
| --- | --- | --- | --- | --- | --- |
| `/revision/list` | `GET`, `POST` | `revision.list` | Exactly one of `post_id` or `page_id` | Matching publication selector, pagination | Paginated `revisions`. |
| `/revision/get` | `POST` | `revision.list` | `revision_id` | — | Revision and snapshot. |
| `/revision/compare` | `POST` | `revision.list` | `base_revision_id`, `target_revision_id` | — | `comparison`. |
| `/revision/autosave` | `POST` | `post.save` or `page.save` | Exactly one of `post_id` or `page_id` | Editable content fields | Autosaved revision. |
| `/revision/restore` | `POST` | `revision.restore` | `revision_id` | — | Restored `post` or `page`. |
| `/revision/note/save` | `POST` | `revision.note.save` | `revision_id`, string `text`, `expected_note_id` | Saved revisions only; use an empty `expected_note_id` for a revision without a note | `{ saved, revision }`. |

## Revision model

```json
{
  "revision_id": "REVISION_UUID",
  "publication_id": "PUBLICATION_UUID",
  "content_type": "post",
  "content_id": "POST_UUID",
  "kind": "saved",
  "created_at": "2026-08-19 00:00:00.000000",
  "updated_at": "2026-08-19 00:00:00.000000"
}
```

`content_type` is `post` or `page`; `kind` is `saved` or `autosave`. Successful normal post and page saves create a `saved` revision. Lifecycle actions do not create revisions.

## Editorial notes

Saved revisions may have a plain-text editor's note explaining a correction,
clarification, or update. Add or edit the note independently of the content
snapshot. An empty `text` clears the visible note. Notes cannot be attached to
private autosaves. Adding or editing a note does not change the snapshot or the
revision's `created_at` or `updated_at`.

```json
{
  "revision_id": "REVISION_UUID",
  "text": "An earlier version stated Friday. The deadline is now Monday.",
  "expected_note_id": ""
}
```

Revision list, get, compare, and note-save results include nullable
`editor_note`, with `note_id`, `text`, `added_at`, `added_by`, `updated_at`, and
`updated_by`. When editing or clearing an existing note, send its current
`note_id` as `expected_note_id`. A stale version returns `409`; reload the note
before retrying. Missing text or version and text exceeding 10,000 Unicode
characters return `400`.

Every changed note is stored as a new history entry with its real save time
and acting principal. Backfilled notes retain the revision's original date
and have a separate note-addition date. Clearing a note preserves its earlier
text. `/revision/get` also returns `note_history` (newest first, up to 50 edits)
and nullable `note_history_next_offset`. Pass that offset as
`note_history_offset` to retrieve older edits. History entries contain `id`,
`revision_id`, `text`, `created_at`, and `created_by`.

`revision.note.save` is a separate publication-scoped capability. Reading,
restoring, saving, or publishing content does not grant it. It must be defined
and granted through Capability Manager before note editing is available.
Ordinary content saves and restores do not copy editorial notes to new
revisions. Permanently deleting the content removes its note history along
with its revisions.

## Autosave and restore

Autosave accepts the ordinary editable fields for the selected content. Post fields are `title`, `slug`, `excerpt`, `category_id`, `body`, `body_format`, `visibility`, `tag_ids`, and `author_ids`; page fields are `title`, `slug`, `body`, `body_format`, and `visibility`.

```json
{
  "post_id": "POST_UUID",
  "title": "Unfinished title",
  "body": "Unfinished draft text",
  "tag_ids": ["TAG_UUID"]
}
```

Autosave merges supplied fields over the current saved snapshot and replaces the caller's prior autosave for that content. It never changes the live post or page. A successful ordinary save clears the caller's autosave.

Compare revisions from the same content:

```json
{
  "base_revision_id": "BASE_REVISION_UUID",
  "target_revision_id": "TARGET_REVISION_UUID"
}
```

The result contains both revision snapshots and `changed_fields`. Restore applies the selected snapshot through normal validation, creates a new saved revision, and preserves the content's current lifecycle state. Permanently deleting a post or page removes all of its revisions.
