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
- Variables
- func AtomicWriteFile(path string, data []byte, perm os.FileMode) error
- func ClaudeModelAliases() []string
- func ClaudeModelSupports1M(alias string) bool
- func EnsureGitignore(repoPath string) error
- func GetClaudeCommand() (string, error)
- func GetConfigDir() (string, error)
- func GetGlobalConfigDir() (string, error)
- func MigrateLegacyHome() error
- func SaveConfigTo(config *Config, dir string) error
- func SaveState(state *State) error
- func SaveStateTo(state *State, dir string) error
- func SaveWorkspaceRegistry(reg *WorkspaceRegistry) error
- func WorkspaceConfigDir(ws *Workspace) string
- type AppState
- type ClaudeModel
- type Config
- type InstanceStorage
- type Profile
- type Settings
- func (s Settings) CacheTTL1hEnabled() bool
- func (s Settings) ClaudeTmpArchiveRoot() (string, error)
- func (s Settings) Clone() Settings
- func (s Settings) Context1MEnabled() bool
- func (s Settings) Effort() string
- func (s Settings) GetBaseBranch() string
- func (s Settings) GetBranchPrefix() string
- func (s Settings) GetProfiles() []Profile
- func (s Settings) GetProgram() string
- func (s Settings) GetTheme() string
- func (s Settings) HeadroomProxyEnabled() bool
- func (s Settings) LoomContextEnabled() bool
- func (s Settings) Model() string
- func (s Settings) PermissionMode() string
- func (s Settings) RemoteControlEnabled() bool
- func (s Settings) SubagentTrackingEnabled() bool
- type State
- func (s *State) DeleteAllInstances() error
- func (s *State) GetHelpScreensSeen() uint32
- func (s *State) GetInstances() json.RawMessage
- func (s *State) GetUIPrefs() UIPrefs
- func (s *State) SaveInstances(instancesJSON json.RawMessage) error
- func (s *State) SetHelpScreensSeen(seen uint32) error
- func (s *State) SetUIPrefs(p UIPrefs) error
- type StateManager
- type UIPrefs
- type Workspace
- type WorkspaceContext
- type WorkspaceRegistry
- func (r *WorkspaceRegistry) Add(name, repoPath string) error
- func (r *WorkspaceRegistry) FindByPath(path string) *Workspace
- func (r *WorkspaceRegistry) Get(name string) *Workspace
- func (r *WorkspaceRegistry) GetOpenWorkspaces() []Workspace
- func (r *WorkspaceRegistry) Reload() error
- func (r *WorkspaceRegistry) Remove(name string) error
- func (r *WorkspaceRegistry) Rename(oldName, newName string) error
- func (r *WorkspaceRegistry) SetOpenWorkspaces(names []string) error
- func (r *WorkspaceRegistry) UpdateLastUsed(name string) error
Constants ¶
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.
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).
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.
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 ¶
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.
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.
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 ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
SaveConfigTo saves the configuration to an explicit directory.
func SaveStateTo ¶
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 ¶
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
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 FromSettings ¶ added in v0.14.0
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 ¶
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
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
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
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
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
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
ReplaceSettings replaces every setting with a copy of s, 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
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
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
Clone deep-copies s: Profiles and every pointer field are its own.
func (Settings) Context1MEnabled ¶ added in v0.14.0
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
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
GetBaseBranch returns BaseBranch (see Config.GetBaseBranch).
func (Settings) GetBranchPrefix ¶ added in v0.14.0
GetBranchPrefix returns BranchPrefix. Config's own GetBranchPrefix reads it under the lock.
func (Settings) GetProfiles ¶ added in v0.14.0
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
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
GetTheme returns the configured UI theme name (see Config.GetTheme).
func (Settings) HeadroomProxyEnabled ¶ added in v0.14.0
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
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
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
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
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
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 LoadState ¶
func LoadState() *State
LoadState loads the state from disk. If it cannot be done, we return the default state.
func LoadStateFrom ¶
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 ¶
DeleteAllInstances removes all stored instances
func (*State) GetHelpScreensSeen ¶
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
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 ¶
SetHelpScreensSeen updates the bitmask of seen help screens
func (*State) SetUIPrefs ¶ added in v0.13.0
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.
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.