Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config loads graphmaster settings. Layers are applied in order defaults < user (~/.config/graphmaster/config.toml) < project (<root>/.graphmaster/config.toml) < environment (GRAPHMASTER_*); a later layer overrides only the keys it sets.

Index

Constants

View Source
const (
	EnvMode          = "GRAPHMASTER_MODE"
	EnvMaxFileSize   = "GRAPHMASTER_MAX_FILE_SIZE"
	EnvExcludes      = "GRAPHMASTER_EXCLUDES"       // replaces excludes
	EnvExtraExcludes = "GRAPHMASTER_EXTRA_EXCLUDES" // appended to extra_excludes
	EnvLanguages     = "GRAPHMASTER_LANGUAGES"
	EnvSoftBudget    = "GRAPHMASTER_SOFT_BUDGET"
	// EnvTimeoutPrefix + upper-cased timeout key, e.g. GRAPHMASTER_TIMEOUT_PRE_TOOL_USE.
	EnvTimeoutPrefix = "GRAPHMASTER_TIMEOUT_"
)

Environment variables. Lists are comma-separated.

Variables

This section is empty.

Functions

func ProjectConfigPath

func ProjectConfigPath(root string) string

ProjectConfigPath returns <root>/.graphmaster/config.toml.

func UserConfigPath

func UserConfigPath(lookup func(string) (string, bool)) (string, error)

UserConfigPath returns $XDG_CONFIG_HOME/graphmaster/config.toml, or $HOME/.config/graphmaster/config.toml. A relative XDG_CONFIG_HOME is ignored, as the XDG spec requires.

Types

type ByteSize

type ByteSize int64

ByteSize is a size in bytes. In TOML it is either an integer or a string with a unit: B, KB/MB/GB/TB (powers of 1000) or KiB/MiB/GiB/TiB (powers of 1024), case-insensitive.

func (ByteSize) MarshalText

func (b ByteSize) MarshalText() ([]byte, error)

MarshalText renders exact binary multiples with a unit, else plain bytes.

func (*ByteSize) UnmarshalText

func (b *ByteSize) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Config

type Config struct {
	Mode        Mode     `toml:"mode"`
	MaxFileSize ByteSize `toml:"max_file_size"`
	// Excludes replaces the default exclude list (gitignore syntax).
	Excludes []string `toml:"excludes"`
	// ExtraExcludes accumulates across layers on top of Excludes.
	ExtraExcludes []string `toml:"extra_excludes"`
	// Languages lists enabled language names; empty means all.
	Languages  []string `toml:"languages"`
	SoftBudget int      `toml:"soft_budget"` // balanced-mode denies per (session, agent)
	Timeouts   Timeouts `toml:"timeouts"`

	// Sources lists the layers that contributed (file paths and/or "env").
	Sources []string `toml:"-"`
	// Warnings collects non-fatal problems such as unknown keys.
	Warnings []string `toml:"-"`
}

Config is the effective configuration.

func Default

func Default() *Config

Default returns the built-in configuration.

func Load

func Load(root string) (*Config, error)

Load loads the configuration for the repository at root using the real environment. On error callers should fall back to Default (fail-open).

func LoadWith

func LoadWith(opts Options) (*Config, error)

LoadWith loads defaults < user < project < env per opts.

func (*Config) AllExcludes

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

AllExcludes returns Excludes followed by ExtraExcludes, deduplicated.

func (*Config) EnabledLangs

func (c *Config) EnabledLangs() []model.Lang

EnabledLangs returns the enabled languages in model order. Unknown names are skipped (Validate reports them).

func (*Config) LangEnabled

func (c *Config) LangEnabled(l model.Lang) bool

LangEnabled reports whether l is enabled.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks semantic constraints.

type Duration

type Duration time.Duration

Duration is a time.Duration that (un)marshals as a Go duration string such as "1.5s" or "750ms".

func (Duration) D

func (d Duration) D() time.Duration

D returns the value as a time.Duration.

func (Duration) MarshalText

func (d Duration) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (*Duration) UnmarshalText

func (d *Duration) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Mode

type Mode string

Mode is the steering mode.

const (
	ModeStrict   Mode = "strict"   // deny every code-scoped grep/glob
	ModeBalanced Mode = "balanced" // deny first symbol-like grep, then allow
	ModeOff      Mode = "off"      // never steer
)

Steering modes.

func ParseMode

func ParseMode(s string) (Mode, error)

ParseMode parses a mode name case-insensitively.

func (*Mode) UnmarshalText

func (m *Mode) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler with validation.

type Options

type Options struct {
	// Root is the repository root; "" skips the project layer.
	Root string
	// UserPath overrides the user config file location.
	UserPath string
	// LookupEnv defaults to os.LookupEnv.
	LookupEnv func(string) (string, bool)
}

Options controls Load. Zero values use the real environment.

type Timeouts

type Timeouts struct {
	MCP           Duration `toml:"mcp"`
	PreToolUse    Duration `toml:"pre_tool_use"`
	PostToolUse   Duration `toml:"post_tool_use"`
	SessionStart  Duration `toml:"session_start"`
	SubagentStart Duration `toml:"subagent_start"`
	PreCompact    Duration `toml:"pre_compact"`
}

Timeouts are freshness lock-wait budgets per caller: how long a caller waits for the index writer before answering from the current (stale) graph with a banner.

func (Timeouts) ForEvent

func (t Timeouts) ForEvent(e hookapi.Event) time.Duration

ForEvent returns the budget for a hook event. Events without a budget (e.g. Stop) return 0: they never wait for the writer.

Jump to

Keyboard shortcuts

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