fix(installer): deploy commands directory in local installs (#1843)

* fix(installer): deploy commands directory in local installs (#1736)

Local Claude installs now populate .claude/commands/gsd/ with command .md
files. Claude Code reads local project commands from .claude/commands/gsd/,
not .claude/skills/ — only the global ~/.claude/skills/ is used for the
skills format. The previous code deployed skills/ for both global and local
installs, causing all /gsd-* commands to return "Unknown skill" after a
local install.

Global installs continue to use skills/gsd-xxx/SKILL.md (Claude Code 2.1.88+
format). Local installs now use commands/gsd/xxx.md (the format Claude Code
reads for local project commands).

Also adds execute-phase.md to the prompt-injection scan allowlist (the
workflow grew past 50K chars, matching the existing discuss-phase.md exemption).

Closes #1736

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

* fix(installer): fix test cleanup pattern and uninstall local/global split (#1736)

Replace try/finally with t.after() in all 3 regression tests per CONTRIBUTING.md
conventions. Split the Claude Code uninstall branch on isGlobal: global removes
skills/gsd-*/ directories (with legacy commands/gsd/ cleanup), local removes
commands/gsd/ as the primary install location since #1736.

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-04-05 23:11:18 -04:00
committed by GitHub
parent 5884a24d14
commit c0145018f6
2 changed files with 137 additions and 6 deletions

View File

@@ -4285,8 +4285,8 @@ function uninstall(isGlobal, runtime = 'claude') {
}
}
}
} else {
// Claude Code: remove skills/gsd-*/ directories
} else if (isGlobal) {
// Claude Code global: remove skills/gsd-*/ directories (primary global install location)
const skillsDir = path.join(targetDir, 'skills');
if (fs.existsSync(skillsDir)) {
let skillCount = 0;
@@ -4303,7 +4303,7 @@ function uninstall(isGlobal, runtime = 'claude') {
}
}
// Also clean up legacy commands/gsd/ from older installs
// Also clean up legacy commands/gsd/ from older global installs
const legacyCommandsDir = path.join(targetDir, 'commands', 'gsd');
if (fs.existsSync(legacyCommandsDir)) {
// Preserve user-generated files before legacy wipe (#1423)
@@ -4324,6 +4324,28 @@ function uninstall(isGlobal, runtime = 'claude') {
}
}
}
} else {
// Claude Code local: remove commands/gsd/ (primary local install location since #1736)
const gsdCommandsDir = path.join(targetDir, 'commands', 'gsd');
if (fs.existsSync(gsdCommandsDir)) {
// Preserve user-generated files before wipe (#1423)
const devPrefsPath = path.join(gsdCommandsDir, 'dev-preferences.md');
const preservedDevPrefs = fs.existsSync(devPrefsPath) ? fs.readFileSync(devPrefsPath, 'utf-8') : null;
fs.rmSync(gsdCommandsDir, { recursive: true });
removedCount++;
console.log(` ${green}✓${reset} Removed commands/gsd/`);
if (preservedDevPrefs) {
try {
fs.mkdirSync(gsdCommandsDir, { recursive: true });
fs.writeFileSync(devPrefsPath, preservedDevPrefs);
console.log(` ${green}✓${reset} Preserved commands/gsd/dev-preferences.md`);
} catch (err) {
console.error(` ${red}✗${reset} Failed to restore dev-preferences.md: ${err.message}`);
}
}
}
}
// 2. Remove get-shit-done directory
@@ -5168,8 +5190,8 @@ function install(isGlobal, runtime = 'claude') {
} else {
failures.push('commands/gsd');
}
} else {
// Claude Code: skills/ format (2.1.88+ compatibility)
} else if (isGlobal) {
// Claude Code global: skills/ format (2.1.88+ compatibility)
const skillsDir = path.join(targetDir, 'skills');
const gsdSrc = path.join(src, 'commands', 'gsd');
copyCommandsAsClaudeSkills(gsdSrc, skillsDir, 'gsd', pathPrefix, runtime, isGlobal);
@@ -5185,12 +5207,39 @@ function install(isGlobal, runtime = 'claude') {
failures.push('skills/gsd-*');
}
// Clean up legacy commands/gsd/ from previous installs
// Clean up legacy commands/gsd/ from previous global installs
const legacyCommandsDir = path.join(targetDir, 'commands', 'gsd');
if (fs.existsSync(legacyCommandsDir)) {
fs.rmSync(legacyCommandsDir, { recursive: true });
console.log(` ${green}✓${reset} Removed legacy commands/gsd/ directory`);
}
} else {
// Claude Code local: commands/gsd/ format — Claude Code reads local project
// commands from .claude/commands/gsd/, not .claude/skills/
const commandsDir = path.join(targetDir, 'commands');
fs.mkdirSync(commandsDir, { recursive: true });
const gsdSrc = path.join(src, 'commands', 'gsd');
const gsdDest = path.join(commandsDir, 'gsd');
copyWithPathReplacement(gsdSrc, gsdDest, pathPrefix, runtime, true, isGlobal);
if (verifyInstalled(gsdDest, 'commands/gsd')) {
const count = fs.readdirSync(gsdDest).filter(f => f.endsWith('.md')).length;
console.log(` ${green}✓${reset} Installed ${count} commands to commands/gsd/`);
} else {
failures.push('commands/gsd');
}
// Clean up any stale skills/ from a previous local install
const staleSkillsDir = path.join(targetDir, 'skills');
if (fs.existsSync(staleSkillsDir)) {
const staleGsd = fs.readdirSync(staleSkillsDir, { withFileTypes: true })
.filter(e => e.isDirectory() && e.name.startsWith('gsd-'));
for (const e of staleGsd) {
fs.rmSync(path.join(staleSkillsDir, e.name), { recursive: true });
}
if (staleGsd.length > 0) {
console.log(` ${green}✓${reset} Removed ${staleGsd.length} stale GSD skill(s) from skills/`);
}
}
}
// Copy get-shit-done skill with path replacement

