Split a comma-separated YAML inline list, respecting single/double-quoted items. Handles `tools: [Read, Grep]` → ['Read', 'Grep'] AND `tools: ["foo, bar", baz]` → ['foo, bar', 'baz']
(inner: str)
| 176 | |
| 177 | |
| 178 | def _split_inline_list(inner: str) -> list[str]: |
| 179 | """Split a comma-separated YAML inline list, respecting single/double-quoted items. |
| 180 | |
| 181 | Handles `tools: [Read, Grep]` → ['Read', 'Grep'] |
| 182 | AND `tools: ["foo, bar", baz]` → ['foo, bar', 'baz'] |
| 183 | """ |
| 184 | items: list[str] = [] |
| 185 | buf: list[str] = [] |
| 186 | quote: str | None = None |
| 187 | for ch in inner: |
| 188 | if quote: |
| 189 | if ch == quote: |
| 190 | quote = None |
| 191 | else: |
| 192 | buf.append(ch) |
| 193 | elif ch in ('"', "'"): |
| 194 | quote = ch |
| 195 | elif ch == ",": |
| 196 | item = "".join(buf).strip() |
| 197 | if item: |
| 198 | items.append(item) |
| 199 | buf = [] |
| 200 | else: |
| 201 | buf.append(ch) |
| 202 | tail = "".join(buf).strip() |
| 203 | if tail: |
| 204 | items.append(tail) |
| 205 | return items |
| 206 | |
| 207 | |
| 208 | def split_tools_list(raw) -> list[str]: |