Skip to content

Commit 7f74d0f

Browse files
authored
Merge pull request #704 from dgageot/remove-dead-code-exec
Remove dead code
2 parents f41db20 + 2213278 commit 7f74d0f

4 files changed

Lines changed: 51 additions & 83 deletions

File tree

cmd/root/alias.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func runAliasListCommand(cmd *cobra.Command, args []string) error {
143143
out.Printf(" %s%s → %s\n", name, padding, path)
144144
}
145145

146-
out.Print("\nRun an alias with: cagent run <alias>\n")
146+
out.Println("\nRun an alias with: cagent run <alias>")
147147

148148
return nil
149149
}

cmd/root/new.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ func (f *newFlags) runNewCommand(cmd *cobra.Command, args []string) error {
7171
switch {
7272
case os.Getenv("ANTHROPIC_API_KEY") != "":
7373
modelProvider = "anthropic"
74-
out.Printf("%s\n\n", cli.White("ANTHROPIC_API_KEY found, using Anthropic"))
74+
out.Printf("%s\n\n", "ANTHROPIC_API_KEY found, using Anthropic")
7575
case os.Getenv("OPENAI_API_KEY") != "":
7676
modelProvider = "openai"
77-
out.Printf("%s\n\n", cli.White("OPENAI_API_KEY found, using OpenAI"))
77+
out.Printf("%s\n\n", "OPENAI_API_KEY found, using OpenAI")
7878
case os.Getenv("GOOGLE_API_KEY") != "":
7979
modelProvider = "google"
80-
out.Printf("%s\n\n", cli.White("GOOGLE_API_KEY found, using Google"))
80+
out.Printf("%s\n\n", "GOOGLE_API_KEY found, using Google")
8181
default:
8282
modelProvider = "dmr"
83-
out.Printf("%s\n\n", cli.Yellow("⚠️ No provider credentials found, defaulting to Docker Model Runner (DMR)"))
83+
out.Printf("%s\n\n", "⚠️ No provider credentials found, defaulting to Docker Model Runner (DMR)")
8484
}
8585
if f.modelParam == "" {
86-
out.Printf("%s\n\n", cli.White("use \"--model provider/model\" to use a different model"))
86+
out.Printf("%s\n\n", "use \"--model provider/model\" to use a different model")
8787
}
8888
} else {
8989
// Using Models Gateway; default to Anthropic if not specified
@@ -95,10 +95,10 @@ func (f *newFlags) runNewCommand(cmd *cobra.Command, args []string) error {
9595
if len(args) > 0 {
9696
prompt = strings.Join(args, " ")
9797
} else {
98-
out.Printf("%s\n", cli.Blue("------- Welcome to %s! -------", cli.Bold(AppName)))
99-
out.Printf("%s\n\n", cli.White(" (Ctrl+C to exit)"))
100-
out.Printf("%s\n\n", cli.Blue("What should your agent/agent team do? (describe its purpose)"))
101-
out.Print(cli.Blue("> "))
98+
out.Printf("------- Welcome to %s! -------\n", AppName)
99+
out.Printf("%s\n\n", " (Ctrl+C to exit)")
100+
out.Printf("%s\n\n", "What should your agent/agent team do? (describe its purpose)")
101+
out.Print("> ")
102102

103103
var err error
104104
prompt, err = input.ReadLine(ctx, os.Stdin)

pkg/cli/runner.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ func Run(ctx context.Context, out *Printer, cfg Config, agentFilename string, rt
123123
if e.AgentName != "" && e.AgentName != "root" {
124124
prefix = prefix + e.AgentName + ": "
125125
}
126-
out.Printf("\n%s", White(prefix))
126+
out.Printf("\n%s", prefix)
127127
reasoningStarted = true
128128
}
129129
// Continue printing reasoning content
130-
out.Printf("%s", White(e.Content))
130+
out.Print(e.Content)
131131
case *runtime.ToolCallConfirmationEvent:
132132
if llmIsTyping {
133133
out.Println()
@@ -223,7 +223,7 @@ func Run(ctx context.Context, out *Printer, cfg Config, agentFilename string, rt
223223

224224
// If the loop ended due to Ctrl+C, inform the user succinctly
225225
if ctx.Err() != nil {
226-
out.Println(Yellow("\n⚠️ agent stopped ⚠️"))
226+
out.Println("\n⚠️ agent stopped ⚠️")
227227
}
228228

229229
// Wrap runtime errors to prevent duplicate error messages and usage display
@@ -253,9 +253,10 @@ func Run(ctx context.Context, out *Printer, cfg Config, agentFilename string, rt
253253
firstQuestion := true
254254
for {
255255
if !firstQuestion {
256-
out.Print("\n\n")
256+
out.Println()
257+
out.Println()
257258
}
258-
out.Print(Blue("> "))
259+
out.Print("> ")
259260
firstQuestion = false
260261

261262
line, err := input.ReadLine(ctx, os.Stdin)
@@ -285,21 +286,21 @@ func runUserCommand(out *Printer, userInput string, sess *session.Session, rt ru
285286
case "/eval":
286287
evalFile, err := evaluation.Save(sess)
287288
if err == nil {
288-
out.Printf("%s\n", Yellow("Evaluation saved to file %s", evalFile))
289+
out.Println("Evaluation saved to file:", evalFile)
289290
return true, err
290291
}
291292
return true, nil
292293
case "/usage":
293-
out.Printf("%s\n", Yellow("Input tokens: %d", sess.InputTokens))
294-
out.Printf("%s\n", Yellow("Output tokens: %d", sess.OutputTokens))
294+
out.Println("Input tokens:", sess.InputTokens)
295+
out.Println("Output tokens:", sess.OutputTokens)
295296
return true, nil
296297
case "/new":
297298
// Reset session items
298299
sess.Messages = []session.Item{}
299300
return true, nil
300301
case "/compact":
301302
// Generate a summary of the session and compact the history
302-
out.Printf("%s\n", Yellow("Generating summary..."))
303+
out.Println("Generating summary...")
303304

304305
// Create a channel to capture summary events
305306
events := make(chan runtime.Event, 100)
@@ -314,17 +315,17 @@ func runUserCommand(out *Printer, userInput string, sess *session.Session, rt ru
314315
for event := range events {
315316
switch e := event.(type) {
316317
case *runtime.SessionSummaryEvent:
317-
out.Printf("%s\n", Yellow("Summary generated and added to session"))
318-
out.Printf("Summary: %s\n", e.Summary)
318+
out.Println("Summary generated and added to session")
319+
out.Println("Summary:", e.Summary)
319320
summaryGenerated = true
320321
case *runtime.WarningEvent:
321-
out.Printf("%s\n", Yellow("Warning: "+e.Message))
322+
out.Println("Warning:", e.Message)
322323
hasWarning = true
323324
}
324325
}
325326

326327
if !summaryGenerated && !hasWarning {
327-
out.Printf("%s\n", Yellow("No summary generated"))
328+
out.Println("No summary generated")
328329
}
329330

330331
return true, nil

pkg/cli/text.go

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ import (
1515
"github.com/docker/cagent/pkg/tools"
1616
)
1717

18-
var (
19-
// Let's disable the colors in non TUI mode.
20-
// (dga): I kept those functions in case we find a proper way to use them in both dark and light modes.
21-
blue = fmt.Sprintf
22-
yellow = fmt.Sprintf
23-
red = fmt.Sprintf
24-
white = fmt.Sprintf
25-
green = fmt.Sprintf
26-
27-
bold = color.New(color.Bold).SprintfFunc()
28-
)
29-
3018
// ConfirmationResult represents the result of a user confirmation prompt
3119
type ConfirmationResult string
3220

@@ -37,15 +25,7 @@ const (
3725
ConfirmationAbort ConfirmationResult = "abort"
3826
)
3927

40-
// Color formatting functions (exported for use by other packages)
41-
var (
42-
Blue = blue
43-
Yellow = yellow
44-
Red = red
45-
White = white
46-
Green = green
47-
Bold = bold
48-
)
28+
var bold = color.New(color.Bold).SprintfFunc()
4929

5030
type Printer struct {
5131
out io.Writer
@@ -71,41 +51,36 @@ func (p *Printer) Printf(format string, a ...any) (n int, err error) {
7151

7252
// PrintWelcomeMessage prints the welcome message
7353
func (p *Printer) PrintWelcomeMessage(appName string) {
74-
p.Printf("\n%s\n%s\n\n", blue("------- Welcome to %s! -------", bold(appName)), white("(Ctrl+C to stop the agent and exit)"))
54+
p.Printf("\n------- Welcome to %s! -------\n(Ctrl+C to stop the agent and exit)\n\n", bold(appName))
7555
}
7656

7757
// PrintError prints an error message
7858
func (p *Printer) PrintError(err error) {
79-
p.Print(red("❌ %s", err))
59+
p.Printf("❌ %s", err)
8060
}
8161

8262
// PrintAgentName prints the agent name header
8363
func (p *Printer) PrintAgentName(agentName string) {
84-
p.Printf("\n%s\n", blue("--- Agent: %s ---", bold(agentName)))
64+
p.Printf("\n--- Agent: %s ---\n", bold(agentName))
8565
}
8666

8767
// PrintToolCall prints a tool call
88-
func (p *Printer) PrintToolCall(toolCall tools.ToolCall, colorFunc ...func(format string, a ...any) string) {
89-
c := white
90-
if len(colorFunc) > 0 && colorFunc[0] != nil {
91-
c = colorFunc[0]
92-
}
93-
p.Printf("\nCalling %s\n", c("%s%s", bold(toolCall.Function.Name), formatToolCallArguments(toolCall.Function.Arguments)))
68+
func (p *Printer) PrintToolCall(toolCall tools.ToolCall) {
69+
p.Printf("\nCalling %s%s\n", bold(toolCall.Function.Name), formatToolCallArguments(toolCall.Function.Arguments))
9470
}
9571

9672
// PrintToolCallWithConfirmation prints a tool call and prompts for confirmation
9773
func (p *Printer) PrintToolCallWithConfirmation(ctx context.Context, toolCall tools.ToolCall, rd io.Reader) ConfirmationResult {
98-
p.Printf("\n%s\n", bold(yellow("🛠️ Tool call requires confirmation 🛠️")))
99-
p.PrintToolCall(toolCall, color.New(color.FgWhite).SprintfFunc())
100-
p.Printf("\n%s", bold(yellow("Can I run this tool? ([y]es/[a]ll/[n]o): ")))
74+
p.Printf("\n%s\n", bold("🛠️ Tool call requires confirmation 🛠️"))
75+
p.PrintToolCall(toolCall)
76+
p.Printf("\n%s", bold("Can I run this tool? ([y]es/[a]ll/[n]o): "))
10177

10278
// Try single-character input from stdin in raw mode (no Enter required)
10379
fd := int(os.Stdin.Fd())
10480
if oldState, err := term.MakeRaw(fd); err == nil {
10581
defer func() {
10682
if err := term.Restore(fd, oldState); err != nil {
107-
p.
108-
Printf("\n%s\n", yellow("Failed to restore terminal state: %v", err))
83+
p.Printf("\nFailed to restore terminal state: %v\n", err)
10984
}
11085
}()
11186
buf := make([]byte, 1)
@@ -154,61 +129,53 @@ func (p *Printer) PrintToolCallWithConfirmation(ctx context.Context, toolCall to
154129

155130
// PrintToolCallResponse prints a tool call response
156131
func (p *Printer) PrintToolCallResponse(toolCall tools.ToolCall, response string) {
157-
p.Printf("\n%s\n", white("%s response%s", bold(toolCall.Function.Name), formatToolCallResponse(response)))
132+
p.Printf("\n%s response%s\n", bold(toolCall.Function.Name), formatToolCallResponse(response))
158133
}
159134

160135
// PromptMaxIterationsContinue prompts the user to continue after max iterations
161136
func (p *Printer) PromptMaxIterationsContinue(ctx context.Context, maxIterations int) ConfirmationResult {
162-
p.Printf("\n%s\n", yellow("⚠️ Maximum iterations (%d) reached. The agent may be stuck in a loop.", maxIterations))
163-
p.Printf("%s\n", white("This can happen with smaller or less capable models."))
164-
p.Printf("\n%s (y/n): ", blue("Do you want to continue for 10 more iterations?"))
137+
p.Printf("\n⚠️ Maximum iterations (%d) reached. The agent may be stuck in a loop.\n", maxIterations)
138+
p.Printf("%s\n", "This can happen with smaller or less capable models.")
139+
p.Printf("\n%s (y/n): ", "Do you want to continue for 10 more iterations?")
165140

166141
response, err := input.ReadLine(ctx, os.Stdin)
167142
if err != nil {
168-
p.
169-
Printf("\n%s\n", red("Failed to read input, exiting..."))
143+
p.Println("\nFailed to read input, exiting...")
170144
return ConfirmationAbort
171145
}
172146

173147
response = strings.TrimSpace(strings.ToLower(response))
174148
if response == "y" || response == "yes" {
175-
p.
176-
Printf("%s\n\n", green("✓ Continuing..."))
149+
p.Print("✓ Continuing...\n\n")
177150
return ConfirmationApprove
178151
} else {
179-
p.
180-
Printf("%s\n\n", white("Exiting..."))
152+
p.Print("Exiting...\n\n")
181153
return ConfirmationReject
182154
}
183155
}
184156

185157
// PromptOAuthAuthorization prompts the user for OAuth authorization
186158
func (p *Printer) PromptOAuthAuthorization(ctx context.Context, serverURL string) ConfirmationResult {
187-
p.Printf("\n%s\n", yellow("🔐 OAuth Authorization Required"))
188-
p.Printf("%s %s (remote)\n", white("Server:"), blue(serverURL))
189-
p.Printf("%s\n", white("This server requires OAuth authentication to access its tools."))
190-
p.Printf("%s\n", white("Your browser will open automatically to complete the authorization."))
191-
p.Printf("\n%s (y/n): ", blue("Do you want to authorize access?"))
159+
p.Println("\n🔐 OAuth Authorization Required")
160+
p.Println("Server:", serverURL, "(remote)")
161+
p.Println("This server requires OAuth authentication to access its tools.")
162+
p.Println("Your browser will open automatically to complete the authorization.")
163+
p.Printf("\n%s (y/n): ", "Do you want to authorize access?")
192164

193165
response, err := input.ReadLine(ctx, os.Stdin)
194166
if err != nil {
195-
p.
196-
Printf("\n%s\n", red("Failed to read input, aborting authorization..."))
167+
p.Printf("\n%s\n", "Failed to read input, aborting authorization...")
197168
return ConfirmationAbort
198169
}
199170

200171
response = strings.TrimSpace(strings.ToLower(response))
201172
if response == "y" || response == "yes" {
202-
p.
203-
Printf("%s\n", green("✓ Starting OAuth authorization..."))
204-
p.
205-
Printf("%s\n", white("Please complete the authorization in your browser."))
206-
p.
207-
Printf("%s\n\n", white("Once completed, the agent will continue automatically."))
173+
p.Println("✓ Starting OAuth authorization...")
174+
p.Println("Please complete the authorization in your browser.")
175+
p.Print("Once completed, the agent will continue automatically.\n\n")
208176
return ConfirmationApprove
209177
} else {
210-
p.
211-
Printf("%s\n\n", white("Authorization declined. Exiting..."))
178+
p.Print("Authorization declined. Exiting...\n\n")
212179
return ConfirmationReject
213180
}
214181
}

0 commit comments

Comments
 (0)