(output: string, key: string)
| 180 | * Supports multi-line values with pipe delimiter. |
| 181 | */ |
| 182 | export function extractValueForKey(output: string, key: string): string | null { |
| 183 | if (!output) return null |
| 184 | const lines = output.split('\n') |
| 185 | for (let i = 0; i < lines.length; i++) { |
| 186 | const line = lines[i] |
| 187 | const match = line.match(/^\s*([A-Za-z0-9_]+):\s*(.*)$/) |
| 188 | if (match && match[1] === key) { |
| 189 | const rest = match[2] |
| 190 | if (rest.trim().startsWith('|')) { |
| 191 | const baseIndent = lines[i + 1]?.match(/^\s*/)?.[0].length ?? 0 |
| 192 | const acc: string[] = [] |
| 193 | for (let j = i + 1; j < lines.length; j++) { |
| 194 | const l = lines[j] |
| 195 | const indent = l.match(/^\s*/)?.[0].length ?? 0 |
| 196 | if (l.trim().length === 0) { |
| 197 | acc.push('') |
| 198 | continue |
| 199 | } |
| 200 | if (indent < baseIndent) break |
| 201 | acc.push(l.slice(baseIndent)) |
| 202 | } |
| 203 | return acc.join('\n') |
| 204 | } else { |
| 205 | let val = rest.trim() |
| 206 | if (val.startsWith('"') && val.endsWith('"')) { |
| 207 | val = val.slice(1, -1) |
| 208 | } |
| 209 | return val |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | return null |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Extract file path from tool block. |
no outgoing calls
no test coverage detected