@chrysb/alphaclaw 0.8.7-beta.4 → 0.8.7-beta.6
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/gateway.js +32 -14
- package/lib/server/openclaw-runtime.js +51 -66
- package/package.json +1 -1
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(
|
|
@@ -11,7 +11,6 @@ const {
|
|
|
11
11
|
isPackageRootSymlink,
|
|
12
12
|
packLocalPackageForInstall,
|
|
13
13
|
resolvePackageRootFromEntryPath,
|
|
14
|
-
seedRuntimeFromBundledInstall,
|
|
15
14
|
} = require("./package-fingerprint");
|
|
16
15
|
|
|
17
16
|
const getManagedOpenclawRuntimeDir = ({ rootDir = kRootDir } = {}) =>
|
|
@@ -157,6 +156,49 @@ const applyManagedOpenclawPatch = ({
|
|
|
157
156
|
return true;
|
|
158
157
|
};
|
|
159
158
|
|
|
159
|
+
const kDisableBundledPluginPostinstallEnv =
|
|
160
|
+
"OPENCLAW_DISABLE_BUNDLED_PLUGIN_POSTINSTALL";
|
|
161
|
+
const kBundledPluginPostinstallFailureMarker =
|
|
162
|
+
"[postinstall] could not install bundled plugin deps:";
|
|
163
|
+
|
|
164
|
+
const runManagedOpenclawBundledPluginPostinstall = ({
|
|
165
|
+
execSyncImpl,
|
|
166
|
+
fsModule = fs,
|
|
167
|
+
logger = console,
|
|
168
|
+
runtimeDir,
|
|
169
|
+
} = {}) => {
|
|
170
|
+
const packageRoot = getManagedOpenclawPackageRoot({ runtimeDir });
|
|
171
|
+
const postinstallScriptPath = path.join(
|
|
172
|
+
packageRoot,
|
|
173
|
+
"scripts",
|
|
174
|
+
"postinstall-bundled-plugins.mjs",
|
|
175
|
+
);
|
|
176
|
+
if (!fsModule.existsSync(postinstallScriptPath)) {
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
const env = { ...process.env };
|
|
180
|
+
delete env[kDisableBundledPluginPostinstallEnv];
|
|
181
|
+
const output = String(
|
|
182
|
+
execSyncImpl(
|
|
183
|
+
`${shellQuote(process.execPath)} ${shellQuote(postinstallScriptPath)} 2>&1`,
|
|
184
|
+
{
|
|
185
|
+
cwd: packageRoot,
|
|
186
|
+
env,
|
|
187
|
+
encoding: "utf8",
|
|
188
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
189
|
+
timeout: 180000,
|
|
190
|
+
},
|
|
191
|
+
) || "",
|
|
192
|
+
).trim();
|
|
193
|
+
if (output) {
|
|
194
|
+
logger.log(output);
|
|
195
|
+
}
|
|
196
|
+
if (output.includes(kBundledPluginPostinstallFailureMarker)) {
|
|
197
|
+
throw new Error(output);
|
|
198
|
+
}
|
|
199
|
+
return true;
|
|
200
|
+
};
|
|
201
|
+
|
|
160
202
|
const installManagedOpenclawRuntime = ({
|
|
161
203
|
execSyncImpl,
|
|
162
204
|
fsModule = fs,
|
|
@@ -191,6 +233,10 @@ const installManagedOpenclawRuntime = ({
|
|
|
191
233
|
`npm install ${shellQuote(installTarget)} --omit=dev --no-save --save=false --package-lock=false --prefer-online`,
|
|
192
234
|
{
|
|
193
235
|
cwd: runtimeDir,
|
|
236
|
+
env: {
|
|
237
|
+
...process.env,
|
|
238
|
+
[kDisableBundledPluginPostinstallEnv]: "1",
|
|
239
|
+
},
|
|
194
240
|
stdio: "inherit",
|
|
195
241
|
timeout: 180000,
|
|
196
242
|
},
|
|
@@ -198,47 +244,12 @@ const installManagedOpenclawRuntime = ({
|
|
|
198
244
|
} finally {
|
|
199
245
|
packedSource?.cleanup?.();
|
|
200
246
|
}
|
|
201
|
-
|
|
202
|
-
fsModule,
|
|
203
|
-
runtimeDir,
|
|
204
|
-
});
|
|
205
|
-
applyManagedOpenclawPatch({
|
|
247
|
+
runManagedOpenclawBundledPluginPostinstall({
|
|
206
248
|
execSyncImpl,
|
|
207
249
|
fsModule,
|
|
208
250
|
logger,
|
|
209
251
|
runtimeDir,
|
|
210
|
-
version: installedVersion,
|
|
211
|
-
alphaclawRoot,
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
spec: normalizedSpec,
|
|
215
|
-
version: installedVersion,
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
const seedManagedOpenclawRuntimeFromBundledInstall = ({
|
|
220
|
-
execSyncImpl,
|
|
221
|
-
fsModule = fs,
|
|
222
|
-
logger = console,
|
|
223
|
-
runtimeDir,
|
|
224
|
-
bundledPackageRoot,
|
|
225
|
-
alphaclawRoot,
|
|
226
|
-
} = {}) => {
|
|
227
|
-
const seedResult = seedRuntimeFromBundledInstall({
|
|
228
|
-
fsModule,
|
|
229
|
-
packageRoot: bundledPackageRoot,
|
|
230
|
-
runtimeDir,
|
|
231
|
-
runtimePackageJson: {
|
|
232
|
-
name: "alphaclaw-openclaw-runtime",
|
|
233
|
-
private: true,
|
|
234
|
-
},
|
|
235
252
|
});
|
|
236
|
-
if (!seedResult.seeded) {
|
|
237
|
-
return {
|
|
238
|
-
seeded: false,
|
|
239
|
-
version: null,
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
253
|
const installedVersion = readManagedOpenclawRuntimeVersion({
|
|
243
254
|
fsModule,
|
|
244
255
|
runtimeDir,
|
|
@@ -251,9 +262,8 @@ const seedManagedOpenclawRuntimeFromBundledInstall = ({
|
|
|
251
262
|
version: installedVersion,
|
|
252
263
|
alphaclawRoot,
|
|
253
264
|
});
|
|
254
|
-
logger.log("[alphaclaw] Seeded managed OpenClaw runtime from bundled node_modules");
|
|
255
265
|
return {
|
|
256
|
-
|
|
266
|
+
spec: normalizedSpec,
|
|
257
267
|
version: installedVersion,
|
|
258
268
|
};
|
|
259
269
|
};
|
|
@@ -323,35 +333,10 @@ const syncManagedOpenclawRuntimeWithBundled = ({
|
|
|
323
333
|
logger.log(
|
|
324
334
|
runtimeVersion
|
|
325
335
|
? `[alphaclaw] Managed OpenClaw runtime ${runtimeVersion} is older than bundled ${bundledVersion}; syncing runtime...`
|
|
326
|
-
: `[alphaclaw] Managed OpenClaw runtime missing;
|
|
336
|
+
: `[alphaclaw] Managed OpenClaw runtime missing; installing bundled OpenClaw ${bundledVersion}...`,
|
|
327
337
|
);
|
|
328
338
|
}
|
|
329
339
|
|
|
330
|
-
if (!runtimeVersion) {
|
|
331
|
-
try {
|
|
332
|
-
const seedResult = seedManagedOpenclawRuntimeFromBundledInstall({
|
|
333
|
-
execSyncImpl,
|
|
334
|
-
fsModule,
|
|
335
|
-
logger,
|
|
336
|
-
runtimeDir,
|
|
337
|
-
bundledPackageRoot,
|
|
338
|
-
alphaclawRoot,
|
|
339
|
-
});
|
|
340
|
-
if (seedResult.seeded) {
|
|
341
|
-
return {
|
|
342
|
-
checked: true,
|
|
343
|
-
synced: true,
|
|
344
|
-
bundledVersion,
|
|
345
|
-
runtimeVersion: seedResult.version || bundledVersion,
|
|
346
|
-
};
|
|
347
|
-
}
|
|
348
|
-
} catch (error) {
|
|
349
|
-
logger.log(
|
|
350
|
-
`[alphaclaw] Could not seed managed OpenClaw runtime from bundled node_modules: ${error.message}`,
|
|
351
|
-
);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
340
|
const installResult = installManagedOpenclawRuntime({
|
|
356
341
|
execSyncImpl,
|
|
357
342
|
fsModule,
|
|
@@ -402,6 +387,6 @@ module.exports = {
|
|
|
402
387
|
prependManagedOpenclawBinToPath,
|
|
403
388
|
readBundledOpenclawVersion,
|
|
404
389
|
readManagedOpenclawRuntimeVersion,
|
|
405
|
-
|
|
390
|
+
runManagedOpenclawBundledPluginPostinstall,
|
|
406
391
|
syncManagedOpenclawRuntimeWithBundled,
|
|
407
392
|
};
|