health

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 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 health is a workspace's dashboard (spec_044_health): the facts about what it holds and how its runs go, taken from what it already records (no model call), and the judge's verdicts on each item's quality, kept with their history.

Index

Constants

View Source
const (
	KindAgent     = "agent"
	KindSkill     = "skill"
	KindRule      = "rule"
	KindGuardrail = "guardrail"
	KindEval      = "eval"
	KindWorkflow  = "workflow"
	KindWorker    = "worker"
)

The kinds of item, in the order the dashboard shows them.

View Source
const (
	FlagUncovered = "uncovered" // an agent no eval checks
	FlagStale     = "stale"     // an agent changed since its evals last ran
	FlagUnused    = "unused"    // a skill or rule nothing uses, a worker that hasn't run
	FlagNeverRun  = "never_run" // a workflow or eval never run
	FlagFailing   = "failing"   // most of its recent runs failed
	FlagDisabled  = "disabled"  // a worker switched off
	FlagOff       = "off"       // a guardrail switched off
)

What an item's flags say about it.

View Source
const (
	RunDone    = "done"
	RunFailed  = "failed"
	RunStopped = "stopped"
)

The statuses a Run has.

View Source
const Days = 30

Days is how many days the charts cover.

View Source
const Instruction = `` /* 745-byte string literal not displayed */

Instruction tells the judge its job.

View Source
const Keep = 90 * 24 * time.Hour

Keep is how long verdicts are kept, for trends (HL-11).

View Source
const RubricVersion = 1

RubricVersion changes when the rubrics do: every item is judged again.

View Source
const Window = 30 * 24 * time.Hour

Window is how far back the facts look.

Variables

View Source
var ErrNoVerdict = errors.New("the judge's answer isn't a verdict")

ErrNoVerdict means the judge's answer isn't one.

View Source
var Rubrics = map[string][]string{
	KindAgent: {
		"Its instructions are clear and complete: what it's for, how it works, when it's done",
		"Its tools fit what it's for, and no more",
		"Its evals cover what it does",
		"Its runs succeed",
	},
	KindSkill: {
		"Its description says when to use it (it's what makes an agent choose it)",
		"Its instructions can be followed step by step",
		"Its scripts run and pass the policy (or it needs none)",
		"Something uses it",
	},
	KindRule: {
		"It can be judged pass or fail from a prompt or an answer alone",
		"It isn't redundant with another rule or guardrail",
		"It fires when it should, and only then",
	},
	KindGuardrail: {
		"What it checks is clear and can be decided",
		"Its action fits the risk (block, redact or warn)",
		"It fires when it should, and only then",
	},
	KindEval: {
		"Its cases cover the agent's job, the hard cases too",
		"Its expected outputs and thresholds are sensible",
		"It tells good from bad (not always passing or always failing)",
	},
	KindWorkflow: {
		"Its steps are well defined and in a sensible order",
		"It handles failure (retries, error links, timeouts)",
		"Its cost and duration fit what it does",
		"Its runs succeed",
		"Its permission mode fits what it does",
	},
	KindWorker: {
		"Its permissions are as tight as its work allows",
		"Its schedule and limits fit its work",
		"Its runs succeed",
	},
}

Rubrics are what the judge scores, per kind (HL-10).

Functions

func Due

func Due(it Item, latest map[string]Verdict, model string, force bool) bool

Due reports whether an item needs judging: it loads, and has no verdict for its content under this rubric version and model setting (or force).

func Evidence

func Evidence(it Item) string

Evidence is what the facts say about it, in words.

func Grade

func Grade(score float64) string

Grade is a score's letter (HL-12): A from 4.5, B from 3.5, C from 2.5, else D; "" for none.

func Prompt

func Prompt(it Item, file string) string

Prompt is what the judge gets for it: the rubric, the item's file and its evidence (what the facts say about it).

func Scores

func Scores(items []Item, latest map[string]Verdict) (overall float64, byKind map[string]float64)

Scores are the workspace's and each kind's scores: their items' verdicts averaged, weighted by use (at least 1), an item with a problem counting as a D; items not judged leave them out. 0 is not judged.

Types

type Day

type Day struct {
	Date                  string
	Done, Failed, Stopped int
	CostUSD               float64
}

Day is one day's runs.

type EvalResult

type EvalResult struct {
	Agent  string
	Passed bool
}

EvalResult is one case's result for one agent.

type EvalRun

type EvalRun struct {
	Started time.Time
	Results []EvalResult
}

EvalRun is one run of an eval: when, and its cases' results.

type EvalStats

type EvalStats struct {
	// Runs are the eval runs in the window.
	Runs   int
	Last   time.Time
	Passed int
	Cases  int
}

EvalStats are an agent's or an eval's latest results.

func (EvalStats) PassRate

func (e EvalStats) PassRate() float64

PassRate is the share of cases passed (0 without cases).

type Facts

type Facts struct {
	At    time.Time
	Items []Item
	// Days are the runs per day, oldest first, the last of them today.
	Days    []Day
	Signals []Signal
}

Facts are a workspace's dashboard without the judge's verdicts.

func Build

func Build(in Inputs) Facts

Build makes the facts from in.

type Inputs

type Inputs struct {
	Now time.Time
	// DefaultAgent is who an eval naming no agent checks.
	DefaultAgent string
	Agents       []Source
	Skills       []Source
	Rules        []Source
	Guardrails   []Source
	Evals        []Source
	Workflows    []Source
	Workers      []Source
	// Audit is the workspace's audit entries in the window.
	Audit []audit.Entry
}

