From 981683a405db2870019732e4a6a653fa27256cd7 Mon Sep 17 00:00:00 2001 From: Leo Alho <46094014+leoalho@users.noreply.github.com> Date: Thu, 29 Jan 2026 15:06:30 +0200 Subject: [PATCH] feat: Allow starting CLI without initial prompt (#2) Make the initial prompt optional. When no arguments are provided, the CLI now goes directly to interactive mode instead of exiting. Co-authored-by: Claude Opus 4.5 --- main.go | 55 ++++++++++++++++++++++++++----------------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/main.go b/main.go index 506ebf3..97c5470 100644 --- a/main.go +++ b/main.go @@ -178,39 +178,36 @@ func main() { logFilePath = filepath.Join(stateDir, "klod", "sessions", sessionTime+".log") } - // Get initial prompt from command-line arguments - if len(os.Args) < 2 { - fmt.Fprintln(os.Stderr, "Usage: klod ") - os.Exit(1) - } + // Get initial prompt from command-line arguments (if provided) + if len(os.Args) >= 2 { + initialPrompt := strings.Join(os.Args[1:], " ") - initialPrompt := strings.Join(os.Args[1:], " ") + // Add initial user message to conversation history + userMsg := Message{ + Role: "user", + Content: initialPrompt, + } + conversationHistory = append(conversationHistory, userMsg) + logConversation(userMsg) - // Add initial user message to conversation history - userMsg := Message{ - Role: "user", - Content: initialPrompt, - } - conversationHistory = append(conversationHistory, userMsg) - logConversation(userMsg) + // Send initial message + printSeparator() + fmt.Print("\033[34mAssistant: \033[0m") + response, err := sendMessage(apiKey, model, systemPrompt) + if err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } + printSeparator() - // Send initial message - printSeparator() - fmt.Print("\033[34mAssistant: \033[0m") - response, err := sendMessage(apiKey, model, systemPrompt) - if err != nil { - fmt.Fprintf(os.Stderr, "Error: %v\n", err) - os.Exit(1) + // Add assistant's response to conversation history + assistantMsg := Message{ + Role: "assistant", + Content: response, + } + conversationHistory = append(conversationHistory, assistantMsg) + logConversation(assistantMsg) } - printSeparator() - - // Add assistant's response to conversation history - assistantMsg := Message{ - Role: "assistant", - Content: response, - } - conversationHistory = append(conversationHistory, assistantMsg) - logConversation(assistantMsg) // Interactive conversation loop reader := bufio.NewReader(os.Stdin)