MAESTRO: Prevent nested duplicate directory creation in CLAUDE.md paths (PR #836 concept)

Add hasConsecutiveDuplicateSegments() check to isValidPathForClaudeMd() to reject paths
like frontend/frontend/ or src/src/ that occur when cwd already includes the directory name.
3 new tests added (46 total for claude-md-utils). Fixes #814. Credit to @Glucksberg.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Alex Newman
2026-02-06 00:03:03 -05:00
parent 15e9473533
commit e5a133b3da
4 changed files with 126 additions and 48 deletions
+21
View File
@@ -16,6 +16,21 @@ import { getWorkerHost } from '../shared/worker-utils.js';
const SETTINGS_PATH = path.join(os.homedir(), '.claude-mem', 'settings.json');
/**
* Check for consecutive duplicate path segments like frontend/frontend/ or src/src/.
* This catches paths created when cwd already includes the directory name (Issue #814).
*
* @param resolvedPath - The resolved absolute path to check
* @returns true if consecutive duplicate segments are found
*/
function hasConsecutiveDuplicateSegments(resolvedPath: string): boolean {
const segments = resolvedPath.split(path.sep).filter(s => s && s !== '.' && s !== '..');
for (let i = 1; i < segments.length; i++) {
if (segments[i] === segments[i - 1]) return true;
}
return false;
}
/**
* Validate that a file path is safe for CLAUDE.md generation.
* Rejects tilde paths, URLs, command-like strings, and paths with invalid chars.
@@ -48,6 +63,12 @@ function isValidPathForClaudeMd(filePath: string, projectRoot?: string): boolean
if (!resolved.startsWith(normalizedRoot + path.sep) && resolved !== normalizedRoot) {
return false;
}
// Reject paths with consecutive duplicate segments (Issue #814)
// e.g., frontend/frontend/, backend/backend/, src/src/
if (hasConsecutiveDuplicateSegments(resolved)) {
return false;
}
}
return true;