dsh-console-sentinel 0.3.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +438 -1
- package/README.md +104 -108
- package/README.zh.md +96 -102
- package/docs/screenshots/01-panel-overview.png +0 -0
- package/docs/screenshots/02-confirm-dialog.png +0 -0
- package/docs/screenshots/03-preview-result.png +0 -0
- package/docs/screenshots/04-detail-view.png +0 -0
- package/docs/screenshots/05-console-tab.png +0 -0
- package/docs/screenshots/06-whitelist-tab.png +0 -0
- package/lib/client.js +733 -91
- package/lib/desktop.js +397 -9
- package/lib/index.js +305 -7
- package/lib/probe.js +2 -1
- package/lib/whitelist.js +12 -6
- package/package.json +90 -82
- package/README-es.md +0 -29
- package/README-hi.md +0 -29
- package/README-pt.md +0 -29
package/README.md
CHANGED
|
@@ -1,126 +1,122 @@
|
|
|
1
1
|
# dsh-console-sentinel
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
|
|
6
|
-
长时间运行的自动化工作流(Fluent 无人值守任务、批量脚本、WMI 拉起的脱离进程)
|
|
7
|
-
会在任务栏堆下一排 PowerShell/Python 黑窗口。你分不清哪些还在跑,也不敢随手关。
|
|
8
|
-
本插件替你追踪它们、区分「在忙」和「用完了」,并把用完的隐藏掉 —— 进程继续跑、
|
|
9
|
-
数据不丢,每个窗口都能随时叫回来。
|
|
10
|
-
|
|
11
|
-
## 工作原理
|
|
12
|
-
|
|
13
|
-
1. 每隔 `scanIntervalSec` 秒(默认 10)用零依赖的 Windows PowerShell 探针
|
|
14
|
-
(`user32` + `ntdll` P/Invoke)枚举控制台窗口:`CASCADIA_HOSTING_WINDOW_CLASS`
|
|
15
|
-
(Windows Terminal)、`ConsoleWindowClass`(传统 conhost)、
|
|
16
|
-
`PseudoConsoleWindow`(ConPTY 伪控制台)。
|
|
17
|
-
2. 按进程归类:优先看**父进程**(父进程是 `WmiPrvSE.exe` → `wmi-detached`,
|
|
18
|
-
WMI 拉起的脱离任务,无人值守 Fluent 计算正是这样启动的;父进程是
|
|
19
|
-
`DSH Desktop.exe` → `dsh-host`;父进程已退出 → `orphaned`)。当父链说明
|
|
20
|
-
不了问题时(Windows Terminal 的窗口归属于 WindowsTerminal 进程,而不是
|
|
21
|
-
它里面跑的脚本),改看**控制台标题**:脚本启动的控制台标题默认是
|
|
22
|
-
被启动程序的路径(`...\python.exe`),而交互式手开的控制台是提示符式
|
|
23
|
-
标题(`Windows PowerShell`)→ 归为 `script-console`。
|
|
24
|
-
3. 每轮采样进程 CPU(累计 CPU 时间差值)。CPU 低于 `cpuThresholdPct`(默认 1%)
|
|
25
|
-
且持续 `idleThresholdSec`(默认 60 秒)即判定为**用完了**。单次采样的后台
|
|
26
|
-
CPU 抖动不会重置空闲时钟(`spikeTolerance`,默认 2)。
|
|
27
|
-
4. 在管理范围内的「用完了」窗口执行配置的 `autoAction`(默认 `hide` = `SW_HIDE`,
|
|
28
|
-
进程继续跑)。`close` 发送 `WM_CLOSE`。前台窗口永不自动处理(`guardForeground`)。
|
|
29
|
-
|
|
30
|
-
父进程 PID 用 `NtQueryInformationProcess` 而非 CIM(`Get-CimInstance Win32_Process`)
|
|
31
|
-
—— 参考机上实测 **39 秒 vs 24 毫秒**(13 个进程)。单次完整探针约 350 毫秒。
|
|
32
|
-
|
|
33
|
-
## 安装
|
|
34
|
-
|
|
35
|
-
```sh
|
|
36
|
-
dsh plugin --profile <name> add dsh-console-sentinel
|
|
37
|
-
```
|
|
3
|
+
[](https://www.npmjs.com/package/dsh-console-sentinel)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+

|
|
38
6
|
|
|
39
|
-
|
|
40
|
-
|
|
7
|
+
A **DSH (DeepSeek Harness) plugin for Windows** that cleans up your taskbar in one click:
|
|
8
|
+
close every window of an app the way **Alt+F4** would (graceful `WM_CLOSE`, not a force-kill),
|
|
9
|
+
close leftover **empty console shells**, and never touch the harness itself or an in-progress
|
|
10
|
+
Fluent / MPI solver run.
|
|
41
11
|
|
|
42
|
-
|
|
12
|
+
> 中文说明见 [README.zh.md](./README.zh.md)
|
|
43
13
|
|
|
44
|
-
-
|
|
45
|
-
- `console_window_action` —— 对单个窗口执行 hide / show / minimize / restore / close
|
|
46
|
-
(用 `hwnd` 或 `pid` 定位)。`hide` 无损;`close` 可能丢失未保存输出。
|
|
47
|
-
对前台窗口操作需传 `force`。
|
|
48
|
-
- `console_windows_sweep` —— 一次性对所有空闲且在范围内的窗口执行动作
|
|
49
|
-
(跑完一批 Fluent 任务后清任务栏很好用)。
|
|
50
|
-
- `desktop_windows_cleanup` —— **一键关闭其他窗口**:关闭桌面上除前台、自身、
|
|
51
|
-
系统外壳和受保护进程以外的所有应用窗口(`dryRun` 先出计划;`protected` /
|
|
52
|
-
`keepTitle` / `keepPid` 可临时加固保护)。
|
|
53
|
-
- `sentinel_whitelist` —— 管理**持久化豁免白名单**:`list` / `add` / `remove` / `reset`,
|
|
54
|
-
`kind=process`(按映像名,如 `code.exe`)或 `kind=title`(按标题子串)。
|
|
55
|
-
白名单同时作用于自动隐藏/关闭与一键关闭窗口,落盘到
|
|
56
|
-
`~/.dsh/console-sentinel/whitelist.json`。
|
|
14
|
+

|
|
57
15
|
|
|
58
|
-
|
|
16
|
+
---
|
|
59
17
|
|
|
60
|
-
|
|
61
|
-
不记工具名也能点操作:
|
|
18
|
+
## Why
|
|
62
19
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
20
|
+
Windows accumulates windows you no longer need: empty PowerShell/cmd shells left behind by
|
|
21
|
+
tooling, terminals you forgot about, apps you closed the document for but not the program.
|
|
22
|
+
Closing them one by one is tedious, and a careless "kill everything" script will happily take
|
|
23
|
+
down your harness or a running CFD job.
|
|
67
24
|
|
|
68
|
-
|
|
69
|
-
capability header),不使用 iframe。改 `lib/client.js` 后按 **Ctrl+Shift+R** 硬刷新;
|
|
70
|
-
改宿主(`lib/index.js` / `package.json`)需**完全退出 DSH 再启动**。
|
|
25
|
+
This plugin does the closing **safely**:
|
|
71
26
|
|
|
72
|
-
|
|
27
|
+
* it closes **gracefully** (`WM_CLOSE`, exactly what Alt+F4 sends) so apps can save and exit;
|
|
28
|
+
* it closes **per window, per app, or as a batch** — no clicking through every window;
|
|
29
|
+
* it **never** closes the DSH host, and never closes Fluent / MPI / ANSYS solver processes;
|
|
30
|
+
* it can close **elevated (admin) windows** too, via a single UAC prompt.
|
|
73
31
|
|
|
74
|
-
|
|
75
|
-
|---|---|---|
|
|
76
|
-
| `enabled` | `true` | 总开关 |
|
|
77
|
-
| `scanIntervalSec` | `10` | 扫描 + CPU 采样间隔 |
|
|
78
|
-
| `idleThresholdSec` | `60` | 持续低 CPU 多少秒算「用完了」 |
|
|
79
|
-
| `cpuThresholdPct` | `1` | CPU 低于此值算空闲 |
|
|
80
|
-
| `autoAction` | `hide` | `none` \| `hide` \| `close` |
|
|
81
|
-
| `probeTimeoutMs` | `20000` | 探针硬超时 |
|
|
82
|
-
| `spikeTolerance` | `2` | 连续多少次「忙」采样才重置空闲时钟 |
|
|
83
|
-
| `guardForeground` | `true` | 永不自动处理前台窗口 |
|
|
84
|
-
| `scope.wmiDetached` | `true` | 管理 WMI 拉起的脱离控制台 |
|
|
85
|
-
| `scope.dshHost` | `true` | 管理宿主派生的控制台 |
|
|
86
|
-
| `scope.orphaned` | `false` | 管理父进程已退出的控制台 |
|
|
87
|
-
| `scope.scriptConsole` | `true` | 管理标题是脚本可执行文件路径的控制台(Windows Terminal 承载的脚本会话) |
|
|
88
|
-
| `scope.excludeTitles` | `[]` | 标题 substring 黑名单 |
|
|
89
|
-
| `scope.emptyConsole` | `true` | 把「没有任何工作子进程」的解释器控制台(PowerShell/Python/cmd 只剩 conhost)判为**空壳**,无论父链如何都纳入管理 —— 这是安全清理残留空 PowerShell 的开关(不必打开整个 `orphaned`,后者会误伤 mpiexec/fl2610/在跑的计算) |
|
|
90
|
-
| `emptyConsoleAction` | `hide` | 对空壳控制台的动作:`none` \| `hide` \| `close`;独立于 `autoAction`,即便自动动作关闭也能单独生效 |
|
|
91
|
-
| `whitelist.processes` | `[]` | 豁免进程映像名(如 `code.exe`),永不自动处理/一键关闭(运行时用 `sentinel_whitelist` 增删) |
|
|
92
|
-
| `whitelist.titles` | `[]` | 豁免标题子串,永不自动处理/一键关闭 |
|
|
93
|
-
|
|
94
|
-
```yaml
|
|
95
|
-
- id: dsh-console-sentinel
|
|
96
|
-
config:
|
|
97
|
-
idleThresholdSec: 90
|
|
98
|
-
scope:
|
|
99
|
-
excludeTitles:
|
|
100
|
-
- keep-alive
|
|
101
|
-
```
|
|
32
|
+
## Features
|
|
102
33
|
|
|
103
|
-
|
|
34
|
+
### One-click taskbar cleanup (preview first)
|
|
104
35
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
实测 `SW_SHOW` 无法恢复被隐藏的 Windows Terminal 窗口)。`close` 发 `WM_CLOSE`
|
|
108
|
-
(优雅关闭,和你点 X 一样),但可能丢失未保存状态,所以从不是默认动作。
|
|
109
|
-
自动动作绝不触碰:前台窗口、手动打开的控制台(`manual` 来源)、
|
|
110
|
-
标题命中黑名单或**白名单**的窗口、以及 `HARD_PROTECTED_PROCESSES` 里的系统/计算进程
|
|
111
|
-
(explorer、taskmgr、dsh desktop、fl2610/cx2610/mpiexec/smpd/fluent 等)。
|
|
112
|
-
每个动作都发 `console-sentinel/action` 事件并写日志。
|
|
36
|
+
`预演清理` lists exactly which windows would be closed (with icons), `执行清理` then closes them.
|
|
37
|
+
Execute stays disabled until you have previewed — no blind destructive clicks.
|
|
113
38
|
|
|
114
|
-
|
|
39
|
+

