task

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	ToolNameTaskStop   = "task_stop"
	ToolNameTaskList   = "task_list"
	ToolNameTaskGet    = "task_get"
	ToolNameTaskOutput = "task_output"
	ToolNameTaskCreate = "task_create"
	ToolNameTaskUpdate = "task_update"
)

Tool name constants

View Source
const (
	SearchHintTaskStop   = "stop tracking a task or kill a background task"
	SearchHintTaskList   = "list tracked tasks or background tasks"
	SearchHintTaskGet    = "get details of a tracked task or background task by ID"
	SearchHintTaskOutput = "read output from a background task"
	SearchHintTaskCreate = "create a task in the task list"
	SearchHintTaskUpdate = "update a task in the task list"
)

Search hints

View Source
const (
	ToolDescriptionTaskStop = `` /* 552-byte string literal not displayed */

	ToolDescriptionTaskList = `` /* 546-byte string literal not displayed */

	ToolDescriptionTaskGet = `` /* 566-byte string literal not displayed */

	ToolDescriptionTaskOutput = `` /* 490-byte string literal not displayed */

	ToolDescriptionTaskCreate = `` /* 1381-byte string literal not displayed */

	ToolDescriptionTaskUpdate = `` /* 1248-byte string literal not displayed */

	// TaskStatus constants
	TaskStatusPending    = "pending"
	TaskStatusInProgress = "in_progress"
	TaskStatusCompleted  = "completed"
	TaskStatusDeleted    = "deleted"
)

Tool descriptions

Variables

This section is empty.

Functions

func FormatTaskOutput

func FormatTaskOutput(taskID, status, output string) string

formatTaskOutput formats task output for display

func InitializeGlobalTaskStore

func InitializeGlobalTaskStore(path string) error

func JoinFields

func JoinFields(fields []string) string

JoinFields joins a slice of strings with comma

func JoinLines

func JoinLines(lines []string) string

JoinLines joins lines with newlines

func ListRunningTasks

func ListRunningTasks(ctx context.Context) []map[string]any

ListRunningTasks returns all running background tasks.

func SetRuntime

func SetRuntime(runtime Runtime)

func StatusToString

func StatusToString(status bashTool.TaskStatus) string

statusToString converts TaskStatus to string

Types

type Runtime

type Runtime interface {
	GetTask(ctx context.Context, taskID string) (*RuntimeTask, error)
	ListTasks(ctx context.Context) ([]*RuntimeTask, error)
	ReadTaskOutput(ctx context.Context, taskID string) (string, error)
	WaitForTask(ctx context.Context, taskID string, timeout time.Duration) (*RuntimeTask, error)
	KillTask(ctx context.Context, taskID string) error
}

Runtime is the small contract that task-facing tools depend on. Keeping it here lets the task tools ask for task state/output without importing the full tasks manager package or its process-control details.

func RuntimeImpl

func RuntimeImpl() Runtime

type RuntimeTask

type RuntimeTask struct {
	ID          string
	Type        RuntimeTaskType
	Status      RuntimeTaskStatus
	Command     string
	Description string
	Output      string
	OutputFile  string
	ExitCode    *int
	CreatedAt   time.Time
	StartedAt   *time.Time
	CompletedAt *time.Time
}

type RuntimeTaskStatus

type RuntimeTaskStatus string
const (
	RuntimeTaskStatusPending   RuntimeTaskStatus = "pending"
	RuntimeTaskStatusRunning   RuntimeTaskStatus = "running"
	RuntimeTaskStatusCompleted RuntimeTaskStatus = "completed"
	RuntimeTaskStatusFailed    RuntimeTaskStatus = "failed"
	RuntimeTaskStatusKilled    RuntimeTaskStatus = "killed"
)

type RuntimeTaskType

type RuntimeTaskType string

type Task

