Documentation
¶
Overview ¶
Package background tells which background work an agent conversation still has running — shells, monitors, async agents, dynamic workflows and pending wakeups started from its transcript — reconciled with the agent's own footer, and keeps that list current for every live tab.
Index ¶
Constants ¶
const ( Shell = "shell" Monitor = "monitor" Agent = "agent" Wakeup = "wakeup" // Workflow is a dynamic workflow (Claude Code's Workflow tool): a script that starts subagents in the background. Workflow = "workflow" )
Kinds of background work.
const ( TeammateWorking = "working" TeammateIdle = "idle" TeammateShutDown = "shutdown" )
A named teammate (the agent-teams feature: an Agent call with a `name`) lives beside the agent between its turns. It works on what it was sent, then says it is idle and waits for the next message; it is over when it shut down.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counts ¶
type Counts struct{ Shell, Monitor int }
Counts is what the agent's own footer says is running (`· 2 shells, 1 monitor ·`); its `← N agent` counts peers, not background work.
func ParseFooter ¶
ParseFooter reads the footer from a plain capture of the pane; nil when the last lines are not one.
type Deps ¶
type Deps struct {
ReadTasks func(transcript string) []Task
// ReadPane is a plain capture of the agent's pane: its footer is the authority on shells and monitors still running.
ReadPane func(tmuxSession string) (string, bool)
Reconcile func(tasks []Task, pane string, ok bool) []Task
Publish func(tabID string, tasks []Task)
Forget func(transcript string)
}
Deps are what the feed reads with and publishes to.
type Ended ¶ added in v0.15.40
Ended is a background agent or workflow that is over: how the agent said it ended ("completed", "failed", "killed", ...) and when. Only those are kept: a shell or a monitor that ended has nothing left to read.
type Feed ¶
type Feed struct {
// contains filtered or unexported fields
}
Feed keeps the background work of every live agent tab, recomputed when something happened to the tab (a transcript write, a hook, a state change) and published only when it changed.
func (*Feed) Remove ¶
Remove: the agent is gone or the tab closed, so its background work is over as far as the page is concerned.
func (*Feed) Snapshot ¶
Snapshot is every tab with background work, for a client that just connected.
type Ms ¶
type Ms float64
Ms is a time in epoch milliseconds; an unparsable time is NaN and written as null.
func (Ms) MarshalJSON ¶
type Reader ¶
type Reader struct {
// TempDir is where the agent keeps task output (<TempDir>/claude-<uid>/<project>/<session>/tasks/<id>.output).
TempDir string
UID int
Now func() float64 // epoch milliseconds
// contains filtered or unexported fields
}
Reader keeps one cursor per transcript: read once from its tail, then only what was appended since, so a busy agent's every write costs the new lines, not the whole tail again.
func (*Reader) OutputFile ¶ added in v0.15.40
OutputFile is where the agent writes a shell's or monitor's output: the path its result named, else the folder the agent keeps task output in.
func (*Reader) Read ¶
Read is the background work of a transcript still running. Reads of one transcript take turns: two at once would both consume the same appended lines.
type Source ¶
type Source struct {
TmuxSession string
Transcript string // "" when the tab has none yet
Provider string
}
Source is where a tab's background work is read from.
type Task ¶
type Task struct {
ID string `json:"id"`
Kind string `json:"kind"`
Label string `json:"label"`
StartedAt Ms `json:"startedAt"`
Until *Ms `json:"until,omitempty"` // wakeups and expiring monitors are pending only until then
Output *string `json:"outputPath,omitempty"` // gone means the task is over
// A workflow's run (wf_…, which names its folder) and the Workflow call that started it.
RunID string `json:"-"`
ToolUseID string `json:"-"`
}
Task is one piece of background work. Times are epoch milliseconds.
func ParseTasks ¶
ParseTasks is the background work a whole transcript leaves running; now is epoch milliseconds.
type Teammate ¶ added in v0.15.40
type Teammate struct {
ID string // the agent id: its transcript is subagents/agent-<ID>.jsonl beside the lead's
Name string // what the lead sends to
Description string
Model string // what the spawn asked for, "" when it did not say
State string
SpawnedAt Ms
// WorkFrom is when its current stretch of work began (spawned or sent a message); Since is when it went idle or
// shut down, 0 while it works.
WorkFrom Ms
Since Ms
// contains filtered or unexported fields
}
Teammate is one named teammate the transcript started, as its lead last saw it. Times are epoch milliseconds.
func ParseTeammates ¶ added in v0.15.40
ParseTeammates is the teammates a whole transcript started, as it leaves them; now is epoch milliseconds.
type Timings ¶
type Timings struct {
// MinInterval: one tab reads its transcript at most this often, however fast the transcript grows.
MinInterval time.Duration
// PaneRefresh: the footer is captured when the transcript's tasks changed, after an event, else at most this often.
PaneRefresh time.Duration
// Recheck: tabs with work are read again this often although nothing was written — a shell can end, a wakeup come
// due and an output file go away without a line in the transcript.
Recheck time.Duration
// MaxReads: a restart finds every live agent at once; their cold tails are read a few at a time.
MaxReads int
}
Timings of the feed; the zero value is the production one.