Files
DeepSeek-Reasonix/internal/tool/progress.go
T
reasonix a4ce28c58d feat(bash): interruptible runs with live streamed output
Kill the whole process tree on cancel — Setpgid + SIGKILL on unix,
taskkill /T on windows — so Esc actually stops `go test ./...` and the
binaries it spawns, not just the shell leader that previously survived.

Stream combined stdout/stderr via a new ToolProgress event so a long
command shows live progress under its card (the last N lines on a ⎿
block), collapsing to a "N lines" summary when it finishes.
2026-06-01 20:12:08 -07:00

23 lines
831 B
Go

package tool
import "context"
// ProgressFunc receives a chunk of a tool's combined output as it is produced, so
// a long-running tool (bash) can stream progress to a frontend before it returns.
type ProgressFunc func(chunk string)
type progressKey struct{}
// WithProgress stamps ctx with a progress sink the executing tool may call; the
// agent sets it per call so the chunk reaches the right tool card.
func WithProgress(ctx context.Context, fn ProgressFunc) context.Context {
return context.WithValue(ctx, progressKey{}, fn)
}
// ProgressFrom returns the progress sink, if one was stamped (ok is false for a
// plain context — headless tests or calls outside the run loop).
func ProgressFrom(ctx context.Context) (ProgressFunc, bool) {
fn, ok := ctx.Value(progressKey{}).(ProgressFunc)
return fn, ok && fn != nil
}