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 ¶
const ( CardWidth = 1200 CardHeight = 630 )
Card sizes: the Open Graph image size, which X, LinkedIn and Slack all show uncropped.
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 ¶
Types ¶
type Action ¶
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 ¶
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.
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.
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.