dsh-dev-modes 1.1.9 → 1.1.11

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.
@@ -18,7 +18,7 @@
18
18
  param(
19
19
  [string]$FlagFile,
20
20
  [string]$StateUrl,
21
- [int]$IntervalMs = 700,
21
+ [int]$IntervalMs = 120,
22
22
  [int]$X = 20000,
23
23
  [int]$Y = 20000
24
24
  )
@@ -118,12 +118,21 @@ function Get-WindowSnapshot {
118
118
  return $rows
119
119
  }
120
120
 
121
+ # 进程名缓存:每轮都 Get-Process 太慢,缓起来才能压到百毫秒级响应
122
+ $procNameCache = @{}
123
+
124
+ function Get-ProcName([int]$procId) {
125
+ if ($procNameCache.ContainsKey($procId)) { return $procNameCache[$procId] }
126
+ $name = ''
127
+ try { $name = (Get-Process -Id $procId -ErrorAction Stop).ProcessName } catch { $name = '' }
128
+ $procNameCache[$procId] = $name
129
+ return $name
130
+ }
131
+
121
132
  function Should-Skip($w) {
122
133
  if ($skipClasses -contains $w.klass) { return $true }
123
- try {
124
- $proc = Get-Process -Id $w.pid -ErrorAction Stop
125
- if ($skipProcessNames -contains $proc.ProcessName) { return $true }
126
- } catch { }
134
+ $name = Get-ProcName $w.pid
135
+ if ($name -and ($skipProcessNames -contains $name)) { return $true }
127
136
  # 窗口比 40x40 小的多为工具提示类,不处理
128
137
  if ($w.width -lt 40 -or $w.height -lt 40) { return $true }
129
138
  return $false
@@ -216,5 +225,6 @@ while ($true) {
216
225
 
217
226
  # 忘掉已关闭的窗口,避免集合无限增长
218
227
  $known = $currentHandles
228
+ if ($procNameCache.Count -gt 400) { $procNameCache = @{} }
219
229
  Start-Sleep -Milliseconds $IntervalMs
220
230
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-dev-modes",
3
- "version": "1.1.9",
3
+ "version": "1.1.11",
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",
@@ -55,6 +55,27 @@ function appendWatcherDebug(text) {
55
55
  }
56
56
  }
57
57
 
58
+ /**
59
+ * 后台监视器该不该动手,由「最后一次明确点开关的会话」决定。
60
+ *
61
+ * 试过两种信号都不对:
62
+ * - 用"这次轮询的会话":多开窗口时互相覆盖,A 开了静默被 B 盖回关闭。
63
+ * - 用"最近轮询过的任意会话,有一个开着就算数":A 窗口遗留的开启会强行让
64
+ * 别的窗口也静默,与 B 窗口显示的「可见运行」矛盾。
65
+ * 现在改成只看用户最后一次点开关的那一下——所见即所得。
66
+ */
67
+ let lastToggle = null;
68
+
69
+ /** 依据「最后一次点开关的会话」重算静默状态,并落给后台监视器。 */
70
+ function syncWatchFlag() {
71
+ if (!lastToggle) {
72
+ // 还没有人点过:按默认(静默)处理
73
+ writeWatchFlag(null, true);
74
+ return;
75
+ }
76
+ writeWatchFlag(lastToggle, isQuiet(lastToggle));
77
+ }
78
+
58
79
  function writeWatchFlag(sessionId, quiet) {
59
80
  try {
60
81
  fs.mkdirSync(STORE_DIR, { recursive: true });
@@ -367,7 +388,6 @@ export function apply(ctx) {
367
388
  const asked = url.searchParams.get('sessionId');
368
389
  const sessionId = asked || activeSessionId;
369
390
  const quietNow = sessionId ? isQuiet(sessionId) : true;
370
- if (sessionId) writeWatchFlag(sessionId, quietNow);
371
391
  logRequest({ kind: 'state', asked: asked ?? null, resolved: sessionId, fromActive: !asked });
372
392
  if (!sessionId) {
373
393
  sendJson(res, 200, { sessionId: null, quiet: true, ready: false, diag });
@@ -406,7 +426,8 @@ export function apply(ctx) {
406
426
  }
407
427
  const quiet = Boolean(body.quiet);
408
428
  const saved = setQuiet(sessionId, quiet);
409
- writeWatchFlag(sessionId, quiet);
429
+ lastToggle = sessionId;
430
+ syncWatchFlag();
410
431
  sendJson(res, 200, { sessionId, quiet, saved });
411
432
  },
412
433
  });