spec

package
v0.2.0-dev.9 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const (
	KindCheck     = "check"
	KindAssistant = "assistant"
)

Kinds of task.

View Source
const (
	Every  = "every"
	Daily  = "daily"
	Weekly = "weekly"
)

Kinds of schedule.

View Source
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

Ops lists the operators in the order the editor offers them.

Functions

func Jitter

func Jitter(id string, s Schedule) time.Duration

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 MinEvery

func MinEvery(kind string) int

MinEvery is the shortest interval a task of this kind may run at.

func Name

func Name(name string) error

Name checks a task's name.

func Prompt

func Prompt(prompt string) error

Prompt checks an assistant task's prompt.

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.

func (Condition) Match

func (c Condition) Match(result []byte, limit int) ([]string, error)

Match evaluates the condition on a tool's result (JSON) and returns what matched, as "<path> = <value>" lines (at most limit). Invalid JSON is an error so a caller cannot mistake a failed tool result for a passing check.

func (Condition) Validate

func (c Condition) Validate() error

Validate checks the condition's form.

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

type Error struct {
	Code   string
	Params [][2]string
}

Error is a refusal with a code ("schedule_too_often") and parameters, worded by the admin ("code: k=v&k=v").

func (*Error) Error

func (e *Error) Error() string

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

func ParseSchedule(text string) (Schedule, error)

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

func (s Schedule) Next(after time.Time, offsetMin int, jitter time.Duration) time.Time

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.

func (Schedule) String

func (s Schedule) String() string

String is the schedule in the words ParseSchedule reads: "every 15m", "every 2h", "daily 07:30", "weekly mon 07:30".

func (Schedule) Validate

func (s Schedule) Validate(kind string) error

Validate checks the schedule for a task of the kind.

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 {}).

type Tools

type Tools struct {
	Allowed  func(string) bool
	SchemaOf func(string) json.RawMessage
}

Tools is what a check's steps are checked against: whether a tool may be a step, and its input schema. A nil Allowed means the list could not be read (tools_unavailable).

Jump to

Keyboard shortcuts

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