@kangyishuai/dsh-session-delete 0.1.0 → 0.3.0

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/lib/client.js CHANGED
@@ -55,6 +55,7 @@ window.__ModuleLoader__.load({
55
55
  "confirm.size": "会话日志约 {size}",
56
56
  "confirm.live": "该会话仍在本机打开,删除前会先停止它的工作。",
57
57
  "confirm.children": "会一并带上 {n} 个子代理会话",
58
+ "confirm.cascade": "同时删除这 {n} 个子会话(各自进入回收站,需分别恢复)",
58
59
  "confirm.refs": "将清理:{list}",
59
60
  "confirm.trashPath": "回收站位置:{path}",
60
61
  "confirm.blocked": "暂时无法删除:{reason}",
@@ -67,6 +68,22 @@ window.__ModuleLoader__.load({
67
68
  "panel.title": "会话回收站",
68
69
  "panel.tabTrash": "回收站",
69
70
  "panel.tabAudit": "审计",
71
+ "panel.tabHealth": "体检",
72
+ "panel.tabReceipts": "回执",
73
+ "receipts.empty": "还没有操作回执。",
74
+ "receipts.restored": "已移回原位置",
75
+ "health.loading": "正在检查…",
76
+ "health.inventory":
77
+ "已存 {stored} · live {live} · 归档 {archived} · 回收站 {trash} · 待处理 {pending}",
78
+ "health.ok": "未发现失效引用。",
79
+ "health.items": "{n} 条",
80
+ "health.agentTool": "模型工具 session_delete:{state}",
81
+ "health.agentToolOn": "已注册",
82
+ "health.agentToolOff": "未注册(宿主未提供 tools 运行时)",
83
+ "health.unavailable": "无法体检:{reason}",
84
+ "health.clean": "清理失效引用({n})",
85
+ "health.cleanConfirm": "确认清理 {n} 条?只动登记表,不碰会话文件",
86
+ "health.cleanDone": "已清理 {n} 条",
70
87
  "panel.empty": "回收站是空的。",
71
88
  "panel.auditEmpty": "还没有审计记录。",
72
89
  "panel.restore": "恢复",
@@ -92,6 +109,7 @@ window.__ModuleLoader__.load({
92
109
  "confirm.size": "Session log is about {size}",
93
110
  "confirm.live": "This session is still open; its work is stopped first.",
94
111
  "confirm.children": "{n} subagent session(s) come along",
112
+ "confirm.cascade": "Also delete these {n} child session(s) (each goes to trash separately)",
95
113
  "confirm.refs": "Will clean: {list}",
96
114
  "confirm.trashPath": "Trash location: {path}",
97
115
  "confirm.blocked": "Cannot delete right now: {reason}",
@@ -104,6 +122,22 @@ window.__ModuleLoader__.load({
104
122
  "panel.title": "Session trash",
105
123
  "panel.tabTrash": "Trash",
106
124
  "panel.tabAudit": "Audit",
125
+ "panel.tabHealth": "Health",
126
+ "panel.tabReceipts": "Receipts",
127
+ "receipts.empty": "No operation receipts yet.",
128
+ "receipts.restored": "restored",
129
+ "health.loading": "Checking…",
130
+ "health.inventory":
131
+ "stored {stored} · live {live} · archived {archived} · trash {trash} · pending {pending}",
132
+ "health.ok": "No dangling references found.",
133
+ "health.items": "{n} item(s)",
134
+ "health.agentTool": "Agent tool session_delete: {state}",
135
+ "health.agentToolOn": "registered",
136
+ "health.agentToolOff": "not registered (host has no tools runtime)",
137
+ "health.unavailable": "Cannot run the check: {reason}",
138
+ "health.clean": "Clean dangling references ({n})",
139
+ "health.cleanConfirm": "Clean {n} dangling reference(s)? Bookkeeping only, no session files.",
140
+ "health.cleanDone": "Cleaned {n}",
107
141
  "panel.empty": "The trash is empty.",
108
142
  "panel.auditEmpty": "No audit entries yet.",
109
143
  "panel.restore": "Restore",
@@ -441,12 +475,16 @@ window.__ModuleLoader__.load({
441
475
  var busy = busyState[0];
442
476
  var setBusy = busyState[1];
443
477
  var requestId = request ? request.sessionId : null;
478
+ var cascadeState = React.useState(false);
479
+ var cascade = cascadeState[0];
480
+ var setCascade = cascadeState[1];
444
481
 
445
482
  React.useEffect(() => {
446
483
  if (!requestId) {
447
484
  setPlan(null);
448
485
  setError(null);
449
486
  setBusy(false);
487
+ setCascade(false);
450
488
  return undefined;
451
489
  }
452
490
  var alive = true;
@@ -479,6 +517,7 @@ window.__ModuleLoader__.load({
479
517
  sessionId: request.sessionId,
480
518
  digest: plan.digest,
481
519
  title: request.title || null,
520
+ cascade: cascade && plan.children.length > 0,
482
521
  })
483
522
  .then((/** @type {any} */ result) => {
484
523
  props.requestStore.set(null);
@@ -515,6 +554,42 @@ window.__ModuleLoader__.load({
515
554
  request.title
516
555
  ? h("div", { style: { fontWeight: 600, marginBottom: "10px" } }, request.title)
517
556
  : null,
557
+ plan && plan.children.length > 0
558
+ ? h(
559
+ "label",
560
+ {
561
+ style: {
562
+ display: "flex",
563
+ alignItems: "flex-start",
564
+ gap: "8px",
565
+ margin: "8px 0 4px",
566
+ cursor: "pointer",
567
+ },
568
+ },
569
+ h("input", {
570
+ type: "checkbox",
571
+ checked: cascade,
572
+ disabled: busy,
573
+ onChange: (/** @type {any} */ event) => setCascade(Boolean(event.target.checked)),
574
+ style: { marginTop: "2px" },
575
+ }),
576
+ h(
577
+ "span",
578
+ null,
579
+ props.t("confirm.cascade", { n: plan.children.length }),
580
+ h(
581
+ "span",
582
+ {
583
+ style: { display: "block", color: T.faint, fontSize: "12px", marginTop: "2px" },
584
+ },
585
+ plan.children
586
+ .slice(0, 4)
587
+ .map((/** @type {any} */ child) => child.title || child.id)
588
+ .join(" · ") + (plan.children.length > 4 ? " …" : ""),
589
+ ),
590
+ ),
591
+ )
592
+ : null,
518
593
  lines.map((/** @type {any} */ line, /** @type {any} */ index) =>
519
594
  h("div", { key: "line-" + index, style: { marginBottom: "4px" } }, line),
520
595
  ),
@@ -568,6 +643,43 @@ window.__ModuleLoader__.load({
568
643
  var purgeState = React.useState(null);
569
644
  var confirmPurge = purgeState[0];
570
645
  var setConfirmPurge = purgeState[1];
646
+ var scanState = React.useState(null);
647
+ var scan = scanState[0];
648
+ var setScan = scanState[1];
649
+ var scanErrorState = React.useState(null);
650
+ var scanError = scanErrorState[0];
651
+ var setScanError = scanErrorState[1];
652
+ var cleanState = React.useState(false);
653
+ var cleaning = cleanState[0];
654
+ var setCleaning = cleanState[1];
655
+ var cleanMsgState = React.useState("");
656
+ var cleanMsg = cleanMsgState[0];
657
+ var setCleanMsg = cleanMsgState[1];
658
+ var receiptsState = React.useState(null);
659
+ var receipts = receiptsState[0];
660
+ var setReceipts = receiptsState[1];
661
+
662
+ const loadReceipts = React.useCallback(() => {
663
+ props
664
+ .call("receipts", { limit: 50 })
665
+ .then((/** @type {any} */ value) => {
666
+ setReceipts(value && value.entries ? value.entries : []);
667
+ })
668
+ .catch(() => setReceipts([]));
669
+ }, []);
670
+
671
+ const loadHealth = React.useCallback(() => {
672
+ setScan(null);
673
+ setScanError(null);
674
+ props
675
+ .call("healthScan")
676
+ .then((/** @type {any} */ value) => {
677
+ setScan(value);
678
+ })
679
+ .catch((/** @type {any} */ reason) => {
680
+ setScanError(errorText(reason));
681
+ });
682
+ }, []);
571
683
 
572
684
  const loadAudit = React.useCallback(() => {
573
685
  props
@@ -711,10 +823,224 @@ window.__ModuleLoader__.load({
711
823
  },
712
824
  props.t("panel.tabAudit"),
713
825
  ),
826
+ h(
827
+ Btn,
828
+ {
829
+ onClick: () => {
830
+ setTab("health");
831
+ loadHealth();
832
+ },
833
+ },
834
+ props.t("panel.tabHealth"),
835
+ ),
836
+ h(
837
+ Btn,
838
+ {
839
+ onClick: () => {
840
+ setTab("receipts");
841
+ loadReceipts();
842
+ },
843
+ },
844
+ props.t("panel.tabReceipts"),
845
+ ),
714
846
  ),
715
847
  );
716
848
 
717
- if (tab === "trash") {
849
+ if (tab === "receipts") {
850
+ if (!receipts || receipts.length === 0) {
851
+ content.push(
852
+ h(
853
+ "div",
854
+ { key: "receipts-empty", style: { color: T.dim, padding: "8px 0" } },
855
+ props.t("receipts.empty"),
856
+ ),
857
+ );
858
+ } else {
859
+ receipts.forEach((/** @type {any} */ receipt, /** @type {any} */ index) => {
860
+ const removed = receipt.removed || [];
861
+ const okCount = removed.filter(
862
+ (/** @type {any} */ item) => item.status === "ok",
863
+ ).length;
864
+ const detail =
865
+ receipt.action === "trash"
866
+ ? formatBytes(receipt.sizeBytes || 0) + " · " + okCount + "/" + removed.length
867
+ : receipt.action === "restore"
868
+ ? props.t("receipts.restored")
869
+ : receipt.action === "purge"
870
+ ? formatBytes(receipt.bytes || 0)
871
+ : String(receipt.total || 0);
872
+ content.push(
873
+ h(
874
+ "div",
875
+ {
876
+ key: "receipt-" + index,
877
+ title: String(receipt.sessionId || ""),
878
+ style: {
879
+ borderTop: "1px solid " + T.border,
880
+ padding: "7px 0",
881
+ fontSize: "12px",
882
+ display: "flex",
883
+ alignItems: "baseline",
884
+ gap: "6px",
885
+ },
886
+ },
887
+ h(
888
+ "span",
889
+ { style: { color: T.faint, whiteSpace: "nowrap" } },
890
+ formatTime(receipt.at),
891
+ ),
892
+ h(
893
+ "span",
894
+ { style: { fontWeight: 600, whiteSpace: "nowrap" } },
895
+ String(receipt.action || ""),
896
+ ),
897
+ h(
898
+ "span",
899
+ {
900
+ style: {
901
+ flex: 1,
902
+ minWidth: 0,
903
+ color: T.dim,
904
+ overflow: "hidden",
905
+ textOverflow: "ellipsis",
906
+ whiteSpace: "nowrap",
907
+ },
908
+ },
909
+ String(receipt.title || receipt.sessionId || "—"),
910
+ ),
911
+ h("span", { style: { color: T.faint, whiteSpace: "nowrap" } }, detail),
912
+ ),
913
+ );
914
+ });
915
+ }
916
+ } else if (tab === "health") {
917
+ if (scanError) {
918
+ content.push(
919
+ h("div", { key: "scan-err", style: { color: T.danger, padding: "8px 0" } }, scanError),
920
+ );
921
+ } else if (!scan) {
922
+ content.push(
923
+ h(
924
+ "div",
925
+ { key: "scan-loading", style: { color: T.dim, padding: "8px 0" } },
926
+ props.t("health.loading"),
927
+ ),
928
+ );
929
+ } else if (!scan.ok) {
930
+ content.push(
931
+ h(
932
+ "div",
933
+ { key: "scan-na", style: { color: T.dim, padding: "8px 0" } },
934
+ props.t("health.unavailable", { reason: scan.reason || "" }),
935
+ ),
936
+ );
937
+ } else {
938
+ content.push(
939
+ h(
940
+ "div",
941
+ { key: "scan-inventory", style: { color: T.dim, fontSize: "12px" } },
942
+ props.t("health.inventory", scan.inventory || {}),
943
+ ),
944
+ );
945
+ content.push(
946
+ h(
947
+ "div",
948
+ { key: "scan-agent-tool", style: { color: T.dim, fontSize: "12px" } },
949
+ props.t("health.agentTool", {
950
+ state: scan.agentTool
951
+ ? props.t("health.agentToolOn")
952
+ : props.t("health.agentToolOff"),
953
+ }),
954
+ ),
955
+ );
956
+ if (scan.findings.length === 0) {
957
+ content.push(
958
+ h("div", { key: "scan-ok", style: { padding: "8px 0" } }, props.t("health.ok")),
959
+ );
960
+ }
961
+ scan.findings.forEach((/** @type {any} */ finding, /** @type {any} */ index) => {
962
+ content.push(
963
+ h(
964
+ "div",
965
+ {
966
+ key: "finding-" + index,
967
+ style: {
968
+ borderTop: "1px solid " + T.border,
969
+ padding: "8px 0",
970
+ color: finding.severity === "warn" ? T.text : T.dim,
971
+ },
972
+ },
973
+ h(
974
+ "div",
975
+ { style: { fontWeight: 600 } },
976
+ finding.label + " · " + props.t("health.items", { n: finding.items.length }),
977
+ ),
978
+ h(
979
+ "div",
980
+ { style: { color: T.faint, fontSize: "12px", wordBreak: "break-all" } },
981
+ finding.items
982
+ .slice(0, 6)
983
+ .map((/** @type {any} */ item) =>
984
+ typeof item === "string" ? item : JSON.stringify(item),
985
+ )
986
+ .join(" · "),
987
+ ),
988
+ ),
989
+ );
990
+ });
991
+ if (scan.cleanable && scan.cleanable.total > 0) {
992
+ content.push(
993
+ h(
994
+ "div",
995
+ {
996
+ key: "scan-clean",
997
+ style: { marginTop: "10px", display: "flex", gap: "8px", alignItems: "center" },
998
+ },
999
+ confirmPurge === "__health__"
1000
+ ? h(
1001
+ Btn,
1002
+ {
1003
+ danger: true,
1004
+ disabled: cleaning,
1005
+ onClick: () => {
1006
+ setCleaning(true);
1007
+ setCleanMsg("");
1008
+ props
1009
+ .call("cleanHealth", { classes: ["archived", "pinned", "workspace"] })
1010
+ .then((/** @type {any} */ result) => {
1011
+ setCleaning(false);
1012
+ setConfirmPurge(null);
1013
+ setCleanMsg(props.t("health.cleanDone", { n: result.total }));
1014
+ loadHealth();
1015
+ props.bump?.();
1016
+ })
1017
+ .catch((/** @type {any} */ reason) => {
1018
+ setCleaning(false);
1019
+ setCleanMsg(errorText(reason));
1020
+ });
1021
+ },
1022
+ },
1023
+ props.t("health.cleanConfirm", { n: scan.cleanable.total }),
1024
+ )
1025
+ : h(
1026
+ Btn,
1027
+ { onClick: () => setConfirmPurge("__health__") },
1028
+ props.t("health.clean", { n: scan.cleanable.total }),
1029
+ ),
1030
+ ),
1031
+ );
1032
+ }
1033
+ if (cleanMsg) {
1034
+ content.push(
1035
+ h(
1036
+ "div",
1037
+ { key: "scan-msg", style: { color: T.dim, marginTop: "8px", fontSize: "12px" } },
1038
+ cleanMsg,
1039
+ ),
1040
+ );
1041
+ }
1042
+ }
1043
+ } else if (tab === "trash") {
718
1044
  if (entries.length === 0) {
719
1045
  content.push(
720
1046
  h(
@@ -1060,6 +1386,24 @@ window.__ModuleLoader__.load({
1060
1386
  void refreshRows(result && result.sessionId ? result.sessionId : undefined);
1061
1387
  tickStore.set(tickStore.getSnapshot() + 1);
1062
1388
  };
1389
+ // 外部变更(agent 工具、另一个窗口、CLI)不会通知本页面,
1390
+ // 定期拉一次会话列表;页面重新可见时也立刻拉一次。
1391
+ ctx.effect(() => {
1392
+ const pull = () => {
1393
+ if (document.visibilityState === "visible") {
1394
+ void refreshRows(undefined);
1395
+ // 回收站条目也可能被 agent 工具/另一个窗口改变,顺带刷新页脚计数
1396
+ tickStore.set(tickStore.getSnapshot() + 1);
1397
+ }
1398
+ };
1399
+ const timer = setInterval(pull, 10_000);
1400
+ document.addEventListener("visibilitychange", pull);
1401
+ return () => {
1402
+ clearInterval(timer);
1403
+ document.removeEventListener("visibilitychange", pull);
1404
+ };
1405
+ }, "session-delete: poll external session removals");
1406
+
1063
1407
  const onPurged = (/** @type {any} */ sessionId) => {
1064
1408
  void refreshRows(sessionId || undefined);
1065
1409
  };
package/lib/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // @ts-check
2
- // host 半入口:Cordis 插件(类形态),构造时探测宿主能力并注册 sessionDelete Remote 服务。
3
- // 改动后需要重启 DSH 桌面版。
2
+ // host 半入口:Cordis 插件(类形态)。Remote 方法必须定义在导出的这个类自身的原型上,
3
+ // 否则 Typert 网关不会 claim 端点(不要包一层子类)。
4
+ // 模型工具 session_delete 在 SessionDeleteService 构造函数里注册。
4
5
  import { SessionDeleteService } from "./service.js";
5
6
 
6
7
  export { SessionDeleteService };