fix(terminal): honor configured terminal profile in background exec mode#11283
fix(terminal): honor configured terminal profile in background exec mode#11283sanidhyasin wants to merge 3 commits into
Conversation
Greptile SummaryThis PR fixes
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to StandaloneTerminalManager and correctly mirrors the already-working VscodeTerminalManager behavior. The logic is straightforward: profile id resolution is added in exactly two places (terminal creation and profile-change cleanup), the default-profile path (shellPath = undefined) is preserved unchanged, and the new tests validate all three behavioural cases across both posix and Windows platforms. No regressions were found in terminal reuse, background-command tracking, or the handleTerminalProfileChange cleanup path. No files require special attention.
|
| Filename | Overview |
|---|---|
| apps/vscode/src/integrations/terminal/standalone/StandaloneTerminalManager.ts | Core fix: resolves the configured terminal profile to a shell path in getOrCreateTerminal() and setDefaultTerminalProfile(), mirroring VscodeTerminalManager; terminal matching and creation now both honour the expectedShellPath. |
| apps/vscode/src/integrations/terminal/tests/StandaloneTerminalManager.profile.test.ts | New unit tests covering profile-to-shell-path resolution, default-profile preservation, and cross-profile terminal isolation; platform-aware profile selection handled correctly. |
| .changeset/honest-otters-shine.md | Patch-level changeset entry accurately describing the terminal profile fix. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["getOrCreateTerminal(cwd)"] --> B["Resolve expectedShellPath\n(profile !== 'default'\n ? getShellForProfile(profile)\n : undefined)"]
B --> C{"Find terminal\n!busy &&\nshellPath === expected &&\n_cwd === cwd?"}
C -- match --> D["Return existing terminal"]
C -- no match --> E{"terminalReuseEnabled?"}
E -- yes --> F{"Find terminal\n!busy &&\nshellPath === expected?"}
F -- match --> G["cd to cwd\nReturn reused terminal"]
F -- no match --> H["Create new terminal\nwith shellPath = expected"]
E -- no --> H
H --> I["registry.createTerminal\n({ cwd, name, shellPath })"]
I --> J["TerminalInfo.shellPath set\n→ StandaloneTerminalProcess.run\n uses shellPath"]
K["setDefaultTerminalProfile(profile)"] --> L["previousProfile !== profile?"]
L -- yes --> M["newShellPath =\nprofile !== 'default'\n ? getShellForProfile(profile)\n : undefined"]
M --> N["handleTerminalProfileChange(newShellPath)\nclose idle terminals where\nshellPath !== newShellPath"]
L -- no --> O["return {closedCount:0, busyTerminals:[]}"]
Reviews (3): Last reviewed commit: "test(terminal): use built-in Windows Pow..." | Re-trigger Greptile
|
Pushed a follow-up (a0eaca0):
|
|
Both changes look good. The test file is clean and the fixes are well-reasoned:
One minor note: Otherwise this is solid — nice work addressing both points. Tip: You can customize Greptile's behavior for this repo with |
|
Good catch on the PS7 assumption — switched the Windows pair to For the record: |
In background execution mode the StandaloneTerminalManager always spawned the system default shell, ignoring the user's "Default Terminal Profile" setting. Unlike VscodeTerminalManager, it never resolved the configured profile to a shell path when creating terminals. Resolve the profile to a shell path via getShellForProfile() and pass it when creating terminals, and match/reuse terminals by shell path so that switching profiles spawns the correct shell. Also resolve the profile id before handleTerminalProfileChange(), which expects a shell path. Fixes cline#11017
…assertion The reuse test assumed bash/zsh resolve to distinct shells, which fails on Windows where getAvailableTerminalProfiles() exposes powershell/cmd instead (both bash and zsh fell back to the same default shell, so the terminal was reused). Pick a platform-appropriate pair of profiles and guard the distinctness assertion in case a platform ever maps them to the same shell. Also drop the redundant private _shellPath assertion per review feedback: terminalInfo.shellPath already carries the same value the registry assigns.
powershell-legacy (Windows PowerShell 5.x) is present on every Windows install, whereas powershell-7 may be absent on a CI runner. Both resolve to distinct constant paths vs cmd, so this only hardens the test's assumptions.
f1da853 to
90f57ea
Compare
Related Issue
Issue: #11017
Description
When the terminal Execution Mode is set to Background Exec, Cline ignored the Default Terminal Profile setting and always spawned the system default shell (e.g.
fish), even when the user explicitly selected another profile (e.g.bash).The root cause is in
StandaloneTerminalManager(used for background execution, and in CLI/JetBrains environments). UnlikeVscodeTerminalManager, it never resolved the configureddefaultTerminalProfileinto a shell path:getOrCreateTerminal()created terminals without ashellPath, soStandaloneTerminalProcess.run()fell back toprocess.env.SHELL || "/bin/bash".setDefaultTerminalProfile()passed the raw profile id (e.g."bash") intohandleTerminalProfileChange(), which expects a shell path.This change mirrors the existing, working behavior of
VscodeTerminalManager:getShellForProfile()and pass it asshellPathwhen creating terminals.shellPath, so switching profiles spawns the correct shell instead of reusing a terminal running the old shell.handleTerminalProfileChange().getShellForProfile()maps"default"toundefined(preserving the existing default-shell behavior) and any other profile id to its configured shell path. Importing@utils/shellis safe in standalone/CLI builds becausevscodeis stubbed at runtime there.Test Procedure
StandaloneTerminalManager.profile.test.tscovering:bash) resolves to its shell path on created terminals (bothTerminalInfo.shellPathand the underlying terminal's_shellPath);defaultprofile leavesshellPathundefined (unchanged behavior);bash, Terminal Execution Mode to Background Exec, on a system whose default shell isfish. Before this change Cline ran commands underfish; after it runs underbash.I scoped the change to mirror
VscodeTerminalManagerso behavior stays consistent across hosts. Thedefaultprofile path is unchanged, so existing setups are unaffected.Type of Change
Pre-flight Checklist
.changeset/honest-otters-shine.md)