@chrysb/alphaclaw 0.1.5 → 0.1.7
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/lib/server/alphaclaw-version.js +26 -20
- package/package.json +1 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
const { exec } = require("child_process");
|
|
2
|
-
const { spawn } = require("child_process");
|
|
3
2
|
const fs = require("fs");
|
|
4
3
|
const path = require("path");
|
|
5
4
|
const https = require("https");
|
|
@@ -30,19 +29,27 @@ const createAlphaclawVersionService = () => {
|
|
|
30
29
|
|
|
31
30
|
const fetchLatestVersionFromRegistry = () =>
|
|
32
31
|
new Promise((resolve, reject) => {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
resolve(parsed["dist-tags"]?.latest || null);
|
|
41
|
-
} catch (e) {
|
|
42
|
-
reject(new Error("Failed to parse registry response"));
|
|
32
|
+
const doGet = (url, redirects = 0) => {
|
|
33
|
+
if (redirects > 3) return reject(new Error("Too many redirects"));
|
|
34
|
+
const get = url.startsWith("https") ? https.get : http.get;
|
|
35
|
+
get(url, { headers: { Accept: "application/vnd.npm.install-v1+json" } }, (res) => {
|
|
36
|
+
if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
37
|
+
res.resume();
|
|
38
|
+
return doGet(res.headers.location, redirects + 1);
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
let data = "";
|
|
41
|
+
res.on("data", (chunk) => { data += chunk; });
|
|
42
|
+
res.on("end", () => {
|
|
43
|
+
try {
|
|
44
|
+
const parsed = JSON.parse(data);
|
|
45
|
+
resolve(parsed["dist-tags"]?.latest || null);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
reject(new Error(`Failed to parse registry response (status ${res.statusCode})`));
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}).on("error", reject);
|
|
51
|
+
};
|
|
52
|
+
doGet(kAlphaclawRegistryUrl);
|
|
46
53
|
});
|
|
47
54
|
|
|
48
55
|
const readAlphaclawUpdateStatus = async ({ refresh = false } = {}) => {
|
|
@@ -124,13 +131,12 @@ const createAlphaclawVersionService = () => {
|
|
|
124
131
|
});
|
|
125
132
|
|
|
126
133
|
const restartProcess = () => {
|
|
127
|
-
console.log("[alphaclaw] Restarting process...");
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
process.exit(0);
|
|
134
|
+
console.log("[alphaclaw] Restarting process (exit 1 to trigger container restart)...");
|
|
135
|
+
// Exit with code 1 so container orchestrators (Railway, Docker restart policy)
|
|
136
|
+
// treat it as a crash and automatically restart the service.
|
|
137
|
+
// The spawned-child approach doesn't work in containers because killing PID 1
|
|
138
|
+
// tears down the entire container.
|
|
139
|
+
process.exit(1);
|
|
134
140
|
};
|
|
135
141
|
|
|
136
142
|
const getVersionStatus = async (refresh) => {
|