omnius 1.0.965 → 1.0.967

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.
@@ -689,9 +689,24 @@ function cleanNexus() {
689
689
 
690
690
  // ─── Linux: systemd user unit ───────────────────────────────────────────────
691
691
 
692
- function hasSystemDaemonUnit() {
693
- if (!IS_LINUX) return false;
694
- return runCapture("systemctl show " + SERVICE_LABEL + ".service --property=LoadState --value").trim() === "loaded";
692
+ function userSystemctl(user) {
693
+ if (process.getuid && process.getuid() === 0 && user && user !== "root") {
694
+ var uid = runCapture("id -u " + shellQuote(user));
695
+ if (/^\d+$/.test(uid)) {
696
+ return "sudo -n -u " + shellQuote(user) + " XDG_RUNTIME_DIR=/run/user/" + uid +
697
+ " DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/" + uid + "/bus systemctl --user";
698
+ }
699
+ }
700
+ return "systemctl --user";
701
+ }
702
+
703
+ function discoverSystemdOwner(user, capture) {
704
+ if (!IS_LINUX) return null;
705
+ var request = " show " + SERVICE_LABEL + ".service --property=LoadState,ActiveState";
706
+ var system = capture("systemctl" + request);
707
+ if (/^LoadState=loaded$/m.test(system) && /^ActiveState=(active|activating|reloading|deactivating)$/m.test(system)) return "system";
708
+ if (/^LoadState=loaded$/m.test(capture(userSystemctl(user) + request))) return "user";
709
+ return /^LoadState=loaded$/m.test(system) ? "system" : null;
695
710
  }
696
711
 
697
712
  function installDesktopCompanion(nodeBin, omniusScript, user) {
@@ -734,9 +749,10 @@ function installDesktopCompanion(nodeBin, omniusScript, user) {
734
749
  // Linger is a one-time account setting. Re-requesting it on every update can
735
750
  // raise a polkit password prompt, so ask only when it is off and never
736
751
  // interactively; a missing grant is reported instead of prompting.
737
- function ensureLinger(user, prefix) {
738
- if (runCapture((prefix || "") + "loginctl show-user " + shellQuote(user) + " --property=Linger --value") === "yes") return;
739
- if (!runQuiet((prefix || "") + "loginctl --no-ask-password enable-linger " + shellQuote(user))) {
752
+ function ensureLinger(user) {
753
+ if (runCapture("loginctl show-user " + shellQuote(user) + " --property=Linger --value") === "yes") return;
754
+ var prefix = process.getuid && process.getuid() === 0 ? "" : "sudo -n ";
755
+ if (!runQuiet(prefix + "loginctl --no-ask-password enable-linger " + shellQuote(user))) {
740
756
  warn("User services stop at logout until linger is enabled once: loginctl enable-linger " + user);
741
757
  }
742
758
  }
@@ -766,7 +782,7 @@ function ensureDeclaredDaemonEnvironmentFiles(sysctl, userHome, user) {
766
782
  }
767
783
  }
768
784
 
769
- function installSystemd(nodeBin, omniusScript, user) {
785
+ function installSystemd(nodeBin, omniusScript, user, owner) {
770
786
  if (!IS_LINUX) return false;
771
787
  if (!hasCmd("systemctl")) {
772
788
  warn("systemctl not found — skipping systemd install.");
@@ -781,7 +797,7 @@ function installSystemd(nodeBin, omniusScript, user) {
781
797
  }
782
798
  } catch (e) {}
783
799
 
784
- if (hasSystemDaemonUnit()) {
800
+ if (owner === "system") {
785
801
  log("Native system daemon unit is installed; preserving its launcher and sole service ownership.");
786
802
  ensureDeclaredDaemonEnvironmentFiles("systemctl", userHome, user);
787
803
  return true;
@@ -861,23 +877,9 @@ function installSystemd(nodeBin, omniusScript, user) {
861
877
  return false;
862
878
  }
863
879
 
864
- // If we're root installing for another user, we need to wrap systemctl
865
- // calls in `sudo -u USER XDG_RUNTIME_DIR=/run/user/UID systemctl --user`.
866
- var asUserPrefix = "";
867
- if (!IS_WIN && process.getuid && process.getuid() === 0 && user !== "root") {
868
- // Try to resolve UID for the target user.
869
- var uid = runCapture("id -u " + user);
870
- if (uid && /^\d+$/.test(uid)) {
871
- // Ensure loginctl linger so user services can run without a session.
872
- ensureLinger(user);
873
- asUserPrefix = "sudo -u " + user + " XDG_RUNTIME_DIR=/run/user/" + uid + " DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/" + uid + "/bus ";
874
- }
875
- } else if (!IS_WIN && process.getuid && process.getuid() !== 0) {
876
- // Self-install: enable-linger ourselves if we can (best-effort; needs sudo on most distros).
877
- ensureLinger(user);
878
- }
879
-
880
- var sysctl = asUserPrefix + "systemctl --user";
880
+ // Linger is account setup. Existing unit updates only use the user manager.
881
+ if (!owner) ensureLinger(user);
882
+ var sysctl = userSystemctl(user);
881
883
  runQuiet(sysctl + " daemon-reload");
882
884
  ensureDeclaredDaemonEnvironmentFiles(sysctl, userHome, user);
883
885
  // A unit that previously failed (e.g. a missing EnvironmentFile) can be
@@ -1235,19 +1237,20 @@ function main() {
1235
1237
  // the new service-managed daemon fails to bind port 11435 and the user
1236
1238
  // ends up running stale in-memory code from the previous version.
1237
1239
  progress(6, INSTALL_STEPS, "Clearing daemon port");
1238
- if (hasSystemDaemonUnit()) {
1239
- log("Native system service owns daemon restart; skipping standalone process signals.");
1240
- return runMainAfterKill();
1240
+ var owner = discoverSystemdOwner(effectiveUser(), runCapture);
1241
+ if (owner) {
1242
+ log("The " + owner + " service owns daemon restart; skipping standalone process signals.");
1243
+ return runMainAfterKill(owner);
1241
1244
  }
1242
1245
  stopAttestedDaemonPortHolder(PORT, function (killedCount) {
1243
1246
  if (killedCount > 0) {
1244
1247
  log("Killed " + killedCount + " stale daemon process(es) holding port " + PORT + ".");
1245
1248
  }
1246
- runMainAfterKill();
1249
+ runMainAfterKill(owner);
1247
1250
  });
1248
1251
  }
1249
1252
 
1250
- function runMainAfterKill() {
1253
+ function runMainAfterKill(owner) {
1251
1254
  // Fast path: daemon already answering /health on the target port.
1252
1255
  // After forceKillPortHolder, this should be false unless a service manager
1253
1256
  // already auto-restarted (rare race). We still check so the rest of the
@@ -1285,7 +1288,7 @@ function runMainAfterKill() {
1285
1288
 
1286
1289
  var ok = false;
1287
1290
  if (IS_LINUX) {
1288
- ok = installSystemd(nodeBin, omniusScript, user);
1291
+ ok = installSystemd(nodeBin, omniusScript, user, owner);
1289
1292
  } else if (IS_MAC) {
1290
1293
  ok = installLaunchd(nodeBin, omniusScript, user);
1291
1294
  } else if (IS_WIN) {
@@ -5141,6 +5141,14 @@ var init_verificationRevision = __esm({
5141
5141
  }
5142
5142
  });
5143
5143
 
5144
+ // packages/execution/dist/focusedPythonAssertion.js
5145
+ var init_focusedPythonAssertion = __esm({
5146
+ "packages/execution/dist/focusedPythonAssertion.js"() {
5147
+ "use strict";
5148
+ init_verificationCommand();
5149
+ }
5150
+ });
5151
+
5144
5152
  // packages/execution/dist/system-auth.js
5145
5153
  var init_system_auth = __esm({
5146
5154
  "packages/execution/dist/system-auth.js"() {
@@ -5180,6 +5188,7 @@ var init_shell = __esm({
5180
5188
  init_verificationCommand();
5181
5189
  init_verificationPreviewReceipt();
5182
5190
  init_verificationRevision();
5191
+ init_focusedPythonAssertion();
5183
5192
  init_system_auth();
5184
5193
  init_shell_pipeline_status();
5185
5194
  init_shell_observation_only();
@@ -303936,6 +303945,7 @@ var init_dist5 = __esm({
303936
303945
  init_network_egress_policy();
303937
303946
  init_shell();
303938
303947
  init_verificationPreviewReceipt();
303948
+ init_verificationCommand();
303939
303949
  init_verificationRevision();
303940
303950
  init_native_operation_observation();
303941
303951
  init_native_memory_operation_observation();
@@ -304303,6 +304313,15 @@ var init_daemon_supervision = __esm({
304303
304313
  }
304304
304314
  });
304305
304315
 
304316
+ // packages/cli/src/daemon-service-authorization.ts
304317
+ var DaemonServiceAuthorizationError;
304318
+ var init_daemon_service_authorization = __esm({
304319
+ "packages/cli/src/daemon-service-authorization.ts"() {
304320
+ DaemonServiceAuthorizationError = class extends Error {
304321
+ };
304322
+ }
304323
+ });
304324
+
304306
304325
  // packages/cli/src/daemon-tray.ts
304307
304326
  var daemon_tray_exports = {};
304308
304327
  __export(daemon_tray_exports, {
@@ -304338,32 +304357,31 @@ function daemonSystemctlArgs(scope, args) {
304338
304357
  return scope === "user" ? ["--user", ...args] : args;
304339
304358
  }
304340
304359
  async function discoverManagedDaemonService(run2 = runDaemonServiceCommand, requestedScope) {
304341
- for (const scope of requestedScope ? [requestedScope] : ["system", "user"]) {
304360
+ const read = async (scope) => {
304342
304361
  const result = await run2("systemctl", daemonSystemctlArgs(scope, [
304343
304362
  "show",
304344
304363
  DAEMON_SERVICE_UNIT,
304345
- "--property=LoadState,ActiveState,UnitFileState,FragmentPath,User"
304364
+ "--property=LoadState,ActiveState,UnitFileState,FragmentPath,User,ControlGroup"
304346
304365
  ]), 5e3);
304347
- if (result.code !== 0) continue;
304366
+ if (result.code !== 0) return null;
304348
304367
  const values = Object.fromEntries(result.stdout.split(/\r?\n/).filter((line) => line.includes("=")).map((line) => {
304349
304368
  const at = line.indexOf("=");
304350
304369
  return [line.slice(0, at), line.slice(at + 1)];
304351
304370
  }));
304352
- if (values.LoadState !== "loaded") continue;
304371
+ if (values.LoadState !== "loaded") return null;
304353
304372
  return {
304354
304373
  scope,
304355
304374
  unit: DAEMON_SERVICE_UNIT,
304356
304375
  active: values.ActiveState || "unknown",
304357
304376
  enabled: values.UnitFileState || "unknown",
304358
304377
  fragmentPath: values.FragmentPath || "",
304359
- user: values.User || ""
304378
+ user: values.User || "",
304379
+ controlGroup: values.ControlGroup || void 0
304360
304380
  };
304361
- }
304362
- return null;
304363
- }
304364
- async function runManagedDaemonSystemctl(args, timeoutMs = 2e4) {
304365
- const service = await discoverManagedDaemonService();
304366
- return runDaemonServiceControl(service?.scope ?? "user", args, timeoutMs);
304381
+ };
304382
+ if (requestedScope) return read(requestedScope);
304383
+ const [system, user] = await Promise.all([read("system"), read("user")]);
304384
+ return system && serviceIsBusy(system.active) ? system : user ?? system;
304367
304385
  }
304368
304386
  function daemonOwnerAwareRunner(owner, run2 = runDaemonServiceCommand) {
304369
304387
  return (command, args, timeoutMs) => command === "systemctl" && args.includes("--user") && process.getuid?.() === 0 && owner && owner.uid !== 0 ? run2("runuser", [
@@ -304380,6 +304398,12 @@ function daemonOwnerAwareRunner(owner, run2 = runDaemonServiceCommand) {
304380
304398
  function serviceIsBusy(active) {
304381
304399
  return ["active", "activating", "reloading", "deactivating"].includes(active);
304382
304400
  }
304401
+ function daemonControlGroupContains(group, cgroup) {
304402
+ return Boolean(group && group !== "/" && cgroup.split(/\r?\n/).some((line) => {
304403
+ const path3 = line.slice(line.indexOf(":", line.indexOf(":") + 1) + 1);
304404
+ return path3 === group || path3.startsWith(`${group}/`);
304405
+ }));
304406
+ }
304383
304407
  async function assertNoCompetingDaemonService(scope, owner, run2 = runDaemonServiceCommand) {
304384
304408
  const other = await discoverManagedDaemonService(daemonOwnerAwareRunner(owner, run2), scope === "system" ? "user" : "system");
304385
304409
  if (other && serviceIsBusy(other.active)) throw new Error(`The ${other.scope} daemon unit is ${other.active}; stop/disable the old ${other.scope} unit first before starting the ${scope} daemon service. No existing service was stopped.`);
@@ -304421,9 +304445,14 @@ async function ensureManagedDaemonEnvironmentFiles(service, run2 = runDaemonServ
304421
304445
  }
304422
304446
  async function runDaemonServiceControl(scope, args, timeoutMs = 2e4, run2 = runDaemonServiceCommand) {
304423
304447
  const commandArgs = daemonSystemctlArgs(scope, ["--no-ask-password", ...args]);
304424
- const result = await run2("systemctl", commandArgs, timeoutMs);
304425
- if (result.code === 0 || scope !== "system" || process.getuid?.() === 0 || !["start", "stop", "restart", "enable", "disable", "reset-failed", "daemon-reload"].includes(args[0] || "")) return result;
304426
- return run2("sudo", ["-n", "systemctl", ...commandArgs], timeoutMs);
304448
+ if (scope !== "system" || process.getuid?.() === 0 || ["show", "status", "is-active", "is-enabled"].includes(args[0] || "")) {
304449
+ return run2("systemctl", commandArgs, timeoutMs);
304450
+ }
304451
+ const result = await run2("sudo", ["-n", "systemctl", ...commandArgs], timeoutMs);
304452
+ if (!result.available || result.code !== 0 && /^sudo:/m.test(result.stderr)) {
304453
+ throw new DaemonServiceAuthorizationError("System-owned Omnius daemon requires an existing noninteractive administrator grant. Run the update from the owning administrator context or migrate the daemon to user scope once.");
304454
+ }
304455
+ return result;
304427
304456
  }
304428
304457
  function quote(value) {
304429
304458
  if (/[\r\n\0]/.test(value)) throw new Error("Service values must not contain control characters");
@@ -304601,6 +304630,7 @@ async function daemonServiceAction(action, scope) {
304601
304630
  var DAEMON_SERVICE_UNIT, DAEMON_SERVICE_STOP_GRACE_MS, DAEMON_SERVICE_COMMAND_TIMEOUT_MS, runDaemonServiceCommand, daemonEnvironmentModule;
304602
304631
  var init_daemon_service = __esm({
304603
304632
  "packages/cli/src/daemon-service.ts"() {
304633
+ init_daemon_service_authorization();
304604
304634
  DAEMON_SERVICE_UNIT = "omnius-daemon.service";
304605
304635
  DAEMON_SERVICE_STOP_GRACE_MS = 12e4;
304606
304636
  DAEMON_SERVICE_COMMAND_TIMEOUT_MS = 13e4;
@@ -304849,18 +304879,19 @@ function runUtilityCommand(command, args, timeout) {
304849
304879
  timer.unref?.();
304850
304880
  });
304851
304881
  }
304852
- async function runUserSystemctl(args, timeout = 2e4) {
304882
+ async function runScopedSystemctl(scope, args, timeout = 2e4) {
304853
304883
  const commandTimeout = ["stop", "restart", "start"].includes(args[0] || "") ? Math.max(timeout, DAEMON_SERVICE_COMMAND_TIMEOUT_MS) : timeout;
304854
- const result = await runManagedDaemonSystemctl(args, commandTimeout);
304884
+ const result = await runDaemonServiceControl(scope, args, commandTimeout);
304855
304885
  return { available: result.available, ok: result.code === 0 };
304856
304886
  }
304857
- async function readUserSystemctl(args, timeout = 5e3) {
304858
- const result = await runManagedDaemonSystemctl(args, timeout);
304887
+ async function readDaemonServiceEnvironment(scope) {
304888
+ const result = await runDaemonServiceControl(
304889
+ scope,
304890
+ ["show", "omnius-daemon.service", "--property", "Environment", "--value"],
304891
+ 5e3
304892
+ );
304859
304893
  return result.code === 0 ? result.stdout.trim() : null;
304860
304894
  }
304861
- async function hasManagedDaemonService() {
304862
- return await discoverManagedDaemonService() !== null;
304863
- }
304864
304895
  function daemonPortFromServiceEnvironment(value) {
304865
304896
  const host = value.match(/(?:^|\s)OMNIUS_HOST=(?:"([^"]+)"|'([^']+)'|([^\s]+))/)?.slice(1).find(Boolean);
304866
304897
  const direct = value.match(/(?:^|\s)OMNIUS_PORT=(?:"(\d+)"|'(\d+)'|(\d+))/)?.slice(1).find(Boolean);
@@ -304873,17 +304904,18 @@ function daemonServiceMatchesPort(requestedPort, effectiveEnvironment) {
304873
304904
  const effectivePort = daemonPortFromServiceEnvironment(effectiveEnvironment);
304874
304905
  return effectivePort === null ? requestedPort === DEFAULT_PORT2 : effectivePort === requestedPort;
304875
304906
  }
304876
- async function managedDaemonServiceMatchesPort(port) {
304877
- if (!await hasManagedDaemonService()) return false;
304878
- const environment = await readUserSystemctl([
304879
- "show",
304880
- "omnius-daemon.service",
304881
- "--property",
304882
- "Environment",
304883
- "--value"
304884
- ]);
304885
- if (environment === null) return false;
304886
- return daemonServiceMatchesPort(port, environment);
304907
+ async function discoverDaemonServiceAtPort(port, scope) {
304908
+ const service = await discoverManagedDaemonService(void 0, scope);
304909
+ if (!service) return null;
304910
+ const matches = async (candidate) => {
304911
+ const environment = await readDaemonServiceEnvironment(candidate.scope);
304912
+ return environment !== null && daemonServiceMatchesPort(port, environment);
304913
+ };
304914
+ const declared = await matches(service) ? service : null;
304915
+ if (scope || declared && await scopedDaemonServiceOwnsPort(declared, port)) return declared;
304916
+ const other = await discoverManagedDaemonService(void 0, service.scope === "system" ? "user" : "system");
304917
+ if (other && await matches(other) && await scopedDaemonServiceOwnsPort(other, port)) return other;
304918
+ return declared;
304887
304919
  }
304888
304920
  function pidIsInManagedDaemonUnit(pid, readCgroup = defaultReadProcCgroup) {
304889
304921
  const cgroup = readCgroup(pid);
@@ -304906,18 +304938,23 @@ async function managedDaemonServiceOwnsPort(port, dependencies = {
304906
304938
  if (uniqueHolders.length === 0) return true;
304907
304939
  return uniqueHolders.every((pid) => dependencies.pidInUnit(pid));
304908
304940
  }
304909
- async function repairManagedDaemonUnit(port, preferredEntrypoint) {
304941
+ function scopedDaemonServiceOwnsPort(service, port) {
304942
+ return managedDaemonServiceOwnsPort(port, {
304943
+ holderPids: portHolderPids,
304944
+ pidInUnit: (pid) => daemonControlGroupContains(service.controlGroup, defaultReadProcCgroup(pid) ?? "")
304945
+ });
304946
+ }
304947
+ async function repairManagedDaemonUnit(managed, port, preferredEntrypoint) {
304910
304948
  if (process.platform !== "linux") return false;
304911
304949
  const command = await resolveDaemonCommand(process.execPath, preferredEntrypoint);
304912
304950
  if (!command) return false;
304913
304951
  try {
304914
- const managed = await discoverManagedDaemonService();
304915
- const scope = managed?.scope ?? "user";
304952
+ const scope = managed.scope;
304916
304953
  if (scope === "system" && process.getuid?.() !== 0) return false;
304917
304954
  if (command.args[0] === "serve") return false;
304918
304955
  const definition = await resolveDaemonServiceDefinition({
304919
304956
  scope,
304920
- user: managed?.user || void 0,
304957
+ user: managed.user || void 0,
304921
304958
  entrypoint: command.args[0],
304922
304959
  nodePath: command.command,
304923
304960
  port,
@@ -304926,12 +304963,15 @@ async function repairManagedDaemonUnit(port, preferredEntrypoint) {
304926
304963
  const unitDir = scope === "system" ? "/etc/systemd/system" : join15(definition.homeDir, ".config", "systemd", "user");
304927
304964
  const unitPath = join15(unitDir, "omnius-daemon.service");
304928
304965
  mkdirSync6(unitDir, { recursive: true });
304929
- const priorUnitPath = managed?.fragmentPath || unitPath;
304930
- const unit = existsSync7(priorUnitPath) ? repairDaemonSystemdUnit(readFileSync6(priorUnitPath, "utf8"), definition) : buildDaemonSystemdUnit(definition);
304931
- const tmp = `${unitPath}.tmp.${process.pid}.${Date.now()}`;
304932
- writeFileSync4(tmp, unit, { encoding: "utf8", mode: 384 });
304933
- renameSync4(tmp, unitPath);
304934
- return (await runUserSystemctl(["daemon-reload"], 1e4)).ok;
304966
+ const priorUnitPath = managed.fragmentPath || unitPath;
304967
+ const priorUnit = existsSync7(priorUnitPath) ? readFileSync6(priorUnitPath, "utf8") : null;
304968
+ const unit = priorUnit === null ? buildDaemonSystemdUnit(definition) : repairDaemonSystemdUnit(priorUnit, definition);
304969
+ if (priorUnitPath !== unitPath || priorUnit !== unit) {
304970
+ const tmp = `${unitPath}.tmp.${process.pid}.${Date.now()}`;
304971
+ writeFileSync4(tmp, unit, { encoding: "utf8", mode: 384 });
304972
+ renameSync4(tmp, unitPath);
304973
+ }
304974
+ return (await runScopedSystemctl(scope, ["daemon-reload"], 1e4)).ok;
304935
304975
  } catch {
304936
304976
  return false;
304937
304977
  }
@@ -305089,34 +305129,39 @@ async function reclaimOwnedDaemonListener(port = getDaemonPort(), dependencies =
305089
305129
  }
305090
305130
  return { ok: true, action: "cleared", port, clearedPids, blockedPids: [] };
305091
305131
  }
305092
- async function restartDaemon(port, expectedVersion, preferredEntrypoint) {
305132
+ async function restartDaemon(port, expectedVersion, preferredEntrypoint, serviceScope) {
305093
305133
  const p = port ?? getDaemonPort();
305094
305134
  const supervision = readDaemonSupervisionHealth(p);
305095
305135
  if (supervision.degraded && supervision.retryAfterMs > 0) return false;
305096
- const managed = await managedDaemonServiceMatchesPort(p);
305136
+ const managed = serviceScope === null ? null : await discoverDaemonServiceAtPort(p, serviceScope);
305137
+ if (serviceScope && !managed) return false;
305097
305138
  if (managed) {
305098
- if (!await managedDaemonServiceOwnsPort(p)) {
305139
+ if (!await scopedDaemonServiceOwnsPort(managed, p)) {
305140
+ const holders = await portHolderPids(p);
305141
+ if (!holders || holders.some((pid2) => pidIsInManagedDaemonUnit(pid2))) return false;
305099
305142
  const reclaimed2 = await reclaimOwnedDaemonListener(p);
305100
305143
  if (!reclaimed2.ok) return false;
305101
305144
  await reclaimStaleDaemonEndpointClaim(p, new Set(reclaimed2.clearedPids));
305102
305145
  }
305146
+ const scope = managed.scope;
305103
305147
  try {
305104
- await ensureManagedDaemonEnvironmentFiles();
305148
+ await ensureManagedDaemonEnvironmentFiles(managed);
305105
305149
  } catch {
305106
305150
  }
305107
- await runUserSystemctl(["reset-failed", "omnius-daemon.service"]);
305108
- const restarted = await runUserSystemctl(["restart", "omnius-daemon.service"]);
305151
+ const repairedBeforeRestart = Boolean(preferredEntrypoint && await repairManagedDaemonUnit(managed, p, preferredEntrypoint));
305152
+ await runScopedSystemctl(scope, ["reset-failed", "omnius-daemon.service"]);
305153
+ const restarted = await runScopedSystemctl(scope, ["restart", "omnius-daemon.service"]);
305109
305154
  if (restarted.ok && (await waitForDaemonReady(p, expectedVersion)).ok) return true;
305110
- const repaired = await repairManagedDaemonUnit(p, preferredEntrypoint);
305155
+ const repaired = !repairedBeforeRestart && await repairManagedDaemonUnit(managed, p, preferredEntrypoint);
305111
305156
  if (repaired) {
305112
- await runUserSystemctl(["stop", "omnius-daemon.service"]);
305157
+ await runScopedSystemctl(scope, ["stop", "omnius-daemon.service"]);
305113
305158
  await waitForDaemonStopped(p);
305114
- await runUserSystemctl(["reset-failed", "omnius-daemon.service"]);
305115
- const started = await runUserSystemctl(["start", "omnius-daemon.service"]);
305159
+ await runScopedSystemctl(scope, ["reset-failed", "omnius-daemon.service"]);
305160
+ const started = await runScopedSystemctl(scope, ["start", "omnius-daemon.service"]);
305116
305161
  if (started.ok && (await waitForDaemonReady(p, expectedVersion)).ok) return true;
305117
305162
  }
305118
- if (await reinstallUserDaemonService(p, expectedVersion, preferredEntrypoint)) return true;
305119
- await runUserSystemctl(["stop", "omnius-daemon.service"]);
305163
+ if (scope === "user" && await reinstallUserDaemonService(p, expectedVersion, preferredEntrypoint)) return true;
305164
+ await runScopedSystemctl(scope, ["stop", "omnius-daemon.service"]);
305120
305165
  if (!await waitForDaemonStopped(p)) {
305121
305166
  const reclaimed2 = await reclaimOwnedDaemonListener(p);
305122
305167
  if (!reclaimed2.ok) return false;
@@ -305171,7 +305216,7 @@ async function resolveDaemonCommand(nodeExe, preferredEntrypoint) {
305171
305216
  async function reinstallUserDaemonService(port, expectedVersion, preferredEntrypoint) {
305172
305217
  if (process.platform !== "linux" || process.getuid?.() === 0) return false;
305173
305218
  try {
305174
- if ((await discoverManagedDaemonService())?.scope !== "user") return false;
305219
+ if (!await discoverDaemonServiceAtPort(port, "user")) return false;
305175
305220
  const command = await resolveDaemonCommand(process.execPath, preferredEntrypoint);
305176
305221
  if (!command || command.args[0] === "serve") return false;
305177
305222
  await installDaemonService({
@@ -305184,7 +305229,7 @@ async function reinstallUserDaemonService(port, expectedVersion, preferredEntryp
305184
305229
  enable: true,
305185
305230
  start: false
305186
305231
  });
305187
- await runUserSystemctl(["stop", "omnius-daemon.service"]);
305232
+ await runScopedSystemctl("user", ["stop", "omnius-daemon.service"]);
305188
305233
  await waitForDaemonStopped(port);
305189
305234
  await daemonServiceAction("start", "user");
305190
305235
  return (await waitForDaemonReady(port, expectedVersion)).ok;
@@ -305259,28 +305304,29 @@ async function startDaemon(port = getDaemonPort(), preferredEntrypoint) {
305259
305304
  }
305260
305305
  }
305261
305306
  }
305262
- async function stopDaemonAtPort(port = getDaemonPort(), dependencies = DEFAULT_DAEMON_STOP_DEPENDENCIES) {
305263
- if (await dependencies.managedServiceMatchesPort(port)) {
305264
- const stopped = await dependencies.stopManagedService();
305265
- if (stopped && await dependencies.waitForStopped(port)) return true;
305266
- }
305267
- const reclaimed = await dependencies.reclaimListener(port);
305307
+ async function stopDaemonAtPort(port = getDaemonPort(), dependencies) {
305308
+ const deps = dependencies ?? daemonStopDependencies(await discoverDaemonServiceAtPort(port));
305309
+ if (await deps.managedServiceMatchesPort(port)) return await deps.stopManagedService() && await deps.waitForStopped(port);
305310
+ const reclaimed = await deps.reclaimListener(port);
305268
305311
  if (!reclaimed.ok) return false;
305269
- const claimCleared = await dependencies.reclaimClaim(
305312
+ const claimCleared = await deps.reclaimClaim(
305270
305313
  port,
305271
305314
  new Set(reclaimed.clearedPids)
305272
305315
  );
305273
- return claimCleared && dependencies.waitForStopped(port);
305316
+ return claimCleared && deps.waitForStopped(port);
305274
305317
  }
305275
- async function quiesceDaemonForUpdate(port = getDaemonPort()) {
305276
- return stopDaemonAtPort(port);
305318
+ async function quiesceDaemonForUpdate(port = getDaemonPort(), scope) {
305319
+ const managed = scope === null ? null : await discoverDaemonServiceAtPort(port, scope);
305320
+ if (scope && !managed) return false;
305321
+ return stopDaemonAtPort(port, daemonStopDependencies(managed));
305277
305322
  }
305278
- var OMNIUS_DIR, PID_FILE, DEFAULT_PORT2, LOCK_INITIALIZATION_GRACE_MS, DAEMON_GRACEFUL_STOP_ATTEMPTS, DEFAULT_RECLAIM_DEPENDENCIES, DEFAULT_CLAIM_RECLAIM_DEPENDENCIES, DEFAULT_DAEMON_STOP_DEPENDENCIES;
305323
+ var OMNIUS_DIR, PID_FILE, DEFAULT_PORT2, LOCK_INITIALIZATION_GRACE_MS, DAEMON_GRACEFUL_STOP_ATTEMPTS, DEFAULT_RECLAIM_DEPENDENCIES, DEFAULT_CLAIM_RECLAIM_DEPENDENCIES, daemonStopDependencies;
305279
305324
  var init_daemon = __esm({
305280
305325
  "packages/cli/src/daemon.ts"() {
305281
305326
  init_dist5();
305282
305327
  init_daemon_supervision();
305283
305328
  init_daemon_service();
305329
+ init_daemon_service_authorization();
305284
305330
  OMNIUS_DIR = process.env["OMNIUS_HOME"]?.trim() || join15(homedir15(), ".omnius");
305285
305331
  PID_FILE = join15(OMNIUS_DIR, "daemon.pid");
305286
305332
  DEFAULT_PORT2 = 11435;
@@ -305301,13 +305347,17 @@ var init_daemon = __esm({
305301
305347
  stopLease: (leaseId, port) => stopDaemonLeaseGracefully(leaseId, `stale daemon endpoint claim on port ${port}`),
305302
305348
  removeLockIfUnchanged: (port, expected) => removeDaemonLockIfUnchanged(port, expected)
305303
305349
  };
305304
- DEFAULT_DAEMON_STOP_DEPENDENCIES = {
305305
- managedServiceMatchesPort: (port) => managedDaemonServiceMatchesPort(port),
305306
- stopManagedService: async () => (await runUserSystemctl(["stop", "omnius-daemon.service"])).ok,
305350
+ daemonStopDependencies = (managed) => ({
305351
+ managedServiceMatchesPort: async (port) => Boolean(managed && await scopedDaemonServiceOwnsPort(managed, port)),
305352
+ stopManagedService: async () => Boolean(managed && (await runScopedSystemctl(managed.scope, ["stop", managed.unit])).ok),
305307
305353
  waitForStopped: (port) => waitForDaemonStopped(port),
305308
- reclaimListener: (port) => reclaimOwnedDaemonListener(port),
305354
+ reclaimListener: async (port) => {
305355
+ const holders = await portHolderPids(port);
305356
+ const unitPids = holders?.filter((pid) => pidIsInManagedDaemonUnit(pid));
305357
+ return unitPids?.length ? { ok: false, action: "blocked", port, clearedPids: [], blockedPids: unitPids, reason: "Listener belongs to a different systemd service scope" } : reclaimOwnedDaemonListener(port);
305358
+ },
305309
305359
  reclaimClaim: (port, verifiedStoppedPids) => reclaimStaleDaemonEndpointClaim(port, verifiedStoppedPids)
305310
- };
305360
+ });
305311
305361
  }
305312
305362
  });
305313
305363
 
@@ -305395,6 +305445,9 @@ function compareOmniusVersions(left, right) {
305395
305445
  return 0;
305396
305446
  }
305397
305447
 
305448
+ // packages/cli/src/update-service.ts
305449
+ init_daemon_service_authorization();
305450
+
305398
305451
  // packages/cli/src/user-systemd-environment.ts
305399
305452
  import { lstatSync as lstatSync2 } from "node:fs";
305400
305453
  function userManagerEnvironment(env, uid = process.getuid?.(), inspect = lstatSync2) {
@@ -306471,7 +306524,8 @@ async function quiesceDaemonWithRetry(quiesce, attempts = 3, pauseMs = 250) {
306471
306524
  for (let attempt = 1; attempt <= boundedAttempts; attempt++) {
306472
306525
  try {
306473
306526
  if (await quiesce()) return true;
306474
- } catch {
306527
+ } catch (error) {
306528
+ if (error instanceof DaemonServiceAuthorizationError) throw error;
306475
306529
  }
306476
306530
  if (attempt < boundedAttempts && pauseMs > 0) {
306477
306531
  await new Promise((resolve13) => setTimeout(resolve13, pauseMs));
@@ -307959,13 +308013,17 @@ async function runUpdateWorkerRuntime(state, paths, endpoint) {
307959
308013
  const port = Number(new URL(endpoint).port || "11435");
307960
308014
  const trayWasRunning = state.tray_was_running || !cancellation.signal.aborted && (await getTrayStatus(endpoint)).running;
307961
308015
  state.tray_was_running = trayWasRunning;
308016
+ let daemonScope;
307962
308017
  const finalState = await runVerifiedUpdateTransaction(
307963
308018
  state,
307964
308019
  {
307965
- quiesceDaemon: () => quiesceDaemonForUpdate(port),
307966
- restartDaemon: (expected, executable) => restartDaemon(port, expected, executable),
308020
+ quiesceDaemon: async () => {
308021
+ if (daemonScope === void 0) daemonScope = (await discoverDaemonServiceAtPort(port))?.scope ?? null;
308022
+ return quiesceDaemonForUpdate(port, daemonScope);
308023
+ },
308024
+ restartDaemon: (expected, executable) => restartDaemon(port, expected, executable, daemonScope),
307967
308025
  recoverDaemon: async () => {
307968
- await restartDaemon(port);
308026
+ await restartDaemon(port, void 0, void 0, daemonScope);
307969
308027
  return Boolean(await getDaemonReportedIdentity(port));
307970
308028
  },
307971
308029
  observeDaemon: async () => {
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "omnius",
3
- "version": "1.0.965",
3
+ "version": "1.0.967",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "omnius",
9
- "version": "1.0.965",
9
+ "version": "1.0.967",
10
10
  "hasInstallScript": true,
11
11
  "license": "CC-BY-NC-4.0",
12
12
  "dependencies": {
@@ -7880,9 +7880,9 @@
7880
7880
  }
7881
7881
  },
7882
7882
  "node_modules/jose": {
7883
- "version": "6.2.17",
7884
- "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.17.tgz",
7885
- "integrity": "sha512-wOuK9V1yujQFH5S0ZWmLcDZN7+IKh9bUCC2ZPCf2HDlol3WWHy+PPyNjEI75FXRLMp3vDKQcupP59xhVU95hcg==",
7883
+ "version": "6.2.18",
7884
+ "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.18.tgz",
7885
+ "integrity": "sha512-doV4thUwgkrycJH4yLeqwTGIIZphHl+pk7CPReuMIhYhncmgzdko85MaCG4YQFTxqMFr1/oEH32tZuKKovcDEg==",
7886
7886
  "license": "MIT",
7887
7887
  "funding": {
7888
7888
  "url": "https://github.com/sponsors/panva"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnius",
3
- "version": "1.0.965",
3
+ "version": "1.0.967",
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/library.js",