@restregular/dsh-powerup 0.10.1 → 0.10.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.
Files changed (3) hide show
  1. package/README.md +14 -5
  2. package/client.js +524 -137
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -184,12 +184,21 @@ Save reusable prompts and drop one into a new session without retyping it.
184
184
  and the prompt body. Without a title the dropdown shows the first few
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
+ - Prompts are split into two sections: **Global** (visible in every workspace)
188
+ and **This workspace**. Each section can hold custom named groups, which can
189
+ be collapsed and expanded. Prompts not in any group are shown at the same
190
+ level as the group headers, under **Ungrouped**. In the **Prompts** settings
191
+ tab you can create, rename and delete groups for each scope, and **drag a
192
+ prompt onto a group header to move it** (or onto Ungrouped to take it out of
193
+ a group). Deleting a group never deletes its prompts — they become ungrouped.
187
194
  - In the New Session row, to the right of the Agent preset, a dropdown lists the
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.
195
+ prompts available in the current workspace, grouped the same way. In an
196
+ **ongoing session** the same picker also appears in the composer's bottom
197
+ tool row, just right of the permission dropdown; there its menu opens
198
+ **upward**. **Clicking a prompt fills the composer** so you can keep editing
199
+ before sending. Each row also has a **Send now** button that fills and
200
+ submits immediately, and an **Edit** icon button that opens the prompt dialog
201
+ to change its title, scope and text.
193
202
  - **Create a new prompt…** in the dropdown opens an in-conversation dialog. A
194
203
  prompt created here is pinned to the current workspace — you may only keep
195
204
  that scope or switch to **All workspaces**, never pick another workspace.
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.10.1';
86
+ const VERSION = '0.10.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. */
@@ -350,7 +350,7 @@
350
350
  'prompts.tabFeatures': '功能列表',
351
351
  'prompts.tabManage': '提示词',
352
352
  'prompts.sectionTitle': '统一管理各工作区的提示词',
353
- 'prompts.sectionSub': '提示词按工作区分组保存在工作区目录的 .dsh/dsh-powerup/prompts.json;选择后填入输入框,可继续编辑再发送。',
353
+ 'prompts.sectionSub': '提示词按「全局 / 当前工作区」分区,区内可自定义分组并折叠展开;未分组提示词与分组同级展示,拖拽提示词到分组标题即可移动。',
354
354
  'prompts.new': '新建提示词',
355
355
  'prompts.cancel': '取消',
356
356
  'prompts.save': '保存',
@@ -382,10 +382,24 @@
382
382
  'prompts.createNew': '创建新的提示词…',
383
383
  'prompts.noPrompts': '这个工作区还没有提示词',
384
384
  'prompts.createTitle': '新建提示词',
385
+ 'prompts.editTitle': '编辑提示词',
386
+ 'prompts.editHint': '修改这条提示词的标题、可见范围与正文。',
385
387
  'prompts.createScopeHint': '这个提示词会自动归属到当前工作区;你也可以改为「所有工作区」。',
386
388
  'prompts.createFailed': '创建失败:{message}',
387
389
  'prompts.workspaceCurrent': '当前工作区',
388
390
  'prompts.workspaceNone': '未识别当前工作区,将保存到所有工作区',
391
+ 'prompts.scopeGlobal': '全局提示词',
392
+ 'prompts.scopeWorkspace': '当前工作区',
393
+ 'prompts.ungrouped': '未分组',
394
+ 'prompts.groupNew': '新建分组',
395
+ 'prompts.groupRename': '重命名',
396
+ 'prompts.groupDelete': '删除分组',
397
+ 'prompts.groupNamePlaceholder': '分组名称',
398
+ 'prompts.groupCreate': '创建分组',
399
+ 'prompts.groupConfirmDelete': '删除这个分组?其中的提示词会变为未分组,不会被删除。',
400
+ 'prompts.moveToGroup': '移动到分组',
401
+ 'prompts.moveUngrouped': '移出分组',
402
+ 'prompts.dropHint': '拖拽提示词到分组标题即可移动;拖到「未分组」可移出分组。',
389
403
  },
390
404
  en: {
391
405
  'panel.title': 'Power-Up',
@@ -642,7 +656,7 @@
642
656
  'prompts.tabFeatures': 'Features',
643
657
  'prompts.tabManage': 'Prompts',
644
658
  'prompts.sectionTitle': 'Manage prompts for every workspace',
645
- 'prompts.sectionSub': 'Prompts are grouped by workspace and stored in that workspace\'s .dsh/dsh-powerup/prompts.json. Picking one fills the composer so you can edit before sending.',
659
+ 'prompts.sectionSub': 'Prompts are split into Global / This workspace sections. Each section can have custom collapsible groups; ungrouped prompts sit beside groups, and you can drag a prompt onto a group header to move it.',
646
660
  'prompts.new': 'New prompt',
647
661
  'prompts.cancel': 'Cancel',
648
662
  'prompts.save': 'Save',
@@ -674,10 +688,24 @@
674
688
  'prompts.createNew': 'Create a new prompt…',
675
689
  'prompts.noPrompts': 'No prompts for this workspace yet',
676
690
  'prompts.createTitle': 'New prompt',
691
+ 'prompts.editTitle': 'Edit prompt',
692
+ 'prompts.editHint': 'Change this prompt\'s title, scope and text.',
677
693
  'prompts.createScopeHint': 'This prompt will belong to the current workspace automatically; you can also choose "All workspaces".',
678
694
  'prompts.createFailed': 'Could not create: {message}',
679
695
  'prompts.workspaceCurrent': 'Current workspace',
680
696
  'prompts.workspaceNone': 'Current workspace unknown; it will be saved for all workspaces',
697
+ 'prompts.scopeGlobal': 'Global prompts',
698
+ 'prompts.scopeWorkspace': 'This workspace',
699
+ 'prompts.ungrouped': 'Ungrouped',
700
+ 'prompts.groupNew': 'New group',
701
+ 'prompts.groupRename': 'Rename',
702
+ 'prompts.groupDelete': 'Delete group',
703
+ 'prompts.groupNamePlaceholder': 'Group name',
704
+ 'prompts.groupCreate': 'Create group',
705
+ 'prompts.groupConfirmDelete': 'Delete this group? Its prompts stay as ungrouped and are not deleted.',
706
+ 'prompts.moveToGroup': 'Move to group',
707
+ 'prompts.moveUngrouped': 'Move out of group',
708
+ 'prompts.dropHint': 'Drag a prompt onto a group header to move it; drop on Ungrouped to take it out of a group.',
681
709
  },
682
710
  };
683
711
 
@@ -796,20 +824,46 @@
796
824
  let promptsCache = [];
797
825
  let promptsLoaded = false;
798
826
 
