store

package
v0.3.23 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 16 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 store persists the window layout between runs.

Only the shape of the workspace is saved — tabs, splits, working directories, pane ids, which agent and model each pane runs, and the size each pane's terminal was last drawn at. Conversation history lives in the agent's own transcript store and is reattached by id, which is why pane ids are generated as UUIDs.

Index

Constants

View Source
const Version = 2

Version is the schema version of the persisted state.

Version 2 is where a pane began saying which agent it runs and which model it was asked for. Version 1 knew only one agent, so its panes are "claude" or "shell"; they are brought forward on the way in rather than being thrown away, because a layout is the user's open tabs and losing them on an upgrade would be unforgivable.

Variables

View Source
var ErrStartLocked = errors.New("another flockdeck is starting")

ErrStartLocked is TryLockStart's answer while another launch holds the lock.

Functions

func BrowserProfileDir

func BrowserProfileDir() (string, error)

BrowserProfileDir returns the directory holding the browser profile used for the application window. Keeping it separate from the user's own profile means the window opens clean and does not disturb their browsing session.

On Windows it is kept in the local application data folder rather than beside the rest of the state, which is in the roaming one. The profile is a couple of hundred megabytes of browser components and caches, and where profiles roam Windows copies the roaming folder to and from the network at every logon, or keeps it on a network share where it is redirected; Chrome and Edge keep their own profiles out of it for the same reason. A profile an earlier build left in the roaming folder is moved across, or deleted once there is one here.

func ClearInstance

func ClearInstance() error

ClearInstance removes the record, and does nothing if it is already gone.

A record naming another process that is still running is left alone. There are two callers — an instance shutting down, and a launch that found the recorded address unreachable — and neither can tell whether the record it is about to delete is still its own. It often is not: an instance whose server briefly failed to answer a probe has its record cleared and then overwritten by the rival launch, and when the first one finally exits it would delete the second one's record, leaving a running instance that no later launch can find and attach to.

func Dir

func Dir() (string, error)

Dir returns the per-user directory holding Flockdeck's state.

It is kept private to the user. Below it sit the local server's auth token, the browser profile the application window signs in through (except on Windows, where BrowserProfileDir keeps it in the local folder instead), and the generated settings handed to each agent; the files themselves are written 0600, but a world-readable directory still lets any other account on the machine list them and read whatever was not written by this package.

func ForgetRecent

func ForgetRecent(root string) error

ForgetRecent drops a project from the remembered list.

func ProcessAlive added in v0.3.3

func ProcessAlive(pid int) bool

ProcessAlive reports whether a process id still names a running process. It is how `flockdeck -quit` tells that the instance it asked to stop has gone, rather than only stopped listening.

func ReadState added in v0.3.2

func ReadState(path string) ([]byte, error)

ReadState is readState for files other packages keep in the state directory, so a read of the key store made while a save is replacing it waits the save out rather than reading as no key at all.

func RenameWithRetry added in v0.3.2

func RenameWithRetry(src, dst string) error

RenameWithRetry is renameWithRetry for files other packages keep in the state directory. The key store is replaced the same way these files are and opened just as often -- by every pane that starts, by the picker asking whether an agent has a key, and by the virus scanner after each save -- so on Windows a save of it failed "Access is denied" whenever one of those had it open.

func Save

func Save(root string, s *State) error

Save writes the state atomically so an interrupted write cannot leave a truncated layout behind.

func SaveInstance

func SaveInstance(inst *Instance) error

SaveInstance records this process as the running instance.

func SavePrefs

func SavePrefs(p Prefs) error

SavePrefs writes the preferences.

func SaveSession

func SaveSession(s *Session) error

SaveSession records which projects are open.

func SessionsDir

func SessionsDir() (string, error)

SessionsDir returns the directory holding generated per-session settings.

func SweepSessions

func SweepSessions(maxAge time.Duration) (int, error)

SweepSessions removes files left behind by runs that were killed rather than closed, and returns how many it deleted: generated per-session settings, and the temporaries of writes that never reached their rename.

Files are only removed once they are older than maxAge. Normal shutdown deletes both as it goes, so what is left after that is orphaned.

Age settles it for a temporary: a write is a few milliseconds, so nothing part-way through is a day old. It does not settle it for a pane's settings. Those are written once when the pane starts and never touched again, so an agent that has been running since yesterday has a settings file that looks a day abandoned — and deleting it takes the hooks out from under a pane that is still working, which is how flockdeck knows whether that agent is waiting on its user. Whether they are in use is not a question about the file, so it is asked of the instance instead: while another one is running, its panes keep their settings and only the temporaries go.

