Documentation
¶
Overview ¶
Package timeline folds an ordered stream of session events into the nodes the connect TUI renders. It mirrors the fold of the web session viewer that --web serves, so both views agree on turns, tool previews, bodies and truncation caps. Pure: no I/O, no styling.
Files:
- timeline.go: the fold's output types (Node, Block, ToolCall, Status).
- fold.go: Fold, the reducer that builds and refines those nodes.
- tools.go: one-line previews and expanded bodies for tool calls.
- eventtext.go: the readable text of any event.
- sanitize.go: stripping terminal control sequences from event text.
Index ¶
- func EventText(ev Event) string
- func Sanitize(s string) string
- func ToolDisplayName(ev Event) string
- func ToolKind(name string) string
- func ToolPayloadPreview(ev Event) string
- func ToolPreview(ev Event) string
- type Block
- type BlockKind
- type Event
- type Fold
- type Lifecycle
- type Line
- type LineKind
- type Node
- type NodeKind
- type Status
- type ToolCall
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EventText ¶
EventText is an event's readable text: joined text blocks for messages and tool results, the message for errors, explanation/description for outcomes. "" if none.
func Sanitize ¶
Sanitize strips what a terminal would act on rather than print: escape sequences (CSI, OSC, DCS/PM/APC, or a lone ESC and the byte after it), C0 controls other than \n and \t, DEL, and C1 controls. Event text is authored by models, tools and peers; rendered raw it could clear the screen, move the cursor or retitle the window. Everything else, valid UTF-8 or not, passes through untouched.
func ToolDisplayName ¶
ToolDisplayName is the name to show for a tool use, qualified by its MCP server when it has one.
func ToolKind ¶
ToolKind maps a tool name to the built-in whose body renderer applies; "" is unknown.
func ToolPayloadPreview ¶
ToolPayloadPreview prefers what will actually execute over the model's own description of it, for places where the user is asked to approve it.
func ToolPreview ¶
ToolPreview is the call's one identifying argument on a single line: the first string-valued key in a fixed precedence, whitespace collapsed, capped at previewMaxRunes.
Types ¶
type Block ¶
type Block struct {
Kind BlockKind
Event Event // every kind but BlockTools
Calls []ToolCall // BlockTools
}
Block is one thing a model request produced, in arrival order. Consecutive tool uses share one BlockTools; anything else between them starts another.
type Event ¶
type Event = anthropic.BetaManagedAgentsSessionEventUnion
Event is one session event as the API returns it.
type Fold ¶
type Fold struct {
// contains filtered or unexported fields
}
Fold is the reducer that builds and refines the nodes: Upsert files an event and Reset refolds a whole log. Queued user nodes (sent, not yet ingested) wait at the tail and everything else files ahead of them, where the server will order it once it ingests them. The accepting turn is always the last node before that tail; only queued nodes ever shift, and each owns just its own id, so indices held in `owner` stay cheap to keep valid.
type Lifecycle ¶
type Lifecycle string
Lifecycle is where a ToolCall stands, derived from its parts.
type Line ¶
Line is one styled line of a tool body.
func ToolBody ¶
ToolBody is the expanded view of a call: the user's verdict if any, the input in the tool's own idiom, then the result. Write and edit results are one-line acks, so they only surface on error.
func TruncateDense ¶
TruncateDense keeps the head of a body within the dense caps and appends a note saying what it dropped. denseMaxChars counts runes, newlines included; the line that crosses it is cut to the remaining budget on a rune boundary.
type LineKind ¶
type LineKind int
LineKind says how a renderer should style a Line of a tool body.
const ( LineMeta LineKind = iota // dim header: a path, or "@@" between edits LineCmd // the call's one-line input: "$ cmd", "pattern in path", url LineOut // payload: result text, written content, diff context, input JSON LineAdd LineDel LineErr // result text of a failed call LineNote // "(non-text content)", "… N more lines" LineAllow // the user's verdict: "Allowed" LineDeny // "Denied — msg" )
type Node ¶
type Node struct {
Kind NodeKind
Event Event // the node's event; NodeTurn / NodeOutcome: the span start, if seen
Blocks []Block // NodeTurn
Open bool // NodeTurn: no span.model_request_end yet
Brief *Event // NodeThreadReceived: our last thread_message_sent to that peer
OutcomeEnd *Event // NodeOutcome: the verdict (Result, Explanation); nil while grading
IdleFrom, IdleTo time.Time
}
Node is one row group of the transcript, in render order.
type NodeKind ¶
type NodeKind string
NodeKind says what a Node represents and which of its fields are set.
const ( NodeTurn NodeKind = "turn" NodeUser NodeKind = "user" NodeThreadReceived NodeKind = "thread_received" NodeOutcome NodeKind = "outcome" NodeError NodeKind = "error" NodeInterrupted NodeKind = "interrupted" NodeRescheduled NodeKind = "rescheduled" NodeTerminated NodeKind = "terminated" NodeOutcomeDefined NodeKind = "outcome_defined" NodeIdle NodeKind = "idle" // a status_idle→status_running gap >= idleThreshold NodeSilent NodeKind = "silent" // status machinery between turns; verbose-only NodeUnknown NodeKind = "unknown" // system.message, thread_context_compacted, anything unrecognised )
type Status ¶
type Status struct {
State string // running | idle | rescheduling | terminated | deleted | ""
StopReason string // status_idle only: end_turn | requires_action | retries_exhausted
Pending []ToolCall // requires_action calls still AwaitingApproval, oldest first
}
Status is the latest session.status_* (or session.deleted) event, digested. StopReason "requires_action" with no Pending means the session waits on a custom tool result (a worker's job), not on an approval we can give.