dsh-session-ops 0.2.6 → 0.2.7

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.zh.md CHANGED
@@ -28,7 +28,7 @@ dsh plugin --profile <profile> add dsh-session-ops
28
28
  - `<DSH_HOME>/storages/session_projcache/sessions/<session-id>.json`:投影缓存
29
29
  - `<DSH_HOME>/rewind-snapshots/<session-id>/`:回退快照(若有)
30
30
 
31
- 删除后顺手清理因此变空的项目目录。没有回收站,删了无法恢复;删除前请自行备份 `$DSH_HOME`。面板提供预演与二次确认,但最终责任在操作者。
31
+ 删除后顺手清理因此变空的项目目录。没有回收站,删了无法恢复;删除前请自行备份 `$DSH_HOME`。面板提供预演与确认卡片(输入「删除」才能继续),但最终责任在操作者。
32
32
 
33
33
  默认安全边界(可在配置里改):`allowWorkspaceSessions=false`、`allowLiveSessions=false`、`refuseRunning=true`。工作区会话、正在跑的会话、运行中的搬迁默认都被拒绝。
34
34
 
@@ -56,7 +56,7 @@ DSH 0.2.2-rc.3 起,会话标题栏的「会话面板」里会出现本插件
56
56
  | `root` | `''` | 会话根目录;空则取 `sessionPersistence.root`(jsonl 后端为 `$DSH_HOME/sessions`) |
57
57
  | `adminAllowHosts` | `[]` | 删除半边的 LAN 信任列表(按 `Host` 头解析 `host` 或 `host:port`) |
58
58
  | `moveAllowHosts` | `[]` | 搬迁半边的 LAN 信任列表(按 `Host` 头完整值精确匹配) |
59
- | `headerDeleteButton` | `true` | 会话标题栏垃圾桶图标(图标 + 两步确认) |
59
+ | `headerDeleteButton` | `true` | 会话标题栏垃圾桶图标(图标 + 输入确认词的确认卡片) |
60
60
  | `allowWorkspaceSessions` | `false` | 允许删除已归属工作区的会话 |
61
61
  | `allowLiveSessions` | `false` | 允许删除宿主里驻留的会话 |
62
62
  | `maxBatch` | `200` | 单次批量删除上限 |
package/lib/client.js CHANGED
@@ -22,7 +22,7 @@
22
22
  * 与 `dsh-session-move:panel`(+`…:panel-via-better-sidebar`),标题分别是
23
23
  * 「会话管理」「会话归位」,角标语义不变(删除半边:未分组条数;搬迁半边:无);
24
24
  * - 会话标题栏垃圾桶的 id `dsh-session-admin:delete-current`(仍然是**图标**,
25
- * 开关由 Host 的 `headerDeleteButton` 决定,默认开启,删除要两步确认);
25
+ * 开关由 Host 的 `headerDeleteButton` 决定,默认开启,删除要在卡片里输入确认词);
26
26
  * - 数据面仍然只打各自的前缀:`/session-admin/api` 与 `/session-move/api`。
27
27
  *
28
28
  * ## 统一右键菜单(DSH 0.2.2-rc.1 起)
@@ -33,7 +33,7 @@
33
33
  * - 「移动会话到工作区…」(搬迁半边,order 500):菜单里只判断能不能搬并写出理由,
34
34
  * 点下去时重新读一次 Host 状态,然后打开既有右栏「会话归位」面板并选中这条会话;
35
35
  * - 「删除会话…」(删除半边,order 620,`afterContent` 与原生「归档」同区):与标题栏
36
- * 垃圾桶**共用** `deleteSessionFlow`(预演 → 二次确认 → 删除),`run` 里会再预演
36
+ * 垃圾桶**共用** `deleteSessionFlow`(预演 → 输入确认词 → 删除),`run` 里会再预演
37
37
  * 一次,所以菜单打开到点下去之间状态变了也不会绕过守卫。
38
38
  *
39
39
  * 两项的图标注册在 `contextMenu.icon` 的 keyed slot 上;没有 `contextMenus` 服务
@@ -144,26 +144,147 @@
144
144
  }
145
145
  return `${value.toFixed(unit === 0 ? 0 : 1)} ${units[unit]}`;
