dsh-prompt-pool 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +2 -0
  2. package/client.js +167 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -3,6 +3,8 @@
3
3
  A staging pool for prompts inside DeepSeek Harness: park a draft without sending it, arrange a playlist
4
4
  of prompt items, and release the batch into the composer's send queue in order.
5
5
 
6
+ ![The prompt pool panel open above the composer](https://raw.githubusercontent.com/Ganttfly/dsh-prompt-pool/main/docs/images/panel.png)
7
+
6
8
  - Composer trigger beside the send controls (accent + count while something is queued)
7
9
  - Composer panel with search, group tabs, row actions and a send-queue card
8
10
  - Full-height page in the right sidebar (native tab on DSH 0.2+, `dsh-better-sidebar` fallback)
package/client.js CHANGED
@@ -24,7 +24,7 @@ window.__ModuleLoader__.load({
24
24
  const NATIVE_TAB_ID = 'dsh-prompt-pool';
25
25
  const NATIVE_TAB_KIND = 'prompt-pool';
26
26
  /** Shown in the settings about card; keep in step with plugin/package.json. */
27
- const PLUGIN_VERSION = '1.0.0';
27
+ const PLUGIN_VERSION = '1.0.2';
28
28
  const PLUGIN_AUTHOR = 'GanttShen';
29
29
  /** Replace once the public repository exists; the row hides while it is empty. */
30
30
  const PLUGIN_REPO = 'https://github.com/Ganttfly/dsh-prompt-pool';
@@ -36,6 +36,30 @@ window.__ModuleLoader__.load({
36
36
  const MAX_IMAGE_BYTES = 12 * 1024 * 1024;
37
37
  const IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/webp', 'image/gif'];
38
38
  const EMPTY_PENDING = [];
39
+ /**
40
+ * Space kept between the panel's top edge and the pane that clips it: the
41
+ * panel is anchored to the composer, which in a new session sits well above
42
+ * the window bottom, so its height has to stop at the pane instead of
43
+ * running past it.
44
+ */
45
+ const PANEL_TOP_GAP = 10;
46
+
47
+ /**
48
+ * Top of the nearest ancestor that clips its overflow — the pane the panel
49
+ * is drawn in. The window top is not enough: the app's own top bar sits
50
+ * above that pane, and a panel sized to the window hides its header under
51
+ * the clip. 0 when nothing clips.
52
+ */
53
+ function clipTopOf(node) {
54
+ let top = 0;
55
+ for (let current = node.parentElement; current; current = current.parentElement) {
56
+ const style = getComputedStyle(current);
57
+ if (style.overflowX === 'visible' && style.overflowY === 'visible') continue;
58
+ const rect = current.getBoundingClientRect();
59
+ if (rect.top > top) top = rect.top;
60
+ }
61
+ return Math.max(0, Math.round(top));
62
+ }
39
63
 
40
64
  // ---------------------------------------------------------------- locale
41
65
  const ZH = {
@@ -177,7 +201,7 @@ window.__ModuleLoader__.load({
177
201
  'tray.release': '发送',
178
202
  'tray.clear': '清空',
179
203
  'tray.clearTitle': '清空待发送队列',
180
- 'tray.clearConfirm': '队列里的 {n} 条会被一起移出,这个操作不能撤销。',
204
+ 'tray.clearConfirm': '队列里的 {n} 条会被一起移出。',
181
205
  'tray.clearAction': '清空',
182
206
  'tray.empty': '还没选中任何条目,点左侧「+」加入',
183
207
  'tray.remove': '移出',
@@ -204,6 +228,7 @@ window.__ModuleLoader__.load({
204
228
  'status.releaseStopped': '已释放 {n} 条,其余 {rest} 条没发出去:输入框繁忙或内容被改动',
205
229
  'status.draftBusy': '输入框里还有内容,先清空或存进池子再释放',
206
230
  'status.deleted': '已删除「{title}」',
231
+ 'status.cleared': '已清空 {n} 条待发送',
207
232
  'status.undo': '撤销',
208
233
  'status.releasing': '正在释放 {n} 条…',
209
234
  };
@@ -347,7 +372,7 @@ window.__ModuleLoader__.load({
347
372
  'tray.release': 'Send',
348
373
  'tray.clear': 'Clear',
349
374
  'tray.clearTitle': 'Clear the send queue',
350
- 'tray.clearConfirm': 'All {n} queued items are removed at once. This cannot be undone.',
375
+ 'tray.clearConfirm': 'All {n} queued items are removed at once.',
351
376
  'tray.clearAction': 'Clear',
352
377
  'tray.empty': 'Nothing selected yet — use the + control on a row',
353
378
  'tray.remove': 'Remove',
@@ -374,6 +399,7 @@ window.__ModuleLoader__.load({
374
399
  'status.releaseStopped': 'Released {n}; {rest} left because the composer was busy or edited',
375
400
  'status.draftBusy': 'The composer still has text. Clear it or save it to the pool first.',
376
401
  'status.deleted': 'Deleted this item',
402
+ 'status.cleared': 'Cleared {n} queued items',
377
403
  'status.undo': 'Undo',
378
404
  'status.releasing': 'Releasing {n}…',
379
405
  };
@@ -807,9 +833,9 @@ window.__ModuleLoader__.load({
807
833
  onAdd: (name) => {
808
834
  const created = poolActions.addCategory(name);
809
835
  if (!created) return;
810
- // Folded custom groups share one tab, so aim at that tab instead.
811
- const folded = normalizeSettings(pool.get().settings).customNested;
812
- setTab(folded ? 'nested:custom' : 'custom:' + created.id);
836
+ // Folded groups share one tab; a hidden family has no tab to aim at.
837
+ const mode = normalizeSettings(pool.get().settings).display.custom;
838
+ setTab(mode === 'nested' ? 'nested:custom' : mode === 'hidden' ? 'all' : 'custom:' + created.id);
813
839
  },
814
840
  onRename: (id, name) => {
815
841
  if (id.indexOf('custom:') === 0) poolActions.renameCategory(id.slice(7), name);
@@ -1467,8 +1493,25 @@ window.__ModuleLoader__.load({
1467
1493
  return { ...state, tray };
1468
1494
  });
1469
1495
  },
1470
- setTray(entries) {
1471
- mutate((state) => ({ ...state, tray: entries.slice() }));
1496
+ /** Drop exactly these entries, so a release cannot overwrite concurrent edits. */
1497
+ removeTrayKeys(keys) {
1498
+ const drop = new Set(keys);
1499
+ mutate((state) => {
1500
+ const next = state.tray.filter((entry) => !drop.has(entry.key));
1501
+ if (next.length === state.tray.length) return null;
1502
+ return { ...state, tray: next };
1503
+ });
1504
+ },
1505
+ /** Put cleared entries back in front; anything queued since stays behind them. */
1506
+ restoreTray(entries) {
1507
+ const restore = Array.isArray(entries) ? entries : [];
1508
+ if (restore.length === 0) return;
1509
+ mutate((state) => {
1510
+ const present = new Set(state.tray.map((entry) => entry.key));
1511
+ const missing = restore.filter((entry) => !present.has(entry.key));
1512
+ if (missing.length === 0) return null;
1513
+ return { ...state, tray: [...missing, ...state.tray] };
1514
+ });
1472
1515
  },
1473
1516
  clearTray() {
1474
1517
  mutate((state) => (state.tray.length === 0 ? null : { ...state, tray: [] }));
@@ -2262,6 +2305,18 @@ window.__ModuleLoader__.load({
2262
2305
  setEditing({ id: item.id, group, title: '', body: '', images: [] });
2263
2306
  };
2264
2307
 
2308
+ /**
2309
+ * Cancel drops an item the editor created and never saved, so no empty
2310
+ * row is left behind; an existing item keeps its stored content.
2311
+ */
2312
+ const cancelEdit = () => {
2313
+ const current = editing;
2314
+ setEditing(null);
2315
+ if (!current) return;
2316
+ const stored = pool.get().items.find((item) => item.id === current.id);
2317
+ if (stored && !stored.body.trim() && !(stored.images && stored.images.length > 0)) poolActions.remove(stored.id);
2318
+ };
2319
+
2265
2320
  const rowOf = (item, index) => {
2266
2321
  if (editing && editing.id === item.id) {
2267
2322
  return h(
@@ -2329,7 +2384,7 @@ window.__ModuleLoader__.load({
2329
2384
  : null,
2330
2385
  ),
2331
2386
  h('span', { className: 'pp-grow' }),
2332
- h('button', { type: 'button', className: 'pp-mini', onClick: () => setEditing(null) }, translate('row.cancel')),
2387
+ h('button', { type: 'button', className: 'pp-mini', onClick: cancelEdit }, translate('row.cancel')),
2333
2388
  h('button', { type: 'button', className: 'pp-primary', onClick: save }, translate('row.save')),
2334
2389
  ),
2335
2390
  );
@@ -2460,8 +2515,18 @@ window.__ModuleLoader__.load({
2460
2515
  ? h(TrayClearConfirm, {
2461
2516
  count: state.tray.length,
2462
2517
  onConfirm: () => {
2518
+ const entries = pool.get().tray.slice();
2463
2519
  poolActions.clearTray();
2464
2520
  setConfirmClear(false);
2521
+ if (entries.length === 0) return;
2522
+ flash({
2523
+ kind: 'info',
2524
+ text: translate('status.cleared', { n: entries.length }),
2525
+ undo: () => {
2526
+ poolActions.restoreTray(entries);
2527
+ setStatus(null);
2528
+ },
2529
+ });
2465
2530
  },
2466
2531
  onCancel: () => setConfirmClear(false),
2467
2532
  })
@@ -3301,13 +3366,51 @@ window.__ModuleLoader__.load({
3301
3366
  const panelHeight = dragHeight || normalizeSettings(state.settings).panelHeight;
3302
3367
  const panelHeightRef = useRef(panelHeight);
3303
3368
  panelHeightRef.current = panelHeight;
3369
+
3370
+ // Room from the top of the pane that clips the panel down to the panel's
3371
+ // own bottom edge. The overlay anchors that bottom edge to the composer,
3372
+ // and a new session puts the composer mid-page, so the panel is capped by
3373
+ // that pane rather than by 70vh of a viewport it does not reach. This runs
3374
+ // after every render because a layout shift can move the composer without
3375
+ // a resize; the equality check ends the extra render.
3376
+ const [room, setRoom] = useState(0);
3377
+ const roomRef = useRef(0);
3378
+ roomRef.current = room;
3379
+ const layoutEffect = React.useLayoutEffect || useEffect;
3380
+ layoutEffect(() => {
3381
+ if (!view.open) return undefined;
3382
+ const node = panelRef.current;
3383
+ if (!node) return undefined;
3384
+ const measure = () => {
3385
+ // Only the list and the queue tray scroll. If something inside the
3386
+ // panel takes focus, the browser can scroll this box instead, which
3387
+ // parks the header above its own viewport; pin it back.
3388
+ if (node.scrollTop !== 0) node.scrollTop = 0;
3389
+ const ceiling = node.getBoundingClientRect().bottom - clipTopOf(node) - PANEL_TOP_GAP;
3390
+ const next = Math.max(160, Math.round(ceiling));
3391
+ setRoom((previous) => (previous === next ? previous : next));
3392
+ };
3393
+ measure();
3394
+ // The composer can settle a frame or two after the panel opens (fonts,
3395
+ // entry animation, a restored draft), so follow the first measurement.
3396
+ const timers = [120, 400].map((delay) => window.setTimeout(measure, delay));
3397
+ node.addEventListener('scroll', measure);
3398
+ window.addEventListener('resize', measure);
3399
+ return () => {
3400
+ timers.forEach((timer) => window.clearTimeout(timer));
3401
+ node.removeEventListener('scroll', measure);
3402
+ window.removeEventListener('resize', measure);
3403
+ };
3404
+ });
3405
+
3304
3406
  const startResize = (event) => {
3305
3407
  if (event.button !== undefined && event.button !== 0) return;
3306
3408
  event.preventDefault();
3307
3409
  const startY = event.clientY;
3308
3410
  const startHeight = panelRef.current ? panelRef.current.getBoundingClientRect().height : panelHeightRef.current;
3309
3411
  const apply = (clientY) => {
3310
- const limit = Math.max(360, window.innerHeight - 96);
3412
+ const ceiling = roomRef.current > 0 ? roomRef.current : window.innerHeight - 96;
3413
+ const limit = Math.max(320, Math.min(ceiling, window.innerHeight - 96));
3311
3414
  setDragHeight(Math.round(Math.min(limit, Math.max(320, startHeight + (startY - clientY)))));
3312
3415
  };
3313
3416
  const onMove = (moveEvent) => {
@@ -3514,6 +3617,8 @@ window.__ModuleLoader__.load({
3514
3617
  const group = groupForTab(tab, inWorkspace && wsActive ? 'workspace:' + wsActive.slice(3) : '');
3515
3618
  // The new row must land on a visible list, so plain tabs switch to the kind tab.
3516
3619
  if (!inWorkspace && !familyOf(tab)) setTab(group);
3620
+ // A search would filter the brand-new empty row out of the list.
3621
+ setQuery('');
3517
3622
  const item = poolActions.add({
3518
3623
  id: uid(),
3519
3624
  group,
@@ -3526,6 +3631,18 @@ window.__ModuleLoader__.load({
3526
3631
  setEditing({ id: item.id, group, title: '', body: '', images: [] });
3527
3632
  };
3528
3633
 
3634
+ /**
3635
+ * Cancel drops an item the editor created and never saved, so no empty
3636
+ * row is left behind; an existing item keeps its stored content.
3637
+ */
3638
+ const cancelEdit = () => {
3639
+ const current = editing;
3640
+ setEditing(null);
3641
+ if (!current) return;
3642
+ const stored = pool.get().items.find((item) => item.id === current.id);
3643
+ if (stored && !stored.body.trim() && !(stored.images && stored.images.length > 0)) poolActions.remove(stored.id);
3644
+ };
3645
+
3529
3646
  const startEdit = (item) => setEditing({ id: item.id, group: groupOf(item), title: item.title, body: item.body, images: normalizeImages(item.images) });
3530
3647
 
3531
3648
  const saveEdit = () => {
@@ -3583,11 +3700,17 @@ window.__ModuleLoader__.load({
3583
3700
  setBusy(true);
3584
3701
  setStatus({ kind: 'info', text: translate('status.releasing', { n: entries.length }) });
3585
3702
  let sent = 0;
3703
+ // Keys finished by this run; the queue is filtered by key afterwards so
3704
+ // rows queued (or removed) meanwhile are not overwritten.
3705
+ const done = [];
3586
3706
  try {
3587
3707
  for (const entry of entries) {
3588
3708
  const body = typeof entry.body === 'string' ? entry.body : '';
3589
3709
  const images = normalizeImages(entry.images);
3590
- if (!body.trim() && images.length === 0) continue;
3710
+ if (!body.trim() && images.length === 0) {
3711
+ done.push(entry.key);
3712
+ continue;
3713
+ }
3591
3714
  const clear = await waitFor(() => draftRef.current.trim() === '' && phaseRef.current === 'plain', 2500);
3592
3715
  if (!clear) break;
3593
3716
  try {
@@ -3626,6 +3749,7 @@ window.__ModuleLoader__.load({
3626
3749
  }
3627
3750
  await waitFor(() => phaseRef.current === 'plain', 1500);
3628
3751
  sent += 1;
3752
+ done.push(entry.key);
3629
3753
  }
3630
3754
  } catch (error) {
3631
3755
  flash({ kind: 'error', text: String((error && error.message) || error) });
@@ -3633,7 +3757,7 @@ window.__ModuleLoader__.load({
3633
3757
  busyRef.current = false;
3634
3758
  setBusy(false);
3635
3759
  }
3636
- poolActions.setTray(entries.slice(sent));
3760
+ poolActions.removeTrayKeys(done);
3637
3761
  flash(
3638
3762
  sent === entries.length
3639
3763
  ? { kind: 'ok', text: translate('status.released', { n: sent }) }
@@ -3708,7 +3832,7 @@ window.__ModuleLoader__.load({
3708
3832
  : null,
3709
3833
  ),
3710
3834
  h('span', { className: 'pp-grow' }),
3711
- h('button', { type: 'button', className: 'pp-mini', onClick: () => setEditing(null) }, translate('row.cancel')),
3835
+ h('button', { type: 'button', className: 'pp-mini', onClick: cancelEdit }, translate('row.cancel')),
3712
3836
  h('button', { type: 'button', className: 'pp-primary', onClick: saveEdit }, translate('row.save')),
3713
3837
  ),
3714
3838
  );
@@ -3739,6 +3863,7 @@ window.__ModuleLoader__.load({
3739
3863
  onClick: () => poolActions.move(item.id, 1),
3740
3864
  }),
3741
3865
  h(IconButton, { name: 'edit', label: translate('row.edit'), onClick: () => startEdit(item) }),
3866
+ h(IconButton, { name: 'copy', label: translate('row.duplicate'), onClick: () => poolActions.duplicateItem(item.id) }),
3742
3867
  h(IconButton, { name: 'trash', label: translate('row.delete'), danger: true, onClick: () => setPendingDelete(item) }),
3743
3868
  ),
3744
3869
  );
@@ -3844,6 +3969,19 @@ window.__ModuleLoader__.load({
3844
3969
  }
3845
3970
  : null;
3846
3971
 
3972
+ // --pp-room carries the measured cap into the stylesheet; a dragged height
3973
+ // is capped by the same value, so no path can push the header above the
3974
+ // pane that clips the panel. --pp-h is the panel's own height, which the
3975
+ // queue card uses to keep itself to a share of the panel.
3976
+ const panelStyle = {};
3977
+ if (room > 0) panelStyle['--pp-room'] = room + 'px';
3978
+ if (panelHeight) {
3979
+ const size = 'min(' + panelHeight + 'px, var(--pp-room, 90vh))';
3980
+ panelStyle['--pp-h'] = size;
3981
+ panelStyle.height = size;
3982
+ panelStyle.maxHeight = 'none';
3983
+ }
3984
+
3847
3985
  return h(
3848
3986
  'div',
3849
3987
  {
@@ -3851,7 +3989,7 @@ window.__ModuleLoader__.load({
3851
3989
  role: 'dialog',
3852
3990
  'aria-label': translate('panel.title'),
3853
3991
  ref: panelRef,
3854
- style: panelHeight ? { height: 'min(' + panelHeight + 'px, 90vh)', maxHeight: 'none' } : undefined,
3992
+ style: Object.keys(panelStyle).length > 0 ? panelStyle : undefined,
3855
3993
  onMouseDown: (event) => event.stopPropagation(),
3856
3994
  },
3857
3995
  h('style', null, CSS),
@@ -3908,8 +4046,18 @@ window.__ModuleLoader__.load({
3908
4046
  ? h(TrayClearConfirm, {
3909
4047
  count: tray.length,
3910
4048
  onConfirm: () => {
4049
+ const entries = pool.get().tray.slice();
3911
4050
  poolActions.clearTray();
3912
4051
  setConfirmClear(false);
4052
+ if (entries.length === 0) return;
4053
+ flash({
4054
+ kind: 'info',
4055
+ text: translate('status.cleared', { n: entries.length }),
4056
+ undo: () => {
4057
+ poolActions.restoreTray(entries);
4058
+ setStatus(null);
4059
+ },
4060
+ });
3913
4061
  },
3914
4062
  onCancel: () => setConfirmClear(false),
3915
4063
  })
@@ -4144,7 +4292,7 @@ window.__ModuleLoader__.load({
4144
4292
  '.pp-trigger[data-queued="true"]{border-color:var(--pp-accent-line);background:var(--pp-accent-soft);color:var(--pp-accent);font-weight:600}' +
4145
4293
  '.pp-trigger[data-queued="true"]:hover{background:color-mix(in srgb,var(--pp-accent) 20%,transparent);color:var(--pp-accent)}' +
4146
4294
  '.pp-trigger[data-queued="true"] .pp-badge{border-color:var(--pp-accent);background:var(--pp-accent);color:var(--pp-on-accent);font-weight:600}' +
4147
- '.pp-panel{position:absolute;left:auto;right:0;bottom:0;margin:0;max-width:min(920px,100%);z-index:40;display:flex;flex-direction:column;height:min(70vh,720px);max-height:min(70vh,720px);border:1px solid var(--pp-line);border-radius:var(--dsw-radius-panel,12px);background:var(--dsw-alias-bg-base,var(--pp-surface-2));box-shadow:var(--dsw-elevation-soft,0 10px 30px rgba(0,0,0,.16));overflow:hidden;font-size:13px;line-height:1.5;color:var(--pp-ink);text-align:left}' +
4295
+ '.pp-panel{position:absolute;left:auto;right:0;bottom:0;margin:0;max-width:min(920px,100%);z-index:40;display:flex;flex-direction:column;--pp-h:min(70vh,720px,var(--pp-room,100vh));height:var(--pp-h);max-height:var(--pp-h);border:1px solid var(--pp-line);border-radius:var(--dsw-radius-panel,12px);background:var(--dsw-alias-bg-base,var(--pp-surface-2));box-shadow:var(--dsw-elevation-soft,0 10px 30px rgba(0,0,0,.16));overflow:hidden;overflow:clip;font-size:13px;line-height:1.5;color:var(--pp-ink);text-align:left}' +
4148
4296
  // The grip above the header resizes the panel; a long queue may keep half the list.
4149
4297
  '.pp-panel-grip{flex:none;display:flex;align-items:center;justify-content:center;height:11px;cursor:ns-resize;touch-action:none}' +
4150
4298
  '.pp-grip-bar{width:44px;height:4px;border-radius:2px;background:var(--pp-line-2);transition:background .12s ease}' +
@@ -4154,7 +4302,10 @@ window.__ModuleLoader__.load({
4154
4302
  // A short panel used to cap the card at 45% of itself, so even two chips
4155
4303
  // scrolled; a generous share of the panel keeps a few rows whole, and only a
4156
4304
  // genuinely long queue scrolls inside the card.
4157
- '.pp-panel .pp-page-foot{flex:none;max-height:min(70%,320px);min-height:0}' +
4305
+ // The card sizes to its rows and only then scrolls. A percentage cap here
4306
+ // resolves against an auto-height dock and collapses the card to one row,
4307
+ // so the cap is expressed against the panel's own measured cap instead.
4308
+ '.pp-panel .pp-page-foot{flex:none;max-height:min(calc(var(--pp-h, 100vh) * 0.7), 320px);min-height:0}' +
4158
4309
  // flex:1 would collapse an auto-height card to zero and clip the empty hint;
4159
4310
  // the tray sizes to its content and only shrinks (then scrolls) at the cap.
4160
4311
  '.pp-panel .pp-page-foot .pp-tray{max-height:none;min-height:0;flex:0 1 auto}' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-prompt-pool",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "private": false,
5
5
  "description": "A prompt staging pool beside the DSH composer: capture drafts, arrange a playlist, release it into the queue.",
6
6
  "license": "MIT",