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
- Variables
- func EndpointPlaceholders(endpoint string) ([]string, error)
- func ExpandHome(path, home string) string
- func Path() (string, error)
- func ReadEnvKey(path, name string) (string, error)
- type Activity
- type Cache
- type Classifier
- type Classifiers
- type Config
- type Context
- type Effort
- type Policy
- type Preset
- type Price
- type Proxy
- type Route
- type Tier
Constants ¶
const ( DirName = "codex-router" FileName = "config.json" )
File locations under the XDG config dir.
const ( APISystemOne = "system-one" APIOpenAIDecisions = "openai-decisions" APIOllama = "ollama" )
Classifier wire adapters.
const ClassifierOff = "off"
ClassifierOff as Config.Classifier turns the classifier off: no prompt leaves the machine, and only pins and the context guard change the model.
Variables ¶
var ( ErrEnvFileMode = errors.New("open to group or others; chmod 600 it") ErrKeyNotInEnv = errors.New("key not in file") )
Env file errors. Their text never holds a value from the file.
var Activities = []Activity{ ActivityCode, ActivityDebug, ActivityExplore, ActivityPlan, ActivityReview, ActivityOps, ActivityDocs, }
Activities lists the seven routable activities.
var Efforts = []Effort{EffortLow, EffortMedium, EffortHigh, EffortXHigh}
Efforts lists efforts weakest first.
var Tiers = []Tier{TierMicro, TierLow, TierMedium, TierHigh}
Tiers lists every tier by rank.
Functions ¶
func EndpointPlaceholders ¶ added in v0.5.0
EndpointPlaceholders returns the NAMEs of the {NAME} placeholders in endpoint, in order of first use. A brace that is not part of a well-formed placeholder is an error.
func ExpandHome ¶ added in v0.3.0
ExpandHome turns a leading "~/" into home. Other paths are returned as is.
func Path ¶
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.
func ReadEnvKey ¶ added in v0.3.0
ReadEnvKey returns the value of name in the dotenv file at path: lines KEY=value or export KEY=value, values optionally in single or double quotes (no escapes), # comment lines, and a " #" comment after an unquoted value. The last assignment wins; an empty value counts as missing. Nothing is exported to the process env. A file that group or others can read is refused, as a shared key file is a leaked key.
Types ¶
type Activity ¶
type Activity string
Activity names what a turn produces. ActivityUncertain is a classifier answer, never a config key.
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"`
EnvFile string `json:"envFile,omitempty"`
TimeoutMs int `json:"timeoutMs"`
}
Classifier describes one classifier endpoint. API names the wire adapter ("system-one", "openai-decisions" or "ollama"). KeyEnv names the environment variable holding the bearer key; empty means no key. Endpoint may hold {NAME} placeholders, filled from the variable NAME. EnvFile is a dotenv file (absolute or ~/ path) read for KeyEnv and each placeholder when the process env does not set it: service units do not see the shell's env.
type Classifiers ¶ added in v0.3.2
type Classifiers map[string]Classifier
Classifiers maps a name to a classifier. A config file's entry is decoded over the entry of the same name, so it names only the fields it changes.
func (*Classifiers) UnmarshalJSON ¶ added in v0.3.2
func (cs *Classifiers) UnmarshalJSON(b []byte) error
UnmarshalJSON decodes each entry over the one already in cs. Unknown fields are errors, as in the rest of the file.
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 Classifiers `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, classifier Jev with Clef, OpenAI and a local Ollama option. Routes use two models of one compatibility group (plan D2): gpt-6-luna for micro and low, gpt-6.1-sol for medium and high. Codex caches per model, not per effort, so only a move between the two models costs cache. Tuned on live routing tests and benchmarks on 2026-10-15/16: Luna at high effort matched Sol on bounded review, debug, ops, code, explore and plan tasks at 5-10% of the list cost; xhigh on either model cost more and planned no better than high.
func Load ¶
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, and a classifiers entry changes only the fields it names. A missing file yields the defaults. Unknown keys and invalid values are errors.
func (Config) DecideTimeout ¶
DecideTimeout bounds one routing decision: the selected classifier's timeout plus a margin, so the proxy outlasts the classifier call.
func (Config) Effective ¶
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.
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"`
ContinuationMass float64 `json:"continuationMass"`
EscalationHoldTurns int `json:"escalationHoldTurns"`
ReviewEveryRequests int `json:"reviewEveryRequests"`
MinDwellRequests int `json:"minDwellRequests"`
ActivityMass float64 `json:"activityMass"`
ContextFill float64 `json:"contextFill"`
// Deprecated: accepted for existing configs; has no effect.
DowngradeHorizonTurns int `json:"downgradeHorizonTurns,omitempty"`
}
Policy holds the switching thresholds. Taxes are in uncached tokens.
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.