exec

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package exec runs child processes and streams their output line-by-line.

Built for `codag onboard`, where bulk log fetches (e.g. `vercel logs --since=7d`) can spit out hundreds of thousands of lines. The MCP-side `codag wrap` and MCP tools use the same streaming path so log commands do not have to finish before codag starts bounding their output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Collect

func Collect(ctx context.Context, cmd string, args []string, maxLines int, timeout time.Duration) (lines []string, truncated bool, err error)

Collect streams a child command into memory with practical incident-sized bounds. maxLines = 0 means unlimited; timeout = 0 means no extra timeout. truncated reports that the line cap cut the stream short; a timeout surfaces as a context.DeadlineExceeded error with the collected lines.

Types

type Streamed

type Streamed struct {
	Lines <-chan string
	// contains filtered or unexported fields
}

Stream spawns `cmd args...` and returns a channel of non-empty trimmed stdout+stderr lines. The channel closes when the child exits, the context is cancelled, or maxLines lines have been emitted (whichever comes first). Calling Wait() blocks until the child exits and returns the child's exit error.

On context cancel or maxLines reached, the child is killed via the context. Always drain the channel — leaking a reader leaks a goroutine.

func Stream

func Stream(ctx context.Context, cmd string, args []string, maxLines int) (*Streamed, error)

Stream starts the child and begins emitting lines on the returned channel. maxLines = 0 means unlimited.

func StreamStdout

func StreamStdout(ctx context.Context, cmd string, args []string, maxLines int) (*Streamed, error)

StreamStdout is like Stream, but stderr is captured only for Wait() errors. Use this for provider CLIs where stderr is command diagnostics, not log data.

func (*Streamed) HitLineLimit added in v0.1.14

func (s *Streamed) HitLineLimit() bool

HitLineLimit reports whether the stream stopped because maxLines was reached. Only meaningful once the Lines channel has closed. Callers should surface this — a silently capped log window reads as complete.

func (*Streamed) Wait

func (s *Streamed) Wait() error

Jump to

Keyboard shortcuts

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