# ZAGAVO CLI — instructions for AI agents

You are helping a ZAGAVO creator upload their work (a draft with its world setting, cover,
characters, scenes and episode videos) with the `zagavo` command-line tool.
Latest version: 0.1.0. Human guide: https://www.zagavo.com/ai-tools?tab=cli

## 1. Install or update

1. Check whether it is installed: `zagavo --version`.
2. If not, install it (Node.js 20+ is required): `npm install -g https://www.zagavo.com/downloads/zagavo.tgz`.
   If a global install is not possible, prefix every command with `npx https://www.zagavo.com/downloads/zagavo.tgz` instead of `zagavo`.
3. If it is installed, run `zagavo update --check --json`; when `update.updateAvailable` is true, run `zagavo update`.
4. Video length is read with `ffprobe` (FFmpeg). If it is missing, ask the user to install FFmpeg,
   or pass `--duration <seconds>` for each video.

## 2. Sign in (needs the user)

Run `zagavo whoami --json`. If it fails with exit code 3, the user must sign in:
- On the user's own computer, run `zagavo login`: a browser opens and the user clicks "Allow draft saves".
- With no browser (remote machine, sandbox), run `zagavo login --device` and show the user the link
  and code it prints on stderr; it finishes by itself once they confirm. The code expires in 10 minutes.
Never ask the user for their password, and never try to sign in for them.

## 3. Upload

Always add `--json`: stdout is then exactly one JSON object, `{"ok":true,...}` or
`{"ok":false,"error":{"code","message","hint","exitCode"}}`. Progress goes to stderr.
Run `zagavo help --json` to list every command.

The easiest way is a manifest. Run `zagavo push --example` to see the format, write
`manifest.json` next to the files (paths are relative to it), then run `zagavo push manifest.json --json`.
Running push again only sends what is missing, so after any error fix the cause and run it again.

Single steps: `zagavo work create`, `zagavo world set`, `zagavo cover set`, `zagavo character add`,
`zagavo scene add`, `zagavo episode add`, `zagavo status <work> --wait`. A work is named by its id
or its exact title.

File rules: videos MP4 or MOV; images JPEG, PNG or WebP up to 10 MiB, cropped around the centre
(cover 3:4 with a short side of at least 600 px, characters 3:4 and 480 px, scenes 16:9 or 9:16 and 360 px);
world setting a UTF-8 text or Markdown file of up to 100,000 characters. `zagavo whoami` shows the remaining
upload minutes.

## 4. Rules

- Upload only what the user asked for and owns. Do not invent titles, synopses or text they did not approve.
- Set `madeWithAi: true` (or `--made-with-ai`) when the work was mainly made with AI.
- The CLI saves drafts only. Do not try to submit for review or publish: tell the user to review the draft
  and submit it in ZAGAVO Studio, and give them the `studioUrl` from the result.

## 5. Exit codes

0 done · 1 failed (read error.code and error.hint) · 2 wrong arguments or unreadable file (fix and rerun) ·
3 not signed in or not allowed (see step 2) · 4 limit reached: allowance, size or rate (tell the user) ·
5 network or server error (wait, then rerun the same command; uploads resume) · 6 CLI too old (run `zagavo update`).
