Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/root/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ func (f *runExecFlags) runExecCommand(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
out := cli.NewPrinter(cmd.OutOrStdout())

return f.runOrExec(ctx, out, args, true)
tui := false
return f.runOrExec(ctx, out, args, tui)
}
8 changes: 5 additions & 3 deletions cmd/root/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log/slog"
"os"

"github.com/mattn/go-isatty"
"github.com/spf13/cobra"
"go.opentelemetry.io/otel"

Expand Down Expand Up @@ -72,10 +73,11 @@ func (f *runExecFlags) runRunCommand(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
out := cli.NewPrinter(cmd.OutOrStdout())

return f.runOrExec(ctx, out, args, false)
tui := isatty.IsTerminal(os.Stdout.Fd())
return f.runOrExec(ctx, out, args, tui)
}

func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []string, exec bool) error {
func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []string, tui bool) error {
slog.Debug("Starting agent", "agent", f.agentName)

var agentFileName string
Expand Down Expand Up @@ -122,7 +124,7 @@ func (f *runExecFlags) runOrExec(ctx context.Context, out *cli.Printer, args []s
return nil
}

if exec {
if !tui {
return f.handleExecMode(ctx, out, agentFileName, rt, sess, args)
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/junegunn/fzf v0.67.0
github.com/k3a/html2text v1.2.1
github.com/labstack/echo/v4 v4.13.4
github.com/mattn/go-isatty v0.0.20
github.com/mattn/go-runewidth v0.0.19
github.com/modelcontextprotocol/go-sdk v1.1.0
github.com/openai/openai-go/v3 v3.8.1
Expand Down Expand Up @@ -104,7 +105,6 @@ require (
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/microcosm-cc/bluemonday v1.0.27 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
Expand Down
7 changes: 6 additions & 1 deletion pkg/cli/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
"strings"

"github.com/fatih/color"
"github.com/wk8/go-ordered-map/v2"
"github.com/mattn/go-isatty"
orderedmap "github.com/wk8/go-ordered-map/v2"
"golang.org/x/term"

"github.com/docker/cagent/pkg/input"
Expand Down Expand Up @@ -76,6 +77,10 @@ func (p *Printer) PrintToolCallWithConfirmation(ctx context.Context, toolCall to
p.PrintToolCall(toolCall)
p.Printf("\n%s", bold("Can I run this tool? ([y]es/[a]ll/[n]o): "))

if !isatty.IsTerminal(os.Stdout.Fd()) {
Copy link
Contributor

@krissetto krissetto Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to consider the possible presence of the --yolo flag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in yolo mode, we don't enter this function.

return ConfirmationReject
}

// Try single-character input from stdin in raw mode (no Enter required)
fd := int(os.Stdin.Fd())
if oldState, err := term.MakeRaw(fd); err == nil {
Expand Down
Loading