dsh-better-display 0.3.8 → 0.3.10

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 (190) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/DESIGN.md +43 -3
  3. package/README.en.md +10 -2
  4. package/README.md +10 -2
  5. package/compat/harness-rc2.json +17 -13
  6. package/docs/dependency-update-policy.md +9 -0
  7. package/docs/extension-points.md +172 -0
  8. package/docs/official-rendering-bridge.md +49 -20
  9. package/docs/openapi.yaml +147 -0
  10. package/docs/runbooks/blank-reader.md +39 -0
  11. package/lib/client.js +1802 -872
  12. package/lib/client.js.map +1 -1
  13. package/lib/dsh-better-display.js +376 -151
  14. package/lib/types/client/AssistantNode.d.ts +20 -0
  15. package/lib/types/client/AssistantNode.d.ts.map +1 -0
  16. package/lib/types/client/AssistantNode.js +46 -0
  17. package/lib/types/client/AssistantNode.js.map +1 -0
  18. package/lib/types/client/Blocks.d.ts.map +1 -1
  19. package/lib/types/client/Blocks.js +33 -10
  20. package/lib/types/client/Blocks.js.map +1 -1
  21. package/lib/types/client/ChoreographedFlow.d.ts.map +1 -1
  22. package/lib/types/client/ChoreographedFlow.js +2 -0
  23. package/lib/types/client/ChoreographedFlow.js.map +1 -1
  24. package/lib/types/client/ClosedProcessSummary.d.ts.map +1 -1
  25. package/lib/types/client/ClosedProcessSummary.js +3 -1
  26. package/lib/types/client/ClosedProcessSummary.js.map +1 -1
  27. package/lib/types/client/McpAppFrame.d.ts.map +1 -1
  28. package/lib/types/client/McpAppFrame.js +5 -11
  29. package/lib/types/client/McpAppFrame.js.map +1 -1
  30. package/lib/types/client/OfficialContent.d.ts +17 -3
  31. package/lib/types/client/OfficialContent.d.ts.map +1 -1
  32. package/lib/types/client/OfficialContent.js +37 -12
  33. package/lib/types/client/OfficialContent.js.map +1 -1
  34. package/lib/types/client/Reader.d.ts.map +1 -1
  35. package/lib/types/client/Reader.js +45 -77
  36. package/lib/types/client/Reader.js.map +1 -1
  37. package/lib/types/client/SettingsSection.d.ts.map +1 -1
  38. package/lib/types/client/SettingsSection.js +0 -5
  39. package/lib/types/client/SettingsSection.js.map +1 -1
  40. package/lib/types/client/StickyLane.d.ts +12 -0
  41. package/lib/types/client/StickyLane.d.ts.map +1 -1
  42. package/lib/types/client/StickyLane.js +78 -2
  43. package/lib/types/client/StickyLane.js.map +1 -1
  44. package/lib/types/client/ToolActivity.js.map +1 -1
  45. package/lib/types/client/index.d.ts +3 -1
  46. package/lib/types/client/index.d.ts.map +1 -1
  47. package/lib/types/client/index.js +6 -0
  48. package/lib/types/client/index.js.map +1 -1
  49. package/lib/types/client/live-turn.d.ts +17 -5
  50. package/lib/types/client/live-turn.d.ts.map +1 -1
  51. package/lib/types/client/live-turn.js +106 -76
  52. package/lib/types/client/live-turn.js.map +1 -1
  53. package/lib/types/client/motion.d.ts +26 -2
  54. package/lib/types/client/motion.d.ts.map +1 -1
  55. package/lib/types/client/motion.js +136 -10
  56. package/lib/types/client/motion.js.map +1 -1
  57. package/lib/types/client/official-slots.d.ts +24 -3
  58. package/lib/types/client/official-slots.d.ts.map +1 -1
  59. package/lib/types/client/official-slots.js +59 -11
  60. package/lib/types/client/official-slots.js.map +1 -1
  61. package/lib/types/client/primitive-labels.d.ts.map +1 -1
  62. package/lib/types/client/primitive-labels.js +1 -0
  63. package/lib/types/client/primitive-labels.js.map +1 -1
  64. package/lib/types/client/projection.d.ts +15 -2
  65. package/lib/types/client/projection.d.ts.map +1 -1
  66. package/lib/types/client/projection.js +16 -4
  67. package/lib/types/client/projection.js.map +1 -1
  68. package/lib/types/client/rewind-cut.d.ts +131 -0
  69. package/lib/types/client/rewind-cut.d.ts.map +1 -0
  70. package/lib/types/client/rewind-cut.js +321 -0
  71. package/lib/types/client/rewind-cut.js.map +1 -0
  72. package/lib/types/client/text-transform.d.ts +93 -0
  73. package/lib/types/client/text-transform.d.ts.map +1 -0
  74. package/lib/types/client/text-transform.js +183 -0
  75. package/lib/types/client/text-transform.js.map +1 -0
  76. package/lib/types/client/timeline.d.ts.map +1 -1
  77. package/lib/types/client/timeline.js.map +1 -1
  78. package/lib/types/client/tool-activity.d.ts +9 -2
  79. package/lib/types/client/tool-activity.d.ts.map +1 -1
  80. package/lib/types/client/tool-activity.js +42 -2
  81. package/lib/types/client/tool-activity.js.map +1 -1
  82. package/lib/types/client/turn-slots.d.ts +29 -0
  83. package/lib/types/client/turn-slots.d.ts.map +1 -0
  84. package/lib/types/client/turn-slots.js +62 -0
  85. package/lib/types/client/turn-slots.js.map +1 -0
  86. package/lib/types/client/types.d.ts +18 -0
  87. package/lib/types/client/types.d.ts.map +1 -1
  88. package/lib/types/dsh-better-display.d.ts +4 -1
  89. package/lib/types/dsh-better-display.d.ts.map +1 -1
  90. package/lib/types/dsh-better-display.js +56 -7
  91. package/lib/types/dsh-better-display.js.map +1 -1
  92. package/lib/types/flags.d.ts +7 -0
  93. package/lib/types/flags.d.ts.map +1 -0
  94. package/lib/types/flags.js +37 -0
  95. package/lib/types/flags.js.map +1 -0
  96. package/lib/types/log.d.ts +17 -0
  97. package/lib/types/log.d.ts.map +1 -0
  98. package/lib/types/log.js +122 -0
  99. package/lib/types/log.js.map +1 -0
  100. package/lib/types/metrics.d.ts +18 -0
  101. package/lib/types/metrics.d.ts.map +1 -0
  102. package/lib/types/metrics.js +35 -0
  103. package/lib/types/metrics.js.map +1 -0
  104. package/package.json +55 -23
  105. package/scripts/changelog.mjs +20 -0
  106. package/scripts/check-agents-md.mjs +67 -0
  107. package/scripts/check-bundle-size.mjs +38 -0
  108. package/scripts/check-dead-flags.mjs +55 -0
  109. package/scripts/check-harness-compat.mjs +4 -2
  110. package/scripts/check-todo-debt.mjs +69 -0
  111. package/scripts/link-harness-dependencies.mjs +48 -11
  112. package/scripts/security-audit-report.mjs +92 -0
  113. package/scripts/verify-commentary-visible.mjs +627 -0
  114. package/src/client/AssistantNode.tsx +72 -0
  115. package/src/client/Blocks.tsx +49 -10
  116. package/src/client/ChoreographedFlow.tsx +3 -1
  117. package/src/client/ClosedProcessSummary.tsx +3 -1
  118. package/src/client/McpAppFrame.tsx +5 -13
  119. package/src/client/OfficialContent.tsx +52 -14
  120. package/src/client/Reader.module.css +68 -18
  121. package/src/client/Reader.tsx +38 -82
  122. package/src/client/SettingsSection.tsx +1 -7
  123. package/src/client/StickyLane.tsx +81 -2
  124. package/src/client/ToolActivity.tsx +1 -1
  125. package/src/client/index.tsx +8 -1
  126. package/src/client/live-turn.ts +100 -69
  127. package/src/client/motion.tsx +135 -7
  128. package/src/client/official-slots.tsx +61 -12
  129. package/src/client/primitive-labels.ts +1 -0
  130. package/src/client/projection.ts +16 -4
  131. package/src/client/rewind-cut.ts +340 -0
  132. package/src/client/text-transform.ts +265 -0
  133. package/src/client/timeline.ts +0 -2
  134. package/src/client/tool-activity.ts +49 -2
  135. package/src/client/turn-slots.ts +80 -0
  136. package/src/client/types.ts +19 -0
  137. package/src/dsh-better-display.ts +58 -7
  138. package/src/flags.ts +40 -0
  139. package/src/log.ts +137 -0
  140. package/src/metrics.ts +50 -0
  141. package/tests/browser-commentary.tsx +191 -0
  142. package/tests/browser-official-bridge.tsx +2 -1
  143. package/tests/chat-flow-hook.test.ts +1 -1
  144. package/tests/cloud-gate.test.ts +1 -1
  145. package/tests/context-tool-update.test.ts +1 -1
  146. package/tests/conversation-scroll.test.ts +1 -1
  147. package/tests/deliverables.test.ts +1 -1
  148. package/tests/entry.test.ts +1 -1
  149. package/tests/fixtures/reader-lane-owners.tsx +46 -0
  150. package/tests/fixtures/reader-official-users.tsx +64 -0
  151. package/tests/fixtures/reader-theme-overlap.html +80 -0
  152. package/tests/fixtures/reader-user-bubble.tsx +244 -0
  153. package/tests/flags.test.ts +66 -0
  154. package/tests/fold-choreography.test.ts +32 -8
  155. package/tests/fold-intensity.test.ts +11 -6
  156. package/tests/footer-precedence.test.ts +1 -1
  157. package/tests/history-word-regression.test.ts +1 -1
  158. package/tests/live-turn.test.ts +125 -54
  159. package/tests/log.test.ts +99 -0
  160. package/tests/mcp-apps.test.ts +1 -1
  161. package/tests/message-chrome.test.ts +1 -1
  162. package/tests/metrics.test.ts +52 -0
  163. package/tests/official-slots.test.ts +41 -2
  164. package/tests/open-file.test.ts +1 -1
  165. package/tests/pending-submission.test.ts +12 -1
  166. package/tests/pinned-selection.test.ts +16 -0
  167. package/tests/platform-media.test.ts +1 -1
  168. package/tests/projection.test.ts +66 -3
  169. package/tests/reader-glass-css.test.ts +1 -1
  170. package/tests/reader-official-users.test.ts +11 -1
  171. package/tests/reader-sticky-surface.test.ts +377 -0
  172. package/tests/reader-theme-lanes.test.ts +54 -0
  173. package/tests/reader-theme-overlap.test.ts +151 -0
  174. package/tests/reader-user-bubble.test.ts +138 -0
  175. package/tests/reasoning-follow.test.ts +1 -1
  176. package/tests/retiring-content.test.ts +98 -6
  177. package/tests/reveal.test.ts +3 -3
  178. package/tests/rewind-cut.test.ts +1090 -0
  179. package/tests/settings-copy.test.ts +1 -1
  180. package/tests/skill-status.test.ts +1 -1
  181. package/tests/stock-install.test.ts +11 -7
  182. package/tests/stream-buffer.test.ts +1 -1
  183. package/tests/styles.test.ts +30 -3
  184. package/tests/terminal-input-preview.test.ts +1 -1
  185. package/tests/text-transform.test.ts +272 -0
  186. package/tests/timeline.test.ts +1 -1
  187. package/tests/tool-clock.test.ts +1 -1
  188. package/tests/tool-diff.test.ts +1 -1
  189. package/tests/waiting-clock.test.ts +1 -1
  190. package/tests/word-timeline.test.ts +1 -1
