background

package
v0.16.5 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: Apache-2.0 Imports: 14 Imported by: 0 modules, 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 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

View Source
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.

View Source
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

func ParseFooter(pane string) *Counts

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

type Ended struct {
	Task
	Status  string
	EndedAt Ms
}

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 NewFeed

func NewFeed(deps Deps, timing Timings, now func() time.Time) *Feed

NewFeed makes a feed; now is the clock (nil for the real one).

func (*Feed) Remove

func (f *Feed) Remove(tabID string)

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

func (f *Feed) Snapshot() map[string][]Task

Snapshot is every tab with background work, for a client that just connected.

func (*Feed) SourceOf

func (f *Feed) SourceOf(tabID string) (Source, bool)

SourceOf is where a followed tab is read from.

func (*Feed) Stop

func (f *Feed) Stop()

Stop forgets every tab.

func (*Feed) TabIDs

func (f *Feed) TabIDs() []string

TabIDs are the tabs the feed follows.

func (*Feed) Touch

func (f *Feed) Touch(tabID string, source Source, event bool)

Touch says something happened to the tab. A transcript write alone captures the footer only when the transcript's tasks changed; any other event (hook, state change, new tab) captures it too.

type Ms

type Ms float64

Ms is a time in epoch milliseconds; an unparsable time is NaN and written as null.

func (Ms) MarshalJSON

func (m Ms) MarshalJSON() ([]byte, error)

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) Forget

func (r *Reader) Forget(path string)

Forget drops the cursor of a transcript no tab shows any more.

func (*Reader) OutputFile added in v0.15.40

func (r *Reader) OutputFile(transcript string, t Task) string

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

func (r *Reader) Read(path string) []Task

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.

func (*Reader) ReadAll added in v0.15.40

func (r *Reader) ReadAll(path string) ([]Task, []Ended)

ReadAll is Read and the agents that ended, the latest first: a person who comes back to a chat sees what its subagents did, not only the ones still running.

func (*Reader) Teammates added in v0.15.40

func (r *Reader) Teammates(path string) []Teammate

Teammates are the named teammates the transcript started, the latest first, in the state its lead last saw them.

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

func ParseTasks(lines []string, now float64) []Task

ParseTasks is the background work a whole transcript leaves running; now is epoch milliseconds.

func Reconcile

func Reconcile(tasks []Task, counts *Counts) []Task

Reconcile keeps the newest transcript tasks of each kind, as many as the footer says run, and pads with unnamed ones up to its counts. Without a footer the transcript list stands.

func ReconcileWithFooter

func ReconcileWithFooter(tasks []Task, pane string, ok bool) []Task

ReconcileWithFooter is the production Reconcile: the transcript list trimmed and padded by the footer.

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

func ParseTeammates(lines []string, now float64) []Teammate

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.

Jump to

Keyboard shortcuts

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