status

package
v1.0.0-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 9 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 status writes a run's status file: what the run has spent so far, its cap, what is left and what holds it, for the agent and the job to read while the agent works. The file holds amounts, counts, times and words from closed lists, never a prompt, a path or a model's answer. Its contract is status/v0.1 of Costroid/costroid-schemas.

Index

Constants

View Source
const FileVariable = "COSTROID_STATUS_FILE"

FileVariable names the status file's path.

View Source
const Schema = "costroid.status/0.1"

Schema names the contract's version in every file.

Variables

This section is empty.

Functions

func Path

func Path(getenv func(string) string) string

Path is where a run writes its status file: FileVariable, else costroid-status.json in GitHub Actions' RUNNER_TEMP. Empty means neither is set, and no file is written.

func Write

func Write(path string, s Status) error

Write replaces the file at path with the status. It writes a new file beside the old one and renames it over it, so a reader finds the last whole status or none, never part of one. A failed write leaves the old file as it was.

Types

type Cap

type Cap struct {
	Currency  string           `json:"currency"`
	Amount    decimal.Decimal  `json:"amount"`
	Remainder *decimal.Decimal `json:"remainder"`
	Overshoot *decimal.Decimal `json:"overshoot"`
}

Cap is the run's cap beside its spend in USD. Remainder and Overshoot are nil together, when no one figure compares with the cap.

func NewCap

func NewCap(amount decimal.Decimal, spend []Spend) Cap

NewCap sets the cap beside the spend. Spend in no USD entry is zero; spend in two USD entries, or spend not known, compares with nothing.

func (*Cap) UnmarshalJSON

func (c *Cap) UnmarshalJSON(data []byte) error

UnmarshalJSON reads a cap whose amounts are decimal strings or null.

type NoFileError

type NoFileError struct {
	Path string
}

NoFileError is a status file that does not exist: no costroid run has started an agent that writes it in this job. An empty Path is an environment that names no status file.

func (*NoFileError) Error

func (e *NoFileError) Error() string

type Spend

type Spend struct {
	Currency  string           `json:"currency"`
	CostBasis *focus.CostBasis `json:"cost_basis"`
	ListCost  decimal.Decimal  `json:"list_cost"`
}

Spend is what the run's priced usage comes to in one currency and basis, at the catalog's list prices. A nil CostBasis is a basis the agent's reader states only when the agent ends.

func (*Spend) UnmarshalJSON

func (s *Spend) UnmarshalJSON(data []byte) error

UnmarshalJSON reads an entry whose amount is a decimal string.

type State

type State string

State says whether the agent still works.

const (
	Running State = "running"
	Ended   State = "ended"
)

The states a run's status file can be in.

type Status

type Status struct {
	Schema           string    `json:"schema"`
	State            State     `json:"state"`
	Agent            string    `json:"agent"`
	Updates          Updates   `json:"updates"`
	StartedAt        time.Time `json:"started_at"`
	UpdatedAt        time.Time `json:"updated_at"`
	Spend            []Spend   `json:"spend"`
	Requests         *int      `json:"requests"`
	Cap              Cap       `json:"cap"`
	EnforcementGrade string    `json:"enforcement_grade"`
}

Status is one write of the file. A nil Spend is spend not known, and an empty one is a run that has spent nothing yet.

func Read

func Read(getenv func(string) string) (Status, error)

Read reads the status file where Path says it is. A file that does not exist is a *NoFileError; any other failure, a file that cannot be read or is not a status of this version, is an error of its own.

type Updates

type Updates string

Updates says when the file's spend changes.

const (
	// EachRequest is a run whose spend is priced after each request it sees
	// settle while the agent works.
	EachRequest Updates = "each_request"
	// AgentEnd is a run whose agent states its usage only when it ends.
	AgentEnd Updates = "agent_end"
)

The two ways a run's spend is read.

Jump to

Keyboard shortcuts

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