( options?: ListSessionsOptions, )
| 437 | * as the original implementation). |
| 438 | */ |
| 439 | export async function listSessionsImpl( |
| 440 | options?: ListSessionsOptions, |
| 441 | ): Promise<SessionInfo[]> { |
| 442 | const { dir, limit, offset, includeWorktrees } = options ?? {} |
| 443 | const off = offset ?? 0 |
| 444 | // Only stat when we need to sort before reading (won't read all anyway). |
| 445 | // limit: 0 means "no limit" (see applySortAndLimit), so treat it as unset. |
| 446 | const doStat = (limit !== undefined && limit > 0) || off > 0 |
| 447 | |
| 448 | const candidates = dir |
| 449 | ? await gatherProjectCandidates(dir, includeWorktrees ?? true, doStat) |
| 450 | : await gatherAllCandidates(doStat) |
| 451 | |
| 452 | if (!doStat) return readAllAndSort(candidates) |
| 453 | return applySortAndLimit(candidates, limit, off) |
| 454 | } |
| 455 |
nothing calls this directly
no test coverage detected