()
| 108 | * `request_access`. Does NOT create — that's `tryAcquireComputerUseLock`'s job. |
| 109 | */ |
| 110 | export async function checkComputerUseLock(): Promise<CheckResult> { |
| 111 | const existing = await readLock() |
| 112 | if (!existing) return { kind: 'free' } |
| 113 | if (existing.sessionId === getSessionId()) return { kind: 'held_by_self' } |
| 114 | if (isProcessRunning(existing.pid)) { |
| 115 | return { kind: 'blocked', by: existing.sessionId } |
| 116 | } |
| 117 | logForDebugging( |
| 118 | `Recovering stale computer-use lock from session ${existing.sessionId} (PID ${existing.pid})`, |
| 119 | ) |
| 120 | await unlink(getLockPath()).catch(() => {}) |
| 121 | return { kind: 'free' } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Zero-syscall check: does THIS process believe it holds the lock? |
no test coverage detected