workers

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 26 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, flowsDir string) (string, error)

HashDir is the hash Load gives the worker in dir: its files and, for a worker that runs a workflow (workflow: in WORKER.md), that workflow's file in flowsDir, or that it's missing. The workflow's steps add to what the job may do (flows.SchedulePermissions), so editing, adding or removing it changes the hash and an enabled job waits to be enabled again (spec_023_workers WK-05a). A worker without a workflow has the hash of its files alone.

func ParseSpec added in v0.8.4

func ParseSpec(name string, data []byte) api.WorkerSpec

ParseSpec is ReadSpec's reading of a WORKER.md's data, for the worker name: what it can of a file that isn't valid, the whole of one whose frontmatter can't be read as its prompt (the composer's drafts too).

func ReadSpec

func ReadSpec(dir, flowsDir 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 (HashDir, with flowsDir), 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 FlowFile added in v0.9.1

type FlowFile struct {
	// Path is the file's path; Data its content.
	Path string
	Data []byte
}

FlowFile is a workflow's file as read when its worker was hashed.

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(flowsDir string, dirs ...string) ([]Found, error)

Discover loads every worker under the directories given (each holding <name>/WORKER.md), invalid ones included with their errors, their workflows read from flowsDir (Load). 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, blitz
	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)
blitz:connector list    one of Blitz's own commands (glob: "connector *")

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). A run log that can't be read is logged: its latest run may be missing.

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 = jobspec.Schedule

Schedule is when a worker runs.

func ParseSchedule

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

ParseSchedule understands a schedule, as jobspec.ParseSchedule.

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) ForgetWorkspace added in v0.7.1

func (s *Store) ForgetWorkspace(dir string) error

ForgetWorkspace drops what the store knows of every worker of dir (its folder is gone): none of them is enabled any more.

func (*Store) Known added in v0.7.1

func (s *Store) Known() map[string]map[string]bool

Known is every worker the store has a record of, by workspace directory and name: whether it's enabled.

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
	// RunsOn is where it runs: jobspec.Here, or jobspec.Service (the
	// organization's service runs it; this computer doesn't, EN-40).
	RunsOn string
	// OnRequest is "refuse" or "pause" ("" for where it runs's default,
	// EN-43).
	OnRequest string
	// Merge is jobspec.MergeMain or jobspec.MergeNever: where a run on the
	// service leaves its changes.
	Merge string
	// Prompt is the workflow: WORKER.md's body.
	Prompt string
	// Flow is a workflow (spec_043_workflows WF-17) the worker runs, its
	// prompt the workflow's input.
	Flow string
	// FlowFile is Flow's file as Hash covers it, read once with it (nil
	// when the worker runs no workflow or its file is missing): a run
	// takes the workflow's steps, and the permissions they grant, from
	// these bytes, never from a later read an edit could have changed
	// (spec_023_workers WK-05b).
	FlowFile *FlowFile
}

Worker is a worker as read from its directory.

func Load

func Load(dir, flowsDir 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. flowsDir is the workspace's workflows folder: a worker that runs a workflow is hashed with that workflow's file (HashDir).

Jump to

Keyboard shortcuts

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