importer

package
v0.0.0-...-53bd38a Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 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 importer writes sessions from an agent's own transcripts on disk into the session archive and the cost ledger, as sessions with the imported mark.

Index

Constants

View Source
const StoppedArchiveFull = "archive full"

StoppedArchiveFull is AgentReport.Stopped when the archive has no headroom left.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentReport

type AgentReport struct {
	Agent          string `json:"agent"`
	Imported       int    `json:"imported"`
	Replaced       int    `json:"replaced"`
	SkippedLive    int    `json:"skippedLive"`
	SkippedCurrent int    `json:"skippedCurrent"`
	SkippedLines   int    `json:"skippedLines"`
	SkippedExpired int    `json:"skippedExpired,omitempty"` // older than the archive's retention
	Unreadable     int    `json:"unreadable,omitempty"`     // sessions whose transcript could not be read
	NotImported    int    `json:"notImported,omitempty"`    // left after an archive-full stop
	Stopped        string `json:"stopped,omitempty"`        // "archive full" or ""
	Error          string `json:"error,omitempty"`
}

AgentReport is the result of the import for one agent.

func Run

func Run(ctx context.Context, src Source, o Options) AgentReport

Run imports the sessions of one source. A session the proxy recorded live is never changed. A cancelled ctx stops the run between two sessions.

A session that the archive removed (an erase, a clear, max_bytes or retention_days) is new again here, but its ledger rows are not removed with it. When the archive has a forget record for the session, toLedger skips each turn in the span of that record. With no record, toLedger skips each turn that has a live row near it, or a row near it that an earlier run imported.

A session older than the archive's retention_days is skipped, so its turns do not reach the ledger even when the ledger keeps rows longer.

type Options

type Options struct {
	Archive *archive.Archive // required
	Store   *session.Store   // the live store; nil in tests
	Ledger  *ledger.Writer   // nil: no ledger rows
	Rates   pricing.Resolver
	Since   time.Time
	DryRun  bool
	// Progress gets the source's progress. nil: none.
	Progress func(done, total int)
}

Options configures Run.

type Progress

type Progress struct {
	Agent string `json:"agent"`
	Done  int    `json:"done"`
	Total int    `json:"total"`
}

Progress is one line of POST /v1/import with Request.Progress: Done of the Total sessions that the source of Agent found.

type Report

type Report struct {
	DryRun bool          `json:"dryRun,omitempty"`
	Agents []AgentReport `json:"agents"`
}

Report is the response body of POST /v1/import.

type Request

type Request struct {
	Agent  string    `json:"agent,omitempty"` // "" = every registered source
	Since  time.Time `json:"since,omitempty"`
	DryRun bool      `json:"dryRun,omitempty"`
	// Progress asks for Progress lines before the Report. See POST /v1/import.
	Progress bool `json:"progress,omitempty"`
}

Request is the body of POST /v1/import.

type Session

type Session struct {
	ID       string               // the Cortex session id
	Updated  time.Time            // At of the newest event
	SizeHint int64                // bytes of the files read, for the archive size check
	Events   []model.SessionEvent // request/response pairs in order; Seq unset
	Skipped  int                  // lines not recognized
	// Unreadable is true when the session's main transcript could not be read. Run counts the
	// session in AgentReport.Unreadable, and does not write it.
	Unreadable bool
}

Session is one agent session that a Source read.

type Source

type Source interface {
	// Agent is the agent name, for example "claude-code".
	Agent() string
	// PricingHost is the host for settle.Input.Host, for example "api.anthropic.com".
	PricingHost() string
	// Sessions yields the sessions newest first (by file mtime). A zero since gives all
	// sessions. A non-nil error stops the import of this agent only, and Run reports it.
	// Before it parses a session, it calls skip with the session id and a time that is not
	// before the parsed Updated. When skip gives true, it does not parse or yield the session.
	// It calls progress (never nil) with the sessions done and the sessions found, before each
	// session and once after the last.
	Sessions(since time.Time, skip func(id string, updated time.Time) bool, progress func(done, total int)) iter.Seq2[Session, error]
}

Source reads the sessions of one agent from its store on disk.

Directories

Path Synopsis
Package bob is the importer source for Bob (Bob Shell and Bob IDE).
Package bob is the importer source for Bob (Bob Shell and Bob IDE).
Package claude is the importer source for Claude Code.
Package claude is the importer source for Claude Code.
Package codex is the importer source for Codex.
Package codex is the importer source for Codex.
Package opencode is the importer source for OpenCode.
Package opencode is the importer source for OpenCode.
Package pi is the importer source for Pi (pi.dev).
Package pi is the importer source for Pi (pi.dev).
Package sqlitecli reads a SQLite database through the sqlite3 program, so that no module links a SQLite driver.
Package sqlitecli reads a SQLite database through the sqlite3 program, so that no module links a SQLite driver.

Jump to

Keyboard shortcuts

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