dsh-planbox-dyb 0.8.0 → 0.8.2

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.
Files changed (4) hide show
  1. package/README.md +27 -85
  2. package/client.js +58 -21
  3. package/index.js +211 -32
  4. package/package.json +1 -1
package/README.md CHANGED
@@ -1,101 +1,43 @@
1
- # dsh-planbox-dyb — 重启后的计划任务收件箱
1
+ # dsh-planbox-dyb
2
2
 
3
- > 名字后缀 `-dyb` = 大尾巴(山东话读 yǐ bā)。
3
+ DSH 计划任务收件箱。
4
4
 
5
- 重启 DSH 前没做完的活,用「计划任务」接住:模型主动登记 + 兜底扫描 + 异常中断检测,你在侧栏面板里**审核后**决定继续或忽略。**它不会在启动时自动发消息。**
5
+ 重启 DSH 前没做完的活,用「计划任务」接住。重启后你在侧栏面板里审核,再决定继续或忽略。
6
6
 
7
- 产品文档在仓库根的 [../USAGE.md](../USAGE.md) / [../DESIGN.md](../DESIGN.md) / [../INSTALL.md](../INSTALL.md)。
7
+ **它不会自动续跑,也不会在启动时发消息。**
8
8
 
9
- ## 平台支持
10
-
11
- | 端 | 支持情况 | 说明 |
12
- |---|---|---|
13
- | **Windows** | ✅ 宿主 + 客户端 | PowerShell 安装脚本 `install-target.ps1`;面板在 Chrome / Edge 验证 |
14
- | **iPadOS / iOS** | ✅ 客户端 | Safari 打开 DSH 网页版即可用;面板已做安全区、`dvh` 高度、触屏加大点击目标 |
15
- | macOS / Linux | ✅ 宿主 + 客户端 | `apply-profile.mjs` 一行安装 |
16
-
17
- 插件是 **DSH Web 插件**:宿主(`index.js`)跑在 Windows / macOS / Linux 的 DSH 上,界面(`client.js`)跑在浏览器里——所以同一份代码,桌面浏览器和 iPhone / iPad 的 Safari 都能用。headless 环境没有侧栏和面板,插件不适用。
9
+ ## 安装
18
10
 
19
- ## 发布状态
11
+ ```bash
12
+ dsh plugin --profile web add dsh-planbox-dyb
13
+ ```
20
14
 
21
- - npm 元数据已就绪(`license` / `repository` / `keywords` / `engines`),包内只含 `index.js` / `client.js` / `cordis.patch.yml` / `README.md` / `LICENSE`;
22
- - 版本 `0.8.0`(`publish` / `mac` 同源),`npm pack --dry-run` 可验证 tarball;
23
- - 干净 Web profile 用 0.8.0 tarball 完成安装、`--dump-config` 与卸载验证(macOS,DSH 0.2.2-rc.5);
24
- - 安装既支持源码 `link:`(见 [../INSTALL.md](../INSTALL.md)),发布后也支持 `dsh plugin --profile web add dsh-planbox-dyb`。
15
+ 重启 DSH,刷新页面。
25
16
 
26
- ## 用法
17
+ ## 使用
27
18
 
28
- 1. 主路径:模型结束本轮前调用 `planbox_defer`,写清标题、续跑说明,并尽量填 `nextSteps` / `filesTouched` / `verifyCommand`;
29
- 2. 兜底:每轮回答下方「加入计划任务」按钮,一键登记当前会话;
30
- 3. 兜底:最后一条**真实用户消息**写着“等重启后继续”的会话,扫描自动列为候选;
31
- 4. 异常兜底:最后一个回合 `error` / `interrupted` / 未正常收尾的会话,列为「异常中断」;
32
- 5. 重启 DSH 后点侧栏底部时钟(右上角红点是条数)打开面板:先「建议」看模型打算怎么做,再决定「恢复中断」或「忽略」。
19
+ 1. 模型会在需要重启时主动登记;你也可以点每轮回答下方的「加入计划任务」。
20
+ 2. 重启后打开侧栏底部的「计划任务」(右上角红点是数量)。
21
+ 3. 先点「建议」看模型打算怎么继续,再决定「恢复中断」或「忽略」。
33
22
 
34
23
  ## 面板
35
24
 