799
- /** Normalize an arbitrary value into a clean prompt record. */
827
+ /** A group record is tagged with kind:'group'; everything else is a prompt. */
828
+ function isGroupRecord(item) {
829
+ return item !== null && typeof item === 'object' && item.kind === 'group';
830
+ }
831
+
832
+ /** Normalize an arbitrary value into a clean prompt or group record. */
800
833
  function normalizePrompt(item) {
801
834
  if (item === null || typeof item !== 'object') return null;
835
+ if (isGroupRecord(item)) {
836
+ return {
837
+ id: typeof item.id === 'string' && item.id !== '' ? item.id : newId(),
838
+ kind: 'group',
839
+ name: typeof item.name === 'string' ? item.name : '',
840
+ workspaceId: typeof item.workspaceId === 'string' ? item.workspaceId : '',
841
+ };
842
+ }
802
843
  return {
803
844
  id: typeof item.id === 'string' && item.id !== '' ? item.id : newId(),
804
845
  title: typeof item.title === 'string' ? item.title : '',
805
846
  text: typeof item.text === 'string' ? item.text : '',
806
847
  workspaceId: typeof item.workspaceId === 'string' ? item.workspaceId : '',
848
+ groupId: typeof item.groupId === 'string' ? item.groupId : '',
807
849
  };
808
850
  }
809
851
 
810
- /** @returns {Array<{id:string,title:string,text:string,workspaceId:string}>} */
852
+ /** @returns {Array<{id:string,title:string,text:string,workspaceId:string,groupId:string}>} */
811
853
  function readPrompts() {
812
- return promptsCache;
854
+ return promptsCache.filter((item) => !isGroupRecord(item));
855
+ }
856
+
857
+ /** @returns {Array<{id:string,kind:'group',name:string,workspaceId:string}>} */
858
+ function readGroups() {
859
+ return promptsCache.filter(isGroupRecord);
860
+ }
861
+
862
+ /** Groups visible in a workspace: its own plus the global ones. */
863
+ function groupsForWorkspace(list, workspaceId) {
864
+ const id = typeof workspaceId === 'string' ? workspaceId : '';
865
+ return (Array.isArray(list) ? list : []).filter((item) => isGroupRecord(item)
866
+ && (item.workspaceId === '' || item.workspaceId === id));
813
867
  }
814
868
 
815
869
  /**
@@ -831,8 +885,7 @@
831
885
  return promptsCache;
832
886
  }
833
887
 
834
- function writePrompts(list) {
835
- const next = (Array.isArray(list) ? list : []).map(normalizePrompt).filter(Boolean);
888
+ function commitStore(next) {
836
889
  promptsCache = next;
837
890
  promptsLoaded = true;
838
891
  emitPrompts();
@@ -845,6 +898,23 @@
845
898
  });
846
899
  }
847
900
 
901
+ /** Replace prompts, keeping the group records already in the cache. */
902
+ function writePrompts(list) {
903
+ const prompts = (Array.isArray(list) ? list : []).map(normalizePrompt).filter(Boolean);
904
+ commitStore([...promptsCache.filter(isGroupRecord), ...prompts]);
905
+ }
906
+
907
+ /** Replace group records, keeping the prompts already in the cache. */
908
+ function writeGroups(list) {
909
+ const groups = (Array.isArray(list) ? list : []).map(normalizePrompt).filter(Boolean);
910
+ commitStore([...groups, ...promptsCache.filter((item) => !isGroupRecord(item))]);
911
+ }
912
+
913
+ /** Replace the whole store (prompts and groups), e.g. after a drag move. */
914
+ function writeAll(list) {
915
+ commitStore((Array.isArray(list) ? list : []).map(normalizePrompt).filter(Boolean));
916
+ }
917
+
848
918
  const promptsListeners = new Set();
849
919
  function subscribePrompts(listener) {
850
920
  promptsListeners.add(listener);
@@ -1025,7 +1095,34 @@
1025
1095
  */
1026
1096
  function promptsForWorkspace(list, workspaceId) {
1027
1097
  const id = typeof workspaceId === 'string' ? workspaceId : '';
1028
- return (Array.isArray(list) ? list : []).filter((item) => item.workspaceId === '' || item.workspaceId === id);
1098
+ return (Array.isArray(list) ? list : []).filter((item) => !isGroupRecord(item)
1099
+ && (item.workspaceId === '' || item.workspaceId === id));
1100
+ }
1101
+
1102
+ /**
1103
+ * Build the grouped view for one scope: custom groups first (in store
1104
+ * order), then ungrouped prompts as a peer group with id ''. Only prompts
1105
+ * whose groupId resolves to a group of the same scope are placed; an
1106
+ * orphaned groupId falls back to ungrouped so no prompt disappears.
1107
+ */
1108
+ function groupPrompts(prompts, groups, scopeId) {
1109
+ const scopeGroups = (Array.isArray(groups) ? groups : [])
1110
+ .filter((group) => group.workspaceId === scopeId);
1111
+ const scopePrompts = (Array.isArray(prompts) ? prompts : [])
1112
+ .filter((prompt) => prompt.workspaceId === scopeId);
1113
+ const known = new Set(scopeGroups.map((group) => group.id));
1114
+ const buckets = new Map(scopeGroups.map((group) => [group.id, []]));
1115
+ const loose = [];
1116
+ for (const prompt of scopePrompts) {
1117
+ const gid = typeof prompt.groupId === 'string' ? prompt.groupId : '';
1118
+ if (gid !== '' && buckets.has(gid)) buckets.get(gid).push(prompt);
1119
+ else loose.push(prompt);
1120
+ }
1121
+ const sections = scopeGroups.map((group) => ({
1122
+ id: group.id, name: group.name, group, items: buckets.get(group.id), isUngrouped: false,
1123
+ }));
1124
+ sections.push({ id: '', name: '', items: loose, isUngrouped: true });
1125
+ return sections;
1029
1126
  }
1030
1127
 
1031
1128
  /** Title, else the first characters of the body, else a localized fallback. */
@@ -1045,6 +1142,13 @@
1045
1142
  return value;
1046
1143
  }
1047
1144
 
1145
+ function usePromptGroups() {
1146
+ const [value, setValue] = useState(readGroups);
1147
+ useEffect(() => subscribePrompts(() => setValue(readGroups())), []);
1148
+ useEffect(() => { void loadPrompts(); }, []);
1149
+ return value;
1150
+ }
1151
+
1048
1152
  // ------------------------------------------------------------------
1049
1153
  // Sidebar launcher: the panel list as an adaptive icon grid
1050
1154
  // ------------------------------------------------------------------
@@ -2856,7 +2960,7 @@
2856
2960
  * Open the prompt picker next to the hero control. Returns a disposer.
2857
2961
  * DOM-based like the session switcher so it survives host re-renders.
2858
2962
  */
