dsh-plugin-notify-sounds 1.8.0 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -95,7 +95,7 @@ dsh plugin --profile <your profile> add github:BillCx330/dsh-plugin-notify-sound
95
95
  **Release archive** — download the `.tgz` from [Releases](https://github.com/BillCx330/dsh-plugin-notify-sounds/releases) and install it by its **path on disk**:
96
96
 
97
97
  ```sh
98
- dsh plugin --profile <your profile> add ./dsh-plugin-notify-sounds-1.8.0.tgz
98
+ dsh plugin --profile <your profile> add ./dsh-plugin-notify-sounds-1.8.4.tgz
99
99
  ```
100
100
 
101
101
  (`dsh plugin add` hands its argument straight to the package manager, so it takes a local file path — a download URL will not work.)
@@ -139,6 +139,10 @@ For anyone hacking on the code (exact details live in the source comments):
139
139
 
140
140
  ## 📜 Changelog
141
141
 
142
+ - **v1.8.4** (2026-10-20) **A click always finds the window.** A trace of a real click showed the native raise giving up with "no window found" while the window existed: a hidden or repainting window can transiently answer with an empty title, and the search had nothing else to match on. The window search now also matches the process that owns the window (the Desktop shell is this Host's parent), and the foreground request is retried three times before the deep-link fallback is paid for.
143
+ - **v1.8.3** (2026-10-20) **Click-to-return works when the window is closed to the tray.** The Win32 raise searched only *visible* windows, so a DSH window hidden to the tray was never found and the click fell back to the slow deep-link route — which reads as "clicked the notification, nothing happened". The search now also remembers an invisible window whose title matches, and the raise shows it (`SW_SHOW`) before restoring and focusing it; the deep link stays as the last resort.
144
+ - **v1.8.2** (2026-10-20) **Actually fixes goal-mode alerting.** The 1.8.1 host route read `stateOf(session, "goal")` but took `current.phase`, while the projection value nests the goal: `current.goal.phase`. Every read therefore came back empty and every round chimed. The route now reads the nested field (with a fallback for a flattened shape), and a Host-side debug trace confirmed `current.goal.phase` is `active` on intermediate rounds and `complete` on the final one.
145
+ - **v1.8.1** (2026-10-20) **Fixes goal-mode alerting.** The 1.8.0 switch read the phase from the browser's own session projection, which only carries sessions that page has opened — for a goal in a session it never opened the read came back empty, which the code treated as "no goal", so every round chimed again. The browser half now asks the Host's new read-only `/notify-sounds/goal` route, whose projection store is authoritative, and re-checks it while the goal is still `active` (the single chime lands when the goal completes, pauses or blocks; a session that starts running again stays silent). A Host that does not answer the route keeps the old behaviour.
142
146
  - **v1.8.0** (2026-10-20) **The plugin stops installing itself; the package manager owns upgrades.** Writing files in place never updated the profile's lockfile, so the next plugin install — or a market upgrade — silently restored the version pnpm had recorded: a 1.7.0 install could roll back to 1.6.9 with no warning. DSH 0.2.1 makes a durable self-install impossible from inside a plugin (the manager refuses a package that is already declared, and its remove-then-install step unloads the very code that would finish the install), so the self-installer is gone: the update row checks npm, reports the newer version, and points at the route that installs — Settings → Plugins (remove, then add again), the marketplace, or `dsh plugin add` on a web profile. It also compares the running version with the version the profile's lockfile would restore and **says so when they differ**, turning the silent rollback into a self-service fix. **New: goal-mode alerts wait for the goal to end** (issue #2) — a goal runs several automatic rounds and every round used to chime; the new switch **Only alert on the final goal round** stays silent on intermediate rounds and chimes once when the goal completes, pauses or blocks (ordinary sessions are unaffected; off by default). The release keeps the same seven filenames, so 1.6.9 / 1.7.0 installations still reach it through their own updater — after one reinstall through the package manager the upgrade is permanent.
143
147
  - **v1.7.0** (2026-10-16) **The update mechanism turns a corner**: one-click update is no longer limited by a fixed list of seven filenames. It now accepts any regular file inside the package directory, governed by rules instead of an inventory — path traversal, absolute paths, symlinks, non-file entries, reserved names (its own backup/temp names and its record file, `.git`, `node_modules`, `.npmrc`), paths containing `:`, names colliding only by case, and a file that differs from the entry point `package.json` declares only by case are all still refused, with the file count and the decompressed size capped (enforced while inflating). **1.7.0 and later update cleanly into a release that adds or drops any number of files**: a file a later release drops is now actually deleted, based on the `.update-manifest.json` record this updater leaves behind — **only files an update installed are ever deleted**, anything you put in that directory yourself is left alone, and installations older than the first record are never guessed at. **1.6.9 and earlier will fail** (safely — nothing is written, the installed version keeps working) if a newer release adds a file, and the README says to reinstall once. Fixed: turning auto-check off ended the daily check chain for good, even after turning it back on; clicking a notification did nothing when the window title changed between the two Win32 reads; prerelease versions compared as strings (`rc.10` looked older than `rc.9`); **two tabs — or two windows — of the same GUI each rang the sound, raised their own system notification and ran their own repeat reminder** (one page is now elected to speak, via BroadcastChannel plus a shared claim, and the others stay silent until it disappears; per-window title marks are unaffected); and custom-sound normalization now visits **every sample** (taking every 8th frame aliased against content near fs/8 and systematically underestimated the peak). A failed update now gives **stage-appropriate advice** — retry for network failures, and the repository plus the uninstall/reinstall steps when the payload itself could not be applied, naming both versions — `package.json` is written **last** (a crash mid-swap leaves the old version number over the new code, so the next check still offers the update instead of declaring success), and the archive's manifest is verified to be this package at the version the registry named. The custom-sound row moved to sit **directly under the three trigger sounds** it is used by, and the smaller fixes on top: the cooldown table is a real LRU rather than FIFO (the session that fired most often was evicted first), one session-list snapshot per pass instead of per session, the macOS Desktop's window-title switch is now disabled rather than merely re-described, the full-width punctuation that leaked into the English update message is gone, and the README's release-archive instructions now give a command that actually works.
144
148
  - **v1.6.9** (2026-10-12) Fixes a README filename compatibility issue in v1.6.8: reverted to `README.md` (English) + `README.zh.md` (Chinese) so the update whitelist in every prior version can recognise them. A new filename would be refused by old users' updates — the whitelist is one-directional because the update runs old code.
package/README.zh.md CHANGED
@@ -95,7 +95,7 @@ dsh plugin --profile <你的 profile> add github:BillCx330/dsh-plugin-notify-sou
95
95
  **Release 压缩包** —— 从 [Releases](https://github.com/BillCx330/dsh-plugin-notify-sounds/releases) 下载 `.tgz`,用它**在磁盘上的路径**安装:
96
96
 
97
97
  ```sh
98
- dsh plugin --profile <你的 profile> add ./dsh-plugin-notify-sounds-1.8.0.tgz
98
+ dsh plugin --profile <你的 profile> add ./dsh-plugin-notify-sounds-1.8.4.tgz
99
99
  ```
100
100
 
101
101
  (`dsh plugin add` 把参数原样交给包管理器,所以要给本地文件路径,不能填下载地址。)
@@ -138,6 +138,10 @@ dsh plugin --profile <你的 profile> add ./dsh-plugin-notify-sounds
138
138
 
139
139
  ## 📜 更新记录
140
140
 
141
+ - **v1.8.4**(2026-10-20)**点击通知一定能找到窗口。** 真实点击的日志显示:窗口明明存在,原生唤窗却报 "no window found"——隐藏或正在重绘的窗口可能瞬时返回空标题,而当时的搜索只认标题。现在窗口搜索同时按「拥有窗口的进程」匹配(桌面壳是本宿主进程的父进程),前台请求连续重试三次之后才走深链兜底。
142
+ - **v1.8.3**(2026-10-20)**窗口关到托盘时,点击通知也能回到 DSH 了。** 原先的 Win32 唤窗只搜**可见**窗口,关到托盘的 DSH 窗口永远找不到,只能退到很慢的深链兜底——表现就是「点了通知没反应」。现在会记住标题匹配的不可见窗口,并在置前之前先 `SW_SHOW` 让它显示出来;深链仍作为最后兜底。
143
+ - **v1.8.2**(2026-10-20)**真正修好目标模式的提醒。** 1.8.1 的宿主路由读了 `stateOf(session, "goal")`,却取 `current.phase`,而投影值把 goal 嵌在里面:`current.goal.phase`。于是每次读取都为空、每轮照响。现在改为读嵌套字段(并保留扁平形状的兜底),宿主侧调试记录已确认:中间轮 `current.goal.phase` 是 `active`,最后一轮是 `complete`。
144
+ - **v1.8.1**(2026-10-20)**修复目标模式的提醒。** 1.8.0 的开关从浏览器自己的会话投影读 phase,而那份投影只包含这个页面打开过的会话——目标所在的会话没被打开过时读到空值,代码把它当成「没有目标」,于是每轮又照响。浏览器半现在改问宿主新增的只读路由 `/notify-sounds/goal`(宿主的投影存储才是权威的),并在目标仍为 `active` 时持续复查:目标完成、暂停或受阻时响唯一一次;会话重新开始运行则保持安静。宿主不回答该路由时退回旧行为。
141
145
  - **v1.8.0**(2026-10-20)**插件不再自己安装更新,改由包管理器负责。** 原地写文件从不会更新 profile 的 lockfile,于是下一次插件安装(或市场升级)会静默把 pnpm 记录的版本装回来:1.7.0 的安装可能一声不响退回 1.6.9。DSH 0.2.1 让插件无法从内部持久地自安装(管理器拒绝已声明的包,而它的「先移除再安装」会先卸载掉正要完成安装的代码),所以自安装器被移除:更新行只检查 npm、报告新版,并指向真正负责安装的入口——设置 → 插件(卸载后再装)、市场,或 web profile 上的 `dsh plugin add`。它还会把「运行版本」与「lockfile 会恢复的版本」做比较,**不一致时明确提示**,把静默回退变成用户可自助修复的状态。**新增:目标模式下等目标结束再提醒**(issue #2)——目标模式会自动进行多轮,原先每轮结束都会响;新开关「目标模式下只在最终轮提醒」让中间轮保持安静,只在目标完成、暂停或受阻时响一次(普通对话不受影响;默认关闭)。本版保持同样的七个文件名,1.6.9 / 1.7.0 的安装仍可通过它们自带的自更新到达 1.8.0——之后用包管理器重装一次,升级即永久生效。
142
146
  - **v1.7.0**(2026-10-16)**更新机制的转折点**:一键更新不再受「固定七个文件名」的白名单约束,改为按规则接受包目录下的任何普通文件——路径穿越、绝对路径、符号链接、非普通文件、保留名字(更新器自己的备份/临时名与记录文件、`.git`、`node_modules`、`.npmrc`)、含 `:` 的路径段,以及只有大小写不同的重名或**与 `package.json` 声明的入口只差大小写**的文件,依然一律拒绝,文件数与解压体积也都有上限(解压时即受 `gunzip` 上限约束)。**1.7.0 及以后可以正常更新到任意增减文件的新版**:某个版本去掉的文件现在会真的被删掉(依据更新器自己留下的 `.update-manifest.json` 记录,**只删它自己装过的文件**,用户放进目录里的东西一律不动;第一条记录之前的安装不做任何猜测)。**1.6.9 及更早**遇到「新增了文件」的新版会更新失败(安全失败:一个字节都不写,已装版本继续正常工作),README 里说明了重装一次的办法。修复:关掉「自动检查更新」会让每日轮询永久停摆(重新打开也不恢复);窗口标题在两次 Win32 读取之间变短时,点通知唤窗会静默失效;预发布版本号按字符串比较(`rc.10` 被误判为比 `rc.9` 旧);**同一个 GUI 开多个标签页或多个窗口时提示音、系统通知、重复提醒全部翻倍**(现在由 BroadcastChannel + 本地记录选出一个「发声页」,其余页保持安静,只在发声页消失后接管;窗口标题标记各窗口独立,不受影响);自定义音效的峰值归一化改为**逐样本**扫描(原先每 8 帧抽样会与接近 fs/8 的高频混叠、系统性低估峰值)。更新失败时给出**按阶段区分的建议**(网络类提示重试;解包/替换类给出手动重装步骤与仓库地址,并列出失败的两个版本号),写入顺序改为**最后写 `package.json`**(中途崩溃时检查仍会提示更新,用户再点一次即可自愈),并会校验归档里的清单确实是本包、确实是 registry 报的那个版本。设置里「自定义音效」移到**三种提示音之后**(它们才是会用到它的三处);`settings` 相关的小修:冷却表改为真正的 LRU(原先是 FIFO,最常触发的会话反而最先被淘汰)、会话列表每轮只取一次快照、macOS 桌面版的「窗口标题提醒」开关改为**禁用**(原先能打开但标记无处显示)、英文界面更新提示里残留的全角标点修掉、README 的 Release 安装说明改为可照做的本地路径写法。
143
147
  - **v1.6.9**(2026-10-12)修正 v1.6.8 的 README 文件名兼容性:改回 `README.md`(英文默认)+ `README.zh.md`(中文),确保旧版本更新白名单能识别。新文件名会让旧用户的更新被拒——白名单是单向兼容的,更新时跑的是旧代码。
package/lib/client.js CHANGED
@@ -1970,6 +1970,7 @@ window.__ModuleLoader__.load({
1970
1970
  ? `${t("update.available")} ${latest}`
1971
1971
  : t("update.uptodate");
1972
1972
  if (state.phase === "checking") status = t("update.checking");
1973
+ if (state.phase === "failed") status = t("update.failed");
1973
1974
  const detail = payload === undefined ? status : `${t("update.current")} ${formatVersion(payload.current)} · ${status}`;
1974
1975
  // The install belongs to the package manager now: this plugin only
1975
1976
  // checks, and every route below installs THROUGH pnpm so the
@@ -2414,89 +2415,81 @@ window.__ModuleLoader__.load({
2414
2415
  }
2415
2416
  return false;
2416
2417
  };
2418
+ /** Route the Host answers a session's goal phase on. */
2419
+ const GOAL_PHASE_PATH = "/notify-sounds/goal";
2420
+ /** How often an active goal's phase is re-read while waiting for its end. */
2421
+ const GOAL_POLL_MS = 2000;
2422
+ /** Longest a goal may stay `active` before its watcher gives up. */
2423
+ const GOAL_SETTLE_TIMEOUT_MS = 30 * 60 * 1000;
2417
2424
  /**
2418
- * The goal projection's phase for one session, when this runtime
2419
- * carries the goal packages.
2425
+ * One goal phase from the Host, or undefined when it cannot be read.
2420
2426
  *
2421
- * DSH's goal mode drives several rounds inside one session, and
2422
- * every round ends with a running→idle edge — so an unguarded
2423
- * completion chime fires once per round. The phase is the host's
2424
- * own vocabulary: `active` keeps going on its own, `complete`
2425
- * finished, and `paused`/`blocked` wait for the user.
2426
- *
2427
- * Every step is optional: a runtime without the goal projection
2428
- * simply answers `undefined`, which reads as "no goal".
2427
+ * The Host owns the durable projection; this page's own store only
2428
+ * carries sessions it has opened, and a completion edge can belong to a
2429
+ * session this page never opened. Undefined keeps the old behaviour
2430
+ * (alert) for any runtime that does not answer the route.
2429
2431
  */
2430
- const goalPhaseOf = (sessionId) => {
2432
+ const readGoalPhase = async (sessionId) => {
2431
2433
  try {
2432
- const sessions = ctx.sessions ?? ctx.uiSession?.sessions;
2433
- const store = sessions?.get?.(sessionId)?.projections;
2434
- const snapshot = store?.get?.("goal") ?? store?.faceOf?.("goal")?.getSnapshot?.();
2435
- const phase = snapshot?.goal?.phase;
2436
- return typeof phase === "string" ? phase : undefined;
2434
+ const response = await fetch(GOAL_PHASE_PATH + "?session=" + encodeURIComponent(sessionId), { method: "GET" });
2435
+ if (!response.ok) return undefined;
2436
+ const payload = await response.json();
2437
+ return typeof payload?.phase === "string" ? payload.phase : undefined;
2437
2438
  } catch {
2438
2439
  return undefined;
2439
2440
  }
2440
2441
  };
2441
- /** Whether the completion edge for a session is worth an alert now. */
2442
- const completionIsFinal = (sessionId, value) => {
2443
- if (value?.goalFinalOnly !== true) return true;
2444
- // A session with no goal, or with one that will not continue on
2445
- // its own (finished, paused, blocked), ends this edge for the
2446
- // user; one that is still `active` drives another round.
2447
- return goalPhaseOf(sessionId) !== "active";
2442
+ /** Deliver the completion alert this edge earns. */
2443
+ const alertCompletion = (sessionId) => {
2444
+ if (!pageIsWatched() && !quietNow()) unreadCompletion = true;
2445
+ notify("completion", undefined, sessionId);
2446
+ refreshFlash();
2448
2447
  };
2449
- /** Longest a goal may stay `active` before its watcher gives up. */
2450
- const GOAL_SETTLE_TIMEOUT_MS = 30 * 60 * 1000;
2451
- /** Settings whose session already has a watcher waiting for its goal. */
2448
+ /** Sessions whose completion alert is waiting for their goal to end. */
2452
2449
  const goalWatchers = new Map();
2453
2450
  /**
2454
- * Serve the single completion chime a goal earns when it ends.
2451
+ * Resolve a running→idle edge against the goal projection.
2455
2452
  *
2456
- * The edge that armed this watcher was an intermediate round (the
2457
- * phase was still `active`). The next round starts at quiescence,
2458
- * so the projection is re-read on every change: running again means
2459
- * the edge was intermediate and stays silent, while any non-active
2460
- * phase means the goal ended and earns the one chime.
2453
+ * A goal drives several rounds and every round ends with this edge; with
2454
+ * `goalFinalOnly` on, the edge is only an alert when the goal will not
2455
+ * continue: no goal, completed, paused or blocked. A goal still `active`
2456
+ * gets one watcher that re-reads the phase until it ends (the single
2457
+ * chime) or the session starts running again (silent intermediate round).
2461
2458
  */
2462
- const watchGoalCompletion = (sessionId) => {
2459
+ const handleCompletion = (sessionId, value) => {
2460
+ if (value?.goalFinalOnly !== true) {
2461
+ alertCompletion(sessionId);
2462
+ return;
2463
+ }
2463
2464
  if (goalWatchers.has(sessionId)) return;
2464
2465
  let settled = false;
2465
- let subscriptionOff = () => {};
2466
- let timer;
2467
- const settle = (chime) => {
2466
+ let pollTimer;
2467
+ let deadline;
2468
+ const finish = (chime) => {
2468
2469
  if (settled) return;
2469
2470
  settled = true;
2470
2471
  goalWatchers.delete(sessionId);
2471
- try {
2472
- subscriptionOff();
2473
- } catch {}
2474
- clearTimeout(timer);
2475
- if (!chime) return;
2476
- if (!pageIsWatched() && !quietNow()) unreadCompletion = true;
2477
- notify("completion", undefined, sessionId);
2478
- refreshFlash();
2472
+ clearTimeout(pollTimer);
2473
+ clearTimeout(deadline);
2474
+ if (chime) alertCompletion(sessionId);
2479
2475
  };
2480
- try {
2481
- const sessions = ctx.sessions ?? ctx.uiSession?.sessions;
2482
- const face = sessions?.get?.(sessionId)?.projections?.faceOf?.("goal");
2483
- if (typeof face?.subscribe === "function") {
2484
- const subscription = face.subscribe(() => {
2485
- if (source.getSnapshot().get(sessionId)?.running === true) {
2486
- settle(false);
2487
- return;
2488
- }
2489
- const phase = goalPhaseOf(sessionId);
2490
- if (phase === undefined || phase !== "active") settle(true);
2491
- });
2492
- if (typeof subscription === "function") subscriptionOff = subscription;
2476
+ goalWatchers.set(sessionId, () => finish(false));
2477
+ const poll = async () => {
2478
+ if (source.getSnapshot().get(sessionId)?.running === true) {
2479
+ finish(false);
2480
+ return;
2493
2481
  }
2494
- } catch {}
2495
- // A goal that never resolves must not pin this entry forever;
2496
- // dropping it silently beats a stray chime minutes later.
2497
- timer = setTimeout(() => settle(false), GOAL_SETTLE_TIMEOUT_MS);
2498
- timer?.unref?.();
2499
- goalWatchers.set(sessionId, () => settle(false));
2482
+ const phase = await readGoalPhase(sessionId);
2483
+ if (settled) return;
2484
+ if (phase !== "active") {
2485
+ finish(true);
2486
+ return;
2487
+ }
2488
+ pollTimer = setTimeout(poll, GOAL_POLL_MS);
2489
+ };
2490
+ deadline = setTimeout(() => finish(true), GOAL_SETTLE_TIMEOUT_MS);
2491
+ deadline?.unref?.();
2492
+ void poll();
2500
2493
  };
2501
2494
  /**
2502
2495
  * Which alert the title should carry, if any.
@@ -2580,20 +2573,7 @@ window.__ModuleLoader__.load({
2580
2573
  notify(status.pendingInteraction.kind === "question" ? "question" : "decision", status.pendingInteraction, sessionId);
2581
2574
  }
2582
2575
  if (before !== undefined && before.running === true && status.running === false) {
2583
- const value = form.getSnapshot().value;
2584
- if (!completionIsFinal(sessionId, value)) {
2585
- // An intermediate goal round: stay silent and let
2586
- // the goal's own end deliver the single chime.
2587
- watchGoalCompletion(sessionId);
2588
- } else {
2589
- // A finish that happens while the user is away is
2590
- // news; one they watch happen is not — and one
2591
- // that happens during quiet hours is forgotten
2592
- // rather than kept for later, so nothing about it
2593
- // shows up when the quiet window ends.
2594
- if (!pageIsWatched() && !quietNow()) unreadCompletion = true;
2595
- notify("completion", undefined, sessionId);
2596
- }
2576
+ handleCompletion(sessionId, form.getSnapshot().value);
2597
2577
  }
2598
2578
  }
2599
2579
  }
package/lib/index.js CHANGED
@@ -62,9 +62,14 @@ const DESKTOP_APP_TITLE = "DeepSeek Harness";
62
62
 
63
63
  /** `ShowWindow` command: restore a minimized or maximized window to its prior size. */
64
64
  const SW_RESTORE = 9;
65
+ /** `ShowWindow` command: show a window without asking for the foreground. */
66
+ const SW_SHOW = 5;
65
67
 
66
68
  /** Virtual key and flag for the ALT tap that satisfies the foreground lock. */
67
69
  const VK_MENU = 0x12;
70
+
71
+ /** The shell owns the window: this Host is its child process. */
72
+ const SHELL_PID = process.ppid;
68
73
  const KEYEVENTF_KEYUP = 0x2;
69
74
 
70
75
  //#region native window raise
@@ -164,6 +169,7 @@ function loadNativeRaise() {
164
169
  AllowSetForegroundWindow: user32.func("bool __stdcall AllowSetForegroundWindow(int pid)"),
165
170
  GetForegroundWindow: user32.func("void * __stdcall GetForegroundWindow()"),
166
171
  GetWindowThreadProcessId: user32.func("uint32 __stdcall GetWindowThreadProcessId(void *h, void *pid)"),
172
+ GetWindowPid: user32.func("uint32 __stdcall GetWindowThreadProcessId(void *h, _Out_ uint32 *pid)"),
167
173
  AttachThreadInput: user32.func("bool __stdcall AttachThreadInput(uint32 attach, uint32 attachTo, bool attachFlag)"),
168
174
  keybd_event: user32.func("void __stdcall keybd_event(uint8 vk, uint8 scan, uint32 flags, uintptr_t extra)"),
169
175
  GetCurrentThreadId: kernel32.func("uint32 __stdcall GetCurrentThreadId()"),
@@ -243,14 +249,36 @@ export function isDesktopTitle(title) {
243
249
  * @param native - the bound Win32 calls.
244
250
  * @returns the window handle, or undefined.
245
251
  */
246
- function findDesktopWindow(native) {
247
- let found;
252
+ export function findDesktopWindow(native) {
253
+ let byTitleVisible;
254
+ let byTitleHidden;
255
+ let byPidVisible;
256
+ let byPidHidden;
257
+ const pidBuffer = new Uint32Array(1);
248
258
  const visit = native.koffi.register((handle) => {
249
259
  try {
250
- if (!native.IsWindowVisible(handle)) return true;
251
- if (!isDesktopTitle(windowTitle(native, handle))) return true;
252
- found = handle;
253
- return false; // stop at the first match
260
+ const visible = native.IsWindowVisible(handle);
261
+ const title = windowTitle(native, handle);
262
+ if (isDesktopTitle(title)) {
263
+ if (visible) {
264
+ byTitleVisible = handle;
265
+ return false; // stop at the first visible title match
266
+ }
267
+ if (byTitleHidden === undefined) byTitleHidden = handle;
268
+ return true;
269
+ }
270
+ // A hidden or repainting window can transiently answer with no
271
+ // title; the shell process owns the window, so match that too.
272
+ if (SHELL_PID === undefined || SHELL_PID === 0) return true;
273
+ if (typeof native.GetWindowPid !== "function") return true;
274
+ pidBuffer[0] = 0;
275
+ native.GetWindowPid(handle, pidBuffer);
276
+ if (pidBuffer[0] !== SHELL_PID) return true;
277
+ if (visible) {
278
+ if (byPidVisible === undefined) byPidVisible = handle;
279
+ } else if (byPidHidden === undefined) {
280
+ byPidHidden = handle;
281
+ }
254
282
  } catch {
255
283
  // A window that cannot be inspected simply does not match.
256
284
  }
@@ -265,7 +293,7 @@ function findDesktopWindow(native) {
265
293
  native.koffi.unregister(visit);
266
294
  } catch {}
267
295
  }
268
- return found;
296
+ return byTitleVisible ?? byTitleHidden ?? byPidVisible ?? byPidHidden;
269
297
  }
270
298
 
271
299
  /**
@@ -281,6 +309,9 @@ function raiseDesktopWindowNative() {
281
309
  // Restore first: `ShowWindow(SW_RESTORE)` is not a foreground request, so it
282
310
  // is granted even to a background process. Its return value is the window's
283
311
  // PREVIOUS visibility, not a success flag, so it is deliberately ignored.
312
+ // SW_SHOW is not a foreground request, so a background process is granted
313
+ // it; it is what makes a tray-hidden window visible again.
314
+ if (!native.IsWindowVisible(handle)) native.ShowWindow(handle, SW_SHOW);
284
315
  native.ShowWindow(handle, SW_RESTORE);
285
316
  native.BringWindowToTop(handle);
286
317
  // The foreground request is the part Windows polices: a background process
@@ -435,45 +466,32 @@ const warned = new Set();
435
466
  *
436
467
  * Every failure mode leaves the click a harmless no-op.
437
468
  */
438
- function focusDesktopWindow() {
469
+ function tryRaiseNative() {
470
+ try {
471
+ if (process.platform !== "win32") return false;
472
+ return raiseDesktopWindowNative();
473
+ } catch (error) {
474
+ warn(`native raise failed: ${error?.message ?? error}`);
475
+ return false;
476
+ }
477
+ }
478
+
479
+ /** Raise the window through the app's own deep link; last resort. */
480
+ function focusDesktopWindowDeepLink() {
439
481
  try {
440
482
  if (process.platform === "win32") {
441
- let raised = false;
442
- try {
443
- raised = raiseDesktopWindowNative();
444
- } catch (error) {
445
- warn(`native raise failed: ${error?.message ?? error}`);
446
- }
447
- if (raised) {
448
- log("window raised");
449
- } else {
450
- log("native raise did not take the foreground; falling back to the deep link");
451
- raiseDesktopWindowDeepLink();
452
- }
483
+ raiseDesktopWindowDeepLink();
453
484
  } else if (process.platform === "darwin") {
454
- // Activate the app by bundle id first: it needs no URL scheme to
455
- // have been registered, which a packaged .app only gets if its
456
- // Info.plist declares CFBundleURLTypes — something this project
457
- // cannot verify from source. The deep link stays as the fallback,
458
- // and a launch that failed is now named in the log instead of
459
- // looking exactly like one that succeeded.
460
485
  log("raising via open -b");
461
486
  launcher("open", ["-b", MACOS_BUNDLE_ID], (ok) => {
462
- if (ok) return;
463
- log("bundle-id activation did not take; falling back to the deep link");
464
- launcher("open", [FOCUS_DEEP_LINK]);
487
+ if (!ok) launcher("open", [FOCUS_DEEP_LINK]);
465
488
  });
466
489
  } else {
467
- // No desktop shell ships for other platforms today — the shell
468
- // itself refuses anything but win32/darwin, and a browser click
469
- // never reaches this function. `xdg-open` is the correct opener
470
- // should a Linux shell ever appear; until then this line is
471
- // unreachable rather than misleading.
472
490
  log("raising via xdg-open + deep link");
473
491
  launcher("xdg-open", [FOCUS_DEEP_LINK]);
474
492
  }
475
493
  } catch (error) {
476
- warn(`focus failed: ${error?.message ?? error}`);
494
+ warn(`focus fallback failed: ${error?.message ?? error}`);
477
495
  }
478
496
  }
479
497
 
@@ -482,6 +500,9 @@ function focusDesktopWindow() {
482
500
  /** Route the browser half reads the update check through. */
483
501
  export const UPDATE_CHECK_PATH = "/notify-sounds/update/check";
484
502
 
503
+ /** Route the browser half reads a session's goal phase through. */
504
+ export const GOAL_PHASE_PATH = "/notify-sounds/goal";
505
+
485
506
  /** The npm package this plugin publishes as — the only name the check ever asks for. */
486
507
  const UPDATE_PACKAGE = "dsh-plugin-notify-sounds";
487
508
 
@@ -1439,7 +1460,14 @@ export function apply(ctx) {
1439
1460
  res.end();
1440
1461
  log(`focus click (fromBrowser=${fromBrowser})`);
1441
1462
  if (!fromBrowser) {
1442
- focusDesktopWindow();
1463
+ // Foreground requests can be refused while another app owns
1464
+ // the input queue; retry before paying for a deep-link launch.
1465
+ let raised = false;
1466
+ for (let attempt = 0; attempt < 3 && !raised; attempt += 1) {
1467
+ raised = tryRaiseNative();
1468
+ if (!raised) await new Promise((resolve) => setTimeout(resolve, 180));
1469
+ }
1470
+ if (!raised) focusDesktopWindowDeepLink();
1443
1471
  }
1444
1472
  },
1445
1473
  }), "notify-sounds: focus route");
@@ -1479,4 +1507,46 @@ export function apply(ctx) {
1479
1507
  }), "notify-sounds: update check route");
1480
1508
 
1481
1509
  });
1510
+ // The goal phase route (1.8.1): the browser cannot rely on its own
1511
+ // session projections for a session it never opened, so goal mode asks
1512
+ // the Host, whose projection store is authoritative. Read-only, one
1513
+ // session id, fenced like every other route here.
1514
+ ctx.inject(["webServer", "connection", "sessions", "sessionProjections"], (child) => {
1515
+ /** The goal phase for one session, or undefined when there is none. */
1516
+ const phaseOf = (sessionId) => {
1517
+ try {
1518
+ const session = child.sessions.get(sessionId);
1519
+ if (session === undefined) return undefined;
1520
+ const projection = child.sessionProjections.stateOf(session, "goal");
1521
+ if (projection === undefined || projection.failure != null) return undefined;
1522
+ const phase = projection.current?.goal?.phase ?? projection.current?.phase;
1523
+ return typeof phase === "string" ? phase : undefined;
1524
+ } catch {
1525
+ return undefined;
1526
+ }
1527
+ };
1528
+ child.effect(() => child.webServer.register({
1529
+ kind: "exact",
1530
+ path: GOAL_PHASE_PATH,
1531
+ handler: (req, res) => {
1532
+ const rejection = child.connection.requestRejection(req);
1533
+ if (rejection !== undefined) {
1534
+ res.statusCode = rejection;
1535
+ res.end();
1536
+ return;
1537
+ }
1538
+ if (req.method !== "GET") {
1539
+ res.statusCode = 405;
1540
+ res.setHeader("allow", "GET");
1541
+ res.end();
1542
+ return;
1543
+ }
1544
+ const sessionId = new URL(req.url ?? "/", "http://localhost").searchParams.get("session") ?? "";
1545
+ const phase = sessionId === "" ? undefined : phaseOf(sessionId);
1546
+ res.statusCode = 200;
1547
+ res.setHeader("content-type", "application/json");
1548
+ res.end(JSON.stringify({ phase: phase ?? null }));
1549
+ },
1550
+ }), "notify-sounds: goal phase route");
1551
+ });
1482
1552
  }
package/package.json CHANGED
@@ -1,62 +1,62 @@
1
- {
2
- "name": "dsh-plugin-notify-sounds",
3
- "version": "1.8.0",
4
- "description": "Notification sounds for DeepSeek Harness — a soft chime when the agent needs your decision or finishes a task, with a Settings section styled like DSH's own · 需要决策或任务完成时播放提示音,点击系统通知可回到窗口,设置面板可调音量与音效",
5
- "type": "module",
6
- "main": "lib/index.js",
7
- "exports": {
8
- ".": {
9
- "default": "./lib/index.js"
10
- },
11
- "./client": {
12
- "default": "./lib/client.js"
13
- },
14
- "./package.json": "./package.json",
15
- "./cordis.patch.yml": "./cordis.patch.yml"
16
- },
17
- "files": [
18
- "lib/index.js",
19
- "lib/client.js",
20
- "cordis.patch.yml",
21
- "README.zh.md"
22
- ],
23
- "license": "MIT",
24
- "repository": {
25
- "type": "git",
26
- "url": "git+https://github.com/BillCx330/dsh-plugin-notify-sounds.git"
27
- },
28
- "bugs": {
29
- "url": "https://github.com/BillCx330/dsh-plugin-notify-sounds/issues"
30
- },
31
- "homepage": "https://github.com/BillCx330/dsh-plugin-notify-sounds#readme",
32
- "keywords": [
33
- "deepseek",
34
- "harness",
35
- "dsh",
36
- "dsh-plugin",
37
- "notification",
38
- "sound"
39
- ],
40
- "peerDependencies": {
41
- "@deepseek-ai/schemastery": "^3.18.1"
42
- },
43
- "devDependencies": {
44
- "@deepseek-ai/schemastery": "^3.18.4"
45
- },
46
- "dsh": {
47
- "bundle": {
48
- "patch": "./cordis.patch.yml"
49
- },
50
- "client": {
51
- "inject": [
52
- "@deepseek-ai/dsh-client-locale",
53
- "@deepseek-ai/dsh-api-session-controller",
54
- "@deepseek-ai/dsh-client-ui-session",
55
- "@deepseek-ai/dsh-client-ui-settings",
56
- "@deepseek-ai/dsh-client-ui-settings-general",
57
- "@deepseek-ai/dsh-client-ui-primitives"
58
- ],
59
- "platform": "web"
60
- }
61
- }
1
+ {
2
+ "name": "dsh-plugin-notify-sounds",
3
+ "version": "1.8.4",
4
+ "description": "Notification sounds for DeepSeek Harness — a soft chime when the agent needs your decision or finishes a task, with a Settings section styled like DSH's own · 需要决策或任务完成时播放提示音,点击系统通知可回到窗口,设置面板可调音量与音效",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": {
9
+ "default": "./lib/index.js"
10
+ },
11
+ "./client": {
12
+ "default": "./lib/client.js"
13
+ },
14
+ "./package.json": "./package.json",
15
+ "./cordis.patch.yml": "./cordis.patch.yml"
16
+ },
17
+ "files": [
18
+ "lib/index.js",
19
+ "lib/client.js",
20
+ "cordis.patch.yml",
21
+ "README.zh.md"
22
+ ],
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/BillCx330/dsh-plugin-notify-sounds.git"
27
+ },
28
+ "bugs": {
29
+ "url": "https://github.com/BillCx330/dsh-plugin-notify-sounds/issues"
30
+ },
31
+ "homepage": "https://github.com/BillCx330/dsh-plugin-notify-sounds#readme",
32
+ "keywords": [
33
+ "deepseek",
34
+ "harness",
35
+ "dsh",
36
+ "dsh-plugin",
37
+ "notification",
38
+ "sound"
39
+ ],
40
+ "peerDependencies": {
41
+ "@deepseek-ai/schemastery": "^3.18.1"
42
+ },
43
+ "devDependencies": {
44
+ "@deepseek-ai/schemastery": "^3.18.4"
45
+ },
46
+ "dsh": {
47
+ "bundle": {
48
+ "patch": "./cordis.patch.yml"
49
+ },
50
+ "client": {
51
+ "inject": [
52
+ "@deepseek-ai/dsh-client-locale",
53
+ "@deepseek-ai/dsh-api-session-controller",
54
+ "@deepseek-ai/dsh-client-ui-session",
55
+ "@deepseek-ai/dsh-client-ui-settings",
56
+ "@deepseek-ai/dsh-client-ui-settings-general",
57
+ "@deepseek-ai/dsh-client-ui-primitives"
58
+ ],
59
+ "platform": "web"
60
+ }
61
+ }
62
62
  }