config

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

README

config

Loom's on-disk configuration, app state, profile catalog and workspace registry, and the resolution of the directories that hold them.

Directories

  • The config dir defaults to ~/.loom; LOOM_HOME overrides it (absolute, ~ expanded), with CLAUDE_SQUAD_HOME still honoured with a deprecation warning. A registered workspace keeps its own config dir at <repo>/.loom/ (WorkspaceConfigDir, EnsureGitignore).
  • GetGlobalConfigDir returns LOOM_GLOBAL_DIR when set, else ~/.loom, regardless of LOOM_HOME: it holds workspaces.json, the global workspace's context (GlobalWorkspaceContext()), the account registry and the daemon's lock, socket fallback and logs.
  • WorkspaceContext carries the resolved config dir for one workspace through the code, instead of globals (ResolveWorkspace, WorkspaceContextFor).
  • LoadConfigFrom("")/LoadStateFrom("") accept an empty string as "use the default directory".
  • config/migration.go:MigrateLegacyHome handles the one-time ~/.claude-squad → ~/.loom rename.

Files

  • settings.go — Settings, the plain struct of every persisted field and its getters, and Clone, FromSettings, Snapshot, ReplaceSettings.
  • config.go — Config (embeds Settings beside the mutex that guards a shared Config; JSON flattens the embedded struct), Mutate, the locked getters, DefaultConfig, LoadConfigFrom, SaveConfigTo (marshals under the read lock), and the cycle lists ClaudePermissionModes, ClaudeModels (ClaudeModel: an alias and its Supports1M), ClaudeEfforts.
  • state.go — State (with its own mutex), UIPrefs, LoadStateFrom, SaveStateTo, and the interfaces InstanceStorage, AppState, StateManager. A save is skipped when nothing changed.
  • workspace.go — WorkspaceRegistry (no mutex: its writes go through the model), WorkspaceContext, GetGlobalConfigDir.
  • atomic.go, quarantine.go — AtomicWriteFile (temp file and rename) and the quarantine that moves a file that fails to parse aside rather than overwrite it.

config.json

User configuration, written only by the model (core.Model.SaveSettings; the settings overlay edits a copy). The getters are the truth for defaults:

  • DefaultProgram (GetProgram); Profiles, named program presets (GetProfiles).
  • BranchPrefix (default {username}/; GetBranchPrefix). Overridable per session from the Session Launch Options modal: launch.Options.BranchPrefix → Instance.SetBranchPrefix → git.WorktreeSpec.BranchPrefix, an ephemeral override that is never persisted.
  • BaseBranch (default empty, Config.GetBaseBranch()): the branch new worktrees are cut from; empty auto-detects via git.ResolveBaseCommit (origin/HEAD → main → master → current HEAD).
  • Theme ("afterglow" default, "legacy"; empty means default, Config.GetTheme()), cycled live from the settings overlay's Theme row.
  • ClaudeTmpArchiveDir (claude_tmp_archive_dir), read from the global config.json only: empty keeps each workspace's Claude temp-dir archives in its own config folder; set, every workspace's go under it in a subfolder per config dir (session.ClaudeTmpArchiveDir). Read via Config.ClaudeTmpArchiveRoot(), which expands ~ and rejects a relative path.
  • ClaudeRemoteControl (*bool, default on): launches Claude sessions with --remote-control <title>; nil is enabled (Config.RemoteControlEnabled()).
  • ClaudePermissionMode (*string, default "default"): launches Claude sessions with --permission-mode <mode>; nil is "default", which injects no flag (Config.PermissionMode()). Valid values are config.ClaudePermissionModes, cycled from the Claude Preferences overlay.
  • Claude1MContext (*bool, default off): appends Claude's [1m] long-context suffix to the launched --model alias, e.g. sonnet[1m]; a no-op for default, haiku and any alias whose config.ClaudeModel.Supports1M is false (Config.Context1MEnabled()). The composed value is single-quoted, because tmux runs the program string through a shell and [/] are zsh glob metacharacters.
  • ClaudeSubagentTracking (*bool, default on): shows the subagents and teammates loom's hooks track; every Claude launch gets the hooks regardless. Nil is enabled (Config.SubagentTrackingEnabled()), toggled from the Claude Preferences overlay's Track Subagents row.
  • ClaudeLoomContext (LoomContextEnabled), HeadroomProxy (HeadroomProxyEnabled), ClaudeModel (Model), ClaudeEffort (Effort) and CacheTTL1h (CacheTTL1hEnabled): the other Claude launch defaults the Session Launch Options modal starts from.

