Documentation
¶
Overview ¶
Package store persists the window layout between runs.
Only the shape of the workspace is saved — tabs, splits, working directories, pane ids, and which agent and model each pane runs. 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
- Variables
- func BrowserProfileDir() (string, error)
- func ClearInstance() error
- func Dir() (string, error)
- func ForgetRecent(root string) error
- func Save(root string, s *State) error
- func SaveInstance(inst *Instance) error
- func SavePrefs(p Prefs) error
- func SaveSession(s *Session) error
- func SessionsDir() (string, error)
- func SweepSessions(maxAge time.Duration) (int, error)
- func TouchRecent(root string) error
- func TryLockStart() (release func(), err error)
- func WriteAtomic(path string, data []byte) error
- type Instance
- type Node
- type Pane
- type Prefs
- type Project
- type Session
- type State
- type Tab
Constants ¶
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 ¶
var ErrStartLocked = errors.New("another flockdeck is starting")
ErrStartLocked is TryLockStart's answer while another launch holds the lock.
Functions ¶
func BrowserProfileDir ¶
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 ¶
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 ¶
ForgetRecent drops a project from the remembered list.
func Save ¶
Save writes the state atomically so an interrupted write cannot leave a truncated layout behind.
func SaveInstance ¶
SaveInstance records this process as the running instance.
func SessionsDir ¶
SessionsDir returns the directory holding generated per-session settings.
func SweepSessions ¶
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 ¶
TouchRecent records that a project was opened, moving it to the front.
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
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 ¶
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.
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"`
// 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"`
}
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"`
// 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"`
}
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 or damaged, they are the defaults: nothing here is worth failing a start-up over.
type Session ¶
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 ¶
LoadSession returns the last workspace, or nil when there is none.
func (*Session) Landing ¶ added in v0.2.10
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 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.
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.