@zqagent/core 0.2.6 → 0.2.8

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.8",
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.8",
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.8",
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.8",
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.8",
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,12 @@ 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);
19486
+ var import_node_child_process6 = require("child_process");
19485
19487
  var import_node_module3 = require("module");
19486
19488
  function currentVersion() {
19487
- const injected = "0.2.6"?.trim();
19489
+ const injected = "0.2.8"?.trim();
19488
19490
  if (injected) return injected;
19489
19491
  try {
19490
19492
  const req2 = (0, import_node_module3.createRequire)(importMetaUrl);
@@ -19499,9 +19501,62 @@ function isSeaRuntime() {
19499
19501
  const base = path33.basename(process.execPath).toLowerCase().replace(/\.exe$/, "");
19500
19502
  return base !== "node" && base !== "nodejs";
19501
19503
  }
19504
+ var DEFAULT_SERVICE_NAME = "zqagent";
19505
+ function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
19506
+ const unitName = `${serviceName}.service`;
19507
+ for (const line of cgroup.split("\n")) {
19508
+ const idx = line.lastIndexOf(":");
19509
+ if (idx < 0) continue;
19510
+ const unitPath = line.slice(idx + 1).trim();
19511
+ if (unitPath.split("/").includes(unitName)) return "systemd";
19512
+ }
19513
+ return null;
19514
+ }
19515
+ function detectServiceManager() {
19516
+ if (process.platform !== "linux") return null;
19517
+ const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
19518
+ try {
19519
+ return serviceManagerFromCgroup(
19520
+ fs27.readFileSync("/proc/self/cgroup", "utf8"),
19521
+ serviceName
19522
+ );
19523
+ } catch {
19524
+ return null;
19525
+ }
19526
+ }
19502
19527
  function serviceManager() {
19503
19528
  const v = process.env.ZQAGENT_SERVICE_MANAGER?.trim().toLowerCase();
19504
- return v === "systemd" || v === "launchd" ? v : null;
19529
+ if (v === "systemd" || v === "launchd") return v;
19530
+ return detectServiceManager();
19531
+ }
19532
+ function parseServiceEnvironment(raw) {
19533
+ const out = {};
19534
+ for (const token of raw.trim().split(/\s+/)) {
19535
+ const idx = token.indexOf("=");
19536
+ if (idx > 0) out[token.slice(0, idx)] = token.slice(idx + 1);
19537
+ }
19538
+ return out;
19539
+ }
19540
+ var cachedServiceEnv = null;
19541
+ function readServiceEnvironment() {
19542
+ const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
19543
+ try {
19544
+ const res = (0, import_node_child_process6.spawnSync)(
19545
+ "systemctl",
19546
+ ["show", serviceName, "--property=Environment", "--value", "--no-pager"],
19547
+ { encoding: "utf8", timeout: 3e3 }
19548
+ );
19549
+ if (res.status !== 0 || !res.stdout) return {};
19550
+ return parseServiceEnvironment(res.stdout);
19551
+ } catch {
19552
+ return {};
19553
+ }
19554
+ }
19555
+ function serviceEnvValue(key) {
19556
+ if (process.platform !== "linux") return void 0;
19557
+ if (serviceManager() !== "systemd") return void 0;
19558
+ cachedServiceEnv ??= readServiceEnvironment();
19559
+ return cachedServiceEnv[key];
19505
19560
  }
19506
19561
  function selfUpdateCapability(hasPublicKey) {
19507
19562
  if (!isSeaRuntime()) {
@@ -19524,12 +19579,12 @@ function selfUpdateCapability(hasPublicKey) {
19524
19579
 
19525
19580
  // src/update/installer.ts
19526
19581
  init_cjs_shims();
19527
- var fs28 = __toESM(require("fs"), 1);
19582
+ var fs29 = __toESM(require("fs"), 1);
19528
19583
  var path35 = __toESM(require("path"), 1);
19529
19584
 
19530
19585
  // src/update/state.ts
19531
19586
  init_cjs_shims();
19532
- var fs27 = __toESM(require("fs"), 1);
19587
+ var fs28 = __toESM(require("fs"), 1);
19533
19588
  var path34 = __toESM(require("path"), 1);
19534
19589
  function updatesDir(dataDir) {
19535
19590
  return path34.join(dataDir, "updates");
@@ -19539,7 +19594,7 @@ function statePath(dataDir) {
19539
19594
  }
19540
19595
  function loadState(dataDir) {
19541
19596
  try {
19542
- const raw = fs27.readFileSync(statePath(dataDir), "utf-8");
19597
+ const raw = fs28.readFileSync(statePath(dataDir), "utf-8");
19543
19598
  const parsed = JSON.parse(raw);
19544
19599
  if (typeof parsed === "object" && parsed !== null) return parsed;
19545
19600
  } catch {
@@ -19548,11 +19603,11 @@ function loadState(dataDir) {
19548
19603
  }
19549
19604
  function saveState(dataDir, state) {
19550
19605
  const dir = updatesDir(dataDir);
19551
- fs27.mkdirSync(dir, { recursive: true });
19606
+ fs28.mkdirSync(dir, { recursive: true });
19552
19607
  const file = statePath(dataDir);
19553
19608
  const tmp = `${file}.tmp`;
19554
- fs27.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
19555
- fs27.renameSync(tmp, file);
19609
+ fs28.writeFileSync(tmp, JSON.stringify(state, null, 2), "utf-8");
19610
+ fs28.renameSync(tmp, file);
19556
19611
  }
19557
19612
  function patchState(dataDir, patch) {
19558
19613
  const next = { ...loadState(dataDir), ...patch };
@@ -19566,32 +19621,32 @@ function backupDir(dataDir) {
19566
19621
  }
19567
19622
  function backupCurrent(dataDir, execPath, version) {
19568
19623
  const dir = backupDir(dataDir);
19569
- fs28.mkdirSync(dir, { recursive: true });
19624
+ fs29.mkdirSync(dir, { recursive: true });
19570
19625
  const target = path35.join(dir, `zqagent-${version}${process.platform === "win32" ? ".exe" : ""}`);
19571
- fs28.copyFileSync(execPath, target);
19572
- fs28.chmodSync(target, 493);
19626
+ fs29.copyFileSync(execPath, target);
19627
+ fs29.chmodSync(target, 493);
19573
19628
  return target;
19574
19629
  }
19575
19630
  function replaceExecutable(execPath, stagedPath) {
19576
19631
  if (process.platform === "win32") {
19577
19632
  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);
19633
+ fs29.rmSync(oldPath, { force: true });
19634
+ fs29.renameSync(execPath, oldPath);
19635
+ fs29.copyFileSync(stagedPath, execPath);
19636
+ fs29.chmodSync(execPath, 493);
19582
19637
  return;
19583
19638
  }
19584
19639
  const tmp = `${execPath}.new`;
19585
- fs28.rmSync(tmp, { force: true });
19640
+ fs29.rmSync(tmp, { force: true });
19586
19641
  try {
19587
- fs28.copyFileSync(stagedPath, tmp);
19588
- fs28.chmodSync(tmp, 493);
19589
- fs28.renameSync(tmp, execPath);
19642
+ fs29.copyFileSync(stagedPath, tmp);
19643
+ fs29.chmodSync(tmp, 493);
19644
+ fs29.renameSync(tmp, execPath);
19590
19645
  } catch (err) {
19591
- fs28.rmSync(tmp, { force: true });
19646
+ fs29.rmSync(tmp, { force: true });
19592
19647
  throw err;
19593
19648
  }
19594
- fs28.rmSync(stagedPath, { force: true });
19649
+ fs29.rmSync(stagedPath, { force: true });
19595
19650
  }
19596
19651
  function installStaged(opts) {
19597
19652
  const log = opts.log ?? (() => {
@@ -19618,18 +19673,18 @@ function rollback(dataDir, execPath, log = () => {
19618
19673
  }) {
19619
19674
  const state = readRollbackTarget(dataDir);
19620
19675
  if (!state?.backupPath || !state.backupVersion) return null;
19621
- if (!fs28.existsSync(state.backupPath)) return null;
19676
+ if (!fs29.existsSync(state.backupPath)) return null;
19622
19677
  log(`\u6B63\u5728\u56DE\u6EDA\u5230 v${state.backupVersion}`);
19623
19678
  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);
19679
+ fs29.rmSync(`${execPath}.old`, { force: true });
19680
+ fs29.renameSync(execPath, `${execPath}.old`);
19681
+ fs29.copyFileSync(state.backupPath, execPath);
19682
+ fs29.chmodSync(execPath, 493);
19628
19683
  } else {
19629
19684
  const tmp = `${execPath}.rollback`;
19630
- fs28.copyFileSync(state.backupPath, tmp);
19631
- fs28.chmodSync(tmp, 493);
19632
- fs28.renameSync(tmp, execPath);
19685
+ fs29.copyFileSync(state.backupPath, tmp);
19686
+ fs29.chmodSync(tmp, 493);
19687
+ fs29.renameSync(tmp, execPath);
19633
19688
  }
19634
19689
  patchState(dataDir, {
19635
19690
  pendingVersion: state.backupVersion,
@@ -19643,7 +19698,7 @@ function rollback(dataDir, execPath, log = () => {
19643
19698
  }
19644
19699
  function readRollbackTarget(dataDir) {
19645
19700
  try {
19646
- const raw = fs28.readFileSync(path35.join(updatesDir(dataDir), "state.json"), "utf-8");
19701
+ const raw = fs29.readFileSync(path35.join(updatesDir(dataDir), "state.json"), "utf-8");
19647
19702
  const s = JSON.parse(raw);
19648
19703
  if (s.backupPath && s.backupVersion) return s;
19649
19704
  } catch {
@@ -19655,7 +19710,9 @@ function readRollbackTarget(dataDir) {
19655
19710
  var DEFAULT_BASE = "https://agent.cd-zq.com/downloads/zqagent";
19656
19711
  function env(key) {
19657
19712
  const v = process.env[key]?.trim();
19658
- return v ? v : void 0;
19713
+ if (v) return v;
19714
+ const fromService = serviceEnvValue(key)?.trim();
19715
+ return fromService ? fromService : void 0;
19659
19716
  }
19660
19717
  function num(key, fallback) {
19661
19718
  const n = Number(env(key));
@@ -19692,7 +19749,7 @@ var UpdateController = class {
19692
19749
  return parsePublicKey(env("ZQAGENT_UPDATE_PUBKEY") ?? "");
19693
19750
  }
19694
19751
  get autoUpdateOff() {
19695
- return process.env.ZQAGENT_AUTO_UPDATE?.trim() === "0";
19752
+ return env("ZQAGENT_AUTO_UPDATE") === "0";
19696
19753
  }
19697
19754
  get enabled() {
19698
19755
  return !this.autoUpdateOff && selfUpdateCapability(Boolean(this.publicKey)).ok;
@@ -19726,7 +19783,7 @@ var UpdateController = class {
19726
19783
  reconcile() {
19727
19784
  const state = loadState(this.opts.dataDir);
19728
19785
  const current = this.currentVersion;
19729
- if (state.stagedPath && !fs29.existsSync(state.stagedPath)) {
19786
+ if (state.stagedPath && !fs30.existsSync(state.stagedPath)) {
19730
19787
  patchState(this.opts.dataDir, { stagedVersion: void 0, stagedPath: void 0 });
19731
19788
  }
19732
19789
  const patch = { runningVersion: current };
@@ -19741,7 +19798,7 @@ var UpdateController = class {
19741
19798
  }
19742
19799
  patchState(this.opts.dataDir, patch);
19743
19800
  if (process.platform === "win32") {
19744
- fs29.rmSync(`${process.execPath}.old`, { force: true });
19801
+ fs30.rmSync(`${process.execPath}.old`, { force: true });
19745
19802
  }
19746
19803
  }
19747
19804
  schedule(delayMs) {
@@ -19817,7 +19874,7 @@ var UpdateController = class {
19817
19874
  const bin = manifest.binaries[platformKey()];
19818
19875
  if (!bin) return `\u6E05\u5355\u6CA1\u6709\u5F53\u524D\u5E73\u53F0\uFF08${platformKey()}\uFF09\u7684\u4EA7\u7269`;
19819
19876
  let stagedPath = state.stagedPath;
19820
- if (!(state.stagedVersion === manifest.version && stagedPath && fs29.existsSync(stagedPath))) {
19877
+ if (!(state.stagedVersion === manifest.version && stagedPath && fs30.existsSync(stagedPath))) {
19821
19878
  stagedPath = path36.join(
19822
19879
  updatesDir(this.opts.dataDir),
19823
19880
  "staged",
@@ -19830,7 +19887,7 @@ var UpdateController = class {
19830
19887
  }
19831
19888
  const selfTest = selfCheck(stagedPath, manifest.version);
19832
19889
  if (!selfTest.ok) {
19833
- fs29.rmSync(stagedPath, { force: true });
19890
+ fs30.rmSync(stagedPath, { force: true });
19834
19891
  this.recordFailure(manifest.version, selfTest.error ?? "\u81EA\u68C0\u5931\u8D25");
19835
19892
  return `\u5B89\u88C5\u5305\u81EA\u68C0\u5931\u8D25\uFF1A${selfTest.error}`;
19836
19893
  }
@@ -19971,7 +20028,7 @@ function pemFile(key) {
19971
20028
  const p = env2(key);
19972
20029
  if (!p) return void 0;
19973
20030
  try {
19974
- return fs30.readFileSync(p);
20031
+ return fs31.readFileSync(p);
19975
20032
  } catch (e) {
19976
20033
  console.warn(`[tls] \u8BFB\u53D6 ${key}=${p} \u5931\u8D25: ${e instanceof Error ? e.message : e}`);
19977
20034
  return void 0;
@@ -20656,17 +20713,17 @@ async function runUpdateCommand(argv) {
20656
20713
 
20657
20714
  // src/cli/sessionMeta.ts
20658
20715
  init_cjs_shims();
20659
- var fs31 = __toESM(require("fs"), 1);
20716
+ var fs32 = __toESM(require("fs"), 1);
20660
20717
  var path40 = __toESM(require("path"), 1);
20661
20718
  function updateSessionMetaFile(stateDir2, sessionId, patch) {
20662
20719
  const file = path40.join(stateDir2, `${sessionId}_state.json`);
20663
20720
  try {
20664
- const raw = fs31.readFileSync(file, "utf8");
20721
+ const raw = fs32.readFileSync(file, "utf8");
20665
20722
  const state = JSON.parse(raw);
20666
20723
  if (patch.name !== void 0) state.name = patch.name;
20667
20724
  if (patch.nameSource !== void 0) state.nameSource = patch.nameSource;
20668
20725
  if (patch.taskCount !== void 0) state.taskCount = patch.taskCount;
20669
- fs31.writeFileSync(file, JSON.stringify(state, null, 2), "utf8");
20726
+ fs32.writeFileSync(file, JSON.stringify(state, null, 2), "utf8");
20670
20727
  return true;
20671
20728
  } catch {
20672
20729
  return false;
@@ -20675,7 +20732,7 @@ function updateSessionMetaFile(stateDir2, sessionId, patch) {
20675
20732
 
20676
20733
  // src/cli/debug.ts
20677
20734
  init_cjs_shims();
20678
- var fs32 = __toESM(require("fs"), 1);
20735
+ var fs33 = __toESM(require("fs"), 1);
20679
20736
  var os8 = __toESM(require("os"), 1);
20680
20737
  var path41 = __toESM(require("path"), 1);
20681
20738
  var LOG_NAME = "zqagent-debug.log";
@@ -20706,8 +20763,8 @@ function enableDebug(argv = process.argv) {
20706
20763
  enabled = true;
20707
20764
  logFile = resolveLogFile();
20708
20765
  try {
20709
- fs32.mkdirSync(path41.dirname(logFile), { recursive: true });
20710
- fs32.writeFileSync(logFile, "");
20766
+ fs33.mkdirSync(path41.dirname(logFile), { recursive: true });
20767
+ fs33.writeFileSync(logFile, "");
20711
20768
  } catch {
20712
20769
  logFile = null;
20713
20770
  }
@@ -20724,7 +20781,7 @@ function dlog(stage, message = "") {
20724
20781
  const line = `[+${String(Date.now() - startedAt).padStart(6)}ms] [${stage}] ${message}`;
20725
20782
  if (logFile) {
20726
20783
  try {
20727
- fs32.appendFileSync(logFile, line + "\n");
20784
+ fs33.appendFileSync(logFile, line + "\n");
20728
20785
  } catch {
20729
20786
  }
20730
20787
  }
@@ -20889,13 +20946,13 @@ var MAX_ITERATIONS = parseMaxIterations(process.env.MAX_ITERATIONS, 300);
20889
20946
  var STATE_DIR = stateDir();
20890
20947
  function listSessions() {
20891
20948
  try {
20892
- const files = fs33.readdirSync(STATE_DIR);
20949
+ const files = fs34.readdirSync(STATE_DIR);
20893
20950
  const sessions = [];
20894
20951
  for (const f of files) {
20895
20952
  if (!f.endsWith("_state.json")) continue;
20896
20953
  try {
20897
20954
  const parsed = JSON.parse(
20898
- fs33.readFileSync(path42.join(STATE_DIR, f), "utf8")
20955
+ fs34.readFileSync(path42.join(STATE_DIR, f), "utf8")
20899
20956
  );
20900
20957
  if (parsed && typeof parsed.sessionId === "string") {
20901
20958
  sessions.push(parsed);
@@ -20932,8 +20989,8 @@ function printLastAssistantMessage(messages) {
20932
20989
  var AGENTS_FILE = path42.join(WORKSPACE, ".agent", "agents.json");
20933
20990
  function loadAgentsFromFile() {
20934
20991
  try {
20935
- if (!fs33.existsSync(AGENTS_FILE)) return [];
20936
- const raw = fs33.readFileSync(AGENTS_FILE, "utf8");
20992
+ if (!fs34.existsSync(AGENTS_FILE)) return [];
20993
+ const raw = fs34.readFileSync(AGENTS_FILE, "utf8");
20937
20994
  const parsed = JSON.parse(raw);
20938
20995
  if (!Array.isArray(parsed)) return [];
20939
20996
  return parsed.filter(
@@ -20945,8 +21002,8 @@ function loadAgentsFromFile() {
20945
21002
  }
20946
21003
  function saveAgentsToFile(defs) {
20947
21004
  try {
20948
- fs33.mkdirSync(path42.dirname(AGENTS_FILE), { recursive: true });
20949
- fs33.writeFileSync(AGENTS_FILE, JSON.stringify(defs, null, 2) + "\n", "utf8");
21005
+ fs34.mkdirSync(path42.dirname(AGENTS_FILE), { recursive: true });
21006
+ fs34.writeFileSync(AGENTS_FILE, JSON.stringify(defs, null, 2) + "\n", "utf8");
20950
21007
  } catch (err) {
20951
21008
  cliErr(`\u26A0\uFE0F \u4FDD\u5B58 agents \u914D\u7F6E\u5931\u8D25: ${err}`);
20952
21009
  }
@@ -20959,8 +21016,8 @@ var MCP_FILE = path42.join(WORKSPACE, ".agent", "mcp.json");
20959
21016
  var COMMAND_TOOLS_FILE = path42.join(WORKSPACE, ".agent", "tools.json");
20960
21017
  function loadJsonArray(file, validate) {
20961
21018
  try {
20962
- if (!fs33.existsSync(file)) return [];
20963
- const parsed = JSON.parse(fs33.readFileSync(file, "utf8"));
21019
+ if (!fs34.existsSync(file)) return [];
21020
+ const parsed = JSON.parse(fs34.readFileSync(file, "utf8"));
20964
21021
  if (!Array.isArray(parsed)) return [];
20965
21022
  if (!validate) return parsed;
20966
21023
  return parsed.filter((v) => validate(v));
@@ -20970,8 +21027,8 @@ function loadJsonArray(file, validate) {
20970
21027
  }
20971
21028
  function saveJsonFile(file, data) {
20972
21029
  try {
20973
- fs33.mkdirSync(path42.dirname(file), { recursive: true });
20974
- fs33.writeFileSync(file, JSON.stringify(data, null, 2) + "\n", "utf8");
21030
+ fs34.mkdirSync(path42.dirname(file), { recursive: true });
21031
+ fs34.writeFileSync(file, JSON.stringify(data, null, 2) + "\n", "utf8");
20975
21032
  } catch (err) {
20976
21033
  cliErr(`\u26A0\uFE0F \u4FDD\u5B58\u914D\u7F6E\u5931\u8D25: ${err}`);
20977
21034
  }
@@ -21072,7 +21129,7 @@ function pruneEmptySessions(keepSessionId) {
21072
21129
  if (!isEmptySession(s) || s.sessionId === keepSessionId) continue;
21073
21130
  for (const suffix of ["_state.json", ".jsonl"]) {
21074
21131
  try {
21075
- fs33.unlinkSync(path42.join(STATE_DIR, `${s.sessionId}${suffix}`));
21132
+ fs34.unlinkSync(path42.join(STATE_DIR, `${s.sessionId}${suffix}`));
21076
21133
  } catch {
21077
21134
  }
21078
21135
  }
@@ -21605,7 +21662,7 @@ async function offerTerminalSetup(engine, canUseAgent) {
21605
21662
  }
21606
21663
  var KNOWN_SUBCOMMANDS = /* @__PURE__ */ new Set(["link", "serve", "update"]);
21607
21664
  function cliVersion() {
21608
- const env3 = "0.2.6"?.trim();
21665
+ const env3 = "0.2.8"?.trim();
21609
21666
  if (env3) return env3;
21610
21667
  try {
21611
21668
  const req2 = (0, import_module.createRequire)(importMetaUrl);
@@ -21810,7 +21867,7 @@ async function main() {
21810
21867
  });
21811
21868
  const savedState = resumeId ? FileLogHook.loadState(resumeId, STATE_DIR) : null;
21812
21869
  const metaStateFile = path42.join(STATE_DIR, `${SESSION_ID}_state.json`);
21813
- const stateForMeta = savedState ?? (fs33.existsSync(metaStateFile) ? FileLogHook.loadState(SESSION_ID, STATE_DIR) : null);
21870
+ const stateForMeta = savedState ?? (fs34.existsSync(metaStateFile) ? FileLogHook.loadState(SESSION_ID, STATE_DIR) : null);
21814
21871
  sessionMeta = {
21815
21872
  sessionId: SESSION_ID,
21816
21873
  name: stateForMeta?.name,