xonecas.io
64875
Mc

mini-coder / commit a5c6a4f

fix: allow graceful interrupt of tool calls on Ctrl+C

Sean2026-03-02 a5c6a4f0c6cebec8fb537e7b88fe10ca06372b89 parent e3249c4

3 files changed

TODO.md+1−25
@@ -9,34 +9,10 @@
99
1010 ## Subagents are spawing more subagents for no reason.
1111
12-- Remove the subagent tool from subagents.
13-- Update the subagent prompt specify to not delegate work.
12+Sometimes, a subagent spawns another subagent to do a task, and it enters an endless loop of spawing more subagents.
1413
1514 ---
1615
17-## CTRL+c during a tool call still exits the app instead of interrupting.
18-
19-As the title says, see example output:
20-
21-```
22-gpt-5.3-codex mm8agcuc ~/src/mini-coder ⎇ main ctx 31.8k/128.0k 25% ↑502.9k ↓2.9k
23-▶ /release
24-· release [.agents/commands/release.md]
25-
26-$ $ bun run typecheck && bun run format && bun run lint && bun test
27- ✔ 0
28-← read package.json:1+200
29- · 37 lines
30-✎ replace package.json 3:a0–3:a0
31-⠹ thinking ✔ hook post-replace
32- ✔ replaced package.json
33-$ $ bun run build
34- ✔ 0
35-$ $ git add -A && git commit -m "chore: release v0.0.10" && git tag v0.0.… <- Shell command hanguing waiting for user input for the git tag call
36-error: script "dev" exited with code 130 <- ctrl+c by the user in hopes to return to the prompt, but app exited.
37-```
38----
39-
4016 ## `/model` thinking-effort toggle
4117
4218 The idea specifies: *"/model allows the user to pick a model as well as thinking
src/cli/input.ts+9−2
@@ -8,6 +8,7 @@ import {
88 loadImageFile,
99 } from "./image-types.ts";
1010 import { loadSkills } from "./skills.ts";
11+import { terminal } from "./terminal-io.ts";
1112
1213 // ─── ANSI escape sequences ────────────────────────────────────────────────────
1314
@@ -195,12 +196,16 @@ export function watchForInterrupt(
195196 ): () => void {
196197 if (!process.stdin.isTTY) return () => {};
197198
199+ const onInterrupt = () => {
200+ cleanup();
201+ abortController.abort();
202+ };
203+
198204 const onData = (chunk: Buffer) => {
199205 for (const byte of chunk) {
200206 if (byte === 0x03) {
201207 // Ctrl+C received — abort and clean up immediately.
202- cleanup();
203- abortController.abort();
208+ onInterrupt();
204209 return;
205210 }
206211 }
@@ -208,10 +213,12 @@ export function watchForInterrupt(
208213
209214 const cleanup = () => {
210215 process.stdin.removeListener("data", onData);
216+ terminal.setInterruptHandler(null);
211217 process.stdin.setRawMode(false);
212218 process.stdin.pause();
213219 };
214220
221+ terminal.setInterruptHandler(onInterrupt);
215222 process.stdin.setRawMode(true);
216223 process.stdin.resume();
217224 process.stdin.on("data", onData);
src/cli/terminal-io.ts+11−3
@@ -3,7 +3,11 @@ export type SignalHandler = () => void;
33 export class TerminalIO {
44 private cleanupHandlers: Set<() => void> = new Set();
55 private rawModeEnabled = false;
6- private abortController = new AbortController();
6+ private interruptHandler: (() => void) | null = null;
7+
8+ setInterruptHandler(handler: (() => void) | null): void {
9+ this.interruptHandler = handler;
10+ }
711
812 stdoutWrite(text: string): void {
913 process.stdout.write(text);
@@ -48,8 +52,12 @@ export class TerminalIO {
4852 process.exit(143);
4953 });
5054 process.on("SIGINT", () => {
51- cleanup();
52- process.exit(130);
55+ if (this.interruptHandler) {
56+ this.interruptHandler();
57+ } else {
58+ cleanup();
59+ process.exit(130);
60+ }
5361 });
5462 process.on("uncaughtException", (err) => {
5563 cleanup();