2859
- function openPromptPopover({ anchor, t, items, onPick, onSend, onCreate, onDispose, placement }) {
2963
+ function openPromptPopover({ anchor, t, sections, collapsed, onToggleGroup, onPick, onSend, onEdit, onCreate, onDispose, placement }) {
2860
2964
  if (anchor === null || anchor === undefined || typeof document === 'undefined') return () => {};
2861
2965
  const element = document.createElement('div');
2862
2966
  element.className = 'dsh-powerup-prompt-pop';
@@ -2886,54 +2990,126 @@
2886
2990
  element.appendChild(head);
2887
2991
  const list = document.createElement('div');
2888
2992
  list.className = 'dsh-powerup-prompt-pop-list';
2889
- if (items.length === 0) {
2890
- const empty = document.createElement('div');
2891
- empty.className = 'dsh-powerup-prompt-pop-empty';
2892
- empty.textContent = t('prompts.noPrompts');
2893
- element.appendChild(empty);
2894
- } else {
2895
- for (const prompt of items) {
2896
- const row = document.createElement('div');
2897
- row.className = 'dsh-powerup-prompt-pop-item';
2898
- const main = document.createElement('button');
2899
- main.type = 'button';
2900
- main.className = 'dsh-powerup-prompt-pop-main';
2901
- main.setAttribute('data-prompt-id', prompt.id);
2902
- const name = document.createElement('span');
2903
- name.className = 'dsh-powerup-prompt-pop-name';
2904
- name.textContent = promptLabel(prompt, t);
2905
- const preview = document.createElement('span');
2906
- preview.className = 'dsh-powerup-prompt-pop-preview';
2907
- preview.textContent = [...(prompt.text || '').trim()].slice(0, 40).join('');
2908
- main.append(name, preview);
2909
- main.addEventListener('click', (event) => {
2910
- event.preventDefault();
2911
- event.stopPropagation();
2912
- dispose();
2913
- onPick(prompt);
2914
- });
2915
- const send = document.createElement('button');
2916
- send.type = 'button';
2917
- send.className = 'dsh-powerup-prompt-pop-send';
2918
- send.setAttribute('data-prompt-send', prompt.id);
2919
- send.setAttribute('aria-label', t('prompts.sendDirect'));
2920
- send.setAttribute('title', t('prompts.sendDirect'));
2921
- // Icon-only send action; label moved to title/aria-label above.
2922
- send.innerHTML = '<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false"><path d="M2 7.5 13.5 3 9 14.5 7.4 9.2 2 7.5Z" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"/></svg>';
2923
- send.addEventListener('click', (event) => {
2993
+ const renderRow = (prompt) => {
2994
+ const row = document.createElement('div');
2995
+ row.className = 'dsh-powerup-prompt-pop-item';
2996
+ const main = document.createElement('button');
2997
+ main.type = 'button';
2998
+ main.className = 'dsh-powerup-prompt-pop-main';
2999
+ main.setAttribute('data-prompt-id', prompt.id);
3000
+ const name = document.createElement('span');
3001
+ name.className = 'dsh-powerup-prompt-pop-name';
3002
+ name.textContent = promptLabel(prompt, t);
3003
+ const preview = document.createElement('span');
3004
+ preview.className = 'dsh-powerup-prompt-pop-preview';
3005
+ preview.textContent = [...(prompt.text || '').trim()].slice(0, 40).join('');
3006
+ main.append(name, preview);
3007
+ main.addEventListener('click', (event) => {
3008
+ event.preventDefault();
3009
+ event.stopPropagation();
3010
+ dispose();
3011
+ onPick(prompt);
3012
+ });
3013
+ const send = document.createElement('button');
3014
+ send.type = 'button';
3015
+ send.className = 'dsh-powerup-prompt-pop-send';
3016
+ send.setAttribute('data-prompt-send', prompt.id);
3017
+ send.setAttribute('aria-label', t('prompts.sendDirect'));
3018
+ send.setAttribute('title', t('prompts.sendDirect'));
3019
+ // Icon-only send action; label moved to title/aria-label above.
3020
+ send.innerHTML = '<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false"><path d="M2 7.5 13.5 3 9 14.5 7.4 9.2 2 7.5Z" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"/></svg>';
3021
+ send.addEventListener('click', (event) => {
3022
+ event.preventDefault();
3023
+ event.stopPropagation();
3024
+ dispose();
3025
+ onSend(prompt);
3026
+ });
3027
+ row.append(main);
3028
+ if (typeof onEdit === 'function') {
3029
+ const edit = document.createElement('button');
3030
+ edit.type = 'button';
3031
+ edit.className = 'dsh-powerup-prompt-pop-edit';
3032
+ edit.setAttribute('data-prompt-edit', prompt.id);
3033
+ edit.setAttribute('aria-label', t('prompts.edit'));
3034
+ edit.setAttribute('title', t('prompts.edit'));
3035
+ // Icon-only edit action; label moved to title/aria-label above.
3036
+ edit.innerHTML = '<svg width="14" height="14" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false"><path d="M11.2 2.6a1.3 1.3 0 0 1 1.8 1.8L6 11.4l-2.4.6.6-2.4 7-7Z" stroke="currentColor" stroke-width="1.2" stroke-linejoin="round"/><path d="M3 14h10" stroke="currentColor" stroke-width="1.2" stroke-linecap="round"/></svg>';
3037
+ edit.addEventListener('click', (event) => {
2924
3038
  event.preventDefault();
2925
3039
  event.stopPropagation();
2926
3040
  dispose();
2927
- onSend(prompt);
3041
+ onEdit(prompt);
2928
3042
  });
2929
- row.append(main, send);
2930
- list.appendChild(row);
3043
+ row.append(edit);
2931
3044
  }
2932
- element.appendChild(list);
2933
- const sep = document.createElement('div');
2934
- sep.className = 'dsh-powerup-prompt-pop-sep';
2935
- element.appendChild(sep);
2936
- }
3045
+ row.append(send);
3046
+ return row;
3047
+ };
3048
+ const sectionsList = Array.isArray(sections) ? sections : [];
3049
+ const emptyNode = document.createElement('div');
3050
+ emptyNode.className = 'dsh-powerup-prompt-pop-empty';
3051
+ emptyNode.textContent = t('prompts.noPrompts');
3052
+ const sep = document.createElement('div');
3053
+ sep.className = 'dsh-powerup-prompt-pop-sep';
3054
+ const localCollapsed = new Set(collapsed instanceof Set ? collapsed : []);
3055
+ const renderList = () => {
3056
+ while (list.firstChild) list.removeChild(list.firstChild);
3057
+ let total = 0;
3058
+ for (const section of sectionsList) {
3059
+ for (const group of section.groups) total += group.items.length;
3060
+ }
3061
+ if (total === 0) {
3062
+ if (emptyNode.parentNode !== element) element.appendChild(emptyNode);
3063
+ if (list.parentNode === element) element.removeChild(list);
3064
+ if (sep.parentNode === element) element.removeChild(sep);
3065
+ return;
3066
+ }
3067
+ if (emptyNode.parentNode === element) element.removeChild(emptyNode);
3068
+ if (list.parentNode !== element) element.insertBefore(list, sep.parentNode === element ? sep : null);
3069
+ if (sep.parentNode !== element) element.appendChild(sep);
3070
+ for (const section of sectionsList) {
3071
+ const scopeHead = document.createElement('div');
3072
+ scopeHead.className = 'dsh-powerup-prompt-pop-scope';
3073
+ scopeHead.textContent = section.label;
3074
+ list.appendChild(scopeHead);
3075
+ for (const group of section.groups) {
3076
+ if (group.items.length === 0 && !group.group) continue;
3077
+ const isUngrouped = group.isUngrouped === true;
3078
+ const key = section.key + ':' + group.id;
3079
+ const isCollapsed = localCollapsed.has(key);
3080
+ if (isUngrouped) {
3081
+ // Ungrouped prompts sit at the same level as group headers.
3082
+ for (const prompt of group.items) list.appendChild(renderRow(prompt));
3083
+ continue;
3084
+ }
3085
+ const head = document.createElement('button');
3086
+ head.type = 'button';
3087
+ head.className = 'dsh-powerup-prompt-pop-group';
3088
+ head.setAttribute('data-prompt-group', key);
3089
+ head.setAttribute('aria-expanded', isCollapsed ? 'false' : 'true');
3090
+ head.innerHTML = '<svg width="10" height="10" viewBox="0 0 16 16" fill="none" aria-hidden="true" focusable="false"><path d="m4 6 4 4 4-4" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>';
3091
+ const label = document.createElement('span');
3092
+ label.textContent = group.name || t('prompts.untitled');
3093
+ const count = document.createElement('span');
3094
+ count.className = 'dsh-powerup-prompt-pop-group-count';
3095
+ count.textContent = String(group.items.length);
3096
+ head.append(label, count);
3097
+ head.addEventListener('click', (event) => {
3098
+ event.preventDefault();
3099
+ event.stopPropagation();
3100
+ if (localCollapsed.has(key)) localCollapsed.delete(key);
3101
+ else localCollapsed.add(key);
3102
+ if (typeof onToggleGroup === 'function') onToggleGroup(key, !localCollapsed.has(key));
3103
+ renderList();
3104
+ });
3105
+ list.appendChild(head);
3106
+ if (!isCollapsed) {
3107
+ for (const prompt of group.items) list.appendChild(renderRow(prompt));
3108
+ }
3109
+ }
3110
+ }
3111
+ };
3112
+ renderList();
2937
3113
  const create = document.createElement('button');
2938
3114
  create.type = 'button';
2939
3115
  create.className = 'dsh-powerup-prompt-pop-create';
@@ -2986,28 +3162,34 @@
2986
3162
  }
2987
3163
 
2988
3164
  /**
2989
- * In-conversation create dialog. The workspace is pinned to the session's
2990
- * own workspace: the user may only keep it or switch to "all workspaces",
2991
- * never pick another workspace.
3165
+ * In-conversation prompt dialog: creates a new prompt, or edits an
3166
+ * existing one when `prompt` is passed. For creation the workspace is
3167
+ * pinned to the session's own workspace: the user may only keep it or
3168
+ * switch to "all workspaces", never pick another workspace.
2992
3169
  */
2993
- function PromptCreateModal({ workspaceId, workspaceTitle, onClose, onCreated }) {
3170
+ function PromptCreateModal({ workspaceId, workspaceTitle, onClose, onCreated, prompt, onUpdated }) {
2994
3171
  const t = (key, params) => translateCurrent(key, params);
2995
- const fixedScope = typeof workspaceId !== 'string' || workspaceId === '';
2996
- // Reopening the dialog for the same workspace restores the previous
2997
- // draft; switching to another workspace starts from a clean slate.
2998
- const sameWorkspace = promptCreateDraft.workspaceId === (fixedScope ? '' : workspaceId);
2999
- if (!sameWorkspace) {
3000
- promptCreateDraft.workspaceId = fixedScope ? '' : workspaceId;
3001
- promptCreateDraft.title = '';
3002
- promptCreateDraft.text = '';
3003
- promptCreateDraft.scope = fixedScope ? 'all' : 'current';
3004
- }
3005
- const [title, setTitle] = useState(promptCreateDraft.title);
3006
- const [text, setText] = useState(promptCreateDraft.text);
3007
- const [scope, setScope] = useState(promptCreateDraft.scope);
3172
+ const editing = prompt !== null && prompt !== undefined && typeof prompt === 'object';
3173
+ const fixedScope = !editing && (typeof workspaceId !== 'string' || workspaceId === '');
3174
+ if (!editing) {
3175
+ // Reopening the dialog for the same workspace restores the previous
3176
+ // draft; switching to another workspace starts from a clean slate.
3177
+ const sameWorkspace = promptCreateDraft.workspaceId === (fixedScope ? '' : workspaceId);
3178
+ if (!sameWorkspace) {
3179
+ promptCreateDraft.workspaceId = fixedScope ? '' : workspaceId;
3180
+ promptCreateDraft.title = '';
3181
+ promptCreateDraft.text = '';
3182
+ promptCreateDraft.scope = fixedScope ? 'all' : 'current';
3183
+ }
3184
+ }
3185
+ const [title, setTitle] = useState(editing ? (prompt.title || '') : promptCreateDraft.title);
3186
+ const [text, setText] = useState(editing ? (prompt.text || '') : promptCreateDraft.text);
3187
+ const [scope, setScope] = useState(editing
3188
+ ? (prompt.workspaceId && prompt.workspaceId === workspaceId ? 'current' : 'all')
3189
+ : promptCreateDraft.scope);
3008
3190
  const titleRef = useRef(null);
3009
3191
  // Close plays an exit animation first, so the dialog does not vanish
3010
- // abruptly; the draft is already persisted by the effect below.
3192
+ // abruptly; the create draft is already persisted by the effect below.
3011
3193
  const [closing, setClosing] = useState(false);
3012
3194
  const closingRef = useRef(false);
3013
3195
  const requestClose = () => {
@@ -3023,10 +3205,11 @@
3023
3205
  }, 140);
3024
3206
  };
3025
3207
  useEffect(() => {
3208
+ if (editing) return;
3026
3209
  promptCreateDraft.title = title;
3027
3210
  promptCreateDraft.text = text;
3028
3211
  promptCreateDraft.scope = scope;
3029
- }, [title, text, scope]);
3212
+ }, [title, text, scope, editing]);
3030
3213
  useEffect(() => {
3031
3214
  try {
3032
3215
  // preventScroll keeps the focus from scrolling the page mid-animation.
@@ -3048,19 +3231,34 @@
3048
3231
  const save = () => {
3049
3232
  const body = typeof text === 'string' ? text.trim() : '';
3050
3233
  if (body === '') return;
3051
- const record = {
3052
- id: newId(),
3053
- title: typeof title === 'string' ? title.trim() : '',
3054
- text: body,
3055
- workspaceId: scope === 'current' && typeof workspaceId === 'string' ? workspaceId : '',
3056
- };
3057
3234
  const list = readPrompts();
3058
- list.push(record);
3235
+ let record;
3236
+ if (editing) {
3237
+ record = {
3238
+ id: prompt.id,
3239
+ title: typeof title === 'string' ? title.trim() : '',
3240
+ text: body,
3241
+ workspaceId: scope === 'current' && typeof workspaceId === 'string' ? workspaceId : '',
3242
+ };
3243
+ const index = list.findIndex((p) => p.id === record.id);
3244
+ if (index === -1) list.push(record);
3245
+ else list[index] = record;
3246
+ } else {
3247
+ record = {
3248
+ id: newId(),
3249
+ title: typeof title === 'string' ? title.trim() : '',
3250
+ text: body,
3251
+ workspaceId: scope === 'current' && typeof workspaceId === 'string' ? workspaceId : '',
3252
+ };
3253
+ list.push(record);
3254
+ }
3059
3255
  writePrompts(list);
3060
- // The draft became a real prompt: the next dialog starts empty.
3061
- promptCreateDraft.title = '';
3062
- promptCreateDraft.text = '';
3063
- promptCreateDraft.scope = fixedScope ? 'all' : 'current';
3256
+ if (!editing) {
3257
+ // The draft became a real prompt: the next dialog starts empty.
3258
+ promptCreateDraft.title = '';
3259
+ promptCreateDraft.text = '';
3260
+ promptCreateDraft.scope = fixedScope ? 'all' : 'current';
3261
+ }
3064
3262
  // Play the exit animation before telling the parent to unmount.
3065
3263
  if (!closingRef.current) {
3066
3264
  closingRef.current = true;
@@ -3068,7 +3266,11 @@
3068
3266
  }
3069
3267
  setTimeout(() => {
3070
3268
  try {
3071
- onCreated(record);
3269
+ if (editing) {
3270
+ if (typeof onUpdated === 'function') onUpdated(record);
3271
+ } else if (typeof onCreated === 'function') {
3272
+ onCreated(record);
3273
+ }
3072
3274
  } catch {
3073
3275
  /* The parent owns unmounting. */
3074
3276
  }
@@ -3088,13 +3290,13 @@
3088
3290
  className: 'dsh-powerup-prompt-modal' + (closing ? ' is-closing' : ''),
3089
3291
  role: 'dialog',
3090
3292
  'aria-modal': 'true',
3091
- 'aria-label': t('prompts.createTitle'),
3293
+ 'aria-label': t(editing ? 'prompts.editTitle' : 'prompts.createTitle'),
3092
3294
  },
3093
3295
  h('div', { className: 'dsh-powerup-prompt-modal-head' },
3094
3296
  h('div', null,
3095
- h('div', { className: 'dsh-powerup-prompt-modal-heading' }, t('prompts.createTitle')),
3297
+ h('div', { className: 'dsh-powerup-prompt-modal-heading' }, t(editing ? 'prompts.editTitle' : 'prompts.createTitle')),
3096
3298
  h('p', { className: 'dsh-powerup-prompt-modal-sub' },
3097
- fixedScope ? t('prompts.workspaceNone') : t('prompts.createScopeHint')),
3299
+ editing ? t('prompts.editHint') : (fixedScope ? t('prompts.workspaceNone') : t('prompts.createScopeHint'))),
3098
3300
  ),
3099
3301
  h('button', {
3100
3302
  type: 'button',
@@ -3150,7 +3352,7 @@
3150
3352
  className: 'dsh-powerup-prompt-modal-save',
3151
3353
  disabled: text.trim() === '',
3152
3354
  onClick: save,
3153
- }, t('prompts.create')),
3355
+ }, t(editing ? 'prompts.save' : 'prompts.create')),
3154
3356
  ),
3155
3357
  ),
3156
3358
  ));
@@ -3172,8 +3374,11 @@
3172
3374
  ? useWorkspaces(workspaceSelector) ?? ''
3173
3375
  : '';
3174
3376
  const prompts = usePrompts(workspaceId);
3377
+ const groups = usePromptGroups();
3175
3378
  const [, forceLocale] = useState(0);
3176
3379
  const [creating, setCreating] = useState(false);
3380
+ const [editing, setEditing] = useState(null);
3381
+ const [collapsed, setCollapsed] = useState(() => new Set());
3177
3382
  const anchorRef = useRef(null);
3178
3383
  const disposeRef = useRef(null);
3179
3384
  const t = (key, params) => translateCurrent(key, params);
@@ -3198,6 +3403,25 @@
3198
3403
  if (!settings.workspacePrompts) return null;
3199
3404
 
3200
3405
  const visible = promptsForWorkspace(prompts, workspaceId);
3406
+ const sections = [];
3407
+ if (workspaceId !== '') {
3408
+ sections.push({
3409
+ key: 'global',
3410
+ label: t('prompts.scopeGlobal'),
3411
+ groups: groupPrompts(visible, groups, ''),
3412
+ });
3413
+ }
3414
+ sections.push({
3415
+ key: 'workspace',
3416
+ label: workspaceId === '' ? t('prompts.scopeGlobal') : t('prompts.scopeWorkspace'),
3417
+ groups: groupPrompts(visible, groups, workspaceId),
3418
+ });
3419
+ const toggleGroup = (key) => setCollapsed((current) => {
3420
+ const next = new Set(current);
3421
+ if (next.has(key)) next.delete(key);
3422
+ else next.add(key);
3423
+ return next;
3424
+ });
3201
3425
  const lastId = readLastPrompt(workspaceId);
3202
3426
  const last = visible.find((p) => p.id === lastId);
3203
3427
  const label = last !== undefined ? promptLabel(last, t) : t('prompts.pick');
@@ -3259,10 +3483,13 @@
3259
3483
  const dispose = openPromptPopover({
3260
3484
  anchor,
3261
3485
  t,
3262
- items: visible,
3486
+ sections,
3487
+ collapsed,
3488
+ onToggleGroup: toggleGroup,
3263
3489
  placement: (node) => popoverPlacement(node, 360, 340, { preferUp: compact }),
3264
3490
  onPick: (prompt) => apply(prompt, false),
3265
3491
  onSend: (prompt) => apply(prompt, true),
3492
+ onEdit: (prompt) => setEditing(prompt),
3266
3493
  onCreate: () => setCreating(true),
3267
3494
  onDispose: () => {
3268
3495
  disposeRef.current = null;
@@ -3299,6 +3526,15 @@
3299
3526
  },
3300
3527
  })
3301
3528
  : null,
3529
+ editing
3530
+ ? h(PromptCreateModal, {
3531
+ workspaceId,
3532
+ workspaceTitle,
3533
+ prompt: editing,
3534
+ onClose: () => setEditing(null),
3535
+ onUpdated: () => setEditing(null),
3536
+ })
3537
+ : null,
3302
3538
  );
