LockFile

Struct LockFile 

Source
pub struct LockFile {
    pub version: u32,
    pub sources: Vec<LockedSource>,
    pub agents: Vec<LockedResource>,
    pub snippets: Vec<LockedResource>,
    pub commands: Vec<LockedResource>,
    pub mcp_servers: Vec<LockedResource>,
    pub scripts: Vec<LockedResource>,
    pub hooks: Vec<LockedResource>,
}
Expand description

The main lockfile structure representing a complete agpm.lock file.

This structure contains all resolved dependencies, source repositories, and their exact versions/commits for reproducible installations. The lockfile is automatically generated from the crate::manifest::Manifest during installation and should not be edited manually.

§Format Version

The lockfile includes a format version to enable future migrations and compatibility checking. The current version is 1.

§Serialization

The lockfile serializes to TOML format with arrays of sources, agents, and snippets. Empty arrays are omitted from serialization to keep the lockfile clean.

§Examples

Creating a new lockfile:

use agpm_cli::lockfile::LockFile;

let lockfile = LockFile::new();
assert_eq!(lockfile.version, 1);
assert!(lockfile.sources.is_empty());

Loading an existing lockfile:

let lockfile = LockFile::load(Path::new("agpm.lock"))?;
println!("Loaded {} sources, {} agents",
         lockfile.sources.len(), lockfile.agents.len());

Fields§

§version: u32

Version of the lockfile format.

This field enables forward and backward compatibility checking. AGPM will refuse to load lockfiles with versions newer than it supports, and may provide migration paths for older versions in the future.

§sources: Vec<LockedSource>

Locked source repositories with their resolved commit hashes.

Each entry represents a Git repository that has been fetched and resolved to an exact commit. The commit hash ensures all team members get identical source content even as the upstream repository evolves.

This field is omitted from TOML serialization if empty to keep the lockfile clean.

§agents: Vec<LockedResource>

Locked agent resources with their exact versions and checksums.

Contains all resolved agent dependencies from the manifest, with exact commit hashes, installation paths, and SHA-256 checksums for integrity verification.

This field is omitted from TOML serialization if empty.

§snippets: Vec<LockedResource>

Locked snippet resources with their exact versions and checksums.

Contains all resolved snippet dependencies from the manifest, with exact commit hashes, installation paths, and SHA-256 checksums for integrity verification.

This field is omitted from TOML serialization if empty.

§commands: Vec<LockedResource>

Locked command resources with their exact versions and checksums.

Contains all resolved command dependencies from the manifest, with exact commit hashes, installation paths, and SHA-256 checksums for integrity verification.

This field is omitted from TOML serialization if empty.

§mcp_servers: Vec<LockedResource>

Locked MCP server resources with their exact versions and checksums.

Contains all resolved MCP server dependencies from the manifest, with exact commit hashes, installation paths, and SHA-256 checksums for integrity verification. MCP servers are installed as JSON files and also configured in .claude/settings.local.json.

This field is omitted from TOML serialization if empty.

§scripts: Vec<LockedResource>

Locked script resources with their exact versions and checksums.

Contains all resolved script dependencies from the manifest, with exact commit hashes, installation paths, and SHA-256 checksums for integrity verification. Scripts are executable files that can be referenced by hooks.

This field is omitted from TOML serialization if empty.

§hooks: Vec<LockedResource>

Locked hook configurations with their exact versions and checksums.

Contains all resolved hook dependencies from the manifest. Hooks are JSON configuration files that define event-based automation in Claude Code.

This field is omitted from TOML serialization if empty.

Implementations§

Source§

impl LockFile

Source

pub const fn new() -> Self

Create a new empty lockfile with the current format version.

Returns a fresh lockfile with no sources or resources. This is typically used when initializing a new project or regenerating a lockfile from scratch.

§Examples
use agpm_cli::lockfile::LockFile;

