@lyra_wang/dsh-pending-queue 0.1.0 → 0.2.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/README.md CHANGED
@@ -29,22 +29,25 @@ dsh plugin --profile desktop add ./lyra_wang-dsh-pending-queue-0.1.0.tgz
29
29
 
30
30
  1. 在右侧栏打开「待发送」。
31
31
  2. 在顶部输入框里记一条,`Cmd/Ctrl + Enter` 或点「存下」。
32
- 3. 每一条可以:
32
+ 3. 想带上引用:在聊天里选中一段文字,回到面板点「引用选中」,它会挂在这条下面;推送时还原成真正的引用块(和输入框的引用同源)。
33
+ 4. 每一条可以:
33
34
  - **发送**:内容进输入框并立刻提交(agent 正在跑时会排进队列,不会打断当前任务)
34
35
  - **填入**:只放进输入框,你自己改两笔再回车
35
36
  - **编辑 / 删除 / ↑ ↓**:改内容、删掉、调整顺序
36
- 4. 发过的行标「已发送」,可以「取回」重新排队,或一键「清空已发送」。
37
+ 5. 发过的行标「已发送」,可以「取回」重新排队,或一键「清空已发送」。
37
38
 
38
39
  ## 实现要点
39
40
 
40
41
  - **不写会话事件**。宿主半只有一份按会话拆开的 JSON,和两条同源路由(`GET /plugins/pending-queue/state`、`POST /plugins/pending-queue/action`),走 DSH 自己的连接鉴权。
41
- - **发送走输入框自己的动作**:`inputActions.setDraft(text)` + `inputActions.submit()`。所以推送出去的消息和你手打的一模一样——同样的排队语义、同样的回显、同样的失败处理,插件不另造一条发送通道。
42
+ - **一条记录 = 片段数组**(文字段 / 引用段),不是一段纯文本。推送时按片段重放:`setDraft()` 放开头的文字,`insertText()` 补后面的文字块,`insertQuote()` 还原引用块,最后 `submit()`。所以引用发出去就是真正的块引用,而不是字面的 `> ` 前缀。
43
+ - **发送走输入框自己的动作**,和你手打的一模一样——同样的排队语义、同样的回显、同样的失败处理,插件不另造一条发送通道。
42
44
  - **按会话存**:`<DSH_HOME>/storages/pending-queue/<sessionId>.json`。两个会话不会共用一条队列;删掉这个文件就是清空。
43
45
  - 面板每 10 秒静默同步一次,切回窗口也会同步;写入按读-改-写串行,两个窗口同时开着不会互相覆盖。
44
46
 
45
47
  ## 已知限制
46
48
 
47
49
  - 拿不到输入框动作(`inputActions`)的位置只提示「填入失败」,不会退化成剪贴板或 DOM 注入——那种兜底会绕开 DSH 自己的提交路径。
50
+ - **附件和 `@` 引用对不齐**:附件是浏览器内存里的 `File` 对象,DSH 自己也不跨会话保留;`@` 引用 chip 读得到(`InputState.occurrences`)但没有公开的插入接口,还原只能退化成文本。这两类不在这版范围内。
48
51
  - 队列只在当前机器上,不跨设备同步。
49
52
  - 「已发送」的行是留痕,不自动清理;不想看就点「清空已发送」。
50
53
 
@@ -58,4 +61,6 @@ node --test test/routes.test.mjs
58
61
 
59
62
  ## 版本
60
63
 
