@laraveladmin/dsh-stay-awake 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # 变更记录 · Changelog
2
2
 
3
+ ## 0.3.4 — 2026-12-03
4
+
5
+ ### 修复
6
+
7
+ - **提问/审批提醒音根本没响**:根因是 waterfall 监听顺序。Web 桥(`dsh-api-remotes`)在本插件之前注册,
8
+ 而它的监听器回答了问题后**不会调用 `next()`**,所以注册在其后的监听器永远不执行。改用宿主
9
+ `sessionController.state().pendingInput`(含 `question` / `approval` / `other`)每 1.5 秒轮询一次——
10
+ 本地读取、不联网、与监听顺序无关;状态清空后立即停止重复提醒。
11
+ - **手动停止不再响完成音**:`aborted`(用户按停止/父级取消)、`blocked`、`interrupted`、`max-tokens`、
12
+ `forked` 一律静音;只有 `completed` 响完成音、`error` 响失败音。你在键盘前按的停止不需要"过来看看"。
13
+ - **目标(goal)不再逐阶段响**:goal 处于 armed 状态时阶段完成静音;activation 解除后的整段结束才响一次
14
+ (响哪一声取决于最后那个回合是完成还是出错)。中途的提问/审批提醒不受影响。
15
+ - 新增配置 `questionPollMs`(默认 1500,最小 200)。
16
+ - 测试 115 → **120 全绿**(轮询检测 question/approval、子代理会话提问、重复与停止、手动停止静音、
17
+ goal 阶段静音与结束响一次、goal 中途提问照响)。
18
+
19
+
3
20
  ## 0.3.3 — 2026-12-03
4
21
 
5
22
  ### 改进
