dsh-session-conductor 1.3.7 → 1.3.9

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.
@@ -12,12 +12,16 @@
12
12
  const [selected, setSelected] = react.useState(() => new Set()); // 批量删除勾选
13
13
  const [fullResults, setFullResults] = react.useState(null); // 全文搜索结果(null=未搜索)
14
14
  const [fullSearching, setFullSearching] = react.useState(false);
15
- const [ruleOpen, setRuleOpen] = react.useState(false); // 按条件删除表单展开
15
+ const [ruleOpen, setRuleOpen] = react.useState(false); // 筛选条件表单展开
16
16
  const [ruleArchivedOnly, setRuleArchivedOnly] = react.useState(true);
17
17
  const [ruleDays, setRuleDays] = react.useState(7);
18
18
  const [rulePrefix, setRulePrefix] = react.useState("");
19
19
  const [ruleLowValue, setRuleLowValue] = react.useState(false); // 低价值筛选(复用价值分析)
20
- const [rulePreview, setRulePreview] = react.useState(null); // dryRun 预览(null=未预览)
20
+ // —— 回收站(删除只是打标记,这里管理被标记的会话)——
21
+ const [trashItems, setTrashItems] = react.useState(null); // null = 尚未加载
22
+ const [trashSel, setTrashSel] = react.useState(() => new Set());
23
+ const [trashRetention, setTrashRetention] = react.useState(7); // 保留天数
24
+ const [trashBatch, setTrashBatch] = react.useState(null); // 最近一个删除批次(撤销用)
21
25
 
22
26
  // list 流式——NDJSON 每行一个会话,读到立即追加显示(每获取一个追加一个,
23
27
  // 不等全部);按 updatedAt 倒序插入保持列表顺序;旧一次性 JSON(预览页离线垫片/
@@ -58,11 +62,25 @@
58
62
  if (!listRes.ok) throw new Error("list failed: HTTP " + listRes.status);
59
63
  let lastBatch = null;
60
64
  if (typeof listRes.body?.getReader === "function") {
61
- // 流式 NDJSON:逐行解析追加
65
+ // 流式 NDJSON:逐行解析追加。
66
+ // 但**不逐行 setState**:上百条会话逐条 setSessions 会触发上百次全列表重渲染
67
+ // (O(n²)),真实数据下界面会卡到无响应。改为攒 150ms 一批、一次性合并。
62
68
  const reader = listRes.body.getReader();
63
69
  const decoder = new TextDecoder();
64
70
  let buf = "";
65
71
  const batch = [];
72
+ const pending = [];
73
+ let flushTimer = null;
74
+ const flush = () => {
75
+ flushTimer = null;
76
+ if (pending.length === 0) return;
77
+ const items = pending.splice(0, pending.length);
78
+ setSessions((cur) => {
79
+ let next = Array.isArray(cur) ? cur : [];
80
+ for (const item of items) next = insertSorted(next, item);
81
+ return next;
82
+ });
83
+ };
66
84
  for (;;) {
67
85
  const { done, value } = await reader.read();
68
86
  if (done) break;
@@ -76,10 +94,12 @@
76
94
  try { parsedLine = JSON.parse(line); } catch { continue; } // 半行/头行跳过
77
95
  if (parsedLine && parsedLine.id) {
78
96
  batch.push(parsedLine);
79
- setSessions((cur) => insertSorted(cur, parsedLine)); // 每获取一个追加一个
97
+ pending.push(parsedLine);
98
+ if (flushTimer === null) flushTimer = setTimeout(flush, 150);
80
99
  }
81
100
  }
82
101
  }
102
+ flush();
83
103
  lastBatch = batch;
