mnemospark 2026.4.10 → 2026.4.12

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
@@ -3216,7 +3216,7 @@ import {
3216
3216
  import { createReadStream as createReadStream2, createWriteStream as createWriteStream2, statfsSync } from "fs";
3217
3217
  import { lstat, mkdir as mkdir6, readFile as readFile4, readdir as readdir2, rm, stat as stat2, writeFile as writeFile4 } from "fs/promises";
3218
3218
  import { homedir as homedir7, tmpdir } from "os";
3219
- import { basename as basename2, dirname as dirname6, join as join10, resolve as resolve2 } from "path";
3219
+ import { basename as basename2, dirname as dirname7, join as join11, resolve as resolve2 } from "path";
3220
3220
  import { Readable } from "stream";
3221
3221
  import { finished } from "stream/promises";
3222
3222
  import { privateKeyToAccount as privateKeyToAccount5 } from "viem/accounts";
@@ -4670,12 +4670,41 @@ async function ensureOpenClawRenewalPrerequisites(options = {}) {
4670
4670
  }
4671
4671
  }
4672
4672
 
4673
+ // src/mnemospark-cli-path.ts
4674
+ import { existsSync as existsSync2 } from "fs";
4675
+ import { dirname as dirname6, join as join10 } from "path";
4676
+ import { fileURLToPath as fileURLToPath2 } from "url";
4677
+ var DEFAULT_MODULE_URL = import.meta.url;
4678
+ function resolveMnemosparkCliPath(options = {}) {
4679
+ const fromEnv = process.env.MNEMOSPARK_CLI_PATH?.trim();
4680
+ if (fromEnv) {
4681
+ assertCliExists(fromEnv, options.requireExists);
4682
+ return fromEnv;
4683
+ }
4684
+ const moduleDir = dirname6(fileURLToPath2(options.moduleUrl ?? DEFAULT_MODULE_URL));
4685
+ const candidates = [join10(moduleDir, "cli.js"), join10(moduleDir, "cli.ts")];
4686
+ const resolved = candidates.find((candidate) => existsSync2(candidate)) ?? candidates[0];
4687
+ assertCliExists(resolved, options.requireExists);
4688
+ return resolved;
4689
+ }
4690
+ function assertCliExists(cliPath, requireExists) {
4691
+ if (requireExists === false) {
4692
+ return;
4693
+ }
4694
+ if (existsSync2(cliPath)) {
4695
+ return;
4696
+ }
4697
+ throw new Error(
4698
+ `mnemospark CLI not found at ${cliPath}. Install the plugin or set MNEMOSPARK_CLI_PATH to the installed dist/cli.js.`
4699
+ );
4700
+ }
4701
+
4673
4702
  // src/cloud-command.ts
4674
4703
  var SUPPORTED_BACKUP_PLATFORMS = /* @__PURE__ */ new Set(["darwin", "linux"]);
4675
- var BACKUP_DIR_SUBPATH = join10(".openclaw", "mnemospark", "backup");
4676
- var DEFAULT_BACKUP_DIR = join10(homedir7(), BACKUP_DIR_SUBPATH);
4677
- var BLOCKRUN_WALLET_KEY_SUBPATH = join10(".openclaw", "blockrun", "wallet.key");
4678
- var MNEMOSPARK_WALLET_KEY_SUBPATH = join10(".openclaw", "mnemospark", "wallet", "wallet.key");
4704
+ var BACKUP_DIR_SUBPATH = join11(".openclaw", "mnemospark", "backup");
4705
+ var DEFAULT_BACKUP_DIR = join11(homedir7(), BACKUP_DIR_SUBPATH);
4706
+ var BLOCKRUN_WALLET_KEY_SUBPATH = join11(".openclaw", "blockrun", "wallet.key");
4707
+ var MNEMOSPARK_WALLET_KEY_SUBPATH = join11(".openclaw", "mnemospark", "wallet", "wallet.key");
4679
4708
  var INLINE_UPLOAD_MAX_BYTES = 45e5;
4680
4709
  var NODE_FS_MAX_READFILE_BYTES = 2147483648;
