report

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 18 Imported by: 0 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 stored run. A report is a pure function of the run's ledger: Load reads only ledger.jsonl, and renderers use no clock, no environment and no map iteration order, so rendering the same run twice produces the same bytes.

Index

Constants

View Source
const JSONSchema = "spackle.report/v1"

JSONSchema names the envelope renderJSON writes. It changes only when a key is removed or changes meaning; adding a key keeps the version.

View Source
const SummaryFile = "summary.json"

SummaryFile is the name of the run summary inside a run directory.

Variables

This section is empty.

Functions

func CleanText added in v0.2.0

func CleanText(s string) string

CleanText makes text from the target safe to print on a terminal or to store in a plain-text file. Line endings become LF; every other C0 or C1 control character (ESC included), DEL, invisible Unicode format characters such as bidirectional overrides, and invalid UTF-8 are replaced with a visible backslash escape. Newline and tab are kept. A hostile repository therefore cannot move the cursor, recolor or retitle the operator's terminal, or reorder what the operator reads. Commands outside the reports that print run content, such as the run list, use it too.

func Ext

func Ext(format string) (string, bool)

Ext returns the file extension for a format, without the dot.

func Formats

func Formats() []string

Formats lists the supported format names in a fixed order.

func Render

func Render(format string, run Run, w io.Writer) error

Render writes the run in the named format.

func RunNames added in v0.2.0

func RunNames(runsDir string) ([]string, error)

RunNames returns the names of the run directories in runsDir, newest first. Run ids start with a UTC timestamp, so that is reverse name order. A runs directory that does not exist yet holds no runs.

func Terminal

func Terminal(run Run, w io.Writer, color bool) error

Terminal writes the plain-text report. With color false the output has no escape bytes at all. Text that came from the target is cleaned first, so the only escape sequences ever written are the fixed ones above.

func WriteSummary added in v0.2.0

func WriteSummary(runDir string, run Run) error

WriteSummary writes the summary of run into runDir.

Types

type ComparedFinding added in v0.2.0

type ComparedFinding struct {
	ID       string `json:"id"`
	Title    string `json:"title"`
	Severity string `json:"severity"`
	Location string `json:"location"`
	Status   string `json:"status"`
	// Change says what differs from the older run, for a finding in both.
	Change string `json:"change,omitempty"`
}

ComparedFinding is one finding in a comparison of two runs.

type Comparison added in v0.2.0

type Comparison struct {
	Older        string            `json:"older"`
	Newer        string            `json:"newer"`
	New          []ComparedFinding `json:"new"`
	Gone         []ComparedFinding `json:"gone"`
	StillPresent []ComparedFinding `json:"still_present"`
}

Comparison joins two runs on finding id and content fingerprint.

func Compare added in v0.2.0

func Compare(older, newer Run) Comparison

Compare reports which findings are only in the newer run, only in the older run, or in both. Dismissed findings are left out on both sides. Findings are matched by id first. The id includes the line, so the findings left over are then matched by their content fingerprint, which does not: a finding whose code only moved to another line is still present, with the change "moved from <old location>". Runs stored before fingerprints existed are matched by id alone. spackle runs compare and the MCP compare_runs tool both use it.

type Counts

type Counts struct {
	Critical, High, Medium, Low, None int
	Open, Fixed, Dismissed            int
	// PatchAvailable counts findings with a checked patch that is not applied.
	PatchAvailable int
	// Accepted counts findings a baseline entry accepted.
	Accepted     int
	Demonstrated int
}

Counts summarizes a run's findings. The severity buckets and Demonstrated cover every finding that is not dismissed (open, patch available and fixed), not only the open ones.

type Run