36
- - 分区:正在查看(置顶)→ 已登记 → 异常中断 → 扫描到;**不显示任务状态**;
37
- - 行内:**建议 / 查看 / 忽略**,整行可点等同「查看」;
38
- - 底部:**全部忽略**(二次确认后清空列表)/ **恢复中断**;
39
- - 「建议」把建议填进输入框但不发送:空输入框直接填,非空则先确认是否从下一行追加;取不到接口时复制到剪贴板;
40
- - 「恢复中断」只处理异常中断项,每项只发一句「继续」,**投递成功后记录即删除**,不跟踪后续进度;
41
- - 「忽略」登记项直接删除,扫描/异常项写入忽略记录直到该会话再次更新。
42
-
43
- ## 模型侧约定
44
-
45
- 系统提示 section `planbox-dyb:policy`:必须重启才能收尾时先登记,而不是只让用户重启。
46
-
47
- | 工具 | 作用 |
48
- |---|---|
49
- | `planbox_defer` | 登记计划任务(`title` / `prompt` / `nextSteps[]` / `filesTouched[]` / `verifyCommand` / `lastFailedCommand`) |
50
- | `planbox_list` | 列出计划任务(已登记 / 异常中断 / 扫描到) |
51
- | `planbox_resume` | 恢复指定任务;不传 `ids` 时恢复全部;成功后删除记录 |
52
-
53
- ## 浏览器接口
54
-
55
- | 路径 | 方法 | 说明 |
56
- |---|---|---|
57
- | `/api/planbox/pending` | GET | 列表;`?refresh=1` 跳过 30s 扫描缓存 |
58
- | `/api/planbox/defer` | POST | body `{ sessionId }`,按钮登记 |
59
- | `/api/planbox/resume` | POST | body `{ ids? }`,逐项返回结果 |
60
- | `/api/planbox/dismiss` | POST | body `{ ids[] }`,批量删除登记 / 写忽略记录(一次落盘) |
61
-
62
- ## 检测口径
63
-
64
- - 取会话摘要按更新时间倒序,冷读最近 80 个会话尾部(6 路并发);
65
- - **扫描到**:只看最后一条真实用户消息(跳过 `time-context` / `runtime-context` / `[自动继续]`),命中“等重启后继续”等说法;
66
- - **异常中断**:最后回合 `error` / `interrupted`,或只有 `turn/start` 未收尾且会话不在运行;默认回溯 7 天(`DSH_PLANBOX_ABNORMAL_DAYS` 可调,`0` 不限);`aborted` 与 `completed` 不算;
67
- - 同会话按「登记 > 异常中断 > 扫描」去重;扫描结果缓存 30 秒。
68
-
69
- ## 性能
70
-
71
- - 忽略/恢复:客户端先本地移除再后台确认,失败恢复;宿主批量一次落盘,只从扫描缓存增量移除;
72
- - 队列增删改**不清空**扫描缓存,避免操作后触发 80 会话全量重扫;
73
- - 打开面板用 30 秒缓存,刷新按钮才强制重扫;单条恢复按 id 定向读目标会话。
74
-
75
- ## 配置
76
-
77
- | 环境变量 | 默认 | 说明 |
78
- |---|---|---|
79
- | `DSH_PLANBOX_DIR` | `~/.dsh/planbox` | 队列与忽略记录目录 |
80
- | `DSH_PLANBOX_ABNORMAL_DAYS` | `7` | 异常中断回溯天数;`0` = 不限 |
81
-
82
- ## 数据文件
83
-
84
- - `~/.dsh/planbox/pending.json` — 登记队列
85
- - `~/.dsh/planbox/dismissed.json` — 扫描/异常项的忽略记录
86
-
87
- ## 安装
25
+ - **已登记**:你点「加入计划任务」手动登记的任务。
26
+ - **异常中断**:上一回合报错或崩溃中断的会话。
27
+ - **扫描到**:模型登记或从会话消息里扫到的任务。
88
28
 
89
- 见 [../INSTALL.md](../INSTALL.md)。本机开发:`node apply-profile.mjs "$HOME/.dsh/profiles/web" "$PWD"`。
29
+ 每行会标注对应的「第 N 轮」对话;同会话的手动登记和自动结果分开显示。
90
30
 
91
- ## 已验证 / 未验证
31
+ 按钮:
92
32
 
93
- - `node test/host.test.mjs`:41 项全过(登记、扫描并发、异常窗口、去重、忽略批量、恢复消费记录、快照、路由与工具);
94
- - `node test/client.test.mjs`:11 项全过(分组、置顶、三按钮、整行点击、建议快照行、恢复中断过滤、插槽注册、侧栏与面板渲染冒烟);
95
- - 真实链路:0.2.0 时代验证过状态机闭环,0.6.0 移除状态机后**尚未在真机走一遍**(恢复中断 → 记录消失)。
33
+ - **建议**:把续跑建议填进输入框,不发送;输入框已有内容会先确认是否从下一行追加。
34
+ - **查看**:跳到对应会话,不关闭面板,并把该任务置顶;会提示打开的是第几轮对话。
35
+ - **忽略**:删除这一条;扫描/异常项会隐藏到该会话下次更新。
36
+ - **全部忽略**:确认后清空当前列表。
37
+ - **恢复中断**:只处理「异常中断」,每项发一句「继续」;发送成功后记录删除,不跟踪后续进度。
96
38
 
97
- ## 已知边界
39
+ ## 注意
98
40
 
99
- - 任何 JS 改动都要重启 DSH:client bundle 由宿主启动时读入并做 immutable 版本缓存,F5 不够;
100
- - 单次最多扫最近 80 个会话;更久远的任务需要重新登记;
101
- - 与自动续跑类插件同装会重复投递,建议二选一。
41
+ - 只支持 DSH Web;headless 没有面板。
42
+ - 不自动续跑、不跟踪任务是否完成,进度需要你自己看会话。
43
+ - 可以和自动续跑插件共存;已被自动续跑的会话会从「异常中断」消失,「恢复中断」投递前也会复核,不会重复发。
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.0";
18
+ const CLIENT_VERSION = "0.8.2";
19
19
 
