Module redundancy

Module redundancy 

Source
Expand description

Redundancy detection and analysis for AGPM dependencies.

This module provides sophisticated analysis of dependency redundancy patterns to help users optimize their manifest files and understand resource usage. Redundancy detection is designed to be advisory rather than blocking, enabling legitimate use cases while highlighting optimization opportunities.

§Types of Redundancy

§Version Redundancy

Multiple resources referencing the same source file with different versions:

[agents]
app-helper = { source = "community", path = "agents/helper.md", version = "v1.0.0" }
tool-helper = { source = "community", path = "agents/helper.md", version = "v2.0.0" }

§Mixed Constraint Redundancy

Some dependencies use specific versions while others use latest:

[agents]
main-agent = { source = "community", path = "agents/helper.md" } # latest
backup-agent = { source = "community", path = "agents/helper.md", version = "v1.0.0" }

§Cross-Source Redundancy (Future)

Same resource available from multiple sources (not yet implemented):

[sources]
official = "https://github.com/org/agpm-official.git"
mirror = "https://github.com/org/agpm-mirror.git"

[agents]
helper1 = { source = "official", path = "agents/helper.md" }
helper2 = { source = "mirror", path = "agents/helper.md" }

§Algorithm Design

The redundancy detection algorithm operates in O(n) time complexity:

  1. Collection Phase: Build usage map of source files → resources (O(n))
  2. Analysis Phase: Identify files with multiple version usages (O(n))
  3. Classification Phase: Categorize redundancy types (O(k) where k = redundancies)

§Data Structures

The detector uses a hash map for efficient lookup:

usages: HashMap<String, Vec<ResourceUsage>>
        ↑                ↑
        source:path      list of resources using this file

§Design Principles

§Non-Blocking Detection

Redundancy analysis never prevents installation because:

  • A/B Testing: Users may intentionally install multiple versions
  • Gradual Migration: Transitioning between versions may require temporary redundancy
  • Testing Environments: Different test scenarios may need different versions
  • Rollback Capability: Keeping previous versions enables quick rollbacks

§Helpful Suggestions

Instead of blocking, the detector provides:

  • Version Alignment: Suggest using consistent versions across resources
  • Consolidation Opportunities: Identify resources that could share versions
  • Best Practices: Guide users toward maintainable dependency patterns

§Performance Considerations

  • Lazy Evaluation: Analysis only runs when explicitly requested
  • Memory Efficient: Uses references where possible to avoid cloning
  • Early Termination: Stops processing once redundancies are found (for boolean checks)
  • Batched Operations: Groups related analysis operations together

§Future Extensions

Planned enhancements for redundancy detection:

§Transitive Analysis

When dependencies-of-dependencies are supported:

impl RedundancyDetector {
    pub fn check_transitive_redundancies(&self) -> Vec<Redundancy> {
        // Analyze entire dependency tree for redundant patterns
    }
}

§Content-Based Detection

Hash-based redundancy detection for identical files:

pub struct ContentRedundancy {
    content_hash: String,
    identical_resources: Vec<ResourceUsage>,
}

§Semantic Analysis

ML-based detection of functionally similar resources:

pub struct SemanticRedundancy {
    similarity_score: f64,
    similar_resources: Vec<ResourceUsage>,
}

Structs§

Redundancy
Represents a detected redundancy pattern where multiple resources use the same source file.
RedundancyDetector
Analyzes dependency patterns to detect and categorize redundancies.
ResourceUsage
Represents a specific usage of a source file by a resource dependency.