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 ¶
Stream starts the child and begins emitting lines on the returned channel. maxLines = 0 means unlimited.
func StreamStdout ¶
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
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.