()
| 41 | * Used to determine if stdin reading should be skipped |
| 42 | */ |
| 43 | export function hasSuppliedPrompt(): boolean { |
| 44 | const args = process.argv.slice(2); |
| 45 | const printIndex = args.findIndex((arg) => arg === "-p" || arg === "--print"); |
| 46 | |
| 47 | if (printIndex === -1) { |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | // Check if --prompt flag is present (indicates a prompt is coming) |
| 52 | // Note: --agent doesn't supply a prompt, it just specifies which agent to use |
| 53 | // Piped stdin should still be read when --agent is present |
| 54 | const hasPromptFlag = args.includes("--prompt"); |
| 55 | if (hasPromptFlag) { |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | // Check if there's a non-flag argument after -p/--print |
| 60 | // We need to skip flags that take values (like --config, --model, etc.) |
| 61 | // Known flags that take values |
| 62 | const flagsWithValues = new Set([ |
| 63 | "--config", |
| 64 | "--model", |
| 65 | "--output", |
| 66 | "--mode", |
| 67 | "--workflow", |
| 68 | "--agent", |
| 69 | "-m", |
| 70 | "-c", |
| 71 | "-o", |
| 72 | ]); |
| 73 | |
| 74 | const argsAfterPrint = args.slice(printIndex + 1); |
| 75 | for (let i = 0; i < argsAfterPrint.length; i++) { |
| 76 | const arg = argsAfterPrint[i]; |
| 77 | |
| 78 | // If this is a flag that takes a value, skip both the flag and its value |
| 79 | if (flagsWithValues.has(arg)) { |
| 80 | i++; // Skip the next argument (the value) |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | // If this is any other flag (starts with -), skip it |
| 85 | if (arg.startsWith("-")) { |
| 86 | continue; |
| 87 | } |
| 88 | |
| 89 | // Found a non-flag argument - this is the prompt |
| 90 | return true; |
| 91 | } |
| 92 | |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | export const escapeEvents = new EventEmitter(); |
| 97 |
no outgoing calls
no test coverage detected