| 449 | } |
| 450 | |
| 451 | function readRecentLogTail(logPath: string): string | undefined { |
| 452 | try { |
| 453 | if (!fs.existsSync(logPath)) return undefined; |
| 454 | const stats = fs.statSync(logPath); |
| 455 | if (stats.size <= 0) return undefined; |
| 456 | const length = Math.min(stats.size, DAEMON_STARTUP_LOG_TAIL_BYTES); |
| 457 | const fd = fs.openSync(logPath, 'r'); |
| 458 | try { |
| 459 | const buffer = Buffer.alloc(length); |
| 460 | fs.readSync(fd, buffer, 0, length, stats.size - length); |
| 461 | const text = buffer.toString('utf8').trim(); |
| 462 | return text.length > 0 ? text : undefined; |
| 463 | } finally { |
| 464 | fs.closeSync(fd); |
| 465 | } |
| 466 | } catch { |
| 467 | return undefined; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | function resolveRemoteDaemonBaseUrl(raw: string | undefined): string | undefined { |
| 472 | if (!raw) return undefined; |