dsh-enhance 0.3.2 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,7 +5,7 @@ DeepSeek Harness(DSH)增强插件:Markdown 主题统一、划词批注、
5
5
  ## 功能
6
6
 
7
7
  - **Markdown 主题** — 统一主对话、侧栏对话、文件预览等所有 `MarkdownText` 渲染的排版:标题配色、加粗、行内代码、代码块、表格、引用块。浅色/深色两套配色自动跟随主题。
8
- - **划词批注** — 选中文字弹出小面板写一句要求(Enter 确认,Esc 取消;弹窗出现即自动聚焦输入框,光标落在末尾)。确认后汇总为输入框内的 `N annotations` 胶囊:
8
+ - **划词批注** — 选中文字弹出小面板写一句要求(Enter 确认,Esc 取消;弹窗出现即自动聚焦输入框,光标落在末尾)。面板打开期间 `Cmd/Ctrl+C` 复制的仍是刚选中的段落(在输入框内自己选中文字时,复制的就是输入框里的那段)。确认后汇总为输入框内的 `N annotations` 胶囊:
9
9
  - 悬停胶囊展开列表,每行显示要求与引文
10
10
  - 悬停行会在正文高亮对应段落,点击行滚动定位到原文
11
11
  - 每行右侧可编辑(弹窗)或删除,胶囊右侧一键清空
@@ -20,7 +20,7 @@ DeepSeek Harness(DSH)增强插件:Markdown 主题统一、划词批注、
20
20
  - **启动即最窄** — 首次启动侧栏直接是 214px(上游每次加载都回到 280px),之后按你上次拖到的宽度打开。折叠/展开不会丢掉这个宽度。
21
21
  - **窗口铺满屏幕** — 首次启动主窗口铺满可用区域(菜单栏与 Dock 保留,等同绿色按钮的缩放);之后按上次关闭时的窗口位置与大小重新打开。保存的窗口若超出当前显示器(换屏、改分辨率)会被拉回可见区域。
22
22
  - **运行中彩色转圈** — 侧栏里正在运行的会话,状态环不再是宿主那样的灰色,而是一圈彩色:蓝→紫→洋红→琥珀的 4 秒色相循环,浅色与深色主题下都清晰。环的转动与虚线段仍由宿主驱动,本插件只改颜色;其他位置的状态点(任务、审批、工作流)保持原样。
23
- - **Dock 完成角标** — macOS Dock 图标上的红色数字 = 侧栏「绿点未读会话」的数量:某会话跑完而你没在看它(切到别的会话或别的 App)就 +1,点开读一下即 -1,全部读完角标消失。直接映射宿主 `uiSession.sessionStatus.completionUnread`(与侧栏绿点同一数据源),走标准 Badging API(`navigator.setAppBadge`),宿主不支持时静默降级。
23
+ - **Dock 完成角标** — macOS Dock 图标上的红色数字 = 侧栏「绿点未读会话」的数量:某会话跑完而你没在看它(切到别的会话或别的 App)就 +1,点开读一下即 -1,全部读完角标消失。直接映射宿主 `uiSession.sessionStatus.completionUnread`(与侧栏绿点同一数据源)。页面侧把数字报到插件自己的 Host 路由 `/dsh-enhance/badge`,由主进程 `app.dock.setBadge` 画角标——Electron 渲染层不实现 Badging API,之前走 `navigator.setAppBadge` 是空操作;普通浏览器里仍保留 Badging API 作为备选。
24
24
 
25
25
  ## 安装
26
26
 
@@ -31,9 +31,9 @@ DSH 打开 **Plugins** 页面 → 添加插件 → 输入 `dsh-enhance` → 安
31
31
  ### 方式二:本地 tar 包
32
32
 
33
33
  ```bash
34
- # 从 Releases 下载 dsh-enhance-0.3.2.tgz 后
34
+ # 从 Releases 下载 dsh-enhance-0.3.4.tgz 后
35
35
  cd ~/.dsh/profiles/desktop
36
- npx pnpm@11.28.5 add "file:/绝对路径/dsh-enhance-0.3.2.tgz"
36
+ npx pnpm@11.28.5 add "file:/绝对路径/dsh-enhance-0.3.4.tgz"
37
37
  ```
38
38
 
39
39
  再编辑 `~/.dsh/profiles/desktop/package.json`,把 `dsh-enhance` 加入 `dsh.profile.bundles`:
@@ -110,7 +110,8 @@ npx pnpm@11.28.5 remove dsh-enhance
110
110
  | `src/client/sidebar-floor.ts` | 侧栏拖拽下限(264 → 214)、启动宽度应用与拖拽落定回调 |
111
111
  | `src/client/sidebar-width.ts` | 记住侧栏宽度(首次 214,之后按上次拖到的值) |
112
112
  | `src/client/window-geometry.ts` | 窗口几何:首次铺满可用区域,之后恢复上次的窗口位置与大小 |
113
- | `src/client/turn-badge.ts` | Dock 未读会话角标(映射宿主 completionUnread) |
113
+ | `src/client/turn-badge.ts` | Dock 未读会话角标(映射宿主 completionUnread,报到 Host 路由) |
114
+ | `src/index.ts` | Host 半边:`/dsh-enhance/badge` 路由,主进程画 Dock 角标 |
114
115
  | `src/client/side-chat.ts` | 侧栏对话资源与标签页 |
115
116
  | `src/client/styles/` | 各样式表(每个文件导出一个 `String.raw` 模板);`running-spinner.ts` 负责侧栏运行中色环 |
116
117
  | `lib/` | 构建产物,即 `npm pack` 打包内容 |