|
|
115
40
|
|
|
41
|
+
### Taskbar windows, grouped by app
|
|
42
|
+
|
|
43
|
+
The **icon grid** view (default) packs every window into a compact 30×30 grid — one click closes
|
|
44
|
+
that window. Switch to **detail view** for a per-app card with full titles, a whitelist checkbox,
|
|
45
|
+
`关掉该软件` (close the whole app), and a per-window `关闭` button.
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
49
|
+
Every close is confirmed first:
|
|
50
|
+
|
|
51
|
+

|
|
52
|
+
|
|
53
|
+
### Empty console shell cleanup
|
|
54
|
+
|
|
55
|
+
A shell with no working child process (just `conhost`) is an "empty shell". Hide them
|
|
56
|
+
(lossless, the process keeps running) or close them for real — only bare
|
|
57
|
+
`cmd` / `powershell` / `pwsh` / `python` are ever targeted.
|
|
58
|
+
|
|
59
|
+

|
|
60
|
+
|
|
61
|
+
### Persistent whitelist
|
|
62
|
+
|
|
63
|
+
Programs and window-title keywords that must never be hidden or closed. Stored in
|
|
64
|
+
`~/.dsh/console-sentinel/whitelist.json`, editable from the panel or the tools.
|
|
65
|
+
|
|
66
|
+

