Repository navigation
fix: inherit active pane profile in agent-created terminals to match … - #366
Conversation
…WSL/Ubuntu session instead of default profile
|
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
Pull request overview
This PR fixes agent-created terminals defaulting to the user’s default profile by propagating the effective active pane’s profile name through the WTA Rust → wtcli → COM CreateTab pipeline, so a new tab created while working in (for example) a WSL/Ubuntu profile launches as the same profile.
Changes:
- WTA
ShellManagerqueriesget_active_paneand forwards itsprofilevalue into thecreate_tabrequest payload. - WTA
CliChannelforwardsprofiletowtcli new-tabvia a new-p/--profileargument. wtcli new-tabadds-p/--profileand passes it through to the COM serverCreateTabcall.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tools/wta/src/shell/wt_channel/cli_channel.rs | Forwards optional profile parameter to wtcli new-tab. |
| tools/wta/src/shell/shell_manager.rs | Reads active pane profile and includes it in create_tab parameters. |
| src/tools/wtcli/main.cpp | Adds --profile to new-tab and passes it to CreateTab. |
|
Nice work, thanks for picking this up! One gap before it fully closes #351: This covers the ACP Could you also thread the active pane's profile through |
|
Kai Tao (@vanzue) Good catch — you're right, the agents use the coordinator path, not the ACP one. I've now fixed both open and open_and_send to automatically pick up the active pane's profile (e.g. "Ubuntu") and pass it through when creating new tabs or panels. The -p/--profile flag I already added to wtcli new-tab is now also wired into split-pane, and all the Rust plumbing connects them together. So whether the agent opens a tab or splits a panel, the new terminal will match the current shell session instead of falling back to the default profile. Please check now. |
The profile field is destructured by reference (&Option<String>), so the Some(p) if !p.is_empty() => Some(p) arm produced Option<&String> while the fallback arm produced owned Option<String>, failing to compile. Clone in the first arm so both arms are Option<String>. Co-authored-by: Copilot <[email protected]>
| // Resolve profile: prefer explicit from LLM, fall back to active pane's profile | ||
| let profile = match profile { | ||
| Some(p) if !p.is_empty() => Some(p.clone()), | ||
| _ => shell_mgr | ||
| .wt_get_active_pane() | ||
| .await | ||
| .ok() | ||
| .and_then(|v| v.get("profile").and_then(|v| v.as_str()).map(|s| s.to_owned())), | ||
| }; |
| // Resolve profile: prefer explicit from LLM, fall back to active pane's profile | ||
| let profile = match profile { | ||
| Some(p) if !p.is_empty() => Some(p.clone()), | ||
| _ => shell_mgr | ||
| .wt_get_active_pane() | ||
| .await | ||
| .ok() | ||
| .and_then(|v| v.get("profile").and_then(|v| v.as_str()).map(|s| s.to_owned())), | ||
| }; |
Extract the profile-resolution logic from execute_choice into a pure resolve_agent_profile() helper and unit-test it, replacing three duplicated inline copies (two in coordinator.rs, one in ShellManager::create_terminal_wt). The helper now also filters an empty active-pane profile to None so all three paths behave consistently and downstream lets Windows Terminal pick the default. Tests: - resolve_agent_profile: explicit-over-active, fallback, empty-explicit, empty/missing/non-string active-pane profile, both-unavailable. - serde: Open/OpenAndSend parse an explicit profile and default to None when the field is absent (pre-microsoft#366 schema compatibility). Co-authored-by: Copilot <[email protected]>
When the active pane is a WSL profile, its reported working directory is a POSIX path (e.g. /home/user). The delegate flow (?<prompt> / Alt+Shift+/) launches a Windows agent CLI (Copilot/Claude/Gemini) and passed that POSIX cwd straight through, which is not a valid working directory for a Windows process — the CLI failed to launch. Add a pure, unit-tested sanitize_windows_agent_cwd() helper: a bare POSIX absolute path falls back to %USERPROFILE% (or is dropped when unavailable), while Windows drive-letter paths, UNC paths (//wsl.localhost/..., \\\\...), and relative paths pass through unchanged. Apply it in delegate_with_context before creating the tab. Running an agent natively inside WSL (so it honors the Linux cwd and uses the WSL toolchain) remains a separate future feature; this is only a guard so the Windows agent CLI doesn't crash on an unusable cwd. Co-authored-by: Copilot <[email protected]>
This comment has been minimized.
This comment has been minimized.
|
Reviewed end-to-end — approach is sound. Pushed 3 commits:
Verified: profile inheritance works for shell opens (#351 goal); no agent-pane leak ( Known limitation: for a Windows agent CLI launched from a WSL pane, inheriting the WSL profile/cwd can't truly "run inside WSL" — the proper fix is running the CLI natively via Thanks a lot for the contribution, Aditya Bagchi (@adityabagchi24)! Really appreciate you tackling #351, and looking forward to more contributions from you. 🙏 |
check-spelling's line_forbidden.patterns rejects ', otherwise' (wants '; otherwise' or '. Otherwise'). Adjust the sanitize_windows_agent_cwd doc comment accordingly. Co-authored-by: Copilot <[email protected]>
|
Kai Tao (@vanzue) Thank you so much for the thorough review and for taking the time to improve the implementation. I really appreciate you fixing the compile issue, refactoring the duplicated logic, adding comprehensive tests, and addressing the WSL working directory edge case. The explanations were very helpful, especially regarding the current limitation with WSL and the rationale for leaving the native wsl -e approach as a future enhancement. |
Second review pass over the release checklist against the v0.1.2 release notes: - Added a [new] coverage marker to the legend and tagged all 12 genuinely-new v0.1.2 test cases with it (the two reworded existing cases — F5 refresh, ACP-sourced historical — are corrections, not new cases, so they stay untagged). - Added 5 more previously-missing cases surfaced by a closer read: - FRE execution-policy detection is correct / no false-block on probe timeout (#336/#338/#309) - wta-master death is a consistent degraded state requiring /restart, no split-brain (#329) - Session titles are clean (no bare '# AGENTS.md instructions' heading) (#355) - Focus brings the target window to the foreground (#353) - Agent-created terminals inherit the active pane profile (#366, closes #351) Co-authored-by: Copilot <[email protected]>
* docs(release-check-list): sync with v0.1.2 features Reviewed the release checklist against the v0.1.2 release notes and fixed two outdated statements plus added seven missing test cases for new features. Outdated statements corrected: - Session view refresh: now F5 on-demand re-scan (incl. WSL distros started after launch), not gated on hooks (#344). - Historical state: history is now sourced from ACP session/list, not on-disk file parsing (#365). Missing test cases added: - Alt+V clipboard image paste into agent chat (#354) - GitHub Enterprise Copilot sign-in (#362) - Bash/WSL shell integration incl. set -u safety (#340) - Shells self-report identity via OSC 9001;ShellType + nested-shell autofix targeting (#345) - Environment-aware answers/fixes: investigate PATH before answering/autofixing (#306) - WSL distro sessions visible and resumable in the correct distro (#323) - Agent panes not persisted into saved window layout (#360/#275) Co-authored-by: Copilot <[email protected]> * docs(release-check-list): tag new v0.1.2 cases with [new] + add 5 more Second review pass over the release checklist against the v0.1.2 release notes: - Added a [new] coverage marker to the legend and tagged all 12 genuinely-new v0.1.2 test cases with it (the two reworded existing cases — F5 refresh, ACP-sourced historical — are corrections, not new cases, so they stay untagged). - Added 5 more previously-missing cases surfaced by a closer read: - FRE execution-policy detection is correct / no false-block on probe timeout (#336/#338/#309) - wta-master death is a consistent degraded state requiring /restart, no split-brain (#329) - Session titles are clean (no bare '# AGENTS.md instructions' heading) (#355) - Focus brings the target window to the foreground (#353) - Agent-created terminals inherit the active pane profile (#366, closes #351) Co-authored-by: Copilot <[email protected]> * test(e2e): add master-death degraded-state integration test (#329); drop rolled-back WSL session checklist item Adds Feature.AgentMasterDeath.Tests.ps1: kills this app's wta-master out from under a live helper and asserts the full #329 contract end-to-end — the pane leaves Connected, the / popup is filtered to only /restart, NO master is silently respawned while degraded (anti-split-brain), and /restart brings up exactly one fresh master and reconnects. Verified passing live against the deployed dev package. Also removes the '[new] WSL distro sessions are visible and resumable' checklist item (#323) since WSL in-distro session support is being rolled back for v0.1.2, and drops the WSL example from the F5 refresh item to match. Co-authored-by: Copilot <[email protected]> * Address Copilot review: tighten master-count assertion and clarify Alt+V behavior - Feature.AgentMasterDeath.Tests.ps1: assert exactly one wta-master while connected (-Be 1, was -BeGreaterThan 0) so the connected-state gate itself catches a split-brain regression. Re-verified passing live. - release-check-list.md: correct the Alt+V item — Alt+V queues the image until the next prompt, and an unsupported agent / empty clipboard surfaces a clear system message rather than being a silent no-op. The [WSL-<distro>] raw-angle-bracket comment is already resolved: that checklist item was removed with the WSL session rollback. Co-authored-by: Copilot <[email protected]> * Address Copilot review round 2: block /stop in degraded popup test, release-agnostic [new] marker, spelling fix - Feature.AgentMasterDeath.Tests.ps1: add /stop to the blocked-slash-command list so a regression that offers /stop while transport-lost is caught (it's a real CommandKind::Stop). Re-verified passing live. - release-check-list.md: reword the [new] marker in release-agnostic terms and say when to clear it (was hard-coded to v0.1.2); fix forbidden spelling non-existent -> nonexistent (check-spelling CI). Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
…ng shut Delegating (?<prompt>) to a non-existent / misconfigured agent opened a tab that flashed shut before the user could read the error. The previous workaround opened a *separate* canned-message `cmd /k` tab; this restores the original behavior of keeping the real error visible in the tab that ran the command, and removes the second tab. Root cause: a protocol `create_tab` that carries a commandline but no profile resolves (via CascadiaSettings::GetProfileForArgs) to the "Defaults" profile, whose pane is auto-closed on *any* process exit -- even a non-zero one. So the doomed `cmd /c <agent>` exited (code 1) and WT closed the pane before the "'<agent>' is not recognized" error was readable. Verified live: a no-profile `wtcli new-tab -c "cmd /c exit 1"` flashed shut, while the same command with an explicit profile stayed open. Fix (two parts): - C++ (TerminalPage.Protocol.cpp): CreateProtocolTab now pins a real profile when the caller specifies none -- the profile of the pane the user is currently working in (so a delegate/agent tab opened from e.g. a WSL/Ubuntu session matches it, same intent as PR #366), falling back to the user's global default profile when there is no focused terminal. Its closeOnExit (automatic/graceful) keeps a non-zero exit visible, exactly like a normally- opened tab. This is never left empty -- that's what re-introduces the auto- closing "Defaults" profile. This fixes every no-profile protocol tab, not just the delegate. An explicitly-requested profile is left untouched; if the resolved GUID somehow can't be matched, GetProfileForArgs falls back to the same "Defaults" profile as before (no regression). - WTA (delegate_with_context): a non-launchable delegate agent is now launched as a bare `cmd /c <agent>` (no baked prompt) so it fails cleanly with a non-zero exit. This keeps the doomed launch out of the fragile prompt-baking path, where a stray `"`/`&` in the pane context could unbalance cmd's quoting and make cmd exit 0 (which the profile would then close). Replaces the separate `cmd /k` error tab. Co-authored-by: Copilot <[email protected]>
…ng shut (#390) * fix: keep a misconfigured delegate agent's tab open instead of flashing shut Delegating (?<prompt>) to a non-existent / misconfigured agent opened a tab that flashed shut before the user could read the error. The previous workaround opened a *separate* canned-message `cmd /k` tab; this restores the original behavior of keeping the real error visible in the tab that ran the command, and removes the second tab. Root cause: a protocol `create_tab` that carries a commandline but no profile resolves (via CascadiaSettings::GetProfileForArgs) to the "Defaults" profile, whose pane is auto-closed on *any* process exit -- even a non-zero one. So the doomed `cmd /c <agent>` exited (code 1) and WT closed the pane before the "'<agent>' is not recognized" error was readable. Verified live: a no-profile `wtcli new-tab -c "cmd /c exit 1"` flashed shut, while the same command with an explicit profile stayed open. Fix (two parts): - C++ (TerminalPage.Protocol.cpp): CreateProtocolTab now pins a real profile when the caller specifies none -- the profile of the pane the user is currently working in (so a delegate/agent tab opened from e.g. a WSL/Ubuntu session matches it, same intent as PR #366), falling back to the user's global default profile when there is no focused terminal. Its closeOnExit (automatic/graceful) keeps a non-zero exit visible, exactly like a normally- opened tab. This is never left empty -- that's what re-introduces the auto- closing "Defaults" profile. This fixes every no-profile protocol tab, not just the delegate. An explicitly-requested profile is left untouched; if the resolved GUID somehow can't be matched, GetProfileForArgs falls back to the same "Defaults" profile as before (no regression). - WTA (delegate_with_context): a non-launchable delegate agent is now launched as a bare `cmd /c <agent>` (no baked prompt) so it fails cleanly with a non-zero exit. This keeps the doomed launch out of the fragile prompt-baking path, where a stray `"`/`&` in the pane context could unbalance cmd's quoting and make cmd exit 0 (which the profile would then close). Replaces the separate `cmd /k` error tab. Co-authored-by: Copilot <[email protected]> * address PR review: scope the profile pin, redact delegate log, fix spelling - TerminalPage.Protocol.cpp: only pin a profile for the case that actually hits the bug -- a commandline with no explicit profile AND no ProfileIndex. A caller that omits the commandline already lands on the user's real default profile (not the auto-closing "Defaults"), and a profile-by-index request must be honored, so neither is overridden now. - main.rs: the "not launchable" warn logs only the executable (first token), not the full delegate commandline, which could embed a custom agent's tokens/credentials. The full commandline stays trace-only. - coordinator.rs: generalize the delegate_command_launchable doc -- the bare launch is only shell-wrapped when needs_shell_launch is true (a direct .exe miss fails to start instead), so the comment no longer hard-codes `cmd /c`. - main.rs: spelling -- "non-existent" -> "nonexistent" (check-spelling forbidden pattern). Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
Summary of the Pull Request
When the AI agent launches a new terminal, it now matches the active session's profile (e.g. WSL/Ubuntu) instead of falling back to the user's default profile (e.g. PowerShell).
References and Relevant Issues
Closes #351
Detailed Description of the Pull Request / Additional comments
The agent's
create_terminalcommand was creating new tabs without specifying a profile, so Windows Terminal would fall back to the default profile. This meant an agent running in an Ubuntu session would spawn new terminals in PowerShell.The fix pipes the active pane's profile name through the entire chain: Rust
ShellManager→CliChannel→wtcli→ COMCreateTab. Now when the agent creates a terminal, the new tab uses the same profile as the currently active pane.Validation Steps Performed
Traced the full data flow end-to-end: the profile name is fetched from the active pane, passed through to the COM
CreateTabcall, and resolved to the correct profile by Windows Terminal's settings engine.PR Checklist