dsh-enhance 0.3.2 → 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.2.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.2.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
@@ -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
@@ -3029,14 +3159,31 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
3029
3159
  return badge;
3030
3160
  }
3031
3161
  /**
3032
- * 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.
3033
3173
  */
3034
- function removeBadges() {
3174
+ function unmountBadges(ids) {
3175
+ const owned = new Set(ids);
3176
+ if (owned.size === 0) return 0;
3177
+ let removed = 0;
3035
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;
3036
3181
  const parent = anchor.parentNode;
3037
3182
  anchor.remove();
3038
3183
  parent?.normalize();
3184
+ removed += 1;
3039
3185
  }
3186
+ return removed;
3040
3187
  }
3041
3188
  // src/client/SelectionToolbar.tsx
3042
3189
  /**
@@ -4022,33 +4169,60 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4022
4169
  if (target !== void 0) highlightAnnotation(target);
4023
4170
  setEditingId(id);
4024
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();
4025
4183
  /** Repaint marks and badges; idempotent, so calling it twice costs nothing. */
4026
4184
  const repaint = () => {
4027
4185
  const pinned = annotationsVisibleIn(sessionId);
4028
4186
  paintMarks(sessionId, pinned);
4029
4187
  mountBadges(pinned, onClick);
4188
+ owned.clear();
4189
+ for (const annotation of pinned) owned.add(annotation.id);
4030
4190
  };
4031
4191
  repaint();
4032
4192
  const scope = root.current?.ownerDocument;
4033
4193
  if (scope === null || scope === void 0) return () => {
4034
4194
  clearMarks(sessionId);
4035
4195
  };
4036
- let queued = false;
4037
4196
  const isOwnMutation = (record) => {
4038
4197
  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;
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;
4042
4203
  });
4043
4204
  };
4044
- const observer = new MutationObserver((records) => {
4045
- if (records.every(isOwnMutation)) return;
4046
- if (queued) return;
4047
- queued = true;
4048
- queueMicrotask(() => {
4049
- 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;
4050
4220
  repaint();
4051
4221
  });
4222
+ };
4223
+ const observer = new MutationObserver((records) => {
4224
+ if (records.every(isOwnMutation)) return;
4225
+ schedule();
4052
4226
  });
4053
4227
  observer.observe(scope, {
4054
4228
  childList: true,
@@ -4056,7 +4230,8 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4056
4230
  });
4057
4231
  return () => {
4058
4232
  observer.disconnect();
4059
- removeBadges();
4233
+ if (frame !== 0) cancelAnimationFrame(frame);
4234
+ unmountBadges(owned);
4060
4235
  clearHighlight();
4061
4236
  clearMarks(sessionId);
4062
4237
  };
@@ -4340,6 +4515,11 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4340
4515
  // src/client/index.tsx
4341
4516
  /** The one side conversation this page opens; later requests add to it. */
4342
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;
4343
4523
  /** Required services: slots, dictionaries, session status, the Workspace list, and the right Sidebar. */
4344
4524
  const inject = [
4345
4525
  "slots",
@@ -4390,12 +4570,24 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4390
4570
  * @returns completion once the tab carries the conversation.
4391
4571
  */
4392
4572
  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));
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
+ }
4399
4591
  };
4400
4592
  ctx.effect(() => ctx.slots.inject("conversation.input.overlay", () => ctx.slots.register({
4401
4593
  name: "conversation.input.overlay",
@@ -4406,6 +4598,25 @@ body[data-ds-dark-theme] .dsh-enhance-edit {
4406
4598
  }, AnnotationSeat)), "dsh-enhance: annotation seat");
4407
4599
  }
4408
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
+ /**
4409
4620
  * The side conversation this page keeps open, once one exists.
4410
4621
  * @returns the remembered session id, or undefined before the first request.
4411
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.2",
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",