dsh-enhance 0.3.9 → 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 (3) hide show
  1. package/README.md +138 -224
  2. package/lib/client.js +1143 -32
  3. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -9,7 +9,7 @@ window.__ModuleLoader__.load({
9
9
  let react_jsx_runtime = require("react/jsx-runtime");
10
10
  // src/client/styles/document-preview.ts
11
11
  /** Global presentation owned by dsh-enhance (migrated from the installer's injected styles). */
12
- const css$9 = String.raw`body[data-ds-dark-theme] [data-document-markdown] {
12
+ const css$11 = String.raw`body[data-ds-dark-theme] [data-document-markdown] {
13
13
  --md-text: #e9e9e9;
14
14
  --md-text-strong: #fff;
15
15
  --md-text-muted: #a5a5a5;
@@ -191,7 +191,7 @@ body:not([data-ds-dark-theme]) [data-document-markdown] {
191
191
  `;
192
192
  // src/client/styles/chat-markdown.ts
193
193
  /** Global presentation owned by dsh-enhance (migrated from the installer's injected styles). */
194
- const css$8 = String.raw`:is([data-ds-dark-theme], [data-ds-dark-theme] body) :is([data-chat-flow-kind="assistant-step"], [class*="_markdown"]) {
194
+ const css$10 = String.raw`:is([data-ds-dark-theme], [data-ds-dark-theme] body) :is([data-chat-flow-kind="assistant-step"], [class*="_markdown"]) {
195
195
  --md-text: #efefef;
196
196
  --md-text-strong: #fff;
197
197
  --md-text-muted: #a5a5a5;
@@ -425,7 +425,7 @@ body:not([data-ds-dark-theme]) [data-document-markdown] {
425
425
  `;
426
426
  // src/client/styles/rightbar-handle.ts
427
427
  /** Global presentation owned by dsh-enhance (migrated from the installer's injected styles). */
428
- const css$7 = String.raw`[data-side="rightbar"] {
428
+ const css$9 = String.raw`[data-side="rightbar"] {
429
429
  width: 18px !important;
430
430
  margin-left: -9px !important;
431
431
  cursor: col-resize;
@@ -457,7 +457,7 @@ body:not([data-ds-dark-theme]) [data-document-markdown] {
457
457
  `;
458
458
  // src/client/styles/running-spinner.ts
459
459
  /** Global presentation owned by dsh-enhance (migrated from the installer's injected styles). */
460
- const css$6 = String.raw`/* A running session's marker is the host's StateDot in its "ongoing" form: an
460
+ const css$8 = String.raw`/* A running session's marker is the host's StateDot in its "ongoing" form: an
461
461
  inline SVG holding two circles — a faint track and a dashed arc that spins
462
462
  and lengthens. Both circles stroke with currentColor, and the host paints
463
463
  that token as label-tertiary, a grey, so a live session reads exactly as
@@ -506,7 +506,7 @@ body:not([data-ds-dark-theme]) [data-document-markdown] {
506
506
  `;
507
507
  // src/client/styles/sidebar-density.ts
508
508
  /** Global presentation owned by dsh-enhance (migrated from the installer's injected styles). */
509
- const css$5 = String.raw`/* Workspace rows: swap the folder icon for the disclosure triangle in every
509
+ const css$7 = String.raw`/* Workspace rows: swap the folder icon for the disclosure triangle in every
510
510
  state, not only on hover.
511
511
 
512
512
  The row already renders both slots — a folder span followed by a chevron span
@@ -690,7 +690,7 @@ body[data-ds-dark-theme] [class*="sidebarCol"] {
690
690
  `;
691
691
  // src/client/styles/sidebar-layout.ts
692
692
  /** Global presentation owned by dsh-enhance (migrated from the installer's injected styles). */
693
- const css$4 = String.raw`[class*="sidebarCol"] [class*="_root"] { position: relative !important; }
693
+ const css$6 = String.raw`[class*="sidebarCol"] [class*="_root"] { position: relative !important; }
694
694
  [class*="sidebarCol"] [class*="logoRow"] { display: none !important; }
695
695
  /* New Session bar removed by local preference: hides it in both the expanded
696
696
  sidebar and the collapsed rail. Sessions are still created with the app's
@@ -1173,7 +1173,7 @@ body[data-ds-dark-theme] .dsh-enhance-bubble {
1173
1173
  `;
1174
1174
  // src/client/styles/toolbar.ts
1175
1175
  /** Global presentation owned by dsh-enhance: annotation popover and tray. */
1176
- const css$3 = String.raw`/* The passage being annotated, painted through the Custom Highlight API so the
1176
+ const css$5 = String.raw`/* The passage being annotated, painted through the Custom Highlight API so the
1177
1177
  mark survives focus moving into the note field (a native selection would not).
1178
1178
  Same blue as the app's document selection, so it reads as the same gesture. */
1179
1179
  ::highlight(dsh-enhance-annotation) {
@@ -2099,7 +2099,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2099
2099
  `;
2100
2100
  // src/client/styles/file-menu.ts
2101
2101
  /** Right-click file menu: a small native-looking panel over the transcript. */
2102
- const css$2 = String.raw`/* The menu is appended to body, outside every chat container, so it needs
2102
+ const css$4 = String.raw`/* The menu is appended to body, outside every chat container, so it needs
2103
2103
  its own type scale and surface. The dark variant keys off the same theme
2104
2104
  attribute the other sheets use, which the app sets on html or body. */
2105
2105
  .dsh-file-menu {
@@ -2229,6 +2229,142 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2229
2229
  box-shadow: 0 10px 30px rgb(0 0 0 / 40%) !important;
2230
2230
  color: #f2f2f4 !important;
2231
2231
  }
2232
+ `;
2233
+ // src/client/styles/annotation-display.ts
2234
+ /**
2235
+ * The display form of a sent annotation entry.
2236
+ *
2237
+ * One entry is a two-column grid: the entry number sits in a column exactly as
2238
+ * wide as the number itself, and the quoted label, the passage and (below them)
2239
+ * the reader's own comment share the second column — so the passage always
2240
+ * starts at the same x as the "quoted" label, whether the entry is number 1 or
2241
+ * 12. The comment spans both columns. It paints inside the message bubble it
2242
+ * arrived in — no card, no fill, nothing that competes with the bubble. Groups
2243
+ * are tight; the blank line the writer puts between entries is what separates
2244
+ * them.
2245
+ *
2246
+ * Labels use literal colours rather than a single theme token: blue reads as
2247
+ * "this is the quoted passage", purple as "this is what I said about it", and
2248
+ * both stay legible over the light and dark bubble. The label colours are
2249
+ * opaque, because the label is small text and has to clear the 4.5:1 contrast
2250
+ * floor on both bubble colours.
2251
+ */
2252
+ const css$3 = String.raw`/* The whole entry. A two-column grid: the number takes a max-content column, the
2253
+ quoted label and passage share the second column, and the comment spans both.
2254
+ Block level so it starts on its own line inside the bubble. */
2255
+ .dsh-enhance-anno {
2256
+ display: grid;
2257
+ grid-template-columns: max-content 1fr;
2258
+ column-gap: 6px;
2259
+ row-gap: 2px;
2260
+ align-items: baseline;
2261
+ margin: 6px 0 4px;
2262
+ padding: 0;
2263
+ font: inherit;
2264
+ line-height: 1.55;
2265
+ }
2266
+
2267
+ /* The head dissolves into the grid: its number lands in column 1 and the quoted
2268
+ label in column 2, on one shared baseline row. */
2269
+ .dsh-enhance-anno__head {
2270
+ display: contents;
2271
+ }
2272
+
2273
+ .dsh-enhance-anno__number {
2274
+ grid-column: 1;
2275
+ grid-row: 1;
2276
+ color: var(--dsw-alias-label-caption);
2277
+ font-size: .85em;
2278
+ font-weight: 600;
2279
+ font-variant-numeric: tabular-nums;
2280
+ line-height: 1.4;
2281
+ }
2282
+
2283
+ .dsh-enhance-anno__label {
2284
+ font-size: .8125em;
2285
+ font-weight: 600;
2286
+ letter-spacing: .01em;
2287
+ line-height: 1.4;
2288
+ }
2289
+
2290
+ /* Saturated blue: the quoted passage. Opaque, so the small label still reads
2291
+ against the light bubble (5.7:1 on the #ECECEC bubble). */
2292
+ .dsh-enhance-anno__label--quote {
2293
+ grid-column: 2;
2294
+ grid-row: 1;
2295
+ color: #1d4ed8;
2296
+ }
2297
+
2298
+ /* Saturated purple: the reader's own comment, on its own line above it.
2299
+ Opaque too, for the same reason (6.0:1 on the light bubble). */
2300
+ .dsh-enhance-anno__label--comment {
2301
+ display: block;
2302
+ margin: 5px 0 2px;
2303
+ color: #6d28d9;
2304
+ }
2305
+
2306
+ /* Dark bubbles keep the light blue and light purple, opaque so the label
2307
+ stays legible there as well (5.7:1 and 5.3:1 on a #2A2A2A bubble). */
2308
+ body[data-ds-dark-theme] .dsh-enhance-anno__label--quote {
2309
+ color: #60a5fa;
2310
+ }
2311
+
2312
+ body[data-ds-dark-theme] .dsh-enhance-anno__label--comment {
2313
+ color: #a78bfa;
2314
+ }
2315
+
2316
+ /* Empty cell under the entry number. It stretches to the passage's height so the
2317
+ vertical rule runs the length of the quote, while staying in the number
2318
+ column (the "hanging indent" guide) rather than at the text's left edge. */
2319
+ .dsh-enhance-anno__gutter {
2320
+ grid-column: 1;
2321
+ grid-row: 2;
2322
+ position: relative;
2323
+ align-self: stretch;
2324
+ }
2325
+
2326
+ /* The hairline: 2px wide, its centre ~3.9px from the entry's left edge — the
2327
+ centre of the first (tabular) digit of the number, so single- and multi-digit
2328
+ entries share one vertical guide line however wide the number column is. */
2329
+ .dsh-enhance-anno__gutter::before {
2330
+ content: "";
2331
+ position: absolute;
2332
+ top: 0;
2333
+ bottom: 0;
2334
+ left: 3px;
2335
+ width: 2px;
2336
+ background: rgb(37 99 235 / 30%);
2337
+ }
2338
+
2339
+ body[data-ds-dark-theme] .dsh-enhance-anno__gutter::before {
2340
+ background: rgb(96 165 250 / 38%);
2341
+ }
2342
+
2343
+ /* The passage: secondary body colour, on the shared text column so it lines up
2344
+ with the "quoted" label. pre-wrap keeps the passage's own line breaks (and any
2345
+ blank line inside it). */
2346
+ .dsh-enhance-anno__quote {
2347
+ grid-column: 2;
2348
+ grid-row: 2;
2349
+ display: block;
2350
+ white-space: pre-wrap;
2351
+ overflow-wrap: anywhere;
2352
+ color: var(--dsw-alias-label-secondary);
2353
+ }
2354
+
2355
+ /* The comment spans both columns, so it starts at the entry's left edge. */
2356
+ .dsh-enhance-anno__comment-block {
2357
+ grid-column: 1 / -1;
2358
+ display: block;
2359
+ margin: 0;
2360
+ }
2361
+
2362
+ .dsh-enhance-anno__comment {
2363
+ display: block;
2364
+ white-space: pre-wrap;
2365
+ overflow-wrap: anywhere;
2366
+ color: var(--dsw-alias-label-primary);
2367
+ }
2232
2368
  `;
2233
2369
  // src/client/surfaces/ds-bot/chrome.ts
2234
2370
  /** DS Bot-only chrome. Shared Markdown and annotation sheets are unchanged.
@@ -2239,7 +2375,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2239
2375
  */
2240
2376
  const CORNER_ROW = ":is(.bt-pane, .bt-panel) .bt-drawer-top";
2241
2377
  const PILL_HEADER = "header[class*=\"_header\"]:has(.bt-head)";
2242
- const css$1 = `
2378
+ const css$2 = `
2243
2379
  /* Keep user messages on the current theme's surface instead of an inverted
2244
2380
  black/white slab. Theme inks retain readable text and adapt to custom themes. */
2245
2381
  body {
@@ -2463,6 +2599,28 @@ ${PILL_HEADER} .bt-pill:active {
2463
2599
  }
2464
2600
  }
2465
2601
 
2602
+ /* A group session with an active goal renders the same .bt-pill inside a
2603
+ .bt-island card (the pill row plus a goal bar below it). The host squares that
2604
+ card off — its own 20px, open 18px superellipse corners tuck inside the
2605
+ pill's 9999px capsule, so the outer card's top corners read squarer than the
2606
+ capsule they wrap. The pill is 50px tall, so its capsule resolves each corner
2607
+ to a 25px radius; give the island that exact radius and the same round
2608
+ corner-shape, and hand it to the goal bar / panel that paint the island's
2609
+ bottom edge, so the inner capsule and the outer card share one curve in both
2610
+ the collapsed (goal bar) and open (goal panel) states. Scoped to the session
2611
+ header island; the plain header pill (no island ancestor) is untouched, and
2612
+ the transition the host declares on the island keeps animating the change. */
2613
+ ${PILL_HEADER} .bt-island {
2614
+ border-radius: 25px !important;
2615
+ corner-shape: round !important;
2616
+ }
2617
+ ${PILL_HEADER} .bt-island:not([data-open]) .bt-goal-bar {
2618
+ border-radius: 0 0 25px 25px !important;
2619
+ }
2620
+ ${PILL_HEADER} .bt-island .bt-goal-panel {
2621
+ border-radius: 0 0 25px 25px !important;
2622
+ }
2623
+
2466
2624
  /* The settled panel starts at chrome-top. Absolute positioning also follows
2467
2625
  its entrance animation instead of changing fixed containing blocks midway.
2468
2626
  Top-aligned with the 14px traffic lights (their top sits at 13px in the 40px
@@ -2532,6 +2690,64 @@ html[data-windows-titlebar] .bt-panel:has(> .bt-panel-view > .bt-subhead) > .bt-
2532
2690
  padding-top: max(20px, calc(var(--bt-lc-clear, 0px) + 8px)) !important;
2533
2691
  }
2534
2692
 
2693
+ /* ---- Window drag from the sidebar background (desktop only) ---- */
2694
+
2695
+ /* The desktop shell is frameless, so the sidebar's empty background is the
2696
+ natural place to grab the window on the left. The host's base.css turns the
2697
+ data-window-drag marker into the sole darwin drag region and
2698
+ data-window-drag-recall into its no-drag carve-out; here the whole left
2699
+ column becomes that region, and every control inside it is carved back out.
2700
+ A drag region is the union of the drag boxes minus the no-drag boxes, so the
2701
+ gaps around the pinned tile, the spacer below the session list, the section
2702
+ spacing and the area beside the rows all drag the window, while the rows,
2703
+ group headers, buttons, menus, inputs and the width grip keep every pointer
2704
+ event (clicks, hover, right-click, wheel). Scoped to data-windows-titlebar so
2705
+ a plain browser tab — which has no native window to move — is left alone.
2706
+ The grip is carved out so panel-widths.ts keeps owning its resize gesture. */
2707
+ html[data-windows-titlebar] .bt-leftcol {
2708
+ -webkit-app-region: drag !important;
2709
+ }
2710
+ html[data-windows-titlebar] .bt-leftcol button,
2711
+ html[data-windows-titlebar] .bt-leftcol a,
2712
+ html[data-windows-titlebar] .bt-leftcol input,
2713
+ html[data-windows-titlebar] .bt-leftcol textarea,
2714
+ html[data-windows-titlebar] .bt-leftcol select,
2715
+ html[data-windows-titlebar] .bt-leftcol [contenteditable="true"],
2716
+ html[data-windows-titlebar] .bt-leftcol [role="menu"],
2717
+ html[data-windows-titlebar] .bt-leftcol [role="menuitem"],
2718
+ html[data-windows-titlebar] .bt-leftcol [role="menuitemcheckbox"],
2719
+ html[data-windows-titlebar] .bt-leftcol-grip {
2720
+ -webkit-app-region: no-drag !important;
2721
+ }
2722
+
2723
+ /* ---- Bot shortcut tile: let the card hold its role label ---- */
2724
+
2725
+ /* The pinned bot card shrink-wraps to its 60px avatar, but the role chip
2726
+ ("Chief Bot Officer") is content-box with 1px 7px padding and a 92px cap, so
2727
+ it measured ~104px and spilled ~5px past the card on each side — the chip's
2728
+ rounded background showed outside the card's rounded bottom. Let the card
2729
+ grow to fit the label with equal side padding, and keep an over-long label
2730
+ wrapped inside the card instead of poking out when the sidebar is narrow.
2731
+ The avatar and its status badge are untouched; a short label leaves a compact
2732
+ card, and a single-line label stays on one line. Not scoped to
2733
+ data-windows-titlebar: the overflow shows in a plain browser too. */
2734
+ .bt-leftcol .bt-tile {
2735
+ width: auto !important;
2736
+ max-width: 100% !important;
2737
+ box-sizing: border-box !important;
2738
+ padding-left: 12px !important;
2739
+ padding-right: 12px !important;
2740
+ }
2741
+ .bt-leftcol .bt-tile .bt-chip {
2742
+ max-width: 100% !important;
2743
+ box-sizing: border-box !important;
2744
+ white-space: normal !important;
2745
+ overflow-wrap: anywhere !important;
2746
+ text-align: center !important;
2747
+ line-height: 1.25 !important;
2748
+ height: auto !important;
2749
+ }
2750
+
2535
2751
  /* ---- Sidebar section headers (DS Bot tree) ---- */
2536
2752
 
2537
2753
  /* The disclosure chevron's glyph sits ~2.5px right of the hover guide line
@@ -2642,7 +2858,7 @@ body[data-ds-dark-theme] .bt-account-menu {
2642
2858
  const md = `[data-slot="conversation.chat.node"] ${bubble} [class*="_markdown"]`;
2643
2859
  const fallback = `${bubble} [class*="_markdown"][class*="_markdown"]`;
2644
2860
  /** The DS Bot anchor overlay. Not mounted on DeepSeek Harness. */
2645
- const css = `${md},
2861
+ const css$1 = `${md},
2646
2862
  ${fallback} {
2647
2863
  color: var(--md-text) !important;
2648
2864
  font-size: 13px !important;
@@ -2763,7 +2979,8 @@ ${fallback} li::marker {
2763
2979
  sectionStats: false,
2764
2980
  whale: false,
2765
2981
  windowGeometry: false,
2766
- liquidGlass: true
2982
+ liquidGlass: true,
2983
+ autoLoadEarlier: true
2767
2984
  };
2768
2985
  return {
2769
2986
  ...shared,
@@ -2773,7 +2990,8 @@ ${fallback} li::marker {
2773
2990
  whale: true,
2774
2991
  windowGeometry: true,
2775
2992
  panelWidths: false,
2776
- liquidGlass: false
2993
+ liquidGlass: false,
2994
+ autoLoadEarlier: false
2777
2995
  };
2778
2996
  }
2779
2997
  /**
@@ -2785,28 +3003,627 @@ ${fallback} li::marker {
2785
3003
  function stylePluginId(surface) {
2786
3004
  return surface === "ds-bot" ? "ds-bot-enhance" : "dsh-enhance";
2787
3005
  }
3006
+ /**
3007
+ * A wheel or a key counts as the same gesture for this long.
3008
+ *
3009
+ * One sweep of the wheel therefore asks for one page: the history cannot be
3010
+ * pulled in a single scroll, and the reader has to let go and start again.
3011
+ */
3012
+ const GESTURE_WINDOW_MS = 250;
3013
+ /** The load is given this long before the reader is handed the button back. */
3014
+ const SETTLE_LIMIT_MS = 8e3;
3015
+ /** The host shows its own loading state; without it the click did not take. */
3016
+ const LOAD_GIVE_UP_MS = 1500;
3017
+ /** The scroller the host renders the transcript in. */
3018
+ const SCROLLER = "[data-conversation-scroll]";
3019
+ /** The element the transcript is laid out in. */
3020
+ const COLUMN = "[data-chat-flow]";
3021
+ /** The slot the host renders the transcript rows into. */
3022
+ const FLOW_SLOT = "[data-slot=\"conversation.chat.flow\"]";
3023
+ /** The rows the host gives a key of its own; those are the rows to bear on. */
3024
+ const ANCHOR_ROWS = "[data-chat-anchor-key]:not(:empty):not([hidden]):not([hidden] *)";
3025
+ /** The host's session-title header, which the indicator has to stay clear of. */
3026
+ const HEADER$1 = "header[class*=\"_header\"]:has(.bt-head)";
3027
+ /** The least correction worth writing, in pixels. */
3028
+ const WRITE_EPS = .5;
3029
+ /** Stamped on the host's "load earlier" row while a load is running. */
3030
+ const LOADING_ATTR = "data-dsh-enhance-older-loading";
3031
+ /** The plugin's own indicator, painted over the host's button. */
3032
+ const SPINNER_CLASS = "dsh-enhance-older-spinner";
3033
+ /**
3034
+ * The row the reader is reading, and where it sits in the content.
3035
+ *
3036
+ * The reader's row is the first row of the list that reaches into the
3037
+ * visible part of the scroller. The rows the host holds the list by are not
3038
+ * used: the host keeps the first row of the list in place when a page lands,
3039
+ * and the reader is somewhere else.
3040
+ *
3041
+ * The place is measured in the scrolled content, not in the viewport: the
3042
+ * row's distance from the top of the scroller's content box, plus the
3043
+ * scroller's own offset. Scrolling by so much moves the row up by so much in
3044
+ * the viewport and the offset up by so much, and the two cancel; adding
3045
+ * content above the row pushes the place down by the height of that content.
3046
+ * @param scrollerEl - the scroller the transcript lives in.
3047
+ * @returns the bearing, or undefined when there is no row to hold on to.
3048
+ */
3049
+ function bearingOf(scrollerEl) {
3050
+ const list = scrollerEl.querySelector(FLOW_SLOT);
3051
+ if (!list) return void 0;
3052
+ const contentTop = scrollerEl.getBoundingClientRect().top + scrollerEl.clientTop;
3053
+ const viewportTop = contentTop + 6;
3054
+ for (const row of Array.from(list.querySelectorAll(ANCHOR_ROWS))) {
3055
+ const key = row.getAttribute("data-chat-anchor-key");
3056
+ if (!key) continue;
3057
+ const rect = row.getBoundingClientRect();
3058
+ if (rect.height <= 0) continue;
3059
+ if (rect.bottom <= viewportTop) continue;
3060
+ return {
3061
+ key,
3062
+ place: rect.top - contentTop + scrollerEl.scrollTop
3063
+ };
3064
+ }
3065
+ }
3066
+ /**
3067
+ * The row with the given key, when the host still has it.
3068
+ * @param scrollerEl - the scroller the transcript lives in.
3069
+ * @param key - the key the host gave the row.
3070
+ * @returns the row, or undefined when the host has dropped it.
3071
+ */
3072
+ function rowByKey(scrollerEl, key) {
3073
+ const list = scrollerEl.querySelector(FLOW_SLOT);
3074
+ if (!list) return void 0;
3075
+ for (const row of Array.from(list.querySelectorAll(ANCHOR_ROWS))) if (row.getAttribute("data-chat-anchor-key") === key) return row;
3076
+ }
3077
+ /**
3078
+ * The place of a row in the scrolled content.
3079
+ * @param scrollerEl - the scroller the transcript lives in.
3080
+ * @param row - the row to measure.
3081
+ * @returns the place, in pixels.
3082
+ */
3083
+ function placeOf(scrollerEl, row) {
3084
+ const contentTop = scrollerEl.getBoundingClientRect().top + scrollerEl.clientTop;
3085
+ return row.getBoundingClientRect().top - contentTop + scrollerEl.scrollTop;
3086
+ }
3087
+ /**
3088
+ * Mount the auto-loader on this surface.
3089
+ * @param ctx - client root, used to follow the open conversation.
3090
+ * @param root - the document the transcript lives in.
3091
+ * @param t - the dictionary for the loading copy.
3092
+ * @returns a cleanup function.
3093
+ */
3094
+ function installAutoLoadEarlier(ctx, root, t) {
3095
+ const win = root.defaultView;
3096
+ if (!win) return () => {};
3097
+ let phase = "idle";
3098
+ /** Counts the reader's gestures; a new one is a new chance to ask. */
3099
+ let gestureSeq = 0;
3100
+ /** The gesture that asked for the last page. */
3101
+ let lastTriggerGesture = -1;
3102
+ /** When the reader's current gesture stops counting as live. */
3103
+ let gestureUntil = 0;
3104
+ let lastScrollTop = 0;
3105
+ let sawDisabled = false;
3106
+ let buttonBack = false;
3107
+ let changed = false;
3108
+ let lastChangeAt = 0;
3109
+ let startedAt = 0;
3110
+ let deadline = 0;
3111
+ let frame = 0;
3112
+ let lastHeight = -1;
3113
+ let lastRows = -1;
3114
+ let indicator;
3115
+ /** The row the reader is reading, and where it sits in the content. */
3116
+ let bearing;
3117
+ /** The sheet that takes the browser's own anchoring out of the way. */
3118
+ let anchorOff;
3119
+ /**
3120
+ * The offset this module last wrote, so that its own scroll is not read as
3121
+ * the reader's gesture.
3122
+ */
3123
+ let ownWriteTop;
3124
+ let disposed = false;
3125
+ let session = sessionKeyOf(ctx);
3126
+ const scroller = () => root.querySelector(SCROLLER);
3127
+ const column = () => root.querySelector(COLUMN);
3128
+ /**
3129
+ * The host's row that holds the "load earlier" button.
3130
+ *
3131
+ * The row is a child of the transcript column that carries a button and not
3132
+ * the transcript itself. Once the history is exhausted the host drops the
3133
+ * row, and the first child of the column is the transcript from then on.
3134
+ * @returns the row, or undefined when there is nothing left to load.
3135
+ */
3136
+ const loadRow = () => {
3137
+ const col = column();
3138
+ if (!col) return void 0;
3139
+ for (const child of Array.from(col.children)) {
3140
+ if (!(child instanceof win.HTMLElement)) continue;
3141
+ if (child.matches(FLOW_SLOT)) continue;
3142
+ if (child.querySelector(FLOW_SLOT) !== null) continue;
3143
+ if (child.querySelector("button") === null) continue;
3144
+ return child;
3145
+ }
3146
+ };
3147
+ /**
3148
+ * The host's "load earlier" button, or undefined when there is nothing left
3149
+ * to load. A missing button is the end of the conversation's past, not a
3150
+ * failure.
3151
+ */
3152
+ const loadButton = () => {
3153
+ const button = loadRow()?.querySelector("button");
3154
+ return button instanceof win.HTMLButtonElement ? button : void 0;
3155
+ };
3156
+ /** How many rows the host has in the list. */
3157
+ const rowCount = () => column()?.querySelector(FLOW_SLOT)?.children.length ?? 0;
3158
+ /**
3159
+ * Take the browser's own anchoring out of the way while the page lands.
3160
+ *
3161
+ * The browser keeps a row in place when content is added above it, and it
3162
+ * does so by moving the scroller's offset by the same amount. That is the
3163
+ * same correction this module makes, and the two together would move the
3164
+ * reader's row twice as far as it should go.
3165
+ *
3166
+ * The rule is set on the scroller and on everything in it, because the
3167
+ * browser picks the anchor among the descendants of the scroller.
3168
+ */
3169
+ const disableAnchoring = () => {
3170
+ if (anchorOff?.isConnected) return;
3171
+ anchorOff?.remove();
3172
+ const style = root.createElement("style");
3173
+ const pluginId = stylePluginId("ds-bot");
3174
+ style.dataset.plugin = pluginId;
3175
+ style.dataset.pluginCss = `${pluginId}/ds-bot-older-anchoring`;
3176
+ style.textContent = `${SCROLLER}, ${SCROLLER} * { overflow-anchor: none !important; }`;
3177
+ (root.head ?? root.documentElement).appendChild(style);
3178
+ anchorOff = style;
3179
+ };
3180
+ /** Give the browser's own anchoring back. */
3181
+ const enableAnchoring = () => {
3182
+ anchorOff?.remove();
3183
+ anchorOff = void 0;
3184
+ };
3185
+ /**
3186
+ * Put the growth of the content back into the scroller.
3187
+ *
3188
+ * The reader's row keeps its place in the content while the older page is
3189
+ * spliced in above it, and that place moves by exactly what was added. The
3190
+ * scroller is moved by the same amount, and the row stays in the viewport
3191
+ * where the reader left it.
3192
+ *
3193
+ * The reader's own scrolling does not move the place — the row's distance
3194
+ * in the viewport and the scroller's offset change by the same amount — so
3195
+ * it is left alone.
3196
+ * @param scrollerEl - the scroller the transcript lives in.
3197
+ */
3198
+ const correct = (scrollerEl) => {
3199
+ if (!bearing) return;
3200
+ const row = rowByKey(scrollerEl, bearing.key);
3201
+ if (!row) {
3202
+ bearing = void 0;
3203
+ return;
3204
+ }
3205
+ const step = placeOf(scrollerEl, row) - bearing.place;
3206
+ if (Math.abs(step) <= WRITE_EPS) return;
3207
+ scrollerEl.scrollTop += step;
3208
+ bearing.place = placeOf(scrollerEl, row);
3209
+ ownWriteTop = scrollerEl.scrollTop;
3210
+ };
3211
+ /**
3212
+ * Note that the reader is doing something.
3213
+ *
3214
+ * Input that follows a pause is a new gesture, and a new gesture is what
3215
+ * allows another page to be asked for.
3216
+ */
3217
+ const markGesture = () => {
3218
+ const now = win.performance.now();
3219
+ if (now > gestureUntil) gestureSeq += 1;
3220
+ gestureUntil = now + GESTURE_WINDOW_MS;
3221
+ };
3222
+ /**
3223
+ * Put the indicator where the host's button is.
3224
+ *
3225
+ * The indicator is pinned to the viewport, not to the content: the older
3226
+ * page is spliced in above the reader, and an indicator that travelled with
3227
+ * the content would be off screen before the load was over. Its spot is the
3228
+ * load row's place in the content, which is where the host's own button
3229
+ * sits while the list is at the top.
3230
+ *
3231
+ * The host's session-title pill hangs over the top of the list, right where
3232
+ * the load row is when the list is at the top, so the indicator is kept
3233
+ * clear of it and of the edge of the list.
3234
+ * @param scrollerEl - the scroller the transcript lives in.
3235
+ */
3236
+ const placeIndicator = (scrollerEl) => {
3237
+ if (!indicator) return;
3238
+ const col = column();
3239
+ const row = loadRow();
3240
+ if (!col || !row) return;
3241
+ const colRect = col.getBoundingClientRect();
3242
+ const scrollerRect = scrollerEl.getBoundingClientRect();
3243
+ const rowRect = row.getBoundingClientRect();
3244
+ const half = (indicator.offsetHeight || 26) / 2;
3245
+ let centre = rowRect.top + rowRect.height / 2;
3246
+ const floor = scrollerRect.top + 8 + half;
3247
+ if (centre < floor) centre = floor;
3248
+ const header = root.querySelector(HEADER$1);
3249
+ if (header instanceof win.HTMLElement) {
3250
+ const clear = header.getBoundingClientRect().bottom + 4 + half;
3251
+ if (centre < clear) centre = clear;
3252
+ }
3253
+ indicator.style.setProperty("--dsh-enhance-older-y", `${Math.round(centre)}px`);
3254
+ indicator.style.setProperty("--dsh-enhance-older-x", `${Math.round(colRect.left + colRect.width / 2)}px`);
3255
+ };
3256
+ /** Show the indicator over the host's button. */
3257
+ const showIndicator = (scrollerEl) => {
3258
+ if (!column()) return;
3259
+ loadRow()?.setAttribute(LOADING_ATTR, "");
3260
+ if (!indicator) {
3261
+ indicator = root.createElement("div");
3262
+ indicator.className = SPINNER_CLASS;
3263
+ const ring = root.createElement("span");
3264
+ ring.className = "dsh-enhance-older-ring";
3265
+ ring.setAttribute("aria-hidden", "true");
3266
+ const label = root.createElement("span");
3267
+ label.className = "dsh-enhance-older-label";
3268
+ indicator.append(ring, label);
3269
+ }
3270
+ const label = indicator.querySelector(".dsh-enhance-older-label");
3271
+ if (label !== null) label.textContent = t("autoLoad.loading");
3272
+ if (!indicator.isConnected) (root.body ?? root.documentElement).appendChild(indicator);
3273
+ placeIndicator(scrollerEl);
3274
+ };
3275
+ /**
3276
+ * Take the indicator away and give the host's button back.
3277
+ *
3278
+ * The host may have rebuilt its load row while the load was on its way, so
3279
+ * the mark is taken off the row that is there now.
3280
+ */
3281
+ const hideIndicator = () => {
3282
+ indicator?.remove();
3283
+ loadRow()?.removeAttribute(LOADING_ATTR);
3284
+ };
3285
+ /** End the load and let the reader have the button back. */
3286
+ const finish = () => {
3287
+ phase = "idle";
3288
+ if (frame !== 0) {
3289
+ win.cancelAnimationFrame(frame);
3290
+ frame = 0;
3291
+ }
3292
+ const scrollerEl = scroller();
3293
+ if (scrollerEl) {
3294
+ correct(scrollerEl);
3295
+ lastScrollTop = scrollerEl.scrollTop;
3296
+ }
3297
+ enableAnchoring();
3298
+ bearing = void 0;
3299
+ ownWriteTop = void 0;
3300
+ hideIndicator();
3301
+ };
3302
+ /**
3303
+ * Ask the host for the previous page.
3304
+ *
3305
+ * The host's own button is clicked, so the host does everything it does for
3306
+ * a reader who clicks it by hand: it retains the row it marks for paging,
3307
+ * pauses following the tail, and puts that row back where it was once the
3308
+ * older page has landed.
3309
+ *
3310
+ * The row the reader is reading is marked down before the click, and the
3311
+ * browser's own anchoring is switched off, so that this module's correction
3312
+ * is the only one made.
3313
+ */
3314
+ const trigger = () => {
3315
+ if (phase === "loading") return;
3316
+ const scrollerEl = scroller();
3317
+ if (!scrollerEl) return;
3318
+ const button = loadButton();
3319
+ if (!button || button.disabled) return;
3320
+ const held = bearingOf(scrollerEl);
3321
+ if (!held) return;
3322
+ phase = "loading";
3323
+ lastTriggerGesture = gestureSeq;
3324
+ sawDisabled = false;
3325
+ buttonBack = false;
3326
+ changed = false;
3327
+ lastChangeAt = 0;
3328
+ startedAt = win.performance.now();
3329
+ deadline = startedAt + SETTLE_LIMIT_MS;
3330
+ lastHeight = scrollerEl.scrollHeight;
3331
+ lastRows = rowCount();
3332
+ bearing = held;
3333
+ disableAnchoring();
3334
+ showIndicator(scrollerEl);
3335
+ button.click();
3336
+ frame = win.requestAnimationFrame(tick);
3337
+ };
3338
+ /**
3339
+ * Whether the reader's movement may ask for a page.
3340
+ *
3341
+ * Three things have to hold: no load is on its way, this gesture has not
3342
+ * already asked for one, and the list is at the top.
3343
+ */
3344
+ const mayTrigger = () => {
3345
+ if (phase === "loading") return false;
3346
+ if (gestureSeq === lastTriggerGesture) return false;
3347
+ const scrollerEl = scroller();
3348
+ if (!scrollerEl) return false;
3349
+ return scrollerEl.scrollTop <= 160;
3350
+ };
3351
+ /** Follow the load until the transcript settles. */
3352
+ const tick = () => {
3353
+ frame = 0;
3354
+ if (disposed || phase !== "loading") return;
3355
+ const scrollerEl = scroller();
3356
+ if (!scrollerEl) {
3357
+ finish();
3358
+ return;
3359
+ }
3360
+ if (syncSession()) {
3361
+ reset();
3362
+ return;
3363
+ }
3364
+ const now = win.performance.now();
3365
+ const visibleFor = now - startedAt;
3366
+ if (loadButton()?.disabled === true) sawDisabled = true;
3367
+ else if (sawDisabled) buttonBack = true;
3368
+ if (scrollerEl.scrollHeight !== lastHeight || rowCount() !== lastRows) {
3369
+ changed = true;
3370
+ lastChangeAt = now;
3371
+ lastHeight = scrollerEl.scrollHeight;
3372
+ lastRows = rowCount();
3373
+ }
3374
+ correct(scrollerEl);
3375
+ loadRow()?.setAttribute(LOADING_ATTR, "");
3376
+ placeIndicator(scrollerEl);
3377
+ if (changed && now - lastChangeAt >= 480) {
3378
+ finish();
3379
+ return;
3380
+ }
3381
+ if (buttonBack && !changed) {
3382
+ finish();
3383
+ return;
3384
+ }
3385
+ if (!sawDisabled && !changed && visibleFor > LOAD_GIVE_UP_MS) {
3386
+ finish();
3387
+ return;
3388
+ }
3389
+ if (now > deadline) {
3390
+ finish();
3391
+ return;
3392
+ }
3393
+ frame = win.requestAnimationFrame(tick);
3394
+ };
3395
+ /** The reader scrolled: their gesture is the only thing that may trigger a load. */
3396
+ const onScroll = () => {
3397
+ const scrollerEl = scroller();
3398
+ if (!scrollerEl) return;
3399
+ const top = scrollerEl.scrollTop;
3400
+ if (syncSession()) {
3401
+ reset();
3402
+ lastScrollTop = top;
3403
+ return;
3404
+ }
3405
+ const moved = top - lastScrollTop;
3406
+ lastScrollTop = top;
3407
+ const echo = ownWriteTop !== void 0 && Math.abs(top - ownWriteTop) <= WRITE_EPS;
3408
+ if (ownWriteTop !== void 0) ownWriteTop = void 0;
3409
+ if (phase === "loading") return;
3410
+ if (echo) return;
3411
+ if (moved >= -.5) return;
3412
+ if (!mayTrigger()) return;
3413
+ trigger();
3414
+ };
3415
+ /**
3416
+ * The reader wheeled up over the transcript.
3417
+ *
3418
+ * The wheel is a gesture of its own, so it may ask for a page on its own.
3419
+ * The reader who is already at the top and wheels up again does not move
3420
+ * the list at all, and no scroll follows to ask for the page; without this
3421
+ * the reader would have to scroll down and back up to get their history.
3422
+ */
3423
+ const onWheel = (event) => {
3424
+ const scrollerEl = scroller();
3425
+ if (!scrollerEl) return;
3426
+ const node = event.target;
3427
+ if (!(node instanceof win.Node)) return;
3428
+ if (!scrollerEl.contains(node)) return;
3429
+ if (!(event.deltaY < 0)) return;
3430
+ markGesture();
3431
+ if (!mayTrigger()) return;
3432
+ trigger();
3433
+ };
3434
+ /** The reader grabbed the scrollbar: a drag is a gesture of its own. */
3435
+ const onPointerDown = (event) => {
3436
+ const scrollerEl = scroller();
3437
+ if (!scrollerEl) return;
3438
+ const node = event.target;
3439
+ if (!(node instanceof win.Node)) return;
3440
+ if (!scrollerEl.contains(node)) return;
3441
+ gestureSeq += 1;
3442
+ gestureUntil = win.performance.now() + GESTURE_WINDOW_MS;
3443
+ };
3444
+ const onKeyDown = (event) => {
3445
+ const key = event.key;
3446
+ if (![
3447
+ "ArrowUp",
3448
+ "PageUp",
3449
+ "Home"
3450
+ ].includes(key)) return;
3451
+ markGesture();
3452
+ if (!mayTrigger()) return;
3453
+ trigger();
3454
+ };
3455
+ /** A different conversation is open: drop the pending load. */
3456
+ const reset = () => {
3457
+ finish();
3458
+ gestureSeq += 1;
3459
+ lastTriggerGesture = -1;
3460
+ lastScrollTop = scroller()?.scrollTop ?? 0;
3461
+ };
3462
+ /**
3463
+ * Read the open conversation and record it.
3464
+ *
3465
+ * The binding may not be readable when the plugin mounts and becomes
3466
+ * readable a moment later; that first answer is adopted, not treated as a
3467
+ * change, or the very first load would be cancelled as a session switch.
3468
+ * @returns true only when a known conversation was replaced by another.
3469
+ */
3470
+ function syncSession() {
3471
+ const key = sessionKeyOf(ctx);
3472
+ if (key === void 0) return false;
3473
+ if (session === void 0) {
3474
+ session = key;
3475
+ return false;
3476
+ }
3477
+ if (key === session) return false;
3478
+ session = key;
3479
+ return true;
3480
+ }
3481
+ const stopSession = subscribeSession(ctx, () => {
3482
+ if (syncSession()) reset();
3483
+ });
3484
+ root.addEventListener("scroll", onScroll, {
3485
+ capture: true,
3486
+ passive: true
3487
+ });
3488
+ root.addEventListener("wheel", onWheel, { passive: true });
3489
+ root.addEventListener("pointerdown", onPointerDown, { passive: true });
3490
+ root.addEventListener("keydown", onKeyDown);
3491
+ lastScrollTop = scroller()?.scrollTop ?? 0;
3492
+ return () => {
3493
+ disposed = true;
3494
+ finish();
3495
+ stopSession();
3496
+ root.removeEventListener("scroll", onScroll, { capture: true });
3497
+ root.removeEventListener("wheel", onWheel);
3498
+ root.removeEventListener("pointerdown", onPointerDown);
3499
+ root.removeEventListener("keydown", onKeyDown);
3500
+ };
3501
+ }
3502
+ /**
3503
+ * The host's binding for the conversation in the main column.
3504
+ * @param ctx - client root.
3505
+ * @returns the binding, when the host exposes one.
3506
+ */
3507
+ function bindingOf(ctx) {
3508
+ const ui = ctx.uiSession;
3509
+ return ui?.adapter?.current ?? ui?.current;
3510
+ }
3511
+ /**
3512
+ * The conversation the main column is showing.
3513
+ * @param ctx - client root.
3514
+ * @returns the session id, or undefined when the host does not say.
3515
+ */
3516
+ function sessionKeyOf(ctx) {
3517
+ const binding = bindingOf(ctx);
3518
+ if (!binding) return void 0;
3519
+ try {
3520
+ const current = binding.getSnapshot?.() ?? binding.value;
3521
+ const key = current?.key ?? current?.props?.sessionId;
3522
+ return typeof key === "string" ? key : void 0;
3523
+ } catch {
3524
+ return;
3525
+ }
3526
+ }
3527
+ /**
3528
+ * Follow the conversation the main column is showing.
3529
+ * @param ctx - client root.
3530
+ * @param listener - called when the conversation changes.
3531
+ * @returns a cleanup function.
3532
+ */
3533
+ function subscribeSession(ctx, listener) {
3534
+ const binding = bindingOf(ctx);
3535
+ try {
3536
+ const stop = binding?.subscribe?.(() => listener());
3537
+ if (typeof stop === "function") return stop;
3538
+ } catch {}
3539
+ return () => {};
3540
+ }
3541
+ /**
3542
+ * The indicator, and the rule that takes the host's button out of the picture
3543
+ * while it is up. The button keeps its place: the indicator is not in the
3544
+ * host's row, so nothing is pushed around by it, and the row keeps the height
3545
+ * it had, so the list does not jump when the indicator comes up.
3546
+ *
3547
+ * The browser's own anchoring is not in this sheet: it is switched off at
3548
+ * runtime, and only while the older page is on its way, by a style this
3549
+ * module injects and takes away again when the page has landed. A sheet that
3550
+ * is mounted for the whole session would switch the browser's anchoring off
3551
+ * for the whole session as well, and the host's own paging would lose it.
3552
+ */
3553
+ const css = `
3554
+ [data-dsh-enhance-older-loading] button {
3555
+ visibility: hidden !important;
3556
+ }
3557
+ .dsh-enhance-older-spinner {
3558
+ position: fixed !important;
3559
+ top: var(--dsh-enhance-older-y, 0px) !important;
3560
+ left: var(--dsh-enhance-older-x, 0px) !important;
3561
+ transform: translate(-50%, -50%) !important;
3562
+ display: inline-flex !important;
3563
+ align-items: center !important;
3564
+ justify-content: center !important;
3565
+ gap: 6px !important;
3566
+ box-sizing: border-box !important;
3567
+ height: 26px !important;
3568
+ padding: 0 11px !important;
3569
+ border-radius: 9999px !important;
3570
+ background: color-mix(in srgb, var(--bt-main, #fff) 82%, transparent) !important;
3571
+ border: 1px solid var(--bt-line, rgba(20, 20, 20, .08)) !important;
3572
+ box-shadow: 0 6px 18px -8px rgba(0, 0, 0, .28), 0 1px 3px rgba(0, 0, 0, .06) !important;
3573
+ -webkit-backdrop-filter: blur(16px) saturate(1.6) !important;
3574
+ backdrop-filter: blur(16px) saturate(1.6) !important;
3575
+ color: var(--bt-ink-2, rgba(20, 20, 20, .6)) !important;
3576
+ font-size: 12px !important;
3577
+ line-height: 1 !important;
3578
+ letter-spacing: .01em !important;
3579
+ white-space: nowrap !important;
3580
+ pointer-events: none !important;
3581
+ user-select: none !important;
3582
+ z-index: 40 !important;
3583
+ }
3584
+ .dsh-enhance-older-ring {
3585
+ flex: none !important;
3586
+ width: 12px !important;
3587
+ height: 12px !important;
3588
+ border-radius: 50% !important;
3589
+ border: 1.5px solid color-mix(in srgb, currentColor 28%, transparent) !important;
3590
+ border-top-color: currentColor !important;
3591
+ animation: dsh-enhance-older-spin .8s linear infinite !important;
3592
+ }
3593
+ @keyframes dsh-enhance-older-spin {
3594
+ to { transform: rotate(360deg); }
3595
+ }
3596
+ @media (prefers-reduced-motion: reduce) {
3597
+ .dsh-enhance-older-ring {
3598
+ animation-duration: 2.6s !important;
3599
+ }
3600
+ }
3601
+ `;
2788
3602
  // src/client/styles.ts
2789
3603
  /** DSH sheet name to CSS, in cascade order: later sheets win ties against earlier ones. */
2790
3604
  const SHEETS = [
2791
- ["document-preview.css", css$9],
2792
- ["chat-markdown.css", css$8],
2793
- ["rightbar-handle.css", css$7],
2794
- ["running-spinner.css", css$6],
2795
- ["sidebar-density.css", css$5],
2796
- ["sidebar-layout.css", css$4],
2797
- ["toolbar.css", css$3],
2798
- ["file-menu.css", css$2]
3605
+ ["document-preview.css", css$11],
3606
+ ["chat-markdown.css", css$10],
3607
+ ["rightbar-handle.css", css$9],
3608
+ ["running-spinner.css", css$8],
3609
+ ["sidebar-density.css", css$7],
3610
+ ["sidebar-layout.css", css$6],
3611
+ ["toolbar.css", css$5],
3612
+ ["file-menu.css", css$4],
3613
+ ["annotation-display.css", css$3]
2799
3614
  ];
2800
3615
  /** DS Bot mounts the shared rules plus its own chrome and md anchors; no DSH chrome. */
2801
3616
  const DS_BOT_SHEETS = [
2802
3617
  ...[
2803
- ["document-preview.css", css$9],
2804
- ["chat-markdown.css", css$8],
2805
- ["toolbar.css", css$3],
2806
- ["file-menu.css", css$2]
3618
+ ["document-preview.css", css$11],
3619
+ ["chat-markdown.css", css$10],
3620
+ ["toolbar.css", css$5],
3621
+ ["file-menu.css", css$4],
3622
+ ["annotation-display.css", css$3]
2807
3623
  ],
2808
- ["ds-bot-chrome.css", css$1],
2809
- ["ds-bot-markdown-anchors.css", css]
3624
+ ["ds-bot-chrome.css", css$2],
3625
+ ["ds-bot-markdown-anchors.css", css$1],
3626
+ ["ds-bot-older.css", css]
2810
3627
  ];
2811
3628
  /**
2812
3629
  * The sheet set for one surface. The two sets never mount together.
@@ -5114,7 +5931,10 @@ ${fallback} li::marker {
5114
5931
  "linkMenu.done.opened": "已打开",
5115
5932
  "linkMenu.done.copied": "已复制链接",
5116
5933
  "linkMenu.done.saved": "已保存",
5117
- "linkMenu.saveFailed": "无法下载该链接(可能受跨域限制)"
5934
+ "linkMenu.saveFailed": "无法下载该链接(可能受跨域限制)",
5935
+ "anno.quote": "引用原文",
5936
+ "anno.comment": "我的意见",
5937
+ "autoLoad.loading": "正在加载更早的消息…"
5118
5938
  };
5119
5939
  /** Toolbar copy, English. */
5120
5940
  const en = {
@@ -5162,7 +5982,10 @@ ${fallback} li::marker {
5162
5982
  "linkMenu.done.opened": "Opened",
5163
5983
  "linkMenu.done.copied": "Link copied",
5164
5984
  "linkMenu.done.saved": "Saved",
5165
- "linkMenu.saveFailed": "Could not download this link (cross-origin restrictions may apply)"
5985
+ "linkMenu.saveFailed": "Could not download this link (cross-origin restrictions may apply)",
5986
+ "anno.quote": "Quoted text",
5987
+ "anno.comment": "User comment",
5988
+ "autoLoad.loading": "Loading earlier messages…"
5166
5989
  };
5167
5990
  // src/client/anchors.ts
5168
5991
  /** Any transcript row the plugin may anchor to. */
@@ -6036,7 +6859,7 @@ ${fallback} li::marker {
6036
6859
  publish();
6037
6860
  }
6038
6861
  /** Column the body of an entry sits at, so it lines up under its label. */
6039
- const INDENT = " ";
6862
+ const INDENT$1 = " ";
6040
6863
  /**
6041
6864
  * Put a block of text under the annotation's labels, one indented line per
6042
6865
  * line of the original.
@@ -6048,7 +6871,7 @@ ${fallback} li::marker {
6048
6871
  * @returns the indented lines.
6049
6872
  */
6050
6873
  function indentedLines(text) {
6051
- return text.split("\n").map((line) => line.length === 0 ? "" : `${INDENT}${line}`);
6874
+ return text.split("\n").map((line) => line.length === 0 ? "" : `${INDENT$1}${line}`);
6052
6875
  }
6053
6876
  /**
6054
6877
  * Render one annotation as two labelled blocks: the passage, then the comment.
@@ -6073,7 +6896,7 @@ ${fallback} li::marker {
6073
6896
  const lines = ["Selected text:", ...indentedLines(passage.length > 140 ? `${passage.slice(0, 139)}…` : passage)];
6074
6897
  const note = annotation.note.replace(/\r\n|\r/g, "\n").trim();
6075
6898
  if (note.length > 0) {
6076
- lines.push(`${INDENT}User comment:`);
6899
+ lines.push(`${INDENT$1}User comment:`);
6077
6900
  lines.push(...indentedLines(note));
6078
6901
  }
6079
6902
  return lines.join("\n");
@@ -6899,6 +7722,283 @@ ${fallback} li::marker {
6899
7722
  return element.closest("[data-sidebar-chat], [data-dsh-enhance-side-chat]") === null;
6900
7723
  }, [root]);
6901
7724
  }
7725
+ // src/client/AnnotationDisplay.tsx
7726
+ /**
7727
+ * Render one annotation entry.
7728
+ * @param props - the node and the translator.
7729
+ * @returns the labelled group.
7730
+ */
7731
+ function AnnotationDisplay(props) {
7732
+ const { number, quote, comment } = props.node.data;
7733
+ const t = props.t;
7734
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
7735
+ className: "dsh-enhance-anno",
7736
+ children: [
7737
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
7738
+ className: "dsh-enhance-anno__head",
7739
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7740
+ className: "dsh-enhance-anno__number",
7741
+ children: `${number}.`
7742
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7743
+ className: "dsh-enhance-anno__label dsh-enhance-anno__label--quote",
7744
+ children: t("anno.quote")
7745
+ })]
7746
+ }),
7747
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7748
+ className: "dsh-enhance-anno__gutter",
7749
+ "aria-hidden": "true"
7750
+ }),
7751
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7752
+ className: "dsh-enhance-anno__quote",
7753
+ children: quote.join("\n")
7754
+ }),
7755
+ comment === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
7756
+ className: "dsh-enhance-anno__comment-block",
7757
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7758
+ className: "dsh-enhance-anno__label dsh-enhance-anno__label--comment",
7759
+ children: t("anno.comment")
7760
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
7761
+ className: "dsh-enhance-anno__comment",
7762
+ children: comment.join("\n")
7763
+ })]
7764
+ })
7765
+ ]
7766
+ });
7767
+ }
7768
+ // src/client/annotation-display.ts
7769
+ /**
7770
+ * Read the annotation entries back out of one sent message, so the transcript
7771
+ * can show them as labelled blocks instead of the raw wire text.
7772
+ *
7773
+ * `annotationsPrompt` writes numbered entries under a plain summary:
7774
+ *
7775
+ * 总结在前。
7776
+ * 1. Selected text:
7777
+ * excerpt line
7778
+ * User comment:
7779
+ * comment line
7780
+ *
7781
+ * 2. Selected text:
7782
+ * ...
7783
+ *
7784
+ * The outgoing message is unchanged — the model still receives exactly that
7785
+ * text, and copying the message still yields it. This module only recognises
7786
+ * the shape so a display rule can paint it. Recognition is deliberately strict:
7787
+ * the number must start at 1 and run consecutively, the `Selected text:` header
7788
+ * must end its line, and every body line must sit at the three-space column the
7789
+ * writer emits. A message that merely mentions "Selected text:" in prose is not
7790
+ * a match, which is what keeps ordinary messages untouched.
7791
+ */
7792
+ /** Column the body of an entry sits at; must match `annotations.ts`. */
7793
+ const INDENT = " ";
7794
+ /** One entry header, anchored to a whole line. */
7795
+ const HEADER = /^(\d+)\. Selected text:$/;
7796
+ /**
7797
+ * A code fence marker at the very start of a line.
7798
+ *
7799
+ * Only a fence that sits in column zero — or one or two spaces in — opens a
7800
+ * code block here. The body of an entry is always indented by three spaces, so
7801
+ * a fence the reader wrote inside a passage or a comment stays part of that
7802
+ * block: it is plain text to the transcript, not a code block, and it must not
7803
+ * swallow the entries that follow it.
7804
+ */
7805
+ const FENCE = /^ {0,2}(`{3,}|~{3,})(.*)$/;
7806
+ /**
7807
+ * Split the message into lines that remember where they start.
7808
+ * @param text - the whole message.
7809
+ * @returns one entry per line, including a trailing empty line after a final newline.
7810
+ */
7811
+ function linesOf(text) {
7812
+ const lines = [];
7813
+ let start = 0;
7814
+ for (;;) {
7815
+ const newline = text.indexOf("\n", start);
7816
+ const end = newline === -1 ? text.length : newline;
7817
+ const raw = text.slice(start, end);
7818
+ lines.push({
7819
+ raw,
7820
+ text: raw.endsWith("\r") ? raw.slice(0, -1) : raw,
7821
+ start
7822
+ });
7823
+ if (newline === -1) break;
7824
+ start = newline + 1;
7825
+ }
7826
+ return lines;
7827
+ }
7828
+ /**
7829
+ * Index of the next non-blank line at or after `from`.
7830
+ * @param lines - the message's lines.
7831
+ * @param from - where to start looking.
7832
+ * @returns that line's index, or undefined when only blanks remain.
7833
+ */
7834
+ function nextNonBlank(lines, from) {
7835
+ for (let index = from; index < lines.length; index += 1) if (lines[index].text.length > 0) return index;
7836
+ }
7837
+ /**
7838
+ * Mark the lines that belong to a fenced code block.
7839
+ *
7840
+ * A reader who pastes an example into their message — a snippet that happens
7841
+ * to look like an annotation — must not have it turned into a labelled block.
7842
+ * Only a fence in the first three columns opens a block here, because the body
7843
+ * of an annotation entry is always indented by three spaces: a fence inside a
7844
+ * passage is plain text to the transcript and stays part of that passage.
7845
+ *
7846
+ * A fence only counts when it is closed. An unterminated fence is ordinary
7847
+ * text, so it must not swallow the real entries that follow it.
7848
+ * @param lines - the message's lines.
7849
+ * @returns one flag per line, true when the line is part of a code block.
7850
+ */
7851
+ function fencedLines(lines) {
7852
+ const inside = new Array(lines.length).fill(false);
7853
+ for (let index = 0; index < lines.length; index += 1) {
7854
+ const open = FENCE.exec(lines[index].text);
7855
+ if (open === null) continue;
7856
+ const marker = open[1];
7857
+ const char = marker[0];
7858
+ const length = marker.length;
7859
+ let close = -1;
7860
+ for (let scan = index + 1; scan < lines.length; scan += 1) {
7861
+ const match = FENCE.exec(lines[scan].text);
7862
+ if (match === null) continue;
7863
+ const end = match[1];
7864
+ if (end[0] === char && end.length >= length && match[2].trim() === "") {
7865
+ close = scan;
7866
+ break;
7867
+ }
7868
+ }
7869
+ if (close === -1) continue;
7870
+ for (let mark = index; mark <= close; mark += 1) inside[mark] = true;
7871
+ index = close;
7872
+ }
7873
+ return inside;
7874
+ }
7875
+ /**
7876
+ * Parse one entry starting at its header line.
7877
+ * @param lines - the message's lines.
7878
+ * @param headerIndex - index of the `N. Selected text:` line.
7879
+ * @param textLength - total message length, for the end offset at EOF.
7880
+ * @param fenced - lines that belong to a code block.
7881
+ * @returns the entry, the index to continue scanning from, or undefined when the
7882
+ * lines under this header do not form a valid entry.
7883
+ */
7884
+ function parseEntry(lines, headerIndex, textLength, fenced) {
7885
+ const header = lines[headerIndex];
7886
+ const number = Number(HEADER.exec(header.text)[1]);
7887
+ const quote = [];
7888
+ const comment = [];
7889
+ let commentStarted = false;
7890
+ let index = headerIndex + 1;
7891
+ while (index < lines.length) {
7892
+ const line = lines[index];
7893
+ if (HEADER.test(line.text) && !fenced[index]) break;
7894
+ if (line.text.length === 0) {
7895
+ const ahead = nextNonBlank(lines, index);
7896
+ if (ahead === void 0) {
7897
+ index = lines.length;
7898
+ break;
7899
+ }
7900
+ if (!lines[ahead].text.startsWith(INDENT)) {
7901
+ index = ahead;
7902
+ break;
7903
+ }
7904
+ for (let blank = index; blank < ahead; blank += 1) if (commentStarted) comment.push("");
7905
+ else quote.push("");
7906
+ index = ahead;
7907
+ continue;
7908
+ }
7909
+ if (!line.text.startsWith(INDENT)) break;
7910
+ const content = line.text.slice(3);
7911
+ if (!commentStarted && content === "User comment:") {
7912
+ commentStarted = true;
7913
+ index += 1;
7914
+ continue;
7915
+ }
7916
+ if (commentStarted) comment.push(content);
7917
+ else quote.push(content);
7918
+ index += 1;
7919
+ }
7920
+ if (quote.every((line) => line.trim().length === 0)) return void 0;
7921
+ if (commentStarted && comment.every((line) => line.trim().length === 0)) return void 0;
7922
+ const end = index >= lines.length ? textLength : lines[index].start;
7923
+ return {
7924
+ entry: {
7925
+ start: header.start,
7926
+ end,
7927
+ number,
7928
+ quote,
7929
+ comment: commentStarted ? comment : void 0
7930
+ },
7931
+ next: index
7932
+ };
7933
+ }
7934
+ /**
7935
+ * Every annotation entry a message carries, in order.
7936
+ *
7937
+ * An entry only counts when its number continues the run from 1, so a message
7938
+ * that quotes a stray `7. Selected text:` in the middle of prose is not split.
7939
+ * @param text - the whole message.
7940
+ * @returns the recognised entries; empty when the message is not an annotation.
7941
+ */
7942
+ function parseAnnotationEntries(text) {
7943
+ const lines = linesOf(text);
7944
+ const fenced = fencedLines(lines);
7945
+ const entries = [];
7946
+ let expected = 1;
7947
+ let index = 0;
7948
+ while (index < lines.length) {
7949
+ const match = fenced[index] ? null : HEADER.exec(lines[index].text);
7950
+ if (match === null || Number(match[1]) !== expected) {
7951
+ index += 1;
7952
+ continue;
7953
+ }
7954
+ const parsed = parseEntry(lines, index, text.length, fenced);
7955
+ if (parsed === void 0) {
7956
+ index += 1;
7957
+ continue;
7958
+ }
7959
+ entries.push(parsed.entry);
7960
+ expected += 1;
7961
+ index = parsed.next;
7962
+ }
7963
+ return entries;
7964
+ }
7965
+ /** Identity the display rule registers under, and the node id it emits. */
7966
+ const ANNOTATION_RULE_ID = "dshEnhance.annotation";
7967
+ /**
7968
+ * User-text rule that lifts each annotation entry out of a message.
7969
+ *
7970
+ * One call returns the first entry at or after `from`; the evaluator calls it
7971
+ * again past that entry for the next one, so a message with several entries
7972
+ * becomes several nodes with the plain summary and body text kept around them.
7973
+ */
7974
+ const annotationDisplayRule = {
7975
+ id: ANNOTATION_RULE_ID,
7976
+ order: 5,
7977
+ /**
7978
+ * Match the next annotation entry.
7979
+ * @param text - the whole message.
7980
+ * @param from - offset the evaluator has reached.
7981
+ * @returns the next entry as a node, or undefined when none is left.
7982
+ */
7983
+ match(text, from) {
7984
+ for (const entry of parseAnnotationEntries(text)) {
7985
+ if (entry.start < from) continue;
7986
+ return {
7987
+ id: ANNOTATION_RULE_ID,
7988
+ start: entry.start,
7989
+ end: entry.end,
7990
+ data: entry.comment === void 0 ? {
7991
+ number: entry.number,
7992
+ quote: entry.quote
7993
+ } : {
7994
+ number: entry.number,
7995
+ quote: entry.quote,
7996
+ comment: entry.comment
7997
+ }
7998
+ };
7999
+ }
8000
+ }
8001
+ };
6902
8002
  // src/client/SideChatBody.tsx
6903
8003
  /**
6904
8004
  * Bind the tab's retained conversation around its slot.
@@ -7069,7 +8169,8 @@ ${fallback} li::marker {
7069
8169
  "resources",
7070
8170
  "sidebarRightTabs",
7071
8171
  "remote",
7072
- "remote.session"
8172
+ "remote.session",
8173
+ "uiConversation"
7073
8174
  ];
7074
8175
  /**
7075
8176
  * Mount the plugin.
@@ -7097,6 +8198,7 @@ ${fallback} li::marker {
7097
8198
  if (features.sidebarTopRow) ctx.effect(() => installSidebarTopRow(document), "dsh-enhance: sidebar top row");
7098
8199
  if (features.panelWidths) ctx.effect(() => installPanelWidths(document), "dsh-enhance: panel widths");
7099
8200
  if (features.liquidGlass) ctx.effect(() => installLiquidGlass(document), "dsh-enhance: liquid glass");
8201
+ if (features.autoLoadEarlier) ctx.effect(() => installAutoLoadEarlier(ctx, document, t), "dsh-enhance: auto load earlier");
7100
8202
  if (features.sectionStats) ctx.effect(() => installSectionStats(ctx, document), "dsh-enhance: section stats");
7101
8203
  if (features.windowGeometry && isDesktopShell()) ctx.effect(() => installStartupGeometry(window), "dsh-enhance: window geometry");
7102
8204
  if (features.badge) ctx.effect(() => installTurnBadge(ctx), "dsh-enhance: turn badge");
@@ -7143,6 +8245,15 @@ ${fallback} li::marker {
7143
8245
  locale: LOCALE_NS,
7144
8246
  inject: () => ({ askInSideChat })
7145
8247
  }, AnnotationSeat)), "dsh-enhance: annotation seat");
8248
+ if (features.annotations) {
8249
+ ctx.effect(() => ctx.uiConversation.userText.register(annotationDisplayRule), "dsh-enhance: annotation display rule");
8250
+ ctx.effect(() => ctx.slots.inject("conversation.user.text.node", () => ctx.slots.register({
8251
+ name: "conversation.user.text.node",
8252
+ key: ANNOTATION_RULE_ID,
8253
+ priority: 100,
8254
+ inject: () => ({ t })
8255
+ }, AnnotationDisplay)), "dsh-enhance: annotation display");
8256
+ }
7146
8257
  }
7147
8258
  /**
7148
8259
  * The workspace a side conversation for one passage belongs in.