let lockfile = LockFile::new();
assert_eq!(lockfile.version, 1);
assert!(lockfile.sources.is_empty());
assert!(lockfile.agents.is_empty());
assert!(lockfile.snippets.is_empty());
Source

pub fn load(path: &Path) -> Result<Self>

Load a lockfile from disk with comprehensive error handling and validation.

Attempts to load and parse a lockfile from the specified path. If the file doesn’t exist, returns a new empty lockfile. Performs format version compatibility checking and provides detailed error messages for common issues.

§Arguments
  • path - Path to the lockfile (typically “agpm.lock”)
§Returns
  • Ok(LockFile) - Successfully loaded lockfile or new empty lockfile if file doesn’t exist
  • Err(anyhow::Error) - Parse error, IO error, or version incompatibility
§Error Handling

This method provides detailed error messages for common issues:

  • File not found: Returns empty lockfile (not an error)
  • Permission denied: Suggests checking file ownership/permissions
  • TOML parse errors: Suggests regenerating lockfile or checking syntax
  • Version incompatibility: Suggests updating AGPM
  • Empty file: Returns empty lockfile (graceful handling)
§Examples
use std::path::Path;
use agpm_cli::lockfile::LockFile;

// Load existing lockfile
let lockfile = LockFile::load(Path::new("agpm.lock"))?;
println!("Loaded {} sources", lockfile.sources.len());

// Non-existent file returns empty lockfile
let empty = LockFile::load(Path::new("missing.lock"))?;
assert!(empty.sources.is_empty());
§Version Compatibility

The method checks the lockfile format version and will refuse to load lockfiles created by newer versions of AGPM:

Error: Lockfile version 2 is newer than supported version 1.
This lockfile was created by a newer version of agpm.
Please update agpm to the latest version to use this lockfile.
Source

pub fn save(&self, path: &Path) -> Result<()>

Save the lockfile to disk with atomic write operations and custom formatting.

Serializes the lockfile to TOML format and writes it atomically to prevent corruption. The output includes a header warning against manual editing and uses custom formatting for better readability compared to standard TOML serialization.

§Arguments
  • path - Path where to save the lockfile (typically “agpm.lock”)
§Returns
  • Ok(()) - Successfully saved lockfile
  • Err(anyhow::Error) - IO error, permission denied, or disk full
§Atomic Write Behavior

The save operation is atomic - the lockfile is written to a temporary file and then renamed to the target path. This ensures the lockfile is never left in a partially written state even if the process is interrupted.

§Custom Formatting

The method uses custom TOML formatting instead of standard serde serialization to produce more readable output:

  • Adds header comment warning against manual editing
  • Groups related fields together
  • Uses consistent indentation and spacing
  • Omits empty arrays to keep the file clean
§Error Handling

Provides detailed error messages for common issues:

  • Permission denied: Suggests running with elevated permissions
  • Directory doesn’t exist: Suggests creating parent directories
  • Disk full: Suggests freeing space or using different location
  • File locked: Suggests closing other programs using the file
§Examples
use std::path::Path;
use agpm_cli::lockfile::LockFile;

let mut lockfile = LockFile::new();

// Add a source
lockfile.add_source(
    "community".to_string(),
    "https://github.com/example/repo.git".to_string(),
    "a1b2c3d4e5f6...".to_string()
);

// Save to disk
lockfile.save(Path::new("agpm.lock"))?;
§Generated File Format

The saved file starts with a warning header:

# Auto-generated lockfile - DO NOT EDIT
version = 1

[[sources]]
name = "community"
url = "https://github.com/example/repo.git"
commit = "a1b2c3d4e5f6..."
fetched_at = "2024-01-15T10:30:00Z"
Source

pub fn add_source(&mut self, name: String, url: String, _commit: String)

Add or update a locked source repository with current timestamp.

Adds a new source entry or updates an existing one with the same name. The fetched_at timestamp is automatically set to the current UTC time in RFC 3339 format.

§Arguments
  • name - Unique source identifier (matches manifest [sources] keys)
  • url - Full Git repository URL
  • commit - Resolved 40-character commit hash