state.json

App state, e.g. the help screens seen (HelpScreensSeen), the serialized instances array (owned by session's storage), and the ui prefs block (config.UIPrefs): view_mode, rail_hidden, terminal_hidden, split_ratios (a per-session-title map of agent/terminal split ratios, written throttled on ctrl+up/ctrl+down resizes) and workbench_ratios (the workbench's agent/panel split, per session).

workspaces.json

In the global dir: the registered workspaces (name, path, added_at), last_used, and the open list (open_workspaces). Every write rereads the file first, so another process's change survives.

Tests

Unlike every other package's, this package's TestMain (config/config_test.go) leaves the loom dir variables unset and points HOME at a throwaway, because the tests exercise default resolution itself.

Documentation

Overview

Package config owns Loom's on-disk configuration, app state, profile catalog, and workspace registry.

The root config directory defaults to ~/.loom (overridable via $LOOM_HOME). WorkspaceContext carries the resolved directory for a given invocation and is threaded through the app rather than relying on globals, so per-workspace configs at <repo>/.loom/ can coexist with the global config. LoadConfigFrom/LoadStateFrom accept an empty path to mean "use the default directory."

MigrateLegacyHome performs the one-shot rename from ~/.claude-squad to ~/.loom that covers users upgrading across the rebrand; it is idempotent and safe to call on every startup.

Index

Constants

View Source
const (
	StateFileName     = "state.json"
	InstancesFileName = "instances.json"
)

StateFileName is the on-disk filename for ephemeral app state (help-screen-seen flags, etc.). InstancesFileName stores the serialized session list. Both are resolved relative to the config directory.

View Source
const (
	ConfigFileName = "config.json"
)

ConfigFileName is the on-disk filename of the Loom user config, resolved relative to the config directory (LOOM_HOME or ~/.loom).

View Source
const EnvGlobalDir = "LOOM_GLOBAL_DIR"

EnvGlobalDir overrides the directory GetGlobalConfigDir returns — the home of workspaces.json and of the global workspace context. Deliberately separate from LOOM_HOME, which GetGlobalConfigDir ignores by design; the dev sandbox (internal/devsandbox) sets both.

View Source
const (
	EnvHome = "LOOM_HOME"
)

EnvHome names the override env var for the application's config directory. Legacy CLAUDE_SQUAD_HOME is honored as a deprecated fallback with a one-time warning so shell configs continue working across the rename from claude-squad to loom.

Variables

View Source
var ClaudeEfforts = []string{"default", "low", "medium", "high", "xhigh", "max"}

ClaudeEfforts lists the --effort values the Claude Preferences and Session Launch Options screens cycle through, matching what `claude --help` documents for --effort.

View Source
var ClaudeModels = []ClaudeModel{
	{"default", false},
	{"sonnet", true},
	{"opus", true},
	{"fable", true},
	{"haiku", false},
}

ClaudeModels lists the --model aliases the Claude Preferences and Session Launch Options screens cycle through. Short aliases, not versioned IDs, so this list doesn't need updating when new Claude models ship.

View Source
var ClaudePermissionModes = []string{"default", "acceptEdits", "plan", "auto", "dontAsk", "bypassPermissions"}

ClaudePermissionModes lists the values --permission-mode accepts, in the order the Claude Preferences screen cycles through them.

Functions

func AtomicWriteFile

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

AtomicWriteFile writes data to path via a temp file in the same directory, fsyncs it, and renames it into place. This guarantees readers see either the old contents or the new contents, never a truncated or empty file.

The temp file is created with O_EXCL so concurrent writers don't share it. If the write or rename fails, the temp file is removed and the original file is left untouched.

After rename we also fsync the parent directory so the directory entry update is durable; without it a power loss between rename and the next filesystem commit can leave the old contents (or, on data=writeback mode, an empty file) visible after reboot. Best-effort — silently a no-op on filesystems/platforms (e.g. Windows) that don't support directory fsync.

func ClaudeModelAliases added in v0.13.0

func ClaudeModelAliases() []string

ClaudeModelAliases returns just the aliases, in cycle order. The overlays cycle with nextInList, which stays []string-shaped so the permission-mode and effort lists keep sharing it unchanged.

