Documentation
¶
Index ¶
- func SetGlobalManager(manager *Manager)
- type Manager
- func (m *Manager) CleanupTasks(maxAge time.Duration) int
- func (m *Manager) CreateAgentTask(ctx context.Context, prompt string, tools []tool.Tool, ...) (*Task, error)
- func (m *Manager) CreateBashTask(ctx context.Context, command string) (*Task, error)
- func (m *Manager) GetTask(taskID TaskID) (*Task, error)
- func (m *Manager) GetTaskStats() *TaskStats
- func (m *Manager) KillTask(taskID TaskID) error
- func (m *Manager) ListTasks() []*Task
- func (m *Manager) ReadTaskOutput(taskID TaskID) (string, error)
- func (m *Manager) ReadTaskOutputTail(taskID TaskID, maxLines int) (string, error)
- func (m *Manager) SetCompletionCallback(cb TaskCompletionCallback)
- func (m *Manager) WaitForTask(ctx context.Context, taskID TaskID, timeout time.Duration) (*Task, error)
- func (m *Manager) WatchTask(ctx context.Context, taskID TaskID) <-chan *Task
- type ManagerConfig
- type Task
- type TaskCompletionCallback
- type TaskID
- type TaskStats
- type TaskStatus
- type TaskType
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 ¶
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 ¶
CreateBashTask creates a new bash task.
func (*Manager) GetTaskStats ¶
GetTaskStats returns statistics about tasks.
func (*Manager) ReadTaskOutput ¶
ReadTaskOutput reads the output file for a task.
func (*Manager) ReadTaskOutputTail ¶
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
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 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" )