# Working as an agent


effects was built to be driven by a model as much as by a person. This page is written for the agent: what the loop looks like, which commands answer which question, and the mistakes that cost the most time.

## The docs as text

- [`/llms.txt`](/llms.txt) lists every page with a one-line summary.
- [`/llms-full.txt`](/llms-full.txt) is all of the documentation in one file, with the source of every demo inlined where its player would be.
- Every page is also available as Markdown: add `.md` to its address without the trailing slash, as in [`/docs/anim.md`](/docs/anim.md).

The library itself is short and commented. When a page and the source disagree, the source is right: `fx/*.odin` in the repository is about 5,000 lines.

## The loop

```bash
$ effects build projects/spot             # does it compile? errors have file and line
$ effects still projects/spot 0.4 2.5 6   # PNGs of the moments you care about
$ effects bench projects/spot             # ms per frame: is anything too slow?
$ effects mix   projects/spot             # the soundtrack alone, with its peak level
$ effects render projects/spot            # the film
```

1. **Write or change a scene.** One procedure, one file.
2. **Build.** `effects build` compiles without drawing anything. An unoptimized build takes about 0.4 s. Read the first error, fix it, build again.
3. **Look.** `effects still <project> <t>…` writes one PNG per time into `.effects/stills/` and prints their paths. Open them. Pick times that matter: just after something appears, mid-transition, the last frame of a scene. Looking at stills is the whole point: a scene that compiles can still be empty, off-screen or unreadable.
4. **Measure.** `effects bench` draws 240 frames spread across the film on one thread and prints the average and the worst frame. If the worst frame is over a second, a full-screen shader is running at full resolution somewhere: see [what things cost](/docs/performance/).
5. **Render** when the stills are right. Use `--from` and `--to` to render a stretch, and `--scale 0.5` for a quick low-resolution pass.

A person watching along can keep `effects-edit` open on the same project: it reloads on every save.

## Rules that save time

**Compute everything from time.** No state survives between frames, and frames are drawn out of order on many threads. A counter that increments per call, a global that remembers the last position, a random number without a fixed seed: all of these produce a film that flickers or differs from run to run. Use [`rng`, `hash01`](/docs/anim/#random-but-the-same-every-time) for randomness.

**Scene and cue tables are globals.** `fx.video` copies the slices, but the literals must still exist when it does.

```odin
SCENES := [?]fx.Scene{{name = "intro", start = 0, dur = 3, draw = intro}} // at file scope
```

**Paths are relative to the project.** `"assets/photo.jpg"` means the project's `assets/` directory, wherever the renderer is run from.

**The stage is 1920×1080** unless the video says otherwise. Text below about 28 px is small on a phone-sized player. Leave a margin: 160 px on the sides is the house style.

**Scopes are groups.** `if fx.group({…}) { … }` ends its group when the block ends. Do not `return` out of the middle of a scene and expect later drawing to happen, and do not call `group_begin` without `end_group`.

**Strings built per frame come from the temp allocator.** `fmt.tprintf` is right; it is freed after the frame. Do not keep pointers to it across frames.

**Durations are in seconds, angles in degrees, colors are `0xAARRGGBB`.** `fx.rgb(0xdd5b3e)` makes an opaque color from the six-digit form.

## Checking your own work

| Question | How to answer it |
| --- | --- |
| Does it compile? | `effects build <project>` |
| What does second 7.6 look like? | `effects still <project> 7.6` |
| Is the text inside the frame? | A still. `fx.measure` returns a text's size if you need to compute it. |
| Is a transition smooth? | Stills at several times across it: `effects still p 3.0 3.1 3.2 3.3 3.4`. |
| Is it too slow to render? | `effects bench <project>` |
| Is the sound clipping? | `effects mix <project>` prints the peak in dB. The mix has a soft limiter at -1 dBFS; a peak pinned there means it is working hard. |
| Where are the beats? | `effects beats song.wav` prints hits, a tempo guess and drops. |
| Did the render come out whole? | `render` counts the frames in the file it wrote and warns when they differ from what it drew. |

Stills are drawn from the unoptimized build by default. Add `--release 1` to draw them from the optimized one when a still takes long (shader-heavy frames).

## Things that go wrong

| What you see | Why |
| --- | --- |
| A black or empty still | The time is outside every scene, the scene's group is at opacity 0 at that time, or everything is drawn off-stage. |
| Banding in dark gradients | The encoder, not the drawing: gradients are dithered. Render dark, grainy films with `--crf 16 --tune grain`. |
| `fx: no cue <name>` | A scene asks for a cue that is not in the video's `cues`. |
| `fx: cannot load font …` | The path is wrong. It is relative to the project directory. |
| A shader draws nothing | Its SkSL did not compile. The error is printed once on stderr, starting with `sksl:`. |
| The film is longer than expected | `duration` defaults to the end of the last scene or of the voice-over, whichever is later. |
| Rendering uses all memory | Each worker is about 1 GB at 1080p. Workers are capped by available memory; pass `--workers n` to go lower. |

## A good first request

When asked for a video, start small: one scene with the headline, a still of it, and only then the rest. Decide the film's look once, in a `master` and an `overlay` (see [scenes and time](/docs/scenes/#master-and-overlay)), so every scene inherits it. Give each scene its own file. Keep the timeline in one table at the top of `main.odin` so the structure of the film can be read in one place.