146
146
  }
147
+ /** 同一时刻只留一张确认卡片;重入按取消处理,不叠第二张。 */
148
+ let confirmDeletionOpen = false;
147
149
  /**
148
- * 删除的二次确认。
150
+ * 删除确认:画在页面里的确认卡片,`Promise<boolean>`。
149
151
  *
150
- * 两步,且第二步必须**动手输入**:
151
- * 1. `confirm` 说明到底要删什么(条数、体积、会话 id);
152
- * 2. `prompt` 要求输入确认词。
152
+ * **不能用 `window.prompt` / `window.confirm`**:DSH Desktop 跑在 Electron 里,
153
+ * `window.prompt` 直接抛 `prompt() is not supported.`(0.2.3-alpha.3 实测),旧实现
154
+ * 因此永远卡在「输入确认词」那一步,界面上只剩一句
155
+ * `删除失败:prompt() is not supported.`——功能看起来像坏了,其实一次都没删过。
156
+ * 卡片挂在 `document.body` 上,不依赖宿主对话框,桌面端与浏览器行为一致。
153
157
  *
154
- * 只弹一个 confirm 不够——那个对话框可以被回车或连点顺手确认掉,而这正是上次
155
- * 「防止误删」担心的事。输入确认词要求的是一次有意的动作,手滑触发不了。
156
- * @param summary - 这次删除的对象描述。
158
+ * 防误删的口径没降:确认按钮在输入框里打出「删除」之前一直禁用——要求一次有意的
159
+ * 动作,回车或连点顺手确认不掉。
160
+ * @param summary - 这次删除的对象描述(条数、体积或会话 id)。
157
161
  * @returns 用户是否确认删除。
158
162
  */
