@idoall/dsh-notify 0.3.0 → 0.3.2

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
@@ -4,6 +4,33 @@ All notable changes to this project are documented here. The format follows [Kee
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.3.2] - 2026-09-20
8
+
9
+ ### Fixed
10
+
11
+ - **Completion now follows DSH's native idle state.** A completed Toast is not emitted when a response first appears or after an arbitrary timer. `turn/end` only creates a candidate; the card is delivered when the owning Agent reports `agent/status: idle`, the same state that stops the native session-tree spinner. A new `running` transition cancels an earlier candidate, so goal continuation, queued work, and tool follow-ups cannot announce completion too early or strand a missing notification.
12
+ - **One continuous task receives one green completion card.** Plan reviews and execution approvals are control gates, not finished tasks. Their transient idle pause no longer adds a green Toast before the user decides and the task resumes; the later non-interactive work turn is the sole completion delivery. This removes the duplicate same-session “任务完成” cards that could appear seconds apart after approval or plan review.
13
+ - **A direct answer no longer loses completion.** Ordinary `ask_user_question` is intentionally distinguished from a plan review or execution approval. When the user answer itself finishes a task and no follow-up turn starts, the native-idle transition still sends exactly one green completion Toast. If work resumes, the pending candidate is cancelled and the final work turn remains the only notification.
14
+
15
+ ### Verified
16
+
17
+ - Host lifecycle regression coverage confirms a completion is withheld while DSH is native `running` and emitted exactly once only after native `idle`.
18
+ - A plan-review pause followed by its approved work emits one completion card, not two.
19
+ - An ordinary question whose answer directly finishes work emits one completion card rather than none.
20
+ - Full verification passed: static source checks, **84 automated tests**, build, and package precondition checks.
21
+
22
+ ## [0.3.1] - 2026-09-20
23
+
24
+ ### Fixed
25
+
26
+ - **Sound now matches visible delivery.** Automatic audio plays only when a notification is admitted to an enabled visual Toast queue. A poll batch produces one cue rather than one cue per record, and a rejected card remains eligible for a later delivery attempt.
27
+ - **Open interaction recovery.** After the Toast overlay remounts, still-open approvals, questions, and plan reviews are restored silently. Settled history stays suppressed, preventing completed messages from replaying.
28
+ - **Approval-colour consistency.** Plan-review notifications now use the same amber approval colour as execution approvals. Ordinary questions remain blue.
29
+
30
+ ### Verified
31
+
32
+ - A live pending-interaction acceptance confirmed the native pending marker, Toast, sound, Toast navigation, and automatic left-sidebar reveal together; clearing the interaction cleared its pending delivery state.
33
+
7
34
  ## [0.3.0] - 2026-09-20
8
35
 
9
36
  ### Added
@@ -156,6 +183,8 @@ First public release. Verified against DeepSeek Harness `0.1.5-rc.1`.
156
183
 
157
184
  - Browser system notifications (channel B), host OS notifications (channel C) and web push / service worker (channel D), along with the `web-push` and `ipaddr.js` dependencies. Those channels failed invisibly (submitted but never seen) and could not be made reliable across browsers and operating systems.
158
185
 
186
+ [0.3.2]: https://github.com/idoall/dsh-notify/releases/tag/v0.3.2
187
+ [0.3.1]: https://github.com/idoall/dsh-notify/releases/tag/v0.3.1
159
188
  [0.3.0]: https://github.com/idoall/dsh-notify/releases/tag/v0.3.0
160
189
  [0.2.3]: https://github.com/idoall/dsh-notify/releases/tag/v0.2.3
161
190
  [0.2.2]: https://github.com/idoall/dsh-notify/releases/tag/v0.2.2
package/README.md CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  > DSH Notify is a DeepSeek Harness community plugin. It registers only a settings section and an in-page overlay; it does not modify DSH source.
24
24
 
