@laraveladmin/dsh-stay-awake 0.1.1 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/README.en.md +20 -3
- package/README.md +20 -3
- package/client.js +112 -94
- package/docs/REQUIREMENTS.md +56 -4
- package/docs/VERIFICATION.md +28 -0
- package/docs/images/indicator.svg +7 -9
- package/docs/images/panel.svg +63 -51
- package/index.js +47 -3
- package/lib/config.js +19 -0
- package/lib/server.js +11 -1
- package/lib/sound.js +93 -0
- package/lib/state.js +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
# 变更记录 · Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1 — 2026-12-03
|
|
4
|
+
|
|
5
|
+
### 修复
|
|
6
|
+
|
|
7
|
+
- 设置弹层改为**锚定在状态栏触发点上方弹出**(CSS anchor positioning,DSH 自身的统计弹层用同一机制),
|
|
8
|
+
桌面端右侧、窄屏自动翻转;不再固定在窗口底部居中,避免与其它功能点交互不一致。
|
|
9
|
+
- 弹层表面改用 DSH 浮动面板的统一 token:`--dsw-specific-menu` 背景 + `--dsw-menu-backdrop-filter` +
|
|
10
|
+
`--dsw-elevation-prominent` 阴影 + `--dsw-radius-lg` 圆角 + 16px 内边距,标题/字段排版对齐宿主弹层。
|
|
11
|
+
- 状态栏触发点改为与 `activity` / `usage` 一致的 pill 样式(`--dsw-radius-sm`、`1px 8px` 内边距、
|
|
12
|
+
`label-tertiary` 文字、hover/展开态 `--dsw-alias-interactive-bg-hover` 背景)。
|
|
13
|
+
- 多语言:中英字典逐键核对(42 键、双向对称、无硬编码文案、英文无中文残留),清理 3 个失效键。
|
|
14
|
+
|
|
15
|
+
## 0.2.0 — 2026-12-03
|
|
16
|
+
|
|
17
|
+
### 新功能
|
|
18
|
+
|
|
19
|
+
- **任务结束提示音**:工作段结束时在宿主机器播放提示音。
|
|
20
|
+
- 成功 `Glass` / 失败或中断 `Basso`;支持自定义音频文件与音量(`cordis.patch.yml`)。
|
|
21
|
+
- 一次工作段只响一次(含后台任务、多会话);短于 20 秒的段不响;goal/定时任务等自主轮次不响。
|
|
22
|
+
- 弹层新增「完成提示音」开关与「试听」按钮;开关写入状态文件,重启保持。
|
|
23
|
+
- 宿主端播放(macOS `afplay`、Windows `SystemSounds`、Linux `paplay`),播放失败静默降级。
|
|
24
|
+
|
|
3
25
|
## 0.1.1 — 2026-12-03
|
|
4
26
|
|
|
5
27
|
### 修复
|
package/README.en.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
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.
|
|
10
|
+
<img alt="version" src="https://img.shields.io/badge/version-0.2.1-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,7 @@ 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
|
-
Published on npm: [`@laraveladmin/dsh-stay-awake@0.
|
|
66
|
+
Published on npm: [`@laraveladmin/dsh-stay-awake@0.2.1`](https://www.npmjs.com/package/@laraveladmin/dsh-stay-awake)
|
|
58
67
|
|
|
59
68
|
### Option 1 — install from npm (recommended)
|
|
60
69
|
|
|
@@ -112,6 +121,13 @@ Override the row by id in the profile's `cordis.patch.yml`:
|
|
|
112
121
|
reconcileSeconds: 60 # reconciliation interval, 0 = disabled
|
|
113
122
|
maxMaintenanceMinutes: 120 # longest a maintenance bracket may stay open
|
|
114
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
|
|
115
131
|
```
|
|
116
132
|
|
|
117
133
|
Invalid values fall back to their defaults with a warning; a bad config never blocks loading.
|
|
@@ -127,12 +143,13 @@ Invalid values fall back to their defaults with a warning; a bad config never bl
|
|
|
127
143
|
|
|
128
144
|
### Settings panel
|
|
129
145
|
|
|
130
|
-
Clicking the icon or the "Stay awake" label opens a panel
|
|
146
|
+
Clicking the icon or the "Stay awake" label opens a panel **above the status bar**, using the same surface, radius, shadow and typography as the shipped `activity` / `usage` popovers:
|
|
131
147
|
|
|
132
148
|
| Control | Effect |
|
|
133
149
|
|---|---|
|
|
134
150
|
| Enabled | Turning it off releases the assertion immediately |
|
|
135
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 |
|
|
136
153
|
| Hold for | 30 min / 2 h / cancel, for temporary keeps |
|
|
137
154
|
| Status block | Active sources, scope, backend, hold duration, error reason |
|
|
138
155
|
| Footer | Where advanced options live, source link, version |
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
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.
|
|
10
|
+
<img alt="version" src="https://img.shields.io/badge/version-0.2.1-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,7 @@ DSH 跑长任务时你离开电脑,系统按空闲策略休眠:进程被挂
|
|
|
55
64
|
|
|
56
65
|
**前置条件**:DSH 0.2.x(Desktop 或 `dsh web`)。插件零第三方运行时依赖,不需要 Node 工具链。
|
|
57
66
|
|
|
58
|
-
已发布到 npm:[`@laraveladmin/dsh-stay-awake@0.
|
|
67
|
+
已发布到 npm:[`@laraveladmin/dsh-stay-awake@0.2.1`](https://www.npmjs.com/package/@laraveladmin/dsh-stay-awake)
|
|
59
68
|
|
|
60
69
|
### 方式一:从 npm 安装(推荐)
|
|
61
70
|
|
|
@@ -113,6 +122,13 @@ plugin_manager action: install_bundle target: @laraveladmin/dsh-stay-awake
|
|
|
113
122
|
reconcileSeconds: 60 # 对账间隔,0 = 关闭
|
|
114
123
|
maxMaintenanceMinutes: 120 # 维护期括号的最长有效期
|
|
115
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: '' # 自定义失败音文件
|
|
116
132
|
```
|
|
117
133
|
|
|
118
134
|
非法值会回落到默认值并记一条 warning,不会导致插件加载失败。
|
|
@@ -128,12 +144,13 @@ plugin_manager action: install_bundle target: @laraveladmin/dsh-stay-awake
|
|
|
128
144
|
|
|
129
145
|
### 设置弹层
|
|
130
146
|
|
|
131
|
-
|
|
147
|
+
点状态栏的「守夜」图标或文字,面板会从状态栏**右侧上方弹出**,与 `activity` / `usage` 的弹层使用同一套表面、圆角、阴影与排版(DSH 的浮动面板样式):
|
|
132
148
|
|
|
133
149
|
| 项 | 作用 |
|
|
134
150
|
|---|---|
|
|
135
151
|
| 总开关 | 关掉后立即释放断言,不再自动保持 |
|
|
136
152
|
| 允许屏幕休眠 | 开 = 只防系统休眠;关 = 连屏幕一起保持 |
|
|
153
|
+
| 完成提示音 | 任务结束响一声;旁边「试听」可立即验证 |
|
|
137
154
|
| 临时保持 | 30 分钟 / 2 小时 / 取消,用于临时不想让机器睡 |
|
|
138
155
|
| 状态区 | 活跃源、范围、后端、已持续时长、错误原因 |
|
|
139
156
|
| 底部 | 高级参数在哪改、源码链接、版本号 |
|
package/client.js
CHANGED
|
@@ -34,14 +34,11 @@ window.__ModuleLoader__.load({
|
|
|
34
34
|
'state.failed': '异常',
|
|
35
35
|
'state.disabled': '已关闭',
|
|
36
36
|
'state.unknown': '状态未知',
|
|
37
|
-
'detail.state': '状态',
|
|
38
37
|
'detail.backend': '后端',
|
|
39
38
|
'detail.scope': '范围',
|
|
40
39
|
'detail.sources': '活跃源',
|
|
41
40
|
'detail.since': '已持续',
|
|
42
41
|
'detail.error': '原因',
|
|
43
|
-
'detail.version': '版本',
|
|
44
|
-
'link.repo': '查看源码',
|
|
45
42
|
'sources.agents': '会话',
|
|
46
43
|
'sources.maintenance': '维护',
|
|
47
44
|
'sources.jobs': '后台任务',
|
|
@@ -59,6 +56,8 @@ window.__ModuleLoader__.load({
|
|
|
59
56
|
'panel.hold30': '30 分钟',
|
|
60
57
|
'panel.hold120': '2 小时',
|
|
61
58
|
'panel.holdCancel': '取消',
|
|
59
|
+
'panel.sound': '完成提示音',
|
|
60
|
+
'panel.testSound': '试听',
|
|
62
61
|
'panel.holdDisabled': '总开关关闭时无法临时保持',
|
|
63
62
|
'panel.holdLeft': '剩余',
|
|
64
63
|
'panel.saved': '已保存',
|
|
@@ -79,14 +78,11 @@ window.__ModuleLoader__.load({
|
|
|
79
78
|
'state.failed': 'Error',
|
|
80
79
|
'state.disabled': 'Off',
|
|
81
80
|
'state.unknown': 'Unknown',
|
|
82
|
-
'detail.state': 'State',
|
|
83
81
|
'detail.backend': 'Backend',
|
|
84
82
|
'detail.scope': 'Scope',
|
|
85
83
|
'detail.sources': 'Sources',
|
|
86
84
|
'detail.since': 'Held for',
|
|
87
85
|
'detail.error': 'Reason',
|
|
88
|
-
'detail.version': 'Version',
|
|
89
|
-
'link.repo': 'View source',
|
|
90
86
|
'sources.agents': 'Agents',
|
|
91
87
|
'sources.maintenance': 'Maintenance',
|
|
92
88
|
'sources.jobs': 'Jobs',
|
|
@@ -104,6 +100,8 @@ window.__ModuleLoader__.load({
|
|
|
104
100
|
'panel.hold30': '30 min',
|
|
105
101
|
'panel.hold120': '2 h',
|
|
106
102
|
'panel.holdCancel': 'Cancel',
|
|
103
|
+
'panel.sound': 'Completion sound',
|
|
104
|
+
'panel.testSound': 'Test',
|
|
107
105
|
'panel.holdDisabled': 'Enable the plugin first to hold',
|
|
108
106
|
'panel.holdLeft': 'left',
|
|
109
107
|
'panel.saved': 'Saved',
|
|
@@ -116,40 +114,52 @@ window.__ModuleLoader__.load({
|
|
|
116
114
|
}
|
|
117
115
|
|
|
118
116
|
const CSS = `
|
|
119
|
-
.dsa-
|
|
120
|
-
.dsa-
|
|
121
|
-
.dsa-
|
|
122
|
-
.dsa-
|
|
123
|
-
.dsa-
|
|
124
|
-
.dsa-
|
|
125
|
-
.dsa-
|
|
126
|
-
|
|
127
|
-
.dsa-
|
|
117
|
+
.dsa-pill{box-sizing:border-box;border-radius:var(--dsw-radius-sm);max-width:100%;color:var(--dsw-alias-label-tertiary);font:inherit;font-variant-numeric:tabular-nums;line-height:inherit;white-space:nowrap;background:0 0;border:none;align-items:center;gap:6px;padding:1px 8px;display:inline-flex;cursor:pointer;anchor-name:--dsh-stay-awake-panel}
|
|
118
|
+
.dsa-pill[aria-expanded="true"]{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}
|
|
119
|
+
@media (hover:hover){.dsa-pill:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}}
|
|
120
|
+
.dsa-pill:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
121
|
+
.dsa-pill svg{flex:none;width:14px;height:14px}
|
|
122
|
+
.dsa-label{text-overflow:ellipsis;min-width:0;overflow:hidden}
|
|
123
|
+
.dsa-panel{position:fixed;left:50%;bottom:150px;transform:translateX(-50%);z-index:1100;box-sizing:border-box;border:0;border-radius:var(--dsw-radius-lg);background:var(--dsw-specific-menu);backdrop-filter:var(--dsw-menu-backdrop-filter);--dsw-elevation-stroke-color:var(--dsw-alias-border-l1);box-shadow:var(--dsw-elevation-prominent);color:var(--dsw-alias-label-secondary);width:max-content;min-width:min(300px,100vw - 24px);max-width:min(440px,100vw - 24px);max-height:calc(100dvh - 24px);overflow:hidden auto;margin:0;padding:16px;font-size:12px;line-height:18px;cursor:default;pointer-events:auto;text-align:left}
|
|
124
|
+
@supports (position-anchor: --dsh-stay-awake-panel){
|
|
125
|
+
.dsa-panel{position-anchor:--dsh-stay-awake-panel;top:max(12px, var(--dsh-frame-overlay-top,12px));bottom:max(12px, calc(anchor(top) + 8px));left:max(12px, anchor(left));right:12px;transform:none;position-try-fallbacks:flip-block, flip-inline;max-height:calc(100dvh - 12px - max(12px, var(--dsh-frame-overlay-top,12px)))}
|
|
126
|
+
}
|
|
127
|
+
.dsa-head{display:flex;align-items:center;justify-content:space-between;gap:16px;margin-bottom:8px;color:var(--dsw-alias-label-primary);font-weight:500}
|
|
128
|
+
.dsa-head-label{display:inline-flex;align-items:center;gap:6px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
129
|
+
.dsa-head-label svg{flex:none;width:14px;height:14px}
|
|
130
|
+
.dsa-head-value{display:inline-flex;align-items:center;gap:8px;color:var(--dsw-alias-label-tertiary);font-weight:400;flex:none}
|
|
131
|
+
.dsa-state{font-variant-numeric:tabular-nums}
|
|
132
|
+
.dsa-close{border:0;background:0 0;color:var(--dsw-alias-label-tertiary);cursor:pointer;font:inherit;line-height:1;padding:2px 4px;border-radius:var(--dsw-radius-sm);margin-right:-4px}
|
|
133
|
+
.dsa-close:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}
|
|
134
|
+
.dsa-rule{border-top:.5px solid var(--dsw-alias-border-l2);margin:0 0 10px}
|
|
135
|
+
.dsa-grid{display:grid;grid-template-columns:minmax(76px,auto) minmax(0,1fr);gap:6px 16px;margin:0}
|
|
136
|
+
.dsa-key{color:var(--dsw-alias-label-tertiary);margin:0;min-width:0}
|
|
137
|
+
.dsa-val{color:var(--dsw-alias-label-secondary);font-variant-numeric:tabular-nums;text-align:right;margin:0;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
138
|
+
.dsa-section{margin-top:14px;padding-top:12px;border-top:.5px solid var(--dsw-alias-border-l2)}
|
|
139
|
+
.dsa-row{display:flex;align-items:center;gap:12px;min-height:24px}
|
|
140
|
+
.dsa-row+.dsa-row{margin-top:6px}
|
|
128
141
|
.dsa-grow{flex:1 1 auto;min-width:0}
|
|
129
|
-
.dsa-
|
|
130
|
-
.dsa-switch{flex:0 0 auto;width:34px;height:18px;border-radius:9px;border:
|
|
142
|
+
.dsa-sub{color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}
|
|
143
|
+
.dsa-switch{flex:0 0 auto;width:34px;height:18px;border-radius:9px;border:0;background:var(--dsw-alias-state-idle-primary);position:relative;cursor:pointer;padding:0;transition:background .15s ease}
|
|
131
144
|
.dsa-switch::after{content:'';position:absolute;top:2px;left:2px;width:12px;height:12px;border-radius:50%;background:var(--dsw-alias-bg-base);transition:transform .15s ease}
|
|
132
|
-
.dsa-switch[aria-checked="true"]{background:var(--dsw-alias-state-success-primary)
|
|
145
|
+
.dsa-switch[aria-checked="true"]{background:var(--dsw-alias-state-success-primary)}
|
|
133
146
|
.dsa-switch[aria-checked="true"]::after{transform:translateX(16px)}
|
|
134
147
|
.dsa-switch:disabled{opacity:.5;cursor:default}
|
|
135
|
-
.dsa-
|
|
136
|
-
.dsa-
|
|
137
|
-
.dsa-button:
|
|
148
|
+
.dsa-switch:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
149
|
+
.dsa-actions{display:flex;gap:6px;flex-wrap:wrap;margin-top:6px}
|
|
150
|
+
.dsa-button{border:0;background:var(--dsw-alias-bg-layer-2);color:var(--dsw-alias-label-primary);border-radius:var(--dsw-radius-sm);padding:4px 10px;cursor:pointer;font:inherit;line-height:16px}
|
|
151
|
+
.dsa-button:hover{background:var(--dsw-alias-interactive-bg-hover)}
|
|
138
152
|
.dsa-button:disabled{opacity:.5;cursor:default}
|
|
139
|
-
.dsa-button:focus-visible
|
|
140
|
-
.dsa-note{color:var(--dsw-alias-label-
|
|
153
|
+
.dsa-button:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
154
|
+
.dsa-note{color:var(--dsw-alias-label-tertiary);margin-top:8px}
|
|
141
155
|
.dsa-error{color:var(--dsw-alias-state-error-primary)}
|
|
142
|
-
.dsa-foot{display:flex;gap:10px;align-items:center;margin-top:10px;
|
|
143
|
-
.dsa-foot .dsa-
|
|
144
|
-
.dsa-icon-link{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;border-radius:
|
|
145
|
-
.dsa-icon-link:hover{background:var(--dsw-alias-bg-
|
|
146
|
-
.dsa-
|
|
147
|
-
.dsa-version
|
|
148
|
-
.dsa-
|
|
149
|
-
.dsa-link:hover{text-decoration:underline}
|
|
150
|
-
.dsa-line{display:inline-flex;align-items:center;gap:6px;min-width:0;white-space:nowrap;font-size:calc(var(--dsh-content-font-size-secondary,13px) - 1px);line-height:calc(20px + var(--dsh-content-font-delta-secondary,0px))}
|
|
151
|
-
.dsa-indicator{display:inline-flex;align-items:center;min-width:0;flex:0 1 auto;background:transparent;border:0;padding:0;font:inherit;cursor:pointer;border-radius:6px}
|
|
152
|
-
.dsa-indicator:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
156
|
+
.dsa-foot{display:flex;gap:10px;align-items:center;margin-top:14px;padding-top:10px;border-top:.5px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary);font-size:11px;line-height:16px}
|
|
157
|
+
.dsa-foot .dsa-grow{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
158
|
+
.dsa-icon-link{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;border-radius:var(--dsw-radius-sm);color:var(--dsw-alias-label-tertiary);text-decoration:none;flex:none}
|
|
159
|
+
.dsa-icon-link:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}
|
|
160
|
+
.dsa-icon-link:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:2px}
|
|
161
|
+
.dsa-version{color:var(--dsw-alias-label-tertiary);text-decoration:none;flex:none;font-variant-numeric:tabular-nums}
|
|
162
|
+
.dsa-version:hover{color:var(--dsw-alias-label-secondary);text-decoration:underline}
|
|
153
163
|
`
|
|
154
164
|
|
|
155
165
|
function createStore() {
|
|
@@ -292,10 +302,6 @@ window.__ModuleLoader__.load({
|
|
|
292
302
|
function Indicator({ store, t }) {
|
|
293
303
|
const snapshot = useStore(store)
|
|
294
304
|
const view = classify(snapshot.status, snapshot.failures)
|
|
295
|
-
const color = toneColor(view.tone)
|
|
296
|
-
const textColor = view.tone === 'error'
|
|
297
|
-
? 'var(--dsw-alias-state-error-primary)'
|
|
298
|
-
: 'var(--dsw-alias-label-secondary)'
|
|
299
305
|
return h(
|
|
300
306
|
React.Fragment,
|
|
301
307
|
null,
|
|
@@ -304,13 +310,13 @@ window.__ModuleLoader__.load({
|
|
|
304
310
|
'button',
|
|
305
311
|
{
|
|
306
312
|
type: 'button',
|
|
307
|
-
className: 'dsa-
|
|
313
|
+
className: 'dsa-pill dsa-root',
|
|
308
314
|
'aria-expanded': snapshot.open === true,
|
|
309
315
|
'aria-haspopup': 'dialog',
|
|
310
|
-
style: { color: textColor },
|
|
311
316
|
onClick: () => store.toggle(),
|
|
312
317
|
},
|
|
313
|
-
h(
|
|
318
|
+
h(Moon, { key: 'icon', color: toneColor(view.tone) }),
|
|
319
|
+
h('span', { key: 'label', className: 'dsa-label' }, `${t('brand')} · ${t(`state.${view.key}`)}`),
|
|
314
320
|
),
|
|
315
321
|
)
|
|
316
322
|
}
|
|
@@ -325,6 +331,7 @@ window.__ModuleLoader__.load({
|
|
|
325
331
|
const unreachable = status === null || failures >= UNKNOWN_AFTER_FAILURES
|
|
326
332
|
const enabled = status === null ? true : status.enabled !== false
|
|
327
333
|
const allowDisplaySleep = (status === null ? 'system' : status.scope) === 'system'
|
|
334
|
+
const soundOn = status === null ? true : status.sound !== false
|
|
328
335
|
const busy = snapshot.busy === true
|
|
329
336
|
const staleHost = status !== null && status.protocol !== 2
|
|
330
337
|
const counts = status && status.counts ? status.counts : { agents: 0, maintenance: 0, jobs: 0 }
|
|
@@ -353,7 +360,6 @@ window.__ModuleLoader__.load({
|
|
|
353
360
|
if (!open) return null
|
|
354
361
|
|
|
355
362
|
const rows = [
|
|
356
|
-
[t('detail.state'), t(`state.${view.key}`)],
|
|
357
363
|
[t('detail.sources'), `${t('sources.agents')} ${counts.agents ?? 0} · ${t('sources.maintenance')} ${counts.maintenance ?? 0} · ${t('sources.jobs')} ${counts.jobs ?? 0}`],
|
|
358
364
|
[t('detail.scope'), allowDisplaySleep ? t('scope.system') : t('scope.display')],
|
|
359
365
|
[t('detail.backend'), status && status.backend ? status.backend : t('unit.none')],
|
|
@@ -365,6 +371,16 @@ window.__ModuleLoader__.load({
|
|
|
365
371
|
const reason = status !== null && !unreachable ? errorText(t, status) : null
|
|
366
372
|
if (reason !== null) rows.push([t('detail.error'), reason])
|
|
367
373
|
|
|
374
|
+
const switchOf = (checked, onClick, label, extraDisabled = false) => h('button', {
|
|
375
|
+
type: 'button',
|
|
376
|
+
className: 'dsa-switch',
|
|
377
|
+
role: 'switch',
|
|
378
|
+
'aria-checked': checked,
|
|
379
|
+
'aria-label': label,
|
|
380
|
+
disabled: busy || unreachable || extraDisabled,
|
|
381
|
+
onClick,
|
|
382
|
+
})
|
|
383
|
+
|
|
368
384
|
return h(
|
|
369
385
|
'div',
|
|
370
386
|
{ className: 'dsa-panel', role: 'dialog', 'aria-label': t('brand') },
|
|
@@ -372,41 +388,47 @@ window.__ModuleLoader__.load({
|
|
|
372
388
|
h(
|
|
373
389
|
'div',
|
|
374
390
|
{ className: 'dsa-head', key: 'head' },
|
|
375
|
-
h(
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
391
|
+
h(
|
|
392
|
+
'span',
|
|
393
|
+
{ className: 'dsa-head-label' },
|
|
394
|
+
h(Moon, { key: 'icon', color: toneColor(view.tone) }),
|
|
395
|
+
t('brand'),
|
|
396
|
+
),
|
|
397
|
+
h(
|
|
398
|
+
'span',
|
|
399
|
+
{ className: 'dsa-head-value' },
|
|
400
|
+
h('span', { className: 'dsa-state' }, t(`state.${view.key}`)),
|
|
401
|
+
h('button', {
|
|
402
|
+
type: 'button',
|
|
403
|
+
className: 'dsa-close',
|
|
404
|
+
title: t('panel.close'),
|
|
405
|
+
'aria-label': t('panel.close'),
|
|
406
|
+
onClick: () => store.close(),
|
|
407
|
+
}, '×'),
|
|
408
|
+
),
|
|
393
409
|
),
|
|
410
|
+
h('div', { className: 'dsa-rule', key: 'rule' }),
|
|
411
|
+
staleHost || snapshot.notice === 'stale'
|
|
412
|
+
? h('div', { className: 'dsa-note dsa-error', key: 'stale' }, t('panel.staleHost'))
|
|
413
|
+
: null,
|
|
414
|
+
unreachable
|
|
415
|
+
? h('div', { className: 'dsa-note dsa-error', key: 'unreachable' }, t('hint.unreachable'))
|
|
416
|
+
: h(
|
|
417
|
+
'dl',
|
|
418
|
+
{ className: 'dsa-grid', key: 'grid' },
|
|
419
|
+
rows.flatMap(([key, value], index) => [
|
|
420
|
+
h('dt', { key: `k${index}`, className: 'dsa-key' }, key),
|
|
421
|
+
h('dd', { key: `v${index}`, className: 'dsa-val', title: value }, value),
|
|
422
|
+
]),
|
|
423
|
+
),
|
|
394
424
|
h(
|
|
395
425
|
'div',
|
|
396
|
-
{ className: 'dsa-
|
|
426
|
+
{ className: 'dsa-section', key: 'switches' },
|
|
397
427
|
h(
|
|
398
428
|
'div',
|
|
399
429
|
{ className: 'dsa-row' },
|
|
400
430
|
h('span', { className: 'dsa-grow' }, t('panel.enabled')),
|
|
401
|
-
|
|
402
|
-
type: 'button',
|
|
403
|
-
className: 'dsa-switch',
|
|
404
|
-
role: 'switch',
|
|
405
|
-
'aria-checked': enabled,
|
|
406
|
-
'aria-label': t('panel.enabled'),
|
|
407
|
-
disabled: busy || unreachable,
|
|
408
|
-
onClick: () => act({ action: 'set-enabled', enabled: !enabled }),
|
|
409
|
-
}),
|
|
431
|
+
switchOf(enabled, () => act({ action: 'set-enabled', enabled: !enabled }), t('panel.enabled')),
|
|
410
432
|
),
|
|
411
433
|
h(
|
|
412
434
|
'div',
|
|
@@ -415,60 +437,56 @@ window.__ModuleLoader__.load({
|
|
|
415
437
|
h('div', null, t('panel.allowDisplaySleep')),
|
|
416
438
|
h('div', { className: 'dsa-sub' }, t('panel.allowDisplaySleepHint')),
|
|
417
439
|
),
|
|
440
|
+
switchOf(allowDisplaySleep, () => act({ action: 'set-scope', scope: allowDisplaySleep ? 'display' : 'system' }), t('panel.allowDisplaySleep')),
|
|
441
|
+
),
|
|
442
|
+
h(
|
|
443
|
+
'div',
|
|
444
|
+
{ className: 'dsa-row' },
|
|
445
|
+
h('span', { className: 'dsa-grow' }, t('panel.sound')),
|
|
418
446
|
h('button', {
|
|
419
447
|
type: 'button',
|
|
420
|
-
className: 'dsa-
|
|
421
|
-
role: 'switch',
|
|
422
|
-
'aria-checked': allowDisplaySleep,
|
|
423
|
-
'aria-label': t('panel.allowDisplaySleep'),
|
|
448
|
+
className: 'dsa-button',
|
|
424
449
|
disabled: busy || unreachable,
|
|
425
|
-
onClick: () => act({ action: '
|
|
426
|
-
}),
|
|
450
|
+
onClick: () => act({ action: 'test-sound' }),
|
|
451
|
+
}, t('panel.testSound')),
|
|
452
|
+
switchOf(soundOn, () => act({ action: 'set-sound', enabled: !soundOn }), t('panel.sound')),
|
|
427
453
|
),
|
|
428
454
|
),
|
|
429
455
|
h(
|
|
430
456
|
'div',
|
|
431
|
-
{ className: 'dsa-
|
|
457
|
+
{ className: 'dsa-section', key: 'hold' },
|
|
432
458
|
h('div', { className: 'dsa-sub' }, t('panel.hold')),
|
|
433
459
|
h(
|
|
434
460
|
'div',
|
|
435
461
|
{ className: 'dsa-actions' },
|
|
436
462
|
h('button', {
|
|
437
|
-
type: 'button',
|
|
438
|
-
className: 'dsa-button',
|
|
463
|
+
type: 'button', className: 'dsa-button',
|
|
439
464
|
disabled: busy || unreachable || !enabled,
|
|
440
465
|
title: enabled ? undefined : t('panel.holdDisabled'),
|
|
441
466
|
onClick: () => act({ action: 'hold', minutes: 30 }),
|
|
442
467
|
}, t('panel.hold30')),
|
|
443
468
|
h('button', {
|
|
444
|
-
type: 'button',
|
|
445
|
-
className: 'dsa-button',
|
|
469
|
+
type: 'button', className: 'dsa-button',
|
|
446
470
|
disabled: busy || unreachable || !enabled,
|
|
447
471
|
title: enabled ? undefined : t('panel.holdDisabled'),
|
|
448
472
|
onClick: () => act({ action: 'hold', minutes: 120 }),
|
|
449
473
|
}, t('panel.hold120')),
|
|
450
|
-
holdLeft === null
|
|
451
|
-
|
|
452
|
-
:
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
disabled: busy || unreachable,
|
|
456
|
-
onClick: () => act({ action: 'cancel-hold' }),
|
|
457
|
-
}, t('panel.holdCancel')),
|
|
474
|
+
holdLeft === null ? null : h('button', {
|
|
475
|
+
type: 'button', className: 'dsa-button',
|
|
476
|
+
disabled: busy || unreachable,
|
|
477
|
+
onClick: () => act({ action: 'cancel-hold' }),
|
|
478
|
+
}, t('panel.holdCancel')),
|
|
458
479
|
),
|
|
459
480
|
snapshot.notice === 'saved'
|
|
460
481
|
? h('div', { className: 'dsa-note' }, t('panel.saved'))
|
|
461
482
|
: snapshot.notice === 'failed'
|
|
462
|
-
? h('div', { className: 'dsa-note dsa-error' }, t('panel.saveFailed'))
|
|
483
|
+
? h('div', { className: 'dsa-note dsa-error' }, `${t('panel.saveFailed')}${snapshot.noticeStatus ? ` (${snapshot.noticeStatus})` : ''}`)
|
|
463
484
|
: null,
|
|
464
485
|
),
|
|
465
486
|
h(
|
|
466
487
|
'div',
|
|
467
488
|
{ className: 'dsa-foot', key: 'foot' },
|
|
468
|
-
h('span', {
|
|
469
|
-
className: 'dsa-grow',
|
|
470
|
-
style: { overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' },
|
|
471
|
-
}, t('panel.advanced')),
|
|
489
|
+
h('span', { className: 'dsa-grow', title: t('panel.advanced') }, t('panel.advanced')),
|
|
472
490
|
h('a', {
|
|
473
491
|
className: 'dsa-icon-link',
|
|
474
492
|
href: REPO_URL,
|
package/docs/REQUIREMENTS.md
CHANGED
|
@@ -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
|
|
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.
|
|
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`
|
|
531
|
+
| FR-8 UI | ✅ 可交互指示器 + 设置弹层(中英双语) | 点击状态栏「守夜」打开 `shell.overlay` 弹层:总开关、允许屏幕休眠、完成提示音(含试听)、临时保持(30 分钟 / 2 小时 / 取消)、状态详情、源码链接;面板与指示器共享单例状态,一个页面只有一个轮询 |
|
|
480
532
|
| FR-9 生命周期 | ✅ 实现并真机验证 | 禁用即释放、重新启用即重取、宿主 SIGKILL 不残留 |
|
|
481
533
|
|
|
482
534
|
**配置优先级**:`cordis.patch.yml` 提供默认值,弹层改过的 `enabled` / `scope` 以状态文件为准;其余参数(防抖、兜底时长、对账间隔等)只能改 patch。
|
package/docs/VERIFICATION.md
CHANGED
|
@@ -97,6 +97,34 @@
|
|
|
97
97
|
- 包上存在一个 `0.0.0-stage` 占位版本(发布流程产生),`latest` 指向 0.1.0、不影响安装;npm 禁止 bypass-2FA token 执行 unpublish,需带 2FA 的手动操作才能清理。
|
|
98
98
|
- README 中的图片已改为 Gitee raw 绝对地址,保证 npm 包页面上也能正常显示(npmjs 不解析仓库相对路径)。
|
|
99
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
|
+
- 插件热重载:禁用再启用后宿主重新持有断言(`caffeinate -i -w 48389`,pid 64764),新宿主代码已生效;浏览器侧新开关需刷新页面后可见。
|
|
111
|
+
- **已发布 npm 0.2.0**:`dist-tags.latest = 0.2.0`,`dist.shasum = 219c56e84bc0c48023586967974638333e2eb2d1`;从干净的已提交工作树重建的 tarball 与该 shasum 完全一致,解包内容与 npm 拉取包逐文件相同;对发布包做冒烟:用户消息 → running → idle 触发一次 `success` 音效调用(SMOKE OK)。
|
|
112
|
+
- 未验证:Windows `SystemSounds` 与 Linux `paplay` 未在真机验证;新开关在亮/暗主题下的观感需目视确认;实际听觉(音量/输出设备)需用户确认。
|
|
113
|
+
|
|
114
|
+
## 0.2.1 界面统一与多语言核对(2026-12-03)
|
|
115
|
+
|
|
116
|
+
- **弹层位置与外观对齐宿主**:改用 CSS anchor positioning(DSH 内置统计弹层 `mR10tW_panel` 用的同一机制),
|
|
117
|
+
面板锚定在状态栏触发点上方 `anchor(top) + 8px`,`@supports` 不支持时回退到窗口底部居中;
|
|
118
|
+
表面改为 `--dsw-specific-menu` + `--dsw-menu-backdrop-filter` + `--dsw-elevation-prominent` +
|
|
119
|
+
`--dsw-radius-lg` + 16px 内边距,标题、分隔线、`dl` 字段网格与字段右对齐方式均照搬宿主样式。
|
|
120
|
+
- **触发点对齐**:改为宿主 dock pill 同款样式(`--dsw-radius-sm`、`1px 8px` 内边距、`label-tertiary` 文字、
|
|
121
|
+
hover 与 `aria-expanded` 时的 `--dsw-alias-interactive-bg-hover` 背景、14px 图标、6px 间距)。
|
|
122
|
+
- **多语言核对**:中英字典各 41 键、顺序与键集合完全一致,无缺失键、无未使用键、无空值、
|
|
123
|
+
英文值无中文残留;组件内无字典外的可见文案(CJK 扫描为空);插件管理器标题/描述由 `locale/zh.json`、
|
|
124
|
+
`locale/en.json` 提供。DSH 仅内置 zh/en,其它语言按 DSH 回退链落到英文。
|
|
125
|
+
- **自动化**:75 个单测/接线测试保持全绿;`npm pack` 产物 24 个文件。
|
|
126
|
+
- 未验证:弹层实际锚定位置与观感需刷新页面后目视确认(本会话无浏览器控制权)。
|
|
127
|
+
|
|
100
128
|
## 未验证(明确记录,不代替验证)
|
|
101
129
|
|
|
102
130
|
| ID / 项 | 原因 | 何时可验 |
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 420 96" width="420" height="96" role="img" aria-label="状态栏指示器示意">
|
|
2
2
|
<rect width="420" height="96" rx="10" fill="#f7f8fa"/>
|
|
3
|
-
<text x="18" y="26" font-family="PingFang SC, Noto Sans SC, Helvetica, Arial, sans-serif" font-size="11" fill="#8a8f98"
|
|
3
|
+
<text x="18" y="26" font-family="PingFang SC, Noto Sans SC, Helvetica, Arial, sans-serif" font-size="11" fill="#8a8f98">输入框下方状态栏(与 activity / usage 同一排)</text>
|
|
4
4
|
|
|
5
|
-
<!--
|
|
5
|
+
<!-- composer dock line -->
|
|
6
6
|
<rect x="18" y="40" width="384" height="34" rx="8" fill="#ffffff" stroke="#e4e6eb"/>
|
|
7
7
|
<text x="34" y="61" font-family="PingFang SC, Noto Sans SC, Helvetica, Arial, sans-serif" font-size="11" fill="#b4b8c0">12.3k tokens · 2 个任务</text>
|
|
8
8
|
|
|
9
|
-
<!--
|
|
10
|
-
<g transform="translate(
|
|
11
|
-
<path d="
|
|
12
|
-
<text x="
|
|
13
|
-
<circle cx="116" cy="16" r="2.6" fill="#22c55e"/>
|
|
9
|
+
<!-- trigger pill: same pill styling as the shipped dock entries -->
|
|
10
|
+
<g transform="translate(258,46)">
|
|
11
|
+
<path d="M9 1.5a6 6 0 1 0 3.7 9A4.9 4.9 0 0 1 9 1.5z" fill="#22c55e" transform="scale(1.1)"/>
|
|
12
|
+
<text x="17" y="16" font-family="PingFang SC, Noto Sans SC, Helvetica, Arial, sans-serif" font-size="12" fill="#9aa0a8">守夜 · 保持中</text>
|
|
14
13
|
</g>
|
|
15
14
|
|
|
16
|
-
<!-- callouts -->
|
|
17
15
|
<line x1="300" y1="40" x2="300" y2="30" stroke="#c9ced6"/>
|
|
18
|
-
<text x="238" y="26" font-family="PingFang SC, Noto Sans SC, Helvetica, Arial, sans-serif" font-size="10" fill="#8a8f98"
|
|
16
|
+
<text x="238" y="26" font-family="PingFang SC, Noto Sans SC, Helvetica, Arial, sans-serif" font-size="10" fill="#8a8f98">点击在状态栏上方弹出面板</text>
|
|
19
17
|
</svg>
|
package/docs/images/panel.svg
CHANGED
|
@@ -1,65 +1,77 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 420 424" width="420" height="424" role="img" aria-label="设置弹层示意">
|
|
2
|
+
<defs>
|
|
3
|
+
<filter id="sh" x="-20%" y="-20%" width="140%" height="140%">
|
|
4
|
+
<feDropShadow dx="0" dy="8" stdDeviation="14" flood-color="#0b1220" flood-opacity="0.16"/>
|
|
5
|
+
</filter>
|
|
6
|
+
</defs>
|
|
2
7
|
<style>
|
|
3
|
-
.bg{fill:#eef0f3}
|
|
4
|
-
.panel{fill:#ffffff}
|
|
5
8
|
.t{font-family:"PingFang SC","Noto Sans SC",Helvetica,Arial,sans-serif}
|
|
6
|
-
.title{font-size:
|
|
7
|
-
.key{font-size:
|
|
8
|
-
.val{font-size:
|
|
9
|
-
.label{font-size:12px;fill:#
|
|
10
|
-
.sub{font-size:
|
|
11
|
-
.
|
|
12
|
-
.btntext{font-size:11px;fill:#3c4149}
|
|
9
|
+
.title{font-size:13px;font-weight:500;fill:#111827}
|
|
10
|
+
.key{font-size:12px;fill:#9aa0a8}
|
|
11
|
+
.val{font-size:12px;fill:#4b5563}
|
|
12
|
+
.label{font-size:12px;fill:#374151}
|
|
13
|
+
.sub{font-size:11px;fill:#9aa0a8}
|
|
14
|
+
.rule{stroke:#e5e7eb;stroke-width:1}
|
|
13
15
|
</style>
|
|
14
16
|
|
|
15
|
-
<rect
|
|
16
|
-
<rect class="panel" x="10" y="10" width="360" height="336" rx="12"/>
|
|
17
|
+
<rect width="420" height="424" fill="#eef0f3"/>
|
|
17
18
|
|
|
18
|
-
<!--
|
|
19
|
-
<
|
|
20
|
-
|
|
21
|
-
<
|
|
22
|
-
<
|
|
19
|
+
<!-- composer dock with the trigger pill, to show the anchor relationship -->
|
|
20
|
+
<rect x="30" y="30" width="360" height="30" rx="8" fill="#ffffff" stroke="#e4e6eb"/>
|
|
21
|
+
<g transform="translate(196,36)">
|
|
22
|
+
<path d="M9 1.5a6 6 0 1 0 3.7 9A4.9 4.9 0 0 1 9 1.5z" fill="#22c55e" transform="scale(1.1)"/>
|
|
23
|
+
<text class="t" x="16" y="15" font-size="12" fill="#9aa0a8">守夜 · 保持中</text>
|
|
23
24
|
</g>
|
|
24
|
-
<text class="t" x="352" y="40" font-size="15" fill="#9aa0a8" text-anchor="middle">×</text>
|
|
25
25
|
|
|
26
|
-
<!--
|
|
27
|
-
<g
|
|
28
|
-
<
|
|
29
|
-
<text class="key" x="24" y="92">活跃源</text><text class="val" x="86" y="92">会话 1 · 维护 0 · 后台任务 0</text>
|
|
30
|
-
<text class="key" x="24" y="112">范围</text><text class="val" x="86" y="112">仅系统</text>
|
|
31
|
-
<text class="key" x="24" y="132">后端</text><text class="val" x="86" y="132">caffeinate</text>
|
|
32
|
-
<text class="key" x="24" y="152">已持续</text><text class="val" x="86" y="152">00:12:31</text>
|
|
26
|
+
<!-- popover panel: anchored above the pill, host dialog styling -->
|
|
27
|
+
<g filter="url(#sh)">
|
|
28
|
+
<rect x="30" y="76" width="360" height="318" rx="12" fill="#ffffff"/>
|
|
33
29
|
</g>
|
|
34
|
-
|
|
35
|
-
<!-- toggles -->
|
|
36
30
|
<g class="t">
|
|
37
|
-
|
|
38
|
-
<
|
|
39
|
-
<
|
|
31
|
+
<!-- title row -->
|
|
32
|
+
<path d="M46 90a7 7 0 1 0 4.4 10.5A5.8 5.8 0 0 1 46 90z" fill="#22c55e"/>
|
|
33
|
+
<text class="t title" x="62" y="101">守夜</text>
|
|
34
|
+
<text class="sub" x="330" y="101" text-anchor="end">保持中</text>
|
|
35
|
+
<text class="t" x="352" y="102" text-anchor="middle" font-size="15" fill="#9aa0a8">×</text>
|
|
40
36
|
|
|
41
|
-
<
|
|
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"/>
|
|
45
|
-
</g>
|
|
37
|
+
<line class="rule" x1="46" y1="114" x2="374" y2="114"/>
|
|
46
38
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
<text class="
|
|
50
|
-
<
|
|
51
|
-
<text class="
|
|
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>
|
|
56
|
-
</g>
|
|
39
|
+
<!-- details grid -->
|
|
40
|
+
<text class="key" x="46" y="138">活跃源</text><text class="val" x="374" y="138" text-anchor="end">会话 1 · 维护 0 · 后台任务 0</text>
|
|
41
|
+
<text class="key" x="46" y="162">范围</text><text class="val" x="374" y="162" text-anchor="end">仅系统</text>
|
|
42
|
+
<text class="key" x="46" y="186">后端</text><text class="val" x="374" y="186" text-anchor="end">caffeinate</text>
|
|
43
|
+
<text class="key" x="46" y="210">已持续</text><text class="val" x="374" y="210" text-anchor="end">00:12:31</text>
|
|
57
44
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
<
|
|
62
|
-
|
|
63
|
-
<
|
|
45
|
+
<line class="rule" x1="46" y1="232" x2="374" y2="232"/>
|
|
46
|
+
|
|
47
|
+
<!-- switches -->
|
|
48
|
+
<text class="label" x="46" y="258">总开关</text>
|
|
49
|
+
<rect x="340" y="247" width="34" height="18" rx="9" fill="#22c55e"/>
|
|
50
|
+
<circle cx="365" cy="256" r="6" fill="#ffffff"/>
|
|
51
|
+
|
|
52
|
+
<text class="label" x="46" y="286">允许屏幕休眠</text>
|
|
53
|
+
<text class="sub" x="46" y="301">只防系统休眠,屏幕按系统设置熄灭</text>
|
|
54
|
+
<rect x="340" y="275" width="34" height="18" rx="9" fill="#22c55e"/>
|
|
55
|
+
<circle cx="365" cy="284" r="6" fill="#ffffff"/>
|
|
56
|
+
|
|
57
|
+
<text class="label" x="46" y="330">完成提示音</text>
|
|
58
|
+
<rect x="266" y="317" width="56" height="22" rx="6" fill="#f3f4f6"/>
|
|
59
|
+
<text class="t" x="294" y="332" text-anchor="middle" font-size="12" fill="#374151">试听</text>
|
|
60
|
+
<rect x="340" y="319" width="34" height="18" rx="9" fill="#22c55e"/>
|
|
61
|
+
<circle cx="365" cy="328" r="6" fill="#ffffff"/>
|
|
62
|
+
|
|
63
|
+
<line class="rule" x1="46" y1="348" x2="374" y2="348"/>
|
|
64
|
+
|
|
65
|
+
<!-- hold -->
|
|
66
|
+
<text class="sub" x="46" y="368">临时保持</text>
|
|
67
|
+
<rect x="46" y="376" width="64" height="22" rx="6" fill="#f3f4f6"/>
|
|
68
|
+
<text class="t" x="78" y="391" text-anchor="middle" font-size="12" fill="#374151">30 分钟</text>
|
|
69
|
+
<rect x="116" y="376" width="58" height="22" rx="6" fill="#f3f4f6"/>
|
|
70
|
+
<text class="t" x="145" y="391" text-anchor="middle" font-size="12" fill="#374151">2 小时</text>
|
|
71
|
+
|
|
72
|
+
<line class="rule" x1="46" y1="410" x2="374" y2="410"/>
|
|
73
|
+
<text class="sub" x="46" y="428">防抖、音效等高级参数在 cordis.patch.yml 中配置</text>
|
|
74
|
+
<path d="M332 419 l-3 3.2 3 3.2 M338 419 l3 3.2 -3 3.2" fill="none" stroke="#9aa0a8" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>
|
|
75
|
+
<text class="sub" x="352" y="428">v0.2.1</text>
|
|
64
76
|
</g>
|
|
65
77
|
</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
|
-
|
|
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
|
|