@restregular/dsh-powerup 0.13.0 → 0.15.0

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/client.js CHANGED
@@ -81,9 +81,11 @@
81
81
  * of resetting it. Cleared once the prompt is actually created.
82
82
  */
83
83
  const promptCreateDraft = { workspaceId: null, title: '', text: '', scope: 'current' };
84
+ /** In-progress "new requirement" dialog draft (progress panel). */
85
+ const requirementCreateDraft = { workspaceId: null, title: '', text: '', scope: 'current' };
84
86
  /** Fallback bucket when the hero cannot resolve an owning workspace yet. */
85
87
  const UNSCOPED_WORKSPACE = '__unscoped__';
86
- const VERSION = '0.11.0';
88
+ const VERSION = '0.15.0';
87
89
  const MENU_GAP = 8;
88
90
  const MENU_WIDTH = 248;
89
91
  /** Reference scheme understood by the Host's `powerup_step_read` tool. */
@@ -383,7 +385,14 @@
383
385
  'progress.clearHistoryConfirm': '确定清空全部历史进度?此操作不可撤销。',
384
386
  'progress.cleared': '历史已清空',
385
387
  'progress.requirements': '生成要求',
386
- 'progress.reqHint': '设置语言、结构、必须包含的数据、额外展示区要回答的问题等;设置后会作为后续生成的默认要求。',
388
+ 'progress.tabRequirements': '要求',
389
+ 'progress.reqHint': '每条要求可设置语言、结构、必须包含的数据、额外展示区要回答的问题等;按工作区隔离,留空工作区则对所有工作区生效。生成进度时可勾选本次要应用哪些要求。',
390
+ 'progress.reqNew': '新建要求',
391
+ 'progress.reqSelect': '本次应用的要求',
392
+ 'progress.reqSelectHint': '勾选要求后内容会填入下方输入框,可自由修改;生成/刷新时会使用输入框里的完整要求。',
393
+ 'progress.reqEditPlaceholder': '在这里编辑本次生成要使用的要求…',
394
+ 'progress.reqTextLabel': '要求内容',
395
+ 'progress.sectionTitle': '生成要求',
387
396
  'progress.reqGlobal': '通用要求(设置页)',
388
397
  'progress.reqWorkspace': '工作区要求',
389
398
  'progress.reqSession': '会话要求',
@@ -415,7 +424,12 @@
415
424
  'directAsk.copied': '已复制',
416
425
  'directAsk.close': '关闭',
417
426
  'directAsk.hide': '隐藏弹窗',
418
- 'directAsk.showHint': '再次点击闪电按钮可显示/隐藏弹窗',
427
+ 'directAsk.showHint': '输入问题开始对话;可继续追问,点「+」开启新对话,点「◷」查看历史。拖动标题栏移动窗口。',
428
+ 'directAsk.newChat': '新对话',
429
+ 'directAsk.history': '历史记录',
430
+ 'directAsk.historyEmpty': '还没有历史对话',
431
+ 'directAsk.clearHistory': '清空历史',
432
+ 'directAsk.clearHistoryConfirm': '确定清空全部问答历史?此操作不可撤销。',
419
433
  'page.promptsTitle': '工作区提示词',
420
434
  'page.promptsDesc': '为每个工作区保存可复用的提示词。开启后,新会话行的 Agent 预设右侧会出现一个下拉列表,选择即可把提示词填入输入框(可继续编辑),或点提示词右侧的发送按钮直接发出。',
421
435
  'page.promptsHow': '先启用本功能,再切到「工作区提示词」标签页创建提示词;提示词按工作区隔离,没有标题时显示开头几个字。',
@@ -761,7 +775,14 @@
761
775
  'progress.clearHistoryConfirm': 'Clear all progress history? This cannot be undone.',
762
776
  'progress.cleared': 'History cleared',
763
777
  'progress.requirements': 'Requirements',
764
- 'progress.reqHint': 'Set language, structure, required data, questions for the display area, etc. Saved requirements apply to future generations.',
778
+ 'progress.tabRequirements': 'Requirements',
779
+ 'progress.reqHint': 'Each requirement sets language, structure, required data, questions for the display area, etc. Scoped per workspace; a blank workspace applies everywhere. Choose which ones to apply when generating progress.',
780
+ 'progress.reqNew': 'New requirement',
781
+ 'progress.reqSelect': 'Requirements for this run',
782
+ 'progress.reqSelectHint': 'Checked requirements fill the box below; edit freely. Generation uses the full text in the box.',
783
+ 'progress.reqEditPlaceholder': 'Edit the requirements to use for this generation…',
784
+ 'progress.reqTextLabel': 'Requirement text',
785
+ 'progress.sectionTitle': 'Generation requirements',
765
786
  'progress.reqGlobal': 'Global requirements (settings)',
766
787
  'progress.reqWorkspace': 'Workspace requirements',
767
788
  'progress.reqSession': 'Session requirements',
@@ -793,7 +814,12 @@
793
814
  'directAsk.copied': 'Copied',
794
815
  'directAsk.close': 'Close',
795
816
  'directAsk.hide': 'Hide dialog',
796
- 'directAsk.showHint': 'Click the lightning button again to show/hide the dialog',
817
+ 'directAsk.showHint': 'Type a question to start; follow up anytime, "+" starts a new chat, "◷" shows history. Drag the title bar to move.',
818
+ 'directAsk.newChat': 'New chat',
819
+ 'directAsk.history': 'History',
820
+ 'directAsk.historyEmpty': 'No saved conversations yet',
821
+ 'directAsk.clearHistory': 'Clear history',
822
+ 'directAsk.clearHistoryConfirm': 'Clear all Q&A history? This cannot be undone.',
797
823
  'page.promptsTitle': 'Workspace prompts',
798
824
  'page.promptsDesc': 'Save reusable prompts per workspace. When enabled, a dropdown appears next to the Agent preset in the New Session row: pick a prompt to fill the composer (still editable), or click its send button to send it right away.',
799
825
  'page.promptsHow': 'Enable this feature, then open the "Workspace prompts" tab to create prompts. Prompts are scoped per workspace; without a title the first few characters are shown.',
@@ -4591,24 +4617,66 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
4591
4617
  .dsh-powerup-progress-history-item{padding:3px 9px;border:.5px solid var(--dsw-alias-border-l2);border-radius:999px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary);font:inherit;font-size:10.5px;line-height:1.5;cursor:pointer}
4592
4618
  .dsh-powerup-progress-history-item.on{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary);background:color-mix(in srgb,var(--dsw-alias-brand-primary) 10%,transparent)}
4593
4619
  .dsh-powerup-progress-age{margin:0 0 10px;padding:6px 10px;border-radius:7px;background:color-mix(in srgb,var(--dsw-alias-state-warning-primary,var(--dsw-alias-state-error-primary)) 10%,transparent);color:var(--dsw-alias-state-warning-primary,var(--dsw-alias-state-error-primary));font-size:11px;line-height:1.5}
4594
- .dsh-powerup-progress-req-pop{padding:10px 16px 0;border-bottom:.5px solid var(--dsw-alias-border-l1)}
4595
- .dsh-powerup-progress-req-pop .dsh-powerup-prompt-textarea{min-height:64px}
4620
+ .dsh-powerup-progress-req-pop{padding:10px 16px 0;border-bottom:.5px solid var(--dsw-alias-border-l1);max-height:160px;overflow-y:auto}
4621
+ .dsh-powerup-req-picker{display:flex;flex-direction:column;gap:4px;padding:4px 0}
4622
+ .dsh-powerup-req-option{display:flex;align-items:center;gap:8px;padding:5px 8px;border-radius:6px;background:var(--dsw-alias-bg-layer-1);color:var(--dsw-alias-label-secondary);font-size:11.5px;cursor:pointer}
4623
+ .dsh-powerup-req-option:hover{background:var(--dsw-alias-interactive-bg-hover)}
4624
+ .dsh-powerup-req-option input{flex:none;accent-color:var(--dsw-alias-brand-primary)}
4625
+ .dsh-powerup-req-textarea{min-height:96px;margin-top:6px}
4626
+ .dsh-powerup-req-create{margin-top:8px}
4627
+ .dsh-powerup-prompt-scope-options{display:flex;flex-wrap:wrap;gap:8px}
4628
+ .dsh-powerup-req-manager{display:flex;flex-direction:column;gap:16px}
4629
+ .dsh-powerup-req-list{display:flex;flex-direction:column;gap:8px;margin:0;padding:0;list-style:none}
4630
+ .dsh-powerup-req-item{display:flex;align-items:flex-start;gap:10px;padding:10px 12px;border:1px solid var(--dsw-alias-border-l1);border-radius:10px;background:var(--dsw-alias-bg-layer-1)}
4631
+ .dsh-powerup-req-item.off{opacity:.55}
4632
+ .dsh-powerup-req-copy{display:flex;flex:1 1 auto;flex-direction:column;gap:3px;min-width:0}
4633
+ .dsh-powerup-req-title{font-size:12.5px;font-weight:600;color:var(--dsw-alias-label-primary)}
4634
+ .dsh-powerup-req-text{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:1.5;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
4635
+ .dsh-powerup-req-form{display:flex;flex-direction:column;gap:8px;margin-top:8px;padding:10px;border-radius:8px;background:var(--dsw-alias-bg-layer-2)}
4636
+ .dsh-powerup-req-form-foot{display:flex;justify-content:flex-end;gap:8px}
4596
4637
  .dsh-powerup-progress-resizer{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;background:linear-gradient(135deg,transparent 50%,var(--dsw-alias-border-l3) 50%,transparent 62%,var(--dsw-alias-border-l3) 62%,var(--dsw-alias-border-l3) 72%,transparent 72%)}
4597
4638
  .dsh-powerup-progress-req-editor{display:flex;flex-direction:column;gap:10px;padding:8px 0}
4598
4639
  @media (prefers-reduced-motion:reduce){.dsh-powerup-progress-panel,.dsh-powerup-progress-btn.is-running svg,.dsh-powerup-progress-fill{animation:none;transition:none}}
4599
4640
  /* Direct-ask button + dialog */
4600
- .dsh-powerup-directask-btn{display:inline-flex;align-items:center;gap:4px;height:26px;padding:0 8px;border:.5px solid var(--dsw-alias-border-l2);border-radius:7px;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-secondary);font:inherit;font-size:11.5px;line-height:1;cursor:pointer}
4641
+ .dsh-powerup-directask-btn{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-2);color:var(--dsw-alias-label-secondary);font:inherit;line-height:1;cursor:pointer}
4601
4642
  .dsh-powerup-directask-btn:hover,.dsh-powerup-directask-btn.on{border-color:var(--dsw-alias-brand-primary);color:var(--dsw-alias-brand-primary)}
