@zqagent/core 0.2.6 → 0.2.7

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.
@@ -555,7 +555,7 @@ import "dotenv/config";
555
555
 
556
556
  // src/server/runtime.ts
557
557
  init_esm_shims();
558
- import * as fs28 from "fs";
558
+ import * as fs29 from "fs";
559
559
  import * as path34 from "path";
560
560
 
561
561
  // src/server/store.ts
@@ -11396,7 +11396,7 @@ function buildNodeInfo(store, opts) {
11396
11396
  nodeId: opts.nodeId ?? ensureNodeId(store),
11397
11397
  platform: process.platform,
11398
11398
  mode: process.env.NODE_MODE ?? "standalone",
11399
- version: "0.2.6",
11399
+ version: "0.2.7",
11400
11400
  admin: opts.admin,
11401
11401
  projects: opts.projects
11402
11402
  };
@@ -12389,7 +12389,7 @@ function buildNodeHost(store, manager, diskPath) {
12389
12389
  arch: process.arch,
12390
12390
  release: os6.release(),
12391
12391
  uptimeSec: Math.round(os6.uptime()),
12392
- version: "0.2.6",
12392
+ version: "0.2.7",
12393
12393
  mode: process.env.NODE_MODE ?? "standalone",
12394
12394
  cpu: {
12395
12395
  count: cpus2.length,
@@ -13941,7 +13941,7 @@ function createApp(store, manager, opts = {}) {
13941
13941
  json(res, 200, {
13942
13942
  status: "ok",
13943
13943
  // 版本让运维/探针能确认线上跑的是哪个构建(更新与回滚据此判断)
13944
- version: "0.2.6",
13944
+ version: "0.2.7",
13945
13945
  features: { mcp: hasServerMcpConfig() }
13946
13946
  });
13947
13947
  return;
@@ -15644,7 +15644,7 @@ var FleetNodeBridge = class {
15644
15644
  label: this.opts.deps.store.loadNodeLabel() ?? void 0,
15645
15645
  platform: process.platform,
15646
15646
  mode: process.env.NODE_MODE ?? "standalone",
15647
- version: "0.2.6",
15647
+ version: "0.2.7",
15648
15648
  ip: primaryIp()
15649
15649
  };
15650
15650
  }
@@ -15699,7 +15699,7 @@ var FleetNodeBridge = class {
15699
15699
  label: this.opts.deps.store.loadNodeLabel() ?? void 0,
15700
15700
  platform: process.platform,
15701
15701
  mode: process.env.NODE_MODE ?? "standalone",
15702
- version: "0.2.6",
15702
+ version: "0.2.7",
15703
15703
  ip: primaryIp(),
15704
15704
  projects,
15705
15705
  totals,
@@ -17162,7 +17162,7 @@ async function hubEnrollByAccount(baseUrl, input) {
17162
17162
 
17163
17163
  // src/update/controller.ts
17164
17164
  init_esm_shims();
17165
- import * as fs27 from "fs";
17165
+ import * as fs28 from "fs";
17166
17166
  import * as path33 from "path";
17167
17167
 
17168
17168
  // src/update/downloader.ts
@@ -17415,10 +17415,11 @@ function selfCheck(binPath, expectedVersion) {
17415
17415
 
17416
17416
  // src/update/platform.ts
17417
17417
  init_esm_shims();
17418
+ import * as fs25 from "fs";
17418
17419
  import * as path30 from "path";
17419
17420
  import { createRequire as createRequire3 } from "module";
17420
17421
  function currentVersion() {
17421
- const injected = "0.2.6"?.trim();
17422
+ const injected = "0.2.7"?.trim();
17422
17423
  if (injected) return injected;
17423
17424
  try {
17424
17425
  const req2 = createRequire3(import.meta.url);
@@ -17433,9 +17434,33 @@ function isSeaRuntime() {
17433
17434
  const base = path30.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
17434
17435
  return base !== "node" && base !== "nodejs";
17435
17436
  }
17437
+ var DEFAULT_SERVICE_NAME = "zqagent";
17438
+ function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
17439
+ const unitName = `${serviceName}.service`;
17440
+ for (const line of cgroup.split("\n")) {
17441
+ const idx = line.lastIndexOf(":");
17442
+ if (idx < 0) continue;
17443
+ const unitPath = line.slice(idx + 1).trim();
17444
+ if (unitPath.split("/").includes(unitName)) return "systemd";
17445
+ }
17446
+ return null;
17447
+ }
17448
+ function detectServiceManager() {
17449
+ if (process.platform !== "linux") return null;
17450
+ const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
17451
+ try {
17452
+ return serviceManagerFromCgroup(
17453
+ fs25.readFileSync("/proc/self/cgroup", "utf8"),
17454
+ serviceName
17455
+ );
17456
+ } catch {
17457
+ return null;
17458
+ }
17459
+ }
17436
17460
  function serviceManager() {
17437
17461
  const v = process.env.ZQAGENT_SERVICE_MANAGER?.trim().toLowerCase();
17438
- return v === "systemd" || v === "launchd" ? v : null;
17462
+ if (v === "systemd" || v === "launchd") return v;
17463
+ return detectServiceManager();
17439
17464
  }
17440
17465
  function selfUpdateCapability(hasPublicKey) {
17441
17466
  if (!isSeaRuntime()) {
@@ -17458,12 +17483,12 @@ function selfUpdateCapability(hasPublicKey) {
17458
17483
 
17459
17484
  // src/update/installer.ts
17460
17485
  init_esm_shims();
17461
- import * as fs26 from "fs";
17486
+ import * as fs27 from "fs";
17462
17487
  import * as path32 from "path";
17463
17488
 
17464
17489
  // src/update/state.ts
17465
17490
  init_esm_shims();
17466
- import * as fs25 from "fs";
17491
+ import * as fs26 from "fs";
17467
17492
  import * as path31 from "path";
17468
17493
  function updatesDir(dataDir) {
17469
17494
  return path31.join(dataDir, "updates");
@@ -17473,7 +17498,7 @@ function statePath(dataDir) {
17473
17498
  }
17474
17499
  function loadState(dataDir) {
17475
17500
  try {
17476
- const raw = fs25.readFileSync(statePath(dataDir), "utf-8");
17501
+ const raw = fs26.readFileSync(statePath(dataDir), "utf-8");
17477
17502
  const parsed = JSON.parse(raw);
17478
17503
  if (typeof parsed === "object" && parsed !== null) return parsed;
17479
17504
  } catch {
@@ -17482,11 +17507,11 @@ function loadState(dataDir) {
17482
17507
  }
17483
17508
  function saveState(dataDir, state) {
17484
17509
  const dir = updatesDir(dataDir);
17485
- fs25.mkdirSync(dir, { recursive: true });
17510
+ fs26.mkdirSync(dir, { recursive: true });
17486
17511
  const file = statePath(dataDir);
17487
17512
  const tmp = `${file}.tmp`;
17488
- fs25.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
17489
- fs25.renameSync(tmp, file);
17513
+ fs26.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
17514
+ fs26.renameSync(tmp, file);
17490
17515
  }
17491
17516
  function patchState(dataDir, patch) {
17492
17517
  const next = { ...loadState(dataDir), ...patch };
@@ -17500,32 +17525,32 @@ function backupDir(dataDir) {
17500
17525
  }
17501
17526
  function backupCurrent(dataDir, execPath, version) {
17502
17527
  const dir = backupDir(dataDir);
17503
- fs26.mkdirSync(dir, { recursive: true });
17528
+ fs27.mkdirSync(dir, { recursive: true });
17504
17529
  const target = path32.join(dir, `zqagent-${version}${process.platform === "win32" ? ".exe" : ""}`);
17505
- fs26.copyFileSync(execPath, target);
17506
- fs26.chmodSync(target, 493);
17530
+ fs27.copyFileSync(execPath, target);
17531
+ fs27.chmodSync(target, 493);
17507
17532
  return target;
17508
17533
  }
17509
17534
  function replaceExecutable(execPath, stagedPath) {
17510
17535
  if (process.platform === "win32") {
17511
17536
  const oldPath = `${execPath}.old`;
17512
- fs26.rmSync(oldPath, { force: true });
17513
- fs26.renameSync(execPath, oldPath);
17514
- fs26.copyFileSync(stagedPath, execPath);
17515
- fs26.chmodSync(execPath, 493);
17537
+ fs27.rmSync(oldPath, { force: true });
17538
+ fs27.renameSync(execPath, oldPath);
17539
+ fs27.copyFileSync(stagedPath, execPath);
17540
+ fs27.chmodSync(execPath, 493);
17516
17541
  return;
17517
17542
  }
17518
17543
  const tmp = `${execPath}.new`;
17519
- fs26.rmSync(tmp, { force: true });
17544
+ fs27.rmSync(tmp, { force: true });
17520
17545
  try {
17521
- fs26.copyFileSync(stagedPath, tmp);
17522
- fs26.chmodSync(tmp, 493);
17523
- fs26.renameSync(tmp, execPath);
17546
+ fs27.copyFileSync(stagedPath, tmp);
17547
+ fs27.chmodSync(tmp, 493);
17548
+ fs27.renameSync(tmp, execPath);
17524
17549
  } catch (err) {
17525
- fs26.rmSync(tmp, { force: true });
17550
+ fs27.rmSync(tmp, { force: true });
17526
17551
  throw err;
17527
17552
  }
17528
- fs26.rmSync(stagedPath, { force: true });
17553
+ fs27.rmSync(stagedPath, { force: true });
17529
17554
  }
17530
17555
  function installStaged(opts) {
17531
17556
  const log = opts.log ?? (() => {
@@ -17552,18 +17577,18 @@ function rollback(dataDir, execPath, log = () => {
17552
17577
  }) {
17553
17578
  const state = readRollbackTarget(dataDir);
17554
17579
  if (!state?.backupPath || !state.backupVersion) return null;
17555
- if (!fs26.existsSync(state.backupPath)) return null;
17580
+ if (!fs27.existsSync(state.backupPath)) return null;
17556
17581
  log(`\u6B63\u5728\u56DE\u6EDA\u5230 v${state.backupVersion}`);
17557
17582
  if (process.platform === "win32") {
17558
- fs26.rmSync(`${execPath}.old`, { force: true });
17559
- fs26.renameSync(execPath, `${execPath}.old`);
17560
- fs26.copyFileSync(state.backupPath, execPath);
17561
- fs26.chmodSync(execPath, 493);
17583
+ fs27.rmSync(`${execPath}.old`, { force: true });
17584
+ fs27.renameSync(execPath, `${execPath}.old`);
17585
+ fs27.copyFileSync(state.backupPath, execPath);
17586
+ fs27.chmodSync(execPath, 493);
17562
17587
  } else {
17563
17588
  const tmp = `${execPath}.rollback`;
17564
- fs26.copyFileSync(state.backupPath, tmp);
17565
- fs26.chmodSync(tmp, 493);
17566
- fs26.renameSync(tmp, execPath);
17589
+ fs27.copyFileSync(state.backupPath, tmp);
17590
+ fs27.chmodSync(tmp, 493);
17591
+ fs27.renameSync(tmp, execPath);
17567
17592
  }
17568
17593
  patchState(dataDir, {
17569
17594
  pendingVersion: state.backupVersion,
@@ -17577,7 +17602,7 @@ function rollback(dataDir, execPath, log = () => {
17577
17602
  }
17578
17603
  function readRollbackTarget(dataDir) {
17579
17604
  try {
17580
- const raw = fs26.readFileSync(path32.join(updatesDir(dataDir), "state.json"), "utf-8");
17605
+ const raw = fs27.readFileSync(path32.join(updatesDir(dataDir), "state.json"), "utf-8");
17581
17606
  const s = JSON.parse(raw);
17582
17607
  if (s.backupPath && s.backupVersion) return s;
17583
17608
  } catch {
@@ -17660,7 +17685,7 @@ var UpdateController = class {
17660
17685
  reconcile() {
17661
17686
  const state = loadState(this.opts.dataDir);
17662
17687
  const current = this.currentVersion;
17663
- if (state.stagedPath && !fs27.existsSync(state.stagedPath)) {
17688
+ if (state.stagedPath && !fs28.existsSync(state.stagedPath)) {
17664
17689
  patchState(this.opts.dataDir, { stagedVersion: void 0, stagedPath: void 0 });
17665
17690
  }
17666
17691
  const patch = { runningVersion: current };
@@ -17675,7 +17700,7 @@ var UpdateController = class {
17675
17700
  }
17676
17701
  patchState(this.opts.dataDir, patch);
17677
17702
  if (process.platform === "win32") {
17678
- fs27.rmSync(`${process.execPath}.old`, { force: true });
17703
+ fs28.rmSync(`${process.execPath}.old`, { force: true });
17679
17704
  }
17680
17705
  }
17681
17706
  schedule(delayMs) {
@@ -17751,7 +17776,7 @@ var UpdateController = class {
17751
17776
  const bin = manifest.binaries[platformKey()];
17752
17777
  if (!bin) return `\u6E05\u5355\u6CA1\u6709\u5F53\u524D\u5E73\u53F0\uFF08${platformKey()}\uFF09\u7684\u4EA7\u7269`;
17753
17778
  let stagedPath = state.stagedPath;
17754
- if (!(state.stagedVersion === manifest.version && stagedPath && fs27.existsSync(stagedPath))) {
17779
+ if (!(state.stagedVersion === manifest.version && stagedPath && fs28.existsSync(stagedPath))) {
17755
17780
  stagedPath = path33.join(
17756
17781
  updatesDir(this.opts.dataDir),
17757
17782
  "staged",
@@ -17764,7 +17789,7 @@ var UpdateController = class {
17764
17789
  }
17765
17790
  const selfTest = selfCheck(stagedPath, manifest.version);
17766
17791
  if (!selfTest.ok) {
17767
- fs27.rmSync(stagedPath, { force: true });
17792
+ fs28.rmSync(stagedPath, { force: true });
17768
17793
  this.recordFailure(manifest.version, selfTest.error ?? "\u81EA\u68C0\u5931\u8D25");
17769
17794
  return `\u5B89\u88C5\u5305\u81EA\u68C0\u5931\u8D25\uFF1A${selfTest.error}`;
17770
17795
  }
@@ -17905,7 +17930,7 @@ function pemFile(key) {
17905
17930
  const p = env2(key);
17906
17931
  if (!p) return void 0;
17907
17932
  try {
17908
- return fs28.readFileSync(p);
17933
+ return fs29.readFileSync(p);
17909
17934
  } catch (e) {
17910
17935
  console.warn(`[tls] \u8BFB\u53D6 ${key}=${p} \u5931\u8D25: ${e instanceof Error ? e.message : e}`);
17911
17936
  return void 0;