Add --session option to focus-tab command#19784
Add --session option to focus-tab command#19784shanselman wants to merge 1 commit intomicrosoft:mainfrom
Conversation
a2dd48f to
77934eb
Compare
Adds the ability to focus a tab by its WT_SESSION GUID, enabling external processes (like AI coding agents) to programmatically return users to the correct terminal tab. Usage: wt focus-tab --session <guid> or: wt ft -s <guid> Changes: - Added --session/-s option to focus-tab CLI parser - Extended SwitchToTabArgs with SessionId property - Added FocusPaneBySessionId() to Tab class to walk pane tree - Modified _HandleSwitchToTab to lookup by session ID - Auto-routes to existing window (implicit -w 0) for session targeting - Added unit tests for --session parsing Fixes microsoft#19783
7f4efb8 to
65961ae
Compare
|
As much as I'd like to accept this, I worry about its impact on the Windows application ecosystem in the long-term. I understand the need for long-running tasks to bring the user back to focus on them, but I think allowing them to bring Terminal to the foreground and demand focus for themselves sets the wrong precedent. Even though you're launching it from a notification (good) with user consent (good), Contoso may not be so kind as to ask first. I'd rather tackle this by allowing VT-compliant applications to natively request notifications (ala OSC 777); that puts Terminal back in control of the interaction. It also works better in remote sessions (SSH, WSL) and moves the ecosystem forward. |
|
This will also be hampered by #13006 - when a process gets yott into Terminal it doesn't have access to |
|
This is a feature I really want. However, I tried this PR, and it seems to have a bug. In the Windows Terminal compiled from this PR, whenever I click Settings, the program freezes briefly and then exits. Does the version you compiled behave the same way? If not, could you share the compiled binary version with me? |
Summary of the Pull Request
Adds a
--session/-soption to thewt focus-tabcommand that accepts aWT_SESSIONGUID. This allows external processes to programmatically focus the exact terminal tab and pane where a specific shell session is running.Primary use case: AI coding agents (GitHub Copilot CLI, Claude Code, Cursor, Aider, etc.) run long-running tasks in terminal sessions. When the task completes, users have often alt-tabbed away and opened many other tabs. This feature lets agents bring users back to the correct tab automatically:
References and Relevant Issues
Detailed Description of the Pull Request / Additional comments
Usage
What it does
WT_SESSIONGUIDImplementation
AppCommandlineArgs.cpp--session/-soption with GUID parsing. Auto-sets-w 0. UpdatedValidateStartupCommands().AppCommandlineArgs.h_focusTabSessionmemberActionArgs.idlSwitchToTabArgswithGuid SessionIdpropertyActionArgs.hSWITCH_TO_TAB_ARGSmacroAppActionHandlers.cpp_HandleSwitchToTab()to find session and callFocusPaneBySessionId()Tab.cppFocusPaneBySessionId()- walks pane tree, calls_rootPane->FocusPane(pane)Tab.hFocusPaneBySessionId()Resources.reswTerminalPage.cppDesign decisions
12345678-1234-...and{12345678-...}formats-w 0since session GUID uniquely identifies a pane--sessionexcludes--target,--next,--previousValidation Steps Performed
wt focus-tab --helpshows new--sessionoptionPR Checklist