Documentation
¶
Index ¶
- Constants
- func MarshalToolData(claudeSessionID string, claudeDetectedAt time.Time, geminiSessionID string, ...) json.RawMessage
- func MigrateFromJSON(jsonPath string, db *StateDB) (int, int, error)
- func SetGlobal(db *StateDB)
- func UnmarshalToolData(data json.RawMessage) (claudeSessionID string, claudeDetectedAt time.Time, geminiSessionID string, ...)
- type GroupRow
- type InstanceRow
- type StateDB
- func (s *StateDB) AliveInstanceCount() (int, error)
- func (s *StateDB) CleanDeadInstances(timeout time.Duration) error
- func (s *StateDB) Close() error
- func (s *StateDB) DB() *sql.DB
- func (s *StateDB) DeleteGroup(path string) error
- func (s *StateDB) DeleteInstance(id string) error
- func (s *StateDB) GetMeta(key string) (string, error)
- func (s *StateDB) Heartbeat() error
- func (s *StateDB) IsEmpty() (bool, error)
- func (s *StateDB) LastModified() (int64, error)
- func (s *StateDB) LoadGroups() ([]*GroupRow, error)
- func (s *StateDB) LoadInstances() ([]*InstanceRow, error)
- func (s *StateDB) Migrate() error
- func (s *StateDB) ReadAllStatuses() (map[string]StatusRow, error)
- func (s *StateDB) RegisterInstance(isPrimary bool) error
- func (s *StateDB) SaveGroups(groups []*GroupRow) error
- func (s *StateDB) SaveInstance(inst *InstanceRow) error
- func (s *StateDB) SaveInstances(insts []*InstanceRow) error
- func (s *StateDB) SetAcknowledged(id string, ack bool) error
- func (s *StateDB) SetMeta(key, value string) error
- func (s *StateDB) Touch() error
- func (s *StateDB) UnregisterInstance() error
- func (s *StateDB) UpdateInstanceField(id, field string, value any) error
- func (s *StateDB) WriteStatus(id, status, tool string) error
- type StatusRow
Constants ¶
const SchemaVersion = 1
SchemaVersion tracks the current database schema version. Bump this when adding migrations.
Variables ¶
This section is empty.
Functions ¶
func MarshalToolData ¶
func MarshalToolData( claudeSessionID string, claudeDetectedAt time.Time, geminiSessionID string, geminiDetectedAt time.Time, geminiYoloMode *bool, geminiModel string, openCodeSessionID string, openCodeDetectedAt time.Time, codexSessionID string, codexDetectedAt time.Time, latestPrompt string, loadedMCPNames []string, toolOptionsJSON json.RawMessage, ) json.RawMessage
MarshalToolData creates a tool_data JSON blob from individual fields. This is the forward path: Instance fields -> JSON blob for SQLite storage.
func MigrateFromJSON ¶
MigrateFromJSON reads a sessions.json file and inserts all data into the StateDB. Returns the number of instances and groups migrated.
func UnmarshalToolData ¶
func UnmarshalToolData(data json.RawMessage) ( claudeSessionID string, claudeDetectedAt time.Time, geminiSessionID string, geminiDetectedAt time.Time, geminiYoloMode *bool, geminiModel string, openCodeSessionID string, openCodeDetectedAt time.Time, codexSessionID string, codexDetectedAt time.Time, latestPrompt string, loadedMCPNames []string, toolOptionsJSON json.RawMessage, )
UnmarshalToolData extracts individual fields from the tool_data JSON blob. This is the reverse path: JSON blob from SQLite -> individual Instance fields.
Types ¶
type InstanceRow ¶
type InstanceRow struct {
ID string
Title string
ProjectPath string
GroupPath string
Order int
Command string
Wrapper string
Tool string
Status string
TmuxSession string
CreatedAt time.Time
LastAccessed time.Time
ParentSessionID string
WorktreePath string
WorktreeRepo string
WorktreeBranch string
ToolData json.RawMessage // JSON blob for tool-specific data
}
InstanceRow represents a session row in the database.
type StateDB ¶
type StateDB struct {
// contains filtered or unexported fields
}
StateDB wraps a SQLite database for session/group persistence. Thread-safe for concurrent use from multiple goroutines within one process. Multiple OS processes can safely read/write via WAL mode + busy timeout.
func GetGlobal ¶
func GetGlobal() *StateDB
GetGlobal returns the global StateDB instance (may be nil).
func (*StateDB) AliveInstanceCount ¶
AliveInstanceCount returns how many TUI instances have fresh heartbeats.
func (*StateDB) CleanDeadInstances ¶
CleanDeadInstances removes heartbeat entries that haven't been updated within timeout.
func (*StateDB) DeleteGroup ¶
DeleteGroup removes a group by path.
func (*StateDB) DeleteInstance ¶
DeleteInstance removes an instance by ID.
func (*StateDB) LastModified ¶
LastModified returns the last_modified timestamp from metadata.
func (*StateDB) LoadGroups ¶
LoadGroups returns all groups ordered by sort_order.
func (*StateDB) LoadInstances ¶
func (s *StateDB) LoadInstances() ([]*InstanceRow, error)
LoadInstances returns all instances ordered by sort_order.
func (*StateDB) Migrate ¶
Migrate creates tables if they don't exist and runs any pending migrations.
func (*StateDB) ReadAllStatuses ¶
ReadAllStatuses returns status + acknowledged flag for every instance.
func (*StateDB) RegisterInstance ¶
RegisterInstance records this process as an active TUI instance.
func (*StateDB) SaveGroups ¶
SaveGroups replaces all groups in a single transaction.
func (*StateDB) SaveInstance ¶
func (s *StateDB) SaveInstance(inst *InstanceRow) error
SaveInstance inserts or replaces a single instance.
func (*StateDB) SaveInstances ¶
func (s *StateDB) SaveInstances(insts []*InstanceRow) error
SaveInstances inserts or replaces multiple instances in a single transaction.
func (*StateDB) SetAcknowledged ¶
SetAcknowledged sets or clears the acknowledged flag for an instance.
func (*StateDB) Touch ¶
Touch updates a metadata timestamp that other instances can poll to detect changes.
func (*StateDB) UnregisterInstance ¶
UnregisterInstance removes this process from the heartbeat table.
func (*StateDB) UpdateInstanceField ¶
UpdateInstanceField updates a single column for a given instance. field must be a valid column name (caller is responsible for safety).
func (*StateDB) WriteStatus ¶
WriteStatus updates the status and tool for an instance.