config

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 20 Imported by: 0 modules, 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 config loads and validates ~/.config/smif/config.toml (RFC 7.6).

Decoding is strict: unknown keys are rejected. Validation enforces every rule the daemon relies on for safety (R-ISO-3), including the catch-all rule at the end of each agent's rule list.

Index

Constants

View Source
const (
	Human = "human"
)

Reserved principals that are not agents.

Variables

View Source
var (
	Kinds           = []string{"tell", "ask", "event", "reply"}
	Priorities      = []string{"low", "normal", "high", "urgent"}
	Handlers        = []string{"command", "worker", "escalate", "digest", "drop"}
	PermissionModes = []string{"default", "acceptEdits", "plan", "bypassPermissions"}
	WriteScopes     = []string{"none", "worktree", "direct"}
	Efforts         = []string{"low", "medium", "high", "xhigh", "max"}
)

Kinds, priorities, handlers and modes accepted by the schema.

Functions

func AddRemote added in v0.2.0

func AddRemote(file, host string) (bool, error)

AddRemote puts host in daemon.remotes in the config file and keeps the rest of the file as it is, comments included. It reports false when the host is already there. The edit must parse back to the expected list, or the file stays untouched.

func BuiltinProfiles

func BuiltinProfiles() map[string]Profile

BuiltinProfiles returns triage, fix, answer and release (RFC 6.2).

func ContextWarnTokens added in v0.2.0

func ContextWarnTokens(v string) (int64, error)

ContextWarnTokens reads daemon.context_warn: a positive token count with an optional k or m, or "off" (0).

func IntentMatches

func IntentMatches(glob, intent string) bool

IntentMatches reports whether a dotted intent matches a glob.

func PriorityLevel

func PriorityLevel(p string) int

PriorityLevel converts a priority name to 0..3 (-1 if unknown).

func RemoveRemote added in v0.3.0

func RemoveRemote(file, host string) (bool, error)

RemoveRemote takes host out of daemon.remotes. It reports false when the host was not there.

func SetRemoteName added in v0.3.1

func SetRemoteName(file, host, name string) error

SetRemoteName names a machine, and an empty name takes the name away. The rest of the file stays as it is.

func SetRemoteWrite added in v0.3.2

func SetRemoteWrite(file, host string, on bool) error

SetRemoteWrite says whether you can type into that machine's sessions.

func ValidHarnessName added in v0.2.0

func ValidHarnessName(s string) bool

ValidHarnessName reports whether s can name a harness.

func ValidIntent

func ValidIntent(s string) bool

ValidIntent checks an intent label.

func ValidRemote added in v0.2.0

func ValidRemote(host string) bool

ValidRemote says whether host can go in daemon.remotes.

func ValidRemoteName added in v0.3.1

func ValidRemoteName(name string) bool

ValidRemoteName says whether a name can stand for a machine.

func WatchdogEvery

func WatchdogEvery(v string) (time.Duration, error)

WatchdogEvery reads a watchdog setting: a duration of a second or more, or "off" (0).

Types

type Agent

type Agent struct {
	Repo           string   `toml:"repo"`
	BaseRef        string   `toml:"base_ref"`
	AcceptFrom     []string `toml:"accept_from"`
	BudgetUSD      float64  `toml:"budget_usd"`
	BudgetTokens   int64    `toml:"budget_tokens"`
	OnBudget       string   `toml:"on_budget"`       // hold | escalate
	DirectConflict string   `toml:"direct_conflict"` // hold | worktree
	AllowBypass    bool     `toml:"allow_bypass"`
	PR             bool     `toml:"pr"`
	MaxHops        int      `toml:"max_hops"`
	MaxAttempts    int      `toml:"max_attempts"`
	Rules          []*Rule  `toml:"rules"`
	// ProfileOverrides lets an agent change fields of a named profile.
	ProfileOverrides map[string]map[string]any `toml:"profile_overrides"`

	ID string `toml:"-"`
}

Agent is one project role.

func (*Agent) Intents

func (a *Agent) Intents() []string

Intents lists the intent globs an agent handles (its capabilities, 7.1).

func (*Agent) RepoPath

func (a *Agent) RepoPath() string

RepoPath returns the agent's expanded repository path.

type Config

