pub async fn install_resources(
filter: ResourceFilter,
lockfile: &Arc<LockFile>,
manifest: &Manifest,
project_dir: &Path,
cache: Cache,
force_refresh: bool,
max_concurrency: Option<usize>,
progress: Option<Arc<MultiPhaseProgress>>,
verbose: bool,
old_lockfile: Option<&LockFile>,
) -> Result<(usize, Vec<(ResourceId, String)>, Vec<(ResourceId, Option<String>)>, Vec<(ResourceId, AppliedPatches)>)>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::AllorResourceFilter::Updated)lockfile- The lockfile containing all resource definitions to installmanifest- The project manifest providing configuration and target directoriesproject_dir- Root directory where resources should be installedcache- Cache instance for Git repository and worktree managementforce_refresh- Whether to force refresh of cached repositoriesmax_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
Nonefor quiet operation (scripts and automation)
§Installation Process
- Resource filtering: Collects entries based on filter criteria
- Cache warming: Pre-creates worktrees for all unique repositories
- Parallel installation: Processes resources with configured concurrency
- Progress coordination: Updates progress based on configuration
- 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_concurrencylimits 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, _old_checksums, _patches) = install_resources(
ResourceFilter::All,
&lockfile,
&manifest,
&project_dir,
cache,
false,
Some(8), // Limit to 8 concurrent operations
Some(progress),
false, // verbose
None, // old_lockfile
).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;
use std::sync::Arc;
let updates = vec![("agent1".to_string(), None, "v1.0".to_string(), "v1.1".to_string())];
let (count, _checksums, _old_checksums, _patches) = install_resources(
ResourceFilter::Updated(updates),
&lockfile,
&manifest,
&project_dir,
cache,
false,
None, // Unlimited concurrency
None, // No progress output
false, // verbose
None, // old_lockfile
).await?;
println!("Updated {} resources", count);