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 ¶
- type Account
- type RefreshEntry
- type Session
- type Store
- func (s *Store) ActiveSessionCount(accountID int) (int, error)
- func (s *Store) Close() error
- func (s *Store) CloseDeadSessions(alive map[int]bool) (int, error)
- func (s *Store) CloseSession(id int64) error
- func (s *Store) DeleteAccount(id int) error
- func (s *Store) GetAccount(id int) (Account, error)
- func (s *Store) InsertUsageSample(u UsageSample) error
- func (s *Store) LastRefresh(accountID int) (RefreshEntry, bool, error)
- func (s *Store) LatestUsageSample(accountID int) (UsageSample, bool, error)
- func (s *Store) ListAccounts() ([]Account, error)
- func (s *Store) ListActiveSessions() ([]Session, error)
- func (s *Store) LogRefresh(accountID int, ok bool, errMsg string) error
- func (s *Store) NextAccountIndex() (int, error)
- func (s *Store) OpenSession(accountID, pid int, configDir string) (int64, error)
- func (s *Store) RecentUsageSamples(accountID, limit int) ([]UsageSample, error)
- func (s *Store) UpsertAccount(a Account) error
- type UsageSample
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 ¶
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 Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps the sqlite connection.
func (*Store) ActiveSessionCount ¶
ActiveSessionCount returns the number of live sessions for an account.
func (*Store) CloseDeadSessions ¶
CloseDeadSessions ends every active session whose pid is not in alive.
func (*Store) CloseSession ¶
CloseSession marks a session ended by id.
func (*Store) DeleteAccount ¶
DeleteAccount removes an account and its dependent rows.
func (*Store) GetAccount ¶
GetAccount returns one account by id.
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 ¶
ListAccounts returns all accounts ordered by id.
func (*Store) ListActiveSessions ¶
ListActiveSessions returns all live sessions across accounts.
func (*Store) LogRefresh ¶
LogRefresh records a refresh attempt outcome.
func (*Store) NextAccountIndex ¶
NextAccountIndex returns the smallest unused account index >= 1.
func (*Store) OpenSession ¶
OpenSession records a new checkout and returns its id.
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 ¶
UpsertAccount inserts or replaces an account row by id.
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.