dsh-dev-modes 1.1.9 → 1.1.10

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.10",
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,39 @@ function appendWatcherDebug(text) {
55
55
  }
56
56
  }
57
57
 
58
+ /**
59
+ * 哪个会话"正在被看":每次前端轮询 /state 就记一下。
60
+ *
61
+ * 早先直接把标志写成"这次请求的会话的 quiet",问题是多开窗口时会互相覆盖——
62
+ * A 窗口开了静默,B 窗口(关着)下一秒轮询就把它盖回 false,表现为"开了不生效"。
63
+ * 现在改成:最近 15 秒内被轮询过、且自己开着静默的会话,只要有一个,就算静默生效。
64
+ */
65
+ const recentPolls = new Map();
66
+ const RECENT_WINDOW_MS = 15000;
67
+
68
+ function notePoll(sessionId) {
69
+ if (sessionId) recentPolls.set(sessionId, Date.now());
70
+ }
71
+
72
+ /** 依据"最近仍在轮询的会话"重算静默状态,并落给后台监视器。 */
73
+ function syncWatchFlag() {
74
+ const now = Date.now();
75
+ let quiet = false;
76
+ let winner = null;
77
+ for (const [sessionId, at] of recentPolls) {
78
+ if (now - at > RECENT_WINDOW_MS) {
79
+ recentPolls.delete(sessionId);
80
+ continue;
81
+ }
82
+ if (isQuiet(sessionId)) {
83
+ quiet = true;
84
+ winner = sessionId;
85
+ break;
86
+ }
87
+ }
88
+ writeWatchFlag(winner, quiet);
89
+ }
90
+
58
91
  function writeWatchFlag(sessionId, quiet) {
59
92
  try {
60
93
  fs.mkdirSync(STORE_DIR, { recursive: true });
@@ -367,7 +400,8 @@ export function apply(ctx) {
367
400
  const asked = url.searchParams.get('sessionId');
368
401
  const sessionId = asked || activeSessionId;
369
402
  const quietNow = sessionId ? isQuiet(sessionId) : true;
370
- if (sessionId) writeWatchFlag(sessionId, quietNow);
403
+ notePoll(sessionId);
404
+ syncWatchFlag();
371
405
  logRequest({ kind: 'state', asked: asked ?? null, resolved: sessionId, fromActive: !asked });
372
406
  if (!sessionId) {
373
407
  sendJson(res, 200, { sessionId: null, quiet: true, ready: false, diag });
@@ -406,7 +440,8 @@ export function apply(ctx) {
406
440
  }
407
441
  const quiet = Boolean(body.quiet);
408
442
  const saved = setQuiet(sessionId, quiet);
409
- writeWatchFlag(sessionId, quiet);
443
+ notePoll(sessionId);
444
+ syncWatchFlag();
410
445
  sendJson(res, 200, { sessionId, quiet, saved });
411
446
  },
412
447
  });