159
163
  function confirmDeletion(summary) {
160
- if (!window.confirm(`${summary}\n\n这会移除会话日志、投影缓存与回退快照,没有撤销、没有回收站。继续?`)) {
161
- return false;
162
- }
163
- const typed = window.prompt(`最后一步:输入「删除」以确认\n\n${summary}`, '');
164
- if (typed === null)
165
- return false;
166
- return typed.trim() === '删除';
164
+ if (confirmDeletionOpen)
165
+ return Promise.resolve(false);
166
+ confirmDeletionOpen = true;
167
+ return new Promise((resolve) => {
168
+ const overlay = document.createElement('div');
169
+ overlay.style.position = 'fixed';
170
+ overlay.style.inset = '0';
171
+ overlay.style.zIndex = '2147483000';
172
+ overlay.style.display = 'flex';
173
+ overlay.style.alignItems = 'center';
174
+ overlay.style.justifyContent = 'center';
175
+ overlay.style.padding = '24px';
176
+ overlay.style.background = 'rgba(0, 0, 0, 0.42)';
177
+ const card = document.createElement('div');
178
+ card.setAttribute('role', 'alertdialog');
179
+ card.setAttribute('aria-modal', 'true');
180
+ card.style.width = '100%';
181
+ card.style.maxWidth = '420px';
182
+ card.style.boxSizing = 'border-box';
183
+ card.style.display = 'flex';
184
+ card.style.flexDirection = 'column';
185
+ card.style.gap = '10px';
186
+ card.style.padding = '16px';
187
+ card.style.borderRadius = '12px';
188
+ card.style.border = '1px solid var(--dsw-alias-border-l2, var(--dsh-border, #d0d5dd))';
189
+ card.style.background = 'var(--dsw-alias-bg-overlay, var(--dsh-surface, #fff))';
190
+ card.style.color = 'inherit';
191
+ card.style.boxShadow = '0 12px 32px rgba(0, 0, 0, 0.28)';
192
+ const what = document.createElement('div');
193
+ what.style.fontSize = '13px';
194
+ what.style.lineHeight = '1.55';
195
+ what.textContent = summary;
196
+ const note = document.createElement('div');
197
+ note.style.fontSize = '12px';
198
+ note.style.lineHeight = '1.5';
199
+ note.style.color = 'var(--dsw-alias-label-secondary, rgba(128, 128, 128, 0.95))';
200
+ note.textContent = '会话日志、投影缓存与回退快照一并移除,无法撤销。';
201
+ const input = document.createElement('input');
202
+ input.type = 'text';
203
+ input.autocomplete = 'off';
204
+ input.placeholder = '输入「删除」以确认';
205
+ input.style.padding = '6px 9px';
206
+ input.style.fontSize = '12.5px';
207
+ input.style.borderRadius = '8px';
208
+ input.style.border = '1px solid var(--dsw-alias-border-l2, var(--dsh-border, #d0d5dd))';
209
+ input.style.background = 'transparent';
210
+ input.style.color = 'inherit';
211
+ const bar = document.createElement('div');
212
+ bar.style.display = 'flex';
213
+ bar.style.gap = '8px';
214
+ bar.style.justifyContent = 'flex-end';
215
+ const dismiss = document.createElement('button');
216
+ dismiss.type = 'button';
217
+ dismiss.textContent = '取消';
218
+ dismiss.style.cssText =
219
+ 'padding:5px 12px;font-size:12.5px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2, #d0d5dd);background:transparent;color:inherit;cursor:pointer';
220
+ const accept = document.createElement('button');
221
+ accept.type = 'button';
222
+ accept.textContent = '删除';
223
+ accept.style.cssText =
224
+ 'padding:5px 12px;font-size:12.5px;border-radius:8px;border:1px solid transparent;background:var(--dsw-alias-state-error-primary, #d92d20);color:#fff';
225
+ /** 输入框内容 → 确认按钮可用性(唯一判据:整串等于「删除」)。 */
226
+ function syncAccept() {
227
+ const ready = input.value.trim() === '删除';
228
+ accept.disabled = !ready;
229
+ accept.style.opacity = ready ? '1' : '0.45';
230
+ accept.style.cursor = ready ? 'pointer' : 'default';
231
+ }
232
+ let settled = false;
233
+ function finish(confirmed) {
234
+ if (settled)
235
+ return;
236
+ settled = true;
237
+ confirmDeletionOpen = false;
238
+ input.removeEventListener('input', syncAccept);
239
+ input.removeEventListener('keydown', onKey);
240
+ dismiss.removeEventListener('click', onDismiss);
241
+ accept.removeEventListener('click', onAccept);
242
+ overlay.removeEventListener('mousedown', onBackdrop);
243
+ if (overlay.parentNode !== null)
244
+ overlay.parentNode.removeChild(overlay);
245
+ resolve(confirmed);
246
+ }
247
+ function onDismiss() {
248
+ finish(false);
249
+ }
250
+ function onAccept() {
251
+ if (accept.disabled !== true)
252
+ finish(true);
253
+ }
254
+ function onBackdrop(event) {
255
+ if (event.target === overlay)
256
+ finish(false);
257
+ }
258
+ function onKey(event) {
259
+ if (event.key === 'Escape') {
260
+ if (typeof event.preventDefault === 'function')
261
+ event.preventDefault();
262
+ finish(false);
263
+ return;
264
+ }
265
+ if (event.key === 'Enter' && input.value.trim() === '删除') {
266
+ if (typeof event.preventDefault === 'function')
267
+ event.preventDefault();
268
+ finish(true);
269
+ }
270
+ }
271
+ input.addEventListener('input', syncAccept);
272
+ input.addEventListener('keydown', onKey);
273
+ dismiss.addEventListener('click', onDismiss);
274
+ accept.addEventListener('click', onAccept);
275
+ overlay.addEventListener('mousedown', onBackdrop);
276
+ card.appendChild(what);
277
+ card.appendChild(note);
278
+ card.appendChild(input);
279
+ bar.appendChild(dismiss);
280
+ bar.appendChild(accept);
281
+ card.appendChild(bar);
282
+ overlay.appendChild(card);
283
+ syncAccept();
284
+ document.body.appendChild(overlay);
285
+ if (typeof input.focus === 'function')
286
+ input.focus();
287
+ });
167
288
  }
168
289
  /** 时间戳 → `MM-DD HH:mm`。 */
