@@ -79,29 +79,34 @@ func callTool(tool *Tool) (string, error) {
7979 }
8080 }
8181
82+ var out bytes.Buffer
83+ var stderr bytes.Buffer
8284 // Combine the tool name and arguments for the mai-tool command
8385 // tool.Name may be in the format "server/tool"
84- cmdArgs := append ([] string { "call" , toolName }, safeArgs ... )
86+ /*
8587 cmd := exec.Command("mai-tool", cmdArgs...)
8688
87- var out bytes.Buffer
88- var stderr bytes.Buffer
8989 cmd.Stdout = &out
9090 cmd.Stderr = &stderr
91+ */
92+ timeout := 60
93+ cmdArgs := append ([]string {"call" , toolName }, safeArgs ... )
9194
9295 // Set a timeout for the command execution
93- timeoutCtx , cancel := context .WithTimeout (context .Background (), 60 * time .Second )
96+ timeoutCtx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
9497 defer cancel ()
9598
9699 // Set the command context with timeout
97- cmd = exec .CommandContext (timeoutCtx , "mai-tool" , cmdArgs ... )
100+ cmd : = exec .CommandContext (timeoutCtx , "mai-tool" , cmdArgs ... )
98101 cmd .Stdout = & out
99102 cmd .Stderr = & stderr
103+ fmt .Println ("MAITOOLRUN " + toolName )
104+ fmt .Println ("MAITOOLARG " + strings .Join (cmdArgs , " '" ))
100105
101106 err := cmd .Run ()
102107 if err != nil {
103108 if errors .Is (err , context .DeadlineExceeded ) {
104- return "" , fmt .Errorf ("tool execution timed out after 30 seconds: %s" , tool .Name )
109+ return "" , fmt .Errorf ("tool execution timed out after %d seconds: %s" , timeout , tool .Name )
105110 }
106111 return "" , fmt .Errorf ("error executing tool %s: %v: %s" , tool .Name , err , stderr .String ())
107112 }
@@ -168,6 +173,9 @@ func mapToArray(m map[string]interface{}) []string {
168173// extractJSONBlock locates the first balanced JSON object in text (or fenced JSON)
169174// and returns it plus any remaining tail text.
170175func extractJSONBlock (text string ) (string , string ) {
176+ if ! strings .Contains (text , "\" plan\" " ) {
177+ return "" , text
178+ }
171179 // Attempt fenced JSON block: ```json ... ```
172180 re := regexp .MustCompile ("(?s)```json\\ s*(.*?)\\ s*```" )
173181 matches := re .FindStringSubmatch (text )
0 commit comments