dsh-enhance 0.3.8 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +166 -87
  2. package/lib/client.js +2292 -85
  3. package/lib/index.js +45 -44
  4. package/package.json +2 -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$7 = 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$6 = 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$5 = 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$4 = 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$3 = 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$2 = 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$1 = 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 = 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,23 +2229,1412 @@ 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
+ }
2368
+ `;
2369
+ // src/client/surfaces/ds-bot/chrome.ts
2370
+ /** DS Bot-only chrome. Shared Markdown and annotation sheets are unchanged.
2371
+ * The desktop preload sets data-windows-titlebar, caption height 40px and
2372
+ * --dsh-frame-chrome-top:0px: the viewport reaches the native window top.
2373
+ * material.css pads the chat column by the caption height; remove that padding
2374
+ * so the host's absolute header can keep its horizontal layout at top:20px.
2375
+ */
2376
+ const CORNER_ROW = ":is(.bt-pane, .bt-panel) .bt-drawer-top";
2377
+ const PILL_HEADER = "header[class*=\"_header\"]:has(.bt-head)";
2378
+ const css$2 = `
2379
+ /* Keep user messages on the current theme's surface instead of an inverted
2380
+ black/white slab. Theme inks retain readable text and adapt to custom themes. */
2381
+ body {
2382
+ --bt-user: color-mix(in srgb, var(--bt-ink) 7%, var(--bt-main)) !important;
2383
+ --bt-user-ink: var(--bt-ink) !important;
2384
+ }
2385
+ body[data-ds-dark-theme] {
2386
+ --bt-user: color-mix(in srgb, var(--bt-ink) 12%, var(--bt-main)) !important;
2387
+ }
2388
+
2389
+ /* Shift the entire sidebar stack, including the list, with its action row.
2390
+ The native traffic-light/sidebar switch belongs to another shell element.
2391
+ The row sits in the 40px caption band: its buttons are 30px, starting at
2392
+ 5px so their centre (20px) lines up with the 14px traffic lights. */
2393
+ .bt-leftcol {
2394
+ padding-top: 5px !important;
2395
+ }
2396
+ .bt-leftcol .bt-side-top {
2397
+ padding-top: 0 !important;
2398
+ padding-right: 0 !important;
2399
+ gap: 3px !important;
2400
+ -webkit-app-region: no-drag !important;
2401
+ }
2402
+ .bt-leftcol .bt-side-top button {
2403
+ -webkit-app-region: no-drag !important;
2404
+ width: 30px !important;
2405
+ height: 30px !important;
2406
+ }
2407
+ .bt-leftcol .bt-side-top .bt-round svg {
2408
+ width: 18px !important;
2409
+ height: 18px !important;
2410
+ }
2411
+
2412
+ /* The visible inner corner belongs to the chat column, not .bt-leftcol.
2413
+ Removing its caption padding also keeps the header inside its clipping root. */
2414
+ html[data-windows-titlebar] div[class*="_centerCol"] {
2415
+ padding-top: 0 !important;
2416
+ border-top-left-radius: 0 !important;
2417
+ }
2418
+
2419
+ /* Desktop material.css reserves a second caption band on the host's right
2420
+ column using a 40px top border. File, browser and terminal tabs share this
2421
+ column; let their own tab-strip padding supply the top clearance instead. */
2422
+ html[data-windows-titlebar] div[class*="_rightbarCol"] {
2423
+ border-top: 0 !important;
2424
+ }
2425
+
2426
+ /* With that 40px band gone the dockkit tab strip sits inside the native
2427
+ title-bar drag region. The host marks the strip itself as a window drag
2428
+ handle (data-window-drag → app-region: drag), so the strip's own padding,
2429
+ the gap between tabs and the empty span beside the buttons all drag the
2430
+ window: a click there moves the window instead of reaching the bar, and the
2431
+ whole row reads as dead. Make the entire strip — tabs, close, +, split,
2432
+ fullscreen, collapse and the space around them — one no-drag island.
2433
+ Nothing is repositioned, so the removed 40px blank band stays gone. */
2434
+ html[data-windows-titlebar] [class*="_tabStrip_"],
2435
+ html[data-windows-titlebar] [class*="_tabStrip_"] *,
2436
+ html[data-windows-titlebar] [class*="_stripTabs_"],
2437
+ html[data-windows-titlebar] [class*="_stripChrome_"],
2438
+ html[data-windows-titlebar] [class*="_tab_"],
2439
+ html[data-windows-titlebar] [class*="_tabClose_"],
2440
+ html[data-windows-titlebar] [class*="_addTab_"] {
2441
+ -webkit-app-region: no-drag !important;
2442
+ }
2443
+
2444
+ /* The composer's "/" command menu is nested inside the composer card, which
2445
+ sets its own backdrop-filter. A backdrop-filter turns its element into a
2446
+ backdrop root, so the menu material's own backdrop-filter (the host declares
2447
+ blur(40px)) has nothing to sample and never paints: the conversation text
2448
+ behind the menu reads straight through it. Drop the card's blur only while
2449
+ one of the composer's trigger menus is open, so the menu can sample the page
2450
+ again and its declared blur finally frosts out the text behind it. The card's
2451
+ blur returns as soon as the menu closes; the title pill and every menu that
2452
+ is not rendered inside the composer card are untouched. */
2453
+ [data-composer-card]:has([data-trigger-menu]) {
2454
+ -webkit-backdrop-filter: none !important;
2455
+ backdrop-filter: none !important;
2456
+ }
2457
+
2458
+ /* Keep the user's settled 12px top offset. Absolute positioning preserves
2459
+ the host's horizontal centring as the sidebar and detail panel resize. */
2460
+ ${PILL_HEADER} {
2461
+ top: 12px !important;
2462
+ padding: 0 !important;
2463
+ }
2464
+
2465
+ /* The host's fading header backdrop must not paint a horizontal light band,
2466
+ and its 60px-tall ::before band also intercepted clicks over the pill's top
2467
+ half (only the bottom sliver stayed hittable). Remove it entirely. */
2468
+ ${PILL_HEADER}::before {
2469
+ content: none !important;
2470
+ background: none !important;
2471
+ height: 0 !important;
2472
+ pointer-events: none !important;
2473
+ }
2474
+
2475
+ /* Keep the pill fully clickable: the header/head pass clicks through except on
2476
+ the pill itself, and the pill is never a window-drag handle. */
2477
+ ${PILL_HEADER} .bt-head {
2478
+ height: 50px !important;
2479
+ pointer-events: none !important;
2480
+ }
2481
+ ${PILL_HEADER} .bt-pill,
2482
+ ${PILL_HEADER} .bt-pill * {
2483
+ pointer-events: auto !important;
2484
+ -webkit-app-region: no-drag !important;
2485
+ }
2486
+
2487
+ /* Liquid glass on the session-title pill, ported from
2488
+ lucasromerodb/liquid-glass-effect-macos (the source behind the user's
2489
+ CodeSandbox reference nn5q2y; that repo ships no LICENSE and is used as an
2490
+ effect reference only). The reference layers one clipped shape as:
2491
+ effect layer - backdrop-filter: blur(3px) AND filter: url(#glass-distortion)
2492
+ on the SAME element, so the backdrop is softened first and
2493
+ bent afterwards by the turbulence displacement map;
2494
+ tint layer - a flat white 25% film over the bend;
2495
+ shine layer - two inset white shadows that draw the lit lip;
2496
+ text layer - the content, above every layer.
2497
+ Here the effect layer is ::before, the tint and the shine share ::after, and
2498
+ the pill's own box clips both to the capsule. The pill carries no border: the
2499
+ reference has none, and its only outline is the shine. The soft drop shadow
2500
+ is kept light. Padding grows by 5px on each side; height grows accordingly
2501
+ so the avatar and title keep the same space inside the capsule. */
2502
+ ${PILL_HEADER} .bt-pill {
2503
+ position: relative !important;
2504
+ height: 50px !important;
2505
+ padding: 12.5px 18.5px 12.5px 12.5px !important;
2506
+ /* Own the silhouette instead of inheriting a host/theme corner radius. */
2507
+ border-radius: 9999px !important;
2508
+ corner-shape: round !important;
2509
+ overflow: hidden !important;
2510
+ background: transparent !important;
2511
+ -webkit-backdrop-filter: none !important;
2512
+ backdrop-filter: none !important;
2513
+ --dsh-lg-tint: rgba(255, 255, 255, .25);
2514
+ /* No border: the reference draws the edge with the shine layer alone. */
2515
+ border: none !important;
2516
+ box-shadow:
2517
+ 0 2px 5px rgba(0, 0, 0, .10),
2518
+ 0 0 8px rgba(0, 0, 0, .04) !important;
2519
+ }
2520
+
2521
+ /* Dark glass takes a much lighter white tint: the backdrop is already dark, and
2522
+ the reference's 25% film over it turns the pill into a grey card. */
2523
+ body[data-ds-dark-theme] ${PILL_HEADER} .bt-pill {
2524
+ --dsh-lg-tint: rgba(255, 255, 255, .08);
2525
+ box-shadow:
2526
+ 0 3px 3px rgba(0, 0, 0, .34),
2527
+ 0 0 10px rgba(0, 0, 0, .18) !important;
2528
+ }
2529
+
2530
+ /* The glass itself: the softening pass and the bend ride the same element, as
2531
+ in the reference. The bend uses the plain filter property because Chromium
2532
+ drops a url() from backdrop-filter; the unset variable keeps this at none, so
2533
+ the frosted fallback still works. */
2534
+ ${PILL_HEADER} .bt-pill::before {
2535
+ content: "" !important;
2536
+ position: absolute !important;
2537
+ inset: 0 !important;
2538
+ z-index: 0 !important;
2539
+ border-radius: inherit !important;
2540
+ corner-shape: round !important;
2541
+ overflow: hidden !important;
2542
+ isolation: isolate !important;
2543
+ -webkit-backdrop-filter: var(--dsh-lg-backdrop, blur(3px)) !important;
2544
+ backdrop-filter: var(--dsh-lg-backdrop, blur(3px)) !important;
2545
+ -webkit-filter: var(--dsh-lg-filter, none) !important;
2546
+ filter: var(--dsh-lg-filter, none) !important;
2547
+ pointer-events: none !important;
2548
+ }
2549
+
2550
+ /* The body of the glass and its lip: the reference's flat white film plus its
2551
+ two inset shines, one catching the light on the top-left curve and one
2552
+ holding the bottom-right edge. That pair is what makes the outline read as
2553
+ a thin bright lip at 1x; a single top highlight only brightens the top. */
2554
+ ${PILL_HEADER} .bt-pill::after {
2555
+ content: "" !important;
2556
+ position: absolute !important;
2557
+ inset: 0 !important;
2558
+ z-index: 2 !important;
2559
+ border-radius: inherit !important;
2560
+ corner-shape: round !important;
2561
+ background: var(--dsh-lg-tint) !important;
2562
+ box-shadow:
2563
+ inset .5px .5px .75px 0 rgba(255, 255, 255, .45),
2564
+ inset -.5px -.5px .75px 0 rgba(255, 255, 255, .28) !important;
2565
+ pointer-events: none !important;
2566
+ }
2567
+
2568
+ /* Avatar, name and back arrow sit above both layers so the text stays crisp
2569
+ instead of getting washed by the tint. */
2570
+ ${PILL_HEADER} .bt-pill > * {
2571
+ position: relative !important;
2572
+ z-index: 3 !important;
2573
+ }
2574
+
2575
+ /* A single gentle squash-and-stretch on entry, then settle at the original
2576
+ size. The outer header stays still, preserving centring and hit geometry. */
2577
+ @keyframes dsh-pill-pop {
2578
+ 0% { transform: scale(1); }
2579
+ 35% { transform: scale(1.045, .96); }
2580
+ 65% { transform: scale(.985, 1.025); }
2581
+ 100% { transform: scale(1); }
2582
+ }
2583
+ ${PILL_HEADER} .bt-pill:hover {
2584
+ --dsh-lg-tint: rgba(255, 255, 255, .32);
2585
+ animation: dsh-pill-pop 440ms cubic-bezier(.22, .61, .36, 1) both !important;
2586
+ }
2587
+ body[data-ds-dark-theme] ${PILL_HEADER} .bt-pill:hover {
2588
+ --dsh-lg-tint: rgba(255, 255, 255, .12);
2589
+ }
2590
+ ${PILL_HEADER} .bt-pill:active {
2591
+ animation: none !important;
2592
+ transform: scale(.97) !important;
2593
+ }
2594
+ @media (prefers-reduced-motion: reduce) {
2595
+ ${PILL_HEADER} .bt-pill:hover,
2596
+ ${PILL_HEADER} .bt-pill:active {
2597
+ animation: none !important;
2598
+ transform: none !important;
2599
+ }
2600
+ }
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
+
2624
+ /* The settled panel starts at chrome-top. Absolute positioning also follows
2625
+ its entrance animation instead of changing fixed containing blocks midway.
2626
+ Top-aligned with the 14px traffic lights (their top sits at 13px in the 40px
2627
+ band), as requested — the row's own top edge matches the lights' top edge. */
2628
+ ${CORNER_ROW} {
2629
+ position: absolute !important;
2630
+ top: calc(13px - var(--dsh-frame-chrome-top, 0px)) !important;
2631
+ right: 20px !important;
2632
+ margin: 0 !important;
2633
+ padding: 0 !important;
2634
+ z-index: 50 !important;
2635
+ justify-content: flex-end !important;
2636
+ }
2637
+
2638
+ /* Buttons inside the native caption band must remain interactive. The host
2639
+ already exempts the pill; also exempt the relocated panel controls. */
2640
+ ${CORNER_ROW},
2641
+ ${CORNER_ROW} button,
2642
+ .bt-panel .bt-subhead button {
2643
+ -webkit-app-region: no-drag !important;
2644
+ }
2645
+
2646
+ /* Reserve the detached buttons' 36px height down to viewport y=49 (13 + 36). */
2647
+ .bt-panel-view:has(> .bt-drawer-top) {
2648
+ padding-top: max(0px, calc(49px - var(--bt-caption-band, 0px))) !important;
2649
+ }
2650
+
2651
+ /* The settings view uses an in-flow subheader instead of .bt-drawer-top.
2652
+ Without a tab strip, replace the inherited 40px band with the 20px inset
2653
+ (10px panel clearance plus the subheader's existing 10px padding). */
2654
+ html[data-windows-titlebar] .bt-panel:not(:has(> .bt-ptabs)):has(> .bt-panel-view > .bt-subhead) {
2655
+ padding-top: 10px !important;
2656
+ }
2657
+
2658
+ /* The host paints its whole --bt-caption-band as a positioned, drag-region
2659
+ ::before strip on the panel. This panel's top inset is only 10px, so that
2660
+ 40px strip reached down over the subheader and swallowed clicks on the top
2661
+ half of the back/close buttons (their own no-drag is painted over by the
2662
+ strip, which sits above the static subheader). Clamp the strip to the same
2663
+ 10px inset so it never overlaps the interactive row. */
2664
+ html[data-windows-titlebar] .bt-panel:not(:has(> .bt-ptabs)):has(> .bt-panel-view > .bt-subhead)::before {
2665
+ height: 10px !important;
2666
+ }
2667
+
2668
+ /* Also lift the whole subheader above any residual drag strip and make it and
2669
+ every descendant a no-drag island, so the back/close controls (Bot settings
2670
+ and Group settings share this in-flow subheader) stay clickable at every
2671
+ height, top edge included. */
2672
+ html[data-windows-titlebar] .bt-panel:has(> .bt-panel-view > .bt-subhead) > .bt-panel-view > .bt-subhead {
2673
+ position: relative !important;
2674
+ z-index: 1 !important;
2675
+ }
2676
+ html[data-windows-titlebar] .bt-panel:has(> .bt-panel-view > .bt-subhead) > .bt-panel-view > .bt-subhead,
2677
+ html[data-windows-titlebar] .bt-panel:has(> .bt-panel-view > .bt-subhead) > .bt-panel-view > .bt-subhead * {
2678
+ -webkit-app-region: no-drag !important;
2679
+ }
2680
+
2681
+ /* Only expanded columns have an expanded minimum; the width module owns the
2682
+ actual drag. This keeps the static floor below the host's 264px. */
2683
+ .bt-leftcol:is([data-left="open"], [data-left="drawer"]) {
2684
+ min-width: 220px !important;
2685
+ }
2686
+ .bt-leftcol[data-left="rail"] {
2687
+ min-width: 0 !important;
2688
+ /* With the toggle removed, keep the first avatar below native window controls.
2689
+ The live inline width still owns both the rail and its resize boundary. */
2690
+ padding-top: max(20px, calc(var(--bt-lc-clear, 0px) + 8px)) !important;
2691
+ }
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
+
2751
+ /* ---- Sidebar section headers (DS Bot tree) ---- */
2752
+
2753
+ /* The disclosure chevron's glyph sits ~2.5px right of the hover guide line
2754
+ that descends through the child rows (the 14px chev box is centred at 25px,
2755
+ the guide at ~22.75px), so its tip misses the line. Nudge only the glyph
2756
+ left with a relative offset so the tip lands on the guide; the title row,
2757
+ its spacing and the button hit area stay exactly where they were. */
2758
+ .bt-leftcol .bt-sec-chev {
2759
+ position: relative !important;
2760
+ left: -2.5px !important;
2761
+ }
2762
+
2763
+ /* The "…" section action renders as three ~1px dots in a 13px svg and reads far
2764
+ fainter than the "+" beside it, although both share the same ink colour and
2765
+ opacity (so colour is not the cause — the glyph is). Give the dots a slightly
2766
+ larger glyph box (15px) and a heavier stroke so the three dots read at the
2767
+ same weight as the "+"; colour, opacity and the button hit area are unchanged. */
2768
+ .bt-leftcol .bt-sec-acts .bt-sec-act:last-child svg {
2769
+ width: 15px !important;
2770
+ height: 15px !important;
2771
+ }
2772
+ .bt-leftcol .bt-sec-acts .bt-sec-act:last-child svg path {
2773
+ stroke-width: 2.8 !important;
2774
+ }
2775
+
2776
+ /* The three sidebar actions read as normal tools, not filled buttons:
2777
+ secondary ink on the surface, with the shared hover treatment. */
2778
+ .bt-side-top .bt-round {
2779
+ background: transparent !important;
2780
+ border-color: transparent !important;
2781
+ color: var(--bt-ink-2) !important;
2782
+ }
2783
+ .bt-side-top .bt-round:hover {
2784
+ background: color-mix(in srgb, var(--bt-hover) 60%, transparent) !important;
2785
+ color: var(--bt-ink) !important;
2786
+ }
2787
+
2788
+ /* The rail's + button carries the same disc as the account and plugins
2789
+ buttons: those wrap their icon in a 36px round bt-you disc, which is a
2790
+ #262626 fill with a 1px inner ring, and that ring reads as the button face.
2791
+ The host's .bt-round only fills the button, so paint the same disc here. */
2792
+ .bt-leftcol-foot-rail .bt-round {
2793
+ width: 36px !important;
2794
+ height: 36px !important;
2795
+ border-radius: 50% !important;
2796
+ border-color: transparent !important;
2797
+ background: #262626 !important;
2798
+ box-shadow: inset 0 0 0 1px rgba(242, 242, 242, .08) !important;
2799
+ color: var(--bt-ink-2) !important;
2800
+ }
2801
+ .bt-leftcol-foot-rail .bt-round:hover {
2802
+ background: color-mix(in srgb, #262626 82%, var(--bt-hover)) !important;
2803
+ color: var(--bt-ink) !important;
2804
+ }
2805
+
2806
+ /* Sidebar visibility is controlled by the host shortcut and the existing grip.
2807
+ Hide the Bot controls and the shell fallback, which is exposed after the Bot
2808
+ column unmounts. Otherwise hiding the sidebar reveals another open button. */
2809
+ .bt-title-toggle,
2810
+ .bt-side-collapse,
2811
+ button[data-sidebar-toggle],
2812
+ button[data-sidebar-opener] {
2813
+ display: none !important;
2814
+ }
2815
+
2816
+ .bt-leftcol,
2817
+ .bt-leftcol > :first-child {
2818
+ border-top-right-radius: 0 !important;
2819
+ }
2820
+
2821
+ .bt-side-top .bt-brand {
2822
+ display: none !important;
2823
+ }
2824
+
2825
+ /* ---- Account menu (bottom-left gear) — frostier, more opaque, larger radius ---- */
2826
+
2827
+ /* The host paints every pop menu as a 78% (light) / 74% (dark) glass tint with
2828
+ a 24px blur, so the sidebar's session titles still read through the bottom-left
2829
+ account menu. Deepen only this menu: a stronger blur plus a more opaque surface
2830
+ hide the text behind it, and a larger corner radius softens its edges. Scoped to
2831
+ .bt-account-menu so the other pop menus keep the host's look; corner-shape is
2832
+ left untouched so the curve stays consistent with the rest of the shell. */
2833
+ .bt-account-menu {
2834
+ -webkit-backdrop-filter: blur(40px) saturate(180%) !important;
2835
+ backdrop-filter: blur(40px) saturate(180%) !important;
2836
+ background: color-mix(in srgb, var(--bt-main) 92%, transparent) !important;
2837
+ border-radius: 16px !important;
2838
+ }
2839
+ body[data-ds-dark-theme] .bt-account-menu {
2840
+ background: color-mix(in srgb, var(--bt-main) 90%, transparent) !important;
2841
+ }
2842
+ `;
2843
+ // src/client/surfaces/ds-bot/markdown-anchors.ts
2844
+ /**
2845
+ * DS Bot's own bubble CSS outranks the shared markdown sheet:
2846
+ * .bt-bubble [class*="_markdown"] { color/font-size/line-height: inherit !important }
2847
+ * .bt-bubble p { margin: 0 }
2848
+ * .bt-bubble [class*="_markdown"] li::marker { color: var(--bt-ink-2) }
2849
+ *
2850
+ * The first rule carries !important at (0,2,0), while the shared sheet states
2851
+ * its measure at (0,1,0) on `[class*="_markdown"]`, so the host wins and the
2852
+ * body inherits the bubble's 14px. Restate the same declarations under a
2853
+ * three-anchor selector (0,3,0) plus a node-free fallback, so they win on
2854
+ * specificity rather than on load order. Only the measured declarations are
2855
+ * repeated; every other markdown rule stays on the shared sheet.
2856
+ */
2857
+ const bubble = ".bt-bubble";
2858
+ const md = `[data-slot="conversation.chat.node"] ${bubble} [class*="_markdown"]`;
2859
+ const fallback = `${bubble} [class*="_markdown"][class*="_markdown"]`;
2860
+ /** The DS Bot anchor overlay. Not mounted on DeepSeek Harness. */
2861
+ const css$1 = `${md},
2862
+ ${fallback} {
2863
+ color: var(--md-text) !important;
2864
+ font-size: 13px !important;
2865
+ line-height: 1.75 !important;
2866
+ letter-spacing: .01em;
2867
+ }
2868
+ ${md} p,
2869
+ ${fallback} p {
2870
+ margin: 0 0 1em !important;
2871
+ font-size: 13px !important;
2872
+ line-height: 1.75 !important;
2873
+ }
2874
+ ${md} li::marker,
2875
+ ${fallback} li::marker {
2876
+ color: var(--md-accent) !important;
2877
+ font-weight: 700 !important;
2878
+ }
2879
+ `;
2880
+ // src/client/surface.ts
2881
+ /** DS Bot draws its own left column under this class. */
2882
+ const DS_BOT_COLUMN = ".bt-leftcol";
2883
+ /** A service id that names the ds-bot bundle, not a longer unrelated token. */
2884
+ const DS_BOT_SERVICE = /(^|[\/.:])ds-bot($|[\/.:@])/;
2885
+ /**
2886
+ * Decide the surface from a probe.
2887
+ *
2888
+ * A `ds-bot` service or bundle name wins. Otherwise the host's own left column
2889
+ * means DS Bot. Anything else is DeepSeek Harness.
2890
+ * @param probe - names and an optional DOM root. Omit both for the page default.
2891
+ * @returns the surface this process should mount.
2892
+ */
2893
+ function detectSurface(probe = {}) {
2894
+ if ((probe.serviceNames ?? []).some((name) => DS_BOT_SERVICE.test(name))) return "ds-bot";
2895
+ try {
2896
+ if (probe.root?.querySelector?.(DS_BOT_COLUMN) != null) return "ds-bot";
2897
+ } catch {}
2898
+ return "dsh";
2899
+ }
2900
+ let decided;
2901
+ /**
2902
+ * The surface for this process. The first call wins; later probes are ignored.
2903
+ * @param probe - optional probe used only while the surface is still undecided.
2904
+ * @returns the remembered surface.
2905
+ */
2906
+ function currentSurface(probe) {
2907
+ if (decided !== void 0) return decided;
2908
+ decided = detectSurface(probe ?? defaultProbe());
2909
+ return decided;
2910
+ }
2911
+ /**
2912
+ * Probe the page: the boot graph first, then the DS Bot column.
2913
+ *
2914
+ * DS Boot injects `window.__DSH_BOOT__` as a manifest whose `entries` is an
2915
+ * array of `WebBootEntry` rows carrying an `id` (`"ds-bot"` for DS Bot's own
2916
+ * bundle). Older/alternate shapes expose `bundles` or `services` instead, so
2917
+ * every field is read. The DOM column is only a fallback: DS Bot mounts
2918
+ * `.bt-leftcol` after plugins have already been asked to decide.
2919
+ * @returns the probe `currentSurface` uses when the caller does not pass one.
2920
+ */
2921
+ function defaultProbe() {
2922
+ const names = [];
2923
+ const boot = globalThis.__DSH_BOOT__;
2924
+ collectNames(boot?.entries, names);
2925
+ collectNames(boot?.bundles, names);
2926
+ collectNames(boot?.services, names);
2927
+ collectNames(boot?.batches, names);
2928
+ return {
2929
+ serviceNames: names,
2930
+ root: typeof document === "undefined" ? null : document
2931
+ };
2932
+ }
2933
+ /**
2934
+ * Pull string names out of a boot payload, recursing through nested rows.
2935
+ * @param value - a name, a list, or a map of boot entries.
2936
+ * @param into - the list being filled.
2937
+ */
2938
+ function collectNames(value, into) {
2939
+ if (typeof value === "string") {
2940
+ into.push(value);
2941
+ return;
2942
+ }
2943
+ if (Array.isArray(value)) {
2944
+ for (const item of value) collectNames(item, into);
2945
+ return;
2946
+ }
2947
+ if (value !== null && typeof value === "object") for (const [key, item] of Object.entries(value)) {
2948
+ into.push(key);
2949
+ if (typeof item === "string") into.push(item);
2950
+ else collectNames(item, into);
2951
+ }
2952
+ }
2953
+ /**
2954
+ * Feature switches for one surface.
2955
+ *
2956
+ * DS Bot draws its own sidebar, so the DSH chrome (width, icon row, section
2957
+ * counts, whale, window geometry) stays off there. Annotations, side chat,
2958
+ * both context menus, markdown, document preview, and the badge mechanism stay
2959
+ * on. The running-marker and send-button looks are part of the DSH chrome
2960
+ * sheets, so they stay off with those sheets. Edge refraction belongs to the
2961
+ * DS Bot pill only: DSH draws no such pill, so it stays off there.
2962
+ * @param surface - the decided surface.
2963
+ * @returns the switches `apply` reads.
2964
+ */
2965
+ function featuresFor(surface) {
2966
+ const shared = {
2967
+ annotations: true,
2968
+ sideChat: true,
2969
+ fileMenu: true,
2970
+ markdown: true,
2971
+ documentPreview: true,
2972
+ badge: true,
2973
+ panelWidths: true
2974
+ };
2975
+ if (surface === "ds-bot") return {
2976
+ ...shared,
2977
+ sidebarFloor: false,
2978
+ sidebarTopRow: false,
2979
+ sectionStats: false,
2980
+ whale: false,
2981
+ windowGeometry: false,
2982
+ liquidGlass: true,
2983
+ autoLoadEarlier: true
2984
+ };
2985
+ return {
2986
+ ...shared,
2987
+ sidebarFloor: true,
2988
+ sidebarTopRow: true,
2989
+ sectionStats: true,
2990
+ whale: true,
2991
+ windowGeometry: true,
2992
+ panelWidths: false,
2993
+ liquidGlass: false,
2994
+ autoLoadEarlier: false
2995
+ };
2996
+ }
2997
+ /**
2998
+ * Style-tag identity. The two surfaces never share a prefix, so a page can
2999
+ * show which set is mounted.
3000
+ * @param surface - the decided surface.
3001
+ * @returns the `data-plugin` value.
3002
+ */
3003
+ function stylePluginId(surface) {
3004
+ return surface === "ds-bot" ? "ds-bot-enhance" : "dsh-enhance";
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
+ }
2232
3601
  `;
2233
3602
  // src/client/styles.ts
2234
- /** Stable plugin identity stamped onto every injected style tag. */
2235
- const PLUGIN_ID = "dsh-enhance";
2236
- /** Sheet name to CSS, in cascade order: later sheets win ties against earlier ones. */
3603
+ /** DSH sheet name to CSS, in cascade order: later sheets win ties against earlier ones. */
2237
3604
  const SHEETS = [
2238
- ["document-preview.css", css$7],
2239
- ["chat-markdown.css", css$6],
2240
- ["rightbar-handle.css", css$5],
2241
- ["running-spinner.css", css$4],
2242
- ["sidebar-density.css", css$3],
2243
- ["sidebar-layout.css", css$2],
2244
- ["toolbar.css", css$1],
2245
- ["file-menu.css", css]
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]
3614
+ ];
3615
+ /** DS Bot mounts the shared rules plus its own chrome and md anchors; no DSH chrome. */
3616
+ const DS_BOT_SHEETS = [
3617
+ ...[
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]
3623
+ ],
3624
+ ["ds-bot-chrome.css", css$2],
3625
+ ["ds-bot-markdown-anchors.css", css$1],
3626
+ ["ds-bot-older.css", css]
2246
3627
  ];