§Behavior

If a source with the same name already exists, it will be replaced with the new information. This ensures that each source name appears exactly once in the lockfile.

§Examples
use agpm_cli::lockfile::LockFile;

let mut lockfile = LockFile::new();
lockfile.add_source(
    "community".to_string(),
    "https://github.com/example/community.git".to_string(),
    "a1b2c3d4e5f6789abcdef0123456789abcdef012".to_string()
);

assert_eq!(lockfile.sources.len(), 1);
assert_eq!(lockfile.sources[0].name, "community");
§Time Zone

The fetched_at timestamp is always recorded in UTC to ensure consistency across different time zones and systems.

Source

pub fn add_resource( &mut self, name: String, resource: LockedResource, is_agent: bool, )

Add or update a locked resource (agent or snippet).

Adds a new resource entry or updates an existing one with the same name within the appropriate resource type (agents or snippets).

Note: This method is kept for backward compatibility but only supports agents and snippets. Use add_typed_resource to support all resource types including commands.

§Arguments
  • name - Unique resource identifier within its type
  • resource - Complete LockedResource with all resolved information
  • is_agent - true for agents, false for snippets
§Behavior

If a resource with the same name already exists in the same type category, it will be replaced. Resources are categorized separately (agents vs snippets), so an agent named “helper” and a snippet named “helper” can coexist.

§Examples

Adding an agent:

use agpm_cli::lockfile::{LockFile, LockedResource};
use agpm_cli::core::ResourceType;

let mut lockfile = LockFile::new();
let resource = LockedResource {
    name: "example-agent".to_string(),
    source: Some("community".to_string()),
    url: Some("https://github.com/example/repo.git".to_string()),
    path: "agents/example.md".to_string(),
    version: Some("^1.0".to_string()),
    resolved_commit: Some("a1b2c3d...".to_string()),
    checksum: "sha256:abcdef...".to_string(),
    installed_at: "agents/example-agent.md".to_string(),
    dependencies: vec![],
    resource_type: ResourceType::Agent,
    tool: Some("claude-code".to_string()),
    manifest_alias: None,
    applied_patches: std::collections::HashMap::new(),
};

lockfile.add_resource("example-agent".to_string(), resource, true);
assert_eq!(lockfile.agents.len(), 1);

Adding a snippet:

let snippet = LockedResource {
    name: "util-snippet".to_string(),
    source: None,  // Local resource
    url: None,
    path: "../local/utils.md".to_string(),
    version: None,
    resolved_commit: None,
    checksum: "sha256:fedcba...".to_string(),
    installed_at: "snippets/util-snippet.md".to_string(),
    dependencies: vec![],
    resource_type: ResourceType::Snippet,
    tool: Some("claude-code".to_string()),
    manifest_alias: None,
    applied_patches: std::collections::HashMap::new(),
};

lockfile.add_resource("util-snippet".to_string(), snippet, false);
assert_eq!(lockfile.snippets.len(), 1);
Source

pub fn add_typed_resource( &mut self, name: String, resource: LockedResource, resource_type: ResourceType, )

Add or update a locked resource with specific resource type.

This is the preferred method for adding resources as it explicitly supports all resource types including commands.

§Arguments
  • name - Unique resource identifier within its type
  • resource - Complete LockedResource with all resolved information
  • resource_type - The type of resource (Agent, Snippet, or Command)
§Examples
use agpm_cli::lockfile::{LockFile, LockedResource};
use agpm_cli::core::ResourceType;

let mut lockfile = LockFile::new();
let command = LockedResource {
    name: "build-command".to_string(),
    source: Some("community".to_string()),
    url: Some("https://github.com/example/repo.git".to_string()),
    path: "commands/build.md".to_string(),
    version: Some("v1.0.0".to_string()),
    resolved_commit: Some("a1b2c3d...".to_string()),
    checksum: "sha256:abcdef...".to_string(),
    installed_at: ".claude/commands/build-command.md".to_string(),
    dependencies: vec![],
    resource_type: ResourceType::Command,
    tool: Some("claude-code".to_string()),
    manifest_alias: None,
    applied_patches: std::collections::HashMap::new(),
};

