> ## Documentation Index
> Fetch the complete documentation index at: https://demoman.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Refresh

> How Demoman records the repo's flows again and decides which videos changed.

```bash theme={null}
npx demoman refresh
```

A refresh records every flow in the repo again from its DemoScript, with no
agent, and replaces a flow's exports only when the picture changed. CI runs it
on the trigger you chose in [Keep videos current](https://demoman.io/docs/get-started/ci.md); you can
run it locally too.

\~/nylon

<pre />

## What each line means

| Line | Meaning |
| - | - |
| `<name>: changed: <what changed>` | The picture changed: how much, and when in the video. The files are replaced |
| `<name>: added: <which file>` | It looks the same, and an output that was not there yet is written. Once, after its receipt predates page screens, `added: recorded again and not compared`: every file is replaced, with nothing compared |
| `<name>: uncompared: nothing to compare against; delivered as new` | No earlier video to compare with. The files are written |
| `<name>: unchanged: <how much changed>` | It looks the same. The files are left as they are |
| `<name>: failed: <why>` | The run was not clean. The committed files stay, and the command exits 1. When the script no longer fits the page (a target is gone, a step did not do what it asked), the line ends with the fix: ask your agent to record the flow again, then commit its `.demoman/flows/` file. With `--failures`, it also says where the run's report and last still are |

## How a change is judged

After every step, Demoman waits for the page to settle: painted, no
request open, no animation finishing, and no change on the page for 200 ms.
A request may hold it up to 6 seconds, such as an answer streamed in; the
page then gets 2 more. A request opened more than 6 seconds before a
step's wait begins, such as a long poll, is not waited for, and the run
says so (`requestNotWaited`). The page is then saved as a screen: one as each
step begins, and the last screen. A screen shows the page alone, so
Demoman's cursor, click ripple and camera never count as a change.

Each export has a receipt in `.demoman/receipts/` with those screens beside
it. A refresh records the flow again, saves the same screens, and compares
them. If the picture changed, every file of the flow is replaced along with
its receipt. The DemoScript is never rewritten, and videos are not compared
byte for byte, so an unchanged app makes no commit.

A page that never settles is still saved, unless the capture itself fails,
and is marked with what never held, such as
`before step 3: the DOM never went quiet`. That screen is never compared:
the refresh line names it beside the screens that were. When no screen
settled in both videos, nothing is compared and the flow fails with the
reason, its files left as they are.

A compared screen catches a change as small as one digit of body text, or a
colour change alone. Five things are not caught, or caught when they should
not be:

* A change seen only in motion or mid-scroll, or something that appears and
  goes within one step.
* A change too faint to count: a single character in very light text, a
  slight shade change on a thin border.
* Script that keeps changing the page never settles: its screen is skipped
  and named. Canvas drawing, a playing video and an animated GIF are not
  seen as motion, so their screen is compared as captured and can read as
  changed. A CSS spinner is held still and compared.
* A change that comes after more than 200 ms of quiet with no request open,
  from a timer alone or a slow debounce, is saved before it happens and can
  read as changed.
* A flow added on macOS is replaced once by the first refresh on Linux,
  whose fonts differ. After that, refresh in CI only.

A receipt written by Demoman 0.9.4 or earlier has no page screens. Its first
refresh records the flow again and replaces its files once, with nothing
compared, and says so: `added: recorded again and not compared`, noting
that the receipt predates page screens.

Waiting for each step adds about a second to each video's refresh. A step
whose request streams its answer waits for it.

An app that shows today's date changes every day. Pin its clock with `now`
([app.json](https://demoman.io/docs/reference/app-json.md#pinned-dates)).

## Where changed videos go

`demoman deliver pr` or `demoman deliver main` delivers what a refresh
handed off with `--hand-off`, in a CI job of its own:

* **`pr`**: force-pushes `demoman/refresh` and opens or updates one pull
  request, "Refresh demo videos", listing each changed video and any flow
  that failed, with its fix when the flow must be recorded again. Open its files
  under "Files changed" to watch them. GitHub starts no checks on a pull
  request the workflow's own token opened, so a required check waits at
  "Expected": close the pull request and reopen it to run them. The pull
  request says so too.
* **`main`**: one "Refresh demo videos" commit on the branch, pushed with no
  review.

When a flow fails in the workflow `setup --ci` writes, the run keeps each
failed flow's run report and the last frame it recorded, so you can see
where it broke without running it yourself: a refresh uploads them as the
`demoman-failed` artifact, and the check on a pull request keeps them in
`failed/` inside its `demoman-check` artifact. A workflow set up with
Demoman 0.9.7 or earlier lacks this: run `npx demoman setup --ci` again,
which updates the workflow in one pull request.

When no video changed, nothing is committed, and an open refresh pull request
whose videos are now out of date is closed with a comment.

The bot's commits and the refresh pull request's merge are marked, so they
never start another refresh.

## Keeping videos out of git

A flow added with `--deliver files` keeps only its DemoScript in the repo.
Refresh then writes the videos, receipts and a `demoman-refresh.json` listing
into `--out-dir`, and you upload the folder with your own step:

```bash theme={null}
npx demoman refresh --out-dir demoman-out --previous demoman-out
```

`--previous` is a copy of everything earlier refreshes delivered, such as your
bucket synced back down, so the new run has something to compare with.
Without it every video reads `uncompared`. See [refresh](https://demoman.io/docs/reference/refresh.md).

## The self-check

The workflow also runs on pull requests that change `demoman.yml` or
`.demoman/**`, as a `check` job that records every flow and commits nothing.
It is the setup pull request's first run. A pull request from a fork gets no
secrets, so its check fails and says why.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.