dsh-bark-push 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1 — 2026-11-17
4
+
5
+ - 静音入口重排,避免与其它通知插件争抢会话行尾的 hover 按钮条:
6
+ - 移除 `sidebar.workspaces.session.row.action` 的铃铛;会话静音改由 `sidebar.workspaces.session.menu.item` slot 承担(见下),行「…」菜单与右键菜单共用,不会重复。
7
+ - 新增 `sidebar.session.row.trailing` 的**不可点**小铃铛标记,仅在该会话被静音时显示,保留状态可见性。
8
+ - 新增 `conversation.session.header.utilities` 的当前会话头部铃铛,提供一键静音/取消静音。
9
+ - 会话菜单项改用 `sidebar.workspaces.session.menu.item` slot,`order: 510`:该 slot 同时渲染进行「…」菜单与右键菜单,且整体位于内置「归档会话」之前,因此稳定排在其它插件项之后、归档之前;不再使用会受其它插件 order 影响的 `contextMenus` 注入。
10
+ - 会话菜单项优先渲染宿主原语 `@deepseek-ai/dsh-client-ui-primitives` 的 `MenuItemButton`,样式/间距/hover 完全跟随宿主;仅当宿主未注入该原语时回退到本地 `bark-menuItem` 样式。
11
+ - 会话菜单项样式按宿主菜单行对齐:`bark-menuItem` 使用 flex、左对齐、`6px 10px` 内边距、16px 图标与 hover 背景;修正先前裸 `<button>` 默认居中、与其它项不一致的问题。
12
+ - 修复设置页会话列表不完整:`/state` 的 catalog 现在返回“已加载会话 ∪ 工作区 sessionIds 中的持久化会话 ∪ 已静音会话”,未加载的会话标为离线;客户端据此为每个会话建立 workspace 映射,工作区静音标记不再依赖先点一次会话静音。
13
+ - 修复客户端首次拉取 `/state` 可能失败导致静音状态/映射空白:启动后按 600ms/1.5s/3s/6s/12s 重试,直到成功。
14
+ - 修复工作区静音对“未登记在 workspace.sessionIds 但位于工作区子目录”的会话不生效:服务端在精确路径匹配失败后按最长工作区路径前缀解析。
15
+ - 工作区静音增加常驻状态提示:客户端缓存 `session → workspace` 映射,会话行尾的铃铛标记现在同时反映“会话静音”和“工作区静音”,tooltip 分别显示「推送通知已静音」/「工作区推送通知已静音」。宿主未提供工作区行装饰 slot,因此标记落在该工作区的会话行上。
16
+ - 工作区菜单项 `order` 由 900 降到 199:宿主的「在文件夹显示/复制目录/打开目录/归档工作区」是一个 order 200 的 provider 组,因此放在 199 可整体位于「归档工作区」上方(无法插进组内,宿主未提供工作区菜单 slot)。
17
+ - 测试同步更新(83 / 83 通过);已用真实 `dsh web` 验证行尾铃铛消失、行「…」菜单静音项唯一、静音后出现行尾标记。
18
+
3
19
  ## 0.2.0 — 2026-11-13
4
20
 
5
21
  - 新增「更多推送渠道」:在 Bark 之外可同时启用 Gotify、ntfy、PushDeer、Server酱、PushPlus、额外 Bark 服务器与自定义 Webhook。每条通知并行投递到 Bark 和所有已启用渠道,渠道之间互相隔离,单个渠道失败不影响其他渠道或 DSH。
@@ -11,7 +27,7 @@
11
27
  - 交互重构(遵循 DSH 插件最佳实践):管理页 iframe 无法固定底部 toast(宿主会把 iframe 撑到内容全高),改由客户端半注册官方 `shell.overlay` 框架级浮层来显示 toast——它位于顶层文档、盖在所有列之上,滚动到任何位置都可见;测试结果就近显示在触发它的卡片内,页面顶部状态改为轻量状态条。
12
28
  - 配置新增 `channels` 数组(最多 20 个),`publicConfig` 对渠道密钥脱敏;新增 `POST /api/bark-push/test-channel` 单渠道测试路由。
