Documentation
¶
Index ¶
- Variables
- func GenerateID() string
- type AgentTask
- func (t *AgentTask) AppendOutput(data []byte)
- func (t *AgentTask) AppendProgress(msg string)
- func (t *AgentTask) Complete(err error)
- func (t *AgentTask) GetCancel() context.CancelFunc
- func (t *AgentTask) GetContext() context.Context
- func (t *AgentTask) GetDescription() string
- func (t *AgentTask) GetID() string
- func (t *AgentTask) GetOutput() string
- func (t *AgentTask) GetStatus() TaskInfo
- func (t *AgentTask) GetType() TaskType
- func (t *AgentTask) IsRunning() bool
- func (t *AgentTask) Kill() error
- func (t *AgentTask) MarkKilled()
- func (t *AgentTask) Stop() error
- func (t *AgentTask) Subscribe() <-chan ProgressUpdate
- func (t *AgentTask) UpdateProgress(turnCount, tokenUsage int)
- func (t *AgentTask) WaitForCompletion(timeout time.Duration) bool
- type BackgroundTask
- type BashTask
- func (t *BashTask) AppendOutput(data []byte)
- func (t *BashTask) Complete(exitCode int, err error)
- func (t *BashTask) GetDescription() string
- func (t *BashTask) GetID() string
- func (t *BashTask) GetOutput() string
- func (t *BashTask) GetStatus() TaskInfo
- func (t *BashTask) GetType() TaskType
- func (t *BashTask) IsRunning() bool
- func (t *BashTask) Kill() error
- func (t *BashTask) MarkKilled()
- func (t *BashTask) Stop() error
- func (t *BashTask) WaitForCompletion(timeout time.Duration) bool
- type Manager
- func (m *Manager) Cleanup(maxAge time.Duration)
- func (m *Manager) Create(cmd *exec.Cmd, command, description string, ctx context.Context, ...) *BashTask
- func (m *Manager) CreateBashTask(cmd *exec.Cmd, command, description string, ctx context.Context, ...) *BashTask
- func (m *Manager) Get(id string) (BackgroundTask, bool)
- func (m *Manager) GetBashTask(id string) (*BashTask, bool)
- func (m *Manager) Kill(id string) error
- func (m *Manager) List() []BackgroundTask
- func (m *Manager) ListRunning() []BackgroundTask
- func (m *Manager) RegisterTask(task BackgroundTask)
- func (m *Manager) Remove(id string)
- type ProgressUpdate
- type TaskInfo
- type TaskStatus
- type TaskType
Constants ¶
This section is empty.
Variables ¶
var DefaultManager = NewManager()
DefaultManager is the global default task manager
Functions ¶
func GenerateID ¶ added in v1.2.0
func GenerateID() string
GenerateID creates a short random ID (exported for agent tasks)
Types ¶
type AgentTask ¶ added in v1.2.0
type AgentTask struct {
ID string // Unique task ID
AgentName string // Name of the agent type (Explore, Plan, etc.)
Description string // Brief description of the task
Status TaskStatus // Current status
StartTime time.Time // When the task started
EndTime time.Time // When the task ended (if completed)
TurnCount int // Number of conversation turns
TokenUsage int // Total tokens consumed
Error string // Error message (if failed)
// contains filtered or unexported fields
}
AgentTask represents a background agent task It implements the BackgroundTask interface
func NewAgentTask ¶ added in v1.2.0
func NewAgentTask(id, agentName, description string, ctx context.Context, cancel context.CancelFunc) *AgentTask
NewAgentTask creates a new agent task
func (*AgentTask) AppendOutput ¶ added in v1.2.0
AppendOutput appends data to the output buffer and notifies subscribers
func (*AgentTask) AppendProgress ¶ added in v1.2.0
AppendProgress appends a progress message and notifies subscribers
func (*AgentTask) Complete ¶ added in v1.2.0
Complete marks the task as completed and notifies subscribers
func (*AgentTask) GetCancel ¶ added in v1.2.0
func (t *AgentTask) GetCancel() context.CancelFunc
GetCancel returns the task's cancel function
func (*AgentTask) GetContext ¶ added in v1.2.0
GetContext returns the task's context
func (*AgentTask) GetDescription ¶ added in v1.2.0
GetDescription returns the task description
func (*AgentTask) MarkKilled ¶ added in v1.2.0
func (t *AgentTask) MarkKilled()
MarkKilled marks the task as killed (internal use)
func (*AgentTask) Subscribe ¶ added in v1.2.0
func (t *AgentTask) Subscribe() <-chan ProgressUpdate
Subscribe returns a channel that receives progress updates The channel is closed when the task completes
func (*AgentTask) UpdateProgress ¶ added in v1.2.0
UpdateProgress updates the turn count and token usage
type BackgroundTask ¶ added in v1.2.0
type BackgroundTask interface {
// GetID returns the unique task identifier
GetID() string
// GetType returns the task type (bash or agent)
GetType() TaskType
// GetDescription returns a brief description of the task
GetDescription() string
// GetStatus returns the current task status info
GetStatus() TaskInfo
// IsRunning returns true if the task is still running
IsRunning() bool
// WaitForCompletion waits until the task completes or timeout
// Returns true if completed, false if timeout
WaitForCompletion(timeout time.Duration) bool
// Stop gracefully stops the task (SIGTERM for bash, context cancel for agent)
Stop() error
// Kill forcefully terminates the task (SIGKILL for bash)
Kill() error
// AppendOutput appends data to the output buffer
AppendOutput(data []byte)
// GetOutput returns the current output
GetOutput() string
}
BackgroundTask is the common interface for all background task types Both BashTask and AgentTask implement this interface
type BashTask ¶ added in v1.2.0
type BashTask struct {
ID string // Unique task ID
Command string // The command being executed
Description string // Brief description
Status TaskStatus // Current status
PID int // Process ID
StartTime time.Time // When the task started
EndTime time.Time // When the task ended (if completed)
ExitCode int // Exit code (if completed)
Error string // Error message (if failed)
Cmd *exec.Cmd // The running command
Ctx context.Context // Task context
Cancel context.CancelFunc // Cancel function
// contains filtered or unexported fields
}
BashTask represents a background bash command task It implements the BackgroundTask interface
func NewBashTask ¶ added in v1.2.0
func NewBashTask(id, command, description string, cmd *exec.Cmd, ctx context.Context, cancel context.CancelFunc) *BashTask
NewBashTask creates a new bash task
func (*BashTask) AppendOutput ¶ added in v1.2.0
AppendOutput appends data to the output buffer
func (*BashTask) GetDescription ¶ added in v1.2.0
GetDescription returns the task description
func (*BashTask) MarkKilled ¶ added in v1.2.0
func (t *BashTask) MarkKilled()
MarkKilled marks the task as killed (internal use)
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages background tasks
func (*Manager) Create ¶
func (m *Manager) Create(cmd *exec.Cmd, command, description string, ctx context.Context, cancel context.CancelFunc) *BashTask
Create is an alias for CreateBashTask for backward compatibility Deprecated: Use CreateBashTask instead
func (*Manager) CreateBashTask ¶ added in v1.2.0
func (m *Manager) CreateBashTask(cmd *exec.Cmd, command, description string, ctx context.Context, cancel context.CancelFunc) *BashTask
CreateBashTask creates and registers a new bash task
func (*Manager) Get ¶
func (m *Manager) Get(id string) (BackgroundTask, bool)
Get retrieves a task by ID
func (*Manager) GetBashTask ¶ added in v1.2.0
GetBashTask retrieves a bash task by ID (for backward compatibility)
func (*Manager) ListRunning ¶
func (m *Manager) ListRunning() []BackgroundTask
ListRunning returns all running tasks
func (*Manager) RegisterTask ¶ added in v1.2.0
func (m *Manager) RegisterTask(task BackgroundTask)
RegisterTask registers an existing task (used for agent tasks)
type ProgressUpdate ¶ added in v1.2.0
type ProgressUpdate struct {
Message string // Progress message (e.g., "Reading: file.go")
Done bool // True if task is complete
}
ProgressUpdate represents a progress update from the agent
type TaskInfo ¶
type TaskInfo struct {
// Common fields
ID string
Type TaskType
Description string
Status TaskStatus
StartTime time.Time
EndTime time.Time
Output string
Error string
// Bash-specific fields
Command string
PID int
ExitCode int
// Agent-specific fields
AgentName string
TurnCount int
TokenUsage int
}
TaskInfo is a snapshot of task information It contains both common fields and type-specific fields
type TaskStatus ¶
type TaskStatus string
TaskStatus represents the status of a background task
const ( StatusRunning TaskStatus = "running" StatusCompleted TaskStatus = "completed" StatusFailed TaskStatus = "failed" StatusKilled TaskStatus = "killed" )