Repository navigation
Description
Summary
prepareCapture restores a minimized target window (and may pin it on top) before confirmCapture asks the user. A declined or timed-out capture still un-minimizes the window, and nothing re-minimizes it after a successful capture either.
Where
src/tools/screenshot.ts:67-79src/tools/findText.ts:103-114src/tools/waitForChange.ts:114-132src/tools/startRecording.ts:606-648src/utils/resolveTarget.ts:107-122src/utils/windowControl.ts:54-61src/tools/screenshot.ts:68-79src/tools/waitForChange.ts:114-136src/tools/startRecording.ts:606-613src/tools/startRecording.ts:635-649src/utils/resolveTarget.ts:109-118
Details
prepareCapture calls restoreWindow(err.hwnd, ...) when the target window is minimized (resolveTarget.ts:110-112). The restore script runs ShowWindow(SW_SHOWNOACTIVATE) and SetWindowPos(HWND_BOTTOM) (windowControl.ts:58). Every capture tool calls prepareCapture first and asks consent only afterwards, for example screenshot:
const prep = await prepareCapture(args.target, { ..., mode: "still", signal: extra.signal });
...
await confirmCapture(server, `Take a screenshot of ${describeTarget(args.target, window)}, saved to ${output}?`, extra.signal);findText, waitForChange and startRecording (prepareStart: prepareCapture at 606, confirmCapture at 648) use the same order. Nothing in src minimizes the window again after the capture (no SW_MINIMIZE / SW_SHOWMINNOACTIVE anywhere). The consent text also doesn't say that a window will be restored or pinned on top.
Also: A minimized target is restored before the capture is approved
Each capture tool calls prepareCapture first, and prepareCapture restores a minimized window (restored = await restoreWindow(err.hwnd, opts.signal)). Only after that does the tool call confirmCapture (screenshot.ts:79, findText.ts:114, waitForChange.ts:132, startRecording.ts:648). With consent enabled (#222) and the person declining, or the elicitation being cancelled, the window has already been un-minimized and stays that way. The tool then returns an error and nothing undoes the restore.
Steps: With a client that supports elicitation (SCREENCAST_CONFIRM_CAPTURE auto or always, consent.ts:17-31), minimize Notepad, call screenshot { target: "window:Notepad" } and decline the prompt. The call fails as declined, and Notepad is no longer minimized.
Impact
The consent design (#222, consent.ts:1-5) is meant to keep a prompt-injected call from acting on the desktop without the user. Here a declined or timed-out capture still changes the desktop: a window the user deliberately minimized (often one they wanted out of sight) comes back un-minimized, possibly visible around other windows and in any later full-screen capture or screen share. It stays that way after a successful capture too.
Steps to reproduce
Minimize a window titled "Bank". Call screenshot { target: "window:Bank" } in a client with elicitation and decline. The response says nothing was captured, but the Bank window is now restored on the desktop.
Suggested fix
Split prepareCapture so the window is selected (and its minimized state detected) without side effects, ask consent (mentioning "restore the minimized window" and "keep it on top" when they apply), then restore and pin. Record restored and re-minimize (SW_SHOWMINNOACTIVE) when the still or the recording ends.
For "A minimized target is restored before the capture is approved": Resolve without restoring first (catch MinimizedWindowError and describe the target), ask for consent, then restore and re-resolve. Or re-minimize the window (ShowWindow SW_MINIMIZE) when consent is refused.
Acceptance criteria
- Selecting the window and detecting that it is minimized has no side effects; the restore and pin happen only after consent
- The consent prompt says when a minimized window will be restored or kept on top
- A window the server restored is minimized again when the still or the recording ends
- Declining consent leaves the desktop unchanged (test with a stubbed restore)
Getting started
- Relevant files:
src/tools/screenshot.ts,src/tools/findText.ts,src/tools/waitForChange.ts,src/tools/startRecording.ts - Run tests:
npm test(alsonpm run typecheckandnpm run lint); see CONTRIBUTING.md - If you change a tool's schema or description, run
npm run docs
Filed by repo-audit/full-audit at f0e5ebd. Severity: medium. Effort: M. audit-key: privacy|src/utils/resolveTarget.ts|prepareCapture
Activity
TMHSDigital commentedon Nov 29, 2026
Fixed in 36dfd39: prepareCapture gained a beforeRestore hook that runs before a minimized window is restored. prepareWithConsent asks consent there (the prompt says the window will be restored, then minimized again), else once the target resolved. screenshot, find_text, wait_for_change and start_recording use it, and call minimizeRestored (SW_SHOWMINNOACTIVE) when the capture ends or fails; for a recording it runs as a session finalizer. Verified with tests using a stubbed restore and minimize: declining leaves the window minimized, approving restores and later minimizes, and a non-minimized window is asked once and never minimized. Plus the full suite, typecheck, lint and docs:check.