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