store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package store is cc-pool's sole state layer: a modernc.org/sqlite (pure-Go) database holding accounts, usage samples, sessions, and the refresh log. It stores NO secrets — the Keychain is the only secret store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ID              int
	ConfigDir       string // exact string exported as CLAUDE_CONFIG_DIR
	KeychainService string
	KeychainAccount string
	Label           string // human note, e.g. an email or alias
	OverlayKind     string // "symlink" | "fuse"
	IsZero          bool   // true for acct-00
	CreatedAt       time.Time
}

Account is one pool account. ID is the account index; ID 0 is acct-00 (~/.claude, the canonical dir plain `claude` uses).

type RefreshEntry

type RefreshEntry struct {
	AccountID int
	TS        time.Time
	OK        bool
	Err       string
}

RefreshEntry is one credential-refresh attempt.

type Session

type Session struct {
	ID        int64
	AccountID int
	PID       int
	ConfigDir string
	StartedAt time.Time
	EndedAt   *time.Time
}

Session is a checkout of an account to a live claude process.

type Sticky added in v0.2.0

type Sticky struct {
	Cwd        string
	AccountID  int
	SelectedAt time.Time
}

Sticky is the last account selected for a working directory, used to keep resumed sessions on the same account for prompt-cache continuity.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store wraps the sqlite connection.

func Open

func Open(path string) (*Store, error)

Open opens (creating if needed) the database at path and applies the schema.

func (*Store) ActiveSessionCount

func (s *Store) ActiveSessionCount(accountID int) (int, error)

ActiveSessionCount returns the number of live sessions for an account.

func (*Store) Close

func (s *Store) Close() error

Close closes the database.

func (*Store) CloseDeadSessions

func (s *Store) CloseDeadSessions(alive map[int]bool) (int, error)

CloseDeadSessions ends every active session whose pid is not in alive.

func (*Store) CloseSession

func (s *Store) CloseSession(id int64) error

CloseSession marks a session ended by id.

func (*Store) DeleteAccount

func (s *Store) DeleteAccount(id int) error

DeleteAccount removes an account and its dependent rows.

func (*Store) GetAccount

func (s *Store) GetAccount(id int) (Account, error)

GetAccount returns one account by id.

func (*Store) GetSticky added in v0.2.0

func (s *Store) GetSticky(cwd string) (Sticky, bool, error)

GetSticky returns the sticky record for cwd, ok=false if none exists.

func (*Store) InsertUsageSample

func (s *Store) InsertUsageSample(u UsageSample) error

InsertUsageSample records one usage poll.

func (*Store) LastRefresh

func (s *Store) LastRefresh(accountID int) (RefreshEntry, bool, error)

LastRefresh returns the most recent refresh attempt for an account, ok=false if none.

func (*Store) LatestUsageSample

func (s *Store) LatestUsageSample(accountID int) (UsageSample, bool, error)

LatestUsageSample returns the most recent sample for an account, or ok=false.

func (*Store) ListAccounts

func (s *Store) ListAccounts() ([]Account, error)

ListAccounts returns all accounts ordered by id.

func (*Store) ListActiveSessions

func (s *Store) ListActiveSessions() ([]Session, error)

ListActiveSessions returns all live sessions across accounts.

func (*Store) LogRefresh

func (s *Store) LogRefresh(accountID int, ok bool, errMsg string) error

LogRefresh records a refresh attempt outcome.

func (*Store) NextAccountIndex

func (s *Store) NextAccountIndex() (int, error)

NextAccountIndex returns the smallest unused account index >= 1.

func (*Store) OpenSession

func (s *Store) OpenSession(accountID, pid int, configDir string) (int64, error)

OpenSession records a new checkout and returns its id.

func (*Store) PruneSticky added in v0.2.0

func (s *Store) PruneSticky(cutoff time.Time) (int, error)

PruneSticky deletes sticky rows last refreshed before cutoff, returning the number deleted.

func (*Store) RecentUsageSamples

func (s *Store) RecentUsageSamples(accountID, limit int) ([]UsageSample, error)

RecentUsageSamples returns up to limit of an account's most recent samples, newest first. Used to estimate the utilization burn rate.

func (*Store) UpsertAccount

func (s *Store) UpsertAccount(a Account) error

UpsertAccount inserts or replaces an account row by id.

func (*Store) UpsertSticky added in v0.2.0

func (s *Store) UpsertSticky(cwd string, accountID int, at time.Time) error

UpsertSticky records (or refreshes) the account last selected for cwd.

type UsageSample

type UsageSample struct {
	AccountID    int
	TS           time.Time
	Util5h       float64
	Util7d       float64
	Util7dOpus   float64
	Resets5h     time.Time
	Resets7d     time.Time
	Resets7dOpus time.Time
	RateLimited  bool
}

UsageSample is one poll of an account's quota windows. Utilization fields are stored as 0..100 "percent used" to feed scoring directly.

Jump to

Keyboard shortcuts

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