state

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package state manages persistent user state such as diff mode preferences, pane widths, and plugin-specific state per working directory across sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearLastWorktreePath

func ClearLastWorktreePath(mainRepoPath string) error

ClearLastWorktreePath removes the saved worktree path for a main repo.

func ForgetPaneLayouts added in v0.99.0

func ForgetPaneLayouts(s *WorkspaceState, surfaces ...string) bool

ForgetPaneLayouts removes only the named surfaces, including a matching legacy single-slot record. It reports whether anything changed so callers can avoid unrelated state writes while still writing a last-entry removal.

func GetActivePlugin

func GetActivePlugin(workdir string) string

GetActivePlugin returns the saved active plugin ID for a given working directory.

func GetActivePluginForWorkDir added in v0.94.0

func GetActivePluginForWorkDir(workdir, projectRoot string) string

GetActivePluginForWorkDir performs the additive migration from the former repository-root key to a concrete worktree key. It never overwrites an existing worktree choice and retains the legacy entry.

func GetAgentAutoApprove added in v1.0.0

func GetAgentAutoApprove(agent string) bool

GetAgentAutoApprove returns the persisted auto-approve preference for agent. A missing key is false.

func GetConversationsSideWidth

func GetConversationsSideWidth() int

GetConversationsSideWidth returns the saved conversations sidebar width. Returns 0 if no preference is saved (use default).

func GetDiffTabFileListWidth added in v0.81.0

func GetDiffTabFileListWidth() int

GetDiffTabFileListWidth returns the saved diff tab file list width (in pixels). Returns 0 if no preference is saved (use default).

func GetFileBrowserTreeWidth

func GetFileBrowserTreeWidth() int

GetFileBrowserTreeWidth returns the saved file browser tree pane width. Returns 0 if no preference is saved (use default).

func GetGitDiffMode

func GetGitDiffMode() string

GetGitDiffMode returns the saved diff mode.

func GetGitGraphEnabled

func GetGitGraphEnabled() bool

GetGitGraphEnabled returns whether the commit graph is enabled.

func GetGitStatusSidebarWidth

func GetGitStatusSidebarWidth() int

GetGitStatusSidebarWidth returns the saved git status sidebar width. Returns 0 if no preference is saved (use default).

func GetLastCreateAgent added in v1.0.0

func GetLastCreateAgent() string

GetLastCreateAgent returns the last agent chosen when creating a worktree.

func GetLastGlobalCreateProject added in v1.0.0

func GetLastGlobalCreateProject() string

GetLastGlobalCreateProject returns the last project root chosen in global Workspaces creation.

func GetLastGlobalTab added in v0.98.0

func GetLastGlobalTab() string

GetLastGlobalTab returns the saved global tab ID, or empty if none is saved.

func GetLastWorktreePath

func GetLastWorktreePath(mainRepoPath string) string

GetLastWorktreePath returns the last active worktree path for a main repo.

func GetLineWrapEnabled

func GetLineWrapEnabled() bool

GetLineWrapEnabled returns whether line wrapping is enabled.

func GetPinnedWorkspaceIDs added in v0.98.0

func GetPinnedWorkspaceIDs() []string

GetPinnedWorkspaceIDs returns the saved global pin order, or nil if none.

func GetSeenDefaultThemeNotice added in v1.0.0

func GetSeenDefaultThemeNotice() bool

GetSeenDefaultThemeNotice reports whether the one-time new-default-theme toast has already been shown. Fresh state has not seen it.

func GetShowIdleWorktrees added in v0.98.0

func GetShowIdleWorktrees() bool

GetShowIdleWorktrees reports whether the global list should include idle worktrees. A missing or fresh state is off.

func GetTermPanelLayout added in v0.83.0

func GetTermPanelLayout() string

GetTermPanelLayout returns the saved terminal panel layout ("bottom" or "right").

func GetTermPanelSize added in v0.83.0

func GetTermPanelSize() int

GetTermPanelSize returns the saved terminal panel split size (percentage).

func GetTermPanelVisible added in v0.83.0

func GetTermPanelVisible() bool

GetTermPanelVisible returns whether the terminal panel was visible at last exit.