lockfile.add_typed_resource("build-command".to_string(), command, ResourceType::Command);
assert_eq!(lockfile.commands.len(), 1);
Source

pub fn get_resource(&self, name: &str) -> Option<&LockedResource>

Get a locked resource by name, searching across all resource types.

Searches for a resource with the given name in the agents, snippets, commands, scripts, hooks, and mcp-servers collections. This method returns the first match found, which is suitable when resource names are unique or when the source doesn’t matter.

Note: When multiple resources have the same name from different sources (common with transitive dependencies), this method returns the first match based on search order. For precise lookups that distinguish between sources, use Self::get_resource_by_source.

§Arguments
  • name - Resource name to search for
§Returns
  • Some(&LockedResource) - Reference to the first matching resource
  • None - No resource with that name exists
§Examples
// Simple lookup when resource names are unique
if let Some(resource) = lockfile.get_resource("example-agent") {
    println!("Found resource: {}", resource.installed_at);
} else {
    println!("Resource not found");
}
§Search Order

The method searches in order: agents, snippets, commands, scripts, hooks, mcp-servers. If multiple resource types or sources have the same name, the first match will be returned.

§See Also
  • get_resource_by_source - Precise lookup with source filtering for handling same-named resources from different sources
Source

pub fn get_resource_by_source( &self, name: &str, source: Option<&str>, ) -> Option<&LockedResource>

Get a locked resource by name and source.

This method provides precise resource lookup when multiple resources share the same name but come from different sources. This commonly occurs with transitive dependencies where different dependency chains pull in the same resource name from different repositories.

§Arguments
  • name - Resource name to search for
  • source - Optional source name to match (None matches resources without a source, e.g., local resources)
§Returns

First matching resource with the specified name and source, or None if not found.

§Examples
// When multiple resources have the same name from different sources
if let Some(resource) = lockfile.get_resource_by_source("helper", Some("community")) {
    println!("Found helper from community source: {}", resource.installed_at);
}

if let Some(resource) = lockfile.get_resource_by_source("helper", Some("internal")) {
    println!("Found helper from internal source: {}", resource.installed_at);
}

// Match local resources (no source)
if let Some(resource) = lockfile.get_resource_by_source("local-helper", None) {
    println!("Found local resource: {}", resource.installed_at);
}
§Search Order

The method searches in order: agents, snippets, commands, scripts, hooks, mcp-servers. Only resources matching both the name AND source are returned.

§See Also
  • get_resource - Simple name-based lookup without source filtering
Source

pub fn get_source(&self, name: &str) -> Option<&LockedSource>

Get a locked source repository by name.

Searches for a source repository with the given name in the sources collection.

§Arguments
  • name - Source name to search for (matches manifest [sources] keys)
§Returns
  • Some(&LockedSource) - Reference to the found source
  • None - No source with that name exists
§Examples
if let Some(source) = lockfile.get_source("community") {
    println!("Source URL: {}", source.url);
    println!("Fetched at: {}", source.fetched_at);
}
Source

pub fn has_resource(&self, name: &str) -> bool

Check if a resource is locked in the lockfile.

Convenience method that checks whether a resource with the given name exists in either the agents or snippets collections.

§Arguments
  • name - Resource name to check
§Returns
  • true - Resource exists in the lockfile
  • false - Resource does not exist
§Examples
if lockfile.has_resource("example-agent") {
    println!("Agent is already locked");
} else {
    println!("Agent needs to be resolved and installed");
}

This is equivalent to calling lockfile.get_resource(name).is_some().

Source

pub fn get_resources(&self, resource_type: ResourceType) -> &[LockedResource]

Get all locked resources as a combined vector.

