Documentation
¶
Overview ¶
Package stats provides session token usage statistics reading and formatting.
Index ¶
- func ExtractStatsSessionID(basename string) string
- func FormatDumpStats(entries []Entry, last int, jsonOut bool) []string
- func FormatStatsHeader() (string, string)
- func FormatStatsJSON(entries []Entry) []string
- func FormatStatsLine(e *Entry) string
- func FormatStatsTimestamp(ts string) string
- func StreamStats(w io.Writer, dir, sessionFilter string, jsonOut bool) error
- type Entry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractStatsSessionID ¶
ExtractStatsSessionID gets the session ID from a filename like "stats-abc123.jsonl".
Parameters:
- basename: file basename
Returns:
- string: session ID
func FormatDumpStats ¶
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 ¶
FormatStatsHeader formats the column header lines for human output.
Returns:
- string: header line
- string: separator line
func FormatStatsJSON ¶
FormatStatsJSON formats entries as raw JSONL lines.
Parameters:
- entries: stats entries to serialize
Returns:
- []string: JSON lines (marshal errors are silently skipped)
func FormatStatsLine ¶
FormatStatsLine formats a single stats entry in human-readable format.
Parameters:
- e: stats entry to format
Returns:
- string: formatted stats line
func FormatStatsTimestamp ¶
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 ¶
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 ¶
Entry is a Stats with the source session ID for display.
func ParseStatsFile ¶
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 ¶
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 ¶
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