Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions Sources/mcs/Install/Configurator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ struct Configurator {
}

case let .copyPackFile(_, destination, fileType):
let relativePath = deriveFileRelativePath(
let relativePath = strategy.fileRelativePath(
destination: destination, fileType: fileType
)
if removeFileArtifactItem(relativePath: relativePath) {
Expand Down Expand Up @@ -519,26 +519,6 @@ struct Configurator {
}
}

/// Derive the relative file path that `installArtifacts` would have recorded for a `copyPackFile` component.
private func deriveFileRelativePath(destination: String, fileType: CopyFileType) -> String {
if scope.isGlobalScope {
let baseDir = fileType.baseDirectory(in: environment)
let destURL = baseDir.appendingPathComponent(destination)
return PathContainment.relativePath(
of: destURL.path,
within: environment.claudeDirectory.path
)
} else {
let projectPath = scope.targetPath.deletingLastPathComponent()
let baseDir = fileType.projectBaseDirectory(projectPath: projectPath)
let destURL = baseDir.appendingPathComponent(destination)
return PathContainment.relativePath(
of: destURL.path,
within: projectPath.path
)
}
}

/// Resolve all template/placeholder values upfront (single pass).
///
/// Resolves built-in values (e.g. REPO_NAME), shared cross-pack prompts,
Expand Down
17 changes: 11 additions & 6 deletions Sources/mcs/Install/GlobalSyncStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ struct GlobalSyncStrategy: SyncStrategy {
resolvedValues: resolvedValues
)
if result.success {
let baseDir = fileType.baseDirectory(in: environment)
let destURL = baseDir.appendingPathComponent(destination)
let relativePath = PathContainment.relativePath(
of: destURL.path,
within: environment.claudeDirectory.path
)
let relativePath = fileRelativePath(destination: destination, fileType: fileType)
artifacts.files.append(relativePath)
artifacts.fileHashes.merge(result.hashes) { _, new in new }
if component.type == .hookFile,
Expand Down Expand Up @@ -301,6 +296,16 @@ struct GlobalSyncStrategy: SyncStrategy {
return Set(allContributions.map(\.sectionIdentifier))
}

// MARK: - File Path Derivation

func fileRelativePath(destination: String, fileType: CopyFileType) -> String {
let destURL = fileType.destinationURL(in: environment, destination: destination)
return PathContainment.relativePath(
of: destURL.path,
within: environment.claudeDirectory.path
)
}

// MARK: - File Removal

func removeFileArtifact(relativePath: String, output: CLIOutput) -> Bool {
Expand Down
11 changes: 11 additions & 0 deletions Sources/mcs/Install/ProjectSyncStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ struct ProjectSyncStrategy: SyncStrategy {
return Set(allContributions.map(\.sectionIdentifier))
}

// MARK: - File Path Derivation

func fileRelativePath(destination: String, fileType: CopyFileType) -> String {
let baseDir = fileType.projectBaseDirectory(projectPath: projectPath)
let destURL = baseDir.appendingPathComponent(destination)
return PathContainment.relativePath(
of: destURL.path,
within: projectPath.path
)
}

// MARK: - File Removal

func removeFileArtifact(relativePath: String, output: CLIOutput) -> Bool {
Expand Down
6 changes: 6 additions & 0 deletions Sources/mcs/Install/SyncStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ protocol SyncStrategy {
output: CLIOutput
) throws -> Set<String>?

/// Derive the relative file path that artifact tracking records for a `copyPackFile` component.
///
/// Global scope computes relative to `~/.claude/`.
/// Project scope computes relative to the project root.
func fileRelativePath(destination: String, fileType: CopyFileType) -> String

/// Remove a file artifact during pack unconfiguration.
///
/// Project scope uses `ComponentExecutor.removeProjectFile`.
Expand Down
Loading