25
- When a session really stops, fails, asks a question, or needs approval, a card appears in the top-right corner of the current page. Intermediate goal rounds and queued follow-up turns stay quiet. Everything happens in the page you already have open: there is no service worker, web push, host OS notification, or notification history.
25
+ When a session really stops, fails, asks a question, or needs approval, a card appears in the top-right corner of the current page. A green **Task completed** card follows DSH's native `agent/status: idle` transition — the same state that stops the session-tree spinner — rather than the earlier moment when text first looks complete. Intermediate goal rounds and queued follow-up turns stay quiet. Everything happens in the page you already have open: there is no service worker, web push, host OS notification, or notification history.
26
26
 
27
27
  <p align="center">
28
28
  <img src="./assets/toast.png" width="70%" alt="Enhanced notification stack: the newest error card is fully visible and earlier blue, amber and green cards expose equal lower edges">
@@ -33,10 +33,11 @@ When a session really stops, fails, asks a question, or needs approval, a card a
33
33
  - **Enhanced or soft toast styling.** The default **Enhanced** style gives each notification a clear status colour and a short four-second attention bar; the bar is attention only, not a dismissal timer. **Soft** is a lower-key alternative. A card remains until you close it, open its session, or complete an in-card answer.
34
34
  - **A collapsible page-local stack.** With **Collapse multiple notifications** enabled (the default), the second card and onward form a pile: the newest card is fully readable on top, while earlier cards remain complete underneath and expose equal `18px` lower edges. Pointer entry or keyboard focus expands the pile. The page keeps up to 50 live cards; pending actions are prioritised before ordinary cards, then newer cards come first.
35
35
  - **Direct, traceable navigation.** Clicking a card opens its session and the exact originating turn. After the host selects that session, the selected row is smoothly revealed in the left session tree, even when it lives in a different off-screen workspace. A card stays put with an explanation if navigation cannot succeed.
36
- - **Answer in the toast.** A pending question or approval renders the same compatible options as the composer. In-card and composer answers share the same host interaction.
37
- - **Sound and background attention.** Built-in WebAudio cues and validated custom uploads play for new toasts, including while the page is hidden. A background tab with unseen notifications receives a temporary bell prefix and favicon attention marker.
36
+ - **Answer in the toast.** A pending question or approval renders the same compatible options as the composer. Execution approvals and plan reviews share DSH's amber decision colour; ordinary questions remain blue. In-card and composer answers share the same host interaction.
37
+ - **Sound and background attention.** Built-in WebAudio cues and validated custom uploads play only after a card is admitted to an enabled visual Toast queue, including while the page is hidden. One polling batch produces one cue. A background tab with unseen notifications receives a temporary bell prefix and favicon attention marker.
38
+ - **Completion means native idle, once per task.** A green card waits until DSH reports the owning Agent as `idle`, matching the session-tree spinner instead of guessing from a rendered answer or an elapsed timer. A plan review and an execution approval are control gates, so their temporary idle pause does not create an extra completion card; the later work turn supplies the one card. An ordinary question is different: if its answer directly finishes the task, that same turn still produces one green card. If work resumes, the prior candidate is cancelled and only the final native-idle transition is announced.
38
39
  - **Task-noise control.** Subtask, background-job, and workflow completion notifications are off by default.
39
- - **No history by design.** Notification records are held only in the open page's in-memory queue. Refreshing the page clears them; an unopened page is not replayed a backlog.
40
+ - **No history by design.** Notification records are held only in the open page's in-memory queue. Settled history is never replayed after a refresh or overlay remount; an interaction that is still open when the host can report it is restored silently.
40
41
 
41
42
  ## Quick start
42
43
 
@@ -84,7 +85,7 @@ Reload the profile or restart DSH only when its plugin host has not hot-reloaded
84
85
  | Toast position | conversation top-right | Anchors the overlay to the chat column and follows sidebar layout changes. |
85
86
  | Notification style | **Enhanced** | Enhanced uses clear status colours and a short attention bar; Soft uses a quieter presentation. |
86
87
  | Collapse multiple notifications | **on** | From two cards onward, show the newest card fully and stack older cards below it; hover or focus expands them. |
