ParseLineCursor parses a single line of Cursor CLI stream-json NDJSON and returns an Event. If the line cannot be parsed or is not relevant, it returns nil.
(line string)
| 157 | // ParseLineCursor parses a single line of Cursor CLI stream-json NDJSON and returns an Event. |
| 158 | // If the line cannot be parsed or is not relevant, it returns nil. |
| 159 | func ParseLineCursor(line string) *Event { |
| 160 | line = strings.TrimSpace(line) |
| 161 | if line == "" { |
| 162 | return nil |
| 163 | } |
| 164 | |
| 165 | var ev cursorEvent |
| 166 | if err := json.Unmarshal([]byte(line), &ev); err != nil { |
| 167 | return nil |
| 168 | } |
| 169 | |
| 170 | switch ev.Type { |
| 171 | case "system": |
| 172 | if ev.Subtype == "init" { |
| 173 | return &Event{Type: EventIterationStart} |
| 174 | } |
| 175 | return nil |
| 176 | |
| 177 | case "assistant": |
| 178 | return parseCursorAssistantMessage(ev.Message) |
| 179 | |
| 180 | case "tool_call": |
| 181 | return parseCursorToolCall(ev.Subtype, ev.ToolCall) |
| 182 | |
| 183 | case "user", "result": |
| 184 | return nil |
| 185 | |
| 186 | default: |
| 187 | return nil |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | func parseCursorAssistantMessage(raw json.RawMessage) *Event { |
| 192 | if raw == nil { |