@laraveladmin/dsh-stay-awake 0.1.0 → 0.2.0

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,9 +1,30 @@
1
1
  # 变更记录 · Changelog
2
2
 
3
+ ## 0.2.0 — 2026-12-03
4
+
5
+ ### 新功能
6
+
7
+ - **任务结束提示音**:工作段结束时在宿主机器播放提示音。
8
+ - 成功 `Glass` / 失败或中断 `Basso`;支持自定义音频文件与音量(`cordis.patch.yml`)。
9
+ - 一次工作段只响一次(含后台任务、多会话);短于 20 秒的段不响;goal/定时任务等自主轮次不响。
10
+ - 弹层新增「完成提示音」开关与「试听」按钮;开关写入状态文件,重启保持。
11
+ - 宿主端播放(macOS `afplay`、Windows `SystemSounds`、Linux `paplay`),播放失败静默降级。
12
+
13
+ ## 0.1.1 — 2026-12-03
14
+
15
+ ### 修复
16
+
17
+ - npm 包页面上的相对链接(语言切换 `README.en.md`、`LICENSE`、`docs/VERIFICATION.md`)在 npmjs 上解析错误,
18
+ 点击「English」会跳到不存在的 npm 路径;现全部改为 Gitee 绝对地址,中英文文档、许可证与验证记录均可直接打开。
19
+
3
20
  ## 0.1.0 — 2026-12-03
4
21
 
5
22
  首个版本。
6
23
 
24
+ ### 发布
25
+
26
+ - 已发布到 npm:`@laraveladmin/dsh-stay-awake@0.1.0`(2026-12-03)。
27
+
7
28
  ### 功能
8
29
 
9
30
  - **三类活跃源**:运行中的会话(`agent/status`)、手动 `/compact` 的维护期(会话事件 `compaction/start` → `compaction/end`)、后台任务(`ctx.jobs` + 持久事件 `job/registered` / `job/settled`)。
package/README.en.md CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  **A DeepSeek Harness plugin that keeps the machine awake only while unattended work is still running, then releases automatically.**
4
4
 
