What a viewer of a session sees: its current state, kept by folding changes.
A viewer that attaches to a session mid-turn, or reconnects, starts from the session's view and then applies only the changes after it. The view holds:
messages- the committed history, newest lastrun- the turn in flight, ornilwhen the session is idle. Itsitemsare the turn's steps in order, starting with its input:%{type: :user, message: message},%{type: :assistant, text: text, thinking: thinking}, or%{type: :tool, id: id, name: name, args: args, status: status, result: result, output: output, subagent: run}. A tool'sstatusis:runninguntil its result arrives, then:okor:error.outputis what the call streamed while it ran, as{:tool_output, tool_call_id, chunk}events, up to its last 64 KiB.subagentholds a foreground sub-agent's own run, folded from the{:subagent, tool_call_id, event}events of that call. Itserrorholds an{:error, reason}the turn reported.error- why the last finished turn failed, ornilqueue- input waiting to start or join a turn, in the order the session takes it, each%{kind: kind, message: message}withkindone of:prompt(a caller'srunorstreamwaiting),:steer,:follow_up,:input(submitted by id withCondukt.Sessions.submit/3), or:report(a background sub-agent's answer)background- background sub-agents by name, each%{name: name, role: role, session_id: id, call_id: id, status: status, run: run}.call_idis the tool call that spawned it,statusis:workingor:idle, andrunholds its current or last turn, the same shape as the session's own run: the message the turn started from, steering that joined it, and its steps. It isnilbefore the first turn starts.agent- the agent module, model name, thinking level, tool names, and runtime module
Nothing in the view carries a secret. User input and tool results, in the
history, the run, the queue, and the changes, pass through the session's
redactors, Condukt.Secrets included, as they do on their way to the model.
The configuration leaves out keys, URLs, options, and the system prompt.
Changes
The session's view process numbers each change. It is linked to the
session and lives as long as it does. epoch is drawn when the session
starts, so a restarted session's numbers are not mistaken for the old
one's, and seq counts its changes; the view records the position of the
last one it holds.
A change is an event the session published, with tool results redacted, or
one of:
{:run_started, message}- a turn started from this input{:input, message}- steering joined the running turn{:run_finished, error, messages}- the turn ended, addingmessagesto the history;erroris why it failed, ornil{:messages, :append | :replace, messages}- the history changed outside a turn ending, such as by compaction orCondukt.clear/1{:queue, items}- queued input changed{:background, name, entry}- a background sub-agent started or changed status, or, withnil, is gone{:background_event, name, event}- a background sub-agent's turn changed:eventis one of its events, or{:run_started, message}and{:input, message}as above
advance/4 applies a numbered change and tells a viewer when it missed one.
Changes are what a remote viewer needs; the view itself is only sent once.
Summary
Functions
Applies the change numbered seq in epoch.
Returns {:ok, view} for the next change, :stale for one the view already
holds, which a viewer drops, and :gap when the viewer missed changes or the
session restarted. On a gap, fetch the view again with
Condukt.Session.view/1 and keep applying from there.
Whether a turn is in flight.