dsh-planbox-dyb 0.8.2 → 0.8.4
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 +11 -9
- package/client.js +450 -133
- package/index.js +169 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,26 +18,28 @@ dsh plugin --profile web add dsh-planbox-dyb
|
|
|
18
18
|
|
|
19
19
|
1. 模型会在需要重启时主动登记;你也可以点每轮回答下方的「加入计划任务」。
|
|
20
20
|
2. 重启后打开侧栏底部的「计划任务」(右上角红点是数量)。
|
|
21
|
-
3.
|
|
21
|
+
3. 先点「建议」看模型打算怎么继续,再决定「中断恢复」或「忽略」。
|
|
22
22
|
|
|
23
23
|
## 面板
|
|
24
24
|
|
|
25
|
-
-
|
|
26
|
-
-
|
|
27
|
-
-
|
|
25
|
+
- **手动**:你点「加入计划任务」手动登记的任务。
|
|
26
|
+
- **发现**:模型登记、助手结尾出现「重启」和「需要」(间隔不超过 5 个字符,且「需要」前没有「不」),或从会话消息里扫到的任务。
|
|
27
|
+
- **中断**:上一回合报错或崩溃中断的会话。
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
同一个会话的回合放在一块,手动、发现、中断混排,按由旧到新排列。最近从计划任务点开过的会话排在最前,其余按任务更新时间排序。手动登记同一回合后,该回合的发现或中断记录让位,显示为手动。
|
|
30
|
+
|
|
31
|
+
每行会标注对应的「第 N 轮」对话;同会话的手动登记和发现结果分开显示。手动登记会记下你点的是哪一轮,之后从这一轮开头查看。
|
|
30
32
|
|
|
31
33
|
按钮:
|
|
32
34
|
|
|
33
35
|
- **建议**:把续跑建议填进输入框,不发送;输入框已有内容会先确认是否从下一行追加。
|
|
34
|
-
-
|
|
36
|
+
- **详情**:在当前行展开完整说明、下一步和校验信息;点整行仍跳到对应会话;行内保留「第 N 轮」锚点。跳转期间行内标签旁显示「跳转中…」,完成或超时后消失。
|
|
35
37
|
- **忽略**:删除这一条;扫描/异常项会隐藏到该会话下次更新。
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
+
- **全部忽略**:确认后清空当前列表;点确认框以外的位置会取消确认。
|
|
39
|
+
- **中断恢复**:只处理「中断」,每项发一句「继续」;发送成功后记录删除,不跟踪后续进度。
|
|
38
40
|
|
|
39
41
|
## 注意
|
|
40
42
|
|
|
41
43
|
- 只支持 DSH Web;headless 没有面板。
|
|
42
44
|
- 不自动续跑、不跟踪任务是否完成,进度需要你自己看会话。
|
|
43
|
-
-
|
|
45
|
+
- 可以和自动续跑插件共存;已被自动续跑的会话会从「中断」消失,「中断恢复」投递前也会复核,不会重复发。
|
package/client.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* dsh-planbox-dyb — 浏览器侧。
|
|
3
3
|
*
|
|
4
4
|
* 侧栏底部一个“计划任务”入口:列出已登记的计划任务和扫描到的“等重启后继续”会话。
|
|
5
|
-
* 面板只做审核:建议 / 查看 /
|
|
5
|
+
* 面板只做审核:建议 / 查看 / 忽略;底部的「中断恢复」只对异常中断项投递一句「继续」。
|
|
6
6
|
* 面板浮在侧栏上方,点遮罩或 Esc 关闭。
|
|
7
7
|
*/
|
|
8
8
|
window.__ModuleLoader__.load({
|
|
@@ -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.
|
|
18
|
+
const CLIENT_VERSION = "0.8.4";
|
|
19
19
|
|
|
20
20
|
const FALLBACK = {
|
|
21
21
|
open: "计划任务",
|
|
@@ -24,21 +24,23 @@ window.__ModuleLoader__.load({
|
|
|
24
24
|
refresh: "重新扫描",
|
|
25
25
|
empty: "没有发现计划任务。在会话里说“重启后继续”,或点回答下方的「加入计划任务」登记。",
|
|
26
26
|
hint: "扫描会话中…",
|
|
27
|
-
queueTag: "
|
|
28
|
-
scanTag: "
|
|
29
|
-
abnormalTag: "
|
|
30
|
-
registeredSection: "
|
|
31
|
-
abnormalSection: "
|
|
32
|
-
pinnedSection: "
|
|
33
|
-
scannedSection: "
|
|
27
|
+
queueTag: "手动",
|
|
28
|
+
scanTag: "发现",
|
|
29
|
+
abnormalTag: "中断",
|
|
30
|
+
registeredSection: "手动({n})",
|
|
31
|
+
abnormalSection: "中断({n})",
|
|
32
|
+
pinnedSection: "当前详情",
|
|
33
|
+
scannedSection: "发现({n})",
|
|
34
|
+
sessionCount: "{n} 条",
|
|
34
35
|
running: "运行中",
|
|
35
36
|
anchorTurn: "第 {turn} 轮",
|
|
36
37
|
anchorTurnSeq: "第 {turn} 轮 · #{seq}",
|
|
37
38
|
anchorSeq: "消息 #{seq}",
|
|
38
|
-
|
|
39
|
+
jumping: "跳转中",
|
|
39
40
|
resume: "继续",
|
|
40
|
-
view: "
|
|
41
|
-
|
|
41
|
+
view: "详情",
|
|
42
|
+
detailEmpty: "无更多详情",
|
|
43
|
+
resumeAll: "中断恢复",
|
|
42
44
|
ignoreAll: "全部忽略",
|
|
43
45
|
ignoreAllConfirm: "确定忽略全部 {n} 项?扫描/中断项会写入忽略记录。",
|
|
44
46
|
ignoreAllOk: "确定",
|
|
@@ -65,8 +67,6 @@ window.__ModuleLoader__.load({
|
|
|
65
67
|
fillAppendText: "是否从下一行开始填入建议?",
|
|
66
68
|
fillOk: "确定",
|
|
67
69
|
fillCancel: "取消",
|
|
68
|
-
fillDone: "已填入建议",
|
|
69
|
-
fillCopied: "无法直接填入,已复制到剪贴板",
|
|
70
70
|
fillFailed: "填入失败:{message}",
|
|
71
71
|
};
|
|
72
72
|
|
|
@@ -80,20 +80,22 @@ window.__ModuleLoader__.load({
|
|
|
80
80
|
empty:
|
|
81
81
|
"No pending tasks found. Say “continue after restart” in a session, or use “Add to pending” under a reply.",
|
|
82
82
|
hint: "Scanning sessions…",
|
|
83
|
-
queueTag: "
|
|
83
|
+
queueTag: "Manual",
|
|
84
84
|
scanTag: "Found",
|
|
85
|
-
abnormalTag: "
|
|
86
|
-
registeredSection: "
|
|
87
|
-
abnormalSection: "
|
|
85
|
+
abnormalTag: "Interrupted",
|
|
86
|
+
registeredSection: "Manual ({n})",
|
|
87
|
+
abnormalSection: "Interrupted ({n})",
|
|
88
88
|
pinnedSection: "Viewing",
|
|
89
|
-
scannedSection: "
|
|
89
|
+
scannedSection: "Found ({n})",
|
|
90
|
+
sessionCount: "{n} items",
|
|
90
91
|
running: "Running",
|
|
91
92
|
anchorTurn: "Turn {turn}",
|
|
92
93
|
anchorTurnSeq: "Turn {turn} · #{seq}",
|
|
93
94
|
anchorSeq: "Message #{seq}",
|
|
94
|
-
|
|
95
|
+
jumping: "Jumping",
|
|
95
96
|
resume: "Resume",
|
|
96
|
-
view: "
|
|
97
|
+
view: "Details",
|
|
98
|
+
detailEmpty: "No more details",
|
|
97
99
|
resumeAll: "Restore interrupted",
|
|
98
100
|
ignoreAll: "Ignore all",
|
|
99
101
|
ignoreAllConfirm: "Ignore all {n}? Scanned and interrupted items will be hidden.",
|
|
@@ -121,8 +123,6 @@ window.__ModuleLoader__.load({
|
|
|
121
123
|
fillAppendText: "Append the suggestion below the existing text?",
|
|
122
124
|
fillOk: "Append",
|
|
123
125
|
fillCancel: "Cancel",
|
|
124
|
-
fillDone: "Suggestion filled",
|
|
125
|
-
fillCopied: "Copied to clipboard instead",
|
|
126
126
|
fillFailed: "Fill failed: {message}",
|
|
127
127
|
};
|
|
128
128
|
|
|
@@ -219,9 +219,6 @@ window.__ModuleLoader__.load({
|
|
|
219
219
|
".dpb-tail-btn[data-state=\"error\"]{color:#ff9a9d;border-color:rgba(255,154,157,.5)}",
|
|
220
220
|
".dpb-badge{position:absolute;top:-4px;right:-4px;min-width:15px;height:15px;padding:0 4px;border-radius:999px;background:#e5484d;color:#fff;font-size:10px;line-height:15px;text-align:center;font-variant-numeric:tabular-nums;box-shadow:0 0 0 2px var(--dsw-alias-bg-layer-1,#1e1e1f)}",
|
|
221
221
|
".dpb-backdrop{position:fixed;inset:0;background:transparent;z-index:79}",
|
|
222
|
-
".dpb-toast{position:fixed;left:12px;bottom:100px;z-index:81;padding:7px 10px;border-radius:8px;background:var(--dsw-alias-bg-layer-1,#1e1e1f);border:1px solid var(--dsw-elevation-stroke-color,rgba(255,255,255,.12));box-shadow:0 8px 24px rgba(0,0,0,.35);font-size:12px;color:var(--dsw-alias-label-primary,#e8eaed)}",
|
|
223
|
-
".dpb-toast.ok{color:#8fd18f}",
|
|
224
|
-
".dpb-toast.bad{color:#ff9a9d}",
|
|
225
222
|
".dpb-modal-backdrop{position:fixed;inset:0;z-index:90;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.45)}",
|
|
226
223
|
".dpb-modal{width:min(360px,calc(100vw - 40px));padding:16px 18px 12px;border-radius:12px;background:var(--dsw-alias-bg-layer-1,#1e1e1f);border:1px solid var(--dsw-elevation-stroke-color,rgba(255,255,255,.14));box-shadow:0 18px 46px rgba(0,0,0,.5);color:var(--dsw-alias-label-primary,#e8eaed);font-size:13px;box-sizing:border-box}",
|
|
227
224
|
".dpb-modal-title{font-weight:600;margin-bottom:6px}",
|
|
@@ -257,12 +254,24 @@ window.__ModuleLoader__.load({
|
|
|
257
254
|
".dpb-tag.queue{background:rgba(76,141,255,.18);color:#9dbcff}",
|
|
258
255
|
".dpb-tag.abnormal{background:rgba(229,72,77,.16);color:#ff9a9d}",
|
|
259
256
|
".dpb-tag.scan{background:rgba(255,196,0,.16);color:#e7c063}",
|
|
257
|
+
".dpb-jumping{flex:none;display:inline-flex;align-items:center;gap:3px;font-size:10px;line-height:15px;color:var(--dsw-alias-state-business-primary,#4c8dff)}",
|
|
258
|
+
".dpb-dots{display:inline-flex;gap:1px}",
|
|
259
|
+
".dpb-dots i{width:2px;height:2px;border-radius:50%;background:currentColor;animation:dpb-jumping-dot 1.1s infinite ease-in-out}",
|
|
260
|
+
".dpb-dots i:nth-child(2){animation-delay:.18s}",
|
|
261
|
+
".dpb-dots i:nth-child(3){animation-delay:.36s}",
|
|
262
|
+
"@keyframes dpb-jumping-dot{0%,80%,100%{opacity:.2}40%{opacity:1}}",
|
|
260
263
|
".dpb-section{padding:9px 9px 3px;font-size:10.5px;line-height:15px;letter-spacing:.03em;color:var(--dsw-alias-label-tertiary,#8b8f95)}",
|
|
264
|
+
".dpb-session{margin:0 0 6px;padding:0 4px 4px;border-left:2px solid var(--dsw-alias-border-secondary,rgba(255,255,255,.08))}",
|
|
265
|
+
".dpb-session-head{display:flex;align-items:center;gap:6px;padding:5px 5px 3px;font-size:10.5px;line-height:15px;color:var(--dsw-alias-label-secondary,#b6bac0)}",
|
|
266
|
+
".dpb-session-title{min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:600}",
|
|
267
|
+
".dpb-session-count{flex:none;color:var(--dsw-alias-label-tertiary,#8b8f95);font-variant-numeric:tabular-nums}",
|
|
261
268
|
".dpb-section-pinned{color:var(--dsw-alias-state-business-primary,#4c8dff);font-weight:600}",
|
|
262
269
|
".dpb-section-abnormal{color:#ff9a9d}",
|
|
263
270
|
".dpb-next{font-size:11px;line-height:16px;color:#9dbcff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
|
|
264
271
|
".dpb-snippet{font-size:11.5px;line-height:17px;color:var(--dsw-alias-label-secondary,#b6bac0);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere}",
|
|
265
272
|
".dpb-meta{display:flex;align-items:center;gap:5px;font-size:10.5px;line-height:15px;color:var(--dsw-alias-label-tertiary,#8b8f95);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
|
|
273
|
+
".dpb-detail{margin-top:7px;padding:8px 9px;border-radius:8px;background:rgba(128,128,128,.1);font-size:11.5px;line-height:18px;color:var(--dsw-alias-label-secondary,#b6bac0);white-space:pre-wrap;word-break:break-word;max-height:260px;overflow:auto;cursor:text}",
|
|
274
|
+
".dpb-detail-anchor{margin-top:6px;color:var(--dsw-alias-label-tertiary,#8b8f95);font-size:10.5px}",
|
|
266
275
|
".dpb-anchor{flex:none;color:var(--dsw-alias-state-business-primary,#4c8dff)}",
|
|
267
276
|
".dpb-dot{opacity:.6}",
|
|
268
277
|
".dpb-row-actions{flex:none;display:flex;align-items:center;gap:2px}",
|
|
@@ -340,13 +349,74 @@ window.__ModuleLoader__.load({
|
|
|
340
349
|
});
|
|
341
350
|
}
|
|
342
351
|
// 会话切换可能导致组件的宿主重新挂载;把面板开关和置顶项记在模块级,避免“查看”后面板消失。
|
|
343
|
-
const panelState = { open: false, pinnedId: null };
|
|
352
|
+
const panelState = { open: false, pinnedId: null, jumpingId: null };
|
|
353
|
+
const RECENT_KEY = "dsh-planbox-dyb:recent-sessions";
|
|
344
354
|
|
|
345
|
-
function
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
355
|
+
function readRecentSessions() {
|
|
356
|
+
const recent = new Map();
|
|
357
|
+
try {
|
|
358
|
+
const raw = globalThis.localStorage?.getItem(RECENT_KEY);
|
|
359
|
+
if (typeof raw !== "string" || raw === "") return recent;
|
|
360
|
+
const parsed = JSON.parse(raw);
|
|
361
|
+
for (const [sessionId, at] of Object.entries(parsed ?? {})) {
|
|
362
|
+
const value = Number(at);
|
|
363
|
+
if (typeof sessionId === "string" && Number.isFinite(value)) recent.set(sessionId, value);
|
|
364
|
+
}
|
|
365
|
+
} catch {
|
|
366
|
+
/* 读取失败就按内存顺序 */
|
|
367
|
+
}
|
|
368
|
+
return recent;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
const recentSessions = readRecentSessions();
|
|
372
|
+
|
|
373
|
+
function markSessionOpened(sessionId) {
|
|
374
|
+
if (typeof sessionId !== "string" || sessionId === "") return;
|
|
375
|
+
recentSessions.set(sessionId, Date.now());
|
|
376
|
+
try {
|
|
377
|
+
globalThis.localStorage?.setItem(
|
|
378
|
+
RECENT_KEY,
|
|
379
|
+
JSON.stringify(Object.fromEntries(recentSessions)),
|
|
380
|
+
);
|
|
381
|
+
} catch {
|
|
382
|
+
/* 存不下就只保留内存顺序 */
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function emitJumping() {
|
|
387
|
+
if (
|
|
388
|
+
typeof window !== "undefined" &&
|
|
389
|
+
typeof window.dispatchEvent === "function" &&
|
|
390
|
+
typeof CustomEvent !== "undefined"
|
|
391
|
+
) {
|
|
392
|
+
window.dispatchEvent(new CustomEvent("dsh-planbox-dyb:jumping"));
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function setJumping(id) {
|
|
397
|
+
panelState.jumpingId = id;
|
|
398
|
+
emitJumping();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function finishJump(id) {
|
|
402
|
+
if (panelState.jumpingId !== id) return;
|
|
403
|
+
panelState.jumpingId = null;
|
|
404
|
+
emitJumping();
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function kindOfItem(item) {
|
|
408
|
+
if (item?.kind === "manual" || item?.kind === "auto" || item?.kind === "interrupted") {
|
|
409
|
+
return item.kind;
|
|
349
410
|
}
|
|
411
|
+
if (item?.source === "abnormal") return "interrupted";
|
|
412
|
+
if (item?.source === "queue" && item?.origin !== "model") return "manual";
|
|
413
|
+
return "auto";
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function tagFor(item) {
|
|
417
|
+
const kind = kindOfItem(item);
|
|
418
|
+
if (kind === "interrupted") return { key: "abnormalTag", className: "abnormal" };
|
|
419
|
+
if (kind === "manual") return { key: "queueTag", className: "queue" };
|
|
350
420
|
return { key: "scanTag", className: "scan" };
|
|
351
421
|
}
|
|
352
422
|
|
|
@@ -381,8 +451,141 @@ window.__ModuleLoader__.load({
|
|
|
381
451
|
return "";
|
|
382
452
|
}
|
|
383
453
|
|
|
454
|
+
/** 已渲染时滚到回合开头:从 turn-tail 往前找到上一回合边界后的第一个节点。 */
|
|
455
|
+
function scrollTurnStart(turn, root = document) {
|
|
456
|
+
const scope = root ?? document;
|
|
457
|
+
const tail = scope.querySelector?.(`[data-turn-tail="${turn}"]`);
|
|
458
|
+
if (tail === null || tail === undefined) return false;
|
|
459
|
+
let first = tail;
|
|
460
|
+
let node = tail;
|
|
461
|
+
while (node.previousElementSibling !== null) {
|
|
462
|
+
const previous = node.previousElementSibling;
|
|
463
|
+
if (previous.matches?.("[data-turn-tail]")) break;
|
|
464
|
+
first = previous;
|
|
465
|
+
node = previous;
|
|
466
|
+
}
|
|
467
|
+
first.scrollIntoView({ block: "start", behavior: "auto" });
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/** 回合导航是虚拟列表;目标回合不在可视区时先滚动导航轨,再点它的按钮。 */
|
|
472
|
+
function nudgeTurnRail(root, turn) {
|
|
473
|
+
const buttons = [...root.querySelectorAll("button[data-index][aria-label]")];
|
|
474
|
+
if (buttons.length === 0) return false;
|
|
475
|
+
let scroller = buttons[0].parentElement;
|
|
476
|
+
while (scroller !== null) {
|
|
477
|
+
const overflow =
|
|
478
|
+
typeof getComputedStyle === "function"
|
|
479
|
+
? getComputedStyle(scroller).overflowY
|
|
480
|
+
: scroller.style.overflowY;
|
|
481
|
+
if (
|
|
482
|
+
scroller.scrollHeight > scroller.clientHeight &&
|
|
483
|
+
(overflow === "auto" || overflow === "scroll")
|
|
484
|
+
) {
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
scroller = scroller.parentElement;
|
|
488
|
+
}
|
|
489
|
+
if (scroller === null || scroller.clientHeight === 0) return false;
|
|
490
|
+
let offset = null;
|
|
491
|
+
for (const button of buttons) {
|
|
492
|
+
const label = button.getAttribute("aria-label") || "";
|
|
493
|
+
const labelTurn = /第\s*(\d+)\s*轮/.exec(label) ?? /turn\s+(\d+)/i.exec(label);
|
|
494
|
+
const index = Number(button.getAttribute("data-index"));
|
|
495
|
+
if (labelTurn !== null && Number.isFinite(index)) {
|
|
496
|
+
offset = Number(labelTurn[1]) - index;
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
if (offset === null) return false;
|
|
501
|
+
const targetIndex = turn - offset;
|
|
502
|
+
const targetTop = Math.max(
|
|
503
|
+
0,
|
|
504
|
+
Math.min(
|
|
505
|
+
scroller.scrollHeight - scroller.clientHeight,
|
|
506
|
+
targetIndex * 10 + 6 - scroller.clientHeight / 2,
|
|
507
|
+
),
|
|
508
|
+
);
|
|
509
|
+
scroller.scrollTop = targetTop;
|
|
510
|
+
return true;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
/** 打开会话后尽量定位到锚点回合开头;只在新会话挂载后操作,避免误点旧会话的导航。 */
|
|
514
|
+
function revealTurn(turn, sessionId, onDone) {
|
|
515
|
+
let settled = false;
|
|
516
|
+
const done = () => {
|
|
517
|
+
if (settled) return;
|
|
518
|
+
settled = true;
|
|
519
|
+
if (typeof onDone === "function") onDone();
|
|
520
|
+
};
|
|
521
|
+
if (!(turn > 0) || typeof document === "undefined") {
|
|
522
|
+
done();
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
let attempts = 0;
|
|
526
|
+
let railNudged = false;
|
|
527
|
+
const tick = () => {
|
|
528
|
+
if (settled) return;
|
|
529
|
+
const matches = sessionId
|
|
530
|
+
? document.querySelectorAll(`[data-conversation-session="${sessionId}"]`)
|
|
531
|
+
: [];
|
|
532
|
+
const root = sessionId
|
|
533
|
+
? [...matches].find(
|
|
534
|
+
(element) =>
|
|
535
|
+
element.querySelector("[data-turn-tail], button[data-index]") !== null,
|
|
536
|
+
) ?? null
|
|
537
|
+
: document;
|
|
538
|
+
if (sessionId && root === null) {
|
|
539
|
+
attempts += 1;
|
|
540
|
+
if (attempts < 200) globalThis.setTimeout(tick, 120);
|
|
541
|
+
else done();
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
const buttons = root.querySelectorAll("button[data-index][aria-label]");
|
|
545
|
+
for (const button of buttons) {
|
|
546
|
+
if (button.disabled || button.getAttribute("aria-busy") === "true") continue;
|
|
547
|
+
const label = button.getAttribute("aria-label") || "";
|
|
548
|
+
if (
|
|
549
|
+
label.includes(`第 ${turn} 轮`) ||
|
|
550
|
+
new RegExp(`\\bturn ${turn}\\b`, "i").test(label)
|
|
551
|
+
) {
|
|
552
|
+
button.click();
|
|
553
|
+
// 按钮触发的是 DSH 自己的加载/滚动,留一点时间让指示器覆盖这段等待。
|
|
554
|
+
globalThis.setTimeout(done, 1_200);
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
if (!railNudged && nudgeTurnRail(root, turn)) {
|
|
559
|
+
railNudged = true;
|
|
560
|
+
attempts += 1;
|
|
561
|
+
globalThis.setTimeout(tick, 180);
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
if (scrollTurnStart(turn, root)) {
|
|
565
|
+
done();
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
attempts += 1;
|
|
569
|
+
if (attempts < 200) globalThis.setTimeout(tick, 120);
|
|
570
|
+
else done();
|
|
571
|
+
};
|
|
572
|
+
globalThis.setTimeout(tick, 180);
|
|
573
|
+
}
|
|
574
|
+
|
|
384
575
|
function Row(props) {
|
|
385
|
-
const {
|
|
576
|
+
const {
|
|
577
|
+
item,
|
|
578
|
+
t,
|
|
579
|
+
busy,
|
|
580
|
+
pinned,
|
|
581
|
+
hideTitle,
|
|
582
|
+
jumping,
|
|
583
|
+
expanded = false,
|
|
584
|
+
onOpen,
|
|
585
|
+
onDismiss,
|
|
586
|
+
onSuggest,
|
|
587
|
+
onDetail,
|
|
588
|
+
} = props;
|
|
386
589
|
const queue = item.source === "queue";
|
|
387
590
|
const tag = tagFor(item);
|
|
388
591
|
const detail = queue ? item.snippet || item.prompt : item.snippet;
|
|
@@ -392,9 +595,22 @@ window.__ModuleLoader__.load({
|
|
|
392
595
|
anchor === "" || !item.anchor?.at
|
|
393
596
|
? anchor
|
|
394
597
|
: `${anchor} · ${new Date(item.anchor.at).toLocaleString()}`;
|
|
395
|
-
// 整行可点:和「查看」同一条路径(跳转 + 置顶),行内按钮自己 stopPropagation。
|
|
396
|
-
const open = () => onOpen(item.sessionId, item.id, item.anchor);
|
|
397
598
|
const next = nextStep(item);
|
|
599
|
+
const detailParts = [];
|
|
600
|
+
if (full !== "") detailParts.push(full);
|
|
601
|
+
if (next !== null) detailParts.push(next.full);
|
|
602
|
+
if (item.snapshot?.filesTouched?.length) {
|
|
603
|
+
detailParts.push(`涉及文件:\n${item.snapshot.filesTouched.join("\n")}`);
|
|
604
|
+
}
|
|
605
|
+
if (item.snapshot?.verifyCommand) detailParts.push(`验证:${item.snapshot.verifyCommand}`);
|
|
606
|
+
if (item.snapshot?.lastFailedCommand) {
|
|
607
|
+
detailParts.push(`上次失败:${item.snapshot.lastFailedCommand}`);
|
|
608
|
+
}
|
|
609
|
+
const detailText = detailParts.join("\n\n");
|
|
610
|
+
const toggle = () => {
|
|
611
|
+
if (typeof onDetail === "function") onDetail(item);
|
|
612
|
+
};
|
|
613
|
+
const open = () => onOpen(item.sessionId, item.id, item.anchor);
|
|
398
614
|
return h(
|
|
399
615
|
"div",
|
|
400
616
|
{
|
|
@@ -416,23 +632,46 @@ window.__ModuleLoader__.load({
|
|
|
416
632
|
h(
|
|
417
633
|
"div",
|
|
418
634
|
{ className: "dpb-row-head" },
|
|
419
|
-
h("span", { className: "dpb-title"
|
|
635
|
+
hideTitle ? null : h("span", { className: "dpb-title" }, item.title),
|
|
420
636
|
h("span", { className: "dpb-tag " + tag.className }, t(tag.key)),
|
|
637
|
+
jumping
|
|
638
|
+
? h(
|
|
639
|
+
"span",
|
|
640
|
+
{ className: "dpb-jumping", "aria-live": "polite" },
|
|
641
|
+
t("jumping"),
|
|
642
|
+
h(
|
|
643
|
+
"span",
|
|
644
|
+
{ className: "dpb-dots", "aria-hidden": "true" },
|
|
645
|
+
h("i", null),
|
|
646
|
+
h("i", null),
|
|
647
|
+
h("i", null),
|
|
648
|
+
),
|
|
649
|
+
)
|
|
650
|
+
: null,
|
|
421
651
|
),
|
|
422
|
-
detail
|
|
423
|
-
|
|
424
|
-
: null,
|
|
425
|
-
next ? h("div", { className: "dpb-next", title: next.full }, next.text) : null,
|
|
652
|
+
detail ? h("div", { className: "dpb-snippet" }, detail) : null,
|
|
653
|
+
next ? h("div", { className: "dpb-next" }, next.text) : null,
|
|
426
654
|
h(
|
|
427
655
|
"div",
|
|
428
656
|
{ className: "dpb-meta" },
|
|
429
|
-
anchor !== ""
|
|
430
|
-
? h("span", { className: "dpb-anchor", title: anchorTitle }, anchor)
|
|
431
|
-
: null,
|
|
657
|
+
anchor !== "" ? h("span", { className: "dpb-anchor" }, anchor) : null,
|
|
432
658
|
h("span", null, ago(t, item.updatedAt)),
|
|
433
659
|
item.running ? h("span", { className: "dpb-dot" }, "·") : null,
|
|
434
660
|
item.running ? h("span", null, t("running")) : null,
|
|
435
661
|
),
|
|
662
|
+
expanded
|
|
663
|
+
? h(
|
|
664
|
+
"div",
|
|
665
|
+
{
|
|
666
|
+
className: "dpb-detail",
|
|
667
|
+
onClick: (event) => event.stopPropagation(),
|
|
668
|
+
},
|
|
669
|
+
h("div", { className: "dpb-detail-text" }, detailText === "" ? t("detailEmpty") : detailText),
|
|
670
|
+
anchorTitle !== ""
|
|
671
|
+
? h("div", { className: "dpb-detail-anchor" }, anchorTitle)
|
|
672
|
+
: null,
|
|
673
|
+
)
|
|
674
|
+
: null,
|
|
436
675
|
),
|
|
437
676
|
h(
|
|
438
677
|
"div",
|
|
@@ -461,7 +700,7 @@ window.__ModuleLoader__.load({
|
|
|
461
700
|
"aria-label": t("view"),
|
|
462
701
|
onClick: (event) => {
|
|
463
702
|
event.stopPropagation();
|
|
464
|
-
|
|
703
|
+
toggle();
|
|
465
704
|
},
|
|
466
705
|
},
|
|
467
706
|
t("view"),
|
|
@@ -485,34 +724,78 @@ window.__ModuleLoader__.load({
|
|
|
485
724
|
);
|
|
486
725
|
}
|
|
487
726
|
|
|
488
|
-
/**
|
|
727
|
+
/** 「中断恢复」只处理异常中断项。 */
|
|
489
728
|
function restorableItems(items) {
|
|
490
|
-
return items.filter((item) => item
|
|
729
|
+
return items.filter((item) => kindOfItem(item) === "interrupted");
|
|
491
730
|
}
|
|
492
731
|
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
),
|
|
500
|
-
|
|
732
|
+
/** 按会话聚合,手动/发现/中断混排;最近点开过的会话优先,其余按任务最近更新。 */
|
|
733
|
+
function groupSessions(items, recent = recentSessions) {
|
|
734
|
+
const groups = new Map();
|
|
735
|
+
for (const item of items) {
|
|
736
|
+
const key = item.sessionId ?? "";
|
|
737
|
+
const group = groups.get(key);
|
|
738
|
+
if (group === undefined) groups.set(key, [item]);
|
|
739
|
+
else group.push(item);
|
|
740
|
+
}
|
|
741
|
+
const latest = (group) => Math.max(...group.map((item) => Number(item.updatedAt ?? 0)));
|
|
742
|
+
return [...groups.entries()]
|
|
743
|
+
.map(([sessionId, group]) => ({
|
|
744
|
+
sessionId,
|
|
745
|
+
title: String(group[0]?.title ?? ""),
|
|
746
|
+
openedAt: Number(recent?.get(sessionId) ?? 0),
|
|
747
|
+
items: group.sort(
|
|
748
|
+
(left, right) =>
|
|
749
|
+
Number(left.anchor?.turn ?? 0) - Number(right.anchor?.turn ?? 0) ||
|
|
750
|
+
Number(left.anchor?.at ?? left.updatedAt ?? 0) -
|
|
751
|
+
Number(right.anchor?.at ?? right.updatedAt ?? 0) ||
|
|
752
|
+
Number(left.updatedAt ?? 0) - Number(right.updatedAt ?? 0),
|
|
753
|
+
),
|
|
754
|
+
}))
|
|
755
|
+
.sort(
|
|
756
|
+
(left, right) =>
|
|
757
|
+
(right.openedAt || latest(right.items)) - (left.openedAt || latest(left.items)),
|
|
758
|
+
);
|
|
501
759
|
}
|
|
502
760
|
|
|
503
|
-
/**
|
|
761
|
+
/** 把正在查看的任务单独置顶,其余按会话聚合。 */
|
|
504
762
|
function orderPending(items, pinnedId) {
|
|
505
763
|
const pinned = items.find((item) => item.id === pinnedId) ?? null;
|
|
506
764
|
const rest = pinned === null ? items : items.filter((item) => item.id !== pinnedId);
|
|
507
|
-
return { pinned,
|
|
765
|
+
return { pinned, sessions: groupSessions(rest) };
|
|
508
766
|
}
|
|
509
767
|
|
|
510
768
|
function Panel(props) {
|
|
511
|
-
const { t, items, loading, busy, busyAction, error, result, pinnedId, onClose, onRefresh, onResume, onOpen, onDismiss, onSuggest, onDismissAll } = props;
|
|
769
|
+
const { t, items, loading, busy, busyAction, error, result, pinnedId, jumpingId, onClose, onRefresh, onResume, onOpen, onDismiss, onSuggest, onDismissAll } = props;
|
|
512
770
|
const [confirmDismiss, setConfirmDismiss] = React.useState(false);
|
|
513
|
-
|
|
771
|
+
const [detailId, setDetailId] = React.useState(null);
|
|
772
|
+
const confirmRef = React.useRef(null);
|
|
773
|
+
const ignoreAllRef = React.useRef(null);
|
|
774
|
+
// 「中断恢复」只处理异常中断项,其余任务由用户自己审核。
|
|
514
775
|
const interrupted = restorableItems(items);
|
|
515
776
|
|
|
777
|
+
React.useEffect(() => {
|
|
778
|
+
if (detailId !== null && !items.some((item) => item.id === detailId)) {
|
|
779
|
+
setDetailId(null);
|
|
780
|
+
}
|
|
781
|
+
}, [detailId, items]);
|
|
782
|
+
|
|
783
|
+
const toggleDetail = React.useCallback((item) => {
|
|
784
|
+
setDetailId((current) => (current === item.id ? null : item.id));
|
|
785
|
+
}, []);
|
|
786
|
+
|
|
787
|
+
React.useEffect(() => {
|
|
788
|
+
if (!confirmDismiss) return undefined;
|
|
789
|
+
const onPointerDown = (event) => {
|
|
790
|
+
const target = event.target;
|
|
791
|
+
if (confirmRef.current?.contains(target)) return;
|
|
792
|
+
if (ignoreAllRef.current?.contains(target)) return;
|
|
793
|
+
setConfirmDismiss(false);
|
|
794
|
+
};
|
|
795
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
796
|
+
return () => document.removeEventListener("pointerdown", onPointerDown, true);
|
|
797
|
+
}, [confirmDismiss]);
|
|
798
|
+
|
|
516
799
|
React.useEffect(() => {
|
|
517
800
|
const onKeyDown = (event) => {
|
|
518
801
|
if (event.key !== "Escape") return;
|
|
@@ -530,7 +813,7 @@ window.__ModuleLoader__.load({
|
|
|
530
813
|
} else if (items.length === 0) {
|
|
531
814
|
body = h("div", { className: "dpb-hint" }, t("empty"));
|
|
532
815
|
} else {
|
|
533
|
-
const { pinned,
|
|
816
|
+
const { pinned, sessions } = orderPending(items, pinnedId);
|
|
534
817
|
const nodes = [];
|
|
535
818
|
if (pinned !== null) {
|
|
536
819
|
nodes.push(
|
|
@@ -541,50 +824,55 @@ window.__ModuleLoader__.load({
|
|
|
541
824
|
),
|
|
542
825
|
);
|
|
543
826
|
nodes.push(
|
|
544
|
-
h(Row, {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
827
|
+
h(Row, {
|
|
828
|
+
key: pinned.id,
|
|
829
|
+
item: pinned,
|
|
830
|
+
t,
|
|
831
|
+
busy,
|
|
832
|
+
pinned: true,
|
|
833
|
+
jumping: jumpingId === pinned.id,
|
|
834
|
+
expanded: detailId === pinned.id,
|
|
835
|
+
onOpen,
|
|
836
|
+
onDismiss,
|
|
837
|
+
onSuggest,
|
|
838
|
+
onDetail: toggleDetail,
|
|
839
|
+
}),
|
|
554
840
|
);
|
|
555
|
-
for (const item of registered) {
|
|
556
|
-
nodes.push(
|
|
557
|
-
h(Row, { key: item.id, item, t, busy, onOpen, onDismiss, onSuggest }),
|
|
558
|
-
);
|
|
559
|
-
}
|
|
560
841
|
}
|
|
561
|
-
|
|
562
|
-
|
|
842
|
+
for (let index = 0; index < sessions.length; index += 1) {
|
|
843
|
+
const group = sessions[index];
|
|
844
|
+
const groupNodes = [
|
|
563
845
|
h(
|
|
564
846
|
"div",
|
|
565
|
-
{ className: "dpb-
|
|
566
|
-
|
|
847
|
+
{ className: "dpb-session-head", key: "head" },
|
|
848
|
+
h("span", { className: "dpb-session-title" }, group.title === "" ? t("title") : group.title),
|
|
849
|
+
h("span", { className: "dpb-session-count" }, t("sessionCount", { n: group.items.length })),
|
|
567
850
|
),
|
|
568
|
-
|
|
569
|
-
for (const item of
|
|
570
|
-
|
|
571
|
-
h(Row, {
|
|
851
|
+
];
|
|
852
|
+
for (const item of group.items) {
|
|
853
|
+
groupNodes.push(
|
|
854
|
+
h(Row, {
|
|
855
|
+
key: item.id,
|
|
856
|
+
item,
|
|
857
|
+
t,
|
|
858
|
+
busy,
|
|
859
|
+
hideTitle: true,
|
|
860
|
+
jumping: jumpingId === item.id,
|
|
861
|
+
expanded: detailId === item.id,
|
|
862
|
+
onOpen,
|
|
863
|
+
onDismiss,
|
|
864
|
+
onSuggest,
|
|
865
|
+
onDetail: toggleDetail,
|
|
866
|
+
}),
|
|
572
867
|
);
|
|
573
868
|
}
|
|
574
|
-
}
|
|
575
|
-
if (scanned.length > 0) {
|
|
576
869
|
nodes.push(
|
|
577
870
|
h(
|
|
578
871
|
"div",
|
|
579
|
-
{ className: "dpb-
|
|
580
|
-
|
|
872
|
+
{ className: "dpb-session", key: `session-${index}` },
|
|
873
|
+
groupNodes,
|
|
581
874
|
),
|
|
582
875
|
);
|
|
583
|
-
for (const item of scanned) {
|
|
584
|
-
nodes.push(
|
|
585
|
-
h(Row, { key: item.id, item, t, busy, onOpen, onDismiss, onSuggest }),
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
876
|
}
|
|
589
877
|
body = nodes;
|
|
590
878
|
}
|
|
@@ -643,7 +931,7 @@ window.__ModuleLoader__.load({
|
|
|
643
931
|
confirmDismiss
|
|
644
932
|
? h(
|
|
645
933
|
"div",
|
|
646
|
-
{ className: "dpb-confirm" },
|
|
934
|
+
{ className: "dpb-confirm", ref: confirmRef },
|
|
647
935
|
h("span", { className: "dpb-confirm-text" }, t("ignoreAllConfirm", { n: items.length })),
|
|
648
936
|
h(
|
|
649
937
|
"button",
|
|
@@ -680,7 +968,8 @@ window.__ModuleLoader__.load({
|
|
|
680
968
|
{
|
|
681
969
|
type: "button",
|
|
682
970
|
className: "dpb-secondary",
|
|
683
|
-
|
|
971
|
+
ref: ignoreAllRef,
|
|
972
|
+
disabled: busy || items.length === 0,
|
|
684
973
|
onClick: () => setConfirmDismiss(true),
|
|
685
974
|
},
|
|
686
975
|
t("ignoreAll"),
|
|
@@ -690,7 +979,7 @@ window.__ModuleLoader__.load({
|
|
|
690
979
|
{
|
|
691
980
|
type: "button",
|
|
692
981
|
className: "dpb-primary",
|
|
693
|
-
disabled: busy ||
|
|
982
|
+
disabled: busy || interrupted.length === 0,
|
|
694
983
|
title: interrupted.length === 0 ? t("noInterrupted") : undefined,
|
|
695
984
|
onClick: () => onResume(interrupted.map((item) => item.id)),
|
|
696
985
|
},
|
|
@@ -714,9 +1003,12 @@ window.__ModuleLoader__.load({
|
|
|
714
1003
|
const [error, setError] = React.useState(null);
|
|
715
1004
|
const [result, setResult] = React.useState(null);
|
|
716
1005
|
const [pinnedId, setPinnedId] = React.useState(panelState.pinnedId);
|
|
717
|
-
// 「建议」:pendingFill
|
|
1006
|
+
// 「建议」:pendingFill 非空时弹确认框。
|
|
718
1007
|
const [pendingFill, setPendingFill] = React.useState(null);
|
|
719
|
-
const [
|
|
1008
|
+
const [jumpingId, setJumpingState] = React.useState(panelState.jumpingId);
|
|
1009
|
+
const [, bumpRecent] = React.useState(0);
|
|
1010
|
+
const loadSeq = React.useRef(0);
|
|
1011
|
+
const busyRef = React.useRef(false);
|
|
720
1012
|
|
|
721
1013
|
React.useEffect(() => {
|
|
722
1014
|
panelState.open = open;
|
|
@@ -726,25 +1018,48 @@ window.__ModuleLoader__.load({
|
|
|
726
1018
|
panelState.pinnedId = pinnedId;
|
|
727
1019
|
}, [pinnedId]);
|
|
728
1020
|
|
|
1021
|
+
React.useEffect(() => {
|
|
1022
|
+
const syncJumping = () => setJumpingState(panelState.jumpingId);
|
|
1023
|
+
window.addEventListener("dsh-planbox-dyb:jumping", syncJumping);
|
|
1024
|
+
return () => window.removeEventListener("dsh-planbox-dyb:jumping", syncJumping);
|
|
1025
|
+
}, []);
|
|
1026
|
+
|
|
1027
|
+
const markJumping = React.useCallback((id) => {
|
|
1028
|
+
panelState.jumpingId = id;
|
|
1029
|
+
setJumpingState(id);
|
|
1030
|
+
emitJumping();
|
|
1031
|
+
}, []);
|
|
1032
|
+
|
|
1033
|
+
const clearJumping = React.useCallback((id) => {
|
|
1034
|
+
finishJump(id);
|
|
1035
|
+
}, []);
|
|
1036
|
+
|
|
729
1037
|
const closePanel = React.useCallback(() => {
|
|
730
1038
|
panelState.open = false;
|
|
731
1039
|
panelState.pinnedId = null;
|
|
1040
|
+
panelState.jumpingId = null;
|
|
732
1041
|
setOpen(false);
|
|
733
1042
|
setPinnedId(null);
|
|
1043
|
+
setJumpingState(null);
|
|
734
1044
|
}, []);
|
|
735
1045
|
|
|
736
1046
|
const muted = React.useRef(false);
|
|
737
1047
|
|
|
738
1048
|
const load = React.useCallback(
|
|
739
1049
|
async (refresh) => {
|
|
740
|
-
if (muted.current) return;
|
|
1050
|
+
if (muted.current || busyRef.current) return;
|
|
1051
|
+
const seq = loadSeq.current + 1;
|
|
1052
|
+
loadSeq.current = seq;
|
|
741
1053
|
setLoading(true);
|
|
742
1054
|
try {
|
|
743
1055
|
const data = await request(`${API}/pending${refresh ? "?refresh=1" : ""}`);
|
|
1056
|
+
if (seq !== loadSeq.current || muted.current) return;
|
|
744
1057
|
setItems(Array.isArray(data.items) ? data.items : []);
|
|
745
1058
|
setError(data.scanError ? t("scanFailed", { message: data.scanError }) : null);
|
|
746
1059
|
} catch (cause) {
|
|
747
|
-
|
|
1060
|
+
if (seq === loadSeq.current && !muted.current) {
|
|
1061
|
+
setError(t("loadFailed", { message: String(cause?.message ?? cause) }));
|
|
1062
|
+
}
|
|
748
1063
|
} finally {
|
|
749
1064
|
setLoading(false);
|
|
750
1065
|
}
|
|
@@ -780,6 +1095,8 @@ window.__ModuleLoader__.load({
|
|
|
780
1095
|
if (busy) return;
|
|
781
1096
|
const wanted = Array.isArray(ids) ? ids.filter((id) => typeof id === "string") : [];
|
|
782
1097
|
if (wanted.length === 0) return;
|
|
1098
|
+
busyRef.current = true;
|
|
1099
|
+
loadSeq.current += 1;
|
|
783
1100
|
setBusyAction("resume");
|
|
784
1101
|
setResult(null);
|
|
785
1102
|
try {
|
|
@@ -811,6 +1128,7 @@ window.__ModuleLoader__.load({
|
|
|
811
1128
|
} catch (cause) {
|
|
812
1129
|
setError(t("loadFailed", { message: String(cause?.message ?? cause) }));
|
|
813
1130
|
} finally {
|
|
1131
|
+
busyRef.current = false;
|
|
814
1132
|
setBusyAction(null);
|
|
815
1133
|
}
|
|
816
1134
|
},
|
|
@@ -822,6 +1140,8 @@ window.__ModuleLoader__.load({
|
|
|
822
1140
|
async (id) => {
|
|
823
1141
|
if (busy) return;
|
|
824
1142
|
const snapshot = items;
|
|
1143
|
+
busyRef.current = true;
|
|
1144
|
+
loadSeq.current += 1;
|
|
825
1145
|
setBusyAction("dismiss");
|
|
826
1146
|
setResult(null);
|
|
827
1147
|
setItems((previous) => previous.filter((item) => item.id !== id));
|
|
@@ -836,6 +1156,7 @@ window.__ModuleLoader__.load({
|
|
|
836
1156
|
setItems(snapshot);
|
|
837
1157
|
setError(t("loadFailed", { message: String(cause?.message ?? cause) }));
|
|
838
1158
|
} finally {
|
|
1159
|
+
busyRef.current = false;
|
|
839
1160
|
setBusyAction(null);
|
|
840
1161
|
}
|
|
841
1162
|
},
|
|
@@ -849,6 +1170,8 @@ window.__ModuleLoader__.load({
|
|
|
849
1170
|
const wanted = Array.isArray(ids) ? ids : [];
|
|
850
1171
|
if (wanted.length === 0) return;
|
|
851
1172
|
const snapshot = items;
|
|
1173
|
+
busyRef.current = true;
|
|
1174
|
+
loadSeq.current += 1;
|
|
852
1175
|
setBusyAction("dismiss");
|
|
853
1176
|
setResult(null);
|
|
854
1177
|
setItems([]);
|
|
@@ -863,6 +1186,7 @@ window.__ModuleLoader__.load({
|
|
|
863
1186
|
setItems(snapshot);
|
|
864
1187
|
setError(t("loadFailed", { message: String(cause?.message ?? cause) }));
|
|
865
1188
|
} finally {
|
|
1189
|
+
busyRef.current = false;
|
|
866
1190
|
setBusyAction(null);
|
|
867
1191
|
}
|
|
868
1192
|
},
|
|
@@ -871,14 +1195,14 @@ window.__ModuleLoader__.load({
|
|
|
871
1195
|
|
|
872
1196
|
const openSession = React.useCallback(
|
|
873
1197
|
(sessionId, itemId, anchor) => {
|
|
1198
|
+
// 最近点开过的会话排到最前;切换可能导致组件重挂载,顺序也写进模块级缓存。
|
|
1199
|
+
markSessionOpened(sessionId);
|
|
1200
|
+
bumpRecent((value) => value + 1);
|
|
874
1201
|
// 会话切换可能让组件重挂载,先把“面板开着 + 看的是哪条”同步写进模块状态。
|
|
875
1202
|
panelState.open = true;
|
|
876
1203
|
panelState.pinnedId = itemId ?? null;
|
|
877
1204
|
setPinnedId(itemId ?? null);
|
|
878
|
-
|
|
879
|
-
if (label !== "") {
|
|
880
|
-
setFillNotice({ bad: false, text: t("viewAnchor", { label }) });
|
|
881
|
-
}
|
|
1205
|
+
if (itemId !== null && itemId !== undefined) markJumping(itemId);
|
|
882
1206
|
let workspace = null;
|
|
883
1207
|
try {
|
|
884
1208
|
workspace = pluginCtx?.get?.("uiWorkspace") ?? null;
|
|
@@ -888,26 +1212,25 @@ window.__ModuleLoader__.load({
|
|
|
888
1212
|
if (workspace !== null && typeof workspace.openSession === "function") {
|
|
889
1213
|
try {
|
|
890
1214
|
workspace.openSession(sessionId);
|
|
1215
|
+
revealTurn(anchor?.turn, sessionId, () => {
|
|
1216
|
+
if (itemId !== null && itemId !== undefined) clearJumping(itemId);
|
|
1217
|
+
});
|
|
891
1218
|
return;
|
|
892
1219
|
} catch (cause) {
|
|
893
1220
|
/* 回退到 URL 跳转 */
|
|
894
1221
|
}
|
|
895
1222
|
}
|
|
1223
|
+
if (itemId !== null && itemId !== undefined) clearJumping(itemId);
|
|
896
1224
|
window.location.assign(`/?session=${encodeURIComponent(sessionId)}`);
|
|
897
1225
|
},
|
|
898
|
-
[t],
|
|
1226
|
+
[t, markJumping, clearJumping],
|
|
899
1227
|
);
|
|
900
|
-
|
|
901
1228
|
const copySuggestion = React.useCallback(
|
|
902
1229
|
async (text) => {
|
|
903
1230
|
try {
|
|
904
1231
|
await navigator.clipboard.writeText(text);
|
|
905
|
-
setFillNotice({ bad: false, text: t("fillCopied") });
|
|
906
1232
|
} catch (cause) {
|
|
907
|
-
|
|
908
|
-
bad: true,
|
|
909
|
-
text: t("fillFailed", { message: String(cause?.message ?? cause) }),
|
|
910
|
-
});
|
|
1233
|
+
setError(t("fillFailed", { message: String(cause?.message ?? cause) }));
|
|
911
1234
|
}
|
|
912
1235
|
},
|
|
913
1236
|
[t],
|
|
@@ -926,6 +1249,8 @@ window.__ModuleLoader__.load({
|
|
|
926
1249
|
const workspace = clientService("uiWorkspace");
|
|
927
1250
|
if (workspace && typeof workspace.openSession === "function") {
|
|
928
1251
|
try {
|
|
1252
|
+
markSessionOpened(item.sessionId);
|
|
1253
|
+
bumpRecent((value) => value + 1);
|
|
929
1254
|
workspace.openSession(item.sessionId);
|
|
930
1255
|
} catch (cause) {
|
|
931
1256
|
/* 切不过去也继续尝试填当前会话 */
|
|
@@ -951,7 +1276,6 @@ window.__ModuleLoader__.load({
|
|
|
951
1276
|
whenDraftExists: "keep",
|
|
952
1277
|
});
|
|
953
1278
|
if (first === "applied") {
|
|
954
|
-
setFillNotice({ bad: false, text: t("fillDone") });
|
|
955
1279
|
return;
|
|
956
1280
|
}
|
|
957
1281
|
if (first !== "preserved") throw new Error(String(first));
|
|
@@ -975,22 +1299,14 @@ window.__ModuleLoader__.load({
|
|
|
975
1299
|
if (pending === null) return;
|
|
976
1300
|
try {
|
|
977
1301
|
const result = pending.apply();
|
|
978
|
-
if (result
|
|
979
|
-
|
|
1302
|
+
if (result !== "applied") {
|
|
1303
|
+
setError(t("fillFailed", { message: String(result) }));
|
|
1304
|
+
}
|
|
980
1305
|
} catch (cause) {
|
|
981
|
-
|
|
982
|
-
bad: true,
|
|
983
|
-
text: t("fillFailed", { message: String(cause?.message ?? cause) }),
|
|
984
|
-
});
|
|
1306
|
+
setError(t("fillFailed", { message: String(cause?.message ?? cause) }));
|
|
985
1307
|
}
|
|
986
1308
|
}, [pendingFill, t]);
|
|
987
1309
|
|
|
988
|
-
React.useEffect(() => {
|
|
989
|
-
if (fillNotice === null) return undefined;
|
|
990
|
-
const timer = window.setTimeout(() => setFillNotice(null), 2600);
|
|
991
|
-
return () => window.clearTimeout(timer);
|
|
992
|
-
}, [fillNotice]);
|
|
993
|
-
|
|
994
1310
|
const label = t("open");
|
|
995
1311
|
const badge = items.length;
|
|
996
1312
|
|
|
@@ -1021,16 +1337,6 @@ window.__ModuleLoader__.load({
|
|
|
1021
1337
|
: h("span", { className: "dpb-trigger-label" }, label),
|
|
1022
1338
|
badge > 0 ? h("span", { className: "dpb-badge" }, badge > 99 ? "99+" : badge) : null,
|
|
1023
1339
|
),
|
|
1024
|
-
fillNotice === null
|
|
1025
|
-
? null
|
|
1026
|
-
: ReactDOM.createPortal(
|
|
1027
|
-
h(
|
|
1028
|
-
"div",
|
|
1029
|
-
{ className: "dpb-toast " + (fillNotice.bad ? "bad" : "ok") },
|
|
1030
|
-
fillNotice.text,
|
|
1031
|
-
),
|
|
1032
|
-
document.body,
|
|
1033
|
-
),
|
|
1034
1340
|
pendingFill === null
|
|
1035
1341
|
? null
|
|
1036
1342
|
: ReactDOM.createPortal(
|
|
@@ -1087,6 +1393,7 @@ window.__ModuleLoader__.load({
|
|
|
1087
1393
|
error,
|
|
1088
1394
|
result,
|
|
1089
1395
|
pinnedId,
|
|
1396
|
+
jumpingId,
|
|
1090
1397
|
onClose: closePanel,
|
|
1091
1398
|
onRefresh: () => load(true),
|
|
1092
1399
|
onOpen: openSession,
|
|
@@ -1106,6 +1413,8 @@ window.__ModuleLoader__.load({
|
|
|
1106
1413
|
const [state, setState] = React.useState("idle");
|
|
1107
1414
|
const timer = React.useRef(0);
|
|
1108
1415
|
const sessionId = props.sessionId;
|
|
1416
|
+
const turn = Number(props.turn?.turn ?? props.turn ?? 0) || 0;
|
|
1417
|
+
const seq = Number(props.seq ?? 0) || 0;
|
|
1109
1418
|
|
|
1110
1419
|
React.useEffect(
|
|
1111
1420
|
() => () => {
|
|
@@ -1123,7 +1432,12 @@ window.__ModuleLoader__.load({
|
|
|
1123
1432
|
await request(`${API}/defer`, {
|
|
1124
1433
|
method: "POST",
|
|
1125
1434
|
headers: { "content-type": "application/json" },
|
|
1126
|
-
body: JSON.stringify({
|
|
1435
|
+
body: JSON.stringify({
|
|
1436
|
+
sessionId,
|
|
1437
|
+
...(turn > 0
|
|
1438
|
+
? { anchor: { turn, seq, at: Date.now(), kind: "user" } }
|
|
1439
|
+
: {}),
|
|
1440
|
+
}),
|
|
1127
1441
|
});
|
|
1128
1442
|
setState("done");
|
|
1129
1443
|
window.dispatchEvent(new CustomEvent("dsh-planbox-dyb:changed"));
|
|
@@ -1219,11 +1533,14 @@ window.__ModuleLoader__.load({
|
|
|
1219
1533
|
AutoResumeAction,
|
|
1220
1534
|
Row,
|
|
1221
1535
|
Panel,
|
|
1222
|
-
|
|
1536
|
+
groupSessions,
|
|
1223
1537
|
orderPending,
|
|
1224
1538
|
tagFor,
|
|
1225
1539
|
restorableItems,
|
|
1226
1540
|
anchorText,
|
|
1541
|
+
revealTurn,
|
|
1542
|
+
scrollTurnStart,
|
|
1543
|
+
nudgeTurnRail,
|
|
1227
1544
|
nextStep,
|
|
1228
1545
|
},
|
|
1229
1546
|
};
|
package/index.js
CHANGED
|
@@ -54,6 +54,13 @@ const SCAN_MAX_SESSIONS = 80;
|
|
|
54
54
|
const SCAN_CONCURRENCY = 6;
|
|
55
55
|
/** 异常中断默认只回溯 7 天,避免历史 error/interrupted 会话永远堆在面板里。 */
|
|
56
56
|
const DEFAULT_ABNORMAL_WINDOW_MS = 7 * 24 * 60 * 60 * 1000;
|
|
57
|
+
/** 助手结尾的“需要重启”只自动收最近 24 小时的会话,避免历史会话全部堆进来。 */
|
|
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
|
+
];
|
|
57
64
|
const MARKER_PATTERNS = [
|
|
58
65
|
/等?重启后(?:继续|接着)/,
|
|
59
66
|
/等?重启再(?:继续|接着)?/,
|
|
@@ -330,6 +337,8 @@ export function createStore(options = {}) {
|
|
|
330
337
|
queueFile,
|
|
331
338
|
dismissedFile,
|
|
332
339
|
scanCache: null,
|
|
340
|
+
scanEpoch: 0,
|
|
341
|
+
scanRefresh: null,
|
|
333
342
|
|
|
334
343
|
/** 当前登记队列。 */
|
|
335
344
|
queue() {
|
|
@@ -338,12 +347,19 @@ export function createStore(options = {}) {
|
|
|
338
347
|
);
|
|
339
348
|
},
|
|
340
349
|
|
|
341
|
-
/**
|
|
350
|
+
/** 新增:自动按会话更新;手动只在同一回合内更新,不同回合分别保留。 */
|
|
342
351
|
add(entry) {
|
|
343
352
|
const automatic = entry.origin === 'model';
|
|
344
|
-
const
|
|
345
|
-
|
|
346
|
-
|
|
353
|
+
const entryTurn = automatic
|
|
354
|
+
? 0
|
|
355
|
+
: Number(entry.anchor?.turn ?? 0) || Number(entry.anchor?.seq ?? 0) || 0;
|
|
356
|
+
const items = store.queue().filter((item) => {
|
|
357
|
+
if (item.sessionId !== entry.sessionId) return true;
|
|
358
|
+
if ((item.origin === 'model') !== automatic) return true;
|
|
359
|
+
if (automatic) return false;
|
|
360
|
+
const itemTurn = Number(item.anchor?.turn ?? 0) || Number(item.anchor?.seq ?? 0) || 0;
|
|
361
|
+
return itemTurn !== entryTurn;
|
|
362
|
+
});
|
|
347
363
|
items.unshift(entry);
|
|
348
364
|
writeJsonAtomic(queueFile, { version: 1, items });
|
|
349
365
|
return entry;
|
|
@@ -456,6 +472,7 @@ function queueItems(store) {
|
|
|
456
472
|
.queue()
|
|
457
473
|
.map((entry) => {
|
|
458
474
|
const prompt = typeof entry.prompt === 'string' ? entry.prompt : '';
|
|
475
|
+
const origin = entry.origin === 'model' ? 'model' : 'manual';
|
|
459
476
|
return {
|
|
460
477
|
id: entry.id,
|
|
461
478
|
source: 'queue',
|
|
@@ -464,7 +481,8 @@ function queueItems(store) {
|
|
|
464
481
|
prompt,
|
|
465
482
|
snippet: tailOf(prompt),
|
|
466
483
|
detailSource: 'prompt',
|
|
467
|
-
origin
|
|
484
|
+
origin,
|
|
485
|
+
kind: origin === 'model' ? 'auto' : 'manual',
|
|
468
486
|
note: typeof entry.note === 'string' ? entry.note : '',
|
|
469
487
|
snapshot: entry.snapshot && typeof entry.snapshot === 'object' ? entry.snapshot : null,
|
|
470
488
|
anchor: normalizeAnchor(entry.anchor),
|
|
@@ -559,6 +577,7 @@ function detectCandidate(summary, tail, turn, options) {
|
|
|
559
577
|
return {
|
|
560
578
|
id: `abnormal:${sessionId}`,
|
|
561
579
|
source: 'abnormal',
|
|
580
|
+
kind: 'interrupted',
|
|
562
581
|
sessionId,
|
|
563
582
|
title: summaryTitle(summary),
|
|
564
583
|
snippet: tailOf(detail),
|
|
@@ -570,6 +589,25 @@ function detectCandidate(summary, tail, turn, options) {
|
|
|
570
589
|
};
|
|
571
590
|
}
|
|
572
591
|
|
|
592
|
+
const restartWindow =
|
|
593
|
+
Number(summary.updatedAt ?? 0) > 0 &&
|
|
594
|
+
now - Number(summary.updatedAt ?? now) <= restartWindowMs();
|
|
595
|
+
if (summary.running !== true && restartWindow && restartNeededIn(tail.lastAssistantText)) {
|
|
596
|
+
return {
|
|
597
|
+
id: `scan:${sessionId}`,
|
|
598
|
+
source: 'scan',
|
|
599
|
+
kind: 'auto',
|
|
600
|
+
sessionId,
|
|
601
|
+
title: summaryTitle(summary),
|
|
602
|
+
snippet: snippetAround(tail.lastAssistantText, RESTART_NEEDED_PATTERN(restartGapChars())),
|
|
603
|
+
prompt: tailOf(tail.lastAssistantText, 240),
|
|
604
|
+
anchor: normalizeAnchor(options.anchor),
|
|
605
|
+
updatedAt: Number(summary.updatedAt ?? options.now),
|
|
606
|
+
running: false,
|
|
607
|
+
cwd: typeof summary.cwd === 'string' ? summary.cwd : undefined,
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
|
|
573
611
|
const realUserText = tail.lastRealUserText ?? '';
|
|
574
612
|
if (realUserText === '' || isAutoPrompt(realUserText) || !markerIn(realUserText)) return null;
|
|
575
613
|
|
|
@@ -587,9 +625,31 @@ function detectCandidate(summary, tail, turn, options) {
|
|
|
587
625
|
};
|
|
588
626
|
}
|
|
589
627
|
|
|
628
|
+
/** 判断文本里“重启”和“需要”的间隔,可由 DSH_PLANBOX_RESTART_GAP 覆盖(0–20,默认 5)。 */
|
|
629
|
+
export function restartGapChars() {
|
|
630
|
+
const raw = Number(process.env.DSH_PLANBOX_RESTART_GAP ?? DEFAULT_RESTART_GAP);
|
|
631
|
+
if (!Number.isFinite(raw) || raw < 0 || raw > 20) return DEFAULT_RESTART_GAP;
|
|
632
|
+
return Math.floor(raw);
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
/** 助手重启结论的自动收集窗口,可由 DSH_PLANBOX_RESTART_HOURS 覆盖(0 = 不限,默认 24 小时)。 */
|
|
636
|
+
export function restartWindowMs() {
|
|
637
|
+
const raw = process.env.DSH_PLANBOX_RESTART_HOURS;
|
|
638
|
+
if (raw === undefined || raw.trim() === '') return DEFAULT_RESTART_WINDOW_MS;
|
|
639
|
+
const hours = Number(raw);
|
|
640
|
+
if (!Number.isFinite(hours) || hours < 0) return DEFAULT_RESTART_WINDOW_MS;
|
|
641
|
+
return hours === 0 ? Number.POSITIVE_INFINITY : hours * 60 * 60 * 1000;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
/** 助手最后一条消息是否同时提到“重启”和“需要”(间隔内,且需要/重启前都不是“不”)。 */
|
|
645
|
+
export function restartNeededIn(text) {
|
|
646
|
+
const value = typeof text === 'string' ? text : '';
|
|
647
|
+
return RESTART_NEEDED_PATTERN(restartGapChars()).some((pattern) => pattern.test(value));
|
|
648
|
+
}
|
|
649
|
+
|
|
590
650
|
/**
|
|
591
651
|
* 兜底扫描:找“最后一条真实用户消息在说等重启后继续”的会话。
|
|
592
|
-
* 主路径是模型调用 planbox_defer
|
|
652
|
+
* 主路径是模型调用 planbox_defer 主动登记,扫描只负责兜底;助手明确说“DSH 重启:需要”也自动收。
|
|
593
653
|
* @param {object} ctx - 宿主上下文(需要 sessionController)。
|
|
594
654
|
* @param {ReturnType<typeof createStore>} store - 持久存储。
|
|
595
655
|
* @param {{ refresh?: boolean, signal?: AbortSignal, now?: number }} [options] - 扫描选项。
|
|
@@ -597,10 +657,26 @@ function detectCandidate(summary, tail, turn, options) {
|
|
|
597
657
|
*/
|
|
598
658
|
export async function scanCandidates(ctx, store, options = {}) {
|
|
599
659
|
const now = typeof options.now === 'number' ? options.now : Date.now();
|
|
600
|
-
if (!options.refresh && store.scanCache
|
|
660
|
+
if (!options.refresh && store.scanCache) {
|
|
661
|
+
if (now - store.scanCache.at < SCAN_TTL_MS) {
|
|
662
|
+
return store.scanCache.value;
|
|
663
|
+
}
|
|
664
|
+
// 过期缓存先返回,后台更新;面板打开不再等整轮扫描。
|
|
665
|
+
if (store.scanRefresh === null) {
|
|
666
|
+
store.scanRefresh = scanCandidates(ctx, store, {
|
|
667
|
+
refresh: true,
|
|
668
|
+
background: true,
|
|
669
|
+
now: Date.now(),
|
|
670
|
+
})
|
|
671
|
+
.catch(() => null)
|
|
672
|
+
.finally(() => {
|
|
673
|
+
store.scanRefresh = null;
|
|
674
|
+
});
|
|
675
|
+
}
|
|
601
676
|
return store.scanCache.value;
|
|
602
677
|
}
|
|
603
678
|
|
|
679
|
+
const epoch = store.scanEpoch ?? 0;
|
|
604
680
|
const controller = withTimeout(options.signal, 20_000);
|
|
605
681
|
const items = [];
|
|
606
682
|
let scanError;
|
|
@@ -657,8 +733,19 @@ export async function scanCandidates(ctx, store, options = {}) {
|
|
|
657
733
|
scanError = String(error?.message ?? error);
|
|
658
734
|
}
|
|
659
735
|
|
|
660
|
-
const
|
|
661
|
-
|
|
736
|
+
const dismissedNow = store.dismissed();
|
|
737
|
+
const liveItems = items.filter((item) => {
|
|
738
|
+
const ignoredAt = Number(dismissedNow[item.sessionId] ?? 0);
|
|
739
|
+
return !(ignoredAt > 0 && Number(item.updatedAt ?? 0) <= ignoredAt);
|
|
740
|
+
});
|
|
741
|
+
const value = {
|
|
742
|
+
items: liveItems,
|
|
743
|
+
scannedAt: now,
|
|
744
|
+
...(scanError === undefined ? {} : { scanError }),
|
|
745
|
+
};
|
|
746
|
+
if ((store.scanEpoch ?? 0) === epoch) {
|
|
747
|
+
store.scanCache = { at: now, value };
|
|
748
|
+
}
|
|
662
749
|
return value;
|
|
663
750
|
}
|
|
664
751
|
|
|
@@ -669,23 +756,61 @@ export async function scanCandidates(ctx, store, options = {}) {
|
|
|
669
756
|
* @param {{ refresh?: boolean, signal?: AbortSignal, now?: number }} [options] - 选项。
|
|
670
757
|
* @returns {Promise<{ items: object[], queueCount: number, scanCount: number, scannedAt: number, scanError?: string }>} 汇总。
|
|
671
758
|
*/
|
|
672
|
-
|
|
673
|
-
|
|
759
|
+
function turnOfItem(item) {
|
|
760
|
+
return Number(item?.anchor?.turn ?? 0) || 0;
|
|
761
|
+
}
|
|
674
762
|
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
763
|
+
/** 统一任务类别:manual / auto / interrupted。 */
|
|
764
|
+
export function kindOf(item) {
|
|
765
|
+
if (item?.kind === 'manual' || item?.kind === 'auto' || item?.kind === 'interrupted') {
|
|
766
|
+
return item.kind;
|
|
767
|
+
}
|
|
768
|
+
if (item?.source === 'abnormal') return 'interrupted';
|
|
769
|
+
if (item?.source === 'queue' && item?.origin !== 'model') return 'manual';
|
|
770
|
+
return 'auto';
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
export async function collectPending(ctx, store, options = {}) {
|
|
774
|
+
const [queue, scanned] = await Promise.all([
|
|
775
|
+
queueItemsWithDetails(ctx, store, options),
|
|
776
|
+
scanCandidates(ctx, store, options),
|
|
777
|
+
]);
|
|
778
|
+
|
|
779
|
+
const priority = { auto: 1, interrupted: 2, manual: 3 };
|
|
780
|
+
const merged = new Map();
|
|
781
|
+
for (const item of [...queue, ...scanned.items]) {
|
|
782
|
+
const kind = kindOf(item);
|
|
783
|
+
const normalized = item.kind === kind ? item : { ...item, kind };
|
|
784
|
+
const key =
|
|
785
|
+
turnOfItem(normalized) > 0
|
|
786
|
+
? `${normalized.sessionId}\u0000${turnOfItem(normalized)}`
|
|
787
|
+
: `id:${normalized.id}`;
|
|
788
|
+
const current = merged.get(key);
|
|
789
|
+
if (current === undefined) {
|
|
790
|
+
merged.set(key, normalized);
|
|
791
|
+
continue;
|
|
792
|
+
}
|
|
793
|
+
const currentPriority = priority[kindOf(current)];
|
|
794
|
+
const nextPriority = priority[kind];
|
|
795
|
+
if (nextPriority > currentPriority) {
|
|
796
|
+
merged.set(key, normalized);
|
|
797
|
+
} else if (
|
|
798
|
+
nextPriority === currentPriority &&
|
|
799
|
+
current.source !== 'queue' &&
|
|
800
|
+
normalized.source === 'queue'
|
|
801
|
+
) {
|
|
802
|
+
merged.set(key, normalized);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
683
805
|
|
|
684
|
-
const items = [...
|
|
806
|
+
const items = [...merged.values()]
|
|
807
|
+
.sort((left, right) => right.updatedAt - left.updatedAt)
|
|
808
|
+
.map((item) => ({ ...item, suggestion: suggestionFor(item) }));
|
|
809
|
+
const visibleQueue = items.filter((item) => item.source === 'queue');
|
|
685
810
|
return {
|
|
686
811
|
items,
|
|
687
|
-
queueCount:
|
|
688
|
-
scanCount:
|
|
812
|
+
queueCount: visibleQueue.length,
|
|
813
|
+
scanCount: items.length - visibleQueue.length,
|
|
689
814
|
scannedAt: scanned.scannedAt,
|
|
690
815
|
...(scanned.scanError === undefined ? {} : { scanError: scanned.scanError }),
|
|
691
816
|
};
|
|
@@ -757,6 +882,8 @@ async function itemsForIds(ctx, store, ids, options = {}) {
|
|
|
757
882
|
|
|
758
883
|
/** 已处理的项从扫描缓存里移除,避免下一次 GET 又看到它。 */
|
|
759
884
|
function forgetFromCache(store, doneIds, doneSessions) {
|
|
885
|
+
// 让正在进行的扫描在写入缓存前发现“已忽略/已恢复”,避免旧结果把数字又刷回来。
|
|
886
|
+
store.scanEpoch = (store.scanEpoch ?? 0) + 1;
|
|
760
887
|
const cache = store.scanCache;
|
|
761
888
|
if (!cache) return;
|
|
762
889
|
cache.value = {
|
|
@@ -803,6 +930,9 @@ function resumeText(item) {
|
|
|
803
930
|
// 异常中断的会话,直接发一句“继续”最自然;完整上下文本来就在会话里。
|
|
804
931
|
return '继续';
|
|
805
932
|
}
|
|
933
|
+
if (item.source === 'scan' && item.prompt) {
|
|
934
|
+
return `${RESUME_PREFIX}DSH 已重启,请继续这个任务:${item.prompt}`;
|
|
935
|
+
}
|
|
806
936
|
return (
|
|
807
937
|
`${RESUME_PREFIX}DSH 已重启。请接着处理本会话里此前标注“等重启后继续”的任务:` +
|
|
808
938
|
'先确认上次做到哪里,再从未完成处继续,不要重做已完成的部分;如果任务已经完成,请简短说明。'
|
|
@@ -992,7 +1122,7 @@ export async function deferFromSession(ctx, store, sessionId, overrides = {}, op
|
|
|
992
1122
|
|
|
993
1123
|
let title = String(overrides.title ?? '').trim();
|
|
994
1124
|
let prompt = String(overrides.prompt ?? '').trim();
|
|
995
|
-
let anchor =
|
|
1125
|
+
let anchor = normalizeAnchor(overrides.anchor);
|
|
996
1126
|
|
|
997
1127
|
const controller = withTimeout(options.signal, 8_000);
|
|
998
1128
|
if (title === '') {
|
|
@@ -1009,7 +1139,7 @@ export async function deferFromSession(ctx, store, sessionId, overrides = {}, op
|
|
|
1009
1139
|
{ address: { kind: 'session', sessionId: target }, maxMessages: 30 },
|
|
1010
1140
|
controller,
|
|
1011
1141
|
);
|
|
1012
|
-
anchor = anchorOf(page?.records);
|
|
1142
|
+
if (anchor === null) anchor = anchorOf(page?.records);
|
|
1013
1143
|
if (prompt === '') {
|
|
1014
1144
|
const lastUser = tailMessages(page?.records).lastRealUserText;
|
|
1015
1145
|
if (lastUser !== '') prompt = lastUser.slice(0, 200);
|
|
@@ -1096,6 +1226,7 @@ export function registerRoutes(ctx, store, connection) {
|
|
|
1096
1226
|
title: typeof body?.title === 'string' ? body.title : undefined,
|
|
1097
1227
|
prompt: typeof body?.prompt === 'string' ? body.prompt : undefined,
|
|
1098
1228
|
note: typeof body?.note === 'string' ? body.note : undefined,
|
|
1229
|
+
anchor: body?.anchor,
|
|
1099
1230
|
origin: 'manual',
|
|
1100
1231
|
},
|
|
1101
1232
|
);
|
|
@@ -1268,7 +1399,7 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1268
1399
|
|
|
1269
1400
|
const listTool = {
|
|
1270
1401
|
name: 'planbox_list',
|
|
1271
|
-
description: '
|
|
1402
|
+
description: '列出计划任务:手动、发现、中断三类。',
|
|
1272
1403
|
parameters: { type: 'object', additionalProperties: false, properties: {} },
|
|
1273
1404
|
output: {
|
|
1274
1405
|
schema: {
|
|
@@ -1285,6 +1416,7 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1285
1416
|
id: { type: 'string' },
|
|
1286
1417
|
source: { type: 'string' },
|
|
1287
1418
|
origin: { type: 'string' },
|
|
1419
|
+
kind: { type: 'string' },
|
|
1288
1420
|
sessionId: { type: 'string' },
|
|
1289
1421
|
title: { type: 'string' },
|
|
1290
1422
|
anchor: {
|
|
@@ -1322,12 +1454,8 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1322
1454
|
render(_args, value) {
|
|
1323
1455
|
if (value.count === 0) return [{ type: 'text', text: '当前没有计划任务。' }];
|
|
1324
1456
|
const line = (item) => {
|
|
1325
|
-
const
|
|
1326
|
-
|
|
1327
|
-
? '异常中断'
|
|
1328
|
-
: item.source === 'queue' && item.origin !== 'model'
|
|
1329
|
-
? '已登记'
|
|
1330
|
-
: '扫描到';
|
|
1457
|
+
const kind = kindOf(item);
|
|
1458
|
+
const tag = kind === 'manual' ? '手动' : kind === 'interrupted' ? '中断' : '发现';
|
|
1331
1459
|
const detail = item.snippet ? `\n ${item.snippet}` : '';
|
|
1332
1460
|
const anchor =
|
|
1333
1461
|
item.anchor?.turn > 0
|
|
@@ -1337,22 +1465,18 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1337
1465
|
: '';
|
|
1338
1466
|
return `- [${tag}] ${item.title}(${item.sessionId})${anchor}${detail}`;
|
|
1339
1467
|
};
|
|
1340
|
-
const
|
|
1341
|
-
|
|
1342
|
-
);
|
|
1343
|
-
const abnormal = value.items.filter((item) => item.source === 'abnormal');
|
|
1344
|
-
const scanned = value.items.filter((item) =>
|
|
1345
|
-
item.source === 'queue' ? item.origin === 'model' : item.source !== 'abnormal',
|
|
1346
|
-
);
|
|
1468
|
+
const manual = value.items.filter((item) => kindOf(item) === 'manual');
|
|
1469
|
+
const auto = value.items.filter((item) => kindOf(item) === 'auto');
|
|
1470
|
+
const interrupted = value.items.filter((item) => kindOf(item) === 'interrupted');
|
|
1347
1471
|
const sections = [];
|
|
1348
|
-
if (
|
|
1349
|
-
sections.push(
|
|
1472
|
+
if (manual.length > 0) {
|
|
1473
|
+
sections.push(`【手动】\n${manual.map(line).join('\n')}`);
|
|
1350
1474
|
}
|
|
1351
|
-
if (
|
|
1352
|
-
sections.push(
|
|
1475
|
+
if (auto.length > 0) {
|
|
1476
|
+
sections.push(`【发现】\n${auto.map(line).join('\n')}`);
|
|
1353
1477
|
}
|
|
1354
|
-
if (
|
|
1355
|
-
sections.push(
|
|
1478
|
+
if (interrupted.length > 0) {
|
|
1479
|
+
sections.push(`【中断】\n${interrupted.map(line).join('\n')}`);
|
|
1356
1480
|
}
|
|
1357
1481
|
return [{ type: 'text', text: `计划任务共 ${value.count} 条:\n\n${sections.join('\n\n')}` }];
|
|
1358
1482
|
},
|
|
@@ -1366,6 +1490,7 @@ export function createToolDefinitions(ctx, store) {
|
|
|
1366
1490
|
id: item.id,
|
|
1367
1491
|
source: item.source,
|
|
1368
1492
|
origin: item.origin ?? 'manual',
|
|
1493
|
+
kind: kindOf(item),
|
|
1369
1494
|
sessionId: item.sessionId,
|
|
1370
1495
|
title: item.title,
|
|
1371
1496
|
...(item.anchor === null || item.anchor === undefined ? {} : { anchor: item.anchor }),
|
package/package.json
CHANGED