From e120a629397a8c594497bd61b8b1d9e5c0babf78 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Wed, 14 Jan 2026 09:42:11 +0300 Subject: Feat: shellmode to chat history --- tui.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tui.go b/tui.go index 72d456f..a7570cf 100644 --- a/tui.go +++ b/tui.go @@ -221,20 +221,37 @@ func executeCommandAndDisplay(cmdText string) { output, err := cmd.CombinedOutput() // Add the command being executed to the chat fmt.Fprintf(textView, "\n[yellow]$ %s[-:-:-]\n", cmdText) + var outputContent string if err != nil { // Include both output and error - fmt.Fprintf(textView, "[red]Error: %s[-:-:-]\n", err.Error()) + errorMsg := "Error: " + err.Error() + fmt.Fprintf(textView, "[red]%s[-:-:-]\n", errorMsg) if len(output) > 0 { - fmt.Fprintf(textView, "[red]%s[-:-:-]\n", string(output)) + outputStr := string(output) + fmt.Fprintf(textView, "[red]%s[-:-:-]\n", outputStr) + outputContent = errorMsg + "\n" + outputStr + } else { + outputContent = errorMsg } } else { // Only output if successful if len(output) > 0 { - fmt.Fprintf(textView, "[green]%s[-:-:-]\n", string(output)) + outputStr := string(output) + fmt.Fprintf(textView, "[green]%s[-:-:-]\n", outputStr) + outputContent = outputStr } else { - fmt.Fprintf(textView, "[green]Command executed successfully (no output)[-:-:-]\n") + successMsg := "Command executed successfully (no output)" + fmt.Fprintf(textView, "[green]%s[-:-:-]\n", successMsg) + outputContent = successMsg } } + // Combine command and output in a single message for chat history + combinedContent := "$ " + cmdText + "\n\n" + outputContent + combinedMsg := models.RoleMsg{ + Role: cfg.ToolRole, + Content: combinedContent, + } + chatBody.Messages = append(chatBody.Messages, combinedMsg) // Scroll to end and update colors if scrollToEndEnabled { textView.ScrollToEnd() -- cgit v1.2.3