func ClaudeModelSupports1M added in v0.13.0

func ClaudeModelSupports1M(alias string) bool

ClaudeModelSupports1M reports whether alias accepts the [1m] long-context suffix. An unknown alias reports false: declining to append is a silent no-op, whereas appending to a model that rejects it kills the pane at launch.

func EnsureGitignore

func EnsureGitignore(repoPath string) error

EnsureGitignore ensures .loom/ is listed in the repo's .gitignore. Writes atomically via AtomicWriteFile so a crash or a concurrent call can't leave a half-written entry behind. An O_APPEND-based write would issue two syscalls (newline fixup, then entry), and racing callers each saw an absent entry and each appended their own copy.

func GetClaudeCommand

func GetClaudeCommand() (string, error)

GetClaudeCommand attempts to find the "claude" command in the user's shell It checks in the following order: 1. Shell alias resolution: using "which" command 2. PATH lookup

If both fail, it returns an error.

func GetConfigDir

func GetConfigDir() (string, error)

GetConfigDir returns the path to the application's configuration directory. If LOOM_HOME is set, that value is used directly as the config directory. CLAUDE_SQUAD_HOME is honored as a deprecated fallback with a one-time warning. The value must be an absolute path (after ~ expansion). Falls back to ~/.loom otherwise.

func GetGlobalConfigDir

func GetGlobalConfigDir() (string, error)

GetGlobalConfigDir returns $LOOM_GLOBAL_DIR when set, otherwise ~/.loom/ — regardless of LOOM_HOME.

func MigrateLegacyHome

func MigrateLegacyHome() error

MigrateLegacyHome performs a one-time rename of the legacy config directory (~/.claude-squad) to its new location (~/.loom) so that in-flight instances, worktrees, and scripts survive the rename.

Behavior:

  • If ~/.loom already exists, return (idempotent; nothing to do).
  • If ~/.claude-squad is absent, return (fresh install).
  • Otherwise os.Rename the directory and print a one-line notice to stderr so the operator knows what happened.

When LOOM_HOME, CLAUDE_SQUAD_HOME, or LOOM_GLOBAL_DIR is set (i.e. the user has overridden the default path), migration is skipped — the user has explicitly chosen a location and is assumed to have already placed their state there.

Errors from os.Rename (e.g. cross-device) are returned; the caller should fall through to normal startup on failure since the legacy dir is still readable and GetConfigDir will honor CLAUDE_SQUAD_HOME as a deprecated fallback if the user points at it explicitly.

func SaveConfigTo

func SaveConfigTo(config *Config, dir string) error

SaveConfigTo saves the configuration to an explicit directory.

func SaveState

func SaveState(state *State) error

SaveState saves the state to disk

func SaveStateTo

func SaveStateTo(state *State, dir string) error

SaveStateTo saves state to an explicit directory.

func SaveWorkspaceRegistry

func SaveWorkspaceRegistry(reg *WorkspaceRegistry) error

SaveWorkspaceRegistry writes the workspace registry to the global config dir.

func WorkspaceConfigDir

func WorkspaceConfigDir(ws *Workspace) string

WorkspaceConfigDir returns the .loom directory inside the workspace repo.

Types

type AppState

type AppState interface {
	// GetHelpScreensSeen returns the bitmask of seen help screens
	GetHelpScreensSeen() uint32
	// SetHelpScreensSeen updates the bitmask of seen help screens
	SetHelpScreensSeen(seen uint32) error
	// GetUIPrefs returns a copy of the persisted UI layout prefs.
	GetUIPrefs() UIPrefs
	// SetUIPrefs replaces and persists the UI layout prefs.
	SetUIPrefs(p UIPrefs) error
}

AppState handles application-level state

type ClaudeModel added in v0.13.0

type ClaudeModel struct {
	Alias      string
	Supports1M bool
}

ClaudeModel pairs a --model alias with whether it accepts Claude Code's [1m] long-context suffix. The capability lives on the model rather than in a parallel list so the two can't drift; this mirrors how Claude Code itself models it (supports_1m_suffix is a field on the model, not a side table).

type Config

type Config struct {
	Settings
	// contains filtered or unexported fields
}

Config represents the application configuration: the persisted Settings and the lock that guards them once a Config is shared.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default configuration

func FromSettings added in v0.14.0

func FromSettings(s Settings) *Config

FromSettings builds a Config holding a copy of s: a new object with its own lock, for a caller that edits settings without touching anyone else's (the TUI's settings overlay).

