streamrunner

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: MIT Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package streamrunner spawns claude with the stream-json input/output formats as a plain subprocess (no PTY), writes one user-turn JSON envelope to its stdin, forwards stdout/stderr to caller-supplied writers, and waits for the child to exit.

`pyry agent-run` uses streamrunner to drive claude in `--input-format stream-json --output-format stream-json` mode from a single shot of stdin; the package owns the spawn, the stdin write, and the wait — nothing else.

The package logs only error messages and never logs prompt bytes or any substring of the stream-json event stream — writers are opaque io.Writer values and the package does not parse what passes through them.

Dependency direction: the package must not import github.com/pyrycode/pyrycode/internal/supervisor (the PTY helper) nor any of the other agentrun subpackages. Verify with:

go list -deps ./internal/agentrun/streamrunner/... | grep pyrycode/internal/supervisor

Expected output: empty.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, cfg Config) error

Run spawns claude with cfg.Args, writes one stream-json user-turn envelope to its stdin and closes stdin, forwards stdout/stderr to the configured writers, and waits for the child to exit.

Return value contract:

  • nil on a clean (exit 0) child termination.
  • nil on ctx-cancel-driven teardown — operator shutdown is success.
  • *exec.ExitError on non-zero child exit not triggered by ctx cancel.
  • a wrapped error from pre-Start setup (stdin pipe, spawn).

On ctx cancel, the child receives SIGTERM and is given killGrace to exit before stdlib follows up with SIGKILL. This is wired via exec.Cmd.Cancel + exec.Cmd.WaitDelay — no goroutine or timer is owned by this package.

Types

type Config

type Config struct {
	// ClaudeBin is the resolved path to the claude executable. Required.
	ClaudeBin string

	// WorkDir is the child process's working directory. Required.
	WorkDir string

	// Args is the full claude argv (excluding argv[0]). The caller
	// assembles flag shape — Run does not know about claude's flags.
	Args []string

	// PromptBytes is the user-turn prompt text. UTF-8; may contain quotes,
	// newlines, or control characters — Run JSON-encodes it, so embedded
	// metacharacters are safe. May be empty (a valid no-op turn).
	PromptBytes []byte

	// Stdout receives the child's stdout. Required.
	//
	// MUST NOT block — a writer that stalls will deadlock cmd.Wait()
	// because the stdlib's internal forwarder blocks on writing into it
	// while the child is still running.
	Stdout io.Writer

	// Stderr receives the child's stderr. Required. Same non-blocking
	// requirement as Stdout.
	Stderr io.Writer

	// Env is appended to os.Environ() in the child process. Optional;
	// production callers leave it nil. Tests use it to thread
	// TestHelperProcess wiring.
	Env []string

	// Logger is used for the small number of Warn-level diagnostics this
	// package emits (stdin write/close failures). Optional; nil falls
	// back to slog.Default().
	Logger *slog.Logger
}

Config configures Run. Required fields are validated at entry; zero values for optional fields fall through to documented defaults.

Jump to

Keyboard shortcuts

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