feat: add background bash sessions

This commit is contained in:
Peter Steinberger
2025-12-25 00:25:11 +00:00
parent 4eecb6841a
commit 3c6432da1f
10 changed files with 1169 additions and 25 deletions

41
src/agents/shell-utils.ts Normal file
View File

@@ -0,0 +1,41 @@
import { spawn } from "node:child_process";
export function getShellConfig(): { shell: string; args: string[] } {
if (process.platform === "win32") {
const shell = process.env.COMSPEC?.trim() || "cmd.exe";
return { shell, args: ["/d", "/s", "/c"] };
}
const shell = process.env.SHELL?.trim() || "sh";
return { shell, args: ["-c"] };
}
export function sanitizeBinaryOutput(text: string): string {
return text
.replace(/[\p{Format}\p{Surrogate}]/gu, "")
.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "");
}
export function killProcessTree(pid: number): void {
if (process.platform === "win32") {
try {
spawn("taskkill", ["/F", "/T", "/PID", String(pid)], {
stdio: "ignore",
detached: true,
});
} catch {
// ignore errors if taskkill fails
}
return;
}
try {
process.kill(-pid, "SIGKILL");
} catch {
try {
process.kill(pid, "SIGKILL");
} catch {
// process already dead
}
}
}