omnius 1.0.556 → 1.0.558

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.
@@ -251,6 +251,41 @@ function tryHealth(port, cb) {
251
251
  req.end();
252
252
  }
253
253
 
254
+ function tryHealthIdentity(port, cb) {
255
+ var http = require("http");
256
+ var settled = false;
257
+ function done(version) {
258
+ if (settled) return;
259
+ settled = true;
260
+ cb(version);
261
+ }
262
+ var req = http.request(
263
+ { host: "127.0.0.1", port: port, path: "/health", method: "GET", timeout: 1500 },
264
+ function (res) {
265
+ var body = "";
266
+ res.setEncoding("utf8");
267
+ res.on("data", function (chunk) { body += chunk; });
268
+ res.on("end", function () {
269
+ if (res.statusCode !== 200) return done(null);
270
+ try {
271
+ var data = JSON.parse(body);
272
+ done(data.boot_version || data.version || null);
273
+ } catch (e) { done(null); }
274
+ });
275
+ }
276
+ );
277
+ req.on("timeout", function () { try { req.destroy(); } catch (e) {} done(null); });
278
+ req.on("error", function () { done(null); });
279
+ req.end();
280
+ }
281
+
282
+ function installedPackageVersion() {
283
+ try {
284
+ var pkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "package.json"), "utf8"));
285
+ return typeof pkg.version === "string" ? pkg.version : null;
286
+ } catch (e) { return null; }
287
+ }
288
+
254
289
  // Resolve the `omnius` launcher script.
255
290
  //
256
291
  // PRIORITY ORDER (most stable first):
@@ -316,13 +351,12 @@ function effectiveUser() {
316
351
  return process.env.USER || process.env.LOGNAME || os.userInfo().username;
317
352
  }
318
353
 
319
- // ─── Force-kill port holder (regardless of how it was launched) ────────────
354
+ // ─── Stop only an attested Omnius port holder ───────────────────────────────
320
355
  //
321
- // Critical for upgrade correctness: when an OLD daemon (started before this
322
- // install) is running, it holds port 11435 with stale in-memory code. The
323
- // systemctl/launchctl `restart` calls below CANNOT reach it because the
324
- // service manager doesn't own that process it was started detached by
325
- // `omnius serve --daemon` from a previous TUI session.
356
+ // Critical for upgrade correctness: when an OLD *Omnius* daemon started by a
357
+ // previous install holds port 11435, the new service cannot bind it. Do not
358
+ // treat every listener as disposable: postinstall runs with whatever rights
359
+ // npm was given, and an arbitrary process may legitimately own this port.
326
360
  //
327
361
  // Result without this kill: postinstall tries to start a NEW systemd
328
362
  // daemon, port-bind fails, old daemon stays alive serving stale code,
@@ -330,12 +364,25 @@ function effectiveUser() {
330
364
  //
331
365
  // Strategy (matches packages/cli/src/daemon.ts:forceKillDaemon):
332
366
  // 1. SIGTERM via known PID files (~/.omnius/daemon.pid + .omnius/nexus/daemon.pid)
333
- // 2. lsof / fuser port probe — find ANY other holder
367
+ // 2. lsof / fuser port probe — admit only a process whose cmdline proves it
368
+ // is `omnius ... serve --daemon`
334
369
  // 3. 2s graceful grace, then SIGKILL stragglers
335
370
  // 4. Poll /health up to 5s for confirmation
336
371
  //
337
372
  // Skips when OMNIUS_DISABLE_FORCE_KILL_DAEMON=1 (escape valve).
338
- function forceKillPortHolder(port, cb) {
373
+ function processCommandLine(pid) {
374
+ if (IS_WIN) return "";
375
+ try { return fs.readFileSync("/proc/" + pid + "/cmdline", "utf8").replace(/\0/g, " "); } catch (e) {}
376
+ return "";
377
+ }
378
+
379
+ function isAttestedOmniusDaemon(pid) {
380
+ var cmd = processCommandLine(pid);
381
+ return /(?:^|[\\/\s])omnius(?:[\\/\s]|$)|[\\/]omnius[\\/]dist[\\/]index\.js\b|launcher\.cjs\b/i.test(cmd) &&
382
+ /\bserve\b/.test(cmd) && /--daemon\b/.test(cmd);
383
+ }
384
+
385
+ function stopStaleAttestedDaemonPortHolder(port, cb) {
339
386
  if (process.env.OMNIUS_DISABLE_FORCE_KILL_DAEMON === "1") {
340
387
  log("OMNIUS_DISABLE_FORCE_KILL_DAEMON=1 — skipping port-holder kill (upgrades may not pick up new code).");
341
388
  return cb(0);
@@ -353,7 +400,8 @@ function forceKillPortHolder(port, cb) {
353
400
  if (!fs.existsSync(pidFile)) return;
354
401
  var n = parseInt(fs.readFileSync(pidFile, "utf8").trim(), 10);
355
402
  if (!n || n <= 0) return;
356
- try { process.kill(n, "SIGTERM"); killed++; log("SIGTERM old daemon (pid " + n + ", from " + pidFile + ")"); } catch (e) { /* dead */ }
403
+ if (!isAttestedOmniusDaemon(n)) return;
404
+ try { process.kill(n, "SIGTERM"); killed++; log("SIGTERM old Omnius daemon (pid " + n + ", from " + pidFile + ")"); } catch (e) { /* dead */ }
357
405
  } catch (e) { /* */ }
358
406
  });
359
407
 
@@ -370,7 +418,8 @@ function forceKillPortHolder(port, cb) {
370
418
  return Number.isFinite(n) && n > 0 && n !== process.pid;
371
419
  });
372
420
  pids.forEach(function (otherPid) {
373
- try { process.kill(otherPid, "SIGTERM"); killed++; log("SIGTERM port-holder (pid " + otherPid + ")"); } catch (e) { /* */ }
421
+ if (!isAttestedOmniusDaemon(otherPid)) return;
422
+ try { process.kill(otherPid, "SIGTERM"); killed++; log("SIGTERM attested Omnius port-holder (pid " + otherPid + ")"); } catch (e) { /* */ }
374
423
  });
375
424
  }
