timeline

package
v0.0.0-...-53bd38a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package timeline turns one session's events into spans on a time axis: which Claude Code agent was generating, which tool it was running, when a subagent was spawned and when its result came back, and which hosts the session talked to. agentop's Timeline pane draws them.

Computed on read from the whole history rather than folded at append time. A session is a few thousand events, and reading all of them removes every ordering problem an incremental fold has: a subagent's first request routinely lands before the response that spawned it is recorded, because Claude Code starts a tool while the response is still streaming.

Build depends only on model.SessionEvent, so it works on events from the store, the archive, or any other producer that fills the same fields.

Index

Constants

View Source
const HostLostAfter = 10 * time.Minute

HostLostAfter is how long an unanswered request may sit before it is called lost. Ten minutes covers the longest real model calls (the slowest seen was under 22 minutes, and those were the rare tail), while not drawing a dead stream as busy.

Exported for agentop's events pane, which marks the same requests lost by the same rule, so a request is never lost in one pane and in flight in the other (#1681).

View Source
const MainAgent = toolpair.MainAgent

MainAgent is the agent id of the main conversation.

ALIASED, NOT RESPELLED. core/session/toolpair assigns these keys and this package compares against them (buildAgents' resent line, and agentLabel). Two literals that must be equal and are written in two files drift in silence: the comparison simply stops matching, and every subagent turn reads as a fresh agent. Taking the value from the producer makes that impossible rather than unlikely.

View Source
const UnseparatedAgent = toolpair.UnseparatedAgent

UnseparatedAgent holds subagent traffic recorded before the proxy captured Claude Code's agent id header (#1459): AgentRole says "subagent" but nothing says which one.

Variables

This section is empty.

Functions

func AfterInterrupt

func AfterInterrupt(s string) string

AfterInterrupt is what the person typed after an interrupt: the human text after the last interrupt line, or "". Only after it: what comes before is the cancelled tools' (a "Tool loaded.", a skill's body).

func HostKey

func HostKey(host string) string

HostKey is the row a host lands in: lowercased, with the default HTTPS port dropped, so a request to h and an opaque tunnel to h:443 share one row. Other ports stay distinct.

func HumanText

func HumanText(s string) string

HumanText returns what is left of a user message's text once the injected blocks and lines are taken out, trimmed: "" when the person typed none of it. Each tag is one pass that copies what it keeps, so a message of many reminders costs its length, not its length squared.

func InsideInjected

func InsideInjected(s string) bool

InsideInjected reports whether the end of s is inside an injected block: an injected tag opens in s more times than it closes.

func IsSuggestionCall

func IsSuggestionCall(msgs []model.InferenceMessage) bool

IsSuggestionCall reports whether the newest user message asks for a suggestion.

func QueuedText

func QueuedText(s string) string

func RejectedReason

func RejectedReason(ids string, results []model.InferenceToolResult) string

RejectedReason returns the person's words in a rejection of one of the calls ids names (", "-joined): the human text after "the user said:". It returns "" when no such result has words.

func WithoutInjected

func WithoutInjected(s string) string

WithoutInjected returns s with each injected tag's blocks removed.

Types

type Agent

type Agent struct {
	ID     string `json:"id"`
	Parent string `json:"parent,omitempty"`
	Label  string `json:"label"`
	Type   string `json:"type,omitempty"`
	// SpawnTool is the id of the Agent tool call that started this agent.
	SpawnTool  string     `json:"spawnTool,omitempty"`
	SpawnedAt  *time.Time `json:"spawnedAt,omitempty"`
	ReturnedAt *time.Time `json:"returnedAt,omitempty"`
}

Agent is one row of the agent tree.

type Host

type Host struct {
	Host   string     `json:"host"`
	Kind   Kind       `json:"kind"`
	Start  time.Time  `json:"start"`
	End    *time.Time `json:"end,omitempty"`
	Status int        `json:"status,omitempty"`
	Error  bool       `json:"error,omitempty"`
	Lost   bool       `json:"lost,omitempty"`
	Seq    uint64     `json:"seq"`
	// contains filtered or unexported fields
}

Host is one outbound request, or one opaque tunnel, to a host.

type Job

type Job struct {
	Agent string `json:"agent"`
	ID    string `json:"id"`
	// ToolUseID is the Bash call whose result started the job. Empty from an older proxy.
	ToolUseID string     `json:"toolUseId,omitempty"`
	Start     time.Time  `json:"start"`
	End       *time.Time `json:"end,omitempty"`
	Seq       uint64     `json:"seq"`
}

Job is a background shell command: from the tool result that acknowledged it ("Command running in background with ID: …") to the <task-notification> naming that id, or to the TaskStop result that stopped it. Its tool call ends at the acknowledgement, so without this the agent looks idle while the job runs.

type Kind

type Kind string

Kind classifies a host span.

const (
	KindLLM    Kind = "llm"
	KindMCP    Kind = "mcp"
	KindHTTP   Kind = "http"
	KindTunnel Kind = "tunnel"
)

type Prompt

