subprocess

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package subprocess manages the opencode acp child process and wires its stdio into the coder/acp-go-sdk protocol layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Path is the resolved path to the opencode binary.
	Path string
	// Args are user-supplied flags appended to `opencode acp`. The
	// SDK always prepends `--host 127.0.0.1 --port 0` and `--cwd <Cwd>`
	// (when Cwd is set) to these flags.
	Args []string
	// Env overlays the inherited environment. nil means inherit
	// os.Environ() unchanged.
	Env map[string]string
	// Cwd is the working directory for the subprocess.
	Cwd string
	// Logger receives diagnostics. Must not be nil.
	Logger *slog.Logger
	// StderrCallback, if set, receives each stderr line. If nil, stderr
	// is forwarded to Logger at debug level.
	StderrCallback func(line string)
}

Config configures the opencode acp subprocess.

type Process

type Process struct {
	// contains filtered or unexported fields
}

Process is a running `opencode acp` subprocess attached to a coder ClientSideConnection.

func Spawn

func Spawn(ctx context.Context, cfg Config, client acp.Client) (*Process, error)

Spawn launches opencode acp with the supplied configuration and wires its stdio into a ClientSideConnection bound to the provided client. The returned Process is responsible for the subprocess lifetime; call Close to terminate.

Spawn does not run the ACP initialize handshake — callers invoke Process.Conn().Initialize themselves so they can control timeout and parameters.

func (*Process) Close

func (p *Process) Close() error

Close shuts down the subprocess. It closes stdin (requesting graceful shutdown), waits up to 5s for the process to exit, then delivers a process-group-wide SIGKILL so any children opencode spawned are also reaped. Close is idempotent and safe to call after Start failures.

func (*Process) Conn

func (p *Process) Conn() *acp.ClientSideConnection

Conn returns the underlying ClientSideConnection for making outbound ACP calls.

func (*Process) Done

func (p *Process) Done() <-chan struct{}

Done returns a channel that closes when the peer disconnects.

func (*Process) ExitErr

func (p *Process) ExitErr() error

ExitErr returns the subprocess's exit error once Exited() has fired. Returns nil before exit, and nil if the subprocess exited cleanly or via our intentional shutdown.

func (*Process) Exited

func (p *Process) Exited() <-chan struct{}

Exited returns a channel that is closed after the subprocess has exited (for any reason — clean shutdown, crash, or SIGKILL).

Jump to

Keyboard shortcuts

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