export

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package export produces normalized, schema-stable JSON exports of session data.

The export format is independent of Devin CLI's internal SQLite schema, so it can be uploaded to a future web service without that service needing to know about schema migrations. This is the stable contract for sharing.

Index

Constants

View Source
const SchemaVersion = 1

SchemaVersion is the version of this normalized export format. Bump when the structure changes in a backward-incompatible way.

Variables

This section is empty.

Functions

func CompactStatus added in v0.2.0

func CompactStatus(snap StatusSnapshot) string

CompactStatus renders a single-line status: "Today: $X | Month: $Y | Sessions: Z".

func CopyDB added in v0.2.0

func CopyDB(srcPath, dstPath string) error

CopyDB copies the sessions database file to dstPath. This is a plain byte copy of the SQLite file. Returns an error if srcPath does not exist.

func FormatTitle added in v0.2.0

func FormatTitle(snap StatusSnapshot, format string) string

FormatTitle renders a terminal title from a template with {cost} and {sessions} placeholders. {cost} = today's cost, {sessions} = total count.

func SetTerminalTitle added in v0.2.0

func SetTerminalTitle(w io.Writer, title string)

SetTerminalTitle writes the OSC escape sequence to set the terminal title to the given string on stdout.

func ShellStatus added in v0.2.0

func ShellStatus(snap StatusSnapshot) string

ShellStatus renders just the today cost number (for PS1 integration).

func WriteBackupJSON added in v0.2.0

func WriteBackupJSON(w io.Writer, ss []model.Session, sourceDBPath string) error

WriteBackupJSON writes a normalized JSON backup of all sessions (with per-request detail) to w.

func WriteCSV added in v0.2.0

func WriteCSV(w io.Writer, ss []model.Session) error

WriteCSV writes sessions as CSV. Columns: id, title, model, project, cost, tokens, duration, created_at. The cost column uses the authoritative credit/ACU value when available, otherwise the pricing estimate.

func WriteHTML added in v0.2.0

func WriteHTML(w io.Writer, ss []model.Session) error

WriteHTML writes a self-contained interactive HTML snapshot with a styled session table and lightweight client-side filtering. No external assets.

func WriteJSON

func WriteJSON(w io.Writer, doc Document) error

WriteJSON writes the document as pretty-printed JSON to w.

func WriteMarkdown added in v0.2.0

func WriteMarkdown(w io.Writer, ss []model.Session) error

WriteMarkdown writes sessions as a paste-friendly GitHub-flavored markdown table. Numeric columns are right-aligned via the separator row.

func WriteReport added in v0.2.0

func WriteReport(w io.Writer, ss []model.Session, days int) error

WriteReport writes a text-based shareable usage receipt.

func WriteReportSVG added in v0.2.0

func WriteReportSVG(w io.Writer, ss []model.Session, days int) error

WriteReportSVG writes a simple SVG bar chart of daily cost for the window. It is intentionally minimal so it can be embedded in READMEs / PR comments.

func WriteState added in v0.2.0

func WriteState(snap StatusSnapshot, path string) error

WriteState writes a status snapshot atomically to a state file (JSON). The parent directory is created if missing.

Types

type BackupDocument added in v0.2.0

type BackupDocument struct {
	BackupType   string    `json:"backup_type"` // "json" | "db"
	GeneratedAt  time.Time `json:"generated_at"`
	SourceDBPath string    `json:"source_db_path,omitempty"`
	Document     Document  `json:"document"`
}

BackupDocument is the normalized JSON backup container. It wraps the existing export Document with backup-specific metadata.

type Document

type Document struct {
	ExportSchema int          `json:"export_schema"`
	GeneratedAt  time.Time    `json:"generated_at"`
	Sessions     []ExpSession `json:"sessions"`
}

Document is the top-level export container.

func BuildDocument

func BuildDocument(ss []model.Session, includeRequests bool) Document

BuildDocument creates a normalized export from sessions. includeRequests controls whether per-request detail is included.

type ExpRequest

type ExpRequest struct {
	RequestID        string    `json:"request_id"`
	Model            string    `json:"model"`
	FinishReason     string    `json:"finish_reason"`
	CreatedAt        time.Time `json:"created_at"`
	TTFTMs           float64   `json:"ttft_ms"`
	TotalTimeMs      float64   `json:"total_time_ms"`
	InputTokens      int64     `json:"input_tokens"`
	OutputTokens     int64     `json:"output_tokens"`
	CacheReadTokens  int64     `json:"cache_read_tokens"`
	CacheWriteTokens int64     `json:"cache_write_tokens"`
	TokensPerSec     float64   `json:"tokens_per_sec"`
	ContextSize      int       `json:"context_size"`
	ToolCalls        []string  `json:"tool_calls"`
}

ExpRequest is a per-request record (assistant turn).

type ExpSession

type ExpSession struct {
	ID               string         `json:"id"`
	Title            string         `json:"title"`
	Project          string         `json:"project"`
	WorkingDir       string         `json:"working_dir"`
	Model            string         `json:"model"`
	AgentMode        string         `json:"agent_mode"`
	BackendType      string         `json:"backend_type"`
	CreatedAt        time.Time      `json:"created_at"`
	LastActivityAt   time.Time      `json:"last_activity_at"`
	DurationSec      float64        `json:"duration_sec"`
	Requests         int            `json:"requests"`
	InputTokens      int64          `json:"input_tokens"`
	OutputTokens     int64          `json:"output_tokens"`
	CacheReadTokens  int64          `json:"cache_read_tokens"`
	CacheWriteTokens int64          `json:"cache_write_tokens"`
	CreditCost       float64        `json:"credit_cost"`
	ACUCost          float64        `json:"acu_cost"`
	EstimatedCost    float64        `json:"estimated_cost"`
	IsFree           bool           `json:"is_free"`
	ToolCalls        map[string]int `json:"tool_calls"`
	Requests2        []ExpRequest   `json:"requests_detail,omitempty"`
}

ExpSession is a normalized session for export.

type ReportSummary added in v0.2.0

type ReportSummary struct {
	Window    string
	From      time.Time
	To        time.Time
	Sessions  int
	Requests  int
	InputTok  int64
	OutputTok int64
	Cost      float64
	Daily     []report.TimeRow
}

ReportSummary is the aggregated usage window used by the shareable report.

func BuildReportSummary added in v0.2.0

func BuildReportSummary(ss []model.Session, days int) ReportSummary

BuildReportSummary aggregates sessions created within the last `days` days into a ReportSummary. days<=0 means "all time".

type StatusSnapshot added in v0.2.0

type StatusSnapshot struct {
	GeneratedAt time.Time `json:"generated_at"`
	TodayCost   float64   `json:"today_cost"`
	MonthCost   float64   `json:"month_cost"`
	Sessions    int       `json:"sessions"`
}

StatusSnapshot is a compact usage snapshot used by status-bar integrations.

func BuildStatusSnapshot added in v0.2.0

func BuildStatusSnapshot(ss []model.Session) StatusSnapshot

BuildStatusSnapshot computes today's and this month's cost plus total non-hidden session count.

Jump to

Keyboard shortcuts

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