pub struct LockfileBuilder<'a> { /* private fields */ }Expand description
Manages lockfile operations including entry creation, updates, and cleanup.
Implementations§
Source§impl<'a> LockfileBuilder<'a>
impl<'a> LockfileBuilder<'a>
Sourcepub fn new(manifest: &'a Manifest) -> Self
pub fn new(manifest: &'a Manifest) -> Self
Create a new lockfile builder with the given manifest.
Sourcepub fn add_or_update_lockfile_entry(
&self,
lockfile: &mut LockFile,
_name: &str,
entry: LockedResource,
)
pub fn add_or_update_lockfile_entry( &self, lockfile: &mut LockFile, _name: &str, entry: LockedResource, )
Add or update a lockfile entry with deterministic merging for duplicates.
This method handles deduplication by using (name, source, tool) tuples as the unique key. When duplicates are found, it uses a deterministic merge strategy to ensure consistent lockfile generation across runs, regardless of processing order.
§Merge Strategy (deterministic, order-independent)
When merging duplicate entries:
- Prefer direct manifest dependencies (has
manifest_alias) over transitive dependencies - Prefer install=true over install=false (prefer dependencies that create files)
- Otherwise, keep the existing entry (first-wins for same priority)
This ensures that even with non-deterministic HashMap iteration order, the same logical dependency structure produces the same lockfile.
§Arguments
lockfile- The mutable lockfile to updatename- The name of the dependency (for documentation purposes)entry- The locked resource entry to add or update
§Examples
let mut lockfile = LockFile::new();
let entry = LockedResource {
name: "my-agent".to_string(),
source: Some("community".to_string()),
tool: "claude-code".to_string(),
// ... other fields
};
resolver.add_or_update_lockfile_entry(&mut lockfile, "my-agent", entry);
// Later updates use deterministic merge strategy
let updated_entry = LockedResource {
name: "my-agent".to_string(),
source: Some("community".to_string()),
tool: "claude-code".to_string(),
// ... updated fields
};
resolver.add_or_update_lockfile_entry(&mut lockfile, "my-agent", updated_entry);Sourcepub fn remove_stale_manifest_entries(&self, lockfile: &mut LockFile)
pub fn remove_stale_manifest_entries(&self, lockfile: &mut LockFile)
Removes stale lockfile entries that are no longer in the manifest.
This method removes lockfile entries for direct manifest dependencies that have been
commented out or removed from the manifest. This must be called BEFORE
remove_manifest_entries_for_update() to ensure stale entries don’t cause conflicts
during resolution.
A manifest-level entry is identified by:
manifest_alias.is_none()- Direct dependency with no pattern expansionmanifest_alias.is_some()- Pattern-expanded dependency (alias must be in manifest)
For each stale entry found, this also removes its transitive children to maintain lockfile consistency.
§Arguments
lockfile- The mutable lockfile to clean
§Examples
If a user comments out an agent in agpm.toml:
# [agents]
# example = { source = "community", path = "agents/example.md", version = "v1.0.0" }This function will remove the “example” agent from the lockfile and all its transitive dependencies before the update process begins.
Sourcepub fn remove_manifest_entries_for_update(
&self,
lockfile: &mut LockFile,
manifest_keys: &HashSet<String>,
)
pub fn remove_manifest_entries_for_update( &self, lockfile: &mut LockFile, manifest_keys: &HashSet<String>, )
Removes lockfile entries for manifest dependencies that will be re-resolved.
This method removes old entries for direct manifest dependencies before updating, which handles the case where a dependency’s source or resource type changes. This prevents duplicate entries with the same name but different sources.
Pattern-expanded and transitive dependencies are preserved because:
- Pattern expansions will be re-added during resolution with (name, source) matching
- Transitive dependencies aren’t manifest keys and won’t be removed
§Arguments
lockfile- The mutable lockfile to cleanmanifest_keys- Set of manifest dependency keys being updated