processHistoryCommand adiciona o histórico do shell ao contexto
(userInput string)
| 59 | |
| 60 | // processHistoryCommand adiciona o histórico do shell ao contexto |
| 61 | func (cli *ChatCLI) processHistoryCommand(userInput string) (string, string) { |
| 62 | var additionalContext string |
| 63 | if strings.Contains(strings.ToLower(userInput), "@history") { |
| 64 | historyData, err := utils.GetShellHistory() |
| 65 | if err != nil { |
| 66 | cli.logger.Error("Erro ao obter o histórico do shell", zap.Error(err)) |
| 67 | } else { |
| 68 | allLines := filterEmptyLines(strings.Split(historyData, "\n")) |
| 69 | total := len(allLines) |
| 70 | |
| 71 | n := 30 |
| 72 | var lastLines []string |
| 73 | if total > n { |
| 74 | lastLines = allLines[total-n:] |
| 75 | } else { |
| 76 | lastLines = allLines |
| 77 | } |
| 78 | |
| 79 | startNumber := total - len(lastLines) + 1 |
| 80 | formatted := make([]string, len(lastLines)) |
| 81 | for i, cmd := range lastLines { |
| 82 | formatted[i] = fmt.Sprintf("%d: %s", startNumber+i, cmd) |
| 83 | } |
| 84 | limitedHistoryData := strings.Join(formatted, "\n") |
| 85 | additionalContext += "\n" + i18n.T("command.context.shell_history") + ":\n" + limitedHistoryData |
| 86 | } |
| 87 | userInput = removeCommandAndNormalizeSpaces(userInput, "@history") |
| 88 | } |
| 89 | return userInput, additionalContext |
| 90 | } |
| 91 | |
| 92 | // processGitCommand adiciona informações do Git ao contexto |
| 93 | func (cli *ChatCLI) processGitCommand(userInput string) (string, string) { |
no test coverage detected