@remnic/cli 10.0.170 → 10.0.172

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 +123 -2
  2. package/package.json +32 -32
package/dist/index.js CHANGED
@@ -9508,6 +9508,77 @@ Or add it to a project:
9508
9508
  );
9509
9509
  }
9510
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
+
9511
9582
  // src/import-dispatch.ts
9512
9583
  var IMPORT_USAGE = `remnic import \u2014 Bring memory from ChatGPT, Claude, Gemini, Mem0, Supermemory, or OKF
9513
9584
 
@@ -9608,14 +9679,17 @@ function rejectLeftoverImportArgs(args, command) {
9608
9679
  }
9609
9680
  }
9610
9681
  async function runImportCommand(args, io) {
9611
- 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))) {
9612
9684
  throw new Error(
9613
9685
  `unpack first: archive imports are not supported ('${args.file}'). Extract the archive, then pass the directory.`
9614
9686
  );
9615
9687
  }
9616
9688
  const adapter = await io.loadAdapter(args.adapter);
9617
9689
  let input;
9618
- if (args.adapter === "okf") {
9690
+ if (chatgptZip) {
9691
+ input = await readChatGPTExportZip(args.file, io);
9692
+ } else if (args.adapter === "okf") {
9619
9693
  if (!args.file) {
9620
9694
  throw new Error("OKF import requires a directory path (remnic import okf <dir>)");
9621
9695
  }
@@ -9670,6 +9744,52 @@ async function runImportCommand(args, io) {
9670
9744
  }
9671
9745
  return result;
9672
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
+ }
9673
9793
  function isZipFilePath(filePath) {
9674
9794
  return pathExtension(filePath) === ".zip";
9675
9795
  }
@@ -9814,6 +9934,7 @@ async function cmdImport(rest, targetFactory, disposeTarget, ioOverrides = {}) {
9814
9934
  let materializePromise;
9815
9935
  const io = {
9816
9936
  readFile: ioOverrides.readFile ?? (async (p) => fs30.promises.readFile(p, "utf-8")),
9937
+ readFileBytes: ioOverrides.readFileBytes ?? (async (p) => fs30.promises.readFile(p)),
9817
9938
  loadAdapter: ioOverrides.loadAdapter ?? (async (name) => (await loadImporterModule(name)).adapter),
9818
9939
  runImporter: ioOverrides.runImporter ?? runImporter,
9819
9940
  getWriteTarget: async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remnic/cli",
3
- "version": "10.0.170",
3
+ "version": "10.0.172",
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.170",
30
- "@remnic/server": "^10.0.170",
31
- "@remnic/core": "^10.0.170"
29
+ "@remnic/plugin-pi": "^10.0.172",
30
+ "@remnic/server": "^10.0.172",
31
+ "@remnic/core": "^10.0.172"
32
32
  },
33
33
  "peerDependencies": {
34
- "@remnic/bench": "^10.0.170",
35
- "@remnic/plugin-openclaw": "^10.0.170",
36
- "@remnic/export-weclone": "^10.0.170",
37
- "@remnic/import-weclone": "^10.0.170",
38
- "@remnic/import-chatgpt": "^10.0.170",
39
- "@remnic/import-claude": "^10.0.170",
40
- "@remnic/import-gemini": "^10.0.170",
41
- "@remnic/import-lossless-claw": "^10.0.170",
42
- "@remnic/import-mem0": "^10.0.170",
43
- "@remnic/import-supermemory": "^10.0.170",
44
- "@remnic/import-okf": "^10.0.170",
45
- "@remnic/connector-limitless": "^10.0.170",
46
- "@remnic/connector-bee": "^10.0.170",
47
- "@remnic/connector-omi": "^10.0.170",
48
- "@remnic/capture-audio": "^10.0.170"
34
+ "@remnic/bench": "^10.0.172",
35
+ "@remnic/plugin-openclaw": "^10.0.172",
36
+ "@remnic/export-weclone": "^10.0.172",
37
+ "@remnic/import-weclone": "^10.0.172",
38
+ "@remnic/import-chatgpt": "^10.0.172",
39
+ "@remnic/import-claude": "^10.0.172",
40
+ "@remnic/import-gemini": "^10.0.172",
41
+ "@remnic/import-lossless-claw": "^10.0.172",
42
+ "@remnic/import-mem0": "^10.0.172",
43
+ "@remnic/import-supermemory": "^10.0.172",
44
+ "@remnic/import-okf": "^10.0.172",
45
+ "@remnic/connector-limitless": "^10.0.172",
46
+ "@remnic/connector-bee": "^10.0.172",
47
+ "@remnic/connector-omi": "^10.0.172",
48
+ "@remnic/capture-audio": "^10.0.172"
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.170",
101
- "@remnic/plugin-openclaw": "10.0.170",
102
- "@remnic/export-weclone": "10.0.170",
103
- "@remnic/import-weclone": "10.0.170",
104
- "@remnic/import-chatgpt": "10.0.170",
105
- "@remnic/import-gemini": "10.0.170",
106
- "@remnic/import-claude": "10.0.170",
107
- "@remnic/import-lossless-claw": "10.0.170",
108
- "@remnic/connector-bee": "10.0.170",
109
- "@remnic/import-mem0": "10.0.170",
110
- "@remnic/connector-limitless": "10.0.170",
111
- "@remnic/import-supermemory": "10.0.170",
112
- "@remnic/connector-omi": "10.0.170"
100
+ "@remnic/plugin-openclaw": "10.0.172",
101
+ "@remnic/export-weclone": "10.0.172",
102
+ "@remnic/bench": "10.0.172",
103
+ "@remnic/import-chatgpt": "10.0.172",
104
+ "@remnic/import-gemini": "10.0.172",
105
+ "@remnic/import-claude": "10.0.172",
106
+ "@remnic/import-weclone": "10.0.172",
107
+ "@remnic/import-lossless-claw": "10.0.172",
108
+ "@remnic/import-mem0": "10.0.172",
109
+ "@remnic/import-supermemory": "10.0.172",
110
+ "@remnic/connector-limitless": "10.0.172",
111
+ "@remnic/connector-omi": "10.0.172",
112
+ "@remnic/connector-bee": "10.0.172"
113
113
  },
114
114
  "license": "MIT",
115
115
  "repository": {