dsh-session-ops 0.2.8 → 0.2.10
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 +2 -3
- package/README.zh.md +3 -3
- package/cordis.patch.yml +1 -0
- package/lib/admin.js +15 -3
- package/lib/client.js +80 -57
- package/lib/engine.js +10 -1
- package/lib/move.js +48 -24
- package/lib/store/frames.js +26 -5
- package/lib/store/registry.js +9 -6
- package/lib/types/store/registry.d.ts +1 -0
- package/package.json +4 -5
package/README.md
CHANGED
|
@@ -33,8 +33,7 @@ The plugin row is declared in the bundled `cordis.patch.yml`; its entry id is `s
|
|
|
33
33
|
- `<DSH_HOME>/rewind-snapshots/<session-id>/` (rewind snapshots, if present)
|
|
34
34
|
|
|
35
35
|
All three are removed from disk, and project directories left empty are cleaned up. **There is no
|
|
36
|
-
trash and no undo.** Back up `$DSH_HOME` yourself; the panel provides a dry run and
|
|
37
|
-
confirmation card, but the operator owns the outcome.
|
|
36
|
+
trash and no undo.** Back up `$DSH_HOME` yourself; the panel provides a dry run and a one-click confirmation card, but the operator owns the outcome.
|
|
38
37
|
|
|
39
38
|
The context-menu row resolves through a **single-session probe** (`/session-admin/api/probe`): a
|
|
40
39
|
menu `resolve` gets a 1 s budget (`resolutionTimeoutMs`, and a timed-out provider is dropped), while
|
|
@@ -42,7 +41,7 @@ a table-wide dry run measures every session directory (≈3.6 s for 391 sessions
|
|
|
42
41
|
used to appear only sometimes. The probe skips byte measurement and shares the exact guard chain
|
|
43
42
|
with `delete`; it only decides whether the row is enabled, and `delete` re-checks every guard. The
|
|
44
43
|
confirmation card is drawn in the page (never `window.confirm` / `window.prompt`: Electron throws
|
|
45
|
-
`prompt() is not supported.`)
|
|
44
|
+
`prompt() is not supported.`) and deliberately asks for a single click — no typed confirmation word.
|
|
46
45
|
|
|
47
46
|
Safe defaults (configurable): `allowWorkspaceSessions=false`, `allowLiveSessions=false`,
|
|
48
47
|
`refuseRunning=true` — workspace sessions, live sessions and mid-turn moves are refused by default.
|
package/README.zh.md
CHANGED
|
@@ -28,9 +28,9 @@ 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
|
-
右键菜单的「删除会话…」用**单条预演**(`/session-admin/api/probe`)决定能不能点:菜单的 `resolve` 只有 1 s 预算(`resolutionTimeoutMs`,超时整项被丢弃),而整表 dryRun 要把每个会话目录的体积都走一遍(本机 391 条约 3.6 s),结果就是这一项在菜单里时有时无。`probe` 只做无体积统计的扫描 + 与 `delete` **同一份**守卫判定,毫秒级返回 `{removable, reason}`;它只管菜单显示,真删时 `delete` 会重新过一遍守卫。确认卡片是页面里自己画的(不用 `window.confirm` / `window.prompt`——Electron 里 `window.prompt` 直接抛 `prompt() is not supported
|
|
33
|
+
右键菜单的「删除会话…」用**单条预演**(`/session-admin/api/probe`)决定能不能点:菜单的 `resolve` 只有 1 s 预算(`resolutionTimeoutMs`,超时整项被丢弃),而整表 dryRun 要把每个会话目录的体积都走一遍(本机 391 条约 3.6 s),结果就是这一项在菜单里时有时无。`probe` 只做无体积统计的扫描 + 与 `delete` **同一份**守卫判定,毫秒级返回 `{removable, reason}`;它只管菜单显示,真删时 `delete` 会重新过一遍守卫。确认卡片是页面里自己画的(不用 `window.confirm` / `window.prompt`——Electron 里 `window.prompt` 直接抛 `prompt() is not supported.`):卡片刻意只用一次点击,不要求输入确认词。
|
|
34
34
|
|
|
35
35
|
默认安全边界(可在配置里改):`allowWorkspaceSessions=false`、`allowLiveSessions=false`、`refuseRunning=true`。工作区会话、正在跑的会话、运行中的搬迁默认都被拒绝。
|
|
36
36
|
|
|
@@ -58,7 +58,7 @@ DSH 0.2.2-rc.3 起,会话标题栏的「会话面板」里会出现本插件
|
|
|
58
58
|
| `root` | `''` | 会话根目录;空则取 `sessionPersistence.root`(jsonl 后端为 `$DSH_HOME/sessions`) |
|
|
59
59
|
| `adminAllowHosts` | `[]` | 删除半边的 LAN 信任列表(按 `Host` 头解析 `host` 或 `host:port`) |
|
|
60
60
|
| `moveAllowHosts` | `[]` | 搬迁半边的 LAN 信任列表(按 `Host` 头完整值精确匹配) |
|
|
61
|
-
| `headerDeleteButton` | `true` | 会话标题栏垃圾桶图标(图标 +
|
|
61
|
+
| `headerDeleteButton` | `true` | 会话标题栏垃圾桶图标(图标 + 一次点击的确认卡片) |
|
|
62
62
|
| `allowWorkspaceSessions` | `false` | 允许删除已归属工作区的会话 |
|
|
63
63
|
| `allowLiveSessions` | `false` | 允许删除宿主里驻留的会话 |
|
|
64
64
|
| `maxBatch` | `200` | 单次批量删除上限 |
|
package/cordis.patch.yml
CHANGED
package/lib/admin.js
CHANGED
|
@@ -526,6 +526,11 @@ export function isTrustedRequest(req, allowHosts = []) {
|
|
|
526
526
|
const authority = parseAuthority(rawHost);
|
|
527
527
|
if (authority === undefined)
|
|
528
528
|
return false;
|
|
529
|
+
const remote = req.socket?.remoteAddress;
|
|
530
|
+
if (typeof remote === 'string' && remote.length > 0) {
|
|
531
|
+
if (!isLoopback(remote) && !isAllowedAuthority(authority, allowHosts))
|
|
532
|
+
return false;
|
|
533
|
+
}
|
|
529
534
|
if (!isLoopback(authority.hostname) && !isAllowedAuthority(authority, allowHosts))
|
|
530
535
|
return false;
|
|
531
536
|
if (req.headers?.['sec-fetch-site'] === 'cross-site')
|
|
@@ -535,7 +540,7 @@ export function isTrustedRequest(req, allowHosts = []) {
|
|
|
535
540
|
return true;
|
|
536
541
|
try {
|
|
537
542
|
// 头可能是数组(重复头);`URL` 的入参本来就是字符串,这里按原语义做一次 ToString。
|
|
538
|
-
return new URL(String(origin)).
|
|
543
|
+
return new URL(String(origin)).host.toLowerCase() === authority.host.toLowerCase();
|
|
539
544
|
}
|
|
540
545
|
catch {
|
|
541
546
|
return false;
|
|
@@ -829,11 +834,10 @@ function buildApi(admin, config, log, holds, health) {
|
|
|
829
834
|
},
|
|
830
835
|
/** 删除:先按范围解析出目标集合,再逐条过守卫。 */
|
|
831
836
|
async delete(payload) {
|
|
832
|
-
const records = admin.scan();
|
|
833
837
|
const explicit = Array.isArray(payload?.sessionIds) ? payload.sessionIds : null;
|
|
834
838
|
const targets = explicit !== null
|
|
835
839
|
? explicit
|
|
836
|
-
: admin.select(
|
|
840
|
+
: admin.select(admin.scan(), payload).map((record) => record.id);
|
|
837
841
|
if (targets.length === 0)
|
|
838
842
|
return { removed: 0, reclaimed: 0, results: [], pruned: [] };
|
|
839
843
|
const result = await admin.remove(targets, {
|
|
@@ -1029,6 +1033,13 @@ function buildTool(admin, config, log, holds, health) {
|
|
|
1029
1033
|
.join(' | ')}`,
|
|
1030
1034
|
};
|
|
1031
1035
|
}
|
|
1036
|
+
if (args.action !== 'delete') {
|
|
1037
|
+
return {
|
|
1038
|
+
ok: false,
|
|
1039
|
+
error: `Unsupported action: ${String(args.action ?? '')}`,
|
|
1040
|
+
summary: `Unsupported action "${String(args.action ?? '')}". Expected "list" or "delete".`,
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1032
1043
|
// `dryRun` 的语义是「绝不落盘」,优先级高于 `confirm`:`confirm=true` 只是
|
|
1033
1044
|
// 「允许真删」的前置条件,不能反过来把 dryRun 盖掉。2026-11-07 修:此前只在
|
|
1034
1045
|
// confirm !== true 时才走预演,confirm=true 时 dryRun 被静默忽略、直接真删。
|
|
@@ -1044,6 +1055,7 @@ function buildTool(admin, config, log, holds, health) {
|
|
|
1044
1055
|
includeWorkspace: args.includeWorkspace === true,
|
|
1045
1056
|
includeArchived: args.includeArchived === true,
|
|
1046
1057
|
includeSubagent: args.includeSubagent === true,
|
|
1058
|
+
callerSessionId,
|
|
1047
1059
|
};
|
|
1048
1060
|
const value = await api.delete(payload);
|
|
1049
1061
|
const rejections = value.results.filter((r) => r.status === 'skipped');
|
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`(预演 →
|
|
36
|
+
* 垃圾桶**共用** `deleteSessionFlow`(预演 → 确认卡片 → 删除),`run` 里会再预演
|
|
37
37
|
* 一次,所以菜单打开到点下去之间状态变了也不会绕过守卫。
|
|
38
38
|
*
|
|
39
39
|
* 两项的图标注册在 `contextMenu.icon` 的 keyed slot 上;没有 `contextMenus` 服务
|
|
@@ -155,8 +155,9 @@
|
|
|
155
155
|
* `删除失败:prompt() is not supported.`——功能看起来像坏了,其实一次都没删过。
|
|
156
156
|
* 卡片挂在 `document.body` 上,不依赖宿主对话框,桌面端与浏览器行为一致。
|
|
157
157
|
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
158
|
+
* 一步:说明删什么,点「删除」即可。「删除」是危险色按钮且排在最后,误点仍要
|
|
159
|
+
* 多走一步;Esc、取消、点遮罩都按取消处理。
|
|
160
|
+
*
|
|
160
161
|
* @param summary - 这次删除的对象描述(条数、体积或会话 id)。
|
|
161
162
|
* @returns 用户是否确认删除。
|
|
162
163
|
*/
|
|
@@ -178,7 +179,7 @@
|
|
|
178
179
|
card.setAttribute('role', 'alertdialog');
|
|
179
180
|
card.setAttribute('aria-modal', 'true');
|
|
180
181
|
card.style.width = '100%';
|
|
181
|
-
card.style.maxWidth = '
|
|
182
|
+
card.style.maxWidth = '400px';
|
|
182
183
|
card.style.boxSizing = 'border-box';
|
|
183
184
|
card.style.display = 'flex';
|
|
184
185
|
card.style.flexDirection = 'column';
|
|
@@ -198,16 +199,6 @@
|
|
|
198
199
|
note.style.lineHeight = '1.5';
|
|
199
200
|
note.style.color = 'var(--dsw-alias-label-secondary, rgba(128, 128, 128, 0.95))';
|
|
200
201
|
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
202
|
const bar = document.createElement('div');
|
|
212
203
|
bar.style.display = 'flex';
|
|
213
204
|
bar.style.gap = '8px';
|
|
@@ -221,25 +212,17 @@
|
|
|
221
212
|
accept.type = 'button';
|
|
222
213
|
accept.textContent = '删除';
|
|
223
214
|
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
|
-
}
|
|
215
|
+
'padding:5px 12px;font-size:12.5px;border-radius:8px;border:1px solid transparent;background:var(--dsw-alias-state-error-primary, #d92d20);color:#fff;cursor:pointer';
|
|
232
216
|
let settled = false;
|
|
233
217
|
function finish(confirmed) {
|
|
234
218
|
if (settled)
|
|
235
219
|
return;
|
|
236
220
|
settled = true;
|
|
237
221
|
confirmDeletionOpen = false;
|
|
238
|
-
input.removeEventListener('input', syncAccept);
|
|
239
|
-
input.removeEventListener('keydown', onKey);
|
|
240
222
|
dismiss.removeEventListener('click', onDismiss);
|
|
241
223
|
accept.removeEventListener('click', onAccept);
|
|
242
224
|
overlay.removeEventListener('mousedown', onBackdrop);
|
|
225
|
+
document.removeEventListener('keydown', onKey, true);
|
|
243
226
|
if (overlay.parentNode !== null)
|
|
244
227
|
overlay.parentNode.removeChild(overlay);
|
|
245
228
|
resolve(confirmed);
|
|
@@ -248,42 +231,35 @@
|
|
|
248
231
|
finish(false);
|
|
249
232
|
}
|
|
250
233
|
function onAccept() {
|
|
251
|
-
|
|
252
|
-
finish(true);
|
|
234
|
+
finish(true);
|
|
253
235
|
}
|
|
254
236
|
function onBackdrop(event) {
|
|
255
237
|
if (event.target === overlay)
|
|
256
238
|
finish(false);
|
|
257
239
|
}
|
|
258
240
|
function onKey(event) {
|
|
259
|
-
if (event.key
|
|
260
|
-
if (typeof event.preventDefault === 'function')
|
|
261
|
-
event.preventDefault();
|
|
262
|
-
finish(false);
|
|
241
|
+
if (event.key !== 'Escape')
|
|
263
242
|
return;
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
243
|
+
if (typeof event.preventDefault === 'function')
|
|
244
|
+
event.preventDefault();
|
|
245
|
+
if (typeof event.stopPropagation === 'function')
|
|
246
|
+
event.stopPropagation();
|
|
247
|
+
finish(false);
|
|
270
248
|
}
|
|
271
|
-
input.addEventListener('input', syncAccept);
|
|
272
|
-
input.addEventListener('keydown', onKey);
|
|
273
249
|
dismiss.addEventListener('click', onDismiss);
|
|
274
250
|
accept.addEventListener('click', onAccept);
|
|
275
251
|
overlay.addEventListener('mousedown', onBackdrop);
|
|
252
|
+
// Esc 兜底:捕获阶段监听,输入框有焦点时也收得到。
|
|
253
|
+
document.addEventListener('keydown', onKey, true);
|
|
276
254
|
card.appendChild(what);
|
|
277
255
|
card.appendChild(note);
|
|
278
|
-
card.appendChild(input);
|
|
279
256
|
bar.appendChild(dismiss);
|
|
280
257
|
bar.appendChild(accept);
|
|
281
258
|
card.appendChild(bar);
|
|
282
259
|
overlay.appendChild(card);
|
|
283
|
-
syncAccept();
|
|
284
260
|
document.body.appendChild(overlay);
|
|
285
|
-
if (typeof
|
|
286
|
-
|
|
261
|
+
if (typeof dismiss.focus === 'function')
|
|
262
|
+
dismiss.focus();
|
|
287
263
|
});
|
|
288
264
|
}
|
|
289
265
|
/** 时间戳 → `MM-DD HH:mm`。 */
|
|
@@ -563,14 +539,18 @@
|
|
|
563
539
|
}, [sessionId]);
|
|
564
540
|
const entry = health.entryOf(sessionId);
|
|
565
541
|
const [openState, setOpenState] = React.useState({ kind: 'idle', message: '' });
|
|
542
|
+
React.useEffect(() => {
|
|
543
|
+
setOpenState({ kind: 'idle', message: '' });
|
|
544
|
+
}, [sessionId]);
|
|
566
545
|
// 失败/读取中只给「重试」;有数据时给「打开目录」——刷新按钮对只读面板没有意义。
|
|
567
546
|
const retryButton = h('button', { type: 'button', style: S.button, onClick: () => void health.refresh(sessionId) }, '重试');
|
|
568
547
|
const openButton = h('button', {
|
|
569
548
|
type: 'button',
|
|
570
549
|
style: S.button,
|
|
571
550
|
onClick: () => {
|
|
551
|
+
const targetId = sessionId;
|
|
572
552
|
setOpenState({ kind: 'opening', message: '' });
|
|
573
|
-
void health.openDir(
|
|
553
|
+
void health.openDir(targetId).then((result) => {
|
|
574
554
|
if (result?.ok === true)
|
|
575
555
|
setOpenState({ kind: 'opened', message: '已在文件管理器中打开' });
|
|
576
556
|
else
|
|
@@ -639,8 +619,13 @@
|
|
|
639
619
|
refresh,
|
|
640
620
|
start() {
|
|
641
621
|
void refresh();
|
|
642
|
-
if (state.timer === undefined)
|
|
643
|
-
state.timer = setInterval(() =>
|
|
622
|
+
if (state.timer === undefined) {
|
|
623
|
+
state.timer = setInterval(() => {
|
|
624
|
+
if (typeof document !== 'undefined' && document.hidden)
|
|
625
|
+
return;
|
|
626
|
+
void refresh();
|
|
627
|
+
}, 120_000);
|
|
628
|
+
}
|
|
644
629
|
},
|
|
645
630
|
stop() {
|
|
646
631
|
if (state.timer !== undefined) {
|
|
@@ -703,7 +688,9 @@
|
|
|
703
688
|
const [failure, setFailure] = React.useState(undefined);
|
|
704
689
|
const [result, setResult] = React.useState(undefined);
|
|
705
690
|
const [showAll, setShowAll] = React.useState(false);
|
|
691
|
+
const loadSeqRef = React.useRef(0);
|
|
706
692
|
const load = React.useCallback(async () => {
|
|
693
|
+
const seq = ++loadSeqRef.current;
|
|
707
694
|
setBusy(true);
|
|
708
695
|
setFailure(undefined);
|
|
709
696
|
try {
|
|
@@ -713,19 +700,31 @@
|
|
|
713
700
|
cwdPrefix: cwdPrefix === '' ? undefined : cwdPrefix,
|
|
714
701
|
limit: 2000,
|
|
715
702
|
});
|
|
703
|
+
if (seq !== loadSeqRef.current)
|
|
704
|
+
return;
|
|
716
705
|
setData(value);
|
|
717
706
|
setSelected(new Set());
|
|
718
707
|
}
|
|
719
708
|
catch (error) {
|
|
709
|
+
if (seq !== loadSeqRef.current)
|
|
710
|
+
return;
|
|
720
711
|
setFailure(String(error?.message ?? error));
|
|
721
712
|
}
|
|
722
713
|
finally {
|
|
723
|
-
|
|
714
|
+
if (seq === loadSeqRef.current)
|
|
715
|
+
setBusy(false);
|
|
724
716
|
}
|
|
725
717
|
}, [scope, search, cwdPrefix]);
|
|
718
|
+
const firstLoadRef = React.useRef(true);
|
|
726
719
|
React.useEffect(() => {
|
|
727
|
-
|
|
728
|
-
|
|
720
|
+
if (firstLoadRef.current) {
|
|
721
|
+
firstLoadRef.current = false;
|
|
722
|
+
void load();
|
|
723
|
+
return undefined;
|
|
724
|
+
}
|
|
725
|
+
const timer = setTimeout(() => void load(), search === '' ? 0 : 250);
|
|
726
|
+
return () => clearTimeout(timer);
|
|
727
|
+
}, [load, search]);
|
|
729
728
|
const rows = data?.sessions ?? [];
|
|
730
729
|
const visible = showAll ? rows : rows.slice(0, 200);
|
|
731
730
|
function toggle(id) {
|
|
@@ -816,7 +815,7 @@
|
|
|
816
815
|
? 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)
|
|
817
816
|
: null);
|
|
818
817
|
// 待删除队列:条目、状态、撤销、立即重试。
|
|
819
|
-
return h('div', { style: fill ? { ...S.root, ...S_FILL.root } : S.root }, h('div', { style: S.muted }, 'DSH
|
|
818
|
+
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);
|
|
820
819
|
};
|
|
821
820
|
}
|
|
822
821
|
/** 右侧页签的标题条。 */
|
|
@@ -958,7 +957,7 @@
|
|
|
958
957
|
return { sessionId, removable: report?.removed > 0, reason: row?.reason };
|
|
959
958
|
}
|
|
960
959
|
/**
|
|
961
|
-
* 删除一个会话的整条流程:预演 →
|
|
960
|
+
* 删除一个会话的整条流程:预演 → 确认卡片 → 删除。
|
|
962
961
|
*
|
|
963
962
|
* 标题栏垃圾桶与右键菜单共用这一段:两处删的是同一个东西,只是入口不同,守卫与
|
|
964
963
|
* 确认必须逐字一致,否则「从菜单删」就等于绕开「从图标删」的那些检查。
|
|
@@ -1145,7 +1144,7 @@
|
|
|
1145
1144
|
key: 'headerDeleteButton',
|
|
1146
1145
|
kind: 'boolean',
|
|
1147
1146
|
label: '标题栏删除图标',
|
|
1148
|
-
hint: '
|
|
1147
|
+
hint: '在会话标题栏显示垃圾桶图标(默认开启)。它是图标而不是按钮,且删除要过一次确认卡片。改完刷新页面生效。',
|
|
1149
1148
|
},
|
|
1150
1149
|
{
|
|
1151
1150
|
key: 'allowLiveSessions',
|
|
@@ -1246,8 +1245,16 @@
|
|
|
1246
1245
|
// 注册项的 `inject` 把共享表单的 `{ state, mutate }` 作为 `form` 传进来;命名空间
|
|
1247
1246
|
// 不是「Host 在服务的设置命名空间」时快照是 undefined(见 dsh-client-ui-settings
|
|
1248
1247
|
// 的 ConfigFormController 与 dsh-client-ui-plugin-manager 的 formFor)。
|
|
1248
|
+
const [, setRevisionTick] = React.useState(0);
|
|
1249
1249
|
const form = props.form;
|
|
1250
|
-
|
|
1250
|
+
React.useEffect(() => {
|
|
1251
|
+
if (typeof form?.subscribe !== 'function')
|
|
1252
|
+
return undefined;
|
|
1253
|
+
return form.subscribe(() => setRevisionTick((n) => n + 1));
|
|
1254
|
+
}, [form]);
|
|
1255
|
+
const snapshot = form !== undefined && form !== null
|
|
1256
|
+
? (typeof form.getState === 'function' ? form.getState() : form.state)
|
|
1257
|
+
: undefined;
|
|
1251
1258
|
const writable = snapshot !== undefined && snapshot.writable !== false;
|
|
1252
1259
|
if (props.view === 'summary')
|
|
1253
1260
|
return h('span', null, SUMMARY);
|
|
@@ -1420,7 +1427,9 @@
|
|
|
1420
1427
|
// 因为要等一次请求才知道开关,所以注册是异步的;请求失败时按「不渲染」处理
|
|
1421
1428
|
// (安全的那一侧),而不是把按钮露出来。
|
|
1422
1429
|
let headerButtonDispose;
|
|
1430
|
+
let headerButtonDisposed = false;
|
|
1423
1431
|
ctx.effect(() => () => {
|
|
1432
|
+
headerButtonDisposed = true;
|
|
1424
1433
|
try {
|
|
1425
1434
|
headerButtonDispose?.();
|
|
1426
1435
|
}
|
|
@@ -1431,7 +1440,7 @@
|
|
|
1431
1440
|
void api
|
|
1432
1441
|
.call('config', {})
|
|
1433
1442
|
.then((config) => {
|
|
1434
|
-
if (config?.headerDeleteButton !== true)
|
|
1443
|
+
if (headerButtonDisposed || config?.headerDeleteButton !== true)
|
|
1435
1444
|
return;
|
|
1436
1445
|
headerButtonDispose = ctx.slots.inject('conversation.session.header.utilities', () => ctx.slots.register({
|
|
1437
1446
|
name: 'conversation.session.header.utilities',
|
|
@@ -1579,6 +1588,10 @@
|
|
|
1579
1588
|
inject: () => ({
|
|
1580
1589
|
form: {
|
|
1581
1590
|
state: configForm.getSnapshot(),
|
|
1591
|
+
getState: () => configForm.getSnapshot(),
|
|
1592
|
+
subscribe: typeof configForm.subscribe === 'function'
|
|
1593
|
+
? (listener) => configForm.subscribe(listener)
|
|
1594
|
+
: undefined,
|
|
1582
1595
|
mutate: (ops, revision) => configForm.mutate(ops, revision),
|
|
1583
1596
|
},
|
|
1584
1597
|
}),
|
|
@@ -1912,13 +1925,23 @@
|
|
|
1912
1925
|
* 工作区登记(客户端服务优先,回落 Host 路由)。
|
|
1913
1926
|
* @returns 面板组件。
|
|
1914
1927
|
*/
|
|
1915
|
-
function createPanel(React, api, workspaceTools) {
|
|
1928
|
+
function createPanel(React, api, workspaceTools, sessionsList) {
|
|
1916
1929
|
const h = React.createElement;
|
|
1917
1930
|
const { pickDirectory, createWorkspaceAt } = workspaceTools;
|
|
1918
1931
|
return function SessionMovePanel(props) {
|
|
1919
1932
|
const fill = props.fill === true;
|
|
1920
1933
|
const useSessions = props.useSessions;
|
|
1921
|
-
const
|
|
1934
|
+
const storeFromHook = typeof useSessions === 'function' ? useSessions((snapshot) => snapshot) : undefined;
|
|
1935
|
+
const [fallbackStore, setFallbackStore] = React.useState(() => typeof useSessions !== 'function' && typeof sessionsList?.getSnapshot === 'function'
|
|
1936
|
+
? sessionsList.getSnapshot()
|
|
1937
|
+
: undefined);
|
|
1938
|
+
React.useEffect(() => {
|
|
1939
|
+
if (typeof useSessions === 'function' || typeof sessionsList?.subscribe !== 'function')
|
|
1940
|
+
return undefined;
|
|
1941
|
+
setFallbackStore(sessionsList.getSnapshot?.());
|
|
1942
|
+
return sessionsList.subscribe(() => setFallbackStore(sessionsList.getSnapshot?.()));
|
|
1943
|
+
}, [useSessions]);
|
|
1944
|
+
const store = storeFromHook ?? fallbackStore;
|
|
1922
1945
|
const byId = store !== undefined && store !== null ? store.byId : undefined;
|
|
1923
1946
|
const [snapshot, setSnapshot] = React.useState(null);
|
|
1924
1947
|
const [failure, setFailure] = React.useState(null);
|
|
@@ -2266,7 +2289,7 @@
|
|
|
2266
2289
|
throw new Error('Host 没有返回工作区记录');
|
|
2267
2290
|
return workspace;
|
|
2268
2291
|
};
|
|
2269
|
-
const Panel = createPanel(React, api, { pickDirectory, createWorkspaceAt });
|
|
2292
|
+
const Panel = createPanel(React, api, { pickDirectory, createWorkspaceAt }, ctx.sessions?.list);
|
|
2270
2293
|
// 右侧面板服务:右键菜单要借它把搬迁页签打开(与删除半边同一套可选注入)。
|
|
2271
2294
|
let sidebarRight;
|
|
2272
2295
|
ctx.inject(['sidebarRight'], (injected) => {
|
package/lib/engine.js
CHANGED
|
@@ -154,7 +154,16 @@ export function applyPlan(plan) {
|
|
|
154
154
|
const parkedPath = plan.sourcePath + PARKED_SUFFIX;
|
|
155
155
|
writeDurable(tmpPath, plan.buffer);
|
|
156
156
|
renameSync(plan.sourcePath, parkedPath);
|
|
157
|
-
|
|
157
|
+
try {
|
|
158
|
+
renameSync(tmpPath, plan.targetPath);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
try {
|
|
162
|
+
renameSync(parkedPath, plan.sourcePath);
|
|
163
|
+
}
|
|
164
|
+
catch { }
|
|
165
|
+
throw error;
|
|
166
|
+
}
|
|
158
167
|
rmSync(parkedPath, { force: true });
|
|
159
168
|
// 0.2.2 起每个会话目录里有 `session.lock`(POSIX flock,写入句柄整个生命周期持有;
|
|
160
169
|
// 内核约定这个文件永不删除、靠稳定 inode 判断归属)。搬迁必须把它一起搬过去:
|
package/lib/move.js
CHANGED
|
@@ -86,16 +86,15 @@ export function isTrustedRequest(req, allowHosts) {
|
|
|
86
86
|
const host = String(req.headers?.host ?? '');
|
|
87
87
|
if (!fromLoopback && !(Array.isArray(allowHosts) && allowHosts.includes(host)))
|
|
88
88
|
return false;
|
|
89
|
-
// 3) 带了 Origin 就必须与请求的 authority
|
|
89
|
+
// 3) 带了 Origin 就必须与请求的 authority 同源(包含端口)。
|
|
90
90
|
const origin = req?.headers?.origin;
|
|
91
91
|
if (origin === undefined)
|
|
92
92
|
return true;
|
|
93
|
-
|
|
94
|
-
if (hostname === undefined)
|
|
93
|
+
if (host.length === 0)
|
|
95
94
|
return false;
|
|
96
95
|
try {
|
|
97
96
|
// 头可能是数组(重复头);`URL` 的入参本来就是字符串,这里按原语义做一次 ToString。
|
|
98
|
-
return new URL(String(origin)).
|
|
97
|
+
return new URL(String(origin)).host.toLowerCase() === host.toLowerCase();
|
|
99
98
|
}
|
|
100
99
|
catch {
|
|
101
100
|
return false;
|
|
@@ -106,7 +105,6 @@ function createMover(ctx, config, log) {
|
|
|
106
105
|
const persistence = ctx.sessionPersistence;
|
|
107
106
|
const registry = ctx.workspaceRegistry;
|
|
108
107
|
const sessionStore = ctx.get('sessions');
|
|
109
|
-
const agents = ctx.get('agents');
|
|
110
108
|
const rootOf = () => {
|
|
111
109
|
if (typeof config.root === 'string' && config.root.length > 0)
|
|
112
110
|
return config.root;
|
|
@@ -119,7 +117,7 @@ function createMover(ctx, config, log) {
|
|
|
119
117
|
// 下面这几个查询都来自 `lib/store/registry.js`(与删除半边共用一份):
|
|
120
118
|
// 服务挂在哪、id 怎么比、状态叫什么,规则只写在一个地方。
|
|
121
119
|
const residentIds = () => residentSessionIds(sessionStore);
|
|
122
|
-
const runningOf = (id) => agentSessionStatus(agents, id);
|
|
120
|
+
const runningOf = (id) => agentSessionStatus(ctx.get('agents'), id);
|
|
123
121
|
const writersOf = () => sessionWriteHandles(persistence);
|
|
124
122
|
const ownerOf = (sessionId) => workspaceOwningSession(registry.list(), sessionId);
|
|
125
123
|
const resolveWorkspace = (key) => findWorkspace(registry.list(), key);
|
|
@@ -334,25 +332,40 @@ function createMover(ctx, config, log) {
|
|
|
334
332
|
report.dryRunOnly = true;
|
|
335
333
|
return report;
|
|
336
334
|
}
|
|
337
|
-
// 1)
|
|
335
|
+
// 1) 落盘前先 flush 活跃写入句柄,免得 applyPlan 删掉源目录后 flush 撞上 ENOENT。
|
|
336
|
+
const writers = writersOf();
|
|
337
|
+
const preHandle = writers?.get(sessionId);
|
|
338
|
+
let preFlushError;
|
|
339
|
+
if (preHandle !== undefined && preHandle !== null && typeof preHandle.flush === 'function') {
|
|
340
|
+
try {
|
|
341
|
+
await preHandle.flush();
|
|
342
|
+
}
|
|
343
|
+
catch (error) {
|
|
344
|
+
preFlushError = messageOf(error);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
// 2) 落盘:日志搬家 + header cwd 改写。
|
|
338
348
|
const storage = applyPlan(plan);
|
|
339
349
|
report.storage = storage;
|
|
340
350
|
if (storage.ok !== true) {
|
|
341
351
|
throw new Error(`the log was moved to ${plan.targetPath} but the rewritten header did not verify: ${JSON.stringify(storage.verifiedHeader)}`);
|
|
342
352
|
}
|
|
343
|
-
//
|
|
353
|
+
// 3) 内存态:让"以后继续写"落到新位置。
|
|
344
354
|
// 写入句柄每次 append 都从自己的 header 重新推 logPath(appendLines → logPath(meta.cwd)),
|
|
345
355
|
// 所以改写 handle.header 就够了;会话对象自身的 header 也同步,供工具解析 cwd;
|
|
346
356
|
// 注册表里的头部缓存也要一起改。三处都在 `lib/store/registry.js`。
|
|
347
357
|
const redirect = await redirectSessionWriters({
|
|
348
|
-
writers
|
|
358
|
+
writers,
|
|
349
359
|
sessions: sessionStore,
|
|
350
360
|
registry,
|
|
351
361
|
sessionId,
|
|
352
362
|
cwd: targetPath,
|
|
363
|
+
skipFlush: true,
|
|
353
364
|
});
|
|
354
365
|
const live = redirect.liveSession;
|
|
355
|
-
if (
|
|
366
|
+
if (preFlushError !== undefined)
|
|
367
|
+
report.handleFlushError = preFlushError;
|
|
368
|
+
else if (redirect.flushError !== undefined)
|
|
356
369
|
report.handleFlushError = redirect.flushError;
|
|
357
370
|
if (redirect.writeHandleRedirected)
|
|
358
371
|
report.writeHandleRedirected = true;
|
|
@@ -904,23 +917,34 @@ export async function sweepForkChildrenOnBoot(ctx, config = {}, log = () => { },
|
|
|
904
917
|
report.skipped = 'listing-failed';
|
|
905
918
|
return report;
|
|
906
919
|
}
|
|
907
|
-
|
|
920
|
+
const forkSnapshots = (Array.isArray(snapshots) ? snapshots : []).filter((snapshot) => {
|
|
908
921
|
const header = snapshot?.header;
|
|
909
922
|
const sessionId = String(header?.id ?? snapshot?.id ?? '');
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
+
return sessionId.length > 0 && isForkChild(header);
|
|
924
|
+
});
|
|
925
|
+
report.checked = forkSnapshots.length;
|
|
926
|
+
const failed = new Set();
|
|
927
|
+
for (let pass = 0; pass < 5; pass += 1) {
|
|
928
|
+
let progress = false;
|
|
929
|
+
for (const snapshot of forkSnapshots) {
|
|
930
|
+
const header = snapshot?.header;
|
|
931
|
+
const sessionId = String(header?.id ?? snapshot?.id ?? '');
|
|
932
|
+
if (failed.has(sessionId) || repairer.ownerOf(sessionId) !== undefined)
|
|
933
|
+
continue;
|
|
934
|
+
try {
|
|
935
|
+
await repairer.repair(sessionId, header, 'boot-sweep');
|
|
936
|
+
if (repairer.ownerOf(sessionId) !== undefined) {
|
|
937
|
+
report.attached += 1;
|
|
938
|
+
progress = true;
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
catch (error) {
|
|
942
|
+
failed.add(sessionId);
|
|
943
|
+
log('warn', `membership sweep: ${sessionId} failed: ${messageOf(error)}`);
|
|
944
|
+
}
|
|
923
945
|
}
|
|
946
|
+
if (!progress)
|
|
947
|
+
break;
|
|
924
948
|
}
|
|
925
949
|
if (report.attached > 0)
|
|
926
950
|
log('info', `membership sweep: re-attached ${report.attached} of ${report.checked} fork child(ren) that had lost workspace accounting`);
|
package/lib/store/frames.js
CHANGED
|
@@ -176,11 +176,27 @@ export function readSessionHeader(dir, cache = new Map()) {
|
|
|
176
176
|
let header;
|
|
177
177
|
try {
|
|
178
178
|
const raw = readFileSync(path);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
179
|
+
let text;
|
|
180
|
+
if (log.name.endsWith('.zstd')) {
|
|
181
|
+
if (zstdDecompress !== undefined) {
|
|
182
|
+
const scan = scanZstdFrames(raw);
|
|
183
|
+
if (scan.frames.length > 0) {
|
|
184
|
+
try {
|
|
185
|
+
const first = scan.frames[0];
|
|
186
|
+
text = zstdDecompress(raw.subarray(first.start, first.end)).toString('utf8');
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
text = undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (text === undefined) {
|
|
193
|
+
text = zstdDecompress(raw).toString('utf8');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
text = raw.toString('utf8');
|
|
199
|
+
}
|
|
184
200
|
if (text !== undefined) {
|
|
185
201
|
const end = text.indexOf('\n');
|
|
186
202
|
header = JSON.parse(end === -1 ? text : text.slice(0, end));
|
|
@@ -189,6 +205,11 @@ export function readSessionHeader(dir, cache = new Map()) {
|
|
|
189
205
|
catch {
|
|
190
206
|
header = undefined;
|
|
191
207
|
}
|
|
208
|
+
if (cache.size >= 2000) {
|
|
209
|
+
const oldest = cache.keys().next().value;
|
|
210
|
+
if (oldest !== undefined)
|
|
211
|
+
cache.delete(oldest);
|
|
212
|
+
}
|
|
192
213
|
cache.set(key, header);
|
|
193
214
|
return header;
|
|
194
215
|
}
|
package/lib/store/registry.js
CHANGED
|
@@ -159,7 +159,8 @@ export function findWorkspace(workspaces, key) {
|
|
|
159
159
|
export async function releaseSessionEverywhere(registry, sessionId) {
|
|
160
160
|
const detached = [];
|
|
161
161
|
for (const workspace of registry.list()) {
|
|
162
|
-
|
|
162
|
+
const ids = accountedSessionIds(workspace) ?? workspace.sessionIds;
|
|
163
|
+
if (!ids.includes(sessionId))
|
|
163
164
|
continue;
|
|
164
165
|
await workspace.detachSession(sessionId);
|
|
165
166
|
detached.push(String(workspace.id));
|
|
@@ -208,11 +209,13 @@ export async function redirectSessionWriters(options) {
|
|
|
208
209
|
};
|
|
209
210
|
const handle = writers === undefined ? undefined : writers.get(sessionId);
|
|
210
211
|
if (handle !== undefined && handle !== null && typeof handle.header === 'object') {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
212
|
+
if (options.skipFlush !== true && typeof handle.flush === 'function') {
|
|
213
|
+
try {
|
|
214
|
+
await handle.flush();
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
outcome.flushError = messageOf(error);
|
|
218
|
+
}
|
|
216
219
|
}
|
|
217
220
|
handle.header = { ...handle.header, cwd };
|
|
218
221
|
outcome.writeHandleRedirected = true;
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-ops",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"description": "Session operations for DeepSeek Harness: really delete persisted sessions (ungrouped/temp/archive/subagent filters, running-session guards) and move sessions between workspaces (log relocation, header.cwd rewrite, workspace registry follow). Ships the shared session-store primitives (project-directory keys, jsonl.zstd frames, workspace registry, host/HTTP plumbing) as lib/store. One host entry with two HTTP prefixes and
|
|
8
|
+
"description": "Session operations for DeepSeek Harness: really delete persisted sessions (ungrouped/temp/archive/subagent filters, running-session guards) and move sessions between workspaces (log relocation, header.cwd rewrite, workspace registry follow). Ships the shared session-store primitives (project-directory keys, jsonl.zstd frames, workspace registry, host/HTTP plumbing) as lib/store. One host entry with two HTTP prefixes and three model tools, one browser bundle with two right-pane tabs and a merged config card.",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"dsh",
|
|
11
11
|
"dsh-plugin",
|
|
@@ -34,6 +34,8 @@
|
|
|
34
34
|
"types": "./lib/types/store/index.d.ts",
|
|
35
35
|
"default": "./lib/store/index.js"
|
|
36
36
|
},
|
|
37
|
+
"./locale/*.json": "./locale/*.json",
|
|
38
|
+
"./icon": "./icon.svg",
|
|
37
39
|
"./package.json": "./package.json"
|
|
38
40
|
},
|
|
39
41
|
"files": [
|
|
@@ -56,9 +58,6 @@
|
|
|
56
58
|
"node": ">=24",
|
|
57
59
|
"dsh": "^0.2.1-rc.2 || ^0.2.2-alpha.2 || ^0.2.3-alpha.1"
|
|
58
60
|
},
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"@deepseek-ai/schemastery": "^3.18.5 || ^3.18.6-alpha.1"
|
|
61
|
-
},
|
|
62
61
|
"peerDependencies": {
|
|
63
62
|
"@deepseek-ai/schemastery": "^3.18.5 || ^3.18.6-alpha.1"
|
|
64
63
|
},
|