dsh-session-relocate 0.2.0 → 0.2.2
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 +7 -0
- package/docs/DESIGN.md +11 -0
- package/lib/client.js +269 -33
- package/package.json +1 -1
- package/src/plugin.js +99 -2
package/README.md
CHANGED
|
@@ -71,9 +71,16 @@ curl http://127.0.0.1:3080/api/dsh-session-relocate/status
|
|
|
71
71
|
|
|
72
72
|
- 装了 [`dsh-delete-session`](https://www.npmjs.com/package/dsh-delete-session) 的话,它的「多选」底栏会多出一个 **移动** 按钮 —— 两个插件共用同一套选择模式,不会出现两个「多选」入口。
|
|
73
73
|
- 多选状态下**直接拖**也行:抓一条选中的行拖到目标工作区,整批一起搬(见上一节)。
|
|
74
|
+
- 目标列表会直接标出「**将移动 M 个 / 跳过 K 个**」;全部已在目标工作区的项会置灰,点了也不会发请求。
|
|
74
75
|
- 批量不是把 N 次单搬简单循环:文件事务逐条做(进度、失败隔离),**工作区归属最后一次性写入**。按实测的单条固定开销推算,3 条会话的总耗时从约 0.96 秒降到约 0.6 秒,条数越多差距越大。
|
|
75
76
|
- 中途崩了也不怕:每条会话的迁移日志还在,下次启动(或下一次桥接调用)会按文件状态幂等补完归属。
|
|
76
77
|
|
|
78
|
+
### 连同子对话(默认开)
|
|
79
|
+
|
|
80
|
+
子智能体的会话(`origin: subagent`,侧边栏里是隐藏的)默认会**跟着父对话一起搬**:父搬到哪,它的子、孙会话也搬到哪里,`cwd` 和工作区归属一起改。每条子会话独立走事务,失败按条隔离,不会拖累父对话的回执。
|
|
81
|
+
|
|
82
|
+
想只搬父对话:**Plugins → dsh-session-relocate → 配置** 里把「连同子对话一起移动」关掉(存在浏览器本地,默认开)。关掉后子会话留在旧工作区 —— 旧工作区先别删,子会话日志还在里面。
|
|
83
|
+
|
|
77
84
|
### 正在回答的对话也能搬
|
|
78
85
|
|
|
79
86
|
**包括正在回答、正跑子代理、正跑后台任务的那个。** 插件会先拿到它的写所有权,再动文件:
|
package/docs/DESIGN.md
CHANGED
|
@@ -202,6 +202,17 @@ header 是冻的,所以**那一轮的工具仍然用旧目录**;下次打开
|
|
|
202
202
|
不止一条时,投放走 `runBulkMove`(逐条 defer + 一次 commit),完成后发一个 `Escape` 让宿主收起
|
|
203
203
|
多选;拖一条没被选中的行仍按单条搬。
|
|
204
204
|
|
|
205
|
+
**目标预分类**:打开目标面板时不隐藏任何工作区,而是按选中会话当前的 DOM 归属,给每一项算出
|
|
206
|
+
「将移动 M / 跳过 K」;M=0 的项置灰、不绑点击 —— 省掉纯 no-op 的 N 次请求,又不会在多选跨工作区时
|
|
207
|
+
误删合法目标(例如 A 里 2 条、B 里 1 条,选 A 是合法的:搬 B 的 1 条、跳过 A 的 2 条)。
|
|
208
|
+
|
|
209
|
+
**连同子对话**:主机在搬完一条会话后,用 `sessionPersistence.list()` 的 header 关系找
|
|
210
|
+
`origin === 'subagent' && parentSession === 本会话` 的后代(递归到孙),逐条走完整的
|
|
211
|
+
`relocateSession`(文件 + 归属),`already-there` 记为跳过、其余失败按条隔离。开关在插件设置页
|
|
212
|
+
(`plugins.row.config` 槽),值存 localStorage,**默认开**;关掉时客户端在 `/move` 里显式传
|
|
213
|
+
`includeChildren: false`,主机就不找子会话。不搬子对话不会破坏父对话(子代理的产出事件本来就在
|
|
214
|
+
父日志里),但子会话的日志/`cwd`/归属会留在旧工作区 —— 旧目录被删就一起没了。
|
|
215
|
+
|
|
205
216
|
失效降级(分级,绝不错猜):分组结构读不到 → 退化成「只认文件夹行」(更早版本的老行为);
|
|
206
217
|
连行属性也读不到 → 完全不介入(不会误伤官方拖动)。菜单那条路始终可用;
|
|
207
218
|
`config.dragMove = false` 让客户端根本不挂这些监听。
|
package/lib/client.js
CHANGED
|
@@ -19,34 +19,65 @@ window.__ModuleLoader__.load({
|
|
|
19
19
|
|
|
20
20
|
var STYLE_ID = 'dsh-session-relocate-styles';
|
|
21
21
|
var CSS = [
|
|
22
|
-
'.dshsm-item{display:block;width:100%;box-sizing:border-box;text-align:left;font:inherit;font-size:13px;line-height:1.45;padding:6px 10px;border:0;border-radius:6px;background:0 0;color:
|
|
22
|
+
'.dshsm-item{display:block;width:100%;box-sizing:border-box;text-align:left;font:inherit;font-size:13px;line-height:1.45;padding:6px 10px;border:0;border-radius:6px;background:0 0;color:inherit;cursor:pointer;white-space:normal;overflow-wrap:anywhere}',
|
|
23
23
|
'.dshsm-item:hover:not(:disabled){background:var(--dsw-alias-fill-secondary,rgba(127,127,127,.12))}',
|
|
24
|
-
'.dshsm-item:disabled{color:
|
|
24
|
+
'.dshsm-item:disabled{color:inherit;opacity:.45;cursor:default}',
|
|
25
25
|
'.dshsm-target{padding-left:18px}',
|
|
26
|
-
'.dshsm-meta{display:block;font-size:11px;color:
|
|
26
|
+
'.dshsm-meta{display:block;font-size:11px;color:inherit;opacity:.65;overflow-wrap:anywhere}',
|
|
27
27
|
'.dshsm-bad{color:#ff453a}',
|
|
28
28
|
// 拖动时给工作区行加的高亮(官方行本身没有 drop 语义,所以这个类只由本插件加)
|
|
29
29
|
'.dshsm-drop{outline:2px solid #4c8dff;outline-offset:-2px;border-radius:6px}',
|
|
30
30
|
// 多选模式:行首勾选圈 + 底部操作条 + 目标工作区面板
|
|
31
31
|
'.dshsm-check{display:inline-flex;align-items:center;justify-content:center;width:18px;height:18px;margin-right:6px;border-radius:50%;border:1.5px solid var(--dsw-alias-border-l3,rgba(128,128,128,.5));background:0 0;flex:none}',
|
|
32
|
-
'.dshsm-check-on{border-color:#4c8dff;background:#4c8dff;box-shadow:inset 0 0 0 3px
|
|
33
|
-
'.dshsm-
|
|
32
|
+
'.dshsm-check-on{border-color:#4c8dff;background:#4c8dff;box-shadow:inset 0 0 0 3px #fff}',
|
|
33
|
+
'.dshsm-dark .dshsm-check-on{box-shadow:inset 0 0 0 3px #1f232b}',
|
|
34
|
+
'.dshsm-bar{position:fixed;left:12px;bottom:12px;z-index:2147483600;display:flex;align-items:center;gap:10px;padding:10px 12px;border-radius:12px;border:1px solid transparent;box-shadow:0 8px 28px rgba(0,0,0,.28)}',
|
|
35
|
+
'.dshsm-bar.dshsm-dark{background:#1f232b;color:#f2f3f5;border-color:rgba(255,255,255,.18);color-scheme:dark}',
|
|
36
|
+
'.dshsm-bar.dshsm-light{background:#fff;color:#12151a;border-color:rgba(0,0,0,.14);color-scheme:light}',
|
|
34
37
|
'.dshsm-bar-count{font-size:13px;white-space:nowrap}',
|
|
35
|
-
'.dshsm-bar-btn{appearance:none;min-height:30px;padding:0 12px;border-radius:8px;border:1px solid
|
|
36
|
-
'.dshsm-bar-btn:hover:not(:disabled){background:
|
|
38
|
+
'.dshsm-bar-btn{appearance:none;min-height:30px;padding:0 12px;border-radius:8px;border:1px solid rgba(127,127,127,.45);background:0 0;color:inherit;font:inherit;font-size:13px;cursor:pointer}',
|
|
39
|
+
'.dshsm-dark .dshsm-bar-btn:hover:not(:disabled){background:rgba(255,255,255,.08)}',
|
|
40
|
+
'.dshsm-light .dshsm-bar-btn:hover:not(:disabled){background:rgba(0,0,0,.06)}',
|
|
37
41
|
'.dshsm-bar-btn:disabled{opacity:.5;cursor:default}',
|
|
38
42
|
'.dshsm-bar-primary{border-color:#4c8dff;background:#4c8dff;color:#fff}',
|
|
39
|
-
'.dshsm-picker-backdrop{position:fixed;inset:0;z-index:2147483602;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.
|
|
40
|
-
'.dshsm-picker{width:min(440px,92vw);max-height:70vh;overflow:auto;display:flex;flex-direction:column;gap:10px;padding:16px;border-radius:14px;
|
|
43
|
+
'.dshsm-picker-backdrop{position:fixed;inset:0;z-index:2147483602;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.42)}',
|
|
44
|
+
'.dshsm-picker{width:min(440px,92vw);max-height:70vh;overflow:auto;display:flex;flex-direction:column;gap:10px;padding:16px;border-radius:14px;border:1px solid transparent;box-shadow:0 18px 48px rgba(0,0,0,.36)}',
|
|
45
|
+
'.dshsm-picker.dshsm-dark{background:#1f232b;color:#f2f3f5;border-color:rgba(255,255,255,.18);color-scheme:dark}',
|
|
46
|
+
'.dshsm-picker.dshsm-light{background:#fff;color:#12151a;border-color:rgba(0,0,0,.14);color-scheme:light}',
|
|
41
47
|
'.dshsm-picker-title{font-size:14px;font-weight:600}',
|
|
42
48
|
'.dshsm-picker-list{display:flex;flex-direction:column;gap:6px}',
|
|
43
49
|
'.dshsm-picker-item{display:flex;flex-direction:column;gap:2px;width:100%;text-align:left;padding:8px 10px;border-radius:8px;border:1px solid transparent;background:0 0;color:inherit;font:inherit;font-size:13px;cursor:pointer}',
|
|
44
|
-
'.dshsm-picker-item:hover{background:
|
|
45
|
-
'.dshsm-picker-
|
|
46
|
-
'.dshsm-picker-
|
|
47
|
-
'.dshsm-picker-
|
|
50
|
+
'.dshsm-dark .dshsm-picker-item:hover{background:rgba(255,255,255,.08)}',
|
|
51
|
+
'.dshsm-light .dshsm-picker-item:hover{background:rgba(0,0,0,.06)}',
|
|
52
|
+
'.dshsm-picker-name{font-weight:500;color:inherit}',
|
|
53
|
+
'.dshsm-picker-path{font-size:11px;overflow-wrap:anywhere}',
|
|
54
|
+
'.dshsm-dark .dshsm-picker-path,.dshsm-dark .dshsm-picker-empty{color:#a7b0bf}',
|
|
55
|
+
'.dshsm-light .dshsm-picker-path,.dshsm-light .dshsm-picker-empty{color:#667085}',
|
|
56
|
+
'.dshsm-picker-count{font-size:11px}',
|
|
57
|
+
'.dshsm-dark .dshsm-picker-count{color:#a7b0bf}',
|
|
58
|
+
'.dshsm-light .dshsm-picker-count{color:#667085}',
|
|
59
|
+
'.dshsm-picker-item:disabled{opacity:.55;cursor:default}',
|
|
60
|
+
'.dshsm-picker-empty{font-size:12px}',
|
|
48
61
|
'.dshsm-picker-actions{display:flex;justify-content:flex-end}',
|
|
49
|
-
'.dshsm-picker-btn{appearance:none;min-height:30px;padding:0 12px;border-radius:8px;border:1px solid
|
|
62
|
+
'.dshsm-picker-btn{appearance:none;min-height:30px;padding:0 12px;border-radius:8px;border:1px solid rgba(127,127,127,.45);background:0 0;color:inherit;font:inherit;font-size:13px;cursor:pointer}',
|
|
63
|
+
'.dshsm-dark .dshsm-picker-btn:hover:not(:disabled){background:rgba(255,255,255,.08)}',
|
|
64
|
+
'.dshsm-light .dshsm-picker-btn:hover:not(:disabled){background:rgba(0,0,0,.06)}',
|
|
65
|
+
'.dshsm-picker-btn:disabled{opacity:.45;cursor:default}',
|
|
66
|
+
// 插件设置页:连同子对话开关
|
|
67
|
+
'.dshsm-setting{display:flex;align-items:flex-start;gap:16px;padding:12px 0;width:100%}',
|
|
68
|
+
'.dshsm-setting-text{flex:1;min-width:0}',
|
|
69
|
+
'.dshsm-setting-title{font-size:13px;font-weight:600;line-height:20px}',
|
|
70
|
+
'.dshsm-setting-desc{font-size:12px;line-height:18px;opacity:.7;margin-top:2px}',
|
|
71
|
+
'.dshsm-switch{position:relative;flex:none;width:38px;height:22px;border-radius:11px;border:0;padding:0;cursor:pointer;background:rgba(127,127,127,.4)}',
|
|
72
|
+
'.dshsm-switch[aria-checked="true"]{background:#4c8dff}',
|
|
73
|
+
'.dshsm-switch::after{content:"";position:absolute;top:2px;left:2px;width:18px;height:18px;border-radius:50%;background:#fff;transition:left .15s ease}',
|
|
74
|
+
'.dshsm-switch[aria-checked="true"]::after{left:18px}',
|
|
75
|
+
'.dshsm-card{display:flex;flex-direction:column;gap:10px;width:100%}',
|
|
76
|
+
'.dshsm-star{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin-top:6px;padding:8px 10px;border-radius:8px;border:1px solid rgba(0,0,0,.08);background:rgba(255,196,0,.06);color:inherit;text-decoration:none;font-size:12px;line-height:1.4}',
|
|
77
|
+
'.dshsm-star:hover{background:rgba(255,196,0,.14)}',
|
|
78
|
+
'.dshsm-starIcon{font-size:14px;line-height:1}',
|
|
79
|
+
'.dshsm-starCta{margin-left:auto;color:#8a6d00;font-weight:600}',
|
|
80
|
+
'@media (prefers-color-scheme: dark){.dshsm-star{border-color:rgba(255,255,255,.12);background:rgba(255,196,0,.08)}.dshsm-starCta{color:#e8c15a}}',
|
|
50
81
|
].join('');
|
|
51
82
|
|
|
52
83
|
function ensureStyles() {
|
|
@@ -111,9 +142,16 @@ window.__ModuleLoader__.load({
|
|
|
111
142
|
bulkDone: '已移动 {ok} 个',
|
|
112
143
|
bulkPartial: '已移动 {ok} 个,{fail} 个失败',
|
|
113
144
|
bulkSkipped: '({n} 个本来就在目标工作区)',
|
|
145
|
+
bulkPlanMove: '将移动 {m} 个',
|
|
146
|
+
bulkPlanSkip: ' · 跳过 {s} 个',
|
|
147
|
+
bulkPlanAllHere: '全部已在这里',
|
|
114
148
|
bulkFailed: '批量移动失败:',
|
|
115
149
|
noteReleaseRetries: '(释放重试 {n} 次)',
|
|
116
150
|
noteSampled: '(大会话:抽样校验)',
|
|
151
|
+
childrenSettingTitle: '连同子对话一起移动',
|
|
152
|
+
childrenSettingDesc: '默认开。移动父对话时,它的子智能体会话(侧边栏里隐藏的 subagent 会话)一起搬到目标工作区;关掉后只搬父对话。',
|
|
153
|
+
starPrompt: '顺手留颗 Star,作者能高兴一整天',
|
|
154
|
+
starCta: '行,给你一颗 Star',
|
|
117
155
|
};
|
|
118
156
|
var EN = {
|
|
119
157
|
open: 'Move to',
|
|
@@ -139,15 +177,79 @@ window.__ModuleLoader__.load({
|
|
|
139
177
|
bulkDone: 'Moved {ok}',
|
|
140
178
|
bulkPartial: 'Moved {ok}, {fail} failed',
|
|
141
179
|
bulkSkipped: ' ({n} already there)',
|
|
180
|
+
bulkPlanMove: 'Move {m}',
|
|
181
|
+
bulkPlanSkip: ' · skip {s}',
|
|
182
|
+
bulkPlanAllHere: 'All already here',
|
|
142
183
|
bulkFailed: 'Bulk move failed: ',
|
|
143
184
|
noteReleaseRetries: ' (release retried {n}×)',
|
|
144
185
|
noteSampled: ' (large session: sampled verify)',
|
|
186
|
+
childrenSettingTitle: 'Move child conversations too',
|
|
187
|
+
childrenSettingDesc: 'On by default. Moving a conversation also moves its hidden subagent sessions to the target workspace; turn it off to move only the parent conversation.',
|
|
188
|
+
starPrompt: 'Leave a star — it makes the author’s day',
|
|
189
|
+
starCta: 'Give a star',
|
|
145
190
|
};
|
|
146
191
|
|
|
147
192
|
function text() {
|
|
148
193
|
return isChinese() ? ZH : EN;
|
|
149
194
|
}
|
|
150
195
|
|
|
196
|
+
/** 「连同子对话」开关:插件设置页里改,存 localStorage,默认开。 */
|
|
197
|
+
function wantChildren() {
|
|
198
|
+
try {
|
|
199
|
+
if (typeof localStorage !== 'undefined' && localStorage !== null) {
|
|
200
|
+
return localStorage.getItem('dsh-session-relocate.includeChildren') !== 'false';
|
|
201
|
+
}
|
|
202
|
+
} catch (error) { /* 隐私模式读不了就按默认 */ }
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function setWantChildren(value) {
|
|
207
|
+
try {
|
|
208
|
+
if (typeof localStorage !== 'undefined' && localStorage !== null) {
|
|
209
|
+
localStorage.setItem('dsh-session-relocate.includeChildren', value ? 'true' : 'false');
|
|
210
|
+
}
|
|
211
|
+
} catch (error) { /* 写不进去就算了,下次还是默认开 */ }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** 插件设置页里的「连同子对话」开关(行配置页与包配置页共用)。 */
|
|
215
|
+
function ChildrenSetting() {
|
|
216
|
+
var strings = text();
|
|
217
|
+
var state = react.useState(wantChildren() ? 'on' : 'off');
|
|
218
|
+
var on = state[0] === 'on';
|
|
219
|
+
function toggle() {
|
|
220
|
+
var next = on !== true;
|
|
221
|
+
state[1](next ? 'on' : 'off');
|
|
222
|
+
setWantChildren(next);
|
|
223
|
+
}
|
|
224
|
+
return react.createElement('div', { className: 'dshsm-card' }, [
|
|
225
|
+
react.createElement('div', { className: 'dshsm-setting', key: 'setting' }, [
|
|
226
|
+
react.createElement('div', { className: 'dshsm-setting-text', key: 'text' }, [
|
|
227
|
+
react.createElement('div', { className: 'dshsm-setting-title', key: 'title' }, strings.childrenSettingTitle),
|
|
228
|
+
react.createElement('div', { className: 'dshsm-setting-desc', key: 'desc' }, strings.childrenSettingDesc),
|
|
229
|
+
]),
|
|
230
|
+
react.createElement('button', {
|
|
231
|
+
key: 'switch',
|
|
232
|
+
type: 'button',
|
|
233
|
+
role: 'switch',
|
|
234
|
+
'aria-checked': on === true ? 'true' : 'false',
|
|
235
|
+
className: 'dshsm-switch',
|
|
236
|
+
onClick: toggle,
|
|
237
|
+
}),
|
|
238
|
+
]),
|
|
239
|
+
react.createElement('a', {
|
|
240
|
+
key: 'star',
|
|
241
|
+
className: 'dshsm-star',
|
|
242
|
+
href: 'https://github.com/DDDMUC/dsh-session-relocate',
|
|
243
|
+
target: '_blank',
|
|
244
|
+
rel: 'noopener noreferrer',
|
|
245
|
+
}, [
|
|
246
|
+
react.createElement('span', { className: 'dshsm-starIcon', key: 'icon' }, '⭐'),
|
|
247
|
+
react.createElement('span', { key: 'prompt' }, strings.starPrompt),
|
|
248
|
+
react.createElement('span', { className: 'dshsm-starCta', key: 'cta' }, strings.starCta),
|
|
249
|
+
]),
|
|
250
|
+
]);
|
|
251
|
+
}
|
|
252
|
+
|
|
151
253
|
function post(path, body) {
|
|
152
254
|
var options = { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body !== undefined ? body : {}) };
|
|
153
255
|
return fetch(bridgePrefix() + path, options).then(function (response) {
|
|
@@ -537,7 +639,9 @@ window.__ModuleLoader__.load({
|
|
|
537
639
|
function moveByDrag(sessionId, targetWorkspaceId, hostSelected) {
|
|
538
640
|
var strings = text();
|
|
539
641
|
toast(strings.moving);
|
|
540
|
-
|
|
642
|
+
var payload = { sessionId: sessionId, targetWorkspaceId: targetWorkspaceId };
|
|
643
|
+
if (wantChildren() === false) payload.includeChildren = false;
|
|
644
|
+
post('/move', payload).then(function (result) {
|
|
541
645
|
if (result !== null && result !== undefined && result.ok === true) {
|
|
542
646
|
var title = result.targetTitle;
|
|
543
647
|
var label = typeof title === 'string' && title.length > 0 ? title : targetWorkspaceId;
|
|
@@ -767,7 +871,9 @@ window.__ModuleLoader__.load({
|
|
|
767
871
|
function step(index) {
|
|
768
872
|
if (index >= ids.length) return twoPhase && deferred.length > 0 ? commit(deferred) : Promise.resolve(finish());
|
|
769
873
|
var sessionId = ids[index];
|
|
770
|
-
var
|
|
874
|
+
var payload = { sessionId: sessionId, targetWorkspaceId: targetWorkspaceId, deferRegistry: twoPhase };
|
|
875
|
+
if (wantChildren() === false) payload.includeChildren = false;
|
|
876
|
+
var done = post('/move', payload).then(function (result) {
|
|
771
877
|
if (result !== null && typeof result === 'object' && result.ok === true) {
|
|
772
878
|
if (result.verification === 'sampled') sampled = true;
|
|
773
879
|
if (Number.isSafeInteger(result.releaseAttempts) && result.releaseAttempts > releaseRetries) releaseRetries = result.releaseAttempts;
|
|
@@ -802,18 +908,92 @@ window.__ModuleLoader__.load({
|
|
|
802
908
|
return step(0);
|
|
803
909
|
}
|
|
804
910
|
|
|
911
|
+
/** 把一个 CSS 颜色转成 0..1 的相对亮度;透明 / 解析不了返回 null。 */
|
|
912
|
+
function colorLuminance(value) {
|
|
913
|
+
var match = /rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?/.exec(String(value));
|
|
914
|
+
if (match === null) return null;
|
|
915
|
+
if (match[4] !== undefined && Number(match[4]) === 0) return null;
|
|
916
|
+
return (0.2126 * Number(match[1]) + 0.7152 * Number(match[2]) + 0.0722 * Number(match[3])) / 255;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
/**
|
|
920
|
+
* 页面是深色还是浅色 —— 先看 body 的**背景亮度**,背景拿不到再看**文字亮度**。
|
|
921
|
+
* 不读 `--dsw-*` token:实测某些主题/皮肤下 token 缺失或与背景不配对,选择面板会变成
|
|
922
|
+
* 「深底 + 深字」。拿不到任何样式时退回深色(深底浅字在任何主题下都能看清)。
|
|
923
|
+
*/
|
|
924
|
+
function pageIsDark() {
|
|
925
|
+
try {
|
|
926
|
+
if (typeof document === 'undefined' || typeof getComputedStyle !== 'function') return true;
|
|
927
|
+
var style = getComputedStyle(document.body);
|
|
928
|
+
var bg = colorLuminance(style.backgroundColor);
|
|
929
|
+
if (bg !== null) return bg < 0.5;
|
|
930
|
+
var fg = colorLuminance(style.color);
|
|
931
|
+
if (fg !== null) return fg > 0.5;
|
|
932
|
+
return true;
|
|
933
|
+
} catch (error) {
|
|
934
|
+
return true;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
function themeClass() {
|
|
939
|
+
return pageIsDark() ? 'dshsm-dark' : 'dshsm-light';
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
/** 这条会话现在挂在哪个工作区分组里(按侧边栏 DOM;行没渲染就返回 null)。 */
|
|
943
|
+
function ownerWorkspaceOf(sessionId) {
|
|
944
|
+
if (typeof document === 'undefined' || typeof document.querySelector !== 'function') return null;
|
|
945
|
+
var row = null;
|
|
946
|
+
try {
|
|
947
|
+
row = document.querySelector('[data-row-key="session:' + sessionId + '"]');
|
|
948
|
+
} catch (error) {
|
|
949
|
+
row = null;
|
|
950
|
+
}
|
|
951
|
+
if (row === null || row === undefined) return null;
|
|
952
|
+
var group = workspaceGroupOf(row);
|
|
953
|
+
return group === null ? null : group.workspaceId;
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
/**
|
|
957
|
+
* 纯逻辑:按每条会话的归属,给每个目标算出「将移动 m / 跳过 s」。
|
|
958
|
+
* 归属未知(行没渲染、读不到分组)一律算「会搬」,宁可多问一次也不误导用户。
|
|
959
|
+
*/
|
|
960
|
+
function planTargetsWith(ids, workspaces, ownerOf) {
|
|
961
|
+
var owners = {};
|
|
962
|
+
for (var i = 0; i < ids.length; i += 1) {
|
|
963
|
+
try { owners[ids[i]] = ownerOf(ids[i]); } catch (error) { owners[ids[i]] = null; }
|
|
964
|
+
}
|
|
965
|
+
var plans = [];
|
|
966
|
+
for (var j = 0; j < workspaces.length; j += 1) {
|
|
967
|
+
var workspace = workspaces[j];
|
|
968
|
+
var moved = 0;
|
|
969
|
+
var skipped = 0;
|
|
970
|
+
for (var k = 0; k < ids.length; k += 1) {
|
|
971
|
+
var owner = owners[ids[k]];
|
|
972
|
+
if (owner !== null && owner !== undefined && owner === workspace.id) skipped += 1;
|
|
973
|
+
else moved += 1;
|
|
974
|
+
}
|
|
975
|
+
plans.push({ workspace: workspace, moved: moved, skipped: skipped, disabled: moved === 0 });
|
|
976
|
+
}
|
|
977
|
+
return plans;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
function planTargets(ids, workspaces) {
|
|
981
|
+
return planTargetsWith(ids, workspaces, ownerWorkspaceOf);
|
|
982
|
+
}
|
|
983
|
+
|
|
805
984
|
/** 弹一个居中的目标工作区面板;取消返回 { canceled: true }。 */
|
|
806
|
-
function pickBulkTarget(
|
|
985
|
+
function pickBulkTarget(sessionIds) {
|
|
986
|
+
var ids = Array.isArray(sessionIds) ? sessionIds.filter(function (id) { return typeof id === 'string' && id.length > 0; }) : [];
|
|
807
987
|
return new Promise(function (resolve) {
|
|
808
988
|
var strings = text();
|
|
809
989
|
var backdrop = document.createElement('div');
|
|
810
990
|
backdrop.className = 'dshsm-picker-backdrop';
|
|
811
991
|
var panel = document.createElement('div');
|
|
812
|
-
panel.className = 'dshsm-picker';
|
|
992
|
+
panel.className = 'dshsm-picker ' + themeClass();
|
|
813
993
|
panel.setAttribute('role', 'dialog');
|
|
814
994
|
var title = document.createElement('div');
|
|
815
995
|
title.className = 'dshsm-picker-title';
|
|
816
|
-
title.textContent = strings.bulkPicking.replace('{n}', String(
|
|
996
|
+
title.textContent = strings.bulkPicking.replace('{n}', String(ids.length));
|
|
817
997
|
panel.appendChild(title);
|
|
818
998
|
var list = document.createElement('div');
|
|
819
999
|
list.className = 'dshsm-picker-list';
|
|
@@ -862,8 +1042,10 @@ window.__ModuleLoader__.load({
|
|
|
862
1042
|
list.appendChild(empty);
|
|
863
1043
|
return;
|
|
864
1044
|
}
|
|
865
|
-
|
|
866
|
-
|
|
1045
|
+
var plans = planTargets(ids, spaces);
|
|
1046
|
+
for (var i = 0; i < plans.length; i += 1) {
|
|
1047
|
+
(function (plan) {
|
|
1048
|
+
var workspace = plan.workspace;
|
|
867
1049
|
var item = document.createElement('button');
|
|
868
1050
|
item.type = 'button';
|
|
869
1051
|
item.className = 'dshsm-picker-item';
|
|
@@ -877,9 +1059,20 @@ window.__ModuleLoader__.load({
|
|
|
877
1059
|
path.textContent = workspace.path;
|
|
878
1060
|
item.appendChild(path);
|
|
879
1061
|
}
|
|
880
|
-
|
|
1062
|
+
var countLine = document.createElement('span');
|
|
1063
|
+
countLine.className = 'dshsm-picker-count';
|
|
1064
|
+
countLine.textContent = plan.disabled === true
|
|
1065
|
+
? strings.bulkPlanAllHere
|
|
1066
|
+
: strings.bulkPlanMove.replace('{m}', String(plan.moved))
|
|
1067
|
+
+ (plan.skipped > 0 ? strings.bulkPlanSkip.replace('{s}', String(plan.skipped)) : '');
|
|
1068
|
+
item.appendChild(countLine);
|
|
1069
|
+
if (plan.disabled === true) {
|
|
1070
|
+
item.disabled = true;
|
|
1071
|
+
} else {
|
|
1072
|
+
item.addEventListener('click', function () { done({ workspace: workspace }); });
|
|
1073
|
+
}
|
|
881
1074
|
list.appendChild(item);
|
|
882
|
-
})(
|
|
1075
|
+
})(plans[i]);
|
|
883
1076
|
}
|
|
884
1077
|
}, function (error) {
|
|
885
1078
|
if (settled) return;
|
|
@@ -902,7 +1095,7 @@ window.__ModuleLoader__.load({
|
|
|
902
1095
|
if (ids.length === 0) {
|
|
903
1096
|
return Promise.resolve({ canceled: false, moved: 0, failed: 0, skipped: 0, total: 0, results: [] });
|
|
904
1097
|
}
|
|
905
|
-
return pickBulkTarget(ids
|
|
1098
|
+
return pickBulkTarget(ids).then(function (picked) {
|
|
906
1099
|
if (picked === null || picked === undefined || picked.workspace === undefined) {
|
|
907
1100
|
return { canceled: true, moved: 0, failed: 0, skipped: 0, total: ids.length, results: [] };
|
|
908
1101
|
}
|
|
@@ -972,7 +1165,7 @@ window.__ModuleLoader__.load({
|
|
|
972
1165
|
function buildBulkBar() {
|
|
973
1166
|
var strings = text();
|
|
974
1167
|
var bar = document.createElement('div');
|
|
975
|
-
bar.className = 'dshsm-bar';
|
|
1168
|
+
bar.className = 'dshsm-bar ' + themeClass();
|
|
976
1169
|
bar.setAttribute('role', 'toolbar');
|
|
977
1170
|
var count = document.createElement('span');
|
|
978
1171
|
count.className = 'dshsm-bar-count';
|
|
@@ -1133,28 +1326,70 @@ window.__ModuleLoader__.load({
|
|
|
1133
1326
|
} else {
|
|
1134
1327
|
installDrag();
|
|
1135
1328
|
}
|
|
1136
|
-
|
|
1137
|
-
|
|
1329
|
+
var disposers = [];
|
|
1330
|
+
// 插件设置页(Plugins → 本插件):把「连同子对话」开关挂到这一行的配置页。
|
|
1331
|
+
// 槽的 renderSlot 用 options.key 过滤,所以这里把「行 id 的两种可能写法」都登记上,
|
|
1332
|
+
// 行页和包页各一条,匹配不上的那条不会渲染。
|
|
1333
|
+
if (typeof ctx.slots.inject === 'function') {
|
|
1334
|
+
disposers.push(ctx.slots.inject('plugins.row.config', function () {
|
|
1335
|
+
var keys = ['dsh-session-relocate#session-relocate', 'dsh-session-relocate#dsh-session-relocate'];
|
|
1336
|
+
var entries = [];
|
|
1337
|
+
for (var i = 0; i < keys.length; i += 1) {
|
|
1338
|
+
entries.push(ctx.slots.register(
|
|
1339
|
+
{ name: 'plugins.row.config', key: keys[i], id: 'session-relocate-children-row-' + i, order: 100 },
|
|
1340
|
+
ChildrenSetting,
|
|
1341
|
+
));
|
|
1342
|
+
}
|
|
1343
|
+
return function () {
|
|
1344
|
+
for (var j = 0; j < entries.length; j += 1) {
|
|
1345
|
+
if (typeof entries[j] === 'function') {
|
|
1346
|
+
try { entries[j](); } catch (error) { /* ignore */ }
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
};
|
|
1350
|
+
}));
|
|
1351
|
+
disposers.push(ctx.slots.inject('plugins.bundle.config', function () {
|
|
1352
|
+
return ctx.slots.register(
|
|
1353
|
+
{ name: 'plugins.bundle.config', key: 'dsh-session-relocate', id: 'session-relocate-children-bundle', order: 100 },
|
|
1354
|
+
ChildrenSetting,
|
|
1355
|
+
);
|
|
1356
|
+
}));
|
|
1357
|
+
}
|
|
1358
|
+
disposers.push(ctx.slots.inject('sidebar.workspaces.session.menu.item', function () {
|
|
1359
|
+
var items = [];
|
|
1138
1360
|
// 「多选」入口:dsh-delete-session 支持批量动作时该组件渲染 null(入口交给它那根底栏)。
|
|
1139
|
-
|
|
1361
|
+
items.push(ctx.slots.register(
|
|
1140
1362
|
{ name: 'sidebar.workspaces.session.menu.item', id: 'session-relocate-bulk', order: 351 },
|
|
1141
1363
|
BulkEntry,
|
|
1142
1364
|
));
|
|
1143
|
-
|
|
1365
|
+
items.push(ctx.slots.register(
|
|
1144
1366
|
{ name: 'sidebar.workspaces.session.menu.item', id: 'session-relocate', order: 350 },
|
|
1145
1367
|
Entry,
|
|
1146
1368
|
));
|
|
1147
1369
|
return function () {
|
|
1148
|
-
for (var i = 0; i <
|
|
1149
|
-
if (typeof
|
|
1150
|
-
try {
|
|
1370
|
+
for (var i = 0; i < items.length; i += 1) {
|
|
1371
|
+
if (typeof items[i] === 'function') {
|
|
1372
|
+
try { items[i](); } catch (error) { /* ignore */ }
|
|
1151
1373
|
}
|
|
1152
1374
|
}
|
|
1153
1375
|
};
|
|
1154
|
-
});
|
|
1376
|
+
}));
|
|
1377
|
+
return function () {
|
|
1378
|
+
for (var i = 0; i < disposers.length; i += 1) {
|
|
1379
|
+
if (typeof disposers[i] === 'function') {
|
|
1380
|
+
try { disposers[i](); } catch (error) { /* ignore */ }
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1155
1384
|
}
|
|
1156
1385
|
|
|
1157
1386
|
exports.apply = apply;
|
|
1387
|
+
exports.__ui = { pageIsDark: pageIsDark, themeClass: themeClass };
|
|
1388
|
+
exports.__settings = {
|
|
1389
|
+
ChildrenSetting: ChildrenSetting,
|
|
1390
|
+
wantChildren: wantChildren,
|
|
1391
|
+
setWantChildren: setWantChildren,
|
|
1392
|
+
};
|
|
1158
1393
|
exports.inject = inject;
|
|
1159
1394
|
exports.__entry = Entry;
|
|
1160
1395
|
exports.__bulkEntry = BulkEntry;
|
|
@@ -1163,6 +1398,7 @@ window.__ModuleLoader__.load({
|
|
|
1163
1398
|
moveSelection: moveSelection,
|
|
1164
1399
|
runBulkMove: runBulkMove,
|
|
1165
1400
|
pickBulkTarget: pickBulkTarget,
|
|
1401
|
+
planTargetsWith: planTargetsWith,
|
|
1166
1402
|
hostSupportsBulkMove: hostSupportsBulkMove,
|
|
1167
1403
|
enterBulk: enterBulk,
|
|
1168
1404
|
exitBulk: exitBulk,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-session-relocate",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "跨工作区移动 DSH 对话:把某个 Session 的日志文件与工作区归属整体搬到另一个工作区(可自动注册新工作区)。带日志级崩溃恢复的安全事务,并且会先安全释放「已打开但空闲」的会话 —— 所以正在打开的对话也能直接搬,不需要重启 DSH。",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/plugin.js",
|
package/src/plugin.js
CHANGED
|
@@ -114,6 +114,37 @@ function failure(error) {
|
|
|
114
114
|
return { ok: false, code: 'internal', message: String(error && error.message ? error.message : error) };
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/**
|
|
118
|
+
* 从全部会话快照里找出 rootId 的**所有后代**(按 header.parentSession 递归)。
|
|
119
|
+
* 子代理会话在侧边栏是隐藏的,只能靠 header 关系找;孤儿(父不存在)自然找不到。
|
|
120
|
+
*
|
|
121
|
+
* @param snapshots - `sessionPersistence.list()` 的返回(每项至少带 `header`)。
|
|
122
|
+
* @param rootId - 父会话 id。
|
|
123
|
+
* @returns 后代 id(不含 root),按层序。
|
|
124
|
+
*/
|
|
125
|
+
export function descendantIdsOf(snapshots, rootId) {
|
|
126
|
+
const out = [];
|
|
127
|
+
const seen = new Set([rootId]);
|
|
128
|
+
let frontier = [rootId];
|
|
129
|
+
const all = Array.isArray(snapshots) ? snapshots : [];
|
|
130
|
+
while (frontier.length > 0) {
|
|
131
|
+
const next = [];
|
|
132
|
+
for (const snapshot of all) {
|
|
133
|
+
const header = snapshot !== null && typeof snapshot === 'object' ? snapshot.header : null;
|
|
134
|
+
if (header === null || header === undefined || typeof header !== 'object') continue;
|
|
135
|
+
if (typeof header.parentSession !== 'string' || frontier.indexOf(header.parentSession) < 0) continue;
|
|
136
|
+
// 只认子代理会话(与 DSH 自己 sessionVisible 的过滤一致);分支/分叉是可见会话,不跟着搬。
|
|
137
|
+
if (header.origin !== 'subagent') continue;
|
|
138
|
+
if (typeof header.id !== 'string' || seen.has(header.id)) continue;
|
|
139
|
+
seen.add(header.id);
|
|
140
|
+
out.push(header.id);
|
|
141
|
+
next.push(header.id);
|
|
142
|
+
}
|
|
143
|
+
frontier = next;
|
|
144
|
+
}
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
117
148
|
/**
|
|
118
149
|
* 挂载插件。
|
|
119
150
|
*
|
|
@@ -233,6 +264,21 @@ export function apply(ctx, config) {
|
|
|
233
264
|
async statSession(sessionId) {
|
|
234
265
|
return await ctx.sessionPersistence.stat(sessionId);
|
|
235
266
|
},
|
|
267
|
+
/**
|
|
268
|
+
* 全部会话快照(含隐藏的子代理会话)—— 用来找 `parentSession` 后代。
|
|
269
|
+
* 后端不支持或读失败时返回空数组:父会话照常搬,只是不带子。
|
|
270
|
+
*/
|
|
271
|
+
async listSessions() {
|
|
272
|
+
const persistence = ctx.sessionPersistence;
|
|
273
|
+
if (persistence === undefined || persistence === null || typeof persistence.list !== 'function') return [];
|
|
274
|
+
try {
|
|
275
|
+
const snapshots = await persistence.list();
|
|
276
|
+
return Array.isArray(snapshots) ? snapshots : [];
|
|
277
|
+
} catch (error) {
|
|
278
|
+
log('warn', '列会话失败,按没有子对话继续:' + String(error && error.message));
|
|
279
|
+
return [];
|
|
280
|
+
}
|
|
281
|
+
},
|
|
236
282
|
getWorkspace(workspaceId) {
|
|
237
283
|
return registry.get(workspaceId);
|
|
238
284
|
},
|
|
@@ -611,7 +657,8 @@ export function apply(ctx, config) {
|
|
|
611
657
|
const targetWorkspaceId = typeof body.targetWorkspaceId === 'string' ? body.targetWorkspaceId : '';
|
|
612
658
|
const targetPath = typeof body.targetPath === 'string' ? body.targetPath.trim() : '';
|
|
613
659
|
try {
|
|
614
|
-
const
|
|
660
|
+
const host = buildHost();
|
|
661
|
+
const receipt = await relocateSession(host, store, {
|
|
615
662
|
sessionId,
|
|
616
663
|
targetWorkspaceId,
|
|
617
664
|
targetPath,
|
|
@@ -620,13 +667,63 @@ export function apply(ctx, config) {
|
|
|
620
667
|
// 批量搬移时客户端逐条 defer:文件事务各自做完,注册表最后一次性写。
|
|
621
668
|
deferRegistry: body.deferRegistry === true,
|
|
622
669
|
});
|
|
623
|
-
|
|
670
|
+
// 「连同子对话」默认开;客户端在用户关掉开关时会显式传 false。
|
|
671
|
+
// 子会话走**完整**事务(文件 + 归属),每条失败按条隔离,不拖累父回执。
|
|
672
|
+
let children;
|
|
673
|
+
if (body.includeChildren !== false) {
|
|
674
|
+
const snapshots = await host.listSessions();
|
|
675
|
+
const childIds = descendantIdsOf(snapshots, sessionId);
|
|
676
|
+
if (childIds.length > 0) children = await moveChildren(host, childIds, body);
|
|
677
|
+
}
|
|
678
|
+
return children === undefined ? { ok: true, ...receipt } : { ok: true, ...receipt, children };
|
|
624
679
|
} catch (error) {
|
|
625
680
|
log('warn', '迁移失败:' + String(error && error.message));
|
|
626
681
|
return failure(error);
|
|
627
682
|
}
|
|
628
683
|
}
|
|
629
684
|
|
|
685
|
+
/**
|
|
686
|
+
* 把父会话的全部后代(子代理会话)搬到同一个目标。
|
|
687
|
+
* 每个子会话走完整事务(文件 + 归属);失败按条隔离,父会话的成功回执不受影响。
|
|
688
|
+
*/
|
|
689
|
+
async function moveChildren(host, ids, body) {
|
|
690
|
+
const results = [];
|
|
691
|
+
let moved = 0;
|
|
692
|
+
let failed = 0;
|
|
693
|
+
let skipped = 0;
|
|
694
|
+
for (const id of ids) {
|
|
695
|
+
try {
|
|
696
|
+
await relocateSession(host, store, {
|
|
697
|
+
sessionId: id,
|
|
698
|
+
targetWorkspaceId: body.targetWorkspaceId,
|
|
699
|
+
targetPath: body.targetPath,
|
|
700
|
+
releaseLive,
|
|
701
|
+
moveLive,
|
|
702
|
+
// 子会话不参与两段式:条数少,直接落归属,避免 commit 回执里混进子 id。
|
|
703
|
+
deferRegistry: false,
|
|
704
|
+
});
|
|
705
|
+
moved += 1;
|
|
706
|
+
results.push({ sessionId: id, status: 'moved' });
|
|
707
|
+
} catch (error) {
|
|
708
|
+
if (error !== null && typeof error === 'object' && error.code === 'already-there') {
|
|
709
|
+
skipped += 1;
|
|
710
|
+
results.push({ sessionId: id, status: 'skipped', message: String(error.message) });
|
|
711
|
+
} else {
|
|
712
|
+
failed += 1;
|
|
713
|
+
results.push({
|
|
714
|
+
sessionId: id,
|
|
715
|
+
status: 'failed',
|
|
716
|
+
code: error !== null && typeof error === 'object' && typeof error.code === 'string' ? error.code : 'failed',
|
|
717
|
+
message: String(error !== null && typeof error === 'object' && typeof error.message === 'string'
|
|
718
|
+
? error.message
|
|
719
|
+
: error),
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
return { total: ids.length, moved, failed, skipped, results };
|
|
725
|
+
}
|
|
726
|
+
|
|
630
727
|
/** 批量收尾:把一串 defer 过的迁移的归属一次性写进注册表。 */
|
|
631
728
|
async function moveCommit(body) {
|
|
632
729
|
const ids = Array.isArray(body.sessionIds)
|