dsh-goodnight 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 tzzs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,215 @@
1
- # Temporary Holding Version
1
+ # Goodnight
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **English** · [简体中文](./README.zh-CN.md)
4
+
5
+ Say goodnight to Windows once **every** task in your DeepSeek Harness Host has finished. A 60-second countdown fills the whole window, then the plugin hibernates or powers off. Cancel it any time before zero.
6
+
7
+ Long agent runs usually end when you have walked away. This plugin lets you say *"put the machine to bed when everything is actually done"*, then keeps its promise safe: it waits for all agents, subagents and background jobs in this Host, shows a full-window countdown, and **voids itself the moment new work appears**.
8
+
9
+ ![The countdown dialog](docs/countdown.png)
10
+
11
+ The background is switchable from the page: **solid** (default, above), **frosted glass**, and **gaussian blur**:
12
+
13
+ ![Frosted glass and gaussian blur](docs/backgrounds.png)
14
+
15
+ The entry sits in the left rail, right under **Plugins** and **Automation tasks**, and reads **Goodnight**:
16
+
17
+ ![The scheduling page](docs/page.png)
18
+
19
+ The page carries the power action, the countdown background, the live task counts, the flow and the notes. The action bar at the bottom names what the button will do (**Goodnight · shut down** / **Goodnight · hibernate**), becomes **Cancel schedule** while a reservation is live, and the rail glyph grows a small dot.
20
+
21
+ ---
22
+
23
+ ## Why it is safe
24
+
25
+ Turning off a machine in the middle of an agent run is the interesting problem here, so the plugin is built around not doing that.
26
+
27
+ It treats the whole Harness as busy if **any** of these is true:
28
+
29
+ | Checked | Why |
30
+ |---|---|
31
+ | `agent.status === 'running'` | an agent is taking a turn |
32
+ | `agent.inbox.nextTurn` / `.nextStep` non-empty | work has been queued but not started — the hand-off gap |
33
+ | a job is `running` or `stopping` | a shell/background job is alive, including ones owned by a session |
34
+ | subagents and workflow children | they are ordinary live agents, so one status check covers them |
35
+
36
+ Then:
37
+
38
+ 1. **Quiet period — 20 s.** All of the above must stay empty continuously. A single tick with work resets the clock. A missing agent registry counts as unknown activity, never as idle.
39
+ 2. **Countdown — 60 s.** The screen becomes one countdown screen: it first asks the engine for real fullscreen (covering the taskbar), then paints a rail draining across the top edge, digits and a progress ring that scale with the display, status and warnings spread to the corners, and a high-contrast `Cancel` button (`Esc` works too). When the engine refuses the automatic request for lack of a user gesture, a `Full screen` button in the corner repeats it from a click.
40
+ 3. **Any new task voids the countdown** and drops back to waiting. You never have to race it.
41
+ 4. Only when the countdown genuinely reaches zero does it run the power command. **Once the command is committed, cancel and mode changes are refused with `409`**, so the UI can never imply a cancellation that did not happen.
42
+ 5. **Waking from sleep never fires immediately.** If one tick arrives far past the deadline — the Host was frozen or the machine was suspended — the plugin re-arms and replays the whole quiet window instead of powering off the moment you sit back down.
43
+
44
+ **The countdown is the only undo you get.** `shutdown /s /t 0` runs immediately and `shutdown /h` has no `shutdown /a` counterpart, so the plugin does not rely on a Windows-provided reversal window — it provides its own.
45
+
46
+ Arming is always an explicit, human action. There is no model-facing tool, so the assistant can never decide to power off your machine.
47
+
48
+ ## Modes
49
+
50
+ | Mode | Command | What you get |
51
+ |---|---|---|
52
+ | `shutdown` **(default)** | `shutdown /s /t 0 /f` | Powers off. DSH conversations are still on disk. |
53
+ | `hibernate` | `shutdown /h /f` | Writes the memory image to disk. Next boot restores every open window and unsaved edit. |
54
+
55
+ Switch modes on the page; the Host remembers the choice, so it survives a reload.
56
+
57
+ > **Fast Startup note.** If Windows Fast Startup is enabled, `shutdown /s` is a *hybrid* shutdown: the kernel state is saved and the next boot resumes it. The browser half cannot reliably detect that system setting, so the page does not claim it is on; it warns instead that apps will be forced closed and unsaved work may be lost. A true cold boot needs `powercfg /h off` (admin, permanent) — this plugin deliberately does not touch your system settings.
58
+
59
+ ## The countdown screen and multiple monitors
60
+
61
+ The countdown is no longer a small centred card: the window — or the whole display once it is fullscreen — becomes one countdown screen, with information spread to its corners so it stays readable from across the room.
62
+
63
+ - A **rail pinned to the top edge** drains continuously and turns red for the last 10 seconds, so time is visible even in peripheral vision.
64
+ - **Giant digits** scale with `vmin` (readable on 4K, high-DPI and 200% zoom), wrapped by a ring driven by the fractional remainder so it sweeps instead of stepping once a second.
65
+ - **Information has a hierarchy**: why it started (N seconds of continuous idle) top-left, the window length top-right, the absolute "Scheduled for HH:MM:SS (local time)" and the action in the middle, and what voids the countdown / what is monitored / the unsaved-work warning along the bottom.
66
+ - **Cancel** is the highest-contrast control on screen and `Esc` works from anywhere. The tab title also carries the remaining seconds — the taskbar is often visible on every monitor, which makes this the one cross-screen cue that needs no permission.
67
+
68
+ ### Multiple monitors
69
+
70
+ A web overlay can only paint inside the Harness window's own screen; it cannot draw on another display. The desktop Harness also denies every `window.open` and exposes no display-enumeration or always-on-top API to plugins, so the plugin never opens a window without an explicit click. Three layers of handling:
71
+
72
+ | Case | Behaviour |
73
+ |---|---|
74
+ | Any screen size / DPI / zoom, ultrawide, high magnification | `dvh` + `vmin` + `clamp` + wrapping flex, no fixed card width: no horizontal scroll or clipping. Short windows shrink the dial automatically and Cancel always stays above the fold. |
75
+ | Window spanning two screens (dead centre may land on the bezel) | The top rail spans the whole window; when multiple screens are detected, "Timer position" appears top-right and can pin the hero to the left or right half. |
76
+ | Multiple screens detected (`screen.isExtended`) | A "Show on other screens" button appears. Clicking it tries the Window Management API for per-screen geometry and opens one lightweight mirror window per other screen; cancelling in any window stops the power action. |
77
+
78
+ Mirrors are **best-effort**: they work in the browser-hosted Harness; the desktop build denies the pop-ups, in which case the overlay states the limitation plainly (move the Harness window to the screen you are watching, or span both screens and use "Timer position") and keeps the full-window countdown. Mirrors are driven from the main window through DOM APIs — no scripts loaded, no new Host routes, no change to the authentication boundary — and are closed when the countdown ends.
79
+
80
+ > The countdown is still owned by the Host. Closing the page or a mirror window does not cancel the reservation.
81
+
82
+ ### Background styles
83
+
84
+ Three presets, switched from the page (applied immediately, remembered by the Host across reloads), with `backgroundStyle` in `cordis.patch.yml` deciding the default after a Host restart.
85
+
86
+ | Preset | Look | How contrast is kept |
87
+ |---|---|---|
88
+ | `solid` (default) | Opaque surface; the Harness window behind is fully hidden | Surface and label tokens are the host's own pair, so both themes get maximum contrast |
89
+ | `glass` | Translucent + blur + saturation; the window behind shows through faintly | A 66%-opaque surface over a dimmed, blurred layer keeps body contrast above 6:1 in both themes |
90
+ | `blur` | 34 px gaussian blur over a dark scrim with light text; an immersive dark warning | Host tokens are replaced inside this subtree with a fixed light-on-dark pair, independent of the current theme |
91
+
92
+ All three change **only the overlay itself**: the `blur` token overrides are scoped to the `.ipa-scrim` subtree and never leak into the rest of Harness. Translucency uses `color-mix()` and falls back to the opaque surface when an engine does not support it, so there is never a half-transparent unreadable state.
93
+
94
+ ## Install
95
+
96
+ The plugin is a regular DSH bundle: an npm package that ships a `cordis.patch.yml` and a `dsh.client` entry. The package is `dsh-goodnight`, and it shows itself in the app as **Goodnight**.
97
+
98
+ **Option A — Plugins page (recommended).** Open the Plugins page in Harness and install the bundle `dsh-goodnight` (or the spec `github:tzzs/dsh-goodnight`). It writes the dependency and adds the bundle to your profile for you.
99
+
100
+ **Option B — edit the profile by hand.** In your profile's `package.json`, list the package and add it to the bundle list:
101
+
102
+ ```jsonc
103
+ {
104
+ "dependencies": { "dsh-goodnight": "github:tzzs/dsh-goodnight" },
105
+ "dsh": { "profile": { "bundles": ["dsh-goodnight"] } }
106
+ }
107
+ ```
108
+
109
+ Then install dependencies in the profile directory and restart Harness.
110
+
111
+ Either way, **a restart or a plugin reload is required** — the Host half registers its routes when it loads.
112
+
113
+ ## Use
114
+
115
+ The entry sits in the left rail, right under **Plugins** and **Automation tasks**, and reads **Goodnight**:
116
+
117
+ ![The scheduling page](docs/page.png)
118
+
119
+ From top to bottom the page shows the current state (not scheduled / waiting · N tasks running / counting down / executing / failed), the live load, the power action, the countdown background, the flow and the notes.
120
+
121
+ - **Goodnight · shut down** or **Goodnight · hibernate**, whichever the selected power action is, sits in the action bar at the bottom next to a one-line plan ("20 s idle → 60 s countdown → shutdown") that names the same action, so the commit button never leaves the choices behind. While a reservation is live the same spot becomes **Cancel schedule**.
122
+ - **State on the rail** — while a reservation is live the power glyph grows a small dot; during the countdown that dot turns red and blinks. The dot survives the rail collapsing to icons.
123
+ - **Countdown background** — three preview tiles that draw the countdown window each preset produces (solid / frosted glass / gaussian blur), applied immediately and persisted on the Host.
124
+ - **A solid surface can be recoloured** — with the solid preset selected, a colour row offers the theme, six presets (four dark, two light) and the system colour picker; the ink switches between black and white by luminance.
125
+ - **A reservation keeps the machine awake** — an idle desktop turns the display off, then locks, then sleeps, and a **suspended Host never reaches the end of its countdown**: that is exactly why "the shutdown stopped working after the lock screen". While a reservation is pending the plugin holds `SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED)`, so it neither sleeps nor blanks the display (and therefore never auto-locks), and releases it the moment the reservation ends or the command is committed. The switch lives in the "Stay awake" section and is on by default.
126
+ - **The waiting phase can take the screen too** — with "Whole screen → Full screen while waiting" on, arming goes straight to a fullscreen waiting screen: what is still running, the quiet-window progress, and Cancel. When the quiet window passes it hands the screen to the countdown without ever leaving fullscreen. `Esc` takes the whole presentation away (fullscreen included) and keeps the reservation; the countdown screen cannot be dismissed.
127
+
128
+ ![The waiting screen](docs/wait.png)
129
+ - **Countdown preview** — the Preview button in that section runs the real countdown component for ten seconds with the current colour, background and mode. Nothing is armed, no route is called, and it closes itself at zero.
130
+
131
+ ![Countdown preview](docs/preview.png)
132
+ - **How it runs** — `20 s continuously idle → 60 s cancellable countdown → run`, plus "closing this page does not cancel; only this Host is monitored".
133
+ - **What is running** — running agents, queued messages and background jobs are listed separately, with a total.
134
+ - **Connection state** — "Loading status…" before the first answer, "Cannot reach the plugin Host" with controls disabled when the connection drops, "Submitting…" while a request is in flight so a button cannot be pressed twice.
135
+ - **Failure state** — if cancelling the countdown fails, the dialog stays and says cancellation is unconfirmed instead of pretending it worked.
136
+
137
+ Keyboard: on the **waiting screen** `Esc` closes the whole presentation (fullscreen and overlay together) and keeps the reservation; the **countdown screen** cannot be dismissed — `Esc` leaves fullscreen first (the countdown keeps running) and a second press cancels; windowed, `Esc` cancels directly; modes, backgrounds and colours are native radio groups (a radio inside a `<label>` card), so the arrow keys move and select; `Tab` cycles through every button inside the dialog instead of escaping it.
138
+
139
+ ## Configuration
140
+
141
+ Set these on the plugin row in your profile's `cordis.patch.yml`:
142
+
143
+ | Option | Default | Meaning |
144
+ |---|---|---|
145
+ | `countdownSeconds` | `60` | Countdown length, clamped to 5–3600 |
146
+ | `quietSeconds` | `20` | Required quiet period, clamped to 3–3600 |
147
+ | `defaultMode` | `'shutdown'` | `'hibernate'` or `'shutdown'` |
148
+ | `backgroundStyle` | `'solid'` | Countdown background: `'solid'` / `'glass'` / `'blur'`; an unknown value falls back to `'solid'` |
149
+ | `countdownColor` | `null` | Custom solid colour as `#rrggbb`; `null` follows the Host theme, and an invalid value falls back to `null` |
150
+ | `fullscreenOnWait` | `false` | Whether a reservation takes the whole screen from the **waiting** phase; the "Whole screen → Full screen while waiting" switch writes it back to the Host |
151
+ | `stayAwake` | `true` | Whether a pending reservation blocks sleep and the lock screen; the "Stay awake" switch writes it back |
152
+ | `shutdownCommand` | `'shutdown'` | Power command; resolved via PATH when the plugin loads |
153
+
154
+ A mode or background you pick in the UI is remembered by the Host (it survives a page reload) and resets to `defaultMode` / `backgroundStyle` when the Host restarts.
155
+
156
+ ## HTTP routes
157
+
158
+ The browser half talks to the Host over six authenticated routes. Every one checks Host, Origin, `sec-fetch-site` and the auth cookie first, answering `403` or `401`; when the connection service is unavailable every route answers `503`.
159
+
160
+ | Method | Path | Purpose |
161
+ |---|---|---|
162
+ | `GET` | `/goodnight/state` | mode, phase, remaining seconds, background style, live task counts |
163
+ | `POST` | `/goodnight/arm` | reserve; body `{ "mode": "hibernate" \| "shutdown" }` |
164
+ | `POST` | `/goodnight/cancel` | cancel a reservation or a running countdown |
165
+ | `POST` | `/goodnight/mode` | change the mode when nothing is reserved |
166
+ | `POST` | `/goodnight/background` | change the background only; body `{ "backgroundStyle": "solid" \| "glass" \| "blur" }` |
167
+ | `POST` | `/goodnight/color` | change the solid colour only; body `{ "color": "#rrggbb" \| null }` |
168
+ | `POST` | `/goodnight/fullscreen` | change the waiting fullscreen only; body `{ "onWait": true \| false }` |
169
+ | `POST` | `/goodnight/awake` | change the stay-awake behaviour only; body `{ "on": true \| false }` |
170
+
171
+ Once the power command is committed, `/arm`, `/cancel`, `/mode`, `/background`, `/color`, `/fullscreen` and `/awake` all answer `409 execution-in-progress`. A superseded arm, and any `/mode` sent while a reservation is live, answers `409 reservation-changed`; to change the action of an existing reservation, arm again so the quiet window restarts.
172
+
173
+ `/background` is a pure appearance preference and **deliberately does not touch the reservation state machine**: it never bumps the internal revision, so changing the background can never make an in-flight arm look superseded.
174
+
175
+ Execution happens in the **Host**, not the browser. Closing the tab does not stop a countdown; that is deliberate — a browser-side timer would never fire if the browser crashed. The trade-off is that an armed reservation keeps running while Harness is open.
176
+
177
+ ## Requirements
178
+
179
+ - **Windows.** `shutdown.exe` is the only backend; on other platforms the plugin reports "unsupported" instead of pretending.
180
+ - A DSH profile that mounts `agents` and `webServer`. `jobs` is optional — without it the plugin still runs, it just cannot see background jobs.
181
+
182
+ ## Tests
183
+
184
+ ```powershell
185
+ npm test
186
+ ```
187
+
188
+ Three dependency-free harnesses drive the real code with stand-ins, so the suite can run on any machine without powering anything off:
189
+
190
+ - `test/host.test.mjs` — the state machine against fake agents, fake jobs and a subprocess that records `argv` instead of executing. Covers the busy predicate, a missing registry, quiet behaviour, countdown voiding, both command lines, cancellation, failure reporting, the mode and background routes, background config fallback for unknown values, and the races: mutations refused once execution is committed, a background change that must not disturb a pending arm, a cancel beating a slow arm upload, a stale lookup unable to overwrite a cancellation, and a suspend that overshoots the deadline re-arming instead of firing.
191
+ - `test/client.test.cjs` — renders the real `client.js` components with a minimal React stand-in and asserts on the produced tree: the rail glyph and its pending dot, every page state (loading / offline / registry unavailable / executing / failed), the live load and per-kind task breakdown, mode and background selection with their disabled states, the flow and notes, the full-screen countdown's information hierarchy and progressbar semantics, the emitted `data-background` with fallback for unknown values, the progress ring's geometry and edge cases, multi-screen detection and mirror degradation, cancel-failure feedback, and `prefers-reduced-motion` coverage.
192
+ - `test/locale.test.cjs` — renders the rail entry, the page, the countdown and the waiting screen with the real dictionaries, and fails on a label that resolves to nothing, a placeholder that only one language has, or a retired product name coming back.
193
+
194
+ The host tests also cover a failed trust check, an unavailable connection service, mode changes during a reservation, and waking up during the executable lookup; the client tests cover keyboard access to every countdown control plus the fullscreen request and the two-step `Esc`.
195
+
196
+ ### Cross-platform testing
197
+
198
+ The plugin **only takes effect on Windows**, but the state machine and the browser half are platform independent, so the suite runs on **Windows, Ubuntu and macOS** runners (`.github/workflows/ci.yml`, three operating systems × Node 20 and 24). To make that possible the Host half takes the platform as an injectable parameter instead of reading the global:
199
+
200
+ - `apply(ctx, config, environment)` takes a third argument used only by the tests; passing `{ platform: 'linux' }` exercises the unsupported-platform branch on any machine.
201
+ - The user-facing configuration (`cordis.patch.yml`) **cannot reach that switch**: a `platform: linux` key in the config is ignored, so a mis-copied config cannot disable the plugin on Windows. That is pinned by an assertion.
202
+
203
+ The host suite used to carry an `if (process.platform !== 'win32')` skip, which meant the whole suite **only passed on Windows**. Linux and macOS runners now execute the same assertions for real instead of skipping them.
204
+
205
+ For an interactive motion preview, open `docs/preview.html?page=1&live=1` in a browser. It uses local mock state for mode/background selection, scheduling and cancellation, and offers a simulated countdown. It sends no Host requests and never executes a power command.
206
+
207
+ The motion takes inspiration from [DesignBookmark Motion](https://designbookmark.com/motion): mode cards and background tiles mark the selection with an accent ring and a checkmark that draws in only after the Host confirms it. Countdown digits update in place on a fixed baseline, with no per-second displacement or flashing, and stay readable during the final red warning. The progress rail uses `transform` rather than changing layout width. All decorative motion respects `prefers-reduced-motion`, while time and cancellation keep working.
208
+
209
+ `docs/preview.html` without `live=1` is a dependency-free static preview: it renders the real `client.js` components and real stylesheet in a browser without triggering a power action. Query parameters switch states, e.g. `?s=6&mode=shutdown&multi=1` for the urgent state and the multi-screen controls, `?bg=glass` / `?bg=blur` for the backgrounds, `?page=1` for the page, `?dark=1` for the dark theme; `docs/backgrounds.html` puts frosted glass and gaussian blur side by side on one page.
210
+
211
+ Neither suite replaces looking at the page, and neither proves that `shutdown` really powers the machine off — that needs a human clicking the button.
212
+
213
+ ## License
214
+
215
+ MIT
@@ -0,0 +1,221 @@
1
+ # 晚安
2
+
3
+ [English](./README.md) · **简体中文**
4
+
5
+ 等 **DeepSeek Harness 当前 Host 里所有任务** 都跑完之后,替你把机器休眠或关掉。屏幕先变成一块 60 秒的倒计时,窗口会自动进入全屏,随时可以取消。
6
+
7
+ 长任务通常在你离开电脑之后才结束。这个插件让你提前说一句「跑完了就睡吧」,然后用一套防误关的机制来兑现:
8
+
9
+ ![倒计时对话框](docs/countdown.png)
10
+
11
+ 页面里可以切换背景:**纯色**(默认,见上图)、**毛玻璃**、**高斯模糊**:
12
+
13
+ ![毛玻璃与高斯模糊](docs/backgrounds.png)
14
+
15
+ 入口就在左侧导航里,紧挨「插件」和「自动化任务」,名字叫「晚安」:
16
+
17
+ ![预约页](docs/page.png)
18
+
19
+ 页面里选电源操作和倒计时背景,实时看到在跑的任务数、执行流程和说明;底部的动作栏写着这次预约会怎么执行,按钮直接叫「道晚安 · 关机 / 道晚安 · 休眠」,已预约时同一个位置变成「取消预约」,左侧导航的电源图标上会多出一个小圆点。
20
+
21
+ ---
22
+
23
+ ## 为什么它不会把你正在跑的东西关掉
24
+
25
+ 在 agent 任务进行中关机,是这个插件唯一重要的难题。所以它的判断覆盖整个 Harness Host:
26
+
27
+ 只要满足**任意一条**,就认为还有活没干完:
28
+
29
+ | 检查项 | 原因 |
30
+ |---|---|
31
+ | `agent.status === 'running'` | 有 agent 正在执行回合 |
32
+ | `agent.inbox.nextTurn` / `.nextStep` 非空 | 已经排进队列但还没开始 —— 任务交接的空档 |
33
+ | 有 job 处于 `running` 或 `stopping` | shell / 后台任务还活着,包括挂在某个会话下面的 |
34
+
35
+ 子智能体和 workflow 子节点本身就是普通 agent,所以一次状态检查就能覆盖它们。
36
+
37
+ 然后:
38
+
39
+ 1. **安静期 20 秒** —— 上面这些必须持续为空。任何一次检查发现活,计时归零重来;注册表不可用时按“有活”处理,不会误判空闲。
40
+ 2. **倒计时 60 秒** —— 屏幕变成一块倒计时屏:打开时先尝试把 Harness 窗口切到真全屏(覆盖任务栏),顶部贯穿的进度条、随屏幕尺寸放大的秒数与进度环、四角铺开的状态与警告,以及对比度最高的「取消」按钮(`Esc` 也行)。如果浏览器以“缺少用户手势”为由拒绝自动全屏,右上角有「全屏显示」按钮,点一下即可覆盖整屏。
41
+ 3. **一有新任务,倒计时立刻作废** —— 退回等待状态,你不需要和它抢时间。
42
+ 4. 只有倒计时真正归零,才执行电源命令。**命令一旦提交执行,取消和改模式都会被拒绝(409)**,界面不会出现“取消了但其实还在关机”的错觉。
43
+ 5. **睡眠/休眠后醒来不会立刻关机** —— 如果一次检查发现已经远过倒计时终点(Host 进程被挂起、机器睡过去了),插件重新回到等待,重新走完整的安静期,而不是在你刚坐回电脑前突然断电。
44
+
45
+ **倒计时是你唯一的撤销窗口。** `shutdown /s /t 0` 立即执行,`shutdown /h` 更是完全没有 `shutdown /a` 可以撤销。所以插件不依赖 Windows 提供的反悔期,而是自己提供。
46
+
47
+ 预约永远是**人**的显式动作:插件不注册任何模型可见的工具,助手无法替你决定关机。
48
+
49
+ ## 两种模式
50
+
51
+ | 模式 | 命令 | 结果 |
52
+ |---|---|---|
53
+ | `shutdown`(**默认**) | `shutdown /s /t 0 /f` | 断电关机。DSH 里的对话记录仍在磁盘上。 |
54
+ | `hibernate` | `shutdown /h /f` | 内存快照落盘。下次开机原样恢复所有窗口和未保存的内容。 |
55
+
56
+ 在页面里切换模式,Host 会记住这个选择(刷新页面不丢)。
57
+
58
+ > **快速启动说明**:如果 Windows 开着快速启动,`shutdown /s` 其实是**混合关机**——内核状态被保存、下次开机是恢复。插件在浏览器侧无法可靠检测这个系统设置,所以界面不会声称已开启,只提示「会强制关闭应用,未保存的内容可能丢失」。真要冷启动需要 `powercfg /h off`(管理员,永久生效),本插件刻意不碰你的系统设置。
59
+
60
+ ## 倒计时界面与多屏幕
61
+
62
+ 倒计时不再是一个居中的小卡片:窗口(或整块屏幕)变成一块倒计时屏,信息铺到四角,远处或余光里也能读。
63
+
64
+ - **顶部进度条**贴着窗口上沿按剩余时间连续收缩,最后 10 秒转为红色。
65
+ - **巨型秒数**按 `vmin` 缩放(4K、高 DPI、200% 缩放下仍可读),外圈进度环用未取整的剩余值平滑扫动而不是逐秒跳。
66
+ - **信息分层**:左上写「为什么开始」(已通过 N 秒持续空闲),右上写「窗口多长」,中间写「预计 HH:MM:SS 执行(本机时间)」和即将发生的操作,下方列出「什么会让它作废 / 监控范围 / 关机时未保存内容的警告」。
67
+ - **取消按钮**是全屏对比度最高的控件,任意位置按 `Esc` 都能触发。倒计时期间标签页标题也会带上剩余秒数 —— 任务栏常常在每块屏幕上都可见,这是唯一不需要额外权限的跨屏提醒。
68
+
69
+ ### 多屏幕
70
+
71
+ 一个 Web 覆盖层只能画在 Harness 窗口所在的那一块屏幕上,无法直接绘制到别的显示器。桌面版 Harness 还明确拒绝所有 `window.open`,也不向插件暴露显示器枚举或置顶窗口 API,所以插件**不会**在你没点过的情况下擅自弹窗。在此基础上做了三层处理:
72
+
73
+ | 情况 | 行为 |
74
+ |---|---|
75
+ | 任意屏幕尺寸 / DPI / 缩放、超宽屏、高倍率 | 布局用 `dvh`、`vmin`、`clamp` 与自动换行,没有固定卡片宽度,不会横向滚动或裁切;矮窗口自动缩小表盘,取消按钮始终在首屏。 |
76
+ | 窗口横跨两块屏幕(正中可能正好压在边框上) | 顶部进度条贯穿整个窗口;检测到多屏时右上角出现「计时器位置」,可把主体固定在左侧或右侧那半边。 |
77
+ | 倒计时只覆盖窗口、没盖住任务栏或桌面图标 | 倒计时打开时会调用 Fullscreen API 请求真全屏;被引擎以“缺少用户手势”拒绝时,右上角显示「全屏显示」,点一下(用户手势)即可覆盖整块屏幕。取消或倒计时结束后自动退出全屏,且只退出自己进入的那次全屏。 |
78
+ | 检测到多块屏幕(`screen.isExtended`) | 出现「在其它屏幕也显示」按钮。点击后尝试用窗口管理 API 取各屏幕坐标,在其它屏幕各打开一个轻量镜像窗口;在任一窗口取消都会停止本次电源操作。 |
79
+
80
+ 镜像窗口是**尽力而为**:浏览器版 Harness 可用;桌面版会拒绝弹窗,此时界面直接说明限制(把 Harness 窗口移到你正在看的屏幕,或跨屏后用「计时器位置」),并照常保留全窗口倒计时。镜像窗口由主窗口通过 DOM API 驱动,不加载脚本、不新增 Host 路由、不改动认证边界;倒计时结束时自动关闭。
81
+
82
+ > 倒计时仍由 Host 侧计时。关闭页面、关掉镜像窗口都不会取消预约。
83
+
84
+ ### 背景样式
85
+
86
+ 倒计时背景有三档预设,在页面里点一下就生效,由 Host 记住(刷新不丢),`cordis.patch.yml` 里的 `backgroundStyle` 决定 Host 重启后的默认值。
87
+
88
+ | 预设 | 观感 | 对比度怎么办 |
89
+ |---|---|---|
90
+ | `solid`(默认) | 不透明底色,背后的 Harness 完全看不到 | 表面色与文字色都取宿主 token,明暗主题下都是最高对比 |
91
+ | `glass` | 半透明 + 模糊 + 提饱和,隐约透出背后的窗口 | 表面 66% 不透明叠在压暗的模糊层上,两种主题下正文对比度仍在 6:1 以上 |
92
+ | `blur` | 34px 重度模糊 + 暗底浅字,沉浸式深色提示 | 在这个子树里把宿主 token 换成固定的浅字/暗底配对,不依赖当前主题 |
93
+
94
+ 三个预设都**只改覆盖层自己**:`blur` 那套 token 覆盖作用在 `.ipa-scrim` 子树上,不会污染 Harness 其他部分。半透明用的是 `color-mix()`,引擎不支持时会自动退回不透明表面,不会出现读不清的半透明状态。
95
+
96
+ ## 安装
97
+
98
+ 插件就是普通的 DSH bundle:一个 npm 包,带 `cordis.patch.yml` 和 `dsh.client` 声明。包名 `dsh-goodnight`,它在应用里显示为**晚安**。
99
+
100
+ **方式 A —— 用插件页(推荐)**:在 Harness 的「插件」页安装 bundle `dsh-goodnight`(或安装串 `github:tzzs/dsh-goodnight`),它会自动写入依赖并把 bundle 加进你的 profile。
101
+
102
+ **方式 B —— 手动改 profile**:在 profile 的 `package.json` 里加上依赖和 bundle:
103
+
104
+ ```jsonc
105
+ {
106
+ "dependencies": { "dsh-goodnight": "github:tzzs/dsh-goodnight" },
107
+ "dsh": { "profile": { "bundles": ["dsh-goodnight"] } }
108
+ }
109
+ ```
110
+
111
+ 然后在 profile 目录里装一次依赖,重启 Harness。
112
+
113
+ 两种方式都一样:**必须重启或重载插件**——Host 半是在加载时才注册路由的。
114
+
115
+ ## 使用
116
+
117
+ 入口在左侧导航,紧挨「插件」「自动化任务」:
118
+
119
+ ![预约页](docs/page.png)
120
+
121
+ 页面从上到下是:当前状态(未预约 / 等待中 · N 个任务在跑 / 倒计时中 / 执行中 / 失败)、实时负载、电源操作、倒计时背景、执行流程和说明。
122
+
123
+ - **道晚安 / 取消预约**在页面底部的动作栏:旁边一行写清「空闲 20 秒 → 倒计时 60 秒 → 关机」,按钮名称跟着选中的电源操作走(道晚安 · 关机 / 道晚安 · 休眠),不用再滚回顶部找入口。
124
+ - **导航上的状态**:已预约时电源图标右上角多出一个小圆点,倒计时期间圆点变红并闪烁;导航折叠成图标轨道时圆点依然在。
125
+ - **倒计时背景**:三张预览卡直接画出每档下倒计时窗口的样子(纯色 / 毛玻璃 / 高斯模糊),点一下即时生效并写入 Host。
126
+ - **纯色可换颜色**:选「纯色」时下方出现颜色行——跟随主题、六个预设(四深两浅),或用系统取色器自定义;文字颜色按底色亮度自动选黑或白。
127
+ - **预约期间不让电脑睡过去**:电脑空闲久了会关屏、进而锁屏甚至休眠,而**被挂起的 Host 根本不会走到倒计时终点**——这正是「锁屏之后关机就不管用了」的原因。插件在预约期间用一个后台 helper 申请 `SetThreadExecutionState(ES_CONTINUOUS|ES_SYSTEM_REQUIRED|ES_DISPLAY_REQUIRED)`,既不休眠也不关屏(因此不会自动锁屏),取消预约或命令提交后立刻释放;开关在「保持唤醒」区,默认开启。
128
+ - **等待也能整屏**:打开「整屏展示 → 等待时也整屏」后,预约一建立就进入全屏的等待屏——显示还在跑的任务、安静期进度和「取消预约」;安静期走完自动交棒给倒计时屏,全程不退出全屏。按 `Esc` 可以把这层展示整个收掉(全屏一起退),预约照旧;倒计时屏不可关闭。
129
+
130
+ ![等待屏](docs/wait.png)
131
+ - **倒计时预览**:背景区右上角「预览」用真实的倒计时组件演一遍 10 秒,颜色、背景、模式都按当前选择来,不预约、不调用任何 Host 路由,到 0 自动结束。
132
+
133
+ ![倒计时预览](docs/preview.png)
134
+ - **执行流程**:`20 秒持续空闲 → 60 秒可取消倒计时 → 执行`,以及「关闭页面不会取消预约;只监测当前 Host」。
135
+ - **在跑什么**:按「运行中的智能体 / 排队消息 / 后台任务」分项列出数量,再给一个合计。
136
+ - **状态反馈**:首次读取时显示「正在读取状态…」,断线显示「连不上插件 Host」并禁用操作;提交中显示「正在提交…」,按钮不会重复触发。
137
+ - **失败反馈**:倒计时里取消失败会保留弹窗并提示「取消尚未确认,请重试」,不会假装取消成功。
138
+
139
+ 键盘操作:**等待屏**里 `Esc` 直接关掉整块大屏展示(全屏和遮罩一起退,预约保留,回页面就能取消);**倒计时屏**不可关闭,`Esc` 先退出全屏(倒计时继续),再按一次才取消;非全屏时 `Esc` 直接取消;模式和背景都是原生单选组(单选按钮 + `<label>` 卡片),方向键在选项间移动并选中;倒计时与等待屏里 `Tab` 遍历弹窗内所有可用按钮(不会跑出弹窗)。
140
+
141
+ ### 交互动效
142
+
143
+ 参考 [DesignBookmark Motion](https://designbookmark.com/motion) 的选项切换思路:模式卡片用一圈强调色描边和勾选标记表示选择,勾选在 Host 确认后才画入;背景预览卡用同一圈描边和角标勾选。提交和取消状态仍以实际请求结果为准。
144
+
145
+ 倒计时表盘出现时轻微收拢,秒数在固定基线上直接更新,不做逐秒位移或闪烁;最后十秒用红色提示。进度条通过 `transform` 连续收缩,不再每帧改变布局宽度。系统开启「减少动态效果」后,展开、移动高亮与按压效果会立即切换到最终状态,时间和取消操作照常有效。
146
+
147
+ 在浏览器打开 `docs/preview.html?page=1&live=1` 可以体验模式切换、背景选择、预约和取消;也可以用预览工具栏直接播放倒计时。预览只操作本地模拟状态,不连接 Host,也不会执行电源命令。
148
+
149
+ ## 配置
150
+
151
+ 在 profile 的 `cordis.patch.yml` 里改插件行:
152
+
153
+ | 选项 | 默认 | 含义 |
154
+ |---|---|---|
155
+ | `countdownSeconds` | `60` | 倒计时秒数,钳制在 5–3600 |
156
+ | `quietSeconds` | `20` | 安静期秒数,钳制在 3–3600 |
157
+ | `defaultMode` | `'shutdown'` | `'hibernate'` 或 `'shutdown'` |
158
+ | `backgroundStyle` | `'solid'` | 倒计时背景:`'solid'` / `'glass'` / `'blur'`,非法值退回 `'solid'` |
159
+ | `countdownColor` | `null` | 纯色模式的自定义底色,`#rrggbb`;`null` 表示跟随宿主主题,非法值同样退回 `null` |
160
+ | `fullscreenOnWait` | `false` | 预约后是否**从等待阶段**就占满整屏;页面上的「整屏展示 → 等待时也整屏」开关会改写它并写回 Host |
161
+ | `stayAwake` | `true` | 预约期间是否阻止系统休眠与锁屏;页面上的「保持唤醒」开关会改写它 |
162
+ | `shutdownCommand` | `'shutdown'` | 电源命令,加载时按 PATH 解析 |
163
+
164
+ 你在界面上选过的模式和背景会被 Host 记住(刷新页面不丢),Host 重启后回到 `defaultMode` / `backgroundStyle`。
165
+
166
+ ## 路由
167
+
168
+ 浏览器半通过六条需要认证的路由和 Host 通信。每条都先检查 Host、Origin、`sec-fetch-site` 和认证 Cookie,拒绝请求时返回 `403` 或 `401`;连接服务不可用时,所有路由返回 `503`。
169
+
170
+ | 方法 | 路径 | 用途 |
171
+ |---|---|---|
172
+ | `GET` | `/goodnight/state` | 模式、阶段、剩余秒数、背景样式、在跑的任务数 |
173
+ | `POST` | `/goodnight/arm` | 预约;body `{ "mode": "hibernate" \| "shutdown" }` |
174
+ | `POST` | `/goodnight/cancel` | 取消预约或取消倒计时 |
175
+ | `POST` | `/goodnight/mode` | 没有预约时修改模式 |
176
+ | `POST` | `/goodnight/background` | 只改背景;body `{ "backgroundStyle": "solid" \| "glass" \| "blur" }` |
177
+ | `POST` | `/goodnight/color` | 只改纯色底色;body `{ "color": "#rrggbb" \| null }` |
178
+ | `POST` | `/goodnight/fullscreen` | 只改「等待时也整屏」;body `{ "onWait": true \| false }` |
179
+ | `POST` | `/goodnight/awake` | 只改「预约期间保持唤醒」;body `{ "on": true \| false }` |
180
+
181
+ 命令进入执行阶段后,`/arm`、`/cancel`、`/mode`、`/background`、`/color`、`/fullscreen`、`/awake` 一律返回 `409 execution-in-progress`,已经提交的电源操作不能撤。过期的预约请求,以及预约期间发往 `/mode` 的请求,会收到 `409 reservation-changed`。要修改已有预约的模式,用 `/arm` 重新开始安静期。
182
+
183
+ `/background` 是纯外观偏好,**刻意不碰预约状态机**:它不会递增内部 revision,所以改背景永远不会让正在上传的预约被判成「已过期」。
184
+
185
+ **执行发生在 Host 侧,不在浏览器。** 关掉标签页不会中止倒计时——这是刻意的:浏览器端的定时器一旦浏览器崩溃就永远不会触发。代价是 Harness 开着的时候预约会一直有效。
186
+
187
+ ## 环境要求
188
+
189
+ - **仅 Windows。** 唯一实现是 `shutdown.exe`;其他平台明确报「不支持」而不是假装能用。
190
+ - 一个挂载了 `agents` 和 `webServer` 的 DSH profile。`jobs` 可选——没有它插件照常工作,只是看不到后台任务。
191
+
192
+ ## 测试
193
+
194
+ ```powershell
195
+ npm test
196
+ ```
197
+
198
+ 三个零依赖的测试夹具用替身驱动**真实代码**,所以在任何机器上都能跑完而不会真的关机:
199
+
200
+ - `test/host.test.mjs` —— 用假 agents、假 jobs 和一个只记录 `argv` 不执行的 subprocess 驱动状态机。覆盖忙碌判定、注册表缺失、安静期行为、倒计时作废、两种命令行、取消、失败上报、模式与背景路由、背景配置的非法值回退,以及并发竞争:执行提交后的修改请求被拒绝、改背景不会让在途预约过期、取消压过正在上传的预约、过期查表结果不能覆盖取消、睡眠跨过倒计时终点后重新等待。
201
+ - `test/client.test.cjs` —— 用最小 React 替身渲染真实的 `client.js` 组件并对产出的树做断言:导航入口图标与状态圆点、整页各状态(读取中 / 断线 / 注册表不可用 / 执行中 / 失败)、实时负载与分项任务数、模式与背景的选择和禁用态、执行流程与说明、整屏倒计时的信息分层与进度条语义、`data-background` 的输出与未知值回退、进度环的几何与边界、多屏检测与镜像窗口的降级、倒计时取消失败反馈、`prefers-reduced-motion` 覆盖。
202
+ - `test/locale.test.cjs` —— 用真实词典渲染导航入口、页面、倒计时和等待屏,检查每条文案都解析得到、两种语言的 `%s` 数量一致,并且旧名字不会回流。
203
+
204
+ Host 测试还覆盖信任检查失败、连接服务不可用、预约期间的模式修改,以及电源命令查找期间的休眠恢复;客户端测试覆盖倒计时里所有控件的键盘访问、整屏全屏请求与 `Esc` 的两段语义。
205
+
206
+ ### 跨平台测试
207
+
208
+ 插件**只在 Windows 上真正生效**,但状态机和浏览器半与平台无关,所以测试套件在 **Windows / Ubuntu / macOS** 三种 runner 上都跑(`.github/workflows/ci.yml`,三系统 × Node 20 / 24)。为此宿主半把平台从 `process.platform` 改成了**可注入的参数**:
209
+
210
+ - `apply(ctx, config, environment)` 的第三个参数只用于测试,传 `{ platform: 'linux' }` 就能在任意机器上跑「非 Windows 拒绝预约」这条分支。
211
+ - 用户配置(`cordis.patch.yml`)**碰不到这个开关**:在配置里写 `platform: linux` 会被忽略,Windows 上的插件不会被一份误抄的配置搞坏——这条专门写了断言。
212
+
213
+ 在此之前,宿主测试里有 `if (process.platform !== 'win32')` 的跳过分支,也就是说整套测试**只有 Windows 能过**;现在 Linux/macOS runner 上跑的是同一批断言的真实执行,而不是跳过。
214
+
215
+ `docs/preview.html` 是零依赖的静态预览页:用真实的 `client.js` 组件和真实样式表在浏览器里渲染倒计时与整页,不会触发电源操作。查询串可切换状态,例如 `?s=6&mode=shutdown&multi=1` 查看紧急态与多屏控件,`?bg=glass` / `?bg=blur` 对比背景,`?page=1` 看整页,`?dark=1` 看暗色主题;`docs/backgrounds.html` 把毛玻璃与高斯模糊并排放在一页里。
216
+
217
+ 三套测试都不能替代肉眼看页面,也**不能证明 `shutdown` 真的把机器关掉**——那一步需要人按一次。
218
+
219
+ ## 许可
220
+
221
+ MIT