subprocessrecord

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package subprocessrecord provides recording and replay of subprocess I/O for CLI-based providers (claudecode, codex, dsh, opencode).

It is the subprocess analog of httprecord: httprecord wraps http.RoundTripper, subprocessrecord wraps genai.Starter.

In record mode the real subprocess is launched and its stdout is teed into an NDJSON file. In replay mode the fixture is read back without launching any subprocess.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LineSanitizer added in v0.8.0

type LineSanitizer func([]byte) ([]byte, error)

LineSanitizer transforms one recorded stdout line without changing the data returned to the subprocess client.

type Recorder

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

Recorder records or replays subprocess I/O.

Use Wrap as a genai.ProviderOptionStarterWrapper:

rec, err := subprocessrecord.New("testdata/scenario", nil)
if err != nil {
	log.Print(err)
	return
}
defer func() {
	if err := rec.Stop(); err != nil {
		log.Print(err)
	}
}()
ctx := context.Background()
opts := []genai.ProviderOption{genai.ProviderOptionStarterWrapper(rec.Wrap)}
c, err := codex.New(ctx, opts...)
if err != nil {
	log.Print(err)
	return
}
defer func() {
	if err := c.Close(); err != nil {
		log.Print(err)
	}
}()

func New

func New(path string, sanitize LineSanitizer) (*Recorder, error)

New creates a Recorder for the given path.

The path should not include the ".ndjson" extension; it is appended automatically. A non-empty fixture is replayed. Empty fixtures are removed because they are incomplete recordings, then recorded again. If sanitize is non-nil, it transforms each recorded line before persistence.

func (*Recorder) Stop

func (r *Recorder) Stop() error

Stop is called when the recording session is done.

It discards an empty fixture because it is an incomplete recording and must never be replayed.

func (*Recorder) Wrap

func (r *Recorder) Wrap(inner genai.Starter) genai.Starter

Wrap returns a starter that either records subprocess I/O or replays the fixture.

It implements the genai.ProviderOptionStarterWrapper signature.

Jump to

Keyboard shortcuts

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