config

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package config loads daemon settings from environment variables and flags.

Index

Constants

View Source
const (
	SMTPStartTLS = "starttls" // plain connection upgraded with STARTTLS, which the server must offer
	SMTPImplicit = "implicit" // TLS from the first byte (SMTPS)
	SMTPNoTLS    = "none"     // no encryption: only for a mail server on this machine
)

SMTP TLS modes, as MAILRULES_SMTP_TLS takes them.

Variables

View Source
var ComposerProviders = []string{"anthropic", "openai", "ollama"}

ComposerProviders are the providers the rule composer can write with.

Functions

func MissingModel

func MissingModel(role, provider string) error

MissingModel is the error for a provider spec that names a provider with no default model and no model: role is what the spec is for ("decider", "composer").

func SplitComposerModel

func SplitComposerModel(spec string) (provider, model string, err error)

SplitComposerModel reads MAILRULES_COMPOSER_MODEL (the composer_model setting): a bare model name is a Claude model on Anthropic, as it always was; provider:model names the provider (anthropic, openai or ollama), and everything after the first colon is the model, so ollama:llama3.2:3b is the model llama3.2:3b. On error provider and model are still what was written, so a caller can tell a missing model from an unknown provider.

func ValidWorkspaceID

func ValidWorkspaceID(id string) bool

ValidWorkspaceID reports whether id can name an Anthropic workspace: empty (none), or wrkspc_ followed by letters and digits, as the Claude Console shows them. Nothing else may reach the anthropic-workspace-id header.

Types

type Config

type Config struct {
	DataDir       string
	Listen        string
	Mode          string
	MasterKey     string
	MasterKeyFile string
	// NewMasterKey lets the daemon start although the master key cannot open any stored
	// mailbox password or model key; see ext/daemon's openMasterKey.
	NewMasterKey bool
	DryRun       bool

	Decider          string
	DeciderModel     string
	FallbackModel    string
	ComposerModel    string
	EscalateBelow    float64
	MinConfidence    float64
	BodyChars        int
	ModelConcurrency int

	OpenRouterAPIKey    string
	CloudflareAccountID string
	CloudflareAPIToken  string
	AnthropicAPIKey     string
	// AnthropicWorkspaceID names the workspace every Claude request runs in (the
	// anthropic-workspace-id header). Only a key that covers a whole organisation needs it;
	// empty = none sent.
	AnthropicWorkspaceID string
	OpenAIBaseURL        string
	OpenAIAPIKey         string
	OllamaURL            string

	PricesFile string
	LogLevel   string

	// CookieSecure is auto, true or false; see SecureCookies.
	CookieSecure string

	// TrustedProxies lists the reverse proxies whose X-Forwarded-For header is believed,
	// as IP addresses or CIDR ranges separated by commas; see TrustedProxyPrefixes.
	TrustedProxies string

	// The outgoing mail server the summary email is sent through. SMTPPort 0 means the
	// usual port for SMTPTLS; SMTPPasswordFile names a file holding the password, like
	// MasterKeyFile. Never logged.
	SMTPHost         string
	SMTPPort         int
	SMTPUser         string
	SMTPPassword     string
	SMTPPasswordFile string
	SMTPFrom         string
	SMTPTLS          string // starttls | implicit | none (none: localhost only)

	// PublicURL is where the web app is reached from the user's mail program: links in the
	// summary email start with it.
	PublicURL string
}

Config holds every setting from the backend plan's Configuration table.

func Load

func Load(args []string, getenv func(string) string) (*Config, error)

Load reads settings from the environment, then lets flags in args override them. It does not validate; call Validate before serving.

func (*Config) ComposerReady

func (c *Config) ComposerReady() error

ComposerReady is DeciderReady for the rule composer's model.

func (*Config) DeciderReady

func (c *Config) DeciderReady() error

DeciderReady reports what the chosen decider still needs before it can run. It is not part of Validate: a fresh install starts without a key so the first-run wizard can collect one, and mail waits for review until then.

func (*Config) DeciderSpec

func (c *Config) DeciderSpec() string

DeciderSpec is the decider as models.NewRouter takes it: "name" or "name:model".

func (*Config) ListensLocally

func (c *Config) ListensLocally() bool

ListensLocally reports whether the HTTP address is loopback-only.

func (*Config) SMTPAddr

func (c *Config) SMTPAddr() string

SMTPAddr is the mail server's host:port, with the usual port for the TLS mode when none is set.

func (*Config) SMTPMissing

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

SMTPMissing lists the environment variables still to set before the summary email can be sent, in the order to set them; empty when it can be. A user name needs a password and a password a user name.

func (*Config) SMTPSecret

func (c *Config) SMTPSecret() (string, error)

SMTPSecret returns the mail server's password: MAILRULES_SMTP_PASSWORD, or the contents of MAILRULES_SMTP_PASSWORD_FILE without its line ending.

func (*Config) SecureCookies

func (c *Config) SecureCookies() bool

SecureCookies reports whether login cookies are marked HTTPS-only. "auto" means yes unless the daemon listens on loopback only. Set "false" when the daemon listens on every interface but is only published to this machine over plain HTTP (the Docker Compose setup); set "true" behind a TLS proxy.

func (*Config) TrustedProxyPrefixes added in v0.1.2

func (c *Config) TrustedProxyPrefixes() ([]netip.Prefix, error)

TrustedProxyPrefixes parses MAILRULES_TRUSTED_PROXIES: IP addresses and CIDR ranges separated by commas or spaces. A bare address names just itself. A range that covers every address (/0) is refused: it would let anyone forge X-Forwarded-For.

func (*Config) Validate

func (c *Config) Validate() error

Validate reports every problem at once, one message per problem.

type Setting added in v0.1.1

type Setting struct {
	Group   string // the heading it is listed under
	Env     string // the environment variable
	Flag    string // the command-line flag, without the leading --
	Default string // the default as the flag package prints it; empty for none
	Help    string // what it does, for a reader of the reference
}

Setting describes one setting as the settings reference (docs/guide/settings.md) lists it.

func Settings added in v0.1.1

func Settings() []Setting

Settings lists every setting in the order the reference shows them.

Directories

Path Synopsis
Command docgen writes the settings reference, docs/guide/settings.md, from the settings internal/config registers, so the page cannot drift from the daemon.
Command docgen writes the settings reference, docs/guide/settings.md, from the settings internal/config registers, so the page cannot drift from the daemon.

Jump to

Keyboard shortcuts

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