|
|
67
|
+
|
|
68
|
+
## Safety model
|
|
69
|
+
|
|
70
|
+
Bulk-closing windows is a destructive operation, so the plugin layers several hard guards:
|
|
71
|
+
|
|
72
|
+
| Guard | Behaviour |
|
|
73
|
+
|---|---|
|
|
74
|
+
| **Host process tree** | The DSH host, all its ancestors, and every descendant (`dsh` / `electron` / `deepseek` images) are never touched — closing one of those consoles can take the harness down. |
|
|
75
|
+
| **Compute protection** | `mpi` / `fluent` / `ansys` / `cx*` / `solver` / `cae` / `launcher` are never selected. An `mpiexec` console looks like a plain window but killing it ends a running simulation. |
|
|
76
|
+
| **Bare-interpreter only** | Empty-shell closing is restricted to `cmd` / `powershell` / `pwsh` / `python`. |
|
|
77
|
+
| **Foreground & self** | The focused window and the plugin's own process are skipped. |
|
|
78
|
+
| **Whitelist** | Anything you tick is permanently exempt. |
|
|
79
|
+
|
|
80
|
+
Graceful close (`WM_CLOSE`) is used everywhere; `taskkill /F` is deliberately **not** offered.
|
|
81
|
+
|
|
82
|
+
## Elevated (admin) windows
|
|
83
|
+
|
|
84
|
+
A non-elevated process cannot close an elevated window — Windows UIPI silently drops the message,
|
|
85
|
+
which looks like "the button does nothing". When you close an admin window (Task Manager,
|
|
86
|
+
screen recorders, …) the plugin starts **one** elevated helper: you get a single UAC prompt, it
|
|
87
|
+
sends the same `WM_CLOSE`, and reports back through a temp file (an elevated child's stdout is
|
|
88
|
+
not readable). Answer **No** and nothing happens — the plugin says so instead of pretending success.
|
|
89
|
+
|
|
90
|
+
## Install
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
dsh plugin --profile desktop add dsh-console-sentinel
|
|
116
94
|
```
|
|
117
|
-
lib/index.js Cordis 插件:配置、扫描调度、工具
|
|
118
|
-
lib/logic.js 纯台账/空闲状态机(单测覆盖)
|
|
119
|
-
lib/probe.js 内嵌 PowerShell 探针 + 窗口动作
|
|
120
|
-
tests/ 仅 node 的回归测试,不需要真实 Windows
|
|
121
|
-
```
|
|
122
95
|
|
|
123
|
-
|
|
124
|
-
|
|
96
|
+
Windows only. Declares `dsh.bundle` (host half) and `dsh.client` (settings-panel half), so it shows
|
|
97
|
+
up under **Settings → 控制台哨兵** with a terminal icon.
|
|
98
|
+
|
|
99
|
+
## Configuration
|
|
100
|
+
|
|
101
|
+
Defaults in `cordis.patch.yml`:
|
|
102
|
+
|
|
103
|
+
| Key | Default | Meaning |
|
|
104
|
+
|---|---|---|
|
|
105
|
+
| `scanIntervalSec` | `10` | probe interval |
|
|
106
|
+
| `idleThresholdSec` | `60` | how long a console must idle before it counts as empty |
|
|
107
|
+
| `cpuThresholdPct` | `1` | CPU floor for the idle test |
|
|
108
|
+
| `autoAction` | `none` | `none` \| `hide` \| `close` for idle consoles |
|
|
109
|
+
| `emptyConsoleAction` | `hide` | action for empty shells |
|
|
110
|
+
| `guardForeground` | `true` | never touch the focused window |
|
|
111
|
+
| `cleanup.protectedProcesses` | see above | never closed by the desktop cleanup |
|
|
112
|
+
| `whitelist.processes` / `.titles` / `.unprotect` | `[]` | runtime-managed exemptions |
|
|
113
|
+
|
|
114
|
+
## Tools
|
|
115
|
+
|
|
116
|
+
Host-side tools for scripted use: `console_windows_list`, `console_windows_action`,
|
|
117
|
+
`console_windows_sweep`, `desktop_windows_cleanup`, plus `sentinel_whitelist` for the
|
|
118
|
+
exemption list. A CLI is available via `lib/desktop-cli.mjs list|cleanup`.
|
|
119
|
+
|
|
120
|
+
## Licence
|
|
125
121
|
|
|
126
|
-
MIT
|
|
122
|
+
MIT
|
package/README.zh.md
CHANGED
|
@@ -1,123 +1,117 @@
|
|
|
1
1
|
# dsh-console-sentinel
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[
|
|
5
|
-
|
|
6
|
-
长时间运行的自动化工作流(Fluent 无人值守任务、批量脚本、WMI 拉起的脱离进程)
|
|
7
|
-
会在任务栏堆下一排 PowerShell/Python 黑窗口。你分不清哪些还在跑,也不敢随手关。
|
|
8
|
-
本插件替你追踪它们、区分「在忙」和「用完了」,并把用完的隐藏掉 —— 进程继续跑、
|
|
9
|
-
数据不丢,每个窗口都能随时叫回来。
|
|
10
|
-
|
|
11
|
-
## 工作原理
|
|
12
|
-
|
|
13
|
-
1. 每隔 `scanIntervalSec` 秒(默认 10)用零依赖的 Windows PowerShell 探针
|
|
14
|
-
(`user32` + `ntdll` P/Invoke)枚举控制台窗口:`CASCADIA_HOSTING_WINDOW_CLASS`
|
|
15
|
-
(Windows Terminal)、`ConsoleWindowClass`(传统 conhost)、
|
|
16
|
-
`PseudoConsoleWindow`(ConPTY 伪控制台)。
|
|
17
|
-
2. 按进程归类:优先看**父进程**(父进程是 `WmiPrvSE.exe` → `wmi-detached`,
|
|
18
|
-
WMI 拉起的脱离任务,无人值守 Fluent 计算正是这样启动的;父进程是
|
|
19
|
-
`DSH Desktop.exe` → `dsh-host`;父进程已退出 → `orphaned`)。当父链说明
|
|
20
|
-
不了问题时(Windows Terminal 的窗口归属于 WindowsTerminal 进程,而不是
|
|
21
|
-
它里面跑的脚本),改看**控制台标题**:脚本启动的控制台标题默认是
|
|
22
|
-
被启动程序的路径(`...\python.exe`),而交互式手开的控制台是提示符式
|
|
23
|
-
标题(`Windows PowerShell`)→ 归为 `script-console`。
|
|
24
|
-
3. 每轮采样进程 CPU(累计 CPU 时间差值)。CPU 低于 `cpuThresholdPct`(默认 1%)
|
|
25
|
-
且持续 `idleThresholdSec`(默认 60 秒)即判定为**用完了**。单次采样的后台
|
|
26
|
-
CPU 抖动不会重置空闲时钟(`spikeTolerance`,默认 2)。
|
|
27
|
-
4. 在管理范围内的「用完了」窗口执行配置的 `autoAction`(默认 `hide` = `SW_HIDE`,
|
|
28
|
-
进程继续跑)。`close` 发送 `WM_CLOSE`。前台窗口永不自动处理(`guardForeground`)。
|
|
29
|
-
|
|
30
|
-
父进程 PID 用 `NtQueryInformationProcess` 而非 CIM(`Get-CimInstance Win32_Process`)
|
|
31
|
-
—— 参考机上实测 **39 秒 vs 24 毫秒**(13 个进程)。单次完整探针约 350 毫秒。
|
|
3
|
+
[](https://www.npmjs.com/package/dsh-console-sentinel)
|
|
4
|
+
[](./LICENSE)
|
|
5
|
+

|
|
32
6
|
|
|
33
|
-
|
|
7
|
+
**DSH(DeepSeek Harness)Windows 插件**:一键清理任务栏窗口——按软件整体关闭、
|
|
8
|
+
关掉残留的空壳控制台,关闭方式等同于对每个窗口按 **Alt+F4**(优雅 `WM_CLOSE`,非强杀),
|
|
9
|
+
并且**绝不碰 DSH 宿主本身、也绝不碰正在计算的 Fluent / MPI**。
|
|
34
10
|
|
|
35
|
-
|
|
36
|
-
dsh plugin --profile <name> add dsh-console-sentinel
|
|
37
|
-
```
|
|
11
|
+
> English: [README.md](./README.md)
|
|
38
12
|
|
|
39
|
-
|
|
40
|
-
仅限 Windows —— patch 行在其他平台 `disabled`,`apply()` 运行时也会再守一次。
|
|
13
|
+

|
|
41
14
|
|
|
42
|
-
|
|
15
|
+
---
|
|
43
16
|
|
|
44
|
-
|
|
45
|
-
- `console_window_action` —— 对单个窗口执行 hide / show / minimize / restore / close
|
|
46
|
-
(用 `hwnd` 或 `pid` 定位)。`hide` 无损;`close` 可能丢失未保存输出。
|
|
47
|
-
对前台窗口操作需传 `force`。
|
|
48
|
-
- `console_windows_sweep` —— 一次性对所有空闲且在范围内的窗口执行动作
|
|
49
|
-
(跑完一批 Fluent 任务后清任务栏很好用)。
|
|
50
|
-
- `desktop_windows_cleanup` —— 一键关闭其它程序的窗口(受保护进程与白名单自动跳过)。
|
|
51
|
-
- `sentinel_whitelist` —— 管理豁免白名单(list/add/remove/reset,kind=process|title)。
|
|
17
|
+
## 为什么需要它
|
|
52
18
|
|
|
53
|
-
|
|
19
|
+
Windows 上总会攒下一堆不再需要的窗口:工具留下的空 PowerShell / cmd 空壳、忘了关的终端、
|
|
20
|
+
文档关了但程序还开着的软件。一个个点太麻烦,而粗暴的"全杀掉"脚本又会顺手带走你的宿主或正在跑的 CFD。
|
|
54
21
|
|
|
55
|
-
|
|
56
|
-
不用记工具名,点按钮即可:
|
|
22
|
+
这个插件**安全地**帮你关:
|
|
57
23
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
- **豁免白名单**:以标签形式管理进程名与窗口标题关键字,改动即时落盘
|
|
63
|
-
`~/.dsh/console-sentinel/whitelist.json`。
|
|
24
|
+
* **优雅关闭**(`WM_CLOSE`,正是 Alt+F4 发出的消息),软件能正常保存退出;
|
|
25
|
+
* 支持**按窗口 / 按软件 / 批量**三种粒度,不用挨个点;
|
|
26
|
+
* **永不关闭** DSH 宿主,**永不关闭** Fluent / MPI / ANSYS 求解器进程;
|
|
27
|
+
* 支持关闭**管理员权限窗口**——弹一次 UAC 即可。
|
|
64
28
|
|
|
65
|
-
|
|
66
|
-
capability header),不使用 iframe。改 `lib/client.js` 后按 **Ctrl+Shift+R** 硬刷新;
|
|
67
|
-
改宿主(`lib/index.js` / `package.json`)需**完全退出 DSH 再启动**。
|
|
29
|
+
## 功能
|
|
68
30
|
|
|
69
|
-
|
|
31
|
+
### 一键清理任务栏窗口(先预演)
|
|
70
32
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
| `enabled` | `true` | 总开关 |
|
|
74
|
-
| `scanIntervalSec` | `10` | 扫描 + CPU 采样间隔 |
|
|
75
|
-
| `idleThresholdSec` | `60` | 持续低 CPU 多少秒算「用完了」 |
|
|
76
|
-
| `cpuThresholdPct` | `1` | CPU 低于此值算空闲 |
|
|
77
|
-
| `autoAction` | `hide` | `none` \| `hide` \| `close` |
|
|
78
|
-
| `probeTimeoutMs` | `20000` | 探针硬超时 |
|
|
79
|
-
| `spikeTolerance` | `2` | 连续多少次「忙」采样才重置空闲时钟 |
|
|
80
|
-
| `guardForeground` | `true` | 永不自动处理前台窗口 |
|
|
81
|
-
| `scope.wmiDetached` | `true` | 管理 WMI 拉起的脱离控制台 |
|
|
82
|
-
| `scope.dshHost` | `true` | 管理宿主派生的控制台 |
|
|
83
|
-
| `scope.orphaned` | `false` | 管理父进程已退出的控制台 |
|
|
84
|
-
| `scope.scriptConsole` | `true` | 管理标题是脚本可执行文件路径的控制台(Windows Terminal 承载的脚本会话) |
|
|
85
|
-
| `scope.excludeTitles` | `[]` | 标题 substring 黑名单 |
|
|
86
|
-
|
|
87
|
-
```yaml
|
|
88
|
-
- id: dsh-console-sentinel
|
|
89
|
-
config:
|
|
90
|
-
idleThresholdSec: 90
|
|
91
|
-
scope:
|
|
92
|
-
excludeTitles:
|
|
93
|
-
- keep-alive
|
|
94
|
-
```
|
|
33
|
+
`预演清理` 列出将被关闭的窗口(带图标),核对无误再点 `执行清理`。
|
|
34
|
+
**没预演时「执行清理」是禁用的**——不会让你盲着执行破坏性操作。
|
|
95
35
|
|
|
96
|
-
|
|
36
|
+

|
|
97
37
|
|
|
98
|
-
|
|
99
|
-
`console_window_action` 的 `show` 可随时恢复(用 `SW_SHOWNORMAL` ——
|
|
100
|
-
实测 `SW_SHOW` 无法恢复被隐藏的 Windows Terminal 窗口)。`close` 发 `WM_CLOSE`
|
|
101
|
-
(优雅关闭,和你点 X 一样),但可能丢失未保存状态,所以从不是默认动作。
|
|
102
|
-
自动动作绝不触碰:前台窗口、手动打开的控制台(`manual` 来源)、
|
|
103
|
-
标题命中黑名单的窗口。每个动作都发 `console-sentinel/action` 事件并写日志。
|
|
38
|
+
### 任务栏窗口 · 按软件分组
|
|
104
39
|
|
|
105
|
-
|
|
40
|
+
默认是 **仅图标视图**:每个窗口压成一个 30×30 图标格,**点一下即关闭该窗口**,最省空间。
|
|
41
|
+
切到 **详细视图** 则按软件分组显示完整标题、白名单勾选框、`关掉该软件`(整个软件一次关掉)
|
|
42
|
+
以及每个窗口独立的 `关闭` 按钮。
|
|
106
43
|
|
|
44
|
+

|
|
45
|
+
|
|
46
|
+
每次关闭都会先确认:
|
|
47
|
+
|
|
48
|
+

|
|
49
|
+
|
|
50
|
+
### 空壳控制台清理
|
|
51
|
+
|
|
52
|
+
没有业务子进程(只剩 `conhost`)的解释器窗口即"空壳"。可以**隐藏**(无损,进程继续跑),
|
|
53
|
+
也可以**真正关闭**——且只针对裸 `cmd` / `powershell` / `pwsh` / `python`。
|
|
54
|
+
|
|
55
|
+

|
|
56
|
+
|
|
57
|
+
### 持久化白名单
|
|
58
|
+
|
|
59
|
+
进程名与窗口标题关键字,命中即永不隐藏、永不关闭。存于
|
|
60
|
+
`~/.dsh/console-sentinel/whitelist.json`,面板里点标签即可增删。
|
|
61
|
+
|
|
62
|
+

|
|
63
|
+
|
|
64
|
+
## 安全模型
|
|
65
|
+
|
|
66
|
+
批量关窗口是不可逆操作,因此叠加了多重硬保护:
|
|
67
|
+
|
|
68
|
+
| 保护层 | 行为 |
|
|
69
|
+
|---|---|
|
|
70
|
+
| **宿主进程树** | DSH 宿主本身、其全部祖先、以及所有 `dsh` / `electron` / `deepseek` 进程**及其全部后代**永不触碰——关掉其中某个控制台会连带把宿主杀掉。 |
|
|
71
|
+
| **计算保护** | `mpi` / `fluent` / `ansys` / `cx*` / `solver` / `cae` / `launcher` 一律不选。`mpiexec` 的控制台看上去像普通窗口,但它被杀就等于终止正在跑的仿真。 |
|
|
72
|
+
| **只动裸解释器** | 空壳关闭仅限 `cmd` / `powershell` / `pwsh` / `python`。 |
|
|
73
|
+
| **前台与自身** | 当前焦点窗口、插件自身进程一律跳过。 |
|
|
74
|
+
| **白名单** | 你勾选过的软件永久豁免。 |
|
|
75
|
+
|
|
76
|
+
全链路只用优雅关闭(`WM_CLOSE`),**刻意不提供 `taskkill /F` 强杀**。
|
|
77
|
+
|
|
78
|
+
## 管理员窗口关不掉怎么办
|
|
79
|
+
|
|
80
|
+
普通权限进程无法关闭管理员窗口——Windows 的 UIPI 会把消息**静默丢弃**,表现就是"点了没反应"。
|
|
81
|
+
关这类窗口时(任务管理器、录屏工具等),插件会启动**一个**提权助手:你只会看到**一次** UAC,
|
|
82
|
+
它发出同样的 `WM_CLOSE`,并通过临时文件把结果回传(提权子进程的 stdout 是拿不到的)。
|
|
83
|
+
点「否」则什么都不做,插件会**如实告知失败**,而不是假装成功。
|
|
84
|
+
|
|
85
|
+
## 安装
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
dsh plugin --profile desktop add dsh-console-sentinel
|
|
107
89
|
```
|
|
108
|
-
lib/index.js Cordis 插件:配置、扫描调度、工具、设置面板 HTTP 路由
|
|
109
|
-
lib/logic.js 纯台账/空闲状态机 + 空壳判定(单测覆盖)
|
|
110
|
-
lib/probe.js 内嵌 PowerShell 探针(含父子进程表)+ 窗口动作
|
|
111
|
-
lib/desktop.js 任务栏窗口清理(受保护进程/白名单/前台守卫)
|
|
112
|
-
lib/whitelist.js 持久化豁免白名单(~/.dsh/console-sentinel/whitelist.json)
|
|
113
|
-
lib/client.js 设置面板客户端 bundle(__ModuleLoader__,settings.section)
|
|
114
|
-
tests/ 仅 node 的回归测试,不需要真实 Windows
|
|
115
|
-
```
|
|
116
90
|
|
|
117
|
-
|
|
118
|
-
|
|
91
|
+
仅支持 Windows。同时声明 `dsh.bundle`(宿主半边)与 `dsh.client`(设置面板半边),
|
|
92
|
+
装好后在 **设置 → 控制台哨兵** 出现,带自定义终端图标。
|
|
93
|
+
|
|
94
|
+
## 配置
|
|
95
|
+
|
|
96
|
+
`cordis.patch.yml` 默认值:
|
|
97
|
+
|
|
98
|
+
| 键 | 默认 | 含义 |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| `scanIntervalSec` | `10` | 扫描间隔(秒) |
|
|
101
|
+
| `idleThresholdSec` | `60` | 判定空闲所需的秒数 |
|
|
102
|
+
| `cpuThresholdPct` | `1` | 空闲判定的 CPU 下限 |
|
|
103
|
+
| `autoAction` | `none` | 空闲控制台动作:`none` / `hide` / `close` |
|
|
104
|
+
| `emptyConsoleAction` | `hide` | 空壳动作 |
|
|
105
|
+
| `guardForeground` | `true` | 不处理前台窗口 |
|
|
106
|
+
| `cleanup.protectedProcesses` | 见上表 | 桌面清理永不选中 |
|
|
107
|
+
| `whitelist.processes` / `.titles` / `.unprotect` | `[]` | 运行时豁免清单 |
|
|
108
|
+
|
|
109
|
+
## 工具
|
|
110
|
+
|
|
111
|
+
宿主侧工具:`console_windows_list`、`console_windows_action`、`console_windows_sweep`、
|
|
112
|
+
`desktop_windows_cleanup`,以及管理豁免清单的 `sentinel_whitelist`。
|
|
113
|
+
命令行:`lib/desktop-cli.mjs list|cleanup`。
|
|
119
114
|
|
|
120
|
-
|
|
121
|
-
忙碌脉冲重置、范围守卫、台账 GC、排序。
|
|
115
|
+
## 许可
|
|
122
116
|
|
|
123
|
-
MIT
|
|
117
|
+
MIT
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|