report

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: Apache-2.0 Imports: 29 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package report renders a tokenhound.Report. Render is the only output path and every reporter is a pure function of the canonical Report.

Index

Constants

View Source
const (
	CardWidth  = 1200
	CardHeight = 630
)

Card geometry and colours (DESIGN.md share card).

View Source
const (
	// FormatTerminal is the plain-ASCII human summary.
	FormatTerminal = "terminal"
	// FormatJSON is the canonical JSON Report (docs/schema/report.v1.json).
	FormatJSON = "json"
	// FormatSARIF is SARIF 2.1.0 for code scanning, one run per target.
	FormatSARIF = "sarif"
	// FormatCard is the 1200x630 PNG share card (RenderCard); through Render it has
	// no label.
	FormatCard = "card"
	// FormatBadge is the shields.io flat-style SVG README badge (RenderBadge).
	FormatBadge = "badge"
)

Output formats Render implements.

View Source
const (
	// DefaultWidth is the terminal width assumed when TerminalOptions.Width is 0.
	DefaultWidth = 80
	// DefaultMaxRows is the number of rows shown without --all.
	DefaultMaxRows = 20
)

Terminal defaults.

View Source
const CardLabelMax = 40

CardLabelMax is the longest label the card draws, in characters.

View Source
const FormatGHA = "gha"

FormatGHA is GitHub Actions workflow commands: one ::error, ::warning or ::notice line per location of every non-suppressed finding.

Variables

View Source
var (
	// ErrUnknownFormat: the format is not one Render implements.
	ErrUnknownFormat = errors.New("report: unknown format")
	// ErrNilReport: Render was given no Report.
	ErrNilReport = errors.New("report: nil report")
	// ErrWrite: the writer failed.
	ErrWrite = errors.New("report: write failed")
)

Errors returned by Render.

Functions

func CardAltText

func CardAltText(d CardData) string

CardAltText is the card's sentence, also its PNG alt text: "2 live keys, $3,100 a day at risk, grade D". It always uses the live form, so it needs nothing but d.

func Formats

func Formats() []string

Formats returns the names of the formats Render implements, in documented order.

func GHA

func GHA(w io.Writer, r *tokenhound.Report, opts GHAOptions) error