@@ -2,6 +2,7 @@ import { useCallback, useContext, useEffect, useLayoutEffect, useRef, useState }
2
2
  import type { ReactNode, RefObject } from 'react';
3
3
  import css from './Reader.module.css';
4
4
  import { StreamMotionContext } from './streaming.js';
5
+ import { reconcileTurnSlots, type TurnSlot } from './turn-slots.js';
5
6
 
6
7
  const EASING = 'cubic-bezier(.22,1,.36,1)';
7
8
 
@@ -16,7 +17,7 @@ export function useMotionAllowed(enabled: boolean): boolean {
16
17
  return enabled && !reduced;
17
18
  }
18
19
 
19
- export function usePinnedSelection(root: RefObject<HTMLElement>, selector = '[data-reader-answer], [data-reader-process]'): readonly string[] {
20
+ export function usePinnedSelection(root: RefObject<HTMLElement>, selector = '[data-reader-answer], [data-reader-body], [data-reader-process]'): readonly string[] {
20
21
  const [keys, setKeys] = useState<readonly string[]>([]);
21
22
  useEffect(() => {
22
23
  const update = () => {
@@ -89,7 +90,7 @@ export function StatusText({ text, motion, shimmer = false }: { text: string; mo
89
90
 
90
91
  export function Disclosure({ open, onChange, label, controls, buttonRef, ariaLabel }: {
91
92
  open: boolean; onChange: (value: boolean) => void; label: ReactNode;
92
- controls?: string; buttonRef: RefObject<HTMLButtonElement>;
93
+ controls?: string; buttonRef?: RefObject<HTMLButtonElement>;
93
94
  ariaLabel?: string;
94
95
  }) {
95
96
  const name = ariaLabel ?? '思考与过程';
@@ -170,12 +171,16 @@ export function ProcessFragment({ open, motion, onRead, returnFocusTo, nodeKey,
170
171
  }
171
172
 
172
173
  /** Retire only narration that was actually visible; historical rows stay folded. */
173
- export function RetiringContent({ visible, children }: { visible: boolean; children: ReactNode }) {
174
+ export function RetiringContent({ visible, children, onRetired }: { visible: boolean; children: ReactNode; onRetired?: () => void }) {
174
175
  const { enabled } = useContext(StreamMotionContext);
175
176
  const root = useRef<HTMLDivElement>(null);
176
177
  const animation = useRef<Animation | null>(null);
177
178
  const [present, setPresent] = useState(visible);
178
179
  const [focusHeld, setFocusHeld] = useState(false);
180
+ // Held in a ref so a caller passing an inline closure does not restart the
181
+ // collapse every render, and so the settle path always sees the latest one.
182
+ const retired = useRef(onRetired);
183
+ retired.current = onRetired;
179
184
  useLayoutEffect(() => {
180
185
  const element = root.current;
181
186
  if (visible) {
@@ -184,18 +189,49 @@ export function RetiringContent({ visible, children }: { visible: boolean; child
184
189
  return;
185
190
  }
186
191
  if (!element) return;
187
- if (element.contains(document.activeElement)) { setFocusHeld(true); return; }
188
- if (focusHeld) return;
192
+ // Reduced motion and a hidden page settle immediately. Focus may defer a
193
+ // collapse that will actually play; it must not pin a reduced-motion rewind.
194
+ // Move it to a surviving turn or the reading column first, or the browser
195
+ // drops it on the document when this subtree unmounts.
196
+ let retiredNow = false;
197
+ const retireNow = () => {
198
+ if (retiredNow) return;
199
+ retiredNow = true;
200
+ animation.current?.cancel(); animation.current = null;
201
+ focusSurvivesRetire(element);
202
+ setPresent(false); retired.current?.();
203
+ };
204
+ if (!enabled || document.hidden) { retireNow(); return; }
205
+ // The retiring-content harness stubs document without addEventListener.
206
+ const canListen = typeof document.addEventListener === 'function';
207
+ const holdsFocus = element.contains(document.activeElement);
208
+ if (holdsFocus || focusHeld) {
209
+ if (holdsFocus) setFocusHeld(true);
210
+ // Focus defers only a collapse that will play. `document.hidden` is not
211
+ // state, so a page hidden while focus waits must retire from here.
212
+ const onHiddenWhileHeld = () => { if (document.hidden) retireNow(); };
213
+ if (canListen) document.addEventListener('visibilitychange', onHiddenWhileHeld);
214
+ return () => { if (canListen) document.removeEventListener('visibilitychange', onHiddenWhileHeld); };
215
+ }
189
216
  const from = element.getBoundingClientRect().height;
190
217
  animation.current?.cancel(); animation.current = null;
191
- if (!enabled || from < 1) { setPresent(false); return; }
218
+ if (from < 1) { setPresent(false); retired.current?.(); return; }
192
219
  const next = element.animate([{ height: `${from}px`, opacity: 1 }, { height: '0px', opacity: 0 }], { duration: 220, easing: EASING, fill: 'both' });
193
220
  animation.current = next;
194
- const settle = () => { if (animation.current === next) { animation.current = null; next.cancel(); setPresent(false); } };
221
+ let settled = false;
222
+ const settle = () => {
223
+ if (settled || animation.current !== next) return;
224
+ settled = true;
225
+ animation.current = null; next.cancel(); setPresent(false); retired.current?.();
226
+ };
195
227
  next.onfinish = settle;
228
+ // #60: a stalled WAAPI finish must not leave the row mounted.
196
229
  const deadline = window.setTimeout(settle, 220 + 240);
230
+ const onHide = () => { if (document.hidden) settle(); };
231
+ if (canListen) document.addEventListener('visibilitychange', onHide);
197
232
  return () => {
198
233
  window.clearTimeout(deadline);
234
+ if (canListen) document.removeEventListener('visibilitychange', onHide);
199
235
  if (animation.current === next) animation.current = null;
200
236
  next.cancel();
201
237
  };
@@ -208,6 +244,98 @@ export function RetiringContent({ visible, children }: { visible: boolean; child
208
244
  </div>;
209
245
  }
210
246
 
247
+ /**
248
+ * Keeps a departing turn mounted for the length of its own collapse.
249
+ *
250
+ * A rewind removes turns from the visible order, and unmounting them outright
251
+ * snapped the transcript: every withdrawn row disappeared in one frame with
252
+ * nothing to scroll. Instead each departing turn is retained, rendered with
253
+ * `visible={false}` so it animates to zero height, and released only once the
254
+ * collapse has settled — so the reader watches the rows fold away and the rows
255
+ * below glide up into their place.
256
+ *
257
+ * Live slots follow the incoming group order, so older history stays above the
258
+ * tail. A collapsing turn stays next to the live neighbour that preceded it;
259
+ * appending it would jump it to the bottom for the length of the animation.
260
+ * Retention is bounded by the animation itself: `onRetired`
261
+ * drops the slot, so a departing turn lives for one collapse and no longer —
262
+ * and a key that comes back later is re-added as a live slot.
263
+ */
264
+ export function RetiringTurns<T extends { readonly key: string }>({ groups, render }: {
265
+ groups: readonly T[];
266
+ render: (group: T) => ReactNode;
267
+ }) {
268
+ const [slots, setSlots] = useState<readonly TurnSlot<T>[]>(() =>
269
+ groups.map((group) => ({ group, live: true })),
270
+ );
271
+ // Reconcile after every commit rather than during render: a key that left the
272
+ // order becomes `live: false` and keeps its index, which is what lets the
273
+ // collapse play in place instead of jumping the turn to the bottom.
274
+ useLayoutEffect(() => {
275
+ setSlots(current => reconcileTurnSlots(current, groups));
276
+ }, [groups]);
277
+ return (
278
+ <>
279
+ {slots.map((slot) => (
280
+ <RetiringContent
281
+ key={slot.group.key}
282
+ visible={slot.live}
283
+ onRetired={() => setSlots((current) => current.filter((candidate) =>
284
+ candidate.live || candidate.group.key !== slot.group.key))}
285
+ >
286
+ {render(slot.group)}
287
+ </RetiringContent>
288
+ ))}
289
+ </>
290
+ );
291
+ }
292
+
293
+ /** A turn that is still on screen, not one this commit is about to unmount. */
294
+ function survivingTurn(node: Element): HTMLElement | null {
295
+ if (!(node instanceof HTMLElement) || node.dataset.readerRetiring === 'retiring') return null;
296
+ const turn = node.hasAttribute('data-reader-turn') ? node : node.querySelector<HTMLElement>('[data-reader-turn]');
297
+ if (turn === null) return null;
298
+ const retiring = turn.closest('[data-reader-retiring]');
299
+ if (retiring instanceof HTMLElement && retiring.dataset.readerRetiring === 'retiring') return null;
300
+ return turn;
301
+ }
302
+
303
+ /**
304
+ * Where focus goes when cut content is removed without an animation.
305
+ * Prefer the nearest turn that is still live. Otherwise the reading column
306
+ * (or the host scrollport) so focus does not fall through to the document.
307
+ */
308
+ function retireFocusTarget(element: HTMLElement): HTMLElement | null {
309
+ const parent = element.parentElement;
310
+ if (parent) {
311
+ const siblings = [...parent.children];
312
+ const index = siblings.indexOf(element);
313
+ for (let cursor = index - 1; cursor >= 0; cursor--) {
314
+ const turn = survivingTurn(siblings[cursor]!);
315
+ if (turn) return turn;
316
+ }
317
+ for (let cursor = index + 1; cursor < siblings.length; cursor++) {
318
+ const turn = survivingTurn(siblings[cursor]!);
319
+ if (turn) return turn;
320
+ }
321
+ }
322
+ const column = element.closest<HTMLElement>('[data-chat-flow]');
323
+ if (column && !element.contains(column)) return column;
324
+ const scroll = element.closest<HTMLElement>('[data-conversation-scroll]');
325
+ if (scroll && !element.contains(scroll)) return scroll;
326
+ return null;
327
+ }
328
+
329
+ /** Move focus out of `element` before it unmounts. A no-op when focus is elsewhere. */
330
+ function focusSurvivesRetire(element: HTMLElement): void {
331
+ const active = document.activeElement;
332
+ if (active === null || !element.contains(active)) return;
333
+ const target = retireFocusTarget(element);
334
+ if (target === null || element.contains(target)) return;
335
+ if (target.tabIndex < 0) target.tabIndex = -1;
336
+ target.focus({ preventScroll: true });
337
+ }
338
+
211
339
  // DOM-only behavior: the native Session remains the sole source of business data.
212
340
  export function useReadingScroll(root: RefObject<HTMLElement>, motion: boolean): {
213
341
  detached: boolean;
@@ -1,5 +1,6 @@
1
- import { createElement, memo, useMemo, type ComponentType, type ReactNode } from 'react';
1
+ import { createElement, memo, useEffect, useLayoutEffect, useMemo, useRef, type ComponentType, type ReactNode, type RefObject } from 'react';
2
2
  import type { Context } from '@deepseek-ai/cordis';
3
+ import type { UseGroupAction } from '@deepseek-ai/dsh-client-ui-chat/client';
3
4
  import type { SlotEntryDef, SlotMap, SlotSpec, StoredEntry } from '@deepseek-ai/dsh-client-ui-slots';
4
5
  import type {} from '@deepseek-ai/dsh-client-ui-renderer/client';
5
6
 
@@ -18,7 +19,8 @@ export const OFFICIAL_SLOTS = {
18
19
  tools: 'tool.call.toolview',
19
20
  tail: 'conversation.chat.turnTail',
20
21
  nodes: 'conversation.chat.node',
21
- images: 'conversation.message.images',
22
+ messageImages: 'conversation.chat.message.images',
23
+ userImages: 'conversation.chat.user.images',
22
24
  } as const;
23
25
  export type OfficialFamily = keyof typeof OFFICIAL_SLOTS;
24
26
  export const OFFICIAL_SEATS = {
@@ -26,7 +28,8 @@ export const OFFICIAL_SEATS = {
26
28
  tools: 'dsh-better-display.official.tools/tool.call.toolview',
27
29
  tail: 'dsh-better-display.official.tail/conversation.chat.turnTail',
28
30
  nodes: 'dsh-better-display.official.nodes/conversation.chat.node',
29
- images: 'dsh-better-display.official.images/conversation.message.images',
31
+ messageImages: 'dsh-better-display.official.messageImages/conversation.chat.message.images',
32
+ userImages: 'dsh-better-display.official.userImages/conversation.chat.user.images',
30
33
  } as const;
31
34
  export type OfficialSeat = typeof OFFICIAL_SEATS[OfficialFamily];
32
35
  export const officialSeat = (family: OfficialFamily, source: string = OFFICIAL_SLOTS[family]) =>
@@ -52,22 +55,68 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
52
55
  'dsh-better-display.official.tools/tool.call.toolview': SlotMap['tool.call.toolview'];
53
56
  'dsh-better-display.official.tail/conversation.chat.turnTail': SlotMap['conversation.chat.turnTail'];
54
57
  'dsh-better-display.official.nodes/conversation.chat.node': SlotMap['conversation.chat.node'];
55
- 'dsh-better-display.official.images/conversation.message.images': SlotMap['conversation.message.images'];
58
+ 'dsh-better-display.official.messageImages/conversation.chat.message.images': SlotMap['conversation.chat.message.images'];
59
+ 'dsh-better-display.official.userImages/conversation.chat.user.images': SlotMap['conversation.chat.user.images'];
56
60
  }
57
61
  }
58
62
 
59
- // Existing Reader presentations own these rows. All other node kinds, including
60
- // future registrations, reach the official renderer through the mirror seat.
61
- // 'user' and 'steering' are mirrored too, so third-party renderers registered
62
- // on the official node slot (e.g. message-recall buttons) keep working inside
63
- // the Reader instead of being silently dropped.
64
- const READER_OWNED_NODES = new Set(['assistant-step', 'tool-call', 'turn-tail', 'turn-process']);
63
+ /**
64
+ * Searchable hide for official nodes drawn outside the Chat flow viewport.
65
+ * The flow's own `useGroupAction` is not in scope here; this keeps the same
66
+ * `hidden="until-found"` contract so browser find can still reveal the row.
67
+ */
68
+ export function useReaderGroupAction(hidden: boolean, reveal: () => void): RefObject<HTMLDivElement> {
69
+ const ref = useRef<HTMLDivElement>(null);
70
+ useLayoutEffect(() => {
71
+ const element = ref.current;
72
+ if (element === null) return;
73
+ if (hidden && element.contains(element.ownerDocument.activeElement)) {
74
+ reveal();
75
+ return;
76
+ }
77
+ if (hidden) element.setAttribute('hidden', 'until-found');
78
+ else element.removeAttribute('hidden');
79
+ }, [hidden, reveal]);
80
+ useEffect(() => {
81
+ const element = ref.current;
82
+ if (element === null) return;
83
+ element.addEventListener('beforematch', reveal);
84
+ return () => { element.removeEventListener('beforematch', reveal); };
85
+ }, [reveal]);
86
+ return ref;
87
+ }
88
+
89
+ export const readerGroupAction: UseGroupAction = useReaderGroupAction;
90
+
91
+ // Reader draws these rows itself. Everything else, including future kinds, is
92
+ // mirrored so the official renderer still runs inside the reading view.
93
+ // 'user' and 'steering' stay mirrored (message-recall buttons and the like).
94
+ // 'assistant-step' is special: the official renderer is priority 0 and Reader
95
+ // keeps that presentation. A strictly lower priority is a keyed-slot
96
+ // replacement (lowest priority renders) and is mirrored for body content.
97
+ const READER_OWNED_NODES = new Set(['tool-call', 'turn-tail', 'turn-process']);
98
+
99
+ /** Official `AssistantNodeView` registers at priority 0. Lower wins. */
100
+ export const OFFICIAL_ASSISTANT_PRIORITY = 0;
101
+
102
+ /**
103
+ * Mirror a chat-node registration into the Reader seat.
104
+ * Assistant replacements are the entries that would actually replace the
105
+ * official renderer on the host. The official priority itself stays out, so
106
+ * Reader keeps its own answer markdown until a plugin opts in.
107
+ */
108
+ export function acceptMirroredChatNode(entry: StoredEntry): boolean {
109
+ const key = entry.options.key ?? '';
110
+ if (key === 'assistant-step') return (entry.options.priority ?? OFFICIAL_ASSISTANT_PRIORITY) < OFFICIAL_ASSISTANT_PRIORITY;
111
+ return !READER_OWNED_NODES.has(key);
112
+ }
65
113
  const EXPECTED: Record<OfficialFamily, Spec> = {
66
114
  actions: { kind: 'list', scope: 'session' },
67
115
  tools: { kind: 'keyed', scope: 'session' },
68
116
  tail: { kind: 'list', scope: 'session' },
69
117
  nodes: { kind: 'keyed', scope: 'session' },
70
- images: { kind: 'single', scope: 'session' },
118
+ messageImages: { kind: 'single', scope: 'session' },
119
+ userImages: { kind: 'single', scope: 'session' },
71
120
  };
72
121
 
73
122
  /**
@@ -201,7 +250,7 @@ export function installOfficialSlots(ctx: Context): () => void {
201
250
  throw new Error(`Official slot contract changed: ${source}`);
202
251
  }
203
252
  return mirrorOfficialSlot(slots, source, target, `dsh-better-display.official.${family}`,
204
- family === 'nodes' ? entry => !READER_OWNED_NODES.has(entry.options.key ?? '') : undefined);
253
+ family === 'nodes' ? acceptMirroredChatNode : undefined);
205
254
  }));
206
255
  }
207
256
  } catch (error) {
@@ -21,6 +21,7 @@ export const readBlockLabels: ReadBlockLabels = {
21
21
  };
22
22
 
23
23
  export const terminalBlockLabels: TerminalBlockLabels = {
24
+ commandLine: line => `命令第 ${line} 行`,
24
25
  signal: signal => `信号 ${signal}`, exitCode: code => `退出码 ${code}`, noExitCode: '无退出码',
25
26
  running: '执行中', failed: '失败', done: '已完成', copy: '复制', copied: '已复制',
26
27
  noOutput: '没有输出', collapseAria: '收起命令输出', collapse: '收起',
@@ -33,6 +33,13 @@ export function boundaryOf(turn: TurnLocation | undefined): TurnBoundary {
33
33
  };
34
34
  }
35
35
 
36
+ /**
37
+ * A settled body step before the closing step of a successful turn.
38
+ *
39
+ * This is presentation classification only. Narration is never process content
40
+ * and never folds. The flag only marks body text that is no longer the turn's
41
+ * final answer, so copy and fork stay on that final answer.
42
+ */
36
43
  export function isEarlierNarration(data: AssistantChatData, boundary: TurnBoundary): boolean {
37
44
  // New body text, a tool call, or a settled step is not a completed turn.
38
45
  if (data.status !== 'settled' || boundary.status !== 'closed' || boundary.reason !== 'completed') return false;
@@ -49,13 +56,18 @@ export function processChoiceKey(groupKey: string, boundary: TurnBoundary): stri
49
56
  return `${groupKey}:${boundary.status}:${boundary.reason ?? 'pending'}`;
50
57
  }
51
58
 
52
- /** A body-only assistant step is not a thinking/process disclosure. */
53
- export function hasProcessContent(node: ChatConversationViewNode | undefined, boundary: TurnBoundary): boolean {
59
+ /**
60
+ * A body-only assistant step is not a thinking/process disclosure.
61
+ *
62
+ * Narration (text/image/other blocks) is always visible, so it never counts as
63
+ * foldable process content; only literal reasoning does. Tool calls arrive as
64
+ * their own flow entries and are checked separately by the reader.
65
+ */
66
+ export function hasProcessContent(node: ChatConversationViewNode | undefined, _boundary: TurnBoundary): boolean {
54
67
  if (!node || node.visibility === 'hidden') return false;
55
68
  if (node.kind === 'assistant-step') {
56
69
  const data = node.data as AssistantChatData;
57
- return data.blocks.some(block => block.kind === 'reasoning' && block.text.trim() !== '')
58
- || (isEarlierNarration(data, boundary) && hasVisibleBody(data.blocks));
70
+ return data.blocks.some(block => block.kind === 'reasoning' && block.text.trim() !== '');
59
71
  }
60
72
  return node.kind === 'context' || node.kind === 'model-retry' || node.kind === 'system-prompt' || node.kind === 'turn-process'
61
73
  || node.kind === 'command' || node.kind === 'manual-compaction' || node.kind === 'compaction';