config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 12 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 config holds the router configuration: tiers, activities, routes, policy, classifiers, and the JSON file under the XDG config dir they load from. It is a leaf package: nothing in internal/ is imported here.

Index

Constants

View Source
const (
	DirName  = "codex-router"
	FileName = "config.json"
)

File locations under the XDG config dir.

View Source
const (
	APISystemOne = "system-one"
	APIOllama    = "ollama"
)

Classifier wire adapters.

Variables

Activities lists the seven routable activities.

Efforts lists efforts weakest first.

Tiers lists every tier by rank.

Functions

func Path

func Path() (string, error)

Path returns the config file location: $XDG_CONFIG_HOME/codex-router/config.json, else ~/.config/codex-router/config.json. A relative XDG_CONFIG_HOME is ignored per the XDG spec.

Types

type Activity

type Activity string

Activity names what a turn produces. ActivityUncertain is a classifier answer, never a config key.

const (
	ActivityCode      Activity = "code"
	ActivityDebug     Activity = "debug"
	ActivityExplore   Activity = "explore"
	ActivityPlan      Activity = "plan"
	ActivityReview    Activity = "review"
	ActivityOps       Activity = "ops"
	ActivityDocs      Activity = "docs"
	ActivityUncertain Activity = "uncertain"
)

type Cache

type Cache struct {
	TTLMs        int `json:"ttlMs"`
	WarmMarginMs int `json:"warmMarginMs"`
}

Cache models prompt-cache warmth: per model, effort-neutral (spikes 3, 5).

type Classifier

type Classifier struct {
	Label     string `json:"label"`
	API       string `json:"api"`
	Endpoint  string `json:"endpoint"`
	Model     string `json:"model"`
	KeyEnv    string `json:"keyEnv,omitempty"`
	TimeoutMs int    `json:"timeoutMs"`
}

Classifier describes one classifier endpoint. API names the wire adapter ("system-one" or "ollama"). KeyEnv names the environment variable holding the bearer key; empty means no key.

type Config

type Config struct {
	Baseline    Tier                        `json:"baseline"`
	Routes      map[Tier]Route              `json:"routes"`
	Activities  map[Activity]map[Tier]Route `json:"activities,omitempty"`
	Prices      map[string]Price            `json:"prices,omitempty"`
	Policy      Policy                      `json:"policy"`
	Preset      Preset                      `json:"preset"`
	Classifier  string                      `json:"classifier"`
	Classifiers map[string]Classifier       `json:"classifiers"`
	Context     Context                     `json:"context"`
	Cache       Cache                       `json:"cache"`
	Proxy       Proxy                       `json:"proxy"`
	CodexBin    string                      `json:"codexBin,omitempty"`
}

Config is the whole router configuration.

func Default

func Default() Config

Default returns the built-in configuration: the four gpt-6 models that share one compatibility group (plan D2), classifier Jev with a local Ollama option.

func Load

func Load(path string) (Config, error)

Load reads the config file over Default(): keys the file omits keep their defaults, a map entry the file names replaces the default entry whole. A missing file yields the defaults. Unknown keys and invalid values are errors.

func (Config) DecideTimeout

func (c Config) DecideTimeout() time.Duration

DecideTimeout bounds one routing decision: the selected classifier's timeout plus a margin, so the proxy outlasts the classifier call.

func (Config) Effective

func (c Config) Effective() Policy

Effective returns Policy with the preset applied. Balanced keeps Policy as configured; thrifty makes upgrades harder and downgrades easier; quality does the opposite. Preset fields replace the configured values. The claude-model-router has no named presets, only the policy fields these adjust, so the values are new and chosen for direction, not ported.

func (Config) RouteFor

func (c Config) RouteFor(t Tier, a Activity) Route

RouteFor returns the route for a tier and activity. An activity override replaces the tier's model and effort field by field; an empty override field inherits the tier's route.

func (Config) Validate

func (c Config) Validate() error

Validate checks the config and reports the first problem with its field path.

type Context

type Context struct {
	RecentTurns  int `json:"recentTurns"`
	MaxTextChars int `json:"maxTextChars"`
}

Context bounds what the classifier sees.

type Effort

type Effort string

Effort is a Codex reasoning effort as sent in reasoning.effort.

const (
	EffortLow    Effort = "low"
	EffortMedium Effort = "medium"
	EffortHigh   Effort = "high"
	EffortXHigh  Effort = "xhigh"
)

type Policy

type Policy struct {
	UpgradeVotes          int     `json:"upgradeVotes"`
	UpgradeBase           float64 `json:"upgradeBase"`
	UpgradeSlope          float64 `json:"upgradeSlope"`
	UpgradePivotTokens    int     `json:"upgradePivotTokens"`
	JumpConfidence        float64 `json:"jumpConfidence"`
	DowngradeVotes        int     `json:"downgradeVotes"`
	DowngradeMass         float64 `json:"downgradeMass"`
	DowngradeSlope        float64 `json:"downgradeSlope"`
	DowngradePivotTokens  int     `json:"downgradePivotTokens"`
	DowngradeHorizonTurns int     `json:"downgradeHorizonTurns"`
	ContinuationMass      float64 `json:"continuationMass"`
	EscalationHoldTurns   int     `json:"escalationHoldTurns"`
	ReviewEveryRequests   int     `json:"reviewEveryRequests"`
	MinDwellRequests      int     `json:"minDwellRequests"`
	ActivityMass          float64 `json:"activityMass"`
	ContextFill           float64 `json:"contextFill"`
}

Policy holds the switching thresholds. Taxes are in uncached tokens.

type Preset

type Preset string

Preset selects a built-in policy override set.

const (
	PresetThrifty  Preset = "thrifty"
	PresetBalanced Preset = "balanced"
	PresetQuality  Preset = "quality"
)

type Price

type Price struct {
	Input       float64 `json:"input"`
	CachedInput float64 `json:"cachedInput"`
	Output      float64 `json:"output"`
}

Price is a model's list price in USD per million tokens. Zero values mean unpriced: estimates then stay in tokens.

type Proxy

type Proxy struct {
	Port int `json:"port"`
}

Proxy holds listener settings. Port 0 binds an ephemeral port per session.

type Route

type Route struct {
	Model  string `json:"model"`
	Effort Effort `json:"effort,omitempty"`
}

Route is a model slug plus the effort the router sends for it. An empty Effort keeps the effort Codex sent.

type Tier

type Tier string

Tier is a task-complexity level. Tiers is ordered weakest first; the index in Tiers is the rank.

const (
	TierMicro  Tier = "micro"
	TierLow    Tier = "low"
	TierMedium Tier = "medium"
	TierHigh   Tier = "high"
)

Jump to

Keyboard shortcuts

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