dsh-native-uia 0.6.0 → 0.6.1

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.1**。
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 # 静态闸门 91 项:解析、策略、契约、外观不变量、工具与 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.1.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,7 @@ npm pack # → dsh-native-uia-0.6.0.tgz
106
106
 
107
107
  ## 8. 变更记录(压缩版,细节见 git)
108
108
 
109
+ - **0.6.1** 边缘光改成一整圈。原来四条 `E = 4×环厚` 的渐变带各自铺满整条边,四个角互相重叠、alpha 相加,读出来就是"四条叠着、角上更亮"。现在用 `IndRing` 在 C# 里按**到最近屏幕边的距离**烘焙一张距离场贴图(≤1280 px 宽,上采样由 WPF 做),整屏一个 `Image`,四边亮度一致、四角连续;换阶段只重烤这张图,脉冲照旧只写它一个 `Opacity`。删掉 `New-Bar` / `New-GradH` / `New-Fade` / `New-Vignette` 四个只服务旧四条带的函数。闸门 90 → 91。
109
110
  - **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
111
  - **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
112
  - **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.1",
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,10 +1167,11 @@ 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
  });
@@ -1277,10 +1296,10 @@ gate('the overlay palette is a two-theme catalog, with brand black as the defaul
1277
1296
  // THE actual bug: the ring has to be painted from ringFrom/ringTo, not from the shell's border
1278
1297
  // colour (which both palettes share, so a switch could never change a pixel).
1279
1298
  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'));
1299
+ const ringBody = server.slice(server.indexOf('function New-RingTexture'), server.indexOf('function New-CursorGlowSource'));
1281
1300
  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
1301
+ 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');
1302
+ 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
1303
  // the ambient cannot re-tint the capsule by accident.
1285
1304
  const shell = ['pillBg', 'pillBorder', 'pillText'];
1286
1305
  const drifted = shell.filter((k) => brand[k] !== graphite[k]);
@@ -2176,8 +2195,8 @@ gate('notes persist across runs, and the clipboard read stays gated on the run o
2176
2195
  assert(!/Set-Clipboard -Value ''/.test(ps), "Set-Clipboard -Value '' throws on Windows PowerShell 5.1; use [string[]]@()");
2177
2196
  assert((ps.match(/\[string\[\]\]@\(\)/g) ?? []).length >= 2, 'clear and empty write no longer both use the empty-array form');
2178
2197
  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';
2198
+ assert(pkg.version === '0.6.1', `package.json version is ${pkg.version}, not the 0.6.1 this work is released as`);
2199
+ return 'notes capped/deduped/sanitised and read back by observations; clipboard read gated on ctrl+c; version 0.6.1';
2181
2200
  });
2182
2201
 
2183
2202
  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,36 +576,23 @@ $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
552
597
  pillX = 0
553
598
  pillY = 0
@@ -803,26 +848,6 @@ function New-Solid($rgb, [double]$a) {
803
848
  return $b
804
849
  }
