fix(#1453): rewrite stale get-shit-done paths in Codex skill mirror on upgrade (#1491)

* fix(#1453): clean up stale get-shit-done paths in Codex skill mirror on upgrade

Extends planLegacyCleanup in gsd-core/bin/lib/legacy-cleanup.cjs to scan
skills/gsd-* subdirectories for .md files that still embed the pre-rename
get-shit-done/ path (e.g. ~/.agents/skills/gsd-docs-update/SKILL.md).
These stale copies are removed by cleanupLegacyGsdCc during the next
install/upgrade so Codex can no longer discover and select them.

Adds 5 regression tests to tests/issue-607-legacy-cleanup.test.cjs covering
the stale path detection, non-flagging of fresh skills and user-owned dirs,
and the end-to-end ~/.agents/skills scenario from the issue.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(#1453): add gsd-allow-legacy-name markers to intentional legacy name references

Comments and test descriptions in legacy-cleanup.cjs and its test file
legitimately cite the old 'get-shit-done' directory name to explain what
the cleanup logic removes. Add the lint-exemption marker to each line so
lint-legacy-dir-name passes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-06-20 13:37:38 -04:00
committed by GitHub
parent 4719b36d41
commit e627584f87
3 changed files with 201 additions and 3 deletions

View File

@@ -37,6 +37,33 @@ const OLD_PACKAGE_SIGNAL = 'gsd-core' + '-cc';
*/
const GSD_MANAGED_SUBTREES = ['hooks', 'commands'];
/**
* Substring that identifies a skill file as referencing the pre-rename GSD
* runtime config subdirectory. Assembled from parts to avoid self-flagging.
*
* Old installs wrote skill bodies that embed the path to the GSD runtime
* directory — e.g. `@$HOME/.codex/get-shit-done/workflows/plan.md`. After // gsd-allow-legacy-name
* the rename to `gsd-core/` (#604), those embedded paths are stale and the
* skill file must be removed so the runtime does not pick up the wrong copy.
*
* Issue: #1453
*/
const LEGACY_SKILL_PATH_SIGNAL = 'get-shit-done'; // gsd-allow-legacy-name
/**
* Prefix that identifies a skill directory as GSD-managed.
* Only `gsd-*` subdirectories under the `skills/` subtree are scanned; user
* skill directories with other prefixes are never touched.
*/
const GSD_SKILL_DIR_PREFIX = 'gsd-';
/**
* File extensions eligible for the stale-skill-path scan.
* SKILL.md is the only file in a codex/cursor/kilo/etc skill directory that
* embeds an @-import path to the GSD runtime config tree.
*/
const SKILL_MD_EXTENSIONS = new Set(['.md']);
/**
* Extensions eligible for the content-reference scan.
*
@@ -113,6 +140,24 @@ function fileContainsOldPackageSignal(absPath, fsMod) {
}
}
/**
* Return true if the file at `absPath` contains the legacy skill path signal
* (`get-shit-done` as a path component inside an @-import or similar reference). // gsd-allow-legacy-name
* Skips unreadable files (returns false on any error).
*
* @param {string} absPath
* @param {object} fsMod
* @returns {boolean}
*/
function fileContainsLegacySkillPathSignal(absPath, fsMod) {
try {
const content = fsMod.readFileSync(absPath, 'utf8');
return content.includes('/' + LEGACY_SKILL_PATH_SIGNAL + '/'); // gsd-allow-legacy-name
} catch {
return false;
}
}
// ─── Public API ──────────────────────────────────────────────────────────────
/**
@@ -122,6 +167,9 @@ function fileContainsOldPackageSignal(absPath, fsMod) {
* Possible reasons in returned entries:
* - 'content-references-old-package': a code file whose content contains
* the old package name signal (hooks/ and commands/ subtrees only).
* - 'stale-get-shit-done-path': a skill markdown file whose content contains
* a path reference to the pre-rename `get-shit-done/` runtime directory // gsd-allow-legacy-name
* (skills/ subtree, gsd-* directories only). Issue #1453.
* - 'legacy-shared-cache': the old package's shared update-check cache file.
*
* @param {string[]} configDirs - absolute paths to runtime config dirs to scan
@@ -164,6 +212,54 @@ function planLegacyCleanup(configDirs, opts = {}) {
}
}
}
// #1453: Scan skills/gsd-* directories for stale get-shit-done path references. // gsd-allow-legacy-name
//
// Background: older GSD installs wrote SKILL.md files that embedded a path to
// the GSD runtime config directory, e.g.:
// @$HOME/.codex/get-shit-done/workflows/docs-update.md // gsd-allow-legacy-name
//
// After the rename to gsd-core/ (#604), the correct path is:
// @$HOME/.codex/gsd-core/workflows/docs-update.md
//
// When Codex upgrades to gsd-core 1.5.0 it writes fresh skill files to
// ~/.codex/skills/ but does NOT remove stale copies that an older install
// may have placed under OTHER discoverable skill roots (e.g. ~/.agents/skills/,
// ~/.config/agents/skills/). Codex can pick up either copy and the stale one
// breaks the session (#1453).
//
// This scan removes GSD-managed skill files (under gsd-* subdirs) that still
// reference the old path. Only .md files are scanned (SKILL.md is the sole
// embedded-path carrier in a skill dir). The skills/ dir itself is not deleted;
// user-owned non-gsd-* skill dirs are never touched.
const skillsDir = path.join(configDir, 'skills');
let skillDirEntries;
try {
skillDirEntries = fsMod.readdirSync(skillsDir, { withFileTypes: true });
} catch {
skillDirEntries = null;
}
if (skillDirEntries) {
for (const entry of skillDirEntries) {
// Only process gsd-* subdirectories (GSD-managed skill dirs).
if (!entry.isDirectory()) continue;
if (!entry.name.startsWith(GSD_SKILL_DIR_PREFIX)) continue;
const skillDir = path.join(skillsDir, entry.name);
const files = collectFilesUnder(skillDir, fsMod);
for (const absPath of files) {
// Never flag user-authored dev-preferences artifacts
if (isDevPreferencesPath(absPath)) continue;
// Only scan .md files for the stale path signal.
const ext = path.extname(absPath).toLowerCase();
if (SKILL_MD_EXTENSIONS.has(ext) && fileContainsLegacySkillPathSignal(absPath, fsMod)) {
addCandidate(absPath, 'stale-get-shit-done-path'); // gsd-allow-legacy-name
}
}
}
}
}
// Legacy shared cache (fixed name from the old package)