greptile 2.2.7 → 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.
- package/health-server.js +75 -0
- package/package.json +1 -1
- package/postinstall.sh +2 -0
- package/preuninstall.sh +2 -2
package/health-server.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const http = require('http')
|
|
3
|
+
const https = require('https')
|
|
3
4
|
const fs = require('fs')
|
|
4
5
|
const path = require('path')
|
|
6
|
+
const { spawn } = require('child_process')
|
|
5
7
|
|
|
6
8
|
const PORT = 4747
|
|
7
9
|
|
|
@@ -11,8 +13,13 @@ const PORT = 4747
|
|
|
11
13
|
// launchd runs with a minimal PATH that doesn't include npm global bin.
|
|
12
14
|
const PACKAGE_MARKER = path.join(__dirname, 'package.json')
|
|
13
15
|
const SELF_CHECK_INTERVAL_MS = 30_000
|
|
16
|
+
const UPDATE_CHECK_INTERVAL_MS = 6 * 60 * 60 * 1000 // 6 hours
|
|
17
|
+
let isUpdating = false
|
|
14
18
|
|
|
15
19
|
function selfCheck() {
|
|
20
|
+
// Don't self-destruct during an update — npm temporarily removes the package dir
|
|
21
|
+
if (isUpdating) return
|
|
22
|
+
|
|
16
23
|
const markerGone = !fs.existsSync(PACKAGE_MARKER)
|
|
17
24
|
|
|
18
25
|
if (markerGone) {
|
|
@@ -36,6 +43,71 @@ function selfCheck() {
|
|
|
36
43
|
}
|
|
37
44
|
}
|
|
38
45
|
|
|
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.
|
|
48
|
+
function checkForUpdate() {
|
|
49
|
+
if (isUpdating) return
|
|
50
|
+
let localVersion
|
|
51
|
+
try {
|
|
52
|
+
const pkg = JSON.parse(fs.readFileSync(PACKAGE_MARKER, 'utf8'))
|
|
53
|
+
localVersion = pkg.version
|
|
54
|
+
} catch {
|
|
55
|
+
return // Can't read local version, skip
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const req = https.get('https://registry.npmjs.org/greptile/latest', { timeout: 10_000 }, (res) => {
|
|
59
|
+
if (res.statusCode !== 200) { res.resume(); return }
|
|
60
|
+
let data = ''
|
|
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
|
+
})
|
|
66
|
+
res.on('end', () => {
|
|
67
|
+
try {
|
|
68
|
+
const latest = JSON.parse(data)
|
|
69
|
+
if (latest.version && latest.version !== localVersion) {
|
|
70
|
+
console.log(`Update available: ${localVersion} → ${latest.version}. Installing...`)
|
|
71
|
+
// Resolve npm path — launchd has minimal PATH
|
|
72
|
+
const npmPaths = ['/opt/homebrew/bin/npm', '/usr/local/bin/npm']
|
|
73
|
+
let npmBin = 'npm'
|
|
74
|
+
for (const p of npmPaths) {
|
|
75
|
+
if (fs.existsSync(p)) { npmBin = p; break }
|
|
76
|
+
}
|
|
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
|
|
88
|
+
child.unref()
|
|
89
|
+
child.on('close', (code) => {
|
|
90
|
+
isUpdating = false
|
|
91
|
+
if (code === 0) {
|
|
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)
|
|
95
|
+
} else {
|
|
96
|
+
console.error(`Update failed with exit code ${code}`)
|
|
97
|
+
}
|
|
98
|
+
})
|
|
99
|
+
child.on('error', (err) => {
|
|
100
|
+
isUpdating = false
|
|
101
|
+
console.error('Update spawn error:', err.message)
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
} catch {}
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
req.on('error', () => {}) // Silently ignore network errors
|
|
108
|
+
req.on('timeout', () => { req.destroy() })
|
|
109
|
+
}
|
|
110
|
+
|
|
39
111
|
const ALLOWED_ORIGINS = ['https://app.greptile.com', 'https://app.staging.greptile.com', 'http://localhost:3000']
|
|
40
112
|
|
|
41
113
|
const server = http.createServer((req, res) => {
|
|
@@ -75,4 +147,7 @@ server.listen(PORT, '127.0.0.1', () => {
|
|
|
75
147
|
console.log(`Greptile health server listening on http://127.0.0.1:${PORT}`)
|
|
76
148
|
// Start self-check loop after server is up
|
|
77
149
|
setInterval(selfCheck, SELF_CHECK_INTERVAL_MS)
|
|
150
|
+
// Check for updates on startup and then every 6 hours
|
|
151
|
+
checkForUpdate()
|
|
152
|
+
setInterval(checkForUpdate, UPDATE_CHECK_INTERVAL_MS)
|
|
78
153
|
})
|
package/package.json
CHANGED
package/postinstall.sh
CHANGED
|
@@ -45,6 +45,8 @@ if [ -f "$PLIST_SRC" ]; then
|
|
|
45
45
|
echo "Greptile health server installed and started."
|
|
46
46
|
fi
|
|
47
47
|
|
|
48
|
+
echo ""
|
|
49
|
+
echo "✓ greptile-cli installed successfully."
|
|
48
50
|
echo ""
|
|
49
51
|
echo "Repo path mappings are stored in ~/.greptile/repos.json."
|
|
50
52
|
echo "The first time you click 'Fix in Claude Code' for a repo,"
|
package/preuninstall.sh
CHANGED
|
@@ -11,7 +11,6 @@ APP_PATH="$HOME/Applications/Greptile Fix.app"
|
|
|
11
11
|
|
|
12
12
|
if [ -d "$APP_PATH" ]; then
|
|
13
13
|
rm -rf "$APP_PATH"
|
|
14
|
-
echo "Removed: $APP_PATH"
|
|
15
14
|
fi
|
|
16
15
|
|
|
17
16
|
# --- Health server LaunchAgent ---
|
|
@@ -19,5 +18,6 @@ PLIST_PATH="$HOME/Library/LaunchAgents/com.greptile.health.plist"
|
|
|
19
18
|
if [ -f "$PLIST_PATH" ]; then
|
|
20
19
|
launchctl unload "$PLIST_PATH" 2>/dev/null || true
|
|
21
20
|
rm -f "$PLIST_PATH"
|
|
22
|
-
echo "Removed Greptile health server LaunchAgent."
|
|
23
21
|
fi
|
|
22
|
+
|
|
23
|
+
echo "✓ greptile-cli uninstalled successfully."
|