4602
- .dsh-powerup-directask-mask{position:fixed;z-index:1600;display:flex;box-sizing:border-box;max-height:calc(100dvh - 24px);pointer-events:none}
4603
- .dsh-powerup-directask-dialog{box-sizing:border-box;display:flex;flex-direction:column;width:100%;max-height:min(80vh,760px);border-radius:var(--dsw-radius-panel,14px);background:var(--dsw-alias-bg-layer-2);box-shadow:var(--dsw-elevation-prominent);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2);pointer-events:auto;animation:dsh-powerup-progress-in .15s ease-out}
4604
- .dsh-powerup-directask-files{display:flex;flex-wrap:wrap;gap:6px;margin-bottom:8px}
4643
+ .dsh-powerup-directask-window{position:fixed;z-index:1600;box-sizing:border-box;display:flex;flex-direction:column;min-width:360px;min-height:280px;border-radius:var(--dsw-radius-panel,14px);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:13px;line-height:1.6;overflow:hidden;animation:dsh-powerup-progress-in .15s ease-out}
4644
+ .dsh-powerup-directask-titlebar{display:flex;align-items:center;gap:8px;flex:none;padding:10px 12px;border-bottom:.5px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-3);cursor:move;user-select:none}
4645
+ .dsh-powerup-directask-title{font-size:13px;font-weight:600;white-space:nowrap}
4646
+ .dsh-powerup-directask-subtitle{flex:1 1 auto;min-width:0;color:var(--dsw-alias-label-tertiary);font-size:10.5px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
4647
+ .dsh-powerup-directask-titlebtn,.dsh-powerup-directask-close{flex:none;display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:0;border-radius:var(--dsw-radius-sm,6px);background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:15px;line-height:1;cursor:pointer}
4648
+ .dsh-powerup-directask-titlebtn:hover,.dsh-powerup-directask-titlebtn.on,.dsh-powerup-directask-close:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
4649
+ .dsh-powerup-directask-history{flex:none;max-height:180px;overflow-y:auto;padding:10px 14px;border-bottom:.5px solid var(--dsw-alias-border-l1);background:var(--dsw-alias-bg-layer-1)}
4650
+ .dsh-powerup-directask-history-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px;font-size:11.5px}
4651
+ .dsh-powerup-directask-history-list{margin:0;padding:0;list-style:none}
4652
+ .dsh-powerup-directask-history-list button{width:100%;padding:5px 8px;border:0;border-radius:6px;background:transparent;color:var(--dsw-alias-label-secondary);font:inherit;font-size:11px;text-align:left;cursor:pointer;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
4653
+ .dsh-powerup-directask-history-list button:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
4654
+ .dsh-powerup-directask-thread{flex:1 1 auto;min-height:0;overflow-y:auto;padding:14px 16px;display:flex;flex-direction:column;gap:12px;--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2)}
4655
+ .dsh-powerup-directask-welcome{margin:auto;color:var(--dsw-alias-label-tertiary);font-size:12px;text-align:center}
4656
+ .dsh-powerup-directask-turn{display:flex;flex-direction:column;gap:6px}
4657
+ .dsh-powerup-directask-msg{display:flex;flex-direction:column;gap:4px;max-width:88%}
4658
+ .dsh-powerup-directask-msg.user{align-self:flex-end;align-items:flex-end}
4659
+ .dsh-powerup-directask-msg.assistant{align-self:flex-start;align-items:flex-start}
4660
+ .dsh-powerup-directask-msg-body{padding:8px 12px;border-radius:12px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font-size:12.5px;line-height:1.7;white-space:pre-wrap;overflow-wrap:anywhere}
4661
+ .dsh-powerup-directask-msg.user .dsh-powerup-directask-msg-body{background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-primary-foreground,var(--dsw-alias-bg-layer-1));border-bottom-right-radius:3px}
4662
+ .dsh-powerup-directask-msg.assistant .dsh-powerup-directask-msg-body{border-bottom-left-radius:3px}
4663
+ .dsh-powerup-directask-ctx{display:flex;flex-wrap:wrap;gap:4px;align-self:flex-end}
4664
+ .dsh-powerup-directask-ctx span{padding:2px 7px;border-radius:999px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-tertiary);font-size:10px}
4665
+ .dsh-powerup-directask-files{display:flex;flex-wrap:wrap;gap:6px;padding:0 14px 6px}
4605
4666
  .dsh-powerup-directask-file{display:inline-flex;align-items:center;gap:5px;padding:3px 8px;border-radius:999px;background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-secondary);font-size:11px}
4606
4667
  .dsh-powerup-directask-file button{border:0;background:transparent;color:var(--dsw-alias-label-tertiary);cursor:pointer;font-size:13px;line-height:1}
