jsonInt mirrors jsonString for integer fields. Tries each alias, returns the first parseable int. Strings that contain a valid int (e.g. "10") are coerced — the LLM occasionally emits stringified numbers and we don't want to reject those.
(raw map[string]json.RawMessage, keys ...string)
| 99 | // (e.g. "10") are coerced — the LLM occasionally emits stringified |
| 100 | // numbers and we don't want to reject those. |
| 101 | func jsonInt(raw map[string]json.RawMessage, keys ...string) int { |
| 102 | for _, k := range keys { |
| 103 | val, ok := raw[k] |
| 104 | if !ok { |
| 105 | continue |
| 106 | } |
| 107 | var n int |
| 108 | if err := json.Unmarshal(val, &n); err == nil { |
| 109 | return n |
| 110 | } |
| 111 | // Fallback: stringified integer. |
| 112 | var s string |
| 113 | if err := json.Unmarshal(val, &s); err == nil { |
| 114 | if parsed, perr := strconv.Atoi(strings.TrimSpace(s)); perr == nil { |
| 115 | return parsed |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | return 0 |
| 120 | } |
| 121 | |
| 122 | // stringFromFlagArgs scans positional args for `--key value` pairs. The |
| 123 | // value may be the next arg or, after stripping quotes, embedded as |
no outgoing calls