task

package
v0.16.9 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxConcurrent guards provider rate limits, not local resources — the
	// runs are IO-bound model streams, so CPU count is irrelevant.
	MaxConcurrent = 16
	MaxPerSession = 50

	// MaxRunDuration bounds one background run so a hung model stream cannot
	// occupy a concurrency slot forever.
	MaxRunDuration = 30 * time.Minute
)
View Source
const KindCommand = "command"

KindCommand marks events published for backgrounded shell commands rather than subagent runs; those have no Task in the registry.

View Source
const KindSchedule = "schedule"

KindSchedule marks a scheduled task coming due. Unlike the other kinds it carries work to do rather than a finished result: Description holds the schedule expression and Result the task prompt.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Task        *Task
	ID          string
	Kind        string
	Description string
	AgentType   string
	Seq         int
	Status      Status
	Result      string
	Elapsed     time.Duration
}

Event is an immutable snapshot of one finished run, taken before the task can be resumed — delivery must never read the live task, which a relaunch may already have reset.

func (Event) Label added in v0.11.4

func (e Event) Label() string

Label names the event source for status lines and notifications.

func (Event) Notice added in v0.12.19

func (e Event) Notice() string

Notice renders the one-line user-facing announcement shown in the chat when the event is delivered.

func (Event) Notification

func (e Event) Notification() string

Notification renders the model-facing completion block delivered as hidden context by every UI surface.

func (Event) Verb

func (e Event) Verb() string

Verb describes how the run ended, for status lines: "finished", "replied" (a resumed run), "failed", or "was stopped" — and "is due" for a schedule, which announces work rather than reporting it.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry tracks the background subagents of one session. Completed tasks stay listed for task_output until the session ends; completion events are buffered so a consumer that attaches late still receives them.

func NewFileRegistry added in v0.15.8

func NewFileRegistry(path string) (*Registry, error)

NewFileRegistry restores a session registry. Runs that were active when the process stopped become failed terminal snapshots and emit one notification; they are never replayed automatically.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Adopt added in v0.12.2

func (r *Registry) Adopt(description, agentType, result string, elapsed time.Duration) *Task

Adopt registers an already-finished run (a synchronous agent call) so it can be inspected and resumed like a background task. It emits no event — the result was already delivered inline. Returns nil when the registry is closed or at capacity; the caller then skips follow-up support.

func (*Registry) AdoptAgent added in v0.15.8

func (r *Registry) AdoptAgent(agentID, description, agentType, result string, elapsed time.Duration, prepare func(*Task) error) (*Task, error)

AdoptAgent is Adopt with durable child state installed before it becomes visible to task_send or UI readers.

func (*Registry) Close

func (r *Registry) Close()

Close cancels all running tasks and stops event delivery.

func (*Registry) Counts

func (r *Registry) Counts() (running, total int)

func (*Registry) Done

func (r *Registry) Done() <-chan struct{}

Done is closed when the registry shuts down, so event consumers can exit.

func (*Registry) Events

func (r *Registry) Events() <-chan Event

Events delivers one snapshot per finished run.

func (*Registry) Get

func (r *Registry) Get(id string) *Task

func (*Registry) Launch

func (r *Registry) Launch(description, agentType string, run func(ctx context.Context, t *Task) (string, error)) (*Task, error)

Launch starts run in a goroutine detached from the launching tool call; it is canceled only by Stop or Close. The returned error reports cap or shutdown rejections, never run failures — those surface via the task. run receives the task so it can publish activity and a transcript peek.

func (*Registry) LaunchAgent added in v0.15.8

func (r *Registry) LaunchAgent(agentID, description, agentType string, prepare func(*Task) error, run func(ctx context.Context, t *Task) (string, error)) (*Task, error)

LaunchAgent is Launch with a stable child identity and a preparation step that is persisted before the goroutine can start.

func (*Registry) List

func (r *Registry) List() []*Task

func (*Registry) Publish added in v0.11.4

func (r *Registry) Publish(ev Event)

Publish delivers an external background event (e.g. an exec_command exit) through the session's notification channel alongside subagent completions.

func (*Registry) Relaunch

func (r *Registry) Relaunch(t *Task, run func(ctx context.Context, t *Task) (string, error)) error

Relaunch restarts a finished task with a new run — the task_send follow-up path. The task keeps its id and history; status, timing, and cancellation reset for the new run, and completion fires another event.

func (*Registry) Stop

func (r *Registry) Stop(id string) error

type Status

type Status string
const (
	StatusRunning Status = "running"
	StatusDone    Status = "done"
	StatusFailed  Status = "failed"
	StatusStopped Status = "stopped"
)

type Task

type Task struct {
	ID          string
	AgentID     string
	Description string
	AgentType   string
	Started     time.Time
	// contains filtered or unexported fields
}

func (*Task) Activity

func (t *Task) Activity() string

func (*Task) AppendAgentEvents added in v0.15.8

func (t *Task) AppendAgentEvents(events []agent.RuntimeEvent) error

AppendAgentEvents implements the child's live durability boundary. Events have already been assigned monotonically by that child Agent.

func (*Task) DurableAgent added in v0.15.8

func (t *Task) DurableAgent() (string, agent.State, json.RawMessage)

func (*Task) Elapsed

func (t *Task) Elapsed() time.Duration

func (*Task) PeekMessages

func (t *Task) PeekMessages() []agent.Message

func (*Task) Result

func (t *Task) Result() string

Result returns the agent's final report; empty while the task is running.

func (*Task) Resume

func (t *Task) Resume(prompt string) error

func (*Task) ResumeContext added in v0.15.8

func (t *Task) ResumeContext(ctx context.Context, prompt string) error

func (*Task) Seq

func (t *Task) Seq() int

Seq counts the task's runs: 1 for the initial launch, +1 per resume. It distinguishes the completion notifications of successive runs.

func (*Task) SetActivity

func (t *Task) SetActivity(text string)

SetActivity records what the agent is currently doing (e.g. its running tool call) for live status displays.

func (*Task) SetAgentState added in v0.15.8

func (t *Task) SetAgentState(state agent.State) error

func (*Task) SetDurableAgent added in v0.15.8

func (t *Task) SetDurableAgent(agentID string, state agent.State, resumeData json.RawMessage) error

SetDurableAgent binds the stable child identity, its current event ledger, and opaque resume specification. The subagent package owns the spec format; Registry only guarantees atomic persistence.

func (*Task) SetPeek

func (t *Task) SetPeek(fn func() []agent.Message)

SetPeek installs a snapshot function for the agent's transcript so UIs can watch a running task and re-read a finished one.

func (*Task) SetResume

func (t *Task) SetResume(fn func(prompt string) error)

SetResume installs the follow-up hook used by task_send: it restarts the finished agent with a new prompt and its full prior context.

func (*Task) SetResumeContext added in v0.15.8

func (t *Task) SetResumeContext(fn func(context.Context, string) error)

func (*Task) Status

func (t *Task) Status() Status

func (*Task) SupportsResume added in v0.15.8

func (t *Task) SupportsResume() bool

Jump to

Keyboard shortcuts

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