dsh-keeper-plugin 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +44 -11
- package/client.js +105 -55
- package/index.js +170 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,14 +37,14 @@ DSH 管家是一个带左侧栏入口的 DSH 插件。它把散落在 DSH 各处
|
|
|
37
37
|
- 按工作区分组展示会话:标题、最后活动时间、消息数、日志占用,以及运行中、已归档、
|
|
38
38
|
空会话等状态徽标。
|
|
39
39
|
- 搜索、按活动时间 / 大小 / 标题排序;当前工作区高亮;列表每 8 秒自动刷新。
|
|
40
|
-
-
|
|
40
|
+
- 列表「删除会话」的行为可在设置中二选一,默认移入回收站:
|
|
41
41
|
- **归档**:只从侧栏隐藏,随时可以取消归档,不移动磁盘文件。
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
-
|
|
45
|
-
|
|
46
|
-
-
|
|
47
|
-
-
|
|
42
|
+
- **移入回收站**(默认):先把运行中的会话解绑,再把日志目录移入插件回收站;可以恢复,
|
|
43
|
+
删除后还有撤销提示;回收站里的彻底删除仍会二次确认。
|
|
44
|
+
- **永久删除**:直接删除会话日志目录,并同步清理投影缓存、spill 缓存、工作区挂载、
|
|
45
|
+
归档/置顶状态与会话索引;运行中的会话禁止删除,删除前会二次确认(可在设置中关闭)。
|
|
46
|
+
- 批量选择、批量归档、批量删除。
|
|
47
|
+
- 清理空会话(仍先移入回收站)、「空间占用排行」Top 5、删除前导出会话日志。
|
|
48
48
|
- 侧栏显示预设:精简 / 全部显示。
|
|
49
49
|
|
|
50
50
|
### 插件与侧栏入口
|
|
@@ -114,7 +114,7 @@ cd dsh-keeper
|
|
|
114
114
|
3. **插件管理**
|
|
115
115
|
4. **回收站**
|
|
116
116
|
|
|
117
|
-
设置页在「设置 → DSH
|
|
117
|
+
设置页在「设置 → DSH 管家」,包含删除会话行为(移入回收站 / 永久删除)、删除前二次确认、入口显示和通知偏好。
|
|
118
118
|
|
|
119
119
|
## 数据与权限
|
|
120
120
|
|
|
@@ -126,8 +126,8 @@ cd dsh-keeper
|
|
|
126
126
|
| 会话日志(只读写 DSH 已有文件) | `~/.dsh/sessions/<workspace>/session-<uuid>/session.v4.jsonl.zstd` |
|
|
127
127
|
|
|
128
128
|
插件使用 DSH 的 Host 服务完成这些操作:读取工作区与会话清单、停止/解绑运行中的会话、
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
删除会话日志目录并清理投影缓存与索引;回收站条目恢复时移回原路径并重新挂载。所有本机 API
|
|
130
|
+
只接受同源 POST,并通过 `ctx.connection.requestRejection` 做信任校验。
|
|
131
131
|
|
|
132
132
|
插件**不会**:
|
|
133
133
|
|
|
@@ -151,7 +151,7 @@ cd dsh-keeper
|
|
|
151
151
|
- 侧栏入口的显示/隐藏是客户端样式层实现。DSH 宿主改版导致类名变化时,入口可能重新出现,
|
|
152
152
|
但不会报错,也不会影响插件本体。
|
|
153
153
|
- 运行中的会话不能直接删除;需要先停止任务或等待任务结束。
|
|
154
|
-
-
|
|
154
|
+
- 永久删除模式会直接删除日志目录,不可撤销;回收站可恢复误删的会话,并保留空会话清理的中间层。
|
|
155
155
|
|
|
156
156
|
## 开发
|
|
157
157
|
|
|
@@ -166,6 +166,39 @@ node .dsh-keeper-dev/test-client.mjs
|
|
|
166
166
|
node .dsh-keeper-dev/test-expand.mjs
|
|
167
167
|
```
|
|
168
168
|
|
|
169
|
+
## 更新日志
|
|
170
|
+
|
|
171
|
+
### 0.1.5 - 2026-11-25
|
|
172
|
+
|
|
173
|
+
#### 变更
|
|
174
|
+
|
|
175
|
+
- README 的「更新日志」改为按版本分节(新增 / 变更 / 修复),并移除重复的 CHANGELOG 链接。
|
|
176
|
+
- CHANGELOG.md 所有版本统一为相同结构。
|
|
177
|
+
|
|
178
|
+
### 0.1.4 - 2026-11-25
|
|
179
|
+
|
|
180
|
+
#### 新增
|
|
181
|
+
|
|
182
|
+
- 设置页新增「删除会话行为」二选一:`移入回收站`(默认,可恢复)或 `永久删除`;列表里的「删除会话」按钮按此设置执行。
|
|
183
|
+
- 永久删除模式下,列表删除会先弹二次确认(可在设置中关闭确认)。
|
|
184
|
+
|
|
185
|
+
#### 变更
|
|
186
|
+
|
|
187
|
+
- 回收站的「彻底删除」和「清空回收站」补齐与永久删除相同的清理:会话日志目录、官方投影缓存、spill 目录、工作区挂载、归档/置顶标记与索引记录,并广播 `api-session/removed` 事件。
|
|
188
|
+
- 永久删除会级联删除 `origin: "subagent"` 且 `parentSession` 指向该会话的子会话;fork 会话不级联。
|
|
189
|
+
|
|
190
|
+
#### 修复
|
|
191
|
+
|
|
192
|
+
- 修复 DSH 管家自身在「插件管理」中可被卸载的问题。
|
|
193
|
+
|
|
194
|
+
### 0.1.3 - 2026-11-14
|
|
195
|
+
|
|
196
|
+
#### 变更
|
|
197
|
+
|
|
198
|
+
- 放宽 DSH 版本要求为 `engines.dsh: ">=0.2.2-rc.1"`;0.3 及之后未逐版验证。
|
|
199
|
+
|
|
200
|
+
更早版本见 [CHANGELOG.md](https://github.com/swrabbit/dsh-keeper/blob/main/CHANGELOG.md) 与 [GitHub Releases](https://github.com/swrabbit/dsh-keeper/releases)。
|
|
201
|
+
|
|
169
202
|
## 反馈
|
|
170
203
|
|
|
171
204
|
- Issue:<https://github.com/swrabbit/dsh-keeper/issues>
|
package/client.js
CHANGED
|
@@ -11,6 +11,8 @@ const NS = 'dsh-keeper';
|
|
|
11
11
|
const PANEL_ID = 'dsh-keeper';
|
|
12
12
|
const API_BASE = '/dsh-keeper/api/';
|
|
13
13
|
const LEGACY_BUNDLE = 'dsh-sidebar-studio';
|
|
14
|
+
/** Bundle names the keeper may be installed under; every self-protection check must recognize all of them. */
|
|
15
|
+
const SELF_BUNDLES = new Set(['dsh-keeper', 'dsh-keeper-plugin', LEGACY_BUNDLE]);
|
|
14
16
|
const STORAGE_PREFIX = 'dsh-keeper:';
|
|
15
17
|
const LEGACY_STORAGE_PREFIX = 'dsh-sidebar-studio:';
|
|
16
18
|
|
|
@@ -134,6 +136,8 @@ const DICT = {
|
|
|
134
136
|
archive: '归档',
|
|
135
137
|
unarchive: '取消归档',
|
|
136
138
|
moveToTrash: '移入回收站',
|
|
139
|
+
deleteSession: '删除会话',
|
|
140
|
+
deleteSessionHint: '永久删除该会话:日志、缓存与索引一并清理,不可恢复',
|
|
137
141
|
restore: '恢复',
|
|
138
142
|
purge: '彻底删除',
|
|
139
143
|
open: '打开',
|
|
@@ -175,12 +179,15 @@ const DICT = {
|
|
|
175
179
|
archivedMsg: '已归档 {n} 项',
|
|
176
180
|
restoredMsg: '已恢复 {n} 项',
|
|
177
181
|
purgedMsg: '已彻底删除 {n} 项',
|
|
182
|
+
deletedMsg: '已删除 {n} 个会话',
|
|
178
183
|
cleanedMsg: '已清理 {n} 个空会话',
|
|
179
184
|
undo: '撤销',
|
|
180
185
|
confirmPurgeTitle: '彻底删除会话?',
|
|
181
186
|
confirmPurgeBody: '将从磁盘删除 {n} 个会话(约 {size})。此操作不可撤销,删除后重启也不会恢复。',
|
|
182
187
|
confirmEmptyTitle: '清空回收站?',
|
|
183
188
|
confirmEmptyBody: '将彻底删除回收站中全部 {n} 个会话(约 {size}),此操作不可撤销。',
|
|
189
|
+
confirmDeleteTitle: '删除会话?',
|
|
190
|
+
confirmDeleteBody: '将永久删除 {n} 个会话(约 {size}),并清理其日志、缓存与索引。此操作不可撤销,删除后重启也不会恢复。',
|
|
184
191
|
cancel: '取消',
|
|
185
192
|
confirm: '确认删除',
|
|
186
193
|
topSizes: '空间占用排行',
|
|
@@ -336,13 +343,16 @@ const DICT = {
|
|
|
336
343
|
settingsHint: '设置页位于「设置 → DSH 管家」。',
|
|
337
344
|
settingsTitle: 'DSH 管家设置',
|
|
338
345
|
settingsSubtitle: '删除策略与侧栏入口的默认行为',
|
|
339
|
-
defaultDeleteMode: '
|
|
346
|
+
defaultDeleteMode: '删除会话行为',
|
|
340
347
|
modeTrash: '移入回收站',
|
|
341
348
|
modeTrashHint: '推荐。会话先进入回收站,可恢复;彻底删除需要再次确认。',
|
|
342
349
|
modeArchive: '仅归档',
|
|
343
350
|
modeArchiveHint: '只从侧栏隐藏,不移动磁盘文件,可从会话列表取消归档。',
|
|
344
|
-
|
|
345
|
-
|
|
351
|
+
modeDelete: '永久删除',
|
|
352
|
+
modeDeleteHint: '直接删除日志、缓存与索引,不可恢复。',
|
|
353
|
+
deleteModeHint: '列表「删除会话」的行为:默认移入回收站、可恢复;选永久删除时删除前会二次确认。',
|
|
354
|
+
confirmPurgeLabel: '永久删除前二次确认',
|
|
355
|
+
confirmPurgeHint: '关闭后永久删除(列表删除或回收站彻底删除)不再弹出确认框,请谨慎使用。',
|
|
346
356
|
entryVisible: '显示侧栏入口',
|
|
347
357
|
entryVisibleHint: '关闭后侧栏底部不再显示「DSH 管家」图标,设置页仍然可用。',
|
|
348
358
|
resetSettings: '恢复默认设置',
|
|
@@ -455,6 +465,8 @@ const DICT = {
|
|
|
455
465
|
archive: 'Archive',
|
|
456
466
|
unarchive: 'Unarchive',
|
|
457
467
|
moveToTrash: 'Move to trash',
|
|
468
|
+
deleteSession: 'Delete session',
|
|
469
|
+
deleteSessionHint: 'Permanently delete this session: transcript, caches and index are removed. This cannot be undone.',
|
|
458
470
|
restore: 'Restore',
|
|
459
471
|
purge: 'Delete permanently',
|
|
460
472
|
open: 'Open',
|
|
@@ -496,12 +508,15 @@ const DICT = {
|
|
|
496
508
|
archivedMsg: 'Archived {n}',
|
|
497
509
|
restoredMsg: 'Restored {n}',
|
|
498
510
|
purgedMsg: 'Permanently deleted {n}',
|
|
511
|
+
deletedMsg: 'Deleted {n} sessions',
|
|
499
512
|
cleanedMsg: 'Cleaned {n} blank sessions',
|
|
500
513
|
undo: 'Undo',
|
|
501
514
|
confirmPurgeTitle: 'Delete permanently?',
|
|
502
515
|
confirmPurgeBody: 'This removes {n} sessions ({size}) from disk. It cannot be undone and will not come back after a restart.',
|
|
503
516
|
confirmEmptyTitle: 'Empty the trash?',
|
|
504
517
|
confirmEmptyBody: 'This permanently deletes all {n} sessions in the trash ({size}). It cannot be undone.',
|
|
518
|
+
confirmDeleteTitle: 'Delete session?',
|
|
519
|
+
confirmDeleteBody: 'This permanently deletes {n} sessions ({size}) and clears their transcript, caches and index. It cannot be undone and will not come back after a restart.',
|
|
505
520
|
cancel: 'Cancel',
|
|
506
521
|
confirm: 'Delete permanently',
|
|
507
522
|
topSizes: 'Largest sessions',
|
|
@@ -657,13 +672,16 @@ const DICT = {
|
|
|
657
672
|
settingsHint: 'Find this page under Settings → DSH Keeper.',
|
|
658
673
|
settingsTitle: 'DSH Keeper settings',
|
|
659
674
|
settingsSubtitle: 'Delete policy and sidebar entry defaults',
|
|
660
|
-
defaultDeleteMode: '
|
|
675
|
+
defaultDeleteMode: 'Delete action in the session list',
|
|
661
676
|
modeTrash: 'Move to trash',
|
|
662
677
|
modeTrashHint: 'Recommended. Sessions go to the trash first and can be restored; purging asks again.',
|
|
663
678
|
modeArchive: 'Archive only',
|
|
664
679
|
modeArchiveHint: 'Hides the session from the sidebar without touching the log; unarchive from the session list.',
|
|
680
|
+
modeDelete: 'Delete permanently',
|
|
681
|
+
modeDeleteHint: 'Removes the log, cache and index at once; cannot be undone.',
|
|
682
|
+
deleteModeHint: 'What the list Delete action does: move to trash (restorable) by default; permanent delete asks first.',
|
|
665
683
|
confirmPurgeLabel: 'Confirm before permanent delete',
|
|
666
|
-
confirmPurgeHint: 'When off, permanent
|
|
684
|
+
confirmPurgeHint: 'When off, permanent deletes (from the list or the trash) happen without a dialog. Use with care.',
|
|
667
685
|
entryVisible: 'Show sidebar entry',
|
|
668
686
|
entryVisibleHint: 'Hide the DSH Keeper icon at the sidebar foot; the settings page stays available.',
|
|
669
687
|
resetSettings: 'Reset to defaults',
|
|
@@ -2752,7 +2770,8 @@ function MainPanel(props) {
|
|
|
2752
2770
|
bridge.applyHide([...hidden], panels);
|
|
2753
2771
|
}, [hidden, panels, tick]);
|
|
2754
2772
|
|
|
2755
|
-
const settings = boot?.state?.settings ?? {
|
|
2773
|
+
const settings = boot?.state?.settings ?? { deleteMode: 'trash', confirmPurge: true };
|
|
2774
|
+
const deleteMode = settings.deleteMode === 'delete' ? 'delete' : 'trash';
|
|
2756
2775
|
|
|
2757
2776
|
const sessions = React.useMemo(() => {
|
|
2758
2777
|
const out = [];
|
|
@@ -2775,6 +2794,10 @@ function MainPanel(props) {
|
|
|
2775
2794
|
const trash = boot?.trash ?? [];
|
|
2776
2795
|
const trashSize = trash.reduce((sum, entry) => sum + (Number(entry.sizeBytes) || 0), 0);
|
|
2777
2796
|
|
|
2797
|
+
const listDeleteMode = settings.deleteMode === 'delete' ? 'delete' : 'trash';
|
|
2798
|
+
const listDeleteLabel = listDeleteMode === 'delete' ? t('deleteSession') : t('moveToTrash');
|
|
2799
|
+
const listDeleteHint = listDeleteMode === 'delete' ? t('deleteSessionHint') : t('trashSessionHint');
|
|
2800
|
+
|
|
2778
2801
|
// Status filter mirrors the plugin manager: one chip narrows the list without
|
|
2779
2802
|
// changing which sessions exist, so bulk actions stay scoped to the filter.
|
|
2780
2803
|
const sessionStatusMatches = (session) => {
|
|
@@ -2885,23 +2908,57 @@ function MainPanel(props) {
|
|
|
2885
2908
|
}
|
|
2886
2909
|
};
|
|
2887
2910
|
|
|
2888
|
-
const
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2911
|
+
const deleteSessionsFromList = (ids) => {
|
|
2912
|
+
const mode = settings.deleteMode === 'delete' ? 'delete' : 'trash';
|
|
2913
|
+
const rows = sessions.filter((session) => ids.includes(session.id));
|
|
2914
|
+
const size = rows.reduce((sum, session) => sum + (Number(session.sizeBytes) || 0), 0);
|
|
2915
|
+
|
|
2916
|
+
if (mode === 'trash') {
|
|
2917
|
+
void run(async () => {
|
|
2918
|
+
const result = await bridge.api('deleteSessions', { sessionIds: ids, mode: 'trash' });
|
|
2919
|
+
const done = (result?.done ?? []).map((item) => item.sessionId);
|
|
2920
|
+
const errors = result?.errors ?? [];
|
|
2921
|
+
setSelected(new Set());
|
|
2922
|
+
if (errors.length > 0) return errors[0].message;
|
|
2923
|
+
if (done.length === 0) return '';
|
|
2924
|
+
setToast({
|
|
2925
|
+
text: t('movedToTrash').replace('{n}', String(done.length)),
|
|
2926
|
+
undoValue: { kind: 'restore', ids: done },
|
|
2927
|
+
});
|
|
2896
2928
|
return '';
|
|
2897
|
-
}
|
|
2898
|
-
if (done.length === 0) return '';
|
|
2899
|
-
setToast({
|
|
2900
|
-
text: t('movedToTrash').replace('{n}', String(done.length)),
|
|
2901
|
-
undoValue: { kind: 'restore', ids: done },
|
|
2902
2929
|
});
|
|
2903
|
-
return
|
|
2930
|
+
return;
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
const runDelete = () =>
|
|
2934
|
+
run(async () => {
|
|
2935
|
+
const result = await bridge.api('deleteSessionsPermanently', { sessionIds: ids });
|
|
2936
|
+
const done = (result?.done ?? []).map((item) => item.sessionId);
|
|
2937
|
+
const errors = result?.errors ?? [];
|
|
2938
|
+
setSelected(new Set());
|
|
2939
|
+
if (errors.length > 0) {
|
|
2940
|
+
setToast({ text: errors[0].message });
|
|
2941
|
+
return '';
|
|
2942
|
+
}
|
|
2943
|
+
if (done.length === 0) return '';
|
|
2944
|
+
return t('deletedMsg').replace('{n}', String(done.length));
|
|
2945
|
+
});
|
|
2946
|
+
if (!settings.confirmPurge) {
|
|
2947
|
+
void runDelete();
|
|
2948
|
+
return;
|
|
2949
|
+
}
|
|
2950
|
+
setConfirm({
|
|
2951
|
+
title: t('confirmDeleteTitle'),
|
|
2952
|
+
body: t('confirmDeleteBody')
|
|
2953
|
+
.replace('{n}', String(rows.length || ids.length))
|
|
2954
|
+
.replace('{size}', fmtBytes(size)),
|
|
2955
|
+
danger: true,
|
|
2956
|
+
onConfirm: async () => {
|
|
2957
|
+
setConfirm(null);
|
|
2958
|
+
await runDelete();
|
|
2959
|
+
},
|
|
2904
2960
|
});
|
|
2961
|
+
};
|
|
2905
2962
|
|
|
2906
2963
|
const archiveSessions = (ids) =>
|
|
2907
2964
|
run(async () => {
|
|
@@ -3374,16 +3431,16 @@ function MainPanel(props) {
|
|
|
3374
3431
|
),
|
|
3375
3432
|
React.createElement(
|
|
3376
3433
|
Tip,
|
|
3377
|
-
{ text: session.running ? t('runningHint') :
|
|
3434
|
+
{ text: session.running ? t('runningHint') : listDeleteHint },
|
|
3378
3435
|
React.createElement(
|
|
3379
3436
|
'button',
|
|
3380
3437
|
{
|
|
3381
3438
|
type: 'button',
|
|
3382
3439
|
className: 'ss-iconbtn',
|
|
3383
3440
|
disabled: busy || session.running,
|
|
3384
|
-
onClick: () =>
|
|
3441
|
+
onClick: () => deleteSessionsFromList([session.id]),
|
|
3385
3442
|
},
|
|
3386
|
-
|
|
3443
|
+
listDeleteLabel,
|
|
3387
3444
|
),
|
|
3388
3445
|
),
|
|
3389
3446
|
React.createElement(
|
|
@@ -3522,8 +3579,8 @@ function MainPanel(props) {
|
|
|
3522
3579
|
),
|
|
3523
3580
|
React.createElement(
|
|
3524
3581
|
Tip,
|
|
3525
|
-
{ text:
|
|
3526
|
-
React.createElement('button', { type: 'button', className: 'ss-btn tiny', disabled: busy, onClick: () =>
|
|
3582
|
+
{ text: listDeleteHint },
|
|
3583
|
+
React.createElement('button', { type: 'button', className: 'ss-btn tiny', disabled: busy, onClick: () => deleteSessionsFromList([...selected]) }, listDeleteLabel),
|
|
3527
3584
|
),
|
|
3528
3585
|
)
|
|
3529
3586
|
: React.createElement(
|
|
@@ -4222,12 +4279,12 @@ function MainPanel(props) {
|
|
|
4222
4279
|
const canTogglePlugin = (item) => Boolean(item && item.entryId && !item.readOnlyReason && !isSelfEntry(item));
|
|
4223
4280
|
|
|
4224
4281
|
const canUninstallPlugin = (item) => Boolean(
|
|
4225
|
-
item && item.bundle && item.removable === true && item
|
|
4282
|
+
item && item.bundle && item.removable === true && !isSelfEntry(item) && !SELF_BUNDLES.has(item.bundle),
|
|
4226
4283
|
);
|
|
4227
4284
|
|
|
4228
4285
|
const uninstallReason = (item) => {
|
|
4229
4286
|
if (!item) return t('uninstallLockedBuiltin');
|
|
4230
|
-
if (isSelfEntry(item) ||
|
|
4287
|
+
if (isSelfEntry(item) || SELF_BUNDLES.has(item.bundle)) return t('uninstallLockedSelf');
|
|
4231
4288
|
if (!item.bundle) return t('uninstallLockedNoBundle');
|
|
4232
4289
|
return t('uninstallLockedManaged');
|
|
4233
4290
|
};
|
|
@@ -4237,7 +4294,7 @@ function MainPanel(props) {
|
|
|
4237
4294
|
if (canUninstallPlugin(item)) return t('panelYes');
|
|
4238
4295
|
const short = !item
|
|
4239
4296
|
? t('uninstallLockedBuiltinShort')
|
|
4240
|
-
: isSelfEntry(item) ||
|
|
4297
|
+
: isSelfEntry(item) || SELF_BUNDLES.has(item.bundle)
|
|
4241
4298
|
? t('uninstallLockedSelfShort')
|
|
4242
4299
|
: !item.bundle
|
|
4243
4300
|
? t('uninstallLockedNoBundleShort')
|
|
@@ -5648,10 +5705,11 @@ function SettingsPage(props) {
|
|
|
5648
5705
|
return () => clearTimeout(timer);
|
|
5649
5706
|
}, [toast]);
|
|
5650
5707
|
|
|
5651
|
-
const settings = boot?.state?.settings ?? {
|
|
5708
|
+
const settings = boot?.state?.settings ?? { deleteMode: 'trash', confirmPurge: true };
|
|
5709
|
+
const deleteMode = settings.deleteMode === 'delete' ? 'delete' : 'trash';
|
|
5652
5710
|
const hidden = new Set(boot?.state?.hiddenPanels ?? []);
|
|
5653
5711
|
const paths = boot?.paths ?? {};
|
|
5654
|
-
const version = boot?.version ?? '0.1.
|
|
5712
|
+
const version = boot?.version ?? '0.1.5';
|
|
5655
5713
|
const trashCount = Array.isArray(boot?.trash) ? boot.trash.length : 0;
|
|
5656
5714
|
|
|
5657
5715
|
const call = async (work, message) => {
|
|
@@ -5672,7 +5730,6 @@ function SettingsPage(props) {
|
|
|
5672
5730
|
await bridge.api('saveSettings', { settings: patch });
|
|
5673
5731
|
}, t('settingsSaved'));
|
|
5674
5732
|
|
|
5675
|
-
const setDeleteMode = (mode) => saveSettings({ defaultDeleteMode: mode });
|
|
5676
5733
|
const setConfirmPurge = (value) => saveSettings({ confirmPurge: value });
|
|
5677
5734
|
|
|
5678
5735
|
const exportFormatOptions = [
|
|
@@ -5759,33 +5816,26 @@ function SettingsPage(props) {
|
|
|
5759
5816
|
null,
|
|
5760
5817
|
field(
|
|
5761
5818
|
t('defaultDeleteMode'),
|
|
5762
|
-
t(
|
|
5819
|
+
t('deleteModeHint'),
|
|
5763
5820
|
React.createElement(
|
|
5764
5821
|
'div',
|
|
5765
5822
|
{ className: 'ss-radios' },
|
|
5766
|
-
|
|
5767
|
-
'label',
|
|
5768
|
-
{
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5776
|
-
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
|
|
5781
|
-
|
|
5782
|
-
type: 'radio',
|
|
5783
|
-
name: 'ss-delete-mode',
|
|
5784
|
-
checked: settings.defaultDeleteMode === 'archive',
|
|
5785
|
-
disabled: busy,
|
|
5786
|
-
onChange: () => setDeleteMode('archive'),
|
|
5787
|
-
}),
|
|
5788
|
-
t('modeArchive'),
|
|
5823
|
+
[
|
|
5824
|
+
{ id: 'trash', label: t('modeTrash') },
|
|
5825
|
+
{ id: 'delete', label: t('modeDelete') },
|
|
5826
|
+
].map((option) =>
|
|
5827
|
+
React.createElement(
|
|
5828
|
+
'label',
|
|
5829
|
+
{ className: 'ss-radio', key: option.id },
|
|
5830
|
+
React.createElement('input', {
|
|
5831
|
+
type: 'radio',
|
|
5832
|
+
name: 'ss-delete-mode',
|
|
5833
|
+
checked: deleteMode === option.id,
|
|
5834
|
+
disabled: busy,
|
|
5835
|
+
onChange: () => saveSettings({ deleteMode: option.id }),
|
|
5836
|
+
}),
|
|
5837
|
+
option.label,
|
|
5838
|
+
),
|
|
5789
5839
|
),
|
|
5790
5840
|
),
|
|
5791
5841
|
),
|
package/index.js
CHANGED
|
@@ -28,12 +28,14 @@ export const inject = [
|
|
|
28
28
|
const NS = 'dsh-keeper';
|
|
29
29
|
const PANEL_ID = 'dsh-keeper';
|
|
30
30
|
const API_PATH = '/dsh-keeper/api';
|
|
31
|
-
const PLUGIN_VERSION = '0.1.
|
|
31
|
+
const PLUGIN_VERSION = '0.1.5';
|
|
32
32
|
const META_NAME = '.dsh-keeper-trash.json';
|
|
33
33
|
/** Pre-rename identifiers. Kept only so existing installs migrate in place. */
|
|
34
34
|
const LEGACY_NS = 'sidebar-studio';
|
|
35
35
|
const LEGACY_META_NAME = '.sidebar-studio-trash.json';
|
|
36
36
|
const LEGACY_BUNDLE = 'dsh-sidebar-studio';
|
|
37
|
+
/** Bundle names the keeper may be installed under; every self-protection check must recognize all of them. */
|
|
38
|
+
const SELF_BUNDLES = new Set(['dsh-keeper', 'dsh-keeper-plugin', LEGACY_BUNDLE]);
|
|
37
39
|
|
|
38
40
|
function isSelfEntryId(value) {
|
|
39
41
|
return typeof value === 'string' && (value.indexOf('dsh-keeper') !== -1 || value.indexOf(LEGACY_BUNDLE) !== -1);
|
|
@@ -63,7 +65,7 @@ const NOTIFY_DEFAULTS = {
|
|
|
63
65
|
};
|
|
64
66
|
|
|
65
67
|
const DEFAULT_SETTINGS = {
|
|
66
|
-
|
|
68
|
+
deleteMode: 'trash',
|
|
67
69
|
confirmPurge: true,
|
|
68
70
|
defaultExportFormat: 'md',
|
|
69
71
|
notifications: { ...NOTIFY_DEFAULTS },
|
|
@@ -342,7 +344,7 @@ function readState() {
|
|
|
342
344
|
version: 1,
|
|
343
345
|
hiddenPanels: [...new Set(hidden)],
|
|
344
346
|
settings: {
|
|
345
|
-
|
|
347
|
+
deleteMode: settings.deleteMode === 'delete' ? 'delete' : 'trash',
|
|
346
348
|
confirmPurge: settings.confirmPurge !== false,
|
|
347
349
|
defaultExportFormat: normalizeExportFormat(settings.defaultExportFormat),
|
|
348
350
|
notifications: normalizeNotificationSettings(settings.notifications),
|
|
@@ -356,7 +358,7 @@ function writeState(state) {
|
|
|
356
358
|
version: 1,
|
|
357
359
|
hiddenPanels: [...new Set(state.hiddenPanels ?? [])],
|
|
358
360
|
settings: {
|
|
359
|
-
|
|
361
|
+
deleteMode: state.settings?.deleteMode === 'delete' ? 'delete' : 'trash',
|
|
360
362
|
confirmPurge: state.settings?.confirmPurge !== false,
|
|
361
363
|
defaultExportFormat: normalizeExportFormat(state.settings?.defaultExportFormat),
|
|
362
364
|
notifications: normalizeNotificationSettings(state.settings?.notifications),
|
|
@@ -869,7 +871,7 @@ async function uninstallPlugin(ctx, payload) {
|
|
|
869
871
|
const name = typeof payload?.bundle === 'string' ? payload.bundle.trim() : '';
|
|
870
872
|
if (!name) throw fail('BAD_BUNDLE', '缺少插件包名。');
|
|
871
873
|
if (payload?.confirm !== true) throw fail('CONFIRM_REQUIRED', '卸载操作需要二次确认。');
|
|
872
|
-
if (name
|
|
874
|
+
if (SELF_BUNDLES.has(name)) throw fail('PROTECTED', '不能卸载 DSH 管家自身。');
|
|
873
875
|
let bundle = null;
|
|
874
876
|
try {
|
|
875
877
|
const bundles = await manager.listBundles();
|
|
@@ -1235,11 +1237,171 @@ async function purgeSessions(ctx, payload) {
|
|
|
1235
1237
|
} catch {
|
|
1236
1238
|
/* ignore */
|
|
1237
1239
|
}
|
|
1240
|
+
await forgetSessionProjection(ctx, id);
|
|
1241
|
+
await cleanSessionSpill(ctx, id);
|
|
1242
|
+
emitSessionRemoved(ctx, id);
|
|
1238
1243
|
done.push({ sessionId: id });
|
|
1239
1244
|
}
|
|
1240
1245
|
return { done, errors };
|
|
1241
1246
|
}
|
|
1242
1247
|
|
|
1248
|
+
/* ------------------------------------------------------ permanent delete */
|
|
1249
|
+
|
|
1250
|
+
function sessionService(ctx) {
|
|
1251
|
+
try {
|
|
1252
|
+
if (ctx && typeof ctx.get === 'function') {
|
|
1253
|
+
const service = ctx.get('sessions');
|
|
1254
|
+
if (service !== undefined) return service;
|
|
1255
|
+
}
|
|
1256
|
+
} catch {
|
|
1257
|
+
/* service lookup is best effort */
|
|
1258
|
+
}
|
|
1259
|
+
try {
|
|
1260
|
+
return ctx ? ctx.sessions : undefined;
|
|
1261
|
+
} catch {
|
|
1262
|
+
return undefined;
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function insideDirectory(root, target) {
|
|
1267
|
+
const base = path.resolve(root);
|
|
1268
|
+
const resolved = path.resolve(target);
|
|
1269
|
+
return resolved === base || resolved.startsWith(base + path.sep);
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
async function forgetSessionProjection(ctx, sessionId) {
|
|
1273
|
+
try {
|
|
1274
|
+
if (!ctx || typeof ctx.get !== 'function') return;
|
|
1275
|
+
const cache = ctx.get('sessionProjectionCache');
|
|
1276
|
+
if (cache && typeof cache.requireTable === 'function') {
|
|
1277
|
+
await cache.requireTable().delete(sessionId);
|
|
1278
|
+
}
|
|
1279
|
+
} catch {
|
|
1280
|
+
/* projection cache cleanup is best effort */
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
async function cleanSessionSpill(ctx, sessionId) {
|
|
1285
|
+
try {
|
|
1286
|
+
if (!ctx || typeof ctx.get !== 'function') return;
|
|
1287
|
+
const store = ctx.get('spillStore');
|
|
1288
|
+
const root = store && typeof store.root === 'string' ? store.root : '';
|
|
1289
|
+
if (!root) return;
|
|
1290
|
+
const target = path.join(root, sessionId);
|
|
1291
|
+
if (!insideDirectory(root, target) || !fs.existsSync(target)) return;
|
|
1292
|
+
fs.rmSync(target, { recursive: true, force: true });
|
|
1293
|
+
} catch {
|
|
1294
|
+
/* spill cleanup is best effort */
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
function removeSessionTranscriptDir(dir) {
|
|
1299
|
+
if (!insideDirectory(sessionsRoot(), dir)) {
|
|
1300
|
+
throw fail('BAD_SESSION_DIR', '会话目录不在 sessions 根目录下,拒绝删除。');
|
|
1301
|
+
}
|
|
1302
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
async function subagentDescendantIds(ctx, parentId) {
|
|
1306
|
+
const ids = [];
|
|
1307
|
+
try {
|
|
1308
|
+
const snapshots = await ctx.sessionPersistence.list();
|
|
1309
|
+
for (const snapshot of snapshots) {
|
|
1310
|
+
const header = snapshot && snapshot.header;
|
|
1311
|
+
if (!header || typeof header.id !== 'string' || header.id === parentId) continue;
|
|
1312
|
+
if (header.origin === 'subagent' && header.parentSession === parentId) ids.push(header.id);
|
|
1313
|
+
}
|
|
1314
|
+
} catch {
|
|
1315
|
+
/* descendant lookup is best effort */
|
|
1316
|
+
}
|
|
1317
|
+
return ids;
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function emitSessionRemoved(ctx, sessionId) {
|
|
1321
|
+
try {
|
|
1322
|
+
if (ctx && typeof ctx.emit === 'function') ctx.emit('api-session/removed', sessionId);
|
|
1323
|
+
} catch {
|
|
1324
|
+
/* listeners are best effort */
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
|
|
1328
|
+
async function detachLiveSession(ctx, sessionId) {
|
|
1329
|
+
const sessions = sessionService(ctx);
|
|
1330
|
+
if (!sessions || typeof sessions.get !== 'function') return;
|
|
1331
|
+
let live;
|
|
1332
|
+
try {
|
|
1333
|
+
live = sessions.get(sessionId);
|
|
1334
|
+
} catch {
|
|
1335
|
+
live = undefined;
|
|
1336
|
+
}
|
|
1337
|
+
if (!live) return;
|
|
1338
|
+
try {
|
|
1339
|
+
if (typeof sessions.flush === 'function') await sessions.flush(live);
|
|
1340
|
+
} catch {
|
|
1341
|
+
/* flush is best effort */
|
|
1342
|
+
}
|
|
1343
|
+
try {
|
|
1344
|
+
if (typeof sessions.liveEntryFor === 'function' && typeof sessions.detachEntered === 'function') {
|
|
1345
|
+
await sessions.detachEntered(sessions.liveEntryFor(live));
|
|
1346
|
+
}
|
|
1347
|
+
} catch {
|
|
1348
|
+
/* detach is best effort */
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
async function deleteSessionsPermanently(ctx, payload) {
|
|
1353
|
+
const sessionIds = Array.isArray(payload?.sessionIds) ? payload.sessionIds : [];
|
|
1354
|
+
if (sessionIds.length === 0) throw fail('BAD_REQUEST', '没有选择会话。');
|
|
1355
|
+
if (sessionIds.length > 100) throw fail('BAD_REQUEST', '一次最多处理 100 个会话。');
|
|
1356
|
+
const running = await runningSet(ctx);
|
|
1357
|
+
const done = [];
|
|
1358
|
+
const errors = [];
|
|
1359
|
+
const pending = [...sessionIds];
|
|
1360
|
+
const seen = new Set();
|
|
1361
|
+
while (pending.length > 0) {
|
|
1362
|
+
const rawId = pending.shift();
|
|
1363
|
+
let id;
|
|
1364
|
+
try {
|
|
1365
|
+
id = assertSessionId(rawId);
|
|
1366
|
+
} catch (error) {
|
|
1367
|
+
errors.push({ sessionId: String(rawId), code: error.code ?? 'BAD_SESSION_ID', message: error.message });
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1370
|
+
if (seen.has(id)) continue;
|
|
1371
|
+
seen.add(id);
|
|
1372
|
+
if (running.has(id)) {
|
|
1373
|
+
errors.push({ sessionId: id, code: 'SESSION_RUNNING', message: '会话正在运行,无法删除。' });
|
|
1374
|
+
continue;
|
|
1375
|
+
}
|
|
1376
|
+
try {
|
|
1377
|
+
const found = listSessionDirs().find((entry) => entry.id === id);
|
|
1378
|
+
await detachLiveSession(ctx, id);
|
|
1379
|
+
await detachSession(ctx, id);
|
|
1380
|
+
await forgetSessionProjection(ctx, id);
|
|
1381
|
+
await cleanSessionSpill(ctx, id);
|
|
1382
|
+
try {
|
|
1383
|
+
await ctx.workspaceRegistry.unarchiveSession(id);
|
|
1384
|
+
} catch {
|
|
1385
|
+
/* stale archive flag is harmless */
|
|
1386
|
+
}
|
|
1387
|
+
try {
|
|
1388
|
+
await ctx.workspaceRegistry.unpinSession(id);
|
|
1389
|
+
} catch {
|
|
1390
|
+
/* stale pin flag is harmless */
|
|
1391
|
+
}
|
|
1392
|
+
if (found) removeSessionTranscriptDir(found.dir);
|
|
1393
|
+
emitSessionRemoved(ctx, id);
|
|
1394
|
+
done.push({ sessionId: id, mode: 'delete' });
|
|
1395
|
+
for (const childId of await subagentDescendantIds(ctx, id)) {
|
|
1396
|
+
if (!seen.has(childId) && !running.has(childId)) pending.push(childId);
|
|
1397
|
+
}
|
|
1398
|
+
} catch (error) {
|
|
1399
|
+
errors.push({ sessionId: id, code: error.code ?? 'DELETE_FAILED', message: error?.message ?? '删除失败' });
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
return { done, errors };
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1243
1405
|
/* --------------------------------------------------------------- export */
|
|
1244
1406
|
|
|
1245
1407
|
const EXPORT_FORMATS = ['jsonl', 'md', 'txt', 'html', 'zstd'];
|
|
@@ -2510,6 +2672,7 @@ function createApi(ctx) {
|
|
|
2510
2672
|
return {
|
|
2511
2673
|
bootstrap: () => buildBootstrap(ctx),
|
|
2512
2674
|
deleteSessions: (payload) => deleteSessions(ctx, payload),
|
|
2675
|
+
deleteSessionsPermanently: (payload) => deleteSessionsPermanently(ctx, payload),
|
|
2513
2676
|
restoreSessions: (payload) => restoreSessions(ctx, payload),
|
|
2514
2677
|
purgeSessions: (payload) => purgeSessions(ctx, payload),
|
|
2515
2678
|
archiveSessions: (payload) => deleteSessions(ctx, { ...payload, mode: 'archive' }),
|
|
@@ -2576,8 +2739,8 @@ function createApi(ctx) {
|
|
|
2576
2739
|
const patch = payload?.settings;
|
|
2577
2740
|
if (!patch || typeof patch !== 'object') throw fail('BAD_REQUEST', '缺少设置内容。');
|
|
2578
2741
|
const state = readState();
|
|
2579
|
-
if (patch.
|
|
2580
|
-
state.settings.
|
|
2742
|
+
if (patch.deleteMode === 'trash' || patch.deleteMode === 'delete') {
|
|
2743
|
+
state.settings.deleteMode = patch.deleteMode;
|
|
2581
2744
|
}
|
|
2582
2745
|
if (typeof patch.confirmPurge === 'boolean') state.settings.confirmPurge = patch.confirmPurge;
|
|
2583
2746
|
if (EXPORT_FORMATS.includes(patch.defaultExportFormat)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-keeper-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "DSH Keeper — manage DSH workspace sessions, plugins, sidebar entries, and notifications in one place. DSH 管家:集中管理 DSH 的会话、插件、侧栏入口与通知。",
|
|
5
5
|
"icon": "icon.svg",
|
|
6
6
|
"type": "module",
|