diff --git a/cmd/chat.go b/cmd/chat.go index bbfa2f8..6a9c900 100644 --- a/cmd/chat.go +++ b/cmd/chat.go @@ -150,9 +150,9 @@ func runChat(cmd *cobra.Command, args []string) { color.Green("Grok > ") reply := client.Stream(history, model) - // === AGENT TOOL CALL HANDLING === + // Agent tool call handling if agentMode && strings.Contains(reply, "```tool") { - handleToolCall(reply, &history, model) + handleToolCall(reply, &history) continue } @@ -163,8 +163,7 @@ func runChat(cmd *cobra.Command, args []string) { } } -// handleToolCall is now inside cmd package — no import cycle -func handleToolCall(reply string, history *[]map[string]string, model string) { +func handleToolCall(reply string, history *[]map[string]string) { start := strings.Index(reply, "```tool") if start == -1 { return @@ -186,23 +185,40 @@ func handleToolCall(reply string, history *[]map[string]string, model string) { switch tc.Tool { case "edit": if tc.File != "" && tc.Instruction != "" { - RunEditWithInstruction(tc.File, tc.Instruction) + // Reuse the existing edit command's logic (preview + confirm) + editCmd.RunE = func(cmd *cobra.Command, args []string) error { + RunEditWithInstruction(tc.File, tc.Instruction) // we'll define this helper next + return nil + } + _ = editCmd.Execute() } case "scaffold": if tc.Path != "" && tc.Description != "" { - RunScaffoldWithDescription(tc.Path, tc.Description) + scaffoldCmd.RunE = func(cmd *cobra.Command, args []string) error { + RunScaffoldWithDescription(tc.Path, tc.Description) + return nil + } + _ = scaffoldCmd.Execute() } case "testgen": if tc.File != "" { - RunTestgenWithFile(tc.File) + testgenCmd.RunE = func(cmd *cobra.Command, args []string) error { + RunTestgenWithFile(tc.File) + return nil + } + _ = testgenCmd.Execute() } case "lint": if tc.File != "" { - RunLintWithFile(tc.File) + lintCmd.RunE = func(cmd *cobra.Command, args []string) error { + RunLintWithFile(tc.File) + return nil + } + _ = lintCmd.Execute() } case "commit": if tc.Message != "" { - git.Run([]string{"commit", "-m", tc.Message}) + _, _ = git.Run([]string{"commit", "-m", tc.Message}) } default: color.Red("Unknown tool: %s", tc.Tool)