stats

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 14 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 stats is the pure arithmetic behind the all-time FindingRollup objects: micro-USD cost parsing, per-scope delta computation, and exactly-once ledger application. The rollup reconciler supplies objects and writes results; this package never touches the cluster, so all of it is table-testable.

Index

Constants

View Source
const MinCalibrationRuns = 3

MinCalibrationRuns is the fewest runs an estimate history must hold before it is worth showing an agent as guidance. Below this the average is noise, and anchoring the next estimate on noise is worse than saying nothing.

Variables

This section is empty.

Functions

func Apply

func Apply(
	st *v1alpha1.FindingRollupStatus, ledgerKey string,
	stage *StageDelta, finding *FindingDelta, now time.Time, month string,
) bool

Apply folds one delta into a rollup status under the exactly-once ledger: it returns false (and mutates nothing) when ledgerKey was already applied. Exactly one of stage/finding may be non-nil. The monthly trend line is maintained only when month is non-empty (the total scope).

func CalibrationFrom added in v0.8.0

func CalibrationFrom(st *v1alpha1.FindingRollupStatus, scope string) *templates.Calibration

CalibrationFrom derives the estimate-accuracy summary for a scope from its rollup, or nil when the history is too thin to be meaningful. scope names the source for the prompt ("owner/repo", "all repositories").

func ParseCostMicroUSD

func ParseCostMicroUSD(s string) (int64, error)

ParseCostMicroUSD converts a CRD decimal cost string into integer micro-USD without float arithmetic. Empty means zero.

func PhaseKey

func PhaseKey(p v1alpha1.Phase) string

PhaseKey maps a Finding phase onto its rollup histogram key.

func RecordCompletion

func RecordCompletion(ctx context.Context, phase, recommendation, repo string)

RecordCompletion emits a finding's terminal-entry metrics (first rollup only).

func RecordDeleted

func RecordDeleted(ctx context.Context, reason string)

RecordDeleted emits a finding deletion (reason: ttl or manual).

func RecordStage

func RecordStage(ctx context.Context, d StageDelta, repo string)

RecordStage emits one run's metrics (called at total-scope aggregation so it fires exactly once per run).

func ScopeObjectName

func ScopeObjectName(scope v1alpha1.RollupScope) string

ScopeObjectName is the deterministic FindingRollup object name for a scope value: total, repo-<hash>, harness-<sanitized>, model-<sanitized>.

Types

type EstimateDelta added in v0.8.0

type EstimateDelta struct {
	PredictedTurns, ActualTurns               int64
	PredictedOutputTokens, ActualOutputTokens int64
}

EstimateDelta is one run's predicted cost, paired with the actual cost of that same run so the two accumulate together.

type FindingDelta

type FindingDelta struct {
	// Phase bucket to increment, as PhaseKey renders it (remediated, failed,
	// dismissed, handedoff, deleted); empty on a pure reversal.
	Phase string
	// PrevPhase, when non-empty, is decremented: the previously counted
	// phase no longer holds (revived, or completed again differently).
	PrevPhase string
	// Recommendation histogram key (remediate/ignore/manual) to increment;
	// empty skips.
	Recommendation string
	// PrevRecommendation, when non-empty, is decremented.
	PrevRecommendation string
	// Attempts summed (investigation + remediation), counted only on the
	// first terminal entry (corrections pass zero to avoid double counts).
	Attempts int64
	// Count marks the finding entering the counted set (findings++).
	Count bool
	// Uncount reverses a prior count (findings--) after a revival.
	Uncount bool
	// First marks the finding's first terminal entry ever. Attempts and the
	// monthly trend line are counted once and never reversed.
	First bool
}

FindingDelta is one finding's terminal contribution (total and repository scopes only, since a finding has no single harness/model owner). It has three shapes:

  • a count: Phase + Count;
  • a swap between terminal phases: Phase + PrevPhase;
  • a reversal, when a revival moved the finding back into flight: PrevPhase + Uncount, no Phase.

type StageDelta

type StageDelta struct {
	// Stage is "investigation" or "remediation".
	Stage string
	// Outcome from the envelope vocabulary (+ "aborted").
	Outcome string
	// Succeeded marks an ok run (for remediation: ok and successful).
	Succeeded bool
	// Harness/Model executed the run; empty when the run died without one.
	Harness string
	Model   string
	// Token sums.
	InputTokens, OutputTokens, CacheReadTokens, CacheCreationTokens int64
	// CostMicroUSD spent.
	CostMicroUSD int64
	// ElapsedMilliseconds of wall clock.
	ElapsedMilliseconds int64
	// Turns the run took.
	Turns int64
	// Estimate is what the investigation predicted this run would cost, when
	// it predicted anything. Nil contributes nothing to the estimate
	// aggregate, not even to its Runs denominator, so the predicted and
	// actual sums always cover the same set of runs.
	Estimate *EstimateDelta
}

StageDelta is one agent run's contribution to a StageAggregate.

func StageDeltaFrom

func StageDeltaFrom(
	stage string, st *v1alpha1.StageResult, succeeded bool, estimate *v1alpha1.AgentEstimate,
) (StageDelta, error)

StageDeltaFrom derives the delta from a child's stage result. estimate is the investigation's prediction for this run, or nil when there was none.

Jump to

Keyboard shortcuts

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