config

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package config loads the settings `patchcord serve` runs with from three layered sources — a YAML file, environment variables, and CLI flags — in that increasing order of precedence: a flag explicitly passed always wins, then an environment variable, then the config file, then a built-in default (ADR-0038). It only holds the settings themselves; the CLI (internal/cli/serve.go) owns the built-in defaults and the flag layer, since only it knows which flags were actually passed (cobra's Flags().Changed).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultDataDir

func DefaultDataDir() string

DefaultDataDir resolves the built-in default for --data-dir / PATCHCORD_DATA_DIR (ADR-0038, ADR-0049): the lowest-precedence source, used only when neither a flag nor the environment variable is set. Unlike the "./data" it replaces, this is a per-user, per-machine location that does not depend on the directory a command happens to be run from — every patchcord command run by the same user resolves the same agent database by default (ADR-0052).

It follows each OS's own convention for per-user application data:

  • macOS: ~/Library/Application Support/patchcord
  • Linux/BSD: $XDG_DATA_HOME/patchcord, or ~/.local/share/patchcord if unset
  • Windows: %LOCALAPPDATA%\patchcord

Types

type AppsConfig added in v0.1.4

type AppsConfig struct {
	DirectoryListing DirectoryListingConfig `yaml:"directory_listing"`
}

AppsConfig holds settings for installed application hosting.

type Config

type Config struct {
	Listen  string `yaml:"listen"`
	DataDir string `yaml:"data_dir"`
	// SecretsMasterKeyFile points to the file holding the base64 AES-256
	// master key for the "file" secret store (secrets.FileStore). Left
	// empty, the "file" secret reference type is simply not available on
	// this agent — see ADR-0040.
	SecretsMasterKeyFile string `yaml:"secrets_master_key_file"`
	// Apps holds settings for the /apps/{id}/ hosting surface (ADR-0026).
	Apps AppsConfig `yaml:"apps"`
}

Config holds the subset of runtime.Config that can come from a file or environment variables, not just CLI flags. An empty field means that source expressed no opinion — see Merge.

func FromEnv

func FromEnv() Config

FromEnv reads PATCHCORD_LISTEN, PATCHCORD_DATA_DIR, PATCHCORD_SECRETS_MASTER_KEY_FILE and PATCHCORD_APPS_DIRECTORY_LISTING_ENABLED. An unset variable leaves the corresponding field empty (or false), so Merge falls through to a lower-precedence source for it. An unparseable PATCHCORD_APPS_DIRECTORY_LISTING_ENABLED value (anything strconv.ParseBool rejects) is treated the same as unset, rather than failing startup — this setting only ever turns a 404 into an index page, never something worth refusing to boot over.

func Load

func Load(path string) (Config, error)

Load reads and parses a YAML config file. Unknown top-level keys are rejected (a typo'd "liste:" is caught here, not silently ignored) — the same discipline internal/workflow.Validate already applies to workflow YAML.

func Merge

func Merge(base, override Config) Config

Merge layers override on top of base, field by field: a non-empty field in override replaces base's; an empty one leaves base untouched. Callers apply this once per source, from lowest to highest precedence — file, then env, then flags (internal/cli/serve.go).

Apps.DirectoryListing.Enabled is boolean, so it can't distinguish "this source said false" from "this source expressed no opinion" the way an empty string can — Merge treats override's true as an opinion and leaves base alone otherwise. That is a real limitation (a higher-precedence source can enable but never force-disable what a lower one enabled), but nothing in this setting's three sources needs to force-disable it today: there is no CLI flag for it, so the highest-precedence source is env, and an operator who wants it off can simply not set the env var or the file key and rely on the false default.

type DirectoryListingConfig added in v0.1.4

type DirectoryListingConfig struct {
	// Enabled turns the listing on. Left false (the default), GET /apps/
	// returns a plain 404, unchanged from before this setting existed —
	// the operator opts in explicitly (ADR-0007: no behavior change without
	// one).
	Enabled bool `yaml:"enabled"`
}

DirectoryListingConfig controls GET /apps/, an Apache-style index page listing every installed application with a link to its /apps/{id}/ — see ADR-0061.

Jump to

Keyboard shortcuts

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