dsh-better-display 0.3.8 → 0.3.9

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 (182) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/DESIGN.md +43 -3
  3. package/README.en.md +9 -1
  4. package/README.md +9 -1
  5. package/docs/dependency-update-policy.md +9 -0
  6. package/docs/extension-points.md +172 -0
  7. package/docs/official-rendering-bridge.md +48 -19
  8. package/docs/openapi.yaml +147 -0
  9. package/docs/runbooks/blank-reader.md +39 -0
  10. package/lib/client.js +1417 -490
  11. package/lib/client.js.map +1 -1
  12. package/lib/dsh-better-display.js +378 -144
  13. package/lib/types/client/AssistantNode.d.ts +20 -0
  14. package/lib/types/client/AssistantNode.d.ts.map +1 -0
  15. package/lib/types/client/AssistantNode.js +46 -0
  16. package/lib/types/client/AssistantNode.js.map +1 -0
  17. package/lib/types/client/Blocks.d.ts.map +1 -1
  18. package/lib/types/client/Blocks.js +33 -10
  19. package/lib/types/client/Blocks.js.map +1 -1
  20. package/lib/types/client/ChoreographedFlow.d.ts.map +1 -1
  21. package/lib/types/client/ChoreographedFlow.js +2 -0
  22. package/lib/types/client/ChoreographedFlow.js.map +1 -1
  23. package/lib/types/client/ClosedProcessSummary.d.ts.map +1 -1
  24. package/lib/types/client/ClosedProcessSummary.js +3 -1
  25. package/lib/types/client/ClosedProcessSummary.js.map +1 -1
  26. package/lib/types/client/McpAppFrame.d.ts.map +1 -1
  27. package/lib/types/client/McpAppFrame.js +5 -11
  28. package/lib/types/client/McpAppFrame.js.map +1 -1
  29. package/lib/types/client/OfficialContent.d.ts +17 -3
  30. package/lib/types/client/OfficialContent.d.ts.map +1 -1
  31. package/lib/types/client/OfficialContent.js +33 -7
  32. package/lib/types/client/OfficialContent.js.map +1 -1
  33. package/lib/types/client/Reader.d.ts.map +1 -1
  34. package/lib/types/client/Reader.js +43 -71
  35. package/lib/types/client/Reader.js.map +1 -1
  36. package/lib/types/client/SettingsSection.d.ts.map +1 -1
  37. package/lib/types/client/SettingsSection.js +0 -5
  38. package/lib/types/client/SettingsSection.js.map +1 -1
  39. package/lib/types/client/StickyLane.d.ts +12 -0
  40. package/lib/types/client/StickyLane.d.ts.map +1 -1
  41. package/lib/types/client/StickyLane.js +78 -2
  42. package/lib/types/client/StickyLane.js.map +1 -1
  43. package/lib/types/client/ToolActivity.js.map +1 -1
  44. package/lib/types/client/index.d.ts +3 -1
  45. package/lib/types/client/index.d.ts.map +1 -1
  46. package/lib/types/client/index.js +6 -0
  47. package/lib/types/client/index.js.map +1 -1
  48. package/lib/types/client/live-turn.d.ts +17 -5
  49. package/lib/types/client/live-turn.d.ts.map +1 -1
  50. package/lib/types/client/live-turn.js +106 -76
  51. package/lib/types/client/live-turn.js.map +1 -1
  52. package/lib/types/client/motion.d.ts +26 -2
  53. package/lib/types/client/motion.d.ts.map +1 -1
  54. package/lib/types/client/motion.js +136 -10
  55. package/lib/types/client/motion.js.map +1 -1
  56. package/lib/types/client/official-slots.d.ts +9 -0
  57. package/lib/types/client/official-slots.d.ts.map +1 -1
  58. package/lib/types/client/official-slots.js +22 -7
  59. package/lib/types/client/official-slots.js.map +1 -1
  60. package/lib/types/client/projection.d.ts +15 -2
  61. package/lib/types/client/projection.d.ts.map +1 -1
  62. package/lib/types/client/projection.js +16 -4
  63. package/lib/types/client/projection.js.map +1 -1
  64. package/lib/types/client/rewind-cut.d.ts +131 -0
  65. package/lib/types/client/rewind-cut.d.ts.map +1 -0
  66. package/lib/types/client/rewind-cut.js +321 -0
  67. package/lib/types/client/rewind-cut.js.map +1 -0
  68. package/lib/types/client/text-transform.d.ts +93 -0
  69. package/lib/types/client/text-transform.d.ts.map +1 -0
  70. package/lib/types/client/text-transform.js +183 -0
  71. package/lib/types/client/text-transform.js.map +1 -0
  72. package/lib/types/client/timeline.d.ts.map +1 -1
  73. package/lib/types/client/timeline.js.map +1 -1
  74. package/lib/types/client/tool-activity.d.ts +9 -2
  75. package/lib/types/client/tool-activity.d.ts.map +1 -1
  76. package/lib/types/client/tool-activity.js +42 -2
  77. package/lib/types/client/tool-activity.js.map +1 -1
  78. package/lib/types/client/turn-slots.d.ts +29 -0
  79. package/lib/types/client/turn-slots.d.ts.map +1 -0
  80. package/lib/types/client/turn-slots.js +62 -0
  81. package/lib/types/client/turn-slots.js.map +1 -0
  82. package/lib/types/client/types.d.ts +18 -0
  83. package/lib/types/client/types.d.ts.map +1 -1
  84. package/lib/types/dsh-better-display.d.ts +4 -1
  85. package/lib/types/dsh-better-display.d.ts.map +1 -1
  86. package/lib/types/dsh-better-display.js +56 -7
  87. package/lib/types/dsh-better-display.js.map +1 -1
  88. package/lib/types/flags.d.ts +7 -0
  89. package/lib/types/flags.d.ts.map +1 -0
  90. package/lib/types/flags.js +37 -0
  91. package/lib/types/flags.js.map +1 -0
  92. package/lib/types/log.d.ts +17 -0
  93. package/lib/types/log.d.ts.map +1 -0
  94. package/lib/types/log.js +122 -0
  95. package/lib/types/log.js.map +1 -0
  96. package/lib/types/metrics.d.ts +18 -0
  97. package/lib/types/metrics.d.ts.map +1 -0
  98. package/lib/types/metrics.js +35 -0
  99. package/lib/types/metrics.js.map +1 -0
  100. package/package.json +36 -5
  101. package/scripts/changelog.mjs +20 -0
  102. package/scripts/check-agents-md.mjs +67 -0
  103. package/scripts/check-bundle-size.mjs +38 -0
  104. package/scripts/check-dead-flags.mjs +55 -0
  105. package/scripts/check-todo-debt.mjs +69 -0
  106. package/scripts/security-audit-report.mjs +92 -0
  107. package/scripts/verify-commentary-visible.mjs +627 -0
  108. package/src/client/AssistantNode.tsx +72 -0
  109. package/src/client/Blocks.tsx +49 -10
  110. package/src/client/ChoreographedFlow.tsx +3 -1
  111. package/src/client/ClosedProcessSummary.tsx +3 -1
  112. package/src/client/McpAppFrame.tsx +5 -13
  113. package/src/client/OfficialContent.tsx +47 -9
  114. package/src/client/Reader.module.css +68 -18
  115. package/src/client/Reader.tsx +36 -76
  116. package/src/client/SettingsSection.tsx +1 -7
  117. package/src/client/StickyLane.tsx +81 -2
  118. package/src/client/ToolActivity.tsx +1 -1
  119. package/src/client/index.tsx +8 -1
  120. package/src/client/live-turn.ts +100 -69
  121. package/src/client/motion.tsx +135 -7
  122. package/src/client/official-slots.tsx +23 -7
  123. package/src/client/projection.ts +16 -4
  124. package/src/client/rewind-cut.ts +340 -0
  125. package/src/client/text-transform.ts +265 -0
  126. package/src/client/timeline.ts +0 -2
  127. package/src/client/tool-activity.ts +49 -2
  128. package/src/client/turn-slots.ts +80 -0
  129. package/src/client/types.ts +19 -0
  130. package/src/dsh-better-display.ts +58 -7
  131. package/src/flags.ts +40 -0
  132. package/src/log.ts +137 -0
  133. package/src/metrics.ts +50 -0
  134. package/tests/browser-commentary.tsx +191 -0
  135. package/tests/chat-flow-hook.test.ts +1 -1
  136. package/tests/cloud-gate.test.ts +1 -1
  137. package/tests/context-tool-update.test.ts +1 -1
  138. package/tests/conversation-scroll.test.ts +1 -1
  139. package/tests/deliverables.test.ts +1 -1
  140. package/tests/entry.test.ts +1 -1
  141. package/tests/fixtures/reader-lane-owners.tsx +46 -0
  142. package/tests/fixtures/reader-official-users.tsx +64 -0
  143. package/tests/fixtures/reader-theme-overlap.html +80 -0
  144. package/tests/fixtures/reader-user-bubble.tsx +222 -0
  145. package/tests/flags.test.ts +66 -0
  146. package/tests/fold-choreography.test.ts +32 -8
  147. package/tests/fold-intensity.test.ts +11 -6
  148. package/tests/footer-precedence.test.ts +1 -1
  149. package/tests/history-word-regression.test.ts +1 -1
  150. package/tests/live-turn.test.ts +125 -54
  151. package/tests/log.test.ts +99 -0
  152. package/tests/mcp-apps.test.ts +1 -1
  153. package/tests/message-chrome.test.ts +1 -1
  154. package/tests/metrics.test.ts +52 -0
  155. package/tests/official-slots.test.ts +41 -2
  156. package/tests/open-file.test.ts +1 -1
  157. package/tests/pending-submission.test.ts +12 -1
  158. package/tests/pinned-selection.test.ts +16 -0
  159. package/tests/platform-media.test.ts +1 -1
  160. package/tests/projection.test.ts +66 -3
  161. package/tests/reader-glass-css.test.ts +1 -1
  162. package/tests/reader-official-users.test.ts +11 -1
  163. package/tests/reader-sticky-surface.test.ts +377 -0
  164. package/tests/reader-theme-lanes.test.ts +54 -0
  165. package/tests/reader-theme-overlap.test.ts +151 -0
  166. package/tests/reader-user-bubble.test.ts +137 -0
  167. package/tests/reasoning-follow.test.ts +1 -1
  168. package/tests/retiring-content.test.ts +98 -6
  169. package/tests/reveal.test.ts +3 -3
  170. package/tests/rewind-cut.test.ts +1090 -0
  171. package/tests/settings-copy.test.ts +1 -1
  172. package/tests/skill-status.test.ts +1 -1
  173. package/tests/stock-install.test.ts +1 -1
  174. package/tests/stream-buffer.test.ts +1 -1
  175. package/tests/styles.test.ts +30 -3
  176. package/tests/terminal-input-preview.test.ts +1 -1
  177. package/tests/text-transform.test.ts +272 -0
  178. package/tests/timeline.test.ts +1 -1
  179. package/tests/tool-clock.test.ts +1 -1
  180. package/tests/tool-diff.test.ts +1 -1
  181. package/tests/waiting-clock.test.ts +1 -1
  182. package/tests/word-timeline.test.ts +1 -1
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Which chat rows a `/rewind` withdrew, expressed as a pure function of the
3
+ * chat snapshot.
4
+ *
5
+ * WHY THIS EXISTS. A rewind never deletes history: the host appends one
6
+ * replacement `user/message` marker whose `surfaceOp` shadows everything after
7
+ * the target, and the transcript must then read as it did *before* the target
8
+ * was sent. The official ChatView is a per-node renderer, so the rewind plugin
9
+ * (`dsh-rewind-plugin`) hides withdrawn rows by DOM: it computes the shadowed
10
+ * anchor seqs from the command node and sets `display:none` on every element
11
+ * carrying the official `data-chat-anchor-key` seat attribute.
12
+ *
13
+ * The Reader replaces ChatView's message list and renders its own row shapes
14
+ * (turn sections, answer articles, tool rows), so it does not republish that
15
+ * seat attribute on every row. DOM hiding therefore reaches only the user and
16
+ * steering bubbles, and every other withdrawn row — the answer, the tool rows,
17
+ * and the `/rewind` command row itself — stayed on screen. That is the reported
18
+ * defect: the command is recorded as a rewind row instead of the Reader rolling
19
+ * back to the state before the message was sent.
20
+ *
21
+ * The Reader decides visibility from React state, so it must apply the same
22
+ * contract itself instead of waiting for a third-party MutationObserver. The
23
+ * marker node is not admitted as a chat node (only append-origin surface events
24
+ * become nodes), so the command node's `outcome.sourceEventSeq` — the marker's
25
+ * log seq — plus the `@<seq>` target in its `args` are the only client-side
26
+ * signal for the shadowed range. This mirrors the plugin's own reader of that
27
+ * contract, and is pinned by `tests/rewind-cut.test.ts` so a plugin or host
28
+ * change cannot silently regress it.
29
+ *
30
+ * @module dsh-better-display/rewind-cut
31
+ */
32
+ /** A chat-snapshot view node, read structurally (only the fields this module needs). */
33
+ export interface CutChatNode {
34
+ readonly key: string;
35
+ readonly kind?: string;
36
+ readonly anchorSeq?: number;
37
+ readonly visibility?: string;
38
+ readonly data?: unknown;
39
+ /**
40
+ * Where the host placed the node in the session's location index. Only the
41
+ * owning turn is read from it, and an absent or foreign location is fine.
42
+ */
43
+ readonly location?: unknown;
44
+ }
45
+ /** The minimal chat-snapshot reader the cut logic needs. */
46
+ export interface CutChat {
47
+ readonly order: readonly string[];
48
+ readonly nodes: {
49
+ get(key: string): CutChatNode | undefined;
50
+ };
51
+ }
52
+ /** One closed shadow range `[start, end]` in surface/anchor seq space. */
53
+ export interface CutSpan {
54
+ readonly start: number;
55
+ readonly end: number;
56
+ }
57
+ /**
58
+ * The render POSITION a row is anchored at: the view node's `anchorSeq`, else
59
+ * its payload seq.
60
+ *
61
+ * This is deliberately NOT integer-only. The host anchors synthetic rows at
62
+ * fractional offsets off a real seq (`CHAT_SYNTHETIC_SEQ_OFFSETS` in the
63
+ * official ChatView: `turn-process` at `controlAnchorSeq - 0.1`, `turn-tail` at
64
+ * `seq + 0.1`, an interrupted assistant step at `seq - 0.9`). An integer-only
65
+ * read made those rows invisible to the cut, so the last `turn-process` of a
66
+ * withdrawn turn survived on its own. Log seqs (marker, target) stay integer:
67
+ * see `safeSeq`.
68
+ */
69
+ export declare function anchorSeqOf(node: CutChatNode): number | undefined;
70
+ /**
71
+ * Extract the rewind target seq from a `/rewind` command's structured `args`
72
+ * (e.g. `@5 chat`, `preview @5 both`). Locale-independent: it never parses the
73
+ * host's human outcome copy.
74
+ */
75
+ export declare function rewindTargetOfArgs(args: unknown): number | undefined;
76
+ /**
77
+ * Merge overlapping or touching shadow ranges.
78
+ *
79
+ * Spans are kept SEPARATE unless they genuinely overlap: collapsing every cut
80
+ * to `[min target, max marker]` would hide a still-on-surface gap of new traffic
81
+ * between an earlier marker and a later target.
82
+ */
83
+ export declare function coalesceCutSpans(spans: readonly CutSpan[]): CutSpan[];
84
+ /**
85
+ * True when a row anchored at `seq` falls inside one of the cut spans.
86
+ *
87
+ * A cut runs from the target seq through the marker's own log seq, inclusive
88
+ * (`target <= anchorSeq && anchorSeq <= marker`), the same comparison
89
+ * `dsh-rewind-plugin`'s `RewindVisibilityBuilder` uses. The upper bound stops
90
+ * at the marker. Extending it to the next integer hides the following turn's
91
+ * process row, which the host anchors at `startSeq - 0.1` and therefore in
92
+ * `[marker, marker + 1)`. Fractional anchors inside the closed range still
93
+ * match: `anchorSeqOf` keeps them. A process or tail row parked outside the
94
+ * range is handled by `summaryTurns`, not by widening the cut. Spans stay
95
+ * disjoint, so new traffic between two rewinds survives.
96
+ */
97
+ export declare function cutContains(cuts: readonly CutSpan[], seq: number): boolean;
98
+ /**
99
+ * The shadow ranges a session's executed rewinds produced, newest state last.
100
+ * An executed rewind cuts `[target, marker]` — the target itself is included,
101
+ * because a rewind restores the state *before* that message was sent (its text
102
+ * goes back to the composer).
103
+ */
104
+ export declare function rewindCutSpans(chat: CutChat | undefined): CutSpan[];
105
+ /**
106
+ * The anchor seqs the Reader must not render: every withdrawn message (the
107
+ * target, everything after it, and the unrendered marker), plus every `/rewind`
108
+ * row that exists only to feed the popover — the candidate-list probe and each
109
+ * impact preview. A SUCCESSFUL executed command row is covered by its own cut;
110
+ * a failed or unsettled one stays visible as an ordinary command record.
111
+ */
112
+ export declare function hiddenRewindSeqs(chat: CutChat | undefined): Set<number>;
113
+ /**
114
+ * The chat keys the Reader should render, in snapshot order: withdrawn rows and
115
+ * rows the host itself marked hidden are dropped, everything else keeps its
116
+ * position. Returns the snapshot's own `order` array when nothing is filtered,
117
+ * so React selectors see a stable reference.
118
+ */
119
+ export declare function visibleChatKeys(chat: CutChat): readonly string[];
120
+ /**
121
+ * A comparable signal for the visible row set, built for
122
+ * `useSyncExternalStore`-style subscription: the host re-runs a chat selector
123
+ * on every publish and compares the RESULT by `Object.is`, and a rewind
124
+ * publishes an in-place upsert of an existing command row. The snapshot's
125
+ * `order` array and node store are therefore both reference-stable across a
126
+ * rewind, so a selector on them never re-renders; a string does change exactly
127
+ * when the visible set does. Never return the array itself from a selector —
128
+ * a fresh array fails the `Object.is` check on every publish.
129
+ */
130
+ export declare function visibleChatSignature(chat: CutChat): string;
131
+ //# sourceMappingURL=rewind-cut.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rewind-cut.d.ts","sourceRoot":"","sources":["../../../src/client/rewind-cut.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,wFAAwF;AACxF,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,4DAA4D;AAC5D,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,QAAQ,CAAC,KAAK,EAAE;QACd,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;KAC3C,CAAC;CACH;AAED,0EAA0E;AAC1E,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;CACtB;AAkCD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAGjE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIpE;AAYD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,EAAE,CAarE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,OAAO,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAgB1E;AA4ED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,OAAO,EAAE,CAoBnE;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,GAAG,GAAG,CAAC,MAAM,CAAC,CAavE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,CAYhE;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAE1D"}
@@ -0,0 +1,321 @@
1
+ /**
2
+ * Which chat rows a `/rewind` withdrew, expressed as a pure function of the
3
+ * chat snapshot.
4
+ *
5
+ * WHY THIS EXISTS. A rewind never deletes history: the host appends one
6
+ * replacement `user/message` marker whose `surfaceOp` shadows everything after
7
+ * the target, and the transcript must then read as it did *before* the target
8
+ * was sent. The official ChatView is a per-node renderer, so the rewind plugin
9
+ * (`dsh-rewind-plugin`) hides withdrawn rows by DOM: it computes the shadowed
10
+ * anchor seqs from the command node and sets `display:none` on every element
11
+ * carrying the official `data-chat-anchor-key` seat attribute.
12
+ *
13
+ * The Reader replaces ChatView's message list and renders its own row shapes
14
+ * (turn sections, answer articles, tool rows), so it does not republish that
15
+ * seat attribute on every row. DOM hiding therefore reaches only the user and
16
+ * steering bubbles, and every other withdrawn row — the answer, the tool rows,
17
+ * and the `/rewind` command row itself — stayed on screen. That is the reported
18
+ * defect: the command is recorded as a rewind row instead of the Reader rolling
19
+ * back to the state before the message was sent.
20
+ *
21
+ * The Reader decides visibility from React state, so it must apply the same
22
+ * contract itself instead of waiting for a third-party MutationObserver. The
23
+ * marker node is not admitted as a chat node (only append-origin surface events
24
+ * become nodes), so the command node's `outcome.sourceEventSeq` — the marker's
25
+ * log seq — plus the `@<seq>` target in its `args` are the only client-side
26
+ * signal for the shadowed range. This mirrors the plugin's own reader of that
27
+ * contract, and is pinned by `tests/rewind-cut.test.ts` so a plugin or host
28
+ * change cannot silently regress it.
29
+ *
30
+ * @module dsh-better-display/rewind-cut
31
+ */
32
+ function asRecord(value) {
33
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
34
+ ? value
35
+ : undefined;
36
+ }
37
+ function safeSeq(value) {
38
+ return typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : undefined;
39
+ }
40
+ /** The command payload of a `command` chat node, when it is structurally readable. */
41
+ function commandOf(node) {
42
+ if (node.kind !== 'command')
43
+ return undefined;
44
+ return asRecord(node.data);
45
+ }
46
+ /**
47
+ * The engine names an executed rewind command node can carry. The plugin
48
+ * registers its command as `rewind-plugin` (`ENGINE_COMMANDS = new
49
+ * Set(['rewind-plugin', 'rewind'])` in dsh-rewind-plugin's
50
+ * `src/client/hidden.ts`), and that is the name the client projection actually
51
+ * publishes — the session log's `command/run.name` is not what the Reader sees.
52
+ * `rewind` stays accepted because older logs and the bili-side proxy record the
53
+ * shorter spelling.
54
+ */
55
+ const REWIND_COMMANDS = new Set(['rewind-plugin', 'rewind']);
56
+ /** True when a command payload is the rewind engine command, in either spelling. */
57
+ function isRewindCommand(command) {
58
+ return typeof command.name === 'string' && REWIND_COMMANDS.has(command.name);
59
+ }
60
+ /**
61
+ * The render POSITION a row is anchored at: the view node's `anchorSeq`, else
62
+ * its payload seq.
63
+ *
64
+ * This is deliberately NOT integer-only. The host anchors synthetic rows at
65
+ * fractional offsets off a real seq (`CHAT_SYNTHETIC_SEQ_OFFSETS` in the
66
+ * official ChatView: `turn-process` at `controlAnchorSeq - 0.1`, `turn-tail` at
67
+ * `seq + 0.1`, an interrupted assistant step at `seq - 0.9`). An integer-only
68
+ * read made those rows invisible to the cut, so the last `turn-process` of a
69
+ * withdrawn turn survived on its own. Log seqs (marker, target) stay integer:
70
+ * see `safeSeq`.
71
+ */
72
+ export function anchorSeqOf(node) {
73
+ const raw = node.anchorSeq ?? asRecord(node.data)?.seq;
74
+ return typeof raw === 'number' && Number.isFinite(raw) && raw >= 0 ? raw : undefined;
75
+ }
76
+ /**
77
+ * Extract the rewind target seq from a `/rewind` command's structured `args`
78
+ * (e.g. `@5 chat`, `preview @5 both`). Locale-independent: it never parses the
79
+ * host's human outcome copy.
80
+ */
81
+ export function rewindTargetOfArgs(args) {
82
+ if (typeof args !== 'string')
83
+ return undefined;
84
+ const match = args.match(/@(\d+)/);
85
+ return match === null ? undefined : Number(match[1]);
86
+ }
87
+ /** True for the internal candidate-list probe (`/rewind __candidates`). */
88
+ function isCandidateCommand(command) {
89
+ return typeof command.args === 'string' && command.args.includes('__candidates');
90
+ }
91
+ /** True for an impact preview (`/rewind preview @5 both`). */
92
+ function isPreviewCommand(command) {
93
+ return typeof command.args === 'string' && command.args.includes('preview');
94
+ }
95
+ /**
96
+ * Merge overlapping or touching shadow ranges.
97
+ *
98
+ * Spans are kept SEPARATE unless they genuinely overlap: collapsing every cut
99
+ * to `[min target, max marker]` would hide a still-on-surface gap of new traffic
100
+ * between an earlier marker and a later target.
101
+ */
102
+ export function coalesceCutSpans(spans) {
103
+ if (spans.length < 2)
104
+ return [...spans];
105
+ const sorted = [...spans].sort((left, right) => left.start - right.start || left.end - right.end);
106
+ const merged = [];
107
+ for (const span of sorted) {
108
+ const last = merged.at(-1);
109
+ if (last !== undefined && span.start <= last.end) {
110
+ if (span.end > last.end)
111
+ last.end = span.end;
112
+ continue;
113
+ }
114
+ merged.push({ start: span.start, end: span.end });
115
+ }
116
+ return merged;
117
+ }
118
+ /**
119
+ * True when a row anchored at `seq` falls inside one of the cut spans.
120
+ *
121
+ * A cut runs from the target seq through the marker's own log seq, inclusive
122
+ * (`target <= anchorSeq && anchorSeq <= marker`), the same comparison
123
+ * `dsh-rewind-plugin`'s `RewindVisibilityBuilder` uses. The upper bound stops
124
+ * at the marker. Extending it to the next integer hides the following turn's
125
+ * process row, which the host anchors at `startSeq - 0.1` and therefore in
126
+ * `[marker, marker + 1)`. Fractional anchors inside the closed range still
127
+ * match: `anchorSeqOf` keeps them. A process or tail row parked outside the
128
+ * range is handled by `summaryTurns`, not by widening the cut. Spans stay
129
+ * disjoint, so new traffic between two rewinds survives.
130
+ */
131
+ export function cutContains(cuts, seq) {
132
+ let low = 0;
133
+ let high = cuts.length - 1;
134
+ let found = -1;
135
+ while (low <= high) {
136
+ const middle = (low + high) >> 1;
137
+ const cut = cuts[middle];
138
+ if (cut === undefined)
139
+ return false;
140
+ if (seq < cut.start)
141
+ high = middle - 1;
142
+ else {
143
+ found = middle;
144
+ low = middle + 1;
145
+ }
146
+ }
147
+ const span = found < 0 ? undefined : cuts[found];
148
+ return span !== undefined && seq <= span.end;
149
+ }
150
+ /** The turn id a node belongs to (absent outside a turn). */
151
+ function turnIdOf(node) {
152
+ // The location's own `kind` varies (`turn` for a turn's synthetic rows,
153
+ // `step` for one of its messages); only the turn it carries matters here.
154
+ const turn = asRecord(asRecord(node.location)?.turn);
155
+ if (turn === undefined || !Object.hasOwn(turn, 'turn'))
156
+ return undefined;
157
+ return turn.turn;
158
+ }
159
+ /**
160
+ * Node kinds that SUMMARIZE a turn instead of carrying its content, so the host
161
+ * anchors them at the turn's edges rather than at an event inside it.
162
+ */
163
+ const TURN_SUMMARY_KINDS = new Set(['turn-process', 'turn-tail']);
164
+ /**
165
+ * True for a rewind command row the transcript should not keep.
166
+ *
167
+ * Probes (`preview`, `__candidates`) exist only to feed the popover. An
168
+ * executed rewind — success plus a marker seq — is the command that performed
169
+ * the cut, and the plugin hides that row even when its anchor sits outside
170
+ * the numeric range. A failed or still-running command stays visible.
171
+ */
172
+ function commandHidden(node) {
173
+ const command = commandOf(node);
174
+ if (command === undefined || !isRewindCommand(command))
175
+ return false;
176
+ if (isPreviewCommand(command) || isCandidateCommand(command))
177
+ return true;
178
+ const outcome = asRecord(command.outcome);
179
+ return outcome?.kind === 'success' && safeSeq(outcome.sourceEventSeq) !== undefined;
180
+ }
181
+ /** True when the row's own anchor falls in a cut, or the row is a rewind command to hide. */
182
+ function anchorWithdrawn(node, cuts) {
183
+ if (commandHidden(node))
184
+ return true;
185
+ const seq = anchorSeqOf(node);
186
+ return seq !== undefined && cutContains(cuts, seq);
187
+ }
188
+ /**
189
+ * Turns whose process and tail rows must leave.
190
+ *
191
+ * The host opens a turn before its user message is logged and anchors
192
+ * `turn-process` at `controlAnchorSeq - 0.1`, below the first withdrawn
193
+ * event, and `turn-tail` at `turn.end.seq + 0.1`, which can sit past the
194
+ * marker. Containment therefore misses those two rows, and the transcript
195
+ * kept announcing `执行过程 / 本轮已停止,已生成的内容仍保留。`
196
+ *
197
+ * A summary leaves only when every content row of its turn is already
198
+ * withdrawn — the same rule as the plugin's `deriveTurnProcess`. One content
199
+ * row before the target (a mid-turn steering rewind) keeps the summary and
200
+ * that earlier message. A turn with no content rows is left alone.
201
+ */
202
+ function summaryTurns(chat, cuts) {
203
+ const stays = new Map();
204
+ for (const key of chat.order) {
205
+ const node = chat.nodes.get(key);
206
+ if (node === undefined || TURN_SUMMARY_KINDS.has(node.kind ?? ''))
207
+ continue;
208
+ const id = turnIdOf(node);
209
+ if (id === undefined)
210
+ continue;
211
+ const visible = node.visibility !== 'hidden' && !anchorWithdrawn(node, cuts);
212
+ stays.set(id, (stays.get(id) ?? false) || visible);
213
+ }
214
+ const withdrawn = new Set();
215
+ for (const [id, visible] of stays)
216
+ if (!visible)
217
+ withdrawn.add(id);
218
+ return withdrawn;
219
+ }
220
+ /** True when this row is a summary of a turn whose content is fully withdrawn. */
221
+ function summaryWithdrawn(node, summaries) {
222
+ if (!TURN_SUMMARY_KINDS.has(node.kind ?? ''))
223
+ return false;
224
+ const id = turnIdOf(node);
225
+ return id !== undefined && summaries.has(id);
226
+ }
227
+ /**
228
+ * The shadow ranges a session's executed rewinds produced, newest state last.
229
+ * An executed rewind cuts `[target, marker]` — the target itself is included,
230
+ * because a rewind restores the state *before* that message was sent (its text
231
+ * goes back to the composer).
232
+ */
233
+ export function rewindCutSpans(chat) {
234
+ if (chat === undefined)
235
+ return [];
236
+ const spans = [];
237
+ for (const key of chat.order) {
238
+ const node = chat.nodes.get(key);
239
+ if (node === undefined)
240
+ continue;
241
+ const command = commandOf(node);
242
+ if (command === undefined || !isRewindCommand(command))
243
+ continue;
244
+ // Probes never open a span, even when a later host stamps them with a
245
+ // success marker. Matching them would roll the transcript back on preview.
246
+ if (isPreviewCommand(command) || isCandidateCommand(command))
247
+ continue;
248
+ const outcome = asRecord(command.outcome);
249
+ if (outcome?.kind !== 'success')
250
+ continue;
251
+ const marker = safeSeq(outcome.sourceEventSeq);
252
+ if (marker === undefined)
253
+ continue;
254
+ const target = rewindTargetOfArgs(command.args);
255
+ if (target === undefined || target > marker)
256
+ continue;
257
+ spans.push({ start: target, end: marker });
258
+ }
259
+ return coalesceCutSpans(spans);
260
+ }
261
+ /**
262
+ * The anchor seqs the Reader must not render: every withdrawn message (the
263
+ * target, everything after it, and the unrendered marker), plus every `/rewind`
264
+ * row that exists only to feed the popover — the candidate-list probe and each
265
+ * impact preview. A SUCCESSFUL executed command row is covered by its own cut;
266
+ * a failed or unsettled one stays visible as an ordinary command record.
267
+ */
268
+ export function hiddenRewindSeqs(chat) {
269
+ const hidden = new Set();
270
+ if (chat === undefined)
271
+ return hidden;
272
+ const cuts = rewindCutSpans(chat);
273
+ const summaries = summaryTurns(chat, cuts);
274
+ for (const key of chat.order) {
275
+ const node = chat.nodes.get(key);
276
+ if (node === undefined)
277
+ continue;
278
+ if (!anchorWithdrawn(node, cuts) && !summaryWithdrawn(node, summaries))
279
+ continue;
280
+ const seq = anchorSeqOf(node);
281
+ if (seq !== undefined)
282
+ hidden.add(seq);
283
+ }
284
+ return hidden;
285
+ }
286
+ /**
287
+ * The chat keys the Reader should render, in snapshot order: withdrawn rows and
288
+ * rows the host itself marked hidden are dropped, everything else keeps its
289
+ * position. Returns the snapshot's own `order` array when nothing is filtered,
290
+ * so React selectors see a stable reference.
291
+ */
292
+ export function visibleChatKeys(chat) {
293
+ const cuts = rewindCutSpans(chat);
294
+ const summaries = summaryTurns(chat, cuts);
295
+ const visible = [];
296
+ for (const key of chat.order) {
297
+ const node = chat.nodes.get(key);
298
+ if (node === undefined)
299
+ continue;
300
+ if (node.visibility === 'hidden')
301
+ continue;
302
+ if (anchorWithdrawn(node, cuts) || summaryWithdrawn(node, summaries))
303
+ continue;
304
+ visible.push(key);
305
+ }
306
+ return visible.length === chat.order.length ? chat.order : visible;
307
+ }
308
+ /**
309
+ * A comparable signal for the visible row set, built for
310
+ * `useSyncExternalStore`-style subscription: the host re-runs a chat selector
311
+ * on every publish and compares the RESULT by `Object.is`, and a rewind
312
+ * publishes an in-place upsert of an existing command row. The snapshot's
313
+ * `order` array and node store are therefore both reference-stable across a
314
+ * rewind, so a selector on them never re-renders; a string does change exactly
315
+ * when the visible set does. Never return the array itself from a selector —
316
+ * a fresh array fails the `Object.is` check on every publish.
317
+ */
318
+ export function visibleChatSignature(chat) {
319
+ return visibleChatKeys(chat).join('\u0000');
320
+ }
321
+ //# sourceMappingURL=rewind-cut.js.map
@@ -0,0 +1 @@
1
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,CAAC,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;AACrE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAa;IAChD,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,93 @@
1
+ import type { ReaderBlockOwner, ReaderBlockPresentation } from './types.js';
2
+ /**
3
+ * Cordis service name. Another client plugin lists this in `inject` and
4
+ * registers a transformer. The reading view paints the result. The session
5
+ * block, transcript, and fold inputs stay on the original text.
6
+ */
7
+ export declare const TEXT_TRANSFORM_SERVICE = "dsh-better-display.text-transform";
8
+ export type DisplayTextKind = 'reasoning' | 'body';
9
+ export interface DisplayTextRequest {
10
+ /** Original block text. Registrants must not write it back onto the block. */
11
+ text: string;
12
+ streaming: boolean;
13
+ /** Opaque id of this mounted block. Stable until the block unmounts. */
14
+ blockKey: string;
15
+ kind: DisplayTextKind;
16
+ /** Assistant body and reasoning are the usual targets. Tool prose uses `tool`. */
17
+ source?: ReaderBlockOwner['source'];
18
+ }
19
+ export interface DisplayText {
20
+ text: string;
21
+ /**
22
+ * True when this string is the settled display for the current source.
23
+ * False keeps the live reveal open, including after the model has stopped
24
+ * but a translation batch is still outstanding.
25
+ */
26
+ final: boolean;
27
+ }
28
+ /**
29
+ * Sync `read` on every paint, plus `subscribe` when a later batch changes
30
+ * what `read` returns. `subscribe` may be called once per kind and must
31
+ * accept more than one listener.
32
+ */
33
+ export interface DisplayTextTransformer {
34
+ read(request: DisplayTextRequest): DisplayText | string | undefined;
35
+ subscribe?(listener: () => void): () => void;
36
+ }
37
+ export interface DisplayCursor extends DisplayText {
38
+ /**
39
+ * Increments when the displayed string or its `final` bit changes.
40
+ * This is not the reveal clock. Passing it to the word timeline as the
41
+ * motion revision replays or snaps the paragraph.
42
+ */
43
+ transformRevision: number;
44
+ /**
45
+ * Reveal identity. Stays put when the new string extends the previous
46
+ * display string, so an appended translation batch continues the fade.
47
+ * Increments only when the string is replaced, which settles the new
48
+ * text instead of typing it again from the first grapheme.
49
+ */
50
+ motionRevision: number;
51
+ }
52
+ export interface TextTransformRegistry {
53
+ register(kind: DisplayTextKind | readonly DisplayTextKind[], transformer: DisplayTextTransformer): () => void;
54
+ has(kind: DisplayTextKind): boolean;
55
+ read(request: DisplayTextRequest): DisplayCursor;
56
+ subscribe(kind: DisplayTextKind, listener: () => void): () => void;
57
+ release(kind: DisplayTextKind, blockKey: string): void;
58
+ }
59
+ /**
60
+ * Appends keep the motion revision. A replacement gets a new one so the
61
+ * timeline treats the swapped string as already settled.
62
+ */
63
+ export declare function nextDisplayCursor(previous: DisplayCursor | undefined, display: DisplayText): DisplayCursor;
64
+ /**
65
+ * Streaming flag fed to the reveal. With no transformer this is the model's
66
+ * flag. A transformer that reports `final: !streaming` produces the same flag.
67
+ */
68
+ export declare function displayStreaming(sourceStreaming: boolean, shown: Pick<DisplayCursor, 'final'>, active: boolean): boolean;
69
+ /** No registry, or none for this kind: the source string, and no cursor write. */
70
+ export declare function readDisplayText(registry: TextTransformRegistry | undefined, request: DisplayTextRequest): DisplayCursor;
71
+ export declare function createTextTransformRegistry(): TextTransformRegistry;
72
+ /** Points the reading view at the registry this client plugin provides. */
73
+ export declare function installTextTransformRegistry(registry: TextTransformRegistry | undefined): () => void;
74
+ export declare function activeTextTransform(): TextTransformRegistry | undefined;
75
+ /**
76
+ * Subscribe while mounted. The reveal components call this only after
77
+ * `has(kind)`, so an empty registry adds no hook and no listener.
78
+ */
79
+ export declare function useDisplayText(registry: TextTransformRegistry, request: DisplayTextRequest): DisplayCursor;
80
+ /** Chain-slot owner. Extra fields are optional so older callers still type-check. */
81
+ export declare function readerBlockOwner(block: ReaderBlockOwner['block'], streaming: boolean, source: ReaderBlockOwner['source'], presentation: ReaderBlockPresentation, holdFormatting: boolean): ReaderBlockOwner;
82
+ /** Copy actions read this. Display text never replaces it. */
83
+ export declare function originalAnswerText(blocks: readonly {
84
+ readonly kind: string;
85
+ readonly text?: string;
86
+ }[]): string;
87
+ declare module '@deepseek-ai/cordis' {
88
+ interface Context {
89
+ /** Display-only reader text transforms. Present after this client plugin applies. */
90
+ 'dsh-better-display.text-transform'?: TextTransformRegistry;
91
+ }
92
+ }
93
+ //# sourceMappingURL=text-transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-transform.d.ts","sourceRoot":"","sources":["../../../src/client/text-transform.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAE5E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,sCAAsC,CAAC;AAE1E,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,MAAM,CAAC;AAEnD,MAAM,WAAW,kBAAkB;IACjC,8EAA8E;IAC9E,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,eAAe,CAAC;IACtB,kFAAkF;IAClF,MAAM,CAAC,EAAE,gBAAgB,CAAC,QAAQ,CAAC,CAAC;CACrC;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;IACpE,SAAS,CAAC,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,aAAc,SAAQ,WAAW;IAChD;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;;;;OAKG;IACH,cAAc,EAAE,MAA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