Documentation
¶
Overview ¶
Package index implements core.Store over a Claude directory. At start-up it reads every transcript in a bounded worker pool, continuing from an on-disk cache of derived numbers where it can, and publishes sessions as they complete. After that it keeps them current by watching the files, with a slow poll as a safety net.
Concurrency: one goroutine (run) owns the parse state of every session and is the only writer of the published summaries; a second (watch) turns file-system events into pending work for it. The public methods read the published summaries under a mutex and never wait for parsing.
Index ¶
- Variables
- type Options
- type Price
- type Stats
- type Store
- func (s *Store) Close() error
- func (s *Store) Daily(days int) []core.DayUsage
- func (s *Store) Entries(id string, limit int) ([]core.Entry, error)
- func (s *Store) Limits() ([]core.RateLimit, time.Time)
- func (s *Store) Ready() <-chan struct{}
- func (s *Store) SearchPrompts(query string, limit int) []core.PromptHit
- func (s *Store) Session(id string) (core.Session, bool)
- func (s *Store) Sessions() []core.Session
- func (s *Store) Stats() Stats
- func (s *Store) Subscribe() (events <-chan core.Event, cancel func())
Constants ¶
This section is empty.
Variables ¶
var ErrClaudeDir = errors.New("index: cannot read the Claude directory")
ErrClaudeDir is returned by New, wrapped with the directory and the reason, when the Claude directory is missing or cannot be read.
var ErrUnknownSession = errors.New("index: unknown session")
ErrUnknownSession is returned by Entries for a session id the store does not know.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// ClaudeDir is the Claude directory. Empty means $CLAUDE_CONFIG_DIR,
// else ~/.claude.
ClaudeDir string
// CacheDir holds the index cache. Empty means $XDG_CACHE_HOME/ccdeck,
// else ~/.cache/ccdeck.
CacheDir string
// Prices maps usage keys (model ids, or model ids with a tier suffix
// such as "+fast"; see claude.Prices) to prices that override Claude
// Code's own price cache, typically the [prices] table of the config
// file.
Prices map[string]Price
// MeterDir is the status-line meter's state directory (see package
// meter). Empty means the meter is off: no reports, no limits.
MeterDir string
// Logger receives warnings about unreadable files, failed watches and
// cache problems. Nil discards them.
Logger *slog.Logger
}
Options configures a Store. Every field is optional.
type Price ¶
Price is what a model costs, in dollars per million tokens (WebSearch is dollars per request).
type Stats ¶
type Stats struct {
Sessions int // sessions published, live ones without a transcript included
Files int // transcripts read, main and subagent
Resumed int // of Files, those continued from the cache
Lines int // non-blank transcript lines folded
Skipped int // malformed lines among them
ScanTime time.Duration // from New until every session was published
Watches int // directories watched now
Watching bool // fsnotify works; false means polling only
Cache string // the cache file; empty when there is no cache directory
}
Stats describes the start-up scan, for diagnostics.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a live core.Store over one Claude directory. Create it with New and release it with Close.
func New ¶
New starts a Store. It returns at once: sessions appear as the start-up scan publishes them, and Ready is closed when the scan is complete.
func (*Store) Close ¶
Close stops the watchers and background work, saves the cache, and closes every subscription. It is safe to call more than once.
func (*Store) Daily ¶
Daily returns usage for the last days local calendar days, oldest first, including days with no activity. Usage includes subagents; CostUSD is an estimate, 0 unless every model used that day has a price.
func (*Store) Entries ¶
Entries returns up to limit most recent conversation entries of a session's main thread, oldest first; limit <= 0 means all. The conversations of recently viewed sessions are kept and extended as their transcripts grow. A live session with no transcript yet has no entries.
func (*Store) Limits ¶
Limits returns the rate-limit windows of the newest status-line report that has any, without the windows whose reset time has passed, and when that report was written. Both are zero when the meter is off, has never run, or every window has reset.
func (*Store) Ready ¶
func (s *Store) Ready() <-chan struct{}
Ready is closed when the start-up scan has published every session, or when the store is closed first.
func (*Store) SearchPrompts ¶
SearchPrompts finds prompts from the prompt history that contain query, case-insensitively, newest first. limit <= 0 means all.