@@ -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
3119type 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
5030type 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
7353func (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
7858func (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
8363func (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 ("\n Calling %s\n " , c ("%s%s" , bold (toolCall .Function .Name ), formatToolCallArguments (toolCall .Function .Arguments )))
68+ func (p * Printer ) PrintToolCall (toolCall tools.ToolCall ) {
69+ p .Printf ("\n Calling %s%s\n " , bold (toolCall .Function .Name ), formatToolCallArguments (toolCall .Function .Arguments ))
9470}
9571
9672// PrintToolCallWithConfirmation prints a tool call and prompts for confirmation
9773func (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 ("\n Failed 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
156131func (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
161136func (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 ("\n Failed 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
186158func (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