func LoadConfig

func LoadConfig() *Config

LoadConfig loads configuration from the default config directory. It is a convenience wrapper around LoadConfigFrom(""). If the config file does not yet exist, a default config is written to disk.

func LoadConfigFrom

func LoadConfigFrom(dir string) *Config

LoadConfigFrom loads configuration from an explicit directory. Empty `dir` is a soft shim: a warning is logged and the global config directory is used. Per docs/specs/workspaces.md §3 internal callers must pass a resolved WorkspaceContext.ConfigDir.

func LoadConfigFromGlobal

func LoadConfigFromGlobal() *Config

LoadConfigFromGlobal loads configuration from the global (LOOM_HOME or ~/.loom) directory. Prefer this over LoadConfigFrom("") at call sites that truly want the global config — the explicit name prevents workspace-context leaks.

func (*Config) ClaudeTmpArchiveRoot added in v0.14.0

func (c *Config) ClaudeTmpArchiveRoot() (string, error)

ClaudeTmpArchiveRoot returns ClaudeTmpArchiveDir with a leading ~ expanded, or "" when it is unset. A value that is not absolute after expansion is an error: the caller keeps the default location rather than archive relative to whatever directory loom runs in.

func (*Config) GetBaseBranch added in v0.13.0

func (c *Config) GetBaseBranch() string

GetBaseBranch returns BaseBranch under a read lock. Locked rather than bare like PermissionMode because worktree setup reads it from a tea.Cmd goroutine (Instance.Start) while the settings overlay writes it from the main goroutine — the same race GetBranchPrefix closes.

func (*Config) GetBranchPrefix added in v0.3.0

func (c *Config) GetBranchPrefix() string

GetBranchPrefix returns BranchPrefix under a read lock. Use this instead of reading the field directly from any goroutine other than the one currently calling Mutate — in practice, scriptHost.BranchPrefix, which runs on the Lua dispatch goroutine.

func (*Config) GetTheme added in v0.13.0

func (c *Config) GetTheme() string

GetTheme returns the configured UI theme name under the config lock (the settings overlay mutates Config at runtime).

func (*Config) Mutate added in v0.3.0

func (c *Config) Mutate(fn func(*Config))

Mutate runs fn with the write lock held. Callers outside this package (the settings overlay) use this instead of writing exported fields directly, so a concurrent GetBranchPrefix cannot observe a torn write. fn must not call GetBranchPrefix or Mutate itself (would deadlock).

func (*Config) ReplaceSettings added in v0.14.0

func (c *Config) ReplaceSettings(s Settings)

ReplaceSettings replaces every setting with a copy of s, under the lock.

func (*Config) Snapshot added in v0.14.0

func (c *Config) Snapshot() Settings

Snapshot is a deep copy of the settings, taken under the lock.

type InstanceStorage

type InstanceStorage interface {
	// SaveInstances saves the raw instance data
	SaveInstances(instancesJSON json.RawMessage) error
	// GetInstances returns the raw instance data
	GetInstances() json.RawMessage
	// DeleteAllInstances removes all stored instances
	DeleteAllInstances() error
}

InstanceStorage handles instance-related operations

type Profile

type Profile struct {
	// Name is the short identifier shown in the profile picker. Must be
	// unique within a Config's Profiles list.
	Name string `json:"name"`
	// Program is the literal command string run when this profile is
	// selected (e.g. "aider --model gpt-4"). No templating is applied.
	Program string `json:"program"`
}

Profile is a named shortcut for a program invocation. Profiles let users store multiple agent configurations (e.g. "aider-gpt4", "claude-fast") and pick between them at session creation or by setting DefaultProgram to a profile's Name.

type Settings added in v0.14.0