type Run struct {
	ID         string
	Version    string
	Command    string
	Target     string
	TargetKind string
	// TargetPath is the absolute directory a path target was scanned in.
	// It is empty for runs stored before it was recorded.
	TargetPath string
	// RepoPrefix is the scanned directory's path from the top of its git
	// work tree ("" at the top). Finding paths are relative to the scanned
	// directory; SARIF needs them relative to the repository.
	RepoPrefix string
	// Ref is the branch or tag a git URL target was scanned at, when one
	// was asked for.
	Ref    string
	Commit string
	// Since and Changed are the diff base of a diff scan: the --since
	// revision, or true for --changed. Both are empty for a full scan.
	Since   string
	Changed bool
	// Staged is true for a scan of staged changes (--staged).
	Staged bool
	// DiffScope is "lines" when a diff scan reported only the leads on the
	// changed lines, and empty when it reported whole changed files.
	DiffScope   string
	Mode        string // deterministic|agentic
	Provider    string
	Model       string
	Offline     bool
	Scope       string
	ScopeSource string
	Isolation   string
	StartedAt   time.Time
	EndedAt     time.Time
	Outcome     string

	Map      ledger.MapSummary
	Seeders  []ledger.SeederStatus
	Findings []finding.Finding // ranked; includes dismissed and fixed
	Skipped  []ledger.BudgetSkip
	// Rejected lists work that produced nothing: an investigation that
	// failed or whose draft was refused, and leads dropped at validation.
	Rejected []ledger.Reject
	Notes    []string
	Usage    Usage
}

Run is everything a renderer needs.

func Load

func Load(runDir string) (Run, error)

Load builds a Run from the ledger in runDir and nothing else.

func (Run) Active

func (r Run) Active() []finding.Finding

Active returns the findings that are not dismissed, in rank order.

func (Run) Count

func (r Run) Count() Counts

Count tallies the run's findings.

func (Run) Dismissed

func (r Run) Dismissed() []finding.Finding

Dismissed returns the findings the reviewer refuted, in rank order.

type StageUsage added in v0.2.0

type StageUsage struct {
	Calls        int
	InputTokens  int
	OutputTokens int
	CostUSD      float64
	// CostKnown is false when any call of the stage had no known price.
	CostKnown bool
	// Models lists the models the stage called, sorted.
	Models []string
}

StageUsage totals the model calls of one stage.

type Summary added in v0.2.0

type Summary struct {
	RunID    string    `json:"run_id"`
	Target   string    `json:"target"`
	Outcome  string    `json:"outcome"`
	Started  time.Time `json:"started"`
	Findings int       `json:"findings"`
	Counts   Counts    `json:"counts"`
	// ModelCalls and CostUSD total the run's model calls. CostKnown is
	// false when a call had no known price, and in a summary written
	// before these fields existed.
	ModelCalls int     `json:"model_calls"`
	CostUSD    float64 `json:"cost_usd"`
	CostKnown  bool    `json:"cost_known"`
	// LedgerBytes is the size of the ledger this summary was made from.
	LedgerBytes int64 `json:"ledger_bytes"`
}

Summary is the part of a run that a listing of runs shows. It is written next to the ledger when the run's reports are written, so that listing many runs does not read and decode every ledger. The ledger stays the only source of truth: a summary is used only while the ledger still has the size it had when the summary was written.

func LoadSummary added in v0.2.0

func LoadSummary(runDir string) (s Summary, ok bool)

LoadSummary returns the summary of the run in runDir. ok is false when there is none, when it cannot be read, or when the ledger has changed since it was written; the caller then loads the run from the ledger.

func SummaryOf added in v0.2.0

func SummaryOf(runDir string) (Summary, error)

SummaryOf returns the summary of the run in runDir: the stored one while it is current, otherwise one built from the ledger. It is what a listing of runs shows, so both listings (the CLI and MCP) read runs the same way.

func (Summary) Cost added in v0.2.0

func (s Summary) Cost() *float64

Cost is the run's model spend, or nil when it is not known.

func (Summary) CostText added in v0.2.0

func (s Summary) CostText() string

CostText is the run's model spend as a listing shows it.

type Usage

type Usage struct {
	ModelCalls   int
	InputTokens  int
	OutputTokens int
	CostUSD      float64
	// Estimated is true when any call's token counts were estimated.
	Estimated bool
	// CostKnown is false when any call used a model with no known price.
	CostKnown   bool
	SandboxRuns int
	Leads       int
	// ByStage splits the model calls by pipeline stage (planner,
	// investigator, prover, reviewer, fixer, mechanical, ...).
	ByStage map[string]StageUsage
}

Usage totals the run's accounting.

func (Usage) Stages added in v0.2.0

func (u Usage) Stages() []string

Stages returns the names in ByStage, sorted.

Jump to

Keyboard shortcuts

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