func GetWorkspaceDiffMode

func GetWorkspaceDiffMode() string

GetWorkspaceDiffMode returns the saved workspace diff mode.

func GetWorkspaceListSort added in v1.0.0

func GetWorkspaceListSort() string

GetWorkspaceListSort returns the global Workspaces list's saved order label, or "" when the user has never chosen one.

func GetWorkspaceSidebarWidth

func GetWorkspaceSidebarWidth() int

GetWorkspaceSidebarWidth returns the saved workspace sidebar width. Returns 0 if no preference is saved (use default).

func Init

func Init() error

Init loads state from the default location.

func InitWithDir

func InitWithDir(dir string) error

InitWithDir loads state from a specified directory. This is primarily for testing to avoid reading real user state.

func Load

func Load() error

Load reads state from disk.

func MigratePaneLayouts added in v0.99.0

func MigratePaneLayouts(s *WorkspaceState)

MigratePaneLayouts copies a legacy single-slot PaneLayout into PaneLayouts when the map is empty. The legacy field is left for the writer to drop.

func PaneLayoutOpen added in v0.99.0

func PaneLayoutOpen(l *PaneLayoutJSON) bool

PaneLayoutOpen reports whether restore should rebuild the split. Open=true restores. Open=false is hide: tabs stay in the map, the live tree does not.

func Save

func Save() error

Save writes state to disk.

func SetActivePlugin

func SetActivePlugin(workdir, pluginID string) error

SetActivePlugin saves the active plugin ID for a given working directory.

func SetAgentAutoApprove added in v1.0.0

func SetAgentAutoApprove(agent string, on bool) error

SetAgentAutoApprove saves the auto-approve preference for agent.

func SetConversationsSideWidth

func SetConversationsSideWidth(width int) error

SetConversationsSideWidth saves the conversations sidebar width.

func SetDiffTabFileListWidth added in v0.81.0

func SetDiffTabFileListWidth(width int) error

SetDiffTabFileListWidth saves the diff tab file list width (in pixels).

func SetFileBrowserState

func SetFileBrowserState(workdir string, fbState FileBrowserState) error

SetFileBrowserState saves the file browser state for a given working directory.

func SetFileBrowserTreeWidth

func SetFileBrowserTreeWidth(width int) error

SetFileBrowserTreeWidth saves the file browser tree pane width.

func SetGitDiffMode

func SetGitDiffMode(mode string) error

SetGitDiffMode saves the diff mode preference.

func SetGitGraphEnabled

func SetGitGraphEnabled(enabled bool) error

SetGitGraphEnabled saves the commit graph preference.

func SetGitStatusSidebarWidth

func SetGitStatusSidebarWidth(width int) error

SetGitStatusSidebarWidth saves the git status sidebar width.

func SetLastCreateAgent added in v1.0.0

func SetLastCreateAgent(agent string) error

SetLastCreateAgent saves the last agent chosen when creating a worktree.

func SetLastGlobalCreateProject added in v1.0.0

func SetLastGlobalCreateProject(project string) error

SetLastGlobalCreateProject persists the last project root chosen in global Workspaces creation.

func SetLastGlobalTab added in v0.98.0

func SetLastGlobalTab(tab string) error

SetLastGlobalTab saves the last selected global tab ID.

func SetLastWorktreePath

func SetLastWorktreePath(mainRepoPath, worktreePath string) error

SetLastWorktreePath saves the last active worktree path for a main repo.

func SetLineWrapEnabled

func SetLineWrapEnabled(enabled bool) error

SetLineWrapEnabled saves the line wrap preference.

func SetNotesListWidth

func SetNotesListWidth(width int) error

SetNotesListWidth saves just the notes list width for a given working directory.

func SetNotesState

func SetNotesState(workdir string, notesState NotesState) error

SetNotesState saves the notes state for a given working directory.

func SetPinnedWorkspaceIDs added in v0.98.0

func SetPinnedWorkspaceIDs(ids []string) error

SetPinnedWorkspaceIDs saves the global Workspaces pin order.

func SetSeenDefaultThemeNotice added in v1.0.0

func SetSeenDefaultThemeNotice(seen bool) error

