workers

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 23 Imported by: 1 module, 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 workers reads workers: scheduled workflows a workspace defines in workers/<name>/WORKER.md (ROADMAP item 24). The frontmatter says when the worker runs and what it may do unattended; the body is the workflow the agent is given.

Index

Constants

View Source
const FileName = "WORKER.md"

FileName is the file that defines a worker, in its own directory.

Variables

This section is empty.

Functions

func Allows

func Allows(perms []Permission, req api.ApprovalRequest) bool

Allows reports whether the permissions cover the request: its kind has a permission matching every one of its targets. A request without targets is never covered.

func HashDir

func HashDir(dir string) (string, error)

HashDir is the hash Load gives the worker in dir.

func ReadSpec

func ReadSpec(dir string) (api.WorkerSpec, string, error)

ReadSpec reads the worker in dir as written, for editing: its frontmatter as given (not as the policy caps it), and the hash of its files, which an edit must still match. It reads what it can of a file that isn't valid: unknown keys are ignored, and a file whose frontmatter can't be read at all comes back whole as the workflow.

func Render

func Render(s api.WorkerSpec) []byte

Render writes a worker's WORKER.md: its frontmatter (the fields set) and its workflow.

func ValidName

func ValidName(name string) bool

ValidName reports whether name can be a worker's: lowercase letters, digits, - and _. Names become file names, so nothing else is looked up.

Types

type Effective

type Effective struct {
	Permissions []Permission
	Limits      api.Limits
	Notes       []string
}

Effective is what a worker may actually do and spend: its permissions without those the host policy doesn't allow, and its limits with the policy's defaults filled in and its maximums applied. Notes say what the policy changed.

func Apply

func Apply(w *Worker, p config.WorkerPolicy) Effective

Apply applies the host policy p to w.

type Found

type Found struct {
	Worker *Worker
	Err    error
}

Found is a worker found by Discover, with why it can't be used if it can't.

func Discover

func Discover(dirs ...string) ([]Found, error)

Discover loads every worker under the directories given (each holding <name>/WORKER.md), invalid ones included with their errors. Directories without a WORKER.md are ignored; a root that can't be read is an error.

type InvalidError

type InvalidError struct {
	Path     string
	Problems []string
}

InvalidError lists what makes a WORKER.md unusable. Load still returns what it could read, so a listing can show the worker and why.

func (*InvalidError) Error

func (e *InvalidError) Error() string

Error names the WORKER.md and its problems.

func (*InvalidError) Is

func (e *InvalidError) Is(target error) bool

Is makes errors.Is(err, api.ErrWorkerInvalid) true, as it is for the error a client gets back from the service.

type Permission

type Permission struct {
	Kind    string // shell, write, delete, web, mcp
	Pattern string
}

Permission is something a worker may do without approval, as written in its frontmatter: "<kind>:<pattern>".

shell:go test ./...     a command, exactly, or a glob ("go list *")
write:reports/*.md      creating or editing workspace files (glob)
delete:tmp/*            deleting workspace files (glob)
web:proxy.golang.org    fetching from a host, or searching with a provider
mcp:github:create_issue an MCP tool, as server:tool (glob)

Globs use path.Match, where * doesn't cross "/"; a pattern ending in "/" covers everything under that directory. A shell glob never covers a command that chains, pipes, redirects or substitutes (see shellMeta): "go list *" must not cover "go list x; rm -rf ~". Such a command is covered only by a permission that is exactly it. Reading never needs permission. Anything a worker isn't permitted is refused and recorded.

func ParsePermission

func ParsePermission(s string) (Permission, error)

ParsePermission reads "<kind>:<pattern>".

func (Permission) String

func (p Permission) String() string

String is the permission as written: kind:pattern.

type RunLog

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

RunLog keeps finished runs, one JSON line each, in a file per worker.

func OpenRunLog

func OpenRunLog(dir string) *RunLog

OpenRunLog keeps runs under dir.

func (*RunLog) Append

func (l *RunLog) Append(r api.Run) error

Append records a finished run.

func (*RunLog) Get

func (l *RunLog) Get(id string) (api.Run, bool, error)

Get finds a run by ID.

func (*RunLog) Last

func (l *RunLog) Last(workspace, worker string) time.Time

Last is the start of a worker's latest run (zero if none).

func (*RunLog) List

func (l *RunLog) List(workspace, worker string, limit int) ([]api.Run, error)

List returns a worker's runs, newest first, at most limit (0: all).

type Schedule

type Schedule struct {
	// Text is the schedule as written.
	Text string
	// Cron is how it was understood: a five-field cron expression, or a
	// descriptor ("@hourly", "@every 90m").
	Cron     string
	Location *time.Location
	// contains filtered or unexported fields
}

Schedule is when a worker runs.

func ParseSchedule

func ParseSchedule(text, tz string) (Schedule, error)

ParseSchedule understands a cron expression, a descriptor, or plain text ("Every two hours", "Daily at 6 AM", "Weekdays at 9:30", "Every Monday at 8 PM") in the time zone named tz ("" for the machine's). Plain text is translated by fixed rules, never guessed: anything else is an error.

func (Schedule) Next

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

Next is the first run after t.

type Store

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

Store keeps which workers are enabled, at which hash, in one file for the user (~/.blitz/workers.json). The service is its only writer.

func OpenStore

func OpenStore(path string) (*Store, error)

OpenStore reads the store at path; a missing file is an empty store.

func (*Store) Disable

func (s *Store) Disable(dir, name string) error

Disable turns the named worker off.

func (*Store) Enable

func (s *Store) Enable(dir string, w *Worker, hash string) error

Enable enables w at hash, which must be its current hash.

func (*Store) Forget

func (s *Store) Forget(dir, name string) error

Forget drops what the store knows of the named worker (it was deleted).

func (*Store) State

func (s *Store) State(dir string, w *Worker, loadErr error) api.State

State says whether the worker w, found in the workspace dir, may run. A worker Load reported invalid is StateInvalid.

func (*Store) Workspaces

func (s *Store) Workspaces() []string

Workspaces are the directories with at least one enabled worker, which the service watches even when no client has them open.

type Worker

type Worker struct {
	Name        string
	Description string
	// Dir is the worker's directory; Path its WORKER.md.
	Dir, Path string
	// Hash identifies the worker's files: enabling pins it, so any change
	// needs re-enabling. Format "sha256:<hex>", as for skills.
	Hash     string
	Schedule Schedule
	Agent    string
	Model    string
	// Permissions are what the worker asks to do without approval.
	Permissions []Permission
	Limits      api.Limits
	// Overlap is "skip" (a run still going when the next is due skips it).
	Overlap string
	// CatchUp is "none" or "once" (run once for runs missed while the
	// service wasn't running).
	CatchUp string
	// Prompt is the workflow: WORKER.md's body.
	Prompt string
}

Worker is a worker as read from its directory.

func Load

func Load(dir string) (*Worker, error)

Load reads the worker in dir (a directory holding WORKER.md). The directory's name is the worker's name; a name in the frontmatter must match it.

Jump to

Keyboard shortcuts

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