Inputs are what the facts are made from: the workspace's items and their records, gathered by the engine.

type Item

type Item struct {
	Kind, Name, Path, Detail string
	Problem                  string
	Hash                     string
	Flags                    []string
	// Uses are its runs (a workflow, a worker, an eval), activations (a
	// skill) or verdicts (a rule, a guardrail) in the window: the weight of
	// its grade.
	Uses int
	// Fired is how often a rule or a guardrail stopped, warned or revised.
	Fired int
	Runs  *RunStats
	Evals *EvalStats
	// Daily are its uses per day, as Days.
	Daily []int
}

Item is one agent, skill, rule, guardrail, eval, workflow or worker.

func (Item) Key

func (it Item) Key() string

Key is the item's identity in verdicts: kind and name.

type Run

type Run struct {
	Started  time.Time
	Duration time.Duration
	// Status is done, failed or stopped.
	Status  string
	CostUSD float64
	// FailedStep is the step a workflow run failed at.
	FailedStep string
}

Run is one run of a workflow or a worker, as the facts count it.

type RunStats

type RunStats struct {
	Runs, Done, Failed, Stopped int
	CostUSD                     float64
	Median                      time.Duration
	Last                        time.Time
	// FailingStep is the step its runs fail at most.
	FailingStep string
}

RunStats are a workflow's or a worker's runs in the window.

func (RunStats) SuccessRate

func (r RunStats) SuccessRate() float64

SuccessRate is the share of runs done (0 without runs).

type Score

type Score struct {
	Line   string `json:"line"`
	Score  int    `json:"score"`
	Reason string `json:"reason"`
}

Score is one rubric line's.

type Signal

type Signal struct {
	// Kind is denial, guardrail or rule.
	Kind  string
	About string
	Count int
	Last  time.Time
	// Detail is the latest one's why.
	Detail string
}

Signal is a safety signal in the window: the auto reviewer's denials, a guardrail's or a rule's decisions, by what they were about.

type Source

type Source struct {
	Name, Path string
	// Detail is what kind of that kind it is: a skill's type, a rule's
	// stage, a guardrail's built-in check.
	Detail  string
	Problem string
	// Hash is the file's content's (verdicts follow it).
	Hash     string
	Modified time.Time
	// Agents are those a rule, a skill or an eval is for (empty: all, or
	// for an eval its default agent).
	Agents []string
	// Skills are those an agent step, a meta skill or an eval uses.
	Skills []string
	// Off is a guardrail switched off or a worker disabled.
	Off bool
	// Cases is an eval's number of cases.
	Cases    int
	Runs     []Run
	EvalRuns []EvalRun
}

Source is one item as the engine read it.

type State

type State struct {
	// LastCheck is when the last check ended (zero: never checked, and
	// the schedule waits for a first check by hand).
	LastCheck time.Time `json:"last_check"`
	LastCost  float64   `json:"last_cost_usd,omitempty"`
	// Judged and Errors are what the last check judged, and the items it
	// couldn't, with why.
	Judged int      `json:"judged,omitempty"`
	Errors []string `json:"errors,omitempty"`
	// Skipped is why the last scheduled check didn't run.
	Skipped string `json:"skipped,omitempty"`
}

State is what the store remembers of the checks.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store keeps a workspace's verdicts and its checks' state, in a folder of the service's storage.

func NewStore

func NewStore(dir string) *Store

NewStore is the store in dir (made when first written).

func (*Store) Add

func (s *Store) Add(v Verdict) error

Add keeps v, and lets verdicts older than Keep go.

func (*Store) All

func (s *Store) All() []Verdict

All are the verdicts kept, oldest first (what could be read, when the file can't be read whole).

func (*Store) History

func (s *Store) History(key string) []Verdict

History is an item's verdicts, oldest first.

func (*Store) Latest

func (s *Store) Latest() map[string]Verdict

Latest is each item's latest verdict, by Key.

func (*Store) SetState

func (s *Store) SetState(st State) error

SetState writes the checks' state.

func (*Store) State

func (s *Store) State() State

State reads the checks' state.

type Verdict

type Verdict struct {
	Kind   string `json:"kind"`
	Name   string `json:"name"`
	Hash   string `json:"hash"`
	Rubric int    `json:"rubric"`
	// Model is the model that answered; Ref the one set to judge ("" the
	// default), which a check compares.
	Model  string    `json:"model"`
	Ref    string    `json:"ref,omitempty"`
	At     time.Time `json:"at"`
	Scores []Score   `json:"scores"`
	// Overall is 1–5.
	Overall float64 `json:"overall"`
	Summary string  `json:"summary,omitempty"`
	// Fixes are concrete changes, each a suggestion.
	Fixes   []string `json:"fixes,omitempty"`
	CostUSD float64  `json:"cost_usd,omitempty"`
}

Verdict is the judge's on one item as it was (its hash), under one rubric version and model.

func Parse

func Parse(it Item, reply string) (Verdict, error)

Parse reads the judge's answer (in a code fence or not) into a verdict for it, its scores clamped to 1–5.

func (Verdict) Key

func (v Verdict) Key() string

Key is the verdict's item's: kind and name.

Jump to

Keyboard shortcuts

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