SetSeenDefaultThemeNotice records that the notice has been shown, so it never appears again.

func SetShowIdleWorktrees added in v0.98.0

func SetShowIdleWorktrees(show bool) error

SetShowIdleWorktrees saves the global idle-worktree visibility preference.

func SetTermPanelLayout added in v0.83.0

func SetTermPanelLayout(layout string) error

SetTermPanelLayout saves the terminal panel layout ("bottom" or "right").

func SetTermPanelSize added in v0.83.0

func SetTermPanelSize(size int) error

SetTermPanelSize saves the terminal panel split size (percentage).

func SetTermPanelVisible added in v0.83.0

func SetTermPanelVisible(visible bool) error

SetTermPanelVisible saves the terminal panel visibility state.

func SetWorkspaceDiffMode

func SetWorkspaceDiffMode(mode string) error

SetWorkspaceDiffMode saves the workspace diff mode preference.

func SetWorkspaceListSort added in v1.0.0

func SetWorkspaceListSort(label string) error

SetWorkspaceListSort saves the global Workspaces list's chosen order.

func SetWorkspaceSidebarWidth

func SetWorkspaceSidebarWidth(width int) error

SetWorkspaceSidebarWidth saves the workspace sidebar width.

func SetWorkspaceState

func SetWorkspaceState(workdir string, wtState WorkspaceState) error

SetWorkspaceState saves the workspace state for a given working directory.

Types

type FileBrowserState

type FileBrowserState struct {
	SelectedFile  string                `json:"selectedFile,omitempty"`  // Currently selected file path (relative)
	TreeScroll    int                   `json:"treeScroll,omitempty"`    // Tree pane scroll offset
	PreviewScroll int                   `json:"previewScroll,omitempty"` // Preview pane scroll offset
	ExpandedDirs  []string              `json:"expandedDirs,omitempty"`  // List of expanded directory paths
	ActivePane    string                `json:"activePane,omitempty"`    // "tree" or "preview"
	PreviewFile   string                `json:"previewFile,omitempty"`   // File being previewed (relative)
	TreeCursor    int                   `json:"treeCursor,omitempty"`    // Tree cursor position
	ShowIgnored   *bool                 `json:"showIgnored,omitempty"`   // Whether to show git-ignored files (nil = default true)
	Tabs          []FileBrowserTabState `json:"tabs,omitempty"`
	ActiveTab     int                   `json:"activeTab,omitempty"`
}

FileBrowserState holds persistent file browser state.

func GetFileBrowserState

func GetFileBrowserState(workdir string) FileBrowserState

GetFileBrowserState returns the saved file browser state for a given working directory.

func GetFileBrowserStateForWorkDir added in v0.94.0

func GetFileBrowserStateForWorkDir(workdir, projectRoot string) FileBrowserState

GetFileBrowserStateForWorkDir returns content state keyed by the concrete worktree. Older Sidecar versions keyed this state by the repository root; on first access, copy that legacy value forward only when the worktree has no value of its own. The root entry is deliberately retained for rollback.

type FileBrowserTabState

type FileBrowserTabState struct {
	Path   string `json:"path,omitempty"`   // File path (relative)
	Scroll int    `json:"scroll,omitempty"` // Preview scroll offset
}

FileBrowserTabState holds persistent tab state for the file browser.

type NotesState

type NotesState struct {
	ListWidth    int    `json:"listWidth,omitempty"`    // Width of list pane
	LastNoteID   string `json:"lastNoteID,omitempty"`   // Last selected note ID
	ShowArchived bool   `json:"showArchived,omitempty"` // Whether to show archived notes
}

NotesState holds persistent notes plugin state.

func GetNotesState

func GetNotesState(workdir string) NotesState

GetNotesState returns the saved notes state for a given working directory.

type PaneDiffTabJSON added in v1.0.0

type PaneDiffTabJSON struct {
	Spec   string `json:"spec"`
	Path   string `json:"path,omitempty"`
	Scope  string `json:"scope,omitempty"`
	Mode   string `json:"mode,omitempty"`
	Scroll int    `json:"scroll,omitempty"`
}

PaneDiffTabJSON is one persisted Diff tab. Restore reloads the target spec; the diff body is not cached.

