dsh-caffeinate 0.1.0 → 0.1.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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.1] - 2026-11-29
4
+
5
+ ### Changed
6
+
7
+ - **Behaviour change:** the default `mode` is now `running-only` in the Config schema,
8
+ bundle patch and runtime normalization; omitted or invalid modes also fall back to
9
+ `running-only`. `enabled` remains `true`. On macOS, sleep is prevented only while
10
+ an agent turn runs, with up to 15 seconds of start/stop polling delay.
11
+ - `mode: always` remains an explicit opt-in to keeping the machine awake for the
12
+ whole DSH session; existing explicit `always` configurations retain that behaviour.
13
+ - Added `/keepawake always` (existing `on` / `start` aliases retained); runtime
14
+ switching uses `/keepawake always|running|off`. Updated help, status, both READMEs
15
+ and locales to describe the defaults and macOS-only support.
16
+ - Read the host agent registry through `list()` (with a `values()` fallback) and
17
+ slash-command input through `rawInput` (with an `args` fallback) to match DSH 0.2.2-rc.5.
18
+ - Declared engines: Node `>=20` and DSH `>=0.2.2-rc.1 <0.3.0`.
19
+
3
20
  ## [0.1.0] - 2026-11-11
4
21
 
5
22
  First public release.
package/README.en.md CHANGED
@@ -1,4 +1,4 @@
1
- # dsh-caffeinate — keep the Mac awake while DSH runs
1
+ # dsh-caffeinate — keep the Mac awake while agent turns run
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
4
4
  [![Node 20](https://img.shields.io/badge/node-20-blue.svg)](./.github/workflows/ci.yml)
@@ -6,11 +6,11 @@
6
6
 
7
7
  <!-- npm badge: add https://img.shields.io/npm/v/dsh-caffeinate once the package is published -->
8
8
 
9
- > A host-side DSH plugin: it spawns the `caffeinate` that ships with macOS and binds the assertion to the DSH main process with `-w`. When the host goes away, the assertion goes away. The display still sleeps as usual.
9
+ > **macOS only. Defaults to `enabled: true`, `mode: running-only`: awake only while an agent turn runs, with up to 15 seconds of start/stop polling delay.** Opting into `mode: always` keeps the machine awake for the whole DSH session, even when no task is running. Switch at runtime with `/keepawake always|running|off`; changes are not persisted. The plugin uses macOS's built-in `caffeinate` with `-w` to bind assertions to the DSH main process. When the host exits, assertions are released; the display may still sleep by default.
10
10
 
11
11
  ## What it does
12
12
 
13
- 1. **Spawns one `caffeinate` child** — on plugin load it runs `spawn("/usr/bin/caffeinate", args)` with `stdio: "ignore"`, `detached: false`, then `unref()`, so it never holds the host open.
13
+ 1. **Spawns one `caffeinate` child when the mode requires it** — on plugin load it checks for a running agent turn in the default `running-only` mode; no child starts while idle. It uses `spawn("/usr/bin/caffeinate", args)` with `stdio: "ignore"`, `detached: false`, then `unref()`, so it never holds the host open.
14
14
  2. **Arguments come from settings, with `-w <host pid>` always appended** — the default build is `/usr/bin/caffeinate -i -s -m -w <pid>`; no `-d` unless display sleep prevention is enabled.
15
15
  3. **The assertion is bound to the host process** — `-w` in `caffeinate(8)` means "wait for the process with the specified pid to exit; once it exits, the assertion is also released". A DSH exit or kill therefore does not leave an orphaned `caffeinate` holding the machine awake.
16
16
  4. **Re-checks every 15 seconds** — `setInterval(reconcile, 15000)`: in `always` mode a missing child is restarted; in `running-only` mode the child is started and stopped based on whether any agent is running.
@@ -30,7 +30,7 @@
30
30
  | all four off | — | fallback `-i` | if the flag list is empty, `-i` is added |
31
31
  | always appended | — | `-w <pid>` | watch the host process, `process.pid` |
32
32
 
33
- With the defaults the real command line is:
33
+ Once the default `running-only` mode detects a running agent turn, the command line is (`-d` is off by default):
34
34
 
35
35
  ```text
36
36
  /usr/bin/caffeinate -i -s -m -w <DSH main process PID>
@@ -46,7 +46,7 @@ With the defaults the real command line is:
46
46
  | Every 15 s | `setInterval` calls `reconcile()` again; the timer is `unref()`ed |
47
47
  | Plugin unload | `clearInterval` + `kill("SIGTERM")` on the child |
48
48
  | Host process gone | `caffeinate -w` releases the assertion and exits on its own |
49
- | Child exits or fails to start | `exit` / `error` handlers clear `state.child`; the next `reconcile()` restarts it, errors land in `state.lastError` |
49
+ | Child exits or fails to start | `exit` / `error` handlers clear `state.child`; the next `reconcile()` decides whether to restart it based on the mode and agent status; errors land in `state.lastError` |
50
50
 
51
51
  ### The three `reconcile()` outcomes
52
52
 
@@ -54,7 +54,7 @@ With the defaults the real command line is:
54
54
  - `mode === "always"` → start a child if there is none;
55
55
  - `mode === "running-only"` → start only if some agent has `status === "running"`, otherwise stop.
56
56
 
57
- That check reads the host's `agents` service and scans its `values()` for `status`.
57
+ That check reads the host's `agents` service, obtains agents through `list()` (falling back to `values()` for registries that only expose that method), and scans their `status`. DSH 0.2.2-rc.5 exposes `list()`.
58
58
 
59
59
  ## Install
60
60
 
@@ -84,6 +84,8 @@ Ask the agent inside DSH to install `dsh-caffeinate`; it calls `plugin_manager`:
84
84
 
85
85
  `index.js` needs `@deepseek-ai/schemastery` for host-side config validation. **DSH ships that package**, so a normal install needs nothing extra; `package.json` declares it under `peerDependencies` (`>=3.0.0-0`) only to state the relationship. This repo ships no `node_modules`.
86
86
 
87
+ The plugin declares Node `>=20` and DSH `>=0.2.2-rc.1 <0.3.0`. The host may require a newer Node version: DSH 0.2.2-rc.5 requires Node `>=24.9.0`.
88
+
87
89
  ## Configuration
88
90
 
89
91
  Settings live in the plugin's standard form (Schemastery `Config`):
@@ -91,13 +93,15 @@ Settings live in the plugin's standard form (Schemastery `Config`):
91
93
  | Key | Type | Default | Notes |
92
94
  | --- | --- | --- | --- |
93
95
  | `enabled` | boolean | `true` | master switch |
94
- | `mode` | `"always"` \| `"running-only"` | `"always"` | `always` = stay awake the whole time DSH is open; `running-only` = only while an agent is executing |
96
+ | `mode` | `"always"` \| `"running-only"` | `"running-only"` | default: awake only while an agent turn runs; opt into `always` to stay awake for the whole DSH session |
95
97
  | `preventIdleSystemSleep` | boolean | `true` | maps to `-i` |
96
98
  | `preventSystemSleepOnAC` | boolean | `true` | maps to `-s` |
97
99
  | `preventDiskSleep` | boolean | `true` | maps to `-m` |
98
100
  | `preventDisplaySleep` | boolean | `false` | maps to `-d`; off by default so the display still sleeps and locks |
99
101
 
100
- Invalid values (`normalizeConfig`): booleans are `true` unless explicitly `false`; `mode` is `"always"` unless explicitly `"running-only"`; `preventDisplaySleep` goes through `Boolean()`, so anything not truthy becomes `false`.
102
+ Invalid values (`normalizeConfig`): booleans are `true` unless explicitly `false`; `mode` is `"always"` only when explicitly set to `"always"`, otherwise omitted or invalid values fall back to `"running-only"`; `preventDisplaySleep` goes through `Boolean()`, so anything not truthy becomes `false`.
103
+
104
+ Upgrading does not overwrite a saved `mode: always`. If an earlier install saved the old default, change it to `mode: running-only`; `/keepawake running` switches only the current runtime.
101
105
 
102
106
  Config is read once at `apply()` time; there is no config-change listener in the code.
103
107
 
@@ -108,10 +112,10 @@ Config is read once at `apply()` time; there is no config-change listener in the
108
112
  | Input | In-memory change | Restarts the child |
109
113
  | --- | --- | --- |
110
114
  | `/keepawake status` (or empty, or any unrecognized word) | none | no, report only |
111
- | `/keepawake on` / `start` | `enabled=true`, `mode=always`, display policy reset to the configured `preventDisplaySleep` | yes (stop then start; PID and uptime reset) |
115
+ | `/keepawake always` / `on` / `start` | opt into staying awake for the whole DSH session: `enabled=true`, `mode=always`, display policy reset to the configured `preventDisplaySleep` | yes (stop then start; PID and uptime reset) |
112
116
  | `/keepawake display` / `screen` | `enabled=true`, `mode=always`, `preventDisplaySleep=true` | yes |
113
117
  | `/keepawake nodisplay` / `headless` | `enabled=true`, `mode=always`, `preventDisplaySleep=false` | yes |
114
- | `/keepawake running` / `auto` | `enabled=true`, `mode=running-only` | no, left to `reconcile()` |
118
+ | `/keepawake running` / `auto` | switch to the default mode: `enabled=true`, `mode=running-only`, awake only while an agent turn runs | no, left to `reconcile()` |
115
119
  | `/keepawake off` / `stop` | `enabled=false` | yes (stop) |
116
120
 
117
121
  Note that `status` is not a branch of its own: there is no `status` check in the code, so it lands on the same report-only default path as an unknown word.
@@ -120,14 +124,14 @@ Every invocation returns the same report: state, current `mode`, the exact spawn
120
124
 
121
125
  ## Known limitations
122
126
 
123
- - **macOS only.** On any platform other than `darwin` nothing is spawned and `state.lastError` records an unsupported-platform message; the `pmset` part of the report says so too.
127
+ - **macOS only.** On any platform other than `darwin` nothing is spawned; both the status and `pmset` parts of the report say the platform is unsupported. An attempted start also records the unsupported platform in `state.lastError`.
124
128
  - **Requires `/usr/bin/caffeinate`** (bundled with macOS). The plugin does not check for it or advise on install; a failed `spawn` only shows up in `lastError`.
125
129
  - **`-w` watches the host main process pid.** Processes DSH forks are outside the binding: their absence cannot keep `caffeinate` alive and their presence cannot extend it — when the main process goes, this layer of assertion ends.
126
130
  - **`running-only` depends on the host exposing an `agents` service** with `status === "running"`. When that service is unavailable the check is always false, so this mode never starts `caffeinate` (it fails toward not holding the machine awake).
127
131
  - **15-second polling**: start/stop in `running-only` can lag by up to 15 seconds; it is not event driven.
128
132
  - **Command changes are not persisted**: `/keepawake` only mutates in-memory state. A plugin reload returns to the configured values.
129
133
  - **`/keepawake display` and `/keepawake nodisplay` force `mode` to `always`**: "display stays on" and "only while an agent runs" cannot currently be combined.
130
- - **`/keepawake on` does not force the display to stay on** — it restores the display policy from config, so if `preventDisplaySleep` is `false` the display still sleeps.
134
+ - **`/keepawake always` (aliases `on` / `start`) does not force the display to stay on** — it restores the display policy from config, so if `preventDisplaySleep` is `false` the display still sleeps.
131
135
  - **`-s` is only effective on AC power**; that is `caffeinate`'s own semantics, and the plugin does not inspect power state.
132
136
  - **Assertions are not merged**: if the machine also runs a system-level `caffeinate` (for example the resident LaunchAgent in `examples/com.user.caffeinate.plist`), both layers hold assertions at once and `/keepawake off` only turns off the plugin's layer.
133
137
  - **No unit tests**: the gate is `node --check` plus the sanitization scan; `scripts/sanitize-check.mjs` checks text, not behavior.
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # dsh-caffeinate — DSH 运行期间不让 Mac 睡过去
1
+ # dsh-caffeinate — Agent 轮次运行时不让 Mac 睡过去
2
2
 
3
3
  [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE)
4
4
  [![Node 20](https://img.shields.io/badge/node-20-blue.svg)](./.github/workflows/ci.yml)
@@ -6,11 +6,11 @@
6
6
 
7
7
  <!-- npm 徽章:`dsh-caffeinate` 发布后再补 https://img.shields.io/npm/v/dsh-caffeinate -->
8
8
 
9
- > 一个 Host 侧 DSH 插件:拉一个 macOS 自带的 `caffeinate` 子进程,用 `-w` 把防休眠断言绑到 DSH 主进程上。宿主没了,断言跟着没;屏幕该息屏还是息屏。
9
+ > **仅 macOS。默认 `enabled: true`、`mode: running-only`:仅当有 Agent 轮次运行时防休眠,起停最多有 15 秒轮询延迟。** 主动设置 `mode: always` 会在整个 DSH 会话期间保持机器唤醒,即使没有任务运行。用 `/keepawake always|running|off` 在运行时切换;改动不落盘。插件使用 macOS 自带的 `caffeinate`,用 `-w` 把断言绑定到 DSH 主进程;宿主退出,断言释放,默认允许屏幕正常息屏。
10
10
 
11
11
  ## 它做什么
12
12
 
13
- 1. **拉起一个 `caffeinate` 子进程** —— 插件加载时 `spawn("/usr/bin/caffeinate", args)`,`stdio: "ignore"`、`detached: false`,随后 `unref()`,不拖住宿主退出。
13
+ 1. **按模式拉起一个 `caffeinate` 子进程** —— 插件加载时先检查:默认 `running-only` 仅在有运行中的 Agent 轮次时 `spawn("/usr/bin/caffeinate", args)`;空闲时不拉起。使用 `stdio: "ignore"`、`detached: false`,随后 `unref()`,不拖住宿主退出。
14
14
  2. **参数由设置决定,末尾固定 `-w <Host PID>`** —— 默认拼出来是 `/usr/bin/caffeinate -i -s -m -w <pid>`;不勾「阻止显示器休眠」就不带 `-d`。
15
15
  3. **断言绑在宿主进程上** —— `-w` 的语义来自 `caffeinate(8)`:「等待指定 pid 的进程退出,进程退出后断言一并释放」。所以 DSH 正常退出或被杀掉之后,不会留下一个继续压着系统的孤儿 `caffeinate`。
16
16
  4. **每 15 秒自检一次** —— `setInterval(reconcile, 15000)`:`always` 模式下子进程没了就重拉;`running-only` 模式下按「有没有正在执行的 agent」决定起停。
@@ -30,7 +30,7 @@
30
30
  | 四个全关时 | — | 兜底 `-i` | 代码里 flags 为空会补一个 `-i` |
31
31
  | 固定尾部 | — | `-w <pid>` | 监视宿主进程,`process.pid` |
32
32
 
33
- 默认全开(`-d` 除外)时,实际命令行是:
33
+ 默认 `running-only` 检测到运行中的 Agent 轮次后,使用的命令行是(`-d` 默认关闭):
34
34
 
35
35
  ```text
36
36
  /usr/bin/caffeinate -i -s -m -w <DSH 主进程 PID>
@@ -46,7 +46,7 @@
46
46
  | 每 15 秒 | `setInterval` 再跑一次 `reconcile()`,定时器 `unref()` |
47
47
  | 插件卸载 | `clearInterval` + 对子进程 `kill("SIGTERM")` |
48
48
  | 宿主进程消失 | 由 `caffeinate -w` 自行释放断言并退出 |
49
- | 子进程自己退出 / 起不来 | `exit` / `error` 回调把 `state.child` 清空,下一次 `reconcile()` 重拉;错误记进 `state.lastError` |
49
+ | 子进程自己退出 / 起不来 | `exit` / `error` 回调把 `state.child` 清空,下一次 `reconcile()` 按当前模式和 Agent 状态决定是否重拉;错误记进 `state.lastError` |
50
50
 
51
51
  ### `reconcile()` 的三种结果
52
52
 
@@ -54,7 +54,7 @@
54
54
  - `mode === "always"` → 没有子进程就起一个;
55
55
  - `mode === "running-only"` → 有 `status === "running"` 的 agent 才起,否则停。
56
56
 
57
- 判断方式是从宿主取 `agents` 服务,遍历其 `values()` 看 `status`。
57
+ 判断方式是从宿主取 `agents` 服务,通过 `list()` 获取 Agent,兼容仅提供 `values()` 的注册表,再遍历检查 `status`。DSH 0.2.2-rc.5 提供的是 `list()`。
58
58
 
59
59
  ## 安装
60
60
 
@@ -84,6 +84,8 @@
84
84
 
85
85
  `index.js` 需要 `@deepseek-ai/schemastery`(Host 侧配置校验)。**DSH 自带这个包**,正常安装不需要另装;`package.json` 里它是 `peerDependencies`(`>=3.0.0-0`),只用来把依赖关系写明。本仓库不带 `node_modules`。
86
86
 
87
+ 插件声明 Node `>=20`、DSH `>=0.2.2-rc.1 <0.3.0`。宿主自身可能要求更高版本:DSH 0.2.2-rc.5 的 Node 要求为 `>=24.9.0`。
88
+
87
89
  ## 配置
88
90
 
89
91
  配置项在插件的标准设置表单里(Schemastery `Config`):
@@ -91,13 +93,15 @@
91
93
  | 键 | 类型 | 默认值 | 说明 |
92
94
  | --- | --- | --- | --- |
93
95
  | `enabled` | boolean | `true` | 是否启用守护 |
94
- | `mode` | `"always"` \| `"running-only"` | `"always"` | `always` = DSH 打开期间一直防休眠;`running-only` = 只有 agent 在执行时才防休眠 |
96
+ | `mode` | `"always"` \| `"running-only"` | `"running-only"` | 默认仅 Agent 轮次运行时防休眠;主动设置 `always` 会在整个 DSH 会话期间防休眠 |
95
97
  | `preventIdleSystemSleep` | boolean | `true` | 对应 `-i` |
96
98
  | `preventSystemSleepOnAC` | boolean | `true` | 对应 `-s` |
97
99
  | `preventDiskSleep` | boolean | `true` | 对应 `-m` |
98
100
  | `preventDisplaySleep` | boolean | `false` | 对应 `-d`;默认关闭,屏幕照常息屏锁屏 |
99
101
 
100
- 非法值的行为(`normalizeConfig`):布尔项除显式 `false` 外都按 `true`;`mode` 除显式 `"running-only"` 外都按 `"always"`;`preventDisplaySleep` 走 `Boolean()`,非真值即 `false`。
102
+ 非法值的行为(`normalizeConfig`):布尔项除显式 `false` 外都按 `true`;`mode` 仅显式 `"always"` 才按 `"always"`,省略或其他值均回退为 `"running-only"`;`preventDisplaySleep` 走 `Boolean()`,非真值即 `false`。
103
+
104
+ 升级不会覆盖已保存的 `mode: always`。若此前安装时保存了旧默认值,请改为 `mode: running-only`;`/keepawake running` 只切换本次运行。
101
105
 
102
106
  配置在 `apply()` 时读一次即定型,代码里没有监听配置变更的分支。
103
107
 
@@ -108,10 +112,10 @@
108
112
  | 输入 | 内存状态变化 | 是否重启子进程 |
109
113
  | --- | --- | --- |
110
114
  | `/keepawake status`(或空、或任何未识别的词) | 无 | 否,只报告 |
111
- | `/keepawake on` / `start` | `enabled=true`、`mode=always`、屏幕策略回到配置里的 `preventDisplaySleep` 值 | 是(先停再起,PID 与运行时长归零) |
115
+ | `/keepawake always` / `on` / `start` | 主动选择整个 DSH 会话期间防休眠:`enabled=true`、`mode=always`、屏幕策略回到配置里的 `preventDisplaySleep` 值 | 是(先停再起,PID 与运行时长归零) |
112
116
  | `/keepawake display` / `screen` | `enabled=true`、`mode=always`、`preventDisplaySleep=true` | 是 |
113
117
  | `/keepawake nodisplay` / `headless` | `enabled=true`、`mode=always`、`preventDisplaySleep=false` | 是 |
114
- | `/keepawake running` / `auto` | `enabled=true`、`mode=running-only` | 否,交给 `reconcile()` 决定 |
118
+ | `/keepawake running` / `auto` | 切换到默认模式:`enabled=true`、`mode=running-only`,仅 Agent 轮次运行时防休眠 | 否,交给 `reconcile()` 决定 |
115
119
  | `/keepawake off` / `stop` | `enabled=false` | 是(停) |
116
120
 
117
121
  注意 `status` 不是独立分支:代码里没有 `status` 判断,它和不认识的词一样落到「只报告」这条默认路径上。
@@ -120,14 +124,14 @@
120
124
 
121
125
  ## 已知限制
122
126
 
123
- - **仅 macOS**。非 `darwin` 平台不会 `spawn`,`state.lastError` 记下「不支持的操作系统平台」,指令报告里能看到;`pmset` 那一段也会说明平台不支持。
127
+ - **仅 macOS**。非 `darwin` 平台不会 `spawn`,指令状态与 `pmset` 部分均说明平台不支持;尝试启动时 `state.lastError` 也会记录不支持的平台。
124
128
  - **需要 `/usr/bin/caffeinate` 存在**(macOS 自带)。插件不检查路径、不做安装提示;`spawn` 失败只会进 `lastError`。
125
129
  - **`-w` 绑的是宿主主进程 pid**。DSH fork 出去的进程不在绑定范围内:它们不在时不会让 `caffeinate` 续命,它们还在时也不会让 `caffeinate` 多活——主进程一走,这一层断言就结束。
126
130
  - **`running-only` 依赖宿主暴露 `agents` 服务**,且 agent 的 `status` 为 `"running"`。取不到该服务时判断恒为「没有正在执行的 agent」,结果是这个模式下不会拉起 `caffeinate`(宁可不防,也不乱防)。
127
131
  - **15 秒轮询**:`running-only` 的起停最多有 15 秒延迟,不是事件驱动的即时反应。
128
132
  - **指令改动不落盘**:`/keepawake` 只改内存里的状态,不写配置。重载插件后回到配置文件里的值。
129
133
  - **`/keepawake display`、`/keepawake nodisplay` 会把 `mode` 强制成 `always`**:想同时保持「屏幕常亮 + 仅任务执行时防休眠」当前做不到,得二选一。
130
- - **`/keepawake on` 不会强制开屏幕常亮**,它把屏幕策略恢复成配置里的值——如果配置里 `preventDisplaySleep` 是 `false`,它就是关的。
134
+ - **`/keepawake always`(别名 `on` / `start`)不会强制开屏幕常亮**,它把屏幕策略恢复成配置里的值——如果配置里 `preventDisplaySleep` 是 `false`,它就是关的。
131
135
  - **`-s` 只在交流电下有效**,这是 `caffeinate` 自身语义,插件不额外判断电源状态。
132
136
  - **不改断言的叠加关系**:若机器上另有系统级 `caffeinate`(例如 `examples/com.user.caffeinate.plist` 那种常驻 LaunchAgent),两层断言会同时存在,`/keepawake off` 只关插件这一层。
133
137
  - **没有单元测试**:门禁是 `node --check` 加脱敏扫描,`scripts/sanitize-check.mjs` 不覆盖行为。
package/cordis.patch.yml CHANGED
@@ -3,7 +3,8 @@
3
3
  # 由 DSH Loader 读取并把本插件插入为一行 Loader 条目。
4
4
  # 注意:insert.name 必须与 package.json 的 name 完全一致,Loader 按包名解析模块。
5
5
  #
6
- # 运行时行为:在 DSH 运行期间调用 macOS 自带的 /usr/bin/caffeinate,
6
+ # 仅 macOS;默认 running-only:仅当有 Agent 轮次运行时调用 /usr/bin/caffeinate(每 15 秒检查)。
7
+ # mode: always 为主动选择,会在整个 DSH 会话期间防休眠。
7
8
  # 末尾固定加 -w <Host PID>,把断言绑到宿主进程生命周期上;
8
9
  # 宿主退出或崩溃后 caffeinate 自行释放断言并退出(caffeinate(8) 的 -w 语义)。
9
10
  - insert:
@@ -11,7 +12,7 @@
11
12
  name: 'dsh-caffeinate'
12
13
  config:
13
14
  enabled: true
14
- mode: always
15
+ mode: running-only
15
16
  preventIdleSystemSleep: true
16
17
  preventSystemSleepOnAC: true
17
18
  preventDiskSleep: true
package/index.js CHANGED
@@ -11,8 +11,8 @@ export const Config = z.object({
11
11
  enabled: z.boolean().default(true).description("是否启用 DSH 防休眠守护"),
12
12
  mode: z
13
13
  .union(["always", "running-only"])
14
- .default("always")
15
- .description("守护模式:always(DSH 打开期间始终防休眠)或 running-only(仅当有 Agent 会话正在执行时防休眠)"),
14
+ .default("running-only")
15
+ .description("守护模式:默认 running-only(仅当有 Agent 轮次正在执行时防休眠,最多 15 秒起停延迟);always 为主动选择(整个 DSH 会话期间防休眠);仅 macOS"),
16
16
  preventIdleSystemSleep: z
17
17
  .boolean()
18
18
  .default(true)
@@ -35,7 +35,7 @@ function normalizeConfig(raw = {}) {
35
35
  const cfg = typeof raw === "object" && raw !== null ? raw : {};
36
36
  return {
37
37
  enabled: cfg.enabled !== false,
38
- mode: cfg.mode === "running-only" ? "running-only" : "always",
38
+ mode: cfg.mode === "always" ? "always" : "running-only",
39
39
  preventIdleSystemSleep: cfg.preventIdleSystemSleep !== false,
40
40
  preventSystemSleepOnAC: cfg.preventSystemSleepOnAC !== false,
41
41
  preventDiskSleep: cfg.preventDiskSleep !== false,
@@ -137,8 +137,10 @@ export function apply(ctx, rawConfig) {
137
137
  function hasRunningAgent() {
138
138
  try {
139
139
  const agents = ctx.get?.("agents");
140
- if (!agents || typeof agents.values !== "function") return false;
141
- for (const agent of agents.values()) {
140
+ const entries = typeof agents?.list === "function"
141
+ ? agents.list()
142
+ : typeof agents?.values === "function" ? agents.values() : [];
143
+ for (const agent of entries) {
142
144
  if (agent?.status === "running") return true;
143
145
  }
144
146
  } catch {}
@@ -154,7 +156,7 @@ export function apply(ctx, rawConfig) {
154
156
  if (!state.child) startCaffeinate();
155
157
  return;
156
158
  }
157
- // running-only mode
159
+ // Default running-only mode: hold assertions only while an agent turn runs.
158
160
  if (hasRunningAgent()) {
159
161
  if (!state.child) startCaffeinate();
160
162
  } else {
@@ -176,12 +178,12 @@ export function apply(ctx, rawConfig) {
176
178
  stopCaffeinate();
177
179
  });
178
180
 
179
- async function handleCommand({ args }) {
180
- const sub = String(args ?? "")
181
+ async function handleCommand({ rawInput, args }) {
182
+ const sub = String(rawInput ?? args ?? "")
181
183
  .trim()
182
184
  .toLowerCase();
183
185
 
184
- if (sub === "on" || sub === "start") {
186
+ if (sub === "always" || sub === "on" || sub === "start") {
185
187
  state.enabled = true;
186
188
  state.mode = "always";
187
189
  state.preventDisplaySleep = config.preventDisplaySleep;
@@ -210,13 +212,24 @@ export function apply(ctx, rawConfig) {
210
212
  const uptimeSec = state.startedAt
211
213
  ? Math.max(0, Math.round((Date.now() - state.startedAt.getTime()) / 1000))
212
214
  : 0;
215
+ const statusText = process.platform !== "darwin"
216
+ ? "⚪ 不支持(仅 macOS)"
217
+ : isRunning
218
+ ? `🟢 运行中 (caffeinate PID: \`${state.child.pid}\`, 绑定 DSH Host PID: \`${process.pid}\`, 已持续 ${uptimeSec}s)`
219
+ : !state.enabled
220
+ ? "⚪ 已关闭"
221
+ : state.lastError
222
+ ? "🔴 启动失败(见最近异常)"
223
+ : state.mode === "running-only"
224
+ ? "🟡 待命(running-only 模式,暂无运行中的 Agent 轮次;每 15 秒检查)"
225
+ : "🟡 待命(always 模式,等待下次自检)";
213
226
 
214
227
  return {
215
228
  kind: "success",
216
229
  text: [
217
230
  `☕ **DSH 防休眠守护 (dsh-caffeinate)**`,
218
- `- 守护状态:${isRunning ? `🟢 运行中 (caffeinate PID: \`${state.child.pid}\`, 绑定 DSH Host PID: \`${process.pid}\`, 已持续 ${uptimeSec}s)` : state.enabled ? "🟡 待命(running-only 模式下暂无运行中会话)" : "⚪ 已关闭"}`,
219
- `- 当前模式:\`${state.mode}\`(${state.mode === "always" ? "DSH 运行期间始终防休眠" : "仅当有 Agent 任务运行时防休眠"})`,
231
+ `- 守护状态:${statusText}`,
232
+ `- 当前模式:\`${state.mode}\`(${state.mode === "always" ? "主动选择:整个 DSH 会话期间防休眠" : "默认:仅当有 Agent 轮次运行时防休眠,最多 15 秒起停延迟"})`,
220
233
  `- 启动参数:\`/usr/bin/caffeinate ${state.lastArgs.join(" ")}\``,
221
234
  `- 屏幕策略:${state.preventDisplaySleep ? "🔆 保持屏幕常亮 (-d)" : "🌙 允许屏幕正常息屏省电,仅阻止系统/CPU/网络/磁盘休眠 (-i -s -m)"}`,
222
235
  state.lastError ? `- 最近异常:${state.lastError}` : "",
@@ -226,7 +239,7 @@ export function apply(ctx, rawConfig) {
226
239
  assertions,
227
240
  "```",
228
241
  ``,
229
- `**可用指令**:\`/keepawake status\` · \`/keepawake on\`(允许息屏防系统休眠)· \`/keepawake display\`(连屏幕也保持常亮)· \`/keepawake running\`(仅任务运行时防休眠)· \`/keepawake off\`(关闭插件内防休眠)`,
242
+ `**可用指令**(仅 macOS):\`/keepawake status\` · \`/keepawake always\`(整个 DSH 会话期间防休眠;别名 on / start)· \`/keepawake display\`(整个 DSH 会话期间连屏幕也保持常亮)· \`/keepawake running\`(默认模式:仅 Agent 轮次运行时防休眠)· \`/keepawake off\`(关闭插件内防休眠)`,
230
243
  ]
231
244
  .filter((line) => line !== "")
232
245
  .join("\n"),
@@ -236,9 +249,9 @@ export function apply(ctx, rawConfig) {
236
249
  ctx.inject(["commands"], (cmdCtx) => {
237
250
  const definition = {
238
251
  description:
239
- "查看或控制 DSH 防休眠守护(Keep Awake):通过 macOS caffeinate 绑定主进程防止系统/网络/磁盘休眠",
252
+ "查看或控制 DSH 防休眠守护(仅 macOS):默认 running-only,仅 Agent 轮次运行时防休眠;always 为整个 DSH 会话期间防休眠",
240
253
  input: {
241
- hint: "[status | on | display | nodisplay | running | off]",
254
+ hint: "[status | always | on | display | nodisplay | running | off]",
242
255
  attachments: false,
243
256
  },
244
257
  handler: handleCommand,
package/locale/en.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "Caffeinate · Sleep Guard",
4
- "description": "Runs macOS caffeinate while DeepSeek Harness is running and binds the assertion to the host process with -w: the display may still lock and sleep, while system, CPU and disk idle sleep are held off during long tasks. Includes the /keepawake command."
4
+ "description": "macOS only. Enabled by default in running-only mode: caffeinate prevents sleep only while an agent turn runs, with up to 15 seconds of start/stop delay. Opt-in mode: always keeps the machine awake for the whole DSH session. Switch at runtime with /keepawake always|running|off; the display may still sleep by default."
5
5
  }
6
6
  }
package/locale/zh.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "meta": {
3
3
  "title": "防休眠守护 · Caffeinate",
4
- "description": "在 DSH 运行期间调用 macOS 自带的 caffeinate,并用 -w 把断言绑定到宿主进程:允许显示器正常息屏锁屏,但阻止系统、CPU 与磁盘空闲休眠,防止长任务与编队执行被打断。可用 /keepawake 查看与切换。"
4
+ "description": "仅 macOS。默认启用 running-only:仅当有 Agent 轮次运行时调用 caffeinate 防休眠,起停最多延迟 15 秒。主动选择 mode: always 后会在整个 DSH 会话期间保持机器唤醒。可用 /keepawake always|running|off 在运行时切换;默认允许屏幕正常息屏。"
5
5
  }
6
6
  }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "dsh-caffeinate",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
- "description": "Keep the Mac awake while DeepSeek Harness runs: a macOS caffeinate child process bound to the host pid with -w, plus the /keepawake command family.",
5
+ "description": "macOS-only sleep guard for DeepSeek Harness: running-only by default while an agent turn runs, with opt-in always mode for the whole DSH session and /keepawake runtime controls.",
6
6
  "license": "MIT",
7
7
  "author": {
8
8
  "name": "veritaswiki",
@@ -47,6 +47,10 @@
47
47
  "access": "public",
48
48
  "provenance": true
49
49
  },
50
+ "engines": {
51
+ "node": ">=20",
52
+ "dsh": ">=0.2.2-rc.1 <0.3.0"
53
+ },
50
54
  "peerDependencies": {
51
55
  "@deepseek-ai/schemastery": ">=3.0.0-0"
52
56
  },