(args map[string]any, defaultPath string)
| 99 | } |
| 100 | |
| 101 | func parseCommentsInner(args map[string]any, defaultPath string) ([]model.LlmComment, *CommentRepair, string) { |
| 102 | var rawComments []any |
| 103 | var repair *CommentRepair |
| 104 | if arr, ok := args["comments"].([]any); ok && len(arr) > 0 { |
| 105 | rawComments = arr |
| 106 | } else if s, ok := args["comments"].(string); ok && s != "" { |
| 107 | if err := json.Unmarshal([]byte(s), &rawComments); err != nil { |
| 108 | // A string here is a schema violation that in practice fails to |
| 109 | // parse and takes the whole batch with it. Try the repair first. |
| 110 | entries, rep := parseRepairedComments(s) |
| 111 | if entries == nil { |
| 112 | // Keep "invalid character" as the parser produced it: that |
| 113 | // phrasing is what leads the model to regenerate the batch, |
| 114 | // while naming the schema violation instead makes it resend the |
| 115 | // same broken string. |
| 116 | return nil, nil, fmt.Sprintf("Error: failed to parse 'comments' JSON string: %v", err) |
| 117 | } |
| 118 | rawComments = entries |
| 119 | repair = rep |
| 120 | } |
| 121 | } |
| 122 | if len(rawComments) == 0 { |
| 123 | raw, _ := json.Marshal(args) |
| 124 | return nil, nil, fmt.Sprintf("Error: 'comments' array is required. Got args: %s", string(raw)) |
| 125 | } |
| 126 | |
| 127 | var comments []model.LlmComment |
| 128 | for _, raw := range rawComments { |
| 129 | obj, ok := raw.(map[string]any) |
| 130 | if !ok { |
| 131 | continue |
| 132 | } |
| 133 | |
| 134 | cm := model.LlmComment{} |
| 135 | |
| 136 | if content, ok := obj["content"].(string); ok { |
| 137 | cm.Content = content |
| 138 | } |
| 139 | if suggestion, ok := obj["suggestion_code"].(string); ok { |
| 140 | cm.SuggestionCode = suggestion |
| 141 | } |
| 142 | if existing, ok := obj["existing_code"].(string); ok { |
| 143 | cm.ExistingCode = existing |
| 144 | } |
| 145 | if thinking, ok := obj["thinking"].(string); ok { |
| 146 | cm.Thinking = thinking |
| 147 | } |
| 148 | if category, ok := obj["category"].(string); ok { |
| 149 | cm.Category = normalizeCodeCommentCategory(category) |
| 150 | } |
| 151 | if severity, ok := obj["severity"].(string); ok { |
| 152 | cm.Severity = normalizeCodeCommentSeverity(severity) |
| 153 | } |
| 154 | if pathVal, ok := obj["path"].(string); ok && pathVal != "" { |
| 155 | cm.Path = normalizeCommentPath(pathVal) |
| 156 | } |
| 157 | if cm.Path == "" { |
| 158 | cm.Path = normalizeCommentPath(defaultPath) |
no test coverage detected