805
850
 
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
851
  function Test-DarkAmbient($rgb) {
827
852
  # A ramp whose average luminance is below mid-grey is an ambient that DARKENS the screen instead
828
853
  # of lighting it. The two need opposite geometry (see New-Vignette), so the distinction has to be
@@ -832,101 +857,62 @@ function Test-DarkAmbient($rgb) {
832
857
  return ($l -lt 96.0)
833
858
  }
834
859
 
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
860
+ function New-RingTexture([double]$W, [double]$H, [double]$T, $ph) {
861
+ # One continuous ring, baked as a distance field: alpha depends on the distance to the NEAREST
862
+ # screen edge, so brightness is constant along each edge and the four corners join without a seam
863
+ # or a doubled-up patch. Four per-edge gradients cannot do that -- where two of them overlap the
864
+ # alphas add, which is what the eye reads as four strips with bright corners instead of one frame.
865
+ #
866
+ # Baked at <= 1280 px wide: the field is a smooth gradient, so a 2-3x upscale is invisible, while
867
+ # a device-resolution bake on a 4K panel would cost 8 MB and ~30 ms on every phase change.
868
+ if (-not $script:nativeLoaded) { return $null }
869
+ $sc = [double]$script:S.scale; if ($sc -le 0) { $sc = 1.0 }
870
+ $wd = [double]$W * $sc; $hd = [double]$H * $sc
871
+ if ($wd -le 0 -or $hd -le 0) { return $null }
872
+ $k = 1.0
873
+ if ($wd -gt 1280.0) { $k = 1280.0 / $wd }
874
+ $bw = [int][Math]::Max(2, [Math]::Round($wd * $k))
875
+ $bh = [int][Math]::Max(2, [Math]::Round($hd * $k))
876
+ $e = [Math]::Max(2.0, [double]$T * 4.0 * $sc * $k)
877
+ $profile = 0
878
+ if (Test-DarkAmbient $ph.g0) { $profile = 1 }
879
+ $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)
880
+ $bmp = [System.Windows.Media.Imaging.BitmapSource]::Create($bw, $bh, 96.0, 96.0, [System.Windows.Media.PixelFormats]::Pbgra32, $null, $px, $bw * 4)
881
+ $bmp.Freeze()
882
+ return $bmp
858
883
  }
859
884
 
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
885
+ function New-RingLayer([double]$W, [double]$H, [double]$T, $ph) {
886
+ # Stretch=Fill maps the baked bitmap onto the window surface in DIPs; its own pixels are only
887
+ # ~1280 wide, and HighQuality scaling keeps the upscaled gradient free of visible steps.
888
+ $img = New-Object System.Windows.Controls.Image
889
+ $img.Width = $W
890
+ $img.Height = $H
891
+ $img.Stretch = [System.Windows.Media.Stretch]::Fill
892
+ $img.Source = (New-RingTexture $W $H $T $ph)
893
+ if ($null -eq $img.Source) { return $null }
894
+ [System.Windows.Controls.Canvas]::SetLeft($img, 0.0)
895
+ [System.Windows.Controls.Canvas]::SetTop($img, 0.0)
896
+ $img.IsHitTestVisible = $false
897
+ [System.Windows.Media.RenderOptions]::SetBitmapScalingMode($img, [System.Windows.Media.BitmapScalingMode]::HighQuality)
898
+ return $img
887
899
  }
888
900
 
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
901
  function Build-Ring([double]$W, [double]$H, [double]$T, $ph) {
902
+ # ONE element, one opacity write per pulse tick. The old build composed four E-wide bands that each
903
+ # spanned their full edge, so every corner square carried two gradients (alpha added up there) and
904
+ # the frame read as four strips meeting at bright patches -- the "stacked / layered" report.
909
905
  $bars = New-Object System.Collections.Generic.List[object]
910
906
  $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)))
907
+ $layer = New-RingLayer $W $H $T $ph
908
+ if ($null -eq $layer) {
909
+ # Without the native helper there is no distance field. An overlay with no edge light is still a
910
+ # working overlay; falling back to four gradients would put the artefact back on screen.
911
+ Log 'ring texture unavailable: edge light skipped'
912
+ } else {
913
+ $script:S.ringImg = $layer
914
+ [void]$bloom.Add($layer)
915
+ }
930
916
  return @{ bars = $bars; bloom = $bloom }
931
917
  }
932
918
 