type Task struct {
	ID          string         `json:"id"`
	SessionID   string         `json:"sessionId,omitempty"`
	Position    int            `json:"position,omitempty"`
	Subject     string         `json:"subject"`
	Description string         `json:"description"`
	Status      string         `json:"status"`
	ActiveForm  string         `json:"activeForm,omitempty"`
	Owner       string         `json:"owner,omitempty"`
	Blocks      []string       `json:"blocks,omitempty"`
	BlockedBy   []string       `json:"blockedBy,omitempty"`
	Metadata    map[string]any `json:"metadata,omitempty"`
	CreatedAt   time.Time      `json:"createdAt"`
	UpdatedAt   time.Time      `json:"updatedAt"`
}

Task represents a task in the task list.

type TaskCreateTool

type TaskCreateTool struct{}

TaskCreateTool implements the TaskCreate tool for creating tasks

func NewTaskCreateTool

func NewTaskCreateTool() *TaskCreateTool

NewTaskCreateTool creates a new TaskCreate tool

func (*TaskCreateTool) BackfillInput

func (t *TaskCreateTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

BackfillInput backfills input

func (*TaskCreateTool) Call

func (t *TaskCreateTool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)

Call executes the TaskCreate tool

func (*TaskCreateTool) CheckPermissions

func (t *TaskCreateTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

CheckPermissions checks permissions (always allowed)

func (*TaskCreateTool) Definition

func (t *TaskCreateTool) Definition() tool.Definition

Definition returns the tool definition

func (*TaskCreateTool) Description

func (t *TaskCreateTool) Description(ctx context.Context) (string, error)

Description returns a human-readable description

func (*TaskCreateTool) FormatResult

func (t *TaskCreateTool) FormatResult(data any) string

FormatResult formats the result

func (*TaskCreateTool) IsConcurrencySafe

func (t *TaskCreateTool) IsConcurrencySafe(input map[string]any) bool

IsConcurrencySafe returns whether the tool is concurrency safe

func (*TaskCreateTool) IsEnabled

func (t *TaskCreateTool) IsEnabled() bool

IsEnabled returns whether the tool is enabled

func (*TaskCreateTool) IsReadOnly

func (t *TaskCreateTool) IsReadOnly(input map[string]any) bool

IsReadOnly returns whether the tool is read-only

func (*TaskCreateTool) ValidateInput

func (t *TaskCreateTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInput validates the input

type TaskDetails

type TaskDetails struct {
	ID        string `json:"id"`
	Command   string `json:"command"`
	Status    string `json:"status"`
	StartTime int64  `json:"startTime"`
	EndTime   *int64 `json:"endTime,omitempty"`
	ExitCode  *int   `json:"exitCode,omitempty"`
}

TaskDetails represents detailed information about a background task.

type TaskGetTodoDetails

type TaskGetTodoDetails struct {
	ID          string   `json:"id"`
	Subject     string   `json:"subject"`
	Description string   `json:"description"`
	Status      string   `json:"status"`
	ActiveForm  string   `json:"activeForm,omitempty"`
	Owner       string   `json:"owner,omitempty"`
	Blocks      []string `json:"blocks,omitempty"`
	BlockedBy   []string `json:"blockedBy,omitempty"`
	CreatedAt   int64    `json:"createdAt"`
	UpdatedAt   int64    `json:"updatedAt"`
}

type TaskGetTool

type TaskGetTool struct{}

TaskGetTool implements the TaskGet tool for getting task details.

func NewTaskGetTool

func NewTaskGetTool() *TaskGetTool

NewTaskGetTool creates a new TaskGet tool.

func (*TaskGetTool) BackfillInput

func (t *TaskGetTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

BackfillInput backfills input.

func (*TaskGetTool) Call

func (t *TaskGetTool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)

Call executes the TaskGet tool.

func (*TaskGetTool) CheckPermissions

func (t *TaskGetTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

CheckPermissions checks permissions.

func (*TaskGetTool) Definition

func (t *TaskGetTool) Definition() tool.Definition

Definition returns the tool definition.

func (*TaskGetTool) Description

func (t *TaskGetTool) Description(ctx context.Context) (string, error)

Description returns a human-readable description.

func (*TaskGetTool) FormatResult

func (t *TaskGetTool) FormatResult(data any) string

FormatResult formats the result.

func (*TaskGetTool) IsConcurrencySafe

func (t *TaskGetTool) IsConcurrencySafe(input map[string]any) bool

IsConcurrencySafe returns whether the tool is concurrency safe.

func (*TaskGetTool) IsEnabled

func (t *TaskGetTool) IsEnabled() bool

IsEnabled returns whether the tool is enabled.

func (*TaskGetTool) IsReadOnly

func (t *TaskGetTool) IsReadOnly(input map[string]any) bool

IsReadOnly returns whether the tool is read-only.

func (*TaskGetTool) ValidateInput

func (t *TaskGetTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInput validates the input.

type TaskInfo

type TaskInfo struct {
	ID        string `json:"id"`
	Command   string `json:"command"`
	Status    string `json:"status"`
	StartTime int64  `json:"startTime"`
	EndTime   *int64 `json:"endTime,omitempty"`
	ExitCode  int    `json:"exitCode,omitempty"`
}

TaskInfo represents information about a background task

type TaskListTool

type TaskListTool struct{}

TaskListTool implements the TaskList tool for listing todo and background tasks.

func NewTaskListTool

func NewTaskListTool() *TaskListTool

NewTaskListTool creates a new TaskList tool

func (*TaskListTool) BackfillInput

func (t *TaskListTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

BackfillInput backfills input

func (*TaskListTool) Call

func (t *TaskListTool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)

Call executes the TaskList tool

func (*TaskListTool) CheckPermissions

func (t *TaskListTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

CheckPermissions checks permissions (always allowed)

func (*TaskListTool) Definition

func (t *TaskListTool) Definition() tool.Definition

Definition returns the tool definition

func (*TaskListTool) Description

func (t *TaskListTool) Description(ctx context.Context) (string, error)

Description returns a human-readable description

func (*TaskListTool) FormatResult

func (t *TaskListTool) FormatResult(data any) string

FormatResult formats the result

func (*TaskListTool) IsConcurrencySafe

func (t *TaskListTool) IsConcurrencySafe(input map[string]any) bool

IsConcurrencySafe returns whether the tool is concurrency safe

func (*TaskListTool) IsEnabled

func (t *TaskListTool) IsEnabled() bool

IsEnabled returns whether the tool is enabled

func (*TaskListTool) IsReadOnly

func (t *TaskListTool) IsReadOnly(input map[string]any) bool

IsReadOnly returns whether the tool is read-only

func (*TaskListTool) ValidateInput

func (t *TaskListTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInput validates the input

type TaskStopTodoDetails

type TaskStopTodoDetails struct {
	ID             string `json:"id"`
	Subject        string `json:"subject"`
	PreviousStatus string `json:"previousStatus,omitempty"`
}

type TaskStopTool

type TaskStopTool struct{}

TaskStopTool implements the TaskStop tool for stopping tracked tasks.

func NewTaskStopTool

func NewTaskStopTool() *TaskStopTool

func (*TaskStopTool) BackfillInput

func (t *TaskStopTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

func (*TaskStopTool) Call

func (t *TaskStopTool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)

func (*TaskStopTool) CheckPermissions

func (t *TaskStopTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

func (*TaskStopTool) Definition

func (t *TaskStopTool) Definition() tool.Definition

func (*TaskStopTool) Description

func (t *TaskStopTool) Description(ctx context.Context) (string, error)

func (*TaskStopTool) FormatResult

func (t *TaskStopTool) FormatResult(data any) string

func (*TaskStopTool) IsConcurrencySafe

func (t *TaskStopTool) IsConcurrencySafe(input map[string]any) bool

func (*TaskStopTool) IsEnabled

func (t *TaskStopTool) IsEnabled() bool

func (*TaskStopTool) IsReadOnly

func (t *TaskStopTool) IsReadOnly(input map[string]any) bool

func (*TaskStopTool) ValidateInput

func (t *TaskStopTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

type TaskStore

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

TaskStore provides task storage, using SQLite when configured and falling back to an in-memory session-scoped store otherwise.

func GlobalTaskStore

func GlobalTaskStore() *TaskStore

func NewSQLiteTaskStore

func NewSQLiteTaskStore(path string) (*TaskStore, error)

func NewTaskStore

func NewTaskStore() *TaskStore

func (*TaskStore) BlockTask

func (s *TaskStore) BlockTask(ctx context.Context, sessionID, blockerID, blockedID string) error

func (*TaskStore) ConfigureSQLite

func (s *TaskStore) ConfigureSQLite(path string) error

func (*TaskStore) CreateTask

func (s *TaskStore) CreateTask(ctx context.Context, sessionID, subject, description, activeForm string, metadata map[string]any) (*Task, error)

func (*TaskStore) DeleteTask

func (s *TaskStore) DeleteTask(ctx context.Context, sessionID, taskID string) error

func (*TaskStore) GetTask

func (s *TaskStore) GetTask(ctx context.Context, sessionID, taskID string) (*Task, error)

func (*TaskStore) ListTasks

func (s *TaskStore) ListTasks(ctx context.Context, sessionID string) ([]*Task, error)

func (*TaskStore) UpdateTask

func (s *TaskStore) UpdateTask(ctx context.Context, sessionID, taskID string, updates map[string]any) (*Task, error)

type TaskUpdateTool

type TaskUpdateTool struct{}

TaskUpdateTool implements the TaskUpdate tool for updating tasks

func NewTaskUpdateTool

func NewTaskUpdateTool() *TaskUpdateTool

NewTaskUpdateTool creates a new TaskUpdate tool

func (*TaskUpdateTool) BackfillInput

func (t *TaskUpdateTool) BackfillInput(ctx context.Context, input map[string]any) map[string]any

BackfillInput backfills input

func (*TaskUpdateTool) Call

func (t *TaskUpdateTool) Call(ctx context.Context, input tool.CallInput, permissionCheck types.CanUseToolFn) (tool.CallResult, error)

Call executes the TaskUpdate tool

func (*TaskUpdateTool) CheckPermissions

func (t *TaskUpdateTool) CheckPermissions(ctx context.Context, input map[string]any, toolCtx tool.ToolUseContext) types.PermissionResult

CheckPermissions checks permissions (always allowed)

func (*TaskUpdateTool) Definition

func (t *TaskUpdateTool) Definition() tool.Definition

Definition returns the tool definition

func (*TaskUpdateTool) Description

func (t *TaskUpdateTool) Description(ctx context.Context) (string, error)

Description returns a human-readable description

func (*TaskUpdateTool) FormatResult

func (t *TaskUpdateTool) FormatResult(data any) string

FormatResult formats the result

func (*TaskUpdateTool) IsConcurrencySafe

func (t *TaskUpdateTool) IsConcurrencySafe(input map[string]any) bool

IsConcurrencySafe returns whether the tool is concurrency safe

func (*TaskUpdateTool) IsEnabled

func (t *TaskUpdateTool) IsEnabled() bool

IsEnabled returns whether the tool is enabled

func (*TaskUpdateTool) IsReadOnly

func (t *TaskUpdateTool) IsReadOnly(input map[string]any) bool

IsReadOnly returns whether the tool is read-only

func (*TaskUpdateTool) ValidateInput

func (t *TaskUpdateTool) ValidateInput(ctx context.Context, input map[string]any) (map[string]any, error)

ValidateInput validates the input

Jump to

Keyboard shortcuts

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