Documentation
¶
Index ¶
- Constants
- func BaseConfigExists(baseDir string) (bool, error)
- func Bootstrap(baseDir string) error
- func ConfigGet(s *Settings, key string) (string, bool)
- func ConfigSet(s *Settings, key, val string) error
- func DefaultBaseDir() (string, error)
- func Migrate(baseDir string) (applied bool, err error)
- func MigrationStatus(s *Settings) (current, latest int, stale bool)
- func Save(baseDir string, s *Settings) error
- func Update(baseDir string, mutate func(*Settings) error) error
- func WithLock(baseDir string, fn func() error) error
- func WriteDockerfile(baseDir string) error
- type ConfigEntry
- type Settings
- type Workspace
Constants ¶
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 )
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 ¶
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 ¶
Bootstrap is idempotent: creates the agent directories and seed files under baseDir, never overwriting existing content. settings.json is not touched.
func ConfigSet ¶
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 Migrate ¶
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 ¶
MigrationStatus returns s.Version, the latest ConfigVersion, and whether the config is stale (current < latest).
func Save ¶
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
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 WriteDockerfile ¶ added in v0.0.4
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 ¶
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.