376
425
  } catch (e) { /* */ }
@@ -391,7 +440,8 @@ function forceKillPortHolder(port, cb) {
391
440
  return Number.isFinite(n) && n > 0 && n !== process.pid;
392
441
  });
393
442
  pids.forEach(function (otherPid) {
394
- try { process.kill(otherPid, "SIGKILL"); log("SIGKILL straggler (pid " + otherPid + ")"); } catch (e) { /* */ }
443
+ if (!isAttestedOmniusDaemon(otherPid)) return;
444
+ try { process.kill(otherPid, "SIGKILL"); log("SIGKILL attested Omnius straggler (pid " + otherPid + ")"); } catch (e) { /* */ }
395
445
  });
396
446
  }
397
447
  } catch (e) { /* */ }
@@ -415,6 +465,18 @@ function forceKillPortHolder(port, cb) {
415
465
  }, 2000);
416
466
  }
417
467
 
468
+ function stopAttestedDaemonPortHolder(port, cb) {
469
+ var targetVersion = installedPackageVersion();
470
+ if (!targetVersion) return stopStaleAttestedDaemonPortHolder(port, cb);
471
+ tryHealthIdentity(port, function (runningVersion) {
472
+ if (runningVersion === targetVersion) {
473
+ log("Omnius daemon already reports installed boot version " + targetVersion + " — preserving active run.");
474
+ return cb(0);
475
+ }
476
+ stopStaleAttestedDaemonPortHolder(port, cb);
477
+ });
478
+ }
479
+
418
480
  // ─── Nexus cleanup (preserve prior postinstall behaviour) ──────────────────
419
481
 
420
482
  function cleanNexus() {
@@ -479,6 +541,8 @@ function installSystemd(nodeBin, omniusScript, user) {
479
541
  "Documentation=https://github.com/robit-man/omnius",
480
542
  "After=network-online.target",
481
543
  "Wants=network-online.target",
544
+ "StartLimitIntervalSec=30",
545
+ "StartLimitBurst=10",
482
546
  "",
483
547
  "[Service]",
484
548
  "Type=simple",
@@ -492,8 +556,6 @@ function installSystemd(nodeBin, omniusScript, user) {
492
556
  // Pair with StartLimitIntervalSec to prevent thrash loops.
493
557
  "Restart=always",
494
558
  "RestartSec=3",
495
- "StartLimitIntervalSec=30",
496
- "StartLimitBurst=10",
497
559
  "StandardOutput=append:" + path.join(logDir, "daemon.log"),
498
560
  "StandardError=append:" + path.join(logDir, "daemon.err.log"),
499
561
  "",
@@ -856,14 +918,14 @@ function main() {
856
918
  return safeExit(0);
857
919
  }
858
920
 
859
- // Force-kill any process holding the daemon port BEFORE we try to install
921
+ // Stop an attested old Omnius daemon before we try to install
860
922
  // a service. This handles the orphan-detached-daemon case (started by
861
923
  // `omnius serve --daemon` from a previous TUI session) — systemctl/launchctl
862
924
  // restart can't reach it, so we have to clean up explicitly. Without this,
863
925
  // the new service-managed daemon fails to bind port 11435 and the user
864
926
  // ends up running stale in-memory code from the previous version.
865
927
  progress(5, INSTALL_STEPS, "Clearing daemon port");
866
- forceKillPortHolder(PORT, function (killedCount) {
928
+ stopAttestedDaemonPortHolder(PORT, function (killedCount) {
867
929
  if (killedCount > 0) {
868
930
  log("Killed " + killedCount + " stale daemon process(es) holding port " + PORT + ".");
869
931
  }
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "omnius",
3
- "version": "1.0.556",
3
+ "version": "1.0.558",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "omnius",
9
- "version": "1.0.556",
9
+ "version": "1.0.558",
10
10
  "bundleDependencies": [
11
11
  "image-to-ascii"
12
12
  ],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnius",
3
- "version": "1.0.556",
3
+ "version": "1.0.558",
4
4
  "description": "AI coding agent powered by open-source models (Ollama/vLLM) — interactive TUI with agentic tool-calling loop",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",