The contexts file¶
contexts.toml lists the virtufin-api endpoints (contexts) the TUI can work with. What a context is, switching, health and the write gate: Contexts and the write gate. Switching step by step: Switch context.
First run¶
On first run, if ~/.config/virtufin/api/contexts.toml (or
~/.config/virtufin/tui/config.toml) doesn't exist yet, it's seeded from the
shipped defaults: a local context (localhost:5002) and a kubernetes context
(api.virtufin.com:443, TLS, protected, with an api_key placeholder to replace) --
edit the copy under ~/.config to add other environments. A fuller template
lives at contexts.toml.example in the repo root. The worker catalog is not copied:
the TUI merges the catalog it ships under ~/.config/virtufin/tui/workers.toml, so
that file holds only your own entries (an entry there overrides the shipped one of the
same name field by field; a full copy would go stale).
Example contexts.toml:
[[contexts]]
name = "local"
api_host = "localhost"
api_port = 5002
description = "Local dev virtufin-api"
[[contexts]]
name = "staging"
api_host = "staging.virtufin.com"
api_port = 5002
tls = true
description = "Staging cluster"
[[contexts]]
name = "kubernetes"
api_host = "api.virtufin.com"
api_port = 443
tls = true
worker_api_host = "api.virtufin.svc.cluster.local"
worker_api_port = 5002
description = "k3s cluster via ingress; workers dial the in-cluster Service directly"
The active context itself isn't set here -- it's state, not config; see Persistence.
Configuration¶
| Field | Type | Default | Description |
|---|---|---|---|
name |
string | required | Display name (must be unique within [[contexts]]) |
api_host |
string | required | Hostname of the virtufin-api gRPC endpoint |
api_port |
int (1-65535) | required | Port of the gRPC endpoint (typically 5002) |
tls |
bool | false |
Use TLS for the gRPC channel |
api_key |
string | unset (falls back to VIRTUFIN_API_KEY env var) |
Sent as x-api-key metadata on every call; required when the endpoint enforces API-key auth. See Contexts for the env-var fallback and error reporting. |
worker_api_host |
string | unset (falls back to api_host) |
Address a spawned worker process dials for its own Gateway callback; set for contexts where the worker runs somewhere api_host isn't reachable from (e.g. cluster-internal) |
worker_api_port |
int (1-65535) | unset (falls back to api_port) |
Port for worker_api_host |
description |
string | "" |
Free-form label shown on the Contexts page |
Environment variables override file values:
| Env var | Overrides |
|---|---|
VIRTUFIN_TUI_API_HOST |
api_host of the active context |
VIRTUFIN_TUI_API_PORT |
api_port of the active context |
VIRTUFIN_TUI_CONTEXT |
the active context (see Persistence) |
Config file location: $XDG_CONFIG_HOME/virtufin/api/contexts.toml if
$XDG_CONFIG_HOME is set, otherwise ~/.config/virtufin/api/contexts.toml
on every OS (there's no platform-specific path like macOS's "Application
Support" or Windows's %APPDATA% -- the same ~/.config/... layout is
used everywhere). Runtime state (active context, active Scenario,
subscribed event topics) lives separately under $XDG_STATE_HOME
(default ~/.local/state), not in this file. The TUI's own log file
(tui.log, everything logged during a session -- see
Architecture) lives alongside that runtime state at
$XDG_STATE_HOME/virtufin/tui/tui.log, for the same reason: it's
generated output, not something you hand-author. It rotates at 10 MB and keeps
three old files (tui.log.1 .. tui.log.3). A failure that repeats on every
attempt (a rejected API key, say) is logged with its traceback once, then at
DEBUG until it recovers or changes.
Per-context settings¶
| Field | Purpose |
|---|---|
tls |
Use TLS for the gRPC channel, verified against the system CA roots. Required for endpoints behind a TLS-terminating ingress; recommended for any non-localhost endpoint. |
api_key |
Sent as x-api-key metadata on every call. Required when the endpoint enforces API-key auth (the cluster ingress does); keys are provisioned per user in the API's ApiAuth:Keys config — an admin runs python scripts/provision_api_key.py <username> in the api repo to generate one and give it to you out-of-band. The file's 0600 mode protects the stored key. If a context has no api_key set, the VIRTUFIN_API_KEY env var is used instead (same variable name workmanager reads for its own outbound calls to the gateway) — useful for CI or a shared shell profile without putting the key in contexts.toml. An inline api_key always wins over the env var when both are set. |
worker_api_host |
The address a worker (a separate process the WorkManager spawns — e.g. the HttpGet example — not this TUI) must dial for its own callback connection to the virtufin-api Gateway. Defaults to api_host when unset. Set this when the worker runs somewhere api_host isn't reachable from — e.g. api_host is a TLS-terminating ingress address reachable only from outside the cluster, but the worker runs inside the cluster and needs a plaintext, cluster-internal address such as api.virtufin.svc.cluster.local. |
worker_api_port |
Port for worker_api_host. Defaults to api_port when unset. |
description |
Free-form label shown in the picker (e.g. "Production — last deploy 2026-07-05"). |
protected |
true for a context where a mistake costs (production): its context row is red on every tab and every change the TUI makes there asks first. See Protected contexts and the write gate. |
An entry without name, api_host or api_port (or with a port that is not a
number), or a file that is not valid TOML, does not stop the TUI: the entry is
skipped and the problem is shown when the TUI starts (and logged).
Programmatic override¶
For one-off overrides without editing contexts.toml, set the env var
VIRTUFIN_TUI_CONTEXT=name. The TUI starts with that context active, ignoring
the stored active-context state (see Persistence below).
VIRTUFIN_TUI_API_HOST and VIRTUFIN_TUI_API_PORT override the host/port of the
active context, the one --context or VIRTUFIN_TUI_CONTEXT names when set
(useful for ad-hoc connections to a port-forwarded gRPC server).
Persistence¶
contexts.toml holds only the context definitions -- which context is
currently active is state, not config, and lives separately at
~/.local/state/virtufin/api/state.toml ($XDG_STATE_HOME-aware, same
convention as $XDG_CONFIG_HOME for contexts.toml). Switching context
from the Contexts page writes active_context = "<name>" there immediately.
The file is created with mode 0600.