Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

3.9 KB
Raw Blame
//! Config load/save and environment variable overrides.

mod active_workspace;
mod branches;
mod config_file_read;
pub(crate) mod context_overlay;
mod context_refresh;
mod diagnostics;
mod dirs;
pub(in crate::config::schema) mod env;
mod env_overlay;
mod impl_load;
mod migrate;
mod parse;
mod parse_source;
mod provenance;
mod saas_scope;
mod secrets;
pub(crate) mod source;

pub(crate) use diagnostics::{ConfigLoadFallback, ConfigParseError, LoadDiagnostics};

#[cfg(test)]
#[path = "diagnostics_tests.rs"]
mod diagnostics_tests;

pub use active_workspace::active_workspace_dir_cached;
pub(crate) use active_workspace::invalidate_active_workspace;
pub use dirs::{
    action_dir_env_override, active_user_marker_path, active_workspace_dir,
    active_workspace_snapshot, clear_active_user, default_action_dir, default_files_dir,
    default_projects_dir, default_root_openhuman_dir, pre_login_user_dir, read_active_user_id,
    resolve_action_dir, resolve_files_dir, user_openhuman_dir, write_active_user_id,
    PRE_LOGIN_USER_ID,
};

// redact_url_for_log is pub(super) for the schema module; tests inside load
// can access it because they are a submodule and use `use super::*`.
pub(super) use migrate::redact_url_for_log;

// The wire contract between the config loader (which appends the marker to a
// read failure) and `core::observability::expected_error_kind` (which keys on
// it to keep an ownership mismatch paging instead of demoting it as
// user-environment state). Exported so the classifier's tests can assert
// against the real constant rather than a copied literal.
pub(crate) use impl_load::CONFIG_OWNER_MISMATCH_MARKER;
pub(crate) use migrate::apply_loaded_config_migrations;
pub(crate) use provenance::{
    current_dotenv_load, dotenv_loaded_variable, set_current_dotenv_load, ConfigProvenance,
    DotenvLoadProvenance, ProvenanceSource, ValueProvenance,
};

// Items needed by load_tests.rs (loaded as `mod tests` below).
// Tests are a submodule of `load`, so `super::*` == this module's namespace.
#[cfg(test)]
pub(crate) use dirs::default_root_dir_name_pub as default_root_dir_name;
// The strict active-user read is consumed by the resolver via `dirs`'s own
// re-export; only the load_tests module needs it visible at this level.
#[cfg(test)]
pub(crate) use dirs::read_active_user_id_checked;
// Non-test: the managed embedding factory resolves its credential scope
// through the same workspace→config-dir mapping `config::load` uses, so a
// legacy `.../workspace` override lands on the sibling `.openhuman` root that
// holds `auth-profiles.json`.
pub(crate) use dirs::resolve_config_dir_for_workspace;
pub(crate) use dirs::{
    load_persisted_workspace_dirs, read_active_user_id_checked_async, ConfigResolutionSource,
};
#[cfg(test)]
pub(crate) use dirs::{resolve_runtime_config_dirs, resolve_runtime_config_dirs_with};
// PathBuf and Config were in scope via `use super::*` in the original load.rs.
#[cfg(test)]
pub(crate) use super::Config;
#[cfg(test)]
pub(crate) use dirs::ACTIVE_USER_STATE_FILE;
#[cfg(test)]
pub(crate) use impl_load::parse_config_with_recovery;
#[cfg(test)]
pub(crate) use migrate::{migrate_cloud_provider_slugs, migrate_legacy_inference_url};
pub(crate) use parse::config_from_toml_str;
#[cfg(test)]
pub(crate) use std::path::PathBuf;

#[cfg(test)]
#[path = "provenance_tests.rs"]
mod provenance_tests;

pub(super) mod atomic_commit;

#[cfg(unix)]
pub(super) async fn sync_directory(path: &std::path::Path) -> anyhow::Result<()> {
    use anyhow::Context;
    use tokio::fs::File;
    let dir = File::open(path)
        .await
        .with_context(|| format!("Failed to open directory for fsync: {}", path.display()))?;
    dir.sync_all()
        .await
        .with_context(|| format!("Failed to fsync directory metadata: {}", path.display()))?;
    Ok(())
}

#[cfg(not(unix))]
pub(super) async fn sync_directory(_path: &std::path::Path) -> anyhow::Result<()> {
    Ok(())
}

#[cfg(test)]
#[path = "../load_tests.rs"]
mod tests;