| ... | ... | @@ -314,14 +314,20 @@ export default function ChatView() { |
| 314 | 314 | const closeTerminal = useCallback( |
| 315 | 315 | (terminalId: string) => { |
| 316 | 316 | if (!activeThreadId || !api) return; |
| 317 | const isFinalTerminal = (activeThread?.terminalIds.length ?? 0) <= 1; |
| 317 | 318 | const fallbackExitWrite = () => |
| 318 | 319 | api.terminal |
| 319 | 320 | .write({ threadId: activeThreadId, terminalId, data: "exit\n" }) |
| 320 | 321 | .catch(() => undefined); |
| 321 | 322 | if ("close" in api.terminal && typeof api.terminal.close === "function") { |
| 322 | | void api.terminal |
| 323 | | .close({ threadId: activeThreadId, terminalId, deleteHistory: true }) |
| 324 | | .catch(() => fallbackExitWrite()); |
| 323 | void (async () => { |
| 324 | if (isFinalTerminal) { |
| 325 | await api.terminal |
| 326 | .clear({ threadId: activeThreadId, terminalId }) |
| 327 | .catch(() => undefined); |
| 328 | } |
| 329 | await api.terminal.close({ threadId: activeThreadId, terminalId, deleteHistory: true }); |
| 330 | })().catch(() => fallbackExitWrite()); |
| 325 | 331 | } else { |
| 326 | 332 | void fallbackExitWrite(); |
| 327 | 333 | } |
| ... | ... | @@ -332,7 +338,7 @@ export default function ChatView() { |
| 332 | 338 | }); |
| 333 | 339 | setTerminalFocusRequestId((value) => value + 1); |
| 334 | 340 | }, |
| 335 | | [activeThreadId, api, dispatch], |
| 341 | [activeThread?.terminalIds.length, activeThreadId, api, dispatch], |
| 336 | 342 | ); |
| 337 | 343 | |
| 338 | 344 | const handleRuntimeModeChange = async (mode: "approval-required" | "full-access") => { |