jbc-dssi 1.1.106 → 1.1.107

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.
@@ -6,6 +6,8 @@
6
6
  * 电脑侧按白名单执行本地脚本,回传摘要 + 结果文件路径;完整日志留在电脑。
7
7
  * · **手机不能传 shell、路径、可执行文件** —— 白名单里没有的 id 一律拒绝。
8
8
  * · 危险指令(发版/重启/停服务…)必须:手机二次确认 + 一次性 nonce(30s、用一次即废)。
9
+ * · **票据按需领取**(2026-11-09 真机修复):nonce 由 `proc_ticket` 在"用户点确认的瞬间"签发,
10
+ * 不是打开页面时预取 —— 否则用户看一眼说明再确认,30 秒早过了,重启永远点不动。
9
11
  * · 同一指令单飞;危险级共用一把全局锁(防发版/重启踩踏);到点超时杀进程。
10
12
  * · 每次执行留痕:`proc-runs/<runId>.log`(脚本输出)+ `proc-runs/index.jsonl`(一行一条)。
11
13
  *
@@ -262,21 +264,28 @@ export function createProcEngine(opts = {}) {
262
264
  });
263
265
  return {
264
266
  commands: items,
265
- // 高危指令要用这张一次性票据;30s 内有效、用一次即废
267
+ // 兼容老 App(1.1.106):它从 proc_list 取票。新 App 改用 proc_ticket 按需领票。
266
268
  nonce: issueNonce(),
267
269
  nonceTtlMs: NONCE_TTL_MS,
268
270
  version: String(version ?? ''),
269
271
  };
270
272
  }
271
273
 
272
- function issueNonce() {
273
- nonce = { value: randomBytes(16).toString('hex'), expiresAt: now() + NONCE_TTL_MS };
274
+ /**
275
+ * 签一张一次性确认票据。
276
+ *
277
+ * @param {string|null} cmdId 绑定到哪条指令;null = 不绑定(老路径 proc_list 兼容用)。
278
+ * 同时只保留**一张**有效票:新票签发即作废旧票(防止开两个确认弹窗后旧票还能用)。
279
+ */
280
+ function issueNonce(cmdId = null) {
281
+ nonce = { value: randomBytes(16).toString('hex'), expiresAt: now() + NONCE_TTL_MS, cmdId };
274
282
  return nonce.value;
275
283
  }
276
284
 
277
- function consumeNonce(given) {
278
- if (!nonce || now() > nonce.expiresAt) throw new Error('确认已过期,请刷新页面后重试');
279
- if (typeof given !== 'string' || given !== nonce.value) throw new Error('确认票据无效,请刷新页面后重试');
285
+ function consumeNonce(cmdId, given) {
286
+ if (!nonce || now() > nonce.expiresAt) throw new Error('确认已过期,请重新点执行');
287
+ if (nonce.cmdId != null && nonce.cmdId !== cmdId) throw new Error('确认票据与指令不匹配,请重新点执行');
288
+ if (typeof given !== 'string' || given !== nonce.value) throw new Error('确认票据无效,请重新点执行');
280
289
  nonce = null;
281
290
  }
282
291
 
@@ -499,12 +508,33 @@ export function createProcEngine(opts = {}) {
499
508
  /** 统一命令入口(`proc_*`)。与 dssAgent 的 command 同形状:同步校验、异步执行。 */
500
509
  async function command(op, payload = {}) {
501
510
  if (op === 'proc_list') return list();
511
+ if (op === 'proc_ticket') return ticket(payload);
502
512
  if (op === 'proc_run') return runCommand(payload);
503
513
  if (op === 'proc_status') return status(payload);
504
514
  if (op === 'proc_cancel') return cancel(payload);
505
515
  throw new Error(`未知的程序指令命令:${op}`);
506
516
  }
507
517
 
518
+ /**
519
+ * 领一张绑定到某条指令的一次性确认票据(用户点"确认"后再领,30 秒内立刻用掉)。
520
+ *
521
+ * 为什么不复用 proc_list 里的票:那张是打开页面时签的,用户看说明、犹豫一下就会过期
522
+ * (2026-11-09 真机反馈:体检能跑、重启报"确认已过期")。票据的生命周期应该从
523
+ * "用户真的决定执行"那一刻开始。
524
+ */
525
+ function ticket(payload) {
526
+ const cmdId = typeof payload?.cmdId === 'string' ? payload.cmdId : '';
527
+ const cmd = commands.get(cmdId);
528
+ if (!cmd) throw new Error(`没有这条程序指令:${cmdId || '(空)'}`);
529
+ if (!cmd.builtin) {
530
+ const scriptPath = resolveScript(cmd, repoRoot);
531
+ if (!scriptPath || !fs.existsSync(scriptPath)) {
532
+ throw new Error('电脑侧未配置仓库根目录或脚本不存在');
533
+ }
534
+ }
535
+ return { nonce: issueNonce(cmd.id), cmdId: cmd.id, ttlMs: NONCE_TTL_MS };
536
+ }
537
+
508
538
  function runCommand(payload) {
509
539
  const cmdId = typeof payload?.cmdId === 'string' ? payload.cmdId : '';
510
540
  const cmd = commands.get(cmdId);
@@ -513,7 +543,7 @@ export function createProcEngine(opts = {}) {
513
543
  if (cmd.danger !== 'low') {
514
544
  if (payload?.confirm !== true) throw new Error(`「${cmd.name}」需要二次确认`);
515
545
  }
516
- if (cmd.danger === 'high') consumeNonce(payload?.nonce);
546
+ if (cmd.danger === 'high') consumeNonce(cmd.id, payload?.nonce);
517
547
  if (activeByCmd.has(cmd.id)) throw new Error(`「${cmd.name}」正在执行中,请等它结束`);
518
548
  if (cmd.danger !== 'low' && activeHigh) throw new Error('有其它危险指令正在执行,稍后再试');
519
549
  if (!cmd.builtin) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jbc-dssi",
3
- "version": "1.1.106",
3
+ "version": "1.1.107",
4
4
  "type": "module",
5
5
  "description": "鲸编程 - 不只是手机遥控操作电脑,而是将电脑级的Agent能力装进手机",
6
6
  "keywords": [