package/lib/client.js CHANGED
@@ -856,8 +856,10 @@ body[data-ds-dark-theme] ::highlight(dsh-enhance-annotation-mark) {
856
856
  vertical-align: 8px;
857
857
  cursor: pointer;
858
858
  /* The glyph floats over the passage: a soft cast shadow puts it in front of the
859
- text instead of sitting flat in the line. */
860
- filter: drop-shadow(0 2px 3px rgb(0 0 0 / 42%));
859
+ text instead of sitting flat in the line. On white paper the dark-theme cast
860
+ read as a smudge under the disc, so the light theme gets the same lift at a
861
+ third of the weight. */
862
+ filter: drop-shadow(0 1px 2px rgb(15 17 21 / 22%));
861
863
  transition: transform 110ms ease, filter 110ms ease;
862
864
  }
863
865
 
@@ -871,6 +873,14 @@ body[data-ds-dark-theme] ::highlight(dsh-enhance-annotation-mark) {
871
873
 
872
874
  .dsh-enhance-badge:hover {
873
875
  transform: scale(1.1);
876
+ filter: drop-shadow(0 2px 5px rgb(15 17 21 / 32%));
877
+ }
878
+
879
+ body[data-ds-dark-theme] .dsh-enhance-badge {
880
+ filter: drop-shadow(0 2px 3px rgb(0 0 0 / 42%));
881
+ }
882
+
883
+ body[data-ds-dark-theme] .dsh-enhance-badge:hover {
874
884
  filter: drop-shadow(0 3px 6px rgb(0 0 0 / 52%));
875
885
  }
876
886
 
@@ -899,15 +909,22 @@ body[data-ds-dark-theme] ::highlight(dsh-enhance-annotation-mark) {
899
909
  horizontal padding, so text never touches the rounded corners. */
900
910
  padding: 0;
901
911
  border-radius: 18px;
902
- border: 0.5px solid color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent);
903
- background: color-mix(in srgb, var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-l1, #fff)) 76%, transparent);
904
- box-shadow: 0 16px 40px -12px rgb(0 0 0 / 40%);
912
+ border: 0.5px solid var(--dsw-alias-border-l3);
913
+ /* The app's real surface token, not a guessed name: --dsw-alias-bg-layer-1
914
+ is #fff on the light theme and #232324 on the dark one, so one rule covers
915
+ both. The light card stays nearly opaque — a translucent white over white
916
+ text has no edge at all — while the dark card keeps its glass. */
917
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 96%, transparent);
918
+ /* Hairline stroke + a low, soft cast: the theme's own elevation, which is far
919
+ quieter than a black 40% shadow and is what makes a white card sit on a
920
+ white page instead of dissolving into it. */
921
+ box-shadow: var(--dsw-elevation-prominent, 0 3px 8px rgb(0 0 0 / 6%)), 0 12px 32px -14px rgb(15 17 21 / 20%);
905
922
  backdrop-filter: blur(24px) saturate(1.6);
906
923
  animation: dsh-enhance-pop-in 110ms cubic-bezier(.2, .8, .3, 1);
907
924
  }
908
925
 
