singularity-forge/patches/@mariozechner+pi-coding-agent+0.57.1.patch
Lex Christopherson 58ca04e7de fix: restore Windows VT input after child processes exit (#41)
Child processes (Git Bash/MSYS2) strip the ENABLE_VIRTUAL_TERMINAL_INPUT
flag from the shared stdin console handle, corrupting terminal input.
Re-enable the flag after every child process exits in bash.js, bg-shell,
and cache FFI handles in pi-tui for cheap repeated calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 11:24:44 -06:00

48 lines
2.3 KiB
Diff

diff --git a/node_modules/@mariozechner/pi-coding-agent/dist/core/tools/bash.js b/node_modules/@mariozechner/pi-coding-agent/dist/core/tools/bash.js
index 27fe820..68f277f 100644
--- a/node_modules/@mariozechner/pi-coding-agent/dist/core/tools/bash.js
+++ b/node_modules/@mariozechner/pi-coding-agent/dist/core/tools/bash.js
@@ -1,11 +1,35 @@
import { randomBytes } from "node:crypto";
import { createWriteStream, existsSync } from "node:fs";
+import { createRequire } from "node:module";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Type } from "@sinclair/typebox";
import { spawn } from "child_process";
import { getShellConfig, getShellEnv, killProcessTree } from "../../utils/shell.js";
import { DEFAULT_MAX_BYTES, DEFAULT_MAX_LINES, formatSize, truncateTail } from "./truncate.js";
+// Cached Win32 FFI handles for restoring VT input after child processes
+let _vtHandles = null;
+function restoreWindowsVTInput() {
+ if (process.platform !== "win32") return;
+ try {
+ if (!_vtHandles) {
+ const cjsRequire = createRequire(import.meta.url);
+ const koffi = cjsRequire("koffi");
+ const k32 = koffi.load("kernel32.dll");
+ const GetStdHandle = k32.func("void* __stdcall GetStdHandle(int)");
+ const GetConsoleMode = k32.func("bool __stdcall GetConsoleMode(void*, _Out_ uint32_t*)");
+ const SetConsoleMode = k32.func("bool __stdcall SetConsoleMode(void*, uint32_t)");
+ const handle = GetStdHandle(-10);
+ _vtHandles = { GetConsoleMode, SetConsoleMode, handle };
+ }
+ const ENABLE_VIRTUAL_TERMINAL_INPUT = 0x0200;
+ const mode = new Uint32Array(1);
+ _vtHandles.GetConsoleMode(_vtHandles.handle, mode);
+ if (!(mode[0] & ENABLE_VIRTUAL_TERMINAL_INPUT)) {
+ _vtHandles.SetConsoleMode(_vtHandles.handle, mode[0] | ENABLE_VIRTUAL_TERMINAL_INPUT);
+ }
+ } catch { }
+}
/**
* Generate a unique temp file path for bash output
*/
@@ -76,6 +100,7 @@ const defaultBashOperations = {
}
// Handle process exit
child.on("close", (code) => {
+ restoreWindowsVTInput();
if (timeoutHandle)
clearTimeout(timeoutHandle);
if (signal)