2247
3628
  /**
2248
- * Mount every global sheet for exactly the owning plugin lifetime.
3629
+ * The sheet set for one surface. The two sets never mount together.
3630
+ * @param surface - the decided surface.
3631
+ * @returns that surface's sheets.
3632
+ */
3633
+ function sheetsFor(surface) {
3634
+ return surface === "ds-bot" ? DS_BOT_SHEETS : SHEETS;
3635
+ }
3636
+ /**
3637
+ * Mount one surface's sheets for exactly the owning plugin lifetime.
2249
3638
  *
2250
3639
  * The tags carry `data-plugin`, so the client module system's entry lifecycle
2251
3640
  * evicts them when this plugin unloads even if the fiber is torn down abruptly.
@@ -2253,16 +3642,18 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2253
3642
  */
2254
3643
  function installStyles(ctx) {
2255
3644
  if (typeof document === "undefined") return;
2256
- for (const [name, css] of SHEETS) ctx.effect(() => {
3645
+ const surface = currentSurface();
3646
+ const pluginId = stylePluginId(surface);
3647
+ for (const [name, css] of sheetsFor(surface)) ctx.effect(() => {
2257
3648
  const tag = document.createElement("style");
2258
- tag.dataset.plugin = PLUGIN_ID;
2259
- tag.dataset.pluginCss = `${PLUGIN_ID}/${name}`;
3649
+ tag.dataset.plugin = pluginId;
3650
+ tag.dataset.pluginCss = `${pluginId}/${name}`;
2260
3651
  tag.textContent = css;
2261
3652
  document.head.appendChild(tag);
2262
3653
  return () => {
2263
3654
  tag.remove();
2264
3655
  };
2265
- }, `dsh-enhance: ${name} stylesheet`);
3656
+ }, `${pluginId}: ${name} stylesheet`);
2266
3657
  }
