Commit Graph

149068 Commits

Author SHA1 Message Date
Alexandru Dima
ca117fbb4f Accept "Command produced no output" when shell integration is off (#303866)
Accept "Command produced no output" when shell integration is off (#303865)
2026-03-22 14:36:27 +00:00
Alexandru Dima
a7e3a4e1e5 fix: remove backslash escaping from terminal command labels (#303856)
* fix: remove escapeMarkdownSyntaxTokens from terminal command labels

Fixes #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
2026-03-22 23:24:40 +09:00
Alexandru Dima
12e343fccb fix: exclude sandbox analyzer when sandbox rewriting is disabled (#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
2026-03-22 21:45:40 +09:00
Alexandru Dima
be95b65d71 Fix terminal output capture: strip command echo/prompt, fix premature idle detection, improve sandbox failure detection, force bash over sh (#303754)
* fix: strip command echo and prompt from terminal output (#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
2026-03-22 11:37:34 +01:00
Alex Dima
487646cee8 Attempt to cover up the run_in_terminal tool not being registered quickly 2026-03-22 10:50:35 +01:00
Alex Dima
b2b4e0e207 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.
2026-03-22 10:10:09 +01:00
Alex Dima
9644aa33b4 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
2026-03-22 09:16:43 +01:00
Robo
30c0bd03a4 chore: bump electron@39.8.3 (#303738)
* chore: bump electron@39.8.3

* chore: update build

* chore: bump distro
2026-03-22 07:20:14 +01:00
Alex Dima
6e84e45d56 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.
2026-03-22 02:07:34 +01:00
Copilot
e428f03c19 fix: fetch tool should not warn when reading files inside the workspace (#303789) 2026-03-22 00:51:11 +00:00
Alex Dima
f0a7531832 Install bubblewrap and socat in Linux CI pipelines
These are required for terminal sandbox integration tests.
2026-03-22 01:49:00 +01:00
Alex Dima
e1fdfd1f1b 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)
2026-03-22 01:36:32 +01:00
Alex Dima
bd3ecf8f4d Fix mock in unit test 2026-03-22 00:54:34 +01:00
Alexandru Dima
5563927f89 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
2026-03-22 00:46:48 +01:00
Alex Dima
5059232618 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.
2026-03-22 00:17:30 +01:00
Alex Dima
4ed68ee36f Fix slash history test 2026-03-21 23:23:32 +01:00
Alex Dima
61627c8b44 Merge remote-tracking branch 'origin/main' into alexdima/fix-303531-sandbox-no-output-leak 2026-03-21 22:36:11 +01:00
Alex Dima
436b09abc3 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
2026-03-21 22:36:04 +01:00
Alex Dima
f4644120bc Cover case where the command is duplicated in stripCommandEchoAndPrompt 2026-03-21 22:28:19 +01:00
Alexandru Dima
c02137526e Use terminal-secure icon for sandboxed commands (#303778)
* Adopt new codicons version

* terminal: use terminal-secure codicon for sandboxed commands

Add per-invocation icon support to tool invocations via
`IPreparedToolInvocation.icon` and `IChatToolInvocation.icon`.
The terminal tool sets the icon to `terminal-secure` when sandbox
is active, or `terminal` otherwise. The thinking content part and
subagent content part use this icon when rendering, falling back
to the existing heuristic for tools without a registered icon.

Also removes the $(lock) theme icon prefix from sandbox invocation
messages since the icon now communicates the sandbox state.

* Fix unit test

* Review feedback
2026-03-21 22:15:48 +01:00
Alex Dima
cbc41b0485 Review feedback 2026-03-21 21:51:03 +01:00
Alex Dima
7517f8a3ee refactor: extract findCommandEcho and use prompt evidence to narrow trailing prompt regex matching 2026-03-21 21:44:03 +01:00
dileepyavan
ae0f754c98 Fix terminal sandbox tmp dir scoping (#303770) 2026-03-21 20:40:12 +00:00
Alex Dima
894596bbea Fix unit test 2026-03-21 21:34:54 +01:00
Alex Dima
d3d1f067e8 terminal: use terminal-secure codicon for sandboxed commands
Add per-invocation icon support to tool invocations via
`IPreparedToolInvocation.icon` and `IChatToolInvocation.icon`.
The terminal tool sets the icon to `terminal-secure` when sandbox
is active, or `terminal` otherwise. The thinking content part and
subagent content part use this icon when rendering, falling back
to the existing heuristic for tools without a registered icon.

Also removes the $(lock) theme icon prefix from sandbox invocation
messages since the icon now communicates the sandbox state.
2026-03-21 21:25:59 +01:00
Osvaldo Ortega
bb217020c0 Merge pull request #303343 from microsoft/osortega/steady-puma
Sessions: E2E test fixes
2026-03-21 14:17:48 -06:00
Alex Dima
0a0ba75021 Adopt new codicons version 2026-03-21 21:08:48 +01:00
Osvaldo Ortega
d811b6623c Fix assert 2026-03-21 14:01:17 -06:00
Osvaldo Ortega
e769150e8b Test fix 2026-03-21 13:32:14 -06:00
Osvaldo Ortega
a342d8ccc7 Merge branch 'main' of https://github.com/microsoft/vscode into osortega/steady-puma 2026-03-21 13:31:50 -06:00
Rob Lourens
896c13e4a8 Add unit test skill for vscode (#303766) 2026-03-21 19:10:48 +00:00
Alex Dima
f4c042bfc8 Relax some tests when shell integration is off 2026-03-21 19:56:04 +01:00
Alex Dima
22913a387d fix: detect sandbox failures heuristically when exit code is unavailable 2026-03-21 19:20:59 +01:00
Rob Lourens
146a2ea7e7 Human-readable remote agent host address (#303758) 2026-03-21 11:14:33 -07:00
Rob Lourens
6ae7d0c592 Fix workbench contrib warning (#303760) 2026-03-21 11:13:36 -07:00
Alex Dima
865568dbbc 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)
2026-03-21 19:06:50 +01:00
Alex Dima
5c733b67ac 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
2026-03-21 18:50:17 +01:00
Alexandru Dima
5bd41fae60 Re-register run_in_terminal tool when sandbox settings change (#303748)
* Re-register run_in_terminal tool when sandbox settings change

When the terminal sandbox setting is toggled at runtime, the
run_in_terminal tool's schema and description were not updated because
the tool data was only computed once at startup. This meant the model
never learned about requestUnsandboxedExecution when sandbox was
enabled after startup.

Fix by using a MutableDisposable to manage the tool registration and
re-registering whenever sandbox-related settings, network domains, or
trusted domains change.

Fixes #303714

* Fix race condition in run_in_terminal tool re-registration and add refresh tests

Guard _registerRunInTerminalTool against stale async resolutions using a monotonically increasing version counter. Export ChatAgentToolsContribution for testability. Add integration tests verifying tool data refreshes on config and trusted domain changes.
2026-03-21 10:42:19 -07:00
Alex Dima
842c746bb2 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.
2026-03-21 18:35:26 +01:00
Alex Dima
d4359ab0d8 Review feedback 2026-03-21 18:07:41 +01:00
Alex Dima
a32b488b9d 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 #".
2026-03-21 18:05:15 +01:00
Alex Dima
31a4a74df7 Fix compilation errors 2026-03-21 17:58:07 +01:00
Alex Dima
34dd7810b7 fix: strip command echo and prompt from terminal output (#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.
2026-03-21 17:43:25 +01:00
Alexandru Dima
930498f060 Merge pull request #303720 from microsoft/fix/terminal-sandbox-instructions
Improve terminal sandbox instructions for LLM tool descriptions
2026-03-21 12:16:20 +01:00
Alex Dima
babe1c71b0 Address review feedback for terminal sandbox instructions
- Extract sandbox line generation into shared createSandboxLines() helper
- Compute effective allowed domains by filtering out denied domains
- Add sandbox/network domain instructions to PowerShell description
- Add tests for network domain inclusion and denied domain filtering
2026-03-21 11:49:56 +01:00
Alex Dima
2ed5b851eb Include allowed/blocked network domains in run_in_terminal tool instructions (#303582) 2026-03-21 10:59:54 +01:00
Alex Dima
0c86a6f765 Clarify sandbox retry prompts to instruct LLM to set requestUnsandboxedExecution=true directly (#303436) 2026-03-21 10:41:55 +01:00
dileepyavan
ac2da2ad98 Fixing incorrect rendering of invocation message in sandbox mode. (#303711)
rendering in markdown string
2026-03-21 09:30:56 +00:00
dileepyavan
b978bf74b2 tmp directory should not be used by sandboxed commands (#303699)
* Fix terminal sandbox tmp handling and upgrade sandbox runtime

Fixes #299224

Fixes #303568

* fixing test

* merging changes
2026-03-21 10:20:44 +01:00
Don Jayamanne
a1254fd4c2 update external tool invocations so terminal output renders (#303394) 2026-03-21 08:18:30 +00:00