Skip to content
Source on GitHub (opens in a new tab)
import "github.com/barevoidco/zelk/core/preset"

Package preset defines host defaults for the two common ways of running zelk: an interactive terminal (CLI) and an unattended server (Server). Constructors seal a validated preset; Settings returns an isolated snapshot. zelk.WithPreset applies it, and zelk.New fails when later options contradict what a preset guarantees. Presets never depend on the model.

var ErrInvalid = defaults.ErrInvalid

ErrInvalid reports a preset whose guarantees cannot be met.

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

Preset is a validated set of host defaults. Construct one with CLI or Server. Its zero value is invalid. Settings returns a snapshot, not a mutable preset.

func CLI() Preset

CLI returns interactive defaults with callback input and all terminal modes.

func Server(opts ServerOptions) (Preset, error)

Server returns bounded unattended defaults with suspended input and no shell.

Example

p, err := preset.Server(preset.ServerOptions{Budget: event.Budget{Total: event.Limit{Max: 500000}}})
if err != nil {
panic(err)
}
settings := p.Settings()
fmt.Println(settings.Mode, settings.Input, settings.NoShell)
// Output: auto suspend true

Output:

auto suspend true
func (p Preset) Settings() Settings

Settings returns a snapshot that shares no mutable configuration with p.

type ServerOptions struct {
// Mode is auto or plan; auto is the default.
Mode permission.Mode
// Budget is the hard token budget of each run. Required: an
// unattended server never runs without one. Every limit must be hard.
Budget event.Budget
// ApprovalTimeout expires an approval or question no one answered,
// which then means deny. The default is one hour.
ApprovalTimeout time.Duration
// MaxTurns and MaxTime bound each run; the defaults are 100 turns
// and an hour.
MaxTurns int
MaxTime time.Duration
}

ServerOptions configure the server preset.

type Settings struct {
// Name names the preset in errors.
Name string
// Mode is the starting mode; Modes the modes switches may select.
Mode permission.Mode
Modes []permission.Mode
// Input is how approvals and questions are answered; InputTimeout
// expires an unanswered one, which then fails closed: a denial.
Input event.InputPolicy
InputTimeout time.Duration
// NoShell guarantees sessions can't reach a shell: no Bash or process
// tools, and zelk.New fails if the host configures one.
NoShell bool
// Budget is a hard token budget for each run; nil sets none.
Budget *event.Budget
// MaxTurns and MaxTime bound each run; zero sets no bound.
MaxTurns int
MaxTime time.Duration
}

Settings is a read-only snapshot of a preset’s host defaults.