From 36e5ef0a467c766ac7ea44773c06e0d94cb18033 Mon Sep 17 00:00:00 2001 From: Jan Brennenstuhl <351f49a18b8d@brnnnsthl.eu> Date: Mon, 27 Jul 2026 19:58:50 +0200 Subject: [PATCH] fix(omp): discover title-first session transcripts Co-authored-by: openai/gpt-5.6-terra --- src/providers/pi.ts | 25 +++++++++++++++---------- tests/providers/omp.test.ts | 19 ++++++++++++++++++- tests/providers/pi.test.ts | 2 +- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/providers/pi.ts b/src/providers/pi.ts index 85d5f25c..fa10e1b1 100644 --- a/src/providers/pi.ts +++ b/src/providers/pi.ts @@ -90,16 +90,21 @@ function getOmpSessionsDir(override?: string): string { return override ?? join(homedir(), '.omp', 'agent', 'sessions') } -async function readFirstEntry(filePath: string): Promise { +async function readSessionEntry(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 { - return JSON.parse(line) as PiEntry - } catch { - return null + + for (const line of content.split('\n')) { + if (!line.trim()) continue + try { + const entry = JSON.parse(line) as PiEntry + if (entry?.type === 'session') return entry + } catch { + continue + } } + + return null } async function discoverSessionsInDir(sessionsDir: string, providerName: string): Promise { @@ -130,10 +135,10 @@ async function discoverSessionsInDir(sessionsDir: string, providerName: string): const fileStat = await stat(filePath).catch(() => null) if (!fileStat?.isFile()) continue - const first = await readFirstEntry(filePath) - if (!first || first.type !== 'session') continue + const entry = await readSessionEntry(filePath) + if (!entry) continue - const cwd = first.cwd ?? dirName + const cwd = entry.cwd ?? dirName sources.push({ path: filePath, project: basename(cwd), provider: providerName }) } } diff --git a/tests/providers/omp.test.ts b/tests/providers/omp.test.ts index 6a25c27e..1a1a7249 100644 --- a/tests/providers/omp.test.ts +++ b/tests/providers/omp.test.ts @@ -110,13 +110,30 @@ describe('omp provider - session discovery', () => { expect(sessions[0]!.project).toBe('myproject') }) + it('discovers title-first sessions', async () => { + const projectDir = join(tmpDir, '--Users-test-myproject--') + await writeSession(projectDir, 'title-first.jsonl', [ + JSON.stringify({ type: 'title', title: 'OMP title-first session' }), + '', + sessionMeta({ cwd: '/Users/test/myproject' }), + assistantMessage({}), + ]) + + const provider = createOmpProvider(tmpDir) + const sessions = await provider.discoverSessions() + + expect(sessions).toHaveLength(1) + expect(sessions[0]!.provider).toBe('omp') + expect(sessions[0]!.project).toBe('myproject') + }) + it('returns empty for non-existent directory', async () => { const provider = createOmpProvider('/nonexistent/omp/path') const sessions = await provider.discoverSessions() expect(sessions).toEqual([]) }) - it('skips files whose first line is not a session entry', async () => { + it('skips files without a session entry', async () => { const projectDir = join(tmpDir, '--Users-test-myproject--') await writeSession(projectDir, 'bad.jsonl', [ JSON.stringify({ type: 'message', id: 'x' }), diff --git a/tests/providers/pi.test.ts b/tests/providers/pi.test.ts index 398d5098..06736287 100644 --- a/tests/providers/pi.test.ts +++ b/tests/providers/pi.test.ts @@ -165,7 +165,7 @@ describe('pi provider - session discovery', () => { expect(sessions).toEqual([]) }) - it('skips files whose first line is not a session entry', async () => { + it('skips files without a session entry', async () => { const projectDir = join(tmpDir, '--Users-test-myproject--') await writeSession(projectDir, 'bad.jsonl', [ JSON.stringify({ type: 'message', id: 'x' }),