@zqagent/core 0.2.12 → 0.2.15

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.
@@ -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.12",
11399
+ version: "0.2.15",
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.12",
12392
+ version: "0.2.15",
12393
12393
  mode: process.env.NODE_MODE ?? "standalone",
12394
12394
  cpu: {
12395
12395
  count: cpus2.length,
@@ -12759,6 +12759,24 @@ function createApp(store, manager, opts = {}) {
12759
12759
  ok(res, opts.fleet.status());
12760
12760
  }
12761
12761
  },
12762
+ // 修改本机节点显示名:写本地配置并立即上报;已接入 Hub 时同步 Hub 记录。
12763
+ // `zqagent rename` 在有 server 在跑时走这里(热生效,免重启)。
12764
+ {
12765
+ method: "POST",
12766
+ pattern: ["fleet", "label"],
12767
+ adminOnly: true,
12768
+ fn: async (_req, res, { body }) => {
12769
+ if (!opts.fleet) {
12770
+ throw new ApiError(503, "fleet_disabled", "\u8282\u70B9\u7BA1\u7406\u63A7\u5236\u5668\u672A\u542F\u7528");
12771
+ }
12772
+ const raw = body ?? {};
12773
+ const label2 = typeof raw.label === "string" ? raw.label.trim() : "";
12774
+ if (!label2) {
12775
+ throw new ApiError(400, "bad_request", "label \u4E0D\u80FD\u4E3A\u7A7A");
12776
+ }
12777
+ ok(res, await opts.fleet.rename(label2));
12778
+ }
12779
+ },
12762
12780
  // 运行时热接入:凭一次性注册码或 Hub 账号接入(落盘 fleet.json + 立即连接,免重启)
