@masslessai/push-todo 3.5.1 → 3.5.2
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/lib/daemon-health.js +34 -2
- package/package.json +1 -1
package/lib/daemon-health.js
CHANGED
|
@@ -180,14 +180,46 @@ export function stopDaemon() {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
/**
|
|
183
|
-
*
|
|
184
|
-
|
|
183
|
+
* Get the installed package version (npm package version).
|
|
184
|
+
*/
|
|
185
|
+
function getInstalledVersion() {
|
|
186
|
+
try {
|
|
187
|
+
const pkgPath = join(__dirname, '..', 'package.json');
|
|
188
|
+
const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
|
|
189
|
+
return pkg.version || null;
|
|
190
|
+
} catch {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Ensure daemon is running with correct version - called on every /push-todo command.
|
|
197
|
+
* Auto-restarts daemon if version mismatch detected.
|
|
198
|
+
*
|
|
199
|
+
* This prevents stale daemons from running after npm package updates.
|
|
200
|
+
* See: /docs/20260204_daemon_heartbeat_status_indicator_implementation_plan.md
|
|
185
201
|
*/
|
|
186
202
|
export function ensureDaemonRunning() {
|
|
187
203
|
const status = getDaemonStatus();
|
|
204
|
+
const installedVersion = getInstalledVersion();
|
|
205
|
+
|
|
206
|
+
// Case 1: Daemon not running - start it
|
|
188
207
|
if (!status.running) {
|
|
189
208
|
startDaemon();
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Case 2: Daemon running but version mismatch - restart it
|
|
213
|
+
if (installedVersion && status.version && status.version !== installedVersion) {
|
|
214
|
+
// Version mismatch - restart daemon with new version
|
|
215
|
+
stopDaemon();
|
|
216
|
+
// Brief delay to ensure clean shutdown
|
|
217
|
+
const start = Date.now();
|
|
218
|
+
while (Date.now() - start < 500) {} // 500ms busy wait
|
|
219
|
+
startDaemon();
|
|
190
220
|
}
|
|
221
|
+
|
|
222
|
+
// Case 3: Daemon running with correct version - do nothing
|
|
191
223
|
}
|
|
192
224
|
|
|
193
225
|
export { PID_FILE, LOG_FILE, STATUS_FILE, PUSH_DIR };
|