@remnic/cli 10.0.169 → 10.0.171

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.
Files changed (2) hide show
  1. package/dist/index.js +130 -3
  2. package/package.json +32 -32
package/dist/index.js CHANGED
@@ -8769,11 +8769,17 @@ async function daemonFetch(baseUrl, relativePath, token, timeoutMs, init) {
8769
8769
  try {
8770
8770
  const headers = { accept: "application/json" };
8771
8771
  if (token) headers.authorization = `Bearer ${token}`;
8772
- return await fetch(url, {
8772
+ const response = await fetch(url, {
8773
8773
  ...init,
8774
8774
  headers: { ...headers, ...init?.headers },
8775
8775
  signal: controller.signal
8776
8776
  });
8777
+ const text = await response.text();
8778
+ return new Response(text === "" ? null : text, {
8779
+ status: response.status,
8780
+ statusText: response.statusText,
8781
+ headers: response.headers
8782
+ });
8777
8783
  } finally {
8778
8784
  clearTimeout(timeoutId);
8779
8785
  }
@@ -9502,6 +9508,77 @@ Or add it to a project:
9502
9508
  );
9503
9509
  }
9504
9510
 
9511
+ // src/zip-entries.ts
9512
+ import { crc32, inflateRawSync } from "zlib";
9513
+ var EOCD = 101010256;
9514
+ var CENTRAL = 33639248;
9515
+ var LOCAL = 67324752;
9516
+ var DEFAULT_ZIP_LIMITS = { maxEntryBytes: 512 * 1024 * 1024, maxTotalBytes: 1024 * 1024 * 1024 };
9517
+ function readZipEntries(bytes, want, limits = DEFAULT_ZIP_LIMITS) {
9518
+ const buf = Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength);
9519
+ let end = -1;
9520
+ for (let i = buf.length - 22; i >= Math.max(0, buf.length - 22 - 65535); i--) {
9521
+ if (buf.readUInt32LE(i) === EOCD && i + 22 + buf.readUInt16LE(i + 20) === buf.length) {
9522
+ end = i;
9523
+ break;
9524
+ }
9525
+ }
9526
+ if (end < 0) throw new Error("not a ZIP archive: no end-of-central-directory record");
9527
+ const count = buf.readUInt16LE(end + 10);
9528
+ const dirSize = buf.readUInt32LE(end + 12);
9529
+ let pos = buf.readUInt32LE(end + 16);
9530
+ if (count === 65535 || dirSize === 4294967295 || pos === 4294967295) {
9531
+ throw new Error("ZIP64 archives are not supported; unzip the export and pass the JSON file");
9532
+ }
9533
+ const out = /* @__PURE__ */ new Map();
9534
+ let total = 0;
9535
+ for (let i = 0; i < count; i++) {
9536
+ if (pos + 46 > buf.length || buf.readUInt32LE(pos) !== CENTRAL) throw new Error("corrupt ZIP central directory");
9537
+ const flags = buf.readUInt16LE(pos + 8);
9538
+ const method = buf.readUInt16LE(pos + 10);
9539
+ const crc = buf.readUInt32LE(pos + 16);
9540
+ const packed = buf.readUInt32LE(pos + 20);
9541
+ const size = buf.readUInt32LE(pos + 24);
9542
+ const nameLen = buf.readUInt16LE(pos + 28);
9543
+ const extraLen = buf.readUInt16LE(pos + 30);
9544
+ const commentLen = buf.readUInt16LE(pos + 32);
9545
+ const local = buf.readUInt32LE(pos + 42);
9546
+ const name = buf.toString("utf8", pos + 46, pos + 46 + nameLen);
9547
+ pos += 46 + nameLen + extraLen + commentLen;
9548
+ if (!want(name)) continue;
9549
+ if (flags & 1) throw new Error(`ZIP entry '${name}' is encrypted`);
9550
+ if (packed === 4294967295 || size === 4294967295 || local === 4294967295) {
9551
+ throw new Error(`ZIP entry '${name}' needs ZIP64, which is not supported`);
9552
+ }
9553
+ if (size > limits.maxEntryBytes) {
9554
+ throw new Error(`ZIP entry '${name}' declares ${size} bytes, which exceeds the per-entry limit of ${limits.maxEntryBytes}`);
9555
+ }
9556
+ total += size;
9557
+ if (total > limits.maxTotalBytes) {
9558
+ throw new Error(`ZIP entries reach ${total} bytes at '${name}', which exceeds the total limit of ${limits.maxTotalBytes}`);
9559
+ }
9560
+ if (local + 30 > buf.length || buf.readUInt32LE(local) !== LOCAL) throw new Error(`corrupt ZIP local header for '${name}'`);
9561
+ const start = local + 30 + buf.readUInt16LE(local + 26) + buf.readUInt16LE(local + 28);
9562
+ if (start + packed > buf.length) throw new Error(`ZIP entry '${name}' is truncated`);
9563
+ const body = buf.subarray(start, start + packed);
9564
+ let data;
9565
+ if (method === 0) data = Buffer.from(body);
9566
+ else if (method === 8) {
9567
+ try {
9568
+ data = inflateRawSync(body, { maxOutputLength: Math.max(size, 1) });
9569
+ } catch (err) {
9570
+ if (err instanceof Error && "code" in err && err.code === "ERR_BUFFER_TOO_LARGE") {
9571
+ throw new Error(`ZIP entry '${name}' inflates past its declared size`);
9572
+ }
9573
+ throw err;
9574
+ }
9575
+ } else throw new Error(`ZIP entry '${name}' uses compression method ${method}; only stored and deflate are supported`);
9576
+ if (data.length !== size || crc32(data) >>> 0 !== crc) throw new Error(`ZIP entry '${name}' failed its CRC check`);
9577
+ out.set(name, data);
9578
+ }
9579
+ return out;
9580
+ }
9581
+
9505
9582
  // src/import-dispatch.ts
