greptile 2.2.8 → 2.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/health-server.js +24 -7
  2. package/package.json +1 -1
package/health-server.js CHANGED
@@ -17,6 +17,9 @@ const UPDATE_CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000 // 6 hours
17
17
  let isUpdating = false
18
18
 
19
19
  function selfCheck() {
20
+ // Don't self-destruct during an update — npm temporarily removes the package dir
21
+ if (isUpdating) return
22
+
20
23
  const markerGone = !fs.existsSync(PACKAGE_MARKER)
21
24
 
22
25
  if (markerGone) {
@@ -41,6 +44,7 @@ function selfCheck() {
41
44
  }
42
45
 
43
46
  // Auto-update: periodically check npm registry for a newer version and install it.
47
+ // After a successful update, the process exits so launchd restarts it with the new code.
44
48
  function checkForUpdate() {
45
49
  if (isUpdating) return
46
50
  let localVersion
@@ -52,29 +56,42 @@ function checkForUpdate() {
52
56
  }
53
57
 
54
58
  const req = https.get('https://registry.npmjs.org/greptile/latest', { timeout: 10_000 }, (res) => {
59
+ if (res.statusCode !== 200) { res.resume(); return }
55
60
  let data = ''
56
- res.on('data', (chunk) => { data += chunk })
61
+ const MAX_BODY = 100_000 // 100KB safety limit
62
+ res.on('data', (chunk) => {
63
+ data += chunk
64
+ if (data.length > MAX_BODY) { req.destroy(); return }
65
+ })
57
66
  res.on('end', () => {
58
67
  try {
59
68
  const latest = JSON.parse(data)
60
69
  if (latest.version && latest.version !== localVersion) {
61
70
  console.log(`Update available: ${localVersion} → ${latest.version}. Installing...`)
62
- isUpdating = true
63
71
  // Resolve npm path — launchd has minimal PATH
64
72
  const npmPaths = ['/opt/homebrew/bin/npm', '/usr/local/bin/npm']
65
73
  let npmBin = 'npm'
66
74
  for (const p of npmPaths) {
67
75
  if (fs.existsSync(p)) { npmBin = p; break }
68
76
  }
69
- const child = spawn(npmBin, ['install', '-g', 'greptile@latest'], {
70
- stdio: 'ignore',
71
- detached: true,
72
- })
77
+ let child
78
+ try {
79
+ child = spawn(npmBin, ['install', '-g', 'greptile@latest'], {
80
+ stdio: 'ignore',
81
+ detached: true,
82
+ })
83
+ } catch (err) {
84
+ console.error('Failed to spawn npm:', err.message)
85
+ return
86
+ }
87
+ isUpdating = true
73
88
  child.unref()
74
89
  child.on('close', (code) => {
75
90
  isUpdating = false
76
91
  if (code === 0) {
77
- console.log(`Updated to greptile@${latest.version}`)
92
+ console.log(`Updated to greptile@${latest.version}. Restarting...`)
93
+ // Exit so launchd restarts the server with the new code
94
+ setTimeout(() => process.exit(0), 2000)
78
95
  } else {
79
96
  console.error(`Update failed with exit code ${code}`)
80
97
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greptile",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
4
4
  "description": "Bridge for Greptile code review 'Fix in Claude Code' and 'Fix in Codex' links",
5
5
  "bin": {
6
6
  "greptile-fix": "bin/greptile-fix.js"