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

config

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config reads and writes ~/.config/hadron/config.toml.

Index

Constants

View Source
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

View Source
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

func AuthFile() (string, error)

AuthFile returns the path of the fallback token file used when no OS keychain is available.

func Dir

func Dir() (string, error)

Dir returns the hadron config directory: $XDG_CONFIG_HOME/hadron, defaulting to ~/.config/hadron (gh-style, on every platform).

func EnsureDir

func EnsureDir() (string, error)

EnsureDir creates the config directory with owner-only permissions.

func File

func File() (string, error)

File returns the path of the main config file.

func WithLock added in v0.6.0

func WithLock(fn func() error) error

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

func WriteFileAtomic(path string, data []byte, perm os.FileMode) error

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 Load

func Load() (*Config, error)

Load reads the config file if it exists; a missing file yields an all-defaults config.

func (*Config) All

func (c *Config) All() map[string]string

All returns every known key with its effective value.

func (*Config) App

func (c *Config) App() string

App returns the default App URN, or "" for no App context.

func (*Config) Get

func (c *Config) Get(key string) (string, error)

Get returns a known key's value.

func (*Config) Memory added in v0.3.0

func (c *Config) Memory() string

Memory returns the default memory URN or ID, or "" for no memory context.

func (*Config) Org added in v0.14.0

func (c *Config) Org() string

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

func (c *Config) Scope() string

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

func (c *Config) Server() string

Server returns the configured server base URL, with the HADRON_SERVER environment variable taking precedence.

func (*Config) Set

func (c *Config) Set(key, value string) error

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

func (c *Config) SpecMemory() string

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.

func (*Config) Unset

func (c *Config) Unset(key string) error

Unset removes a key and persists the file (locked + fresh-read, as Set).

Jump to

Keyboard shortcuts

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