Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { installSigchldHandler } from './core/zombie-reap.ts';
installSigchldHandler();

import { readFileSync } from 'fs';
import { readFileSync, readSync } from 'fs';
import { loadConfig, loadConfigWithEngine, toEngineConfig, isThinClient } from './core/config.ts';
import type { GBrainConfig } from './core/config.ts';
import type { AIGatewayConfig } from './core/ai/types.ts';
Expand Down Expand Up @@ -508,7 +508,21 @@ export function parseOpArgs(op: Operation, args: string[]): Record<string, unkno

// Read stdin for content params
if (op.cliHints?.stdin && !params[op.cliHints.stdin] && !process.stdin.isTTY) {
const stdinContent = readFileSync('/dev/stdin', 'utf-8');
let stdinContent: string;
try {
// Try Unix /dev/stdin first
stdinContent = readFileSync('/dev/stdin', 'utf-8');
} catch {
// Windows fallback: read from stdin fd directly
const fd = 0;
const chunks: Buffer[] = [];
const buf = Buffer.alloc(65536);
let nread: number;
while ((nread = readSync(fd, buf, 0, buf.length, null)) > 0) {
chunks.push(buf.slice(0, nread));
}
stdinContent = Buffer.concat(chunks).toString('utf-8');
}
const MAX_STDIN = 5_000_000; // 5MB
if (Buffer.byteLength(stdinContent, 'utf-8') > MAX_STDIN) {
console.error(`Error: stdin content exceeds ${MAX_STDIN} bytes. Split into smaller inputs.`);
Expand Down