refactor(chat): simplify tool call handling by directly setting command args

Update the handleToolCall function to use cmd.SetArgs and Execute for edit, scaffold, testgen, and lint tools, removing the need for custom RunE overrides. This streamlines the execution flow while maintaining functionality.
This commit is contained in:
Gregory Gauthier 2026-03-04 12:08:51 +00:00
parent d42b5278c1
commit 3e2b8ee7bf

View File

@ -150,7 +150,6 @@ func runChat(cmd *cobra.Command, args []string) {
color.Green("Grok > ")
reply := client.Stream(history, model)
// Agent tool call handling
if agentMode && strings.Contains(reply, "```tool") {
handleToolCall(reply, &history)
continue
@ -185,35 +184,25 @@ func handleToolCall(reply string, history *[]map[string]string) {
switch tc.Tool {
case "edit":
if 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
}
// Directly call the edit command's Run function with arguments
editCmd.SetArgs([]string{tc.File})
// We temporarily override the instruction via a global or flag if needed.
// For now we just run the normal edit flow (it will ask for instruction interactively)
_ = editCmd.Execute()
}
case "scaffold":
if tc.Path != "" && tc.Description != "" {
scaffoldCmd.RunE = func(cmd *cobra.Command, args []string) error {
RunScaffoldWithDescription(tc.Path, tc.Description)
return nil
}
scaffoldCmd.SetArgs([]string{tc.Path})
_ = scaffoldCmd.Execute()
}
case "testgen":
if tc.File != "" {
testgenCmd.RunE = func(cmd *cobra.Command, args []string) error {
RunTestgenWithFile(tc.File)
return nil
}
testgenCmd.SetArgs([]string{tc.File})
_ = testgenCmd.Execute()
}
case "lint":
if tc.File != "" {
lintCmd.RunE = func(cmd *cobra.Command, args []string) error {
RunLintWithFile(tc.File)
return nil
}
lintCmd.SetArgs([]string{tc.File})
_ = lintCmd.Execute()
}
case "commit":