models

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 6 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 models defines agent stages, model catalogs, and per-stage model resolution.

Index

Constants

View Source
const BackendField = FieldPrefix + "backend"

BackendField names the field carrying the backend a selection is for.

View Source
const DefaultKey = "default"

DefaultKey is the Selections key holding the ticket-wide model choice.

View Source
const FieldPrefix = "model_"

FieldPrefix names the form and query fields a selection is submitted in: FieldPrefix + DefaultKey, and FieldPrefix + <stage>.

Variables

Stages is the closed set of stages, in display order.

Functions

func Describe

func Describe(sel Selections) string

Describe renders sel as "default=opus, plan=sonnet".

func FromValues

func FromValues(v url.Values) (map[string]string, string)

FromValues reads a selection out of submitted values, dropping empties, and returns it with the backend named alongside it.

func Resolve

func Resolve(c Catalog, s Selections) (map[Stage]string, []string)

Resolve returns a model id for every stage and the selections it dropped, each as "stage=value".

func TierValue

func TierValue(t Tier) string

TierValue is the Selections value that names t.

func ValidModelID

func ValidModelID(id string) bool

ValidModelID reports whether id is safe to pass as a single argv token. "/" is allowed for provider-qualified ids (opencode's "provider/model" form); it cannot start a flag, escape an argv element, or glob-expand because adapters never pass model ids through a shell.

Types

type Catalog

type Catalog struct {
	SupportsSelection bool           `json:"supports_selection" yaml:"supports_selection"`
	Tiers             []Tier         `json:"tiers"              yaml:"tiers"`
	Models            []Model        `json:"models"             yaml:"models"`
	StageDefaults     map[Stage]Tier `json:"stage_defaults"     yaml:"stage_defaults"`
}

Catalog is a backend's selectable models and per-stage default tiers.

func Union

func Union(cs []Catalog) Catalog

Union merges catalogs; the first declaration of a tier, model or stage default wins.

func (Catalog) ForTier

func (c Catalog) ForTier(t Tier) string

ForTier returns the first model at t, else the nearest cheaper, else the nearest larger, else "".

func (Catalog) Has

func (c Catalog) Has(s Selections) bool

Has reports whether every model id in s names a model in c. Tier references always resolve, so they are ignored.

func (Catalog) Validate

func (c Catalog) Validate() error

Validate reports the first structural problem in c.

func (Catalog) ValidateSelections

func (c Catalog) ValidateSelections(s Selections) error

ValidateSelections reports the first selection c cannot satisfy.

type Model

type Model struct {
	ID    string `json:"id"    yaml:"id"`
	Label string `json:"label" yaml:"label"`
	Tier  Tier   `json:"tier"  yaml:"tier"`
}

type Selections

type Selections map[string]string

Selections maps a stage name, or DefaultKey, to a model id or a "tier:<label>" reference.

func ValidateSelections

func ValidateSelections(catalogs map[string][]Catalog, backend string, raw map[string]string) (Selections, string, error)

ValidateSelections checks raw against the named backend's shem catalogs, one of which must declare all of it, and returns the selections to store and the backend to bind them to. A tier-only selection binds no backend.

type Stage

type Stage string

Stage is an agent invocation site.

const (
	StageBrainstorm    Stage = "brainstorm"
	StagePlan          Stage = "plan"
	StageImplement     Stage = "implement"
	StageRevise        Stage = "revise"
	StageValidate      Stage = "validate"
	StageObserve       Stage = "observe"
	StageReview        Stage = "review"
	StagePRDescription Stage = "pr-description"
	StageGraph         Stage = "graph"
	// StageTest is the epic tester, whose verdict gates auto-merge.
	StageTest Stage = "test"
	// StageEpicPlan is the plan-generation session a shem runs for an epic:
	// one long-form session that writes the plan JSON. Planning shapes every
	// ticket downstream, so it defaults to the large tier.
	StageEpicPlan Stage = "epic-plan"
	// StageDiagnose classifies a failed run and writes repair feedback.
	StageDiagnose Stage = "diagnose"
)

type Tier

type Tier string

Tier is an operator-defined label; Catalog.Tiers lists them cheapest first.

func TierRef

func TierRef(v string) (Tier, bool)

TierRef returns the tier a value names, if it names one.

Jump to

Keyboard shortcuts

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