Skip to main content

Module credentials

Module credentials 

Source
Expand description

Provider credentials: one type-tagged credential per provider, one write path, and one resolution result that names its source.

§Attribution

The design of this module is ported from pi-mono by Mario Zechner (https://github.com/earendil-works/pi-mono), MIT licensed, specifically:

pi-mono fileported into
packages/ai/src/auth/types.tsCredential, CredentialStore, AuthContext
packages/ai/src/auth/credential-store.tsstore::InMemoryCredentialStore
packages/ai/src/auth/context.tscontext::ProcessAuthContext
packages/ai/src/auth/resolve.tscodewhale_tui::config::credential_resolve

This is a design port into idiomatic Rust, not a line-for-line copy. pi’s module is async TypeScript over a Provider record with a single auth.json; CodeWhale’s is synchronous Rust over ProviderKind and the several pre-existing on-disk stores (secret store, config file, ambient environment, externally consented CLI credential files). The four ideas taken verbatim in spirit are: one type-tagged credential per provider, modify as the only serialized write path, one stated precedence rule in one place, and every resolution carrying a human-readable source label. Several doc comments are adapted closely enough that the MIT permission notice travels with them, reproduced below.

MIT License

Copyright (c) 2025 Mario Zechner

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

§Redaction

Nothing in this module renders or logs secret material. Credential deliberately has a hand-written std::fmt::Debug that prints only the variant tag, so a credential cannot reach a log line through {:?} on a surrounding struct.

Re-exports§

pub use context::AuthContext;
pub use store::CredentialInfo;
pub use store::CredentialStore;

Modules§

context
Injectable ambient-environment access for credential resolution.
store
App-owned credential storage: modify is the only write path.

Structs§

CredentialProbe
One place credential resolution looked, and what would put a credential there. Labels only; never a value.
CredentialResolution
A resolution plus its source. Deliberately does not carry the credential: readiness surfaces need the source, and the request path already has its own resolver that returns the secret.

Enums§

Credential
One type-tagged credential per provider — pi’s Credential union.
CredentialKind
CredentialSource
The place a credential was resolved from, or the fact that no place had one. This is the single value every readiness surface should render.