tally

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package tally parses fo's tally input format — a count→label distribution that renders as a Leaderboard view. The format is the minimal shape needed to feed arbitrary tallies (e.g. `sort | uniq -c` output) into fo without going through SARIF (whose parser computes scores internally and would discard caller-supplied counts).

Format:

# fo:tally [tool=<name>]
<count> <label>
<count> <label>
...

One header line, then count/label rows. Leading whitespace is tolerated on data rows so `sort | uniq -c` output (which right-aligns counts) is accepted verbatim. Lines beginning with `#` after the header are comments and ignored. Blank lines are ignored.

Index

Constants

View Source
const HeaderPrefix = "# fo:tally"

HeaderPrefix is the sentinel that marks tally input. Used by fo's stdin sniffer to route tally streams away from SARIF/test-json parsing.

Variables

View Source
var ErrMalformedRow = errors.New("tally: malformed row")

ErrMalformedRow wraps row-level shape and parse failures. Wrapped via fmt.Errorf("...: %w", ErrMalformedRow) at call sites — sentinel keeps err113 happy and lets callers errors.Is on a single root.

View Source
var ErrNoHeader = errors.New("tally: missing '# fo:tally' header")

ErrNoHeader is returned when input lacks the tally header line.

View Source
var ErrNoRows = errors.New("tally: no data rows")

ErrNoRows is returned when the header is present but no data rows followed.

Functions

func IsHeader

func IsHeader(data []byte) bool

IsHeader reports whether data begins with the tally header sentinel (after optional leading whitespace). Cheap; safe on partial peeked input.

Types

type Row

type Row struct {
	Label string  `json:"label"`
	Value float64 `json:"value"`
}

Row is one count/label pair.

type Tally

type Tally struct {
	Tool string `json:"tool,omitempty"`
	Rows []Row  `json:"rows"`
}

Tally is a parsed tally stream.

func Parse

func Parse(r io.Reader) (Tally, error)

Parse reads tally input from r and returns the parsed Tally. Malformed data lines (no count, non-numeric count) cause a parse error pinned to the line number; tolerant to leading whitespace and comment/blank lines.

func (Tally) RenderLLM

func (t Tally) RenderLLM(w io.Writer) error

RenderLLM emits a terse plain-text ranking. Used when fo's output mode is llm — bar charts are useless to AI consumers; a sorted "label\tcount" listing is the densest faithful form.

func (Tally) ToLeaderboard

func (t Tally) ToLeaderboard() view.Leaderboard

ToLeaderboard builds a view.Leaderboard from t. Rows are emitted in input order; Total is the sum of all values (used by the renderer to scale bars).

Jump to

Keyboard shortcuts

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