mirror of
https://github.com/glittercowboy/get-shit-done
synced 2026-05-15 11:36:37 +02:00
* feat(hooks): opt-in SessionStart update banner for non-statusline users (#2795) When a user declines (or keeps a non-GSD) statusline at install time, the installer now offers an opt-in SessionStart banner that surfaces GSD update availability. The banner reads the existing ~/.cache/gsd/gsd-update-check.json cache (written by gsd-check-update-worker.js) and emits a single systemMessage line only when update_available is true: GSD update available: <installed> → <latest>. Run /gsd-update. It is silent when up-to-date and rate-limits "check failed" diagnostics to once per 24h via a sentinel file so a corrupt cache doesn't nag every session. Removed cleanly by `npx get-shit-done-cc --uninstall` which strips both the script and the SessionStart entry. The banner is never offered when GSD's statusline is being installed (statusline already surfaces update info, so re-prompting would be noise). Implementation: - hooks/gsd-update-banner.js — pure functions buildBannerOutput, shouldSuppressFailureWarning, readCache; thin main() wires them. - bin/install.js — handleUpdateBanner() prompt, parseUpdateBannerInput(), buildUpdateBannerHookEntry(), buildUpdateBannerPromptText(); chained into installAllRuntimes() so finalize() receives both flags. updateBannerCommand computed alongside the other JS-hook commands; finishInstall() registers the SessionStart entry only when shouldInstallBanner === true and the hook file is present at the target. - Hook ships in scripts/build-hooks.js HOOKS_TO_COPY, listed in MANAGED_HOOKS for stale-detection in gsd-check-update-worker.js, in the uninstall hook-removal lists in install.js, and in the rewriteLegacyManagedNodeHookCommands allowlist. Tests: - tests/feat-2795-update-banner.test.cjs — 22 tests, structural-IR assertions on parsed JSON envelopes (no raw-text matching). Covers pure-function branches (cache present/absent, parseError, rate-limit suppression, missing version fields), end-to-end hook invocation against fixture cache states, and install.js wiring (prompt text, input parsing, hook entry shape). - tests/trae-install.test.cjs — updated install() return-shape assertion to include updateBannerCommand: null for the no-settings runtime. - 6881/6881 tests pass. Docs (bundled in same commit per the bundle-docs-with-code skill): - docs/USER-GUIDE.md — new "Surface GSD Update Notifications Without GSD's Statusline" task section with opt-in/opt-out instructions. - docs/FEATURES.md — REQ-HOOK-08 added; "Update Banner" subsection under the Hook System feature with cache flow + removal path. - docs/INVENTORY.md — hook count 11 → 12, new row for gsd-update-banner.js. - docs/INVENTORY-MANIFEST.json — regenerated. Closes #2795 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * fix(install): gate banner prompt on actual installability (CR #3035) CodeRabbit findings on PR #3035: - bin/install.js (Major): continueAfterStatusline gated banner prompt on the raw `shouldInstallStatusline` flag from handleStatusline. But finishInstall later silently skips the statusline write on local installs unless --force-statusline is set (#2248). Two consequences: 1. Interactive local Claude/Gemini installs got neither a statusline nor a banner offer. 2. Codex/Cursor/Copilot/Windsurf/Trae/Cline-only installs (where every result.updateBannerCommand is null) still got prompted even though the choice was silently ignored. Fix: derive willInstallStatusline = shouldInstallStatusline && (isGlobal || forceStatusline), and gate the banner prompt on a canInstallBanner precondition computed from results[].updateBannerCommand. Pass the raw shouldInstallStatusline through to finalize unchanged so per-runtime statusline gating in finishInstall is unaffected. - tests/feat-2795-update-banner.test.cjs (Minor): rate-limit suppression test parsed r1.stdout without first asserting r1.status === 0. Other e2e tests in this file (lines 210, 241) do this. A non-zero exit would surface as a cryptic SyntaxError instead of a status assertion failure. Fix applied verbatim. 6881/6881 tests pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
269 lines
8.8 KiB
JavaScript
269 lines
8.8 KiB
JavaScript
// allow-test-rule: pending-migration-to-typed-ir [#2974]
|
|
// Tracked in #2974 for migration to typed-IR assertions per CONTRIBUTING.md
|
|
// "Prohibited: Raw Text Matching on Test Outputs". Per-file review may
|
|
// reclassify some entries as source-text-is-the-product during migration.
|
|
|
|
process.env.GSD_TEST_MODE = '1';
|
|
|
|
const { test, describe, beforeEach, afterEach } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const os = require('node:os');
|
|
const { createTempDir, cleanup } = require('./helpers.cjs');
|
|
|
|
const {
|
|
getDirName,
|
|
getGlobalDir,
|
|
getConfigDirFromHome,
|
|
convertClaudeToTraeMarkdown,
|
|
convertClaudeCommandToTraeSkill,
|
|
convertClaudeAgentToTraeAgent,
|
|
copyCommandsAsTraeSkills,
|
|
install,
|
|
uninstall,
|
|
writeManifest,
|
|
} = require('../bin/install.js');
|
|
|
|
describe('Trae runtime directory mapping', () => {
|
|
test('maps Trae to .trae for local installs', () => {
|
|
assert.strictEqual(getDirName('trae'), '.trae');
|
|
});
|
|
|
|
test('maps Trae to ~/.trae for global installs', () => {
|
|
assert.strictEqual(getGlobalDir('trae'), path.join(os.homedir(), '.trae'));
|
|
});
|
|
|
|
test('returns .trae config fragments for local and global installs', () => {
|
|
assert.strictEqual(getConfigDirFromHome('trae', false), "'.trae'");
|
|
assert.strictEqual(getConfigDirFromHome('trae', true), "'.trae'");
|
|
});
|
|
});
|
|
|
|
describe('getGlobalDir (Trae)', () => {
|
|
let originalTraeConfigDir;
|
|
|
|
beforeEach(() => {
|
|
originalTraeConfigDir = process.env.TRAE_CONFIG_DIR;
|
|
});
|
|
|
|
afterEach(() => {
|
|
if (originalTraeConfigDir !== undefined) {
|
|
process.env.TRAE_CONFIG_DIR = originalTraeConfigDir;
|
|
} else {
|
|
delete process.env.TRAE_CONFIG_DIR;
|
|
}
|
|
});
|
|
|
|
test('returns ~/.trae with no env var or explicit dir', () => {
|
|
delete process.env.TRAE_CONFIG_DIR;
|
|
const result = getGlobalDir('trae');
|
|
assert.strictEqual(result, path.join(os.homedir(), '.trae'));
|
|
});
|
|
|
|
test('returns explicit dir when provided', () => {
|
|
const result = getGlobalDir('trae', '/custom/trae-path');
|
|
assert.strictEqual(result, '/custom/trae-path');
|
|
});
|
|
|
|
test('respects TRAE_CONFIG_DIR env var', () => {
|
|
process.env.TRAE_CONFIG_DIR = '~/custom-trae';
|
|
const result = getGlobalDir('trae');
|
|
assert.strictEqual(result, path.join(os.homedir(), 'custom-trae'));
|
|
});
|
|
|
|
test('explicit dir takes priority over TRAE_CONFIG_DIR', () => {
|
|
process.env.TRAE_CONFIG_DIR = '~/from-env';
|
|
const result = getGlobalDir('trae', '/explicit/path');
|
|
assert.strictEqual(result, '/explicit/path');
|
|
});
|
|
|
|
test('does not break other runtimes', () => {
|
|
assert.strictEqual(getGlobalDir('claude'), path.join(os.homedir(), '.claude'));
|
|
assert.strictEqual(getGlobalDir('codex'), path.join(os.homedir(), '.codex'));
|
|
});
|
|
});
|
|
|
|
describe('Trae markdown conversion', () => {
|
|
test('converts Claude-specific references to Trae equivalents', () => {
|
|
const input = [
|
|
'Claude Code reads CLAUDE.md before using .claude/skills/.',
|
|
'Run /gsd:plan-phase with $ARGUMENTS.',
|
|
'Use Bash(command) and Edit(file).',
|
|
].join('\n');
|
|
|
|
const result = convertClaudeToTraeMarkdown(input);
|
|
|
|
assert.ok(result.includes('Trae reads .trae/rules/ before using .trae/skills/.'), result);
|
|
assert.ok(result.includes('/gsd-plan-phase'), result);
|
|
assert.ok(result.includes('{{GSD_ARGS}}'), result);
|
|
assert.ok(result.includes('Shell('), result);
|
|
assert.ok(result.includes('StrReplace('), result);
|
|
});
|
|
|
|
test('converts commands and agents to Trae frontmatter', () => {
|
|
const command = `---
|
|
name: gsd:new-project
|
|
description: Initialize a project
|
|
---
|
|
|
|
Use .claude/skills/ and /gsd:help.
|
|
`;
|
|
const agent = `---
|
|
name: gsd-planner
|
|
description: Planner agent
|
|
tools: Read, Write
|
|
color: blue
|
|
---
|
|
|
|
Read CLAUDE.md before acting.
|
|
`;
|
|
|
|
const convertedCommand = convertClaudeCommandToTraeSkill(command, 'gsd-new-project');
|
|
const convertedAgent = convertClaudeAgentToTraeAgent(agent);
|
|
|
|
assert.ok(convertedCommand.includes('name: gsd-new-project'), convertedCommand);
|
|
assert.ok(!convertedCommand.includes('<trae_skill_adapter>'), convertedCommand);
|
|
assert.ok(convertedCommand.includes('.trae/skills/'), convertedCommand);
|
|
assert.ok(convertedCommand.includes('/gsd-help'), convertedCommand);
|
|
|
|
assert.ok(convertedAgent.includes('name: gsd-planner'), convertedAgent);
|
|
assert.ok(!convertedAgent.includes('color:'), convertedAgent);
|
|
assert.ok(convertedAgent.includes('.trae/rules/'), convertedAgent);
|
|
});
|
|
});
|
|
|
|
describe('copyCommandsAsTraeSkills', () => {
|
|
let tmpDir;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempDir('gsd-trae-copy-');
|
|
});
|
|
|
|
afterEach(() => {
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('creates one skill directory per GSD command', () => {
|
|
const srcDir = path.join(__dirname, '..', 'commands', 'gsd');
|
|
const skillsDir = path.join(tmpDir, '.trae', 'skills');
|
|
|
|
copyCommandsAsTraeSkills(srcDir, skillsDir, 'gsd', '$HOME/.trae/', 'trae');
|
|
|
|
const generated = path.join(skillsDir, 'gsd-help', 'SKILL.md');
|
|
assert.ok(fs.existsSync(generated), generated);
|
|
|
|
const content = fs.readFileSync(generated, 'utf8');
|
|
assert.ok(!content.includes('<trae_skill_adapter>'), content);
|
|
assert.ok(content.includes('name: gsd-help'), content);
|
|
});
|
|
});
|
|
|
|
describe('Trae local install/uninstall', () => {
|
|
let tmpDir;
|
|
let previousCwd;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempDir('gsd-trae-install-');
|
|
previousCwd = process.cwd();
|
|
process.chdir(tmpDir);
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.chdir(previousCwd);
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('installs GSD into ./.trae and removes it cleanly', () => {
|
|
const result = install(false, 'trae');
|
|
const targetDir = path.join(tmpDir, '.trae');
|
|
|
|
assert.deepStrictEqual(result, {
|
|
settingsPath: null,
|
|
settings: null,
|
|
statuslineCommand: null,
|
|
updateBannerCommand: null,
|
|
runtime: 'trae',
|
|
configDir: fs.realpathSync(targetDir),
|
|
});
|
|
|
|
assert.ok(fs.existsSync(path.join(targetDir, 'skills', 'gsd-help', 'SKILL.md')));
|
|
assert.ok(fs.existsSync(path.join(targetDir, 'get-shit-done', 'VERSION')));
|
|
assert.ok(fs.existsSync(path.join(targetDir, 'agents')));
|
|
|
|
const manifest = writeManifest(targetDir, 'trae');
|
|
assert.ok(Object.keys(manifest.files).some(file => file.startsWith('skills/gsd-help/')), manifest);
|
|
|
|
uninstall(false, 'trae');
|
|
|
|
assert.ok(!fs.existsSync(path.join(targetDir, 'skills', 'gsd-help')), 'Trae skill directory removed');
|
|
assert.ok(!fs.existsSync(path.join(targetDir, 'get-shit-done')), 'get-shit-done removed');
|
|
});
|
|
});
|
|
|
|
describe('E2E: Trae uninstall skills cleanup', () => {
|
|
let tmpDir;
|
|
let previousCwd;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempDir('gsd-trae-uninstall-');
|
|
previousCwd = process.cwd();
|
|
process.chdir(tmpDir);
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.chdir(previousCwd);
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
test('removes all gsd-* skill directories on --trae --uninstall', () => {
|
|
const targetDir = path.join(tmpDir, '.trae');
|
|
install(false, 'trae');
|
|
|
|
const skillsDir = path.join(targetDir, 'skills');
|
|
assert.ok(fs.existsSync(skillsDir), 'skills dir exists after install');
|
|
|
|
const installedSkills = fs.readdirSync(skillsDir, { withFileTypes: true })
|
|
.filter(e => e.isDirectory() && e.name.startsWith('gsd-'));
|
|
assert.ok(installedSkills.length > 0, `found ${installedSkills.length} gsd-* skill dirs before uninstall`);
|
|
|
|
uninstall(false, 'trae');
|
|
|
|
if (fs.existsSync(skillsDir)) {
|
|
const remainingGsd = fs.readdirSync(skillsDir, { withFileTypes: true })
|
|
.filter(e => e.isDirectory() && e.name.startsWith('gsd-'));
|
|
assert.strictEqual(remainingGsd.length, 0,
|
|
`Expected 0 gsd-* skill dirs after uninstall, found: ${remainingGsd.map(e => e.name).join(', ')}`);
|
|
}
|
|
});
|
|
|
|
test('preserves non-GSD skill directories during --trae --uninstall', () => {
|
|
const targetDir = path.join(tmpDir, '.trae');
|
|
install(false, 'trae');
|
|
|
|
const customSkillDir = path.join(targetDir, 'skills', 'my-custom-skill');
|
|
fs.mkdirSync(customSkillDir, { recursive: true });
|
|
fs.writeFileSync(path.join(customSkillDir, 'SKILL.md'), '# My Custom Skill\n');
|
|
|
|
assert.ok(fs.existsSync(path.join(customSkillDir, 'SKILL.md')), 'custom skill exists before uninstall');
|
|
|
|
uninstall(false, 'trae');
|
|
|
|
assert.ok(fs.existsSync(path.join(customSkillDir, 'SKILL.md')),
|
|
'Non-GSD skill directory should be preserved after Trae uninstall');
|
|
});
|
|
|
|
test('removes engine directory on --trae --uninstall', () => {
|
|
const targetDir = path.join(tmpDir, '.trae');
|
|
install(false, 'trae');
|
|
|
|
assert.ok(fs.existsSync(path.join(targetDir, 'get-shit-done', 'VERSION')),
|
|
'engine exists before uninstall');
|
|
|
|
uninstall(false, 'trae');
|
|
|
|
assert.ok(!fs.existsSync(path.join(targetDir, 'get-shit-done')),
|
|
'get-shit-done engine should be removed after Trae uninstall');
|
|
});
|
|
});
|