@restregular/dsh-powerup 0.9.1 → 0.9.3
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 +10 -5
- package/client.js +115 -65
- package/index.js +68 -65
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -185,9 +185,11 @@ Save reusable prompts and drop one into a new session without retyping it.
|
|
|
185
185
|
characters of the body. A blank workspace scope makes the prompt available in
|
|
186
186
|
every workspace; otherwise it appears only in that one.
|
|
187
187
|
- In the New Session row, to the right of the Agent preset, a dropdown lists the
|
|
188
|
-
prompts available in the current workspace.
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
prompts available in the current workspace. In an **ongoing session** the same
|
|
189
|
+
picker also appears in the composer's bottom tool row, just right of the
|
|
190
|
+
permission dropdown; there its menu opens **upward**. **Clicking a prompt
|
|
191
|
+
fills the composer** so you can keep editing before sending. Each row also has
|
|
192
|
+
a **Send now** button that fills and submits immediately.
|
|
191
193
|
- **Create a new prompt…** in the dropdown opens an in-conversation dialog. A
|
|
192
194
|
prompt created here is pinned to the current workspace — you may only keep
|
|
193
195
|
that scope or switch to **All workspaces**, never pick another workspace.
|
|
@@ -389,8 +391,11 @@ Each rule has:
|
|
|
389
391
|
|
|
390
392
|
Global rules are managed on the Power-Up page's **Masking** tab. Workspace rules
|
|
391
393
|
are managed from the **PowerUp** tab in any conversation header (it appears
|
|
392
|
-
after Trajectory)
|
|
393
|
-
|
|
394
|
+
after Trajectory). Both prompts and workspace rules live in ONE central store
|
|
395
|
+
under `~/.dsh/dsh-powerup/` (`prompts.json` / `mask-rules.json`), with each
|
|
396
|
+
record carrying its own workspace id, so the settings page can manage every
|
|
397
|
+
workspace together. Older per-workspace files are migrated automatically on
|
|
398
|
+
first access.
|
|
394
399
|
|
|
395
400
|
### Dual send buttons
|
|
396
401
|
|
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.9.
|
|
86
|
+
const VERSION = '0.9.3';
|
|
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. */
|
|
@@ -786,14 +786,15 @@
|
|
|
786
786
|
}
|
|
787
787
|
|
|
788
788
|
// ------------------------------------------------------------------
|
|
789
|
-
// Workspace prompts store.
|
|
790
|
-
//
|
|
791
|
-
//
|
|
792
|
-
//
|
|
789
|
+
// Workspace prompts store. All workspaces' prompts live in ONE central
|
|
790
|
+
// file (~/.dsh/dsh-powerup/prompts.json) through a Host route; each
|
|
791
|
+
// record carries its own workspaceId ('' = global). The browser keeps an
|
|
792
|
+
// in-memory cache of the whole list so the hero dropdown and the
|
|
793
|
+
// management tab see every workspace together.
|
|
793
794
|
// ------------------------------------------------------------------
|
|
794
795
|
const PROMPTS_API = '/dsh-powerup/api/prompts';
|
|
795
796
|
let promptsCache = [];
|
|
796
|
-
let
|
|
797
|
+
let promptsLoaded = false;
|
|
797
798
|
|
|
798
799
|
/** Normalize an arbitrary value into a clean prompt record. */
|
|
799
800
|
function normalizePrompt(item) {
|
|
@@ -812,17 +813,14 @@
|
|
|
812
813
|
}
|
|
813
814
|
|
|
814
815
|
/**
|
|
815
|
-
* Load the
|
|
816
|
-
*
|
|
817
|
-
* open provides the file; a missing file is simply an empty store.
|
|
816
|
+
* Load the whole central store once. The list includes every workspace's
|
|
817
|
+
* prompts; callers filter by workspaceId through `promptsForWorkspace`.
|
|
818
818
|
*/
|
|
819
|
-
async function loadPrompts(
|
|
820
|
-
|
|
821
|
-
|
|
819
|
+
async function loadPrompts() {
|
|
820
|
+
if (promptsLoaded) return promptsCache;
|
|
821
|
+
promptsLoaded = true;
|
|
822
822
|
try {
|
|
823
|
-
const response = await fetch(PROMPTS_API
|
|
824
|
-
headers: { accept: 'application/json' },
|
|
825
|
-
});
|
|
823
|
+
const response = await fetch(PROMPTS_API, { headers: { accept: 'application/json' } });
|
|
826
824
|
const data = response.ok ? await response.json() : null;
|
|
827
825
|
const list = data !== null && Array.isArray(data.prompts) ? data.prompts : [];
|
|
828
826
|
promptsCache = list.map(normalizePrompt).filter(Boolean);
|
|
@@ -836,12 +834,12 @@
|
|
|
836
834
|
function writePrompts(list) {
|
|
837
835
|
const next = (Array.isArray(list) ? list : []).map(normalizePrompt).filter(Boolean);
|
|
838
836
|
promptsCache = next;
|
|
837
|
+
promptsLoaded = true;
|
|
839
838
|
emitPrompts();
|
|
840
|
-
const id = promptStoreWorkspace;
|
|
841
839
|
fetch(PROMPTS_API, {
|
|
842
840
|
method: 'POST',
|
|
843
841
|
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
844
|
-
body: JSON.stringify({
|
|
842
|
+
body: JSON.stringify({ prompts: next }),
|
|
845
843
|
}).catch(() => {
|
|
846
844
|
/* The in-memory list still works for this page. */
|
|
847
845
|
});
|
|
@@ -874,15 +872,18 @@
|
|
|
874
872
|
|
|
875
873
|
// ------------------------------------------------------------------
|
|
876
874
|
// Mask rules for the content-rendering enhancement.
|
|
877
|
-
// Global rules live in localStorage
|
|
878
|
-
//
|
|
879
|
-
//
|
|
875
|
+
// Global rules live in localStorage (already shared by every workspace
|
|
876
|
+
// in this browser). Workspace rules live in ONE central file
|
|
877
|
+
// (~/.dsh/dsh-powerup/mask-rules.json) via a Host route, together with
|
|
878
|
+
// every other workspace's rules; the client filters by workspaceId.
|
|
879
|
+
// Both lists share one normalize/compile helper.
|
|
880
880
|
// ------------------------------------------------------------------
|
|
881
881
|
const MASK_RULES_KEY = 'dsh-powerup:mask-rules:v1';
|
|
882
882
|
const MASK_RULES_API = '/dsh-powerup/api/mask-rules';
|
|
883
883
|
const MASK_PLACEHOLDER = '[已屏蔽]';
|
|
884
884
|
let globalMaskRules = readGlobalMaskRules();
|
|
885
|
-
let
|
|
885
|
+
let allWorkspaceMaskRules = [];
|
|
886
|
+
let maskRulesLoaded = false;
|
|
886
887
|
let maskRulesWorkspace = '';
|
|
887
888
|
const maskRulesListeners = new Set();
|
|
888
889
|
|
|
@@ -896,6 +897,7 @@
|
|
|
896
897
|
enabled: item.enabled !== false,
|
|
897
898
|
// Existing rules predate this flag and were regexes, so default true.
|
|
898
899
|
regex: item.regex !== false,
|
|
900
|
+
workspaceId: typeof item.workspaceId === 'string' ? item.workspaceId : '',
|
|
899
901
|
scope: item.scope === 'workspace' ? 'workspace' : 'global',
|
|
900
902
|
};
|
|
901
903
|
}
|
|
@@ -919,32 +921,44 @@
|
|
|
919
921
|
emitMaskRules();
|
|
920
922
|
}
|
|
921
923
|
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
924
|
+
/** Workspace rules belonging to one workspace id. */
|
|
925
|
+
function workspaceRulesFor(id) {
|
|
926
|
+
const ws = typeof id === 'string' ? id : '';
|
|
927
|
+
return allWorkspaceMaskRules.filter((rule) => rule.workspaceId === ws);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** Load the whole central rules file once (all workspaces). */
|
|
931
|
+
async function loadWorkspaceMaskRules() {
|
|
932
|
+
if (maskRulesLoaded) return allWorkspaceMaskRules;
|
|
933
|
+
maskRulesLoaded = true;
|
|
925
934
|
try {
|
|
926
|
-
const response = await fetch(MASK_RULES_API
|
|
927
|
-
headers: { accept: 'application/json' },
|
|
928
|
-
});
|
|
935
|
+
const response = await fetch(MASK_RULES_API, { headers: { accept: 'application/json' } });
|
|
929
936
|
const data = response.ok ? await response.json() : null;
|
|
930
937
|
const rules = data !== null && Array.isArray(data.rules) ? data.rules : [];
|
|
931
|
-
|
|
932
|
-
.map((rule) => ({ ...rule, scope: 'workspace' }));
|
|
938
|
+
allWorkspaceMaskRules = rules.map(normalizeMaskRule).filter(Boolean)
|
|
939
|
+
.map((rule) => ({ ...rule, scope: 'workspace', workspaceId: rule.workspaceId ?? '' }));
|
|
933
940
|
} catch {
|
|
934
941
|
/* Host unavailable: keep the last known list. */
|
|
935
942
|
}
|
|
936
943
|
emitMaskRules();
|
|
937
|
-
return
|
|
944
|
+
return allWorkspaceMaskRules;
|
|
938
945
|
}
|
|
939
946
|
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
947
|
+
/** Replace the rules of one workspace, leaving other workspaces intact. */
|
|
948
|
+
function writeWorkspaceMaskRules(list, workspaceId) {
|
|
949
|
+
const ws = typeof workspaceId === 'string' ? workspaceId : maskRulesWorkspace;
|
|
950
|
+
const next = (Array.isArray(list) ? list : []).map(normalizeMaskRule).filter(Boolean)
|
|
951
|
+
.map((rule) => ({ ...rule, scope: 'workspace', workspaceId: ws }));
|
|
952
|
+
allWorkspaceMaskRules = [
|
|
953
|
+
...allWorkspaceMaskRules.filter((rule) => rule.workspaceId !== ws),
|
|
954
|
+
...next,
|
|
955
|
+
];
|
|
956
|
+
maskRulesLoaded = true;
|
|
943
957
|
emitMaskRules();
|
|
944
958
|
fetch(MASK_RULES_API, {
|
|
945
959
|
method: 'POST',
|
|
946
960
|
headers: { 'content-type': 'application/json', accept: 'application/json' },
|
|
947
|
-
body: JSON.stringify({
|
|
961
|
+
body: JSON.stringify({ rules: allWorkspaceMaskRules }),
|
|
948
962
|
}).catch(() => {
|
|
949
963
|
/* The in-memory list still works this page. */
|
|
950
964
|
});
|
|
@@ -962,7 +976,9 @@
|
|
|
962
976
|
|
|
963
977
|
/** Rules that apply to the current workspace: global plus its own. */
|
|
964
978
|
function activeMaskRules() {
|
|
965
|
-
|
|
979
|
+
const ws = typeof maskRulesWorkspace === 'string' ? maskRulesWorkspace : '';
|
|
980
|
+
return [...globalMaskRules, ...workspaceRulesFor(ws)]
|
|
981
|
+
.filter((rule) => rule.enabled && rule.pattern !== '');
|
|
966
982
|
}
|
|
967
983
|
|
|
968
984
|
/** Escape a literal string so it can be used as an exact regex source. */
|
|
@@ -1022,14 +1038,10 @@
|
|
|
1022
1038
|
return t('prompts.summaryFallback');
|
|
1023
1039
|
}
|
|
1024
1040
|
|
|
1025
|
-
function usePrompts(
|
|
1041
|
+
function usePrompts() {
|
|
1026
1042
|
const [value, setValue] = useState(readPrompts);
|
|
1027
1043
|
useEffect(() => subscribePrompts(() => setValue(readPrompts())), []);
|
|
1028
|
-
useEffect(() => {
|
|
1029
|
-
if (typeof workspaceId === 'string' && workspaceId !== '') {
|
|
1030
|
-
void loadPrompts(workspaceId);
|
|
1031
|
-
}
|
|
1032
|
-
}, [workspaceId]);
|
|
1044
|
+
useEffect(() => { void loadPrompts(); }, []);
|
|
1033
1045
|
return value;
|
|
1034
1046
|
}
|
|
1035
1047
|
|
|
@@ -2741,7 +2753,8 @@
|
|
|
2741
2753
|
? resolveWorkspaceIdFromSnapshot(workspaces.list.getSnapshot(), sessionId)
|
|
2742
2754
|
: '';
|
|
2743
2755
|
if (typeof wsId === 'string' && wsId !== '' && wsId !== maskRulesWorkspace) {
|
|
2744
|
-
|
|
2756
|
+
maskRulesWorkspace = wsId;
|
|
2757
|
+
void loadWorkspaceMaskRules();
|
|
2745
2758
|
}
|
|
2746
2759
|
}
|
|
2747
2760
|
return () => {
|
|
@@ -3113,12 +3126,16 @@
|
|
|
3113
3126
|
}
|
|
3114
3127
|
|
|
3115
3128
|
/**
|
|
3116
|
-
*
|
|
3117
|
-
*
|
|
3118
|
-
*
|
|
3129
|
+
* Prompt picker shared by two slots: `conversation.hero.options` (new
|
|
3130
|
+
* session) and `conversation.input.left` (ongoing session, beside the
|
|
3131
|
+
* host's permission dropdown). In the composer the popover expands
|
|
3132
|
+
* upward and the trigger uses a compact icon-only style.
|
|
3133
|
+
* Choosing a prompt fills the composer; the per-row send button submits
|
|
3134
|
+
* immediately.
|
|
3119
3135
|
*/
|
|
3120
|
-
function
|
|
3136
|
+
function PromptsControl({ sessionId, inputActions, useWorkspaces, useInput, variant }) {
|
|
3121
3137
|
const settings = useSettings();
|
|
3138
|
+
const compact = variant === 'composer';
|
|
3122
3139
|
const workspaceSelector = useMemo(() => (snapshot) => resolveWorkspaceIdFromSnapshot(snapshot, sessionId), [sessionId]);
|
|
3123
3140
|
const workspaceId = typeof useWorkspaces === 'function'
|
|
3124
3141
|
? useWorkspaces(workspaceSelector) ?? ''
|
|
@@ -3192,8 +3209,9 @@
|
|
|
3192
3209
|
h('button', {
|
|
3193
3210
|
type: 'button',
|
|
3194
3211
|
ref: anchorRef,
|
|
3195
|
-
className: 'dsh-powerup-prompt-trigger',
|
|
3212
|
+
className: 'dsh-powerup-prompt-trigger' + (compact ? ' dsh-powerup-prompt-trigger-compact' : ''),
|
|
3196
3213
|
'data-powerup-prompts': '',
|
|
3214
|
+
'data-powerup-prompts-variant': compact ? 'composer' : 'hero',
|
|
3197
3215
|
'aria-haspopup': 'menu',
|
|
3198
3216
|
'aria-expanded': 'false',
|
|
3199
3217
|
title: t('prompts.pickHint'),
|
|
@@ -3211,7 +3229,7 @@
|
|
|
3211
3229
|
anchor,
|
|
3212
3230
|
t,
|
|
3213
3231
|
items: visible,
|
|
3214
|
-
placement: (node) => popoverPlacement(node, 260, 340),
|
|
3232
|
+
placement: (node) => popoverPlacement(node, 260, 340, { preferUp: compact }),
|
|
3215
3233
|
onPick: (prompt) => apply(prompt, false),
|
|
3216
3234
|
onSend: (prompt) => apply(prompt, true),
|
|
3217
3235
|
onCreate: () => setCreating(true),
|
|
@@ -3253,6 +3271,14 @@
|
|
|
3253
3271
|
);
|
|
3254
3272
|
}
|
|
3255
3273
|
|
|
3274
|
+
/** Thin wrappers so both slots share one implementation. */
|
|
3275
|
+
function HeroPromptsControl(props) {
|
|
3276
|
+
return PromptsControl({ ...props, variant: 'hero' });
|
|
3277
|
+
}
|
|
3278
|
+
function ComposerPromptsControl(props) {
|
|
3279
|
+
return PromptsControl({ ...props, variant: 'composer' });
|
|
3280
|
+
}
|
|
3281
|
+
|
|
3256
3282
|
// ------------------------------------------------------------------
|
|
3257
3283
|
// Icons (16-grid, currentColor, host stroke convention)
|
|
3258
3284
|
// ------------------------------------------------------------------
|
|
@@ -3906,20 +3932,24 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
3906
3932
|
.dsh-powerup-prompt-trigger-label{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
3907
3933
|
.dsh-powerup-prompt-trigger-chevron{flex:none;display:inline-flex;color:var(--dsw-alias-label-tertiary);transition:transform .15s ease}
|
|
3908
3934
|
.dsh-powerup-prompt-trigger[aria-expanded=true] .dsh-powerup-prompt-trigger-chevron{transform:rotate(180deg)}
|
|
3909
|
-
|
|
3935
|
+
/* Compact variant in the ongoing-session composer tool row: icon + short label,
|
|
3936
|
+
left of the send controls, pops upward above the permission dropdown row. */
|
|
3937
|
+
.dsh-powerup-prompt-trigger-compact{max-width:none;height:30px;padding:0 8px;font-size:11.5px}
|
|
3938
|
+
.dsh-powerup-prompt-trigger-compact .dsh-powerup-prompt-trigger-label{max-width:96px}
|
|
3939
|
+
.dsh-powerup-prompt-pop{position:fixed;z-index:1600;box-sizing:border-box;display:flex;flex-direction:column;overflow:hidden;overflow-x:hidden;border:0;border-radius:10px;background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary);font-size:12.5px;line-height:1.5;opacity:0;transform:translateY(-4px);transition:opacity .12s ease,transform .12s ease;pointer-events:auto;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}
|
|
3910
3940
|
.dsh-powerup-prompt-pop.is-open{opacity:1;transform:none}
|
|
3911
|
-
.dsh-powerup-prompt-pop-head{display:flex;align-items:center;gap:6px;padding:8px 11px 7px;color:var(--dsw-alias-label-tertiary);font-size:10.5px;font-weight:600;letter-spacing:.03em}
|
|
3912
|
-
.dsh-powerup-prompt-pop-list{display:flex;flex-direction:column;gap:1px;padding:4px;overflow-y:auto}
|
|
3913
|
-
.dsh-powerup-prompt-pop-item{display:flex;align-items:center;gap:4px;width:100%;min-height:34px;padding:2px 4px 2px 7px;border:0;border-radius:var(--dsw-radius-md,8px);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:left}
|
|
3941
|
+
.dsh-powerup-prompt-pop-head{flex:none;display:flex;align-items:center;gap:6px;padding:8px 11px 7px;color:var(--dsw-alias-label-tertiary);font-size:10.5px;font-weight:600;letter-spacing:.03em}
|
|
3942
|
+
.dsh-powerup-prompt-pop-list{flex:1 1 auto;min-height:0;display:flex;flex-direction:column;gap:1px;padding:4px;overflow-y:auto;overflow-x:hidden}
|
|
3943
|
+
.dsh-powerup-prompt-pop-item{display:flex;align-items:center;gap:4px;width:100%;min-width:0;min-height:34px;padding:2px 4px 2px 7px;border:0;border-radius:var(--dsw-radius-md,8px);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:left}
|
|
3914
3944
|
.dsh-powerup-prompt-pop-item:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
3915
3945
|
.dsh-powerup-prompt-pop-main{flex:1 1 auto;display:flex;flex-direction:column;gap:1px;min-width:0;padding:3px 0;border:0;background:transparent;color:inherit;font:inherit;text-align:left;cursor:pointer}
|
|
3916
3946
|
.dsh-powerup-prompt-pop-name{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12.5px;line-height:18px}
|
|
3917
3947
|
.dsh-powerup-prompt-pop-preview{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-tertiary);font-size:10.5px;line-height:15px}
|
|
3918
|
-
.dsh-powerup-prompt-pop-send{flex:none;display:inline-flex;align-items:center;gap:4px;height:24px;padding:0 7px;border:.5px solid var(--dsw-alias-border-l2);border-radius:
|
|
3948
|
+
.dsh-powerup-prompt-pop-send{flex:none;display:inline-flex;align-items:center;gap:4px;height:24px;padding:0 7px;border:.5px solid var(--dsw-alias-border-l2);border-radius:8px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary);font:inherit;font-size:10.5px;line-height:16px;white-space:nowrap;cursor:pointer;transition:background .12s ease,color .12s ease,border-color .12s ease}
|
|
3919
3949
|
.dsh-powerup-prompt-pop-send:hover{border-color:var(--dsw-alias-state-business-primary);background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-brand-primary)}
|
|
3920
3950
|
.dsh-powerup-prompt-pop-send:focus-visible,.dsh-powerup-prompt-pop-main:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:-1px}
|
|
3921
|
-
.dsh-powerup-prompt-pop-sep{height:1px;margin:4px 6px;background:var(--dsw-alias-border-l1)}
|
|
3922
|
-
.dsh-powerup-prompt-pop-create{display:flex;align-items:center;gap:7px;width:100%;min-height:32px;padding:0 10px;border:0;border-radius:var(--dsw-radius-md,8px);background:transparent;color:var(--dsw-alias-brand-primary);font:inherit;font-size:12px;line-height:18px;cursor:pointer}
|
|
3951
|
+
.dsh-powerup-prompt-pop-sep{flex:none;height:1px;margin:4px 6px;background:var(--dsw-alias-border-l1)}
|
|
3952
|
+
.dsh-powerup-prompt-pop-create{flex:none;display:flex;align-items:center;gap:7px;width:100%;min-height:32px;padding:0 10px;border:0;border-radius:var(--dsw-radius-md,8px);background:transparent;color:var(--dsw-alias-brand-primary);font:inherit;font-size:12px;line-height:18px;cursor:pointer}
|
|
3923
3953
|
.dsh-powerup-prompt-pop-create:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
3924
3954
|
.dsh-powerup-prompt-pop-empty{padding:12px 10px;color:var(--dsw-alias-label-tertiary);font-size:11.5px;line-height:1.55;text-align:center}
|
|
3925
3955
|
/* DSH-memory-style tab bar: inline segmented control. */
|
|
@@ -3965,7 +3995,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
3965
3995
|
.dsh-powerup-ws-value{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
3966
3996
|
.dsh-powerup-ws-chevron{flex:none;display:inline-flex;color:var(--dsw-alias-label-tertiary);transition:transform .15s ease}
|
|
3967
3997
|
.dsh-powerup-ws-trigger[aria-expanded=true] .dsh-powerup-ws-chevron{transform:rotate(180deg)}
|
|
3968
|
-
.dsh-powerup-ws-menu{position:fixed;z-index:1600;box-sizing:border-box;min-width:180px;max-width:min(360px,calc(100vw - 24px));max-height:min(320px,50vh);overflow-y:auto;padding:4px;border:0;border-radius:
|
|
3998
|
+
.dsh-powerup-ws-menu{position:fixed;z-index:1600;box-sizing:border-box;min-width:180px;max-width:min(360px,calc(100vw - 24px));max-height:min(320px,50vh);overflow-y:auto;padding:4px;border:0;border-radius:10px;background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2);color:var(--dsw-alias-label-primary);font-size:12.5px;line-height:1.5;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2)}
|
|
3969
3999
|
.dsh-powerup-ws-option{display:flex;align-items:center;gap:8px;width:100%;min-height:30px;padding:0 9px;border:0;border-radius:var(--dsw-radius-md,8px);background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:left;cursor:pointer}
|
|
3970
4000
|
.dsh-powerup-ws-option:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
3971
4001
|
.dsh-powerup-ws-option[aria-selected=true]{background:var(--dsw-alias-interactive-bg-active)}
|
|
@@ -6360,17 +6390,22 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
6360
6390
|
* @param {number} preferredHeight
|
|
6361
6391
|
* @returns {{ left: number, width: number, top?: number, bottom?: number, maxHeight: number }}
|
|
6362
6392
|
*/
|
|
6363
|
-
function popoverPlacement(anchor, minWidth, preferredHeight) {
|
|
6393
|
+
function popoverPlacement(anchor, minWidth, preferredHeight, options) {
|
|
6364
6394
|
const rect = anchor.getBoundingClientRect();
|
|
6365
6395
|
const gap = 6;
|
|
6366
6396
|
const margin = 12;
|
|
6397
|
+
const opts = options ?? {};
|
|
6367
6398
|
const viewportWidth = typeof window === 'undefined' ? 1280 : window.innerWidth;
|
|
6368
6399
|
const viewportHeight = typeof window === 'undefined' ? 900 : window.innerHeight;
|
|
6369
6400
|
const width = Math.min(Math.max(rect.width, minWidth), Math.max(200, viewportWidth - margin * 2));
|
|
6370
6401
|
const left = Math.min(Math.max(margin, rect.left), Math.max(margin, viewportWidth - width - margin));
|
|
6371
6402
|
const spaceBelow = viewportHeight - rect.bottom - margin - gap;
|
|
6372
6403
|
const spaceAbove = rect.top - margin - gap;
|
|
6373
|
-
|
|
6404
|
+
// 'up' forces upward expansion (composer at the screen bottom); 'auto'
|
|
6405
|
+
// keeps the original flip-when-cramped behavior used by the hero.
|
|
6406
|
+
const above = opts.preferUp === true
|
|
6407
|
+
? spaceAbove >= Math.min(preferredHeight, 180)
|
|
6408
|
+
: spaceBelow < Math.min(preferredHeight, 180) && spaceAbove > spaceBelow;
|
|
6374
6409
|
return {
|
|
6375
6410
|
left,
|
|
6376
6411
|
width,
|
|
@@ -8224,11 +8259,16 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8224
8259
|
* Shared editor for a list of mask rules. `scope` is 'global' or
|
|
8225
8260
|
* 'workspace'; writes go through the matching store functions.
|
|
8226
8261
|
*/
|
|
8227
|
-
function MaskRuleEditor({ scope, t }) {
|
|
8262
|
+
function MaskRuleEditor({ scope, t, workspaceId }) {
|
|
8228
8263
|
const rules = useMaskRules();
|
|
8229
|
-
const
|
|
8264
|
+
const ws = typeof workspaceId === 'string' ? workspaceId : maskRulesWorkspace;
|
|
8265
|
+
const visible = rules.filter((rule) => {
|
|
8266
|
+
const ruleScope = rule.scope || 'global';
|
|
8267
|
+
if (ruleScope !== scope) return false;
|
|
8268
|
+
return scope === 'workspace' ? (rule.workspaceId ?? '') === ws : true;
|
|
8269
|
+
});
|
|
8230
8270
|
const commit = (next) => {
|
|
8231
|
-
if (scope === 'workspace') writeWorkspaceMaskRules(next);
|
|
8271
|
+
if (scope === 'workspace') writeWorkspaceMaskRules(next, ws);
|
|
8232
8272
|
else writeGlobalMaskRules(next);
|
|
8233
8273
|
};
|
|
8234
8274
|
const update = (id, patch) => {
|
|
@@ -8238,7 +8278,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8238
8278
|
commit(visible.filter((rule) => rule.id !== id));
|
|
8239
8279
|
};
|
|
8240
8280
|
const add = () => {
|
|
8241
|
-
commit([...visible, { id: newId(), pattern: '', replacement: '', enabled: true, scope }]);
|
|
8281
|
+
commit([...visible, { id: newId(), pattern: '', replacement: '', enabled: true, scope, workspaceId: scope === 'workspace' ? ws : '' }]);
|
|
8242
8282
|
};
|
|
8243
8283
|
const title = scope === 'workspace' ? t('mask.workspaceTitle') : t('mask.globalTitle');
|
|
8244
8284
|
return h('div', { className: 'dsh-powerup-mask-editor' },
|
|
@@ -8313,8 +8353,9 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8313
8353
|
function useMaskRules() {
|
|
8314
8354
|
const [revision, setRevision] = useState(0);
|
|
8315
8355
|
useEffect(() => subscribeMaskRules(() => setRevision((v) => v + 1)), []);
|
|
8356
|
+
useEffect(() => { void loadWorkspaceMaskRules(); }, []);
|
|
8316
8357
|
void revision;
|
|
8317
|
-
return [...globalMaskRules, ...
|
|
8358
|
+
return [...globalMaskRules, ...allWorkspaceMaskRules];
|
|
8318
8359
|
}
|
|
8319
8360
|
|
|
8320
8361
|
/**
|
|
@@ -8443,7 +8484,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8443
8484
|
const workspaceSelector = useMemo(() => (snapshot) => resolveWorkspaceIdFromSnapshot(snapshot, ownerId), [ownerId]);
|
|
8444
8485
|
const workspaceId = typeof useWorkspaces === 'function' ? useWorkspaces(workspaceSelector) ?? '' : '';
|
|
8445
8486
|
useEffect(() => {
|
|
8446
|
-
if (typeof workspaceId === 'string' && workspaceId !== '')
|
|
8487
|
+
if (typeof workspaceId === 'string' && workspaceId !== '') maskRulesWorkspace = workspaceId;
|
|
8488
|
+
void loadWorkspaceMaskRules();
|
|
8447
8489
|
}, [workspaceId]);
|
|
8448
8490
|
void rules; void settings;
|
|
8449
8491
|
return h('div', { className: 'dsh-powerup-page' },
|
|
@@ -8454,7 +8496,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8454
8496
|
h('p', null, t('mask.sessionDesc')),
|
|
8455
8497
|
),
|
|
8456
8498
|
),
|
|
8457
|
-
h(MaskRuleEditor, { scope: 'workspace', t }),
|
|
8499
|
+
h(MaskRuleEditor, { scope: 'workspace', t, workspaceId }),
|
|
8458
8500
|
),
|
|
8459
8501
|
);
|
|
8460
8502
|
}
|
|
@@ -8937,6 +8979,14 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8937
8979
|
t: (key, params) => translateCurrent(key, params),
|
|
8938
8980
|
}), 'dsh-powerup: dual send buttons');
|
|
8939
8981
|
|
|
8982
|
+
// In an ongoing session, place the prompt picker in the bottom tool row
|
|
8983
|
+
// just after the host's permission / plan dropdowns; its popover opens
|
|
8984
|
+
// upward so it is not clipped by the screen bottom.
|
|
8985
|
+
register('conversation.input.left', {
|
|
8986
|
+
id: 'powerup-prompts-composer',
|
|
8987
|
+
order: 10,
|
|
8988
|
+
}, ComposerPromptsControl, 'dsh-powerup: composer prompt picker');
|
|
8989
|
+
|
|
8940
8990
|
// Per-workspace Power-Up settings as a Conversation View tab, ordered
|
|
8941
8991
|
// after the host's Trajectory view (order 10).
|
|
8942
8992
|
register('conversation.view', {
|
package/index.js
CHANGED
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
*/
|
|
32
32
|
|
|
33
33
|
import { randomUUID } from 'node:crypto';
|
|
34
|
-
import { appendFileSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
34
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
35
35
|
import { dirname, join, resolve as resolvePath, sep } from 'node:path';
|
|
36
36
|
import { homedir } from 'node:os';
|
|
37
37
|
import { defineTool } from '@deepseek-ai/dsh-tools';
|
|
@@ -50,11 +50,18 @@ 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
|
-
/**
|
|
54
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Central state lives under ~/.dsh/dsh-powerup so one file holds every
|
|
55
|
+
* workspace's records (each record carries its own workspaceId). This lets the
|
|
56
|
+
* Power-Up settings page manage all workspaces in one place. Older releases
|
|
57
|
+
* kept these files in each workspace's own `.dsh/dsh-powerup`, migrated once
|
|
58
|
+
* on first access by `migrateLegacyStore`.
|
|
59
|
+
*/
|
|
60
|
+
const STORE_DIR_NAME = 'dsh-powerup';
|
|
55
61
|
const PROMPTS_FILE = 'prompts.json';
|
|
56
|
-
/** Per-workspace mask rules used by the content-rendering enhancement. */
|
|
57
62
|
const MASK_RULES_FILE = 'mask-rules.json';
|
|
63
|
+
/** Legacy relative location inside a workspace, used only for migration. */
|
|
64
|
+
const LEGACY_STORE_DIR = join('.dsh', 'dsh-powerup');
|
|
58
65
|
|
|
59
66
|
/** The moment this Host process started; a profile file newer than it may await a restart. */
|
|
60
67
|
const HOST_STARTED_AT = Date.now() - process.uptime() * 1000;
|
|
@@ -350,35 +357,23 @@ export async function performSelfUpdate(ctx, version, registry, options = {}) {
|
|
|
350
357
|
}
|
|
351
358
|
|
|
352
359
|
/**
|
|
353
|
-
* Absolute path of
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
* @param {import('@deepseek-ai/cordis').Context} ctx
|
|
357
|
-
* @param {string} workspaceId
|
|
360
|
+
* Absolute path of the central state file under ~/.dsh/dsh-powerup. One file
|
|
361
|
+
* holds every workspace's records; no workspace registry lookup is needed, so
|
|
362
|
+
* the store works even for workspaces not currently registered.
|
|
358
363
|
* @param {string} fileName
|
|
359
|
-
* @returns {string
|
|
364
|
+
* @returns {string}
|
|
360
365
|
*/
|
|
361
|
-
function
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const workspace = registry?.get?.(workspaceId);
|
|
365
|
-
if (workspace === null || workspace === undefined || typeof workspace.path !== 'string' || workspace.path === '') {
|
|
366
|
-
return undefined;
|
|
367
|
-
}
|
|
368
|
-
const root = resolvePath(workspace.path);
|
|
369
|
-
const target = resolvePath(root, PROMPTS_DIR, fileName);
|
|
370
|
-
// The store must stay inside the workspace, whatever the registry returned.
|
|
371
|
-
const prefix = root.endsWith(sep) ? root : root + sep;
|
|
372
|
-
if (!target.startsWith(prefix)) return undefined;
|
|
373
|
-
return target;
|
|
366
|
+
function storePath(fileName) {
|
|
367
|
+
const home = process.env.DSH_HOME?.trim() || join(homedir(), '.dsh');
|
|
368
|
+
return join(home, STORE_DIR_NAME, fileName);
|
|
374
369
|
}
|
|
375
370
|
|
|
376
|
-
/**
|
|
377
|
-
function promptStorePath(
|
|
378
|
-
return
|
|
371
|
+
/** The central prompts file path (kept for callers/tests). */
|
|
372
|
+
function promptStorePath() {
|
|
373
|
+
return storePath(PROMPTS_FILE);
|
|
379
374
|
}
|
|
380
375
|
|
|
381
|
-
/** Read one
|
|
376
|
+
/** Read one JSON list from disk; a missing file is an empty list. */
|
|
382
377
|
function readJsonStore(filePath) {
|
|
383
378
|
try {
|
|
384
379
|
const parsed = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
@@ -389,6 +384,38 @@ function readJsonStore(filePath) {
|
|
|
389
384
|
}
|
|
390
385
|
}
|
|
391
386
|
|
|
387
|
+
/**
|
|
388
|
+
* One-time migration of the old per-workspace files into the central store.
|
|
389
|
+
* Records from every registered workspace are merged by identity (prompt id /
|
|
390
|
+
* rule id), tagging each with its source workspaceId. A marker file prevents
|
|
391
|
+
* re-merging on later writes. Legacy files are left in place (never deleted).
|
|
392
|
+
* @param {string} fileName
|
|
393
|
+
* @param {'prompts'|'rules'} kind
|
|
394
|
+
*/
|
|
395
|
+
function migrateLegacyStore(ctx, fileName) {
|
|
396
|
+
const target = storePath(fileName);
|
|
397
|
+
const marker = target + '.migrated';
|
|
398
|
+
if (existsSync(marker)) return;
|
|
399
|
+
const registry = ctx?.get?.('workspaceRegistry');
|
|
400
|
+
const workspaces = typeof registry?.list === 'function' ? registry.list() : [];
|
|
401
|
+
const merged = readJsonStore(target);
|
|
402
|
+
const seen = new Set(merged.map((r) => r?.id).filter(Boolean));
|
|
403
|
+
for (const ws of workspaces) {
|
|
404
|
+
if (typeof ws?.path !== 'string' || ws.path === '') continue;
|
|
405
|
+
const legacy = resolvePath(resolvePath(ws.path), LEGACY_STORE_DIR, fileName);
|
|
406
|
+
const rows = readJsonStore(legacy);
|
|
407
|
+
if (rows.length === 0) continue;
|
|
408
|
+
for (const row of rows) {
|
|
409
|
+
if (row === null || typeof row !== 'object' || seen.has(row.id)) continue;
|
|
410
|
+
merged.push({ ...row, workspaceId: row.workspaceId ?? ws.id });
|
|
411
|
+
if (row.id) seen.add(row.id);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
mkdirSync(dirname(target), { recursive: true });
|
|
415
|
+
writeFileSync(target, JSON.stringify(merged, null, 2) + '\n', 'utf8');
|
|
416
|
+
writeFileSync(marker, new Date().toISOString() + '\n', 'utf8');
|
|
417
|
+
}
|
|
418
|
+
|
|
392
419
|
/** Read one workspace's prompts from disk; a missing file is an empty list. */
|
|
393
420
|
function readPromptStore(filePath) {
|
|
394
421
|
return readJsonStore(filePath);
|
|
@@ -413,23 +440,14 @@ async function handle(req, res, ctx) {
|
|
|
413
440
|
}
|
|
414
441
|
|
|
415
442
|
if (op === 'mask-rules') {
|
|
416
|
-
const
|
|
417
|
-
? (url.searchParams.get('workspaceId') ?? '')
|
|
418
|
-
: '';
|
|
419
|
-
let workspaceId = targetId;
|
|
443
|
+
const filePath = storePath(MASK_RULES_FILE);
|
|
420
444
|
if (req.method === 'POST') {
|
|
421
445
|
try {
|
|
422
446
|
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
447
|
const rules = Array.isArray(body?.rules) ? body.rules : [];
|
|
430
448
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
431
449
|
writeFileSync(filePath, JSON.stringify(rules, null, 2) + '\n', 'utf8');
|
|
432
|
-
sendJson(res, { ok: true,
|
|
450
|
+
sendJson(res, { ok: true, rules });
|
|
433
451
|
} catch (error) {
|
|
434
452
|
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
435
453
|
}
|
|
@@ -440,12 +458,8 @@ async function handle(req, res, ctx) {
|
|
|
440
458
|
return;
|
|
441
459
|
}
|
|
442
460
|
try {
|
|
443
|
-
|
|
444
|
-
|
|
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) });
|
|
461
|
+
migrateLegacyStore(ctx, MASK_RULES_FILE);
|
|
462
|
+
sendJson(res, { ok: true, rules: readJsonStore(filePath) });
|
|
449
463
|
} catch (error) {
|
|
450
464
|
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
451
465
|
}
|
|
@@ -453,25 +467,16 @@ async function handle(req, res, ctx) {
|
|
|
453
467
|
}
|
|
454
468
|
|
|
455
469
|
if (op === 'prompts') {
|
|
456
|
-
//
|
|
457
|
-
//
|
|
458
|
-
const
|
|
459
|
-
? (url.searchParams.get('workspaceId') ?? '')
|
|
460
|
-
: '';
|
|
461
|
-
let workspaceId = targetId;
|
|
470
|
+
// One central file holds prompts for every workspace; each record carries
|
|
471
|
+
// its own workspaceId ('' means all workspaces). The client filters by scope.
|
|
472
|
+
const filePath = promptStorePath();
|
|
462
473
|
if (req.method === 'POST') {
|
|
463
474
|
try {
|
|
464
475
|
const body = await readJsonBody(req);
|
|
465
|
-
workspaceId = typeof body?.workspaceId === 'string' ? body.workspaceId.trim() : '';
|
|
466
|
-
const filePath = promptStorePath(ctx, workspaceId);
|
|
467
|
-
if (filePath === undefined) {
|
|
468
|
-
sendJson(res, { ok: false, code: 'workspace-not-found', error: 'workspace not found' }, 404);
|
|
469
|
-
return;
|
|
470
|
-
}
|
|
471
476
|
const prompts = Array.isArray(body?.prompts) ? body.prompts : [];
|
|
472
477
|
mkdirSync(dirname(filePath), { recursive: true });
|
|
473
478
|
writeFileSync(filePath, JSON.stringify(prompts, null, 2) + '\n', 'utf8');
|
|
474
|
-
sendJson(res, { ok: true,
|
|
479
|
+
sendJson(res, { ok: true, prompts });
|
|
475
480
|
} catch (error) {
|
|
476
481
|
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
477
482
|
}
|
|
@@ -482,12 +487,8 @@ async function handle(req, res, ctx) {
|
|
|
482
487
|
return;
|
|
483
488
|
}
|
|
484
489
|
try {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
sendJson(res, { ok: false, code: 'workspace-not-found', error: 'workspace not found' }, 404);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
sendJson(res, { ok: true, workspaceId, prompts: readPromptStore(filePath) });
|
|
490
|
+
migrateLegacyStore(ctx, PROMPTS_FILE);
|
|
491
|
+
sendJson(res, { ok: true, prompts: readPromptStore(filePath) });
|
|
491
492
|
} catch (error) {
|
|
492
493
|
sendJson(res, { ok: false, error: String(error?.message ?? error) }, 500);
|
|
493
494
|
}
|
|
@@ -644,12 +645,14 @@ export const __test = {
|
|
|
644
645
|
profileDirectory,
|
|
645
646
|
promptStorePath,
|
|
646
647
|
readPromptStore,
|
|
647
|
-
|
|
648
|
+
storePath,
|
|
648
649
|
readJsonStore,
|
|
650
|
+
migrateLegacyStore,
|
|
651
|
+
PROMPTS_FILE,
|
|
649
652
|
MASK_RULES_FILE,
|
|
650
653
|
HOST_STARTED_AT,
|
|
651
654
|
SELF_VERSION,
|
|
652
655
|
ROUTE,
|
|
653
656
|
MODULE_ID,
|
|
654
|
-
|
|
657
|
+
STORE_DIR_NAME,
|
|
655
658
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restregular/dsh-powerup",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.3",
|
|
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",
|