2267
3658
  // src/client/whale-bubbles.ts
2268
3659
  /**
@@ -2704,6 +4095,404 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2704
4095
  else home.append(moved);
2705
4096
  };
2706
4097
  }
4098
+ const LEFT_MAX = 420;
4099
+ const DETAILS_MAX = 520;
4100
+ const CHAT_MIN = 420;
4101
+ const RAIL_SNAP = 176;
4102
+ const LEFT_KEY = "ds-bot-enhance.sidebar-width.v1";
4103
+ const RIGHT_KEY = "ds-bot-enhance.details-width.v1";
4104
+ function installPanelWidths(root) {
4105
+ const win = root.defaultView;
4106
+ const preferred = {};
4107
+ const owned = {
4108
+ left: /* @__PURE__ */ new Map(),
4109
+ right: /* @__PURE__ */ new Map()
4110
+ };
4111
+ let drag;
4112
+ let nativeDrag = false;
4113
+ let replaying = false;
4114
+ let frame = 0;
4115
+ let disposed = false;
4116
+ const key = (side) => side === "left" ? LEFT_KEY : RIGHT_KEY;
4117
+ const minimum = (side) => side === "left" ? 220 : 260;
4118
+ const maximum = (side) => side === "left" ? LEFT_MAX : DETAILS_MAX;
4119
+ for (const side of ["left", "right"]) try {
4120
+ const raw = win.localStorage.getItem(key(side));
4121
+ const n = raw === null ? NaN : Number(raw);
4122
+ if (Number.isFinite(n) && n >= minimum(side) && n <= maximum(side)) preferred[side] = Math.round(n);
4123
+ } catch {}
4124
+ const save = (side) => {
4125
+ try {
4126
+ const width = preferred[side];
4127
+ if (width === void 0) win.localStorage.removeItem(key(side));
4128
+ else win.localStorage.setItem(key(side), String(width));
4129
+ } catch {}
4130
+ };
4131
+ const put = (side, element, property, value) => {
4132
+ let properties = owned[side].get(element);
4133
+ if (!properties) {
4134
+ properties = /* @__PURE__ */ new Map();
4135
+ owned[side].set(element, properties);
4136
+ }
4137
+ if (!properties.has(property)) properties.set(property, {
4138
+ value: element.style.getPropertyValue(property),
4139
+ priority: element.style.getPropertyPriority(property)
4140
+ });
4141
+ if (element.style.getPropertyValue(property) !== value || element.style.getPropertyPriority(property) !== "important") element.style.setProperty(property, value, "important");
4142
+ };
4143
+ const clear = (side) => {
4144
+ for (const [element, properties] of owned[side]) for (const [property, original] of properties) if (original.value) element.style.setProperty(property, original.value, original.priority);
4145
+ else element.style.removeProperty(property);
4146
+ owned[side].clear();
4147
+ };
4148
+ const leftColumn = () => root.querySelector(".bt-leftcol");
4149
+ const detailPanel = () => root.querySelector(".bt-panel[data-view=\"details\"]:not([data-leaving])");
4150
+ const centers = () => [...root.querySelectorAll("[class*=\"_centerCol\"]")];
4151
+ const shellWidth = () => root.querySelector("[class*=\"_sidebarCol\"]")?.getBoundingClientRect().width ?? 0;
4152
+ const bound = (side, value) => {
4153
+ const left = leftColumn();
4154
+ const occupied = left?.dataset.left === "open" ? left.getBoundingClientRect().width : left?.dataset.left === "rail" ? 88 : 0;
4155
+ const available = side === "right" ? win.innerWidth - occupied - CHAT_MIN : win.innerWidth - CHAT_MIN;
4156
+ return Math.round(Math.max(minimum(side), Math.min(value, maximum(side), Math.max(minimum(side), available))));
4157
+ };
4158
+ const paint = () => {
4159
+ if (disposed || nativeDrag) return;
4160
+ const left = leftColumn();
4161
+ const mode = left?.dataset.left;
4162
+ if (left && preferred.left !== void 0 && (mode === "open" || mode === "drawer")) {
4163
+ const width = bound("left", preferred.left);
4164
+ put("left", left, "width", `${width}px`);
4165
+ put("left", left, "--bt-lc-w", `${width}px`);
4166
+ const occupied = mode === "open" ? width : 88;
4167
+ if (mode === "open") for (const center of centers()) put("left", center, "margin-left", `${Math.max(0, occupied - shellWidth())}px`);
4168
+ for (const pane of root.querySelectorAll(".bt-pane")) put("left", pane, "left", `${occupied}px`);
4169
+ } else clear("left");
4170
+ const panel = detailPanel();
4171
+ if (panel && preferred.right !== void 0) {
4172
+ const width = bound("right", preferred.right);
4173
+ put("right", panel, "width", `${width}px`);
4174
+ put("right", panel, "--bt-panel-w", `${width}px`);
4175
+ if (!panel.hasAttribute("data-overlay")) for (const center of centers()) put("right", center, "margin-right", `${width}px`);
4176
+ else for (const center of centers()) {
4177
+ const properties = owned.right.get(center);
4178
+ if (properties) {
4179
+ for (const [property, original] of properties) if (original.value) center.style.setProperty(property, original.value, original.priority);
4180
+ else center.style.removeProperty(property);
4181
+ owned.right.delete(center);
4182
+ }
4183
+ }
4184
+ } else clear("right");
4185
+ for (const side of ["left", "right"]) for (const element of owned[side].keys()) if (!element.isConnected) owned[side].delete(element);
4186
+ observer.takeRecords();
4187
+ };
4188
+ const schedule = () => {
4189
+ if (disposed || frame) return;
4190
+ frame = win.requestAnimationFrame(() => {
4191
+ frame = 0;
4192
+ paint();
4193
+ });
4194
+ };
4195
+ const observer = new MutationObserver(schedule);
4196
+ const finish = (commit) => {
4197
+ const active = drag;
4198
+ if (!active) {
4199
+ nativeDrag = false;
4200
+ schedule();
4201
+ return;
4202
+ }
4203
+ drag = void 0;
4204
+ if (!commit) preferred[active.side] = active.previous;
4205
+ else save(active.side);
4206
+ if (active.grip.hasPointerCapture?.(active.id)) active.grip.releasePointerCapture(active.id);
4207
+ root.documentElement.removeAttribute("data-ds-enhance-resizing");
4208
+ if (preferred[active.side] === void 0) clear(active.side);
4209
+ paint();
4210
+ };
4211
+ const onDown = (event) => {
4212
+ if (replaying || event.button !== 0 || !(event.target instanceof Element)) return;
4213
+ const grip = event.target.closest(".bt-leftcol-grip, .bt-panel-grip");
4214
+ if (!grip) return;
4215
+ const side = grip.classList.contains("bt-leftcol-grip") ? "left" : "right";
4216
+ const element = side === "left" ? grip.closest(".bt-leftcol") : grip.closest(".bt-panel");
4217
+ if (!element) return;
4218
+ if (side === "left" && !["open", "drawer"].includes(element.dataset.left ?? "") || side === "right" && element.dataset.view !== "details") {
4219
+ nativeDrag = true;
4220
+ return;
4221
+ }
4222
+ event.preventDefault();
4223
+ event.stopImmediatePropagation();
4224
+ drag = {
4225
+ side,
4226
+ grip,
4227
+ id: event.pointerId,
4228
+ x: event.clientX,
4229
+ width: element.getBoundingClientRect().width,
4230
+ previous: preferred[side]
4231
+ };
4232
+ root.documentElement.setAttribute("data-ds-enhance-resizing", "");
4233
+ grip.setPointerCapture?.(event.pointerId);
4234
+ };
4235
+ const track = (event) => {
4236
+ if (!drag || event.pointerId !== drag.id) return;
4237
+ const active = drag;
4238
+ if (active.side === "left" && event.clientX < RAIL_SNAP) {
4239
+ finish(false);
4240
+ nativeDrag = true;
4241
+ clear("left");
4242
+ replaying = true;
4243
+ try {
4244
+ active.grip.dispatchEvent(new PointerEvent("pointerdown", {
4245
+ bubbles: true,
4246
+ button: 0,
4247
+ buttons: 1,
4248
+ pointerId: event.pointerId,
4249
+ clientX: event.clientX,
4250
+ clientY: event.clientY
4251
+ }));
4252
+ active.grip.dispatchEvent(new PointerEvent("pointermove", {
4253
+ bubbles: true,
4254
+ buttons: 1,
4255
+ pointerId: event.pointerId,
4256
+ clientX: event.clientX,
4257
+ clientY: event.clientY
4258
+ }));
4259
+ } finally {
4260
+ replaying = false;
4261
+ }
4262
+ return;
4263
+ }
4264
+ preferred[active.side] = bound(active.side, active.width + (event.clientX - active.x) * (active.side === "left" ? 1 : -1));
4265
+ paint();
4266
+ };
4267
+ const onMove = (event) => {
4268
+ if (!drag) return;
4269
+ if (event.buttons === 0) {
4270
+ finish(true);
4271
+ return;
4272
+ }
4273
+ event.stopImmediatePropagation();
4274
+ track(event);
4275
+ };
4276
+ const onUp = (event) => {
4277
+ if (drag) {
4278
+ event.stopImmediatePropagation();
4279
+ track(event);
4280
+ finish(true);
4281
+ } else if (nativeDrag) {
4282
+ nativeDrag = false;
4283
+ const left = leftColumn();
4284
+ if (left && left.dataset.left === "open" && event.target instanceof Element && event.target.closest(".bt-leftcol-grip")) {
4285
+ preferred.left = bound("left", left.getBoundingClientRect().width);
4286
+ save("left");
4287
+ }
4288
+ schedule();
4289
+ }
4290
+ };
4291
+ const onCancel = () => {
4292
+ finish(false);
4293
+ };
4294
+ const style = root.createElement("style");
4295
+ style.dataset.plugin = "ds-bot-enhance-widths";
4296
+ style.textContent = "[data-ds-enhance-resizing] :is(.bt-leftcol,.bt-panel,[class*=\"_centerCol\"]){transition:none!important}[data-ds-enhance-resizing] *{cursor:col-resize!important;user-select:none!important}";
4297
+ root.head.appendChild(style);
4298
+ root.addEventListener("pointerdown", onDown, true);
4299
+ root.addEventListener("pointermove", onMove, true);
4300
+ root.addEventListener("pointerup", onUp, true);
4301
+ root.addEventListener("pointercancel", onCancel, true);
4302
+ win.addEventListener("blur", onCancel);
4303
+ win.addEventListener("resize", schedule);
4304
+ observer.observe(root.body, {
4305
+ childList: true,
4306
+ subtree: true,
4307
+ attributes: true,
4308
+ attributeFilter: [
4309
+ "style",
4310
+ "data-left",
4311
+ "data-view",
4312
+ "data-overlay",
4313
+ "data-leaving"
4314
+ ]
4315
+ });
4316
+ paint();
4317
+ return () => {
4318
+ disposed = true;
4319
+ finish(false);
4320
+ observer.disconnect();
4321
+ win.cancelAnimationFrame(frame);
4322
+ root.removeEventListener("pointerdown", onDown, true);
4323
+ root.removeEventListener("pointermove", onMove, true);
4324
+ root.removeEventListener("pointerup", onUp, true);
4325
+ root.removeEventListener("pointercancel", onCancel, true);
4326
+ win.removeEventListener("blur", onCancel);
4327
+ win.removeEventListener("resize", schedule);
4328
+ clear("left");
4329
+ clear("right");
4330
+ style.remove();
4331
+ };
4332
+ }
4333
+ // src/client/surfaces/ds-bot/liquid-glass.ts
4334
+ /** Liquid-glass refraction for the DS Bot session pill.
4335
+ *
4336
+ * Ported from `lucasromerodb/liquid-glass-effect-macos`
4337
+ * (https://github.com/lucasromerodb/liquid-glass-effect-macos) — the source
4338
+ * behind the user's CodeSandbox reference (nn5q2y). That repository ships no
4339
+ * LICENSE file, so it is used here as an effect reference only.
4340
+ *
4341
+ * The reference does not build a displacement map by hand. It generates a
4342
+ * low-frequency fractal noise, blurs it, and bends the element's backdrop with
4343
+ * feDisplacementMap; the element that carries the refraction also carries the
4344
+ * backdrop-filter, so the backdrop is softened first and bent afterwards. The
4345
+ * visible distortion comes from that chain. feComponentTransfer and
4346
+ * feSpecularLighting are part of the original markup and are kept verbatim,
4347
+ * even though the reference's own chain never reads their results back.
4348
+ *
4349
+ * The filter is written once and needs no per-frame work: the turbulence is a
4350
+ * pure function of user space, and `filterUnits="objectBoundingBox"` lets the
4351
+ * region follow the pill's box, so the filter survives the pill growing when
4352
+ * the back arrow appears.
4353
+ *
4354
+ * chrome.ts carries the layering: `::before` is the effect layer (softening
4355
+ * pass plus the bend on the same element, exactly like the reference), `::after`
4356
+ * is the tint and the lip, and the pill's own box clips both to the capsule.
4357
+ */
4358
+ const NS = "http://www.w3.org/2000/svg";
4359
+ /** The one filter id this module owns on the page. */
4360
+ const FILTER_ID = "dsh-lg-pill";
4361
+ /** CSS variable chrome.ts reads for the softening pass; unset means "frosted fallback". */
4362
+ const BACKDROP_VAR = "--dsh-lg-backdrop";
4363
+ /** CSS variable chrome.ts reads for the SVG distortion. */
4364
+ const FILTER_VAR = "--dsh-lg-filter";
4365
+ /** Page attribute that says which look is live, for tests and inspection. */
4366
+ const MODE_ATTR = "data-dsh-lg";
4367
+ /** The reference's softening pass on the effect layer: `blur(3px)`. The
4368
+ * backdrop is blurred before it is bent, which is what keeps the bend reading
4369
+ * as glass instead of as a smeared copy of the text behind. */
4370
+ const GLASS_SOFTEN = { blur: 3 };
4371
+ /** Keep the CodeSandbox reference's turbulence and displacement unchanged.
4372
+ * Scaling the displacement down and increasing blur erased the visible glass
4373
+ * effect in earlier revisions. The capsule clips the reference effect; only
4374
+ * its text/content is excluded from filtering. */
4375
+ const GLASS_DISTORTION = {
4376
+ baseFrequencyX: .001,
4377
+ baseFrequencyY: .005,
4378
+ numOctaves: 1,
4379
+ seed: 17,
4380
+ stdDeviation: 3,
4381
+ scale: 200,
4382
+ surfaceScale: 5,
4383
+ specularConstant: 1,
4384
+ specularExponent: 100,
4385
+ lightX: -200,
4386
+ lightY: -200,
4387
+ lightZ: 300
4388
+ };
4389
+ /** The value published to `--dsh-lg-backdrop`: the softening pass only. It
4390
+ * intentionally carries no url() — Chromium ignores the whole declaration when
4391
+ * backdrop-filter references an SVG filter, which is why the bend rides the
4392
+ * plain `filter` property, exactly like the reference does. */
4393
+ const BACKDROP_VALUE = `blur(${GLASS_SOFTEN.blur}px)`;
4394
+ /** The value published to `--dsh-lg-filter`: the reference's distortion. */
4395
+ const FILTER_VALUE = `url(#${FILTER_ID})`;
4396
+ const inert = () => {};
4397
+ /** Build the reference's filter: turbulence → component transfer → blur →
4398
+ * specular lighting → composite → displacement. */
4399
+ function buildFilter(root) {
4400
+ const svg = root.createElementNS(NS, "svg");
4401
+ svg.setAttribute("aria-hidden", "true");
4402
+ svg.setAttribute("data-plugin", "ds-bot-enhance-liquid-glass");
4403
+ svg.style.cssText = "position:absolute;width:0;height:0;overflow:hidden;pointer-events:none";
4404
+ const filter = root.createElementNS(NS, "filter");
4405
+ filter.setAttribute("id", FILTER_ID);
4406
+ filter.setAttribute("x", "0%");
4407
+ filter.setAttribute("y", "0%");
4408
+ filter.setAttribute("width", "100%");
4409
+ filter.setAttribute("height", "100%");
4410
+ filter.setAttribute("filterUnits", "objectBoundingBox");
4411
+ const turbulence = root.createElementNS(NS, "feTurbulence");
4412
+ turbulence.setAttribute("type", "fractalNoise");
4413
+ turbulence.setAttribute("baseFrequency", `${GLASS_DISTORTION.baseFrequencyX} ${GLASS_DISTORTION.baseFrequencyY}`);
4414
+ turbulence.setAttribute("numOctaves", String(GLASS_DISTORTION.numOctaves));
4415
+ turbulence.setAttribute("seed", String(GLASS_DISTORTION.seed));
4416
+ turbulence.setAttribute("result", "turbulence");
4417
+ const transfer = root.createElementNS(NS, "feComponentTransfer");
4418
+ transfer.setAttribute("in", "turbulence");
4419
+ transfer.setAttribute("result", "mapped");
4420
+ const funcR = root.createElementNS(NS, "feFuncR");
4421
+ funcR.setAttribute("type", "gamma");
4422
+ funcR.setAttribute("amplitude", "1");
4423
+ funcR.setAttribute("exponent", "10");
4424
+ funcR.setAttribute("offset", "0.5");
4425
+ const funcG = root.createElementNS(NS, "feFuncG");
4426
+ funcG.setAttribute("type", "gamma");
4427
+ funcG.setAttribute("amplitude", "0");
4428
+ funcG.setAttribute("exponent", "1");
4429
+ funcG.setAttribute("offset", "0");
4430
+ const funcB = root.createElementNS(NS, "feFuncB");
4431
+ funcB.setAttribute("type", "gamma");
4432
+ funcB.setAttribute("amplitude", "0");
4433
+ funcB.setAttribute("exponent", "1");
4434
+ funcB.setAttribute("offset", "0.5");
4435
+ transfer.append(funcR, funcG, funcB);
4436
+ const blur = root.createElementNS(NS, "feGaussianBlur");
4437
+ blur.setAttribute("in", "turbulence");
4438
+ blur.setAttribute("stdDeviation", String(GLASS_DISTORTION.stdDeviation));
4439
+ blur.setAttribute("result", "softMap");
4440
+ const specular = root.createElementNS(NS, "feSpecularLighting");
4441
+ specular.setAttribute("in", "softMap");
4442
+ specular.setAttribute("surfaceScale", String(GLASS_DISTORTION.surfaceScale));
4443
+ specular.setAttribute("specularConstant", String(GLASS_DISTORTION.specularConstant));
4444
+ specular.setAttribute("specularExponent", String(GLASS_DISTORTION.specularExponent));
4445
+ specular.setAttribute("lighting-color", "white");
4446
+ specular.setAttribute("result", "specLight");
4447
+ const pointLight = root.createElementNS(NS, "fePointLight");
4448
+ pointLight.setAttribute("x", String(GLASS_DISTORTION.lightX));
4449
+ pointLight.setAttribute("y", String(GLASS_DISTORTION.lightY));
4450
+ pointLight.setAttribute("z", String(GLASS_DISTORTION.lightZ));
4451
+ specular.append(pointLight);
4452
+ const composite = root.createElementNS(NS, "feComposite");
4453
+ composite.setAttribute("in", "specLight");
4454
+ composite.setAttribute("operator", "arithmetic");
4455
+ composite.setAttribute("k1", "0");
4456
+ composite.setAttribute("k2", "1");
4457
+ composite.setAttribute("k3", "1");
4458
+ composite.setAttribute("k4", "0");
4459
+ composite.setAttribute("result", "litImage");
4460
+ const bend = root.createElementNS(NS, "feDisplacementMap");
4461
+ bend.setAttribute("in", "SourceGraphic");
4462
+ bend.setAttribute("in2", "softMap");
4463
+ bend.setAttribute("scale", String(GLASS_DISTORTION.scale));
4464
+ bend.setAttribute("xChannelSelector", "R");
4465
+ bend.setAttribute("yChannelSelector", "G");
4466
+ filter.append(turbulence, transfer, blur, specular, composite, bend);
4467
+ svg.appendChild(filter);
4468
+ return {
4469
+ svg,
4470
+ filter
4471
+ };
4472
+ }
4473
+ /**
4474
+ * Publish the reference's liquid-glass distortion for the session pill on this
4475
+ * document.
4476
+ * @param root - the document the plugin runs in.
4477
+ * @returns the dispose function; a no-op when the shell cannot refract.
4478
+ */
4479
+ function installLiquidGlass(root) {
4480
+ const win = root.defaultView;
4481
+ if (!win || !root.body || typeof win.CSS?.supports !== "function") return inert;
4482
+ if (!win.CSS.supports("filter", `url(#dsh-lg-pill)`)) return inert;
4483
+ root.getElementById?.(FILTER_ID)?.remove();
4484
+ const { svg } = buildFilter(root);
4485
+ root.body.appendChild(svg);
4486
+ root.documentElement.style.setProperty(BACKDROP_VAR, BACKDROP_VALUE);
4487
+ root.documentElement.style.setProperty(FILTER_VAR, FILTER_VALUE);
4488
+ root.documentElement.setAttribute(MODE_ATTR, "refract");
4489
+ return () => {
4490
+ svg.remove();
4491
+ root.documentElement.style.removeProperty(BACKDROP_VAR);
4492
+ root.documentElement.style.removeProperty(FILTER_VAR);
4493
+ root.documentElement.removeAttribute(MODE_ATTR);
4494
+ };
4495
+ }
2707
4496
  // src/client/section-stats.ts