type Settings struct {
	// DefaultProgram is the default program to run in new instances
	DefaultProgram string `json:"default_program"`
	// BranchPrefix is the prefix used for git branches created by the application.
	BranchPrefix string `json:"branch_prefix"`
	// BaseBranch names the branch new session worktrees are cut from.
	// Empty means auto-detect (origin/HEAD, then main, then master, then
	// whatever the root repo currently has checked out) — see
	// git.ResolveBaseCommit. DefaultConfig deliberately leaves it empty:
	// unlike BranchPrefix there is no sensible universal literal, and
	// auto-detect is correct for main/master/develop repos alike.
	// Read through GetBaseBranch.
	BaseBranch string `json:"base_branch,omitempty"`
	// Profiles is a list of named program profiles.
	Profiles []Profile `json:"profiles,omitempty"`
	// ClaudeRemoteControl controls whether new Claude sessions launch
	// with `--remote-control` (named after the session title). It is a
	// pointer so a config file predating this field (nil) is treated as
	// enabled rather than taking the bool zero value; only an explicit
	// false disables it. Read it through RemoteControlEnabled.
	ClaudeRemoteControl *bool `json:"claude_remote_control,omitempty"`
	// ClaudeLoomContext controls whether new Claude sessions launch with
	// --append-system-prompt-file pointing at loom's embedded context
	// file (see session.WriteLoomContextFiles). nil is treated as enabled
	// (read via LoomContextEnabled), matching ClaudeRemoteControl. A no-op
	// for agents other than Claude.
	ClaudeLoomContext *bool `json:"claude_loom_context,omitempty"`
	// ClaudeSubagentTracking controls whether the subagents and teammates
	// loom's hooks track are shown, as a count on rail cards and as rows
	// on overview cards (see session/subagent). Every Claude launch gets
	// the hooks regardless, since they also carry status, the session ID
	// and the last message. nil is treated as enabled (read via
	// SubagentTrackingEnabled), matching ClaudeLoomContext. Takes effect
	// at once.
	ClaudeSubagentTracking *bool `json:"claude_subagent_tracking,omitempty"`
	// ClaudePermissionMode is the --permission-mode value new Claude
	// sessions launch with. Unlike ClaudeRemoteControl, DefaultConfig
	// sets this explicitly to "default" rather than leaving it nil — nil
	// only occurs for a config.json predating this field, and is
	// treated identically to "default" (no flag injected; Claude's own
	// default applies). Read it through PermissionMode.
	ClaudePermissionMode *string `json:"claude_permission_mode,omitempty"`
	// Theme names the active UI color theme (see ui.ThemeNames).
	// Empty (pre-existing config files) means the default theme.
	// Read through GetTheme.
	Theme string `json:"theme,omitempty"`
	// ClaudeTmpArchiveDir relocates the zips loom archives Claude's
	// per-session temp dirs into (session.ClaudeTmpArchiveDir): every
	// workspace's archives go under it, each workspace in its own
	// subfolder. Read from the global config.json only. Empty (the
	// default) keeps each workspace's archives in its own loom config
	// folder. Absolute, or starting with ~. Read through
	// ClaudeTmpArchiveRoot.
	ClaudeTmpArchiveDir string `json:"claude_tmp_archive_dir,omitempty"`
	// HeadroomProxy controls whether new Claude sessions launch with
	// ANTHROPIC_BASE_URL pointed at Headroom's proxy (see
	// session.HeadroomProxyEnv). A no-op for agents other than Claude.
	// Loom does not start or manage the headroom proxy process itself —
	// the user is expected to have it running separately. Defaults to
	// off (DefaultConfig sets it explicitly to false) since it's
	// opt-in. Mutually exclusive with ClaudeRemoteControl: enabling one
	// disables the other, enforced in the Claude Preferences toggle
	// handler, the Session Launch Options modal, and defensively again
	// in launch.Compose so a hand-edited config.json with both
	// fields true still can't launch both at once. Read it through
	// HeadroomProxyEnabled.
	HeadroomProxy *bool `json:"headroom_proxy,omitempty"`
	// ClaudeModel is the --model value new Claude sessions launch with.
	// Values are short CLI aliases (not versioned IDs) so the list
	// stays valid as new models ship without a code change. "default"
	// is a no-op — Claude's own default applies. Read it through Model.
	ClaudeModel *string `json:"claude_model,omitempty"`
	// ClaudeEffort is the --effort value new Claude sessions launch
	// with. "default" is a no-op — Claude's own default applies. Read
	// it through Effort.
	ClaudeEffort *string `json:"claude_effort,omitempty"`
	// CacheTTL1h controls whether new Claude sessions launch with
	// ENABLE_PROMPT_CACHING_1H=1 (see session.CacheTTL1hEnv), extending
	// Claude's prompt cache from the default 5-minute TTL to 1 hour. A
	// no-op for agents other than Claude. Defaults to off (DefaultConfig
	// sets it explicitly to false) since it's opt-in. Read it through
	// CacheTTL1hEnabled.
	CacheTTL1h *bool `json:"cache_ttl_1h,omitempty"`
	// Claude1MContext controls whether new Claude sessions launch with
	// the [1m] long-context suffix appended to their --model alias
	// (e.g. "sonnet[1m]"). A no-op for agents other than Claude, and
	// for aliases that don't accept the suffix (see
	// ClaudeModelSupports1M). Defaults to off (DefaultConfig sets it
	// explicitly to false) since it's opt-in. Read it through
	// Context1MEnabled.
	Claude1MContext *bool `json:"claude_1m_context,omitempty"`
}

