@namzu/computer-use 3.1.0 → 4.0.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +64 -1
  2. package/README.md +3 -3
  3. package/dist/SubprocessComputerUseHost.d.ts +58 -10
  4. package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
  5. package/dist/SubprocessComputerUseHost.js +214 -47
  6. package/dist/SubprocessComputerUseHost.js.map +1 -1
  7. package/dist/adapters/cua-driver/adapter.d.ts +171 -10
  8. package/dist/adapters/cua-driver/adapter.d.ts.map +1 -1
  9. package/dist/adapters/cua-driver/adapter.js +1479 -161
  10. package/dist/adapters/cua-driver/adapter.js.map +1 -1
  11. package/dist/adapters/cua-driver/client.d.ts +16 -0
  12. package/dist/adapters/cua-driver/client.d.ts.map +1 -1
  13. package/dist/adapters/cua-driver/client.js +54 -5
  14. package/dist/adapters/cua-driver/client.js.map +1 -1
  15. package/dist/adapters/cua-driver/escalation.d.ts +67 -0
  16. package/dist/adapters/cua-driver/escalation.d.ts.map +1 -0
  17. package/dist/adapters/cua-driver/escalation.js +82 -0
  18. package/dist/adapters/cua-driver/escalation.js.map +1 -0
  19. package/dist/adapters/cua-driver/keys.d.ts +5 -0
  20. package/dist/adapters/cua-driver/keys.d.ts.map +1 -1
  21. package/dist/adapters/cua-driver/keys.js +23 -0
  22. package/dist/adapters/cua-driver/keys.js.map +1 -1
  23. package/dist/adapters/cua-driver/observe.d.ts +99 -0
  24. package/dist/adapters/cua-driver/observe.d.ts.map +1 -0
  25. package/dist/adapters/cua-driver/observe.js +227 -0
  26. package/dist/adapters/cua-driver/observe.js.map +1 -0
  27. package/dist/adapters/cua-driver/provision.d.ts +13 -13
  28. package/dist/adapters/cua-driver/provision.js +13 -13
  29. package/dist/adapters/cua-driver/ui-tree.d.ts +75 -2
  30. package/dist/adapters/cua-driver/ui-tree.d.ts.map +1 -1
  31. package/dist/adapters/cua-driver/ui-tree.js +142 -14
  32. package/dist/adapters/cua-driver/ui-tree.js.map +1 -1
  33. package/dist/adapters/types.d.ts +4 -4
  34. package/dist/adapters/types.d.ts.map +1 -1
  35. package/dist/adapters/types.js.map +1 -1
  36. package/dist/adapters/win32.d.ts +10 -0
  37. package/dist/adapters/win32.d.ts.map +1 -1
  38. package/dist/adapters/win32.js +12 -2
  39. package/dist/adapters/win32.js.map +1 -1
  40. package/dist/errors.d.ts +19 -0
  41. package/dist/errors.d.ts.map +1 -1
  42. package/dist/errors.js +26 -0
  43. package/dist/errors.js.map +1 -1
  44. package/dist/foreground/guard.d.ts +31 -0
  45. package/dist/foreground/guard.d.ts.map +1 -0
  46. package/dist/foreground/guard.js +156 -0
  47. package/dist/foreground/guard.js.map +1 -0
  48. package/dist/foreground/index.d.ts +11 -0
  49. package/dist/foreground/index.d.ts.map +1 -0
  50. package/dist/foreground/index.js +7 -0
  51. package/dist/foreground/index.js.map +1 -0
  52. package/dist/foreground/ladder.d.ts +143 -0
  53. package/dist/foreground/ladder.d.ts.map +1 -0
  54. package/dist/foreground/ladder.js +505 -0
  55. package/dist/foreground/ladder.js.map +1 -0
  56. package/dist/foreground/lease.d.ts +69 -0
  57. package/dist/foreground/lease.d.ts.map +1 -0
  58. package/dist/foreground/lease.js +182 -0
  59. package/dist/foreground/lease.js.map +1 -0
  60. package/dist/foreground/types.d.ts +287 -0
  61. package/dist/foreground/types.d.ts.map +1 -0
  62. package/dist/foreground/types.js +32 -0
  63. package/dist/foreground/types.js.map +1 -0
  64. package/dist/foreground/windows-helper-script.d.ts +19 -0
  65. package/dist/foreground/windows-helper-script.d.ts.map +1 -0
  66. package/dist/foreground/windows-helper-script.js +472 -0
  67. package/dist/foreground/windows-helper-script.js.map +1 -0
  68. package/dist/foreground/windows-monitor.d.ts +75 -0
  69. package/dist/foreground/windows-monitor.d.ts.map +1 -0
  70. package/dist/foreground/windows-monitor.js +216 -0
  71. package/dist/foreground/windows-monitor.js.map +1 -0
  72. package/dist/foreground/windows.d.ts +21 -0
  73. package/dist/foreground/windows.d.ts.map +1 -0
  74. package/dist/foreground/windows.js +54 -0
  75. package/dist/foreground/windows.js.map +1 -0
  76. package/dist/index.d.ts +6 -1
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +3 -1
  79. package/dist/index.js.map +1 -1
  80. package/dist/presence/helper-script.d.ts +39 -0
  81. package/dist/presence/helper-script.d.ts.map +1 -0
  82. package/dist/presence/helper-script.js +320 -0
  83. package/dist/presence/helper-script.js.map +1 -0
  84. package/dist/presence/index.d.ts +6 -0
  85. package/dist/presence/index.d.ts.map +1 -0
  86. package/dist/presence/index.js +4 -0
  87. package/dist/presence/index.js.map +1 -0
  88. package/dist/presence/presence.d.ts +70 -0
  89. package/dist/presence/presence.d.ts.map +1 -0
  90. package/dist/presence/presence.js +147 -0
  91. package/dist/presence/presence.js.map +1 -0
  92. package/dist/presence/windows.d.ts +19 -0
  93. package/dist/presence/windows.d.ts.map +1 -0
  94. package/dist/presence/windows.js +39 -0
  95. package/dist/presence/windows.js.map +1 -0
  96. package/dist/util/call-scope.d.ts +34 -0
  97. package/dist/util/call-scope.d.ts.map +1 -0
  98. package/dist/util/call-scope.js +58 -0
  99. package/dist/util/call-scope.js.map +1 -0
  100. package/package.json +2 -2
  101. package/src/SubprocessComputerUseHost.ts +288 -46
  102. package/src/adapters/cua-driver/adapter.ts +1754 -175
  103. package/src/adapters/cua-driver/client.ts +59 -2
  104. package/src/adapters/cua-driver/escalation.ts +137 -0
  105. package/src/adapters/cua-driver/keys.ts +20 -0
  106. package/src/adapters/cua-driver/observe.ts +310 -0
  107. package/src/adapters/cua-driver/provision.ts +13 -13
  108. package/src/adapters/cua-driver/ui-tree.ts +219 -15
  109. package/src/adapters/types.ts +8 -3
  110. package/src/adapters/win32.ts +26 -3
  111. package/src/errors.ts +32 -0
  112. package/src/foreground/guard.ts +182 -0
  113. package/src/foreground/index.ts +45 -0
  114. package/src/foreground/ladder.ts +616 -0
  115. package/src/foreground/lease.ts +232 -0
  116. package/src/foreground/types.ts +318 -0
  117. package/src/foreground/windows-helper-script.ts +471 -0
  118. package/src/foreground/windows-monitor.ts +288 -0
  119. package/src/foreground/windows.ts +73 -0
  120. package/src/index.ts +15 -1
  121. package/src/presence/helper-script.ts +323 -0
  122. package/src/presence/index.ts +17 -0
  123. package/src/presence/presence.ts +195 -0
  124. package/src/presence/windows.ts +54 -0
  125. package/src/util/call-scope.ts +73 -0
