config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SettingsFile   = "settings.json"
	WorkspacesDir  = "workspaces"
	DockerfileFile = "Dockerfile"

	// ConfigVersion is the single version governing both the settings schema and the
	// one-shot ~/.makeslop asset refresh. Bump when the embedded assets OR the Settings
	// shape change; `migrate` re-runs all idempotent steps and re-stamps.
	ConfigVersion = 1
)
View Source
const (
	DefaultImage      = "claudebox"
	DefaultShell      = "/bin/zsh"
	DefaultTmpDirSize = "100m"
)

omitempty + Load-time defaulting keeps pre-existing files byte-stable until a user overrides.

Variables

This section is empty.

Functions

func BaseConfigExists

func BaseConfigExists(baseDir string) (bool, error)

BaseConfigExists reports whether <baseDir>/settings.json exists. Returns (false, nil) when absent and (false, err) for any other stat failure, so callers can distinguish "not initialised" from "unreadable".

func Bootstrap

func Bootstrap(baseDir string) error

Bootstrap is idempotent: creates the agent directories and seed files under baseDir, never overwriting existing content. settings.json is not touched.

func ConfigGet

func ConfigGet(s *Settings, key string) (string, bool)

ConfigGet returns the stored value for key, or ("", false) for unknown keys.

func ConfigSet

func ConfigSet(s *Settings, key, val string) error

ConfigSet validates and applies a key=value update to s. Returns an error for unknown keys or invalid values; s is not mutated on error.

func DefaultBaseDir

func DefaultBaseDir() (string, error)

func Migrate

func Migrate(baseDir string) (applied bool, err error)

Migrate runs all migration steps when Version differs from ConfigVersion, returning (true, nil) when applied and (false, nil) when already up to date.

The Load→stamp→Save sequence is protected by WithLock so a concurrent init or config set cannot lose the Version stamp. The steps themselves run outside the lock because they are idempotent and don't touch settings.json.

func MigrationStatus

func MigrationStatus(s *Settings) (current, latest int, stale bool)

MigrationStatus returns s.Version, the latest ConfigVersion, and whether the config is stale (current < latest).

func Save

func Save(baseDir string, s *Settings) error

Save atomically writes settings via temp-file + intra-dir rename so a crash mid-write cannot leave a half-written settings.json behind.

func Update added in v0.1.0

func Update(baseDir string, mutate func(*Settings) error) error

WithLock calls fn while holding an exclusive advisory lock on <baseDir>/.settings.lock, releasing it (and closing the fd) when fn returns.

Two-level: inProcessMu serializes goroutines (flock doesn't on Linux); a POSIX flock(LOCK_EX) guards against separate processes (e.g. two concurrent `makeslop init` shells).

NO-NESTING INVARIANT: WithLock MUST NOT be nested — a nested call in the same goroutine self-deadlocks on inProcessMu. Each Load→mutate→Save site acquires its own short-lived lock sequentially. Update runs a locked Load→mutate→Save read-modify-write on settings.json. When mutate returns an error the save is skipped and the error is returned verbatim. The WithLock no-nesting invariant applies to mutate too.

func WithLock added in v0.0.4

func WithLock(baseDir string, fn func() error) error

func WriteDockerfile added in v0.0.4

func WriteDockerfile(baseDir string) error

WriteDockerfile atomically writes the embedded assets.Dockerfile to <baseDir>/Dockerfile, always overwriting any existing file (temp-file+rename). Also called by `build --refresh` to reset a hand-edited Dockerfile without running a migration or touching the Version stamp.

Types

type ConfigEntry

type ConfigEntry struct {
	Name  string
	Value string
}

ConfigEntry is a key/value pair returned by ConfigList.

func ConfigList

func ConfigList(s *Settings) []ConfigEntry

ConfigList returns the current value of every settable key in registry order.

type Settings

type Settings struct {
	Version    int                  `json:"version"`
	Image      string               `json:"image,omitempty"`
	Shell      string               `json:"shell,omitempty"`
	TmpDirSize string               `json:"tmp_dir_size,omitempty"`
	Workspaces map[string]Workspace `json:"workspaces"`
}

Settings is the persisted shape of <baseDir>/settings.json. Workspaces is keyed by absolute, symlink-evaluated workspace root paths.

func Load

func Load(baseDir string) (*Settings, error)

Load reads <baseDir>/settings.json. A missing file yields default Settings (not an error); malformed JSON is an error. Empty Image/Shell/TmpDirSize default for backward compatibility.

type Workspace

type Workspace struct {
	Name      string    `json:"name"`
	CreatedAt time.Time `json:"created_at"`
}

Jump to

Keyboard shortcuts

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