Documentation
¶
Overview ¶
Package bgtask reads the background tasks (shells and sub-agents) a session launched from its transcript, and builds the Diagnostics tab's view of them.
What is read is undocumented Claude Code internals, measured over real transcripts (see the README): the launch is an assistant tool_use with run_in_background, answered by a tool result whose toolUseResult carries backgroundTaskId (a shell) or agentId with status async_launched (a sub-agent); each state change is a <task-notification> that Claude Code writes several times (a queue-operation enqueue, a dequeue, an attachment, sometimes a user entry): only the enqueue is read, so a notification is counted once.
Index ¶
Constants ¶
const ( OpLaunch = "launch" OpNotify = "notify" )
Ops of an event.
const ( ClassWaiting = "waiting" // an agent parked on its own background work ClassFinished = "finished" // done, or came to rest ClassFailed = "failed" ClassStopped = "stopped" )
Classes of a notification.
const MaxText = 120
MaxText bounds every text kept from a transcript, in runes.
Variables ¶
This section is empty.
Functions ¶
func Build ¶
func Build(in Input) *model.Background
Build is the Diagnostics tab's background-tasks view.
func Clip ¶
Clip is what is kept of a text from a transcript: passed through gitsafe's redaction so a token-shaped string never reaches the cache or the screen, the home directory written "~", white space collapsed, capped at n runes.
func DefaultRoot ¶
func DefaultRoot() string
DefaultRoot is where Claude Code keeps the task output files of the user.
Types ¶
type Dir ¶
type Dir struct {
Root string
Projects string
Home string
// contains filtered or unexported fields
}
Dir reads the output files of the tasks: Root/<project>/<session>/tasks/<id>.output (Claude Code keeps them under /private/tmp/claude-<uid>, where they are volatile). It reads the end of a file, signals no process, and refuses a name that is not a plain name and a link that does not resolve under Projects (the transcript tree: a sub-agent's output file is a link to its transcript).
type Event ¶
type Event struct {
T int64 `json:"t"` // Unix seconds
Session string `json:"s"`
Proj string `json:"p,omitempty"` // the transcript directory's name
Op string `json:"o"`
ID string `json:"i"`
Kind string `json:"k"` // bash or agent
Title string `json:"ti,omitempty"`
Waits string `json:"w,omitempty"`
Class string `json:"c,omitempty"`
Quota bool `json:"q,omitempty"` // a failure on a quota limit
Detail string `json:"d,omitempty"` // a failure's own words
}
Event is one launch or one notification, as kept on disk.
type Input ¶
type Input struct {
Now time.Time
Events []Event
// Scanned is whether a pass over the transcripts has ended; Unreadable how many
// transcripts the last pass could not open.
Scanned bool
Unreadable int
// Sessions are the sessions with a live process, from the registry; nil when the
// registry could not be read, in which case no task is judged orphaned.
Sessions map[string]Session
// Stat reads a task's output file; ok is false when there is none (or it was
// refused). nil reads none.
Stat func(proj, session, id string) (o Output, ok bool)
}
Input is what the view is built from at Now.
type Output ¶
Output is what is known of a task's output file: when it last changed and its last line (already redacted and capped).