---
name: ferret-live-edit
description: Use for any change to a Ferret scene seen at once: light, places and parameters by commands in the live viewer, logic by edit.game.set or ferret dev; rebuild only what changed, a full build only at the end. Replaces the rebuild-dist-reload loop.
---

# The live loop: change, look

## When to use
Setting light, sun, fog, sky, post, where things stand, a behaviour's parameters, spawns, zones. Any "make it look like the reference" iteration. Never loop through package rebuild, dist build and browser load for these: that is 20 to 40 minutes a turn; a command is seconds.

## Logic, live
- A program in the game language: `edit.game.set` in the running game, from the next step, no build (`ferret-motion`).
- A built example: `ferret dev <example>`, then `ferret scene dev:<port> ...`; a changed `.fgl` goes in live, changed TypeScript rebuilds only the example's own code and reloads (`reference/scene-runner.md`).
- Facts (in view, on the ground, errors, a game value) are asked as probes and tests, not read off a picture.

## The model
The viewer (`tools/viewer`) is a headless Chromium on the NVIDIA GPU with an HTTP command API. A level folder opened in it has the editor session "edit" (`ferret-level-editor`): `edit.patch` changes the draft and, with `live`, the level reloads at once. Nothing reaches the files until `edit.save`, which writes only `manifest.json`, `navmesh.bin`, `.ferret`, `.fprj` under the served folder.

## Steps
1. Start the viewer server on the level folder: `FERRET_GPU=1 node tools/viewer/server.mjs --headless --port <p> --files <repo root> --level /files/<path to the level folder>`, started at BelowNormal priority; commands `POST /api/command {name,args}`, frame `GET /api/screenshot.png?w=&h=`.
2. `edit.open {level:"edit", live:true}` (for `--level` the name is always "edit"). Look first: `camera.set {position,target,fov}` or `camera.view`, a frame.
3. Change by command: `edit.patch {ops:[{op:"replace",path:"/environment/sun/intensity",value:2.5}]}` (JSON pointers into the manifest: `/environment/{sun,ambient,fog,sky,reflection,post,probes}`, `/entities/N/params/...`), or the typed `edit.entity.*`, `edit.spawn.*`, `edit.zone.*`. Frame at once; compare with the reference (`ferret-frame-check`).
4. `edit.validate` must be empty; `edit.diff` lists what changed; `edit.save` writes the manifest. `edit.undo` while trying.
5. **Materials** are changed live like light: `edit.material.set|get|list|remove {scope: type|instance, uid, material}` (see `ferret-level-editor`); the command `help` lists what exists, do not invent one.
6. Sources (`tools/*.mjs`, the build inputs) are changed after the person's "ok", from the saved manifest. A build makes only what changed; the package and the dist are rebuilt when geometry changes and once at the end, never for one edit.

## Check afterwards
The frame shows the change; `edit.validate` is empty; the saved `manifest.json` differs from the old one only by what `edit.diff` said (`git diff`); the renderer string is the RTX (`WEBGL_debug_renderer_info` says "NVIDIA GeForce RTX 3050"); the viewer and its Chromium are stopped when you finish.

## What usually goes wrong
- `edit.open` fails "is not a parameter of this behaviour": the behaviour's `static schema` misses that param (add it to the schema in the engine).
- A saved test value left in a tracked manifest: keep a copy of the file before experiments and restore it.
- Capture windows over the person's work: headless only.
- A viewer left running after the task: stop it and say so in the report.

## Files

- `reference/scene-runner.md` — ferret scene and ferret dev: one headless runner on the video card for commands, Ferretic tests, probes, frames and video; a scene kept open with programs changed live and only the example's own code rebuilt.
