@restregular/dsh-powerup 0.8.19 → 0.9.1
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 +34 -0
- package/client.js +661 -6
- package/index.js +63 -7
- package/locale/en.json +1 -1
- package/locale/zh.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -371,6 +371,40 @@ fiber is unloaded. The panel closes; refresh the page when the install finishes.
|
|
|
371
371
|
fixed-position popovers anchored to their triggers, so they never grow the
|
|
372
372
|
dialog or get clipped by its scroll area.
|
|
373
373
|
|
|
374
|
+
### Conversation rendering enhancements
|
|
375
|
+
|
|
376
|
+
A feature set for more readable conversations, toggled as a whole on the
|
|
377
|
+
Power-Up page. Its first sub-feature is **reply masking**: each rule matches
|
|
378
|
+
Agent reply prose and replaces matching fragments. Reasoning blocks, tool calls
|
|
379
|
+
and user messages are never touched — only the assistant's answer text,
|
|
380
|
+
including the final task summary.
|
|
381
|
+
|
|
382
|
+
Each rule has:
|
|
383
|
+
- a pattern, with a per-rule **Regex** toggle (on = regular expression with
|
|
384
|
+
`g/u/m/s` flags so `^`/`$` match line boundaries and `.` crosses newlines;
|
|
385
|
+
off = plain literal text),
|
|
386
|
+
- a replacement (blank removes the match; a **Default** button fills in
|
|
387
|
+
`[已屏蔽]`),
|
|
388
|
+
- an enable switch.
|
|
389
|
+
|
|
390
|
+
Global rules are managed on the Power-Up page's **Masking** tab. Workspace rules
|
|
391
|
+
are managed from the **PowerUp** tab in any conversation header (it appears
|
|
392
|
+
after Trajectory), and are stored in the workspace's
|
|
393
|
+
`.dsh/dsh-powerup/mask-rules.json` through a local Host route.
|
|
394
|
+
|
|
395
|
+
### Dual send buttons
|
|
396
|
+
|
|
397
|
+
When enabled on the Power-Up page, two compact controls appear at the right of
|
|
398
|
+
the composer: a queued send and an interrupt (steer) send. They bypass the
|
|
399
|
+
system "busy Enter" preference:
|
|
400
|
+
|
|
401
|
+
- **Enter** always queues the message as a next turn.
|
|
402
|
+
- **Ctrl+Shift+Enter** (Cmd+Shift+Enter on macOS) always interrupts the running
|
|
403
|
+
turn with the message.
|
|
404
|
+
|
|
405
|
+
Plain Shift+Enter still inserts a newline, IME composition and slash/mention
|
|
406
|
+
menus are left to the host, and an empty draft keeps the host's retry behavior.
|
|
407
|
+
|
|
374
408
|
## Development
|
|
375
409
|
|
|
376
410
|
```bash
|
package/client.js
CHANGED
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
const promptCreateDraft = { workspaceId: null, title: '', text: '', scope: 'current' };
|
|
84
84
|
/** Fallback bucket when the hero cannot resolve an owning workspace yet. */
|
|
85
85
|
const UNSCOPED_WORKSPACE = '__unscoped__';
|
|
86
|
-
const VERSION = '0.
|
|
86
|
+
const VERSION = '0.9.1';
|
|
87
87
|
const MENU_GAP = 8;
|
|
88
88
|
const MENU_WIDTH = 248;
|
|
89
89
|
/** Reference scheme understood by the Host's `powerup_step_read` tool. */
|
|
@@ -135,6 +135,41 @@
|
|
|
135
135
|
'page.scrollToTopHow': '在左侧边栏向下滚动工作区列表,顶部的「新会话」旁会出现向上箭头按钮,点击即可回到顶部。',
|
|
136
136
|
'scrollToTop.label': '回到顶部',
|
|
137
137
|
'scrollToTop.hint': '将左侧边栏滚动回最顶部',
|
|
138
|
+
'page.renderingTitle': '会话内容渲染增强',
|
|
139
|
+
'page.renderingDesc': '一组让会话内容更好读的增强,当前包含「回复内容屏蔽」:按正则表达式把 Agent 回复正文中匹配的片段替换成占位符,例如隐藏内部标签、水印或重复前缀。思考过程与工具调用不会被动到,只有发给你的回复正文(含最终总结)会被处理。',
|
|
140
|
+
'page.renderingHow': '在 Power-Up 设置页的「内容屏蔽」标签页管理全局规则;也可以在会话顶部的 PowerUp 标签页管理当前工作区的规则。每条规则填一个正则表达式和替换文本;替换文本留空表示直接删除匹配内容,也可点「默认值」按钮填入 [已屏蔽]。正则支持多行匹配(^/$ 匹配行首行尾,. 可跨行)。',
|
|
141
|
+
'page.dualSendTitle': '双发送按钮',
|
|
142
|
+
'page.dualSendDesc': '在输入框右侧增加两个发送按钮:普通发送(等待/排队)与插话发送(立即打断当前生成)。快捷键 Enter 固定为等待发送、Ctrl+Shift+Enter 固定为插话发送,不受系统「繁忙时发送行为」设置影响。',
|
|
143
|
+
'page.dualSendHow': '启用后输入框里会出现两个按钮,鼠标悬停可看到各自说明;输入文字后按 Enter 排队发送,按 Ctrl+Shift+Enter 立即插话发送。',
|
|
144
|
+
'mask.tab': '内容屏蔽',
|
|
145
|
+
'mask.tabFeatures': '功能',
|
|
146
|
+
'mask.tabWorkspace': '工作区设置',
|
|
147
|
+
'mask.globalTitle': '全局屏蔽规则',
|
|
148
|
+
'mask.workspaceTitle': '工作区屏蔽规则',
|
|
149
|
+
'mask.hint': '每条规则是一个正则表达式;命中的片段会被替换为占位符。思考过程与工具调用不会被处理。',
|
|
150
|
+
'mask.pattern': '正则表达式',
|
|
151
|
+
'mask.patternPlaceholder': '例如:\\[内部[^\\]]*\\]',
|
|
152
|
+
'mask.replacement': '替换为',
|
|
153
|
+
'mask.replacementPlaceholder': '留空则删除匹配内容',
|
|
154
|
+
'mask.useDefault': '默认值',
|
|
155
|
+
'mask.useDefaultHint': '填入 [已屏蔽]',
|
|
156
|
+
'mask.regex': '正则',
|
|
157
|
+
'mask.regexHint': '关闭后按纯文本匹配',
|
|
158
|
+
'mask.enabled': '启用',
|
|
159
|
+
'mask.add': '添加规则',
|
|
160
|
+
'mask.delete': '删除',
|
|
161
|
+
'mask.empty': '还没有规则。',
|
|
162
|
+
'mask.invalid': '正则表达式无效',
|
|
163
|
+
'mask.scopeGlobal': '全局',
|
|
164
|
+
'mask.scopeWorkspace': '当前工作区',
|
|
165
|
+
'mask.sessionTitle': 'Power-Up 设置',
|
|
166
|
+
'mask.viewTabLabel': 'PowerUp',
|
|
167
|
+
'mask.sessionDesc': '管理当前工作区的 Power-Up 功能设置与内容屏蔽规则。',
|
|
168
|
+
'send.wait': '等待发送',
|
|
169
|
+
'send.waitHint': '排队发送(Enter)',
|
|
170
|
+
'send.interrupt': '插话发送',
|
|
171
|
+
'send.interruptHint': '立即打断并发送(Ctrl+Shift+Enter)',
|
|
172
|
+
'send.empty': '输入为空',
|
|
138
173
|
'launcher.groupDefault': '分组',
|
|
139
174
|
'launcher.count': '{count} 个面板',
|
|
140
175
|
'launcher.renameHint': '点击重命名',
|
|
@@ -392,6 +427,41 @@
|
|
|
392
427
|
'page.scrollToTopHow': 'Scroll the workspace list down in the left sidebar; an up-arrow button appears beside New Session — click it to return to the top.',
|
|
393
428
|
'scrollToTop.label': 'Back to top',
|
|
394
429
|
'scrollToTop.hint': 'Scroll the left sidebar back to the top',
|
|
430
|
+
'page.renderingTitle': 'Conversation rendering enhancements',
|
|
431
|
+
'page.renderingDesc': 'A feature set for more readable conversations. Its first sub-feature is reply masking: regular expressions replace matching fragments in Agent reply text with a placeholder, for example to hide internal tags, watermarks or repeated prefixes. Reasoning and tool calls are untouched; only reply prose (including the final summary) is processed.',
|
|
432
|
+
'page.renderingHow': 'Manage global rules on the Power-Up page\'s Masking tab, or workspace rules from the PowerUp tab in a session header. Each rule has a regular expression and a replacement text; a blank replacement removes the match, or click the Default button to fill in [masked]. Regex supports multiline matching (^/$ match line boundaries, . matches newlines).',
|
|
433
|
+
'page.dualSendTitle': 'Dual send buttons',
|
|
434
|
+
'page.dualSendDesc': 'Adds two send buttons beside the composer: a normal (queued) send and an interrupt (steer) send. Enter always queues and Ctrl+Shift+Enter always interrupts, overriding the system busy-time send behavior.',
|
|
435
|
+
'page.dualSendHow': 'Once enabled, two buttons appear in the composer with hover labels. Press Enter to queue a message, or Ctrl+Shift+Enter to interrupt the running turn with it.',
|
|
436
|
+
'mask.tab': 'Masking',
|
|
437
|
+
'mask.tabFeatures': 'Features',
|
|
438
|
+
'mask.tabWorkspace': 'Workspace settings',
|
|
439
|
+
'mask.globalTitle': 'Global masking rules',
|
|
440
|
+
'mask.workspaceTitle': 'Workspace masking rules',
|
|
441
|
+
'mask.hint': 'Each rule is a regular expression; matching fragments are replaced with a placeholder. Reasoning and tool calls are never touched.',
|
|
442
|
+
'mask.pattern': 'Regular expression',
|
|
443
|
+
'mask.patternPlaceholder': 'e.g. \\[internal[^\\]]*\\]',
|
|
444
|
+
'mask.replacement': 'Replace with',
|
|
445
|
+
'mask.replacementPlaceholder': 'Blank removes the match',
|
|
446
|
+
'mask.useDefault': 'Default',
|
|
447
|
+
'mask.useDefaultHint': 'Fill in [masked]',
|
|
448
|
+
'mask.regex': 'Regex',
|
|
449
|
+
'mask.regexHint': 'Off means plain-text match',
|
|
450
|
+
'mask.enabled': 'Enabled',
|
|
451
|
+
'mask.add': 'Add rule',
|
|
452
|
+
'mask.delete': 'Delete',
|
|
453
|
+
'mask.empty': 'No rules yet.',
|
|
454
|
+
'mask.invalid': 'Invalid regular expression',
|
|
455
|
+
'mask.scopeGlobal': 'Global',
|
|
456
|
+
'mask.scopeWorkspace': 'This workspace',
|
|
457
|
+
'mask.sessionTitle': 'Power-Up settings',
|
|
458
|
+
'mask.viewTabLabel': 'PowerUp',
|
|
459
|
+
'mask.sessionDesc': 'Manage Power-Up settings and masking rules for this workspace.',
|
|
460
|
+
'send.wait': 'Send (queued)',
|
|
461
|
+
'send.waitHint': 'Queue to send (Enter)',
|
|
462
|
+
'send.interrupt': 'Send (interrupt)',
|
|
463
|
+
'send.interruptHint': 'Interrupt and send now (Ctrl+Shift+Enter)',
|
|
464
|
+
'send.empty': 'Empty input',
|
|
395
465
|
'launcher.groupDefault': 'Group',
|
|
396
466
|
'launcher.count': '{count} panels',
|
|
397
467
|
'launcher.renameHint': 'Click to rename',
|
|
@@ -646,6 +716,8 @@
|
|
|
646
716
|
update: true,
|
|
647
717
|
locateSession: true,
|
|
648
718
|
scrollToTop: true,
|
|
719
|
+
contentRendering: true,
|
|
720
|
+
dualSend: false,
|
|
649
721
|
workspacePrompts: true,
|
|
650
722
|
oneClickEnable: true,
|
|
651
723
|
oneClickRestart: true,
|
|
@@ -666,6 +738,8 @@
|
|
|
666
738
|
update: parsed.update !== false,
|
|
667
739
|
locateSession: parsed.locateSession !== false,
|
|
668
740
|
scrollToTop: parsed.scrollToTop !== false,
|
|
741
|
+
contentRendering: parsed.contentRendering !== false,
|
|
742
|
+
dualSend: parsed.dualSend === true,
|
|
669
743
|
workspacePrompts: parsed.workspacePrompts !== false,
|
|
670
744
|
oneClickEnable: parsed.oneClickEnable !== false,
|
|
671
745
|
oneClickRestart: parsed.oneClickRestart !== false,
|
|
@@ -798,6 +872,137 @@
|
|
|
798
872
|
}
|
|
799
873
|
}
|
|
800
874
|
|
|
875
|
+
// ------------------------------------------------------------------
|
|
876
|
+
// Mask rules for the content-rendering enhancement.
|
|
877
|
+
// Global rules live in localStorage; workspace rules live in the
|
|
878
|
+
// workspace's `.dsh/dsh-powerup/mask-rules.json` via a Host route, exactly
|
|
879
|
+
// like prompts. Both lists share one normalize/compile helper.
|
|
880
|
+
// ------------------------------------------------------------------
|
|
881
|
+
const MASK_RULES_KEY = 'dsh-powerup:mask-rules:v1';
|
|
882
|
+
const MASK_RULES_API = '/dsh-powerup/api/mask-rules';
|
|
883
|
+
const MASK_PLACEHOLDER = '[已屏蔽]';
|
|
884
|
+
let globalMaskRules = readGlobalMaskRules();
|
|
885
|
+
let workspaceMaskRules = [];
|
|
886
|
+
let maskRulesWorkspace = '';
|
|
887
|
+
const maskRulesListeners = new Set();
|
|
888
|
+
|
|
889
|
+
/** Normalize one stored rule; invalid regex is kept but never compiled. */
|
|
890
|
+
function normalizeMaskRule(item) {
|
|
891
|
+
if (item === null || typeof item !== 'object') return null;
|
|
892
|
+
return {
|
|
893
|
+
id: typeof item.id === 'string' && item.id !== '' ? item.id : newId(),
|
|
894
|
+
pattern: typeof item.pattern === 'string' ? item.pattern : '',
|
|
895
|
+
replacement: typeof item.replacement === 'string' ? item.replacement : '',
|
|
896
|
+
enabled: item.enabled !== false,
|
|
897
|
+
// Existing rules predate this flag and were regexes, so default true.
|
|
898
|
+
regex: item.regex !== false,
|
|
899
|
+
scope: item.scope === 'workspace' ? 'workspace' : 'global',
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
function readGlobalMaskRules() {
|
|
904
|
+
try {
|
|
905
|
+
const parsed = JSON.parse(localStorage.getItem(MASK_RULES_KEY) || '[]');
|
|
906
|
+
return Array.isArray(parsed) ? parsed.map(normalizeMaskRule).filter(Boolean) : [];
|
|
907
|
+
} catch {
|
|
908
|
+
return [];
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
function writeGlobalMaskRules(list) {
|
|
913
|
+
globalMaskRules = (Array.isArray(list) ? list : []).map(normalizeMaskRule).filter(Boolean);
|
|
914
|
+
try {
|
|
915
|
+
localStorage.setItem(MASK_RULES_KEY, JSON.stringify(globalMaskRules));
|
|
916
|
+
} catch {
|
|
917
|
+
/* Private mode: the in-memory list still works this page. */
|
|
918
|
+
}
|
|
919
|
+
emitMaskRules();
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
async function loadWorkspaceMaskRules(workspaceId) {
|
|
923
|
+
const id = typeof workspaceId === 'string' ? workspaceId : '';
|
|
924
|
+
maskRulesWorkspace = id;
|
|
925
|
+
try {
|
|
926
|
+
const response = await fetch(MASK_RULES_API + '?workspaceId=' + encodeURIComponent(id), {
|
|
927
|
+
headers: { accept: 'application/json' },
|
|
928
|
+
});
|
|
929
|
+
const data = response.ok ? await response.json() : null;
|
|
930
|
+
const rules = data !== null && Array.isArray(data.rules) ? data.rules : [];
|
|
931
|
+
workspaceMaskRules = rules.map(normalizeMaskRule).filter(Boolean)
|
|
932
|
+
.map((rule) => ({ ...rule, scope: 'workspace' }));
|
|
933
|
+
} catch {
|
|
934
|
+
/* Host unavailable: keep the last known list. */
|
|
935
|
+
}
|
|
936
|
+
emitMaskRules();
|
|
937
|
+
return workspaceMaskRules;
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
function writeWorkspaceMaskRules(list) {
|
|
941
|
+
workspaceMaskRules = (Array.isArray(list) ? list : []).map(normalizeMaskRule).filter(Boolean)
|
|
942
|
+
.map((rule) => ({ ...rule, scope: 'workspace' }));
|
|
943
|
+
emitMaskRules();
|
|
944
|
+
fetch(MASK_RULES_API, {
|
|
945
|
+
method: 'POST',
|
|
946
|
+
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
947
|
+
body: JSON.stringify({ workspaceId: maskRulesWorkspace, rules: workspaceMaskRules }),
|
|
948
|
+
}).catch(() => {
|
|
949
|
+
/* The in-memory list still works this page. */
|
|
950
|
+
});
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function subscribeMaskRules(listener) {
|
|
954
|
+
maskRulesListeners.add(listener);
|
|
955
|
+
return () => maskRulesListeners.delete(listener);
|
|
956
|
+
}
|
|
957
|
+
function emitMaskRules() {
|
|
958
|
+
for (const listener of [...maskRulesListeners]) {
|
|
959
|
+
try { listener(); } catch { /* one listener must not break the rest */ }
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
/** Rules that apply to the current workspace: global plus its own. */
|
|
964
|
+
function activeMaskRules() {
|
|
965
|
+
return [...globalMaskRules, ...workspaceMaskRules].filter((rule) => rule.enabled && rule.pattern !== '');
|
|
966
|
+
}
|
|
967
|
+
|
|
968
|
+
/** Escape a literal string so it can be used as an exact regex source. */
|
|
969
|
+
function escapeRegExp(text) {
|
|
970
|
+
return text.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Compile rules once per change into reusable RegExp objects. Regex mode
|
|
975
|
+
* uses 'g' (all), 'u' (unicode), 'm' (^/$ per line) and 's' (dot crosses
|
|
976
|
+
* newlines); plain-text mode escapes the pattern for a literal match.
|
|
977
|
+
*/
|
|
978
|
+
function compileMaskRules(list) {
|
|
979
|
+
const compiled = [];
|
|
980
|
+
for (const rule of Array.isArray(list) ? list : []) {
|
|
981
|
+
if (rule === null || rule.enabled === false || typeof rule.pattern !== 'string' || rule.pattern === '') continue;
|
|
982
|
+
const isRegex = rule.regex !== false;
|
|
983
|
+
try {
|
|
984
|
+
compiled.push({
|
|
985
|
+
re: isRegex ? new RegExp(rule.pattern, 'gums') : new RegExp(escapeRegExp(rule.pattern), 'gu'),
|
|
986
|
+
// A blank replacement is intentional: remove the matched text.
|
|
987
|
+
replacement: typeof rule.replacement === 'string' ? rule.replacement : '',
|
|
988
|
+
});
|
|
989
|
+
} catch {
|
|
990
|
+
/* Invalid regex is skipped, never throws into rendering. */
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
return compiled;
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/** Apply compiled rules to one text fragment; safe for any string. */
|
|
997
|
+
function applyMaskRules(text, compiled) {
|
|
998
|
+
if (typeof text !== 'string' || text === '' || compiled.length === 0) return text;
|
|
999
|
+
let out = text;
|
|
1000
|
+
for (const rule of compiled) {
|
|
1001
|
+
out = out.replace(rule.re, rule.replacement);
|
|
1002
|
+
}
|
|
1003
|
+
return out;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
801
1006
|
/**
|
|
802
1007
|
* A prompt is visible in a workspace when it is global ('') or scoped to
|
|
803
1008
|
* that exact workspace. The dropdown never shows prompts of other workspaces.
|
|
@@ -2528,6 +2733,17 @@
|
|
|
2528
2733
|
bridge.sessionId = sessionId;
|
|
2529
2734
|
bridge.trajectory = snapshot;
|
|
2530
2735
|
bridge.inputActions = inputActions;
|
|
2736
|
+
// Keep workspace masking rules loaded for the active session so the
|
|
2737
|
+
// DOM mask observer can use them without the settings tab being open.
|
|
2738
|
+
if (typeof sessionId === 'string' && sessionId !== '') {
|
|
2739
|
+
const workspaces = ctxRef.current?.get?.('workspaces');
|
|
2740
|
+
const wsId = typeof workspaces?.list?.getSnapshot === 'function'
|
|
2741
|
+
? resolveWorkspaceIdFromSnapshot(workspaces.list.getSnapshot(), sessionId)
|
|
2742
|
+
: '';
|
|
2743
|
+
if (typeof wsId === 'string' && wsId !== '' && wsId !== maskRulesWorkspace) {
|
|
2744
|
+
void loadWorkspaceMaskRules(wsId);
|
|
2745
|
+
}
|
|
2746
|
+
}
|
|
2531
2747
|
return () => {
|
|
2532
2748
|
if (bridge.token === token) {
|
|
2533
2749
|
bridge.token = null;
|
|
@@ -3653,6 +3869,31 @@ default; shown only while the sidebar workspace list is scrolled down. */
|
|
|
3653
3869
|
html[data-platform="darwin"] .dsh-powerup-scrolltop{background:var(--dsw-specific-sidebar-glass-fill)}
|
|
3654
3870
|
html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-specific-sidebar-glass-hover)}
|
|
3655
3871
|
@media (prefers-reduced-motion:reduce){.dsh-powerup-scrolltop{transition:none}}
|
|
3872
|
+
`;
|
|
3873
|
+
|
|
3874
|
+
const RENDERING_CSS = `
|
|
3875
|
+
/* Masked fragments get a subtle marker so the reader knows text was hidden. */
|
|
3876
|
+
.dsh-powerup-masked{color:var(--dsw-alias-label-caption);font-style:italic;opacity:.72}
|
|
3877
|
+
/* Dual send buttons injected into the composer's right slot. */
|
|
3878
|
+
.dsh-powerup-send{display:inline-flex;align-items:center;justify-content:center;width:34px;height:34px;padding:0;box-sizing:border-box;border:.5px solid var(--dsw-alias-border-l3);border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font:inherit;cursor:pointer;transition:background .12s ease,color .12s ease,border-color .12s ease}
|
|
3879
|
+
.dsh-powerup-send:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary);border-color:var(--dsw-alias-border-l3)}
|
|
3880
|
+
.dsh-powerup-send:disabled{opacity:.45;cursor:not-allowed}
|
|
3881
|
+
.dsh-powerup-send:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
|
|
3882
|
+
.dsh-powerup-send[data-kind="interrupt"]{color:var(--dsw-alias-state-warn-label,var(--dsw-alias-label-secondary))}
|
|
3883
|
+
.dsh-powerup-send svg{width:16px;height:16px}
|
|
3884
|
+
.dsh-powerup-dual-send{display:inline-flex;align-items:center;gap:4px}
|
|
3885
|
+
.dsh-powerup-mask-editor{display:flex;flex-direction:column;gap:10px}
|
|
3886
|
+
.dsh-powerup-mask-row{display:grid;grid-template-columns:minmax(0,1.4fr) minmax(0,1fr) auto auto;gap:8px;align-items:center;padding:8px;border:.5px solid var(--dsw-alias-border-l1);border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-1)}
|
|
3887
|
+
.dsh-powerup-mask-default.on{background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-bg-layer-1);border-color:var(--dsw-alias-brand-primary)}
|
|
3888
|
+
.dsh-powerup-mask-input{width:100%;box-sizing:border-box;padding:6px 8px;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm,6px);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:inherit;font-size:12px;line-height:18px}
|
|
3889
|
+
.dsh-powerup-mask-input.invalid{border-color:var(--dsw-alias-state-error-primary)}
|
|
3890
|
+
.dsh-powerup-mask-replacement{display:flex;align-items:center;gap:4px;min-width:0}
|
|
3891
|
+
.dsh-powerup-mask-replacement .dsh-powerup-mask-input{flex:1 1 auto;min-width:0}
|
|
3892
|
+
.dsh-powerup-mask-default{flex:none;padding:5px 8px;border:.5px solid var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-sm,6px);background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;line-height:18px;white-space:nowrap;cursor:pointer;transition:background .12s ease,color .12s ease}
|
|
3893
|
+
.dsh-powerup-mask-default:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
|
|
3894
|
+
.dsh-powerup-mask-default:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:1px}
|
|
3895
|
+
.dsh-powerup-mask-empty{color:var(--dsw-alias-label-secondary);font-size:12px}
|
|
3896
|
+
@media (max-width:680px){.dsh-powerup-mask-row{grid-template-columns:minmax(0,1fr)}}
|
|
3656
3897
|
`;
|
|
3657
3898
|
|
|
3658
3899
|
const PROMPTS_CSS = `
|
|
@@ -4841,11 +5082,138 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
4841
5082
|
return core;
|
|
4842
5083
|
}
|
|
4843
5084
|
|
|
5085
|
+
/**
|
|
5086
|
+
* DOM-based masking for assistant reply prose. We observe the Chat view's
|
|
5087
|
+
* assistant reply rows and replace matching text fragments in place. The
|
|
5088
|
+
* original text of each text node is cached in a WeakMap so a re-render
|
|
5089
|
+
* that restores it can be masked again, and a re-render that produces a
|
|
5090
|
+
* new node is picked up by the MutationObserver. Only reply rows
|
|
5091
|
+
* (`data-chat-flow-kind="assistant-step"` with `group-part="response"`)
|
|
5092
|
+
* are touched; reasoning disclosures and tool calls are left alone.
|
|
5093
|
+
* @param {{isEnabled?: Function, rules?: Function}} deps
|
|
5094
|
+
*/
|
|
5095
|
+
function createReplyMaskCore(deps) {
|
|
5096
|
+
const options = deps ?? {};
|
|
5097
|
+
const isEnabled = typeof options.isEnabled === 'function' ? options.isEnabled : () => true;
|
|
5098
|
+
const rulesOf = typeof options.rules === 'function' ? options.rules : () => [];
|
|
5099
|
+
const originals = new WeakMap();
|
|
5100
|
+
let observer = null;
|
|
5101
|
+
let timer = null;
|
|
5102
|
+
let started = false;
|
|
5103
|
+
let compiled = [];
|
|
5104
|
+
let sweeping = false;
|
|
5105
|
+
|
|
5106
|
+
function hasDocument() {
|
|
5107
|
+
return typeof document !== 'undefined' && document !== null
|
|
5108
|
+
&& typeof document.querySelectorAll === 'function' && document.body !== null;
|
|
5109
|
+
}
|
|
5110
|
+
|
|
5111
|
+
function refreshRules() {
|
|
5112
|
+
compiled = compileMaskRules(rulesOf());
|
|
5113
|
+
}
|
|
5114
|
+
|
|
5115
|
+
function maskTextNode(node) {
|
|
5116
|
+
if (node.nodeType !== 3) return; // Node.TEXT_NODE
|
|
5117
|
+
const current = node.nodeValue ?? '';
|
|
5118
|
+
const original = originals.get(node);
|
|
5119
|
+
if (original !== undefined) {
|
|
5120
|
+
const maskedFromOriginal = applyMaskRules(original, compiled);
|
|
5121
|
+
if (current === maskedFromOriginal) return; // still our masked output
|
|
5122
|
+
}
|
|
5123
|
+
// Either a fresh node, React restored the original, or streaming grew
|
|
5124
|
+
// the text. Treat what is on screen now as the source of truth.
|
|
5125
|
+
originals.set(node, current);
|
|
5126
|
+
const masked = applyMaskRules(current, compiled);
|
|
5127
|
+
if (masked !== current) node.nodeValue = masked;
|
|
5128
|
+
}
|
|
5129
|
+
|
|
5130
|
+
function maskRow(row) {
|
|
5131
|
+
// Only the assistant's answer prose; skip reasoning / tool rows.
|
|
5132
|
+
const kind = row.getAttribute('data-chat-flow-kind');
|
|
5133
|
+
const part = row.getAttribute('data-chat-group-part');
|
|
5134
|
+
if (kind !== 'assistant-step' || (part !== null && part !== 'response')) return;
|
|
5135
|
+
const body = row.querySelector('[data-streaming], .dsh-powerup-mask-root') ?? row;
|
|
5136
|
+
const walker = document.createTreeWalker(body, 4 /* NodeFilter.SHOW_TEXT */, null);
|
|
5137
|
+
let node;
|
|
5138
|
+
while ((node = walker.nextNode()) !== null) {
|
|
5139
|
+
maskTextNode(node);
|
|
5140
|
+
}
|
|
5141
|
+
}
|
|
5142
|
+
|
|
5143
|
+
function sweep() {
|
|
5144
|
+
if (!started || !isEnabled() || compiled.length === 0 || sweeping) return;
|
|
5145
|
+
// Changing nodeValue fires our own characterData observer; the flag
|
|
5146
|
+
// keeps that from cascading into another full sweep.
|
|
5147
|
+
sweeping = true;
|
|
5148
|
+
try {
|
|
5149
|
+
const rows = document.querySelectorAll('[data-chat-flow-kind="assistant-step"]');
|
|
5150
|
+
for (const row of rows) maskRow(row);
|
|
5151
|
+
} finally {
|
|
5152
|
+
setTimeout(() => { sweeping = false; }, 0);
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5155
|
+
|
|
5156
|
+
function schedule() {
|
|
5157
|
+
if (timer !== null) return;
|
|
5158
|
+
timer = setTimeout(() => {
|
|
5159
|
+
timer = null;
|
|
5160
|
+
sweep();
|
|
5161
|
+
}, 40);
|
|
5162
|
+
}
|
|
5163
|
+
|
|
5164
|
+
function start() {
|
|
5165
|
+
if (started || !hasDocument()) return;
|
|
5166
|
+
started = true;
|
|
5167
|
+
refreshRules();
|
|
5168
|
+
sweep();
|
|
5169
|
+
if (typeof MutationObserver === 'function') {
|
|
5170
|
+
observer = new MutationObserver(() => schedule());
|
|
5171
|
+
observer.observe(document.body, { childList: true, subtree: true, characterData: true });
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
|
|
5175
|
+
function stop() {
|
|
5176
|
+
started = false;
|
|
5177
|
+
if (observer !== null) observer.disconnect();
|
|
5178
|
+
observer = null;
|
|
5179
|
+
if (timer !== null) clearTimeout(timer);
|
|
5180
|
+
timer = null;
|
|
5181
|
+
}
|
|
5182
|
+
|
|
5183
|
+
return { start, stop, sweep, refreshRules, maskRow, applyMaskRules, compileMaskRules };
|
|
5184
|
+
}
|
|
5185
|
+
|
|
5186
|
+
/** Install the reply-mask observer and keep its compiled rules in sync. */
|
|
5187
|
+
function installReplyMask(ctx) {
|
|
5188
|
+
const core = createReplyMaskCore({
|
|
5189
|
+
isEnabled: () => getSettings().contentRendering,
|
|
5190
|
+
rules: () => activeMaskRules(),
|
|
5191
|
+
});
|
|
5192
|
+
const enabled = () => getSettings().contentRendering;
|
|
5193
|
+
ctx.effect(() => {
|
|
5194
|
+
if (enabled()) core.start();
|
|
5195
|
+
const offSettings = subscribeSettings(() => {
|
|
5196
|
+
if (enabled()) { core.refreshRules(); core.start(); core.sweep(); }
|
|
5197
|
+
else core.stop();
|
|
5198
|
+
});
|
|
5199
|
+
const offRules = subscribeMaskRules(() => {
|
|
5200
|
+
core.refreshRules();
|
|
5201
|
+
if (enabled()) core.sweep();
|
|
5202
|
+
});
|
|
5203
|
+
return () => {
|
|
5204
|
+
offSettings();
|
|
5205
|
+
offRules();
|
|
5206
|
+
core.stop();
|
|
5207
|
+
};
|
|
5208
|
+
}, 'dsh-powerup: reply mask');
|
|
5209
|
+
return core;
|
|
5210
|
+
}
|
|
5211
|
+
|
|
4844
5212
|
function installStyles(ctx) {
|
|
4845
5213
|
try {
|
|
4846
5214
|
const style = document.createElement('style');
|
|
4847
5215
|
style.setAttribute('data-dsh-powerup', '');
|
|
4848
|
-
style.textContent = CSS + '\n' + LAUNCHER_CSS + '\n' + SESSION_SWITCH_CSS + '\n' + LOCATE_CSS + '\n' + SCROLL_TOP_CSS + '\n' + PROMPTS_CSS;
|
|
5216
|
+
style.textContent = CSS + '\n' + LAUNCHER_CSS + '\n' + SESSION_SWITCH_CSS + '\n' + LOCATE_CSS + '\n' + SCROLL_TOP_CSS + '\n' + RENDERING_CSS + '\n' + PROMPTS_CSS;
|
|
4849
5217
|
document.head.appendChild(style);
|
|
4850
5218
|
ctx.effect(() => () => style.remove(), 'dsh-powerup: styles');
|
|
4851
5219
|
} catch (error) {
|
|
@@ -7852,6 +8220,245 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
7852
8220
|
);
|
|
7853
8221
|
}
|
|
7854
8222
|
|
|
8223
|
+
/**
|
|
8224
|
+
* Shared editor for a list of mask rules. `scope` is 'global' or
|
|
8225
|
+
* 'workspace'; writes go through the matching store functions.
|
|
8226
|
+
*/
|
|
8227
|
+
function MaskRuleEditor({ scope, t }) {
|
|
8228
|
+
const rules = useMaskRules();
|
|
8229
|
+
const visible = rules.filter((rule) => (rule.scope || 'global') === scope);
|
|
8230
|
+
const commit = (next) => {
|
|
8231
|
+
if (scope === 'workspace') writeWorkspaceMaskRules(next);
|
|
8232
|
+
else writeGlobalMaskRules(next);
|
|
8233
|
+
};
|
|
8234
|
+
const update = (id, patch) => {
|
|
8235
|
+
commit(visible.map((rule) => (rule.id === id ? { ...rule, ...patch } : rule)));
|
|
8236
|
+
};
|
|
8237
|
+
const remove = (id) => {
|
|
8238
|
+
commit(visible.filter((rule) => rule.id !== id));
|
|
8239
|
+
};
|
|
8240
|
+
const add = () => {
|
|
8241
|
+
commit([...visible, { id: newId(), pattern: '', replacement: '', enabled: true, scope }]);
|
|
8242
|
+
};
|
|
8243
|
+
const title = scope === 'workspace' ? t('mask.workspaceTitle') : t('mask.globalTitle');
|
|
8244
|
+
return h('div', { className: 'dsh-powerup-mask-editor' },
|
|
8245
|
+
h('h3', { className: 'dsh-powerup-section-title' }, title),
|
|
8246
|
+
h('p', { className: 'dsh-powerup-card-desc' }, t('mask.hint')),
|
|
8247
|
+
...visible.map((rule) => {
|
|
8248
|
+
let invalid = false;
|
|
8249
|
+
if (rule.pattern !== '' && rule.regex !== false) {
|
|
8250
|
+
try { new RegExp(rule.pattern, 'gums'); } catch { invalid = true; }
|
|
8251
|
+
}
|
|
8252
|
+
return h('div', { key: rule.id, className: 'dsh-powerup-mask-row' },
|
|
8253
|
+
h('div', { className: 'dsh-powerup-mask-replacement' },
|
|
8254
|
+
h('input', {
|
|
8255
|
+
type: 'text',
|
|
8256
|
+
className: 'dsh-powerup-mask-input' + (invalid ? ' invalid' : ''),
|
|
8257
|
+
value: rule.pattern,
|
|
8258
|
+
placeholder: t('mask.patternPlaceholder'),
|
|
8259
|
+
'aria-label': t('mask.pattern'),
|
|
8260
|
+
title: invalid ? t('mask.invalid') : t('mask.pattern'),
|
|
8261
|
+
onChange: (event) => update(rule.id, { pattern: event.target.value }),
|
|
8262
|
+
}),
|
|
8263
|
+
h('button', {
|
|
8264
|
+
type: 'button',
|
|
8265
|
+
role: 'switch',
|
|
8266
|
+
'aria-checked': rule.regex !== false ? 'true' : 'false',
|
|
8267
|
+
className: 'dsh-powerup-mask-default' + (rule.regex !== false ? ' on' : ''),
|
|
8268
|
+
title: t('mask.regexHint'),
|
|
8269
|
+
'aria-label': t('mask.regexHint'),
|
|
8270
|
+
onClick: () => update(rule.id, { regex: rule.regex === false }),
|
|
8271
|
+
}, t('mask.regex')),
|
|
8272
|
+
),
|
|
8273
|
+
h('div', { className: 'dsh-powerup-mask-replacement' },
|
|
8274
|
+
h('input', {
|
|
8275
|
+
type: 'text',
|
|
8276
|
+
className: 'dsh-powerup-mask-input',
|
|
8277
|
+
value: rule.replacement,
|
|
8278
|
+
placeholder: t('mask.replacementPlaceholder'),
|
|
8279
|
+
'aria-label': t('mask.replacement'),
|
|
8280
|
+
onChange: (event) => update(rule.id, { replacement: event.target.value }),
|
|
8281
|
+
}),
|
|
8282
|
+
h('button', {
|
|
8283
|
+
type: 'button',
|
|
8284
|
+
className: 'dsh-powerup-mask-default',
|
|
8285
|
+
title: t('mask.useDefaultHint'),
|
|
8286
|
+
'aria-label': t('mask.useDefaultHint'),
|
|
8287
|
+
onClick: () => update(rule.id, { replacement: MASK_PLACEHOLDER }),
|
|
8288
|
+
}, t('mask.useDefault')),
|
|
8289
|
+
),
|
|
8290
|
+
h('button', {
|
|
8291
|
+
type: 'button',
|
|
8292
|
+
role: 'switch',
|
|
8293
|
+
'aria-checked': rule.enabled ? 'true' : 'false',
|
|
8294
|
+
className: 'dsh-powerup-switch',
|
|
8295
|
+
onClick: () => update(rule.id, { enabled: !rule.enabled }),
|
|
8296
|
+
}, invalid ? t('mask.invalid') : (rule.enabled ? t('page.enabled') : t('page.disabled'))),
|
|
8297
|
+
h('button', {
|
|
8298
|
+
type: 'button',
|
|
8299
|
+
className: 'dsh-powerup-prompt-new',
|
|
8300
|
+
onClick: () => remove(rule.id),
|
|
8301
|
+
}, t('mask.delete')),
|
|
8302
|
+
);
|
|
8303
|
+
}),
|
|
8304
|
+
visible.length === 0 ? h('p', { className: 'dsh-powerup-mask-empty' }, t('mask.empty')) : null,
|
|
8305
|
+
h('button', {
|
|
8306
|
+
type: 'button',
|
|
8307
|
+
className: 'dsh-powerup-prompt-new',
|
|
8308
|
+
onClick: add,
|
|
8309
|
+
}, t('mask.add')),
|
|
8310
|
+
);
|
|
8311
|
+
}
|
|
8312
|
+
|
|
8313
|
+
function useMaskRules() {
|
|
8314
|
+
const [revision, setRevision] = useState(0);
|
|
8315
|
+
useEffect(() => subscribeMaskRules(() => setRevision((v) => v + 1)), []);
|
|
8316
|
+
void revision;
|
|
8317
|
+
return [...globalMaskRules, ...workspaceMaskRules];
|
|
8318
|
+
}
|
|
8319
|
+
|
|
8320
|
+
/**
|
|
8321
|
+
* Two send buttons injected into the composer's right slot. Enter / the
|
|
8322
|
+
* host primary button keep their own behavior; we add explicit queued and
|
|
8323
|
+
* interrupt controls that bypass the system busy-time setting.
|
|
8324
|
+
*/
|
|
8325
|
+
function DualSendButtons({ sessionId, useInput, inputActions, ctx, t }) {
|
|
8326
|
+
const settings = useSettings();
|
|
8327
|
+
const draft = typeof useInput === 'function' ? useInput((s) => s.draft) : '';
|
|
8328
|
+
// Session-scope slots usually pass sessionId; fall back to the DOM
|
|
8329
|
+
// contract the rest of this plugin already relies on.
|
|
8330
|
+
const ownerId = () => {
|
|
8331
|
+
if (typeof sessionId === 'string' && sessionId !== '') return sessionId;
|
|
8332
|
+
try {
|
|
8333
|
+
const el = document.querySelector('[data-conversation-session]');
|
|
8334
|
+
const id = el === null ? null : el.getAttribute('data-conversation-session');
|
|
8335
|
+
return typeof id === 'string' && id !== '' ? id : '';
|
|
8336
|
+
} catch {
|
|
8337
|
+
return '';
|
|
8338
|
+
}
|
|
8339
|
+
};
|
|
8340
|
+
const trimmed = typeof draft === 'string' ? draft.trim() : '';
|
|
8341
|
+
const currentDraft = { trimmed, sessionId, inputActions, ctx };
|
|
8342
|
+
const send = (mode, text) => {
|
|
8343
|
+
const value = typeof text === 'string' ? text.trim() : trimmed;
|
|
8344
|
+
const id = ownerId();
|
|
8345
|
+
if (value === '' || id === '') return;
|
|
8346
|
+
try {
|
|
8347
|
+
const sessions = ctx.get('sessions');
|
|
8348
|
+
const binding = sessions?.binding?.(id);
|
|
8349
|
+
const session = binding?.session;
|
|
8350
|
+
if (session === undefined || typeof session.prompt !== 'function') return;
|
|
8351
|
+
const handle = typeof session.beginSubmission === 'function'
|
|
8352
|
+
? session.beginSubmission({ mode, text: value, attachments: [] })
|
|
8353
|
+
: null;
|
|
8354
|
+
void session.prompt([{ type: 'text', text: value }], mode, undefined, handle?.requestId);
|
|
8355
|
+
if (typeof inputActions?.setDraft === 'function') inputActions.setDraft('');
|
|
8356
|
+
} catch (error) {
|
|
8357
|
+
console.warn('[dsh-powerup] dual send failed:', error?.message ?? error);
|
|
8358
|
+
}
|
|
8359
|
+
};
|
|
8360
|
+
// Capture-phase keymap overrides the host's busy-time send behavior:
|
|
8361
|
+
// Enter always queues, Ctrl/Cmd+Shift+Enter always interrupts. Plain
|
|
8362
|
+
// Shift+Enter (newline), IME composition, and an open command listbox
|
|
8363
|
+
// are left to the host.
|
|
8364
|
+
useEffect(() => {
|
|
8365
|
+
if (!settings.dualSend || typeof document === 'undefined' || document === null) return undefined;
|
|
8366
|
+
const onKeyDown = (event) => {
|
|
8367
|
+
if (event.key !== 'Enter' || event.isComposing === true || event.repeat === true) return;
|
|
8368
|
+
const target = event.target;
|
|
8369
|
+
const editor = target !== null && typeof target.closest === 'function'
|
|
8370
|
+
? target.closest('[data-composer-input]')
|
|
8371
|
+
: null;
|
|
8372
|
+
if (editor === null) return;
|
|
8373
|
+
if (editor.hasAttribute('data-composer-composing')) return;
|
|
8374
|
+
// An empty draft is the host's retry gesture; leave it alone.
|
|
8375
|
+
if (trimmed === '') return;
|
|
8376
|
+
// Let the host resolve Enter while a / or @ menu (or a selected
|
|
8377
|
+
// command chip) is open — the menu can be portaled outside the card.
|
|
8378
|
+
const openMenu = document.querySelector?.(
|
|
8379
|
+
'[aria-haspopup="listbox"][aria-expanded="true"], [aria-haspopup="menu"][aria-expanded="true"], [role="listbox"]:not([hidden]), [role="menu"]:not([hidden])',
|
|
8380
|
+
);
|
|
8381
|
+
if (openMenu !== null && openMenu !== undefined) return;
|
|
8382
|
+
if (editor.hasAttribute('data-composer-chip-selected')) return;
|
|
8383
|
+
const interrupt = event.shiftKey && (event.ctrlKey || event.metaKey);
|
|
8384
|
+
if (event.shiftKey && !interrupt) return; // plain Shift+Enter = newline
|
|
8385
|
+
if (!interrupt && (event.ctrlKey || event.metaKey || event.altKey)) return;
|
|
8386
|
+
event.preventDefault();
|
|
8387
|
+
event.stopPropagation();
|
|
8388
|
+
send(interrupt ? 'steer' : 'queue');
|
|
8389
|
+
};
|
|
8390
|
+
document.addEventListener('keydown', onKeyDown, true);
|
|
8391
|
+
return () => document.removeEventListener('keydown', onKeyDown, true);
|
|
8392
|
+
}, [settings.dualSend, sessionId, draft, ctx, inputActions]);
|
|
8393
|
+
void currentDraft;
|
|
8394
|
+
if (!settings.dualSend) return null;
|
|
8395
|
+
return h('div', { className: 'dsh-powerup-dual-send' },
|
|
8396
|
+
h('button', {
|
|
8397
|
+
type: 'button',
|
|
8398
|
+
className: 'dsh-powerup-send',
|
|
8399
|
+
'data-kind': 'wait',
|
|
8400
|
+
'aria-label': t('send.waitHint'),
|
|
8401
|
+
title: t('send.waitHint'),
|
|
8402
|
+
disabled: trimmed === '',
|
|
8403
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
8404
|
+
onClick: () => send('queue'),
|
|
8405
|
+
}, h('svg', { viewBox: '0 0 16 16', width: 16, height: 16, 'aria-hidden': 'true' },
|
|
8406
|
+
h('path', { d: 'M3 8h9M8.5 4.5 12 8l-3.5 3.5', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' }))),
|
|
8407
|
+
h('button', {
|
|
8408
|
+
type: 'button',
|
|
8409
|
+
className: 'dsh-powerup-send',
|
|
8410
|
+
'data-kind': 'interrupt',
|
|
8411
|
+
'aria-label': t('send.interruptHint'),
|
|
8412
|
+
title: t('send.interruptHint'),
|
|
8413
|
+
disabled: trimmed === '',
|
|
8414
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
8415
|
+
onClick: () => send('steer'),
|
|
8416
|
+
}, h('svg', { viewBox: '0 0 16 16', width: 16, height: 16, 'aria-hidden': 'true' },
|
|
8417
|
+
h('path', { d: 'M8 2v12M3 6l5-4 5 4', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' }))),
|
|
8418
|
+
);
|
|
8419
|
+
}
|
|
8420
|
+
|
|
8421
|
+
/**
|
|
8422
|
+
* Conversation View tab for per-workspace Power-Up settings. Registered
|
|
8423
|
+
* after Trajectory so it appears last in the header tab row.
|
|
8424
|
+
*/
|
|
8425
|
+
function WorkspaceSettingsView({ ctx, sessionId, useWorkspaces }) {
|
|
8426
|
+
const settings = useSettings();
|
|
8427
|
+
const rules = useMaskRules();
|
|
8428
|
+
const [, forceLocale] = useState(0);
|
|
8429
|
+
const t = useCallback((key, params) => translateCurrent(key, params), []);
|
|
8430
|
+
useEffect(() => {
|
|
8431
|
+
const off = ctx.locale?.subscribe?.(() => forceLocale((v) => v + 1));
|
|
8432
|
+
return typeof off === 'function' ? off : undefined;
|
|
8433
|
+
}, [ctx]);
|
|
8434
|
+
// Prefer the slot's sessionId; fall back to the live DOM contract.
|
|
8435
|
+
let ownerId = sessionId;
|
|
8436
|
+
if (typeof ownerId !== 'string' || ownerId === '') {
|
|
8437
|
+
try {
|
|
8438
|
+
const el = document.querySelector('[data-conversation-session]');
|
|
8439
|
+
const id = el === null ? null : el.getAttribute('data-conversation-session');
|
|
8440
|
+
if (typeof id === 'string' && id !== '') ownerId = id;
|
|
8441
|
+
} catch { /* keep the empty id */ }
|
|
8442
|
+
}
|
|
8443
|
+
const workspaceSelector = useMemo(() => (snapshot) => resolveWorkspaceIdFromSnapshot(snapshot, ownerId), [ownerId]);
|
|
8444
|
+
const workspaceId = typeof useWorkspaces === 'function' ? useWorkspaces(workspaceSelector) ?? '' : '';
|
|
8445
|
+
useEffect(() => {
|
|
8446
|
+
if (typeof workspaceId === 'string' && workspaceId !== '') void loadWorkspaceMaskRules(workspaceId);
|
|
8447
|
+
}, [workspaceId]);
|
|
8448
|
+
void rules; void settings;
|
|
8449
|
+
return h('div', { className: 'dsh-powerup-page' },
|
|
8450
|
+
h('div', { className: 'dsh-powerup-shell' },
|
|
8451
|
+
h('header', { className: 'dsh-powerup-hero' },
|
|
8452
|
+
h('div', { className: 'dsh-powerup-hero-copy' },
|
|
8453
|
+
h('h1', null, t('mask.sessionTitle')),
|
|
8454
|
+
h('p', null, t('mask.sessionDesc')),
|
|
8455
|
+
),
|
|
8456
|
+
),
|
|
8457
|
+
h(MaskRuleEditor, { scope: 'workspace', t }),
|
|
8458
|
+
),
|
|
8459
|
+
);
|
|
8460
|
+
}
|
|
8461
|
+
|
|
7855
8462
|
function PromptManager({ ctx }) {
|
|
7856
8463
|
const prompts = usePrompts();
|
|
7857
8464
|
const [, forceLocale] = useState(0);
|
|
@@ -8094,7 +8701,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8094
8701
|
}, []);
|
|
8095
8702
|
useEffect(() => {
|
|
8096
8703
|
if (settings.workspacePrompts === false && tab === 'prompts') setTab('features');
|
|
8097
|
-
|
|
8704
|
+
if (settings.contentRendering === false && tab === 'mask') setTab('features');
|
|
8705
|
+
}, [settings.workspacePrompts, settings.contentRendering, tab]);
|
|
8098
8706
|
const t = (key, params) => translateCurrent(key, params);
|
|
8099
8707
|
const actions = [
|
|
8100
8708
|
{ id: 'copy', icon: CopyIcon, name: t('action.copy'), hint: t('action.copyHint') },
|
|
@@ -8176,6 +8784,15 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8176
8784
|
className: 'dsh-powerup-tab' + (tab === 'features' ? ' on' : ''),
|
|
8177
8785
|
onClick: () => setTab('features'),
|
|
8178
8786
|
}, t('prompts.tabFeatures')),
|
|
8787
|
+
settings.contentRendering !== false
|
|
8788
|
+
? h('button', {
|
|
8789
|
+
type: 'button',
|
|
8790
|
+
role: 'tab',
|
|
8791
|
+
'aria-selected': tab === 'mask' ? 'true' : 'false',
|
|
8792
|
+
className: 'dsh-powerup-tab' + (tab === 'mask' ? ' on' : ''),
|
|
8793
|
+
onClick: () => setTab('mask'),
|
|
8794
|
+
}, t('mask.tab'))
|
|
8795
|
+
: null,
|
|
8179
8796
|
settings.workspacePrompts !== false
|
|
8180
8797
|
? h('button', {
|
|
8181
8798
|
type: 'button',
|
|
@@ -8197,6 +8814,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8197
8814
|
featureCard('sessionSwitch', QuickIcon, 'page.sessionSwitchTitle', 'page.sessionSwitchDesc', 'page.sessionSwitchHow'),
|
|
8198
8815
|
featureCard('locateSession', LocateIcon, 'page.locateTitle', 'page.locateDesc', 'page.locateHow'),
|
|
8199
8816
|
featureCard('scrollToTop', ScrollTopIcon, 'page.scrollToTopTitle', 'page.scrollToTopDesc', 'page.scrollToTopHow'),
|
|
8817
|
+
featureCard('contentRendering', PowerUpLineIcon, 'page.renderingTitle', 'page.renderingDesc', 'page.renderingHow'),
|
|
8818
|
+
featureCard('dualSend', LauncherIcon, 'page.dualSendTitle', 'page.dualSendDesc', 'page.dualSendHow'),
|
|
8200
8819
|
featureCard('workspacePrompts', TagIcon, 'page.promptsTitle', 'page.promptsDesc', 'page.promptsHow'),
|
|
8201
8820
|
featureCard('jobStop', StopIcon, 'page.jobStopTitle', 'page.jobStopDesc', 'page.jobStopHow'),
|
|
8202
8821
|
featureCard('update', UpdateIcon, 'page.updateTitle', 'page.updateDesc', 'page.updateHow', oneClickDetail),
|
|
@@ -8212,9 +8831,11 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8212
8831
|
),
|
|
8213
8832
|
),
|
|
8214
8833
|
tabs,
|
|
8215
|
-
tab === '
|
|
8216
|
-
? h(
|
|
8217
|
-
:
|
|
8834
|
+
tab === 'mask' && settings.contentRendering !== false
|
|
8835
|
+
? h(MaskRuleEditor, { scope: 'global', t })
|
|
8836
|
+
: tab === 'prompts' && settings.workspacePrompts !== false
|
|
8837
|
+
? h(PromptManager, { ctx })
|
|
8838
|
+
: featuresContent,
|
|
8218
8839
|
h('footer', { className: 'dsh-powerup-foot' },
|
|
8219
8840
|
h('span', null, format(t('page.footer'), { version: VERSION })),
|
|
8220
8841
|
h('span', { className: 'dsh-powerup-dot' }),
|
|
@@ -8262,6 +8883,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8262
8883
|
installSessionSwitcher(ctx);
|
|
8263
8884
|
installLocateSession(ctx);
|
|
8264
8885
|
installScrollToTop(ctx);
|
|
8886
|
+
installReplyMask(ctx);
|
|
8265
8887
|
|
|
8266
8888
|
const slots = ctx.get('slots');
|
|
8267
8889
|
if (slots === undefined || typeof slots.inject !== 'function' || typeof slots.register !== 'function') {
|
|
@@ -8303,6 +8925,26 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8303
8925
|
order: 60,
|
|
8304
8926
|
}, HeroPromptsControl, 'dsh-powerup: prompt picker');
|
|
8305
8927
|
|
|
8928
|
+
// Session-scope composer controls. These receive sessionId/useInput/
|
|
8929
|
+
// inputActions from the host's conversation slot wiring; the t() locale
|
|
8930
|
+
// seat is provided by the slot, so we wrap to use the plugin dictionary.
|
|
8931
|
+
register('conversation.input.right', {
|
|
8932
|
+
id: 'powerup-dual-send',
|
|
8933
|
+
order: 80,
|
|
8934
|
+
}, (props) => h(DualSendButtons, {
|
|
8935
|
+
...props,
|
|
8936
|
+
ctx,
|
|
8937
|
+
t: (key, params) => translateCurrent(key, params),
|
|
8938
|
+
}), 'dsh-powerup: dual send buttons');
|
|
8939
|
+
|
|
8940
|
+
// Per-workspace Power-Up settings as a Conversation View tab, ordered
|
|
8941
|
+
// after the host's Trajectory view (order 10).
|
|
8942
|
+
register('conversation.view', {
|
|
8943
|
+
id: 'powerup-settings',
|
|
8944
|
+
order: 20,
|
|
8945
|
+
label: () => translateCurrent('mask.viewTabLabel'),
|
|
8946
|
+
}, (props) => h(WorkspaceSettingsView, { ...props, ctx }), 'dsh-powerup: workspace settings view');
|
|
8947
|
+
|
|
8306
8948
|
// The update control drives the built-in plugin manager through its
|
|
8307
8949
|
// `remote.pluginManager` namespace. Register it in a nested inject scope
|
|
8308
8950
|
// so a late-provided service is observed instead of sampled once.
|
|
@@ -8361,6 +9003,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8361
9003
|
SESSION_SWITCH_CSS,
|
|
8362
9004
|
LOCATE_CSS,
|
|
8363
9005
|
SCROLL_TOP_CSS,
|
|
9006
|
+
RENDERING_CSS,
|
|
8364
9007
|
PROMPTS_CSS,
|
|
8365
9008
|
PROMPTS_LAST_KEY,
|
|
8366
9009
|
promptCreateDraft,
|
|
@@ -8441,6 +9084,18 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8441
9084
|
operationReason,
|
|
8442
9085
|
restorePreviousBundle,
|
|
8443
9086
|
runOneClickUpdate,
|
|
9087
|
+
MASK_RULES_KEY,
|
|
9088
|
+
MASK_PLACEHOLDER,
|
|
9089
|
+
readGlobalMaskRules,
|
|
9090
|
+
writeGlobalMaskRules,
|
|
9091
|
+
normalizeMaskRule,
|
|
9092
|
+
activeMaskRules,
|
|
9093
|
+
compileMaskRules,
|
|
9094
|
+
applyMaskRules,
|
|
9095
|
+
createReplyMaskCore,
|
|
9096
|
+
DualSendButtons,
|
|
9097
|
+
MaskRuleEditor,
|
|
9098
|
+
WorkspaceSettingsView,
|
|
8444
9099
|
},
|
|
8445
9100
|
};
|
|
8446
9101
|
},
|
package/index.js
CHANGED
|
@@ -50,9 +50,11 @@ const SELF_UPDATE_DELAY_MS = 600;
|
|
|
50
50
|
/** Request body bound for the small JSON commands. */
|
|
51
51
|
const BODY_LIMIT = 16 * 1024;
|
|
52
52
|
|
|
53
|
-
/** Per-workspace
|
|
53
|
+
/** Per-workspace state files live under the workspace's own .dsh directory. */
|
|
54
54
|
const PROMPTS_DIR = join('.dsh', 'dsh-powerup');
|
|
55
55
|
const PROMPTS_FILE = 'prompts.json';
|
|
56
|
+
/** Per-workspace mask rules used by the content-rendering enhancement. */
|
|
57
|
+
const MASK_RULES_FILE = 'mask-rules.json';
|
|
56
58
|
|
|
57
59
|
/** The moment this Host process started; a profile file newer than it may await a restart. */
|
|
58
60
|
const HOST_STARTED_AT = Date.now() - process.uptime() * 1000;
|
|
@@ -348,14 +350,15 @@ export async function performSelfUpdate(ctx, version, registry, options = {}) {
|
|
|
348
350
|
}
|
|
349
351
|
|
|
350
352
|
/**
|
|
351
|
-
* Absolute path of one workspace's
|
|
353
|
+
* Absolute path of one workspace's state file. The workspace path is
|
|
352
354
|
* canonical (realpath) and the id is a uuid, so a stray id can never escape
|
|
353
355
|
* into an arbitrary directory.
|
|
354
356
|
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
355
357
|
* @param {string} workspaceId
|
|
358
|
+
* @param {string} fileName
|
|
356
359
|
* @returns {string | undefined}
|
|
357
360
|
*/
|
|
358
|
-
function
|
|
361
|
+
function workspaceStorePath(ctx, workspaceId, fileName) {
|
|
359
362
|
if (typeof workspaceId !== 'string' || workspaceId === '') return undefined;
|
|
360
363
|
const registry = ctx?.get?.('workspaceRegistry');
|
|
361
364
|
const workspace = registry?.get?.(workspaceId);
|
|
@@ -363,15 +366,20 @@ function promptStorePath(ctx, workspaceId) {
|
|
|
363
366
|
return undefined;
|
|
364
367
|
}
|
|
365
368
|
const root = resolvePath(workspace.path);
|
|
366
|
-
const target = resolvePath(root, PROMPTS_DIR,
|
|
369
|
+
const target = resolvePath(root, PROMPTS_DIR, fileName);
|
|
367
370
|
// The store must stay inside the workspace, whatever the registry returned.
|
|
368
371
|
const prefix = root.endsWith(sep) ? root : root + sep;
|
|
369
372
|
if (!target.startsWith(prefix)) return undefined;
|
|
370
373
|
return target;
|
|
371
374
|
}
|
|
372
375
|
|
|
373
|
-
/**
|
|
374
|
-
function
|
|
376
|
+
/** One workspace's prompt store path. */
|
|
377
|
+
function promptStorePath(ctx, workspaceId) {
|
|
378
|
+
return workspaceStorePath(ctx, workspaceId, PROMPTS_FILE);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Read one workspace's JSON list from disk; a missing file is an empty list. */
|
|
382
|
+
function readJsonStore(filePath) {
|
|
375
383
|
try {
|
|
376
384
|
const parsed = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
377
385
|
return Array.isArray(parsed) ? parsed : [];
|
|
@@ -381,6 +389,11 @@ function readPromptStore(filePath) {
|
|
|
381
389
|
}
|
|
382
390
|
}
|
|
383
391
|
|
|
392
|
+
/** Read one workspace's prompts from disk; a missing file is an empty list. */
|
|
393
|
+
function readPromptStore(filePath) {
|
|
394
|
+
return readJsonStore(filePath);
|
|
395
|
+
}
|
|
396
|
+
|
|
384
397
|
/**
|
|
385
398
|
* @param {import('node:http').IncomingMessage} req
|
|
386
399
|
* @param {import('node:http').ServerResponse} res
|
|
@@ -394,11 +407,51 @@ async function handle(req, res, ctx) {
|
|
|
394
407
|
|
|
395
408
|
const url = new URL(req.url ?? ROUTE, 'http://localhost');
|
|
396
409
|
const op = url.pathname.slice(ROUTE.length).replace(/^\/+/u, '') || url.searchParams.get('op') || '';
|
|
397
|
-
if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts') {
|
|
410
|
+
if (op !== '' && op !== 'restart' && op !== 'close' && op !== 'self-update' && op !== 'audit' && op !== 'job-kill' && op !== 'prompts' && op !== 'mask-rules') {
|
|
398
411
|
sendJson(res, { ok: false, error: 'not-found' }, 404);
|
|
399
412
|
return;
|
|
400
413
|
}
|
|
401
414
|
|
|
415
|
+
if (op === 'mask-rules') {
|
|
416
|
+
const targetId = req.method === 'GET'
|
|
417
|
+
? (url.searchParams.get('workspaceId') ?? '')
|
|
418
|
+
: '';
|
|
419
|
+
let workspaceId = targetId;
|
|
420
|
+
if (req.method === 'POST') {
|
|
421
|
+
try {
|
|
422
|
+
const body = await readJsonBody(req);
|
|
423
|
+
workspaceId = typeof body?.workspaceId === 'string' ? body.workspaceId.trim() : '';
|
|
424
|
+
const filePath = workspaceStorePath(ctx, workspaceId, MASK_RULES_FILE);
|
|
425
|
+
if (filePath === undefined) {
|
|
426
|
+
sendJson(res, { ok: false, code: 'workspace-not-found', error: 'workspace not found' }, 404);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const rules = Array.isArray(body?.rules) ? body.rules : [];
|
|
430
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
431
|
+
writeFileSync(filePath, JSON.stringify(rules, null, 2) + '\n', 'utf8');
|
|
432
|
+
sendJson(res, { ok: true, workspaceId, rules });
|
|
433
|
+
} catch (error) {
|
|
434
|
+
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
435
|
+
}
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
if (req.method !== 'GET') {
|
|
439
|
+
sendJson(res, { ok: false, error: 'method-not-allowed' }, 405);
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
try {
|
|
443
|
+
const filePath = workspaceStorePath(ctx, workspaceId, MASK_RULES_FILE);
|
|
444
|
+
if (filePath === undefined) {
|
|
445
|
+
sendJson(res, { ok: false, code: 'workspace-not-found', error: 'workspace not found' }, 404);
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
sendJson(res, { ok: true, workspaceId, rules: readJsonStore(filePath) });
|
|
449
|
+
} catch (error) {
|
|
450
|
+
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
451
|
+
}
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
402
455
|
if (op === 'prompts') {
|
|
403
456
|
// The active workspace's directory holds the whole prompt store, including
|
|
404
457
|
// prompts scoped to other workspaces and the "all workspaces" ones.
|
|
@@ -591,6 +644,9 @@ export const __test = {
|
|
|
591
644
|
profileDirectory,
|
|
592
645
|
promptStorePath,
|
|
593
646
|
readPromptStore,
|
|
647
|
+
workspaceStorePath,
|
|
648
|
+
readJsonStore,
|
|
649
|
+
MASK_RULES_FILE,
|
|
594
650
|
HOST_STARTED_AT,
|
|
595
651
|
SELF_VERSION,
|
|
596
652
|
ROUTE,
|
package/locale/en.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Power-Up",
|
|
4
|
-
"description": "
|
|
4
|
+
"description": "Independently toggleable upgrades for DeepSeek Harness on the Power-Up page: trajectory context menu and step references, job stop reasons, one-click plugin install, sidebar icon grid and back-to-top, session switching and locating, workspace prompts, plus conversation rendering enhancements (regex reply masking) and dual send buttons (queued/interrupt)."
|
|
5
5
|
}
|
|
6
6
|
}
|
package/locale/zh.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"meta": {
|
|
3
3
|
"title": "Power-Up",
|
|
4
|
-
"description": "为 DeepSeek Harness 提供一组可在 Power-Up
|
|
4
|
+
"description": "为 DeepSeek Harness 提供一组可在 Power-Up 页面独立开关的增强:轨迹右键菜单与步骤引用、后台任务停止原因、插件一键安装、侧边栏图标网格与回到顶部、会话切换与定位、工作区提示词,以及会话内容渲染增强(回复内容正则屏蔽)和双发送按钮(等待/插话)。"
|
|
5
5
|
}
|
|
6
6
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
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, and workspace prompts — each toggled independently on the Power-Up page.",
|
|
5
5
|
"icon": "./icon.svg",
|
|
6
6
|
"type": "module",
|