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