fix(vscode): persist Agent Manager focus per session - #12801
Conversation
Remember whether each session last focused the prompt or its right-side embedded terminal, and restore that focus owner when switching back. - Add a focus-owner map keyed by (context, session) in AgentManagerApp that records the last focused surface per session. - Make side-terminal creation explicit: / focus the new terminal, while and context switches do not. - Suppress the PromptInput draft-change focus dispatch when the target session's remembered owner is the terminal. - Side terminals opt out of auto-focus on activation via a new prop so context switches don't steal the cursor. - Replace the unconditional prompt dispatch with a restore-focus path that follows the saved owner. - Add regression tests distinguishing explicit vs background side creates, and a changeset.
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Resolved since last review
Files Reviewed (1 file changed since last review)
Fix these issues in Kilo Cloud Previous Review Summaries (3 snapshots, latest commit ab296d4)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit ab296d4)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)SUGGESTION
Resolved since last review
Files Reviewed (1 file changed since last review)
Fix these issues in Kilo Cloud Previous review (commit b0e60e9)Status: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Resolved since last review
Files Reviewed (4 files changed since last review)
Fix these issues in Kilo Cloud Previous review (commit 66427c4)Status: 4 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)WARNING
SUGGESTION
Files Reviewed (8 files)
Reviewed by claude-opus-5 · Input: 44 · Output: 8.2K · Cached: 1.4M Review guidance: REVIEW.md from base branch |
| focusMemory.delete(key) | ||
| return true | ||
| } | ||
| return terminalVisible() ? false : true |
There was a problem hiding this comment.
SUGGESTION: x ? false : true is just !x
Minor readability nit on the new guard. While here, the freshly extracted terminalVisible() isn't reused at the two other spots that still spell the condition out inline (if (focus && sidePanel() === "terminal" && !history() && !reviewActive() && ...) around line 1327, and visible: () => sidePanel() === "terminal" && !history() && !reviewActive() around line 2068). Routing those through the helper keeps the four call sites from drifting apart later.
| return terminalVisible() ? false : true | |
| return !terminalVisible() |
Reply with @kilocode-bot fix it to have Kilo Code address this issue.
* fix(vscode): persist Agent Manager focus per session Remember whether each session last focused the prompt or its right-side embedded terminal, and restore that focus owner when switching back. - Add a focus-owner map keyed by (context, session) in AgentManagerApp that records the last focused surface per session. - Make side-terminal creation explicit: / focus the new terminal, while and context switches do not. - Suppress the PromptInput draft-change focus dispatch when the target session's remembered owner is the terminal. - Side terminals opt out of auto-focus on activation via a new prop so context switches don't steal the cursor. - Replace the unconditional prompt dispatch with a restore-focus path that follows the saved owner. - Add regression tests distinguishing explicit vs background side creates, and a changeset. * fix(vscode): address Agent Manager focus review * fix(vscode): self-heal stale Agent Manager focus * fix(vscode): align Agent Manager focus visibility
The Agent Manager webview steals the prompt cursor whenever a session or worktree switch happens while the right-side embedded terminal is open. This was caused by three independent focus paths that all unconditionally dispatched
focusPrompt: the draft-key effect inPromptInput, theonWindowFocushandler inAgentManagerApp, and the side-terminal activation transition inTerminalTab. None of them knew whether the target session last used the prompt or the terminal.What changed
AgentManagerAppnow keeps afocusMemorymap keyed by(context, session)that records whether the last focused surface in that session was the prompt or a specific side-terminal id. The key is derived fromterms.sideKey()+session.currentSessionID()so it tracks the actual chat session, not just the worktree.requestSide()andaddSide()passfocus=true;ensureSide()and background context switches passfocus=false. The newfocusflag travels throughbeginSide→SideRequest→onSideCreatedso the handler only callsrequestFocuswhen the user explicitly opened the terminal.focusOnActivateprop onTerminalTabprevents theactiveprop transition from stealing the cursor when a context switch makes a remembered terminal visible without an explicit focus request.PromptInputaccepts afocusOnDraftChangeaccessor; Agent Manager passesfocusPromptForSessionwhich returnsfalsewhen the target session's remembered owner is the terminal.onWindowFocusprompt dispatch is replaced withrestoreFocus(), which either re-focuses the remembered terminal (when the side panel is still open) or falls through to the prompt.Validation
bun run compile,bun run check-types,bun run lintall pass.agent-manager-terminal-state.test.tsnow distinguish explicit vs background side creates and assert thefocusflag on the resultingonSideCreatedcallback.