@chrysb/alphaclaw 0.8.7 → 0.8.8
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/bin/alphaclaw.js +174 -43
- package/lib/public/css/tailwind.generated.css +1 -1
- package/lib/public/dist/app.bundle.js +2109 -2089
- package/lib/public/js/app.js +3 -0
- package/lib/public/js/components/gateway.js +6 -3
- package/lib/public/js/components/general/index.js +2 -0
- package/lib/public/js/components/onboarding/welcome-form-step.js +29 -4
- package/lib/public/js/components/routes/general-route.js +2 -0
- package/lib/public/js/components/routes/watchdog-route.js +2 -0
- package/lib/public/js/components/sidebar.js +20 -7
- package/lib/public/js/components/update-modal-helpers.js +12 -0
- package/lib/public/js/components/update-modal.js +2 -1
- package/lib/public/js/components/watchdog-tab/index.js +2 -0
- package/lib/public/js/components/welcome/index.js +1 -0
- package/lib/public/js/components/welcome/use-welcome.js +52 -2
- package/lib/public/js/hooks/use-app-shell-controller.js +37 -9
- package/lib/public/js/lib/api.js +36 -0
- package/lib/release/managed-release.js +180 -0
- package/lib/server/alphaclaw-runtime.js +294 -0
- package/lib/server/alphaclaw-version.js +37 -128
- package/lib/server/gateway.js +32 -14
- package/lib/server/init/register-server-routes.js +7 -1
- package/lib/server/openclaw-runtime.js +428 -0
- package/lib/server/openclaw-version.js +76 -136
- package/lib/server/package-fingerprint.js +274 -0
- package/lib/server/pending-alphaclaw-update.js +85 -0
- package/lib/server/pending-openclaw-update.js +86 -0
- package/lib/server/routes/pages.js +9 -1
- package/lib/server/routes/system.js +6 -1
- package/lib/server/usage-tracker-config.js +27 -3
- package/package.json +3 -2
- package/patches/openclaw+2026.4.9.patch +13 -0
- package/patches/openclaw+2026.4.5.patch +0 -13
package/lib/server/gateway.js
CHANGED
|
@@ -2,6 +2,7 @@ const path = require("path");
|
|
|
2
2
|
const { spawn, execSync } = require("child_process");
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const net = require("net");
|
|
5
|
+
const { getManagedOpenclawBinPath } = require("./openclaw-runtime");
|
|
5
6
|
const {
|
|
6
7
|
ALPHACLAW_DIR,
|
|
7
8
|
OPENCLAW_DIR,
|
|
@@ -48,6 +49,16 @@ const gatewayEnv = () => ({
|
|
|
48
49
|
XDG_CONFIG_HOME: OPENCLAW_DIR,
|
|
49
50
|
});
|
|
50
51
|
|
|
52
|
+
const shellQuote = (value) =>
|
|
53
|
+
`'${String(value || "").replace(/'/g, `'\"'\"'`)}'`;
|
|
54
|
+
|
|
55
|
+
const getOpenclawCommandPath = () => {
|
|
56
|
+
const managedBinPath = getManagedOpenclawBinPath();
|
|
57
|
+
return fs.existsSync(managedBinPath) ? managedBinPath : "openclaw";
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const getOpenclawCommandPrefix = () => shellQuote(getOpenclawCommandPath());
|
|
61
|
+
|
|
51
62
|
const writeOnboardingMarker = (reason) => {
|
|
52
63
|
fs.mkdirSync(ALPHACLAW_DIR, { recursive: true });
|
|
53
64
|
fs.writeFileSync(
|
|
@@ -119,9 +130,10 @@ const isGatewayRunning = () =>
|
|
|
119
130
|
});
|
|
120
131
|
|
|
121
132
|
const runGatewayCmd = (cmd) => {
|
|
122
|
-
|
|
133
|
+
const openclawCommandPrefix = getOpenclawCommandPrefix();
|
|
134
|
+
console.log(`[alphaclaw] Running: ${openclawCommandPrefix} gateway ${cmd}`);
|
|
123
135
|
try {
|
|
124
|
-
const out = execSync(
|
|
136
|
+
const out = execSync(`${openclawCommandPrefix} gateway ${cmd}`, {
|
|
125
137
|
env: gatewayEnv(),
|
|
126
138
|
timeout: 15000,
|
|
127
139
|
encoding: "utf8",
|
|
@@ -146,7 +158,7 @@ const launchGatewayProcess = () => {
|
|
|
146
158
|
return gatewayChild;
|
|
147
159
|
}
|
|
148
160
|
gatewayStderrTail = [];
|
|
149
|
-
const child = spawn(
|
|
161
|
+
const child = spawn(getOpenclawCommandPath(), ["gateway", "run"], {
|
|
150
162
|
env: gatewayEnv(),
|
|
151
163
|
stdio: ["pipe", "pipe", "pipe"],
|
|
152
164
|
});
|
|
@@ -306,7 +318,7 @@ const syncChannelConfig = (savedVars, mode = "all") => {
|
|
|
306
318
|
const appToken = savedMap[def.extraEnvKeys?.[0]];
|
|
307
319
|
if (!appToken) continue;
|
|
308
320
|
execSync(
|
|
309
|
-
|
|
321
|
+
`${getOpenclawCommandPrefix()} channels add --channel slack --bot-token "${token}" --app-token "${appToken}"`,
|
|
310
322
|
{ env, timeout: 15000, encoding: "utf8" },
|
|
311
323
|
);
|
|
312
324
|
let raw = fs.readFileSync(configPath, "utf8");
|
|
@@ -318,11 +330,14 @@ const syncChannelConfig = (savedVars, mode = "all") => {
|
|
|
318
330
|
}
|
|
319
331
|
fs.writeFileSync(configPath, raw);
|
|
320
332
|
} else {
|
|
321
|
-
execSync(
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
333
|
+
execSync(
|
|
334
|
+
`${getOpenclawCommandPrefix()} channels add --channel ${ch} --token "${token}"`,
|
|
335
|
+
{
|
|
336
|
+
env,
|
|
337
|
+
timeout: 15000,
|
|
338
|
+
encoding: "utf8",
|
|
339
|
+
},
|
|
340
|
+
);
|
|
326
341
|
const raw = fs.readFileSync(configPath, "utf8");
|
|
327
342
|
if (raw.includes(token)) {
|
|
328
343
|
fs.writeFileSync(
|
|
@@ -344,11 +359,14 @@ const syncChannelConfig = (savedVars, mode = "all") => {
|
|
|
344
359
|
) {
|
|
345
360
|
console.log(`[alphaclaw] Removing channel: ${ch}`);
|
|
346
361
|
try {
|
|
347
|
-
execSync(
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
362
|
+
execSync(
|
|
363
|
+
`${getOpenclawCommandPrefix()} channels remove --channel ${ch} --delete`,
|
|
364
|
+
{
|
|
365
|
+
env,
|
|
366
|
+
timeout: 15000,
|
|
367
|
+
encoding: "utf8",
|
|
368
|
+
},
|
|
369
|
+
);
|
|
352
370
|
console.log(`[alphaclaw] Channel ${ch} removed`);
|
|
353
371
|
} catch (e) {
|
|
354
372
|
console.error(
|
|
@@ -90,7 +90,13 @@ const registerServerRoutes = ({
|
|
|
90
90
|
loginThrottle,
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
-
registerPageRoutes({
|
|
93
|
+
registerPageRoutes({
|
|
94
|
+
app,
|
|
95
|
+
requireAuth,
|
|
96
|
+
isGatewayRunning,
|
|
97
|
+
alphaclawVersionService,
|
|
98
|
+
openclawVersionService,
|
|
99
|
+
});
|
|
94
100
|
registerModelRoutes({
|
|
95
101
|
app,
|
|
96
102
|
shellCmd,
|
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const os = require("os");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
|
|
5
|
+
const { kRootDir } = require("./constants");
|
|
6
|
+
const {
|
|
7
|
+
compareVersionParts,
|
|
8
|
+
normalizeOpenclawVersion,
|
|
9
|
+
} = require("./helpers");
|
|
10
|
+
const {
|
|
11
|
+
computePackageFingerprint,
|
|
12
|
+
isPackageRootSymlink,
|
|
13
|
+
packLocalPackageForInstall,
|
|
14
|
+
resolvePackageRootFromEntryPath,
|
|
15
|
+
} = require("./package-fingerprint");
|
|
16
|
+
|
|
17
|
+
const getManagedOpenclawRuntimeDir = ({ rootDir = kRootDir } = {}) =>
|
|
18
|
+
path.join(rootDir, ".openclaw-runtime");
|
|
19
|
+
|
|
20
|
+
const getBundledOpenclawPackageRoot = ({
|
|
21
|
+
fsModule = fs,
|
|
22
|
+
resolveImpl = require.resolve,
|
|
23
|
+
} = {}) =>
|
|
24
|
+
resolvePackageRootFromEntryPath({
|
|
25
|
+
fsModule,
|
|
26
|
+
entryPath: resolveImpl("openclaw"),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const getManagedOpenclawPackageRoot = ({ runtimeDir } = {}) =>
|
|
30
|
+
path.join(
|
|
31
|
+
runtimeDir || getManagedOpenclawRuntimeDir(),
|
|
32
|
+
"node_modules",
|
|
33
|
+
"openclaw",
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const getManagedOpenclawBinDir = ({ runtimeDir } = {}) =>
|
|
37
|
+
path.join(
|
|
38
|
+
runtimeDir || getManagedOpenclawRuntimeDir(),
|
|
39
|
+
"node_modules",
|
|
40
|
+
".bin",
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
const getManagedOpenclawBinPath = ({ runtimeDir } = {}) =>
|
|
44
|
+
path.join(getManagedOpenclawBinDir({ runtimeDir }), "openclaw");
|
|
45
|
+
|
|
46
|
+
const getManagedOpenclawPackageJsonPath = ({ runtimeDir } = {}) =>
|
|
47
|
+
path.join(
|
|
48
|
+
getManagedOpenclawPackageRoot({ runtimeDir }),
|
|
49
|
+
"package.json",
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const ensureManagedOpenclawRuntimeProject = ({
|
|
53
|
+
fsModule = fs,
|
|
54
|
+
runtimeDir,
|
|
55
|
+
} = {}) => {
|
|
56
|
+
const resolvedRuntimeDir = runtimeDir || getManagedOpenclawRuntimeDir();
|
|
57
|
+
const packageJsonPath = path.join(resolvedRuntimeDir, "package.json");
|
|
58
|
+
fsModule.mkdirSync(resolvedRuntimeDir, { recursive: true });
|
|
59
|
+
if (!fsModule.existsSync(packageJsonPath)) {
|
|
60
|
+
fsModule.writeFileSync(
|
|
61
|
+
packageJsonPath,
|
|
62
|
+
JSON.stringify(
|
|
63
|
+
{
|
|
64
|
+
name: "alphaclaw-openclaw-runtime",
|
|
65
|
+
private: true,
|
|
66
|
+
},
|
|
67
|
+
null,
|
|
68
|
+
2,
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
runtimeDir: resolvedRuntimeDir,
|
|
74
|
+
packageJsonPath,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const readManagedOpenclawRuntimeVersion = ({
|
|
79
|
+
fsModule = fs,
|
|
80
|
+
runtimeDir,
|
|
81
|
+
} = {}) => {
|
|
82
|
+
try {
|
|
83
|
+
const pkg = JSON.parse(
|
|
84
|
+
fsModule.readFileSync(
|
|
85
|
+
getManagedOpenclawPackageJsonPath({ runtimeDir }),
|
|
86
|
+
"utf8",
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
return normalizeOpenclawVersion(pkg?.version || "");
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const readBundledOpenclawVersion = ({
|
|
96
|
+
fsModule = fs,
|
|
97
|
+
resolveImpl = require.resolve,
|
|
98
|
+
} = {}) => {
|
|
99
|
+
try {
|
|
100
|
+
const packageRoot = getBundledOpenclawPackageRoot({
|
|
101
|
+
fsModule,
|
|
102
|
+
resolveImpl,
|
|
103
|
+
});
|
|
104
|
+
if (!packageRoot) return null;
|
|
105
|
+
const pkg = JSON.parse(
|
|
106
|
+
fsModule.readFileSync(path.join(packageRoot, "package.json"), "utf8"),
|
|
107
|
+
);
|
|
108
|
+
return normalizeOpenclawVersion(pkg?.version || "");
|
|
109
|
+
} catch {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const shellQuote = (value) =>
|
|
115
|
+
`'${String(value || "").replace(/'/g, `'\"'\"'`)}'`;
|
|
116
|
+
|
|
117
|
+
const applyManagedOpenclawPatch = ({
|
|
118
|
+
execSyncImpl,
|
|
119
|
+
fsModule = fs,
|
|
120
|
+
logger = console,
|
|
121
|
+
runtimeDir,
|
|
122
|
+
version,
|
|
123
|
+
alphaclawRoot = path.resolve(__dirname, "..", ".."),
|
|
124
|
+
} = {}) => {
|
|
125
|
+
const normalizedVersion = normalizeOpenclawVersion(version);
|
|
126
|
+
if (!normalizedVersion) return false;
|
|
127
|
+
const patchesDir = path.join(alphaclawRoot, "patches");
|
|
128
|
+
const patchFileName = `openclaw+${normalizedVersion}.patch`;
|
|
129
|
+
const patchFilePath = path.join(patchesDir, patchFileName);
|
|
130
|
+
if (!fsModule.existsSync(patchFilePath)) {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const runtimePatchDirName = ".alphaclaw-patches";
|
|
135
|
+
const runtimePatchDirPath = path.join(runtimeDir, runtimePatchDirName);
|
|
136
|
+
try {
|
|
137
|
+
if (fsModule.existsSync(runtimePatchDirPath)) {
|
|
138
|
+
fsModule.rmSync(runtimePatchDirPath, { recursive: true, force: true });
|
|
139
|
+
}
|
|
140
|
+
} catch {}
|
|
141
|
+
fsModule.symlinkSync(patchesDir, runtimePatchDirPath);
|
|
142
|
+
|
|
143
|
+
const patchPackageMain = require.resolve("patch-package/dist/index.js", {
|
|
144
|
+
paths: [alphaclawRoot],
|
|
145
|
+
});
|
|
146
|
+
logger.log(
|
|
147
|
+
`[alphaclaw] Applying bundled OpenClaw patch for ${normalizedVersion}...`,
|
|
148
|
+
);
|
|
149
|
+
execSyncImpl(
|
|
150
|
+
`${shellQuote(process.execPath)} ${shellQuote(patchPackageMain)} --patch-dir ${shellQuote(runtimePatchDirName)}`,
|
|
151
|
+
{
|
|
152
|
+
cwd: runtimeDir,
|
|
153
|
+
stdio: "inherit",
|
|
154
|
+
timeout: 120000,
|
|
155
|
+
},
|
|
156
|
+
);
|
|
157
|
+
return true;
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const kDisableBundledPluginPostinstallEnv =
|
|
161
|
+
"OPENCLAW_DISABLE_BUNDLED_PLUGIN_POSTINSTALL";
|
|
162
|
+
const kBundledPluginPostinstallFailureMarker =
|
|
163
|
+
"[postinstall] could not install bundled plugin deps:";
|
|
164
|
+
|
|
165
|
+
const runManagedOpenclawBundledPluginPostinstall = ({
|
|
166
|
+
execSyncImpl,
|
|
167
|
+
fsModule = fs,
|
|
168
|
+
logger = console,
|
|
169
|
+
runtimeDir,
|
|
170
|
+
} = {}) => {
|
|
171
|
+
const packageRoot = getManagedOpenclawPackageRoot({ runtimeDir });
|
|
172
|
+
const postinstallScriptPath = path.join(
|
|
173
|
+
packageRoot,
|
|
174
|
+
"scripts",
|
|
175
|
+
"postinstall-bundled-plugins.mjs",
|
|
176
|
+
);
|
|
177
|
+
if (!fsModule.existsSync(postinstallScriptPath)) {
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
const env = { ...process.env };
|
|
181
|
+
delete env[kDisableBundledPluginPostinstallEnv];
|
|
182
|
+
const logDir = fsModule.mkdtempSync(
|
|
183
|
+
path.join(os.tmpdir(), "openclaw-bundled-postinstall-"),
|
|
184
|
+
);
|
|
185
|
+
const logPath = path.join(logDir, "postinstall.log");
|
|
186
|
+
let commandError = null;
|
|
187
|
+
let output = "";
|
|
188
|
+
let stdoutFd;
|
|
189
|
+
let stderrFd;
|
|
190
|
+
try {
|
|
191
|
+
stdoutFd = fsModule.openSync(logPath, "a");
|
|
192
|
+
stderrFd = fsModule.openSync(logPath, "a");
|
|
193
|
+
try {
|
|
194
|
+
execSyncImpl(
|
|
195
|
+
`${shellQuote(process.execPath)} ${shellQuote(postinstallScriptPath)}`,
|
|
196
|
+
{
|
|
197
|
+
cwd: packageRoot,
|
|
198
|
+
env,
|
|
199
|
+
stdio: ["ignore", stdoutFd, stderrFd],
|
|
200
|
+
timeout: 180000,
|
|
201
|
+
},
|
|
202
|
+
);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
commandError = error;
|
|
205
|
+
}
|
|
206
|
+
} finally {
|
|
207
|
+
if (typeof stdoutFd === "number") {
|
|
208
|
+
try {
|
|
209
|
+
fsModule.closeSync(stdoutFd);
|
|
210
|
+
} catch {}
|
|
211
|
+
}
|
|
212
|
+
if (typeof stderrFd === "number") {
|
|
213
|
+
try {
|
|
214
|
+
fsModule.closeSync(stderrFd);
|
|
215
|
+
} catch {}
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
output = String(fsModule.readFileSync(logPath, "utf8") || "").trim();
|
|
219
|
+
} catch {
|
|
220
|
+
output = "";
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
fsModule.rmSync(logDir, { recursive: true, force: true });
|
|
224
|
+
} catch {}
|
|
225
|
+
}
|
|
226
|
+
if (output) {
|
|
227
|
+
logger.log(output);
|
|
228
|
+
}
|
|
229
|
+
if (output.includes(kBundledPluginPostinstallFailureMarker)) {
|
|
230
|
+
throw new Error(output);
|
|
231
|
+
}
|
|
232
|
+
if (commandError) {
|
|
233
|
+
throw commandError;
|
|
234
|
+
}
|
|
235
|
+
return true;
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const installManagedOpenclawRuntime = ({
|
|
239
|
+
execSyncImpl,
|
|
240
|
+
fsModule = fs,
|
|
241
|
+
logger = console,
|
|
242
|
+
runtimeDir,
|
|
243
|
+
spec,
|
|
244
|
+
sourcePath,
|
|
245
|
+
alphaclawRoot,
|
|
246
|
+
} = {}) => {
|
|
247
|
+
const normalizedSourcePath = String(sourcePath || "").trim();
|
|
248
|
+
const normalizedSpec = normalizedSourcePath
|
|
249
|
+
? normalizedSourcePath
|
|
250
|
+
: String(spec || "").trim() || "openclaw@latest";
|
|
251
|
+
ensureManagedOpenclawRuntimeProject({
|
|
252
|
+
fsModule,
|
|
253
|
+
runtimeDir,
|
|
254
|
+
});
|
|
255
|
+
let packedSource = null;
|
|
256
|
+
try {
|
|
257
|
+
const installTarget = normalizedSourcePath
|
|
258
|
+
? (() => {
|
|
259
|
+
packedSource = packLocalPackageForInstall({
|
|
260
|
+
execSyncImpl,
|
|
261
|
+
fsModule,
|
|
262
|
+
packageRoot: normalizedSourcePath,
|
|
263
|
+
tempDirPrefix: "openclaw-runtime-pack-",
|
|
264
|
+
});
|
|
265
|
+
return packedSource.tarballPath;
|
|
266
|
+
})()
|
|
267
|
+
: normalizedSpec;
|
|
268
|
+
execSyncImpl(
|
|
269
|
+
`npm install ${shellQuote(installTarget)} --omit=dev --no-save --save=false --package-lock=false --prefer-online`,
|
|
270
|
+
{
|
|
271
|
+
cwd: runtimeDir,
|
|
272
|
+
env: {
|
|
273
|
+
...process.env,
|
|
274
|
+
[kDisableBundledPluginPostinstallEnv]: "1",
|
|
275
|
+
},
|
|
276
|
+
stdio: "inherit",
|
|
277
|
+
timeout: 180000,
|
|
278
|
+
},
|
|
279
|
+
);
|
|
280
|
+
} finally {
|
|
281
|
+
packedSource?.cleanup?.();
|
|
282
|
+
}
|
|
283
|
+
runManagedOpenclawBundledPluginPostinstall({
|
|
284
|
+
execSyncImpl,
|
|
285
|
+
fsModule,
|
|
286
|
+
logger,
|
|
287
|
+
runtimeDir,
|
|
288
|
+
});
|
|
289
|
+
const installedVersion = readManagedOpenclawRuntimeVersion({
|
|
290
|
+
fsModule,
|
|
291
|
+
runtimeDir,
|
|
292
|
+
});
|
|
293
|
+
applyManagedOpenclawPatch({
|
|
294
|
+
execSyncImpl,
|
|
295
|
+
fsModule,
|
|
296
|
+
logger,
|
|
297
|
+
runtimeDir,
|
|
298
|
+
version: installedVersion,
|
|
299
|
+
alphaclawRoot,
|
|
300
|
+
});
|
|
301
|
+
return {
|
|
302
|
+
spec: normalizedSpec,
|
|
303
|
+
version: installedVersion,
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const syncManagedOpenclawRuntimeWithBundled = ({
|
|
308
|
+
execSyncImpl,
|
|
309
|
+
fsModule = fs,
|
|
310
|
+
logger = console,
|
|
311
|
+
runtimeDir,
|
|
312
|
+
resolveImpl,
|
|
313
|
+
alphaclawRoot,
|
|
314
|
+
} = {}) => {
|
|
315
|
+
const bundledPackageRoot = getBundledOpenclawPackageRoot({
|
|
316
|
+
fsModule,
|
|
317
|
+
resolveImpl,
|
|
318
|
+
});
|
|
319
|
+
const bundledVersion = readBundledOpenclawVersion({
|
|
320
|
+
fsModule,
|
|
321
|
+
resolveImpl,
|
|
322
|
+
});
|
|
323
|
+
if (!bundledVersion) {
|
|
324
|
+
return {
|
|
325
|
+
checked: false,
|
|
326
|
+
synced: false,
|
|
327
|
+
bundledVersion: null,
|
|
328
|
+
runtimeVersion: readManagedOpenclawRuntimeVersion({ fsModule, runtimeDir }),
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const runtimeVersion = readManagedOpenclawRuntimeVersion({
|
|
333
|
+
fsModule,
|
|
334
|
+
runtimeDir,
|
|
335
|
+
});
|
|
336
|
+
const runtimePackageRoot = getManagedOpenclawPackageRoot({ runtimeDir });
|
|
337
|
+
const runtimePackageRootIsSymlink = isPackageRootSymlink({
|
|
338
|
+
fsModule,
|
|
339
|
+
packageRoot: runtimePackageRoot,
|
|
340
|
+
});
|
|
341
|
+
const bundledFingerprint = computePackageFingerprint({
|
|
342
|
+
fsModule,
|
|
343
|
+
packageRoot: bundledPackageRoot,
|
|
344
|
+
});
|
|
345
|
+
const runtimeFingerprint = computePackageFingerprint({
|
|
346
|
+
fsModule,
|
|
347
|
+
packageRoot: runtimePackageRoot,
|
|
348
|
+
packageJsonPath: getManagedOpenclawPackageJsonPath({ runtimeDir }),
|
|
349
|
+
});
|
|
350
|
+
if (runtimeVersion && compareVersionParts(runtimeVersion, bundledVersion) >= 0) {
|
|
351
|
+
if (
|
|
352
|
+
compareVersionParts(runtimeVersion, bundledVersion) > 0 ||
|
|
353
|
+
(!runtimePackageRootIsSymlink &&
|
|
354
|
+
(!bundledFingerprint || runtimeFingerprint === bundledFingerprint))
|
|
355
|
+
) {
|
|
356
|
+
return {
|
|
357
|
+
checked: true,
|
|
358
|
+
synced: false,
|
|
359
|
+
bundledVersion,
|
|
360
|
+
runtimeVersion,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
logger.log(
|
|
364
|
+
runtimePackageRootIsSymlink
|
|
365
|
+
? `[alphaclaw] Managed OpenClaw runtime ${runtimeVersion} is symlinked to the bundled package; refreshing runtime...`
|
|
366
|
+
: `[alphaclaw] Managed OpenClaw runtime ${runtimeVersion} differs from bundled ${bundledVersion}; refreshing runtime...`,
|
|
367
|
+
);
|
|
368
|
+
} else {
|
|
369
|
+
logger.log(
|
|
370
|
+
runtimeVersion
|
|
371
|
+
? `[alphaclaw] Managed OpenClaw runtime ${runtimeVersion} is older than bundled ${bundledVersion}; syncing runtime...`
|
|
372
|
+
: `[alphaclaw] Managed OpenClaw runtime missing; installing bundled OpenClaw ${bundledVersion}...`,
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
const installResult = installManagedOpenclawRuntime({
|
|
377
|
+
execSyncImpl,
|
|
378
|
+
fsModule,
|
|
379
|
+
logger,
|
|
380
|
+
runtimeDir,
|
|
381
|
+
sourcePath: bundledPackageRoot,
|
|
382
|
+
alphaclawRoot,
|
|
383
|
+
});
|
|
384
|
+
return {
|
|
385
|
+
checked: true,
|
|
386
|
+
synced: true,
|
|
387
|
+
bundledVersion,
|
|
388
|
+
runtimeVersion: installResult.version || bundledVersion,
|
|
389
|
+
};
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
const prependManagedOpenclawBinToPath = ({
|
|
393
|
+
env = process.env,
|
|
394
|
+
fsModule = fs,
|
|
395
|
+
logger = console,
|
|
396
|
+
runtimeDir,
|
|
397
|
+
} = {}) => {
|
|
398
|
+
const resolvedRuntimeDir = runtimeDir || getManagedOpenclawRuntimeDir();
|
|
399
|
+
const binDir = getManagedOpenclawBinDir({ runtimeDir: resolvedRuntimeDir });
|
|
400
|
+
const binPath = getManagedOpenclawBinPath({ runtimeDir: resolvedRuntimeDir });
|
|
401
|
+
if (!fsModule.existsSync(binPath)) {
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
const currentEntries = String(env.PATH || "")
|
|
405
|
+
.split(path.delimiter)
|
|
406
|
+
.filter(Boolean);
|
|
407
|
+
const nextEntries = [binDir, ...currentEntries.filter((entry) => entry !== binDir)];
|
|
408
|
+
env.PATH = nextEntries.join(path.delimiter);
|
|
409
|
+
logger.log(`[alphaclaw] Using managed OpenClaw runtime from ${resolvedRuntimeDir}`);
|
|
410
|
+
return true;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
module.exports = {
|
|
414
|
+
applyManagedOpenclawPatch,
|
|
415
|
+
ensureManagedOpenclawRuntimeProject,
|
|
416
|
+
getBundledOpenclawPackageRoot,
|
|
417
|
+
getManagedOpenclawBinDir,
|
|
418
|
+
getManagedOpenclawBinPath,
|
|
419
|
+
getManagedOpenclawPackageRoot,
|
|
420
|
+
getManagedOpenclawPackageJsonPath,
|
|
421
|
+
getManagedOpenclawRuntimeDir,
|
|
422
|
+
installManagedOpenclawRuntime,
|
|
423
|
+
prependManagedOpenclawBinToPath,
|
|
424
|
+
readBundledOpenclawVersion,
|
|
425
|
+
readManagedOpenclawRuntimeVersion,
|
|
426
|
+
runManagedOpenclawBundledPluginPostinstall,
|
|
427
|
+
syncManagedOpenclawRuntimeWithBundled,
|
|
428
|
+
};
|