mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-17 04:11:35 +00:00
ts_prefix captured its own start per pipe, so each log's [+MM:SS] was relative to that log's creation - the install log started at +0:00, the app-update log at +0:00 too, and no single offset could align all files with the recording. The drivers now stamp TS_BASE= $SECONDS once at start and ts_prefix stamps every line relative to it (falling back to its own start when unset): all logs in a leg share the driver's clock, and playback.html's one offset slider (recording start vs driver start) aligns every file at once. The ps1 twin was already driver-relative (TsPrefixStart is captured at dot-source time, near the driver's top). Verified: two pipes in one shell - the second starts at [+00:03], continuing the driver clock instead of resetting to [+00:00].
25 lines
1,011 B
Shell
25 lines
1,011 B
Shell
#!/usr/bin/env bash
|
|
# ts_prefix: prefix each stdin line with [+MM:SS] relative to the DRIVER's
|
|
# start (TS_BASE), not this pipe's start -- every log in a leg shares one
|
|
# time base, so the playback.html sync (one offset slider against the
|
|
# recording) aligns all files at once. The playback.html leg player uses
|
|
# these prefixes to sync a log file to the screen recording's timeline
|
|
# (the video starts a few seconds before the driver, hence the player's
|
|
# offset slider).
|
|
#
|
|
# Usage (sourced from a driver):
|
|
# TS_BASE=$SECONDS # once, at driver start
|
|
# cmd 2>&1 | ts_prefix > "$LOG_DIR/x.log"
|
|
#
|
|
# Must be the LAST consumer in the pipe: with `set -o pipefail` the exit
|
|
# status stays the command's, while ts_prefix's own status is always 0.
|
|
# SECONDS is bash-specific, so this helper is bash-only.
|
|
|
|
ts_prefix() {
|
|
local _base="${TS_BASE:-$SECONDS}"
|
|
local _line _t
|
|
while IFS= read -r _line; do
|
|
_t=$((SECONDS - _base))
|
|
printf '[+%02d:%02d] %s\n' $((_t / 60)) $((_t % 60)) "$_line"
|
|
done
|
|
}
|