3303
3539
  }
3304
3540
 
@@ -3970,16 +4206,22 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
3970
4206
  .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)}
3971
4207
  .dsh-powerup-prompt-pop.is-open{opacity:1;transform:none}
3972
4208
  .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}
4209
+ .dsh-powerup-prompt-pop-scope{flex:none;padding:5px 9px 3px;color:var(--dsw-alias-label-tertiary);font-size:10px;font-weight:600;letter-spacing:.03em}
4210
+ .dsh-powerup-prompt-pop-group{flex:none;display:flex;align-items:center;gap:5px;width:100%;min-height:26px;padding:2px 9px;border:0;border-radius:7px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;font-weight:600;line-height:1.5;text-align:left;cursor:pointer}
4211
+ .dsh-powerup-prompt-pop-group svg{flex:none;color:var(--dsw-alias-label-tertiary);transition:transform .12s ease}
4212
+ .dsh-powerup-prompt-pop-group[aria-expanded=false] svg{transform:rotate(-90deg)}
4213
+ .dsh-powerup-prompt-pop-group:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
4214
+ .dsh-powerup-prompt-pop-group-count{margin-left:auto;color:var(--dsw-alias-label-tertiary);font-size:10px;font-weight:400}
3973
4215
  .dsh-powerup-prompt-pop-list{flex:1 1 auto;min-height:0;display:flex;flex-direction:column;gap:4px;padding:6px;overflow-y:auto;overflow-x:hidden}
