config

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxTurns = 30

DefaultMaxTurns is the application-wide default for agent max turns. Used as the fallback in config.IntOr(settings.Agent.MaxTurns, config.DefaultMaxTurns).

View Source
const DefaultSubAgentMaxTurns = 30

DefaultSubAgentMaxTurns is the default max turns for sub-agent dispatch (SubAgentSettings.MaxTurns zero value).

Variables

This section is empty.

Functions

func AtomicWrite added in v0.16.8

func AtomicWrite(path string, data []byte, perm os.FileMode) error

AtomicWrite writes data to path using a temp file + rename pattern. Creates parent directories with 0o700 if needed.

func AuthPath

func AuthPath() (string, error)

AuthPath returns ~/.config/piglet/auth.json.

func ConfigDir

func ConfigDir() (string, error)

ConfigDir returns ~/.config/piglet/, respecting XDG_CONFIG_HOME.

func ExtensionConfigDir added in v0.16.26

func ExtensionConfigDir(name string) (string, error)

ExtensionConfigDir returns the namespaced config directory for an extension: ~/.config/piglet/extensions/<name>/. It does not create the directory.

func HistoryPath added in v0.16.24

func HistoryPath() (string, error)

HistoryPath returns ~/.config/piglet/history.

func IntOr added in v0.4.0

func IntOr(v, fallback int) int

IntOr returns v if positive, otherwise fallback.

func ModelsPath added in v0.5.0

func ModelsPath() (string, error)

ModelsPath returns the path to models.yaml in the config dir.

func NeedsSetup added in v0.5.0

func NeedsSetup() bool

NeedsSetup returns true if config.yaml or models.yaml is missing.

func NormalizeProvider

func NormalizeProvider(name string) string

NormalizeProvider resolves aliases to canonical provider names.

func ReadExtensionConfig added in v0.5.0

func ReadExtensionConfig(name string) (string, error)

ReadExtensionConfig reads a markdown config file for the named extension. Looks for ~/.config/piglet/extensions/<name>/<name>.md first, falling back to ~/.config/piglet/<name>.md for backward compatibility. Returns empty string (not error) if the file doesn't exist.

func RunSetup added in v0.5.0

func RunSetup(writeModels func(path string) error, modelDefaults map[string]string) error

RunSetup runs the interactive first-time setup flow. writeModels is called to write the default models.yaml file. modelDefaults maps provider key → default model ID (used during key detection).

func Save

func Save(s Settings) error

Save writes settings to the config file.

func SaveTo

func SaveTo(s Settings, path string) error

SaveTo writes settings to a specific path.

func SessionsDir

func SessionsDir() (string, error)

SessionsDir returns ~/.config/piglet/sessions/.

func SettingsPath

func SettingsPath() (string, error)

SettingsPath returns ~/.config/piglet/config.yaml.

Types

type AgentSettings added in v0.4.0

type AgentSettings struct {
	MaxTurns          int   `yaml:"maxTurns,omitempty"`          // default DefaultMaxTurns
	BgMaxTurns        int   `yaml:"bgMaxTurns,omitempty"`        // default 5
	AutoTitle         *bool `yaml:"autoTitle,omitempty"`         // default true; pointer distinguishes false from unset
	CompactKeepRecent int   `yaml:"compactKeepRecent,omitempty"` // default 6
	CompactAt         int   `yaml:"compactAt,omitempty"`         // token threshold for auto-compact; 0 = disabled
	MaxMessages       int   `yaml:"maxMessages,omitempty"`       // hard cap on messages; 0 = unlimited
	MaxTokens         int   `yaml:"maxTokens,omitempty"`         // output token limit; 0 = use model default
	MaxRetries        int   `yaml:"maxRetries,omitempty"`        // retry attempts on error; 0 = use default (3)
	ToolConcurrency   int   `yaml:"toolConcurrency,omitempty"`   // max parallel tool calls; 0 = use default (10)
}

AgentSettings controls agent loop behavior. Zero values use defaults.

func (AgentSettings) AutoTitleEnabled added in v0.4.0

func (a AgentSettings) AutoTitleEnabled() bool

AutoTitleEnabled returns whether auto-title generation is on (default true).

type Auth

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

Auth manages API key resolution. Priority: runtime overrides → stored credentials → environment variables → command values.

func NewAuth

func NewAuth(path string) *Auth

NewAuth creates an Auth that persists to the given path. Pass "" for in-memory only (tests).

func NewAuthDefault

func NewAuthDefault() (*Auth, error)

NewAuthDefault creates an Auth using the default auth path.

func (*Auth) GetAPIKey

func (a *Auth) GetAPIKey(provider string) string

GetAPIKey returns the API key for a provider. Resolution order: runtime override → stored credential → env var → empty.

func (*Auth) HasAuth

func (a *Auth) HasAuth(provider string) bool

HasAuth reports whether any form of auth exists for the provider.

func (*Auth) Providers

func (a *Auth) Providers() []string

Providers returns a list of providers with stored credentials.

func (*Auth) RemoveKey

func (a *Auth) RemoveKey(provider string) error

RemoveKey removes a stored API key and persists.

func (*Auth) SetKey

func (a *Auth) SetKey(provider, key string) error

SetKey stores an API key and persists to disk.

func (*Auth) SetRuntimeKey

func (a *Auth) SetRuntimeKey(provider, key string)

SetRuntimeKey sets a runtime API key override (not persisted).

type BashSettings added in v0.4.0

