diff options
| author | Wietse Venema <[email protected]> | 2025-08-14 20:08:59 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-14 18:08:59 +0000 |
| commit | ec7b84191f539c1a3f890fc994dd62b68d3232fd (patch) | |
| tree | 724959da814e41af19d76bcc0a8174530a67d20f /packages/cli/src/utils/readStdin.ts | |
| parent | 798c4d1311dc9e415caf422f5eb6a7d7e65f0a7a (diff) | |
feat: Allow combining -p and stdin for prompt input (#4406)
Co-authored-by: Allen Hutchison <[email protected]>
Diffstat (limited to 'packages/cli/src/utils/readStdin.ts')
| -rw-r--r-- | packages/cli/src/utils/readStdin.ts | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/packages/cli/src/utils/readStdin.ts b/packages/cli/src/utils/readStdin.ts index 2e005526..f309c53e 100644 --- a/packages/cli/src/utils/readStdin.ts +++ b/packages/cli/src/utils/readStdin.ts @@ -5,14 +5,26 @@ */ export async function readStdin(): Promise<string> { + const MAX_STDIN_SIZE = 8 * 1024 * 1024; // 8MB return new Promise((resolve, reject) => { let data = ''; + let totalSize = 0; process.stdin.setEncoding('utf8'); const onReadable = () => { let chunk; while ((chunk = process.stdin.read()) !== null) { + if (totalSize + chunk.length > MAX_STDIN_SIZE) { + const remainingSize = MAX_STDIN_SIZE - totalSize; + data += chunk.slice(0, remainingSize); + console.warn( + `Warning: stdin input truncated to ${MAX_STDIN_SIZE} bytes.`, + ); + process.stdin.destroy(); // Stop reading further + break; + } data += chunk; + totalSize += chunk.length; } }; |