9506
9583
  var IMPORT_USAGE = `remnic import \u2014 Bring memory from ChatGPT, Claude, Gemini, Mem0, Supermemory, or OKF
9507
9584
 
@@ -9602,14 +9679,17 @@ function rejectLeftoverImportArgs(args, command) {
9602
9679
  }
9603
9680
  }
9604
9681
  async function runImportCommand(args, io) {
9605
- if (args.file && (isZipFilePath(args.file) || /\.(tgz|tar\.gz)$/i.test(args.file))) {
9682
+ const chatgptZip = args.adapter === "chatgpt" && !!args.file && isZipFilePath(args.file);
9683
+ if (args.file && !chatgptZip && (isZipFilePath(args.file) || /\.(tgz|tar\.gz)$/i.test(args.file))) {
9606
9684
  throw new Error(
9607
9685
  `unpack first: archive imports are not supported ('${args.file}'). Extract the archive, then pass the directory.`
9608
9686
  );
9609
9687
  }
9610
9688
  const adapter = await io.loadAdapter(args.adapter);
9611
9689
  let input;
9612
- if (args.adapter === "okf") {
9690
+ if (chatgptZip) {
9691
+ input = await readChatGPTExportZip(args.file, io);
9692
+ } else if (args.adapter === "okf") {
9613
9693
  if (!args.file) {
9614
9694
  throw new Error("OKF import requires a directory path (remnic import okf <dir>)");
9615
9695
  }
@@ -9664,6 +9744,52 @@ async function runImportCommand(args, io) {
9664
9744
  }
9665
9745
  return result;
9666
9746
  }
9747
+ var CHATGPT_ZIP_KEYS = /* @__PURE__ */ new Map([
9748
+ ["memory.json", "memory"],
9749
+ ["memories.json", "memories"],
9750
+ ["user.json", "user"],
9751
+ ["conversations.json", "conversations"]
9752
+ ]);
9753
+ async function readChatGPTExportZip(file, io) {
9754
+ let bytes;
9755
+ try {
9756
+ bytes = await (io.readFileBytes ?? ((p) => fs30.promises.readFile(p)))(file);
9757
+ } catch (err) {
9758
+ throw new Error(`Failed to read --file '${file}': ${err instanceof Error ? err.message : String(err)}`);
9759
+ }
9760
+ const base = (name) => name.slice(name.lastIndexOf("/") + 1).toLowerCase();
9761
+ const entries = readZipEntries(bytes, (name) => CHATGPT_ZIP_KEYS.has(base(name)));
9762
+ const bundle = {};
9763
+ for (const [name, data] of entries) {
9764
+ const key = CHATGPT_ZIP_KEYS.get(base(name));
9765
+ if (key === void 0) continue;
9766
+ let value;
9767
+ try {
9768
+ value = JSON.parse(data.toString("utf8"));
9769
+ } catch (err) {
9770
+ throw new Error(`'${name}' in '${file}' is not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
9771
+ }
9772
+ mergeChatGPTZipSection(bundle, key, value);
9773
+ }
9774
+ if (Object.keys(bundle).length === 0) {
9775
+ throw new Error(`'${file}' holds none of ${[...CHATGPT_ZIP_KEYS.keys()].join(", ")}; is it a ChatGPT data export?`);
9776
+ }
9777
+ return bundle;
9778
+ }
9779
+ function mergeChatGPTZipSection(bundle, key, value) {
9780
+ if (key === "user" || !(value instanceof Object) || Array.isArray(value)) {
9781
+ bundle[key] = value;
9782
+ return;
9783
+ }
9784
+ let merged = false;
9785
+ for (const section of CHATGPT_ZIP_KEYS.values()) {
9786
+ if (section in value) {
9787
+ bundle[section] = value[section];
9788
+ merged = true;
9789
+ }
9790
+ }
9791
+ if (!merged) bundle[key] = value;
9792
+ }
9667
9793
  function isZipFilePath(filePath) {
9668
9794
  return pathExtension(filePath) === ".zip";
9669
9795
  }
