@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.
package/dist/cli/index.js CHANGED
@@ -552,7 +552,7 @@ var init_wire = __esm({
552
552
  // src/cli/index.ts
553
553
  init_esm_shims();
554
554
  import "dotenv/config";
555
- import * as fs33 from "fs";
555
+ import * as fs34 from "fs";
556
556
  import * as readline2 from "readline";
557
557
  import * as path43 from "path";
558
558
  import { exec } from "child_process";
@@ -11170,7 +11170,7 @@ init_esm_shims();
11170
11170
 
11171
11171
  // src/server/runtime.ts
11172
11172
  init_esm_shims();
11173
- import * as fs30 from "fs";
11173
+ import * as fs31 from "fs";
11174
11174
  import * as path38 from "path";
11175
11175
 
11176
11176
  // src/server/session.ts
@@ -13562,7 +13562,7 @@ function buildNodeInfo(store, opts) {
13562
13562
  nodeId: opts.nodeId ?? ensureNodeId2(store),
13563
13563
  platform: process.platform,
13564
13564
  mode: process.env.NODE_MODE ?? "standalone",
13565
- version: "0.2.6",
13565
+ version: "0.2.7",
13566
13566
  admin: opts.admin,
13567
13567
  projects: opts.projects
13568
13568
  };
@@ -14555,7 +14555,7 @@ function buildNodeHost(store, manager, diskPath) {
14555
14555
  arch: process.arch,
14556
14556
  release: os6.release(),
14557
14557
  uptimeSec: Math.round(os6.uptime()),
14558
- version: "0.2.6",
14558
+ version: "0.2.7",
14559
14559
  mode: process.env.NODE_MODE ?? "standalone",
14560
14560
  cpu: {
14561
14561
  count: cpus2.length,
@@ -16107,7 +16107,7 @@ function createApp(store, manager, opts = {}) {
16107
16107
  json(res, 200, {
16108
16108
  status: "ok",
16109
16109
  // 版本让运维/探针能确认线上跑的是哪个构建(更新与回滚据此判断)
16110
- version: "0.2.6",
16110
+ version: "0.2.7",
16111
16111
  features: { mcp: hasServerMcpConfig() }
16112
16112
  });
16113
16113
  return;
@@ -17745,7 +17745,7 @@ var FleetNodeBridge = class {
17745
17745
  label: this.opts.deps.store.loadNodeLabel() ?? void 0,
17746
17746
  platform: process.platform,
17747
17747
  mode: process.env.NODE_MODE ?? "standalone",
17748
- version: "0.2.6",
17748
+ version: "0.2.7",
17749
17749
  ip: primaryIp()
17750
17750
  };
17751
17751
  }
@@ -17800,7 +17800,7 @@ var FleetNodeBridge = class {
17800
17800
  label: this.opts.deps.store.loadNodeLabel() ?? void 0,
17801
17801
  platform: process.platform,
17802
17802
  mode: process.env.NODE_MODE ?? "standalone",
17803
- version: "0.2.6",
17803
+ version: "0.2.7",
17804
17804
  ip: primaryIp(),
17805
17805
  projects,
17806
17806
  totals,
@@ -19211,7 +19211,7 @@ var PairingCodeStore = class {
19211
19211
 
19212
19212
  // src/update/controller.ts
19213
19213
  init_esm_shims();
19214
- import * as fs29 from "fs";
19214
+ import * as fs30 from "fs";
19215
19215
  import * as path37 from "path";
19216
19216
 
19217
19217
  // src/update/downloader.ts
@@ -19464,10 +19464,11 @@ function selfCheck(binPath, expectedVersion) {
19464
19464
 
19465
19465
  // src/update/platform.ts
19466
19466
  init_esm_shims();
19467
+ import * as fs27 from "fs";
19467
19468
  import * as path34 from "path";
19468
19469
  import { createRequire as createRequire3 } from "module";
19469
19470
  function currentVersion() {
19470
- const injected = "0.2.6"?.trim();
19471
+ const injected = "0.2.7"?.trim();
19471
19472
  if (injected) return injected;
19472
19473
  try {
19473
19474
  const req2 = createRequire3(import.meta.url);
@@ -19482,9 +19483,33 @@ function isSeaRuntime() {
19482
19483
  const base = path34.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
19483
19484
  return base !== "node" && base !== "nodejs";
19484
19485
  }
19486
+ var DEFAULT_SERVICE_NAME = "zqagent";
19487
+ function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
19488
+ const unitName = `${serviceName}.service`;
19489
+ for (const line of cgroup.split("\n")) {
19490
+ const idx = line.lastIndexOf(":");
19491
+ if (idx < 0) continue;
19492
+ const unitPath = line.slice(idx + 1).trim();
19493
+ if (unitPath.split("/").includes(unitName)) return "systemd";
19494
+ }
19495
+ return null;
19496
+ }
19497
+ function detectServiceManager() {
19498
+ if (process.platform !== "linux") return null;
19499
+ const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
19500
+ try {
19501
+ return serviceManagerFromCgroup(
19502
+ fs27.readFileSync("/proc/self/cgroup", "utf8"),
19503
+ serviceName
19504
+ );
19505
+ } catch {
19506
+ return null;
19507
+ }
19508
+ }
19485
19509
  function serviceManager() {
19486
19510
  const v = process.env.ZQAGENT_SERVICE_MANAGER?.trim().toLowerCase();
19487
- return v === "systemd" || v === "launchd" ? v : null;
19511
+ if (v === "systemd" || v === "launchd") return v;
19512
+ return detectServiceManager();
19488
19513
  }
19489
19514
  function selfUpdateCapability(hasPublicKey) {
19490
19515
  if (!isSeaRuntime()) {
@@ -19507,12 +19532,12 @@ function selfUpdateCapability(hasPublicKey) {
19507
19532
 
19508
19533
  // src/update/installer.ts
19509
19534
  init_esm_shims();
19510
- import * as fs28 from "fs";
19535
+ import * as fs29 from "fs";
19511
19536
  import * as path36 from "path";
19512
19537
 
19513
19538
  // src/update/state.ts
19514
19539
  init_esm_shims();
19515
- import * as fs27 from "fs";
19540
+ import * as fs28 from "fs";
19516
19541
  import * as path35 from "path";
19517
19542
  function updatesDir(dataDir) {
19518
19543
  return path35.join(dataDir, "updates");
@@ -19522,7 +19547,7 @@ function statePath(dataDir) {
19522
19547
  }
19523
19548
  function loadState(dataDir) {
19524
19549
  try {
19525
- const raw = fs27.readFileSync(statePath(dataDir), "utf-8");
19550
+ const raw = fs28.readFileSync(statePath(dataDir), "utf-8");
19526
19551
  const parsed = JSON.parse(raw);
19527
19552
  if (typeof parsed === "object" && parsed !== null) return parsed;
19528
19553
  } catch {
@@ -19531,11 +19556,11 @@ function loadState(dataDir) {
19531
19556
  }
19532
19557
  function saveState(dataDir, state) {
19533
19558
  const dir = updatesDir(dataDir);
19534
- fs27.mkdirSync(dir, { recursive: true });
19559
+ fs28.mkdirSync(dir, { recursive: true });
19535
19560
  const file = statePath(dataDir);
19536
19561
  const tmp = `${file}.tmp`;
19537
- fs27.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
19538
- fs27.renameSync(tmp, file);
19562
+ fs28.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
19563
+ fs28.renameSync(tmp, file);
19539
19564
  }
19540
19565
  function patchState(dataDir, patch) {
19541
19566
  const next = { ...loadState(dataDir), ...patch };
@@ -19549,32 +19574,32 @@ function backupDir(dataDir) {
19549
19574
  }
19550
19575
  function backupCurrent(dataDir, execPath, version) {
19551
19576
  const dir = backupDir(dataDir);
19552
- fs28.mkdirSync(dir, { recursive: true });
19577
+ fs29.mkdirSync(dir, { recursive: true });
19553
19578
  const target = path36.join(dir, `zqagent-${version}${process.platform === "win32" ? ".exe" : ""}`);
19554
- fs28.copyFileSync(execPath, target);
19555
- fs28.chmodSync(target, 493);
19579
+ fs29.copyFileSync(execPath, target);
19580
+ fs29.chmodSync(target, 493);
19556
19581
  return target;
19557
19582
  }
19558
19583
  function replaceExecutable(execPath, stagedPath) {
19559
19584
  if (process.platform === "win32") {
19560
19585
  const oldPath = `${execPath}.old`;
19561
- fs28.rmSync(oldPath, { force: true });
19562
- fs28.renameSync(execPath, oldPath);
19563
- fs28.copyFileSync(stagedPath, execPath);
19564
- fs28.chmodSync(execPath, 493);
19586
+ fs29.rmSync(oldPath, { force: true });
19587
+ fs29.renameSync(execPath, oldPath);
19588
+ fs29.copyFileSync(stagedPath, execPath);
19589
+ fs29.chmodSync(execPath, 493);
19565
19590
  return;
19566
19591
  }
19567
19592
  const tmp = `${execPath}.new`;
19568
- fs28.rmSync(tmp, { force: true });
19593
+ fs29.rmSync(tmp, { force: true });
19569
19594
  try {
19570
- fs28.copyFileSync(stagedPath, tmp);
19571
- fs28.chmodSync(tmp, 493);
19572
- fs28.renameSync(tmp, execPath);
19595
+ fs29.copyFileSync(stagedPath, tmp);
19596
+ fs29.chmodSync(tmp, 493);
19597
+ fs29.renameSync(tmp, execPath);
19573
19598
  } catch (err) {
19574
- fs28.rmSync(tmp, { force: true });
19599
+ fs29.rmSync(tmp, { force: true });
19575
19600
  throw err;
19576
19601
  }
19577
- fs28.rmSync(stagedPath, { force: true });
19602
+ fs29.rmSync(stagedPath, { force: true });
19578
19603
  }
19579
19604
  function installStaged(opts) {
19580
19605
  const log = opts.log ?? (() => {
@@ -19601,18 +19626,18 @@ function rollback(dataDir, execPath, log = () => {
19601
19626
  }) {
19602
19627
  const state = readRollbackTarget(dataDir);
19603
19628
  if (!state?.backupPath || !state.backupVersion) return null;
19604
- if (!fs28.existsSync(state.backupPath)) return null;
19629
+ if (!fs29.existsSync(state.backupPath)) return null;
19605
19630
  log(`\u6B63\u5728\u56DE\u6EDA\u5230 v${state.backupVersion}`);
19606
19631
  if (process.platform === "win32") {
19607
- fs28.rmSync(`${execPath}.old`, { force: true });
19608
- fs28.renameSync(execPath, `${execPath}.old`);
19609
- fs28.copyFileSync(state.backupPath, execPath);
19610
- fs28.chmodSync(execPath, 493);
19632
+ fs29.rmSync(`${execPath}.old`, { force: true });
19633
+ fs29.renameSync(execPath, `${execPath}.old`);
19634
+ fs29.copyFileSync(state.backupPath, execPath);
19635
+ fs29.chmodSync(execPath, 493);
19611
19636
  } else {
19612
19637
  const tmp = `${execPath}.rollback`;
19613
- fs28.copyFileSync(state.backupPath, tmp);
19614
- fs28.chmodSync(tmp, 493);
19615
- fs28.renameSync(tmp, execPath);
19638
+ fs29.copyFileSync(state.backupPath, tmp);
19639
+ fs29.chmodSync(tmp, 493);
19640
+ fs29.renameSync(tmp, execPath);
19616
19641
  }
19617
19642
  patchState(dataDir, {
19618
19643
  pendingVersion: state.backupVersion,
@@ -19626,7 +19651,7 @@ function rollback(dataDir, execPath, log = () => {
19626
19651
  }
19627
19652
  function readRollbackTarget(dataDir) {
19628
19653
  try {
19629
- const raw = fs28.readFileSync(path36.join(updatesDir(dataDir), "state.json"), "utf-8");
19654
+ const raw = fs29.readFileSync(path36.join(updatesDir(dataDir), "state.json"), "utf-8");
19630
19655
  const s = JSON.parse(raw);
19631
19656
  if (s.backupPath && s.backupVersion) return s;
19632
19657
  } catch {
@@ -19709,7 +19734,7 @@ var UpdateController = class {
19709
19734
  reconcile() {
19710
19735
  const state = loadState(this.opts.dataDir);
19711
19736
  const current = this.currentVersion;
19712
- if (state.stagedPath && !fs29.existsSync(state.stagedPath)) {
19737
+ if (state.stagedPath && !fs30.existsSync(state.stagedPath)) {
19713
19738
  patchState(this.opts.dataDir, { stagedVersion: void 0, stagedPath: void 0 });
19714
19739
  }
19715
19740
  const patch = { runningVersion: current };
@@ -19724,7 +19749,7 @@ var UpdateController = class {
19724
19749
  }
19725
19750
  patchState(this.opts.dataDir, patch);
19726
19751
  if (process.platform === "win32") {
19727
- fs29.rmSync(`${process.execPath}.old`, { force: true });
19752
+ fs30.rmSync(`${process.execPath}.old`, { force: true });
19728
19753
  }
19729
19754
  }
19730
19755
  schedule(delayMs) {
@@ -19800,7 +19825,7 @@ var UpdateController = class {
19800
19825
  const bin = manifest.binaries[platformKey()];
19801
19826
  if (!bin) return `\u6E05\u5355\u6CA1\u6709\u5F53\u524D\u5E73\u53F0\uFF08${platformKey()}\uFF09\u7684\u4EA7\u7269`;
19802
19827
  let stagedPath = state.stagedPath;
19803
- if (!(state.stagedVersion === manifest.version && stagedPath && fs29.existsSync(stagedPath))) {
19828
+ if (!(state.stagedVersion === manifest.version && stagedPath && fs30.existsSync(stagedPath))) {
19804
19829
  stagedPath = path37.join(
19805
19830
  updatesDir(this.opts.dataDir),
19806
19831
  "staged",
@@ -19813,7 +19838,7 @@ var UpdateController = class {
19813
19838
  }
19814
19839
  const selfTest = selfCheck(stagedPath, manifest.version);
19815
19840
  if (!selfTest.ok) {
19816
- fs29.rmSync(stagedPath, { force: true });
19841
+ fs30.rmSync(stagedPath, { force: true });
19817
19842
  this.recordFailure(manifest.version, selfTest.error ?? "\u81EA\u68C0\u5931\u8D25");
19818
19843
  return `\u5B89\u88C5\u5305\u81EA\u68C0\u5931\u8D25\uFF1A${selfTest.error}`;
19819
19844
  }
@@ -19954,7 +19979,7 @@ function pemFile(key) {
19954
19979
  const p = env2(key);
19955
19980
  if (!p) return void 0;
19956
19981
  try {
19957
- return fs30.readFileSync(p);
19982
+ return fs31.readFileSync(p);
19958
19983
  } catch (e) {
19959
19984
  console.warn(`[tls] \u8BFB\u53D6 ${key}=${p} \u5931\u8D25: ${e instanceof Error ? e.message : e}`);
19960
19985
  return void 0;
@@ -20639,17 +20664,17 @@ async function runUpdateCommand(argv) {
20639
20664
 
20640
20665
  // src/cli/sessionMeta.ts
20641
20666
  init_esm_shims();
20642
- import * as fs31 from "fs";
20667
+ import * as fs32 from "fs";
20643
20668
  import * as path41 from "path";
20644
20669
  function updateSessionMetaFile(stateDir2, sessionId, patch) {
20645
20670
  const file = path41.join(stateDir2, `${sessionId}_state.json`);
20646
20671
  try {
20647
- const raw = fs31.readFileSync(file, "utf8");
20672
+ const raw = fs32.readFileSync(file, "utf8");
20648
20673
  const state = JSON.parse(raw);
20649
20674
  if (patch.name !== void 0) state.name = patch.name;
20650
20675
  if (patch.nameSource !== void 0) state.nameSource = patch.nameSource;
20651
20676
  if (patch.taskCount !== void 0) state.taskCount = patch.taskCount;
20652
- fs31.writeFileSync(file, JSON.stringify(state, null, 2), "utf8");
20677
+ fs32.writeFileSync(file, JSON.stringify(state, null, 2), "utf8");
20653
20678
  return true;
20654
20679
  } catch {
20655
20680
  return false;
@@ -20658,7 +20683,7 @@ function updateSessionMetaFile(stateDir2, sessionId, patch) {
20658
20683
 
20659
20684
  // src/cli/debug.ts
20660
20685
  init_esm_shims();
20661
- import * as fs32 from "fs";
20686
+ import * as fs33 from "fs";
20662
20687
  import * as os8 from "os";
20663
20688
  import * as path42 from "path";
20664
20689
  var LOG_NAME = "zqagent-debug.log";
@@ -20689,8 +20714,8 @@ function enableDebug(argv = process.argv) {
20689
20714
  enabled = true;
20690
20715
  logFile = resolveLogFile();
20691
20716
  try {
20692
- fs32.mkdirSync(path42.dirname(logFile), { recursive: true });
20693
- fs32.writeFileSync(logFile, "");
20717
+ fs33.mkdirSync(path42.dirname(logFile), { recursive: true });
20718
+ fs33.writeFileSync(logFile, "");
20694
20719
  } catch {
20695
20720
  logFile = null;
20696
20721
  }
@@ -20707,7 +20732,7 @@ function dlog(stage, message = "") {
20707
20732
  const line = `[+${String(Date.now() - startedAt).padStart(6)}ms] [${stage}] ${message}`;
20708
20733
  if (logFile) {
20709
20734
  try {
20710
- fs32.appendFileSync(logFile, line + "\n");
20735
+ fs33.appendFileSync(logFile, line + "\n");
20711
20736
  } catch {
20712
20737
  }
20713
20738
  }
@@ -20872,13 +20897,13 @@ var MAX_ITERATIONS = parseMaxIterations(process.env.MAX_ITERATIONS, 300);
20872
20897
  var STATE_DIR = stateDir();
20873
20898
  function listSessions() {
20874
20899
  try {
20875
- const files = fs33.readdirSync(STATE_DIR);
20900
+ const files = fs34.readdirSync(STATE_DIR);
20876
20901
  const sessions = [];
20877
20902
  for (const f of files) {
20878
20903
  if (!f.endsWith("_state.json")) continue;
20879
20904
  try {
20880
20905
  const parsed = JSON.parse(
20881
- fs33.readFileSync(path43.join(STATE_DIR, f), "utf8")
20906
+ fs34.readFileSync(path43.join(STATE_DIR, f), "utf8")
20882
20907
  );
20883
20908
  if (parsed && typeof parsed.sessionId === "string") {
20884
20909
  sessions.push(parsed);
@@ -20915,8 +20940,8 @@ function printLastAssistantMessage(messages) {
20915
20940
  var AGENTS_FILE = path43.join(WORKSPACE, ".agent", "agents.json");
20916
20941
  function loadAgentsFromFile() {
20917
20942
  try {
20918
- if (!fs33.existsSync(AGENTS_FILE)) return [];
20919
- const raw = fs33.readFileSync(AGENTS_FILE, "utf8");
20943
+ if (!fs34.existsSync(AGENTS_FILE)) return [];
20944
+ const raw = fs34.readFileSync(AGENTS_FILE, "utf8");
20920
20945
  const parsed = JSON.parse(raw);
20921
20946
  if (!Array.isArray(parsed)) return [];
20922
20947
  return parsed.filter(
@@ -20928,8 +20953,8 @@ function loadAgentsFromFile() {
20928
20953
  }
20929
20954
  function saveAgentsToFile(defs) {
20930
20955
  try {
20931
- fs33.mkdirSync(path43.dirname(AGENTS_FILE), { recursive: true });
20932
- fs33.writeFileSync(AGENTS_FILE, JSON.stringify(defs, null, 2) + "\n", "utf8");
20956
+ fs34.mkdirSync(path43.dirname(AGENTS_FILE), { recursive: true });
20957
+ fs34.writeFileSync(AGENTS_FILE, JSON.stringify(defs, null, 2) + "\n", "utf8");
20933
20958
  } catch (err) {
20934
20959
  cliErr(`\u26A0\uFE0F \u4FDD\u5B58 agents \u914D\u7F6E\u5931\u8D25: ${err}`);
20935
20960
  }
@@ -20942,8 +20967,8 @@ var MCP_FILE = path43.join(WORKSPACE, ".agent", "mcp.json");
20942
20967
  var COMMAND_TOOLS_FILE = path43.join(WORKSPACE, ".agent", "tools.json");
20943
20968
  function loadJsonArray(file, validate) {
20944
20969
  try {
20945
- if (!fs33.existsSync(file)) return [];
20946
- const parsed = JSON.parse(fs33.readFileSync(file, "utf8"));
20970
+ if (!fs34.existsSync(file)) return [];
20971
+ const parsed = JSON.parse(fs34.readFileSync(file, "utf8"));
20947
20972
  if (!Array.isArray(parsed)) return [];
20948
20973
  if (!validate) return parsed;
20949
20974
  return parsed.filter((v) => validate(v));
@@ -20953,8 +20978,8 @@ function loadJsonArray(file, validate) {
20953
20978
  }
20954
20979
  function saveJsonFile(file, data) {
20955
20980
  try {
20956
- fs33.mkdirSync(path43.dirname(file), { recursive: true });
20957
- fs33.writeFileSync(file, JSON.stringify(data, null, 2) + "\n", "utf8");
20981
+ fs34.mkdirSync(path43.dirname(file), { recursive: true });
20982
+ fs34.writeFileSync(file, JSON.stringify(data, null, 2) + "\n", "utf8");
20958
20983
  } catch (err) {
20959
20984
  cliErr(`\u26A0\uFE0F \u4FDD\u5B58\u914D\u7F6E\u5931\u8D25: ${err}`);
20960
20985
  }
@@ -21055,7 +21080,7 @@ function pruneEmptySessions(keepSessionId) {
21055
21080
  if (!isEmptySession(s) || s.sessionId === keepSessionId) continue;
21056
21081
  for (const suffix of ["_state.json", ".jsonl"]) {
21057
21082
  try {
21058
- fs33.unlinkSync(path43.join(STATE_DIR, `${s.sessionId}${suffix}`));
21083
+ fs34.unlinkSync(path43.join(STATE_DIR, `${s.sessionId}${suffix}`));
21059
21084
  } catch {
21060
21085
  }
21061
21086
  }
@@ -21588,7 +21613,7 @@ async function offerTerminalSetup(engine, canUseAgent) {
21588
21613
  }
21589
21614
  var KNOWN_SUBCOMMANDS = /* @__PURE__ */ new Set(["link", "serve", "update"]);
21590
21615
  function cliVersion() {
21591
- const env3 = "0.2.6"?.trim();
21616
+ const env3 = "0.2.7"?.trim();
21592
21617
  if (env3) return env3;
21593
21618
  try {
21594
21619
  const req2 = createRequire4(import.meta.url);
@@ -21793,7 +21818,7 @@ async function main() {
21793
21818
  });
21794
21819
  const savedState = resumeId ? FileLogHook.loadState(resumeId, STATE_DIR) : null;
21795
21820
  const metaStateFile = path43.join(STATE_DIR, `${SESSION_ID}_state.json`);
21796
- const stateForMeta = savedState ?? (fs33.existsSync(metaStateFile) ? FileLogHook.loadState(SESSION_ID, STATE_DIR) : null);
21821
+ const stateForMeta = savedState ?? (fs34.existsSync(metaStateFile) ? FileLogHook.loadState(SESSION_ID, STATE_DIR) : null);
21797
21822
  sessionMeta = {
21798
21823
  sessionId: SESSION_ID,
21799
21824
  name: stateForMeta?.name,