12763
12781
  {
12764
12782
  method: "POST",
@@ -13978,7 +13996,7 @@ function createApp(store, manager, opts = {}) {
13978
13996
  json(res, 200, {
13979
13997
  status: "ok",
13980
13998
  // 版本让运维/探针能确认线上跑的是哪个构建(更新与回滚据此判断)
13981
- version: "0.2.12",
13999
+ version: "0.2.15",
13982
14000
  features: { mcp: hasServerMcpConfig() }
13983
14001
  });
13984
14002
  return;
@@ -15672,6 +15690,11 @@ var FleetNodeBridge = class {
15672
15690
  refreshInfo() {
15673
15691
  this._publishInfo();
15674
15692
  }
15693
+ /** 本地改名后把 status(含 label)与 info 立即重发,控制台不必等下一次周期上报 */
15694
+ republishLabel() {
15695
+ this._send({ kind: "status", status: this._status(this.isConnected()) });
15696
+ this._publishInfo();
15697
+ }
15675
15698
  // ===================== 内部 =====================
15676
15699
  _status(online) {
15677
15700
  return {
@@ -15681,7 +15704,7 @@ var FleetNodeBridge = class {
15681
15704
  label: this.opts.deps.store.loadNodeLabel() ?? void 0,
15682
15705
  platform: process.platform,
15683
15706
  mode: process.env.NODE_MODE ?? "standalone",
15684
- version: "0.2.12",
15707
+ version: "0.2.15",
15685
15708
  ip: primaryIp()
15686
15709
  };
15687
15710
  }
@@ -15700,7 +15723,23 @@ var FleetNodeBridge = class {
15700
15723
  byDay: days
15701
15724
  };
15702
15725
  }
15726
+ /**
15727
+ * 上报 info(项目/会话快照)。
15728
+ *
15729
+ * 失败必须留痕:这是控制台「项目列表」的唯一数据源,静默失败会表现为
15730
+ * 「这台节点永远没有任何项目」,且只能靠网关 detail=null 才发现。
15731
+ * 同时用 try 包住,避免一次读盘异常中断 `_onUp` 后续的状态通知。
15732
+ */
15703
15733
  _publishInfo() {
15734
+ try {
15735
+ this._publishInfoNow();
15736
+ } catch (e) {
15737
+ console.warn(
15738
+ `[fleet] \u8282\u70B9 ${this.nodeId} \u4E0A\u62A5 info \u5931\u8D25: ${e instanceof Error ? e.message : String(e)}`
15739
+ );
15740
+ }
15741
+ }
15742
+ _publishInfoNow() {
15704
15743
  const totals = { projects: 0, sessions: 0, running: 0, waiting: 0 };
15705
15744
  const sessions = [];
15706
15745
  const projects = allProjectSummaries(this.opts.deps.store).map((p) => {
@@ -15727,7 +15766,15 @@ var FleetNodeBridge = class {
15727
15766
  totals.sessions += p.sessionCount;
15728
15767
  totals.running += running;
15729
15768
  totals.waiting += waiting;
15730
- return { id: p.id, name: p.name, sessionCount: p.sessionCount, running, waiting };
15769
+ return {
15770
+ id: p.id,
15771
+ name: p.name,
15772
+ sessionCount: p.sessionCount,
15773
+ running,
15774
+ waiting,
15775
+ // 控制台项目列表要展示工作目录(Hub 落盘快照后即可离线查看)
15776
+ workspaceRoot: p.workspaceRoot ?? null
15777
+ };
15731
15778
  });
15732
15779
  this._send({
15733
15780
  kind: "info",
@@ -15736,7 +15783,7 @@ var FleetNodeBridge = class {
15736
15783
  label: this.opts.deps.store.loadNodeLabel() ?? void 0,
15737
15784
  platform: process.platform,
15738
15785
  mode: process.env.NODE_MODE ?? "standalone",
15739
- version: "0.2.12",
15786
+ version: "0.2.15",
15740
15787
  ip: primaryIp(),
15741
15788
  projects,
15742
15789
  totals,
@@ -15946,6 +15993,14 @@ function resolveFleetConfig(store) {
15946
15993
  return fleetConfigFromEnv(store);
15947
15994
  }
15948
15995
 
15996
+ // src/node-name.ts
15997
+ init_esm_shims();
15998
+ import * as os8 from "os";
15999
+ function defaultNodeLabel() {
16000
+ const name = os8.hostname().trim();
16001
+ return name || "zqagent-node";
16002
+ }
16003
+
15949
16004
  // src/server/notify/index.ts
15950
16005
  init_esm_shims();
15951
16006
 
@@ -17196,6 +17251,12 @@ async function hubEnrollByAccount(baseUrl, input) {
17196
17251
  });
17197
17252
  return { hubUrl: baseUrl.replace(/\/$/, ""), ...data };
17198
17253
  }
17254
+ async function hubUpdateNodeLabelSelf(baseUrl, fleetToken, input) {
17255
+ return await req(baseUrl, fleetToken, "/api/hub/nodes/self/label", {
17256
+ method: "POST",
17257
+ body: JSON.stringify(input)
17258
+ });
17259
+ }
17199
17260
 
17200
17261
  // src/update/controller.ts
17201
17262
  init_esm_shims();
@@ -17455,12 +17516,12 @@ function selfCheck(binPath, expectedVersion) {
17455
17516
  // src/update/platform.ts
17456
17517
  init_esm_shims();
17457
17518
  import * as fs25 from "fs";
17458
- import * as os8 from "os";
17519
+ import * as os9 from "os";
17459
17520
  import * as path30 from "path";
17460
17521
  import { spawnSync as spawnSync3 } from "child_process";
17461
17522
  import { createRequire as createRequire3 } from "module";
17462
17523
  function currentVersion() {
17463
- const injected = "0.2.12"?.trim();
17524
+ const injected = "0.2.15"?.trim();
17464
17525
  if (injected) return injected;
17465
17526
  try {
17466
17527
  const req2 = createRequire3(import.meta.url);
@@ -17498,7 +17559,7 @@ function launchdPlistPath() {
17498
17559
  const label2 = launchdLabel();
17499
17560
  const uid = typeof process.getuid === "function" ? process.getuid() : -1;
17500
17561
  if (uid === 0) return `/Library/LaunchDaemons/${label2}.plist`;
17501
- return path30.join(os8.homedir(), "Library", "LaunchAgents", `${label2}.plist`);
17562
+ return path30.join(os9.homedir(), "Library", "LaunchAgents", `${label2}.plist`);
17502
17563
  }
17503
17564
  function serviceManagerFromLaunchctl(output, pid, execPath, sea = true) {
17504
17565
  const pidMatch = /^\s*pid = (\d+)\s*$/m.exec(output);
@@ -18294,7 +18355,7 @@ function startServer(opts = {}) {
18294
18355
  hubUrl: fleetCred?.hubUrl,
18295
18356
  gatewayUrl: fleetCred?.gatewayUrl ?? env2("FLEET_GATEWAY_URL"),
18296
18357
  online: fleet?.isConnected() ?? false,
18297
- label: fleetCred?.label,
18358
+ label: fleetCred?.label ?? store.loadNodeLabel() ?? void 0,
18298
18359
  lastError: fleet?.getLastError() ?? void 0,
18299
18360
  reconnectCount: fleet?.getErrorCount() ?? 0
18300
18361
  };
@@ -18303,27 +18364,53 @@ function startServer(opts = {}) {
18303
18364
  status: fleetStatus,
18304
18365
  async enroll(input) {
18305
18366
  const nodeId = ensureNodeId(store);
18367
+ const label2 = input.label?.trim() || defaultNodeLabel();
18306
18368
  const cred = input.account ? await hubEnrollByAccount(input.hubUrl, {
18307
18369
  email: input.account.email,
18308
18370
  phone: input.account.phone,
18309
18371
  password: input.account.password,
18310
18372
  code: input.account.smsCode,
18311
18373
  nodeId,
18312
- label: input.label
18374
+ label: label2
18313
18375
  }) : await hubEnrollByCode(input.hubUrl, {
18314
18376
  code: input.code,
18315
18377
  nodeId,
18316
- label: input.label
18378
+ label: label2
18317
18379
  });
18318
18380
  const full = {
18319
18381
  ...cred,
18320
- label: input.label ?? cred.label,
18382
+ label: label2,
18321
18383
  enrolledAt: (/* @__PURE__ */ new Date()).toISOString()
18322
18384
  };
18323
18385
  store.saveFleetCredential(full);
18386
+ store.saveNodeLabel(label2);
18324
18387
  connectFleet(full);
18325
18388
  return fleetStatus();
18326
18389
  },
18390
+ async rename(label2) {
18391
+ const name = label2.trim();
18392
+ store.saveNodeLabel(name);
18393
+ if (fleetCred) {
18394
+ fleetCred = { ...fleetCred, label: name };
18395
+ store.saveFleetCredential(fleetCred);
18396
+ }
18397
+ fleet?.republishLabel();
18398
+ let hubSynced = false;
18399
+ let hubError;
18400
+ const cred = fleetCred;
18401
+ if (cred?.hubUrl && cred.fleetToken) {
18402
+ try {
18403
+ await hubUpdateNodeLabelSelf(cred.hubUrl, cred.fleetToken, {
18404
+ nodeId: ensureNodeId(store),
18405
+ label: name
18406
+ });
18407
+ hubSynced = true;
18408
+ } catch (e) {
18409
+ hubError = e instanceof Error ? e.message : String(e);
18410
+ }
18411
+ }
18412
+ return { ...fleetStatus(), hubSynced, hubError };
18413
+ },
18327
18414
  unlink() {
18328
18415
  fleet?.close();
18329
18416
  fleet = null;
@@ -18618,16 +18705,18 @@ async function runWizard(rl, store, opts) {
18618
18705
  const prompted = await promptLinkAccount(rl, opts.hubUrl);
18619
18706
  if (!prompted) return;
18620
18707
  const nodeId = ensureNodeId(store);
18708
+ const label2 = opts.label?.trim() || defaultNodeLabel();
18621
18709
  const cred = await hubEnrollByAccount(prompted.hubUrl, {
18622
18710
  ...prompted.auth,
18623
18711
  nodeId,
18624
- label: opts.label
18712
+ label: label2
18625
18713
  });
18626
18714
  store.saveFleetCredential({
18627
18715
  ...cred,
18628
- label: opts.label ?? cred.label,
18716
+ label: label2,
18629
18717
  enrolledAt: (/* @__PURE__ */ new Date()).toISOString()
18630
18718
  });
18719
+ store.saveNodeLabel(label2);
18631
18720
  cliLog(`\u2705 \u5DF2\u63A5\u5165 Hub\uFF1A\u8282\u70B9 ${cred.nodeId}\uFF08\u7F51\u5173 ${cred.gatewayUrl ?? "\u672A\u4E0B\u53D1"}\uFF09`);
18632
18721
  cliLog(" \u51ED\u636E\u5DF2\u4FDD\u5B58\u5230 fleet.json\uFF0C\u672C\u6B21\u542F\u52A8\u5373\u8FDE\u63A5 Hub\u3002");
18633
18722
  }
@@ -18687,7 +18776,7 @@ import * as readline2 from "readline";
18687
18776
  init_esm_shims();
18688
18777
  import { spawnSync as spawnSync4 } from "child_process";
18689
18778
  import * as fs30 from "fs";
18690
- import * as os9 from "os";
18779
+ import * as os10 from "os";
18691
18780
  import * as path36 from "path";
18692
18781
 
18693
18782
  // src/cli/link.ts