2708
4497
  /** Marks the injected row, for the stylesheet and the disposer. */
2709
4498
  const STATS_ATTRIBUTE = "data-dsh-enhance-stats";
@@ -2922,6 +4711,10 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2922
4711
  */
2923
4712
  /** localStorage key holding the last width this plugin settled on. */
2924
4713
  const STORAGE_KEY$1 = "dsh-enhance.sidebar-width.v1";
4714
+ /** DS Bot keeps its own width preference; the two apps never share one. */
4715
+ function storageKeyFor$1(surface) {
4716
+ return surface === "ds-bot" ? "ds-bot-enhance.sidebar-width.v1" : STORAGE_KEY$1;
4717
+ }
2925
4718
  /**
2926
4719
  * Read a remembered width, rejecting anything outside the contract range.
2927
4720
  * @param raw - the stored string, or null.
@@ -2941,7 +4734,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2941
4734
  function startupSidebarWidth(store) {
2942
4735
  if (store === null) return 214;
2943
4736
  try {
2944
- return readSidebarWidth(store.getItem("dsh-enhance.sidebar-width.v1")) ?? 214;
4737
+ return readSidebarWidth(store.getItem(storageKeyFor$1(currentSurface()))) ?? 214;
2945
4738
  } catch {
2946
4739
  return 214;
2947
4740
  }
@@ -2955,7 +4748,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2955
4748
  if (store === null) return;
2956
4749
  const bounded = Math.round(Math.min(Math.max(width, 214), 420));
2957
4750
  try {
2958
- store.setItem(STORAGE_KEY$1, String(bounded));
4751
+ store.setItem(storageKeyFor$1(currentSurface()), String(bounded));
2959
4752
  } catch {}
2960
4753
  }
2961
4754
  /**
@@ -2994,6 +4787,10 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2994
4787
  */
