ParseComments extracts LlmComment entries from tool call arguments without writing to the Collector. Returns parsed comments and an error message (empty on success).
(args map[string]any)
| 69 | // ParseComments extracts LlmComment entries from tool call arguments without writing |
| 70 | // to the Collector. Returns parsed comments and an error message (empty on success). |
| 71 | func ParseComments(args map[string]any) ([]model.LlmComment, string) { |
| 72 | var rawComments []any |
| 73 | if arr, ok := args["comments"].([]any); ok && len(arr) > 0 { |
| 74 | rawComments = arr |
| 75 | } else if s, ok := args["comments"].(string); ok && s != "" { |
| 76 | if err := json.Unmarshal([]byte(s), &rawComments); err != nil { |
| 77 | return nil, fmt.Sprintf("Error: failed to parse 'comments' JSON string: %v", err) |
| 78 | } |
| 79 | } |
| 80 | if len(rawComments) == 0 { |
| 81 | raw, _ := json.Marshal(args) |
| 82 | return nil, fmt.Sprintf("Error: 'comments' array is required. Got args: %s", string(raw)) |
| 83 | } |
| 84 | |
| 85 | var comments []model.LlmComment |
| 86 | for _, raw := range rawComments { |
| 87 | obj, ok := raw.(map[string]any) |
| 88 | if !ok { |
| 89 | continue |
| 90 | } |
| 91 | |
| 92 | cm := model.LlmComment{} |
| 93 | |
| 94 | if content, ok := obj["content"].(string); ok { |
| 95 | cm.Content = content |
| 96 | } |
| 97 | if suggestion, ok := obj["suggestion_code"].(string); ok { |
| 98 | cm.SuggestionCode = suggestion |
| 99 | } |
| 100 | if existing, ok := obj["existing_code"].(string); ok { |
| 101 | cm.ExistingCode = existing |
| 102 | } |
| 103 | if thinking, ok := obj["thinking"].(string); ok { |
| 104 | cm.Thinking = thinking |
| 105 | } |
| 106 | if category, ok := obj["category"].(string); ok { |
| 107 | cm.Category = normalizeCodeCommentCategory(category) |
| 108 | } |
| 109 | if severity, ok := obj["severity"].(string); ok { |
| 110 | cm.Severity = normalizeCodeCommentSeverity(severity) |
| 111 | } |
| 112 | if path, ok := args["path"].(string); ok { |
| 113 | cm.Path = path |
| 114 | } |
| 115 | |
| 116 | if cm.Path == "" || cm.Content == "" { |
| 117 | continue |
| 118 | } |
| 119 | |
| 120 | comments = append(comments, cm) |
| 121 | } |
| 122 | return comments, "" |
| 123 | } |
| 124 | |
| 125 | func normalizeCodeCommentCategory(category string) string { |
| 126 | normalized := strings.ToLower(category) |