cli: exit on stdin EOF and drop the console wide Ctrl+C broadcast (#29722)

* cli: exit on stdin EOF and drop the console wide Ctrl+C broadcast

On Windows the simple input reader sends CTRL_C_EVENT to every process
attached to the console when stdin reaches EOF, killing unrelated
processes such as a supervising agent. The CLI only stopped on EOF
because of that self inflicted SIGINT; on POSIX, and with the advanced
reader, it spins forever printing prompts.

Drop the broadcast so both platforms just return an empty read, and
treat an empty read as EOF in the chat loop and the model selection,
since a submitted line always ends with a newline.

* cli: keep the newline of a trailing "/" and stop mtmd-cli on EOF

A lone "/" came back as an empty read and was taken for EOF, and
mtmd-cli only stopped on EOF through the removed broadcast.
This commit is contained in:
Pascal
2026-09-30 16:24:46 +02:00
committed by GitHub
parent 22bdcc4cdd
commit b04642061d
3 changed files with 13 additions and 4 deletions
+7 -2
View File
@@ -255,7 +255,7 @@ bool cli_context::list_and_ask_models() {
ui::user_turn user_turn;
selection = user_turn.read_input(false, "Select model by number: ");
if (selection.empty()) {
continue;
return false;
}
try {
size_t idx = std::stoul(selection);
@@ -502,8 +502,13 @@ int cli_context::run() {
break;
}
// a submitted line always ends with a newline, an empty read is EOF
if (buffer.empty()) {
break;
}
// remove trailing newline
if (!buffer.empty() && buffer.back() == '\n') {
if (buffer.back() == '\n') {
buffer.pop_back();
}