84
104
  } else {
85
105
  const body = await listRes.json();
@@ -105,6 +125,23 @@
105
125
  refreshRef.current = refresh;
106
126
 
107
127
  // 启动即自动加载(插件挂载就预取一次,不依赖面板打开);打开面板时再刷新一次保证最新
128
+ // ① 先读**落盘索引**(毫秒级)把列表填出来 —— 索引只写不用的话,冷缓存时面板要等
129
+ // 全量构建(实测 41~226 秒)才有内容,看起来就是「空的」。
130
+ // ② 随后 refresh() 的流式全量刷新在后台覆盖(每条到了就追加),两者互不阻塞。
131
+ react.useEffect(() => {
132
+ let alive = true;
133
+ (async () => {
134
+ try {
135
+ const res = await window.__scFetch("/api/session-conductor/list?fromIndex=true", { headers: { Accept: "application/json" } }, 0);
136
+ const body = await res.json();
137
+ if (!alive || !body?.ok) return;
138
+ const items = Array.isArray(body.sessions) ? body.sessions : [];
139
+ // 只在当前还是空列表时填充:不要用陈旧索引覆盖已经流式到达的新数据
140
+ if (items.length > 0) setSessions((cur) => (Array.isArray(cur) && cur.length > 0 ? cur : items));
141
+ } catch { /* 索引不可用就走全量刷新 */ }
142
+ })();
143
+ return () => { alive = false; };
144
+ }, []);
108
145
  react.useEffect(() => {
109
146
  refresh();
110
147
  }, [refresh]);
@@ -465,15 +502,20 @@
465
502
  usedFallback = true;
466
503
  }
467
504
  if (!body?.ok) throw new Error(body?.error?.message ?? "search failed");
468
- const hits = (body.items ?? []).map((h) => ({
469
- sessionId: h.sessionId,
505
+ // 两条搜索来源、两种返回形状:官方 FTS 给 items[],本插件内置扫描给 hits[]。
506
+ // 原先只认 items ⇒ 官方接口不存在(本机实测 /api/session-search/query 直接 404,
507
+ // 必然走内置扫描)时命中恒为空 —— 搜到了也显示「没有找到」,命中区自然点不动。
508
+ const rawHits = Array.isArray(body.items) ? body.items : (Array.isArray(body.hits) ? body.hits : []);
509
+ const hits = rawHits.map((h) => ({
510
+ // sessionId 是点开会话的唯一凭据:缺了就是「点了没反应」,这里兼容常见别名并滤掉空值
511
+ sessionId: h.sessionId ?? h.session?.id ?? h.id ?? null,
470
512
  title: h.title ?? null,
471
513
  cwd: h.cwd ?? null,
472
514
  archived: h.archived === true,
473
515
  running: h.running === true,
474
516
  updatedAt: h.updatedAt ?? null,
475
517
  matches: Array.isArray(h.matches) ? h.matches : (h.match ? [h.match] : []),
476
- }));
518
+ })).filter((h) => typeof h.sessionId === "string" && h.sessionId !== "");
477
519
  setFullResults({ query: keywordText, hits, usedFallback });
478
520
  } catch (cause) {
479
521
  const message = cause instanceof Error ? cause.message : String(cause);
@@ -510,119 +552,276 @@
510
552
  }
511
553
  };
512
554
 
