@restregular/dsh-powerup 0.19.15 → 0.19.17
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 +30 -1
- package/client.js +258 -146
- package/index.js +41 -1
- package/lib/system-theme.js +72 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -577,10 +577,39 @@ returned as the cleanup), so a toggle cannot leave stale registrations behind.
|
|
|
577
577
|
|
|
578
578
|
## Development
|
|
579
579
|
|
|
580
|
+
The client source lives in `src/`, one module per feature; the shipped
|
|
581
|
+
`client.js` is generated by concatenating those modules into a single classic
|
|
582
|
+
script (the host merges every client bundle into one script realm, so the
|
|
583
|
+
artifact must stay self-contained).
|
|
584
|
+
|
|
580
585
|
```bash
|
|
581
|
-
|
|
586
|
+
node scripts/build.mjs # concatenate src/ -> client.js
|
|
587
|
+
node scripts/build.mjs --check # fail when client.js is stale (runs before tests)
|
|
588
|
+
pnpm test # build check + full test suite
|
|
582
589
|
```
|
|
583
590
|
|
|
591
|
+
### Source layout
|
|
592
|
+
|
|
593
|
+
| Path | Contents |
|
|
594
|
+
|---|---|
|
|
595
|
+
| `src/prelude/` | IIFE wrapper, runtime shims, plugin constants, module exports |
|
|
596
|
+
| `src/i18n/` | zh/en dictionaries and translator wiring |
|
|
597
|
+
| `src/stores/` | settings, workspace prompts, mask rules (cache + subscription) |
|
|
598
|
+
| `src/features/<name>/` | one directory per feature (launcher, context-menu, progress, quick-replies, plugin-update, direct-ask, ...) |
|
|
599
|
+
| `src/ui/` | shared icons, styles, toast, popover placement, markdown renderer, Power-Up page |
|
|
600
|
+
| `src/core/` | cross-feature installers (style injection) |
|
|
601
|
+
| `src/apply.js` | `PREINSTALL` steps + the `REGISTRY` table that registers every host slot |
|
|
602
|
+
|
|
603
|
+
### Adding a feature
|
|
604
|
+
|
|
605
|
+
1. Create `src/features/<name>/` with the feature's code (it shares the
|
|
606
|
+
factory scope — do not redeclare existing top-level names).
|
|
607
|
+
2. Add one entry to `REGISTRY` in `src/apply.js` (slot, options, component,
|
|
608
|
+
label; use `inject` for services that may arrive late).
|
|
609
|
+
3. Add styles to `src/styles/10-css.js`, dictionary keys to `src/i18n/10-dict.js`,
|
|
610
|
+
and exports used by tests to `src/prelude/90-exports.js`.
|
|
611
|
+
4. `node scripts/build.mjs && pnpm test`.
|
|
612
|
+
|
|
584
613
|
`node test/smoke.mjs` loads the real Client module with React/browser doubles,
|
|
585
614
|
applies it to a fake slot context, and checks registrations, icons, helpers,
|
|
586
615
|
theme tokens, the step-reference copy path, the stop-reason mapping, the Host
|
package/client.js
CHANGED
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
const requirementCreateDraft = { workspaceId: null, title: '', text: '', scope: 'current' };
|
|
99
99
|
/** Fallback bucket when the hero cannot resolve an owning workspace yet. */
|
|
100
100
|
const UNSCOPED_WORKSPACE = '__unscoped__';
|
|
101
|
-
const VERSION = '0.19.
|
|
101
|
+
const VERSION = '0.19.17';
|
|
102
102
|
const MENU_GAP = 8;
|
|
103
103
|
const MENU_WIDTH = 248;
|
|
104
104
|
/** Reference scheme understood by the Host's `powerup_step_read` tool. */
|
|
@@ -143,6 +143,10 @@
|
|
|
143
143
|
'page.themeBrief': '在侧边栏点一下图标,在亮色与暗色之间切换。',
|
|
144
144
|
'page.themeDesc': '在左侧边栏的品牌行加入一个主题切换按钮:点击即在亮色和暗色之间切换,图标随当前配色显示(暗色显示太阳,亮色显示月亮)。主题偏好交给 DSH 自身的主题服务保存,与系统设置里的「外观」保持一致。',
|
|
145
145
|
'page.themeHow': '启用本功能后,左侧边栏顶部品牌名旁会出现一个太阳/月亮图标,点击即可切换亮暗模式;关闭本功能后按钮消失,主题设置仍由 DSH 管理。',
|
|
146
|
+
'page.themeSystemLabel': '同时切换操作系统主题',
|
|
147
|
+
'page.themeSystemHint': '开启后点击按钮会连同 Windows 的系统亮暗模式一起切换;仅 Windows 桌面版生效,其余环境仅切换 DSH 主题。',
|
|
148
|
+
'theme.osApplied': '已同时切换系统主题',
|
|
149
|
+
'theme.osFailed': '系统主题切换失败,仅切换了 DSH 主题',
|
|
146
150
|
'theme.toLight': '切换到亮色模式',
|
|
147
151
|
'theme.toDark': '切换到暗色模式',
|
|
148
152
|
'page.actions': '可用操作',
|
|
@@ -579,6 +583,10 @@
|
|
|
579
583
|
'page.themeBrief': 'Toggle light and dark mode from a sidebar button.',
|
|
580
584
|
'page.themeDesc': 'Adds a theme toggle button to the sidebar brand row: one click flips between light and dark, with the icon following the active palette (sun in dark mode, moon in light mode). The preference is persisted by DSH\'s own theme service, in sync with the Appearance setting.',
|
|
581
585
|
'page.themeHow': 'Once enabled, a sun/moon icon appears next to the brand name at the top of the left sidebar; click it to switch palettes. Turning the feature off removes the button; theme preferences remain managed by DSH.',
|
|
586
|
+
'page.themeSystemLabel': 'Also switch the operating system theme',
|
|
587
|
+
'page.themeSystemHint': 'When on, clicking the button also flips the Windows system light/dark mode; Windows desktop only, other environments still switch the DSH theme.',
|
|
588
|
+
'theme.osApplied': 'System theme switched too',
|
|
589
|
+
'theme.osFailed': 'Could not switch the system theme; only the DSH theme changed',
|
|
582
590
|
'theme.toLight': 'Switch to light mode',
|
|
583
591
|
'theme.toDark': 'Switch to dark mode',
|
|
584
592
|
'page.actions': 'What you can do',
|
|
@@ -1020,6 +1028,7 @@
|
|
|
1020
1028
|
locateSession: true,
|
|
1021
1029
|
scrollToTop: true,
|
|
1022
1030
|
themeToggle: true,
|
|
1031
|
+
themeToggleSystem: false,
|
|
1023
1032
|
contentRendering: true,
|
|
1024
1033
|
dualSend: false,
|
|
1025
1034
|
workspacePrompts: true,
|
|
@@ -1048,6 +1057,7 @@
|
|
|
1048
1057
|
locateSession: parsed.locateSession !== false,
|
|
1049
1058
|
scrollToTop: parsed.scrollToTop !== false,
|
|
1050
1059
|
themeToggle: parsed.themeToggle !== false,
|
|
1060
|
+
themeToggleSystem: parsed.themeToggleSystem === true,
|
|
1051
1061
|
contentRendering: parsed.contentRendering !== false,
|
|
1052
1062
|
dualSend: parsed.dualSend === true,
|
|
1053
1063
|
workspacePrompts: parsed.workspacePrompts !== false,
|
|
@@ -5978,6 +5988,30 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
5978
5988
|
return core;
|
|
5979
5989
|
}
|
|
5980
5990
|
|
|
5991
|
+
/**
|
|
5992
|
+
* Standalone toast for installers outside the React tree (e.g. the theme
|
|
5993
|
+
* toggle). Reuses the overlay's toast class so it looks native.
|
|
5994
|
+
*/
|
|
5995
|
+
let standaloneToast = null;
|
|
5996
|
+
function toastMessage(message) {
|
|
5997
|
+
if (typeof message !== 'string' || message === '' || !hasDocumentSafe()) return;
|
|
5998
|
+
if (standaloneToast !== null) standaloneToast.remove();
|
|
5999
|
+
const node = document.createElement('div');
|
|
6000
|
+
node.className = 'dsh-powerup-toast';
|
|
6001
|
+
node.setAttribute('role', 'status');
|
|
6002
|
+
node.textContent = message;
|
|
6003
|
+
document.body.appendChild(node);
|
|
6004
|
+
standaloneToast = node;
|
|
6005
|
+
setTimeout(() => {
|
|
6006
|
+
if (standaloneToast === node) standaloneToast = null;
|
|
6007
|
+
node.remove();
|
|
6008
|
+
}, 2400);
|
|
6009
|
+
}
|
|
6010
|
+
|
|
6011
|
+
function hasDocumentSafe() {
|
|
6012
|
+
return typeof document !== 'undefined' && document !== null && document.body !== null;
|
|
6013
|
+
}
|
|
6014
|
+
|
|
5981
6015
|
/**
|
|
5982
6016
|
* DOM controller for a theme toggle button in the sidebar brand row (the
|
|
5983
6017
|
* logoRow that also holds the collapsed-rail toggle). It reads the theme
|
|
@@ -5985,7 +6019,9 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
5985
6019
|
* showing a sun glyph in dark mode (click to go light) and a moon glyph in
|
|
5986
6020
|
* light mode (click to go dark). Falls back to `prefers-color-scheme` via
|
|
5987
6021
|
* the active theme's colorScheme when the preference is `system`.
|
|
5988
|
-
*
|
|
6022
|
+
* When `applySystem` is enabled, the click also asks the Host to flip the
|
|
6023
|
+
* operating system's light/dark mode and lets DSH follow the system.
|
|
6024
|
+
* @param {{getTheme?: Function, setTheme?: Function, t?: Function, isEnabled?: Function, applySystem?: Function, notify?: Function}} deps
|
|
5989
6025
|
*/
|
|
5990
6026
|
function createThemeToggleCore(deps) {
|
|
5991
6027
|
const options = deps ?? {};
|
|
@@ -5993,6 +6029,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
5993
6029
|
const setTheme = typeof options.setTheme === 'function' ? options.setTheme : () => {};
|
|
5994
6030
|
const t = typeof options.t === 'function' ? options.t : (key) => key;
|
|
5995
6031
|
const isEnabled = typeof options.isEnabled === 'function' ? options.isEnabled : () => true;
|
|
6032
|
+
const applySystem = typeof options.applySystem === 'function' ? options.applySystem : () => Promise.resolve({ ok: false });
|
|
6033
|
+
const notify = typeof options.notify === 'function' ? options.notify : () => {};
|
|
5996
6034
|
|
|
5997
6035
|
let button = null;
|
|
5998
6036
|
let observer = null;
|
|
@@ -6057,7 +6095,24 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
6057
6095
|
button.addEventListener('click', (event) => {
|
|
6058
6096
|
event.preventDefault();
|
|
6059
6097
|
event.stopPropagation();
|
|
6060
|
-
|
|
6098
|
+
const next = isDark() ? 'light' : 'dark';
|
|
6099
|
+
if (getSettings().themeToggleSystem === true) {
|
|
6100
|
+
void applySystem(next).then((result) => {
|
|
6101
|
+
if (result?.ok === true) {
|
|
6102
|
+
// Host switched the OS theme; let DSH follow the system so both
|
|
6103
|
+
// palettes stay in sync.
|
|
6104
|
+
setTheme('system');
|
|
6105
|
+
} else {
|
|
6106
|
+
setTheme(next);
|
|
6107
|
+
notify(t('theme.osFailed'));
|
|
6108
|
+
}
|
|
6109
|
+
}).catch(() => {
|
|
6110
|
+
setTheme(next);
|
|
6111
|
+
notify(t('theme.osFailed'));
|
|
6112
|
+
});
|
|
6113
|
+
} else {
|
|
6114
|
+
setTheme(next);
|
|
6115
|
+
}
|
|
6061
6116
|
refresh();
|
|
6062
6117
|
});
|
|
6063
6118
|
refresh();
|
|
@@ -6114,6 +6169,16 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
6114
6169
|
setTheme: (id) => {
|
|
6115
6170
|
try { if (typeof theme.setTheme === 'function') theme.setTheme(id); } catch { /* ignore */ }
|
|
6116
6171
|
},
|
|
6172
|
+
notify: toastMessage,
|
|
6173
|
+
applySystem: (id) => {
|
|
6174
|
+
const scheme = id === 'dark' ? 'dark' : 'light';
|
|
6175
|
+
return fetch('/dsh-powerup/api/system-theme', {
|
|
6176
|
+
method: 'POST',
|
|
6177
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
6178
|
+
body: JSON.stringify({ scheme }),
|
|
6179
|
+
}).then((response) => response.json().catch(() => ({ ok: false })))
|
|
6180
|
+
.then((data) => ({ ok: data?.ok === true, supported: data?.supported === true }));
|
|
6181
|
+
},
|
|
6117
6182
|
});
|
|
6118
6183
|
scope.effect(() => {
|
|
6119
6184
|
core.start();
|
|
@@ -11337,6 +11402,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
11337
11402
|
featureCard('themeToggle', QuickIcon, 'page.themeTitle', 'page.themeBrief', {
|
|
11338
11403
|
descKey: 'page.themeDesc',
|
|
11339
11404
|
howKey: 'page.themeHow',
|
|
11405
|
+
detail: settingRow('themeToggleSystem', settings.themeToggleSystem === true,
|
|
11406
|
+
t('page.themeSystemLabel'), t('page.themeSystemHint')),
|
|
11340
11407
|
}),
|
|
11341
11408
|
featureCard('launcher', LauncherIcon, 'page.launcherTitle', 'page.launcherBrief', {
|
|
11342
11409
|
descKey: 'page.launcherDesc',
|
|
@@ -12497,171 +12564,216 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
12497
12564
|
}
|
|
12498
12565
|
|
|
12499
12566
|
// ------------------------------------------------------------------
|
|
12500
|
-
// Plugin body
|
|
12567
|
+
// Plugin body: one registry drives every slot registration.
|
|
12568
|
+
//
|
|
12569
|
+
// To add a feature: create src/features/<name>/, then add ONE entry to
|
|
12570
|
+
// REGISTRY below (plus its exports in prelude/90-exports.js when tests
|
|
12571
|
+
// need them). Registration order in REGISTRY is also install order.
|
|
12501
12572
|
// ------------------------------------------------------------------
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12573
|
+
/** Install steps that run before any slot registration. */
|
|
12574
|
+
const PREINSTALL = [
|
|
12575
|
+
{ label: 'dsh-powerup: client context', run(ctx) {
|
|
12576
|
+
ctxRef.current = ctx;
|
|
12577
|
+
ctx.effect(() => () => {
|
|
12578
|
+
if (ctxRef.current === ctx) ctxRef.current = null;
|
|
12579
|
+
}, 'dsh-powerup: client context');
|
|
12580
|
+
} },
|
|
12581
|
+
{ label: 'dsh-powerup: locale', run: bindLocale },
|
|
12582
|
+
{ label: 'dsh-powerup: styles', run: installStyles },
|
|
12509
12583
|
// Align the Host tool/prompt registration with this browser's switch on load.
|
|
12510
|
-
syncQuickRepliesEnabled(settingsValue.quickReplies)
|
|
12511
|
-
installLauncher
|
|
12512
|
-
installSessionSwitcher
|
|
12513
|
-
installLocateSession
|
|
12514
|
-
installScrollToTop
|
|
12515
|
-
installThemeToggle
|
|
12516
|
-
installReplyMask
|
|
12517
|
-
|
|
12518
|
-
const slots = ctx.get('slots');
|
|
12519
|
-
if (slots === undefined || typeof slots.inject !== 'function' || typeof slots.register !== 'function') {
|
|
12520
|
-
console.warn('[dsh-powerup] slots service missing; Power-Up UI disabled');
|
|
12521
|
-
return;
|
|
12522
|
-
}
|
|
12523
|
-
|
|
12524
|
-
const register = (slot, options, component, label) => {
|
|
12525
|
-
try {
|
|
12526
|
-
ctx.effect(
|
|
12527
|
-
() => slots.inject(slot, () => slots.register({ name: slot, ...options }, component)),
|
|
12528
|
-
label,
|
|
12529
|
-
);
|
|
12530
|
-
} catch (error) {
|
|
12531
|
-
console.warn(`[dsh-powerup] could not register ${slot}:`, error?.message ?? error);
|
|
12532
|
-
}
|
|
12533
|
-
};
|
|
12534
|
-
|
|
12535
|
-
register('sidebar.panellist', {
|
|
12536
|
-
id: 'powerup',
|
|
12537
|
-
order: 30,
|
|
12538
|
-
label: () => translateCurrent('panel.title'),
|
|
12539
|
-
}, (props) => h(PowerUpLineIcon, { size: props?.size ?? 16 }), 'dsh-powerup: sidebar entry');
|
|
12540
|
-
|
|
12541
|
-
register('main', { key: 'powerup' }, () => h(PowerUpPage, { ctx }), 'dsh-powerup: main page');
|
|
12542
|
-
|
|
12543
|
-
register('shell.overlay', {
|
|
12544
|
-
id: 'powerup-context-menu',
|
|
12545
|
-
order: 55,
|
|
12546
|
-
}, () => h(PowerUpOverlay, { ctx }), 'dsh-powerup: context menu');
|
|
12547
|
-
|
|
12548
|
-
register('conversation.session.header.utilities', {
|
|
12549
|
-
id: 'powerup-bridge',
|
|
12550
|
-
order: 50,
|
|
12551
|
-
}, PowerUpBridge, 'dsh-powerup: session bridge');
|
|
12552
|
-
|
|
12553
|
-
register('conversation.session.header.utilities', {
|
|
12554
|
-
id: 'powerup-progress',
|
|
12555
|
-
order: 52,
|
|
12556
|
-
}, (props) => h(ProgressControl, {
|
|
12557
|
-
sessionId: props?.sessionId,
|
|
12558
|
-
// The header utilities slot provides useWorkspaces as a standard
|
|
12559
|
-
// scoped hook; forward it so the requirement modal can resolve the
|
|
12560
|
-
// owning workspace (ctx.get('workspaces').list is Host-only).
|
|
12561
|
-
useWorkspaces: props?.useWorkspaces,
|
|
12562
|
-
// DSH 0.2.3 standard hooks, forwarded to the host ModelSelect we
|
|
12563
|
-
// render inside the panel. Without them the slot entry crashes and
|
|
12564
|
-
// this very button disappears once the panel is opened.
|
|
12565
|
-
useMobile: props?.useMobile,
|
|
12566
|
-
useDocumentPortal: props?.useDocumentPortal,
|
|
12567
|
-
}), 'dsh-powerup: task progress');
|
|
12568
|
-
|
|
12569
|
-
register('conversation.hero.options', {
|
|
12570
|
-
id: 'powerup-prompts',
|
|
12571
|
-
order: 60,
|
|
12572
|
-
}, HeroPromptsControl, 'dsh-powerup: prompt picker');
|
|
12584
|
+
{ label: 'dsh-powerup: quick replies sync', run: () => syncQuickRepliesEnabled(settingsValue.quickReplies) },
|
|
12585
|
+
{ label: 'dsh-powerup: launcher', run: installLauncher },
|
|
12586
|
+
{ label: 'dsh-powerup: session switcher', run: installSessionSwitcher },
|
|
12587
|
+
{ label: 'dsh-powerup: locate session', run: installLocateSession },
|
|
12588
|
+
{ label: 'dsh-powerup: scroll to top', run: installScrollToTop },
|
|
12589
|
+
{ label: 'dsh-powerup: theme toggle', run: installThemeToggle },
|
|
12590
|
+
{ label: 'dsh-powerup: reply mask', run: installReplyMask },
|
|
12591
|
+
];
|
|
12573
12592
|
|
|
12593
|
+
/**
|
|
12594
|
+
* Every slot Power-Up registers, in one table. Shape:
|
|
12595
|
+
* slot — the host slot name
|
|
12596
|
+
* options — the entry options (id/order/label/key)
|
|
12597
|
+
* component — React component receiving (props) or a factory (ctx)
|
|
12598
|
+
* label — effect label used in logs and disposal
|
|
12599
|
+
* inject — optional nested-inject service(s); the entry mounts in a
|
|
12600
|
+
* child scope that observes the service instead of the
|
|
12601
|
+
* root scope, so a late-provided service still registers.
|
|
12602
|
+
* forward — optional list of standard slot props (useWorkspaces,
|
|
12603
|
+
* useMobile, useDocumentPortal) to pass through explicitly.
|
|
12604
|
+
*/
|
|
12605
|
+
const REGISTRY = [
|
|
12606
|
+
{
|
|
12607
|
+
slot: 'sidebar.panellist',
|
|
12608
|
+
options: { id: 'powerup', order: 30, label: () => translateCurrent('panel.title') },
|
|
12609
|
+
component: (props) => h(PowerUpLineIcon, { size: props?.size ?? 16 }),
|
|
12610
|
+
label: 'dsh-powerup: sidebar entry',
|
|
12611
|
+
},
|
|
12612
|
+
{
|
|
12613
|
+
slot: 'main',
|
|
12614
|
+
options: { key: 'powerup' },
|
|
12615
|
+
component: () => h(PowerUpPage, { ctx }),
|
|
12616
|
+
label: 'dsh-powerup: main page',
|
|
12617
|
+
},
|
|
12618
|
+
{
|
|
12619
|
+
slot: 'shell.overlay',
|
|
12620
|
+
options: { id: 'powerup-context-menu', order: 55 },
|
|
12621
|
+
component: () => h(PowerUpOverlay, { ctx }),
|
|
12622
|
+
label: 'dsh-powerup: context menu',
|
|
12623
|
+
},
|
|
12624
|
+
{
|
|
12625
|
+
slot: 'conversation.session.header.utilities',
|
|
12626
|
+
options: { id: 'powerup-bridge', order: 50 },
|
|
12627
|
+
component: PowerUpBridge,
|
|
12628
|
+
label: 'dsh-powerup: session bridge',
|
|
12629
|
+
},
|
|
12630
|
+
{
|
|
12631
|
+
slot: 'conversation.session.header.utilities',
|
|
12632
|
+
options: { id: 'powerup-progress', order: 52 },
|
|
12633
|
+
component: (props) => h(ProgressControl, {
|
|
12634
|
+
sessionId: props?.sessionId,
|
|
12635
|
+
// The header utilities slot provides useWorkspaces as a standard
|
|
12636
|
+
// scoped hook; forward it so the requirement modal can resolve the
|
|
12637
|
+
// owning workspace (ctx.get('workspaces').list is Host-only).
|
|
12638
|
+
useWorkspaces: props?.useWorkspaces,
|
|
12639
|
+
// DSH 0.2.3 standard hooks, forwarded to the host ModelSelect we
|
|
12640
|
+
// render inside the panel. Without them the slot entry crashes and
|
|
12641
|
+
// this very button disappears once the panel is opened.
|
|
12642
|
+
useMobile: props?.useMobile,
|
|
12643
|
+
useDocumentPortal: props?.useDocumentPortal,
|
|
12644
|
+
}),
|
|
12645
|
+
label: 'dsh-powerup: task progress',
|
|
12646
|
+
},
|
|
12647
|
+
{
|
|
12648
|
+
slot: 'conversation.hero.options',
|
|
12649
|
+
options: { id: 'powerup-prompts', order: 60 },
|
|
12650
|
+
component: HeroPromptsControl,
|
|
12651
|
+
label: 'dsh-powerup: prompt picker',
|
|
12652
|
+
},
|
|
12574
12653
|
// Session-scope composer controls. These receive sessionId/useInput/
|
|
12575
12654
|
// inputActions from the host's conversation slot wiring; the t() locale
|
|
12576
12655
|
// seat is provided by the slot, so we wrap to use the plugin dictionary.
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
order: 80,
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12598
|
-
|
|
12599
|
-
|
|
12600
|
-
|
|
12601
|
-
|
|
12602
|
-
|
|
12603
|
-
|
|
12656
|
+
{
|
|
12657
|
+
slot: 'conversation.input.right',
|
|
12658
|
+
options: { id: 'powerup-dual-send', order: 80 },
|
|
12659
|
+
component: (props) => h(DualSendButtons, {
|
|
12660
|
+
...props,
|
|
12661
|
+
ctx,
|
|
12662
|
+
t: (key, params) => translateCurrent(key, params),
|
|
12663
|
+
}),
|
|
12664
|
+
label: 'dsh-powerup: dual send buttons',
|
|
12665
|
+
},
|
|
12666
|
+
{
|
|
12667
|
+
slot: 'conversation.input.right',
|
|
12668
|
+
options: { id: 'powerup-direct-ask', order: 82 },
|
|
12669
|
+
component: (props) => h(DirectAskButton, {
|
|
12670
|
+
...props,
|
|
12671
|
+
ctx,
|
|
12672
|
+
t: (key, params) => translateCurrent(key, params),
|
|
12673
|
+
}),
|
|
12674
|
+
label: 'dsh-powerup: direct ask',
|
|
12675
|
+
},
|
|
12676
|
+
{
|
|
12677
|
+
slot: 'conversation.input.right',
|
|
12678
|
+
options: { id: 'powerup-quick-replies', order: 84 },
|
|
12679
|
+
component: (props) => h(QuickReplies, {
|
|
12680
|
+
...props,
|
|
12681
|
+
ctx,
|
|
12682
|
+
t: (key, params) => translateCurrent(key, params),
|
|
12683
|
+
}),
|
|
12684
|
+
label: 'dsh-powerup: quick replies',
|
|
12685
|
+
},
|
|
12604
12686
|
// In an ongoing session, place the prompt picker in the bottom tool row
|
|
12605
12687
|
// just after the host's permission / plan dropdowns; its popover opens
|
|
12606
12688
|
// upward so it is not clipped by the screen bottom.
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
order: 10,
|
|
12610
|
-
|
|
12611
|
-
|
|
12689
|
+
{
|
|
12690
|
+
slot: 'conversation.input.left',
|
|
12691
|
+
options: { id: 'powerup-prompts-composer', order: 10 },
|
|
12692
|
+
component: ComposerPromptsControl,
|
|
12693
|
+
label: 'dsh-powerup: composer prompt picker',
|
|
12694
|
+
},
|
|
12612
12695
|
// Per-workspace Power-Up settings as a Conversation View tab, ordered
|
|
12613
12696
|
// after the host's Trajectory view (order 10).
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
order: 20,
|
|
12617
|
-
|
|
12618
|
-
|
|
12619
|
-
|
|
12697
|
+
{
|
|
12698
|
+
slot: 'conversation.view',
|
|
12699
|
+
options: { id: 'powerup-settings', order: 20, label: () => translateCurrent('mask.viewTabLabel') },
|
|
12700
|
+
component: (props) => h(WorkspaceSettingsView, { ...props, ctx }),
|
|
12701
|
+
label: 'dsh-powerup: workspace settings view',
|
|
12702
|
+
},
|
|
12620
12703
|
// The update control drives the built-in plugin manager through its
|
|
12621
12704
|
// `remote.pluginManager` namespace. Register it in a nested inject scope
|
|
12622
12705
|
// so a late-provided service is observed instead of sampled once.
|
|
12623
|
-
|
|
12706
|
+
{
|
|
12707
|
+
slot: 'shell.overlay',
|
|
12708
|
+
options: { id: 'powerup-plugin-update', order: 56 },
|
|
12709
|
+
component: (scope) => h(PluginUpdateOverlay, { manager: scope.get('remote.pluginManager'), remote: scope.get('remote'), ctx: scope }),
|
|
12710
|
+
label: 'dsh-powerup: plugin update',
|
|
12711
|
+
inject: ['remote.pluginManager'],
|
|
12712
|
+
},
|
|
12713
|
+
// The stop-reason popover reads the Client jobs snapshot while the
|
|
12714
|
+
// built-in jobs panel owns the stop buttons. Wait for the jobs service
|
|
12715
|
+
// in a nested inject scope so a late-provided service still registers.
|
|
12716
|
+
{
|
|
12717
|
+
slot: 'shell.overlay',
|
|
12718
|
+
options: { id: 'powerup-job-stop', order: 57 },
|
|
12719
|
+
component: (scope) => h(JobStopOverlay, { jobs: scope.get('jobs'), ctx: scope }),
|
|
12720
|
+
label: 'dsh-powerup: job stop reason',
|
|
12721
|
+
inject: ['jobs'],
|
|
12722
|
+
},
|
|
12723
|
+
];
|
|
12724
|
+
|
|
12725
|
+
function apply(ctx) {
|
|
12726
|
+
for (const step of PREINSTALL) {
|
|
12624
12727
|
try {
|
|
12625
|
-
|
|
12626
|
-
const manager = scope.get('remote.pluginManager');
|
|
12627
|
-
const remote = scope.get('remote');
|
|
12628
|
-
const childSlots = scope.get('slots');
|
|
12629
|
-
if (manager === undefined || childSlots === undefined || typeof childSlots.register !== 'function') return;
|
|
12630
|
-
scope.effect(
|
|
12631
|
-
() => childSlots.inject('shell.overlay', () => childSlots.register({
|
|
12632
|
-
name: 'shell.overlay',
|
|
12633
|
-
id: 'powerup-plugin-update',
|
|
12634
|
-
order: 56,
|
|
12635
|
-
}, () => h(PluginUpdateOverlay, { manager, remote, ctx: scope }))),
|
|
12636
|
-
'dsh-powerup: plugin update',
|
|
12637
|
-
);
|
|
12638
|
-
});
|
|
12728
|
+
step.run(ctx);
|
|
12639
12729
|
} catch (error) {
|
|
12640
|
-
console.warn(
|
|
12730
|
+
console.warn(`[dsh-powerup] ${step.label} failed:`, error?.message ?? error);
|
|
12641
12731
|
}
|
|
12642
12732
|
}
|
|
12643
12733
|
|
|
12644
|
-
|
|
12645
|
-
|
|
12646
|
-
|
|
12647
|
-
|
|
12734
|
+
const slots = ctx.get('slots');
|
|
12735
|
+
if (slots === undefined || typeof slots.inject !== 'function' || typeof slots.register !== 'function') {
|
|
12736
|
+
console.warn('[dsh-powerup] slots service missing; Power-Up UI disabled');
|
|
12737
|
+
return;
|
|
12738
|
+
}
|
|
12739
|
+
|
|
12740
|
+
const register = (slot, options, component, label) => {
|
|
12648
12741
|
try {
|
|
12649
|
-
ctx.
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
scope.effect(
|
|
12654
|
-
() => childSlots.inject('shell.overlay', () => childSlots.register({
|
|
12655
|
-
name: 'shell.overlay',
|
|
12656
|
-
id: 'powerup-job-stop',
|
|
12657
|
-
order: 57,
|
|
12658
|
-
}, () => h(JobStopOverlay, { jobs, ctx: scope }))),
|
|
12659
|
-
'dsh-powerup: job stop reason',
|
|
12660
|
-
);
|
|
12661
|
-
});
|
|
12742
|
+
ctx.effect(
|
|
12743
|
+
() => slots.inject(slot, () => slots.register({ name: slot, ...options }, component)),
|
|
12744
|
+
label,
|
|
12745
|
+
);
|
|
12662
12746
|
} catch (error) {
|
|
12663
|
-
console.warn(
|
|
12747
|
+
console.warn(`[dsh-powerup] could not register ${slot}:`, error?.message ?? error);
|
|
12748
|
+
}
|
|
12749
|
+
};
|
|
12750
|
+
|
|
12751
|
+
for (const entry of REGISTRY) {
|
|
12752
|
+
if (entry.inject !== undefined) {
|
|
12753
|
+
// Nested inject scope: observe the listed services instead of
|
|
12754
|
+
// sampling them once from the root scope.
|
|
12755
|
+
if (typeof ctx.inject !== 'function') {
|
|
12756
|
+
console.warn(`[dsh-powerup] ctx.inject missing; ${entry.label} skipped`);
|
|
12757
|
+
continue;
|
|
12758
|
+
}
|
|
12759
|
+
try {
|
|
12760
|
+
ctx.inject(entry.inject, (scope) => {
|
|
12761
|
+
const missing = entry.inject.some((name) => scope.get(name) === undefined);
|
|
12762
|
+
if (missing || typeof scope.get('slots')?.register !== 'function') return;
|
|
12763
|
+
scope.effect(
|
|
12764
|
+
() => scope.get('slots').inject(entry.slot, () => scope.get('slots').register(
|
|
12765
|
+
{ name: entry.slot, ...entry.options },
|
|
12766
|
+
(props) => entry.component(scope),
|
|
12767
|
+
)),
|
|
12768
|
+
entry.label,
|
|
12769
|
+
);
|
|
12770
|
+
});
|
|
12771
|
+
} catch (error) {
|
|
12772
|
+
console.warn(`[dsh-powerup] ${entry.label} registration failed:`, error?.message ?? error);
|
|
12773
|
+
}
|
|
12774
|
+
continue;
|
|
12664
12775
|
}
|
|
12776
|
+
register(entry.slot, entry.options, entry.component, entry.label);
|
|
12665
12777
|
}
|
|
12666
12778
|
}
|
|
12667
12779
|
|
package/index.js
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* for the current session's composer
|
|
27
27
|
* GET /dsh-powerup/api/quick-replies → reads the current session's options
|
|
28
28
|
* POST /dsh-powerup/api/quick-replies → clears them after a user message
|
|
29
|
+
* POST /dsh-powerup/api/system-theme → flips the Windows OS light/dark mode
|
|
29
30
|
*
|
|
30
31
|
* The Client half drives other plugins' installation through the built-in
|
|
31
32
|
* `pluginManager` Remote. Only the process restart, the self-update handoff,
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
*/
|
|
39
40
|
|
|
40
41
|
import { randomUUID } from 'node:crypto';
|
|
42
|
+
import { execFile } from 'node:child_process';
|
|
41
43
|
import { appendFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
42
44
|
import { dirname, join, resolve as resolvePath, sep } from 'node:path';
|
|
43
45
|
import { homedir } from 'node:os';
|
|
@@ -59,10 +61,28 @@ import {
|
|
|
59
61
|
createQuickRepliesStore,
|
|
60
62
|
createQuickRepliesTool,
|
|
61
63
|
} from './lib/quick-replies.js';
|
|
64
|
+
import { describeSystemTheme, setSystemTheme } from './lib/system-theme.js';
|
|
62
65
|
|
|
63
66
|
/** Prefix owned by this plugin. */
|
|
64
67
|
const ROUTE = '/dsh-powerup/api';
|
|
65
68
|
|
|
69
|
+
/** Run a host command with a bounded timeout, capturing its output. */
|
|
70
|
+
function runCommand(command, args) {
|
|
71
|
+
return new Promise((resolve) => {
|
|
72
|
+
try {
|
|
73
|
+
execFile(command, args, { windowsHide: true, timeout: 8000 }, (error, stdout, stderr) => {
|
|
74
|
+
resolve({
|
|
75
|
+
code: typeof error?.code === 'number' ? error.code : (error ? 1 : 0),
|
|
76
|
+
stdout: String(stdout ?? ''),
|
|
77
|
+
stderr: String(stderr ?? ''),
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
} catch (error) {
|
|
81
|
+
resolve({ code: 1, stderr: String(error?.message ?? error) });
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
66
86
|
/** The bundle this pair of routes may replace while its own UI unloads. */
|
|
67
87
|
const MODULE_ID = '@restregular/dsh-powerup';
|
|
68
88
|
|
|
@@ -555,11 +575,31 @@ async function handle(req, res, ctx) {
|
|
|
555
575
|
|
|
556
576
|
const url = new URL(req.url ?? ROUTE, 'http://localhost');
|
|
557
577
|
const op = url.pathname.slice(ROUTE.length).replace(/^\/+/u, '') || url.searchParams.get('op') || '';
|
|
558
|
-
if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules' && op !== 'progress' && op !== 'progress-requirements' && op !== 'progress-history' && op !== 'direct-ask' && op !== 'ask-title' && op !== 'quick-replies') {
|
|
578
|
+
if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules' && op !== 'progress' && op !== 'progress-requirements' && op !== 'progress-history' && op !== 'direct-ask' && op !== 'ask-title' && op !== 'quick-replies' && op !== 'system-theme') {
|
|
559
579
|
sendJson(res, { ok: false, error: 'not-found' }, 404);
|
|
560
580
|
return;
|
|
561
581
|
}
|
|
562
582
|
|
|
583
|
+
if (op === 'system-theme') {
|
|
584
|
+
const capability = describeSystemTheme();
|
|
585
|
+
if (req.method === 'GET') {
|
|
586
|
+
sendJson(res, { ok: true, ...capability });
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
if (req.method !== 'POST') {
|
|
590
|
+
sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
593
|
+
try {
|
|
594
|
+
const body = await readJsonBody(req);
|
|
595
|
+
const result = await setSystemTheme(body, { run: runCommand });
|
|
596
|
+
sendJson(res, result, result.ok ? 200 : 409);
|
|
597
|
+
} catch (error) {
|
|
598
|
+
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
599
|
+
}
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
|
|
563
603
|
if (op === 'quick-replies') {
|
|
564
604
|
const store = createQuickRepliesStore({
|
|
565
605
|
file: storePath(QUICK_REPLIES_FILE),
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-powerup — flip the Windows OS light/dark mode.
|
|
3
|
+
*
|
|
4
|
+
* The browser cannot change the operating system palette; only the Host half
|
|
5
|
+
* can. On Windows the per-user preference lives under
|
|
6
|
+
* `HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize` with two
|
|
7
|
+
* DWORD values: `AppsUseLightTheme` (app palette) and `SystemUsesLightTheme`
|
|
8
|
+
* (taskbar/Start palette). After writing them, an `ImmersiveColorSet`
|
|
9
|
+
* `WM_SETTINGCHANGE` broadcast tells running apps to re-read the preference.
|
|
10
|
+
*
|
|
11
|
+
* Both writes go through `reg.exe` / PowerShell `Add-Type`, launched via the
|
|
12
|
+
* injected `run` callback so this module stays pure and testable. The caller
|
|
13
|
+
* must guarantee the request came from the loopback Host origin.
|
|
14
|
+
*
|
|
15
|
+
* @module dsh-powerup/system-theme
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** Registry key holding the per-user light/dark preference. */
|
|
19
|
+
export const PERSONALIZE_KEY = 'Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Describe whether this Host can switch the OS theme.
|
|
23
|
+
* @param {{ platform?: string, execPath?: string }} env runtime environment
|
|
24
|
+
* @returns {{ supported: boolean, reason?: string }}
|
|
25
|
+
*/
|
|
26
|
+
export function describeSystemTheme(env = {}) {
|
|
27
|
+
const platform = typeof env.platform === 'string' ? env.platform : process.platform;
|
|
28
|
+
if (platform !== 'win32') {
|
|
29
|
+
return { supported: false, reason: 'OS theme switching is only available on Windows.' };
|
|
30
|
+
}
|
|
31
|
+
return { supported: true };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Apply the requested OS color scheme.
|
|
36
|
+
* @param {{ scheme: 'light' | 'dark' }} request
|
|
37
|
+
* @param {{ platform?: string, run: (command: string, args: string[]) => Promise<{ code: number, stdout?: string, stderr?: string }> }} deps
|
|
38
|
+
* @returns {Promise<{ ok: boolean, supported: boolean, scheme?: string, reason?: string }>}
|
|
39
|
+
*/
|
|
40
|
+
export async function setSystemTheme(request, deps) {
|
|
41
|
+
const capability = describeSystemTheme(deps ?? {});
|
|
42
|
+
if (!capability.supported) return { ok: false, supported: false, reason: capability.reason };
|
|
43
|
+
const scheme = request?.scheme === 'light' ? 'light' : request?.scheme === 'dark' ? 'dark' : null;
|
|
44
|
+
if (scheme === null) return { ok: false, supported: true, reason: 'scheme must be light or dark' };
|
|
45
|
+
const run = typeof deps?.run === 'function' ? deps.run : null;
|
|
46
|
+
if (run === null) return { ok: false, supported: true, reason: 'no command runner available' };
|
|
47
|
+
|
|
48
|
+
const value = scheme === 'light' ? '1' : '0';
|
|
49
|
+
const key = `HKCU\\${PERSONALIZE_KEY}`;
|
|
50
|
+
try {
|
|
51
|
+
for (const name of ['AppsUseLightTheme', 'SystemUsesLightTheme']) {
|
|
52
|
+
const result = await run('reg.exe', ['add', key, '/v', name, '/t', 'REG_DWORD', '/d', value, '/f']);
|
|
53
|
+
if (result?.code !== 0) {
|
|
54
|
+
return { ok: false, supported: true, reason: `failed to write ${name}: ${String(result?.stderr ?? '').trim()}` };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Broadcast the settings change so running apps pick up the new palette.
|
|
58
|
+
// PowerShell is available on every supported Windows desktop; Add-Type is
|
|
59
|
+
// scoped to this process so no file is written.
|
|
60
|
+
const ps = [
|
|
61
|
+
'-NoProfile', '-NonInteractive', '-Command',
|
|
62
|
+
"Add-Type -TypeDefinition 'using System;using System.Runtime.InteropServices;public class PowerupTheme{[DllImport(\"user32.dll\",SetLastError=true,CharSet=CharSet.Auto)]public static extern IntPtr SendMessageTimeout(IntPtr hWnd,uint Msg,UIntPtr wParam,string lParam,uint fuFlags,uint uTimeout,out UIntPtr lpdwResult);};';" +
|
|
63
|
+
'$r=[UIntPtr]::Zero;[void][PowerupTheme]::SendMessageTimeout([IntPtr]0xffff,0x001A,[UIntPtr]::Zero,"ImmersiveColorSet",2,1000,[ref]$r)',
|
|
64
|
+
];
|
|
65
|
+
const broadcast = await run('powershell.exe', ps);
|
|
66
|
+
// The broadcast is best-effort: even if it fails the registry values are
|
|
67
|
+
// written and will apply to apps that start afterwards.
|
|
68
|
+
return { ok: true, supported: true, scheme, broadcast: broadcast?.code === 0 };
|
|
69
|
+
} catch (error) {
|
|
70
|
+
return { ok: false, supported: true, reason: String(error?.message ?? error) };
|
|
71
|
+
}
|
|
72
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.17",
|
|
4
4
|
"description": "为 DeepSeek Harness 提供一组可选的小型增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格、会话切换、定位当前会话、工作区提示词、旁路模型生成的结构化任务进度;所有功能均可在 Power-Up 页面独立开关。 · Opt-in upgrades for DeepSeek Harness: Trajectory context menu and step references, job stop reasons, one-click plugin install, an adaptive sidebar launcher, session switching, locating the current session, workspace prompts, and non-blocking model-generated structured task progress — each toggled independently on the Power-Up page.",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|
|
@@ -16,8 +16,7 @@
|
|
|
16
16
|
"files": [
|
|
17
17
|
"index.js",
|
|
18
18
|
"client.js",
|
|
19
|
-
"cordis.patch.yml",
|
|
20
|
-
"lib/restart.js",
|
|
19
|
+
"cordis.patch.yml", "lib/restart.js",
|
|
21
20
|
"lib/restart-helper.cjs",
|
|
22
21
|
"lib/step-reference.js",
|
|
23
22
|
"lib/step-tool.js",
|
|
@@ -26,6 +25,7 @@
|
|
|
26
25
|
"lib/task-resume.js",
|
|
27
26
|
"lib/direct-ask.js",
|
|
28
27
|
"lib/quick-replies.js",
|
|
28
|
+
"lib/system-theme.js",
|
|
29
29
|
"locale/*.json",
|
|
30
30
|
"icon.svg",
|
|
31
31
|
"README.md",
|
|
@@ -99,7 +99,9 @@
|
|
|
99
99
|
"node": ">=22.13.0"
|
|
100
100
|
},
|
|
101
101
|
"scripts": {
|
|
102
|
-
"
|
|
102
|
+
"build": "node scripts/build.mjs",
|
|
103
|
+
"pretest": "node scripts/build.mjs --check",
|
|
104
|
+
"test": "node test/smoke.mjs && node test/host.mjs && node test/progress.mjs && node test/task-resume.mjs && node test/direct-ask.mjs && node test/quick-replies.mjs && node test/system-theme.mjs"
|
|
103
105
|
},
|
|
104
106
|
"license": "MIT",
|
|
105
107
|
"author": "RestRegular"
|