DependencyResolver

Struct DependencyResolver 

Source
pub struct DependencyResolver { /* private fields */ }
Expand description

Main dependency resolver with service-based architecture.

This orchestrates multiple specialized services to handle different aspects of the dependency resolution process while maintaining compatibility with existing interfaces.

§Architecture

The resolver follows a modular service pattern where each complex aspect of resolution is delegated to a specialized service:

§Resolution Process

The resolution occurs in distinct phases:

  1. Collection Phase: Extract dependencies from the project manifest
  2. Version Resolution Phase: Batch resolve all version constraints to commit SHAs
  3. Pattern Expansion Phase: Expand glob patterns (e.g., agents/*.md) into individual resources
  4. Transitive Resolution Phase (optional): Resolve dependencies declared within resources
  5. Conflict Detection Phase: Detect and report version conflicts across the dependency graph

§Examples

use agpm_cli::resolver::DependencyResolver;
use agpm_cli::manifest::Manifest;
use agpm_cli::cache::Cache;

// Load manifest and create cache
let manifest = Manifest::load_from_file("agpm.toml")?;
let cache = Cache::new()?;

// Create resolver and resolve dependencies
let mut resolver = DependencyResolver::new(manifest, cache).await?;
let lockfile = resolver.resolve().await?;

println!("Resolved {} dependencies", lockfile.total_resources());

§Key Features

  • Parallel Processing: Configurable concurrency for performance
  • SHA-based Deduplication: Shared worktrees for identical commits
  • Transitive Dependencies: Optional resolution of dependencies of dependencies
  • Version Constraints: Support for semver-style constraints (^1.0, ~2.1)
  • Pattern Support: Glob patterns for bulk dependency inclusion
  • Conflict Detection: Comprehensive detection of version conflicts
  • VersionResolutionService: Git operations and SHA resolution
  • PatternExpansionService: Glob pattern handling
  • Service container for transitive resolution (transitive_resolver::ResolutionServices)
  • Version conflict detection and reporting (conflict_detector::ConflictDetector)

Implementations§

Source§

impl DependencyResolver

Source

pub async fn new(manifest: Manifest, cache: Cache) -> Result<Self>

Create a new dependency resolver.

§Arguments
  • manifest - Project manifest with dependencies
  • cache - Cache for Git operations and worktrees
§Errors

Returns an error if source manager cannot be created

Source

pub async fn new_with_context( manifest: Manifest, cache: Cache, operation_context: Option<Arc<OperationContext>>, ) -> Result<Self>

Create a new dependency resolver with operation context.

§Arguments
  • manifest - Project manifest with dependencies
  • cache - Cache for Git operations and worktrees
  • operation_context - Optional context for warning deduplication
§Errors

Returns an error if source manager cannot be created

Source

pub async fn new_with_global(manifest: Manifest, cache: Cache) -> Result<Self>

Create a new resolver with global configuration support.

This loads both manifest sources and global sources from ~/.agpm/config.toml.

§Arguments
  • manifest - Project manifest with dependencies
  • cache - Cache for Git operations and worktrees
§Errors

Returns an error if global configuration cannot be loaded

Source

pub async fn new_with_global_concurrency( manifest: Manifest, cache: Cache, max_concurrency: Option<usize>, operation_context: Option<Arc<OperationContext>>, ) -> Result<Self>

Creates a new dependency resolver with global config and custom concurrency limit.

§Arguments
  • manifest - Project manifest with dependencies
  • cache - Cache for Git operations and worktrees
  • max_concurrency - Optional concurrency limit for parallel operations
  • operation_context - Optional context for warning deduplication
§Errors

Returns an error if global configuration cannot be loaded

Source

pub async fn with_cache(manifest: Manifest, cache: Cache) -> Result<Self>

Creates a new dependency resolver with custom cache directory.

§Arguments
  • cache - Cache for Git operations and worktrees
§Errors

Returns an error if source manager cannot be created

Source

pub async fn new_with_global_context( manifest: Manifest, cache: Cache, operation_context: Option<Arc<OperationContext>>, ) -> Result<Self>

Create a new resolver with global configuration and operation context.

§Arguments
  • manifest - Project manifest with dependencies
  • cache - Cache for Git operations and worktrees
  • operation_context - Optional context for warning deduplication
§Errors

Returns an error if global configuration cannot be loaded

Source

pub fn core(&self) -> &ResolutionCore

Get a reference to the resolution core.

Source

pub async fn resolve(&mut self) -> Result<LockFile>

Resolve all dependencies and generate a complete lockfile.

Performs dependency resolution with automatic conflict detection and backtracking to find compatible versions when conflicts occur.

§Errors

Returns an error if any step of resolution fails

Source

pub async fn resolve_with_options( &mut self, enable_transitive: bool, progress: Option<Arc<MultiPhaseProgress>>, ) -> Result<LockFile>

Resolve dependencies with transitive resolution option.

§Arguments
  • enable_transitive - Whether to resolve transitive dependencies
§Errors

Returns an error if resolution fails

Source

pub async fn pre_sync_sources( &mut self, deps: &[(String, ResourceDependency)], progress: Option<Arc<MultiPhaseProgress>>, ) -> Result<()>

Pre-sync sources for the given dependencies.

This performs Git operations to ensure all required sources are available before the main resolution process begins.

§Arguments
  • deps - List of (name, dependency) pairs to sync sources for
§Errors

Returns an error if source synchronization fails

Source

pub async fn update( &mut self, existing: &LockFile, deps_to_update: Option<Vec<String>>, progress: Option<Arc<MultiPhaseProgress>>, ) -> Result<LockFile>

Update dependencies with existing lockfile and specific dependencies to update.

§Arguments
  • existing - Existing lockfile to update
  • deps_to_update - Optional specific dependency names to update (None = all)
  • progress - Optional multi-phase progress tracker for UI updates
§Current Implementation (MVP)

Currently performs full resolution regardless of deps_to_update value. This is correct but not optimized - all dependencies are re-resolved even when only specific ones are requested.

§Future Enhancement

Full incremental update would:

  1. Match deps_to_update names to lockfile entries
  2. Keep unchanged dependencies at their locked versions
  3. Re-resolve only specified dependencies to latest matching versions
  4. Re-extract transitive dependencies for updated resources
  5. Merge updated entries with unchanged entries from existing lockfile
  6. Detect and resolve any new conflicts

This requires significant changes to the resolution pipeline to support “pinned” versions alongside “latest” resolution.

§Errors

Returns an error if update process fails

Source

pub async fn get_available_versions( &self, repo_path: &Path, ) -> Result<Vec<String>>

Get available versions for a repository.

§Arguments
  • repo_path - Path to the Git repository
§Returns

List of available version strings (tags and branches)

Source

pub async fn verify(&self, _lockfile: &LockFile) -> Result<()>

Verify that existing lockfile is still valid.

§Arguments
  • _lockfile - Existing lockfile to verify
§Errors

Returns an error if verification fails

Source

pub fn operation_context(&self) -> Option<&Arc<OperationContext>>

Get current operation context if available.

Source

pub fn set_operation_context(&mut self, context: Arc<OperationContext>)

Set the operation context for warning deduplication.

§Arguments
  • context - The operation context to use

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more