@restregular/dsh-powerup 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/client.js +77 -57
- package/index.js +68 -65
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -389,8 +389,11 @@ Each rule has:
|
|
|
389
389
|
|
|
390
390
|
Global rules are managed on the Power-Up page's **Masking** tab. Workspace rules
|
|
391
391
|
are managed from the **PowerUp** tab in any conversation header (it appears
|
|
392
|
-
after Trajectory)
|
|
393
|
-
|
|
392
|
+
after Trajectory). Both prompts and workspace rules live in ONE central store
|
|
393
|
+
under `~/.dsh/dsh-powerup/` (`prompts.json` / `mask-rules.json`), with each
|
|
394
|
+
record carrying its own workspace id, so the settings page can manage every
|
|
395
|
+
workspace together. Older per-workspace files are migrated automatically on
|
|
396
|
+
first access.
|
|
394
397
|
|
|
395
398
|
### Dual send buttons
|
|
396
399
|
|
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.2';
|
|
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 () => {
|
|
@@ -3906,20 +3919,20 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
3906
3919
|
.dsh-powerup-prompt-trigger-label{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
3907
3920
|
.dsh-powerup-prompt-trigger-chevron{flex:none;display:inline-flex;color:var(--dsw-alias-label-tertiary);transition:transform .15s ease}
|
|
3908
3921
|
.dsh-powerup-prompt-trigger[aria-expanded=true] .dsh-powerup-prompt-trigger-chevron{transform:rotate(180deg)}
|
|
3909
|
-
.dsh-powerup-prompt-pop{position:fixed;z-index:1600;box-sizing:border-box;display:flex;flex-direction:column;overflow:hidden;border:0;border-radius:
|
|
3922
|
+
.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
3923
|
.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}
|
|
3924
|
+
.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}
|
|
3925
|
+
.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}
|
|
3926
|
+
.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
3927
|
.dsh-powerup-prompt-pop-item:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
3915
3928
|
.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
3929
|
.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
3930
|
.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:
|
|
3931
|
+
.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
3932
|
.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
3933
|
.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}
|
|
3934
|
+
.dsh-powerup-prompt-pop-sep{flex:none;height:1px;margin:4px 6px;background:var(--dsw-alias-border-l1)}
|
|
3935
|
+
.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
3936
|
.dsh-powerup-prompt-pop-create:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
3924
3937
|
.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
3938
|
/* DSH-memory-style tab bar: inline segmented control. */
|
|
@@ -3965,7 +3978,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
3965
3978
|
.dsh-powerup-ws-value{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
3966
3979
|
.dsh-powerup-ws-chevron{flex:none;display:inline-flex;color:var(--dsw-alias-label-tertiary);transition:transform .15s ease}
|
|
3967
3980
|
.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:
|
|
3981
|
+
.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
3982
|
.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
3983
|
.dsh-powerup-ws-option:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
3971
3984
|
.dsh-powerup-ws-option[aria-selected=true]{background:var(--dsw-alias-interactive-bg-active)}
|
|
@@ -8224,11 +8237,16 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8224
8237
|
* Shared editor for a list of mask rules. `scope` is 'global' or
|
|
8225
8238
|
* 'workspace'; writes go through the matching store functions.
|
|
8226
8239
|
*/
|
|
8227
|
-
function MaskRuleEditor({ scope, t }) {
|
|
8240
|
+
function MaskRuleEditor({ scope, t, workspaceId }) {
|
|
8228
8241
|
const rules = useMaskRules();
|
|
8229
|
-
const
|
|
8242
|
+
const ws = typeof workspaceId === 'string' ? workspaceId : maskRulesWorkspace;
|
|
8243
|
+
const visible = rules.filter((rule) => {
|
|
8244
|
+
const ruleScope = rule.scope || 'global';
|
|
8245
|
+
if (ruleScope !== scope) return false;
|
|
8246
|
+
return scope === 'workspace' ? (rule.workspaceId ?? '') === ws : true;
|
|
8247
|
+
});
|
|
8230
8248
|
const commit = (next) => {
|
|
8231
|
-
if (scope === 'workspace') writeWorkspaceMaskRules(next);
|
|
8249
|
+
if (scope === 'workspace') writeWorkspaceMaskRules(next, ws);
|
|
8232
8250
|
else writeGlobalMaskRules(next);
|
|
8233
8251
|
};
|
|
8234
8252
|
const update = (id, patch) => {
|
|
@@ -8238,7 +8256,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8238
8256
|
commit(visible.filter((rule) => rule.id !== id));
|
|
8239
8257
|
};
|
|
8240
8258
|
const add = () => {
|
|
8241
|
-
commit([...visible, { id: newId(), pattern: '', replacement: '', enabled: true, scope }]);
|
|
8259
|
+
commit([...visible, { id: newId(), pattern: '', replacement: '', enabled: true, scope, workspaceId: scope === 'workspace' ? ws : '' }]);
|
|
8242
8260
|
};
|
|
8243
8261
|
const title = scope === 'workspace' ? t('mask.workspaceTitle') : t('mask.globalTitle');
|
|
8244
8262
|
return h('div', { className: 'dsh-powerup-mask-editor' },
|
|
@@ -8313,8 +8331,9 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8313
8331
|
function useMaskRules() {
|
|
8314
8332
|
const [revision, setRevision] = useState(0);
|
|
8315
8333
|
useEffect(() => subscribeMaskRules(() => setRevision((v) => v + 1)), []);
|
|
8334
|
+
useEffect(() => { void loadWorkspaceMaskRules(); }, []);
|
|
8316
8335
|
void revision;
|
|
8317
|
-
return [...globalMaskRules, ...
|
|
8336
|
+
return [...globalMaskRules, ...allWorkspaceMaskRules];
|
|
8318
8337
|
}
|
|
8319
8338
|
|
|
8320
8339
|
/**
|
|
@@ -8443,7 +8462,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8443
8462
|
const workspaceSelector = useMemo(() => (snapshot) => resolveWorkspaceIdFromSnapshot(snapshot, ownerId), [ownerId]);
|
|
8444
8463
|
const workspaceId = typeof useWorkspaces === 'function' ? useWorkspaces(workspaceSelector) ?? '' : '';
|
|
8445
8464
|
useEffect(() => {
|
|
8446
|
-
if (typeof workspaceId === 'string' && workspaceId !== '')
|
|
8465
|
+
if (typeof workspaceId === 'string' && workspaceId !== '') maskRulesWorkspace = workspaceId;
|
|
8466
|
+
void loadWorkspaceMaskRules();
|
|
8447
8467
|
}, [workspaceId]);
|
|
8448
8468
|
void rules; void settings;
|
|
8449
8469
|
return h('div', { className: 'dsh-powerup-page' },
|
|
@@ -8454,7 +8474,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
|
|
|
8454
8474
|
h('p', null, t('mask.sessionDesc')),
|
|
8455
8475
|
),
|
|
8456
8476
|
),
|
|
8457
|
-
h(MaskRuleEditor, { scope: 'workspace', t }),
|
|
8477
|
+
h(MaskRuleEditor, { scope: 'workspace', t, workspaceId }),
|
|
8458
8478
|
),
|
|
8459
8479
|
);
|
|
8460
8480
|
}
|
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.2",
|
|
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",
|