Returns references to all resources (agents, snippets, and commands) in a single vector for easy iteration. The order is agents first, then snippets, then commands.

§Returns

Vector of references to all locked resources, preserving the order within each type as they appear in the lockfile.

§Examples
let all_resources = lockfile.all_resources();
println!("Total locked resources: {}", all_resources.len());

for resource in all_resources {
    println!("- {}: {}", resource.name, resource.installed_at);
}
§Use Cases
  • Generating reports of all installed resources
  • Validating checksums across all resources
  • Listing resources for user display
  • Bulk operations on all resources Get locked resources for a specific resource type

Returns a slice of locked resources for the specified type.

Source

pub const fn get_resources_mut( &mut self, resource_type: ResourceType, ) -> &mut Vec<LockedResource>

Get mutable locked resources for a specific resource type

Returns a mutable slice of locked resources for the specified type.

Source

pub fn all_resources(&self) -> Vec<&LockedResource>

Returns all locked resources across all resource types.

This method collects all resources from agents, snippets, commands, scripts, hooks, and MCP servers into a single vector. It’s useful for operations that need to process all resources uniformly, such as:

  • Generating installation reports
  • Validating checksums across all resources
  • Bulk operations on resources
§Returns

A vector containing references to all LockedResource entries in the lockfile. The order matches the resource type order defined in crate::core::ResourceType::all().

§Examples
let all_resources = lockfile.all_resources();
println!("Total locked resources: {}", all_resources.len());

for resource in all_resources {
    println!("- {}: {}", resource.name, resource.installed_at);
}
Source

pub fn clear(&mut self)

Clear all locked entries from the lockfile.

Removes all sources, agents, snippets, and commands from the lockfile, returning it to an empty state. The format version remains unchanged.

§Examples
let mut lockfile = LockFile::new();
// ... add sources and resources ...

lockfile.clear();
assert!(lockfile.sources.is_empty());
assert!(lockfile.agents.is_empty());
assert!(lockfile.snippets.is_empty());
§Use Cases
  • Preparing for complete lockfile regeneration
  • Implementing agpm clean functionality
  • Resetting lockfile state during testing
  • Handling lockfile corruption recovery
Source

pub fn compute_checksum(path: &Path) -> Result<String>

Compute SHA-256 checksum for a file with integrity verification.

Calculates the SHA-256 hash of a file’s content for integrity verification. The checksum is used to detect file corruption, tampering, or changes after installation.

§Arguments
  • path - Path to the file to checksum
§Returns
  • Ok(String) - Checksum in format “sha256:hexadecimal_hash
  • Err(anyhow::Error) - File read error with detailed context
§Checksum Format

The returned checksum follows the format:

  • Algorithm prefix: “sha256:”
  • Hash encoding: Lowercase hexadecimal
  • Length: 71 characters total (7 for prefix + 64 hex digits)
§Examples
use std::path::Path;
use agpm_cli::lockfile::LockFile;

let checksum = LockFile::compute_checksum(Path::new("example.md"))?;
println!("File checksum: {}", checksum);
// Output: "sha256:a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3"
§Error Handling

Provides detailed error context for common issues:

  • File not found: Suggests checking the path
  • Permission denied: Suggests checking file permissions
  • IO errors: Suggests checking disk health or file locks
§Security Considerations
  • Uses SHA-256, a cryptographically secure hash function
  • Suitable for integrity verification and tamper detection
  • Consistent across platforms (Windows, macOS, Linux)
  • Not affected by line ending differences (hashes actual bytes)
§Performance

The method reads the entire file into memory before hashing. For very large files (>100MB), consider streaming implementations in future versions.

Source

pub fn verify_checksum(path: &Path, expected: &str) -> Result<bool>

Verify that a file matches its expected checksum.

Computes the current checksum of a file and compares it against the expected checksum. Used to verify file integrity and detect corruption or tampering after installation.

§Arguments
  • path - Path to the file to verify
  • expected - Expected checksum in “sha256:hex” format
