Commit 6d473ab

mo khan <mo@mokhan.ca>
2025-06-22 15:36:42
Format the output
1 parent 9736477
Changed files (1)
cmd
cmd/del/main.go
@@ -989,6 +989,45 @@ func (d *Del) askConfirmation(operation string, description string) bool {
 	return confirmed
 }
 
+// formatArgs formats tool arguments for display
+func (d *Del) formatArgs(args map[string]interface{}) string {
+	if len(args) == 0 {
+		return ""
+	}
+	
+	var parts []string
+	for key, value := range args {
+		switch v := value.(type) {
+		case string:
+			if len(v) > 30 {
+				parts = append(parts, fmt.Sprintf("%s: \"%.30s...\"", key, v))
+			} else {
+				parts = append(parts, fmt.Sprintf("%s: \"%s\"", key, v))
+			}
+		default:
+			parts = append(parts, fmt.Sprintf("%s: %v", key, v))
+		}
+	}
+	return strings.Join(parts, ", ")
+}
+
+// summarizeResult creates a brief summary of tool results
+func (d *Del) summarizeResult(result interface{}) string {
+	switch v := result.(type) {
+	case string:
+		lines := strings.Split(v, "\n")
+		if len(lines) == 1 && len(v) < 50 {
+			return v
+		} else if len(lines) > 1 {
+			return fmt.Sprintf("Output: %d lines", len(lines))
+		} else {
+			return fmt.Sprintf("Output: %d chars", len(v))
+		}
+	default:
+		return "Completed successfully"
+	}
+}
+
 // parseChineseFormat handles Chinese model format: <|tool▁calls▁begin|>...
 func (d *Del) parseChineseFormat(response string) []ToolCall {
 	var calls []ToolCall
@@ -1373,11 +1412,13 @@ func (d *Del) streamChat(ctx context.Context, history []api.Message) (string, er
 func (d *Del) executeToolCalls(ctx context.Context, toolCalls []ToolCall) map[string]interface{} {
 	results := make(map[string]interface{})
 	
-	fmt.Printf("\n🔧 Executing %d tool call(s)...\n", len(toolCalls))
+	fmt.Printf("\n● Executing %d tool call(s):\n", len(toolCalls))
 	
 	for i, toolCall := range toolCalls {
+		fmt.Printf("\n● %s(%s)\n", toolCall.Name, d.formatArgs(toolCall.Args))
 		tool, ok := d.tools[toolCall.Name]
 		if !ok {
+			fmt.Printf("  ⎿  ❌ Unknown tool: %s\n", toolCall.Name)
 			results[fmt.Sprintf("tool_%d", i)] = map[string]interface{}{
 				"tool": toolCall.Name,
 				"error": fmt.Sprintf("unknown tool: %s", toolCall.Name),
@@ -1390,6 +1431,7 @@ func (d *Del) executeToolCalls(ctx context.Context, toolCalls []ToolCall) map[st
 			argsJSON, _ := json.Marshal(toolCall.Args)
 			description := fmt.Sprintf("%s with args: %s", toolCall.Name, string(argsJSON))
 			if !d.askConfirmation(toolCall.Name, description) {
+				fmt.Printf("  ⎿  🚫 Operation cancelled by user\n")
 				results[fmt.Sprintf("tool_%d", i)] = map[string]interface{}{
 					"tool": toolCall.Name,
 					"error": "operation cancelled by user",
@@ -1398,10 +1440,13 @@ func (d *Del) executeToolCalls(ctx context.Context, toolCalls []ToolCall) map[st
 			}
 		}
 		
+		fmt.Printf("  ⎿  ")
 		ch := make(chan string, 10)
+		var output strings.Builder
 		go func() {
 			for line := range ch {
 				fmt.Print(line)
+				output.WriteString(line)
 			}
 		}()
 		
@@ -1409,11 +1454,15 @@ func (d *Del) executeToolCalls(ctx context.Context, toolCalls []ToolCall) map[st
 		close(ch)
 		
 		if err != nil {
+			fmt.Printf("  ⎿  ❌ Error: %s\n", err.Error())
 			results[fmt.Sprintf("tool_%d", i)] = map[string]interface{}{
 				"tool": toolCall.Name,
 				"error": err.Error(),
 			}
 		} else {
+			// Show success with brief result summary
+			resultSummary := d.summarizeResult(result)
+			fmt.Printf("  ⎿  ✅ %s\n", resultSummary)
 			results[fmt.Sprintf("tool_%d", i)] = map[string]interface{}{
 				"tool": toolCall.Name,
 				"result": result,
@@ -1431,6 +1480,9 @@ func (d *Del) handleToolCalls(ctx context.Context, response string) (bool, map[s
 		return false, nil // No tool calls found
 	}
 	
+	// Show parsing success
+	fmt.Printf("\n● Detected %d tool call(s) using universal parser\n", len(toolCalls))
+	
 	// Execute all tool calls and return results
 	results := d.executeToolCalls(ctx, toolCalls)
 	return true, results
@@ -1610,7 +1662,7 @@ func (d *Del) StartREPL(ctx context.Context) {
 			// Stage 2: Tool calls were found and executed, ask model for final response
 			d.chatHistory = append(d.chatHistory, api.Message{Role: "assistant", Content: response})
 			
-			fmt.Printf("\n📋 Providing tool results to model for final response...\n")
+			fmt.Printf("\n● Providing tool results to model for final response...\n")
 			
 			// Create tool results message
 			toolResultsJSON, _ := json.MarshalIndent(toolResults, "", "  ")
@@ -1620,10 +1672,11 @@ func (d *Del) StartREPL(ctx context.Context) {
 			// Get final response with tool results
 			finalResponse, err := d.aiProvider.Chat(ctx, d.chatHistory)
 			if err != nil {
-				fmt.Printf("\n⚠️  Error getting final response: %s\n\n", err)
+				fmt.Printf("  ⎿  ❌ Error getting final response: %s\n\n", err)
 				continue
 			}
-			fmt.Printf("🤖 Del: %s", finalResponse)
+			fmt.Printf("  ⎿  ✅ Generated natural response\n")
+			fmt.Printf("\n🤖 Del: %s", finalResponse)
 			d.chatHistory = append(d.chatHistory, api.Message{Role: "assistant", Content: finalResponse})
 		} else {
 			// No tool calls, just display the response normally