61
- 0.1.0 — 首个版本:新增、编辑、删除、排序、发送、填入、已发送留痕。
64
+ - 0.1.0 — 首个版本:新增、编辑、删除、排序、发送、填入、已发送留痕。
65
+ - 0.2.0 — 引用:一条记录改成分段结构(文字 / 引用),面板可「引用选中」聊天里的文字,推送时还原成真引用块。
66
+ - 0.1.1 — 补上 `icon.svg`。0.1.0 的 `package.json` 声明了 `icon` 与 `./icon` 导出,但文件没进包,插件管理器读元信息时 `lstat` 失败,列表里会显示「包元信息错误」。
package/client.js CHANGED
@@ -5,11 +5,12 @@
5
5
  * (/plugins/pending-queue/*), keyed by the session the tab belongs to, so two
6
6
  * conversations never share one queue.
7
7
  *
8
- * Pushing a row into the chat uses the composer's public input actions:
9
- * setDraft() puts the text in the input box exactly as if it had been typed,
10
- * and submit() sends it. While the agent is running, submit() queues the
11
- * message the same way a typed message is queued, so a push never interrupts
12
- * the current task.
8
+ * A row is a list of segments. Pushing it into the chat replays those segments
9
+ * through the composer's public input actions: setDraft() for the leading
10
+ * text, insertText() for later text blocks, insertQuote() for quotes. A quote
11
+ * stored here therefore comes back as the same atomic quote block the composer
12
+ * itself inserts, and submit() sends it exactly like typed text (queued while
13
+ * the agent is running).
13
14
  */
14
15
  window.__ModuleLoader__.load({
15
16
  id: '@lyra_wang/dsh-pending-queue',
@@ -28,6 +29,14 @@ window.__ModuleLoader__.load({
28
29
  const ACTION_URL = '/plugins/pending-queue/action'
29
30
  const ROOT = 'dsh-pending-queue'
30
31
 
32
+ /**
33
+ * The last non-empty chat selection, captured from the moment the plugin
34
+ * loads. A tab mounts later than the selection it wants to quote, and the
35
+ * click that opens the panel usually collapses the live selection, so the
36
+ * value has to live outside the component.
37
+ */
38
+ let lastChatSelection = ''
39
+
31
40
  /* --------------------------------- copy --------------------------------- */
32
41
 
33
42
  const ZH = {
@@ -52,11 +61,17 @@ window.__ModuleLoader__.load({
52
61
  'action.restore': '取回',
53
62
  'action.cancel': '取消',
54
63
  'action.saveEdit': '保存',
64
+ 'action.quote': '引用选中',
65
+ 'action.removeQuote': '移除引用',
66
+ 'quote.hint': '先在聊天里选中一段文字,再点「引用选中」;推送时它会还原成真正的引用块。',
67
+ 'quote.empty': '先在聊天里选中一段文字',
68
+ 'quote.badge': '引用',
55
69
  'status.sent': '已发送',
56
70
  'notice.filled': '已填入输入框',
57
71
  'notice.sent': '已推送',
58
72
  'error.network': '连不上插件接口',
59
73
  'error.noComposer': '这个位置还拿不到会话输入框,换到聊天页面再试',
74
+ 'error.push': '内容没能写进输入框(可能正在发送中)',
60
75
  'error.empty': '先写点什么',
61
76
  'time.justNow': '刚刚',
62
77
  }
@@ -83,11 +98,17 @@ window.__ModuleLoader__.load({
83
98
  'action.restore': 'Restore',
84
99
  'action.cancel': 'Cancel',
85
100
  'action.saveEdit': 'Save',
101
+ 'action.quote': 'Quote selection',
102
+ 'action.removeQuote': 'Remove quote',
103
+ 'quote.hint': 'Select text in the chat first, then press Quote selection; pushing rebuilds it as a real quote block.',
104
+ 'quote.empty': 'Select text in the chat first',
105
+ 'quote.badge': 'Quote',
86
106
  'status.sent': 'Sent',
87
107
  'notice.filled': 'Filled into the composer',
88
108
  'notice.sent': 'Pushed',
89
109
  'error.network': 'Cannot reach the plugin route',
90
110
  'error.noComposer': 'The composer is not reachable from here; open the chat view and retry',
111
+ 'error.push': 'The text could not enter the composer (it may be sending)',
91
112
  'error.empty': 'Write something first',
92
113
  'time.justNow': 'just now',
93
114
  }
@@ -127,7 +148,7 @@ window.__ModuleLoader__.load({
127
148
  try {
128
149
  return relativeFormatter.format(-value, pair[0])
129
150
  } catch {
130
- /* fall through to a plain label */
151
+ /* fall through */
131
152
  }
132
153
  }
133
154
  return String(value) + ' ' + pair[0]
@@ -172,9 +193,19 @@ window.__ModuleLoader__.load({
172
193
  return payload.queue || { items: [] }
173
194
  }
174
195
 
196
+ /** Rows written by 0.1.x carry a single 'text' field. */
197
+ function segmentsOfItem(item) {
198
+ if (item && Array.isArray(item.segments) && item.segments.length > 0) return item.segments
199
+ if (item && typeof item.text === 'string' && item.text.trim() !== '') return [{ type: 'text', text: item.text }]
200
+ return []
201
+ }
202
+
203
+ function hasContent(segments) {
204
+ return segments.some((segment) => typeof segment.text === 'string' && segment.text.trim() !== '')
205
+ }
206
+
175
207
  /* -------------------------------- artwork -------------------------------- */
176
208
 
177
- /** One glyph for the guide card and the tab chip. */
178
209
  function QueueGlyph(props) {
179
210
  const size = props && props.size ? props.size : 16
180
211
  return h('svg', {
@@ -216,6 +247,14 @@ window.__ModuleLoader__.load({
216
247
  '.dsh-pending-queue-primary{all:unset;cursor:pointer;flex:none;height:24px;padding:0 10px;border-radius:var(--dsw-radius-sm,8px);',
217
248
  ' font-size:12px;background:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4d8dff);color:#fff}',
218
249
  '.dsh-pending-queue-primary[disabled]{opacity:.45;cursor:default}',
250
+ '.dsh-pending-queue-quotes{display:flex;flex-direction:column;gap:4px;margin:6px 0 0}',
251
+ '.dsh-pending-queue-quoteChip{display:flex;align-items:flex-start;gap:6px;padding:4px 6px 4px 8px;border-radius:var(--dsw-radius-sm,8px);',
252
+ ' background:var(--dsw-alias-bg-layer-2,#26262a);border-left:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4d8dff);',
253
+ ' font-size:12px;line-height:1.45;color:var(--dsw-alias-label-secondary,#b9b9c0)}',
254
+ '.dsh-pending-queue-quoteChipText{flex:1;min-width:0;white-space:pre-wrap;word-break:break-word;',
255
+ ' display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}',
256
+ '.dsh-pending-queue-x{all:unset;cursor:pointer;flex:none;font-size:11px;color:var(--dsw-alias-label-tertiary,#9a9aa2)}',
257
+ '.dsh-pending-queue-x:hover{color:var(--dsw-alias-state-error-primary,#f56c6c)}',
219
258
  '.dsh-pending-queue-body{flex:1;min-height:0;overflow:auto;padding:0 10px 16px;overscroll-behavior:contain}',
220
259
  '.dsh-pending-queue-hintBlock{padding:28px 12px;text-align:center;color:var(--dsw-alias-label-tertiary,#9a9aa2);',
221
260
  ' font-size:12.5px;line-height:1.7}',
@@ -226,8 +265,9 @@ window.__ModuleLoader__.load({
226
265
  '.dsh-pending-queue-card{position:relative;margin:0 0 10px;padding:10px 12px 8px;border-radius:var(--dsw-radius-md,12px);',
227
266
  ' background:var(--dsw-alias-bg-layer-1,#1f1f22);border:0.5px solid var(--dsw-alias-border-l3,#ffffff1a)}',
228
267
  '.dsh-pending-queue-card[data-sent="true"]{opacity:.6}',
229
- '.dsh-pending-queue-text{white-space:pre-wrap;word-break:break-word;font-size:13px;line-height:1.55;',
230
- ' display:-webkit-box;-webkit-line-clamp:6;-webkit-box-orient:vertical;overflow:hidden}',
268
+ '.dsh-pending-queue-text{white-space:pre-wrap;word-break:break-word;font-size:13px;line-height:1.55}',
269
+ '.dsh-pending-queue-quote{margin:4px 0;padding:2px 0 2px 8px;border-left:2px solid var(--dsw-alias-border-l3,#ffffff2e);',
270
+ ' white-space:pre-wrap;word-break:break-word;color:var(--dsw-alias-label-secondary,#b9b9c0);font-size:12.5px}',
231
271
  '.dsh-pending-queue-meta{display:flex;align-items:center;gap:6px;margin-top:6px;font-size:11px;',
232
272
  ' color:var(--dsw-alias-label-tertiary,#9a9aa2)}',
233
273
  '.dsh-pending-queue-badge{flex:none;border:0.5px solid var(--dsw-alias-border-l3,#ffffff1f);border-radius:999px;',
@@ -238,8 +278,8 @@ window.__ModuleLoader__.load({
238
278
  '.dsh-pending-queue-act:hover{background:var(--dsw-alias-interactive-bg-hover,#ffffff14);color:var(--dsw-alias-label-primary,#e8e8ea)}',
239
279
  '.dsh-pending-queue-act[disabled]{opacity:.4;cursor:default}',
240
280
  '.dsh-pending-queue-act[data-tone="send"]{color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4d8dff)}',
241
- '.dsh-pending-queue-edit{box-sizing:border-box;width:100%;min-height:64px;resize:vertical;border-radius:var(--dsw-radius-sm,8px);',
242
- ' border:0.5px solid var(--dsw-alias-border-l3,#ffffff1a);background:transparent;color:inherit;font:inherit;padding:6px 8px}',
281
+ '.dsh-pending-queue-edit{box-sizing:border-box;width:100%;min-height:52px;resize:vertical;border-radius:var(--dsw-radius-sm,8px);',
282
+ ' border:0.5px solid var(--dsw-alias-border-l3,#ffffff1a);background:transparent;color:inherit;font:inherit;padding:6px 8px;margin:2px 0}',
243
283
  '.dsh-pending-queue-notice{flex:none;margin:0 12px 6px;font-size:11.5px;color:var(--dsw-alias-label-tertiary,#9a9aa2)}',
244
284
  ].join('\n')
245
285
 
@@ -254,6 +294,7 @@ window.__ModuleLoader__.load({
254
294
  const [loading, setLoading] = useState(true)
255
295
  const [error, setError] = useState('')
256
296
  const [draft, setDraft] = useState('')
297
+ const [quotes, setQuotes] = useState([])
257
298
  const [editing, setEditing] = useState(null)
258
299
  const [busy, setBusy] = useState('')
259
300
  const [notice, setNotice] = useState('')
@@ -322,34 +363,87 @@ window.__ModuleLoader__.load({
322
363
 
323
364
  const saveDraft = useCallback(async () => {
324
365
  const text = draft.trim()
325
- if (text === '') {
366
+ const segments = []
367
+ if (text !== '') segments.push({ type: 'text', text })
368
+ for (const quote of quotes) segments.push({ type: 'quote', text: quote })
369
+ if (segments.length === 0) {
326
370
  setError(t('error.empty'))
327
371
  return
328
372
  }
329
373
  setBusy('add')
330
- const next = await act({ action: 'add', text })
374
+ const next = await act({ action: 'add', segments })
331
375
  if (live.current) {
332
376
  setBusy('')
333
- if (next) setDraft('')
377
+ if (next) {
378
+ setDraft('')
379
+ setQuotes([])
380
+ }
334
381
  }
335
- }, [draft, act, t])
382
+ }, [draft, quotes, act, t])
336
383
 
337
- /** Push one row into the composer, standing in for the user's own typing. */
338
- const push = useCallback(async (item, mode) => {
384
+ const addQuote = useCallback(() => {
385
+ let live = ''
386
+ try {
387
+ live = String(window.getSelection() || '')
388
+ } catch {
389
+ live = ''
390
+ }
391
+ const text = (live.trim() !== '' ? live : lastChatSelection).trim()
392
+ if (text === '') {
393
+ setError(t('quote.empty'))
394
+ return
395
+ }
396
+ setQuotes((current) => [...current, text])
397
+ setError('')
398
+ }, [t])
399
+
400
+ /**
401
+ * Replay one row through the composer: leading text replaces the draft,
402
+ * later text blocks are inserted, quotes are inserted as real quote
403
+ * nodes. Nothing here writes a session event directly.
404
+ */
405
+ const replay = useCallback((segments, mode) => {
339
406
  if (!inputActions || typeof inputActions.setDraft !== 'function') {
340
407
  setError(t('error.noComposer'))
341
- return
408
+ return false
409
+ }
410
+ const rest = segments.map((segment) => ({ type: segment.type, text: segment.text }))
411
+ let head = ''
412
+ if (rest.length > 0 && rest[0].type === 'text') head = rest.shift().text
413
+ inputActions.setDraft(head)
414
+ for (const segment of rest) {
415
+ if (segment.type === 'text') {
416
+ if (typeof inputActions.captureInsertion !== 'function' || typeof inputActions.insertText !== 'function') {
417
+ setError(t('error.noComposer'))
418
+ return false
419
+ }
420
+ if (!inputActions.insertText(segment.text, inputActions.captureInsertion())) {
421
+ setError(t('error.push'))
422
+ return false
423
+ }
424
+ } else if (typeof inputActions.insertQuote !== 'function' || !inputActions.insertQuote(segment.text)) {
425
+ setError(t('error.push'))
426
+ return false
427
+ }
428
+ }
429
+ if (mode === 'send') {
430
+ if (typeof inputActions.submit !== 'function') {
431
+ setError(t('error.noComposer'))
432
+ return false
433
+ }
434
+ inputActions.submit()
342
435
  }
436
+ return true
437
+ }, [inputActions, t])
438
+
439
+ const push = useCallback(async (item, mode) => {
440
+ const segments = segmentsOfItem(item)
441
+ if (!hasContent(segments)) return
343
442
  setBusy(item.id)
344
443
  setError('')
345
444
  try {
346
- inputActions.setDraft(item.text)
445
+ if (!replay(segments, mode)) return
347
446
  if (mode === 'send') {
348
- if (typeof inputActions.submit !== 'function') {
349
- setError(t('error.noComposer'))
350
- return
351
- }
352
- inputActions.submit()
353
447
  flash(t('notice.sent'))
354
448
  await act({ action: 'markSent', id: item.id })
355
449
  } else {
@@ -358,21 +452,21 @@ window.__ModuleLoader__.load({
358
452
  } finally {
359
453
  if (live.current) setBusy('')
360
454
  }
361
- }, [inputActions, act, flash, t])
455
+ }, [replay, act, flash, t])
362
456
 
363
457
  const startEdit = useCallback((item) => {
364
- setEditing({ id: item.id, text: item.text })
458
+ setEditing({ id: item.id, segments: segmentsOfItem(item).map((segment) => ({ type: segment.type, text: segment.text })) })
365
459
  }, [])
366
460
 
367
461
  const saveEdit = useCallback(async () => {
368
462
  if (editing === null) return
369
- const text = editing.text.trim()
370
- if (text === '') {
463
+ const segments = editing.segments.filter((segment) => segment.text.trim() !== '')
464
+ if (segments.length === 0) {
371
465
  setError(t('error.empty'))
372
466
  return
373
467
  }
374
468
  setBusy(editing.id)
375
- const next = await act({ action: 'update', id: editing.id, text })
469
+ const next = await act({ action: 'update', id: editing.id, segments })
376
470
  if (live.current) {
377
471
  setBusy('')
378
472
  if (next) setEditing(null)
@@ -392,134 +486,78 @@ window.__ModuleLoader__.load({
392
486
 
393
487
  const countLabel = [count(t, 'queue.pending', pending), sent > 0 ? count(t, 'queue.sent', sent) : ''].filter(Boolean).join(' · ')
394
488
 
395
- const children = [
396
- h('style', { key: 'css' }, CSS),
397
- h('div', { key: 'head', className: ROOT + '-head' }, [
398
- h('span', { key: 'title', className: ROOT + '-title' }, t('queue.title')),
399
- h('span', { key: 'counts', className: ROOT + '-counts' }, countLabel),
400
- sent > 0
401
- ? h('button', {
402
- key: 'clear',
403
- type: 'button',
404
- className: ROOT + '-ghost',
405
- onClick: () => { void act({ action: 'clearSent' }) },
406
- }, t('queue.clearSent'))
407
- : null,
408
- h('button', {
409
- key: 'refresh',
410
- type: 'button',
411
- className: ROOT + '-ghost',
412
- onClick: () => { void load(true) },
413
- }, t('queue.refresh')),
414
- ]),
415
- h('div', { key: 'compose', className: ROOT + '-compose' }, [
416
- h('textarea', {
417
- key: 'input',
418
- className: ROOT + '-input',
419
- value: draft,
420
- placeholder: t('input.placeholder'),
421
- rows: 2,
422
- onChange: (event) => setDraft(event.target.value),
423
- onKeyDown: onComposeKey,
424
- }),
425
- h('div', { key: 'foot', className: ROOT + '-composeFoot' }, [
426
- h('span', { key: 'hint', className: ROOT + '-hint' }, t('input.hint')),
427
- h('button', {
428
- key: 'save',
429
- type: 'button',
430
- className: ROOT + '-primary',
431
- disabled: busy === 'add' || draft.trim() === '',
432
- onClick: () => { void saveDraft() },
433
- }, t('action.save')),
434
- ]),
435
- ]),
436
- notice !== '' ? h('div', { key: 'notice', className: ROOT + '-notice', role: 'status' }, notice) : null,
437
- error !== '' ? h('div', { key: 'err', className: ROOT + '-err', role: 'alert' }, error) : null,
438
- h('div', { key: 'body', className: ROOT + '-body' },
439
- loading && items.length === 0
440
- ? [h('div', { key: 'loading', className: ROOT + '-hintBlock' }, '…')]
441
- : items.length === 0
442
- ? [h('div', { key: 'empty', className: ROOT + '-hintBlock' }, [
443
- h('span', { key: 'title', className: ROOT + '-hintTitle' }, t('empty.title')),
444
- h('span', { key: 'body' }, t('empty.body')),
445
- ])]
446
- : items.map((item, index) => renderRow(item, index))),
447
- ]
489
+ function renderSegments(segments, keyPrefix) {
490
+ return segments.map((segment, index) => (segment.type === 'quote'
491
+ ? h('div', { key: keyPrefix + '-q' + index, className: ROOT + '-quote' }, segment.text)
492
+ : h('div', { key: keyPrefix + '-t' + index, className: ROOT + '-text' }, segment.text)))
493
+ }
448
494
 
449
495
  function renderRow(item, index) {
450
496
  const isEditing = editing !== null && editing.id === item.id
451
497
  const isSent = item.sentAt !== null && item.sentAt !== undefined
452
498
  const isBusy = busy === item.id
499
+ const segments = segmentsOfItem(item)
453
500
  const actions = []
454
501
  if (!isEditing && !isSent) {
455
502
  actions.push(h('button', {
456
- key: 'send',
457
- type: 'button',
458
- className: ROOT + '-act',
459
- 'data-tone': 'send',
460
- disabled: isBusy,
503
+ key: 'send', type: 'button', className: ROOT + '-act', 'data-tone': 'send', disabled: isBusy,
461
504
  onClick: () => { void push(item, 'send') },
462
505
  }, t('action.send')))
463
506
  actions.push(h('button', {
464
- key: 'fill',
465
- type: 'button',
466
- className: ROOT + '-act',
467
- disabled: isBusy,
507
+ key: 'fill', type: 'button', className: ROOT + '-act', disabled: isBusy,
468
508
  onClick: () => { void push(item, 'fill') },
469
509
  }, t('action.fill')))
470
510
  actions.push(h('button', {
471
- key: 'edit',
472
- type: 'button',
473
- className: ROOT + '-act',
511
+ key: 'edit', type: 'button', className: ROOT + '-act',
474
512
  onClick: () => startEdit(item),
475
513
  }, t('action.edit')))
476
514
  }
477
515
  if (isSent) {
478
516
  actions.push(h('button', {
479
- key: 'restore',
480
- type: 'button',
481
- className: ROOT + '-act',
517
+ key: 'restore', type: 'button', className: ROOT + '-act',
482
518
  onClick: () => { void act({ action: 'restore', id: item.id }) },
483
519
  }, t('action.restore')))
484
520
  }
485
521
  if (!isEditing) {
486
522
  actions.push(h('button', {
487
- key: 'up',
488
- type: 'button',
489
- className: ROOT + '-act',
490
- disabled: index === 0,
491
- 'aria-label': t('action.up'),
523
+ key: 'up', type: 'button', className: ROOT + '-act', disabled: index === 0, 'aria-label': t('action.up'),
492
524
  onClick: () => { void act({ action: 'move', id: item.id, direction: 'up' }) },
493
525
  }, '↑'))
494
526
  actions.push(h('button', {
495
- key: 'down',
496
- type: 'button',
497
- className: ROOT + '-act',
498
- disabled: index === items.length - 1,
499
- 'aria-label': t('action.down'),
527
+ key: 'down', type: 'button', className: ROOT + '-act', disabled: index === items.length - 1, 'aria-label': t('action.down'),
500
528
  onClick: () => { void act({ action: 'move', id: item.id, direction: 'down' }) },
501
529
  }, '↓'))
502
530
  actions.push(h('button', {
503
- key: 'remove',
504
- type: 'button',
505
- className: ROOT + '-act',
531
+ key: 'remove', type: 'button', className: ROOT + '-act',
506
532
  onClick: () => { void act({ action: 'remove', id: item.id }) },
507
533
  }, t('action.remove')))
508
534
  }
509
535
 
510
- return h('div', {
511
- key: item.id,
512
- className: ROOT + '-card',
513
- 'data-sent': isSent ? 'true' : 'false',
514
- }, [
515
- isEditing
516
- ? h('div', { key: 'editing' }, [
517
- h('textarea', {
518
- key: 'ta',
536
+ const body = isEditing
537
+ ? h('div', { key: 'editing' }, [
538
+ ...editing.segments.map((segment, segmentIndex) => (segment.type === 'quote'
539
+ ? h('div', { key: 'eq' + segmentIndex, className: ROOT + '-quoteChip' }, [
540
+ h('span', { key: 'txt', className: ROOT + '-quoteChipText' }, segment.text),
541
+ h('button', {
542
+ key: 'x', type: 'button', className: ROOT + '-x', 'aria-label': t('action.removeQuote'),
543
+ onClick: () => setEditing((current) => current === null ? current : ({
544
+ id: current.id,
545
+ segments: current.segments.filter((_, i) => i !== segmentIndex),
546
+ })),
547
+ }, '×'),
548
+ ])
549
+ : h('textarea', {
550
+ key: 'et' + segmentIndex,
519
551
  className: ROOT + '-edit',
520
- value: editing.text,
521
- rows: 3,
522
- onChange: (event) => setEditing({ id: item.id, text: event.target.value }),
552
+ value: segment.text,
553
+ rows: 2,
554
+ onChange: (event) => {
555
+ const value = event.target.value
556
+ setEditing((current) => current === null ? current : ({
557
+ id: current.id,
558
+ segments: current.segments.map((entry, i) => (i === segmentIndex ? { type: 'text', text: value } : entry)),
559
+ }))
560
+ },
523
561
  onKeyDown: (event) => {
524
562
  if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
525
563
  event.preventDefault()
@@ -530,25 +568,26 @@ window.__ModuleLoader__.load({
530
568
  setEditing(null)
531
569
  }
532
570
  },
533
- }),
534
- h('div', { key: 'acts', className: ROOT + '-acts' }, [
535
- h('button', {
536
- key: 'save',
537
- type: 'button',
538
- className: ROOT + '-act',
539
- 'data-tone': 'send',
540
- disabled: isBusy,
541
- onClick: () => { void saveEdit() },
542
- }, t('action.saveEdit')),
543
- h('button', {
544
- key: 'cancel',
545
- type: 'button',
546
- className: ROOT + '-act',
547
- onClick: () => setEditing(null),
548
- }, t('action.cancel')),
549
- ]),
550
- ])
551
- : h('div', { key: 'text', className: ROOT + '-text' }, item.text),
571
+ }))),
572
+ h('div', { key: 'acts', className: ROOT + '-acts' }, [
573
+ h('button', {
574
+ key: 'save', type: 'button', className: ROOT + '-act', 'data-tone': 'send', disabled: isBusy,
575
+ onClick: () => { void saveEdit() },
576
+ }, t('action.saveEdit')),
577
+ h('button', {
578
+ key: 'cancel', type: 'button', className: ROOT + '-act',
579
+ onClick: () => setEditing(null),
580
+ }, t('action.cancel')),
581
+ ]),
582
+ ])
583
+ : h('div', { key: 'content' }, renderSegments(segments, item.id))
584
+
585
+ return h('div', {
586
+ key: item.id,
587
+ className: ROOT + '-card',
588
+ 'data-sent': isSent ? 'true' : 'false',
589
+ }, [
590
+ body,
552
591
  h('div', { key: 'meta', className: ROOT + '-meta' }, [
553
592
  h('span', { key: 'time' }, relativeTime(item.createdAt, t)),
554
593
  isSent ? h('span', { key: 'sent', className: ROOT + '-badge' }, t('status.sent')) : null,
@@ -557,7 +596,60 @@ window.__ModuleLoader__.load({
557
596
  ])
558
597
  }
559
598
 
560
- return h('div', { className: ROOT }, children)
599
+ return h('div', { className: ROOT }, [
600
+ h('style', { key: 'css' }, CSS),
601
+ h('div', { key: 'head', className: ROOT + '-head' }, [
602
+ h('span', { key: 'title', className: ROOT + '-title' }, t('queue.title')),
603
+ h('span', { key: 'counts', className: ROOT + '-counts' }, countLabel),
604
+ sent > 0
605
+ ? h('button', { key: 'clear', type: 'button', className: ROOT + '-ghost', onClick: () => { void act({ action: 'clearSent' }) } }, t('queue.clearSent'))
606
+ : null,
607
+ h('button', { key: 'refresh', type: 'button', className: ROOT + '-ghost', onClick: () => { void load(true) } }, t('queue.refresh')),
608
+ ]),
609
+ h('div', { key: 'compose', className: ROOT + '-compose' }, [
610
+ h('textarea', {
611
+ key: 'input',
612
+ className: ROOT + '-input',
613
+ value: draft,
614
+ placeholder: t('input.placeholder'),
615
+ rows: 2,
616
+ onChange: (event) => setDraft(event.target.value),
617
+ onKeyDown: onComposeKey,
618
+ }),
619
+ quotes.length > 0
620
+ ? h('div', { key: 'quotes', className: ROOT + '-quotes' }, quotes.map((text, index) => h('div', {
621
+ key: 'qc' + index,
622
+ className: ROOT + '-quoteChip',
623
+ }, [
624
+ h('span', { key: 'txt', className: ROOT + '-quoteChipText' }, text),
625
+ h('button', {
626
+ key: 'x', type: 'button', className: ROOT + '-x', 'aria-label': t('action.removeQuote'),
627
+ onClick: () => setQuotes((current) => current.filter((_, i) => i !== index)),
628
+ }, '×'),
629
+ ])))
630
+ : null,
631
+ h('div', { key: 'foot', className: ROOT + '-composeFoot' }, [
632
+ h('span', { key: 'hint', className: ROOT + '-hint' }, quotes.length > 0 ? t('quote.hint') : t('input.hint')),
633
+ h('button', { key: 'quote', type: 'button', className: ROOT + '-ghost', onClick: addQuote }, t('action.quote')),
634
+ h('button', {
635
+ key: 'save', type: 'button', className: ROOT + '-primary',
636
+ disabled: busy === 'add' || (draft.trim() === '' && quotes.length === 0),
637
+ onClick: () => { void saveDraft() },
638
+ }, t('action.save')),
639
+ ]),
640
+ ]),
641
+ notice !== '' ? h('div', { key: 'notice', className: ROOT + '-notice', role: 'status' }, notice) : null,
642
+ error !== '' ? h('div', { key: 'err', className: ROOT + '-err', role: 'alert' }, error) : null,
643
+ h('div', { key: 'body', className: ROOT + '-body' },
644
+ loading && items.length === 0
645
+ ? [h('div', { key: 'loading', className: ROOT + '-hintBlock' }, '…')]
646
+ : items.length === 0
647
+ ? [h('div', { key: 'empty', className: ROOT + '-hintBlock' }, [
648
+ h('span', { key: 'title', className: ROOT + '-hintTitle' }, t('empty.title')),
649
+ h('span', { key: 'body' }, t('empty.body')),
650
+ ])]
651
+ : items.map(renderRow)),
652
+ ])
561
653
  }
562
654
 
563
655
  /** The tab chip: one glyph and the localized type name. */
@@ -578,6 +670,20 @@ window.__ModuleLoader__.load({
578
670
 
579
671
  ctx.effect(() => ctx.locale.register(NS, { zh: ZH, en: EN }), 'pending-queue: dictionaries')
580
672
 
673
+ ctx.effect(() => {
674
+ if (typeof document === 'undefined') return () => {}
675
+ const onSelection = () => {
676
+ try {
677
+ const text = String(window.getSelection() || '')
678
+ if (text.trim() !== '') lastChatSelection = text
679
+ } catch {
680
+ /* selection API unavailable */
681
+ }
682
+ }
683
+ document.addEventListener('selectionchange', onSelection)
684
+ return () => document.removeEventListener('selectionchange', onSelection)
685
+ }, 'pending-queue: selection capture')
686
+
581
687
  const definition = {
582
688
  id: PKG,
583
689
  kind: KIND,
package/icon.svg ADDED
@@ -0,0 +1,8 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64" role="img" aria-label="Pending queue">
2
+ <rect x="5" y="11" width="54" height="42" rx="12" fill="#2f6feb"/>
3
+ <rect x="14" y="19" width="3" height="26" rx="1.5" fill="#ffffff" opacity="0.55"/>
4
+ <path d="M22 24h20" stroke="#ffffff" stroke-width="4" stroke-linecap="round"/>
5
+ <path d="M22 33h14" stroke="#ffffff" stroke-width="4" stroke-linecap="round" opacity="0.8"/>
6
+ <path d="M22 42h10" stroke="#ffffff" stroke-width="4" stroke-linecap="round" opacity="0.6"/>
7
+ <path d="M44 37.5l7 6-7 6" stroke="#ffffff" stroke-width="3.4" stroke-linecap="round" stroke-linejoin="round" fill="none"/>
8
+ </svg>
package/index.js CHANGED
@@ -8,6 +8,10 @@
8
8
  * happens in the client half through the composer's own input actions, so a
9
9
  * queued row behaves exactly like text the user typed themselves.
10
10
  *
11
+ * A row is a list of segments, not one string. A quote is its own segment so
12
+ * the client half can rebuild it with inputActions.insertQuote() — a real
13
+ * quote block, not a literal "> " prefix.
14
+ *
11
15
  * Storage: <DSH_HOME>/storages/pending-queue/<sessionId>.json.
12
16
  * DSH_HOME defaults to ~/.dsh.
13
17
  */
@@ -31,20 +35,60 @@ const SESSION_ID = /^[A-Za-z0-9._-]{1,128}$/
31
35
  /** Bounded so one runaway session cannot grow the document without limit. */
32
36
  const MAX_ITEMS = 200
33
37
  const MAX_TEXT = 4000
38
+ const MAX_TOTAL = 12000
34
39
 
35
40
  function nowIso() {
36
41
  return new Date().toISOString()
37
42
  }
38
43
 
39
- /** One row's text: newlines survive, edges do not. */
44
+ /** One segment's text: newlines survive, edges do not. */
40
45
  function textOf(value) {
41
46
  if (typeof value !== 'string') return ''
42
47
  return value.replace(/\r\n/g, '\n').trim().slice(0, MAX_TEXT)
43
48
  }
44
49
 
50
+ /**
51
+ * A row is a list of segments, not one string: a quote travels as its own
52
+ * segment so the composer can rebuild it as a real quote block instead of a
53
+ * literal "> " prefix.
54
+ */
55
+ function segmentsOf(value) {
56
+ if (!Array.isArray(value)) throw new Error('segments must be an array')
57
+ const segments = []
58
+ let total = 0
59
+ for (const raw of value) {
60
+ if (raw === null || typeof raw !== 'object') throw new Error('invalid segment')
61
+ if (raw.type !== 'text' && raw.type !== 'quote') throw new Error('unknown segment type: ' + String(raw.type))
62
+ const text = textOf(raw.text)
63
+ if (text === '') continue
64
+ total += text.length
65
+ if (total > MAX_TOTAL) throw new Error('this row is too long (max ' + MAX_TOTAL + ' characters)')
66
+ segments.push({ type: raw.type, text })
67
+ }
68
+ if (segments.length === 0) throw new Error('text is required')
69
+ return segments
70
+ }
71
+
72
+ /** 'segments' is the shape the panel writes; a bare 'text' stays accepted. */
73
+ function segmentsFromBody(body) {
74
+ if (body !== null && typeof body === 'object' && Array.isArray(body.segments)) return segmentsOf(body.segments)
75
+ const text = textOf(body && body.text)
76
+ if (text === '') throw new Error('text is required')
77
+ return [{ type: 'text', text }]
78
+ }
79
+
80
+ /** The flattened form for readers that only want one string. */
81
+ function flattenSegments(segments) {
82
+ return segments
83
+ .map((segment) => (segment.type === 'quote'
84
+ ? segment.text.split('\n').map((line) => '> ' + line).join('\n')
85
+ : segment.text))
86
+ .join('\n\n')
87
+ }
88
+
45
89
  function createDoc(sessionId) {
46
90
  return {
47
- version: 1,
91
+ version: 2,
48
92
  sessionId,
49
93
  seq: 1,
50
94
  items: [],
@@ -72,7 +116,7 @@ async function readDoc(sessionId) {
72
116
  try {
73
117
  const raw = await readFile(fileFor(sessionId), 'utf8')
74
118
  const parsed = JSON.parse(raw)
75
- if (parsed !== null && typeof parsed === 'object' && parsed.version === 1 && Array.isArray(parsed.items)) {
119
+ if (parsed !== null && typeof parsed === 'object' && (parsed.version === 1 || parsed.version === 2) && Array.isArray(parsed.items)) {
76
120
  return normalizeDoc(parsed, sessionId)
77
121
  }
78
122
  return createDoc(sessionId)
@@ -84,17 +128,27 @@ async function readDoc(sessionId) {
84
128
  }
85
129
  }
86
130
 
87
- /** Fill fields an older document may lack, so one shape reaches every reader. */
131
+ /** Fill fields an older document may lack, and lift v1 text rows to segments. */
88
132
  function normalizeDoc(doc, sessionId) {
133
+ doc.version = 2
89
134
  doc.sessionId = sessionId
90
135
  doc.items = doc.items.filter((item) => item && typeof item.id === 'string')
91
136
  if (!Number.isInteger(doc.seq) || doc.seq < 1) doc.seq = doc.items.length + 1
92
137
  for (const item of doc.items) {
93
- if (typeof item.text !== 'string') item.text = ''
138
+ if (!Array.isArray(item.segments)) {
139
+ const text = typeof item.text === 'string' ? item.text : ''
140
+ item.segments = text.trim() === '' ? [] : [{ type: 'text', text }]
141
+ }
142
+ item.segments = item.segments.filter((segment) => segment
143
+ && (segment.type === 'text' || segment.type === 'quote')
144
+ && typeof segment.text === 'string'
145
+ && segment.text !== '')
146
+ delete item.text
94
147
  if (typeof item.createdAt !== 'string') item.createdAt = nowIso()
95
148
  if (typeof item.updatedAt !== 'string') item.updatedAt = item.createdAt
96
149
  if (typeof item.sentAt !== 'string') delete item.sentAt
97
150
  }
151
+ doc.items = doc.items.filter((item) => item.segments.length > 0)
98
152
  return doc
99
153
  }
100
154
 
@@ -134,22 +188,19 @@ function requireItem(doc, id) {
134
188
  function applyAction(doc, body) {
135
189
  const action = String((body && body.action) || '')
136
190
  if (action === 'add') {
137
- const text = textOf(body.text)
138
- if (text === '') throw new Error('text is required')
191
+ const segments = segmentsFromBody(body)
139
192
  if (doc.items.length >= MAX_ITEMS) {
140
193
  throw new Error('this queue already holds ' + MAX_ITEMS + ' rows; send or delete some first')
141
194
  }
142
195
  const at = nowIso()
143
196
  const id = 'q' + doc.seq
144
197
  doc.seq += 1
145
- doc.items.push({ id, text, createdAt: at, updatedAt: at })
198
+ doc.items.push({ id, segments, createdAt: at, updatedAt: at })
146
199
  return { id }
147
200
  }
148
201
  if (action === 'update') {
149
202
  const item = requireItem(doc, body.id)
150
- const text = textOf(body.text)
151
- if (text === '') throw new Error('text is required')
152
- item.text = text
203
+ item.segments = segmentsFromBody(body)
153
204
  item.updatedAt = nowIso()
154
205
  return { id: item.id }
155
206
  }
@@ -189,7 +240,8 @@ function viewDoc(doc) {
189
240
  updatedAt: doc.updatedAt,
190
241
  items: doc.items.map((item) => ({
191
242
  id: item.id,
192
- text: item.text,
243
+ segments: item.segments.map((segment) => ({ type: segment.type, text: segment.text })),
244
+ text: flattenSegments(item.segments),
193
245
  createdAt: item.createdAt,
194
246
  updatedAt: item.updatedAt,
195
247
  sentAt: typeof item.sentAt === 'string' ? item.sentAt : null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyra_wang/dsh-pending-queue",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Right-sidebar draft queue for DeepSeek Harness: jot ideas down, then push one into the session when the previous task is finished.",
5
5
  "type": "module",
6
6
  "main": "index.js",