Expand description
The dayscript recorder and in-process playback (§14.6): capture the events an app
receives back into a replayable dayscript, and replay one against the live UI. See
record::start/record::play.
The dayscript recorder (DESIGN.md §14.6): the inverse of playback. Where the engine turns a
script into synthesized Day events, the recorder turns the events an app receives back into a
script. It hooks one point, day_core::set_event_observer, which every backend funnels its
native events through (day_core::enqueue_events), so it needs no per-toolkit code, and it
emits an ordinary dayscript that replays cross-toolkit through the same executor as any
hand-written one.
Scope is narrow: actions only, and only where the step is portable. A tap, a text edit, a
selection/toggle, a navigation, a back: the id-addressed things a walkthrough is made of.
Positional taps, gestures, slider drags, and native OS chrome are dropped (see
event_to_step); the resulting script is a starting point to edit, not a pixel-exact replay.
Everything here is main-thread state (the observer only ever runs on the main thread, where
day-core dispatches). On wasm there is no in-process playback (play); the WebSocket
transport drives the page instead (docs/web.md).
Functions§
- annotate_
yaml - Like
steps_to_yaml, but each step’s identifying line carries a trailing# "label"comment naming the control it came from (§14.6): its accessibility label, or its visible text. The comment sits on theid:line for a tap/input/select and theroute:line for a navigate, so a reader seesroute: focus # "Focus". Comments are ordinary YAML, so an annotated script parses and replays exactly as the bare one does; this is the form the recorder streams and saves. - clear
- Discard the recorded steps (recording, if live, continues from empty). Mirrors the emptied script into any live sink.
- exclude_
prefix - Skip events whose element id starts with
prefix: set it to the id prefix an app gives its record/stop/play controls so they never record themselves. Set beforestart*. - is_
logging_ actions - Whether
log_actionsis on. - is_
paused - Whether a live run is suspended.
- is_
playable - Whether
yamlis a non-empty, parseable script, which a Play button binds its enabled state to. - is_
playing - Whether a script is playing right now; paused counts as playing.
- is_
recording - Whether a recording is currently live.
- log_
actions - Log every action the app receives to stdout, in the recorder’s vocabulary, the same lines a recording echoes, minus the recording:
- pause_
playback - Suspend the running script between steps. The step in flight finishes, because a step is one synthesized action dispatched to the main thread, and abandoning it mid-flight would leave the UI in a state no script describes.
- paused_
signal - The reactive “playback is paused” flag. Only meaningful while
playing_signalis set. - play
- Play a dayscript in-process (§14.6): parse
yamland run each step through the same executor the socket runner uses (crate::run_step_with_wait), on a spawned thread that dispatches each step to the main thread and awaits its reply, mirroring the engine’s connection loop. Returns as soon as the run is dispatched (the steps then run asynchronously against the live UI). Refuses while a recording is live, so a replay never records itself. - play_
with_ delay - Play with an artificial pause (seconds) between each step: a slow-motion replay for watching a
script drive the UI. Returns
Errwithout spawning when the script is empty or does not parse, so a UI can call it to validate (seeis_playable) and to run from one path. - playback_
supported - Whether in-process playback exists on this target: false on wasm, which has no background thread to drive the steps from (drive the page over the dayscript WebSocket transport there, docs/web.md).
- playing_
signal - The reactive “a script is playing” flag, which a Play/Pause button binds its icon to.
- recording_
signal - The reactive recording flag:
truewhile recording. Bind a control’s label/style to it (the showcase’s Record↔Stop button does). The same global handle every call, so reads from any page track the one signal. - resume_
playback - Resume a paused run.
- save
- Write the recorded script to
path. - script
- The recorded script as canonical dayscript YAML (
steps_to_yaml);flow: []when empty. - start
- Start recording into memory only (read it back with
script/steps/save). - start_
into - Start recording, mirroring the script text into
sigon every event: the streaming, editable buffer an app binds atext_areato. Called again while already recording, it re-targets the stream atsig(keeping the recording so far) rather than restarting, which is what a page needs after it was disposed and rebuilt mid-recording. - start_
to_ file - Start recording, continuously flushing the script to
path; this is howDAY_RECORD/day launch --recordcapture headlessly. Crash-resilient: the file holds everything up to the last event even if the app is killed. - steps
- The recorded steps, cloned.
- steps_
from_ yaml - Read operations for in-process playback. Host annotations and failure policy are validated but execution remains the caller’s responsibility.
- steps_
to_ yaml - Serialize operations without host annotations, as the recorder does.
- stop
- Stop recording and remove the observer. The captured script is kept (read it with
script/steps/save, or resume with astart*). - stop_
playback - Abandon the run: the replay thread stops before its next step (immediately if it is paused). The steps already played are not undone; there is nothing to undo them with.
- version
- A counter that increments each time a step is recorded (or the recording is cleared). A UI can watch it to react to recording progress (a live step count, say) without owning the mirrored buffer signal. Global-scoped, so it survives page rebuilds.