@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.
@@ -569,7 +569,7 @@ var init_wire = __esm({
569
569
  // src/cli/index.ts
570
570
  init_cjs_shims();
571
571
  var import_config = require("dotenv/config");
572
- var fs33 = __toESM(require("fs"), 1);
572
+ var fs34 = __toESM(require("fs"), 1);
573
573
  var readline2 = __toESM(require("readline"), 1);
574
574
  var path42 = __toESM(require("path"), 1);
575
575
  var import_child_process = require("child_process");
@@ -11187,7 +11187,7 @@ init_cjs_shims();
11187
11187
 
11188
11188
  // src/server/runtime.ts
11189
11189
  init_cjs_shims();
11190
- var fs30 = __toESM(require("fs"), 1);
11190
+ var fs31 = __toESM(require("fs"), 1);
11191
11191
  var path37 = __toESM(require("path"), 1);
11192
11192
 
11193
11193
  // src/server/session.ts
@@ -13579,7 +13579,7 @@ function buildNodeInfo(store, opts) {
13579
13579
  nodeId: opts.nodeId ?? ensureNodeId2(store),
13580
13580
  platform: process.platform,
13581
13581
  mode: process.env.NODE_MODE ?? "standalone",
13582
- version: "0.2.6",
13582
+ version: "0.2.7",
13583
13583
  admin: opts.admin,
13584
13584
  projects: opts.projects
13585
13585
  };
@@ -14572,7 +14572,7 @@ function buildNodeHost(store, manager, diskPath) {
14572
14572
  arch: process.arch,
14573
14573
  release: os6.release(),
14574
14574
  uptimeSec: Math.round(os6.uptime()),
14575
- version: "0.2.6",
14575
+ version: "0.2.7",
14576
14576
  mode: process.env.NODE_MODE ?? "standalone",
14577
14577
  cpu: {
14578
14578
  count: cpus2.length,
@@ -16124,7 +16124,7 @@ function createApp(store, manager, opts = {}) {
16124
16124
  json(res, 200, {
16125
16125
  status: "ok",
16126
16126
  // 版本让运维/探针能确认线上跑的是哪个构建(更新与回滚据此判断)
16127
- version: "0.2.6",
16127
+ version: "0.2.7",
16128
16128
  features: { mcp: hasServerMcpConfig() }
16129
16129
  });
16130
16130
  return;
@@ -17762,7 +17762,7 @@ var FleetNodeBridge = class {
17762
17762
  label: this.opts.deps.store.loadNodeLabel() ?? void 0,
17763
17763
  platform: process.platform,
17764
17764
  mode: process.env.NODE_MODE ?? "standalone",
17765
- version: "0.2.6",
17765
+ version: "0.2.7",
17766
17766
  ip: primaryIp()
17767
17767
  };
17768
17768
  }
@@ -17817,7 +17817,7 @@ var FleetNodeBridge = class {
17817
17817
  label: this.opts.deps.store.loadNodeLabel() ?? void 0,
17818
17818
  platform: process.platform,
17819
17819
  mode: process.env.NODE_MODE ?? "standalone",
17820
- version: "0.2.6",
17820
+ version: "0.2.7",
17821
17821
  ip: primaryIp(),
17822
17822
  projects,
17823
17823
  totals,
@@ -19228,7 +19228,7 @@ var PairingCodeStore = class {
19228
19228
 
19229
19229
  // src/update/controller.ts
19230
19230
  init_cjs_shims();
19231
- var fs29 = __toESM(require("fs"), 1);
19231
+ var fs30 = __toESM(require("fs"), 1);
19232
19232
  var path36 = __toESM(require("path"), 1);
19233
19233
 
19234
19234
  // src/update/downloader.ts
@@ -19481,10 +19481,11 @@ function selfCheck(binPath, expectedVersion) {
19481
19481
 
19482
19482
  // src/update/platform.ts
19483
19483
  init_cjs_shims();
19484
+ var fs27 = __toESM(require("fs"), 1);
19484
19485
  var path33 = __toESM(require("path"), 1);
19485
19486
  var import_node_module3 = require("module");
19486
19487
  function currentVersion() {
19487
- const injected = "0.2.6"?.trim();
19488
+ const injected = "0.2.7"?.trim();
19488
19489
  if (injected) return injected;
19489
19490
  try {
19490
19491
  const req2 = (0, import_node_module3.createRequire)(importMetaUrl);
@@ -19499,9 +19500,33 @@ function isSeaRuntime() {
19499
19500
  const base = path33.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
19500
19501
  return base !== "node" && base !== "nodejs";
19501
19502
  }
19503
+ var DEFAULT_SERVICE_NAME = "zqagent";
19504
+ function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
19505
+ const unitName = `${serviceName}.service`;
19506
+ for (const line of cgroup.split("\n")) {
19507
+ const idx = line.lastIndexOf(":");
19508
+ if (idx < 0) continue;
19509
+ const unitPath = line.slice(idx + 1).trim();
19510
+ if (unitPath.split("/").includes(unitName)) return "systemd";
19511
+ }
19512
+ return null;
19513
+ }
19514
+ function detectServiceManager() {
19515
+ if (process.platform !== "linux") return null;
19516
+ const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
19517
+ try {
19518
+ return serviceManagerFromCgroup(
19519
+ fs27.readFileSync("/proc/self/cgroup", "utf8"),
19520
+ serviceName
19521
+ );
19522
+ } catch {
19523
+ return null;
19524
+ }
19525
+ }
19502
19526
  function serviceManager() {
19503
19527
  const v = process.env.ZQAGENT_SERVICE_MANAGER?.trim().toLowerCase();
19504
- return v === "systemd" || v === "launchd" ? v : null;
19528
+ if (v === "systemd" || v === "launchd") return v;
19529
+ return detectServiceManager();
19505
19530
  }
19506
19531
  function selfUpdateCapability(hasPublicKey) {
19507
19532
  if (!isSeaRuntime()) {
@@ -19524,12 +19549,12 @@ function selfUpdateCapability(hasPublicKey) {
19524
19549
 
19525
19550
  // src/update/installer.ts
19526
19551
  init_cjs_shims();
19527
- var fs28 = __toESM(require("fs"), 1);
19552
+ var fs29 = __toESM(require("fs"), 1);
19528
19553
  var path35 = __toESM(require("path"), 1);
19529
19554
 
19530
19555
  // src/update/state.ts
19531
19556
  init_cjs_shims();
19532
- var fs27 = __toESM(require("fs"), 1);
19557
+ var fs28 = __toESM(require("fs"), 1);
19533
19558
  var path34 = __toESM(require("path"), 1);
19534
19559
  function updatesDir(dataDir) {
19535
19560
  return path34.join(dataDir, "updates");
@@ -19539,7 +19564,7 @@ function statePath(dataDir) {
19539
19564
  }
19540
19565
  function loadState(dataDir) {
19541
19566
  try {
19542
- const raw = fs27.readFileSync(statePath(dataDir), "utf-8");
19567
+ const raw = fs28.readFileSync(statePath(dataDir), "utf-8");
19543
19568
  const parsed = JSON.parse(raw);
19544
19569
  if (typeof parsed === "object" && parsed !== null) return parsed;
19545
19570
  } catch {
@@ -19548,11 +19573,11 @@ function loadState(dataDir) {
19548
19573
  }
19549
19574
  function saveState(dataDir, state) {
19550
19575
  const dir = updatesDir(dataDir);
19551
- fs27.mkdirSync(dir, { recursive: true });
19576
+ fs28.mkdirSync(dir, { recursive: true });
19552
19577
  const file = statePath(dataDir);
19553
19578
  const tmp = `${file}.tmp`;
19554
- fs27.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
19555
- fs27.renameSync(tmp, file);
19579
+ fs28.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
19580
+ fs28.renameSync(tmp, file);
19556
19581
  }
19557
19582
  function patchState(dataDir, patch) {
19558
19583
  const next = { ...loadState(dataDir), ...patch };
@@ -19566,32 +19591,32 @@ function backupDir(dataDir) {
19566
19591
  }
19567
19592
  function backupCurrent(dataDir, execPath, version) {
19568
19593
  const dir = backupDir(dataDir);
19569
- fs28.mkdirSync(dir, { recursive: true });
19594
+ fs29.mkdirSync(dir, { recursive: true });
19570
19595
  const target = path35.join(dir, `zqagent-${version}${process.platform === "win32" ? ".exe" : ""}`);
19571
- fs28.copyFileSync(execPath, target);
19572
- fs28.chmodSync(target, 493);
19596
+ fs29.copyFileSync(execPath, target);
19597
+ fs29.chmodSync(target, 493);
19573
19598
  return target;
19574
19599
  }
19575
19600
  function replaceExecutable(execPath, stagedPath) {
19576
19601
  if (process.platform === "win32") {
19577
19602
  const oldPath = `${execPath}.old`;
19578
- fs28.rmSync(oldPath, { force: true });
19579
- fs28.renameSync(execPath, oldPath);
19580
- fs28.copyFileSync(stagedPath, execPath);
19581
- fs28.chmodSync(execPath, 493);
19603
+ fs29.rmSync(oldPath, { force: true });
19604
+ fs29.renameSync(execPath, oldPath);
19605
+ fs29.copyFileSync(stagedPath, execPath);
19606
+ fs29.chmodSync(execPath, 493);
19582
19607
  return;
19583
19608
  }
19584
19609
  const tmp = `${execPath}.new`;
19585
- fs28.rmSync(tmp, { force: true });
19610
+ fs29.rmSync(tmp, { force: true });
19586
19611
  try {
19587
- fs28.copyFileSync(stagedPath, tmp);
19588
- fs28.chmodSync(tmp, 493);
19589
- fs28.renameSync(tmp, execPath);
19612
+ fs29.copyFileSync(stagedPath, tmp);
19613
+ fs29.chmodSync(tmp, 493);
19614
+ fs29.renameSync(tmp, execPath);
19590
19615
  } catch (err) {
19591
- fs28.rmSync(tmp, { force: true });
19616
+ fs29.rmSync(tmp, { force: true });
19592
19617
  throw err;
19593
19618
  }
19594
- fs28.rmSync(stagedPath, { force: true });
19619
+ fs29.rmSync(stagedPath, { force: true });
19595
19620
  }
19596
19621
  function installStaged(opts) {
19597
19622
  const log = opts.log ?? (() => {
@@ -19618,18 +19643,18 @@ function rollback(dataDir, execPath, log = () => {
19618
19643
  }) {
19619
19644
  const state = readRollbackTarget(dataDir);
19620
19645
  if (!state?.backupPath || !state.backupVersion) return null;
19621
- if (!fs28.existsSync(state.backupPath)) return null;
19646
+ if (!fs29.existsSync(state.backupPath)) return null;
19622
19647
  log(`\u6B63\u5728\u56DE\u6EDA\u5230 v${state.backupVersion}`);
19623
19648
  if (process.platform === "win32") {
19624
- fs28.rmSync(`${execPath}.old`, { force: true });
19625
- fs28.renameSync(execPath, `${execPath}.old`);
19626
- fs28.copyFileSync(state.backupPath, execPath);
19627
- fs28.chmodSync(execPath, 493);
19649
+ fs29.rmSync(`${execPath}.old`, { force: true });
19650
+ fs29.renameSync(execPath, `${execPath}.old`);
19651
+ fs29.copyFileSync(state.backupPath, execPath);
19652
+ fs29.chmodSync(execPath, 493);
19628
19653
  } else {
19629
19654
  const tmp = `${execPath}.rollback`;
19630
- fs28.copyFileSync(state.backupPath, tmp);
19631
- fs28.chmodSync(tmp, 493);
19632
- fs28.renameSync(tmp, execPath);
19655
+ fs29.copyFileSync(state.backupPath, tmp);
19656
+ fs29.chmodSync(tmp, 493);
19657
+ fs29.renameSync(tmp, execPath);
19633
19658
  }
19634
19659
  patchState(dataDir, {
19635
19660
  pendingVersion: state.backupVersion,
@@ -19643,7 +19668,7 @@ function rollback(dataDir, execPath, log = () => {
19643
19668
  }
19644
19669
  function readRollbackTarget(dataDir) {
19645
19670
  try {
19646
- const raw = fs28.readFileSync(path35.join(updatesDir(dataDir), "state.json"), "utf-8");
19671
+ const raw = fs29.readFileSync(path35.join(updatesDir(dataDir), "state.json"), "utf-8");
19647
19672
  const s = JSON.parse(raw);
19648
19673
  if (s.backupPath && s.backupVersion) return s;
19649
19674
  } catch {
@@ -19726,7 +19751,7 @@ var UpdateController = class {
19726
19751
  reconcile() {
19727
19752
  const state = loadState(this.opts.dataDir);
19728
19753
  const current = this.currentVersion;
19729
- if (state.stagedPath && !fs29.existsSync(state.stagedPath)) {
19754
+ if (state.stagedPath && !fs30.existsSync(state.stagedPath)) {
19730
19755
  patchState(this.opts.dataDir, { stagedVersion: void 0, stagedPath: void 0 });
19731
19756
  }
19732
19757
  const patch = { runningVersion: current };
@@ -19741,7 +19766,7 @@ var UpdateController = class {
19741
19766
  }
19742
19767
  patchState(this.opts.dataDir, patch);
19743
19768
  if (process.platform === "win32") {
19744
- fs29.rmSync(`${process.execPath}.old`, { force: true });
19769
+ fs30.rmSync(`${process.execPath}.old`, { force: true });
19745
19770
  }
19746
19771
  }
19747
19772
  schedule(delayMs) {
@@ -19817,7 +19842,7 @@ var UpdateController = class {
19817
19842
  const bin = manifest.binaries[platformKey()];
19818
19843
  if (!bin) return `\u6E05\u5355\u6CA1\u6709\u5F53\u524D\u5E73\u53F0\uFF08${platformKey()}\uFF09\u7684\u4EA7\u7269`;
19819
19844
  let stagedPath = state.stagedPath;
19820
- if (!(state.stagedVersion === manifest.version && stagedPath && fs29.existsSync(stagedPath))) {
19845
+ if (!(state.stagedVersion === manifest.version && stagedPath && fs30.existsSync(stagedPath))) {
19821
19846
  stagedPath = path36.join(
19822
19847
  updatesDir(this.opts.dataDir),
19823
19848
  "staged",
@@ -19830,7 +19855,7 @@ var UpdateController = class {
19830
19855
  }
19831
19856
  const selfTest = selfCheck(stagedPath, manifest.version);
19832
19857
  if (!selfTest.ok) {
19833
- fs29.rmSync(stagedPath, { force: true });
19858
+ fs30.rmSync(stagedPath, { force: true });
19834
19859
  this.recordFailure(manifest.version, selfTest.error ?? "\u81EA\u68C0\u5931\u8D25");
19835
19860
  return `\u5B89\u88C5\u5305\u81EA\u68C0\u5931\u8D25\uFF1A${selfTest.error}`;
19836
19861
  }
@@ -19971,7 +19996,7 @@ function pemFile(key) {
19971
19996
  const p = env2(key);
19972
19997
  if (!p) return void 0;
19973
19998
  try {
19974
- return fs30.readFileSync(p);
19999
+ return fs31.readFileSync(p);
19975
20000
  } catch (e) {
19976
20001
  console.warn(`[tls] \u8BFB\u53D6 ${key}=${p} \u5931\u8D25: ${e instanceof Error ? e.message : e}`);
19977
20002
  return void 0;
@@ -20656,17 +20681,17 @@ async function runUpdateCommand(argv) {
20656
20681
 
20657
20682
  // src/cli/sessionMeta.ts
20658
20683
  init_cjs_shims();
20659
- var fs31 = __toESM(require("fs"), 1);
20684
+ var fs32 = __toESM(require("fs"), 1);
20660
20685
  var path40 = __toESM(require("path"), 1);
20661
20686
  function updateSessionMetaFile(stateDir2, sessionId, patch) {
20662
20687
  const file = path40.join(stateDir2, `${sessionId}_state.json`);
20663
20688
  try {
20664
- const raw = fs31.readFileSync(file, "utf8");
20689
+ const raw = fs32.readFileSync(file, "utf8");
20665
20690
  const state = JSON.parse(raw);
20666
20691
  if (patch.name !== void 0) state.name = patch.name;
20667
20692
  if (patch.nameSource !== void 0) state.nameSource = patch.nameSource;
20668
20693
  if (patch.taskCount !== void 0) state.taskCount = patch.taskCount;
20669
- fs31.writeFileSync(file, JSON.stringify(state, null, 2), "utf8");
20694
+ fs32.writeFileSync(file, JSON.stringify(state, null, 2), "utf8");
20670
20695
  return true;
20671
20696
  } catch {
20672
20697
  return false;
@@ -20675,7 +20700,7 @@ function updateSessionMetaFile(stateDir2, sessionId, patch) {
20675
20700
 
20676
20701
  // src/cli/debug.ts
20677
20702
  init_cjs_shims();
20678
- var fs32 = __toESM(require("fs"), 1);
20703
+ var fs33 = __toESM(require("fs"), 1);
20679
20704
  var os8 = __toESM(require("os"), 1);
20680
20705
  var path41 = __toESM(require("path"), 1);
20681
20706
  var LOG_NAME = "zqagent-debug.log";
@@ -20706,8 +20731,8 @@ function enableDebug(argv = process.argv) {
20706
20731
  enabled = true;
20707
20732
  logFile = resolveLogFile();
20708
20733
  try {
20709
- fs32.mkdirSync(path41.dirname(logFile), { recursive: true });
20710
- fs32.writeFileSync(logFile, "");
20734
+ fs33.mkdirSync(path41.dirname(logFile), { recursive: true });
20735
+ fs33.writeFileSync(logFile, "");
20711
20736
  } catch {
20712
20737
  logFile = null;
20713
20738
  }
@@ -20724,7 +20749,7 @@ function dlog(stage, message = "") {
20724
20749
  const line = `[+${String(Date.now() - startedAt).padStart(6)}ms] [${stage}] ${message}`;
20725
20750
  if (logFile) {
20726
20751
  try {
20727
- fs32.appendFileSync(logFile, line + "\n");
20752
+ fs33.appendFileSync(logFile, line + "\n");
20728
20753
  } catch {
20729
20754
  }
20730
20755
  }
@@ -20889,13 +20914,13 @@ var MAX_ITERATIONS = parseMaxIterations(process.env.MAX_ITERATIONS, 300);
20889
20914
  var STATE_DIR = stateDir();
20890
20915
  function listSessions() {
20891
20916
  try {
20892
- const files = fs33.readdirSync(STATE_DIR);
20917
+ const files = fs34.readdirSync(STATE_DIR);
20893
20918
  const sessions = [];
20894
20919
  for (const f of files) {
20895
20920
  if (!f.endsWith("_state.json")) continue;
20896
20921
  try {
20897
20922
  const parsed = JSON.parse(
20898
- fs33.readFileSync(path42.join(STATE_DIR, f), "utf8")
20923
+ fs34.readFileSync(path42.join(STATE_DIR, f), "utf8")
20899
20924
  );
20900
20925
  if (parsed && typeof parsed.sessionId === "string") {
20901
20926
  sessions.push(parsed);
@@ -20932,8 +20957,8 @@ function printLastAssistantMessage(messages) {
20932
20957
  var AGENTS_FILE = path42.join(WORKSPACE, ".agent", "agents.json");
20933
20958
  function loadAgentsFromFile() {
20934
20959
  try {
20935
- if (!fs33.existsSync(AGENTS_FILE)) return [];
20936
- const raw = fs33.readFileSync(AGENTS_FILE, "utf8");
20960
+ if (!fs34.existsSync(AGENTS_FILE)) return [];
20961
+ const raw = fs34.readFileSync(AGENTS_FILE, "utf8");
20937
20962
  const parsed = JSON.parse(raw);
20938
20963
  if (!Array.isArray(parsed)) return [];
20939
20964
  return parsed.filter(
@@ -20945,8 +20970,8 @@ function loadAgentsFromFile() {
20945
20970
  }
20946
20971
  function saveAgentsToFile(defs) {
20947
20972
  try {
20948
- fs33.mkdirSync(path42.dirname(AGENTS_FILE), { recursive: true });
20949
- fs33.writeFileSync(AGENTS_FILE, JSON.stringify(defs, null, 2) + "\n", "utf8");
20973
+ fs34.mkdirSync(path42.dirname(AGENTS_FILE), { recursive: true });
20974
+ fs34.writeFileSync(AGENTS_FILE, JSON.stringify(defs, null, 2) + "\n", "utf8");
20950
20975
  } catch (err) {
20951
20976
  cliErr(`\u26A0\uFE0F \u4FDD\u5B58 agents \u914D\u7F6E\u5931\u8D25: ${err}`);
20952
20977
  }
@@ -20959,8 +20984,8 @@ var MCP_FILE = path42.join(WORKSPACE, ".agent", "mcp.json");
20959
20984
  var COMMAND_TOOLS_FILE = path42.join(WORKSPACE, ".agent", "tools.json");
20960
20985
  function loadJsonArray(file, validate) {
20961
20986
  try {
20962
- if (!fs33.existsSync(file)) return [];
20963
- const parsed = JSON.parse(fs33.readFileSync(file, "utf8"));
20987
+ if (!fs34.existsSync(file)) return [];
20988
+ const parsed = JSON.parse(fs34.readFileSync(file, "utf8"));
20964
20989
  if (!Array.isArray(parsed)) return [];
20965
20990
  if (!validate) return parsed;
20966
20991
  return parsed.filter((v) => validate(v));
@@ -20970,8 +20995,8 @@ function loadJsonArray(file, validate) {
20970
20995
  }
20971
20996
  function saveJsonFile(file, data) {
20972
20997
  try {
20973
- fs33.mkdirSync(path42.dirname(file), { recursive: true });
20974
- fs33.writeFileSync(file, JSON.stringify(data, null, 2) + "\n", "utf8");
20998
+ fs34.mkdirSync(path42.dirname(file), { recursive: true });
20999
+ fs34.writeFileSync(file, JSON.stringify(data, null, 2) + "\n", "utf8");
20975
21000
  } catch (err) {
20976
21001
  cliErr(`\u26A0\uFE0F \u4FDD\u5B58\u914D\u7F6E\u5931\u8D25: ${err}`);
20977
21002
  }
@@ -21072,7 +21097,7 @@ function pruneEmptySessions(keepSessionId) {
21072
21097
  if (!isEmptySession(s) || s.sessionId === keepSessionId) continue;
21073
21098
  for (const suffix of ["_state.json", ".jsonl"]) {
21074
21099
  try {
21075
- fs33.unlinkSync(path42.join(STATE_DIR, `${s.sessionId}${suffix}`));
21100
+ fs34.unlinkSync(path42.join(STATE_DIR, `${s.sessionId}${suffix}`));
21076
21101
  } catch {
21077
21102
  }
21078
21103
  }
@@ -21605,7 +21630,7 @@ async function offerTerminalSetup(engine, canUseAgent) {
21605
21630
  }
21606
21631
  var KNOWN_SUBCOMMANDS = /* @__PURE__ */ new Set(["link", "serve", "update"]);
21607
21632
  function cliVersion() {
21608
- const env3 = "0.2.6"?.trim();
21633
+ const env3 = "0.2.7"?.trim();
21609
21634
  if (env3) return env3;
21610
21635
  try {
21611
21636
  const req2 = (0, import_module.createRequire)(importMetaUrl);
@@ -21810,7 +21835,7 @@ async function main() {
21810
21835
  });
21811
21836
  const savedState = resumeId ? FileLogHook.loadState(resumeId, STATE_DIR) : null;
21812
21837
  const metaStateFile = path42.join(STATE_DIR, `${SESSION_ID}_state.json`);
21813
- const stateForMeta = savedState ?? (fs33.existsSync(metaStateFile) ? FileLogHook.loadState(SESSION_ID, STATE_DIR) : null);
21838
+ const stateForMeta = savedState ?? (fs34.existsSync(metaStateFile) ? FileLogHook.loadState(SESSION_ID, STATE_DIR) : null);
21814
21839
  sessionMeta = {
21815
21840
  sessionId: SESSION_ID,
21816
21841
  name: stateForMeta?.name,