Settings is config.json's content: every persisted field, with the getters that read them. A plain value: the model hands copies of it across the boundary (core.WorkspaceView.Settings), and the TUI's settings overlay edits its own Config built from one (FromSettings). Config embeds it beside the mutex that guards the live, shared copy; JSON flattens the embedded struct, so config.json's format is the one Config always had.

func (Settings) CacheTTL1hEnabled added in v0.14.0

func (s Settings) CacheTTL1hEnabled() bool

CacheTTL1hEnabled reports whether new Claude sessions should launch with ENABLE_PROMPT_CACHING_1H=1. Defaults to false when unset.

func (Settings) ClaudeTmpArchiveRoot added in v0.14.0

func (s Settings) ClaudeTmpArchiveRoot() (string, error)

ClaudeTmpArchiveRoot returns ClaudeTmpArchiveDir with a leading ~ expanded, or "" when it is unset. A value that is not absolute after expansion is an error: the caller keeps the default location rather than archive relative to whatever directory loom runs in.

func (Settings) Clone added in v0.14.0

func (s Settings) Clone() Settings

Clone deep-copies s: Profiles and every pointer field are its own.

func (Settings) Context1MEnabled added in v0.14.0

func (s Settings) Context1MEnabled() bool

Context1MEnabled reports whether new Claude sessions should launch with the [1m] long-context suffix on their --model alias. Defaults to false when unset. Unlocked for the same reason as PermissionMode.

func (Settings) Effort added in v0.14.0

func (s Settings) Effort() string

Effort returns the configured --effort value, defaulting to "default" when unset. Unlocked for the same reason as PermissionMode/Model.

func (Settings) GetBaseBranch added in v0.14.0

func (s Settings) GetBaseBranch() string

GetBaseBranch returns BaseBranch (see Config.GetBaseBranch).

func (Settings) GetBranchPrefix added in v0.14.0

func (s Settings) GetBranchPrefix() string

GetBranchPrefix returns BranchPrefix. Config's own GetBranchPrefix reads it under the lock.

func (Settings) GetProfiles added in v0.14.0

func (s Settings) GetProfiles() []Profile

GetProfiles returns a unified list of profiles. If Profiles is defined, those are returned with the default profile first. Otherwise, a single profile is synthesized from DefaultProgram.

func (Settings) GetProgram added in v0.14.0

func (s Settings) GetProgram() string

GetProgram returns the program to run. If Profiles is non-empty and DefaultProgram matches a profile name, that profile's Program is returned. Otherwise DefaultProgram is returned as-is.

func (Settings) GetTheme added in v0.14.0

func (s Settings) GetTheme() string

GetTheme returns the configured UI theme name (see Config.GetTheme).

func (Settings) HeadroomProxyEnabled added in v0.14.0

func (s Settings) HeadroomProxyEnabled() bool

HeadroomProxyEnabled reports whether new Claude sessions should launch with ANTHROPIC_BASE_URL pointed at Headroom's proxy. Defaults to false when unset.

func (Settings) LoomContextEnabled added in v0.14.0

func (s Settings) LoomContextEnabled() bool

LoomContextEnabled reports whether new Claude sessions should launch with loom's context file injected. nil (unset) is treated as enabled, mirroring RemoteControlEnabled. Read only from the main goroutine.

func (Settings) Model added in v0.14.0

func (s Settings) Model() string

Model returns the configured --model alias, defaulting to "default" when unset (nil). Unlocked for the same reason as PermissionMode.

func (Settings) PermissionMode added in v0.14.0

func (s Settings) PermissionMode() string

PermissionMode returns the configured --permission-mode value, defaulting to "default" when unset (nil). Deliberately unlocked, like RemoteControlEnabled: it's read only from the main goroutine (view rendering, instance creation during key handling, and from inside a Mutate callback in the Claude Preferences cycle handler — a Mutate-held lock is not reentrant, so a locked accessor here would deadlock). If a future caller needs this from the Lua dispatch goroutine, add a locked variant rather than locking this one.