20
20
  const FALLBACK = {
21
21
  open: "计划任务",
@@ -32,6 +32,10 @@ window.__ModuleLoader__.load({
32
32
  pinnedSection: "正在查看",
33
33
  scannedSection: "扫描到({n})",
34
34
  running: "运行中",
35
+ anchorTurn: "第 {turn} 轮",
36
+ anchorTurnSeq: "第 {turn} 轮 · #{seq}",
37
+ anchorSeq: "消息 #{seq}",
38
+ viewAnchor: "已打开:{label}",
35
39
  resume: "继续",
36
40
  view: "查看",
37
41
  resumeAll: "恢复中断",
@@ -84,6 +88,10 @@ window.__ModuleLoader__.load({
84
88
  pinnedSection: "Viewing",
85
89
  scannedSection: "Scanned ({n})",
86
90
  running: "Running",
91
+ anchorTurn: "Turn {turn}",
92
+ anchorTurnSeq: "Turn {turn} · #{seq}",
93
+ anchorSeq: "Message #{seq}",
94
+ viewAnchor: "Opened: {label}",
87
95
  resume: "Resume",
88
96
  view: "View",
89
97
  resumeAll: "Restore interrupted",
@@ -255,6 +263,7 @@ window.__ModuleLoader__.load({
255
263
  ".dpb-next{font-size:11px;line-height:16px;color:#9dbcff;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
256
264
  ".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}",
257
265
  ".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}",
266
+ ".dpb-anchor{flex:none;color:var(--dsw-alias-state-business-primary,#4c8dff)}",
258
267
  ".dpb-dot{opacity:.6}",
259
268
  ".dpb-row-actions{flex:none;display:flex;align-items:center;gap:2px}",
260
269
  ".dpb-mini{padding:0 7px;height:24px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);font:inherit;font-size:11px;cursor:pointer}",
@@ -360,14 +369,31 @@ window.__ModuleLoader__.load({
360
369
  };
361
370
  }
362
371
 
372
+ /** 任务对应的最近一次对话:第 N 轮 / 消息 #seq。 */
373
+ function anchorText(t, item) {
374
+ const anchor = item?.anchor;
375
+ if (anchor === null || anchor === undefined) return "";
376
+ if (anchor.turn > 0 && anchor.seq > 0) {
377
+ return t("anchorTurnSeq", { turn: anchor.turn, seq: anchor.seq });
378
+ }
379
+ if (anchor.turn > 0) return t("anchorTurn", { turn: anchor.turn });
380
+ if (anchor.seq > 0) return t("anchorSeq", { seq: anchor.seq });
381
+ return "";
382
+ }
383
+
363
384
  function Row(props) {
364
385
  const { item, t, busy, pinned, onOpen, onDismiss, onSuggest } = props;
365
386
  const queue = item.source === "queue";
366
387
  const tag = tagFor(item);
367
388
  const detail = queue ? item.snippet || item.prompt : item.snippet;
368
389
  const full = queue ? item.prompt : item.snippet;
390
+ const anchor = anchorText(t, item);
391
+ const anchorTitle =
392
+ anchor === "" || !item.anchor?.at
393
+ ? anchor
394
+ : `${anchor} · ${new Date(item.anchor.at).toLocaleString()}`;
369
395
  // 整行可点:和「查看」同一条路径(跳转 + 置顶),行内按钮自己 stopPropagation。
370
- const open = () => onOpen(item.sessionId, item.id);
396
+ const open = () => onOpen(item.sessionId, item.id, item.anchor);
371
397
  const next = nextStep(item);
372
398
  return h(
373
399
  "div",
@@ -400,6 +426,9 @@ window.__ModuleLoader__.load({
400
426
  h(
401
427
  "div",
402
428
  { className: "dpb-meta" },
429
+ anchor !== ""
430
+ ? h("span", { className: "dpb-anchor", title: anchorTitle }, anchor)
431
+ : null,
403
432
  h("span", null, ago(t, item.updatedAt)),
404
433
  item.running ? h("span", { className: "dpb-dot" }, "·") : null,
405
434
  item.running ? h("span", null, t("running")) : null,
@@ -432,7 +461,7 @@ window.__ModuleLoader__.load({
432
461
  "aria-label": t("view"),
433
462
  onClick: (event) => {
434
463
  event.stopPropagation();
435
- onOpen(item.sessionId, item.id);
464
+ onOpen(item.sessionId, item.id, item.anchor);
436
465
  },
437
466
  },
438
467
  t("view"),
@@ -840,27 +869,34 @@ window.__ModuleLoader__.load({
840
869
  [busy, items, t],
841
870
  );
842
871
 
843
- const openSession = React.useCallback((sessionId, itemId) => {
844
- // 会话切换可能让组件重挂载,先把“面板开着 + 看的是哪条”同步写进模块状态。
845
- panelState.open = true;
846
- panelState.pinnedId = itemId ?? null;
847
- setPinnedId(itemId ?? null);
848
- let workspace = null;
849
- try {
850
- workspace = pluginCtx?.get?.("uiWorkspace") ?? null;
851
- } catch (cause) {
852
- workspace = null;
853
- }
854
- if (workspace !== null && typeof workspace.openSession === "function") {
872
+ const openSession = React.useCallback(
873
+ (sessionId, itemId, anchor) => {
874
+ // 会话切换可能让组件重挂载,先把“面板开着 + 看的是哪条”同步写进模块状态。
875
+ panelState.open = true;
876
+ panelState.pinnedId = itemId ?? null;
877
+ setPinnedId(itemId ?? null);
878
+ const label = anchorText(t, { anchor });
879
+ if (label !== "") {
880
+ setFillNotice({ bad: false, text: t("viewAnchor", { label }) });
881
+ }
882
+ let workspace = null;
855
883
  try {
856
- workspace.openSession(sessionId);
857
- return;
884
+ workspace = pluginCtx?.get?.("uiWorkspace") ?? null;
858
885
  } catch (cause) {
859
- /* 回退到 URL 跳转 */
886
+ workspace = null;
860
887
  }
861
- }
862
- window.location.assign(`/?session=${encodeURIComponent(sessionId)}`);
863
- }, []);
888
+ if (workspace !== null && typeof workspace.openSession === "function") {
889
+ try {
890
+ workspace.openSession(sessionId);
891
+ return;
892
+ } catch (cause) {
893
+ /* 回退到 URL 跳转 */
894
+ }
895
+ }
896
+ window.location.assign(`/?session=${encodeURIComponent(sessionId)}`);
897
+ },
898
+ [t],
899
+ );
864
900
 
865
901
  const copySuggestion = React.useCallback(
866
902
  async (text) => {
@@ -1187,6 +1223,7 @@ window.__ModuleLoader__.load({
1187
1223
  orderPending,
1188
1224
  tagFor,
1189
1225
  restorableItems,
1226
+ anchorText,
1190
1227
  nextStep,
1191
1228
  },
1192
1229
  };
package/index.js CHANGED
@@ -119,7 +119,7 @@ function isInjectedSource(source) {
119
119
  * 读事件页的最后一条用户消息和最后一条助手消息。
120
120
  * `lastRealUserText` 只认真正的用户输入,跳过 DSH 注入的上下文。
121
121
  * @param {readonly unknown[]} records - sessionController.events() 返回的记录。
122
- * @returns {{ lastUserText: string, lastRealUserText: string, lastAssistantText: string, lastType: string }} 尾部消息。
122
+ * @returns {{ lastUserText: string, lastRealUserText: string, lastAssistantText: string, lastType: string, lastUserAt: number, lastAssistantAt: number }} 尾部消息。
123
123
  */
124
124
  export function tailMessages(records) {
125
125
  const result = {
@@ -127,6 +127,8 @@ export function tailMessages(records) {
127
127
  lastRealUserText: '',
128
128
  lastAssistantText: '',
129
129
  lastType: '',
130
+ lastUserAt: 0,
131
+ lastAssistantAt: 0,
130
132
  };
131
133
  if (!Array.isArray(records)) return result;
132
134
  for (let index = records.length - 1; index >= 0; index -= 1) {
@@ -134,16 +136,19 @@ export function tailMessages(records) {
134
136
  const event = record && typeof record === 'object' && record.type === 'event' ? record.event : null;
135
137
  if (!event) continue;
136
138
  if (event.type !== 'user/message' && event.type !== 'assistant/message') continue;
139
+ const at = Number(event.time ?? record.time ?? 0) || 0;
137
140
  if (result.lastType === '') result.lastType = event.type;
138
141
  if (event.type === 'user/message') {
139
142
  const text = textOf(event.data?.content);
140
143
  if (result.lastUserText === '') result.lastUserText = text;
144
+ if (result.lastUserAt === 0) result.lastUserAt = at;
141
145
  if (result.lastRealUserText === '' && !isInjectedSource(event.data?.source)) {
142
146
  result.lastRealUserText = text;
143
147
  }
144
148
  }
145
149
  if (event.type === 'assistant/message' && result.lastAssistantText === '') {
146
150
  result.lastAssistantText = textOf(event.data?.message?.content ?? event.data?.content);
151
+ result.lastAssistantAt = at;
147
152
  }
148
153
  if (
149
154
  result.lastUserText !== '' &&
@@ -181,12 +186,75 @@ export function tailTurnState(records) {
181
186
  if (event.type === 'turn/start') {
182
187
  result.kind = 'open';
183
188
  result.open = true;
189
+ result.at = Number(event.time ?? record.time ?? 0) || 0;
184
190
  return result;
185
191
  }
186
192
  }
187
193
  return result;
188
194
  }
189
195
 
196
+ /**
197
+ * 取任务对应的“最近一次对话”锚点:优先最后一条真实用户消息,退化为最近回合。
198
+ * 用于面板显示和「查看」时说明是哪一轮对话。
199
+ * @param {readonly unknown[]} records - sessionController.events() 返回的记录。
200
+ * @returns {{ turn: number, seq: number, at: number, messageId: string, kind: string } | null} 锚点。
201
+ */
202
+ export function anchorOf(records) {
203
+ if (!Array.isArray(records)) return null;
204
+ let user = null;
205
+ let turn = null;
206
+ for (let index = records.length - 1; index >= 0; index -= 1) {
207
+ const record = records[index];
208
+ const event = record && typeof record === 'object' && record.type === 'event' ? record.event : null;
209
+ if (!event) continue;
210
+ const seq = Number(event.seq ?? record.seq ?? 0) || 0;
211
+ const at = Number(event.time ?? record.time ?? 0) || 0;
212
+ if (
213
+ user === null &&
214
+ event.type === 'user/message' &&
215
+ !isInjectedSource(event.data?.source)
216
+ ) {
217
+ user = {
218
+ seq,
219
+ at,
220
+ messageId: typeof event.data?.id === 'string' ? event.data.id : '',
221
+ kind: 'user',
222
+ };
223
+ }
224
+ if (
225
+ turn === null &&
226
+ (event.type === 'turn/start' || event.type === 'turn/end')
227
+ ) {
228
+ turn = {
229
+ turn: Number(event.data?.turn ?? 0) || 0,
230
+ seq,
231
+ at,
232
+ kind: 'turn',
233
+ };
234
+ }
235
+ if (user !== null && turn !== null) break;
236
+ }
237
+ const chosen = user ?? turn;
238
+ if (chosen === null) return null;
239
+ return {
240
+ turn: turn?.turn ?? 0,
241
+ seq: chosen.seq,
242
+ at: chosen.at,
243
+ messageId: user?.messageId ?? '',
244
+ kind: chosen.kind,
245
+ };
246
+ }
247
+
248
+ function normalizeAnchor(value) {
249
+ if (value === null || typeof value !== 'object') return null;
250
+ const turn = Number(value.turn ?? 0) || 0;
251
+ const seq = Number(value.seq ?? 0) || 0;
252
+ const at = Number(value.at ?? 0) || 0;
253
+ const messageId = typeof value.messageId === 'string' ? value.messageId : '';
254
+ if (turn === 0 && seq === 0 && at === 0) return null;
255
+ return { turn, seq, at, messageId, kind: value.kind === 'turn' ? 'turn' : 'user' };
256
+ }
257
+
190
258
  /** 是否是异常中断(错误、崩溃补记,或未正常收尾的回合)。 */
191
259
  function isAbnormalTurn(turn) {
192
260
  return turn.open || turn.kind === 'error' || turn.kind === 'interrupted';
@@ -270,9 +338,12 @@ export function createStore(options = {}) {
270
338
  );
271
339
  },
272
340
 
273
- /** 新增(同一会话的旧登记会被替换,只保留最新一条)。 */
341
+ /** 新增(同一会话、同一来源类别只保留最新一条;手动与自动分开)。 */
274
342
  add(entry) {
275
- const items = store.queue().filter((item) => item.sessionId !== entry.sessionId);
343
+ const automatic = entry.origin === 'model';
344
+ const items = store.queue().filter(
345
+ (item) => !(item.sessionId === entry.sessionId && (item.origin === 'model') === automatic),
346
+ );
276
347
  items.unshift(entry);
277
348
  writeJsonAtomic(queueFile, { version: 1, items });
278
349
  return entry;
@@ -396,6 +467,7 @@ function queueItems(store) {
396
467
  origin: entry.origin === 'model' ? 'model' : 'manual',
397
468
  note: typeof entry.note === 'string' ? entry.note : '',
398
469
  snapshot: entry.snapshot && typeof entry.snapshot === 'object' ? entry.snapshot : null,
470
+ anchor: normalizeAnchor(entry.anchor),
399
471
  updatedAt: Number(entry.createdAt ?? Date.now()),
400
472
  };
401
473
  })
@@ -427,12 +499,14 @@ async function queueItemsWithDetails(ctx, store, options = {}) {
427
499
  const detailed = [];
428
500
  for (const item of base) {
429
501
  let assistantText = '';
502
+ let records = null;
430
503
  try {
431
504
  const page = await ctx.sessionController.events(
432
505
  { address: { kind: 'session', sessionId: item.sessionId }, maxMessages: 30 },
433
506
  controller,
434
507
  );
435
- assistantText = tailMessages(page?.records).lastAssistantText;
508
+ records = page?.records;
509
+ assistantText = tailMessages(records).lastAssistantText;
436
510
  } catch {
437
511
  /* 读不到就用续跑说明兜底 */
438
512
  }
@@ -442,6 +516,7 @@ async function queueItemsWithDetails(ctx, store, options = {}) {
442
516
  title: summary ? summaryTitle(summary) : item.title,
443
517
  snippet: tailOf(assistantText !== '' ? assistantText : item.prompt),
444
518
  detailSource: assistantText !== '' ? 'assistant' : 'prompt',
519
+ anchor: item.anchor ?? normalizeAnchor(anchorOf(records)),
445
520
  });
446
521
  }
447
522
  return detailed;
@@ -469,7 +544,12 @@ function detectCandidate(summary, tail, turn, options) {
469
544
  // 只有显式给出有限窗口时才按时间过滤;显式续跑单条(itemsForIds)不看窗口。
470
545
  const withinWindow = !Number.isFinite(window) || now - Number(summary.updatedAt ?? now) <= window;
471
546
 
472
- if (summary.running !== true && withinWindow && isAbnormalTurn(turn)) {
547
+ // 中断回合之后又出现了用户消息:说明已被自动续跑插件或用户手动继续,
548
+ // 不再作为「异常中断」重复列出。
549
+ const promptedAfter =
550
+ turn.at > 0 && tail.lastUserAt > turn.at;
551
+
552
+ if (summary.running !== true && !promptedAfter && withinWindow && isAbnormalTurn(turn)) {
473
553
  const detail =
474
554
  turn.message !== ''
475
555
  ? `异常中断:${turn.message}`
@@ -483,6 +563,7 @@ function detectCandidate(summary, tail, turn, options) {
483
563
  title: summaryTitle(summary),
484
564
  snippet: tailOf(detail),
485
565
  prompt: '',
566
+ anchor: normalizeAnchor(options.anchor),
486
567
  updatedAt: Number(summary.updatedAt ?? options.now),
487
568
  running: false,
488
569
  cwd: typeof summary.cwd === 'string' ? summary.cwd : undefined,
@@ -499,6 +580,7 @@ function detectCandidate(summary, tail, turn, options) {
499
580
  title: summaryTitle(summary),
500
581
  snippet: snippetAround(realUserText, MARKER_PATTERNS),
501
582
  prompt: '',
583
+ anchor: normalizeAnchor(options.anchor),
502
584
  updatedAt: Number(summary.updatedAt ?? options.now),
503
585
  running: summary.running === true,
504
586
  cwd: typeof summary.cwd === 'string' ? summary.cwd : undefined,
@@ -549,13 +631,15 @@ export async function scanCandidates(ctx, store, options = {}) {
549
631
  { address: { kind: 'session', sessionId: summary.sessionId }, maxMessages: 80 },
550
632
  controller,
551
633
  );
634
+ const records = page?.records;
552
635
  settled[index] = detectCandidate(
553
636
  summary,
554
- tailMessages(page?.records),
555
- tailTurnState(page?.records),
637
+ tailMessages(records),
638
+ tailTurnState(records),
556
639
  {
557
640
  dismissed,
558
641
  now,
642
+ anchor: anchorOf(records),
559
643
  abnormalWindowMs: options.abnormalWindowMs ?? abnormalWindowMs(),
560
644
  },
561
645
  );
@@ -589,7 +673,10 @@ export async function collectPending(ctx, store, options = {}) {
589
673
  const queue = await queueItemsWithDetails(ctx, store, options);
590
674
 
591
675
  const scanned = await scanCandidates(ctx, store, options);
592
- const known = new Set(queue.map((item) => item.sessionId));
676
+ // 只有自动登记项会吞掉同会话的扫描结果;手动登记与自动结果要分开显示。
677
+ const known = new Set(
678
+ queue.filter((item) => item.origin === 'model').map((item) => item.sessionId),
679
+ );
593
680
  const extra = scanned.items
594
681
  .filter((item) => !known.has(item.sessionId))
595
682
  .sort((left, right) => right.updatedAt - left.updatedAt);
@@ -654,9 +741,11 @@ async function itemsForIds(ctx, store, ids, options = {}) {
654
741
  { address: { kind: 'session', sessionId: summary.sessionId }, maxMessages: 80 },
655
742
  controller,
656
743
  );
657
- const item = detectCandidate(summary, tailMessages(page?.records), tailTurnState(page?.records), {
744
+ const records = page?.records;
745
+ const item = detectCandidate(summary, tailMessages(records), tailTurnState(records), {
658
746
  dismissed,
659
747
  now: Date.now(),
748
+ anchor: anchorOf(records),
660
749
  });
661
750
  if (item !== null) selected.push(item);
662
751
  } catch {
@@ -731,6 +820,35 @@ export function suggestionFor(item) {
731
820
  return text.startsWith(RESUME_PREFIX) ? text.slice(RESUME_PREFIX.length) : text;
732
821
  }
733
822
 
823
+ /**
824
+ * 恢复异常中断项前再核对一次会话尾部:自动续跑插件可能已经抢先投递,
825
+ * 或者用户已经手动继续。此时不能再重复发一遍「继续」。
826
+ * @param {object} ctx - 宿主上下文。
827
+ * @param {object} item - 待恢复项。
828
+ * @param {Map<string, object>} summaries - 会话摘要。
829
+ * @param {AbortSignal} signal - 取消信号。
830
+ * @returns {Promise<boolean>} 是否仍然是可以恢复的异常中断。
831
+ */
832
+ async function abnormalStillPending(ctx, item, summaries, signal) {
833
+ if (item.source !== 'abnormal') return true;
834
+ if (summaries.get(item.sessionId)?.running === true) return false;
835
+ try {
836
+ const page = await ctx.sessionController.events(
837
+ { address: { kind: 'session', sessionId: item.sessionId }, maxMessages: 40 },
838
+ withTimeout(signal, 8_000),
839
+ );
840
+ const records = page?.records;
841
+ const turn = tailTurnState(records);
842
+ const tail = tailMessages(records);
843
+ if (!isAbnormalTurn(turn)) return false;
844
+ if (turn.at > 0 && tail.lastUserAt > turn.at) return false;
845
+ return true;
846
+ } catch {
847
+ // 读不到就按原样尝试;prompt 本身会报错,不会造成重复投递。
848
+ return true;
849
+ }
850
+ }
851
+
734
852
  /**
735
853
  * 正在投递续跑提示的会话。并发调用不再共享同一个 promise:
736
854
  * 同一会话的第二个请求会拿到一条失败结果(`error` 说明正在继续),
@@ -756,8 +874,35 @@ export async function resumeSelected(ctx, store, options = {}) {
756
874
  const queueIds = [];
757
875
  const dismissedSessions = [];
758
876
  const results = [];
877
+ const summaries = new Map();
878
+
879
+ if (selected.some((item) => item.source === 'abnormal')) {
880
+ try {
881
+ const listed = await ctx.sessionController.list(
882
+ {},
883
+ withTimeout(options.signal, 8_000),
884
+ );
885
+ for (const summary of listed?.items ?? []) {
886
+ if (summary && typeof summary.sessionId === 'string') {
887
+ summaries.set(summary.sessionId, summary);
888
+ }
889
+ }
890
+ } catch {
891
+ /* 摘要读不到时,后面只靠事件尾部复核 */
892
+ }
893
+ }
759
894
 
760
895
  for (const item of selected) {
896
+ if (!(await abnormalStillPending(ctx, item, summaries, options.signal))) {
897
+ results.push({
898
+ id: item.id,
899
+ source: item.source,
900
+ ok: false,
901
+ error: '该会话已被继续,已跳过。',
902
+ });
903
+ continue;
904
+ }
905
+
761
906
  if (resumingSessions.has(item.sessionId)) {
762
907
  results.push({
763
908
  id: item.id,
@@ -809,7 +954,7 @@ export async function resumeSelected(ctx, store, options = {}) {
809
954
  * 登记一条待续任务。
810
955
  * @param {object} ctx - 宿主上下文。
811
956
  * @param {ReturnType<typeof createStore>} store - 持久存储。
812
- * @param {{ sessionId: string, title: string, prompt?: string, note?: string }} input - 登记内容。
957
+ * @param {{ sessionId: string, title: string, prompt?: string, note?: string, anchor?: object }} input - 登记内容。
813
958
  * @returns {object} 新登记项。
814
959
  */
815
960
  export function deferTask(store, input) {
@@ -825,6 +970,7 @@ export function deferTask(store, input) {
825
970
  note: String(input.note ?? '').trim(),
826
971
  origin: input.origin === 'model' ? 'model' : 'manual',
827
972
  snapshot: normalizeSnapshot(input),
973
+ anchor: normalizeAnchor(input.anchor),
828
974
  createdAt: Date.now(),
829
975
  };
830
976
  return store.add(entry);
@@ -846,30 +992,30 @@ export async function deferFromSession(ctx, store, sessionId, overrides = {}, op
846
992
 
847
993
  let title = String(overrides.title ?? '').trim();
848
994
  let prompt = String(overrides.prompt ?? '').trim();
995
+ let anchor = null;
849
996
 
850
- if (title === '' || prompt === '') {
851
- const controller = withTimeout(options.signal, 8_000);
852
- if (title === '') {
853
- try {
854
- const listed = await ctx.sessionController.list({}, controller);
855
- const summary = (listed?.items ?? []).find((item) => item?.sessionId === target);
856
- if (summary) title = summaryTitle(summary);
857
- } catch {
858
- /* 标题拿不到就用兜底 */
859
- }
997
+ const controller = withTimeout(options.signal, 8_000);
998
+ if (title === '') {
999
+ try {
1000
+ const listed = await ctx.sessionController.list({}, controller);
1001
+ const summary = (listed?.items ?? []).find((item) => item?.sessionId === target);
1002
+ if (summary) title = summaryTitle(summary);
1003
+ } catch {
1004
+ /* 标题拿不到就用兜底 */
860
1005
  }
1006
+ }
1007
+ try {
1008
+ const page = await ctx.sessionController.events(
1009
+ { address: { kind: 'session', sessionId: target }, maxMessages: 30 },
1010
+ controller,
1011
+ );
1012
+ anchor = anchorOf(page?.records);
861
1013
  if (prompt === '') {
862
- try {
863
- const page = await ctx.sessionController.events(
864
- { address: { kind: 'session', sessionId: target }, maxMessages: 20 },
865
- controller,
866
- );
867
- const lastUser = tailMessages(page?.records).lastRealUserText;
868
- if (lastUser !== '') prompt = lastUser.slice(0, 200);
869
- } catch {
870
- /* 拿不到就用兜底 */
871
- }
1014
+ const lastUser = tailMessages(page?.records).lastRealUserText;
1015
+ if (lastUser !== '') prompt = lastUser.slice(0, 200);
872
1016
  }
1017
+ } catch {
1018
+ /* 读不到就用兜底 */
873
1019
  }
874
1020
 
875
1021
  return deferTask(store, {
@@ -878,6 +1024,7 @@ export async function deferFromSession(ctx, store, sessionId, overrides = {}, op
878
1024
  prompt: prompt === '' ? '继续完成此前未完成的任务。' : prompt,
879
1025
  note: overrides.note,
880
1026
  origin: overrides.origin,
1027
+ anchor,
881
1028
  });
882
1029
  }
883
1030
 
@@ -1090,8 +1237,21 @@ export function createToolDefinitions(ctx, store) {
1090
1237
  },
1091
1238
  },
1092
1239
  async execute(args, exec) {
1240
+ const sessionId = sessionIdOf(exec);
1241
+ let anchor = null;
1242
+ if (sessionId !== '') {
1243
+ try {
1244
+ const page = await ctx.sessionController.events(
1245
+ { address: { kind: 'session', sessionId }, maxMessages: 30 },
1246
+ withTimeout(undefined, 8_000),
1247
+ );
1248
+ anchor = anchorOf(page?.records);
1249
+ } catch {
1250
+ /* 读不到就不带锚点 */
1251
+ }
1252
+ }
1093
1253
  const entry = deferTask(store, {
1094
- sessionId: sessionIdOf(exec),
1254
+ sessionId,
1095
1255
  title: args?.title,
1096
1256
  prompt: args?.prompt,
1097
1257
  nextSteps: args?.nextSteps,
@@ -1100,6 +1260,7 @@ export function createToolDefinitions(ctx, store) {
1100
1260
  lastFailedCommand: args?.lastFailedCommand,
1101
1261
  note: args?.note,
1102
1262
  origin: 'model',
1263
+ anchor,
1103
1264
  });
1104
1265
  return { ok: true, id: entry.id, title: entry.title, pending: store.queue().length };
1105
1266
  },
@@ -1126,6 +1287,17 @@ export function createToolDefinitions(ctx, store) {
1126
1287
  origin: { type: 'string' },
1127
1288
  sessionId: { type: 'string' },
1128
1289
  title: { type: 'string' },
1290
+ anchor: {
1291
+ type: 'object',
1292
+ additionalProperties: false,
1293
+ properties: {
1294
+ turn: { type: 'integer' },
1295
+ seq: { type: 'integer' },
1296
+ at: { type: 'integer' },
1297
+ messageId: { type: 'string' },
1298
+ kind: { type: 'string' },
1299
+ },
1300
+ },
1129
1301
  snapshot: {
1130
1302
  type: 'object',
1131
1303
  additionalProperties: false,
@@ -1157,7 +1329,13 @@ export function createToolDefinitions(ctx, store) {
1157
1329
  ? '已登记'
1158
1330
  : '扫描到';
1159
1331
  const detail = item.snippet ? `\n ${item.snippet}` : '';
1160
- return `- [${tag}] ${item.title}(${item.sessionId})${detail}`;
1332
+ const anchor =
1333
+ item.anchor?.turn > 0
1334
+ ? ` · 第 ${item.anchor.turn} 轮`
1335
+ : item.anchor?.seq > 0
1336
+ ? ` · 消息 #${item.anchor.seq}`
1337
+ : '';
1338
+ return `- [${tag}] ${item.title}(${item.sessionId})${anchor}${detail}`;
1161
1339
  };
1162
1340
  const registered = value.items.filter(
1163
1341
  (item) => item.source === 'queue' && item.origin !== 'model',
@@ -1190,6 +1368,7 @@ export function createToolDefinitions(ctx, store) {
1190
1368
  origin: item.origin ?? 'manual',
1191
1369
  sessionId: item.sessionId,
1192
1370
  title: item.title,
1371
+ ...(item.anchor === null || item.anchor === undefined ? {} : { anchor: item.anchor }),
1193
1372
  ...(item.snapshot === null || item.snapshot === undefined ? {} : { snapshot: item.snapshot }),
1194
1373
  updatedAt: Math.round(item.updatedAt),
1195
1374
  prompt: item.prompt ?? '',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-planbox-dyb",
3
- "version": "0.8.0",
3
+ "version": "0.8.2",
4
4
  "description": "PlanBox:DSH 计划任务收件箱——重启前登记、重启后审核并恢复中断任务。宿主 Windows / macOS / Linux,客户端任意现代浏览器(含 iOS / iPadOS Safari)。",
5
5
  "license": "MIT",
6
6
  "author": "ZhibinYU",