greptile 2.2.8 → 2.2.10

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 +36 -10
  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,49 @@ 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) {
60
+ res.resume()
61
+ return
62
+ }
55
63
  let data = ''
56
- res.on('data', (chunk) => { data += chunk })
64
+ const MAX_BODY = 100_000 // 100KB safety limit
65
+ res.on('data', (chunk) => {
66
+ data += chunk
67
+ if (data.length > MAX_BODY) {
68
+ req.destroy()
69
+ return
70
+ }
71
+ })
57
72
  res.on('end', () => {
58
73
  try {
59
74
  const latest = JSON.parse(data)
60
75
  if (latest.version && latest.version !== localVersion) {
61
76
  console.log(`Update available: ${localVersion} → ${latest.version}. Installing...`)
62
- isUpdating = true
63
77
  // Resolve npm path — launchd has minimal PATH
64
78
  const npmPaths = ['/opt/homebrew/bin/npm', '/usr/local/bin/npm']
65
79
  let npmBin = 'npm'
66
80
  for (const p of npmPaths) {
67
- if (fs.existsSync(p)) { npmBin = p; break }
81
+ if (fs.existsSync(p)) {
82
+ npmBin = p
83
+ break
84
+ }
68
85
  }
69
- const child = spawn(npmBin, ['install', '-g', 'greptile@latest'], {
70
- stdio: 'ignore',
71
- detached: true,
72
- })
73
- child.unref()
86
+ let child
87
+ try {
88
+ child = spawn(npmBin, ['install', '-g', 'greptile@latest'], {
89
+ stdio: 'inherit',
90
+ })
91
+ } catch (err) {
92
+ console.error('Failed to spawn npm:', err.message)
93
+ return
94
+ }
95
+ isUpdating = true
74
96
  child.on('close', (code) => {
75
97
  isUpdating = false
76
98
  if (code === 0) {
77
- console.log(`Updated to greptile@${latest.version}`)
99
+ console.log(`Updated to greptile@${latest.version}. Restarting...`)
100
+ // Exit so launchd restarts the server with the new code
101
+ setTimeout(() => process.exit(0), 2000)
78
102
  } else {
79
103
  console.error(`Update failed with exit code ${code}`)
80
104
  }
@@ -88,7 +112,9 @@ function checkForUpdate() {
88
112
  })
89
113
  })
90
114
  req.on('error', () => {}) // Silently ignore network errors
91
- req.on('timeout', () => { req.destroy() })
115
+ req.on('timeout', () => {
116
+ req.destroy()
117
+ })
92
118
  }
93
119
 
94
120
  const ALLOWED_ORIGINS = ['https://app.greptile.com', 'https://app.staging.greptile.com', 'http://localhost:3000']
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greptile",
3
- "version": "2.2.8",
3
+ "version": "2.2.10",
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"