mindweave 3.3.0 → 3.4.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/dist/alternator/chassis/lsp.js +1 -1
- package/dist/alternator/chassis/lsp.js.map +1 -1
- package/dist/alternator/chassis/provision.js +2 -2
- package/dist/alternator/chassis/provision.js.map +1 -1
- package/dist/cli/App.js +221 -57
- package/dist/cli/App.js.map +1 -1
- package/dist/cli/attachments.js +2 -1
- package/dist/cli/attachments.js.map +1 -1
- package/dist/cli/blockHeights.js +14 -0
- package/dist/cli/blockHeights.js.map +1 -1
- package/dist/cli/components/BlockView.js +9 -1
- package/dist/cli/components/BlockView.js.map +1 -1
- package/dist/cli/components/EditGroup.js +50 -0
- package/dist/cli/components/EditGroup.js.map +1 -0
- package/dist/cli/components/FadeText.js +47 -0
- package/dist/cli/components/FadeText.js.map +1 -0
- package/dist/cli/components/PromptInput.js +26 -4
- package/dist/cli/components/PromptInput.js.map +1 -1
- package/dist/cli/components/ToolLine.js +5 -3
- package/dist/cli/components/ToolLine.js.map +1 -1
- package/dist/cli/components/WorkGroup.js +34 -23
- package/dist/cli/components/WorkGroup.js.map +1 -1
- package/dist/cli/diffRows.js +16 -0
- package/dist/cli/diffRows.js.map +1 -1
- package/dist/cli/editGroup.js +122 -0
- package/dist/cli/editGroup.js.map +1 -0
- package/dist/cli/entrance.js +95 -0
- package/dist/cli/entrance.js.map +1 -0
- package/dist/cli/framebuffer/parse.js +99 -16
- package/dist/cli/framebuffer/parse.js.map +1 -1
- package/dist/cli/framebuffer/writer.js +46 -28
- package/dist/cli/framebuffer/writer.js.map +1 -1
- package/dist/cli/help.js +6 -0
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/inkSpeedLoader.js +9 -5
- package/dist/cli/inkSpeedLoader.js.map +1 -1
- package/dist/cli/inkThrottlePatch.js +43 -0
- package/dist/cli/inkThrottlePatch.js.map +1 -0
- package/dist/cli/screenMode.js +8 -1
- package/dist/cli/screenMode.js.map +1 -1
- package/dist/cli/sessionCarry.js.map +1 -1
- package/dist/cli/toolDisplay.js +2 -2
- package/dist/cli/toolDisplay.js.map +1 -1
- package/dist/cli/transcript.js +67 -14
- package/dist/cli/transcript.js.map +1 -1
- package/dist/cli/workLines.js +27 -4
- package/dist/cli/workLines.js.map +1 -1
- package/dist/core/turnRunner.js +98 -7
- package/dist/core/turnRunner.js.map +1 -1
- package/dist/drivers/anthropic/client.js +16 -3
- package/dist/drivers/anthropic/client.js.map +1 -1
- package/dist/drivers/anthropic/manifest.js +10 -0
- package/dist/drivers/anthropic/manifest.js.map +1 -1
- package/dist/drivers/glm/manifest.js +9 -0
- package/dist/drivers/glm/manifest.js.map +1 -1
- package/dist/drivers/groq/manifest.js +5 -0
- package/dist/drivers/groq/manifest.js.map +1 -1
- package/dist/drivers/mistral/client.js +3 -0
- package/dist/drivers/mistral/client.js.map +1 -1
- package/dist/drivers/openai/client.js +3 -0
- package/dist/drivers/openai/client.js.map +1 -1
- package/dist/drivers/openai/manifest.js +5 -0
- package/dist/drivers/openai/manifest.js.map +1 -1
- package/dist/drivers/openaiCompat/wire.js +7 -2
- package/dist/drivers/openaiCompat/wire.js.map +1 -1
- package/dist/drivers/openrouter/client.js +6 -0
- package/dist/drivers/openrouter/client.js.map +1 -1
- package/dist/drivers/xai/client.js +9 -0
- package/dist/drivers/xai/client.js.map +1 -1
- package/dist/dynamo/cacheBreak.js +8 -5
- package/dist/dynamo/cacheBreak.js.map +1 -1
- package/dist/dynamo/contextWindow.js +64 -12
- package/dist/dynamo/contextWindow.js.map +1 -1
- package/dist/dynamo/engine.js +132 -66
- package/dist/dynamo/engine.js.map +1 -1
- package/dist/dynamo/prompt.js +8 -2
- package/dist/dynamo/prompt.js.map +1 -1
- package/dist/dynamo/toolAliases.js +73 -0
- package/dist/dynamo/toolAliases.js.map +1 -0
- package/dist/dynamo/toolArgs.js +82 -0
- package/dist/dynamo/toolArgs.js.map +1 -0
- package/dist/dynamo/verify.js +16 -2
- package/dist/dynamo/verify.js.map +1 -1
- package/dist/memory/clearedArchive.js +2 -20
- package/dist/memory/clearedArchive.js.map +1 -1
- package/dist/memory/compaction.js +3 -1
- package/dist/memory/compaction.js.map +1 -1
- package/dist/memory/localCommand.js +30 -3
- package/dist/memory/localCommand.js.map +1 -1
- package/dist/memory/presence.js +44 -0
- package/dist/memory/presence.js.map +1 -1
- package/dist/memory/session.js +4 -0
- package/dist/memory/session.js.map +1 -1
- package/dist/memory/store.js +27 -4
- package/dist/memory/store.js.map +1 -1
- package/dist/memory/types.js.map +1 -1
- package/dist/memory/userNotes.js +17 -0
- package/dist/memory/userNotes.js.map +1 -0
- package/dist/tools/backgroundShells.js +38 -7
- package/dist/tools/backgroundShells.js.map +1 -1
- package/dist/tools/deferredNative.js +24 -0
- package/dist/tools/deferredNative.js.map +1 -1
- package/dist/tools/edit.js +18 -3
- package/dist/tools/edit.js.map +1 -1
- package/dist/tools/editCore.js +107 -1
- package/dist/tools/editCore.js.map +1 -1
- package/dist/tools/mcpSearch.js +8 -2
- package/dist/tools/mcpSearch.js.map +1 -1
- package/dist/tools/readFile.js +16 -1
- package/dist/tools/readFile.js.map +1 -1
- package/dist/tools/rebuildDetail.js +94 -3
- package/dist/tools/rebuildDetail.js.map +1 -1
- package/dist/tools/registry.js +12 -12
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/runCommand.js +10 -3
- package/dist/tools/runCommand.js.map +1 -1
- package/dist/tools/screenshot.js +42 -3
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/screenshotWin.js +221 -216
- package/dist/tools/screenshotWin.js.map +1 -1
- package/dist/tools/search.js +4 -1
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/shellTools.js +17 -25
- package/dist/tools/shellTools.js.map +1 -1
- package/dist/tools/ui.js +26 -9
- package/dist/tools/ui.js.map +1 -1
- package/dist/tools/uiWin.js +4 -1
- package/dist/tools/uiWin.js.map +1 -1
- package/dist/tools/untrusted.js +24 -0
- package/dist/tools/untrusted.js.map +1 -1
- package/package.json +78 -78
|
@@ -42,221 +42,225 @@ import { tmpdir } from "node:os";
|
|
|
42
42
|
import { join } from "node:path";
|
|
43
43
|
import { DESK_CS, HIDDEN_MARK, hiddenDesktopName, windowArgs } from "./hiddenDesktop.js";
|
|
44
44
|
const PS_TIMEOUT_MS = 20_000;
|
|
45
|
-
const SCRIPT = String.raw `
|
|
46
|
-
param([string]$Mode = "list", [string]$Handle = "", [string]$Out = "", [string]$Desktop = "", [string]$Hidden = "", [int]$Owner = 0)
|
|
47
|
-
$ErrorActionPreference = "Stop"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
using System
|
|
56
|
-
using System.
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
[DllImport("user32.dll"
|
|
68
|
-
[DllImport("user32.dll")] static extern bool
|
|
69
|
-
[DllImport("user32.dll")] static extern bool
|
|
70
|
-
[DllImport("user32.dll")] static extern
|
|
71
|
-
[DllImport("user32.dll")]
|
|
72
|
-
[DllImport("user32.dll")] static extern
|
|
73
|
-
[DllImport("user32.dll")] static extern
|
|
74
|
-
[DllImport("
|
|
75
|
-
[DllImport("
|
|
76
|
-
|
|
77
|
-
[
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
[
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
public static
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
//
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
return
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
$
|
|
230
|
-
$
|
|
231
|
-
$
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if ($
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if ($
|
|
255
|
-
exit
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
exit
|
|
45
|
+
const SCRIPT = String.raw `
|
|
46
|
+
param([string]$Mode = "list", [string]$Handle = "", [string]$Out = "", [string]$Desktop = "", [string]$Hidden = "", [int]$Owner = 0)
|
|
47
|
+
$ErrorActionPreference = "Stop"
|
|
48
|
+
# The window list is read back as UTF-8. Without this the console's own code page is used, and every title with a
|
|
49
|
+
# dash, an accent or a CJK character reached the model as "?" (real sessions: "Microsoft? Edge", "? Greeting"),
|
|
50
|
+
# which made the title impossible to copy back into a call.
|
|
51
|
+
try { [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false) } catch {}
|
|
52
|
+
Add-Type -AssemblyName System.Drawing
|
|
53
|
+
|
|
54
|
+
Add-Type -ReferencedAssemblies System.Drawing -TypeDefinition @"
|
|
55
|
+
using System;
|
|
56
|
+
using System.Collections.Generic;
|
|
57
|
+
using System.Drawing;
|
|
58
|
+
using System.Drawing.Imaging;
|
|
59
|
+
using System.Runtime.InteropServices;
|
|
60
|
+
using System.Text;
|
|
61
|
+
|
|
62
|
+
public static class MwCapture {
|
|
63
|
+
// The processes this one runs inside (the terminal, its console host, the app hosting it).
|
|
64
|
+
// Their windows are marked "host" in the list, so the caller can tell them from the app under test.
|
|
65
|
+
public static HashSet<uint> HostPids = new HashSet<uint>();
|
|
66
|
+
delegate bool EnumProc(IntPtr hWnd, IntPtr lParam);
|
|
67
|
+
[DllImport("user32.dll")] static extern bool EnumWindows(EnumProc cb, IntPtr l);
|
|
68
|
+
[DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
|
|
69
|
+
[DllImport("user32.dll")] static extern bool IsIconic(IntPtr h);
|
|
70
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetWindowTextLength(IntPtr h);
|
|
71
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)] static extern int GetWindowText(IntPtr h, StringBuilder s, int n);
|
|
72
|
+
[DllImport("user32.dll")] static extern bool PrintWindow(IntPtr h, IntPtr hdc, uint flags);
|
|
73
|
+
[DllImport("user32.dll")] static extern bool SetProcessDPIAware();
|
|
74
|
+
[DllImport("user32.dll")] static extern bool GetWindowRect(IntPtr h, out RECT r);
|
|
75
|
+
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
|
|
76
|
+
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
|
|
77
|
+
[DllImport("user32.dll")] static extern int GetWindowLong(IntPtr h, int index);
|
|
78
|
+
[DllImport("dwmapi.dll")] static extern int DwmGetWindowAttribute(IntPtr h, int attr, out RECT r, int size);
|
|
79
|
+
[DllImport("dwmapi.dll", EntryPoint = "DwmGetWindowAttribute")] static extern int DwmGetIntAttribute(IntPtr h, int attr, out int v, int size);
|
|
80
|
+
|
|
81
|
+
[StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left, Top, Right, Bottom; }
|
|
82
|
+
|
|
83
|
+
public static void Dpi() { SetProcessDPIAware(); }
|
|
84
|
+
|
|
85
|
+
[DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow();
|
|
86
|
+
[DllImport("user32.dll")] static extern IntPtr GetAncestor(IntPtr h, uint flags);
|
|
87
|
+
|
|
88
|
+
// The window the console this process is attached to is drawn in. In Windows Terminal the console
|
|
89
|
+
// window is a hidden stand-in owned by the real top-level window, so the owner is what is returned.
|
|
90
|
+
// Empty when there is no console (the desktop app, a service).
|
|
91
|
+
public static string HostWindow() {
|
|
92
|
+
IntPtr c = GetConsoleWindow();
|
|
93
|
+
if (c == IntPtr.Zero) return "";
|
|
94
|
+
IntPtr root = GetAncestor(c, 3 /* GA_ROOTOWNER */);
|
|
95
|
+
return (root == IntPtr.Zero ? c : root).ToInt64().ToString();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// A DWM-cloaked window passes IsWindowVisible but is not actually on screen — the
|
|
99
|
+
// invisible UWP and host windows that would otherwise flood the list. Any failure to
|
|
100
|
+
// read the attribute is treated as not-cloaked, so a window is never dropped on error.
|
|
101
|
+
static bool Cloaked(IntPtr h) {
|
|
102
|
+
int v;
|
|
103
|
+
return DwmGetIntAttribute(h, 14 /* DWMWA_CLOAKED */, out v, sizeof(int)) == 0 && v != 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// The Shell's own "is this an Alt-Tab window" test: a tool window is a palette or
|
|
107
|
+
// tray surface and is never what "the app" means, unless it also asks for the taskbar.
|
|
108
|
+
static bool AltTabWorthy(IntPtr h) {
|
|
109
|
+
int ex = GetWindowLong(h, -20 /* GWL_EXSTYLE */);
|
|
110
|
+
bool tool = (ex & 0x00000080) != 0; // WS_EX_TOOLWINDOW
|
|
111
|
+
bool app = (ex & 0x00040000) != 0; // WS_EX_APPWINDOW
|
|
112
|
+
return !tool || app;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// The window's process name, for a window that has no title of its own. Wrapped
|
|
116
|
+
// because the process can exit between the enum and the lookup.
|
|
117
|
+
static string ProcName(IntPtr h) {
|
|
118
|
+
try {
|
|
119
|
+
uint pid;
|
|
120
|
+
GetWindowThreadProcessId(h, out pid);
|
|
121
|
+
if (pid == 0) return "";
|
|
122
|
+
using (var p = System.Diagnostics.Process.GetProcessById((int)pid)) return p.ProcessName;
|
|
123
|
+
} catch { return ""; }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// DWMWA_EXTENDED_FRAME_BOUNDS. GetWindowRect includes an invisible border on
|
|
127
|
+
// Windows 10+, so it is the fallback rather than the first choice.
|
|
128
|
+
static bool Bounds(IntPtr h, out RECT r) {
|
|
129
|
+
if (DwmGetWindowAttribute(h, 9, out r, Marshal.SizeOf(typeof(RECT))) == 0
|
|
130
|
+
&& r.Right > r.Left && r.Bottom > r.Top) return true;
|
|
131
|
+
return GetWindowRect(h, out r);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// The hidden desktop's windows are marked, so a capture is sent back there.
|
|
135
|
+
public static string ListOn(string desk) {
|
|
136
|
+
return MwDesk.On(desk, () => string.Join("\n", List("${HIDDEN_MARK}").ToArray()));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public static List<string> List(string mark) {
|
|
140
|
+
var found = new List<string>();
|
|
141
|
+
IntPtr fg = GetForegroundWindow();
|
|
142
|
+
EnumWindows(delegate(IntPtr h, IntPtr l) {
|
|
143
|
+
if (!IsWindowVisible(h) || IsIconic(h)) return true;
|
|
144
|
+
if (Cloaked(h) || !AltTabWorthy(h)) return true;
|
|
145
|
+
RECT r;
|
|
146
|
+
if (!Bounds(h, out r)) return true;
|
|
147
|
+
// Tool windows and tray hosts are real but never what anyone means.
|
|
148
|
+
if (r.Right - r.Left < 120 || r.Bottom - r.Top < 120) return true;
|
|
149
|
+
int len = GetWindowTextLength(h);
|
|
150
|
+
string title = "";
|
|
151
|
+
if (len > 0) {
|
|
152
|
+
var sb = new StringBuilder(len + 1);
|
|
153
|
+
GetWindowText(h, sb, sb.Capacity);
|
|
154
|
+
title = sb.ToString().Trim();
|
|
155
|
+
}
|
|
156
|
+
// An empty title is NOT a reason to drop the window. A custom title bar
|
|
157
|
+
// (Tauri or Electron with decorations off) leaves the OS title blank, as does
|
|
158
|
+
// an app whose web content has not set document.title yet — and dropping it
|
|
159
|
+
// makes a window the user is plainly looking at impossible to capture, by name
|
|
160
|
+
// OR as the foreground. Label it by its process so it stays nameable.
|
|
161
|
+
if (title.Length == 0) {
|
|
162
|
+
string pn = ProcName(h);
|
|
163
|
+
title = pn.Length > 0 ? pn : "(untitled window)";
|
|
164
|
+
}
|
|
165
|
+
// The leading marker is how the caller knows which window the user is
|
|
166
|
+
// actually looking at, so it can name it when asking permission.
|
|
167
|
+
uint wpid; GetWindowThreadProcessId(h, out wpid);
|
|
168
|
+
string hostCol = mark.Length == 0 && HostPids.Contains(wpid) ? "\thost" : "";
|
|
169
|
+
found.Add((h == fg && mark.Length == 0 ? "*" : "-") + mark + h.ToInt64().ToString() + "\t" + title + hostCol);
|
|
170
|
+
return true;
|
|
171
|
+
}, IntPtr.Zero);
|
|
172
|
+
return found;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
public static string CaptureOn(string desk, IntPtr h, string path) {
|
|
176
|
+
return MwDesk.On(desk, () => Capture(h, path, string.IsNullOrEmpty(desk)));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// screen: whether a blank PrintWindow may fall back to copying the screen. Never for a
|
|
180
|
+
// window on the hidden desktop: the screen is the USER's, and that window is not on it.
|
|
181
|
+
public static string Capture(IntPtr h, string path, bool screen) {
|
|
182
|
+
RECT r;
|
|
183
|
+
if (!Bounds(h, out r)) return "ERR could not measure the window";
|
|
184
|
+
int w = r.Right - r.Left, ht = r.Bottom - r.Top;
|
|
185
|
+
if (w <= 0 || ht <= 0) return "ERR the window has no visible area";
|
|
186
|
+
using (var bmp = new Bitmap(w, ht)) {
|
|
187
|
+
bool drew = false;
|
|
188
|
+
using (var g = Graphics.FromImage(bmp)) {
|
|
189
|
+
IntPtr hdc = g.GetHdc();
|
|
190
|
+
drew = PrintWindow(h, hdc, 2); // PW_RENDERFULLCONTENT
|
|
191
|
+
g.ReleaseHdc(hdc);
|
|
192
|
+
}
|
|
193
|
+
if (!drew || Blank(bmp)) {
|
|
194
|
+
if (!screen) return "ERR the window drew nothing to capture";
|
|
195
|
+
using (var g = Graphics.FromImage(bmp)) {
|
|
196
|
+
g.CopyFromScreen(r.Left, r.Top, 0, 0, new Size(w, ht));
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
bmp.Save(path, ImageFormat.Png);
|
|
200
|
+
return "OK " + w + " " + ht;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// PrintWindow can report success and draw nothing. Sampling three corners of a
|
|
205
|
+
// fully transparent bitmap is enough to tell that apart from a real capture.
|
|
206
|
+
static bool Blank(Bitmap b) {
|
|
207
|
+
if (b.Width < 4 || b.Height < 4) return false;
|
|
208
|
+
return b.GetPixel(1, 1).A == 0
|
|
209
|
+
&& b.GetPixel(b.Width / 2, b.Height / 2).A == 0
|
|
210
|
+
&& b.GetPixel(b.Width - 2, b.Height - 2).A == 0;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
${DESK_CS}
|
|
214
|
+
"@
|
|
215
|
+
|
|
216
|
+
# Before any measurement, or every rectangle is in the wrong coordinate space.
|
|
217
|
+
[MwCapture]::Dpi() | Out-Null
|
|
218
|
+
|
|
219
|
+
if ($Mode -eq "host") {
|
|
220
|
+
Write-Output ([MwCapture]::HostWindow())
|
|
221
|
+
exit 0
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if ($Mode -eq "list") {
|
|
225
|
+
# Which windows are the one this process runs in: walk up from it, stopping at the shell that
|
|
226
|
+
# started the whole session (the desktop, services), and take each console host that belongs to
|
|
227
|
+
# one of those on the way. Every process passed may own the window.
|
|
228
|
+
if ($Owner -gt 0) {
|
|
229
|
+
$procs = Get-CimInstance Win32_Process -Property ProcessId, ParentProcessId, Name
|
|
230
|
+
$parent = @{}
|
|
231
|
+
$name = @{}
|
|
232
|
+
foreach ($p in $procs) { $parent[[int]$p.ProcessId] = [int]$p.ParentProcessId; $name[[int]$p.ProcessId] = ([string]$p.Name).ToLower() }
|
|
233
|
+
$stop = @("explorer.exe", "services.exe", "wininit.exe", "winlogon.exe", "csrss.exe", "svchost.exe", "system")
|
|
234
|
+
$seen = @{}
|
|
235
|
+
$at = $Owner
|
|
236
|
+
while ($at -gt 0 -and -not $seen.ContainsKey($at)) {
|
|
237
|
+
$seen[$at] = $true
|
|
238
|
+
if ($stop -contains $name[$at]) { break }
|
|
239
|
+
[void][MwCapture]::HostPids.Add([uint32]$at)
|
|
240
|
+
$at = $parent[$at]
|
|
241
|
+
}
|
|
242
|
+
foreach ($p in $procs) {
|
|
243
|
+
$n = ([string]$p.Name).ToLower()
|
|
244
|
+
if (($n -eq "conhost.exe" -or $n -eq "openconsole.exe") -and [MwCapture]::HostPids.Contains([uint32]$p.ParentProcessId)) { [void][MwCapture]::HostPids.Add([uint32]$p.ProcessId) }
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
[MwCapture]::List("") | ForEach-Object { Write-Output $_ }
|
|
248
|
+
# The windows of apps started for testing, which are never on the screen.
|
|
249
|
+
if ($Hidden -and [MwDesk]::Exists($Hidden)) { Write-Output ([MwCapture]::ListOn($Hidden)) }
|
|
250
|
+
exit 0
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
if ($Mode -eq "capture") {
|
|
254
|
+
$h = if ($Handle -eq "foreground") { [MwCapture]::GetForegroundWindow() } else { [IntPtr][Int64]$Handle }
|
|
255
|
+
if ($h -eq [IntPtr]::Zero) { Write-Output "ERR no such window"; exit 1 }
|
|
256
|
+
$r = [MwCapture]::CaptureOn($Desktop, $h, $Out)
|
|
257
|
+
Write-Output $r
|
|
258
|
+
if ($r.StartsWith("ERR")) { exit 1 }
|
|
259
|
+
exit 0
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
Write-Output "ERR unknown mode"
|
|
263
|
+
exit 1
|
|
260
264
|
`;
|
|
261
265
|
let scriptPath = null;
|
|
262
266
|
/** Write the capture script to a temp file once per process. */
|
|
@@ -284,7 +288,8 @@ async function runScript(args, signal, shareConsole = false) {
|
|
|
284
288
|
}, PS_TIMEOUT_MS);
|
|
285
289
|
const onAbort = () => child.kill();
|
|
286
290
|
signal?.addEventListener("abort", onAbort, { once: true });
|
|
287
|
-
child.stdout.
|
|
291
|
+
child.stdout.setEncoding("utf8"); // a character split across two chunks is joined, not broken
|
|
292
|
+
child.stdout.on("data", (d) => (out += d));
|
|
288
293
|
child.stderr.on("data", (d) => (err += d.toString()));
|
|
289
294
|
child.on("error", (e) => {
|
|
290
295
|
clearTimeout(timer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshotWin.js","sourceRoot":"","sources":["../../src/tools/screenshotWin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAiBzF,MAAM,aAAa,GAAG,MAAM,CAAC;AAE7B,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"screenshotWin.js","sourceRoot":"","sources":["../../src/tools/screenshotWin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EA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E,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;IACxH,MAAM,KAAK,GAAG,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,+BAA+B,CAAC,CAAC;IAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/D,CAAC"}
|
package/dist/tools/search.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { FULL_DETAIL_MAX, capLines } from "./detail.js";
|
|
1
2
|
import { grepDef, GREP_MAX_OUTPUT_LINES } from "./grep.js";
|
|
2
3
|
import { globDef, GLOB_MAX_RESULTS } from "./glob.js";
|
|
3
4
|
import { listDir, MAX_ENTRIES } from "./listDir.js";
|
|
@@ -115,7 +116,9 @@ export const search = {
|
|
|
115
116
|
// Quiet is applied HERE, on every path including errors, rather than inside either
|
|
116
117
|
// implementation. One tool, one display policy — and a failed search is exactly the
|
|
117
118
|
// row most likely to creep back onto the screen if each branch decided for itself.
|
|
118
|
-
|
|
119
|
+
// The words behind the row's click: what the search printed, which the model got whole.
|
|
120
|
+
const printed = result.isError || result.detail ? undefined : capLines(result.output.split("\n"), FULL_DETAIL_MAX);
|
|
121
|
+
return { ...result, quiet: true, ...(printed ? { detail: printed, detailKind: "text" } : {}) };
|
|
119
122
|
},
|
|
120
123
|
};
|
|
121
124
|
//# sourceMappingURL=search.js.map
|
package/dist/tools/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/tools/search.ts"],"names":[],"mappings":"AAkCA,OAAO,EAAE,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAC3D,O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,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;QAEhF,mFAAmF;QACnF,oFAAoF;QACpF,mFAAmF;QACnF,wFAAwF;QACxF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,eAAe,CAAC,CAAC;QACnH,OAAO,EAAE,GAAG,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;IAC1G,CAAC;CACF,CAAC"}
|
package/dist/tools/shellTools.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { relativize } from "./paths.js";
|
|
2
2
|
import { MAX_READ_CHARS } from "./backgroundShells.js";
|
|
3
3
|
import { fail, failQuietly } from "./results.js";
|
|
4
|
+
import { COMMAND_OUTPUT_NOTE, commandReachesOutside } from "./untrusted.js";
|
|
4
5
|
/**
|
|
5
6
|
* One read-only tool at two levels of specificity: no `id` lists, an `id` reads.
|
|
6
7
|
*
|
|
@@ -19,24 +20,12 @@ import { fail, failQuietly } from "./results.js";
|
|
|
19
20
|
export const shellsTool = {
|
|
20
21
|
name: "shells",
|
|
21
22
|
readOnly: true,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
* every uncached request of every session — including the many that never background
|
|
29
|
-
* anything.
|
|
30
|
-
*
|
|
31
|
-
* The condition is `list()`, which retains FINISHED shells, and not `running()`.
|
|
32
|
-
* That is deliberate and is about the prompt cache rather than about correctness: the
|
|
33
|
-
* tool list is part of the cached prefix, so a condition that flipped off again when
|
|
34
|
-
* the last process exited would invalidate the whole prefix twice per shell instead
|
|
35
|
-
* of once per session. `list()` only ever goes from empty to non-empty, so the cost
|
|
36
|
-
* is a single rebuild the first time a shell appears. Reading a finished shell's
|
|
37
|
-
* output is a real use anyway.
|
|
38
|
-
*/
|
|
39
|
-
relevantWhen: (ctx) => (ctx.backgroundShells?.list().length ?? 0) > 0,
|
|
23
|
+
// Always advertised. The tool list is the first thing a provider hashes for its prompt cache,
|
|
24
|
+
// so a tool that appears when the first background shell starts re-bills the system prompt
|
|
25
|
+
// and the whole conversation at full price at that moment. Recorded sessions lost 35k
|
|
26
|
+
// tokens per occurrence on average, and about half of them start a background command.
|
|
27
|
+
// This tool and `kill_shell` weigh roughly 600 tokens, read from the cache after the first
|
|
28
|
+
// request, which costs far less than one rebuild.
|
|
40
29
|
// The description never mentioned polling, while the tool itself pushes a strong
|
|
41
30
|
// don't-poll nudge at runtime; the two now agree. It also never mentioned either cap,
|
|
42
31
|
// and the buffer one matters: a chatty process can roll output out of the retained
|
|
@@ -80,8 +69,13 @@ export const shellsTool = {
|
|
|
80
69
|
if (id === null)
|
|
81
70
|
return failQuietly("`id` must be a shell number.");
|
|
82
71
|
const res = await mgr.read(id);
|
|
83
|
-
if (!res)
|
|
84
|
-
|
|
72
|
+
if (!res) {
|
|
73
|
+
// Say what DOES exist: the model usually has a stale number (shells do not survive a restart or /continue).
|
|
74
|
+
const known = mgr.list();
|
|
75
|
+
return fail(known.length === 0
|
|
76
|
+
? `no background shell #${id}. None exist in this session (they do not survive a restart or /continue), so start the command again with run_in_background.`
|
|
77
|
+
: `no background shell #${id}. The shells that exist: ${known.map((s) => `#${s.id}`).join(", ")}.`);
|
|
78
|
+
}
|
|
85
79
|
const head = statusLine(res.info);
|
|
86
80
|
const body = res.chunk.trim();
|
|
87
81
|
// If it's still running, stop the model polling: the event is pushed to it, so a
|
|
@@ -99,7 +93,8 @@ export const shellsTool = {
|
|
|
99
93
|
: "\n[Still running. You'll be notified automatically when it finishes — do NOT poll again. " +
|
|
100
94
|
"End your turn and let the user know you'll report when it's done.]";
|
|
101
95
|
return {
|
|
102
|
-
output: (body ? `${head}\n${body}` : `${head}\n(no new output)`) +
|
|
96
|
+
output: (body ? `${head}\n${body}${commandReachesOutside(res.info.command) ? `\n${COMMAND_OUTPUT_NOTE}` : ""}` : `${head}\n(no new output)`) +
|
|
97
|
+
nudge,
|
|
103
98
|
summary: `shell #${id} (${res.info.status})`,
|
|
104
99
|
};
|
|
105
100
|
},
|
|
@@ -107,10 +102,7 @@ export const shellsTool = {
|
|
|
107
102
|
export const killShell = {
|
|
108
103
|
name: "kill_shell",
|
|
109
104
|
readOnly: false,
|
|
110
|
-
|
|
111
|
-
* than `running()` so the tool list latches once per session instead of flipping
|
|
112
|
-
* with every process that starts and stops. */
|
|
113
|
-
relevantWhen: (ctx) => (ctx.backgroundShells?.list().length ?? 0) > 0,
|
|
105
|
+
// Always advertised, for the same reason as `shells`.
|
|
114
106
|
description: "Stop a running background shell by id. Kills the whole process tree, not just the " +
|
|
115
107
|
"shell, so a dev server that spawned its own children goes down with it. " +
|
|
116
108
|
"It records that YOU stopped it, which is what later lets the status be reported as " +
|