Documentation
¶
Overview ¶
Package backfill extracts token usage from Claude Code transcripts and backfills historical nodes in the tapes database.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ScanTranscriptDir ¶
ScanTranscriptDir finds all JSONL files under the given directory.
Types ¶
type Backfiller ¶
type Backfiller struct {
// contains filtered or unexported fields
}
Backfiller matches Claude Code transcript usage data to tapes DB nodes.
func NewBackfiller ¶
func NewBackfiller(ctx context.Context, dbPath string, opts Options) (*Backfiller, func() error, error)
NewBackfiller creates a Backfiller connected to the given SQLite database. The returned cleanup function closes the database.
type Result ¶
type Result struct {
Matched int
Skipped int
Unmatched int
TotalTokensBackfilled int
TranscriptFiles int
TranscriptEntries int
}
Result contains statistics from a backfill run.
type TranscriptBlock ¶
TranscriptBlock represents a content block in a transcript message.
type TranscriptEntry ¶
type TranscriptEntry struct {
Type string `json:"type"`
UUID string `json:"uuid"`
ParentUUID *string `json:"parentUuid"`
Timestamp string `json:"timestamp"`
SessionID string `json:"sessionId"`
Message *TranscriptMessage `json:"message"`
}
TranscriptEntry represents a single line in a Claude Code JSONL transcript.
func ParseTranscript ¶
func ParseTranscript(path string) ([]TranscriptEntry, error)
ParseTranscript reads a JSONL file and returns assistant entries with usage data. It deduplicates by message ID, keeping the last (most complete) entry per message.
func (*TranscriptEntry) TextContent ¶
func (e *TranscriptEntry) TextContent() string
TextContent extracts the concatenated text from all text content blocks.
type TranscriptMessage ¶
type TranscriptMessage struct {
ID string `json:"id"`
Role string `json:"role"`
Model string `json:"model"`
Content []TranscriptBlock `json:"content"`
Usage *TranscriptUsage `json:"usage"`
StopReason json.RawMessage `json:"stop_reason"`
}
TranscriptMessage represents the message field within a JSONL entry.
type TranscriptUsage ¶
type TranscriptUsage struct {
InputTokens int `json:"input_tokens"`
OutputTokens int `json:"output_tokens"`
CacheCreationInputTokens int `json:"cache_creation_input_tokens"`
CacheReadInputTokens int `json:"cache_read_input_tokens"`
}
TranscriptUsage contains token counts from a Claude Code transcript entry.