dsh-native-uia 0.4.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.
@@ -179,6 +179,14 @@ gate('guard denies every category the user asked to block (MUST FIRE)', () => {
179
179
  { action: 'toggle', descriptor: { name: 'Delete all history', controlType: 'Button' } },
180
180
  { action: 'close_window', descriptor: { name: 'Settings', ownedByPlugin: false } },
181
181
  { action: 'launch', descriptor: {}, extra: 'shutdown.exe' },
182
+ // The interpreter family: refusing the six shutdown tools means nothing while `launch` will
183
+ // start a shell, because one typed line there runs anything the name table above refuses.
184
+ { action: 'launch', descriptor: {}, extra: 'cmd.exe' },
185
+ { action: 'launch', descriptor: {}, extra: 'C:\\Windows\\System32\\powershell.exe' },
186
+ { action: 'launch', descriptor: {}, extra: 'CMD.EXE' },
187
+ { action: 'launch', descriptor: {}, extra: 'wscript.exe' },
188
+ { action: 'launch', descriptor: {}, extra: 'mshta.exe' },
189
+ { action: 'launch', descriptor: {}, extra: 'taskmgr.exe' },
182
190
  // The window-close affordance: invoking it ends the application exactly like Alt+F4, and it
183
191
  // used to be allowed because the pattern only knew the words "退出程序"/"关闭程序".
184
192
  { action: 'invoke', descriptor: { name: '关闭', controlType: 'Button' } },
@@ -1050,9 +1058,9 @@ gate('the first delivery asks permission through the host question card, and ref
1050
1058
  // Fail-closed: only the literal allow option arms the session.
1051
1059
  assert(/armed = picked === '允许'/.test(index), 'the gate arms on something other than the explicit allow answer');
1052
1060
  assert(/store\.armed = picked === '允许'/.test(index), 'the decision never reaches the store');
1053
- const actSrc = readFileSync(join(ROOT, 'src', 'tools', 'defs', 'act.js'), 'utf8');
1054
- assert(/ensureArmed\(exec\?\.agent, exec\.signal\)/.test(actSrc), 'the delivery tools do not consult the gate with their exec.agent + exec.signal');
1055
- const pointerSrc = readFileSync(join(ROOT, 'src', 'tools', 'defs', 'pointer.js'), 'utf8');
1061
+ const actSrc = readFileSync(join(ROOT, 'src', 'tools', 'defs', 'act.js'), 'utf8');
1062
+ assert(/ensureArmed\(exec\?\.agent, exec\.signal\)/.test(actSrc), 'the delivery tools do not consult the gate with their exec.agent + exec.signal');
1063
+ const pointerSrc = readFileSync(join(ROOT, 'src', 'tools', 'defs', 'pointer.js'), 'utf8');
1056
1064
  assert(/ensureArmed\(exec\?\.agent, exec\?\.signal\)/.test(pointerSrc), 'the pointer domain gate drops the abort signal');
1057
1065
  // Un-armed refuses delivery at the choke point, before the spawn, without consuming the latch.
1058
1066
  assert(/disarmed/.test(client), 'the worker client has no activation gate');
@@ -1125,6 +1133,24 @@ gate('a repeated action does not rebuild the capsule, so the intro does not repl
1125
1133
  return 'repeated actions rebuild 0 times; a real look change rebuilds once; stopped recolours in place';
1126
1134
  });
1127
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
+
1128
1154
  gate('a phase change recolours in place instead of rebuilding the capsule', () => {
1129
1155
  // acting -> stopped used to clear the canvas and rebuild every visual, which replayed
1130
1156
  // Start-PillIntro's 340 ms scale-and-fade on the way out: the person saw the colour turn red AND
@@ -1141,10 +1167,11 @@ gate('a phase change recolours in place instead of rebuilding the capsule', () =
1141
1167
  'Set-PhaseInPlace no longer recolours in place');
1142
1168
  assert(!/if \(\$changed -and \$script:S\.built\) \{ Render-Layout/.test(server),
1143
1169
  'Set-PhaseInPlace rebuilds the tree again: the intro animation replays and stopped flashes twice');
1144
- // 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.
1145
1172
  const look = server.slice(server.indexOf('function Update-PhaseLook'), server.indexOf('function Render-Layout'));
1146
- assert(/New-GradH \$s\.g0 \$s\.g1/.test(look), 'the in-place recolour no longer repaints the ring');
1147
- 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');
1148
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');
1149
1176
  return 'phase changes recolour ring + mask + bloom in place; no rebuild, no replayed intro';
1150
1177
  });
@@ -1269,10 +1296,10 @@ gate('the overlay palette is a two-theme catalog, with brand black as the defaul
1269
1296
  // THE actual bug: the ring has to be painted from ringFrom/ringTo, not from the shell's border
1270
1297
  // colour (which both palettes share, so a switch could never change a pixel).
1271
1298
  const server = readFileSync(join(ROOT, 'worker', 'indicator-server.ps1'), 'utf8');
1272
- 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'));
1273
1300
  assert(/\$ph\.g0/.test(ringBody) && /\$ph\.g1/.test(ringBody), 'Build-Ring no longer paints with the palette ramp: the ambient cannot change');
1274
- assert(!/New-GradH \$ph\.base \$ph\.base/.test(ringBody), 'Build-Ring paints from pillBorder again: both palettes share it, so the switch is invisible');
1275
- // 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
1276
1303
  // the ambient cannot re-tint the capsule by accident.
1277
1304
  const shell = ['pillBg', 'pillBorder', 'pillText'];
1278
1305
  const drifted = shell.filter((k) => brand[k] !== graphite[k]);
@@ -1316,7 +1343,7 @@ gate('the ambient palette is switchable from the plugin page and survives restar
1316
1343
  assert(/id: 'orb'/.test(stylesBlock), 'the orb is no longer offered');
1317
1344
  // The worker rejects an unknown style, so the two sides can never drift silently.
1318
1345
  assert(/@\('orb','wave','mark','inverse'\) -notcontains \$st/.test(workerSrc), 'the worker stopped validating the style it is handed');
1319
- return '2 ambient palettes, one capsule shape, switched on the plugin page, applied live and persisted';
1346
+ return '2 ambient palettes, four capsule shapes, switched on the plugin page, applied live and persisted';
1320
1347
  });
1321
1348
 
1322
1349
  gate('the capsule is built like an island, not a badge', () => {
@@ -1513,6 +1540,107 @@ gate('computer_snapshot exposes depth and passes it through as maxDepth', () =>
1513
1540
  return 'depth parameter declared and forwarded as worker maxDepth';
1514
1541
  });
1515
1542
 
1543
+ gate('a snapshot node publishes its state, cached first with one budgeted live read', () => {
1544
+ // The tree used to answer "does this node support Toggle" and never "is it ON". A checked and an
1545
+ // unchecked checkbox rendered identically, a selected row looked like any other row, and the
1546
+ // model had to act blind or take a second observation after every click. State is now part of the
1547
+ // node, read from the cache the snapshot already materialised; providers that hand back an empty
1548
+ // cached struct (Explorer's shell items) get ONE live read, capped per snapshot.
1549
+ const tools = toolsSource();
1550
+ const ps = workerSource();
1551
+ const snap = tools.match(/name: 'computer_snapshot'([\s\S]*?)\n \}\)\)\);/)?.[1] ?? '';
1552
+ assert(snap !== '', 'computer_snapshot is missing');
1553
+ assert(/state \(toggle\/selected\/expanded\/range\/scroll\)/.test(snap), 'the snapshot description stopped promising node state');
1554
+ assert(/function State-Of\(/.test(ps), 'State-Of is gone: nodes cannot report toggle/selected/expanded/range/scroll');
1555
+ assert(/function State-Missing\(/.test(ps), 'State-Missing is gone: the live fallback can no longer tell a missing field from a missing state');
1556
+ assert(/GetCachedPattern/.test(ps) && /GetCurrentPattern/.test(ps), 'state reads no longer have both a cached and a live path');
1557
+ const cache = ps.match(/\$script:snapPatterns = @\(([\s\S]*?)\)/)?.[1] ?? '';
1558
+ assert(/SelectionItemPattern/.test(cache) && /ScrollPattern/.test(cache), 'the cache request no longer materialises SelectionItem/Scroll, so selected/scroll state silently disappears');
1559
+ assert(/State-Of \$el \$patterns \$true/.test(ps), 'Build-SnapshotNode no longer tries the cached state read');
1560
+ assert(/stateLiveBudget/.test(ps) && /State-Missing \$patterns \$st/.test(ps), 'the live state fallback lost its budget or its trigger');
1561
+ assert(/\$node\['state'\] = \$st/.test(ps), 'the node no longer carries the state it read');
1562
+ // The renderer must actually show it, or the worker pays for fields nobody reads.
1563
+ assert(/function stateText\(/.test(tools), 'the renderer lost stateText: state is collected and never printed');
1564
+ assert(/stateText\(n\.state\)/.test(tools), 'renderTree no longer prints node state');
1565
+ return 'toggle/selected/expanded/range/scroll on the node, cached first, live reads budgeted, rendered';
1566
+ });
1567
+
1568
+ gate('the tree can be walked in the raw/content views and drilled from a ref subtree', () => {
1569
+ // Coverage is a VIEW question, not a depth question: ControlView is the curated tree providers
1570
+ // publish, and "this Pane has nothing inside" is usually a ControlView answer. Raw exposes the
1571
+ // plumbing panes; a subtree root turns one located container into a cheap deep pass.
1572
+ const tools = toolsSource();
1573
+ const ps = workerSource();
1574
+ assert(/RawViewWalker/.test(ps) && /ContentViewWalker/.test(ps), 'the raw/content walkers are gone: only the curated tree is reachable');
1575
+ assert(/Get-SnapshotWalker \$view/.test(ps), 'Build-Snapshot walks a fixed view again');
1576
+ assert(/StrArg \$A 'view'/.test(ps), 'Build-Snapshot no longer reads the view argument');
1577
+ assert(/\$subReq = if \(\$view -eq 'control'\)/.test(ps), 'a non-control view can reach the one-shot cache path, which cannot honour it');
1578
+ assert(/StrArg \$A 'root'/.test(ps) && /Resolve-Ref \$rootRef/.test(ps), 'the subtree root argument is gone: digging into one container means re-snapshotting the window');
1579
+ assert(/if \(\$null -eq \$rootEl\) \{ \$entry\.revision \+= 1 \}/.test(ps), 'a subtree pass bumps the revision again, which invalidates the skeleton the caller just read');
1580
+ assert(/\$result\['subtree'\] = \$true/.test(ps), 'the reply no longer says it was a subtree pass');
1581
+ const snap = tools.match(/name: 'computer_snapshot'([\s\S]*?)\n \}\)\)\);/)?.[1] ?? '';
1582
+ assert(/enum: \['control', 'raw', 'content'\]/.test(snap), 'computer_snapshot has no view parameter');
1583
+ assert(/view: args\.view/.test(snap) && /root: args\.root/.test(snap), 'view/root are declared but not forwarded to the worker');
1584
+ assert(/\[cut\]/.test(tools), 'the per-node cut marker is gone: the reply stops saying where the walk stopped');
1585
+ return 'control/raw/content views, subtree root that keeps the revision, per-node cut markers';
1586
+ });
1587
+
1588
+ gate('find_text can be scoped to one container instead of scanning the window', () => {
1589
+ // The documented rhythm was "find_text into the container you located" with no way to name the
1590
+ // container, so every search paid the whole window (1-3 ms per element). within=<ref> makes the
1591
+ // promise real, and the reply says which scope produced the hits.
1592
+ const tools = toolsSource();
1593
+ const ps = workerSource();
1594
+ assert(/StrArg \$A 'within'/.test(ps) && /Resolve-Ref \$within/.test(ps), 'Cmd-FindText no longer scopes its scan by ref');
1595
+ assert(/\$r\['within'\] = \$within/.test(ps), 'the find_text reply no longer reports its within scope');
1596
+ const ft = tools.match(/name: 'computer_find_text'([\s\S]*?)\n \}\)\)\);/)?.[1] ?? '';
1597
+ assert(ft !== '', 'computer_find_text is missing');
1598
+ assert(/within: \{ \.\.\.STR/.test(ft), 'computer_find_text has no within parameter');
1599
+ assert(/within: args\.within/.test(ft), 'within is declared but not forwarded to the worker');
1600
+ assert(/scopeText/.test(ft), 'a scoped search no longer says it was scoped, so a zero-hit reply reads as "the text does not exist"');
1601
+ return 'within=<ref> reaches the worker and every reply names its scope';
1602
+ });
1603
+
1604
+ gate('the action surface covers range/selection/scroll-item, not only the original patterns', () => {
1605
+ // Four verbs that existed only as "you could drag it and hope": set_range (sliders/spinners),
1606
+ // scroll_to (bring one item into view via the provider), deselect / add_to_selection (multi-select
1607
+ // lists where `select` alone resets the selection).
1608
+ const tools = toolsSource();
1609
+ const ps = workerSource();
1610
+ for (const verb of ['deselect', 'add_to_selection', 'scroll_to', 'set_range']) {
1611
+ assert(new RegExp(`'${verb}' \\{`).test(ps), `the worker has no ${verb} branch`);
1612
+ }
1613
+ assert(/RemoveFromSelection\(\)/.test(ps) && /AddToSelection\(\)/.test(ps), 'deselect/add_to_selection lost their UIA calls');
1614
+ assert(/ScrollIntoView\(\)/.test(ps), 'scroll_to lost ScrollIntoView');
1615
+ assert(/SetValue\(\$num\)/.test(ps), 'set_range never calls RangeValue.SetValue');
1616
+ assert(/ScrollItem\s*=\s*\[System\.Windows\.Automation\.ScrollItemPattern\]/.test(ps), 'ScrollItem is not in the pattern table, so scroll_to can never obtain an object');
1617
+ const act = tools.match(/name: 'computer_act'([\s\S]*?)\n \}\)\)\);/)?.[1] ?? '';
1618
+ for (const verb of ["'deselect'", "'add_to_selection'", "'scroll_to'", "'set_range'"]) {
1619
+ assert(act.includes(verb), `computer_act does not declare ${verb}`);
1620
+ }
1621
+ assert(/ACT_VERBS = new Set\(\[[^\]]*'RangeValue'/.test(tools), 'RangeValue is not advertised as actionable even though set_range exists');
1622
+ assert(/ACT_VERBS = new Set\(\[[^\]]*'ScrollItem'/.test(tools), 'ScrollItem is not advertised, so scroll_to targets never look actionable');
1623
+ return 'deselect/add_to_selection/scroll_to/set_range wired end to end, ScrollItem obtainable';
1624
+ });
1625
+
1626
+ gate('pointer tools take a ref, and a mixed batch runs one step at a time', () => {
1627
+ // Physical actions were coordinate-only, so any model that had a ref still had to do rect
1628
+ // arithmetic (and could click where the element USED to be). And a batch could only carry UIA
1629
+ // verbs, so "click the field, type, press enter" was three calls with no shared stop rule.
1630
+ const tools = toolsSource();
1631
+ const block = (name) => tools.match(new RegExp(`name: '${name}'([\\s\\S]*?)\\n \\}\\)\\)\\);`))?.[1] ?? '';
1632
+ for (const tool of ['computer_click', 'computer_drag', 'computer_scroll', 'computer_mouse']) {
1633
+ const b = block(tool);
1634
+ assert(b !== '', `${tool} is missing`);
1635
+ assert(/ref: \{ \.\.\.STR/.test(b), `${tool} has no ref parameter`);
1636
+ }
1637
+ assert(/resolvePoint/.test(tools) && /worker\.call\('describe'/.test(tools), 'the pointer path no longer derives a centre from describe');
1638
+ assert(/POINTER_STEPS/.test(tools) && /runPointerStep/.test(tools), 'the lazy batch has no pointer step path');
1639
+ assert(/lazy: true/.test(tools), 'a mixed batch no longer tells the caller how to run it');
1640
+ assert(/含指针步骤的批次不存配方/.test(tools), 'mixed batches may still be saved as recipes (coordinates drift)');
1641
+ return 'ref targets on click/drag/scroll/mouse; click/type/key/scroll/drag/wait run inside a lazy batch';
1642
+ });
1643
+
1516
1644
  gate('find_text ranks actionable hits first and labels containers', () => {
1517
1645
  // Searching a window title ("插件") matches the window's own Pane and Document first — both huge,
1518
1646
  // both clickable only in the "focus the window" sense. A model reading top-down picks #1 and
@@ -2031,7 +2159,7 @@ gate('the confirm layer stays removed, and the policy has no interactive verdict
2031
2159
  assert(!/verdict: 'confirm'/.test(guard), 'classify() can return a confirm verdict again');
2032
2160
  assert(!/confirmable/.test(guard), 'POLICY grew a confirmable flag again');
2033
2161
  assert(!/ctrl\+alt\+y/.test(guard), 'the allow chord is back in the policy wording');
2034
- assert(/deniedCategories: \['shutdown', 'logoff', 'restart', 'exit', 'delete'\]/.test(guard), 'the hard-refuse list changed');
2162
+ assert(/deniedCategories: \['shutdown', 'exit', 'delete', 'loop', 'shell'\]/.test(guard), 'the hard-refuse list changed');
2035
2163
  assert(/approvable: false/.test(guard), 'POLICY made refusals approvable again');
2036
2164
  // No caller, no handler, no import of the deleted module.
2037
2165
  assert(!/askConfirm/.test(act), 'act.js asks the confirm gate again');
@@ -2067,8 +2195,8 @@ gate('notes persist across runs, and the clipboard read stays gated on the run o
2067
2195
  assert(!/Set-Clipboard -Value ''/.test(ps), "Set-Clipboard -Value '' throws on Windows PowerShell 5.1; use [string[]]@()");
2068
2196
  assert((ps.match(/\[string\[\]\]@\(\)/g) ?? []).length >= 2, 'clear and empty write no longer both use the empty-array form');
2069
2197
  const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
2070
- assert(pkg.version === '0.4.0', `package.json version is ${pkg.version}, not the 0.4.0 this work is released as`);
2071
- return 'notes capped/deduped/sanitised and read back by observations; clipboard read gated on ctrl+c; version 0.4.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';
2072
2200
  });
2073
2201
 
2074
2202
  gate('the worker body lives in lib, and the entry dot-sources the same list the gates read', () => {
@@ -2101,6 +2229,7 @@ gate('the split tool modules actually resolve and register as a graph', () => {
2101
2229
  assert(existsSync(join(ROOT, rel)), `${rel} is missing from the split`);
2102
2230
  }
2103
2231
  assert(!existsSync(join(ROOT, 'src', 'tools.js')), 'src/tools.js came back: one tool source or the other, not both');
2232
+ assert(!existsSync(join(ROOT, 'src', 'native-uia-remote.js')), 'native-uia-remote.js came back: the panel polls the loopback service, there is no host remote channel');
2104
2233
  assert(/TOOLS_FILES/.test(readFileSync(join(ROOT, 'scripts', 'lib', 'sources.mjs'), 'utf8')), 'sources.mjs no longer declares the concatenation order');
2105
2234
  return `graph loads: ${out.trim().split('\n').pop()}`;
2106
2235
  });
package/src/guard.js CHANGED
@@ -4,7 +4,7 @@
4
4
  * `commit_batch`, so one guard covers interactive calls and replayed recipes.
5
5
  */
6
6
 
7
- const RISKY_ACTIONS = new Set(['invoke', 'toggle', 'select', 'close_window']);
7
+ const RISKY_ACTIONS = new Set(['invoke', 'toggle', 'select']);
8
8
 
9
9
  const SHUTDOWN = /(?:\b(?:shut\s*down|shutdown|power\s*off|restart|reboot|sign\s*out|log\s*off|logoff|log\s*out|hibernate)\b|关机|注销|重启|休眠|退出登录)/i;
10
10
  // A window's close affordance is called 关闭 / Close / ✕ in real UIA trees, not "关闭程序". Without
@@ -15,7 +15,16 @@ const SHUTDOWN = /(?:\b(?:shut\s*down|shutdown|power\s*off|restart|reboot|sign\s
15
15
  const EXIT = /(?:^(?:exit|quit|close\s*(?:app|application|program))\b|^(?:close|关闭|✕|✖|×)$|退出(?:程序|应用)|关闭(?:程序|应用|窗口))/i;
16
16
  const DELETE = /(?:\b(?:delete|remove|discard|erase|empty\s+recycle\s+bin|shred)\b|删除|彻底删除|清空回收站|丢弃)/i;
17
17
 
18
+ // The interpreter family. Refusing the six shutdown tools by name is worth nothing if `launch` will
19
+ // happily start cmd.exe, because one typed line there runs anything the name table below refuses —
20
+ // including the shutdown the person just denied. These are the shells and script hosts Windows
21
+ // ships, plus the process/task managers that can end an application without going through EXIT.
18
22
  const DENY_EXECUTABLES = /^(?:shutdown|logoff|taskkill|psshutdown|restart|poweroff)\.exe$/i;
23
+ const DENY_SHELLS = new Set([
24
+ 'cmd.exe', 'powershell.exe', 'pwsh.exe', 'wscript.exe', 'cscript.exe', 'mshta.exe',
25
+ 'rundll32.exe', 'regsvr32.exe', 'reg.exe', 'wsl.exe', 'bash.exe', 'wt.exe', 'conhost.exe',
26
+ 'taskmgr.exe', 'msconfig.exe', 'mmc.exe',
27
+ ]);
19
28
 
20
29
  const CATEGORIES = {
21
30
  shutdown: {
@@ -34,6 +43,10 @@ const CATEGORIES = {
34
43
  refusal: '同批内连续重复同一滚动动作且没有任何结果校验(疑似无效滚动循环)',
35
44
  advice: '先重新 snapshot/find_text 观察列表是否真的滚动了;或给滚动步加 verify:{type:"scroll_percent_changed"},滚动无效果时批次会停下来。',
36
45
  },
46
+ shell: {
47
+ refusal: '启动命令行或脚本宿主',
48
+ advice: '这类程序能把上面每一条拒收改写成一行命令,所以整族不开放;需要命令行的步骤请让用户自己开终端执行,应用请用它的正常入口启动。',
49
+ },
37
50
  };
38
51
 
39
52
  function text(descriptor) {
@@ -42,11 +55,10 @@ function text(descriptor) {
42
55
  .join(' ');
43
56
  }
44
57
 
45
- function categoryOf(descriptor, action) {
58
+ function categoryOf(descriptor) {
46
59
  const hay = `${text(descriptor)} ${descriptor?.command ?? ''}`.trim();
47
60
  if (hay === '') return null;
48
61
  if (SHUTDOWN.test(hay)) return 'shutdown';
49
- if (action === 'close_window') return null;
50
62
  if (EXIT.test(hay)) return 'exit';
51
63
  if (DELETE.test(hay)) return 'delete';
52
64
  return null;
@@ -81,7 +93,7 @@ export function classifyKeys(combo) {
81
93
  if (hay === '') return { verdict: 'allow' };
82
94
  if (KEY_LOCK.test(hay)) return denied('shutdown'); // win+l locks the session
83
95
  if (KEY_EXIT.test(hay)) return denied('exit'); // alt+f4 closes the focused app
84
- const category = categoryOf({ name: hay, command: hay }, 'invoke');
96
+ const category = categoryOf({ name: hay, command: hay });
85
97
  if (category === null) return { verdict: 'allow' };
86
98
  return denied(category);
87
99
  }
@@ -96,7 +108,7 @@ export function classify(request) {
96
108
  // one policy gate must normalise before matching or a case variant sails past the text refusal.
97
109
  const action = String(request.action ?? '').toLowerCase();
98
110
  if (!RISKY_ACTIONS.has(action)) return { verdict: 'allow' };
99
- const category = categoryOf(request.descriptor, action);
111
+ const category = categoryOf(request.descriptor);
100
112
  if (category === null) return { verdict: 'allow' };
101
113
  return verdictFor(category);
102
114
  }
@@ -177,14 +189,21 @@ export function classifyClose(descriptor) {
177
189
  export function classifyLaunch(app) {
178
190
  const leaf = String(app ?? '').trim().split(/[\\/]/).pop() ?? '';
179
191
  if (DENY_EXECUTABLES.test(leaf)) {
180
- return { verdict: 'deny', category: 'shutdown', refusal: CATEGORIES.shutdown.refusal, advice: CATEGORIES.shutdown.advice };
192
+ return denied('shutdown');
193
+ }
194
+ // Case-insensitive because Windows is: `CMD.EXE` is the same program.
195
+ if (DENY_SHELLS.has(leaf.toLowerCase())) {
196
+ return denied('shell');
181
197
  }
182
198
  return { verdict: 'allow' };
183
199
  }
184
200
 
185
201
  export const POLICY = {
186
202
  mode: 'dev',
187
- deniedCategories: ['shutdown', 'logoff', 'restart', 'exit', 'delete'],
203
+ // Every key that can appear in a verdict, and nothing else: this list is read by the panel and by
204
+ // the model-facing note, so a name here that no CATEGORIES entry defines is a claim about a rule
205
+ // that does not exist.
206
+ deniedCategories: ['shutdown', 'exit', 'delete', 'loop', 'shell'],
188
207
  // Every refusal is final: nothing here can be turned into a button, and there is no interactive
189
208
  // verdict at all. The former "hold for a person at the keyboard" family is gone -- it drew a
190
209
  // permission prompt on the capsule, which is not a channel this plugin owns.
package/src/index.js CHANGED
@@ -19,7 +19,7 @@ export const inject = ['tools', 'systemPrompt'];
19
19
  const INDICATOR_SCRIPT = fileURLToPath(new URL('../worker/indicator-server.ps1', import.meta.url));
20
20
 
21
21
  /**
22
- * How long a kill (Esc / control page) keeps refusing input.
22
+ * How long a stop (Esc / the panel's stop) keeps refusing input.
23
23
  *
24
24
  * The latch exists to stop the command that was ALREADY in flight when the person hit stop —
25
25
  * killing the worker is what surfaces that pending commit as WorkerDeadError. It must not
@@ -57,7 +57,7 @@ export function apply(ctx, config = {}) {
57
57
  // plugin page all have to report the same number that is actually in force.
58
58
  const leaseMs = Number(config.leaseMs ?? process.env.DSH_NATIVE_UIA_LEASE_MS ?? 300000) || 300000;
59
59
  // The chosen action-delivery mode must survive an app restart; without this the store resets to
60
- // its hardcoded default ('background') every launch, so the control-page toggle looked like it
60
+ // its hardcoded default ('background') every launch, so the panel's toggle looked like it
61
61
  // forgot the user's pick.
62
62
  const settingsPath = join(dataDir, 'settings.json');
63
63
  const saveSettings = () => {
@@ -101,7 +101,7 @@ export function apply(ctx, config = {}) {
101
101
  // The overlay process dying used to be nearly silent (a WPF composition-thread COM crash was
102
102
  // observed in the wild: WER event 1001, DUCE.Channel.SyncFlush, Node only saw "exit 2"). The
103
103
  // exit handler logs one info line; this warn-level event makes the crash readable from the
104
- // control page. Recovery needs no new code: the lazy start in CuaWorker.call respawns the
104
+ // panel log. Recovery needs no new code: the lazy start in CuaWorker.call respawns the
105
105
  // process on the next indicator command, and Cmd-Beat/Cmd-Show re-light an invisible window.
106
106
  onEvent: (kind, payload) => {
107
107
  if (kind === 'worker' && payload?.started === false) {
@@ -244,7 +244,7 @@ export function apply(ctx, config = {}) {
244
244
  logger('已从插件面板终止:worker 停止,在飞动作中断', 'error');
245
245
  return { ok: true };
246
246
  }
247
- return { ok: false, error: `未知操作 "${kind}"(mode|kill)` };
247
+ return { ok: false, error: `未知操作 "${kind}"(mode|theme|style|mist|kill)` };
248
248
  },
249
249
  };
250
250
 
@@ -255,8 +255,8 @@ export function apply(ctx, config = {}) {
255
255
  policy: POLICY,
256
256
  commands,
257
257
  // What the plugin page reports but cannot change from there: the bind address, the read-only
258
- // switch (activation env), and the two timeouts. The only writable setting is pointerMode, and
259
- // it goes through the same action the detail panel uses.
258
+ // switch (activation env), and the two timeouts. pointerMode/theme/style/mist are the four
259
+ // writable settings, and they go through the same action the panel uses.
260
260
  config: () => ({
261
261
  host, port, readOnly: store.readOnly === true, leaseMs, idleMs: idleTimeoutMs(),
262
262
  // Catalogs, not free text: the panel renders exactly what the worker can build, and a name
@@ -264,40 +264,6 @@ export function apply(ctx, config = {}) {
264
264
  themes: THEMES, styles: STYLES, defaultTheme: DEFAULT_THEME, defaultStyle: DEFAULT_STYLE,
265
265
  }),
266
266
  });
267
- // The native client channel: the panel component calls ctx.remote.nativeUia.*
268
- // instead of fetching a loopback port, so it inherits host theme tokens and locale.
269
- // Imported lazily and guarded: a resolution or decorator failure must not take
270
- // the plugin down, and the reason has to be readable from the panel's own log.
271
- store.remoteChannel = 'pending';
272
- const mountRemoteChannel = async () => {
273
- try {
274
- const { NativeUiaRemote } = await import('./native-uia-remote.js');
275
- // The instance self-registers inside the base constructor (TypertRemoteService mounts it on
276
- // ctx.remote); nothing reads the handle afterwards — the mount-state carrier is
277
- // store.remoteChannel, so a bare `new` keeps the guard shape without a dead variable.
278
- new NativeUiaRemote(ctx, { store, commands, policy: POLICY });
279
- store.remoteChannel = 'mounted';
280
- logger('宿主通道已挂载:ctx.remote.nativeUia');
281
- } catch (error) {
282
- store.remoteChannel = { failed: true, reason: String(error?.message ?? error) };
283
- logger(`宿主通道挂载失败,面板回退回环接口:${store.remoteChannel.reason}`, 'error');
284
- // Control experiment: both specifiers sit at the same level of the app's own
285
- // node_modules. If one resolves and the other does not, the host resolver is
286
- // composition-scoped, not Node-scoped, and a plugin cannot import a library
287
- // that no bundle depends on.
288
- const probed = [];
289
- for (const spec of ['@deepseek-ai/dsh-tools', '@deepseek-ai/dsh-typert-protocol', '@deepseek-ai/cordis']) {
290
- try {
291
- await import(spec);
292
- probed.push(`${spec}=ok`);
293
- } catch (probeError) {
294
- probed.push(`${spec}=${String(probeError?.code ?? probeError?.message ?? 'fail')}`);
295
- }
296
- }
297
- logger(`解析对照:${probed.join(' ')}`, 'warn');
298
- }
299
- store.emit('state', { reason: 'remote' });
300
- };
301
267
  // ---- the permission question: asked at FIRST DELIVERY, not at activation ----
302
268
  // Measured: asking at activation always fails with NO_PROVIDER — the answerer for
303
269
  // user-questions/request is the session UI, and at activation there is no live agent/session to
@@ -412,9 +378,6 @@ export function apply(ctx, config = {}) {
412
378
  logger('契约:心跳只喂渲染不续租,静默 run 在租约内自动收尾;Esc 主通道=指示层进程;find_text 已暴露为工具');
413
379
 
414
380
  // ---- permission question: asked at FIRST DELIVERY (see ensureArmed above) ----
415
- // The service is resolved here; the ask itself lives in ensureArmed, which the delivery tools
416
- // call with the exec.agent of their first mutating command.
417
- void mountRemoteChannel();
418
381
  const reservation = optional('computerUse');
419
382
  if (reservation !== undefined && reservation !== null) {
420
383
  try {
@@ -424,8 +387,6 @@ export function apply(ctx, config = {}) {
424
387
  logger(`computer-use 槽位已被其它 provider 占用:${error?.message ?? error}`, 'error');
425
388
  }
426
389
  }
427
- store.visionRoute = optional('attachments') !== undefined;
428
-
429
390
  const unregisterPrompt = ctx.systemPrompt.section({
430
391
  name: 'computer-use:native-uia',
431
392
  order: 3000,
@@ -449,8 +410,9 @@ export function apply(ctx, config = {}) {
449
410
  logger(`屏幕指示层不可用,桌面动作照常执行:${error?.message ?? error}`, 'warn');
450
411
  }
451
412
 
452
- // Global Esc-to-stop: the control-page keydown only fires when the browser has focus, so while
453
- // the overlay is up the host also polls for a physically-held VK_ESCAPE and ends the run.
413
+ // Global Esc-to-stop: the indicator overlay cannot take keyboard focus (it is a click-through
414
+ // window), so while the overlay is up the host polls for a physically-held VK_ESCAPE and ends
415
+ // the run.
454
416
  // The INDICATOR process is the primary channel: it is idle by design and answers in ms, while
455
417
  // the worker may sit inside a 40 s OCR or a long batch, where a queued probe cannot even run —
456
418
  // a tapped Esc is released long before that queue drains. The worker stays as fallback for
@@ -458,7 +420,7 @@ export function apply(ctx, config = {}) {
458
420
  // own per-step Esc check: that one reads "held right now" only at step boundaries, so a tap
459
421
  // released mid-step is invisible to it and the batch would run to completion, come back
460
422
  // "all passed" and save a recipe for a run the user just stopped. That is why the handler
461
- // below shuts the worker down exactly like the control-page kill — the pending commit comes
423
+ // below shuts the worker down exactly like the panel's stop — the pending commit comes
462
424
  // back as WorkerDeadError, which computer_run reports as "user stopped, nothing rolled back".
463
425
  let escBusy = false;
464
426
  const escTimer = setInterval(() => {
@@ -489,7 +451,7 @@ export function apply(ctx, config = {}) {
489
451
  if (r && r.pressed === true) {
490
452
  store.setKilled(true);
491
453
  void activity.end({ reason: '用户按下 Esc' });
492
- // Same closing sequence as the control-page kill above: a batch already mid-flight
454
+ // Same closing sequence as the panel's stop above: a batch already mid-flight
493
455
  // cannot see a tap (its per-step check needs the key held across a boundary), so
494
456
  // without the shutdown it runs to completion and saves a recipe. Killing the worker
495
457
  // surfaces the pending commit as WorkerDeadError. The latch is armed WITH a timestamp
package/src/state.js CHANGED
@@ -38,7 +38,6 @@ export class Store extends EventEmitter {
38
38
  // cached in the client, so a future re-ask (panel button) applies to the next call immediately.
39
39
  armed = false;
40
40
  running = false;
41
- visionRoute = false;
42
41
  counters = { stepsRun: 0, actions: 0, blocked: 0, refused: 0, stepMsTotal: 0, stepSamples: 0 };
43
42
  // Mouse buttons currently held down by computer_mouse action:"down". A dangling press is a stuck
44
43
  // desktop (every later click becomes a drag), so it is tracked here and released on run end.
@@ -210,14 +209,12 @@ export class Store extends EventEmitter {
210
209
  armed: this.armed === true,
211
210
  target: this.#targetView(),
212
211
  policy,
213
- remoteChannel: this.remoteChannel ?? 'pending',
214
212
  stats: {
215
213
  stepsRun: c.stepsRun,
216
214
  actions: c.actions,
217
215
  blocked: c.blocked,
218
216
  refused: c.refused,
219
217
  avgStepMs: c.stepSamples > 0 ? Math.round(c.stepMsTotal / c.stepSamples) : 0,
220
- visionRoute: this.visionRoute,
221
218
  },
222
219
  },
223
220
  windows: this.#windowsView(),
package/src/themes.js CHANGED
@@ -11,16 +11,13 @@
11
11
  */
12
12
 
13
13
  /**
14
- * Two palettes. `ring*` paints the screen-edge glow; `pill*` stays identical in both.
14
+ * Two palettes. `ring*` paints the screen-edge glow; `pill*` is identical in both, because the
15
+ * capsule shell colour is not part of what a theme changes.
15
16
  *
16
- * `brand` is the brand black: a near-black ramp, which is what the name means and what the shell
17
- * already is. It is deliberately dark -- the ambient is a dark rim that reads as a vignette on a
18
- * light wallpaper, not as a bright line. `graphite` is the silver one, and the two are chosen for
19
- * different walls.
20
- *
21
- * The bug that made "switching does nothing" was NOT these numbers: the renderer built its ring
22
- * from `pillBorder` (identical in both palettes) instead of from `ringFrom`/`ringTo`, so no value
23
- * here could ever reach the screen. That is fixed in Build-Ring; these are the values it now uses.
17
+ * `brand` is the brand black: a near-black ramp that reads as a vignette on a light wallpaper, not
18
+ * as a bright line. `graphite` is the cool blue-silver one, for a dark desktop where a dark rim
19
+ * would vanish. The renderer must paint the ring from `ringFrom`/`ringTo` only — `pillBorder` is
20
+ * identical in both palettes, so a ring built from it makes the switch look dead.
24
21
  */
25
22
  export const THEMES = Object.freeze([
26
23
  Object.freeze({ id: 'brand', name: '品牌黑', ringFrom: '#2A2E34', ringTo: '#000000', pillBg: '#0B0D10', pillBorder: '#A9B4C4', pillText: '#F2F5FA' }),
@@ -31,23 +28,18 @@ export const THEMES = Object.freeze([
31
28
  /**
32
29
  * The capsule shapes the worker can actually build.
33
30
  *
34
- * This list is the panel's catalog, so it has to match `Build-Pill` in the worker exactly: an id
35
- * the worker cannot build is a switch that silently does nothing, and an id missing here is a shape
36
- * the person cannot reach at all -- which is what happened when only `orb` was listed while the
37
- * renderer already had four.
38
- *
39
- * `compact` says which heights the worker gives it (44 DIP single line, 56 DIP with the second
40
- * line), so the panel does not have to describe sizes in prose.
31
+ * This list is the panel's catalog, so it has to match the worker's style switch exactly: an id the
32
+ * worker cannot build is a switch that silently does nothing, and an id missing here is a shape the
33
+ * person cannot reach. All four are the same size (172×44 DIP) — a shape changes the shell's look,
34
+ * never the silhouette.
41
35
  */
42
36
  export const STYLES = Object.freeze([
43
- // `orb` is the historical id; the mark has been the DSH whale for a long time, and "光球" (the
44
- // glass bead it started as) described something that is no longer drawn. The name the person
45
- // reads is the whale, so the label says so. The id stays: it is persisted in settings.json and
46
- // pinned by the gates.
47
- Object.freeze({ id: 'orb', name: '深黑', compact: true, hint: '深黑壳,白鲸直接画在壳上' }),
48
- Object.freeze({ id: 'wave', name: '声波', compact: true, hint: '三根声波条' }),
49
- Object.freeze({ id: 'mark', name: '标块', compact: true, hint: '浅色圆角块 + 深鲸' }),
50
- Object.freeze({ id: 'inverse', name: '反白', compact: true, hint: '白壳黑字,浅色壁纸' }),
37
+ // `orb` keeps its historical id because settings.json persists it and the gates pin it; the label
38
+ // says what is actually drawn (the DSH whale cut out of a near-black shell).
39
+ Object.freeze({ id: 'orb', name: '深黑', hint: '深黑壳,白鲸直接画在壳上' }),
40
+ Object.freeze({ id: 'wave', name: '声波', hint: '三根声波条' }),
41
+ Object.freeze({ id: 'mark', name: '标块', hint: '浅色圆角块 + 深鲸' }),
42
+ Object.freeze({ id: 'inverse', name: '反白', hint: '白壳黑字,浅色壁纸' }),
51
43
  ]);
52
44
 
53
45
  export const DEFAULT_THEME = 'brand';