That case is `flockdeck -solo`, which is the one way to get a second instance past a first that is still answering — including one left detached with its agents still going, which is exactly the run with the most to lose.

func TouchRecent

func TouchRecent(root string) error

TouchRecent records that a project was opened, moving it to the front.

func TouchRecents added in v0.3.1

func TouchRecents(roots ...string) error

TouchRecents records that several projects were opened, moving them to the front in the order given, the first given first.

It is one read of the list and at most one write. Recording them one at a time was a write each, and a start records every project it reopens around the one it was started on: on Windows each write came to eleven milliseconds of the start.

func TryLockStart added in v0.2.3

func TryLockStart() (release func(), err error)

TryLockStart takes the lock a launch holds from looking for a running instance until it has put itself on record.

A launch records itself only once its layout is restored, its agents are started and its server is answering, which takes a few hundred milliseconds on an empty state and longer with a real layout. Two launches inside that time, as an impatient second double-click makes, each found nothing on record and started an instance, and both resumed the same conversations. With the lock the second waits, finds the first on record and joins it.

The lock belongs to the process: the system lets it go if the process dies holding it, so a crash cannot leave every later launch waiting. release may be called more than once.

func WriteAtomic added in v0.2.0

func WriteAtomic(path string, data []byte) error

WriteAtomic is writeAtomic for the packages that keep a file of their own in the state directory. It carries the same promise — the old file or the new one, never a mixture — and the same 0600, which is what any file sitting beside the local server's token wants too.

Types

type Instance

type Instance struct {
	PID     int       `json:"pid"`
	URL     string    `json:"url"`
	Token   string    `json:"token"`
	Started time.Time `json:"started"`
}

Instance records a running flockdeck so a second launch can attach to it instead of starting a rival server, and so agents can outlive the window.

func LoadInstance

func LoadInstance() (*Instance, error)

LoadInstance returns the recorded running instance, or nil when there is none. A stale record left by a crash is not detected here: the caller has to probe the address, which is the only reliable test.

func (*Instance) StillRunning added in v0.3.4

func (inst *Instance) StillRunning() bool

StillRunning reports whether the process that made this record is still running.

Its id alone cannot say. Once that process has exited, the system is free to give the id to any process started since, and asking after the id then answers for that one. A process that started after the record was made cannot be the one that made it, so where the system says when a process started -- Windows and Linux -- that is checked as well. Elsewhere, and for a record with no start time, a live process id is taken at its word.

type Kept added in v0.3.3

type Kept struct {
	// What names what the file held, as a sentence would: "the saved layout
	// for /repo/a".
	What string
	// Path is where it is kept now.
	Path string
	// Why is why it was moved aside.
	Why KeptWhy
}

Kept is a state file this run moved aside: one it could not read, moved before the save that replaced it, or one it read and could not use.

func TakeKept added in v0.3.3

func TakeKept() []Kept

TakeKept returns the files moved aside since it was last called, and forgets them.

A file that could not be read at start is moved aside by the first save after, and the project it held came up on one fresh tab: without this, the only sign of either was a file with a new name in a folder nobody looks in. Whoever can tell the user asks, and says where their file went.

func (Kept) Sentence added in v0.3.4

func (k Kept) Sentence() string

Sentence says what happened to the file, and where it is now, in the words the user is told it in.

type KeptWhy added in v0.3.4

type KeptWhy int

KeptWhy is why a state file was moved aside.

const (
	// KeptUnread is a file this run could not read at all.
	KeptUnread KeptWhy = iota
	// KeptDamaged is a file that was read and made no sense.
	KeptDamaged
	// KeptNewer is a layout saved by a newer build, in a form this one does
	// not know.
	KeptNewer
)

type Node

type Node struct {
	Pane     *Pane   `json:"pane,omitempty"`
	Dir      string  `json:"dir,omitempty"` // "h" or "v"
	Weight   float64 `json:"weight,omitempty"`
	Children []*Node `json:"children,omitempty"`
}

Node mirrors layout.Node in a form that survives a round trip through JSON.

type Pane