13
29
  - “恢复默认”保留已配置的 Device Key 与额外渠道,避免误删凭据。
14
- - 测试:77 / 77 通过(新增 `test/channels.test.js`、默认测试仅 Bark 的回归用例)。
30
+ - 测试:83 / 83 通过(新增 `test/channels.test.js`、默认测试仅 Bark 的回归用例)。
15
31
 
16
32
  ## 0.1.6 — unreleased
17
33
 
package/README.md CHANGED
@@ -331,15 +331,17 @@ curl -X POST 'https://api.day.app/push' \
331
331
 
332
332
  ### 6.1 工作区静音
333
333
 
334
- - 在左侧工作区列表右键点击工作区 → **静音 Bark 通知** / **取消静音 Bark 通知**。
335
- - 或在 Settings → Bark 推送 → **工作区** 列表中勾选。
334
+ - 在左侧工作区列表右键点击工作区 → **静音推送通知** / **取消静音推送通知**。
335
+ - 或在 Settings → 推送通知 → **工作区** 列表中勾选。
336
+ - 工作区被静音后,其下每个会话行都会显示一个**不可点的铃铛标记**(tooltip 为“工作区推送通知已静音”)。宿主没有工作区行的装饰 slot,因此标记落在该工作区的会话行上;工作区静音本来就会抑制这些会话。
336
337
  - 按稳定的 `WorkspaceId` 保存,不受路径重命名影响。
337
338
 
338
339
  ### 6.2 对话静音
339
340
 
340
- - 会话右键菜单 → **静音 Bark 通知** / **取消静音 Bark 通知**。
341
- - 或会话行尾的 🔔/🔕 按钮。
342
- - 或在 Settings → Bark 推送 → **会话** 列表中勾选,支持按标题/ID 过滤。
341
+ - 会话行尾「…」菜单或右键菜单 → **静音推送通知** / **取消静音推送通知**(不再占用行尾 hover 按钮条,避免与其它插件抢位)。
342
+ - 正在打开的会话:顶部工具区有一个铃铛,可快速静音/取消静音当前会话。
343
+ - 被静音的会话行会显示一个**不可点的小铃铛标记**,状态一眼可见。
344
+ - 或在 Settings → 推送通知 → **会话** 列表中勾选,支持按标题/ID 过滤。列表包含当前已加载的会话**以及工作区中已持久化但暂未加载的会话**(离线会话标为“离线”),不会只显示一部分。
343
345
 
344
346
  ### 6.3 优先级与持久化
345
347
 
@@ -463,7 +465,7 @@ cd dsh-bark-push
463
465
  npm test
