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