§Returns
  • Ok(true) - File checksum matches expected value
  • Ok(false) - File checksum does not match (corruption detected)
  • Err(anyhow::Error) - File read error or checksum calculation failed
§Examples
use std::path::Path;
use agpm_cli::lockfile::LockFile;

let expected = "sha256:a665a45920422f9d417e4867efdc4fb8a04a1f3fff1fa07e998e86f7f7a27ae3";
let is_valid = LockFile::verify_checksum(Path::new("example.md"), expected)?;

if is_valid {
    println!("File integrity verified");
} else {
    println!("WARNING: File has been modified or corrupted!");
}
§Use Cases
  • Installation verification: Ensure copied files are intact
  • Periodic validation: Detect file corruption over time
  • Security checks: Detect unauthorized modifications
  • Troubleshooting: Diagnose installation issues
§Performance

This method internally calls compute_checksum, so it has the same performance characteristics. For bulk verification operations, consider caching computed checksums.

§Security

The comparison is performed using standard string equality, which is not timing-attack resistant. Since checksums are not secrets, this is acceptable for integrity verification purposes.

Source

pub fn validate_against_manifest( &self, manifest: &Manifest, strict: bool, ) -> Result<Option<StalenessReason>>

Validate the lockfile against a manifest to detect staleness.

Checks if the lockfile is consistent with the current manifest and detects common staleness indicators that require lockfile regeneration. Performs comprehensive validation similar to Cargo’s --locked mode.

§Arguments
  • manifest - The current project manifest to validate against
  • strict - If true, check version/path changes; if false, only check corruption and security
§Returns
  • Ok(None) - Lockfile is valid and up-to-date
  • Ok(Some(StalenessReason)) - Lockfile is stale and needs regeneration
  • Err(anyhow::Error) - Validation failed due to IO or parse error
§Examples
let lockfile = LockFile::load(Path::new("agpm.lock"))?;
let manifest = Manifest::load(Path::new("agpm.toml"))?;

// Strict mode: check everything including version/path changes
match lockfile.validate_against_manifest(&manifest, true)? {
    None => println!("Lockfile is valid"),
    Some(reason) => {
        eprintln!("Lockfile is stale: {}", reason);
        eprintln!("Run 'agpm install' to auto-update it");
    }
}

// Lenient mode: only check corruption and security (for --frozen)
match lockfile.validate_against_manifest(&manifest, false)? {
    None => println!("Lockfile has no critical issues"),
    Some(reason) => eprintln!("Critical issue: {}", reason),
}
§Staleness Detection

The method checks for several staleness indicators:

  • Duplicate entries: Multiple entries for the same dependency (corruption) - always checked
  • Source URL changes: Source URLs changed in manifest (security concern) - always checked
  • Missing dependencies: Manifest has deps not in lockfile - only in strict mode
  • Version changes: Same dependency with different version constraint - only in strict mode
  • Path changes: Same dependency with different source path - only in strict mode

Note: Extra lockfile entries are allowed (for transitive dependencies).

Source

pub fn is_stale(&self, manifest: &Manifest, strict: bool) -> Result<bool>

Check if the lockfile is stale relative to the manifest.

This is a convenience method that returns a simple boolean instead of the detailed StalenessReason. Useful for quick staleness checks.

§Arguments
  • manifest - The current project manifest to validate against
  • strict - If true, check version/path changes; if false, only check corruption and security
§Returns
  • Ok(true) - Lockfile is stale and needs updating
  • Ok(false) - Lockfile is valid and up-to-date
  • Err(anyhow::Error) - Validation failed due to IO or parse error
§Examples
let lockfile = LockFile::load(Path::new("agpm.lock"))?;
let manifest = Manifest::load(Path::new("agpm.toml"))?;

if lockfile.is_stale(&manifest, true)? {
    println!("Lockfile needs updating");
}
Source

pub fn validate_no_duplicates(&self, path: &Path) -> Result<()>