View File

@@ -0,0 +1,82 @@
/**
* Regression test for #1736: local Claude install missing commands/gsd/
*
* After a fresh local install (`--claude --local`), all /gsd-* commands
* except /gsd-help return "Unknown skill: gsd-quick" because
* .claude/commands/gsd/ is not populated. Claude Code reads local project
* commands from .claude/commands/gsd/ (the commands/ format), not from
* .claude/skills/ — only the global ~/.claude/skills/ is used for skills.
*/
'use strict';
process.env.GSD_TEST_MODE = '1';
const { describe, test, beforeEach, afterEach } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('fs');
const path = require('path');
const os = require('os');
const { execFileSync } = require('child_process');
const INSTALL_SRC = path.join(__dirname, '..', 'bin', 'install.js');
const { install, copyCommandsAsClaudeSkills } = require(INSTALL_SRC);
// ─── #1736: local install deploys commands/gsd/ ─────────────────────────────
describe('#1736: local Claude install populates .claude/commands/gsd/', () => {
let tmpDir;
beforeEach(() => {
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gsd-local-install-1736-'));
});
afterEach(() => {
fs.rmSync(tmpDir, { recursive: true, force: true });
});
test('local install creates .claude/commands/gsd/ directory', (t) => {
const origCwd = process.cwd();
t.after(() => { process.chdir(origCwd); });
process.chdir(tmpDir);
install(false, 'claude');
const commandsDir = path.join(tmpDir, '.claude', 'commands', 'gsd');
assert.ok(
fs.existsSync(commandsDir),
'.claude/commands/gsd/ directory must exist after local install'
);
});
test('local install deploys at least one .md command file to .claude/commands/gsd/', (t) => {
const origCwd = process.cwd();
t.after(() => { process.chdir(origCwd); });
process.chdir(tmpDir);
install(false, 'claude');
const commandsDir = path.join(tmpDir, '.claude', 'commands', 'gsd');
assert.ok(
fs.existsSync(commandsDir),
'.claude/commands/gsd/ must exist'
);
const files = fs.readdirSync(commandsDir).filter(f => f.endsWith('.md'));
assert.ok(
files.length > 0,
`.claude/commands/gsd/ must contain at least one .md file, found: ${JSON.stringify(files)}`
);
});
test('local install deploys quick.md to .claude/commands/gsd/', (t) => {
const origCwd = process.cwd();
t.after(() => { process.chdir(origCwd); });
process.chdir(tmpDir);
install(false, 'claude');
const quickCmd = path.join(tmpDir, '.claude', 'commands', 'gsd', 'quick.md');
assert.ok(
fs.existsSync(quickCmd),
'.claude/commands/gsd/quick.md must exist after local install'
);
});
});