type Config struct {
	Daemon   Daemon             `toml:"daemon"`
	Defaults Defaults           `toml:"defaults"`
	Profiles map[string]Profile `toml:"profiles"`
	Agents   map[string]*Agent  `toml:"agents"`
	// Prompts are the human's saved prompts (ADR-0015): name → one line of
	// text, sent to a session with `p` in the UI or as @name.
	Prompts map[string]string `toml:"prompts"`
	// Harnesses adds coding agents with no code (ADR-0021): their sessions
	// show at the Listed level, and `n` can start them.
	Harnesses map[string]Harness `toml:"harnesses"`

	// Path is where the config was loaded from (not part of the file).
	Path string `toml:"-"`
	// Warnings are non-fatal findings from Validate.
	Warnings []string `toml:"-"`
	// contains filtered or unexported fields
}

Config is the whole file.

func Load

func Load(file string) (*Config, error)

Load reads, decodes, defaults and validates a config file.

func Parse

func Parse(b []byte) (*Config, error)

Parse decodes, defaults and validates config bytes.

func (*Config) Accepts

func (c *Config) Accepts(to *Agent, from string) bool

Accepts reports whether the agent accepts traffic from sender (R-SEC-2). The default is every configured agent plus the human.

func (*Config) Agent

func (c *Config) Agent(id string) *Agent

Agent returns the agent or nil.

func (*Config) AgentForPath

func (c *Config) AgentForPath(dir string) *Agent

AgentForPath returns the agent whose repo contains dir (longest match). Symlinks are resolved on both sides, so a symlinked checkout matches.

func (*Config) AgentIDs

func (c *Config) AgentIDs() []string

AgentIDs returns sorted agent ids.

func (*Config) EffectiveProfile

func (c *Config) EffectiveProfile(agentID, name string) (Profile, error)

EffectiveProfile returns profile name for agent id with overrides applied.

func (*Config) HarnessCommand added in v0.2.0

func (c *Config) HarnessCommand(name string) string

HarnessCommand is the program that starts a harness, from the config or the built-in table ("" = none).

func (*Config) IsTestCommand added in v0.2.0

func (c *Config) IsTestCommand(command string) bool

IsTestCommand reports a shell command that runs tests: a built-in pattern or one of daemon.test_commands.

func (*Config) ListedProcesses added in v0.2.0

func (c *Config) ListedProcesses() map[string]string

ListedProcesses maps the configured process names to their harness.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks every rule in RFC 6 and 7.6. It collects all problems.

type Daemon

type Daemon struct {
	MaxWorkers  int      `toml:"max_workers"`
	CommandPool int      `toml:"command_pool"`
	DefaultTTL  Duration `toml:"default_ttl"`
	PresenceTTL Duration `toml:"presence_ttl"`
	Notify      string   `toml:"notify"` // "os", "none" or "log:<path>"
	// SessionNotify says which session changes raise a notification
	// (ADR-0014): "waiting,answered" (default), "waiting", "answered" or
	// "none".
	SessionNotify string `toml:"session_notify"`
	// NotifyURL gets a POST for each notification (ADR-0021): https, or
	// http to localhost. Empty is off. It can hold a topic's secret, so
	// no log, error or doctor line names it.
	NotifyURL string `toml:"notify_url"`
	// Remotes are ssh hosts that run smif too (ADR-0023): their sessions show
	// here, read only.
	Remotes []string `toml:"remotes"`
	// RemoteWrite are the hosts you allowed yourself to type into (ADR-0024).
	RemoteWrite []string `toml:"remote_write"`
	// RemoteNames are the names you gave them, by host.
	RemoteNames map[string]string `toml:"remote_names"`
	// KeepAwake stops idle sleep on macOS while a session works.
	KeepAwake bool `toml:"keep_awake"`
	// Watchdogs (ADR-0015), each a duration or "off": remind again while a
	// session waits in its tab (every RemindWaiting, at most 3 times), and
	// tell once when a working session writes nothing for AlertSilent or
	// works longer than AlertLongTurn.
	RemindWaiting string `toml:"remind_waiting"`
	AlertSilent   string `toml:"alert_silent"`
	AlertLongTurn string `toml:"alert_long_turn"`
	// TestCommands adds regexes to the built-in test command patterns of
	// the session facts (ADR-0021). ContextWarn is the context size over
	// which a session's row shows it: "200k", "1m", a count, or "off".
	TestCommands []string `toml:"test_commands"`
	ContextWarn  string   `toml:"context_warn"`
	// Terminal types the human's prompts into idle sessions (ADR-0012):
	// "auto" (Terminal.app on macOS), "none" (off) or "log:<path>" (tests).
	Terminal           string     `toml:"terminal"`
	RateLimitPerMinute int        `toml:"rate_limit_per_minute"`
	MaxThreadMessages  int        `toml:"max_thread_messages"`
	PingPongLimit      int        `toml:"ping_pong_limit"`
	PingPongWindow     Duration   `toml:"ping_pong_window"`
	AgingStep          Duration   `toml:"aging_step"`
	RetryBackoff       []Duration `toml:"retry_backoff"`
	OverloadExtra      int        `toml:"overload_extra_attempts"`
	MessageRetention   Duration   `toml:"message_retention"`
	TranscriptRetain   Duration   `toml:"transcript_retention"`
	BlobGrace          Duration   `toml:"blob_grace"`
	BranchRetention    Duration   `toml:"branch_retention"`
	AuditRetention     Duration   `toml:"audit_retention"`
	LogRetention       Duration   `toml:"log_retention"`
}