package/README.en.md CHANGED
@@ -36,8 +36,10 @@ The rule is a pure function: `wanted = enabled && (agents + maintenance + jobs >
36
36
  Three moments each get one cue, played on the machine that runs the DSH host — they reach you even when the window is minimised.
37
37
 
38
38
  - **Done**: one chime per work segment (from work starting to everything finishing), including background jobs and multiple sessions. `Glass` by default.
39
+ - **You pressed stop**: silent. You are at the keyboard, and a "done" chime would be a lie.
40
+ - **Goals / autonomous work**: stage completions stay silent; the whole goal rings once when it disarms; a question or approval in the middle still rings.
39
41
  - **Failed**: only when the turn **really errored** (`error`). A stop you pressed, a rejected approval, a subagent wound down by its parent, `max-tokens` or `forked` do not count; when a work segment contains several turns, the **last ordinary-session turn** decides, so a retried success no longer rings the failure cue.
40
- - **Your turn**: the agent asked a question (`ask_user_question`) or a tool call waits for approval — rings immediately, `Ping` by default. This is the only cue that can fire while the turn is still open; without it the agent would wait for you in silence. One short cue is easy to miss, so it **repeats every 20 seconds until you answer** (capped at 10 minutes) and stops the moment the question is answered.
42
+ - **Your turn**: the agent asked a question (`ask_user_question`) or a tool call waits for approval — rings immediately, `Ping` by default. This is the only cue that can fire while the turn is still open; without it the agent would wait for you in silence. It is detected by reading the Host's `sessionState.pendingInput` every 1.5 seconds (local, no network). One short cue is easy to miss, so it **repeats every 20 seconds until you answer** (capped at 10 minutes) and stops the moment the question is answered.
41
43
  - Segments shorter than 20 seconds stay silent; autonomous goal/scheduled rounds stay silent (questions and approvals still ring).
42
44
  - The panel's **Sounds** master switch covers all three; three small buttons (Done / Error / Alert) audition each cue.
43
45
  - Sound files, volume, the minimum duration and whether questions ring live in `cordis.patch.yml`.
@@ -178,6 +180,7 @@ Override the row by id in the profile's `cordis.patch.yml`:
178
180
  questionSound: '' # custom "your turn" sound file (absolute path)
179
181
  questionRepeatSeconds: 20 # repeat the cue while unanswered, 0 = once
180
182
  questionRepeatMaxMinutes: 10 # longest repeat window
183
+ questionPollMs: 1500 # how often pending human input is checked
181
184
  soundVolume: 1 # 0-3, macOS/Linux
182
185
  successSound: '' # custom completion file (absolute path)
183
186
  errorSound: '' # custom failure file
package/README.md CHANGED
@@ -37,7 +37,9 @@ DSH 跑长任务时你离开电脑,系统按空闲策略休眠:进程被挂
37
37
 
38
38
  - **完成**:一次「工作段」(从有工作到全部结束)结束时响一次,含后台任务与多会话。默认 `Glass`。
39
39
  - **失败**:只有这一轮**真的报错**(`error`)才响,默认 `Basso`。你主动按停止、审批被拒、子代理被父轮次收尾、`max-tokens`/`forked` 这类结束都不算失败;一个工作段里有多个回合时,以**最后一个普通会话回合**的结果为准,重试成功不会还响失败音。
40
- - **需要你回答**:agent 用 `ask_user_question` 提问、或工具调用等审批时立刻响,默认 `Ping`——这是唯一一个「回合还没结束也响」的情况,否则它会一直静默等你。单声响很容易被错过,所以**在你回答之前每 20 秒重复一次**(最多 10 分钟),一旦回答就立刻停。
40
+ - **需要你回答**:agent 用 `ask_user_question` 提问、或工具调用等审批时立刻响,默认 `Ping`——这是唯一一个「回合还没结束也响」的情况,否则它会一直静默等你。检测方式是每 1.5 秒读一次宿主的 `sessionState.pendingInput`(本地、不联网);单声响容易被错过,所以**在你回答之前每 20 秒重复一次**(最多 10 分钟),一旦回答就立刻停。
41
+ - **你主动停止**:静音。你就在键盘前按的停止,不需要"过来看看",也不会再误响完成音。
42
+ - **目标(goal)/自主任务**:阶段完成保持静音;整个 goal 结束(activation 解除)后的那一整段结束才响一次;中途需要你回答/审批时照常响。
41
43
  - 短于 20 秒的任务不响;goal/定时任务等自主轮次不响,避免连响(但提问/审批仍然会提醒你)。
42
44
  - 弹层「提示音」总开关控制全部三种;旁边三个小按钮「完成 / 失败 / 提醒」可分别试听。
43
45
  - 音效文件、音量、最短时长、是否提醒提问在 `cordis.patch.yml` 配置。
@@ -179,6 +181,7 @@ DSH 默认不带任何索引源。添加本项目随 npm 包发布的索引文
179
181
  questionSound: '' # 自定义「提醒」音文件(绝对路径)
180
182
  questionRepeatSeconds: 20 # 未回答时每隔多久再响一次,0 = 只响一次
181
183
  questionRepeatMaxMinutes: 10 # 最多重复多久
184
+ questionPollMs: 1500 # 多久查一次「是否在等你回答」
182
185
  soundVolume: 1 # 0~3,macOS/Linux 生效
183
186
  successSound: '' # 自定义完成音文件(绝对路径)
184
187
  errorSound: '' # 自定义失败音文件
@@ -253,6 +253,24 @@
253
253
  - 关于「重启后试听点两次才出声」:定位为宿主重启后路由注册完成前的初始化窗口(首次点击落空),
254
254
  不是试听逻辑需要两次;`test-sound` 始终以 `force: true` 绕过节流。
255
255
 
256
+ ## 0.3.4 提醒音改用状态轮询、停止静音、目标只响结束(2026-12-03)
257
+
258
+ - **现场**:用户报告「有问题要回答时根本没有声音」。排查结论(读源码):
259
+ - `dsh-api-remotes` 用 `ctx.on` 注册 `user-questions/request` / `approval/request` 的 forwarder,它在
260
+ `dsh.profile.bundles` 里排在 bundle 顺序的前面(base → web-app → 本插件),因此先于本插件注册;
261
+ - waterfall 的语义是监听器调用 `next()` 才继续下一位,而 Web 桥把问题转发给浏览器并**直接返回答案**,
262
+ 不再调用 `next()` → 注册在其后的本插件监听器**永远不会执行**。这解释了「试听有声音、提问没声音」。
263
+ - **改法**:轮询宿主 `sessionController.state({ sessionId }).pendingInput`,它由宿主自己根据
264
+ `approval/request` / `user-questions/request` 维护(`dsh-api-session-controller/src/state/controller.ts`),
265
+ 与监听顺序无关;默认 1.5 秒一次、只读本地状态。检测到 `question|approval|other` → 响一次并每 20 秒重复,
266
+ 状态清空立即停止。
267
+ - **手动停止**:`aborted` / `blocked` / `interrupted` / `max-tokens` / `forked` 归为 `silent`,不再响完成音。
268
+ - **目标(goal)**:监听 `goal/activation-changed`;armed 期间阶段完成静音,解除后的整段结束响一次
269
+ (成功/失败取决于最后回合),中途提问照响(不受 goal 静音影响,也不受 `soundOnlyUserTasks` 限制)。
270
+ - 自动化:接线测试新增 5 项(轮询 question/approval、子代理会话、重复与停止、手动停止、goal 三态),
271
+ 115 → **120 全绿**。
272
+ - 未验证:真实 UI 上「提问时能听到 Ping、回答后停止」与真实 goal 结束那一声,需要重启宿主后实测。
273
+
256
274
  ## 未验证(明确记录,不代替验证)
257
275
 
258
276
  | ID / 项 | 原因 | 何时可验 |
package/index.js CHANGED
@@ -99,20 +99,33 @@ export function start(ctx, rawConfig, deps = {}) {
99
99
  let wasWorking = false
100
100
  let workStartedAt = 0
101
101
  let pendingUserSound = false
102
- let lastOutcome = 'ok'
103
- // Only a real failure is a failure for the person listening. DSH's own chat
104
- // view shows no failure row for `aborted` (user stop, parent cleanup),
105
- // `blocked` (a guard rejected a step), `max-tokens` or `forked`; those are
106
- // routine endings, and treating them as errors made successful work ring the
107
- // failure cue.
108
- const SOUND_ERROR_KINDS = new Set(['error'])
102
+ /**
103
+ * How this segment ended: `done` rings the completion cue, `error` the failure
104
+ * cue, and `silent` rings nothing. A stop you pressed, a blocked guard, a
105
+ * `max-tokens` or `forked` ending are neither success nor failure, so they
106
+ * must not claim "done" — DSH's own chat view shows no failure row for them
107
+ * either.
108
+ */
109
+ let lastEnding = 'done'
110
+ /** Session that produced `lastEnding`; a goal there silences its stage edges. */
111
+ let lastEndingSession = null
112
+ /** Sessions whose goal is armed (the autonomous loop keeps running turns). */
113
+ const goalSessions = new Set()
114
+ /** A goal disarmed during this segment: its completion rings once at the end. */
115
+ let goalJustFinished = false
109
116
 
110
117
  function maybeRing(durationMs) {
111
118
  try {
112
119
  if (!config.enabled || !config.sound) return
113
- if (config.soundOnlyUserTasks && !pendingUserSound) return
120
+ if (lastEnding === 'silent') return
121
+ // A goal continues turn after turn; its stage edges stay silent and only
122
+ // the segment after the disarm rings, so "goal finished" is heard once.
123
+ const goalRunning = lastEndingSession !== null && goalSessions.has(lastEndingSession)
124
+ if (goalRunning && !goalJustFinished) return
125
+ const goalEnded = goalJustFinished
126
+ if (!goalEnded && config.soundOnlyUserTasks && !pendingUserSound) return
114
127
  if (config.soundMinSeconds > 0 && durationMs < config.soundMinSeconds * 1000) return
115
- const kind = config.soundOnError && lastOutcome === 'error' ? 'error' : 'success'
128
+ const kind = config.soundOnError && lastEnding === 'error' ? 'error' : 'success'
116
129
  sound.play(kind)
117
130
  } catch (error) {
118
131
  log.warn(`stay-awake: notification sound failed: ${describe(error)}`)
@@ -162,9 +175,12 @@ export function start(ctx, rawConfig, deps = {}) {
162
175
 
163
176
  // ---- "your turn": the agent is waiting for an answer or an approval ----
164
177
  /**
165
- * These two are waterfall events, so the listener asks for a sound and then
166
- * hands the request back untouched. Ringing is best effort: a missing player
167
- * or a closed sound switch must never affect the question itself.
178
+ * Why this polls instead of listening to the waterfall events: the web
179
+ * bridge that answers `user-questions/request` / `approval/request` is
180
+ * registered before this plugin, and a waterfall listener that answers does
181
+ * not call `next()`, so a later listener never runs. The Host's passive
182
+ * `sessionState.pendingInput` carries exactly the same fact and does not
183
+ * depend on listener order.
168
184
  */
169
185
  const ringQuestion = () => {
170
186
  try {
@@ -175,39 +191,121 @@ export function start(ctx, rawConfig, deps = {}) {
175
191
  }
176
192
  }
177
193
 
194
+ let attentionTimer = null
195
+ let attentionSince = 0
196
+ let attentionActive = false
197
+
198
+ function stopAttentionRepeats() {
199
+ if (attentionTimer !== null && typeof clearInterval === 'function') clearInterval(attentionTimer)
200
+ attentionTimer = null
201
+ }
202
+
178
203
  /**
179
- * A single short cue is easy to miss when the user is away from the screen,
180
- * so the alert repeats while the question or approval is still unanswered and
181
- * stops the moment it is answered (the waterfall result settles).
182
- * @returns {() => void} stop the repeats
204
+ * A single short cue is easy to miss while the user is away, so the alert
205
+ * repeats while anything still waits for a human and stops the moment the
206
+ * state clears.
207
+ * @param {boolean} active
183
208
  */
184
- function startQuestionReminder() {
209
+ function setAttention(active) {
210
+ if (active === attentionActive) return
211
+ attentionActive = active
212
+ if (!active) {
213
+ attentionSince = 0
214
+ stopAttentionRepeats()
215
+ return
216
+ }
217
+ attentionSince = clockNow()
185
218
  ringQuestion()
186
219
  const repeatMs = Number(config.questionRepeatSeconds) * 1_000
187
220
  const maxMs = Number(config.questionRepeatMaxMinutes) * 60_000
188
- if (!(repeatMs > 0) || !(maxMs > 0) || typeof setInterval !== 'function') return () => {}
189
- const deadline = clockNow() + maxMs
190
- const timer = setInterval(() => {
191
- if (clockNow() >= deadline) {
192
- clearInterval(timer)
221
+ if (!(repeatMs > 0) || !(maxMs > 0) || typeof setInterval !== 'function') return
222
+ stopAttentionRepeats()
223
+ attentionTimer = setInterval(() => {
224
+ if (clockNow() - attentionSince >= maxMs) {
225
+ stopAttentionRepeats()
193
226
  return
194
227
  }
195
228
  ringQuestion()
196
229
  }, repeatMs)
197
- if (typeof timer.unref === 'function') timer.unref()
198
- return () => clearInterval(timer)
230
+ if (typeof attentionTimer.unref === 'function') attentionTimer.unref()
199
231
  }
200
232
 
233
+ async function pollHumanInput() {
234
+ if (!config.enabled || !config.sound || config.soundOnQuestion !== true) {
235
+ setAttention(false)
236
+ return
237
+ }
238
+ const sessionController = ctx.get('sessionController')
239
+ if (sessionController === undefined || sessionController === null
240
+ || typeof sessionController.state !== 'function') return
241
+ let agents = []
242
+ try {
243
+ agents = ctx.agents.list()
244
+ } catch {
245
+ agents = []
246
+ }
247
+ let pending = false
248
+ for (const agent of agents) {
249
+ const session = agent?.session
250
+ if (session === undefined || session === null) continue
251
+ try {
252
+ const state = await sessionController.state({ sessionId: session.id })
253
+ const input = Array.isArray(state?.pendingInput) ? state.pendingInput : []
254
+ if (input.includes('question') || input.includes('approval') || input.includes('other')) {
255
+ pending = true
256
+ break
257
+ }
258
+ } catch {
259
+ // A cold or disposed session answers nothing; keep looking at the rest.
260
+ }
261
+ }
262
+ setAttention(pending)
263
+ }
264
+
265
+ ctx.effect(() => {
266
+ const timer = setInterval(() => {
267
+ Promise.resolve(pollHumanInput()).catch(() => {})
268
+ }, Number(config.questionPollMs) || 1_500)
269
+ if (typeof timer.unref === 'function') timer.unref()
270
+ return () => {
271
+ clearInterval(timer)
272
+ setAttention(false)
273
+ }
274
+ }, 'stay-awake: human attention')
275
+
276
+ // A goal keeps the turn loop going; its disarm is the moment the whole
277
+ // autonomous run is over, so that segment may ring even without a user prompt.
278
+ ctx.effect(() => {
279
+ try {
280
+ return ctx.on('goal/activation-changed', (payload) => {
281
+ const sessionId = payload?.sessionId
282
+ if (typeof sessionId !== 'string') return
283
+ if (payload?.goal?.activation === 'armed') {
284
+ goalSessions.add(sessionId)
285
+ return
286
+ }
287
+ if (goalSessions.delete(sessionId)) goalJustFinished = true
288
+ })
289
+ } catch (error) {
290
+ log.warn(`stay-awake: could not subscribe to goal/activation-changed: ${describe(error)}`)
291
+ return () => {}
292
+ }
293
+ }, 'stay-awake: goal activation')
294
+
201
295
  const sync = () => {
202
296
  const working = activity.hasWork(config)
203
297
  if (working && !wasWorking) {
204
298
  workStartedAt = clockNow()
205
- lastOutcome = 'ok'
299
+ lastEnding = 'done'
300
+ lastEndingSession = null
301
+ goalJustFinished = false
206
302
  }
207
303
  if (!working && wasWorking) {
208
304
  maybeRing(clockNow() - workStartedAt)
209
305
  pendingUserSound = false
210
- lastOutcome = 'ok'
306
+ lastEnding = 'done'
307
+ lastEndingSession = null
308
+ goalJustFinished = false
211
309
  }
212
310
  wasWorking = working
213
311
  controller.update(activity.counts(config))
@@ -255,7 +353,11 @@ export function start(ctx, rawConfig, deps = {}) {
255
353
  if (event?.type === 'turn/end') {
256
354
  // The *last* ordinary turn decides the cue: a failure the user then
257
355
  // retried into a success must not keep the failure sound.
258
- if (ordinary) lastOutcome = SOUND_ERROR_KINDS.has(event.data?.reason?.kind) ? 'error' : 'ok'
356
+ if (ordinary) {
357
+ const kind = event.data?.reason?.kind
358
+ lastEnding = kind === 'error' ? 'error' : kind === 'completed' ? 'done' : 'silent'
359
+ lastEndingSession = session?.id ?? null
360
+ }
259
361
  return
260
362
  }
261
363
  if (config.includeMaintenance !== true) return
@@ -279,34 +381,6 @@ export function start(ctx, rawConfig, deps = {}) {
279
381
  }
280
382
  }, 'stay-awake: activity sources')
281
383
 
282
- ctx.effect(() => {
283
- const listen = (name) => {
284
- try {
285
- return ctx.on(name, async (_payload, next) => {
286
- const stop = startQuestionReminder()
287
- try {
288
- return typeof next === 'function' ? await next() : undefined
289
- } finally {
290
- stop()
291
- }
292
- })
293
- } catch (error) {
294
- log.warn(`stay-awake: could not subscribe to ${name}: ${describe(error)}`)
295
- return () => {}
296
- }
297
- }
298
- const disposers = [listen('user-questions/request'), listen('approval/request')]
299
- return () => {
300
- for (const dispose of disposers) {
301
- try {
302
- dispose()
303
- } catch {
304
- // Unloading is best effort.
305
- }
306
- }
307
- }
308
- }, 'stay-awake: question sound')
309
-
310
384
  const jobs = ctx.get('jobs')
311
385
  if (jobs !== undefined && jobs !== null && config.includeBackgroundJobs) {
312
386
  ctx.effect(() => {
package/lib/config.js CHANGED
@@ -30,6 +30,9 @@ export const DEFAULTS = Object.freeze({
30
30
  // while the question or approval is still waiting for the human.
31
31
  questionRepeatSeconds: 20,
32
32
  questionRepeatMaxMinutes: 10,
33
+ // How often the host asks its own session state whether a human answer is
34
+ // pending. Cheap, local, and it sees approvals the waterfall bridge answers.
35
+ questionPollMs: 1500,
33
36
  soundVolume: 1,
34
37
  // "Retry the turn that died with the network": on by default, but it only
35
38
  // fires for a lost connection, never for a user abort or an approval wait.
@@ -114,6 +117,7 @@ export function normalizeConfig(raw) {
114
117
  soundOnQuestion: asBoolean(input.soundOnQuestion, DEFAULTS.soundOnQuestion),
115
118
  questionRepeatSeconds: asNumber(input.questionRepeatSeconds, DEFAULTS.questionRepeatSeconds, { min: 0, max: 60 * 30 }),
116
119
  questionRepeatMaxMinutes: asNumber(input.questionRepeatMaxMinutes, DEFAULTS.questionRepeatMaxMinutes, { min: 0, max: 24 * 60 }),
120
+ questionPollMs: asNumber(input.questionPollMs, DEFAULTS.questionPollMs, { min: 200, max: 10_000 }),
117
121
  soundVolume: asNumber(input.soundVolume, DEFAULTS.soundVolume, { min: 0, max: 3 }),
118
122
  autoResume: asBoolean(input.autoResume, DEFAULTS.autoResume),
119
123
  autoResumeCodes: asCodes(input.autoResumeCodes, DEFAULTS.autoResumeCodes),
package/market/index.json CHANGED
@@ -51,8 +51,8 @@
51
51
  },
52
52
  "versions": [
53
53
  {
54
- "version": "0.3.3",
55
- "publishTimestamp": 1796365892,
54
+ "version": "0.3.4",
55
+ "publishTimestamp": 1796366608,
56
56
  "source": {
57
57
  "type": "npm"
58
58
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laraveladmin/dsh-stay-awake",
3
- "version": "0.3.3",
3
+ "version": "0.3.4",
4
4
  "description": "DeepSeek Harness plugin that keeps the machine awake only while unattended work runs, and retries the turn that died with the network once it is back.",
5
5
  "keywords": [
6
6
  "dsh-plugin",