3974
4216
  .dsh-powerup-prompt-pop-item{box-sizing:border-box;display:flex;align-items:center;gap:6px;width:100%;min-width:0;min-height:38px;padding:4px 5px 4px 9px;border:.5px solid transparent;border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-primary);font:inherit;text-align:left;transition:border-color .12s ease,background .12s ease}
3975
4217
  .dsh-powerup-prompt-pop-item:hover{border-color:var(--dsw-alias-border-l2);background:var(--dsw-alias-interactive-bg-hover)}
3976
4218
  .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}
3977
4219
  .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}
3978
4220
  .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}
3979
- .dsh-powerup-prompt-pop-send{flex:none;display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;padding:0;border:.5px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary);font:inherit;line-height:1;cursor:pointer;transition:background .12s ease,color .12s ease,border-color .12s ease}
3980
- .dsh-powerup-prompt-pop-send svg{width:14px;height:14px}
3981
- .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)}
3982
- .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}
4221
+ .dsh-powerup-prompt-pop-send,.dsh-powerup-prompt-pop-edit{flex:none;display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;padding:0;border:.5px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary);font:inherit;line-height:1;cursor:pointer;transition:background .12s ease,color .12s ease,border-color .12s ease}
4222
+ .dsh-powerup-prompt-pop-send svg,.dsh-powerup-prompt-pop-edit svg{width:14px;height:14px}
4223
+ .dsh-powerup-prompt-pop-send:hover,.dsh-powerup-prompt-pop-edit:hover{border-color:var(--dsw-alias-state-business-primary);background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-brand-primary)}
4224
+ .dsh-powerup-prompt-pop-send:focus-visible,.dsh-powerup-prompt-pop-edit: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}
3983
4225
  .dsh-powerup-prompt-pop-sep{flex:none;height:1px;margin:4px 6px;background:var(--dsw-alias-border-l1)}