909
926
  body[data-ds-dark-theme] .dsh-enhance-popover {
910
- background: color-mix(in srgb, var(--dsw-alias-bg-l1, #1b1b1c) 70%, transparent);
927
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #1b1b1c) 70%, transparent);
911
928
  box-shadow: 0 20px 48px -16px rgb(0 0 0 / 62%), inset 0 0 0 0.5px rgb(255 255 255 / 7%);
912
929
  }
913
930
 
@@ -970,13 +987,21 @@ body[data-ds-dark-theme] .dsh-enhance-popover {
970
987
  border: 0;
971
988
  border-radius: 50%;
972
989
  background: var(--dsw-alias-label-primary);
973
- color: var(--dsw-alias-bg-l1, #111);
990
+ /* The token that actually flips with the theme: white on light, #0f1115 on
991
+ dark. --dsw-alias-bg-l1 does not exist, so the glyph fell back to a
992
+ literal and only looked right by luck in one theme. */
993
+ color: var(--dsw-alias-label-primary-foreground);
974
994
  cursor: pointer;
975
- transition: opacity 120ms ease, transform 120ms ease;
995
+ transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
976
996
  }
977
997
 
998
+ /* Nothing to confirm yet: a hairline ring with a muted check, not a filled disc
999
+ faded to 22%. On a white card the faded fill read as a grey blob with an
1000
+ invisible glyph, which looks like a loading placeholder rather than a state. */
978
1001
  .dsh-enhance-popover__confirm:disabled {
979
- opacity: .22;
1002
+ background: transparent;
1003
+ box-shadow: inset 0 0 0 1px var(--dsw-alias-border-l3);
1004
+ color: var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));
980
1005
  cursor: default;
981
1006
  }
982
1007
 
@@ -1004,7 +1029,9 @@ body[data-ds-dark-theme] .dsh-enhance-popover {
1004
1029
  .dsh-enhance-popover__quote {
1005
1030
  min-width: 0;
1006
1031
  overflow: hidden;
1007
- color: var(--dsw-alias-label-tertiary, var(--dsw-alias-label-secondary));
1032
+ /* Secondary, not tertiary: the quote previews the passage under discussion, and
1033
+ at 11px on a white card the tertiary grey was too faint to read at a glance. */
1034
+ color: var(--dsw-alias-label-secondary);
1008
1035
  font-size: 11px;
1009
1036
  line-height: 15px;
1010
1037
  text-overflow: ellipsis;
@@ -1059,13 +1086,19 @@ body[data-ds-dark-theme] .dsh-enhance-popover {
1059
1086
  align-items: center;
1060
1087
  border: 0.5px solid var(--dsw-alias-border-l3);
1061
1088
  border-radius: 10px;
1062
- background: var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-l1, #fff));
1063
- box-shadow: 0 2px 8px rgb(0 0 0 / 14%);
1089
+ /* The pill sits on the composer card, so it takes the raised layer rather than
1090
+ the page colour: white-on-white on the light theme had no edge but its
1091
+ hairline, and the card's own shadow is what does the lifting. */
1092
+ background: var(--dsw-alias-bg-layer-1, #fff);
1093
+ box-shadow: var(--dsw-elevation-panel, 0 2px 8px rgb(0 0 0 / 8%));
1064
1094
  overflow: hidden;
1065
1095
  }
1066
1096
 
1067
1097
  body[data-ds-dark-theme] .dsh-enhance-tray__pill {
1068
- background: color-mix(in srgb, var(--dsw-alias-bg-l1, #1b1b1c) 94%, #fff 6%);
1098
+ /* One step above the composer's own layer, so the pill still reads as raised
1099
+ when both are dark. */
1100
+ background: var(--dsw-alias-bg-layer-2, #2c2c2e);
1101
+ box-shadow: 0 2px 8px rgb(0 0 0 / 28%);
1069
1102
  }
1070
1103
 
1071
1104
  .dsh-enhance-tray__divider {
@@ -1131,17 +1164,17 @@ body[data-ds-dark-theme] .dsh-enhance-tray__pill {
1131
1164
  margin: 0;
1132
1165
  padding: 6px;
1133
1166
  list-style: none;
1134
- border: 0.5px solid color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent);
1167
+ border: 0.5px solid var(--dsw-alias-border-l3);
1135
1168
  border-radius: 14px;
1136
- background: color-mix(in srgb, var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-l1, #fff)) 82%, transparent);
1169
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 97%, transparent);
1137
1170
  backdrop-filter: blur(20px) saturate(1.4);
1138
- box-shadow: 0 12px 32px -8px rgb(0 0 0 / 38%);
1171
+ box-shadow: var(--dsw-elevation-prominent, 0 3px 8px rgb(0 0 0 / 6%)), 0 18px 44px -18px rgb(15 17 21 / 24%);
1139
1172
  max-height: 260px;
1140
1173
  overflow-y: auto;
1141
1174
  }
1142
1175
 
1143
1176
  body[data-ds-dark-theme] .dsh-enhance-tray__list {
1144
- background: color-mix(in srgb, var(--dsw-alias-bg-l1, #1b1b1c) 82%, transparent);
1177
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-2, #2c2c2e) 94%, transparent);
1145
1178
  box-shadow: 0 16px 40px -12px rgb(0 0 0 / 58%);
1146
1179
  }
1147
1180
 
@@ -1218,17 +1251,20 @@ body[data-ds-dark-theme] .dsh-enhance-tray__list {
1218
1251
  border-radius: 999px;
1219
1252
  /* A solid pill, not a gradient: fading over text looked like a smudge, and the
1220
1253
  icons must stay readable on top of the note they cover. */
1221
- background: var(--dsw-alias-bg-elevated, #1b1b1c);
1254
+ background: var(--dsw-alias-bg-layer-1, #fff);
1222
1255
  box-shadow:
1223
- 0 0 0 0.5px color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent),
1224
- 0 2px 8px rgb(0 0 0 / 22%);
1256
+ 0 0 0 0.5px var(--dsw-alias-border-l3),
1257
+ 0 2px 8px rgb(15 17 21 / 18%);
1225
1258
  opacity: 0;
1226
1259
  pointer-events: none;
1227
1260
  transition: opacity 110ms ease;
1228
1261
  }
1229
1262
 
1230
1263
  body[data-ds-dark-theme] .dsh-enhance-tray__actions {
1231
- background: color-mix(in srgb, var(--dsw-alias-bg-l1, #1b1b1c) 96%, #fff 4%);
1264
+ background: var(--dsw-alias-bg-layer-2, #2c2c2e);
1265
+ box-shadow:
1266
+ 0 0 0 0.5px var(--dsw-alias-border-l3),
1267
+ 0 2px 8px rgb(0 0 0 / 40%);
1232
1268
  }
1233
1269
 
1234
1270
  .dsh-enhance-tray__icon {
@@ -1285,16 +1321,16 @@ body[data-ds-dark-theme] .dsh-enhance-tray__actions {
1285
1321
  max-width: calc(100vw - 24px);
1286
1322
  gap: 2px;
1287
1323
  padding: 10px;
1288
- border: 0.5px solid color-mix(in srgb, var(--dsw-alias-label-primary) 15%, transparent);
1324
+ border: 0.5px solid var(--dsw-alias-border-l3);
1289
1325
  border-radius: 14px;
1290
- background: color-mix(in srgb, var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-l1, #fff)) 94%, transparent);
1326
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 96%, transparent);
1291
1327
  backdrop-filter: blur(24px) saturate(1.5);
1292
- box-shadow: 0 18px 44px -14px rgb(0 0 0 / 46%);
1328
+ box-shadow: var(--dsw-elevation-prominent, 0 3px 8px rgb(0 0 0 / 6%)), 0 18px 44px -16px rgb(15 17 21 / 24%);
1293
1329
  animation: dsh-enhance-pop-in 100ms cubic-bezier(.2, .8, .3, 1);
1294
1330
  }
1295
1331
 
1296
1332
  body[data-ds-dark-theme] .dsh-enhance-edit {
1297
- background: color-mix(in srgb, var(--dsw-alias-bg-l1, #1b1b1c) 94%, transparent);
1333
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #1b1b1c) 92%, transparent);
1298
1334
  box-shadow: 0 20px 48px -16px rgb(0 0 0 / 62%), inset 0 0 0 0.5px rgb(255 255 255 / 7%);
1299
1335
  }
1300
1336
 
@@ -1448,16 +1484,16 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
1448
1484
  max-width: calc(100vw - 24px);
1449
1485
  padding: 8px;
1450
1486
  gap: 6px;
1451
- border: 0.5px solid color-mix(in srgb, var(--dsw-alias-label-primary) 16%, transparent);
1487
+ border: 0.5px solid var(--dsw-alias-border-l3);
1452
1488
  border-radius: 14px;
1453
- background: color-mix(in srgb, var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-l1, #fff)) 92%, transparent);
1489
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 96%, transparent);
1454
1490
  backdrop-filter: blur(24px) saturate(1.5);
1455
- box-shadow: 0 20px 48px -14px rgb(0 0 0 / 48%);
1491
+ box-shadow: var(--dsw-elevation-prominent, 0 3px 8px rgb(0 0 0 / 6%)), 0 20px 48px -16px rgb(15 17 21 / 24%);
1456
1492
  animation: dsh-enhance-pop-in 100ms cubic-bezier(.2, .8, .3, 1);
1457
1493
  }
1458
1494
 
1459
1495
  body[data-ds-dark-theme] .dsh-enhance-edit {
1460
- background: color-mix(in srgb, var(--dsw-alias-bg-l1, #1b1b1c) 92%, transparent);
1496
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #1b1b1c) 92%, transparent);
1461
1497
  box-shadow: 0 22px 52px -16px rgb(0 0 0 / 62%), inset 0 0 0 0.5px rgb(255 255 255 / 7%);
1462
1498
  }
1463
1499
 
@@ -1592,15 +1628,16 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
1592
1628
  /* Flush like the selection popover: the field and the header sit on the
1593
1629
  dialog's own surface instead of inside a second inset frame. */
1594
1630
  padding: 0;
1595
- border: 0.5px solid color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent);
1631
+ border: 0.5px solid var(--dsw-alias-border-l3);
1596
1632
  border-radius: 16px;
1597
- background: color-mix(in srgb, var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-l1, #fff)) 90%, transparent);
1633
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-1, #fff) 96%, transparent);
1598
1634
  backdrop-filter: blur(24px) saturate(1.5);
1599
- box-shadow: 0 24px 64px -16px rgb(0 0 0 / 52%);
1635
+ box-shadow: var(--dsw-elevation-prominent, 0 3px 8px rgb(0 0 0 / 6%)), 0 24px 64px -18px rgb(15 17 21 / 26%);
1600
1636
  }
1601
1637
 
1602
1638
  body[data-ds-dark-theme] .dsh-enhance-edit {
1603
- background: color-mix(in srgb, var(--dsw-alias-bg-l1, #1b1b1c) 88%, transparent);
1639
+ background: color-mix(in srgb, var(--dsw-alias-bg-layer-2, #2c2c2e) 92%, transparent);
1640
+ box-shadow: 0 24px 64px -16px rgb(0 0 0 / 62%), inset 0 0 0 0.5px rgb(255 255 255 / 7%);
1604
1641
  }
1605
1642
 
1606
1643
  /* Anchored variant: coordinates come from the badge, so the centring transform
@@ -2376,26 +2413,88 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2376
2413
  return null;
2377
2414
  }
2378
2415
  }
2416
+ // src/badge-route.ts
2417
+ /**
2418
+ * The one path the browser half and the Host half share for the Dock badge.
2419
+ *
2420
+ * The two halves are separate bundles (node ESM for the Host, a module-table
2421
+ * factory for the page) and cannot call each other directly, so the count
2422
+ * travels over the Host's own HTTP surface: the page POSTs it, the Host paints
2423
+ * the Dock tile. Keeping the path in one module is what stops the two halves
2424
+ * from drifting apart silently — a mismatch would look exactly like a badge
2425
+ * that never appears.
2426
+ */
2427
+ /** Host route that paints the Dock badge; also the URL the page POSTs to. */
2428
+ const BADGE_ROUTE = "/dsh-enhance/badge";
2379
2429
  // src/client/turn-badge.ts
2380
2430
  /** localStorage key of the pre-v2 accumulating badge; cleared once on mount. */
2381
2431
  const LEGACY_STORAGE_KEY = "dsh-enhance.turn-badge.v1";
2382
2432
  /**
2433
+ * Report one count to the Host's badge route.
2434
+ *
2435
+ * Fire-and-forget by design: a failed badge is cosmetic, and the sidebar dots
2436
+ * remain the source of truth the reader can still act on.
2437
+ * @param count - unread completions; 0 clears the tile.
2438
+ */
2439
+ function postBadgeCount(count) {
2440
+ if (typeof fetch !== "function" || typeof document === "undefined") return;
2441
+ const base = document.baseURI;
2442
+ if (typeof base !== "string" || base === "") return;
2443
+ let url;
2444
+ try {
2445
+ url = new URL(BADGE_ROUTE, base).href;
2446
+ } catch {
2447
+ return;
2448
+ }
2449
+ try {
2450
+ fetch(url, {
2451
+ method: "POST",
2452
+ headers: { "content-type": "application/json" },
2453
+ body: JSON.stringify({ count })
2454
+ }).catch(() => {});
2455
+ } catch {}
2456
+ }
2457
+ /**
2383
2458
  * Ids of visible (non-blank, non-subagent) sessions whose completion is
2384
2459
  * unread. Statuses of rows the list no longer carries are skipped: a deleted
2385
2460
  * conversation shows no dot in the sidebar either.
2386
2461
  * @param byId - the list snapshot's rows by id.
2387
2462
  * @param status - the Session status snapshot.
2463
+ * @param attention - sessions that finished while the window was in the
2464
+ * background; the Host's projection does not mark those.
2388
2465
  * @returns the ids to count on the tile, in list order.
2389
2466
  */
2390
- function unreadVisibleIds(byId, status) {
2467
+ function unreadVisibleIds(byId, status, attention) {
2391
2468
  const unread = [];
2392
2469
  for (const [id, row] of Object.entries(byId)) {
2393
2470
  if (row.blank === true || row.origin === "subagent") continue;
2394
- if (status.get(id)?.completionUnread === true) unread.push(id);
2471
+ if (status.get(id)?.completionUnread === true || attention?.has(id) === true) unread.push(id);
2395
2472
  }
2396
2473
  return unread;
2397
2474
  }
2398
2475
  /**
2476
+ * The page's own attention source: the window focus the browser reports, with
2477
+ * a hidden (minimised or fully occluded) document counting as unfocused.
2478
+ * @returns the source, or undefined outside a DOM.
2479
+ */
2480
+ function documentAttention() {
2481
+ if (typeof document === "undefined" || typeof window === "undefined") return void 0;
2482
+ const focused = () => document.hasFocus() && document.visibilityState !== "hidden";
2483
+ return {
2484
+ focused,
2485
+ subscribe(listener) {
2486
+ window.addEventListener("focus", listener);
2487
+ window.addEventListener("blur", listener);
2488
+ document.addEventListener("visibilitychange", listener);
2489
+ return () => {
2490
+ window.removeEventListener("focus", listener);
2491
+ window.removeEventListener("blur", listener);
2492
+ document.removeEventListener("visibilitychange", listener);
2493
+ };
2494
+ }
2495
+ };
2496
+ }
2497
+ /**
2399
2498
  * Install the unread-session Dock badge.
2400
2499
  * @param ctx - client root context providing the sessions and uiSession services.
2401
2500
  * @param deps - seams, overridable in tests.
@@ -2407,25 +2506,56 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2407
2506
  set: (contents) => badgeNavigator.setAppBadge?.(contents) ?? Promise.resolve(),
2408
2507
  clear: () => badgeNavigator.clearAppBadge?.() ?? Promise.resolve()
2409
2508
  } : void 0);
2410
- if (badge === void 0) return () => {};
2509
+ const paintHost = deps.paintHost ?? postBadgeCount;
2510
+ const attentionSource = deps.attention ?? documentAttention();
2411
2511
  const statusStore = deps.statusSource ?? ctx.uiSession?.sessionStatus;
2412
2512
  if (statusStore === void 0) return () => {};
2413
2513
  try {
2414
2514
  localStorage.removeItem(LEGACY_STORAGE_KEY);
2415
2515
  } catch {}
2416
2516
  let painted;
2517
+ /** Sessions that finished while the window was in the background. */
2518
+ const attention = /* @__PURE__ */ new Set();
2519
+ /** Last observed running flag per session, for detecting the finish edge. */
2520
+ let wasRunning = /* @__PURE__ */ new Map();
2521
+ /**
2522
+ * Record completions the Host's projection cannot see.
2523
+ *
2524
+ * The Host marks a finish unread only when that conversation is not the one
2525
+ * on screen; a turn that ends while the reader is in another app leaves the
2526
+ * running session on screen, so it is never marked. This watches the same
2527
+ * list for a running→idle edge while the page is unfocused.
2528
+ */
2529
+ const observeRunning = (byId) => {
2530
+ const next = /* @__PURE__ */ new Map();
2531
+ for (const [id, row] of Object.entries(byId)) {
2532
+ const running = row.running === true;
2533
+ if (wasRunning.get(id) === true && !running && attentionSource?.focused() === false) attention.add(id);
2534
+ next.set(id, running);
2535
+ }
2536
+ wasRunning = next;
2537
+ for (const id of [...attention]) if (!(id in byId)) attention.delete(id);
2538
+ };
2417
2539
  const paint = () => {
2418
- const count = unreadVisibleIds(ctx.sessions.list.getSnapshot().byId, statusStore.getSnapshot()).length;
2540
+ const byId = ctx.sessions.list.getSnapshot().byId;
2541
+ observeRunning(byId);
2542
+ const count = unreadVisibleIds(byId, statusStore.getSnapshot(), attention).length;
2419
2543
  if (painted === count) return;
2420
2544
  painted = count;
2421
- (count > 0 ? badge.set(count) : badge.clear()).catch(() => {});
2545
+ paintHost(count);
2546
+ if (badge !== void 0) (count > 0 ? badge.set(count) : badge.clear()).catch(() => {});
2422
2547
  };
2423
2548
  const stopStatus = statusStore.subscribe(paint);
2424
2549
  const stopList = ctx.sessions.list.subscribe(paint);
2550
+ const stopAttention = attentionSource?.subscribe(() => {
2551
+ if (attentionSource.focused()) attention.clear();
2552
+ paint();
2553
+ });
2425
2554
  paint();
2426
2555
  return () => {
2427
2556
  stopStatus();
2428
2557
  stopList();
2558
+ stopAttention?.();
2429
2559
  };
2430
2560
  }
2431
2561
  // src/client/locales.ts
@@ -2545,6 +2675,23 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2545
2675
  return collapsed.length > 8e3 ? collapsed.slice(0, MAX_SELECTION_CHARS) : collapsed;
2546
2676
  }
2547
2677
  /**
2678
+ * Text the copy shortcut should carry while the annotation popover is open.
2679
+ *
2680
+ * Opening the popover focuses the note field, and focusing a field takes the
2681
+ * document selection with it: Cmd+C then copies an empty box instead of the
2682
+ * words the reader just highlighted. So while the field holds no selection of
2683
+ * its own, the copy carries the marked passage; the moment the reader selects
2684
+ * text inside the field, the native copy is the one they asked for.
2685
+ * @param passage - the marked passage, when the popover is showing one.
2686
+ * @param field - the note field, once the popover has rendered it.
2687
+ * @returns text to write to the clipboard, or undefined to leave the copy alone.
2688
+ */
2689
+ function copyTextFor(passage, field) {
2690
+ if (passage === void 0 || passage.length === 0) return void 0;
2691
+ if (field !== null && field.selectionStart !== field.selectionEnd) return void 0;
2692
+ return passage;
2693
+ }
2694
+ /**
2548
2695
  * Place a `width`-wide box below (or above) an anchor rect, clamped into the viewport.
2549
2696
  * @param anchor - the selection rectangle.
2550
2697
  * @param width - toolbar width in CSS pixels.
@@ -3029,14 +3176,31 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3029
3176
  return badge;
3030
3177
  }
3031
3178
  /**
3032
- * Remove every badge this plugin inserted, restoring the text it split.
3179
+ * Remove the badges one owner mounted, leaving every other owner's in place.
3180
+ *
3181
+ * Two composers can be on screen at once — the main conversation and a side
3182
+ * chat tab — and each mounts markers for the passages it quotes. A global sweep
3183
+ * from one of them deletes the other's markers, the other re-mounts them, and
3184
+ * the two take turns writing the same subtree on every mutation. That is a
3185
+ * self-feeding loop with no end: it never yields, so the window stops painting
3186
+ * and every click is lost. Teardown is therefore keyed to the ids this owner
3187
+ * actually put on screen.
3188
+ * @param ids - annotation ids whose badges belong to the caller.
3189
+ * @returns how many badges were removed.
3033
3190
  */
3034
- function removeBadges() {
3191
+ function unmountBadges(ids) {
3192
+ const owned = new Set(ids);
3193
+ if (owned.size === 0) return 0;
3194
+ let removed = 0;
3035
3195
  for (const anchor of [...document.querySelectorAll("[data-dsh-enhance-badge-anchor]")]) {
3196
+ const id = anchor.querySelector(`[${BADGE_ATTRIBUTE}]`)?.getAttribute(BADGE_ATTRIBUTE);
3197
+ if (id === null || id === void 0 || !owned.has(id)) continue;
3036
3198
  const parent = anchor.parentNode;
3037
3199
  anchor.remove();
3038
3200
  parent?.normalize();
3201
+ removed += 1;
3039
3202
  }
3203
+ return removed;
3040
3204
  }
3041
3205
  // src/client/SelectionToolbar.tsx
3042
3206
  /**
@@ -3110,6 +3274,22 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3110
3274
  const onKey = (event) => {
3111
3275
  if (event.key === "Escape") dismiss();
3112
3276
  };
3277
+ /**
3278
+ * Keep Cmd/Ctrl+C working on the passage the popover just took focus from.
3279
+ *
3280
+ * The popover focuses the note field as it opens, which moves the document
3281
+ * selection into that field — a copy then finds an empty box and the reader
3282
+ * loses the words they highlighted. While the field holds no selection of
3283
+ * its own, the copy is answered with the marked passage instead; a selection
3284
+ * made inside the field still goes through the browser's own copy.
3285
+ */
3286
+ const onCopy = (event) => {
3287
+ if (event.defaultPrevented) return;
3288
+ const text = copyTextFor(latest.current?.text, input.current);
3289
+ if (text === void 0) return;
3290
+ event.clipboardData?.setData("text/plain", text);
3291
+ event.preventDefault();
3292
+ };
3113
3293
  const onScroll = (event) => {
3114
3294
  if (isInsidePopover(event.target)) return;
3115
3295
  dismiss();
@@ -3117,12 +3297,14 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3117
3297
  for (const name of SETTLE_EVENTS) document.addEventListener(name, settle, true);
3118
3298
  document.addEventListener("selectionchange", onChange);
3119
3299
  document.addEventListener("keydown", onKey, true);
3300
+ document.addEventListener("copy", onCopy);
3120
3301
  window.addEventListener("scroll", onScroll, true);
3121
3302
  window.addEventListener("resize", dismiss);
3122
3303
  return () => {
3123
3304
  for (const name of SETTLE_EVENTS) document.removeEventListener(name, settle, true);
3124
3305
  document.removeEventListener("selectionchange", onChange);
3125
3306
  document.removeEventListener("keydown", onKey, true);
3307
+ document.removeEventListener("copy", onCopy);
3126
3308
  window.removeEventListener("scroll", onScroll, true);
3127
3309
  window.removeEventListener("resize", dismiss);
3128
3310
  };
@@ -4022,33 +4204,60 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4022
4204
  if (target !== void 0) highlightAnnotation(target);
4023
4205
  setEditingId(id);
4024
4206
  };
4207
+ /**
4208
+ * Badges this seat put on screen.
4209
+ *
4210
+ * A second composer can be mounted at the same time — `Ask in side chat`
4211
+ * opens a tab whose seat marks the same transcript — and a teardown that
4212
+ * swept every badge in the document would delete the other seat's markers,
4213
+ * which the other seat then re-mounted, which fired this seat's observer
4214
+ * again. Two owners taking turns writing one subtree never yields: the page
4215
+ * stops painting entirely, which is what a frozen window looks like.
4216
+ */
4217
+ const owned = /* @__PURE__ */ new Set();
4025
4218
  /** Repaint marks and badges; idempotent, so calling it twice costs nothing. */
4026
4219
  const repaint = () => {
4027
4220
  const pinned = annotationsVisibleIn(sessionId);
4028
4221
  paintMarks(sessionId, pinned);
4029
4222
  mountBadges(pinned, onClick);
4223
+ owned.clear();
4224
+ for (const annotation of pinned) owned.add(annotation.id);
4030
4225
  };
4031
4226
  repaint();
4032
4227
  const scope = root.current?.ownerDocument;
4033
4228
  if (scope === null || scope === void 0) return () => {
4034
4229
  clearMarks(sessionId);
4035
4230
  };
4036
- let queued = false;
4037
4231
  const isOwnMutation = (record) => {
4038
4232
  const touch = [...record.addedNodes, ...record.removedNodes];
4039
- return touch.length > 0 && touch.every((node) => {
4040
- if (!(node instanceof Element)) return false;
4041
- return node.matches("[data-dsh-enhance-badge], [data-dsh-enhance-badge-anchor]") || node.querySelector("[data-dsh-enhance-badge]") !== null;
4233
+ if (touch.length === 0) return false;
4234
+ const holdsBadge = (record.target instanceof Element ? record.target : record.target.parentElement)?.querySelector("[data-dsh-enhance-badge-anchor]") != null;
4235
+ return touch.every((node) => {
4236
+ if (node instanceof Element) return node.matches("[data-dsh-enhance-badge], [data-dsh-enhance-badge-anchor]") || node.querySelector("[data-dsh-enhance-badge]") !== null;
4237
+ return holdsBadge && node.nodeType === Node.TEXT_NODE;
4042
4238
  });
4043
4239
  };
4044
- const observer = new MutationObserver((records) => {
4045
- if (records.every(isOwnMutation)) return;
4046
- if (queued) return;
4047
- queued = true;
4048
- queueMicrotask(() => {
4049
- queued = false;
4240
+ const MAX_REPAINTS_PER_SECOND = 30;
4241
+ let frame = 0;
4242
+ let windowStart = 0;
4243
+ let windowCount = 0;
4244
+ const schedule = () => {
4245
+ if (frame !== 0) return;
4246
+ frame = requestAnimationFrame(() => {
4247
+ frame = 0;
4248
+ const now = performance.now();
4249
+ if (now - windowStart > 1e3) {
4250
+ windowStart = now;
4251
+ windowCount = 0;
4252
+ }
4253
+ windowCount += 1;
4254
+ if (windowCount > MAX_REPAINTS_PER_SECOND) return;
4050
4255
  repaint();
4051
4256
  });
4257
+ };
4258
+ const observer = new MutationObserver((records) => {
4259
+ if (records.every(isOwnMutation)) return;
4260
+ schedule();
4052
4261
  });
4053
4262
  observer.observe(scope, {
4054
4263
  childList: true,
@@ -4056,7 +4265,8 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4056
4265
  });
4057
4266
  return () => {
4058
4267
  observer.disconnect();
4059
- removeBadges();
4268
+ if (frame !== 0) cancelAnimationFrame(frame);
4269
+ unmountBadges(owned);
4060
4270
  clearHighlight();
4061
4271
  clearMarks(sessionId);
4062
4272
  };
@@ -4340,6 +4550,11 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4340
4550
  // src/client/index.tsx
4341
4551
  /** The one side conversation this page opens; later requests add to it. */
4342
4552
  let openSideChat;
4553
+ /**
4554
+ * The open that is in flight, so a second click joins it instead of creating a
4555
+ * second conversation (a created-but-unused session is never reclaimed).
4556
+ */
4557
+ let openingSideChat;
4343
4558
  /** Required services: slots, dictionaries, session status, the Workspace list, and the right Sidebar. */
4344
4559
  const inject = [
4345
4560
  "slots",
@@ -4390,12 +4605,24 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4390
4605
  * @returns completion once the tab carries the conversation.
4391
4606
  */
4392
4607
  const askInSideChat = async (passage, note = "", sourceSessionId, anchor) => {
4393
- const workspaceId = ctx.workspaces.list.getSnapshot().items[0]?.workspaceId;
4394
- if (workspaceId === void 0) throw new Error(t("error.noWorkspace"));
4395
- const sessionId = sideChatSession() ?? await createSideChatSession(ctx, workspaceId);
4396
- rememberTitle(sessionId, firstLine(passage));
4397
- addAnnotation(sessionId, passage, note, anchor, sourceSessionId);
4398
- ctx.sidebarRight.openResource(sideChatAddress(sessionId));
4608
+ if (openingSideChat !== void 0) {
4609
+ await openingSideChat;
4610
+ return;
4611
+ }
4612
+ const work = (async () => {
4613
+ const workspaceId = workspaceFor(ctx, sourceSessionId);
4614
+ if (workspaceId === void 0) throw new Error(t("error.noWorkspace"));
4615
+ const sessionId = sideChatSession() ?? await createSideChatSession(ctx, workspaceId);
4616
+ rememberTitle(sessionId, firstLine(passage));
4617
+ addAnnotation(sessionId, passage, note, anchor, sourceSessionId);
4618
+ ctx.sidebarRight.openResource(sideChatAddress(sessionId));
4619
+ })();
4620
+ openingSideChat = work;
4621
+ try {
4622
+ await work;
4623
+ } finally {
4624
+ if (openingSideChat === work) openingSideChat = void 0;
4625
+ }
4399
4626
  };
4400
4627
  ctx.effect(() => ctx.slots.inject("conversation.input.overlay", () => ctx.slots.register({
4401
4628
  name: "conversation.input.overlay",
@@ -4406,6 +4633,25 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4406
4633
  }, AnnotationSeat)), "dsh-enhance: annotation seat");
4407
4634
  }
4408
4635
  /**
4636
+ * The workspace a side conversation for one passage belongs in.
4637
+ *
4638
+ * A Workspace is the container a session is listed under; the reader asked from
4639
+ * a conversation, so that conversation's own workspace is the answer. Falling
4640
+ * back to the first workspace keeps the gesture working before the list has
4641
+ * loaded.
4642
+ * @param ctx - client root carrying the Workspace list.
4643
+ * @param sourceSessionId - conversation the passage was selected in.
4644
+ * @returns the workspace to create the side conversation in.
4645
+ */
4646
+ function workspaceFor(ctx, sourceSessionId) {
4647
+ const items = ctx.workspaces.list.getSnapshot().items;
4648
+ if (sourceSessionId !== void 0) {
4649
+ const owner = items.find((item) => item.sessionIds?.includes(sourceSessionId) === true);
4650
+ if (owner !== void 0) return owner.workspaceId;
4651
+ }
4652
+ return items[0]?.workspaceId;
4653
+ }
4654
+ /**
4409
4655
  * The side conversation this page keeps open, once one exists.
4410
4656
  * @returns the remembered session id, or undefined before the first request.
4411
4657
  */
package/lib/index.js CHANGED
@@ -1,11 +1,114 @@
1
+ // src/badge-route.ts
2
+ /**
3
+ * The one path the browser half and the Host half share for the Dock badge.
4
+ *
5
+ * The two halves are separate bundles (node ESM for the Host, a module-table
6
+ * factory for the page) and cannot call each other directly, so the count
7
+ * travels over the Host's own HTTP surface: the page POSTs it, the Host paints
8
+ * the Dock tile. Keeping the path in one module is what stops the two halves
9
+ * from drifting apart silently — a mismatch would look exactly like a badge
10
+ * that never appears.
11
+ */
12
+ /** Host route that paints the Dock badge; also the URL the page POSTs to. */
13
+ const BADGE_ROUTE = "/dsh-enhance/badge";
1
14
  // src/index.ts
15
+ /** Largest request body this route reads; the payload is one small number. */
16
+ const MAX_BODY = 2048;
2
17
  /**
3
- * Node half of dsh-enhance.
18
+ * Read the count out of a request body.
19
+ * @param req - the incoming request.
20
+ * @returns a clamped count, or undefined when the body is unusable.
21
+ */
22
+ async function readCount(req) {
23
+ const decoder = new TextDecoder();
24
+ let text = "";
25
+ for await (const chunk of req) {
26
+ text += typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
27
+ if (text.length > MAX_BODY) return void 0;
28
+ }
29
+ try {
30
+ const count = JSON.parse(text).count;
31
+ if (typeof count !== "number" || !Number.isFinite(count)) return void 0;
32
+ return Math.max(0, Math.min(999, Math.trunc(count)));
33
+ } catch {
34
+ return;
35
+ }
36
+ }
37
+ /**
38
+ * Paint the native badge for one count.
4
39
  *
5
- * The plugin is browser-only: its row exists so the host's client module
6
- * system serves the bundle, and so the bundle can be switched on and off as
7
- * one unit. Nothing runs on the host.
40
+ * `electron` is imported at call time, never at module load: the same bundle
41
+ * also runs in hosts that are not Electron shells (a `dsh web` server, a test
42
+ * harness), where the import is unavailable and the badge simply stays off.
43
+ * @param count - unread completions; 0 clears the tile.
44
+ * @returns whether a native badge was painted.
45
+ */
46
+ async function paintDockBadge(count) {
47
+ try {
48
+ const app = (await import("electron")).app;
49
+ if (app === void 0) return false;
50
+ if (typeof app.dock?.setBadge === "function") {
51
+ app.dock.setBadge(count > 0 ? String(count) : "");
52
+ return true;
53
+ }
54
+ if (typeof app.setBadgeCount === "function") return app.setBadgeCount(count);
55
+ return false;
56
+ } catch {
57
+ return false;
58
+ }
59
+ }
60
+ /**
61
+ * Mount the badge route on the Host's web server.
62
+ * @param ctx - host context carrying `webServer` and `connection`.
8
63
  */
9
- /** Loader entry for the local enhancement bundle. */
10
- function apply() {}
64
+ function apply(ctx) {
65
+ const scope = ctx;
66
+ /** Register the route once the services it needs are present. */
67
+ const install = (host) => {
68
+ const webServer = host.webServer;
69
+ const connection = host.connection;
70
+ if (webServer === void 0 || connection === void 0) return;
71
+ /** One route: read the reported count and paint the native tile. */
72
+ const register = () => webServer.register({
73
+ kind: "exact",
74
+ path: BADGE_ROUTE,
75
+ async handler(req, res) {
76
+ const rejection = connection.requestRejection(req);
77
+ if (rejection !== void 0) {
78
+ res.writeHead(rejection);
79
+ res.end();
80
+ return;
81
+ }
82
+ if (req.method !== "POST") {
83
+ res.writeHead(405, { "content-type": "application/json" });
84
+ res.end("{\"ok\":false}");
85
+ return;
86
+ }
87
+ const count = await readCount(req);
88
+ if (count === void 0) {
89
+ res.writeHead(400, { "content-type": "application/json" });
90
+ res.end("{\"ok\":false}");
91
+ return;
92
+ }
93
+ const painted = await paintDockBadge(count);
94
+ res.writeHead(200, { "content-type": "application/json" });
95
+ res.end(JSON.stringify({
96
+ ok: true,
97
+ painted
98
+ }));
99
+ }
100
+ });
101
+ const effect = host.effect;
102
+ if (typeof effect === "function") {
103
+ effect(register, "dsh-enhance: dock badge route");
104
+ return;
105
+ }
106
+ register();
107
+ };
108
+ if (typeof scope.inject === "function") {
109
+ scope.inject(["webServer", "connection"], install);
110
+ return;
111
+ }
112
+ install(ctx);
113
+ }
11
114
  export { apply };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-enhance",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "DeepSeek Harness enhancements: Markdown theme for every renderer, select-text annotations with pins, a narrower sidebar, and startup defaults (maximized window, narrowest sidebar, colourful running marker). 中文:DSH 增强插件——Markdown 主题、划词批注、侧栏宽度、启动默认状态。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",