fix(tasks): keep agent input focused after sidebar switch
Description
- keep agent input focused after switching back to conversation in sidebar
- refocuses the active conversation pty onyl when main content has focus
Checklist
- [X] I kept this PR small and focused
- [X] I ran a self-review before opening this PR
- [X] I ran the relevant local checks or explained why not
- [X] I updated docs when behavior or setup changed
- [X] I added or updated tests when behavior changed, or explained why not
- [X] I only added comments where the logic is not obvious
- [X] I used Conventional Commits for commit messages and, when possible, the PR title
Greptile Summary
This PR restores focus to the active conversation's PTY terminal whenever the user switches back to the conversations sidebar tab, but only when the main content region is active โ ensuring the terminal drawer's own focus state is never stolen.
- Adds a private
focusActiveConversationTerminalmethod that walksconversationRegistry โ sessions โ pty โ terminal.focus()via optional chaining, with an early-exit guard for a missing active conversation ID. setSidebarTabnow calls the helper only whenv === 'conversations' && focusedRegion === 'main', keeping the guard logic co-located with the tab-switch side effect.- A new test verifies both the focus path (
focusedRegion === 'main') and the no-focus path (focusedRegion === 'bottom') in a single, well-structured scenario.
Confidence Score: 5/5
Safe to merge โ the change is minimal, well-guarded, and directly tested.
The new code path is a single conditional inside setSidebarTab with optional-chaining throughout, so a missing registry entry or null PTY session degrades gracefully to a no-op. The focusedRegion guard is exercised by the new test, which confirms focus is called exactly once on the happy path and not at all when the terminal drawer has focus.
No files require special attention.
Important Files Changed
| Filename | Overview |
|---|---|
| apps/emdash-desktop/src/renderer/features/tasks/stores/workspace-view-model.tsx | Adds a private focusActiveConversationTerminal helper and calls it from setSidebarTab when switching to conversations only if focusedRegion === 'main'. Logic is tight and the guard correctly prevents stealing focus from the terminal drawer. |
| apps/emdash-desktop/src/renderer/features/tasks/stores/workspace-view-model.test.ts | New test covers both the happy path (focus called when switching to conversations with main focused) and the guard (focus not called when bottom region is focused). Clean setup and teardown with dispose() at the end. |
Sequence Diagram
sequenceDiagram
participant User
participant Sidebar
participant WorkspaceViewModel
participant ConversationRegistry
participant PtyTerminal
User->>Sidebar: click "conversations" tab
Sidebar->>WorkspaceViewModel: setSidebarTab('conversations')
WorkspaceViewModel->>WorkspaceViewModel: "sidebarTab = 'conversations'"
alt "focusedRegion === 'main'"
WorkspaceViewModel->>WorkspaceViewModel: focusActiveConversationTerminal()
WorkspaceViewModel->>ConversationRegistry: get(taskId)?.sessions.get(conversationId)
ConversationRegistry-->>WorkspaceViewModel: PtySession
WorkspaceViewModel->>PtyTerminal: terminal.focus()
else "focusedRegion === 'bottom'"
WorkspaceViewModel-->>Sidebar: (no focus action)
end
Reviews (2): Last reviewed commit: "fix(tasks): guard conversation terminal ..." | Re-trigger Greptile
@greptileai
Thanks for catching this and for the fix, @janburzinski small screen recording would help next time ๐
happy to merge after recording:)
before: https://streamable.com/xeygn1
after: https://streamable.com/swjxdw
again my bad, but here is the demo :D @arnestrickmann
lgtm!