Skip to content

[mirror] microsoft/vscode#307884 terminal: fix unreliable middle-click paste on Linux#1100

Open
austindyoung wants to merge 2468 commits intomainfrom
driftfence/mirror/pr-307884/latest
Open

[mirror] microsoft/vscode#307884 terminal: fix unreliable middle-click paste on Linux#1100
austindyoung wants to merge 2468 commits intomainfrom
driftfence/mirror/pr-307884/latest

Conversation

@austindyoung
Copy link
Copy Markdown
Owner

Automated mirror PR for DriftFence counterfactual telemetry.

Source PR: microsoft#307884
Source URL: microsoft#307884
Mirror branch: driftfence/mirror/pr-307884/latest

This PR is maintained by automation for telemetry and review links.

alexdima and others added 30 commits March 22, 2026 10:50
… idle detection, improve sandbox failure detection, force bash over sh (microsoft#303754)

* fix: strip command echo and prompt from terminal output (microsoft#303531)

Prevent sandbox-wrapped command lines from leaking as output when

commands produce no actual output. Adds stripCommandEchoAndPrompt()

to isolate real output from marker-based terminal buffer captures.

Also adds configurable idle poll interval and shell integration

timeout=0 support for faster test execution.

* Fix compilation errors

* fix: tighten trailing prompt stripping to avoid dropping legitimate output

Anchor prompt-detection regexes to specific prompt shapes instead of
broadly matching any line ending with $, #, %, or >. This prevents
stripping real command output like "100%", "<div>", or "item #".

* Review feedback

* fix: skip stale prompt fragments before command echo in stripping

In CI, ^C cancellations leave stale prompt fragments before the actual
command echo line. The leading-strip loop now continues scanning past
unmatched lines until it finds the command echo, instead of breaking
on the first non-matching line.

* fix: handle macOS CI prompt format and add stripping to rich strategy

- Add trailing prompt patterns for hostname:path user$ (no @ sign)
- Handle wrapped prompt fragments like "er$" at line boundaries
- Add stripCommandEchoAndPrompt to RichExecuteStrategy marker fallback
- Context-aware wrapped prompt continuation detection

* fix: Linux CI sandbox prereqs, platform-aware tests, broader prompt stripping

- Add bubblewrap and socat to Linux CI apt-get install
- Make sandbox test assertions platform-aware (macFileSystem vs linuxFileSystem)
- Make /etc/shells test accept both macOS and Linux first-line format
- Broaden wrapped prompt fragment regex to handle path chars (ts/testWorkspace$)
- Fix continuation pattern to match user@host:path wrapped lines
- Apply stripCommandEchoAndPrompt to getOutput() in BasicExecuteStrategy
  (basic shell integration lacks reliable 133;C markers so getOutput()
  can include command echo)
- Keep RichExecuteStrategy getOutput() unstripped (rich integration
  has reliable markers)

* fix: detect sandbox failures heuristically when exit code is unavailable

* Relax some tests when shell integration is off

* refactor: extract findCommandEcho and use prompt evidence to narrow trailing prompt regex matching

* Cover case where the command is duplicated in `stripCommandEchoAndPrompt`

* Fix sandbox tests for Linux: handle different shell path and error message

- Handle /usr/bin/bash (Linux) vs /bin/bash (macOS) in /tmp write test
- Handle 'Read-only file system' (Linux) vs 'Operation not permitted' (macOS)
- Add 'Read-only file system' to outputLooksSandboxBlocked heuristic
- Replace newlines with spaces (not empty) to handle terminal wrapping
- Extract outputLooksSandboxBlocked as exported function with unit tests

* Fix slash history test

* Fix sandbox execPath resolution for remote environments

Add execPath to IRemoteAgentEnvironment so the server sends its actual
process.execPath to the client. The sandbox service now uses this instead
of hardcoding appRoot + '/node', which only works in production builds.

* Fix terminal output capture: prevent premature idle detection and handle partial command echoes

- setupRecreatingStartMarker returns IDisposable to stop marker recreation
  before sending commands (prevents marker jumping on PSReadLine re-renders)
- noneExecuteStrategy waits for cursor to move past start line after sendText
  before starting idle detection (prevents end marker at same line as start)
- findCommandEcho supports suffix matching for partial command echoes from
  wrapped getOutput() results (shell integration ON with long commands)
- Suffix matching requires mid-word split to avoid false positives on output
  that happens to be a suffix of the command (e.g. echo output)
- Integration tests: use ; separator on Windows, add && conversion test,
  handle Windows exit code quirks with cmd /c

* Fix mock in unit test

* Address PR feedback: logging, performance, timeout, and docs

- Strip sensitive data from debug logs (log metadata only)
- Use array join instead of O(n^2) string concat in stripNewLinesAndBuildMapping
- Add 5s timeout to cursor-move wait to prevent indefinite hangs
- Align shellIntegrationTimeout descriptions (0 = skip the wait)

* Install bubblewrap and socat in Linux CI pipelines

These are required for terminal sandbox integration tests.

* Force /bin/bash over /bin/sh for copilot terminal profile

Shell integration cannot be injected into /bin/sh, causing loss of
exit code detection. This matches the existing cmd.exe -> powershell
override pattern.

* Fix bracketed prompt without @ and cap trailing prompt stripping at 2 lines

- Extend bracketed prompt patterns from isUnixAt to isUnix so prompts
  like [W007DV9PF9-1:~/path] are recognized (CI macOS prompt format)
- Cap trailing prompt stripping at 2 non-empty lines to prevent
  over-stripping legitimate output
- Add unit tests for bracketed prompt without @ format

* Distinguish complete vs fragment prompts to prevent false stripping

Split trailing prompt patterns into two categories:
- Complete prompts (user@host:~ $, PS C:\>, etc.) stop stripping
  immediately — anything above is command output, not a wrapped prompt
- Fragment patterns (er$, ] $, [host:~/path...) allow continued
  stripping to reassemble wrapped prompts

This prevents falsely stripping output lines that happen to end with
$ or # when a real complete prompt sits below them. Added adversarial
tests verifying correct behavior for output containing prompt-like
characters.

* Attempt to cover up the `run_in_terminal` tool not being registered quickly
…rosoft#303846)

* fix: exclude sandbox analyzer when sandbox rewriting is disabled

When `ConfirmTerminalCommandTool` (used by CLI for
`vscode_get_terminal_confirmation`) disables sandbox command rewriting
via `_enableCommandLineSandboxRewriting = false`, the
`CommandLineSandboxAnalyzer` was still active and returning
`forceAutoApproval: true`. This caused the confirmation to be skipped
even though the command would not actually be sandboxed.

Guard `CommandLineSandboxAnalyzer` with the same
`_enableCommandLineSandboxRewriting` check that already guards
`CommandLineSandboxRewriter`.

Fixes microsoft/vscode-internalbacklog#7187

* update doc comment for _enableCommandLineSandboxRewriting

* clarify test name per review feedback
…t#303856)

* fix: remove escapeMarkdownSyntaxTokens from terminal command labels

Fixes microsoft#303844

The command text in ChatTerminalThinkingCollapsibleWrapper was being
escaped with escapeMarkdownSyntaxTokens(), which adds backslashes before
chars like - * # etc. This is unnecessary because the text is always
rendered inside markdown code spans or via .textContent, both of which
treat content as literal.

Also adds a component fixture for the terminal collapsible wrapper to
enable visual regression testing of command label rendering.

* fix: use DOM nodes instead of MarkdownString for sandbox command labels

Addresses review feedback: commands containing backticks (common in
PowerShell) would break the inline-code markdown spans. Now both
sandbox and non-sandbox paths use text nodes + <code> elements with
.textContent, which is always safe for arbitrary command text.

Also adds fixture cases for backtick-containing commands to catch
this class of issue.

* fix: remove colons from fixture names to fix CI artifact paths

* add screenshot baselines for terminal collapsible fixtures
…crosoft#303866)

Accept "Command produced no output" when shell integration is off (microsoft#303865)
…rosoft#303859)

* fix: command rewriting issues when terminal sandboxing is enabled

Fixes two issues with sandboxed terminal commands:

1. Sandboxed commands end up in shell history (microsoft#303769): The
   PreventHistoryRewriter was running before SandboxRewriter, so the
   leading space was applied to the inner command but not the final
   sandbox-wrapped command. Moved PreventHistoryRewriter to run last.

2. cd CWD prefix not stripped in sandbox mode (microsoft#303848): The
   SandboxedCommandLinePresenter was using the original (un-rewritten)
   command for display, bypassing cd prefix stripping. Changed to use
   forDisplay instead.

3. Fixed forDisplay being clobbered: The rewriter loop unconditionally
   overwrote forDisplay, so later rewriters without a forDisplay
   (like PreventHistoryRewriter) would clear the sandbox's display
   value. Changed to only update when explicitly provided.

Fixes microsoft#303769
Fixes microsoft#303848

* update doc comment for SandboxedCommandLinePresenter

* improve execute strategy logging for CI diagnostics

Upgrade strategy selection and completion logs to info level in
runInTerminalTool. In richExecuteStrategy, log at info level when
running in CI (for diagnosing shell integration race conditions)
and debug otherwise.

* fix: include ignorespace in bash shell integration history verification

When VSCODE_PREVENT_SHELL_HISTORY=1 is set (which it is for all tool
terminals created by the run_in_terminal tool), the bash shell
integration script sets HISTCONTROL="ignorespace" (line 67). This
causes bash to exclude space-prefixed commands from history.

Later in the same script (line 200), a regex decides whether to use
`history 1` or $BASH_COMMAND to capture the current command in
__vsc_preexec. The regex checks for erasedups, ignoreboth, and
ignoredups — but NOT ignorespace. This is a bug because:

1. The same script sets HISTCONTROL=ignorespace 130 lines earlier
2. ignoreboth (which IS in the regex) is defined by bash as
   "ignorespace + ignoredups" — so the compound form was handled
   but the simple form was not

The consequence: with HISTCONTROL=ignorespace and __vsc_history_verify=1,
__vsc_preexec calls `history 1` to get the current command. But the
command has a leading space (added by PreventHistoryRewriter), so bash
history never recorded it. `history 1` returns the PREVIOUS command
or nothing. This causes __vsc_current_command to be wrong or empty.

In __vsc_command_complete, when __vsc_current_command is empty, the
script sends the OSC sequence 633;D WITHOUT an exit code (line 373).
The VS Code side then receives onCommandFinished with exitCode=undefined,
breaking exit code detection for ALL tool terminal commands on bash.

The fix adds ignorespace to the existing regex, so bash falls back to
$BASH_COMMAND (which always works regardless of history settings).
This matches the behavior already provided when ignoreboth is set.

* docs: improve fix-ci-failures skill with faster log retrieval workflow
… enhance attachment handling (microsoft#303643)

* fix: update chat slash commands to include GitHub Copilot targets and enhance attachment handling

This may not be the right way to handle this... but look, slash commands that are silent like `/clear`, `/fork`, `/debug`, `/models` are not attachments. They're simply another way to invoke a command simple as that.

This code originally gated those showing up in completions AND actually working (parser changes) on whether or not the chatSession supported PromptAttachments. This refactors that to allow silent commands to go through even if that's not defined.

2nd. This change then caused allllll these permissiony commands to show up for Claude even though that UX doesn't exist for Claude so I have hard coded the target only because the when clause is also hard coded here:
https://github.com/microsoft/vscode/blob/5ce6509b44ef4567da385254af426dc6ca79deae/src/vs/workbench/contrib/chat/browser/actions/chatExecuteActions.ts#L480

With these 2 changes, Claude gets a few more slash commands:
* `/clear`
* `/fork`
* `/debug`
* `/models` (and Copilot CLI gets this one too since I removed the hardcoded target)

* feedback
…microsoft#303712)

* Intercept vscode meta keybindings before xterm.js when kitty keyboard active

* better word

* Add test
Bumps [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser) from 5.5.6 to 5.5.8.
- [Release notes](https://github.com/NaturalIntelligence/fast-xml-parser/releases)
- [Changelog](https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/CHANGELOG.md)
- [Commits](NaturalIntelligence/fast-xml-parser@v5.5.6...v5.5.8)

---
updated-dependencies:
- dependency-name: fast-xml-parser
  dependency-version: 5.5.8
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
git: fix parent directory loop using wrong set for early exit in worktree include paths

Co-authored-by: xingsy97 <[email protected]>
* Revert "Add chat session header component and styles"

This reverts commit e4c0ce5.

* fix compilation
…y/sessions-panel-animations"

This reverts commit dd92840, reversing
changes made to 1e6a57b.
…oft#304066)

* style: enhance chat bar appearance with margin and background styling

Co-authored-by: Copilot <[email protected]>

* style: adjust padding and margin for title bar and chat bar components

* style: adjust chat bar and title bar padding, add border width for layout consistency

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: mrleemurray <[email protected]>
Co-authored-by: Copilot <[email protected]>
Fixes microsoft#303361

Introduces \\\ variables that extract named capture groups
from a task problem matcher's endsPattern and make them available for
substitution in launch configurations and other variable-resolved contexts.

Changes:
- WatchingProblemCollector.tryFinish() extracts matches.groups from endsPattern
- IProblemCollectorEvent carries capturedVariables in BackgroundProcessingEnds
- TerminalTaskSystem registers captured variables via contributeVariable()
- VariableKind.TaskVar added to the enum
- Test added for taskVar variable resolution
- .vscode/launch.json updated to use \
…t#304062)

* feat: enhance GitHub PR handling with headSha support and immediate refresh on session change

* feat: implement immediate PR data refresh on active session change

* feat: add URI import and enhance session resource handling in GitHubActiveSessionRefreshContribution
mrleemurray and others added 29 commits March 25, 2026 08:25
* Add "Mark as Done" button to sessions title bar for archiving sessions

Co-authored-by: Copilot <[email protected]>

* Enhance "Mark as Done" button functionality with focus styles and session state checks

Co-authored-by: Copilot <[email protected]>

* style: adjust padding for agent sessions titlebar container and add Mark Session As Done action

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: mrleemurray <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…ive-plum-heron

Sessions: Add subtle appear transitions for sidebar and auxiliary parts
…chat

Pass the session's file URI and initial selection to the panel chat widget
when continuing an inline chat session in panel chat. The selection is
added as a file attachment before the request is sent, ensuring the panel
chat has the same context as the original inline chat session.

Fixes microsoft#249226

Co-authored-by: jrieken <[email protected]>
Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/d8bafe8b-3607-4025-864e-0d47bd376f9c
untitled uri strikes again... we should try getting the real session first before resolving to an untitled uri.
* sessions - fix title for cloud sessions

* Update src/vs/sessions/contrib/sessions/browser/sessionsTitleBarWidget.ts

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
…#304718)

* fix - update confirmation dialog for archiving sessions

* fix - update confirmation dialog for archiving sessions

* fix - update detail message for archiving sessions

* fix - update confirmation dialogs for archiving sessions

* Update src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsActions.ts

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
* Can't read archived sessions in light mode (fix microsoft#304294)

* feat - add metadata logging for agent sessions

* Update src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionsModel.ts

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
style - remove file icon from modal editor titles
* sessions - separate user dir for `--sessions` runs

* Update tasks.json

---------

Co-authored-by: Benjamin Christopher Simmonds <[email protected]>
…-chat-context-loss

Preserve selection context when "Ask in Chat" from inline chat
…-rose-python

Sessions: Update titlebar action icon color
On Linux the middle-click paste in the terminal was unreliable when the
click occurred over a word because xterm.js intercepts the mouse event
to select the word before the browser can perform the primary-selection
paste. Instead of relying on Chromium's primary-selection paste, this
change explicitly pastes the primary selection clipboard when
middleClickBehavior is 'default' on Linux, matching the behavior users
expect and making the paste reliable regardless of cursor position.

Fixes microsoft#272927
@austindyoung austindyoung force-pushed the driftfence/mirror/pr-307884/latest branch from 297e3d4 to 3243a6c Compare April 6, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.