install_resources

Function install_resources 

Source
pub async fn install_resources(
    filter: ResourceFilter,
    lockfile: &LockFile,
    manifest: &Manifest,
    project_dir: &Path,
    cache: Cache,
    force_refresh: bool,
    max_concurrency: Option<usize>,
    progress: Option<Arc<MultiPhaseProgress>>,
) -> Result<(usize, Vec<(String, String)>)>
Expand description

Resource installation function supporting multiple progress configurations.

This function consolidates all resource installation patterns into a single, flexible interface that can handle both full installations and selective updates with different progress reporting mechanisms. It represents the modernized installation architecture introduced in AGPM v0.3.0.

§Architecture Benefits

  • Single API: Single function handles install and update commands
  • Flexible progress: Supports dynamic, simple, and quiet progress modes
  • Selective installation: Can install all resources or just updated ones
  • Optimal concurrency: Leverages worktree-based parallel operations
  • Cache efficiency: Integrates with instance-level caching systems

§Parameters

  • filter - Determines which resources to install (ResourceFilter::All or ResourceFilter::Updated)
  • lockfile - The lockfile containing all resource definitions to install
  • manifest - The project manifest providing configuration and target directories
  • project_dir - Root directory where resources should be installed
  • cache - Cache instance for Git repository and worktree management
  • force_refresh - Whether to force refresh of cached repositories
  • max_concurrency - Optional limit on concurrent operations (None = unlimited)
  • progress - Optional multi-phase progress manager (MultiPhaseProgress)

§Progress Reporting

Progress is reported through the optional MultiPhaseProgress parameter:

  • Enabled: Pass Some(progress) for multi-phase progress with live updates
  • Disabled: Pass None for quiet operation (scripts and automation)

§Installation Process

  1. Resource filtering: Collects entries based on filter criteria
  2. Cache warming: Pre-creates worktrees for all unique repositories
  3. Parallel installation: Processes resources with configured concurrency
  4. Progress coordination: Updates progress based on configuration
  5. Error aggregation: Collects and reports any installation failures

§Concurrency Behavior

The function implements advanced parallel processing:

  • Pre-warming phase: Creates all needed worktrees upfront for maximum parallelism
  • Parallel execution: Each resource installed in its own async task
  • Concurrency control: max_concurrency limits simultaneous operations
  • Thread safety: Progress updates are atomic and thread-safe

§Returns

Returns a tuple of:

  • The number of resources that were actually installed (new or updated content). Resources that already exist with identical content are not counted.
  • A vector of (resource_name, checksum) pairs for all processed resources

§Errors

Returns an error if any resource installation fails. The error includes details about all failed installations with specific error messages for debugging.

§Examples

Install all resources with progress tracking:

use agpm_cli::installer::{install_resources, ResourceFilter};
use agpm_cli::utils::progress::MultiPhaseProgress;
use agpm_cli::lockfile::LockFile;
use agpm_cli::manifest::Manifest;
use agpm_cli::cache::Cache;
use std::sync::Arc;
use std::path::Path;

let progress = Arc::new(MultiPhaseProgress::new(true));

let (count, _checksums) = install_resources(
    ResourceFilter::All,
    &lockfile,
    &manifest,
    &project_dir,
    cache,
    false,
    Some(8), // Limit to 8 concurrent operations
    Some(progress),
).await?;

println!("Installed {} resources", count);

Install resources quietly (for automation):

use agpm_cli::installer::{install_resources, ResourceFilter};
use agpm_cli::lockfile::LockFile;
use agpm_cli::manifest::Manifest;
use agpm_cli::cache::Cache;
use std::path::Path;

let updates = vec![("agent1".to_string(), None, "v1.0".to_string(), "v1.1".to_string())];

let (count, _checksums) = install_resources(
    ResourceFilter::Updated(updates),
    &lockfile,
    &manifest,
    &project_dir,
    cache,
    false,
    None, // Unlimited concurrency
    None, // No progress output
).await?;

println!("Updated {} resources", count);