Daemon holds process-wide settings.

type Defaults

type Defaults struct {
	ClaudeCommand   string   `toml:"claude_command"`
	MaxHops         int      `toml:"max_hops"`
	MaxAttempts     int      `toml:"max_attempts"`
	CommandTimeout  Duration `toml:"command_timeout"`
	MaxOutputBytes  int64    `toml:"max_output_bytes"`
	RotateAtTokens  int64    `toml:"rotate_at_tokens"`
	RotateAfterRuns int      `toml:"rotate_after_runs"`
}

Defaults apply to every agent unless overridden.

type Duration

type Duration struct{ time.Duration }

Duration is a time.Duration decoded from strings such as "6h" or "30m". A trailing "d" (days) is also accepted.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

type Harness added in v0.2.0

type Harness struct {
	Process []string `toml:"process"`
	Command string   `toml:"command"`
}

Harness is one [harnesses.<name>] table. Process lists the process names of the agent, Command the program that starts it. A name that a built-in provider owns may set Command only.

type Match

type Match struct {
	From            any    `toml:"from"`
	Kind            any    `toml:"kind"`
	Intent          string `toml:"intent"`
	PriorityAtLeast string `toml:"priority_at_least"`
	// contains filtered or unexported fields
}

Match is the rule predicate. From and Kind accept a string or a list.

func (*Match) FromList

func (m *Match) FromList() []string

FromList returns the normalised sender list (nil = any).

func (*Match) IsCatchAll

func (m *Match) IsCatchAll() bool

IsCatchAll reports whether the match has no predicate at all.

func (*Match) KindList

func (m *Match) KindList() []string

KindList returns the normalised kind list (nil = any).

type Profile

type Profile struct {
	Model           string   `toml:"model"`
	Effort          string   `toml:"effort"`
	PermissionMode  string   `toml:"permission_mode"`
	AllowedTools    []string `toml:"allowed_tools"`
	DisallowedTools []string `toml:"disallowed_tools"`
	WriteScope      string   `toml:"write_scope"`
	MaxTurns        int      `toml:"max_turns"`
	TimeoutS        int      `toml:"timeout_s"`
	Policy          string   `toml:"policy"`
	OnwardMCP       bool     `toml:"onward_mcp"`
	// Hooks lets the user's and the repo's Claude Code hooks run inside the
	// worker. Off by default: hooks have side effects outside the worker
	// (memory capture, checkpoints, nested claude calls).
	Hooks      bool     `toml:"hooks"`
	Minimal    bool     `toml:"minimal"`
	MaxCostUSD float64  `toml:"max_cost_usd"`
	ExtraArgs  []string `toml:"extra_args"`
	// Harness runs the worker on another coding agent: "" is Claude Code,
	// "codex" is `codex exec`, read only (ADR-0022).
	Harness string `toml:"harness"`
}

Profile is a named worker runtime (RFC 6.2).

type Rule

type Rule struct {
	ID          string   `toml:"id"`
	Match       Match    `toml:"match"`
	Handler     string   `toml:"handler"`
	Profile     string   `toml:"profile"`
	Command     []string `toml:"command"`
	Timeout     Duration `toml:"timeout"`
	Cooldown    Duration `toml:"cooldown"`
	ReopenAfter int      `toml:"reopen_after"`
}

Rule maps matching messages to a handler (RFC 6.1).

Jump to

Keyboard shortcuts

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