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
- func Allows(perms []Permission, req api.ApprovalRequest) bool
- func HashDir(dir string) (string, error)
- func ReadSpec(dir string) (api.WorkerSpec, string, error)
- func Render(s api.WorkerSpec) []byte
- func ValidName(name string) bool
- type Effective
- type Found
- type InvalidError
- type Permission
- type RunLog
- type Schedule
- type Store
- func (s *Store) Disable(dir, name string) error
- func (s *Store) Enable(dir string, w *Worker, hash string) error
- func (s *Store) Forget(dir, name string) error
- func (s *Store) ForgetWorkspace(dir string) error
- func (s *Store) Known() map[string]map[string]bool
- func (s *Store) State(dir string, w *Worker, loadErr error) api.State
- func (s *Store) Workspaces() []string
- type Worker
Constants ¶
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 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.
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.
type InvalidError ¶
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 ¶
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.
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 ¶
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.
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 (*Store) ForgetWorkspace ¶ added in v0.7.1
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
Known is every worker the store has a record of, by workspace directory and name: whether it's enabled.
func (*Store) State ¶
State says whether the worker w, found in the workspace dir, may run. A worker Load reported invalid is StateInvalid.
func (*Store) Workspaces ¶
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
// Flow is a workflow (spec_workflows_043 WF-17) the worker runs, its
// prompt the workflow's input.
Flow string
}
Worker is a worker as read from its directory.