bloby-bot 0.22.16 → 0.22.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +55 -15
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -715,19 +715,26 @@ function writeVersionFile(version) {
|
|
|
715
715
|
}
|
|
716
716
|
|
|
717
717
|
/**
|
|
718
|
-
* Poll
|
|
718
|
+
* Poll daemon log for __READY__ and config.json for tunnel URL until the daemon
|
|
719
|
+
* is fully ready (tunnel registered with relay). logOffset should be captured
|
|
720
|
+
* BETWEEN stopping and starting the daemon so only new-session output is checked.
|
|
721
|
+
*
|
|
719
722
|
* Advances the stepper through tunnel + verification steps.
|
|
720
723
|
*/
|
|
721
|
-
async function waitForDaemonHealth(stepper, config, hasTunnel) {
|
|
724
|
+
async function waitForDaemonHealth(stepper, config, hasTunnel, logOffset) {
|
|
722
725
|
const port = config.port || 7400;
|
|
723
726
|
const relayUrl = config.relay?.url || null;
|
|
724
727
|
let tunnelUrl = null;
|
|
725
728
|
let tunnelShown = false;
|
|
726
|
-
let
|
|
729
|
+
let ready = false;
|
|
727
730
|
|
|
728
|
-
// Clear any stale tunnelUrl from config so we detect the fresh one
|
|
729
731
|
const oldTunnelUrl = config.tunnelUrl || null;
|
|
730
732
|
|
|
733
|
+
// Daemon log file — the supervisor writes __READY__ to stdout which goes here
|
|
734
|
+
const logFile = PLATFORM === 'darwin'
|
|
735
|
+
? path.join(LAUNCHD_LOG_DIR, 'bloby.log')
|
|
736
|
+
: null;
|
|
737
|
+
|
|
731
738
|
for (let i = 0; i < 120; i++) {
|
|
732
739
|
await new Promise(r => setTimeout(r, 1000));
|
|
733
740
|
|
|
@@ -749,14 +756,32 @@ async function waitForDaemonHealth(stepper, config, hasTunnel) {
|
|
|
749
756
|
} catch {}
|
|
750
757
|
}
|
|
751
758
|
|
|
752
|
-
// Check
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
759
|
+
// Check for __READY__ in daemon log (emitted after relay registration)
|
|
760
|
+
if (!ready) {
|
|
761
|
+
if (logFile && fs.existsSync(logFile)) {
|
|
762
|
+
try {
|
|
763
|
+
const currentSize = fs.statSync(logFile).size;
|
|
764
|
+
if (currentSize > logOffset) {
|
|
765
|
+
const fd = fs.openSync(logFile, 'r');
|
|
766
|
+
const buf = Buffer.alloc(currentSize - logOffset);
|
|
767
|
+
fs.readSync(fd, buf, 0, buf.length, logOffset);
|
|
768
|
+
fs.closeSync(fd);
|
|
769
|
+
const newContent = buf.toString('utf-8');
|
|
770
|
+
if (newContent.includes('__READY__')) {
|
|
771
|
+
ready = true;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
} catch {}
|
|
775
|
+
} else {
|
|
776
|
+
// Linux / no log file fallback: check local health
|
|
777
|
+
try {
|
|
778
|
+
const res = await fetch(`http://127.0.0.1:${port}/api/health`);
|
|
779
|
+
if (res.ok) ready = true;
|
|
780
|
+
} catch {}
|
|
758
781
|
}
|
|
759
|
-
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
if (ready && (!hasTunnel || tunnelShown)) break;
|
|
760
785
|
}
|
|
761
786
|
|
|
762
787
|
// If tunnel never came up, advance past tunnel step anyway
|
|
@@ -777,7 +802,7 @@ async function waitForDaemonHealth(stepper, config, hasTunnel) {
|
|
|
777
802
|
if (cfg.tunnelUrl) tunnelUrl = cfg.tunnelUrl;
|
|
778
803
|
} catch {}
|
|
779
804
|
|
|
780
|
-
return { tunnelUrl, relayUrl, healthOk };
|
|
805
|
+
return { tunnelUrl, relayUrl, healthOk: ready };
|
|
781
806
|
}
|
|
782
807
|
|
|
783
808
|
// ── Steps ──
|
|
@@ -1484,6 +1509,13 @@ async function update() {
|
|
|
1484
1509
|
// Restart daemon if it was running (skipped during self-update)
|
|
1485
1510
|
let updateResult = null;
|
|
1486
1511
|
if (daemonWasRunning) {
|
|
1512
|
+
// Capture log offset before starting so we only detect new-session __READY__
|
|
1513
|
+
const updateLogFile = path.join(LAUNCHD_LOG_DIR, 'bloby.log');
|
|
1514
|
+
let updateLogOffset = 0;
|
|
1515
|
+
if (PLATFORM === 'darwin' && fs.existsSync(updateLogFile)) {
|
|
1516
|
+
try { updateLogOffset = fs.statSync(updateLogFile).size; } catch {}
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1487
1519
|
try {
|
|
1488
1520
|
if (PLATFORM === 'darwin') {
|
|
1489
1521
|
execSync(`launchctl load "${LAUNCHD_PLIST_PATH}"`, { stdio: 'ignore' });
|
|
@@ -1495,7 +1527,7 @@ async function update() {
|
|
|
1495
1527
|
stepper.advance(); // Restarting daemon done
|
|
1496
1528
|
|
|
1497
1529
|
// Wait for daemon to become healthy and tunnel to connect
|
|
1498
|
-
updateResult = await waitForDaemonHealth(stepper, updateConfig, updateHasTunnel);
|
|
1530
|
+
updateResult = await waitForDaemonHealth(stepper, updateConfig, updateHasTunnel, updateLogOffset);
|
|
1499
1531
|
}
|
|
1500
1532
|
|
|
1501
1533
|
stepper.finish();
|
|
@@ -1645,10 +1677,17 @@ async function daemon(sub) {
|
|
|
1645
1677
|
try { execSync(`launchctl unload "${LAUNCHD_PLIST_PATH}" 2>/dev/null`, { stdio: 'ignore' }); } catch {}
|
|
1646
1678
|
restartStepper.advance(); // Stopping daemon done
|
|
1647
1679
|
|
|
1680
|
+
// Capture log offset between stop and start so we only see new session output
|
|
1681
|
+
const restartLogFile = path.join(LAUNCHD_LOG_DIR, 'bloby.log');
|
|
1682
|
+
let restartLogOffset = 0;
|
|
1683
|
+
if (fs.existsSync(restartLogFile)) {
|
|
1684
|
+
try { restartLogOffset = fs.statSync(restartLogFile).size; } catch {}
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1648
1687
|
execSync(`launchctl load "${LAUNCHD_PLIST_PATH}"`, { stdio: 'ignore' });
|
|
1649
1688
|
restartStepper.advance(); // Starting daemon done
|
|
1650
1689
|
|
|
1651
|
-
const restartResult = await waitForDaemonHealth(restartStepper, restartConfig, restartHasTunnel);
|
|
1690
|
+
const restartResult = await waitForDaemonHealth(restartStepper, restartConfig, restartHasTunnel, restartLogOffset);
|
|
1652
1691
|
restartStepper.finish();
|
|
1653
1692
|
|
|
1654
1693
|
console.log(`\n ${c.blue}✔${c.reset} Bloby daemon restarted.\n`);
|
|
@@ -1787,7 +1826,8 @@ async function daemon(sub) {
|
|
|
1787
1826
|
execSync(`systemctl start ${SERVICE_NAME}`, { stdio: 'ignore' });
|
|
1788
1827
|
sysRestartStepper.advance(); // Starting daemon done
|
|
1789
1828
|
|
|
1790
|
-
|
|
1829
|
+
// Linux: no log file offset, falls back to local health check
|
|
1830
|
+
const sysRestartResult = await waitForDaemonHealth(sysRestartStepper, sysRestartConfig, sysRestartHasTunnel, 0);
|
|
1791
1831
|
sysRestartStepper.finish();
|
|
1792
1832
|
|
|
1793
1833
|
console.log(`\n ${c.blue}✔${c.reset} Bloby daemon restarted.\n`);
|