Config file parsing and provider/profile resolution.
The config file is a sequence of [provider] sections and an optional [settings] section (see config.example in the project root for the format). parseConfigFile turns it into a list of ProviderRec values; buildProfile resolves a provider.model string to a Profile ready for API calls.
Known-good validation lives here: a profile must correspond to a KnownGoodCombos entry unless experimentalEnabled is true. Tab-completion and :model cycling both walk KnownGoodCombos order, so the curated ranking determines what the user sees first when tabbing through models.
Types
ProviderRec = object name*, url*, key*, modelPrefix*, family*: string models*: seq[string] reasoning*: string ## persisted current reasoning level for this ## provider ("low" / "medium" / "high"), empty if ## the user hasn't picked one — `buildProfile` ## then falls back to the known-good default. reasonings*: seq[string] ## available reasoning levels for `:reasoning` ## listing. Empty means "fall back to the ## model default" (`defaultReasoningsFor`).
- In-memory mirror of a provider section. family is the optional experimental override (broad name like "glm"/"qwen"/"gpt-oss") used to pick a system prompt; only honored when --experimental is on. Known-good combos ignore it. models is the list of full API model ids (e.g. "openai/gpt-oss-120b") as sent on the wire. modelPrefix is only populated transiently when reading old config files that stored a separate model_prefix key; it is expanded into the model ids on load and never written back out.
Vars
activeCurrent: string
activeProviders: seq[ProviderRec]
activeSearchUrl: string = DefaultSearchUrl
- Resolved at config load. Overridden by [settings] search-url = "...". Persisted back to disk only when it differs from DefaultSearchUrl, so users who never customize keep a clean config.
bashPathOverride: string
- Windows-only. [settings] bash_path = "..." overrides MSYS2 detection in streamexec.resolveBash for users with bash at a non-standard location. Empty on POSIX (where /bin/sh is always used).
notifyEnabled: bool = false
- Resolved at config load. Set true by [settings] notify = on. When true, a native desktop notification fires when a turn ends.
Consts
KeyPrefixCatalog: seq[(string, string)] = [("sk-ant-", "anthropic"), ("sk-or-", "openrouter"), ("sk-proj-", "openai"), ("gsk_", "groq"), ("xai-", "xai"), ("pplx-", "perplexity"), ("nvapi-", "nvidia"), ("fw_", "fireworks"), ("csk-", "cerebras"), ("tgp_", "together"), ("AIza", "google")]
ProviderCatalog: seq[(string, string)] = [ ("anthropic", "https://api.anthropic.com/v1"), ("arcee", "https://conductor.arcee.ai/v1"), ("baseten", "https://inference.baseten.co/v1"), ("cerebras", "https://api.cerebras.ai/v1"), ("deepinfra", "https://api.deepinfra.com/v1/openai"), ("deepseek", "https://api.deepseek.com/v1"), ("fireworks", "https://api.fireworks.ai/inference/v1"), ("friendli", "https://api.friendli.ai/serverless/v1"), ("google", "https://generativelanguage.googleapis.com/v1beta/openai"), ("groq", "https://api.groq.com/openai/v1"), ("huggingface", "https://router.huggingface.co/v1"), ("hyperbolic", "https://api.hyperbolic.xyz/v1"), ("inceptron", "https://api.inceptron.io/v1"), ("mistral", "https://api.mistral.ai/v1"), ("moonshot", "https://api.moonshot.ai/v1"), ("moonshot-cn", "https://api.moonshot.cn/v1"), ("nebius", "https://api.tokenfactory.nebius.com/v1"), ("nvidia", "https://integrate.api.nvidia.com/v1"), ("openai", "https://api.openai.com/v1"), ("openrouter", "https://openrouter.ai/api/v1"), ("ovh", "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1"), ("perplexity", "https://api.perplexity.ai"), ("qwen", "https://dashscope-intl.aliyuncs.com/compatible-mode/v1"), ("qwen-cn", "https://dashscope.aliyuncs.com/compatible-mode/v1"), ("qwen-us", "https://dashscope-us.aliyuncs.com/compatible-mode/v1"), ("sambanova", "https://api.sambanova.ai/v1"), ("scaleway", "https://api.scaleway.ai/v1"), ("together", "https://api.together.xyz/v1"), ("together-eu", "https://eu.api.together.xyz/v1"), ("xai", "https://api.x.ai/v1"), ("zai", "https://api.z.ai/api/paas/v4"), ("zaicode", "https://api.z.ai/api/coding/paas/v4")]
- Skipped on purpose: cortects.ai is a router (an OpenAI-compatible front-end that fans out to other providers' models), so adding it here would just duplicate the underlying providers we already list. Routers belong in user config when wanted, not in the catalog.
Procs
proc availableReasonings(prov: ProviderRec; family, model: string): seq[string] {. ...raises: [], tags: [], forbids: [].}
-
Value set offered by :reasoning for the active provider+model. The per-provider config override wins; otherwise the model-aware default from the known-good table (glm has per-model value sets).
In experimental mode the set is empty: the effort level is free-form (the user types whatever the model's wire surface accepts), so there is no fixed list to validate or tab-complete against.
proc buildProfile(current: string; providers: seq[ProviderRec]; wanted: string): Profile {. ...raises: [], tags: [], forbids: [].}
- Resolve a Profile from in-memory state; empty Profile on failure.
proc catalogUrl(name: string): string {....raises: [], tags: [], forbids: [].}
proc configPath(): string {....raises: [], tags: [ReadEnvEffect, ReadIOEffect], forbids: [].}
proc curatedFor(provider: string): seq[string] {....raises: [], tags: [], forbids: [].}
- Full model ids from KnownGoodCombos for the given provider name.
proc currentProvider(): ProviderRec {....raises: [], tags: [], forbids: [].}
proc defaultNameFromUrl(url: string): string {....raises: [], tags: [], forbids: [].}
proc explainExperimentalGate(p: Profile) {....raises: [IOError], tags: [WriteIOEffect], forbids: [].}
proc findModel(p: ProviderRec; name: string): int {....raises: [], tags: [], forbids: [].}
- Matches by full model id or by short name (everything after the last /). Short-name matching handles :variant <name> from users who type the bare model name and old current = provider.shortname config values that haven't been rewritten yet.
proc firstKnownGoodCombo(providers: seq[ProviderRec]): string {....raises: [], tags: [], forbids: [].}
- "<provider>.<model>" of the first known-good (provider, model) pair across providers, walking KnownGoodCombos order so the curated ranking drives the fallback, not config-file order.
proc firstModel(prov: ProviderRec): string {....raises: [], tags: [], forbids: [].}
- First model in KnownGoodCombos order, or models[0] if none are known-good (e.g. a provider added with --experimental).
proc formatModels(models: seq[string]): string {....raises: [], tags: [], forbids: [].}
proc gateExperimental(p: Profile): bool {....raises: [], tags: [], forbids: [].}
- True if the profile is allowed to run a turn under current policy: empty profile (caller handles that), known-good model, or the --experimental override. False otherwise — caller should bail out and call explainExperimentalGate for the user-facing hint.
proc hasKnownGoodModel(prov: ProviderRec): bool {....raises: [], tags: [], forbids: [].}
proc inferProvider(key: string): string {....raises: [], tags: [], forbids: [].}
- Returns catalog provider name, or "" if key prefix is not uniquely identifying.
proc loadProfile(wanted: string): Profile {. ...raises: [IOError, OSError, ValueError], tags: [ReadEnvEffect, ReadIOEffect, ReadDirEffect, WriteIOEffect, RootEffect], forbids: [].}
proc loadStateOrEmpty(path: string): (string, seq[ProviderRec]) {. ...raises: [IOError, OSError, ValueError], tags: [ReadDirEffect, WriteIOEffect, ReadIOEffect, RootEffect, ReadEnvEffect], forbids: [].}
- Returns (current, providers) and updates activeSearchUrl as a side effect when the config sets search-url. Missing file is benign.
proc orderedModels(prov: ProviderRec): seq[string] {....raises: [], tags: [], forbids: [].}
-
Models in the order they should be presented to the user and used for default selection:
- Known-good models in KnownGoodCombos order (curated quality ranking).
- Experimental models in config-file order, appended after.
This way the best-tested model is always first regardless of how the config was written or the API listed them.
proc parseConfigFile(path: string): (string, string, seq[ProviderRec]) {. ...raises: [IOError, OSError, ValueError], tags: [WriteIOEffect, ReadIOEffect, RootEffect, ReadEnvEffect], forbids: [].}
- Streaming parse so that repeated provider sections accumulate as a list. Returns (current, searchUrl, providers). searchUrl is "" when the key was absent; the caller decides whether to fall back to the default.
proc providerForProfile(prof: Profile): ProviderRec {....raises: [], tags: [], forbids: [].}
- The provider rec backing a profile, looked up by the provider prefix of prof.name ("nebius.zai-org/GLM-5.1" -> nebius). Falls back to currentProvider() when the name has no dot (e.g. a bare default).
proc resolveFamily(prov: ProviderRec; prof: Profile): string {....raises: [], tags: [], forbids: [].}
-
Family is resolved at profile-build time:
- KnownGoodCombos hardcode (always wins; ignores config and -x)
- provider-level family = ... — only honored under --experimental
- default → "glm"
proc resolveReasoning(prov: ProviderRec; prof: Profile): string {....raises: [], tags: [], forbids: [].}
-
Reasoning level resolution at profile-build time:
- provider config reasoning = ... (user picked / persisted)
- KnownGoodCombos default for this (provider, model)
- "" — caller treats as "no wire param"
In experimental mode the known-good default is skipped: reasoning stays empty (no wire param) unless the user picks one. The effort level for an uncured model can't be guessed, and an empty value is the safe default: passing nothing beats passing a wrong knob.
proc shortModel(model: string): string {....raises: [], tags: [], forbids: [].}
- Everything after the last / in a model id. This is the user-visible short name: gpt-oss-120b for openai/gpt-oss-120b, glm-5p1 for accounts/fireworks/models/glm-5p1. When there is no slash, the model id is already a bare name and is returned as-is.
proc shortToFull(models: seq[string]): Table[string, string] {....raises: [], tags: [], forbids: [].}
- Maps each short model name (after the last /) to the full model id. When two full ids share the same short name — e.g. nvidia sometimes lists a model both as org/model-name and bare model-name — only the first occurrence is kept. This mirrors the display list: the user sees both names, picks the short one, and gets the first match. If genuine ambiguity arises in the future we can promote a conflict notice here; for now silent first-wins is the right trade-off.
proc splitModels(s: string): seq[string] {....raises: [], tags: [], forbids: [].}
- Whitespace- (and comma-) separated list of bare model names. Family lives elsewhere — KnownGoodCombos hardcodes it; the provider family = ... key supplies an experimental override.
proc writeConfigFile(path: string; current: string; providers: seq[ProviderRec]) {. ...raises: [OSError, IOError], tags: [WriteDirEffect, ReadDirEffect, WriteIOEffect], forbids: [].}