stats

package
v0.0.0-beta Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package stats tracks session-level metrics for the assistant.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Snapshot

type Snapshot struct {
	StartTime    time.Time      `json:"start_time"`
	Interactions int            `json:"interactions"`
	Turns        int            `json:"turns"`
	Iterations   int            `json:"iterations"`
	ParseRetries int            `json:"parse_retries"`
	Compactions  int            `json:"compactions"`
	Tools        ToolsSnapshot  `json:"tools"`
	Tokens       TokensSnapshot `json:"tokens"`
}

Snapshot is a frozen, mutex-free copy of Stats for safe read-only use.

func (Snapshot) Duration

func (s Snapshot) Duration() time.Duration

Duration returns the elapsed time since the session started.

func (Snapshot) TopTools

func (s Snapshot) TopTools(n int) []ToolCount

TopTools returns the top N most-used tools sorted by frequency.

type Stats

type Stats struct {
	StartTime time.Time `json:"start_time"`

	Interactions int            `json:"interactions"`
	Turns        int            `json:"turns"`
	Iterations   int            `json:"iterations"`
	ParseRetries int            `json:"parse_retries"`
	Compactions  int            `json:"compactions"`
	Tools        ToolsSnapshot  `json:"tools"`
	Tokens       TokensSnapshot `json:"tokens"`
	// contains filtered or unexported fields
}

Stats holds cumulative session metrics. All mutation and read methods are safe for concurrent use.

func New

func New() *Stats

New creates a Stats with the start time set to now.

func (*Stats) Display

func (s *Stats) Display() string

Display returns a formatted multi-line stats string. Only formats data owned by Stats — context/message counts belong to ui.Status.

func (*Stats) Duration

func (s *Stats) Duration() time.Duration

Duration returns the elapsed time since the session started.

func (*Stats) MergeToolCalls

func (s *Stats) MergeToolCalls(tools map[string]int)

MergeToolCalls merges tool call counts from a subagent into the session stats.

func (*Stats) RecordCompaction

func (s *Stats) RecordCompaction()

RecordCompaction increments the compaction counter.

func (*Stats) RecordInteraction

func (s *Stats) RecordInteraction()

RecordInteraction increments the interaction counter (every ProcessInput call).

func (*Stats) RecordIteration

func (s *Stats) RecordIteration()

RecordIteration increments the iteration counter.

func (*Stats) RecordParseRetry

func (s *Stats) RecordParseRetry()

RecordParseRetry increments the parse retry counter.

func (*Stats) RecordTokens

func (s *Stats) RecordTokens(input, output int)

RecordTokens adds token counts from a single chat round.

func (*Stats) RecordToolCall

func (s *Stats) RecordToolCall(name string)

RecordToolCall records a successful tool execution.

func (*Stats) RecordToolError

func (s *Stats) RecordToolError(name string)

RecordToolError records a failed tool execution.

func (*Stats) RecordTurn

func (s *Stats) RecordTurn()

RecordTurn increments the LLM turn counter.

func (*Stats) Snapshot

func (s *Stats) Snapshot() Snapshot

Snapshot returns a frozen, mutex-free copy of the current stats.

func (*Stats) TopTools

func (s *Stats) TopTools(n int) []ToolCount

TopTools returns the top N most-used tools sorted by frequency.

type TokensSnapshot

type TokensSnapshot struct {
	In  int `json:"in"`
	Out int `json:"out"`
}

TokensSnapshot holds cumulative token counts.

type ToolCount

type ToolCount struct {
	Name  string
	Count int
}

ToolCount pairs a tool name with its invocation count.

type ToolsSnapshot

type ToolsSnapshot struct {
	Calls  int            `json:"calls"`
	Errors int            `json:"errors"`
	Freq   map[string]int `json:"freq,omitempty"`
}

ToolsSnapshot holds cumulative tool invocation metrics.

Jump to

Keyboard shortcuts

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