pub struct ConfigPaths {
pub config_dir: PathBuf,
pub home_dir: PathBuf,
pub platform: Platform,
}Expand description
Centralizes all path resolution for cmx configuration and install directories.
Production code constructs this via ConfigPaths::from_env; tests use
ConfigPaths::for_test to inject arbitrary root directories and avoid
touching the real home directory.
Fields§
§config_dir: PathBuf§home_dir: PathBuf§platform: PlatformImplementations§
Source§impl ConfigPaths
impl ConfigPaths
Sourcepub fn from_env(platform: Platform) -> Result<Self>
pub fn from_env(platform: Platform) -> Result<Self>
Production constructor — derives paths from the real home and config directories.
Sourcepub fn for_test(home: PathBuf, config: PathBuf) -> Self
pub fn for_test(home: PathBuf, config: PathBuf) -> Self
Test constructor — uses arbitrary root directories so no real home
directory is touched. Defaults to Platform::Claude.
Sourcepub fn for_test_with_platform(
home: PathBuf,
config: PathBuf,
platform: Platform,
) -> Self
pub fn for_test_with_platform( home: PathBuf, config: PathBuf, platform: Platform, ) -> Self
Test constructor with explicit platform.
Sourcepub fn with_platform(&self, platform: Platform) -> ConfigPaths
pub fn with_platform(&self, platform: Platform) -> ConfigPaths
Return a view of these paths bound to a different platform.
home_dir and config_dir are platform-independent — only the active
platform changes. cmx doctor uses this to survey every platform’s
install directories and lock files from a single base, reusing all the
platform-aware path resolution without rebuilding it per platform.
Sourcepub fn sources_path(&self) -> PathBuf
pub fn sources_path(&self) -> PathBuf
Path to sources.json.
Sourcepub fn git_clones_dir(&self) -> PathBuf
pub fn git_clones_dir(&self) -> PathBuf
Directory where git-backed sources are cloned.
Sourcepub fn sets_path(&self, scope: InstallScope) -> PathBuf
pub fn sets_path(&self, scope: InstallScope) -> PathBuf
Path to sets.json for the given scope.
Sets are platform-independent — a single file per scope, unlike
lock_path which carries a per-platform slug.
Sourcepub fn config_path(&self) -> PathBuf
pub fn config_path(&self) -> PathBuf
Path to config.json (LLM gateway settings).
Sourcepub fn default_artifact_home(&self) -> PathBuf
pub fn default_artifact_home(&self) -> PathBuf
Default location of the canonical artifact home — under cmx’s existing
config root, alongside sources.json and the lockfiles.
This is the default; the home field in config.json can override it.
Use crate::config::resolve_artifact_home to get the effective home,
which consults the config first. Note this is unrelated to
home_dir, which is the OS home ($HOME).
Sourcepub fn lock_path(&self, scope: InstallScope) -> PathBuf
pub fn lock_path(&self, scope: InstallScope) -> PathBuf
Path to the lock file for the given scope.
Claude uses cmx-lock.json for backward compatibility. All other
platforms use cmx-lock-<slug>.json.
Sourcepub fn install_dir(
&self,
kind: ArtifactKind,
scope: InstallScope,
) -> Option<PathBuf>
pub fn install_dir( &self, kind: ArtifactKind, scope: InstallScope, ) -> Option<PathBuf>
Directory where artifacts of the given kind and scope are installed.
Resolution is delegated to Platform::install_subpath, which encodes
each platform’s layout (including per-kind divergence such as codex/pi
skills living under the shared .agents/skills). Local installs are
relative to the project root; global installs are anchored at $HOME.
Returns None for unsupported (platform, kind) combinations. Callers
should gate on ensure_supports or
Platform::supports before calling this.
Sourcepub fn installed_artifact_path(
&self,
kind: ArtifactKind,
name: &str,
scope: InstallScope,
) -> Option<PathBuf>
pub fn installed_artifact_path( &self, kind: ArtifactKind, name: &str, scope: InstallScope, ) -> Option<PathBuf>
Full path to where an artifact of kind named name is (or would be)
installed under scope, accounting for the platform’s agent file format.
Agents use the platform’s agent_extension
(e.g. .md, or .toml for codex); skills resolve to a directory named
after the artifact.
Returns None for unsupported (platform, kind) combinations.
Sourcepub fn is_installed(
&self,
kind: ArtifactKind,
name: &str,
scope: InstallScope,
fs: &dyn Filesystem,
) -> bool
pub fn is_installed( &self, kind: ArtifactKind, name: &str, scope: InstallScope, fs: &dyn Filesystem, ) -> bool
Returns true if an artifact of kind named name exists on disk under scope.
Returns false for unsupported (platform, kind) combinations.
Sourcepub fn ensure_supports(&self, kind: ArtifactKind) -> Result<()>
pub fn ensure_supports(&self, kind: ArtifactKind) -> Result<()>
Verify the active platform supports the given artifact kind, returning a user-facing error otherwise (e.g. pi has no agent concept).
Sourcepub fn require_install_dir(
&self,
kind: ArtifactKind,
scope: InstallScope,
) -> Result<PathBuf>
pub fn require_install_dir( &self, kind: ArtifactKind, scope: InstallScope, ) -> Result<PathBuf>
Like install_dir, but returns Err for unsupported
(platform, kind) combinations instead of None.
Sourcepub fn require_installed_artifact_path(
&self,
kind: ArtifactKind,
name: &str,
scope: InstallScope,
) -> Result<PathBuf>
pub fn require_installed_artifact_path( &self, kind: ArtifactKind, name: &str, scope: InstallScope, ) -> Result<PathBuf>
Like installed_artifact_path, but returns
Err for unsupported (platform, kind) combinations instead of None.