procutil

package
v0.6.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package procutil abstracts the per-OS process plumbing the agent needs:

  • Detach marks a child so it neither dies with the turn nor receives the terminal's ctrl-c, and so killing it takes its whole tree.
  • Alive reports whether a pid is still running (signal 0 on unix, OpenProcess + exit-code query on Windows, where os.FindProcess always succeeds).
  • KillTree stops a process and everything it started (negative-pid group kill on unix, taskkill /T on Windows where process-group semantics do not exist and a Job Object handle would not survive the turn boundary).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alive

func Alive(pid int) bool

Alive reports whether pid is still running.

func ConsoleName

func ConsoleName() string

ConsoleName is the path OpenConsole opens, for error messages.

func Detach

func Detach(cmd *exec.Cmd)

Detach detaches cmd so it outlives the turn's iterations and can be killed as a tree. It must be called before cmd.Start.

func DetachProcessGroup

func DetachProcessGroup(cmd *exec.Cmd)

DetachProcessGroup marks cmd as its own process group (Setpgid variant used by short-lived Shell tool children, as opposed to the Setsid session used for background processes).

func InterruptSignals

func InterruptSignals() []os.Signal

InterruptSignals is what cancels a turn: SIGINT always, plus SIGTERM where the OS has one. The agent's double-ctrl-c path (first cancels the turn, second exits 130) is shared; only the set differs per OS.

func KillProcessGroup

func KillProcessGroup(cmd *exec.Cmd)

KillProcessGroup kills the process group of an already-started command. It is the exec.Cmd variant of KillTree for callers that hold the child.

func KillTree

func KillTree(pid int) error

KillTree stops pid and everything it started. Killing an already-dead process is not an error.

func MediateMCPCommand

func MediateMCPCommand(command string, args []string) (string, []string)

MediateMCPCommand returns the command and args to spawn for an MCP stdio server. On unix the resolved command runs directly.

func OpenConsole

func OpenConsole() (*os.File, error)

OpenConsole opens the controlling terminal for a direct confirmation read.

func ResolveShell

func ResolveShell() (string, error)

ResolveShell returns the POSIX shell to run agent commands through. On unix it is always "sh" (exec.LookPath resolution happens at spawn time so the error surfaces where the command runs).

func RestoreTerminal

func RestoreTerminal()

RestoreTerminal resets a garbled terminal after the agent exits. On unix this is `stty sane` against the controlling terminal.

func ShellNameForPrompt

func ShellNameForPrompt() string

ShellNameForPrompt reports the shell for the environment prompt block.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL