Sign in
Explore
Add-ons · HookEveryday codingReviewed

gsd-check-update-worker.js

Background worker started by gsd-check-update.js. Checks for GSD updates and stale hooks, and writes the result to a cache.

Kind
Hook
Works with
Claude Code, Gemini / Antigravity
Languages
TypeScript / JavaScript
Source
gsd-build/get-shit-done @ bdcaab2c752d
Path
hooks/gsd-check-update-worker.js
License
MIT
Jobs
Automation
InstallCopy it from the source repository, or sign in and let the assistant adapt it for your project.
#!/usr/bin/env node
// gsd-hook-version: {{GSD_VERSION}}
// Background worker spawned by gsd-check-update.js (SessionStart hook).
// Checks for GSD updates and stale hooks, writes result to cache file.
// Receives paths via environment variables set by the parent hook.
//
// Using a separate file (rather than node -e '<inline code>') avoids the
// template-literal regex-escaping problem: regex source is plain JS here.

'use strict';

const fs = require('fs');
const path = require('path');
const { execFileSync } = require('child_process');

const cacheFile = process.env.GSD_CACHE_FILE;
const projectVersionFile = process.env.GSD_PROJECT_VERSION_FILE;
const globalVersionFile = process.env.GSD_GLOBAL_VERSION_FILE;

// Compare semver: true if a > b (a is strictly newer than b)
// Strips pre-release suffixes (e.g. '3-beta.1' → '3') to avoid NaN from Number()
function isNewer(a, b) {
  const pa = (a || '').split('.').map(s => Number(s.replace(/-.*/, '')) || 0);
  const pb = (b || '').split('.').map(s => Number(s.replace(/-.*/, '')) || 0);
  for (let i = 0; i < 3; i++) {
    if (pa[i] > pb[i]) return true;
    if (pa[i] < pb[i]) return false;
  }
  return false;
}
…