dsh-quote-followup 0.2.7 → 0.2.8

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
@@ -17,13 +17,14 @@ A Web-only [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) p
17
17
  ## Features
18
18
 
19
19
  - Select text inside the Web conversation transcript to reveal a floating **Quote** button.
20
- - Append a native DSH conversation-reference chip without replacing the existing draft.
20
+ - Append a native DSH conversation-reference chip without replacing the existing draft, using the session-scoped composer input facade rather than Lexical's private node registry.
21
21
  - Reuse the same atomic `ReferenceChipNode`, conversation icon, and business color as `@file` / `@session`.
22
22
  - Keep each chip compact by showing only the excerpt; the bubble icon already conveys that it is a quote.
23
23
  - Follow the active DSH locale for the floating action and serialized quote frame.
24
- - Attach the conversation turn number to the serialized frame when the selection comes from a DSH chat row, so follow-ups like "revisit turn 3" stay resolvable. Selections without a turn marker keep the provenance-free frame.
24
+ - Attach the conversation turn number to the serialized frame when both ends of the selection belong to the same DSH chat row. Selections spanning messages keep the excerpt but omit ambiguous role/turn provenance.
25
25
  - Quote multiple excerpts; on send, the plugin codec expands each chip into a model-readable Markdown blockquote.
26
26
  - Fall back to a plain-text quote when the host lacks native chip support.
27
+ - Show a localized notice if the composer is missing or unavailable, restore the selection, and let you retry quoting the original text.
27
28
 
28
29
  TUI is intentionally unsupported.
29
30
 
@@ -57,7 +58,7 @@ Add `dsh-quote-followup` to the Web profile's `dsh.profile.bundles`, then restar
57
58
  npm test
58
59
  ```
59
60
 
60
- The regression harness covers compact native quote chips, locale switching, turn-number provenance with graceful degradation, repeated quoting, spacing after an existing draft, codec serialization, the Firefox text fallback, and current-client takeover of stale singleton/button state after a hot swap.
61
+ The regression harness covers compact native quote chips, locale switching, single-row versus cross-message provenance, missing/locked composer feedback and retry, repeated quoting, spacing after an existing draft, codec serialization, the Firefox text fallback, and current-client takeover of stale singleton/button state after a hot swap.
61
62
 
62
63
  An opt-in [assembled DSH Web regression](https://github.com/tr1v3r/dsh-quote-followup/blob/master/test/integration/README.md) runs the plugin through a pinned, built DSH checkout with Chromium. It covers existing drafts, repeated quoting, undo/redo, session isolation, prompt serialization, and Host-driven unavailable input.
63
64
 
package/README.zh.md CHANGED
@@ -17,13 +17,14 @@
17
17
  ## 功能
18
18
 
19
19
  - 在 Web 对话区选中文本后显示浮动的 **❐ 引用** 按钮。
20
- - 以 DSH 原生对话引用 chip 追加到现有草稿,不覆盖已输入内容。
20
+ - 通过会话级输入接口将 DSH 原生对话引用 chip 追加到现有草稿,不覆盖已输入内容,也不直接读取 Lexical 私有节点注册表。
21
21
  - chip 使用与 `@文件` / `@对话` 相同的 `ReferenceChipNode`、对话图标和业务色,可整体删除。
22
22
  - chip 只展示摘录正文,引用语义由气泡图标表达,减少重复标签。
23
23
  - 浮动按钮和发送时的引用框架跟随 DSH 当前语言。
24
- - 选中内容来自 DSH 聊天行时,序列化引用会附带对话轮次编号,模型可定位"第 3 轮引用的内容";无轮次标记时保持原有框架。
24
+ - 选区两端属于同一 DSH 聊天行时,序列化引用附带对话轮次编号;跨消息选区保留摘录,但不标注归属不明的角色与轮次。
25
25
  - 可连续引用多段内容;发送时由插件 codec 将各 chip 展开为模型可读的 Markdown 引用块。
26
26
  - 旧版 DSH 缺少原生 chip 能力时,自动降级为纯文本引用。
27
+ - 输入框缺失或暂不可编辑时显示本地化提示,恢复原选区,便于重试引用。
27
28
 
28
29
  本插件不再适配 TUI。
29
30
 
@@ -57,7 +58,7 @@ dsh plugin --profile web add dsh-quote-followup
57
58
  npm test
58
59
  ```
