dsh-native-uia 0.6.0 → 0.6.2

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
@@ -1,6 +1,6 @@
1
1
  # 御屏 · dsh-native-uia
2
2
 
3
- 给 DeepSeek Harness(DSH)桌面端加 **Windows 原生 computer-use**:以 UI Automation 控件树为主观测通道,纯文本模型就能看懂并操控桌面;动作后台投递(默认不动鼠标、不抢焦点),一次调用批量执行、逐步校验,成功的批次自动存成可回放配方。当前版本 **0.6.0**。
3
+ 给 DeepSeek Harness(DSH)桌面端加 **Windows 原生 computer-use**:以 UI Automation 控件树为主观测通道,纯文本模型就能看懂并操控桌面;动作后台投递(默认不动鼠标、不抢焦点),一次调用批量执行、逐步校验,成功的批次自动存成可回放配方。当前版本 **0.6.2**。
4
4
 
5
5
  - 运行要求:Windows 10/11(UI Automation 客户端走 .NET Framework,由 PowerShell 5.1 承载),DSH 桌面端,Node ≥ 18。
6
6
  - 组成:`src/`(DSH 插件主进程:工具定义、策略、状态、面板服务)、`worker/`(两个 PowerShell 进程:`uia-worker.ps1` 观察与投递,`indicator-server.ps1` 屏幕指示层)、`client/`(面板)、`scripts/`(闸门与回归)。
@@ -16,7 +16,7 @@
16
16
  | | `computer_capture` | 窗口/屏幕截图(PNG,可裁 `region`) |
17
17
  | 动作 | `computer_act` | 对一个 ref 做一个 UIA 动作:invoke / set_value / toggle / select / **deselect / add_to_selection** / expand / collapse / scroll_up / scroll_down / **scroll_to** / **set_range** / focus / text_append;可选 `verify` 校验 |
18
18
  | | `computer_run` | 批次:先 `prepare_batch` 逐段校验(ref 是否仍有效、元素是否可用),再 `commit_batch`;`lazy` 逐段解析;重复看门狗(3 次落空 / 4 次重复即停);`lazy:true` 时同批可混指针与键盘步 |
19
- | | `computer_wait` | 等元素出现/消失、名称/值变化、启用状态、窗口出现/消失/标题变化 |
19
+ | | `computer_wait` | 等元素出现/消失、名称/值变化、静止(`no_change`)、启用状态、窗口出现/消失/标题变化 |
20
20
  | | `computer_resolve_window` | 按 windowId / pid / 标题 / 正则 / 类名解析窗口 |
21
21
  | | `computer_replay` | 按名字回放已保存的配方(`names:"list"` 列出) |
22
22
  | 指针/键盘 | `computer_click` | 点击:`ref`(中心现算)或 `x/y`;左/右/中、双击/三击、修饰键、按压时长 |
@@ -37,9 +37,9 @@ ref 属于一个窗口的一次 revision:**整窗**新快照使旧 ref 失效
37
37
 
38
38
  **观察优先,像素兜底。** 大窗口先 `depth=4-5` 看骨架,再用 `root=<容器 ref>` 或 `find_text within=<容器 ref>` 只挖那一块——而不是把整个窗口 `maxNodes` 抬高;没有 UIA 的 Canvas/游戏走 `computer_parse` + 像素坐标。`computer_act` 默认后台投递;`pointerMode=auto` 时元素不支持 UIA 动作才落到真实光标点击,`foreground` 模式全部像素投递。
39
39
 
40
- **节点树怎么读。** 每个节点一行:`ref 类型 "名称" 值 状态 [可做动词] 标志`。状态是 0.5.0 新加的:开关是 `{On}`,选中是 `{选中}`,树节点是 `{Expanded}` / `{Collapsed}` / `{LeafNode}`,滑块是 `{40/0-100}`,列表是 `{滚动 0%/35%}`;`[cut]` 表示走到深度上限、这里就是该下钻的 ref。状态优先从快照缓存读,遇到只回空气的桥接 provider(资源管理器的 shell 项)才补一次实时读,整次快照最多 30 次。树"卡在一个空 Pane"时换 `view:"raw"`——ControlView 是给辅助技术裁剪过的树,raw 会把被藏起来的管道面板也吐出来(同一个资源管理器窗口实测 79 → 89 节点,且因为跳过整树物化,反而更快:731 ms → 523 ms)。
40
+ **节点树怎么读。** 每个节点一行:`ref 类型 "名称" 值 状态 [可做动词] 标志`。状态字段:开关是 `{On}`,选中是 `{选中}`,树节点是 `{Expanded}` / `{Collapsed}` / `{LeafNode}`,滑块是 `{40/0-100}`,列表是 `{滚动 0%/35%}`;`[cut]` 表示走到深度上限、这里就是该下钻的 ref。状态优先从快照缓存读,遇到只回空气的桥接 provider(资源管理器的 shell 项)才补一次实时读,整次快照最多 30 次。树"卡在一个空 Pane"时换 `view:"raw"`——ControlView 是给辅助技术裁剪过的树,raw 会把被藏起来的管道面板也吐出来(同一个资源管理器窗口实测 79 → 89 节点,且因为跳过整树物化,反而更快:731 ms → 523 ms)。
41
41
 
42
- **批次先校验再执行。** `computer_run` 的每一步在 `prepare_batch` 里走同一套定位阶梯(strict → automationId → 归一化名称 → 显式子串),回 `matchedBy/score/degraded`;`lazy:true` 逐步在执行时解析;重复看门狗停死循环。全部通过的批次以 `goal` 为名存入配方(`~/.dsh/native-uia/recipes/`,保留 50 条),`computer_replay` 按名回放,参数可覆盖。
42
+ **批次先校验再执行。** `computer_run` 的每一步在 `prepare_batch` 里走同一套定位阶梯(strict → automationId → 归一化名称 → 显式子串),回 `matchedBy/score/degraded`;`lazy:true` 逐步在执行时解析;重复看门狗停死循环。全部通过的批次以 `goal` 为名存入配方(`~/.dsh/native-uia/recipes/`,保留 50 条,`DSH_NATIVE_UIA_RECIPE_KEEP` 可改),`computer_replay` 按名回放,参数可覆盖。
43
43
 
44
44
  **一个批次里可以混动作,但只有 lazy。** `lazy:true` 时同批可写 `click / double_click / right_click / hover / type / key / scroll / drag / wait` 与 UIA 动词,按顺序一段一段执行、共用同一套策略检查与"遇错即停";指针步的 `ref` 在执行那一刻现算中心。这类批次**不存配方**——坐标是执行时的产物,回放会打到别处。非 lazy 批次遇到指针步直接拒绝并提示改 `lazy:true` 或拆开调用,一个键都不碰。
45
45
 
@@ -62,11 +62,11 @@ ref 属于一个窗口的一次 revision:**整窗**新快照使旧 ref 失效
62
62
 
63
63
  ## 4. 指示层
64
64
 
65
- 屏幕顶部居中一颗 **172×44 DIP** 的胶囊(黑壳 / 石墨银两种氛围光,深黑 / 声波 / 标块 / 反白四种样式),四态 `observe → act → verify → done/blocked/failed` 常驻显示;壳上画银色 DSH 鲸鱼,尾鳍 20° 蒙皮摆尾;壳底缘内侧一层薄雾(fBm 密度场两层,可在面板关掉);四边一条渐变边缘光随阶段呼吸;`act` 阶段指针跟一圈光晕。
65
+ 屏幕顶部居中一颗 **172×44 DIP** 的胶囊(黑壳 / 石墨银两种氛围光,深黑 / 声波 / 标块 / 反白四种样式),两种可见状态 `acting`(银白呼吸)/ `stopped`(暖红)常驻,`hidden` 整层收起;壳上画银色 DSH 鲸鱼,尾鳍 20° 蒙皮摆尾;壳底缘内侧一层薄雾(fBm 密度场两层,可在面板关掉);**一整圈**边缘光随阶段呼吸(单张按"到最近屏幕边的距离"烘焙的距离场贴图,四边亮度一致、四角不再叠加,换阶段只重烤这张图);`act` 阶段指针跟一圈光晕。
66
66
 
67
- 指示层是独立进程,坏掉只降级为日志,不影响桌面动作。实测帧率受 `AllowsTransparency` 分层窗限制,约 10 fps。
67
+ 指示层是独立进程,坏掉只降级为日志,不影响桌面动作。呼吸由 **33 ms 的 `DispatcherTimer`** 驱动,且 `Tick-Pulse` 对不足 33 ms 的重复 tick 直接丢弃——所以**视觉更新上限约 30 Hz**(这是代码里唯一的确定数)。真实合成帧率由分层透明窗和 GPU 决定,代码不承诺、也不统计;诊断时开 `DSH_INDICATOR_RENDER_HOOK=1` 会把 WPF 的 `CompositionTarget.Rendering` 一并接上(实测能把 2560×1600 分层表面顶到 ~55 Hz 合成),`framesRendered` 仍然只数"推过更新的 tick"。
68
68
 
69
- 调参(环境变量,物理像素):`DSH_INDICATOR_RENDER_MS`(33)、`PULSE_MS`(2400)、`RING_PX`(26)、`HALO_PX`(16)、`HALO_ON`(1)、`PILL_TOP_PX`(24)、`IDLE_MS`(120000)、`STOPPED_MS`(1200)、`PUMP_MS`(250)、`RENDER_HOOK`(0)。
69
+ 调参(环境变量,物理像素):`DSH_INDICATOR_RENDER_MS`(33)、`DSH_INDICATOR_PULSE_MS`(2400)、`DSH_INDICATOR_RING_PX`(26)、`DSH_INDICATOR_HALO_PX`(16)、`DSH_INDICATOR_HALO_ON`(1)、`DSH_INDICATOR_PILL_TOP_PX`(24)、`DSH_INDICATOR_IDLE_MS`(120000)、`DSH_INDICATOR_STOPPED_MS`(1200)、`DSH_INDICATOR_PUMP_MS`(250)、`DSH_INDICATOR_RENDER_HOOK`(0)、`DSH_INDICATOR_DPI_AWARE`(1)。
70
70
 
