tasks

package
v0.0.0-...-e74ad27 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadDelta

func ReadDelta(path string, offset int64, maxBytes int64) (string, int64, error)

ReadDelta reads output from a file starting at offset. Returns the content string, the new offset, and any error. If maxBytes <= 0, defaults to 32KB.

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

func NewCronStore(path string) *CronStore

NewCronStore creates a cron store at the given path.

func (*CronStore) Add

func (cs *CronStore) Add(schedule, prompt, agent, entryType, sessionID string) (*CronEntry, error)

Add creates a new cron entry with the given schedule and prompt.

func (*CronStore) All

func (cs *CronStore) All() []CronEntry

All returns all cron entries.

func (*CronStore) Due

func (cs *CronStore) Due() []CronEntry

Due returns all enabled entries whose NextRun has passed.

func (*CronStore) FormatList

func (cs *CronStore) FormatList() string

FormatList returns a human-readable list of cron entries.

func (*CronStore) Load

func (cs *CronStore) Load() error

Load reads cron entries from disk.

func (*CronStore) MarkRun

func (cs *CronStore) MarkRun(id string) error

MarkRun records that a cron entry was executed and computes its next run time.

func (*CronStore) Remove

func (cs *CronStore) Remove(id string) error

Remove deletes a cron entry by ID.

func (*CronStore) Save

func (cs *CronStore) Save() error

Save writes cron entries to disk.

func (*CronStore) UpdatePrompt

func (cs *CronStore) UpdatePrompt(id, prompt string) error

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.

func (*TaskOutput) Close

func (o *TaskOutput) Close() error

Close closes the output file.

func (*TaskOutput) Path

func (o *TaskOutput) Path() string

Path returns the output file path.

func (*TaskOutput) Size

func (o *TaskOutput) Size() int64

Size returns bytes written so far.

func (*TaskOutput) Write

func (o *TaskOutput) Write(p []byte) (int, error)

Write appends data to the output file.

Jump to

Keyboard shortcuts

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