Documentation
¶
Overview ¶
Package task is a unified registry for background tasks. Tools (shell commands, sub-agent dispatch, etc.) register their long-running work via a shared Runtime so callers can list and cancel them through one surface.
Index ¶
Constants ¶
const CompletedTag = "background-task-completed"
CompletedTag is the XML-style wrapper tag used in the AgentMessage emitted by ToAgentMessage().
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
ID string
Type Type
Description string
Status Status
StartedAt time.Time
EndedAt time.Time
OutputFile string // path to output file on disk
Error string
ExitCode int // shell: process exit code
ToolCount int // number of tool calls executed
// Shell-specific
PID int
Command string
// SubAgent-specific
Agent string
Prompt string // original task prompt
TokensIn int
TokensOut int
// contains filtered or unexported fields
}
Entry is the unified representation of any background task. Both shell tools and sub-agent tools register entries through a shared Runtime.
type Notification ¶
type Notification struct {
TaskID string `json:"task_id"`
Type Type `json:"type"`
Status Status `json:"status"`
Description string `json:"description,omitempty"`
OutputFile string `json:"output_file,omitempty"`
Error string `json:"error,omitempty"`
ExitCode *int `json:"exit_code,omitempty"`
Command string `json:"command,omitempty"`
Agent string `json:"agent,omitempty"`
}
Notification is the JSON payload delivered to the calling agent when a background task finishes.
func NotificationFromEntry ¶
func NotificationFromEntry(e *Entry) Notification
NotificationFromEntry converts a task entry into a notification payload.
func (Notification) ToAgentMessage ¶
func (n Notification) ToAgentMessage() agentcore.AgentMessage
ToAgentMessage wraps the notification as a user-role AgentMessage that the parent agent can consume as a follow-up.
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime is a unified registry for background tasks.
func (*Runtime) NextID ¶
NextID generates a sequential task ID with the given prefix (e.g. "shell", "bg").
func (*Runtime) Register ¶
Register adds a task entry. The caller is responsible for populating all fields.
func (*Runtime) Stop ¶
Stop cancels a running task by ID. Returns true if a running task was found and its cancel function was invoked. The background goroutine is responsible for writing the terminal status and EndedAt after observing the cancellation.