feat: ultra polish package manager (#13573)

See the readme
This commit is contained in:
jif-oai
2026-03-05 13:02:30 +00:00
committed by GitHub
parent a246dbf9d1
commit 0cc6835416
13 changed files with 1731 additions and 1167 deletions

View File

@@ -0,0 +1,40 @@
use crate::ManagedPackage;
use std::path::PathBuf;
/// Immutable configuration for a [`crate::PackageManager`] instance.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct PackageManagerConfig<P> {
pub(crate) codex_home: PathBuf,
pub(crate) package: P,
cache_root: Option<PathBuf>,
}
impl<P> PackageManagerConfig<P> {
/// Creates a config rooted at the provided Codex home directory.
pub fn new(codex_home: PathBuf, package: P) -> Self {
Self {
codex_home,
package,
cache_root: None,
}
}
/// Overrides the package cache root instead of deriving it from `codex_home`.
pub fn with_cache_root(mut self, cache_root: PathBuf) -> Self {
self.cache_root = Some(cache_root);
self
}
}
impl<P: ManagedPackage> PackageManagerConfig<P> {
/// Returns the effective cache root for the package.
pub fn cache_root(&self) -> PathBuf {
self.cache_root.clone().unwrap_or_else(|| {
self.codex_home.join(
self.package
.default_cache_root_relative()
.replace('/', std::path::MAIN_SEPARATOR_STR),
)
})
}
}