checkComputerUseLock method

Future<CheckResult> checkComputerUseLock()

Check lock state without acquiring.

Implementation

Future<CheckResult> checkComputerUseLock() async {
  final existing = await _readLock();
  if (existing == null) return CheckResultFree();
  if (existing.sessionId == _sessionId) return CheckResultHeldBySelf();
  if (_isProcessRunning(existing.pid)) {
    return CheckResultBlocked(by: existing.sessionId);
  }
  // Stale lock — recover
  _logDebug(
    'Recovering stale computer-use lock from session ${existing.sessionId} (PID ${existing.pid})',
  );
  try {
    await File(_lockPath).delete();
  } catch (_) {}
  return CheckResultFree();
}