@opentrust/cli 7.3.35 → 7.3.37
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/dist/commands/init.js +3 -3
- package/dist/lib/command-handler.js +126 -36
- package/package.json +1 -1
package/dist/commands/init.js
CHANGED
|
@@ -13,9 +13,9 @@ const SCAFFOLD_PKG = {
|
|
|
13
13
|
status: "opentrust status",
|
|
14
14
|
},
|
|
15
15
|
dependencies: {
|
|
16
|
-
"@opentrust/core": "^7.3.
|
|
17
|
-
"@opentrust/gateway": "^7.3.
|
|
18
|
-
"@opentrust/dashboard": "^7.3.
|
|
16
|
+
"@opentrust/core": "^7.3.37",
|
|
17
|
+
"@opentrust/gateway": "^7.3.37",
|
|
18
|
+
"@opentrust/dashboard": "^7.3.37",
|
|
19
19
|
},
|
|
20
20
|
};
|
|
21
21
|
const ENV_TEMPLATE = `# OpenTrust Configuration
|
|
@@ -282,13 +282,13 @@ function runClawPluginCmd(cmd, timeoutMs = 180_000) {
|
|
|
282
282
|
}
|
|
283
283
|
function handleInstallGuards(payload) {
|
|
284
284
|
const version = payload.version || "latest";
|
|
285
|
-
const spec = version === "latest" ? "@opentrust/
|
|
285
|
+
const spec = version === "latest" ? "@opentrust/opentrust-guard" : `@opentrust/opentrust-guard@${version}`;
|
|
286
286
|
return runClawPluginCmd(`openclaw plugins install ${spec}`);
|
|
287
287
|
}
|
|
288
288
|
function handleUpgradeGuards(payload) {
|
|
289
289
|
const version = payload.version || "latest";
|
|
290
|
-
const spec = version === "latest" ? "@opentrust/
|
|
291
|
-
const uninstall = runClawPluginCmd("openclaw plugins uninstall @opentrust/
|
|
290
|
+
const spec = version === "latest" ? "@opentrust/opentrust-guard" : `@opentrust/opentrust-guard@${version}`;
|
|
291
|
+
const uninstall = runClawPluginCmd("openclaw plugins uninstall @opentrust/opentrust-guard --force", 60_000);
|
|
292
292
|
if (!uninstall.success)
|
|
293
293
|
return uninstall;
|
|
294
294
|
const install = runClawPluginCmd(`openclaw plugins install ${spec}`);
|
|
@@ -305,10 +305,24 @@ function findOpenclawBin() {
|
|
|
305
305
|
"/usr/local/bin/openclaw",
|
|
306
306
|
path.join(os.homedir(), ".openclaw", "bin", "openclaw"),
|
|
307
307
|
];
|
|
308
|
+
// Try npm global bin path
|
|
309
|
+
try {
|
|
310
|
+
const npmPrefix = execSync("npm config get prefix", { encoding: "utf-8", timeout: 5_000 }).trim();
|
|
311
|
+
if (npmPrefix)
|
|
312
|
+
candidates.push(path.join(npmPrefix, "bin", "openclaw"));
|
|
313
|
+
}
|
|
314
|
+
catch { }
|
|
308
315
|
for (const p of candidates) {
|
|
309
316
|
if (fs.existsSync(p))
|
|
310
317
|
return p;
|
|
311
318
|
}
|
|
319
|
+
// Last resort: try `which openclaw`
|
|
320
|
+
try {
|
|
321
|
+
const w = execSync("which openclaw", { encoding: "utf-8", timeout: 5_000 }).trim();
|
|
322
|
+
if (w)
|
|
323
|
+
return w;
|
|
324
|
+
}
|
|
325
|
+
catch { }
|
|
312
326
|
return "openclaw";
|
|
313
327
|
}
|
|
314
328
|
async function handleInstallOpenclaw(payload, progress) {
|
|
@@ -337,76 +351,152 @@ async function handleInstallOpenclaw(payload, progress) {
|
|
|
337
351
|
});
|
|
338
352
|
cmdLog(`Guards URLs → dashboardUrl=${gc.dashboardUrl}, coreUrl=${gc.coreUrl}`);
|
|
339
353
|
}
|
|
340
|
-
//
|
|
341
|
-
|
|
354
|
+
// Ensure plugins.allow includes opentrust-guard
|
|
355
|
+
if (!config.plugins)
|
|
356
|
+
config.plugins = {};
|
|
357
|
+
if (!Array.isArray(config.plugins.allow))
|
|
358
|
+
config.plugins.allow = [];
|
|
359
|
+
if (!config.plugins.allow.includes("opentrust-guard")) {
|
|
360
|
+
config.plugins.allow.push("opentrust-guard");
|
|
361
|
+
}
|
|
362
|
+
const clawHome = path.join(os.homedir(), ".openclaw");
|
|
363
|
+
const configFile = path.join(clawHome, "openclaw.json");
|
|
364
|
+
// Helper: resolve openclaw binary with extra PATH entries
|
|
365
|
+
const resolveExtraPaths = () => {
|
|
366
|
+
const extra = [
|
|
367
|
+
path.join(os.homedir(), ".local", "bin"),
|
|
368
|
+
path.join(os.homedir(), ".openclaw", "bin"),
|
|
369
|
+
"/usr/local/bin",
|
|
370
|
+
];
|
|
371
|
+
try {
|
|
372
|
+
const npmPrefix = execSync("npm config get prefix", { encoding: "utf-8", timeout: 5_000 }).trim();
|
|
373
|
+
if (npmPrefix)
|
|
374
|
+
extra.push(path.join(npmPrefix, "bin"));
|
|
375
|
+
}
|
|
376
|
+
catch { }
|
|
377
|
+
return extra;
|
|
378
|
+
};
|
|
379
|
+
const makeEnv = (extraPaths) => {
|
|
380
|
+
const { OPENCLAW_HOME: _, ...rest } = process.env;
|
|
381
|
+
return { ...rest, HOME: os.homedir(), PATH: `${extraPaths.join(":")}:${process.env.PATH ?? ""}` };
|
|
382
|
+
};
|
|
383
|
+
// Step 1: Write initial config (so install script detects it and skips interactive setup)
|
|
384
|
+
cmdLog("[1/5] Writing ~/.openclaw/openclaw.json ...");
|
|
385
|
+
await sendProgress();
|
|
386
|
+
try {
|
|
387
|
+
fs.mkdirSync(clawHome, { recursive: true });
|
|
388
|
+
fs.writeFileSync(configFile, JSON.stringify(config, null, 2) + "\n", "utf-8");
|
|
389
|
+
cmdLog(`[1/5] Config written to ${configFile}`);
|
|
390
|
+
}
|
|
391
|
+
catch (err) {
|
|
392
|
+
const msg = `Failed to write config: ${(err.message || String(err)).slice(0, 500)}`;
|
|
393
|
+
cmdLog(`[1/5] ${msg}`);
|
|
394
|
+
await sendProgress();
|
|
395
|
+
return { success: false, output: _cmdOutput.join("\n"), error: msg };
|
|
396
|
+
}
|
|
397
|
+
await sendProgress();
|
|
398
|
+
// Step 2: Install OpenClaw via curl (non-interactive)
|
|
399
|
+
cmdLog("[2/5] Installing OpenClaw (curl -fsSL https://openclaw.ai/install.sh | bash)...");
|
|
342
400
|
await sendProgress();
|
|
343
401
|
try {
|
|
344
402
|
execSync("curl -fsSL https://openclaw.ai/install.sh | bash", {
|
|
345
403
|
encoding: "utf-8",
|
|
346
|
-
timeout:
|
|
347
|
-
stdio: ["
|
|
404
|
+
timeout: 300_000,
|
|
405
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
348
406
|
cwd: os.homedir(),
|
|
349
|
-
env: {
|
|
407
|
+
env: {
|
|
408
|
+
...process.env,
|
|
409
|
+
HOME: os.homedir(),
|
|
410
|
+
CI: "1",
|
|
411
|
+
NONINTERACTIVE: "1",
|
|
412
|
+
OPENCLAW_ACCEPT_TOS: "1",
|
|
413
|
+
},
|
|
350
414
|
shell: "/bin/bash",
|
|
351
415
|
});
|
|
352
|
-
cmdLog("[
|
|
416
|
+
cmdLog("[2/5] OpenClaw install script completed");
|
|
353
417
|
}
|
|
354
418
|
catch (err) {
|
|
355
419
|
const code = err.status;
|
|
356
420
|
if (code === 0 || code === null) {
|
|
357
|
-
cmdLog("[
|
|
421
|
+
cmdLog("[2/5] OpenClaw install script finished (exit code ignored)");
|
|
358
422
|
}
|
|
359
423
|
else {
|
|
360
|
-
cmdLog(`[
|
|
424
|
+
cmdLog(`[2/5] Install script exited with code ${code}`);
|
|
361
425
|
}
|
|
362
426
|
}
|
|
363
427
|
await sendProgress();
|
|
364
|
-
// Step
|
|
365
|
-
|
|
428
|
+
// Step 3: Non-interactive onboarding + daemon install
|
|
429
|
+
const clawBin = findOpenclawBin();
|
|
430
|
+
cmdLog(`[3/5] Running onboarding (${clawBin} onboard --non-interactive --install-daemon)...`);
|
|
366
431
|
await sendProgress();
|
|
367
432
|
try {
|
|
368
|
-
const
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
433
|
+
const extraPaths = resolveExtraPaths();
|
|
434
|
+
execSync(`${clawBin} onboard --non-interactive --install-daemon`, {
|
|
435
|
+
encoding: "utf-8",
|
|
436
|
+
timeout: 120_000,
|
|
437
|
+
stdio: ["ignore", "inherit", "inherit"],
|
|
438
|
+
cwd: os.homedir(),
|
|
439
|
+
env: {
|
|
440
|
+
...makeEnv(extraPaths),
|
|
441
|
+
CI: "1",
|
|
442
|
+
NONINTERACTIVE: "1",
|
|
443
|
+
OPENCLAW_ACCEPT_TOS: "1",
|
|
444
|
+
OPENCLAW_ACCEPT_RISK: "1",
|
|
445
|
+
},
|
|
446
|
+
});
|
|
447
|
+
cmdLog("[3/5] Onboarding completed");
|
|
373
448
|
}
|
|
374
449
|
catch (err) {
|
|
375
|
-
const
|
|
376
|
-
cmdLog(`[
|
|
377
|
-
await sendProgress();
|
|
378
|
-
return { success: false, output: _cmdOutput.join("\n"), error: msg };
|
|
450
|
+
const code = err.status;
|
|
451
|
+
cmdLog(`[3/5] Onboarding exited with code ${code ?? "unknown"} (continuing)`);
|
|
379
452
|
}
|
|
380
453
|
await sendProgress();
|
|
381
|
-
// Step
|
|
382
|
-
|
|
383
|
-
cmdLog(`[3/3] Installing Guards plugin (${clawBin} plugins install @opentrust/guards)...`);
|
|
454
|
+
// Step 4: Re-write config (onboarding may have overwritten our template)
|
|
455
|
+
cmdLog("[4/5] Re-writing config (ensuring our template + plugins.allow)...");
|
|
384
456
|
await sendProgress();
|
|
385
457
|
try {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
"
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
458
|
+
// Merge: read current config from disk (onboarding may have added fields), overlay our template
|
|
459
|
+
let merged = config;
|
|
460
|
+
try {
|
|
461
|
+
const diskConfig = JSON.parse(fs.readFileSync(configFile, "utf-8"));
|
|
462
|
+
merged = { ...diskConfig, ...config, plugins: { ...diskConfig.plugins, ...config.plugins } };
|
|
463
|
+
// Re-ensure plugins.allow
|
|
464
|
+
if (!Array.isArray(merged.plugins.allow))
|
|
465
|
+
merged.plugins.allow = [];
|
|
466
|
+
if (!merged.plugins.allow.includes("opentrust-guard"))
|
|
467
|
+
merged.plugins.allow.push("opentrust-guard");
|
|
468
|
+
}
|
|
469
|
+
catch { }
|
|
470
|
+
fs.writeFileSync(configFile, JSON.stringify(merged, null, 2) + "\n", "utf-8");
|
|
471
|
+
cmdLog("[4/5] Config written with plugins.allow: " + JSON.stringify(merged.plugins.allow));
|
|
472
|
+
}
|
|
473
|
+
catch (err) {
|
|
474
|
+
cmdLog(`[4/5] Config re-write failed: ${(err.message || String(err)).slice(0, 200)}`);
|
|
475
|
+
}
|
|
476
|
+
await sendProgress();
|
|
477
|
+
// Step 5: Auto-install Guards plugin
|
|
478
|
+
cmdLog(`[5/5] Installing Guards plugin (${clawBin} plugins install @opentrust/opentrust-guard)...`);
|
|
479
|
+
await sendProgress();
|
|
480
|
+
try {
|
|
481
|
+
const extraPaths = resolveExtraPaths();
|
|
482
|
+
execSync(`${clawBin} plugins install @opentrust/opentrust-guard`, {
|
|
393
483
|
encoding: "utf-8",
|
|
394
484
|
timeout: 180_000,
|
|
395
485
|
stdio: ["pipe", "pipe", "pipe"],
|
|
396
486
|
cwd: os.homedir(),
|
|
397
|
-
env:
|
|
487
|
+
env: makeEnv(extraPaths),
|
|
398
488
|
});
|
|
399
|
-
cmdLog("[
|
|
489
|
+
cmdLog("[5/5] Guards plugin installed successfully");
|
|
400
490
|
}
|
|
401
491
|
catch (err) {
|
|
402
492
|
const stderr = err.stderr?.toString() || "";
|
|
403
493
|
const stdout = err.stdout?.toString() || "";
|
|
404
494
|
if (isOnlyWarnings(stderr) || isOnlyWarnings(stdout + stderr)) {
|
|
405
|
-
cmdLog("[
|
|
495
|
+
cmdLog("[5/5] Guards plugin installed (with warnings)");
|
|
406
496
|
}
|
|
407
497
|
else {
|
|
408
498
|
const errMsg = (stderr || err.message || String(err)).slice(0, 300);
|
|
409
|
-
cmdLog(`[
|
|
499
|
+
cmdLog(`[5/5] Guards plugin install failed: ${errMsg}`);
|
|
410
500
|
}
|
|
411
501
|
}
|
|
412
502
|
cmdLog("install_openclaw complete");
|