config

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 29 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 merges bitc's TOML files (spec 5). model.go is the effective configuration every other package reads.

Index

Constants

View Source
const (
	TransportGitPush = "git-push"
	TransportUpload  = "upload"
	DefaultMaxBundle = Size(1 << 30)
	MaxBundleLimit   = Size(8 << 30)
)

The transport kinds, and the bounds of transport.max_bundle.

View Source
const BuiltinKnownHosts = `` /* 827-byte string literal not displayed */

BuiltinKnownHosts are GitHub's published SSH host keys (spec 8.4), updated per release. Verify with: printf '%s\n' "$BuiltinKnownHosts" | ssh-keygen -lf -

View Source
const ExperimentalRemoteCleanup = "To clean up resources left by an earlier version, set the flag and run bitc sweep."

ExperimentalRemoteCleanup follows the refusal for sweep, doctor --remote and a host that an earlier version left remote reservations or ledger lines on.

View Source
const ExperimentalRemoteRefusal = "remote providers are experimental in this release and off by default; " +
	"their spend accounting is still under review (see https://github.com/Exploded-views/bitc#known-issues). " +
	"To use them anyway, set [host] experimental_remote = true."

ExperimentalRemoteRefusal is the config problem for a remote provider without [host] experimental_remote = true (README "Known issues").

View Source
const ModulePath = "github.com/Exploded-views/bitc"

ModulePath is this module's path, the one a module_dir tree must declare.

View Source
const SpritesRefusal = "Sprites jobs are refused in this release: their network policy does not restrict " +
	"egress yet, and a job would receive the forwarded environment and the deploy key. `bitc sweep` can " +
	"still clean up Sprites left by 0.1.0 (see https://github.com/Exploded-views/bitc/issues/6 and " +
	"https://github.com/Exploded-views/bitc#known-issues)."