87
- | In-page sound | **on** | Plays a cue for each new toast, including while DSH is in a background tab. Built-ins: chime, ping, alert, silent; custom uploads are supported. |
88
+ | In-page sound | **on** | Plays one cue when a polling batch admits one or more new visible Toasts, including while DSH is in a background tab. Built-ins: chime, ping, alert, silent; custom uploads are supported. |
88
89
  | Subtask / background completion | **off** | Enables notifications for subagents, background jobs, and workflows, which can otherwise be noisy. |
89
90
  | Preview and self-test | — | Sends page-local examples only: **Completed**, **Confirm**, **Failed**, **Info**, replay all four styles, fold the active examples, or clear them. No test sends a system notification or changes a real task. |
90
91
 
@@ -92,10 +93,12 @@ Custom sounds are stored in `<dataDir>/sounds/` in the profile data directory, n
92
93
 
93
94
  ## Compatibility
94
95
 
95
- Current release target: plugin **`0.3.0`** verified against DeepSeek Harness **`0.1.6-alpha.1`**.
96
+ Current release target: plugin **`0.3.2`** verified against DeepSeek Harness **`0.1.6-alpha.1`**.
96
97
 
97
98
  | Plugin | Verified DeepSeek Harness |
98
99
  | --- | --- |
100
+ | `0.3.2` | `0.1.6-alpha.1` |
101
+ | `0.3.1` | `0.1.6-alpha.1` |
99
102
  | `0.3.0` | `0.1.6-alpha.1` |
100
103
  | `0.2.2` | `0.1.6-alpha.1` |
101
104
  | `0.2.1` | `0.1.6-alpha.1` |
@@ -131,8 +134,8 @@ npm run pack:check # publish preconditions + client registration check
131
134
  Releases are tag-driven. Bump `package.json`, move the matching CHANGELOG section out of `Unreleased`, write `release-notes/v<version>.md`, then push the release commit and tag:
132
135
 
133
136
  ```sh
134
- git tag v0.3.0
135
- git push origin v0.3.0
137
+ git tag v0.3.2
138
+ git push origin v0.3.2
136
139
  ```
137
140
 
138
141
  The release workflow runs `npm run verify`, packs the plugin, publishes through npm trusted publishing (OIDC), and creates a GitHub Release with the package tarball and sha256.
package/README.zh.md CHANGED
@@ -22,7 +22,7 @@
22
22
 
23
23
  > DSH Notify 是 DeepSeek Harness 社区插件,只注册设置区块与页内浮层,不修改 DSH 源码。
24
24
 
25
- 会话真正停下、运行失败、向你提问或请求审批时,当前页面右上角会出现通知卡片。goal 自动续跑和排队的下一轮保持安静。一切发生在你已打开的页面内:没有 Service Worker、Web Push、宿主机系统通知或通知历史。
25
+ 会话真正停下、运行失败、向你提问或请求审批时,当前页面右上角会出现通知卡片。绿色**任务完成**卡以 DSH 原生 `agent/status: idle` 为准——这与左侧会话树转圈停止是同一个状态——而不是以右侧文字看起来已经结束的时刻推测。goal 自动续跑和排队的下一轮保持安静。一切发生在你已打开的页面内:没有 Service Worker、Web Push、宿主机系统通知或通知历史。
26
26
 
27
27
  <p align="center">
28
28
  <img src="./assets/toast.png" width="70%" alt="增强版通知堆叠:最新的失败通知完整显示,较早的蓝色、橙色和绿色通知等距露出下边缘">
@@ -33,10 +33,11 @@
33
33
  - **增强版或柔和版通知样式**:默认的**增强版**使用清晰状态色与四秒短暂提醒条;提醒条只用于吸引注意,不负责关闭通知。**柔和版**提供更克制的视觉效果。卡片会保留到你关闭、打开对应会话或完成卡片内回答为止。
34
34
  - **可折叠的页内通知栈**:开启默认的**多条通知折叠显示**后,从第 2 条起会折叠:最新卡片完整可读,早期卡片仍保留完整内容并在下方等距露出 `18px` 边缘。鼠标移入或键盘焦点进入时会展开。本页最多保存 50 条活跃卡片;待处理通知优先,其余按最新优先。
