task

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxConcurrent = 4
	MaxPerSession = 50

	// MaxRunDuration bounds one background run so a hung model stream cannot
	// occupy a concurrency slot forever.
	MaxRunDuration = 30 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Task        *Task
	ID          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) 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".

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 NewRegistry

func NewRegistry() *Registry

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

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

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
	Description string
	AgentType   string
	Started     time.Time
	// contains filtered or unexported fields
}

func (*Task) Activity

func (t *Task) Activity() string

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

func (t *Task) Status() Status

Jump to

Keyboard shortcuts

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