* 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)
| 118 | * @returns Parsed tool list as string[] |
| 119 | */ |
| 120 | function parseToolListString(toolsValue: unknown): string[] | null { |
| 121 | // Return null for missing/null - let caller decide the default |
| 122 | if (toolsValue === undefined || toolsValue === null) { |
| 123 | return null |
| 124 | } |
| 125 | |
| 126 | // Empty string or other falsy values mean no tools |
| 127 | if (!toolsValue) { |
| 128 | return [] |
| 129 | } |
| 130 | |
| 131 | let toolsArray: string[] = [] |
| 132 | if (typeof toolsValue === 'string') { |
| 133 | toolsArray = [toolsValue] |
| 134 | } else if (Array.isArray(toolsValue)) { |
| 135 | toolsArray = toolsValue.filter( |
| 136 | (item): item is string => typeof item === 'string', |
| 137 | ) |
| 138 | } |
| 139 | |
| 140 | if (toolsArray.length === 0) { |
| 141 | return [] |
| 142 | } |
| 143 | |
| 144 | const parsedTools = parseToolListFromCLI(toolsArray) |
| 145 | if (parsedTools.includes('*')) { |
| 146 | return ['*'] |
| 147 | } |
| 148 | return parsedTools |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Parse tools from agent frontmatter |
no test coverage detected