terminalEnvironment.ts ×6

Frontier kind: Code frontier

unlabeled · c_bfd49ed814d0

1061 tests · 9484 LOC · 44 files · introduces 0 tests · 123 LOC · 1 file

Introduces — evidence that enters the hierarchy at this concept

Code
6 ranges123 lines · 1 files
Tests
0 tests

Contains — complete concept membership

All code (extent)
1289 ranges9484 lines · 44 files · Browse complete extent
All tests (intent)
1061 testsBrowse complete intent

Neighbourhood graph

The orange circle is the focus. Violet and green circles are every ancestor and descendant, broader and narrower, at any distance; blue squares and pink diamonds are the introduced files and exact introduced tests of every visible concept, not only the focus's. Arrows point from broader to narrower concepts and bridge only concepts omitted from this view. Undirected links show source or test introduction. Concept and file size follows LOC; exact test nodes use test-count units.

Introduced files, introduced tests, and structurally relevant concept specialization

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the native relationship evidence on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the native relationship evidence on this page while the interactive map is unavailable.

Native relationship evidence

Every exact file and test below is linked only from the concept that introduces it.

Introduced tests

Every collected test enters the hierarchy at exactly one concept.

No tests are introduced at this concept. Its intent tests are introduced by other concepts.

Introduced code

Every collected source range enters the hierarchy at exactly one concept.

1 file ranked by introduced lines: 123 introduced LOC across 6 ranges. Expand a file to inspect source; the > gutter marks introduced lines.

src/vs/platform/terminal/node/terminalEnvironment.ts 123 introduced LOC · 6 ranges

Open complete file

