background

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 13 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 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"
)

Kinds of background work.

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

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
}

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