adhdev 0.9.13 → 0.9.14

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/dist/cli/index.js CHANGED
@@ -38719,10 +38719,14 @@ var init_router = __esm({
38719
38719
  currentInstalled = parsed?.dependencies?.[pkgName]?.version || null;
38720
38720
  } catch {
38721
38721
  }
38722
- if (currentInstalled === latest) {
38722
+ const runningVersion = typeof this.deps.statusVersion === "string" ? this.deps.statusVersion.trim().replace(/^v/, "") : null;
38723
+ if (currentInstalled === latest && runningVersion === latest) {
38723
38724
  LOG.info("Upgrade", `Already on latest version v${latest}; skipping install`);
38724
38725
  return { success: true, upgraded: false, alreadyLatest: true, version: latest };
38725
38726
  }
38727
+ if (currentInstalled === latest && runningVersion && runningVersion !== latest) {
38728
+ LOG.info("Upgrade", `Installed package is v${latest}, but running daemon is v${runningVersion}; scheduling restart`);
38729
+ }
38726
38730
  spawnDetachedDaemonUpgradeHelper({
38727
38731
  packageName: pkgName,
38728
38732
  targetVersion: latest,
@@ -87136,21 +87140,65 @@ function isAdhdevProcess(pid) {
87136
87140
  return true;
87137
87141
  }
87138
87142
  }
87139
- function getDaemonPid(ref = {}) {
87140
- const pidFile = getDaemonPidFile(ref);
87143
+ function getDaemonHealthPid(ref = {}) {
87144
+ const port = resolveDaemonPort(ref);
87141
87145
  try {
87142
- if (!fs23.existsSync(pidFile)) return null;
87143
- const pid = parseInt(fs23.readFileSync(pidFile, "utf-8").trim(), 10);
87146
+ const { execFileSync: execFileSync5 } = require("child_process");
87147
+ const probe = `
87148
+ const http = require('http');
87149
+ const req = http.get('http://127.0.0.1:${port}/health', { timeout: 1500 }, (res) => {
87150
+ let body = '';
87151
+ res.setEncoding('utf8');
87152
+ res.on('data', (chunk) => { body += chunk; });
87153
+ res.on('end', () => {
87154
+ if (res.statusCode !== 200) return;
87155
+ try {
87156
+ const json = JSON.parse(body || '{}');
87157
+ if (Number.isFinite(json.pid)) process.stdout.write(String(json.pid));
87158
+ } catch {}
87159
+ });
87160
+ });
87161
+ req.on('error', () => {});
87162
+ req.on('timeout', () => { req.destroy(); });
87163
+ `;
87164
+ const result = execFileSync5(process.execPath, ["-e", probe], {
87165
+ encoding: "utf-8",
87166
+ timeout: 3e3,
87167
+ stdio: ["ignore", "pipe", "ignore"]
87168
+ }).trim();
87169
+ const pid = parseInt(result, 10);
87144
87170
  return Number.isFinite(pid) ? pid : null;
87145
87171
  } catch {
87146
87172
  return null;
87147
87173
  }
87148
87174
  }
87175
+ function getDaemonPid(ref = {}) {
87176
+ const pidFile = getDaemonPidFile(ref);
87177
+ try {
87178
+ if (fs23.existsSync(pidFile)) {
87179
+ const pid = parseInt(fs23.readFileSync(pidFile, "utf-8").trim(), 10);
87180
+ if (Number.isFinite(pid)) return pid;
87181
+ }
87182
+ } catch {
87183
+ }
87184
+ return getDaemonHealthPid(ref);
87185
+ }
87149
87186
  function stopDaemon(ref = {}) {
87150
87187
  const pidFile = getDaemonPidFile(ref);
87188
+ let pid = null;
87189
+ try {
87190
+ if (fs23.existsSync(pidFile)) {
87191
+ const pidFromFile = parseInt(fs23.readFileSync(pidFile, "utf-8").trim(), 10);
87192
+ if (Number.isFinite(pidFromFile)) pid = pidFromFile;
87193
+ }
87194
+ } catch {
87195
+ removeDaemonPid(ref);
87196
+ }
87197
+ if (pid === null) {
87198
+ pid = getDaemonHealthPid(ref);
87199
+ }
87200
+ if (pid === null) return false;
87151
87201
  try {
87152
- if (!fs23.existsSync(pidFile)) return false;
87153
- const pid = parseInt(fs23.readFileSync(pidFile, "utf-8").trim());
87154
87202
  process.kill(pid, "SIGTERM");
87155
87203
  removeDaemonPid(ref);
87156
87204
  return true;
@@ -87180,7 +87228,7 @@ var init_adhdev_daemon = __esm({
87180
87228
  init_version();
87181
87229
  init_src();
87182
87230
  init_runtime_defaults();
87183
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.13" });
87231
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.14" });
87184
87232
  AdhdevDaemon = class _AdhdevDaemon {
87185
87233
  localHttpServer = null;
87186
87234
  localWss = null;