memex-mvp 0.10.1 → 0.10.2

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/lib/cli/index.js CHANGED
@@ -1308,8 +1308,10 @@ async function tgCmdImport(positionals, opts, pending, decisions) {
1308
1308
  raw = parseTelegramHtmlExport(t.path);
1309
1309
  } else if (t.kind === 'json-file') {
1310
1310
  raw = JSON.parse(readFileSync(t.path, 'utf-8'));
1311
+ } else if (t.kind === 'json-in-dir' && t.inner_json_path) {
1312
+ raw = JSON.parse(readFileSync(t.inner_json_path, 'utf-8'));
1311
1313
  } else {
1312
- results.push({ path: t.path, error: 'unknown kind' });
1314
+ results.push({ path: t.path, error: `unknown kind: ${t.kind}` });
1313
1315
  continue;
1314
1316
  }
1315
1317
  if (!raw) {
@@ -267,18 +267,21 @@ export function previewExport(path) {
267
267
  out.size_bytes = s.isDirectory() ? dirSizeShallow(path) : s.size;
268
268
 
269
269
  if (s.isDirectory()) {
270
+ // Telegram Desktop directories can contain EITHER messages.html (HTML
271
+ // export) OR a top-level *.json (JSON export — usually `result.json`
272
+ // but custom names like `kimi.json` also occur when user renamed).
273
+ // Try HTML first; fall back to the first JSON file we find inside.
270
274
  out.kind = 'html-dir';
275
+ let parsedOk = false;
271
276
  try {
272
277
  const parsed = parseTelegramHtmlExport(path);
273
- if (parsed && parsed.chats.list[0]) {
278
+ if (parsed && parsed.chats.list[0] && parsed.chats.list[0].messages.length > 0) {
274
279
  const chat = parsed.chats.list[0];
275
280
  out.chat_title = chat.name;
276
281
  out.chat_type = chat.type;
277
282
  out.message_count = chat.messages.length;
278
- if (chat.messages.length > 0) {
279
- out.date_first = chat.messages[0].date || null;
280
- out.date_last = chat.messages[chat.messages.length - 1].date || null;
281
- }
283
+ out.date_first = chat.messages[0].date || null;
284
+ out.date_last = chat.messages[chat.messages.length - 1].date || null;
282
285
  const seen = new Set();
283
286
  for (const m of chat.messages) {
284
287
  if (m.from && m.from !== 'Unknown' && !seen.has(m.from)) {
@@ -287,8 +290,50 @@ export function previewExport(path) {
287
290
  if (out.senders_sample.length >= 6) break;
288
291
  }
289
292
  }
293
+ parsedOk = true;
290
294
  }
291
- } catch (_) { /* swallow — bad export */ }
295
+ } catch (_) { /* swallow — try JSON next */ }
296
+
297
+ // JSON fallback — look for any *.json directly in the dir
298
+ if (!parsedOk) {
299
+ try {
300
+ const entries = readdirSync(path);
301
+ // Prefer result.json; otherwise first *.json
302
+ const jsonName = entries.find((n) => n === 'result.json')
303
+ || entries.find((n) => n.endsWith('.json'));
304
+ if (jsonName) {
305
+ const jsonPath = join(path, jsonName);
306
+ out.kind = 'json-in-dir';
307
+ out.inner_json_path = jsonPath;
308
+ const data = JSON.parse(readFileSync(jsonPath, 'utf-8'));
309
+ let chat = null;
310
+ if (data && data.chats && Array.isArray(data.chats.list) && data.chats.list[0]) {
311
+ chat = data.chats.list[0];
312
+ } else if (data && Array.isArray(data.messages)) {
313
+ chat = data;
314
+ }
315
+ if (chat) {
316
+ out.chat_title = chat.name || 'Telegram chat';
317
+ out.chat_type = chat.type || null;
318
+ const msgs = Array.isArray(chat.messages) ? chat.messages : [];
319
+ out.message_count = msgs.length;
320
+ if (msgs.length > 0) {
321
+ out.date_first = msgs[0].date || null;
322
+ out.date_last = msgs[msgs.length - 1].date || null;
323
+ }
324
+ const seen = new Set();
325
+ for (const m of msgs) {
326
+ const from = m.from || m.actor;
327
+ if (from && !seen.has(from)) {
328
+ seen.add(from);
329
+ out.senders_sample.push(from);
330
+ if (out.senders_sample.length >= 6) break;
331
+ }
332
+ }
333
+ }
334
+ }
335
+ } catch (_) { /* swallow */ }
336
+ }
292
337
  } else if (s.isFile() && path.endsWith('.json')) {
293
338
  out.kind = 'json-file';
294
339
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "memex-mvp",
3
- "version": "0.10.1",
3
+ "version": "0.10.2",
4
4
  "description": "Local-first MCP server for cross-agent AI memory. One SQLite + FTS5 corpus across Claude Code, Cowork, Cursor, Continue, Zed, Obsidian, and Telegram — passively captured, verbatim, searchable from any MCP-compatible client.",
5
5
  "type": "module",
6
6
  "main": "server.js",
package/server.js CHANGED
@@ -3192,6 +3192,8 @@ server.setRequestHandler(CallToolRequestSchema, async (req) => {
3192
3192
  let raw;
3193
3193
  if (t.kind === 'html-dir') {
3194
3194
  raw = parseTelegramHtmlExport(t.path);
3195
+ } else if (t.kind === 'json-in-dir' && t.inner_json_path) {
3196
+ raw = JSON.parse(readFileSync(t.inner_json_path, 'utf-8'));
3195
3197
  } else {
3196
3198
  raw = JSON.parse(readFileSync(t.path, 'utf-8'));
3197
3199
  }