type Pane struct {
	ID   string `json:"id"`
	Kind string `json:"kind"` // "agent" or "shell"
	Cwd  string `json:"cwd"`
	Name string `json:"name,omitempty"`
	// Agent is the id of the agent an agent pane runs, and Model the model it
	// was asked for. Both are absent for a shell pane, and an absent Agent on
	// an agent pane means whatever the catalog's default is — which is what a
	// layout written before panes could choose meant, and what a fresh pane
	// opened with one keystroke still means.
	Agent string `json:"agent,omitempty"`
	Model string `json:"model,omitempty"`
	// Routed names the rule that chose Model, and RoutedFrom the model the
	// pane would have run without it. Both are absent for a model chosen by
	// hand or by default, which is every pane of a layout written before
	// routing, and they come back with the pane so its header goes on saying
	// the model was routed.
	Routed     string `json:"routed,omitempty"`
	RoutedFrom string `json:"routedFrom,omitempty"`
	// Task is what a spawned pane was asked to do. It is kept so a restored
	// agent can still be told why its pane exists.
	Task string `json:"task,omitempty"`
	// Root is the project the pane belongs to, written only when it is not the
	// project of the tab holding it. A tab may show agents from more than one
	// project, and without this a borrowed pane would come back counted
	// against the tab's project: shown under the wrong name, stopped when the
	// wrong project was closed, and told it was working somewhere it was not.
	//
	// Absent — which is every layout written before this — means the tab's own
	// project, which is what those layouts meant.
	Root string `json:"root,omitempty"`
	// Conversation is the agent's own id for the conversation the pane is in,
	// written only when that is no longer the pane's id: Claude Code carries on
	// under a new one after /clear. Absent means the pane's id, which is what
	// every layout written before this meant.
	Conversation string `json:"conversation,omitempty"`
	// Cols and Rows are the size the pane's terminal was last drawn at, so a
	// restored pane starts at that size rather than at eighty by twenty-four.
	// Absent, which is every layout written before this, means the default.
	Cols int `json:"cols,omitempty"`
	Rows int `json:"rows,omitempty"`
	// Parent is the id of the pane whose agent started this one with its own
	// `flockdeck spawn`, absent for a pane the user started themselves. See
	// workspace.Pane.Parent.
	Parent string `json:"parent,omitempty"`
}

Pane is a single restored pane.

type Prefs

type Prefs struct {
	// HelpSeen records that the help has been opened at least once, which is
	// what keeps the first-run welcome from reappearing forever.
	HelpSeen bool `json:"helpSeen,omitempty"`
	// DismissedTips holds the ids of the inline hints that have been sent
	// away. A hint that is dismissed should stay dismissed.
	DismissedTips []string `json:"dismissedTips,omitempty"`
	// FontSize is the size the terminals are drawn at, in pixels. Zero is the
	// default size.
	FontSize int `json:"fontSize,omitempty"`
	// NotificationsOff stops the desktop notification raised when an agent
	// stops to wait while the window is behind something else.
	NotificationsOff bool `json:"notificationsOff,omitempty"`
	// Scrollback is how many lines each terminal keeps once they have
	// scrolled off the top. Zero is the default.
	Scrollback int `json:"scrollback,omitempty"`
	// UpdatesOff stops the background check for a new release, as the
	// FLOCKDECK_UPDATE=off environment variable does.
	UpdatesOff bool `json:"updatesOff,omitempty"`
	// CursorSteady stops the terminal cursors blinking.
	CursorSteady bool `json:"cursorSteady,omitempty"`
	// ScreenReader has every terminal keep an accessible copy of its lines,
	// which is what lets a screen reader read what the agents write. It costs
	// every terminal some speed, so it is off until it is asked for.
	ScreenReader bool `json:"screenReader,omitempty"`
	// CursorStyle is the shape of the terminal cursors: "bar" or
	// "underline". Empty is the default, a block.
	CursorStyle string `json:"cursorStyle,omitempty"`
	// FontFamily is the typeface the terminals are drawn in, as a CSS font
	// family list. Empty is the default.
	FontFamily string `json:"fontFamily,omitempty"`
	// Spend is how the pane headers show what the agents spend and how near
	// they are to their limits. Left out of the file while it is all defaults.
	Spend SpendPrefs `json:"spend,omitzero"`
	// Push is what the relay is asked to send the account's paired devices
	// when an agent has been waiting a while. Left out of the file while it is
	// all defaults.
	Push PushPrefs `json:"push,omitzero"`
	// contains filtered or unexported fields
}

Prefs is what the interface remembers about the person using it, as opposed to what it remembers about a workspace.

It cannot live in the browser. The server binds a fresh random port on every run, so each run is a different origin as far as the browser is concerned, and anything kept in local storage is gone by the next one.

func LoadPrefs

func LoadPrefs() Prefs

LoadPrefs reads the preferences. Absent, damaged or unreadable, they are the defaults: nothing here is worth failing a start-up over.

func ReadPrefs added in v0.3.2

func ReadPrefs() (Prefs, error)

ReadPrefs is LoadPrefs for a caller about to write the preferences back with one change made, which has to know whether what it read is what is there.

