receipt

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 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 receipt summarises one run of `orch run`: what got done, what got stuck, how long it took and what it cost. `orch report receipt` prints it and the dashboard's Now page shows it, from this one builder, so the two cannot disagree.

It is computed from the event log and the spend table rather than stored: the `runs` row never records an end (Go writes no `status = 'done'`), and the `sprint_done` event the runner writes when its loop ends is the one reliable "this run finished" signal.

Index

Constants

View Source
const (
	CardWidth  = 1200
	CardHeight = 630
)

Card sizes: the Open Graph image size, which X, LinkedIn and Slack all show uncropped.

View Source
const BuiltWith = "Built with [orch](https://github.com/Guria-Studio/orch)"

BuiltWith is the footer a shared receipt carries unless its author opts out.

Variables

This section is empty.

Functions

func Duration

func Duration(seconds float64) string

Duration formats seconds the way the receipt shows them: "2d 3h", "2h 5m", "50m", "40s".

func Titles

func Titles(tasks []model.Task) map[string]string

Titles maps task id to title, for Build.

Types

type Action

type Action struct {
	Text    string `json:"text"`
	Command string `json:"command,omitempty"`
}

Action is one next step. Command, when set, is the shell command that does it; Text says what to do first.

type Merge

type Merge struct {
	TaskID string `json:"task_id"`
	Title  string `json:"title"`
	Base   string `json:"base"`
	Commit string `json:"commit"`
}

Merge is a task the run merged into the base here.

type PR

type PR struct {
	TaskID   string `json:"task_id"`
	Title    string `json:"title"`
	URL      string `json:"url"`
	CIStatus string `json:"ci_status"`
}

PR is a pull request the run opened, with its CI state now.

type Provider

type Provider struct {
	Provider   string `json:"provider"`
	Dispatches int    `json:"dispatches"`
	// TokensIn/TokensOut are as the CLI reported them, cache included;
	// WeightedTokens is what the budget gate counts (cache reads at 10%,
	// writes at 125%).
	TokensIn       int `json:"tokens_in"`
	TokensOut      int `json:"tokens_out"`
	WeightedTokens int `json:"weighted_tokens"`
	// CostUSD is reported dollars plus, for rows with tokens and no price,
	// the pricing.yaml estimate. CostSource says which it is: "reported" when
	// the CLI reported any dollars, "estimated" when all of it is the
	// estimate, "no_data" when the provider reported neither.
	CostUSD          float64 `json:"cost_usd"`
	EstimatedCostUSD float64 `json:"estimated_cost_usd"`
	CostSource       string  `json:"cost_source"`
}

Provider is one backend's share of the run.

type Reader

type Reader interface {
	AllEvents(ctx context.Context, n int) ([]state.Event, error)
	AllSpend(ctx context.Context, since time.Time) ([]state.Spend, error)
	Tasks(ctx context.Context, filter state.TaskFilter) ([]state.TaskRuntime, error)
}

Reader is what Load reads; state.Backend and the dashboard's StateReader both satisfy it.

type Receipt

type Receipt struct {
	RunID     string `json:"run_id"`
	StartedAt string `json:"started_at"`
	// FinishedAt is the run's sprint_done event; empty while it has none.
	FinishedAt string `json:"finished_at"`
	Finished   bool   `json:"finished"`
	// WallSeconds runs from the run's first event to its sprint_done (or its
	// last event, for an unfinished run). AgentSeconds adds up the durations
	// of the dispatches that finished inside that span.
	WallSeconds  float64 `json:"wall_seconds"`
	AgentSeconds float64 `json:"agent_seconds"`

	Dispatches int `json:"dispatches"`
	// FailedAttempts counts `fail` and `timeout` events: attempts, not tasks.
	FailedAttempts int `json:"failed_attempts"`
	Retries        int `json:"retries"`
	// Done and Blocked are tasks by their last outcome in this run, in the
	// order they first reached one. Blocked counts a terminal failure (one
	// no retry followed) and a task its agent blocked, not only `block` and
	// `ci_blocked` events; a task tried again and never decided is in neither.
	Done    []TaskRef `json:"done"`
	Blocked []TaskRef `json:"blocked"`

	Providers        []Provider `json:"providers"`
	TotalCostUSD     float64    `json:"total_cost_usd"`
	EstimatedCostUSD float64    `json:"estimated_cost_usd"`
	PRs              []PR       `json:"prs"`
	// MergedLocally is the tasks squash-merged into the base here, in place
	// of a PR (vcs.provider: local, #455).
	MergedLocally []Merge `json:"merged_locally"`
}

Receipt is one run's summary. Its JSON is what `/api/receipt` and `orch report receipt --json` return.

func Build

func Build(events []state.Event, spend []state.Spend, tasks []state.TaskRuntime, titles map[string]string, table pricing.Table, runID string) *Receipt

Build computes the receipt for runID ("" = the latest finished run) from the whole event log and spend table. nil when there is no such run.

func Load

func Load(ctx context.Context, r Reader, runID string, titles map[string]string, table pricing.Table) (*Receipt, error)

Load reads everything Build needs. runID "" means the latest finished run; nil with no error means there is no such run.

func (*Receipt) Markdown

func (r *Receipt) Markdown() string

Markdown renders the receipt for pasting into a PR, a chat or an email. It does not carry BuiltWith: the caller appends it unless its author opted out.

func (*Receipt) SVG

func (r *Receipt) SVG(project string, builtWith bool) string

SVG renders the receipt as a picture to post: the run's headline numbers on one card, with the "Built with orch" mark unless builtWith is false. Hand-written SVG with system fonts, so neither orch nor the page that turns it into a PNG needs an image library.

func (*Receipt) Summary

func (r *Receipt) Summary(lang string, autoMerge bool) Summary

Summary words the receipt in lang (en, es or pt; anything else is en). autoMerge is github.auto_merge: a project that merges its own green PRs is not told to merge them.

type Summary

type Summary struct {
	Lang    string   `json:"lang"`
	Lines   []string `json:"lines"`
	Actions []Action `json:"actions"`
}

Summary is a run's receipt in plain words (#456): what was built, what stopped and why, and the next one to three things to do, each with the command that does it. Deterministic: built from the receipt alone, so `orch report summary`, the Now page and the post-run notification say the same thing.

func (Summary) Text

func (s Summary) Text() string

Text is the summary as `orch report summary` prints it and the notification posts it.

type TaskRef

type TaskRef struct {
	TaskID       string `json:"task_id"`
	Title        string `json:"title"`
	Cause        string `json:"cause,omitempty"`
	FailureClass string `json:"failure_class,omitempty"`
	Reason       string `json:"reason,omitempty"`
}

TaskRef names a task. On a blocked task, Cause says why it stopped: "verify" (the local verify kept rejecting its work), "failure" (its agent failed; FailureClass is the classifier's verdict), "ci" (its PR kept failing CI), "not_started" (orch could not start it) or "agent" (its agent blocked it). Reason is the event's own text, or the agent's note.

Jump to

Keyboard shortcuts

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