* Turn the MCP server's stdout into an async iterator of line strings. * @param {NodeJS.ReadableStream} stdout
(stdout)
| 450 | * @param {NodeJS.ReadableStream} stdout |
| 451 | */ |
| 452 | async function* lineIterator(stdout) { |
| 453 | let buffer = ""; |
| 454 | for await (const chunk of stdout) { |
| 455 | buffer += chunk.toString(); |
| 456 | let newlineIdx; |
| 457 | while ((newlineIdx = buffer.indexOf("\n")) !== -1) { |
| 458 | const line = buffer.slice(0, newlineIdx).trim(); |
| 459 | buffer = buffer.slice(newlineIdx + 1); |
| 460 | if (line) { |
| 461 | yield line; |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | if (buffer.trim()) { |
| 466 | yield buffer.trim(); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | /** |
| 471 | * Locate the safe_outputs_mcp_server.cjs script. The setup action copies it |