dsh-enhance 0.3.1 → 0.3.3

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
@@ -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.1.tgz 后
34
+ # 从 Releases 下载 dsh-enhance-0.3.3.tgz 后
35
35
  cd ~/.dsh/profiles/desktop
36
- npx pnpm@11.28.5 add "file:/绝对路径/dsh-enhance-0.3.1.tgz"
36
+ npx pnpm@11.28.5 add "file:/绝对路径/dsh-enhance-0.3.3.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
@@ -569,14 +569,21 @@ body:not([data-ds-dark-theme]) [data-document-markdown] {
569
569
 
570
570
  /* Dark mode: the app's label tokens resolve to near-white (label-primary #f9fafb,
571
571
  label-secondary #cfd3d6), which reads as glare against the dark sidebar surface.
572
- Redefining the two tokens inside the sidebar subtree dims only its text; the centre
573
- column, the right panel and the app's own dark palette keep their values. Measured
574
- against the dark sidebar surface this takes label-primary from ~16.6:1 to ~11:1 and
575
- label-secondary from ~11.5:1 to ~7.3:1, so both stay above WCAG AA. The variable
576
- override needs no !important: every rule above resolves through these tokens. */
572
+ Redefining the tokens inside the sidebar subtree dims only its text; the centre
573
+ column, the right panel and the app's own dark palette keep their values.
574
+
575
+ Measured live against the dark sidebar (#1b1b1c): titles and workspace names
576
+ paint through label-primary, section headings and timestamps through
577
+ label-secondary, and the overflow row ("Show N more sessions") plus the
578
+ running-status slot through label-tertiary. All three move down one step
579
+ together, so the whole column dims evenly instead of one row staying bright.
580
+ Against that surface the step lands at about 9.2:1, 6.2:1 and 6.7:1, all
581
+ still above WCAG AA. The variable override needs no !important: the rules
582
+ above, and the host's own rows, resolve through these tokens. */
577
583
  body[data-ds-dark-theme] [class*="sidebarCol"] {
578
- --dsw-alias-label-primary: #c9ced6;
579
- --dsw-alias-label-secondary: #a2a8b0;
584
+ --dsw-alias-label-primary: #bbc0c8;
585
+ --dsw-alias-label-secondary: #949aa2;
586
+ --dsw-alias-label-tertiary: #9fa4aa;
580
587
  }
581
588
 
582
589
  /* Text scale for a sidebar this plugin allows to be much narrower than upstream's
@@ -849,8 +856,10 @@ body[data-ds-dark-theme] ::highlight(dsh-enhance-annotation-mark) {
849
856
  vertical-align: 8px;
850
857
  cursor: pointer;
851
858
  /* The glyph floats over the passage: a soft cast shadow puts it in front of the
852
- text instead of sitting flat in the line. */
853
- 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%));
854
863
  transition: transform 110ms ease, filter 110ms ease;
855
864
  }
856
865
 
@@ -864,6 +873,14 @@ body[data-ds-dark-theme] ::highlight(dsh-enhance-annotation-mark) {
864
873
 
865
874
  .dsh-enhance-badge:hover {
866
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 {
867
884
  filter: drop-shadow(0 3px 6px rgb(0 0 0 / 52%));
868
885
  }
869
886
 
@@ -892,15 +909,22 @@ body[data-ds-dark-theme] ::highlight(dsh-enhance-annotation-mark) {
892
909
  horizontal padding, so text never touches the rounded corners. */
893
910
  padding: 0;
894
911
  border-radius: 18px;
895
- border: 0.5px solid color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent);
896
- background: color-mix(in srgb, var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-l1, #fff)) 76%, transparent);
897
- 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%);
898
922
  backdrop-filter: blur(24px) saturate(1.6);
899
923
  animation: dsh-enhance-pop-in 110ms cubic-bezier(.2, .8, .3, 1);
900
924
  }
901
925
 
902
926
  body[data-ds-dark-theme] .dsh-enhance-popover {
903
- 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);
904
928
  box-shadow: 0 20px 48px -16px rgb(0 0 0 / 62%), inset 0 0 0 0.5px rgb(255 255 255 / 7%);
905
929
  }
906
930
 
@@ -963,13 +987,21 @@ body[data-ds-dark-theme] .dsh-enhance-popover {
963
987
  border: 0;
964
988
  border-radius: 50%;
965
989
  background: var(--dsw-alias-label-primary);
966
- 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);
967
994
  cursor: pointer;
968
- transition: opacity 120ms ease, transform 120ms ease;
995
+ transition: background-color 120ms ease, color 120ms ease, transform 120ms ease;
969
996
  }
