feat: manage task process lifetimes and preserve turn history

This commit is contained in:
Ed1s0nZ
2026-09-16 17:52:58 +08:00
parent fd1c13a43d
commit f7882be546
54 changed files with 3650 additions and 330 deletions
+14 -1
View File
@@ -3,9 +3,11 @@
package security
import (
"context"
"os/exec"
"strconv"
"syscall"
"time"
)
func prepareShellCmdSession(cmd *exec.Cmd) error {
@@ -29,7 +31,9 @@ func terminateProcessGroup(rootPID int, cmd *exec.Cmd) {
if pid <= 0 {
return
}
tk := exec.Command("taskkill", "/F", "/T", "/PID", strconv.Itoa(pid))
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
tk := exec.CommandContext(ctx, "taskkill", "/F", "/T", "/PID", strconv.Itoa(pid))
if err := tk.Run(); err != nil {
if cmd != nil && cmd.Process != nil {
_ = cmd.Process.Kill()
@@ -41,3 +45,12 @@ func terminateProcessGroup(rootPID int, cmd *exec.Cmd) {
func terminateCmdTree(cmd *exec.Cmd) {
terminateProcessGroup(0, cmd)
}
func stopProcessGroup(pid int, cmd *exec.Cmd) {
// Windows has no portable SIGTERM equivalent for arbitrary console jobs.
terminateProcessGroup(pid, cmd)
}
// Windows taskkill /T is best effort; unlike a Unix PGID it has no persistent
// group handle to query after the root exits. Job Objects are needed for that.
func processGroupExists(pid int) bool { return false }