Documentation
¶
Index ¶
- Constants
- Variables
- func AddSessionTask(task *CronTask) error
- func BuildLoopSkillPrompt() string
- func CleanupExpiredTasks(dir string) error
- func ClearSessionTasks()
- func ComputeNextCronRun(fields *CronFields, from time.Time) *time.Time
- func CreateLoopTools(projectDir string) []interface{ ... }
- func CronToHuman(cron string) string
- func GenerateTaskID() (string, error)
- func GetCronFilePath(dir string) string
- func HasTasks(dir string) bool
- func IntervalToCron(interval string) string
- func MarkTasksFired(ids []string, firedAt int64, dir string) error
- func NextCronRunMs(cron string, fromMs int64) (int64, error)
- func RemoveSessionTasks(ids []string) int
- func RemoveTasks(ids []string, dir string) error
- func WriteCronTasks(tasks []*CronTask, dir string) error
- type CronCreateInput
- type CronCreateOutput
- type CronCreateTool
- type CronDeleteInput
- type CronDeleteOutput
- type CronDeleteTool
- type CronFields
- type CronFile
- type CronListOutput
- type CronListTool
- type CronTask
- type CronTaskInfo
- type FieldRange
- type JitterConfig
- type Scheduler
- type TaskFiredFunc
- type TaskHandler
- type ValidationResult
Constants ¶
const ( CronCreateToolName = "cron_create" CronDeleteToolName = "cron_delete" CronListToolName = "cron_list" )
const ( MaxJobs = 50 // 最大任务数限制 DefaultMaxAgeDays = 7 // 循环任务 7 天后自动过期 DefaultMaxAgeMs = 7 * 24 * 60 * 60 * 1000 // 7 days in ms )
Variables ¶
var DefaultJitterConfig = JitterConfig{
RecurringFrac: 0.1,
RecurringCapMs: 15 * 60 * 1000,
OneShotMaxMs: 90 * 1000,
OneShotFloorMs: 0,
OneShotMinuteMod: 30,
}
Functions ¶
func AddSessionTask ¶
AddSessionTask adds a task to the session store
func BuildLoopSkillPrompt ¶
func BuildLoopSkillPrompt() string
BuildLoopSkillPrompt returns the prompt for the loop skill
func CleanupExpiredTasks ¶
CleanupExpiredTasks removes expired tasks
func ComputeNextCronRun ¶
func ComputeNextCronRun(fields *CronFields, from time.Time) *time.Time
ComputeNextCronRun computes the next Date strictly after `from` that matches the cron fields. Returns nil if no match within 366 days.
func CreateLoopTools ¶
func CreateLoopTools(projectDir string) []interface { Info(ctx context.Context) (*schema.ToolInfo, error) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error) }
CreateLoopTools creates all loop/cron tools
func CronToHuman ¶
CronToHuman converts a cron expression to a human-readable string
func GenerateTaskID ¶
GenerateTaskID generates a short task ID (8 hex chars)
func GetCronFilePath ¶
GetCronFilePath returns the path to the cron tasks file
func IntervalToCron ¶
IntervalToCron converts interval notation to cron expression Nm (N ≤ 59) → */N * * * * Nm (N ≥ 60) → 0 */H * * * (转为小时) Nh (N ≤ 23) → 0 */N * * * Nd → 0 0 */N * *
func MarkTasksFired ¶
MarkTasksFired updates the LastFiredAt timestamp for tasks
func NextCronRunMs ¶
NextCronRunMs computes the next fire time in epoch ms
func RemoveSessionTasks ¶
RemoveSessionTasks removes tasks by IDs from the session store
func RemoveTasks ¶
RemoveTasks removes tasks by IDs
func WriteCronTasks ¶
WriteCronTasks writes tasks to the persistent file
Types ¶
type CronCreateInput ¶
type CronCreateInput struct {
Cron string `json:"cron"`
Prompt string `json:"prompt"`
Recurring *bool `json:"recurring"`
Durable *bool `json:"durable"`
}
CronCreateInput for cron_create tool
type CronCreateOutput ¶
type CronCreateOutput struct {
ID string `json:"id"`
HumanSchedule string `json:"human_schedule"`
Recurring bool `json:"recurring"`
Durable bool `json:"durable,omitempty"`
}
CronCreateOutput for cron_create tool
type CronCreateTool ¶
type CronCreateTool struct {
// contains filtered or unexported fields
}
CronCreateTool is the tool for creating scheduled tasks
func NewCronCreateTool ¶
func NewCronCreateTool(projectDir string) *CronCreateTool
NewCronCreateTool creates a new CronCreateTool
func (*CronCreateTool) InvokableRun ¶
func (t *CronCreateTool) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error)
InvokableRun executes the tool
func (*CronCreateTool) ValidateInput ¶
func (t *CronCreateTool) ValidateInput(ctx context.Context, argumentsInJSON string) *ValidationResult
ValidateInput validates the input before execution
type CronDeleteInput ¶
type CronDeleteInput struct {
ID string `json:"id"`
}
CronDeleteInput for cron_delete tool
type CronDeleteOutput ¶
CronDeleteOutput for cron_delete tool
type CronDeleteTool ¶
type CronDeleteTool struct {
// contains filtered or unexported fields
}
CronDeleteTool is the tool for deleting scheduled tasks
func NewCronDeleteTool ¶
func NewCronDeleteTool(projectDir string) *CronDeleteTool
NewCronDeleteTool creates a new CronDeleteTool
func (*CronDeleteTool) InvokableRun ¶
func (t *CronDeleteTool) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error)
InvokableRun executes the tool
type CronFields ¶
CronFields represents expanded cron expression fields
func ParseCronExpression ¶
func ParseCronExpression(expr string) *CronFields
ParseCronExpression parses a 5-field cron expression into expanded number arrays. Returns nil if invalid or unsupported syntax. Format: "M H DoM Mon DoW" (minute hour day-of-month month day-of-week)
type CronFile ¶
type CronFile struct {
Tasks []CronTask `json:"tasks"`
}
CronFile represents the on-disk format for persistent tasks
type CronListOutput ¶
type CronListOutput struct {
Tasks []CronTaskInfo `json:"tasks"`
}
CronListOutput for cron_list tool
type CronListTool ¶
type CronListTool struct {
// contains filtered or unexported fields
}
CronListTool is the tool for listing scheduled tasks
func NewCronListTool ¶
func NewCronListTool(projectDir string) *CronListTool
NewCronListTool creates a new CronListTool
func (*CronListTool) InvokableRun ¶
func (t *CronListTool) InvokableRun(ctx context.Context, argumentsInJSON string, opts ...tool.Option) (string, error)
InvokableRun executes the tool
type CronTask ¶
type CronTask struct {
ID string `json:"id"`
Cron string `json:"cron"` // 5-field cron expression
Prompt string `json:"prompt"` // Prompt to execute when task fires
CreatedAt int64 `json:"created_at"` // Epoch ms when created
LastFiredAt *int64 `json:"last_fired_at,omitempty"` // Epoch ms of most recent fire
Recurring bool `json:"recurring"` // Whether task reschedules after firing
Permanent bool `json:"permanent,omitempty"` // Exempt from auto-expiry (system use)
Durable bool `json:"-"` // Runtime-only: false = session-scoped
AgentID string `json:"agent_id,omitempty"` // Teammate agent ID (runtime-only)
}
CronTask represents a scheduled cron task
func FindExpiredTasks ¶
FindExpiredTasks finds tasks that have exceeded max age
func ListAllTasks ¶
ListAllTasks returns all tasks (both file-based and session)
func ReadCronTasks ¶
ReadCronTasks reads tasks from the persistent file
type CronTaskInfo ¶
type CronTaskInfo struct {
ID string `json:"id"`
Cron string `json:"cron"`
HumanSchedule string `json:"human_schedule"`
Prompt string `json:"prompt"`
Recurring bool `json:"recurring"`
Durable bool `json:"durable"`
CreatedAt int64 `json:"created_at"`
NextFireAt *int64 `json:"next_fire_at,omitempty"`
LastFiredAt *int64 `json:"last_fired_at,omitempty"`
}
CronTaskInfo represents a task in list output
type FieldRange ¶
FieldRange represents min/max values for a cron field
type JitterConfig ¶
type JitterConfig struct {
RecurringFrac float64 // Fraction of interval for recurring task delay
RecurringCapMs int64 // Max delay for recurring tasks
OneShotMaxMs int64 // Max early fire for one-shot tasks
OneShotFloorMs int64 // Min early fire for one-shot tasks
OneShotMinuteMod int // Minute mod gate for one-shot jitter
}
JitterConfig holds jitter configuration for task firing
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler manages cron task execution
func GetScheduler ¶
func GetScheduler() *Scheduler
GetScheduler returns the default scheduler instance
func NewScheduler ¶
NewScheduler creates a new scheduler
func (*Scheduler) SetHandler ¶
func (s *Scheduler) SetHandler(handler TaskHandler)
SetHandler sets the task handler for when tasks fire
type TaskFiredFunc ¶
TaskFiredFunc is a function adapter for TaskHandler
func (TaskFiredFunc) OnTaskError ¶
func (f TaskFiredFunc) OnTaskError(taskID string, err error)
OnTaskError implements TaskHandler
func (TaskFiredFunc) OnTaskFired ¶
func (f TaskFiredFunc) OnTaskFired(taskID string, prompt string)
OnTaskFired implements TaskHandler
type TaskHandler ¶
type TaskHandler interface {
// OnTaskFired is called when a task fires
OnTaskFired(taskID string, prompt string)
// OnTaskError is called when a task execution fails
OnTaskError(taskID string, err error)
}
TaskHandler handles task firing events
type ValidationResult ¶
ValidationResult represents input validation result