464
466
  ```
465
467
 
466
- 当前结果:**77 / 77 通过**(Node v24,`node:test`)。
468
+ 当前结果:**83 / 83 通过**(Node v24,`node:test`)。
467
469
 
468
470
  | 验收场景 | 对应测试 |
469
471
  |---|---|
package/lib/client.js CHANGED
@@ -5,6 +5,14 @@ window.__ModuleLoader__.load({
5
5
  var exports = module.exports;
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
7
  var React = require("react");
8
+ // Host-shipped menu primitive; absent in minimal/test hosts, so fall back
9
+ // to a locally styled button.
10
+ var UI_PRIMITIVES = null;
11
+ try {
12
+ UI_PRIMITIVES = require("@deepseek-ai/dsh-client-ui-primitives") || null;
13
+ } catch (_) {
14
+ UI_PRIMITIVES = null;
15
+ }
8
16
 
9
17
  /**
10
18
  * Browser half of dsh-bark-push.
@@ -32,6 +40,7 @@ window.__ModuleLoader__.load({
32
40
  mute: "静音推送通知",
33
41
  unmute: "取消静音推送通知",
34
42
  muted: "推送通知已静音",
43
+ mutedWorkspace: "工作区推送通知已静音",
35
44
  unmuted: "推送通知已取消静音",
36
45
  settingsTitle: "推送通知",
37
46
  settingsIntro: "在下方管理推送渠道、通知规则与静音状态。",
@@ -43,6 +52,7 @@ window.__ModuleLoader__.load({
43
52
  mute: "Mute push notifications",
44
53
  unmute: "Unmute push notifications",
45
54
  muted: "Push notifications muted",
55
+ mutedWorkspace: "Workspace push notifications muted",
46
56
  unmuted: "Push notifications unmuted",
47
57
  settingsTitle: "Push notifications",
48
58
  settingsIntro: "Manage push channels, notification rules, and mute state below.",
@@ -71,6 +81,10 @@ window.__ModuleLoader__.load({
71
81
  loaded: false,
72
82
  workspaces: new Set(),
73
83
  sessions: new Set(),
84
+ /** Session id -> workspace id, so a row can reflect workspace-level mute. */
85
+ sessionWorkspace: new Map(),
86
+ /** Workspace id -> root path, used to infer a workspace from a Session cwd. */
87
+ workspacePaths: new Map(),
74
88
  listeners: new Set(),
75
89
  };
76
90
 
@@ -122,10 +136,58 @@ window.__ModuleLoader__.load({
122
136
  }
123
137
  }
124
138
 
139
+ /** Longest workspace root containing a Session cwd. */
140
+ function workspaceIdForPath(paths, cwd) {
141
+ const target = String(cwd || "").replace(/[\\/]+$/, "");
142
+ if (target.length === 0) return undefined;
143
+ let best;
144
+ let bestLength = -1;
145
+ for (const [id, path] of paths) {
146
+ const root = String(path || "").replace(/[\\/]+$/, "");
147
+ if (root.length === 0) continue;
148
+ if (target === root || target.startsWith(root + "/") || target.startsWith(root + "\\")) {
149
+ if (root.length > bestLength) {
150
+ best = id;
151
+ bestLength = root.length;
152
+ }
153
+ }
154
+ }
155
+ return best;
156
+ }
157
+
125
158
  function adopt(payload) {
126
159
  if (!payload || !payload.mute) return;
127
160
  store.workspaces = new Set(Array.isArray(payload.mute.workspaces) ? payload.mute.workspaces : []);
128
161
  store.sessions = new Set(Array.isArray(payload.mute.sessions) ? payload.mute.sessions : []);
162
+ if (payload.catalog && typeof payload.catalog === "object") {
163
+ const catalog = payload.catalog;
164
+ const paths = new Map();
165
+ for (const row of Array.isArray(catalog.workspaces) ? catalog.workspaces : []) {
166
+ if (row && typeof row.id === "string" && typeof row.path === "string" && row.path.length > 0) {
167
+ paths.set(row.id, row.path);
168
+ }
169
+ }
170
+ store.workspacePaths = paths;
171
+
172
+ const map = new Map();
173
+ if (catalog.sessionWorkspace && typeof catalog.sessionWorkspace === "object") {
174
+ for (const [sessionId, workspaceId] of Object.entries(catalog.sessionWorkspace)) {
175
+ if (typeof sessionId === "string" && typeof workspaceId === "string" && workspaceId.length > 0) {
176
+ map.set(sessionId, workspaceId);
177
+ }
178
+ }
179
+ }
180
+ for (const row of Array.isArray(catalog.sessions) ? catalog.sessions : []) {
181
+ if (!row || typeof row.id !== "string") continue;
182
+ if (typeof row.workspaceId === "string" && row.workspaceId.length > 0) {
183
+ map.set(row.id, row.workspaceId);
184
+ } else if (typeof row.cwd === "string" && row.cwd.length > 0) {
185
+ const inferred = workspaceIdForPath(paths, row.cwd);
186
+ if (inferred !== undefined) map.set(row.id, inferred);
187
+ }
188
+ }
189
+ store.sessionWorkspace = map;
190
+ }
129
191
  store.loaded = true;
130
192
  emit();
131
193
  }
@@ -181,6 +243,20 @@ window.__ModuleLoader__.load({
181
243
  return set.has(id);
182
244
  }
183
245
 
246
+ /** Effective mute for a Session row: its own mute, or its workspace's mute. */
247
+ function useSessionMuteState(sessionId) {
248
+ const [, force] = React.useReducer((value) => value + 1, 0);
249
+ React.useEffect(() => {
250
+ const listener = () => force();
251
+ store.listeners.add(listener);
252
+ return () => store.listeners.delete(listener);
253
+ }, []);
254
+ const session = store.sessions.has(sessionId);
255
+ const workspaceId = store.sessionWorkspace.get(sessionId);
256
+ const workspace = typeof workspaceId === "string" && store.workspaces.has(workspaceId);
257
+ return { session, workspace };
258
+ }
259
+
184
260
  // Bell / bell-off glyphs mirror lib/assets/bell.svg and bell-off.svg.
185
261
  // They are inlined so `currentColor` follows the host theme and no
186
262
  // authenticated image request is needed for a 24x24 icon.
@@ -263,10 +339,92 @@ window.__ModuleLoader__.load({
263
339
  );
264
340
  }
265
341
 
266
- function SessionMuteAction(props) {
342
+ function sessionCopy(props) {
343
+ return typeof props.t === "function" ? props.t : (key) => COPY.zh[key] || key;
344
+ }
345
+
346
+ /** Inject the menu-row styles once; mirrors the host's own menu item look. */
347
+ function ensureMenuStyles() {
348
+ try {
349
+ if (typeof document === "undefined" || !document.head) return;
350
+ if (document.getElementById("dsh-bark-push-menu-style")) return;
351
+ const style = document.createElement("style");
352
+ style.id = "dsh-bark-push-menu-style";
353
+ style.textContent =
354
+ ".bark-menuItem{display:flex;align-items:center;gap:8px;width:100%;box-sizing:border-box;" +
355
+ "padding:6px 10px;border:0;border-radius:6px;background:none;" +
356
+ "color:var(--dsw-alias-label-primary,rgba(20,20,20,.9));font-family:inherit;" +
357
+ "font-size:13px;line-height:20px;text-align:left;cursor:pointer}" +
358
+ ".bark-menuItem:hover{background:var(--dsw-alias-bg-layer-2,rgba(128,128,128,.14))}" +
359
+ ".bark-menuIcon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;flex:none}" +
360
+ ".bark-menuLabel{flex:1;min-width:0;text-align:left}";
361
+ document.head.append(style);
362
+ } catch (_) {
363
+ // Styling is cosmetic; the menu entry still works without it.
364
+ }
365
+ }
366
+
367
+ /** Session-row "..." / right-click menu entry that toggles this mute. */
368
+ function SessionMuteMenuItem(props) {
369
+ const translate = sessionCopy(props);
370
+ const muted = useMuted("session", props.sessionId);
371
+ const label = muted ? translate("unmute") : translate("mute");
372
+ const menu = typeof props.useMenuOpenState === "function" ? props.useMenuOpenState() : [false, () => {}];
373
+ const setMenuOpen = menu[1];
374
+ const select = (event) => {
375
+ if (event && typeof event.preventDefault === "function") event.preventDefault();
376
+ setMenuOpen(false);
377
+ toggle("session", props.sessionId).catch(() => {});
378
+ };
379
+ const icon = React.createElement(BellGlyph, { off: muted, size: 16 });
380
+ const MenuItemButton = UI_PRIMITIVES && typeof UI_PRIMITIVES.MenuItemButton === "function"
381
+ ? UI_PRIMITIVES.MenuItemButton
382
+ : null;
383
+ if (MenuItemButton) {
384
+ return React.createElement(
385
+ MenuItemButton,
386
+ { icon, onSelect: select, "data-bark-muted": muted ? "1" : "0" },
387
+ label,
388
+ );
389
+ }
390
+ return React.createElement(
391
+ "button",
392
+ {
393
+ type: "button",
394
+ role: "menuitem",
395
+ className: "bark-menuItem",
396
+ "data-bark-muted": muted ? "1" : "0",
397
+ onClick: select,
398
+ },
399
+ React.createElement("span", { className: "bark-menuIcon" }, icon),
400
+ React.createElement("span", { className: "bark-menuLabel" }, label),
401
+ );
402
+ }
403
+
404
+ /** Non-interactive muted mark in the Session row, only while muted. */
405
+ function SessionMutedMark(props) {
406
+ const translate = sessionCopy(props);
407
+ const state = useSessionMuteState(props.sessionId);
408
+ if (!state.session && !state.workspace) return null;
409
+ const label = state.workspace ? translate("mutedWorkspace") : translate("muted");
410
+ return React.createElement(
411
+ "span",
412
+ {
413
+ role: "img",
414
+ title: label,
415
+ "aria-label": label,
416
+ "data-bark-muted-mark": state.workspace ? "workspace" : "session",
417
+ style: { display: "inline-flex", alignItems: "center", opacity: 0.72 },
418
+ },
419
+ React.createElement(BellGlyph, { off: true, size: 12 }),
420
+ );
421
+ }
422
+
423
+ /** Current Session's header bell toggle (quick access, one icon only). */
424
+ function SessionHeaderMute(props) {
425
+ const translate = sessionCopy(props);
267
426
  const muted = useMuted("session", props.sessionId);
268
427
  const [busy, setBusy] = React.useState(false);
269
- const translate = typeof props.t === "function" ? props.t : (key) => COPY.zh[key] || key;
270
428
  const label = muted ? translate("unmute") : translate("mute");
271
429
  return React.createElement(
272
430
  "button",
@@ -279,22 +437,20 @@ window.__ModuleLoader__.load({
279
437
  style: {
280
438
  background: "transparent",
281
439
  border: 0,
282
- padding: "0 2px",
440
+ padding: "0 6px",
283
441
  cursor: "pointer",
284
- fontSize: "12px",
285
- lineHeight: "1",
286
- opacity: muted ? 0.95 : 0.5,
442
+ display: "inline-flex",
443
+ alignItems: "center",
444
+ opacity: muted ? 0.95 : 0.6,
287
445
  },
288
- onClick: (event) => {
289
- event.preventDefault();
290
- event.stopPropagation();
446
+ onClick: () => {
291
447
  setBusy(true);
292
448
  toggle("session", props.sessionId)
293
449
  .catch(() => {})
294
450
  .finally(() => setBusy(false));
295
451
  },
296
452
  },
297
- React.createElement(BellGlyph, { off: muted, size: 14 }),
453
+ React.createElement(BellGlyph, { off: muted, size: 16 }),
298
454
  );
299
455
  }
300
456
 
@@ -400,6 +556,7 @@ window.__ModuleLoader__.load({
400
556
  function apply(ctx) {
401
557
  propsContext = ctx;
402
558
  const t = bindCopy(ctx);
559
+ ensureMenuStyles();
403
560
 
404
561
  let disposeLocale;
405
562
  try {
@@ -410,6 +567,19 @@ window.__ModuleLoader__.load({
410
567
  }
411
568
 
412
569
  refresh();
570
+ // The first state fetch can race the connection/route mount. Retry soon
571
+ // until one succeeds, so mute state and the session->workspace map do not
572
+ // stay empty for a whole 60s polling period.
573
+ try {
574
+ const bootTimers = [];
575
+ const retry = () => { if (!store.loaded) refresh(); };
576
+ for (const delay of [600, 1500, 3000, 6000, 12000]) bootTimers.push(window.setTimeout(retry, delay));
577
+ ctx.effect(() => () => {
578
+ for (const id of bootTimers) window.clearTimeout(id);
579
+ }, "bark-push: initial refresh retry");
580
+ } catch (_) {
581
+ // No timers in a non-DOM harness: the normal refresh still runs later.
582
+ }
413
583
  try {
414
584
  ctx.effect(() => {
415
585
  const timer = window.setInterval(refresh, 60_000);
@@ -497,22 +667,45 @@ window.__ModuleLoader__.load({
497
667
  // Older Settings shells render their fallback nav glyph.
498
668
  }
499
669
 
500
- // Session-row bell, shown only when the host declares the list slot.
670
+ // Per-Session mute is contributed through the existing contextMenus
671
+ // session entry, which the host renders in both the right-click menu and
672
+ // the row's "..." menu. The crowded row hover strip is no longer used.
673
+ // A small non-interactive mark keeps the muted state glanceable without
674
+ // adding another clickable icon to the row.
501
675
  try {
502
- ctx.slots.inject("sidebar.workspaces.session.row.action", () =>
676
+ ctx.slots.inject("sidebar.session.row.trailing", () =>
503
677
  ctx.slots.register(
504
678
  {
505
- name: "sidebar.workspaces.session.row.action",
506
- id: "bark-push-mute",
507
- order: 30,
679
+ name: "sidebar.session.row.trailing",
680
+ id: "bark-push.muted-mark",
681
+ order: 500,
508
682
  locale: NS,
509
683
  inject: () => ({ t }),
510
684
  },
511
- SessionMuteAction,
685
+ SessionMutedMark,
512
686
  ),
513
687
  );
514
688
  } catch (_) {
515
- // Older hosts may not declare the row action slot.
689
+ // Older hosts may not declare the row trailing slot.
690
+ }
691
+
692
+ // Quick toggle for the Session that is currently open, in the header's
693
+ // right-aligned utilities. Session-scoped inject supplies the id.
694
+ try {
695
+ ctx.slots.inject("conversation.session.header.utilities", () =>
696
+ ctx.slots.register(
697
+ {
698
+ name: "conversation.session.header.utilities",
699
+ id: "bark-push.mute",
700
+ order: 10,
701
+ locale: NS,
702
+ inject: (sessionId) => ({ sessionId, t }),
703
+ },
704
+ SessionHeaderMute,
705
+ ),
706
+ );
707
+ } catch (_) {
708
+ // Older hosts may not declare the header utilities slot.
516
709
  }
517
710
 
518
711
  // Context-menu icons use the keyed contextMenu.icon slot. Register both
@@ -536,41 +729,39 @@ window.__ModuleLoader__.load({
536
729
  // Hosts without the keyed icon slot render text-only menu rows.
537
730
  }
538
731
 
539
- // Native context-menu entries for Session and workspace mute. The
540
- // service may activate after this plugin, so wait for it through
541
- // ctx.inject() instead of reading ctx.contextMenus at apply time.
732
+ // Session mute is a React menu row in the legacy slot the host renders
733
+ // in BOTH the row "..." menu and the right-click menu, together before
734
+ // the built-in Archive row. Using this slot instead of contextMenus
735
+ // keeps the position deterministic.
736
+ try {
737
+ ctx.slots.inject("sidebar.workspaces.session.menu.item", () =>
738
+ ctx.slots.register(
739
+ {
740
+ name: "sidebar.workspaces.session.menu.item",
741
+ id: "bark-push.mute",
742
+ order: 510,
743
+ locale: NS,
744
+ inject: () => ({ t }),
745
+ },
746
+ SessionMuteMenuItem,
747
+ ),
748
+ );
749
+ } catch (_) {
750
+ // Older hosts may not declare the row menu slot.
751
+ }
752
+
753
+ // Workspace mute stays in the context menu. The host renders the
754
+ // reveal/copy/open/archive workspace actions as one provider group at
755
+ // order 200, so "above archive" means sitting just before that group;
756
+ // order 199 is the closest slot available without a workspace menu slot.
542
757
  try {
543
758
  ctx.inject(["contextMenus"], (scope) => {
544
- scope.effect(
545
- () =>
546
- scope.contextMenus.register({
547
- id: "bark-push.session",
548
- target: "session",
549
- order: 900,
550
- resolve: (target) => {
551
- const id = target && target.sessionId;
552
- if (!id) return [];
553
- const muted = store.sessions.has(id);
554
- return [
555
- {
556
- id: "bark-mute",
557
- label: muted ? t("unmute") : t("mute"),
558
- icon: { key: muted ? "bark-push.bell-off" : "bark-push.bell" },
559
- run: () => {
560
- toggle("session", id).catch(() => {});
561
- },
562
- },
563
- ];
564
- },
565
- }),
566
- "bark-push: session mute menu",
567
- );
568
759
  scope.effect(
569
760
  () =>
570
761
  scope.contextMenus.register({
571
762
  id: "bark-push.workspace",
572
763
  target: "workspace",
573
- order: 900,
764
+ order: 199,
574
765
  resolve: (target) => {
575
766
  const id = target && target.workspaceId;
576
767
  if (!id) return [];
package/lib/http.js CHANGED
@@ -116,19 +116,26 @@ function buildCatalog(ctx, snapshot) {
116
116
  const mutedWorkspaces = new Set(snapshot.mutedWorkspaces);
117
117
  const mutedSessions = new Set(snapshot.mutedSessions);
118
118
  const workspaces = [];
119
+ /** Session id -> workspace id for every Session the registry knows. */
119
120
  const workspaceBySession = new Map();
121
+ /** Workspace id -> root path, used as a fallback row detail. */
122
+ const workspacePathById = new Map();
120
123
  try {
121
124
  const registry = serviceOf(ctx, 'workspaceRegistry');
122
125
  const list = typeof registry?.list === 'function' ? registry.list() : [];
123
126
  for (const workspace of list) {
124
127
  const id = String(workspace.id);
128
+ const path = typeof workspace.path === 'string' ? workspace.path : '';
125
129
  workspaces.push({
126
130
  id,
127
131
  title: workspace.title,
128
- path: workspace.path,
132
+ path,
129
133
  muted: mutedWorkspaces.has(id),
130
134
  });
131
- for (const sessionId of workspace.sessionIds ?? []) workspaceBySession.set(String(sessionId), id);
135
+ workspacePathById.set(id, path);
136
+ for (const sessionId of Array.isArray(workspace.sessionIds) ? workspace.sessionIds : []) {
137
+ workspaceBySession.set(String(sessionId), id);
138
+ }
132
139
  }
133
140
  } catch {
134
141
  // A missing or broken registry only means the page shows no projects.
@@ -136,45 +143,65 @@ function buildCatalog(ctx, snapshot) {
136
143
 
137
144
  const sessions = [];
138
145
  const seen = new Set();
146
+ const liveRows = [];
139
147
  try {
140
148
  const sessionsService = serviceOf(ctx, 'sessions');
141
149
  const live = typeof sessionsService?.list === 'function' ? sessionsService.list() : [];
142
- const rows = live
143
- .map((session) => {
144
- const id = String(session.header?.id ?? session.id ?? '');
145
- let title = '';
146
- try {
147
- title = serviceOf(ctx, 'sessionTitle')?.get?.(session)?.title ?? '';
148
- } catch {
149
- title = '';
150
- }
151
- return {
152
- id,
153
- title: typeof title === 'string' ? title : '',
154
- cwd: typeof session.header?.cwd === 'string' ? session.header.cwd : '',
155
- workspaceId: workspaceBySession.get(id) ?? null,
156
- origin: session.header?.origin ?? null,
157
- createdAt: Number.isFinite(session.header?.createdAt) ? session.header.createdAt : 0,
158
- muted: mutedSessions.has(id),
159
- offline: false,
160
- };
161
- })
162
- .filter((row) => row.id.length > 0)
163
- .sort((left, right) => right.createdAt - left.createdAt)
164
- .slice(0, 300);
165
- for (const row of rows) {
166
- sessions.push(row);
167
- seen.add(row.id);
150
+ for (const session of live) {
151
+ const id = String(session.header?.id ?? session.id ?? '');
152
+ if (id.length === 0) continue;
153
+ let title = '';
154
+ try {
155
+ title = serviceOf(ctx, 'sessionTitle')?.get?.(session)?.title ?? '';
156
+ } catch {
157
+ title = '';
158
+ }
159
+ liveRows.push({
160
+ id,
161
+ title: typeof title === 'string' ? title : '',
162
+ cwd: typeof session.header?.cwd === 'string' ? session.header.cwd : '',
163
+ workspaceId: workspaceBySession.get(id) ?? null,
164
+ origin: session.header?.origin ?? null,
165
+ createdAt: Number.isFinite(session.header?.createdAt) ? session.header.createdAt : 0,
166
+ muted: mutedSessions.has(id),
167
+ offline: false,
168
+ });
168
169
  }
169
170
  } catch {
170
171
  // Live Session enumeration is optional.
171
172
  }
173
+ liveRows.sort((left, right) => right.createdAt - left.createdAt);
174
+ for (const row of liveRows.slice(0, 300)) {
175
+ sessions.push(row);
176
+ seen.add(row.id);
177
+ }
178
+
179
+ // Persisted Sessions that are not loaded right now still belong to a
180
+ // workspace. Include them so the mute list is complete and the client can
181
+ // map every row to its workspace.
182
+ for (const [sessionId, workspaceId] of workspaceBySession) {
183
+ if (seen.has(sessionId)) continue;
184
+ sessions.push({
185
+ id: sessionId,
186
+ title: '',
187
+ cwd: workspacePathById.get(workspaceId) ?? '',
188
+ workspaceId,
189
+ origin: null,
190
+ createdAt: 0,
191
+ muted: mutedSessions.has(sessionId),
192
+ offline: true,
193
+ });
194
+ seen.add(sessionId);
195
+ if (sessions.length >= 500) break;
196
+ }
172
197
 
173
198
  for (const id of mutedSessions) {
174
199
  if (seen.has(id)) continue;
175
- sessions.push({ id, title: '', cwd: '', workspaceId: null, origin: null, createdAt: 0, muted: true, offline: true });
200
+ sessions.push({ id, title: '', cwd: '', workspaceId: workspaceBySession.get(id) ?? null, origin: null, createdAt: 0, muted: true, offline: true });
201
+ seen.add(id);
202
+ if (sessions.length >= 500) break;
176
203
  }
177
- return { workspaces, sessions };
204
+ return { workspaces, sessions, sessionWorkspace: Object.fromEntries(workspaceBySession) };
178
205
  }
179
206
 
180
207
  /**
package/lib/notifier.js CHANGED
@@ -107,17 +107,19 @@ export class Notifier {
107
107
  if (cached !== undefined && now - cached.at < 60_000) return cached.key;
108
108
  }
109
109
  const registry = optionalService(this.ctx, 'workspaceRegistry');
110
- let key;
110
+ let list = [];
111
111
  try {
112
- const list = typeof registry?.list === 'function' ? registry.list() : [];
113
- for (const workspace of list) {
114
- if (Array.isArray(workspace?.sessionIds) && workspace.sessionIds.includes(sessionId)) {
115
- key = String(workspace.id);
116
- break;
117
- }
118
- }
112
+ list = typeof registry?.list === 'function' ? registry.list() : [];
119
113
  } catch {
120
- // A broken registry is not a reason to stop notifying.
114
+ list = [];
115
+ }
116
+ let key;
117
+ for (const workspace of list) {
118
+ const ids = Array.isArray(workspace?.sessionIds) ? workspace.sessionIds.map(String) : [];
119
+ if (ids.includes(sessionId)) {
120
+ key = String(workspace.id);
121
+ break;
122
+ }
121
123
  }
122
124
  const cwd = session?.header?.cwd;
123
125
  if (key === undefined && typeof cwd === 'string' && cwd.length > 0) {
@@ -127,6 +129,25 @@ export class Notifier {
127
129
  } catch {
128
130
  // Missing directories and unavailable registries fall through.
129
131
  }
132
+ if (key === undefined) {
133
+ // A Session created inside a workspace subdirectory may not be listed in
134
+ // that workspace's sessionIds yet. Fall back to the longest containing
135
+ // workspace path so workspace-level mute still applies.
136
+ const target = cwd.replace(/[\\/]+$/, "");
137
+ let bestId;
138
+ let bestLength = -1;
139
+ for (const workspace of list) {
140
+ const root = typeof workspace?.path === "string" ? workspace.path.replace(/[\\/]+$/, "") : "";
141
+ if (root.length === 0) continue;
142
+ if (target === root || target.startsWith(root + "/") || target.startsWith(root + "\\")) {
143
+ if (root.length > bestLength) {
144
+ bestId = String(workspace.id);
145
+ bestLength = root.length;
146
+ }
147
+ }
148
+ }
149
+ if (bestId !== undefined) key = bestId;
150
+ }
130
151
  if (key === undefined) key = `cwd:${cwd}`;
131
152
  }
132
153
  if (key !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-bark-push",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Push notifications for DeepSeek Harness: reply summaries, approval requests, and user questions via Bark plus Gotify, ntfy, PushDeer, Server酱, PushPlus, extra Bark servers, and generic webhooks, with per-workspace and per-session mute.",
5
5
  "license": "MIT",
6
6
  "author": "Diana <1072486605@qq.com>",