stats

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package stats provides session token usage statistics reading and formatting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractStatsSessionID

func ExtractStatsSessionID(basename string) string

ExtractStatsSessionID gets the session ID from a filename like "stats-abc123.jsonl".

Parameters:

  • basename: file basename

Returns:

  • string: session ID

func FormatDumpStats

func FormatDumpStats(entries []Entry, last int, jsonOut bool) []string

FormatDumpStats formats the last N entries in either JSON or human-readable format.

Parameters:

  • entries: stats entries to display
  • last: number of entries to show (0 for all)
  • jsonOut: whether to output as JSONL

Returns:

  • []string: formatted output lines

func FormatStatsHeader

func FormatStatsHeader() (string, string)

FormatStatsHeader formats the column header lines for human output.

Returns:

  • string: header line
  • string: separator line

func FormatStatsJSON

func FormatStatsJSON(entries []Entry) []string

FormatStatsJSON formats entries as raw JSONL lines.

Parameters:

  • entries: stats entries to serialize

Returns:

  • []string: JSON lines (marshal errors are silently skipped)

func FormatStatsLine

func FormatStatsLine(e *Entry) string

FormatStatsLine formats a single stats entry in human-readable format.

Parameters:

  • e: stats entry to format

Returns:

  • string: formatted stats line

func FormatStatsTimestamp

func FormatStatsTimestamp(ts string) string

FormatStatsTimestamp converts an RFC3339 timestamp to local time display using the DateTimePreciseFormat layout.

Parameters:

  • ts: RFC3339-formatted timestamp string

Returns:

  • string: local time formatted as "2006-01-02 15:04:05", or the original string on parse failure

func StreamStats

func StreamStats(w io.Writer, dir, sessionFilter string, jsonOut bool) error

StreamStats polls for new JSONL lines and writes them as they arrive.

Parameters:

  • w: output writer
  • dir: path to the state directory
  • sessionFilter: session ID prefix to filter by (empty for all)
  • jsonOut: whether to output as JSONL

Returns:

  • error: Always nil

Types

type Entry

type Entry struct {
	entity.Stats
	Session string `json:"session"`
}

Entry is a Stats with the source session ID for display.

func ParseStatsFile

func ParseStatsFile(path, sid string) ([]Entry, error)

ParseStatsFile reads all JSONL lines from a stats file.

Parameters:

  • path: absolute path to the stats file
  • sid: session ID for this file

Returns:

  • []Entry: parsed entries
  • error: non-nil on read failure

func ReadNewLines

func ReadNewLines(path string, offset int64, sid string) []Entry

ReadNewLines reads bytes from offset to end and parses JSONL lines.

Parameters:

  • path: absolute path to the stats file
  • offset: byte offset to start reading from
  • sid: session ID for this file

Returns:

  • []Entry: newly parsed entries

func ReadStatsDir

func ReadStatsDir(dir, sessionFilter string) ([]Entry, error)

ReadStatsDir reads all stats JSONL files, optionally filtered by session prefix.

Parameters:

  • dir: path to the state directory
  • sessionFilter: session ID prefix to filter by (empty for all)

Returns:

  • []Entry: sorted stats entries
  • error: non-nil on glob failure

Jump to

Keyboard shortcuts

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