Documentation
¶
Overview ¶
Package config reads and writes ~/.config/hadron/config.toml.
Index ¶
- Constants
- Variables
- func AuthFile() (string, error)
- func Dir() (string, error)
- func EnsureDir() (string, error)
- func File() (string, error)
- func WithLock(fn func() error) error
- func WriteFileAtomic(path string, data []byte, perm os.FileMode) error
- type Config
- func (c *Config) All() map[string]string
- func (c *Config) App() string
- func (c *Config) Get(key string) (string, error)
- func (c *Config) Memory() string
- func (c *Config) Org() string
- func (c *Config) Scope() string
- func (c *Config) Server() string
- func (c *Config) Set(key, value string) error
- func (c *Config) SpecMemory() string
- func (c *Config) Unset(key string) error
Constants ¶
const DefaultServer = "https://srv.hadronmemory.com"
DefaultServer is the hosted Hadron platform's API server (the GraphQL + OAuth host; hadronmemory.com itself is the portal).
Variables ¶
var Keys = map[string]string{
"server": "Hadron server base URL",
"app": "default App sent with requests — an App id or hrn:app:<root>:<slug> (set via hadron app set-active)",
"memory": "default memory URN or ID (set via hadron memory set-active)",
"spec_memory": "default memory for spec commands (set via hadron spec use); overrides the global memory for `hadron spec`",
"org": "active organization — an organization root, URN or id (set via hadron org use, which verifies membership; `config set` does not); what `--scope global` resolves against",
"scope": "default search scope — a scope name, id, `app` or `global` (set via hadron scope use, which verifies it resolves; `config set` does not); applied when `hadron search` is run without --scope",
}
Keys lists the settings hadron config get/set accepts.
It is also the ALLOW-LIST for `hadron config set`, which is a generic key-value writer and performs no per-key validation. Several keys have a dedicated setter that does — `org use` checks membership, `scope use` checks the value resolves, `app set-active` shape-checks the ref — so `config set` is deliberately the UNVERIFIED path for all of them (@copilot, #597).
That is a choice, not an oversight: routing the generic setter through each key's resolver would give one command a dozen different failure modes and a network dependency, and would remove the only way to fix a config offline. The per-key descriptions say which setter verifies what, so the trade is visible where a reader meets it.
Functions ¶
func AuthFile ¶
AuthFile returns the path of the fallback token file used when no OS keychain is available.
func Dir ¶
Dir returns the hadron config directory: $XDG_CONFIG_HOME/hadron, defaulting to ~/.config/hadron (gh-style, on every platform).
func WithLock ¶ added in v0.6.0
WithLock runs fn while holding an exclusive advisory lock on the config directory, serializing the whole read-modify-write across concurrent `hadron` processes (AI agents shell out in parallel). The OS releases the lock when the process exits, so a crash never leaves a stale lock. The lock file is separate from the data files it guards.
func WriteFileAtomic ¶ added in v0.6.0
WriteFileAtomic writes data to path atomically and with exactly perm, replacing any existing file. It refuses to write through a symlink, and installs a fresh file via a same-dir temp + rename — so a crash mid-write never truncates the target (the reader sees either the old or the new complete file, never an empty/partial one), and a pre-existing loose-mode file is replaced by one at perm rather than left group/world-readable (#117, #118).
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func (*Config) Memory ¶ added in v0.3.0
Memory returns the default memory URN or ID, or "" for no memory context.
func (*Config) Org ¶ added in v0.14.0
Org returns the active organization ref, or "" for none.
Not shape-checked on read. An organization is addressed by its root (acme.com), its URN or its id, and the server resolves all three — there is no client-side grammar here to enforce, and inventing one would reject refs the server accepts.
func (*Config) Scope ¶ added in v0.14.0
Scope returns the default search scope, or "" for none.
A search that applies this instead of the caller's flag MUST say so: it changes what a flagless `hadron search` returns, and a narrowing the reader did not ask for and cannot see is indistinguishable from missing data.
func (*Config) Server ¶
Server returns the configured server base URL, with the HADRON_SERVER environment variable taking precedence.
func (*Config) Set ¶
Set updates a known key and persists the file with 0600 perms. The whole reload→mutate→write runs under the config-dir lock and re-reads the file fresh, so a concurrent writer changing a different key isn't clobbered (#118).
func (*Config) SpecMemory ¶ added in v0.7.0
SpecMemory returns the default memory for `hadron spec` commands, with the HADRON_SPEC_MEMORY environment variable taking precedence over the spec_memory config key. Empty means no spec-specific default (callers then fall back to the global Memory()). The spec corpus is usually a fixed memory distinct from the global active memory, so it gets its own default.