fix(3663): preserve Hermes user-skill dirs under skills/gsd/ namespace
When kindPrefix === '' (Hermes: destSubpath=skills/gsd, no per-skill prefix),
startsWith('') always returns true so the prior removal loop would delete any
dir not in the staged set — including user-owned skill dirs. Guard the entire
removal block behind kindPrefix !== '' so non-staged dirs are never pruned when
there is no prefix to distinguish GSD-owned from user-owned entries.
TDD: failing test added first asserting user-custom-skill is preserved through
a _syncGsdDir call with kindPrefix=''.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -256,14 +256,21 @@ function _syncGsdDir(stagedDir, destDir, kind) {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove dirs in dest that match the prefix but are not in staged set
|
||||
const destEntries = fs.readdirSync(destDir);
|
||||
for (const entry of destEntries) {
|
||||
const entryPath = path.join(destDir, entry);
|
||||
if (!fs.statSync(entryPath).isDirectory()) continue;
|
||||
if (!entry.startsWith(kindPrefix)) continue; // only touch prefix-matched dirs
|
||||
if (!stagedDirs.has(entry)) {
|
||||
try { fs.rmSync(entryPath, { recursive: true, force: true }); } catch {}
|
||||
// Empty prefix = destSubpath is the GSD namespace (Hermes: skills/gsd/).
|
||||
// With no prefix filter, we cannot safely distinguish GSD-owned from user-owned dirs,
|
||||
// so we only remove dirs that match the prefix. When kindPrefix === '',
|
||||
// startsWith('') is always true but we must guard: skip removal entirely if prefix is
|
||||
// empty so user dirs under skills/gsd/ are preserved (Hermes user-skill safety).
|
||||
if (kindPrefix !== '') {
|
||||
// Remove prefix-matched dirs in dest that are not in staged set
|
||||
const destEntries = fs.readdirSync(destDir);
|
||||
for (const entry of destEntries) {
|
||||
const entryPath = path.join(destDir, entry);
|
||||
if (!fs.statSync(entryPath).isDirectory()) continue;
|
||||
if (!entry.startsWith(kindPrefix)) continue; // preserve user-owned dirs
|
||||
if (!stagedDirs.has(entry)) {
|
||||
try { fs.rmSync(entryPath, { recursive: true, force: true }); } catch {}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user