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§
- Model
Definition - One model under a provider.
idis required (mirrors TSModelDefinition). - Models
Config - The
models.jsondocument. Mirrors TS{ providers: Record<id, ProviderConfig> }(core/model-config.tsModelsConfigSchema). - Provider
Config - A provider entry in
models.json. The fields mirror the TSProviderConfigone-for-one; v1 honorsbase_url/api_key/headers/auth_header/models, and ignoresapivalues other thananthropic-messages(documented).
Enums§
- Config
Error - A config-layer error (path resolution, IO, JSON). Surfaced to the user by
the
authsubcommand /provider::resolve. - Credential
- A stored credential. Mirrors the TS
Credentialunion (packages/ai/src/auth/types.ts). TheOauthvariant exists for forward compatibility but v1 never writes it (no OAuth device-code flow);resolvedoes not consume it.
Constants§
- ANTHROPIC_
DEFAULT_ BASE_ URL - The first-party Anthropic endpoint — used as the fallback
base_urlwhen a models.json provider omits it. Kept here (not imported fromrpi_ai) so the config layer never depends on the provider’s privatemodelsmodule. Public socrate::provider::resolvecan tell a gateway model (whosebase_urldiffers 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.rpito avoid colliding with a nativepiinstall on the same machine. - DEFAULT_
PROVIDER_ ID - The provider id under which
rpi auth loginstores the Anthropic key. Mirrors upstream’s fixedanthropicprovider id.
Functions§
- agent_
dir - The rpi config directory (
~/.rpiby default,RPI_CODING_AGENT_DIRoverride). Creates nothing — purely a path computation. - auth_
path ~/.rpi/auth.json.- delete_
credential - Remove
provider_idfrom the store. Returnstrueif a credential was present (and is now gone),falseif it was already absent. Always rewrites the file when the provider existed (soauth logoutreflects 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_idspeaks the v1-honored protocol (anthropic-messages, or omitted/unknown). Unknownapiis allowed through for forward-compat but flagged ignored-in-v1 in the docs. Public socrate::providercan scan models.json providers for anauthHeader:truegateway bearer source. - provider_
to_ models - Convert a
(provider_id, ProviderConfig)pair into a list of libraryModels. Provider-levelbase_url/headers/auth_headerfold into each model. ReturnsNonefor 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, thenchmod 0o600on Unix).
Type Aliases§
- Auth
Store - The auth store:
providerId -> Credential. Mirrors upstreamRecord<providerId, Credential>.