type Prompt struct {
	// Index is the prompt's number in the session, from 1. A clipped window keeps the session's
	// numbering, so its first prompt need not be 1.
	Index int `json:"index"`
	// Start is the request of the prompt's first call; End the end of its last call to finish,
	// a subagent's included. Absent while one of its calls is still open. A call that runs past
	// the next prompt's start (a background subagent's) carries End past it: prompts can overlap.
	Start time.Time  `json:"start"`
	End   *time.Time `json:"end,omitempty"`
	// FirstSeq is the first call's request; LastSeq the last call's.
	FirstSeq uint64 `json:"firstSeq"`
	LastSeq  uint64 `json:"lastSeq,omitempty"`
	// ThinkMs is the person's time before this prompt: from the end of the previous prompt's
	// last main-agent call to this prompt's start. Absent for the first prompt.
	ThinkMs int64 `json:"thinkMs,omitempty"`
	// Source is how the prompt was found: "derived", from the bodies. Telemetry (#1924) will
	// add "telemetry".
	Source string `json:"source"`
}

Prompt is one human instruction and the calls it caused.

type Return

type Return struct {
	Agent string    `json:"agent"`
	Into  string    `json:"into"`
	At    time.Time `json:"at"`
	Seq   uint64    `json:"seq"`
}

Return is a subagent's result reaching another agent's context.

type Timeline

type Timeline struct {
	ID        string    `json:"id"`
	LastSeq   uint64    `json:"lastSeq"`
	Start     time.Time `json:"start"`
	End       time.Time `json:"end"`
	Truncated bool      `json:"truncated,omitempty"`
	Agents    []Agent   `json:"agents"`
	Turns     []Turn    `json:"turns"`
	Tools     []Tool    `json:"tools"`
	Returns   []Return  `json:"returns"`
	Hosts     []Host    `json:"hosts"`
	// Jobs are background shell commands. Omitted when empty, so an older agentop never sees it.
	Jobs []Job `json:"jobs,omitempty"`
	// Prompts group the turns by the human instruction that caused them (prompts.go). Omitted
	// when empty, so an older agentop never sees it.
	Prompts []Prompt `json:"prompts,omitempty"`
	// contains filtered or unexported fields
}

Timeline is one session's spans. An absent End means the span is still in flight. A span that never got an answer but provably stopped (its agent moved on, or the session did) is Lost: its End is its Start, so it draws as a tick rather than a bar that runs forever. On real sessions some unanswered requests were eleven days old.

func Build

func Build(id string, events []model.SessionEvent, now time.Time) *Timeline

Build computes the timeline of events, which must be one session's events in Seq order. now ages out requests that never got an answer; see LoseUnanswered.

func (*Timeline) Clip

func (t *Timeline) Clip(from, to time.Time)

Clip keeps the spans that overlap [from, to]. Zero bounds are open. Agents are kept whole, so a client can lay out the tree before it has fetched every window.

func (*Timeline) FillLive

func (t *Timeline) FillLive(bytes func(requestID string) (int64, bool))

FillLive sets LiveTokens on each open turn for which bytes gives the stream size. It uses the bytes-per-token ratio of the long finished turns of the session. With no ratio, it does nothing. It writes the turns, so a cache runs it on a copy whose Turns it owns.

func (*Timeline) LoseUnanswered

func (t *Timeline) LoseUnanswered(now time.Time)

LoseUnanswered ends, as lost, each request still unanswered HostLostAfter before the later of now and the session's newest event. The one part of a timeline that depends on the clock, so a cache can keep the rest until the session records something new and run this on each read. It writes h.End, so a cache runs it on a copy whose Hosts it owns.

type Tool

type Tool struct {
	Agent   string     `json:"agent"`
	ID      string     `json:"id"`
	Name    string     `json:"name"`
	Start   time.Time  `json:"start"`
	End     *time.Time `json:"end,omitempty"`
	Preview string     `json:"preview,omitempty"`
	Error   bool       `json:"error,omitempty"`
	Lost    bool       `json:"lost,omitempty"`
	Seq     uint64     `json:"seq"`
}

Tool is one tool call: from the response that requested it to the agent's first request carrying its result.

type Turn

type Turn struct {
	Agent  string     `json:"agent"`
	Start  time.Time  `json:"start"`
	End    *time.Time `json:"end,omitempty"`
	Finish string     `json:"finish,omitempty"`
	// Error is a call that failed: an upstream error, the client giving up, or a finish in
	// failedFinish.
	Error bool `json:"error,omitempty"`
	Lost  bool `json:"lost,omitempty"`
	// Resent is a call that sent the agent's previous call's conversation again, unchanged: a
	// retry, so the time before it went to retrying rather than to the user, who added nothing.
	Resent bool   `json:"resent,omitempty"`
	Seq    uint64 `json:"seq"`
	// Model is the model the call asked for, so a client that runs several models side by
	// side (Bob's premium-ide turns beside its security classifier) reads apart.
	Model string `json:"model,omitempty"`
	// OutputTokens is the number of tokens the response generated, as its usage reports it.
	OutputTokens int `json:"outputTokens,omitempty"`
	// LiveTokens is an estimate of the tokens an open response has streamed until now. Only
	// FillLive sets it.
	LiveTokens int `json:"liveTokens,omitempty"`
	// contains filtered or unexported fields
}

Turn is one model call an agent made: from its request to the end of the response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL