export

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package export serializes a stats.Report as JSON, CSV, or Markdown for consumption by scripts, dashboards, or human readers.

Index

Constants

View Source
const Schema = "v1"

Variables

This section is empty.

Functions

func ToCSV

func ToCSV(w io.Writer, r stats.Report) error

ToCSV writes per-day rows as CSV.

func ToJSON

func ToJSON(w io.Writer, label string, from, to time.Time, r stats.Report) error

ToJSON writes a full JSON dump.

func ToMarkdown

func ToMarkdown(w io.Writer, label string, r stats.Report) error

ToMarkdown writes a human-readable markdown report with overall + by-day + by-model.

Types

type ByModelCompact added in v0.3.0

type ByModelCompact struct {
	Model  string  `json:"model"`
	Turns  int     `json:"turns"`
	Tokens int     `json:"tokens"`
	Cost   float64 `json:"cost_usd"`
}

type CompactPayload added in v0.3.0

type CompactPayload struct {
	Range    string           `json:"range"`
	From     string           `json:"from,omitempty"`
	To       string           `json:"to,omitempty"`
	Prompts  int              `json:"prompts"`
	Turns    int              `json:"turns"`
	Tokens   int              `json:"tokens"`
	Cost     float64          `json:"cost_usd"`
	TopModel string           `json:"top_model,omitempty"`
	ByModel  []ByModelCompact `json:"by_model,omitempty"`
}

CompactPayload is the shape returned by `claumeter today` / `week` / `range` and the `/today` HTTP endpoint. Keep field names stable — widgets depend on them.

func NewCompact added in v0.3.0

func NewCompact(label string, from, to time.Time, r stats.Report) CompactPayload

NewCompact builds a CompactPayload for the given filtered report. `label` is the human-readable range name (e.g. "Today", "This week", "2026-04-01 → 2026-04-17"). `from` / `to` are the [from, to) window; zero values are omitted from the JSON.

type ComparisonDeltasDTO added in v0.6.0

type ComparisonDeltasDTO struct {
	Prompts             DeltaDTO `json:"prompts"`
	Turns               DeltaDTO `json:"turns"`
	InputTokens         DeltaDTO `json:"input_tokens"`
	CacheCreationTokens DeltaDTO `json:"cache_creation_tokens"`
	CacheReadTokens     DeltaDTO `json:"cache_read_tokens"`
	OutputTokens        DeltaDTO `json:"output_tokens"`
	TotalTokens         DeltaDTO `json:"total_tokens"`
	CostUSD             DeltaDTO `json:"cost_usd"`
}

ComparisonDeltasDTO holds one DeltaDTO per tracked metric.

type ComparisonPayload added in v0.6.0

type ComparisonPayload struct {
	Schema    string              `json:"schema"`
	Generated time.Time           `json:"generated"`
	A         ComparisonSideDTO   `json:"a"`
	B         ComparisonSideDTO   `json:"b"`
	Deltas    ComparisonDeltasDTO `json:"deltas"`
}

ComparisonPayload is the top-level JSON shape returned by NewComparison and the GET /compare endpoint.

func NewComparison added in v0.6.0

func NewComparison(
	aLabel string, aFrom, aTo time.Time, aTotals stats.Totals,
	bLabel string, bFrom, bTo time.Time, bTotals stats.Totals,
	cmp stats.Comparison,
) ComparisonPayload

NewComparison constructs a ComparisonPayload from two resolved range sides and the Comparison produced by stats.Compare.

type ComparisonSideDTO added in v0.6.0

type ComparisonSideDTO struct {
	Label string    `json:"label"`
	From  time.Time `json:"from,omitempty"`
	To    time.Time `json:"to,omitempty"`
	TotalsDTO
}

ComparisonSideDTO describes one side (A or B) of a comparison.

type CostBreakdownDTO added in v0.8.2

type CostBreakdownDTO struct {
	Overall   ModelBreakdownDTO   `json:"overall"`
	ByModel   []ModelBreakdownDTO `json:"by_model"`
	TotalCost float64             `json:"total_cost_usd"`
}

CostBreakdownDTO aggregates overall + per-model 5-bucket cost breakdowns.

type CostBucketDTO added in v0.8.2

type CostBucketDTO struct {
	Kind   string  `json:"kind"`
	Tokens int     `json:"tokens"`
	Rate   float64 `json:"rate_usd_per_mtok"`
	Cost   float64 `json:"cost_usd"`
	Pct    float64 `json:"pct_of_parent"`
}

CostBucketDTO is one of the 5 priced buckets (input / cache writes / cache read / output) for a model, with its tokens, rate, cost and share of total.

type DayDTO

type DayDTO struct {
	Day string `json:"day"`
	TotalsDTO
	ByModel map[string]TotalsDTO `json:"by_model,omitempty"`
}

type DeltaDTO added in v0.6.0

type DeltaDTO struct {
	A     float64 `json:"a"`
	B     float64 `json:"b"`
	Delta float64 `json:"delta"`
	Pct   float64 `json:"pct"`
	Gt    bool    `json:"gt"`
}

DeltaDTO is the wire shape for a single metric comparison.

type ModelBreakdownDTO added in v0.8.2

type ModelBreakdownDTO struct {
	Model     string          `json:"model"`
	Buckets   []CostBucketDTO `json:"buckets"`
	TotalCost float64         `json:"total_cost_usd"`
	Pct       float64         `json:"pct_of_grand_total"`
}

ModelBreakdownDTO is the 5-bucket breakdown for a single model.

type ModelDTO

type ModelDTO struct {
	Model string `json:"model"`
	TotalsDTO
}

type Payload

type Payload struct {
	Schema        string           `json:"schema"`
	Generated     time.Time        `json:"generated"`
	Range         RangeDTO         `json:"range"`
	Overall       TotalsDTO        `json:"overall"`
	ByDay         []DayDTO         `json:"by_day"`
	ByModel       []ModelDTO       `json:"by_model"`
	BySession     []SessionDTO     `json:"by_session"`
	ByProject     []ProjectDTO     `json:"by_project"`
	Tools         ToolsDTO         `json:"tools"`
	CostBreakdown CostBreakdownDTO `json:"cost_breakdown"`
}

Payload is the canonical shape returned by ToJSON. Field names are stable.

type ProjectDTO

type ProjectDTO struct {
	Cwd string `json:"cwd"`
	TotalsDTO
}

type RangeDTO

type RangeDTO struct {
	Label string    `json:"label"`
	From  time.Time `json:"from"`
	To    time.Time `json:"to"`
}

type SessionDTO

type SessionDTO struct {
	SessionID string    `json:"session_id"`
	Cwd       string    `json:"cwd"`
	FirstSeen time.Time `json:"first_seen"`
	LastSeen  time.Time `json:"last_seen"`
	Models    []string  `json:"models"`
	TotalsDTO
}

type SessionDetailDTO added in v0.6.0

type SessionDetailDTO struct {
	SessionID string           `json:"session_id"`
	Cwd       string           `json:"cwd"`
	FirstSeen time.Time        `json:"first_seen"`
	LastSeen  time.Time        `json:"last_seen"`
	Models    []string         `json:"models"`
	TotalsDTO                  // flattened at top level
	Turns     []SessionTurnDTO `json:"turns"`
}

SessionDetailDTO is the JSON shape returned by GET /session/:id.

func NewSessionDetail added in v0.6.0

func NewSessionDetail(sd stats.SessionDetail) SessionDetailDTO

NewSessionDetail converts a stats.SessionDetail to its DTO form.

type SessionTurnDTO added in v0.6.0

type SessionTurnDTO struct {
	Timestamp time.Time `json:"timestamp"`
	Model     string    `json:"model"`
	TotalsDTO           // flattened
	Tools     []string  `json:"tools,omitempty"`
}

SessionTurnDTO is one assistant turn inside a session.

type ToolEntryDTO

type ToolEntryDTO struct {
	Name  string `json:"name"`
	Count int    `json:"count"`
}

type ToolsDTO

type ToolsDTO struct {
	Total    int            `json:"total"`
	Builtins []ToolEntryDTO `json:"builtins"`
	MCPs     []ToolEntryDTO `json:"mcps"`
	Servers  []ToolEntryDTO `json:"mcp_servers"`
	Skills   []ToolEntryDTO `json:"skills"`
	Agents   []ToolEntryDTO `json:"sub_agents"`
}

type TotalsDTO

type TotalsDTO struct {
	Prompts               int     `json:"prompts"`
	Turns                 int     `json:"turns"`
	InputTokens           int     `json:"input_tokens"`
	CacheCreationTokens   int     `json:"cache_creation_tokens"`
	CacheCreation5mTokens int     `json:"cache_creation_5m_tokens"`
	CacheCreation1hTokens int     `json:"cache_creation_1h_tokens"`
	CacheReadTokens       int     `json:"cache_read_tokens"`
	OutputTokens          int     `json:"output_tokens"`
	TotalTokens           int     `json:"total_tokens"`
	CostUSD               float64 `json:"cost_usd"`
}

Jump to

Keyboard shortcuts

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