dsh-planbox-dyb 0.8.4 → 0.8.5

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/README.md CHANGED
@@ -23,7 +23,7 @@ dsh plugin --profile web add dsh-planbox-dyb
23
23
  ## 面板
24
24
 
25
25
  - **手动**:你点「加入计划任务」手动登记的任务。
26
- - **发现**:模型登记、助手结尾出现「重启」和「需要」(间隔不超过 5 个字符,且「需要」前没有「不」),或从会话消息里扫到的任务。
26
+ - **发现**:模型登记、助手结尾出现「重启」和「需要」(间隔不超过 10 个字符,且间隔词不含「之前/以前/可能/不用/无需」),或从会话消息里扫到的任务。
27
27
  - **中断**:上一回合报错或崩溃中断的会话。
28
28
 
29
29
  同一个会话的回合放在一块,手动、发现、中断混排,按由旧到新排列。最近从计划任务点开过的会话排在最前,其余按任务更新时间排序。手动登记同一回合后,该回合的发现或中断记录让位,显示为手动。
package/client.js CHANGED
@@ -15,7 +15,7 @@ window.__ModuleLoader__.load({
15
15
  const NS = "planbox";
16
16
  const API = "/api/planbox";
17
17
  const POLL_MS = 60_000;
18
- const CLIENT_VERSION = "0.8.4";
18
+ const CLIENT_VERSION = "0.8.5";
19
19
 
20
20
  const FALLBACK = {
21
21
  open: "计划任务",
package/index.js CHANGED
@@ -56,15 +56,15 @@ const SCAN_CONCURRENCY = 6;
56
56
  const DEFAULT_ABNORMAL_WINDOW_MS = 7 * 24 * 60 * 60 * 1000;
57
57
  /** 助手结尾的“需要重启”只自动收最近 24 小时的会话,避免历史会话全部堆进来。 */
58
58
  const DEFAULT_RESTART_WINDOW_MS = 24 * 60 * 60 * 1000;
59
- const DEFAULT_RESTART_GAP = 5;
60
- const RESTART_NEEDED_PATTERN = (gap) => [
61
- new RegExp(`(?<!不)重启[\\s\\S]{0,${gap}}(?<!不)需要`),
62
- new RegExp(`(?<!不)需要[\\s\\S]{0,${gap}}(?<!不)重启`),
63
- ];
59
+ const DEFAULT_RESTART_GAP = 10;
60
+ /** 「重启…需要」里不该被当成待续的反向说法。 */
61
+ const RESTART_SKIP_PATTERN = /(?:之前|以前|可能|不用|无需)/;
62
+ const RESTART_HINT_PATTERNS = [/重启/, /需要/];
64
63
  const MARKER_PATTERNS = [
65
- /等?重启后(?:继续|接着)/,
66
- /等?重启再(?:继续|接着)?/,
67
- /重启(?:完成|好|之后)后?(?:继续|接着)/,
64
+ // 重启 / 重启完 / 重启好 / 重启之后 / 重启以后再继续……
65
+ /等?重启(?:完成|完|好)?(?:之后|以后|后|再)?\s*(?:继续|接着)/,
66
+ // 重启 DSH 后继续……
67
+ /重启\s*(?:DSH|dsh)\s*(?:之后|以后|后)\s*(?:再)?\s*(?:继续|接着)/i,
68
68
  /resume after (?:a )?restart/i,
69
69
  /continue after (?:a )?restart/i,
70
70
  ];
@@ -299,10 +299,23 @@ function withTimeout(signal, milliseconds) {
299
299
  }
300
300
 
301
301
  function readJson(file, fallback) {
302
+ let raw;
303
+ try {
304
+ raw = fs.readFileSync(file, 'utf8');
305
+ } catch (error) {
306
+ return fallback;
307
+ }
302
308
  try {
303
- const raw = fs.readFileSync(file, 'utf8');
304
309
  return JSON.parse(raw);
305
310
  } catch (error) {
311
+ // 文件存在但解析失败:备份成 .corrupt-<时间戳> 再按空数据继续,避免被后续写入静默覆盖。
312
+ try {
313
+ const stamp = new Date().toISOString().replace(/[:.]/g, '-');
314
+ fs.renameSync(file, `${file}.corrupt-${stamp}`);
315
+ console.warn(`[planbox-dyb] ${path.basename(file)} 解析失败,已备份为 .corrupt-* 并按空数据处理`);
316
+ } catch (renameError) {
317
+ /* 备份失败也不阻断 */
318
+ }
306
319
  return fallback;
307
320
  }
308
321
  }
@@ -565,7 +578,7 @@ function detectCandidate(summary, tail, turn, options) {
565
578
  // 中断回合之后又出现了用户消息:说明已被自动续跑插件或用户手动继续,
566
579
  // 不再作为「异常中断」重复列出。
567
580
  const promptedAfter =
568
- turn.at > 0 && tail.lastUserAt > turn.at;
581
+ !turn.open && turn.at > 0 && tail.lastUserAt > turn.at;
569
582
 
570
583
  if (summary.running !== true && !promptedAfter && withinWindow && isAbnormalTurn(turn)) {
571
584
  const detail =
@@ -599,7 +612,7 @@ function detectCandidate(summary, tail, turn, options) {
599
612
  kind: 'auto',
600
613
  sessionId,
601
614
  title: summaryTitle(summary),
602
- snippet: snippetAround(tail.lastAssistantText, RESTART_NEEDED_PATTERN(restartGapChars())),
615
+ snippet: snippetAround(tail.lastAssistantText, RESTART_HINT_PATTERNS),
603
616
  prompt: tailOf(tail.lastAssistantText, 240),
604
617
  anchor: normalizeAnchor(options.anchor),
605
618
  updatedAt: Number(summary.updatedAt ?? options.now),
@@ -641,10 +654,31 @@ export function restartWindowMs() {
641
654
  return hours === 0 ? Number.POSITIVE_INFINITY : hours * 60 * 60 * 1000;
642
655
  }
643
656
 
644
- /** 助手最后一条消息是否同时提到“重启”和“需要”(间隔内,且需要/重启前都不是“不”)。 */
645
- export function restartNeededIn(text) {
646
- const value = typeof text === 'string' ? text : '';
647
- return RESTART_NEEDED_PATTERN(restartGapChars()).some((pattern) => pattern.test(value));
657
+ /** 助手最后一条消息是否同时提到“重启”和“需要”(间隔内,排除反向说法)。 */
658
+ export function restartNeededIn(text, gap = restartGapChars()) {
659
+ const value = String(text ?? '').replace(/\s+/g, ' ');
660
+ if (value === '') return false;
661
+ let index = value.indexOf('重启');
662
+ while (index >= 0) {
663
+ if (value[index - 1] === '不') {
664
+ index = value.indexOf('重启', index + 2);
665
+ continue;
666
+ }
667
+ const after = value.slice(index + 2, index + 2 + gap + 2);
668
+ const needAfter = after.indexOf('需要');
669
+ if (needAfter >= 0 && value[index + 2 + needAfter - 1] !== '不') {
670
+ const between = after.slice(0, needAfter);
671
+ if (!RESTART_SKIP_PATTERN.test(between)) return true;
672
+ }
673
+ const before = value.slice(Math.max(0, index - gap - 2), index);
674
+ const needBefore = before.lastIndexOf('需要');
675
+ if (needBefore >= 0 && before[needBefore - 1] !== '不') {
676
+ const between = before.slice(needBefore + 2);
677
+ if (!RESTART_SKIP_PATTERN.test(between)) return true;
678
+ }
679
+ index = value.indexOf('重启', index + 2);
680
+ }
681
+ return false;
648
682
  }
649
683
 
650
684
  /**
@@ -995,6 +1029,9 @@ const resumingSessions = new Set();
995
1029
  */
996
1030
  export async function resumeSelected(ctx, store, options = {}) {
997
1031
  const ids = Array.isArray(options.ids) && options.ids.length > 0 ? options.ids : null;
1032
+ if (ids === null && options.all !== true) {
1033
+ throw new Error('未指定任务:请先用 planbox_list 取 id,或显式传 all: true 恢复全部任务。');
1034
+ }
998
1035
  const selected = ids
999
1036
  ? await itemsForIds(ctx, store, ids, options)
1000
1037
  : (await collectPending(ctx, store, { refresh: true, signal: options.signal })).items;
@@ -1201,7 +1238,8 @@ export function registerRoutes(ctx, store, connection) {
1201
1238
  try {
1202
1239
  const body = await request.json().catch(() => ({}));
1203
1240
  const ids = Array.isArray(body?.ids) ? body.ids.filter((id) => typeof id === 'string') : [];
1204
- const result = await resumeSelected(ctx, store, { ids });
1241
+ const all = body?.all === true;
1242
+ const result = await resumeSelected(ctx, store, { ids, all });
1205
1243
  return json(200, { ok: true, ...result });
1206
1244
  } catch (error) {
1207
1245
  return json(500, { ok: false, message: String(error?.message ?? error) });
@@ -1506,7 +1544,7 @@ export function createToolDefinitions(ctx, store) {
1506
1544
  const resumeTool = {
1507
1545
  name: 'planbox_resume',
1508
1546
  description:
1509
- '恢复计划任务:向对应会话投递续跑提示,冷会话会被唤醒开始新一轮。不传 ids 时恢复全部;投递成功后对应记录会被删除。',
1547
+ '恢复计划任务:向对应会话投递续跑提示,冷会话会被唤醒开始新一轮。传 ids 恢复指定任务;恢复全部必须显式传 all: true。投递成功后对应记录会被删除。',
1510
1548
  timeoutMs: 180_000,
1511
1549
  parameters: {
1512
1550
  type: 'object',
@@ -1515,7 +1553,11 @@ export function createToolDefinitions(ctx, store) {
1515
1553
  ids: {
1516
1554
  type: 'array',
1517
1555
  items: { type: 'string' },
1518
- description: '要恢复的任务 id;省略则恢复全部',
1556
+ description: '要恢复的任务 id;与 all 二选一',
1557
+ },
1558
+ all: {
1559
+ type: 'boolean',
1560
+ description: '显式恢复全部任务;不传 ids 且不传 all=true 时工具会报错,避免误恢复',
1519
1561
  },
1520
1562
  },
1521
1563
  },
@@ -1554,7 +1596,8 @@ export function createToolDefinitions(ctx, store) {
1554
1596
  },
1555
1597
  async execute(args) {
1556
1598
  const ids = Array.isArray(args?.ids) ? args.ids : undefined;
1557
- const result = await resumeSelected(ctx, store, { ids });
1599
+ const all = args?.all === true;
1600
+ const result = await resumeSelected(ctx, store, { ids, all });
1558
1601
  return { ok: true, ...result };
1559
1602
  },
1560
1603
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-planbox-dyb",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "PlanBox:DSH 计划任务收件箱——重启前登记、重启后审核并恢复中断任务。宿主 Windows / macOS / Linux,客户端任意现代浏览器(含 iOS / iPadOS Safari)。",
5
5
  "license": "MIT",
6
6
  "author": "ZhibinYU",