func (Settings) RemoteControlEnabled added in v0.14.0

func (s Settings) RemoteControlEnabled() bool

RemoteControlEnabled reports whether new Claude sessions should launch with the --remote-control flag. Defaults to true when unset so the feature is on out of the box; only an explicit false disables it.

func (Settings) SubagentTrackingEnabled added in v0.14.0

func (s Settings) SubagentTrackingEnabled() bool

SubagentTrackingEnabled reports whether the subagents loom's hooks track are shown. nil (unset) is treated as enabled, mirroring LoomContextEnabled. Read only from the main goroutine.

type State

type State struct {

	// HelpScreensSeen is a bitmask tracking which help screens have been shown
	HelpScreensSeen uint32 `json:"help_screens_seen"`
	// Instances stores the serialized instance data as raw JSON
	InstancesData json.RawMessage `json:"instances"`
	// UI stores the per-workspace UI layout prefs
	UI UIPrefs `json:"ui"`
	// contains filtered or unexported fields
}

State represents the application state that persists between sessions

func DefaultState

func DefaultState() *State

DefaultState returns the default state

func LoadState

func LoadState() *State

LoadState loads the state from disk. If it cannot be done, we return the default state.

func LoadStateFrom

func LoadStateFrom(dir string) *State

LoadStateFrom loads state from an explicit directory. Empty `dir` is a soft shim: a warning is logged and the global config directory is used. Internal callers must pass a resolved WorkspaceContext.ConfigDir per docs/specs/workspaces.md §3. The returned State remembers dir so that SaveState writes back to it.

func LoadStateFromGlobal

func LoadStateFromGlobal() *State

LoadStateFromGlobal loads state from the global config directory. Prefer this over LoadStateFrom("") for call sites that truly want the global state file.

func (*State) DeleteAllInstances

func (s *State) DeleteAllInstances() error

DeleteAllInstances removes all stored instances

func (*State) GetHelpScreensSeen

func (s *State) GetHelpScreensSeen() uint32

GetHelpScreensSeen returns the bitmask of seen help screens

func (*State) GetInstances

func (s *State) GetInstances() json.RawMessage

GetInstances returns the raw instance data

func (*State) GetUIPrefs added in v0.13.0

func (s *State) GetUIPrefs() UIPrefs

GetUIPrefs returns a copy of the persisted UI layout prefs.

func (*State) SaveInstances

func (s *State) SaveInstances(instancesJSON json.RawMessage) error

SaveInstances saves the raw instance data

func (*State) SetHelpScreensSeen

func (s *State) SetHelpScreensSeen(seen uint32) error

SetHelpScreensSeen updates the bitmask of seen help screens

func (*State) SetUIPrefs added in v0.13.0

func (s *State) SetUIPrefs(p UIPrefs) error

SetUIPrefs replaces and persists the UI layout prefs.

type StateManager

type StateManager interface {
	InstanceStorage
	AppState
}

StateManager combines instance storage and app state management

type UIPrefs added in v0.13.0

type UIPrefs struct {
	ViewMode       string             `json:"view_mode,omitempty"`
	RailHidden     bool               `json:"rail_hidden,omitempty"`
	TerminalHidden bool               `json:"terminal_hidden,omitempty"`
	SplitRatios    map[string]float64 `json:"split_ratios,omitempty"`
	// WorkbenchRatios maps session title → agent-pane width share in
	// workbench mode (sibling of SplitRatios, which is the focus-mode
	// vertical split).
	WorkbenchRatios map[string]float64 `json:"workbench_ratios,omitempty"`
}

UIPrefs is per-workspace UI layout state (view mode, rail/terminal visibility, per-session split ratios). Stored in state.json, so each workspace keeps its own layout.

func (UIPrefs) Clone added in v0.14.0

func (p UIPrefs) Clone() UIPrefs

Clone deep-copies the prefs so callers can mutate the returned value (including the SplitRatios map) without affecting the stored state.

type Workspace

type Workspace struct {
	Name    string    `json:"name"`
	Path    string    `json:"path"`
	AddedAt time.Time `json:"added_at"`
}

Workspace represents a registered workspace tied to a git repository.

type WorkspaceContext