SpritesRefusal is the config problem for any [providers.sprites] table or a pool naming sprites on every path but a cleanup: Sprites jobs are refused in this release, with or without experimental_remote, until the egress fix (#6) lands and is reviewed. A cleanup (sweep, doctor --remote: LoadOptions.Cleanup) gets the provider as CleanupOnly instead.

Variables

View Source
var (
	HostOnlyVars   = map[string]bool{"slot": true, "slots": true, "hold": true, "state_dir": true, "worktree": true, "cwd": true}
	RemoteOnlyVars = map[string]bool{"week": true, "sha256": true}
)

HostOnlyVars exist only on the host; RemoteOnlyVars only in a remote job (spec 5.7).

View Source
var Architectures = []string{"amd64", "arm64"}

Architectures are the linux architectures bitc delivers an agent for (spec 8.4 step 1).

Functions

func CanonName

func CanonName(s string) string

func Explain

func Explain(e *Effective, key string) []string

Explain lists effective values with their source (spec 3). Credentials print <redacted>.

func FormatDuration added in v0.1.4

func FormatDuration(d time.Duration) string

FormatDuration is d in the spec's duration grammar (5.2), largest units first: 90m is "1h30m". A duration that is not whole milliseconds is rounded up to the next one.

func GenerateReference

func GenerateReference() string

GenerateReference renders docs/config-reference.md from the schema's struct tags (spec 5.4).

func IsBuiltInType

func IsBuiltInType(typ string) bool

IsBuiltInType reports whether typ names a built-in provider (registered or reserved).

func IsFixedType

func IsFixedType(typ string) bool

IsFixedType reports whether typ is a registered fixed-capacity provider type.

func LeftoverHint added in v0.1.1

func LeftoverHint(typ string) string

LeftoverHint is doctor's warn detail and sweep's hint for a type in UnconfiguredLeftovers.

func LoopbackLiteral

func LoopbackLiteral(ep string) bool

LoopbackLiteral reports whether an endpoint (a host, host:port or URL) is a loopback IP literal.

func Match

func Match(pattern, name string) (bool, error)

Match is path.Match per "/" segment, where a "**" segment matches zero or more segments. name is a canonical absolute path.

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration accepts <int><unit>[<int><unit>...] with units ms s m h d (spec 5.2).

func ParseInt

func ParseInt(s string) (int64, error)

ParseInt accepts 0 or [1-9][0-9]* (spec 5.2; no leading zero, sign, unit or fraction).

func RegisterProviderType

func RegisterProviderType(name string, t ProviderType)

RegisterProviderType adds or replaces a provider type (called from provider packages' init).

func RemoteLeftovers added in v0.1.1

func RemoteLeftovers(e *Effective) []string

RemoteLeftovers lists, sorted, the provider types whose remote/<type>/reservations.json in the accounting dir lists a job: a run that never finished (bitc was killed, the host lost power), whose resource may still exist and cost money until a sweep with that provider configured removes it. The ledger is not used: it is append-only, so its lines only say that remote jobs ran once, and a sweep closes no launch. It only reads, never creates the dir, and never blocks.

func SecretLikeName

func SecretLikeName(name string) bool

SecretLikeName reports whether a variable or key name looks like a secret (spec 8.4).

func SetPlatformForTest added in v0.1.3

func SetPlatformForTest(goos string) (restore func())

SetPlatformForTest makes Load check configs against goos (a test seam for other packages' tests; the in-package tests set platformGOOS directly). Test-only: never call it from product code. It returns the restore function.

func UnconfiguredLeftovers added in v0.1.1

func UnconfiguredLeftovers(e *Effective) []string

UnconfiguredLeftovers is RemoteLeftovers without the types the host configures (a sweep of those removes what is left): what doctor and sweep point out on their own.

func ValidEnvName

func ValidEnvName(s string) bool

ValidEnvName accepts ^[A-Za-z_][A-Za-z0-9_]*$ not starting BITC_ (spec 5.2).

func ValidGlob

func ValidGlob(pattern string) error

ValidGlob checks every segment with path.Match.

func ValidPoolName

func ValidPoolName(s string) bool

func ValidSizeKey

func ValidSizeKey(s string) bool

Types

type Agent

type Agent struct {
	Source string // "release" | "url" | "build"
	URL    string
	Path   string
	Commit string // build: the pinned commit of the job repo (40 hex)
	Image  string // build: the pod image, <name>@sha256:<64 hex>
	SHA256 string // build: the sha256 the built binary must have
	// Paths maps an architecture to the local file whose sha256 is sent (source = "url"); the
	// legacy Path is folded into Paths["amd64"] at load.
	Paths map[string]string
	// ModuleDir is a bitc source tree the host builds the agent from (source = "build" without
	// commit, image and sha256; providers delta C.4 item 3).
	ModuleDir string
}

type Artifact

type Artifact struct {
	Path    string
	Replace bool
}

type ArtifactLimits

type ArtifactLimits struct {
	MaxCompressed Size
	MaxUnpacked   Size
	MaxEntries    int
}

type Breaker

type Breaker struct {
	Failures int
	Window   time.Duration
}

type Compat

type Compat struct {
	LegacyDir  string
	HoldEnv    string
	NamePrefix string
	Groups     map[string]string // bitc group -> legacy lock stem
}

type Detach

type Detach struct{ WaitTimeout time.Duration }

type Effective

type Effective struct {
	HostFile   string // "" if no host file exists
	RepoFile   string // "" if no repo file applies
	Worktree   string // canonical work-tree top (5.1)
	WT8        string // 8 hex of sha256(Worktree)
	Cwd        string // canonical cwd
	LogicalCwd string // $PWD when it names Cwd, else Cwd

	Host         Host
	Pools        map[string]*Pool // canonical name -> pool
	Groups       map[string]Group
	Priority     Priority
	Detach       Detach
	RemoteLimits RemoteLimits
	Providers    map[string]*Provider // provider type -> section
	Repos        []RepoGrant
	Grant        *RepoGrant  // first [[repos]] entry matching Worktree, or nil
	Remote       *RepoRemote // the repo's [remote] table, or nil
	Vars         Vars        // merged [vars], host wins
	Compat       *Compat
	Test         *Test
	EnvProvider  string            // BITC_PROVIDER ("" or "local")
	EnvArtifacts *[]string         // BITC_ARTIFACTS (nil if unset)
	GlobalFlags  Flags             // the global flags Load was given
	LogLevel     string            // BITC_LOG: "info" (default), "debug" or "quiet" (1.2b sets it; -v raises info to debug, 1.7)
	Sources      map[string]string // effective key -> "default" | file path | "env BITC_X" | "flag --x"
	Secrets      []string          // credential values loaded, for redaction

	DefaultPool *Pool // template for ad-hoc pools when Host.UnknownPools == "default"

	Warnings []string // non-fatal config notes, one line each; `config check` prints them to stderr
	// contains filtered or unexported fields
}

Effective is the merged, validated configuration for one invocation.

func Load

func Load(o LoadOptions) (*Effective, error)

Load reads built-in defaults, the host file, one repo file and BITC_* env (spec 5.1-5.6). File problems are 78 (all listed); malformed BITC_* values are 64.

func (*Effective) ApplyRunFlags

func (e *Effective) ApplyRunFlags(f RunFlags) error

ApplyRunFlags records `run` narrowing flags; Resolve applies them to the pool (5.3).

func (*Effective) Resolve

func (e *Effective) Resolve(name string) (*Pool, error)

Resolve looks a pool up by canonical name (spec 6.1) and applies run narrowing.

func (*Effective) Scale

func (e *Effective) Scale(d time.Duration) time.Duration

Scale applies [test] time_scale to a duration bitc waits on.

type Flags

type Flags struct {
	ConfigFile string // --config
	StateDir   string // --state-dir
	Verbose    int    // -v (repeatable)
	JSON       bool   // --json
}

Flags are bitc's global flags (spec 3).

type Group

type Group struct {
	Name  string
	Units int
}

type Hook

type Hook struct {
	Name       string // "pre_run" | "env" | "post_run"
	Argv       []Template
	Timeout    time.Duration
	RefuseExit []int
	Layer      string // "host" | "repo"
}

type Hooks

type Hooks struct {
	PreRun  []Hook // host first
	PostRun []Hook // host first
	Env     *Hook  // at most one
	Wrap    []WrapRule
}

type Host

type Host struct {
	StateDir          string
	Poll              time.Duration
	MemoryFloor       Size
	ReservationWindow time.Duration
	UnknownPools      string // "refuse" | "default"
	Grace             time.Duration
	MaxSignalWait     time.Duration
	HistoryMax        Size
	Retention         time.Duration
	// ExperimentalRemote: [host] experimental_remote, the opt-in remote providers need. Host file
	// only: no repo key and no BITC_* variable sets it.
	ExperimentalRemote bool
}

type LoadOptions

type LoadOptions struct {
	Flags Flags
	Env   []string // the caller's environment, KEY=VALUE
	Cwd   string   // os.Getwd() of the caller

	RepoFile string // `config check --repo FILE`: use FILE as the repo file
	// Cleanup: the caller is sweep or doctor --remote, so a refusal for remote providers says how
	// to clean up what an earlier version left.
	Cleanup bool
}

LoadOptions are Load's inputs.

type Micros

type Micros int64

Micros is US dollars in micro-dollars.

func ParseMoney

func ParseMoney(v any) (Micros, error)

ParseMoney accepts a TOML number >= 0 with at most 4 decimals (spec 5.2).

func (Micros) Dollars

func (m Micros) Dollars() string

Dollars prints the amount with two decimals, as the cap note does (spec 8.3).

type Part

type Part struct {
	Lit string
	Var string
	Op  string // "", "+", "-", ":"
	Arg string
}

Part is one piece of a template: a literal, or {Var}, {Var+Arg} or {Var-Arg}. {sha256:<path>} is Var "sha256" with Arg <path> and Op ":".

func ParseTemplate

func ParseTemplate(raw string) ([]Part, error)

ParseTemplate splits raw into parts; {{ and }} are literal braces.

type PluginPin

type PluginPin struct {
	Path        string
	SHA256      string
	EnvPass     []string
	SecretFiles map[string]string // name -> file (home expanded), 0600 and owned by the user
}

PluginPin is the host-only plugin table of a provider section (A.2): an absolute path and a sha256, env names passed through, and secret files read at spawn and sent on fd 3.

type Pool

type Pool struct {
	Name             string
	AdHoc            bool
	Slots            int
	Wait             time.Duration
	Timeout          time.Duration  // 0: no limit on a local run
	Memory           Size           // 0: no memory admission
	Groups           map[string]int // group -> units consumed
	GroupsMax        map[string]int // group -> most units a run may ask for with --units (absent: the group's units)
	Providers        []string       // effective list, host order
	DefaultsEnvUnset []string       // [defaults].env_unset (both layers): applied first
	EnvDefault       map[string]Template
	Env              map[string]Template
	EnvUnset         []string // pool env_unset (both layers): applied after Env
	Refuse           []RefuseRule
	OnSignal         string // "terminate" | "forward-and-wait"
	Hooks            Hooks
	RemoteSize       map[string]string // provider type -> size key
	RemoteTimeout    time.Duration
	Remote           *PoolRemote // repo [pools.<p>.remote], nil if absent
}

type PoolRemote

type PoolRemote struct {
	Allow     [][]string
	Artifacts []Artifact
	Timeout   time.Duration
	Env       map[string]Template
	EnvUnset  []string
	Arch      []string // linux architectures the pool's jobs may run on; default ["amd64"] (spec 8.4)
}

type Priority

type Priority struct {
	HighCwdContains []string
	HighCwd         []string
}

type Provider

type Provider struct {
	Type  string
	Fixed bool // fixed capacity: slots, no API key (providers delta C.3)
	// CleanupOnly: jobs of this type are refused in this release (sprites); a cleanup (sweep,
	// doctor --remote) may only list, owner-check and delete its resources, through the type's
	// provider.Factory.NewCleaner, never New.
	CleanupOnly  bool
	NamePrefix   string
	APIKey       string // never printed
	APIKeyFile   string
	DailyUSD     Micros
	MaxLive      int
	LaunchWait   time.Duration
	StartTimeout time.Duration
	Breaker      Breaker
	Transport    Transport
	Agent        Agent
	Artifacts    ArtifactLimits
	// FallbackUntil is the effective fallback boundary, "resource" or "attach" (spec 8.2): the
	// host key fallback_until, never later than the type's declaration (FallbackCap).
	FallbackUntil string
	FallbackCap   string
	// SendEnv is the effective caller-env level, "none", "forwarded" or "forced" (providers delta
	// S.2); SendEnvSource is "default" or "host". MultiJob: the type's resources serve more than
	// one job (S.4).
	SendEnv       string
	SendEnvSource string
	MultiJob      bool
	Raw           map[string]any // provider-specific keys, decoded by the provider (8.5)
	Endpoints     []string       // hosts the provider talks to (8.1), for the [test] gate
	// Plugin is set for a plugin type (spec 8.5, providers delta A.2): the pinned executable.
	// Sizes then holds the required host price per size (A.7.1) and SizesRaw the sizes table as
	// decoded, both passed to the plugin's configure.
	Plugin   *PluginPin
	Sizes    map[string]Micros
	SizesRaw map[string]any
}

type ProviderType

type ProviderType struct {
	Endpoints func(raw map[string]any) ([]string, error)
	TestOnly  bool // accepted only with a [test] table (the fake provider)
	// FallbackCap is the latest fallback boundary the type declares ("resource" or "attach", spec
	// 8.2) for these provider-specific keys; nil means "resource".
	FallbackCap func(raw map[string]any) string
	// DefaultResource: fallback_until defaults to "resource" whatever FallbackCap says (a plugin
	// is trusted to attach only after the host opts in, spec 8.2).
	DefaultResource bool
	// SendEnv is the type's default caller-env level for these provider-specific keys ("none",
	// "forwarded" or "forced"); nil means "forwarded" (a plugin). MultiJob reports whether its
	// resources serve more than one job (providers delta S.4); nil means false.
	SendEnv  func(raw map[string]any) string
	MultiJob func(raw map[string]any) bool
	// Validate checks the provider-specific keys once the core keys are decoded; each message is
	// the text after `providers.<type>.` (a 78 at load).
	Validate func(core *Provider) []string
	// Fixed: a fixed-capacity type (ssh, providers delta C.3). It has no API key, daily_usd is
	// the type's own rule (Validate), and max_live defaults to MaxLiveDefault of its keys.
	Fixed          bool
	MaxLiveDefault func(raw map[string]any) int
}

ProviderType is what core needs from a provider before M2: its endpoints, for the [test] gate. Provider packages register their types from init.

type RefuseRule

type RefuseRule struct {
	Tool             string
	When             string // "always" | "repo-wide"
	UnlessArgs       []string
	SkipOptionValues []string
	NpmScript        []string
	ArgvPrefix       []string
	Reason           string
}

type RemoteLimits

type RemoteLimits struct {
	Worktrees       []string
	ForwardEnvAllow []string
	ForwardEnvForce []string
	OnFailure       string // "next" | "stop"
}

type RepoGrant

type RepoGrant struct {
	Match         string
	Config        string
	CloneURL      string
	DeploySecret  string
	DeployKeyFile string // ~ expanded; a 0600 file owned by the user (checked at load; may not exist yet)
	RootSteps     bool
}

type RepoRemote

type RepoRemote struct {
	ForwardEnv    []string
	ForbidIgnored []string
	AllowIgnored  []string
	Env           map[string]Template
	EnvUnset      []string
	Packages      []string
	Tools         []Tool
	Setup         []Step
	Services      []Service
}

type RunFlags

type RunFlags struct {
	Wait      string         // --wait raw value, "" if absent
	Timeout   string         // --timeout raw value, "" if absent
	Local     bool           // --local
	Provider  string         // --provider P
	Artifacts *[]string      // --artifacts a,b (nil if absent)
	Units     map[string]int // --units G=K, group canonical (nil if absent)
}

RunFlags are the narrowing flags of `bitc run` (spec 3.1, 5.3).

type Service

type Service struct {
	Name         string
	RunAs        string
	Argv         []string
	Ready        []string
	ReadyTimeout time.Duration
}

type Size

type Size int64

Size is a byte count ("<int><KiB|MiB|GiB|TiB>").

func ParseSize

func ParseSize(s string) (Size, error)

ParseSize accepts <int><KiB|MiB|GiB|TiB> (spec 5.2).

func (Size) String

func (s Size) String() string

String prints the size in the largest unit that divides it exactly.

type Step

type Step struct {
	Name  string
	RunAs string // "root" | "job"
	Argv  []string
}

type Template

type Template struct{ Raw string }

Template is a string with {name} substitutions (spec 5.7).

func (Template) Expand

func (t Template) Expand(v Vars) (string, error)

Expand substitutes vars. Remote-only variables are an error here (the agent expands them).

func (Template) Names

func (t Template) Names() ([]string, error)

Names lists every variable a template uses, in order (the right side of arithmetic too).

type Test

type Test struct {
	ProcfsRoot    string
	TimeScale     float64 // (0, 1]; 0 means 1
	HTTPResults   bool
	AgentURL      string
	AccountingDir string
	// FixedSecrets makes the job's B, K and M fixed values (see remote.jobSecrets), so a suite that
	// cannot see them in the clear can still look for them in what a plugin or fake recorded.
	FixedSecrets bool
	// SSHExec = "local" makes the ssh provider run the executable SSHGate (with SSHRoot as the
	// fake host's state) instead of the system ssh client (providers delta C.11, sshfake).
	SSHExec, SSHGate, SSHRoot string
	// SSHSshd names the program doctor runs in place of `sshd -T` for the tunnel account check
	// (providers delta C.6.3), so a test needs no root and no sshd.
	SSHSshd string
	// AllowSprites: [test] allow_sprites, the sprites refusal's test-only bypass (spritesRefused).
	AllowSprites bool
}

type Tool

type Tool struct{ Name, Arch, URL, SHA256 string }

Tool is a sha256-pinned download; Arch is "amd64" or "arm64" (default "amd64").

type Transport

type Transport struct {
	Remote     string
	RefPrefix  string
	KnownHosts string // OpenSSH known_hosts text
	// Kind is TransportGitPush (the default) or TransportUpload (ssh only: the commit goes to
	// the host as a git bundle on the gate session). MaxBundle bounds that bundle.
	Kind      string
	MaxBundle Size
}

type Vars

type Vars map[string]string

Vars are the values templates may use; integer vars are decimal strings.

type WrapRule

type WrapRule struct {
	WhenWorktree string // glob
	Argv         []Template
}

Directories

Path Synopsis
Command gen prints the generated configuration reference.
Command gen prints the generated configuration reference.

Jump to

Keyboard shortcuts

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