Skip to main content

Module agent_watch

Module agent_watch 

Source
Expand description

Agents watch (POST /api/v1/agent/watch): replay the recent transcript of an agent, then tail it, for a leader that supervises a worker without opening a pane (docs/specs/SPEC_ALWAYS_AVAILABLE_AGENTS_2026_10_27.md §5.1). It reads the same output file a pane reads, by the agent’s block, so an agent with no pane (parked, or stopped) can be watched too.

A call returns whole lines and next, a byte position. Pass next back as after to get what was written since; with wait_seconds the call waits for a new line instead of answering empty. Without after it is the replay: the last max_lines lines. The position is a byte offset into the file, so a line being written is not returned until it is complete, and a read costs the new bytes, not the whole transcript. If the file shrank (a fresh session) the answer says reset and replays.

Who may watch: the same as transcript for an agent on this host, any agent on this machine; the call is not an action on the watched agent and is not audited.

Structs§

Lines 🔒
Whole lines read from a window of the file, and where the next read starts.
Read 🔒
What one read of the transcript gave.
Source 🔒
The transcript, whole in memory (an archived session) or read in spans from the file store the pane reads: the agent’s own zone in the global transcript store when it has content, else the block’s.
WatchRequest 🔒

Constants§

CHUNK_BYTES 🔒
The most one tail read takes.
DEFAULT_LINES 🔒
MAX_LINES 🔒
MAX_LINE_CHARS 🔒
The longest a line is shown; a tool result can be much larger.
MAX_SCAN_BYTES 🔒
The most searched for the end of one line before it is given up on.
MAX_WAIT_SECONDS 🔒
The longest a call waits for a new line.
OUTPUT_FILE 🔒
The zone’s file the transcript is.
POLL_EVERY 🔒
READ_ATTEMPTS 🔒
Times a read starts again because the file was swapped while it was read.
REPLAY_BYTES 🔒
The most a replay reads back from the end of the file.

Functions§

counted_gen 🔒
The counted generation of the transcript file, None when it has none.
handle_agent_watch 🔒
lines_of 🔒
The whole lines in data, which starts at byte from of the file. mid_line: from may fall inside a line, so the first piece is dropped. from_end: keep the last max lines (a replay) rather than the first (a tail). A last line with no newline yet is not returned and next stays before it.
read_from 🔒
One read of an opened source.
read_lines 🔒
The lines after after, or the tail of the transcript when after is None or no longer valid. A line longer than a read is searched for its end, up to MAX_SCAN_BYTES, and a longer one is skipped with a marker line, so a cursor never stops in front of a line or lands inside one.
shown 🔒
watch 🔒
zone_is_live 🔒
Whether the agent’s zone is still the copy being written: false when the block’s own copy is clearly newer (the zone stopped receiving lines), so a watch reads what the agent is writing now and agrees with Agents transcript (TranscriptSource::resolve, the same rule), not hours-old lines from the zone.