Absent or damaged, they are the defaults and no error: there is nothing there to lose. A file that could not be read is the defaults too, with the read's own failure, because written back those defaults and one change would stand in for every preference the user had set. The save would move the file aside first and keep it, but the settings would still be gone from the window until somebody went looking for the copy.

func (*Prefs) Dismiss

func (p *Prefs) Dismiss(id string) bool

Dismiss records that a hint has been sent away, and reports whether that changed anything.

func (Prefs) Dismissed

func (p Prefs) Dismissed(id string) bool

Dismissed reports whether a hint has been sent away.

type Project

type Project struct {
	Root     string    `json:"root"`
	LastUsed time.Time `json:"lastUsed"`
}

Project is a directory the user has opened.

func Recents

func Recents() ([]Project, error)

Recents returns known projects, most recently used first.

type PushPrefs added in v0.3.5

type PushPrefs struct {
	// Off stops asking the relay to notify the paired devices.
	Off bool `json:"off,omitempty"`
	// Anonymous has a notification say only that an agent on this machine
	// needs you, rather than naming the pane and its project.
	Anonymous bool `json:"anonymous,omitempty"`
	// DelaySeconds is how long a pane has to have been waiting before the
	// devices are told. Zero is the default, 30 seconds.
	DelaySeconds int `json:"delaySeconds,omitempty"`
}

PushPrefs are the preferences for push notifications to paired devices. Each is kept as nothing while it is the default, so a file written before there were any reads the same.

type Session

type Session struct {
	Open   []string `json:"open"`
	Active string   `json:"active"`
	// Away counts, for each project in Open whose folder was not there when
	// a run started -- a USB stick, a network drive not yet connected -- how
	// many starts in a row have found it missing. Such a project is kept in
	// the list for a few starts rather than dropped at the first, and let go
	// once they run out.
	Away map[string]int `json:"away,omitempty"`
}

Session is the set of projects that were open when the application last exited, so a restart brings the whole workspace back rather than only the directory named on the command line.

func LoadSession

func LoadSession() (*Session, error)

LoadSession returns the last workspace, or nil when there is none.

func (*Session) Landing added in v0.2.10

func (s *Session) Landing() string

Landing is the project a launch that named none goes back to: the one the user was last in, or failing that the first of the others that is still there, so one deleted project does not cost them the rest. It is "" when none of them is a directory any more, and for a nil session, so a caller with nothing saved can ask all the same.

type SpendPrefs added in v0.3.0

type SpendPrefs struct {
	// StatusLine says when a Claude pane's status line is routed through
	// Flockdeck, which is how its subscription limits are read: "on", "off",
	// or empty for only where the user has a status line of their own, which
	// it keeps. Those are the session.StatusLine constants.
	StatusLine string `json:"statusLine,omitempty"`
}

SpendPrefs are the preferences for spend and limits.

type State

type State struct {
	Version int    `json:"version"`
	Tabs    []Tab  `json:"tabs"`
	Active  int    `json:"active"`
	Root    string `json:"root,omitempty"` // directory the workspace was opened on
	// HandNames is set by every layout that says, tab by tab, whether a title
	// was chosen by hand. A layout without it was written before that was
	// kept, and a tab's title there may be either; Named being absent means
	// something only where this is set.
	HandNames bool `json:"handNames,omitempty"`
}

State is the whole persisted workspace.

func Load

func Load(root string) (*State, error)

Load reads the saved state for a workspace root. A missing file is not an error: it simply means there is nothing to restore.

It is for a caller about to restore what it reads, because it records how the read went: a layout that could not be read is kept from the next save, and one that could is not.

func Peek added in v0.3.2

func Peek(root string) (*State, error)

Peek is Load for a caller that only wants to look at what was saved and is not going to restore it, and so says nothing about whether the file could be read.

The save of a project nobody has been in since it was opened reads the tab it was last saved on. Through Load, that read taking a moment's trouble in its stride cleared the record of the one at start that had not: a project whose layout could not be read comes up on one fresh tab, and the timed save half a minute later then found nothing to keep and wrote that tab straight over every tab the user had saved.

type Tab

type Tab struct {
	Title string `json:"title,omitempty"`
	Focus string `json:"focus,omitempty"`
	Root  *Node  `json:"root"`
	// Named is set when Title was chosen by hand, and Auto is then the title
	// the tab would have had otherwise, which giving up the name puts back.
	// An empty Auto is not known.
	Named bool   `json:"named,omitempty"`
	Auto  string `json:"auto,omitempty"`
}

Tab is one tab and its pane tree.

Jump to

Keyboard shortcuts

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