diff --git a/src/commands/list.ts b/src/commands/list.ts index e2fb428..a72ebf3 100644 --- a/src/commands/list.ts +++ b/src/commands/list.ts @@ -6,6 +6,11 @@ import * as vm from "../vm.ts" import * as state from "../state.ts" import { die, reset, dim, green, yellow, cyan, magenta, red } from "../fmt.ts" +interface ListSession extends state.Session { + repoRoot: string + repo?: string +} + // ── Shared rendering ───────────────────────────────────────────────── const styleDefs: [string, string, string][] = [ @@ -17,9 +22,9 @@ const styles = Object.fromEntries( ) function renderSessions( - sessions: { branch: string; prompt?: string }[], + sessions: ListSession[], statuses: Record, - keyFn: (s: { branch: string }) => string, + keyFn: (s: ListSession) => string, ) { const branchWidth = Math.max(6, ...sessions.map(s => s.branch.length)) const cols = process.stdout.columns || 80 @@ -49,7 +54,7 @@ async function resolveStatus( ): Promise { try { await stat(s.worktree) } catch { return "idle" } if (vmRunning) { - const active = await vm.isClaudeActive(s.worktree, s.branch) + const active = await vm.isClaudeActive(s.worktree, s.branch).catch(() => false) if (active && s.in_review) return "review" if (active) return "active" } @@ -120,11 +125,6 @@ async function backfillPrompts(sessions: { worktree: string; prompt?: string }[] // ── Commands ───────────────────────────────────────────────────────── -interface ListSession extends state.Session { - repoRoot: string - repo?: string -} - export async function action(opts: { json?: boolean; all?: boolean; add?: string; remove?: string }) { if (opts.add) return actionAdd(opts.add) if (opts.remove) return actionRemove(opts.remove) @@ -185,7 +185,12 @@ async function actionAdd(dir: string) { } async function actionRemove(dir: string) { - const removed = await state.unregisterProject(dir) + let removed: boolean + try { + removed = await state.unregisterProject(dir) + } catch { + die("Could not acquire registry lock") + } if (removed) { console.log(`${red}-${reset} ${dir}`) } else { diff --git a/src/state.ts b/src/state.ts index fb36f62..103ace7 100644 --- a/src/state.ts +++ b/src/state.ts @@ -76,11 +76,7 @@ async function withGlobalLock(fn: () => Promise): Promise { const info = await stat(lockPath) if (Date.now() - info.mtimeMs > 300_000) { await rmdir(lockPath).catch(() => {}) - // Retry mkdir immediately instead of continuing the loop - try { - await mkdir(lockPath) - break - } catch {} + continue } } catch {} if (i === 19) throw new Error("Could not acquire registry lock")