Documentation
¶
Overview ¶
Package process starts the subprocesses Aviary owns, such as CLI providers and the ngrok tunnel, and makes sure none of them outlives Aviary.
Index ¶
- func CombinedOutput(cmd *exec.Cmd) ([]byte, error)
- func Command(ctx context.Context, binary string, args ...string) *exec.Cmd
- func ExitAfterReaping(code int)
- func Kill(cmd *exec.Cmd) error
- func Output(cmd *exec.Cmd) ([]byte, error)
- func Pause(cmd *exec.Cmd) error
- func ReapAll()
- func Resume(cmd *exec.Cmd) error
- func Run(cmd *exec.Cmd) error
- func ShimArgv(binary string, args []string) (string, []string, error)
- func ShutdownContext(prepare func()) (context.Context, func())
- func Start(cmd *exec.Cmd) error
- func Stop(cmd *exec.Cmd) error
- func Wait(cmd *exec.Cmd) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CombinedOutput ¶
CombinedOutput runs a tracked child and returns its standard output and standard error interleaved, the tracked equivalent of exec.Cmd.CombinedOutput.
func Command ¶
Command is exec.CommandContext for a CLI provider such as claude or codex, started through ShimArgv. When the provider cannot be started without losing an argument, Start reports why, so the caller fails loudly instead of the CLI running on truncated arguments.
func ExitAfterReaping ¶
func ExitAfterReaping(code int)
ExitAfterReaping terminates every owned subprocess before exiting, because os.Exit runs no deferred cleanup.
func Kill ¶
Kill ends a tracked child and everything it spawned at once, paused or not. It only signals and never waits, so it is safe as an exec.Cmd Cancel function while another goroutine is in Wait. Killing just the child would leave its descendants holding its output pipes, and a paused descendant never lets go of them, so Wait would never return.
func Output ¶
Output runs a tracked child and returns what it wrote to standard output, the tracked equivalent of exec.Cmd.Output.
func Pause ¶
Pause suspends a tracked child and everything it spawned, so nothing in the tree runs until Resume or a kill. The shutdown checkpoint uses it to commit an agent's checkout without catching a half-written file.
func ReapAll ¶
func ReapAll()
ReapAll terminates every owned subprocess. It is safe to call more than once, so shutdown paths can call it defensively.
func ShimArgv ¶
ShimArgv returns the program and arguments to start a CLI provider with.
On Windows a .cmd or .bat file can only run through cmd.exe, and cmd.exe ends the command line at the first newline, so a multi-line argument handed to an npm shim such as claude.cmd reached the CLI cut short, along with every argument after it: a chat's multi-line system prompt dropped the approval flags that followed it (#553). The shim is therefore replaced by the program it launches, which receives every argument intact. A batch file aviary cannot read through is still run as is, unless an argument has a line break it would lose: that is refused with an error naming models.cli_definitions.<name>.binary as the way to point aviary at the real executable.
func ShutdownContext ¶
ShutdownContext returns a context that is canceled by the first shutdown signal, giving aviary a chance to stop its subprocesses in order. The first signal runs prepare, when given, before the context is canceled, so work that must happen while subprocesses are still alive (the shutdown checkpoint, issue #741) finishes first. A second signal means "now": every owned subprocess is killed and aviary exits immediately, even mid-prepare, so an impatient second Ctrl-C cannot leave an orphan behind.
func Start ¶
Start starts cmd as an owned subprocess: it runs in its own process group so the processes it spawns are terminated with it, it is tracked so aviary kills the whole tree before exiting, and the kernel is asked to tear it down should aviary die without running any cleanup at all.
On platforms where the kernel guard can only be installed on a process that already exists, the child is created in a state where it has not run yet and adoptOrphanedProcess releases it; a child that cannot be released is killed rather than handed back to the caller suspended forever.
Types ¶
This section is empty.