MCPcopy Create free account
hub / github.com/diillson/chatcli / executeCommandsWithOutput

Method executeCommandsWithOutput

cli/agent_command_blocks.go:699–749  ·  view source on GitHub ↗

executeCommandsWithOutput executa comandos usando o CommandExecutor

(ctx context.Context, block agent.CommandBlock)

Source from the content-addressed store, hash-verified

697
698// executeCommandsWithOutput executa comandos usando o CommandExecutor
699func (a *AgentMode) executeCommandsWithOutput(ctx context.Context, block agent.CommandBlock) (string, string) {
700 var allOutput strings.Builder
701 var lastError string
702
703 langNorm := strings.ToLower(block.Language)
704 if langNorm == "git" || langNorm == "docker" || langNorm == "kubectl" {
705 langNorm = "shell"
706 }
707
708 renderer := agent.NewUIRenderer(a.logger)
709 titleContent := i18n.T("agent.status.executing", langNorm)
710 contentWidth := agent.VisibleLen(titleContent)
711 topBorder := strings.Repeat("─", contentWidth)
712
713 fmt.Println("\n" + renderer.Colorize(topBorder, agent.ColorGray))
714 fmt.Println(renderer.Colorize(titleContent, agent.ColorLime+agent.ColorBold))
715
716 allOutput.WriteString(fmt.Sprintf("\nExecutando: %s (tipo: %s)\n", block.Description, langNorm))
717
718 shell := os.Getenv("SHELL")
719 if shell == "" {
720 shell = "/bin/sh"
721 }
722
723 if block.ContextInfo.IsScript {
724 a.runScriptBlock(ctx, block, shell, &allOutput, &lastError)
725 } else {
726 for i, cmd := range block.Commands {
727 a.runSingleCommand(ctx, block, renderer, i, cmd, &allOutput, &lastError)
728 }
729 }
730
731 footerContent := i18n.T("agent.status.execution_complete")
732 if lastError != "" {
733 footerContent = i18n.T("agent.status.execution_complete_with_errors")
734 }
735 footerWidth := agent.VisibleLen(footerContent)
736
737 paddingWidth := contentWidth - footerWidth
738 if paddingWidth < 0 {
739 paddingWidth = 0
740 }
741 leftPadding := paddingWidth / 2
742 rightPadding := paddingWidth - leftPadding
743
744 finalBorder := strings.Repeat("─", leftPadding) + footerContent + strings.Repeat("─", rightPadding)
745 fmt.Println(renderer.Colorize(finalBorder, agent.ColorGray))
746
747 allOutput.WriteString("Execução concluída.\n")
748 return allOutput.String(), lastError
749}
750
751// runScriptBlock writes the block's single script to a temp file and runs it,
752// streaming output to the terminal and accumulating it into allOutput.

Callers 1

RunOnceMethod · 0.95

Calls 7

ColorizeMethod · 0.95
runScriptBlockMethod · 0.95
runSingleCommandMethod · 0.95
NewUIRendererFunction · 0.92
TFunction · 0.92
VisibleLenFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected