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 ¶
- func ClearLastBoundLocation() error
- func ClearLastWorktreePath(mainRepoPath string) error
- func ClearLegacyTermPanel() error
- func ForgetPaneLayouts(s *WorkspaceState, surfaces ...string) bool
- func GetActivePlugin(workdir string) string
- func GetActivePluginForWorkDir(workdir, projectRoot string) string
- func GetAgentAutoApprove(agent string) bool
- func GetContentDeck(workdir, pluginID string) json.RawMessage
- func GetConversationsSideWidth() int
- func GetDiffTabFileListWidth() int
- func GetFileBrowserTreeWidth() int
- func GetGitDiffMode() string
- func GetGitGraphEnabled() bool
- func GetGitStatusSidebarWidth() int
- func GetLastCreateAgent() string
- func GetLastGlobalCreateProject() string
- func GetLastGlobalTab() string
- func GetLastRemoteWorktree(hostID, projectKey string) string
- func GetLastScope() string
- func GetLastWorktreePath(mainRepoPath string) string
- func GetLineWrapEnabled() bool
- func GetNotificationCentreWidth() int
- func GetPinnedWorkspaceIDs() []string
- func GetPluginBrowserSplit(instance string) int
- func GetProjectActivity() map[string]time.Time
- func GetProjectSwitcherOrder() string
- func GetProjectSwitcherSort() string
- func GetProjectSwitcherView() string
- func GetSeenDefaultThemeNotice() bool
- func GetSessionsHiddenHosts() []string
- func GetSessionsPaneLayouts() map[string]*PaneLayoutJSON
- func GetSessionsSelected() string
- func GetShowIdleWorktrees() bool
- func GetWorkspaceDiffMode() string
- func GetWorkspaceListSort() string
- func GetWorkspacePaneLayouts() map[string]*PaneLayoutJSON
- func GetWorkspaceSidebarWidth() int
- func Init() error
- func InitWithDir(dir string) error
- func LegacyTermPanel() (visible bool, side string, size int)
- func Load() error
- func MigratePaneLayouts(s *WorkspaceState)
- func PaneLayoutOpen(l *PaneLayoutJSON) bool
- func ReadPaneLayoutsWithDir(dir string) (map[string]*PaneLayoutJSON, map[string]*PaneLayoutJSON, error)
- func RecordProjectActivity(projectPath string, when time.Time) error
- func Save() error
- func SetActivePlugin(workdir, pluginID string) error
- func SetAgentAutoApprove(agent string, on bool) error
- func SetContentDeck(workdir, pluginID string, raw json.RawMessage) error
- func SetConversationsSideWidth(width int) error
- func SetDiffTabFileListWidth(width int) error
- func SetFileBrowserState(workdir string, fbState FileBrowserState) error
- func SetFileBrowserTreeWidth(width int) error
- func SetGitDiffMode(mode string) error
- func SetGitGraphEnabled(enabled bool) error
- func SetGitStatusSidebarWidth(width int) error
- func SetLastBoundLocation(loc BoundLocation) error
- func SetLastCreateAgent(agent string) error
- func SetLastGlobalCreateProject(project string) error
- func SetLastGlobalTab(tab string) error
- func SetLastRemoteWorktree(hostID, projectKey, worktreeKey string) error
- func SetLastScope(scope string) error
- func SetLastWorktreePath(mainRepoPath, worktreePath string) error
- func SetLineWrapEnabled(enabled bool) error
- func SetNotesListWidth(width int) error
- func SetNotesState(workdir string, notesState NotesState) error
- func SetNotificationCentreWidth(width int) error
- func SetPinnedWorkspaceIDs(ids []string) error
- func SetPluginBrowserSplit(instance string, percent int) error
- func SetPluginBrowserView(instance, collection string, view PluginBrowserViewJSON) error
- func SetProjectSwitcherSort(sortLabel, orderLabel string) error
- func SetProjectSwitcherView(label string) error
- func SetSeenDefaultThemeNotice(seen bool) error
- func SetSessionsHiddenHosts(ids []string) error
- func SetSessionsPaneLayout(id string, layout *PaneLayoutJSON) error
- func SetSessionsSelected(id string) error
- func SetShowIdleWorktrees(show bool) error
- func SetWorkspaceDiffMode(mode string) error
- func SetWorkspaceListSort(label string) error
- func SetWorkspaceSidebarWidth(width int) error
- func SetWorkspaceState(workdir string, wtState WorkspaceState) error
- type BoundLocation
- type FileBrowserState
- type FileBrowserTabState
- type NotesState
- type PaneAttachmentJSON
- type PaneDiffTabJSON
- type PaneDocTabJSON
- type PaneIssueTabJSON
- type PaneLayoutJSON
- type PaneNoteTabJSON
- type PaneResourceTabJSON
- type PaneSplitJSON
- type PluginBrowserViewJSON
- type State
- type WorkspaceState
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClearLastBoundLocation ¶ added in v1.12.0
func ClearLastBoundLocation() error
ClearLastBoundLocation drops the stored host-qualified destination.
func ClearLastWorktreePath ¶
ClearLastWorktreePath removes the saved worktree path for a main repo.
func ClearLegacyTermPanel ¶ added in v1.3.0
func ClearLegacyTermPanel() error
ClearLegacyTermPanel drops the legacy keys once they have been converted, so the conversion happens exactly once per user.
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 ¶
GetActivePlugin returns the saved active plugin ID for a given working directory.
func GetActivePluginForWorkDir ¶ added in v0.94.0
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
GetAgentAutoApprove returns the persisted auto-approve preference for agent. A missing key is false.
func GetContentDeck ¶ added in v1.2.0
func GetContentDeck(workdir, pluginID string) json.RawMessage
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 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 GetLastRemoteWorktree ¶ added in v1.12.0
GetLastRemoteWorktree returns the host-side WorktreeKey last bound for (hostID, projectKey). Empty when none is stored. It is not visible to GetLastWorktreePath.
func GetLastScope ¶ added in v1.4.0
func GetLastScope() string
GetLastScope returns the saved top-level scope ID, or empty when none is saved.
func GetLastWorktreePath ¶
GetLastWorktreePath returns the last active worktree path for a main repo.
func GetLineWrapEnabled ¶
func GetLineWrapEnabled() bool
GetLineWrapEnabled returns whether line wrapping is enabled.
func GetNotificationCentreWidth ¶ added in v1.2.0
func GetNotificationCentreWidth() int
GetNotificationCentreWidth returns the saved notification centre panel width. Returns 0 if no preference is saved (use default).
func GetPinnedWorkspaceIDs ¶ added in v0.98.0
func GetPinnedWorkspaceIDs() []string
GetPinnedWorkspaceIDs returns the saved global pin order, or nil if none.
func GetPluginBrowserSplit ¶ added in v1.14.0
GetPluginBrowserSplit returns the saved list share for one plugin browser, as a percentage of its content box. Returns 0 when nothing is saved for that instance, which means "use the browser's default".
func GetProjectActivity ¶ added in v1.14.0
GetProjectActivity returns the recorded activity times for every project, by cleaned path. A project absent from the map has no recorded activity, which the switcher shows as Unknown rather than guessing.
func GetProjectSwitcherOrder ¶ added in v1.14.0
func GetProjectSwitcherOrder() string
GetProjectSwitcherOrder returns the switcher's saved sort direction label.
func GetProjectSwitcherSort ¶ added in v1.14.0
func GetProjectSwitcherSort() string
GetProjectSwitcherSort returns the switcher's saved sort label, or "" when the user has never chosen one.
func GetProjectSwitcherView ¶ added in v1.14.0
func GetProjectSwitcherView() string
GetProjectSwitcherView returns the switcher's saved layout label.
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 GetSessionsHiddenHosts ¶ added in v1.12.0
func GetSessionsHiddenHosts() []string
GetSessionsHiddenHosts returns the host IDs the global browser is currently withholding rows for. Fresh state hides nothing.
func GetSessionsPaneLayouts ¶ added in v1.8.0
func GetSessionsPaneLayouts() map[string]*PaneLayoutJSON
GetSessionsPaneLayouts returns a copy of every persisted Sessions tree.
func GetSessionsSelected ¶ added in v1.8.0
func GetSessionsSelected() string
GetSessionsSelected returns the durable Sessions row ID last shown, or empty when none is saved.
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 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 GetWorkspacePaneLayouts ¶ added in v1.15.0
func GetWorkspacePaneLayouts() map[string]*PaneLayoutJSON
GetWorkspacePaneLayouts returns copies of every project-surface pane tree, keyed by its persisted surface identity. Recovery uses this alongside the global Sessions layouts because either surface may have been the last writer.
func GetWorkspaceSidebarWidth ¶
func GetWorkspaceSidebarWidth() int
GetWorkspaceSidebarWidth returns the saved workspace sidebar width. Returns 0 if no preference is saved (use default).
func InitWithDir ¶
InitWithDir loads state from a specified directory. This is primarily for testing to avoid reading real user state.
func LegacyTermPanel ¶ added in v1.3.0
LegacyTermPanel returns the pre-split terminal panel preferences: whether the panel was up at exit, which side it was on ("bottom" or "right"), and the percentage it occupied. They exist only to be converted into a pane-tree split once; nothing writes them.
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 ReadPaneLayoutsWithDir ¶ added in v1.15.0
func ReadPaneLayoutsWithDir(dir string) (map[string]*PaneLayoutJSON, map[string]*PaneLayoutJSON, error)
ReadPaneLayoutsWithDir reads persisted pane layouts without changing the process-global UI state. Headless recovery uses this before any TUI exists.
func RecordProjectActivity ¶ added in v1.14.0
RecordProjectActivity stamps a project as active now. It is a no-op for an empty path, and a no-op when the recorded time is already this second, so repeated binds within one interaction do not rewrite the state file.
func SetActivePlugin ¶
SetActivePlugin saves the active plugin ID for a given working directory.
func SetAgentAutoApprove ¶ added in v1.0.0
SetAgentAutoApprove saves the auto-approve preference for agent.
func SetContentDeck ¶ added in v1.2.0
func SetContentDeck(workdir, pluginID string, raw json.RawMessage) error
func SetConversationsSideWidth ¶
SetConversationsSideWidth saves the conversations sidebar width.
func SetDiffTabFileListWidth ¶ added in v0.81.0
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 ¶
SetFileBrowserTreeWidth saves the file browser tree pane width.
func SetGitDiffMode ¶
SetGitDiffMode saves the diff mode preference.
func SetGitGraphEnabled ¶
SetGitGraphEnabled saves the commit graph preference.
func SetGitStatusSidebarWidth ¶
SetGitStatusSidebarWidth saves the git status sidebar width.
func SetLastBoundLocation ¶ added in v1.12.0
func SetLastBoundLocation(loc BoundLocation) error
SetLastBoundLocation persists a host-qualified destination. It never writes a remote path into LastWorktreePath.
func SetLastCreateAgent ¶ added in v1.0.0
SetLastCreateAgent saves the last agent chosen when creating a worktree.
func SetLastGlobalCreateProject ¶ added in v1.0.0
SetLastGlobalCreateProject persists the last project root chosen in global Workspaces creation.
func SetLastGlobalTab ¶ added in v0.98.0
SetLastGlobalTab saves the last selected global tab ID.
func SetLastRemoteWorktree ¶ added in v1.12.0
SetLastRemoteWorktree stores a host-side WorktreeKey for (hostID, projectKey). Empty keys are ignored. It never writes into LastWorktreePath.
func SetLastScope ¶ added in v1.4.0
SetLastScope saves the top-level scope the user is in.
func SetLastWorktreePath ¶
SetLastWorktreePath saves the last active worktree path for a main repo.
func SetLineWrapEnabled ¶
SetLineWrapEnabled saves the line wrap preference.
func SetNotesListWidth ¶
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 SetNotificationCentreWidth ¶ added in v1.2.0
SetNotificationCentreWidth saves the notification centre panel width.
func SetPinnedWorkspaceIDs ¶ added in v0.98.0
SetPinnedWorkspaceIDs saves the global Workspaces pin order.
func SetPluginBrowserSplit ¶ added in v1.14.0
SetPluginBrowserSplit saves one plugin browser's list share.
func SetPluginBrowserView ¶ added in v1.14.0
func SetPluginBrowserView(instance, collection string, view PluginBrowserViewJSON) error
SetPluginBrowserView saves one global protocol tab's view position. An empty position deletes the entry rather than writing a hollow one.
func SetProjectSwitcherSort ¶ added in v1.14.0
SetProjectSwitcherSort saves the switcher's chosen order and direction. They are written together because a direction means nothing without the mode it applies to.
func SetProjectSwitcherView ¶ added in v1.14.0
SetProjectSwitcherView saves the switcher's chosen layout.
func SetSeenDefaultThemeNotice ¶ added in v1.0.0
SetSeenDefaultThemeNotice records that the notice has been shown, so it never appears again.
func SetSessionsHiddenHosts ¶ added in v1.12.0
SetSessionsHiddenHosts saves which hosts the global browser withholds.
func SetSessionsPaneLayout ¶ added in v1.8.0
func SetSessionsPaneLayout(id string, layout *PaneLayoutJSON) error
SetSessionsPaneLayout stores (or, when layout is nil, deletes) the Sessions tree for row id. Unchanged JSON is a no-op.
func SetSessionsSelected ¶ added in v1.8.0
SetSessionsSelected saves the Sessions row last shown. An unchanged value is a no-op so arrowing the sidebar can debounce down to one write.
func SetShowIdleWorktrees ¶ added in v0.98.0
SetShowIdleWorktrees saves the global idle-worktree visibility preference.
func SetWorkspaceDiffMode ¶
SetWorkspaceDiffMode saves the workspace diff mode preference.
func SetWorkspaceListSort ¶ added in v1.0.0
SetWorkspaceListSort saves the global Workspaces list's chosen order.
func SetWorkspaceSidebarWidth ¶
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 BoundLocation ¶ added in v1.12.0
type BoundLocation struct {
HostID string `json:"hostId,omitempty"`
ProjectKey string `json:"projectKey,omitempty"`
WorktreeKey string `json:"worktreeKey,omitempty"`
}
BoundLocation is a host-qualified last location. Empty HostID is unused; local last-worktree memory stays on LastWorktreePath.
func GetLastBoundLocation ¶ added in v1.12.0
func GetLastBoundLocation() (BoundLocation, bool)
GetLastBoundLocation returns the last host-qualified destination, or false when none is stored.
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 PaneAttachmentJSON ¶ added in v1.16.0
type PaneAttachmentJSON struct {
Selector string `json:"selector"`
ExpectedTarget mobileproto.TargetIdentity `json:"expected_target"`
}
PaneAttachmentJSON preserves a catalog candidate without interpreting its opaque selector or granting terminal authority.
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 PaneIssueTabJSON ¶ added in v1.0.0
type PaneIssueTabJSON struct {
Issue string `json:"issue"`
Scroll int `json:"scroll,omitempty"`
OwnerName string `json:"ownerName,omitempty"`
OwnerRoot string `json:"ownerRoot,omitempty"`
}
PaneIssueTabJSON is one persisted issue tab. Restore re-fetches the issue and applies Scroll; the body is not cached. OwnerName and OwnerRoot are set only on a cross-project tab: restore reopens it from its owning store without re-running the search, badge intact.
type PaneLayoutJSON ¶ added in v0.98.0
type PaneLayoutJSON struct {
Root string `json:"root,omitempty"`
Surface string `json:"surface,omitempty"`
// HostID and the remaining source-identity fields are non-authoritative
// hints for a later restore. HostIncarnation is never persisted.
HostID string `json:"hostId,omitempty"`
ProjectKey string `json:"projectKey,omitempty"`
ProjectRoot string `json:"projectRoot,omitempty"`
WorkspaceID string `json:"workspaceId,omitempty"`
WorkspaceKind string `json:"workspaceKind,omitempty"`
WorkspaceKey string `json:"workspaceKey,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"`
// ResourceTabs are external provider references. One list serves every
// provider, so a new integration adds no field here.
ResourceTabs []PaneResourceTabJSON `json:"resourceTabs,omitempty"`
NoteTabs []PaneNoteTabJSON `json:"noteTabs,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"`
// Session is the exact tmux session name, the authoritative routing key.
// It is never an opaque catalog selector or a tmux pane id: pane ids are reassigned by the
// server and mean nothing after a restart, so a leaf that persisted one
// would reattach to whatever now holds that id.
Session string `json:"session,omitempty"`
// Attachment is an untrusted catalog hint. Session remains the routing key;
// a client must resolve/revalidate this hint before opening a terminal.
Attachment *PaneAttachmentJSON `json:"attachment,omitempty"`
// Name is a live leaf's display title (a terminal split's header). Empty
// on every other kind. Additive: older files omit it.
Name string `json:"name,omitempty"`
// FocusKind is the focused leaf in this tree, in PaneLayoutJSON kind
// vocabulary (terminal|doc|issue|note|diff|resource|shell). Restore that
// leaf; if it is gone, fall back to the primary. Additive: older files
// omit it and restore focus to primary.
FocusKind string `json:"focusKind,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 GetSessionsPaneLayout ¶ added in v1.8.0
func GetSessionsPaneLayout(id string) *PaneLayoutJSON
GetSessionsPaneLayout returns a copy of the persisted Sessions tree for row id, or nil when none is stored.
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 PaneNoteTabJSON ¶ added in v1.3.0
PaneNoteTabJSON is one persisted note tab. Restore re-fetches the note through `td note`; the body is not cached.
type PaneResourceTabJSON ¶ added in v1.0.3
type PaneResourceTabJSON struct {
Provider string `json:"provider"`
Matcher string `json:"matcher,omitempty"`
Locator string `json:"locator,omitempty"`
// Collection and the view position beside it are written only for a
// plugin-shaped tab. A matched document omits all five.
Collection string `json:"collection,omitempty"`
Query string `json:"query,omitempty"`
View string `json:"view,omitempty"`
Sort string `json:"sort,omitempty"`
CursorID string `json:"cursorId,omitempty"`
// Filters is the applied filter set, {id: value}. Decode accepts a key the
// plugin no longer declares rather than refusing the record: the tab is
// still the tab, and the host drops an undeclared key at call time — which
// is also what lets a plugin rename a filter without orphaning saved tabs.
Filters map[string]string `json:"filters,omitempty"`
Scroll int `json:"scroll,omitempty"`
}
PaneResourceTabJSON is one persisted external plugin reference. It is deliberately plugin-neutral and deliberately reference-only: Sidecar re-asks on restore and never writes a returned title, field, body, error, URL, or any auth state to disk.
A reference necessarily includes the non-secret locator, such as CASH-1245, because that is the minimum needed to restore the pane the user had open.
It carries the Resource leaf's three tab shapes, exactly one per record:
- MATCHED: Matcher and Locator, Collection empty. The frozen resource protocol's shape, written by every release before the plugin protocol and read back unchanged.
- COLLECTION: Collection set, Matcher and Locator empty, plus the view position (Query, View, Sort, CursorID, Filters) so relaunch reopens the list the user was reading rather than the collection's default page.
- ITEM: Collection and Locator, Matcher empty. One row of a collection, which the plugin's get method addresses by collection and ID.
Decode refuses a record that is more than one shape or none of them. Which shape a half-written record meant is not something the host can infer, and inferring it is how a restored tab silently becomes a different tab.
func (PaneResourceTabJSON) Equal ¶ added in v1.14.0
func (t PaneResourceTabJSON) Equal(other PaneResourceTabJSON) bool
Equal reports whether two persisted resource tabs are the same record. It is spelled out because a collection tab carries an applied filter map, which makes the struct uncomparable with ==.
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 PluginBrowserViewJSON ¶ added in v1.14.0
type PluginBrowserViewJSON struct {
Query string `json:"query,omitempty"`
View string `json:"view,omitempty"`
Sort string `json:"sort,omitempty"`
Filters map[string]string `json:"filters,omitempty"`
}
PluginBrowserViewJSON is one global protocol tab's remembered view position. It is reference-only, exactly as a persisted pane tab is: no row, no title, no body, no error — only what the user asked for.
func GetPluginBrowserView ¶ added in v1.14.0
func GetPluginBrowserView(instance, collection string) PluginBrowserViewJSON
GetPluginBrowserView returns a global protocol tab's remembered view position. The zero value means nothing was saved, which is the collection's own defaults.
func (PluginBrowserViewJSON) Empty ¶ added in v1.14.0
func (v PluginBrowserViewJSON) Empty() bool
Empty reports that there is nothing worth remembering, so the entry is dropped rather than written as an object full of empty strings.
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"`
// PluginBrowserSplit is the shared plugin browser's list share, as a
// percentage of the content box, keyed by plugin instance ID. It is keyed
// per plugin rather than held globally because two plugins' tables are two
// different shapes: a split dragged wide for a four-column results table is
// the wrong one for a two-column source list.
PluginBrowserSplit map[string]int `json:"pluginBrowserSplit,omitempty"`
// PluginBrowserView is a global protocol tab's remembered view position,
// keyed "<instance>\x00<collection>". A pane's tab position is persisted
// with the pane; a global tab has no pane to be persisted with, and a
// search box that forgets what it was asked between launches is a search
// box the user has to re-type into every morning.
PluginBrowserView map[string]PluginBrowserViewJSON `json:"pluginBrowserView,omitempty"`
// NotificationCentreWidth is the app-level right panel's width in columns.
// It belongs to the shell rather than a plugin, but it is the same kind of
// preference as the pane widths above and is persisted the same way.
NotificationCentreWidth int `json:"notificationCentreWidth,omitempty"`
// The three legacy terminal-panel keys below are read once, converted into
// a pane-tree split, and cleared. Nothing writes them any more: the panel is
// a Shell leaf of the persisted pane layout, so its side, its size and its
// presence are the layout's to state.
LegacyTermPanelSize int `json:"termPanelSize,omitempty"` // Panel's own share (percentage, 0 = 50%)
LegacyTermPanelSide string `json:"termPanelLayout,omitempty"` // "bottom" or "right"
LegacyTermPanelVisible bool `json:"termPanelVisible,omitempty"` // Panel was up 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"`
// ContentDeck stores reference-only app-owned passive pane state by
// working-directory and plugin ID. Loaded bodies never cross this boundary.
ContentDeck map[string]json.RawMessage `json:"contentDeck,omitempty"`
// Worktree state: maps main repo path -> last active worktree path
LastWorktreePath map[string]string `json:"lastWorktreePath,omitempty"`
// LastRemoteWorktree maps hosts.ScopedKey(HostID, ProjectKey) to the
// host-side WorktreeKey last entered on that project. GetLastWorktreePath
// never reads this map: a remote path stored there would be treated as a
// local restore.
LastRemoteWorktree map[string]string `json:"lastRemoteWorktree,omitempty"`
// LastBoundLocation is the last host-qualified destination this TUI bound.
// It is never a remote filesystem path: restoring LastWorktreePath as a
// local checkout would follow a remote Root that happens to exist here.
LastBoundLocation *BoundLocation `json:"lastBoundLocation,omitempty"`
// Last selected global tab ("agents", "workspaces", or "tasks").
LastGlobalTab string `json:"lastGlobalTab,omitempty"`
// LastScope is the top-level space the user was in when Sidecar last left
// it: "global" or "project". Together with LastGlobalTab it is the whole of
// the remembered top-level selection — which space, and which tab inside it
// — so a relaunch reopens where the user was rather than always on the
// project workspace. Empty (a first run, or an upgrade from a version that
// never wrote it) means the project workspace, which is the behaviour those
// users already have.
//
// It is deliberately not keyed by working directory. The global space spans
// every configured project, so "I was in Sessions" is not a fact about the
// project Sidecar happened to be launched in, and keying it by one would
// make the answer depend on which checkout the user started from.
LastScope string `json:"lastScope,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"`
// SessionsHiddenHosts are registered host IDs whose rows the global
// Sessions browser withholds. It is a view filter, not a disable: the host
// stays connected and its notifications still arrive, so turning it back on
// is instant. Config's own `disabled` is the other thing, and it is
// deliberately kept separate — "not this week" is a fact about the machine,
// "not right now" is a fact about the list.
SessionsHiddenHosts []string `json:"sessionsHiddenHosts,omitempty"`
// SessionsSelected is the durable inventory row ID last shown in the
// global Sessions browser. Empty (fresh profile, or a version that never
// wrote it) leaves selection to the catalog's default.
SessionsSelected string `json:"sessionsSelected,omitempty"`
// SessionsPaneLayouts is the global Sessions browser's per-row pane trees,
// keyed by the same durable inventory IDs as SessionsSelected. Only
// composed trees are stored: a bare primary preview writes nothing.
SessionsPaneLayouts map[string]*PaneLayoutJSON `json:"sessionsPaneLayouts,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"`
// ProjectActivity is the latest recorded Sidecar activity per project,
// keyed by the project's cleaned absolute path. It is written when Sidecar
// binds a project, which is the one path both the switcher and
// `sidecar project switch` go through.
//
// It records events Sidecar observed; it is not a measurement of the
// directory. A project with no entry has had no recorded activity and reads
// "Unknown" rather than being given a plausible date, and nothing here is
// ever backfilled from a file time or a commit time.
ProjectActivity map[string]time.Time `json:"projectActivity,omitempty"`
// The project switcher's remembered view controls, stored as display
// labels for the same reason WorkspaceListSort is: the file reads plainly
// and the enums can be reordered without invalidating anyone's state. An
// unrecognised or empty value falls back to the surface's own default.
//
// They are deliberately not keyed by working directory. The switcher spans
// every configured project, so "I like the grid" is not a fact about the
// checkout Sidecar happened to launch in.
ProjectSwitcherSort string `json:"projectSwitcherSort,omitempty"`
ProjectSwitcherOrder string `json:"projectSwitcherOrder,omitempty"`
ProjectSwitcherView string `json:"projectSwitcherView,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.