MCPcopy Create free account
hub / github.com/Noumena-Network/code / getInputPrompt

Function getInputPrompt

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

Source from the content-addressed store, hash-verified

917 profileCheckpoint('main_after_run');
918}
919async function getInputPrompt(prompt: string, inputFormat: 'text' | 'stream-json'): Promise<string | AsyncIterable<string>> {
920 if (!process.stdin.isTTY &&
921 // Input hijacking breaks MCP.
922 !process.argv.includes('mcp')) {
923 if (inputFormat === 'stream-json') {
924 return process.stdin;
925 }
926 process.stdin.setEncoding('utf8');
927 let data = '';
928 const onData = (chunk: string) => {
929 data += chunk;
930 };
931 process.stdin.on('data', onData);
932 // If no data arrives in 3s, stop waiting and warn. Stdin is likely an
933 // inherited pipe from a parent that isn't writing (subprocess spawned
934 // without explicit stdin handling). 3s covers slow producers like curl,
935 // jq on large files, python with import overhead. The warning makes
936 // silent data loss visible for the rare producer that's slower still.
937 const timedOut = await peekForStdinData(process.stdin, 3000);
938 process.stdin.off('data', onData);
939 if (timedOut) {
940 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');
941 }
942 return [prompt, data].filter(Boolean).join('\n');
943 }
944 return prompt;
945}
946async function run(): Promise<CommanderCommand> {
947 profileCheckpoint('run_function_start');
948

Callers 1

runFunction · 0.85

Calls 2

peekForStdinDataFunction · 0.85
writeMethod · 0.45

Tested by

no test coverage detected