dsh-dev-modes 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,6 +29,7 @@ param(
29
29
 
30
30
  [string]$Title,
31
31
  [int]$ProcessId = 0,
32
+ [int]$WaitSeconds = 10,
32
33
  [int]$X = 20000,
33
34
  [int]$Y = 20000
34
35
  )
@@ -138,33 +139,68 @@ switch ($Action) {
138
139
  }
139
140
 
140
141
  'hide' {
141
- $matched = $all
142
- if ($ProcessId -gt 0) { $matched = $matched | Where-Object { $_.pid -eq $ProcessId } }
143
- if ($Title) { $matched = $matched | Where-Object { $_.title -like "*$Title*" } }
144
- if (-not $matched) {
145
- "未匹配到窗口(Title='$Title' ProcessId=$ProcessId)" | Write-Error
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
146
178
  exit 1
147
179
  }
148
180
 
149
181
  $state = @(Read-State)
150
182
  foreach ($w in $matched) {
183
+ # 已经在屏幕外的不要重复记,避免 -Action show 时坐标被覆盖成 20000
184
+ $alreadyOut = ($w.left -ge 10000) -or ($w.top -ge 10000)
151
185
  $ok = [DshWin]::Move([IntPtr]$w.handle, $X, $Y, $w.width, $w.height)
152
186
  if (-not $ok) {
153
187
  "移动失败(可能是全屏独占窗口):$($w.title)"
154
188
  continue
155
189
  }
156
- $state += [pscustomobject]@{
157
- handle = $w.handle; pid = $w.pid; title = $w.title
158
- left = $w.left; top = $w.top; width = $w.width; height = $w.height
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
+ }
159
195
  }
160
- "已移出可视区:$($w.title) → ($X,$Y)"
196
+ "已移出可视区:$($w.title) [PID $($w.pid)] → ($X,$Y)"
161
197
  }
162
198
  Write-State $state
163
199
  break
164
200
  }
165
201
 
166
202
  'show' {
167
- $state = Read-State
203
+ $state = @(Read-State)
168
204
  if (-not $state -or $state.Count -eq 0) {
169
205
  '没有记录到需要还原的窗口'
170
206
  break
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dev-modes",
3
- "version": "1.1.2",
3
+ "version": "1.1.4",
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,6 +16,22 @@ import { fileURLToPath } from 'node:url';
16
16
  const HOME = process.env.DSH_HOME || path.join(os.homedir(), '.dsh');
17
17
  const STORE_DIR = path.join(HOME, 'storages', 'dsh-quiet-run');
18
18
  const STORE_FILE = path.join(STORE_DIR, 'state.json');
19
+ const LOG_FILE = path.join(STORE_DIR, 'requests.log');
20
+
21
+ /** 记一行请求日志:排查"点了开关但没生效"时,能看清前端到底传了哪个会话。 */
22
+ function logRequest(entry) {
23
+ try {
24
+ fs.mkdirSync(STORE_DIR, { recursive: true });
25
+ fs.appendFileSync(LOG_FILE, JSON.stringify({ t: Date.now(), ...entry }) + '\n', 'utf8');
26
+ const stat = fs.statSync(LOG_FILE);
27
+ if (stat.size > 200 * 1024) {
28
+ const lines = fs.readFileSync(LOG_FILE, 'utf8').trim().split('\n').slice(-200);
29
+ fs.writeFileSync(LOG_FILE, lines.join('\n') + '\n', 'utf8');
30
+ }
31
+ } catch {
32
+ /* 日志失败不影响功能 */
33
+ }
34
+ }
19
35
 
20
36
  /** 与包一起分发的窗口搬运脚本(绝对路径,写进规则里让模型直接可用)。 */
21
37
  const HELPER = path.join(
@@ -238,6 +254,7 @@ export function apply(ctx) {
238
254
  const url = new URL(req.url || '/', 'http://127.0.0.1');
239
255
  const asked = url.searchParams.get('sessionId');
240
256
  const sessionId = asked || activeSessionId;
257
+ logRequest({ kind: 'state', asked: asked ?? null, resolved: sessionId, fromActive: !asked });
241
258
  if (!sessionId) {
242
259
  sendJson(res, 200, { sessionId: null, quiet: true, ready: false, diag });
243
260
  return;
@@ -262,6 +279,13 @@ export function apply(ctx) {
262
279
  }
263
280
  const body = await readJsonBody(req);
264
281
  const sessionId = body.sessionId || activeSessionId;
282
+ logRequest({
283
+ kind: 'set',
284
+ bodySession: body.sessionId ?? null,
285
+ resolved: sessionId,
286
+ fromActive: !body.sessionId,
287
+ value: body.quiet,
288
+ });
265
289
  if (!sessionId) {
266
290
  sendJson(res, 400, { error: 'no active session yet' });
267
291
  return;
@@ -272,9 +296,28 @@ export function apply(ctx) {
272
296
  },
273
297
  });
274
298
 
299
+ const dumpLog = c.webServer.register({
300
+ kind: 'exact',
301
+ path: '/dsh-quiet-run/log',
302
+ handler: async (req, res) => {
303
+ let lines = [];
304
+ try {
305
+ lines = fs.readFileSync(LOG_FILE, 'utf8').trim().split('\n').slice(-60);
306
+ } catch {
307
+ lines = [];
308
+ }
309
+ res.writeHead(200, {
310
+ 'content-type': 'application/json; charset=utf-8',
311
+ 'cache-control': 'no-store',
312
+ });
313
+ res.end(JSON.stringify({ activeSessionId, entries: lines }));
314
+ },
315
+ });
316
+
275
317
  return () => {
276
318
  state();
277
319
  toggle();
320
+ dumpLog();
278
321
  };
279
322
  });
280
323
  });