jbc-dssi 1.1.109 → 1.1.111

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/index.js CHANGED
@@ -112,6 +112,21 @@ function pluginVersion() {
112
112
  }
113
113
  }
114
114
 
115
+ /**
116
+ * **进程启动时冻结**的插件版本(2026-11-10 老谢定:App 侧"必须重启"弹窗的判据)。
117
+ *
118
+ * 为什么必须冻结:pluginVersion() 是"每次现读 package.json"——
119
+ * npm 在 dsh 运行期间把包版本换成 1.1.110 之后,它立刻返回 1.1.110,
120
+ * 但**内存里跑的仍然是 1.1.109 的代码**。拿现读值当"运行版本",
121
+ * 就永远判断不出"装了新版、没重启"这件事。
122
+ *
123
+ * 所以:
124
+ * · LOADED_VERSION = 启动时的代码版本(下面这个常量);
125
+ * · pluginInstalledVersion = HELLO 里现读的磁盘版本;
126
+ * · 两者不同 = 需要重启 dsh 才生效 → 手机据此弹"立即重启"。
127
+ */
128
+ const LOADED_VERSION = pluginVersion();
129
+
115
130
  export const name = 'jbc-dssi';
116
131
 
117
132
  /**
@@ -1833,6 +1848,15 @@ class BridgeConnection {
1833
1848
  this.send(FRAME.HELLO, {
1834
1849
  protocol: PROTOCOL_VERSION,
1835
1850
  authRequired: opts.token !== null,
1851
+ /*
1852
+ * 插件版本上报(2026-11-10,只加字段不改行为):
1853
+ * · pluginVersion = 进程启动时冻结的版本(内存里跑的代码);
1854
+ * · pluginInstalledVersion = 磁盘上安装的版本(每次现读 package.json)。
1855
+ * 手机侧据此判断"是否必须重启 dsh 才能用新功能"——
1856
+ * 现读值 ≥ App 要求 而 冻结值 < App 要求 → 弹「立即重启」。
1857
+ */
1858
+ pluginVersion: LOADED_VERSION,
1859
+ pluginInstalledVersion: pluginVersion(),
1836
1860
  /*
1837
1861
  * 能力声明(只做加法,老 App 不认识就忽略)。
1838
1862
  * 手机据此决定「团队」tab 是显示数据还是显示"电脑侧插件需更新"。
@@ -2840,6 +2864,8 @@ class BridgeConnection {
2840
2864
  *
2841
2865
  * 纯新增字段:老 App 不认识就忽略;老插件不发 → 新 App 判为"插件需更新"。
2842
2866
  */
