Files
rea/src/windows/WindowsWindowCaptureWorker.ts
T
N0zoM1z0 bb9df948cc fix(windows): preserve capture input, environment and frame bounds
Send bounded UTF-8 requests through supervised stdin rather than expanded Windows command lines. Carry the selected provider environment to the helper and reject changed client dimensions after rendering.

Update the effects audit and test real command input delivery, blocked readers, early close, long request encoding and provider environment propagation. Real Windows non-admin CLI/MCP and Character Map validation passed for the stdin transport.
2026-10-15 22:37:29 +08:00

55 lines
1.8 KiB
TypeScript

import { requireWindowsWindowCaptureAuthority } from "./WindowsNativeLoader.js";
import {
nativeWindowsCaptureSchema,
WINDOWS_CAPTURE_REQUEST_BYTES,
windowsCaptureFailureSchema,
windowsCaptureRequestSchema,
} from "./WindowsWindowCaptureProtocol.js";
// PrintWindow is synchronous and has no timeout API. Only this owned helper
// calls it; the parent can terminate its Job Object without blocking the server
// or leaving a detached native thread/surface in the long-lived REA process.
try {
const chunks: Buffer[] = [];
let bytes = 0;
for await (const chunk of process.stdin) {
if (!Buffer.isBuffer(chunk))
throw new Error("Invalid capture request bytes");
bytes += chunk.byteLength;
if (bytes > WINDOWS_CAPTURE_REQUEST_BYTES)
throw new Error("Capture request exceeds its protocol byte limit");
chunks.push(chunk);
}
const encoded = new TextDecoder("utf-8", { fatal: true }).decode(
Buffer.concat(chunks, bytes),
);
const value: unknown = JSON.parse(encoded);
const input = windowsCaptureRequestSchema.parse(value);
const authority = requireWindowsWindowCaptureAuthority();
const { png, ...capture } = nativeWindowsCaptureSchema.parse(
authority.call("capture_window_png", [
input.pid,
input.window_handle,
input.max_dimension,
input.target_path,
input.target_sha256,
input.target_file_identity,
]),
);
process.stdout.write(
JSON.stringify({
ok: true,
capture: { ...capture, png_base64: png.toString("base64") },
}),
);
} catch (cause: unknown) {
const failure = windowsCaptureFailureSchema.safeParse(cause);
process.stdout.write(
JSON.stringify({
ok: false,
message: cause instanceof Error ? cause.message : String(cause),
failure: failure.success ? failure.data : null,
}),
);
}