3984
4226
  .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}
3985
4227
  .dsh-powerup-prompt-pop-create:hover{background:var(--dsw-alias-interactive-bg-hover)}
@@ -3998,18 +4240,29 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
3998
4240
  .dsh-powerup-prompt-new{height:30px;padding:0 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:8px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);font:inherit;font-size:12.5px;line-height:1.5;cursor:pointer;transition:border-color .12s ease,color .12s ease}
3999
4241
  .dsh-powerup-prompt-new:hover{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}
4000
4242
  .dsh-powerup-prompt-new:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:1px}
4001
- .dsh-powerup-prompt-groups{display:flex;flex-direction:column;gap:14px;margin-top:14px}
4002
- .dsh-powerup-prompt-group{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-2);overflow:hidden}
4003
- .dsh-powerup-prompt-group-head{display:flex;align-items:center;gap:8px;width:100%;padding:9px 12px;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:left;cursor:pointer}
4004
- .dsh-powerup-prompt-group-head:hover{background:var(--dsw-alias-interactive-bg-hover)}
4005
- .dsh-powerup-prompt-group-head:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
4243
+ .dsh-powerup-prompt-scopes{display:flex;flex-direction:column;gap:16px;margin-top:14px}
4244
+ .dsh-powerup-prompt-scope-head{display:flex;align-items:center;gap:8px;padding:4px 2px}
4245
+ .dsh-powerup-prompt-scope-title{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-secondary);font-size:11.5px;font-weight:600;letter-spacing:.03em}
4246
+ .dsh-powerup-prompt-groups{display:flex;flex-direction:column;gap:8px;margin-top:4px}
4247
+ .dsh-powerup-prompt-group{border:1px solid var(--dsw-alias-border-l1);border-radius:12px;background:var(--dsw-alias-bg-layer-2);overflow:hidden;transition:border-color .12s ease,background .12s ease}
4248
+ .dsh-powerup-prompt-group.drop-target{border-color:var(--dsw-alias-state-business-primary);background:var(--dsw-alias-interactive-bg-hover)}
4249
+ .dsh-powerup-prompt-group-head{display:flex;align-items:center;gap:8px;width:100%;padding:7px 12px;background:transparent}
4250
+ .dsh-powerup-prompt-group-toggle{display:flex;flex:1 1 auto;align-items:center;gap:8px;min-width:0;padding:2px 0;border:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;text-align:left;cursor:pointer}
4251
+ .dsh-powerup-prompt-group-toggle:hover{color:var(--dsw-alias-brand-primary)}
4252
+ .dsh-powerup-prompt-group-toggle:focus-visible{outline:2px solid var(--dsw-alias-state-business-primary);outline-offset:-2px}
4253
+ .dsh-powerup-prompt-group-actions{display:flex;align-items:center;gap:2px;flex:none}
4006
4254
  .dsh-powerup-prompt-group-chevron{flex:none;display:inline-flex;color:var(--dsw-alias-label-tertiary);transition:transform .15s ease}
4007
4255
  .dsh-powerup-prompt-group.is-collapsed .dsh-powerup-prompt-group-chevron{transform:rotate(-90deg)}
4008
4256
  .dsh-powerup-prompt-group-title{flex:1 1 auto;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px;font-weight:600;line-height:1.4}
4009
4257
  .dsh-powerup-prompt-group-count{flex:none;color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:1.5;font-variant-numeric:tabular-nums}
4010
4258
  .dsh-powerup-prompt-group-body{display:flex;flex-direction:column;gap:7px;padding:0 8px 8px}
