tasks

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetGlobalManager

func SetGlobalManager(manager *Manager)

SetGlobalManager sets the global task manager used by task tools.

Types

type Manager

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

Manager manages background task execution.

func GlobalManager

func GlobalManager() *Manager

GlobalManager returns the global task manager used by task tools.

func NewDefaultManager

func NewDefaultManager(client *engine.Engine, config *ManagerConfig) *Manager

NewDefaultManager creates and installs a global manager.

func NewManager

func NewManager(client *engine.Engine, config *ManagerConfig) *Manager

func (*Manager) CleanupTasks

func (m *Manager) CleanupTasks(maxAge time.Duration) int

CleanupTasks removes terminal tasks older than maxAge.

func (*Manager) CreateAgentTask

func (m *Manager) CreateAgentTask(ctx context.Context, prompt string, tools []tool.Tool, permissionMode types.PermissionMode, systemPrompt string, toolPatterns []string) (*Task, error)

CreateAgentTask creates a new agent task.

permissionMode, when non-empty, is applied to the new session before it ever runs - a background task has no interactive prompt to show, and without this it silently inherited whatever permission mode m.client defaults new sessions to (typically onRequest), which routes any "ask" through the same engine-wide prompt function the foreground session uses. Callers should resolve this the same way every other sub-agent spawn path does (see agents.subAgentPermissionMode): bypass by default, or never when the spawning session is itself in never mode.

systemPrompt, when non-empty, becomes the session's system prompt template - the caller's resolved agentDef.GetSystemPrompt(), so a background run actually gets the requested agent type's identity and instructions instead of silently running under the engine's default one (the type the model asked for was otherwise only used for display, never to pick a prompt). The session also gets the same "subagent" tool surface profile every other sub-agent spawn path uses (coreagent.RunAgent), instead of the top-level default a plain NewSession would give it.

toolPatterns, when non-empty and not a bare "*", prunes the session down to tools matching one of them (see coreagent.RestrictSessionTools) - the caller's combined agentType-pattern/allowedTools list, mirroring what every synchronous sub-agent spawn path already applies via RunAgent.

func (*Manager) CreateBashTask

func (m *Manager) CreateBashTask(ctx context.Context, command string) (*Task, error)

CreateBashTask creates a new bash task.

func (*Manager) GetTask

func (m *Manager) GetTask(taskID TaskID) (*Task, error)

GetTask retrieves a task by ID.

func (*Manager) GetTaskStats

func (m *Manager) GetTaskStats() *TaskStats

GetTaskStats returns statistics about tasks.

func (*Manager) KillTask

func (m *Manager) KillTask(taskID TaskID) error

KillTask kills a running task.

func (*Manager) ListTasks

func (m *Manager) ListTasks() []*Task

ListTasks lists all tasks in stable order.

func (*Manager) ReadTaskOutput

func (m *Manager) ReadTaskOutput(taskID TaskID) (string, error)

ReadTaskOutput reads the output file for a task.

func (*Manager) ReadTaskOutputTail

func (m *Manager) ReadTaskOutputTail(taskID TaskID, maxLines int) (string, error)

ReadTaskOutputTail reads the tail of a task output file.

func (*Manager) SetCompletionCallback

func (m *Manager) SetCompletionCallback(cb TaskCompletionCallback)

SetCompletionCallback sets a callback that is called when any task completes

func (*Manager) WaitForTask

func (m *Manager) WaitForTask(ctx context.Context, taskID TaskID, timeout time.Duration) (*Task, error)

WaitForTask waits for a task to reach a terminal status.

func (*Manager) WatchTask

func (m *Manager) WatchTask(ctx context.Context, taskID TaskID) <-chan *Task

WatchTask watches a task for completion.

type ManagerConfig

type ManagerConfig struct {
	MaxConcurrentTasks int           `json:"max_concurrent_tasks"`
	TaskTimeout        time.Duration `json:"task_timeout"`
	OutputDir          string        `json:"output_dir"`
}

ManagerConfig represents the manager configuration.

func DefaultManagerConfig

func DefaultManagerConfig() *ManagerConfig

DefaultManagerConfig returns default manager configuration.

type Task

type Task struct {
	ID           TaskID          `json:"id"`
	Type         TaskType        `json:"type"`
	Status       TaskStatus      `json:"status"`
	Command      string          `json:"command,omitempty"`
	Prompt       string          `json:"prompt,omitempty"`
	SessionID    types.SessionID `json:"session_id,omitempty"`
	CreatedAt    time.Time       `json:"created_at"`
	StartedAt    *time.Time      `json:"started_at,omitempty"`
	CompletedAt  *time.Time      `json:"completed_at,omitempty"`
	Output       string          `json:"output,omitempty"`
	OutputFile   string          `json:"output_file,omitempty"`
	ExitCodeFile string          `json:"exit_code_file,omitempty"`
	Error        string          `json:"error,omitempty"`
	Progress     int             `json:"progress"`
	Description  string          `json:"description,omitempty"`
	ExitCode     *int            `json:"exit_code,omitempty"`
	PID          int             `json:"pid,omitempty"`
	// contains filtered or unexported fields
}

Task represents a background task.

type TaskCompletionCallback

type TaskCompletionCallback func(task *Task)

TaskCompletionCallback is called when a task completes.

type TaskID

type TaskID string

TaskID uniquely identifies a task.

type TaskStats

type TaskStats struct {
	Total     int `json:"total"`
	Pending   int `json:"pending"`
	Running   int `json:"running"`
	Completed int `json:"completed"`
	Failed    int `json:"failed"`
	Killed    int `json:"killed"`
}

TaskStats represents task statistics.

type TaskStatus

type TaskStatus string

TaskStatus represents the status of a task.

const (
	TaskStatusPending   TaskStatus = "pending"
	TaskStatusRunning   TaskStatus = "running"
	TaskStatusCompleted TaskStatus = "completed"
	TaskStatusFailed    TaskStatus = "failed"
	TaskStatusKilled    TaskStatus = "killed"
)

type TaskType

type TaskType string

TaskType represents the type of task.

const (
	TaskTypeBash  TaskType = "bash"
	TaskTypeAgent TaskType = "agent"
)

Jump to

Keyboard shortcuts

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