* Read the first JSONL line from a file and parse it.
(filePath: string)
| 30 | * Read the first JSONL line from a file and parse it. |
| 31 | */ |
| 32 | async function readFirstLine(filePath: string): Promise<Record<string, unknown> | null> { |
| 33 | return new Promise((resolve) => { |
| 34 | const rl = createInterface({input: createReadStream(filePath), crlfDelay: Infinity}); |
| 35 | let done = false; |
| 36 | rl.on('line', (line) => { |
| 37 | if (done || !line.trim()) return; |
| 38 | done = true; |
| 39 | rl.close(); |
| 40 | try { |
| 41 | resolve(JSON.parse(line)); |
| 42 | } catch { |
| 43 | resolve(null); |
| 44 | } |
| 45 | }); |
| 46 | rl.on('close', () => { if (!done) resolve(null); }); |
| 47 | rl.on('error', () => resolve(null)); |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Walk ~/.codex/sessions/YYYY/MM/DD/ and yield rollout JSONL files (newest first). |