4011
- .dsh-powerup-prompt-card{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);overflow:hidden}
4012
- .dsh-powerup-prompt-card-head{display:flex;align-items:center;gap:10px;padding:8px 11px;flex-wrap:wrap}
4259
+ .dsh-powerup-group-form{display:flex;align-items:center;gap:6px;padding:6px 12px 9px}
4260
+ .dsh-powerup-group-form .dsh-powerup-prompt-input{flex:1 1 auto;min-width:0}
4261
+ .dsh-powerup-prompt-card{border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1);overflow:hidden;transition:border-color .12s ease}
4262
+ .dsh-powerup-prompt-card.drop-target{border-color:var(--dsw-alias-state-business-primary);background:var(--dsw-alias-interactive-bg-hover)}
4263
+ .dsh-powerup-prompt-card[draggable=true]{cursor:grab}
4264
+ .dsh-powerup-prompt-drag-handle{flex:none;color:var(--dsw-alias-label-tertiary);font-size:13px;line-height:1;cursor:grab}
4265
+ .dsh-powerup-prompt-card-head{display:flex;align-items:center;gap:8px;padding:8px 11px;flex-wrap:wrap}
4013
4266
  .dsh-powerup-prompt-name{font-size:13px;font-weight:600;line-height:1.4;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
4014
4267
  .dsh-powerup-prompt-card-actions{display:flex;align-items:center;gap:4px;margin-left:auto;flex-wrap:wrap}
4015
4268
  .dsh-powerup-linkbtn{background:none;border:0;padding:2px 4px;color:var(--dsw-alias-label-secondary);font:inherit;font-size:12px;line-height:1.7;cursor:pointer;border-radius:5px}
@@ -8640,11 +8893,17 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
8640
8893
 
8641
8894
  function PromptManager({ ctx }) {
8642
8895
  const prompts = usePrompts();
8896
+ const groups = usePromptGroups();
8643
8897
  const [, forceLocale] = useState(0);
8644
8898
  const [expanded, setExpanded] = useState(null);
8645
8899
  const [draft, setDraft] = useState(null);
8646
8900
  // Groups start expanded; collapsing one only affects this view.
8647
8901
  const [collapsedGroups, setCollapsedGroups] = useState(() => new Set());
8902
+ // Group create/rename: { scopeId, id:'', name:'' } (id='' => create).
8903
+ const [groupDraft, setGroupDraft] = useState(null);
8904
+ // Prompt id currently being dragged, for move-to-group drops.
8905
+ const dragRef = useRef(null);
8906
+ const [dragOver, setDragOver] = useState(null);
8648
8907
  const t = (key, params) => translateCurrent(key, params);
8649
8908
  useEffect(() => {
8650
8909
  const locale = ctx.get('locale');
@@ -8697,6 +8956,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
8697
8956
  title: typeof draft.title === 'string' ? draft.title.trim() : '',
8698
8957
  text,
8699
8958
  workspaceId: typeof draft.workspaceId === 'string' ? draft.workspaceId.trim() : '',
8959
+ groupId: typeof draft.groupId === 'string' ? draft.groupId : '',
8700
8960
  };
8701
8961
  const next = prompts.filter((p) => p.id !== record.id);
8702
8962
  next.push(record);
@@ -8708,6 +8968,55 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
8708
8968
  && !window.confirm(t('prompts.confirmDelete'))) return;
8709
8969
  writePrompts(prompts.filter((p) => p.id !== prompt.id));
8710
8970
  };
8971
+
8972
+ // ---- Group management ------------------------------------------
8973
+ const saveGroup = () => {
8974
+ if (groupDraft === null) return;
8975
+ const name = typeof groupDraft.name === 'string' ? groupDraft.name.trim() : '';
8976
+ if (name === '') return;
8977
+ const id = groupDraft.id;
8978
+ if (id === '') {
8979
+ writeGroups([...groups, {
8980
+ id: newId(), kind: 'group', name, workspaceId: groupDraft.scopeId,
8981
+ }]);
8982
+ } else {
8983
+ writeGroups(groups.map((g) => (g.id === id ? { ...g, name } : g)));
8984
+ }
8985
+ setGroupDraft(null);
8986
+ };
8987
+ const deleteGroup = (group) => {
8988
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function'
8989
+ && !window.confirm(t('prompts.groupConfirmDelete'))) return;
8990
+ // Detach its prompts so none disappear; store both lists in one write.
8991
+ writeAll([
8992
+ ...groups.filter((g) => g.id !== group.id),
8993
+ ...prompts.map((p) => (p.groupId === group.id ? { ...p, groupId: '' } : p)),
8994
+ ]);
8995
+ };
8996
+ /** Move the dragged prompt into a group ('' = ungrouped) of a scope. */
8997
+ const movePrompt = (groupId, scopeId) => {
8998
+ const id = dragRef.current;
8999
+ dragRef.current = null;
9000
+ setDragOver(null);
9001
+ if (typeof id !== 'string' || id === '') return;
9002
+ writeAll([
9003
+ ...groups,
9004
+ ...prompts.map((p) => (p.id === id
9005
+ ? { ...p, groupId, workspaceId: scopeId }
9006
+ : p)),
9007
+ ]);
9008
+ };
9009
+ const dropProps = (key, groupId, scopeId) => ({
9010
+ onDragOver: (event) => {
9011
+ event.preventDefault();
9012
+ if (dragOver !== key) setDragOver(key);
9013
+ },
9014
+ onDragLeave: () => setDragOver((current) => (current === key ? null : current)),
9015
+ onDrop: (event) => {
9016
+ event.preventDefault();
9017
+ movePrompt(groupId, scopeId);
9018
+ },
9019
+ });
8711
9020
  const field = (label, key, placeholder, className) => h('label', { className: 'dsh-powerup-prompt-field' },
8712
9021
  h('span', { className: 'dsh-powerup-prompt-field-label' }, label),
8713
9022
  key === 'text'
@@ -8757,40 +9066,32 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
8757
9066
  return found?.title || id;
8758
9067
  };
8759
9068
 
