config

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 11 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 flockd configuration from defaults, an optional TOML file, and FLOCKD_-prefixed environment variables (koanf). Every knob is documented in docs/config.md.

Index

Constants

View Source
const (
	MaxConcurrentLimit = 64
	MinContextFloor    = 256
	MaxContextLimit    = 1 << 20
	MaxExcludeEntries  = 256
)

Bounds of the settings the limits API accepts. The config file is held to the looser Validate; these keep an app from writing a value that makes the node useless.

View Source
const NoDefaultModel = "none"

NoDefaultModel is the models.default (and flockd --default-model) value meaning "load nothing at startup": the node serves what the mesh places or the operator loads (flockd#49). Empty means the same; this spelling exists because an empty flag or env value reads as unset.

Variables

View Source
var LogLevels = []string{"debug", "info", "warn", "error"}

LogLevels are the accepted log.level values.

Functions

func LimitsPath added in v0.3.0

func LimitsPath(dataDir string) string

LimitsPath is the daemon-owned governor-limits overlay location.

func NormalizeDefaultModel added in v0.6.8

func NormalizeDefaultModel(id string) string

NormalizeDefaultModel maps the "none" spelling to empty.

func SaveLimits added in v0.3.0

func SaveLimits(dataDir string, g Governor, l LiveLimits, extra LimitsExtra) error

SaveLimits persists live-edited limits to the overlay file that Load applies on the next start. Only the operator-facing limit knobs are written; poll_interval and the rest stay wherever the operator set them. Of extra, only the fields that are set are written.

Types

type Budget

type Budget struct {
	MaxVRAMPercent int `koanf:"max_vram_percent"`
	// MaxRAMMB is the memory budget for loaded models; 0 = auto (half of
	// physical memory on unified-memory machines, vram × max_vram_percent
	// on discrete GPUs). Loads beyond it unload idle models first, then
	// are refused (mesh placements stay on disk as `cached`).
	MaxRAMMB int64 `koanf:"max_ram_mb"`
	// MaxConcurrent is the slot ceiling per loaded model (llama-server
	// --parallel) and the node's dispatch cap. 0 = auto by accelerator
	// class (16 with a GPU or unified memory, 2 CPU-only; memory.DefaultSlots).
	// Memory decides the actual slot count per load (flockd#46).
	MaxConcurrent int `koanf:"max_concurrent"`
	// MinConcurrent is the slot floor: the slots a chat model starts with
	// and shrinks back to; it grows toward max_concurrent while requests
	// are waiting (flockd#54). 0 = auto (2). At or above max_concurrent it
	// pins the slot count: no scaling.
	MinConcurrent int `koanf:"min_concurrent"`
}

type Config

type Config struct {
	DataDir string `koanf:"data_dir"`

	Log      Log      `koanf:"log"`
	LocalAPI LocalAPI `koanf:"local_api"`
	Runtime  Runtime  `koanf:"runtime"`
	Governor Governor `koanf:"governor"`
	Budget   Budget   `koanf:"budget"`
	Models   Models   `koanf:"models"`
	Tunnel   Tunnel   `koanf:"tunnel"`
	Enroll   Enroll   `koanf:"enroll"`
	Update   Update   `koanf:"update"`
}

Config is the fully resolved daemon configuration.

func Default

func Default() Config

Default returns the built-in defaults.

func Load

func Load(path string) (Config, error)

Load resolves configuration: defaults <- TOML file (if path != "" or the default path exists) <- FLOCKD_* environment variables.

Env mapping: FLOCKD_LOCAL_API__LISTEN=... maps to local_api.listen (double underscore = section separator).

func (Config) Validate

func (c Config) Validate() error

Validate rejects nonsensical configurations early.

type Enroll

type Enroll struct {
	// LoginURL is the invite page. Nothing opens it bare any more: it only
	// answers a link that carries an invite token, which `tera login --url`
	// takes whole. Kept so existing config files keep loading.
	LoginURL string `koanf:"login_url"`
}

type Governor

type Governor struct {
	// ServePolicy: "always", "idle-only" or "scheduled".
	ServePolicy string `koanf:"serve_policy"`
	// IdleAfter is how long input must be quiet before the node counts as
	// idle (idle-only policy).
	IdleAfter time.Duration `koanf:"idle_after"`
	// YieldGrace is the drain-or-cancel window on operator activity
	// (SPEC §4.1 instant-yield). Default 2s.
	YieldGrace time.Duration `koanf:"yield_grace"`
	// PollInterval is how often idle/power signals are sampled.
	PollInterval time.Duration `koanf:"poll_interval"`
	// ServeOnBattery: never serve on battery by default.
	ServeOnBattery bool `koanf:"serve_on_battery"`
	// MaxTempCelsius pauses serving above this temperature (0 disables).
	MaxTempCelsius float64 `koanf:"max_temp_celsius"`
	// Schedule windows for serve_policy=scheduled, e.g. ["22:00-08:00"].
	Schedule []string `koanf:"schedule"`
	// KeepAwake holds a system-sleep assertion (never the display) while a
	// request is in flight or while the node is serving and enrolled, so
	// the OS idle timer does not suspend a node the mesh is counting on
	// (docs/sleep.md). False = flockd never touches power management.
	KeepAwake bool `koanf:"keep_awake"`
}

type LimitsExtra added in v0.7.4

type LimitsExtra struct {
	MaxConcurrent  *int      // budget.max_concurrent
	MinConcurrent  *int      // budget.min_concurrent
	MaxVRAMPercent *int      // budget.max_vram_percent
	MaxContext     *int      // runtime.max_context
	MinContext     *int      // runtime.min_context
	ContextLength  *int      // runtime.context_length
	Exclude        *[]string // models.exclude
	DefaultModel   *string   // models.default ("" = none)
	RequireAuthV1  *bool     // local_api.require_auth_v1
	LogLevel       *string   // log.level
}

LimitsExtra are the settings the limits API exposes beyond the original governor / store / memory knobs (flockd#55). A nil field is "not set through the API": it is not written to the overlay, so config.toml (or the built-in default) keeps deciding it. Once set it lives in limits.toml, which overrides config.toml.

func LoadLimitsExtra added in v0.7.4

func LoadLimitsExtra(dataDir string) (LimitsExtra, error)

LoadLimitsExtra reports which LimitsExtra keys the overlay holds, with their values, so a later SaveLimits carries them forward. A missing overlay is an empty LimitsExtra.

type LiveLimits added in v0.4.0

type LiveLimits struct {
	MeshManaged   bool
	MaxDiskMB     int64
	RetentionDays int
	IdleUnloadS   int
	MaxRAMMB      int64
}

LiveLimits are the non-governor knobs the limits API edits live; they ride the same overlay as the governor policy.

type LocalAPI

type LocalAPI struct {
	// Listen address. Loopback only by default; changing this is dangerous
	// and documented with warnings in docs/config.md.
	Listen string `koanf:"listen"`
	// RequireAuthV1 requires the bearer token on the OpenAI-compatible /v1
	// endpoints too (the daemon-management /api/v1 always requires it).
	RequireAuthV1 bool `koanf:"require_auth_v1"`
}

type Log

type Log struct {
	Level  string `koanf:"level"`  // debug|info|warn|error
	Format string `koanf:"format"` // text|json
	// File, when set, receives a copy of every record (appended, never
	// rotated) in addition to stderr. The Windows logon task sets it via
	// --log-file: a task has no console, so it is the daemon's only sink.
	File string `koanf:"file"`
}

type Models

type Models struct {
	// ManifestPath or ManifestURL locates the model catalog (YAML/JSON,
	// teraflock/models format).
	ManifestPath string `koanf:"manifest_path"`
	ManifestURL  string `koanf:"manifest_url"`
	// Default is the node's default model: loaded at start-up and used
	// for requests that name no model. "none" = load nothing.
	Default string `koanf:"default"`
	// BaseDefault is Default as config.toml / env / the built-in default
	// had it, before limits.toml: what start-up falls back to when a
	// default chosen through the API can no longer be used. Not a config
	// key.
	BaseDefault string `koanf:"-"`
	// MaxDiskMB is the model-cache disk budget; LRU eviction below it.
	MaxDiskMB int64 `koanf:"max_disk_mb"`
	// Pin lists model ids exempt from eviction; Exclude are never assigned.
	Pin     []string `koanf:"pin"`
	Exclude []string `koanf:"exclude"`
	// MeshManaged lets the coordinator place models on this node (download,
	// load, and later evict what it placed) inside max_disk_mb, minus pin
	// and exclude. Off = the node serves only what the operator installed.
	// Default on: an enrolled node that never takes placements never earns.
	MeshManaged bool `koanf:"mesh_managed"`
	// IdleUnloadS unloads a loaded model after this many seconds without a
	// request (0 = never; the default model is exempt). Reload is a mmap
	// re-open, seconds not a download.
	IdleUnloadS int `koanf:"idle_unload_s"`
	// RetentionDays evicts unpinned, unloaded models unused for this many
	// days (0 = never). Mesh and operator models alike.
	RetentionDays int `koanf:"retention_days"`
}

type Runtime

type Runtime struct {
	// Kind selects the runtime adapter: "llamacpp" or "mock".
	Kind string `koanf:"kind"`
	// LlamaServerPath, when set, uses an existing llama-server binary
	// instead of downloading one from the artifact manifest.
	LlamaServerPath string `koanf:"llama_server_path"`
	// ArtifactManifestURL points at the JSON manifest of pinned, SHA-verified
	// llama-server builds (see internal/runtime/llamacpp/artifact.go).
	ArtifactManifestURL string `koanf:"artifact_manifest_url"`
	// MockTokensPerSec controls the synthetic generation speed of the mock
	// runtime (tests, --standalone demos).
	MockTokensPerSec float64 `koanf:"mock_tokens_per_sec"`
	// ContextLength pins the per-request (per-slot) context exactly
	// (0 = planned from the memory budget, flockd#46). Slots still adapt.
	ContextLength int `koanf:"context_length"`
	// MaxContext caps per-request context, in tokens (0 = the model's
	// training window). The planner spends spare memory on context up to
	// this cap, on every slot; the KV cache is sized by slots × context.
	MaxContext int `koanf:"max_context"`
	// MinContext is the per-request floor: the planner gives up slots
	// before a request gets less than this (0 = 8192).
	MinContext int `koanf:"min_context"`
	// ArtifactSigningKey overrides the daemon's built-in pin for the key
	// that runtime manifests and tarballs are cosign-signed with
	// (internal/runtime/llamacpp/trust.go): either an inline PEM public
	// key ("-----BEGIN PUBLIC KEY-----", ECDSA P-256) or the path to a PEM
	// file. For self-hosted coordinators and development catalogs signed
	// with their own key. Never taken from the manifest or artifact host.
	ArtifactSigningKey string `koanf:"artifact_signing_key"`
	// RequireSignature refuses runtime manifests and artifacts that carry
	// no cosign signature, refuses cached extracts that were trusted by
	// sha256 alone, and refuses to run without a pinned signing key.
	// Default true since flockd#25 stage 2: the stable manifest and every
	// artifact it lists are signed (runtimes llamacpp-b9892-4 onward) and
	// the daemon embeds the Teraflock key. A cached runtime that predates
	// signing is refused on the next start and re-fetched from stable;
	// false is for self-hosted catalogs that have not adopted signing.
	RequireSignature bool `koanf:"require_signature"`
}

func (Runtime) ArtifactSigningKeyPEM added in v0.6.1

func (r Runtime) ArtifactSigningKeyPEM() ([]byte, error)

ArtifactSigningKeyPEM resolves Runtime.ArtifactSigningKey to PEM bytes: an inline PEM is returned as-is, anything else is read as a file path. nil when unset (the daemon then relies on its embedded pin, if any).

type Tunnel

type Tunnel struct {
	// CoordinatorAddr is the coordinator endpoint (host:port).
	CoordinatorAddr string `koanf:"coordinator_addr"`
	// Standalone runs the in-process fake coordinator (Phase 0).
	Standalone bool `koanf:"standalone"`
	// HeartbeatInterval between heartbeats (coordinator may override).
	HeartbeatInterval time.Duration `koanf:"heartbeat_interval"`
	// ReconnectMin/Max bound the jittered exponential backoff.
	ReconnectMin time.Duration `koanf:"reconnect_min"`
	ReconnectMax time.Duration `koanf:"reconnect_max"`
	// InsecureSkipVerify disables server cert verification (dev only).
	InsecureSkipVerify bool `koanf:"insecure_skip_verify"`
	// CACert pins an extra root for the coordinator's server certificate:
	// the path of a PEM file, or the PEM itself. Only a self-hosted or
	// staging coordinator whose certificate is issued by its own mesh CA
	// (or a private CA) needs it — tunnel.teraflock.ai presents a public
	// certificate. It applies to every dial (enrollment, cert rotation,
	// the mTLS session) alongside the system roots, which stay trusted;
	// it is never a substitute for insecure_skip_verify's blanket skip.
	// (teraflock/flockd#4)
	CACert string `koanf:"ca_cert"`
	// Insecure dials the coordinator over plaintext gRPC instead of TLS.
	// The dev coordinator (`just run-coordinator`) serves plaintext until
	// mTLS termination lands; never enable this against a real deployment.
	Insecure bool `koanf:"insecure"`
}

func (Tunnel) CACertPEM added in v0.6.1

func (t Tunnel) CACertPEM() ([]byte, error)

CACertPEM resolves Tunnel.CACert: nil when unset, the value itself when it is inline PEM, otherwise the contents of the file it names.

type Update added in v0.4.0

type Update struct {
	// FeedURL is the version feed the daemon polls hourly
	// ({flockd:{latest,minimum,url},desktop:{latest,url}}).
	FeedURL string `koanf:"feed_url"`
}

Jump to

Keyboard shortcuts

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