type PaneDocTabJSON added in v0.98.0

type PaneDocTabJSON struct {
	Path   string `json:"path"`
	Mode   string `json:"mode,omitempty"`
	Wrap   bool   `json:"wrap,omitempty"`
	Scroll int    `json:"scroll,omitempty"`
}

type PaneIssueTabJSON added in v1.0.0

type PaneIssueTabJSON struct {
	Issue  string `json:"issue"`
	Scroll int    `json:"scroll,omitempty"`
}

PaneIssueTabJSON is one persisted issue tab. Restore re-fetches the issue and applies Scroll; the body is not cached.

type PaneLayoutJSON added in v0.98.0

type PaneLayoutJSON struct {
	Root      string             `json:"root,omitempty"`
	Surface   string             `json:"surface,omitempty"`
	Kind      string             `json:"kind,omitempty"`
	Split     *PaneSplitJSON     `json:"split,omitempty"`
	Tabs      []PaneDocTabJSON   `json:"tabs,omitempty"`
	IssueTabs []PaneIssueTabJSON `json:"issueTabs,omitempty"`
	DiffTabs  []PaneDiffTabJSON  `json:"diffTabs,omitempty"`
	Active    int                `json:"active,omitempty"`
	// Open is true when restore should rebuild the split. False means this
	// surface still has tabs but the pane is hidden (q). Omitted on a legacy
	// record that still has a split is treated as open by MigratePaneLayouts.
	Open bool `json:"open,omitempty"`
	// Issue and Scroll are the pre-tab issue leaf. Decode treats them as a
	// one-tab list when IssueTabs is absent.
	Issue  string `json:"issue,omitempty"`
	Scroll int    `json:"scroll,omitempty"`
}

PaneLayoutJSON is the persisted, presentation-neutral pane-tree shape. Doc tabs are a list from the first version so adding tab UI later is additive. Issue tabs are IssueTabs plus Active. Issue and Scroll are read-only legacy and are not written after the first save.

func RekeyPaneLayout added in v0.99.0

func RekeyPaneLayout(s *WorkspaceState, legacySurface, canonicalSurface string) (*PaneLayoutJSON, bool)

RekeyPaneLayout moves a saved surface to its canonical identity. If both identities exist, the canonical record wins and the duplicate legacy key is dropped. The returned bool reports whether the state needs writing.

type PaneSplitJSON added in v0.98.0

type PaneSplitJSON struct {
	Axis  string          `json:"axis"`
	Ratio int             `json:"ratio"`
	A     *PaneLayoutJSON `json:"a"`
	B     *PaneLayoutJSON `json:"b"`
}

type State