4607
- .dsh-powerup-directask-label{display:block}
4608
- .dsh-powerup-directask-label textarea{min-height:90px}
4609
- .dsh-powerup-directask-attach{display:inline-flex;align-items:center;gap:6px;width:fit-content;margin-top:8px;color:var(--dsw-alias-label-secondary);font-size:11.5px;cursor:pointer}
4610
- .dsh-powerup-directask-answer{margin-top:12px;padding-top:10px;border-top:.5px solid var(--dsw-alias-border-l1)}
4611
- .dsh-powerup-directask-answer-body{margin:6px 0;padding:12px;border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-bg-layer-3);color:var(--dsw-alias-label-primary);font-size:12.5px;line-height:1.7;white-space:pre-wrap;overflow-wrap:anywhere;max-height:360px;overflow-y:auto}
4668
+ .dsh-powerup-directask-composer{flex:none;padding:10px 14px 12px;border-top:.5px solid var(--dsw-alias-border-l1)}
4669
+ .dsh-powerup-directask-inputrow{display:flex;align-items:flex-end;gap:8px;padding:6px 6px 6px 10px;border:1px solid var(--dsw-alias-border-l2);border-radius:14px;background:var(--dsw-alias-bg-layer-3)}
4670
+ .dsh-powerup-directask-inputrow:focus-within{border-color:var(--dsw-alias-brand-primary)}
4671
+ /* Native file input is hidden; only the custom '+' chip is shown. */
4672
+ .dsh-powerup-directask-attach{position:relative;display:inline-flex;align-items:center;justify-content:center;flex:none;width:26px;height:26px;border-radius:7px;color:var(--dsw-alias-label-secondary);font-size:18px;line-height:1;cursor:pointer;overflow:hidden}
4673
+ .dsh-powerup-directask-attach:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}
4674
+ .dsh-powerup-directask-attach input[type=file]{position:absolute;inset:0;width:100%;height:100%;opacity:0;cursor:pointer}
4675
+ .dsh-powerup-directask-input{flex:1 1 auto;min-width:0;max-height:140px;border:0;outline:0;background:transparent;color:var(--dsw-alias-label-primary);font:inherit;font-size:12.5px;line-height:1.6;resize:none}
4676
+ .dsh-powerup-directask-input::placeholder{color:var(--dsw-alias-label-tertiary)}
4677
+ .dsh-powerup-directask-send{flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;border:0;border-radius:8px;background:var(--dsw-alias-brand-primary);color:var(--dsw-alias-label-primary-foreground,var(--dsw-alias-bg-layer-1));cursor:pointer}
4678
+ .dsh-powerup-directask-send:disabled{opacity:.4;cursor:not-allowed}
4679
+ .dsh-powerup-directask-resizer{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;background:linear-gradient(135deg,transparent 50%,var(--dsw-alias-border-l3) 50%,transparent 62%,var(--dsw-alias-border-l3) 62%,var(--dsw-alias-border-l3) 72%,transparent 72%)}
4612
4680
  `;
4613
4681
 
4614
4682
  /** Max display length of a session option, in Unicode code points. */
@@ -9111,24 +9179,55 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9111
9179
  }
9112
9180
 
9113
9181
  /**
9114
- * Lighting-bolt button in the composer. Opens a dialog that sends a
9115
- * question straight to the model — no Agent, system prompt, tools or
9116
- * skills. The dialog can be hidden/shown by clicking the button again.
9182
+ * Lightning-bolt button in the composer (icon only). Opens a floating,
9183
+ * draggable + resizable DSH-styled Q&A window that talks straight to the
9184
+ * model — no Agent, system prompt, tools or skills. Supports continuous
9185
+ * multi-turn Q&A and a browsable/clearable history of past exchanges.
9117
9186
  */
9118
9187
  function DirectAskButton({ sessionId }) {
9119
9188
  const settings = useSettings();
9120
9189
  const [open, setOpen] = useState(false);
9121
9190
  const [question, setQuestion] = useState('');
9122
9191
  const [files, setFiles] = useState([]);
9123
- const [answer, setAnswer] = useState('');
9124
9192
  const [busy, setBusy] = useState(false);
9125
9193
  const [error, setError] = useState('');
9126
9194
  const [copied, setCopied] = useState(false);
9195
+ /** Current conversation: [{question, answer, context, at}]. */
9196
+ const [turns, setTurns] = useState([]);
9197
+ /** Archived conversations, newest first: [{id, at, turns}]. */
9198
+ const [history, setHistory] = useState(() => {
9199
+ try { return JSON.parse(localStorage.getItem('dsh-powerup:directask:history:v1') || '[]'); }
9200
+ catch { return []; }
9201
+ });
9202
+ const [showHistory, setShowHistory] = useState(false);
9203
+ const [pos, setPos] = useState(() => {
9204
+ try {
9205
+ const saved = JSON.parse(localStorage.getItem('dsh-powerup:directask:pos:v1') || 'null');
9206
+ if (saved !== null && Number.isFinite(saved.x) && Number.isFinite(saved.y)) return { x: saved.x, y: saved.y };
9207
+ } catch { /* fall through */ }
9208
+ return { x: 24, y: 96 };
9209
+ });
9210
+ const [size, setSize] = useState(() => {
9211
+ try {
9212
+ const saved = JSON.parse(localStorage.getItem('dsh-powerup:directask:size:v1') || 'null');
9213
+ if (saved !== null && Number.isFinite(saved.w) && Number.isFinite(saved.h)) {
9214
+ return { w: Math.max(360, Math.min(1100, saved.w)), h: Math.max(280, Math.min(900, saved.h)) };
9215
+ }
9216
+ } catch { /* fall through */ }
9217
+ return { w: 620, h: 560 };
9218
+ });
9127
9219
  const dialogRef = useRef(null);
9220
+ const dragRef = useRef(null);
9221
+ const bottomRef = useRef(null);
9128
9222
  const sessionRef = useRef(sessionId);
9129
9223
  sessionRef.current = sessionId;
9130
9224
  const t = useCallback((key, params) => translateCurrent(key, params), []);
9131
9225
 
9226
+ const persistHistory = useCallback((next) => {
9227
+ setHistory(next);
9228
+ try { localStorage.setItem('dsh-powerup:directask:history:v1', JSON.stringify(next.slice(0, 30))); } catch { /* ignore */ }
9229
+ }, []);
9230
+
9132
9231
  useEffect(() => {
9133
9232
  if (!open) return undefined;
9134
9233
  const onKey = (event) => {
@@ -9138,12 +9237,58 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9138
9237
  return () => document.removeEventListener('keydown', onKey, true);
9139
9238
  }, [open]);
9140
9239
 
9240
+ // Drag (title bar) and resize (bottom-right handle) with native pointers.
9241
+ useEffect(() => {
9242
+ if (!open) return undefined;
9243
+ const onMove = (event) => {
9244
+ const drag = dragRef.current;
9245
+ if (drag === null) return;
9246
+ if (drag.kind === 'move') {
9247
+ setPos({
9248
+ x: Math.max(0, Math.min(window.innerWidth - 120, drag.px + event.clientX - drag.x)),
9249
+ y: Math.max(0, Math.min(window.innerHeight - 60, drag.py + event.clientY - drag.y)),
9250
+ });
9251
+ } else if (drag.kind === 'resize') {
9252
+ setSize({
9253
+ w: Math.max(360, Math.min(1100, drag.w + event.clientX - drag.x)),
9254
+ h: Math.max(280, Math.min(900, drag.h + event.clientY - drag.y)),
9255
+ });
9256
+ }
9257
+ };
9258
+ const onUp = () => {
9259
+ if (dragRef.current === null) return;
9260
+ dragRef.current = null;
9261
+ try {
9262
+ localStorage.setItem('dsh-powerup:directask:pos:v1', JSON.stringify(pos));
9263
+ localStorage.setItem('dsh-powerup:directask:size:v1', JSON.stringify(size));
9264
+ } catch { /* ignore */ }
9265
+ };
9266
+ document.addEventListener('pointermove', onMove);
9267
+ document.addEventListener('pointerup', onUp);
9268
+ return () => {
9269
+ document.removeEventListener('pointermove', onMove);
9270
+ document.removeEventListener('pointerup', onUp);
9271
+ };
9272
+ }, [open, pos, size]);
9273
+
9274
+ useEffect(() => {
9275
+ if (bottomRef.current !== null) bottomRef.current.scrollIntoView?.({ block: 'nearest' });
9276
+ }, [turns, busy]);
9277
+
9141
9278
  const send = useCallback(async () => {
9142
9279
  const q = question.trim();
9143
9280
  if (q === '') { setError(t('directAsk.empty')); return; }
9281
+ const priorContext = files.map((f) => ({ name: f.name, text: f.text }));
9282
+ // Continuous Q&A: send the current turns as prior messages.
9283
+ const historyMsgs = [];
9284
+ for (const turn of turns) {
9285
+ historyMsgs.push({ role: 'user', text: turn.question });
9286
+ if (turn.answer) historyMsgs.push({ role: 'assistant', text: turn.answer });
9287
+ }
9144
9288
  setBusy(true);
9145
9289
  setError('');
9146
- setAnswer('');
9290
+ setQuestion('');
9291
+ setFiles([]);
9147
9292
  setCopied(false);
9148
9293
  try {
9149
9294
  const response = await fetch(DIRECT_ASK_API, {
@@ -9152,18 +9297,43 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9152
9297
  body: JSON.stringify({
9153
9298
  sessionId: sessionRef.current ?? '',
9154
9299
  question: q,
9155
- context: files.map((f) => ({ name: f.name, text: f.text })),
9300
+ context: priorContext,
9301
+ history: historyMsgs,
9156
9302
  }),
9157
9303
  });
9158
9304
  const body = await response.json();
9159
9305
  if (!body?.ok) throw new Error(body?.error ?? `HTTP ${response.status}`);
9160
- setAnswer(typeof body.answer === 'string' ? body.answer : '');
9306
+ setTurns((cur) => [...cur, {
9307
+ question: q, answer: typeof body.answer === 'string' ? body.answer : '',
9308
+ context: priorContext, at: Date.now(),
9309
+ }]);
9161
9310
  } catch (err) {
9162
9311
  setError(err?.message ?? String(err));
9312
+ setQuestion(q);
9163
9313
  } finally {
9164
9314
  setBusy(false);
9165
9315
  }
9166
- }, [question, files, t]);
9316
+ }, [question, files, turns, t]);
9317
+
9318
+ const newChat = useCallback(() => {
9319
+ if (turns.length > 0) persistHistory([{ id: String(Date.now()), at: Date.now(), turns }, ...history]);
9320
+ setTurns([]);
9321
+ setError('');
9322
+ setShowHistory(false);
9323
+ }, [turns, history, persistHistory]);
9324
+
9325
+ const openArchived = useCallback((entry) => {
9326
+ if (turns.length > 0) persistHistory([{ id: String(Date.now()), at: Date.now(), turns }, ...history.filter((h) => h.id !== entry.id)]);
9327
+ else persistHistory(history.filter((h) => h.id !== entry.id));
9328
+ setTurns(Array.isArray(entry.turns) ? entry.turns : []);
9329
+ setShowHistory(false);
9330
+ }, [turns, history, persistHistory]);
9331
+
9332
+ const clearHistory = useCallback(() => {
9333
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function'
9334
+ && !window.confirm(t('directAsk.clearHistoryConfirm'))) return;
9335
+ persistHistory([]);
9336
+ }, [t, persistHistory]);
9167
9337
 
9168
9338
  const pickFiles = useCallback(async (event) => {
9169
9339
  const picked = Array.from(event?.target?.files ?? []);
@@ -9182,87 +9352,134 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9182
9352
 
9183
9353
  if (settings.directAsk === false) return null;
9184
9354
 
9185
- const lightning = h('svg', { viewBox: '0 0 16 16', width: 15, height: 15, 'aria-hidden': 'true' },
9355
+ const lightning = h('svg', { viewBox: '0 0 16 16', width: 16, height: 16, 'aria-hidden': 'true' },
9186
9356
  h('path', { d: 'M9 1.5 3.5 9H7l-1 5.5L12.5 7H9l1-5.5Z', fill: 'currentColor' }),
9187
9357
  );
9188
9358
 
9359
+ // Icon-only composer button.
9189
9360
  const button = h('button', {
9190
9361
  type: 'button',
9191
9362
  className: 'dsh-powerup-directask-btn' + (open ? ' on' : ''),
9192
9363
  title: t('directAsk.hint'),
9193
9364
  'aria-label': t('directAsk.label'),
9194
9365
  onClick: () => setOpen((v) => !v),
9195
- }, lightning, h('span', null, t('directAsk.label')));
9366
+ }, lightning);
9196
9367
 
9197
9368
  const dialog = !open ? null : h('div', {
9198
- className: 'dsh-powerup-directask-mask',
9199
- style: {
9200
- bottom: '72px',
9201
- right: '18px',
9202
- width: 'min(600px, calc(100vw - 36px))',
9203
- },
9369
+ className: 'dsh-powerup-directask-window',
9370
+ style: { left: `${pos.x}px`, top: `${pos.y}px`, width: `${size.w}px`, height: `${size.h}px` },
9204
9371
  },
9205
9372
  h('div', {
9206
- ref: dialogRef,
9207
- className: 'dsh-powerup-directask-dialog',
9208
- role: 'dialog',
9209
- 'aria-label': t('directAsk.title'),
9373
+ className: 'dsh-powerup-directask-titlebar',
9374
+ onPointerDown: (event) => {
9375
+ const target = event.target;
9376
+ if (target instanceof Element && target.closest('button')) return;
9377
+ dragRef.current = { kind: 'move', x: event.clientX, y: event.clientY, px: pos.x, py: pos.y };
9378
+ },
9210
9379
  },
9211
- h('div', { className: 'dsh-powerup-update-head' },
9212
- h('div', { className: 'dsh-powerup-update-heading' },
9213
- h('h2', null, t('directAsk.title')),
9214
- h('p', { className: 'dsh-powerup-update-note' }, t('directAsk.subtitle')),
9215
- ),
9216
- h('button', {
9217
- type: 'button', className: 'dsh-powerup-update-close',
9218
- 'aria-label': t('directAsk.close'), onClick: () => setOpen(false),
9219
- }, '×'),
9380
+ h('span', { className: 'dsh-powerup-directask-title' }, t('directAsk.title')),
9381
+ h('span', { className: 'dsh-powerup-directask-subtitle' }, t('directAsk.subtitle')),
9382
+ h('button', {
9383
+ type: 'button', className: 'dsh-powerup-directask-titlebtn',
9384
+ title: t('directAsk.newChat'), onClick: newChat,
9385
+ }, '+'),
9386
+ h('button', {
9387
+ type: 'button', className: 'dsh-powerup-directask-titlebtn' + (showHistory ? ' on' : ''),
9388
+ title: t('directAsk.history'), onClick: () => setShowHistory((v) => !v),
9389
+ }, '◷'),
9390
+ h('button', {
9391
+ type: 'button', className: 'dsh-powerup-directask-close',
9392
+ 'aria-label': t('directAsk.close'), onClick: () => setOpen(false),
9393
+ }, '×'),
9394
+ ),
9395
+ showHistory ? h('div', { className: 'dsh-powerup-directask-history' },
9396
+ h('div', { className: 'dsh-powerup-directask-history-head' },
9397
+ h('strong', null, t('directAsk.history')),
9398
+ h('button', { type: 'button', className: 'dsh-powerup-progress-mini', onClick: clearHistory }, t('directAsk.clearHistory')),
9220
9399
  ),
9221
- h('div', { className: 'dsh-powerup-update-body' },
9222
- files.length > 0 ? h('div', { className: 'dsh-powerup-directask-files' },
9223
- files.map((f, i) => h('span', { key: i, className: 'dsh-powerup-directask-file' },
9224
- f.name,
9225
- h('button', {
9226
- type: 'button', 'aria-label': t('directAsk.removeFile'),
9227
- onClick: () => setFiles((cur) => cur.filter((_, j) => j !== i)),
9228
- }, '×'),
9400
+ history.length === 0
9401
+ ? h('p', { className: 'dsh-powerup-progress-empty' }, t('directAsk.historyEmpty'))
9402
+ : h('ul', { className: 'dsh-powerup-directask-history-list' },
9403
+ history.map((entry) => h('li', { key: entry.id },
9404
+ h('button', { type: 'button', onClick: () => openArchived(entry) },
9405
+ new Date(entry.at ?? Date.now()).toLocaleString(),
9406
+ ' · ', String(entry.turns?.[0]?.question ?? '').slice(0, 40),
9407
+ ),
9229
9408
  )),
9230
- ) : null,
9231
- h('label', { className: 'dsh-powerup-directask-label' },
9232
- h('textarea', {
9233
- className: 'dsh-powerup-prompt-input dsh-powerup-prompt-textarea',
9234
- value: question,
9235
- placeholder: t('directAsk.placeholder'),
9236
- disabled: busy,
9237
- onChange: (event) => setQuestion(event.target.value),
9238
- }),
9239
9409
  ),
9240
- h('label', { className: 'dsh-powerup-directask-attach' },
9241
- h('input', { type: 'file', multiple: true, onChange: (e) => void pickFiles(e) }),
9242
- h('span', null, t('directAsk.attach')),
9410
+ ) : null,
9411
+ h('div', { className: 'dsh-powerup-directask-thread' },
9412
+ turns.length === 0 && !busy
9413
+ ? h('p', { className: 'dsh-powerup-directask-welcome' }, t('directAsk.showHint'))
9414
+ : null,
9415
+ turns.map((turn, i) => h('div', { key: i, className: 'dsh-powerup-directask-turn' },
9416
+ h('div', { className: 'dsh-powerup-directask-msg user' },
9417
+ h('div', { className: 'dsh-powerup-directask-msg-body' }, turn.question),
9243
9418
  ),
9244
- h('p', { className: 'dsh-powerup-setting-hint' }, t('directAsk.attachHint')),
9245
- error ? h('p', { className: 'dsh-powerup-progress-error' }, error) : null,
9246
- answer !== '' ? h('div', { className: 'dsh-powerup-directask-answer' },
9247
- h('h4', { className: 'dsh-powerup-section' }, t('directAsk.answer')),
9248
- h('div', { className: 'dsh-powerup-directask-answer-body' }, answer),
9419
+ turn.context?.length ? h('div', { className: 'dsh-powerup-directask-ctx' },
9420
+ turn.context.map((f, j) => h('span', { key: j }, f.name)),
9421
+ ) : null,
9422
+ h('div', { className: 'dsh-powerup-directask-msg assistant' },
9423
+ h('div', { className: 'dsh-powerup-directask-msg-body' }, turn.answer || '…'),
9249
9424
  h('button', {
9250
9425
  type: 'button', className: 'dsh-powerup-progress-mini',
9251
9426
  onClick: async () => {
9252
- const ok = await copyText(answer);
9427
+ const ok = await copyText(turn.answer);
9253
9428
  if (ok) { setCopied(true); setTimeout(() => setCopied(false), 1500); }
9254
9429
  },
9255
9430
  }, copied ? t('directAsk.copied') : t('directAsk.copy')),
9256
- ) : null,
9257
- ),
9258
- h('div', { className: 'dsh-powerup-update-foot' },
9259
- h('span', { className: 'dsh-powerup-setting-hint' }, t('directAsk.showHint')),
9431
+ ),
9432
+ )),
9433
+ busy ? h('div', { className: 'dsh-powerup-directask-msg assistant' },
9434
+ h('div', { className: 'dsh-powerup-directask-msg-body' }, t('directAsk.sending')),
9435
+ ) : null,
9436
+ h('div', { ref: bottomRef }),
9437
+ ),
9438
+ error ? h('p', { className: 'dsh-powerup-progress-error' }, error) : null,
9439
+ h('div', { className: 'dsh-powerup-directask-composer' },
9440
+ files.length > 0 ? h('div', { className: 'dsh-powerup-directask-files' },
9441
+ files.map((f, i) => h('span', { key: i, className: 'dsh-powerup-directask-file' },
9442
+ f.name,
9443
+ h('button', {
9444
+ type: 'button', 'aria-label': t('directAsk.removeFile'),
9445
+ onClick: () => setFiles((cur) => cur.filter((_, j) => j !== i)),
9446
+ }, '×'),
9447
+ )),
9448
+ ) : null,
9449
+ h('div', { className: 'dsh-powerup-directask-inputrow' },
9450
+ h('label', { className: 'dsh-powerup-directask-attach', title: t('directAsk.attachHint') },
9451
+ h('input', { type: 'file', multiple: true, onChange: (e) => void pickFiles(e) }),
9452
+ h('span', null, '+'),
9453
+ ),
9454
+ h('textarea', {
9455
+ className: 'dsh-powerup-directask-input',
9456
+ value: question,
9457
+ placeholder: t('directAsk.placeholder'),
9458
+ disabled: busy,
9459
+ rows: 1,
9460
+ onChange: (event) => setQuestion(event.target.value),
9461
+ onKeyDown: (event) => {
9462
+ if (event.key === 'Enter' && !event.shiftKey && !event.isComposing) {
9463
+ event.preventDefault();
9464
+ void send();
9465
+ }
9466
+ },
9467
+ }),
9260
9468
  h('button', {
9261
- type: 'button', className: 'dsh-powerup-update-primary',
9469
+ type: 'button', className: 'dsh-powerup-directask-send',
9262
9470
  disabled: busy || question.trim() === '', onClick: () => void send(),
9263
- }, busy ? t('directAsk.sending') : t('directAsk.send')),
9471
+ title: t('directAsk.send'),
9472
+ }, h('svg', { viewBox: '0 0 16 16', width: 16, height: 16, 'aria-hidden': 'true' },
9473
+ h('path', { d: 'M3 8h9M8.5 4.5 12 8l-3.5 3.5', fill: 'none', stroke: 'currentColor', strokeWidth: 1.4, strokeLinecap: 'round', strokeLinejoin: 'round' }))),
9264
9474
  ),
9265
9475
  ),
9476
+ h('div', {
9477
+ className: 'dsh-powerup-directask-resizer',
9478
+ onPointerDown: (event) => {
9479
+ event.preventDefault();
9480
+ dragRef.current = { kind: 'resize', x: event.clientX, y: event.clientY, w: size.w, h: size.h };
9481
+ },
9482
+ }),
9266
9483
  );
9267
9484
 
9268
9485
  return h(React.Fragment, null, button, renderInBody(dialog));
@@ -9419,7 +9636,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9419
9636
  ),
9420
9637
  ),
9421
9638
  h(MaskRuleEditor, { scope: 'workspace', t, workspaceId }),
9422
- h(ProgressScopeRequirements, { t, workspaceId, sessionId: ownerId }),
9639
+ h(RequirementManager, { ctx }),
9423
9640
  ),
9424
9641
  );
9425
9642
  }
@@ -9968,6 +10185,15 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9968
10185
  onClick: () => setTab('prompts'),
9969
10186
  }, t('prompts.tabManage'))
9970
10187
  : null,
10188
+ settings.taskProgress !== false
10189
+ ? h('button', {
10190
+ type: 'button',
10191
+ role: 'tab',
10192
+ 'aria-selected': tab === 'requirements' ? 'true' : 'false',
10193
+ className: 'dsh-powerup-tab' + (tab === 'requirements' ? ' on' : ''),
10194
+ onClick: () => setTab('requirements'),
10195
+ }, t('progress.tabRequirements'))
10196
+ : null,
9971
10197
  );
9972
10198
 
9973
10199
  const featuresContent = h('div', null,
@@ -9982,11 +10208,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
9982
10208
  featureCard('scrollToTop', ScrollTopIcon, 'page.scrollToTopTitle', 'page.scrollToTopDesc', 'page.scrollToTopHow'),
9983
10209
  featureCard('contentRendering', PowerUpLineIcon, 'page.renderingTitle', 'page.renderingDesc', 'page.renderingHow'),
9984
10210
  featureCard('dualSend', LauncherIcon, 'page.dualSendTitle', 'page.dualSendDesc', 'page.dualSendHow'),
9985
- featureCard('taskProgress', ProgressIcon, 'page.taskProgressTitle', 'page.taskProgressDesc', 'page.taskProgressHow',
9986
- h('div', { className: 'dsh-powerup-card-detail' },
9987
- h(ProgressRequirementsEditor, { t }),
9988
- ),
9989
- ),
10211
+ featureCard('taskProgress', ProgressIcon, 'page.taskProgressTitle', 'page.taskProgressDesc', 'page.taskProgressHow'),
9990
10212
  featureCard('directAsk', TagIcon, 'page.directAskTitle', 'page.directAskDesc', 'page.directAskHow',
9991
10213
  h('div', { className: 'dsh-powerup-card-detail' },
9992
10214
  settingRow('directAsk', settings.directAsk !== false, t('page.directAskToggle'), t('page.directAskToggleHint')),
@@ -10011,7 +10233,9 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10011
10233
  ? h(MaskRuleEditor, { scope: 'global', t })
10012
10234
  : tab === 'prompts' && settings.workspacePrompts !== false
10013
10235
  ? h(PromptManager, { ctx })
10014
- : featuresContent,
10236
+ : tab === 'requirements' && settings.taskProgress !== false
10237
+ ? h(RequirementManager, { ctx })
10238
+ : featuresContent,
10015
10239
  h('footer', { className: 'dsh-powerup-foot' },
10016
10240
  h('span', null, format(t('page.footer'), { version: VERSION })),
10017
10241
  h('span', { className: 'dsh-powerup-dot' }),
@@ -10053,8 +10277,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10053
10277
  const HISTORY_API = '/dsh-powerup/api/progress-history';
10054
10278
  const DIRECT_ASK_API = '/dsh-powerup/api/direct-ask';
10055
10279
 
10056
- /** Module-level requirements cache: {global, workspaces:{}, sessions:{}}. */
10057
- let requirementsCache = { global: '', workspaces: {}, sessions: {} };
10280
+ /** Module-level requirements cache: flat records [{id,title,text,workspaceId,enabled}]. */
10281
+ let requirementsCache = [];
10058
10282
  let requirementsLoaded = false;
10059
10283
  const requirementsListeners = new Set();
10060
10284
  function emitRequirements() {
@@ -10062,18 +10286,24 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10062
10286
  try { fn(); } catch { /* one listener must not break the rest */ }
10063
10287
  }
10064
10288
  }
10289
+ function normalizeRequirement(item) {
10290
+ if (item === null || typeof item !== 'object') return null;
10291
+ return {
10292
+ id: typeof item.id === 'string' && item.id !== '' ? item.id : newId(),
10293
+ title: typeof item.title === 'string' ? item.title : '',
10294
+ text: typeof item.text === 'string' ? item.text : '',
10295
+ workspaceId: typeof item.workspaceId === 'string' ? item.workspaceId : '',
10296
+ enabled: item.enabled !== false,
10297
+ };
10298
+ }
10065
10299
  async function loadRequirements() {
10066
10300
  if (requirementsLoaded) return requirementsCache;
10067
10301
  requirementsLoaded = true;
10068
10302
  try {
10069
10303
  const response = await fetch(REQUIREMENTS_API, { headers: { accept: 'application/json' } });
10070
10304
  const data = await response.json();
10071
- if (data?.ok && data.requirements !== null && typeof data.requirements === 'object') {
10072
- requirementsCache = {
10073
- global: typeof data.requirements.global === 'string' ? data.requirements.global : '',
10074
- workspaces: data.requirements.workspaces ?? {},
10075
- sessions: data.requirements.sessions ?? {},
10076
- };
10305
+ if (data?.ok && Array.isArray(data.requirements)) {
10306
+ requirementsCache = data.requirements.map(normalizeRequirement).filter(Boolean);
10077
10307
  }
10078
10308
  } catch {
10079
10309
  /* Host unavailable: keep the last known value. */
@@ -10082,12 +10312,12 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10082
10312
  return requirementsCache;
10083
10313
  }
10084
10314
  function saveRequirements(next) {
10085
- requirementsCache = next;
10315
+ requirementsCache = (Array.isArray(next) ? next : []).map(normalizeRequirement).filter(Boolean);
10086
10316
  emitRequirements();
10087
10317
  fetch(REQUIREMENTS_API, {
10088
10318
  method: 'POST',
10089
10319
  headers: { 'content-type': 'application/json', accept: 'application/json' },
10090
- body: JSON.stringify({ requirements: next }),
10320
+ body: JSON.stringify({ requirements: requirementsCache }),
10091
10321
  }).catch(() => { /* in-memory copy still works this session */ });
10092
10322
  }
10093
10323
  function useRequirements() {
@@ -10100,65 +10330,273 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10100
10330
  }, []);
10101
10331
  return requirementsCache;
10102
10332
  }
10333
+ /** Requirements visible to one workspace: global (''), plus that workspace. */
10334
+ function requirementsForWorkspace(list, workspaceId) {
10335
+ const id = typeof workspaceId === 'string' ? workspaceId : '';
10336
+ return (Array.isArray(list) ? list : [])
10337
+ .filter((r) => r.workspaceId === '' || r.workspaceId === id);
10338
+ }
10103
10339
 
10104
- /** Textarea field for one requirements layer. */
10105
- function RequirementField({ label, hint, value, placeholder, onChange }) {
10106
- return h('label', { className: 'dsh-powerup-prompt-field' },
10107
- h('span', { className: 'dsh-powerup-prompt-field-label' }, label),
10108
- hint ? h('span', { className: 'dsh-powerup-setting-hint' }, hint) : null,
10109
- h('textarea', {
10110
- className: 'dsh-powerup-prompt-input dsh-powerup-prompt-textarea',
10111
- value: value ?? '',
10112
- placeholder: placeholder ?? '',
10113
- onChange: (event) => onChange(event.target.value),
10340
+ /**
10341
+ * Create/edit form for one requirement record. On creation the workspace
10342
+ * is chosen here (any workspace, or global) — exactly like the prompt form.
10343
+ */
10344
+ function RequirementForm({ draft, setDraft, workspaces, t, save, cancel }) {
10345
+ const field = (key, placeholder, className) => h('label', { className: 'dsh-powerup-prompt-field' },
10346
+ h('input', {
10347
+ className: 'dsh-powerup-prompt-input' + (className ? ' ' + className : ''),
10348
+ type: 'text', value: draft?.[key] ?? '', placeholder,
10349
+ onChange: (event) => setDraft({ ...draft, [key]: event.target.value }),
10114
10350
  }),
10115
10351
  );
10352
+ return h('div', { className: 'dsh-powerup-req-form' },
10353
+ field('title', t('prompts.titlePlaceholder')),
10354
+ h('label', { className: 'dsh-powerup-prompt-field' },
10355
+ h('span', { className: 'dsh-powerup-prompt-field-label' }, t('prompts.workspaceLabel')),
10356
+ h(WorkspaceSelect, {
10357
+ value: draft?.workspaceId ?? '',
10358
+ options: [
10359
+ { value: '', label: t('prompts.anyWorkspace') },
10360
+ ...workspaces.map((ws) => ({ value: ws.workspaceId, label: ws.title || ws.workspaceId, hint: ws.title ? ws.workspaceId : undefined })),
10361
+ ],
10362
+ onChange: (value) => setDraft({ ...draft, workspaceId: value }),
10363
+ t,
10364
+ }),
10365
+ ),
10366
+ h('label', { className: 'dsh-powerup-prompt-field' },
10367
+ h('span', { className: 'dsh-powerup-prompt-field-label' }, t('progress.reqTextLabel')),
10368
+ h('textarea', {
10369
+ className: 'dsh-powerup-prompt-input dsh-powerup-prompt-textarea',
10370
+ value: draft?.text ?? '', placeholder: t('progress.reqPlaceholder'),
10371
+ onChange: (event) => setDraft({ ...draft, text: event.target.value }),
10372
+ }),
10373
+ ),
10374
+ h('div', { className: 'dsh-powerup-prompt-form-actions' },
10375
+ h('button', { type: 'button', className: 'dsh-powerup-prompt-new', onClick: cancel }, t('prompts.cancel')),
10376
+ h('button', { type: 'button', className: 'dsh-powerup-prompt-new', onClick: save }, t('prompts.save')),
10377
+ ),
10378
+ );
10116
10379
  }
10117
10380
 
10118
- /** Settings-page editor: global progress requirements. */
10119
- function ProgressRequirementsEditor({ t }) {
10381
+ /**
10382
+ * Settings-page manager, modelled on PromptManager: "New requirement"
10383
+ * opens the form where the workspace is picked; only scopes that actually
10384
+ * contain requirements are listed (global first, then each such workspace).
10385
+ */
10386
+ function RequirementManager({ ctx }) {
10120
10387
  const reqs = useRequirements();
10121
- return h('div', { className: 'dsh-powerup-progress-req-editor' },
10122
- h('p', { className: 'dsh-powerup-card-desc' }, t('progress.reqHint')),
10123
- h(RequirementField, {
10124
- label: t('progress.reqGlobal'),
10125
- value: reqs.global,
10126
- placeholder: t('progress.reqPlaceholder'),
10127
- onChange: (value) => saveRequirements({ ...requirementsCache, global: value }),
10128
- }),
10388
+ const [, forceLocale] = useState(0);
10389
+ const [draft, setDraft] = useState(null);
10390
+ const t = (key, params) => translateCurrent(key, params);
10391
+ useEffect(() => {
10392
+ const locale = ctx?.get?.('locale');
10393
+ if (locale === undefined || typeof locale.subscribe !== 'function') return undefined;
10394
+ return locale.subscribe(() => forceLocale((v) => v + 1));
10395
+ }, [ctx]);
10396
+ const workspaces = (() => {
10397
+ try {
10398
+ const snapshot = ctx?.get?.('workspaces')?.list?.getSnapshot?.();
10399
+ return Array.isArray(snapshot?.items) ? snapshot.items : [];
10400
+ } catch { return []; }
10401
+ })();
10402
+ const titleOf = (id) => id === '' ? t('prompts.anyWorkspace') : (workspaces.find((ws) => ws.workspaceId === id)?.title || id);
10403
+
10404
+ const cancel = () => setDraft(null);
10405
+ const save = () => {
10406
+ if (draft === null) return;
10407
+ const text = typeof draft.text === 'string' ? draft.text.trim() : '';
10408
+ if (text === '') return;
10409
+ const record = {
10410
+ id: draft.id || newId(),
10411
+ title: typeof draft.title === 'string' ? draft.title.trim() : '',
10412
+ text,
10413
+ workspaceId: typeof draft.workspaceId === 'string' ? draft.workspaceId : '',
10414
+ enabled: draft.enabled !== false,
10415
+ };
10416
+ const next = reqs.filter((r) => r.id !== record.id);
10417
+ next.push(record);
10418
+ saveRequirements(next);
10419
+ cancel();
10420
+ };
10421
+ const remove = (record) => {
10422
+ if (typeof window !== 'undefined' && typeof window.confirm === 'function'
10423
+ && !window.confirm(t('prompts.confirmDelete'))) return;
10424
+ saveRequirements(reqs.filter((r) => r.id !== record.id));
10425
+ };
10426
+ const toggleEnabled = (record) => {
10427
+ saveRequirements(reqs.map((r) => (r.id === record.id ? { ...r, enabled: r.enabled === false } : r)));
10428
+ };
10429
+
10430
+ // Only show scopes that have requirements (plus orphaned ids).
10431
+ const scopeIds = [];
10432
+ if (reqs.some((r) => r.workspaceId === '')) scopeIds.push('');
10433
+ for (const ws of workspaces) {
10434
+ if (reqs.some((r) => r.workspaceId === ws.workspaceId)) scopeIds.push(ws.workspaceId);
10435
+ }
10436
+ for (const r of reqs) {
10437
+ if (!scopeIds.includes(r.workspaceId)) scopeIds.push(r.workspaceId);
10438
+ }
10439
+
10440
+ return h('div', null,
10441
+ h('div', { className: 'dsh-powerup-prompt-head' },
10442
+ h('div', null,
10443
+ h('div', { className: 'dsh-powerup-prompt-head-title' }, t('progress.sectionTitle')),
10444
+ h('div', { className: 'dsh-powerup-prompt-head-sub' }, t('progress.reqHint')),
10445
+ ),
10446
+ h('button', {
10447
+ type: 'button', className: 'dsh-powerup-prompt-new',
10448
+ onClick: () => setDraft({ id: '', title: '', text: '', workspaceId: '', enabled: true }),
10449
+ }, t('progress.reqNew')),
10450
+ ),
10451
+ draft !== null ? h('section', { className: 'dsh-powerup-prompt-card' },
10452
+ h(RequirementForm, { draft, setDraft, workspaces, t, save, cancel }),
10453
+ ) : null,
10454
+ scopeIds.length === 0
10455
+ ? h('div', { className: 'dsh-powerup-prompt-empty' }, t('progress.reqEmpty'))
10456
+ : h('div', { className: 'dsh-powerup-prompt-scopes' }, scopeIds.map((scopeId) => h('section', {
10457
+ key: 'scope:' + scopeId, className: 'dsh-powerup-prompt-scope',
10458
+ },
10459
+ h('div', { className: 'dsh-powerup-prompt-scope-head' },
10460
+ h('span', { className: 'dsh-powerup-prompt-scope-title' }, titleOf(scopeId)),
10461
+ ),
10462
+ h('div', { className: 'dsh-powerup-req-list' }, reqs.filter((r) => r.workspaceId === scopeId).map((r) => h('div', {
10463
+ key: r.id, className: 'dsh-powerup-req-item' + (r.enabled === false ? ' off' : ''),
10464
+ },
10465
+ h('button', {
10466
+ type: 'button', role: 'switch', 'aria-checked': r.enabled !== false ? 'true' : 'false',
10467
+ className: 'dsh-powerup-switch', title: t('page.enabled'),
10468
+ onClick: () => toggleEnabled(r),
10469
+ }, r.enabled !== false ? t('page.enabled') : t('page.disabled')),
10470
+ h('div', { className: 'dsh-powerup-req-copy' },
10471
+ h('span', { className: 'dsh-powerup-req-title' }, r.title || (r.text.slice(0, 40) + (r.text.length > 40 ? '…' : ''))),
10472
+ h('span', { className: 'dsh-powerup-req-text' }, r.text),
10473
+ ),
10474
+ h('button', {
10475
+ type: 'button', className: 'dsh-powerup-linkbtn',
10476
+ onClick: () => setDraft({ ...r }),
10477
+ }, t('prompts.edit')),
10478
+ h('button', {
10479
+ type: 'button', className: 'dsh-powerup-linkbtn danger',
10480
+ onClick: () => remove(r),
10481
+ }, t('prompts.delete')),
10482
+ ))),
10483
+ ))),
10129
10484
  );
10130
10485
  }
10131
10486
 
10132
- /** Workspace/session-scoped requirements, shown in the conversation settings tab. */
10133
- function ProgressScopeRequirements({ t, workspaceId, sessionId }) {
10134
- const reqs = useRequirements();
10135
- const ws = typeof workspaceId === 'string' ? workspaceId : '';
10136
- const sid = typeof sessionId === 'string' ? sessionId : '';
10137
- const setWorkspace = (value) => {
10138
- const workspaces = { ...(requirementsCache.workspaces ?? {}) };
10139
- workspaces[ws] = value;
10140
- saveRequirements({ ...requirementsCache, workspaces });
10487
+ /**
10488
+ * Create-requirement modal for the session progress panel, mirroring
10489
+ * PromptCreateModal: pinned to the session's workspace, choose keep or
10490
+ * "all workspaces", with an in-memory draft that survives reopening.
10491
+ */
10492
+ function RequirementCreateModal({ workspaceId, workspaceTitle, onClose, onCreated }) {
10493
+ const t = (key, params) => translateCurrent(key, params);
10494
+ const fixedScope = typeof workspaceId !== 'string' || workspaceId === '';
10495
+ const key = fixedScope ? '' : workspaceId;
10496
+ if (requirementCreateDraft.workspaceId !== key) {
10497
+ requirementCreateDraft.workspaceId = key;
10498
+ requirementCreateDraft.title = '';
10499
+ requirementCreateDraft.text = '';
10500
+ requirementCreateDraft.scope = fixedScope ? 'all' : 'current';
10501
+ }
10502
+ const [title, setTitle] = useState(requirementCreateDraft.title);
10503
+ const [text, setText] = useState(requirementCreateDraft.text);
10504
+ const [scope, setScope] = useState(requirementCreateDraft.scope);
10505
+ const [closing, setClosing] = useState(false);
10506
+ const closingRef = useRef(false);
10507
+ const requestClose = () => {
10508
+ if (closingRef.current) return;
10509
+ closingRef.current = true;
10510
+ setClosing(true);
10511
+ setTimeout(() => { try { onClose(); } catch { /* parent owns unmount */ } }, 140);
10141
10512
  };
10142
- const setSession = (value) => {
10143
- const sessions = { ...(requirementsCache.sessions ?? {}) };
10144
- sessions[sid] = value;
10145
- saveRequirements({ ...requirementsCache, sessions });
10513
+ useEffect(() => {
10514
+ requirementCreateDraft.title = title;
10515
+ requirementCreateDraft.text = text;
10516
+ requirementCreateDraft.scope = scope;
10517
+ }, [title, text, scope]);
10518
+ useEffect(() => {
10519
+ const onKey = (event) => { if (event.key === 'Escape') { event.preventDefault(); requestClose(); } };
10520
+ document.addEventListener('keydown', onKey, true);
10521
+ return () => document.removeEventListener('keydown', onKey, true);
10522
+ }, []);
10523
+ const save = () => {
10524
+ const body = typeof text === 'string' ? text.trim() : '';
10525
+ if (body === '') return;
10526
+ const record = {
10527
+ id: newId(),
10528
+ title: typeof title === 'string' ? title.trim() : '',
10529
+ text: body,
10530
+ workspaceId: scope === 'current' && typeof workspaceId === 'string' ? workspaceId : '',
10531
+ enabled: true,
10532
+ };
10533
+ saveRequirements([...requirementsCache, record]);
10534
+ requirementCreateDraft.title = '';
10535
+ requirementCreateDraft.text = '';
10536
+ requirementCreateDraft.scope = fixedScope ? 'all' : 'current';
10537
+ if (!closingRef.current) { closingRef.current = true; setClosing(true); }
10538
+ setTimeout(() => { try { onCreated(record); } catch { /* ignore */ } }, 140);
10146
10539
  };
10147
- return h('div', { className: 'dsh-powerup-progress-req-editor' },
10148
- h('h3', { className: 'dsh-powerup-section-title' }, t('progress.requirements')),
10149
- h('p', { className: 'dsh-powerup-card-desc' }, t('progress.reqHint')),
10150
- h(RequirementField, {
10151
- label: t('progress.reqWorkspace'),
10152
- value: reqs.workspaces?.[ws] ?? '',
10153
- placeholder: t('progress.reqPlaceholder'),
10154
- onChange: setWorkspace,
10540
+ return renderInBody(h('div', {
10541
+ className: 'dsh-powerup-prompt-modal-mask' + (closing ? ' is-closing' : ''),
10542
+ onPointerDown: (event) => { if (event.target === event.currentTarget) requestClose(); },
10543
+ },
10544
+ h('div', { className: 'dsh-powerup-prompt-modal' + (closing ? ' is-closing' : ''), role: 'dialog', 'aria-modal': 'true' },
10545
+ h('div', { className: 'dsh-powerup-prompt-modal-head' },
10546
+ h('div', null,
10547
+ h('div', { className: 'dsh-powerup-prompt-modal-heading' }, t('progress.reqNew')),
10548
+ h('p', { className: 'dsh-powerup-prompt-modal-sub' }, t('prompts.createScopeHint')),
10549
+ ),
10550
+ h('button', { type: 'button', className: 'dsh-powerup-prompt-modal-close', 'aria-label': t('prompts.cancel'), onClick: requestClose }, '×'),
10551
+ ),
10552
+ h('div', { className: 'dsh-powerup-prompt-modal-body' },
10553
+ h('label', { className: 'dsh-powerup-prompt-field' },
10554
+ h('span', { className: 'dsh-powerup-prompt-field-label' }, t('prompts.titleLabel')),
10555
+ h('input', { className: 'dsh-powerup-prompt-input', type: 'text', value: title, placeholder: t('prompts.titlePlaceholder'), onChange: (e) => setTitle(e.target.value) }),
10556
+ ),
10557
+ h('label', { className: 'dsh-powerup-prompt-field' },
10558
+ h('span', { className: 'dsh-powerup-prompt-field-label' }, t('prompts.workspaceLabel')),
10559
+ h('div', { className: 'dsh-powerup-prompt-scope-options' },
10560
+ h('button', {
10561
+ type: 'button', role: 'switch', 'aria-checked': scope === 'all' ? 'true' : 'false',
10562
+ className: 'dsh-powerup-switch', onClick: () => setScope('all'),
10563
+ }, t('prompts.anyWorkspace')),
10564
+ fixedScope ? null : h('button', {
10565
+ type: 'button', role: 'switch', 'aria-checked': scope === 'current' ? 'true' : 'false',
10566
+ className: 'dsh-powerup-switch', onClick: () => setScope('current'),
10567
+ }, workspaceTitle || t('prompts.workspaceCurrent')),
10568
+ ),
10569
+ ),
10570
+ h('label', { className: 'dsh-powerup-prompt-field' },
10571
+ h('span', { className: 'dsh-powerup-prompt-field-label' }, t('progress.reqTextLabel')),
10572
+ h('textarea', { className: 'dsh-powerup-prompt-input dsh-powerup-prompt-textarea', value: text, placeholder: t('progress.reqPlaceholder'), onChange: (e) => setText(e.target.value) }),
10573
+ ),
10574
+ ),
10575
+ h('div', { className: 'dsh-powerup-prompt-modal-foot' },
10576
+ h('button', { type: 'button', className: 'dsh-powerup-update-ghost', onClick: requestClose }, t('prompts.cancel')),
10577
+ h('button', { type: 'button', className: 'dsh-powerup-update-primary', disabled: text.trim() === '', onClick: save }, t('prompts.create')),
10578
+ ),
10579
+ ),
10580
+ ));
10581
+ }
10582
+
10583
+ /**
10584
+ * Panel editor: check requirements to fill the text box, then freely edit
10585
+ * the combined text. On generate/refresh the full text is sent verbatim.
10586
+ */
10587
+ function RequirementPicker({ reqs, selectedIds, text, onToggle, onTextChange, t }) {
10588
+ return h('div', { className: 'dsh-powerup-req-picker' },
10589
+ reqs.length === 0
10590
+ ? h('p', { className: 'dsh-powerup-progress-empty' }, t('progress.reqEmpty'))
10591
+ : reqs.map((r) => h('label', { key: r.id, className: 'dsh-powerup-req-option' },
10592
+ h('input', { type: 'checkbox', checked: selectedIds.includes(r.id), onChange: () => onToggle(r.id) }),
10593
+ h('span', null, r.title || (r.text.slice(0, 50) + (r.text.length > 50 ? '…' : ''))),
10594
+ )),
10595
+ h('textarea', {
10596
+ className: 'dsh-powerup-prompt-input dsh-powerup-prompt-textarea dsh-powerup-req-textarea',
10597
+ value: text ?? '', placeholder: t('progress.reqEditPlaceholder'),
10598
+ onChange: (event) => onTextChange(event.target.value),
10155
10599
  }),
10156
- sid !== '' ? h(RequirementField, {
10157
- label: t('progress.reqSession'),
10158
- value: reqs.sessions?.[sid] ?? '',
10159
- placeholder: t('progress.reqPlaceholder'),
10160
- onChange: setSession,
10161
- }) : null,
10162
10600
  );
10163
10601
  }
10164
10602
 
@@ -10317,7 +10755,41 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10317
10755
  const [historyIndex, setHistoryIndex] = useState(0);
10318
10756
  const [showRaw, setShowRaw] = useState(false);
10319
10757
  const [showReq, setShowReq] = useState(false);
10320
- const [tempReq, setTempReq] = useState('');
10758
+ // Selected requirement ids + the free-editable combined text.
10759
+ const [selectedReqIds, setSelectedReqIds] = useState([]);
10760
+ const [reqText, setReqText] = useState('');
10761
+ const [creatingReq, setCreatingReq] = useState(false);
10762
+ const reqs = useRequirements();
10763
+ // Resolve the owning workspace for requirement filtering + create modal.
10764
+ const workspaceId = useMemo(() => {
10765
+ try {
10766
+ const snapshot = ctxRef.current?.get?.('workspaces')?.list?.getSnapshot?.();
10767
+ return resolveWorkspaceIdFromSnapshot(snapshot, sessionRef.current) ?? '';
10768
+ } catch { return ''; }
10769
+ }, [sessionId, open]);
10770
+ const workspaceTitle = useMemo(() => {
10771
+ try {
10772
+ const items = ctxRef.current?.get?.('workspaces')?.list?.getSnapshot?.()?.items ?? [];
10773
+ const found = items.find((ws) => ws?.workspaceId === workspaceId);
10774
+ return found?.title ?? '';
10775
+ } catch { return ''; }
10776
+ }, [workspaceId, open]);
10777
+ const visibleReqs = requirementsForWorkspace(reqs, workspaceId);
10778
+ /** Concatenate the enabled+selected requirements into editable text. */
10779
+ const composeReqText = useCallback((ids) => {
10780
+ return visibleReqs
10781
+ .filter((r) => ids.includes(r.id) && r.enabled !== false && typeof r.text === 'string' && r.text.trim() !== '')
10782
+ .map((r) => r.text.trim())
10783
+ .join('\n\n');
10784
+ }, [visibleReqs]);
10785
+ /** Toggle one requirement: rebuild the box from the current selection. */
10786
+ const toggleReq = useCallback((id) => {
10787
+ setSelectedReqIds((cur) => {
10788
+ const next = cur.includes(id) ? cur.filter((x) => x !== id) : [...cur, id];
10789
+ setReqText(composeReqText(next));
10790
+ return next;
10791
+ });
10792
+ }, [composeReqText]);
10321
10793
  const [size, setSize] = useState(() => {
10322
10794
  try {
10323
10795
  const saved = JSON.parse(localStorage.getItem('dsh-powerup:progress:size:v1') || 'null');
@@ -10373,7 +10845,8 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10373
10845
  if (typeof id !== 'string' || id === '') return;
10374
10846
  setBusy(true);
10375
10847
  try {
10376
- const body = await progressRequest(id, 'start', { requirements: tempReq });
10848
+ // Send the full, possibly user-edited text verbatim.
10849
+ const body = await progressRequest(id, 'start', { requirements: reqText });
10377
10850
  setView(body);
10378
10851
  setHistoryIndex(0);
10379
10852
  } catch (error) {
@@ -10382,7 +10855,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10382
10855
  setBusy(false);
10383
10856
  if (!open) setOpen(true);
10384
10857
  }
10385
- }, [open, tempReq]);
10858
+ }, [open, reqText]);
10386
10859
 
10387
10860
  const clearHistory = useCallback(async () => {
10388
10861
  const id = sessionRef.current;
@@ -10425,7 +10898,7 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10425
10898
  const drag = dragRef.current;
10426
10899
  if (drag === null) return;
10427
10900
  const w = Math.max(320, Math.min(900, drag.w + drag.x - event.clientX));
10428
- const h = Math.max(240, Math.min(900, drag.h + drag.y - event.clientY));
10901
+ const h = Math.max(240, Math.min(900, drag.h + event.clientY - drag.y));
10429
10902
  setSize({ w, h });
10430
10903
  };
10431
10904
  const onUp = () => {
@@ -10547,13 +11020,20 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10547
11020
  })();
10548
11021
 
10549
11022
  const requirementsEditor = showReq ? h('div', { className: 'dsh-powerup-progress-req-pop' },
10550
- h(RequirementField, {
10551
- label: t('progress.reqTemporary'),
10552
- hint: t('progress.reqTemporaryHint'),
10553
- value: tempReq,
10554
- placeholder: t('progress.reqPlaceholder'),
10555
- onChange: setTempReq,
11023
+ h('span', { className: 'dsh-powerup-prompt-field-label' }, t('progress.reqSelect')),
11024
+ h('p', { className: 'dsh-powerup-setting-hint' }, t('progress.reqSelectHint')),
11025
+ h(RequirementPicker, {
11026
+ reqs: visibleReqs,
11027
+ selectedIds: selectedReqIds,
11028
+ text: reqText,
11029
+ t,
11030
+ onToggle: toggleReq,
11031
+ onTextChange: setReqText,
10556
11032
  }),
11033
+ h('button', {
11034
+ type: 'button', className: 'dsh-powerup-prompt-new dsh-powerup-req-create',
11035
+ onClick: () => setCreatingReq(true),
11036
+ }, t('progress.reqNew')),
10557
11037
  ) : null;
10558
11038
 
10559
11039
  const panel = !open ? null : h('div', {
@@ -10621,6 +11101,18 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10621
11101
  return h('span', { style: { display: 'inline-flex', alignItems: 'center' } },
10622
11102
  button,
10623
11103
  renderInBody(panel),
11104
+ creatingReq ? h(RequirementCreateModal, {
11105
+ workspaceId,
11106
+ workspaceTitle,
11107
+ onClose: () => setCreatingReq(false),
11108
+ onCreated: (record) => {
11109
+ setCreatingReq(false);
11110
+ // Auto-select the freshly created requirement and append its text
11111
+ // to the editable box (the cache may not have re-rendered yet).
11112
+ setSelectedReqIds((cur) => cur.includes(record.id) ? cur : [...cur, record.id]);
11113
+ setReqText((cur) => record.text ? (cur ? `${cur}\n\n${record.text.trim()}` : record.text.trim()) : cur);
11114
+ },
11115
+ }) : null,
10624
11116
  );
10625
11117
  }
10626
11118
 
@@ -10784,8 +11276,11 @@ html[data-platform="darwin"] .dsh-powerup-scrolltop:hover{background:var(--dsw-s
10784
11276
  PROMPTS_CSS,
10785
11277
  PROGRESS_CSS,
10786
11278
  ProgressControl,
10787
- ProgressRequirementsEditor,
10788
- ProgressScopeRequirements,
11279
+ RequirementManager,
11280
+ RequirementCreateModal,
11281
+ RequirementForm,
11282
+ RequirementPicker,
11283
+ requirementForWorkspace: requirementsForWorkspace,
10789
11284
  DirectAskButton,
10790
11285
  ProgressStructure,
10791
11286
  ProgressDisplay,