# Design review automation manifest

This document is the manifest data-format reference. Agents should first read
[`agent-integration.md`](/agents/guide.md) for the workflow and safety boundary, then use
[`cli-reference.md`](/agents/reference.md) for exact commands and exit statuses.

The manifest describes the intended client review using stable keys and source paths. It does not
contain a ZIP path, project password, bearer token, object-storage key, database identifier, or share
credential. The CLI supplies local package input and secrets separately.

The initial version is `design-previewer.di/v1alpha1`. A manifest is applied only after rendering,
when the system can compare every `sourcePath` and viewport key with discovered output. Validation
is all-or-nothing; unknown pages, viewports, or destinations do not create partial configuration.

```json
{
  "apiVersion": "design-previewer.di/v1alpha1",
  "kind": "DesignReviewManifest",
  "project": {
    "name": "Authority Plus",
    "clientReference": "AUTHORITY",
    "accessPolicy": "public_link",
    "visibility": "private"
  },
  "revision": {
    "pages": [
      {
        "key": "home",
        "sourcePath": "index.html",
        "title": "Homepage",
        "order": 0,
        "start": true,
        "visible": true,
        "position": { "x": 0, "y": 0 },
        "hotspots": [
          {
            "key": "learn-more",
            "viewportKey": "desktop",
            "label": "Open frequently asked questions",
            "enabled": true,
            "geometry": { "x": 0.1, "y": 0.4, "width": 0.2, "height": 0.05 },
            "action": { "type": "navigate", "destinationPageKey": "faq" }
          }
        ]
      },
      {
        "key": "faq",
        "sourcePath": "faq/index.html",
        "title": "Frequently asked questions",
        "order": 1,
        "start": false,
        "visible": true,
        "position": { "x": 360, "y": 0 },
        "hotspots": []
      }
    ],
    "connections": [
      {
        "key": "home-to-faq",
        "sourcePageKey": "home",
        "destinationPageKey": "faq",
        "label": "Learn more"
      }
    ]
  }
}
```

## Rules

- `key` values are manifest-local stable identifiers. They use letters, numbers, dots, underscores,
  and dashes and remain stable across retries of the same plan.
- `sourcePath` must exactly match a rendered relative HTML entry path returned by `revision pages`.
- Include every discovered page, including pages you wish to hide with `visible: false`.
- Page `order` values are unique non-negative integers. Exactly one visible page is the start page.
- Connections may reference only visible manifest pages. Navigation hotspots and connections are
  reconciled through application services so they cannot silently disagree.
- Hotspot geometry is normalized from `0` to `1`, remains inside the page, and is scoped to one
  renderer-reported viewport key.
- Hotspot actions are `navigate`, `preview_state`, `scroll`, `play_media`, or `external`. External
  URLs are limited to HTTP and HTTPS and retain the existing publication warning.
- A password-protected project receives its password separately through protected input. Plaintext
  passwords are never valid manifest fields.

## Intended agent flow

1. Prepare the project and upload the ZIP, returning project/revision IDs and an operation ID.
2. Poll revision status until ready, then use `revision pages` for discovered paths and viewport keys.
3. Generate or update a manifest using those stable values.
4. Dry-run the manifest and resolve every actionable validation message.
5. Apply the manifest idempotently with explicit confirmation and inspect the publication checklist.
6. Publish only with deliberate confirmation, then separately create or retrieve the active share link.

Reading comments and approval decisions is a later read-focused contract. It is intentionally absent
from this first manifest and must not be approximated through database or storage access.

## Validate locally

The first CLI command performs structural validation without credentials or application changes:

```sh
node di-review.mjs manifest validate \
  --file example-manifest.json
```

For a clean versioned JSON envelope with no package-script preamble, use:

```sh
node di-review.mjs manifest validate \
  --file example-manifest.json \
  --json
```

Exit status `0` means valid, `2` means the input or manifest is invalid, `64` means the command usage
is invalid, and `1` is reserved for an unexpected CLI failure. Local validation cannot confirm that
source paths or viewports exist in a rendered revision. For credentialed server-aware checks:

```sh
node di-review.mjs revision pages --project <uuid> --revision <uuid> --json
node di-review.mjs manifest dry-run --project <uuid> --revision <uuid> --file manifest.json --json
```

Dry-run accepts up to 1 MiB of JSON and changes no configuration. It validates ready revisions,
page coverage, viewport keys, connections and protected-video targets. It does not validate or
apply project settings, guarantee publication, or override immutable published revisions.

## Apply a reviewed plan

```sh
node di-review.mjs manifest apply --project <uuid> --revision <uuid> --file manifest.json --idempotency-key <new-uuid> --confirm --json
```

Requires `revisions.update`. Apply is a **full replacement** of the ready revision's authored page
configuration, flow and hotspots across all viewports. Include every rendered page and every hotspot
you intend to keep. Omitted hotspots are removed. Rendered artifacts, suggestions, source identities,
comments and approvals remain unchanged. Project fields are not applied; sharing is unchanged.
Missing positions get a deterministic grid. Authored connections determine order using manifest order
as stable fallback; if none are supplied the page order creates an ordering chain. Navigation hotspots
add inferred lines, merged with matching ordering pairs. Hidden pages are ordered last.

The entire encoded apply request (manifest plus confirmation/retry wrapper) is capped at 1 MiB.
Validation, replacement, the retry record and audit records share one database transaction. Retry with
the same key and input after interruptions; changing input or target returns `idempotency_conflict`.
A successful replay returns the original summary and current checklist without overwriting later edits.
New applies reject published revisions; a replay may report an apply that happened before publication.
Applying never publishes. Inspect `data.publication.ready` and each check in `data.publication.checks`.