71
71
  ## 5. 安装与配置
72
72
 
@@ -79,25 +79,25 @@ npm run uninstall-plugin
79
79
 
80
80
  运行时选项写在 `~/.dsh/native-uia/settings.json`:`pointerMode`(auto / foreground / background)、`theme`(brand / graphite)、`style`(orb / wave / mark / inverse)、`mist`(true / false)。面板(插件详情页的「御屏」配置块)可切换投递方式、氛围光、胶囊样式、薄云,并显示监听 / 只读 / 租约 / 空转四行事实;改完立即生效并持久化。
81
81
 
82
- 本机服务:`http://127.0.0.1:3099`(`/api/summary` 轮询、`/api/action` 的 mode / theme / style / mist / kill),只答 JSON。
82
+ 本机服务:`http://127.0.0.1:3099`(`/api/state` 全量状态、`/api/summary` 摘要轮询、POST `/api/action` 的 worker / mode / theme / style / mist / kill),只答 JSON。
83
83
 
84
84
  ## 6. 验证与打包
85
85
 
86
86
  ```powershell
87
- npm run check # 静态闸门 90 项:解析、策略、契约、外观不变量、工具与 worker 能力对齐
87
+ npm run check # 静态闸门 92 项:解析、策略、契约、外观不变量、工具与 worker 能力对齐
88
88
  node scripts/check-lease.mjs # 租约 / 空闲自熄 / Esc 停止(不起桌面)
89
89
  node scripts/smoke.mjs # worker 启停与 ping
90
90
  powershell -NoProfile -ExecutionPolicy Bypass -File scripts/regression-worker.ps1 # 定位阶梯(mock 树)
91
91
  node scripts/regression-tools.mjs # 工具面回归
92
92
  node scripts/regression-quality.mjs # 渲染质量
93
- npm pack # → dsh-native-uia-0.6.0.tgz
93
+ npm pack # → dsh-native-uia-0.6.2.tgz
94
94
  ```
95
95
 
96
96
  真机脚本(会动桌面):`verify-live.mjs`、`verify-live-clipboard.mjs`、`verify-live-style.mjs`、`bench-live.mjs`、`verify-locator.mjs`、`verify-capture-scale.mjs`。
97
97
 
98
98
  ## 7. 已知边界
99
99
 
100
- - 指示层约 10 fps(分层透明窗),慢速动画台阶感明显。
100
+ - 指示层视觉更新上限约 30 Hz(33 ms 定时器 + 同 tick 丢弃);真实合成帧率取决于分层透明窗与机器,未在代码里固定。代码注释记录过一次实测(`renderHook=1`):只推 14 次更新 / 3.4 s,合成回调却有 189 次(≈55 Hz),说明"更新少"与"画面卡"不是一回事。
101
101
  - 批次步骤默认只能是 UIA 动词;要混指针/键盘步必须 `lazy:true`(这类批次不存配方)。
102
102
  - `set_range` 只对真的暴露 RangeValue 的元素生效(滑块、数值调节器);普通文本框用它回 `pattern_unsupported`,该用 `set_value`。`scroll_to` 同理需要 ScrollItem。桌面多数窗口只有 Pane 带 ScrollItem,列表项要不要带取决于 provider。
103
103
  - 节点树:虚拟化列表只扫已物化节点;`view:"raw"` 能吐出 ControlView 藏起来的节点,但同一棵树上 raw 的节点数可能是 control 的几倍,预算仍由 `maxNodes` 卡住;桥接 provider(部分 MSAA/Win32 老程序)连实时读都不给状态时,该节点就没有 state。
@@ -106,6 +106,8 @@ npm pack # → dsh-native-uia-0.6.0.tgz
106
106
 
107
107
  ## 8. 变更记录(压缩版,细节见 git)
108
108
 
109
+ - **0.6.2** 修“停止后再启动,氛围灯还是红的”。`Hide-Overlay` 只把 phase 改成 `hidden`,不重烤边缘光;`Render-Layout` 又按布局键复用整棵树,所以下一次 `show`(phase=acting)只换了胶囊文字,环形贴图仍是上一次 `stopped` 的红。现在记录环形贴图烘焙时的相位(`ringPhase`),`Show-Overlay` 在 `win.Show()` 之前发现相位与贴图不一致就重烤,启动那一帧不会闪旧色。闸门 91 → 92。
110
+ - **0.6.1** 边缘光改成一整圈。原来四条 `E = 4×环厚` 的渐变带各自铺满整条边,四个角互相重叠、alpha 相加,读出来就是"四条叠着、角上更亮"。现在用 `IndRing` 在 C# 里按**到最近屏幕边的距离**烘焙一张距离场贴图(≤1280 px 宽,上采样由 WPF 做),整屏一个 `Image`,四边亮度一致、四角连续;换阶段只重烤这张图,脉冲照旧只写它一个 `Opacity`。删掉 `New-Bar` / `New-GradH` / `New-Fade` / `New-Vignette` 四个只服务旧四条带的函数。闸门 90 → 91。
109
111
  - **0.6.0** 动作面收口。`computer_act` 新增 `deselect` / `add_to_selection`(多选列表叠加,select 会清空别的选择)、`scroll_to`(ScrollItem.ScrollIntoView)、`set_range`(RangeValue.SetValue,按 Min/Max 夹取);`$patternTypes` 补 `ScrollItem`,能拿到对象才算真的能滚动到可见。`click / drag / scroll / mouse` 收 `ref`,中心坐标由 `describe` 现算。`computer_run` 的 `lazy:true` 支持同批混指针与键盘步(共用策略检查、遇错即停、不存配方),非 lazy 批次明确拒绝混步。真机:`scroll_to` 在资源管理器 Pane 上 applied=true / 21.7 ms。闸门 88 → 90。
110
112
  - **0.5.0** 节点树取数扩面。节点带 `state`(toggle / selected / expanded / range / scroll),缓存优先、桥接 provider 补一次实时读(整次快照上限 30 次);`view` 可选 control / raw / content;`root=<ref>` 只扫子树且不升 revision;`find_text within=<ref>` 把"搜进某个容器"变成真的;`[cut]` 标出深度上限处该下钻的节点;渲染每行带状态。实测资源管理器:state 命中 5/79 → 25/79,raw 比 control 多节点且更快(731 → 523 ms)。闸门 85 → 88。
111
113
  - **0.4.1** 收口 0.4.0 未提交的部分并清掉旧层残留:删除 `src/confirm.js` 与 worker 的 `Cmd-Confirm`、`confirm` 分类与 `confirmTimeoutMs`(策略只剩放行/硬拒);`computer_launch` 新增解释器族拒收(`shell` 分类);删掉无人调用的 `@deepseek-ai/dsh-typert-protocol` 宿主通道(面板一直走回环接口);去死状态 `visionRoute`/`remoteChannel`、`STYLES.compact`;配方淘汰改按时间戳(原按文件名字典序会删掉较新的配方);`ACT_VERBS` 不再声称 RangeValue 可 act;README 重写为现在时说明;测试夹具补 `ensureArmed`,确认层用例改为“已武装即投递 / 未武装不过 worker”。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-native-uia",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "displayName": "御屏",
5
5
  "description": "以 Windows UI Automation 控件树为主观测通道的桌面操控插件:纯文本模型即可操控桌面,后台投递动作(不动鼠标、不抢焦点),一次调用批量执行并逐步校验,成功批次自动存为可回放配方。",
6
6
  "type": "module",
@@ -148,7 +148,7 @@ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
148
148
  // --- 8: the choke point classifies commands, and internal probes stay silent ---------------------
149
149
  // This is the flicker regression: the Esc watchdog polls `escape_pressed` every 40 ms. When the
150
150
  // client inferred "observation = not an action", each poll renewed the lease and beat the overlay
