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 <noreply@anthropic.com>
This commit is contained in:
parent
63d4ad95d0
commit
981683a405
1 changed files with 26 additions and 29 deletions
55
main.go
55
main.go
|
|
@ -178,39 +178,36 @@ func main() {
|
||||||
logFilePath = filepath.Join(stateDir, "klod", "sessions", sessionTime+".log")
|
logFilePath = filepath.Join(stateDir, "klod", "sessions", sessionTime+".log")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get initial prompt from command-line arguments
|
// Get initial prompt from command-line arguments (if provided)
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) >= 2 {
|
||||||
fmt.Fprintln(os.Stderr, "Usage: klod <your prompt>")
|
initialPrompt := strings.Join(os.Args[1:], " ")
|
||||||
os.Exit(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
|
// Send initial message
|
||||||
userMsg := Message{
|
printSeparator()
|
||||||
Role: "user",
|
fmt.Print("\033[34mAssistant: \033[0m")
|
||||||
Content: initialPrompt,
|
response, err := sendMessage(apiKey, model, systemPrompt)
|
||||||
}
|
if err != nil {
|
||||||
conversationHistory = append(conversationHistory, userMsg)
|
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
||||||
logConversation(userMsg)
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
printSeparator()
|
||||||
|
|
||||||
// Send initial message
|
// Add assistant's response to conversation history
|
||||||
printSeparator()
|
assistantMsg := Message{
|
||||||
fmt.Print("\033[34mAssistant: \033[0m")
|
Role: "assistant",
|
||||||
response, err := sendMessage(apiKey, model, systemPrompt)
|
Content: response,
|
||||||
if err != nil {
|
}
|
||||||
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
|
conversationHistory = append(conversationHistory, assistantMsg)
|
||||||
os.Exit(1)
|
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
|
// Interactive conversation loop
|
||||||
reader := bufio.NewReader(os.Stdin)
|
reader := bufio.NewReader(os.Stdin)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue