Skip to content

Commit 7051d91

Browse files
committed
fix: prevent spurious readline close from exiting — recreate readline, use stderr for ora
1 parent e84ada6 commit 7051d91

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

src/cli/input.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class CliInput extends EventEmitter {
1717
private userDir: string;
1818
private multilineMode = false;
1919
private multilineBuffer: string[] = [];
20+
private intentionalClose = false;
2021

2122
constructor(params: { prompt: string; userDir: string }) {
2223
super();
@@ -39,12 +40,23 @@ export class CliInput extends EventEmitter {
3940
});
4041

4142
this.rl.on("close", () => {
43+
// readline can close spuriously (e.g. when ora clears lines).
44+
// Only truly exit on Ctrl+C (SIGINT) or explicit exit/quit command.
45+
// Recreate readline to keep accepting input.
46+
if (!this.intentionalClose) {
47+
this.rl = null;
48+
this.start();
49+
}
50+
});
51+
52+
process.on("SIGINT", () => {
4253
this.emit("exit");
4354
});
4455
}
4556

4657
/** Stop listening */
4758
stop(): void {
59+
this.intentionalClose = true;
4860
this.rl?.close();
4961
this.rl = null;
5062
}

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ async function main() {
113113
// Create LLM provider
114114
const llm = createOpenAIProvider(config.llm);
115115

116-
// Spinner for loading states
117-
const spinner = ora({ spinner: "dots", color: "cyan" });
116+
// Spinner for loading states — must use stderr to avoid conflicting with readline on stdout
117+
const spinner = ora({ spinner: "dots", color: "cyan", stream: process.stderr });
118118
let streamingStarted = false;
119119

120120
// Create agent with callbacks

0 commit comments

Comments
 (0)