On Windows, the detached spawn option creates a visible console window. Combined with npm (which is a .cmd batch file), this causes a brief window flash that steals focus from the user's terminal. - Remove detached: true (not needed, child.unref() handles non-blocking) - Add windowsHide: true to both spawn() and inner execSync()
52 lines
1.5 KiB
JavaScript
Executable File
52 lines
1.5 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
// Check for GSD updates in background, write result to cache
|
|
// Called by SessionStart hook - runs once per session
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const os = require('os');
|
|
const { execSync, spawn } = require('child_process');
|
|
|
|
const homeDir = os.homedir();
|
|
const cacheDir = path.join(homeDir, '.claude', 'cache');
|
|
const cacheFile = path.join(cacheDir, 'gsd-update-check.json');
|
|
const versionFile = path.join(homeDir, '.claude', 'get-shit-done', 'VERSION');
|
|
|
|
// Ensure cache directory exists
|
|
if (!fs.existsSync(cacheDir)) {
|
|
fs.mkdirSync(cacheDir, { recursive: true });
|
|
}
|
|
|
|
// Run check in background (spawn background process, windowsHide prevents console flash)
|
|
const child = spawn(process.execPath, ['-e', `
|
|
const fs = require('fs');
|
|
const { execSync } = require('child_process');
|
|
|
|
const cacheFile = ${JSON.stringify(cacheFile)};
|
|
const versionFile = ${JSON.stringify(versionFile)};
|
|
|
|
let installed = '0.0.0';
|
|
try {
|
|
installed = fs.readFileSync(versionFile, 'utf8').trim();
|
|
} catch (e) {}
|
|
|
|
let latest = null;
|
|
try {
|
|
latest = execSync('npm view get-shit-done-cc version', { encoding: 'utf8', timeout: 10000, windowsHide: true }).trim();
|
|
} catch (e) {}
|
|
|
|
const result = {
|
|
update_available: latest && installed !== latest,
|
|
installed,
|
|
latest: latest || 'unknown',
|
|
checked: Math.floor(Date.now() / 1000)
|
|
};
|
|
|
|
fs.writeFileSync(cacheFile, JSON.stringify(result));
|
|
`], {
|
|
stdio: 'ignore',
|
|
windowsHide: true
|
|
});
|
|
|
|
child.unref();
|