mnemospark 2026.4.12 → 2026.4.13

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/cli.js CHANGED
@@ -4450,6 +4450,8 @@ var opStatusSchema = {
4450
4450
  // src/openclaw-cli.ts
4451
4451
  import { spawn } from "child_process";
4452
4452
  import { join as join8 } from "path";
4453
+ var ANSI_ESCAPE_RE = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
4454
+ var BOX_DRAWING_RE = /[\u2500-\u257F]/g;
4453
4455
  async function runOpenClawCli(args, homeDir) {
4454
4456
  return await new Promise((resolvePromise, rejectPromise) => {
4455
4457
  let stdout = "";
@@ -4492,16 +4494,59 @@ function parseOpenClawCliJson(stdout, commandLabel) {
4492
4494
  throw new Error(`openclaw ${commandLabel} returned invalid JSON output`);
4493
4495
  }
4494
4496
  }
4495
- async function resolveOpenClawConfigFilePath(homeDir) {
4496
- const { stdout } = await runOpenClawCli(["config", "file"], homeDir);
4497
- const trimmed = stdout.trim();
4498
- if (trimmed.startsWith("~/")) {
4499
- return join8(homeDir, trimmed.slice(2));
4497
+ function stripCliDecorations(line) {
4498
+ return line.replace(ANSI_ESCAPE_RE, "").replace(BOX_DRAWING_RE, "").trim();
4499
+ }
4500
+ function expandHomePath(homeDir, line) {
4501
+ if (line.startsWith("~/")) {
4502
+ return join8(homeDir, line.slice(2));
4500
4503
  }
4501
- if (trimmed.startsWith("~\\")) {
4502
- return join8(homeDir, trimmed.slice(2));
4504
+ if (line.startsWith("~\\")) {
4505
+ return join8(homeDir, line.slice(2));
4503
4506
  }
4504
- return trimmed;
4507
+ return line;
4508
+ }
4509
+ function looksLikeOpenClawConfigPath(line) {
4510
+ if (!line || line.includes("\n")) {
4511
+ return false;
4512
+ }
4513
+ if (line.endsWith("openclaw.json")) {
4514
+ return true;
4515
+ }
4516
+ if (line.startsWith("~/") || line.startsWith("~\\")) {
4517
+ return true;
4518
+ }
4519
+ if (line.startsWith("/")) {
4520
+ return true;
4521
+ }
4522
+ return /^[A-Za-z]:\\/.test(line);
4523
+ }
4524
+ function parseOpenClawConfigFileStdout(stdout, homeDir) {
4525
+ const lines = stdout.split(/\r?\n/);
4526
+ for (let i = lines.length - 1; i >= 0; i--) {
4527
+ const line = stripCliDecorations(lines[i] ?? "");
4528
+ if (!line || !looksLikeOpenClawConfigPath(line)) {
4529
+ continue;
4530
+ }
4531
+ return expandHomePath(homeDir, line);
4532
+ }
4533
+ return null;
4534
+ }
4535
+ function getOpenClawConfigPath(homeDir, env = process.env) {
4536
+ const stateDir = env.OPENCLAW_STATE_DIR ?? join8(homeDir, ".openclaw");
4537
+ return join8(stateDir, "openclaw.json");
4538
+ }
4539
+ async function resolveOpenClawConfigFilePath(homeDir) {
4540
+ const fallback = getOpenClawConfigPath(homeDir);
4541
+ try {
4542
+ const { stdout } = await runOpenClawCli(["config", "file"], homeDir);
4543
+ const parsed = parseOpenClawConfigFileStdout(stdout, homeDir);
4544
+ if (parsed) {
4545
+ return parsed;
4546
+ }
4547
+ } catch {
4548
+ }
4549
+ return fallback;
4505
4550
  }
4506
4551
 
4507
4552
  // src/openclaw-renewal-runbook.ts
@@ -4509,6 +4554,15 @@ import { mkdir as mkdir5, readFile as readFile3, rename as rename2, writeFile as
4509
4554
  import { homedir as homedir6 } from "os";
4510
4555
  import { dirname as dirname5, join as join9 } from "path";
4511
4556
  import { randomUUID as randomUUID3 } from "crypto";
4557
+ var MAX_CONFIG_PATH_LENGTH = 4096;
4558
+ function assertValidConfigPath(configPath) {
4559
+ if (configPath.includes("\n") || configPath.includes("\r")) {
4560
+ throw new Error("openclaw config path must not contain newlines");
4561
+ }
4562
+ if (configPath.length > MAX_CONFIG_PATH_LENGTH) {
4563
+ throw new Error("openclaw config path is too long");
4564
+ }
4565
+ }
4512
4566
  var DEFAULT_RENEWAL_AGENT_ID = "mnemospark-renewal";
4513
4567
  var DEFAULT_MNEMOSPARK_AGENT_ID = "mnemospark";
4514
4568
  var RENEWAL_NODE_ALLOWLIST_ID = "node-usr-bin-node";
@@ -4617,6 +4671,7 @@ async function ensureOpenClawRenewalPrerequisites(options = {}) {
4617
4671
  const desiredPlugin = runbookDedicatedAgentEntry(pluginAgentId);
4618
4672
  const nodeBinary = getRenewalNodeBinary();
4619
4673
  const configPath = await resolveOpenClawConfigFilePath(homeDir);
4674
+ assertValidConfigPath(configPath);
4620
4675
  let configRaw = "{}";
4621
4676
  try {
4622
4677
  configRaw = await readFile3(configPath, "utf-8");
@@ -8343,12 +8398,8 @@ function isOpenClawAvailable() {
8343
8398
  child.on("close", (code) => resolve3(code === 0));
8344
8399
  });
8345
8400
  }
8346
- function getOpenClawConfigPath() {
8347
- const stateDir = process.env.OPENCLAW_STATE_DIR ?? join12(homedir8(), ".openclaw");
8348
- return join12(stateDir, "openclaw.json");
8349
- }
8350
8401
  async function ensureMnemosparkInPluginsAllow() {
8351
- const configPath = getOpenClawConfigPath();
8402
+ const configPath = getOpenClawConfigPath(homedir8());
8352
8403
  try {
8353
8404
  const raw = await readFile5(configPath, "utf-8");
8354
8405
  const config = JSON.parse(raw);