2995
4788
  /** localStorage key holding the last close's frame. */
2996
4789
  const STORAGE_KEY = "dsh-enhance.window-geometry.v1";
4790
+ /** DS Bot keeps its own frame; the two apps never share one. */
4791
+ function storageKeyFor(surface) {
4792
+ return surface === "ds-bot" ? "ds-bot-enhance.window-geometry.v1" : STORAGE_KEY;
4793
+ }
2997
4794
  /**
2998
4795
  * Read the work area out of a window's screen.
2999
4796
  *
@@ -3176,7 +4973,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3176
4973
  const maximized = isFilled(frame, area);
3177
4974
  if (!maximized) normal = frame;
3178
4975
  try {
3179
- storage.setItem(STORAGE_KEY, JSON.stringify({
4976
+ storage.setItem(storageKeyFor(currentSurface()), JSON.stringify({
3180
4977
  normal,
3181
4978
  maximized
3182
4979
  }));
@@ -3191,7 +4988,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3191
4988
  const onVisibilityChange = () => {
3192
4989
  if (win.document.visibilityState === "hidden") save();
3193
4990
  };
3194
- restore(storage === null ? void 0 : readSavedGeometry(storage.getItem(STORAGE_KEY)));
4991
+ restore(storage === null ? void 0 : readSavedGeometry(storage.getItem(storageKeyFor(currentSurface()))));
3195
4992
  win.addEventListener("resize", schedule);
3196
4993
  win.addEventListener("blur", schedule);
3197
4994
  win.addEventListener("visibilitychange", onVisibilityChange);
@@ -3220,18 +5017,112 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3220
5017
  }
3221
5018
  }
3222
5019
  // src/badge-route.ts
5020
+ /** Return the badge route for one surface. */
5021
+ function badgeRouteFor(surface) {
5022
+ return surface === "ds-bot" ? "/ds-bot-enhance/badge" : "/dsh-enhance/badge";
5023
+ }
5024
+ // src/client/badge-policy.ts
5025
+ /** The dots DS Bot renders on its left column. */
5026
+ const DS_BOT_UNREAD_DOT = ".bt-leftcol .bt-row .bt-unread";
5027
+ /** The row a dot belongs to; one row may carry several marks. */
5028
+ const DS_BOT_ROW = ".bt-row";
5029
+ /**
5030
+ * Visible rows whose completion is unread, plus the attention overlay.
5031
+ *
5032
+ * Blank placeholders and subagent children are skipped. Statuses whose row is
5033
+ * gone are skipped too.
5034
+ * @param byId - list rows by id.
5035
+ * @param status - session status by id.
5036
+ * @param attention - extra ids that finished in the background.
5037
+ * @returns the ids, in list order.
5038
+ */
5039
+ function completionUnreadIds(byId, status, attention) {
5040
+ const unread = [];
5041
+ for (const [id, row] of Object.entries(byId)) {
5042
+ if (row.blank === true || row.origin === "subagent") continue;
5043
+ if (status.get(id)?.completionUnread === true || attention?.has(id) === true) unread.push(id);
5044
+ }
5045
+ return unread;
5046
+ }
5047
+ /**
5048
+ * The rows DS Bot renders with an unread dot.
5049
+ *
5050
+ * One row is one bot, so the number of rows is the number the sidebar shows.
5051
+ * Several marks on one row count once; a mark that is not laid out (a hidden
5052
+ * section, a collapsed group) is skipped.
5053
+ * @param root - the document, or a stand-in in tests. Defaults to `document`.
5054
+ * @returns one entry per unread row, capped at the Host's own badge ceiling.
5055
+ */
5056
+ function unreadSidebarRows(root) {
5057
+ const scope = root ?? defaultRoot();
5058
+ if (scope === void 0 || scope === null) return [];
5059
+ const rows = /* @__PURE__ */ new Set();
5060
+ for (const dot of Array.from(scope.querySelectorAll(DS_BOT_UNREAD_DOT))) {
5061
+ if (!isLaidOut(dot)) continue;
5062
+ const row = dot.closest?.(DS_BOT_ROW) ?? dot;
5063
+ rows.add(row);
5064
+ if (rows.size >= 999) break;
5065
+ }
5066
+ return [...rows];
5067
+ }
5068
+ /**
5069
+ * Whether an element occupies space on the page.
5070
+ *
5071
+ * A stand-in without layout methods counts as shown, so a test can model only
5072
+ * the structure it cares about.
5073
+ * @param element - the candidate.
5074
+ * @returns false only when the element reports that it has no boxes.
5075
+ */
5076
+ function isLaidOut(element) {
5077
+ if (typeof element.getClientRects !== "function") return true;
5078
+ try {
5079
+ return element.getClientRects().length > 0;
5080
+ } catch {
5081
+ return true;
5082
+ }
5083
+ }
3223
5084
  /**
3224
- * The one path the browser half and the Host half share for the Dock badge.
5085
+ * The page's document, when there is one.
5086
+ * @returns the document as a counting root, or undefined outside a DOM.
5087
+ */
5088
+ function defaultRoot() {
5089
+ if (typeof document === "undefined") return void 0;
5090
+ return document;
5091
+ }
5092
+ /**
5093
+ * A stable key for one row, so `select` can return ids rather than elements.
5094
+ * @param row - the row element.
5095
+ * @param index - its position, used when the row carries no id.
5096
+ * @returns the row's bot or room id, else its index.
5097
+ */
5098
+ function rowKey(row, index) {
5099
+ const id = row.getAttribute?.("data-bot-id") ?? row.getAttribute?.("data-room-id");
5100
+ return id === null || id === void 0 || id === "" ? `row-${index}` : id;
5101
+ }
5102
+ /**
5103
+ * The counting rule for one surface.
3225
5104
  *
3226
- * The two halves are separate bundles (node ESM for the Host, a module-table
3227
- * factory for the page) and cannot call each other directly, so the count
3228
- * travels over the Host's own HTTP surface: the page POSTs it, the Host paints
3229
- * the Dock tile. Keeping the path in one module is what stops the two halves
3230
- * from drifting apart silently — a mismatch would look exactly like a badge
3231
- * that never appears.
3232
- */
3233
- /** Host route that paints the Dock badge; also the URL the page POSTs to. */
3234
- const BADGE_ROUTE = "/dsh-enhance/badge";
5105
+ * DS Bot counts the unread rows its own left column renders, which is exactly
5106
+ * the number of green dots the reader sees. An empty sidebar therefore clears
5107
+ * the tile, and an unrendered history session can never inflate it.
5108
+ * @param surface - the decided surface.
5109
+ * @param options - `root` overrides the document in tests.
5110
+ * @returns the policy `installTurnBadge` calls.
5111
+ */
5112
+ function badgePolicyFor(surface, options = {}) {
5113
+ if (surface === "ds-bot") return {
5114
+ id: "ds-bot-sidebar-unread-rows",
5115
+ pending: false,
5116
+ note: "One count per unread row in the DS Bot left column: the same rows that carry a green dot.",
5117
+ select: () => unreadSidebarRows(options.root).map(rowKey)
5118
+ };
5119
+ return {
5120
+ id: "dsh-completion-unread",
5121
+ pending: false,
5122
+ note: "",
5123
+ select: completionUnreadIds
5124
+ };
5125
+ }
3235
5126
  // src/client/turn-badge.ts
