dsh-dev-modes 1.1.1 → 1.1.3

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/README.md CHANGED
@@ -36,7 +36,27 @@ $DSH_HOME/storages/dsh-session-lock/policies.json
36
36
  $DSH_HOME/storages/dsh-quiet-run/state.json
37
37
  ```
38
38
 
39
- > 这两个是**提示词级约束**,不是强制拦截:模型被告知规则并遵守,但宿主不会物理阻止。窗口挪出屏幕后仍占用 GPU/CPU。
39
+ > 这两个是**提示词级约束**,不是强制拦截:模型被告知规则并遵守,但宿主不会物理阻止。
40
+
41
+ ## 静默运行怎么真正生效
42
+
43
+ 光有规则还不够——窗口得有人去搬。本包内置 `helpers/window-quiet.ps1`:
44
+
45
+ ```powershell
46
+ # 列出当前可见窗口(句柄|PID|坐标|标题)
47
+ powershell.exe -NoProfile -ExecutionPolicy Bypass -File helpers\window-quiet.ps1 -Action list
48
+
49
+ # 按进程号或标题把窗口移到 (20000,20000)
50
+ powershell.exe -NoProfile -ExecutionPolicy Bypass -File helpers\window-quiet.ps1 -Action hide -ProcessId 12345
51
+ powershell.exe -NoProfile -ExecutionPolicy Bypass -File helpers\window-quiet.ps1 -Action hide -Title "记事本"
52
+
53
+ # 全部还原到原坐标
54
+ powershell.exe -NoProfile -ExecutionPolicy Bypass -File helpers\window-quiet.ps1 -Action show
55
+ ```
56
+
57
+ 静默规则里写的是**这个脚本的绝对路径**,所以模型拿到的是可直接执行的命令,而不是一句"请把窗口移走"的空话。Godot 项目另有更快的做法:`godot_command eval "DisplayServer.window_set_position(Vector2i(20000, 20000))"`。
58
+
59
+ 局限:全屏独占的窗口搬不动(Windows 限制),脚本会返回失败——这时模型应当如实告诉你,而不是假装藏好了。
40
60
 
41
61
  ## 安装
42
62
 
@@ -0,0 +1,222 @@
1
+ <#
2
+ window-quiet.ps1 — 把窗口挪到屏幕外 / 还原。
3
+
4
+ 用途:静默运行模式下启动 GUI(游戏、编辑器、浏览器预览)后,立刻把窗口移到
5
+ 可视区域之外,避免挡住用户、抢走焦点;需要用户亲眼看时再把它移回来。
6
+
7
+ 用法:
8
+ # 列出当前可见窗口(句柄|PID|left,top|caption)
9
+ pwsh -File window-quiet.ps1 -Action list
10
+
11
+ # 把记事本窗口挪走
12
+ pwsh -File window-quiet.ps1 -Action hide -Title "记事本"
13
+
14
+ # 按进程号挪(适合刚启动、还不确定标题的程序)
15
+ pwsh -File window-quiet.ps1 -Action hide -ProcessId 12345
16
+
17
+ # 全部还原
18
+ pwsh -File window-quiet.ps1 -Action show
19
+
20
+ 说明:
21
+ - 只按"可见且标题非空"的顶层窗口匹配,避免误伤系统窗口。
22
+ - 挪走前会把原坐标记到临时文件,-Action show 时原位还原。
23
+ - 全屏独占的窗口挪不动,这是 Windows 的限制,此脚本会返回失败并说明。
24
+ #>
25
+ param(
26
+ [Parameter(Mandatory = $true)]
27
+ [ValidateSet('list', 'hide', 'show')]
28
+ [string]$Action,
29
+
30
+ [string]$Title,
31
+ [int]$ProcessId = 0,
32
+ [int]$WaitSeconds = 10,
33
+ [int]$X = 20000,
34
+ [int]$Y = 20000
35
+ )
36
+
37
+ $ErrorActionPreference = 'Stop'
38
+
39
+ $sig = @'
40
+ using System;
41
+ using System.Text;
42
+ using System.Collections.Generic;
43
+ using System.Runtime.InteropServices;
44
+ public class DshWin {
45
+ public delegate bool EnumProc(IntPtr h, IntPtr l);
46
+ [DllImport("user32.dll")] public static extern bool EnumWindows(EnumProc cb, IntPtr l);
47
+ [DllImport("user32.dll")] public static extern bool IsWindowVisible(IntPtr h);
48
+ [DllImport("user32.dll")] public static extern bool IsIconic(IntPtr h);
49
+ [DllImport("user32.dll", CharSet=CharSet.Unicode)] public static extern int GetWindowTextW(IntPtr h, StringBuilder s, int n);
50
+ [DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
51
+ [DllImport("user32.dll")] public static extern bool SetWindowPos(IntPtr h, IntPtr after, int x, int y, int cx, int cy, uint flags);
52
+ [DllImport("user32.dll")] public static extern bool GetWindowRect(IntPtr h, out RECT r);
53
+ public struct RECT { public int Left, Top, Right, Bottom; }
54
+
55
+ public static List<string> List() {
56
+ var acc = new List<string>();
57
+ EnumWindows((h, l) => {
58
+ if (!IsWindowVisible(h)) return true;
59
+ var sb = new StringBuilder(1024);
60
+ GetWindowTextW(h, sb, 1024);
61
+ var title = sb.ToString();
62
+ if (title.Length == 0) return true;
63
+ uint pid; GetWindowThreadProcessId(h, out pid);
64
+ RECT r; GetWindowRect(h, out r);
65
+ var w = r.Right - r.Left; var ht = r.Bottom - r.Top;
66
+ acc.Add(h.ToInt64() + "|" + pid + "|" + r.Left + "|" + r.Top + "|" + w + "|" + ht + "|" + title);
67
+ return true;
68
+ }, IntPtr.Zero);
69
+ return acc;
70
+ }
71
+
72
+ public static string Rect(IntPtr h) {
73
+ RECT r; GetWindowRect(h, out r);
74
+ return r.Left + "," + r.Top + "," + (r.Right - r.Left) + "," + (r.Bottom - r.Top);
75
+ }
76
+
77
+ public static bool Move(IntPtr h, int x, int y, int cx, int cy) {
78
+ // SWP_NOZORDER(0x4) | SWP_NOACTIVATE(0x10) —— 不改层级、不抢焦点
79
+ return SetWindowPos(h, IntPtr.Zero, x, y, cx, cy, 0x0014);
80
+ }
81
+ }
82
+ '@
83
+
84
+ if (-not ('DshWin' -as [type])) {
85
+ Add-Type -TypeDefinition $sig -ErrorAction Stop
86
+ }
87
+
88
+ $stateFile = Join-Path $env:TEMP 'dsh-quiet-windows.json'
89
+
90
+ function Read-State {
91
+ if (-not (Test-Path $stateFile)) { return @() }
92
+ try {
93
+ $raw = Get-Content $stateFile -Raw -Encoding UTF8 | ConvertFrom-Json
94
+ } catch {
95
+ return @()
96
+ }
97
+ $flat = New-Object System.Collections.ArrayList
98
+ foreach ($item in @($raw)) {
99
+ if ($null -eq $item) { continue }
100
+ if ($item -is [System.Array]) {
101
+ foreach ($inner in $item) { if ($inner) { [void]$flat.Add($inner) } }
102
+ } else {
103
+ [void]$flat.Add($item)
104
+ }
105
+ }
106
+ return $flat.ToArray()
107
+ }
108
+
109
+ function Write-State($rows) {
110
+ $flat = New-Object System.Collections.ArrayList
111
+ foreach ($item in @($rows)) {
112
+ if ($null -eq $item) { continue }
113
+ if ($item -is [System.Array]) { foreach ($inner in $item) { if ($inner) { [void]$flat.Add($inner) } } }
114
+ else { [void]$flat.Add($item) }
115
+ }
116
+ if ($flat.Count -eq 0) {
117
+ Remove-Item $stateFile -ErrorAction SilentlyContinue
118
+ return
119
+ }
120
+ # 手工拼 JSON 数组,避免单元素被 ConvertTo-Json 序列化成对象
121
+ $body = ($flat | ForEach-Object { $_ | ConvertTo-Json -Depth 5 -Compress }) -join ','
122
+ [System.IO.File]::WriteAllText($stateFile, "[$body]", (New-Object System.Text.UTF8Encoding($false)))
123
+ }
124
+
125
+ $all = [DshWin]::List() | ForEach-Object {
126
+ $p = $_ -split '\|', 7
127
+ [pscustomobject]@{
128
+ handle = [int64]$p[0]; pid = [int]$p[1]
129
+ left = [int]$p[2]; top = [int]$p[3]; width = [int]$p[4]; height = [int]$p[5]
130
+ title = $p[6]
131
+ }
132
+ }
133
+
134
+ switch ($Action) {
135
+ 'list' {
136
+ if (-not $all) { '(没有可见窗口)'; break }
137
+ $all | ForEach-Object { "{0}|{1}|{2},{3}|{4}x{5}|{6}" -f $_.handle, $_.pid, $_.left, $_.top, $_.width, $_.height, $_.title }
138
+ break
139
+ }
140
+
141
+ 'hide' {
142
+ # 打包应用(如 Win11 记事本、部分商店应用)里,Start-Process 拿到的 PID
143
+ # 常常不是真正拥有窗口的那个进程,所以这里把子进程也纳入匹配,
144
+ # 并且轮询等待窗口出现(GUI 启动需要时间)。
145
+ $candidatePids = New-Object System.Collections.Generic.HashSet[int]
146
+ if ($ProcessId -gt 0) {
147
+ [void]$candidatePids.Add($ProcessId)
148
+ try {
149
+ $children = Get-CimInstance Win32_Process -Filter "ParentProcessId = $ProcessId" -ErrorAction SilentlyContinue |
150
+ Select-Object -ExpandProperty ProcessId
151
+ foreach ($childPid in @($children)) { [void]$candidatePids.Add([int]$childPid) }
152
+ } catch {
153
+ # 拿不到进程树就只按原 PID 匹配
154
+ }
155
+ }
156
+
157
+ $matched = @()
158
+ $deadline = (Get-Date).AddSeconds([Math]::Max(0, $WaitSeconds))
159
+ while ($true) {
160
+ $snapshot = [DshWin]::List() | ForEach-Object {
161
+ $p = $_ -split '\|', 7
162
+ [pscustomobject]@{
163
+ handle = [int64]$p[0]; pid = [int]$p[1]
164
+ left = [int]$p[2]; top = [int]$p[3]; width = [int]$p[4]; height = [int]$p[5]
165
+ title = $p[6]
166
+ }
167
+ }
168
+ $matched = @($snapshot)
169
+ if ($candidatePids.Count -gt 0) { $matched = @($matched | Where-Object { $candidatePids.Contains([int]$_.pid) }) }
170
+ if ($Title) { $matched = @($matched | Where-Object { $_.title -like "*$Title*" }) }
171
+ if ($matched.Count -gt 0) { break }
172
+ if ((Get-Date) -ge $deadline) { break }
173
+ Start-Sleep -Milliseconds 250
174
+ }
175
+
176
+ if ($matched.Count -eq 0) {
177
+ "未匹配到窗口(Title='$Title' ProcessId=$ProcessId,已等待 $WaitSeconds 秒)" | Write-Error
178
+ exit 1
179
+ }
180
+
181
+ $state = @(Read-State)
182
+ foreach ($w in $matched) {
183
+ # 已经在屏幕外的不要重复记,避免 -Action show 时坐标被覆盖成 20000
184
+ $alreadyOut = ($w.left -ge 10000) -or ($w.top -ge 10000)
185
+ $ok = [DshWin]::Move([IntPtr]$w.handle, $X, $Y, $w.width, $w.height)
186
+ if (-not $ok) {
187
+ "移动失败(可能是全屏独占窗口):$($w.title)"
188
+ continue
189
+ }
190
+ if (-not $alreadyOut) {
191
+ $state += [pscustomobject]@{
192
+ handle = $w.handle; pid = $w.pid; title = $w.title
193
+ left = $w.left; top = $w.top; width = $w.width; height = $w.height
194
+ }
195
+ }
196
+ "已移出可视区:$($w.title) [PID $($w.pid)] → ($X,$Y)"
197
+ }
198
+ Write-State $state
199
+ break
200
+ }
201
+
202
+ 'show' {
203
+ $state = @(Read-State)
204
+ if (-not $state -or $state.Count -eq 0) {
205
+ '没有记录到需要还原的窗口'
206
+ break
207
+ }
208
+ $remaining = New-Object System.Collections.ArrayList
209
+ foreach ($s in $state) {
210
+ $handle = [int64]$s.handle
211
+ $ok = [DshWin]::Move([IntPtr]$handle, [int]$s.left, [int]$s.top, [int]$s.width, [int]$s.height)
212
+ if ($ok) {
213
+ "已还原:$($s.title) → ($($s.left),$($s.top))"
214
+ } else {
215
+ "还原失败(窗口可能已关闭):$($s.title)"
216
+ [void]$remaining.Add($s)
217
+ }
218
+ }
219
+ Write-State $remaining.ToArray()
220
+ break
221
+ }
222
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dev-modes",
3
- "version": "1.1.1",
3
+ "version": "1.1.3",
4
4
  "type": "module",
5
5
  "description": "Three DeepSeek Harness Agent presets in one bundle — plus the per-session isolation and quiet-run switches: software development, game development, and read-only discussion, with the matching delivery and engine workflows bundled as skills.",
6
6
  "author": "qingfengshangnanzhi",
@@ -16,7 +16,8 @@
16
16
  "files": [
17
17
  "index.js",
18
18
  "client.js",
19
- "session-lock",
19
+ "session-lock",
20
+ "helpers",
20
21
  "quiet-run",
21
22
  "cordis.patch.yml",
22
23
  "skills",
@@ -1,35 +1,45 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import os from 'node:os';
4
+ import { fileURLToPath } from 'node:url';
4
5
 
5
6
  /**
6
7
  * 每个会话独立的「静默运行」开关(并入 dsh-dev-modes)。
7
8
  *
8
- * 静默(默认):启动任何 GUI 都必须挪到屏幕外或改用无窗口方式,不挡用户、不抢焦点。
9
+ * 静默(默认):启动任何 GUI 都必须立刻挪到屏幕外,不挡用户、不抢焦点。
9
10
  * 可见:用户允许窗口出现在前台。
10
11
  *
11
12
  * 存储:$DSH_HOME/storages/dsh-quiet-run/state.json
12
13
  * { "<sessionId>": { "quiet": true, "updatedAt": 1700000000000 } }
13
- *
14
- * 目录名沿用独立插件时期的名字,升级后原有设置继续生效。
15
14
  */
16
15
 
17
16
  const HOME = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
18
17
  const STORE_DIR = path.join(HOME, 'storages', 'dsh-quiet-run');
19
18
  const STORE_FILE = path.join(STORE_DIR, 'state.json');
20
19
 
20
+ /** 与包一起分发的窗口搬运脚本(绝对路径,写进规则里让模型直接可用)。 */
21
+ const HELPER = path.join(
22
+ path.dirname(path.dirname(fileURLToPath(import.meta.url))),
23
+ 'helpers',
24
+ 'window-quiet.ps1',
25
+ );
26
+
21
27
  const QUIET_RULE = [
22
28
  '## 静默运行(本会话已开启)',
23
29
  '',
24
30
  '用户可能正在看视频或打字。启动任何 GUI 都不得挡住他、不得抢走焦点。',
25
31
  '',
26
32
  '- **优先无窗口**:构建、测试、lint、类型检查、逻辑验证一律用无界面方式(headless / batchmode / 纯命令行)',
27
- '- **必须开窗口**(游戏窗口、编辑器、浏览器预览)时:启动后立刻移到屏幕外(例如坐标 10000,10000),或用最小化启动;**禁止全屏**',
28
- '- 不要主动激活、置顶或聚焦任何新窗口;不要调用会抓取全屏的截图方式',
29
- '- 需要用户用肉眼确认效果时,先把窗口移回可见区域之前**先问他**,得到同意再显示',
30
- '- 预计超过 1 分钟的构建或测试(首次导入、cook、导出、编译大项目)先说明再跑',
31
- '',
32
- '如果你无法保证窗口不会出现在前台,就改用无窗口方式,或先问用户。',
33
+ '- **启动 GUI 之后必须立刻把它移出可视区**,别只说不做。命令:',
34
+ ' ```',
35
+ ` powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${HELPER}" -Action hide -ProcessId <刚启动的进程号>`,
36
+ ` powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${HELPER}" -Action hide -Title "<窗口标题片段>"`,
37
+ ` powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${HELPER}" -Action list # 查当前可见窗口`,
38
+ ' ```',
39
+ '- 用户要用肉眼看效果时:先问,得到同意后 `-Action show` 还原。用完记得再移出去。',
40
+ '- 不要全屏;不要主动激活、置顶、聚焦窗口。',
41
+ '- 预计超过 1 分钟的构建或测试(首次导入、cook、导出、编译大项目)先说明再跑。',
42
+ '- `hide` 失败(例如全屏独占窗口)时**如实告诉用户"这个窗口挪不走"**,不要假装已经藏起来。',
33
43
  ].join('\n');
