index

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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.

View Source
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

type Price = claude.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

func New(opts Options) (*Store, error)

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

func (s *Store) Close() error

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

func (s *Store) Daily(days int) []core.DayUsage

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

func (s *Store) Entries(id string, limit int) ([]core.Entry, error)

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

func (s *Store) Limits() ([]core.RateLimit, time.Time)

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

func (s *Store) SearchPrompts(query string, limit int) []core.PromptHit

SearchPrompts finds prompts from the prompt history that contain query, case-insensitively, newest first. limit <= 0 means all.

func (*Store) Session

func (s *Store) Session(id string) (core.Session, bool)

Session returns one session by id.

func (*Store) Sessions

func (s *Store) Sessions() []core.Session

Sessions returns a snapshot of all sessions, most recently active first.

func (*Store) Stats

func (s *Store) Stats() Stats

Stats reports on the start-up scan. It is zero until Ready is closed, apart from Watches, Watching and Cache.

func (*Store) Subscribe

func (s *Store) Subscribe() (events <-chan core.Event, cancel func())

Subscribe delivers change events until cancel is called or the store is closed, and then closes the channel. Events are coalesced while the subscriber is not reading, and the store never waits for it.

Jump to

Keyboard shortcuts

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