970
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. */
971
1001
  .dsh-enhance-popover__confirm:disabled {
972
- 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));
973
1005
  cursor: default;
974
1006
  }
975
1007
 
@@ -997,7 +1029,9 @@ body[data-ds-dark-theme] .dsh-enhance-popover {
997
1029
  .dsh-enhance-popover__quote {
998
1030
  min-width: 0;
999
1031
  overflow: hidden;
1000
- 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);
1001
1035
  font-size: 11px;
1002
1036
  line-height: 15px;
1003
1037
  text-overflow: ellipsis;
@@ -1052,13 +1086,19 @@ body[data-ds-dark-theme] .dsh-enhance-popover {
1052
1086
  align-items: center;
1053
1087
  border: 0.5px solid var(--dsw-alias-border-l3);
1054
1088
  border-radius: 10px;
1055
- background: var(--dsw-alias-bg-elevated, var(--dsw-alias-bg-l1, #fff));
1056
- 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%));
1057
1094
  overflow: hidden;
1058
1095
  }
1059
1096
 
1060
1097
  body[data-ds-dark-theme] .dsh-enhance-tray__pill {
1061
- 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%);
1062
1102
  }
1063
1103
 
1064
1104
  .dsh-enhance-tray__divider {
@@ -1124,17 +1164,17 @@ body[data-ds-dark-theme] .dsh-enhance-tray__pill {
1124
1164
  margin: 0;
1125
1165
  padding: 6px;
1126
1166
  list-style: none;
1127
- 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);
1128
1168
  border-radius: 14px;
1129
- 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);
1130
1170
  backdrop-filter: blur(20px) saturate(1.4);
1131
- 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%);
1132
1172
  max-height: 260px;
1133
1173
  overflow-y: auto;
1134
1174
  }
1135
1175
 
1136
1176
  body[data-ds-dark-theme] .dsh-enhance-tray__list {
1137
- 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);
1138
1178
  box-shadow: 0 16px 40px -12px rgb(0 0 0 / 58%);
1139
1179
  }
1140
1180
 
@@ -1211,17 +1251,20 @@ body[data-ds-dark-theme] .dsh-enhance-tray__list {
1211
1251
  border-radius: 999px;
1212
1252
  /* A solid pill, not a gradient: fading over text looked like a smudge, and the
1213
1253
  icons must stay readable on top of the note they cover. */
1214
- background: var(--dsw-alias-bg-elevated, #1b1b1c);
1254
+ background: var(--dsw-alias-bg-layer-1, #fff);
1215
1255
  box-shadow:
1216
- 0 0 0 0.5px color-mix(in srgb, var(--dsw-alias-label-primary) 14%, transparent),
1217
- 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%);
1218
1258
  opacity: 0;
1219
1259
  pointer-events: none;
1220
1260
  transition: opacity 110ms ease;
1221
1261
  }
1222
1262
 
1223
1263
  body[data-ds-dark-theme] .dsh-enhance-tray__actions {
1224
- 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%);
1225
1268
  }
1226
1269
 
1227
1270
  .dsh-enhance-tray__icon {
@@ -1278,16 +1321,16 @@ body[data-ds-dark-theme] .dsh-enhance-tray__actions {
1278
1321
  max-width: calc(100vw - 24px);
1279
1322
  gap: 2px;
1280
1323
  padding: 10px;
1281
- 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);
1282
1325
  border-radius: 14px;
1283
- 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);
1284
1327
  backdrop-filter: blur(24px) saturate(1.5);
1285
- 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%);
1286
1329
  animation: dsh-enhance-pop-in 100ms cubic-bezier(.2, .8, .3, 1);
1287
1330
  }
1288
1331
 
1289
1332
  body[data-ds-dark-theme] .dsh-enhance-edit {
1290
- 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);
1291
1334
  box-shadow: 0 20px 48px -16px rgb(0 0 0 / 62%), inset 0 0 0 0.5px rgb(255 255 255 / 7%);
1292
1335
  }
1293
1336
 
@@ -1441,16 +1484,16 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
1441
1484
  max-width: calc(100vw - 24px);
1442
1485
  padding: 8px;
1443
1486
  gap: 6px;
1444
- 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);
1445
1488
  border-radius: 14px;
1446
- 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);
1447
1490
  backdrop-filter: blur(24px) saturate(1.5);
1448
- 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%);
1449
1492
  animation: dsh-enhance-pop-in 100ms cubic-bezier(.2, .8, .3, 1);
1450
1493
  }
1451
1494
 