34
44
 
35
45
  const VISIBLE_RULE = [
@@ -25,6 +25,17 @@ whenToUse: 项目有 project.godot 或 .tscn/.gd 文件,需要跑场景、改
25
25
  - `godot_run_project` 可能接管用户已打开的实例并返回 `external:true`:此时**不要杀进程**。让用户在编辑器按 F8,或对子进程运行用 `godot_command` 的 `eval get_tree().quit()`。
26
26
  - `eval` 只在非 debug 实例可用;需要多帧调用栈时才用 `debug:true`。
27
27
 
28
+ ## 静默运行(开关开启时)
29
+
30
+ 系统提示里有「静默运行」段落时,窗口不许挡用户。启动 GUI 后**立刻**执行,别只说不做:
31
+
32
+ - Godot 内部(首选,无闪烁):
33
+ `godot_command eval "DisplayServer.window_set_position(Vector2i(20000, 20000))"`
34
+ - 系统层面(也适用于编辑器、浏览器预览):
35
+ `powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<包内 helpers/window-quiet.ps1>" -Action hide -ProcessId <PID>`
36
+ - 用户要用肉眼看效果:先问,同意后 `-Action show` 还原,用完再移出去。
37
+ - 全屏独占(`window_mode = fullscreen`)的窗口挪不走:如实说明,或先改成窗口模式再跑。
38
+
28
39
  ## 导出
29
40
 
30
41
  - 先确认 `export_presets.cfg` 里已有对应预设、导出模板已安装,再 `godot_export_project`;缺预设就先建预设,不要盲调导出。