1 > /*--------------------------------------------------------------------------------------------- terminalEnvironment.ts
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import * as os from 'os';
7 > import { FileAccess } from '../../../base/common/network.js';
8 > import * as path from '../../../base/common/path.js';
9 > import { IProcessEnvironment, isMacintosh, isWindows } from '../../../base/common/platform.js';
10 > import * as process from '../../../base/common/process.js';
11 > import { format } from '../../../base/common/strings.js';
12 > import { ILogService } from '../../log/common/log.js';
13 > import { IProductService } from '../../product/common/productService.js';
14 > import { IShellLaunchConfig, ITerminalEnvironment, ITerminalProcessOptions, ShellIntegrationInjectionFailureReason } from '../common/terminal.js';
15 > import { EnvironmentVariableMutatorType } from '../common/environmentVariable.js';
16 > import { deserializeEnvironmentVariableCollections } from '../common/environmentVariableShared.js';
17 > import { MergedEnvironmentVariableCollection } from '../common/environmentVariableCollection.js';
18 > import { chmod, realpathSync, mkdirSync } from 'fs';
19 > import { promisify } from 'util';
20 > import { isString, SingleOrMany } from '../../../base/common/types.js';
21 > import { getWindowsBuildNumberAsync } from '../../../base/node/windowsVersion.js';
22 >
23 > export interface IShellIntegrationConfigInjection {
24 > readonly type: 'injection';
25 > /**
26 > * A new set of arguments to use.
27 > */
28 > readonly newArgs: string[] | undefined;
29 > /**
30 > * An optional environment to mixing to the real environment.
31 > */
32 > readonly envMixin?: IProcessEnvironment;
33 > /**
34 > * An optional array of files to copy from `source` to `dest`.
35 > */
36 > readonly filesToCopy?: {
37 > source: string;
38 > dest: string;
39 > }[];
40 > }
41 >
42 > export interface IShellIntegrationInjectionFailure {
43 > readonly type: 'failure';
44 > readonly reason: ShellIntegrationInjectionFailureReason;
45 > }
46 >
47 > /**
48 > * For a given shell launch config, returns arguments to replace and an optional environment to
49 > * mixin to the SLC's environment to enable shell integration. This must be run within the context
50 > * that creates the process to ensure accuracy. Returns undefined if shell integration cannot be
51 > * enabled.
52 > */
53 export async function getShellIntegrationInjection(
54 shellLaunchConfig: IShellLaunchConfig,
279 return { type: 'failure', reason: ShellIntegrationInjectionFailureReason.UnsupportedShell };
280 }
282 > /**
283 > * There are a few situations where some directories are added to the beginning of the PATH.
284 > * 1. On macOS when the profile calls path_helper.
285 > * 2. For fish terminals, which always prepend "$fish_user_paths" to the PATH.
286 > *
287 > * This causes significant problems for the environment variable
288 > * collection API as the custom paths added to the end will now be somewhere in the middle of
289 > * the PATH. To combat this, VSCODE_PATH_PREFIX is used to re-apply any prefix after the profile
290 > * has run. This will cause duplication in the PATH but should fix the issue.
291 > *
292 > * See #99878 for more information.
293 > */
294 function addEnvMixinPathPrefix(options: ITerminalProcessOptions, envMixin: IProcessEnvironment, shell: string): void {
295 if ((isMacintosh || shell === 'fish') && options.environmentVariableCollections) {
315 }
316 }
318 > enum ShellIntegrationExecutable {
319 > WindowsPwsh = 'windows-pwsh',
320 > WindowsPwshLogin = 'windows-pwsh-login',
321 > Pwsh = 'pwsh',
322 > PwshLogin = 'pwsh-login',
323 > Zsh = 'zsh',
324 > ZshLogin = 'zsh-login',
325 > Bash = 'bash',
326 > Fish = 'fish',
327 > FishLogin = 'fish-login',
328 > }
329 >
330 > const shellIntegrationArgs: Map<ShellIntegrationExecutable, string[]> = new Map();
331 > // The try catch swallows execution policy errors in the case of the archive distributable
332 > shellIntegrationArgs.set(ShellIntegrationExecutable.WindowsPwsh, ['-noexit', '-command', 'try { . \"{0}\\out\\vs\\workbench\\contrib\\terminal\\common\\scripts\\shellIntegration.ps1\" } catch {}{1}']);
333 > shellIntegrationArgs.set(ShellIntegrationExecutable.WindowsPwshLogin, ['-l', '-noexit', '-command', 'try { . \"{0}\\out\\vs\\workbench\\contrib\\terminal\\common\\scripts\\shellIntegration.ps1\" } catch {}{1}']);
334 > shellIntegrationArgs.set(ShellIntegrationExecutable.Pwsh, ['-noexit', '-command', '. "{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1"{1}']);
335 > shellIntegrationArgs.set(ShellIntegrationExecutable.PwshLogin, ['-l', '-noexit', '-command', '. "{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1"']);
336 > shellIntegrationArgs.set(ShellIntegrationExecutable.Zsh, ['-i']);
337 > shellIntegrationArgs.set(ShellIntegrationExecutable.ZshLogin, ['-il']);
338 > shellIntegrationArgs.set(ShellIntegrationExecutable.Bash, ['--init-file', '{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration-bash.sh']);
339 > shellIntegrationArgs.set(ShellIntegrationExecutable.Fish, ['--init-command', 'source "{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.fish"']);
340 > shellIntegrationArgs.set(ShellIntegrationExecutable.FishLogin, ['-l', '--init-command', 'source "{0}/out/vs/workbench/contrib/terminal/common/scripts/shellIntegration.fish"']);
341 > const pwshLoginArgs = ['-login', '-l'];
342 > const shLoginArgs = ['--login', '-l'];
343 > const shInteractiveArgs = ['-i', '--interactive'];
344 > const pwshImpliedArgs = ['-nol', '-nologo'];
345 >
346 function arePwshLoginArgs(originalArgs: SingleOrMany<string>): boolean {
347 if (isString(originalArgs)) {
354 }
355 }
357 function arePwshImpliedArgs(originalArgs: SingleOrMany<string>): boolean {
358 if (isString(originalArgs)) {
362 }
363 }
365 function areZshBashFishLoginArgs(originalArgs: SingleOrMany<string>): boolean {
366 if (!isString(originalArgs)) {
370 || !isString(originalArgs) && originalArgs.length === 1 && shLoginArgs.includes(originalArgs[0].toLowerCase());
371 }
373 > /**
374 > * Patterns that indicate sensitive environment variable names.
375 > */
376 > const sensitiveEnvVarNames = /^(?:.*_)?(?:API_?KEY|TOKEN|SECRET|PASSWORD|PASSWD|PWD|CREDENTIAL|AUTH|PRIVATE_?KEY|ACCESS_?KEY|CLIENT_?SECRET|APIKEY)(?:_.*)?$/i;
377 >
378 > /**
379 > * Patterns for detecting secret values in environment variables.
380 > */
381 > const secretValuePatterns = [
382 > // JWT tokens
383 > /^eyJ[a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+$/,
384 > // GitHub tokens
385 > /^gh[psuro]_[a-zA-Z0-9]{36}$/,
386 > /^github_pat_[a-zA-Z0-9]{22}_[a-zA-Z0-9]{59}$/,
387 > // Google API keys
388 > /^AIza[A-Za-z0-9_\-]{35}$/,
389 > // Slack tokens
390 > /^xox[pbar]\-[A-Za-z0-9\-]+$/,
391 > // Azure/MS tokens (common patterns)
392 > /^[a-zA-Z0-9]{32,}$/,
393 > ];
394 >
395 > /**
396 > * Sanitizes environment variables for logging by redacting sensitive values.
397 > */
398 > export function sanitizeEnvForLogging(env: IProcessEnvironment | undefined): IProcessEnvironment | undefined {
399 if (!env) {
400 return env;