type State struct {
	GitDiffMode       string `json:"gitDiffMode"`                 // "unified" or "side-by-side"
	WorkspaceDiffMode string `json:"workspaceDiffMode,omitempty"` // "unified" or "side-by-side"
	GitGraphEnabled   bool   `json:"gitGraphEnabled,omitempty"`   // Show commit graph in sidebar
	LineWrapEnabled   bool   `json:"lineWrapEnabled,omitempty"`   // Wrap long lines instead of truncating

	// Pane width preferences (percentage of total width, 0 = use default)
	FileBrowserTreeWidth   int    `json:"fileBrowserTreeWidth,omitempty"`
	GitStatusSidebarWidth  int    `json:"gitStatusSidebarWidth,omitempty"`
	ConversationsSideWidth int    `json:"conversationsSideWidth,omitempty"`
	WorkspaceSidebarWidth  int    `json:"workspaceSidebarWidth,omitempty"`
	DiffTabFileListWidth   int    `json:"diffTabFileListWidth,omitempty"`
	TermPanelSize          int    `json:"termPanelSize,omitempty"`    // Terminal panel split size (percentage, 0 = 50%)
	TermPanelLayout        string `json:"termPanelLayout,omitempty"`  // "bottom" or "right"
	TermPanelVisible       bool   `json:"termPanelVisible,omitempty"` // Whether terminal panel was visible at exit

	// Plugin-specific state (keyed by working directory path)
	FileBrowser  map[string]FileBrowserState `json:"fileBrowser,omitempty"`
	Workspace    map[string]WorkspaceState   `json:"workspace,omitempty"`
	Notes        map[string]NotesState       `json:"notes,omitempty"`
	ActivePlugin map[string]string           `json:"activePlugin,omitempty"`

	// Worktree state: maps main repo path -> last active worktree path
	LastWorktreePath map[string]string `json:"lastWorktreePath,omitempty"`

	// Last selected global tab ("agents", "workspaces", or "tasks").
	LastGlobalTab string `json:"lastGlobalTab,omitempty"`

	// ShowIdleWorktrees reveals "no session" rows on the global Workspaces list.
	// Fresh state leaves this off so the list is sessions by default.
	ShowIdleWorktrees bool `json:"showIdleWorktrees,omitempty"`

	// PinnedWorkspaceIDs is the ordered catalog IDs pinned to the top of the
	// global Workspaces list. First-pinned first. Gone IDs are dropped on sync.
	PinnedWorkspaceIDs []string `json:"pinnedWorkspaceIDs,omitempty"`

	// WorkspaceListSort is the global Workspaces list's chosen order, stored as
	// its display label ("Activity", "Project", "Recent", "Name") rather than
	// an ordinal, so the file reads plainly and the enum can be reordered.
	// Unrecognised or empty falls back to the default. Its per-project
	// counterpart lives on WorkspaceState, because the two scopes answer the
	// question separately.
	WorkspaceListSort string `json:"workspaceListSort,omitempty"`

	// LastCreateAgent is the last agent chosen when creating a worktree.
	LastCreateAgent string `json:"lastCreateAgent,omitempty"`
	// LastGlobalCreateProject is the stable project root last chosen from the
	// cross-project Workspaces create flow.
	LastGlobalCreateProject string `json:"lastGlobalCreateProject,omitempty"`

	// AgentAutoApprove is the last auto-approve checkbox value per agent type.
	// A missing key is treated as false.
	AgentAutoApprove map[string]bool `json:"agentAutoApprove,omitempty"`

	// SeenDefaultThemeNotice records that the one-time "the default theme
	// changed" toast has been shown.
	//
	// It lives here and not in config.json on purpose. Sidecar only writes
	// config.json when a setting changes, and an absent ui.theme block is
	// exactly the signal that identifies a user who is being restyled. Writing
	// the flag into the config would record a theme choice as a side effect and
	// disarm the very mechanism it is flagging.
	SeenDefaultThemeNotice bool `json:"seenDefaultThemeNotice,omitempty"`
}

State holds persistent user preferences.

type WorkspaceState

type WorkspaceState struct {
	WorkspaceName     string                     `json:"workspaceName,omitempty"`     // Name of selected workspace
	ShellTmuxName     string                     `json:"shellTmuxName,omitempty"`     // TmuxName of selected shell (empty = workspace selected)
	ShellDisplayNames map[string]string          `json:"shellDisplayNames,omitempty"` // TmuxName -> display name
	PaneLayout        *PaneLayoutJSON            `json:"paneLayout,omitempty"`        // Read-only migrate into PaneLayouts
	PaneLayouts       map[string]*PaneLayoutJSON `json:"paneLayouts,omitempty"`       // surface → layout
	// ListSort is the sidebar's chosen order, stored as its display label
	// ("Manual", "Activity", "Recent", "Name") rather than an ordinal. A label
	// survives reordering the enum, reads plainly in the state file, and an
	// unrecognised one falls back to the default instead of selecting an
	// arbitrary mode. Empty means the project has never chosen.
	ListSort string `json:"listSort,omitempty"`
}

WorkspaceState holds persistent workspace plugin state.

func GetWorkspaceState

func GetWorkspaceState(workdir string) WorkspaceState

GetWorkspaceState returns the saved workspace state for a given working directory.

func (WorkspaceState) PaneLayoutFor added in v0.99.0

func (s WorkspaceState) PaneLayoutFor(surface string) *PaneLayoutJSON

PaneLayoutFor returns the layout stored for surface, migrating a legacy single-slot record first. The receiver is a copy; the stored state is not written.

Jump to

Keyboard shortcuts

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