5
- [简体中文](README.md) · [English](README.en.md) · [Repository](https://gitee.com/laravel-admin/dsh-stay-awake)
5
+ [简体中文](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.md) · [English](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.en.md) · [Repository](https://gitee.com/laravel-admin/dsh-stay-awake)
6
6
 
7
7
  `@laraveladmin/dsh-stay-awake` · macOS / Windows / Linux
8
8
 
9
9
  <p>
10
- <img alt="version" src="https://img.shields.io/badge/version-0.1.0-blue">
10
+ <img alt="version" src="https://img.shields.io/badge/version-0.2.0-blue">
11
11
  <img alt="platform" src="https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-4c6ef5">
12
12
  <img alt="license" src="https://img.shields.io/badge/license-MIT-green">
13
13
  </p>
@@ -30,6 +30,15 @@ Most existing plugins equate "a task" with "a session in the running state". DSH
30
30
 
31
31
  The rule is a pure function: `wanted = enabled && (agents + maintenance + jobs > 0)`. Exactly one system power assertion is held process-wide.
32
32
 
33
+ ## Completion sound
34
+
35
+ A short alert when a task finishes, played on the machine that runs the DSH host — it reaches you even when the window is minimised.
36
+
37
+ - One chime per work segment (from work starting to everything finishing), including background jobs and multiple sessions.
38
+ - `Glass` for success, `Basso` for failures/interrupts.
39
+ - Segments shorter than 20 seconds stay silent; autonomous goal/scheduled rounds stay silent.
40
+ - Toggle and a "Test" button live in the settings panel; sound files, volume and the minimum duration live in `cordis.patch.yml`.
41
+
33
42
  ## Behaviour
34
43
 
35
44
  - **Release debounce** (30s): the last work item ending does not release immediately; a new turn inside the window cancels it.
@@ -54,7 +63,21 @@ The rule is a pure function: `wanted = enabled && (agents + maintenance + jobs >
54
63
 
55
64
  **Requirements**: DSH 0.2.x (Desktop or `dsh web`). The plugin has no third-party runtime dependencies and needs no Node toolchain.
56
65
 
57
- ### Option 1 — install from the DSH UI (recommended)
66
+ Published on npm: [`@laraveladmin/dsh-stay-awake@0.2.0`](https://www.npmjs.com/package/@laraveladmin/dsh-stay-awake)
67
+
68
+ ### Option 1 — install from npm (recommended)
69
+
70
+ Run this in a DSH session:
71
+
72
+ ```text
73
+ plugin_manager action: install_bundle target: @laraveladmin/dsh-stay-awake
74
+ ```
75
+
76
+ Then **reload the session page** (`Cmd + R` on macOS, `Ctrl + R` on Windows); the `☾ Stay awake · …` indicator appears in the composer status bar.
77
+
78
+ ### Option 2 — install from the DSH UI (local source directory)
79
+
80
+ Use this when you want to modify the code or prefer not to use npm:
58
81
 
59
82
  1. Clone the repository:
60
83
 
@@ -65,27 +88,12 @@ The rule is a pure function: `wanted = enabled && (agents + maintenance + jobs >
65
88
  2. Open DSH and go to **Plugins**.
66
89
  3. Choose **Add plugin** and pick the cloned directory (the one containing `package.json`).
67
90
  4. After installation, **reload the session page** (`Cmd + R` on macOS, `Ctrl + R` on Windows).
68
- 5. The `☾ Stay awake · …` indicator appears in the composer status bar.
69
-
70
- ### Option 2 — plugin manager command
71
-
72
- Run this in a DSH session, or use the plugin manager's local-directory entry:
73
-
74
- ```text
75
- plugin_manager action: install_bundle target: /absolute/path/to/dsh-stay-awake
76
- ```
77
-
78
- Once published to npm you can install it by package name:
79
-
80
- ```text
81
- plugin_manager action: install_bundle target: @laraveladmin/dsh-stay-awake
82
- ```
83
91
 
84
92
  ### Option 3 — ask the agent to install it
85
93
 
86
94
  Send this to the agent in DSH:
87
95
 
88
- > Clone https://gitee.com/laravel-admin/dsh-stay-awake on this machine and install it into the current DSH profile.
96
+ > Install @laraveladmin/dsh-stay-awake into the current DSH profile (or clone https://gitee.com/laravel-admin/dsh-stay-awake and install it).
89
97
 
90
98
  ### Post-install checks
91
99
 
@@ -113,6 +121,13 @@ Override the row by id in the profile's `cordis.patch.yml`:
113
121
  reconcileSeconds: 60 # reconciliation interval, 0 = disabled
114
122
  maxMaintenanceMinutes: 120 # longest a maintenance bracket may stay open
115
123
  caffeinatePath: /usr/bin/caffeinate # macOS only, advanced override
124
+ sound: true # completion sound (panel toggle)
125
+ soundOnError: true # different sound for failures
126
+ soundMinSeconds: 20 # stay silent below this duration, 0 = always
127
+ soundOnlyUserTasks: true # ignore autonomous rounds
128
+ soundVolume: 1 # 0-3, macOS/Linux
129
+ successSound: '' # custom completion file (absolute path)
130
+ errorSound: '' # custom failure file
116
131
  ```
117
132
 
118
133
  Invalid values fall back to their defaults with a warning; a bad config never blocks loading.
@@ -134,6 +149,7 @@ Clicking the icon or the "Stay awake" label opens a panel at the bottom of the w
134
149
  |---|---|
135
150
  | Enabled | Turning it off releases the assertion immediately |
136
151
  | Allow display sleep | On = block system sleep only; off = keep the screen on too |
152
+ | Completion sound | One chime when a task ends; the Test button verifies it |
137
153
  | Hold for | 30 min / 2 h / cancel, for temporary keeps |
138
154
  | Status block | Active sources, scope, backend, hold duration, error reason |
139
155
  | Footer | Where advanced options live, source link, version |
@@ -176,7 +192,7 @@ systemd-inhibit --list
176
192
 
177
193
  **What no user-space tool can block**: lid-close sleep, manual sleep, critical-battery sleep, and MDM policies. On macOS a closed lid keeps running only through clamshell mode (power plus an external display). Inside WSL the plugin can only inhibit the distribution, not the Windows host.
178
194
 
179
- **Verification scope**: macOS is the author's real-hardware acceptance platform; see the [verification record](docs/VERIFICATION.md) (Chinese) for per-case evidence. Windows and Linux ship with implementations and unit tests, but their power effect must be confirmed on the corresponding machine. A release note will never present "implemented" as "verified".
195
+ **Verification scope**: macOS is the author's real-hardware acceptance platform; see the [verification record](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/docs/VERIFICATION.md) (Chinese) for per-case evidence. Windows and Linux ship with implementations and unit tests, but their power effect must be confirmed on the corresponding machine. A release note will never present "implemented" as "verified".
180
196
 
181
197
  **Local writes**: exactly one state file, `~/.dsh/plugin-data/dsh-stay-awake/state.json` (the two panel preferences). It does not modify system power plans, request privileges, use the network, or read session content.
182
198
 
@@ -184,7 +200,7 @@ systemd-inhibit --list
184
200
 
185
201
  - The composer indicator follows the active DSH locale, with built-in Simplified Chinese and English; other locales fall back to English.
186
202
  - The plugin manager title and description are localized as well (`locale/zh.json`, `locale/en.json`).
187
- - Repository documentation: [简体中文](README.md) / [English](README.en.md).
203
+ - Repository documentation: [简体中文](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.md) / [English](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.en.md).
188
204
 
189
205
  ## Development
190
206
 
@@ -221,4 +237,4 @@ npm publish # package.json sets publishCo
221
237
 
222
238
  ## License
223
239
 
224
- Released under the [MIT](LICENSE) license: use, modify, redistribute and sell freely, as long as the copyright and permission notice are retained.
240
+ Released under the [MIT](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/LICENSE) license: use, modify, redistribute and sell freely, as long as the copyright and permission notice are retained.
package/README.md CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  **DeepSeek Harness 插件:只在「无人值守但仍需继续的工作」存在时保持机器不休眠,工作结束自动释放。**
4
4
 
5
- [简体中文](README.md) · [English](README.en.md) · [仓库](https://gitee.com/laravel-admin/dsh-stay-awake)
5
+ [简体中文](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.md) · [English](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.en.md) · [仓库](https://gitee.com/laravel-admin/dsh-stay-awake)
6
6
 
7
7
  `@laraveladmin/dsh-stay-awake` · macOS / Windows / Linux
8
8
 
9
9
  <p>
10
- <img alt="version" src="https://img.shields.io/badge/version-0.1.0-blue">
10
+ <img alt="version" src="https://img.shields.io/badge/version-0.2.0-blue">
11
11
  <img alt="platform" src="https://img.shields.io/badge/platform-macOS%20%7C%20Windows%20%7C%20Linux-4c6ef5">
12
12
  <img alt="license" src="https://img.shields.io/badge/license-MIT-green">
13
13
  </p>
@@ -30,6 +30,15 @@ DSH 跑长任务时你离开电脑,系统按空闲策略休眠:进程被挂
30
30
 
31
31
  判定为纯函数:`wanted = enabled && (会话 + 维护期 + 后台任务 > 0)`。全局只持有一个系统电源断言。
32
32
 
33
+ ## 任务结束提示音
34
+
35
+ 任务跑完会响一声,不用盯着屏幕——声音在**运行 DSH 的这台机器**上播放,窗口最小化也听得到。
36
+
37
+ - 一次「工作段」(从有工作到全部结束)只响一次,含后台任务与多会话。
38
+ - 成功用 `Glass`,失败/中断用 `Basso`,不同结果听得出区别。
39
+ - 短于 20 秒的任务不响;goal/定时任务等自主轮次不响,避免连响。
40
+ - 弹层里可开关、可点「试听」;音效/音量/最短时长在 `cordis.patch.yml` 配置。
41
+
33
42
  ## 释放与自愈
34
43
 
35
44
  - **释放防抖**:最后一个工作结束后等 30 秒再释放,避免回合间隙误放;期间来了新工作就取消。
@@ -55,7 +64,21 @@ DSH 跑长任务时你离开电脑,系统按空闲策略休眠:进程被挂
55
64
 
56
65
  **前置条件**:DSH 0.2.x(Desktop 或 `dsh web`)。插件零第三方运行时依赖,不需要 Node 工具链。
57
66
 
58
- ### 方式一:DSH 界面安装(推荐)
67
+ 已发布到 npm:[`@laraveladmin/dsh-stay-awake@0.2.0`](https://www.npmjs.com/package/@laraveladmin/dsh-stay-awake)
68
+
69
+ ### 方式一:从 npm 安装(推荐)
70
+
71
+ 在 DSH 会话里执行:
72
+
73
+ ```text
74
+ plugin_manager action: install_bundle target: @laraveladmin/dsh-stay-awake
75
+ ```
76
+
77
+ 然后**刷新会话页面**(macOS `Cmd + R`,Windows `Ctrl + R`),输入框下方状态栏出现 `☾ 守夜 · …` 即安装成功。
78
+
79
+ ### 方式二:DSH 界面安装(从本地源码目录)
80
+
81
+ 想自己改代码、或暂时不用 npm 时:
59
82
 
60
83
  1. 克隆仓库:
61
84
 
@@ -66,27 +89,12 @@ DSH 跑长任务时你离开电脑,系统按空闲策略休眠:进程被挂
66
89
  2. 打开 DSH,进入 **插件(Plugins)** 页面。
67
90
  3. 点 **添加插件(Add plugin)**,选择克隆下来的目录(必须是含 `package.json` 的那一层)。
68
91
  4. 安装完成后**刷新会话页面**(macOS `Cmd + R`,Windows `Ctrl + R`)。
69
- 5. 输入框下方状态栏出现 `☾ 守夜 · …` 即安装成功。
70
-
71
- ### 方式二:插件管理器命令
72
-
73
- 在 DSH 会话里执行,或使用插件管理器的本地目录安装入口:
74
-
75
- ```text
76
- plugin_manager action: install_bundle target: /absolute/path/to/dsh-stay-awake
77
- ```
78
-
79
- 发布到 npm 之后也可以直接按包名安装:
80
-
81
- ```text
82
- plugin_manager action: install_bundle target: @laraveladmin/dsh-stay-awake
83
- ```
84
92
 
85
93
  ### 方式三:让 AI 帮你装
86
94
 
87
95
  把这句话发给 DSH 里的 AI:
88
96
 
89
- > 帮我把 https://gitee.com/laravel-admin/dsh-stay-awake 克隆到本机,并安装到当前 DSH profile。
97
+ > 帮我把 @laraveladmin/dsh-stay-awake 安装到当前 DSH profile(或从 https://gitee.com/laravel-admin/dsh-stay-awake 克隆后安装)。
90
98
 
91
99
  ### 安装后自检
92
100
 
@@ -114,6 +122,13 @@ plugin_manager action: install_bundle target: @laraveladmin/dsh-stay-awake
114
122
  reconcileSeconds: 60 # 对账间隔,0 = 关闭
115
123
  maxMaintenanceMinutes: 120 # 维护期括号的最长有效期
116
124
  caffeinatePath: /usr/bin/caffeinate # 仅 macOS,高级覆盖
125
+ sound: true # 任务结束提示音(弹层开关)
126
+ soundOnError: true # 失败/中断用不同音效
127
+ soundMinSeconds: 20 # 短于该时长不响,0 = 都响
128
+ soundOnlyUserTasks: true # 只响用户发起的任务,自主轮次不响
129
+ soundVolume: 1 # 0~3,macOS/Linux 生效
130
+ successSound: '' # 自定义完成音文件(绝对路径)
131
+ errorSound: '' # 自定义失败音文件
117
132
  ```
118
133
 
119
134
  非法值会回落到默认值并记一条 warning,不会导致插件加载失败。
@@ -135,6 +150,7 @@ plugin_manager action: install_bundle target: @laraveladmin/dsh-stay-awake
135
150
  |---|---|
136
151
  | 总开关 | 关掉后立即释放断言,不再自动保持 |
137
152
  | 允许屏幕休眠 | 开 = 只防系统休眠;关 = 连屏幕一起保持 |
153
+ | 完成提示音 | 任务结束响一声;旁边「试听」可立即验证 |
138
154
  | 临时保持 | 30 分钟 / 2 小时 / 取消,用于临时不想让机器睡 |
139
155
  | 状态区 | 活跃源、范围、后端、已持续时长、错误原因 |
140
156
  | 底部 | 高级参数在哪改、源码链接、版本号 |
@@ -179,7 +195,7 @@ systemd-inhibit --list
179
195
 
180
196
  **挡不住的**(任何用户态方案都一样):合盖休眠、手动点「睡眠」、低电量强制睡眠、企业 MDM 策略。macOS 合盖时要继续跑,只能靠「插电 + 外接显示器」进入合盖模式。WSL 内只能约束 WSL,管不到 Windows 宿主。
181
197
 
182
- **验证范围**:macOS 为作者真机验收平台(逐条证据见 [验证记录](docs/VERIFICATION.md));Windows / Linux 提供实现与单元测试,电源效果需在对应真机用上面的命令确认。发布说明不会用「已实现」代替「已验证」。
198
+ **验证范围**:macOS 为作者真机验收平台(逐条证据见 [验证记录](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/docs/VERIFICATION.md));Windows / Linux 提供实现与单元测试,电源效果需在对应真机用上面的命令确认。发布说明不会用「已实现」代替「已验证」。
183
199
 
184
200
  **本地写入**:只写一个状态文件 `~/.dsh/plugin-data/dsh-stay-awake/state.json`(弹层里的两个偏好),不碰系统电源计划、不申请提权、不联网、不读取会话内容。
185
201
 
@@ -187,7 +203,7 @@ systemd-inhibit --list
187
203
 
188
204
  - 状态栏指示器跟随 DSH 当前语言,内置简体中文与英文,其余语言回退到英文。
189
205
  - 插件管理器中的标题与说明同样提供中英文(`locale/zh.json`、`locale/en.json`)。
190
- - 仓库文档:[简体中文](README.md) / [English](README.en.md)。
206
+ - 仓库文档:[简体中文](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.md) / [English](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/README.en.md)。
191
207
 
192
208
  ## 开发
193
209
 
@@ -224,4 +240,4 @@ npm publish # package.json 已配置 publ
224
240
 
225
241
  ## 许可证
226
242
 
227
- 本项目以 [MIT](LICENSE) 协议开源:可自由使用、修改、分发与商用,保留版权与许可声明即可。
243
+ 本项目以 [MIT](https://gitee.com/laravel-admin/dsh-stay-awake/blob/main/LICENSE) 协议开源:可自由使用、修改、分发与商用,保留版权与许可声明即可。
package/client.js CHANGED
@@ -59,6 +59,8 @@ window.__ModuleLoader__.load({
59
59
  'panel.hold30': '30 分钟',
60
60
  'panel.hold120': '2 小时',
61
61
  'panel.holdCancel': '取消',
62
+ 'panel.sound': '完成提示音',
63
+ 'panel.testSound': '试听',
62
64
  'panel.holdDisabled': '总开关关闭时无法临时保持',
63
65
  'panel.holdLeft': '剩余',
64
66
  'panel.saved': '已保存',
@@ -104,6 +106,8 @@ window.__ModuleLoader__.load({
104
106
  'panel.hold30': '30 min',
105
107
  'panel.hold120': '2 h',
106
108
  'panel.holdCancel': 'Cancel',
109
+ 'panel.sound': 'Completion sound',
110
+ 'panel.testSound': 'Test',
107
111
  'panel.holdDisabled': 'Enable the plugin first to hold',
108
112
  'panel.holdLeft': 'left',
109
113
  'panel.saved': 'Saved',
@@ -327,6 +331,7 @@ window.__ModuleLoader__.load({
327
331
  const allowDisplaySleep = (status === null ? 'system' : status.scope) === 'system'
328
332
  const busy = snapshot.busy === true
329
333
  const staleHost = status !== null && status.protocol !== 2
334
+ const soundOn = status === null ? true : status.sound !== false
330
335
  const counts = status && status.counts ? status.counts : { agents: 0, maintenance: 0, jobs: 0 }
331
336
  const holdLeft = status && typeof status.manualUntil === 'number' && status.manualUntil > Date.now()
332
337
  ? status.manualUntil - Date.now()
@@ -425,6 +430,26 @@ window.__ModuleLoader__.load({
425
430
  onClick: () => act({ action: 'set-scope', scope: allowDisplaySleep ? 'display' : 'system' }),
426
431
  }),
427
432
  ),
433
+ h(
434
+ 'div',
435
+ { className: 'dsa-row' },
436
+ h('span', { className: 'dsa-grow' }, t('panel.sound')),
437
+ h('button', {
438
+ type: 'button',
439
+ className: 'dsa-button',
440
+ disabled: busy || unreachable,
441
+ onClick: () => act({ action: 'test-sound' }),
442
+ }, t('panel.testSound')),
443
+ h('button', {
444
+ type: 'button',
445
+ className: 'dsa-switch',
446
+ role: 'switch',
447
+ 'aria-checked': soundOn,
448
+ 'aria-label': t('panel.sound'),
449
+ disabled: busy || unreachable,
450
+ onClick: () => act({ action: 'set-sound', enabled: !soundOn }),
451
+ }),
452
+ ),
428
453
  ),
429
454
  h(
430
455
  'div',
@@ -101,6 +101,7 @@ DSH 执行长任务(长构建、训练、下载、批量重构、多轮自主
101
101
  | 断言 | 操作系统层面阻止休眠的持有物(caffeinate 子进程、Windows holder 进程、systemd-inhibit 会话) |
102
102
  | 范围 | `system`(只防系统休眠,允许息屏)或 `display`(连屏幕一起防) |
103
103
  | 防抖窗口 | 工作信号消失后延迟释放的时间窗,用于避免回合间隙误释放 |
104
+ | 工作段 | 从「有工作」到「无工作」的一段连续区间;提示音按工作段触发,一段只响一次 |
104
105
 
105
106
  ---
106
107
 
@@ -211,12 +212,19 @@ wanted = config.enabled && hasWork
211
212
  | `batteryPolicy` | `'always' \| 'ac'` | `'always'` | `ac` = 仅插电时持有 |
212
213
  | `minBatteryPercent` | number | `0` | 低于该电量释放,0 = 不限制(P2) |
213
214
  | `caffeinatePath` | string | `/usr/bin/caffeinate` | 高级覆盖 |
215
+ | `sound` | boolean | `true` | 任务结束提示音(弹层开关) |
216
+ | `soundOnError` | boolean | `true` | 失败/中断用不同音效 |
217
+ | `soundMinSeconds` | number | `20` | 短于该时长不响,0 = 都响 |
218
+ | `soundOnlyUserTasks` | boolean | `true` | 只响用户发起的任务,自主轮次不响 |
219
+ | `successSound` | string | 平台默认 | 自定义完成音文件(绝对路径) |
220
+ | `errorSound` | string | 平台默认 | 自定义失败音文件 |
221
+ | `soundVolume` | number | `1` | 0~3,macOS/Linux 生效;Windows 不支持 |
214
222
 
215
223
  配置经 DSH `Config`(Schemastery)在 `cordis.patch.yml` 覆盖;UI 侧的临时开关(P1)写入独立状态文件,不污染 patch 层。
216
224
 
217
225
  **FR-6.1** Loader 行 id 固定为 `stay-awake`,包名 `@laraveladmin/dsh-stay-awake`。用户 patch 层按 id 覆盖 `config`,插件升级不丢配置;id 一经发布不得更改。
218
226
 
219
- **FR-6.2** 状态文件固定为 `~/.dsh/plugin-data/dsh-stay-awake/state.json`(目录名去掉 npm scope,避免路径分隔符);只存 UI 的临时开关与手动保持截止时间,**配置永远以 patch 层为准**,不得把配置回写进状态文件。
227
+ **FR-6.2** 状态文件固定为 `~/.dsh/plugin-data/dsh-stay-awake/state.json`(目录名去掉 npm scope,避免路径分隔符);只存 UI 可改的偏好(`enabled`、`scope`、`sound`),**其余配置以 patch 层为准**,不得把配置回写进状态文件。
220
228
 
221
229
  **FR-6.3** 配置校验:非法值(负延时、越界枚举、非数字)回落到默认值并记一条 warning;任何配置错误都不得导致拒绝加载。
222
230
 
@@ -239,6 +247,38 @@ wanted = config.enabled && hasWork
239
247
  | FR-8.4 | 不提供设置面板;设置走 `Config`(避免双份状态源) |
240
248
  | FR-8.5 | 指示器状态必须来自 Host(经同源 fetch 路由),不得在客户端自行推断 |
241
249
 
250
+ ### FR-10 任务结束提示音
251
+
252
+ 目标:用户离开电脑时,任务结束能"听见",不必回来看屏幕。
253
+
254
+ | 序号 | 规则 |
255
+ |---|---|
256
+ | FR-10.1 | 触发点为**全局工作段结束边沿**:`hasWork` 由 true 变 false 的那一刻(与电源断言的判定同源),一次工作段只响一次 |
257
+ | FR-10.2 | 工作段包含会话、维护期、后台任务;因此「后台构建跑完」会响,「会话先空闲但后台仍在跑」不响 |
258
+ | FR-10.3 | 多会话并发只在全部结束时响一次;子代理 / workflow 子任务不单独响 |
259
+ | FR-10.4 | 仅响**用户发起的任务**:连接 `session/event` 的 `user/message` 置位待响标记,工作段结束时消费;goal/定时任务等自主轮次不响(`soundOnlyUserTasks`,默认 true) |
260
+ | FR-10.5 | 最短任务时长 `soundMinSeconds`(默认 20 秒):短于该时长的工作段不响,避免快速问答打断 |
261
+ | FR-10.6 | 成功与失败区分音效:工作段内最后一次 `turn/end` 的 `reason.kind ∈ {error, aborted, interrupted, blocked}` 用错误音,否则用完成音 |
262
+ | FR-10.7 | **宿主端播放**(不依赖浏览器自动播放策略,DSH 窗口最小化/后台也能响):macOS `afplay`、Windows `System.Media.SystemSounds`、Linux `paplay`(不可用时静默降级) |
263
+ | FR-10.8 | 播放必须异步、不阻塞事件循环;子进程 `unref`,5 秒未结束则忽略;同一秒内最多播放一次 |
264
+ | FR-10.9 | 播放失败(无播放器、无音频文件、静音)只记日志,不弹错、不影响其它功能 |
265
+ | FR-10.10 | 支持试听:弹层「试听」调用宿主立即播放一次完成音,用于确认设备与音量 |
266
+ | FR-10.11 | 弹层只放「完成提示音」开关;音效文件、音量、最短时长、是否只响用户任务走 `cordis.patch.yml` |
267
+ | FR-10.12 | `sound` 开关与 `enabled`/`scope` 一样持久化到状态文件,重启后保持 |
268
+
269
+ | FR-10.13 | 插件总开关 `enabled=false` 时不响(用户明确关掉了整套防护) |
270
+ | FR-10.14 | 「试听」不受 `sound` 开关与 `enabled` 限制,任何时候都能验证设备与音量 |
271
+
272
+ 平台默认音效:
273
+
274
+ | 平台 | 完成音 | 失败音 | 说明 |
275
+ |---|---|---|---|
276
+ | macOS | `/System/Library/Sounds/Glass.aiff` | `/System/Library/Sounds/Basso.aiff` | 播放器 `afplay`,支持 `-v` 音量 |
277
+ | Windows | `SystemSounds.Asterisk` | `SystemSounds.Hand` | PowerShell 调用,无音量参数 |
278
+ | Linux | `/usr/share/sounds/freedesktop/stereo/complete.oga` | `dialog-error.oga` | `paplay`;文件缺失则静默 |
279
+
280
+ **边界说明**:系统静音、耳机未佩戴、音频设备切走时用户听不到,插件无法感知;DSH 跑在远程主机时声音在远端播放(本插件只作用于运行 Host 的机器)。
281
+
242
282
  ### FR-9 生命周期
243
283
 
244
284
  | 序号 | 规则 |
@@ -273,6 +313,11 @@ wanted = config.enabled && hasWork
273
313
  | 17 | 持有中关闭总开关,会话仍在跑 | 无(`enabled=false`) | 立即释放,不等防抖 | P0 | AC-13 |
274
314
  | 18 | 同时装了其它防休眠插件 | 两个断言并存 | 互不干扰、不误杀对方进程 | P1 | AC-14 |
275
315
  | 19 | 工作流脚本的纯计算阶段(无活跃 agent) | 无信号 | 可能释放(已知盲区,文档披露) | — | 已知限制 |
316
+ | 20 | 用户发起的任务跑完(≥20s) | 工作段结束 | 响完成音 1 次 | P0 | AC-15 |
317
+ | 21 | 任务失败/中断 | 工作段结束 | 响失败音 | P0 | AC-16 |
318
+ | 22 | 关闭提示音开关 | — | 不响 | P0 | AC-17 |
319
+ | 23 | 后台构建跑完(会话早已空闲) | 工作段结束 | 响完成音 | P0 | AC-18 |
320
+ | 24 | goal/定时任务自主轮次结束 | 工作段结束 | 不响(`soundOnlyUserTasks`) | P0 | AC-19 |
276
321
 
277
322
  ---
278
323
 
@@ -389,6 +434,12 @@ Idle ──wanted──▶ Holding ──!wanted──▶ Releasing ──超时
389
434
  | AC-12 | 卸载 | 插件管理器中卸载 | 断言立即消失;无残留进程 |
390
435
  | AC-13 | 持有中 | 关闭 `enabled`(会话仍在跑) | ≤ 2s 内释放,不走防抖 |
391
436
  | AC-14 | 与其它防休眠插件共存 | 两者同时持有 | 断言并存、互不影响;卸载任一方不误杀对方进程 |
437
+ | AC-15 | 提示音开启 | 用户发起的 ≥20 秒任务跑完 | 听到一次完成音,控制台/日志无异常 |
438
+ | AC-16 | 提示音开启 | 任务中按停止或触发错误结束 | 听到失败音(与完成音不同) |
439
+ | AC-17 | 关闭弹层「完成提示音」 | 跑完一个任务 | 没有声音 |
440
+ | AC-18 | 提示音开启 | `run_in_background` 的 30 秒任务跑完 | 响一次,且不早于后台进程结束 |
441
+ | AC-19 | 提示音开启,`soundOnlyUserTasks` | 自主轮次(goal)结束 | 不响 |
442
+ | AC-20 | 无播放器/静音环境 | 任务结束 | 无异常抛出,插件其余功能正常 |
392
443
 
393
444
  平台归属:**AC-1 ~ AC-14 在 macOS 上由作者逐条真机验收**;Windows / Linux 先以单元测试与命令生成验证,真机验收由使用者或 CI 补充(见 §14.3)。
394
445
 
@@ -461,7 +512,7 @@ pgrep -fl "caffeinate -i -w"
461
512
 
462
513
  ---
463
514
 
464
- ## 15. v0.1.0 实现与需求的差异(2026-12-03)
515
+ ## 15. 实现与需求的差异(截至 0.2.0)
465
516
 
466
517
  | 需求 | 状态 | 说明 |
467
518
  |---|---|---|
@@ -469,14 +520,15 @@ pgrep -fl "caffeinate -i -w"
469
520
  | FR-1.2 维护期 | ✅ 实现,逻辑测试覆盖 | 事件接线由 `test/wiring.test.js` 验证;真机需用户手动 `/compact` 观察 |
470
521
  | FR-1.3 后台任务 | ✅ 实现,逻辑测试覆盖 | `ctx.jobs` 事件 + `jobs.list(sessionId)` 对账;真机需用户在 agent idle 时跑后台任务观察 |
471
522
  | FR-1.4 计划任务 | ❌ 未实现 | 仍为 P2 |
523
+ | FR-10 任务结束提示音 | ✅ 实现 | 工作段结束边沿触发、成功/失败区分、最短时长、仅用户任务、宿主端播放、弹层开关 + 试听;开关持久化 |
472
524
  | FR-2 释放判定 | ✅ 实现并真机验证 | 防抖释放、竞争重算、禁用立即释放 |
473
525
  | FR-3 三平台后端 | macOS ✅ 真机;Windows / Linux ✅ 实现 + 单测 | Windows/Linux 电源效果未真机验证 |
474
526
  | FR-4.2 `scope` 热切换 | ✅ 实现 | 弹层切换时先起新断言再停旧的;改 `cordis.patch.yml` 的 scope 仍需要插件重载 |
475
527
  | FR-5 兜底与自愈 | ✅ 实现并真机验证 | 失败退避在真机用 `kill` 断言进程验证过 |
476
528
  | FR-6 配置 | ✅ 除 `batteryPolicy` / `minBatteryPercent` | 两项未实现,也未暴露,避免"配置了却不生效" |
477
- | FR-6.2 状态文件 | ✅ 实现 | `~/.dsh/plugin-data/dsh-stay-awake/state.json`,只存弹层里的 enabled/scope;原子写(tmp+rename),损坏或非法值回落默认并记 warning |
529
+ | FR-6.2 状态文件 | ✅ 实现 | `~/.dsh/plugin-data/dsh-stay-awake/state.json`,只存弹层里的 enabled/scope/sound;原子写(tmp+rename),损坏或非法值回落默认并记 warning |
478
530
  | FR-7 可观测 | 🟡 部分 | 有内存环形日志与 `/api/stay-awake` 状态;无日志导出 |
479
- | FR-8 UI | ✅ 可交互指示器 + 设置弹层(中英双语) | 点击状态栏「守夜」打开 `shell.overlay` 弹层:总开关、允许屏幕休眠、临时保持(30 分钟 / 2 小时 / 取消)、状态详情、源码链接;面板与指示器共享单例状态,一个页面只有一个轮询 |
531
+ | FR-8 UI | ✅ 可交互指示器 + 设置弹层(中英双语) | 点击状态栏「守夜」打开 `shell.overlay` 弹层:总开关、允许屏幕休眠、完成提示音(含试听)、临时保持(30 分钟 / 2 小时 / 取消)、状态详情、源码链接;面板与指示器共享单例状态,一个页面只有一个轮询 |
480
532
  | FR-9 生命周期 | ✅ 实现并真机验证 | 禁用即释放、重新启用即重取、宿主 SIGKILL 不残留 |
481
533
 
482
534
  **配置优先级**:`cordis.patch.yml` 提供默认值,弹层改过的 `enabled` / `scope` 以状态文件为准;其余参数(防抖、兜底时长、对账间隔等)只能改 patch。
@@ -91,9 +91,24 @@
91
91
  - 把 tarball 解包后用假 DSH 上下文跑了一次冒烟:`start()` 能正常订阅事件并在会话 running 时持有恰好 1 个断言(`SMOKE OK`)。
92
92
  - npm 上 `@laraveladmin/dsh-stay-awake` 尚不存在(404)。
93
93
  - 已确认发布账号 `laraveladmin.cn` **同时拥有 `@laraveladmin` 与 `qlzt` 两个 org 的 owner 权限**,包名与作用域均无问题。
94
- - 发布时 npm 拒绝:`E403 Two-factor authentication or granular access token with bypass 2fa enabled is required`。账号开启了 2FA,`npm login` 的会话 token 不允许发布;需要「带 bypass 2FA 的 granular access token」或每次发布提供一次性验证码。
94
+ - 账号开启 2FA,`npm login` 的会话 token 不能发布;最终使用**勾选了 Bypass 2FA 的 granular access token** 完成发布。
95
+ - **已发布**:`@laraveladmin/dsh-stay-awake@0.1.0`,dist-tag `latest`,`dist.shasum = c604252dc9ebaf54a0ddaae9d6f5b1768e47b66a`;从 npm 拉回的 tarball sha1 与之一致,解包后冒烟通过(SMOKE OK)。
96
+ - 发布接口返回 202「processing」,注册表约 **3.5 分钟**后才可读取(期间 `npm view` 返回 404,属正常传播延迟,与网络/代理无关)。
97
+ - 包上存在一个 `0.0.0-stage` 占位版本(发布流程产生),`latest` 指向 0.1.0、不影响安装;npm 禁止 bypass-2FA token 执行 unpublish,需带 2FA 的手动操作才能清理。
95
98
  - README 中的图片已改为 Gitee raw 绝对地址,保证 npm 包页面上也能正常显示(npmjs 不解析仓库相对路径)。
96
99
 
100
+ ## 0.2.0 任务结束提示音(2026-12-03)
101
+
102
+ - 自动化测试:75 个单测/接线测试(新增 19 项),覆盖
103
+ - 播放命令生成:macOS `afplay`(Glass/Basso、音量、自定义文件)、Windows `SystemSounds`、Linux `paplay`、不支持平台返回 null;
104
+ - 播放器:1 秒节流、spawn 抛错静默返回 false、不支持平台不 spawn;
105
+ - 接线:用户任务结束响一次、自主轮次不响、失败回合用错误音、关闭开关不响、短于 `soundMinSeconds` 不响;
106
+ - 配置/状态/路由:新增 sound 字段的默认值、钳制、持久化与 `set-sound` / `test-sound` 动作。
107
+ - 真机(macOS):`createSound().play('success')` 返回 true,系统中出现
108
+ `64593 /usr/bin/afplay /System/Library/Sounds/Glass.aiff` 进程,说明命令拼装、系统音效文件与调度链路可用;
109
+ 实际能否听见取决于音量与音频输出设备(用户确认)。
110
+ - 未验证:Windows `SystemSounds` 与 Linux `paplay` 未在真机验证;新开关在亮/暗主题下的观感需目视确认。
111
+
97
112
  ## 未验证(明确记录,不代替验证)
98
113
 
99
114
  | ID / 项 | 原因 | 何时可验 |
@@ -1,4 +1,4 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 380 356" width="380" height="356" role="img" aria-label="设置弹层示意">
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 380 376" width="380" height="376" role="img" aria-label="设置弹层示意">
2
2
  <style>
3
3
  .bg{fill:#eef0f3}
4
4
  .panel{fill:#ffffff}
@@ -12,8 +12,8 @@
12
12
  .btntext{font-size:11px;fill:#3c4149}
13
13
  </style>
14
14
 
15
- <rect class="bg" width="380" height="356"/>
16
- <rect class="panel" x="10" y="10" width="360" height="336" rx="12"/>
15
+ <rect class="bg" width="380" height="376"/>
16
+ <rect class="panel" x="10" y="10" width="360" height="356" rx="12"/>
17
17
 
18
18
  <!-- header: same status line as the collapsed indicator -->
19
19
  <g transform="translate(24,26)">
@@ -34,32 +34,38 @@
34
34
 
35
35
  <!-- toggles -->
36
36
  <g class="t">
37
- <text class="label" x="24" y="186">总开关</text>
38
- <rect x="320" y="174" width="34" height="18" rx="9" fill="#22c55e"/>
39
- <circle cx="345" cy="183" r="6" fill="#ffffff"/>
37
+ <text class="label" x="24" y="182">总开关</text>
38
+ <rect x="320" y="170" width="34" height="18" rx="9" fill="#22c55e"/>
39
+ <circle cx="345" cy="179" r="6" fill="#ffffff"/>
40
40
 
41
- <text class="label" x="24" y="212">允许屏幕休眠</text>
42
- <text class="sub" x="24" y="226">只防系统休眠,屏幕按系统设置熄灭</text>
43
- <rect x="320" y="200" width="34" height="18" rx="9" fill="#22c55e"/>
44
- <circle cx="345" cy="209" r="6" fill="#ffffff"/>
41
+ <text class="label" x="24" y="208">允许屏幕休眠</text>
42
+ <text class="sub" x="24" y="222">只防系统休眠,屏幕按系统设置熄灭</text>
43
+ <rect x="320" y="196" width="34" height="18" rx="9" fill="#22c55e"/>
44
+ <circle cx="345" cy="205" r="6" fill="#ffffff"/>
45
+
46
+ <text class="label" x="24" y="246">完成提示音</text>
47
+ <rect class="btn" x="244" y="233" width="60" height="22" rx="8"/>
48
+ <text class="btntext" x="274" y="248" text-anchor="middle">试听</text>
49
+ <rect x="320" y="234" width="34" height="18" rx="9" fill="#22c55e"/>
50
+ <circle cx="345" cy="243" r="6" fill="#ffffff"/>
45
51
  </g>
46
52
 
47
53
  <!-- hold row -->
48
54
  <g class="t">
49
- <text class="sub" x="24" y="256">临时保持</text>
50
- <rect class="btn" x="24" y="264" width="64" height="22" rx="8"/>
51
- <text class="btntext" x="56" y="279" text-anchor="middle">30 分钟</text>
52
- <rect class="btn" x="94" y="264" width="58" height="22" rx="8"/>
53
- <text class="btntext" x="123" y="279" text-anchor="middle">2 小时</text>
54
- <rect class="btn" x="158" y="264" width="50" height="22" rx="8"/>
55
- <text class="btntext" x="183" y="279" text-anchor="middle">取消</text>
55
+ <text class="sub" x="24" y="274">临时保持</text>
56
+ <rect class="btn" x="24" y="282" width="64" height="22" rx="8"/>
57
+ <text class="btntext" x="56" y="297" text-anchor="middle">30 分钟</text>
58
+ <rect class="btn" x="94" y="282" width="58" height="22" rx="8"/>
59
+ <text class="btntext" x="123" y="297" text-anchor="middle">2 小时</text>
60
+ <rect class="btn" x="158" y="282" width="50" height="22" rx="8"/>
61
+ <text class="btntext" x="183" y="297" text-anchor="middle">取消</text>
56
62
  </g>
57
63
 
58
64
  <!-- footer: advanced hint + repo icon + npm version -->
59
65
  <g class="t">
60
- <text class="sub" x="24" y="316">防抖、兜底时长等高级参数在 cordis.patch.yml 中配置</text>
61
- <path d="M306 306 l-3.4 3.6 3.4 3.6 M313 306 l3.4 3.6 -3.4 3.6"
66
+ <text class="sub" x="24" y="332">防抖、兜底时长、音效等高级参数在 cordis.patch.yml 中配置</text>
67
+ <path d="M306 322 l-3.4 3.6 3.4 3.6 M313 322 l3.4 3.6 -3.4 3.6"
62
68
  fill="none" stroke="#6b7280" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
63
- <text class="sub" x="322" y="316" fill="#6b7280">v0.1.0</text>
69
+ <text class="sub" x="322" y="332" fill="#6b7280">v0.2.0</text>
64
70
  </g>
65
71
  </svg>
package/index.js CHANGED
@@ -21,6 +21,7 @@ import { createLog } from './lib/log.js'
21
21
  import { backendName, verifyCommand } from './lib/platform.js'
22
22
  import { createPower } from './lib/power.js'
23
23
  import { createStatusHandler } from './lib/server.js'
24
+ import { createSound } from './lib/sound.js'
24
25
  import { defaultStatePath, loadState, saveState } from './lib/state.js'
25
26
 
26
27
  const ROUTE = '/api/stay-awake'
@@ -48,7 +49,7 @@ export function apply(ctx, rawConfig) {
48
49
  *
49
50
  * @param {import('@deepseek-ai/cordis').Context} ctx
50
51
  * @param {Record<string, unknown> | undefined} rawConfig
51
- * @param {{ power?: object, platform?: string, statePath?: string | false, now?: () => number, setTimer?: Function, clearTimer?: Function }} deps
52
+ * @param {{ power?: object, sound?: object, platform?: string, statePath?: string | false, now?: () => number, setTimer?: Function, clearTimer?: Function }} deps
52
53
  */
53
54
  export function start(ctx, rawConfig, deps = {}) {
54
55
  const normalized = normalizeConfig(rawConfig)
@@ -64,7 +65,7 @@ export function start(ctx, rawConfig, deps = {}) {
64
65
 
65
66
  const persist = () => {
66
67
  if (deps.statePath === false) return
67
- const result = saveState(statePath, { enabled: config.enabled, scope: config.scope })
68
+ const result = saveState(statePath, { enabled: config.enabled, scope: config.scope, sound: config.sound })
68
69
  if (!result.ok) log.warn(`stay-awake: could not persist settings: ${result.error}`)
69
70
  }
70
71
 
@@ -73,6 +74,8 @@ export function start(ctx, rawConfig, deps = {}) {
73
74
  const supported = backend !== null
74
75
 
75
76
  const activity = createActivity()
77
+ const sound = deps.sound ?? createSound({ platform, config, log })
78
+ const clockNow = deps.now ?? Date.now
76
79
  const power = deps.power ?? createPower({ platform, config, log })
77
80
  const controller = createController({
78
81
  config,
@@ -84,7 +87,39 @@ export function start(ctx, rawConfig, deps = {}) {
84
87
  clearTimer: deps.clearTimer,
85
88
  })
86
89
 
87
- const sync = () => controller.update(activity.counts(config))
90
+ // ---- work-segment edges drive the completion sound ----
91
+ let wasWorking = false
92
+ let workStartedAt = 0
93
+ let pendingUserSound = false
94
+ let lastOutcome = 'ok'
95
+ const SOUND_ERROR_KINDS = new Set(['error', 'aborted', 'interrupted', 'blocked'])
96
+
97
+ function maybeRing(durationMs) {
98
+ try {
99
+ if (!config.enabled || !config.sound) return
100
+ if (config.soundOnlyUserTasks && !pendingUserSound) return
101
+ if (config.soundMinSeconds > 0 && durationMs < config.soundMinSeconds * 1000) return
102
+ const kind = config.soundOnError && lastOutcome === 'error' ? 'error' : 'success'
103
+ sound.play(kind)
104
+ } catch (error) {
105
+ log.warn(`stay-awake: notification sound failed: ${describe(error)}`)
106
+ }
107
+ }
108
+
109
+ const sync = () => {
110
+ const working = activity.hasWork(config)
111
+ if (working && !wasWorking) {
112
+ workStartedAt = clockNow()
113
+ lastOutcome = 'ok'
114
+ }
115
+ if (!working && wasWorking) {
116
+ maybeRing(clockNow() - workStartedAt)
117
+ pendingUserSound = false
118
+ lastOutcome = 'ok'
119
+ }
120
+ wasWorking = working
121
+ controller.update(activity.counts(config))
122
+ }
88
123
 
89
124
  if (!supported) {
90
125
  log.warn(`stay-awake: no power backend on "${platform}"; the plugin is a no-op here`)
@@ -114,6 +149,14 @@ export function start(ctx, rawConfig, deps = {}) {
114
149
  sync()
115
150
  }),
116
151
  ctx.on('session/event', (session, event) => {
152
+ if (event?.type === 'user/message') {
153
+ pendingUserSound = true
154
+ return
155
+ }
156
+ if (event?.type === 'turn/end') {
157
+ if (SOUND_ERROR_KINDS.has(event.data?.reason?.kind)) lastOutcome = 'error'
158
+ return
159
+ }
117
160
  if (config.includeMaintenance !== true) return
118
161
  if (event?.type === 'compaction/start') {
119
162
  activity.openMaintenance(session.id, event.data?.compactionId)
@@ -206,6 +249,7 @@ export function start(ctx, rawConfig, deps = {}) {
206
249
  const handler = createStatusHandler({
207
250
  controller,
208
251
  activity,
252
+ sound,
209
253
  config,
210
254
  platform,
211
255
  version: VERSION,
package/lib/config.js CHANGED
@@ -18,6 +18,13 @@ export const DEFAULTS = Object.freeze({
18
18
  reconcileSeconds: 60,
19
19
  maxMaintenanceMinutes: 120,
20
20
  caffeinatePath: '/usr/bin/caffeinate',
21
+ sound: true,
22
+ soundOnError: true,
23
+ soundMinSeconds: 20,
24
+ soundOnlyUserTasks: true,
25
+ successSound: '',
26
+ errorSound: '',
27
+ soundVolume: 1,
21
28
  })
22
29
 
23
30
  const SCOPES = new Set(['system', 'display'])
@@ -32,6 +39,7 @@ export function applyState(config, state) {
32
39
  const next = { ...config }
33
40
  if (typeof state?.enabled === 'boolean') next.enabled = state.enabled
34
41
  if (SCOPES.has(state?.scope)) next.scope = state.scope
42
+ if (typeof state?.sound === 'boolean') next.sound = state.sound
35
43
  return next
36
44
  }
37
45
 
@@ -50,6 +58,10 @@ function asPath(value, fallback) {
50
58
  return typeof value === 'string' && value.trim() !== '' ? value.trim() : fallback
51
59
  }
52
60
 
61
+ function asOptionalPath(value) {
62
+ return typeof value === 'string' ? value.trim() : ''
63
+ }
64
+
53
65
  /**
54
66
  * @param {Record<string, unknown> | undefined} raw
55
67
  * @returns {{ config: typeof DEFAULTS, warnings: string[] }}
@@ -68,6 +80,13 @@ export function normalizeConfig(raw) {
68
80
  reconcileSeconds: asNumber(input.reconcileSeconds, DEFAULTS.reconcileSeconds, { min: 0, max: 3_600 }),
69
81
  maxMaintenanceMinutes: asNumber(input.maxMaintenanceMinutes, DEFAULTS.maxMaintenanceMinutes, { min: 1, max: 24 * 60 }),
70
82
  caffeinatePath: asPath(input.caffeinatePath, DEFAULTS.caffeinatePath),
83
+ sound: asBoolean(input.sound, DEFAULTS.sound),
84
+ soundOnError: asBoolean(input.soundOnError, DEFAULTS.soundOnError),
85
+ soundMinSeconds: asNumber(input.soundMinSeconds, DEFAULTS.soundMinSeconds, { min: 0, max: 3_600 }),
86
+ soundOnlyUserTasks: asBoolean(input.soundOnlyUserTasks, DEFAULTS.soundOnlyUserTasks),
87
+ successSound: asOptionalPath(input.successSound),
88
+ errorSound: asOptionalPath(input.errorSound),
89
+ soundVolume: asNumber(input.soundVolume, DEFAULTS.soundVolume, { min: 0, max: 3 }),
71
90
  }
72
91
 
73
92
  for (const key of Object.keys(config)) {
package/lib/server.js CHANGED
@@ -3,7 +3,7 @@
3
3
  const MAX_BODY_BYTES = 4096
4
4
  const SCOPES = new Set(['system', 'display'])
5
5
 
6
- export function createStatusHandler({ controller, activity, config, platform, version, backend, verify, onChange }) {
6
+ export function createStatusHandler({ controller, activity, sound, config, platform, version, backend, verify, onChange }) {
7
7
  return async function handle(request) {
8
8
  try {
9
9
  if (request.method === 'GET') {
@@ -44,6 +44,14 @@ export function createStatusHandler({ controller, activity, config, platform, ve
44
44
  controller.configure({ scope: body.scope })
45
45
  notify(onChange)
46
46
  break
47
+ case 'set-sound':
48
+ if (typeof body.enabled !== 'boolean') return json({ error: 'invalid-body' }, 400)
49
+ config.sound = body.enabled
50
+ notify(onChange)
51
+ break
52
+ case 'test-sound':
53
+ if (typeof sound?.play === 'function') sound.play('success')
54
+ break
47
55
  default:
48
56
  return json({ error: 'invalid-action' }, 400)
49
57
  }
@@ -75,6 +83,8 @@ function payload({ controller, activity, config, platform, version, backend, ver
75
83
  scope: config.scope,
76
84
  releaseDelayMs: config.releaseDelayMs,
77
85
  maxHoldHours: config.maxHoldHours,
86
+ sound: config.sound,
87
+ soundMinSeconds: config.soundMinSeconds,
78
88
  counts: activity.counts(config),
79
89
  ...controller.status(),
80
90
  }
package/lib/sound.js ADDED
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Host-side completion sound.
3
+ *
4
+ * Plays on the machine that runs the DSH host, so the alert still arrives when
5
+ * the window is minimised or behind other apps (a browser-side player would be
6
+ * subject to autoplay policies and background throttling).
7
+ *
8
+ * Every failure path is silent: a missing player, a missing audio file or a
9
+ * muted system must never affect the plugin's actual job.
10
+ */
11
+
12
+ import { spawn as nodeSpawn } from 'node:child_process'
13
+
14
+ const MAC_SUCCESS = '/System/Library/Sounds/Glass.aiff'
15
+ const MAC_ERROR = '/System/Library/Sounds/Basso.aiff'
16
+ const LINUX_SUCCESS = '/usr/share/sounds/freedesktop/stereo/complete.oga'
17
+ const LINUX_ERROR = '/usr/share/sounds/freedesktop/stereo/dialog-error.oga'
18
+
19
+ /** @returns {{ command: string, args: string[] } | null} */
20
+ export function buildSoundCommand({ platform, kind = 'success', config = {} }) {
21
+ const isError = kind === 'error'
22
+ const volume = Number(config.soundVolume)
23
+
24
+ if (platform === 'darwin') {
25
+ const file = isError
26
+ ? config.errorSound || MAC_ERROR
27
+ : config.successSound || MAC_SUCCESS
28
+ const args = [file]
29
+ if (Number.isFinite(volume) && volume > 0 && volume !== 1) args.push('-v', String(volume))
30
+ return { command: '/usr/bin/afplay', args }
31
+ }
32
+
33
+ if (platform === 'win32') {
34
+ const sound = isError ? 'Hand' : 'Asterisk'
35
+ return {
36
+ command: 'powershell.exe',
37
+ args: ['-NoProfile', '-NonInteractive', '-Command', `[System.Media.SystemSounds]::${sound}.Play()`],
38
+ }
39
+ }
40
+
41
+ if (platform === 'linux') {
42
+ const file = isError
43
+ ? config.errorSound || LINUX_ERROR
44
+ : config.successSound || LINUX_SUCCESS
45
+ const args = [file]
46
+ if (Number.isFinite(volume) && volume > 0) args.push('--volume', String(Math.round(volume * 65536)))
47
+ return { command: 'paplay', args }
48
+ }
49
+
50
+ return null
51
+ }
52
+
53
+ /**
54
+ * @param {object} options
55
+ * @param {string} options.platform
56
+ * @param {object} options.config normalized config (`soundVolume`, custom files)
57
+ * @param {{ warn: (message: string) => void }} options.log
58
+ */
59
+ export function createSound({ platform, config, log, spawn = nodeSpawn, now = Date.now, throttleMs = 1_000 }) {
60
+ // `null` (not 0) so the very first trigger is never mistaken for a repeat.
61
+ let lastPlayedAt = null
62
+
63
+ /** @param {'success'|'error'} kind */
64
+ function play(kind = 'success') {
65
+ const timestamp = now()
66
+ if (lastPlayedAt !== null && timestamp - lastPlayedAt < throttleMs) return false
67
+
68
+ const launch = buildSoundCommand({ platform, kind, config })
69
+ if (launch === null) return false
70
+
71
+ try {
72
+ const child = spawn(launch.command, launch.args, {
73
+ stdio: 'ignore',
74
+ windowsHide: true,
75
+ detached: true,
76
+ })
77
+ child.on?.('error', (error) => log.warn(`stay-awake: sound failed: ${describe(error)}`))
78
+ child.unref?.()
79
+ lastPlayedAt = timestamp
80
+ return true
81
+ } catch (error) {
82
+ log.warn(`stay-awake: sound failed: ${describe(error)}`)
83
+ return false
84
+ }
85
+ }
86
+
87
+ return { play }
88
+ }
89
+
90
+ function describe(error) {
91
+ if (error instanceof Error) return error.message
92
+ return String(error)
93
+ }
package/lib/state.js CHANGED
@@ -26,6 +26,7 @@ export function sanitizeState(raw) {
26
26
  if (raw === null || typeof raw !== 'object') return result
27
27
  if (typeof raw.enabled === 'boolean') result.enabled = raw.enabled
28
28
  if (SCOPES.has(raw.scope)) result.scope = raw.scope
29
+ if (typeof raw.sound === 'boolean') result.sound = raw.sound
29
30
  return result
30
31
  }
31
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laraveladmin/dsh-stay-awake",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "DeepSeek Harness plugin that keeps the machine awake only while unattended work runs.",
5
5
  "keywords": [
6
6
  "dsh-plugin",