Documentation
¶
Overview ¶
Package tasks provides background task execution including cron scheduling.
Package tasks provides shared output-streaming infrastructure for background workers. The execution runtime has been consolidated into teams.TeammateRunner.
Index ¶
- func ReadDelta(path string, offset int64, maxBytes int64) (string, int64, error)
- type CronEntry
- type CronRunner
- type CronStore
- func (cs *CronStore) Add(schedule, prompt, agent, entryType, sessionID string) (*CronEntry, error)
- func (cs *CronStore) All() []CronEntry
- func (cs *CronStore) Due() []CronEntry
- func (cs *CronStore) FormatList() string
- func (cs *CronStore) Load() error
- func (cs *CronStore) MarkRun(id string) error
- func (cs *CronStore) Remove(id string) error
- func (cs *CronStore) Save() error
- func (cs *CronStore) UpdatePrompt(id, prompt string) error
- type TaskOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CronEntry ¶
type CronEntry struct {
ID string `json:"id"`
Schedule string `json:"schedule"` // simplified: "@every 1h", "@daily", or "HH:MM"
Prompt string `json:"prompt"` // what to execute
Agent string `json:"agent,omitempty"`
Type string `json:"type,omitempty"` // "inline" (default) or "background"
SessionID string `json:"session_id,omitempty"` // owning session for inject/store
LastRun time.Time `json:"last_run,omitempty"`
NextRun time.Time `json:"next_run"`
Enabled bool `json:"enabled"`
}
CronEntry defines a scheduled recurring task.
type CronRunner ¶
type CronRunner struct {
// DefaultModel is the model ID used when ResolveModelFn returns an empty string.
// Set this at construction time from the application's configured model.
DefaultModel string
// InjectFn is called for inline fires — injects prompt into session as user msg.
InjectFn func(sessionID, prompt string)
// StoreFn is called for background fires — stores result in session as assistant msg.
StoreFn func(sessionID, agentName, content string)
// ResolveModelFn resolves an agent name to (modelID, systemPrompt).
// For shorthands like "haiku"/"sonnet"/"opus" it returns the model ID + empty system prompt.
// For named agents it loads the agent definition and returns model + system prompt.
ResolveModelFn func(agentName string) (modelID, systemPrompt string)
// RunBackgroundFn runs a single-turn engine with the given model, system prompt, and user prompt.
// Returns the assistant response text.
RunBackgroundFn func(ctx context.Context, modelID, systemPrompt, prompt string) (string, error)
// contains filtered or unexported fields
}
CronRunner polls CronStore.Due() and fires entries in goroutines. Uses callback functions to avoid importing comandcenter/engine packages.
func NewCronRunner ¶
func NewCronRunner(store *CronStore) *CronRunner
NewCronRunner creates a runner backed by the given store.
func (*CronRunner) Start ¶
func (r *CronRunner) Start(ctx context.Context)
Start begins the poll loop. Ticks every 60s, fires due entries.
func (*CronRunner) Stop ¶
func (r *CronRunner) Stop()
Stop cancels the poll loop and waits for in-flight goroutines.
type CronStore ¶
type CronStore struct {
// contains filtered or unexported fields
}
CronStore manages persisted cron entries.
func NewCronStore ¶
NewCronStore creates a cron store at the given path.
func (*CronStore) FormatList ¶
FormatList returns a human-readable list of cron entries.
func (*CronStore) MarkRun ¶
MarkRun records that a cron entry was executed and computes its next run time.
func (*CronStore) UpdatePrompt ¶
UpdatePrompt replaces the Prompt field of a cron entry in-memory and saves.
type TaskOutput ¶
type TaskOutput struct {
// contains filtered or unexported fields
}
TaskOutput provides disk-backed output streaming for background workers.
func NewTaskOutput ¶
func NewTaskOutput(outputDir, taskID string) (*TaskOutput, error)
NewTaskOutput creates a new output file for a worker.