type BashSettings struct {
	DefaultTimeout int `yaml:"defaultTimeout,omitempty"` // seconds, default 30
	MaxTimeout     int `yaml:"maxTimeout,omitempty"`     // seconds, default 300
	MaxStdout      int `yaml:"maxStdout,omitempty"`      // bytes, default 100000
	MaxStderr      int `yaml:"maxStderr,omitempty"`      // bytes, default 50000
}

BashSettings controls the bash tool limits. Zero values use defaults.

type ExtensionSettings added in v0.16.8

type ExtensionSettings struct {
	RepoURL  string   `yaml:"repoUrl,omitempty"`
	Official []string `yaml:"official,omitempty"`
}

ExtensionSettings controls extension installation defaults.

type GitSettings added in v0.4.0

type GitSettings struct {
	MaxDiffStatFiles int `yaml:"maxDiffStatFiles,omitempty"` // default 30
	MaxLogLines      int `yaml:"maxLogLines,omitempty"`      // default 5
	MaxDiffHunkLines int `yaml:"maxDiffHunkLines,omitempty"` // default 50
	CommandTimeout   int `yaml:"commandTimeout,omitempty"`   // seconds, default 5
}

GitSettings controls git context in the system prompt. Zero values use defaults.

type LocalDefaults added in v0.17.0

type LocalDefaults struct {
	ContextWindow int `yaml:"contextWindow,omitempty"`
	MaxTokens     int `yaml:"maxTokens,omitempty"`
}

LocalDefaults holds default values for ad-hoc local model connections.

type Settings

type Settings struct {
	DefaultProvider        string            `yaml:"defaultProvider,omitempty"`
	DefaultModel           string            `yaml:"defaultModel,omitempty"`
	SmallModel             string            `yaml:"smallModel,omitempty"`
	SystemPrompt           string            `yaml:"systemPrompt,omitempty"` // base identity; overridden by prompt.md
	Theme                  string            `yaml:"theme,omitempty"`
	Extensions             []string          `yaml:"extensions,omitempty"`
	Providers              map[string]string `yaml:"providers,omitempty"` // provider name → base URL override
	Agent                  AgentSettings     `yaml:"agent,omitempty"`
	Git                    GitSettings       `yaml:"git,omitempty"`
	Tools                  ToolSettings      `yaml:"tools,omitempty"`
	Bash                   BashSettings      `yaml:"bash,omitempty"`
	Shortcuts              map[string]string `yaml:"shortcuts,omitempty"`              // action → keybind (e.g. "model": "ctrl+p")
	PromptOrder            map[string]int    `yaml:"promptOrder,omitempty"`            // section title → order override
	RTK                    *bool             `yaml:"rtk,omitempty"`                    // nil = auto-detect; true/false = explicit
	Debug                  bool              `yaml:"debug,omitempty"`                  // log all request/response payloads
	Safeguard              *bool             `yaml:"safeguard,omitempty"`              // nil/true = enabled; false = disabled
	MouseCapture           *bool             `yaml:"mouseCapture,omitempty"`           // nil/true = TUI captures mouse for scrolling; false = terminal handles (native text selection)
	DisabledExtensions     []string          `yaml:"disabled_extensions,omitempty"`    // extensions to skip during loading
	AllowProjectExtensions *bool             `yaml:"allowProjectExtensions,omitempty"` // default false; must opt-in for security
	SubAgent               SubAgentSettings  `yaml:"subagent,omitempty"`
	ExtInstall             ExtensionSettings `yaml:"extInstall,omitempty"`
	LocalServers           []string          `yaml:"localServers,omitempty"` // URLs of local model servers to probe on startup
	LocalDefaults          LocalDefaults     `yaml:"localDefaults,omitempty"`
	DeferredToolsNote      string            `yaml:"deferredToolsNote,omitempty"` // instruction shown when deferred tools are present
}

Settings holds user configuration.

func DefaultSettings added in v0.17.0

func DefaultSettings() Settings

DefaultSettings returns a Settings with all defaults applied. Useful for testing and for code that needs a baseline configuration.

func Load

func Load() (Settings, error)

Load reads settings from the config file. Returns zero Settings if file doesn't exist.

func LoadFrom

func LoadFrom(path string) (Settings, error)

LoadFrom reads settings from a specific path.

func (Settings) IsExtensionDisabled added in v0.16.16

func (s Settings) IsExtensionDisabled(name string) bool

IsExtensionDisabled reports whether the named extension is in the disabled list.

func (Settings) MouseCaptureEnabled added in v0.23.0

func (s Settings) MouseCaptureEnabled() bool

MouseCaptureEnabled reports whether TUI mouse capture is on. Default (nil) is true.

func (Settings) ResolveDefaultModel added in v0.9.0

func (s Settings) ResolveDefaultModel() string

ResolveDefaultModel returns the first non-empty value from the default model cascade: PIGLET_DEFAULT_MODEL env → DefaultModel config.

func (Settings) ResolveSmallModel added in v0.9.0

func (s Settings) ResolveSmallModel() string

ResolveSmallModel returns the first non-empty value from the small model cascade: PIGLET_SMALL_MODEL env → SmallModel config → PIGLET_DEFAULT_MODEL env → DefaultModel config.

type SubAgentSettings added in v0.5.0

type SubAgentSettings struct {
	MaxTurns int `yaml:"maxTurns,omitempty"` // default DefaultSubAgentMaxTurns
}

SubAgentSettings controls the dispatch tool's sub-agent defaults.

type ToolSettings added in v0.5.0

type ToolSettings struct {
	ReadLimit int `yaml:"readLimit,omitempty"` // max lines per read; default 2000
	GrepLimit int `yaml:"grepLimit,omitempty"` // max grep matches; default 100
}

ToolSettings controls built-in tool defaults. Zero values use defaults.

Jump to

Keyboard shortcuts

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