/** * @file runWorktree.ts * @description Which `claude --worktree` session the Workspace's Changes panel * follows for the URL's `?run=` pane. A poll that misses the run (one bad read * lists no runs) keeps the last answer instead of moving the panel to the main * folder — which, while it holds an unsaved edit, asked to discard it out of * nowhere. * @author Nguyễn Ngọc Trí Vĩ */ export interface RunWorktree { run: string; session: string; } /** * @param prev The previous answer. * @param runParam The URL's `?run=`. * @param opened That run in the latest list, if the list had it. */ export function runWorktreeSession( prev: RunWorktree | null, runParam: string | null, opened: { worktree?: boolean; sessionId: string | null } | undefined ): RunWorktree | null { if (!runParam) return null; if (!opened) return prev?.run === runParam ? prev : null; return opened.worktree && opened.sessionId ? { run: runParam, session: opened.sessionId } : null; }