3236
5127
  /** localStorage key of the pre-v2 accumulating badge; cleared once on mount. */
3237
5128
  const LEGACY_STORAGE_KEY = "dsh-enhance.turn-badge.v1";
@@ -3248,7 +5139,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3248
5139
  if (typeof base !== "string" || base === "") return;
3249
5140
  let url;
3250
5141
  try {
3251
- url = new URL(BADGE_ROUTE, base).href;
5142
+ url = new URL(badgeRouteFor(currentSurface()), base).href;
3252
5143
  } catch {
3253
5144
  return;
3254
5145
  }
@@ -3261,24 +5152,6 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3261
5152
  } catch {}
3262
5153
  }
3263
5154
  /**
3264
- * Ids of visible (non-blank, non-subagent) sessions whose completion is
3265
- * unread. Statuses of rows the list no longer carries are skipped: a deleted
3266
- * conversation shows no dot in the sidebar either.
3267
- * @param byId - the list snapshot's rows by id.
3268
- * @param status - the Session status snapshot.
3269
- * @param attention - sessions that finished while the window was in the
3270
- * background; the Host's projection does not mark those.
3271
- * @returns the ids to count on the tile, in list order.
3272
- */
3273
- function unreadVisibleIds(byId, status, attention) {
3274
- const unread = [];
3275
- for (const [id, row] of Object.entries(byId)) {
3276
- if (row.blank === true || row.origin === "subagent") continue;
3277
- if (status.get(id)?.completionUnread === true || attention?.has(id) === true) unread.push(id);
3278
- }
3279
- return unread;
3280
- }
3281
- /**
3282
5155
  * The page's own attention source: the window focus the browser reports, with
3283
5156
  * a hidden (minimised or fully occluded) document counting as unfocused.
3284
5157
  * @returns the source, or undefined outside a DOM.
@@ -3317,7 +5190,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3317
5190
  const statusStore = deps.statusSource ?? ctx.uiSession?.sessionStatus;
3318
5191
  if (statusStore === void 0) return () => {};
3319
5192
  try {
3320
- localStorage.removeItem(LEGACY_STORAGE_KEY);
5193
+ localStorage.removeItem(currentSurface() === "ds-bot" ? "ds-bot-enhance.badge.legacy.v1" : LEGACY_STORAGE_KEY);
3321
5194
  } catch {}
3322
5195
  let painted;
3323
5196
  /** Sessions that finished while the window was in the background. */
