compute_and_ensure_bundle_dir

Function compute_and_ensure_bundle_dir 

Source
fn compute_and_ensure_bundle_dir(
    into_bundle_id: Option<&str>,
    provider_id: &str,
    auth_env: &mut HashMap<String, String>,
) -> Option<String>
Expand description

Compute the per-bundle OAuth config dir + ensure it exists + override the provider’s auth_config_dir_env_var entry in auth_env.

Returns Some(<absolute path string>) when:

  • into_bundle_id is Some and non-empty AND
  • the provider is registered in the CLI provider registry AND
  • the provider declares an auth_config_dir_env_var (oauth-class providers — claude / codex / openclaw — per spec §4.3) AND
  • DataPaths::from_env() resolves AND
  • create_dir_all succeeds.

Otherwise returns None and leaves auth_env untouched. Callers must continue without per-bundle isolation (legacy ambient path, or skip the binding-persist step) — never abort the OAuth start.

Per SPEC_OAUTH_IDENTITY_BUNDLES_2026_05_22.md §4.5: the dir (and the env-var key) come from the CLI provider registry (backend::providers::get_provider(id)) so the resolver / spawn path / OAuth-start handler never drift on which env var redirects each CLI’s config home. The single source of truth lives in agentmux-srv/src/backend/providers.rs.