MCPcopy
hub / github.com/codeaashu/claude-code / getInputPrompt

Function getInputPrompt

src/main.tsx:857–883  ·  view source on GitHub ↗
(prompt: string, inputFormat: 'text' | 'stream-json')

Source from the content-addressed store, hash-verified

855 profileCheckpoint('main_after_run');
856}
857async function getInputPrompt(prompt: string, inputFormat: 'text' | 'stream-json'): Promise<string | AsyncIterable<string>> {
858 if (!process.stdin.isTTY &&
859 // Input hijacking breaks MCP.
860 !process.argv.includes('mcp')) {
861 if (inputFormat === 'stream-json') {
862 return process.stdin;
863 }
864 process.stdin.setEncoding('utf8');
865 let data = '';
866 const onData = (chunk: string) => {
867 data += chunk;
868 };
869 process.stdin.on('data', onData);
870 // If no data arrives in 3s, stop waiting and warn. Stdin is likely an
871 // inherited pipe from a parent that isn't writing (subprocess spawned
872 // without explicit stdin handling). 3s covers slow producers like curl,
873 // jq on large files, python with import overhead. The warning makes
874 // silent data loss visible for the rare producer that's slower still.
875 const timedOut = await peekForStdinData(process.stdin, 3000);
876 process.stdin.off('data', onData);
877 if (timedOut) {
878 process.stderr.write('Warning: no stdin data received in 3s, proceeding without it. ' + 'If piping from a slow command, redirect stdin explicitly: < /dev/null to skip, or wait longer.\n');
879 }
880 return [prompt, data].filter(Boolean).join('\n');
881 }
882 return prompt;
883}
884async function run(): Promise<CommanderCommand> {
885 profileCheckpoint('run_function_start');
886

Callers 1

runFunction · 0.85

Calls 4

peekForStdinDataFunction · 0.85
onMethod · 0.80
offMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected