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, flowsDir string) (string, error)
- func ParseSpec(name string, data []byte) api.WorkerSpec
- func ReadSpec(dir, flowsDir string) (api.WorkerSpec, string, error)
- func Render(s api.WorkerSpec) []byte
- func ValidName(name string) bool
- type Effective
- type FlowFile
- 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 HashDir ¶
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.
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 Found ¶
Found is a worker found by Discover, with why it can't be used if it can't.
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 ¶
Schedule is when a worker runs.
func ParseSchedule ¶
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 (*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
// 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.