Fix FIFO stdin handling by opening for read+write like tty-fwd

- Open stdin FIFO with 'r+' mode to keep it open continuously
- Use fs.openSync + createReadStream for proper FIFO handling
- Prevent FIFO from closing when external writers disconnect
- Follow tty-fwd pattern of opening FIFO for both read and write
- Remove problematic spawn('cat') approach that was exiting

This should fix the issue where stdin FIFO closes after first input.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mario Zechner 2025-06-19 06:17:44 +02:00
parent a2b0ba77da
commit 7a37f7a231

View file

@ -209,11 +209,9 @@ async function main() {
console.log(`Monitoring stdin pipe: ${stdinPath}`);
try {
// Open the FIFO for reading (non-blocking)
const stdinStream = fs.createReadStream(stdinPath, {
encoding: 'utf8',
flags: 'r',
});
// Open FIFO for both read and write (like tty-fwd) to keep it open
const stdinFd = fs.openSync(stdinPath, 'r+'); // r+ = read/write
const stdinStream = fs.createReadStream('', { fd: stdinFd, encoding: 'utf8' });
stdinStream.on('data', (data: string) => {
try {
@ -228,9 +226,18 @@ async function main() {
console.warn('Stdin FIFO stream error:', error);
});
stdinStream.on('end', () => {
console.log('Stdin FIFO stream ended');
});
// Clean up on exit
process.on('exit', () => {
stdinStream.destroy();
try {
stdinStream.destroy();
fs.closeSync(stdinFd);
} catch (_e) {
// Ignore cleanup errors
}
});
} catch (error) {
console.warn('Failed to set up stdin FIFO monitoring:', error);