Expand description
§Module: log_time
Human-readable log timestamps (#opslogts) and low-level ops-log line
formatting. Operators read the supervisor session log and
.agent-doc/logs/ops.log to verify reported issues, and a bare Unix epoch
like 1781771180 is not legible. This module formats every log entry’s
timestamp as ISO-8601 UTC and parses it back, with no external date
dependency (Howard Hinnant’s civil-date algorithms).
§Spec
format_log_timestamprenders a Unix epoch (seconds) asYYYY-MM-DDTHH:MM:SSZ(UTC).parse_log_timestampis the matching reader: it accepts either a bare Unix epoch (pre-#opslogtslog lines and cycles.jsonl timestamps) or an ISO-8601 UTC string and returns epoch seconds. This backward compatibility keeps the staleness / accretion / startup-miss /gate_verifyscanners working across the format switch — old[<epoch>]lines still parse, andparse(format(x)) == xround-trips.current_log_timestampsamples the system clock and returns the current timestamp in the same ISO-8601 UTC format.format_ops_log_tracking_suffixrenders the appendeddoc=<stem>[ session=<id>][ turn=<cycle_id>]suffix without knowing how callers found those values.format_ops_log_linerenders the final bracketed ops-log line.
§Agentic Contracts
- Formatting/parsing helpers are pure and deterministic for unit testing; no I/O and no orchestration dependencies.
- Clock helpers fail closed to Unix epoch
0when the system clock is beforeUNIX_EPOCH. parse_log_timestampfails closed (None) on garbage rather than mapping it to0, so a malformed line is skipped, not mis-windowed.
Functions§
- current_
epoch_ secs - Return the current Unix epoch seconds, defaulting to
0when the system clock is earlier thanUNIX_EPOCH. - current_
human_ timestamp - Return the current timestamp in a compact human display format
YYYY-MM-DD HH:MM:SS(UTC). - current_
local_ date_ ymd - Return the current local date as
YYYY-MM-DDusing the platformdatecommand, falling back tounknown-datewhen it is unavailable. - current_
log_ timestamp - Return the current timestamp in the log format
YYYY-MM-DDTHH:MM:SSZ. - format_
human_ timestamp - Format a Unix epoch (seconds) as
YYYY-MM-DD HH:MM:SS(UTC). - format_
log_ timestamp - Format a Unix epoch (seconds) as a human-readable ISO-8601 UTC timestamp
YYYY-MM-DDTHH:MM:SSZ(#opslogts). - format_
ops_ log_ line - Render a full bracketed
.agent-doc/logs/ops.logline. - format_
ops_ log_ tracking_ suffix - Render the
#opslogtracksuffix appended to each ops-log line. - parse_
log_ timestamp - Parse a log timestamp that is either a bare Unix epoch (seconds) or an
ISO-8601 UTC string
YYYY-MM-DDTHH:MM:SSZ, returning epoch seconds (#opslogts). The trailingZis optional. ReturnsNoneon anything that is neither, so the staleness/gate scanners skip a malformed line.