4681
4710
  var PAYMENT_CRON_SCHEDULE = "0 0 1 * *";
@@ -4696,7 +4725,7 @@ function expandTilde(path) {
4696
4725
  return homedir7();
4697
4726
  }
4698
4727
  if (trimmed.startsWith("~/") || trimmed.startsWith("~\\")) {
4699
- return join10(homedir7(), trimmed.slice(2));
4728
+ return join11(homedir7(), trimmed.slice(2));
4700
4729
  }
4701
4730
  return path;
4702
4731
  }
@@ -5288,7 +5317,7 @@ async function calculateInputSizeBytes(targetPath) {
5288
5317
  let total = 0;
5289
5318
  const entries = await readdir2(targetPath, { withFileTypes: true });
5290
5319
  for (const entry of entries) {
5291
- total += await calculateInputSizeBytes(join10(targetPath, entry.name));
5320
+ total += await calculateInputSizeBytes(join11(targetPath, entry.name));
5292
5321
  }
5293
5322
  return total;
5294
5323
  }
@@ -5300,7 +5329,7 @@ function getAvailableDiskBytes(tmpDir, options) {
5300
5329
  return stats.bavail * stats.bsize;
5301
5330
  }
5302
5331
  async function runTarGzip(archivePath, sourcePath) {
5303
- const sourceDir = dirname6(sourcePath);
5332
+ const sourceDir = dirname7(sourcePath);
5304
5333
  const sourceName = basename2(sourcePath);
5305
5334
  await new Promise((resolvePromise, rejectPromise) => {
5306
5335
  let stderr = "";
@@ -5334,7 +5363,7 @@ async function resolveLocalUploadArchivePath(backupDir, objectId, friendlyName)
5334
5363
  if (friendlyName?.trim()) {
5335
5364
  try {
5336
5365
  const sanitized = sanitizeFriendlyNameForLocalBasename(friendlyName);
5337
- const candidate = join10(backupDir, sanitized);
5366
+ const candidate = join11(backupDir, sanitized);
5338
5367
  try {
5339
5368
  const st = await stat2(candidate);
5340
5369
  if (st.isFile()) {
@@ -5345,7 +5374,7 @@ async function resolveLocalUploadArchivePath(backupDir, objectId, friendlyName)
5345
5374
  } catch {
5346
5375
  }
5347
5376
  }
5348
- const legacyPath = join10(backupDir, objectId);
5377
+ const legacyPath = join11(backupDir, objectId);
5349
5378
  try {
5350
5379
  const legacyStats = await stat2(legacyPath);
5351
5380
  if (!legacyStats.isFile()) {
@@ -5400,7 +5429,7 @@ async function buildBackupObject(targetPathArg, options = {}) {
5400
5429
  }
5401
5430
  const objectId = createObjectId(options);
5402
5431
  const archiveBaseSegment = options.archiveBasename?.trim() || objectId;
5403
- const archivePath = join10(tmpDir, archiveBaseSegment);
5432
+ const archivePath = join11(tmpDir, archiveBaseSegment);
5404
5433
  if (options.archiveBasename?.trim()) {
5405
5434
  try {
5406
5435
  const existing = await stat2(archivePath);
@@ -5539,8 +5568,8 @@ function buildStoragePaymentRenewalArgs(job) {
5539
5568
  function buildStoragePaymentCronCommand(job) {
5540
5569
  return `/mnemospark cloud ${buildStoragePaymentRenewalArgs(job)}`;
5541
5570
  }
5542
- function buildOpenClawRenewalAgentMessage(openClawHome, renewalArgs) {
5543
- const cliPath = join10(openClawHome, ".openclaw/extensions/mnemospark/dist/cli.js");
5571
+ function buildOpenClawRenewalAgentMessage(renewalArgs) {
5572
+ const cliPath = resolveMnemosparkCliPath();
5544
5573
  const nodeBin = getRenewalNodeBinary();
5545
5574
  return `Command: ${nodeBin} ${cliPath} cloud ${renewalArgs}`;
5546
5575
  }
@@ -5595,7 +5624,7 @@ async function appendStoragePaymentCronJob(cronJob, adapter, payloadMessage) {
5595
5624
  async function removeStoragePaymentCronJob(cronId, adapter) {
5596
5625
  return adapter.remove(cronId);
5597
5626
  }
5598
- async function createStoragePaymentCronJob(upload, storagePrice, openClawCronAdapter, openClawHomeDir, nowDateFn = () => /* @__PURE__ */ new Date()) {
5627
+ async function createStoragePaymentCronJob(upload, storagePrice, openClawCronAdapter, nowDateFn = () => /* @__PURE__ */ new Date()) {
5599
5628
  const renewalFields = {
5600
5629
  walletAddress: upload.addr,
5601
5630
  objectId: upload.object_id,
@@ -5618,7 +5647,7 @@ async function createStoragePaymentCronJob(upload, storagePrice, openClawCronAda
5618
5647
  bucketName: upload.bucket_name,
5619
5648
  location: upload.location
5620
5649
  };
5621
- const payloadMessage = buildOpenClawRenewalAgentMessage(openClawHomeDir, renewalArgs);
5650
+ const payloadMessage = buildOpenClawRenewalAgentMessage(renewalArgs);
5622
5651
  const created = await appendStoragePaymentCronJob(cronJob, openClawCronAdapter, payloadMessage);
5623
5652
  if (created.jobId?.trim()) {
5624
5653
  cronJob.cronId = created.jobId.trim();
@@ -5642,8 +5671,8 @@ async function resolveWalletPrivateKey(homeDir) {
5642
5671
  return envKey;
5643
5672
  }
5644
5673
  const baseHome = homeDir ?? homedir7();
5645
- const primaryWalletPath = join10(baseHome, MNEMOSPARK_WALLET_KEY_SUBPATH);
5646
- const fallbackWalletPath = join10(baseHome, BLOCKRUN_WALLET_KEY_SUBPATH);
5674
+ const primaryWalletPath = join11(baseHome, MNEMOSPARK_WALLET_KEY_SUBPATH);
5675
+ const fallbackWalletPath = join11(baseHome, BLOCKRUN_WALLET_KEY_SUBPATH);
5647
5676
  const fromPrimary = await readWalletKeyIfPresent(primaryWalletPath);
5648
5677
  if (fromPrimary) {
5649
5678
  return fromPrimary;
@@ -5707,7 +5736,7 @@ async function encryptPlaintextFileToAesGcmPath(plaintextPath, dek, outPath, ran
5707
5736
  }
5708
5737
  async function loadOrCreateKek(walletAddress, homeDir) {
5709
5738
  const keyPath = resolveWalletKekPath(walletAddress, homeDir);
5710
- await mkdir6(dirname6(keyPath), { recursive: true });
5739
+ await mkdir6(dirname7(keyPath), { recursive: true });
5711
5740
  try {
5712
5741
  const existing = await readFile4(keyPath);
5713
5742
  return { kek: parseStoredAes256Key(existing), keyPath };
@@ -5729,7 +5758,7 @@ async function prepareUploadPayload(archivePath, walletAddress, homeDir) {
5729
5758
  const dek = randomBytesNode(32);
5730
5759
  const wrappedDek = encryptAesGcm(dek, kek);
5731
5760
  if (archiveStat.size >= NODE_FS_MAX_READFILE_BYTES) {
5732
- const encryptedTempPath = join10(tmpdir(), `mnemospark-upload-${randomUUID4()}.enc`);
5761
+ const encryptedTempPath = join11(tmpdir(), `mnemospark-upload-${randomUUID4()}.enc`);
5733
5762
  try {
5734
5763
  await encryptPlaintextFileToAesGcmPath(archivePath, dek, encryptedTempPath);
5735
5764
  const encStat = await stat2(encryptedTempPath);
@@ -7428,7 +7457,6 @@ operation-id: ${operationId}`,
7428
7457
  finalizedUploadResponse,
7429
7458
  cronStoragePrice,
7430
7459
  openClawCronAdapter,
7431
- mnemosparkHomeDir ?? homedir7(),
7432
7460
  nowDateFn
7433
7461
  );
7434
7462
  await datastore.upsertObject({
@@ -8177,10 +8205,10 @@ async function buildWalletExportResponse() {
8177
8205
 
8178
8206
  // src/cli.ts
8179
8207
  import { spawn as spawn3 } from "child_process";
8180
- import { dirname as dirname7, join as join11 } from "path";
8181
- import { fileURLToPath as fileURLToPath2 } from "url";
8208
+ import { dirname as dirname8, join as join12 } from "path";
8209
+ import { fileURLToPath as fileURLToPath3 } from "url";
8182
8210
  import { mkdir as mkdir7, readFile as readFile5, writeFile as writeFile5 } from "fs/promises";
8183
- import { existsSync as existsSync2 } from "fs";
8211
+ import { existsSync as existsSync3 } from "fs";
8184
8212
  import { homedir as homedir8 } from "os";
8185
8213
  function isHexPrivateKey(value) {
8186
8214
  return typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value.trim());
@@ -8288,21 +8316,21 @@ function parseArgs(args) {
8288
8316
  }
8289
8317
  return result;
8290
8318
  }
8291
- var __filename2 = fileURLToPath2(import.meta.url);
8292
- var __dirname2 = dirname7(__filename2);
8293
- var PACKAGE_ROOT = dirname7(__dirname2);
8319
+ var __filename2 = fileURLToPath3(import.meta.url);
8320
+ var __dirname2 = dirname8(__filename2);
8321
+ var PACKAGE_ROOT = dirname8(__dirname2);
8294
8322
  async function ensureDir(path) {
8295
8323
  await mkdir7(path, { recursive: true });
8296
8324
  }
8297
8325
  async function deployExtensionFiles() {
8298
- const scriptsSource = join11(PACKAGE_ROOT, "scripts");
8299
- if (!existsSync2(scriptsSource)) return;
8300
- const mnemoScriptsDir = join11(homedir8(), ".openclaw", "mnemospark", "scripts");
8326
+ const scriptsSource = join12(PACKAGE_ROOT, "scripts");
8327
+ if (!existsSync3(scriptsSource)) return;
8328
+ const mnemoScriptsDir = join12(homedir8(), ".openclaw", "mnemospark", "scripts");
8301
8329
  await ensureDir(mnemoScriptsDir);
8302
- const uninstallSrc = join11(scriptsSource, "uninstall.sh");
8303
- if (existsSync2(uninstallSrc)) {
8330
+ const uninstallSrc = join12(scriptsSource, "uninstall.sh");
8331
+ if (existsSync3(uninstallSrc)) {
8304
8332
  const content = await readFile5(uninstallSrc);
8305
- await writeFile5(join11(mnemoScriptsDir, "uninstall.sh"), content, { mode: 493 });
8333
+ await writeFile5(join12(mnemoScriptsDir, "uninstall.sh"), content, { mode: 493 });
8306
8334
  }
8307
8335
  }
8308
8336
  function isOpenClawAvailable() {
@@ -8316,8 +8344,8 @@ function isOpenClawAvailable() {
8316
8344
  });
8317
8345
  }
8318
8346
  function getOpenClawConfigPath() {
8319
- const stateDir = process.env.OPENCLAW_STATE_DIR ?? join11(homedir8(), ".openclaw");
8320
- return join11(stateDir, "openclaw.json");
8347
+ const stateDir = process.env.OPENCLAW_STATE_DIR ?? join12(homedir8(), ".openclaw");
8348
+ return join12(stateDir, "openclaw.json");
8321
8349
  }
8322
8350
  async function ensureMnemosparkInPluginsAllow() {
8323
8351
  const configPath = getOpenClawConfigPath();
@@ -8387,7 +8415,7 @@ async function readLegacyWalletIfPresent() {
8387
8415
  }
8388
8416
  }
8389
8417
  async function writeMnemosparkWallet(key) {
8390
- const dir = dirname7(WALLET_FILE);
8418
+ const dir = dirname8(WALLET_FILE);
8391
8419
  await ensureDir(dir);
8392
8420
  await writeFile5(WALLET_FILE, `${key}
8393
8421
  `, { mode: 384 });