cron

package
v1.1.62 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package cron implements scheduled task management for vibecoding. Cron jobs are persisted in sessions.db and executed by spawning agents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseSchedule

func ParseSchedule(schedule string, from time.Time) (next time.Time, isOneShot bool, err error)

ParseSchedule parses a human-readable schedule string into a next-run time. Supported formats:

""           → one-shot (no next run)
"@once"      → one-shot (same as empty)
"@every 30m" → every 30 minutes
"@every 2h"  → every 2 hours
"@every 1d"  → every 1 day
"@hourly"    → every 1 hour
"@daily"     → every 24 hours (midnight)
"@weekly"    → every 7 days
"@monthly"   → 1st of next month

Types

type CronJob

type CronJob struct {
	ID         string    `json:"id"`
	SessionID  string    `json:"session_id,omitempty"`
	Name       string    `json:"name"`              // Short description
	Prompt     string    `json:"prompt"`            // Task prompt for sub-agent
	Schedule   string    `json:"schedule"`          // Schedule: @daily, @every 30m, 5-field cron, or empty for one-shot
	OneShot    bool      `json:"oneshot,omitempty"` // If true, auto-disable after first run
	Mode       string    `json:"mode"`              // "agent" or "yolo"
	WorkDir    string    `json:"work_dir,omitempty"`
	A2ATarget  string    `json:"a2a_target,omitempty"` // A2A server URL (if set, send task via A2A protocol)
	A2AToken   string    `json:"a2a_token,omitempty"`  // Bearer token for A2A server
	Enabled    bool      `json:"enabled"`
	CreatedAt  time.Time `json:"created_at"`
	LastRun    time.Time `json:"last_run,omitempty"`
	NextRun    time.Time `json:"next_run,omitempty"`
	RunCount   int       `json:"run_count"`
	LastStatus string    `json:"last_status,omitempty"` // "success", "failed", "running"
	LastError  string    `json:"last_error,omitempty"`
}

CronJob represents a scheduled task.

type CronStore

type CronStore interface {
	List() ([]CronJob, error)
	Get(id string) (*CronJob, error)
	Create(job CronJob) (*CronJob, error)
	Update(job CronJob) error
	Delete(id string) error
}

CronStore is the interface for cron job persistence.

type CronTool

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

CronTool provides cron job management for the agent.

func NewCronTool

func NewCronTool(store CronStore, scheduler *Scheduler) *CronTool

NewCronTool creates a new cron management tool.

func (*CronTool) Description

func (t *CronTool) Description() string

func (*CronTool) Execute

func (t *CronTool) Execute(ctx context.Context, params map[string]any) (tools.ToolResult, error)

func (*CronTool) Name

func (t *CronTool) Name() string

func (*CronTool) Parameters

func (t *CronTool) Parameters() json.RawMessage

func (*CronTool) PromptGuidelines

func (t *CronTool) PromptGuidelines() []string

func (*CronTool) PromptSnippet

func (t *CronTool) PromptSnippet() string

type SQLiteCronStore added in v1.1.61

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

SQLiteCronStore persists cron jobs in the shared sessions.db database.

func NewSQLiteCronStore added in v1.1.61

func NewSQLiteCronStore(sessionDir string) *SQLiteCronStore

NewSQLiteCronStore creates a SQLite-backed cron store rooted at sessionDir.

func (*SQLiteCronStore) ClaimDue added in v1.1.62

func (s *SQLiteCronStore) ClaimDue(id string, now time.Time) (bool, error)

ClaimDue atomically marks a due job as running. Only the caller that updates a row may execute it, preventing duplicate runs across scheduler instances.

func (*SQLiteCronStore) Create added in v1.1.61

func (s *SQLiteCronStore) Create(job CronJob) (*CronJob, error)

Create adds a new cron job.

func (*SQLiteCronStore) Delete added in v1.1.61

func (s *SQLiteCronStore) Delete(id string) error

Delete removes a cron job.

func (*SQLiteCronStore) Get added in v1.1.61

func (s *SQLiteCronStore) Get(id string) (*CronJob, error)

Get returns a cron job by ID.

func (*SQLiteCronStore) List added in v1.1.61

func (s *SQLiteCronStore) List() ([]CronJob, error)

List returns all cron jobs.

func (*SQLiteCronStore) Update added in v1.1.61

func (s *SQLiteCronStore) Update(job CronJob) error

Update updates an existing cron job.

type Scheduler

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

Scheduler checks for due cron jobs and executes them via sub-agents.

func NewScheduler

func NewScheduler(store CronStore, manager *agent.AgentManager, interval time.Duration) *Scheduler

NewScheduler creates a new cron scheduler.

func NewSchedulerWithSessionDir added in v1.1.61

func NewSchedulerWithSessionDir(store CronStore, manager *agent.AgentManager, interval time.Duration, sessionDir string) *Scheduler

NewSchedulerWithSessionDir creates a scheduler that can attach scheduled local runs to existing sessions by session ID.

func (*Scheduler) IsRunning

func (s *Scheduler) IsRunning() bool

IsRunning returns whether the scheduler is running.

func (*Scheduler) Start

func (s *Scheduler) Start()

Start begins the scheduler loop.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops the scheduler.

type SessionScopedStore added in v1.1.61

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

SessionScopedStore limits a CronStore to one session.

func NewSessionScopedStore added in v1.1.61

func NewSessionScopedStore(base CronStore, sessionID string) *SessionScopedStore

NewSessionScopedStore returns a cron store view bound to sessionID.

func NewSessionScopedStoreWithWorkDir added in v1.1.61

func NewSessionScopedStoreWithWorkDir(base CronStore, sessionID, workDir string) *SessionScopedStore

NewSessionScopedStoreWithWorkDir returns a cron store view bound to sessionID. Jobs created through the scoped view inherit workDir when they do not specify one explicitly.

func (*SessionScopedStore) Create added in v1.1.61

func (s *SessionScopedStore) Create(job CronJob) (*CronJob, error)

func (*SessionScopedStore) Delete added in v1.1.61

func (s *SessionScopedStore) Delete(id string) error

func (*SessionScopedStore) Get added in v1.1.61

func (s *SessionScopedStore) Get(id string) (*CronJob, error)

func (*SessionScopedStore) List added in v1.1.61

func (s *SessionScopedStore) List() ([]CronJob, error)

func (*SessionScopedStore) Update added in v1.1.61

func (s *SessionScopedStore) Update(job CronJob) error

Jump to

Keyboard shortcuts

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