bgtask

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: BSD-3-Clause Imports: 13 Imported by: ? 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 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

View Source
const (
	OpLaunch = "launch"
	OpNotify = "notify"
)

Ops of an event.

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

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

func Clip(s, home string, n int) string

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.

func WaitsOn

func WaitsOn(cmd string) string

WaitsOn says what a waiting verb of the fleet in a command waits for: "PR o/r#n" for prwait, "REST budget >= N" for ratewait, "lease o/r" for agentsync claim --wait. "" when the command waits on none of them.

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

func (*Dir) Refused

func (d *Dir) Refused() int

Refused is how many output files were refused (a bad name, a link out of the transcript tree, not a regular file) since the Dir was made.

func (*Dir) Stat

func (d *Dir) Stat(proj, session, id string) (Output, bool)

Stat reads one task's output file: ok is false when there is none or it was refused.

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.

func Parse

func Parse(line []byte, session, proj, home string, pend *[]Pending) []Event

Parse reads one transcript line of session (in the transcript directory proj) and returns the events it holds, if any. pend is the transcript's launches waiting for their result (at most maxRing, oldest dropped). home is written "~".

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

type Output struct {
	MTime int64
	Last  string
}

Output is what is known of a task's output file: when it last changed and its last line (already redacted and capped).

type Pending

type Pending struct {
	ToolUse string `json:"u"`
	Title   string `json:"t,omitempty"`
	Waits   string `json:"w,omitempty"`
	Agent   bool   `json:"a,omitempty"`
}

Pending is a background launch whose result has not been read yet: the description and what it waits on, both already redacted.

type Session

type Session struct{ Idle bool }

Session is what the session registry says of a session with a live process.

Jump to

Keyboard shortcuts

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