35
35
  - **可追溯的会话跳转**:点通知会打开对应会话并定位到来源轮次。宿主选中会话后,左侧会话树会自动平滑滚动并展示已选行,即使它位于另一个屏幕外工作区。跳转失败时卡片会留在原地说明原因。
36
- - **在卡片内回答**:待回复问题或审批会显示可兼容的输入框选项;卡片内回答与输入框操作同一份宿主交互。
37
- - **提示音与后台提醒**:新通知可以播放内置 WebAudio 或经过校验的自定义提示音,页面在后台时仍可播放。后台标签有未查看通知时,标题和 favicon 会短暂提示。
36
+ - **在卡片内回答**:待回复问题或审批会显示可兼容的输入框选项;执行审批与计划待审沿用 DSH 的橙色决策语义,普通需要回复保持蓝色;卡片内回答与输入框操作同一份宿主交互。
37
+ - **提示音与后台提醒**:通知成功进入已启用的可视 Toast 队列后,才会播放内置 WebAudio 或经过校验的自定义提示音;页面在后台时也适用。同一轮轮询的一批通知只播放一次。后台标签有未查看通知时,标题和 favicon 会短暂提示。
38
+ - **完成以原生 idle 为准,并且每项任务只通知一次**:绿色完成卡等待 DSH 报告所属 Agent 为 `idle` 才发送,和左侧会话树转圈停止一致;不再依据已渲染的回答或计时器猜测。计划待审和执行审批是控制门:它们短暂进入 idle 不会额外生成完成卡,批准后的后续工作轮才产生唯一一张。普通需要回复不同:如果你的回答直接结束任务,该轮仍会产生一张绿色完成卡;若之后又继续运行,旧候选会被取消,最终只通知真正结束的 native-idle 状态。
38
39
  - **任务噪声控制**:子任务、后台任务和工作流完成通知默认关闭。
39
- - **无历史设计**:通知仅保存在当前页面内存中;刷新即清空,未打开的页面不会收到旧消息回放。
40
+ - **无历史设计**:通知仅保存在当前页面内存中;刷新或 Toast 浮层重新挂载后,不会回放已结算历史;若宿主仍能报告未处理交互,则会静默恢复。
40
41
 
41
42
  ## 快速开始
42
43
 
@@ -84,7 +85,7 @@ dsh plugin --profile web add "link:$(pwd)"
84
85
  | Toast 位置 | 会话区右上 | 浮层贴在聊天区,并跟随左右侧栏布局变化。 |
85
86
  | 通知样式 | **增强版** | 增强版使用清晰状态色和短提醒条;柔和版更克制。 |
86
87
  | 多条通知折叠显示 | **开** | 从两条开始完整显示最新一条,旧卡叠在下方;悬停或聚焦即可展开。 |
87
- | 页内提示音 | **开** | 每条新通知播放提示音,即使 DSH 标签在后台。内置 chime / ping / alert / 静音,也可上传自定义声音。 |
88
+ | 页内提示音 | **开** | 一轮轮询只要有一条或多条新 Toast 成功进入可视队列,就播放一次提示音,即使 DSH 标签在后台。内置 chime / ping / alert / 静音,也可上传自定义声音。 |
88
89
  | 子任务 / 后台任务完成时通知 | **关** | 开启子代理、后台任务与工作流的完成通知;默认避免噪声。 |
89
90
  | 预览与自测 | — | 仅发送当前页面的完成、确认、失败、信息示例;也可重播四种状态、折叠当前示例或清空。不会发系统通知,也不影响真实任务。 |
90
91
 
@@ -92,10 +93,12 @@ dsh plugin --profile web add "link:$(pwd)"
92
93
 
93
94
  ## 兼容性
94
95
 
95
- 当前发布目标:插件 **`0.3.0`** 已在 DeepSeek Harness **`0.1.6-alpha.1`** 上验证。
96
+ 当前发布目标:插件 **`0.3.2`** 已在 DeepSeek Harness **`0.1.6-alpha.1`** 上验证。
96
97
 
97
98
  | 插件 | 已验证的 DeepSeek Harness |
98
99
  | --- | --- |