@@ -3345,7 +5218,7 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3345
5218
  const paint = () => {
3346
5219
  const byId = ctx.sessions.list.getSnapshot().byId;
3347
5220
  observeRunning(byId);
3348
- const count = unreadVisibleIds(byId, statusStore.getSnapshot(), attention).length;
5221
+ const count = badgePolicyFor(currentSurface()).select(byId, { get: (id) => statusStore.getSnapshot().get(id) }, attention).length;
3349
5222
  if (painted === count) return;
3350
5223
  painted = count;
3351
5224
  paintHost(count);
@@ -4058,7 +5931,10 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4058
5931
  "linkMenu.done.opened": "已打开",
4059
5932
  "linkMenu.done.copied": "已复制链接",
4060
5933
  "linkMenu.done.saved": "已保存",
4061
- "linkMenu.saveFailed": "无法下载该链接(可能受跨域限制)"
5934
+ "linkMenu.saveFailed": "无法下载该链接(可能受跨域限制)",
5935
+ "anno.quote": "引用原文",
5936
+ "anno.comment": "我的意见",
5937
+ "autoLoad.loading": "正在加载更早的消息…"
4062
5938
  };
4063
5939
  /** Toolbar copy, English. */
4064
5940
  const en = {
@@ -4106,7 +5982,10 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4106
5982
  "linkMenu.done.opened": "Opened",
4107
5983
  "linkMenu.done.copied": "Link copied",
4108
5984
  "linkMenu.done.saved": "Saved",
4109
- "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…"
4110
5989
  };