Validate that there are no duplicate names within each resource type.

This method checks for lockfile corruption by ensuring that no resource type contains multiple entries with the same name. This is a stricter validation than detect_duplicate_entries and is used during lockfile loading to catch corruption early.

§Arguments
  • path - Path to the lockfile (used for error messages)
§Returns
  • Ok(()) - No duplicates found
  • Err(anyhow::Error) - Duplicates found with detailed error message
§Errors

Returns an error if any resource type contains duplicate names, with details about which resource type and names are duplicated.

Source

pub fn find_resource( &self, name: &str, resource_type: ResourceType, ) -> Option<&LockedResource>

Find a specific resource by name and type.

This method searches for a resource with the given name within the specified resource type only. It’s more precise than get_resource when you know the resource type and need to avoid ambiguity when multiple resource types have resources with the same name.

§Arguments
  • name - Resource name to search for
  • resource_type - The type of resource to search within
§Returns
  • Some(&LockedResource) - Reference to the found resource
  • None - No resource with that name exists in the specified type
§Examples
// Find a specific agent
if let Some(agent) = lockfile.find_resource("helper", ResourceType::Agent) {
    println!("Found agent: {}", agent.installed_at);
}

// Find a specific snippet
if let Some(snippet) = lockfile.find_resource("utils", ResourceType::Snippet) {
    println!("Found snippet: {}", snippet.installed_at);
}
§See Also
Source

pub fn get_resources_by_type( &self, resource_type: ResourceType, ) -> &[LockedResource]

Get all resources of a specific type for templating.

This method returns all resources of the specified type, which is useful for templating operations that need to iterate over all resources of a particular type (e.g., all agents, all snippets).

§Arguments
  • resource_type - The type of resources to retrieve
§Returns

A slice of all resources of the specified type.

§Examples
// Get all agents for templating
let agents = lockfile.get_resources_by_type(ResourceType::Agent);
for agent in agents {
    println!("Agent: {} -> {}", agent.name, agent.installed_at);
}

// Get all snippets for templating
let snippets = lockfile.get_resources_by_type(ResourceType::Snippet);
println!("Found {} snippets", snippets.len());
§See Also
Source

pub fn update_resource_checksum(&mut self, name: &str, checksum: &str) -> bool

Update the checksum for a specific resource in the lockfile.

This method finds a resource by name across all resource types and updates its checksum value. Used after installation to record the actual file checksum.

§Arguments
  • name - The name of the resource to update
  • checksum - The new SHA-256 checksum in “sha256:hex” format
§Returns

Returns true if the resource was found and updated, false otherwise.

§Examples
let updated = lockfile.update_resource_checksum(
    "my-agent",
    "sha256:abcdef123456..."
);
assert!(updated);
Source

pub fn update_resource_applied_patches( &mut self, name: &str, applied_patches: &AppliedPatches, ) -> bool

Updates the applied patches for a resource in the lockfile by name.

This method searches through all resource types to find a resource with the matching name and updates its applied_patches field with the patches that were actually applied during installation.

The applied_patches parameter should be the AppliedPatches struct returned from the installer, which contains both project and private patches that were successfully applied.

§Arguments
  • name - The name of the resource to update
  • applied_patches - The patches that were applied (from AppliedPatches struct)
§Returns

Returns true if the resource was found and updated, false otherwise.

§Examples
let mut applied = AppliedPatches::new();
applied.project.insert("model".to_string(), toml::Value::String("haiku".into()));

let updated = lockfile.update_resource_applied_patches("my-agent", &applied);
assert!(updated);

Trait Implementations§

Source§

impl Clone for LockFile

Source§

fn clone(&self) -> LockFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LockFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for LockFile

Source§

fn default() -> Self

Create a new empty lockfile using the current format version.

This implementation of Default is equivalent to calling LockFile::new(). It creates a fresh lockfile with no sources or resources.

Source§

impl<'de> Deserialize<'de> for LockFile

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for LockFile

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,