1452
1495
  body[data-ds-dark-theme] .dsh-enhance-edit {
1453
- 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);
1454
1497
  box-shadow: 0 22px 52px -16px rgb(0 0 0 / 62%), inset 0 0 0 0.5px rgb(255 255 255 / 7%);
1455
1498
  }
1456
1499
 
@@ -1585,15 +1628,16 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
1585
1628
  /* Flush like the selection popover: the field and the header sit on the
1586
1629
  dialog's own surface instead of inside a second inset frame. */
1587
1630
  padding: 0;
1588
- 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);
1589
1632
  border-radius: 16px;
1590
- 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);
1591
1634
  backdrop-filter: blur(24px) saturate(1.5);
1592
- 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%);
1593
1636
  }
1594
1637
 
1595
1638
  body[data-ds-dark-theme] .dsh-enhance-edit {
1596
- 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%);
1597
1641
  }
1598
1642
 
1599
1643
  /* Anchored variant: coordinates come from the badge, so the centring transform
@@ -2369,26 +2413,88 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2369
2413
  return null;
2370
2414
  }
2371
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";
2372
2429
  // src/client/turn-badge.ts
2373
2430
  /** localStorage key of the pre-v2 accumulating badge; cleared once on mount. */
2374
2431
  const LEGACY_STORAGE_KEY = "dsh-enhance.turn-badge.v1";
2375
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
+ /**
2376
2458
  * Ids of visible (non-blank, non-subagent) sessions whose completion is
2377
2459
  * unread. Statuses of rows the list no longer carries are skipped: a deleted
2378
2460
  * conversation shows no dot in the sidebar either.
2379
2461
  * @param byId - the list snapshot's rows by id.
2380
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.
2381
2465
  * @returns the ids to count on the tile, in list order.
2382
2466
  */
