( home: string, zipBuffer: Buffer, originalName: string | null, now: Date, )
| 47 | * `import-meta.json` contents. |
| 48 | */ |
| 49 | export async function importSessionZip( |
| 50 | home: string, |
| 51 | zipBuffer: Buffer, |
| 52 | originalName: string | null, |
| 53 | now: Date, |
| 54 | ): Promise<ImportInfo> { |
| 55 | const importId = newImportId(); |
| 56 | const dir = importedDirOf(home, importId); |
| 57 | await mkdir(dir, { recursive: true }); |
| 58 | |
| 59 | try { |
| 60 | await extractZip(zipBuffer, dir); |
| 61 | |
| 62 | // A debug bundle must contain a main wire; without it there is nothing to |
| 63 | // visualize. `state.json` / `manifest.json` are best-effort. |
| 64 | const hasMainWire = await pathExists(join(dir, 'agents', 'main', 'wire.jsonl')); |
| 65 | if (!hasMainWire) { |
| 66 | throw new ZipImportError( |
| 67 | 'zip does not look like a kimi-code session bundle (missing agents/main/wire.jsonl)', |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | const manifest = await readManifest(dir); |
| 72 | const meta: ImportInfo = { |
| 73 | importId, |
| 74 | importedAt: now.toISOString(), |
| 75 | originalName: originalName !== null && originalName.length > 0 ? originalName : null, |
| 76 | manifest, |
| 77 | }; |
| 78 | await writeFile(join(dir, META_FILE), JSON.stringify(meta, null, 2), 'utf8'); |
| 79 | return meta; |
| 80 | } catch (error) { |
| 81 | await rm(dir, { recursive: true, force: true }).catch(() => {}); |
| 82 | throw error instanceof ZipImportError ? error : new ZipImportError((error as Error).message); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** Enumerate imported bundle ids (newest-first by directory mtime). */ |
| 87 | export async function listImportedIds(home: string): Promise<string[]> { |
no test coverage detected