Skip to content

Extract shared artifact-removal helpers to reduce duplication in Configurator #236

@bguidolim

Description

@bguidolim

Context

PR #234 added removeNewlyExcludedComponentArtifacts() and reconcileStaleArtifacts() to handle convergence gaps. Both methods duplicate the same per-artifact-type removal patterns (MCP servers, files, brew packages, plugins, gitignore entries) that already exist in unconfigurePack().

Problem

Three methods in Configurator.swift perform artifact removal with near-identical patterns:

  • unconfigurePack() — removes all artifacts for a whole pack
  • removeNewlyExcludedComponentArtifacts() — removes artifacts for newly-excluded components
  • reconcileStaleArtifacts() — removes stale artifacts from previous sync

Each reimplements: ResourceRefCounter checks for brew/plugins, GitignoreManager removal loops, exec.removeMCPServer() calls, strategy.removeFileArtifact() calls. ~100-120 lines of duplicated removal logic.

Proposed Solution

Extract per-artifact-type removal helpers:

  • removeMCPArtifact(name:scope:executor:) -> Bool
  • removeFileArtifact(relativePath:) -> Bool
  • removeBrewArtifact(package:packID:refCounter:executor:) -> Bool
  • removePluginArtifact(name:packID:refCounter:executor:) -> Bool
  • removeGitignoreArtifact(entry:) -> Bool

All three callsites can then use these helpers, reducing duplication and ensuring removal logic stays consistent.

Notes

The three methods operate at different abstraction levels (component definitions vs artifact records), so a full unification isn't practical. Per-type helpers are the right granularity.

Discovered during /simplify code review of PR #234.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions