( projectPath: string, )
| 352 | * prefix-based scanning when the exact match doesn't exist. |
| 353 | */ |
| 354 | export async function findProjectDir( |
| 355 | projectPath: string, |
| 356 | ): Promise<string | undefined> { |
| 357 | const exact = getProjectDir(projectPath) |
| 358 | try { |
| 359 | await readdir(exact) |
| 360 | return exact |
| 361 | } catch { |
| 362 | // Exact match failed — for short paths this means no sessions exist. |
| 363 | // For long paths, try prefix matching to handle hash mismatches. |
| 364 | const sanitized = sanitizePath(projectPath) |
| 365 | if (sanitized.length <= MAX_SANITIZED_LENGTH) { |
| 366 | return undefined |
| 367 | } |
| 368 | const prefix = sanitized.slice(0, MAX_SANITIZED_LENGTH) |
| 369 | const projectsDir = getProjectsDir() |
| 370 | try { |
| 371 | const dirents = await readdir(projectsDir, { withFileTypes: true }) |
| 372 | const match = dirents.find( |
| 373 | d => d.isDirectory() && d.name.startsWith(prefix + '-'), |
| 374 | ) |
| 375 | return match ? join(projectsDir, match.name) : undefined |
| 376 | } catch { |
| 377 | return undefined |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | /** |
| 383 | * Resolve a sessionId to its on-disk JSONL file path. |
no test coverage detected