xonecas.io
64875
Mc

mini-coder / commit 59bdcd4

fix: preserve stdin raw mode after shell tool execution

Sean2026-03-01 59bdcd4fc52a5b3abbf537d77a67084d8b7fdf70 parent 316347a

2 files changed

src/tools/shell.test.ts+42−0
@@ -0,0 +1,42 @@
1+import { describe, expect, it } from "bun:test";
2+import { shellTool } from "./shell.ts";
3+
4+describe("shellTool", () => {
5+ it("preserves stdin raw mode if it was enabled", async () => {
6+ // Only run this test if stdin is a TTY, otherwise raw mode concepts don't apply.
7+ if (!process.stdin.isTTY) {
8+ console.log("Skipping raw mode test because stdin is not a TTY");
9+ return;
10+ }
11+
12+ // Set raw mode to true initially
13+ process.stdin.setRawMode(true);
14+ expect(process.stdin.isRaw).toBe(true);
15+
16+ // Execute a quick command
17+ await shellTool.execute({ command: "echo hello" });
18+
19+ // Verify it restored raw mode
20+ expect(process.stdin.isRaw).toBe(true);
21+
22+ // Clean up
23+ process.stdin.setRawMode(false);
24+ });
25+
26+ it("leaves raw mode disabled if it was disabled", async () => {
27+ if (!process.stdin.isTTY) {
28+ console.log("Skipping raw mode test because stdin is not a TTY");
29+ return;
30+ }
31+
32+ // Ensure raw mode is false
33+ process.stdin.setRawMode(false);
34+ expect(process.stdin.isRaw).toBe(false);
35+
36+ // Execute a quick command
37+ await shellTool.execute({ command: "echo hello" });
38+
39+ // Verify it stayed false
40+ expect(process.stdin.isRaw).toBe(false);
41+ });
42+});
src/tools/shell.ts+9−0
@@ -48,6 +48,8 @@ export const shellTool: ToolDef<ShellInput, ShellOutput> = {
4848
4949 let timedOut = false;
5050
51+ const wasRaw = process.stdin.isTTY ? process.stdin.isRaw : false;
52+
5153 const proc = Bun.spawn(["bash", "-c", input.command], {
5254 cwd,
5355 env,
@@ -115,6 +117,13 @@ export const shellTool: ToolDef<ShellInput, ShellOutput> = {
115117 // Ensure the terminal is in a sane state if the spawn caused any
116118 // raw-mode or cursor-visibility side-effects
117119 restoreTerminal();
120+ if (wasRaw) {
121+ try {
122+ process.stdin.setRawMode(true);
123+ } catch {
124+ /* ignore */
125+ }
126+ }
118127 }
119128
120129 return {