From 716e080cb3b9d53ab3a562864efb780bbd87dd0b Mon Sep 17 00:00:00 2001 From: Ninym Date: Fri, 17 Apr 2026 08:08:54 +0200 Subject: [PATCH] fix(pi): use bounded readSessionFile helper Both Pi session read paths (first-entry meta and full-session parse) now pass through the 128 MB-capped helper. MEDIUM-1 coverage for the Pi provider. --- src/providers/pi.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/providers/pi.ts b/src/providers/pi.ts index 4fb42cf..92af213 100644 --- a/src/providers/pi.ts +++ b/src/providers/pi.ts @@ -1,7 +1,8 @@ -import { readdir, readFile, stat } from 'fs/promises' +import { readdir, stat } from 'fs/promises' import { basename, join } from 'path' import { homedir } from 'os' +import { readSessionFile } from '../fs-utils.js' import { calculateCost } from '../models.js' import { extractBashCommands } from '../bash-utils.js' import type { Provider, SessionSource, SessionParser, ParsedProviderCall } from './types.js' @@ -56,10 +57,11 @@ function getPiSessionsDir(override?: string): string { } async function readFirstEntry(filePath: string): Promise { + const content = await readSessionFile(filePath) + if (content === null) return null + const line = content.split('\n')[0] + if (!line?.trim()) return null try { - const content = await readFile(filePath, 'utf-8') - const line = content.split('\n')[0] - if (!line?.trim()) return null return JSON.parse(line) as PiEntry } catch { return null @@ -108,13 +110,8 @@ async function discoverSessionsInDir(sessionsDir: string): Promise): SessionParser { return { async *parse(): AsyncGenerator { - let content: string - try { - content = await readFile(source.path, 'utf-8') - } catch { - return - } - + const content = await readSessionFile(source.path) + if (content === null) return const lines = content.split('\n').filter(l => l.trim()) let sessionId = basename(source.path, '.jsonl') let pendingUserMessage = ''