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 APIRunRequest ¶ added in v0.5.0
type APIRunRequest struct {
TranscriptDir string `json:"transcript_dir"`
DryRun bool `json:"dry_run,omitempty"`
Verbose bool `json:"verbose,omitempty"`
}
APIRunRequest is the request payload for the API-backed usage sync flow.
type Backfiller ¶
type Backfiller struct {
// contains filtered or unexported fields
}
Backfiller matches Claude Code transcript usage data to tapes DB nodes.
func NewBackfillerWithDriver ¶ added in v0.5.0
func NewBackfillerWithDriver(driver storage.Driver, opts Options) *Backfiller
NewBackfillerWithDriver creates a Backfiller using an existing storage driver.
type Result ¶
type Result struct {
Matched int `json:"matched"`
Skipped int `json:"skipped"`
Unmatched int `json:"unmatched"`
TotalTokensBackfilled int `json:"total_tokens_backfilled"`
TranscriptFiles int `json:"transcript_files"`
TranscriptEntries int `json:"transcript_entries"`
}
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.