Skip to main content

ConfigPaths

Struct ConfigPaths 

Source
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: Platform

Implementations§

Source§

impl ConfigPaths

Source

pub fn from_env(platform: Platform) -> Result<Self>

Production constructor — derives paths from the real home and config directories.

Source

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.

Source

pub fn for_test_with_platform( home: PathBuf, config: PathBuf, platform: Platform, ) -> Self

Test constructor with explicit platform.

Source

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.

Source

pub fn sources_path(&self) -> PathBuf

Path to sources.json.

Source

pub fn git_clones_dir(&self) -> PathBuf

Directory where git-backed sources are cloned.

Source

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.

Source

pub fn config_path(&self) -> PathBuf

Path to config.json (LLM gateway settings).

Source

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).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.