( localDir: string, nowMs: number = Date.now(), ttlMs: number = PANE_TARGET_TTL_MS, )
| 24 | } |
| 25 | |
| 26 | export function readArmedPaneTarget( |
| 27 | localDir: string, |
| 28 | nowMs: number = Date.now(), |
| 29 | ttlMs: number = PANE_TARGET_TTL_MS, |
| 30 | ): string | null { |
| 31 | const path = resolve(localDir, PANE_TARGET_FILE); |
| 32 | if (!existsSync(path)) return null; |
| 33 | try { |
| 34 | const state = JSON.parse(readFileSync(path, 'utf-8')) as Partial<PaneTargetState>; |
| 35 | if (typeof state.route !== 'string' || typeof state.armedAtMs !== 'number') return null; |
| 36 | if (nowMs - state.armedAtMs > ttlMs) return null; |
| 37 | return state.route; |
| 38 | } catch (err) { |
| 39 | const code = (err as { code?: string }).code; |
| 40 | if (code === 'EACCES' || code === 'EPERM' || code === 'EIO') { |
| 41 | process.stderr.write( |
| 42 | `[pane-target] readArmedPaneTarget failed at ${path}: ${err instanceof Error ? err.message : String(err)}\n`, |
| 43 | ); |
| 44 | } |
| 45 | return null; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | export function clearArmedPaneTarget(localDir: string): void { |
| 50 | const path = resolve(localDir, PANE_TARGET_FILE); |
no test coverage detected