MCPcopy
hub / github.com/google-labs-code/design.md / readInput

Function readInput

packages/cli/src/utils.ts:21–42  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

19 * Never throws — returns the content string or exits with error JSON.
20 */
21export async function readInput(filePath: string): Promise<string> {
22 if (filePath === '-') {
23 // Read from stdin
24 const chunks: Buffer[] = [];
25 for await (const chunk of process.stdin) {
26 chunks.push(chunk as Buffer);
27 }
28 return Buffer.concat(chunks).toString('utf-8');
29 }
30
31 try {
32 return readFileSync(filePath, 'utf-8');
33 } catch (error) {
34 console.error(JSON.stringify({
35 error: 'FILE_READ_ERROR',
36 message: error instanceof Error ? error.message : String(error),
37 path: filePath,
38 }));
39 process.exitCode = 2;
40 throw error; // bubbles up, but process will exit with code 2 if uncaught
41 }
42}
43
44/**
45 * Format output as JSON or human-readable text.

Callers 3

runFunction · 0.85
runFunction · 0.85
runFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…