Documentation
¶
Overview ¶
Package spec is what a scheduled task is (mistgate.tasks.v1): its schedule and when it runs next, the steps of a check task and the conditions on their results, and the limits every definition is checked against. It is plain Go with no panel dependency, shared by the TasksService (internal/panel/tasks) and the MCP task tools (internal/panel/mcp), so a plan an agent makes is checked by the same rules as a task the owner saves.
Index ¶
- Constants
- Variables
- func Jitter(id string, s Schedule) time.Duration
- func MinEvery(kind string) int
- func Name(name string) error
- func Prompt(prompt string) error
- func ValidateArgs(schemaRaw, args json.RawMessage) (json.RawMessage, error)
- type Condition
- type Definition
- type Error
- type Schedule
- type Step
- type Tools
Constants ¶
const ( OpSeverityAtLeast = "severity_at_least" OpEq = "eq" OpNe = "ne" OpIn = "in" OpNotIn = "not_in" OpGt = "gt" OpGte = "gte" OpLt = "lt" OpLte = "lte" OpNonempty = "nonempty" OpContains = "contains" )
Condition operators.
const ( KindCheck = "check" KindAssistant = "assistant" )
Kinds of task.
const ( Every = "every" Daily = "daily" Weekly = "weekly" )
Kinds of schedule.
const ( MaxTasks = 50 MaxNameRunes = 80 MaxSteps = 8 MaxConditions = 5 MaxArgsBytes = 4 << 10 MaxPromptRunes = 4000 MaxPathRunes = 200 MaxValueRunes = 200 MinCheckEvery = 5 // minutes MinAssistantEvery = 15 // minutes MaxEvery = 10080 // a week, in minutes // MaxJitter is the longest delay a task's runs start after their time. MaxJitter = 3 * time.Minute )
Limits of a definition.
Variables ¶
var Ops = []string{OpSeverityAtLeast, OpGt, OpGte, OpLt, OpLte, OpEq, OpNe, OpIn, OpNotIn, OpNonempty, OpContains}
Ops lists the operators in the order the editor offers them.
Functions ¶
func Jitter ¶
Jitter is the delay of a task's runs after their time: from its id, so it stays the same, and at most a tenth of an EVERY interval (a task every 5 minutes starts at most 30 s late).
func ValidateArgs ¶
func ValidateArgs(schemaRaw, args json.RawMessage) (json.RawMessage, error)
ValidateArgs checks a step's arguments: one JSON object, valid against the tool's schema when one is given. It returns them compacted.
Types ¶
type Condition ¶
type Condition struct {
Path string `json:"path,omitempty"`
Op string `json:"op"`
Value string `json:"value,omitempty"`
}
Condition is a test on a step's result: it holds when any value at Path matches Op and Value.
Path is dotted names into the result; "name[]" walks every element of the list name (a bare "[]" the list at hand); "**." before a name finds that name at any depth. "totals.nodes_problem_now", "nodes[].status", "**.severity". An empty path is the whole result.
type Definition ¶
type Definition struct {
Name string
Kind string // KindCheck or KindAssistant
Enabled bool
Schedule Schedule
Steps []Step // check
Prompt string // assistant
NotifyTelegram bool
}
Definition is what the owner writes for a task.
func Check ¶
func Check(d Definition, tools Tools, secret func(string) bool) (Definition, error)
Check checks a definition and returns it normalised (trimmed name and prompt, compact arguments): the name, the kind, the schedule and its minimum for the kind, a check's steps against the tools, an assistant task's prompt, and no secret in a name, an argument, a condition or a prompt (secret reports one: the MCP scrubber would change the text).
type Error ¶
Error is a refusal with a code ("schedule_too_often") and parameters, worded by the admin ("code: k=v&k=v").
type Schedule ¶
type Schedule struct {
Kind string // Every, Daily or Weekly
EveryMinutes int
MinuteOfDay int
Weekday int // 0 Sunday .. 6 Saturday
}
Schedule is when a task runs.
func ParseSchedule ¶
ParseSchedule reads "every 15m" (m, h or d), "daily 07:30" and "weekly mon 07:30" (sun..sat), ignoring case. It checks the form, not the minimum interval of a kind (Validate does).
func (Schedule) Next ¶
Next is the first time the schedule fires strictly after `after`, plus the task's jitter, in a zone of offsetMin minutes east of UTC. EVERY counts from midnight of that zone, so "every 15m" is :00, :15, :30 and :45 and "every 2h" is the even hours. A time that already passed is never returned: a task the panel missed runs once, at the next time from now.
type Step ¶
type Step struct {
Tool string `json:"tool"`
Args json.RawMessage `json:"args,omitempty"`
Conditions []Condition `json:"conditions,omitempty"`
ErrorIsProblem bool `json:"error_is_problem,omitempty"`
}
Step is one step of a check task.
func Steps ¶
func Steps(steps []Step, allowed func(string) bool, schemaOf func(string) json.RawMessage) ([]Step, error)
Steps checks the steps of a check task: allowed reports whether a tool may run in one (the operator profile's read and run tools), schemaOf gives a tool's input schema (nil: the arguments are only checked to be an object). The steps come back with their arguments normalised (an empty one is {}).