151
- // ~8×/s, which interleaved with the 100 ms pulse and made the ring visibly flicker.
151
+ // ~8×/s, which interleaved with the pulse tick and made the ring visibly flicker.
152
152
  {
153
153
  const { CuaWorker } = await import('../src/worker-client.js');
154
154
  const fired = { action: [], observe: [] };
@@ -5,7 +5,7 @@
5
5
  * and `dependencies`. Both edits are derived from the file as it is on disk,
6
6
  * never from a copied-out list, and every run leaves a timestamped backup.
7
7
  */
8
- import { readFileSync, writeFileSync, copyFileSync, existsSync, mkdirSync } from 'node:fs';
8
+ import { readFileSync, writeFileSync, copyFileSync, existsSync } from 'node:fs';
9
9
  import { dirname, join, resolve, isAbsolute } from 'node:path';
10
10
  import { fileURLToPath } from 'node:url';
11
11
  import { homedir } from 'node:os';
@@ -25,7 +25,6 @@ const PLUGIN_ROOT = process.env.DSH_PLUGIN_ROOT ?? join(homedir(), '.dsh', 'plug
25
25
  * (`dsh.client` in the same manifest), so there are no component packages to
26
26
  * link and no rows beyond the one bare-name row the patch inserts.
27
27
  */
28
- import { readdirSync } from 'node:fs';
29
28
  const ALL = [{ name: CORE_NAME, dir: CORE_DIR }];
30
29
  // DSH_PROFILE is often a bare profile NAME ("desktop"), not a path — the host exports it that way.
31
30
  // Joining it directly produced "desktop\package.json" relative to the cwd and status failed with
@@ -26,10 +26,6 @@ export function toolsSource() {
26
26
  return TOOLS_FILES.map((rel) => `// ---- ${rel} ----\n${readFileSync(join(root, rel), 'utf8')}`).join('\n');
27
27
  }
28
28
 
29
- export function toolsFileList() {
30
- return TOOLS_FILES.slice();
31
- }
32
-
33
29
  /**
34
30
  * The PowerShell worker, split the same way: the entry keeps process setup and the stdio loop, the
35
31
  * body lives in worker/lib in this order. The entry dot-sources the very list below at run time,
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * The kill latch must refuse only the command that was in flight at the stop instant.
4
+ *
5
+ * Measured bug (2026-11-21): Esc armed the latch, the next mutating call consumed it and was
6
+ * refused, and the model — reading "本轮已被终止" — never retried. `killed` stayed true, the run
7
+ * could not light again, and the person saw an unresponsive overlay. A second Esc re-armed it,
8
+ * so every stop kept poisoning one more action.
9
+ *
10
+ * This exercises the real halt callback from src/index.js against a fake store: no desktop input,
11
+ * no worker spawn.
12
+ */
13
+ import assert from 'node:assert/strict';
14
+ import { readFileSync } from 'node:fs';
15
+ import { dirname, join } from 'node:path';
16
+ import { fileURLToPath } from 'node:url';
17
+
18
+ const root = dirname(dirname(fileURLToPath(import.meta.url)));
19
+ const source = readFileSync(join(root, 'src/index.js'), 'utf8');
20
+
21
+ // Pull the production halt callback and its window constant out of index.js so the test cannot
22
+ // drift from the shipped logic.
23
+ const latchMs = Number(source.match(/const HALT_LATCH_MS = (\d+);/)?.[1]);
24
+ const haltBody = source.match(/halt: \(\) => \{([\s\S]*?)\n \},/)?.[1];
25
+
26
+ let passed = 0;
27
+ function test(name, fn) {
28
+ try { fn(); passed++; console.log(`PASS ${name}`); }
29
+ catch (error) { console.log(`FAIL ${name}: ${error.message}`); process.exitCode = 1; }
30
+ }
31
+
32
+ test('the latch window and the halt callback are present in the shipped source', () => {
33
+ assert.ok(Number.isFinite(latchMs) && latchMs > 0, 'HALT_LATCH_MS is missing or not a number');
34
+ assert.ok(typeof haltBody === 'string' && haltBody.length > 0, 'the halt callback was not found in index.js');
35
+ assert.match(haltBody, /killedAt/, 'the halt callback no longer considers when the latch was armed');
36
+ });
37
+
38
+ // Build a store shaped like src/state.js and run the production halt body against it.
39
+ function makeHalt() {
40
+ const logged = [];
41
+ const store = { killed: false, killedAt: 0, setKilled(v) { this.killed = v; if (v) this.killedAt = Date.now(); } };
42
+ const logger = (m) => logged.push(m);
43
+ const halt = new Function('store', 'logger', 'HALT_LATCH_MS', `return () => {${haltBody}\n};`)(store, logger, latchMs);
44
+ return { store, halt, logged };
45
+ }
46
+
47
+ test('a stopped command is refused inside the latch window', () => {
48
+ const { store, halt, logged } = makeHalt();
49
+ store.setKilled(true); // Esc fired
50
+ const message = halt(); // the in-flight command arrives immediately
51
+ assert.equal(typeof message, 'string', 'the command in flight at the stop was allowed through');
52
+ assert.match(message, /本轮已被终止/);
53
+ assert.equal(store.killed, false, 'the one-shot latch was not cleared after refusing');
54
+ assert.equal(logged.length, 1);
55
+ });
56
+
57
+ test('the next instruction after the window is delivered, not refused', () => {
58
+ const { store, halt, logged } = makeHalt();
59
+ store.setKilled(true);
60
+ store.killedAt = Date.now() - (latchMs + 500); // the person asked for something new
61
+ const message = halt();
62
+ assert.equal(message, null, 'a fresh instruction was refused because of an old stop');
63
+ assert.equal(store.killed, false, 'the stale latch was left armed');
64
+ assert.equal(logged.length, 0, 'a stale latch logged a stop that did not apply to this action');
65
+ });
66
+
67
+ test('an unarmed latch never blocks anything', () => {
68
+ const { halt, logged } = makeHalt();
69
+ assert.equal(halt(), null);
70
+ assert.equal(logged.length, 0);
71
+ });
72
+
73
+ test('a latch with no timestamp is treated as stale, not as fresh', () => {
74
+ // Defensive: a store restored from an older build has no killedAt. Reading it as age 0 would
75
+ // make the very first action after an upgrade look like the stopped command.
76
+ const { store, halt } = makeHalt();
77
+ store.killed = true;
78
+ store.killedAt = 0;
79
+ assert.equal(halt(), null, 'a timestamp-less latch blocked a new instruction');
80
+ });
81
+
82
+ test('Esc clears the latch even when no command ever consumes it', () => {
83
+ // The overlay is dismissed by Esc, so nothing else would ever clear a latch nobody read: the
84
+ // panel kept showing 已终止. index.js schedules a clear after the window.
85
+ assert.match(source, /clearAt/, 'index.js does not schedule a latch clear after Esc');
86
+ assert.match(source, /HALT_LATCH_MS \+ 250/, 'the scheduled clear does not wait for the latch window to pass');
87
+ });
88
+
89
+ test('Esc is sampled while the run is live, not only while the overlay is painted', () => {
90
+ // The overlay self-closes after DSH_NATIVE_UIA_IDLE_MS (20 s default) of tool silence, so a
91
+ // model thinking pause set activity.active=false. Gating the watchdog on that made Esc dead
92
+ // exactly when a person watches the agent work — the reported "运行中按 ESC 没反应".
93
+ const esc = source.match(/const escTimer = setInterval\(\(\) => \{([\s\S]*?)\n \}, (\d+)\)/)?.[1] ?? '';
94
+ assert.ok(esc !== '', 'the Esc watchdog block was not found');
95
+ assert.doesNotMatch(esc, /!activity\.active/, 'the watchdog still gates on the rendered overlay');
96
+ assert.match(esc, /store\.running !== true && store\.busy !== true/,
97
+ 'the watchdog does not gate on the live run plus in-flight commands');
98
+ });
99
+
100
+ console.log(`\n${passed}/7 halt-latch regressions passed (no desktop input)`);
@@ -1133,6 +1133,24 @@ gate('a repeated action does not rebuild the capsule, so the intro does not repl
1133
1133
  return 'repeated actions rebuild 0 times; a real look change rebuilds once; stopped recolours in place';
1134
1134
  });
1135
1135
 
1136
+ gate('the edge light is one ring, not four bands that add up at the corners', () => {
1137
+ // Reported twice: the frame reads as four strips, and the corners are brighter than the edges. Both
1138
+ // are geometric, not a colour tweak: each band spanned its whole edge, so two bands painted inside
1139
+ // every corner square and their alphas summed. A ring needs a field that depends only on the
1140
+ // distance to the NEAREST edge -- constant along each edge, continuous through the corner.
1141
+ const server = readFileSync(join(ROOT, 'worker', 'indicator-server.ps1'), 'utf8');
1142
+ assert(!/function New-Bar\b/.test(server), 'the per-edge band builder is back');
1143
+ assert(!/function New-GradH\b/.test(server), 'the per-edge gradient ramp is back');
1144
+ assert(/public static class IndRing/.test(server), 'the distance-field baker is gone');
1145
+ assert(/Math\.Min\(x, w - 1 - x\)/.test(server) && /Math\.Min\(y, h - 1 - y\)/.test(server),
1146
+ 'the ring alpha no longer measures the distance to the nearest edge');
1147
+ const ring = server.slice(server.indexOf('function New-RingTexture'), server.indexOf('function New-CursorGlowSource'));
1148
+ assert(/Add\(\$layer\)/.test(ring) && !/New-Bar/.test(ring), 'Build-Ring still adds more than one layer');
1149
+ assert(/\$script:S\.ringImg/.test(server), 'the ring element is not kept for the pulse and the recolour to drive');
1150
+ assert(/Stretch\]::Fill/.test(ring), 'the ring bitmap is no longer mapped onto the whole window surface');
1151
+ return 'one baked distance-field ring; corners join instead of doubling';
1152
+ });
1153
+
1136
1154
  gate('a phase change recolours in place instead of rebuilding the capsule', () => {
1137
1155
  // acting -> stopped used to clear the canvas and rebuild every visual, which replayed
1138
1156
  // Start-PillIntro's 340 ms scale-and-fade on the way out: the person saw the colour turn red AND
@@ -1149,14 +1167,32 @@ gate('a phase change recolours in place instead of rebuilding the capsule', () =
1149
1167
  'Set-PhaseInPlace no longer recolours in place');
1150
1168
  assert(!/if \(\$changed -and \$script:S\.built\) \{ Render-Layout/.test(server),
1151
1169
  'Set-PhaseInPlace rebuilds the tree again: the intro animation replays and stopped flashes twice');
1152
- // The recolour has to actually touch the ring, or the phase change is invisible.
1170
+ // The recolour has to actually touch the ring, or the phase change is invisible. The ring is ONE
1171
+ // baked texture now, so "recolour" means re-bake with the new palette rather than repaint brushes.
1153
1172
  const look = server.slice(server.indexOf('function Update-PhaseLook'), server.indexOf('function Render-Layout'));
1154
- assert(/New-GradH \$s\.g0 \$s\.g1/.test(look), 'the in-place recolour no longer repaints the ring');
1155
- assert(/\$b\.OpacityMask = \(& \$mask/.test(look), 'the in-place recolour no longer repaints the ring mask');
1173
+ assert(/New-RingTexture \$W \$H \$T \$ph/.test(look), 'the in-place recolour no longer re-bakes the edge ring');
1174
+ assert(/\$script:S\.ringImg\.Source = \$fresh/.test(look), 'the recolour no longer swaps the ring texture');
1156
1175
  assert(/\$script:S\.pill\.Effect = \$fresh/.test(look), 'the capsule bloom does not follow the phase: a red stopped capsule would sit in a silver halo');
1157
1176
  return 'phase changes recolour ring + mask + bloom in place; no rebuild, no replayed intro';
1158
1177
  });
1159
1178
 
1179
+ gate('a show that resumes a stopped run repaints the ring', () => {
1180
+ // Stopped auto-hides with the red palette still baked into the ring element. Render-Layout reuses
1181
+ // the tree on the next show, so without an explicit repaint the capsule announces "running" over
1182
+ // a red edge light -- the "restart after a stop, the ring is red" report.
1183
+ const server = readFileSync(join(ROOT, 'worker', 'indicator-server.ps1'), 'utf8');
1184
+ assert(/ringPhase\s*=/.test(server), 'the baked ring phase is no longer tracked: a resumed show cannot tell the palette is stale');
1185
+ const show = server.slice(server.indexOf('function Show-Overlay'), server.indexOf('function Hide-Overlay'));
1186
+ assert(/if \(\$script:S\.phase -ne 'hidden' -and \$script:S\.ringPhase -ne \[string\]\$script:S\.phase\) \{ Update-PhaseLook \}/.test(show),
1187
+ 'Show-Overlay no longer repaints a stale ring: resuming after a stop shows a red ring under a running capsule');
1188
+ assert(show.indexOf('Update-PhaseLook') < show.indexOf('win.Show()'),
1189
+ 'the repaint happens after the window is shown: the stale colour flashes for a frame');
1190
+ const look = server.slice(server.indexOf('function Update-PhaseLook'), server.indexOf('function Render-Layout'));
1191
+ assert(/\$script:S\.ringPhase = \[string\]\$script:S\.phase/.test(look),
1192
+ 'the in-place recolour no longer records which palette the ring now carries');
1193
+ return 'show repaints a stale ring before the window is shown';
1194
+ });
1195
+
1160
1196
  gate('a look change is visible on an idle session, not only during a run', () => {
1161
1197
  // Choosing a shape or a palette used to do nothing a person could SEE unless a run was already
1162
1198
  // painting the capsule: `refresh()` returns early when no run is active, so the stored value
@@ -1277,10 +1313,10 @@ gate('the overlay palette is a two-theme catalog, with brand black as the defaul
1277
1313
  // THE actual bug: the ring has to be painted from ringFrom/ringTo, not from the shell's border
1278
1314
  // colour (which both palettes share, so a switch could never change a pixel).
1279
1315
  const server = readFileSync(join(ROOT, 'worker', 'indicator-server.ps1'), 'utf8');
1280
- const ringBody = server.slice(server.indexOf('function Build-Ring'), server.indexOf('function New-CursorGlowSource'));
1316
+ const ringBody = server.slice(server.indexOf('function New-RingTexture'), server.indexOf('function New-CursorGlowSource'));
1281
1317
  assert(/\$ph\.g0/.test(ringBody) && /\$ph\.g1/.test(ringBody), 'Build-Ring no longer paints with the palette ramp: the ambient cannot change');
1282
- assert(!/New-GradH \$ph\.base \$ph\.base/.test(ringBody), 'Build-Ring paints from pillBorder again: both palettes share it, so the switch is invisible');
1283
- // The shell is explicitly out of scope: both themes must carry the SAME pill colours, so switching
1318
+ assert(!/New-Bar |New-GradH|New-Fade\(|New-Vignette\(/.test(ringBody), 'Build-Ring is composing per-edge bands again: four gradients add up at the corners, which is the "stacked strips" artefact');
1319
+ assert(/New-RingLayer \$W \$H \$T \$ph/.test(ringBody), 'Build-Ring no longer builds the single ring layer'); // The shell is explicitly out of scope: both themes must carry the SAME pill colours, so switching
1284
1320
  // the ambient cannot re-tint the capsule by accident.
1285
1321
  const shell = ['pillBg', 'pillBorder', 'pillText'];
1286
1322
  const drifted = shell.filter((k) => brand[k] !== graphite[k]);
@@ -2176,8 +2212,12 @@ gate('notes persist across runs, and the clipboard read stays gated on the run o
2176
2212
  assert(!/Set-Clipboard -Value ''/.test(ps), "Set-Clipboard -Value '' throws on Windows PowerShell 5.1; use [string[]]@()");
2177
2213
  assert((ps.match(/\[string\[\]\]@\(\)/g) ?? []).length >= 2, 'clear and empty write no longer both use the empty-array form');
2178
2214
  const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
2179
- assert(pkg.version === '0.6.0', `package.json version is ${pkg.version}, not the 0.6.0 this work is released as`);
2180
- return 'notes capped/deduped/sanitised and read back by observations; clipboard read gated on ctrl+c; version 0.6.0';
2215
+ // The release number lives in two places a person reads; pin them to each other instead of
2216
+ // hardcoding the current version here, which turns every bump into a gate failure.
2217
+ const readme = readFileSync(join(ROOT, 'README.md'), 'utf8');
2218
+ const claim = readme.match(/当前版本 \*\*([0-9]+\.[0-9]+\.[0-9]+)\*\*/)?.[1];
2219
+ assert(claim === pkg.version, `README advertises version ${claim} while package.json is ${pkg.version}`);
2220
+ return `notes capped/deduped/sanitised and read back by observations; clipboard read gated on ctrl+c; version ${pkg.version} matches README`;
2181
2221
  });
2182
2222
 
2183
2223
  gate('the worker body lives in lib, and the entry dot-sources the same list the gates read', () => {
@@ -57,7 +57,7 @@ const ACTION_COMMANDS = new Set([
57
57
  * This is a whitelist on purpose. Treating "not an action" as "an observation" looked equivalent
58
58
  * and was not: the Esc watchdog polls `escape_pressed` every 40 ms, so the else-branch fired a
59
59
  * beat ~25×/s. Each beat re-syncs the HWND, re-positions the pill and re-renders its text while
60
- * the pulse timer is pushing new opacity values every 100 ms, and the two interleave into a
60
+ * the pulse timer is pushing new opacity values on every tick (~30 Hz), and the two interleave into a
61
61
  * visible flicker on the ring. Internal probes are not observations and must stay silent here.
62
62
  */
63
63
  const OBSERVE_COMMANDS = new Set([
@@ -40,8 +40,7 @@
40
40
  # * never activated (ShowActivated=false, WS_EX_NOACTIVATE), never in the taskbar or alt-tab
41
41
  # (ShowInTaskbar=false, WS_EX_TOOLWINDOW), mouse-transparent (WS_EX_TRANSPARENT), and the
42
42
  # visuals are IsHitTestVisible=false as a second line of defence. A watchdog asserts the overlay
43
- # never becomes GetForegroundWindow(); if it ever did that is logged and counted
44
- # (state().fgThefts) instead of being silently accepted.
43
+ # never becomes GetForegroundWindow(); if it ever did, that is logged instead of silently accepted.
45
44
  #
46
45
  # Run: powershell.exe -NoProfile -ExecutionPolicy Bypass -File indicator-server.ps1
47
46
  $ErrorActionPreference = 'Stop'
@@ -242,6 +241,68 @@ public static class IndNative {
242
241
  public static int PhysWidth { get { try { return GetSystemMetrics(0); } catch { return 0; } } }
243
242
  public static int PhysHeight { get { try { return GetSystemMetrics(1); } catch { return 0; } } }
244
243
  }
244
+
245
+ // Edge light: ONE continuous ring, baked as a distance field.
246
+ //
247
+ // Alpha depends on the distance to the NEAREST screen edge, so it is constant along each edge and the
248
+ // four corners join with neither a seam nor a doubled patch. Four per-edge linear gradients cannot do
249
+ // that: where two of them overlap the alphas add, which is what reads as four strips with bright
250
+ // corners instead of one breathing frame. A radial gradient is the other obvious answer and is also
251
+ // wrong -- it brightens the middle of each edge and dims the corners, i.e. the opposite artefact.
252
+ //
253
+ // Two profiles, chosen from the palette, exactly like the old masks: 0 = light bleeding in from the
254
+ // frame (dense at the edge, dissolving inward); 1 = vignette for a darkening ambient (ramps up just
255
+ // inside the edge, holds, then releases, so the frame reads as intentional rather than as a dim border).
256
+ public static class IndRing {
257
+ public static byte[] Pixels(int w, int h, double e, int r0, int g0, int b0, int r1, int g1, int b1, double amp, int profile) {
258
+ byte[] px = new byte[w * h * 4];
259
+ if (w <= 0 || h <= 0 || e <= 0) return px;
260
+ // Distance to the NEAREST edge: constant along every edge, and at a corner the two nearest edges
261
+ // meet on the diagonal, so the iso-lines turn a mitre there instead of two bands adding up. A
262
+ // rounded-rectangle field was tried and read as a bevelled picture frame -- the physical corner
263
+ // triangle ends up outside the arc and takes full alpha.
264
+ for (int y = 0; y < h; y++) {
265
+ double dy = Math.Min(y, h - 1 - y);
266
+ for (int x = 0; x < w; x++) {
267
+ double dx = Math.Min(x, w - 1 - x);
268
+ // Plain minimum of the two nearest-edge distances. Measured alternatives, so nobody retries
269
+ // them: a rounded-rectangle field put the physical corner outside the arc and painted that
270
+ // triangle at full alpha (a bevelled picture frame); a smooth minimum rounded the iso-lines
271
+ // but carved a visibly dimmer notch out of each corner. The min() leaves one gradient crease
272
+ // on the 45-degree diagonal and is otherwise uniform -- the least artefact of the three.
273
+ double t = (dx < dy ? dx : dy) / e;
274
+ if (t >= 1.0) continue;
275
+ double a;
276
+ if (profile == 1) {
277
+ if (t < 0.18) {
278
+ double u = t / 0.18;
279
+ a = 0.55 + 0.45 * (u * u * (3.0 - 2.0 * u));
280
+ } else if (t < 0.46) {
281
+ a = 1.0;
282
+ } else {
283
+ double u = (t - 0.46) / 0.54;
284
+ a = 1.0 - (u * u * (3.0 - 2.0 * u));
285
+ }
286
+ } else {
287
+ double s = 1.0 - t;
288
+ a = s * s * s * (s * (s * 6.0 - 15.0) + 10.0);
289
+ }
290
+ a *= amp;
291
+ if (a <= 0.0) continue;
292
+ if (a > 1.0) a = 1.0;
293
+ double rr = r0 + (r1 - r0) * t;
294
+ double gg = g0 + (g1 - g0) * t;
295
+ double bb = b0 + (b1 - b0) * t;
296
+ int i = (y * w + x) * 4;
297
+ px[i + 0] = (byte)(bb * a);
298
+ px[i + 1] = (byte)(gg * a);
299
+ px[i + 2] = (byte)(rr * a);
300
+ px[i + 3] = (byte)(a * 255.0);
301
+ }
302
+ }
303
+ return px;
304
+ }
305
+ }
245
306
  '@
246
307
  $script:nativeLoaded = $false
247
308
  $script:dpiMode = 0
@@ -470,16 +531,12 @@ function Apply-Palette($A) {
470
531
  $script:S = [ordered]@{
471
532
  startTick = [Diagnostics.Stopwatch]::GetTimestamp()
472
533
  app = $null
473
- dispatcher = $null
474
534
  win = $null
475
535
  canvas = $null
476
536
  ring = @()
477
537
  bloom = @()
478
538
  outline = $null
479
539
  halo = $null
480
- haloBlooms = @()
481
- haloX = 0
482
- haloY = 0
483
540
  haloOn = $false
484
541
  haloCurs = $null
485
542
  haloShape = [IntPtr]::Zero
@@ -487,6 +544,7 @@ $script:S = [ordered]@{
487
544
  pill = $null
488
545
  pillText = $null
489
546
  pillSub = $null
547
+ ringImg = $null
490
548
  pillOrb = $null
491
549
  pillOrbScale = $null
492
550
  pillOrbHalo = $null
@@ -518,37 +576,25 @@ $script:S = [ordered]@{
518
576
  textOverride = ''
519
577
  subtext = ''
520
578
  framesRendered = [Int64]0
521
- renderCallbacks = [Int64]0
522
- visualUpdates = [Int64]0
523
579
  appliedAlpha = $null
524
580
  renderOn = $false
525
- renderHookOn = $false
526
- renderDriver = ''
527
581
  lastPulseStamp = [Int64]0
528
582
  lastPulseMsWall = [Int64]0
529
583
  phaseStartTick = [Diagnostics.Stopwatch]::GetTimestamp()
530
- pulseOffset = 0.0
531
- pulseAlpha = 0.0
532
584
  exStyles = 0
533
- straddle = $false
534
585
  idleHideMs = [int]$CFG.idleMs
535
586
  lastCmdTick = [Diagnostics.Stopwatch]::GetTimestamp()
536
- autoHides = [Int64]0
537
- showCount = [Int64]0
538
- hideCount = [Int64]0
539
587
  hwndCreateCount = [Int64]0
540
588
  hwndChanges = [Int64]0
541
589
  hwndSeen = @()
542
590
  fitPasses = 0
543
591
  fitConverged = $false
544
592
  fitDelta = $null
545
- fitRect = $null
546
- fgThefts = [Int64]0
547
593
  fontProbe = $null
548
594
  chosenFont = ''
549
595
  dipW = 0.0
550
- dipH = 0.0
551
596
  ringDip = 0.0
597
+ ringPhase = ''
552
598
  pillX = 0
553
599
  pillY = 0
554
600
  pillW = 0
@@ -803,26 +849,6 @@ function New-Solid($rgb, [double]$a) {
803
849
  return $b
804
850
  }
805
851
 
806
- function New-GradH($rgb0, $rgb1, [double]$a, [bool]$flip) {
807
- # colour ramp across the ring direction, constant alpha
808
- $b = New-Object System.Windows.Media.LinearGradientBrush
809
- if ($flip) {
810
- $b.StartPoint = New-Object System.Windows.Point -ArgumentList 1.0, 0.5
811
- $b.EndPoint = New-Object System.Windows.Point -ArgumentList 0.0, 0.5
812
- } else {
813
- $b.StartPoint = New-Object System.Windows.Point -ArgumentList 0.0, 0.5
814
- $b.EndPoint = New-Object System.Windows.Point -ArgumentList 1.0, 0.5
815
- }
816
- $s0 = New-Object System.Windows.Media.GradientStop
817
- $s0.Color = (ColA $a $rgb0); $s0.Offset = 0.0
818
- $s1 = New-Object System.Windows.Media.GradientStop
819
- $s1.Color = (ColA $a $rgb1); $s1.Offset = 1.0
820
- [void]$b.GradientStops.Add($s0)
821
- [void]$b.GradientStops.Add($s1)
822
- [void]$b.Freeze()
823
- return $b
824
- }
825
-
826
852
  function Test-DarkAmbient($rgb) {
827
853
  # A ramp whose average luminance is below mid-grey is an ambient that DARKENS the screen instead
828
854
  # of lighting it. The two need opposite geometry (see New-Vignette), so the distinction has to be
@@ -832,101 +858,63 @@ function Test-DarkAmbient($rgb) {
832
858
  return ($l -lt 96.0)
833
859
  }
834
860
 
835
- function New-Fade([double]$sx, [double]$sy, [double]$ex, [double]$ey, [double]$strength) {
836
- # opacity mask: solid at the monitor edge, fading inward
837
- $b = New-Object System.Windows.Media.LinearGradientBrush
838
- $b.StartPoint = New-Object System.Windows.Point -ArgumentList $sx, $sy
839
- $b.EndPoint = New-Object System.Windows.Point -ArgumentList $ex, $ey
840
- $a255 = [int][Math]::Round([Math]::Min(1.0, $strength) * 255.0)
841
- # One continuous falloff: no mid-stop shelf, no second hard edge. The old 0.42 shelf plus the
842
- # separate solid ring bar is what read as two stacked bands around the screen.
843
- foreach ($p in @(
844
- @{ o = 0.00; a = $a255 },
845
- @{ o = 0.16; a = [int]($a255 * 0.86) },
846
- @{ o = 0.36; a = [int]($a255 * 0.58) },
847
- @{ o = 0.58; a = [int]($a255 * 0.30) },
848
- @{ o = 0.78; a = [int]($a255 * 0.10) },
849
- @{ o = 1.00; a = 0 }
850
- )) {
851
- $gs = New-Object System.Windows.Media.GradientStop
852
- $gs.Color = [System.Windows.Media.Color]::FromArgb([byte]$p.a, 255, 255, 255)
853
- $gs.Offset = [double]$p.o
854
- [void]$b.GradientStops.Add($gs)
855
- }
856
- [void]$b.Freeze()
857
- return $b
861
+ function New-RingTexture([double]$W, [double]$H, [double]$T, $ph) {
862
+ # One continuous ring, baked as a distance field: alpha depends on the distance to the NEAREST
863
+ # screen edge, so brightness is constant along each edge and the four corners join without a seam
864
+ # or a doubled-up patch. Four per-edge gradients cannot do that -- where two of them overlap the
865
+ # alphas add, which is what the eye reads as four strips with bright corners instead of one frame.
866
+ #
867
+ # Baked at <= 1280 px wide: the field is a smooth gradient, so a 2-3x upscale is invisible, while
868
+ # a device-resolution bake on a 4K panel would cost 8 MB and ~30 ms on every phase change.
869
+ if (-not $script:nativeLoaded) { return $null }
870
+ $sc = [double]$script:S.scale; if ($sc -le 0) { $sc = 1.0 }
871
+ $wd = [double]$W * $sc; $hd = [double]$H * $sc
872
+ if ($wd -le 0 -or $hd -le 0) { return $null }
873
+ $k = 1.0
874
+ if ($wd -gt 1280.0) { $k = 1280.0 / $wd }
875
+ $bw = [int][Math]::Max(2, [Math]::Round($wd * $k))
876
+ $bh = [int][Math]::Max(2, [Math]::Round($hd * $k))
877
+ $e = [Math]::Max(2.0, [double]$T * 4.0 * $sc * $k)
878
+ $profile = 0
879
+ if (Test-DarkAmbient $ph.g0) { $profile = 1 }
880
+ $px = [IndRing]::Pixels($bw, $bh, $e, [int]$ph.g0[0], [int]$ph.g0[1], [int]$ph.g0[2], [int]$ph.g1[0], [int]$ph.g1[1], [int]$ph.g1[2], 0.85, $profile)
881
+ $bmp = [System.Windows.Media.Imaging.BitmapSource]::Create($bw, $bh, 96.0, 96.0, [System.Windows.Media.PixelFormats]::Pbgra32, $null, $px, $bw * 4)
882
+ $bmp.Freeze()
883
+ return $bmp
858
884
  }
859
885
 
860
- function New-Vignette([double]$sx, [double]$sy, [double]$ex, [double]$ey, [double]$strength) {
861
- # The mask for a DARK ambient. A black rim drawn with New-Fade's profile is densest at the screen
862
- # edge and dissolves inward, which on a dark desktop reads as "the screen is a bit dim at the
863
- # border" -- measured at luminance 4..21 against a desktop edge of 75, i.e. it merged into the
864
- # wallpaper and was invisible as a deliberate effect. A vignette has the opposite profile: it
865
- # ramps UP over the first part of the band, holds at full density through the middle, and then
866
- # releases -- so the darkest part sits just inside the edge, where the eye reads it as a frame
867
- # rather than as missing pixels. That is what makes a black ambient look intentional.
868
- $b = New-Object System.Windows.Media.LinearGradientBrush
869
- $b.StartPoint = New-Object System.Windows.Point -ArgumentList $sx, $sy
870
- $b.EndPoint = New-Object System.Windows.Point -ArgumentList $ex, $ey
871
- $a255 = [int][Math]::Round([Math]::Min(1.0, $strength) * 255.0)
872
- foreach ($p in @(
873
- @{ o = 0.00; a = [int]($a255 * 0.55) },
874
- @{ o = 0.18; a = $a255 },
875
- @{ o = 0.46; a = $a255 },
876
- @{ o = 0.70; a = [int]($a255 * 0.72) },
877
- @{ o = 0.88; a = [int]($a255 * 0.28) },
878
- @{ o = 1.00; a = 0 }
879
- )) {
880
- $gs = New-Object System.Windows.Media.GradientStop
881
- $gs.Color = [System.Windows.Media.Color]::FromArgb([byte]$p.a, 255, 255, 255)
882
- $gs.Offset = [double]$p.o
883
- [void]$b.GradientStops.Add($gs)
884
- }
885
- [void]$b.Freeze()
886
- return $b
886
+ function New-RingLayer([double]$W, [double]$H, [double]$T, $ph) {
887
+ # Stretch=Fill maps the baked bitmap onto the window surface in DIPs; its own pixels are only
888
+ # ~1280 wide, and HighQuality scaling keeps the upscaled gradient free of visible steps.
889
+ $img = New-Object System.Windows.Controls.Image
890
+ $img.Width = $W
891
+ $img.Height = $H
892
+ $img.Stretch = [System.Windows.Media.Stretch]::Fill
893
+ $img.Source = (New-RingTexture $W $H $T $ph)
894
+ if ($null -eq $img.Source) { return $null }
895
+ [System.Windows.Controls.Canvas]::SetLeft($img, 0.0)
896
+ [System.Windows.Controls.Canvas]::SetTop($img, 0.0)
897
+ $img.IsHitTestVisible = $false
898
+ [System.Windows.Media.RenderOptions]::SetBitmapScalingMode($img, [System.Windows.Media.BitmapScalingMode]::HighQuality)
899
+ return $img
887
900
  }
888
901
 
889
- function New-Bar([double]$x, [double]$y, [double]$w, [double]$h, $fill, $mask) {
890
- $r = New-Object System.Windows.Shapes.Rectangle
891
- $r.Width = [Math]::Max(0.5, $w)
892
- $r.Height = [Math]::Max(0.5, $h)
893
- $r.Fill = $fill
894
- if ($null -ne $mask) { $r.OpacityMask = $mask }
895
- [System.Windows.Controls.Canvas]::SetLeft($r, $x)
896
- [System.Windows.Controls.Canvas]::SetTop($r, $y)
897
- $r.SnapsToDevicePixels = $true
898
- $r.IsHitTestVisible = $false
899
- return $r
900
- }
901
-
902
- # Ring geometry for a window surface of W x H DIPs, thickness T DIPs.
903
- # BOTH pairs of bars span their full edge (horizontals full width, verticals full height) and therefore
904
- # overlap in the four T x T corner squares. That overlap is what makes the frame continuous -- if either
905
- # pair is inset, the corner is left to the perpendicular bar's fading tail and reads as a dark break.
906
- # The corner overlap only lifts alpha a little (pale lavender, perpendicular fades), so it glows rather
907
- # than burns.
908
902
  function Build-Ring([double]$W, [double]$H, [double]$T, $ph) {
903
+ # ONE element, one opacity write per pulse tick. The old build composed four E-wide bands that each
904
+ # spanned their full edge, so every corner square carried two gradients (alpha added up there) and
905
+ # the frame read as four strips meeting at bright patches -- the "stacked / layered" report.
909
906
  $bars = New-Object System.Collections.Generic.List[object]
910
907
  $bloom = New-Object System.Collections.Generic.List[object]
911
- # One wide falloff layer per edge, no separate hard ring bar: the edge light is a single soft
912
- # gradient that dissolves inward, so there are no stacked bands.
913
- #
914
- # The ramp is g0 -> g1, i.e. the palette's ringFrom -> ringTo. It used to be base -> base, and
915
- # `base` is pillBorder -- which BOTH palettes carry identically. That is why choosing an ambient
916
- # moved the stored value and not one pixel of the ring: the theme only ever reached the capsule.
917
- #
918
- # The MASK depends on whether the ambient lightens or darkens. A light ramp with the edge-dense
919
- # falloff looks like light bleeding in from the frame; a dark ramp with the same profile just looks
920
- # like a slightly dimmer border that merges into the wallpaper (measured: luminance 4..21 against a
921
- # desktop edge of 75 -- present, and invisible as an effect). A dark ambient gets the vignette
922
- # profile instead, which puts its darkest band just inside the edge so the eye reads a frame.
923
- $dark = Test-DarkAmbient $ph.g0
924
- $E = $T * 4.0
925
- $mask = if ($dark) { 'New-Vignette' } else { 'New-Fade' }
926
- [void]$bloom.Add((New-Bar 0 0 $W $E (New-GradH $ph.g0 $ph.g1 0.85 $false) (& $mask 0.5 0.0 0.5 1.0 1.0)))
927
- [void]$bloom.Add((New-Bar 0 ($H - $E) $W $E (New-GradH $ph.g1 $ph.g0 0.85 $false) (& $mask 0.5 1.0 0.5 0.0 1.0)))
928
- [void]$bloom.Add((New-Bar 0 0 $E $H (New-GradH $ph.g0 $ph.g1 0.85 $true) (& $mask 0.0 0.5 1.0 0.5 1.0)))
929
- [void]$bloom.Add((New-Bar ($W - $E) 0 $E $H (New-GradH $ph.g0 $ph.g1 0.85 $false) (& $mask 1.0 0.5 0.0 0.5 1.0)))
908
+ $layer = New-RingLayer $W $H $T $ph
909
+ if ($null -eq $layer) {
910
+ # Without the native helper there is no distance field. An overlay with no edge light is still a
911
+ # working overlay; falling back to four gradients would put the artefact back on screen.
912
+ Log 'ring texture unavailable: edge light skipped'
913
+ } else {
914
+ $script:S.ringImg = $layer
915
+ $script:S.ringPhase = [string]$script:S.phase
916
+ [void]$bloom.Add($layer)
917
+ }
930
918
  return @{ bars = $bars; bloom = $bloom }
931
919
  }
932
920
 
@@ -1033,7 +1021,6 @@ function Position-Halo {
1033
1021
  $lt = New-Object System.Windows.Media.TranslateTransform -ArgumentList $lx, $ly
1034
1022
  foreach ($it in $script:S.halo.items) { $it.RenderTransform = $lt; $it.Opacity = 1.0 }
1035
1023
  $script:S.haloOn = $true
1036
- $script:S.haloX = $c[0]; $script:S.haloY = $c[1]
1037
1024
  } elseif ($script:S.haloOn) {
1038
1025
  $script:S.haloOn = $false
1039
1026
  foreach ($it in $script:S.halo.items) { $it.Opacity = 0.0 }
@@ -1241,10 +1228,9 @@ function New-PillOrb($ph, [bool]$inverse) {
1241
1228
  # host uses in its welcome wordmark; it is scaled into an 18 DIP slot so the silhouette stays
1242
1229
  # crisp at any DPI.
1243
1230
  #
1244
- # The paper capsule used to wrap this in a 20 DIP rounded chip so a white whale had something to
1245
- # sit on. That chip was the "why does the white capsule's whale have its own background" problem:
1246
- # the mark carried a second surface the black capsule never had, and the two shapes no longer read
1247
- # as the same object. The whale is drawn straight onto the shell instead, in ink for paper.
1231
+ # The whale is drawn straight onto the shell, in ink on the paper style: no chip behind it. A chip
1232
+ # that only the paper style carried made its mark read as a second surface the black capsule never
1233
+ # had, and the two styles stopped looking like the same object.
1248
1234
  $wrap = New-Object System.Windows.Controls.Grid
1249
1235
  $wrap.Width = 18; $wrap.Height = 18
1250
1236
  $wrap.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
@@ -1303,9 +1289,9 @@ function New-PillMark {
1303
1289
  # A 20 DIP rounded square holding the identity mark, for the `mark` style only -- here the chip IS
1304
1290
  # the shape, so it has a surface of its own on purpose.
1305
1291
  #
1306
- # The paper capsule used to come through this function too, which is why its whale looked like it
1307
- # had a separate background: it did. `inverse` now draws the bare whale like `orb` does, in ink,
1308
- # so no style except this one carries a second surface.
1292
+ # This chip is the shape itself, so it is the one style allowed a second surface. `inverse` draws
1293
+ # the bare whale in ink like `orb`; putting it through this function gives the paper capsule a
1294
+ # background its whale should not have.
1309
1295
  $chip = New-Object System.Windows.Controls.Border
1310
1296
  $chip.Width = 20; $chip.Height = 20
1311
1297
  $chip.CornerRadius = New-Object System.Windows.CornerRadius -ArgumentList 6
@@ -1576,10 +1562,10 @@ function New-PillFloor([bool]$inverse) {
1576
1562
  function Build-Pill($ph) {
1577
1563
  # Four shapes, two things to decide: the shell (black or paper) and the mark.
1578
1564
  #
1579
- # ALL FOUR are the same size: 44 DIP, 22 DIP radius. `inverse` used to be grouped with `wave` as
1580
- # a "dense" two-line shape, so the paper capsule came out 56 DIP tall with a 25 DIP radius and
1581
- # switching to it moved the pill under the pointer. Size is not part of what "paper" means, so the
1582
- # shell colour and the height are decided separately now.
1565
+ # ALL FOUR are the same size: 44 DIP, 22 DIP radius. Size is not part of what "paper" means, so
1566
+ # the shell colour and the height are decided separately: grouping `inverse` with `wave` as a
1567
+ # "dense" two-line shape makes the paper capsule 56 DIP tall with a 25 DIP radius, and switching
1568
+ # styles then jumps the pill under the pointer.
1583
1569
  #
1584
1570
  # The mark is the whale on every style. `orb` and `inverse` draw it bare on the shell; `mark`
1585
1571
  # keeps the chip, because that chip IS the shape; `wave` shows bars instead.
@@ -1589,13 +1575,13 @@ function Build-Pill($ph) {
1589
1575
  $border = New-Object System.Windows.Controls.Border
1590
1576
  $border.CornerRadius = New-Object System.Windows.CornerRadius -ArgumentList 22
1591
1577
  $border.MinHeight = 44
1592
- # FIXED width. The capsule used to size to its content, which made its length a function of the
1593
- # text: the thin-smoke host (186 DIP) was the widest child and stretched every capsule to 218 DIP
1594
- # with ~80 empty DIP of shell past the type. A fixed length keeps the silhouette stable --
1595
- # constant shape, constant position of everything inside it, no layout shift when the state word
1596
- # changes -- and the smoke sheet fills whatever this width is instead of dictating it.
1578
+ # FIXED width. Sizing to content makes the length a function of the text: the thin-smoke host
1579
+ # (186 DIP) is the widest child and stretches every capsule to 218 DIP with ~80 empty DIP of shell
1580
+ # past the type. A fixed length keeps the silhouette stable -- constant shape, constant position of
1581
+ # everything inside it, no layout shift when the state word changes -- and the smoke sheet fills
1582
+ # whatever this width is instead of dictating it.
1597
1583
  # 172 DIP: mark(18) + gap(9) + heading(~34) + gap(10) + longest state word(~78) + padding(26).
1598
- # 160 was tried and squeezed the heading against the state word; the user settled on 172.
1584
+ # 160 squeezes the heading against the state word; do not go below 172.
1599
1585
  $border.Width = 172.0
1600
1586
  $bgT = $script:S.pillBg; if ($null -eq $bgT) { $bgT = @(11, 13, 16) }
1601
1587
  $bgBrush = New-Object System.Windows.Media.LinearGradientBrush
@@ -1857,11 +1843,11 @@ function Clear-Canvas {
1857
1843
  # twenty actions must show layoutBuilds = 1, not 20.
1858
1844
  $script:S.layoutBuilds += 1
1859
1845
  if ($null -ne $script:S.canvas) { $script:S.canvas.Children.Clear() }
1860
- $script:S.ring = @(); $script:S.bloom = @()
1846
+ $script:S.ring = @(); $script:S.bloom = @(); $script:S.ringImg = $null; $script:S.ringPhase = ''
1861
1847
  $script:S.pill = $null; $script:S.pillText = $null; $script:S.pillSub = $null
1862
1848
  $script:S.pillOrb = $null; $script:S.pillOrbScale = $null; $script:S.pillOrbHalo = $null; $script:S.pillOrbHaloScale = $null; $script:S.pillBars = @()
1863
1849
  $script:S.pillScale = $null; $script:S.pillBrandRun = $null; $script:S.pillRestRun = $null
1864
- $script:S.halo = $null; $script:S.haloBlooms = @(); $script:S.haloOn = $false
1850
+ $script:S.halo = $null; $script:S.haloOn = $false
1865
1851
  $script:S.haloCurs = $null; $script:S.haloShape = [IntPtr]::Zero
1866
1852
  }
1867
1853
 
@@ -1870,10 +1856,9 @@ function Clear-Canvas {
1870
1856
  function Update-PhaseLook {
1871
1857
  # Recolour the live tree for the current phase, WITHOUT rebuilding it.
1872
1858
  #
1873
- # The phase used to be part of Render-Layout's cache key, so acting -> stopped cleared the canvas
1874
- # and rebuilt every visual, which replayed the intro animation: the person saw the capsule turn
1875
- # red and then pop in again -- "the stopped state flashes twice". A phase change only needs new
1876
- # colours, so this rewrites the brushes that depend on the phase and leaves geometry, layout and
1859
+ # A phase change must not rebuild the tree: clearing the canvas replays the intro animation, so
1860
+ # the capsule turns red and then pops in again -- "the stopped state flashes twice". Phase only
1861
+ # needs new colours, so this rewrites the brushes that depend on it and leaves geometry, layout and
1877
1862
  # the running animations alone.
1878
1863
  #
1879
1864
  # Only the ring/bloom and the pill's own accent depend on the phase; the shell colour, the text
@@ -1887,26 +1872,14 @@ function Update-PhaseLook {
1887
1872
  $W = [double]$m.w / $sc
1888
1873
  $H = [double]$m.h / $sc
1889
1874
  $T = [double]$CFG.ringPx / $sc
1890
- $dark = Test-DarkAmbient $ph.g0
1891
- $mask = if ($dark) { 'New-Vignette' } else { 'New-Fade' }
1892
- # Rebuild only the four ring/bloom bars in place: they are pure colour + mask, no layout state.
1893
- $E = $T * 4.0
1894
- # `$edges`, not `$specs`: a gate forbids that name outside the smoke builder, where it used to be
1895
- # the signature of the drawn mist lobes.
1896
- $edges = @(
1897
- @{ x = 0; y = 0; w = $W; h = $E; g0 = $ph.g0; g1 = $ph.g1; flip = $false; m = @(0.5, 0.0, 0.5, 1.0) },
1898
- @{ x = 0; y = ($H - $E); w = $W; h = $E; g0 = $ph.g1; g1 = $ph.g0; flip = $false; m = @(0.5, 1.0, 0.5, 0.0) },
1899
- @{ x = 0; y = 0; w = $E; h = $H; g0 = $ph.g0; g1 = $ph.g1; flip = $true; m = @(0.0, 0.5, 1.0, 0.5) },
1900
- @{ x = ($W - $E); y = 0; w = $E; h = $H; g0 = $ph.g0; g1 = $ph.g1; flip = $false; m = @(1.0, 0.5, 0.0, 0.5) }
1901
- )
1902
- $i = 0
1903
- foreach ($b in @($script:S.bloom)) {
1904
- if ($null -eq $b -or $i -ge $edges.Count) { break }
1905
- $s = $edges[$i]
1906
- $b.Fill = (New-GradH $s.g0 $s.g1 0.85 ([bool]$s.flip))
1907
- $b.OpacityMask = (& $mask $s.m[0] $s.m[1] $s.m[2] $s.m[3] 1.0)
1908
- $i++
1909
- }
1875
+ # The ring is ONE baked texture, so a phase change re-bakes it (~10 ms at <= 1280 px wide) instead of
1876
+ # repainting four brushes. Geometry, position and the running breath are untouched: the pulse keeps
1877
+ # driving this element's Opacity exactly as before.
1878
+ if ($null -ne $script:S.ringImg) {
1879
+ $fresh = New-RingTexture $W $H $T $ph
1880
+ if ($null -ne $fresh) { $script:S.ringImg.Source = $fresh }
1881
+ }
1882
+ $script:S.ringPhase = [string]$script:S.phase
1910
1883
  # The pill's bloom is the phase accent, so it has to follow too -- otherwise a red stopped phase
1911
1884
  # sits in a silver halo.
1912
1885
  if ($null -ne $script:S.pill) {
@@ -1942,10 +1915,10 @@ function Render-Layout {
1942
1915
  # restart every animation, which read as one hard flash per tool action. Reuse the live tree and
1943
1916
  # only refresh text/position; the tail and the edge breath keep their phase.
1944
1917
  #
1945
- # The phase is deliberately NOT part of the key. It used to be, so acting -> stopped rebuilt the
1946
- # whole tree and replayed Start-PillIntro's 340 ms scale-and-fade on the way out: the person saw
1947
- # the colour turn red AND the capsule pop in again, which is the "stopped flashes twice" report.
1948
- # A phase change is a RECOLOUR, and Set-PhaseInPlace already does that in place.
1918
+ # The phase is deliberately NOT part of the key. Putting it there rebuilds the whole tree and
1919
+ # replays Start-PillIntro's 340 ms scale-and-fade on the way out: the colour turns red AND the
1920
+ # capsule pops in again, which is the "stopped flashes twice" report. A phase change is a RECOLOUR,
1921
+ # and Update-PhaseLook already does that in place.
1949
1922
  # The smoke flag IS part of the key: turning it on or off changes which children the tree has, so
1950
1923
  # it is a structural change and has to rebuild. It is a rare, deliberate act (a click on the plugin
1951
1924
  # page), not something that happens per action, so it does not reintroduce the per-action flash.
@@ -1957,7 +1930,6 @@ function Render-Layout {
1957
1930
  }
1958
1931
  $script:S.layoutKey = $layoutKey
1959
1932
  $script:S.dipW = $W
1960
- $script:S.dipH = $H
1961
1933
  $script:S.ringDip = $T
1962
1934
  $ph = $script:PH[$script:S.phase]
1963
1935
  if ($null -eq $ph) { $ph = $script:PH['acting'] }
@@ -2183,7 +2155,6 @@ function Fit-To-Monitor($m, [int]$maxPasses) {
2183
2155
  $r = Get-WindowRect
2184
2156
  if ($null -eq $r) { return }
2185
2157
  $script:S.fitPasses = $pass
2186
- $script:S.fitRect = $r
2187
2158
  $dw = [int]$target.w - [int]$r.w
2188
2159
  $dh = [int]$target.h - [int]$r.h
2189
2160
  $dx = [int]$target.x - [int]$r.x
@@ -2218,6 +2189,10 @@ function Show-Overlay($m) {
2218
2189
  $ds = (Get-DeviceScale)
2219
2190
  if ($ds -gt 0) { $script:S.scale = $ds } else { $script:S.scale = ([double]$m.dpi / 96.0) }
2220
2191
  Render-Layout | Out-Null
2192
+ # The tree is reused across a stop, and Hide-Overlay leaves the last baked palette on the ring:
2193
+ # a `show` that resumes with phase=acting would otherwise light a red ring under a running capsule
2194
+ # until the next phase command. Repaint before the window is shown, so no frame flashes the old colour.
2195
+ if ($script:S.phase -ne 'hidden' -and $script:S.ringPhase -ne [string]$script:S.phase) { Update-PhaseLook }
2221
2196
  Move-To-Monitor $m
2222
2197
  if (-not $script:S.visible) {
2223
2198
  $win.Show() # ShowActivated=false, so this never takes the foreground
@@ -2241,7 +2216,6 @@ function Hide-Overlay([string]$why) {
2241
2216
  }
2242
2217
  try { $script:S.win.Hide() } catch { Log ('hide threw: ' + $_.Exception.Message) }
2243
2218
  $script:S.visible = $false
2244
- $script:S.hideCount += 1
2245
2219
  $script:S.phase = 'hidden'
2246
2220
  Stop-RenderLoop
2247
2221
  Stop-HaloLoop
@@ -2249,10 +2223,9 @@ function Hide-Overlay([string]$why) {
2249
2223
  }
2250
2224
 
2251
2225
  # ---------------------------------------------------------------- render loop / pulse
2252
- # Only ever called when DSH_INDICATOR_RENDER_HOOK=1. renderCallbacks counts real composition frames;
2253
- # framesRendered counts pulse updates pushed, from timer or render event whichever is driving.
2226
+ # Only ever called when DSH_INDICATOR_RENDER_HOOK=1: framesRendered counts pulse updates
2227
+ # actually pushed, from the timer or the render event, whichever is driving.
2254
2228
  function On-Frame {
2255
- $script:S.renderCallbacks += 1
2256
2229
  Pump-Inbox
2257
2230
  Tick-Pulse
2258
2231
  }
@@ -2272,17 +2245,13 @@ function Start-RenderLoop {
2272
2245
  # Subscribing to WPF's render event is only an OBSERVER, and an expensive one: measured on this
2273
2246
  # box it kept a 2560x1600 layered surface compositing at ~55 Hz even while only 4 updates a
2274
2247
  # second were pushed (14 pushes -> 189 callbacks in 3.4 s). Off by default, on for diagnostics.
2275
- $hooked = $false
2276
2248
  if ($script:renderLoaded -and [int]$CFG.renderHook -eq 1) {
2277
2249
  try {
2278
2250
  [IndWpf]::StartRendering([System.Action]{ On-Frame })
2279
- $hooked = [bool][IndWpf]::RenderingOn
2280
2251
  } catch {
2281
2252
  Log ('render subscription failed: ' + $_.Exception.Message)
2282
2253
  }
2283
2254
  }
2284
- $script:S.renderHookOn = $hooked
2285
- $script:S.renderDriver = if ($hooked) { 'dispatcher-timer+composition-render-event' } else { 'dispatcher-timer' }
2286
2255
  $script:S.renderOn = $true
2287
2256
  }
2288
2257
 
@@ -2290,13 +2259,12 @@ function Stop-RenderLoop {
2290
2259
  if ($script:renderLoaded) { try { [IndWpf]::StopRendering() } catch { } }
2291
2260
  if ($null -ne $script:pulseTimer) { try { $script:pulseTimer.Stop() } catch { } }
2292
2261
  $script:S.renderOn = $false
2293
- $script:S.renderHookOn = $false
2294
2262
  }
2295
2263
 
2296
2264
  $script:pulseTimer = $null
2297
2265
  $script:haloTimer = $null
2298
2266
 
2299
- # The halo is decoupled from the 100 ms pulse: a dedicated ~16 ms loop repositions it with
2267
+ # The halo is decoupled from the pulse tick: a dedicated ~16 ms loop repositions it with
2300
2268
  # GetCursorPos, so it tracks the pointer without the one-beat lag a shared pulse tick would cause.
2301
2269
  function Start-HaloLoop {
2302
2270
  if ($null -ne $script:haloTimer) { return }
@@ -2339,8 +2307,6 @@ function Update-Pulse([Int64]$now) {
2339
2307
  elseif ($alpha -lt $prev - $step) { $alpha = $prev - $step }
2340
2308
  }
2341
2309
  $script:S.appliedAlpha = $alpha
2342
- $script:S.pulseOffset = $frac
2343
- $script:S.pulseAlpha = [Math]::Round($alpha, 4)
2344
2310
  foreach ($b in $script:S.ring) { if ($null -ne $b) { $b.Opacity = $alpha } }
2345
2311
  $bloomAlpha = $alpha * 0.72
2346
2312
  foreach ($b in $script:S.bloom) { if ($null -ne $b) { $b.Opacity = $bloomAlpha } }
@@ -2351,7 +2317,7 @@ function Update-Pulse([Int64]$now) {
2351
2317
  }
2352
2318
 
2353
2319
  # One pulse tick, from whatever source raised it. framesRendered counts ticks where a visual update
2354
- # was actually pushed; renderCallbacks counts composition frames WPF presented.
2320
+ # was actually pushed; composition frames are not counted here.
2355
2321
  function Tick-Pulse {
2356
2322
  if ($script:S.closing -or -not $script:S.visible) { return }
2357
2323
  $now = [Diagnostics.Stopwatch]::GetTimestamp()
@@ -2360,7 +2326,7 @@ function Tick-Pulse {
2360
2326
  if ($sinceMs -lt [double]$CFG.renderMs) { return }
2361
2327
  $script:S.lastPulseStamp = $now
2362
2328
  $script:S.framesRendered += 1
2363
- if (Update-Pulse $now) { $script:S.visualUpdates += 1 }
2329
+ [void](Update-Pulse $now)
2364
2330
  Position-Halo
2365
2331
  }
2366
2332
 
@@ -2494,8 +2460,6 @@ function Cmd-Show($A) {
2494
2460
  if ($phase -eq 'hidden') { Hide-Overlay 'show asked for phase hidden' }
2495
2461
  Start-RenderLoop
2496
2462
  Sync-Hwnd | Out-Null
2497
- $script:S.showCount += 1
2498
- $script:S.straddle = [bool]$pick.straddle
2499
2463
  $fgAfter = (Get-Fg)
2500
2464
  return [ordered]@{
2501
2465
  visible = [bool]$script:S.visible
@@ -2861,7 +2825,7 @@ function Close-Server([string]$why) {
2861
2825
  $aliveAfter = (Test-HwndAlive)
2862
2826
  Log ('hwnd ' + [Int64]$script:S.hwnd + ' IsWindow before close = ' + $aliveBefore + ', after close = ' + $aliveAfter)
2863
2827
  }
2864
- try { $script:S.canvas = $null; $script:S.win = $null; $script:S.ring = @(); $script:S.bloom = @() } catch { }
2828
+ try { $script:S.canvas = $null; $script:S.win = $null; $script:S.ring = @(); $script:S.bloom = @(); $script:S.ringImg = $null } catch { }
2865
2829
  try { if ($null -ne $script:S.app) { $script:S.app.Shutdown() } } catch { }
2866
2830
  try { if ($null -ne $script:dispatcher) { $script:dispatcher.InvokeShutdown() } } catch { }
2867
2831
  # A stuck overlay is the worst failure mode on this list, so unwinding the dispatcher is not
@@ -2878,7 +2842,6 @@ function Close-Server([string]$why) {
2878
2842
 
2879
2843
  # ---------------------------------------------------------------- bootstrap
2880
2844
  $script:dispatcher = [System.Windows.Threading.Dispatcher]::CurrentDispatcher
2881
- $script:S.dispatcher = $script:dispatcher
2882
2845
  $script:pumpAction = [System.Action]{ Pump-Inbox; [IndWake]::Clear() }
2883
2846
  $app = New-Object System.Windows.Application
2884
2847
  $app.ShutdownMode = [System.Windows.ShutdownMode]::OnExplicitShutdown
@@ -2897,7 +2860,6 @@ New-ServerTimer 250 {
2897
2860
  if ($script:S.visible) {
2898
2861
  $idle = (SinceMs $script:S.lastCmdTick)
2899
2862
  if ([int]$script:S.idleHideMs -gt 0 -and $idle -gt [double]$script:S.idleHideMs) {
2900
- $script:S.autoHides += 1
2901
2863
  $script:S.stats.autoHides += 1
2902
2864
  Log ('idle ' + [Math]::Round($idle, 0) + ' ms > idleHideMs ' + $script:S.idleHideMs + ' -- auto-hiding')
2903
2865
  Hide-Overlay 'idle auto-hide'
@@ -2905,7 +2867,6 @@ New-ServerTimer 250 {
2905
2867
  if ($script:nativeLoaded -and [Int64]$script:S.hwnd -ne 0) {
2906
2868
  try {
2907
2869
  if ((Get-Fg) -eq [Int64]$script:S.hwnd) {
2908
- $script:S.fgThefts += 1
2909
2870
  Log 'tripwire: the overlay became GetForegroundWindow() despite NOACTIVATE'
2910
2871
  }
2911
2872
  } catch { }