169
290
  function stamp(ms) {
@@ -623,7 +744,7 @@
623
744
  return;
624
745
  const bytes = rows.filter((r) => selected.has(r.id)).reduce((sum, r) => sum + (r.bytes ?? 0), 0);
625
746
  if (dryRun !== true) {
626
- if (!confirmDeletion(`将永久删除 ${ids.length} 个会话(约 ${human(bytes)})。`))
747
+ if (!(await confirmDeletion(`将永久删除 ${ids.length} 个会话(约 ${human(bytes)})。`)))
627
748
  return;
628
749
  }
629
750
  setBusy(true);
@@ -695,7 +816,7 @@
695
816
  ? h('div', { style: { marginTop: 6 } }, h('div', { style: S.muted }, `未处理 ${refusalRows.length} 条:`), refusalRows.slice(0, 12).map((row) => h('div', { key: row.id, style: S.muted }, `${row.id} — ${REASONS[row.reason] ?? row.reason}`)), refusalRows.length > 12 ? h('div', { style: S.muted }, `…以及另外 ${refusalRows.length - 12} 条`) : null)
696
817
  : null);
697
818
  // 待删除队列:条目、状态、撤销、立即重试。
698
- return h('div', { style: fill ? { ...S.root, ...S_FILL.root } : S.root }, h('div', { style: S.muted }, 'DSH 只能「归档」(隐藏)会话;这里做的是把会话的持久化数据真正从磁盘移除。删除需要二次确认,不可恢复。'), head, pathBar, toolbar, failure !== undefined ? h('div', { style: S.error }, `失败:${failure}`) : null, list, resultBox);
819
+ return h('div', { style: fill ? { ...S.root, ...S_FILL.root } : S.root }, h('div', { style: S.muted }, 'DSH 只能「归档」(隐藏)会话;这里做的是把会话的持久化数据真正从磁盘移除。删除要在确认卡片里输入「删除」,不可恢复。'), head, pathBar, toolbar, failure !== undefined ? h('div', { style: S.error }, `失败:${failure}`) : null, list, resultBox);
699
820
  };
700
821
  }
701
822
  /** 右侧页签的标题条。 */
@@ -777,7 +898,7 @@
777
898
  }
778
899
  }
779
900
  /**
780
- * 删除一个会话的整条流程:预演 → 二次确认 → 删除。
901
+ * 删除一个会话的整条流程:预演 → 输入确认词 → 删除。
781
902
  *
782
903
  * 标题栏垃圾桶与右键菜单共用这一段:两处删的是同一个东西,只是入口不同,守卫与
783
904
  * 确认必须逐字一致,否则「从菜单删」就等于绕开「从图标删」的那些检查。
@@ -804,7 +925,7 @@
804
925
  if (probe.removed === 0) {
805
926
  return { ok: false, note: REASONS[entry?.reason] ?? entry?.reason ?? '无法删除' };
806
927
  }
807
- if (!confirmDeletion(`永久删除会话 ${sessionId}?`))
928
+ if (!(await confirmDeletion(`永久删除会话 ${sessionId}?`)))
808
929
  return { ok: false };
809
930
  const value = await api.call('delete', target);
810
931
  const outcome = value.results[0];
@@ -816,7 +937,7 @@
816
937
  /**
817
938
  * 会话标题栏的垃圾桶图标:删除当前会话。
818
939
  *
819
- * 形态是「图标 + 二次确认」而不是带字面标签的按钮:标签会招来点击,而这里删的
940
+ * 形态是「图标 + 确认卡片」而不是带字面标签的按钮:标签会招来点击,而这里删的
820
941
  * 正是你正在用的会话。图标不占字面位置,误点最多弹出一个确认框。
821
942
  */
822
943
  function createHeaderButton(React, ctx, api) {
@@ -969,7 +1090,7 @@
969
1090
  key: 'headerDeleteButton',
970
1091
  kind: 'boolean',
971
1092
  label: '标题栏删除图标',
972
- hint: '在会话标题栏显示垃圾桶图标(默认开启)。它是图标而不是按钮,且删除要两步确认。改完刷新页面生效。',
1093
+ hint: '在会话标题栏显示垃圾桶图标(默认开启)。它是图标而不是按钮,且删除要在卡片里输入确认词。改完刷新页面生效。',
973
1094
  },
974
1095
  {
975
1096
  key: 'allowLiveSessions',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-session-ops",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"