Metadata-Version: 2.4
Name: amagi-democast
Version: 0.1.0
Summary: Turn the shell blocks in your README into a demo GIF from a real run, and fail CI when the tool's output no longer matches the GIF. Pillow only: no ffmpeg, ttyd, Go or Node.
Author-email: "AmagiLabs (Amagisolutionsgroup, Inc.)" <dev@amagisolutionsgroup.com>
License: MIT
Project-URL: Homepage, https://github.com/amagilabs/amagi-democast
Keywords: gif,demo,readme,terminal,cli,documentation,ci,screencast,claude-code
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Environment :: Console
Classifier: Topic :: Documentation
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Multimedia :: Graphics
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Pillow>=9.1
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Dynamic: license-file

# amagi-democast

Make the demo GIF in your README from a real run of the commands in it, then fail CI when the tool's output stops matching the GIF. Pillow is the only dependency.

A README demo GIF goes stale the moment you rename a flag or reword an error. Nobody notices, because nothing checks it. amagi-democast reads the commands from a code block you mark in your README, runs them, draws the real output as a terminal GIF, and saves what each command printed next to the GIF. `amagi-democast check` runs them again and exits `1` with a diff when the output, an exit code or the GIF itself has changed.

![demo](assets/demo.gif)

## Install

```bash
pipx install amagi-democast
```

Python 3.9 or newer. The one dependency is Pillow. No ffmpeg, ttyd, Go or Node.

## Usage

Put a `<!-- democast -->` comment on the line above a code block of commands. GitHub does not render the comment, so readers see a normal code block:

````markdown
<!-- democast -->
```console
$ mytool --help
$ mytool run example.txt
```
````

Then, from the folder with the README:

```bash
amagi-democast record     # run the commands, write assets/demo.gif and assets/demo.democast.json
amagi-democast check      # run them again; exit 1 if anything drifted
amagi-democast list       # show the marked blocks and their commands
```

The GIF at the top of this page was made by `amagi-democast record` from this block in this README:

<!-- democast -->
```console
$ amagi-democast list examples/greet
$ amagi-democast check examples/greet
$ amagi-democast check examples/drifted
```

Real output of those three commands:

```
$ amagi-democast list examples/greet
block 1 (line 7)
  $ python greet.py Ada
  $ python greet.py Ada --shout
  $ python greet.py

$ amagi-democast check examples/greet
OK  3 commands in examples/greet/README.md still match examples/greet/assets/demo.gif

$ amagi-democast check examples/drifted
DRIFT  the demo GIF no longer matches what the commands print (2 problems)
  - step 1 `python greet.py Ada`: output changed
    --- in the GIF
    +++ now
    @@ -1 +1 @@
    -Hello, Ada!
    +Hi there, Ada.
  - step 2 `python greet.py Ada --shout`: output changed
    --- in the GIF
    +++ now
    @@ -1 +1 @@
    -HELLO, ADA!
    +HI THERE, ADA.
Fix: run `amagi-democast record` and commit the new GIF, or revert the change.
```

`examples/drifted` is a copy of `examples/greet` that was recorded, after which its greeting was changed from `Hello, Ada!` to `Hi there, Ada.` without recording again. That is the stale-GIF case `check` exists to catch.

Exit codes: `0` everything matches, `1` drift (or no recording yet), `2` usage error, such as a README with no marked block.

## In CI

```yaml
- run: pipx install amagi-democast
- run: amagi-democast check
```

Run `check` on the same operating system you recorded on, since command output often differs between Windows and Linux.

## Options

| Option | What it does |
|---|---|
| `README` | Markdown file or folder to read (default `README.md`) |
| `-o, --output GIF` | Where the GIF goes (default `assets/demo.gif` next to the README). The sidecar is `<name>.democast.json` beside it. |
| `--ignore REGEX` | Text matching REGEX is treated as equal when checking, for timings, dates and temp paths. Repeatable. |
| `--timeout S` | Seconds each command may run (default 60). A timeout is shown in the GIF as exit code 124. |
| `--cols N` | Terminal width in characters (default 100). Long lines wrap. |
| `--rows N` | Terminal height for `record` (default: fit the output, 8 to 28 lines). Longer output scrolls. |
| `--theme dark\|light` | Colours for `record` |
| `--title TEXT` | Window title for `record` (default: the README's folder name) |

Per-block options go in the comment itself: `<!-- democast cwd=examples timeout=120 ignore="took [0-9.]+s" -->`. The `cwd` option is relative to the README.

## How it works

1. **Find.** Every fenced block with a `<!-- democast -->` comment above it, in order. In a block with `$ ` lines, those lines are the commands and the rest is treated as sample output. Otherwise every non-empty line that is not a `#` comment is a command. Several marked blocks make one GIF.
2. **Run.** Each command runs through your shell in the README's folder, with `NO_COLOR=1` and `TERM=dumb` so colour codes stay out. Stdout and stderr are both captured. A nonzero exit is shown in the GIF as `[exit code N]` and is not treated as a failure, because a demo often shows an error on purpose.
3. **Draw.** The command is typed out, the output appears, and the last frame holds. The font is Consolas, Menlo or DejaVu Sans Mono, whichever the machine has, or Pillow's built-in font if none is found. Frames are stored with their own durations, so pauses cost nothing.
4. **Save.** The sidecar JSON holds each command, its output with colour codes stripped, its exit code, and the GIF's SHA-256.
5. **Check.** `check` compares the README's commands with the sidecar, runs them again, and compares output and exit codes after normalising line endings and trailing spaces. It does not redraw the GIF, because fonts differ between machines. It checks the GIF file against the recorded hash instead.

## How it differs from vhs and asciinema

[vhs](https://github.com/charmbracelet/vhs) records a GIF from a `.tape` script you write, and needs ttyd and ffmpeg. [asciinema](https://asciinema.org) records a terminal session to its own cast format. Both make better-looking recordings. Neither tells you when a recording no longer matches the tool. amagi-democast takes its commands from the README itself and adds the `check` step, at the cost of a plainer animation: no real terminal emulator, no colours, no interactive programs.

## Limits

- Commands run with your current `PATH`, so install the tool or activate its venv before you record. `record` warns when a command is not found.
- Commands run without a terminal attached. Programs that need one (full-screen apps, prompts, progress bars that redraw) show their non-interactive output or hang until `--timeout`.
- Colour is stripped. The GIF is drawn in one foreground colour, with nonzero exit codes in red.
- Commands run through `cmd.exe` on Windows and `/bin/sh` elsewhere, so write the block for the shell you record on. The example uses `python`, which may be `python3` on Linux.
- `check` compares text, not pixels. Changing `--cols`, `--theme` or fonts does not count as drift until you record again.

## If this saved you time

A star helps other people find it.

## More from AmagiLabs

- [amagilabs](https://github.com/amagilabs): other small open source dev tools from the same lab.
- [amagi-hookguard](https://github.com/amagilabs/amagi-hookguard): Claude Code hooks that block `rm -rf ~`, force pushes and `.env` reads.
- [amagi-docleak](https://github.com/amagilabs/amagi-docleak): checks a file you are about to send for tracked changes, metadata and badly redacted text.
- [amagi-legal-review-skills](https://github.com/amagilabs/amagi-legal-review-skills): Claude Code skills for contract and lease review.

## License

MIT, see [LICENSE](LICENSE). Copyright (c) 2026 Amagisolutionsgroup, Inc. (AmagiLabs)
