( projectDir: string, doStat: boolean, projectPath?: string, )
| 167 | * (caller must sort/dedup after reading file contents instead). |
| 168 | */ |
| 169 | export async function listCandidates( |
| 170 | projectDir: string, |
| 171 | doStat: boolean, |
| 172 | projectPath?: string, |
| 173 | ): Promise<Candidate[]> { |
| 174 | let names: string[] |
| 175 | try { |
| 176 | names = await readdir(projectDir) |
| 177 | } catch { |
| 178 | return [] |
| 179 | } |
| 180 | |
| 181 | const results = await Promise.all( |
| 182 | names.map(async (name): Promise<Candidate | null> => { |
| 183 | if (!name.endsWith('.jsonl')) return null |
| 184 | const sessionId = validateUuid(name.slice(0, -6)) |
| 185 | if (!sessionId) return null |
| 186 | const filePath = join(projectDir, name) |
| 187 | if (!doStat) return { sessionId, filePath, mtime: 0, projectPath } |
| 188 | try { |
| 189 | const s = await stat(filePath) |
| 190 | return { sessionId, filePath, mtime: s.mtime.getTime(), projectPath } |
| 191 | } catch { |
| 192 | return null |
| 193 | } |
| 194 | }), |
| 195 | ) |
| 196 | |
| 197 | return results.filter((c): c is Candidate => c !== null) |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Reads a candidate's file contents and extracts full SessionInfo. |
no test coverage detected