@opentrust/cli 7.3.34 → 7.3.35

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.
@@ -170,9 +170,12 @@ async function runDaemon(config) {
170
170
  for (const cmd of cmds) {
171
171
  log(`Executing command: ${cmd.type} (${cmd.id})`);
172
172
  await client.ackCommand(cmd.id, "running").catch(() => { });
173
+ const progressFn = async (output) => {
174
+ await client.ackCommand(cmd.id, "running", { output }).catch(() => { });
175
+ };
173
176
  let result;
174
177
  try {
175
- result = executeHostCommand(cmd);
178
+ result = await executeHostCommand(cmd, progressFn);
176
179
  }
177
180
  catch (err) {
178
181
  log(`Command ${cmd.id} threw unexpectedly: ${err.message ?? err}`);
@@ -13,9 +13,9 @@ const SCAFFOLD_PKG = {
13
13
  status: "opentrust status",
14
14
  },
15
15
  dependencies: {
16
- "@opentrust/core": "^7.3.34",
17
- "@opentrust/gateway": "^7.3.34",
18
- "@opentrust/dashboard": "^7.3.34",
16
+ "@opentrust/core": "^7.3.35",
17
+ "@opentrust/gateway": "^7.3.35",
18
+ "@opentrust/dashboard": "^7.3.35",
19
19
  },
20
20
  };
21
21
  const ENV_TEMPLATE = `# OpenTrust Configuration
@@ -4,5 +4,6 @@ export interface CommandResult {
4
4
  output?: string;
5
5
  error?: string;
6
6
  }
7
+ export type ProgressFn = (output: string) => Promise<void>;
7
8
  export declare function setCommandLogger(fn: (msg: string) => void): void;
8
- export declare function executeHostCommand(cmd: HostCommand): CommandResult;
9
+ export declare function executeHostCommand(cmd: HostCommand, progress?: ProgressFn): Promise<CommandResult>;
@@ -7,8 +7,12 @@ import { paths, projectRoot, projectMode } from "./paths.js";
7
7
  import { loadConfig } from "./dashboard-client.js";
8
8
  let _logger = null;
9
9
  export function setCommandLogger(fn) { _logger = fn; }
10
- function cmdLog(msg) { if (_logger)
11
- _logger(msg); }
10
+ let _cmdOutput = [];
11
+ function cmdLog(msg) {
12
+ if (_logger)
13
+ _logger(msg);
14
+ _cmdOutput.push(msg);
15
+ }
12
16
  const SERVICE_KEYS = Object.keys(SERVICES);
13
17
  const OPENCLAW_HOME = process.env.OPENCLAW_HOME || path.join(os.homedir(), ".openclaw");
14
18
  function clawExecOpts(timeoutMs = 120_000) {
@@ -21,7 +25,8 @@ function clawExecOpts(timeoutMs = 120_000) {
21
25
  env: { ...restEnv, HOME: os.homedir() },
22
26
  };
23
27
  }
24
- export function executeHostCommand(cmd) {
28
+ export async function executeHostCommand(cmd, progress) {
29
+ _cmdOutput = [];
25
30
  const payload = cmd.payload ?? {};
26
31
  switch (cmd.type) {
27
32
  case "start_service":
@@ -53,7 +58,7 @@ export function executeHostCommand(cmd) {
53
58
  case "upgrade_guards":
54
59
  return handleUpgradeGuards(payload);
55
60
  case "install_openclaw":
56
- return handleInstallOpenclaw(payload);
61
+ return handleInstallOpenclaw(payload, progress);
57
62
  default:
58
63
  return { success: false, error: `Unknown command type: ${cmd.type}` };
59
64
  }
@@ -306,23 +311,35 @@ function findOpenclawBin() {
306
311
  }
307
312
  return "openclaw";
308
313
  }
309
- function handleInstallOpenclaw(payload) {
314
+ async function handleInstallOpenclaw(payload, progress) {
310
315
  const config = payload.config;
311
316
  if (!config)
312
317
  return { success: false, error: "Missing config in payload. Configure OpenClaw template in Settings first." };
313
- const results = [];
318
+ const sendProgress = async () => {
319
+ if (progress)
320
+ await progress(_cmdOutput.join("\n")).catch(() => { });
321
+ };
314
322
  // Override Guards plugin URLs with the CLI's own connection URL
315
323
  const cliConfig = loadConfig();
316
324
  if (cliConfig?.dashboardUrl) {
317
- const guardEntry = config?.plugins?.entries?.["opentrust-guard"];
318
- if (guardEntry?.config) {
319
- guardEntry.config.dashboardUrl = cliConfig.dashboardUrl;
320
- guardEntry.config.coreUrl = cliConfig.dashboardUrl.replace(/:53667/, ":53666");
321
- cmdLog(` Guards URLs → dashboardUrl=${guardEntry.config.dashboardUrl}, coreUrl=${guardEntry.config.coreUrl}`);
322
- }
325
+ if (!config.plugins)
326
+ config.plugins = {};
327
+ if (!config.plugins.entries)
328
+ config.plugins.entries = {};
329
+ if (!config.plugins.entries["opentrust-guard"])
330
+ config.plugins.entries["opentrust-guard"] = { enabled: true, config: {} };
331
+ if (!config.plugins.entries["opentrust-guard"].config)
332
+ config.plugins.entries["opentrust-guard"].config = {};
333
+ const gc = config.plugins.entries["opentrust-guard"].config;
334
+ gc.dashboardUrl = cliConfig.dashboardUrl;
335
+ gc.coreUrl = cliConfig.dashboardUrl.replace(/:(\d+)$/, (_, port) => {
336
+ return `:${Number(port) === 53667 ? 53666 : Number(port) - 1}`;
337
+ });
338
+ cmdLog(`Guards URLs → dashboardUrl=${gc.dashboardUrl}, coreUrl=${gc.coreUrl}`);
323
339
  }
324
340
  // Step 1: Install OpenClaw via curl
325
- cmdLog(" [1/3] Installing OpenClaw (curl -fsSL https://openclaw.ai/install.sh | bash)...");
341
+ cmdLog("[1/3] Installing OpenClaw (curl -fsSL https://openclaw.ai/install.sh | bash)...");
342
+ await sendProgress();
326
343
  try {
327
344
  execSync("curl -fsSL https://openclaw.ai/install.sh | bash", {
328
345
  encoding: "utf-8",
@@ -332,40 +349,39 @@ function handleInstallOpenclaw(payload) {
332
349
  env: { ...process.env, HOME: os.homedir() },
333
350
  shell: "/bin/bash",
334
351
  });
335
- results.push("Install script: completed");
336
- cmdLog(" [1/3] OpenClaw install script completed");
352
+ cmdLog("[1/3] OpenClaw install script completed");
337
353
  }
338
354
  catch (err) {
339
355
  const code = err.status;
340
356
  if (code === 0 || code === null) {
341
- results.push("Install script: completed (non-zero might be ok)");
342
- cmdLog(" [1/3] OpenClaw install script finished (exit code ignored)");
357
+ cmdLog("[1/3] OpenClaw install script finished (exit code ignored)");
343
358
  }
344
359
  else {
345
- const msg = `Install script exited with code ${code}`;
346
- cmdLog(` [1/3] ${msg}`);
347
- results.push(msg);
348
- // Don't return failure — the binary may already exist or the error is non-fatal
360
+ cmdLog(`[1/3] Install script exited with code ${code}`);
349
361
  }
350
362
  }
363
+ await sendProgress();
351
364
  // Step 2: Write openclaw.json config
352
- cmdLog(" [2/3] Writing ~/.openclaw/openclaw.json ...");
365
+ cmdLog("[2/3] Writing ~/.openclaw/openclaw.json ...");
366
+ await sendProgress();
353
367
  try {
354
368
  const clawHome = path.join(os.homedir(), ".openclaw");
355
369
  fs.mkdirSync(clawHome, { recursive: true });
356
370
  const configFile = path.join(clawHome, "openclaw.json");
357
371
  fs.writeFileSync(configFile, JSON.stringify(config, null, 2) + "\n", "utf-8");
358
- results.push(`Config written to ${configFile}`);
359
- cmdLog(` [2/3] Config written to ${configFile}`);
372
+ cmdLog(`[2/3] Config written to ${configFile}`);
360
373
  }
361
374
  catch (err) {
362
375
  const msg = `Failed to write config: ${(err.message || String(err)).slice(0, 500)}`;
363
- cmdLog(` [2/3] ${msg}`);
364
- return { success: false, error: msg };
376
+ cmdLog(`[2/3] ${msg}`);
377
+ await sendProgress();
378
+ return { success: false, output: _cmdOutput.join("\n"), error: msg };
365
379
  }
366
- // Step 3: Auto-install Guards plugin — expand PATH to find freshly-installed openclaw
380
+ await sendProgress();
381
+ // Step 3: Auto-install Guards plugin
367
382
  const clawBin = findOpenclawBin();
368
- cmdLog(` [3/3] Installing Guards plugin (${clawBin} plugins install @opentrust/guards)...`);
383
+ cmdLog(`[3/3] Installing Guards plugin (${clawBin} plugins install @opentrust/guards)...`);
384
+ await sendProgress();
369
385
  try {
370
386
  const extraPaths = [
371
387
  path.join(os.homedir(), ".local", "bin"),
@@ -373,29 +389,26 @@ function handleInstallOpenclaw(payload) {
373
389
  "/usr/local/bin",
374
390
  ].join(":");
375
391
  const { OPENCLAW_HOME: _, ...restEnv } = process.env;
376
- const output = execSync(`${clawBin} plugins install @opentrust/guards`, {
392
+ execSync(`${clawBin} plugins install @opentrust/guards`, {
377
393
  encoding: "utf-8",
378
394
  timeout: 180_000,
379
395
  stdio: ["pipe", "pipe", "pipe"],
380
396
  cwd: os.homedir(),
381
397
  env: { ...restEnv, HOME: os.homedir(), PATH: `${extraPaths}:${process.env.PATH ?? ""}` },
382
398
  });
383
- results.push(`Guards plugin: installed`);
384
- cmdLog(` [3/3] Guards plugin installed successfully`);
399
+ cmdLog("[3/3] Guards plugin installed successfully");
385
400
  }
386
401
  catch (err) {
387
402
  const stderr = err.stderr?.toString() || "";
388
403
  const stdout = err.stdout?.toString() || "";
389
404
  if (isOnlyWarnings(stderr) || isOnlyWarnings(stdout + stderr)) {
390
- results.push("Guards plugin: installed (with warnings)");
391
- cmdLog(" [3/3] Guards plugin installed (with warnings)");
405
+ cmdLog("[3/3] Guards plugin installed (with warnings)");
392
406
  }
393
407
  else {
394
408
  const errMsg = (stderr || err.message || String(err)).slice(0, 300);
395
- results.push(`Guards plugin: install failed ${errMsg}`);
396
- cmdLog(` [3/3] Guards plugin install failed: ${errMsg}`);
409
+ cmdLog(`[3/3] Guards plugin install failed: ${errMsg}`);
397
410
  }
398
411
  }
399
- cmdLog(" install_openclaw complete");
400
- return { success: true, output: results.join("\n") };
412
+ cmdLog("install_openclaw complete");
413
+ return { success: true, output: _cmdOutput.join("\n") };
401
414
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentrust/cli",
3
- "version": "7.3.34",
3
+ "version": "7.3.35",
4
4
  "description": "CLI tool to manage OpenTrust AI Agent Runtime Security Platform — setup, start, stop, status, logs",
5
5
  "type": "module",
6
6
  "bin": {