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
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.