1import type { ThreadId, WorktreeSetupSnapshot } from "@t3tools/contracts";
2
3/** A subscription can close or replay an older value during the setup handoff. */
4export function resolveWorktreeSetupSnapshot(
5 threadId: ThreadId | null,
6 latest: WorktreeSetupSnapshot | null | undefined,
7 held: WorktreeSetupSnapshot | null,
8): WorktreeSetupSnapshot | null {
9 const current = latest?.threadId === threadId ? latest : null;
10 const previous = held?.threadId === threadId ? held : null;
11 return current && (!previous || current.sequence >= previous.sequence) ? current : previous;
12}