Repository navigation
Commit d44725a
Add noninteractive, isolated Python environment tooling for agents (#1900)
# Add noninteractive, isolated Python environment tooling for agents
## Summary
Add a private, versioned `__pythonTools` capability to the existing flat
extension export so Python agent tools can configure environments,
inspect interpreters/packages, and install packages without requiring
extension-owned pickers or dialogs.
The companion Python-extension change consumes this capability. The
public API contract is unchanged, and host tool approval remains in
force.
## Motivation
Agent requests currently reuse interactive environment workflows, which
can pause for interpreter, manager, package, or environment-creation
choices. A selected global interpreter can also become the
package-installation target.
This change gives agents an explicit noninteractive path with isolation
by default, actionable errors, and scoped results, without recording why
an interpreter was selected.
## Behavior
- Automatic configuration reuses a usable isolated environment or
creates one for the project. A selected System/Pyenv base creates a venv
using that interpreter; Conda base creates a project Conda environment
with the same Python major/minor version.
- An explicit `pythonPath` still selects that exact existing
interpreter. Package tools reject global/base environments even when
selected explicitly.
- Queries do not create environments or change selection. Package
installation does not implicitly configure an environment.
- Configuration and installation require an open, trusted, local
workspace. Results identify the effective resource, environment, and
execution information.
- Root selections survive reload, including when
`python.defaultInterpreterPath` is configured. Nested targets persist
exact project entries without replacing root defaults.
- Existing Poetry/Pipenv project caches and enabled PEP 723 scripts have
noninteractive discovery/setup paths.
- Errors and partial creation results are returned explicitly.
Same-scope operations are serialized; cancellation and timeouts await
owned-process cleanup and report uncertainty instead of falsely claiming
that a process stopped.
- Failed human venv initialization invalidates partial discovery and
readiness state, so subsequent public lookups retry discovery instead of
remaining on a stale global fallback. Private discovery remains
independent of human onboarding.
## Human-flow compatibility
Built-in managers opt in through internal symbol capabilities and
explicit operation flags. Normal public selection, creation, package,
and execution entry points retain their interactive behavior, including
public quick-create's `.venv-N` suffixing.
This is not a claim that all shared code is untouched:
- Venv collection events can arrive earlier relative to base-manager
onboarding.
- Public Conda command failures no longer generate the extra unhandled
rejection caused by the old unused `finally()` promise.
- Agent selections, settings, and package changes intentionally remain
visible to subsequent human operations.
## Validation
- Full ESLint and TypeScript checks pass.
- Windows unit suite after rebasing onto current upstream `main`:
**2,752 passing, 7 pending**. Six new failure-path assertions failed
before the retry fix and now pass; successful initialization remains
cached. The new upstream venv deletion, unresolved-selection recovery,
refresh selection-race, uv bootstrap, and scoped Conda discovery tests
also pass with the combined implementation.
- Reviewer regression coverage verifies that private Conda execution
preserves shell metacharacters as one argument with shell execution
disabled, resolves Windows batch launchers to a real executable or fails
actionably, and scopes both package queries and installation
independently when two Poetry projects share one environment.
- Linux private/public boundary and owned-process suites with the retry
fix: **116 passing**.
- Real VS Code comparisons against the current base verified manual
selection, package install/remove, Run Python File, debugging, unittest
discovery/execution, switching back to global Python, and public
quick-create.
- Real-host agent verification covered fresh/global setup, selected-base
preservation, reload, multi-root, nested targets, Conda, Poetry/Pipenv,
PEP 723, cancellation, no-workspace behavior, and invalid input.
- Critical flows were repeated against freshly built production VSIX
contents. Installed files were compared with the packages rather than
inferred from unchanged version numbers.
- An additional real VS Code before/after retry check used the loaded
extension's actual venv manager, native discovery, a real newly created
venv, public selection and Run Python File. A one-shot post-discovery
base failure was injected only in the isolated test host. Both direct
initialization and public-get retries recovered without manual manager
refresh after the fix; the pre-fix build required refresh.
## Known findings before merge
- Ordinary project `.python-version` / `pyproject.toml` interpreter
constraints are not automatically resolved. Selected base interpreters
and `defaultInterpreterPath` are honored; PEP 723 constraints are
handled separately.
- macOS/remote E2E, arbitrary third-party integrations, and real-chat
model choices/approval combinations have not been exhaustively verified.
## Companion change
Python consumer PR:
[microsoft/vscode-python#26208](microsoft/vscode-python#26208).
The consumer checks the private version/method shape and retains a
compatibility route when the capability is unavailable.
---------
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>1 parent 4faeedf commit d44725a
56 files changed
Lines changed: 6090 additions & 566 deletions
File tree
- .github/instructions
- src
- common
- inlineScript
- utils
- features
- settings
- internal
- managers
- base/commands
- builtin
- commands
- inlineScript
- common
- conda
- commands
- pipenv
- poetry
- commands
- pyenv
- test
- common
- inlineScript
- features/settings
- internal
- managers
- builtin
- inlineScript
- conda
- mocks/vsc
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
98 | 98 | | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
101 | 247 | | |
102 | 248 | | |
103 | 249 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| 657 | + | |
| 658 | + | |
657 | 659 | | |
658 | | - | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
659 | 664 | | |
660 | 665 | | |
661 | 666 | | |
| |||
671 | 676 | | |
672 | 677 | | |
673 | 678 | | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
674 | 682 | | |
675 | 683 | | |
676 | 684 | | |
677 | 685 | | |
678 | | - | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
679 | 695 | | |
680 | 696 | | |
681 | 697 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
| 56 | + | |
55 | 57 | | |
56 | 58 | | |
57 | 59 | | |
| |||
0 commit comments