59
60
 
60
- 回归测试覆盖精简的原生引用 chip、中英文 locale 切换、轮次溯源与降级、连续引用、已有草稿后的间距、codec 序列化、Firefox 文本降级路径,以及热替换后新版 client 接管旧按钮/单例状态。
61
+ 回归测试覆盖精简的原生引用 chip、中英文 locale 切换、同消息与跨消息的来源判定、输入框缺失/不可编辑时的提示与重试、连续引用、已有草稿后的间距、codec 序列化、Firefox 文本降级路径,以及热替换后新版 client 接管旧按钮/单例状态。
61
62
 
62
63
  可选的[真实 DSH Web 集成回归](https://github.com/tr1v3r/dsh-quote-followup/blob/master/test/integration/README.md)通过固定版本、已构建的 DSH 和 Chromium 加载插件,验证已有草稿、连续引用、撤销重做、会话隔离、发送序列化及 Host 驱动的不可写输入状态。
63
64
 
package/lib/client.js CHANGED
@@ -7,9 +7,10 @@
7
7
  * can edit before sending — a visible, targeted follow-up with zero hidden
8
8
  * state and zero host-side privileges.
9
9
  *
10
- * Pure DOM (no React). The only injected host services are DSH's
11
- * `inputTriggers` codec registry and `locale` (both optional — the module
12
- * degrades to English text fallbacks when either is absent). Mounted by the
10
+ * Pure DOM (no React). The injected host services are DSH's
11
+ * `inputTriggers` codec registry, `locale`, and `sessions`. Without the
12
+ * optional codec, quotes degrade to plain text; without locale, copy is English.
13
+ * Session scoping is needed for native reference insertion. Mounted by the
13
14
  * web client runtime through the package's `dsh.client` declaration
14
15
  * (`platform: "web"`).
15
16
  *
@@ -26,6 +27,7 @@ window.__ModuleLoader__.load({
26
27
  const TRANSCRIPT_SELECTOR = '[data-slot="conversation.session"]';
27
28
  /** Composer input candidates, most specific first (official slot → legacy hints). */
28
29
  const COMPOSER_SELECTORS = [
30
+ '[data-composer-input]',
29
31
  '[data-slot="conversation.composer"] textarea',
30
32
  '[data-slot="conversation.composer"] [contenteditable="true"]',
31
33
  'textarea[data-phase]',
@@ -35,11 +37,13 @@ window.__ModuleLoader__.load({
35
37
  ];
36
38
  const BUTTON_ID = "dsh-quote-followup-btn";
37
39
  const BUTTON_VERSION_ATTR = "data-dsh-quote-followup-version";
38
- const CLIENT_VERSION = "0.2.7";
40
+ const CLIENT_VERSION = "0.2.8";
39
41
  /** Shared <style> element; versioned like the button so hot-swaps replace it. */
40
42
  const STYLE_ID = "dsh-quote-followup-style";
41
43
  const STYLE_VERSION_ATTR = "data-dsh-quote-followup-style-version";
42
44
  const BUTTON_CLASS = "dsh-qf-btn";
45
+ const NOTICE_ID = "dsh-quote-followup-notice";
46
+ const NOTICE_CLASS = "dsh-qf-notice";
43
47
  /** Codec owner for native DSH reference chips. */
44
48
  const QUOTE_SOURCE = "quote-followup";
45
49
  const LOCALE_NS = "quote-followup";
@@ -53,7 +57,10 @@ window.__ModuleLoader__.load({
53
57
  "conversation.role.user": "用户",
54
58
  "conversation.role.assistant": "助手",
55
59
  "quote.turn": "第 {n} 轮",
56
- "quote.truncated": "已截断"
60
+ "quote.truncated": "已截断",
61
+ "notice.composer-missing": "未找到输入框;摘录已保留,请选中原文重试。",
62
+ "notice.composer-locked": "输入框暂不可编辑;摘录已保留,请选中原文重试。",
63
+ "notice.insert-failed": "引用未能插入;摘录已保留,请选中原文重试。"
57
64
  },
58
65
  en: {
59
66
  "button.label": "❐ Quote",
@@ -63,7 +70,10 @@ window.__ModuleLoader__.load({
63
70
  "conversation.role.user": "user",
64
71
  "conversation.role.assistant": "assistant",
65
72
  "quote.turn": "turn {n}",
66
- "quote.truncated": "truncated"
73
+ "quote.truncated": "truncated",
74
+ "notice.composer-missing": "Composer not found; excerpt saved. Select the original text to retry.",
75
+ "notice.composer-locked": "Composer is unavailable; excerpt saved. Select the original text to retry.",
76
+ "notice.insert-failed": "Quote could not be inserted; excerpt saved. Select the original text to retry."
67
77
  }
68
78
  };
69
79
  const fallbackT = (key) => LOCALE_DICT.en[key] ?? key;
@@ -99,6 +109,9 @@ window.__ModuleLoader__.load({
99
109
  return null;
100
110
  return anchor;
101
111
  };
112
+ /** Only assign provenance when both ends belong to the same marked chat row. */
113
+ const messageRowOf = (node, transcript) =>
114
+ walkAncestors(node, transcript, (element) => element.hasAttribute?.("data-chat-turn") ? element : undefined);
102
115
  /**
103
116
  * Best-effort role for the quoted fragment: walk up from the range start
104
117
  * looking for role markers (data attributes, then class-name hints).
@@ -210,49 +223,52 @@ window.__ModuleLoader__.load({
210
223
  return null;
211
224
  };
212
225
  /**
213
- * Insert through DSH's registered ReferenceChipNode so the quote uses the
214
- * exact same atomic editor entity and visual treatment as @file/@session.
215
- * The node class is already registered on the live composer; no second
216
- * Lexical or React runtime is loaded by this plugin.
226
+ * The per-session input facade owns chip creation, editor transactions and
227
+ * phase/revision guards. Append at its published draft end (detect-text
228
+ * offsets differ from clipboard-text lengths when a draft contains chips).
217
229
  */
218
- const appendQuoteChip = (element, payload, t) => {
219
- const editor = element.__lexicalEditor;
220
- const registry = editor?._nodes;
221
- const ChipNode = registry?.get?.("reference-chip")?.klass;
222
- const TextNode = registry?.get?.("text")?.klass;
223
- const ParagraphNode = registry?.get?.("paragraph")?.klass;
224
- if (typeof editor?.update !== "function" || typeof ChipNode !== "function" || typeof TextNode !== "function" || typeof ParagraphNode !== "function")
230
+ const appendQuoteChip = (ctx, element, payload, t) => {
231
+ const sessions = ctx?.get?.("sessions");
232
+ const sessionId = sessions?.list?.getSnapshot?.()?.current;
233
+ const scope = sessionId === undefined ? null : sessions?.scope?.(sessionId);
234
+ const conversation = scope?.get?.("conversation");
235
+ if (scope === null || scope === undefined || typeof conversation?.input?.for !== "function")
225
236
  return false;
237
+ let input;
226
238
  try {
227
- let inserted = false;
228
- editor.update(() => {
229
- const state = editor._pendingEditorState ?? editor._editorState;
230
- const root = state?._nodeMap?.get?.("root");
231
- if (root === void 0 || root === null || typeof root.append !== "function")
232
- return;
233
- let block = typeof root.getLastChild === "function" ? root.getLastChild() : null;
234
- if (block === null || typeof block.append !== "function") {
235
- block = new ParagraphNode();
236
- root.append(block);
237
- }
238
- const nodes = [];
239
- const tail = typeof block.getTextContent === "function" ? block.getTextContent().slice(-1) : "";
240
- if (tail !== "" && !/\s/u.test(tail))
241
- nodes.push(new TextNode(" "));
242
- nodes.push(new ChipNode(quoteInsert(payload, t)));
243
- const trailing = new TextNode(" ");
244
- nodes.push(trailing);
245
- block.append(...nodes);
246
- if (typeof trailing.selectEnd === "function")
247
- trailing.selectEnd();
248
- inserted = true;
249
- }, { discrete: true });
239
+ input = conversation.input.for(scope);
240
+ } catch (error) {
241
+ console.warn("[dsh-quote-followup] scoped composer unavailable", error);
242
+ return false;
243
+ }
244
+ const state = input?.state?.getSnapshot?.();
245
+ if (state === undefined || typeof state.draftRev !== "number" || typeof input.insertReference !== "function")
246
+ return false;
247
+ // This is a rejected edit, not a missing feature: never bypass the
248
+ // facade's admission guard with an unguarded text fallback.
249
+ if (state.phase !== "plain" && state.phase !== "claimed")
250
+ return null;
251
+ const end = state.draft.length - (state.occurrences ?? []).reduce((extra, occurrence) =>
252
+ extra + Math.max(0, occurrence.length - 1), 0);
253
+ if (!Number.isSafeInteger(end) || end < 0)
254
+ return null;
255
+ const lead = end > 0 && !/\s/u.test(state.draft.slice(-1)) ? " " : "";
256
+ try {
257
+ if (lead !== "" && input.insertText(lead, { start: end, end, draftRev: state.draftRev }) !== true)
258
+ return null;
259
+ const current = input.state.getSnapshot();
260
+ if (current.draftRev !== state.draftRev + lead.length)
261
+ return null;
262
+ const at = end + lead.length;
263
+ const inserted = input.insertReference(quoteInsert(payload, t), {
264
+ start: at, end: at, draftRev: current.draftRev
265
+ });
250
266
  if (inserted)
251
267
  element.focus();
252
- return inserted;
268
+ return inserted ? true : null;
253
269
  } catch (error) {
254
- console.warn("[dsh-quote-followup] native reference chip failed; using text fallback", error);
255
- return false;
270
+ console.warn("[dsh-quote-followup] scoped reference insertion failed", error);
271
+ return null;
256
272
  }
257
273
  };
258
274
  /**
@@ -362,6 +378,34 @@ window.__ModuleLoader__.load({
362
378
  let pendingQuote = null;
363
379
  let quoteSourceReady = false;
364
380
  let currentT = fallbackT;
381
+ let clientContext = null;
382
+ let noticeTimer = null;
383
+ const clearNotice = () => {
384
+ if (noticeTimer !== null)
385
+ clearTimeout(noticeTimer);
386
+ noticeTimer = null;
387
+ document.getElementById(NOTICE_ID)?.remove();
388
+ };
389
+ const showNotice = (key) => {
390
+ clearNotice();
391
+ const notice = document.createElement("div");
392
+ notice.id = NOTICE_ID;
393
+ notice.className = NOTICE_CLASS;
394
+ notice.setAttribute("role", "status");
395
+ notice.setAttribute("data-message-key", key);
396
+ notice.textContent = currentT(key);
397
+ document.body.appendChild(notice);
398
+ noticeTimer = setTimeout(clearNotice, 4000);
399
+ };
400
+ const restoreSelection = (range) => {
401
+ if (range === null)
402
+ return;
403
+ try {
404
+ const selection = document.getSelection();
405
+ selection?.removeAllRanges();
406
+ selection?.addRange(range);
407
+ } catch {}
408
+ };
365
409
  /**
366
410
  * Inject the button stylesheet once per client version. Visuals follow
367
411
  * the dsh-annotation convention: a single idempotent <style> element
@@ -414,6 +458,21 @@ window.__ModuleLoader__.load({
414
458
  " outline: 2px solid var(--dsw-alias-text-accent, #4c9aff);",
415
459
  " outline-offset: 1px;",
416
460
  "}",
461
+ `.${NOTICE_CLASS} {`,
462
+ " position: fixed;",
463
+ " z-index: 2147483600;",
464
+ " left: 50%;",
465
+ " bottom: 24px;",
466
+ " transform: translateX(-50%);",
467
+ " max-width: min(90vw, 480px);",
468
+ " padding: 8px 12px;",
469
+ " border-radius: 8px;",
470
+ " background: var(--dsw-alias-button-primary-fill, rgba(56, 56, 62, .94));",
471
+ " color: var(--dsw-alias-label-primary-foreground, #f5f5f7);",
472
+ " font-family: var(--dsw-font-family, system-ui);",
473
+ " font-size: 12px;",
474
+ " pointer-events: none;",
475
+ "}",
417
476
  "@keyframes dsh-qf-pop {",
418
477
  " from { opacity: 0; transform: translateY(3px); }",
419
478
  " to { opacity: 1; transform: none; }",
@@ -469,29 +528,36 @@ window.__ModuleLoader__.load({
469
528
  if (button !== null)
470
529
  button.style.display = "none";
471
530
  };
531
+ const dismissQuote = () => {
532
+ pendingQuote = null;
533
+ hideButton();
534
+ };
472
535
  const onSelectionChange = () => {
473
536
  const selection = document.getSelection();
474
537
  const transcript = selectionInTranscript(selection);
475
538
  if (transcript === null) {
476
- pendingQuote = null;
477
- hideButton();
539
+ dismissQuote();
478
540
  return;
479
541
  }
480
542
  const text = selection.toString();
481
543
  if (text === null || text.trim() === "") {
482
- pendingQuote = null;
483
- hideButton();
544
+ dismissQuote();
484
545
  return;
485
546
  }
486
- const rect = selection.getRangeAt(0).getBoundingClientRect();
547
+ const range = selection.getRangeAt(0);
548
+ const rect = range.getBoundingClientRect();
487
549
  if (rect.width === 0 && rect.height === 0) {
488
- hideButton();
550
+ dismissQuote();
489
551
  return;
490
552
  }
553
+ const startRow = messageRowOf(range.startContainer, transcript);
554
+ const endRow = messageRowOf(range.endContainer, transcript);
555
+ const sameRow = startRow !== null && startRow === endRow;
491
556
  pendingQuote = {
492
557
  text: text.trim(),
493
- role: detectRole(selection.getRangeAt(0), transcript),
494
- turn: detectTurn(selection.getRangeAt(0), transcript)
558
+ role: sameRow ? detectRole(range, transcript) : null,
559
+ turn: sameRow ? detectTurn(range, transcript) : null,
560
+ range: range.cloneRange()
495
561
  };
496
562
  placeButton(ensureButton(), rect);
497
563
  };
@@ -499,19 +565,39 @@ window.__ModuleLoader__.load({
499
565
  if (pendingQuote === null)
500
566
  return;
501
567
  const quote = pendingQuote;
502
- pendingQuote = null;
503
568
  hideButton();
504
569
  const composer = findComposer();
505
570
  if (composer === null) {
506
- console.warn("[dsh-quote-followup] composer input not found — quote dropped");
571
+ restoreSelection(quote.range);
572
+ showNotice("notice.composer-missing");
573
+ return;
574
+ }
575
+ if (composer.disabled || composer.readOnly || composer.getAttribute("contenteditable") === "false" ||
576
+ (composer.isContentEditable === false && composer.tagName !== "TEXTAREA" && composer.tagName !== "INPUT")) {
577
+ restoreSelection(quote.range);
578
+ showNotice("notice.composer-locked");
507
579
  return;
508
580
  }
509
581
  // Clear the transcript range BEFORE focusing the composer. Clearing after
510
582
  // insertion destroys Lexical's caret and makes the next quote unreliable.
511
583
  document.getSelection()?.removeAllRanges();
512
584
  const payload = quotePayload(quote.text, quote.role, quote.turn);
513
- if (!(quoteSourceReady && appendQuoteChip(composer, payload, currentT)))
514
- appendToComposer(composer, quoteFrame(payload, currentT));
585
+ try {
586
+ const inserted = quoteSourceReady ? appendQuoteChip(clientContext, composer, payload, currentT) : false;
587
+ if (inserted === false)
588
+ appendToComposer(composer, quoteFrame(payload, currentT));
589
+ if (inserted === null) {
590
+ restoreSelection(quote.range);
591
+ showNotice("notice.insert-failed");
592
+ return;
593
+ }
594
+ pendingQuote = null;
595
+ clearNotice();
596
+ } catch (error) {
597
+ console.warn("[dsh-quote-followup] quote insertion failed", error);
598
+ restoreSelection(quote.range);
599
+ showNotice("notice.insert-failed");
600
+ }
515
601
  };
516
602
  //#endregion
517
603
  //#region apply
@@ -522,6 +608,7 @@ window.__ModuleLoader__.load({
522
608
  return;
523
609
  if (typeof previous?.dispose === "function")
524
610
  previous.dispose();
611
+ clientContext = ctx;
525
612
  let unregisterSource = null;
526
613
  let unregisterLocale = null;
527
614
  let unsubscribeLocale = null;
@@ -531,6 +618,9 @@ window.__ModuleLoader__.load({
531
618
  button.textContent = currentT("button.label");
532
619
  button.title = currentT("button.title");
533
620
  }
621
+ const notice = document.getElementById(NOTICE_ID);
622
+ if (notice !== null)
623
+ notice.textContent = currentT(notice.getAttribute("data-message-key"));
534
624
  };
535
625
  try {
536
626
  const locale = typeof ctx?.get === "function" ? ctx.get("locale") : null;
@@ -556,14 +646,14 @@ window.__ModuleLoader__.load({
556
646
  } catch (error) {
557
647
  console.warn("[dsh-quote-followup] native reference codec unavailable; using text fallback", error);
558
648
  }
559
- const onScroll = () => hideButton();
649
+ const onScroll = () => dismissQuote();
560
650
  const onKeyDown = (event) => {
561
651
  if (event.key === "Escape")
562
- hideButton();
652
+ dismissQuote();
563
653
  };
564
654
  const onMouseDown = (event) => {
565
655
  if (event.target instanceof Element && event.target.id !== BUTTON_ID)
566
- hideButton();
656
+ dismissQuote();
567
657
  };
568
658
  let disposed = false;
569
659
  let state;
@@ -571,6 +661,9 @@ window.__ModuleLoader__.load({
571
661
  if (disposed)
572
662
  return;
573
663
  disposed = true;
664
+ clientContext = null;
665
+ dismissQuote();
666
+ clearNotice();
574
667
  quoteSourceReady = false;
575
668
  if (typeof unsubscribeLocale === "function")
576
669
  unsubscribeLocale();
@@ -605,7 +698,7 @@ window.__ModuleLoader__.load({
605
698
  ctx.effect(() => cleanup, "dsh-quote-followup: selection quote ui");
606
699
  }
607
700
  //#endregion
608
- exports.inject = ["inputTriggers", "locale"];
701
+ exports.inject = ["inputTriggers", "locale", "sessions"];
609
702
  exports.apply = apply;
610
703
  return module.exports;
611
704
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-quote-followup",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "Quote selected Web conversation text into the DeepSeek Harness composer for targeted follow-up turns.",
5
5
  "keywords": [
6
6
  "dsh",