import { resolve } from "node:path"; export function cachedWorkspaceMatches( cached: unknown, requested: string, ): boolean { // Lexical only. realpath/stat would send the health probe back onto FUSE. return typeof cached === "string" && resolve(cached) === resolve(requested); } /** Health probes use cached local state only: never touch the mounted tree. */ export function isDaemonHealthy( state: { startedAt: number; lastUpdatedAt: number; lastReconcile: { finishedAt: number } | null; mountWorker?: { state: string; lastProgressAt: number | null }; } | null, pidAlive: boolean, now = Date.now(), ): boolean { const fresh = (timestamp: number | null | undefined, maxAge: number) => typeof timestamp === "number" && Number.isFinite(timestamp) && now - timestamp >= 0 && now - timestamp < maxAge; return Boolean( pidAlive && state && fresh(state.lastUpdatedAt, 15_000) && state.mountWorker?.state === "ready" && fresh(state.mountWorker.lastProgressAt, 45_000) && (state.lastReconcile ? fresh(state.lastReconcile.finishedAt, 60_000) : fresh(state.startedAt, 10_000)), ); }