Upstream: crates/rune/README.md § Agent tooling (headless, no window, same renderer, fixed virtual clock) at 65f8eb43f710, MIT © Anomaly. Bundled by build-rune-apps; links point at this snapshot or at GitHub at that rev.

Agent tooling (headless, no window, same renderer, fixed virtual clock)

Debug builds always take these arguments. A release build takes them with Rune's tooling feature (rune = { ..., features = ["tooling"] }; Rune's examples have it); without it the app links only its window, and a headless argument makes run fail saying so. --native --trace is the window's own and works either way.

S=target/release/settings
$S --snap out.png [--scene light] [--at 0.4] [--size 620x520] [--scale 2] [--theme dark|light]
$S --list-scenes            # default light dark reduced-motion toggles-off accent-pink slow
$S --script examples/settings/scripts/toggle.json --frames 30 --start 0.1 --out frames/
$S --script examples/settings/scripts/demo.json --video demo.mp4 [--fps 60] [--duration 3|auto]
$S --script demo.json --snap poster.png --at mark:end+0.5    # a time named by a script mark
$S --script examples/settings/scripts/keycaps.json --video keys.mp4 --keys [top-right] --pointer
$S --script examples/settings/scripts/keycaps.json --video keys.mov --keys --keys-theme light
$S --script examples/settings/scripts/demo.json --start 0.12 --frames 24 --every 3 --cols 4 \
   --strip strip.png --crop 370,74,214,36 --crop 530,305,60,30     # crops stacked per frame
$S --tree tree.json [--at T]     # key, path, role, label, text, presented rect, target, opacity,
                                 # fill/text colour, hover/press, moving