@@ -0,0 +1,472 @@
1
+ /**
2
+ * The Windows side of the foreground ladder: one long-lived PowerShell
3
+ * process that watches real keyboard and mouse input through low-level hooks
4
+ * (events the machine injected carry a flag and are not counted), reads the
5
+ * window in front, the cursor and the input desktop, and puts the window and
6
+ * cursor back after a burst.
7
+ *
8
+ * It is handed to PowerShell as an encoded command, never as a file: a file
9
+ * on the Linux side is reached through a network path on WSL, and compiling
10
+ * from there took 80 s the first time. The line protocol is one JSON object
11
+ * per line in each direction.
12
+ *
13
+ * Should the program that started it die, its input closes; the helper then
14
+ * puts back what a burst in progress had moved and deletes the lease file, so
15
+ * a crash cannot leave the user's window or cursor displaced or the screen
16
+ * leased.
17
+ */
18
+ export const WINDOWS_HELPER_SCRIPT = String.raw `
19
+ $ErrorActionPreference = 'Stop'
20
+ [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false)
21
+ [Console]::InputEncoding = New-Object System.Text.UTF8Encoding($false)
22
+ Add-Type -TypeDefinition @"
23
+ using System; using System.Text; using System.Threading; using System.Runtime.InteropServices;
24
+ public static class NzG {
25
+ [StructLayout(LayoutKind.Sequential)] public struct LII { public uint cb; public uint t; }
26
+ [StructLayout(LayoutKind.Sequential)] public struct PT { public int x; public int y; }
27
+ [StructLayout(LayoutKind.Sequential)] public struct MSG { public IntPtr h; public uint m; public IntPtr w; public IntPtr l; public uint t; public PT p; }
28
+ delegate IntPtr LL(int c, IntPtr w, IntPtr l);
29
+ [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LII p);
30
+ [DllImport("user32.dll")] static extern bool GetCursorPos(out PT p);
31
+ [DllImport("user32.dll")] static extern bool SetCursorPos(int x, int y);
32
+ [DllImport("user32.dll")] static extern IntPtr GetForegroundWindow();
33
+ [DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
34
+ [DllImport("user32.dll")] static extern bool SetForegroundWindow(IntPtr h);
35
+ [DllImport("user32.dll")] static extern bool AttachThreadInput(uint a, uint b, bool f);
36
+ [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr h, int c);
37
+ [DllImport("user32.dll")] static extern bool IsIconic(IntPtr h);
38
+ [DllImport("user32.dll")] static extern bool IsWindow(IntPtr h);
39
+ [DllImport("user32.dll")] static extern void SwitchToThisWindow(IntPtr h, bool alt);
40
+ [DllImport("user32.dll")] static extern void keybd_event(byte vk, byte scan, uint flags, UIntPtr extra);
41
+ [StructLayout(LayoutKind.Sequential)] public struct RC { public int l; public int t; public int r; public int b; }
42
+ [StructLayout(LayoutKind.Sequential)] public struct GTI { public int cb; public int fl; public IntPtr act; public IntPtr foc; public IntPtr cap; public IntPtr mo; public IntPtr ms; public IntPtr car; public RC rc; }
43
+ delegate bool EP(IntPtr h, IntPtr l);
44
+ [DllImport("user32.dll")] static extern bool EnumChildWindows(IntPtr p, EP f, IntPtr l);
45
+ [DllImport("user32.dll", CharSet=CharSet.Unicode)] static extern int GetClassName(IntPtr h, StringBuilder s, int n);
46
+ [DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
47
+ [DllImport("user32.dll")] static extern bool IsChild(IntPtr p, IntPtr c);
48
+ [DllImport("user32.dll")] static extern bool GetWindowRect(IntPtr h, out RC r);
49
+ [DllImport("user32.dll")] static extern bool GetClientRect(IntPtr h, out RC r);
50
+ [DllImport("user32.dll")] static extern IntPtr GetParent(IntPtr h);
51
+ [DllImport("user32.dll")] static extern int GetWindowLong(IntPtr h, int i);
52
+ [DllImport("user32.dll")] static extern bool GetGUIThreadInfo(uint t, ref GTI i);
53
+ [DllImport("user32.dll")] static extern bool SetProcessDPIAware();
54
+ [DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Unicode)] static extern IntPtr SendMessageTimeout(IntPtr h, uint m, IntPtr w, string l, uint f, uint t, out IntPtr r);
55
+ [DllImport("user32.dll", SetLastError=true, CharSet=CharSet.Unicode)] static extern IntPtr SendMessageTimeout(IntPtr h, uint m, IntPtr w, StringBuilder l, uint f, uint t, out IntPtr r);
56
+ [DllImport("user32.dll", SetLastError=true)] static extern IntPtr SendMessageTimeout(IntPtr h, uint m, IntPtr w, IntPtr l, uint f, uint t, out IntPtr r);
57
+ [DllImport("kernel32.dll")] static extern uint GetCurrentProcessId();
58
+ [DllImport("user32.dll")] static extern IntPtr SetWindowsHookEx(int id, LL f, IntPtr m, uint t);
59
+ [DllImport("user32.dll")] static extern IntPtr CallNextHookEx(IntPtr h, int c, IntPtr w, IntPtr l);
60
+ [DllImport("user32.dll")] static extern int GetMessage(out MSG m, IntPtr h, uint a, uint b);
61
+ [DllImport("user32.dll")] static extern IntPtr OpenInputDesktop(uint f, bool i, uint a);
62
+ [DllImport("user32.dll")] static extern bool CloseDesktop(IntPtr d);
63
+ [DllImport("user32.dll", CharSet=CharSet.Unicode)] static extern bool GetUserObjectInformation(IntPtr d, int i, StringBuilder s, int n, out int need);
64
+ [DllImport("kernel32.dll")] static extern IntPtr GetModuleHandle(string n);
65
+ [DllImport("kernel32.dll")] static extern uint GetCurrentThreadId();
66
+ [DllImport("kernel32.dll")] static extern IntPtr OpenProcess(uint a, bool i, uint pid);
67
+ [DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr h);
68
+ [DllImport("kernel32.dll", CharSet=CharSet.Unicode)] static extern bool QueryFullProcessImageName(IntPtr p, uint f, StringBuilder s, ref int n);
69
+ [DllImport("advapi32.dll")] static extern bool OpenProcessToken(IntPtr p, uint a, out IntPtr t);
70
+ [DllImport("advapi32.dll")] static extern bool GetTokenInformation(IntPtr t, int c, out int v, int n, out int r);
71
+ [DllImport("advapi32.dll")] static extern bool GetTokenInformation(IntPtr t, int c, IntPtr v, int n, out int r);
72
+ [DllImport("advapi32.dll")] static extern IntPtr GetSidSubAuthorityCount(IntPtr sid);
73
+ [DllImport("advapi32.dll")] static extern IntPtr GetSidSubAuthority(IntPtr sid, uint i);
74
+ static LL kp, mp; static IntPtr kh, mh;
75
+ public static long Inputs, Escapes, LastReal; public static bool Hooks; public static string HookError = "";
76
+ static ManualResetEvent ready = new ManualResetEvent(false);
77
+ static IntPtr K(int c, IntPtr w, IntPtr l) {
78
+ if (c >= 0) {
79
+ int m = (int)w; int flags = Marshal.ReadInt32(l, 8);
80
+ if ((flags & 0x10) == 0 && (m == 0x100 || m == 0x104)) {
81
+ Interlocked.Increment(ref Inputs); Interlocked.Exchange(ref LastReal, Environment.TickCount);
82
+ if (Marshal.ReadInt32(l, 0) == 0x1B) Interlocked.Increment(ref Escapes);
83
+ }
84
+ }
85
+ return CallNextHookEx(IntPtr.Zero, c, w, l);
86
+ }
87
+ static IntPtr M(int c, IntPtr w, IntPtr l) {
88
+ if (c >= 0) {
89
+ int flags = Marshal.ReadInt32(l, 12);
90
+ if ((flags & 1) == 0) { Interlocked.Increment(ref Inputs); Interlocked.Exchange(ref LastReal, Environment.TickCount); }
91
+ }
92
+ return CallNextHookEx(IntPtr.Zero, c, w, l);
93
+ }
94
+ public static bool StartHooks() {
95
+ try { SetProcessDPIAware(); } catch { }
96
+ var t = new Thread(() => {
97
+ kp = K; mp = M; var mod = GetModuleHandle(null);
98
+ kh = SetWindowsHookEx(13, kp, mod, 0); mh = SetWindowsHookEx(14, mp, mod, 0);
99
+ Hooks = kh != IntPtr.Zero && mh != IntPtr.Zero;
100
+ if (!Hooks) HookError = "SetWindowsHookEx failed " + Marshal.GetLastWin32Error();
101
+ ready.Set();
102
+ if (!Hooks) return;
103
+ MSG msg; while (GetMessage(out msg, IntPtr.Zero, 0, 0) > 0) { }
104
+ });
105
+ t.IsBackground = true; t.SetApartmentState(ApartmentState.STA); t.Start();
106
+ ready.WaitOne(5000); return Hooks;
107
+ }
108
+ public static long GliTick() { LII l = new LII(); l.cb = 8; GetLastInputInfo(ref l); return l.t; }
109
+ public static long Tick() { return (long)(uint)Environment.TickCount; }
110
+ public static long Since(long t) { return (long)(uint)(Environment.TickCount - (int)t); }
111
+ public static int CursorX() { PT p; GetCursorPos(out p); return p.x; }
112
+ public static int CursorY() { PT p; GetCursorPos(out p); return p.y; }
113
+ public static bool Cursor(int x, int y) { return SetCursorPos(x, y); }
114
+ public static long Fg() { return (long)GetForegroundWindow(); }
115
+ public static uint PidOf(long h) { uint p; GetWindowThreadProcessId((IntPtr)h, out p); return p; }
116
+ public static string Exe(uint pid) {
117
+ IntPtr h = OpenProcess(0x1000, false, pid); if (h == IntPtr.Zero) return "";
118
+ try { var sb = new StringBuilder(520); int n = 520; if (!QueryFullProcessImageName(h, 0, sb, ref n)) return ""; var s = sb.ToString(); int i = s.LastIndexOf('\\'); return i >= 0 ? s.Substring(i + 1) : s; } finally { CloseHandle(h); }
119
+ }
120
+ // The mandatory integrity level of a process as its RID: 0x1000 low, 0x2000 medium,
121
+ // 0x3000 high, 0x4000 system. -1 when it cannot be read (a program with higher rights refuses).
122
+ public static int Integrity(uint pid) {
123
+ IntPtr h = OpenProcess(0x1000, false, pid);
124
+ if (h == IntPtr.Zero) return -1;
125
+ try {
126
+ IntPtr t; if (!OpenProcessToken(h, 8, out t)) return -1;
127
+ try {
128
+ int need; GetTokenInformation(t, 25, IntPtr.Zero, 0, out need);
129
+ if (need <= 0) return -1;
130
+ IntPtr buf = Marshal.AllocHGlobal(need);
131
+ try {
132
+ if (!GetTokenInformation(t, 25, buf, need, out need)) return -1;
133
+ IntPtr sid = Marshal.ReadIntPtr(buf);
134
+ int n = Marshal.ReadByte(GetSidSubAuthorityCount(sid));
135
+ if (n < 1) return -1;
136
+ return Marshal.ReadInt32(GetSidSubAuthority(sid, (uint)(n - 1)));
137
+ } finally { Marshal.FreeHGlobal(buf); }
138
+ } finally { CloseHandle(t); }
139
+ } finally { CloseHandle(h); }
140
+ }
141
+ [DllImport("user32.dll")] static extern IntPtr GetMenu(IntPtr h);
142
+ [DllImport("user32.dll")] static extern IntPtr GetSubMenu(IntPtr m, int i);
143
+ [DllImport("user32.dll")] static extern int GetMenuItemCount(IntPtr m);
144
+ [DllImport("user32.dll")] static extern uint GetMenuItemID(IntPtr m, int i);
145
+ [DllImport("user32.dll")] static extern uint GetMenuState(IntPtr m, uint i, uint f);
146
+ [DllImport("user32.dll", CharSet=CharSet.Unicode)] static extern int GetMenuString(IntPtr m, uint i, StringBuilder s, int n, uint f);
147
+ [DllImport("user32.dll")] static extern bool PostMessage(IntPtr h, uint m, IntPtr w, IntPtr l);
148
+ // The classic menu of a window: the command whose item names the accelerator (the text after the tab, "Ctrl+O").
149
+ // Sent as the window message a click on the item would send, so it needs no focus and no screen. Reports what it found:
150
+ // "none" (no classic menu or no item with that accelerator), "disabled", or "sent|<id>|<item text>".
151
+ // The keys of a combination in a fixed order, so "Shift+Ctrl+S" and "Ctrl+Shift+S" are the same.
152
+ static string AccelKey(string a) {
153
+ var parts = a.Replace(" ", "").ToUpperInvariant().Split('+'); Array.Sort(parts, StringComparer.Ordinal); return string.Join("+", parts);
154
+ }
155
+ static string MenuWalk(IntPtr top, IntPtr m, int parentAt, string want, int depth, out uint id, out bool off) {
156
+ id = 0; off = false; int n = GetMenuItemCount(m);
157
+ for (int i = 0; i < n && i < 200; i++) {
158
+ var sb = new StringBuilder(256); GetMenuString(m, (uint)i, sb, 256, 0x400);
159
+ string text = sb.ToString(); int tab = text.IndexOf('\t');
160
+ if (tab >= 0 && AccelKey(text.Substring(tab + 1)) == AccelKey(want)) {
161
+ // An app enables or greys items when the popup is about to open: ask it to, as opening the menu would, then read the state.
162
+ if (depth > 0) { IntPtr ir; SendMessageTimeout(top, 0x117, m, (IntPtr)parentAt, 2, 1000, out ir); }
163
+ uint st = GetMenuState(m, (uint)i, 0x400); id = GetMenuItemID(m, i);
164
+ off = (st & 3) != 0; return text.Substring(0, tab);
165
+ }
166
+ if (depth < 4) { IntPtr sub = GetSubMenu(m, i); if (sub != IntPtr.Zero) { string r = MenuWalk(top, sub, i, want, depth + 1, out id, out off); if (r != null) return r; } }
167
+ }
168
+ return null;
169
+ }
170
+ public static string MenuCommand(long hwnd, string accel) {
171
+ IntPtr m = GetMenu((IntPtr)hwnd); if (m == IntPtr.Zero) return "none";
172
+ uint id; bool off; string text = MenuWalk((IntPtr)hwnd, m, 0, accel, 0, out id, out off);
173
+ if (text == null || id == 0 || id == 0xFFFFFFFF) return "none";
174
+ if (off) return "disabled";
175
+ if (!PostMessage((IntPtr)hwnd, 0x111, (IntPtr)id, IntPtr.Zero)) return "none";
176
+ return "sent|" + id + "|" + text;
177
+ }
178
+ [DllImport("user32.dll")] static extern short GetAsyncKeyState(int vk);
179
+ // A key or mouse button is physically down right now (a drag, a held modifier): the person is using the computer.
180
+ public static bool Held() {
181
+ for (int vk = 1; vk < 255; vk++) { if (vk == 3 || vk == 7 || vk == 0xE7) continue; if ((GetAsyncKeyState(vk) & 0x8000) != 0) return true; }
182
+ return false;
183
+ }
184
+ static int selfRid = -2;
185
+ public static int SelfIntegrity() { if (selfRid == -2) selfRid = Integrity(GetCurrentProcessId()); return selfRid; }
186
+ // Whether Windows keeps this program's input from that process: it runs above us, or cannot be read.
187
+ public static bool Elevated(uint pid) {
188
+ int r = Integrity(pid); if (r < 0) return true;
189
+ return r > SelfIntegrity();
190
+ }
191
+ // Whether a process is positively read to run above this program's rights; unreadable is not a yes.
192
+ public static bool Above(uint pid) {
193
+ if (pid == 0) return false;
194
+ int r = Integrity(pid); return r >= 0 && r > SelfIntegrity();
195
+ }
196
+ public static string Desktop() {
197
+ IntPtr d = OpenInputDesktop(0, false, 1); if (d == IntPtr.Zero) return "(unreadable)";
198
+ try { var sb = new StringBuilder(256); int need; if (!GetUserObjectInformation(d, 2, sb, 512, out need)) return "(unreadable)"; return sb.ToString(); } finally { CloseDesktop(d); }
199
+ }
200
+ public class EditRes { public bool Found; public string Reason = ""; public long Hwnd; public string Cls = ""; public bool Done; public long Len; public string Text = ""; public string Seen = ""; }
201
+ static bool EditClass(string c) { return c == "Edit" || c.StartsWith("RichEdit", StringComparison.OrdinalIgnoreCase) || c.StartsWith("RICHEDIT", StringComparison.OrdinalIgnoreCase); }
202
+ static string ClassOf(IntPtr h) { var sb = new StringBuilder(256); GetClassName(h, sb, 256); return sb.ToString(); }
203
+ // How many times a text occurs in another, without overlap: typing one letter after another is judged on the text so far.
204
+ static int Occ(string text, string want) {
205
+ if (want.Length == 0) return 0;
206
+ int n = 0, at = text.IndexOf(want, StringComparison.Ordinal);
207
+ while (at >= 0) { n++; at = text.IndexOf(want, at + want.Length, StringComparison.Ordinal); }
208
+ return n;
209
+ }
210
+ static string Norm(string s) { return s.Replace("\r\n", "\n").Replace("\r", "\n"); }
211
+ // The text of an edit control through WM_GETTEXT; null when it cannot be read.
212
+ static string TextOf(IntPtr h, out string why) {
213
+ why = ""; IntPtr r;
214
+ if (SendMessageTimeout(h, 0xE, IntPtr.Zero, IntPtr.Zero, 2, 2000, out r) == IntPtr.Zero) { why = Marshal.GetLastWin32Error() == 5 ? "uipi" : "hung"; return null; }
215
+ long n = (long)r; if (n > 2000000) { why = "unreadable"; return null; }
216
+ var sb = new StringBuilder((int)n + 2);
217
+ if (SendMessageTimeout(h, 0xD, (IntPtr)(n + 1), sb, 2, 2000, out r) == IntPtr.Zero && n > 0) { why = Marshal.GetLastWin32Error() == 5 ? "uipi" : "hung"; return null; }
218
+ return sb.ToString();
219
+ }
220
+ public static EditRes EditOp(long top, string op, string text, int cx, int cy, bool hasC, string pick) {
221
+ var res = new EditRes(); IntPtr t = (IntPtr)top;
222
+ if (!IsWindow(t)) { res.Reason = "gone"; return res; }
223
+ uint pid; uint tid = GetWindowThreadProcessId(t, out pid);
224
+ if (Elevated(pid)) { res.Reason = "uipi"; return res; }
225
+ var found = new System.Collections.Generic.List<IntPtr>();
226
+ EnumChildWindows(t, (h, l) => { if (IsWindowVisible(h) && EditClass(ClassOf(h))) found.Add(h); return true; }, IntPtr.Zero);
227
+ IntPtr pickH = IntPtr.Zero;
228
+ if (pick == "focus") {
229
+ var g = new GTI(); g.cb = Marshal.SizeOf(typeof(GTI));
230
+ // Only a focus inside the chosen window counts: a dialog of the same thread is not it.
231
+ bool have = GetGUIThreadInfo(tid, ref g);
232
+ if (have && g.foc != IntPtr.Zero) {
233
+ if ((g.foc == t || IsChild(t, g.foc)) && EditClass(ClassOf(g.foc))) pickH = g.foc;
234
+ } else if (have && (g.act == IntPtr.Zero || g.act == t) && found.Count == 1) {
235
+ // A thread that is not the active one has no focus window at all. With no other active window of
236
+ // the thread (a dialog) and a single edit control in the chosen window, that control is the target.
237
+ // A focus on any other control, or on another window, never reaches here.
238
+ // It must be enabled, not the inner field of a combo box, and fill most of the window: a small or
239
+ // inner field is a guess about where the text was meant to go, so the caller is told it was not found.
240
+ IntPtr only = found[0]; RC er, cr;
241
+ bool usable = (GetWindowLong(only, -16) & 0x08000000) == 0 && ClassOf(GetParent(only)).IndexOf("ComboBox", StringComparison.OrdinalIgnoreCase) < 0
242
+ && GetWindowRect(only, out er) && GetClientRect(t, out cr)
243
+ && (long)(er.r - er.l) * (er.b - er.t) * 2 >= (long)(cr.r - cr.l) * (cr.b - cr.t);
244
+ if (usable) pickH = only;
245
+ }
246
+ } else if (hasC) {
247
+ foreach (var h in found) { RC rc; if (GetWindowRect(h, out rc) && cx >= rc.l && cx < rc.r && cy >= rc.t && cy < rc.b) { pickH = h; break; } }
248
+ }
249
+ if (pickH == IntPtr.Zero) {
250
+ // The lone-edit shortcut is for a chosen place only; a focus that is not an edit is not one.
251
+ if (pick == "focus") { res.Reason = "no_edit"; return res; }
252
+ if (found.Count == 1) pickH = found[0];
253
+ else { res.Reason = found.Count == 0 ? "no_edit" : "ambiguous"; return res; }
254
+ }
255
+ res.Found = true; res.Hwnd = (long)pickH; res.Cls = ClassOf(pickH);
256
+ int style = GetWindowLong(pickH, -16);
257
+ if (op != "get" && (style & 0x800) != 0) { res.Reason = "read_only"; return res; }
258
+ string why; string before = TextOf(pickH, out why);
259
+ if (before == null) { res.Reason = why; return res; }
260
+ if (op == "get") { res.Len = before.Length; res.Text = before.Length > 65536 ? before.Substring(0, 65536) : before; res.Done = true; return res; }
261
+ string send = (style & 0x4) != 0 ? Norm(text).Replace("\n", "\r\n") : text;
262
+ IntPtr rr;
263
+ bool sent = op == "set"
264
+ ? SendMessageTimeout(pickH, 0xC, IntPtr.Zero, send, 2, 3000, out rr) != IntPtr.Zero
265
+ : SendMessageTimeout(pickH, 0xC2, (IntPtr)1, send, 2, 3000, out rr) != IntPtr.Zero;
266
+ int err = sent ? 0 : Marshal.GetLastWin32Error();
267
+ if (!sent) { res.Reason = err == 5 ? "uipi" : (err == 1460 ? "hung" : "refused"); return res; }
268
+ string after = TextOf(pickH, out why);
269
+ if (after == null) { res.Reason = "unreadable"; return res; }
270
+ res.Len = after.Length;
271
+ string a = Norm(after), b = Norm(before), w = Norm(text);
272
+ res.Done = op == "set" ? a == w : (a != b && Occ(a, w) > Occ(b, w));
273
+ int at = op == "type" ? a.IndexOf(w) : 0; if (at < 0) at = 0;
274
+ int from = Math.Max(0, at - 40); res.Seen = a.Substring(from, Math.Min(a.Length - from, w.Length + 80));
275
+ return res;
276
+ }
277
+
278
+ public static string How = "";
279
+ public static bool Alive(long h) { return IsWindow((IntPtr)h); }
280
+ public static bool Raise(long hv) {
281
+ IntPtr h = (IntPtr)hv; if (!IsWindow(h)) { How = "gone"; return false; }
282
+ IntPtr cur = GetForegroundWindow(); if (cur == h) { How = "already"; return true; }
283
+ if (IsIconic(h)) ShowWindow(h, 9);
284
+ SetForegroundWindow(h);
285
+ if (GetForegroundWindow() == h) { How = "plain"; return true; }
286
+ // Windows lets a program take the front only if it has just been given input. An
287
+ // unassigned key tapped by this program (flagged as injected, so it is not counted
288
+ // as a person's) gives it that right and does nothing in any window.
289
+ keybd_event(0x87, 0, 0, UIntPtr.Zero); keybd_event(0x87, 0, 2, UIntPtr.Zero);
290
+ SetForegroundWindow(h);
291
+ if (GetForegroundWindow() == h) { How = "unlock"; return true; }
292
+ uint p; uint ct = GetWindowThreadProcessId(cur, out p); uint mt = GetCurrentThreadId();
293
+ bool at = ct != 0 && ct != mt && AttachThreadInput(mt, ct, true);
294
+ SetForegroundWindow(h);
295
+ if (at) AttachThreadInput(mt, ct, false);
296
+ if (GetForegroundWindow() == h) { How = "attach"; return true; }
297
+ SwitchToThisWindow(h, true);
298
+ Thread.Sleep(30);
299
+ if (GetForegroundWindow() == h) { How = "switch"; return true; }
300
+ How = "refused"; return false;
301
+ }
302
+ }
303
+ "@
304
+ $hooks = [NzG]::StartHooks()
305
+ $selfIntegrity = [NzG]::SelfIntegrity()
306
+ $selfElevated = ($selfIntegrity -ge 12288)
307
+ $ownStart = 0; $ownEnd = 0
308
+ $burst = $null
309
+ function Hx($h) { '0x{0:X}' -f [int64]$h }
310
+ function State($pidArg) {
311
+ $fgH = [NzG]::Fg(); $fgPid = [NzG]::PidOf($fgH)
312
+ $gli = [NzG]::GliTick()
313
+ $real = [NzG]::LastReal
314
+ $realIdle = if ($real -eq 0) { [int64]::MaxValue } else { [NzG]::Since($real) }
315
+ $own = ($ownStart -ne 0 -and [NzG]::Since($gli) -le [NzG]::Since($ownStart) -and ($ownEnd -eq 0 -or [NzG]::Since($gli) -ge ([NzG]::Since($ownEnd) - 300)))
316
+ $gliIdle = if ($own) { [int64]::MaxValue } else { [NzG]::Since($gli) }
317
+ $idle = [Math]::Min($realIdle, $gliIdle)
318
+ # A key or button held down is use, however long ago it was pressed.
319
+ if ([NzG]::Held()) { $idle = 0 }
320
+ if ($idle -eq [int64]::MaxValue) { $idle = 86400000 }
321
+ $r = @{
322
+ userIdleMs = $idle; userInputs = [NzG]::Inputs; escapes = [NzG]::Escapes; desktop = [NzG]::Desktop(); selfElevated = $selfElevated; selfIntegrity = $selfIntegrity; inputTick = $gli
323
+ cursor = @{ x = [NzG]::CursorX(); y = [NzG]::CursorY() }
324
+ foreground = $null
325
+ }
326
+ if ($fgH -ne 0) { $r.foreground = @{ hwnd = (Hx $fgH); pid = $fgPid; exe = [NzG]::Exe($fgPid); elevated = [NzG]::Elevated($fgPid); integrity = [NzG]::Integrity($fgPid) } }
327
+ if ($pidArg) { $r.target = @{ exe = [NzG]::Exe([uint32]$pidArg); elevated = [NzG]::Elevated([uint32]$pidArg); integrity = [NzG]::Integrity([uint32]$pidArg) } }
328
+ $r
329
+ }
330
+ function EndBurst($restore, $keepCursor) {
331
+ $res = @{ inputsDuring = 0; escapesDuring = 0; restoredForeground = $false; restoredCursor = $false }
332
+ if ($null -eq $script:burst) { return $res }
333
+ $b = $script:burst; $script:burst = $null
334
+ $script:ownEnd = [NzG]::Tick()
335
+ $res.inputsDuring = [NzG]::Inputs - $b.inputs; $res.escapesDuring = [NzG]::Escapes - $b.escapes
336
+ # Input that Windows dropped (a window above this program's rights) leaves the tick where it was.
337
+ $res.inputMoved = ([NzG]::GliTick() -ne $b.tick)
338
+ $fgNow = [NzG]::Fg(); $res.frontElevated = [NzG]::Above([NzG]::PidOf($fgNow))
339
+ if ($restore) {
340
+ # The window is put back only when this burst moved the front: the window it
341
+ # raised, or, where the raise was refused and the driver took the front itself,
342
+ # the target (or another window of its program) now in front. Anything else in
343
+ # front means the user, or a click of the burst, has already moved on: leave it.
344
+ $cur = [NzG]::Fg()
345
+ $mine = if ($b.raised -ne 0) { $b.raised } else { $b.target }
346
+ $minePid = if ($b.raised -ne 0) { $b.raisedPid } else { $b.targetPid }
347
+ if ($b.fg -eq 0 -or $mine -eq 0) { $res.restoreNote = 'the burst had no window to put back' }
348
+ elseif ($cur -eq $b.fg) { $res.restoreNote = 'the window that was in front is in front again' }
349
+ elseif ($cur -ne $mine -and ([NzG]::PidOf($cur) -ne $minePid -or $minePid -eq 0)) { $res.restoreNote = 'another window was in front by then, so it was left alone' }
350
+ elseif (-not [NzG]::Alive($b.fg)) { $res.restoreNote = 'the window that was in front is gone' }
351
+ else {
352
+ $res.restoredForeground = [NzG]::Raise($b.fg); $res.restoreHow = [NzG]::How
353
+ if (-not $res.restoredForeground) { $res.restoreNote = 'Windows would not give the front back to the previous window' }
354
+ }
355
+ }
356
+ if ($restore -and $res.inputsDuring -eq 0) {
357
+ if (-not $keepCursor -and ([NzG]::CursorX() -ne $b.x -or [NzG]::CursorY() -ne $b.y)) { $res.restoredCursor = [NzG]::Cursor($b.x, $b.y) }
358
+ }
359
+ $res
360
+ }
361
+ function Release($path, $token) {
362
+ if (-not $path) { return }
363
+ try { if (Test-Path -LiteralPath $path) { $t = (Get-Content -LiteralPath $path -Raw | ConvertFrom-Json).token; if ($t -eq $token) { Remove-Item -LiteralPath $path -Force } } } catch { }
364
+ }
365
+ function Reply($o) { [Console]::Out.WriteLine((ConvertTo-Json -InputObject $o -Compress -Depth 6)) }
366
+ Reply @{ ok = $true; hooks = $hooks; hookError = [NzG]::HookError; selfElevated = $selfElevated }
367
+ while (($line = [Console]::In.ReadLine()) -ne $null) {
368
+ $cid = $null
369
+ try {
370
+ $c = $line | ConvertFrom-Json
371
+ $cid = $c.id
372
+ switch ($c.cmd) {
373
+ 'state' { $r = State $c.pid }
374
+ 'begin' {
375
+ $script:burst = @{ inputs = [NzG]::Inputs; escapes = [NzG]::Escapes; fg = [NzG]::Fg(); raised = 0; raisedPid = 0; target = 0; targetPid = 0; tick = 0; x = [NzG]::CursorX(); y = [NzG]::CursorY(); lease = $c.lease; token = $c.token }
376
+ $pre = State $null
377
+ if ($c.idleMs -and $pre.userIdleMs -lt [int64]$c.idleMs) {
378
+ # A person is still using the machine: move nothing.
379
+ $script:burst = $null
380
+ $r = $pre; $r.refused = $true
381
+ } else {
382
+ $script:ownStart = [NzG]::Tick(); $script:ownEnd = 0
383
+ $raised = $null
384
+ if ($c.raise) {
385
+ $target = [Convert]::ToInt64(([string]$c.raise).Substring(2), 16)
386
+ $script:burst.target = $target; $script:burst.targetPid = [NzG]::PidOf($target)
387
+ $raised = [NzG]::Raise($target)
388
+ if ($raised -and [NzG]::Fg() -ne $script:burst.fg) { $script:burst.raised = $target; $script:burst.raisedPid = [NzG]::PidOf($target) }
389
+ }
390
+ # Taken after the raise: the unlock tap above is this program's own input.
391
+ $script:burst.tick = [NzG]::GliTick()
392
+ $r = State $null
393
+ if ($null -ne $raised) { $r.raised = $raised; $r.raiseHow = [NzG]::How }
394
+ }
395
+ }
396
+ 'edit' {
397
+ $t = [Convert]::ToInt64(([string]$c.hwnd).Substring(2), 16)
398
+ $e = [NzG]::EditOp($t, [string]$c.op, [string]$c.text, [int]$c.x, [int]$c.y, ($null -ne $c.x), [string]$c.pick)
399
+ $r = @{ found = $e.Found; reason = $e.Reason; hwnd = (Hx $e.Hwnd); cls = $e.Cls; done = $e.Done; len = $e.Len; text = $e.Text; seen = $e.Seen }
400
+ }
401
+ 'select' {
402
+ # A list or tree item is selected without opening it. The accessibility selection pattern gives a folder window's
403
+ # item view the focus, which brings the window forward; the shell's own view selects without either.
404
+ if (-not $script:uia) { Add-Type -AssemblyName UIAutomationClient,UIAutomationTypes; $script:uia = $true }
405
+ $A = [System.Windows.Automation.AutomationElement]
406
+ $t = [Convert]::ToInt64(([string]$c.hwnd).Substring(2), 16)
407
+ if (-not [NzG]::Alive($t)) { $r = @{ found = $false; reason = 'gone'; selected = $false } }
408
+ else {
409
+ $root = $A::FromHandle([IntPtr]$t)
410
+ $byName = New-Object System.Windows.Automation.PropertyCondition($A::NameProperty, [string]$c.name)
411
+ $hits = @($root.FindAll([System.Windows.Automation.TreeScope]::Descendants, $byName) | Where-Object { $_.Current.ControlType.ProgrammaticName -eq ('ControlType.' + [string]$c.role) })
412
+ # The id the driver reports is not always the one the control has: it tells equals apart only when it narrows the match.
413
+ if ($hits.Count -gt 1 -and $c.autoId) {
414
+ $same = @($hits | Where-Object { $_.Current.AutomationId -eq [string]$c.autoId })
415
+ if ($same.Count -ge 1) { $hits = $same }
416
+ }
417
+ if ($hits.Count -gt 1 -and $null -ne $c.x) {
418
+ $cx = [double]$c.x + [double]$c.w / 2; $cy = [double]$c.y + [double]$c.h / 2
419
+ $near = @($hits | Where-Object { $b = $_.Current.BoundingRectangle; [Math]::Abs(($b.X + $b.Width / 2) - $cx) -le 8 -and [Math]::Abs(($b.Y + $b.Height / 2) - $cy) -le 8 })
420
+ if ($near.Count -ge 1) { $hits = $near }
421
+ }
422
+ if ($hits.Count -eq 0) { $r = @{ found = $false; reason = 'not_found'; selected = $false } }
423
+ elseif ($hits.Count -gt 1) { $r = @{ found = $false; reason = 'ambiguous'; selected = $false } }
424
+ else {
425
+ $o = $null; $how = ''
426
+ if ($root.Current.ClassName -eq 'CabinetWClass') {
427
+ # Select and clear the others (1 and 4), without focus or scrolling.
428
+ try {
429
+ $win = $null
430
+ foreach ($w in (New-Object -ComObject Shell.Application).Windows()) { if ([int64]$w.HWND -eq $t) { $win = $w } }
431
+ if ($null -ne $win) {
432
+ $items = @($win.Document.Folder.Items() | Where-Object { $_.Name -eq [string]$c.name })
433
+ if ($items.Count -eq 1) { $win.Document.SelectItem($items[0], 5); $how = 'shell' }
434
+ }
435
+ } catch { $how = '' }
436
+ }
437
+ if ($how -eq '' -and -not $hits[0].TryGetCurrentPattern([System.Windows.Automation.SelectionItemPattern]::Pattern, [ref]$o)) { $r = @{ found = $false; reason = 'no_pattern'; selected = $false } }
438
+ else {
439
+ try {
440
+ if ($how -eq '') { $o.Select(); $how = 'pattern' }
441
+ $p = $null; $now = $hits[0].TryGetCurrentPattern([System.Windows.Automation.SelectionItemPattern]::Pattern, [ref]$p) -and $p.Current.IsSelected
442
+ $r = @{ found = $true; reason = ''; selected = [bool]$now; how = $how }
443
+ } catch { $r = @{ found = $false; reason = 'refused'; selected = $false } }
444
+ }
445
+ }
446
+ }
447
+ }
448
+ 'menu' {
449
+ # A keyboard shortcut whose effect is a menu command of a classic window: the command is sent as the message
450
+ # its menu item sends, so nothing is raised and no key is pressed.
451
+ $t = [Convert]::ToInt64(([string]$c.hwnd).Substring(2), 16)
452
+ if (-not [NzG]::Alive($t)) { $r = @{ found = $false; reason = 'gone' } }
453
+ else {
454
+ $m = [NzG]::MenuCommand($t, [string]$c.accel)
455
+ if ($m.StartsWith('sent|')) { $p = $m.Split('|', 3); $r = @{ found = $true; reason = ''; id = [int]$p[1]; label = $p[2] } }
456
+ else { $r = @{ found = $false; reason = $m } }
457
+ }
458
+ }
459
+ 'end' { $r = EndBurst ([bool]$c.restore) ([bool]$c.keepCursor) }
460
+ 'release' { Release $c.lease $c.token; $r = @{ ok = $true } }
461
+ 'quit' { break }
462
+ default { $r = @{ error = 'unknown command' } }
463
+ }
464
+ if ($c.cmd -eq 'quit') { break }
465
+ Reply @{ ok = $true; id = $cid; r = $r }
466
+ } catch {
467
+ Reply @{ ok = $false; id = $cid; error = "$_" }
468
+ }
469
+ }
470
+ if ($null -ne $burst) { $keep = $burst; EndBurst $true $false | Out-Null; Release $keep.lease $keep.token }
471
+ `;
472
+ //# sourceMappingURL=windows-helper-script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windows-helper-script.js","sourceRoot":"","sources":["../../src/foreground/windows-helper-script.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqc9C,CAAA"}
@@ -0,0 +1,75 @@
1
+ import type { EditTextRequest, EditTextResult, ForegroundMonitor, MenuCommandRequest, MenuCommandResult, MonitorBurstEnd, MonitorState, SelectItemRequest, SelectItemResult } from './types.js';
2
+ /** The ends of a started helper; the real one is a child process. */
3
+ export interface HelperProcess {
4
+ write(line: string): void;
5
+ onLine(handler: (line: string) => void): void;
6
+ onExit(handler: () => void): void;
7
+ kill(): void;
8
+ }
9
+ export interface WindowsMonitorOptions {
10
+ /** Windows PowerShell, as this process starts it. */
11
+ readonly powershell: string;
12
+ readonly env?: NodeJS.ProcessEnv;
13
+ /** Waiting for the first answer (compiling the helper), ms. Default 60 000. */
14
+ readonly startTimeoutMs?: number;
15
+ /** Waiting for each later answer, ms. Default 10 000. */
16
+ readonly requestTimeoutMs?: number;
17
+ /** How Windows names a path this process knows (the lease file). Default: unchanged. */
18
+ readonly toWindowsPath?: (path: string) => string;
19
+ /** For tests. */
20
+ readonly spawnHelper?: (script: string) => HelperProcess;
21
+ }
22
+ /**
23
+ * What PowerShell is started with: a bootstrap that reads the helper script
24
+ * from the first line of its input (UTF-8, base64) and runs it, so the script
25
+ * can grow past the 32 767 characters a command line allows. The line protocol
26
+ * follows on the same stream.
27
+ */
28
+ export declare const HELPER_BOOTSTRAP = "$s=[Console]::In.ReadLine();Invoke-Expression ([Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($s)))";
29
+ /** The bootstrap as PowerShell's `-EncodedCommand` takes it. */
30
+ export declare function encodeHelperCommand(script?: string): string;
31
+ /** The first line written to a helper started with {@link HELPER_BOOTSTRAP}. */
32
+ export declare function helperScriptLine(script?: string): string;
33
+ /**
34
+ * A {@link ForegroundMonitor} backed by the long-lived PowerShell helper.
35
+ * One poll answers in well under a millisecond once it runs; starting it
36
+ * compiles a small hook library and takes about half a second warm.
37
+ */
38
+ export declare class WindowsInputMonitor implements ForegroundMonitor {
39
+ private readonly options;
40
+ private proc;
41
+ private nextId;
42
+ private waiting;
43
+ private exited;
44
+ constructor(options: WindowsMonitorOptions);
45
+ start(): Promise<void>;
46
+ state(query?: {
47
+ readonly pid?: number;
48
+ }): Promise<MonitorState>;
49
+ begin(args: {
50
+ readonly leasePath: string;
51
+ readonly token: string;
52
+ readonly raise?: string;
53
+ readonly idleMs?: number;
54
+ }): Promise<MonitorState & {
55
+ readonly raised?: boolean;
56
+ readonly refused?: boolean;
57
+ }>;
58
+ end(args: {
59
+ readonly restore: boolean;
60
+ readonly keepCursor?: boolean;
61
+ }): Promise<MonitorBurstEnd>;
62
+ editText(request: EditTextRequest): Promise<EditTextResult>;
63
+ menuCommand(request: MenuCommandRequest): Promise<MenuCommandResult>;
64
+ selectItem(request: SelectItemRequest): Promise<SelectItemResult>;
65
+ release(args: {
66
+ readonly leasePath: string;
67
+ readonly token: string;
68
+ }): Promise<void>;
69
+ dispose(): Promise<void>;
70
+ private winPath;
71
+ private onLine;
72
+ private expect;
73
+ private call;
74
+ }
75
+ //# sourceMappingURL=windows-monitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"windows-monitor.d.ts","sourceRoot":"","sources":["../../src/foreground/windows-monitor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACX,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,YAAY,CAAA;AAGnB,qEAAqE;AACrE,MAAM,WAAW,aAAa;IAC7B,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI,CAAA;IAC7C,MAAM,CAAC,OAAO,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;IACjC,IAAI,IAAI,IAAI,CAAA;CACZ;AAED,MAAM,WAAW,qBAAqB;IACrC,qDAAqD;IACrD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAA;IAChC,+EAA+E;IAC/E,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;IAChC,yDAAyD;IACzD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,wFAAwF;IACxF,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACjD,iBAAiB;IACjB,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,aAAa,CAAA;CACxD;AAYD;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,qHACsF,CAAA;AAEnH,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,MAAM,GAAE,MAAyB,GAAG,MAAM,CAE7E;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,MAAM,GAAE,MAA8B,GAAG,MAAM,CAE/E;AAuCD;;;;GAIG;AACH,qBAAa,mBAAoB,YAAW,iBAAiB;IAUhD,OAAO,CAAC,QAAQ,CAAC,OAAO;IATpC,OAAO,CAAC,IAAI,CAA2B;IACvC,OAAO,CAAC,MAAM,CAAI;IAClB,OAAO,CAAC,OAAO,CAIR;IACP,OAAO,CAAC,MAAM,CAAQ;gBAEO,OAAO,EAAE,qBAAqB;IAErD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAuB5B,KAAK,CAAC,KAAK,GAAE;QAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAOnE,KAAK,CAAC,IAAI,EAAE;QACX,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;QAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;QACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;QACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KACxB,GAAG,OAAO,CAAC,YAAY,GAAG;QAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;IAUrF,GAAG,CAAC,IAAI,EAAE;QACT,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;QACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;KAC7B,GAAG,OAAO,CAAC,eAAe,CAAC;IAQ5B,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAW3D,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAQpE,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAkB3D,OAAO,CAAC,IAAI,EAAE;QACnB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;QAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;KACtB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQX,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAW9B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,MAAM;IAwBd,OAAO,CAAC,MAAM;YAcA,IAAI;CAUlB"}