100
+ | `0.3.2` | `0.1.6-alpha.1` |
101
+ | `0.3.1` | `0.1.6-alpha.1` |
99
102
  | `0.3.0` | `0.1.6-alpha.1` |
100
103
  | `0.2.2` | `0.1.6-alpha.1` |
101
104
  | `0.2.1` | `0.1.6-alpha.1` |
@@ -131,8 +134,8 @@ npm run pack:check # 发布前置条件 + 客户端注册校验
131
134
  发版由 tag 驱动。更新 `package.json`、将对应 CHANGELOG 段落移出 `Unreleased`、编写 `release-notes/v<版本>.md` 后,推送发版提交与 tag:
132
135
 
133
136
  ```sh
134
- git tag v0.3.0
135
- git push origin v0.3.0
137
+ git tag v0.3.2
138
+ git push origin v0.3.2
136
139
  ```
137
140
 
138
141
  发版工作流会运行 `npm run verify`、打包插件、通过 npm trusted publishing(OIDC)发布,并创建附带 tarball 与 sha256 的 GitHub Release。
package/dist/client.js CHANGED
@@ -498,7 +498,7 @@ window.__ModuleLoader__.load({
498
498
  function toastOrder(records = []) {
499
499
  return [...records.filter((record) => record?.phase === "open"), ...records.filter((record) => record?.phase !== "open")];
500
500
  }
501
- var TOAST_TONE_BY_KIND = Object.freeze({ approval: "warning", question: "info", "plan-review": "info", completed: "success", failed: "error", "job-end": "neutral", "workflow-end": "neutral", test: "neutral" });
501
+ var TOAST_TONE_BY_KIND = Object.freeze({ approval: "warning", question: "info", "plan-review": "warning", completed: "success", failed: "error", "job-end": "neutral", "workflow-end": "neutral", test: "neutral" });
502
502
  function toastTone(kind) {
503
503
  return TOAST_TONE_BY_KIND[kind] ?? "neutral";
504
504
  }
@@ -833,15 +833,18 @@ window.__ModuleLoader__.load({
833
833
  }
834
834
  };
835
835
  }, [anyCard]);