2383
- function unreadVisibleIds(byId, status) {
2467
+ function unreadVisibleIds(byId, status, attention) {
2384
2468
  const unread = [];
2385
2469
  for (const [id, row] of Object.entries(byId)) {
2386
2470
  if (row.blank === true || row.origin === "subagent") continue;
2387
- if (status.get(id)?.completionUnread === true) unread.push(id);
2471
+ if (status.get(id)?.completionUnread === true || attention?.has(id) === true) unread.push(id);
2388
2472
  }
2389
2473
  return unread;
2390
2474
  }
2391
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
+ /**
2392
2498
  * Install the unread-session Dock badge.
2393
2499
  * @param ctx - client root context providing the sessions and uiSession services.
2394
2500
  * @param deps - seams, overridable in tests.
@@ -2400,25 +2506,56 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
2400
2506
  set: (contents) => badgeNavigator.setAppBadge?.(contents) ?? Promise.resolve(),
2401
2507
  clear: () => badgeNavigator.clearAppBadge?.() ?? Promise.resolve()
2402
2508
  } : void 0);
2403
- if (badge === void 0) return () => {};
2509
+ const paintHost = deps.paintHost ?? postBadgeCount;
2510
+ const attentionSource = deps.attention ?? documentAttention();
2404
2511
  const statusStore = deps.statusSource ?? ctx.uiSession?.sessionStatus;
2405
2512
  if (statusStore === void 0) return () => {};
2406
2513
  try {
2407
2514
  localStorage.removeItem(LEGACY_STORAGE_KEY);
2408
2515
  } catch {}
2409
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
+ };
2410
2539
  const paint = () => {
2411
- 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;
2412
2543
  if (painted === count) return;
2413
2544
  painted = count;
2414
- (count > 0 ? badge.set(count) : badge.clear()).catch(() => {});
2545
+ paintHost(count);
2546
+ if (badge !== void 0) (count > 0 ? badge.set(count) : badge.clear()).catch(() => {});
2415
2547
  };
2416
2548
  const stopStatus = statusStore.subscribe(paint);
2417
2549
  const stopList = ctx.sessions.list.subscribe(paint);
2550
+ const stopAttention = attentionSource?.subscribe(() => {
2551
+ if (attentionSource.focused()) attention.clear();
2552
+ paint();
2553
+ });
2418
2554
  paint();
2419
2555
  return () => {
2420
2556
  stopStatus();
2421
2557
  stopList();
2558
+ stopAttention?.();
2422
2559
  };
2423
2560
  }
2424
2561
  // src/client/locales.ts
@@ -3022,14 +3159,31 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3022
3159
  return badge;
3023
3160
  }
3024
3161
  /**
3025
- * Remove every badge this plugin inserted, restoring the text it split.
3162
+ * Remove the badges one owner mounted, leaving every other owner's in place.
3163
+ *
3164
+ * Two composers can be on screen at once — the main conversation and a side
3165
+ * chat tab — and each mounts markers for the passages it quotes. A global sweep
3166
+ * from one of them deletes the other's markers, the other re-mounts them, and
3167
+ * the two take turns writing the same subtree on every mutation. That is a
3168
+ * self-feeding loop with no end: it never yields, so the window stops painting
3169
+ * and every click is lost. Teardown is therefore keyed to the ids this owner
3170
+ * actually put on screen.
3171
+ * @param ids - annotation ids whose badges belong to the caller.
3172
+ * @returns how many badges were removed.
3026
3173
  */
3027
- function removeBadges() {
3174
+ function unmountBadges(ids) {
3175
+ const owned = new Set(ids);
3176
+ if (owned.size === 0) return 0;
3177
+ let removed = 0;
3028
3178
  for (const anchor of [...document.querySelectorAll("[data-dsh-enhance-badge-anchor]")]) {
3179
+ const id = anchor.querySelector(`[${BADGE_ATTRIBUTE}]`)?.getAttribute(BADGE_ATTRIBUTE);
3180
+ if (id === null || id === void 0 || !owned.has(id)) continue;
3029
3181
  const parent = anchor.parentNode;
3030
3182
  anchor.remove();
3031
3183
  parent?.normalize();
3184
+ removed += 1;
3032
3185
  }
3186
+ return removed;
3033
3187
  }
3034
3188
  // src/client/SelectionToolbar.tsx
3035
3189
  /**
@@ -4015,33 +4169,60 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4015
4169
  if (target !== void 0) highlightAnnotation(target);
4016
4170
  setEditingId(id);
4017
4171
  };
4172
+ /**
4173
+ * Badges this seat put on screen.
4174
+ *
4175
+ * A second composer can be mounted at the same time — `Ask in side chat`
4176
+ * opens a tab whose seat marks the same transcript — and a teardown that
4177
+ * swept every badge in the document would delete the other seat's markers,
4178
+ * which the other seat then re-mounted, which fired this seat's observer
4179
+ * again. Two owners taking turns writing one subtree never yields: the page
4180
+ * stops painting entirely, which is what a frozen window looks like.
4181
+ */
4182
+ const owned = /* @__PURE__ */ new Set();
4018
4183
  /** Repaint marks and badges; idempotent, so calling it twice costs nothing. */
4019
4184
  const repaint = () => {
4020
4185
  const pinned = annotationsVisibleIn(sessionId);
4021
4186
  paintMarks(sessionId, pinned);
4022
4187
  mountBadges(pinned, onClick);
4188
+ owned.clear();
4189
+ for (const annotation of pinned) owned.add(annotation.id);
4023
4190
  };
4024
4191
  repaint();
4025
4192
  const scope = root.current?.ownerDocument;
4026
4193
  if (scope === null || scope === void 0) return () => {
4027
4194
  clearMarks(sessionId);
4028
4195
  };
4029
- let queued = false;
4030
4196
  const isOwnMutation = (record) => {
4031
4197
  const touch = [...record.addedNodes, ...record.removedNodes];
4032
- return touch.length > 0 && touch.every((node) => {
4033
- if (!(node instanceof Element)) return false;
4034
- return node.matches("[data-dsh-enhance-badge], [data-dsh-enhance-badge-anchor]") || node.querySelector("[data-dsh-enhance-badge]") !== null;
4198
+ if (touch.length === 0) return false;
4199
+ const holdsBadge = (record.target instanceof Element ? record.target : record.target.parentElement)?.querySelector("[data-dsh-enhance-badge-anchor]") != null;
4200
+ return touch.every((node) => {
4201
+ if (node instanceof Element) return node.matches("[data-dsh-enhance-badge], [data-dsh-enhance-badge-anchor]") || node.querySelector("[data-dsh-enhance-badge]") !== null;
4202
+ return holdsBadge && node.nodeType === Node.TEXT_NODE;
4035
4203
  });
4036
4204
  };
4037
- const observer = new MutationObserver((records) => {
4038
- if (records.every(isOwnMutation)) return;
4039
- if (queued) return;
4040
- queued = true;
4041
- queueMicrotask(() => {
4042
- queued = false;
4205
+ const MAX_REPAINTS_PER_SECOND = 30;
4206
+ let frame = 0;
4207
+ let windowStart = 0;
4208
+ let windowCount = 0;
4209
+ const schedule = () => {
4210
+ if (frame !== 0) return;
4211
+ frame = requestAnimationFrame(() => {
4212
+ frame = 0;
4213
+ const now = performance.now();
4214
+ if (now - windowStart > 1e3) {
4215
+ windowStart = now;
4216
+ windowCount = 0;
4217
+ }
4218
+ windowCount += 1;
4219
+ if (windowCount > MAX_REPAINTS_PER_SECOND) return;
4043
4220
  repaint();
4044
4221
  });
4222
+ };
4223
+ const observer = new MutationObserver((records) => {
4224
+ if (records.every(isOwnMutation)) return;
4225
+ schedule();
4045
4226
  });
4046
4227
  observer.observe(scope, {
4047
4228
  childList: true,
@@ -4049,7 +4230,8 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4049
4230
  });
4050
4231
  return () => {
4051
4232
  observer.disconnect();
4052
- removeBadges();
4233
+ if (frame !== 0) cancelAnimationFrame(frame);
4234
+ unmountBadges(owned);
4053
4235
  clearHighlight();
4054
4236
  clearMarks(sessionId);
4055
4237
  };
@@ -4333,6 +4515,11 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4333
4515
  // src/client/index.tsx
4334
4516
  /** The one side conversation this page opens; later requests add to it. */
4335
4517
  let openSideChat;
4518
+ /**
4519
+ * The open that is in flight, so a second click joins it instead of creating a
4520
+ * second conversation (a created-but-unused session is never reclaimed).
4521
+ */
4522
+ let openingSideChat;
4336
4523
  /** Required services: slots, dictionaries, session status, the Workspace list, and the right Sidebar. */
4337
4524
  const inject = [
4338
4525
  "slots",
@@ -4383,12 +4570,24 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4383
4570
  * @returns completion once the tab carries the conversation.
4384
4571
  */
4385
4572
  const askInSideChat = async (passage, note = "", sourceSessionId, anchor) => {
4386
- const workspaceId = ctx.workspaces.list.getSnapshot().items[0]?.workspaceId;
4387
- if (workspaceId === void 0) throw new Error(t("error.noWorkspace"));
4388
- const sessionId = sideChatSession() ?? await createSideChatSession(ctx, workspaceId);
4389
- rememberTitle(sessionId, firstLine(passage));
4390
- addAnnotation(sessionId, passage, note, anchor, sourceSessionId);
4391
- ctx.sidebarRight.openResource(sideChatAddress(sessionId));
4573
+ if (openingSideChat !== void 0) {
4574
+ await openingSideChat;
4575
+ return;
4576
+ }
4577
+ const work = (async () => {
4578
+ const workspaceId = workspaceFor(ctx, sourceSessionId);
4579
+ if (workspaceId === void 0) throw new Error(t("error.noWorkspace"));
4580
+ const sessionId = sideChatSession() ?? await createSideChatSession(ctx, workspaceId);
4581
+ rememberTitle(sessionId, firstLine(passage));
4582
+ addAnnotation(sessionId, passage, note, anchor, sourceSessionId);
4583
+ ctx.sidebarRight.openResource(sideChatAddress(sessionId));
4584
+ })();
4585
+ openingSideChat = work;
4586
+ try {
4587
+ await work;
4588
+ } finally {
4589
+ if (openingSideChat === work) openingSideChat = void 0;
4590
+ }
4392
4591
  };
4393
4592
  ctx.effect(() => ctx.slots.inject("conversation.input.overlay", () => ctx.slots.register({
4394
4593
  name: "conversation.input.overlay",
@@ -4399,6 +4598,25 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4399
4598
  }, AnnotationSeat)), "dsh-enhance: annotation seat");
4400
4599
  }
4401
4600
  /**
4601
+ * The workspace a side conversation for one passage belongs in.
4602
+ *
4603
+ * A Workspace is the container a session is listed under; the reader asked from
4604
+ * a conversation, so that conversation's own workspace is the answer. Falling
4605
+ * back to the first workspace keeps the gesture working before the list has
4606
+ * loaded.
4607
+ * @param ctx - client root carrying the Workspace list.
4608
+ * @param sourceSessionId - conversation the passage was selected in.
4609
+ * @returns the workspace to create the side conversation in.
4610
+ */
4611
+ function workspaceFor(ctx, sourceSessionId) {
4612
+ const items = ctx.workspaces.list.getSnapshot().items;
4613
+ if (sourceSessionId !== void 0) {
4614
+ const owner = items.find((item) => item.sessionIds?.includes(sourceSessionId) === true);
4615
+ if (owner !== void 0) return owner.workspaceId;
4616
+ }
4617
+ return items[0]?.workspaceId;
4618
+ }
4619
+ /**
4402
4620
  * The side conversation this page keeps open, once one exists.
4403
4621
  * @returns the remembered session id, or undefined before the first request.
4404
4622
  */
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.1",
3
+ "version": "0.3.3",
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",