Skip to main content

Module config

Module config 

Source
Expand description

~/.rpi/ persistent configuration — auth + model catalog. Mirrors (a Rust-flattened slice of) the TS packages/coding-agent/src/config.ts (getAgentDir/getAuthPath/getModelsPath) + core/auth-storage.ts (FileAuthStorageBackend) + core/model-config.ts (ModelConfig).

§Layout (divergence from upstream — documented in docs/m6-cli-open-questions.md)

Upstream uses ~/.pi/agent/{auth.json, models.json, …} because the same dir also hosts themes/bin/prompts/sessions. rpi v1 has only two files, so it drops the agent/ layer and goes flat:

~/.rpi/                 (RPI_CODING_AGENT_DIR env overrides this)
├── auth.json          # persisted credentials (mode 0o600 on Unix)
└── models.json        # user-defined provider/model catalog (hand-edited)

§Concurrency

v1 is a single-process CLI, so we use atomic rename instead of upstream’s proper-lockfile: write a sibling temp file, fs::rename over the target, then chmod 0o600 on Unix (Windows chmod is a no-op, matching Node). Concurrent rpi auth login from two shells could lose one update — that’s accepted and documented; adding a file lock is deferred.

§models.json credential expansion

Upstream resolveConfigValue expands $ENV/!command/${ENV} inside apiKey/headers. v1 does not — only literal strings are accepted (use the ANTHROPIC_* env vars for dynamic secrets). Documented divergence.

Structs§

ModelDefinition
One model under a provider. id is required (mirrors TS ModelDefinition).
ModelsConfig
The models.json document. Mirrors TS { providers: Record<id, ProviderConfig> } (core/model-config.ts ModelsConfigSchema).
ProviderConfig
A provider entry in models.json. The fields mirror the TS ProviderConfig one-for-one; v1 honors base_url/api_key/headers/auth_header/models, and ignores api values other than anthropic-messages (documented).

Enums§

ConfigError
A config-layer error (path resolution, IO, JSON). Surfaced to the user by the auth subcommand / provider::resolve.
Credential
A stored credential. Mirrors the TS Credential union (packages/ai/src/auth/types.ts). The Oauth variant exists for forward compatibility but v1 never writes it (no OAuth device-code flow); resolve does not consume it.

Constants§

ANTHROPIC_DEFAULT_BASE_URL
The first-party Anthropic endpoint — used as the fallback base_url when a models.json provider omits it. Kept here (not imported from rpi_ai) so the config layer never depends on the provider’s private models module. Public so crate::provider::resolve can tell a gateway model (whose base_url differs from this) from a built-in Anthropic model.
CONFIG_DIR_ENV
Env var that overrides the whole config dir (mirrors upstream PI_CODING_AGENT_DIR). Absolute path; relative values are rejected.
CONFIG_DIR_NAME
The config directory name under the home dir. Upstream is .pi; rpi uses .rpi to avoid colliding with a native pi install on the same machine.
DEFAULT_PROVIDER_ID
The provider id under which rpi auth login stores the Anthropic key. Mirrors upstream’s fixed anthropic provider id.

Functions§

agent_dir
The rpi config directory (~/.rpi by default, RPI_CODING_AGENT_DIR override). Creates nothing — purely a path computation.
auth_path
~/.rpi/auth.json.
delete_credential
Remove provider_id from the store. Returns true if a credential was present (and is now gone), false if it was already absent. Always rewrites the file when the provider existed (so auth logout reflects the new state on disk even if the map isn’t empty).
load_models_config
Load ~/.rpi/models.json. Missing file ⇒ empty config (no error).
models_path
~/.rpi/models.json.
provider_is_anthropic_compatible
Whether the entry under provider_id speaks the v1-honored protocol (anthropic-messages, or omitted/unknown). Unknown api is allowed through for forward-compat but flagged ignored-in-v1 in the docs. Public so crate::provider can scan models.json providers for an authHeader:true gateway bearer source.
provider_to_models
Convert a (provider_id, ProviderConfig) pair into a list of library Models. Provider-level base_url/headers/auth_header fold into each model. Returns None for non-anthropic providers (v1 ignores them).
read_auth
Read the auth store. Missing file ⇒ empty store (not an error). Malformed JSON ⇒ ConfigError::Json (we do not silently swallow a corrupt auth file).
upsert_credential
Read-modify-write: upsert a credential for provider_id.
write_auth
Atomically write the whole auth store (ensures the dir exists, writes a temp sibling, renames over the target, then chmod 0o600 on Unix).

Type Aliases§

AuthStore
The auth store: providerId -> Credential. Mirrors upstream Record<providerId, Credential>.