4111
5990
  // src/client/anchors.ts
4112
5991
  /** Any transcript row the plugin may anchor to. */
@@ -4980,7 +6859,20 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4980
6859
  publish();
4981
6860
  }
4982
6861
  /** Column the body of an entry sits at, so it lines up under its label. */
4983
- const INDENT = " ";
6862
+ const INDENT$1 = " ";
6863
+ /**
6864
+ * Put a block of text under the annotation's labels, one indented line per
6865
+ * line of the original.
6866
+ *
6867
+ * A passage can cover several lines of the transcript, and a comment can be
6868
+ * written with Shift+Enter. Folding both onto one line lost that shape, so the
6869
+ * line breaks are kept and every line sits at the same column.
6870
+ * @param text - the text to indent.
6871
+ * @returns the indented lines.
6872
+ */
6873
+ function indentedLines(text) {
6874
+ return text.split("\n").map((line) => line.length === 0 ? "" : `${INDENT$1}${line}`);
6875
+ }
4984
6876
  /**
4985
6877
  * Render one annotation as two labelled blocks: the passage, then the comment.
4986
6878
  *
@@ -4991,19 +6883,21 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4991
6883
  * already says what the text under it is. Without a comment only the passage
4992
6884
  * block is sent — an empty label would ask the model to answer nothing.
4993
6885
  *
6886
+ * The comment label follows the passage on the very next line: a blank line
6887
+ * between them read as if the comment belonged to nothing above it.
6888
+ *
4994
6889
  * The number goes on in `annotationsPrompt`, which keeps this text contiguous:
4995
6890
  * the composer looks for it in the draft before carrying an annotation again.
4996
6891
  * @param annotation - the annotation to render.
4997
6892
  * @returns message text for one annotation, its continuation lines indented.
4998
6893
  */
4999
6894
  function annotationBlock(annotation) {
5000
- const passage = annotation.passage.replace(/\s+/g, " ").trim();
5001
- const quoted = passage.length > 140 ? `${passage.slice(0, 139)}…` : passage;
5002
- const lines = ["Selected text:", `${INDENT}${quoted}`];
6895
+ const passage = annotation.passage.replace(/\r\n|\r/g, "\n").trim();
6896
+ const lines = ["Selected text:", ...indentedLines(passage.length > 140 ? `${passage.slice(0, 139)}…` : passage)];
5003
6897
  const note = annotation.note.replace(/\r\n|\r/g, "\n").trim();
5004
6898
  if (note.length > 0) {
5005
- lines.push("", `${INDENT}User comment:`);
5006
- for (const line of note.split("\n")) lines.push(`${INDENT}${line}`);
6899
+ lines.push(`${INDENT$1}User comment:`);
6900
+ lines.push(...indentedLines(note));
5007
6901
  }
5008
6902
  return lines.join("\n");
5009
6903
  }
@@ -5020,6 +6914,25 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
5020
6914
  return annotations.map((annotation, index) => `${index + 1}. ${annotationBlock(annotation)}`).join("\n\n");
5021
6915
  }
5022
6916
  /**
6917
+ * The text the composer inserts for the marked passages.
6918
+ *
6919
+ * The reader's own summary is already in the draft, and the passages follow it.
6920
+ * Left on the same line, the summary and the first entry read as one sentence,
6921
+ * so the passages start on the next line whenever something precedes them. The
6922
+ * block itself keeps one blank line between entries, and the trailing blank
6923
+ * line leaves room for the reader's body text under the passages.
6924
+ * @param draft - the text already in the composer.
6925
+ * @param annotations - the annotations being carried.
6926
+ * @param caret - where the passages are inserted, as an offset into the draft.
6927
+ * @returns the text to insert, or an empty string when there is nothing to carry.
6928
+ */
6929
+ function annotationInsertion(draft, annotations, caret = draft.length) {
6930
+ const block = annotationsPrompt(annotations);
6931
+ if (block === "") return "";
6932
+ const at = Math.max(0, Math.min(caret, draft.length));
6933
+ return `${draft.slice(0, at).trim().length > 0 ? "\n" : ""}${block}\n\n`;
6934
+ }
6935
+ /**
5023
6936
  * Annotations whose passage is rendered in one Session's transcript.
5024
6937
  *
5025
6938
  * An annotation is listed under the composer it will be sent from, but its mark
@@ -5714,10 +7627,11 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
5714
7627
  try {
5715
7628
  const missing = annotations.filter((annotation) => !draft.includes(annotationBlock(annotation)));
5716
7629
  if (missing.length > 0) {
5717
- const text = `${annotationsPrompt(missing)}\n\n`;
5718
7630
  const insertion = inputActions.captureInsertion();
7631
+ const text = annotationInsertion(draft, missing, insertion.start);
5719
7632
  if (!inputActions.insertText(text, insertion)) {
5720
- inputActions.setDraft(`${draft}${draft === "" ? "" : "\n\n"}${text}`);
7633
+ const fallback = annotationInsertion(draft, missing);
7634
+ inputActions.setDraft(`${draft}${fallback}`);
5721
7635
  inputActions.persistDraft();
5722
7636
  }
5723
7637
  }
@@ -5808,6 +7722,283 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
5808
7722
  return element.closest("[data-sidebar-chat], [data-dsh-enhance-side-chat]") === null;
5809
7723
  }, [root]);
5810
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
+ };
5811
8002
  // src/client/SideChatBody.tsx
5812
8003
  /**
5813
8004
  * Bind the tab's retained conversation around its slot.
@@ -5978,7 +8169,8 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
5978
8169
  "resources",
5979
8170
  "sidebarRightTabs",
5980
8171
  "remote",
5981
- "remote.session"
8172
+ "remote.session",
8173
+ "uiConversation"
5982
8174
  ];
5983
8175
  /**
5984
8176
  * Mount the plugin.
@@ -5986,25 +8178,31 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
5986
8178
  */
5987
8179
  function apply(ctx) {
5988
8180
  const t = ctx.locale.bind(LOCALE_NS);
8181
+ const features = featuresFor(currentSurface());
5989
8182
  ctx.effect(() => ctx.locale.register(LOCALE_NS, {
5990
8183
  zh,
5991
8184
  en
5992
8185
  }), "dsh-enhance: dictionaries");
5993
8186
  installStyles(ctx);
5994
- ctx.effect(() => installWhaleBubbles(document), "dsh-enhance: whale bubbles");
5995
- ctx.effect(() => installFileMenu(ctx, t), "dsh-enhance: file context menu");
5996
- const widthStore = pageStorage();
5997
- ctx.effect(() => installSidebarFloor(document, {
5998
- initialWidth: startupSidebarWidth(widthStore),
5999
- onCommit: (width) => {
6000
- rememberSidebarWidth(widthStore, width);
6001
- }
6002
- }), "dsh-enhance: sidebar floor");
6003
- ctx.effect(() => installSidebarTopRow(document), "dsh-enhance: sidebar top row");
6004
- ctx.effect(() => installSectionStats(ctx, document), "dsh-enhance: section stats");
6005
- if (isDesktopShell()) ctx.effect(() => installStartupGeometry(window), "dsh-enhance: window geometry");
6006
- ctx.effect(() => installTurnBadge(ctx), "dsh-enhance: turn badge");
6007
- registerSideChat(ctx, t);
8187
+ if (features.whale) ctx.effect(() => installWhaleBubbles(document), "dsh-enhance: whale bubbles");
8188
+ if (features.fileMenu) ctx.effect(() => installFileMenu(ctx, t), "dsh-enhance: file context menu");
8189
+ if (features.sidebarFloor) {
8190
+ const widthStore = pageStorage();
8191
+ ctx.effect(() => installSidebarFloor(document, {
8192
+ initialWidth: startupSidebarWidth(widthStore),
8193
+ onCommit: (width) => {
8194
+ rememberSidebarWidth(widthStore, width);
8195
+ }
8196
+ }), "dsh-enhance: sidebar floor");
8197
+ }
8198
+ if (features.sidebarTopRow) ctx.effect(() => installSidebarTopRow(document), "dsh-enhance: sidebar top row");
8199
+ if (features.panelWidths) ctx.effect(() => installPanelWidths(document), "dsh-enhance: panel widths");
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");
8202
+ if (features.sectionStats) ctx.effect(() => installSectionStats(ctx, document), "dsh-enhance: section stats");
8203
+ if (features.windowGeometry && isDesktopShell()) ctx.effect(() => installStartupGeometry(window), "dsh-enhance: window geometry");
8204
+ if (features.badge) ctx.effect(() => installTurnBadge(ctx), "dsh-enhance: turn badge");
8205
+ if (features.sideChat) registerSideChat(ctx, t);
6008
8206
  /**
6009
8207
  * Open a side conversation beside the current one and hand it the passage as
6010
8208
  * an annotation, not as typed text.
@@ -6040,13 +8238,22 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
6040
8238
  if (openingSideChat === work) openingSideChat = void 0;
6041
8239
  }
6042
8240
  };
6043
- ctx.effect(() => ctx.slots.inject("conversation.input.overlay", () => ctx.slots.register({
8241
+ if (features.annotations) ctx.effect(() => ctx.slots.inject("conversation.input.overlay", () => ctx.slots.register({
6044
8242
  name: "conversation.input.overlay",
6045
8243
  id: "dsh-enhance-annotations",
6046
8244
  order: 10,
6047
8245
  locale: LOCALE_NS,
6048
8246
  inject: () => ({ askInSideChat })
6049
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
+ }
6050
8257
  }
6051
8258
  /**
6052
8259
  * The workspace a side conversation for one passage belongs in.