mirror of
https://github.com/stablyai/orca.git
synced 2026-10-19 16:03:26 +00:00
28 lines
855 B
TypeScript
28 lines
855 B
TypeScript
// Picks the worktree the home-screen Resume card falls back to for a host when
|
|
// there's no mobile session history yet. Mirrors the desktop's focused
|
|
// workspace (worktree.ps marks exactly one isActive) rather than an arbitrary
|
|
// list-order pick, so a cold launch resumes the right thing.
|
|
|
|
export type ResumeCandidate = {
|
|
isActive?: boolean
|
|
lastOutputAt?: number
|
|
}
|
|
|
|
export function pickResumeWorktree<T extends ResumeCandidate>(worktrees: T[]): T | null {
|
|
if (worktrees.length === 0) {
|
|
return null
|
|
}
|
|
const desktopActive = worktrees.find((w) => w.isActive)
|
|
if (desktopActive) {
|
|
return desktopActive
|
|
}
|
|
// No desktop focus → most recent terminal output, else the first.
|
|
let best = worktrees[0]
|
|
for (const w of worktrees) {
|
|
if ((w.lastOutputAt ?? 0) > (best.lastOutputAt ?? 0)) {
|
|
best = w
|
|
}
|
|
}
|
|
return best
|
|
}
|