schedule

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package schedule defines the calendar-scheduling capability: a durable set of cron jobs that schedule/cron fires and a tool can edit. Splitting it this way is what lets the agent schedule its own follow-up work without knowing who runs it.

Index

Constants

View Source
const (
	SessionModeStateless = "stateless"
	SessionModeReuse     = "reuse"
	SessionModeFresh     = "fresh" // alias of stateless
	SessionModeFixed     = "fixed"
)
View Source
const (
	SourceConfig = "config"
	SourceAgent  = "agent"
)

Job sources. Config jobs are owned by the preset and re-synced on every start; agent jobs are created at runtime and survive restarts untouched.

View Source
const (
	KindCron  = "cron"
	KindDelay = "delay"
	KindAt    = "at"
)

Job kinds distinguish repeating cron jobs from one-shot jobs.

View Source
const InFlightTimeout = 30 * time.Minute

InFlightTimeout is how long a one-shot job may stay claimed before Due reclaims it.

Variables

View Source
var ErrJobNotFound = errors.New("schedule: job not found")

ErrJobNotFound is returned when a registry operation targets a missing job id.

Functions

func FireMeta added in v0.1.10

func FireMeta(metadata map[string]any) (map[string]any, bool)

FireMeta returns schedule fire metadata when present on an inbound event.

func InFlightExpired added in v0.1.10

func InFlightExpired(job Job, now time.Time) bool

InFlightExpired reports whether a claimed one-shot should be reclaimed.

func IsFireStateless added in v0.1.10

func IsFireStateless(metadata map[string]any) bool

IsFireStateless reports whether a schedule-fired inbound event should run in a fresh side session without parent history.

func IsFireTurn added in v0.1.10

func IsFireTurn(metadata map[string]any) bool

IsFireTurn reports whether metadata marks a schedule-fired inbound turn.

func IsOneShot added in v0.1.10

func IsOneShot(job Job) bool

IsOneShot reports whether a job fires once at an absolute time.

func IsStatelessSessionMode added in v0.1.10

func IsStatelessSessionMode(mode string) bool

IsStatelessSessionMode reports whether a schedule turn should avoid inheriting the delivery conversation's active session history.

func JobKind added in v0.1.10

func JobKind(job Job) string

JobKind returns the normalized job kind.

func NextFire

func NextFire(job Job, after time.Time) (time.Time, bool)

NextFire reports when a job should next run, given its anchor. It is shared by registries and by anything that wants to show "next run" without firing.

func SessionModeFromMeta added in v0.1.10

func SessionModeFromMeta(meta map[string]any) string

SessionModeFromMeta reads sessionMode from schedule fire metadata.

Types

type Job

type Job struct {
	ID     string    `json:"id"`
	Kind   string    `json:"kind,omitempty"`
	Cron   string    `json:"cron,omitempty"`
	In     string    `json:"in,omitempty"`
	FireAt time.Time `json:"fireAt,omitzero"`
	Prompt string    `json:"prompt,omitempty"`
	// Script is a workspace-relative bash script. When set, the job runs the
	// script directly instead of starting an agent turn.
	Script string `json:"script,omitempty"`
	Source string `json:"source"`
	// Disabled jobs stay in the registry but never fire.
	Disabled  bool      `json:"disabled,omitempty"`
	CreatedAt time.Time `json:"createdAt,omitzero"`
	// LastRun anchors the schedule. A new job is stamped at creation time so its
	// first fire is the next real boundary rather than immediately.
	LastRun time.Time `json:"lastRun,omitzero"`
	Fired   bool      `json:"fired,omitempty"`
	FiredAt time.Time `json:"firedAt,omitzero"`
	// InFlight marks a one-shot job claimed by Due but not yet MarkFired.
	InFlight   bool      `json:"inFlight,omitempty"`
	InFlightAt time.Time `json:"inFlightAt,omitzero"`
	LastError  string    `json:"lastError,omitempty"`
	// Note is free-form context the agent can leave for its future self.
	Note string `json:"note,omitempty"`
	// DeliverySessionID is the platform inbox to route outbound messages (e.g. send)
	// when the job fires. Captured automatically when tool/schedule creates the job.
	DeliverySessionID string `json:"deliverySessionId,omitempty"`
	PlatformID        string `json:"platformId,omitempty"`
	UserID            string `json:"userId,omitempty"`
	AgentID           string `json:"agentId,omitempty"`
	ChannelKey        string `json:"channelKey,omitempty"`
}

Job is one scheduled task.

type Registry

type Registry interface {
	List(ctx context.Context) ([]Job, error)
	// Add stores a job, assigning an ID when the given one is empty. It returns
	// the stored job.
	Add(ctx context.Context, job Job) (Job, error)
	// Remove deletes a job by ID, reporting whether it existed.
	Remove(ctx context.Context, id string) (bool, error)
	// SyncSource replaces every job with the given source, leaving other sources
	// alone. Used to reconcile config-declared jobs on startup.
	SyncSource(ctx context.Context, source string, jobs []Job) error
	// Due returns the enabled jobs whose next fire time has arrived, and stamps
	// them as run at now. Missed boundaries are skipped rather than backfilled.
	Due(ctx context.Context, now time.Time) ([]Job, error)
	// MarkFired records that a one-shot job has been handled while retaining it
	// for audit/listing.
	MarkFired(ctx context.Context, id string, firedAt time.Time, fireErr error) error
}

Registry is the durable job set. Implementations must be safe for concurrent use: the firing runtime and the agent's tool touch it from different goroutines.

type Runtime added in v0.1.3

type Runtime interface {
	Start(context.Context, SubmitFunc) error
	Stop(context.Context) error
}

Runtime watches a Registry and submits due jobs as inbound turns. It is started by runner after build; it must not depend on runner in the plugin graph.

type Schedule

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

Schedule is a parsed cron expression. Times are interpreted in the location of whatever time.Time it is asked about, so a schedule built from local time behaves like an OS crontab entry.

func ParseCron

func ParseCron(expr string) (Schedule, error)

ParseCron parses a 5-field cron expression: minute hour day-of-month month day-of-week. Each field accepts `*`, a number, `a-b`, comma-separated lists, and `*/n` or `a-b/n` steps. The @hourly/@daily/@weekly/@monthly/@yearly shorthands are also accepted.

func (Schedule) Matches

func (s Schedule) Matches(t time.Time) bool

Matches reports whether t (to the minute) satisfies the schedule.

func (Schedule) Next

func (s Schedule) Next(t time.Time) (time.Time, bool)

Next returns the first matching minute strictly after t. The second result is false when nothing matches within the search horizon, which only happens for impossible dates such as "0 0 30 2 *".

func (Schedule) String

func (s Schedule) String() string

type SubmitFunc added in v0.1.3

type SubmitFunc func(ctx context.Context, event agentkit.MessageEvent) error

SubmitFunc delivers one inbound turn. Runner provides this when starting a Runtime so due jobs enter the same path as platform messages.

Jump to

Keyboard shortcuts

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