Documentation
¶
Overview ¶
Package tasks is the owner's scheduled tasks (mistgate.tasks.v1, design/adr/0017-agent-operable-fleet.md section 5): the TasksService, the scheduler that runs the tasks, and the two runners.
- A check task runs its steps, MCP tools of the operator profile, in process through the same MCP server as an outside agent (scrubbed results, the panel's rate limits, the audit), with the hidden identity of the owner's scheduled tasks (store.ScheduledTokenID). No model is involved: each step's conditions are tested on the tool's JSON result.
- An assistant task gives its prompt to the assistant (assistant.Service.RunScheduled), same identity and profile.
The same scheduler runs the assistant's follow-ups (follow_up.go): one-time continuations of a conversation, held under a lease of their own so each runs once.
The scheduler wakes every 20 seconds (and at once after a change), takes the due tasks, and starts a run of each that no run holds: a lease in the task's row means one run of a task at a time, and the run row is written with it. Runs are bounded (a check run 5 minutes, an assistant run assistant.ScheduledRunLimit) and at most two check runs and one assistant run go at a time. A run that ends gives the lease back with the next time from now, so a task the panel missed while it was down runs once on start, not once per missed time. A run a stopped panel left behind reads as interrupted when it starts again.
A run that found a problem, and a task that failed three runs in a row, are alert conditions the health evaluator reads (Conditions): SCHEDULED_CHECK and SCHEDULED_TASK_FAILING, which close themselves with a clean run.
The Cloudflare edition has none of it: the package is not linked into its Workers, and the app mounts a stub that answers UNIMPLEMENTED (internal/panel/app/tasks_wiring_js.go).
Index ¶
- Constants
- func CheckToolName(name string) bool
- func DefinitionOf(in *tasksv1.TaskInput) spec.Definition
- func InputOf(d spec.Definition) *tasksv1.TaskInput
- func LooksSecret(text string) bool
- func PromptAAD(id string) string
- func RunProto(r store.ScheduledTaskRun) *tasksv1.TaskRun
- func ScheduleProto(sc spec.Schedule) *tasksv1.Schedule
- type Assistant
- type Config
- type Service
Constants ¶
const ( AlertProblem = "scheduled_check" AlertFailing = "scheduled_task_failing" )
Alert kinds the tasks raise through the health evaluator (health.AddConditionSource).
Variables ¶
This section is empty.
Functions ¶
func CheckToolName ¶
CheckToolName reports whether a tool of the operator profile may be a step of a check: not a plan, not an apply, not a task tool.
func DefinitionOf ¶
func DefinitionOf(in *tasksv1.TaskInput) spec.Definition
DefinitionOf is a TaskInput as the spec package checks it.
func InputOf ¶
func InputOf(d spec.Definition) *tasksv1.TaskInput
InputOf is a definition as the API carries it.
func LooksSecret ¶
LooksSecret rejects task text the scrubber would change or that carries a credential label.
Types ¶
type Assistant ¶
type Assistant interface {
RunScheduled(context.Context, assistant.ScheduledRun) assistant.ScheduledOutcome
RunFollowUp(context.Context, store.AssistantFollowUp) assistant.FollowUpOutcome
}
Assistant runs a scheduled assistant task (assistant.Service.RunScheduled) and a follow-up the assistant set in a conversation (RunFollowUp).
type Config ¶
type Config struct {
Store *store.Store
Vault *vault.Vault
// Assistant runs the assistant tasks and the follow-ups; nil: the tasks are skipped (assistant_off), no follow-up runs.
Assistant Assistant
Now func() time.Time
Log *slog.Logger
// Tick is how often the scheduler looks for due tasks (20 s).
Tick time.Duration
}
Config configures Service.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the TasksService and the scheduler.
func (*Service) Conditions ¶
Conditions is the health condition source (health.Service.AddConditionSource): SCHEDULED_CHECK for an enabled task whose last finished run found a problem, SCHEDULED_TASK_FAILING for one that failed three runs in a row. Both close when the condition goes: a clean run, the task disabled or deleted.
func (*Service) Handler ¶
Handler is the Connect handler, mounted at /api/mistgate.tasks.v1.TasksService/ behind the session middleware.
func (*Service) Run ¶
Run is the scheduler: it ends the runs a stopped panel left, then starts the due tasks every tick until ctx ends, and waits for the runs in progress (they end as interrupted).
func (*Service) SetToolRuntime ¶
func (s *Service) SetToolRuntime(r mcp.AssistantRuntime)
SetToolRuntime installs the in-process MCP server once the admin API is assembled (the assistant's, internal/panel/app).
Directories
¶
| Path | Synopsis |
|---|---|
|
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.
|
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. |