8760
- /**
8761
- * Group prompts by workspace: "all workspaces" first, then every real
8762
- * workspace in list order, then any orphaned scope not in the registry.
8763
- */
8764
- const groups = [];
8765
- const seenScope = new Set();
8766
- const pushGroup = (id) => {
8767
- if (seenScope.has(id)) return;
8768
- const items = prompts.filter((p) => p.workspaceId === id);
8769
- if (items.length === 0) return;
8770
- seenScope.add(id);
8771
- groups.push({ id, title: workspaceTitleOf(id), items });
8772
- };
8773
- pushGroup('');
8774
- for (const ws of workspaces) pushGroup(ws.workspaceId);
8775
- for (const prompt of prompts) pushGroup(prompt.workspaceId);
8776
-
8777
- const toggleGroup = (id) => {
9069
+ const toggleGroup = (key) => {
8778
9070
  setCollapsedGroups((current) => {
8779
9071
  const next = new Set(current);
8780
- if (next.has(id)) next.delete(id);
8781
- else next.add(id);
9072
+ if (next.has(key)) next.delete(key);
9073
+ else next.add(key);
8782
9074
  return next;
8783
9075
  });
8784
9076
  };
8785
9077
 
8786
- /** One collapsed prompt card: only the title plus edit/delete actions. */
8787
- const promptCard = (prompt) => {
9078
+ /** One collapsed prompt card: title + edit/delete, draggable. */
9079
+ const promptCard = (prompt, scopeId) => {
8788
9080
  const isExpanded = expanded === prompt.id;
8789
9081
  return h('section', {
8790
9082
  key: prompt.id,
8791
- className: 'dsh-powerup-prompt-card' + (isExpanded ? '' : ' folded'),
9083
+ draggable: !isExpanded,
9084
+ 'data-prompt-drag': prompt.id,
9085
+ className: 'dsh-powerup-prompt-card' + (isExpanded ? '' : ' folded')
9086
+ + (dragOver === 'card:' + prompt.id ? ' drop-target' : ''),
9087
+ onDragStart: (event) => {
9088
+ dragRef.current = prompt.id;
9089
+ try { event.dataTransfer?.setData?.('text/plain', prompt.id); } catch { /* best effort */ }
9090
+ },
9091
+ onDragEnd: () => { dragRef.current = null; setDragOver(null); },
8792
9092
  },
8793
9093
  h('div', { className: 'dsh-powerup-prompt-card-head' },
9094
+ h('span', { className: 'dsh-powerup-prompt-drag-handle', 'aria-hidden': 'true' }, '\u2807'),
8794
9095
  h('span', { className: 'dsh-powerup-prompt-name' }, promptLabel(prompt, t)),
8795
9096
  h('div', { className: 'dsh-powerup-prompt-card-actions' },
8796
9097
  h('button', {
@@ -8809,19 +9110,26 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
8809
9110
  );
8810
9111
  };
8811
9112
 
8812
- const groupsView = groups.length === 0
8813
- ? h('div', { className: 'dsh-powerup-prompt-empty' }, t('prompts.empty'))
8814
- : h('div', { className: 'dsh-powerup-prompt-groups' }, groups.map((group) => {
8815
- const collapsed = collapsedGroups.has(group.id);
8816
- return h('section', {
8817
- key: 'group:' + group.id,
8818
- className: 'dsh-powerup-prompt-group' + (collapsed ? ' is-collapsed' : ''),
8819
- },
9113
+ /** One group block: header (drop target) + collapsible body. */
9114
+ const groupBlock = (section, scopeId) => {
9115
+ const key = scopeId + ':' + section.id;
9116
+ const collapsed = collapsedGroups.has(key);
9117
+ const isUngrouped = section.isUngrouped;
9118
+ const drop = dropProps(key, section.id, scopeId);
9119
+ const editingThis = groupDraft !== null && groupDraft.scopeId === scopeId
9120
+ && groupDraft.id === (isUngrouped ? '' : section.group.id);
9121
+ return h('section', {
9122
+ key,
9123
+ className: 'dsh-powerup-prompt-group' + (isUngrouped ? ' dsh-powerup-prompt-ungrouped' : '')
9124
+ + (collapsed ? ' is-collapsed' : '') + (dragOver === key ? ' drop-target' : ''),
9125
+ ...drop,
9126
+ },
9127
+ h('div', { className: 'dsh-powerup-prompt-group-head' },
8820
9128
  h('button', {
8821
9129
  type: 'button',
8822
- className: 'dsh-powerup-prompt-group-head',
9130
+ className: 'dsh-powerup-prompt-group-toggle',
8823
9131
  'aria-expanded': collapsed ? 'false' : 'true',
8824
- onClick: () => toggleGroup(group.id),
9132
+ onClick: () => toggleGroup(key),
8825
9133
  },
8826
9134
  h('span', {
8827
9135
  className: 'dsh-powerup-prompt-group-chevron',
@@ -8834,12 +9142,85 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
8834
9142
  strokeLinecap: 'round',
8835
9143
  strokeLinejoin: 'round',
8836
9144
  }))),
8837
- h('span', { className: 'dsh-powerup-prompt-group-title' }, group.title),
9145
+ h('span', { className: 'dsh-powerup-prompt-group-title' },
9146
+ isUngrouped ? t('prompts.ungrouped') : (section.name || t('prompts.untitled'))),
8838
9147
  h('span', { className: 'dsh-powerup-prompt-group-count' },
8839
- t('prompts.itemsCount', { count: group.items.length })),
9148
+ t('prompts.itemsCount', { count: section.items.length })),
8840
9149
  ),
8841
- collapsed ? null : h('div', { className: 'dsh-powerup-prompt-group-body' },
8842
- group.items.map(promptCard)),
9150
+ !isUngrouped
9151
+ ? h('div', { className: 'dsh-powerup-prompt-group-actions' },
9152
+ h('button', {
9153
+ type: 'button', className: 'dsh-powerup-linkbtn',
9154
+ onClick: () => setGroupDraft({ scopeId, id: section.group.id, name: section.name }),
9155
+ }, t('prompts.groupRename')),
9156
+ h('button', {
9157
+ type: 'button', className: 'dsh-powerup-linkbtn danger',
9158
+ onClick: () => deleteGroup(section.group),
9159
+ }, t('prompts.groupDelete')),
9160
+ )
9161
+ : null,
9162
+ ),
9163
+ editingThis
9164
+ ? h('div', { className: 'dsh-powerup-group-form' },
9165
+ h('input', {
9166
+ className: 'dsh-powerup-prompt-input',
9167
+ type: 'text',
9168
+ value: groupDraft.name,
9169
+ placeholder: t('prompts.groupNamePlaceholder'),
9170
+ onChange: (event) => setGroupDraft((current) => ({ ...current, name: event.target.value })),
9171
+ }),
9172
+ h('button', { type: 'button', className: 'dsh-powerup-prompt-new', onClick: saveGroup },
9173
+ groupDraft.id === '' ? t('prompts.groupCreate') : t('prompts.save')),
9174
+ h('button', { type: 'button', className: 'dsh-powerup-prompt-new', onClick: () => setGroupDraft(null) },
9175
+ t('prompts.cancel')),
9176
+ )
9177
+ : null,
9178
+ collapsed ? null : h('div', { className: 'dsh-powerup-prompt-group-body' },
9179
+ section.items.map((prompt) => promptCard(prompt, scopeId))),
9180
+ );
9181
+ };
9182
+
9183
+ // Scopes: global first, then every registered workspace, then orphaned.
9184
+ const scopeIds = [];
9185
+ if (prompts.some((p) => p.workspaceId === '') || groups.some((g) => g.workspaceId === '')) scopeIds.push('');
9186
+ for (const ws of workspaces) {
9187
+ if (prompts.some((p) => p.workspaceId === ws.workspaceId)
9188
+ || groups.some((g) => g.workspaceId === ws.workspaceId)) scopeIds.push(ws.workspaceId);
9189
+ }
9190
+ for (const prompt of prompts) {
9191
+ if (!scopeIds.includes(prompt.workspaceId)) scopeIds.push(prompt.workspaceId);
9192
+ }
9193
+ for (const group of groups) {
9194
+ if (!scopeIds.includes(group.workspaceId)) scopeIds.push(group.workspaceId);
9195
+ }
9196
+
9197
+ const groupsView = scopeIds.length === 0
9198
+ ? h('div', { className: 'dsh-powerup-prompt-empty' }, t('prompts.empty'))
9199
+ : h('div', { className: 'dsh-powerup-prompt-scopes' }, scopeIds.map((scopeId) => {
9200
+ const sub = groupPrompts(prompts, groups, scopeId);
9201
+ const creatingGroupHere = groupDraft !== null && groupDraft.scopeId === scopeId && groupDraft.id === '';
9202
+ return h('section', { key: 'scope:' + scopeId, className: 'dsh-powerup-prompt-scope' },
9203
+ h('div', { className: 'dsh-powerup-prompt-scope-head' },
9204
+ h('span', { className: 'dsh-powerup-prompt-scope-title' }, workspaceTitleOf(scopeId)),
9205
+ h('button', {
9206
+ type: 'button', className: 'dsh-powerup-linkbtn',
9207
+ onClick: () => setGroupDraft({ scopeId, id: '', name: '' }),
9208
+ }, t('prompts.groupNew')),
9209
+ ),
9210
+ creatingGroupHere
9211
+ ? h('div', { className: 'dsh-powerup-group-form' },
9212
+ h('input', {
9213
+ className: 'dsh-powerup-prompt-input', type: 'text', value: groupDraft.name,
9214
+ placeholder: t('prompts.groupNamePlaceholder'),
9215
+ onChange: (event) => setGroupDraft((current) => ({ ...current, name: event.target.value })),
9216
+ }),
9217
+ h('button', { type: 'button', className: 'dsh-powerup-prompt-new', onClick: saveGroup },
9218
+ t('prompts.groupCreate')),
9219
+ h('button', { type: 'button', className: 'dsh-powerup-prompt-new', onClick: () => setGroupDraft(null) },
9220
+ t('prompts.cancel')),
9221
+ )
9222
+ : null,
9223
+ h('div', { className: 'dsh-powerup-prompt-groups' }, sub.map((section) => groupBlock(section, scopeId))),
8843
9224
  );
8844
9225
  }));
8845
9226
 
@@ -9200,11 +9581,17 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9200
9581
  promptCreateDraft,
9201
9582
  readPrompts,
9202
9583
  writePrompts,
9584
+ readGroups,
9585
+ writeGroups,
9586
+ writeAll,
9587
+ groupPrompts,
9203
9588
  promptsForWorkspace,
9204
9589
  promptLabel,
9205
9590
  readLastPrompt,
9206
9591
  writeLastPrompt,
9207
9592
  resolveWorkspaceIdFromSnapshot,
9593
+ openPromptPopover,
9594
+ PromptCreateModal,
9208
9595
  HeroPromptsControl,
9209
9596
  PromptManager,
9210
9597
  runningSessionRows,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restregular/dsh-powerup",
3
- "version": "0.10.1",
3
+ "version": "0.10.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",