513
- // —— 按条件删除(预览 + 执行)——
514
- // 预览页离线模式(window.__BACKEND__ === ""):按条件删除在快照数据上本地计算预览
515
- // (真实 GUI 走后端 API;预览页点预览可立即看到命中,无需后端)
516
- const previewLocally = () => {
517
- const ep = window.__ENDPOINTS__ || {};
518
- const listBody = ep["/api/session-conductor/list"];
519
- const vaBody = ep["/api/session-conductor/value-analysis"];
520
- const rows = (listBody?.sessions ?? []).map((s) => ({
521
- sessionId: s.id,
522
- title: s.title,
523
- cwd: s.cwd,
524
- archived: s.archived === true,
525
- updatedAt: typeof s.updatedAt === "number" ? s.updatedAt : null,
526
- }));
527
- const now = Date.now();
528
- const lowIds = new Set((vaBody?.low ?? []).map((i) => i.id));
529
- const prefix = rulePrefix.trim().replace(/\/+$/, "");
530
- const days = Number(ruleDays) || 0;
531
- const matched = rows.filter((m) => {
532
- if (ruleArchivedOnly && !m.archived) return false;
533
- if (days > 0) {
534
- const updated = m.updatedAt;
535
- if (!Number.isFinite(updated) || now - updated < days * 86400000) return false;
536
- }
537
- if (prefix !== "") {
538
- const cwd = String(m.cwd ?? "").replace(/\/+$/, "");
539
- if (cwd !== prefix && !cwd.startsWith(prefix + "/")) return false;
540
- }
541
- if (ruleLowValue && !lowIds.has(m.sessionId)) return false;
542
- return true;
555
+ // —— 勾选的公共入口 ——
556
+ // 行内勾选框、筛选、清空都必须走这两个函数:状态只有 `selected` 一处。
557
+ // 之前行内勾选自己写一段 setSelected、筛选另写一段,两处口径一旦不同就会出现
558
+ // 「删除按钮的计数变了,但行内勾选框没勾上」这种鬼现象。
559
+ const setRowSelected = (sessionId, checked) => {
560
+ if (typeof sessionId !== "string" || sessionId === "") return;
561
+ setSelected((prev) => {
562
+ const next = new Set(prev);
563
+ if (checked) next.add(sessionId); else next.delete(sessionId);
564
+ return next;
543
565
  });
544
- return matched;
566
+ };
567
+ const replaceSelected = (ids) => {
568
+ setSelected(new Set((Array.isArray(ids) ? ids : []).filter((id) => typeof id === "string" && id !== "")));
545
569
  };
546
570
 
547
- const previewRuleDelete = async () => {
548
- setBusy("__rule__");
549
- setRulePreview(null);
550
- if (typeof window.__BACKEND__ !== "undefined" && window.__BACKEND__ === "") {
551
- // 预览页离线:本地计算
552
- try {
553
- const matched = previewLocally();
554
- setRulePreview(matched);
555
- if (matched.length === 0) window.alert(t("deleteByRule.noMatch"));
556
- } catch (cause) {
557
- window.alert(t("error.action", { message: cause instanceof Error ? cause.message : String(cause) }));
558
- } finally {
559
- setBusy(null);
560
- }
561
- return;
571
+ // —— 回收站操作 ——
572
+ // 删除只是打标记,所以还原就是「删标记」,几乎零成本;真删只发生在到期与一键清空。
573
+ const loadTrashItems = async () => {
574
+ try {
575
+ const res = await window.__scFetch("/api/session-conductor/trash", { headers: { accept: "application/json" } }, 0);
576
+ const body = await res.json();
577
+ if (!body?.ok) throw new Error(body?.error?.message ?? "trash load failed");
578
+ const items = Array.isArray(body.items) ? body.items : [];
579
+ setTrashItems(items);
580
+ setTrashRetention(Number(body.retentionDays) || 7);
581
+ setTrashBatch(body.latestBatch ?? null);
582
+ setTrashSel((prev) => new Set([...prev].filter((id) => items.some((it) => it.sessionId === id))));
583
+ } catch (cause) {
584
+ window.alert(t("error.action", { message: cause instanceof Error ? cause.message : String(cause) }));
562
585
  }
586
+ };
587
+ const restoreTrash = async (ids) => {
588
+ if (!Array.isArray(ids) || ids.length === 0) return;
563
589
  try {
564
- const res = await window.__scFetch("/api/session-conductor/delete-by-rule", {
590
+ const res = await window.__scFetch("/api/session-conductor/trash/restore", {
565
591
  method: "POST",
566
592
  headers: { "Content-Type": CONTENT_TYPE_JSON },
567
- body: JSON.stringify({
568
- archivedOnly: ruleArchivedOnly,
569
- inactiveDays: Number(ruleDays) || 0,
570
- cwdPrefix: rulePrefix.trim(),
571
- lowValue: ruleLowValue,
572
- dryRun: true,
573
- }),
574
- });
593
+ body: JSON.stringify({ sessionIds: ids }),
594
+ }, 0);
575
595
  const body = await res.json();
576
- if (!body.ok) throw new Error(body.error?.message ?? "preview failed");
577
- setRulePreview(body.matched ?? []);
578
- if (!body.matched || body.matched.length === 0) window.alert(t("deleteByRule.noMatch"));
596
+ if (!body?.ok) throw new Error(body?.error?.message ?? "restore failed");
597
+ setTrashSel(new Set());
598
+ await loadTrashItems();
599
+ await refresh();
579
600
  } catch (cause) {
580
- const message = cause instanceof Error ? cause.message : String(cause);
581
- window.alert(t("error.action", { message }));
582
- } finally {
583
- setBusy(null);
601
+ window.alert(t("error.action", { message: cause instanceof Error ? cause.message : String(cause) }));
584
602
  }
585
603
  };
586
-
587
- const runRuleDelete = async () => {
588
- if (!rulePreview || rulePreview.length === 0) return;
589
- // 预览页离线模式:不执行真实删除(破坏性操作需真实后端),提示到 DSH GUI
590
- if (typeof window.__BACKEND__ !== "undefined" && window.__BACKEND__ === "") {
591
- window.alert(t("deleteByRule.offlineHint"));
592
- return;
604
+ const restoreLastBatch = async () => {
605
+ try {
606
+ const res = await window.__scFetch("/api/session-conductor/trash/restore-last-batch", { method: "POST", headers: { "Content-Type": CONTENT_TYPE_JSON }, body: "{}" }, 0);
607
+ const body = await res.json();
608
+ if (!body?.ok) throw new Error(body?.error?.message ?? "restore batch failed");
609
+ if ((body.restored ?? []).length === 0) window.alert(t("trash.nothingToUndo"));
610
+ setTrashSel(new Set());
611
+ await loadTrashItems();
612
+ await refresh();
613
+ } catch (cause) {
614
+ window.alert(t("error.action", { message: cause instanceof Error ? cause.message : String(cause) }));
593
615
  }
594
- const yes = window.confirm(t("deleteByRule.preview", { n: rulePreview.length }));
595
- if (!yes) return;
596
- setBusy("__rule__");
616
+ };
617
+ const emptyTrashAll = async () => {
618
+ const n = (trashItems ?? []).length;
619
+ if (n === 0) return;
620
+ if (!window.confirm(t("trash.emptyConfirm", { n }))) return;
597
621
  try {
598
- const res = await window.__scFetch("/api/session-conductor/delete-by-rule", {
622
+ const res = await window.__scFetch("/api/session-conductor/trash/empty", {
599
623
  method: "POST",
600
624
  headers: { "Content-Type": CONTENT_TYPE_JSON },
601
- body: JSON.stringify({
602
- archivedOnly: ruleArchivedOnly,
603
- inactiveDays: Number(ruleDays) || 0,
604
- cwdPrefix: rulePrefix.trim(),
605
- lowValue: ruleLowValue,
606
- dryRun: false,
607
- }),
608
- });
625
+ body: JSON.stringify({ confirm: true }),
626
+ }, 0);
609
627
  const body = await res.json();
610
- if (!body.ok) throw new Error(body.error?.message ?? "delete failed");
611
- window.alert(t("deleteBatch.done", {
612
- deleted: body.deleted?.length ?? 0,
613
- skippedText: body.skipped?.length > 0 ? t("deleteBatch.skipped", { n: body.skipped.length }) : "",
614
- }));
615
- setRuleOpen(false);
616
- setRulePreview(null);
617
- await refresh();
628
+ if (!body?.ok) throw new Error(body?.error?.message ?? "empty failed");
629
+ setTrashSel(new Set());
630
+ await loadTrashItems();
631
+ } catch (cause) {
632
+ window.alert(t("error.action", { message: cause instanceof Error ? cause.message : String(cause) }));
633
+ }
634
+ };
635
+ const saveTrashRetention = async () => {
636
+ try {
637
+ const res = await window.__scFetch("/api/session-conductor/trash/retention", {
638
+ method: "POST",
639
+ headers: { "Content-Type": CONTENT_TYPE_JSON },
640
+ body: JSON.stringify({ days: Number(trashRetention) || 7 }),
641
+ }, 0);
642
+ const body = await res.json();
643
+ if (!body?.ok) throw new Error(body?.error?.message ?? "retention failed");
644
+ setTrashRetention(Number(body.retentionDays) || 7);
645
+ await loadTrashItems();
646
+ } catch (cause) {
647
+ window.alert(t("error.action", { message: cause instanceof Error ? cause.message : String(cause) }));
648
+ }
649
+ };
650
+ const toggleTrashSel = (sessionId, checked) => {
651
+ setTrashSel((prev) => {
652
+ const next = new Set(prev);
653
+ if (checked) next.add(sessionId); else next.delete(sessionId);
654
+ return next;
655
+ });
656
+ };
657
+
658
+ // —— 筛选:按条件把会话**自动勾选**到列表里 ——
659
+ // 批量删除只有一条路径:「勾选 → 删除选中」。条件(归档 / 价值 / 时间 / 目录)只负责把该勾的勾上。
660
+ // ① 归档 / 时间 / 目录:面板手里每一行已经带着 archived / cwd / updatedAt,
661
+ // 纯内存过滤 —— 点完即勾,**不发任何请求**。
662
+ // ② 低价值:唯一需要读日志的条件,走**流式**分析 —— 服务端每算完一条推一行,
663
+ // 前端**分析出一个勾一个**。服务端另有价值索引(按 updatedAt + TTL,默认 24 小时),
664
+ // 命中索引的会话零 I/O 秒回,只有新会话/变过的会话才真读日志。
665
+ // 全程不设时间上限:完成与否由**请求事件**判定(每行一个结果,读完即结束)。
666
+ const [filterProgress, setFilterProgress] = react.useState(null); // {done,total};null=没在分析
667
+ const streamLowValue = async (baseIds) => {
668
+ const base = new Set(baseIds);
669
+ replaceSelected([]); // 低价值:从空开始,分析出一个勾一个
670
+ setFilterProgress({ done: 0, total: base.size });
671
+ const res = await window.__scFetch("/api/session-conductor/value-analysis?stream=1", {
672
+ method: "POST",
673
+ headers: { "Content-Type": CONTENT_TYPE_JSON, Accept: "application/x-ndjson" },
674
+ body: JSON.stringify({ ids: baseIds }),
675
+ }, 0);
676
+ if (!res.ok) throw new Error("value analysis failed: HTTP " + res.status);
677
+ if (typeof res.body?.getReader !== "function") throw new Error("value analysis: 宿主未提供流式响应");
678
+ const reader = res.body.getReader();
679
+ const decoder = new TextDecoder();
680
+ let buf = "";
681
+ let picked = 0;
682
+ let seen = 0;
683
+ for (;;) {
684
+ const { done, value } = await reader.read();
685
+ if (done) break;
686
+ buf += decoder.decode(value, { stream: true });
687
+ let nl;
688
+ while ((nl = buf.indexOf("\n")) >= 0) {
689
+ const line = buf.slice(0, nl).trim();
690
+ buf = buf.slice(nl + 1);
691
+ if (!line) continue;
692
+ let row;
693
+ try { row = JSON.parse(line); } catch { continue; }
694
+ if (!row || typeof row.id !== "string") continue; // 头行({ok,stream,total})跳过
695
+ seen += 1;
696
+ setFilterProgress({ done: typeof row.done === "number" ? row.done : seen, total: typeof row.total === "number" ? row.total : base.size });
697
+ if (row.value === "low" && base.has(row.id)) {
698
+ picked += 1;
699
+ setRowSelected(row.id, true); // 走公共勾选入口,行内勾选框与计数永远一致
700
+ }
701
+ }
702
+ }
703
+ return picked;
704
+ };
705
+
706
+ const applyFilter = async () => {
707
+ const list = Array.isArray(sessions) ? sessions : [];
708
+ const now = Date.now();
709
+ const prefix = rulePrefix.trim().replace(/\/+$/, "");
710
+ const days = Number(ruleDays) || 0;
711
+ const baseIds = list.filter((s) => {
712
+ if (ruleArchivedOnly && s.archived !== true) return false;
713
+ if (days > 0) {
714
+ const updated = typeof s.updatedAt === "number" ? s.updatedAt : NaN;
715
+ if (!Number.isFinite(updated) || now - updated < days * 86400000) return false;
716
+ }
717
+ if (prefix !== "") {
718
+ const cwd = String(s.cwd ?? "").replace(/\/+$/, "");
719
+ if (cwd !== prefix && !cwd.startsWith(prefix + "/")) return false;
720
+ }
721
+ return true;
722
+ }).map((s) => s.id);
723
+ if (baseIds.length === 0) {
724
+ // 勾选是「替换」语义:这次条件什么都没匹配到,必须把上一次的勾选清掉 ——
725
+ // 否则界面还留着上次的勾选与「删除选中 (N)」,很容易照着上次的结果误删。
726
+ replaceSelected([]);
727
+ window.alert(t("deleteByRule.noMatch"));
728
+ return;
729
+ }
730
+ // 切到「全部」让勾选结果当场可见 + 收起条件表单回到列表
731
+ setTab("all");
732
+ setRuleOpen(false);
733
+ if (!ruleLowValue) { replaceSelected(baseIds); return; } // 纯本地,点完即勾
734
+ setBusy("__rule__");
735
+ try {
736
+ const picked = await streamLowValue(baseIds);
737
+ if (picked === 0) window.alert(t("deleteByRule.noMatch"));
618
738
  } catch (cause) {
619
739
  const message = cause instanceof Error ? cause.message : String(cause);
620
740
  window.alert(t("error.action", { message }));
621
741
  } finally {
622
742
  setBusy(null);
743
+ setFilterProgress(null);
623
744
  }
624
745
  };
625
746
 
747
+ /** 回收站面板:工具栏(保留期 / 撤销 / 还原选中 / 全选 / 一键清空)+ 条目列表 */
748
+ const renderTrash = () => (0, react_jsx_runtime.jsxs)("div", {
749
+ style: { padding: PADDING_BAR },
750
+ children: [
751
+ (0, react_jsx_runtime.jsxs)("div", {
752
+ style: { display: "flex", gap: 6, alignItems: "center", flexWrap: "wrap", marginBottom: 8, fontSize: FONT_SIZE_SMALL },
753
+ children: [
754
+ (0, react_jsx_runtime.jsx)("span", { style: { color: CSS_LABEL_SECONDARY }, children: t("trash.retention.label") }),
755
+ (0, react_jsx_runtime.jsx)("input", {
756
+ type: "number", min: 1, max: 365, value: trashRetention,
757
+ style: { width: 64, height: SMALL_CONTROL_HEIGHT, borderRadius: CONTROL_RADIUS, border: CSS_BORDER_L2, background: CSS_BG_BASE, color: CSS_LABEL_PRIMARY, padding: "0 6px", fontSize: FONT_SIZE_SMALL },
758
+ onChange: (e) => setTrashRetention(e.target.value),
759
+ }),
760
+ (0, react_jsx_runtime.jsx)("span", { style: { color: CSS_LABEL_TERTIARY }, children: t("trash.retention.unit") }),
761
+ (0, react_jsx_runtime.jsx)("button", { style: S.actionBtn(false), onClick: saveTrashRetention, children: t("trash.retention.save") }),
762
+ (0, react_jsx_runtime.jsx)("button", {
763
+ style: S.actionBtn(false),
764
+ disabled: !trashBatch || (trashBatch.ids ?? []).length === 0,
765
+ title: trashBatch ? t("trash.undo.title", { n: (trashBatch.ids ?? []).length }) : t("trash.nothingToUndo"),
766
+ onClick: restoreLastBatch,
767
+ children: t("trash.undo"),
768
+ }),
769
+ (0, react_jsx_runtime.jsx)("button", {
770
+ style: S.actionBtn(false),
771
+ disabled: trashSel.size === 0,
772
+ onClick: () => restoreTrash([...trashSel]),
773
+ children: t("trash.restoreSelected", { n: trashSel.size }),
774
+ }),
775
+ (0, react_jsx_runtime.jsx)("button", {
776
+ style: S.actionBtn(false),
777
+ disabled: (trashItems ?? []).length === 0,
778
+ onClick: () => setTrashSel(new Set((trashItems ?? []).map((it) => it.sessionId))),
779
+ children: t("trash.selectAll"),
780
+ }),
781
+ (0, react_jsx_runtime.jsx)("button", {
782
+ style: { ...S.actionBtn(true), borderColor: CSS_DANGER, color: CSS_DANGER, marginLeft: "auto" },
783
+ disabled: (trashItems ?? []).length === 0,
784
+ onClick: emptyTrashAll,
785
+ children: t("trash.empty"),
786
+ }),
787
+ ],
788
+ }),
789
+ (0, react_jsx_runtime.jsx)("div", { style: { fontSize: 11.5, color: CSS_LABEL_TERTIARY, marginBottom: 6 }, children: t("trash.hint") }),
790
+ trashItems === null
791
+ ? (0, react_jsx_runtime.jsx)("div", { style: S.empty, children: t("list.loading") })
792
+ : trashItems.length === 0
793
+ ? (0, react_jsx_runtime.jsx)("div", { style: S.empty, children: t("trash.emptyList") })
794
+ : trashItems.map((item) => (0, react_jsx_runtime.jsxs)("div", {
795
+ style: { display: "flex", alignItems: "center", gap: 8, padding: "6px 4px", borderTop: "1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.15))" },
796
+ children: [
797
+ (0, react_jsx_runtime.jsx)("input", {
798
+ type: "checkbox",
799
+ checked: trashSel.has(item.sessionId),
800
+ onChange: (e) => toggleTrashSel(item.sessionId, e.target.checked),
801
+ }),
802
+ (0, react_jsx_runtime.jsxs)("div", {
803
+ style: { flex: 1, minWidth: 0 },
804
+ children: [
805
+ (0, react_jsx_runtime.jsx)("div", {
806
+ style: { fontSize: FONT_SIZE_SMALL, color: CSS_LABEL_PRIMARY, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
807
+ children: item.title || basenameOf(item.cwd) || item.sessionId,
808
+ }),
809
+ (0, react_jsx_runtime.jsx)("div", {
810
+ style: { fontSize: 11.5, color: CSS_LABEL_TERTIARY, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
811
+ children: `${item.cwd || item.sessionId} | ${t("trash.remaining", { n: item.remainingDays ?? 0 })}`,
812
+ }),
813
+ ],
814
+ }),
815
+ (0, react_jsx_runtime.jsx)("button", {
816
+ style: S.actionBtn(false),
817
+ onClick: () => restoreTrash([item.sessionId]),
818
+ children: t("trash.restore"),
819
+ }),
820
+ ],
821
+ }, item.sessionId)),
822
+ ],
823
+ });
824
+
626
825
  const rows = sessions ?? [];
627
826
  // 列表过滤:标题 / cwd / id / 状态词(大小写不敏感)
628
827
  const ql = query.trim().toLowerCase();
@@ -747,14 +946,7 @@
747
946
  children: (0, react_jsx_runtime.jsx)("input", {
748
947
  type: "checkbox",
749
948
  checked: selected.has(session.id),
750
- onChange: (event) => {
751
- setSelected((prev) => {
752
- const next = new Set(prev);
753
- if (event.target.checked) next.add(session.id);
754
- else next.delete(session.id);
755
- return next;
756
- });
757
- },
949
+ onChange: (event) => setRowSelected(session.id, event.target.checked),
758
950
  }),
759
951
  }),
760
952
  (0, react_jsx_runtime.jsxs)("div", {
@@ -1085,6 +1277,11 @@
1085
1277
  onClick: () => setTab("active"),
1086
1278
  children: `${t("tab.active")} (${rows.filter((row) => !row.archived && (row.live === true || row.running === true)).length})`,
1087
1279
  }),
1280
+ (0, react_jsx_runtime.jsx)("button", {
1281
+ style: S.tab(tab === "trash"),
1282
+ onClick: () => { setTab("trash"); loadTrashItems(); },
1283
+ children: `${t("tab.trash")}${trashItems === null ? "" : ` (${trashItems.length})`}`,
1284
+ }),
1088
1285
  (0, react_jsx_runtime.jsx)("button", {
1089
1286
  style: S.tab(tab === "help"),
1090
1287
  onClick: () => setTab("help"),
@@ -1117,10 +1314,16 @@
1117
1314
  onClick: () => deleteSelected(),
1118
1315
  children: t("deleteBatch.action", { n: selected.size }),
1119
1316
  }),
1317
+ // 低价值流式分析进度:每收到一条结果就 +1(事件驱动,不是秒表)
1318
+ filterProgress !== null &&
1319
+ (0, react_jsx_runtime.jsx)("span", {
1320
+ style: { fontSize: 12, color: CSS_LABEL_TERTIARY, whiteSpace: "nowrap" },
1321
+ children: t("deleteByRule.analyzing", { done: filterProgress.done, total: filterProgress.total }),
1322
+ }),
1120
1323
  (0, react_jsx_runtime.jsx)("button", {
1121
1324
  style: S.actionBtn(false),
1122
1325
  disabled: busy !== null,
1123
- onClick: () => { setRuleOpen((v) => !v); setRulePreview(null); },
1326
+ onClick: () => { setRuleOpen((v) => !v); },
1124
1327
  children: t("deleteByRule.action"),
1125
1328
  }),
1126
1329
  (0, react_jsx_runtime.jsx)("button", {
@@ -1166,32 +1369,30 @@
1166
1369
  (0, react_jsx_runtime.jsx)("input", {
1167
1370
  type: "text", value: rulePrefix, placeholder: t("deleteByRule.label.cwdPrefix"),
1168
1371
  style: { flex: 1, minWidth: RULE_PREFIX_MIN_WIDTH, height: SMALL_CONTROL_HEIGHT, borderRadius: CONTROL_RADIUS, border: CSS_BORDER_L2, background: CSS_BG_BASE, color: CSS_LABEL_PRIMARY, padding: "0 8px", fontSize: FONT_SIZE_SMALL, outline: "none" },
1169
- onChange: (e) => { setRulePrefix(e.target.value); setRulePreview(null); },
1372
+ onChange: (e) => { setRulePrefix(e.target.value); },
1170
1373
  }),
1171
1374
  (0, react_jsx_runtime.jsx)("button", {
1172
1375
  style: S.actionBtn(false),
1173
1376
  disabled: busy !== null,
1174
- onClick: previewRuleDelete,
1175
- children: t("deleteByRule.previewBtn"),
1377
+ onClick: applyFilter,
1378
+ // 状态由**请求事件**驱动:发起 → 显示「筛选中…」,响应回来 → 立刻给结果。
1379
+ // 不用秒表、不设超时上限:慢但正常的请求不该被任何时间阈值判成失败。
1380
+ children: busy === "__rule__" ? t("deleteByRule.filtering") : t("deleteByRule.previewBtn"),
1381
+ }),
1382
+ // 条件关系提示:四个条件(归档 / 价值 / 时间 / 目录)是**与**关系,
1383
+ // 必须同时满足才会被勾选;界面上写清楚,免得误以为是不限/或关系。
1384
+ (0, react_jsx_runtime.jsx)("span", {
1385
+ style: { fontSize: 11.5, color: CSS_LABEL_TERTIARY, flexBasis: "100%" },
1386
+ children: t("deleteByRule.andHint"),
1176
1387
  }),
1177
- rulePreview !== null && rulePreview.length > 0 &&
1178
- (0, react_jsx_runtime.jsx)("button", {
1179
- style: { ...S.actionBtn(true), borderColor: CSS_DANGER, color: CSS_DANGER },
1180
- disabled: busy !== null,
1181
- onClick: runRuleDelete,
1182
- children: t("deleteByRule.run") + ` (${rulePreview.length})`,
1183
- }),
1184
- rulePreview !== null && rulePreview.length > 0 &&
1185
- (0, react_jsx_runtime.jsx)("span", {
1186
- style: { color: CSS_LABEL_TERTIARY, fontSize: 12 },
1187
- children: t("search.hits", { n: rulePreview.length }),
1188
- }),
1189
1388
  ],
1190
1389
  }),
1191
1390
  (0, react_jsx_runtime.jsx)("div", {
1192
1391
  style: S.body,
1193
1392
  children: tab === "help"
1194
1393
  ? renderHelp()
1394
+ : tab === "trash"
1395
+ ? renderTrash()
1195
1396
  : (0, react_jsx_runtime.jsxs)(react.Fragment, {
1196
1397
  children: [
1197
1398
  // —— 全文搜索结果区(官方 FTS5 优先,自研兜底) ——
@@ -13,18 +13,16 @@
13
13
 
14
14
  // ---------- 工具 ----------
15
15
 
16
- // 全局 fetch 超时兜底:DSH API 挂起(重负载/路由未注册)时界面不再无限等待。
17
- // 与 fetch 同签名(url, opts, timeoutMs),默认 30s;分片统一走 __scFetch。
18
- // timeoutMs 传 0(或负数)= **不设超时**:只适合「本来就慢、但会持续吐数据」的流式接口
19
- // (会话列表冷缓存要逐份解压上百份日志,实测 41~226 秒;套 30 秒上限必然被中途掐断,
20
- // 表现为面板刚重启就报「读取会话列表失败」,等缓存建好后重试又正常)。
21
- // 这类接口的正确判据不是「多久没回完」,而是「有没有在吐数据」,由调用方自己盯流。
22
- const FETCH_TIMEOUT_MS = 30000;
16
+ // 统一 fetch 入口(url, opts, timeoutMs)。**默认不设超时**。
17
+ // 曾经默认 30 秒「兜底」,结果两次把慢但正常的请求掐成失败:
18
+ // · 会话列表冷缓存要逐份解压上百份日志(实测 41~226 秒)→ 刚重启报「读取会话列表失败」;
19
+ // · 按条件筛选勾了「低价值」时要逐个会话读事件 → 报「操作失败:signal is aborted…」。
20
+ // 结论:**判定只能按事件驱动**(请求完成 / 失败 / 数据到达),不能靠拍一个秒数上限;
21
+ // 时间阈值一写死,慢就被误读成坏。真要限时,必须由调用方显式传 timeoutMs 并说清依据。
23
22
  window.__scFetch = function (url, opts, timeoutMs) {
24
- const budget = timeoutMs === void 0 ? FETCH_TIMEOUT_MS : timeoutMs;
25
- if (!(budget > 0)) return fetch(url, opts || {});
23
+ if (!(timeoutMs > 0)) return fetch(url, opts || {});
26
24
  const controller = new AbortController();
27
- const timer = setTimeout(() => controller.abort(), budget);
25
+ const timer = setTimeout(() => controller.abort(), timeoutMs);
28
26
  const next = opts ? Object.assign({}, opts, { signal: controller.signal }) : { signal: controller.signal };
29
27
  return fetch(url, next).finally(() => clearTimeout(timer));
30
28
  };