836
- const showToast = (record) => {
837
- if (!record?.eventId) return;
838
- if (globalThis.document?.hidden) unseen.current.add(record.eventId);
839
- toasted.current.add(record.eventId);
836
+ const showToast = (record, { playSound = true } = {}) => {
837
+ if (!record?.eventId) return false;
840
838
  const incoming = [{ record, status: "idle", error: null, lastLabel: null, leaving: false, attention: true }, ...cardsRef.current.filter((card) => card.record.eventId !== record.eventId)];
841
839
  const next = queueCards(incoming);
840
+ const admitted = next.some((card) => card.record.eventId === record.eventId);
842
841
  for (const card of incoming) if (!next.includes(card)) forget(card.record.eventId);
843
842
  commit(next);
844
- void soundPlayer.play();
843
+ if (!admitted) return false;
844
+ toasted.current.add(record.eventId);
845
+ if (globalThis.document?.hidden) unseen.current.add(record.eventId);
846
+ if (playSound && toastConfig.toastEnabled && toastConfig.toastPosition !== "off") void soundPlayer.play();
847
+ return true;
845
848
  };
846
849
  import_react.default.useEffect(() => {
847
850
  const local = (event) => {
@@ -897,6 +900,8 @@ window.__ModuleLoader__.load({
897
900
  for (const id of seen) if (!ids.has(id)) seen.delete(id);
898
901
  if (!primed.current) {
899
902
  primed.current = true;
903
+ const waiting = toastOrder(state.records).filter((record) => record?.phase === "open");
904
+ for (const record of waiting.reverse()) showToast(record, { playSound: false });
900
905
  for (const id of ids) seen.add(id);
901
906
  return;
902
907
  }
@@ -908,7 +913,9 @@ window.__ModuleLoader__.load({
908
913
  if (wasWaiting && live.phase !== "open") dismiss(card.record.eventId);
909
914
  }
910
915
  const fresh = toastOrder(state.records).filter((record) => !seen.has(record.eventId));
911
- for (const record of fresh.reverse()) showToast(record);
916
+ let admitted = false;
917
+ for (const record of fresh.reverse()) admitted = showToast(record, { playSound: false }) || admitted;
918
+ if (admitted && toastConfig.toastEnabled && toastConfig.toastPosition !== "off") void soundPlayer.play();
912
919
  }, [state.records, state.primed]);
913
920
  import_react.default.useEffect(() => {
914
921
  const sync = () => {
package/dist/index.js CHANGED
@@ -9,8 +9,9 @@ export const name = 'dsh-notify';
9
9
  export const inject = [];
10
10
  export const Config = z.object({
11
11
  dataDir: z.string().description('Absolute path to the profile-owned dsh-notify data directory.'),
12
- // 0 restores the old "notify on every finished turn" behaviour.
13
- completionGraceMs: z.number().step(1).min(0).max(600_000).default(8_000).description('How long a finished turn must stay quiet before it counts as a finished task (ms).'),
12
+ // Compatibility switch for old hosts/tests without `agent/status`; current DSH releases use the
13
+ // authoritative idle transition instead of guessing completion from elapsed time.
14
+ completionGraceMs: z.number().step(1).min(0).max(600_000).default(8_000).description('Legacy fallback for hosts without agent lifecycle status; current DSH releases notify on authoritative idle.'),
14
15
  });
15
16
  export { EventReducer, PLAN_REVIEW_FALLBACK, sanitizeBody, validateRequest } from './core.js';
16
17
  export { createBuffer, createSettings, BUFFER_LIMIT } from './buffer.js';
@@ -176,6 +177,24 @@ export async function apply(ctx, config = {}) {
176
177
  // A live user-questions/request has no source-proven causal callId, therefore
177
178
  // this host must not infer one from an arrival queue or FIFO ordering.
178
179
  const pendingToolCalls = new Map();
180
+ // Plan reviews and execution approvals are control gates: their idle pause is not task completion.
181
+ // An ordinary question can instead be the last operation of a task, so retain its kind and allow that
182
+ // directly-settled turn to announce completion once native DSH reaches idle.
183
+ const interactiveTurns = new Map();
184
+ const markInteractiveTurn = (sessionId, turn, kind = 'question') => {
185
+ if (!Number.isSafeInteger(turn) || turn <= 0) return;
186
+ let turns = interactiveTurns.get(sessionId);
187
+ if (!turns) { turns = new Map(); interactiveTurns.set(sessionId, turns); }
188
+ turns.set(turn, kind);
189
+ };
190
+ const consumeInteractiveTurn = (sessionId, turn) => {
191
+ const turns = interactiveTurns.get(sessionId);
192
+ if (!turns || !turns.has(turn)) return undefined;
193
+ const kind = turns.get(turn);
194
+ turns.delete(turn);
195
+ if (!turns.size) interactiveTurns.delete(sessionId);
196
+ return kind;
197
+ };
179
198
  const pendingFor = (sessionId) => {
180
199
  let calls = pendingToolCalls.get(sessionId);
181
200
  if (!calls) { calls = new Set(); pendingToolCalls.set(sessionId, calls); }
@@ -202,15 +221,16 @@ export async function apply(ctx, config = {}) {
202
221
  };
203
222
  const safely = (work) => { Promise.resolve().then(work).catch(() => { diagnostics.eventErrors += 1; }); };
204
223
  /**
205
- * A turn ending is not the task finishing. With goals, queued prompts or an agent that keeps
206
- * working, one job produces several turns — and therefore several "任务完成" toasts, which is
207
- * exactly the noise the user could not reconcile. So a notifiable turn end is *deferred*: if the
208
- * session starts working again inside the grace window (which is what a goal round does), nothing is
209
- * recorded at all; if a goal is engaged, nothing is recorded until that goal ends.
224
+ * A turn boundary only says that one response has ended. DSH's native sidebar stays busy until the
225
+ * owning Agent enters `idle`; that lifecycle transition is the authority for a completed task. The
226
+ * old elapsed-time heuristic could disagree with the spinner and, worse, leave a goal-held candidate
227
+ * stranded forever. Keep the timer solely as a compatibility fallback for pre-lifecycle hosts.
210
228
  */
211
229
  const completionGraceMs = Number.isSafeInteger(config.completionGraceMs) ? config.completionGraceMs : 8_000;
212
230
  const deferredCompletions = new Map(); // sessionId -> { payload, timer }
213
- const engagedGoals = new Set(); // sessionIds whose goal loop is still running
231
+ const engagedGoals = new Set(); // only used for a legacy host without agent/status
232
+ const agentStatuses = new Map(); // sessionId -> 'idle' | 'running'
233
+ const statusCapable = new Set(); // sessions for which the Host has emitted agent/status
214
234
  const clearDeferred = (sessionId) => { const entry = deferredCompletions.get(sessionId); if (entry?.timer) clearTimeout(entry.timer); };
215
235
  const flushCompletion = async (sessionId) => {
216
236
  const entry = deferredCompletions.get(sessionId);
@@ -229,8 +249,13 @@ export async function apply(ctx, config = {}) {
229
249
  const deferCompletion = (sessionId, payload) => {
230
250
  const existing = deferredCompletions.get(sessionId);
231
251
  if (existing?.timer) clearTimeout(existing.timer);
232
- // An engaged goal holds the payload with no timer: the announcement waits for the goal to end.
233
- // Grace 0 is the old "every finished turn" behaviour and flushes immediately.
252
+ // Current DSH: wait for exactly the same idle state that clears the native sidebar spinner.
253
+ if (statusCapable.has(sessionId)) {
254
+ deferredCompletions.set(sessionId, { payload, timer: null });
255
+ if (agentStatuses.get(sessionId) === 'idle') void flushCompletion(sessionId).catch(() => { diagnostics.eventErrors += 1; });
256
+ return;
257
+ }
258
+ // Legacy DSH has no status lifecycle: retain the old grace behaviour as a safe fallback.
234
259
  if (engagedGoals.has(sessionId)) {
235
260
  deferredCompletions.set(sessionId, { payload, timer: null });
236
261
  return;
@@ -284,11 +309,24 @@ export async function apply(ctx, config = {}) {
284
309
  const liveTurns = new Map();
285
310
  const turnOf = (sessionId, event) => (Number.isSafeInteger(event?.turn) && event.turn > 0 ? event.turn : liveTurns.get(sessionId));
286
311
 
312
+ // `agent/status: idle` is the public DSH signal that no driver remains scheduled or active. It
313
+ // matches the native session spinner, so completion Toasts cannot precede the sidebar state.
314
+ ctx?.on?.('agent/status', ({ agent, status } = {}) => {
315
+ const sessionId = sessionIdOf(agent);
316
+ if (typeof sessionId !== 'string' || sessionId === '') return;
317
+ if (status !== 'idle' && status !== 'running') return;
318
+ statusCapable.add(sessionId);
319
+ agentStatuses.set(sessionId, status);
320
+ if (status === 'running') { cancelCompletion(sessionId); return; }
321
+ safely(() => flushCompletion(sessionId));
322
+ });
323
+
287
324
  ctx?.on?.('session/event', (session, event) => {
288
325
  const data = event?.data ?? {};
289
326
  const sessionId = session?.id;
290
327
  if (Number.isSafeInteger(data.turn) && data.turn > 0) liveTurns.set(sessionId, data.turn);
291
328
  if (event?.type === 'tool/call' && data.callId && (data.name === 'ask_user_question' || data.name === 'exit_plan_mode')) {
329
+ markInteractiveTurn(sessionId, turnOf(sessionId, data), data.name === 'exit_plan_mode' ? 'plan-review' : 'question');
292
330
  pendingFor(sessionId).add(data.callId);
293
331
  const interaction = reducer.question({ sessionId, callId: data.callId, intent: data.name === 'exit_plan_mode' ? { kind: 'plan-review' } : undefined, title: interactionBody(data.name, data.arguments), turn: turnOf(sessionId, data) });
294
332
  safely(() => dispatch(interaction));
@@ -307,8 +345,10 @@ export async function apply(ctx, config = {}) {
307
345
  safely(async () => {
308
346
  // Work resumed: whatever turn end is still pending for this session was not the end of the task.
309
347
  if (event?.type === 'turn/start' || event?.type === 'tool/call') cancelCompletion(sessionId);
310
- if (event?.type === 'approval/asked') await dispatch(reducer.approvalAsked({ ...data, turn: turnOf(sessionId, data) }, sessionId));
311
- else if (event?.type === 'approval/decided') await dispatch(reducer.approvalDecided(data.id, data.outcome));
348
+ if (event?.type === 'approval/asked') {
349
+ markInteractiveTurn(sessionId, turnOf(sessionId, data), 'approval');
350
+ await dispatch(reducer.approvalAsked({ ...data, turn: turnOf(sessionId, data) }, sessionId));
351
+ } else if (event?.type === 'approval/decided') await dispatch(reducer.approvalDecided(data.id, data.outcome));
312
352
  else if (event?.type === 'turn/end') {
313
353
  const error = pendingErrors.get(`${sessionId}:${data.turn}`);
314
354
  pendingErrors.delete(`${sessionId}:${data.turn}`);
@@ -316,7 +356,12 @@ export async function apply(ctx, config = {}) {
316
356
  // leftover whose decision event was never observed, and one leftover used to shadow every
317
357
  // later toast. Persist the expiry before the completion notification.
318
358
  for (const stale of reducer.expireOpenForSession(sessionId)) await dispatch(stale);
319
- deferCompletion(sessionId, { sessionId, turn: data.turn, reason: data.reason, body: error?.message || String(error || ''), origin: originOf(session) });
359
+ // Plan reviews and execution approvals are intermediate native-idle control gates. An ordinary
360
+ // question may directly finish the task after the user answers, so only the gates are suppressed.
361
+ const interactionKind = consumeInteractiveTurn(sessionId, data.turn);
362
+ if (interactionKind !== 'plan-review' && interactionKind !== 'approval') {
363
+ deferCompletion(sessionId, { sessionId, turn: data.turn, reason: data.reason, body: error?.message || String(error || ''), origin: originOf(session) });
364
+ }
320
365
  }
321
366
  });
322
367
  });
@@ -325,15 +370,13 @@ export async function apply(ctx, config = {}) {
325
370
  // the past is not news, so a rebuild would only re-announce an approval the user can already see in
326
371
  // the DSH UI, and it would do it on every session open.
327
372
  ctx?.on?.('approval/request', (request, next) => { try { /* live reason is non-authoritative */ } catch { diagnostics.eventErrors += 1; } return next(); });
328
- // A goal loop keeps starting rounds after each turn ends, so a completion is not news until the goal
329
- // itself is done. `goal` is omitted from the payload exactly when there is no goal for the session.
373
+ // Older Hosts may not publish agent/status. Keep goal awareness only for that legacy fallback;
374
+ // lifecycle-capable Hosts flush on native `idle`, not when a separate goal bookkeeping event arrives.
330
375
  ctx?.on?.('goal/activation-changed', (payload) => safely(async () => {
331
376
  const sessionId = sessionIdOf(payload?.sessionId) ?? payload?.sessionId;
332
- if (typeof sessionId !== 'string' || sessionId === '') return;
377
+ if (typeof sessionId !== 'string' || sessionId === '' || statusCapable.has(sessionId)) return;
333
378
  if (payload?.goal) {
334
379
  engagedGoals.add(sessionId);
335
- // A goal engaging after a turn ended holds that announcement: the loop is still working, so the
336
- // pending payload waits for the goal to finish instead of firing on the grace timer.
337
380
  const entry = deferredCompletions.get(sessionId);
338
381
  if (entry?.timer) { clearTimeout(entry.timer); entry.timer = null; }
339
382
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idoall/dsh-notify",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "DSH web plugin: in-page task notifications for DeepSeek Harness — enhanced or soft status toasts, a collapsible top-right stack, answer buttons, background-tab attention, and a WebAudio cue that also plays while the page is hidden. Live delivery only: no history, no service worker, no web push, no OS notification matrix.",
6
6
  "main": "./dist/index.js",