@@ -9808,6 +9934,7 @@ async function cmdImport(rest, targetFactory, disposeTarget, ioOverrides = {}) {
9808
9934
  let materializePromise;
9809
9935
  const io = {
9810
9936
  readFile: ioOverrides.readFile ?? (async (p) => fs30.promises.readFile(p, "utf-8")),
9937
+ readFileBytes: ioOverrides.readFileBytes ?? (async (p) => fs30.promises.readFile(p)),
9811
9938
  loadAdapter: ioOverrides.loadAdapter ?? (async (name) => (await loadImporterModule(name)).adapter),
9812
9939
  runImporter: ioOverrides.runImporter ?? runImporter,
9813
9940
  getWriteTarget: async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/cli",
3
- "version": "10.0.169",
3
+ "version": "10.0.171",
4
4
  "description": "CLI for Remnic memory — init, query, doctor, daemon management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,26 +26,26 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "yaml": "^2.4.2",
29
- "@remnic/plugin-pi": "^10.0.169",
30
- "@remnic/core": "^10.0.169",
31
- "@remnic/server": "^10.0.169"
29
+ "@remnic/plugin-pi": "^10.0.171",
30
+ "@remnic/server": "^10.0.171",
31
+ "@remnic/core": "^10.0.171"
32
32
  },
33
33
  "peerDependencies": {
34
- "@remnic/bench": "^10.0.169",
35
- "@remnic/plugin-openclaw": "^10.0.169",
36
- "@remnic/export-weclone": "^10.0.169",
37
- "@remnic/import-weclone": "^10.0.169",
38
- "@remnic/import-chatgpt": "^10.0.169",
39
- "@remnic/import-claude": "^10.0.169",
40
- "@remnic/import-gemini": "^10.0.169",
41
- "@remnic/import-lossless-claw": "^10.0.169",
42
- "@remnic/import-mem0": "^10.0.169",
43
- "@remnic/import-supermemory": "^10.0.169",
44
- "@remnic/import-okf": "^10.0.169",
45
- "@remnic/connector-limitless": "^10.0.169",
46
- "@remnic/connector-bee": "^10.0.169",
47
- "@remnic/connector-omi": "^10.0.169",
48
- "@remnic/capture-audio": "^10.0.169"
34
+ "@remnic/bench": "^10.0.171",
35
+ "@remnic/plugin-openclaw": "^10.0.171",
36
+ "@remnic/export-weclone": "^10.0.171",
37
+ "@remnic/import-weclone": "^10.0.171",
38
+ "@remnic/import-chatgpt": "^10.0.171",
39
+ "@remnic/import-claude": "^10.0.171",
40
+ "@remnic/import-gemini": "^10.0.171",
41
+ "@remnic/import-lossless-claw": "^10.0.171",
42
+ "@remnic/import-mem0": "^10.0.171",
43
+ "@remnic/import-supermemory": "^10.0.171",
44
+ "@remnic/import-okf": "^10.0.171",
45
+ "@remnic/connector-limitless": "^10.0.171",
46
+ "@remnic/connector-bee": "^10.0.171",
47
+ "@remnic/connector-omi": "^10.0.171",
48
+ "@remnic/capture-audio": "^10.0.171"
49
49
  },
50
50
  "peerDependenciesMeta": {
51
51
  "@remnic/bench": {
@@ -97,19 +97,19 @@
97
97
  "devDependencies": {
98
98
  "tsup": "^8.5.1",
99
99
  "typescript": "^5.9.3",
100
- "@remnic/bench": "10.0.169",
101
- "@remnic/plugin-openclaw": "10.0.169",
102
- "@remnic/import-weclone": "10.0.169",
103
- "@remnic/import-chatgpt": "10.0.169",
104
- "@remnic/import-claude": "10.0.169",
105
- "@remnic/import-lossless-claw": "10.0.169",
106
- "@remnic/import-gemini": "10.0.169",
107
- "@remnic/import-mem0": "10.0.169",
108
- "@remnic/import-supermemory": "10.0.169",
109
- "@remnic/connector-limitless": "10.0.169",
110
- "@remnic/connector-bee": "10.0.169",
111
- "@remnic/export-weclone": "10.0.169",
112
- "@remnic/connector-omi": "10.0.169"
100
+ "@remnic/bench": "10.0.171",
101
+ "@remnic/plugin-openclaw": "10.0.171",
102
+ "@remnic/export-weclone": "10.0.171",
103
+ "@remnic/import-weclone": "10.0.171",
104
+ "@remnic/import-claude": "10.0.171",
105
+ "@remnic/import-chatgpt": "10.0.171",
106
+ "@remnic/import-lossless-claw": "10.0.171",
107
+ "@remnic/import-gemini": "10.0.171",
108
+ "@remnic/import-mem0": "10.0.171",
109
+ "@remnic/connector-limitless": "10.0.171",
110
+ "@remnic/connector-bee": "10.0.171",
111
+ "@remnic/connector-omi": "10.0.171",
112
+ "@remnic/import-supermemory": "10.0.171"
113
113
  },
114
114
  "license": "MIT",
115
115
  "repository": {