Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

fix(import): ignore root Finder metadata when locating a ZIP export (#6704)

ZedingZhangf2076520ca66
diff --git a/src/services/history-import/export-files.ts b/src/services/history-import/export-files.ts
index 753ea9b76..89349738f 100644
--- a/src/services/history-import/export-files.ts
+++ b/src/services/history-import/export-files.ts
@@ -110,10 +110,14 @@ async function* readZip(path: string): AsyncGenerator<ExportFile> {
const name = entry.fileName;
if (name.endsWith('/') || name.startsWith('__MACOSX/')) continue;
const slash = name.indexOf('/');
+ const inner = slash < 0 ? name : name.slice(slash + 1);
+ const candidate = [name, inner].some(file => CHAT_FILE.test(file) || isProjectFile(file) || NATIVE_FILE.test(file));
+ // A stray root file (.DS_Store, Thumbs.db, a readme) is not part of the
+ // export, so it must not cancel the single enclosing folder.
+ if (slash < 0 && !candidate) continue;
const folder = slash < 0 ? null : name.slice(0, slash);
commonFolder = commonFolder === undefined || commonFolder === folder ? folder : null;
- const inner = slash < 0 ? name : name.slice(slash + 1);
- if (![name, inner].some(file => CHAT_FILE.test(file) || isProjectFile(file) || NATIVE_FILE.test(file))) continue;
+ if (!candidate) continue;
if (selected.has(name)) throw new Error('Export contains duplicate JSON entries.');
selected.set(name, entry);
if (selected.size > MAX_SELECTED_FILES) throw new Error('Too many JSON files in this export.');
diff --git a/tests/services/history-import/export-files.test.ts b/tests/services/history-import/export-files.test.ts
index e1d4e4946..8f4bca185 100644
--- a/tests/services/history-import/export-files.test.ts
+++ b/tests/services/history-import/export-files.test.ts
@@ -34,6 +34,33 @@ describe('historical export file selection', () => {
]);
});
+ it.each([true, false])('ignores macOS root metadata when detecting a wrapper (metadata first: %s)', async first => {
+ const archive = join(root, 'export.zip');
+ const metadata = { '.DS_Store': Buffer.from('metadata') };
+ const contents = { 'export/conversations.json': Buffer.from('[]') };
+ await writeFile(archive, zipOf(first ? { ...metadata, ...contents } : { ...contents, ...metadata }));
+ expect(await read(archive)).toEqual([{ name: 'conversations.json', value: [] }]);
+ });
+
+ it('ignores any stray root file when detecting a wrapper', async () => {
+ const archive = join(root, 'export.zip');
+ await writeFile(archive, zipOf({
+ 'Thumbs.db': Buffer.from('thumbnails'),
+ 'README.txt': Buffer.from('readme'),
+ 'export/conversations.json': Buffer.from('[]'),
+ }));
+ expect(await read(archive)).toEqual([{ name: 'conversations.json', value: [] }]);
+ });
+
+ it('does not treat one of two top-level folders as the wrapper', async () => {
+ const archive = join(root, 'export.zip');
+ await writeFile(archive, zipOf({
+ 'export/conversations.json': Buffer.from('[]'),
+ 'other/notes.txt': Buffer.from('notes'),
+ }));
+ await expect(read(archive)).rejects.toThrow('No conversations JSON');
+ });
+
it.each(['', 'work/'])('reads native JSONL from the archive root or one wrapper (%s)', async prefix => {
const archive = join(root, 'native.zip');
await writeFile(archive, zipOf({