@restregular/dsh-powerup 0.8.13 → 0.8.14
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 +18 -0
- package/client.js +184 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -40,6 +40,24 @@ actions. The setting is stored in the browser. It also holds the defaults for
|
|
|
40
40
|
**one-click install** (auto-enable and auto-restart), which the plugin installer
|
|
41
41
|
uses.
|
|
42
42
|
|
|
43
|
+
### Switch sessions from the title
|
|
44
|
+
|
|
45
|
+
Clicking the current conversation title opens a dropdown of the sessions that
|
|
46
|
+
are running, each prefixed with its workspace name; picking one switches the
|
|
47
|
+
conversation. The title is only marked with a `data-*` attribute — React keeps
|
|
48
|
+
owning the crumb — and the dropdown is a body-level fixed panel, so the header's
|
|
49
|
+
drag area and clipping cannot swallow it. The title row is also a window-drag
|
|
50
|
+
region, so a press that moves more than a few pixels is treated as a drag and
|
|
51
|
+
never opens the panel.
|
|
52
|
+
|
|
53
|
+
The panel behaves like the host's own background-jobs popover: it stays open
|
|
54
|
+
while the page keeps changing. Streaming output, new records, a refreshed job
|
|
55
|
+
list or a session starting/stopping only re-render the rows in place. If the
|
|
56
|
+
host replaces the crumb node the panel re-anchors onto the new one instead of
|
|
57
|
+
closing; if the current session changes, the header disappears, or the panel's
|
|
58
|
+
title is clicked again, it closes. `Esc` and a click anywhere outside also
|
|
59
|
+
close it. It is on by default and can be turned off in the Power-Up page.
|
|
60
|
+
|
|
43
61
|
### Stop a background job with a reason
|
|
44
62
|
|
|
45
63
|
The session header's background jobs panel keeps the host's list, live output,
|
package/client.js
CHANGED
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
|
|
70
70
|
const NS = 'dsh-powerup';
|
|
71
71
|
const SETTINGS_KEY = 'dsh-powerup:settings:v1';
|
|
72
|
-
const VERSION = '0.8.
|
|
72
|
+
const VERSION = '0.8.14';
|
|
73
73
|
const MENU_GAP = 8;
|
|
74
74
|
const MENU_WIDTH = 248;
|
|
75
75
|
/** Reference scheme understood by the Host's `powerup_step_read` tool. */
|
|
@@ -2987,17 +2987,24 @@ marker is only present while our button is mounted, and the host's
|
|
|
2987
2987
|
const t = typeof options.t === 'function' ? options.t : (key) => key;
|
|
2988
2988
|
const listRows = typeof options.listRows === 'function' ? options.listRows : () => [];
|
|
2989
2989
|
const openSession = typeof options.openSession === 'function' ? options.openSession : () => false;
|
|
2990
|
+
const currentSessionId = typeof options.currentSessionId === 'function' ? options.currentSessionId : () => undefined;
|
|
2990
2991
|
|
|
2991
2992
|
const MIN_WIDTH = 220;
|
|
2992
2993
|
const PREFERRED_HEIGHT = 320;
|
|
2993
2994
|
const GAP = 6;
|
|
2994
2995
|
const DRAG_THRESHOLD = 6;
|
|
2996
|
+
/** Re-anchor retries before a missing title counts as a view switch. */
|
|
2997
|
+
const REANCHOR_RETRY = 3;
|
|
2998
|
+
const REANCHOR_DELAY = 120;
|
|
2999
|
+
/** How often an open popup re-reads the session list while the host mutates. */
|
|
3000
|
+
const ROWS_REFRESH_MS = 400;
|
|
2995
3001
|
|
|
2996
3002
|
let observer = null;
|
|
2997
3003
|
let marked = [];
|
|
2998
3004
|
let popup = null;
|
|
2999
3005
|
let press = null;
|
|
3000
3006
|
let started = false;
|
|
3007
|
+
let positionQueued = false;
|
|
3001
3008
|
|
|
3002
3009
|
function warn(message, error) {
|
|
3003
3010
|
try {
|
|
@@ -3038,7 +3045,13 @@ marker is only present while our button is mounted, and the host's
|
|
|
3038
3045
|
return out;
|
|
3039
3046
|
}
|
|
3040
3047
|
|
|
3041
|
-
/**
|
|
3048
|
+
/**
|
|
3049
|
+
* Re-apply the marker after React re-renders the crumb. An open popup
|
|
3050
|
+
* must survive unrelated re-renders: React may replace the crumb node
|
|
3051
|
+
* the popup was anchored to (streaming tokens, a new background job, a
|
|
3052
|
+
* status line), which used to look like a view switch. Instead of
|
|
3053
|
+
* closing, re-anchor to the live title and re-place the panel.
|
|
3054
|
+
*/
|
|
3042
3055
|
function sync() {
|
|
3043
3056
|
if (!started || !hasDocument()) return;
|
|
3044
3057
|
const found = findTitles();
|
|
@@ -3048,6 +3061,100 @@ marker is only present while our button is mounted, and the host's
|
|
|
3048
3061
|
if (!el.hasAttribute('data-powerup-session-title')) el.setAttribute('data-powerup-session-title', '');
|
|
3049
3062
|
if (el.getAttribute('title') !== hint) el.setAttribute('title', hint);
|
|
3050
3063
|
}
|
|
3064
|
+
if (popup === null) return;
|
|
3065
|
+
// A mounted title belonging to another session means the view really
|
|
3066
|
+
// switched. An empty list is only a re-render in progress, so it is
|
|
3067
|
+
// left to the retry path below.
|
|
3068
|
+
const owners = found
|
|
3069
|
+
.map((el) => ownerSessionId(el))
|
|
3070
|
+
.filter((id) => typeof id === 'string' && id !== '');
|
|
3071
|
+
if (typeof popup.sessionId === 'string' && popup.sessionId !== ''
|
|
3072
|
+
&& owners.length > 0 && !owners.includes(popup.sessionId)) {
|
|
3073
|
+
closePopup();
|
|
3074
|
+
return;
|
|
3075
|
+
}
|
|
3076
|
+
if (isUsableAnchor(popup.anchor)) {
|
|
3077
|
+
popup.retries = 0;
|
|
3078
|
+
refreshPopupRows();
|
|
3079
|
+
schedulePosition();
|
|
3080
|
+
return;
|
|
3081
|
+
}
|
|
3082
|
+
reanchor(found);
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
/** A title crumb the panel can actually be placed against. */
|
|
3086
|
+
function isUsableAnchor(el) {
|
|
3087
|
+
return el !== null && el !== undefined
|
|
3088
|
+
&& el.isConnected === true
|
|
3089
|
+
&& typeof el.getBoundingClientRect === 'function';
|
|
3090
|
+
}
|
|
3091
|
+
|
|
3092
|
+
/** The conversation header that owns a title crumb. */
|
|
3093
|
+
function ownerHeader(el) {
|
|
3094
|
+
try {
|
|
3095
|
+
return typeof el.closest === 'function' ? el.closest('header[data-window-drag]') : null;
|
|
3096
|
+
} catch {
|
|
3097
|
+
return null;
|
|
3098
|
+
}
|
|
3099
|
+
}
|
|
3100
|
+
|
|
3101
|
+
/** The session id of the conversation subtree that owns a node. */
|
|
3102
|
+
function ownerSessionId(el) {
|
|
3103
|
+
try {
|
|
3104
|
+
const host = typeof el.closest === 'function' ? el.closest('[data-conversation-session]') : null;
|
|
3105
|
+
const id = host === null ? null : host.getAttribute('data-conversation-session');
|
|
3106
|
+
return typeof id === 'string' && id !== '' ? id : undefined;
|
|
3107
|
+
} catch {
|
|
3108
|
+
return undefined;
|
|
3109
|
+
}
|
|
3110
|
+
}
|
|
3111
|
+
|
|
3112
|
+
/**
|
|
3113
|
+
* Move the open popup onto a live title after its anchor was replaced.
|
|
3114
|
+
* A view switch removes every title, so a missing anchor only counts
|
|
3115
|
+
* as a switch once the retries are exhausted; until then the popup
|
|
3116
|
+
* stays open at its last position.
|
|
3117
|
+
*/
|
|
3118
|
+
function reanchor(found) {
|
|
3119
|
+
if (popup === null) return;
|
|
3120
|
+
const target = pickAnchor(found);
|
|
3121
|
+
if (target !== null && target !== popup.anchor) {
|
|
3122
|
+
popup.anchor = target;
|
|
3123
|
+
popup.retries = 0;
|
|
3124
|
+
schedulePosition();
|
|
3125
|
+
return;
|
|
3126
|
+
}
|
|
3127
|
+
if (popup.retries >= REANCHOR_RETRY) {
|
|
3128
|
+
closePopup();
|
|
3129
|
+
return;
|
|
3130
|
+
}
|
|
3131
|
+
popup.retries += 1;
|
|
3132
|
+
scheduleRetry();
|
|
3133
|
+
}
|
|
3134
|
+
|
|
3135
|
+
/** The title to anchor on: the same header's crumb, else the session's. */
|
|
3136
|
+
function pickAnchor(found) {
|
|
3137
|
+
if (!Array.isArray(found) || found.length === 0) return null;
|
|
3138
|
+
const usable = found.filter((el) => isUsableAnchor(el));
|
|
3139
|
+
if (usable.length === 0) return null;
|
|
3140
|
+
if (usable.length === 1) return usable[0];
|
|
3141
|
+
if (popup !== null && popup.header !== null) {
|
|
3142
|
+
const same = usable.filter((el) => ownerHeader(el) === popup.header);
|
|
3143
|
+
if (same.length > 0) return same[0];
|
|
3144
|
+
}
|
|
3145
|
+
if (popup !== null && typeof popup.sessionId === 'string' && popup.sessionId !== '') {
|
|
3146
|
+
for (const el of usable) {
|
|
3147
|
+
if (ownerSessionId(el) === popup.sessionId) return el;
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
return usable[0];
|
|
3151
|
+
}
|
|
3152
|
+
|
|
3153
|
+
function scheduleRetry() {
|
|
3154
|
+
if (!started) return;
|
|
3155
|
+
if (typeof window !== 'undefined' && window !== null && typeof window.setTimeout === 'function') {
|
|
3156
|
+
window.setTimeout(() => { if (started && popup !== null) sync(); }, REANCHOR_DELAY);
|
|
3157
|
+
}
|
|
3051
3158
|
}
|
|
3052
3159
|
|
|
3053
3160
|
function scheduleSync() {
|
|
@@ -3059,6 +3166,45 @@ marker is only present while our button is mounted, and the host's
|
|
|
3059
3166
|
}
|
|
3060
3167
|
}
|
|
3061
3168
|
|
|
3169
|
+
/** Coalesce position updates coming from host re-renders. */
|
|
3170
|
+
function schedulePosition() {
|
|
3171
|
+
if (popup === null || positionQueued) return;
|
|
3172
|
+
positionQueued = true;
|
|
3173
|
+
const run = () => {
|
|
3174
|
+
positionQueued = false;
|
|
3175
|
+
if (popup !== null) positionPopup();
|
|
3176
|
+
};
|
|
3177
|
+
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(run);
|
|
3178
|
+
else run();
|
|
3179
|
+
}
|
|
3180
|
+
|
|
3181
|
+
/** Rows as a stable signature, so unchanged lists cost no DOM work. */
|
|
3182
|
+
function rowsSignature(rows) {
|
|
3183
|
+
return rows.map((row) => `${row.id}\u0000${row.current ? '1' : '0'}\u0000${row.title}`).join('\u0001');
|
|
3184
|
+
}
|
|
3185
|
+
|
|
3186
|
+
/**
|
|
3187
|
+
* Keep the open list current while the host keeps mutating the page:
|
|
3188
|
+
* a session that starts or stops changes the rows, and the popup must
|
|
3189
|
+
* reflect that without being torn down and reopened. Reading the
|
|
3190
|
+
* session snapshot is cheap but not free, so it is throttled.
|
|
3191
|
+
*/
|
|
3192
|
+
function refreshPopupRows() {
|
|
3193
|
+
if (popup === null) return;
|
|
3194
|
+
const now = Date.now();
|
|
3195
|
+
if (popup.rowsAt !== undefined && now - popup.rowsAt < ROWS_REFRESH_MS) return;
|
|
3196
|
+
popup.rowsAt = now;
|
|
3197
|
+
let rows;
|
|
3198
|
+
try {
|
|
3199
|
+
rows = listRows();
|
|
3200
|
+
} catch {
|
|
3201
|
+
return;
|
|
3202
|
+
}
|
|
3203
|
+
if (!Array.isArray(rows)) return;
|
|
3204
|
+
if (popup.signature === rowsSignature(rows)) return;
|
|
3205
|
+
renderPopup();
|
|
3206
|
+
}
|
|
3207
|
+
|
|
3062
3208
|
function onMouseDown(event) {
|
|
3063
3209
|
if (event.button !== 0 || typeof event.target?.closest !== 'function') return;
|
|
3064
3210
|
const anchor = event.target.closest('[data-powerup-session-title]');
|
|
@@ -3068,7 +3214,13 @@ marker is only present while our button is mounted, and the host's
|
|
|
3068
3214
|
function onOutside(event) {
|
|
3069
3215
|
if (popup === null || event.target === null || event.target === undefined) return;
|
|
3070
3216
|
if (typeof popup.element.contains === 'function' && popup.element.contains(event.target)) return;
|
|
3071
|
-
|
|
3217
|
+
// A re-rendered title is still our anchor: let the click handler
|
|
3218
|
+
// decide between closing and switching, never treat it as outside.
|
|
3219
|
+
if (typeof event.target.closest === 'function') {
|
|
3220
|
+
const title = event.target.closest('[data-powerup-session-title]');
|
|
3221
|
+
if (title !== null) return;
|
|
3222
|
+
}
|
|
3223
|
+
if (popup.anchor !== null && typeof popup.anchor.contains === 'function' && popup.anchor.contains(event.target)) return;
|
|
3072
3224
|
closePopup();
|
|
3073
3225
|
}
|
|
3074
3226
|
|
|
@@ -3079,10 +3231,19 @@ marker is only present while our button is mounted, and the host's
|
|
|
3079
3231
|
closePopup();
|
|
3080
3232
|
}
|
|
3081
3233
|
|
|
3234
|
+
/**
|
|
3235
|
+
* Scrolling is not a dismissal: the host scrolls its own content while
|
|
3236
|
+
* a response streams. Keep the panel open and follow the anchor.
|
|
3237
|
+
*/
|
|
3082
3238
|
function onScroll(event) {
|
|
3083
3239
|
if (popup === null || event.target === null || event.target === undefined) return;
|
|
3084
3240
|
if (typeof popup.element.contains === 'function' && popup.element.contains(event.target)) return;
|
|
3085
|
-
|
|
3241
|
+
schedulePosition();
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
function onResize() {
|
|
3245
|
+
if (popup === null) return;
|
|
3246
|
+
schedulePosition();
|
|
3086
3247
|
}
|
|
3087
3248
|
|
|
3088
3249
|
function onClick(event) {
|
|
@@ -3098,7 +3259,8 @@ marker is only present while our button is mounted, and the host's
|
|
|
3098
3259
|
&& Math.abs(event.clientX - press.x) + Math.abs(event.clientY - press.y) > DRAG_THRESHOLD) return;
|
|
3099
3260
|
event.preventDefault();
|
|
3100
3261
|
event.stopPropagation();
|
|
3101
|
-
|
|
3262
|
+
// The title is the toggle: a second click closes, never reopens.
|
|
3263
|
+
if (popup !== null) {
|
|
3102
3264
|
closePopup();
|
|
3103
3265
|
return;
|
|
3104
3266
|
}
|
|
@@ -3109,7 +3271,9 @@ marker is only present while our button is mounted, and the host's
|
|
|
3109
3271
|
if (popup === null || typeof window === 'undefined' || window === null) return;
|
|
3110
3272
|
const anchor = popup.anchor;
|
|
3111
3273
|
if (anchor === null || anchor.isConnected !== true || typeof anchor.getBoundingClientRect !== 'function') {
|
|
3112
|
-
|
|
3274
|
+
// Leave the panel where it is and let sync() re-anchor it; that
|
|
3275
|
+
// path also owns the "the view really switched" close decision.
|
|
3276
|
+
scheduleSync();
|
|
3113
3277
|
return;
|
|
3114
3278
|
}
|
|
3115
3279
|
const rect = anchor.getBoundingClientRect();
|
|
@@ -3135,6 +3299,7 @@ marker is only present while our button is mounted, and the host's
|
|
|
3135
3299
|
if (popup === null) return;
|
|
3136
3300
|
const rows = listRows();
|
|
3137
3301
|
popup.rows = rows;
|
|
3302
|
+
popup.signature = rowsSignature(rows);
|
|
3138
3303
|
const element = popup.element;
|
|
3139
3304
|
element.textContent = '';
|
|
3140
3305
|
const head = document.createElement('div');
|
|
@@ -3190,7 +3355,13 @@ marker is only present while our button is mounted, and the host's
|
|
|
3190
3355
|
element.setAttribute('role', 'dialog');
|
|
3191
3356
|
element.setAttribute('data-powerup-session-pop', '');
|
|
3192
3357
|
document.body.appendChild(element);
|
|
3193
|
-
|
|
3358
|
+
let openedSessionId;
|
|
3359
|
+
try {
|
|
3360
|
+
openedSessionId = currentSessionId();
|
|
3361
|
+
} catch {
|
|
3362
|
+
openedSessionId = undefined;
|
|
3363
|
+
}
|
|
3364
|
+
popup = { element, anchor, rows: [], retries: 0, sessionId: openedSessionId, header: ownerHeader(anchor) };
|
|
3194
3365
|
renderPopup();
|
|
3195
3366
|
const reveal = () => {
|
|
3196
3367
|
if (popup !== null && popup.element === element) element.classList.add('is-open');
|
|
@@ -3200,7 +3371,7 @@ marker is only present while our button is mounted, and the host's
|
|
|
3200
3371
|
document.addEventListener('pointerdown', onOutside, true);
|
|
3201
3372
|
document.addEventListener('keydown', onKey, true);
|
|
3202
3373
|
if (typeof window !== 'undefined' && window !== null) {
|
|
3203
|
-
window.addEventListener('resize',
|
|
3374
|
+
window.addEventListener('resize', onResize, true);
|
|
3204
3375
|
window.addEventListener('scroll', onScroll, true);
|
|
3205
3376
|
}
|
|
3206
3377
|
}
|
|
@@ -3209,10 +3380,11 @@ marker is only present while our button is mounted, and the host's
|
|
|
3209
3380
|
if (popup === null) return;
|
|
3210
3381
|
const element = popup.element;
|
|
3211
3382
|
popup = null;
|
|
3383
|
+
positionQueued = false;
|
|
3212
3384
|
document.removeEventListener('pointerdown', onOutside, true);
|
|
3213
3385
|
document.removeEventListener('keydown', onKey, true);
|
|
3214
3386
|
if (typeof window !== 'undefined' && window !== null) {
|
|
3215
|
-
window.removeEventListener('resize',
|
|
3387
|
+
window.removeEventListener('resize', onResize, true);
|
|
3216
3388
|
window.removeEventListener('scroll', onScroll, true);
|
|
3217
3389
|
}
|
|
3218
3390
|
element.classList.remove('is-open');
|
|
@@ -3226,7 +3398,8 @@ marker is only present while our button is mounted, and the host's
|
|
|
3226
3398
|
document.addEventListener('click', onClick, true);
|
|
3227
3399
|
if (typeof MutationObserver === 'function') {
|
|
3228
3400
|
observer = new MutationObserver(() => {
|
|
3229
|
-
|
|
3401
|
+
// Host re-renders are not view switches: keep an open popup and
|
|
3402
|
+
// let sync() re-anchor it onto the live title.
|
|
3230
3403
|
scheduleSync();
|
|
3231
3404
|
});
|
|
3232
3405
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
@@ -3315,6 +3488,7 @@ marker is only present while our button is mounted, and the host's
|
|
|
3315
3488
|
};
|
|
3316
3489
|
const core = createSessionSwitcherCore({
|
|
3317
3490
|
t: (key, params) => translateCurrent(key, params),
|
|
3491
|
+
currentSessionId,
|
|
3318
3492
|
listRows: () => {
|
|
3319
3493
|
try {
|
|
3320
3494
|
const sessions = ctx.get('sessions');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.14",
|
|
4
4
|
"description": "Power-Up — small, opt-in upgrades for DeepSeek Harness. Adds a right-click action menu to the Trajectory ledger, an optional stop reason in the session header's background jobs panel (appended to the injected completion notice), and an install control for third-party plugins from the Plugins page: read versions from the configured registries, install the version in the input through the Add plugin path (removing the old copy first), mark restart-needed installs, hand Power-Up's own install to the background, and optionally restart DSH. One-click install skips the enable and restart questions and can apply those actions automatically with configurable defaults. The ledger menu also copies a step reference (session id + step id) that the read-only powerup_step_read tool resolves back into the raw session data. · 为 DeepSeek Harness 提供小型增强:在轨迹页面右键记录即可复制、引用、查看详情或从该记录 Fork;右键「复制步骤引用」得到「会话 ID + 步骤 ID」,Agent 用只读工具 powerup_step_read 即可取回该步骤的完整原始数据;在会话顶部的后台任务面板手动停止任务时可填写停止原因,原因会附加到任务结束后的会话提示;并在插件页为第三方已安装插件提供安装按钮,从安装源读取版本,按输入框中的版本沿用「添加插件」流程安装(先卸载旧版),支持待重启标记、Power-Up 自身后台安装与可选重启;安装面板提供「一键安装」,按输入框版本安装并跳过启用/重启询问,默认自动启用并重启,可在 Power-Up 页面调整默认行为。 · 侧边栏启动器:把左侧边栏的面板按钮变成随宽度自适应的图标网格(图标在上、文字在下),支持拖拽排序与分组(拖到另一个图标中间即合并为分组,点击分组弹出浮层展示内部图标),可随时整体关闭;网格里自带「返回会话」「重启 DSH」「关闭 DSH」三个按钮,它们和「更多」一样可以拖进分组,重启/关闭沿用插件安装流程的确认对话框。 · 会话切换:把会话标题变成可点击,点击后弹出下拉列表,列出正在运行中的会话标题(带工作区名称前缀),点击即可切换到对应会话。 · 定位当前会话:工作区按钮栏新增按钮,把当前会话在工作区列表中展开并居中显示,自动展开折叠的工作区。 · 所有功能均可在 Power-Up 页面独立启用/禁用,弹窗统一为宿主原生样式。",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|