@@ -1033,7 +1019,6 @@ function Position-Halo {
1033
1019
  $lt = New-Object System.Windows.Media.TranslateTransform -ArgumentList $lx, $ly
1034
1020
  foreach ($it in $script:S.halo.items) { $it.RenderTransform = $lt; $it.Opacity = 1.0 }
1035
1021
  $script:S.haloOn = $true
1036
- $script:S.haloX = $c[0]; $script:S.haloY = $c[1]
1037
1022
  } elseif ($script:S.haloOn) {
1038
1023
  $script:S.haloOn = $false
1039
1024
  foreach ($it in $script:S.halo.items) { $it.Opacity = 0.0 }
@@ -1241,10 +1226,9 @@ function New-PillOrb($ph, [bool]$inverse) {
1241
1226
  # host uses in its welcome wordmark; it is scaled into an 18 DIP slot so the silhouette stays
1242
1227
  # crisp at any DPI.
1243
1228
  #
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.
1229
+ # The whale is drawn straight onto the shell, in ink on the paper style: no chip behind it. A chip
1230
+ # that only the paper style carried made its mark read as a second surface the black capsule never
1231
+ # had, and the two styles stopped looking like the same object.
1248
1232
  $wrap = New-Object System.Windows.Controls.Grid
1249
1233
  $wrap.Width = 18; $wrap.Height = 18
1250
1234
  $wrap.VerticalAlignment = [System.Windows.VerticalAlignment]::Center
@@ -1303,9 +1287,9 @@ function New-PillMark {
1303
1287
  # A 20 DIP rounded square holding the identity mark, for the `mark` style only -- here the chip IS
1304
1288
  # the shape, so it has a surface of its own on purpose.
1305
1289
  #
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.
1290
+ # This chip is the shape itself, so it is the one style allowed a second surface. `inverse` draws
1291
+ # the bare whale in ink like `orb`; putting it through this function gives the paper capsule a
1292
+ # background its whale should not have.
1309
1293
  $chip = New-Object System.Windows.Controls.Border
1310
1294
  $chip.Width = 20; $chip.Height = 20
1311
1295
  $chip.CornerRadius = New-Object System.Windows.CornerRadius -ArgumentList 6
@@ -1576,10 +1560,10 @@ function New-PillFloor([bool]$inverse) {
1576
1560
  function Build-Pill($ph) {
1577
1561
  # Four shapes, two things to decide: the shell (black or paper) and the mark.
1578
1562
  #
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.
1563
+ # ALL FOUR are the same size: 44 DIP, 22 DIP radius. Size is not part of what "paper" means, so
1564
+ # the shell colour and the height are decided separately: grouping `inverse` with `wave` as a
1565
+ # "dense" two-line shape makes the paper capsule 56 DIP tall with a 25 DIP radius, and switching
1566
+ # styles then jumps the pill under the pointer.
1583
1567
  #
1584
1568
  # The mark is the whale on every style. `orb` and `inverse` draw it bare on the shell; `mark`
1585
1569
  # keeps the chip, because that chip IS the shape; `wave` shows bars instead.
@@ -1589,13 +1573,13 @@ function Build-Pill($ph) {
1589
1573
  $border = New-Object System.Windows.Controls.Border
1590
1574
  $border.CornerRadius = New-Object System.Windows.CornerRadius -ArgumentList 22
1591
1575
  $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.
1576
+ # FIXED width. Sizing to content makes the length a function of the text: the thin-smoke host
1577
+ # (186 DIP) is the widest child and stretches every capsule to 218 DIP with ~80 empty DIP of shell
1578
+ # past the type. A fixed length keeps the silhouette stable -- constant shape, constant position of
1579
+ # everything inside it, no layout shift when the state word changes -- and the smoke sheet fills
1580
+ # whatever this width is instead of dictating it.
1597
1581
  # 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.
1582
+ # 160 squeezes the heading against the state word; do not go below 172.
1599
1583
  $border.Width = 172.0
1600
1584
  $bgT = $script:S.pillBg; if ($null -eq $bgT) { $bgT = @(11, 13, 16) }
1601
1585
  $bgBrush = New-Object System.Windows.Media.LinearGradientBrush
@@ -1857,11 +1841,11 @@ function Clear-Canvas {
1857
1841
  # twenty actions must show layoutBuilds = 1, not 20.
1858
1842
  $script:S.layoutBuilds += 1
1859
1843
  if ($null -ne $script:S.canvas) { $script:S.canvas.Children.Clear() }
1860
- $script:S.ring = @(); $script:S.bloom = @()
1844
+ $script:S.ring = @(); $script:S.bloom = @(); $script:S.ringImg = $null
1861
1845
  $script:S.pill = $null; $script:S.pillText = $null; $script:S.pillSub = $null
1862
1846
  $script:S.pillOrb = $null; $script:S.pillOrbScale = $null; $script:S.pillOrbHalo = $null; $script:S.pillOrbHaloScale = $null; $script:S.pillBars = @()
1863
1847
  $script:S.pillScale = $null; $script:S.pillBrandRun = $null; $script:S.pillRestRun = $null
1864
- $script:S.halo = $null; $script:S.haloBlooms = @(); $script:S.haloOn = $false
1848
+ $script:S.halo = $null; $script:S.haloOn = $false
1865
1849
  $script:S.haloCurs = $null; $script:S.haloShape = [IntPtr]::Zero
1866
1850
  }
1867
1851
 
@@ -1870,10 +1854,9 @@ function Clear-Canvas {
1870
1854
  function Update-PhaseLook {
1871
1855
  # Recolour the live tree for the current phase, WITHOUT rebuilding it.
1872
1856
  #
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
1857
+ # A phase change must not rebuild the tree: clearing the canvas replays the intro animation, so
1858
+ # the capsule turns red and then pops in again -- "the stopped state flashes twice". Phase only
1859
+ # needs new colours, so this rewrites the brushes that depend on it and leaves geometry, layout and
1877
1860
  # the running animations alone.
1878
1861
  #
1879
1862
  # Only the ring/bloom and the pill's own accent depend on the phase; the shell colour, the text
@@ -1887,25 +1870,12 @@ function Update-PhaseLook {
1887
1870
  $W = [double]$m.w / $sc
1888
1871
  $H = [double]$m.h / $sc
1889
1872
  $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++
1873
+ # The ring is ONE baked texture, so a phase change re-bakes it (~10 ms at <= 1280 px wide) instead of
1874
+ # repainting four brushes. Geometry, position and the running breath are untouched: the pulse keeps
1875
+ # driving this element's Opacity exactly as before.
1876
+ if ($null -ne $script:S.ringImg) {
1877
+ $fresh = New-RingTexture $W $H $T $ph
1878
+ if ($null -ne $fresh) { $script:S.ringImg.Source = $fresh }
1909
1879
  }
1910
1880
  # The pill's bloom is the phase accent, so it has to follow too -- otherwise a red stopped phase
1911
1881
  # sits in a silver halo.
@@ -1942,10 +1912,10 @@ function Render-Layout {
1942
1912
  # restart every animation, which read as one hard flash per tool action. Reuse the live tree and
1943
1913
  # only refresh text/position; the tail and the edge breath keep their phase.
1944
1914
  #
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.
1915
+ # The phase is deliberately NOT part of the key. Putting it there rebuilds the whole tree and
1916
+ # replays Start-PillIntro's 340 ms scale-and-fade on the way out: the colour turns red AND the
1917
+ # capsule pops in again, which is the "stopped flashes twice" report. A phase change is a RECOLOUR,
1918
+ # and Update-PhaseLook already does that in place.
1949
1919
  # The smoke flag IS part of the key: turning it on or off changes which children the tree has, so
1950
1920
  # it is a structural change and has to rebuild. It is a rare, deliberate act (a click on the plugin
1951
1921
  # page), not something that happens per action, so it does not reintroduce the per-action flash.
@@ -1957,7 +1927,6 @@ function Render-Layout {
1957
1927
  }
1958
1928
  $script:S.layoutKey = $layoutKey
1959
1929
  $script:S.dipW = $W
1960
- $script:S.dipH = $H
1961
1930
  $script:S.ringDip = $T
1962
1931
  $ph = $script:PH[$script:S.phase]
1963
1932
  if ($null -eq $ph) { $ph = $script:PH['acting'] }
@@ -2183,7 +2152,6 @@ function Fit-To-Monitor($m, [int]$maxPasses) {
2183
2152
  $r = Get-WindowRect
2184
2153
  if ($null -eq $r) { return }
2185
2154
  $script:S.fitPasses = $pass
2186
- $script:S.fitRect = $r
2187
2155
  $dw = [int]$target.w - [int]$r.w
2188
2156
  $dh = [int]$target.h - [int]$r.h
2189
2157
  $dx = [int]$target.x - [int]$r.x
@@ -2241,7 +2209,6 @@ function Hide-Overlay([string]$why) {
2241
2209
  }
2242
2210
  try { $script:S.win.Hide() } catch { Log ('hide threw: ' + $_.Exception.Message) }
2243
2211
  $script:S.visible = $false
2244
- $script:S.hideCount += 1
2245
2212
  $script:S.phase = 'hidden'
2246
2213
  Stop-RenderLoop
2247
2214
  Stop-HaloLoop
@@ -2249,10 +2216,9 @@ function Hide-Overlay([string]$why) {
2249
2216
  }
2250
2217
 
2251
2218
  # ---------------------------------------------------------------- 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.
2219
+ # Only ever called when DSH_INDICATOR_RENDER_HOOK=1: framesRendered counts pulse updates
2220
+ # actually pushed, from the timer or the render event, whichever is driving.
2254
2221
  function On-Frame {
2255
- $script:S.renderCallbacks += 1
2256
2222
  Pump-Inbox
2257
2223
  Tick-Pulse
2258
2224
  }
@@ -2272,17 +2238,13 @@ function Start-RenderLoop {
2272
2238
  # Subscribing to WPF's render event is only an OBSERVER, and an expensive one: measured on this
2273
2239
  # box it kept a 2560x1600 layered surface compositing at ~55 Hz even while only 4 updates a
2274
2240
  # second were pushed (14 pushes -> 189 callbacks in 3.4 s). Off by default, on for diagnostics.
2275
- $hooked = $false
2276
2241
  if ($script:renderLoaded -and [int]$CFG.renderHook -eq 1) {
2277
2242
  try {
2278
2243
  [IndWpf]::StartRendering([System.Action]{ On-Frame })
2279
- $hooked = [bool][IndWpf]::RenderingOn
2280
2244
  } catch {
2281
2245
  Log ('render subscription failed: ' + $_.Exception.Message)
2282
2246
  }
2283
2247
  }
2284
- $script:S.renderHookOn = $hooked
2285
- $script:S.renderDriver = if ($hooked) { 'dispatcher-timer+composition-render-event' } else { 'dispatcher-timer' }
2286
2248
  $script:S.renderOn = $true
2287
2249
  }
2288
2250
 
@@ -2290,13 +2252,12 @@ function Stop-RenderLoop {
2290
2252
  if ($script:renderLoaded) { try { [IndWpf]::StopRendering() } catch { } }
2291
2253
  if ($null -ne $script:pulseTimer) { try { $script:pulseTimer.Stop() } catch { } }
2292
2254
  $script:S.renderOn = $false
2293
- $script:S.renderHookOn = $false
2294
2255
  }
2295
2256
 
2296
2257
  $script:pulseTimer = $null
2297
2258
  $script:haloTimer = $null
2298
2259
 
2299
- # The halo is decoupled from the 100 ms pulse: a dedicated ~16 ms loop repositions it with
2260
+ # The halo is decoupled from the pulse tick: a dedicated ~16 ms loop repositions it with
2300
2261
  # GetCursorPos, so it tracks the pointer without the one-beat lag a shared pulse tick would cause.
2301
2262
  function Start-HaloLoop {
2302
2263
  if ($null -ne $script:haloTimer) { return }
@@ -2339,8 +2300,6 @@ function Update-Pulse([Int64]$now) {
2339
2300
  elseif ($alpha -lt $prev - $step) { $alpha = $prev - $step }
2340
2301
  }
2341
2302
  $script:S.appliedAlpha = $alpha
2342
- $script:S.pulseOffset = $frac
2343
- $script:S.pulseAlpha = [Math]::Round($alpha, 4)
2344
2303
  foreach ($b in $script:S.ring) { if ($null -ne $b) { $b.Opacity = $alpha } }
2345
2304
  $bloomAlpha = $alpha * 0.72
2346
2305
  foreach ($b in $script:S.bloom) { if ($null -ne $b) { $b.Opacity = $bloomAlpha } }
@@ -2351,7 +2310,7 @@ function Update-Pulse([Int64]$now) {
2351
2310
  }
2352
2311
 
2353
2312
  # 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.
2313
+ # was actually pushed; composition frames are not counted here.
2355
2314
  function Tick-Pulse {
2356
2315
  if ($script:S.closing -or -not $script:S.visible) { return }
2357
2316
  $now = [Diagnostics.Stopwatch]::GetTimestamp()
@@ -2360,7 +2319,7 @@ function Tick-Pulse {
2360
2319
  if ($sinceMs -lt [double]$CFG.renderMs) { return }
2361
2320
  $script:S.lastPulseStamp = $now
2362
2321
  $script:S.framesRendered += 1
2363
- if (Update-Pulse $now) { $script:S.visualUpdates += 1 }
2322
+ [void](Update-Pulse $now)
2364
2323
  Position-Halo
2365
2324
  }
2366
2325
 
@@ -2494,8 +2453,6 @@ function Cmd-Show($A) {
2494
2453
  if ($phase -eq 'hidden') { Hide-Overlay 'show asked for phase hidden' }
2495
2454
  Start-RenderLoop
2496
2455
  Sync-Hwnd | Out-Null
2497
- $script:S.showCount += 1
2498
- $script:S.straddle = [bool]$pick.straddle
2499
2456
  $fgAfter = (Get-Fg)
2500
2457
  return [ordered]@{
2501
2458
  visible = [bool]$script:S.visible
@@ -2861,7 +2818,7 @@ function Close-Server([string]$why) {
2861
2818
  $aliveAfter = (Test-HwndAlive)
2862
2819
  Log ('hwnd ' + [Int64]$script:S.hwnd + ' IsWindow before close = ' + $aliveBefore + ', after close = ' + $aliveAfter)
2863
2820
  }
2864
- try { $script:S.canvas = $null; $script:S.win = $null; $script:S.ring = @(); $script:S.bloom = @() } catch { }
2821
+ try { $script:S.canvas = $null; $script:S.win = $null; $script:S.ring = @(); $script:S.bloom = @(); $script:S.ringImg = $null } catch { }
2865
2822
  try { if ($null -ne $script:S.app) { $script:S.app.Shutdown() } } catch { }
2866
2823
  try { if ($null -ne $script:dispatcher) { $script:dispatcher.InvokeShutdown() } } catch { }
2867
2824
  # A stuck overlay is the worst failure mode on this list, so unwinding the dispatcher is not
@@ -2878,7 +2835,6 @@ function Close-Server([string]$why) {
2878
2835
 
2879
2836
  # ---------------------------------------------------------------- bootstrap
2880
2837
  $script:dispatcher = [System.Windows.Threading.Dispatcher]::CurrentDispatcher
2881
- $script:S.dispatcher = $script:dispatcher
2882
2838
  $script:pumpAction = [System.Action]{ Pump-Inbox; [IndWake]::Clear() }
2883
2839
  $app = New-Object System.Windows.Application
2884
2840
  $app.ShutdownMode = [System.Windows.ShutdownMode]::OnExplicitShutdown
@@ -2897,7 +2853,6 @@ New-ServerTimer 250 {
2897
2853
  if ($script:S.visible) {
2898
2854
  $idle = (SinceMs $script:S.lastCmdTick)
2899
2855
  if ([int]$script:S.idleHideMs -gt 0 -and $idle -gt [double]$script:S.idleHideMs) {
2900
- $script:S.autoHides += 1
2901
2856
  $script:S.stats.autoHides += 1
2902
2857
  Log ('idle ' + [Math]::Round($idle, 0) + ' ms > idleHideMs ' + $script:S.idleHideMs + ' -- auto-hiding')
2903
2858
  Hide-Overlay 'idle auto-hide'
@@ -2905,7 +2860,6 @@ New-ServerTimer 250 {
2905
2860
  if ($script:nativeLoaded -and [Int64]$script:S.hwnd -ne 0) {
2906
2861
  try {
2907
2862
  if ((Get-Fg) -eq [Int64]$script:S.hwnd) {
2908
- $script:S.fgThefts += 1
2909
2863
  Log 'tripwire: the overlay became GetForegroundWindow() despite NOACTIVATE'
2910
2864
  }
2911
2865
  } catch { }