mirror of
https://github.com/AgentSeal/codeburn.git
synced 2026-12-03 12:32:02 +00:00
Merge pull request #846 from jbspeakr/fix/omp-session-discovery
fix(omp): discover title-first session transcripts
This commit is contained in:
commit
b8c92bfba7
3 changed files with 34 additions and 12 deletions
|
|
@ -90,16 +90,21 @@ function getOmpSessionsDir(override?: string): string {
|
|||
return override ?? join(homedir(), '.omp', 'agent', 'sessions')
|
||||
}
|
||||
|
||||
async function readFirstEntry(filePath: string): Promise<PiEntry | null> {
|
||||
async function readSessionEntry(filePath: string): Promise<PiEntry | null> {
|
||||
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<SessionSource[]> {
|
||||
|
|
@ -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 })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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' }),
|
||||
|
|
|
|||
|
|
@ -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' }),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue