(tools: string[])
| 811 | } |
| 812 | |
| 813 | export function parseToolListFromCLI(tools: string[]): string[] { |
| 814 | if (tools.length === 0) { |
| 815 | return [] |
| 816 | } |
| 817 | |
| 818 | const result: string[] = [] |
| 819 | |
| 820 | // Process each string in the array |
| 821 | for (const toolString of tools) { |
| 822 | if (!toolString) continue |
| 823 | |
| 824 | let current = '' |
| 825 | let isInParens = false |
| 826 | |
| 827 | // Parse each character in the string |
| 828 | for (const char of toolString) { |
| 829 | switch (char) { |
| 830 | case '(': |
| 831 | isInParens = true |
| 832 | current += char |
| 833 | break |
| 834 | case ')': |
| 835 | isInParens = false |
| 836 | current += char |
| 837 | break |
| 838 | case ',': |
| 839 | if (isInParens) { |
| 840 | current += char |
| 841 | } else { |
| 842 | // Comma separator - push current tool and start new one |
| 843 | if (current.trim()) { |
| 844 | result.push(current.trim()) |
| 845 | } |
| 846 | current = '' |
| 847 | } |
| 848 | break |
| 849 | case ' ': |
| 850 | if (isInParens) { |
| 851 | current += char |
| 852 | } else if (current.trim()) { |
| 853 | // Space separator - push current tool and start new one |
| 854 | result.push(current.trim()) |
| 855 | current = '' |
| 856 | } |
| 857 | break |
| 858 | default: |
| 859 | current += char |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | // Push any remaining tool |
| 864 | if (current.trim()) { |
| 865 | result.push(current.trim()) |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | return result |
| 870 | } |
no test coverage detected