GHA writes r to w as GitHub Actions workflow commands: one line per location of every non-suppressed finding, in Report finding order then location order (a finding without locations gets one line without file and line), at most 10 per level (GitHub's per-step limit); when lines are left out, the ninth notice slot onward is replaced by one closing notice that counts them. File locations are joined to Meta.PathPrefix so file= is a repository path. The level is ::error for a live key, ::warning for an unverified high-confidence key and ::notice otherwise. File and staged locations carry file, line and col properties; every other kind names the location in the message. Text is escaped per GitHub's workflow command rules and reduced to printable ASCII; only redacted key forms are printed. An empty or all-suppressed Report renders zero bytes. The output is a pure function of r and opts.

func Render

func Render(w io.Writer, format string, r *tokenhound.Report) error

Render writes r to w in format, one of Formats(). It is the only output path for a Report, and every reporter is a pure function of r: the same Report always renders the same bytes. Output is ASCII only, except the card, which is a PNG image.

func RenderBadge

func RenderBadge(w io.Writer, r *tokenhound.Report) error

RenderBadge writes r as a shields.io flat-style SVG README badge, 20px high: the left side reads "tokenhound" on grey, the right side "<grade> &#183; <n> live" on the grade colour. The <title> is the terminal headline sentence, which carries only counts, dollars and the grade. Text widths come from an embedded 11px Verdana table, so the output is a pure function of r, ASCII only and free of external references.

func RenderCard

func RenderCard(w io.Writer, d CardData) error

RenderCard writes d as a 1200x630 PNG share card: the wordmark top left (with the label under it when set), the card sentence, the grade tile on the grade colour with the letter in ink, a Hound amber accent rule and the footer. Fonts are embedded; the PNG carries exactly one text chunk, tEXt "Description" with CardAltText(d). The output is a pure function of d.

func RenderFix

RenderFix writes the fix plan of finding f (plan, as tokenhound.FixPlan returns it) in format: "terminal" prints a header (status word, provider, redacted key and dollars per day), the How line of a metered dollars figure and the numbered steps, with each command on its own unindented line; "json" prints fixEnvelope. The status word is the terminal summary's (LIVE, DEAD, UNKNOWN, RATE-LTD, UNVER). r supplies the provider name. Every string from r, f and plan is reduced to printable ASCII, and only redacted forms are printed. Only opts.Color is read. The output is a pure function of its arguments.

func RenderSARIF

func RenderSARIF(w io.Writer, r *tokenhound.Report) error

RenderSARIF writes r to w as SARIF 2.1.0: one run per target, one result per finding and target, with stable partialFingerprints. It is Render with FormatSARIF.

func RenderWith

func RenderWith(w io.Writer, format string, r *tokenhound.Report, opts TerminalOptions) error

RenderWith is Render with the options of the terminal format; the machine formats ignore them. The output is a pure function of r and opts.

Types

type CardData

type CardData struct {
	// LiveCount is the number of non-suppressed live findings.
	LiveCount int
	// DollarsAtRiskPerDay is the summed dollars at risk of those findings.
	DollarsAtRiskPerDay tokenhound.USD
	// Grade is the report grade; anything other than A to F is shown as "?".
	Grade tokenhound.Grade
	// Label is an optional caption drawn under the wordmark (--card-label). It is
	// reduced to printable ASCII and cut to CardLabelMax characters.
	Label string
}

CardData is everything the share card shows. It holds totals only: no repository, path, provider, detector, finding id or key can reach the card, because RenderCard takes nothing else.

func CardDataFrom

func CardDataFrom(r *tokenhound.Report, label string) CardData

CardDataFrom derives the card totals from r with the terminal tally (non-suppressed live findings and their dollars) and adds label.

type FormatInfo

type FormatInfo struct {
	// Name is the --format name, one of the closed AD-10 list.
	Name string
	// File is the file name the format is written as under -o <dir>; "" means the
	// format always goes to stdout (terminal).
	File string
	// Binary says the output is not text and is never written to a terminal.
	Binary bool
}

FormatInfo describes one registered output format.

func Lookup

func Lookup(name string) (FormatInfo, bool)

Lookup returns the description of the registered format name.

type GHAOptions

type GHAOptions struct {
	// NewOnly lowers every baselined finding (NewVsBaseline set and false) to
	// ::notice, so only new findings fail a pull request check.
	NewOnly bool
}

GHAOptions are the options of the gha format.

type TerminalOptions

type TerminalOptions struct {
	// Width is the terminal width in columns; 0 means 80. Under 80 the rows are
	// stacked as "key: value" lines, like Plain.
	Width int
	// Color adds ANSI colour codes to status words and grade letters. The text is the
	// same with or without them.
	Color bool
	// All shows every row instead of the first MaxRows.
	All bool
	// Quiet prints only the headline sentence.
	Quiet bool
	// Plain stacks every row as "key: value" lines.
	Plain bool
	// MaxRows caps the rows shown without All; 0 means DefaultMaxRows.
	MaxRows int
	// NotScanned lists things the CLI chose not to scan, for example "repo not
	// scanned"; each is added to the meta line. It is a CLI decision the Report cannot
	// derive, so it is not part of the Report.
	NotScanned []string
	// NewOnly says the run's fail_on leaves baselined findings out (--new-only); the
	// notes then count the findings whose new_vs_baseline is false.
	NewOnly bool
	// SessionKeys is how many keys the last Claude Code session-end scans found that
	// are still present; when positive the meta line adds "N new keys found after your
	// last Claude Code session". It is CLI state, not part of the Report.
	SessionKeys int
	// Rerun is the command that reruns this scan with verification on, for example
	// "tokenhound scan ./repo". The Next line names it when unverified findings are
	// shown; when empty it names "tokenhound scan".
	Rerun string
	// RerunVerify is Rerun with --verify, for example "tokenhound scan ./repo
	// --verify". After a scan with verification off the Next line names it with the
	// reason; when empty it names "tokenhound scan --verify".
	RerunVerify string
	// contains filtered or unexported fields
}

TerminalOptions are the render options of the terminal summary. The CLI decides every one of them (TTY, width, NO_COLOR, --no-color, --plain, --quiet, --all); the reporter reads nothing but the Report and these options. The zero value renders an 80 column table without colour and shows at most 20 rows.

Jump to

Keyboard shortcuts

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