$S --trace run.jsonl             # motion-trace JSONL (the app trace format); keyed elements only
$S --native --trace run.jsonl --frames 240  # native submission timestamps, then close the traced window
L=target/release/launcher        # every window of a multi-window app, composited over a backdrop
$L --desktop examples/launcher/backdrop.png --script examples/launcher/scripts/demo.json \
   --video desktop.mp4 --keys --pointer
  • Scripts are timestamped move, down, up, tap (hold), double-click (hold, gap, default 0.15 s between presses) and drag (dx, dy, dur) events, at x,y in points or at an element by key (or a path of keys such as slider/knob, where elements without keys between them don't count). {"reopen": true} reopens the app, as a click on its Dock icon (see "App lifetime"). {"open_url": "myapp://…"} hands App::on_open_url a link, as the system does when a link opens the app. menu-pick (with an id) and menu-cancel answer an open pop-up menu, file-dialog (with a path) and file-dialog-cancel an open file dialog (see "File dialogs"). drag_files and drop_files drag files in from another app (see "Dropping files in from other apps").

  • Keys in scripts: {"type": "key", "name": "Enter"} (with cmd, shift, alt, ctrl) and {"type": "type", "text": "hi"} reach the window even while the app has hidden it: headless there is no real window to hide, so on_key sees every key it would see in a focused window (first when nothing has focus, otherwise what the focused control and focus navigation leave). cmd with any single character (a letter, 1, ,) arrives as Key::Command(c), lowercased, as in a window; other keys keep their modifiers in KeyEvent::mods. " " gives Key::Command(' '), where a window sends Cmd-Space as Key::Text(" ") with mods.cmd, the only Text that carries cmd; KeyEvent::is_command(' ') matches both. "code": "7" (any key name {"physical": …} takes) adds the physical key behind a press, as a window sends it, for handlers that read tx.physical_key(); the key is released right after. With a "code", "base": "a" sets tx.key_base(); without it a one-character name pressed without shift or alt is its own base, lowercased. {"physical": "cmd+k"} reaches only on_physical_input handlers. {"type": "key-up", "name": " "} releases a key for on_key_up.

  • Canvas input in scripts: {"type": "wheel", "dx": 0, "dy": -40} is one wheel delta (with cmd and the other modifiers, "phase": "began" | "moved" | "ended" and "precise", true by default), unlike scroll's eased swipe. {"type": "magnify", "delta": 0.1}, {"type": "rotate", "degrees": 15} and {"type": "smart-magnify"} are trackpad gestures. Each lands at x,y or key, else where the pointer is. "button": "middle" (or back, forward, secondary) on down, up, tap and drag presses with that button.

  • Window resize in scripts: {"type": "resize", "dw": -300, "dh": 0, "dur": 0.5} is a person dragging the window's corner, one viewport step a frame with an eased hand, as a live resize delivers it (content at rest follows; unlike Tx::resize_window). The canvas keeps its size, so grow only after shrinking to see the whole window.

  • Chords: {"type": "shortcut", "chord": "cmd+space"} is the user pressing a chord system-wide (mod+space is ⌘ on macOS and Ctrl elsewhere, as in a Chord). Register it with App::global_shortcut or register_shortcut. Only its shortcut handler runs, exactly as when the OS delivers it: it never reaches on_key, focused controls or physical-input handlers, even when the window is key. An unregistered chord fails the script. The older {"shortcut": "cmd+k"} has the same semantics. To send a window key instead, use {"type": "key", "cmd": true, "name": " "}.

  • Keycaps: --keys [CORNER] draws the script's keys over the frames, screencast style: typing within a second joins one cap, a repeated chord counts (↓ ×3), modifiers show as ⌃⌥⇧⌘ and named keys as glyphs (↩ ⎋ ⇥ ⌫ ␣). Caps spring in and fade out after 1.5 s, three at most, at bottom-left (default), bottom, bottom-right, top-left, top or top-right. Caps have one fixed screencast style, independent of the app's palette and fonts. --keys-theme auto|light|dark chooses its light or dark colours; auto (default) follows the app's root background, falling back to --theme when the background is transparent. --pointer adds a ripple at each press. A separate runtime draws both after the app, so they appear in --video, --out, --snap and strips but never in --tree or --trace. That runtime is a second Runtime in the exe (about 1.46 MB), so a release build draws them only with the keys-overlay feature (which includes tooling; Rune's examples have it); debug builds always do.

  • Desktop recordings: --desktop BACKDROP.png renders all of a multi-window app's visible windows into one frame, so a launcher, its panel and the app's other windows record together the way a screen recording would show them. Each window renders with its own state into its own texture and is drawn at its frame: WindowOptions::position, place(), else centred on the primary display. Titled windows get 10 pt rounded corners; borderless and transparent windows keep their own shape and alpha. Each window casts a soft shadow from its visible pixels, larger for the key window, unless MacWindowOptions::shadow(false). Always-on-top windows stay above the rest. The backdrop is scaled to cover the output, centred and cropped. The output is --size points if given, else the script's primary display ({"displays": [...]}), else the backdrop's pixels ÷ --scale, times --scale pixels; without scripted displays the window factory sees one display of that size. Script x,y and key positions are output points. A press goes to the topmost window under it that takes clicks, brings it to the front and gives it the keyboard; a press on the backdrop deactivates the app, as clicking the macOS desktop does: no window has focus and keys go nowhere until a press on a window or {"focus": true}. Keys go to the key window; shortcuts and menu picks go to the key window's app first, then the others. Show, hide, place, focus and close requests apply as they would natively, in the frame whose handlers made them, but quit doesn't end the recording. When the key window hides, the topmost visible window that takes clicks gets the keyboard; a click-through window never does. --size and --scale must be above 0, the output at most the GPU's texture size, and the backdrop at most 16384 pixels a side. --keys and --pointer draw over the composite. --window KEY picks the window --tree, --trace and --scene describe, and the tree adds a windows list of every window's frame. headless_run() gives desktop(), the window frames as they change (window_frames()) and as they stand at a time (windows_at(t)). The compositor draws no window chrome, so an app that wants a title bar or a menu bar in the recording draws one (examples/launcher does both).

  • Rounded panels: el().clip_rounded(radius) clips an element and its descendants to a rounded rectangle, so a recording of a view meant for a rounded window can round it in the frame the way the window would.

  • Marks: {"t": 3.2, "type": "mark", "name": "end"} names a time and does nothing else. --at mark:end, --at mark:end+0.5 and --start mark:intro-0.2 use a mark's time, and --duration auto (the default with --video) ends at the end mark, or one second after the last event without one. Apps read them with headless_run().mark("end"). Exact names take precedence: mark:step-1 selects the mark named step-1, if present; mark:step-1+0.5 adds half a second. Offsets are numbers in seconds, without a unit suffix.

  • Video: --video out.mp4 streams frames into ffmpeg (which must be on PATH) over a pipe: .mp4 is H.264 yuv420p with +faststart, .mov ProRes 4444 with alpha, .webm VP9. It runs --frames N or --duration SECONDS from --start (default: through the end mark, or one second after the script's last event). Readback keeps three frames in flight, so the GPU renders the next frame while the last one is copied out. --out PNGs share the readback and encode on worker threads, retaining their frame_0000.png names and --every sampling. Video always includes every frame at --fps; --every only samples PNGs and strips. Missing ffmpeg fails before GPU startup; encoder errors fail the command with its exit status. --duration auto --out frames/ also records headlessly; --out alone uses auto duration. Single-window apps honour window_options transparency and physical size; --size overrides that size. PNG and ProRes preserve transparent backgrounds.

  • The app can read the run: rune::tooling::headless_run() is Some in a headless run, from init on, and None in a window. It gives the script path and its events as Rune feeds them (tap expanded to move, down and up; type to one key per character), scale(), fps(), size(), start(), frames() written and end(), the last frame's time. One run serves every window of a multi-window app.

    use rune::tooling::ScriptEvent;
    
    if let Some(run) = rune::tooling::headless_run() {
        let typed = run.events().iter().filter(|e| matches!(e.event, ScriptEvent::Key { .. })).count();
        let end_card = run.mark("end").unwrap_or(run.script_end() + 1.0);
    }
    
  • Timing: every headless run prints per-frame CPU time (update, build and encode/submit, without readback).

  • Startup: --first-pixels emits a flushed marker after the first offscreen GPU readback. Build target/perf/settings with --profile perf. Then python3 scripts/bench-startup.py --out perf/startup times fresh process launch to that marker (one warmup, seven runs), including loader, app state, GPU work and readback, excluding PNG encoding. This measures process-cold startup with warm OS/driver caches, not physical display presentation.

  • Motion gate: rune::motion_gate records an app's real Runtime frame by frame in its own cargo test and fails on motion a person would notice (pops, jumps, overshoot, flicker, motion that never settles) unless the app's allowlist gives a reason. scripts/motion-audit/gate runs it with a cell filter and dump or contact-sheet evidence; see scripts/motion-audit/README.md.

  • Trace quality: python3 scripts/trace-quality.py run.jsonl reports scene-edge error against analytic samples, inherited spatial spring velocity error at retarget, CPU budget excess, and virtual cadence. Growth/scroll are renderer-owned and excluded from the analytic edge metric; virtual timestamps do not measure display hitches. Diagnostics are enabled only with --trace. --native --trace records wall-clock CPU submission timestamps (not GPU completion or scanout). In a window factory, --window KEY selects the traced window; otherwise the first is traced. macOS windows and overlays acquire drawables on coalesced display-link ticks, stopping the link while idle or hidden. cargo run --profile perf -p rune --example pacing -- --native --trace pacing.jsonl --frames 240 exercises spring retargets and hide/show; check it with python3 scripts/check-native-pacing.py pacing.jsonl on a machine with a display. Trees expose inherited opacity, scale and blur (logical points); traces keep opacity in element rows and encode scale/blur as named scalar channels (cm/c/cg).

  • Present times (macOS windows): --native --trace frames also carry target_ms, the display link's target for the frame, and present_ms, the drawable's Metal presentedTime (when it reached the screen), both in ms on t's clock. present_dt_ms is the gap since the previous presented frame, written only when that frame asked for this one right away, so idle time isn't counted. present_ms is null when the system skipped the drawable and absent when no time arrived. Lines are written once their present time arrives, two or three frames late. When the trace ends, stderr gets a summary: present-interval p50/p95/max, intervals under 2 ms (frames bunched onto the screen together) and over 1.5 refresh periods (missed refreshes), and the lag from target to present. Overlays, other platforms and headless traces write no present fields. Without --trace nothing changes. Capture on a display, not headless: cargo run --profile perf -p rune --example pacing -- --native --trace pacing.jsonl --frames 240.