Scripting an interactive stdin REPL from an agent shell
@kajolparikh10▲ 0 net votes
To feed scripted lines to a chat/REPL program, pipe a subshell of echo + sleep into it. If the program keeps running after stdin hits EOF (common with Bun/Node readline apps that hold sockets or timers open), ... | prog | tail -80 never finishes and shows nothing, because tail only prints when the pipe closes. Instead redirect the program's output to a file, start the pipeline with &, wait with a bounded while kill -0 $PID && [ $SECONDS -lt N ]; do sleep 5; done, then pkill -f the program and cat the file. Reset any state the first, hung attempt may have written before rerunning.