type WorkspaceContext struct {
	// Name is the workspace name. Empty string means global.
	Name string
	// ConfigDir is the absolute path to the config directory
	// (e.g., /repo/.loom or ~/.loom).
	ConfigDir string
	// RepoPath is the absolute path to the repo root. Empty for global.
	RepoPath string
}

WorkspaceContext carries the resolved identity of the active workspace. A nil *WorkspaceContext means "global" (no workspace).

func GlobalWorkspaceContext

func GlobalWorkspaceContext() (*WorkspaceContext, error)

GlobalWorkspaceContext returns a WorkspaceContext pointing at ~/.loom.

func ResolveWorkspace

func ResolveWorkspace(cwd string, registry *WorkspaceRegistry) (*WorkspaceContext, error)

ResolveWorkspace determines the workspace context for the given working directory. If a registered workspace matches, returns its context. Otherwise returns the global context.

func WorkspaceContextFor

func WorkspaceContextFor(ws *Workspace) *WorkspaceContext

WorkspaceContextFor returns a WorkspaceContext for the given workspace.

type WorkspaceRegistry

type WorkspaceRegistry struct {
	Workspaces     []Workspace `json:"workspaces"`
	LastUsed       string      `json:"last_used"`
	OpenWorkspaces []string    `json:"open_workspaces,omitempty"`
}

WorkspaceRegistry holds all registered workspaces, tracks the last-focused one, and records the ordered list of open workspace tabs for restore.

func LoadWorkspaceRegistry

func LoadWorkspaceRegistry() (*WorkspaceRegistry, error)

LoadWorkspaceRegistry reads the workspace registry from the global config dir. Returns an empty registry if the file doesn't exist.

func (*WorkspaceRegistry) Add

func (r *WorkspaceRegistry) Add(name, repoPath string) error

Add registers a new workspace. Validates uniqueness of name and that the path is a git repository. Automatically calls EnsureGitignore.

Like UpdateLastUsed, the on-disk registry is reloaded before save so concurrent writers (another `loom workspace` invocation, a second running TUI) are not clobbered by this process's stale snapshot.

func (*WorkspaceRegistry) FindByPath

func (r *WorkspaceRegistry) FindByPath(path string) *Workspace

FindByPath finds a workspace whose Path matches or is a parent of the given path.

func (*WorkspaceRegistry) Get

func (r *WorkspaceRegistry) Get(name string) *Workspace

Get finds a workspace by name.

func (*WorkspaceRegistry) GetOpenWorkspaces

func (r *WorkspaceRegistry) GetOpenWorkspaces() []Workspace

GetOpenWorkspaces returns the workspaces named in OpenWorkspaces, in order. Names that no longer exist in the registry are skipped silently.

func (*WorkspaceRegistry) Reload added in v0.14.0

func (r *WorkspaceRegistry) Reload() error

Reload replaces the receiver's in-memory state with the registry on disk, as every write does before it saves: another process (`loom workspace add`, a second loom) may have changed it.

func (*WorkspaceRegistry) Remove

func (r *WorkspaceRegistry) Remove(name string) error

Remove removes a workspace by name. Does NOT delete the .loom/ directory.

func (*WorkspaceRegistry) Rename

func (r *WorkspaceRegistry) Rename(oldName, newName string) error

Rename changes a workspace's name. Updates LastUsed if it pointed to the old name.

func (*WorkspaceRegistry) SetOpenWorkspaces

func (r *WorkspaceRegistry) SetOpenWorkspaces(names []string) error

SetOpenWorkspaces replaces the ordered list of open workspace names and persists the registry. Unknown names are silently dropped so the stored list always references workspaces that still exist.

The on-disk registry is reloaded before save so concurrent writers (a `loom workspace add` invocation in another shell, or a second running TUI) are not clobbered by this process's stale snapshot of Workspaces. The receiver's in-memory state is refreshed to match the merged result.

func (*WorkspaceRegistry) UpdateLastUsed

func (r *WorkspaceRegistry) UpdateLastUsed(name string) error

UpdateLastUsed sets the last used workspace and saves the registry. Returns an error if no workspace with the given name exists.

The on-disk registry is reloaded before save so concurrent writers (a `loom workspace add` invocation in another shell, or a second running TUI) are not clobbered by this process's stale snapshot of Workspaces. The receiver's in-memory state is refreshed to match the merged result.

Jump to

Keyboard shortcuts

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