config

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 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 URN sent with requests (set via hadron app use)",
	"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`",
}

Keys lists the settings hadron config get/set accepts.

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) 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