backfill

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

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

func ScanTranscriptDir(dir string) ([]string, error)

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.

func (*Backfiller) Run

func (b *Backfiller) Run(ctx context.Context, transcriptDir string) (*Result, error)

Run scans transcripts and backfills usage data into the database.

type Options

type Options struct {
	DryRun  bool
	Verbose bool
}

Options configures backfill behavior.

type Result

type Result struct {
	Matched               int
	Skipped               int
	Unmatched             int
	TotalTokensBackfilled int
	TranscriptFiles       int
	TranscriptEntries     int
}

Result contains statistics from a backfill run.

func (*Result) Summary

func (r *Result) Summary() string

Summary returns a human-readable summary of the sync result.

type TranscriptBlock

type TranscriptBlock struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

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.

Jump to

Keyboard shortcuts

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