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

Method processHistoryCommand

cli/cli_commands.go:61–90  ·  view source on GitHub ↗

processHistoryCommand adiciona o histórico do shell ao contexto

(userInput string)

Source from the content-addressed store, hash-verified

59
60// processHistoryCommand adiciona o histórico do shell ao contexto
61func (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
93func (cli *ChatCLI) processGitCommand(userInput string) (string, string) {

Callers 1

Calls 5

GetShellHistoryFunction · 0.92
TFunction · 0.92
filterEmptyLinesFunction · 0.85
ErrorMethod · 0.65

Tested by

no test coverage detected