* Parses tools from frontmatter, supporting both string and array formats * Always returns a string array for consistency * @param toolsValue The value from frontmatter * @returns Parsed tool list as string[]
(toolsValue: unknown)
| 75 | * @returns Parsed tool list as string[] |
| 76 | */ |
| 77 | function parseToolListString(toolsValue: unknown): string[] | null { |
| 78 | // Return null for missing/null - let caller decide the default |
| 79 | if (toolsValue === undefined || toolsValue === null) { |
| 80 | return null |
| 81 | } |
| 82 | |
| 83 | // Empty string or other falsy values mean no tools |
| 84 | if (!toolsValue) { |
| 85 | return [] |
| 86 | } |
| 87 | |
| 88 | let toolsArray: string[] = [] |
| 89 | if (typeof toolsValue === 'string') { |
| 90 | toolsArray = [toolsValue] |
| 91 | } else if (Array.isArray(toolsValue)) { |
| 92 | toolsArray = toolsValue.filter( |
| 93 | (item): item is string => typeof item === 'string', |
| 94 | ) |
| 95 | } |
| 96 | |
| 97 | if (toolsArray.length === 0) { |
| 98 | return [] |
| 99 | } |
| 100 | |
| 101 | const parsedTools = parseToolListFromCLI(toolsArray) |
| 102 | if (parsedTools.includes('*')) { |
| 103 | return ['*'] |
| 104 | } |
| 105 | return parsedTools |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Parse tools from agent frontmatter |
no test coverage detected