backfill

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: AGPL-3.0 Imports: 14 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 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.

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 `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.

func RunViaAPI added in v0.5.0

func RunViaAPI(ctx context.Context, apiTarget string, transcriptDir string, opts Options) (*Result, error)

RunViaAPI asks a tapes API server to perform the usage sync.

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