|
| 1 | +# Fix for Issue #1801: Quiet Mode for runPrompt |
| 2 | + |
| 3 | +## Problem |
| 4 | +When a `runPrompt` is executed in `quiet` mode, the output was still being sent to stdout and stderr, even when the CLI `--quiet` flag was used. |
| 5 | + |
| 6 | +## Root Cause |
| 7 | +The console logging functions in `packages/core/src/runpromptcontext.ts` were not checking the `isQuiet` flag before writing to stdout/stderr. |
| 8 | + |
| 9 | +## Solution |
| 10 | +Modified the console logging functions to respect the `isQuiet` flag: |
| 11 | + |
| 12 | +### Changes Made |
| 13 | + |
| 14 | +1. **Added import of quiet module** in `runpromptcontext.ts`: |
| 15 | + ```typescript |
| 16 | + import { isQuiet } from "./quiet.js"; |
| 17 | + ``` |
| 18 | + |
| 19 | +2. **Modified console.log function** to check quiet mode: |
| 20 | + ```typescript |
| 21 | + log: (...args: any[]) => { |
| 22 | + const line = consoleLogFormat(...args); |
| 23 | + if (line) { |
| 24 | + trace?.log(line); |
| 25 | + if (!isQuiet) { |
| 26 | + stdout.write(line + "\n"); |
| 27 | + } |
| 28 | + } |
| 29 | + }, |
| 30 | + ``` |
| 31 | + |
| 32 | +3. **Modified image generation output** to respect quiet mode: |
| 33 | + ```typescript |
| 34 | + if (consoleColors && !isQuiet) { |
| 35 | + // stderr.write for image terminal rendering |
| 36 | + } |
| 37 | + ``` |
| 38 | + |
| 39 | +### Testing |
| 40 | +- Created comprehensive tests in `packages/core/test/quiet.test.ts` |
| 41 | +- Tests verify that stdout.write is not called when `isQuiet` is true |
| 42 | +- Tests verify that trace logging still works in quiet mode |
| 43 | + |
| 44 | +## Impact |
| 45 | +- ✅ `runPrompt` console output now respects the `--quiet` CLI flag |
| 46 | +- ✅ Image generation output is also suppressed in quiet mode |
| 47 | +- ✅ Trace logging continues to work for debugging purposes |
| 48 | +- ✅ Existing functionality is preserved when not in quiet mode |
| 49 | + |
| 50 | +## Files Modified |
| 51 | +- `packages/core/src/runpromptcontext.ts` - Main fix |
| 52 | +- `packages/core/test/quiet.test.ts` - Tests |
| 53 | + |
| 54 | +## Verification |
| 55 | +The fix ensures that when using `genaiscript run --quiet script.genai.mts`, inner `runPrompt` calls will not emit output to stdout/stderr, making the overall execution truly quiet. |
0 commit comments