2867
+ pluginVersion: LOADED_VERSION,
2868
+ pluginInstalledVersion: pluginVersion(),
2843
2869
  caps: [
2844
2870
  ...(this.bots ? ['bots'] : []),
2845
2871
  ...(this.dssAgent ? ['dssAgent'] : []),
@@ -98,7 +98,12 @@ export const PROC_DEFAULTS = [
98
98
  danger: 'high',
99
99
  confirmText: '重启电脑侧 dsh web 会断开当前连接,约 60 秒后自动核验并回群。',
100
100
  timeoutMs: 120_000,
101
- args: [],
101
+ /*
102
+ * silent:App 弹窗触发的重启传 "1" —— 手机上有状态弹窗在显示"重启中/成功",
103
+ * 重启后的群内核验消息(restart-autocheck)就跳过。程序指令页手动点的不传,
104
+ * 行为与以前完全一致(60 秒后群里出核验消息)。
105
+ */
106
+ args: [{ name: 'silent', label: '静默(不往群里发核验)', required: false, pattern: '^(0|1)$' }],
102
107
  // 排程型:先回执、再(延迟)重启;脚本本身是冻结脚本,一个字都不改
103
108
  script: { rel: 'scripts/restart-dsh-web.py', detached: true, delayMs: 1500 },
104
109
  },
@@ -114,6 +119,14 @@ export function defaultRunsDir() {
114
119
  return join(homedir(), '.dsh', 'jbc-dssi', 'proc-runs');
115
120
  }
116
121
 
122
+ /**
123
+ * App 弹窗重启的"静默标记"默认路径(与 lib/restart-autocheck.js 的 cfg.silentFlag 同一处)。
124
+ * 重启前写下 → 重启后 autocheck 读到并消费 → 跳过群消息与主管接续。
125
+ */
126
+ export function defaultSilentFlag() {
127
+ return join(homedir(), '.dsh', 'jbc-dssi', 'restart-silent.flag');
128
+ }
129
+
117
130
  /* ------------------------------------------------------------------ 校验 */
118
131
 
119
132
  /** 一条白名单 spec 是否可用(坏配置跳过,不因此让整个能力失效)。 */
@@ -258,6 +271,8 @@ export function createProcEngine(opts = {}) {
258
271
  probePort = (p) => probeTcpPort(p),
259
272
  now = () => Date.now(),
260
273
  homeDir = homedir(),
274
+ /** App 弹窗重启的静默标记路径(测试注入临时目录用)。 */
275
+ silentFlag = defaultSilentFlag(),
261
276
  } = opts;
262
277
 
263
278
  /** id -> spec(内置 + 白名单文件,文件同 id 覆盖内置)。 */
@@ -552,6 +567,20 @@ export function createProcEngine(opts = {}) {
552
567
  }
553
568
  if (cmd.script?.detached === true) {
554
569
  const delay = Number.isFinite(cmd.script.delayMs) ? cmd.script.delayMs : 1500;
570
+ /*
571
+ * 静默重启(App 弹窗触发):先落一张标记,重启后的 restart-autocheck 读到就
572
+ * 跳过群内核验消息 —— 状态由手机上的弹窗显示(2026-11-10 老谢要求)。
573
+ */
574
+ if (String(record.args?.silent ?? '') === '1') {
575
+ try {
576
+ const flag = cmd.script?.silentFlag || silentFlag;
577
+ fs.mkdirSync(join(flag, '..'), { recursive: true });
578
+ fs.writeFileSync(flag, `${new Date(now()).toISOString()} app-dialog
579
+ `, 'utf8');
580
+ } catch (err) {
581
+ log(`[proc] 写静默标记失败(不影响重启):${err?.message ?? err}`);
582
+ }
583
+ }
555
584
  spawnDetached(cmd, scriptPath, [], delay);
556
585
  finish(record, {
557
586
  exitCode: 0,
@@ -18,7 +18,7 @@
18
18
  */
19
19
 
20
20
  import { createHash } from 'node:crypto';
21
- import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from 'node:fs';
21
+ import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
22
22
  import { get } from 'node:http';
23
23
  import { connect } from 'node:net';
24
24
  import { dirname, join } from 'node:path';
@@ -31,6 +31,12 @@ const DEFAULTS = {
31
31
  marker: '/tmp/dsh-restart-result.txt',
32
32
  cooldownMs: 6 * 60 * 60_000,
33
33
  notifyGroup: true,
34
+ /**
35
+ * App 弹窗触发的重启的"静默标记"(2026-11-10)。
36
+ * 重启前由 proc 执行器写下;重启后本模块读到就消费掉,并**跳过群消息与主管接续** ——
37
+ * 那时手机上已有状态弹窗在显示"重启中/成功/失败",群里不该再多一条。
38
+ */
39
+ silentFlag: join(homedir(), '.dsh', 'jbc-dssi', 'restart-silent.flag'),
34
40
  resumeSession: true,
35
41
  groupId: '',
36
42
  dshWebPort: 3080,
@@ -177,6 +183,21 @@ export function createRestartAutocheck({ ctx, log, config = {}, groups = null, p
177
183
  const checkBaseline = deps.checkBaseline ?? ((markerMtimeMs) => baselineCheck({ markerMtimeMs, config: cfg, log }));
178
184
  const readExpectedVersion = deps.readExpectedVersion ?? (() => resolveExpectedVersion(cfg));
179
185
  const postGroupLine = deps.postGroupLine ?? (async (groupId, line) => groups?.postSystemLine?.(groupId, line));
186
+ /** 读并消费"App 弹窗重启"静默标记(存在 → true 并删除;测试可注入)。 */
187
+ const consumeSilentFlag = deps.consumeSilentFlag ?? (() => {
188
+ try {
189
+ if (!cfg.silentFlag || !existsSync(cfg.silentFlag)) return false;
190
+ /*
191
+ * 只认"新鲜"标记(10 分钟内):万一某次重启没起来、标记留在磁盘上,
192
+ * 不能被下一次(无关的)重启核验误当成"App 弹窗重启"而静默掉。
193
+ */
194
+ const age = now() - statSync(cfg.silentFlag).mtimeMs;
195
+ unlinkSync(cfg.silentFlag);
196
+ return age >= 0 && age <= 10 * 60_000;
197
+ } catch {
198
+ return false;
199
+ }
200
+ });
180
201
  const promptManager = deps.promptManager ?? (async (sessionId, text) => {
181
202
  const controller = ctx?.sessionController;
182
203
  if (!controller?.prompt || !sessionId) return false;
@@ -298,6 +319,16 @@ export function createRestartAutocheck({ ctx, log, config = {}, groups = null, p
298
319
  }
299
320
  const text = baseText + pendingNote;
300
321
 
322
+ /*
323
+ * App 弹窗触发的重启:手机上已有状态弹窗在显示"重启中/重启成功/失败",
324
+ * 群聊里**不再出现核验消息**、也不触发主管接续(2026-11-10 老谢要求)。
325
+ * 判据:proc 执行器在重启前写下 silent 标记;这里读到就消费掉并静默返回。
326
+ */
327
+ if (consumeSilentFlag()) {
328
+ log?.('[autocheck] 本次重启由 App 弹窗触发(silent 标记)→ 跳过群消息与主管接续');
329
+ return { ok, missing, text, checkedAt, silent: true };
330
+ }
331
+
301
332
  /** 通道 1:群消息(以主管身份落一行;posts 后返回主管会话信息,供通道 2 复用)。 */
302
333
  let groupInfo = null;
303
334
  if (cfg.notifyGroup) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbc-dssi",
3
- "version": "1.1.109",
3
+ "version": "1.1.111",
4
4
  "type": "module",
5
5
  "description": "鲸编程 - 不只是手机遥控操作电脑,而是将电脑级的Agent能力装进手机",
6
6
  "keywords": [